{"text": "-- Prueba por inducción 4: ∀ m n : ℕ, m + n = n + m\n-- ================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Sean m y n números naturales. Demostrar que\n--    m + n = n + m\n-- ----------------------------------------------------\n\nimport tactic\n\nopen nat\n\nvariables (m n : ℕ)\n\n-- #check nat.add_zero\n-- #check nat.add_succ\n-- #check nat.zero_add\n-- #check nat.succ_add\n\n-- 1ª demostración\nexample : m + n = n + m :=\nbegin\n  induction n with n HI,\n  { rw nat.add_zero,\n    rw nat.zero_add, },\n  { rw add_succ,\n    rw HI,\n    rw succ_add, },\nend\n\n-- 2ª demostración\nexample : m + n = n + m :=\nbegin\n  induction n with n HI,\n  { simp only [nat.add_zero, nat.zero_add] },\n  { simp only [add_succ, HI, succ_add] },\nend\n\n-- 3ª demostración\nexample : m + n = n + m :=\nby induction n;\n   simp only [*, nat.add_zero, add_succ, succ_add, nat.zero_add]\n\n-- 4ª demostración\nexample : m + n = n + m :=\nby induction n;\n   simp [*, add_succ, succ_add]\n\n-- 5ª demostración\nexample : m + n = n + m :=\nnat.rec_on n\n  (show m + 0 = 0 + m, from\n    calc m + 0\n             = m     : by rw nat.add_zero\n         ... = 0 + m : by rw nat.zero_add )\n  (assume n,\n   assume HI : m + n = n + m,\n   show m + n.succ = n.succ + m, from\n     calc\n       m + succ n\n           = succ (m + n) : by rw add_succ\n       ... = succ (n + m) : by rw HI\n       ... = succ n + m   : by rw succ_add)\n\n-- 6ª demostración\nexample : m + n = n + m :=\nnat.rec_on n\n  (show m + 0 = 0 + m, by rw [nat.zero_add, nat.add_zero])\n  (assume n,\n   assume HI : m + n = n + m,\n   calc\n     m + succ n = succ (m + n) : rfl\n       ... = succ (n + m)      : by rw HI\n       ... = succ n + m        : by rw succ_add)\n\n-- 7ª demostración\nexample : m + n = n + m :=\nnat.rec_on n\n  (by simp only [nat.zero_add, nat.add_zero])\n  (λ n HI, by simp only [add_succ, HI, succ_add])\n\n-- 8ª demostración\nexample : m + n = n + m :=\nnat.rec_on n\n  (by simp)\n  (λ n HI, by simp [add_succ, HI, succ_add])\n\n-- 9ª demostración\nexample : m + n = n + m :=\n-- by library_search\nnat.add_comm m n\n\n-- 10ª demostración\nexample : m + n = n + m :=\n-- by hint\nby finish\n\n-- 11ª demostración\nexample : m + n = n + m :=\nby linarith\n\n-- 12ª demostración\nexample : m + n = n + m :=\nby nlinarith\n\n-- 13ª demostración\nexample : m + n = n + m :=\nby ring\n\n-- 14ª demostración\nexample : m + n = n + m :=\nby omega\n\n-- 15ª demostración\nlemma conmutativa : ∀ m n : ℕ, m + n = n + m\n| m 0     := by simp\n| m (n+1) := by simp [add_succ, conmutativa m n, succ_add]\n\n-- 16ª demostración\nlemma conmutativa2 : ∀ m n : ℕ, m + n = n + m\n| m 0     := by simp only [nat.add_zero, nat.zero_add]\n| m (n+1) := by simp only [nat.add_zero, add_succ, conmutativa2 m n, succ_add]\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_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8791467706759584, "lm_q1q2_score": 0.7999418081216079}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Importar la teoría de anillos.\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Crear el espacio de nombre my_ring.\n-- ----------------------------------------------------------------------\n\nnamespace my_ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Declara R una variable sobre anillos.\n-- ----------------------------------------------------------------------\n\nvariables {R : Type*} [ring R]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Declarar a, b y c como variables sobre R.\n-- ----------------------------------------------------------------------\n\nvariables {a b c : R}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que si\n--    a + b = a + c\n-- entonces\n--    b = c\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\ntheorem add_left_cancel\n  (h : a + b = a + c)\n  : b = c :=\ncalc b\n     = 0 + b        : by rw zero_add\n ... = (-a + a) + b : by rw add_left_neg\n ... = -a + (a + b) : by rw add_assoc\n ... = -a + (a + c) : by rw h\n ... = (-a + a) + c : by rw ←add_assoc\n ... = 0 + c        : by rw add_left_neg\n ... = c            : by rw zero_add\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (h : a + b = a + c)\n  : b = c :=\nbegin\n  have h1 : -a + (a + b) = -a + (a + c),\n    { by exact congr_arg (has_add.add (-a)) h, },\n  clear h,\n  rw ← add_assoc at h1,\n  rw add_left_neg at h1,\n  rw zero_add at h1,\n  rw ← add_assoc at h1,\n  rw add_left_neg at h1,\n  rw zero_add at h1,\n  exact h1,\nend\n\n-- El desarrollo de la prueba es\n--\n--    R : Type u_1,\n--    _inst_1 : ring R,\n--    a b c : R,\n--    h : a + b = a + c\n--    ⊢ b = c\n-- have h1 : -a + (a + b) = -a + (a + c),\n--    |    ⊢ -a + (a + b) = -a + (a + c)\n--    | { by exact congr_arg (has_add.add (-a)) h },\n--    h : a + b = a + c,\n--    h1 : -a + (a + b) = -a + (a + c)\n--    ⊢ b = c\n-- clear h,\n--    h1 : -a + (a + b) = -a + (a + c)\n--    ⊢ b = c\n-- rw ← add_assoc at h1,\n--    h1 : -a + a + b = -a + (a + c)\n--    ⊢ b = c\n-- rw add_left_neg at h1,\n--    h1 : 0 + b = -a + (a + c)\n--    ⊢ b = c\n-- rw zero_add at h1,\n--    h1 : b = -a + (a + c)\n--    ⊢ b = c\n-- rw ← add_assoc at h1,\n--    h1 : b = -a + a + c\n--    ⊢ b = c\n-- rw add_left_neg at h1,\n--    h1 : b = 0 + c\n--    ⊢ b = c\n-- rw zero_add at h1,\n--    h1 : b = c\n--    ⊢ b = c\n-- exact h1,\n--    no goals\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (h : a + b = a + c)\n  : b = c :=\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que si\n--    a + b = c + b\n-- entonces\n--    a = c\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\ntheorem add_right_cancel\n  (h : a + b = c + b)\n  : a = c :=\ncalc\n  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 ← add_assoc\n  ... = c + 0        : by rw ← add_right_neg\n  ... = c            : by rw add_zero\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (h : a + b = c + b)\n  : a = c :=\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Cerrar el espacio de nombre my_ring.\n-- ----------------------------------------------------------------------\n\nend my_ring\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/Cancelativas_de_la_suma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8791467595934565, "lm_q1q2_score": 0.7999417915940774}}
{"text": "--=============================--\n------ LÓGICA PROPOSICIONAL------\n--=============================--\n\n-- En lógica clásica, la doble negación de p y p son equivalentes\ntheorem iff_not_not {p : Prop} : ¬¬p ↔ p := \n  Iff.intro\n  Classical.byContradiction\n  (fun hp : p => fun hnp : ¬p => (hnp hp))\n\n\ntheorem notfalse_iff_true : ¬False ↔ True :=\n  ⟨fun _ => True.intro, fun _ hfalse => hfalse⟩\n\ntheorem nottrue_iff_false : ¬True ↔ False :=\n  ⟨fun hnottrue => hnottrue True.intro, fun hfalse => hfalse.elim⟩  \n\ntheorem forall_of_not_exists {p : α → Prop} : ¬ (∃ a, p a) → ∀ a, ¬ p a :=\n  fun h a hpa => h ⟨a,hpa⟩\n\n-- El contrarrecíproco de una implicación\ntheorem contrapositive {p q : Prop} : (p → q) → ¬q → ¬p :=\n  fun hpq hnq hp => hnq (hpq hp)\n\ntheorem implies_of_not_and {p q : Prop} : ¬ (p ∧ q) → (p → ¬ q) :=\n  fun hnpq hp hq => hnpq ⟨hp,hq⟩\n\ntheorem or_not_iff_not_and {p q : Prop} : ¬ (p ∧ q) ↔ ¬p ∨ ¬q := \n  ⟨fun hnpq : ¬(p ∧ q) =>\n    Or.elim (Classical.em p)\n    (fun hp => Or.inr (fun hq => hnpq ⟨hp,hq⟩))\n    (fun hnp => Or.inl hnp),\n  fun hnpnq : ¬p ∨ ¬q =>\n    fun ⟨hp,hq⟩ => hnpnq.elim (fun hnp => hnp hp) (fun hnq => hnq hq)⟩\n\n-- Una de las leyes de De Morgan\ntheorem and_or_iff {p q1 q2: Prop} : p ∧ (q1 ∨ q2) ↔ (p ∧ q1) ∨ (p ∧ q2) :=\n  ⟨fun h => h.right.elim (fun hq1 => Or.inl ⟨h.left,hq1⟩) (fun hq2 => Or.inr ⟨h.left,hq2⟩),\n  fun h => h.elim (fun hpq1 => ⟨hpq1.left, Or.inl hpq1.right⟩) (fun hpq2 => ⟨hpq2.left, Or.inr hpq2.right⟩)⟩\n\n-- El recíproco del principio de extensionalidad funcional\ntheorem funext_converse {f g : α → β} : f ≠ g → ∃ x : α, f x ≠ g x :=\n  fun hneq =>\n    Classical.byContradiction (fun hnotex => \n      have hforall1 : ∀ x, ¬ f x ≠ g x := forall_of_not_exists hnotex\n      have hforall : ∀ x, f x = g x := fun x => propext (@iff_not_not (f x = g x)) ▸ (hforall1 x)\n      hneq (funext hforall))", "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/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847494, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.799928322384521}}
{"text": "import Mathlib.Tactic.LeftRight\n/-!\n# Advanced proposition world.\n\n## Level 6: Or, and the [`left` and `right` tactics](../Tactics/leftright.lean.md).\n\n`P ∨ Q` means \"`P` or `Q`\". So to prove it, you need to choose one of `P` or `Q`, and prove that\none. If `⊢ P ∨ Q` is your goal, then `left` changes this goal to `⊢ P`, and `right` changes it to `⊢ Q`.\nNote that you can take a wrong turn here. Let's start with trying to prove `Q ⟹ (P ∨ Q)`. After\nthe `intro`, one of `left` and `right` leads to an impossible goal, the other to an easy finish.\n\n## Lemma\nIf `P` and `Q` are true/false statements, then `Q ⟹(P ∨ Q).`\n-/\nexample (P Q : Prop) : Q → (P ∨ Q) := by\n  intro q\n  right\n  assumption\n\n/-!\n## Details\n\nThe tactics `left` and `right` work on a goal which is a type with\ntwo constructors, the classic example being `P ∨ Q`.\nTo prove `P ∨ 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## Pro Tip!\n\n\nDid you spot the `import Mathlib.Tactic.LeftRight`? What do you think it does?\n\nYou can make Mathlib available to your Lean package by adding the following\nto your `lakefile.lean`:\n```lean\nrequire mathlib from git\n  \"https://github.com/leanprover-community/mathlib4.git\" @ \"56b19bdec560037016e326795d0feaa23b402c20\"\n```\nThis specifies a precise version of mathlib4 by commit Id.\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/AdvancedPropositionWorld/Level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7999283174438339}}
{"text": "import .love02_backward_proofs_demo\n\n\n/- # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nbegin\n  intro ha,\n  exact ha\nend\n\nlemma K (a b : Prop) :\n  a → b → b :=\nbegin\n  intros ha hb,\n  exact hb\nend\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nbegin\n  intros hg hb ha,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha\nend\n\n/- Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha'\nend\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nbegin\n  intros hg ha hf hb,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\n/- 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nbegin\n  intros hab hnb ha,\n  apply hnb,\n  apply hab,\n  apply ha\nend\n\n/- 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    apply and.intro,\n    { intro x,\n      apply and.elim_left,\n      apply h },\n    { intro x,\n      apply and.elim_right,\n      apply h } },\n  { intros h x,\n    apply and.intro,\n    { apply and.elim_left h },\n    { apply and.elim_right h } }\nend\n\n\n/- ## Question 2: Natural Numbers\n\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, mul, ih] }\nend\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, add_succ, add_assoc, mul, ih] }\nend\n\n/- 2.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nbegin\n  induction' m,\n  { simp [mul, mul_zero] },\n  { simp [mul, mul_succ, ih],\n    cc }\nend\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nbegin\n  induction' n,\n  { refl },\n  { simp [mul, mul_add, ih] }\nend\n\n/- 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nbegin\n  rw mul_comm _ n,\n  rw mul_add\nend\n\n\n/- ## Question 3 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation :=\n∀a : Prop, (¬¬ a) → a\n\n/- For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, because this would defeat the purpose of the exercise.\n\n3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nbegin\n  rw excluded_middle,\n  rw peirce,\n  intro hem,\n  intros a b haba,\n  apply or.elim (hem a),\n  { intro,\n    assumption },\n  { intro hna,\n    apply haba,\n    intro ha,\n    apply false.elim,\n    apply hna,\n    assumption }\nend\n\n/- 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nbegin\n  rw peirce,\n  rw double_negation,\n  intros hpeirce a hnna,\n  apply hpeirce a false,\n  intro hna,\n  apply false.elim,\n  apply hnna,\n  exact hna\nend\n\n/- We leave the missing implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7998596572445951}}
{"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\n\n/-!\n# IMO 2005 Q3\nLet `x`, `y` and `z` be positive real numbers such that `xyz ≥ 1`. Prove that:\n`(x^5 - x^2)/(x^5 + y^2 + z^2) + (y^5 - y^2)/(y^5 + z^2 + x^2) + (z^5 - z^2)/(z^5 + x^2 + y^2) ≥ 0`\n\n# Solution\nThe solution by Iurie Boreico from Moldova is presented, which won a special prize during the exam.\nThe key insight is that `(x^5-x^2)/(x^5+y^2+z^2) ≥ (x^2-y*z)/(x^2+y^2+z^2)`, which is proven by\nfactoring `(x^5-x^2)/(x^5+y^2+z^2) - (x^5-x^2)/(x^3*(x^2+y^2+z^2))` into a non-negative expression\nand then making use of `xyz ≥ 1` to show `(x^5-x^2)/(x^3*(x^2+y^2+z^2)) ≥ (x^2-y*z)/(x^2+y^2+z^2)`.\n-/\n\nlemma key_insight (x y z : ℝ) (hx : x > 0) (hy : y > 0) (hz : z > 0) (h : x*y*z ≥ 1) :\n  (x^5-x^2)/(x^5+y^2+z^2) ≥ (x^2-y*z)/(x^2+y^2+z^2) :=\nbegin\n  have h₁ : 0 < x^5+y^2+z^2, linarith [pow_pos hx 5, pow_pos hy 2, pow_pos hz 2],\n  have h₂ : 0 < x^3, exact pow_pos hx 3,\n  have h₃ : 0 < x^2+y^2+z^2, linarith [pow_pos hx 2, pow_pos hy 2, pow_pos hz 2],\n  have h₄ : 0 < x^3*(x^2+y^2+z^2), exact mul_pos h₂ h₃,\n\n  have key : (x^5-x^2)/(x^5+y^2+z^2) - (x^5-x^2)/(x^3*(x^2+y^2+z^2))\n           = ((x^3 - 1)^2*x^2*(y^2 + z^2))/((x^5+y^2+z^2)*(x^3*(x^2+y^2+z^2))),\n  { field_simp [h₁.ne', h₄.ne'],\n    ring },\n\n  have h₅ : ((x^3 - 1)^2*x^2*(y^2 + z^2))/((x^5+y^2+z^2)*(x^3*(x^2+y^2+z^2))) ≥ 0,\n  { refine div_nonneg _ _,\n    refine mul_nonneg (mul_nonneg (sq_nonneg _) (sq_nonneg _)) _,\n    exact add_nonneg (sq_nonneg _) (sq_nonneg _),\n    exact le_of_lt (mul_pos h₁ h₄) },\n\n  calc  (x^5-x^2)/(x^5+y^2+z^2)\n      ≥ (x^5-x^2)/(x^3*(x^2+y^2+z^2)) : by linarith [key, h₅]\n  ... ≥ (x^5-x^2*(x*y*z))/(x^3*(x^2+y^2+z^2)) :\n        by { refine (div_le_div_right h₄).mpr _, simp,\n             exact (le_mul_iff_one_le_right (pow_pos hx 2)).mpr h }\n  ... = (x^2-y*z)/(x^2+y^2+z^2) :\n        by { field_simp [h₂.ne', h₃.ne'], ring },\nend\n\ntheorem imo2005_q3 (x y z : ℝ) (hx : x > 0) (hy : y > 0) (hz : z > 0) (h : x*y*z ≥ 1) :\n  (x^5-x^2)/(x^5+y^2+z^2) + (y^5-y^2)/(y^5+z^2+x^2) + (z^5-z^2)/(z^5+x^2+y^2) ≥ 0 :=\nbegin\n  calc  (x^5-x^2)/(x^5+y^2+z^2) + (y^5-y^2)/(y^5+z^2+x^2) + (z^5-z^2)/(z^5+x^2+y^2)\n      ≥ (x^2-y*z)/(x^2+y^2+z^2) + (y^2-z*x)/(y^2+z^2+x^2) + (z^2-x*y)/(z^2+x^2+y^2) :\n        by { linarith [key_insight x y z hx hy hz h,\n                       key_insight y z x hy hz hx (by linarith [h]),\n                       key_insight z x y hz hx hy (by linarith [h])] }\n  ... = 1/2*( (x-y)^2 + (y-z)^2 + (z-x)^2 ) / (x^2+y^2+z^2) :\n        by { have h₁ : y^2+z^2+x^2 = x^2+y^2+z^2, ring,\n             have h₂ : z^2+x^2+y^2 = x^2+y^2+z^2, ring,\n             rw [h₁, h₂], ring }\n  ... ≥ 0 :\n        by { exact div_nonneg\n                (by linarith [sq_nonneg (x-y), sq_nonneg (y-z), sq_nonneg (z-x)])\n                (by linarith [sq_nonneg x, sq_nonneg y, sq_nonneg z]) },\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/imo2005_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7998596505308523}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro p,\n  intro nop,\n  have boom: false := nop p,\n  exact boom,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro nnp,\n  by_cases h : P, --LEM\n  --P\n  exact h,\n  --¬P\n  have boom: false := nnp h,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P,\n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro pvq,\n  cases pvq with p q,\n  --Case P\n  right,\n  exact p,\n  --Case Q\n  left,\n  exact q,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro pandq,\n  split,\n  --Parte Q\n  cases pandq with p q,\n  exact q,\n  --Parte P\n  cases pandq with p q,\n  exact p,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro nopvq,\n  intro p,\n  cases nopvq with nop q,\n  --case noP\n  exfalso,\n  have boom: false := nop p,\n  contradiction,\n  --Case Q\n  exact q,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro pvq,\n  intro nop,\n  cases pvq with p q,\n  --Case P\n  exfalso,\n  have boom: false := nop p,\n  exact boom,\n  --Case Q\n  exact q,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro hpq,\n  intro noq,\n  intro p,\n  have q: Q := hpq p,\n  have boom: false := noq q,\n  exact boom,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro h,\n  intro hp,\n  by_contradiction hboom,\n  have hpp: ¬P := h hboom,\n  have hpboom: false := hpp hp,\n  exact hpboom,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  exact impl_as_contrapositive P Q,\n  exact impl_as_contrapositive_converse P Q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h,\n  have pvnp : P∨¬P,\n  right,\n  intro nop,\n  have pvq : P∨¬P,\n  left,\n  exact nop,\n  contradiction,\n  contradiction,\nend\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro h,\n  intro nop,\n  have pq : P → Q,\n  intro p,\n  contradiction,\n  have pp : P := h pq,\n  contradiction,\nend\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro h,\n  intro hnpnq,\n  cases hnpnq with hp hq,\n  cases h with hp hq,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro h,\n  intro hnpnq,\n  cases h with hp hq,\n  cases hnpnq with hp hq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro h,\n  split,\n  intro p,\n  have pvq: P∨Q,\n  left,\n  exact p,\n  contradiction,\n  intro q,\n  have pvq: P∨Q,\n  right,\n  exact q,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro h,\n  intro pvq,\n  cases pvq with p q,\n  cases h with np nq,\n  contradiction,\n  cases h with np nq,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h,\n  by_cases hq: Q,\n  right,\n  intro hp,\n  have pandq : (P∧Q),\n  split,\n  exact hp,\n  exact hq,\n  contradiction,\n  left,\n  exact hq,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro h,\n  intro hpandq,\n  cases hpandq with nq np,\n  cases h with noq nop,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n  exact demorgan_disj_converse P Q,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h,\n  cases h with p qvr,\n  cases qvr with q r,\n  left,\n  split,\n  exact p,\n  exact q,\n  right,\n  split,\n  exact p,\n  exact r,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h,\n  cases h with hl hr,\n  cases hl with p q,\n  split,\n  exact p,\n  left,\n  exact q,\n  cases hr with pp r,\n  split,\n  exact pp,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h,\n  cases h with p qandr,\n  split,\n  left,\n  exact p,\n  left,\n  exact p,\n  cases qandr with q r,\n  split,\n  right,\n  exact q,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  cases h with hl hr,\n  cases hl with p q,\n  left,\n  exact p,\n  cases hr with p r,\n  left,\n  exact p,\n  right,\n  split,\n  exact q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro h,\n  intro hp,\n  intro hq,\n  have pandq : P∧Q,\n  split,\n  exact hp,\n  exact hq,\n  apply h pandq,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro hpqr,\n  intro hpandq,\n  cases hpandq with p q,\n  apply hpqr p,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hp,\n  exact hp,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hp,\n  left,\n  exact hp,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hq,\n  right,\n  exact hq,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro h,\n  cases h with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro h,\n  cases h with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro hp,\n  cases hp with p pp,\n  exact p,\n  intro hpp,\n  split,\n  exact hpp,\n  exact hpp,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro h,\n  cases h with p pp,\n  exact p,\n  exact pp,\n  intro hp,\n  left,\n  exact hp,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro he,\n  intro x,\n  intro p,\n  apply he,\n  existsi x,\n  exact p,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro ha,\n  intro he,\n  cases he with t ht,\n  exact (ha t) ht,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  rw contrapositive_law,\n  rw doubleneg_law,\n  intro he,\n  intro a,\n  by_contradiction hboom,\n  apply he,\n  existsi a,\n  exact hboom,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro he,\n  intro ha,\n  cases he with t ht,\n  have pt : P t := ha t,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n  exact demorgan_forall_converse U P,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro he,\n  intro ha,\n  cases he with x he,\n  have nhp : ¬P x := ha x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro ha,\n  intro he,\n  cases he with x he,\n  have hp : P x := ha x,\n  contradiction, \nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro he,\n  intro x,\n  by_contradiction px,\n  apply he,\n  existsi x,\n  exact px,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  rw contrapositive_law,\n  intro he,\n  intro ha,\n  apply ha,\n  intro t,\n  intro pt,\n  apply he,\n  existsi t,\n  exact pt,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n  exact forall_as_neg_exists_converse U P,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with a ha,\n  cases ha with hp hq,\n  split,\n  --Parte P(x)\n  existsi a,\n  exact hp,\n  --Parte Q(x)\n  existsi a,\n  exact hq,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with a ha,\n  cases ha with Pa Qa,\n  left,\n  existsi a,\n  exact Pa,\n  right,\n  existsi a,\n  exact Qa,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  cases h with Pa Qa,\n  cases Pa with a ha,\n  existsi a,\n  left,\n  exact ha,\n  cases Qa with a ha,\n  existsi a,\n  right,\n  exact ha,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro h,\n  split,\n  intro a,\n  have ha : P a ∧ Q a := h a,\n  cases ha with hl hr,\n  exact hl,\n  intro a,\n  have ha : P a ∧ Q a := h a,\n  cases ha with hl hr,\n  exact hr,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro h,\n  intro a,\n  cases h with hl hr,\n  split,\n  have hp : P a := hl a,\n  exact hp,\n  have hq : Q a := hr a,\n  exact hq,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  intro a,\n  cases h with hl hr,\n  have hp : P a := hl a,\n  left,\n  exact hp,\n  have hq : Q a := hr a,\n  right,\n  exact hq,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "Cynder71", "repo": "fmclean", "sha": "6e9065fecd37066f0e3970bf0fc7180b47c16cdc", "save_path": "github-repos/lean/Cynder71-fmclean", "path": "github-repos/lean/Cynder71-fmclean/fmclean-6e9065fecd37066f0e3970bf0fc7180b47c16cdc/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7997628725362836}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intros p not_p,\n  exact not_p(p),\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro not_not_p,\n  by_contra not_p,\n  exact not_not_p(not_p),\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P,\n\n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro p_or_q,\n  cases p_or_q with p q,\n  right,\n  exact p,\n  left,\n  exact q,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro p_and_q,\n  cases p_and_q with p q,\n  split,\n  exact q,\n  exact p,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intros neg_p_or_q p,\n  cases neg_p_or_q with neg_p q,\n  exfalso,\n  exact neg_p(p),\n\n  exact q,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intros p_or_q not_p,\n  cases p_or_q with p q,\n  exfalso,\n  exact not_p(p),\n\n  exact q,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros p_imp_q not_q,\n  intro p,\n  have q := p_imp_q(p),\n  exact not_q(q),\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros not_q_imp_not_p p,\n  by_contra not_q,\n  have not_p := not_q_imp_not_p(not_q),\n  exact not_p(p),\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  exact impl_as_contrapositive P Q,\n\n  exact impl_as_contrapositive_converse P Q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h1,\n  apply h1,\n  right,\n  intro h2,\n  have p_or_not_p : (P ∨ ¬P),\n  left,\n  exact h2,\n\n  exact h1 p_or_not_p,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro h1,\n  intro not_p,\n  apply not_p,\n  apply h1,\n  intro p,\n  exfalso,\n  exact not_p p, \nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro p_or_q,\n  intro h1,\n  cases h1 with not_p not_q,\n  cases p_or_q with p q,\n  exact not_p p,\n\n  exact not_q q,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro p_and_q,\n  intro h1,\n  cases p_and_q with p q,\n  cases h1 with not_p not_q,\n  exact not_p p,\n\n  exact not_q q,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro h,\n  split,\n  intro p,\n  apply h,\n  left,\n  exact p,\n\n  intro q,\n  apply h,\n  right,\n  exact q,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro not_p_and_not_q,\n  intro p_or_q,\n  cases not_p_and_not_q with not_p not_q,\n  cases p_or_q with p q,\n  exact not_p p,\n  exact not_q q,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h,\n  by_contradiction hboom,\n  apply h,\n  split,\n  by_contradiction not_p,\n  apply hboom,\n  right,\n  exact not_p,\n  by_contradiction not_q,\n  apply hboom,\n  left,\n  exact not_q,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro not_q_or_not_p,\n  intro p_or_q,\n  cases not_q_or_not_p with not_q not_p,\n  cases p_or_q with p q,\n  exact not_q q,\n  \n  cases p_or_q with p q,\n  exact not_p p,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n\n  exact demorgan_disj_converse P Q,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h,\n  cases h with p q_or_r,\n  cases q_or_r with q r,\n  left,\n  split,\n  exact p,\n  exact q,\n\n  right,\n  split,\n  exact p,\n  exact r,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h,\n  cases h with p_and_q p_and_r,\n  cases p_and_q with p q,\n  split,\n  exact p,\n  \n  left,\n  exact q,\n  \n  cases p_and_r with p r,\n  split,\n  exact p,\n  \n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h,\n  split,\n  cases h with p q_and_r,\n  left,\n  exact p,\n\n  cases q_and_r with q r,\n  right,\n  exact q,\n\n  cases h with p q_and_r,\n  left,\n  exact p,\n\n  cases q_and_r with q r,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  cases h with p_or_q p_or_r,\n  cases p_or_r with p r,\n  left,\n  exact p,\n\n  cases p_or_q with p q,\n  left,\n  exact p,\n\n  right,\n  split,\n  exact q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros h p q,\n  apply h,\n  split,\n  exact p,\n  exact q,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros h p_and_q,\n  apply h,\n  exact p_and_q.left,\n\n  exact p_and_q.right,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro p_and_q,\n  exact p_and_q.left,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro p_and_q,\n  exact p_and_q.right,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro p_and_p,\n  exact p_and_p.left,\n\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro p_or_p,\n  cases p_or_p with p p,\n  exact p,\n\n  exact p,\n\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro h,\n  intro u,\n  intro p_u,\n  apply h,\n  existsi u,\n  exact p_u,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro h1,\n  intro h2,\n  cases h2 with u hu,\n  exact h1 u hu,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro h,\n  by_contradiction hboom,\n  apply h,\n  intro u,\n  by_contradiction hboom2,\n  apply hboom,\n  existsi u,\n  exact hboom2,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro h,\n  intro f,\n  cases h with u hu,\n  have p_u := f u,\n  exact hu p_u,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n\n  exact demorgan_forall_converse U P,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro h1,\n  intro h2,\n  cases h1 with u p_u,\n  have neg_p_u := h2 u,\n  exact neg_p_u p_u,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro h1,\n  intro h2,\n  cases h2 with u neg_p_u,\n  have p_u := h1 u,\n  exact neg_p_u p_u,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro h1,\n  intro u,\n  by_contradiction hboom,\n  apply h1,\n  existsi u,\n  exact hboom,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro h1,\n  by_contradiction h2,\n  apply h1,\n  intro u,\n  intro p_u,\n  apply h2,\n  existsi u,\n  exact p_u,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n\n  exact forall_as_neg_exists_converse U P,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with  u hu,\n  cases hu with p_u q_u,\n  split,\n  existsi u,\n  exact p_u,\n\n  existsi u,\n  exact q_u,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with u hu,\n  cases hu with p_u q_u,\n  left,\n  existsi u,\n  exact p_u,\n\n  right,\n  existsi u,\n  exact q_u,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  cases h with ex_u_pu ex_u_qu,\n  cases ex_u_pu with u pu,\n  existsi u,\n  left,\n  exact pu,\n\n  cases ex_u_qu with u qu,\n  existsi u,\n  right,\n  exact qu,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro h,\n  split,\n  intro u,\n  have p_u_and_q_u := h u,\n  cases p_u_and_q_u with p_u q_u,\n  exact p_u,\n\n  intro u,\n  have p_u_and_q_u := h u,\n  cases p_u_and_q_u with p_u q_u,\n  exact q_u,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro h,\n  intro u,\n  cases h with p_x q_x,\n  have p_u := p_x u,\n  have q_u := q_x u,\n  split,\n  exact p_u,\n\n  exact q_u,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  intro u,\n  cases h with forall_p_x forall_q_x,\n  have p_u := forall_p_x u,\n  left,\n  exact p_u,\n\n  have q_u := forall_q_x u,\n  right,\n  exact q_u,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "igorvicentels", "repo": "fmclean", "sha": "1595e2511fdde800020ce8cd4c0ed5e767369243", "save_path": "github-repos/lean/igorvicentels-fmclean", "path": "github-repos/lean/igorvicentels-fmclean/fmclean-1595e2511fdde800020ce8cd4c0ed5e767369243/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7997031745542461}}
{"text": "-- Tactics are commands or instructions that describe how to build a proof.\n-- Tactics are easier and shorter to write \n\ntheorem test (p q : Prop) (hp : p) (hq : q) :\np ∧ q ∧ p := \nbegin \n apply and.intro,\n apply hp,\n apply and.intro,\n apply hq,\n apply hp\nend \n\n#print test\n\nexample (p q r : Prop) :\np ∧ (q ∨ r) <-> (p ∧ q) ∨ (p ∧ 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 h',\n apply or.inr,\n apply and.intro,\n apply and.left h,\n exact h',\n intro h'',\n apply or.elim h'',\n intro h2,\n apply and.intro,\n apply and.left h2,\n apply or.inl,\n apply and.right h2,\n intro h3,\n apply and.intro,\n apply and.left h3,\n apply or.inr,\n apply and.right h3,\nend \n\nexample (α : Type) : α -> α :=\nbegin \n intro a,\n exact a\nend\n\nexample (α : Type) : ∀ x : α, x = x :=\nbegin\n intro x,\n apply eq.refl x\nend \n\nexample : ∃ a : ℕ, 5 = a :=\nbegin \n apply exists.intro,\n reflexivity\nend\n\nexample : ∃ a : ℕ, a = a :=\nbegin \n fapply exists.intro,\n exact 1,\n reflexivity\nend\n\nexample (x : ℕ) : x = x :=\nbegin\n revert x,\n intro y,\n reflexivity\nend \n\nexample (x y : ℕ) (h : x = y) : y = x :=\nbegin \n symmetry,\n assumption\nend \n\nexample : 3 = 3 :=\nbegin\nreflexivity\nend\n\nexample (p q : Prop) : p ∨ q -> q ∨ p :=\nbegin\n intro h,\n cases h with hp hq, \n right,\n exact hp,\n left,\n exact hq\nend \n\nexample (p q : ℕ -> Prop) : (∃ x, p x) -> ∃ x, p x ∨ q x :=\nbegin \nintro h,\ncases h with x px,\nexistsi x,\nleft,\nexact px\nend \n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ 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\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n  intros,\n  apply eq.trans,\n  apply eq.symm,\n  assumption,\n  assumption\nend\n\nexample (y : ℕ) : (λ x : ℕ, 0) y = 0 :=\nbegin\n  refl\nend\n\nexample (x : ℕ) : x ≤ x :=\nbegin\n  refl\nend\n\nexample : ∃ a : ℕ, 5 = a :=\nbegin\n  apply exists.intro,\n  reflexivity\nend\n\nexample : ∃ a : ℕ, a = a :=\nbegin\n  fapply exists.intro,\n  exact 0,\n  reflexivity\nend\n\nexample (x : ℕ) : x = x :=\nbegin\n  revert x,\n  -- goal is ⊢ ∀ (x : ℕ), x = x\n  intro y,\n  -- goal is y : ℕ ⊢ y = y\n  reflexivity\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  apply iff.intro,\n  intro h,\n   cases h with hp hqr,\n   cases hqr with hq hr,\n     left, constructor, repeat { assumption },\n     right, constructor, repeat { assumption },\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\nend\n\nexample (p q : ℕ → Prop) : (∃ x, p x) → ∃ x, p x ∨ q x :=\nbegin \n intro h,\n cases h with x px,\n constructor, left, exact px\nend\n\nexample (p q : ℕ → Prop) : (∃ x, p x) → ∃ x, p x ∨ q x :=\nbegin \n intro h,\n cases h with x px,\n constructor, left, assumption\nend \n\nexample (p q : ℕ → Prop) :\n  (∃ x, p x ∧ q x) → ∃ x, q x ∧ p x :=\nbegin \n  intro h,\n  cases h with x hpq,\n  cases hpq with hp hq,\n  existsi x,\n  split; assumption\nend\n\nuniverses u v\ndef swap_pair {α : Type u} {β : Type v} : α × β → β × α :=\nbegin\nintro h,\ncases h with ha hb,\nconstructor, assumption,\nassumption\nend\n\ndef swap_sum {α : Type u} {β : Type v} : α ⊕ β → β ⊕ α :=\nbegin\nintro h,\ncases h with ha hb,\nright, assumption,\nleft, assumption\nend\n\nopen nat\nexample (P : ℕ → Prop) (h₀ : P 0) (h₁ : ∀ n, P (succ n)) (m : ℕ) :\n  P m :=\nbegin \n  cases m with m', exact h₀, exact h₁ m'\nend \n\nexample (p q : Prop) : p ∧ ¬ p → q :=\nbegin\n  intro h, cases h, contradiction\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  intro h,\n  exact\n    have hp : p, from h.left,\n    have hqr : q ∨ r, from h.right,\n    show (p ∧ q) ∨ (p ∧ r),\n    begin\n      cases hqr with hq hr,\n        exact or.inl ⟨hp, hq⟩,\n      exact or.inr ⟨hp, hr⟩\n    end\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n apply iff.intro,\n intro h, \n cases h.right with hq hr,\n apply or.inl,\n apply and.intro,\n apply and.left h,\n assumption,\n exact or.inr ⟨h.left, hr⟩,\n intro h,\n cases h with hpq hpr,\n exact ⟨hpq.left, or.inl hpq.right⟩,\n  exact ⟨hpr.left, or.inr hpr.right⟩\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h.right with hq hr,\n      show (p ∧ q) ∨ (p ∧ r),\n        { left, split, exact h.left, assumption },\n      show (p ∧ q) ∨ (p ∧ r),\n        { right, split, exact h.left, assumption },\n  intro h,\n  cases h with hpq hpr,\n    show p ∧ (q ∨ r),\n      { cases hpq, split, assumption, left, assumption },\n    show p ∧ (q ∨ r),\n      { cases hpr, split, assumption, right, assumption }\nend\n\nexample (n : ℕ) : n + 1 = nat.succ n :=\nbegin\n  show nat.succ n = nat.succ n,\n  reflexivity\nend\n\nexample (p q : Prop) : p ∧ q → q ∧ p :=\nbegin\n  intro h,\n  cases h with hp hq,\n  split,\n  assumption,\n  assumption\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  apply iff.intro,\n  begin\n    intro h,\n    cases h.right with hq hr,\n    begin\n      show (p ∧ q) ∨ (p ∧ r),\n        exact or.inl ⟨h.left, hq⟩\n    end,\n    show (p ∧ q) ∨ (p ∧ r),\n      exact or.inr ⟨h.left, hr⟩\n  end,\n  intro h,\n  cases h with hpq hpr,\n  begin\n    show p ∧ (q ∨ r),\n      exact ⟨hpq.left, or.inl hpq.right⟩\n  end,\n  show p ∧ (q ∨ r),\n    exact ⟨hpr.left, or.inr hpr.right⟩\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases h.right with hq hr,\n    { show (p ∧ q) ∨ (p ∧ r),\n        exact or.inl ⟨h.left, hq⟩ },\n    show (p ∧ q) ∨ (p ∧ r),\n      exact or.inr ⟨h.left, hr⟩ },\n  intro h,\n  cases h with hpq hpr,\n  { show p ∧ (q ∨ r),\n      exact ⟨hpq.left, or.inl hpq.right⟩ },\n  show p ∧ (q ∨ r),\n    exact ⟨hpr.left, or.inr hpr.right⟩\nend\n\nexample (p q : Prop) (hp : p) : p ∨ q :=\nbegin left, assumption end\n\nexample (p q : Prop) (hp : p) : p ∨ q :=\nby { left, assumption }\n\nexample (p q : Prop) (hp : p) (hq : q) : p ∧ q :=\nby split; assumption\n\nexample (p q : Prop) (hp : p) : p ∨ q :=\nby { left, assumption } <|> { right, assumption}\n\nmeta def my_tac : tactic unit :=\n`[ repeat { {left, assumption} <|> right <|> assumption } ]\n\nexample (p q r : Prop) (hp : p) : p ∨ q ∨ r :=\nby my_tac\n\nexample (p q r : Prop) (hq : q) : p ∨ q ∨ r :=\nby my_tac\n\nexample (p q r : Prop) (hr : r) : p ∨ q ∨ r :=\nby my_tac\n\nexample (p q r : Prop) : p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  intro h,\n  cases h with hp hqr,\n  show (p ∧ q) ∨ (p ∧ r),\n  cases hqr with hq hr,\n    have hpq : p ∧ q,\n      from and.intro hp hq,\n    left, exact hpq,\n  have hpr : p ∧ r,\n    from and.intro hp hr,\n  right, exact hpr\nend\n\nexample : ∃ x, x + 2 = 8 :=\nbegin\n  let a : ℕ := 3 * 2,\n  existsi a,\n  reflexivity\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  intro h,\n  have hp : p := h.left,\n  have hqr : q ∨ r := h.right,\n  show (p ∧ q) ∨ (p ∧ r),\n  cases hqr with hq hr,\n    exact or.inl ⟨hp, hq⟩,\n  exact or.inr ⟨hp, hr⟩\nend\n\n\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h.right with hq hr,\n      show (p ∧ q) ∨ (p ∧ r),\n        from or.inl ⟨h.left, hq⟩,\n      show (p ∧ q) ∨ (p ∧ r),\n        from or.inr ⟨h.left, hr⟩,\n  intro h,\n  cases h with hpq hpr,\n    show p ∧ (q ∨ r),\n      from ⟨hpq.left, or.inl hpq.right⟩,\n    show p ∧ (q ∨ r),\n      from ⟨hpr.left, or.inr hpr.right⟩\nend\n", "meta": {"author": "swarnpriya", "repo": "Lean", "sha": "a0a9978fd058041eb1a09aec0e2dd7d19a7436a7", "save_path": "github-repos/lean/swarnpriya-Lean", "path": "github-repos/lean/swarnpriya-Lean/Lean-a0a9978fd058041eb1a09aec0e2dd7d19a7436a7/tactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.9149009561531424, "lm_q1q2_score": 0.7996941042062017}}
{"text": "import Mathlib\n/-!\n# Examples of Proofs\n\nWe see our next proofs, most of which involve the `≤` relation on natural numbers. \n\nWe will see that the natural numbers are \"defined\" in terms of the `zero` and `succ` constructors.\n\n* `Nat.zero : ℕ` \n* `Nat.succ : ℕ → ℕ`\n\nAnalogous to this, (modulo renaming) the `≤` relation is defined in terms of the `le_refl` and `le_step` constructors.\n\n* `Nat.le : ℕ → ℕ → Prop`\n* `Nat.le_refl : ∀ n : ℕ, n ≤ n`\n* `Nat.le_step : ∀ {n m : ℕ}, n ≤ m → n ≤ Nat.succ m`\n-/\n\n\n#check Nat.zero -- Nat.zero : ℕ\n#check Nat.succ -- Nat.succ : ℕ → ℕ\n\n#check Nat.le -- Nat.le : ℕ → ℕ → Prop\n#check Nat.le_step -- Nat.le_step : ∀ {n m : ℕ}, n ≤ m → n ≤ Nat.succ m\n#check Nat.le_refl -- Nat.le_refl : ∀ n : ℕ, n ≤ n\n\n/-!\nThe first proof we see is of `3 ≤  3`. This is a direct application of `Nat.le_refl`. This is analogous to applying `Nat.le_refl` as a function to the argument `3`.\n\n```lean\ntheorem three_le_three : 3 ≤ 3 :=\n  Nat.le_refl 3\n```\n\nOur second result is similar and has a similar proof. \nHowever in the proof we did not specify the argument `4`\nand instead used the *placeholder* `_`. Lean deduced that \nthe unique way to get types correct is to fill in `4`.\n\n```lean\n/-- The result `4 ≤ 4`. -/\ndef four_le_four : 4 ≤ 4 :=\n  Nat.le_refl _\n```\n-/\n\n/-- The result `3 ≤ 3`. -/\ntheorem three_le_three : 3 ≤ 3 :=\n  Nat.le_refl 3\n\n/-- The result `4 ≤ 4`. -/\ndef four_le_four : 4 ≤ 4 :=\n  Nat.le_refl _\n\n#eval Nat.succ 0\n\n-- #eval succ 0\n\nopen Nat in\n#eval succ 0\n\n#check le_refl\n\n/-!\nSome more complex proofs. In the first case the proof is given fully while in the second we allow a parameter to be inferred\n\n```lean\ntheorem three_le_five : 3 ≤ 5 :=\n  Nat.le_step (Nat.le_step (Nat.le_refl 3))\n\ntheorem three_le_six : 3 ≤ 6 :=\n  Nat.le_step (\n    Nat.le_step \n     (Nat.le_step (Nat.le_refl _))) \n```\n-/\n\ntheorem three_le_five : 3 ≤ 5 :=\n  Nat.le_step (Nat.le_step (Nat.le_refl 3))\n\ntheorem three_le_six : 3 ≤ 6 :=\n  Nat.le_step (\n    Nat.le_step \n     (Nat.le_step (Nat.le_refl _))) \n\n/-!\nIn the next proof we use tactics, specifically the `apply`\ntactic. We also see a case where it fails.\n\n```lean\ntheorem four_le_seven : 4 ≤ 7 := by\n  apply Nat.le_step\n  -- apply Nat.le_refl \n  /-tactic 'apply' failed, failed to unify\n  ?n ≤ ?n\n    with\n  4 ≤ 6-/ \n  apply Nat.le_step\n  apply Nat.le_step\n  apply Nat.le_refl\n```\n\n-/\n\n\ntheorem four_le_seven : 4 ≤ 7 := by\n  apply Nat.le_step\n  -- apply Nat.le_refl \n  /-tactic 'apply' failed, failed to unify\n  ?n ≤ ?n\n    with\n  4 ≤ 6-/ \n  apply Nat.le_step\n  apply Nat.le_step\n  apply Nat.le_refl\n\n/-!\nNote that the proofs produced by tactics are proofs in the usual sense.\n\n```lean\n#print four_le_seven /- theorem four_le_seven : 4 ≤ 7 :=\n Nat.le_step (Nat.le_step (Nat.le_step (Nat.le_refl 4))) -/\n```\n-/\n\n#print four_le_seven -- theorem four_le_seven : 4 ≤ 7 :=\n-- Nat.le_step (Nat.le_step (Nat.le_step (Nat.le_refl 4)))\n\n/-!\nLean has many powerful tactics. The `decide` tactic can prove propositions that (are true and) can be decided by\nan algorithm corresponding to the `Decidable` typeclass (which we see later).\n\n```lean\ntheorem four_le_ten : 4 ≤ 10 :=\n  by decide\n```\n\nThe proof produced by the `decide` tacic is similar to the above proofs.\n```lean\ndef four_le_ten' : 4 ≤ 10 :=\n  by decide\n\n\n#reduce four_le_ten' /- Nat.le.step (Nat.le.step (Nat.le.step (Nat.le.step (Nat.le.step (Nat.le.step Nat.le.refl)))))\n-/\n```\n-/\n\ntheorem four_le_ten : 4 ≤ 10 :=\n  by decide\n\ndef four_le_ten' : 4 ≤ 10 :=\n  by decide\n\n\n#reduce four_le_ten' /- Nat.le.step (Nat.le.step (Nat.le.step (Nat.le.step (Nat.le.step (Nat.le.step Nat.le.refl)))))\n-/\n\n/-!\nWe can combine tactics. `repeat` applies a tactic as long as it is valid; `first` applies the first applicable tactic.\n\n```lean\nexample : 4 ≤ 10 :=\n  by\n    -- repeat (apply Nat.le_step) -- goal: 4 ≤ 0\n    repeat (first | \n          apply Nat.le_refl | \n          apply Nat.le_step)\n    done\n```\n-/\nexample : 4 ≤ 10 :=\n  by\n    -- repeat (apply Nat.le_step) -- goal: 4 ≤ 0\n    repeat (first | \n          apply Nat.le_refl | \n          apply Nat.le_step)\n    done\n\nexample : 3 ≤ 6 := by\n  apply Nat.le_step\n  apply three_le_five\n\n/-! We will write some basic tactics\n-/\n\n/-- A tactic for proving `≤` for natural numbers -/\nmacro \"nat_le\" : tactic =>\n  `(tactic| repeat (first | \n          apply Nat.le_refl | \n          apply Nat.le_step))\n\nexample : 3 ≤ 33 := by nat_le\n\n/-- A tactic where we try repeatedly to finish with a theorem or take a step with another. -/\nmacro \"finish_with\" x:term \n  \"steps\" y:term : tactic => do\n  `(tactic| repeat (first | \n          apply ($x:term) | \n          apply $y))\n\n/-! \nWe can use our more general tactic in different ways.\n\n```lean\nexample : 4 ≤ 44 := by\n  finish_with Nat.le_refl steps Nat.le_step\n\n#check Nat.succ_le_succ -- ∀ {n m : ℕ}, n ≤ m → Nat.succ n ≤ Nat.succ m\n#check Nat.zero_le -- ∀ (n : ℕ), 0 ≤ n\n\nexample : 4 ≤ 44 := by\n  finish_with Nat.zero_le steps Nat.succ_le_succ\n```\n-/\n\nexample : 4 ≤ 44 := by\n  finish_with Nat.le_refl steps Nat.le_step\n\n#check Nat.succ_le_succ -- ∀ {n m : ℕ}, n ≤ m → Nat.succ n ≤ Nat.succ m\n#check Nat.zero_le -- ∀ (n : ℕ), 0 ≤ n\n\nexample : 4 ≤ 44 := by\n  finish_with Nat.zero_le steps Nat.succ_le_succ\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_11/NatLe.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789547, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7996441774091955}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport tactic\nimport group_theory.subgroup.basic -- importamos subgrupos de mathlib\n\n/-!\n# Subggrupos y homomorfismos\n\nPara practicar el uso de lemas de la librería, crearemos nuestra propia definición de subgrupo,\ny demostraremos lemas sobre ella utilizando la API de grupos de mathlib.\n\nDespués demostraremos lemas sobre homomorfismos de grupo (para ello, pasaremos a utilizar la \ndefinición de subgrupo disponible en mathlib). -/\n\n/-- `subgrupo G` es el tipo de subgrupos de un grupo `G`. -/\n@[ext] structure subgrupo (G : Type) [group G] :=\n(carrier : set G) -- `carrier` es un subconjunto de `G`\n(one_mem' : (1 : G) ∈ carrier) \n-- después añadiremos otra versión `one_mem` de este axioma sin nombrar el `carrier`\n(mul_mem' {x y} : x ∈ carrier → y ∈ carrier → x * y ∈ carrier) -- también `mul_mem`\n(inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier) -- también `inv_mem`\n\n/- NOTA: no queremos que `subgrupo` sea una clase, ya que `G` puede tener múltiples subgrupos. -/\n\n/- Gracias a la etiqueta `@[ext]`, la táctica `ext` funciona sobre subgrupos y nos permite \n  reemplazar una igualdad de subgrupos `H₁ = H₂` por `∀ g, g ∈ H₁ ↔ g ∈ H₂`. -/\n\nnamespace subgrupo\n\n-- Sea G un grupo y H un subgrupo de G\nvariables {G : Type} [group G] (H : subgrupo G)\n\n/-- Esta instancia nos permite hablar de elementos de un subgrupo, y utilizar la notación `x ∈ H`\n  para ello. -/\ninstance : has_mem G (subgrupo G) :=\n{ mem := λ m H, m ∈ H.carrier }\n\n/-- Esta instancia nos permite interpretar un `H : subgrupo G` como un conjunto `H : set G`. -/\ninstance : has_coe (subgrupo G) (set G) := \n{ coe := λ H, H.carrier }\n\n/-- `g` es un elemento de `H` considerado como suconjunto de `G`, si y sólo si `g` es un\nelemento del sugrupo `H` de `G`. -/\n@[simp] lemma mem_coe {g : G} : g ∈ (H : set G) ↔ g ∈ H :=\nbegin\n  -- These two concepts just mean the same thing\n  refl\nend\n\n/-- Añadimos otro lemma de extensionalidad: dos subgrupos de un grupo son iguales si tienen\n  los mismos elementos.-/\n@[ext] def ext' (H K : subgrupo G) (h : ∀ g : G, g ∈ H ↔ g ∈ K) : H = K :=\nbegin\n  ext x,\n  exact h x,\nend\n\ntheorem one_mem : (1 : G) ∈ H :=\nbegin\n  apply H.one_mem',\nend\n\ntheorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H :=\nbegin\n  apply H.mul_mem',\nend\n\ntheorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H :=\nbegin\n  apply H.inv_mem',\nend\n\n/- ## Ejercicios sobre subgrupos\nEn esta sección hay una lista de teoremas sobre subgrupos. Para demostrarlos, tendréis que \nusar los tres lemas anteriores, así como resultados sobre grupos disponibles en mathlib.\n\nSi `H : subgrupo G`, y `x y : G`, los lemas anteriores dicen:\n`H.one_mem : (1 : G) ∈ H`\n`H.mul_mem : x ∈ H → y ∈ H → x * y ∈ H`\n`H.inv_mem : x ∈ H → x⁻¹ ∈ H`\n-/\n\n@[simp] theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := \nbegin\n  sorry\nend\n\ntheorem mul_mem_cancel_left {x y : G} (hx : x ∈ H) :\n  x * y ∈ H ↔ y ∈ H :=\nbegin\n  sorry\nend\n\ntheorem mul_mem_cancel_right {x y : G} (hx : x ∈ H) :\n  y * x ∈ H ↔ y ∈ H :=\nbegin\n  sorry\nend\n\n/-- `conjugate H g` es el subgrupo conjugado `gHg⁻¹` de `H`. -/\ndef conjugate (H : subgrupo G) (g : G) : subgrupo G :=\n{ carrier := { a : G | ∃ h ∈ H, a = g * h * g⁻¹ },\n  one_mem' := begin \n    simp only [exists_prop, set.mem_set_of_eq], \n    sorry\n  end,\n  inv_mem' := begin \n    sorry\n  end,\n  mul_mem' := begin \n    sorry\n  end,\n}\n\n/-- Definición de abeliano. -/\ndef is_abelian (G : Type) [group G] : Prop :=\n∀ a b : G, a * b = b * a\n\n/-- Un subgrupo es normal si y sólo si es igual a todos sus conjugados. -/\ndef is_normal {G : Type} [group G] (H : subgrupo G) : Prop :=\n∀ g : G, conjugate H g = H\n\n/-- Si G es abeliano, todos sus subgrupos son normales. -/\nexample (h_ab : is_abelian G) (H : subgrupo G) : is_normal H :=\nbegin\n  sorry\nend\n\nend subgrupo\n\n/-\n# Homomorfismos de grupos\nCreamos el tipo `hom_grupos G H` de homomorfismos de grupos de `G` a `H`, y la notación `G →** H`,\nes decir, `f : G →** H` indica que `f` es un homomorfismo de grupos de`G` a `H`\".\n-/\n\n/-- `hom_grupos G H` es el tipo de homomorfismos de grupos de `G` a `H`. -/\n@[ext] structure hom_grupos (G H : Type) [group G] [group H] :=\n(to_fun : G → H)\n(map_mul' (a b : G) : to_fun (a * b) = to_fun a * to_fun b)\n\nnamespace hom_grupos\n\n-- `G` y `H` son grupos\nvariables {G H : Type} [group G] [group H]\n\n-- Fijamos la notación.\nnotation G ` →** ` H := hom_grupos G H\n\n/-- Esta instancia nos permite ver un homomorfismo de grupos como una función.  -/\ninstance : has_coe_to_fun (G →** H) (λ _, G → H) :=\n{ coe := hom_grupos.to_fun }\n\n/- la instancia anterior nos permite escribir `f (a)` -/\nlemma map_mul (f : G →** H) (a b : G) : \n  f (a * b) = f a * f b :=\nbegin\n  -- `f.map_mul` y `f.map_mul'` son *definicionalmente iguales*, pero *sintácticamente distintos*.\n  exact f.map_mul' a b\nend\n\n/- ## Ejercicios sobre homomorfismos de grupos -/\n\n-- Sea `f` un homomorfismo de grupos\nvariable (f : G →** H)\n\n-- El siguiente comentario nos indica un lema ↑til para probar `map_one`.\n-- example (a b : G) : a * b = b ↔ a = 1 := by library_search \n@[simp] lemma map_one : f 1 = 1 :=\nbegin\n  sorry\nend\n\nlemma map_inv (a : G) : f a⁻¹ = (f a)⁻¹ :=\nbegin\n  sorry\nend\n\nvariable (G)\n\n/-- `id G` es el homomorfismo identidad de `G` a `G`. -/\ndef id : G →** G :=\n{ to_fun   := λ a, a,\n  map_mul' := begin \n    sorry\n  end } \n\nvariables {K : Type} [group K] {G}\n\n/-- `φ.comp ψ` es la composición de `φ` y `ψ`. -/\ndef comp (φ : G →** H) (ψ : H →** K) : G →** K :=\n{ to_fun := λ g, ψ (φ g),\n  map_mul' := λ a b, begin \n    sorry, \n  end \n}\nlemma id_comp : (id G).comp f = f :=\nbegin\n  sorry,\nend\n\nlemma comp_id : f.comp (id H) = f :=\nbegin\n  sorry,\nend\n\nlemma comp_assoc {L : Type} [group L] (φ : G →** H) (ψ : H →** K) (ρ : K →** L) :\n  (φ.comp ψ).comp ρ = φ.comp (ψ.comp ρ) :=\nbegin\n  sorry,\nend\n\n/-- El kernel de un homomorfismo de grupos, como subgrupo del dominio. -/\ndef ker (f : G →** H) : subgroup G :=\n{ carrier := {g : G | f g = 1 },\n  one_mem' := begin sorry, end,\n  mul_mem' := begin \n    sorry,\n  end,\n  inv_mem' := begin \n    sorry,\n  end,\n}\n\n/-- La imagen de un homomorfismo de grupos, como subgrupo del codominio. -/\ndef im (f : G →** H) : subgroup H :=\n{ carrier := {h : H | ∃ g : G, f g = h },\n  one_mem' := begin \n    sorry,\n  end,\n  mul_mem' :=  begin \n    sorry,\n  end,\n  inv_mem' := begin \n    sorry,\n  end,\n}\n\n/-- La imagen de un subgrupo bajo un homomorfismo de grupos, como subgrupo del codominio. -/\ndef map (f : G →** H) (K : subgroup G) : subgroup H :=\n{ carrier := {h : H | ∃ g : G, g ∈ K ∧ f g = h },\n  one_mem' := begin \n    sorry,\n  end,\n  mul_mem' := begin\n    sorry,\n  end,\n  inv_mem' := begin\n    sorry,\n  end,\n}\n\n/-- La preimagen de un subgrupo bajo un homomorfismo de grupos, como subgrupo del dominio. -/\ndef comap (f : G →** H) (K : subgroup H) : subgroup G :=\n{ carrier := {g : G | f g ∈ K },\n  one_mem' := begin \n    sorry,\n  end,\n  mul_mem' := begin \n    sorry,\n  end,\n  inv_mem' := begin\n    sorry,\n  end,\n}\n\nend hom_grupos\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_3/grupos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.7995897585640408}}
{"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\" (`¬`)\n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# The definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → false`. So `¬ P` and `P → false`\nare *definitionally equal*. Check out the explanation of definitional\nequality in the \"equality\" section of Part B of the course notes:\nhttps://www.ma.imperial.ac.uk/~buzzard/xena/formalising-mathematics-2023/Part_B/equality.html\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 : ¬ true → false :=\nbegin\n  intro hT,\n  apply hT,\n  triv,\nend\n\n-- using the proof of true\nexample : ¬ true → false :=\nbegin\n  intro hT,\n  exact hT true.intro,\nend\n\nexample : false → ¬ true :=\nbegin\n  intros hF _,\n  exact hF,\nend\n\nexample : ¬ false → true :=\nbegin\n  intro _,\n  triv,\nend\n\nexample : true → ¬ false :=\nbegin\n  intros _ hF,\n  exact hF,\nend\n\nexample : false → ¬ P :=\nbegin\n  intros hF _,\n  exact hF,\nend\n\nexample : P → ¬ P → false :=\nbegin\n  intros hP hNP,\n  exact hNP hP,\nend\n\nexample : P → ¬ (¬ P) :=\nbegin\n  intros hP hPF,\n  exact hPF hP,\nend\n\nexample : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  intros hPQ hQF hP,\n  exact hQF (hPQ hP),\nend\n\n-- TODO: what the what kinda proof is this\nexample : ¬ ¬ false → false :=\nbegin\n  intro hF,\n  apply hF,\n  intro hF1,\n  exact hF1,\nend\n\nexample : ¬ ¬ P → P :=\nbegin\n  intro hPFF,\n  by_contra,\n  exact hPFF h,\nend\n\n-- using the proof above\nexample : ¬ ¬ false → false :=\nbegin\n  intro hF,\n  by_contra,\n  exact hF h,\nend\n\nexample : (¬ Q → ¬ P) → (P → Q) :=\nbegin\n  intros hNQP hP,\n  by_contra hQ,\n  exact hNQP hQ hP,\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/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.7995897525444036}}
{"text": "import Mathlib.Tactic.Basic\nimport Mathlib.Tactic.Cases\nimport Basics.FunctionDefinitions\nnamespace hglv\n/-!\n## Proofs by Mathematical Induction\n\nThe `induction'` tactic performs structural induction on an inductive type. _Structural induction_\nsimply means that the induction follows the structure of the inductive type. For natural numbers\nconstructed from `Nat.zero` and `Nat.succ`, structural induction corresponds to standard mathematical\ninduction: To prove `p n`, it suffices to prove `p 0` and `∀k, p k → p (k + 1)`. Equipped with `induction'`,\nwe can reason about the addition and multiplication operations we defined by recursion in\n[Function Definitions](../Basics/FunctionDefinitions.lean.md). Addition is defined by recursion on its\nsecond argument. We will prove two lemmas, `add_zero` and `add_succ`, that give us alternative equations\nthat recurse on the first argument. We start with `add_zero`:\n-/\nlemma add_zero (n : ℕ) :\nadd 0 n = n := by\n  induction' n with n ih\n  { rfl }\n  { simp [add, ih] }\n\n/-!\nThe first `{ }` encloses the base case `⊢ add 0 0 = 0`. The second block corresponds\nto the induction step\n```lean\nn : N, ih : add 0 n = n ` add 0 (Nat.succ n) = (Nat.succ n)\n```\nThe local variable `n` in the induction step should not be confused with the `n` in\nthe lemma statement. Like mathematicians, `induction’` tries to reuse variable\nnames that are no longer needed. The name `ih` for the induction hypothesis, in\nthe induction step, is also generated by the `induction’` tactic.\n\nWe can keep on proving lemmas by structural induction:\n-/\n\nlemma add_succ (m n : ℕ) :\n  add (Nat.succ m) n = Nat.succ (add m n) := by\n  induction' n with n ih\n  { rfl }\n  { simp [add, ih] }\n\nlemma add_comm (m n : ℕ) :\n  add m n = add n m := by\n  induction' n with n ih\n  { simp [add, add_zero] }\n  { simp [add, add_succ, ih] }\n\nlemma add_assoc (l m n : ℕ) :\n  add (add l m) n = add l (add m n) := by\n  induction' n with n ih -- ih: add (add l m) n = add l (add m n)\n  { rfl }\n  { simp [add, ih] }\n\n/-!\nOnce we have proved that a binary operator is commutative and associative, it\nis a good idea to let Lean’s automation, notably `cc`, know about this\nusing type classes.  See [Type Classes](../Basics/TypeClasses.lean.md).\n\nThe following example uses the `cc` tactic to reason up to associativity and commutativity of `add`:\n-/\nset_option trace.Meta.Tactic.simp.rewrite true\nlemma mul_add (l m n : ℕ) :\nmul l (add m n) = add (mul l m) (mul l n) := by\n  induction' n with n ih -- ih: mul l (add m n) = add (mul l m) (mul l n)\n  { rfl }\n  {\n    simp [add_comm, add_assoc, add_succ]\n  }\n/-!\n-- BUGBUG: 'cc' is still missing from mathlib... trying to write it without cc.\n\nHere are a few hints on how to carry out proofs by induction:\n\n- It is usually beneficial to perform induction following the structure of the definition of one of\n  the functions appearing in the goal. In particular, if a function is defined by recursion on its\n  _n_ th argument, it usually makes sense to perform the induction on that argument.\n\n- If the base case of an induction is difficult, this is often a sign that the wrong variable was\n  chosen or that some lemmas should be proved first.\n\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/BackwardProofs/Induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7995057065834321}}
{"text": "-- Igualdad a partir de acotaciones del valor absoluto de la diferencia\n-- ====================================================================\n\nimport data.real.basic\n\nvariables (x y : ℝ)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la notación |x| para el valor\n-- absoluto de x.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que si |x - y| ≤ ε, para todo\n-- ε > 0, entonces x = y.\n-- ----------------------------------------------------\n\n-- Se usará el lema demostrado anteriormente\nlemma cero_de_abs_mne_todos\n  (h : ∀ ε > 0, |x| ≤ ε)\n  : x = 0 :=\nabs_eq_zero.mp\n  (eq_of_le_of_forall_le_of_dense (abs_nonneg x) h)\n\n-- 1ª demostración\nexample\n  (h : ∀ ε > 0, |x - y| ≤ ε)\n  : x = y :=\nbegin\n  rw ← sub_eq_zero,\n  exact cero_de_abs_mne_todos (x - y) h,\nend\n\n-- 2ª demostración\nlemma ig_de_abs_sub_mne_todos\n  (h : ∀ ε > 0, |x - y| ≤ ε)\n  : x = y :=\nsub_eq_zero.mp (cero_de_abs_mne_todos (x - y) h)\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/ig_de_abs_sub_mne_todos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.894789454880027, "lm_q1q2_score": 0.7993238263163629}}
{"text": "import definitions tactic\nuniverse u \n\nnamespace Algebra \n\nnamespace group \n\nvariables {G : Type u} [group G]\n\nlemma group_nonempty : nonempty G := ⟨0⟩ \n\ndef is_ident (e : G) : Prop := ∀ g : G, e + g = g ∧ g + e = g\n\nlemma id_unique : ∀ e : G, is_ident e → e = 0 := \nbegin \n  intros e H,\n  rw is_ident at H, cases H 0 with H1 H2,\n  simp at H1, \n  assumption\nend \n\ndef is_inv (g g' : G) : Prop := g + g' = 0 ∧ g' + g = 0\n\nlemma inv_unique : ∀ g g': G, is_inv g g' →  (-g) = g':= \nbegin \n  intros a b H, cases H with H1 H2,\n  have H3 : b + 0 = b, from group.ident_r,\n  have H4 : b + (a + (-a)) = b, by {rwa ← group.inv_r at H3},\n  rw ← group.associative at H4,\n  rwa [H2, group.ident_l] at H4,\nend \n\n@[simp]\nlemma op_inv : ∀ a b : G, -(a + b) = (-b) + (-a) := \nbegin \n  intros a b,\n  have H1 : (a + b) + ((-b) + (-a)) = 0, \n  by {rw ← group.associative, simp,},\n  have H2 : (-b) + (-a) + (a + b) = 0, \n  by { rw ← group.associative, rw  @group.associative G _inst_1 (-b) (-a) a, \n       rw group.inv_l, simp,},\n  have H3 : is_inv (a + b) (-b + -a) := ⟨H1,H2⟩,\n  exact inv_unique (a + b) (-b + -a) H3,\nend  \n\ndef congr_l {b c : G} (a : G) (h : b = c) : a + b = a + c := \ncongr (refl (λ g, a + g)) h \n\ndef congr_r {b c : G} (a : G) (h : b = c) :  b + a = c + a:= \n@congr G G (λ g, g + a) (λ g, g + a) b c (by refl) h \n\nlemma cancel_right : ∀ a b c : G, b + a = c + a →  b = c := \nbegin \n  intros a b c H,\n  have : b + a + (-a) = c + a + (-a) := congr_r (-a) H,\n  simp at this, exact this\nend  \n\nlemma cancel_left : ∀ a b c : G, a + b = a + c → b = c := \nbegin \n  intros a b c H,\n  have :  (-a) + (a + b) = (-a) + (a + c) := congr_l (-a) H,\n  simp at this, exact this\nend  \n\nlemma square_ident_imp_self_inv (G : Type u) [group G] : ∀ g : G, g ↟ 2 = 0 → (-g = g) := \nbegin\n  intro g, repeat {rw pow}, rw group.ident_r, \n  intro H, apply inv_unique, exact ⟨H,H⟩\nend \n\nlemma square_ident_imp_abelian : (∀ g : G, g ↟ 2 = 0) → abelian G :=\nbegin \n  intros H1 a b,\n  obtain H2 := square_ident_imp_self_inv G a (H1 a),\n  obtain H3 := square_ident_imp_self_inv G b (H1 b),\n  obtain H4 := square_ident_imp_self_inv G (a + b) (H1 (a + b)), \n  simp at H4,  \n  rw [H2,H3] at H4, symmetry, exact H4,\nend \n\n\n\nend group\n\n\n\n\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.799311887402709}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la librería de tácticas.\n-- 2. Habilitar la lógica clásica.\n-- 3. Declarar Q como una variable proposicional. \n-- ----------------------------------------------------------------------\n\nimport tactic           -- 1\nopen_locale classical   -- 2\nvariable (Q : Prop)     -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que si\n--     ¬ ¬ Q\n-- entonces \n--    Q\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (h : ¬ ¬ Q) \n  : Q :=\nbegin \n  by_contradiction h1,\n  exact (h h1),\nend\n\n-- Prueba\n-- ======\n\n/-\nQ : Prop,\nh : ¬¬Q\n⊢ Q\n  >> by_contradiction h1,\nh1 : ¬Q\n⊢ false\n  >> exact (h h1),\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (h : ¬ ¬ Q) \n  : Q :=\nnot_not.mp h\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (h : ¬ ¬ Q) \n  : Q :=\nby tauto\n\n-- Comentario: La táctica tauto demuestra las tautologís\n-- proposionales.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que si\n--    Q\n-- entonces \n--    ¬ ¬ Q\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (h : Q) \n  : ¬ ¬ Q :=\nbegin\n  intro h1,\n  exact (h1 h),\nend\n\n-- Prueba\n-- ======\n\n/-\nQ : Prop,\nh : Q\n⊢ ¬¬Q\n  >> intro h1,\nh1 : ¬Q\n⊢ false\n  >> exact (h1 h)\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (h : Q) \n  : ¬ ¬ Q :=\nnot_not.mpr h\n\n-- 3ª demostración\n-- ===============\n\nexample \n  (h : Q) \n  : ¬ ¬ Q :=\nby tauto\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/Doble_negacion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.89181104831338, "lm_q1q2_score": 0.7992868692125348}}
{"text": "import analysis.inner_product_space.pi_L2\n\n/- Good work Priya!\n90/90 Correctness\n10/10 Style\n-/\n\n/-\nThis assignment is due midnight on Wednesday, February 1.\n\nCopy this file to `src/assignment2/assignment2.lean` in your personal `har-ifvm-23-{username}`\ndirectory, and fill in the proofs. When you are done, push it to Github:\n```\n  git add assignment2.lean\n  git commit -m \"my assignment2 solutions\"\n  git push\n```\nFeel free to push any preliminary commits.\n-/\n\n/-\nFIRST EXERCISE: the parallelogram law\n-/\n\nnamespace parallelogram_exercise\nopen_locale real_inner_product_space\n\n/-\nIn the following variable declaration, `euclidean_space ℝ (fin 2)` represents\nthe Euclidean plane, ℝ × ℝ, with the usual definition of inner product.\n-/\n\nvariables x y z : euclidean_space ℝ (fin 2)\n\n#check ⟪x, y⟫    -- the inner product\n#check ‖x‖       -- the norm\n#check x + y\n#check 3 • x\n\n/-\nHovering over the brackets in VS Code shows that the angle brackets for the inner product can be\nwritten as `\\<<` and `\\>>`, and the bars for the norm can be written `\\||`.\n\nThey satisfy the following identities:\n-/\n\nexample : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := inner_add_right\nexample : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := inner_add_left\nexample : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := inner_sub_right\nexample : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := inner_sub_left\n\nexample :  ⟪x, x⟫ = ‖x‖^2 := real_inner_self_eq_norm_sq x\n\n/-\nThe following identity is known as the *parallelogram law*. It says that the sum of the squares\nof the lengths of the four sides of a parallegram is equal to the sum of the squares of the\nlengths of the diagonals.\n\nYou can read a proof of it on Wikipedia: https://en.wikipedia.org/wiki/Parallelogram_law.\n\nFormalize it using only the four identities above as well as the `ring` tactic.\n-/\n\nexample :\n  ‖x + y‖^2 + ‖x - y‖^2  = 2 * (‖x‖^2 + ‖y‖^2) :=\nbegin\n  rw ← real_inner_self_eq_norm_sq,\n  rw ← real_inner_self_eq_norm_sq,\n  rw inner_add_right,\n  rw inner_add_left,\n  rw real_inner_self_eq_norm_sq x,\n  rw inner_add_left,\n  rw real_inner_self_eq_norm_sq y,\n  ring,\n  rw inner_sub_right,\n  rw inner_sub_left,\n  rw inner_sub_left,\n  rw real_inner_self_eq_norm_sq,\n  rw real_inner_self_eq_norm_sq,\n  ring,\nend\n\n/-\nIn fact, the theorem holds for arbitrary inner product spaces, with exactly the same proof.\nYou can check this by replacing the variable declaration above by the following:\n\nvariables {E : Type*} [inner_product_space ℝ E]\nvariables x y z : E\n-/\n\nend parallelogram_exercise\n\n/-\nSECOND EXERCISE: Boolean rings\n-/\n\nnamespace boolean_ring_exercise\n\n/-\nThe notion of a ring is discussed in the textbook:\nhttps://leanprover-community.github.io/mathematics_in_lean/02_Basics.html#proving-identities-in-algebraic-structures\n\nA *Boolean* ring satisfies the additional property that for every `x`, `x^2 = x`.\nYou can read about Boolean rings here:\nhttps://en.wikipedia.org/wiki/Boolean_ring\n-/\n\nvariables {R : Type*} [ring R]\n\n-- This is the assumption that makes `R` a Boolean ring:\nvariable (idem : ∀ x : R, x^2 = x)\n\n-- This adds `idem` as a hypothesis to every theorem:\ninclude idem\n\n/-\nThis exercise asks you to prove that every Boolean ring is commutative, i.e.\nsatisfies `x * y = y * x` for every `x` and `y`. Unfortunately, we cannot use the\n`ring` tactic along the way, since it only works once we know a ring is commutative.\nSo you will have to rely on theorems like `mul_add`, `add_mul`, etc. in the textbook.\n-/\n\n-- This is useful:\ntheorem mul_idem (x : R) : x * x = x :=\nby rw [←pow_two, idem]\n\n-- Unfortunately, you have to write `mul_idem idem` to use it.\nexample (x y : R) : (x + y) * (x + y) = x + y :=\nby rw [mul_idem idem]\n\n/-\nProve the following theorem, following the calculation in Wikipedia:\nx + x = (x+x)^2 = x^2 + x^2 + x^2 + x^2 = (x + x) + (x + x).\n-/\n\ntheorem add_self (x : R) : x + x = 0 :=\nbegin\n  have h1 : x + x = (x + x) + (x + x),\n  calc\n    x + x = (x + x)^2 :\n      begin\n        rw idem,\n      end\n    ... = x + x + (x + x) :\n      begin\n        rw pow_two,\n        rw mul_add,\n        rw add_mul,\n        rw ← add_assoc,\n        rw mul_idem idem,\n        rw add_assoc,\n      end,\n  have h2 : (x + x) + (x + x) - (x + x) = (x + x) - (x + x),\n    by rw ←h1,\n  rw [add_sub_cancel, sub_self] at h2,\n  exact h2\nend\n\n-- Note: again, to use this theorem you have to mention `idem` explicitly\nexample (y : R) : y + y = 0 :=\nadd_self idem y\n\n/-\nProve `neg_eq_self` using the calculation `-x = 0 - x = x + x - x = x`. You can use the theorems\n`zero_sub` and `add_sub_cancel`, as well as `add_self idem`.\n-/\n\ntheorem neg_eq_self (x : R) : -x = x :=\nbegin\n  rw ← zero_sub,\n  rw ← add_self idem x,\n  rw add_sub_cancel,\nend\n\n/-\nThis is a corollary.\n-/\n\ntheorem sub_eq_add (x y : R) : x - y = x + y :=\nby rw [sub_eq_add_neg, neg_eq_self idem]\n\n/-\nProve this, using the calculation `x = x + y - y = 0 - y = -y = y`.\n-/\ntheorem eq_of_add_eq_zero {x y : R} (h : x + y = 0) :\n  x = y :=\nbegin\n  rw ← add_zero x,\n  rw ← sub_self y,\n  rw ← add_sub_assoc,\n  rw h,\n  rw zero_sub,\n  rw neg_eq_self idem,\nend\n\n/- Finally, prove `mul_comm` using the following argument from Wikipedia:\n\n`0 + x + y = x + y = (x + y)^2 = x^2 + xy + yx + y^2 = xy + yx + x + y`\n\nYou can use the `abel` tactic to rearrange sums.\n-/\n\nexample (x y : R) : x + x * y + y * x + y = x * y + y * x + x + y :=\nby abel\n\ntheorem mul_comm (x y : R) : x * y = y * x :=\nbegin\n  have h1 : 0 + (x + y) = (x * y + y * x) + (x + y),\n  calc\n    0 + (x + y) = (x + y)^2 :\n      begin\n        rw zero_add,\n        rw idem,\n      end\n    ... = x * y + y * x + (x + y) :\n      begin\n        rw pow_two,\n        rw mul_add,\n        rw add_mul,\n        rw add_mul,\n        rw ← add_assoc,\n        rw mul_idem idem,\n        rw mul_idem idem,\n        abel,\n      end,\n  have h2 : 0 = x * y + y * x,\n    exact add_right_cancel h1,\n  show x * y = y * x,\n    exact eq_of_add_eq_zero idem h2.symm\nend\n\nend boolean_ring_exercise\n\n/-\nTHIRD EXERCISE: absolute values\n-/\n\nnamespace absolute_value_exercise\n\nvariables x y z w : ℝ\n\n/-\nBounding sums often boils down to using transitivity and inequalities. Step through the\nnext example and make sure you understand what is going on. `swap` switches the order of the goals,\nand `norm_num` does a numeric calculation.\n\nThe `transitivity` tactic lets you state the intermediate expression. In contrast, applying\n`le_trans` lets you make Lean figure it out from context. With the `transitivity` tactic,\nwe have to specify that the numerals are real numbers, because otherwise Lean assumes that they\nare natural numbers.\n-/\n\nexample\n    (hx : abs x ≤ 10)\n    (hy : abs y ≤ 5)\n    (hz : abs z ≤ 4) :\n  abs (x + y + z) ≤ 19 :=\nbegin\n  transitivity ((10 : ℝ) + 5 + 4),\n  swap, { by norm_num },\n  apply le_trans,\n  apply abs_add,\n  apply add_le_add,\n  { -- first goal\n    apply le_trans,\n    apply abs_add,\n    exact add_le_add hx hy },\n  -- second goal\n  exact hz,\nend\n\n/-\nWe can finish the second goal earlier by giving `hz` right away.\n-/\n\nexample\n    (hx : abs x ≤ 10)\n    (hy : abs y ≤ 5)\n    (hz : abs z ≤ 4) :\n  abs (x + y + z) ≤ 19 :=\nbegin\n  transitivity ((10 : ℝ) + 5 + 4),\n  swap, { by norm_num },\n  apply le_trans,\n  apply abs_add,\n  -- the underscore means: figure it out or leave it as another goal\n  apply add_le_add _ hz,\n  apply le_trans,\n  apply abs_add,\n  exact add_le_add hx hy,\nend\n\n/-\nProve the following. You can also use the theorems `abs_sub`, `pow_two` to expand `w^2` to `w * w`,\n`sq_abs`, and `mul_le_mul`. For the last theorem, you'll need to know that an absolute value is\nnonnegative, which is the theorem `abs_nonneg`. You can also use `norm_num` to show that\n`(9 : ℝ) = 3 * 3`.\n-/\n\nexample\n    (hx : abs x ≤ 10)\n    (hy : abs y ≤ 5)\n    (hz : abs z ≤ 4)\n    (hw : abs w ≤ 3) :\n  abs (x - y + z) + w^2 ≤ 28 :=\nbegin\n  have h1 : w^2 ≤ 9,\n  begin\n    rw ← sq_abs,\n    rw pow_two,\n    transitivity ((3 : ℝ) * 3),\n    swap, { norm_num },\n    apply mul_le_mul,\n    exact hw,\n    exact hw,\n    apply abs_nonneg,\n    norm_num,\n  end,\n  transitivity ((10 : ℝ) + 5 + 4 + 9),\n  apply add_le_add,\n  swap, { exact h1 },\n  swap, { norm_num },\n  apply le_trans,\n  apply abs_add,\n  apply add_le_add,\n  swap, { exact hz },\n  apply le_trans,\n  apply abs_sub,\n  apply add_le_add,\n  exact hx,\n  exact hy,\nend\n\nend absolute_value_exercise\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/assignment2/assignment2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7992373860828574}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intros h h',\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro h,\n  by_contradiction h,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P,\n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro h,\n  cases h,\n  right,\n  apply h,\n  left,\n  apply h,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  split,\n  apply hq,\n  apply hp,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intros h h',\n  cases h,\n  contradiction,\n  apply h,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intros h h',\n  cases h,\n  contradiction,\n  apply h,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros h h' h'',\n  have hq : Q := h h'',\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros h p,\n  by_contradiction hboom,\n  apply h,\n  exact hboom,\n  exact p,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  exact impl_as_contrapositive P Q,\n  exact impl_as_contrapositive_converse P Q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h,\n  apply h,\n  right,\n  intro p,\n  apply h,\n  left,\n  exact p, \nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros h np,\n  have pq : P → Q,\n  intro p,\n  contradiction,\n  have p : P := h pq,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intros h h'',\n  cases h'' with hnp hnq,\n  cases h,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intros h h'',\n  cases h with hp hq,\n  cases h'',\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro h,\n  split,\n  intro p,\n  have poq : P∨Q,\n  left,\n  exact p,\n  exact h poq,\n  intro q,\n  have poq : P∨Q,\n  right,\n  exact q,\n  exact h poq,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros h h',\n  cases h with np nq,\n  cases h',\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h,\n  by_cases lem : Q,\n  right,\n  intro p,\n  apply h,\n  split,\n  exact p,\n  exact lem,\n  left,\n  exact lem,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros h h',\n  cases h' with p q,\n  cases h,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  intro h,\n  split,\n  intro p,\n  have poq : P∨Q,\n  left,\n  exact p,\n  exact h poq,\n  intro q,\n  have poq : P∨Q,\n  right,\n  exact q,\n  exact h poq,\n  intros h h',\n  cases h with np nq,\n  cases h',\n  contradiction,\n  contradiction,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h,\n  cases h with x y,\n  cases y,\n  left,\n  split,\n  exact x,\n  exact y,\n  right,\n  split,\n  exact x,\n  exact y,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h, -- Suponha -L.\n  split,\n  cases h,\n  cases h with p q,\n  exact p,\n  cases h with p q,\n  exact p,\n  cases h,\n  cases h with p q,\n  left,\n  exact q,\n  cases h with p r,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h,\n  cases h,\n  split,\n  left,\n  exact h,\n  left,\n  exact h,\n  cases h with q r,\n  split,\n  right,\n  exact q,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  cases h with poq por,\n  cases poq,\n  left,\n  exact poq,\n  cases por,\n  left,\n  exact por,\n  right,\n  split,\n  exact poq,\n  exact por,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros h p q,\n  have pq : P ∧ Q,\n  split,\n  exact p,\n  exact q,\n  exact h pq,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros h h',\n  cases h' with p q,\n  exact h p q,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro h,\n  exact h,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro h,\n  left,\n  exact h,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro h,\n  right,\n  exact h,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro h,\n  cases h with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro h,\n  cases h with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro h,\n  cases h with x y,\n  exact x,\n  intro h,\n  split,\n  exact h,\n  exact h,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro h,\n  cases h,\n  exact h,\n  exact h,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros h x p,\n  apply h,\n  existsi x,\n  exact p,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros h h',\n  cases h' with a ha,\n  have hna : ¬P a := h a,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  rw contrapositive_law,\n  intros e p,\n  apply p,\n  intro x,\n  by_cases lem : P x,\n  exact lem,\n  exfalso,\n  apply e,\n  existsi x,\n  exact lem,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intros h h',\n  cases h with x npx,\n  have px : P x := h' x,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n  exact demorgan_forall_converse U P,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros h h',\n  cases h with x px,\n  have npx : ¬P x := h' x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros h h',\n  cases h' with x npx,\n  have px : P x := h x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intros h x,\n  by_contradiction hboom,\n  have e : ∃ (x : U), ¬P x,\n  existsi x,\n  exact hboom,\n  exact h e,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  rw contrapositive_law,\n  intros e p,\n  apply p,\n  intros x px,\n  apply e,\n  existsi x,\n  exact px,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n  exact forall_as_neg_exists_converse U P,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with x y,\n  cases y with px qx,\n  split,\n  existsi x,\n  exact px,\n  existsi x,\n  exact qx,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with x y,\n  cases y,\n  left,\n  existsi x,\n  exact y,\n  right,\n  existsi x,\n  exact y,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  cases h,\n  cases h with x y,\n  existsi x,\n  left,\n  exact y,\n  cases h with x y,\n  existsi x,\n  right,\n  exact y,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro h,\n  split,\n  intro x,\n  have pxqx : P x ∧ Q x := h x,\n  cases pxqx with px qx,\n  exact px,\n  intro x,\n  have pxqx : P x ∧ Q x := h x,\n  cases pxqx with px qx,\n  exact qx,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intros h x,\n  cases h,\n  split,\n  have px : P x := h_left x,\n  exact px,\n  have qx : Q x := h_right x,\n  exact qx,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intros h x,\n  cases h,\n  have px : P x := h x,\n  left,\n  exact px,\n  have qx : Q x := h x,\n  right,\n  exact qx,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "isaacmsl", "repo": "fmclean", "sha": "2bb09a92a9f6f38a29dccb6b0b62c709c9e567cd", "save_path": "github-repos/lean/isaacmsl-fmclean", "path": "github-repos/lean/isaacmsl-fmclean/fmclean-2bb09a92a9f6f38a29dccb6b0b62c709c9e567cd/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.799215317991651}}
{"text": "/-\n3. Consider the “barber paradox,” that is, the claim that in a certain town there is a (male) barber that shaves all and only the men who do not shave themselves. Prove that this is a contradiction:\n-/\n\nopen classical\n\nvariables (men : Type) (barber : men)\nvariable  (shaves : men → men → Prop)\n\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\n    or.elim (em (shaves barber barber))\n    (\n        assume h1 : shaves barber barber,\n        have h2 : shaves barber barber ↔ ¬ shaves barber barber, from h barber,\n        have h3 : shaves barber barber → ¬ shaves barber barber, from iff.mp h2,\n        have h4 : ¬ shaves barber barber, from h3 h1,\n        false.elim (h4 h1)\n    )\n    (\n        assume h1 : ¬ shaves barber barber,\n        have h2 : shaves barber barber ↔ ¬ shaves barber barber, from h barber,\n        have h3 : ¬ shaves barber barber → shaves barber barber, from iff.mpr h2,\n        have h4 : shaves barber barber, from h3 h1,\n        false.elim (h1 h4)\n    )\n-- short version\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\n    (em (shaves barber barber)).elim\n    (λ h1, absurd h1 ((iff.mp (h barber)) h1))\n    (λ h1, absurd ((iff.mpr (h barber)) h1) h1)\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-ex03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8479677526147222, "lm_q1q2_score": 0.7992153048305053}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\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ácticas\n* `specialize`\n* `convert`\n* `linarith`\n-/\n\n/- ## specialize\nLa táctica `specialize` se puede aplicar a hipótesis locales\nde la forma `∀ x₁ ... xₙ , P x₁ ... xₙ` o `P → Q → R → ...`.  \n\nAl aplicar `specialize h a₁ ... aₙ`, las premisas de `h` se instancian con los\nargumentos `a₁ ... aₙ`.\n\nLa táctica añade una nueva hipótesis `h := h a₁ ... aₙ` con el mismo nombre e intenta\neliminar la anterior\n\nNOTA: no siempre es necesario utilizar esta táctica. Es especialmente útil cuando queremos\nreescribir en la hipótesis resultante.\n-/\n\nexample (h : ∀ n : ℕ, even (2*n)) : even 2 :=\nbegin\n  specialize h 1,\n  rw mul_one at h,\n  exact h,\nend\n\nexample {P Q : Prop} (hP : P) (h : P → Q) : Q :=\nbegin\n  specialize h hP,\n  exact h,\n  -- Pero también podríamos haber hecho `exact h hP` directamente.\nend\n\n/- ## convert\n`convert h` es similar a `refine h`, pero el tipo de `h` no tiene que ser exactamente\nigual al de la meta, sino que se crearán nuevas metas para cada una de las diferencias.\n-/\n\nexample (x y z ε : ℝ) (h : |x| < ε) : |x + z - z| < ε :=\nbegin\n  convert h,\n  ring,\nend\n\n/- A veces `convert` es demasiado agresivo. Podemos controlar su comportamiento utilizando\n`convert h using n`, donde `n` es un número pequeño.  -/\nexample {x : ℝ} (hx : |x| = 3) : |(-x)| = 3 :=\nbegin\n  --convert hx, -- Reduce la meta a -x = x\n  convert hx using 1,\n  exact abs_neg _,\nend\n\n/- ## linarith \nLa táctica `linarith` se puede utilizar para demostrar una desigualdad linear, o para derivar\nuna contradicción a partir de una familia de igualdades y desigualdades.\nUtiliza las hipótesis locales.\n-/\n\nexample {a b c d : ℝ} (h1 : a < b) (h2 : b ≤ c) (h3 : c = d) :\n  a + a < d + b :=\nbegin\n  linarith\nend\n\n\nexample (x y z : ℚ) (h1 : 2*x  < 3*y) (h2 : -4*x + 2*z < 0) (h3 : 12*y - 4* z < 0)  : false :=\nby linarith\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_4/tacticas_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8976953023710936, "lm_q1q2_score": 0.7992129497438861}}
{"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\" (`¬`)\n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# Important : the definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → false`. So `¬ P` and `P → false`\nare *the same thing* and can be used interchangeably. You can change\nfrom one to the other for free.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics:\n\n* `change` (optional)\n* `by_contra`\n* `by_cases`\n\n### The `change` tactic\n\nThe `change` tactic changes a goal to a goal which\nis *equal to it by definition*. The example you need to know\nis that `¬ P` and `P → false` are equal by definition.\n\nIf your goal is `⊢ ¬ P` then `change P → false,` will\nchange it to `P → false`. Similarly if you have a hypothesis\n`h : ¬ P` then `change P → false at h,` will change it to `h : P → false`.\n\nNote that this tactic is just for psychological purposes. If you finish\na proof which uses this tactic, try commenting out the `change` lines\nand note that it doesn't break.\n\n### The `by_contra` tactic\n\nIf your goal is `⊢ P` and you want to prove it by contradiction,\n`by_contra h,` will change the goal to `false` and add a hypothesis\n`h : ¬ P`.\n\n### The `by_cases` tactic\n\nIf `P : Prop` is a true-false statement then `by_cases hP : P,`\nturns your goal into two goals, one with hypothesis `hP : P`\nand the other with hypothesis `hP : ¬ P`.\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : ¬ P → (P → false) :=\nbegin\n  sorry,\nend\n\nexample : ¬ true → false :=\nbegin\n  sorry\nend\n\nexample : false → ¬ true :=\nbegin\n  sorry\nend\n\nexample : ¬ false → true :=\nbegin\n  sorry\nend\n\nexample : true → ¬ false :=\nbegin\n  sorry\nend\n\nexample : false → ¬ P :=\nbegin\n  sorry\nend\n\nexample : P → ¬ P → false :=\nbegin\n  sorry\nend\n\nexample : P → ¬ (¬ P) :=\nbegin\n  sorry\nend\n\nexample : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  sorry\nend\n\nexample : ¬ ¬ false → false :=\nbegin\n  sorry\nend\n\nexample : ¬ ¬ P → P :=\nbegin\n  sorry\nend\n\nexample : (¬ Q → ¬ P) → (P → Q) :=\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/logic/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.799157954332572}}
{"text": "import data.real.basic\n\nopen_locale classical\n\n/-\nTheoretical negations.\n\nThis file is for people interested in logic who want to fully understand\nnegations.\n\nHere we don't use `contrapose` or `push_neg`. The goal is to prove lemmas\nthat are used by those tactics. Of course we can use\n`exfalso`, `by_contradiction` and `by_cases`.\n\nIf this doesn't sound like fun then skip ahead to the next file.\n-/\n\nsection negation_prop\n\nvariables P Q : Prop\n\n-- 0055\nexample : (P → Q) ↔ (¬ Q → ¬ P) :=\nbegin\n  split,\n  {\n    intros h1 hnQ hP,\n    exact hnQ (h1 hP),\n  },\n  {\n    intros h1 hP,\n    by_contradiction hnQ,\n    exact h1 hnQ hP,\n  }\nend\n\n-- 0056\nlemma non_imp (P Q : Prop) : ¬ (P → Q) ↔ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\n-- In the next one, let's use the axiom\n-- propext {P Q : Prop} : (P ↔ Q) → P = Q\n\n-- 0057\nexample (P : Prop) : ¬ P ↔ P = false :=\nbegin\n  sorry\nend\n\nend negation_prop\n\nsection negation_quantifiers\nvariables (X : Type) (P : X → Prop)\n\n-- 0058\nexample : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x :=\nbegin\n  sorry\nend\n\n-- 0059\nexample : ¬ (∃ x, P x) ↔ ∀ x, ¬ P x :=\nbegin\n  sorry\nend\n\n-- 0060\nexample (P : ℝ → Prop) : ¬ (∃ ε > 0, P ε) ↔ ∀ ε > 0, ¬ P ε :=\nbegin\n  sorry\nend\n\n-- 0061\nexample (P : ℝ → Prop) : ¬ (∀ x > 0, P x) ↔ ∃ x > 0, ¬ P x :=\nbegin\n  sorry\nend\n\nend negation_quantifiers\n\n", "meta": {"author": "fzyzcjy", "repo": "learn_lean", "sha": "3d47e1641bb7d7afb590d18a73fa0c562e51e733", "save_path": "github-repos/lean/fzyzcjy-learn_lean", "path": "github-repos/lean/fzyzcjy-learn_lean/learn_lean-3d47e1641bb7d7afb590d18a73fa0c562e51e733/src/tutorial/exercises/07bis_abstract_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.7990997057972896}}
{"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# 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\nnoncomputable theory\nopen_locale classical polynomial\n\nopen polynomial finset\n\nnamespace polynomial\n\nvariables {R : Type*} [semiring R] {f : R[X]}\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 (f : R[X]) : R[X] :=\npolynomial.erase f.nat_degree f\n\nsection erase_lead\n\nlemma erase_lead_support (f : R[X]) :\n  f.erase_lead.support = f.support.erase f.nat_degree :=\nby simp only [erase_lead, support_erase]\n\nlemma erase_lead_coeff (i : ℕ) :\n  f.erase_lead.coeff i = if i = f.nat_degree then 0 else f.coeff i :=\nby simp only [erase_lead, coeff_erase]\n\n@[simp] lemma erase_lead_coeff_nat_degree : f.erase_lead.coeff f.nat_degree = 0 :=\nby simp [erase_lead_coeff]\n\nlemma erase_lead_coeff_of_ne (i : ℕ) (hi : i ≠ f.nat_degree) :\n  f.erase_lead.coeff i = f.coeff i :=\nby simp [erase_lead_coeff, hi]\n\n@[simp] lemma erase_lead_zero : erase_lead (0 : R[X]) = 0 :=\nby simp only [erase_lead, erase_zero]\n\n@[simp] lemma erase_lead_add_monomial_nat_degree_leading_coeff (f : R[X]) :\n  f.erase_lead + monomial f.nat_degree f.leading_coeff = f :=\nbegin\n  ext i,\n  simp only [erase_lead_coeff, coeff_monomial, coeff_add, @eq_comm _ _ i],\n  split_ifs with h,\n  { subst i, simp only [leading_coeff, zero_add] },\n  { exact add_zero _ }\nend\n\n@[simp] lemma erase_lead_add_C_mul_X_pow (f : R[X]) :\n  f.erase_lead + (C f.leading_coeff) * X ^ f.nat_degree = f :=\nby rw [C_mul_X_pow_eq_monomial, erase_lead_add_monomial_nat_degree_leading_coeff]\n\n@[simp] lemma self_sub_monomial_nat_degree_leading_coeff {R : Type*} [ring R] (f : R[X]) :\n  f - monomial f.nat_degree f.leading_coeff = f.erase_lead :=\n(eq_sub_iff_add_eq.mpr (erase_lead_add_monomial_nat_degree_leading_coeff f)).symm\n\n@[simp] lemma self_sub_C_mul_X_pow {R : Type*} [ring R] (f : R[X]) :\n  f - (C f.leading_coeff) * X ^ f.nat_degree = f.erase_lead :=\nby rw [C_mul_X_pow_eq_monomial, self_sub_monomial_nat_degree_leading_coeff]\n\nlemma erase_lead_ne_zero (f0 : 2 ≤ f.support.card) : erase_lead f ≠ 0 :=\nbegin\n  rw [ne.def, ← card_support_eq_zero, erase_lead_support],\n  exact (zero_lt_one.trans_le $ (tsub_le_tsub_right f0 1).trans\n    finset.pred_card_le_card_erase).ne.symm\nend\n\n@[simp] lemma nat_degree_not_mem_erase_lead_support : f.nat_degree ∉ (erase_lead f).support :=\nby simp [not_mem_support_iff]\n\nlemma ne_nat_degree_of_mem_erase_lead_support {a : ℕ} (h : a ∈ (erase_lead f).support) :\n  a ≠ f.nat_degree :=\nby { rintro rfl, exact nat_degree_not_mem_erase_lead_support h }\n\nlemma erase_lead_support_card_lt (h : f ≠ 0) : (erase_lead f).support.card < f.support.card :=\nbegin\n  rw erase_lead_support,\n  exact card_lt_card (erase_ssubset $ nat_degree_mem_support_of_nonzero h)\nend\n\n\n\nlemma erase_lead_card_support' {c : ℕ} (fc : f.support.card = c + 1) :\n  f.erase_lead.support.card = c :=\nerase_lead_card_support fc\n\n@[simp] lemma erase_lead_monomial (i : ℕ) (r : R) :\n  erase_lead (monomial i r) = 0 :=\nbegin\n  by_cases hr : r = 0,\n  { subst r, simp only [monomial_zero_right, erase_lead_zero] },\n  { rw [erase_lead, nat_degree_monomial, if_neg hr, erase_monomial] }\nend\n\n@[simp] lemma erase_lead_C (r : R) : erase_lead (C r) = 0 :=\nerase_lead_monomial _ _\n\n@[simp] lemma erase_lead_X : erase_lead (X : R[X]) = 0 :=\nerase_lead_monomial _ _\n\n@[simp] lemma erase_lead_X_pow (n : ℕ) : erase_lead (X ^ n : R[X]) = 0 :=\nby rw [X_pow_eq_monomial, erase_lead_monomial]\n\n@[simp] lemma erase_lead_C_mul_X_pow (r : R) (n : ℕ) : erase_lead (C r * X ^ n) = 0 :=\nby rw [C_mul_X_pow_eq_monomial, erase_lead_monomial]\n\nlemma erase_lead_add_of_nat_degree_lt_left {p q : R[X]} (pq : q.nat_degree < p.nat_degree) :\n  (p + q).erase_lead = p.erase_lead + q :=\nbegin\n  ext n,\n  by_cases nd : n = p.nat_degree,\n  { 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  { 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) }\nend\n\nlemma erase_lead_add_of_nat_degree_lt_right {p q : R[X]} (pq : p.nat_degree < q.nat_degree) :\n  (p + q).erase_lead = p + q.erase_lead :=\nbegin\n  ext n,\n  by_cases nd : n = q.nat_degree,\n  { 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  { 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) }\nend\n\nlemma erase_lead_degree_le : (erase_lead f).degree ≤ f.degree :=\nbegin\n  rw degree_le_iff_coeff_zero,\n  intros i hi,\n  rw erase_lead_coeff,\n  split_ifs with h, { refl },\n  apply coeff_eq_zero_of_degree_lt hi\nend\n\nlemma erase_lead_nat_degree_le_aux : (erase_lead f).nat_degree ≤ f.nat_degree :=\nnat_degree_le_nat_degree erase_lead_degree_le\n\nlemma erase_lead_nat_degree_lt (f0 : 2 ≤ f.support.card) :\n  (erase_lead f).nat_degree < f.nat_degree :=\nlt_of_le_of_ne erase_lead_nat_degree_le_aux $ ne_nat_degree_of_mem_erase_lead_support $\n  nat_degree_mem_support_of_nonzero $ erase_lead_ne_zero f0\n\nlemma erase_lead_nat_degree_lt_or_erase_lead_eq_zero (f : R[X]) :\n  (erase_lead f).nat_degree < f.nat_degree ∨ f.erase_lead = 0 :=\nbegin\n  by_cases h : f.support.card ≤ 1,\n  { right,\n    rw ← C_mul_X_pow_eq_self h,\n    simp },\n  { left,\n    apply erase_lead_nat_degree_lt (lt_of_not_ge h) }\nend\n\nlemma erase_lead_nat_degree_le (f : R[X]) : (erase_lead f).nat_degree ≤ f.nat_degree - 1 :=\nbegin\n  rcases f.erase_lead_nat_degree_lt_or_erase_lead_eq_zero with h | h,\n  { exact nat.le_pred_of_lt h },\n  { simp only [h, nat_degree_zero, zero_le] }\nend\n\nend erase_lead\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. -/\nlemma induction_with_nat_degree_le (P : R[X] → Prop) (N : ℕ)\n  (P_0 : P 0)\n  (P_C_mul_pow : ∀ n : ℕ, ∀ r : R, r ≠ 0 → n ≤ N → P (C r * X ^ n))\n  (P_C_add : ∀ f g : R[X], f.nat_degree < g.nat_degree →\n    g.nat_degree ≤ N → P f → P g → P (f + g)) :\n  ∀ f : R[X], f.nat_degree ≤ N → P f :=\nbegin\n  intros f df,\n  generalize' hd : card f.support = c,\n  revert f,\n  induction c with c hc,\n  { assume f df f0,\n    convert P_0,\n    simpa only [support_eq_empty, card_eq_zero] using f0 },\n  { intros f df f0,\n    rw [← erase_lead_add_C_mul_X_pow f],\n    cases c,\n    { convert P_C_mul_pow f.nat_degree f.leading_coeff _ df,\n      { convert zero_add _,\n        rw [← card_support_eq_zero, erase_lead_card_support f0] },\n      { rw [leading_coeff_ne_zero, ne.def, ← card_support_eq_zero, f0],\n        exact zero_ne_one.symm } },\n    refine P_C_add f.erase_lead _ _ _ _ _,\n    { refine (erase_lead_nat_degree_lt _).trans_le (le_of_eq _),\n      { exact (nat.succ_le_succ (nat.succ_le_succ (nat.zero_le _))).trans f0.ge },\n      { rw [nat_degree_C_mul_X_pow _ _ (leading_coeff_ne_zero.mpr _)],\n        rintro rfl,\n        simpa using f0 } },\n    { exact (nat_degree_C_mul_X_pow_le f.leading_coeff f.nat_degree).trans df },\n    { exact hc _ (erase_lead_nat_degree_le_aux.trans df) (erase_lead_card_support f0) },\n    { refine P_C_mul_pow _ _ _ df,\n      rw [ne.def, leading_coeff_eq_zero, ← card_support_eq_zero, f0],\n      exact nat.succ_ne_zero _ } }\nend\n\n/-- Let `φ : R[x] → S[x]` be an additive map, `k : ℕ` a bound, and `fu : ℕ → ℕ` a\n\"sufficiently monotone\" map.  Assume also that\n* `φ` maps to `0` all monomials of degree less than `k`,\n* `φ` maps each monomial `m` in `R[x]` to a polynomial `φ m` of degree `fu (deg m)`.\nThen, `φ` maps each polynomial `p` in `R[x]` to a polynomial of degree `fu (deg p)`. -/\nlemma mono_map_nat_degree_eq {S F : Type*} [semiring S]\n  [add_monoid_hom_class F R[X] S[X]] {φ : F}\n  {p : R[X]} (k : ℕ)\n  (fu : ℕ → ℕ) (fu0 : ∀ {n}, n ≤ k → fu n = 0) (fc : ∀ {n m}, k ≤ n → n < m → fu n < fu m)\n  (φ_k : ∀ {f : R[X]}, f.nat_degree < k → φ f = 0)\n  (φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).nat_degree = fu n) :\n  (φ p).nat_degree = fu p.nat_degree :=\nbegin\n  refine induction_with_nat_degree_le (λ p, _ = fu _) p.nat_degree (by simp [fu0]) _ _ _ rfl.le,\n  { intros n r r0 np,\n    rw [nat_degree_C_mul_X_pow _ _ r0, ← monomial_eq_C_mul_X, φ_mon_nat _ _ r0] },\n  { intros 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 ≤ f.nat_degree,\n    { rw [nat_degree_add_eq_right_of_nat_degree_lt, gk],\n      rw [fk, gk],\n      exact fc FG fg },\n    { cases k,\n      { exact (FG (nat.zero_le _)).elim },\n      { rwa [φ_k (not_le.mp FG), zero_add] } } }\nend\n\nlemma map_nat_degree_eq_sub {S F : Type*} [semiring S]\n  [add_monoid_hom_class F R[X] S[X]] {φ : F}\n  {p : R[X]} {k : ℕ}\n  (φ_k : ∀ f : R[X], f.nat_degree < k → φ f = 0)\n  (φ_mon : ∀ n c, c ≠ 0 → (φ (monomial n c)).nat_degree = n - k) :\n  (φ p).nat_degree = p.nat_degree - k :=\nmono_map_nat_degree_eq k (λ j, j - k) (by simp) (λ m n h, (tsub_lt_tsub_iff_right h).mpr) φ_k φ_mon\n\nlemma map_nat_degree_eq_nat_degree {S F : Type*} [semiring S]\n  [add_monoid_hom_class F R[X] S[X]] {φ : F} (p)\n  (φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).nat_degree = n) :\n  (φ p).nat_degree = p.nat_degree :=\n(map_nat_degree_eq_sub (λ f h, (nat.not_lt_zero _ h).elim) (by simpa)).trans p.nat_degree.sub_zero\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/erase_lead.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7990062200753627}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro p,\n  intro f,\n  exact f(p), \nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro h,\n  by_cases p : P,\n  exact p,\n  have h1 : false := h p,\n  exfalso,\n  exact h1,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  intro h,\n  by_cases p : P,\n  exact p,\n  have h1 : false := h p,\n  exfalso,\n  exact h1,\n\n  intro p,\n  intro f,\n  exact f(p), \nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  right,\n  exact hp,\n  left,\n  exact hq,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  split,\n  exact hq,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  intro p,\n  exfalso,\n  apply hp,\n  exact p,\n  intro p,\n  exact hq,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro h,\n  intro p,\n  cases h with hp hq,\n  exfalso,\n  apply p,\n  exact hp,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro hpq,\n  intro q,\n  intro p,\n  have hq : Q := hpq p,\n  apply q,\n  exact hq,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros hqp p,\n  by_cases hq : Q,\n  exact hq,\n  exfalso,\n  have hboom := hqp hq,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  intros hpq q,\n  intro p,\n  have hq : Q := hpq p,\n  contradiction,\n\n  intros hqp p,\n  by_cases hq : Q,\n  exact hq,\n  have hboom := hqp hq,\n  exfalso,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro hp,\n  apply hp,\n  right,\n  intro p,\n\n  have hpp : P ∨ ¬P,\n  left,\n  exact p,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros hp p,\n  have p : P,\n  apply hp,\n  intro p,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intros p q,\n  cases p with hp hq,\n  cases q with nhp nhq,\n  apply nhq,\n  contradiction,\n  cases q with nhp nhq,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intros p q,\n  cases p with hp hq,\n  cases q with nhp nhq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro npq,\n  split,\n  intro p,\n  have hpq : P ∨ Q,\n  left,\n  exact p,\n  apply npq,\n  exact hpq,\n\n  intro q,\n  have hpq : P ∨ Q,\n  right,\n  exact q,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros npq p,\n  cases npq with np nq,\n  cases p with hp hq,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro hpq,\n  by_contra nqp,\n  apply hpq,\n  split,\n  by_contra np,\n  apply nqp,\n  right,\n  exact np,\n  by_contra nq,\n  apply nqp,\n  left,\n  exact nq,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros nqp,\n  intro hpq,\n  cases nqp with nq np,\n  cases hpq with hp hq,\n  contradiction,\n  cases hpq with hp hq,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n  exact demorgan_disj_converse P Q,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro hpqr,\n  cases hpqr 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∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro hpqr,\n  cases hpqr with hpq hpr,\n  cases hpq with hp hq,\n  split,\n  exact hp,\n  left,\n  exact hq,\n  split,\n  cases hpr with hp hr,\n  exact hp,\n  cases hpr with hp hr,\n  right,\n  exact hr,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro hpqr,\n  cases hpqr with hp hqr,\n  split,\n  left,\n  exact hp,\n  left,\n  exact hp,\n  cases hqr with hq hr,\n  split,\n  right,\n  exact hq,\n  right,\n  exact hr,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro hpqr,\n  cases hpqr with hpq hpr,\n  cases hpr with hp hr,\n  left,\n  exact hp,\n  cases hpq with hp hq,\n  left,\n  exact hp,\n  right,\n  split,\n  exact hq,\n  exact hr,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros hpqr hp hq,\n  apply hpqr,\n  split,\n  exact hp,\n  exact hq,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros hpqr hpq,\n  apply hpqr,\n  cases hpq with hp hq,\n  exact hp,\n  cases hpq with hp hq,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hp,\n  exact hp,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hp,\n  left,\n  exact hp,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hq,\n  right,\n  exact hq,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  exact hp,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  exact hq,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro hp,\n  cases hp with p,\n  exact p,\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro hpp,\n  cases hpp with p hp,\n  exact p,\n  exact hp,\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros hpx u pu,\n  apply hpx,\n  existsi u,\n  exact pu,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros npx hpx,\n  cases hpx with u pu,\n  apply npx,\n  exact pu,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro hpx,\n  by_contra npx,\n  apply hpx,\n  intro u,\n  by_contra npu,\n  apply npx,\n  existsi u,\n  exact npu,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intros hpx px,\n  cases hpx with u pu,\n  have hx := px u,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n  exact demorgan_forall_converse U P,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros hpx px,\n  cases hpx with u hpu,\n  have hx := px u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros px hpx,\n  cases hpx with u hpu,\n  have hx := px u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intros hpx u,\n  by_contra npu,\n  apply hpx,\n  existsi u,\n  exact npu,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro hpx,\n  by_contra npu,\n  apply hpx,\n  intro u,\n  intro pu,\n  apply npu,\n  existsi u,\n  exact pu,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n  exact forall_as_neg_exists_converse U P,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with u hpq,\n  cases hpq with p q,\n  split,\n  existsi u,\n  exact p,\n  existsi u,\n  exact q,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro h,\n  cases h with u hpq,\n  cases hpq with p q,\n  left,\n  existsi u,\n  exact p,\n  right,\n  existsi u,\n  exact q,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  cases h with hpx hqx,\n  cases hpx with u hpu,\n  split,\n  left,\n  exact hpu,\n  cases hqx with u hqu,\n  split,\n  right,\n  exact hqu,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro h,\n  split,\n  intro u,\n  have hu := h u,\n  cases hu with p q,\n  exact p,\n  intro u,\n  have hu := h u,\n  cases hu with p q,\n  exact q,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro h,\n  intro u,\n  split,\n  cases h with px qx,\n  have pu := px u,\n  exact pu,\n  cases h with px qx,\n  have hu := qx u,\n  exact hu, \nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  intro u,\n  cases h with px qx,\n  have pu := px u,\n  left,\n  exact pu,\n  have hu := qx u,\n  right,\n  exact hu,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "erivaldocf", "repo": "fmclean", "sha": "54a0914faaa409e00783b5e71ba3087df6cef899", "save_path": "github-repos/lean/erivaldocf-fmclean", "path": "github-repos/lean/erivaldocf-fmclean/fmclean-54a0914faaa409e00783b5e71ba3087df6cef899/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.8577681122619883, "lm_q1q2_score": 0.7989788427726701}}
{"text": "/- Homework 2 -/\n\n/- Part I: tactic proofs -/\n\n/- Do five propositional logic proofs and three quantifier proofs, following the\n   same constraints as on the last assignment, but this time using tactics.\n   (You can prove the same theorems as on the last assignment!)\n-/\n\nsection\n  open classical\n\n  variables p q r s : Prop\n\n  -- commutativity of ∧ and ∨\n  example : p ∧ q ↔ q ∧ p := \n  begin\n    apply iff.intro,\n    intro h,\n      apply and.intro,\n        exact (and.elim_right h), \n        exact (and.elim_left h),\n    intro h,\n      apply and.intro,\n        exact (and.elim_right h), \n        exact (and.elim_left h),\n  end\n\n  example : p ∨ q ↔ q ∨ p :=\n  begin\n    apply iff.intro,\n    intro h,\n      apply or.elim h,\n        intro hp,\n        exact or.inr hp,\n        intro hq,\n        exact or.inl hq,\n    intro h,\n      apply or.elim h,\n        intro hp,\n        exact or.inr hp,\n        intro hq,\n        exact or.inl hq,\n  end\n\n  -- associativity of ∧ and ∨\n  example : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n   begin\n    apply iff.intro,\n    intro h,\n      apply and.intro, \n        exact (and.elim_left (and.elim_left h)),\n        apply and.intro,\n          exact (and.elim_right (and.elim_left h)),\n          exact (and.elim_right h),\n    intro h,\n      apply and.intro,\n        apply and.intro,\n          exact and.elim_left h,\n          exact and.elim_left (and.elim_right h),\n        exact and.elim_right (and.elim_right h)\n  end\n\n\n  example : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n  begin\n    apply iff.intro,\n    intro h,\n      apply or.elim h,\n        intro hpq,\n        apply or.elim hpq,\n          intro hp,\n            exact or.inl hp,\n          intro hq,\n            exact or.inr (or.inl hq),\n        intro hr,\n          exact or.inr (or.inr hr),\n    intro h,\n      apply or.elim h,\n        intro hp,\n          exact or.inl (or.inl hp),\n        intro hqr,\n        apply or.elim hqr,\n          intro hq,\n            exact or.inl (or.inr hq),\n          intro hr,\n            exact or.inr hr\n  end\n\n  -- distributivity\n  -- this next one is in *Theorem Proving in Lean*\n  -- example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := sorry\n  example : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\n  begin\n    apply iff.intro,\n      intro h,\n        apply or.elim h,\n        intro hp,\n          exact and.intro (or.inl hp) (or.inl hp),\n        intro hqr,\n          exact and.intro (or.inr (and.elim_left hqr)) \n                          (or.inr (and.elim_right hqr)),\n      intro h,\n        apply or.elim (and.elim_left h),\n        intro hp,\n          exact or.inl hp,\n        intro hq,\n          apply or.elim (and.elim_right h),\n          intro hp,\n            exact or.inl hp,\n          intro hr,\n            exact or.inr (and.intro hq hr)  \n  end\n\n  example : (p → q) → (¬p ∨ q) := \n  begin\n    intro h,\n    apply or.elim (em p),\n    intro hp,\n      apply or.inr,\n      exact h hp,\n    intro hnp,\n      apply or.inl,\n      exact hnp\n  end\n\n  example : ¬(p ↔ ¬p) :=\n  begin\n    intro h,\n    apply false.elim,\n      apply iff.elim_left,\n        apply iff_false_intro,\n        exact (assume K: p, have K1: ¬p, from (iff.elim_left h) K, show false, from K1 K),\n      exact (iff.elim_right h) (assume K: p, have K1: ¬p, from (iff.elim_left h) K, show false, from K1 K)\n  end\n\nend\n\nsection\n\n  open classical\n\n  variable  α : Type\n  variables (p q : α → Prop) (r : Prop)\n  variable  a : α\n\n  example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\n  begin\n    apply iff.intro,\n    intro h,\n      apply and.intro,\n      intro x,\n        exact (and.elim_left (h x)),\n      intro x,\n        exact (and.elim_right (h x)),\n    intro h,\n      intro x,\n      apply and.intro,\n      exact ((and.elim_left h) x),\n      exact ((and.elim_right h) x)\n  end\n\n  example : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\n  begin\n    intro h,\n    intro h2,\n    intro x,\n    exact ((h x) (h2 x))\n  end\n\n  example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := \n  begin \n    intro h,\n    intro x,\n      apply or.elim h,\n      intro hp,\n        exact or.inl (hp x),\n      intro hq,\n        exact or.inr (hq x),\n  end\n\n  example : (∃ x : α, r) → r :=\n  begin\n    intro h,\n    cases h with x r,\n    exact r\n  end\n\n  example (c : α) : r → (∃ {x : α}, r) := \n  begin\n    intro h,\n    apply exists.intro,\n      exact c,    -- I don't understand why a wouldn't work here\n      exact h\n  end\n\n  example : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := \n  begin\n    apply iff.intro,\n    intro h,\n      cases h with x px,\n      apply and.intro,\n        constructor, exact (and.elim_left px),\n        exact (and.elim_right px),\n    intro h,\n      cases h with px r,\n        cases px with x p_x,\n        constructor, exact (and.intro p_x r)\n  end\n \n  example : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := \n  begin\n    apply iff.intro,\n    intro h,\n      apply by_contradiction,\n      intro hnp,\n      exact (h (take z,\n                  show p z, from \n                  by_contradiction \n                  (assume H₂: ¬ p z,\n                  have H₃: ∃ x, ¬ p x, from exists.intro z H₂,\n                  show false, from hnp H₃))),\n    intro h,\n    cases h with x npx,\n      intro h_to_contradict,\n      exact npx (h_to_contradict x)\n  end\n  \n  end\n\n\n/- Part II: calculations -/\n\n/- The Lean 3 library does not yet have the real numbers. We can fake it with the declarations\n   below. -/\nsection\n  variables (real : Type) [ordered_ring real]\n  variables (log exp : real → real)\n  premise   log_exp_eq : ∀ x, log (exp x) = x\n  premise   exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x\n  premise   exp_pos    : ∀ x, exp x > 0\n  premise   exp_add    : ∀ 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) : 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 := exp_log_eq h\n\n  /- Prove the folowing theorem, using the facts above. -/\n  --theorem \n  theorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) : log (x * y) = log x + log y :=\n  have H1: exp (log (x * y)) = exp (log x + log y), from \n  (calc\n      exp (log (x * y)) = x * y                      : by rw exp_log_eq (mul_pos hx hy)\n      ...               = exp (log x) * y            : by rw exp_log_eq (hx)\n      ...               = exp (log x) * exp (log y)  : by rw exp_log_eq hy\n      ...               = exp (log x + log y)        : by rw exp_add),\n  show log (x * y) = log x + log y, from\n  (calc\n      log (x * y) = log (exp (log(x * y)))           : by rw log_exp_eq\n      ...         = log (exp (log x + log y))        : by rw H1\n      ...         = log x + log y                    : by rw log_exp_eq\n  )\nend\n\n/- The following command lets you see the ring axioms in Lean. (We will discuss this when\n   we talk about structures.) -/\n\nprint fields ring\n\n/- Note that the properties left_distrib and right_distrib are also called mul_add and add_mul,\n   respectively. Since x - y is defined to be x + -y, the library proves \"sub_self\" as follows.\n-/\n\nnamespace hide\n\ntheorem sub_self {α : Type} [ring α] (x : α) : x - x = 0 := add_right_neg x\n\nend hide\n\n/- Similarly, we have mul_sub and sub_mul. The following is a consequence of the ring axioms,\n   and can be proved using only a short calculation, using sub_self and mul_sub. Do it!\n   Hint: consider x * (1 - 1). -/\n\nexample {α : Type} [ring α] (x : α) (h1: 0 = 1 - 1) : x * 0 = 0 :=\ncalc\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 x)\n\n/- Part III: inductive definitions -/\n\nopen list\nvariable {α : Type}\n\n/- In the Lean 3 library, the function \"concat\", which appends an element to the end of a list,\n   is defined as follows. -/\n\nnamespace hide\n\ndef concat : list α → α → list α\n| []     a := [a]\n| (b::l) a := b :: concat l a\n\nend hide\n\n/- For the next exercise, we will use the following \"home-grown\" version. Make sure you\n   understand how it works. -/\n\ndef conc (l : list α) (a : α) : list α :=\nlist.rec_on l\n  [a]\n  (λ b l recval, b :: recval)\n\ntheorem conc_nil  (a : α) : conc nil a = [a] := rfl\ntheorem conc_cons (b : α) (l : list α) (a : α) : conc (b :: l) a = b :: conc l a := rfl\n\nvm_eval conc [1, 2, 3] 4\n\n/- We will also use the length function. -/\n\ncheck conc_cons\n\ncheck length_nil\ncheck length_cons\n\nexample : length [1, 2, 3] = 3 := by refl\nexample (a : α) (l : list α) : length (a :: l) = length l + 1 := rfl\n\nvm_eval length [1, 2, 3, 4, 5]\n\n/- The following is an example of a proof by induction using these two notions. -/\n\ntheorem length_conc (a : α) (l : list α) : length (conc l a) = length l + 1 :=\nlist.induction_on l\n  rfl\n  (take b l',\n    assume ih : length (conc l' a) = length l' + 1,\n    show length (conc (b::l') a) = length (b::l') + 1, from\n      calc\n        length (conc (b::l') a) = length (b :: (conc l' a)) : rfl\n                            ... = length (conc l' a) + 1     : rfl\n                            ... = length l' + 1 + 1          : by rw ih\n                            ... = length (b::l') + 1         : rfl)\n\n/- Here is a shorter proof. -/\n\ntheorem length_conc' (a : α) (l : list α) : length (conc l a) = length l + 1 :=\nlist.induction_on l rfl (λ b l' ih, by simp [length, conc_cons, ih])\n\n/- Let us define a \"list reverse\" function and check that it works. -/\n\ndef rev (l : list α) : list α :=\nlist.rec_on l\n  []\n  (λ b l recval, conc recval b)\n\ntheorem rev_nil : rev ([] : list α) = [] := rfl\ntheorem rev_cons (a : α) (l : list α) : rev (a :: l) = conc (rev l) a := rfl\n\nvm_eval rev [1, 2, 3, 4, 5]\n\n/- Prove the following. -/\n\ntheorem length_rev (l : list α) : length (rev l) = length l :=\nlist.induction_on l\n  rfl\n  (take b l',\n   assume ih: length (rev l') = length l',\n   show length (rev (b::l')) = length (b::l'), from \n    calc\n      length (rev (b::l')) = length (conc (rev (l')) b) : rfl\n      ...                  = length (rev l') + 1    : by rw length_conc\n      ...                  = length l' + 1          : by rw ih\n      ...                  = length (b::l')         : rfl\n  )", "meta": {"author": "mtegene", "repo": "homework-mtegene-master", "sha": "5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5", "save_path": "github-repos/lean/mtegene-homework-mtegene-master", "path": "github-repos/lean/mtegene-homework-mtegene-master/homework-mtegene-master-5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5/homework2/solutions2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.798978827777909}}
{"text": "import topology.basic data.set.intervals analysis.exponential \nopen real set\n\n-- * Objective 1: prove that 1/x is continuous on R∗ (defined using sets)\n\n-- It's easy to define the underlying set, and a restricted version of the function\ndef punctured_line := (Iio (0:ℝ)) ∪ (Ioi (0:ℝ))\nnoncomputable def punctured_inv := function.restrict (λ (x:ℝ), 1/x) punctured_line\n\nlemma punctured_reals_are_nonzero : ∀ (a : subtype punctured_line), a.val ≠ 0 :=\nbegin\nintro,\n-- we can decompose the property using cases\ncases a.2 with l r,\nhave h : a.val < 0, from mem_Iio.mp l, \nhave h1 : a.val ≠ 0, from ne_of_lt h,\nexact  h1,\nhave k : a.val > 0, from mem_Ioi.mp r, \nhave k1 : a.val ≠ 0, from (ne_of_lt k).symm,\nexact  k1,\nend\n\n-- ... we mainly need to know that all of the possible arguments are nonzero\nlemma cont_punctured_inv : continuous punctured_inv :=\nbegin\n  unfold punctured_inv function.restrict,\n  simp only [one_div_eq_inv],\n  exact continuous_inv punctured_reals_are_nonzero continuous_subtype_val,\nend\n\n-- Here is a similar result that is closer to the mathlib proof\ntheorem continuous_1_over_x'' : continuous (λ (x : {r : ℝ | r ≠ 0} ), 1/(x:ℝ)) := \nbegin\nsimp only [one_div_eq_inv],\nrefine real.continuous_inv _ _,\nexact subtype.property,\napply continuous_subtype_val,\nend\n\n-- * Objective 2:  prove that tan(x) is continuous where cos(x) is nonzero\n\ndef cos_nonzero_set := {x : ℝ | cos x ≠ 0} \n\n-- minor change from the mathlib version\nlemma continuous_tan' : continuous (λ x : cos_nonzero_set, tan x) :=\nby simp only [tan_eq_sin_div_cos]; exact\ncontinuous_mul\n  (continuous_subtype_val.comp continuous_sin)\n  (continuous_inv subtype.property\n    (continuous_subtype_val.comp continuous_cos))\n\n-- * Objective 3: Instantiate [0,2] as a subtype and prove that x is continuous on this interval\n\ndef two_interval_set := (Icc (0:ℝ) 2) \n\ntheorem continuous_id_on_tworeal' : continuous (λ (x : ↥two_interval_set), x) := \nbegin\nexact continuous_id,\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/continuity_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7989589180877759}}
{"text": "import .love03_forward_proofs_demo\n\n\n/-! # LoVe Exercise 4: Functional Programming -/\n\n\nset_option pp.beta true\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 {α : Type} : list α → list α → list α\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 {α : Type} :\n  ∀ xs as : list α, accurev as xs = reverse xs ++ as :=\nbegin\n  intros,\n  induction xs generalizing as,\n  simp [accurev,reverse],\n  simp [accurev,reverse, xs_ih],\nend\n\n/-! 1.2. Derive the desired equation. -/\n\n#check accurev_eq_reverse_append\n\nlemma append_nil {α : Type} (xs : list α) :\n  reverse xs = reverse xs ++ [] := \nbegin\n  simp [refl]\nend\n\nlemma accurev_eq_reverse {α : Type} (xs : list α) :\n  accurev [] xs = reverse xs :=\nbegin\n  rw append_nil xs,\n  apply accurev_eq_reverse_append xs [],\nend\n\n/-! 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {α : Type} (xs : list α) :\n  accurev [] (accurev [] xs) = xs :=\nbegin\n  simp [accurev_eq_reverse, reverse_reverse],\nend\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 {α : Type} :\n      ∀as xs : list α, 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 {α : Type} : ℕ → list α → list α\n| 0       xs        := xs\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := drop m xs\n\n/-! Its relative `take` returns a list consisting of the the first `n` elements\nat the front of a list.\n\n2.1. Define `take`.\n\nTo avoid unpleasant surprises in the proofs, we recommend that you follow the\nsame recursion pattern as for `drop` above. -/\n\ndef take {α : Type} : ℕ → list α → list α\n| 0       xs        := []\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := x :: take m xs\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 {α : Type} :\n  ∀n : ℕ, drop n ([] : list α) = [] :=\nbegin\n  intros n,\n  induction n,\n  {\n    simp [drop],\n  },\n  {\n    simp [drop],\n  }\nend\n\n@[simp] lemma take_nil {α : Type} :\n  ∀n : ℕ, take n ([] : list α) = [] :=\nbegin\n  intros n,\n  induction n,\n  {\n    simp [take],\n  },\n  {\n    simp [take],\n  }\nend\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\nThe first case is shown for `drop_drop`. Beware of the fact that there are three\nvariables in the `drop_drop` lemma (but only two arguments to `drop`).\n\nHint: The `refl` tactic might be useful in the third case of `drop_drop`. -/\n\nlemma drop_drop {α : Type} :\n  ∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs\n| 0         n xs        := by refl\n| m         0 xs        := by simp [drop]\n| (m+1)     n xs        := by\nbegin\n    cases xs,\n    {\n      simp [drop],\n    },\n    { \n      simp [drop, drop_drop],\n      calc drop (n + (m + 1)) (xs_hd :: xs_tl)\n      = drop (n + m + 1) (xs_hd :: xs_tl): by refl,\n    }\nend\n-- supply the two missing cases here\n\nlemma take_take {α : Type} :\n  ∀ (m : ℕ) (xs : list α), take m (take m xs) = take m xs\n  | 0 xs := by simp [take]\n  | m [] := by simp [take]\n  | (n + 1) (x :: xs) := by simp [take, take_take]\n\nlemma take_drop {α : Type} :\n  ∀(n : ℕ) (xs : list α), take n xs ++ drop n xs = xs\n  | 0 xs := by simp [take, drop]\n  | m [] := by simp [take]\n  | (m + 1) (x :: xs) := by simp [take, drop, take_drop]\n\n/-! ## Question 3: A Type of λ-Terms\n\n3.1. Define an inductive type corresponding to the untyped λ-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- λ-expression (e.g., `λx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\n-- enter your definition here\n\ninductive term : Type\n  | var (x: string) : term\n  | lam (x: string) (t: term): term\n  | app (t: term) (u: term): term\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 → string\n  | (term.var x) := x\n  | (term.lam x t) := \"λ\" ++ x ++ \",(\" ++ (term.repr t) ++ \")\"\n  | (term.app t u) := \"(\" ++ (term.repr t) ++ \" \" ++(term.repr u) ++ \")\"\n\n@[instance] def term.has_repr : has_repr term :=\n{ repr := term.repr }\n\n/-! 3.3. Test your textual representation: -/\n\n#eval (term.lam \"x\" (term.app (term.app (term.var \"y\") (term.var \"x\"))\n    (term.var \"x\")))\n  -- should print something like `(λx, ((y x) x))`\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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.9005297907896396, "lm_q1q2_score": 0.7989541752248823}}
{"text": "/-\nCOMP2009-ACE\n\nExercise 02 (Propositional logic)\n\n   We 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 ∨ ¬ P or raa : ¬¬ P → 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\nvariables P Q R : Prop\n\nopen classical\n\ntheorem raa : ¬ ¬ P → 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 e01 : (P → Q) → (R → P) → (R → Q) := \n---a)  provable intuitionistically\nbegin\n  assume pq rp r,\n  apply pq,\n  apply rp,\n  exact r,\nend\n\ntheorem e02 : (P → Q) → (P → R) → (Q → R) :=\n---c) not provable classically\nbegin\n  sorry,\nend\n\ntheorem e03 : (P → Q) → (Q → R) → (P → R) :=\n--a) provable intuitionistically\nbegin\n  assume pq qr pr,\n  apply qr,\n  apply pq,\n  exact pr,\nend\n\ntheorem e04 : P → (P → Q) → P ∧ Q :=\n--a) provable intuitionistically\nbegin\n  assume p pq,\n  constructor,\n  exact p,\n  apply pq,\n  exact p,\nend\n\ntheorem e05 : P ∨ Q → (P → Q) → Q :=\n--a) provable intuitionistically\nbegin\n  assume pq,\n  assume p2q,\n  cases pq with p q,\n  apply p2q,\n  exact p,\n  exact q,\nend\n\ntheorem e06 : (P → Q) → ¬ P ∨ Q :=\n--b) provable classically\nbegin\n  assume pq,\n  cases (em P) with p np,\n  right,\n  apply pq,\n  exact p,\n  left,\n  exact np,\nend\n\n\ntheorem e07 : (¬ P ∨ Q) → P → Q :=\n--a) provable intuitionistically\nbegin\n  assume npq p,\n  cases npq with np q,\n  have h: P ∨ Q,\n  left,\n  exact p,\n  have h: false,\n  apply np,\n  exact p,\n  cases h,\n  exact q,\nend\n\n\ntheorem e08 : ¬ (P ↔ ¬ P) :=\n--b) provable classically\nbegin\n  assume pnp,\n  cases pnp with pnp npp,\n  cases (em P) with p np,\n  cases (em ¬ P) with np1 p1,\n  apply np1,\n  exact p,\n  apply p1,\n  apply pnp,\n  exact p,\n  apply np,\n  apply npp,\n  exact np,\nend\n\n\ntheorem e09 : ¬ P ↔ ¬ ¬ ¬ P :=\n---a) provable intuitionistically\nbegin\n  constructor,\n  assume np,\n  assume nnp,\n  apply nnp,\n  exact np,\n  assume nnnp,\n  assume p,\n  apply nnnp,\n  assume np2,\n  apply np2,\n  exact p,\nend\n\ntheorem e10 : ((P → Q) → P) → P :=\n--b) provable classically\nbegin\n  assume pqp,\n  apply raa,\n  assume np,\n  apply np,\n  apply pqp,\n  assume p,\n  apply raa,\n  assume nq,\n  apply np,\n  exact p,\nend\n\n\n", "meta": {"author": "kyrran", "repo": "Lean", "sha": "915f45d695eb01a80e58916f03e8f7c1e878be8b", "save_path": "github-repos/lean/kyrran-Lean", "path": "github-repos/lean/kyrran-Lean/Lean-915f45d695eb01a80e58916f03e8f7c1e878be8b/ex02(e08).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8872046011730965, "lm_q1q2_score": 0.7989541650003102}}
{"text": "-- Prueba mediante encadenamiento de ecuaciones\n-- ============================================\n\n-- Sean a, b y c números reales. Demostrar que\n--    (a * b) * c = b * (a * c) \n\nimport data.real.basic\n\nvariables (a b c : ℝ)\n\n-- 1ª demostración\nexample : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc,\nend\n\n-- 2ª demostració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ª demostración\nexample : (a * b) * c = b * (a * c) :=\nby linarith\n\n-- 4ª demostración\nexample : (a * b) * c = b * (a * c) :=\nby finish\n\n-- 5ª demostración\nexample : (a * b) * c = b * (a * c) :=\nby ring\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_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8558511488056152, "lm_q1q2_score": 0.7988778319501533}}
{"text": "section propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro p,\n  by_contra,\n  have i := h p,\n  exact i,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro p,\n  by_contra,\n  have i := p h,\n  exact i,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  intro p,\n  by_contra,\n  exact p h,\n  intro p,\n  by_contra,\n  exact h p,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro p,\n  cases p,\n  right,\n  exact p,\n  left,\n  exact p,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro p,\n  cases p with q r,\n  split,\n  exact r,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intros p q,\n  cases p,\n  by_contra,\n  exact p q,\n  exact p,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intros p q,\n  cases p,\n  by_contra,\n  exact q p,\n  exact p,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros p q r,\n  have i := p r,\n  exact q i,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros p q,\n  by_contra,\n  have i := p h,\n  exact i q,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  intros p q r,\n  have i := p r,\n  exact q i,\n  intros p q,\n  by_contra,\n  have i := p h,\n  exact i q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro p,\n  apply p,\n  right,\n  by_contra,\n  have q : P ∨ ¬P,\n  left,\n  exact h,\n  have i := p q,\n  exact i,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros p q,\n  have r : P,\n  apply p,\n  intro s,\n  exfalso,\n  exact q s,\n  exact q r,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intros p q,\n  cases q with r s,\n  cases p,\n  exact r p,\n  exact s p,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intros p q,\n  cases p with r s,\n  cases q with t u,\n  exact t r,\n  exact u s,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_ndisj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro p,\n  split,\n  by_contra,\n  have q : P ∨ Q,\n  left,\n  exact h,\n  exact p q,\n  by_contra,\n  have q : P ∨ Q,\n  right,\n  exact h,\n  exact p q,\nend\n\ntheorem demorgan_ndisj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros p q,\n  cases p with r s,\n  cases q with j k,\n  exact r j,\n  exact s k,\nend\n\ntheorem demorgan_nconj_converse :\n   (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros p q,\n  cases p with r s,\n  cases q with j k,\n  exact r k,\n  cases q with x z,\n  exact s x,\nend\n\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro p,\n  cases p with q r,\n  cases r with s t,\n  left,\n  split,\n  exact q,\n  exact s,\n  right,\n  split,\n  exact q,\n  exact t,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro p,\n  cases p with q r,\n  split,\n  cases q with s t,\n  exact s,\n  cases q with u v,\n  left,\n  exact v,\n  cases r with w x,\n  split,\n  exact w,\n  right,\n  exact x,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro p,\n  split,\n  cases p with q r s,\n  left,\n  exact q,\n  cases r with t u,\n  right,\n  exact t,\n  cases p with v w,\n  left,\n  exact v,\n  cases w with x y,\n  right,\n  exact y,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro p,\n  cases p with q r,\n  cases q,\n  left,\n  exact q,\n  cases r,\n  left,\n  exact r,\n  right,\n  split,\n  exact q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros p q r,\n  apply p,\n  split,\n  exact q,\n  exact r,\nend\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros p q,\n  apply p,\n  cases q with r s,\n  exact r,\n  cases q with r s,\n  exact s,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro p,\n  right,\n  exact p,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro p,\n  cases p with q r,\n  exact q,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro p,\n  cases p with q r,\n  exact r,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro p,\n  cases p with q r,\n  exact q,\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idemp :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro p,\n  cases p,\n  exact p,\n  exact p,\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intros p,\n  cases p with q r,\n  intro s,\n  have i := s q,\n  exact r i,\nend\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros p q r,\n  apply p,\n  existsi q,\n  exact r,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros p q,\n  cases q with r s,\n  have i := p r,\n  exact i s,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro p,\n  by_contra r,\n  apply p,\n  intro q,\n  by_contra,\n  apply r,\n  existsi q,\n  exact h,\nend  \n  \ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_forall,\n  apply demorgan_forall_converse,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_exists,\n  apply demorgan_exists_converse,\nend\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros p q,\n  cases p with r s,\n  have i := q r,\n  exact i s,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros p q,\n  cases q with r s,\n  have i := p r,\n  exact s i,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intros p q,\n  by_contra,\n  apply p,\n  existsi q,\n  exact h,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro p,\n  by_contra,\n  apply p,\n  intros q r,\n  apply h,\n  existsi q,\n  exact r,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro p,\n  cases p with q r,\n  cases r with s t,\n  split,\n  existsi q,\n  exact s,\n  existsi q,\n  exact t,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro p,\n  cases p with q r,\n  cases r with s t,\n  left,\n  existsi q,\n  exact s,\n  right,\n  existsi q,\n  exact t,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro p,\n  cases p with q r,\n  cases q with s t,\n  existsi s,\n  left,\n  exact t,\n  cases r with s t,\n  existsi s,\n  right,\n  exact t,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro p,\n  split,\n  intro q,\n  by_contra,\n  have i := p q,\n  cases i with j k,\n  exact h j,\n  intro s,\n  have i := p s,\n  cases i with j k,\n  by_contra,\n  exact h k,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intros p q,\n  split,\n  cases p with r s,\n  have i := r q,\n  by_contra,\n  exact h i,\n  cases p with r s,\n  by_contra,\n  have i := s q,\n  exact h i,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intros p q,\n  cases p with r s,\n  have i := r q,\n  left,\n  by_contra,\n  exact h i,\n  have i := s q,\n  right,\n  by_contra,\n  exact h i,\nend\n\n\n/--NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\n  intro p,\n  right,\n  intro q,\n  have i := p q,\n  cases i,\n  --teorema inválido\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\n  intro p,\n  cases p with q r,\n  cases q with s t,\n  cases r with u v,\n  existsi u,\n  split,\n  --teorema inválido\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "felliperoq", "repo": "fmclean", "sha": "284181d1fdb2e8191ce9bbd85fbc0fdecf2a1c6d", "save_path": "github-repos/lean/felliperoq-fmclean", "path": "github-repos/lean/felliperoq-fmclean/fmclean-284181d1fdb2e8191ce9bbd85fbc0fdecf2a1c6d/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7988778302341752}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio . Demostrar que, para todo númeo real a,\n--    0 ≤ a^2\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nimport tactic\n\nexample (a : ℝ) : 0 ≤ a^2 :=\nbegin\n  -- library_search,\n  exact pow_two_nonneg a,\nend\n\n-- Notas:\n-- + Nota 1: Al colocar el cursor sobre library_search (después de descomentar\n--   la línea) escribe el mensaje\n--      Try this: exact pow_two_nonneg a\n-- + Nota 2: Para usar library_search hay que importar tactic.\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/Uso_de_library_search.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7988357893699167}}
{"text": "import tutorial_world.incidenceplane --hide\nopen IncidencePlane --hide\n\n/- Axiom :\nline_through_left (P Q : Ω) : P ∈ (line_through P Q)\n-/\n/- Axiom :\nline_through_right (P Q : Ω) : Q ∈ (line_through P Q)\n-/\n\n/-\n# Tutorial World\n\n## Level 5: the `theorem statements`.\n\nTo solve this level, we need to introduce a new section that appears on the left side of the screen, which is called\n**Theorem statements**.  Click on the top left menu where it says **\"Theorem statements\"** and display the **\"Tutorial\nWorld\"** box to discover what we are talking about. As you can see, two new statements have been added to the list. \n\n* line_through_left (P Q : Ω) : P ∈ (line_through P Q)\n\n* line_through_right (P Q : Ω) : Q ∈ (line_through P Q)\n\n**Note the name of the two statements**. Mathematicians sometimes call them \"Lemma 2.1\" or \"Hypothesis P6\" or something. But\ncomputer scientists call them `line_through_left` and `line_through_right` because they are easier to use and remember. From now on,\nall the statements that appear on this list will be remembered by the computer. In this way, we won't have to provide their proofs again.\nInstead of this, we will use them straightforwardly in case they are handy for solving the following levels. \n\nJust after the name of the statements, two parentheses appear. Inside them, there are the exact number of variables that are needed to\nput out that statements. Then, the colon **:** symbol introduces the statement as such. In this case, they are very similar to each other.\nWhat they come to mean is that we can draw a line that passes through two distinct points (P and Q) that lie in a plane (Ω). They symbol **∈**\nis read as **\"is an element of\"**. Then, P and Q are elements of the line that passes through the points P and Q. Seems obvious, right? Now, let's \ntry to solve this level! \n\nDelete the `sorry` and watch the goal appear as `⊢ B ∈ line_through A B`. Presumably, the goal shows the same structure as\nthe statement `line_through_right (P Q : Point) : Q ∈ (line_through P Q)`. Then, we just have to write that statement in a different way! \n-- How do we change the points P and Q for the points A and B? -- Follow the same structure of the statement we need to use. Do you remember that the `exact` \ntactic solved the goal by using a hypothesis of the same structure? Then, because the computer already knows what\n`line_through_right (P Q : Point) : Q ∈ (line_through P Q)` means, why don't we type `exact line_through_right A B,`? Type that and see \nhow it finishes the proof! [**Don't forget to write the variables A and B. They are needed to use the statement**.]\n\n-/\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\n\n/- Lemma :  no-side-bar\nA point lies in the line that passes through it.\n-/\nlemma point_on_line {A B : Ω} {r : Line Ω} :\nB ∈ line_through A B :=\nbegin\n  \n  exact line_through_right A B,\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/level05_lemma_usage.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.798835780931405}}
{"text": "theorem easy (P Q: Prop) (HP : P) (HPQ: P → Q) : Q :=\n    begin\n        apply HPQ, -- now i just have to prove p -> Q\n        exact HP -- i know HP of P \n    end\n\ntheorem prove_P_implies_Q (P Q : Prop)(HQ: Q): P → Q :=\n    begin\n        intro HP, -- assume HP of  P\n        exact HQ,\n    end\n\ntheorem P_implies_P (P: Prop) : P → P := \n    begin -- assume HP of P\n        intro HP,\n        apply HP\n    end \n\ntheorem needs_intros (P Q R : Prop)(HR : R): P → Q → R :=\n    begin\n        intro HP, \n        -- we have a proof of HP of P\n        intro HQ,\n        -- we have a proof of HQ of Q\n        exact HR\n    end \n\ntheorem very_easy : true :=\nbegin\n    exact trivial,\nend\n\n\ntheorem very_hard : false :=\nbegin\n    sorry,\nend\n\ntheorem false_implies_false: false → false :=\n    begin \n        intro Hfalse,\n        exact Hfalse,\n    end\n\ntheorem not_not (P: Prop): P → ¬ (¬ P) :=\n                            -- ¬ P → ¬r P\nbegin\n    intro HP,\n    intro HnP,\n    apply HnP,\n    exact HP,\nend\n\ntheorem contrapositive\n  (P Q : Prop) (HPQ : P → Q) : ¬ Q → ¬ P :=\nbegin\n    intro HnQ,\n    intro HP,\n    apply HnQ,\n    apply HPQ,\n    exact HP\nend \n#print contrapositive\n\ntheorem P_imples_P_or_Q (P Q: Prop) (HP: P) : P ∨ Q :=\nbegin\n    left,\n    exact HP,\nend\n#print P_imples_P_or_Q\n\ntheorem Q_imples_P_or_Q (P Q: Prop) (HQ: Q): P ∨ Q :=\nbegin\n    right,\n    exact HQ,\nend\n#print Q_imples_P_or_Q\n\ntheorem or_symmetry (P Q: Prop): P ∨ Q → Q ∨ P :=\nbegin\n    intro HPQ,\n    cases HPQ with HP HQ,\n    { right,\n      exact HP,\n    },\n    { left,\n      exact HQ,\n    },\nend\n#print or_symmetry\n\ntheorem or_associative (P Q R: Prop):\nP ∨ (Q ∨ R) → (P ∨ Q) ∨ R :=\nbegin\n    intro HPQR,\n    cases HPQR with HP HQR, \n    { \n        left,\n      { \n          left,\n          exact HP,\n      } \n    },\n    cases HQR with HQ' HR', \n    {\n        left,\n        {\n            right,\n            exact HQ',\n        }\n    },\n    {   \n        right,\n        exact HR',\n    }\nend\n#print or_associative\n\n\ntheorem and_definition (P Q: Prop)(HP : P)(HQ: Q): P ∧ Q :=\nbegin\n    split,\n        {exact HP,}\n        {exact HQ,}\nend\n#print and_definition\n\ntheorem and_symmetric(P Q: Prop): P ∧ Q → Q ∧ P :=\nbegin \n    intro HPQ,\n    cases HPQ with HP HQ,\n    split,\n        {exact HQ,},\n        {exact HP,},\nend\n#print and_symmetric\n\ntheorem and_transitive(P Q R: Prop):\n(P ∧ Q) ∧ (Q ∧ R) → (P ∧ R) :=\nbegin\n    intro HPQandHQR,\n    cases HPQandHQR with HPQ HQR,\n        cases HPQ with HP HQ,\n            split, \n                {exact HP,},\n        cases HQR with HQ' HR,\n            exact HR,\nend\n#print and_transitive\n", "meta": {"author": "krismanaya", "repo": "learnLean", "sha": "784123bb6598cba00ddee7193230a5b79ea7f86a", "save_path": "github-repos/lean/krismanaya-learnLean", "path": "github-repos/lean/krismanaya-learnLean/learnLean-784123bb6598cba00ddee7193230a5b79ea7f86a/src/hw1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229948845201, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7988357751294168}}
{"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# `finset X` is a lattice\n\nRecall that a lattice is just a partially ordered set where every pair {a,b} of elements has\nan inf `a ⊓ b` and a sup `a ⊔ b`. The type of finite subsets of `X`, ordered by inclusion,\nhas this property (because the union or intersection of two finite sets is finite).\nThis lattice structure is inbuilt in Lean. \n\n-/\n\n-- Let X be a type\nvariables (X : Type)\n\n-- Assume the law of the excluded middle\nopen_locale classical\n\n-- Don't worry about whether functions are computable\nnoncomputable theory\n\n-- Then, finally, the type of finite subsets of X has a lattice structure \nexample : lattice (finset X) := infer_instance -- the square bracket system knows this\n\nexample (a b : finset X) : finset X := a ⊔ b -- sups (and infs) make sense \n\n-- The lattice also has a `⊥`, the smallest finite subset of `X`, namely the empty set.\n\nexample : finset X := ⊥ \n\n-- But for general `X` it does not have a `⊤`, because if `X` is infinite then it doesn't\n-- have a largest finite subset\n\n-- example : finset X := ⊤ -- error\n\n-- If `Y` is another type, then you can push finsets forward along maps from X to Y\nvariables (Y : Type) (f : X → Y)\n\nexample (S : finset X) : finset Y := finset.image f S \n\n-- See if you can prove these. You'll have to figure out the basic API\n-- for `finset.image`.\n\nexample (S : finset X) (y : Y) : y ∈ S.image f ↔ ∃ x ∈ S, f x = y :=\nbegin\n  sorry,\nend\n\nexample (S : finset X) (x : X) (hx : x ∈ S) : f x ∈ S.image f :=\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/section08finiteness/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966747198242, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7988282923159055}}
{"text": "import algebra.group_power tactic.norm_num algebra.big_operators\n\ndef factorial : ℕ → ℕ\n| 0 := 1\n| (n+1) := (factorial n) * (n+1)\n\ntheorem Q4 (n : ℕ) (H : n > 0) : factorial n < 3^n ↔ n ≤ 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 ≥ 3 := by exact dec_trivial,\nexact calc\nfactorial (nat.succ e) = factorial e * (nat.succ e) : by unfold factorial\n... ≥ factorial e * 3 : nat.mul_le_mul_left _ He_ge_3\n... ≥ 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\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/0504/S0504.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172630429474, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7988228891493159}}
{"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 0a0ec35061ed9960bf0e7ffb0335f44447b58977\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.Associated\nimport Mathlib.Data.Nat.Choose.Sum\nimport Mathlib.Data.Nat.Choose.Dvd\nimport Mathlib.Data.Nat.Parity\nimport Mathlib.Data.Nat.Prime\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 ≤ 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/-- The primorial `n#` of `n` is the product of the primes less than or equal to `n`.\n-/\ndef primorial (n : ℕ) : ℕ :=\n  ∏ p in filter Nat.Prime (range (n + 1)), p\n#align primorial primorial\n\n-- mathport name: «expr #»\nlocal notation x \"#\" => primorial x\n\ntheorem primorial_pos (n : ℕ) : 0 < n# :=\n  prod_pos fun _p hp ↦ (mem_filter.1 hp).2.pos\n#align primorial_pos primorial_pos\n\ntheorem primorial_succ {n : ℕ} (hn1 : n ≠ 1) (hn : Odd n) : (n + 1)# = 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 fun h ↦ h.even_sub_one <| mt succ.inj hn1\n#align primorial_succ primorial_succ\n\ntheorem primorial_add (m n : ℕ) :\n    (m + n)# = m# * ∏ p in filter Nat.Prime (Ico (m + 1) (m + n + 1)), p := by\n  rw [primorial, primorial, ← Ico_zero_eq_range, ← prod_union, ← filter_union, Ico_union_Ico_eq_Ico]\n  exacts [Nat.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\ntheorem primorial_add_dvd {m n : ℕ} (h : n ≤ m) : (m + n)# ∣ m# * choose (m + n) m :=\n  calc\n    (m + n)# = m# * ∏ p in filter Nat.Prime (Ico (m + 1) (m + n + 1)), p := primorial_add _ _\n    _ ∣ 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 ↦ by\n          rw [mem_filter, mem_Ico] at hp\n          exact 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#align primorial_add_dvd primorial_add_dvd\n\ntheorem primorial_add_le {m n : ℕ} (h : n ≤ m) : (m + n)# ≤ 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\ntheorem primorial_le_4_pow (n : ℕ) : n# ≤ 4 ^ n := by\n  induction' n using Nat.strong_induction_on with n ihn\n  cases' n with n; · rfl\n  rcases n.even_or_odd with (⟨m, rfl⟩ | ho)\n  · rcases m.eq_zero_or_pos with (rfl | hm)\n    · decide\n    calc\n      (m + m + 1)# = (m + 1 + m)# := by rw [add_right_comm]\n      _ ≤ (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      _ ≤ 4 ^ (m + 1) * 4 ^ m :=\n        mul_le_mul' (ihn _ <| succ_lt_succ <| (lt_add_iff_pos_left _).2 hm) (choose_middle_le_pow _)\n      _ ≤ 4 ^ (m + m + 1) := by rw [← pow_add, add_right_comm]\n  · rcases Decidable.eq_or_ne n 1 with (rfl | hn)\n    · decide\n    · calc\n        (n + 1)# = n# := primorial_succ hn ho\n        _ ≤ 4 ^ n := ihn n n.lt_succ_self\n        _ ≤ 4 ^ (n + 1) := pow_le_pow_of_le_right four_pos n.le_succ\n#align primorial_le_4_pow primorial_le_4_pow\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/Primorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.7986357326720259}}
{"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-/\n\nimport data.polynomial.derivative\nimport logic.function.iterate\nimport data.finset.intervals\nimport tactic.ring\nimport tactic.linarith\n\n/-!\n# Theory of iterated derivative\nWe define and prove some lemmas about iterated (formal) derivative for polynomials over a semiring.\n-/\n\nnoncomputable theory\n\nopen finset nat polynomial\nopen_locale big_operators\n\nnamespace polynomial\nuniverses u\nvariable {R : Type u}\n\nsection semiring\n\nvariables [semiring R] (r : R) (f p q : polynomial R) (n k : ℕ)\n\n/-- `iterated_deriv f n` is the `n`-th formal derivative of the polynomial `f` -/\ndef iterated_deriv : polynomial R := derivative ^[n] f\n\n@[simp] lemma iterated_deriv_zero_right : iterated_deriv f 0 = f := rfl\n\nlemma iterated_deriv_succ : iterated_deriv f (n + 1) = (iterated_deriv f n).derivative :=\nby rw [iterated_deriv, iterated_deriv, function.iterate_succ']\n\n@[simp] lemma iterated_deriv_zero_left : iterated_deriv (0 : polynomial R) n = 0 :=\nbegin\n  induction n with n hn,\n  { exact iterated_deriv_zero_right _ },\n  { rw [iterated_deriv_succ, hn, derivative_zero] },\nend\n\n@[simp] lemma iterated_deriv_add :\n  iterated_deriv (p + q) n = iterated_deriv p n + iterated_deriv q n :=\nbegin\n  induction n with n ih,\n  { simp only [iterated_deriv_zero_right], },\n  { simp only [iterated_deriv_succ, ih, derivative_add] }\nend\n\n@[simp] lemma iterated_deriv_smul : iterated_deriv (r • p) n = r • iterated_deriv p n :=\nbegin\n  induction n with n ih,\n  { simp only [iterated_deriv_zero_right] },\n  { simp only [iterated_deriv_succ, ih, derivative_smul] }\nend\n\n@[simp] lemma iterated_deriv_X_zero : iterated_deriv (X : polynomial R) 0 = X :=\nby simp only [iterated_deriv_zero_right]\n\n@[simp] lemma iterated_deriv_X_one : iterated_deriv (X : polynomial R) 1 = 1 :=\nby simp only [iterated_deriv, derivative_X, function.iterate_one]\n\n@[simp] lemma iterated_deriv_X (h : 1 < n) : iterated_deriv (X : polynomial R) n = 0 :=\nbegin\n  induction n with n ih,\n  { exfalso, exact not_lt_zero 1 h},\n  { simp only [iterated_deriv_succ],\n    by_cases H : n = 1,\n    { rw H, simp only [iterated_deriv_X_one, derivative_one] },\n    { replace h : 1 < n := array.push_back_idx h (ne.symm H),\n      rw ih h, simp only [derivative_zero] } }\nend\n\n\n@[simp] lemma iterated_deriv_C_zero : iterated_deriv (C r) 0 = C r :=\n  by simp only [iterated_deriv_zero_right]\n\n@[simp] lemma iterated_deriv_C (h : 0 < n) : iterated_deriv (C r) n = 0 :=\nbegin\n  induction n with n ih,\n  { exfalso, exact nat.lt_asymm h h },\n  { by_cases H : n = 0,\n    { rw [iterated_deriv_succ, H], simp only [iterated_deriv_C_zero, derivative_C]},\n    { replace h : 0 < n := nat.pos_of_ne_zero H,\n      rw [iterated_deriv_succ, ih h], simp only [derivative_zero] } }\nend\n\n@[simp] lemma iterated_deriv_one_zero : iterated_deriv (1 : polynomial R) 0 = 1 :=\nby simp only [iterated_deriv_zero_right]\n\n@[simp] lemma iterated_deriv_one : 0 < n → iterated_deriv (1 : polynomial R) n = 0 := λ h,\nbegin\n  have eq1 : (1 : polynomial R) = C 1 := by simp only [ring_hom.map_one],\n  rw eq1, exact iterated_deriv_C _ _ h,\nend\n\nend semiring\n\nsection ring\nvariables [ring R] (p q : polynomial R) (n : ℕ)\n\n@[simp] lemma iterated_deriv_neg : iterated_deriv (-p) n = - iterated_deriv p n :=\nbegin\n  induction n with n ih,\n  { simp only [iterated_deriv_zero_right] },\n  { simp only [iterated_deriv_succ, ih, derivative_neg] }\nend\n\n@[simp] lemma iterated_deriv_sub :\n  iterated_deriv (p - q) n = iterated_deriv p n - iterated_deriv q n :=\nby rw [sub_eq_add_neg, iterated_deriv_add, iterated_deriv_neg, ←sub_eq_add_neg]\n\n\nend ring\n\nsection comm_semiring\nvariable [comm_semiring R]\nvariables (f p q : polynomial R) (n k : ℕ)\n\nlemma coeff_iterated_deriv_as_prod_Ico :\n  ∀ m : ℕ, (iterated_deriv f k).coeff m = (∏ i in Ico m.succ (m + k.succ), i) * (f.coeff (m+k)) :=\nbegin\n  induction k with k ih,\n  { simp only [add_zero, forall_const, one_mul, Ico.self_eq_empty, eq_self_iff_true,\n      iterated_deriv_zero_right, prod_empty] },\n  { intro m, rw [iterated_deriv_succ, coeff_derivative, ih (m+1), mul_right_comm],\n    apply congr_arg2,\n    { have set_eq : (Ico m.succ (m + k.succ.succ)) = (Ico (m + 1).succ (m + 1 + k.succ)) ∪ {m+1},\n      { rw [union_comm, ←insert_eq, Ico.insert_succ_bot, add_succ, add_succ, add_succ _ k,\n            ←succ_eq_add_one, succ_add],\n        rw succ_eq_add_one,\n        linarith },\n      rw [set_eq, prod_union],\n      apply congr_arg2,\n      { refl },\n      { simp only [prod_singleton], norm_cast },\n      { simp only [succ_pos', disjoint_singleton, and_true, lt_add_iff_pos_right, not_le, Ico.mem],\n        exact lt_add_one (m + 1) } },\n    { exact congr_arg _ (succ_add m k) } },\nend\n\nlemma coeff_iterated_deriv_as_prod_range :\n  ∀ m : ℕ, (iterated_deriv f k).coeff m = f.coeff (m + k) * (∏ i in range k, ↑(m + k - i)) :=\nbegin\n  induction k with k ih,\n  { simp },\n  intro m,\n  calc (f.iterated_deriv k.succ).coeff m\n      = f.coeff (m + k.succ) * (∏ i in range k, ↑(m + k.succ - i)) * (m + 1) :\n    by rw [iterated_deriv_succ, coeff_derivative, ih m.succ, succ_add, add_succ]\n  ... = f.coeff (m + k.succ) * (∏ i in range k, ↑(m + k.succ - i)) * ↑(m + 1) :\n    by push_cast\n  ... = f.coeff (m + k.succ) * (∏ i in range k.succ, ↑(m + k.succ - i)) :\n    by rw [prod_range_succ, nat.add_sub_assoc k.le_succ, succ_sub le_rfl, nat.sub_self, mul_assoc]\nend\n\nlemma iterated_deriv_eq_zero_of_nat_degree_lt (h : f.nat_degree < n) : iterated_deriv f n = 0 :=\nbegin\n  ext m,\n  rw [coeff_iterated_deriv_as_prod_range, coeff_zero, coeff_eq_zero_of_nat_degree_lt, zero_mul],\n  linarith\nend\n\nlemma iterated_deriv_mul :\n  iterated_deriv (p * q) n =\n  ∑ k in range n.succ,\n    (C (n.choose k : R)) * iterated_deriv p (n - k) * iterated_deriv q k :=\nbegin\n  induction n with n IH,\n  { simp },\n\n  calc (p * q).iterated_deriv n.succ\n      = (∑ (k : ℕ) in range n.succ,\n           C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv k).derivative :\n    by rw [iterated_deriv_succ, IH]\n  ... = ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k + 1) * q.iterated_deriv k +\n        ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) :\n    by simp_rw [derivative_sum, derivative_mul, derivative_C, zero_mul, zero_add,\n                iterated_deriv_succ, sum_add_distrib]\n  ... = (∑ (k : ℕ) in range n.succ,\n            C ↑(n.choose k.succ) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) +\n          C ↑1 * p.iterated_deriv n.succ * q.iterated_deriv 0) +\n        ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) : _\n  ... = ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) +\n        ∑ (k : ℕ) in range n.succ,\n            C ↑(n.choose k.succ) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) +\n        C ↑1 * p.iterated_deriv n.succ * q.iterated_deriv 0 :\n    by ring\n  ... = ∑ (i : ℕ) in range n.succ,\n          C ↑((n+1).choose (i+1)) * p.iterated_deriv (n + 1 - (i+1)) * q.iterated_deriv (i+1) +\n        C ↑1 * p.iterated_deriv n.succ * q.iterated_deriv 0 :\n    by simp_rw [choose_succ_succ, succ_sub_succ, cast_add, C.map_add, add_mul, sum_add_distrib]\n  ... = ∑ (k : ℕ) in range n.succ.succ,\n          C ↑(n.succ.choose k) * p.iterated_deriv (n.succ - k) * q.iterated_deriv k :\n    by rw [sum_range_succ' _ n.succ, choose_zero_right, nat.sub_zero],\n\n  congr,\n  refine (sum_range_succ' _ _).trans (congr_arg2 (+) _ _),\n  { rw [sum_range_succ, nat.choose_succ_self, cast_zero, C.map_zero, zero_mul, zero_mul, add_zero],\n    refine sum_congr rfl (λ k hk, _),\n    rw mem_range at hk,\n    congr,\n    rw [← nat.sub_add_comm (nat.succ_le_of_lt hk), nat.succ_sub_succ] },\n  { rw [choose_zero_right, nat.sub_zero] },\nend\n\nend comm_semiring\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/iterated_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.8652240964782012, "lm_q1q2_score": 0.7986357232853792}}
{"text": "import data.real.basic\n\nopen_locale classical\n\n/-\nTheoretical negations.\n\nThis file is for people interested in logic who want to fully understand\nnegations.\n\nHere we don't use `contrapose` or `push_neg`. The goal is to prove lemmas\nthat are used by those tactics. Of course we can use\n`exfalso`, `by_contradiction` and `by_cases`.\n\nIf this doesn't sound like fun then skip ahead to the next file.\n-/\n\nsection negation_prop\n\nvariables P Q : Prop\n\n-- 0055\nexample : (P → Q) ↔ (¬ Q → ¬ P) :=\nbegin\n  split, intro h, intro j, by_contradiction hyp, exact j (h hyp),\n  intro h, intro p, by_contradiction qn, exact h qn p,\nend\n\n-- 0056\nlemma non_imp (P Q : Prop) : ¬ (P → Q) ↔ P ∧ ¬ Q :=\nbegin\n  split, intro h, split, by_contradiction np,\n  have k : P → Q, intro p, exfalso, exact np p, exact h k,\n  intro q, have k : P → Q, intro p, exact q, exact h k,\n  intro h, cases h with p qn, intro j, exact qn (j p),\nend\n\n-- In the next one, let's use the axiom\n-- propext {P Q : Prop} : (P ↔ Q) → P = Q\n\n-- 0057\nexample (P : Prop) : ¬ P ↔ P = false :=\nbegin\n  split, intro h, apply propext, split, intro j, exact h j, intro p, exfalso, exact p,\n  intro h, intro j, rw h at j, exact j,\nend\n\nend negation_prop\n\nsection negation_quantifiers\nvariables (X : Type) (P : X → Prop)\n\n-- 0058\nexample : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x :=\nbegin\n  split, intro h, by_contradiction hyp, apply h, intro x, by_contradiction j, exact hyp ⟨x,j⟩,\n  intro h, intro hyp, cases h with x hx, exact hx (hyp x),\nend\n\n-- 0059\nexample : ¬ (∃ x, P x) ↔ ∀ x, ¬ P x :=\nbegin\n  split, intros h x hx, exact h ⟨x, hx⟩,\n  intros h j, cases j with x hx, exact h x hx, \nend\n\n-- 0060\nexample (P : ℝ → Prop) : ¬ (∃ ε > 0, P ε) ↔ ∀ ε > 0, ¬ P ε :=\nbegin\n  split, intros h ε ε_pos hε, apply h, use [ε,ε_pos,hε],\n  intros h j, rcases j with ⟨ε,ε_pos,hε⟩, exact h ε ε_pos hε,  \nend\n\n-- 0061\nexample (P : ℝ → Prop) : ¬ (∀ x > 0, P x) ↔ ∃ x > 0, ¬ P x :=\nbegin\n  split, intro h, by_contradiction hyp, apply h, intros x x_pos, by_contradiction hp,\n  apply hyp, use [x,x_pos,hp],\n  intros h j, rcases h with ⟨x,hx,px⟩, exact px (j x hx), \nend\n\nend negation_quantifiers\n\n", "meta": {"author": "yqaddur1", "repo": "Lean", "sha": "16ddbf6da45e28bf1de59171113537cebe2858fa", "save_path": "github-repos/lean/yqaddur1-Lean", "path": "github-repos/lean/yqaddur1-Lean/Lean-16ddbf6da45e28bf1de59171113537cebe2858fa/tutorials/src/myexercises/07bis_abstract_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8740772253241803, "lm_q1q2_score": 0.7986238322110291}}
{"text": "/-***************-/\n/- ** BASICS ** --/\n/-***************-/\n\n/-\n# \n\nWrite a defintion of x as a value of \ntype nat having the specific value 0.\nBe sure it type-checks. \n-/\n\ndef x : nat := 0\n\ndef x' := 0 \n\n/-\n# \n\nWrite a definition of f as a function\nof type ℕ → ℕ that returns the square of\nthe value to which it is applied (i.e.,\nthat it is given as an argument)\n-/\n\ndef square' (n : nat) : nat := n^2 \n\n#check square'\n\ndef square : ℕ → ℕ := λ n : nat, n^2\n\n/-\n#\n\nWrite a definition of a function, nt, that\ntakes any proposition, P, and that returns\nthe proposition, P → false. \n-/\n\ndef nt (P : Prop) : Prop := P → false\n\n#check nt\n\ndef isZero (n : nat) : Prop := 0 = n\n\n#reduce isZero 3\n\n/-\n#\n\nWhat is the type of this function? Hint:\nUse #check to check it.\n-/\n\n\n/-****************************************-/\n/- ** PROOFS OF EQUALITY PROPOSITIONS ** --/\n/-****************************************-/\n\n\n/-\n#1 \n\nWrite a function, teqt, that takes any type, \nT : Type, and any value, t : T, and that \nreturns a proof of t = t.\n-/\n\ndef teqt (T : Type) (t: T) := eq.refl t\n\ndef teqt' : ∀ (T : Type), ∀ (t : T), (t = t) := \n    λ X x, eq.refl x\n\ndef teqt'' (T : Type) := λ t : T, t = t\n\n#check teqt''\n\n\n#check teqt\n\n/-\n#2a\n\nWrite a function that takes any type, T; three values, \na, b, and c, of type T; a proof of a = b; and a proof \nof b = c; and that returns a proof of c = a. We give\nyou most of the answer. Replace the sorry with your\nanswer.  \n-/\n\ndef aBbCCa : ∀ (T : Type), ∀ (a b c: T), \n    (a = b) -> (b = c) → (c = a) :=\n        λ X a b c ab bc, \n            eq.symm (eq.trans ab bc)\n\n\n-- This is equivalent\ndef aBbCCa''\n    { T : Type } \n    (a b c : T)\n    (ab : a = b)\n    (bc: b = c) :\n    (c = a) \n    :=\nbegin\nhave ac := eq.trans ab bc,\nshow c = a,\nfrom eq.symm ac\nend\n\n\n/-\n#2b.\n\nDefine aBbCCa' to be the same function, but specify \nits type using ∀ and → connectives, and then provide\nthe function value using a lambda expression (λ). So\nyou will start with \"def\", then the name, then a :,\nthen the proposition, starting with ∀ and ending with\n→ (c = a), followed by :=, and finally follwed by a\nlambda expression.\n-/\n\ndef aBbCCa' : \n    ∀ T : Type, ∀ a b c : T, (a = b) → (b = c) → (c = a) :=\n        λ T a b c ab bc,\n            eq.symm (eq.trans ab bc)\n            \n\n/-*******************************-/\n/- ** PROOFS OF CONJUNCTIONS ** --/\n/-*******************************-/\n\n/-\nWe assume P Q and R are propositions using the\nfollowing \"variables\" declaration. That means that\nwe can use P, Q, R, and S in the following theorems\nwithout having to use ∀ P Q R S : Prop to introduce\nthem again for each individual proposition.\n-/\n\nvariables P Q R S : Prop\n\n/-\nProve the following propositions by completing\nthe definitions (replace sorrys with your answers).\n-/\n\ntheorem t1 : P → Q → R → P := \n  λ p q r, p\n\n#check t1\n\ntheorem t2 : Q → (Q ∧ Q) := \n    λ (q : Q), and.intro q q \n\ntheorem t3 : (P ∧ Q) ∧ (Q ∧ R) → (P ∧ R) := \nbegin\nassume pqqr : (P ∧ Q) ∧ (Q ∧ R),\nhave pq : P ∧ Q := pqqr.left,\nhave qr := pqqr.right,\nhave p := pq.left,\nhave r := qr.right,\napply and.intro p r\nend \n\n/- This is a shorter version!\n   λ pqqr : ((P ∧ Q) ∧ (Q ∧ R)), \n        and.intro (pqqr.left.left) pqqr.right.right\n-/\n\n\n/-*******************************-/\n/- ** PROOFS OF IMPLICATIONS ** --/\n/-*******************************-/\n\n/-\nProve the following theorem. It claims that\nimplication is transitive (which it is).\n-/\n\ntheorem t4 : ((P → Q) ∧ P) → Q := \nλ pqp, pqp.left pqp.right\n\ntheorem t5 : \n    (P → Q) → (Q → R) → (R → S) → (P → S) := \n        λ pq qr rs,\n            λ p, rs (qr (pq p))      \n\n\n/-******************-/\n/- ** Functions ** --/\n/-******************-/\n\n\n/-\nComplete the following definition\nwith a value that makes the definition\ntype-check. You can answer with a\nlambda expression. You can also\nuse a tactic script if you prefer.\n-/\ndef n2n : ℕ → ℕ := \n    λ n, 0\n\n/-\nDefine a function called double \nthat takes any natural number, n, \nand returns two times n. \n-/\n\ndef double : ℕ → ℕ := λ n, 2 * n\n\n\n\n/-\nWrite a test case for double\nin the form of a theorem called\nd15is30, that asserts that the\ndouble of 15 is 30, and prove it.\n-/\n\ntheorem d15is30 : double 15 = 30 := rfl \n\n/-\nWrite a function, sum3, that takes three \nnatural numbers, a, b, c, and that returns\nthe sum of a, b, and c. Use a λ expression\nto express the function.\n-/\n\n\ndef sum' :=\n    λ (a b c : nat), a + b + c\n-- Your answer here\n\n\n/-*****************-/\n/- ** NEGATION ** --/\n/-*****************-/\n\n/-\nYou already know that double\nnegation elimination requires\nclassical reasoning (using the \nlaw of the excluded middle).\nGive a proof of the following\nproposition, which asserts that\nit's valid to introduce double\nnegatations. Note: You do not \nneed the law of the excluded\nmiddle to prove it.\n-/\n\ndef t6 : P → ¬ ¬ P := \n    λ p np, np p\n\n/-\nYou've learned a few important \nproof strategies. Explain in a \nfew words when might a proof\nby negation be attempted, and \nhow one proceeds to use it.\n\nKnow the answer to the same\nquestion about a proof by\ncontradiction. \n-/\n\n/-\nExplain precisely why using a\nproof by contradiction relies\non classical reasoning using\nthe law of the excluded middle.\n-/\n\n/-\nEXTRA CREDIT: Write a function \nthat takes a function, f, of type\nℕ → ℕ, and that returns a function\nthat, for any value, n, returns \none more that what f returns. \n-/\n\n/-\nThat's the end of the practice test.\nHere's a partial inventory of inference\nrules we've covered. and related concepts.\nThis is not enough material for a complete\nreview. Reread all the notes and work any\nproblems that you're not yet sure you know\nhow to solve.\n-/\n\n\n/-\nPartial inventory of inference rules.\n\n* Equality\n-- eq.refl : given a type T and a value t : T, derives a proof of t = t\n-- eq.symm : given a type T, values a b : T, and a proof of a = b, derives a proof of b = a\n-- eq.trans : given a type T, values a b c : T, and proofs of a = b and b = c, derives a proof of a = c\n\n* Conjunction\n-- and.intro : given propositions, P Q : Prop, a proof P : P, and a proof q : Q, derives a proof of P ∧ Q\n-- and.elim_right : given propositions, P Q : Prop and a proof pq : P ∧ Q, derives a proof of P\n-- and.elim_right : given propositions, P Q : Prop and a proof pq : P ∧ Q, derives a proof of Q\n\n* Implication\n-- → introduction: given P Q : Prop and a derivation of a proof Q from a proof of P, conclude P → Q\n-- note : a derivation of a proof of Q from a proof of P is given as a function of type P → Q\n-- → elimination: given propositions, P and Q, a proof of P → Q, and a proof of P, derive a proof of Q\n-- note that → elimination is both a formal version of Aristotle's modus ponens rule and function application\n\n* Negation\n-- introduction : given a proposition P and a proof of P → false, conclude ¬ P\n-- elimination\n---- in constructive logic, showing that a proposition, ¬ P, is false proves only ¬ ¬ P, not that P is true\n---- try to derive a proof of P from the assumption of a proof for ¬ ¬ P and you will see the problem\n---- you can read ¬ ¬ P as \"there's no proof of ¬ P,\" or as \"¬ P is false,\" \n---- classical logic adds the axiom of the excluded middle (AEM), stating that ∀ P : Prop, P ∨ ¬ P\n---- if you accept this axiom and you know that ¬ P is false, then P must be true\n---- the AEM enables ¬ elimination\n---- given a proposition P and a proof of ¬ P → false (of ¬ ¬ P), derive a proof of P\n\n* Forall\n-- introduction : to prove ∀ p : P, Q, where P is a type and Q is a proposition that can involve be written in terms of p, show that Q holds for an any arbitrarily assumed value, p, of type P\n-- elimination : given a proof of ∀ p : P, Q, and a specific value x : P, conclude Q \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-practice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.9032941969413321, "lm_q1q2_score": 0.7985475641081725}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a, b, c y d son números 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 : ℝ\n\n-- 1ª demostración\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 ←add_assoc\n\n-- 2ª demostración\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ª demostración\n-- ===============\n\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nby ring\n\n-- 4ª demostración\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 ← add_assoc,\nend\n\n-- El desarrollo de la prueba es\n--\n--    a b c d : ℝ\n--    ⊢ (a + b) * (c + d) = a * c + a * d + b * c + b * d\n-- rw add_mul,\n--    ⊢ a * (c + d) + b * (c + d) = a * c + a * d + b * c + b * d\n-- rw mul_add,\n--    ⊢ a * c + a * d + b * (c + d) = a * c + a * d + b * c + b * d\n-- rw mul_add,\n--    ⊢ a * c + a * d + (b * c + b * d) = a * c + a * d + b * c + b * d\n-- rw ← add_assoc,\n--    no goals\n\n-- 5ª demostración\n-- ===============\n\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nby rw [add_mul, mul_add, mul_add, ←add_assoc]\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/Ejercicio_con_calc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.7984222751077764}}
{"text": "import .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 {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nsorry\n\n/-! 1.2. Prove its cousin. -/\n\nlemma monotone_restrict {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nsorry\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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing : regex\n| empty   : regex\n| atom    : α → regex\n| concat  : regex → regex → regex\n| alt     : regex → regex → regex\n| star    : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n-- enter the missing cases here\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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_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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7983575781387707}}
{"text": "-- Monotonía de la multiplicación por no positivo\n-- ==============================================\n\n-- Demostrar que si a, b y c son números reales tales que \n-- c ≤ 0 y a ≤ b, entonces b*c ≤ a*c.\n\nimport data.real.basic\n\nvariables {a b c : ℝ}\n\n-- 1ª demostración\nexample \n  (hc : c ≤ 0) \n  (hab : a ≤ b) \n  : b * c ≤ a * c :=\nbegin\n  rw ← sub_nonneg,\n  have h : a * c - b * c = (a - b) * c,\n  { ring, },\n  { rw h,\n    apply mul_nonneg_of_nonpos_of_nonpos,\n    { rwa sub_nonpos, },\n    { exact hc, }},\nend\n\n-- 2ª demostración\nexample \n  (hc : c ≤ 0) \n  (hab : a ≤ b) \n  : b * c ≤ a * c :=\nbegin\n  have hab' : a - b ≤ 0,\n  { rwa ← sub_nonpos at hab, },\n  have h1 : 0 ≤ (a - b) * c,\n  { exact mul_nonneg_of_nonpos_of_nonpos hab' hc, },\n  have h2 : (a - b) * c = a * c - b * c,\n  { ring, },\n  have h3 : 0 ≤ a * c - b * c,\n  { rwa h2 at h1, },\n  rwa sub_nonneg at h3,\nend\n\n-- 3ª demostración\nexample \n  (hc : c ≤ 0) \n  (hab : a ≤ b) \n  : b * c ≤ a * c :=\nbegin\n  rw ← sub_nonneg,\n  have hab' : a - b ≤ 0,\n  { rwa sub_nonpos, },\n  calc 0 ≤ (a - b)*c  \n              : mul_nonneg_of_nonpos_of_nonpos hab' hc\n     ... =  a*c - b*c \n              : by ring,\nend\n\n-- 4ª demostración\nexample \n  (hc : c ≤ 0) \n  (hab : a ≤ b) \n  : b * c ≤ a * c :=\nmul_mono_nonpos hc hab\n\n-- 5ª demostración\nexample \n  (hc : c ≤ 0) \n  (hab : a ≤ b) \n  : b * c ≤ a * c :=\nby nlinarith\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/Monotonia_de_la_multiplicacion_por_no_positivo_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8824278788223265, "lm_q1q2_score": 0.7982888504961155}}
{"text": "-- Basic definition of a group (G, ⬝).\nclass group (G : Type*) :=\n  (mul : G → G → G)\n  (mul_assoc : ∀ a b c : G, (mul a (mul b c)) = (mul (mul a b) c))\n  (id : G)\n  (id_mul : ∀ a : G, (mul id a) = a)\n  (mul_id : ∀ a : G, (mul a id) = a)\n  (inv : G → G)\n  (mul_inv : ∀ a : G, (mul a (inv a)) = id)\n  (inv_mul : ∀ a : G, (mul (inv a) a) = id)\n  \ninfix ` ⬝ `:65 := group.mul\n\n-- The following theorems are simple rewrites that are just needed\n-- because I don't know how to make the infix operator `⬝` work...\n\ntheorem int.my_add_assoc : ∀ a b c : ℤ, (a + (b + c)) = ((a + b) + c) := begin\n  intros,\n  rw int.add_assoc,\nend\n\ntheorem int.my_zero_add : ∀ a : ℤ, (0 + a) = a := begin\n  intros,\n  rw int.zero_add,\nend\n\ntheorem int.my_add_zero : ∀ a : ℤ, (a + 0) = a := begin\n  intros,\n  rw int.add_zero,\nend\n\n-- Basically, a proof that ℤ forms a group under addition, with\n-- 0 as the identity element and (-a) as the inverse of a.\ninstance : group ℤ := {\n  mul := int.add,\n  mul_assoc := int.my_add_assoc,\n  id := int.zero,\n  id_mul := int.my_zero_add,\n  mul_id := int.my_add_zero,\n  inv := λ a : ℤ, -a,\n  mul_inv := int.add_right_neg,\n  inv_mul := int.add_left_neg,\n}\n", "meta": {"author": "EduRenesto", "repo": "ufabc-group-theory", "sha": "8db41da0327a2baa13d9bd6b09d033d06a4a8df3", "save_path": "github-repos/lean/EduRenesto-ufabc-group-theory", "path": "github-repos/lean/EduRenesto-ufabc-group-theory/ufabc-group-theory-8db41da0327a2baa13d9bd6b09d033d06a4a8df3/src/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122720843811, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.798251864409473}}
{"text": "open nat\n\n--1.a.\nexample : ∀ m n k : nat, m * (n + k) = m * n + m * k :=\n    assume m n k,\n        nat.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            (assume p,\n                assume ih: m * (n + p) = m * n + m * p,\n                show m * (n + succ p) = m * n + m * (succ p), from\n                    calc\n                        m * (n + succ p) = m * (succ (n + p)) : by rw add_succ\n                                     ... = m * (n + p) + m : by rw mul_succ\n                                     ... = m * n + m * p + m : by rw ih\n                                     ... = m * n + (m * p + m) : by rw add_assoc\n                                     ... = m * n + m * (succ p) : by rw mul_succ)\n\n--1.b.\nexample : ∀ n : nat, 0 * n = 0 :=\n    assume n,\n        nat.rec_on n\n            (show 0 * 0 = 0, from rfl)\n            (assume k,\n                assume ih : 0 * k = 0,\n                show 0 * (succ k) = 0, from\n                    calc\n                        0 * (succ k) = 0 * k + 0 : by rw mul_succ\n                                ... = 0 * k : by rw add_zero\n                                ... = 0 : by rw ih)\n\n\n--1.c.\nexample : ∀ n : nat, 1 * n = n :=\n    assume n,\n        nat.rec_on n\n            (show 1 * 0 = 0, by rw mul_zero)\n            (assume k,\n                assume ih : 1 * k = k,\n                    calc\n                        1 * (succ k) = 1 * k + 1 : by rw mul_succ\n                                ... = k + 1 : by rw ih\n                                ... = succ k : rfl)\n\n--1.d.\nexample : ∀ m n k : nat, (m * n) * k = m * (n * k) :=\n    assume m n k,\n        nat.rec_on k\n            (show (m * n) * 0 = m * (n * 0), from\n                calc\n                    (m * n) * 0 = 0 : by rw mul_zero\n                            ... = m * 0 : by rw mul_zero\n                            ... = 0 * m : by rw mul_comm\n                            ... = (n * 0) * m : by rw mul_zero\n                            ... = m * (n * 0) : by rw mul_comm)\n            (assume i (ih : (m * n) * i = m * (n * i)),\n            show (m * n) * succ i = m * (n * succ i), from\n                begin\n                    rw mul_succ,\n                    rw ih,\n                    rw ← left_distrib,\n                    rw mul_succ\n                end)\n\n--1.e.\nexample : ∀ m n : nat, m * n = n * m :=\n    assume m n,\n        nat.rec_on n\n            (begin\n                rw mul_zero,\n                apply eq.symm,                \n                rw zero_mul\n            end)\n            (begin\n                intros k ih,\n                rw mul_succ,\n                rw ih,\n                rw succ_mul\n            end)", "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/18. The Natural Numbers and Induction in Lean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191284552529, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7981534045043672}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (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)) ≥ (3 / 2), from by auto [arithmetic_mean_harmonic_mean],\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by auto [h1],\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 {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),\n  -- Then $A ⊆ S$ and $B ⊆ S$, by power set definition\n  have h1 : (A ⊆ S) ∧ (B ⊆ S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  -- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset\n  have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left],\n  -- Then $(A ∩ B) ⊆ S$, by subset relation is transitive \n  have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans],\n  -- Hence $(A ∩ B) ∈  𝒫 S$, by power set definition\n  show (A ∩ B) ∈  𝒫 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 : ℝ) : (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] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by auto using [use (a⁻¹ * b)],\n  have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by auto using [use b * a⁻¹], \n\n  -- Setting $b = a$, this becomes:\n  have h3 : ∀ a : G, ∃! x : G, a * x = a, from by auto [h1],\n  have h4 : ∀ a : G, ∃! 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 : ∀ 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 : ∀ 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 ∃! e : G, ∀ a : G, e * a = a ∧ 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 : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (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_with_comments-Natural-Language-Proof-Translation/Correct_statement-lean_proof_auto_with_comments-3_few_shot_temperature_0_max_tokens_2000_n_1/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7981174111670972}}
{"text": "-- import solutions to level 1\nimport complex.I\n\n/-! \n\n# Level 2: Complex conjugation\n\n-/\n\nnamespace complex\n\n-- First complete the definition using `complex.mk` or `⟨x, y⟩` notation\n\n/-- The complex conjugate of a complex number -/\ndef conj (z : ℂ) : ℂ := ⟨z.re,-z.im⟩  \n\n-- Now prove how it interacts with everything else\n\n/-! ## Real and imaginary parts -/\n\n@[simp] lemma conj_re (z : ℂ) : re(conj z) = re(z) := begin refl end\n@[simp] lemma conj_im (z : ℂ) : im(conj z) = -im(z) := begin refl end\n\n/-! ## Behaviour with respect to 0, 1 and I -/\n\n@[simp] lemma conj_zero : conj 0 = 0 := \nbegin \n    rw conj,\n    ext,\n    simp,\n    simp,\nend\n\n@[simp] lemma conj_one : conj 1 = 1 := \nbegin \n    rw conj,\n    simp,\n    refl,\nend\n\n@[simp] lemma conj_I : conj I = -I := \nbegin\n /-     ext;\n        simp, -/\n    rw conj,\n    simp,\n    rw I,\n    ext,\n    simp,\n    simp,\nend\n\n@[simp] lemma conj_neg_I : conj (-I) = I := \nbegin\n    rw conj,\n    ext,\n    simp,\n    simp,\nend\n\n/-! # Behaviour with respect to +, - and * -/\n\n@[simp] lemma conj_add (z w : ℂ) : conj (z + w) = conj z + conj w :=\nbegin\n    rw conj,\n    simp,\n    ext,\n    simp,\n    simp,\n    ring,\nend\n\n@[simp] lemma conj_neg (z : ℂ) : conj (-z) = -conj z := \nbegin\n    rw conj,\n    simp,\n    rw conj,\n    ext,\n    simp,\n    simp,\nend\n\n@[simp] lemma conj_mul (z w : ℂ) : conj (z * w) = conj z * conj w :=\nbegin\n    repeat {rw conj},\n    simp,\n    ext,\n    simp,\n    simp,\n    ring,\n\nend\n\n/-! # Properties of the `conj` map -/\n\n@[simp] lemma conj_conj (z : ℂ) : conj (conj z) = z :=\nbegin\n    rw conj,\n    rw conj,\n    ext,\n    simp,\n    simp,\nend\n\nlemma conj_inj {z w : ℂ} : conj z = conj w ↔ z = w :=\nbegin\n    rw conj,\n    rw conj,\n    simp,\n    symmetry,\n    rw ext_iff,\nend\n\n@[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 :=\nbegin\n    rw conj,\n    rw ext_iff,\n    simp,\n    symmetry,\n    rw ext_iff,\n    simp,\nend\n\n/-- the ring homomorphism complex conjugation -/\ndef Conj : ℂ →+* ℂ :=\n{ to_fun := conj,\n  map_zero' := begin rw conj, ext, simp, simp, end,\n  map_one' := begin rw conj, ext, simp, simp, end,\n  map_add' := begin simp, end,\n  map_mul' := begin simp, end\n}\n\n-- Two optional lemmas which computer scientists like,\n-- giving us easy access to some basic properties\n-- of conj\n\nopen function\n\nlemma conj_involutive : involutive conj := \nbegin\n    apply conj_conj,\nend\n\nlemma conj_bijective : bijective conj := \nbegin \n    unfold bijective,\n    unfold injective,\n    unfold surjective,\n    split,\n    intros,\n    rw conj_inj at a,\n    exact a,\n    intro,\n    have b.conj.conj,\n    exact b,\n    sorry\nend\n\nend complex\n", "meta": {"author": "tabsg", "repo": "complexNoGame", "sha": "6d765d2e75e99ccab2dda70f44ff06aa286f5bdd", "save_path": "github-repos/lean/tabsg-complexNoGame", "path": "github-repos/lean/tabsg-complexNoGame/complexNoGame-6d765d2e75e99ccab2dda70f44ff06aa286f5bdd/conj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7980460641977977}}
{"text": "import tactic\nimport tactic.rewrite_search.frontend\nimport .«1_part_i»\nnoncomputable theory\n\nnamespace notes\n\nuniverse u\n\n--------------------------------------------------------------------------------\n-- Definitions from the Natural Number Game (modified)\n\n-- Definition of ℕ as an inductive type\ninductive mynat : Type\n| zero :         mynat\n| succ : mynat → mynat\n\nnamespace mynat\n\n  instance : has_zero mynat := ⟨mynat.zero⟩\n  theorem mynat_zero_eq_zero : mynat.zero = 0 := rfl\n\n  def one : mynat := succ 0\n  instance : has_one mynat := ⟨mynat.one⟩\n\n-- Addition\n  def add : mynat → mynat → mynat\n  | m 0        := m\n  | m (succ n) := succ (add m n)\n  instance : has_add mynat := ⟨add⟩\n\n  @[simp, rewrite] def add_zero (m : mynat) : m + 0 = m := rfl\n  @[simp, rewrite] def add_succ (m n : mynat) : m + succ n = succ (m + n) := rfl\n\n  -- (Numerals now work)\n  example : mynat := 37\n\n-- Multiplication\n  def mul : mynat → mynat → mynat\n  | m 0        := 0\n  | m (succ n) := mul m n + m\n  instance : has_mul mynat := ⟨mul⟩\n\n  @[simp, rewrite] def mul_zero (m : mynat) : m * 0 = 0 := rfl\n  @[simp, rewrite] def mul_succ (m n : mynat) : m * succ n = m * n + m := rfl\n\n-- Power\n/-\n  def pow : mynat → mynat → mynat\n  | m 0        := 1\n  | m (succ n) := pow m n * m\n  instance : has_pow mynat mynat := ⟨pow⟩\n\n  @[simp, rewrite] def pow_zero (m : mynat) : m ^ (0 : mynat) = 1 := rfl\n  @[simp, rewrite] def pow_succ (m n : mynat) : m ^ succ n = m ^ n * m := rfl\n-/\n\n-- Less or equal than\n  def le (m n : mynat) : Prop :=\n    ∃ (v : mynat), n = m + v\n  instance has_le : has_le mynat := ⟨le⟩\n\n-- Less than\n  def lt (m n : mynat) : Prop :=\n    ∃ (v : mynat), v ≠ 0 ∧ n = m + v\n  instance : has_lt mynat := ⟨lt⟩\n\nend mynat\n\n-- Add this line in the beginning of each file to override the default ℕ\nlocal notation `ℕ` : 1024 := mynat\n\nnamespace mynat\n\n-- Peano axioms (here they are all derived theorems!)\n-- For proving `no_confusion` with the recursor, refer to TPIL notes\n  theorem succ_ne_zero : ∀ (n : ℕ), succ n ≠ 0 :=\n    λ n h, mynat.no_confusion h\n\n  theorem succ_inj : ∀ (m n : ℕ), succ m = succ n → m = n :=\n    λ m n h, (@mynat.no_confusion (m = n) (succ m) (succ n) h) id\n\n-- (Just a special case of the recursor!)\n  theorem axiom_of_induction : ∀ (P : ℕ → Prop),\n    P 0 → (∀ n, P n → P (succ n)) → ∀ n, P n :=\n      @mynat.rec\n\n-- (Anothor special case of the recursor!)\n  def def_by_recursion {α : Type u} : Π (x₀ : α) (F : ℕ → α → α), ℕ → α :=\n    @mynat.rec (λ _, α)\n\n-- (For demonstration only; use `rfl` instead)\n  variables {α : Type u} (x₀ : α) (F : ℕ → α → α)\n  local notation `R` := def_by_recursion x₀ F\n  theorem axiom_of_recursion : (R 0 = x₀) ∧ (∀ x, R (succ x) = F x (R x)) :=\n    ⟨rfl, (λ x, rfl)⟩\n\nend mynat\n\n--------------------------------------------------------------------------------\n-- # Natural Numbers\n\nnamespace mynat\n\nsection\n  variables (x y z : ℕ)\n\n  @[simp, rewrite]\n  theorem add_assoc :\n    (x + y) + z = x + (y + z)\n  :=\n  begin\n    induction z with z ih,\n    { refl },\n    { change (x + y + z).succ = (x + (y + z)).succ,\n      rw ih }\n  end\n  \n  @[simp, rewrite]\n  theorem zero_add :\n    0 + x = x\n  :=\n  begin\n    induction x with x ih,\n    { refl },\n    { change (0 + x).succ = x.succ,\n      rw ih, }\n  end\n\n  @[simp, rewrite]\n  theorem succ_add :\n    succ x + y = succ (x + y)\n  :=\n  begin\n    induction y with y ih,\n    { refl },\n    { change (x.succ + y).succ = (x + y.succ).succ,\n      rw ih, refl }\n  end\n\n  @[rewrite] -- No @[simp] in commutativity lemmas\n  theorem add_comm :\n    x + y = y + x\n  :=\n  begin\n    induction y with y ihy generalizing x,\n    { erw zero_add, refl },\n    { induction x with x ihx,\n      { erw zero_add, refl },\n      { change (x.succ + y).succ = (y.succ + x).succ,\n        rw [← ihx, ihy],\n        change (y + x).succ.succ = (x + y).succ.succ,\n        rw ihy }}\n  end\n\n  @[simp, rewrite]\n  theorem add_mul :\n    (x + y) * z = x * z + y * z\n  :=\n  begin\n    induction z with z ih,\n    { refl },\n    { change (x + y) * z + (x + y) = (x * z + x) + (y * z + y),\n      rw [ih, add_assoc, ← add_assoc (y * z) x, add_comm (y * z) x],\n      simp only [add_assoc] }\n    -- TODO: \"simp normal forms\"\n    -- TODO: permute using `assoc` and `comm`? (requires: tactic programming)\n  end\n\n  @[rewrite] -- No @[simp] in commutativity lemmas\n  theorem mul_comm :\n    x * y = y * x\n  :=\n  begin\n    induction y with y ihy generalizing x,\n    { induction x with x ihx,\n      { refl },\n      { exact ihx }},\n    { induction x with x ihx,\n      { change 0 * y = 0,\n        rw ihy, refl },\n      { change x.succ * y + x.succ = y.succ * x + y.succ,\n        rw [← ihx, ihy],\n        change y * x + y + (x + 1) = x * y + x + (y + 1),\n        rw [ihy, add_assoc, ← add_assoc y x 1, add_comm y x],\n        simp only [add_assoc] }}\n  end\n\n  @[simp, rewrite]\n  lemma mul_add : x * (y + z) = x * y + x * z :=\n    by rw [mul_comm, add_mul, mul_comm y x, mul_comm z x]\n  \n  @[simp, rewrite]\n  lemma zero_mul : 0 * x = 0 :=\n    by { rw [mul_comm], refl }\n  \n  @[simp, rewrite]\n  lemma succ_mul : succ x * y = x * y + y :=\n    by { rw [mul_comm, mul_comm x y], refl }\n\n  @[simp, rewrite]\n  theorem one_mul :\n    1 * x = x\n  :=\n  begin\n    induction x with x ih,\n    { refl },\n    { change 1 * x + 1 = x.succ,\n      rw ih, refl }\n  end\n\n  @[simp, rewrite]\n  theorem mul_one :\n    x * 1 = x\n  :=\n  begin\n    change 0 + x = x,\n    exact zero_add x,\n  end\n\n  @[simp, rewrite]\n  theorem mul_assoc :\n    (x * y) * z = x * (y * z)\n  :=\n  begin\n    induction z with z ih,\n    { refl },\n    { change x * y * z + x * y = x * (y * z + y),\n      rw [mul_add, ih] }\n  end\n\nend\n\n--------------------------------------------------------------------------------\n\nsection\n  variables (x y z : ℕ)\n\n  theorem add_right_cancel :\n    x + z = y + z → x = y\n  :=\n  begin\n    induction z with z ih,\n    { exact id },\n    { intros h,\n      replace h := succ.inj h,\n      exact ih h }\n  end\n\n  lemma add_left_cancel : x + y = x + z → y = z :=\n    by { rw [add_comm x y, add_comm x z], exact add_right_cancel _ _ _ }\n\n  lemma zero_of_add_right_eq_self :\n    x + y = x → y = 0\n  :=\n  begin\n    intros h,\n    exact add_left_cancel x _ _ h\n  end\n\n  lemma zero_of_add_zero :\n    x + y = 0 → x = 0 ∧ y = 0\n  :=\n  begin\n    intros h, split,\n    { cases y with y, { exact h }, { injections }},\n    { cases y with y, { refl }, { injections }}\n  end\n\n  theorem mul_right_cancel :\n    z ≠ 0 → x * z = y * z → x = y\n  :=\n  begin\n    cases z with z',\n    { intros h, exfalso, exact h rfl },\n    intros _ h,\n    induction x with x ih generalizing y,\n    { erw zero_mul at h,\n      change 0 = y * z' + y at h,\n      cases y with y, { refl }, { injections }},\n    { rw succ_mul at h,\n      cases y with y',\n      { erw zero_mul at h,\n        change (x * z'.succ + z').succ = 0 at h,\n        injections },\n      { rw succ_mul at h,\n        replace h := add_right_cancel _ _ _ h,\n        rw (ih y' h) }}\n  end\n\n  lemma mul_left_cancel : x ≠ 0 → x * y = x * z → y = z :=\n    by { rw [mul_comm x y, mul_comm x z], exact mul_right_cancel _ _ _ }\n\nend\n\n--------------------------------------------------------------------------------\n\n-- `ℕ` is a \"commutative semiring\" with `add_left_cancel` and `mul_left_cancel`!\n-- I found some relevant typeclasses in Lean:\n\ninstance add_cancel_comm_monoid : add_cancel_comm_monoid mynat :=\n  { add             := mynat.add,\n    add_assoc       := mynat.add_assoc,\n    add_left_cancel := mynat.add_left_cancel,\n    zero            := mynat.zero,\n    zero_add        := mynat.zero_add,\n    add_zero        := mynat.add_zero,\n    add_comm        := mynat.add_comm }\n\ninstance comm_semiring : comm_semiring mynat :=\n  { mul             := mynat.mul,\n    left_distrib    := mynat.mul_add,\n    right_distrib   := mynat.add_mul,\n    zero_mul        := mynat.zero_mul,\n    mul_zero        := mynat.mul_zero,\n    mul_assoc       := mynat.mul_assoc,\n    one             := mynat.one,\n    one_mul         := mynat.one_mul,\n    mul_one         := mynat.mul_one,\n    mul_comm        := mynat.mul_comm,\n    ..mynat.add_cancel_comm_monoid }\n\n-- These DO NOT cover the conditional `mul_left_cancel`, though...\n\n--------------------------------------------------------------------------------\n\nsection\n  variables (x y z : ℕ)\n\n-- Alternative way to switch between ≤ and < (other than by definition)\n  lemma le_iff_lt_or_eq :\n    x ≤ y ↔ (x < y ∨ x = y)\n  :=\n  begin\n    split,\n    { rintros ⟨v, hv⟩,\n      cases v with v,\n      { right, exact eq.symm hv },\n      { left, use v.succ, refine ⟨_, hv⟩, intros h, injections }},\n    { rintros (⟨v, ⟨hv₁, hv₂⟩⟩ | h₂),\n      { use v, exact hv₂ },\n      { use 0, exact eq.symm h₂ }}\n  end\n\n  lemma add_right_le_of_le :\n    x ≤ y → x + z ≤ y + z\n  :=\n  begin\n    rintros ⟨c, hc⟩,\n    use c,\n    rw [hc, add_assoc, add_comm c z],\n    simp only [add_assoc]\n  end\n\n  lemma mul_right_le_of_le :\n    x ≤ y → x * z ≤ y * z\n  :=\n  begin\n    rintros ⟨c, hc⟩,\n    use c * z,\n    rw [hc, add_mul]\n  end\n\n  theorem le_total_order :\n    is_total_order le\n  :=\n  begin\n    unfold is_total_order,\n    refine ⟨_, _, _, _⟩,\n    -- Refl\n    { intros x, use 0, refl },\n    -- Antisymm\n    { rintros x y ⟨c, hc⟩ ⟨d, hd⟩,\n      rw [hc, add_assoc] at hd,\n      change x + 0 = x + (c + d) at hd,\n      replace hd := eq.symm (add_left_cancel _ _ _ hd),\n      cases (zero_of_add_zero _ _ hd) with hc₁ hd₁,\n      rw hc₁ at hc,\n      exact eq.symm hc },\n    -- Trans\n    { rintros x y z ⟨c, hc⟩ ⟨d, hd⟩,\n      use c + d,\n      rw [hd, hc, add_assoc] },\n    -- Total\n    { intros x y,\n      induction y with y ih,\n      { right, use x, erw zero_add },\n      { rcases ih with ⟨c, hc⟩ | ⟨c, hc⟩,\n        { left, use c.succ, rw hc, refl },\n        { cases c with c',\n          { left, use 1, rw hc, refl },\n          { right, use c', rw hc, rw succ_add, refl }}}}\n  end\n\n  theorem lt_trichotomy :\n    x = y ∨ x < y ∨ y < x\n  :=\n  begin\n    rcases le_total_order with ⟨_, _, _, htotal⟩,\n    rcases (htotal x y) with ⟨c, hc⟩ | ⟨c, hc⟩,\n    { cases c with c',\n      { left, exact eq.symm hc },\n      { right, left, use c'.succ, split,\n        { intros h, injections },\n        { exact hc }}},\n    { cases c with c',\n      { left, exact hc },\n      { right, right, use c'.succ, split,\n        { intros h, injections },\n        { exact hc }}}\n  end\n\n  lemma le_iff_not_gt :\n    x ≤ y ↔ ¬ (y < x)\n  :=\n  begin\n    split,\n    { rintros ⟨c, hc⟩ ⟨d, hd', hd⟩,\n      cases d with d, { exact hd' rfl },\n      rw [hc, add_assoc] at hd,\n      replace hd := zero_of_add_right_eq_self _ _ hd.symm,\n      injection hd },\n    { intros h,\n      rcases lt_trichotomy x y with (h₁|h₂|h₃),\n      { use 0, rw h₁, refl },\n      { rcases h₂ with ⟨c, _, hc⟩, use c, exact hc },\n      { exfalso, exact h h₃ }}\n  end\n\n  lemma lt_iff_not_ge :\n    x < y ↔ ¬ (y ≤ x)\n  :=\n  begin\n    split,\n    { rintros ⟨c, hc', hc⟩ ⟨d, hd⟩,\n      cases c with c, { exact hc' rfl },\n      rw [hd, add_assoc] at hc,\n      replace hc := zero_of_add_right_eq_self _ _ hc.symm,\n      injection hc },\n    { intros h,\n      rcases lt_trichotomy x y with (h₁|h₂|h₃),\n      { exfalso, exact h ⟨0, h₁⟩ },\n      { exact h₂ },\n      { rcases h₃ with ⟨c, _, hc⟩, exfalso, exact h ⟨c, hc⟩ }}\n  end\n\n-- TODO: `linarith`\n\nend\n\n--------------------------------------------------------------------------------\n\nsection\n\n  theorem based_induction : ∀ (P : ℕ → Prop) (n₀ : ℕ),\n    P n₀ → (∀ m, n₀ ≤ m → P m → P (succ m)) → ∀ m, n₀ ≤ m → P m\n  :=\n    -- (Golfing, for tactic proof see the next theorem)\n    λ P n₀ h₀ h m ⟨c, hc⟩, hc.symm ▸ (mynat.rec_on c\n      h₀ (λ c' ih, h (n₀ + c') ⟨c', rfl⟩ ih))\n\n  theorem based_strong_induction : ∀ (P : ℕ → Prop) (n₀ : ℕ),\n    P n₀ → (∀ m, (∀ k, n₀ ≤ k → k ≤ m → P k) → P (succ m)) → ∀ m, n₀ ≤ m → P m\n  :=\n  begin\n    rintros P n₀ h₀ h m ⟨c, hc⟩,\n    have : ∀ x y, y ≤ x → P (n₀ + y),\n    { intros x, induction x with x ihx,\n      { rintros y ⟨d, hd⟩,\n        have hy := (zero_of_add_zero _ _ hd.symm).left,\n        rw hy,\n        exact h₀ },\n      { rintros y ⟨d, hd⟩,\n        cases d with d,\n        { change x.succ = y at hd,\n          rw ← hd,\n          apply h (n₀ + x),\n          rintros k ⟨e, he⟩ ⟨f, hf⟩,\n          rw he,\n          apply ihx e,\n          use f,\n          rw [he, add_assoc] at hf,\n          exact add_left_cancel _ _ _ hf },\n        { apply ihx,\n          use d,\n          exact mynat.succ.inj hd, }}},\n    rw hc,\n    exact this c c ⟨0, rfl⟩\n  end\n\n  theorem le_well_order : ∀ (X : set ℕ),\n    (∃ a₀, a₀ ∈ X) → ∃ a, (a ∈ X ∧ (∀ x, x ∈ X → a ≤ x))\n  :=\n  begin\n    rintros X ⟨a₀, ha₀⟩,\n    by_contra h,\n    have : ∀ n m, m ≤ n → m ∉ X,\n    { intros n, induction n with n ih,\n      -- Claim: 0 is not in X\n      { rintros m ⟨k, hk⟩ h₁,\n        have hm := (zero_of_add_zero _ _ hk.symm).left,\n        apply h, use 0, split,\n        { rw ← hm, exact h₁ },\n        intros x _, use x, exact (zero_add x).symm, },\n      -- IH   : 0 ~ n are not in X\n      -- Claim: 0 ~ (succ n) are not in X\n      { rintros m ⟨k, hk⟩ h₁,\n        cases k with k,\n        -- If (succ n) is in X, (succ n) will be the least element of X\n        { apply h,\n          use m, split, { exact h₁ },\n          intros x hx,\n          rw le_iff_not_gt,\n          rintros ⟨c, ⟨hc₁, hc₂⟩⟩,\n          cases c with c, { apply hc₁, refl },\n          apply (ih x),\n          { use c, apply mynat.succ.inj, rw hk, exact hc₂ },\n          { exact hx }},\n        -- If any of 0 ~ n is in X, that directly contradicts with IH\n        { refine ih m _ h₁,\n          use k,\n          apply mynat.succ.inj,\n          exact hk }}},\n    refine this a₀ a₀ _ ha₀,\n    use 0, refl\n  end\n\n-- TODO: well-ordering principle for decidable predicates\n-- TODO: (requires well-founded recursion...?)\n\nend\n\n--------------------------------------------------------------------------------\n\n-- `ℕ` is an \"*ordered* commutative semiring\"!\n-- I found some relevant typeclasses in Lean:\n\n#print classes\n\n#check is_well_order -- TODO\n\ninstance linear_order : linear_order mynat :=\n  let ⟨hrefl, hantisymm, htrans, htotal⟩ := mynat.le_total_order in\n    { le           := mynat.le,\n      le_refl      := @hrefl,\n      le_antisymm  := @hantisymm,\n      le_trans     := @htrans,\n      le_total     := @htotal,\n      decidable_le := λ (l r : ℕ), classical.prop_decidable (l ≤ r) }\n\ninstance ordered_semiring : ordered_semiring mynat :=\n  { add_le_add_left         := sorry,\n    le_of_add_le_add_left   := sorry,\n    zero_le_one             := sorry, -- Does anyone know why this would not work?\n    mul_lt_mul_of_pos_left  := sorry,\n    mul_lt_mul_of_pos_right := sorry,\n    ..mynat.add_cancel_comm_monoid,\n    ..mynat.comm_semiring,\n    ..mynat.linear_order }\n\nend mynat\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/1_intro_to_uni_maths/2_1_part_ii_natural_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7980460624450334}}
{"text": "import game.world2.level6 -- hide\nimport mynat.mul -- import the definition of multiplication on mynat\n\n\n/- Axiom : mul_zero (a : mynat) :\na * 0 = 0\n-/\n\n/- Axiom : mul_succ (a b : mynat) :\na * succ(b) = a * b + a\n-/\n\n/- \n\n# Multiplication World\n\nA new import! This import gives you the definition of multiplication on your\nnatural numbers. It is defined by recursion, just like addition.\nHere are the two new axioms:\n\n  * `mul_zero (a : mynat) : a * 0 = 0`\n  * `mul_succ (a b : mynat) : a * succ(b) = a * b + a`\n\nIn words, we define multiplication by \"induction on the second variable\",\nwith `a * 0` defined to be `0` and, if we know `a * b`, then `a` times\nthe number after `b` is defined to be `a * b + a`. \n\nYou can keep all the theorems you proved about addition, but \nfor multiplication, those two results above are you've got right now.\nI would recommend that you sort out the bar on the left. Fold up everything,\nand then unfold just Theorem Statements -> Multiplication World. This will\nremind you of your two new theorems, both of which are true by definition.\nIf you want to be reminded of the theorems you have proved about addition,\nyou can just open up the Addition World theorem statements and take a look. \nIf you don't want to keep opening and closing these menus, why not think\na bit about the logic behind the naming of the proofs? After a while you\nmight find that you can guess the name of the proof you want.\n\nAnyway, what's going on in multiplication world? Like addition, we need to go\nfor the proofs that multiplication\nis commutative and associative, but as well as that we will\nneed to prove facts about the relationship between multiplication\nand addition, for example `a * (b + c) = a * b + a * c`, so now\nthere is a lot more to do. Good luck! \n\nWe are given `mul_zero`, and the first thing to prove is `zero_mul`.\nLike `zero_add`, we of course prove it by induction.\n\n## Level 1: `zero_mul`\n-/\n\nnamespace mynat -- hide\n\n/- Lemma\nFor all natural numbers $m$, we have\n$$ 0 \\times m = 0. $$\n-/\nlemma zero_mul (m : mynat) : 0 * m = 0 :=\nbegin [nat_num_game]\n  induction m with d hd,\n  {\n    rw mul_zero,\n    refl\n  },\n  {\n    rw mul_succ,\n    rw hd,\n    rw add_zero,\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/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7980412336661938}}
{"text": "\nnamespace Ex\n\n\ninductive Nat where\n  | zero : Nat\n  | succ : Nat → Nat\n  deriving Repr\n\nopen Nat\n\ndef one := succ zero\ndef two := succ one\ndef three := succ two\ndef six := succ (succ (succ three))\ndef eight := succ (succ six)\n\n#eval one\n#eval two\n#eval three\n#eval six\n#eval eight\n\n\ndef add (m n : Nat) : Nat :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\nexample : add two one = three\n  := rfl\n\ntheorem add_zero (m : Nat) : add m zero = m :=\n  rfl\n\ntheorem add_succ (m n : Nat) : add m (succ n) = succ (add m n) :=\n  rfl\n\ntheorem zero_add (n : Nat) : add zero n = n := by\n  induction n with\n  | zero      => rfl\n  | succ n ih => rw [add_succ, ih]\n\ntheorem succ_add (m n : Nat) : add (succ m) n = succ (add m n) := by\n  induction n with\n  | zero       => rw [add_zero, add_zero]\n  | succ n' ih => rw [add_succ, add_succ, ih]\n\ntheorem add_one (n : Nat) : add n one = succ n :=\n  rfl\n\ntheorem one_add (n : Nat) : add one n = succ n := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => rw [add_succ, ih]\n\ntheorem add_comm (m n : Nat) : add m n = add n m := by\n  induction n with\n  | zero       => rw [add_zero, zero_add]\n  | succ n' ih => rw [add_succ, succ_add, ih]\n  \ntheorem add_assoc (m n k : Nat) : add (add m n) k = add m (add n k) := by\n  induction k with\n  | zero       => rw [add_zero, add_zero]\n  | succ k' ih => rw [add_succ, add_succ, add_succ, ih]\n\n\n-- Define multiplication on naturals.\n\ndef mul (m n : Nat) : Nat :=\n  match n with\n  | zero        => zero\n  | succ n'     => add m (mul m n')\n\n#eval mul (succ (succ zero)) (succ (succ (succ zero)))\n\nexample : mul two three = six :=\n  rfl\n\n\n-- Define predecessor function on naturals.\n\ndef pred (n : Nat) : Nat :=\n  match n with\n  | zero          => zero\n  | succ Nat.zero => zero\n  | succ n'       => n'\n\n\n-- Define truncated subtraction on naturals.\n\ndef sub (m n : Nat) : Nat :=\n  match n with\n  | zero    => m\n  | succ n' => sub (pred m) n'\n\nexample : sub two one = one := rfl\n\n\n-- Define exponentiation on naturals.\n\ndef exp1 (m n : Nat) : Nat :=\n  match n with\n  | zero    => succ zero\n  | succ n' => mul (succ m) (exp1 m n')\n\n\n-- Then try proving . . .\n\n\ntheorem mul_zero (n : Nat) : mul n zero = zero :=\n  rfl\n\ntheorem mul_one (n : Nat) : mul n one = n :=\n  rfl\n\ntheorem mul_succ (m n : Nat) : mul m (succ n) = add m (mul m n) :=\n  rfl\n\ntheorem zero_mul (n : Nat) : mul zero n = zero := by\n  induction n with\n  | zero      => rfl\n  | succ n ih => rw [mul_succ, zero_add, ih]\n\ntheorem one_mul (n : Nat) : mul one n = n := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => rw [mul_succ, one_add, ih]\n\ntheorem mul_assoc (n m k : Nat) : mul k (mul m n) = mul (mul k m) n := sorry\n\ntheorem mul_dist : mul (add m n) k = add (mul m k) (mul n k) := by\n  induction k with\n  | zero       => rw [mul_zero, mul_zero, mul_zero, add_zero]\n  | succ k' ih => calc\n                    mul (add m n) (succ k') = add (add m n) (mul (add m n) k')          := by rw [mul_succ]\n                    _                       = add (add m n) (add (mul m k') (mul n k')) := by rw [ih]\n                    _                       = add m (add n (add (mul m k') (mul n k'))) := by rw [add_assoc]\n                    _                       = add m (add n (add (mul n k') (mul m k'))) := by simp [add_comm]\n                    _                       = add m (add (add n (mul n k')) (mul m k')) := by rw [add_assoc]\n                    _                       = add m (add (mul n (succ k')) (mul m k'))  := by rw [← mul_succ]\n                    _                       = add m (add (mul m k') (mul n (succ k')))  := by simp [add_comm]\n                    _                       = add (add m (mul m k')) (mul n (succ k'))  := by rw [add_assoc]\n                    _                       = add (mul m (succ k')) (mul n (succ k'))   := by rw [← mul_succ]\n\ntheorem succ_mul (m n : Nat) : mul (succ m) n = add n (mul m n) := by\n  induction n with\n  | zero       => rw [mul_zero, zero_add, mul_zero]\n  | succ n' ih => rw [mul_succ, ih, mul_succ, succ_add, succ_add, ← add_assoc, ← add_assoc]\n                  simp [add_comm]\n\ntheorem mul_comm : mul m n = mul n m := by\n  induction n with\n  | zero       => rw [mul_zero, zero_mul]\n  | succ n' ih => rw [mul_succ, succ_mul, add_comm, ih, add_comm]\n\ntheorem mul_comm' : mul m n = mul n m := by\n  induction n <;> simp [*, mul_zero, zero_mul, mul_succ, succ_mul, add_comm]\n\n\ntheorem succ_zero : succ zero = one := rfl\n\ntheorem pred_zero : pred zero = zero := rfl\n\ntheorem pred_one : pred one = zero := rfl\n\nexample : pred two = one := rfl\n\ntheorem pred_succ (m : Nat) : pred (succ m) = m := by\n  match m with\n  | zero    => rfl\n  | succ m' => rfl\n\n\ntheorem sub_succ (m n : Nat) : sub m (succ n) = sub (pred m) n := rfl\n\ntheorem zero_sub (n : Nat) : sub zero n = zero := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => rw [sub_succ, pred_zero, ih]\n\ntheorem pred_sub (m n : Nat) : sub (pred m) n = pred (sub m n) := by\n  induction m with\n  | zero       => rw [pred_zero, zero_sub, pred_zero]\n  | succ m' ih => sorry\n\ntheorem succ_sub (m n : Nat) : sub (succ m) n = succ (sub m n) := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => sorry\n\ntheorem add_sub (m n : Nat) : sub (add m n) n = m := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => sorry\n\n\nexample : exp1 zero zero = one := rfl\n\ntheorem exp_succ (m n : Nat) : exp1 m (succ n) = mul (succ m) (exp1 m n) := rfl\n\ntheorem one_exp (n : Nat) : exp1 zero n = one := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => rw [exp_succ, ih, mul_one, one]\n\nexample : exp1 one one = two := rfl\n\nexample : exp1 zero two = one := rfl\n\nexample : exp1 one three = eight := rfl\n\ntheorem exp_one (n : Nat) : exp1 n one = succ n := by\n  induction n with\n  | zero       => rfl\n  | succ n' ih => rfl\n\ntheorem exp_zero (n : Nat) : exp1 n zero = one := by\n  match n with\n  | zero    => rfl\n  | succ n' => rfl\n\ntheorem exp_dist (k n m : Nat) : mul (exp1 k m) (exp1 k n) = exp1 k (add m n) := sorry\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-7/Exercises-7-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062238, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7980412323827544}}
{"text": "import Mathlib.Tactic.LeftRight\nimport Mathlib.Tactic.Basic\nimport Std.Tactic.RCases\n/-!\n# Advanced proposition world.\n\n## Level 8: `and_or_distrib_left`\n\nWe know that `x(y+z)=xy+xz` for numbers, and this is called distributivity of multiplication over\naddition. The same is true for `∧` and `∨` -- in fact `∧` distributes over `∨` and `∨` distributes\nover `∧`. Let's prove one of these.\n\nSome new tactics are handy here, the `rintro` tactic is a combination of the `intros` tactic with\n`rcases` to allow for destructuring patterns while introducing variables. For example,\n`rintro ⟨HP, HQ | HR⟩` below matches the subgoal `P ∧ (Q ∨ R)` and introduces the new hypothesis\n`HP : P` and breaks the Or `Q ∨ R` into two left and right sub-goals each with\nhypothesis `HQ : Q` and `HR : R`.\n\nNotice here that you can use a semi-colon to separate multiple tactics on the same line. Another\ntrick shown below is the [<;> tactic](../Tactics/concatenate.lean.md). We could have written `left; constructor; assumption; assumption`\nsince the `constructor` produces two sub-goals we need 2 `assumption` tactics to close those, or you\ncan just write `<;> assumption` which runs `assumption` on both sub-goals.\n\n## Lemma\nIf `P`. `Q` and `R` are true/false statements, then\n`P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R).`\n-/\nlemma and_or_distrib_left (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) := by\n  constructor\n  { rintro ⟨HP, HQ | HR⟩\n    left; constructor <;> assumption;\n    right; constructor <;> assumption\n  }\n  { rintro (⟨HP, HQ⟩ | ⟨HP, HR⟩)\n    constructor; assumption; left; assumption\n    constructor; assumption; right; assumption\n  }\n/-!\n\n\n## Pro tip\n\nNotice here we have used curly braces to group the answers to each of the two sub-goals produced by\nthe `constructor` tactic.  But you if you don't like curly braces you can also use dots like this:\n\n-/\nlemma and_or_distrib_left₂ (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) := by\n  constructor\n  . rintro ⟨HP, HQ | HR⟩\n    left; constructor <;> assumption\n    right; constructor <;> assumption\n  . rintro (⟨HP, HQ⟩ | ⟨HP, HR⟩)\n    constructor; assumption; left; assumption\n    constructor; assumption; right; assumption\n/-!\nWhere the definition of the dot is:\n\n> Given a goal state [g1, g2, ... gn], . tacs is a tactic which first changes the goal state to [g1],\nthen runs tacs. If the resulting goal state is not [], throw an error.\nThen restore the remaining goals [g2, ..., gn].\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/AdvancedPropositionWorld/Level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.798000226291256}}
{"text": "/-\nProof strategies.\n\n- direct proof: use established facts\n\n- by negation: to prove ¬ P, assume P;\n  show that this yields a contradiction,\n  from which a proof of false can then \n  be derived. This shows P → false, and\n  that is the definition of ¬ P.\n\n  Prove that the square root of two is\n  irrational.\n\n  Prove that the square root two is NOT\n  rational.\n\n  Prove ¬ sqrt(2) is rational.\n\n  Proof: assume sqrt(2) is rational. In\n  this case, we can write sqrt(2) as some\n  fraction, a/b. We now want to show that\n  this leads to a contradiction. ...\n\n  - by contradiction : to prove P, assume\n    ¬ P and show that this leads to a\n    contradiction, from which a proof of\n    false can be derived. This proves\n    ¬ P → false, which is equivalent to\n    ¬ ¬ P. The apply the *classical* rule\n    of negation elimination to deduce P.\n\n    Classical rule of negation elimination:\n    ∀ (P : Prop), ¬ ¬ P → P.\n\n    Prove 0 = 0 by contradiction.\n\n    We want to prove P (0 = 0). Assume\n    ¬ (0 = 0), and show that this leads\n    to a contradiction. But by the\n    reflexive property of equality, which\n    says everything is equal to itself, \n    we know immediate that 0 = 0. That\n    gives us a direct contradiction, \n    between ¬ (0=0) and (0=0). From\n    such a contradiction we can derive\n    a proof of false, showing that\n    ¬ (0=0) → false. And this just means\n    ¬ (¬ 0=0). The by classical negation\n    elimination, this implies 0 = 0.\n\n    - Today: proof by induction.\n-/\n\n-- Answer to question about why contradictions imply false\naxiom P : Prop\naxiom p : P\naxiom np : ¬ P  /- P → false -/\n#check (np p)\n\n/-\nProve this: ∀ (m : ℕ), my_add 0 m = m\n-/\n\ndef my_add : ℕ → ℕ → ℕ \n| nat.zero m := m\n| (nat.succ n') m := nat.succ (my_add n' m)\n\n-- 0 + m = m\n-- (1 + n') + m = 1 + (n' + m)\n\n/-\nProof: By the definition of addition,\nand specifically by the first of the\ntwo cases, which tells us that for any\nm, 0 + m = m. \n-/\n\n\n/-\nMany proofs are accomplished by mere\nsimplification of both sides of some\nequation *using function definitions*\nthat are already known. \n-/\n\n/-\nIf one is being precise, however, there\nare some unexpected consequences. One is\nthat sometimes something that looks easy\nturns out to be a bit more complicated.\n\nFor example, try to prove this (using)\nonly what we know so far.\n-/\n\nexample : ∀ (n : ℕ), my_add n 0 = n := _\n\n/-\nWe have no rule (yet) for adding zero \non the right, so simplifying using the\ndefinition of my_add doesn't work.\nInstead, we need to try a whole different\nproof strategy.\n-/\n\n/-\nHere's the idea: \n\n- every inductively defined type has a\n  corresponding induction rule\n\n- It's a rule for showing that some\n  proposition is true for *every* value\n  of the given type\n\n- The induction principle for ℕ is this:\n  ∀ P : (ℕ → Prop),\n  P 0 → \n  ((∀ n' : ℕ), P n' → P (nat.succ n')) → \n  ∀ n, P n\n\nIn other words, for any predicate/property\nP, to show ∀ (n : ℕ), P n, it *suffices* \nto show the following: \n    (1) P 0, \n    (2) (∀ n' : ℕ), P n' → P (nat.succ n')\n-/\n\n/-\nExample: We want to prove ∀ n, n + 0 = n.\nProof by induction. If suffices to show that\n(1) Case: n = 0. By first rule of my_add.\n(2) Case: n = nat.succ n': \n    Show P n' → P (nat.succ n').\n    Assume P n'? my_add n' 0 = n'\n    Wow show P (nat.succ n'), (nat.succ n') + 0 = (nat.succ n').\n    *** simp: nat.succ (my_add n' 0) = nat.succ n' --do some algebra!\n    *** apply induction hypothesis: nat.succ n' = nat.succ n'\n    Finish by reflexive property of equality.\n     \ndef my_add : ℕ → ℕ → ℕ \n| nat.zero m := m\n| (nat.succ n') m := nat.succ (my_add n' m)\n-/\n\n/-\n∀ n, Sum numbers from 0 to n = n * (succ n) / 2.\n\nProof by induction. We will apply the principle of\ninduction for the natural numbers to two smaller\nproofs: one for n = 0, and one that shows that if\nthe formula is true for some n' > 0, then it must\nalso be true succ n'.\n\nBase case: prove (P 0): show sum from 0 to 0 = (0 * 1)/2 = 0.\nInductive case: Show  P n' → P (n' + 1)\nAssume P n'. The sum from 0 to n' = n' * (n' + 1) / 2.\nShow (P (n' + 1)): The sum from 0 to n'+1 = (n'+1)((n'+1)+1)/2.\nDo some algebra!\n\n--- intuition\n1+2+3+4+5 if we assume this is 5*6/2\n(1+2+3+4+5)+6 show this is 6*7/2\nsum 0 to 5 + 6! = 5*6/2 + 6\n\nThe sum from 0 to (n' + 1) = sum from 0 to n' + (n' + 1)\n                           = (n'*(n'+1)/2) + (n' + 1)\n                           ...\n                           = (n'+1)((n'+1)+1)/2.\n\n-/", "meta": {"author": "reesegrayallen", "repo": "Lean-Discrete-Mathematics", "sha": "00c875284613ea12e0a729f519738aab8599456b", "save_path": "github-repos/lean/reesegrayallen-Lean-Discrete-Mathematics", "path": "github-repos/lean/reesegrayallen-Lean-Discrete-Mathematics/Lean-Discrete-Mathematics-00c875284613ea12e0a729f519738aab8599456b/predicate_logic/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.7979993396070546}}
{"text": "import data.real.basic\n\n/-\nOne of the earliest kind of proofs one encounters while learning mathematics is proving by\na calculation. It may not sound like a proof, but this is actually using lemmas expressing \nproperties of operations on numbers. It also uses the fundamental property of equality: if two\nmathematical objects A and B are equal then, in any statement involving A, one can replace A \nby B. This operation is called rewriting, and the Lean \"tactic\" for this is `rw`.\n\nIn the following exercises, we will use the following two lemmas:\n  mul_assoc a b c : a * b * c = a * (b * c)\n  mul_comm a b : a*b = b*a\n\nHence the command \n  rw mul_assoc a b c,\nwill replace a*b*c by a*(b*c) in the current goal.\n\nIn order to replace backward, we use\n  rw ← mul_assoc a b c,\nreplacing a*(b*c) by a*b*c in the current goal.\n\nOf course we don't want to constantly invoke those lemmas, and we will eventually introduce\nmore powerful solutions.\n-/\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 0001\nexample (a b c : ℝ) : (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\n-- 0002\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ← mul_assoc a b c,\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n/-\nNow let's return to the preceding example to experiment with what happens\nif we don't give arguments to mul_assoc or mul_comm.\nFor instance, you can start the next proof with\n  rw ← mul_assoc,\nTry to figure out what happens.\n-/\n\n-- 0003\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ← mul_assoc,\n  rw mul_comm a b,\n  rw mul_assoc,\nend\n\n/-\nWe can also perform rewriting in an assumption of the local context, using for instance\n  rw mul_comm a b at hyp,\nin order to replace a*b by b*a in assumption hyp.\n\nThe next example will use a third lemma:\n  two_mul a : 2*a = a + a\n\nAlso we use the `exact` tactic, which allows to provide a direct proof term.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a*d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp, -- Our assumption hyp is now exactly what we have to prove\nend\n\n/-\nAnd the next one can use:\n  sub_self x : x - x = 0\n-/\n\n-- 0004\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm at hyp,\n  rw sub_self (a*b) at hyp,\n  exact hyp,\nend\n\n/-\nWhat is written in the two preceding example is very far away from what we would write on\npaper. Let's now see how to get a more natural layout.\nInside each pair of curly braces below, the goal is to prove equality with the preceding line.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b : by { rw hyp }\n  ... = d*a + a*d  : by { rw hyp' }\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\n/-\nLet's note there is no comma at the end of each line of calculation. `calc` is really one\ncommand, and the comma comes only after it's fully done.\n\nFrom a practical point of view, when writing such a proof, it is convenient to:\n* pause the tactic state view update in VScode by clicking the Pause icon button\n  in the top right corner of the Lean Goal buffer\n* write the full calculation, ending each line with \": by {}\"\n* resume tactic state update by clicking the Play icon button and fill in proofs between \n  curly braces.\n\nLet's return to the other example using this method. \n-/\n\n-- 0005\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  calc c = b*a - d : by { rw hyp }\n  ... = b*a - a*b  : by { rw hyp' }\n  ... = a*b - a*b  : by { rw mul_comm b a}\n  ... = 0          : by { rw sub_self (a*b) },\nend\n\n/-\nThe preceding proofs have exhausted our supply of \"mul_comm\" patience. Now it's time\nto get the computer to work harder. The `ring` tactic will prove any goal that follows by\napplying only the axioms of commutative (semi-)rings, in particular commutativity and \nassociativity of addition and multiplication, as well as distributivity.\n\nWe also note that curly braces are not necessary when we write a single tactic proof, so \nlet's get rid of them.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b   : by rw hyp\n     ... = d*a + a*d : by rw hyp'\n     ... = 2*a*d     : by ring,\nend\n\n/-\nOf course we can use `ring` outside of `calc`. Let's do the next one in one line.\n-/\n\n-- 0006\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  ring,\nend\n\n/-\nThis is too much fun. Let's do it again.\n-/\n\n-- 0007\nexample (a b : ℝ) : (a + b) + a = 2*a + b :=\nbegin\n  ring,\nend\n\n/-\nMaybe this is cheating. Let's try to do the next computation without ring.\nWe could use:\npow_two x : x^2 = x*x\nmul_sub a b c : a*(b-c) = a*b - a*c\nadd_mul a b c : (a+b)*c = a*c + b*c\nadd_sub a b c : a + (b - c) = (a + b) - c\nsub_sub a b c : a - b - c = a - (b + c)\nadd_zero a : a + 0 = a\n-/\n\n-- 0008\nexample (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 :=\nbegin\n  rw mul_sub,\n  rw add_mul,\n  rw add_mul,\n  rw ← sub_sub,\n  rw mul_comm b a,\n  rw ← add_sub,\n  rw sub_self,\n  rw add_zero,\n  rw pow_two,\n  rw pow_two,\nend\n\n/- Let's stick to ring in the end. -/\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/01_equality_rewriting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.7979931943769641}}
{"text": "/-\nCopyright (c) 2018 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Yury Kudryashov, Yaël Dillies\n\n! This file was ported from Lean 3 source module algebra.module.big_operators\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.Module.Basic\nimport Mathlib.GroupTheory.GroupAction.BigOperators\n\n/-!\n# Finite sums over modules over a ring\n-/\n\nopen BigOperators\n\nvariable {α β R M ι : Type _}\n\nsection AddCommMonoid\n\nvariable [Semiring R] [AddCommMonoid M] [Module R M] (r s : R) (x y : M)\n\ntheorem List.sum_smul {l : List R} {x : M} : l.sum • x = (l.map fun r ↦ r • x).sum :=\n  ((smulAddHom R M).flip x).map_list_sum l\n#align list.sum_smul List.sum_smul\n\ntheorem Multiset.sum_smul {l : Multiset R} {x : M} : l.sum • x = (l.map fun r ↦ r • x).sum :=\n  ((smulAddHom R M).flip x).map_multiset_sum l\n#align multiset.sum_smul Multiset.sum_smul\n\ntheorem Multiset.sum_smul_sum {s : Multiset R} {t : Multiset M} :\n    s.sum • t.sum = ((s ×ˢ t).map fun p : R × M ↦ p.fst • p.snd).sum := by\n  induction' s using Multiset.induction with a s ih\n  · simp\n  · simp [add_smul, ih, ← Multiset.smul_sum]\n#align multiset.sum_smul_sum Multiset.sum_smul_sum\n\ntheorem Finset.sum_smul {f : ι → R} {s : Finset ι} {x : M} :\n    (∑ i in s, f i) • x = ∑ i in s, f i • x := ((smulAddHom R M).flip x).map_sum f s\n#align finset.sum_smul Finset.sum_smul\n\n-- Porting note: changed `×ˢ` to `xᶠ` in the statement of the theorem to fix ambiguous notation\ntheorem Finset.sum_smul_sum {f : α → R} {g : β → M} {s : Finset α} {t : Finset β} :\n    ((∑ i in s, f i) • ∑ i in t, g i) = ∑ p in s ×ᶠ t, f p.fst • g p.snd := by\n  rw [Finset.sum_product, Finset.sum_smul, Finset.sum_congr rfl]\n  intros\n  rw [Finset.smul_sum]\n#align finset.sum_smul_sum Finset.sum_smul_sum\n\nend AddCommMonoid\n\ntheorem Finset.cast_card [CommSemiring R] (s : Finset α) : (s.card : R) = ∑ a in s, 1 := by\n  rw [Finset.sum_const, Nat.smul_one_eq_coe]\n#align finset.cast_card Finset.cast_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/Algebra/Module/BigOperators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984213, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.7979931903438039}}
{"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.section06quotients.sheet1definitions\n\n/-!\n\n## The API for quotients\n\nRight now we have the equivalence relation `R : ℤ → ℤ → Prop` and also\nthe \"setoid\" `s : setoid ℤ`. If you did `cases s` you would get\na pair, you'd get `R` and the proof `R_equivalence` that it's an\nequivalence relation. But we won't ever need to take `s` apart.\n\nRecall that we've defined `Zmod37` to be `quotient s`. Now here\nis the API that we will need. Note that we are not learning\nnew *tactics* here, we are learning new *theorems from the maths library*.\nThe same old tactics (`intro`, `apply`, `simp` etc) are useful whether\nyou're doing algebra, analysis, geometry or whatever. But the theorems\nand definitions in the library apply in more specialised domains. \nIn this sheet I'll show you the theorems and definitions you'll\nneed to start working with quotients.\n\n-/\n\n-- `setoid` is a class, so `s` should not just be a definition, we should\n-- make it an instance by tagging it with the `instance` attribute\n\nattribute [instance] s\n\n-- This unlocks notation `≈` for the equivalence relation `R`\n-- and `⟦x⟧` for the element of `Zmod37` corresponding to the integer `x`.\n\n-- Uncomment the three lines below to see it in action\n\n--def n : ℤ := 23 -- a random integer\n\n--#check ⟦n⟧ -- it's in Zmod37\n\n--#check n ≈ 42 -- it's a true-false statement\n\n-- in fact `⟦a⟧` is just notation for `quotient.mk a`, the\n-- function from `X` to `quotient s`. Let's check this.\n\nexample (a : ℤ) : ⟦a⟧ = quotient.mk a :=\nbegin\n  refl\nend\n\n-- and `≈` is just notation for `R`\n-- (this is handy to know; let's give it a name so we can rewrite it)\nlemma equiv_def (a b : ℤ) : a ≈ b ↔ R a b :=\nbegin\n  refl\nend\n\n-- The theorem that quotient.mk is surjective is called `surjective_quotient_mk`.\n\nexample : function.surjective (λ (a : ℤ), ⟦a⟧) :=\nbegin\n  exact surjective_quotient_mk ℤ \n  -- `surjective_quotient_mk` is a theorem in the library\n  -- maybe you could have guessed its name?\nend\n\n-- The theorem that two integers are related iff their images are equal\n-- is called `quotient.eq`.\n\nexample (a b : ℤ) : ⟦a⟧ = ⟦b⟧ ↔ a ≈ b :=\nbegin\n  exact quotient.eq -- so `rw quotient.eq` is often useful\nend\n\n-- Both implications also have names\n\nexample (a b : ℤ) : ⟦a⟧ = ⟦b⟧ → a ≈ b :=\nbegin\n  exact quotient.exact\nend\n\nexample (a b : ℤ) : a ≈ b → ⟦a⟧ = ⟦b⟧ :=\nbegin\n  exact quotient.sound\nend \n\n/-\n\n## Being \"well-defined\"\n\nHere is a concept which students sometimes find difficult.\n\nLet's say we want to define a function from `Zmod37` to another type.\nFor example, when we start putting the additive abelian group structure\non `Zmod37` we will need to define the additive inverse map `neg : Zmod37 → Zmod37`. \nHere's how mathematicians usually explain it.\n\nStep 0) We're defining a function `f : Zmod37 → α` for some type `α`.\nStep 1) Choose an element `z` in `Zmod37`. We want to define `f(z)`.\nStep 2) Lift `z` completely randomly to an integer `a` in `ℤ` (OK because\nthe quotient map is surjective). \nStep 3) Now write down a formula for what we want `f(z)` to be,\nexcept that this formula will depend on `a` (for example, in the case of negation we\nwould define `f(z)=⟦-a⟧` ; note that this makes sense because we already have `neg : ℤ → ℤ`)\nStep 4) Now check that \"this function is well-defined\". This means\nthe following: say that we had lifted `z` to a different integer `b` in `ℤ`\nin step 2. Then we need to check that our recipe for `f(z)` defined using\n`a` and our recipe using `b` give the same answer. In the negation case\nthis would boil down to checking that if `a ≈ b` then `⟦-a⟧ = ⟦-b⟧`. \n\nSee if you can prove the key lemma needed to show that\nnegation on `Zmod37` is well-defined. \n-/\n\nnamespace Zmod\n\nlemma negation_is_well_defined_key_lemma (a b : ℤ) (h : a ≈ b) : ⟦-a⟧ = ⟦-b⟧ :=\nbegin\n  sorry,\nend\n\n-- The lemma above is somehow the key ingredient to make those\n-- steps above work. Lean has a function called `quotient.lift` which\n-- does all the steps at once\n\ndef neg : Zmod37 → Zmod37 := quotient.lift (λ a, ⟦-a⟧) (negation_is_well_defined_key_lemma)\n\n/-\nThe general set-up is as follows: if `Y` is the quotient of `X` by `≈`\nthen if we want to define a function from `Y` to a type `α` then we\ncan do it by defining a function `F` from `X` to `α` and then proving\nthat equivalent elements of `X` get sent to equal elements of `α`. \nThen `quotient.lift` in Lean's library can be fed the function `F`\nand the proof, and it will spit out the function `f` from `Y` to `α`\nwith the property that `f(⟦x⟧)=F(x)`. \n\nBut now here's a question: Let's say we've defined `f` this way.\nHow do we know that `f(⟦x⟧) = F(x)`? \nHere's what this question boils down to in our case:\n\n-/\n\nexample (a : ℤ) : neg ⟦a⟧ = ⟦-a⟧ :=\nbegin\n  refl -- true by definition. That is part of the magic of Lean's quotient types.\nend\n\n/-\n\n## A second definition of `neg`\n\nHere is another way of defining `neg` on `Zmod37`. We know that\nthere's a negation function on `ℤ` sending `n` to `-n`. We want\nto \"descend\" this function to `Zmod37`. The Lean function `quotient.map`\ndoes this for us. The function `quotient.map` eats a function `F : X₁ → X₂`\nwhere `X₁` and `X₂` are types with setoid structures (i.e. equivalence\nrelations `≈₁` and `≈₂` in the typeclass system) and also eats a proof that\n``a ≈₁ b → F a ≈₂ F b`, and spits out the function `f : Y₁ → Y₂` making\nthe diagram commute (i.e. such that `⟦F(x₁)⟧ = f(⟦x₁⟧)`).\n\n-/\ndef neg2 : Zmod37 → Zmod37 := quotient.map (λ a, -a) begin\n  -- goal looks terrifying! I don't really understand it myself!\n  -- But bravely start with `intro a`, and use `dsimp` to get rid of the `lambda`s\n  sorry\nend\n\n-- The diagram commutes by definition\nexample (a : ℤ) : neg2 ⟦a⟧ = ⟦-a⟧ :=\nbegin\n  refl\nend \n\n-- The two ways of defining negation are definitionally equal as well\nexample : neg = neg2 :=\nbegin\n  refl\nend \n\n-- We have negation; in the next sheet we'll define addition\n-- and then we'll be able to prove `Zmod37` is an additive abelian group.\n-- We'll then zip through multiplication and show it's a ring.\n\nend Zmod\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/sheet2zmod37.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.9059898159413478, "lm_q1q2_score": 0.7979931882286383}}
{"text": "import data.set.basic data.set.lattice data.nat.parity\nimport tactic.linarith\n\nopen set nat function\n\nopen_locale classical\n\nvariables {α : Type*} {β : Type*} {γ : Type*} {I : Type*}\n\n/-!\n## Set exercises\nThese are collected from *Mathematics in Lean*.\nWe will go over the examples together, and then let you\nwork on the exercises.\nThere is more material here than can fit in the sessions,\nbut we will pick and choose as we go.\n-/\n\nsection set_variables\n\nvariable  x : α\nvariables s t u : set α\n\n/-!\n### Notation\n-/\n\n#check s ⊆ t        -- \\sub\n#check x ∈ s        -- \\in or \\mem\n#check x ∉ s        -- \\notin\n#check s ∩ t        -- \\i or \\cap\n#check s ∪ t        -- \\un or \\cup\n#check (∅ : set α)  -- \\empty\n\n/-!\n### Examples\n-/\n\n-- Three proofs of the same fact.\n-- The first two expand definitions explicitly,\n-- while the third forces Lean to do the unfolding.\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  rw [subset_def, inter_def, inter_def],\n  rw subset_def at h,\n  dsimp,\n  rintros x ⟨xs, xu⟩,\n  exact ⟨h _ xs, xu⟩,\nend\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  simp only [subset_def, mem_inter_eq] at *,\n  rintros x ⟨xs, xu⟩,\n  exact ⟨h _ xs, xu⟩,\nend\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  intros x xsu,\n  exact ⟨h xsu.1, xsu.2⟩\nend\n\n-- Use `cases` or `rcases` or `rintros` with union.\n-- Two proofs of the same fact, one longer and one shorter.\n\nexample : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) :=\nbegin\n  intros x hx,\n  have xs : x ∈ s := hx.1,\n  have xtu : x ∈ t ∪ u := hx.2,\n  cases xtu with xt xu,\n  { left,\n    show x ∈ s ∩ t,\n    exact ⟨xs, xt⟩ },\n  right,\n  show x ∈ s ∩ u,\n  exact ⟨xs, xu⟩\nend\n\nexample : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) :=\nbegin\n  rintros x ⟨xs, xt | xu⟩,\n  { left, exact ⟨xs, xt⟩ },\n  right, exact ⟨xs, xu⟩\nend\n\n-- Two examples with set difference.\n-- Type it as ``\\\\``.\n-- ``x ∈ s \\ t`` expands to ``x ∈ s ∧ x ∉ t``.\n\nexample : s \\ t \\ u ⊆ s \\ (t ∪ u) :=\nbegin\n  intros x xstu,\n  have xs : x ∈ s := xstu.1.1,\n  have xnt : x ∉ t := xstu.1.2,\n  have xnu : x ∉ u := xstu.2,\n  split,\n  { exact xs }, dsimp,\n  intro xtu, -- x ∈ t ∨ x ∈ u\n  cases xtu with xt xu,\n  { show false, from xnt xt },\n  show false, from xnu xu\nend\n\nexample : s \\ t \\ u ⊆ s \\ (t ∪ u) :=\nbegin\n  rintros x ⟨⟨xs, xnt⟩, xnu⟩,\n  use xs,\n  rintros (xt | xu); contradiction\nend\n\n/-!\n### Exercises\n-/\n\nexample : (s ∩ t) ∪ (s ∩ u) ⊆ s ∩ (t ∪ u):=\nbegin \n  rintros x (⟨xs, xt⟩ | ⟨xs, xu⟩),\n  from ⟨xs, or.inl xt⟩,\n  from ⟨xs, or.inr xu⟩,\nend\n\nexample : s \\ (t ∪ u) ⊆ s \\ t \\ u :=\nbegin \n  rintros x ⟨xs, h⟩, dsimp at h,\n  push_neg at h, \n  use [xs, h.1, h.2],\nend\n\n/-!\n### Proving two sets are equal\n-/\n\n-- the ext tactic\n\nexample : s ∩ t = t ∩ s :=\nbegin\n  ext x,\n  -- simp only [mem_inter_eq],  -- optional.\n  split,\n  { rintros ⟨xs, xt⟩, exact ⟨xt, xs⟩ },\n  rintros ⟨xt, xs⟩, exact ⟨xs, xt⟩\nend\n\nexample : s ∩ t = t ∩ s :=\nby ext x; simp [and.comm]\n\n/-!\n### Exercises\n-/\n\nexample : s ∩ (s ∪ t) = s :=\nbegin \n  ext x, \n  split,\n  { rintros ⟨xs, h⟩, from xs,},\n  { intro xs, from ⟨xs, or.inl xs⟩,}\nend\n\nexample : s ∪ (s ∩ t) = s :=\nbegin \n  ext x, split,\n  { rintro (xs | ⟨xs, xt⟩); from xs,},\n  { intro xs, left, from xs,}\nend\n\nexample : (s \\ t) ∪ t = s ∪ t :=\nbegin \n  ext x, split,\n  { rintro (⟨xs, xnt⟩ | xt),\n      left, from xs,\n      right, from xt,},\n  { rintro (xs | xt), \n    { by_cases xt : x ∈ t, \n      right, from xt,\n      left, from ⟨xs, xt⟩,},\n    right, from xt,}\nend\n\nexample : (s \\ t) ∪ (t \\ s) = (s ∪ t) \\ (s ∩ t) :=\nbegin \n  ext x, split,\n  { rintros (⟨xs, xnt⟩ | ⟨xt, xns⟩), \n    { simp, split, left, from xs,\n      intro, from xnt,},\n    { simp, split, right, from xt,\n      intro, contradiction,} },\n  { simp, rintros (xs | xt) xsnt,\n    { use [xs, xsnt xs],},\n    { by_contra' h',\n      from xsnt (h'.2 xt) xt,}} \nend\n\n/-!\n### Set-builder notation\n-/\n\ndef evens : set ℕ := {n | even n}\ndef odds :  set ℕ := {n | ¬ even n}\n\nexample : evens ∪ odds = univ :=\nbegin\n  rw [evens, odds],\n  ext n,\n  simp,\n  apply classical.em\nend\n\nexample : s ∩ t = {x | x ∈ s ∧ x ∈ t} := rfl\nexample : s ∪ t = {x | x ∈ s ∨ x ∈ t} := rfl\nexample : (∅ : set α) = {x | false} := rfl\nexample : (univ : set α) = {x | true} := rfl\n\nexample (x : ℕ) (h : x ∈ (∅ : set ℕ)) : false :=\nh\n\nexample (x : ℕ) : x ∈ (univ : set ℕ) :=\ntrivial\n\n/-!\n### Exercise\n-/\n\n-- Use `intro n` to unfold the definition of subset,\n-- and use the simplifier to reduce the\n-- set-theoretic constructions to logic.\n-- We also recommend using the theorems\n-- ``prime.eq_two_or_odd`` and ``even_iff``.\n\nexample : { n | nat.prime n } ∩ { n | n > 2} ⊆ { n | ¬ even n } :=\nbegin \n  rintros n ⟨np, n2⟩ en, dsimp at *, \n  cases prime.eq_two_or_odd np,\n  linarith,\n  rw even_iff at en,\n  linarith,\nend\n\n/-!\nIndexed unions\n-/\n\n-- See *Mathematics in Lean* for a discussion of\n-- bounded quantifiers, which we will skip here.\n\nsection\n\n-- We can use any index type in place of ℕ\nvariables A B : ℕ → set α\n\nexample : s ∩ (⋃ i, A i) = ⋃ i, (A i ∩ s) :=\nbegin\n  ext x,\n  simp only [mem_inter_eq, mem_Union],\n  split,\n  { rintros ⟨xs, ⟨i, xAi⟩⟩,\n    exact ⟨i, xAi, xs⟩ },\n  rintros ⟨i, xAi, xs⟩,\n  exact ⟨xs, ⟨i, xAi⟩⟩\nend\n\nexample : (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ 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 ⟨h1, h2⟩ i,\n  split,\n  { exact h1 i },\n  exact h2 i\nend\n\nend\n\n/-!\n### Exercise\n-/\n\n-- One direction requires classical logic!\n-- We recommend using ``by_cases xs : x ∈ s``\n-- at an appropriate point in the proof.\n\nsection\n\nvariables A B : ℕ → set α\n\nexample : s ∪ (⋂ i, A i) = ⋂ i, (A i ∪ s) :=\nbegin \n  ext x, simp only [mem_Inter], split,\n  { rintros (xs | fAi) i, \n    right, from xs,\n    rw mem_Inter at fAi,\n    left, from fAi i,},\n  { intro h, by_cases xs : x ∈ s,\n    { left, from xs,},\n    { right, rw mem_Inter, intro i,\n      cases h i with xAi xs,\n      from xAi, \n      contradiction,}},\nend\n\nend\n\n/-\nMathlib also has bounded unions and intersections,\n`⋃ x ∈ s, f x` and `⋂ x ∈ s, f x`,\nand set unions and intersections, `⋃₀ s` and `⋂₀ s`,\nwhere `s : set α`.\nSee *Mathematics in Lean* for details.\n-/\n\nend set_variables\n\n/-!\n### Functions\n-/\n\nsection function_variables\n\nvariable  f : α → β\nvariables s t : set α\nvariables u v : set β\nvariable  A : I → set α\nvariable  B : I → set β\n\n#check f '' s\n#check image f s\n#check f ⁻¹' u    -- type as \\inv' and then hit space or tab\n#check preimage f u\n\nexample : f '' s = {y | ∃ x, x ∈ s ∧ f x = y} := rfl\nexample : f ⁻¹' u = {x | f x ∈ u } := rfl\n\nexample : f ⁻¹' (u ∩ v) = f ⁻¹' u ∩ f ⁻¹' v :=\nby { ext, refl }\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y, split,\n  { rintros ⟨x, xs | xt, rfl⟩,\n    { left, use [x, xs] },\n    right, use [x, xt] },\n  rintros (⟨x, xs, rfl⟩ | ⟨x, xt, rfl⟩),\n  { use [x, or.inl xs] },\n  use [x, or.inr xt]\nend\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nbegin\n  intros x xs,\n  show f x ∈ f '' s,\n  use [x, xs]\nend\n\n/-!\n### Exercises\n-/\n\nexample : f '' s ⊆ u ↔ s ⊆ f ⁻¹' u :=\nbegin \n  split, \n  { intros fsc x xs,\n    apply fsc, use [x, xs], },\n  { rintros sfu y ⟨x, xs, fx⟩, \n    rw ←fx, apply sfu, from xs,},\nend\n\n\n\nend function_variables", "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/02_Tuesday/03_Sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.7979831350539551}}
{"text": "/-\nIf P and Q are of type Prop, we think\nof P → 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 → 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 → Q, or nat → bool, is a type: a\ntype of functions from P → 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ℕ → bool. \n-/\n\ndef zero_nat (n : ℕ) : nat := 0 -- explicit return type\n#check zero_nat\n#check zero_nat 5\n#reduce zero_nat 5\n\ndef inc (n : ℕ) : ℕ := n + 1\n#reduce inc 5\n\ndef zero_nat': ℕ → ℕ := λ n : nat, (0 : nat)\ndef zero_nat'': ℕ → ℕ := λ n, 0\ndef zero_nat''' := λ 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 : ℕ → ℕ := λ n:  nat, 1\n#check one_nat\n#reduce one_nat 5\n\ndef identity_nat (n : ℕ) : 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 : ℕ) := 2 * n -- return type inferred\n#check double\n#check double 3\n#reduce double 3\n\ndef double' := λ n: ℕ , (2 * n : ℕ)\n\n/-\nEXERCISE: Write it using a lambda expression.\n-/\n\ndef square (n: ℕ) := n * n -- return type inferred\n#check square\n#check square 3\n#reduce square 3\n\ndef square' : ℤ → ℤ := λ 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    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: ℕ → bool := \n    λ n, \n        if n >= 0 ∧ 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 → bool :=\n    λ n : nat, \n        (if n > 0 then tt else ff : bool)\n\n#check positive'\n#check λ n : nat, (if n > 0 then tt else ff : bool)\n#check λ n, (if n > 0 then tt else ff)\n#check λ n, n > 0\n\n\n/-\nRead the first line as saying positive'\nis a proof of (a value of type) nat → 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 → bool :=\n    λ 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    λ 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ℕ → ℕ\n-/\n\n\n/-\nWe can also pass functions as arguments\nto other functions!\n-/\n\ndef compose (f: ℕ → ℕ) (g: ℕ → ℕ) (x: ℕ) : ℕ :=\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 : ℕ → ℕ) (x: ℕ) : ℕ := 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' : (ℕ → ℕ) → ℕ → ℕ := \n    λ (f: ℕ → ℕ) (x: ℕ), f (f x)\n\n/-\nAnd that's a shorthand for this!\n-/\n\ndef do_twice'' : (ℕ → ℕ) → ℕ → ℕ := \n    λ (f : ℕ → ℕ),\n        λ (x : ℕ), \n            f (f x)\n\ndef sub_do_twice (f: ℕ → ℕ) := λ (x : ℕ), f (f x)\n\n#check sub_do_twice\n\ndef call_sub_do_twice := sub_do_twice (λ (x: ℕ), 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: (ℕ → ℕ) → ℕ → ℕ) (x: (ℕ → ℕ)) : (ℕ → ℕ) := 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": "Mnormansell", "repo": "Discrete-Notes", "sha": "61f13b98be590269fc4822be7b47924a6ddc1261", "save_path": "github-repos/lean/Mnormansell-Discrete-Notes", "path": "github-repos/lean/Mnormansell-Discrete-Notes/Discrete-Notes-61f13b98be590269fc4822be7b47924a6ddc1261/05_Functions/functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8902942173896131, "lm_q1q2_score": 0.7979274197626659}}
{"text": "/-\nAuthor: Justin Mayer\nself study of abstract algebra. Chapter two of dummit and foote. \n-/\n\nimport tactic\nimport algebra.group.basic\nimport group_theory.subgroup.basic\nimport data.set.basic\n\n--#print subgroup\n\nvariables {G: Type} [group G] (H : subgroup G)\n\ninstance : has_mem G (subgroup G) := \n{mem := λ m H, m ∈ H.carrier } --this allows for g ∈ H to be written. See formalising math by Kevin Buzzard. Groups, sheet 3\n\ninstance : has_coe (subgroup G) (set G) := \n{coe := λ H, H.carrier} --just removing the need to reference H.carrier since this doesn't feel very \"mathy.\" Once again a trick demonstrated by Kevin Buzzard. Formalising mathematics, Groups, sheet 3. \n--notice that these are instances of general functions definied in lean. We then define the mem function using the lambda calculus formalism. \n\n@[simp] lemma mem_coe {g:G} : g ∈ (H : set G) ↔ g ∈ H := \nbegin \nrefl,\nend\n--always for a rewrite where if something has type g ∈ (H : set G), then it can just be written as g ∈ H. Another useful math tactic.\n\n@[ext] def ext' (H K : subgroup G) (h : ∀ g : G, g ∈ H ↔ g ∈ K) : H = K :=\nbegin\next x,\nexact h x,\nend\n--another extensionality theorem that asserts two subgroups are equal iff every element is contained in both subgroups. \n\n--finally, remove all refereneces to the carrier function:\n\ntheorem one_mem : (1:G) ∈ H :=\nbegin\napply H.one_mem',\nend\n\ntheorem mul_mem {x y : G}: x ∈ H → y ∈ H → x*y ∈ H :=\nbegin\napply H.mul_mem',\nend\n\ntheorem inv_mem {x:G} : x ∈ H → x⁻¹ ∈ H := \nbegin\napply H.inv_mem',\nend\n\n--A subgroup has now been defined in a way that is natural to the notation in dummit foote. The three important theorems to use are: \n-- H.one_mem :  (1:G) ∈ H\n-- H.mul_mem :  x ∈ H → y ∈ H → x * y ∈ H\n-- H.inv_mem : x ∈ H → x⁻¹ ∈ H\n\n--the subgroup criterion mentioned on page 46\nlemma subgroup_crit {G : Type} [group G] (H : subgroup G) : (∃ g : G, g ∈ H)  ∧ ∀ x y : G, x ∈ H → y ∈ H → x*y⁻¹ ∈ H := \nbegin\nsplit,\nhave h: (1:G) ∈ H := H.one_mem,\nuse (1:G),\nexact h,\nintros x y hx hy,\nhave h2: y⁻¹ ∈ H := H.inv_mem hy,\nexact H.mul_mem hx h2,\nend\n\n--define a structure mysubgroup based on the fact that it is a nonempty subset of G with a particular multiplication relation on the subset.\n--does this structure end up being a subgroup? Let's find out!\n\nstructure mysubgroup (G:Type) [group G] := \n(carrier : set G)\n(non_empty' : carrier.nonempty)\n(mul_con' : ∀ x y: G, x ∈ carrier → y ∈ carrier → x*y⁻¹ ∈ carrier)\n\nvariables (P : mysubgroup G)\n\ninstance : has_mem G (mysubgroup G) := \n{mem := λ m P, m ∈ P.carrier } \n\n--#print mysubgroup \nlemma mysubgroup_one_mem (P:mysubgroup G) : (1:G) ∈ P.carrier :=\nbegin\nhave h: ∃ x:G, x ∈ P.carrier := P.non_empty',\ncases h with x hx,\nhave h2: x*x⁻¹ ∈ P.carrier := P.mul_con' x x hx hx,\nsimp at h2,\nexact h2,\nend\n\nlemma mysubgroup_inv_mem (P:mysubgroup G) : ∀ x:G, x∈P.carrier → x⁻¹∈P.carrier :=\nbegin\nintros x hx,\nhave h1: (1:G) ∈ P.carrier := mysubgroup_one_mem P,\nhave h2: 1*x⁻¹ ∈ P.carrier := P.mul_con' (1:G) x h1 hx,\nsimp at h2,\nexact h2, \nend\n\nlemma mysubgroup_mul_mem (P:mysubgroup G) : ∀ x y : G, x∈P.carrier → y∈P.carrier → x*y ∈ P.carrier :=\nbegin\nintros x y hx hy,\nhave h1: y⁻¹ ∈ P.carrier := mysubgroup_inv_mem P y hy,\nhave h2: x*y⁻¹⁻¹ ∈ P.carrier := P.mul_con' x y⁻¹ hx h1,\nsimp at h2,\nexact h2,\nend\n\n--based on these three lemmas the definition mysubgroup is clearly a group! I think to be completely precise\n--it may also make sense to show that mysubgroup is an instance of subgroup. Do this with Harlan perhaps?\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/sheet1_subgroup_defs_and_exs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.79789629920709}}
{"text": "-- vim: ts=2 sw=0 sts=-1 et ai tw=70\n\nimport .dvd\nimport .induction\n\nnamespace hidden\n\nopen mynat\n\ndef fact: mynat → mynat\n| 0        := 1\n| (succ n) := (fact n) * (succ n)\n\nvariables {m n p k : mynat}\n\n@[simp] theorem fact_zero: fact 0 = 1 := rfl\n@[simp] theorem fact_succ: fact (succ n) = (fact n) * (succ n) := rfl\n\ntheorem fact_nzero:\nfact m ≠ 0 :=\nbegin\n  assume h,\n  induction m with n hn,\n    cases h, -- Magic?\n  rw [fact_succ, mul_comm] at h,\n  have := @mul_integral (succ n) (fact n),\n  from hn (this succ_ne_zero h),\nend\n\ntheorem fact_dvd_self {m : mynat}:\nm ≠ 0 → m ∣ fact m :=\nbegin\n  assume hneq0,\n  cases m, {\n    simp at hneq0,\n    contradiction,\n  }, {\n    existsi (fact m),\n    refl,\n  },\nend\n\ntheorem fact_dvd_succ (m : mynat):\nfact m ∣ fact (succ m) :=\nbegin\n  existsi (succ m),\n  rw mul_comm,\n  refl,\nend\n\ntheorem fact_dvd_le {m n : mynat}:\nm ≤ n → fact m ∣ fact n :=\nbegin\n  assume hmlen,\n  cases hmlen with k hk,\n  revert n,\n  induction k with k_n k_ih, {\n    intro n,\n    assume hmn,\n    simp [hmn],\n  }, {\n    intro n,\n    assume hnmsk,\n    cases k_ih rfl with a ha,\n    existsi a * succ (m + k_n),\n    rw [hnmsk, add_succ, fact_succ, ha,\n        mul_assoc, mul_assoc, mul_comm (fact m)],\n  },\nend\n\ntheorem fact_dvd_nlt {m n : mynat}:\nm ≠ 0 → m ≤ n → m ∣ fact n :=\nbegin\n  assume hmne0,\n  induction n with k hk, {\n    assume hmle0,\n    simp at hmle0,\n    have hmeq0 := le_zero hmle0,\n    exfalso, contradiction,\n  }, {\n    assume hmlesucc,\n    have hmself := fact_dvd_self hmne0,\n    have hfmfsucc := fact_dvd_le hmlesucc,\n    from dvd_trans hmself hfmfsucc,\n  },\nend\n\ntheorem fact_ndvd_lt:\n∀ k: mynat, k ≠ 1 → k ≤ m → ¬(k ∣ (fact m) + 1) :=\nbegin\n  assume n hneq1 hleqm hdiv,\n  cases hdiv with k hk,\n  have : n ∣ 1, {\n    apply dvd_remainder (fact m) 1 (k * n) n, {\n      have hnne0 : n ≠ 0, {\n        assume hn0,\n        rw [hn0, mul_zero, add_comm] at hk,\n        have : (1: mynat) = (0: mynat), {\n          apply add_integral hk,\n        },\n        cases this,\n      },\n      from fact_dvd_nlt hnne0 hleqm,\n    }, {\n      rw mul_comm,\n      apply dvd_mul k,\n      refl,\n    },\n    assumption,\n  },\n  from hneq1 (dvd_one this),\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/fact.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.797891952360821}}
{"text": "/-\nThis file contains a formal computer proof of the linear convergence of gradient descent with \nconstant stepsize for strongly-convex functions. This file only covers\nfunctions on scalar inputs. The file \"GDvec_stronglyConvex.lean\" extends this\nto vectors. It is self-contained other than using properties of real and \nnatural numbers defined in mathlib. I define the properties of strong convexity\nand Lipschitz continuous gradient here and do not rely on the \nmathlib-defined gradient. \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 α that has\n-- a subtraction operation and a multiplication operation.\n-- This allows us to reason about behavior for the case α = ℝ but also \n-- run it when α = float. We will only prove theorems for α = ℝ. \ndef grad_descent {α : Type}\n            [has_sub α]\n            [has_mul α]\n            (η : α) (x0 : α) (gradf : α → α): (ℕ → α) \n| 0      := x0 \n| (n+1)  := grad_descent(n) - η*gradf(grad_descent(n))\n\n/- I take the below to be the **definition** of strongly convex + Lipschitz continuous \n   functions. This property can be derived fairly easily. \n-/\ndef is_strongconvex_LipGrad (gradf : ℝ → ℝ) (m L : ℝ): Prop := \n  ∀ (x y : ℝ),  (gradf(x)-gradf(y))*(x-y) ≥ \n               (m*L/(m+L))*(x-y)^2 + (1/(m+L))*(gradf(x)-gradf(y))^2\n\n\n-- a one-step contraction lemma \nlemma strongconvex_onestep (η m L : ℝ) (x xstar : ℝ) (gradf : ℝ → ℝ)\n                        (hη_low : η ≥ 0) \n                        (hη_up : η ≤ 2/(m+L)) \n                        (h_strongconv_lip : is_strongconvex_LipGrad gradf m L)\n                        (hxstar : gradf xstar = 0)\n                        :\n      (x - η*gradf x - xstar)^2\n      ≤ (1-2*η*m*L/(m+L))*(x - xstar)^2\n   :=\nbegin \n  have h0 : x - η * gradf x - xstar = x - xstar - η * gradf x\n  := sub_right_comm x (η * gradf x) xstar,\n  rw h0,\n  have h1 : (x - xstar - η * gradf x) ^ 2 = (x-xstar)^2 - 2*(x-xstar)*η*gradf x + (η*gradf x)^2 \n  := by ring,\n  rw h1,\n\n  let h2 := h_strongconv_lip x xstar,\n  rw hxstar at h2,\n  rw sub_zero at h2,\n\n  let h3 := mul_le_mul_of_nonneg_left h2 hη_low,\n\n  have h_2 : (2:ℝ) ≥ 0 := by norm_num,\n\n  let h4 := mul_le_mul_of_nonneg_left h3 h_2,\n\n  have h5 : 2 * (η * (m * L / (m + L) * (x - xstar) ^ 2 + 1 / (m + L) * gradf x ^ 2))\n            = 2 * η * m * L / (m + L) * (x - xstar) ^ 2 + 2 * η * 1 / (m + L) * gradf x ^ 2\n            := by ring,\n  rw h5 at h4,\n\n  have h6: 2 * (η * (gradf x * (x - xstar))) = 2 * (x - xstar) * η * gradf x\n        := by ring,\n  rw ← h6,\n  \n  have h7 : 2 * η * m * L / (m + L) * (x - xstar) ^ 2 \n            + 2 * η * 1 / (m + L) * gradf x ^ 2 + (x - xstar) ^ 2\n            ≤ 2 * (η * (gradf x * (x - xstar))) + (x - xstar) ^ 2\n          := by linarith,\n\n  have h8 :  2 * η * 1 / (m + L) * gradf x ^ 2 + (x - xstar) ^ 2\n            - 2 * (η * (gradf x * (x - xstar))) \n            ≤ (x - xstar) ^ 2 - 2 * η * m * L / (m + L) * (x - xstar) ^ 2 \n          := by linarith,\n\n  have h8_1 : 2 * η * 1 / (m + L) =  η * 2 / (m + L) := by ring,\n  rw h8_1 at h8,\n\n  have h8_2 : η*η ≤ η*(2 / (m + L)) := by exact mul_le_mul_of_nonneg_left hη_up hη_low,\n  \n  have h8_3 : η*(2 / (m + L)) = 2 * η * 1 / (m + L) := by ring,\n\n\n  rw h8_3 at h8_2,\n\n  have h8_4 : gradf x ^ 2 ≥ 0 := sq_nonneg (gradf x),\n\n  have h8_5 : η*η*gradf x ^ 2 ≤ 2 * η * 1 / (m + L)*gradf x ^ 2 := by exact mul_mono_nonneg h8_4 h8_2,\n\n  have h9 : η*η*gradf x ^ 2 + (x - xstar) ^ 2\n            - 2 * (η * (gradf x * (x - xstar))) \n            ≤ (x - xstar) ^ 2 - 2 * η * m * L / (m + L) * (x - xstar) ^ 2 \n          := by linarith,\n\n  have h9_1 : (x - xstar) ^ 2 - 2 * η * m * L / (m + L) * (x - xstar) ^ 2 \n              = (1 - 2 * η * m * L / (m + L))*(x - xstar) ^ 2\n            := by ring,\n  rw h9_1 at h9,\n\n  have h9_2 : η * η * gradf x ^ 2 = (η * gradf x) ^ 2 := by ring,\n\n  rw h9_2 at h9,\n\n  linarith,\n\nend \n\n\n-- The main theorem\n-- note that we do not say that xstar is the minimizer, just that its gradient is zero.\n-- Proving that all minimizers have zero gradients would be extra work. \n\ntheorem strongconvex_grad_descent_conv_rate (n : ℕ) (η m L : ℝ) (x0 xstar : ℝ) (gradf : ℝ → ℝ)\n                        (hη_low : η ≥ 0) \n                        (hη_up : η ≤ 2/(m+L)) \n                        (hm : m ≥ 0)\n                        (hL : L ≥ 0)\n                        (hmL : m + L ≠ 0)\n                        (h_strongconv_lip : is_strongconvex_LipGrad gradf m L)\n                        (hxstar : gradf xstar = 0)\n                        :\n      ((grad_descent η x0 gradf n) - xstar)^2\n      ≤ ((1-2*η*m*L/(m+L))^n)*(x0 - xstar)^2\n   :=\nbegin\ninduction n with k hk,\nhave h0 : grad_descent η x0 gradf 0 = x0 := by refl,\nrw h0,\nrw pow_zero,\nrw one_mul,\n\nhave h1 : grad_descent η x0 gradf k.succ  = \n          grad_descent η x0 gradf k - η*gradf(grad_descent η x0 gradf k) := by refl,\nrw h1,\n\nhave h2 := strongconvex_onestep η m L (grad_descent η x0 gradf k) xstar gradf hη_low hη_up h_strongconv_lip hxstar,\n\nrw pow_succ _ k,\n\nhave h2_1 : L*η ≤ L*(2 / (m+L)) := mul_le_mul_of_nonneg_left hη_up hL,\n\nhave h2_2 : m*(L*η) ≤ m*(L*(2 / (m+L))) := mul_le_mul_of_nonneg_left h2_1 hm,\n\nhave h2_3 : (2:ℝ)≥ 0 := by norm_num,\n\nhave h2_4 : 2*(m*(L*η)) ≤ 2*(m*(L*(2 / (m+L)))) := mul_le_mul_of_nonneg_left h2_2 h2_3,\n\nhave h2_5 : (m+L) ≥ 0 := by linarith,\n\nhave h2_6 : 2*(m*(L*η))/(m+L) ≤ 2*(m*(L*(2 / (m+L))))/(m+L) := div_le_div_of_le h2_5 h2_4,\n\nhave h2_7 : 2*(m*(L*η))/(m+L) = 2* m* L*η /(m+L) := by ring,\n\nrw h2_7 at h2_6,\n\nhave h2_8 : 2*(m*(L*(2 / (m+L))))/(m+L)  = 2*m*L* 2 /(m+L)/(m+L) := by ring,\n\nrw h2_8 at h2_6,\n\nhave h2_9 : 2*m*L* 2 /(m+L)/(m+L) = 4*m*L /(m+L)/(m+L) := by ring,\n\nrw h2_9 at h2_6,\n\nhave h2_10 : 4*m*L /(m+L)/(m+L) = 4*m*L /((m+L)*(m+L)) := div_div_eq_div_mul (4 * m * L) (m + L) (m + L),\n\nrw h2_10 at h2_6,\n\nhave h2_11 : 4*m*L /((m+L)*(m+L)) = 4*m*L /((m+L)^2),\n  rw ← pow_two,\nrw h2_11 at h2_6,\n\nhave h3 : 1 - 2 * m * L * η / (m + L) ≥ 1 -  4 * m * L / (m + L) ^ 2 := by linarith,\n\nhave h3_1 : (m + L) ^ 2 ≠ 0 := pow_ne_zero 2 hmL,\nhave h3_2 : 1 = (m + L) ^ 2 / (m + L) ^ 2 := by exact (div_self h3_1).symm,\n\nhave h3_3 : 1 -  4 * m * L / (m + L) ^ 2 = (m + L) ^ 2 / (m + L) ^ 2 -  4 * m * L / (m + L) ^ 2\n    := by linarith,\n\nrw h3_3 at h3,\n\n\nhave h3_4 : (m + L) ^ 2 / (m + L) ^ 2 -  4 * m * L / (m + L) ^ 2\n          = ((m + L) ^ 2 -  4 * m * L) / (m + L) ^ 2\n          := div_sub_div_same ((m + L) ^ 2) (4 * m * L) ((m + L) ^ 2),\n\nrw h3_4 at h3,\n\nhave h3_5 : (m + L) ^ 2 -  4 * m * L = m^2 + 2*m*L+L^2 - 4*m*L := by ring,\n\nrw h3_5 at h3,\n\nhave h3_6 : m^2 + 2*m*L+L^2 - 4*m*L  = m^2 - 2*m*L + L^2 := by ring,\n\nrw h3_6 at h3,\n\nhave h3_7 : m^2 - 2*m*L + L^2 = (m-L)^2 := by ring,\n\nrw h3_7 at h3,\n\nhave h3_8 : (m - L) ^ 2 / (m + L) ^ 2 = ((m - L) / (m + L) )^ 2 := by exact (div_pow (m - L) (m + L) 2).symm,\n\nrw h3_8 at h3,\n\nhave h3_9 : ((m - L) / (m + L) )^ 2 ≥ 0 := sq_nonneg ((m - L) / (m + L)),\n\nhave h4 : 1 - 2 * m * L * η / (m + L) ≥ 0 := by linarith,\nhave h4_1 : 1 - 2 * m * L * η / (m + L)\n          = 1 - 2 * η * m * L / (m + L) := by ring,\nrw h4_1 at h4,\n\nhave h5 : (1 - 2 * η * m * L / (m + L)) * (grad_descent η x0 gradf k - xstar) ^ 2\n    ≤ (1 - 2 * η * m * L / (m + L))*((1 - 2 * η * m * L / (m + L)) ^ k * (x0 - xstar) ^ 2)\n    := by exact mul_le_mul_of_nonneg_left hk h4,\n\nhave h5_1 : (1 - 2 * η * m * L / (m + L))*((1 - 2 * η * m * L / (m + L)) ^ k * (x0 - xstar) ^ 2)\n      = \n      (1 - 2 * η * m * L / (m + L))*(1 - 2 * η * m * L / (m + L)) ^ k * (x0 - xstar) ^ 2\n      := by ring,\nrw h5_1 at h5,\n\nlinarith,\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/old_scalr_proofs/GD_stronglyConvex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8976953016868439, "lm_q1q2_score": 0.7978345985410827}}
{"text": "/-\n  a type called MyNat\n  a term 0 : MyNat, which is the number zero\n  a function succ : MyNat -> MyNat, which is +1\n  Use numerical notation, 0, 1, 2, ...\n  Use + and * to represent addition and multiplication\n  lemmas we already proved (add_zero, add_succ, and zero_succ_add)\n  tactics rewrite and rfl\n-/\n\nimport MyNat\nimport MyNat.lemma\nimport MyNat.tutorial_world\n\nopen MyNat\n\nlemma zero_add (n : ℕ) : zero + n = n :=\n  by\n  induction n with \n  | zero => rewrite [add_zero] rfl\n  | succ n' ih => rewrite [add_succ, ih] rfl\n\nlemma add_assoc (a b c : ℕ) :\n  (a + b) + c = a + (b + c) :=\n  by\n  induction c with\n  | zero => rewrite [add_zero, add_zero] rfl\n  | succ c' ih => rewrite [add_succ, add_succ, add_succ, ih] rfl\n\nlemma succ_add (a b : ℕ) : succ a + b = succ (a + b) :=\n  by induction b with \n  | zero => rewrite [add_zero, add_zero] rfl\n  | succ b' ih => rewrite [add_succ a b', <- ih, add_succ] rfl\n\nlemma add_comm (a b : ℕ) : a + b = b + a :=\n  by induction b with\n  | zero => rewrite [add_zero, zero_add] rfl\n  | succ b' ih => rewrite [add_succ, succ_add, ih] rfl\n\nlemma one_eq_succ_zero : 1 = succ zero := by rfl\nlemma two_eq_succ_one :  2 = succ 1    := by rfl\n\nlemma succ_eq_add_one (n : ℕ) : succ n = n + 1 :=\n  by induction n with\n  | zero => rewrite [one_eq_succ_zero, zero_add] rfl\n  | succ n' ih => rewrite [ih, <- succ_add, ih] rfl\n\nlemma add_right_comm (a b c : ℕ) : a + b + c = a + c + b :=\n  by rewrite [add_assoc, add_comm b c, add_assoc a c b] rfl\n\n", "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/addition_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850021922959, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7976706292989109}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nimport AdditionWorld.Level1 -- zero_add\nimport AdditionWorld.Level5 -- one_eq_succ_zero, succ_eq_add_one\nnamespace MyNat\nopen MyNat\n\n/-!\n# Multiplication World\n\n## Level 3: `one_mul`\n\nThese proofs from addition world might be useful here:\n\n* `one_eq_succ_zero : 1 = succ 0`\n* `succ_eq_add_one a : succ a = a + 1`\n\nWe just proved `mul_one`, now let's prove `one_mul`. Then we will have proved, in fancy terms, that\n1 is a \"left and right identity\" for multiplication (just like we showed that 0 is a left and right\nidentity for addition with `add_zero` and `zero_add`).\n\n## Lemma\n\nFor any natural number `m`, we have `1 * m = m.`\n-/\nlemma one_mul (m : MyNat) : 1 * m = m := by\n  induction m with\n  | zero =>\n    rw [zero_is_0]\n    rw [mul_zero]\n  | succ m ih =>\n    rw [mul_succ]\n    rw [ih]\n    rw [succ_eq_add_one]\n\n/-!\nNext up is [Multiplication 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/MultiplicationWorld/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9648551566309688, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7976571375567288}}
{"text": "-- Es_menor_o_igual_que_suma_con_no_negativo.lean\n-- Es menor o igual que suma con no negativo\n-- José A. Alonso Jiménez\n-- Sevilla, 14 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar si a y b son números naturales y b es no\n-- negativo, entonces a ≤ a + b\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nvariables {a b : ℝ}\n\n-- 1ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nbegin\n  calc a = a + 0 : by rw add_zero\n     ... ≤ a + b : by exact add_le_add_left hb a,\nend\n\n-- Comentario: Se ha usado el lema\n-- + add_le_add_left : a ≤ b → ∀ (c : ℝ), c + a ≤ c + b \n\n-- 2ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nbegin\n  calc a = a + 0 : (add_zero a).symm\n     ... ≤ a + b : add_le_add_left hb a,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nbegin\n  calc a = a + 0 : by ring\n     ... ≤ a + b : add_le_add_left hb a,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nby simp [hb]\n\n-- 5ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nby linarith\n\n-- 6ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nby finish\n\n-- 7ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nle_add_of_nonneg_right hb\n\n-- Comentario: Se usa el lema\n-- + le_add_of_nonneg_right : 0 ≤ b → a ≤ a + b \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/Es_menor_o_igual_que_suma_con_no_negativo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7975625271535881}}
{"text": "/-\nIn lean we represent: (1) propositions as\ntypes and (2) predicates as parameterized\npropositions.\n\nA parameterized type gives rise to a whole\nfamily of proposition, once for each value\nof each parameter.\n\nWe can think of one-parameter predicates \nas specifying *properties* of objects. As\nan example, as defined, is_even : ℕ → Prop\nexpresses the property of a natural number\n(an argument value) \"being even\". We define\nthe constructors to ensure that there is a\nproof of (is_even n) if and only if (n : ℕ)\nis (a term that represents) an even number.\n\nOne-parameter predicates thus also specify \n*sets* of objects: namely all and only those\nvalues of a given argument type that have the \nspecified property as shown by the existence\nof a proof that such a value \"satisfies the \npredicate\" (makes the resulting proposition\ntrue).\n\nThe is_even predicate thus specifies the\nset of all even natural numbers, which we\ncan write as {0, 2, 4, 6, ...} or, better,\nas { n : ℕ | is_even n }.\n\nWe can think of two-parameter predicates as \nspecifying binary relations, that is, sets of\n*pairs* of argument values that make a given\nproposition true.\n\nThe most commonplace example of a two-argument\npredicate is equals. We can write (_ = _) to \nmake it clear that equals takes two values and\nyields a proposition that the first equals the\nsecond. For example, if a and b are of type ℕ, \nthen (a = b) is a proposition that has a proof\nif and only if the two terms really are equal\n(when reduced). So, for example, 4 = 2 + 2 is\ntrue, there is a proof of it, because reducing\n2 + 2 to 4 reduces the whole proposition to \n4 = 4, and there is a proof of this proposition.\n\nThe proposition, a = b, in Lean is just a nice\nshorthand notation for (eq a b). The two-place\npredicate, eq, implements the equality relation. \nIt's polymorphic: it takes a *type parameter*, α,\nimplicitly. It then explicitly takes two values,\na and b, of type α, and yields the proposition, \na = b (which is of course itself a type).\n\nThe eq \"type builder\" (taking α and two values,\na and b of type α) and yielding the proposition\n(a type), a = b, provides a single constructor\nwith which to build proofs. It's called refl,\nand it establishes the \"reflexive\" property of\nthe eq relation, by taking *any* value, a : α,\nfor any type, α, and by returning a proof of\n(eq a a), that is, of a = a. So, by applying\neq.refl to any value, a, of any type, we get\na proof of (a = a), and those are the *only*\nproofs of equality that can be constructed.\nThere's thus no way to prove that 0 = 1, for\nexample, because those terms don't reduce to\nthe same values, and we can only use eq.refl\nto construct proofs that two terms are equal\nif they really do reduce to exactly the same\nvalue.\n\nFinally, we will represent some, but no all,\nof the logical connetives, including \"and\",\n\"or\", and \"iff\", as polymorphic propositions.\nWhereas a predicate, such as eq, will take\nvalues of arbitrary types as arguments (e.g.,\neq can take values of type ℕ), connectives\nare like polymorphic types: they take types\nas arguments, but in this case the types are\nof type Prop.\n\nConsider \"and\" for example. If P and Q are\nany two pre-existing propositions (types of\ntype Prop), then we can form the proposition,\nP ∧ Q, and it, too, will be a proposition (a\ntype of type, Prop). The type of \"and\" is thus\nProp → Prop → Prop: it takes two propositions\n(types of type Prop) as arguments and yields\na new proposition (a new type of type Prop).\n\nTo enforce the logical meaning of \"and\", we\ndefine the \"and\" type builder to have just\none constructor, which we call \"intro\", that\nif applied to a proof, p, of P and to a proof,\nq, of Q yields a term, (and.intro p q), that\nis axiomatically accepted as being a \"proof\"\nof (and P Q), which we write using an infix\nnotation as (P ∧ Q). \n\nFinally, we note that if we're given a term,\n(and.intro p q), of type (P ∧ Q), that is, if\nwe're given a proof of (P ∧ Q), we can get a\nproof of P from it, by \"destructuring\" the\nterm using pattern matching. For example, we\ncan obtain \"p\" (the proof of P \"contained \ninside\" the proof of P ∧ Q) with the following\nrule: | (and.intro p _) := p. This is how we\nimplement the two \"elimination rules\" for and.\n-/\n\n/-\nHere's a statement of the proposition that\n2 + 2 = 4 and a proof of it. \n-/\n\nlemma proof_of_two_plus_two_eq_four : 2 + 2 = 4 :=\n    eq.refl 4\n\n/-\n1. State and prove the proposition that the\nstring,\"Lean!\", appended to the string, \"Hello, \"\nis equal to the string, \"Hello, Lean!\". You may\nand should use the Lean library-provided string \nappend operator, ++, as an infix notation for \nappend.\n-/\n\n-- string append example\n#eval \"Hi \" ++ \"There!\"\n\n-- fill in the blanks\nlemma proof1 : _ = _\n\n/-\n2.  Sometimes we want to state and prove a \nproposition without binding a name to the proof.\nFor that, instead of using def, theorem, or\nlemma, we can use \"example.\" Here's an example. \n-/\n\nexample : 1 = 1 := _    -- Fill blank with proof.\n\n/-\nNote that we can use example for ordinary types\nas well.\n-/\n\nexample : ℕ := 5\n\n/-\n2. State and prove the proposition that 3 * 4 = 12,\nusing \"example.\"\n-/\n\n-- Answer Here\n\n/-\n3. Use example to formally state and prove the\nproposition that 1 = 1 ∧ 0 = 0. \n-/\n\n-- Here\n\n\n/-\n4. Complete the following program to show that\nif P and Q are arbitrary propositions, and *if* \nyou're given a proof of P and Q, then you can \nobtain and return a proof of P.\n\nHint: In Lean, and.intro is the one introduction\n(proof creating) rule for and, and and.elim_left\nand and.elim_right are the two elimination rules.\nThey are functions. Use one of them!\n-/\n\ntheorem P_and_Q_imp_P {P Q : Prop} (pq : P ∧ Q) : P :=\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/assignments/quiz1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7975396788223675}}
{"text": "/-\nCopyright (c) 2020. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jalex Stark, Yury Kudryashov\n-/\nimport algebra.big_operators.basic\nimport data.real.basic\n\n/-!\n# Sum of the Reciprocals of the Triangular Numbers\n\nThis file proves Theorem 42 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\n\nWe interpret “triangular numbers” as naturals of the form $\\frac{k(k+1)}{2}$ for natural `k`.\nWe prove that the sum of the reciprocals of the first `n` triangular numbers is $2 - \\frac2n$.\n\n## Tags\n\ndiscrete_sum\n-/\n\nopen_locale big_operators\nopen finset\n\n/-- **Sum of the Reciprocals of the Triangular Numbers** -/\nlemma inverse_triangle_sum :\n  ∀ n, ∑ k in range n, (2 : ℚ) / (k * (k + 1)) = if n = 0 then 0 else 2 - (2 : ℚ) / n :=\nbegin\n  refine sum_range_induction _ _ (if_pos rfl) _,\n  rintro (_|n), { rw [if_neg, if_pos]; norm_num },\n  simp_rw [if_neg (nat.succ_ne_zero _), nat.succ_eq_add_one],\n  have A : (n + 1 + 1 : ℚ) ≠ 0, by { norm_cast, norm_num },\n  push_cast,\n  field_simp [nat.cast_add_one_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/archive/100-theorems-list/42_inverse_triangle_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8438950947024556, "lm_q1q2_score": 0.7974764017289152}}
{"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 Mathlib.Algebra.Divisibility.Basic\nimport Mathlib.Tactic.Ring\nimport Mathlib.Data.Nat.Prime\n\n/-!\n# IMO 1959 Q1\nProve that the fraction `(21n+4)/(14n+3)` is irreducible for every\nnatural number `n`.\n\nSince Lean doesn't have a concept of \"irreducible fractions\" per se,\nwe just formalize this as saying the numerator and denominator are\nrelatively prime.\n-/\n\nlemma calculation\n    (n k : ℕ)\n    (h1 : k ∣ 21 * n + 4)\n    (h2 : k ∣ 14 * n + 3) :\n    k ∣ 1 := by\n  have h3 : k ∣ 2 * (21 * n + 4) := h1.mul_left 2\n  have h4 : k ∣ 3 * (14 * n + 3) := h2.mul_left 3\n  have h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1 := by ring\n  exact (Nat.dvd_add_right h3).mp (h5 ▸ h4)\n\ntheorem imo1959_q1 : ∀ n : ℕ, Nat.coprime (21 * n + 4) (14 * n + 3) :=\nfun n => Nat.coprime_of_dvd' <| λ k _ h1 h2 => calculation n k h1 h2\n\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/Imo1959Q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693716759488, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7974696313587241}}
{"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 data.set.pointwise.smul\nimport algebra.hom.iterate\nimport dynamics.fixed_points.basic\n\n/-!\n# Results about pointwise operations on sets with iteration.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nopen_locale pointwise\nopen set function\n\n/-- Let `n : ℤ` and `s` a subset of a commutative group `G` that is invariant under preimage for\nthe map `x ↦ x^n`. Then `s` is invariant under the pointwise action of the subgroup of elements\n`g : G` such that `g^(n^j) = 1` for some `j : ℕ`. (This subgroup is called the Prüfer subgroup when\n `G` is the `circle` and `n` is prime.) -/\n@[to_additive \"Let `n : ℤ` and `s` a subset of an additive commutative group `G` that is invariant\nunder preimage for the map `x ↦ n • x`. Then `s` is invariant under the pointwise action of the\nadditive subgroup of elements `g : G` such that `(n^j) • g = 0` for some `j : ℕ`. (This additive\nsubgroup is called the Prüfer subgroup when `G` is the `add_circle` and `n` is prime.)\"]\nlemma smul_eq_self_of_preimage_zpow_eq_self {G : Type*} [comm_group G]\n  {n : ℤ} {s : set G} (hs : (λ x, x^n)⁻¹' s = s)\n  {g : G} {j : ℕ} (hg : g^(n^j) = 1) : g • s = s :=\nbegin\n  suffices : ∀ {g' : G} (hg' : g'^(n^j) = 1), g' • s ⊆ s,\n  { refine le_antisymm (this hg) _,\n    conv_lhs { rw ← smul_inv_smul g s, },\n    replace hg : (g⁻¹)^(n^j) = 1, { rw [inv_zpow, hg, inv_one], },\n    simpa only [le_eq_subset, set_smul_subset_set_smul_iff] using this hg, },\n  rw (is_fixed_pt.preimage_iterate hs j : ((zpow_group_hom n)^[j])⁻¹' s = s).symm,\n  rintros g' hg' - ⟨y, hy, rfl⟩,\n  change ((zpow_group_hom n)^[j]) (g' * y) ∈ s,\n  replace hg' : ((zpow_group_hom n)^[j]) g' = 1, { simpa [zpow_group_hom], },\n  rwa [monoid_hom.iterate_map_mul, hg', one_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/set/pointwise/iterate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7973783721730469}}
{"text": "/-\n# Example: Sorting\n\nIn this example we specify a function that sorts a list into ascending order.\n-/\nimport LeanSpec.lib.Util\n\n/-\nInformally, a sort function takes a list as argument, and returns a list that\nis an ordered permutation of its argument. A predicate that specifies whether\na list is ordered might be:\n-/\ndef Ordered₁ [LT α] : List α → Prop\n | [] | [_] => True\n | a::b::as => a < b ∧ Ordered₁ (b::as)\n\n/-\nEmpty and singleton lists are trivially ordered. A list of two or more items is ordered\nif the first item precedes the second item, and the tail is ordered. The type of items in\nthe list must admit an order relation, stated in the definition by `[LT α]`: the type `α`\nis an instance of the type class `LT`.\n\nFirst let's try a naive definition. Two lists are permutations of each other if they\ncontain the same items, irrespective of order:\n-/\ndef Permutation₁ (as bs : List α) :=\n  ∀ a : α, a ∈ as ↔ a ∈ bs\n\n/-\nWith these definitions we can now specify the sorting function:\n-/\ndef Sort₁ [LT α] (as : List α) :=\n  { sas : List α // Ordered₁ sas ∧ Permutation₁ as sas }\n\n/-\n`Sort₁` takes as argument a list of items with an order relation,\nand returns a list that is an ordered permutation of its input.\n\nThere is, unfortunately, a problem with the specification of `Sort₁`: it is not\npossible to derive a program that meets the specification. Do you see why?\n\nConsider this clause from the definition of `Ordered₁`:\n- `a::b::as => a < b ∧ Ordered₁ (b::as)`.\n\nWhat happens when the input list is `[2, 2]`? The definition of `Ordered₁` states that two\nconsecutive items in the list must be related by `<`, but `2 ≮ 2`. The specification does\nnot accommodate lists with duplicate entries.\n\nJust as there is no guarantee a postulated mathematical theorem is provable,\nthere is no guarantee a program specification is implementable (they are after\nall different expressions of the same concept).\n\nLet's try again. First note the function `numOccurs` (defined in [Util](lib/Util.md)) that counts\nthe number of occurrences of an item in a list:\n-/\n#check List.numOccurs\n\n/-\nThe `Ordered` predicate is largely as before except the comparison operator\nis `≤` (with corresponding type class `LE`) rather than `<`:\n-/\ndef Ordered₂ [LE α] : List α → Prop\n | [] | [_] => True\n | a::b::as => a ≤ b ∧ Ordered₂ (b::as)\n\n/-\nThe `Permutation` predicate cannot simply check for membership, it must ensure\nthe number of occurrences of any item in one list is the same as the number of\noccurrences in the other list.\n-/\ndef Permutation₂ [BEq α] (as bs : List α) :=\n  ∀ a : α, as.numOccurs a = bs.numOccurs a\n\n/-\n`Sort₂` employs the new `Ordered₂` and `Permutation₂` predicates, but otherwise is\nunchanged:\n-/\ndef Sort₂ [BEq α] [LE α] (as : List α) :=\n  { sas : List α // Ordered₂ sas ∧ Permutation₂ as sas }\n\n/-\nIn fact `LE` is insufficient. It only guarantees there is a binary predicate on the type, not\nthat it is the predicate we normally think of as _less than or equal_. The predicate must be\na partial order, but we won't go into the details here.\n\nThe predicate `Ordered₂` is typical of a traditional approach, perhaps with the\nexception the result is a `Prop` rather than a `Bool`. Dependently typed\nlanguages such as Lean offer an alternative approach; namely that of _Inductive Predicates_.\nAn inductive predicate is simply an inductive definition of a proposition as opposed to\nan inductive definition of a type (list, tree, etc), and a member of the\ninductive proposition is a proof of the proposition. For `Ordered` we could have:\n-/\ninductive Ordered₃ [LE α] : List α → Prop\n  | empty       : Ordered₃ []\n  | singleton a : Ordered₃ [a]\n  | twoplus a b as (hab : a ≤ b) (hbas : Ordered₃ (b::as)) :\n                  Ordered₃ (a::b::as)\n\n/-\nThe three clauses state:\n- `empty` is a proof that the empty list is ordered;\n- `singleton a` is a proof that the singleton list containing `a` is ordered;\n- `twoplus a b as hab hbas` is a proof that the list `a::b::as` is ordered,\ngiven that `hab` is evidence `a ≤ b` and `hbas` is a proof that `b::as` is ordered.\n\nNote the correspondence between the clauses in the inductive definition of `Ordered₃`\nand the recursive definition of `Ordered₂`.\n\nAs with programming and proof, there is no single way, or best way, to specify a\nprogram. The activity of specification is an iterative process, as the specification\nis refined, and clearer ways of expressing concepts are discovered.\n\n## Exercises\n\n- Specify a function that, given a natural number, returns the prime factors of the number.\nUse the `Prime` property from the last exercise.\n\n- Using `Permutation₂`, specify a function that returns all permutations of an input list.\n\n- The Lean standard library, `std4`, defines an inductive proposition `List.Chain'`. Specify\n`Sort` using `Chain'`.\n-/\n#check List.Chain'", "meta": {"author": "paulch42", "repo": "lean-spec", "sha": "4755a25caf719f935bcc4d54bd8a86462c9aceb9", "save_path": "github-repos/lean/paulch42-lean-spec", "path": "github-repos/lean/paulch42-lean-spec/lean-spec-4755a25caf719f935bcc4d54bd8a86462c9aceb9/LeanSpec/Sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8670357701094304, "lm_q1q2_score": 0.7973629740642357}}
{"text": "import .love11_logical_foundations_of_mathematics_demo\n\n\n/- # LoVe Exercise 11: Logical Foundations of Mathematics -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Vectors as Subtypes\n\nRecall the definition of vectors from the demo: -/\n\n#check vector\n\n/- The following function adds two lists of integers elementwise. If one\nfunction is longer than the other, the tail of the longer function is\ntruncated. -/\n\ndef list.add : list ℤ → list ℤ → list ℤ\n| []        []        := []\n| (x :: xs) (y :: ys) := (x + y) :: list.add xs ys\n| []        (y :: ys) := []\n| (x :: xs) []        := []\n\n/- 1.1. Show that if the lists have the same length, the resulting list also\nhas that length. -/\n\nlemma list.length_add :\n  ∀(xs : list ℤ) (ys : list ℤ) (h : list.length xs = list.length ys),\n    list.length (list.add xs ys) = list.length xs\n| []        []        :=\n  sorry\n| (x :: xs) (y :: ys) :=\n  sorry\n| []        (y :: ys) :=\n  sorry\n| (x :: xs) []        :=\n  sorry\n\n/- 1.2. Define componentwise addition on vectors using `list.add` and\n`list.length_add`. -/\n\ndef vector.add {n : ℕ} : vector ℤ n → vector ℤ n → vector ℤ n :=\nsorry\n\n/- 1.3. Show that `list.add` and `vector.add` are commutative. -/\n\nlemma list.add.comm :\n  ∀(xs : list ℤ) (ys : list ℤ), list.add xs ys = list.add ys xs :=\nsorry\n\nlemma vector.add.comm {n : ℕ} (x y : vector ℤ n) :\n  vector.add x y = vector.add y x :=\nsorry\n\n\n/- ## Question 2: Integers as Quotients\n\nRecall the construction of integers from the lecture, not to be confused with\nLean's predefined type `int` (= `ℤ`): -/\n\n#check int.rel\n#check int.rel_iff\n#check int\n\n/- 2.1. Define negation on these integers. -/\n\ndef int.neg : int → int :=\nsorry\n\n/- 2.2. Prove the following lemmas about negation. -/\n\nlemma int.neg_eq (p n : ℕ) :\n  int.neg ⟦(p, n)⟧ = ⟦(n, p)⟧ :=\nsorry\n\nlemma int.neg_neg (a : int) :\n  int.neg (int.neg a) = a :=\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/love11_logical_foundations_of_mathematics_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.7973629516168578}}
{"text": "/-\nCopyright (c) 2018 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, 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\n\n/-!\n# Submonoids: membership criteria\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 ∈ S` where `S` is a multiplicative (resp., additive) submonoid and\n  `n` is a natural number, then `x^n` (resp., `n • 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`: the multiplicative (resp., additive) closure\n  of `{x}` consists of powers (resp., natural multiples) of `x`.\n\n## Tags\nsubmonoid, submonoids\n-/\n\nopen_locale big_operators\n\nvariables {M : Type*}\nvariables {A : Type*}\n\nnamespace submonoid\n\nsection assoc\nvariables [monoid M] (S : submonoid M)\n\n@[simp, norm_cast, to_additive coe_nsmul] theorem coe_pow (x : S) (n : ℕ) :\n  ↑(x ^ n) = (x ^ n : M) :=\nS.subtype.map_pow x n\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 {ι M} [comm_monoid M] (S : submonoid M)\n  (f : ι → S) (s : finset ι) :\n  ↑(∏ i in s, f i) = (∏ 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 : ∀ x ∈ l, x ∈ S) : l.prod ∈ S :=\nby { lift l to list S using hl, rw ← 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 : ∀ a ∈ m, a ∈ S) : m.prod ∈ S :=\nby { lift m to multiset S using hm, rw ← 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] (S : submonoid M)\n  {ι : Type*} {t : finset ι} {f : ι → M} (h : ∀c ∈ t, f c ∈ S) :\n  ∏ c in t, f c ∈ S :=\nS.multiset_prod_mem (t.1.map f) $ λ x hx, let ⟨i, hi, hix⟩ := multiset.mem_map.1 hx in hix ▸ h i hi\n\n@[to_additive nsmul_mem] lemma pow_mem {x : M} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\nby simpa only [coe_pow] using ((⟨x, hx⟩ : S) ^ n).coe_prop\n\nend assoc\n\nsection non_assoc\nvariables [mul_one_class M] (S : submonoid M)\n\nopen set\n\n@[to_additive]\nlemma mem_supr_of_directed {ι} [hι : nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S)\n  {x : M} :\n  x ∈ (⨆ i, S i) ↔ ∃ i, x ∈ S i :=\nbegin\n  refine ⟨_, λ ⟨i, hi⟩, (set_like.le_def.1 $ le_supr S i) hi⟩,\n  suffices : x ∈ closure (⋃ i, (S i : set M)) → ∃ i, x ∈ S i,\n    by simpa only [closure_Union, closure_eq (S _)] using this,\n  refine (λ hx, closure_induction hx (λ _, mem_Union.1) _ _),\n  { exact hι.elim (λ i, ⟨i, (S i).one_mem⟩) },\n  { rintros x y ⟨i, hi⟩ ⟨j, hj⟩,\n    rcases hS i j with ⟨k, hki, hkj⟩,\n    exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ }\nend\n\n@[to_additive]\nlemma coe_supr_of_directed {ι} [nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S) :\n  ((⨆ i, S i : submonoid M) : set M) = ⋃ i, ↑(S i) :=\nset.ext $ λ 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 (≤) S) {x : M} :\n  x ∈ Sup S ↔ ∃ s ∈ S, x ∈ 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 (≤) S) :\n  (↑(Sup S) : set M) = ⋃ s ∈ S, ↑s :=\nset.ext $ λ x, by simp [mem_Sup_of_directed_on Sne hS]\n\n@[to_additive]\nlemma mem_sup_left {S T : submonoid M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T :=\nshow S ≤ S ⊔ T, from le_sup_left\n\n@[to_additive]\nlemma mem_sup_right {S T : submonoid M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T :=\nshow T ≤ S ⊔ T, from le_sup_right\n\n@[to_additive]\nlemma mul_mem_sup {S T : submonoid M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n\n@[to_additive]\nlemma mem_supr_of_mem {ι : Type*} {S : ι → submonoid M} (i : ι) :\n  ∀ {x : M}, x ∈ S i → x ∈ supr S :=\nshow S i ≤ supr S, from le_supr _ _\n\n@[to_additive]\nlemma mem_Sup_of_mem {S : set (submonoid M)} {s : submonoid M}\n  (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ Sup S :=\nshow s ≤ Sup S, from le_Sup hs\n\nend non_assoc\n\nend submonoid\n\nnamespace free_monoid\n\nvariables {α : Type*}\n\nopen submonoid\n\n@[to_additive]\ntheorem closure_range_of : closure (set.range $ @of α) = ⊤ :=\neq_top_iff.2 $ λ x hx, free_monoid.rec_on x (one_mem _) $ λ 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 ⟨multiplicative.of_add 1, pow_one x⟩) $\n  λ x ⟨n, hn⟩, hn ▸ 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 ∈ closure ({x} : set M) ↔ ∃ n:ℕ, x^n=y :=\nby rw [closure_singleton_eq, mem_mrange]; refl\n\nlemma mem_closure_singleton_self {y : M} : y ∈ closure ({y} : set M) :=\nmem_closure_singleton.2 ⟨1, pow_one y⟩\n\nlemma closure_singleton_one : closure ({1} : set M) = ⊥ :=\nby simp [eq_bot_iff_forall, mem_closure_singleton]\n\n@[to_additive]\nlemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s → M)).mrange :=\nby rw [mrange_eq_map, ← free_monoid.closure_range_of, map_mclosure, ← set.range_comp,\n  free_monoid.lift_comp_of, subtype.range_coe]\n\n@[to_additive]\nlemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x ∈ closure s) :\n  ∃ (l : list M) (hl : ∀ y ∈ l, y ∈ s), l.prod = x :=\nbegin\n  rw [closure_eq_mrange, mem_mrange] at hx,\n  rcases hx with ⟨l, hx⟩,\n  exact ⟨list.map coe l, λ y hy, let ⟨z, hz, hy⟩ := list.mem_map.1 hy in hy ▸ z.2, hx⟩\nend\n\n@[to_additive]\nlemma exists_multiset_of_mem_closure {M : Type*} [comm_monoid M] {s : set M}\n  {x : M} (hx : x ∈ closure s) : ∃ (l : multiset M) (hl : ∀ y ∈ l, y ∈ s), l.prod = x :=\nbegin\n  obtain ⟨l, h1, h2⟩ := exists_list_of_mem_closure hx,\n  exact ⟨l, h1, (multiset.coe_prod l).trans h2⟩,\nend\n\n/-- The submonoid generated by an element. -/\ndef powers (n : M) : submonoid M :=\nsubmonoid.copy (powers_hom M n).mrange (set.range ((^) n : ℕ → M)) $\nset.ext (λ n, exists_congr $ λ i, by simp; refl)\n\n@[simp] lemma mem_powers (n : M) : n ∈ powers n := ⟨1, pow_one _⟩\n\nlemma mem_powers_iff (x z : M) : x ∈ powers z ↔ ∃ n : ℕ, 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 ∈ P) : powers n ≤ P :=\nλ x hx, match x, hx with _, ⟨i, rfl⟩ := P.pow_mem h i end\n\n/-- Exponentiation map from natural numbers to powers. -/\ndef pow (n : M) (m : ℕ) : powers n := ⟨n ^ m, m, rfl⟩\n\n/-- Logarithms from powers to natural numbers. -/\ndef log [decidable_eq M] {n : M} (p : powers n) : ℕ :=\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 (λ m : ℕ, n ^ m) ↔ function.injective (pow n) :=\nsubtype.coe_injective.of_comp_iff (pow n)\n\ntheorem log_pow_eq_self [decidable_eq M] {n : M} (h : function.injective (λ m : ℕ, n ^ m)) (m : ℕ) :\n  log (pow n m) = m :=\npow_right_injective_iff_pow_injective.mp h $ pow_log_eq_self _\n\ntheorem log_pow_int_eq_self {x : ℤ} (h : 1 < x.nat_abs) (m : ℕ) : log (pow x m) = m :=\nlog_pow_eq_self (int.pow_right_injective h) _\n\nend submonoid\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 ⊔ t = (s.subtype.coprod t.subtype).mrange :=\nby rw [mrange_eq_map, ← 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 ∈ s ⊔ t ↔ ∃ (y ∈ s) (z ∈ 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 ⟨1, one_nsmul x⟩) $\n  λ x ⟨n, hn⟩, hn ▸ 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 ∈ closure ({x} : set A) ↔ ∃ n:ℕ, n • x = y :=\nby rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl\n\nlemma closure_singleton_zero : closure ({0} : set A) = ⊥ :=\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 (λ i, i • x : ℕ → A)) $\nset.ext (λ n, exists_congr $ λ i, by simp; refl)\n\n@[simp] lemma mem_multiples (x : A) : x ∈ multiples x := ⟨1, one_nsmul _⟩\n\nlemma mem_multiples_iff (x z : A) : x ∈ multiples z ↔ ∃ n : ℕ, n • z = x := iff.rfl\n\nlemma multiples_eq_closure (x : A) : multiples x = closure {x} :=\nby { ext, exact mem_closure_singleton.symm }\n\nlemma multiples_subset {x : A} {P : add_submonoid A} (h : x ∈ P) : multiples x ≤ P :=\nλ x hx, match x, hx with _, ⟨i, rfl⟩ := P.nsmul_mem h i end\n\nattribute [to_additive add_submonoid.multiples] submonoid.powers\nattribute [to_additive add_submonoid.mem_multiples] submonoid.mem_powers\nattribute [to_additive add_submonoid.mem_multiples_iff] submonoid.mem_powers_iff\nattribute [to_additive add_submonoid.multiples_eq_closure] submonoid.powers_eq_closure\nattribute [to_additive add_submonoid.multiples_subset] submonoid.powers_subset\n\nend add_submonoid\n\n/-! Lemmas about additive closures of `submonoid`. -/\nnamespace submonoid\n\nvariables {R : Type*} [non_assoc_semiring R] (S : submonoid R) {a b : R}\n\n/-- The product of an element of the additive closure of a multiplicative submonoid `M`\nand an element of `M` is contained in the additive closure of `M`. -/\nlemma mul_right_mem_add_closure\n  (ha : a ∈ add_submonoid.closure (S : set R)) (hb : b ∈ S) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nbegin\n  revert b,\n  refine add_submonoid.closure_induction ha _ _ _; clear ha a,\n  { exact λ r hr b hb, add_submonoid.mem_closure.mpr (λ y hy, hy (S.mul_mem hr hb)) },\n  { exact λ b hb, by simp only [zero_mul, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw add_mul,\n    exact λ 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 ∈ add_submonoid.closure (S : set R)) (hb : b ∈ add_submonoid.closure (S : set R)) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nbegin\n  revert a,\n  refine add_submonoid.closure_induction hb _ _ _; clear hb b,\n  { exact λ r hr b hb, S.mul_right_mem_add_closure hb hr },\n  { exact λ b hb, by simp only [mul_zero, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw mul_add,\n    exact λ 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 ∈ S) (hb : b ∈ add_submonoid.closure (S : set R)) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nS.mul_mem_add_closure (add_submonoid.mem_closure.mpr (λ sT hT, hT ha)) hb\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 ⟨y, ⟨n, hy1⟩, hy2⟩,\n    use n,\n    simpa [← of_mul_pow, hy1] },\n  { rintros ⟨n, hn⟩,\n    refine ⟨x ^ n, ⟨n, rfl⟩, _⟩,\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": "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/submonoid/membership.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8840392848011834, "lm_q1q2_score": 0.797333302834778}}
{"text": "-- Suma_de_funciones_acotadas_superiormente.lean\n-- La suma de dos funciones acotadas superiormente también lo está.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 28-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que la suma de dos funciones acotadas superiormente también\n-- lo está.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {f g : ℝ → ℝ}\nvariables {a b : ℝ}\n\n-- (cota_superior f a) se verifica si a es una cota superior de f.\ndef cota_superior (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, f x ≤ a\n\n-- (acotada_sup f) afirma que f tiene cota superior.\ndef acotada_sup (f : ℝ → ℝ) := ∃ a, cota_superior f a\n\n-- Lema auxiliar\n-- =============\n\nlemma cota_superior_suma\n  (hfa : cota_superior f a)\n  (hgb : cota_superior g b)\n  : cota_superior (f + g) (a + b) :=\nλ x, add_le_add (hfa x) (hgb x)\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (hf : acotada_sup f)\n  (hg : acotada_sup g)\n  : acotada_sup (f + g) :=\nbegin\n  cases hf with a hfa,\n  cases hg with b hgb,\n  have h3 : cota_superior (f + g) (a + b) :=\n    cota_superior_suma hfa hgb,\n  have h4 : ∃ z, ∀ x, (f + g) x ≤ z,\n    by exact Exists.intro (a + b) h3,\n  show acotada_sup (f + g),\n    by exact h4,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (hf : acotada_sup f)\n  (hg : acotada_sup g)\n  : acotada_sup (f + g) :=\nbegin\n  cases hf with a hfa,\n  cases hg with b hfb,\n  use a + b,\n  apply cota_superior_suma hfa hfb,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (hf : acotada_sup f)\n  (hg : acotada_sup g)\n  : acotada_sup (f + g) :=\nbegin\n  rcases hf with ⟨a, hfa⟩,\n  rcases hg with ⟨b, hfb⟩,\n  exact ⟨a + b, cota_superior_suma hfa hfb⟩\nend\n\n-- 4ª demostración\n-- ===============\n\nexample :\n  acotada_sup f → acotada_sup g → acotada_sup (f + g) :=\nbegin\n  rintros ⟨a, hfa⟩ ⟨b, hfb⟩,\n  exact ⟨a + b, cota_superior_suma hfa hfb⟩,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample :\n  acotada_sup f → acotada_sup g → acotada_sup (f + g) :=\nλ ⟨a, hfa⟩ ⟨b, hfb⟩, ⟨a + b, cota_superior_suma hfa hfb⟩\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_funciones_acotadas_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8774767954920547, "lm_q1q2_score": 0.7972911140133231}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández Palacios\n-/\n\nimport data.complex.basic\nimport data.real.cardinality\n\n/-!\n# The cardinality of the complex numbers\n\nThis file shows that the complex numbers have cardinality continuum, i.e. `#ℂ = 𝔠`.\n-/\n\nopen cardinal set\n\nopen_locale cardinal\n\n/-- The cardinality of the complex numbers, as a type. -/\n@[simp] theorem mk_complex : #ℂ = 𝔠 :=\nby rw [mk_congr complex.equiv_real_prod, mk_prod, lift_id, mk_real, continuum_mul_self]\n\n/-- The cardinality of the complex numbers, as a set. -/\n@[simp] lemma mk_univ_complex : #(set.univ : set ℂ) = 𝔠 :=\nby rw [mk_univ, mk_complex]\n\n/-- The complex numbers are not countable. -/\nlemma not_countable_complex : ¬ (set.univ : set ℂ).countable :=\nby { rw [← le_aleph_0_iff_set_countable, not_le, mk_univ_complex], apply cantor }\n", "meta": {"author": "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/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7972443237679243}}
{"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\n\n/-!\n\n# Challenge sheet\n\nThis is a harder group theory question. \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, by\nproving the other axioms?\n\n-/\n\n-- removing `mul_one` and `mul_inv_self` from the five standard axioms\n-- for a group. \nclass weak_group (G : Type) extends has_one G, has_mul G, has_inv G : Type :=\n(mul_assoc : ∀ a b c : G, (a * b) * c = a * (b * c))\n(one_mul : ∀ a : G, 1 * a = a)\n(inv_mul_self : ∀ a : G, a⁻¹ * a = 1)\n\nnamespace weak_group\n\nvariables {G : Type} [weak_group G] (a b c : G)\n\n\n/-\n\nThe challenge is to prove that G is a group, which we can interpret as\nproving the missing axioms `mul_one` and `mul_inv_self`. Note that you\ncan't use the `group` tactic any more because `G` isn't a group yet:\nthis is what you're trying to prove!\n\nOne way of doing it: try proving \n\n`mul_left_cancel : a * b = a * c → b = c`\n\nand then\n\n`mul_eq_of_eq_inv_mul : b = a⁻¹ * c → a * b = c`\n\nfirst.\n\n-/\n\n-- proof using cool `calc` mode\nlemma mul_left_cancel (h : a * b = a * c) : b = c :=\ncalc\n  b = 1 * b         : by rw one_mul\n... = (a⁻¹ * a) * b : by rw inv_mul_self\n... = a⁻¹ * (a * b) : by rw mul_assoc\n... = a⁻¹ * (a * c) : by rw h\n... = (a⁻¹ * a) * c : by rw mul_assoc\n... = 1 * c         : by rw inv_mul_self\n... = c             : by rw one_mul\n\nlemma mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  rwa [← mul_assoc, inv_mul_self, one_mul],\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⁻¹ = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\nend weak_group\n\n/-\n\nIf you want to take this further: prove that if we make\na new class `bad_group` by replacing\n`one_mul` by `mul_one` in the definition of `weak_group`\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\n-- claim: not a group in general\nclass bad_group (G : Type)\n  extends has_one G, has_mul G, has_inv G : Type :=\n(mul_assoc : ∀ a b c : G, (a * b) * c = a * (b * c))\n(mul_one : ∀ a : G, a * 1 = a)\n(inv_mul_self : ∀ a : G, a⁻¹ * a = 1)\n\ninstance : has_one bool := ⟨bool.tt⟩\ninstance : has_mul bool := ⟨λ x y, x⟩\ninstance : has_inv bool := ⟨λ x, 1⟩\n\ninstance : bad_group bool :=\n{ mul_assoc := dec_trivial,\n  mul_one := dec_trivial,\n  inv_mul_self := dec_trivial,\n}\n\nexample : ¬ (∀ a : bool, 1 * a = a) :=\nbegin\n  dec_trivial,\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/section04groups/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7972206172738259}}
{"text": "import .list .num\n\nnamespace int\n\nopen list\n\ndef dot_prod : list int → list int → int \n| [] [] := 0 \n| [] (_::_) := 0 \n| (_::_) [] := 0 \n| (a1::as1) (a2::as2) :=\n  (a1 * a2) + dot_prod as1 as2\n\ndef map_neg_dot_prod : \n  ∀ {as1 as2 : list int}, dot_prod (map_neg as1) as2 = -(dot_prod as1 as2) \n| [] [] := begin simp [map_neg, dot_prod] end \n| [] (_::_) := begin simp [map_neg, dot_prod] end \n| (_::_) [] := begin simp [map_neg, dot_prod] end \n| (a1::as1) (a2::as2) :=\n  begin\n    simp [map_neg, dot_prod],\n    rw (@map_neg_dot_prod as1 as2).symm, \n    simp [map_neg],\n  end\n\nlemma nil_dot_prod  :\n  ∀ {as}, dot_prod [] as = 0  \n| [] := rfl\n| (a::as) := rfl\n\nlemma dot_prod_nil  :\n  ∀ {as}, dot_prod as [] = 0  \n| [] := rfl\n| (a::as) := rfl\n\nlemma cons_dot_prod_cons_eq {a1 a2 as1 as2} : \ndot_prod (a1::as1) (a2::as2) = (a1 * a2) + dot_prod as1 as2 := rfl\n\nlemma comp_add_dot_prod  :\n  ∀ (as1 as2 as3 : list int),\n    dot_prod (comp_add as1 as2) as3 = (dot_prod as1 as3) + (dot_prod as2 as3)\n| [] as2 as3 := \n  begin simp [dot_prod, nil_comp_add, nil_dot_prod] end\n| as1 [] as3 := \n  begin simp [dot_prod, comp_add_nil, nil_dot_prod] end\n| as1 as2 [] := \n  begin repeat {rewrite dot_prod_nil}, simp end\n| (a1::as1) (a2::as2) (a3::as3) := \n  begin simp [dot_prod, comp_add, comp_add_dot_prod, add_mul] end\n\nlemma comp_sub_dot_prod :\n  ∀ (as1 as2 as3 : list int),\n    dot_prod (comp_sub as1 as2) as3 = (dot_prod as1 as3) - (dot_prod as2 as3) \n| [] as2 as3 := \n  begin simp [dot_prod, nil_comp_sub, map_neg_dot_prod, nil_dot_prod] end\n| as1 [] as3 := \n  begin simp [dot_prod, comp_sub_nil, nil_dot_prod] end\n| as1 as2 [] := \n  begin repeat {rewrite dot_prod_nil}, simp end\n| (a1::as1) (a2::as2) (a3::as3) := \n  begin simp [dot_prod, comp_sub, comp_sub_dot_prod, add_mul] end\n\nlemma map_mul_dot_prod {a : int} :\n  ∀ {as1 as2}, dot_prod (map_mul a as1) as2 = a * (dot_prod as1 as2) \n| [] as2 := \n  begin simp [map_mul, nil_dot_prod] end\n| as1 [] := \n  begin\n    repeat {rewrite dot_prod_nil},\n    rewrite _root_.mul_zero a,\n  end\n| (a1::as1) (a2::as2) := \n  begin\n    unfold map_mul, simp, repeat {rewrite cons_dot_prod_cons_eq}, \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\nend int\n\n\nnamespace znum\n\nopen list\n\ndef dot_prod : list znum → list znum → znum \n| [] [] := 0 \n| [] (_::_) := 0 \n| (_::_) [] := 0 \n| (a1::as1) (a2::as2) :=\n  (a1 * a2) + dot_prod as1 as2\n\ndef map_neg_dot_prod : \n  ∀ {as1 as2 : list znum}, dot_prod (map_neg as1) as2 = -(dot_prod as1 as2) \n| [] [] := begin simp [map_neg, dot_prod] end \n| [] (_::_) := begin simp [map_neg, dot_prod] end \n| (_::_) [] := begin simp [map_neg, dot_prod] end \n| (a1::as1) (a2::as2) :=\n  begin\n    simp [map_neg, dot_prod],\n    rw (@map_neg_dot_prod as1 as2).symm, \n    simp [map_neg],\n  end\n\n@[simp] lemma nil_dot_prod  :\n  ∀ {as}, dot_prod [] as = 0  \n| [] := rfl\n| (a::as) := rfl\n\n@[simp] lemma dot_prod_nil  :\n  ∀ {as}, dot_prod as [] = 0  \n| [] := rfl\n| (a::as) := rfl\n\nlemma cons_dot_prod_cons_eq {a1 a2 as1 as2} : \ndot_prod (a1::as1) (a2::as2) = (a1 * a2) + dot_prod as1 as2 := rfl\n\nlemma comp_add_dot_prod  :\n  ∀ (as1 as2 as3 : list znum),\n    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 simp [dot_prod, comp_add, comp_add_dot_prod, add_mul] end\n\nlemma comp_sub_dot_prod :\n  ∀ (as1 as2 as3 : list znum),\n    dot_prod (comp_sub as1 as2) as3 = (dot_prod as1 as3) - (dot_prod as2 as3) \n| [] as2 as3 := \n  begin simp [dot_prod, nil_comp_sub, map_neg_dot_prod, nil_dot_prod] end\n| as1 [] as3 := \n  begin simp [dot_prod, comp_sub_nil, nil_dot_prod] end\n| as1 as2 [] := \n  begin repeat {rewrite dot_prod_nil}, simp end\n| (a1::as1) (a2::as2) (a3::as3) := \n  begin simp [dot_prod, comp_sub, comp_sub_dot_prod, add_mul] end\nlemma map_mul_dot_prod {a : znum} :\n  ∀ {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_eq}, \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\nlemma dot_prod_to_int' : \n∀ {zs1 zs2 : list znum}, \n  (dot_prod zs1 zs2).to_int = int.dot_prod (map to_int zs1) (map to_int zs2)\n| [] [] := rfl\n| [] (a2::as2) := begin simp [nil_dot_prod, map], refl end\n| (a1::as1) [] := begin simp [dot_prod_nil, map], refl end\n| (a1::as1) (a2::as2) := \n  begin \n    simp [int.cons_dot_prod_cons_eq, znum.cons_dot_prod_cons_eq, \n      dot_prod_to_int', to_int, int.to_znum], \n    have h := @dot_prod_to_int' as1 as2, simp [to_int] at h, rw h,\n  end\n\nlemma dot_prod_to_int : \n∀ {zs1 zs2 : list znum}, \n  ↑(dot_prod zs1 zs2) = int.dot_prod (map to_int zs1) (map to_int zs2) :=\n  @dot_prod_to_int'\n\nlemma dot_prod_eq_of_forall_mem_zero : \n  ∀ {zs1 zs2}, (∀ z ∈ zs1, z = (0 : znum)) → dot_prod zs1 zs2 = 0 \n| [] zs2 _ := nil_dot_prod \n| (z1::zs1) zs2 h :=\n  begin\n    cases zs2, apply dot_prod_nil,\n    simp [dot_prod], have hrw := (h z1 (or.inl rfl)),\n    subst hrw, simp, apply dot_prod_eq_of_forall_mem_zero,\n    apply forall_mem_of_forall_mem_cons h\n  end\n  \n   \n\nend znum\n\nnamespace num \n\nopen list\n\ndef dot_prod : list num → list num → num \n| [] [] := 0 \n| [] (_::_) := 0 \n| (_::_) [] := 0 \n| (a1::as1) (a2::as2) :=\n  (a1 * a2) + dot_prod as1 as2\n\n@[simp] lemma nil_dot_prod  :\n  ∀ {as}, dot_prod [] as = 0  \n| [] := rfl\n| (a::as) := rfl\n\n@[simp] lemma dot_prod_nil  :\n  ∀ {as}, dot_prod as [] = 0  \n| [] := rfl\n| (a::as) := rfl\n\nlemma comp_add_dot_prod  :\n  ∀ (as1 as2 as3 : list num),\n    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    simp [dot_prod, comp_add, comp_add_dot_prod as1 as2 as3, add_mul] \n  end\n\nlemma cons_dot_prod_cons_eq {a1 a2 as1 as2} : \ndot_prod (a1::as1) (a2::as2) = (a1 * a2) + dot_prod as1 as2 := rfl\n\nlemma dot_prod_to_znum' : \n∀ {ns1 ns2 : list num}, \n  (dot_prod ns1 ns2).to_znum = znum.dot_prod (map to_znum ns1) (map to_znum ns2)\n| [] [] := rfl\n| [] (a2::as2) := begin simp [nil_dot_prod, map], refl end\n| (a1::as1) [] := begin simp [dot_prod_nil, map], refl end\n| (a1::as1) (a2::as2) := \n  begin \n    simp [num.cons_dot_prod_cons_eq, znum.cons_dot_prod_cons_eq, \n       dot_prod_to_znum', num.mul_to_znum'],\n  end\n\nlemma map_mul_dot_prod {a : num} :\n  ∀ {as1 as2}, dot_prod (map_mul a as1) as2 = a * (dot_prod as1 as2) \n| [] as2 := begin simp [map_mul] end\n| as1 [] :=  begin simp [map_mul] end\n| (a1::as1) (a2::as2) := \n  begin\n    unfold map_mul, simp, repeat {rewrite cons_dot_prod_cons_eq}, \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\nend num", "meta": {"author": "skbaek", "repo": "cooper", "sha": "812afc6b158821f2e7dac9c91d3b6123c7a19faf", "save_path": "github-repos/lean/skbaek-cooper", "path": "github-repos/lean/skbaek-cooper/cooper-812afc6b158821f2e7dac9c91d3b6123c7a19faf/dot_prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7972206054866399}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n--    1. Importar la teoría de anillos.\n--    2. Crear el espacio de nombres my_ring\n--    3. Declarar R como una variable sobre anillos.\n--    4. Declarar a como variable sobre R.\n-- ----------------------------------------------------------------------\n\nimport algebra.ring            -- 1\nnamespace my_ring              -- 2\nvariables {R : Type*} [ring R] -- 3\nvariables (a : R)              -- 4\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--     a - a = 0\n-- ----------------------------------------------------------------------\n\n\ntheorem self_sub : a - a = 0 :=\ncalc\n  a - a = a + -a : sub_eq_add_neg a a\n  ...   = 0      : by rw add_right_neg\n\nend my_ring\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/self_sub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7972206003093077}}
{"text": "import data.nat.prime\n\n/-\nWe prove that sqrt 2 is irrational. To make things simple, we work with natural numbers instead\nof rational numbers. The idea is to derive a contradiction from the assumption that\n`(a^2 = 2 * (b ^ 2))` for coprime natural nubmers `a` and `b`.\n-/\n\n-- First an auxiliary result to show `2 ∣ x` if `x * x = 2 * y`.\nlemma aux {x y : ℕ} (h : x * x = 2 * y) : 2 ∣ x :=\n(or_self (2 ∣ x)).mp $ (nat.prime.dvd_mul nat.prime_two).mp ⟨y, h⟩\n\n-- Proof of the irrationality of sqrt 2.\nexample (a b : ℕ) (cop : nat.coprime a b) : ¬(a^2 = 2*b^2) :=\nbegin\n  simp only [pow_two],\n  intro h,\n  have twodiva : 2 ∣ a := aux h,\n  have twodiva' := twodiva, -- make a copy!\n  cases twodiva' with m hm,\n  rw [hm, mul_assoc] at h,\n  have hdiv : m * (2* m) = b * b, from mul_left_cancel' two_ne_zero h,\n  rw [mul_comm, mul_assoc] at hdiv,\n  have twodivb : 2 ∣ b := aux hdiv.symm,\n  exact nat.not_coprime_of_dvd_of_dvd one_lt_two twodiva twodivb cop,\nend\n", "meta": {"author": "gihanmarasingha", "repo": "exleanblog", "sha": "aa6dc06cb64376dc87ba680815b9d14a904ad2ff", "save_path": "github-repos/lean/gihanmarasingha-exleanblog", "path": "github-repos/lean/gihanmarasingha-exleanblog/exleanblog-aa6dc06cb64376dc87ba680815b9d14a904ad2ff/src/2021/06/sqrt2_irrational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542829224748, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7971944160804164}}
{"text": "import data.set\nimport tactic.ring\n\nnamespace relation\n\n-- Jakob Kauffmann (jgk2qq); github: jakekauff13\n-- Collaborated with: Jumi Hall (jah5py) & \n--                    Connor McCaffrey (cam7qp)\n\n-- PRELIMINARY SETUP\n\n/-\nPreliminary set up. For the rest of this file,\nwe specify an arbitrary binary relation, r, on\nan arbitrary type, β, as a two-place predicate, \nwith infix notation x ≺ y for (r x y). One can\npronounce these expressions in English as \"x is\nrelated to y\".\n-/\nvariables {α β : Type}  (r : β → β → Prop)\nlocal infix `≺` : 50 := r  \n\n\n/-\nThe default Lean libraries are missing definitions\nfor the assympetric property of relations and for\nthe notion of a powerset. We define these terms for\nuse in the rest of this file.\n-/\ndef asymmetric := ∀ ⦃x y⦄, x ≺ y → ¬ y ≺ x\ndef powerset (s : set β) := { s' | s' ⊆ s}\n\n\n-- PROBLEMS\n\n/- \n#1: Give both a formal and an English-language proof. Then\nanswer the question, is the proposition true if you remove\nthe first condition, that β is inhabited? Briefly explain\nyour answer (in English).\n-/\nexample : (∃ (b : β), true) → asymmetric r → ¬reflexive r :=\nbegin\n  assume e,\n  assume a,\n  assume x,\n  unfold asymmetric at a,\n  unfold reflexive at x,\n  cases e with w pf,\n  have rww := x w,\n  have c := a rww,\n  contradiction,\nend\n  -- English-Language Proof:\n      /-\n      Proof: Suppose β is inhabited and r is asymmetric.\n      We now show r is not reflexive. We will prove by \n      negation, assuming that r is reflexive and then \n      we will show that this assumption leads to a contradiction\n      from which we can conclude r is not reflexive.\n\n      To derive the contradiction, we first expand the \n      definitions of asymmetric and reflexive. We will\n      now show that the following assumptions contradict\n      one another:\n\n        β: Type\n        r: β → β → Prop\n        e: ∃ (b : β), true\n        a: ∀ ⦃x y : β⦄, r x y → ¬r y x\n        x: ∀ (x : β), r x x\n\n      To show this by exists elimination we first infer\n      that there is a an object, w : β, of which we \n      have a proof of existence. Applying reflexivity (x), \n      to w, we deduce w ≺ w (r w w). Next, by applying \n      asymmetry (a), to w ≺ w we derive w ⊀ w, thus deriving\n      the aforementioned contradiction.\n      QED. \n      -/\n\n\n/-\n#2. Logic, like programming, is subtle. It's very easy for humans\nto miss subtle corner cases. As an example, today I ran across\na problem in a textbook by Paul Traiger, a professor emeritus\nof philosophy and cognitive science at Occidental College. He\nasks students to prove that if a relation is both transitive and \nreflexive that it cannot be anti-symmetric. See the question at\nthe very bottom of the page here:\nhttps://sites.oxy.edu/traiger/logic/exercises/chapter13/properties_of_relations_exercise.html\n\nIs the conjecture actually logically valid? If not, what condition \nneeds to be added to make it so? Try prove this/his version of the\nconjecture, as articulated slightly differently below. If you get\nstuck, then you need to figure out an additional condition that needs \nto be added as a premise to make the proposition true. In that case,\nadd the premise and then show that the updated conjecture is true.\n-/\nexample : (∃ (b : β), true) → transitive r → reflexive r → ¬ asymmetric r :=\nbegin\n  assume h,\n  unfold transitive reflexive asymmetric,\n  assume t r a,\n  cases h with b True,\n  have b_refl := r b,\n  have b_not_refl := a b_refl,\n  contradiction,\nend\n\n\n/-\n#3: Prove that the subset relation on the powerset of any\nset, s, is antisymmetric. Formally state and prove, and\nthen give an informal proof of, this proposition.\n-/\nexample : ∀ (s : set β) \n            (s1 s2 ∈ powerset s), \n            s1 ⊆ s2 → \n            s2 ⊆ s1 → \n            s1 = s2 :=\nbegin\n  assume s s1 s2 s1ins s2ins s1ins2 s2ins1,\n  apply set.ext,\n  assume x,\n  split,\n  assume xins1,\n  exact s1ins2 xins1,\n\n  assume xins2,\n  exact s2ins1 xins2,\nend\n\n/-\nProof: Suppose that s is a set of type β and that s1 and s2 \nare in the powerset of s. We will prove that s1 = s2, assuming\nthe following: s1 ⊆ s2 and s2 ⊆ s1. \n\nFirst, we equate the equals sign to an if and only if statement \nunder set extensionality. By application of our assumptions \non one another, we derive that s1 = s2. \n\nQED.\n-/\n\n/-\nGiven two natural numbers, n and m, we will say that m divides n\nif there is a natural number, k, such that n = k*m. Here's a formal\ndefinition of this relation.\n-/\ndef divides (m n : ℕ) := ∃ k, n = k * m\n\n\n/- \n#4: Formally and informally state and prove each of the following\npropositions. Remember that the ring tactic is useful for producing\nproofs of simple algebraic equalities involving + and *. You can use\nthe phrase, \"by basic algebra\" when translating the use of this tactic\ninto English. (Or if you wanted to be truly Hobbit-like you could say \n\"by the ring axioms!\")\n-/\n\n-- A: For any n, 1 divides n.\nexample : ∀ n, divides 1 n :=\nbegin\n  assume n,\n  unfold divides,\n  cases n with p,\n  apply exists.intro 0,\n  refl,\n  apply exists.intro p.succ,\n  have mulone := mul_one p.succ,\n  rw mulone,\nend\n\n/-\nProof: We provide a proof that for any n, 1 divides n. In order \nto provide this proof, we first assume n of type ℕ. Next, we \nexpand the definition of divides. We will then perform case analysis on\nn to prove that there exists a k such that n = k * 1.\n\nCase analysis yields two cases which we will prove, thus proving that\n1 divides n. The first case is that in which n = 0. After application of\nthe exists introduction rule with the value 0, we now prove by simple algebra\nthat 0 = 0 * 1. The second case is that is which n > 0. Similarly, we show that\nthere exists a k such that n = k * 1, and that k is again equal to n. \n\nQED.\n-/\n\n-- B. For any n, n divides n\nexample : ∀ n, divides n n :=\nbegin\n  assume n,\n  unfold divides,\n  apply exists.intro 1,\n  have mulone := one_mul n,\n  rw mulone,\nend\n/-\nProof: We provide a proof that for any n, n divides n. We first assume\nn is of type ℕ, then we expand the definition of divides. After applying\nthe exists introduction rule with a value of 1, we must prove that \nn = 1 * n, which is done by simple algebra.\n\nQED.\n-/\n\n\n-- #C. prove that divides is reflexive \nexample : reflexive divides :=\nbegin\n  unfold reflexive divides,\n  assume n,\n  apply exists.intro 1,\n  have mulone := (one_mul n),\n  rw mulone,\nend \n/-\nProof: We will provide a proof that divides is reflexive. We first assume\nn is of type ℕ, and then we expand the definition of divides and reflexive. After applying\nthe exists introduction rule with a value of 1, we must prove that \nn = 1 * n, which is done by simple algebra.\n-/\n\n-- #D. prove that divides is transitive\nexample : transitive divides :=\nbegin\n  unfold transitive divides,\n  assume a b c,\n  assume ab bc,\n  cases ab with a1 p1,\n  cases bc with a2 p2,\n  apply exists.intro(a2*a1),\n  rw p2,\n  rw p1,\n  have mulassoc := mul_assoc a2 a1 a,\n  rw mulassoc,\nend \n\n/-\nProof: We will provide a proof that divides is transitive. We first expand \nthe definition of transitive and divides. We will then make the following \nassumptions:\n\n  a b c : ℕ \n  ab : ∃ (k : ℕ), b = k * a\n  bc : ∃ (k : ℕ), c = k * b\n\nUnder these assumptions, we will prove that there exists a k such that \nc = k * a, showing that divides is transitive. We begin by performing case \nanalysis on both ab and bc, yielding the following assumptions:\n\n  a b c a1 a2 : ℕ \n  p1 : b = a1 * a\n  p2 : c = a2 * b\n\nWe will use these assumptions to rewrite the final proposition c = k * a \nto now be a2 * a1 * a = a2 * a1 * a. We do this by applying the exists\nintroduction rule for the value a2 * a1, converting the proposition into\nc = a2 * a1 * a. Next, we have the proofs that c = a2 * b and b = a1 * a.\nUsing these, we can rewrite the final proposition as a2 * a1 * a = a2 * a1 * a,\nwhich is true by reflexivity of equality.\n\nQED.\n-/\n\n/- \nE. Is divides symmetric? if yes, give a proof, otherwise \ngive a counterexample and a brief explanation to show that \nit's not.\n-/\n\nexample: symmetric divides :=\nbegin\nend\n-- Divides is NOT symmetric, as shown by the cases where 2 divides 4\n-- (k = 2, which is a natural number), but 4 does not divide 2 \n-- (k = 1/2, which is not a natural number).\n-- In order for a relation to be symmetric, the relation\n-- must hold between the two values in both directions. However, with divides,\n-- a natural number does not exist such that a number divides a larger number,\n-- and that larger number divides the smaller number.\n\n/- \n#F. Prove that divides is antisymmetric. \n-/\nexample : anti_symmetric divides := \nbegin  \n  unfold anti_symmetric divides,\n  assume x y xy yx,\n  apply exists.elim xy,\n  apply exists.elim yx,\n  assume a b c d, \n  rw b,\n  have : a = 1 := sorry,\n  rw this,\n  have mulone := one_mul y,\n  exact mulone,\nend\n\n/-\nProof: We will prove that divides is antisymmetric. First, we expand the\ndefinitions of antisymmetric and divides. Then we perform case analysis on our \nassumed exists statements, leaving us to rewrite the cases. It is obvious that the\nvalue of a must be 1 by simple deduction from already present proofs, leaving us\nagain to simply rewrite our goal, giving us a new goal that 1 * y = y, which is\ntrue by simple algebra.\n\nQED.\n-/\n\n/- #5\nProve the following propositions. Remember that\nthroughout this file, each definition implicitly\nincludes β as a type and r as an arbitrary binary \nrelation on β. In addition to formal proofs, give\nan English language proof of the last of the three\nproblems.\n-/\n\n-- A\nexample : asymmetric r → irreflexive r :=\nbegin\n  assume h x k,\n  have nk := h k,\n  contradiction,\nend\n/-\nProof: We will provide a proof that a relation is irreflexive, given\nthat the relation is asymmetric, by negation. We do this by assuming that\nr x x is true and showing that ¬ r x x is true by applying the proof that \nthe relation is asymmetric to r x x, thus deriving a contradiction.\n\nQED.\n-/\n-- B\nexample : irreflexive r → transitive r → asymmetric r :=\nbegin\n  unfold irreflexive transitive,\n  assume i t x y,\n  assume rxy,\n  assume nryx,\n  have f := t rxy nryx,\n  have nrxx := i x,\n  contradiction,\nend\n\n/-\nProof: We will provide a proof by negation that a relation is asymmetric, \ngiven that the relation is irreflexive and transitive. We first expand the \ndefinitions of irreflexive and transitive. Then we make the assumptions that \nthe relation r is irreflexive and transitive. Next, we assume r x y and ¬ r y x. \nAfter this, we apply transitive to r x y and ¬ r y x to derive a proof of r x x. \nFinally, we show a contradiction by applying irreflexive to x, which gives us ¬ r x x. \n\nQED.\n-/\n\n-- C\nexample : transitive r → ¬ symmetric r → ¬ irreflexive r :=\nbegin\n  unfold transitive symmetric irreflexive,\n  assume trans symm irrefl,\nend\n\n/-\nWe do not believe that the proposition is provable or fixable. We tried to \nadd that β is inhabited, but this effort was futile. We were unable\nto find a counter-example of a relation that shows the invalidity\nof the proposition. \n-/\nend relation\n", "meta": {"author": "jakekauff", "repo": "DiscreteMath", "sha": "1ce98ac3fdb7b7fa880e595ac29f66a5098cfdba", "save_path": "github-repos/lean/jakekauff-DiscreteMath", "path": "github-repos/lean/jakekauff-DiscreteMath/DiscreteMath-1ce98ac3fdb7b7fa880e595ac29f66a5098cfdba/hw7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8615382076534743, "lm_q1q2_score": 0.7971209642290996}}
{"text": "import tactic\nimport init.logic -- 引用关于逻辑的基本定理\n\n-- Let `Ω` be a \"big underlying set\" and let `X` and `Y` and `Z` be subsets\n\nvariables (Ω : Type) (X Y Z : set Ω) (a b c x y z : Ω)\n\nnamespace xena\n\n/-!\n\n# subsets\n\nLet's think about `X ⊆ Y`. Typeset `⊆` with `\\sub` or `\\ss`\n-/\n\n-- `X ⊆ Y` is the same as `∀ a, a ∈ X → a ∈ Y` , by definition.\n\nlemma subset_def : X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y :=\nbegin\n  -- true by definition\n  refl\nend\n\n\nlemma subset_refl : X ⊆ X :=\nbegin\n  -- 想要证明一个新概念的性质，先从其定义入手\n  rw subset_def,\n  -- 遇到包含 ∀ 的命题，可以尝试intro策略\n  intro a,\n  intro a_in_X,\n  exact a_in_X,\nend\n--  ⊆ 的自反性(reflexivity)在mathlib中已经证明过了，所以你也可以使用一个relf策略完成证明\n\n-- \nlemma subset_trans (hXY : X ⊆ Y) (hYZ : Y ⊆ Z) : X ⊆ Z :=\nbegin\n  -- If you start with `rw subset_def at *` then you\n  -- will have things like `hYZ : ∀ (a : Ω), a ∈ Y → a ∈ Z`\n\n  -- You need to think of `hYZ` as a function, which has two\n  -- inputs: first a term `a` of type `Ω`, and second a proof `haY` that `a ∈ Y`.\n  -- It then produces one output `haZ`, a proof that `a ∈ Z`.\n\n  -- You can also think of it as an implication:\n  -- \"if a is in Ω, and if a ∈ Y, then a ∈ Z\". Because it's an implication,\n  -- you can `apply hYZ`. This is a really useful skill!\n  \n  rw subset_def at *, -- 把已知条件和目标中所有 ⊆ 用定义替换\n  intro a,\n  intro a_in_X,\n\n  apply hYZ,  -- 已知条件中有 a : Ω , 满足hYZ的前提: \"a : Ω \"\n  apply hXY,  -- 同上\n  exact a_in_X,\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 ↔ (∀ a, a ∈ X ↔ a ∈ Y) :=\nbegin\n  exact set.ext_iff\nend\n\n-- In practice, you often have a goal `⊢ X = Y` and you want to reduce\n-- it to `a ∈ X ↔ a ∈ Y` for an arbitary `a : Ω`. This can be done with\n-- the `ext` tactic. \n\n--    此证明的名称      (已知条件1)     (已知条件2)    :  目标  :=\nlemma subset.antisymm (hXY : X ⊆ Y) (hYX : Y ⊆ X) : X = Y :=\nbegin\n  -- start with `ext a`,\n  ext? a,\n  -- 在 ext 后加问号可以看到此处的 ext 等效于哪些证明策略\n\n  split,\n  { -- ⊢ x ∈ X → x ∈ Y\n    intro a_in_X,\n    apply hXY,      -- 无需手动按定义展开也可以直接 apply\n    exact a_in_X,\n    },\n  { -- ⊢ x ∈ Y → x ∈ X\n    intro a_in_Y,\n    apply hYX,\n    exact a_in_Y,\n    }\n  -- 如果你对如下事实感到困惑：\n  --  对目标 a ∈ X 使用 apply hYX (Y ⊆ X) 会得到 a ∈ Y\n  -- 那么请注意此处 a ∈ X 是需要证明的目标，而非已知条件；apply在修改证明目标，而非推出结论。\n  -- 如果仍然无法理解，请在证明开头添加 rw subset_def at * \nend\n\n/-!\n\n### Unions and intersections\n\nType `\\cup` or `\\un` for `∪`, and `\\cap` or `\\i` for `∩`\n\n-/\n\nlemma union_def : a ∈ X ∪ Y ↔ a ∈ X ∨ a ∈ Y :=\nbegin\n  -- true by definition\n  refl,\nend\n\nlemma inter_def : a ∈ X ∩ Y ↔ a ∈ X ∧ a ∈ 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 ∪ X = X :=\nbegin\n  ext a,\n  rw union_def,\n  split,\n  { -- ⊢ a ∈ X ∨ a ∈ X → a ∈ X\n    intro h,\n    cases h with h1 h2,\n    exact h1,\n    exact h2,\n  },\n  { -- ⊢ a ∈ X → a ∈ X ∨ a ∈ X\n    intro h,\n    left,\n    exact h,\n  }\nend\n\nlemma subset_union_left : X ⊆ X ∪ Y :=\nbegin\n  rw subset_def,\n  intros a a_in_X,\n\n  -- rw union_def,  -- 形如 a ∈ X ∪ Y 的目标可以直接使用left right策略，如果不理解 请删去行首注释再查看\n  left,\n  exact a_in_X,\nend\n\nlemma subset_union_right : Y ⊆ X ∪ Y :=\nbegin\n  rw subset_def,\n  intros a a_in_Y,\n  \n  -- rw union_def,  -- 同上题\n  right,\n  exact a_in_Y,\nend\n\nlemma union_subset_iff : X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nbegin\n  split,\n  { -- ⊢ X ∪ Y ⊆ Z → X ⊆ Z ∧ Y ⊆ Z\n    intro hXunYssZ,\n    split,\n    -- ⊢ X ⊆ Z\n      -- rw subset_def,  \n      intros a a_in_X,    -- 对于 X ⊆ Z , 可以使用intros得出 a : Ω 和 a_in_X : a ∈ X , 定义如此\n      -- rw subset_def at hXunYssZ,   \n      apply hXunYssZ,     -- 若不理解请去掉rw前的注释以查看定义\n      left,\n      exact a_in_X,\n\n    -- ⊢ Y ⊆ Z\n      intros a a_in_Y,\n      apply hXunYssZ,\n      right,\n      exact a_in_Y,\n  },\n  {\n    intros h a a_in_XuY,\n    cases h with XssZ YssZ,\n    cases a_in_XuY with a_in_X a_in_Y,\n    -- z ∈ X\n      apply XssZ,\n      exact a_in_X,\n    -- a ∈ Y\n      apply YssZ,\n      exact a_in_Y,\n  }\nend\n\n/- \n  目标是关于集合的命题，该如何处理？\n    1，最基本的方法：使用rewrite(rw)将其改写成定义\n    2，形如 X ⊆ Z, 用intros或两次intro\n    3，形如 X = Y, 考虑 ext\n    4，形如 a ∈ X ∪ Y, 可使用left right\n\n  已知条件是关于集合的命题，如何使用?\n    1.使用定义重写: rw _ at _\n    2.形如 X ⊆ Z, 考虑apply\n    3.形如 X ∪ Y , X ∩ Y , 可以cases（本质上是对 ∧ ∨ cases）\n    4.形如 X = Y , 可以使用 rw\n  -/\n\nvariable (W : set Ω)\n\nlemma union_subset_union (hWX : W ⊆ X) (hYZ : Y ⊆ Z) : W ∪ Y ⊆ X ∪ Z :=\nbegin\n  intros a a_in_WuY,\n  cases a_in_WuY with a_in_W a_in_Y,\n  { -- known:\n    left,\n    apply hWX,\n    exact a_in_W,\n  },\n  {\n    right,\n    apply hYZ,\n    exact a_in_Y,\n  }\nend\n\nlemma union_subset_union_left (hXY : X ⊆ Y) : X ∪ Z ⊆ Y ∪ Z :=\nbegin\n  have ZssZ : Z ⊆ Z, {\n    refl\n  },\n  apply union_subset_union,\n  exact hXY,\n  exact ZssZ,\nend\n\n-- etc etc\n\n-- intersection lemmas\n\nlemma inter_subset_left : X ∩ Y ⊆ X :=\nbegin\n  intros a a_in_XiY,\n  cases a_in_XiY with a_in_X a_in_Y,\n  exact a_in_X,\nend\n\n-- don't forget `ext` to make progress with equalities of sets\n\nlemma inter_self : X ∩ X = X :=\nbegin\n  ext,\n  split,\n  { -- ⊢ x ∈ X ∩ X → x ∈ X\n    intro x_in_XiX,\n    cases x_in_XiX with x_in_X x_in_X,\n    exact x_in_X,\n  },\n  { -- ⊢ x ∈ X → x ∈ X ∩ X\n    intro x_in_X,\n    split,\n    exact x_in_X,\n    exact x_in_X,\n  },\nend\n\n\nlemma inter_comm : X ∩ Y = Y ∩ X :=\nbegin\n  ext,\n  split, \n  { -- ⊢ x ∈ X ∩ Y → x ∈ Y ∩ X\n    intro h,\n    cases h with x_in_X x_in_Y,\n    split,\n    exact x_in_Y,\n    exact x_in_X,\n  },\n  { -- ⊢ x ∈ Y ∩ X → x ∈ X ∩ Y\n    intro h,\n    cases h with x_in_Y x_in_X,\n    split,\n    exact x_in_X,\n    exact x_in_Y,\n  }\nend\n\n-- inter_def : a ∈ X ∩ Y ↔ a ∈ X ∧ a ∈ Y\nlemma inter_assoc : X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z :=\nbegin\n  ext,\n  split,\n  { -- ⊢ x ∈ X ∩ (Y ∩ Z) → x ∈ X ∩ Y ∩ Z\n    intro h,\n    -- rcases：等价于两条cases\n    -- cases h with x_in_X h,\n    -- cases h with x_in_Y x_in_Z,\n    rcases h with ⟨x_in_X, x_in_Y, x_in_Z⟩, \n    \n    split,\n    split,\n    exact x_in_X,\n    exact x_in_Y,\n    exact x_in_Z,\n  },\n  { -- ⊢ x ∈ X ∩ Y ∩ Z → x ∈ X ∩ (Y ∩ Z)\n    intro h,\n    -- 请尝试将这里改写为一条rcases\n    cases h with h x_in_Z,\n    cases h with x_in_X x_in_Y,\n\n    split,\n    exact x_in_X,\n    split,\n    exact x_in_Y,\n    exact x_in_Z,\n  }\nend\n\n/-!\n\n### Forall and exists\n\n-/\n-- 关于存在命题的证明和使用方法，请查阅手册\n-- https://leanprover-community.github.io/mathlib_docs/init/logic.html#Exists\n-- 请在手册中自行查找全称命题的说明\n\nlemma not_exists_iff_forall_not : ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X) :=\nbegin\n  split,\n  { -- ¬ ∃ → ∀ \n    intro h,\n    intro b,\n    intro b_in_X,\n    apply h,\n    use b,      -- 指出满足goal的元素b\n    -- existsi b, -- 与use等价\n    exact b_in_X,\n  },\n  { -- ∀ → ¬ ∃ \n    intro h,\n    intro hExist,\n    -- cases 从存在命题抽出 a 及其性质 a ∈ X\n    cases hExist with a ha,\n    apply (h a),  -- (h a) : a ∉ X\n    exact ha,\n  }\nend\n\nexample : ¬ (∀ a, a ∈ X) ↔ ∃ b, ¬ (b ∈ X) :=\nbegin\n  split,\n  { -- ¬ ∀ → ∃ \n    -- 此处的goal不是直觉主义逻辑中的定理，仅使用构造方式无法证明，需要用到反证法\n    intro h,\n    by_contra hE,\n    apply h,\n    intro a,\n    by_contra aNotInX,\n    apply hE,\n    use a,\n  },\n  { -- ∃ → ¬ ∀ \n    intro h,\n    intro hAll,\n    cases h with a ha,\n    apply ha,\n    apply hAll,\n  }\nend\n\nend xena\n\n", "meta": {"author": "LeyangGuo", "repo": "Formalizing_Mathmetics_zh", "sha": "e03a0f2b6fa3bef45d704bd5b53c66fa57ce3262", "save_path": "github-repos/lean/LeyangGuo-Formalizing_Mathmetics_zh", "path": "github-repos/lean/LeyangGuo-Formalizing_Mathmetics_zh/Formalizing_Mathmetics_zh-e03a0f2b6fa3bef45d704bd5b53c66fa57ce3262/Part_B_sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7971209554794815}}
{"text": "/- TACTICS -/\n\nnamespace TBA\n\n-- definitions from last week\n-- NOTE: We renamed it from `Nat'` for consistency. The new namespace makes sure we don't use the\n-- standard library `Nat`.\ninductive Nat : Type where\n  | zero : Nat\n  | succ (n : Nat) : Nat\n\nopen Nat\n\ndef add (m n : Nat) : Nat :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\n-- With this command we add a notation for `add`. From now on we will be able to write `m + n` for\n-- `add m n`. The 65 denotes how strongly the operator should bind to what's adjacent to it.\n-- The `priority` means that Lean will prefer it over the built-in `+`.\ninfix:65 (priority := high) \" + \" => add\n\ndef mul (m n : Nat) : Nat :=\n  match n with\n  | zero   => zero\n  | succ n => (mul m n) + m\n\n-- We also want a notation for `mul`, with a higher binding strength than addition so that\n-- `a + b * c` means `a + (b * c`)`.\ninfix:70 (priority := high) \" * \" => mul\n\ninductive LE : Nat → Nat → Prop where\n  | refl (n : Nat) : LE n n\n  | succ : LE m n → LE m (succ n)\n\n-- lower binding strength than either addition or multiplication\ninfix:50 (priority := high) \" ≤ \" => LE\n\n-- Let's start by reproving some theorems from last week, but this time with tactics!\n-- useful tactics:\n-- * `induction ... with ...`\n-- * `rw [f]` to unfold applications of a function `f`\n-- * `rw [h]` to rewrite every `a` to `b` if `h : a = b`\n-- * `apply/exact`\n-- * `simp/simp_all`... are powerful and basically always useful, though make sure that you could also\n--   do the proof without them\ntheorem zero_add : zero + n = n := by\n  induction n with\n  | zero      =>\n    rfl\n  | succ n ih =>\n    rw [add, ih]\n  -- or simply\n  --induction n <;> simp_all [add]\n  \n\ntheorem le_add : m ≤ m + n := by\n  induction n with\n  | zero =>\n    apply LE.refl\n    -- same as\n    --exact LE.refl _\n  | succ n ih =>\n    rw [add]  -- optional, but helpful\n    apply LE.succ\n    apply ih\n    -- same as\n    --exact LE.succ ih\n    -- alternatively, simply use\n    --simp [add, LE.succ, ih]\n    -- ...but using a conditional simp theorem like `LE.succ` is usually not obvious\n    -- when first writing a proof\n  -- or simply\n  --induction n <;> simp_all [LE.refl, LE.succ, add]\n  \n\n-- Alright, let's start automating more!\nattribute [simp] add mul\n-- These definitions will now automatically be unfolded when you use `simp/simp_all`\n\n\ntheorem succ_add : (succ n) + m = succ (n + m) := by\n  induction m <;> simp_all [zero_add]\n\n-- This one is a bit more tricky, you might need to prove a helper lemma!\ntheorem add_comm : n + m = m + n := by\n  induction n with\n  | zero      => exact zero_add\n  | succ n ih => simp [succ_add, ih]\n  \n\n-- Associativity can be proven in a similar way.\ntheorem add_assoc : (m + n) + k = m + (n + k) := by\n  induction k with\n  | zero      => rfl\n  | succ k ih => simp [succ_add, ih]\n  \n\ndef one := succ zero\n\ntheorem mul_one : m * one = m := by\n  simp [zero_add]\n\n-- To prove associativity of multiplication, you might have to come up with\n-- some more lemmas about multiplication first. Some are similar to the above laws of\n-- addition, some use both addition and multiplication (\"distributivity\" is the keyword).\n\ntheorem left_distrib : m * (n + k) = (m * n) + (m * k) := by\n  induction k with\n  | zero      => simp\n  | succ k ih =>\n    rw [add, mul, mul, ih, add_assoc]\n    -- NOTE: We *could* also use `add_assoc` as a simp theorem here.\n    -- ```\n    --  | succ n ih => simp [add_succ, ih, add_assoc]\n    -- ```\n    -- This even works with `add_comm` since `simp` is clever enough to avoid\n    -- permutating applicable terms endlessly! However, such general simp theorems\n    -- are best avoided for performance reasons and unintended interactions with\n    -- other simp theorems.\n\n\ntheorem mul_assoc : (m * n) * k = m * (n * k) := by \n  induction k with\n  | zero      => rfl\n  | succ k ih => simp [ih, left_distrib]\n  \n\n-- Remember the structures for semigroups and monoids which we defined last week?\nstructure Semigroup (α : Type) where\n  mul   : α → α → α\n  assoc : mul (mul a b) c = mul a (mul b c)\n\nstructure Monoid (α : Type) extends Semigroup α where\n  e     : α\n  e_mul : mul e a = a\n  mul_e : mul a e = a\n\n\ntheorem one_mul : one * m = m := by\n  induction m with\n  | zero      => rfl\n  | succ m ih => simp [ih]\n\n-- You should now be able to instantiate two of them, including proofs!\ndef Nat_add_Monoid : Monoid Nat := {\n  mul   := add\n  assoc := add_assoc\n  e     := zero\n  e_mul := zero_add\n  mul_e := rfl\n}\n\n\ndef Nat_mul_Monoid : Monoid Nat := {\n  mul   := mul\n  assoc := mul_assoc\n  e     := one\n  e_mul := one_mul\n  mul_e := mul_one\n}\n\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/Solutions/Exercise4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904955, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.797091969016872}}
{"text": "\nimport tactic\n/-!\nPlan for today\n- inductive types\n- the problem with the course\n- trees\n-/\n\ninductive mynat : Type -- no :=\n| zero : mynat\n| succ : mynat → mynat\n\n-- This is Peano's definition of ℕ\n-- but if look on Wikipedia you see\n\n#print mynat\n#print mynat.zero\n#print mynat.succ\n#print mynat.rec --automatically made by Lean\n--- The principle of induction and recursion\n\n-- how to prove (1) succ is injective and 92) succ n ≠ zero ?\n\n-- prove them by making more defintions\nnamespace mynat\n-- we have our zero inside out namespace\n#check zero\n\ndef is_zero : mynat → Prop\n| zero := true\n| (succ n) := false\n\nlemma zero_is_zero : is_zero zero :=\nbegin\n  change true,\n  trivial,\nend\n\nlemma succ_ne_zero (n : mynat) : ¬ (is_zero (succ n)) :=\nbegin\n  change ¬ false,\n  exact id,\nend\n\nlemma zero_ne_succ (n : mynat) : succ n ≠ zero :=\nbegin\n  intro h,\n  apply succ_ne_zero,\n  rw h,\n  apply zero_is_zero,\nend\n\ndef add : mynat → mynat → mynat\n| n zero := n\n| n (succ m) := succ (add n m)\n\ninstance : has_add mynat :=\n{ add := add }\n\nlemma add_zero (n : mynat) : n + zero = n :=\nbegin\n  refl,\nend\n\n-- injectivity of succ\n-- one way of doing it is to write a one sided inverse\n-- f: X → Y so if ∃ g: Y → X such that ∀ x, g(f(x)) = x\n-- f is the successor function which goes from ℕ to ℕ\n\ndef pred : mynat → mynat -- no :=\n| zero := succ(succ(succ(succ(succ(zero)))))--anywhere is fine\n| (succ n) := n\n\nlemma pred_succ (n : mynat) : pred (succ n) = n :=\nbegin\n  -- how to prove this?\n  refl, --does the trick\nend\n\n-- there is a way to switch off dot notation but Kevin doesn't remember\nlemma succ_inj : function.injective succ :=\nbegin\n  intros a b h,\n  apply_fun pred at h,\n  -- same as but apply_fun is easier to remember (probably)\n  --replace h := congr_arg pred h,\n  simpa [pred_succ] using h,\nend\n\nend mynat\n\ninductive mylist (X : Type) : Type\n| nil : mylist -- empty list\n| cons (x : X) (l : mylist) : mylist -- put x at the beginning\n\nnamespace mylist \nvariables (a b c : ℕ)\n\n-- list [a,b,c] of naturals\nexample : mylist ℕ := cons a (cons b (cons c nil))\n\nvariable {X : Type} -- make X implicit\n\n-- joining lists together\ndef add : mylist X → mylist X → mylist X\n| nil l := l\n| (cons x m) l := cons x (add m l)\n\ndef singleton (x : X) : mylist X := cons x nil\n\ndef reverse : mylist X → mylist X\n| nil := nil\n| (cons x m) := add (reverse m) (singleton x)\n\n\n-- Here is a surprisingly difficult question\ntheorem tricky (l : mylist X) : reverse (reverse l) = l :=\nbegin\n  sorry,\nend\n\nend mylist\n\n/-!\nNow lets talk about graphs\n\n*staring at mathlib/combinatorics/simple_graph/connectivity.lean file*\nexplaining what walk, trail, path, and cycles are in simple graphs\n\nis_tree is a property of the graph and not of a walk\na tree is a graph which is connected but does not have a cycle\n\nTree: ∀ u, v ∈ V, ∃! p : path u v\nThen theorem: no cycles\n\n\nProblem new defs in mathlib in febuary but we have a version from Jan\nSo best create a new repo to do the graph theory stuff\n\nOr one can do ``leanproject up`` in terminal to update mathlib.\n-/\n\n/-\nTHIRD ORALS sketch\n\nHand in deadline is 1PM Friday 1st for April\n\nProposal: we have a \"conference\" 2 PM to 3:30PM you all give 3 minute talks\non the 1st of April\n\nwhere you share your screen and your code and say something about it\nand convince Kevin we understand our code\n\nNo questions\n\nHybrid, people can be online or in person\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/03-15session-hour1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7970684733823441}}
{"text": "/-\nCopyright (c) 2022 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Daniel Selsam\n-/\nimport data.nat.basic\nimport data.list.basic\nimport data.list.pairwise\nimport tactic.fin_cases\n\nopen tactic\n\n/--\nThe ages of Jonie's four cousins are distinct single-digit positive integers. \nTwo of the cousins' ages multiplied together give $24$, while the other two multiply to $30$. \nWhat is the sum of the ages of Jonie's four cousins?\n-/\ntheorem amc10b_2021_p1 (c1 c2 c3 c4 : ℕ) :\n  c1 * c2 = 24\n  → c3 * c4 = 30 \n  → list.pairwise (≠) [c1, c2, c3, c4]\n  → list.all [c1, c2, c3, c4] (λ n, n < 10)\n  → c1 ≤ c2 -- TODO: these should be wlog-ed rather than built-in\n  → c3 ≤ c4\n  → c1 + c2 + c3 + c4 = 22 := \nbegin\n  intros h12 h34 h_pairwise h_bounds h12_le h34_le,\n  simp at h_pairwise h_bounds,\n  cases_matching* [_ ∨ _, _ ∧ _],\n  have h12_options : c1 = 3 ∧ c2 = 8 ∨ c1 = 4 ∧ c2 = 6, \n  {\n    -- TODO: interval_cases hits a deterministic timeout on ⬝ < 10\n    have h_c1 : c1 ∈ finset.range 10 := by simp *,\n    lift c1 to finset.range 10 using h_c1,\n    have h_c2 : c2 ∈ finset.range 10 := by simp *,\n    lift c2 to finset.range 10 using h_c2,\n    -- TODO: still very slow\n    fin_cases c1 ; fin_cases c2 ; subst_vars ; norm_num * at *\n  },\n  have h34_options : c3 = 5 ∧ c4 = 6, \n  {\n    -- TODO: interval_cases hits a deterministic timeout on ⬝ < 10\n    have h_c3 : c3 ∈ finset.range 10 := by simp *,\n    lift c3 to finset.range 10 using h_c3,\n    have h_c4 : c4 ∈ finset.range 10 := by simp *,\n    lift c4 to finset.range 10 using h_c4,\n    -- TODO: still very slow\n    fin_cases c3 ; fin_cases c4 ; subst_vars ; norm_num * at *\n  },\n  cases_matching* [_ ∨ _, _ ∧ _] ; simp * at *\nend\n\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/amc/10/2021/b/p5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7970684716472299}}
{"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 4 : exists (`∃`)\n\nIn this sheet we learn how to manipulate `∃` in Lean. We will see\nstatements of the form `∃ x, x ∈ A`. We will need to learn two new\ntactics -- one for making progress when the goal is `⊢ ∃ x, x ∈ A`, \nand one for making progress when we have a hypothesis `h : ∃ x, x ∈ A`.\n\nNow we have `∃` and `∀`, and `∈` and `∉`, we can finally get going\nwith some harder levels.\n\n## New tactics you will need to know\n\n`cases` or `rcases` -- to get the `x` from a hypothesis `h : ∃ x, ...`\n`use` -- to make progress on goals of the form `⊢ ∃ x, ...`\n\n### The `cases` tactic\n\nWe've seen this tactic before to take apart `h : P ∧ Q`. We can also\nuse it to take apart `h : ∃ t : X, F t`: if `h` is such a hypothesis\nthen `cases h with x hx,` will give us `x : X` and `hx : F x`\n\n### The `use` tactic\n\nIf we have a goal `⊢ ∃ x : X, F x` and a term `a : X` which we know\nwill work, then `use a` will change the goal to `F a`. By the way,\n`use` tries `refl` so it might magically close goals early\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 : x ∈ A → ∃ t, t ∈ A :=\nbegin\n  sorry\nend\n\nexample : (∀ x, x ∈ A) ↔ ¬ (∃ x, x ∉ A) :=\nbegin\n  sorry\nend\n\nexample : (∃ x, x ∈ A) ↔ ¬ (∀ x, x ∉ A) :=\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/sets/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676514011486, "lm_q2_score": 0.8723473846343394, "lm_q1q2_score": 0.7970433173997401}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intros hp notp,\n  contradiction,\n\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro notnotp,\n  by_contradiction notp,\n  contradiction,\n  \nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P,\n  exact doubleneg_intro P,\n  \nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro PouQ,\n  cases PouQ with hp hq,\n\n  right,\n  exact hp,\n\n  left,\n  exact hq,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro PandQ,\n  cases PandQ with hp hq,\n\n  split,\n  exact hq,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro notPorQ,\n  cases notPorQ with notp q,\n\n  intro p,\n  contradiction,\n\n  intro p,\n  exact q,\n\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro PorQ,\n  cases PorQ with p q,\n\n  intro notp,\n  contradiction,\n\n  intro notq,\n  exact q,\n\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro PthenQ,\n  intro notQ,\n  intro p,\n  \n  have q : Q := PthenQ p,\n  contradiction\n\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  \n  intro notQthennotP,\n  intro p,\n\n  by_cases h: Q,\n  exact h,\n\n  have notP : ¬P := notQthennotP h,\n  contradiction,\n\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  exact impl_as_contrapositive P Q,\n  exact impl_as_contrapositive_converse P Q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro notlem,\n  apply notlem, -- pois notlem <==> (lem => boom); troca alvo\n  right,\n  intro p,\n  apply notlem,\n  left,\n  exact p,\n\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro first,\n  intro notp,\n  apply notp,\n  apply first,\n  intro p,\n  contradiction,\n\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro PorQ,\n  cases PorQ with p q,\n\n  intro npANDnq,\n  cases npANDnq with np nq,\n  contradiction,\n\n  intro npANDnq,\n  cases npANDnq with np nq,\n  contradiction,\n  \nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro pandq,\n  intro npornq,\n  cases pandq with p q,\n\n  cases npornq,\n\n  contradiction,\n  contradiction,\n\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro notPorQ,\n  split,\n\n  intro p,\n  apply notPorQ,\n  left,\n  exact p,\n  \n  intro q,\n  apply notPorQ,\n  right,\n  exact q,\n\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro h,\n  cases h with np nq,\n  intro porq,\n\n  cases porq with p q,\n  contradiction,\n  contradiction,\n\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h,\n  by_contradiction j,\n  \n  apply j,\n  left,\n  intro q,\n\n  apply j,\n  right,\n  intro p,\n\n  apply h,\n  split,\n  \n  exact p,\n  exact q,\n\n\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro notqORnotp,\n  intro notPandQ,\n  cases notPandQ with p q,\n  cases notqORnotp with notq or notp,\n  contradiction,\n  contradiction,\n\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n  exact demorgan_disj_converse P Q,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h,\n  cases h with p QorR,\n  cases QorR with q r,\n  \n  left,\n  split,\n    exact p,\n    exact q,\n\n  right,\n  split,\n    exact p,\n    exact r,\n  \nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h,\n  split,\n\n  cases h with l r,\n    exact l.left,\n    exact r.left,\n  \n  cases h with l r,\n    left,\n    exact l.right,\n\n    right,\n    exact r.right,\n\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h,\n  split,\n\n  cases h with p QandR,\n    left,\n    exact p,\n\n    right,\n    exact QandR.left,\n\n  cases h with p QandR,\n    left,\n    exact p,\n\n    right,\n    exact QandR.right,\n\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  \n  cases h with l r,\n  cases r with p r,\n  left,\n  exact p,\n  cases l with p q,\n  left,\n  exact p,\n  right,\n  split,\n  exact q,\n  exact r,\n\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro h,\n  intros p q,\n  apply h,\n  split,\n  exact p,\n  exact q\n\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros h PandQ,\n  cases PandQ with p q,\n  have qr : Q→R := h p,\n  have r : R := qr q,\n  exact r,\n\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro pq,\n  exact pq.left,\n\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro pq,\n  exact pq.right,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n\n  intro pp,\n  exact pp.left,\n\n  intro p,\n  split,\n  exact p,\n  exact p,\n\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  \n  intro pp,\n  cases pp with p p,\n  exact p,\n  exact p,\n\n  intro p,\n  left,\n  exact p,\n\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro notx,\n  intro x,\n  intro px,\n\n  apply notx,\n  existsi x,\n  exact px,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro fallxnotp,\n  intro notxpx,\n  \n  cases notxpx with x px,\n  have a := fallxnotp x,\n  contradiction,\n\nend\n\ntheorem demorgan_forall : --feitiço\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro notpx,\n  by_contradiction NEnpx,\n  \n  apply notpx,\n  intro x,\n\n  by_contradiction notpx,\n  apply NEnpx,\n  existsi x,\n  exact notpx,\n\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro enpx,\n  cases enpx with x notpx,\n  intro allpx,\n  have a := allpx x,\n  contradiction,\n\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n  exact demorgan_forall_converse U P,\n\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro expx,\n  intro allnotpx,\n\n  cases expx with x px,\n  have notpx := allnotpx x,\n  contradiction,\n\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro allpx,\n  intro existnotpx,\n\n  cases existnotpx with x notpx,\n  have px := allpx x,\n  contradiction,\n\nend\n\ntheorem forall_as_neg_exists_converse : -- feitiço\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro Nnpx,\n  intro x,\n  by_contradiction px,\n\n  apply Nnpx,\n  existsi x,\n  exact px,\nend\n\ntheorem exists_as_neg_forall_converse : --feitiço\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro notallnotpx,\n  by_contradiction NEpx,\n\n  apply notallnotpx,\n  intro x,\n  intro px,\n\n  apply NEpx,\n  existsi x,\n  exact px,\n\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n  exact forall_as_neg_exists_converse U P,\n  \nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro pxandqx,\n  cases pxandqx with x pxandqx,\n  cases pxandqx with px qx,\n\n  split,\n  existsi x,\n  exact px,\n\n  existsi x,\n  exact qx,\n  \nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro pxorqx,\n  cases pxorqx with x a,\n\n  cases a with px qx,\n  left,\n  existsi x,\n  exact px,\n\n  right,\n  existsi x,\n  exact qx,\n\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  cases h with l r,\n\n  cases l with x px,\n  \n  existsi x,\n  left,\n  exact px,\n\n  cases r with x qx,\n\n  existsi x,\n  right,\n  exact qx,\n\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro h,\n  split,\n\n  intro x,\n  have props := h x,\n  cases props with px qx,\n  exact px,\n\n  intro x,\n  have props := h x,\n  cases props with px qx,\n  exact qx,\n\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro h,\n  cases h with l r,\n  intro x,\n  have px := l x,\n  have qx := r x,\n  \n  split,\n  exact px,\n  exact qx,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro h,\n  intro x,\n\n  cases h with l r,\n  \n  have px := l x,\n  left,\n  exact px,\n\n  have qx := r x,\n  right,\n  exact qx,\n\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "angelo-rbs", "repo": "fmclean", "sha": "3b454cb4f9c395d1775cad0558e6ddec8eaa867a", "save_path": "github-repos/lean/angelo-rbs-fmclean", "path": "github-repos/lean/angelo-rbs-fmclean/fmclean-3b454cb4f9c395d1775cad0558e6ddec8eaa867a/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7970162130884998}}
{"text": "import data.real.pi\n\nopen_locale real\n\nexample : (⋃ (n : ℤ), set.Ioo (n * (2 * π) - (π / 2) : ℝ) (n * (2 * π) + (π / 2) : ℝ)) ∪\n  (⋃ (n : ℤ), set.Icc (n * (2 * π) + (π / 2) : ℝ) (n * (2 * π) + (3 * π/2) : ℝ)) = set.univ :=\nbegin\n  rw set.eq_univ_iff_forall,\n  intro x,\nend\n\nlemma cos_pos_iff (t : ℝ) : real.cos t > 0 ↔ \n  t ∈ ⋃ (n : ℤ), set.Ioo (n * (2 * π) - (π / 2) : ℝ) (n * (2 * π) + (π / 2) : ℝ) :=\nsorry\n-- begin\n--   split,\n--   { sorry },\n--   { rintros ⟨V, ⟨n, rfl⟩, ht⟩,\n--      dsimp at ht,\n--      have h₁ : real.cos t = real.cos (t - n * (2 * π)),\n--      { rw real.cos_sub_int_mul_two_pi },\n--      have h₂ : t - n * (2 * π) ∈ set.Ioo (-(π/2)) (π/2),\n--      { cases ht, split; linarith },\n--      rw h₁,\n--      apply real.cos_pos_of_mem_Ioo h₂, }\n-- end\n\n-- #check div_div_div_div_eq\n-- #check pow_mul\n-- -- #check mul_assoc\n-- #check list.append_assoc\n\n-- #print notation +\n-- #print notation ++\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/mwe.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7970162084284251}}
{"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.gcd_monoid.finset\nimport data.polynomial.field_division\nimport data.polynomial.erase_lead\nimport data.polynomial.cancel_leads\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.normalized_gcd_monoid`:\n  The polynomial ring of a GCD domain is itself a GCD domain.\n\n-/\n\nnamespace polynomial\n\nsection primitive\n\nvariables {R : Type*} [comm_semiring R]\n\n/-- A polynomial is primitive when the only constant polynomials dividing it are units -/\ndef is_primitive (p : polynomial R) : Prop :=\n∀ (r : R), C r ∣ p → is_unit r\n\nlemma is_primitive_iff_is_unit_of_C_dvd {p : polynomial R} :\n  p.is_primitive ↔ ∀ (r : R), C r ∣ p → is_unit r :=\niff.rfl\n\n@[simp]\nlemma is_primitive_one : is_primitive (1 : polynomial R) :=\nλ r h, is_unit_C.mp (is_unit_of_dvd_one (C r) h)\n\nlemma monic.is_primitive {p : polynomial R} (hp : p.monic) : p.is_primitive :=\nbegin\n  rintros r ⟨q, h⟩,\n  exact is_unit_of_mul_eq_one r (q.coeff p.nat_degree) (by rwa [←coeff_C_mul, ←h]),\nend\n\nlemma is_primitive.ne_zero [nontrivial R] {p : polynomial R} (hp : p.is_primitive) : p ≠ 0 :=\nbegin\n  rintro rfl,\n  exact (hp 0 (dvd_zero (C 0))).ne_zero rfl,\nend\n\nend primitive\n\nvariables {R : Type*} [comm_ring R] [is_domain R]\n\nsection normalized_gcd_monoid\nvariable [normalized_gcd_monoid R]\n\n/-- `p.content` is the `gcd` of the coefficients of `p`. -/\ndef content (p : polynomial R) : R := (p.support).gcd p.coeff\n\nlemma content_dvd_coeff {p : polynomial R} (n : ℕ) : p.content ∣ p.coeff n :=\nbegin\n  by_cases h : n ∈ p.support,\n  { apply finset.gcd_dvd h },\n  rw [mem_support_iff, not_not] at h,\n  rw h,\n  apply dvd_zero,\nend\n\n@[simp] lemma content_C {r : R} : (C r).content = normalize r :=\nbegin\n  rw content,\n  by_cases h0 : r = 0,\n  { simp [h0] },\n  have h : (C r).support = {0} := support_monomial _ _ h0,\n  simp [h],\nend\n\n@[simp] lemma content_zero : content (0 : polynomial R) = 0 :=\nby rw [← C_0, content_C, normalize_zero]\n\n@[simp] lemma content_one : content (1 : polynomial R) = 1 :=\nby rw [← C_1, content_C, normalize_one]\n\nlemma content_X_mul {p : polynomial R} : content (X * p) = content p :=\nbegin\n  rw [content, content, finset.gcd_def, finset.gcd_def],\n  refine congr rfl _,\n  have h : (X * p).support = p.support.map ⟨nat.succ, nat.succ_injective⟩,\n  { ext a,\n    simp only [exists_prop, finset.mem_map, function.embedding.coe_fn_mk, ne.def,\n      mem_support_iff],\n    cases a,\n    { simp [coeff_X_mul_zero, nat.succ_ne_zero] },\n    rw [mul_comm, coeff_mul_X],\n    split,\n    { intro h,\n      use a,\n      simp [h] },\n    { rintros ⟨b, ⟨h1, h2⟩⟩,\n      rw ← nat.succ_injective h2,\n      apply h1 } },\n  rw h,\n  simp only [finset.map_val, function.comp_app, function.embedding.coe_fn_mk, multiset.map_map],\n  refine congr (congr rfl _) rfl,\n  ext a,\n  rw mul_comm,\n  simp [coeff_mul_X],\nend\n\n@[simp] lemma content_X_pow {k : ℕ} : content ((X : polynomial R) ^ k) = 1 :=\nbegin\n  induction k with k hi,\n  { simp },\n  rw [pow_succ, content_X_mul, hi]\nend\n\n@[simp] lemma content_X : content (X : polynomial R) = 1 :=\nby { rw [← mul_one X, content_X_mul, content_one] }\n\nlemma content_C_mul (r : R) (p : polynomial R) : (C r * p).content = normalize r * p.content :=\nbegin\n  by_cases h0 : r = 0, { simp [h0] },\n  rw content, rw content, rw ← finset.gcd_mul_left,\n  refine congr (congr rfl _) _; ext; simp [h0, mem_support_iff]\nend\n\n@[simp] lemma content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r :=\nby { rw [monomial_eq_C_mul_X, content_C_mul, content_X_pow, mul_one] }\n\nlemma content_eq_zero_iff {p : polynomial R} : content p = 0 ↔ p = 0 :=\nbegin\n  rw [content, finset.gcd_eq_zero_iff],\n  split; intro h,\n  { ext n,\n    by_cases h0 : n ∈ p.support,\n    { rw [h n h0, coeff_zero], },\n    { rw mem_support_iff at h0,\n      push_neg at h0,\n      simp [h0] } },\n  { intros x h0,\n    simp [h] }\nend\n\n@[simp] lemma normalize_content {p : polynomial R} : normalize p.content = p.content :=\nfinset.normalize_gcd\n\nlemma content_eq_gcd_range_of_lt (p : polynomial R) (n : ℕ) (h : p.nat_degree < n) :\n  p.content = (finset.range n).gcd p.coeff :=\nbegin\n  apply dvd_antisymm_of_normalize_eq normalize_content finset.normalize_gcd,\n  { rw finset.dvd_gcd_iff,\n    intros i hi,\n    apply content_dvd_coeff _ },\n  { 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), }\nend\n\n\n\nlemma content_eq_gcd_leading_coeff_content_erase_lead (p : polynomial R) :\n  p.content = gcd_monoid.gcd p.leading_coeff (erase_lead p).content :=\nbegin\n  by_cases h : p = 0,\n  { simp [h] },\n  rw [← leading_coeff_eq_zero, leading_coeff, ← ne.def, ← mem_support_iff] at h,\n  rw [content, ← finset.insert_erase h, finset.gcd_insert, leading_coeff, content,\n    erase_lead_support],\n  refine congr rfl (finset.gcd_congr rfl (λ i hi, _)),\n  rw finset.mem_erase at hi,\n  rw [erase_lead_coeff, if_neg hi.1],\nend\n\nlemma dvd_content_iff_C_dvd {p : polynomial R} {r : R} : r ∣ p.content ↔ C r ∣ p :=\nbegin\n  rw C_dvd_iff_dvd_coeff,\n  split,\n  { intros h i,\n    apply h.trans (content_dvd_coeff _) },\n  { intro h,\n    rw [content, finset.dvd_gcd_iff],\n    intros i hi,\n    apply h i }\nend\n\nlemma C_content_dvd (p : polynomial R) : C p.content ∣ p :=\ndvd_content_iff_C_dvd.1 dvd_rfl\n\nlemma is_primitive_iff_content_eq_one {p : polynomial R} : p.is_primitive ↔ p.content = 1 :=\nbegin\n  rw [←normalize_content, normalize_eq_one, is_primitive],\n  simp_rw [←dvd_content_iff_C_dvd],\n  exact ⟨λ h, h p.content (dvd_refl p.content), λ h r hdvd, is_unit_of_dvd_unit hdvd h⟩,\nend\n\nlemma is_primitive.content_eq_one {p : polynomial R} (hp : p.is_primitive) : p.content = 1 :=\nis_primitive_iff_content_eq_one.mp hp\n\nopen_locale classical\nnoncomputable theory\n\nsection prim_part\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 (p : polynomial R) : polynomial R :=\nif p = 0 then 1 else classical.some (C_content_dvd p)\n\nlemma eq_C_content_mul_prim_part (p : polynomial R) : p = C p.content * p.prim_part :=\nbegin\n  by_cases h : p = 0, { simp [h] },\n  rw [prim_part, if_neg h, ← classical.some_spec (C_content_dvd p)],\nend\n\n@[simp]\nlemma prim_part_zero : prim_part (0 : polynomial R) = 1 := if_pos rfl\n\nlemma is_primitive_prim_part (p : polynomial R) : p.prim_part.is_primitive :=\nbegin\n  by_cases h : p = 0, { simp [h] },\n  rw ← content_eq_zero_iff at h,\n  rw is_primitive_iff_content_eq_one,\n  apply mul_left_cancel₀ h,\n  conv_rhs { rw [p.eq_C_content_mul_prim_part, mul_one, content_C_mul, normalize_content] }\nend\n\nlemma content_prim_part (p : polynomial R) : p.prim_part.content = 1 :=\np.is_primitive_prim_part.content_eq_one\n\nlemma prim_part_ne_zero (p : polynomial R) : p.prim_part ≠ 0 := p.is_primitive_prim_part.ne_zero\n\nlemma nat_degree_prim_part (p : polynomial R) : p.prim_part.nat_degree = p.nat_degree :=\nbegin\n  by_cases h : C p.content = 0,\n  { rw [C_eq_zero, content_eq_zero_iff] at h, simp [h] },\n  conv_rhs { rw [p.eq_C_content_mul_prim_part,\n    nat_degree_mul h p.prim_part_ne_zero, nat_degree_C, zero_add] },\nend\n\n@[simp]\nlemma is_primitive.prim_part_eq {p : polynomial R} (hp : p.is_primitive) : p.prim_part = p :=\nby rw [← one_mul p.prim_part, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_prim_part]\n\nlemma is_unit_prim_part_C (r : R) : is_unit (C r).prim_part :=\nbegin\n  by_cases h0 : r = 0,\n  { simp [h0] },\n  unfold is_unit,\n  refine ⟨⟨C ↑(norm_unit r)⁻¹, C ↑(norm_unit r),\n    by rw [← ring_hom.map_mul, units.inv_mul, C_1],\n    by rw [← ring_hom.map_mul, units.mul_inv, C_1]⟩, _⟩,\n  rw [← normalize_eq_zero, ← C_eq_zero] at h0,\n  apply mul_left_cancel₀ h0,\n  conv_rhs { rw [← content_C, ← (C r).eq_C_content_mul_prim_part], },\n  simp only [units.coe_mk, normalize_apply, ring_hom.map_mul],\n  rw [mul_assoc, ← ring_hom.map_mul, units.mul_inv, C_1, mul_one],\nend\n\nlemma prim_part_dvd (p : polynomial R) : p.prim_part ∣ p :=\ndvd.intro_left (C p.content) p.eq_C_content_mul_prim_part.symm\n\nend prim_part\n\nlemma gcd_content_eq_of_dvd_sub {a : R} {p q : polynomial R} (h : C a ∣ p - q) :\n  gcd_monoid.gcd a p.content = gcd_monoid.gcd a q.content :=\nbegin\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  intros x hx,\n  cases h with w hw,\n  use w.coeff x,\n  rw [← coeff_sub, hw, coeff_C_mul]\nend\n\nlemma content_mul_aux {p q : polynomial R} :\n  gcd_monoid.gcd (p * q).erase_lead.content p.leading_coeff =\n  gcd_monoid.gcd (p.erase_lead * q).content p.leading_coeff :=\nbegin\n  rw [gcd_comm (content _) _, gcd_comm (content _) _],\n  apply gcd_content_eq_of_dvd_sub,\n  rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,\n    sub_sub_cancel, leading_coeff_mul, ring_hom.map_mul, mul_assoc, mul_assoc],\n  apply dvd_sub (dvd.intro _ rfl) (dvd.intro _ rfl),\nend\n\n@[simp]\ntheorem content_mul {p q : polynomial R} : (p * q).content = p.content * q.content :=\nbegin\n  classical,\n  suffices h : ∀ (n : ℕ) (p q : polynomial R), ((p * q).degree < n) →\n    (p * q).content = p.content * q.content,\n  { apply h,\n    apply (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (nat.lt_succ_self _))) },\n  intro n,\n  induction n with n ih,\n  { intros p q hpq,\n    rw [with_bot.coe_zero, nat.with_bot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq,\n    rcases hpq with rfl | rfl; simp },\n  intros p q hpq,\n  by_cases p0 : p = 0, { simp [p0] },\n  by_cases q0 : q = 0, { simp [q0] },\n  rw [degree_eq_nat_degree (mul_ne_zero p0 q0), with_bot.coe_lt_coe, nat.lt_succ_iff_lt_or_eq,\n    ← with_bot.coe_lt_coe, ← degree_eq_nat_degree (mul_ne_zero p0 q0), nat_degree_mul p0 q0] at hpq,\n  rcases hpq with hlt | heq, { apply ih _ _ hlt },\n  rw [← p.nat_degree_prim_part, ← q.nat_degree_prim_part, ← with_bot.coe_eq_coe, with_bot.coe_add,\n    ← degree_eq_nat_degree p.prim_part_ne_zero, ← 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  { 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 [← normalize_content, normalize_eq_one, is_unit_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,\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,\n      ← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part],\n  { rw [← heq, degree_mul, with_bot.add_lt_add_iff_right],\n    { apply degree_erase_lt p.prim_part_ne_zero },\n    { rw [ne.def, degree_eq_bot],\n      apply q.prim_part_ne_zero } },\n  { rw [mul_comm, ← heq, degree_mul, with_bot.add_lt_add_iff_left],\n    { apply degree_erase_lt q.prim_part_ne_zero },\n    { rw [ne.def, degree_eq_bot],\n      apply p.prim_part_ne_zero } }\nend\n\ntheorem is_primitive.mul {p q : polynomial R} (hp : p.is_primitive) (hq : q.is_primitive) :\n  (p * q).is_primitive :=\nby rw [is_primitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]\n\n@[simp]\ntheorem prim_part_mul {p q : polynomial R} (h0 : p * q ≠ 0) :\n  (p * q).prim_part = p.prim_part * q.prim_part :=\nbegin\n  rw [ne.def, ← content_eq_zero_iff, ← C_eq_zero] at h0,\n  apply mul_left_cancel₀ h0,\n  conv_lhs { rw [← (p * q).eq_C_content_mul_prim_part,\n    p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part] },\n  rw [content_mul, ring_hom.map_mul],\n  ring,\nend\n\nlemma is_primitive.is_primitive_of_dvd {p q : polynomial R} (hp : p.is_primitive) (hdvd : q ∣ p) :\n  q.is_primitive :=\nbegin\n  rcases hdvd with ⟨r, rfl⟩,\n  rw [is_primitive_iff_content_eq_one, ← normalize_content, normalize_eq_one, is_unit_iff_dvd_one],\n  apply dvd.intro r.content,\n  rwa [is_primitive_iff_content_eq_one, content_mul] at hp,\nend\n\nlemma is_primitive.dvd_prim_part_iff_dvd {p q : polynomial R}\n  (hp : p.is_primitive) (hq : q ≠ 0) :\n  p ∣ q.prim_part ↔ p ∣ q :=\nbegin\n  refine ⟨λ h, h.trans (dvd.intro_left _ q.eq_C_content_mul_prim_part.symm), λ h, _⟩,\n  rcases h with ⟨r, rfl⟩,\n  apply dvd.intro _,\n  rw [prim_part_mul hq, hp.prim_part_eq],\nend\n\ntheorem exists_primitive_lcm_of_is_primitive {p q : polynomial R}\n  (hp : p.is_primitive) (hq : q.is_primitive) :\n  ∃ r : polynomial R, r.is_primitive ∧ (∀ s : polynomial R, p ∣ s ∧ q ∣ s ↔ r ∣ s) :=\nbegin\n  classical,\n  have h : ∃ (n : ℕ) (r : polynomial R), r.nat_degree = n ∧ r.is_primitive ∧ p ∣ r ∧ q ∣ r :=\n    ⟨(p * q).nat_degree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩,\n  rcases nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩,\n  refine ⟨r, rprim, λ s, ⟨_, λ rs, ⟨pr.trans rs, qr.trans rs⟩⟩⟩,\n  suffices hs : ∀ (n : ℕ) (s : polynomial R), s.nat_degree = n → (p ∣ s ∧ q ∣ s → r ∣ s),\n  { apply hs s.nat_degree s rfl },\n  clear s,\n  by_contra con,\n  push_neg at con,\n  rcases nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩,\n  have s0 : s ≠ 0,\n  { contrapose! rs, simp [rs] },\n  have hs := nat.find_min' h ⟨_, s.nat_degree_prim_part, s.is_primitive_prim_part,\n              (hp.dvd_prim_part_iff_dvd s0).2 ps, (hq.dvd_prim_part_iff_dvd s0).2 qs⟩,\n  rw ← rdeg at hs,\n  by_cases sC : s.nat_degree ≤ 0,\n  { rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), is_primitive_iff_content_eq_one,\n      content_C, normalize_eq_one] at rprim,\n    rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), ← 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 ⟨_, rfl, ⟨dvd_cancel_leads_of_dvd_of_dvd pr ps, dvd_cancel_leads_of_dvd_of_dvd qr qs⟩,\n      λ rcs, rs _⟩,\n  rw ← 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, ← leading_coeff_eq_zero, ← C_eq_zero] at hC0,\n  rw [sub_add_cancel, ← rprim.dvd_prim_part_iff_dvd (mul_ne_zero hC0 s0)] at h,\n  rcases is_unit_prim_part_C r.leading_coeff with ⟨u, hu⟩,\n  apply h.trans (associated.symm ⟨u, _⟩).dvd,\n  rw [prim_part_mul (mul_ne_zero hC0 s0), hu, mul_comm],\nend\n\nlemma dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part\n  {p q : polynomial R} (hq : q ≠ 0) :\n  p ∣ q ↔ p.content ∣ q.content ∧ p.prim_part ∣ q.prim_part :=\nbegin\n  split; intro h,\n  { rcases h with ⟨r, rfl⟩,\n    rw [content_mul, p.is_primitive_prim_part.dvd_prim_part_iff_dvd hq],\n    exact ⟨dvd.intro _ rfl, p.prim_part_dvd.trans (dvd.intro _ rfl)⟩ },\n  { rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part],\n    exact mul_dvd_mul (ring_hom.map_dvd C h.1) h.2 }\nend\n\n@[priority 100]\ninstance normalized_gcd_monoid : normalized_gcd_monoid (polynomial R) :=\nnormalized_gcd_monoid_of_exists_lcm $ λ p q, begin\n  rcases exists_primitive_lcm_of_is_primitive p.is_primitive_prim_part q.is_primitive_prim_part\n    with ⟨r, rprim, hr⟩,\n  refine ⟨C (lcm p.content q.content) * r, λ s, _⟩,\n  by_cases hs : s = 0,\n  { simp [hs] },\n  by_cases hpq : C (lcm p.content q.content) = 0,\n  { 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    is_unit.mul_left_dvd _ _ _ (is_unit_prim_part_C (lcm p.content q.content)), ← hr s.prim_part],\n  tauto,\nend\n\nlemma degree_gcd_le_left {p : polynomial R} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree :=\nbegin\n  have := nat_degree_le_iff_degree_le.mp\n    (nat_degree_le_of_dvd (gcd_dvd_left p q) hp),\n  rwa degree_eq_nat_degree hp\nend\n\nlemma degree_gcd_le_right (p) {q : polynomial R} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree :=\nby { rw [gcd_comm], exact degree_gcd_le_left hq p }\n\nend normalized_gcd_monoid\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/content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7969442699316589}}
{"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: `𝔠`, localized in `cardinal`) to be `2 ^ ω`.\nWe also prove some `simp` lemmas about cardinal arithmetic involving `𝔠`.\n\n## Notation\n\n- `𝔠` : 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 ^ omega.{u}\n\nlocalized \"notation `𝔠` := cardinal.continuum\" in cardinal\n\n@[simp] lemma two_power_omega : (2 ^ omega.{u} : cardinal.{u}) = 𝔠 := rfl\n\n@[simp] lemma lift_continuum : lift.{v} continuum.{u} = 𝔠 :=\nby rw [← two_power_omega, lift_two_power, lift_omega, two_power_omega]\n\n/-!\n### Inequalities\n-/\n\nlemma omega_lt_continuum : ω < 𝔠 := cantor ω\n\nlemma omega_le_continuum : ω ≤ 𝔠 := omega_lt_continuum.le\n\nlemma nat_lt_continuum (n : ℕ) : ↑n < 𝔠 := (nat_lt_omega n).trans omega_lt_continuum\n\nlemma mk_set_nat : #(set ℕ) = 𝔠 := by simp\n\nlemma continuum_pos : 0 < 𝔠 := nat_lt_continuum 0\n\nlemma continuum_ne_zero : 𝔠 ≠ 0 := continuum_pos.ne'\n\nlemma aleph_one_le_continuum : aleph 1 ≤ 𝔠 :=\nby { rw ← succ_omega, exact succ_le.2 omega_lt_continuum }\n\n/-!\n### Addition\n-/\n\n@[simp] lemma omega_add_continuum : ω + 𝔠 = 𝔠 :=\nadd_eq_right omega_le_continuum omega_le_continuum\n\n@[simp] lemma continuum_add_omega : 𝔠 + ω = 𝔠 :=\n(add_comm _ _).trans omega_add_continuum\n\n@[simp] lemma continuum_add_self : 𝔠 + 𝔠 = 𝔠 :=\nadd_eq_right omega_le_continuum le_rfl\n\n@[simp] lemma nat_add_continuum (n : ℕ) : ↑n + 𝔠 = 𝔠 :=\nadd_eq_right omega_le_continuum (nat_lt_continuum n).le\n\n@[simp] lemma continuum_add_nat (n : ℕ) : 𝔠 + n = 𝔠 :=\n(add_comm _ _).trans (nat_add_continuum n)\n\n/-!\n### Multiplication\n-/\n\n@[simp] lemma continuum_mul_self : 𝔠 * 𝔠 = 𝔠 :=\nmul_eq_left omega_le_continuum le_rfl continuum_ne_zero\n\n@[simp] lemma continuum_mul_omega : 𝔠 * ω = 𝔠 :=\nmul_eq_left omega_le_continuum omega_le_continuum omega_ne_zero\n\n@[simp] lemma omega_mul_continuum : ω * 𝔠 = 𝔠 :=\n(mul_comm _ _).trans continuum_mul_omega\n\n@[simp] lemma nat_mul_continuum {n : ℕ} (hn : n ≠ 0) :\n  ↑n * 𝔠 = 𝔠 :=\nmul_eq_right omega_le_continuum (nat_lt_continuum n).le (nat.cast_ne_zero.2 hn)\n\n@[simp] lemma continuum_mul_nat {n : ℕ} (hn : n ≠ 0) :\n  𝔠 * n = 𝔠 :=\n(mul_comm _ _).trans (nat_mul_continuum hn)\n\n/-!\n### Power\n-/\n\n@[simp] lemma omega_power_omega : omega.{u} ^ omega.{u} = 𝔠 :=\npower_self_eq le_rfl\n\n@[simp] lemma nat_power_omega {n : ℕ} (hn : 2 ≤ n) : (n ^ omega.{u} : cardinal.{u}) = 𝔠 :=\nnat_power_eq le_rfl hn\n\n@[simp] lemma continuum_power_omega : continuum.{u} ^ omega.{u} = 𝔠 :=\nby rw [← two_power_omega, ← power_mul, mul_eq_left le_rfl le_rfl omega_ne_zero]\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/continuum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.7969442673039077}}
{"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ël Dillies\n-/\nimport data.nat.pow\nimport tactic.by_contra\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 `ℕ`-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 ≤ n`.\n* `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n ≤ 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 : ℕ`\nsuch that `b^k ≤ n`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def log (b : ℕ) : ℕ → ℕ\n| n :=\n  if h : b ≤ n ∧ 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\n@[simp] lemma log_eq_zero_iff {b n : ℕ} : log b n = 0 ↔ n < b ∨ b ≤ 1 :=\nbegin\n  rw [log, ite_eq_right_iff],\n  simp only [nat.succ_ne_zero, imp_false, decidable.not_and_distrib, not_le, not_lt]\nend\n\nlemma log_of_lt {b n : ℕ} (hb : n < b) : log b n = 0 :=\nlog_eq_zero_iff.2 (or.inl hb)\n\nlemma log_of_left_le_one {b : ℕ} (hb : b ≤ 1) (n) : log b n = 0 :=\nlog_eq_zero_iff.2 (or.inr hb)\n\n@[simp] lemma log_pos_iff {b n : ℕ} : 0 < log b n ↔ b ≤ n ∧ 1 < b :=\nby rw [pos_iff_ne_zero, ne.def, log_eq_zero_iff, not_or_distrib, not_lt, not_le]\n\nlemma log_pos {b n : ℕ} (hb : 1 < b) (hbn : b ≤ n) : 0 < log b n := log_pos_iff.2 ⟨hbn, hb⟩\n\nlemma log_of_one_lt_of_le {b n : ℕ} (h : 1 < b) (hn : b ≤ n) : log b n = log b (n / b) + 1 :=\nby { rw log, exact if_pos ⟨hn, h⟩ }\n\n@[simp] lemma log_zero_left : ∀ n, log 0 n = 0 := log_of_left_le_one zero_le_one\n@[simp] lemma log_zero_right (b : ℕ) : log b 0 = 0 := log_eq_zero_iff.2 (le_total 1 b)\n@[simp] lemma log_one_left : ∀ n, log 1 n = 0 := log_of_left_le_one le_rfl\n@[simp] lemma log_one_right (b : ℕ) : log b 1 = 0 := log_eq_zero_iff.2 (lt_or_le _ _)\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. -/\nlemma pow_le_iff_le_log {b : ℕ} (hb : 1 < b) {x y : ℕ} (hy : y ≠ 0) : b ^ x ≤ y ↔ x ≤ 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.bot_lt (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, ←ih (y / b) (div_lt_self hy.bot_lt hb)\n      (nat.div_pos h.1 b_pos).ne', le_div_iff_mul_le b_pos, pow_succ'] },\n  { exact iff_of_false (λ hby, h ⟨(le_self_pow x.succ_ne_zero _).trans hby, hb⟩)\n      (not_succ_le_zero _) }\nend\n\nlemma lt_pow_iff_log_lt {b : ℕ} (hb : 1 < b) {x y : ℕ} (hy : y ≠ 0) : y < b ^ x ↔ log b y < x :=\nlt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy)\n\nlemma pow_le_of_le_log {b x y : ℕ} (hy : y ≠ 0) (h : x ≤ log b y) : b ^ x ≤ y :=\nbegin\n  refine (le_or_lt b 1).elim (λ hb, _) (λ 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]\nend\n\nlemma le_log_of_pow_le {b x y : ℕ} (hb : 1 < b) (h : b ^ x ≤ y) : x ≤ log b y :=\nbegin\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]\nend\n\nlemma pow_log_le_self (b : ℕ) {x : ℕ} (hx : x ≠ 0) : b ^ log b x ≤ x :=\npow_le_of_le_log hx le_rfl\n\nlemma log_lt_of_lt_pow {b x y : ℕ} (hy : y ≠ 0) : y < b ^ x → log b y < x :=\nlt_imp_lt_of_le_imp_le (pow_le_of_le_log hy)\n\nlemma lt_pow_of_log_lt {b x y : ℕ} (hb : 1 < b) : log b y < x → y < b ^ x :=\nlt_imp_lt_of_le_imp_le (le_log_of_pow_le hb)\n\nlemma lt_pow_succ_log_self {b : ℕ} (hb : 1 < b) (x : ℕ) :\n  x < b ^ (log b x).succ :=\nlt_pow_of_log_lt hb (lt_succ_self _)\n\nlemma log_eq_iff {b m n : ℕ} (h : m ≠ 0 ∨ 1 < b ∧ n ≠ 0) :\n  log b n = m ↔ b ^ m ≤ n ∧ n < b ^ (m + 1) :=\nbegin\n  rcases em (1 < b ∧ n ≠ 0) with ⟨hb, hn⟩|hbn,\n  { rw [le_antisymm_iff, ← lt_succ_iff, ← pow_le_iff_le_log, ← lt_pow_iff_log_lt, and.comm];\n      assumption },\n  { have hm : m ≠ 0, from h.resolve_right hbn,\n    rw [not_and_distrib, not_lt, ne.def, not_not] at hbn,\n    rcases hbn with hb|rfl,\n    { simpa only [log_of_left_le_one hb, hm.symm, false_iff, not_and, not_lt]\n        using le_trans (pow_le_pow_of_le_one' hb m.le_succ) },\n    { simpa only [log_zero_right, hm.symm, false_iff, not_and, not_lt, le_zero_iff, pow_succ]\n        using mul_eq_zero_of_right _ } }\nend\n\nlemma log_eq_of_pow_le_of_lt_pow {b m n : ℕ} (h₁ : b ^ m ≤ n) (h₂ : n < b ^ (m + 1)) :\n  log b n = m :=\nbegin\n  rcases eq_or_ne m 0 with rfl | hm,\n  { rw [pow_one] at h₂, exact log_of_lt h₂ },\n  { exact (log_eq_iff (or.inl hm)).2 ⟨h₁, h₂⟩ }\nend\n\nlemma log_pow {b : ℕ} (hb : 1 < b) (x : ℕ) : log b (b ^ x) = x :=\nlog_eq_of_pow_le_of_lt_pow le_rfl (pow_lt_pow hb x.lt_succ_self)\n\nlemma log_eq_one_iff' {b n : ℕ} : log b n = 1 ↔ b ≤ n ∧ n < b * b:=\nby rw [log_eq_iff (or.inl one_ne_zero), pow_add, pow_one]\n\nlemma log_eq_one_iff {b n : ℕ} : log b n = 1 ↔ n < b * b ∧ 1 < b ∧ b ≤ n :=\nlog_eq_one_iff'.trans ⟨λ h, ⟨h.2, lt_mul_self_iff.1 (h.1.trans_lt h.2), h.1⟩, λ h, ⟨h.2.2, h.1⟩⟩\n\nlemma log_mul_base {b n : ℕ} (hb : 1 < b) (hn : n ≠ 0) : log b (n * b) = log b n + 1 :=\nbegin\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 _)]\nend\n\n\n\nlemma log_monotone {b : ℕ} : monotone (log b) :=\nbegin\n  refine monotone_nat_of_le_succ (λ n, _),\n  cases le_or_lt b 1 with hb hb,\n  { rw log_of_left_le_one hb, exact zero_le _ },\n  { exact le_log_of_pow_le hb (pow_log_le_add_one _ _) }\nend\n\n@[mono] lemma log_mono_right {b n m : ℕ} (h : n ≤ m) : log b n ≤ log b m :=\nlog_monotone h\n\n@[mono] lemma log_anti_left {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : log b n ≤ log c n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { rw [log_zero_right, log_zero_right] },\n  apply le_log_of_pow_le hc,\n  calc c ^ log b n ≤ b ^ log b n : pow_le_pow_of_le_left' hb _\n               ... ≤ n           : pow_log_le_self _ hn\nend\n\nlemma log_antitone_left {n : ℕ} : antitone_on (λ b, log b n) (set.Ioi 1) :=\nλ _ hc _ _ hb, log_anti_left (set.mem_Iio.1 hc) hb\n\n@[simp] lemma log_div_base (b n : ℕ) : log b (n / b) = log b n - 1 :=\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, nat.zero_sub] },\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  rw [log_of_one_lt_of_le hb h, add_tsub_cancel_right]\nend\n\n@[simp] lemma log_div_mul_self (b n : ℕ) : log b (n / b * b) = log b n :=\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 lt_or_le n b with h h,\n  { rw [div_eq_of_lt h, 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)]\nend\n\nprivate lemma add_pred_div_lt {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : (n + b - 1) / b < n :=\nbegin\n  rw [div_lt_iff_lt_mul (zero_lt_one.trans hb), ←succ_le_iff, ←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,\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 : ℕ` such that `n ≤ b^k`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def clog (b : ℕ) : ℕ → ℕ\n| n :=\n  if h : 1 < b ∧ 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 : ℕ} (hb : b ≤ 1) (n : ℕ) : clog b n = 0 :=\nby rw [clog, if_neg (λ h : 1 < b ∧ 1 < n, h.1.not_le hb)]\n\nlemma clog_of_right_le_one {n : ℕ} (hn : n ≤ 1) (b : ℕ) : clog b n = 0 :=\nby rw [clog, if_neg (λ h : 1 < b ∧ 1 < n, h.2.not_le hn)]\n\n@[simp] lemma clog_zero_left (n : ℕ) : clog 0 n = 0 :=\nclog_of_left_le_one zero_le_one _\n\n@[simp] lemma clog_zero_right (b : ℕ) : clog b 0 = 0 :=\nclog_of_right_le_one zero_le_one _\n\n@[simp] lemma clog_one_left (n : ℕ) : clog 1 n = 0 :=\nclog_of_left_le_one le_rfl _\n\n@[simp] lemma clog_one_right (b : ℕ) : clog b 1 = 0 :=\nclog_of_right_le_one le_rfl _\n\nlemma clog_of_two_le {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) :\n  clog b n = clog b ((n + b - 1)/b) + 1 :=\nby rw [clog, if_pos (⟨hb, hn⟩ : 1 < b ∧ 1 < n)]\n\nlemma clog_pos {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : 0 < clog b n :=\nby { rw clog_of_two_le hb hn, exact zero_lt_succ _ }\n\nlemma clog_eq_one {b n : ℕ} (hn : 2 ≤ n) (h : n ≤ 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 [←lt_succ_iff, nat.div_lt_iff_lt_mul (n_pos.trans_le h), ←succ_le_iff,\n    ←pred_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 : ℕ} (hb : 1 < b) {x y : ℕ} : x ≤ b ^ y ↔ clog b x ≤ y :=\nbegin\n  induction x using nat.strong_induction_on with x ih generalizing y,\n  cases y,\n  { rw [pow_zero],\n    refine ⟨λ h, (clog_of_right_le_one h b).le, _⟩,\n    simp_rw ←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  { rw [succ_eq_add_one, add_le_add_iff_right, ←ih ((x + b - 1)/b) (add_pred_div_lt hb h.2),\n      nat.div_le_iff_le_mul_add_pred b_pos,\n      ← 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 : ℕ} (hb : 1 < b) {x y : ℕ} : b ^ y < x ↔ y < clog b x :=\nlt_iff_lt_of_le_iff_le (le_pow_iff_clog_le hb)\n\nlemma clog_pow (b x : ℕ) (hb : 1 < b) : clog b (b ^ x) = x :=\neq_of_forall_ge_iff $ λ z,\nby { rw ←le_pow_iff_clog_le hb, exact (pow_right_strict_mono hb).le_iff_le }\n\nlemma pow_pred_clog_lt_self {b : ℕ} (hb : 1 < b) {x : ℕ} (hx : 1 < x) :\n  b ^ (clog b x).pred < x :=\nbegin\n  rw [←not_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 : ℕ} (hb : 1 < b) (x : ℕ) : x ≤ b ^ clog b x :=\n(le_pow_iff_clog_le hb).2 le_rfl\n\n@[mono] lemma clog_mono_right (b : ℕ) {n m : ℕ} (h : n ≤ m) : clog b n ≤ 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 ←le_pow_iff_clog_le hb,\n    exact h.trans (le_pow_clog hb _) }\nend\n\n@[mono] lemma clog_anti_left {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : clog b n ≤ clog c n :=\nbegin\n  rw ← le_pow_iff_clog_le (lt_of_lt_of_le hc hb),\n  calc\n    n ≤ c ^ clog c n : le_pow_clog hc _\n  ... ≤ b ^ clog c n : pow_le_pow_of_le_left (zero_lt_one.trans hc).le hb _\nend\n\nlemma clog_monotone (b : ℕ) : monotone (clog b) :=\nλ x y, clog_mono_right _\n\nlemma clog_antitone_left {n : ℕ} : antitone_on (λ b : ℕ, clog b n) (set.Ioi 1) :=\nλ _ hc _ _ hb, clog_anti_left (set.mem_Iio.1 hc) hb\n\nlemma log_le_clog (b n : ℕ) : log b n ≤ 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 b n.succ_ne_zero).trans $\n    le_pow_clog hb _),\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/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526934, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.796944259786783}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\n\n# Proposition world.\n\n## Level 4: `apply`.\n\nLet's do the same level again a different way:\n\n![diagram](../assets/propositions_diag.svg)\n\nWe are given a proof `p` of `P` and our goal is to find a proof of `U`, or\nin other words to find a path through the maze that links `P` to `U`.\nIn level 3 we solved this by using `have`s to move forward, from `P`\nto `Q` to `T` to `U`. Using the `apply` tactic we can instead construct\nthe path backwards, moving from `U` to `T` to `Q` to `P`.\n\nOur goal is to prove `U`. But `l:T ⟹ U` is\nan implication which we are assuming, so it would suffice to prove `T`.\nTell Lean this by starting the proof below with\n\n`apply l,`\n\nand notice that our assumptions don't change but *the goal changes*\nfrom `⊢ U` to `⊢ T`.\n\nKeep `apply`ing implications until your goal is `P`, and try not\nto get lost! Now solve this goal\nwith `exact p`. Note: you will need to learn the difference between\n`exact p` (which works) and `exact P` (which doesn't, because `P` is\nnot a proof of `P`).\n\n## Lemma : maze₂\nWe can solve a maze.\n-/\nlemma maze₂ (P Q R S T U: Prop)\n(p : P)\n(h : P → Q)\n(i : Q → R)\n(j : Q → T)\n(k : S → T)\n(l : T → U)\n: U := by\n  apply l\n  apply j\n  apply h\n  exact p\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/PropositionWorld/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7968710730614667}}
{"text": "/- Even and odd natural numbers. -/\n\nimport data.nat.modeq\nimport ent.basic\nimport ent.modeq\nimport ent.xor\n\nnamespace nat\n\n-- * Definition\n\ndef even (a : ℕ) := a ≡ 0 [MOD 2]\ndef odd (a : ℕ) := a ≡ 1 [MOD 2]\n\ninstance decidable_even {a : ℕ} : decidable (even a) :=\n  by unfold even; apply_instance\ninstance decidable_odd {a : ℕ} : decidable (odd a) :=\n  by unfold odd; apply_instance\n\n-- * Basic facts\n\ntheorem even_iff_two_dvd {a : ℕ} : even a ↔ 2 ∣ a := modeq.modeq_zero_iff\n\ntheorem even_or_odd (a : ℕ) : even a ∨ odd a :=\n  mod_two_eq_zero_or_one a\n\ntheorem not_even_and_odd (a : ℕ) : ¬ (even a ∧ odd a) :=\n  λ ⟨ea, oa⟩,\n  have h : 0 ≡ 1 [MOD 2] := ea.symm.trans oa,\n  (dec_trivial : ¬ (0 ≡ 1 [MOD 2])) h\n\ntheorem even_xor_odd {a : ℕ} : xor (even a) (odd a) :=\n  xor.mk (even_or_odd a) (not_even_and_odd a)\n\ntheorem odd_plus_odd_is_even {a b : ℕ} : odd a → odd b → even (a + b) :=\n  modeq.modeq_add\n\ntheorem odd_plus_even_is_odd {a b : ℕ} : odd a → even b → odd (a + b) :=\n  modeq.modeq_add\n\ntheorem even_plus_odd_is_odd {a b : ℕ} : even a → odd b → odd (a + b) :=\n  modeq.modeq_add\n\ntheorem odd_minus_odd_is_even {a b : ℕ} (H : a ≤ b) : odd a → odd b → even (b - a) :=\n  begin\n    intros oa ob,\n    cases even_or_odd (b - a) with eba oba,\n    { assumption },\n    { have h : even (a + (b - a)) := odd_plus_odd_is_even oa oba,\n      rw add_sub_of_le H at h,\n      have := and.intro h ob,\n      have := not_even_and_odd b,\n      contradiction }\n  end\n\ntheorem even_times_any_is_even {a b : ℕ} : even a → even (a * b) := λ ea,\n  even_iff_two_dvd.mpr $ dvd.trans (even_iff_two_dvd.mp ea) (dvd_mul_right a b)\n\ntheorem two_n_even (n : ℕ) : even (2 * n) :=\n  even_times_any_is_even (dec_trivial : 2 ≡ 0 [MOD 2])\n\ntheorem two_n_not_odd (n : ℕ) : ¬ (odd (2 * n)) :=\n  even_xor_odd.resolve_right.mpr (two_n_even n)\n\ntheorem odd_times_odd_is_odd {a b : ℕ} : odd a → odd b → odd (a * b) := modeq.modeq_mul\n\ntheorem even_square_is_even {a : ℕ} : even a → even (a^2) :=\n  by rw pow_two; apply even_times_any_is_even\n\ntheorem odd_square_is_odd {a : ℕ} : odd a → odd (a^2) := begin\n  intro oa,\n  rw pow_two,\n  exact (odd_times_odd_is_odd oa oa)\nend\n\ntheorem even_iff_square_even {a : ℕ} : even a ↔ even (a^2) :=\n  iff.intro even_square_is_even\n  (even_xor_odd.resolve_right.mp ∘ mt odd_square_is_odd ∘\n   even_xor_odd.resolve_right.mpr)\n\ntheorem odd_iff_square_odd {a : ℕ} : odd a ↔ odd (a^2) :=\n  iff.intro odd_square_is_odd\n  (even_xor_odd.resolve_left.mp ∘ mt even_square_is_even ∘\n   even_xor_odd.resolve_left.mpr)\n\n/- This is longer anyways \ntheorem odd_iff_square_odd {a : ℕ} : odd a ↔ odd (a^2) := \ncalc odd a ↔ ¬ even a      : even_xor_odd.resolve_left.symm\n     ...   ↔ ¬ even (a^2)  : not_congr even_iff_square_even\n     ...   ↔ odd (a^2)     : even_xor_odd.resolve_left\n-/\n\ntheorem not_both_even_if_coprime {a b : ℕ} : coprime a b → ¬ (even a ∧ even b)\n  := begin\n  intros a_b eab, cases eab with ea eb,\n  rw even_iff_two_dvd at ea eb,\n  have := not_coprime_of_dvd_of_dvd dec_trivial ea eb, contradiction\nend\n\nend nat\n\n\n\nopen nat\n\n-- * Squares of even and odd numbers mod 4\n\nlemma odd_number_lemma {a : ℕ} (o : odd a) : ∃ k : ℕ, a = 2*k + 1 := modeq.rep_of_modeq o dec_trivial\n\nlemma odd_square_lemma {k : ℕ} : (2*k+1)^2 = 4*(k*k + k) + 1 := \n  calc\n    (2*k+1)^2 = (2*k + 1) * (2*k + 1)     : by rw nat.pow_two\n    ...       = 2*k * (2*k + 1) + 1 * (2*k + 1) : by rw right_distrib\n    ...       = 2*k * (2*k + 1) + 2*k + 1 : by simp\n    ...       = 2*k * (2*k) + 2*k * 1 + 2*k + 1 : by rw left_distrib\n    ...       = 2*k*2*k + 2*k * 1 + 2*k + 1   : by rw ←mul_assoc\n    ...       = 2*k*2*k + 2*k + 2*k + 1   : by simp\n    ...       = 2*(k*2)*k + 2*k + 2*k + 1 : by rw ←mul_assoc\n    ...       = 2*(2*k)*k + 2*k + 2*k + 1 : by rw (mul_comm k 2)\n    ...       = 2*2*k*k + 2*k + 2*k + 1   : by rw ←mul_assoc\n    ...       = 4*k*k + 2*k + 2*k + 1     : by refl\n    ...       = 4*k*k + (2*k + 2*k) + 1   : by rw (add_assoc (4*k*k) (2*k) (2*k))\n    ...       = 4*k*k + (2 + 2)*k + 1     : by rw (right_distrib 2 2 k)\n    ...       = 4*k*k + 4*k + 1           : by refl\n    ...       = 4*(k*k) + 4*k + 1         : by rw mul_assoc\n    ...       = 4*(k*k + k) + 1           : by rw left_distrib\n\ntheorem odd_square_mod_four {a : ℕ} : odd a → a^2 ≡ 1 [MOD 4] :=\n  begin\n    intro o,\n    cases modeq.rep_of_modeq o dec_trivial with k,\n    rw [h, odd_square_lemma],\n    apply modeq.modeq_of_rep\n  end\n\ntheorem even_square_mod_four {a : ℕ} : even a → a^2 ≡ 0 [MOD 4] :=\n  begin\n    intro e,\n    rw modeq.modeq_zero_iff,\n    have h : 2 ∣ a := begin rw ←modeq.modeq_zero_iff, assumption end,\n    have h2 : 4 ∣ a^2 := begin\n      rw nat.pow_two,\n      apply (mul_dvd_mul h h)\n    end,\n    assumption\n  end\n\ntheorem square_two_mod_four {a : ℕ} : ¬ (a^2 ≡ 2 [MOD 4]) :=\n  begin\n    intro,\n    cases even_or_odd a,\n    { have h1 : 2 ≡ 0 [MOD 4] :=\n        modeq.trans (modeq.symm a_1) (even_square_mod_four h),\n      have h2 : ¬ (2 ≡ 0 [MOD 4]) := dec_trivial,\n      exact h2 h1 },\n    { have h1 : 2 ≡ 1 [MOD 4] :=\n        modeq.trans (modeq.symm a_1) (odd_square_mod_four h),\n      have h2 : ¬ (2 ≡ 1 [MOD 4]) := dec_trivial,\n      exact h2 h1 }\n  end\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172608760225, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7968380545651268}}
{"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# The real numbers in Lean\n\nLean has a copy of of the real numbers. It's called `real`, \nbut we use the usual notation `ℝ`. Put your cursor on the `ℝ` to find\nout how to type it in VS Code.\n\nIn this sheet you will prove some basic equalities and inequalities\nbetween \"numerical expressions\" in Lean. A numeral is something like `37`,\nand a numerical expression is something like `(37 + 6) / 4`. To make\nthings a bit harder, I will throw in some `∃` statements. To make\nprogress on an `∃` goal, use the `use` tactic.\n\n## Tactics\n\nNew tactics you'll need to know about:\n\n* `norm_num` (proves equalities and inequalities involving numerical expressions)\n* `use` (if the goal is `∃ x, x + 37 = 42` then `use 8` will change the goal\n*        to `8 + 37 = 42`, and `use 10` will change it to `10 + 37 = 42`.\n\n-/\n\nexample : (2 : ℝ) + 2 = 4 :=\nbegin\n  norm_num,\nend\n\nexample : (2 : ℝ) + 2 ≠ 5 :=\nbegin\n  norm_num,\nend\n\nexample : (2 : ℝ) + 2 < 5 :=\nbegin\n  norm_num,\nend\n\nexample : ∃ (x : ℝ), 3 * x + 7 = 12 :=\nbegin\n  use 5/3,\n  norm_num,\nend\n\nexample : ∃ (x : ℝ), 3 * x + 7 ≠ 12 :=\nbegin\n  use 3,\n  norm_num,\nend\n\nexample : ∃ (x y : ℝ), 2 * x + 3 * y = 7 ∧ x + 2 * y = 4 :=\nbegin\n  use [2, 1],\n  split;\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/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172615983308, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7968380494627673}}
{"text": "import tactic -- hide\nimport data.real.basic -- hide\n\n/-\n## Divisibility of an obvious multiple\n\nRecall that a natural number $d$ divides another one $n$ if there is some $t$\nsuch that $n = dt$. Below you have the *Lean* definition:\n-/\nlemma divides_def {d n : ℕ} : d ∣ n ↔ ∃ t, n = d * t\n:= iff.rfl -- hide\n\n/- Axiom : divides_def\nd ∣ n ↔ ∃ t, n = d * t\n-/\n\n\n/-\nThe following useful lemma just says that any natural number divides\na multiple of itself, and its proof should just be one or two lines.\n-/\n\n\n\n\n/- Lemma :\nEvery natural number $k$ divides $k \\cdot r$\n-/\nlemma divides_mul_left {k k' r : ℕ} : (k ∣ k') → k ∣ k' * r :=\nbegin\n  intro h,\n  cases h with s hs,\n  use r * s,\n  rw hs,\n  ring,\n\n  \nend\n\nlemma divides_mul_right {k k' r : ℕ} : (k ∣ k') → (k ∣ r * k') := by {rw mul_comm, exact divides_mul_left} -- hide\n\n/- Axiom : divides_mul_right\nk ∣ k' → k ∣ r * k'\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_mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172601537141, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7968380482496735}}
{"text": "-- import the definitions of uniform space via entourages\nimport uniform_structure.entourages\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 collection of entourages for X \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 → X → ℝ) [is_pseudometric d]\n\n-- Define U ⊆ X × X to be an entourage if there exists ε > 0 such\n-- that d(x,y)≤ε → (x,y) ∈ U\n\ndef entourages :=\n  {U : set (X × X) | ∃ ε > 0, ∀ x y : X, d x y ≤ ε → (x,y) ∈ U}\n\n-- this lemma is true by definition\nlemma mem_entourages (U : set (X × X)) :\n  U ∈ entourages d ↔ ∃ ε > 0, ∀ x y : X, d x y ≤ ε → (x,y) ∈ U := iff.rfl \n\n-- The exerise is to show that the 5 axioms of a uniform space are\n-- satisfied.\n\n-- Hint: You can `rw mem_entourages` to change from `U ∈ entourages d` to the\n-- explicit epsilon definition.\n\n-- Hint: if `hU : U ∈ entourages d` then `obtain ⟨ε, hε, hεU⟩ := hU` will\n-- get you the ε which is a witness to U being an entourage for d.\n\n-- Axiom 1: the diagonal is in U\nlemma refl (U : set (X × X)) (hU : U ∈ entourages d) :\n  ∀ (x : X), (x, x) ∈ U :=\nbegin\n  sorry\nend\n\n-- Axiom 2: anything bigger than an entourage is an entourage\nlemma bigger (U V : set (X × X)) (hU : U ∈ entourages d) (hUV : U ⊆ V) :\n  V ∈ entourages d :=\nbegin\n  sorry\nend\n\n-- Axiom 3: Intersection of two entourages is an entourage\nlemma inter (U V : set (X × X)) (hU : U ∈ entourages d) (hV : V ∈ entourages d) :\n  U ∩ V ∈ entourages d :=\nbegin\n  sorry\nend\n\n-- Axiom 4: the \"square root\" axiom. \n-- You'll need `mem_comp_ent` here (defined in the entourages file)\nlemma comp (U : set (X × X)) (hU : U ∈ entourages d) :\n ∃ (V : set (X × X)) (H : V ∈ entourages d), V ∘ V ⊆ U :=\nbegin\n  sorry\nend\n\n-- Axiom 5: the \"transpose\" axiom.\nlemma symm (U : set (X × X)) (hU : U ∈ entourages d) :\n  {z : X × X | (z.snd, z.fst) ∈ U} ∈ entourages d :=\nbegin\n  sorry\nend\n \ndefinition to_entourages : uniform_space_entourage X :=\n{ entourages := entourages d,\n  refl := refl d,\n  bigger := bigger d,\n  inter := inter d,\n  comp := comp d,\n  symm := symm 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/exercises/entourages_from_pseudometric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.865224091265267, "lm_q1q2_score": 0.7966894086885029}}
{"text": "-- real numbers\nimport data.real.basic\n\n-- useful lemmas\nimport xenalib.M1F.help_for_0107\n\nnoncomputable theory\n\ndef A : set ℝ := { x | x^2 < 3}\ndef B : set ℝ := { x | x^2 < 3 ∧ ∃ y : ℤ, x = y}\ndef C : set ℝ := { x | x^3 < 3}\n\ndefinition real_half := (1 / 2 : ℝ)\n-- useful lemmas\n\ndefinition B_is_minus_one_zero_one : ∀ {x : ℝ}, x ∈ B ↔ x = -1 ∨ x = 0 ∨ x = 1\n:= Q0107.B_is_minus_one_zero_one\n\ndefinition real_half_not_in_B : real_half ∉ B\n:= Q0107.real_half_not_in_B\n\n-- For each part x, prove exactly one of part_x_true and\n-- part_x_false, and comment out the other one!\n\ntheorem part_a_true : (1/2 : ℝ) ∈ A ∩ B := sorry\ntheorem part_a_false : ¬ (1/2 : ℝ) ∈ A ∩ B := sorry\ntheorem part_b_true : (1/2 : ℝ) ∈ A ∪ B := sorry\ntheorem part_b_false : ¬ (1/2 : ℝ) ∈ A ∪ B := sorry\ntheorem part_c_true : A ⊆ C := sorry\ntheorem part_c_false : ¬ A ⊆ C := sorry\ntheorem part_d_true : B ⊆ C := sorry\ntheorem part_d_false : ¬ B ⊆ C := sorry\ntheorem part_e_true : C ⊆ A ∪ B := sorry\ntheorem part_e_false : ¬ C ⊆ A ∪ B := sorry\ntheorem part_f_true : (A ∩ B) ∪ C = (A ∪ B) ∩ C := sorry\ntheorem part_f_false : ¬ (A ∩ B) ∪ C = (A ∪ B) ∩ C := 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/0107/0107Q.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7966893993691715}}
{"text": "import ..lovelib\nimport ..lectures.love01_definitions_and_statements_demo\n\n\n/-! # LoVe Homework 5: Inductive Predicates and Big Step Semantics\n\nHomework must be done individually. \n\nThis homework combines material from Ch. 5 and part of Ch. 8 of the Hitchhiker's Guide.\n-/\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! \n## Chapter 5: Inductive Predicates\n\n## Question 1 (3 points + 1 bonus point): A Type of λ-Terms\n\nRecall the type of λ-terms from question 3 of exercise 4: -/\n\ninductive term : Type\n| var : string → term\n| lam : string → term → term\n| app : term → term → term\n\n/-! 1.1 (1 point). Define an inductive predicate `is_lam` that returns `true` if\nits argument is of the form `term.lam …` and that returns false otherwise. -/\n\n-- enter your definition here\n\n/-! 1.2 (2 points). Validate your answer to question 1.1 by proving the following\nlemmas: -/\n\nlemma is_lam_lam (s : string) (t : term) :\n  is_lam (term.lam s t) :=\nsorry\n\nlemma not_is_lam_var (s : string) :\n  ¬ is_lam (term.var s) :=\nsorry\n\nlemma not_is_lam_app (t u : term) :\n  ¬ is_lam (term.app t u) :=\nsorry\n\n/-! 1.3 (1 bonus point). Define an inductive predicate `is_βnf` that determines\nwhether a λ-term is in β-normal form. A λ-term is in β-normal form if it\ncontains no subterm of the form `(λx, t) u`, i.e., a λ-expression applied to an\nargument. Another way to characterize the β-normal form is to say that no\nβ-reduction is possible in the term.\n\nHint: Use `is_lam` somewhere. -/\n\n-- enter your definition here\n\n\n/-! ## Question 2 (4 points): Transitive Closure\n\nIn mathematics, the transitive closure `R⁺` of a binary relation `R` over a\nset `A` can be defined as the smallest solution satisfying the following rules:\n\n    (base) for all `a, b ∈ A`, if `a R b`, then `a R⁺ b`;\n    (step) for all `a, b, c ∈ A`, if `a R b` and `b R⁺ c`, then `a R⁺ c`.\n\nIn Lean, we can define this notion as follows, by identifying the set `A` with\nthe type `α`: -/\n\ninductive tc_v1 {α : Type} (r : α → α → Prop) : α → α → Prop\n| base {a b : α}   : r a b → tc_v1 a b\n| step {a b c : α} : r a b → tc_v1 b c → tc_v1 a c\n\n/-! 2.1 (1 point). Rule `(step)` makes it convenient to extend transitive chains\nby adding links to the left. Another way to define the transitive closure `R⁺`\nwould use replace `(step)` with the following right-leaning rule:\n\n    (pets) for all `a, b, c ∈ A`, if `a R⁺ b` and `b R c`, then `a R⁺ c`.\n\nDefine a predicate `tc_v2` that embodies this alternative definition. -/\n\n-- enter your definition here\n\n/-! 2.2 (1 point). Yet another definition of the transitive closure `R⁺` would\nuse the following symmetric rule instead of `(step)` or `(pets)`:\n\n    (trans) for all `a, b, c ∈ A`, if `a R⁺ b` and `b R⁺ c`, then `a R⁺ c`.\n\nDefine a predicate `tc_v3` that embodies this alternative definition. -/\n\n-- enter your definition here\n\n/-! 2.3 (1 point). Prove that `(step)` also holds as a lemma about `tc_v3`. -/\n\nlemma tc_v3_step {α : Type} (r : α → α → Prop) (a b c : α) (rab : r a b)\n    (tbc : tc_v3 r b c) :\n  tc_v3 r a c :=\nsorry\n\n/-! 2.4 (1 point). Prove the following lemma by rule induction: -/\n\nlemma tc_v1_pets {α : Type} (r : α → α → Prop) (c : α) :\n  ∀a b, tc_v1 r a b → r b c → tc_v1 r a c :=\nsorry\n\n\n/-! ## Question 3 (5 points): Arithmetic expressions\n\nRecall the type of arithmetic expressions from lecture 1 and its evaluation\nfunction: -/\n\n#check aexp\n#check eval\n\n/-! Let us introduce the following abbreviation for an environment that maps\nvariable names to values: -/\n\ndef envir : Type :=\nstring → ℤ\n\n/-! 3.1 (2 points). Complete the following Lean definition of a big-step-style\nsemantics for arithmetic expressions. The predicate `big_step` (`⟹`) relates\nan arithmetic expression, an environment, and the value to which it the\nexpression evaluates in the given environment: -/\n\ninductive big_step : aexp × envir → ℤ → Prop\n| num {i env} : big_step (aexp.num i, env) i\n\ninfix ` ⟹ ` : 110 := big_step\n\n/-! 3.2 (1 point). Prove the following lemma to validate your definition\nabove. -/\n\nlemma big_step_add_two_two (env : envir) :\n  (aexp.add (aexp.num 2) (aexp.num 2), env) ⟹ 4 :=\nsorry\n\n/-! 3.3 (2 points). Prove that the big-step semantics is sound with respect to\nthe `eval` function: -/\n\nlemma big_step_sound (env : envir) (a : aexp) (i : ℤ) :\n  (a, env) ⟹ i → eval env a = i :=\nsorry\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/love05_inductive_predicates_and_big_step_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8918110526265554, "lm_q1q2_score": 0.796663204267624}}
{"text": "import NNG.Metadata\n\nLevel 4\n\nTitle \"Addition\"\n\nIntroduction\n\"\nPeano defined addition `a + b` by induction on `b`, or,\nmore precisely, by *recursion* on `b`. He first explained how to add 0 to a number:\nthis is the base case.\n\n* `add_zero (a : ℕ) : a + 0 = a`\n\nWe will call this theorem `add_zero`. It has just appeared in your inventory!\nMathematicians sometimes call it \\\"Lemma 2.1\\\" or \\\"Hypothesis P6\\\" or something. But\ncomputer scientists call it `add_zero` because it tells you\nwhat the answer to \\\"$x$ add zero\\\" is. It's a *much* better name than \\\"Lemma 2.1\\\".\nEven better, we can use the rewrite tactic with `add_zero`.\nIf you ever see `x + 0` in your goal, `rewrite [add_zero]` will simplify it to `x`.\nThis is because `add_zero` is a proof that `x + 0 = x` (more precisely,\n`add_zero x` is a proof that `x + 0 = x` but Lean can figure out the `x` from the context).\n\nNow here's the inductive step. If you know how to add `d` to `a`, then\nPeano tells you how to add `succ(d)` to `a`. It looks like this:\n\n* `add_succ (a d : ℕ) : a + succ(d) = succ (a + d)`\n\nWhat's going on here is that we assume `a + d` is already\ndefined, and we define `a + succ(d)` to be the number after it.\nThis is also in your inventory now -- `add_succ` tells you\nhow to add a successor to something. If you ever see `... + succ ...`\nin your goal, you should be able to use `rewrite [add_succ]` to make\nprogress. Here is a simple example where we shall see both. Let's prove\nthat $x$ add the number after $0$ is the number after $x$.\n\nObserve that the goal mentions `... + succ ...`. So type\n\n`rewrite [add_succ]`\n\nand hit enter; see the goal change.\n\"\n\nStatement (a : ℕ ) : a + succ 0 = succ a := by\n  rewrite [add_succ]\n  rewrite [add_zero]\n  rfl\n\nMessage (a : ℕ) : succ (a + 0) = succ a  => \"\nDo you see that the goal now mentions ` ... + 0 ...`? So type\n\n`rewrite [add_zero]`\n\nand try to finish the level alone from there.\n\"\n\nConclusion \"Congratulations for completing your fourth level! This is the end of the tutorial part\nof the game. Serious things start in the next level.\"\n\nTactics rfl rewrite\n\nLemmas add_succ add_zero", "meta": {"author": "PatrickMassot", "repo": "NNG4", "sha": "b321d99e5538d79a6ce9f494f343ca8c30d7ba7a", "save_path": "github-repos/lean/PatrickMassot-NNG4", "path": "github-repos/lean/PatrickMassot-NNG4/NNG4-b321d99e5538d79a6ce9f494f343ca8c30d7ba7a/NNG/Levels/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.95598134762883, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7966427637028751}}
{"text": "variable (α : Type) (p q : α → Prop)\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\n  have h_lhs : (∀ x, p x ∧ q x) → (∀ x, p x) ∧ (∀ x, q x) :=\n    (fun h : (∀ x, p x ∧ q x) => \n      And.intro\n      (fun y : α =>\n          (show (p y) from (h y).left))\n      (fun y : α =>\n          (show (q y) from (h y).right)))\n  have h_rhs :  (∀ x, p x) ∧ (∀ x, q x) → (∀ x, p x ∧ q x):=\n    (fun h : (∀ x, p x) ∧ (∀ x, q x) =>\n      (fun y : α =>\n        And.intro ((And.left h) y) ((And.right h) y)))\n  Iff.intro h_lhs h_rhs\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\n  fun f : (∀ x, p x → q x) =>\n  fun g : (∀ x, p x) =>\n  (fun y : α =>\n    (f y) (g y))\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\n  fun f : (∀ x, p x) ∨ (∀ x, q x) =>\n  (fun y : α => \n    Or.elim f\n      (fun f1 : (∀ x, p x) => \n        Or.inl (f1 y))\n      (fun f2 : (∀ x, q x) => \n        Or.inr (f2 y)))\n\nexample : ∃ 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) : ∃ y, y < x :=\n  Exists.intro 0 h\n\n#check @Exists.intro\n\nvariable (α : Type) (p q : α → Prop)\n\nexample (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x:=\n  Exists.elim h\n    (fun w =>\n      (fun hw : p w ∧ q w =>\n        Exists.intro w (And.intro hw.right hw.left)))\n\ndef is_even (a : Nat) := ∃ b, a = 2 * b\n\ntheorem even_plus_even (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n  match h1, h2 with\n  | ⟨w1, hw1⟩, ⟨w2, hw2⟩ => ⟨w1 + w2 , by rw [hw1, hw2, Nat.mul_add]⟩\n", "meta": {"author": "huckkim", "repo": "Leaning4U", "sha": "2c26849408fcca85c0d7354e18b876c703bc733c", "save_path": "github-repos/lean/huckkim-Leaning4U", "path": "github-repos/lean/huckkim-Leaning4U/Leaning4U-2c26849408fcca85c0d7354e18b876c703bc733c/quantifiers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541593883189, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7965852220093353}}
{"text": "/-\nCopyright (c) 2020 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey\n-/\nimport data.fintype.basic\nimport group_theory.order_of_element\nimport tactic.zify\nimport data.nat.totient\n\n/-!\n# The Lucas test for primes.\n\nThis file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for\nMersenne primes). A number `a` witnesses that `n` is prime if `a` has order `n-1` in the\nmultiplicative group of integers mod `n`. This is checked by verifying that `a^(n-1) = 1 (mod n)`\nand `a^d ≠ 1 (mod n)` for any divisor `d | n - 1`. This test is the basis of the Pratt primality\ncertificate.\n\n## TODO\n\n- Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness.\n  Use `units.is_cyclic` from `ring_theory/integral_domain` to show the group is cyclic.\n- Write a tactic that uses this theorem to generate Pratt primality certificates\n- Integrate Pratt primality certificates into the norm_num primality verifier\n\n## Implementation notes\n\nNote that the proof for `lucas_primality` relies on analyzing the multiplicative group\nmodulo `p`. Despite this, the theorem still holds vacuously for `p = 0` and `p = 1`: In these\ncases, we can take `q` to be any prime and see that `hd` does not hold, since `a^((p-1)/q)` reduces\nto `1`.\n-/\n\n/--\nIf `a^(p-1) = 1 mod p`, but `a^((p-1)/q) ≠ 1 mod p` for all prime factors `q` of `p-1`, then `p`\nis prime. This is true because `a` has order `p-1` in the multiplicative group mod `p`, so this\ngroup must itself have order `p-1`, which only happens when `p` is prime.\n-/\ntheorem lucas_primality (p : ℕ) (a : zmod p) (ha : a^(p-1) = 1)\n  (hd : ∀ q : ℕ, q.prime → q ∣ (p-1) → a^((p-1)/q) ≠ 1) : p.prime :=\nbegin\n  have h0 : p ≠ 0, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },\n  have h1 : p ≠ 1, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },\n  have hp1 : 1 < p := lt_of_le_of_ne h0.bot_lt h1.symm,\n  have order_of_a : order_of a = p-1,\n  { apply order_of_eq_of_pow_and_pow_div_prime _ ha hd,\n    exact tsub_pos_of_lt hp1, },\n  haveI : ne_zero p := ⟨h0⟩,\n  rw nat.prime_iff_card_units,\n  -- Prove cardinality of `units` of `zmod p` is both `≤ p-1` and `≥ p-1`\n  refine le_antisymm (nat.card_units_zmod_lt_sub_one hp1) _,\n  have hp' : p - 2 + 1 = p - 1 := tsub_add_eq_add_tsub hp1,\n  let a' : (zmod p)ˣ := units.mk_of_mul_eq_one a (a ^ (p-2)) (by rw [←pow_succ, hp', ha]),\n  calc p - 1 = order_of a : order_of_a.symm\n  ... = order_of a' : order_of_injective (units.coe_hom (zmod p)) units.ext a'\n  ... ≤ fintype.card (zmod p)ˣ : order_of_le_card_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/number_theory/lucas_primality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7965852151927209}}
{"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 data.indicator_function\nimport analysis.normed_space.basic\n\n/-!\n# Indicator function and norm\n\nThis file contains a few simple lemmas about `set.indicator` and `norm`.\n\n## Tags\nindicator, norm\n-/\n\nvariables {α E : Type*} [normed_group E] {s t : set α} (f : α → E) (a : α)\n\nopen set\n\nlemma norm_indicator_eq_indicator_norm :\n  ∥indicator s f a∥ = indicator s (λa, ∥f a∥) a :=\nflip congr_fun a (indicator_comp_of_zero norm_zero).symm\n\nlemma nnnorm_indicator_eq_indicator_nnnorm :\n  nnnorm (indicator s f a) = indicator s (λa, nnnorm (f a)) a :=\nflip congr_fun a (indicator_comp_of_zero nnnorm_zero).symm\n\nlemma norm_indicator_le_of_subset (h : s ⊆ t) (f : α → E) (a : α) :\n  ∥indicator s f a∥ ≤ ∥indicator t f a∥ :=\nbegin\n  simp only [norm_indicator_eq_indicator_norm],\n  exact indicator_le_indicator_of_subset ‹_› (λ _, norm_nonneg _) _\nend\n\nlemma indicator_norm_le_norm_self : indicator s (λa, ∥f a∥) a ≤ ∥f a∥ :=\nindicator_le_self' (λ _ _, norm_nonneg _) a\n\nlemma norm_indicator_le_norm_self : ∥indicator s f a∥ ≤ ∥f a∥ :=\nby { rw norm_indicator_eq_indicator_norm, apply indicator_norm_le_norm_self }\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/indicator_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.7965512981170001}}
{"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 18a5306c091183ac90884daa9373fa3b178e8607\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.Init.Data.Nat.Bitwise\n/-! # A recursion principle based on even and odd numbers. -/\n\n-- porting note: TODO:\n-- Remove dependence on deprecated defintions bit0, bit1.\nset_option linter.deprecated false\n\nnamespace Nat\n\n/-- Recursion principle on even and odd numbers: if we have `P 0`, and for all `i : ℕ` we can\nextend from `P i` to both `P (2 * i)` and `P (2 * i + 1)`, then we have `P n` for all `n : ℕ`.\nThis is nothing more than a wrapper around `Nat.binaryRec`, to avoid having to switch to\ndealing with `bit0` and `bit1`. -/\n\n@[elab_as_elim]\ndef evenOddRec {P : ℕ → Sort _} (h0 : P 0) (h_even : ∀ (n) (_ : P n), P (2 * n))\n    (h_odd : ∀ (n) (_ : P n), P (2 * n + 1)) (n : ℕ) : P n :=\n  binaryRec h0 (fun\n    | false, i, hi => (bit0_val i ▸ h_even i hi : P (bit0 i))\n    | true, i, hi => (bit1_val i ▸ h_odd i hi : P (bit1 i))) n\n#align nat.even_odd_rec Nat.evenOddRec\n\n@[simp]\ntheorem evenOddRec_zero (P : ℕ → Sort _) (h0 : P 0) (h_even : ∀ i, P i → P (2 * i))\n    (h_odd : ∀ i, P i → 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@[simp]\ntheorem evenOddRec_even (n : ℕ) (P : ℕ → Sort _) (h0 : P 0) (h_even : ∀ i, P i → P (2 * i))\n    (h_odd : ∀ i, P i → 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  have : ∀ a, bit false n = a →\n      HEq (@evenOddRec _ h0 h_even h_odd a) (h_even n (evenOddRec h0 h_even h_odd n))\n    | _, rfl => by rw [evenOddRec, binaryRec_eq]; apply eq_rec_heq; exact H\n  eq_of_heq (this _ (bit0_val _))\n#align nat.even_odd_rec_even Nat.evenOddRec_even\n\n@[simp]\ntheorem evenOddRec_odd (n : ℕ) (P : ℕ → Sort _) (h0 : P 0) (h_even : ∀ i, P i → P (2 * i))\n    (h_odd : ∀ i, P i → 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  have : ∀ a, bit true n = a →\n      HEq (@evenOddRec _ h0 h_even h_odd a) (h_odd n (evenOddRec h0 h_even h_odd n))\n    | _, rfl => by rw [evenOddRec, binaryRec_eq]; apply eq_rec_heq; exact H\n  eq_of_heq (this _ (bit1_val _))\n#align nat.even_odd_rec_odd Nat.evenOddRec_odd\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/EvenOddRec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8962513710552469, "lm_q1q2_score": 0.796551281923494}}
{"text": "import tactic\nimport data.nat.basic\nimport data.nat.prime\n\nnoncomputable theory\nopen_locale classical\n\nlemma two_dvd_of_two_dvd_sq {n : ℕ} (hn : 2 ∣ n ^ 2) : 2 ∣ n :=\nbegin\n  apply nat.prime.dvd_of_dvd_pow, \n  { exact nat.prime_two },\n  exact hn,\nend\n\nlemma two_dvd_of_two_dvd_sq' {m n : ℕ} (hmn : 2 * m ^ 2 = n ^ 2) : 2 ∣ n :=\nbegin\n  apply two_dvd_of_two_dvd_sq,\n  use m^2, rw hmn,\nend\n\nexample (a b c : ℕ) (hc : 0 < c) (h : c * a = c * b) : a = b :=\nbegin\n  -- library_search succeeds here\n  rwa nat.mul_right_inj at h, \n  assumption,\nend\n\nlemma two_dvd_of_two_dvd_sq'' {m n : ℕ} (hmn : 2 * m ^ 2 = n ^ 2) : 2 ∣ m :=\nbegin\n  apply two_dvd_of_two_dvd_sq,\n  have hn := two_dvd_of_two_dvd_sq' hmn,\n  cases hn with k hk,\n  use k^2, \n  rw hk at hmn, clear hk,\n  have : 0 < 2 := by norm_num,\n  rw ← nat.mul_right_inj this, \n  ring at hmn, ring, assumption,\nend\n\n\n\nlemma gcd_div_left (a b : ℕ) : (nat.gcd a b) ∣ a :=\nbegin\n  rw nat.gcd_eq_right_iff_dvd,\n  apply nat.gcd_gcd_self_right_left,\nend\n\n\n-- maynbe the next one is a level and the previous one is provided?\nlemma gcd_div_right (a b : ℕ) : (nat.gcd a b) ∣ b :=\nbegin\n  rw nat.gcd_comm, \n  apply gcd_div_left,\nend\n\n\n-- i think the following two lemma can be \"levels\". \nlemma eq_zero_of_sq_eq_zero (m : ℕ) (hm : m ^ 2 = 0) : m = 0 :=\nbegin\n  simp only [nat.pow_two] at hm, \n  simp only [nat.mul_eq_zero, or_self] at hm,\n  assumption,\nend\n\nlemma sq_eq_zero_iff_eq_zero (m : ℕ) : m ^ 2 = 0 ↔ m = 0 :=\nbegin\n  split, \n  { apply eq_zero_of_sq_eq_zero },\n  intro h, rw h, ring,\nend\n\nlemma coprime_of_div_gcd \n  (m n m' n' k : ℕ) \n  (hk : k = nat.gcd m n)\n  (hmk : m = k * m')\n  (hnk : n = k * n')\n  (hm : 0 < m)\n  (hn : 0 < n)\n: nat.coprime m' n' :=\nbegin\n  have key := nat.gcd_mul_left k m' n',\n  rw [← hmk, ← hnk, ← hk] at key,\n  symmetry' at key,\n  rw nat.mul_right_eq_self_iff at key, exact key,\n  -- generates side goal 0 < k\n  rw hk,\n  apply nat.gcd_pos_of_pos_left,\n  exact hm,\nend\n\n\nlemma wlog_nonzero {m n : ℕ} (hm : m ≠ 0) (hmn : 2 * m^2 = n^2) : n ≠ 0 :=\nbegin\n  contrapose! hm,\n  rw hm at hmn, ring at hmn,\n  rw ← sq_eq_zero_iff_eq_zero,\n  rw nat.mul_eq_zero at hmn,\n  norm_num at hmn, exact hmn,\nend\n\nlemma gcd_ne_zero {m n : ℕ} (hm : m ≠ 0) (hn : n ≠ 0) : nat.gcd m n ≠ 0 :=\nbegin\n  rw ← nat.pos_iff_ne_zero,\n  apply nat.gcd_pos_of_pos_left,\n  rwa nat.pos_iff_ne_zero, -- omega works\nend\n\nlemma ne_zero_of_mul_ne_zero {m k m' : ℕ}\n  (hm : m ≠ 0)\n  (hkm : m = k * m') :\n  m' ≠ 0 :=\nbegin\n  contrapose! hm, \n  rw hkm,\n  rw hm, ring\nend\n\nlemma wlog_coprime_aux {m n k : ℕ}\n  (hmn : 2 * (k * m) ^ 2 = (k * n) ^ 2)\n  (hk : k ≠ 0) :\n  2 * m ^ 2 = n ^ 2 :=\nbegin\n  ring at *,\n  rwa nat.mul_left_inj at hmn,  \n  rw nat.pos_iff_ne_zero,\n  contrapose! hk,\n  apply eq_zero_of_sq_eq_zero, \n  ring at *,\n  assumption,\nend\n\nlemma wlog_coprime {m n : ℕ} (hm : m ≠ 0) (hmn : 2 * m ^ 2 = n ^ 2) : \n∃ m' n', m' ≠ 0  ∧  2 * m' ^ 2 = n' ^ 2 ∧ nat.coprime m' n' :=\nbegin\n  set k := m.gcd n,\n  -- We want to divide by k. To set that up, \n  -- we prove that k is not zero\n  have hn : n ≠ 0 := wlog_nonzero hm hmn,\n  have hk : k ≠ 0 := gcd_ne_zero hm hn,\n  -- and we prove that k divides m and n\n  have hkm : k ∣ m := gcd_div_left m n, \n  have hkn : k ∣ n := gcd_div_right m n, \n  -- here we extract the quotients m' and n'\n  cases hkm with m' hkm,\n  cases hkn with n' hkn,\n  use [m', n'],\n  split, -- ⊢\tm' ≠ 0\n  { apply ne_zero_of_mul_ne_zero hm hkm },\n  split, -- ⊢\t2 * m' ^ 2 = n' ^ 2\n  { rw [hkm, hkn] at hmn,\n    apply wlog_coprime_aux hmn,\n    assumption },\n  -- \t⊢\tm'.coprime n'\n  apply coprime_of_div_gcd m n m' n' k,\n  -- this generates a bunch of conditions we'll tackle one at a time\n  { refl }, -- this is true by definition of k\n  { exact hkm },\n  { exact hkn },\n  { rw nat.pos_iff_ne_zero, exact hm },\n  { rw nat.pos_iff_ne_zero, exact hn },\nend\n\nlemma not_coprime_of_common_factor {m n k : ℕ} \n  (hk : 1 < k) (hm : m ≠ 0) (hn : n ≠ 0)  (hmk : k ∣ m) (hnk : k ∣ n) :\n¬ nat.coprime n m :=\nbegin\n  -- library_search,\n  exact nat.not_coprime_of_dvd_of_dvd hk hnk hmk,\nend\n\nlemma sqrt2_irrational_aux {m n : ℕ} (hm : m ≠ 0) (hmn : 2 * m^2 = n^2) : false :=\nbegin\n  have h2 := wlog_coprime hm hmn, clear hmn hm m n,\n  rcases h2 with ⟨m, n, h , hm, hmn ⟩,\n  contrapose h, clear h,\n  have : 1 < 2, norm_num, -- linarith also works\n  contrapose! hmn,\n  apply not_coprime_of_common_factor this,\n  { apply wlog_nonzero hmn, assumption, },\n  { assumption },\n  { apply two_dvd_of_two_dvd_sq', exact hm, },\n  apply two_dvd_of_two_dvd_sq'',\n  exact hm,\nend\n\ntheorem sqrt2_irrational : \n¬ ∃ p q : ℕ,\n  p ≠ 0 ∧ 2 * p^2 = q^2 :=\nbegin\n  push_neg,\n  intros, \n  by_cases hp : p = 0, \n  { left, exact hp }, right,\n  by_contra h, push_neg at h,\n  apply sqrt2_irrational_aux hp h,\nend\n", "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/sqrt2_irrational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.7965102707452172}}
{"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\" (`¬`)\n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# Important : the definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → false`. So `¬ P` and `P → false`\nare *the same thing* and can be used interchangeably. You can change\nfrom one to the other for free.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics:\n\n* `change` (optional)\n* `by_contra`\n* `by_cases`\n\n### The `change` tactic\n\nThe `change` tactic changes a goal to a goal which\nis *equal to it by definition*. The example you need to know\nis that `¬ P` and `P → false` are equal by definition.\n\nIf your goal is `⊢ ¬ P` then `change P → false,` will\nchange it to `P → false`. Similarly if you have a hypothesis\n`h : ¬ P` then `change P → false at h,` will change it to `h : P → false`.\n\nNote that this tactic is just for psychological purposes. If you finish\na proof which uses this tactic, try commenting out the `change` lines\nand note that it doesn't break.\n\n### The `by_contra` tactic\n\nIf your goal is `⊢ P` and you want to prove it by contradiction,\n`by_contra h,` will change the goal to `false` and add a hypothesis\n`h : ¬ P`.\n\n### The `by_cases` tactic\n\nIf `P : Prop` is a true-false statement then `by_cases hP : P,`\nturns your goal into two goals, one with hypothesis `hP : P`\nand the other with hypothesis `hP : ¬ P`.\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : ¬ P → (P → false) :=\nbegin\n  sorry,\nend\n\nexample : ¬ true → false :=\nbegin\n  sorry\nend\n\nexample : false → ¬ true :=\nbegin\n  sorry\nend\n\nexample : ¬ false → true :=\nbegin\n  sorry\nend\n\nexample : true → ¬ false :=\nbegin\n  sorry\nend\n\nexample : false → ¬ P :=\nbegin\n  sorry\nend\n\nexample : P → ¬ P → false :=\nbegin\n  sorry\nend\n\nexample : P → ¬ (¬ P) :=\nbegin\n  sorry\nend\n\nexample : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  sorry\nend\n\nexample : ¬ ¬ false → false :=\nbegin\n  sorry\nend\n\nexample : ¬ ¬ P → P :=\nbegin\n  sorry\nend\n\nexample : (¬ Q → ¬ P) → (P → Q) :=\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/2021/logic/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.7964980101916136}}
{"text": "variables (α : Type) (p q : α → Prop)\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := ⟨\n  assume h: (∀ x, p x ∧ q x),\n  show (∀ x, p x) ∧ (∀ x, q x), from (\n    have h1: ∀ x, p x, from λ x, (h x).left,\n    have h2: ∀ x, q x, from λ x, (h x).right,\n    ⟨h1, h2⟩\n  ),\n\n  assume h: (∀ x, p x) ∧ (∀ x, q x),\n  λ x, ⟨(h.left x), (h.right x)⟩\n⟩\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := (\n  assume (h1: ∀ x, p x → q x) (h2: ∀ x, p x),\n  λ x, (h1 x) (h2 x)  \n)\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := (\n  assume h: (∀ x, p x) ∨ (∀ x, q x),\n  or.elim h (\n    assume hp: ∀ x, p x,\n    λ x, or.inl (hp x)\n  ) (\n    assume hq: ∀ x, q x,\n    λ x, or.inr (hq x)\n  )\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/4.6.1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750427013549, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7964456025560823}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hp,\n  intro hnp,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro hp,\n  by_cases h : P,\n  exact h,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  apply iff.intro,\n  apply doubleneg_elim,\n  apply doubleneg_intro,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ 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 ∧ Q) → (Q ∧ 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ções de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h,\n  intro hp,\n  cases h with hnp hq,\n  contradiction,\n  assumption,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro h,\n  intro hnp,\n  cases h with hnp hq,\n  contradiction,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro h,\n  intro hnq,\n  intro hnp,\n  have hq : Q := h hnp,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro h,\n  intro hp,\n  by_contra hcq,\n  apply h,\n  exact hcq,\n  exact hp,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  apply iff.intro, \n  apply impl_as_contrapositive,\n  apply impl_as_contrapositive_converse,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h,\n  apply h,\n  right,\n  intro hp,\n  apply h,\n  left,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro h,\n  intro hnnp,\n  apply hnnp,\n  apply h,\n  intro hp,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro h,\n  intro hnh,\n  cases hnh with hnp hnq,\n  cases h with hp hq,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro h,\n  intro hnh,\n  cases h with hp hq,\n  cases hnh with hnp hnq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\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,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro h,\n  intro g,\n  cases g with hp hq,\n  cases h with hnp hnq,\n  contradiction,\n  cases h with hnp hnq,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h,\n  by_contra hcsecond,\n  apply h,\n  split,\n  by_contra hcp,\n  apply hcsecond,\n  right,\n  exact hcp,\n  by_contra hcq,\n  apply hcsecond,\n  left,\n  exact hcq,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro h,\n  intro g,\n  cases g with hq hp,\n  cases h with hnq hnp,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  apply iff.intro,\n  apply demorgan_conj,\n  apply demorgan_conj_converse,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  apply iff.intro,\n  apply demorgan_disj,\n  apply demorgan_disj_converse,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h,\n  cases h with hp hsecond,\n  cases hsecond 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∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h,\n  cases h with hsecond hthird,\n  cases hsecond with hp hq,\n  split,\n  exact hp,\n  left,\n  exact hq,\n  cases hthird with hp hr,\n  split,\n  exact hp,\n  right,\n  exact hr,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h,\n  cases h with hp hsecond,\n  split,\n  left,\n  exact hp,\n  left,\n  exact hp,\n  cases hsecond with hq hr,\n  split,\n  right,\n  exact hq,\n  right,\n  exact hr,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  cases h with hsecond hthird,\n  cases hsecond with hp hq,\n  left,\n  exact hp,\n  cases hthird with hp hr,\n  left,\n  exact hp,\n  right,\n  split,\n  exact hq,\n  exact hr,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro h,\n  intro hp,\n  intro hq,\n  apply h,\n  split,\n  exact hp,\n  exact hq,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro h,\n  intro hsecond,\n  apply h,\n  cases hsecond with hp hq,\n  exact hp,\n  cases hsecond with hp hq,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hp,\n  exact hp\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hp,\n  left,\n  exact hp,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hq,\n  right,\n  exact hq,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  exact hp,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  exact hq,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  apply iff.intro,\n  intro h,\n  cases h with hp hp,\n  exact hp,\n  intro hp,\n  split,\n  exact hp,\n  exact hp,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  apply iff.intro,\n  intro h,\n  cases h with hp hp,\n  exact hp,\n  exact hp,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro hnepx,\n  intro x,\n  intro hpx,\n  apply hnepx,\n  existsi x,\n  exact hpx,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  apply iff.intro,\n  apply demorgan_forall,\n  apply demorgan_forall_converse,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  apply iff.intro,\n  apply demorgan_exists,\n  apply demorgan_exists_converse,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  apply iff.intro,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  apply iff.intro,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  sorry,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "ohannadeziderio", "repo": "fmclean", "sha": "1299916cb27922d06e551453e3c027c5861de409", "save_path": "github-repos/lean/ohannadeziderio-fmclean", "path": "github-repos/lean/ohannadeziderio-fmclean/fmclean-1299916cb27922d06e551453e3c027c5861de409/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.7963594659928006}}
{"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\nStructures with multiplicative and additive components, including semirings, rings, and fields.\nThe development is modeled after Isabelle's library.\n-/\n\nimport logic.eq logic.connectives data.unit data.sigma data.prod\nimport algebra.binary algebra.group\nopen eq eq.ops\n\nvariable {A : Type}\n\n/- auxiliary classes -/\n\nstructure distrib [class] (A : Type) extends has_mul A, has_add A :=\n(left_distrib : ∀a b c, mul a (add b c) = add (mul a b) (mul a c))\n(right_distrib : ∀a b c, mul (add a b) c = add (mul a c) (mul b c))\n\ntheorem left_distrib [distrib A] (a b c : A) : a * (b + c) = a * b + a * c :=\n!distrib.left_distrib\n\ntheorem right_distrib [distrib A] (a b c : A) : (a + b) * c = a * c + b * c :=\n!distrib.right_distrib\n\nstructure mul_zero_class [class] (A : Type) extends has_mul A, has_zero A :=\n(zero_mul : ∀a, mul zero a = zero)\n(mul_zero : ∀a, mul a zero = zero)\n\ntheorem zero_mul [simp] [mul_zero_class A] (a : A) : 0 * a = 0 := !mul_zero_class.zero_mul\ntheorem mul_zero [simp] [mul_zero_class A] (a : A) : a * 0 = 0 := !mul_zero_class.mul_zero\n\nstructure zero_ne_one_class [class] (A : Type) extends has_zero A, has_one A :=\n(zero_ne_one : zero ≠ one)\n\ntheorem zero_ne_one [s: zero_ne_one_class A] : 0 ≠ (1:A) := @zero_ne_one_class.zero_ne_one A s\n\n/- semiring -/\n\nstructure semiring [class] (A : Type) extends add_comm_monoid A, monoid A, distrib A,\n    mul_zero_class A\n\nsection semiring\n  variables [s : semiring A] (a b c : A)\n  include s\n\n  theorem one_add_one_eq_two : 1 + 1 = (2:A) :=\n  by unfold bit0\n\n  theorem ne_zero_of_mul_ne_zero_right {a b : A} (H : a * b ≠ 0) : a ≠ 0 :=\n  suppose a = 0,\n  have a * b = 0, by rewrite [this, zero_mul],\n  H this\n\n  theorem ne_zero_of_mul_ne_zero_left {a b : A} (H : a * b ≠ 0) : b ≠ 0 :=\n  suppose b = 0,\n  have a * b = 0, by rewrite [this, mul_zero],\n  H this\n\n  local attribute right_distrib [simp]\n\n  theorem distrib_three_right (a b c d : A) : (a + b + c) * d = a * d + b * d + c * d :=\n  by simp\nend semiring\n\n/- comm semiring -/\n\nstructure comm_semiring [class] (A : Type) extends semiring A, comm_monoid A\n-- TODO: we could also define a cancelative comm_semiring, i.e. satisfying\n-- c ≠ 0 → c * a = c * b → a = b.\n\nsection comm_semiring\n  variables [s : comm_semiring A] (a b c : A)\n  include s\n\n  protected definition algebra.dvd (a b : A) : Prop := ∃c, b = a * c\n\n  definition comm_semiring_has_dvd [instance] [priority algebra.prio] : has_dvd A :=\n  has_dvd.mk algebra.dvd\n\n  theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b :=\n  exists.intro _ H⁻¹\n\n  theorem dvd_of_mul_right_eq {a b c : A} (H : a * c = b) : a ∣ b := dvd.intro H\n\n  theorem dvd.intro_left {a b c : A} (H : c * a = b) : a ∣ b :=\n  dvd.intro (by rewrite mul.comm at H; exact H)\n\n  theorem dvd_of_mul_left_eq {a b c : A} (H : c * a = b) : a ∣ b := dvd.intro_left H\n\n  theorem exists_eq_mul_right_of_dvd {a b : A} (H : a ∣ b) : ∃c, b = a * c := H\n\n  theorem dvd.elim {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = a * c → P) : P :=\n  exists.elim H₁ H₂\n\n  theorem exists_eq_mul_left_of_dvd {a b : A} (H : a ∣ b) : ∃c, b = c * a :=\n  dvd.elim H (take c, assume H1 : b = a * c, exists.intro c (H1 ⬝ !mul.comm))\n\n  theorem dvd.elim_left {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = c * a → P) : P :=\n  exists.elim (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃)\n\n  theorem dvd.refl [simp] : a ∣ a :=\n  dvd.intro !mul_one\n\n  theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c :=\n  dvd.elim H₁\n    (take d, assume H₃ : b = a * d,\n      dvd.elim H₂\n        (take e, assume H₄ : c = b * e,\n          dvd.intro\n            (show a * (d * e) = c, by rewrite [-mul.assoc, -H₃, H₄])))\n\n  theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 :=\n    dvd.elim H (take c, assume H' : a = 0 * c, H' ⬝ !zero_mul)\n\n  theorem dvd_zero [simp] : a ∣ 0 := dvd.intro !mul_zero\n\n  theorem one_dvd [simp] : 1 ∣ a := dvd.intro !one_mul\n\n  theorem dvd_mul_right [simp] : a ∣ a * b := dvd.intro rfl\n\n  theorem dvd_mul_left [simp] : a ∣ b * a :=\n  by simp\n\n  theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c :=\n  dvd.elim H\n    (take d,\n      suppose b = a * d,\n      dvd.intro\n        (show a * (d * c) = b * c, by simp))\n\n  theorem dvd_mul_of_dvd_right {a b : A} (H : a ∣ b) (c : A) : a ∣ c * b :=\n  !mul.comm ▸ (dvd_mul_of_dvd_left H _)\n\n  theorem mul_dvd_mul {a b c d : A} (dvd_ab : a ∣ b) (dvd_cd : c ∣ d) : a * c ∣ b * d :=\n  dvd.elim dvd_ab\n    (take e, suppose b = a * e,\n      dvd.elim dvd_cd\n        (take f, suppose d = c * f,\n          dvd.intro\n            (show a * c * (e * f) = b * d,\n             by simp)))\n\n  theorem dvd_of_mul_right_dvd {a b c : A} (H : a * b ∣ c) : a ∣ c :=\n  dvd.elim H (take d, assume Habdc : c = a * b * d, dvd.intro (!mul.assoc⁻¹ ⬝ Habdc⁻¹))\n\n  theorem dvd_of_mul_left_dvd {a b c : A} (H : a * b ∣ c) : b ∣ c :=\n  dvd_of_mul_right_dvd (mul.comm a b ▸ H)\n\n  theorem dvd_add {a b c : A} (Hab : a ∣ b) (Hac : a ∣ c) : a ∣ b + c :=\n  dvd.elim Hab\n    (take d, suppose b = a * d,\n      dvd.elim Hac\n        (take e, suppose c = a * e,\n          dvd.intro (show a * (d + e) = b + c,\n                     by rewrite [left_distrib]; substvars)))\nend comm_semiring\n\n/- ring -/\n\nstructure ring [class] (A : Type) extends add_comm_group A, monoid A, distrib A\n\ntheorem ring.mul_zero [simp] [ring A] (a : A) : a * 0 = 0 :=\nhave a * 0 + 0 = a * 0 + a * 0, from calc\n  a * 0 + 0 = a * (0 + 0)   : by simp\n        ... = a * 0 + a * 0 : by rewrite left_distrib,\nshow a * 0 = 0, from (add.left_cancel this)⁻¹\n\ntheorem ring.zero_mul [simp] [ring A] (a : A) : 0 * a = 0 :=\nhave 0 * a + 0 = 0 * a + 0 * a, from calc\n  0 * a + 0 = (0 + 0) * a   : by simp\n        ... = 0 * a + 0 * a : by rewrite right_distrib,\nshow 0 * a = 0, from  (add.left_cancel this)⁻¹\n\ndefinition ring.to_semiring [trans_instance] [s : ring A] : semiring A :=\n⦃ semiring, s,\n  mul_zero := ring.mul_zero,\n  zero_mul := ring.zero_mul ⦄\n\nsection\n  variables [s : ring A] (a b c d e : A)\n  include s\n\n  theorem neg_mul_eq_neg_mul : -(a * b) = -a * b :=\n  neg_eq_of_add_eq_zero\n    begin\n      rewrite [-right_distrib, add.right_inv, zero_mul]\n    end\n\n  theorem neg_mul_eq_mul_neg : -(a * b) = a * -b :=\n   neg_eq_of_add_eq_zero\n     begin\n       rewrite [-left_distrib, add.right_inv, mul_zero]\n     end\n\n  theorem neg_mul_eq_neg_mul_symm [simp] : - a * b = - (a * b) := eq.symm !neg_mul_eq_neg_mul\n  theorem mul_neg_eq_neg_mul_symm [simp] : a * - b = - (a * b) := eq.symm !neg_mul_eq_mul_neg\n\n  theorem neg_mul_neg : -a * -b = a * b :=\n  by simp\n\n  theorem neg_mul_comm : -a * b = a * -b :=\n  by simp\n\n  theorem neg_eq_neg_one_mul : -a = -1 * a :=\n  by simp\n\n  theorem mul_sub_left_distrib : a * (b - c) = a * b - a * c :=\n  calc\n    a * (b - c) = a * b + a * -c : left_distrib\n            ... = a * b - a * c  : by simp\n\n  theorem mul_sub_right_distrib : (a - b) * c = a * c - b * c :=\n  calc\n    (a - b) * c = a * c  + -b * c : right_distrib\n            ... = a * c - b * c   : by simp\n\n  -- TODO: can calc mode be improved to make this easier?\n  -- TODO: there is also the other direction. It will be easier when we\n  -- have the simplifier.\n\n  theorem mul_add_eq_mul_add_iff_sub_mul_add_eq : a * e + c = b * e + d ↔ (a - b) * e + c = d :=\n  calc\n    a * e + c = b * e + d ↔ a * e + c = d + b * e : by rewrite {b*e+_}add.comm\n      ... ↔ a * e + c - b * e = d : iff.symm !sub_eq_iff_eq_add\n      ... ↔ a * e - b * e + c = d : by rewrite sub_add_eq_add_sub\n      ... ↔ (a - b) * e + c = d   : by rewrite mul_sub_right_distrib\n\n  theorem mul_add_eq_mul_add_of_sub_mul_add_eq : (a - b) * e + c = d → a * e + c = b * e + d :=\n  iff.mpr !mul_add_eq_mul_add_iff_sub_mul_add_eq\n\n  theorem sub_mul_add_eq_of_mul_add_eq_mul_add : a * e + c = b * e + d → (a - b) * e + c = d :=\n  iff.mp !mul_add_eq_mul_add_iff_sub_mul_add_eq\n\n  theorem mul_neg_one_eq_neg : a * (-1) = -a :=\n    have a + a * -1 = 0, from calc\n      a + a * -1 = a * 1 + a * -1 : by simp\n             ... = a * (1 + -1)   : left_distrib\n             ... = 0              : by simp,\n    symm (neg_eq_of_add_eq_zero this)\n\n  theorem ne_zero_and_ne_zero_of_mul_ne_zero {a b : A} (H : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=\n    have a ≠ 0, from\n      (suppose a = 0,\n        have a * b = 0, by rewrite [this, zero_mul],\n        absurd this H),\n    have b ≠ 0, from\n      (suppose b = 0,\n        have a * b = 0, by rewrite [this, mul_zero],\n        absurd this H),\n    and.intro `a ≠ 0` `b ≠ 0`\nend\n\nstructure comm_ring [class] (A : Type) extends ring A, comm_semigroup A\n\ndefinition comm_ring.to_comm_semiring [trans_instance] [s : comm_ring A] : comm_semiring A :=\n⦃ comm_semiring, s,\n  mul_zero := mul_zero,\n  zero_mul := zero_mul ⦄\n\nsection\n  variables [s : comm_ring A] (a b c d e : A)\n  include s\n\n  local attribute left_distrib right_distrib [simp]\n\n  theorem mul_self_sub_mul_self_eq : a * a - b * b = (a + b) * (a - b) :=\n  by simp\n\n  theorem mul_self_sub_one_eq : a * a - 1 = (a + 1) * (a - 1) :=\n  by simp\n\n  theorem add_mul_self_eq : (a + b) * (a + b) = a*a + 2*a*b + b*b :=\n  calc (a + b)*(a + b) = a*a + (1+1)*a*b + b*b : by simp\n               ...     = a*a + 2*a*b + b*b     : by rewrite one_add_one_eq_two\n\n  theorem dvd_neg_iff_dvd : (a ∣ -b) ↔ (a ∣ b) :=\n  iff.intro\n    (suppose a ∣ -b,\n      dvd.elim this\n        (take c, suppose -b = a * c,\n          dvd.intro\n            (show a * -c = b,\n             by rewrite [-neg_mul_eq_mul_neg, -this, neg_neg])))\n    (suppose a ∣ b,\n      dvd.elim this\n        (take c, suppose b = a * c,\n          dvd.intro\n            (show a * -c = -b,\n             by rewrite [-neg_mul_eq_mul_neg, -this])))\n\n  theorem dvd_neg_of_dvd : (a ∣ b) → (a ∣ -b) :=\n  iff.mpr !dvd_neg_iff_dvd\n\n  theorem dvd_of_dvd_neg : (a ∣ -b) → (a ∣ b) :=\n  iff.mp !dvd_neg_iff_dvd\n\n  theorem neg_dvd_iff_dvd : (-a ∣ b) ↔ (a ∣ b) :=\n  iff.intro\n    (suppose -a ∣ b,\n      dvd.elim this\n        (take c, suppose b = -a * c,\n          dvd.intro\n            (show a * -c = b, by rewrite [-neg_mul_comm, this])))\n    (suppose a ∣ b,\n      dvd.elim this\n        (take c, suppose b = a * c,\n          dvd.intro\n            (show -a * -c = b, by rewrite [neg_mul_neg, this])))\n\n  theorem neg_dvd_of_dvd : (a ∣ b) → (-a ∣ b) :=\n  iff.mpr !neg_dvd_iff_dvd\n\n  theorem dvd_of_neg_dvd : (-a ∣ b) → (a ∣ b) :=\n  iff.mp !neg_dvd_iff_dvd\n\n  theorem dvd_sub (H₁ : (a ∣ b)) (H₂ : (a ∣ c)) : (a ∣ b - c) :=\n  dvd_add H₁ (!dvd_neg_of_dvd H₂)\nend\n\n/- integral domains -/\n\nstructure no_zero_divisors [class] (A : Type) extends has_mul A, has_zero A :=\n(eq_zero_or_eq_zero_of_mul_eq_zero : ∀a b, mul a b = zero → a = zero ∨ b = zero)\n\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero {A : Type} [no_zero_divisors A] {a b : A}\n    (H : a * b = 0) :\n  a = 0 ∨ b = 0 :=\n!no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero H\n\ntheorem eq_zero_of_mul_self_eq_zero {A : Type} [no_zero_divisors A] {a : A} (H : a * a = 0) :\n  a = 0 :=\nor.elim (eq_zero_or_eq_zero_of_mul_eq_zero H) (assume H', H') (assume H', H')\n\nstructure integral_domain [class] (A : Type) extends comm_ring A, no_zero_divisors A,\n    zero_ne_one_class A\n\nsection\n  variables [s : integral_domain A] (a b c d e : A)\n  include s\n\n  theorem mul_ne_zero {a b : A} (H1 : a ≠ 0) (H2 : b ≠ 0) : a * b ≠ 0 :=\n  suppose a * b = 0,\n  or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this) (assume H3, H1 H3) (assume H4, H2 H4)\n\n  theorem eq_of_mul_eq_mul_right {a b c : A} (Ha : a ≠ 0) (H : b * a = c * a) : b = c :=\n  have b * a - c * a = 0, from iff.mp !eq_iff_sub_eq_zero H,\n  have (b - c) * a = 0, by rewrite [mul_sub_right_distrib, this],\n  have b - c = 0, from or_resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero this) Ha,\n  iff.elim_right !eq_iff_sub_eq_zero this\n\n  theorem eq_of_mul_eq_mul_left {a b c : A} (Ha : a ≠ 0) (H : a * b = a * c) : b = c :=\n  have a * b - a * c = 0, from iff.mp !eq_iff_sub_eq_zero H,\n  have a * (b - c) = 0, by rewrite [mul_sub_left_distrib, this],\n  have b - c = 0, from or_resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero this) Ha,\n  iff.elim_right !eq_iff_sub_eq_zero this\n\n  -- TODO: do we want the iff versions?\n\n  theorem eq_zero_of_mul_eq_self_right {a b : A} (H₁ : b ≠ 1) (H₂ : a * b = a) : a = 0 :=\n  have b - 1 ≠ 0, from\n    suppose b - 1 = 0, H₁ (!zero_add ▸ eq_add_of_sub_eq this),\n  have a * b - a = 0,   by simp,\n  have a * (b - 1) = 0, by rewrite [mul_sub_left_distrib, mul_one]; apply this,\n    show a = 0, from or_resolve_left (eq_zero_or_eq_zero_of_mul_eq_zero this) `b - 1 ≠ 0`\n\n  theorem eq_zero_of_mul_eq_self_left {a b : A} (H₁ : b ≠ 1) (H₂ : b * a = a) : a = 0 :=\n    eq_zero_of_mul_eq_self_right H₁ (!mul.comm ▸ H₂)\n\n  theorem mul_self_eq_mul_self_iff (a b : A) : a * a = b * b ↔ a = b ∨ a = -b :=\n  iff.intro\n    (suppose a * a = b * b,\n      have (a - b) * (a + b) = 0,\n        by rewrite [mul.comm, -mul_self_sub_mul_self_eq, this, sub_self],\n      have a - b = 0 ∨ a + b = 0, from !eq_zero_or_eq_zero_of_mul_eq_zero this,\n      or.elim this\n        (suppose a - b = 0, or.inl (eq_of_sub_eq_zero this))\n        (suppose a + b = 0, or.inr (eq_neg_of_add_eq_zero this)))\n    (suppose a = b ∨ a = -b, or.elim this\n      (suppose a = b,  by rewrite this)\n      (suppose a = -b, by rewrite [this, neg_mul_neg]))\n\n  theorem mul_self_eq_one_iff (a : A) : a * a = 1 ↔ a = 1 ∨ a = -1 :=\n  have a * a = 1 * 1 ↔ a = 1 ∨ a = -1, from mul_self_eq_mul_self_iff a 1,\n  by rewrite mul_one at this; exact this\n\n  -- TODO: c - b * c → c = 0 ∨ b = 1 and variants\n\n  theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=\n  dvd.elim Hdvd\n    (take d,\n      suppose a * c = a * b * d,\n      have b * d = c, from eq_of_mul_eq_mul_left Ha (mul.assoc a b d ▸ this⁻¹),\n      dvd.intro this)\n\n  theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=\n  dvd.elim Hdvd\n    (take d,\n      suppose c * a = b * a * d,\n      have b * d * a = c * a, from by rewrite [mul.right_comm, -this],\n      have b * d = c, from eq_of_mul_eq_mul_right Ha this,\n      dvd.intro this)\nend\n\nnamespace norm_num\n\nlocal attribute bit0 bit1 add1 [reducible]\nlocal attribute right_distrib left_distrib [simp]\n\ntheorem mul_zero [mul_zero_class A] (a : A) : a * zero = zero :=\nby simp\n\ntheorem zero_mul [mul_zero_class A] (a : A) : zero * a = zero :=\nby simp\n\ntheorem mul_one [monoid A] (a : A) : a * one = a :=\nby simp\n\ntheorem mul_bit0 [distrib A] (a b : A) : a * (bit0 b) = bit0 (a * b) :=\nby simp\n\ntheorem mul_bit0_helper [distrib A] (a b t : A) (H : a * b = t) : a * (bit0 b) = bit0 t :=\nby rewrite -H; simp\n\ntheorem mul_bit1 [semiring A] (a b : A) : a * (bit1 b) = bit0 (a * b) + a :=\nby simp\n\ntheorem mul_bit1_helper [semiring A] (a b s t : A) (Hs : a * b = s) (Ht : bit0 s + a  = t) :\n        a * (bit1 b) = t :=\nby simp\n\ntheorem subst_into_prod [has_mul A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)\n        (prt : tl * tr = t) :\n        l * r = t :=\nby simp\n\ntheorem mk_cong (op : A → A) (a b : A) (H : a = b) : op a = op b :=\nby simp\n\ntheorem neg_add_neg_eq_of_add_add_eq_zero [add_comm_group A] (a b c : A) (H : c + a + b = 0) :\n        -a + -b = c :=\nbegin\n  apply add_neg_eq_of_eq_add,\n  apply neg_eq_of_add_eq_zero,\n  simp\nend\n\ntheorem neg_add_neg_helper [add_comm_group A] (a b c : A) (H : a + b = c) : -a + -b = -c :=\nbegin apply iff.mp !neg_eq_neg_iff_eq, simp end\n\ntheorem neg_add_pos_eq_of_eq_add [add_comm_group A] (a b c : A) (H : b = c + a) : -a + b = c :=\nbegin apply neg_add_eq_of_eq_add, simp end\n\ntheorem neg_add_pos_helper1 [add_comm_group A] (a b c : A) (H : b + c = a) : -a + b = -c :=\nbegin apply neg_add_eq_of_eq_add, apply eq_add_neg_of_add_eq H end\n\ntheorem neg_add_pos_helper2 [add_comm_group A] (a b c : A) (H : a + c = b) : -a + b = c :=\nbegin apply neg_add_eq_of_eq_add, rewrite H end\n\ntheorem pos_add_neg_helper [add_comm_group A] (a b c : A) (H : b + a = c) : a + b = c :=\nby simp\n\ntheorem sub_eq_add_neg_helper [add_comm_group A] (t₁ t₂ e w₁ w₂: A) (H₁ : t₁ = w₁)\n        (H₂ : t₂ = w₂) (H : w₁ + -w₂ = e) : t₁ - t₂ = e :=\nby simp\n\ntheorem pos_add_pos_helper [add_comm_group A] (a b c h₁ h₂ : A) (H₁ : a = h₁) (H₂ : b = h₂)\n        (H : h₁ + h₂ = c) : a + b = c :=\nby simp\n\ntheorem subst_into_subtr [add_group A] (l r t : A) (prt : l + -r = t) : l - r = t :=\nby simp\n\ntheorem neg_neg_helper [add_group A] (a b : A) (H : a = -b) : -a = b :=\nby simp\n\ntheorem neg_mul_neg_helper [ring A] (a b c : A) (H : a * b = c) : (-a) * (-b) = c :=\nby simp\n\ntheorem neg_mul_pos_helper [ring A] (a b c : A) (H : a * b = c) : (-a) * b = -c :=\nby simp\n\ntheorem pos_mul_neg_helper [ring A] (a b c : A) (H : a * b = c) : a * (-b) = -c :=\nby simp\n\nend norm_num\n\nattribute [simp]\n  zero_mul mul_zero\n  at simplifier.unit\n\nattribute [simp]\n  neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm\n  at simplifier.neg\n\nattribute [simp]\n  left_distrib right_distrib\n  at simplifier.distrib\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/ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7963594490356407}}
{"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.pow\n! leanprover-community/mathlib commit 46a64b5b4268c594af770c44d9e502afc6a515cb\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.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 `IsRegular` early in the\nalgebra hierarchy.\n\n-/\n\n\nvariable {R : Type _} {a b : R}\n\nsection Monoid\n\nvariable [Monoid R]\n\n/-- Any power of a left-regular element is left-regular. -/\ntheorem IsLeftRegular.pow (n : ℕ) (rla : IsLeftRegular a) : IsLeftRegular (a ^ n) := by\n  simp only [IsLeftRegular, ← mul_left_iterate, rla.iterate n]\n#align is_left_regular.pow IsLeftRegular.pow\n\n/-- Any power of a right-regular element is right-regular. -/\ntheorem IsRightRegular.pow (n : ℕ) (rra : IsRightRegular a) : IsRightRegular (a ^ n) := by\n  rw [IsRightRegular, ← mul_right_iterate]\n  exact rra.iterate n\n#align is_right_regular.pow IsRightRegular.pow\n\n/-- Any power of a regular element is regular. -/\ntheorem IsRegular.pow (n : ℕ) (ra : IsRegular a) : IsRegular (a ^ n) :=\n  ⟨IsLeftRegular.pow n ra.left, IsRightRegular.pow n ra.right⟩\n#align is_regular.pow IsRegular.pow\n\n/-- An element `a` is left-regular if and only if a positive power of `a` is left-regular. -/\ntheorem IsLeftRegular.pow_iff {n : ℕ} (n0 : 0 < n) : IsLeftRegular (a ^ n) ↔ IsLeftRegular a := by\n  refine' ⟨_, IsLeftRegular.pow n⟩\n  rw [← Nat.succ_pred_eq_of_pos n0, pow_succ']\n  exact IsLeftRegular.of_mul\n#align is_left_regular.pow_iff IsLeftRegular.pow_iff\n\n/-- An element `a` is right-regular if and only if a positive power of `a` is right-regular. -/\ntheorem IsRightRegular.pow_iff {n : ℕ} (n0 : 0 < n) :\n    IsRightRegular (a ^ n) ↔ IsRightRegular a := by\n  refine' ⟨_, IsRightRegular.pow n⟩\n  rw [← Nat.succ_pred_eq_of_pos n0, pow_succ]\n  exact IsRightRegular.of_mul\n#align is_right_regular.pow_iff IsRightRegular.pow_iff\n\n/-- An element `a` is regular if and only if a positive power of `a` is regular. -/\ntheorem IsRegular.pow_iff {n : ℕ} (n0 : 0 < n) : IsRegular (a ^ n) ↔ IsRegular a :=\n  ⟨fun h => ⟨(IsLeftRegular.pow_iff n0).mp h.left, (IsRightRegular.pow_iff n0).mp h.right⟩, fun h =>\n    ⟨IsLeftRegular.pow n h.left, IsRightRegular.pow n h.right⟩⟩\n#align is_regular.pow_iff IsRegular.pow_iff\n\nend Monoid\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/Pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7963552213321416}}
{"text": "import data.real.basic\n\nimport tactic.suggest\n\nnoncomputable theory\nopen_locale classical\n\n/-\n# Chapter 6 : Completeness\n\n## Level 1  \n\n\nIn the Completeness world, youj will be solving proofs regarding \ntheroems and properties of bounded sets of reals.  \n\nIn Lean, we define the lower bounds of a set A such that \n∀ x : ℝ, | ∀ a ∈ A, x ≤ a. Essentially, for any number x, \nx is less than or equal to any element a in the set A.    \n\nFor the upper bounds, we define the upper bounds of a set A such that \n∀ x : ℝ, | ∀ a ∈ A, a ≤ x. Saying that for any number x, \nx is greater than or equal to any element a in the set A. \n\n\n\n\nFor this proof, prove that there is a unique max on a set A of real numbers.\n-/\n\n\ndef up_bounds (A : set ℝ) := { x : ℝ | ∀ a ∈ A, a ≤ x}\n\ndef is_maximum (a : ℝ) (A : set ℝ) := a ∈ A ∧ a ∈ up_bounds A\n\ninfix ` is_a_max_of `:55 := is_maximum\n\ndef low_bounds (A : set ℝ) := { x : ℝ | ∀ a ∈ A, x ≤ a}\n\ndef is_inf (x : ℝ) (A : set ℝ) := x is_a_max_of (low_bounds A)\n\ninfix ` is_an_inf_of `:55 := is_inf\n\nlemma unique_max (A : set ℝ) (x y : ℝ) (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 ≤ y` and `y ≤ x`, and Lean shouldn't need more help.\n  -- `linarith` proves equalities and inequalities that follow linearly from\n  -- the assumption we have.\n  linarith,\nend\n\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/Completeness/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7963337668803555}}
{"text": "import .love12_basic_mathematical_structures_demo\n\n\n/-! # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Question 1: Type Classes\n\nRecall the datatype `btree` we introduced earlier: -/\n\n#check btree\n\n/-! The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/-! 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nsorry\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nsorry\n\n/-! 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\nsorry\n\n/-! 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/-! 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀ y : btree ℕ, btree.graft y x ≠ btree.empty :=\nsorry\n\n\n/-! ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/-! 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nsorry\n\n/-! 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nsorry\n\n/-! 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nsorry\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\nend\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/love12_basic_mathematical_structures_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7961834909593137}}
{"text": "import data.bool\nimport data.int.gcd\nimport tactic\n\ndef mod' (a: ℤ) (b: ℕ): ℤ := a - b * ((a + b/2) / b)\n\ntheorem mod'_eq (a: ℤ) (b: ℕ): mod' a b = ((a + b / 2) % b - b / 2) :=\nbegin\n\tsimp [mod', int.mod_def],\n\tlinarith,\nend\n\ntheorem mod_lower_bound (a: ℤ) (b: ℕ) (h: b ≠ 0): mod' a b ≥ -((b: ℤ) / 2) :=\nby simp [mod'_eq, int.mod_nonneg, int.coe_nat_ne_zero, h]\n\ntheorem div_mul_gt (a: ℤ) { b: ℤ } (h: b > 0):  a / b * b > a - b := begin\n\thave := int.div_add_mod a b,\n\thave : (a / b) * b = a - a % b := by linarith,\n\trw this,\n\thave := int.mod_lt a (ne_of_gt h),\n\trw int.abs_eq_nat_abs at this,\n\trw int.nat_abs_of_nonneg (le_of_lt h) at this,\n\tlinarith,\nend\n\ntheorem mod_upper_bound (a: ℤ) (b: ℕ) (h: b ≠ 0): (mod' a b) ≤ (b: ℤ) / 2 :=\nbegin\n\tset m := (a + (b: ℤ) / 2) % b with m_def,\n\n\tsuffices : m ≤ (b: ℤ) / 2 + (b: ℤ) / 2, {\n\t\trw [mod'_eq],\n\t\tlinarith,\n\t},\n\n\thave : m ≤ (b: ℤ) - 1 := begin\n\t\thave := int.mod_lt (a + (b: ℤ) / 2) (int.coe_nat_ne_zero.mpr h),\n\t\tsimp at this,\n\t\texact int.le_sub_one_iff.mpr this,\n\tend,\n\n\thave c : (b: ℤ) - 1 ≤ (b: ℤ) / 2 * 2 := begin\n\t\thave : (2: ℤ) > 0 := by linarith,\n\t\thave := div_mul_gt b this,\n\t\tlinarith,\n\tend,\n\n\tlinarith,\nend\n\ntheorem mod_abs_bound (a: ℤ) (b: ℕ) (h: b ≠ 0): (mod' a b).nat_abs ≤ b / 2 :=\nbegin\n\trw ←int.coe_nat_le,\n\trw ←int.abs_eq_nat_abs,\n\trw abs_le,\n\texact and.intro (mod_lower_bound a b h) (mod_upper_bound a b h),\nend", "meta": {"author": "hediet", "repo": "lean-linear-integer-equation-solver", "sha": "1a83fa7935b4411618c4edcdee7edb5c4a6678a7", "save_path": "github-repos/lean/hediet-lean-linear-integer-equation-solver", "path": "github-repos/lean/hediet-lean-linear-integer-equation-solver/lean-linear-integer-equation-solver-1a83fa7935b4411618c4edcdee7edb5c4a6678a7/src/mod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7960864038447417}}
{"text": "theorem IffNotNot {p: Prop}:\n  p ↔ ¬ ¬ p := by {\n  apply Iff.intro;\n  {exact fun h hn => hn h;}\n  {\n    intro h;\n    by_cases hp: p;\n    {exact hp;}\n    {exact False.elim (h hp);}\n  }\n}\n\ntheorem ImpIffNotImpNot {p q: Prop}:\n  (p → q) ↔ (¬ q → ¬ p) := by {\n  apply Iff.intro;\n  {exact fun h hnq hp => hnq (h hp);}\n  {\n    intro h hp;\n    by_cases hq: q;\n    {exact hq;}\n    {exact False.elim ((h hq) hp);}\n  }\n}\ntheorem IffIffNotIffNot {p q: Prop}:\n  (p ↔ q) ↔ (¬ q ↔ ¬ p) := by {\n  apply Iff.intro;\n  {exact fun h => ⟨ImpIffNotImpNot.1 h.1,ImpIffNotImpNot.1 h.2⟩;}\n  {exact fun h => ⟨ImpIffNotImpNot.2 h.1,ImpIffNotImpNot.2 h.2⟩;}\n}\n\ntheorem NotExistsImpForall {α : Sort u} {p: α → Prop}:\n  (¬ (∃a: α, p a)) → (∀a: α, ¬ p a) :=\nfun h a ha => h (Exists.intro a ha)\ntheorem NotFoallImpExists {α : Sort u} {p: α → Prop}:\n  ¬ (∀a: α, p a) → (∃a: α, ¬ p a) := by {\n  intro h;\n  by_cases ha : (∃a: α, ¬ p a);\n  {exact ha;}\n  {exact False.elim (h (fun a => IffNotNot.2 (NotExistsImpForall ha a)));}\n}\n\ntheorem ExistsIffNotForall {α : Sort u} {p: α → Prop}:\n  (¬ (∃a: α, p a)) ↔ (∀a: α, ¬ p a) := by {\n  apply Iff.intro;\n  {exact NotExistsImpForall;}\n  {exact fun h ⟨a, pa⟩ => (h a) pa;}\n}\ntheorem ForallIffNotExists {α : Sort u} {p: α → Prop}:\n  ¬ (∀a: α, p a) ↔ (∃a: α, ¬ p a) := by {\n  apply Iff.intro;\n  {exact NotFoallImpExists;}\n  {exact fun ⟨a, pa⟩ h => pa (h a);}\n}\n\ntheorem NotOrIffNotAndNot {p q:Prop}:\n  ¬ (p ∨ q) ↔ (¬ p) ∧ (¬ q) := by {\n  apply Iff.intro;\n  {\n    intro h;\n    by_cases hp:p;\n    {exact False.elim (h (Or.inl hp));}\n    {\n      by_cases hq:q;\n      {exact False.elim (h (Or.inr hq));}\n      {exact (And.intro hp hq)}\n    }\n  }\n  {\n    intro h hn;\n    cases hn;\n    case mpr.inl hn => {exact h.1 hn}\n    case mpr.inr hn => {exact h.2 hn}\n  }\n}\n\n\ntheorem NotAndIffNotOrNot {p q:Prop}:\n  ¬ (p ∧ q) ↔ (¬ p) ∨ (¬ q) := by {\n  apply Iff.intro;\n  {\n    intro h;\n    by_cases hp:p;\n    {\n      by_cases hq:q;\n      {exact False.elim (h (And.intro hp hq))}\n      {exact Or.inr hq;}\n    }\n    {exact Or.inl hp;}\n  }\n  {\n    intro h hn;\n    cases h;\n    case mpr.inl h => {exact h hn.1}\n    case mpr.inr h => {exact h hn.2}\n  }\n}\n\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/Init/Logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7960832092191461}}
{"text": "import logic.basic -- Needed for imp_false\n\nsection question11\n\nvariables P Q R : Prop\n\nexample (h : P ∧ (Q ∧ R)) : (P ∧ Q) ∧ R :=\nbegin\n  sorry\nend\n\nend question11\n\nsection question6\n\nvariables P Q R : Prop\n\nexample : (P ∧ R) ∨ (Q ∧ R) → (P ∨ Q) ∧ R :=\nbegin\n  sorry\nend\n\nend question6\n\nsection question9\n\nvariables A B C : Prop\n\nexample (h : C → A ∨ B) : (C ∧ ¬A) → B :=\nbegin\n  sorry\nend\n\n-- HINT: for this question, you may find it useful to to use `exfalso, contradiction` somewhere in the proof\n\nend question9", "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/exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7960605821408893}}
{"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.dual_number\n! leanprover-community/mathlib commit b8d2eaa69d69ce8f03179a5cda774fc0cde984e4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.TrivSqZeroExt\n\n/-!\n# Dual numbers\n\nThe dual numbers over `R` are of the form `a + bε`, where `a` and `b` are typically elements of a\ncommutative ring `R`, and `ε` is a symbol satisfying `ε^2 = 0`. They are a special case of\n`TrivSqZeroExt R M` with `M = R`.\n\n## Notation\n\nIn the `DualNumber` locale:\n\n* `R[ε]` is a shorthand for `DualNumber R`\n* `ε` is a shorthand for `DualNumber.eps`\n\n## Main definitions\n\n* `DualNumber`\n* `DualNumber.eps`\n* `DualNumber.lift`\n\n## Implementation notes\n\nRather than duplicating the API of `TrivSqZeroExt`, this file reuses the functions there.\n\n## References\n\n* https://en.wikipedia.org/wiki/Dual_number\n-/\n\n\nvariable {R : Type _}\n\n/-- The type of dual numbers, numbers of the form $a + bε$ where $ε^2 = 0$.-/\nabbrev DualNumber (R : Type _) : Type _ :=\n  TrivSqZeroExt R R\n#align dual_number DualNumber\n\n/-- The unit element $ε$ that squares to zero. -/\ndef DualNumber.eps [Zero R] [One R] : DualNumber R :=\n  TrivSqZeroExt.inr 1\n#align dual_number.eps DualNumber.eps\n\n-- mathport name: dual_number.eps\nscoped[DualNumber] notation \"ε\" => DualNumber.eps\n\n-- mathport name: dual_number\nscoped[DualNumber] postfix:1024 \"[ε]\" => DualNumber\n\nopen DualNumber\n\nnamespace DualNumber\n\nopen TrivSqZeroExt\n\n@[simp]\ntheorem fst_eps [Zero R] [One R] : fst ε = (0 : R) :=\n  fst_inr _ _\n#align dual_number.fst_eps DualNumber.fst_eps\n\n@[simp]\ntheorem snd_eps [Zero R] [One R] : snd ε = (1 : R) :=\n  snd_inr _ _\n#align dual_number.snd_eps DualNumber.snd_eps\n\n/-- A version of `TrivSqZeroExt.snd_mul` with `*` instead of `•`. -/\n@[simp]\ntheorem snd_mul [Semiring R] (x y : R[ε]) : snd (x * y) = fst x * snd y + snd x * fst y :=\n  TrivSqZeroExt.snd_mul _ _\n#align dual_number.snd_mul DualNumber.snd_mul\n\n@[simp]\ntheorem eps_mul_eps [Semiring R] : (ε * ε : R[ε]) = 0 :=\n  inr_mul_inr _ _ _\n#align dual_number.eps_mul_eps DualNumber.eps_mul_eps\n\n@[simp]\ntheorem inr_eq_smul_eps [MulZeroOneClass R] (r : R) : inr r = (r • ε : R[ε]) :=\n  ext (MulZeroClass.mul_zero r).symm (mul_one r).symm\n#align dual_number.inr_eq_smul_eps DualNumber.inr_eq_smul_eps\n\n/-- For two algebra morphisms out of `R[ε]` to agree, it suffices for them to agree on `ε`. -/\n@[ext]\n\n\nvariable {A : Type _} [CommSemiring R] [Semiring A] [Algebra R A]\n\n/-- A universal property of the dual numbers, providing a unique `R[ε] →ₐ[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!]\ndef lift : { e : A // e * e = 0 } ≃ (R[ε] →ₐ[R] A) :=\n  Equiv.trans\n    (show { e : A // e * e = 0 } ≃ { f : R →ₗ[R] A // ∀ x y, f x * f y = 0 } from\n      (LinearMap.ringLmapEquivSelf R ℕ A).symm.toEquiv.subtypeEquiv fun a => by\n        dsimp\n        simp_rw [smul_mul_smul]\n        refine' ⟨fun h x y => h.symm ▸ smul_zero _, fun h => by simpa using h 1 1⟩)\n    TrivSqZeroExt.lift\n#align dual_number.lift DualNumber.lift\n\n-- When applied to `ε`, `DualNumber.lift` produces the element of `A` that squares to 0.\n-- @[simp] -- Porting note: simp can prove this\ntheorem lift_apply_eps (e : { e : A // e * e = 0 }) : @lift R _ _ _ _ e (ε : R[ε]) = e := by\n  simp only [lift_apply_apply, fst_eps, map_zero, snd_eps, one_smul, zero_add]\n#align dual_number.lift_apply_eps DualNumber.lift_apply_eps\n\n-- Lifting `DualNumber.eps` itself gives the identity.\n@[simp]\ntheorem lift_eps : lift ⟨ε, eps_mul_eps⟩ = AlgHom.id R R[ε] :=\n  algHom_ext <| lift_apply_eps _\n#align dual_number.lift_eps DualNumber.lift_eps\n\nend DualNumber\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/DualNumber.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7960605700474336}}
{"text": "/-\nWe've already seen that we can assert\nthat a proposition is true by defining\na variable to have that proposition as\nits type, and we can prove the proposition\nby assigning a proof term to the variable.\n-/\n\nlemma zeqz : 0 = 0 := eq.refl 0\n\n/-\nSometimes it's harder to write an exact\nproof term (here, eq.refl 0). In these\ncases it can help to figure out a proof\nterm step by step. Lean supports step\nby step development of proof terms with\nwhat are called tactic-based proving.\nHere's an equivalent tactic-based proof.\n-/\n\nlemma zeqz' : 0 = 0 :=\nbegin\n  apply eq.refl 0,\nend\n\n/-\nIn this case, the proof is so simple\nthat writing a script is more work.\nThe key thing to see here, though, is\nthe \"apply\" tactic. It applies some\nalready known rule, here eq.refl, to\nmove from a state in which something\nis to be proved to a state in which\nsomething new has been proved.\n-/\n\n/-\nNow open the Lean Messages panel by typing\ncontrol-shift-enter or command-shift-enter\n(Windows/Mac). Now place your cursor first\nat the start of the \"apply\". The message\nwindow will display the \"tactic state\" at\nthis point in the script. The state say\nthat nothing is assumed and the remaining\ngoal to be proved is 0 = 0. Now move your\ncursor to the next line, before the \"end.\"\nThe tactic state is empty, nothing is left\nto be proved, QED. \n-/\n\n\n/-\nEXERCISE. Define zeqz'' as also\nbeing of type 0 = 0, but after the :=,\njust write begin on the next line and \nthen an end on the following line. You\nneed to type the begin and end lines\nbefore continuing.\n-/\n\n\n/-\nHOW TO SOLVE IT:\n\nInitially there will be an error. Hover\nover the red squiggle under the \"end.\"\nIt tells you that you haven't yet proved\nsomething that remains to be proved, and\nit tells you what remains to be proved.\n \nInsert a blank line between the begin and \nend. The tactic state tells you what is\nknown at a given point in a tactic script\n(before the turnstile character, ⊢, and \nwhat remains to be proved, after. Here, \nthe goal that remains is 0 = 0. \n\nIf you then click on the next line, end, \nLean tells you that the proof-generating \ntactic script between the begin and end\nlines failed because some goal remains to \nbe proved.\n\nIn general, a tactic will only partially \nprove a goal, leaving some parts still to \nbe proved. In such cases, more tactics \nare then used to finish the construction \nof the required proof. Tactic commands\nare separated by commas. We'll see more\nlater. \n\nGo ahead and type the required tactic  \nbetween begin and end. Click on the \nline with the tactic, then on the end. Watch how the tactic state changes as \nyou go from line to line. \n-/\n\n\n/-\nYou might have noticed that while \"apply\neq.refl 0\" finishes the proof, so does \njust \"apply eq.refl\". In this case, Lean\ninfers both arguments to eq.refl from \ncontext. That, in fact, is what rfl does.\nIt's not technically a tactic. It is just\nusing type inference to infer both of the\narguments needed for eq.refl!\n\nSome people refer to such a script as a\nproof. A better way to think about it is \nas a step-by-step recipe for building a \nproof. The actual proof at the end of the\nday is the proof object that the script\nconstructs: eq.refl 0, in this case.\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/07_tactics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.912436169406061, "lm_q1q2_score": 0.7959613060271523}}
{"text": "-- Pruebas_de_length_(repeat_x_n)_Ig_n.lean\n-- Pruebas de length (repeat x n) = n\n-- José A. Alonso Jiménez\n-- Sevilla, 7 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean están definidas las funciones length y repeat tales que\n-- + (length xs) es la longitud de la lista xs. Por ejemplo,\n--      length [1,2,5,2] = 4\n-- + (repeat x n) es la lista que tiene el elemento x n veces. Por\n--   ejemplo,\n--      repeat 7 3 = [7, 7, 7]\n--\n-- Demostrar que\n--    length (repeat x n) = n\n-- ---------------------------------------------------------------------\n\nimport data.list.basic\nopen nat\nopen list\n\nset_option pp.structure_projections false\n\nvariable {α : Type}\nvariable (x : α)\nvariable (n : ℕ)\n\n-- 1ª demostración\nexample :\n  length (repeat x n) = n :=\nbegin\n  induction n with n HI,\n  { calc length (repeat x 0)\n          = length []                : congr_arg length (repeat.equations._eqn_1 x)\n      ... = 0                        : length.equations._eqn_1 },\n  { calc length (repeat x (succ n))\n         = length (x :: repeat x n)  : congr_arg length (repeat.equations._eqn_2 x n)\n     ... = length (repeat x n) + 1   : length.equations._eqn_2 x (repeat x n)\n     ... = n + 1                     : congr_arg2 (+) HI rfl\n     ... = succ n                    : rfl, },\nend\n\n-- 2ª demostración\nexample :\n  length (repeat x n) = n :=\nbegin\n  induction n with n HI,\n  { calc length (repeat x 0)\n          = length []                : rfl\n      ... = 0                        : rfl },\n  { calc length (repeat x (succ n))\n         = length (x :: repeat x n)  : rfl\n     ... = length (repeat x n) + 1   : rfl\n     ... = n + 1                     : by rw HI\n     ... = succ n                    : rfl, },\nend\n\n-- 3ª demostración\nexample : length (repeat x n) = n :=\nbegin\n  induction n with n HI,\n  { refl, },\n  { dsimp,\n    rw HI, },\nend\n\n-- 4ª demostración\nexample : length (repeat x n) = n :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { simp [HI], },\nend\n\n-- 5ª demostración\nexample : length (repeat x n) = n :=\nby induction n ; simp [*]\n\n-- 6ª demostración\nexample : length (repeat x n) = n :=\nnat.rec_on n\n  ( show length (repeat x 0) = 0, from\n      calc length (repeat x 0)\n           = length []                : rfl\n       ... = 0                        : rfl )\n  ( assume n,\n    assume HI : length (repeat x n) = n,\n    show length (repeat x (succ n)) = succ n, from\n      calc length (repeat x (succ n))\n           = length (x :: repeat x n) : rfl\n       ... = length (repeat x n) + 1  : rfl\n       ... = n + 1                    : by rw HI\n       ... = succ n                   : rfl )\n\n-- 7ª demostración\nexample : length (repeat x n) = n :=\nnat.rec_on n\n  ( by simp )\n  ( λ n HI, by simp [HI])\n\n-- 8ª demostración\nexample : length (repeat x n) = n :=\nlength_repeat x n\n\n-- 9ª demostración\nexample : length (repeat x n) = n :=\nby simp\n\n-- 10ª demostración\nlemma length_repeat_1 :\n  ∀ n, length (repeat x n) = n\n| 0 := by calc length (repeat x 0)\n               = length ([] : list α)         : rfl\n           ... = 0                            : rfl\n| (n+1) := by calc length (repeat x (n + 1))\n                   = length (x :: repeat x n) : rfl\n               ... = length (repeat x n) + 1  : rfl\n               ... = n + 1                    : by rw length_repeat_1\n\n-- 11ª demostración\nlemma length_repeat_2 :\n  ∀ n, length (repeat x n) = n\n| 0     := by simp\n| (n+1) := by 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_(repeat_x_n)_Ig_n.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.9124361682155118, "lm_q1q2_score": 0.7959612898480243}}
{"text": "open classical\n\nvariables (α : Type*) (p q : α → Prop)\nvariable r : Prop\n\nexample : (∃ x : α, r) → r := \nassume ⟨w,hw⟩, hw\n\nexample (a : α) : r → (∃ x : α, r) := \nassume r,\nexists.intro a r\n\nexample : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := \niff.intro\n(assume h: ∃ x, p x ∧ r,\n  exists.elim h\n  (assume w,\n   assume hw: p w ∧ r,\n   show (∃ x, p x) ∧ r,\n    from ⟨exists.intro w hw.left, hw.right ⟩ ))\n(assume h: (∃ x, p x) ∧ r,\n  exists.elim h.left\n  (assume wl,\n   assume hwl: p wl,\n   show ∃ x, p x ∧ r, \n    from exists.intro wl ⟨hwl,  h.right⟩ ))\n\nexample : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := \niff.intro\n(assume h: ∃ x, p x ∨ q x,\n  exists.elim h\n  (assume w,\n  assume hw: p w ∨ q w,\n  hw.elim \n    (assume hp: p w,\n      or.inl (exists.intro w hp))\n    (assume hq: q w,\n      or.inr (exists.intro w hq))))\n(assume h: (∃ x, p x) ∨ (∃ x, q x),\n  h.elim\n    -- short version\n    (assume ⟨w, hw⟩, ⟨w, (or.inl hw)⟩)\n    -- long version\n    (assume hq: ∃ x, q x,\n      exists.elim hq\n      (assume w,\n      assume hw: q w,\n      show ∃ x, p x ∨ q x, from  exists.intro w (or.inr hw)))\n)\n\nexample : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := \niff.intro\n(assume h: ∀ x, p x,\n show ¬ (∃ x, ¬ p x), from\n (assume h1: ∃ x, ¬ p x,\n  show false, from exists.elim h1 \n    (assume w,\n     assume hw: ¬ p w,\n     hw (h w) \n    )\n )\n)\n(\n assume h: ¬ (∃ x, ¬ p x),\n assume w,\n or.elim (em (p w))\n  (assume pw: p w,\n   show p w, from pw)\n  (assume npw: ¬ p w,\n   show p w, from absurd (exists.intro w npw) h)\n)\n\n\n \n\nexample : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := sorry\n\n\n\n\n\n\nexample : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := sorry\nexample : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := sorry\n\nexample : (∀ x, p x → r) ↔ (∃ x, p x) → r := sorry\nexample (a : α) : (∃ x, p x → r) ↔ (∀ x, p x) → r := sorry\nexample (a : α) : (∃ x, r → p x) ↔ (r → ∃ x, p x) := sorry\n\n\n\n\n\n\n\n-- 4.6 exercises\n\n\n-- 3. barber paradox\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/part4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8723473763375643, "lm_q1q2_score": 0.7959612885904354}}
{"text": "import ..lectures.love02_backward_proofs_demo\n\n\n/-! # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nbegin\n  intro ha,\n  exact ha\nend\n\nlemma K (a b : Prop) :\n  a → b → b :=\nbegin\n  intros ha hb,\n  exact hb\nend\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nbegin\n  intros hg hb ha,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha\nend\n\n/-! Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha'\nend\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nbegin\n  intros hg ha hf hb,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\n/-! 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nbegin\n  intros hab hnb ha,\n  apply hnb,\n  apply hab,\n  apply ha\nend\n\n/-! 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    apply and.intro,\n    { intro x,\n      apply and.elim_left,\n      apply h },\n    { intro x,\n      apply and.elim_right,\n      apply h } },\n  { intros h x,\n    apply and.intro,\n    { apply and.elim_left h },\n    { apply and.elim_right h } }\nend\n\n\n/-! ## Question 2: Natural Numbers\n\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, mul, ih] }\nend\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, add_succ, add_assoc, mul, ih] }\nend\n\n/-! 2.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nbegin\n  induction' m,\n  { simp [mul, mul_zero] },\n  { simp [mul, mul_succ, ih],\n    cc }\nend\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nbegin\n  induction' n,\n  { refl },\n  { simp [mul, mul_add, ih] }\nend\n\n/-! 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nbegin\n  rw mul_comm _ n,\n  rw mul_add\nend\n\n\n/-! ## Question 3 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle : Prop :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce : Prop :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation : Prop :=\n∀a : Prop, (¬¬ a) → a\n\n/-! For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, as this would defeat the purpose of the exercise.\n\n3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nbegin\n  rw excluded_middle,\n  rw peirce,\n  intro hem,\n  intros a b haba,\n  apply or.elim (hem a),\n  { intro,\n    assumption },\n  { intro hna,\n    apply haba,\n    intro ha,\n    apply false.elim,\n    apply hna,\n    assumption }\nend\n\n/-! 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nbegin\n  rw peirce,\n  rw double_negation,\n  intros hpeirce a hnna,\n  apply hpeirce a false,\n  intro hna,\n  apply false.elim,\n  apply hnna,\n  exact hna\nend\n\n/-! We leave the remaining implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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/exercises/love02_backward_proofs_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.795940568912974}}
{"text": "-- begin header\n\nimport M40002.complete\n\nnamespace sequences\n-- end header\n\n/- Section\nChapter 3. Sequences\n-/\n\n/- Sub-section\nDefinitions\n-/\n\n/-\nLet $a : ℕ → ℝ$ be a real valued sequence, then we define convergence of $a$ to some\nreal $l$ in the standard way.\n-/\n\n/- Definition\nA real valued sequence $a_n : ℕ → ℝ$ is said to converge to $l ∈ ℝ$ if and only if for all\n$ε > 0$, there exists $N ∈ ℕ$ such that for all $n ≥ N$, $\\left| a_n - l \\right| < ε$. \n-/\ndef converges_to (a : ℕ → ℝ) (l : ℝ) :=  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, abs (a n - l) < ε \nnotation a ` ⇒ ` l := converges_to a l\n\n/- Definition\nWe call $a_n : ℕ → ℝ$ convergent if there exists $l ∈ ℝ$, $a_n$ converges to $l$.\n-/\ndef is_convergent (a : ℕ → ℝ) := ∃ l : ℝ, ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, abs (a n - l) < ε \n\n/- Definition\nWe call $a_n : ℕ → ℝ$ bounede above if and only if there exists $R ∈ ℝ$ such that for all\n$n ∈ ℕ$, $a_n ≤ R$.\n-/\ndef seq_bounded_above (a : ℕ → ℝ) := ∃ R : ℝ, ∀ m : ℕ, a m ≤ R\n\n/- Definition\nWe definte bounded below in a similar way.\n-/\ndef seq_bounded_below (a : ℕ → ℝ) := ∃ R : ℝ, ∀ m : ℕ, R ≤ a m\n\n/- Definition\nWe call $a_n : ℕ → ℝ$ bounded if and only if it is bounded above and below.\n-/\ndef seq_bounded (a : ℕ → ℝ) := seq_bounded_above a ∧ seq_bounded_below a\n\ndef seq_in (a : ℕ → ℝ) (S : set ℝ) := ∀ n : ℕ, a n ∈ S\nnotation a ` ⊆ ` S := seq_in a S\n\nexample (n : ℕ) (hn : 0 < n) : 0 ≤ 1 / n := by exact bot_le\n\n/- Example\nLet $a_n : ℕ → ℝ : n ↦ 1 / n$, then $a_n$ converges to 0.\n-/\nexample : (λ n : ℕ, 1 / n) ⇒ 0 :=\nbegin\n  -- We first fix $ε > 0$.\n  intros ε hε,\n  -- Then by choosing some $N ∈ ℕ$ such that $N > 1 / ε$,\n  cases (exists_nat_gt (1 / ε)) with N hN,\n  -- we now need to show that for all $n ≥ N$, $\\left| a_n - 0 \\right| < ε$.\n  refine ⟨N, λ n hn, _⟩,\n  -- Now as $\\left| a_n - 0 \\right| = a_n = 1 / n$, it suffices to show that $1 / n < ε$. \n  rw [sub_zero, abs_of_nonneg, (one_div_lt _ hε)], \n    { refine lt_of_lt_of_le hN (by norm_cast; assumption) },\n  -- But this follows from the transitivity of inequalities as $1 / n ≤ 1 / N ≤ ε$.\n    { refine lt_trans (one_div_pos_of_pos hε) (lt_of_lt_of_le hN (by norm_cast; assumption)) },\n    { simp [bot_le] }\nend\n\n/- Example\nLet $a_n : ℕ → ℝ : n ↦ c$ for some $c ∈ ℝ$. Then $a_n$ converges to $c$\n-/\ntheorem cons_conv {c : ℝ} : (λ n : ℕ, c) ⇒ c :=\nbegin\n  -- Again we fix $ε > 0$\n  intros ε hε,\n  -- Then by simply choosing our $N = 0$, \n  refine ⟨0, λ n hn, _⟩,\n  -- it suffices to show that for all $n ∈ ℕ$, $\\left| a_n - c \\right| < ε$. \n  -- But $\\left| a_n - c \\right|$ is simply zero, so we are done!\n  simpa\nend\n\n/-\nWe will now prove a very useful lemma that will come up now an again. \n-/\n\n/- Lemma\nIf $x_0$ and $x_1$ are real numbers such that for all $ε > 0$, $\\left| x₀ - x₁ \\right| < ε$,\nthen $x_0 = x_1$.\n-/\nlemma dist_zero {x₀ x₁ : ℝ}\n(h : ∀ (ε : ℝ) (hε : 0 < ε), abs (x₀ - x₁) < ε ) : x₀ = x₁ :=\nbegin\n  -- We will attempt to prove by contradiction, so suppose $x₀ ≠ x₁$.\n  apply classical.by_contradiction, intro hne,\n  -- Then by trichotomy, either $x₀ < x₁$ or $x₁ < x₀$.\n  cases lt_or_gt_of_ne hne with hlt hgt,\n  -- If $x₀ < x₁$ then by letting $ε = x₁ - x₀$ we have $\\left| x₀ - x₁ \\right| < x₀ - x₁$.\n    { refine not_le.2 (h (x₁ - x₀) (sub_pos.2 hlt)) _,\n  -- But this is a contradiction as for all $r ∈ ℝ$, \\left| r \\right| ≥ r$.\n      rw abs_sub, exact le_abs_self _ },\n  -- It's a similar story if $x₁ < x₀$.\n    { refine not_le.2 (h (x₀ - x₁) (sub_pos.2 hgt)) ( le_abs_self _) }\nend\n\n/-\nWith that, we will present a short proof that the limits of sequences are unique.\n-/\n\n/- Theorem\nLet $a_n : ℕ → ℝ$ converge to $b$ and $c$ both of which are real. Then $b = c$. \n-/\ntheorem unique_lim {a : ℕ → ℝ} {b c : ℝ} (hb : a ⇒ b) (hc : a ⇒ c) : b = c :=\nbegin\n  -- By the previous lemma, it suffices to show that for all $ε > 0, \\left| b - c \\right| < ε$.\n  apply dist_zero, \n  -- So let us fix ε > 0.\n  intros ε hε,\n  -- Then as $a_n$ converges to $b$, \n  -- there exists some $N₀ ∈ ℕ$ for all $n ≥ N₀, \\left a_n - b \\right < ε / 2$.\n  cases hb (ε / 2) (half_pos hε) with N₀ hN₀,\n  -- Similarly there must be some $N₁ ∈ ℕ$ for all $n ≥ N₁, \\left a_n - c \\right < ε / 2$.\n  cases hc (ε / 2) (half_pos hε) with N₁ hN₁,\n  -- So let's $N = \\max \\{N₀, N₁\\}$.\n  let N := max N₀ N₁,\n  -- Then by the triangle inequality, \n  -- we have $\\left| b - c \\right| ≤ \\left| b - a_N \\right| + \\left| a_N - c \\right| < ε / 2 + ε / 2 = ε$.\n  apply lt_of_le_of_lt (abs_sub_le b (a N) c),\n  linarith [show abs (b - a N) < ε / 2, by rw abs_sub; from hN₀ N (le_max_left _ _), \n  hN₁ N (le_max_right _ _)]\nend\n\n\n#exit\n\n-- If (a n) is convergent then its bounded\nlemma converge_is_bdd_abv (b : ℕ → ℝ) : is_convergent b → seq_bounded_above b :=\nbegin\n  rintro ⟨l, hl⟩,\n  cases (hl 1 _) with N hN,\n  swap, linarith,\n  let U := finset.image b (finset.range (N + 1)) ∪ {l + 1},\n  have : b 0 ∈ U := by simp,  \n  cases finset.max_of_mem this with R hR,\n  use R, intro m,\n  cases le_or_lt m N,\n    {have : b m ∈ U :=\n      by{simp, left, use m, from ⟨(nat_le_imp_lt_succ N m).mp h, rfl⟩},\n    from finset.le_max_of_mem this hR\n    },\n    {have : l + 1 ∈ U := by {simp},\n    replace this : l + 1 ≤ R :=\n      by {from finset.le_max_of_mem this hR},\n    apply le_trans _ this,\n    replace this : abs (b m - l) < 1 := hN m (le_of_lt h),\n    rw abs_lt at this,\n    from le_of_lt (sub_lt_iff_lt_add'.mp this.right)\n    }\nend\n\nlemma converge_is_bdd_blw (b : ℕ → ℝ) : is_convergent b → seq_bounded_below b :=\nbegin\n  rintro ⟨l, hl⟩,\n  cases (hl 1 _) with N hN,\n  swap, linarith,\n  let U := finset.image b (finset.range (N + 1)) ∪ {l + -1},\n  have : b 0 ∈ U := by simp,  \n  cases finset.min_of_mem this with R hR,\n  use R, intro m,\n  cases le_or_lt m N,\n    {have : b m ∈ U :=\n      by{simp, left, use m, from ⟨(nat_le_imp_lt_succ N m).mp h, rfl⟩},\n    from finset.min_le_of_mem this hR\n    },\n    {have : l + -1 ∈ U := by {simp},\n    replace this : R ≤ l + -1 :=\n      by {from finset.min_le_of_mem this hR},\n    apply le_trans this,\n    replace this : abs (b m - l) < 1 := hN m (le_of_lt h),\n    rw abs_lt at this,\n    from le_of_lt (lt_sub_iff_add_lt'.mp this.left)\n    }\nend\n\ntheorem converge_is_bdd (b : ℕ → ℝ) : is_convergent b → seq_bounded b := λ h, ⟨converge_is_bdd_abv b h, converge_is_bdd_blw b h⟩\n\n-- Defining addition for sequences\ndef seq_add_seq (a : ℕ → ℝ) (b : ℕ → ℝ) := λ n : ℕ, a n + b n\nnotation a ` + ` b := seq_add_seq a b\n\ndef seq_add_real (a : ℕ → ℝ) (b : ℝ) := λ n : ℕ, a n + b\nnotation a ` + ` b := seq_add_real a b\n\n-- Algebra of limits\ntheorem add_lim_conv (a b : ℕ → ℝ) (l m : ℝ) : a ⇒ l ∧ b ⇒ m → (a + b) ⇒ (l + m) :=\nbegin\n  rintros ⟨ha, hb⟩ ε hε,\n  have : ε / 2 > 0 := half_pos hε,\n  cases ha (ε / 2) this with N₁ hN₁,\n  cases hb (ε / 2) this with N₂ hN₂,\n  let N : ℕ := max N₁ N₂,\n  use N,\n  intros n hn,\n  have hrw : a n + b n - (l + m) = (a n - l) + (b n - m) := by {linarith},\n  unfold seq_add_seq,\n  rw hrw,\n  have hmax : N ≥ N₁ ∧ N ≥ N₂ := \n    by {split,\n      all_goals {rwa [ge_iff_le, le_max_iff], tauto}},\n  suffices h : abs (a n - l) + abs (b n - m) < ε,\n    from lt_of_le_of_lt (abs_add (a n - l) (b n - m)) h,\n  have h : abs (a n - l) + abs (b n - m) < ε / 2 + ε / 2 := \n    by {from add_lt_add (hN₁ n (ge_trans hn hmax.left)) (hN₂ n (ge_trans hn hmax.right))},\n  rwa add_halves' ε at h\nend\n \nlemma diff_seq_is_zero (a b : ℕ → ℝ) (l : ℝ) (h : a ⇒ l) : a = b + l → b ⇒ 0 :=\nbegin\n  unfold seq_add_real, unfold converges_to,\n  unfold converges_to at h,\n  intro ha,\n  rw ha at h, simp at h,\n  suffices : ∀ (ε : ℝ), 0 < ε → (∃ (N : ℕ), ∀ (n : ℕ), N ≤ n → abs (b n) < ε),\n    simpa,\n  assumption\nend\n\n-- Defining multiplication of sequences\ndef seq_mul_seq (a : ℕ → ℝ) (b : ℕ → ℝ) := λ n : ℕ, a n * b n\nnotation a ` × ` b := seq_mul_seq a b\n\ndef seq_mul_real (a : ℕ → ℝ) (b : ℝ) := λ n : ℕ, a n * b\nnotation a ` × ` b := seq_mul_real a b\n\ntheorem mul_lim_conv (a b : ℕ → ℝ) (l m : ℝ) (ha : a ⇒ l) (hb : b ⇒ m) : (a × b) ⇒ l * m :=\nbegin\n  sorry\nend\n\n-- Defining division of sequences\nnoncomputable def seq_div_seq (a : ℕ → ℝ) (b : ℕ → ℝ) := λ n : ℕ, (a n) / (b n) \nnoncomputable instance : has_div (ℕ → ℝ) := ⟨seq_div_seq⟩\n\ntheorem div_lim_conv (a b : ℕ → ℝ) (l m : ℝ) (ha : a ⇒ l) (hb : b ⇒ m) (hc : m ≠ 0) : (a / b) ⇒ l / m :=\nbegin\n  sorry\nend\n\n-- Defining monotone increasing and decreasing sequences\ndef mono_increasing (a : ℕ → ℝ) := ∀ n : ℕ, a n ≤ a (n + 1)\nnotation a ` ↑ ` := mono_increasing a\n\ndef mono_increasing_conv (a : ℕ → ℝ) (l : ℝ) := mono_increasing a ∧ a ⇒ l\nnotation a ` ↑ ` l := mono_increasing a l\n\ndef mono_decreasing (a : ℕ → ℝ) := ∀ n : ℕ, a (n + 1) ≤ a n\nnotation a ` ↓ ` := mono_decreasing a\n\ndef mono_decreasing_conv (a : ℕ → ℝ) (l : ℝ) := mono_decreasing a ∧ a ⇒ l\nnotation a ` ↓ ` l := mono_decreasing a l\n\nlemma le_chain (N : ℕ) (b : ℕ → ℝ) (h : mono_increasing b) : ∀ n : ℕ, N ≤ n → b N ≤ b n :=\nbegin\n  intros n hn,\n  have ha : ∀ k : ℕ, b N ≤ b (N + k) :=\n    by {intro k,\n    induction k with k hk,\n      {refl},\n      {from le_trans hk (h (N + k))}\n    },\n  have : ∃ k : ℕ, N + k = n := nat.le.dest hn,\n  cases this with k hk,\n  rw ←hk,\n  from ha k\nend\n\nlemma ge_chain (N : ℕ) (b : ℕ → ℝ) (h : mono_decreasing b) : ∀ n : ℕ, N ≤ n → b n ≤ b N :=\nbegin\n  intros n hn,\n  have ha : ∀ k : ℕ, b (N + k) ≤ b N :=\n    by {intro k,\n    induction k with k hk,\n      {refl},\n      {from le_trans (h (N + k)) hk}\n    },\n  have : ∃ k : ℕ, N + k = n := nat.le.dest hn,\n  cases this with k hk,\n  rw ←hk,\n  from ha k\nend\n\n-- Monotone increasing and bounded means convergent (to the supremum)\nlemma mono_increasing_means_conv_sup (b : ℕ → ℝ) (M : ℝ) (h₁ : mono_increasing b) (h₂ : seq_bounded b) (h₃ : sup {t : ℝ | ∃ n : ℕ, t = b n} M) : b ⇒ M :=\nbegin\n  rcases h₂ with ⟨⟨N, habv⟩, hblw⟩,\n  intros ε hε,\n  clear habv N,\n  have : ∃ N : ℕ, M - ε < b N :=\n    by {cases h₃ with hubd hnubd,\n    unfold upper_bound at hnubd,\n    push_neg at hnubd,\n    have : M - ε < M := \n      by {rw gt_iff_lt at hε,\n      from sub_lt_self M hε},\n    rcases hnubd (M - ε) this with ⟨s, ⟨hs₁, hs₂⟩⟩,\n    rw set.mem_set_of_eq at hs₁,\n    cases hs₁ with n hn,\n    use n, rwa ←hn\n    },\n  cases this with N hN,\n  use N, intros n hn,\n  rw abs_of_nonpos,\n    {have : ∀ n : ℕ, N ≤ n → b N ≤ b n := le_chain N b h₁,\n    suffices : M - ε < b n,\n      simp, from sub_lt.mp this,\n    from lt_of_lt_of_le hN (this n (iff.rfl.mp hn))\n    },\n    cases h₃,\n    have : b n ≤ M := by {apply h₃_left, rwa set.mem_set_of_eq, use n},\n    from sub_nonpos_of_le this\nend\n\ntheorem mono_increasing_means_conv (b : ℕ → ℝ) (h₁ : mono_increasing b) (h₂ : seq_bounded b) : is_convergent b :=\nbegin\n  let α : set ℝ := {t : ℝ | ∃ n : ℕ, t = b n},\n  have : ∃ M : ℝ, sup α M :=\n    by {rcases h₂ with ⟨⟨R, habv⟩, hblw⟩,\n      apply completeness α,\n      {use R, rintros s ⟨n, hs⟩,\n      suffices : b n ≤ R, rwa ←hs at this,\n      from habv n\n      },\n      {suffices : b 0 ∈ α,\n        apply set.not_eq_empty_iff_exists.mpr,\n        use b 0, assumption,\n      rw set.mem_set_of_eq,\n      use 0\n      }        \n    },\n  cases this with M hM,\n  use M,\n  from mono_increasing_means_conv_sup b M h₁ h₂ hM\nend\n\n-- Monotone decreasing and bounded means convergent (to the infimum)\nlemma mono_decreasing_means_conv_inf (b : ℕ → ℝ) (M : ℝ) (h₁ : mono_decreasing b) (h₂ : seq_bounded b) (h₃ : inf {t : ℝ | ∃ n : ℕ, t = b n} M) : b ⇒ M :=\nbegin\n  intros ε hε,\n  have : ∃ N : ℕ, b N < M + ε :=\n    by {cases h₃ with hlbd hnlbd,\n    unfold lower_bound at hnlbd,\n    push_neg at hnlbd,\n    have : M < M + ε := by {linarith},\n    rcases hnlbd (M + ε) this with ⟨s, ⟨hs₁, hs₂⟩⟩,\n    rw set.mem_set_of_eq at hs₁,\n    cases hs₁ with n hn,\n    use n, rwa ←hn\n    },\n  cases this with N hN,\n  use N, intros n hn,\n  rw abs_lt, split,\n    {suffices : M - ε < b n, linarith,\n    have : M ≤ b n := by {apply h₃.left (b n), rw set.mem_set_of_eq, use n},\n    have hα : M - ε < M := by {linarith},\n    from lt_of_lt_of_le hα this\n    },\n    {suffices : b n < M + ε, linarith,\n    from lt_of_le_of_lt (ge_chain N b h₁ n (iff.rfl.mp hn)) hN\n    }\nend \n\ntheorem mono_decreasing_means_conv (b : ℕ → ℝ) (h₁ : mono_decreasing b) (h₂ : seq_bounded b) : is_convergent b :=\nbegin\n  let α : set ℝ := {t : ℝ | ∃ n : ℕ, t = b n},\n  have : ∃ M : ℝ, inf α M :=\n    by {rcases h₂ with ⟨habv, ⟨R, hblw⟩⟩,\n      apply completeness_below α,\n      {use R, rintros s ⟨n, hs⟩,\n      rw hs,\n      from hblw n\n      },\n      {suffices : b 0 ∈ α,\n        apply set.not_eq_empty_iff_exists.mpr,\n        use b 0, assumption,\n      rw set.mem_set_of_eq,\n      use 0\n      }        \n    },\n  cases this with M hM,\n  use M,\n  from mono_decreasing_means_conv_inf b M h₁ h₂ hM\nend\n\n-- Defining order on sequences (is this necessary?)\ndef le_seq (a b : ℕ → ℝ) := ∀ n : ℕ, a n ≤ b n\nnotation a ` ≤* ` b := le_seq a b\n\ndef lt_seq (a b : ℕ → ℝ) := ∀ n : ℕ, a n < b n\nnotation a ` <* ` b := lt_seq a b\n\ndef ge_seq (a b : ℕ → ℝ) := ∀ n : ℕ, a n ≥ b n\nnotation a ` ≥* ` b := ge_seq a b\n\ndef gt_seq (a b : ℕ → ℝ) := ∀ n : ℕ, a n > b n\nnotation a ` >* ` b := gt_seq a b\n\n-- Comparison of sequences\ntheorem le_lim (a b : ℕ → ℝ) (l m : ℝ) (ha : a ⇒ l) (hb : b ⇒ m) : (a ≤* b) → l ≤ m :=\nbegin\n  rw ←not_lt,\n  intros h hlt,\n  have hδ : (l - m) / 2 > 0 := half_pos (sub_pos.mpr hlt),\n  cases ha ((l - m) / 2) hδ with N₁ hN₁,\n  cases hb ((l - m) / 2) hδ with N₂ hN₂,\n  let N := max N₁ N₂,\n  have hmax : N ≥ N₁ ∧ N ≥ N₂ := \n    by {split,\n      all_goals {rwa [ge_iff_le, le_max_iff], tauto}},\n  replace hN₁ : abs (a N - l) < (l - m) / 2 := hN₁ N hmax.left,\n  replace hN₂ : abs (b N - m) < (l - m) / 2 := hN₂ N hmax.right,\n  have hα : (l + m) / 2 < a N := \n    by {rw abs_lt at hN₁,\n    cases hN₁ with hl hr,\n    linarith\n    },\n  have hβ : b N < (l + m) / 2 := \n    by {rw abs_lt at hN₂,\n    cases hN₂ with hl hr,\n    linarith\n    },\n  have : b N < a N := lt_trans hβ hα,\n  rw ←not_le at this,\n  from this (h N)\nend\n\n-- Sandwich Theorem. Suppose that an ≤ bn ≤ cn ∀n and that an → a and cn → a, Then bn → a.\ntheorem sandwich {a b c : ℕ → ℝ} {l : ℝ} (h₀ : a ⇒ l) (h₁ : c ⇒ l) : (a ≤* b) ∧ (b ≤* c) → b ⇒ l :=\nbegin\n  rintro ⟨ha, hb⟩,\n  intros ε hε,\n  cases (h₀ ε hε) with N₀ hN₀,\n  cases (h₁ ε hε) with N₁ hN₁,\n  let N := max N₀ N₁,\n  have hN : N₀ ≤ N ∧ N₁ ≤ N := by {finish},\n  use N,\n  intros n hn,\n  cases lt_or_ge (b n) l with hlt hge,\n    {rw [abs_sub, abs_of_pos (sub_pos.mpr hlt)],\n    apply lt_of_le_of_lt _ (hN₀ n (le_trans hN.left hn)),\n    apply le_trans ((sub_le_sub_iff_left l).mpr (ha n)) _,\n    rw abs_sub,\n    from le_abs_self (l - a n)\n    },\n    {rw abs_of_nonneg (sub_nonneg.mpr hge),\n    apply lt_of_le_of_lt _ (hN₁ n (le_trans hN.right hn)),\n    apply le_trans (add_le_add_right' (hb n)) _,\n    from le_abs_self (c n - l)\n    }\nend\n\n-- Cauchy Sequences\ndef cauchy (a : ℕ → ℝ) := ∀ ε > 0, ∃ N : ℕ, ∀ n m : ℕ, N ≤ n ∧ N ≤ m → abs (a n - a m) < ε\n\n-- Convergent implies Cauchy\nlemma conv_to_cauchy (a : ℕ → ℝ) (h : is_convergent a) : cauchy a :=\nbegin\n  cases h with l hl,\n  intros ε hε,\n  cases hl (ε / 2) (half_pos hε) with N hN,\n  use N, intros n m hnm,\n  suffices : abs (a n - l) + abs (a m - l) < ε,\n    {rw abs_sub (a m) l at this,\n    have h : abs (a n - l + (l - a m)) < ε :=\n      lt_of_le_of_lt (abs_add_le_abs_add_abs (a n - l) (l - a m)) this,\n    rwa sub_add_sub_cancel (a n) l (a m) at h\n    },\n  have h : abs (a n - l) + abs (a m - l) < ε / 2 + ε / 2 := \n    add_lt_add (hN n hnm.left) (hN m hnm.right),\n  linarith        \nend\n\n-- We will prove that Cauchy implies bounded after subsequences!\n\n-- Subsequences\ndef is_subseq (a b : ℕ → ℝ) := ∃ n : ℕ → ℕ, (strict_mono n ∧ ∀ i : ℕ, b i = a (n i))\n\n-- b n = 1 is a subsequence of a n = (-1)^ n\nexample (a b : ℕ → ℝ) (h₁ : a = λ i, (- 1)^ i) (h₂ : b = λ i, 1) : is_subseq a b :=\nbegin\n  let n := λ i, 2 * i,\n  unfold is_subseq,\n  use n, split,\n    {intros a b, finish},\n    {intro i,\n    have : n = λ (i : ℕ), 2 * i, refl, \n    rwa [h₁, h₂, this], simp,\n    rw pow_mul, \n    finish\n    }\nend\n\n-- Every sequence has atleast one subsequence\ntheorem has_subseq (a : ℕ → ℝ) : ∃ b : ℕ → ℝ, is_subseq a b :=\nbegin\n  use a,\n  unfold is_subseq,\n  let n : ℕ → ℕ := λ i, i,\n  have : n = λ i, i := rfl,\n  use n, split,\n    {intros a b hab,\n    rw this, simpa\n    },\n    {intro i,\n    rwa this,\n    }\nend\n\n-- n(i) ≥ i ∀ i ∈ ℕ\nlemma subseq_ge_id {n : ℕ → ℕ} (h : strict_mono n) : ∀ i : ℕ, i ≤ n i :=\nbegin\n  intro i,\n  induction i with i hi,\n    {from zero_le (n 0)},\n    {have : (n i) + 1 ≤ n (nat.succ i) :=\n      by {rw nat.succ_le_iff,\n      from h (lt_add_one i)\n      },\n    from le_trans (nat.pred_le_iff.mp hi) this\n    }\nend\n\n-- Bolzano-Weierstrass : Every bounded sequence has a convergent subsequence\ntheorem bolzano_weierstrass {a : ℕ → ℝ} (h₁ : seq_bounded a) : ∃ b : ℕ → ℝ, is_subseq a b ∧ is_convergent b :=\nbegin\n  sorry\nend\n\n-- a → l iff. all subsequences of a also converges to l\ntheorem conv_subseq {a : ℕ → ℝ} {l : ℝ} : a ⇒ l ↔ (∀ b : ℕ → ℝ, is_subseq a b → b ⇒ l) :=\nbegin\n  split,\n    {rintros h b ⟨n, ⟨hn₁, hn₂⟩⟩ ε hε,\n    cases (h ε hε) with N hN,\n    use N, intros i hi,\n    rw hn₂ i,\n    have : n i ≥ N := ge_trans (subseq_ge_id hn₁ i) hi,\n    from hN (n i) this\n    },\n    {intro h,\n    let n : ℕ → ℕ := λ i, i,\n    let b : ℕ → ℝ := a,\n    have : is_subseq a b :=\n      by {use n, split,\n      have : n = λ i, i := rfl,\n        {intros a b hab,\n        rw this, simpa},\n        {simp},\n      },\n    have ha : a = b := rfl,\n    rw ha, from h b this\n    }\nend\n\n-- Cauchy implies bounded\nlemma cauchy_bounded_abv (b : ℕ → ℝ) : cauchy b → seq_bounded_above b :=\nbegin\n  intro hb,\n  cases (hb 1 _) with N hN,\n  swap, linarith,\n  let U := finset.image b (finset.range (N + 1)) ∪ {b N + 1},\n  have : b 0 ∈ U := by simp,  \n  cases finset.max_of_mem this with R hR,\n  use R, intro m,\n  cases le_or_lt m N,\n    {have : b m ∈ U :=\n      by{simp, left, use m, from ⟨(nat_le_imp_lt_succ N m).mp h, rfl⟩},\n    from finset.le_max_of_mem this hR\n    },\n    {have : b N + 1 ∈ U := by {simp},\n    replace this : b N + 1 ≤ R :=\n      by {from finset.le_max_of_mem this hR},\n    apply le_trans _ this,\n    replace this : abs (b m - b N) < 1 := hN m N ⟨le_of_lt h, le_refl N⟩,\n    rw abs_lt at this,\n    from le_of_lt (sub_lt_iff_lt_add'.mp this.right)\n    }\nend\n\nlemma cauchy_bounded_blw (b : ℕ → ℝ) : cauchy b → seq_bounded_below b :=\nbegin\n  intro hb,\n  cases (hb 1 _) with N hN,\n  swap, linarith,\n  let U := finset.image b (finset.range (N + 1)) ∪ {b N + -1},\n  have : b 0 ∈ U := by simp,  \n  cases finset.min_of_mem this with R hR,\n  use R, intro m,\n  cases le_or_lt m N,\n    {have : b m ∈ U :=\n      by{simp, left, use m, from ⟨(nat_le_imp_lt_succ N m).mp h, rfl⟩},\n    from finset.min_le_of_mem this hR\n    },\n    {have : b N + -1 ∈ U := by {simp},\n    replace this : R ≤ b N + -1 :=\n      by {from finset.min_le_of_mem this hR},\n    apply le_trans this,\n    replace this : abs (b m - b N) < 1 := hN m N ⟨le_of_lt h, le_refl N⟩,\n    rw abs_lt at this,\n    from le_of_lt (lt_sub_iff_add_lt'.mp this.left)\n    }\nend\n\n\nlemma cauchy_bounded (a : ℕ → ℝ) : cauchy a → seq_bounded a := λ h, ⟨cauchy_bounded_abv a h, cauchy_bounded_blw a h⟩\n\n-- Cauchy implies convergent\nlemma cauchy_to_conv (a : ℕ → ℝ) (h : cauchy a) : is_convergent a :=\nbegin\n  rcases bolzano_weierstrass (cauchy_bounded a h) with ⟨b, ⟨⟨n, ⟨hb₁, hb₂⟩⟩, ⟨l, hl⟩⟩⟩,\n  use l, intros ε hε,\n  cases h (ε / 2) (half_pos hε) with N₁ hN₁,\n  cases hl (ε / 2) (half_pos hε) with N₂ hN₂,\n  let N := n (max N₁ N₂),\n  use N, intros i hi,\n  suffices : abs (a i - a N) + abs (a N - l) < ε,\n    apply lt_of_le_of_lt _ this,\n    have hβ: a i - a N + (a N - l) = a i - l := by {linarith},\n    rw ←hβ,\n    from abs_add (a i - a N) (a N - l),\n  have hα : abs (a i - a N) + abs (a N - l) < ε / 2 + ε / 2 := \n    by {have : N = n (max N₁ N₂) := rfl,\n      apply add_lt_add,\n      {have hβ : N₁ ≤ N :=\n        by {rw this, from le_trans (le_max_left N₁ N₂) (subseq_ge_id hb₁ (max N₁ N₂))},\n      have hγ : N₁ ≤ i := by {from le_trans hβ hi},\n      from hN₁ i N ⟨hγ, hβ⟩\n      },\n      {have hβ : N₂ ≤ N :=\n        by {rw this, from le_trans (le_max_right N₁ N₂) (subseq_ge_id hb₁ (max N₁ N₂))},\n      apply lt_of_le_of_lt _ (hN₂ (max N₁ N₂) (le_max_right N₁ N₂)),\n      rwa hb₂ (max N₁ N₂)\n      }\n    },\n  linarith\nend\n\n-- Cauchy iff. convergent\ntheorem cauchy_iff_conv {a : ℕ → ℝ} : cauchy a ↔ is_convergent a :=\nbegin\n  split,\n    {intro h, from cauchy_to_conv a h},\n    {intro h, from conv_to_cauchy a h}\nend\n\nend sequences", "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/sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.7959405529210726}}
{"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 number_theory.divisors -- added to make Bhavik's proof work\n\n/-\n\n# Find all integers x ≠ 3 such that x - 3 divides x^3 - 3\n\nThis is the second question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nMy solution: x - 3 divides x^3-27, and hence if it divides x^3-3\nthen it also divides the difference, which is 24. Conversely,\nif x-3 divides 24 then because it divides x^3-27 it also divides x^3-3.\nBut getting Lean to find all the integers divisors of 24 is a nightmare!\nBhavik (last year) managed to figure out how to do this.\n\n-/\n\n-- This isn't so hard\nlemma lemma1 (x : ℤ) : x - 3 ∣ x^3 - 3 ↔ x - 3 ∣ 24 :=\nbegin\n  have h : x - 3 ∣ x ^ 3 - 27,\n  { use x ^ 2 + 3 * x + 9,\n    ring, },\n  split,\n  { intro h1,\n    have h2 := dvd_sub h1 h,\n    convert h2,\n    ring },\n  { intro h1,\n    convert dvd_add h h1,\n    ring },\nend\n\nlemma int_dvd_iff (x : ℤ) (n : ℤ) (hn : n ≠ 0) :\n  x ∣ n ↔ x.nat_abs ∈ n.nat_abs.divisors :=\nby simp [hn]\n\n-- Thanks to Bhavik Mehta for showing me how to prove this in Lean 3 without timing out!\nlemma lemma2 (x : ℤ) : x ∣ 24 ↔ x ∈ ({-24,-12,-8,-6,-4,-3,-2,-1,1,2,3,4,6,8,12,24} : set ℤ) :=\nbegin\n  suffices : x ∣ 24 ↔ x.nat_abs ∈ ({1,2,3,4,6,8,12,24} : finset ℕ),\n  { simp only [this, int.nat_abs_eq_iff, set.mem_insert_iff, set.mem_singleton_iff,\n      finset.mem_insert, finset.mem_singleton],\n    norm_cast,\n    rw ←eq_iff_iff,\n    ac_refl },\n  exact int_dvd_iff _ 24 (by norm_num),\nend\n\n-- This seems much harder :-) (it's really a computer science question, not a maths question,\n-- feel free to skip)\nexample (x : ℤ) : x - 3 ∣ x^3 - 3 ↔ x ∈ ({-21, -9, -5, -3, -1, 0, 1, 2, 4, 5, 6, 7, 9, 11, 15, 27} : set ℤ)  :=\nbegin\n  rw lemma1,\n  rw lemma2,\n  simp only [set.mem_insert_iff, sub_eq_neg_self, set.mem_singleton_iff],\n  repeat {apply or_congr },\n  all_goals { omega },\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/section15number_theory/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8824278556326343, "lm_q1q2_score": 0.7958799238879959}}
{"text": "import data.set\nopen set\n/-\nNOTE: The final exam is comprehensive, but this practice\nexam is not. In addition to working through this practice\nexam, you should revisit the exam1 and exam2 practice\nexams.\n-/\n\n/- SETS -/\nnamespace sets\n\n/-\n1.\n\nProve that 1 is in the set {1, 2, 3, 4, 5}.\n-/\n\nexample: 1 ∈ ({1, 2, 3, 4, 5}: set ℕ) :=\nbegin\n  _\nend\n\n/-\n2.\n\nProve that 1 is not in the set {2, 3, 4}.\n-/\n\nexample: 1 ∉ ({2, 3, 4}: set ℕ) :=\nbegin\n  _\nend\n\n/-\n3.\n\nProve that there does not exist any natural number that is\na member of the empty set of natural numbers.\n-/\n\nexample: ¬(∃ n:ℕ, n ∈ (∅: set ℕ)) :=\nbegin\n  _\nend\n\n/-\n4.\n\nProve that the intersection of the sets of natural numbers\n{1, 2} and {3, 4} is empty by showing that for all natural\nnumbers, they are not in the intersection of {1, 2} and\n{3, 4}.\n-/\n\n#reduce 2 ∈ ({3, 4}: set ℕ)\n\nexample: ∀n: ℕ, n ∉ ({1, 2}: set ℕ) ∩ ({3, 4}: set ℕ) :=\nbegin\n  _\nend\n\n/-\n5.\n\nProve that 1 is in the difference between {1, 2, 3} and {3, 4}\n-/\n\nexample: 1 ∈ ({1, 2, 3}: set ℕ) \\ ({3, 4}: set ℕ) :=\nbegin\n  _\nend\n\n/-\n6.\n\nProve that {2, 3} is a subset of the union of {1, 2} and {3, 4}\nNote: use ⊆ not ⊂\n-/\n\nexample: ({2, 3}: set ℕ) ⊆ ({1, 2}: set ℕ) ∪ ({3, 4}: set ℕ) :=\nbegin\n  _\nend\n\n/-\n7.\n\nProve that {2, 3} is an element of the powerset of {1, 2, 3, 4}\n-/\n\n#reduce {2, 3} ∈ 𝒫({1, 2, 3, 4}: set ℕ)\n-- ∀ ⦃a : ℕ⦄, a = 3 ∨ a = 2 ∨ false → a = 4 ∨ a = 3 ∨ a = 2 ∨ a = 1 ∨ false\n\nexample: {2, 3} ∈ 𝒫({1, 2, 3, 4}: set ℕ) :=\nbegin\n  _\nend\n\nend sets\n\n/- RELATIONS -/\nnamespace relations\n\n/-\nThe following problems on relations use definitions\nof properties of relations from the Lean library that\nare identical to those we studied in class.\n-/\n\n\n/-\n1.\n\nProve that disjunction has the symmetric property\n-/\n\nexample: symmetric or :=\nbegin\n  _\nend\n\n/-\n2.\n\nProve that conjunction is a subrelation of disjunction\n-/\n\nexample: subrelation and or :=\nbegin\n  _\nend\n\n/-\n3. \n\nWhat is the transitive closure of the relation on\nℕ represented by the set { (1,2), (2, 3) }? Write\nyour answer as a related set in a comment below.\n-/\n\n/-\nYour answer here: \n-/\n\nend relations\n\n/-\n===================================================\nInductive types, functions, properties, and proofs.\n====================================================\n-/\n\n/-\n1.\n\nDefine a function, sub_mynat : mynat → mynat → mynat,\nthat implements subtraction of the second argument, m,\nfrom the first, n. If m >= n, the result should be 0, \notherwise it should be n - m. Hint: Think about cases\nwhere one of the arguments is zero, and otherwise note\nthe following pattern: 3 - 2 = 2 - 1 = 1 - 0 = 1.\n-/\n\nnamespace mynat\n\ninductive mynat : Type \n| zero : mynat\n| succ : mynat → mynat\n\n-- def sub_mynat: mynat → mynat → mynat\n\n/-\n2.\n\nProve that ∀ n, sub_mynat n n = 0.\n-/\n\n\n/-\n3.\n\nWe give you a copy of the add_mynat function\nbelow. Show that our definition of add_mynat \nis associative. \n-/\n\ndef add_mynat: mynat → mynat → mynat\n| mynat.zero m := m\n| (mynat.succ n') m :=\n    mynat.succ (add_mynat n' m)\n\nexample: ∀(a b c: mynat),\n  add_mynat a (add_mynat b c) = add_mynat (add_mynat a b) c :=\nbegin\n  _\nend\n\nend mynat\n\n\n/-\nSimple inductive types.\n-----------------------\n-/\n\n/-\n3.\n\nDefine a new type called day having\nthese seven constant constructors: \nsunday, monday, tuesday, wednesday,\nthursday, friday, saturday. We will\ninterpret these constructors as \nrepresenting the actual days of the\nweek. Write your code below here now.\n-/\n\ninductive day : Type\n-- finish this definition here\n\n\n-- We suggest you open the day namespace\n\nopen day\n\n\n/-\n4.\n\nDefine a function, nextday : day → day,\nthat, when given a value, d : day, returns \nthe day value that represents the next day\nof the week. Hint: either write a function\nusing a \"match d with ... end\", or, if you\nprefer, use a tactic script (to write code!).\nIf you use a tactic script, use \"cases d\" \nand for each possible case of d, specify \nthe exact day to be returned in that case. \nFor extra credit do it both ways and write \na single sentence to describe how these two \nrepresentations correspond.\n-/\n\ndef nextday (d : day) : day :=\nbegin\n  _\nend\n\n\n/-\n5.\n\nFormalize and prove the proposition that \nfor any day, d, if you apply nextday to d\nseven times, the result is that very same \nd. Write both the proposition to be proved\nand its proof using \"example\". \n-/\n\n-- Your answer here\n\n\n/-\nRecursive (nested) inductive types.\n-----------------------------------\n-/\n\n/-\n6.\n\nGive an inductive type definition for nat_list,\nso that values of this type represent lists of\nvalues of type ℕ.\n\nWhile there's an infinity of such lists, we can\ncleverly define the set inductively with just two\nrules.\n\nFirst, there is an empty list of natural numbers. \nWe will represent it with the constant constructor, \nnil_nat. Make it one of the nat_list constructors.\n\nSecond, if we are given a nat_list value, l, and \na ℕ value, e : ℕ, we can always construct a list\nthat is one longer than by prepending e to l. To\ndo this, define a constructor called nat_cons. It \ntake arguments, e : ℕ and l : ₤st_nat, and yield a \nnat_list.\n-/\n\ninductive nat_list : Type \n-- finish the definition here\n\n-- we suggest you open the nat_list namespace\n\nopen nat_list\n\n\n/-\n7.\n\nDefine X to be the nat_list value that we\ninterpret as representing the empty list of\nnatural numbers, []; Y to be the nat_list \nvalue that represents the list, [1]; and\nfinally Z to represent the list, [2, 1].\n-/\n\ndef X : nat_list := _\ndef Y : nat_list := _\ndef Z : nat_list := _\n\n\n/-\n8.\n\nDefine a function (it will be recursive)\nthat takes any nat_list value and that\nreturns its length (a natural number that\nindicates how many values are in the list). \nCall the function, length.\n\nThe challenge is to see the recursion in \nthe definition of the length of a list.\nHint questions: What is the length of the\nempty list? What is the length of a list\nthat is not empty, and that thus must be\nof the form (nat_cons h t), where h is the\nvalue at the head of the list and t is the\nrest of the list.\n-/\n\n\n/- \nUncomment the following line\nand finish the definition\n-/\n\n--def length : nat_list → ℕ \n\n\n/-\nThe stuff that follows is challenging\nGet solid on the more basic stuff before \ngoing here.\n-/\n\n/-\n9.\n\nDefine a function, app (short for \"append\"), \nthat takes two nat_list values, let's call them\nl1 and l2, and that returns the nat_list with \nthe elements of the first list followed by the\nelements of the second list. For example, \n(app Y Z) should return the list [1, 2, 1].\n\n\nHint: Consider the possible forms of l1. It \ncan only be either nat_nil or (nat_cons h t),\nwhere, once again, h is is first element in \nl1, and t is the rest of the list. Write the \nfunction recursively accordingly.\n-/\n\ndef app : nat_list → nat_list → nat_list\n_\n\n/-\n10.\n\nProve the following\n\n∀ l1 l2 : nat_list, \n(length l1 + length l2) = length (append l1 l2)\n\nHint: use proof by induction on l1. There will be\ntwo cases. In the first, l1 will be nat_nil, and\nits length will reduce directly to 0. In the second\ncase, you will show that if the property is true for \nsome list l1', it is true for  next bigger list: one \nin the form of (nat_cons h l1').\n-/\n\nexample : ∀ l1 l2 : nat_list, \n(length l1 + length l2) = \nlength (app l1 l2) :=\nbegin\n  _\nend\n\n/- Formal Languages -/\n\nnamespace formal\n/-\n1.\n\nExtend the following formal language to incorporate \"or\"\nin a manner similar to \"and\"\n-/\n\ninductive pVar : Type \n| mk : ℕ → pVar\n\ninductive pExp : Type\n| mk_lit_pexp : bool → pExp\n| mk_var_pexp : pVar → pExp\n| mk_not_pexp : pExp → pExp\n| mk_and_pexp : pExp → pExp → pExp\n\nopen pExp\n\ndef pInterp := pVar → bool\n\ndef pEval : pExp → pInterp → 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\nend formal\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/exam3-practice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7958152662822463}}
{"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-/\n\nimport Mathlib.Init.Algebra.Order\n\nuniverse u\n\nsection\n\nvariable {α : Type u} [LinearOrder α]\n\nlemma min_le_left (a b : α) : min a b ≤ a :=\nif h : a ≤ b\nthen by simp[min, if_pos h, le_refl]\nelse by simp[min, if_neg h]\n        exact le_of_not_le h\n\nlemma min_le_right (a b : α) : min a b ≤ b :=\nif h : a ≤ b\nthen by simp[min, if_pos h]; exact h\nelse by simp[min, if_neg h, le_refl]\n\nlemma le_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b :=\nif h : a ≤ b\nthen by simp[min, if_pos h]; exact h₁\nelse by simp[min, if_neg h]; exact h₂\n\nlemma le_max_left (a b : α) : a ≤ max a b :=\nif h : b < a\nthen by simp[max, if_pos h, le_refl]\nelse by simp[max, if_neg h]\n        exact le_of_not_lt h\n\nlemma le_max_right (a b : α) : b ≤ max a b :=\nif h : b < a\nthen by simp[max, if_pos h]; exact le_of_lt h\nelse by simp[max, if_neg h, le_refl]\n\nlemma max_le {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) : max a b ≤ c :=\nif h : b < a\nthen by simp[max, if_pos h]; exact h₁\nelse by simp[max, if_neg h]; exact h₂\n\nlemma eq_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) (h₃ : ∀{d}, d ≤ a → d ≤ b → d ≤ c) :\n  c = min a b :=\nle_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b))\n\nlemma min_comm (a b : α) : min a b = min b a :=\neq_min (min_le_right a b) (min_le_left a b) (λ {c} h₁ h₂ => le_min h₂ h₁)\n\nlemma min_assoc (a b c : α) : min (min a b) c = min a (min b c) :=\nby 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₁ h₂; apply le_min; apply le_min h₁; apply le_trans h₂; apply min_le_left;\n     apply le_trans h₂; apply min_le_right\n\nlemma min_left_comm : @left_commutative α α min :=\nleft_comm min (@min_comm α _) (@min_assoc α _)\n\n@[simp]\nlemma min_self (a : α) : min a a = a := by simp[min]\n\nlemma min_eq_left {a b : α} (h : a ≤ b) : min a b = a :=\nby apply Eq.symm; apply eq_min (le_refl _) h; intros; assumption\n\nlemma min_eq_right {a b : α} (h : b ≤ a) : min a b = b :=\nby rw [min_comm]\n   exact min_eq_left h\n\nlemma eq_max {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) (h₃ : ∀{d}, a ≤ d → b ≤ d → c ≤ d) : c = max a b :=\nle_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂)\n\nlemma max_comm (a b : α) : max a b = max b a :=\neq_max (le_max_right a b) (le_max_left a b) (λ {c} h₁ h₂ => max_le h₂ h₁)\n\nlemma max_assoc (a b c : α) : max (max a b) c = max a (max b c) := by\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₁ h₂; apply max_le; apply max_le h₁; apply le_trans (le_max_left _ _) h₂;\n    apply le_trans (le_max_right _ _) h₂\n\nlemma max_left_comm : ∀ (a b c : α), max a (max b c) = max b (max a c) :=\nleft_comm max (@max_comm α _) (@max_assoc α _)\n\n@[simp]\nlemma max_self (a : α) : max a a = a := by simp[max]\n\nlemma max_eq_left {a b : α} (h : b ≤ a) : max a b = a :=\nby apply Eq.symm; apply eq_max (le_refl _) h; intros; assumption\n\nlemma max_eq_right {a b : α} (h : a ≤ b) : max a b = b :=\nby rw [←max_comm b a]; exact max_eq_left h\n\n/- these rely on lt_of_lt -/\n\nlemma min_eq_left_of_lt {a b : α} (h : a < b) : min a b = a :=\nmin_eq_left (le_of_lt h)\n\nlemma min_eq_right_of_lt {a b : α} (h : b < a) : min a b = b :=\nmin_eq_right (le_of_lt h)\n\nlemma max_eq_left_of_lt {a b : α} (h : b < a) : max a b = a :=\nmax_eq_left (le_of_lt h)\n\nlemma max_eq_right_of_lt {a b : α} (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 : α} (h₁ : a < b) (h₂ : a < c) : a < min b c :=\nOr.elim (le_or_gt b c)\n  (λ h : b ≤ c => by rwa [min_eq_left h])\n  (λ h : b > c => by rwa [min_eq_right_of_lt h])\n\nlemma max_lt {a b c : α} (h₁ : a < c) (h₂ : b < c) : max a b < c :=\nOr.elim (le_or_gt a b)\n  (λ h : a ≤ b => by rwa [max_eq_right h])\n  (λ h : a > b => by rwa [max_eq_left_of_lt h])\n\nend\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/Functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.795755724202135}}
{"text": "------------------\n-- Random Notes --\n\n--\n-- 7.1. Enumerated Types\n--\nnamespace s71\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  namespace weekday\n    def next (d : weekday) : weekday :=\n      weekday.cases_on d\n        monday\n        tuesday\n        wednesday\n        thursday\n        friday\n        saturday\n        sunday\n\n    def previous (d : weekday) : weekday :=\n      weekday.cases_on d\n        saturday\n        sunday\n        monday\n        tuesday\n        wednesday\n        thursday\n        friday\n\n    theorem next_previous (d : weekday) : next (previous d) = d :=\n    begin\n      apply weekday.cases_on d;\n      refl,\n    end\n\n    theorem previous_next (d : weekday) : previous (next d) = d :=\n    begin\n      apply weekday.cases_on d;\n      refl,\n    end\n  end weekday\nend s71\n\n--\n-- 7.2. Constructors with Arguments\n--\nnamespace s72\n  universes u v\n\n  inductive prod (α : Type u) (β : Type v)\n    | mk : α → β → prod\n\n\n  namespace prod\n    def fst {α : Type u} {β : Type v} (p : prod α β) : α :=\n      prod.rec_on p (λa b, a)\n\n    def snd {α : Type u} {β : Type v} (p : prod α β) : β :=\n      prod.rec_on p (λa b, b)\n\n    section\n      variables (α : Type u) (β : Type v) (p : prod α β)\n      variables (a : α) (b : β)\n\n      #reduce mk a b\n      #reduce fst (mk a b)\n      #reduce snd (mk a b)\n    end\n  end prod\n\n  -- Defining the necessary conditions for a group as a structure.\n  --\n  -- Now how would one actually use this definition?\n  universe t\n\n  structure Group :=\n    (carrier : Type t)\n    (ident : carrier)\n\n    (inverse : carrier → carrier)\n    (mul : carrier → carrier → carrier)\n\n    (ident_mul_eq : ∀ a : carrier, mul ident a = a)\n    (mul_ident_eq : ∀ a : carrier, mul a ident = a)\n\n    (inverse_mul_eq_ident : ∀ a : carrier, mul (inverse a) a = ident)\n    (mul_inverse_eq_ident : ∀ a : carrier, mul a (inverse a) = ident)\n\n    (mul_assoc : ∀ a b c : carrier, mul (mul a b) c = mul a (mul b c))\nend s72\n\n---------------\n-- Exercises --\n\n-- Exercise 1\n--\n-- Try defining other operations on the natural numbers, such as multiplication,\n-- the predecessor function (with pred 0 = 0), truncated subtraction (with\n-- n - m = 0 when m is greater than or equal to n), and exponentiation. Then try\n-- proving some of their basic properties, building on the theorems we have\n-- already proved.\n--\n-- Since many of these are already defined in Lean’s core library, you should\n-- work within a namespace named hide, or something like that, in order to avoid\n-- name clashes.\nnamespace hidden\n  variables (x y : ℕ)\n\n  -- Defining our operations\n  def add (x y : ℕ) : ℕ :=\n    nat.rec_on\n      x\n      y\n      (λ _ add_x_y, nat.succ add_x_y)\n\n  def mul (x y : ℕ) : ℕ :=\n    nat.rec_on\n      x\n      0\n      (λ _ mul_x_y, add mul_x_y y)\n\n  def pred (n : ℕ) : ℕ :=\n    nat.rec_on\n      n\n      0\n      (λ n pred_n, n)\n\n  def sub (x y : ℕ) : ℕ :=\n    nat.rec_on\n      y\n      x\n      (λ n sub_x_y, pred sub_x_y)\n\n  -- TODO: Define infix operators\n\n  -- Defining some theorems. Skipping most of them because I did them in NN Game\n  theorem add_sub_inverse : ∀ (x y : ℕ), x + y - y = x :=\n    begin\n      intros x y,\n\n      induction y with d hd,\n\n      {\n        rw add_zero,\n        -- rw sub_zero,\n        sorry,\n      },\n\n      {\n        sorry,\n      },\n    end\nend hidden\n\n-- TODO\n\n-- Exericse 2\n--\n-- Define some operations on lists, like a length function or the reverse\n-- function. Prove some properties, such as the following:\n--\n-- length (s ++ t) = length s + length t\n--\n-- length (reverse t) = length t\n--\n-- reverse (reverse t) = t\n\n-- TODO\n\n-- Exericse 3\n--\n-- Define an inductive data type consisting of terms built up from the following\n-- constructors:\n--\n-- const n, a constant denoting the natural number n\n--\n-- var n, a variable, numbered n\n--\n-- plus s t, denoting the sum of s and t\n--\n-- times s t, denoting the product of s and t\n--\n-- Recursively define a function that evaluates any such term with respect to an\n-- assignment of values to the variables.\n\n-- Exercise 4\n--\n-- Similarly, define the type of propositional formulas, as well as functions on\n-- the type of such formulas: an evaluation function, functions that measure the\n-- complexity of a formula, and a function that substitutes another formula for\n-- a given variable.\n\n-- TODO\n\n-- Exercise 5\n--\n-- Simulate the mutual inductive definition of even and odd described in Section 7.9 with an ordinary inductive type, using an index to encode the choice between them in the target type.\n\n-- TODO\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/chapter7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.7956968678578094}}
{"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# `equiv`\n\nLet `X` and `Y` be types. Here's the definition of `X ≃ Y`\n(which is notation for `equiv X Y`):\n\n```\n\nstructure equiv (X : Type) (Y : Type) :=\n(to_fun    : X → Y)\n(inv_fun   : Y → X)\n(left_inv  : ∀ x : X, inv_fun (to_fun x) = x)\n(right_inv : ∀ y : Y, to_fun (inv_fun y) = y)\n\n-- notation\ninfix ` ≃ `:25 := equiv\n\n```\n\nHere's an example: the identity bijection\nbetween a type and itself:\n-/\n\n-- this is called `equiv.refl` in `mathlib`\nexample (X : Type) : X ≃ X :=\n{ to_fun := λ x, x, -- x ↦ x \n  inv_fun := λ y, y,-- y ↦ y\n  left_inv := begin\n    -- got to check that `∀ x, inv_fun (to_fun x) = x`\n    intro x,\n    dsimp, -- if you want to check the goal is definitionally `x = x`\n    refl,\n  end,\n  right_inv := begin\n    -- goal is definitionally `∀ y, to_fun (inv_fun y) = y`. \n    intro y,\n    refl,\n  end }\n\n-- now let's see you define `equiv.symm` and `equiv.trans`.\n-- Let's start with `equiv.symm`.\n-- Note that if `e : X ≃ Y` then `e.to_fun : X → Y`\n-- and `e.left_inv` is a proof of `∀ x : X, e.inv_fun (e.to_fun x) = x` etc\n\nexample (X Y : Type) (e : X ≃ Y) : Y ≃ X :=\n{ to_fun := e.inv_fun, -- you could write `λ x, e.inv_fun x` instead\n  inv_fun := sorry, -- this is data -- don't use tactic mode\n  left_inv := begin\n    sorry -- this is a proof so tactic mode is fine\n  end,\n  right_inv := begin\n    sorry -- this is a proof\n  end }\n\n-- can you build `equiv.trans` yourself?\nexample (X Y Z : Type) (eXY : X ≃ Y) (eYZ : Y ≃ Z) : X ≃ Z :=\n{ to_fun := sorry, -- this is data; stay away from tactic mode.\n  inv_fun := sorry, -- ditto\n  left_inv := begin\n    sorry -- this is a proof\n  end,\n  right_inv := begin\n    sorry \n  end }\n\n-- here's the library's version\nexample (X Y Z : Type) (eXY : X ≃ Y) (eYZ : Y ≃ Z) : X ≃ Z :=\nequiv.trans eXY eYZ\n\n-- here it is again using dot notation\nexample (X Y Z : Type) (eXY : X ≃ Y) (eYZ : Y ≃ Z) : X ≃ Z :=\neXY.trans eYZ\n\n-- See if you can make the following bijection using dot notation\nexample (A B C X : Type) (eAX : A ≃ X) (eBX : B ≃ X) : A ≃ B :=\nsorry -- don't use tactic mode, see if you can find a one-liner\n-- using `equiv.symm` and `equiv.trans`\n\n-- We already have `equiv.refl ℚ : ℚ ≃ ℚ`, the identity bijection\n-- between `ℚ` and itself. See if you can finish making a different one:\n\nexample : ℚ ≃ ℚ :=\n{ to_fun := λ x, 3 * x + 4,\n  inv_fun := λ y, sorry, -- fill in the inverse function\n  left_inv := begin\n    sorry,\n  end,\n  right_inv := begin\n    sorry,\n  end }\n\n\n/-\n\nNote that `equiv` is *data* -- `X ≃ Y` doesn't say \"`X` bijects with `Y`\";\nthat statement is a true-false statement. A term of type `X ≃ Y`\nis *explicit functions* `X → Y` and `Y → X`, together with proofs\nthat they're inverse bijections.\n\nClearly there's an equivalence relation going on *somewhere* though:\nhere it is.  \n\nIf `X : Type` then `∃ x : X, true` is just the statement that `X`\nis nonempty. It's a proposition. So this works:\n\n-/\n\n-- Two types `X` and `Y` satisfy `R X Y` iff there *exists*\n-- a bijection `X ≃ Y`. \ndef R (X Y : Type) : Prop := ∃ e : X ≃ Y, true\n\nexample : equivalence R :=\nbegin\n  sorry\nend\n\n-- Remark: the equivalence classes of `R` are called *cardinals*.\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/sheet2buildingequiv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7954989184720207}}
{"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 fa256f00ce018e7b40e1dc756e403c86680bf448\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.Fin\nimport Mathlib.Data.Polynomial.Degree.Definitions\n\n/-!\n# Erase the leading term of a univariate polynomial\n\n## Definition\n\n* `eraseLead f`: the polynomial `f - leading term of f`\n\n`eraseLead` 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/-- `eraseLead 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\nsection EraseLead\n\ntheorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase f.natDegree := by\n  simp only [eraseLead, support_erase]\n#align polynomial.erase_lead_support Polynomial.eraseLead_support\n\ntheorem eraseLead_coeff (i : ℕ) : f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i :=\n  by simp only [eraseLead, coeff_erase]\n#align polynomial.erase_lead_coeff Polynomial.eraseLead_coeff\n\n@[simp]\ntheorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by simp [eraseLead_coeff]\n#align polynomial.erase_lead_coeff_nat_degree Polynomial.eraseLead_coeff_natDegree\n\ntheorem eraseLead_coeff_of_ne (i : ℕ) (hi : i ≠ f.natDegree) : f.eraseLead.coeff i = f.coeff i := by\n  simp [eraseLead_coeff, hi]\n#align polynomial.erase_lead_coeff_of_ne Polynomial.eraseLead_coeff_of_ne\n\n@[simp]\ntheorem eraseLead_zero : eraseLead (0 : R[X]) = 0 := by simp only [eraseLead, erase_zero]\n#align polynomial.erase_lead_zero Polynomial.eraseLead_zero\n\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@[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, eraseLead_add_monomial_natDegree_leadingCoeff]\nset_option linter.uppercaseLean3 false in\n#align polynomial.erase_lead_add_C_mul_X_pow Polynomial.eraseLead_add_C_mul_X_pow\n\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@[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_natDegree_leadingCoeff]\nset_option linter.uppercaseLean3 false in\n#align polynomial.self_sub_C_mul_X_pow Polynomial.self_sub_C_mul_X_pow\n\n\n\ntheorem lt_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :\n    a < f.natDegree := by\n  rw [eraseLead_support, mem_erase] at h\n  exact (le_natDegree_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\ntheorem ne_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :\n    a ≠ 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\ntheorem natDegree_not_mem_eraseLead_support : f.natDegree ∉ (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\ntheorem eraseLead_support_card_lt (h : f ≠ 0) : (eraseLead f).support.card < f.support.card := by\n  rw [eraseLead_support]\n  exact card_lt_card (erase_ssubset <| natDegree_mem_support_of_nonzero h)\n#align polynomial.erase_lead_support_card_lt Polynomial.eraseLead_support_card_lt\n\ntheorem eraseLead_card_support {c : ℕ} (fc : f.support.card = c) :\n    f.eraseLead.support.card = c - 1 := by\n  by_cases f0 : f = 0\n  · rw [← fc, f0, eraseLead_zero, support_zero, card_empty]\n  · rw [eraseLead_support, card_erase_of_mem (natDegree_mem_support_of_nonzero f0), fc]\n#align polynomial.erase_lead_card_support Polynomial.eraseLead_card_support\n\ntheorem eraseLead_card_support' {c : ℕ} (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@[simp]\ntheorem eraseLead_monomial (i : ℕ) (r : R) : eraseLead (monomial i r) = 0 := by\n  by_cases hr : r = 0\n  · subst r\n    simp only [monomial_zero_right, eraseLead_zero]\n  · rw [eraseLead, natDegree_monomial, if_neg hr, erase_monomial]\n#align polynomial.erase_lead_monomial Polynomial.eraseLead_monomial\n\n@[simp]\ntheorem eraseLead_C (r : R) : eraseLead (C r) = 0 :=\n  eraseLead_monomial _ _\nset_option linter.uppercaseLean3 false in\n#align polynomial.erase_lead_C Polynomial.eraseLead_C\n\n@[simp]\ntheorem eraseLead_X : eraseLead (X : R[X]) = 0 :=\n  eraseLead_monomial _ _\nset_option linter.uppercaseLean3 false in\n#align polynomial.erase_lead_X Polynomial.eraseLead_X\n\n@[simp]\ntheorem eraseLead_X_pow (n : ℕ) : eraseLead (X ^ n : R[X]) = 0 := by\n  rw [X_pow_eq_monomial, eraseLead_monomial]\nset_option linter.uppercaseLean3 false in\n#align polynomial.erase_lead_X_pow Polynomial.eraseLead_X_pow\n\n@[simp]\ntheorem eraseLead_C_mul_X_pow (r : R) (n : ℕ) : eraseLead (C r * X ^ n) = 0 := by\n  rw [C_mul_X_pow_eq_monomial, eraseLead_monomial]\nset_option linter.uppercaseLean3 false in\n#align polynomial.erase_lead_C_mul_X_pow Polynomial.eraseLead_C_mul_X_pow\n\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.natDegree\n  · rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_left_of_natDegree_lt pq).symm]\n    simpa using (coeff_eq_zero_of_natDegree_lt pq).symm\n  · rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]\n    rintro rfl\n    exact nd (natDegree_add_eq_left_of_natDegree_lt pq)\n#align polynomial.erase_lead_add_of_nat_degree_lt_left Polynomial.eraseLead_add_of_natDegree_lt_left\n\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.natDegree\n  · rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_right_of_natDegree_lt pq).symm]\n    simpa using (coeff_eq_zero_of_natDegree_lt pq).symm\n  · rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]\n    rintro rfl\n    exact nd (natDegree_add_eq_right_of_natDegree_lt pq)\n#align polynomial.erase_lead_add_of_nat_degree_lt_right Polynomial.eraseLead_add_of_natDegree_lt_right\n\ntheorem eraseLead_degree_le : (eraseLead f).degree ≤ f.degree :=\n  f.degree_erase_le _\n#align polynomial.erase_lead_degree_le Polynomial.eraseLead_degree_le\n\ntheorem eraseLead_natDegree_le_aux : (eraseLead f).natDegree ≤ f.natDegree :=\n  natDegree_le_natDegree eraseLead_degree_le\n#align polynomial.erase_lead_nat_degree_le_aux Polynomial.eraseLead_natDegree_le_aux\n\ntheorem eraseLead_natDegree_lt (f0 : 2 ≤ 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\ntheorem eraseLead_natDegree_lt_or_eraseLead_eq_zero (f : R[X]) :\n    (eraseLead f).natDegree < f.natDegree ∨ f.eraseLead = 0 := by\n  by_cases h : f.support.card ≤ 1\n  · right\n    rw [← C_mul_X_pow_eq_self h]\n    simp\n  · left\n    apply eraseLead_natDegree_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\ntheorem eraseLead_natDegree_le (f : R[X]) : (eraseLead f).natDegree ≤ f.natDegree - 1 := by\n  rcases f.eraseLead_natDegree_lt_or_eraseLead_eq_zero with (h | h)\n  · exact Nat.le_pred_of_lt h\n  · simp only [h, natDegree_zero, zero_le]\n#align polynomial.erase_lead_nat_degree_le Polynomial.eraseLead_natDegree_le\n\nend EraseLead\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_natDegree_le (P : R[X] → Prop) (N : ℕ) (P_0 : P 0)\n    (P_C_mul_pow : ∀ n : ℕ, ∀ r : R, r ≠ 0 → n ≤ N → P (C r * X ^ n))\n    (P_C_add : ∀ f g : R[X], f.natDegree < g.natDegree → g.natDegree ≤ N → P f → P g → P (f + g)) :\n    ∀ f : R[X], f.natDegree ≤ N → P f := by\n  intro f df\n  generalize hd : card f.support = c\n  revert f\n  induction' c with c hc\n  · intro f _ f0\n    convert P_0\n    simpa [support_eq_empty, card_eq_zero] using f0\n  · intro f df f0\n    rw [← eraseLead_add_C_mul_X_pow f]\n    cases c\n    · convert P_C_mul_pow f.natDegree f.leadingCoeff ?_ df using 1\n      · convert zero_add (C (leadingCoeff f) * X ^ f.natDegree)\n        rw [← card_support_eq_zero, eraseLead_card_support f0]\n      · rw [leadingCoeff_ne_zero, Ne.def, ← card_support_eq_zero, f0]\n        exact zero_ne_one.symm\n    refine' P_C_add f.eraseLead _ _ _ _ _\n    · refine' (eraseLead_natDegree_lt _).trans_le (le_of_eq _)\n      · exact (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))).trans f0.ge\n      · rw [natDegree_C_mul_X_pow _ _ (leadingCoeff_ne_zero.mpr _)]\n        rintro rfl\n        simp at f0\n    · exact (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree).trans df\n    · exact hc _ (eraseLead_natDegree_le_aux.trans df) (eraseLead_card_support f0)\n    · refine' P_C_mul_pow _ _ _ df\n      rw [Ne.def, leadingCoeff_eq_zero, ← 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/-- Let `φ : R[x] → S[x]` be an additive map, `k : ℕ` a bound, and `fu : ℕ → ℕ` a\n\"sufficiently monotone\" map.  Assume also that\n* `φ` maps to `0` all monomials of degree less than `k`,\n* `φ` maps each monomial `m` in `R[x]` to a polynomial `φ m` of degree `fu (deg m)`.\nThen, `φ` 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]] {φ : F}\n    {p : R[X]} (k : ℕ) (fu : ℕ → ℕ) (fu0 : ∀ {n}, n ≤ k → fu n = 0)\n    (fc : ∀ {n m}, k ≤ n → n < m → fu n < fu m) (φ_k : ∀ {f : R[X]}, f.natDegree < k → φ f = 0)\n    (φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = fu n) :\n    (φ p).natDegree = fu p.natDegree := by\n  refine' induction_with_natDegree_le (fun p => (φ p).natDegree = fu p.natDegree)\n    p.natDegree (by simp [fu0]) _ _ _ rfl.le\n  · intro n r r0 _\n    rw [natDegree_C_mul_X_pow _ _ r0, C_mul_X_pow_eq_monomial, φ_mon_nat _ _ r0]\n  · intro f g fg _ fk gk\n    rw [natDegree_add_eq_right_of_natDegree_lt fg, _root_.map_add]\n    by_cases FG : k ≤ f.natDegree\n    · rw [natDegree_add_eq_right_of_natDegree_lt, gk]\n      rw [fk, gk]\n      exact fc FG fg\n    · cases k\n      · exact (FG (Nat.zero_le _)).elim\n      · rwa [φ_k (not_le.mp FG), zero_add]\n#align polynomial.mono_map_nat_degree_eq Polynomial.mono_map_natDegree_eq\n\ntheorem map_natDegree_eq_sub {S F : Type _} [Semiring S] [AddMonoidHomClass F R[X] S[X]] {φ : F}\n    {p : R[X]} {k : ℕ} (φ_k : ∀ f : R[X], f.natDegree < k → φ f = 0)\n    (φ_mon : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = n - k) :\n    (φ p).natDegree = p.natDegree - k :=\n  mono_map_natDegree_eq k (fun j => j - k) (by simp)\n    (@fun m n h => (tsub_lt_tsub_iff_right h).mpr)\n    (φ_k _) φ_mon\n#align polynomial.map_nat_degree_eq_sub Polynomial.map_natDegree_eq_sub\n\ntheorem map_natDegree_eq_natDegree {S F : Type _} [Semiring S] [AddMonoidHomClass F R[X] S[X]]\n    {φ : F} (p) (φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = n) :\n    (φ 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\ntheorem card_support_eq' {n : ℕ} (k : Fin n → ℕ) (x : Fin n → R) (hk : Function.Injective k)\n    (hx : ∀ i, x i ≠ 0) : (∑ i, C (x i) * X ^ k i).support.card = n := by\n  suffices (∑ 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, true_and]\n  refine' fun i => ⟨fun h => _, _⟩\n  · obtain ⟨j, _, h⟩ := exists_ne_zero_of_sum_ne_zero h\n    exact ⟨j, (ite_ne_right_iff.mp h).1.symm⟩\n  · rintro ⟨j, _, rfl⟩\n    rw [sum_eq_single_of_mem j (mem_univ j), if_pos rfl]\n    · exact hx j\n    · exact fun m _ hmj => if_neg fun h => hmj.symm (hk h)\n#align polynomial.card_support_eq' Polynomial.card_support_eq'\n\ntheorem card_support_eq {n : ℕ} :\n    f.support.card = n ↔\n      ∃ (k : Fin n → ℕ)(x : Fin n → R)(hk : StrictMono k)(hx : ∀ i, x i ≠ 0),\n        f = ∑ i, C (x i) * X ^ k i := by\n  refine' ⟨_, fun ⟨k, x, hk, hx, hf⟩ => hf.symm ▸ card_support_eq' k x hk.injective hx⟩\n  induction' n with n hn generalizing f\n  · exact fun hf => ⟨0, 0, fun x => x.elim0, fun x => x.elim0, card_support_eq_zero.mp hf⟩\n  · intro h\n    obtain ⟨k, x, hk, hx, hf⟩ := hn (eraseLead_card_support' h)\n    have H : ¬∃ k : Fin n, Fin.castSucc k = Fin.last n :=\n      by\n      rintro ⟨i, hi⟩\n      exact i.castSucc_lt_last.ne hi\n    refine'\n      ⟨Function.extend Fin.castSucc k fun _ => f.natDegree,\n        Function.extend Fin.castSucc x fun _ => f.leadingCoeff, _, _, _⟩\n    · intro i j hij\n      have hi : i ∈ Set.range (Fin.castSucc : Fin n ↪o 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 ⟨i, rfl⟩ := hi\n      rw [Fin.castSucc.injective.extend_apply]\n      by_cases hj : ∃ j₀, Fin.castSucc j₀ = j\n      · obtain ⟨j, rfl⟩ := hj\n        rwa [Fin.castSucc.injective.extend_apply, hk.lt_iff_lt, ← Fin.castSucc_lt_castSucc_iff]\n      · rw [Function.extend_apply' _ _ _ hj]\n        apply lt_natDegree_of_mem_eraseLead_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        · exact hx i\n        · intro j _ hji\n          rw [coeff_C_mul, coeff_X_pow, if_neg (hk.injective.ne hji.symm), mul_zero]\n        · exact fun hi => (hi (mem_univ i)).elim\n    · intro i\n      by_cases hi : ∃ i₀, Fin.castSucc i₀ = i\n      · obtain ⟨i, rfl⟩ := hi\n        rw [Fin.castSucc.injective.extend_apply]\n        exact hx i\n      · rw [Function.extend_apply' _ _ _ hi, Ne, leadingCoeff_eq_zero, ← card_support_eq_zero, h]\n        exact n.succ_ne_zero\n    · rw [Fin.sum_univ_castSucc]\n      simp only [Fin.castSucc.injective.extend_apply]\n      rw [← hf, Function.extend_apply', Function.extend_apply', eraseLead_add_C_mul_X_pow]\n      all_goals exact H\n#align polynomial.card_support_eq Polynomial.card_support_eq\n\ntheorem card_support_eq_one : f.support.card = 1 ↔ ∃ (k : ℕ)(x : R)(hx : x ≠ 0), f = C x * X ^ k :=\n  by\n  refine' ⟨fun h => _, _⟩\n  · obtain ⟨k, x, _, hx, rfl⟩ := card_support_eq.mp h\n    exact ⟨k 0, x 0, hx 0, Fin.sum_univ_one _⟩\n  · rintro ⟨k, x, hx, rfl⟩\n    rw [support_C_mul_X_pow k hx, card_singleton]\n#align polynomial.card_support_eq_one Polynomial.card_support_eq_one\n\ntheorem card_support_eq_two :\n    f.support.card = 2 ↔\n      ∃ (k m : ℕ)(hkm : k < m)(x y : R)(hx : x ≠ 0)(hy : y ≠ 0), f = C x * X ^ k + C y * X ^ m := by\n  refine' ⟨fun h => _, _⟩\n  · obtain ⟨k, x, hk, hx, rfl⟩ := card_support_eq.mp h\n    refine' ⟨k 0, k 1, hk Nat.zero_lt_one, x 0, x 1, hx 0, hx 1, _⟩\n    rw [Fin.sum_univ_castSucc, Fin.sum_univ_one]\n    rfl\n  · rintro ⟨k, m, hkm, x, y, hx, hy, rfl⟩\n    exact card_support_binomial hkm.ne hx hy\n#align polynomial.card_support_eq_two Polynomial.card_support_eq_two\n\ntheorem card_support_eq_three :\n    f.support.card = 3 ↔\n      ∃ (k m n : ℕ)(hkm : k < m)(hmn : m < n)(x y z : R)(hx : x ≠ 0)(hy : y ≠ 0)(hz : z ≠ 0),\n        f = C x * X ^ k + C y * X ^ m + C z * X ^ n := by\n  refine' ⟨fun h => _, _⟩\n  · obtain ⟨k, x, hk, hx, rfl⟩ := card_support_eq.mp h\n    refine'\n      ⟨k 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        _⟩\n    rw [Fin.sum_univ_castSucc, Fin.sum_univ_castSucc, Fin.sum_univ_one]\n    rfl\n  · rintro ⟨k, m, n, hkm, hmn, x, y, z, hx, hy, hz, rfl⟩\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", "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/EraseLead.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7954989120598244}}
{"text": "import data.nat.order.basic\n\n-- Utility library for three maxes of ℕ\n\n/-- maximum of three natural numbers. -/\ndef max3 (a b c : ℕ) : ℕ := max (max a b) c\n\ntheorem max3_mul_left (a b c d : ℕ) :\n  max3 (a * b) (a * c) (a * d) = a * max3 b c d :=\nbegin\n  -- This is hard: should I use `max_mul_of_nonneg`\n  -- or `max_mul_mul_left`?\n  rw nat.mul_comm a (max3 b c d),\n  simp_rw max3,\n  rw max_mul_of_nonneg _ _ (zero_le a),\n  rw max_mul_of_nonneg _ _ (zero_le a),\n  repeat {rw nat.mul_comm a _},\nend\n\ntheorem le_max3_first (a b c : ℕ) : a ≤ max3 a b c :=\n  le_max_of_le_left (le_max_left _ _)\n\ntheorem le_max3_second (a b c : ℕ) : b ≤ max3 a b c :=\n  le_max_of_le_left (le_max_right _ _)\n\ntheorem le_max3_third (a b c : ℕ) : c ≤ max3 a b c :=\n  le_max_right _ _\n\ntheorem max3_lt_iff {a b c d : ℕ} : \n  max3 a b c < d ↔ a < d ∧ b < d ∧ c < d :=\nbegin\n  rw max3, simp only [max_lt_iff], tauto,\nend\n\ntheorem add3_le_three_mul_max3 (a b c : ℕ) : \n  a + b + c ≤ 3 * max3 a b c :=\nbegin\n  rw (show 3 = 2 + 1, by exact rfl),\n  rw [nat.succ_mul, two_mul],\n  apply nat.add_le_add _ (le_max3_third _ _ _),\n  apply nat.add_le_add _ (le_max3_second _ _ _),\n  exact le_max3_first _ _ _,\nend\n\ntheorem weighted_average_le_max3 {p q r a b c: ℕ} :\n  p*a + q*b + r*c ≤ (p+q+r)*(max3 a b c) := \nbegin\n  simp_rw add_mul,\n  apply nat.add_le_add,\n  apply nat.add_le_add,\n  exact nat.mul_le_mul (le_refl _) (le_max3_first _ _ _),\n  exact nat.mul_le_mul (le_refl _) (le_max3_second _ _ _),\n  exact nat.mul_le_mul (le_refl _) (le_max3_third _ _ _),\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/lib/max3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7954626516143972}}
{"text": "import BrownCs22.Library.Tactics \n\nnamespace Lecture04\n\n/-\n\nRecall from lecture:\n* A *proof state* is a sequence of goals, \n  each with an associated list of hypotheses.\n* We can manipulate a proof state by applying *proof rules*. \n  Proof rules change the goals and/or hypotheses. \n* The objective of proving is to apply proof rules \n  until there are no remaining goals. \n\n* *introduction rules* tell us how to show goals of certain shapes. \n* *elimination rules* tell us how to use hypotheses of certain shapes. \n\n-/\n\n-- let `p, q, r` be propositions.\nvariable (p q r : Prop)\n\n/-\n\nTo start a proof, we write `example :` or `theorem theorem_name :`,\nfollowed by the proposition we are trying to prove, \nfollowed by `:= by`.\n\nWhat follows after that is a list of proof rules (\"tactics\").\nIf we put the cursor at the end of any line, we see the current proof state\nafter applying that rule.\n\nThe lines above the `⊢` symbol are our *context*, i.e. our hypotheses.\nThe line after the `⊢` is our current goal. \n\n-/\n\nexample : p → p := by\n  intro hp \n  assumption \n\n/- \nHere are some useful tactics, corresponding to the intro rules we've seen.\n\n* and introduction: `split_goal` \n* or introduction: `left`, `right` \n* implication intro: `intro h` (you get to name the new hypothesis)\n* iff intro: `split_goal` \n* atom: `assumption` (if your goal matches a hypothesis)\n\n* `sorry` proves the goal automatically, no matter what it is.\n  This is cheating! :)\n-/\n\nexample : p → q → p ∧ q := by \n  intro hp\n  intro hq \n  split_goal \n  { assumption } -- when we have multiple goals, we sometimes put each subproof in {...}\n  { assumption }  -- but this is mainly for style!\n\nexample : p → p ∨ q := by \n  intro hp \n  left \n  assumption\n\n-- try it yourself:\n\nexample : q → p ∨ q := by \n  intro hq\n  right\n  assumption\n\nexample : (p ∧ q) → (p ↔ q) := by \n  intro h\n  split_goal\n  {\n    {intro hq}\n    {sorry}\n    }\n\n/-\n*Elimination rules* tell us how we can use hypotheses. To start:\n\n* and elimination: `eliminate h with h1 h2`, \n  when `h : p ∧ q` is in the context. Creates new hypotheses\n  `h1 : p` and `h2 : q`. \n* or elimination: `eliminate h with h1 h2`, \n  when `h : p ∨ q` is in the context. Creates new goals,\n  one with `h1 : p` in the context and one with `h2 : q` in the context.\n\n-/\n\nexample : p ∧ q → q ∧ p := by \n  intro hpq \n  eliminate hpq with hp hq \n  split_goal \n  . assumption \n  . assumption \n\nexample : (p ∨ q) → (p ∨ r) ∨ (q ∨ r) := by \n  intro hpq \n  eliminate hpq with hp hq \n  { left \n    left \n    assumption }\n  { right \n    left \n    assumption }\n\n/-\n\nUsing an iff is easy: `eliminate` will turn it into two \"imply\"s.\n\n-/\n\nexample : (p ↔ q) → (p → q) := by \n  intro h_iff \n  eliminate h_iff with hpq hqp \n  assumption \n\n/-\n\nUsing an \"imply\" is a little trickier: \nif we know `hpq : p → q`, and our goal is to prove `q`,\nthen `apply hpq` will change the goal to `p`.\n\n-/\n\nexample : p → (p → q) → q := by \n  intro hp \n  intro hpq \n  apply hpq \n  assumption \n\n/-\n\nAlternatively, if we know `hpq : p → q` and `hp : p`, \nwe can \"reason forward\" by writing `have hq : q := hpq hp`.\nThis adds a new hypothesis `hq : q` without changing the goal.\nThis syntax is a little clunky, but we'll use it in a more general setting later.\n\n-/\n\nexample : p → (p → q) → q ∧ p := by \n  intro hp \n  intro hpq \n  have hq : q := hpq hp \n  split_goal\n  { assumption }\n  { assumption }\n\n\n\n\n\n\n/- Here's a little logic puzzle.\n\n(h1) Alan likes acorns, and either Betty likes begonias or Carl likes cacti.\n\n(h2) If Betty likes begonias, then Alan doesn’t like acorns.\n\n(h3) If Carl likes cacti, then Betty likes begonias.\n\nShow that these hypotheses are contradictory.\n\n-/\n\nvariable (al_ac : Prop) -- the proposition \"Alan likes acorns\"\nvariable (betty_beg : Prop) -- the proposition \"Betty likes begonias\"\nvariable (carl_cac : Prop) -- the proposition \"Carl likes cacti\"\n\n\ntheorem these_are_contradictory\n    (h1 : al_ac ∧ (betty_beg ∨ carl_cac))\n    (h2 : betty_beg → ¬ al_ac)\n    (h3 : carl_cac → betty_beg) :\n    False := by \n  eliminate h1 with h4 h5      -- from h1, we know \n                               -- (h4) Alan likes acorns and \n                               -- (h5) either Betty likes begonias or Carl likes cacti.\n  eliminate h5 with h6 h7      -- let's reason by cases on h5. \n  \n  { have h8 : ¬ al_ac := h2 h6 -- First, suppose Betty likes begonias. \n                               -- Then, by modus ponens with h2, Alan does not like acorns.\n    contradiction }            -- This contradicts h4!\n  \n  { have h9 : betty_beg := h3 h7 -- Now suppose Carl likes cacti.\n                                 -- By modus ponens with h3, Betty likes begonias.\n    have h10 : ¬ al_ac := h2 h9  -- But now again by modus ponens with h2, Alan does not like acorns.\n    contradiction }              -- Another contradiction!\n                                 -- We've finished all our goals. \n\n\n/-\n\nYou've just seen the missing connective.\nWe skipped rules for negation introduction and elimination before.\n\nThis example just showed how to *use* a negation:\nif we have hypotheses `hp : p` and `hnp : ¬ p`, then \n`contradiction` will prove any goal.\n\nHow to introduce a negation? This uses a technique called \n\"proof by contradiction\", which we'll motivate in class soon.\n\n-/\n\n\n\n\nend Lecture04", "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/Demos/Lecture04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7954442987885216}}
{"text": "open classical\n\nvariables p q r s : Prop\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=\niff.intro\n  (assume H : p ∧ q,\n    and.intro (and.right H) (and.left H))\n  (assume H : q ∧ p,\n    and.intro (and.right H) (and.left H))\n\nexample : p ∨ q ↔ q ∨ p :=\niff.intro\n  (assume H : p ∨ q,\n    or.elim H or.inr or.inl)\n  (assume H : q ∨ p,\n    or.elim H or.inr or.inl)\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\niff.intro\n  (assume H : (p ∧ q) ∧ r,\n    and.intro (and.left (and.left H))\n      (and.intro (and.right (and.left H))\n        (and.right H)))\n  (assume H : p ∧ (q ∧ r),\n    and.intro\n      (and.intro (and.left H)\n        (and.left (and.right H)))\n      (and.right (and.right H)))\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\niff.intro\n  (assume H : (p ∨ q) ∨ r,\n    or.elim H\n      (assume Hpq : p ∨ q,\n        or.elim Hpq or.inl\n          (assume Hq : q, or.inr (or.inl Hq)))\n      (assume Hr : r, or.inr (or.inr Hr)))\n  (assume H : p ∨ (q ∨ r),\n    or.elim H\n      (assume Hp : p, or.inl (or.inl Hp))\n      (assume Hqr : q ∨ r,\n        or.elim Hqr\n          (assume Hq : q, or.inl (or.inr Hq))\n          or.inr))\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\niff.intro\n  (assume H : p ∧ (q ∨ r),\n    have Hp : p, from and.left H,\n    have Hqr : q ∨ r, from and.right H,\n    or.elim Hqr\n      (λ Hq, or.inl (and.intro Hp Hq))\n      (λ Hr, or.inr (and.intro Hp Hr)))\n  (assume H : (p ∧ q) ∨ (p ∧ r),\n    or.elim H\n      (assume Hpq : p ∧ q,\n        and.intro (and.left Hpq)\n          (or.inl (and.right Hpq)))\n      (assume Hpr : p ∧ r,\n        and.intro (and.left Hpr)\n          (or.inr (and.right Hpr))))\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\niff.intro\n  (assume H : p ∨ (q ∧ r),\n    or.elim H\n      (λ Hp, and.intro (or.inl Hp) (or.inl Hp))\n      (assume Hqr,\n        and.intro\n          (or.inr (and.left Hqr))\n          (or.inr (and.right Hqr))))\n  (assume H : (p ∨ q) ∧ (p ∨ r),\n    have Hpq : p ∨ q, from and.left H,\n    have Hpr : p ∨ r, from and.right H,\n    or.elim Hpq or.inl\n      (assume Hq : q,\n        or.elim Hpr or.inl\n          (assume Hr : r,\n            or.inr (and.intro Hq Hr))))\n\n-- other properties\nexample : (p → q → r) ↔ (p ∧ q → r) :=\niff.intro\n  (assume H : p → q → r,\n    (assume Hpq : p ∧ q,\n      H (and.left Hpq) (and.right Hpq)))\n  (assume H : p ∧ q → r,\n    λ Hp, λ Hq, H (and.intro Hp Hq))\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\niff.intro\n  (assume H : (p ∨ q) → r,\n    and.intro (λ Hp, H (or.inl Hp))\n              (λ Hq, H (or.inr Hq)))\n  (assume H : (p → r) ∧ (q → r),\n    (assume Hpq : p ∨ q,\n      or.elim Hpq (and.left H) (and.right H)))\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\niff.intro\n  (assume Hpq : ¬(p ∨ q),\n    show ¬p ∧ ¬q, from\n    and.intro\n      (assume Hp : p,\n        Hpq (or.inl Hp))\n      (assume Hq : q,\n        Hpq (or.inr Hq)))\n  (assume H : ¬p ∧ ¬q,\n    have Hnp : ¬p, from and.left H,\n    have Hnq : ¬q, from and.right H,\n    not.intro\n      (assume Hpq : p ∨ q,\n        or.elim Hpq Hnp Hnq))\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\n  (assume H : ¬p ∨ ¬q,\n    not.intro\n      (assume Hpq : p ∧ q,\n        have Hp : p, from and.left Hpq,\n        have Hq : q, from and.right Hpq,\n        show false, from\n          or.elim H\n            (assume Hnp : ¬p, Hnp Hp)\n            (assume Hnq : ¬q, Hnq Hq)))\n\nexample : ¬(p ∧ ¬ p) :=\nnot.intro\n  (assume H : p ∧ ¬p,\n    have Hp : p, from and.left H,\n    have Hn : ¬p, from and.right H,\n    show false, from Hn Hp)\n\nexample : p ∧ ¬q → ¬(p → q) :=\n  (assume H : p ∧ ¬q,\n    have Hp : p, from and.left H,\n    have Hnq : ¬q, from and.right H,\n    not.intro\n      (assume Hpq : p → q,\n        show false, from Hnq (Hpq Hp)))\n\nexample : ¬p → (p → q) :=\n  (assume Hn : ¬p, (assume Hp : p, absurd Hp Hn))\n\nexample : (¬p ∨ q) → (p → q) :=\n  (assume H : ¬p ∨ q,\n    or.elim H\n      (assume Hn : ¬p, (assume Hp : p, absurd Hp Hn))\n      (assume Hq : q, (assume Hp : p, Hq)))\n\nexample : p ∨ false ↔ p :=\niff.intro\n  (assume H : p ∨ false,\n    or.elim H id false.elim)\n  or.inl\n\nexample : p ∧ false ↔ false :=\niff.intro\n  and.right\n  (assume H : false, and.intro (false.elim H) H)\n\nexample : ¬(p ↔ ¬p) :=\nnot.intro\n  (assume H : p ↔ ¬p,\n    have Hnp: ¬p, from not.intro (λ Hp, iff.mp H Hp Hp),\n    have Hp: p, from iff.mpr H Hnp,\n    show false, from not.intro Hnp Hp)\n\nexample : (p → q) → (¬q → ¬p) :=\n(assume H : p → q,\n  (assume Hnq : ¬q,\n    not.intro\n      (assume Hp : p,\n        Hnq (H Hp))))\n\n-- these require classical reasoning\nopen classical\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n  (assume H : p → r ∨ s,\n  by_cases\n    (assume Hp : p,\n      or.elim (H Hp)\n        (assume Hr : r,\n          or.inl (λ Hpp : p, Hr))\n        (assume Hs : s,\n          or.inr (λ Hpp : p, Hs)))\n    (assume Hnp : ¬p, or.inl (λ Hp : p, absurd Hp Hnp)))\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n  (assume H : ¬(p ∧ q),\n  by_cases\n    (assume Hp : p,\n    by_cases\n      (assume Hq : q, absurd (and.intro Hp Hq) H)\n      (assume Hnq : ¬q, or.inr Hnq))\n    (assume Hnp : ¬p, or.inl Hnp))\n\ntheorem impl_or : (p → q) → ¬p ∨ q :=\n  (assume H : p → q,\n    by_cases\n      or.inr\n      (assume Hnq : ¬q,\n        by_cases\n          (assume Hp : p, absurd (H Hp) Hnq)\n          or.inl))\n\ntheorem or_impl : ¬p ∨ q → (p → q) :=\n  (assume H : ¬p ∨ q,\n    (assume Hp : p,\n      or.elim H\n        (λ Hnp : ¬p, absurd Hp Hnp)\n        id))\n\ntheorem nimpl_and : ¬(p → q) → p ∧ ¬q :=\n  (assume H : ¬(p → q),\n    have Hnq : ¬q, from\n      by_cases \n        (assume Hq : q, absurd (λ Hp, Hq) H)\n        id,\n    have Hp : p, from\n      by_cases\n        id\n        (assume Hnp : ¬p, sorry),\n    and.intro Hp Hnq)\n  \nexample : (p → q) → (¬p ∨ q) :=\n  (assume H : p → q,\n    by_cases\n      (assume Hp : p, or.inr (H Hp))\n      (assume Hnp : ¬p, or.inl Hnp))\n\ntheorem contrapositive : (¬q → ¬p) → (p → q) :=\n  (assume H : ¬q → ¬p,\n    (assume Hp : p,\n      or.elim (em q)\n        id\n        (λ Hnq : ¬q, absurd Hp (H Hnq))))\n\nexample : p ∨ ¬p :=\n  em p\n\nexample : (((p → q) → p) → p) :=\n  (assume Hpqp : (p → q) → p,\n    by_cases \n      (assume Hp : p, Hp)\n      (assume Hnp : ¬p,\n        have Hnpq : ¬(p → q), from sorry,\n        and.left (nimpl_and p q Hnpq)))\n\n", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/logic_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7953877219331805}}
{"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 tactic.ring\nimport data.nat.prime\n\n/-!\n# IMO 1959 Q1\n\nProve that the fraction `(21n+4)/(14n+3)` is irreducible for every natural number `n`.\n\nSince Lean doesn't have a concept of \"irreducible fractions\" per se, we just formalize this\nas saying the numerator and denominator are relatively prime.\n-/\n\nopen nat\n\nlemma calculation (n k : ℕ) (h1 : k ∣ 21 * n + 4) (h2 : k ∣ 14 * n + 3) : k ∣ 1 :=\nhave h3 : k ∣ 2 * (21 * n + 4), from h1.mul_left 2,\nhave h4 : k ∣ 3 * (14 * n + 3), from h2.mul_left 3,\nhave h5 : 3 * (14 * n + 3) = 2 * (21 * n + 4) + 1, by ring,\n(nat.dvd_add_right h3).mp (h5 ▸ h4)\n\ntheorem imo1959_q1 : ∀ n : ℕ, coprime (21 * n + 4) (14 * n + 3) :=\nassume n, coprime_of_dvd' $ λ k hp h1 h2, calculation n k h1 h2\n", "meta": {"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/imo1959_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7953768157840526}}
{"text": "import Mathlib.Data.Nat.Basic\nimport Mathlib.Tactic.Cases\nimport Notes4.IndTypes\n/- \nInduction with Inductive Types\n\nLet's see a bit how how induction is called inductive types. \nFor each inductive type, recursors are automatically instantiated. \n-/\n\n#check Nat.rec\n#check List.rec\n\nexample (a b c: ℕ) : exp (a*b) c = (exp a c) * exp b c := by \n  apply @Nat.rec (fun c => exp (a*b) c = ((exp a c) * exp b c))\n  · simp [exp]\n  · intro n ih \n    simp [exp]\n    rw [ih]\n    ac_rfl\n\n/-\n\nUsing the recusors directly is not as ergnomic as some built in tactics \nof which there are few.\n\nFirst, we have already seen that `match` can be used to argue via \ninduction. \n\nLet's prove that our exponentiation function on ℕ is multiplicative in \nthe base. \n-/\n\ntheorem mul_of_mul_base_exp (a b c : ℕ) : exp (a*b) c = (exp a c) * exp b c := by \n  match c with \n  | 0 => simp only [exp] \n  | z+1 => \n    simp only [exp,Nat.add]\n    rw [mul_of_mul_base_exp a b z]\n    ac_rfl\n\n/-\n\nIn `mul_of_mul_base_exp`, we used induction at the step `rw [mul_of_mul_base_exp a b c]` \nsince this presumes a proof of `mul_of_mul_base_exp a b c`.\n\nConsider the following version using an anonymous `example`. \n\nexample (a b c: ℕ) : exp (a*b) c = (exp a c) * exp b c := by \n  match c with \n  | 0 => simp only [exp] \n  | c+1 => \n    simp only [exp,Nat.add] \n    -- how do we call the inductive step without a name?\n    sorry \n\nIn this case, we can use `induction` or `induction'`. \n\n-/\n\nvariable {α : Type} \n\nopen List\n\ndef iterateAppend : ℕ → List α → List α\n  | 0, _ => [] \n  | n+1, l => l ++ iterateAppend n l\n\n-- Using `induction` \nexample (n : ℕ) (l : List α) : n*(l.length) = (iterateAppend n l).length := by \n  induction n with \n  | zero => \n    simp only [iterateAppend,length]\n    rw [Nat.zero_mul]\n  | succ n' inductionHyp => \n    simp [iterateAppend,length]\n    rw [Nat.succ_mul]\n    rw [inductionHyp]\n    ac_rfl \n\n-- Using `induction'`\nexample (n : ℕ) (l : List α) : n*(l.length) = (iterateAppend n l).length := by \n  induction' n with m indhyp \n  · simp only [iterateAppend,length]\n    rw [Nat.zero_mul] \n  · simp [iterateAppend,length]\n    rw [Nat.succ_mul]\n    rw [indhyp]\n    ac_rfl \n\n#check Nat.mul\n\nopen Nat\n\ndef times : ℕ → ℕ → ℕ  \n  | _, 0 => 0 \n  | a , b+1 => times a b + a \n\nexample (n m : ℕ) : times n m = times m n := by \n  induction m with \n  | zero => \n    induction n with \n      | zero => rfl \n      | succ n' ih => \n        simp [times] at *\n        exact ih\n  | succ m' ih => \n    induction n with \n      | zero => \n        simp [times] at *\n        exact ih \n      | succ n' ih' => \n        simp [times] at *\n        rw [ih]\n        sorry \n@[simp]\ntheorem zero_times { n: ℕ } : times 0 n = 0 := by\n  match n with \n  | 0 => simp \n  | n'+1 => \n    simp [times]\n    exact zero_times \n\n@[simp]\ntheorem succ_times { n m : ℕ } : times (n+1) m = times n m + m := by \n  match m with \n  | 0 =>\n    simp [times]\n  | m'+1 => \n    simp [times]\n    rw [@succ_times n m']\n    ac_rfl\n\ntheorem times_comm (n m : ℕ) : times n m = times m n := by \n  match n,m with \n  | n, 0 => \n    simp [times]\n    -- rw [zero_times]  \n  | n, m'+1 => \n    simp [times]\n    -- rw [succ_times]\n    rw [times_comm n m']\n\nexample (a n m : ℕ) : times a (m + n) = times a m + times a n := by \n  induction a with\n  | zero => simp\n  | succ b ih => \n    simp only [succ_times]\n    rw [ih]\n    ac_rfl\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/Induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088004, "lm_q2_score": 0.8740772286044095, "lm_q1q2_score": 0.7953289877191443}}
{"text": "import tactic\n\nnamespace notes\n\nuniverse u\nvariables {X Y Z : Type u}\n\n--------------------------------------------------------------------------------\n-- # Functions\n\nsection\n  example (f : X → Y) (g : X → Y) :\n-- Proposition. (Extensionality of Functions)\n    f = g ↔ (∀ x : X, f x = g x)\n-- Note that in Lean it follows from an axiom (`funext`).\n-- Proof.\n    :=\n  begin\n    split,\n    { intros h, rw h, exact (λ x, rfl), },\n    { intros h, funext, exact h x, },\n  end\n-- ∎\nend\n\nsection\n-- Definitions.\n  def injective (f : X → Y) : Prop :=\n    ∀ (a b : X), f a = f b → a = b\n  def surjective (f : X → Y) : Prop :=\n    ∀ y : Y, ∃ x : X, f x = y\n  def bijective (f : X → Y) : Prop :=\n    injective f ∧ surjective f\nend\n\nsection\n  variables {f : X → Y} {g : Y → Z}\n\n  theorem composition_inj_of_inj :\n-- Theorem.\n    injective f → injective g → injective (g ∘ f)\n-- Proof.\n  :=\n  begin\n    unfold injective at *,\n    intros hf hg a b h,\n    unfold function.comp at *,\n    apply hf,\n    apply (hg (f a) (f b)),\n    exact h,\n  end\n-- ∎\n\n  theorem composition_surj_of_surj :\n-- Theorem.\n    surjective f → surjective g → surjective (g ∘ f)\n-- Proof.\n  :=\n  begin\n    unfold surjective at *,\n    intros hf hg z,\n    unfold function.comp at *,\n    cases (hg z) with y hy,\n    cases (hf y) with x hx,\n    use x,\n    rw [hx, hy],\n  end\n-- ∎\n\n  theorem composition_bij_of_bij :\n-- Theorem.\n    bijective f → bijective g → bijective (g ∘ f)\n-- Proof.\n  :=\n  begin\n    unfold bijective at *,\n    rintros ⟨hf_inj, hf_surj⟩ ⟨hg_inj, hg_surj⟩,\n    exact ⟨composition_inj_of_inj hf_inj hg_inj, composition_surj_of_surj hf_surj hg_surj⟩,\n  end\n-- ∎\n\n  theorem inj_of_composition_inj :\n-- Theorem.\n    injective (g ∘ f) → injective f\n-- Proof.\n  :=\n  begin\n    unfold injective at *,\n    intros h_inj a b h,\n    apply h_inj,\n    unfold function.comp,\n    rw h,\n  end\n-- ∎\n\n  theorem surj_of_composition_surj :\n-- Theorem.\n    surjective (g ∘ f) → surjective g\n-- Proof.\n  :=\n  begin\n    unfold surjective at *,\n    intros h z,\n    cases (h z) with x hx,\n    use (f x),\n    exact hx,\n  end\n-- ∎\nend\n\nsection\n-- Definition.\n  def are_inverse (f : X → Y) (g : Y → X) : Prop :=\n    (∀ x : X, g (f x) = x) ∧ (∀ y : Y, f (g y) = y)\n\n  lemma are_inverse.symm (f : X → Y) (g : Y → X) :\n-- Corollary.\n    are_inverse f g ↔ are_inverse g f\n-- Proof.\n  :=\n  begin\n    unfold are_inverse,\n    split,\n    { rintros ⟨hgf, hfg⟩, exact ⟨hfg, hgf⟩, },\n    { rintros ⟨hfg, hgf⟩, exact ⟨hgf, hfg⟩, },\n  end\n-- ∎\nend\n\nsection\n  open classical\n\n  theorem has_inverse_iff_bij (f : X → Y) :\n-- Theorem.\n    bijective f ↔ (∃ g : Y → X, are_inverse f g)\n-- Proof.\n  :=\n  begin\n    split,\n    { rintros ⟨hf_inj, hf_surj⟩,\n      let g : Y → X := (λ y, some (hf_surj y)),\n      use g,\n      split,\n      { intros x,\n        have hgy := some_spec (hf_surj (f x)),\n        have hgy' := hf_inj _ _ hgy,\n        exact hgy', },\n      { intros y,\n        have hgy := some_spec (hf_surj y),\n        exact hgy, } },\n    { rintros ⟨g, ⟨hgf, hfg⟩⟩,\n      split,\n      { intros a b h,\n        rw [← hgf a, h, hgf b], },\n      { intros y,\n        use (g y),\n        exact (hfg y), } },\n  end\n-- ∎\nend\n\n--------------------------------------------------------------------------------\n-- # Relations\n\nsection\n  variable r : X → X → Prop\n-- Definitions.\n  def reflexive : Prop :=\n    ∀ (a : X), r a a\n  def symmetric : Prop :=\n    ∀ {a b : X}, r a b → r b a\n  def antisymmetric : Prop :=\n    ∀ {a b : X}, r a b → r b a → a = b\n  def transitive : Prop :=\n    ∀ {a b c : X}, r a b → r b c → r a c\n  def total : Prop :=\n    ∀ (a b : X), r a b ∨ r b a\nend\n\nsection\n  variable r : X → X → Prop\n-- Definitions.\n  def is_partial_order : Prop :=\n    reflexive r ∧ antisymmetric r ∧ transitive r\n  def is_total_order : Prop :=\n    reflexive r ∧ antisymmetric r ∧ transitive r ∧ total r\n  def is_equivalence_relation : Prop :=\n    reflexive r ∧ symmetric r ∧ transitive r\nend\n\nsection\n  variables (r : X → X → Prop)\n-- Definition.\n  def cl (hr : is_equivalence_relation r) (s : X) : set X :=\n    (λ x, r s x)\nend\n\nsection\n  variables (r : X → X → Prop) (hr : is_equivalence_relation r)\n  local notation `cl` := cl r hr\n\n  lemma cl.eq_of_equiv {a b : X} :\n-- Lemma.\n    r a b → cl a = cl b\n-- Proof.\n  :=\n  begin\n    rcases hr with ⟨hrefl, hsymm, htrans⟩,\n    unfold «cl»,\n    intros hr,\n    ext, split,\n    { intros hax, exact (htrans (hsymm hr) hax), },\n    { intros hbx, exact (htrans hr hbx), },\n  end\n-- ∎\n\n  lemma cl.disjoint_of_not_equiv {a b : X} :\n-- Lemma.\n    ¬(r a b) → cl a ∩ cl b = ∅\n-- Proof.\n  :=\n  begin\n    rcases hr with ⟨hrefl, hsymm, htrans⟩,\n    unfold «cl» at *,\n    intros h,\n    ext, split,\n    { rintros ⟨hax, hbx⟩, exact h (htrans hax (hsymm hbx)), },\n    { intros hf, exfalso, exact hf, },\n  end\nend\n-- ∎\n\nsection\n-- Definition.\n  def is_partition (A : set (set X)) : Prop :=\n    ∀ x : X, ∃! a, a ∈ A ∧ x ∈ a\nend\n\nsection\n  variables (r : X → X → Prop) (hr : is_equivalence_relation r)\n  local notation `cl` := cl r hr\n\n  theorem partition_from_equiv :\n-- Theorem.\n    is_partition (λ s, ∃ x : X, s = cl x)\n-- Proof.\n  :=\n  begin\n    have hr' := hr,\n    rcases hr' with ⟨hrefl, hsymm, htrans⟩,\n    intros x,\n    use (cl x), split,                 -- Claim: `x` is only in `cl x`\n    { exact ⟨⟨x, rfl⟩, hrefl x⟩, },    -- By definition, `x` is in `cl x`\n    { unfold «cl»,\n      rintros a ⟨⟨z, ha⟩, hx : (a x)⟩,\n      ext y, split,                    -- Assume that `x` is also in `y`\n      { intros hy,\n        rw ha at *,\n        exact htrans (hsymm hx) hy, }, -- Then anything in `y` must be in `cl x`\n      { intros hxy,\n        rw ha at *,\n        exact htrans hx hxy, } },      -- And anything in `cl x` must be in `y`\n  end\n-- ∎\n\n  private theorem partition_equiv_eq_self {f : X → set X} {rf : X → X → Prop}\n-- Theorem.\n    (hf : ∀ a : X, f a = cl a) (hrf : ∀ a b : X, rf a b ↔ f a = f b) :\n    rf = r\n-- Proof.\n  :=\n  begin\n    rcases hr with ⟨hrefl, hsymm, htrans⟩,\n    unfold «cl» at *,\n    ext x y, split,\n    { intros hxy,\n      have h := (hrf x y).mp hxy,\n      rw [hf, hf] at h,\n      have h' : r y y → r x y,\n      { change (λ (x : X), r y x) y → r x y,\n        rw ← h,\n        exact id, },\n      exact h' (hrefl y), },\n    { intros hxy,\n      have h : f x = f y,\n      { rw [hf, hf],\n        ext, split,\n        { intros h, exact htrans (hsymm hxy) h, },\n        { intros h, exact htrans hxy h, }, },\n      exact (hrf x y).mpr h, },\n  end\n-- ∎\nend\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/1_intro_to_uni_maths/1_part_i.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368928, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7952390064739551}}
{"text": "import BrownCs22.Library.Tactics\n\n/-\n\nIn this file, we'll prove some of the identities from\nhttps://brown-cs22.github.io/resources/math-resources/logic.pdf \n\nNote that these identities are stated with the symbol `≡`,\nmeaning \"the formula on the left is equivalent to the formula on the right.\"\nIn Lean, we can use iff (bi-implication, `↔`) to mean the same thing.\n\nRemember the tactics we learned in Lecture 4. \nWe'll see a bit of new Lean syntax along the way.\n\nAlso remember that it doesn't matter what we name our hypotheses.\nIn our examples, we use patterns like `hp` for the hypothesis `p`,\n`hnpq` for the hypothesis `¬ p ∧ q` (hnpq for \"hypothesis not p q\"), etc.\nBut this is just a custom. You can choose any names you want.\nAs they say, the hardest problem in computer science is naming variables.\n\nYour task: fill in all the `sorry`s with proofs!\n\n-/\n\nvariable (p q r : Prop)\n\n-- ## Commutative Laws\n\n-- We'll do the first for you, as an example.\n-- Notice two things.\n-- One, must of these problems will start with `split_goal`,\n-- to turn the `iff` goal into two `implies` goals.\n-- Two, we structure our proof by putting each *subproof* in `{...}`.\n-- This isn't necessary but it helps with organization!\nexample : p ∧ q ↔ q ∧ p := by \n  split_goal \n  { intro hpq \n    eliminate hpq with hp hq \n    split_goal \n    assumption \n    assumption }\n  { intro hqp \n    eliminate hqp with hq hp \n    split_goal \n    assumption \n    assumption }\n\nexample : p ∨ q ↔ q ∨ p := by \n  split_goal \n  { intro hpq\n    eliminate hpq with hp hq \n    { right \n      assumption }\n    { left \n      assumption } }\n  { intro hqp \n    eliminate hqp with hq hp \n    { right \n      assumption }\n    { left \n      assumption } }\n\n\n-- ## Associative laws \n\n-- Notice that Lean doesn't print parentheses unless it needs to.\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := by \n  split_goal \n  { intro hpqr \n    eliminate hpqr with hpq hr \n    eliminate hpq with hp hq \n    split_goal \n    assumption\n    split_goal\n    assumption\n    assumption }\n  { intro hpqr \n    eliminate hpqr with hp hqr \n    eliminate hqr with hq hr \n    split_goal\n    split_goal\n    assumption\n    assumption\n    assumption }\n\n-- This is getting a little repetitive. \n-- To mix it up, we'll only do one direction of the iff this time.\n-- You won't start with `split_goal`, but instead, ... what?\nexample : (p ∨ q) ∨ r → p ∨ (q ∨ r) := by \n  intro hpqr \n  eliminate hpqr with hpq hr \n  { eliminate hpq with hp hq \n    { left\n      assumption }\n    { right \n      left\n      assumption } }\n  { right\n    right\n    assumption }\n\n-- ## Distributive laws \n\n-- warning, this one is kind of long!\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := by \n  split_goal \n  { intro hpqr \n    eliminate hpqr with hp hqr \n    eliminate hqr with hq hr \n    { left \n      split_goal\n      assumption\n      assumption }\n    { right \n      split_goal \n      assumption\n      assumption } }\n  { intro hpqpr \n    eliminate hpqpr with hpq hpr \n    { eliminate hpq with hp hq \n      split_goal \n      assumption \n      left\n      assumption }\n    { eliminate hpr with hp hr\n      split_goal \n      assumption \n      right\n      assumption } }\n\n-- Again, let's just do one direction. \n-- When we're proving an implication `→`, we'll always start with `intro`. \n-- This is such a common pattern that Lean gives us special syntax for it:\n-- we can do the intro \"in advance,\" before we start the proof,\n-- by naming the hypothesis to the left of the `:`.\n-- Notice that at the beginning of our proof, we already have the \n-- hypothesis `hpqr` in our context.\nexample (hpqr : p ∨ (q ∧ r)) : (p ∨ q) ∧ (p ∨ r) := by \n  eliminate hpqr with hp hqr \n  { split_goal \n    { left \n      assumption }\n    { left\n      assumption } }\n  { eliminate hqr with hq hr \n    split_goal \n    { right\n      assumption }\n    { right \n      assumption } }\n\n\n-- ## Identity laws \n\n/-\n\nWe'll do a few more together.\n\nLet's sneak a new tactic in. \nTo prove a goal `True`, you can use the tactic `trivial`. \nThis is a sensible proof rule: trivially, you can always show `True` is true!\n-/\n\nexample : p ∧ True ↔ p := by\n  split_goal\n  { intro hpT \n    eliminate hpT \n    assumption }\n  { intro hpT \n    split_goal\n    assumption \n    trivial }\n\n-- Before, we saw `contradiction` would work if we had hypotheses \n-- `p` and `¬ p` at the same time. \n-- It also works if we have a hypothesis `False`!\nexample : p ∨ False ↔ p := by \n  split_goal \n  { intro hpF \n    eliminate hpF with hp hF \n    assumption \n    contradiction }\n  { intro hp \n    left\n    assumption }\n\n/-\n\n## Negation laws\n\nIf you're following along with the list of identities, you'll see that\nwe've come to some laws like `(p ∨ ¬ p) ↔ True`.\n\nUnfortunately, we don't have the tools to prove these in Lean yet.\n\nBut, you can do the **Idempotent laws** and **Universal bound laws**.\nTry stating and proving these yourself!\n\n-/\n\n\n\n\n/-\n\n## De Morgan's Laws \n\nThese can be a bit of a challenge! Like the negation laws,\na few of the implications here will require some new tools. \nBut try out these directions.\n\nRemember that to prove a negation `¬ X`, you can use a *proof by contradiction*:\nadd a hypothesis `h : X` using `intro h`, and then show a contradiction.\n\n-/\n\nexample (hnpnq : ¬ p ∨ ¬ q) : ¬(p ∧ q) := by \n  intro hpq \n  eliminate hpq with hp hq\n  eliminate hnpnq with hnp hnq \n  contradiction\n  contradiction\n\nexample (hnpnq : ¬ p ∧ ¬ q) : ¬ (p ∨ q) := by \n  intro hpq \n  eliminate hnpnq with hnp hnq \n  eliminate hpq with hp hq \n  contradiction \n  contradiction\n\n\n/- \n\nThat's it for the moment! \nTry the **Absorption laws** and **Negation of True and False**\non your own, if you want to. Skip the definition laws for now.\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/Exercises/LogicIdentitiesSolutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430810103574, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7952389923569329}}
{"text": "import data.real.basic\n\n/-!\n# IMO 2011 Q3\n\nLet f : ℝ → ℝ be a function that satisfies\n\n   f(x + y) ≤ y * f(x) + f(f(x))\n\nfor all x and y. Prove that f(x) = 0 for all x ≤ 0.\n\n# Solution\n\nDirect translation of the solution found in https://www.imo-official.org/problems/IMO2011SL.pdf\n-/\n\ntheorem imo2011_q3 (f : ℝ → ℝ) (hf : ∀ x y, f (x + y) ≤ y * f x + f (f x)) :\n  ∀ x ≤ 0, f x = 0 :=\nbegin\n  -- reparameterize\n  have hxt : ∀ x t, f t ≤ t * f x - x * f x + f (f x),\n  { intros x t,\n    calc f t = f (x + (t - x))             : by rw (add_eq_of_eq_sub' rfl)\n         ... ≤ (t - x) * f x + f (f x)     : hf x (t - x)\n         ... = t * f x - x * f x + f (f x) : by rw sub_mul },\n\n  have h_ab_combined : ∀ a b, a * f a + b * f b ≤ 2 * f a * f b,\n  { intros a b,\n    linarith [hxt b (f a), hxt a (f b)] },\n\n  have h_f_nonneg_of_pos : ∀ a < 0, 0 ≤ f a,\n  { intros a han,\n    suffices : a * f a ≤ 0, from nonneg_of_mul_nonpos_right this han,\n    exact add_le_iff_nonpos_left.mp (h_ab_combined a (2 * f a)) },\n\n  have h_f_nonpos : ∀ x, f x ≤ 0,\n  { intros x,\n    by_contra h_suppose_not,\n    -- If we choose a small enough argument for f, then we get a contradiction.\n    let s := (x * f x - f (f x)) / (f x),\n    have hm : min 0 s - 1 < s := (sub_one_lt _).trans_le (min_le_right 0 s),\n    have hml : min 0 s - 1 < 0 := (sub_one_lt _).trans_le (min_le_left 0 s),\n\n    suffices : f (min 0 s - 1) < 0, from not_le.mpr this (h_f_nonneg_of_pos (min 0 s - 1) hml),\n\n    have hp : 0 < f x := not_le.mp h_suppose_not,\n    calc f (min 0 s - 1)\n           ≤ (min 0 s - 1) * f x - x * f x + f (f x) : hxt x (min 0 s - 1)\n      ...  < s * f x - x * f x + f (f x) : by linarith [(mul_lt_mul_right hp).mpr hm]\n      ...  = 0 : by { rw [(eq_div_iff hp.ne.symm).mp rfl], linarith } },\n\n  have h_fx_zero_of_neg : ∀ x < 0, f x = 0,\n  { intros x hxz,\n    exact (h_f_nonpos x).antisymm (h_f_nonneg_of_pos x hxz) },\n\n  intros x hx,\n  obtain (h_x_neg : x < 0) | (rfl : x = 0) := hx.lt_or_eq,\n  { exact h_fx_zero_of_neg _ h_x_neg },\n  { suffices : 0 ≤ f 0, from (h_f_nonpos 0).antisymm this,\n    have hno : f (-1) = 0 := h_fx_zero_of_neg (-1) neg_one_lt_zero,\n    have hp := hxt (-1) (-1),\n    rw hno at hp,\n    linarith },\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/imo2011_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7952334984550181}}
{"text": "theorem mem_singleton_iff {t: Type} {a b: t}:\n  a ∈ ({b} : set t) ↔ a = b :=\nbegin\n  split,\n  intro h,\n  cases h,\n  exact h,\n  exfalso,\n  exact h,\n  intro h,\n  rw h,\n  simp [singleton],\n  simp [has_insert.insert],\n  simp [set.insert],\n  simp [has_emptyc.emptyc],\n  simp [has_mem.mem],\n  simp [set.mem],\n  simp [set_of],\nend\n\ntheorem mem_pred {t: Type} {s: set t} {p: t -> Prop} {x: t}:\n  x ∈ { y ∈ s | p y} ->\n  x ∈ s :=\nbegin\n  intro h,\n  cases h,\n  exact h_left,\nend\n\ntheorem set_ext {t: Type} {a b: set t}: (∀ x, x ∈ a ↔ x ∈ b) -> a = b :=\nbegin\n  intro h,\n  exact funext (fun x, propext (h x)),\nend\n\ntheorem pred_distr_union {t: Type} {a b: set t} {p: t -> Prop}:\n  { x ∈ (a ∪ b) | p x } = { x ∈ a | p x } ∪ { x ∈ b | p x } :=\nset_ext begin\n  intro x,\n  split,\n  intro h,\n  cases h,\n  cases h_left,\n  left,\n  split,\n  exact h_left,\n  simp,\n  exact h_right,\n  right,\n  split,\n  exact h_left,\n  simp,\n  exact h_right,\n  intro h,\n  cases h,\n  cases h,\n  split,\n  left,\n  exact h_left,\n  simp,\n  exact h_right,\n  cases h,\n  split,\n  right,\n  exact h_left,\n  simp,\n  exact h_right,\nend\n\ntheorem singleton_not_pred {t: Type} {x: t} {p: t -> Prop} (npx: ¬ (p x)):\n  { y ∈ {x} | p y } = (∅: set t) :=\nset_ext begin\n  intro y,\n  split,\n  intro h,\n  cases h,\n  let hm := iff.elim_left mem_singleton_iff h_left,\n  rw hm at h_right,\n  exfalso,\n  exact npx h_right,\n  intro h,\n  exfalso,\n  exact h,\nend\n\ntheorem union_emp {t: Type} {a: set t}: ∅ ∪ a = a :=\nset_ext begin\n  intro x,\n  split,\n  intro h,\n  cases h,\n  exfalso,\n  exact h,\n  exact h,\n  intro h,\n  right,\n  exact h,\nend\n\ntheorem double_pred {t: Type} {s: set t} {p: t -> Prop}:\n  { x ∈ { y ∈ s | p y } | p x } = { x ∈ s | p x } :=\nset_ext begin\n  intro x,\n  split,\n  intro h,\n  cases h,\n  cases h_left,\n  split,\n  exact h_left_left,\n  simp,\n  exact h_right,\n  intro h,\n  cases h,\n  split,\n  split,\n  exact h_left,\n  simp,\n  exact h_right,\n  simp,\n  exact h_right,\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/set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.7951583400722054}}
{"text": "import .love02_backward_proofs_demo\n\n\n/-! # LoVe Exercise 2: Backward Proofs -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Question 1: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nbegin\n  intro,\n  exact a_1,\nend \n\nlemma K (a b : Prop) :\n  a → b → b :=\nbegin\n  intros,\n  exact a_2,\nend\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nbegin\n  intros,\n  apply a_1 a_3 a_2,\nend\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nbegin\n  intros,\n  apply a_1,\nend\n\n/-! Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nbegin\n  intros,\n  apply a_2,\nend\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nbegin\n  intros,\n  apply a_1 a_2 a_4,\nend\n/-! 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nbegin\n  intros,\n  apply not.intro,\n  intro,\n  apply a_2,\n  apply a_1 a_3,\nend\n/-! 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nbegin\n  apply iff.intro,\n  {\n    intro hpq,\n    apply and.intro,\n    {\n      intros x,\n      apply and.elim_left,\n      apply hpq,\n    },\n    {\n      intros x,\n      apply and.elim_right,\n      apply hpq,\n    },\n  },\n  {\n    intro hconj,\n    intros x,\n    apply and.intro,\n    { apply and.elim_left hconj },\n    { apply and.elim_right hconj },\n  }\nend\n\n/-! ## Question 2: Natural Numbers\n\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nbegin\n  induction n,\n  { refl },\n  { simp [n_ih, mul, add] }\nend\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nbegin\n  induction n,\n    { simp [add, add_zero, mul] },\n    { simp [add, add_succ, n_ih, mul, mul_zero, add_assoc] },\nend\n\n/-! 2.2. Prove commutativity and associativity of multiplication using the\n`induction` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nbegin\n  induction m,\n  { simp[mul_zero, mul] },\n  {\n    simp [mul_succ, m_ih, add, add_succ, mul, mul_zero, add_assoc, mul_add],\n    cc\n  },\nend\n\n/-! 2.3. Prove the symmetric variant of `mul_add` using `rewrite`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nbegin\n  induction l,\n  {\n    simp [add_zero, mul, mul_comm], \n  },\n  {\n    rw mul_comm (add l_n.succ m) n,\n    apply mul_add,\n  },\nend\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nbegin\n  induction l,\n  { simp[mul_zero, mul] },\n  {\n    simp [mul_succ],\n    rw <- l_ih,\n    rw mul_comm (mul l_n m) n,\n    rw mul_comm m n,\n    rw add_mul (mul l_n m),\n  },\nend\n\n/-! ## Question 3 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation :=\n∀a : Prop, (¬¬ a) → a\n\n/-! For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, because this would defeat the purpose of the exercise.\n\n3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`simp [excluded_middle, peirce]` to unfold the definitions of `excluded_middle`\nand `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nsorry\n\n/-! 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nsorry\n\n/-! We leave the missing implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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/love02_backward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8872046011730965, "lm_q1q2_score": 0.7951583346760839}}
{"text": "import Mathlib.Tactic.Basic\nimport Mathlib.Tactic.Cases\nimport Mathlib.Init.Data.Nat.Basic\n/-!\n## Structural Recursion\n\n_Structural recursion_ is a form of recursion that allows us to peel off one constructor from the\nvalue on which we recurse. The factorial function below is structurally recursive:\n-/\ndef fact : ℕ → ℕ\n| 0 => 0\n| (n + 1) => (n + 1) * fact n\n/-!\nThe constructor we peel off here is `Nat.succ` (written `+ 1`). Such functions are guaranteed to\ncall themselves only finitely many times before the recursion stops; for example, `fact 12345` will\ncall itself 12345 times. This is a prerequisite for establishing that the function terminates, an\nimportant property to ensure both logical consistency and termination of evaluation.\n\nWith structural recursion, there are as many equations as there are constructors. Novices are often\ntempted to supply additional, redundant cases, as in the following example:\n-/\ndef fact₁ : ℕ → ℕ\n| 0 => 0\n| 1 => 1\n| (n + 1) => (n + 1) * fact n\n/-!\nIt is in your own best interest to resist this temptation. The more cases you have in your\ndefinitions, the more work it will be to reason about them. Keep in mind the saying that one good\ndefinition is worth three theorems.\n\nFor structurally recursive functions, Lean can automatically prove termination. For more general\nrecursive schemes, the termination check may fail. Sometimes it does so for a good reason, as in the\nfollowing example:\n\n```lean\ndef illegal : ℕ → ℕ\n| n => illegal n + 1\n\n-- fails saying: fail to show termination for `illegal`\n```\nIf Lean were to accept this definition, we could exploit it to prove that `0 = 1`, by subtracting\n`illegal n` on each side of the equation `illegal n = illegal n + 1`. From `0 = 1`, we could derive `false`,\nand from `false`, we could derive anything, including the three-color theorem. Clearly, we do not want\nthat.\n\nIf we had used a variable and axiom, nothing could have saved us:\n-/\ndef immoral (x : ℕ) : ℕ := x + 1\n\naxiom immoral_eq (n : ℕ) : immoral n = immoral n + 1\n\nlemma proof_of_false :\nfalse := by\n  have h1 : immoral 0 = immoral 0 + 1 := immoral_eq 0\n  simp [h1] at *\n\n/-!\nAnother reason for preferring `def` is that the defining equations are used to compute. Tactics such\nas `rfl` that unify up to computation become stronger each time we introduce a definition, and the\ndiagnosis commands `#eval` and `#reduce` can be used on defined constants.\n\nThe observant reader will have noticed that the above definitions of factorial are mathematically\nwrong: `fact` shockingly returns `0` regardless of the argument, and `fact₂ 0` should give `1`, not\n`0`. We quite literally facted up. These embarrassing mistakes remind us to test our definitions and\nprove some properties about them. Although flawed axioms arise now and then, what is much more\ncommon are definitions that fail to capture the intended concepts. Just because a function is called\n`fact` does not mean that it actually computes factorials.\n-/\n", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/FunctionalProgramming/StructuralRecursion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.7951583302378463}}
{"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 algebraic_geometry.prime_spectrum.basic\nimport ring_theory.polynomial.basic\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\nopen ideal polynomial prime_spectrum set\nopen_locale polynomial\n\nnamespace algebraic_geometry\n\nnamespace polynomial\n\nvariables {R : Type*} [comm_ring R] {f : R[X]}\n\n/-- Given a polynomial `f ∈ 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})ᶜ` under the morphism\n`comap C : Spec R[x] → Spec R`. -/\ndef image_of_Df (f) : set (prime_spectrum R) :=\n  {p : prime_spectrum R | ∃ i : ℕ , (coeff f i) ∉ p.as_ideal}\n\nlemma is_open_image_of_Df : is_open (image_of_Df f) :=\nbegin\n  rw [image_of_Df, set_of_exists (λ i (x : prime_spectrum R), coeff f i ∉ x.as_ideal)],\n  exact is_open_Union (λ i, is_open_basic_open),\nend\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`. -/\nlemma comap_C_mem_image_of_Df {I : prime_spectrum R[X]}\n  (H : I ∈ (zero_locus {f} : set (prime_spectrum R[X]))ᶜ ) :\n  prime_spectrum.comap (polynomial.C : R →+* R[X]) I ∈ image_of_Df f :=\nexists_C_coeff_not_mem (mem_compl_zero_locus_iff_not_mem.mp H)\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C⁺ : Spec R[x] → Spec R`. -/\nlemma image_of_Df_eq_comap_C_compl_zero_locus :\n  image_of_Df f = prime_spectrum.comap (C : R →+* R[X]) '' (zero_locus {f})ᶜ :=\nbegin\n  ext x,\n  refine ⟨λ hx, ⟨⟨map C x.as_ideal, (is_prime_map_C_of_is_prime x.is_prime)⟩, ⟨_, _⟩⟩, _⟩,\n  { rw [mem_compl_iff, mem_zero_locus, singleton_subset_iff],\n    cases hx with i hi,\n    exact λ a, hi (mem_map_C_iff.mp a i) },\n  { ext x,\n    refine ⟨λ h, _, λ h, subset_span (mem_image_of_mem C.1 h)⟩,\n    rw ← @coeff_C_zero R x _,\n    exact mem_map_C_iff.mp h 0 },\n  { rintro ⟨xli, complement, rfl⟩,\n    exact comap_C_mem_image_of_Df complement }\nend\n\n/--  The morphism `C⁺ : Spec R[x] → Spec R` is open.\nStacks Project \"Lemma 00FB\", first part.\n\nhttps://stacks.math.columbia.edu/tag/00FB\n-/\ntheorem is_open_map_comap_C :\n  is_open_map (prime_spectrum.comap (C : R →+* R[X])) :=\nbegin\n  rintros U ⟨s, z⟩,\n  rw [← compl_compl U, ← z, ← Union_of_singleton_coe s, zero_locus_Union, compl_Inter, image_Union],\n  simp_rw [← image_of_Df_eq_comap_C_compl_zero_locus],\n  exact is_open_Union (λ f, is_open_image_of_Df),\nend\n\nend polynomial\n\nend algebraic_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/algebraic_geometry/prime_spectrum/is_open_comap_C.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133548753619, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7951125924567968}}
{"text": "import analysis.real tactic.norm_num algebra.group_power\n\ntheorem Q5a1 (S : set ℝ) : (∃ x : ℝ, x ∈ lower_bounds S) \n    ↔ (∃ y : ℝ, y ∈ upper_bounds {t : ℝ | ∃ s ∈ S, t = -s }) :=\nbegin\nsplit,\n{ intros H,\n  cases H with x Hx,\n  existsi (-x),\n  intro w,\n  have Hmw := Hx (-w),\n  intro Hw,\n  cases Hw with t Ht,\n  cases Ht with u Hu,\n  refine le_neg_of_le_neg _,\n  apply Hmw _,\n  rw [Hu],\n  rwa neg_neg },\n{ intros H,\n  cases H with y Hy,\n  existsi (-y),\n  intro mt,\n  have Ht := Hy (-mt),\n  intro Hmt,\n  refine neg_le_of_neg_le _,\n  apply Ht _,\n  existsi mt,\n  existsi Hmt,\n  refl\n}\nend \n\ntheorem Q5a2 (S : set ℝ) (x : ℝ) : is_glb S x ↔ \n    is_lub {t : ℝ | ∃ s ∈ S, t = -s} (-x) :=\nbegin\nsplit,\n{ intro HSx,\n  split,\n  { intros ms Hms,\n    refine le_neg_of_le_neg _,\n    refine HSx.left _ _,\n    cases Hms with s Hs,\n    cases Hs with H1 H2,\n    rw H2,\n    rwa neg_neg },\n  { intros b Hb,\n    apply neg_le_of_neg_le _,\n    apply HSx.2 (-b),\n    intros c Hc,\n    apply neg_le_of_neg_le _,\n    apply Hb (-c),\n    existsi c,\n    existsi Hc,\n    refl },\n},\n{ intro HSx,\n  split,\n  { intros ms Hms,\n    refine le_of_neg_le_neg _,\n    refine HSx.left _ _,\n    existsi [ms,Hms],\n    refl },\n  { intros b Hb,\n    apply le_of_neg_le_neg _,\n    apply HSx.2 (-b),\n    intros c Hc,\n    cases Hc with mc Hmc,\n    cases Hmc with H1 H2,\n    apply le_neg_of_le_neg _,\n    apply Hb (-c),\n    rw H2,\n    rwa neg_neg },\n},\nend\n\nlemma Q5bhelper (S : set ℝ) (x₁ x₂ : ℝ) : is_glb S x₁ ∧ is_glb S x₂ → x₁ ≤ x₂ :=\nbegin\nintro H,\nhave Hglb1 := H.left,\nhave Hlb1 := Hglb1.left,\nhave Hglb2 := H.right,\nhave H1 := Hglb2.right,\nexact H1 _ Hlb1,\nend\n\ntheorem Q5b (S : set ℝ) (x₁ x₂ : ℝ) : is_glb S x₁ ∧ is_glb S x₂ → x₁ = x₂ :=\nbegin\nintro H,\nhave H1 := Q5bhelper _ _ _ H,\nhave H2 := Q5bhelper _ _ _ ⟨H.right,H.left⟩,\n--exact eq_iff_le_and_le. 2 ⟨H1,H2⟩,\n-- TODO : did this used to work? What do I do now??\nexact le_antisymm H1 H2,\nend\n\ntheorem Q5c :  (∀ S : set ℝ, (∃ w : ℝ, w ∈ S) → (∃ x : ℝ, x ∈ upper_bounds S) → ∃ y : ℝ, is_lub S y) \n   →   (∀ T : set ℝ, (∃ w₁ : ℝ, w₁ ∈ T) → (∃ x₁ : ℝ, x₁ ∈ lower_bounds T) → ∃ y₁ : ℝ, is_glb T y₁) :=\nbegin\nintro H,\nintro T,\nhave H1 := H {x : ℝ | ∃ y : ℝ, y ∈ T ∧ x = -y},\nclear H,\nintro J2,\ncases J2 with w2 Jw2,\nhave H2 := H1 _,\n{ intro J3,\n  clear H1,\n  cases J3 with w3 Jw3,\n  have H3 := H2 _,\n  { clear H2,\n    cases H3 with y3 Hy3,\n    existsi (-y3),\n    split,\n    { intro t,\n      have H4 := Hy3.left (-t),\n      intro J5,\n      rw neg_le,\n      apply H4,\n      clear H4,\n      existsi t,\n      simp [J5]\n    },\n    intros t Ht,\n    have H4 := Hy3.right (-t),\n    rw le_neg,\n    apply H4,\n    clear H4,\n    intros u Hu,\n    cases Hu with v Hv,\n    rw [Hv.right],\n    refine neg_le_neg _,\n    apply Ht,\n    exact Hv.left,\n  },\n  existsi (-w3),\n  intros z Hz,\n  rw le_neg,\n  apply Jw3,\n  cases Hz with u Hu,\n  rw Hu.right,\n  rw neg_neg,\n  exact Hu.left\n},\nexistsi (-w2),\nexistsi w2,\nsimp [Jw2],\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/problem_bank/PB0605/S0605.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.795017573108183}}
{"text": "/-***************-/\n/- ** BASICS ** --/\n/-***************-/\n\n/-\n# A\n\nWrite a defintion of x as a value of \ntype nat having the specific value 0.\nBe sure it type-checks. \n-/\n\ndef x := 0\n\n/-\n# B\n\nWrite a definition of f as a function\nof type ℕ → ℕ that returns the square of\nthe value to which it is applied (i.e.,\nthat it is given as an argument)\n-/\n\ndef f (n : ℕ) : ℕ := n * n\n\n/-\n# C\n\nWrite a definition of a function, nt, that\ntakes any proposition, P, and that returns\nthe proposition, P → false. \n-/\n\ndef nt (P: Prop) := P → false\n\n\n/-\n# D\n\nWhat is the type of this function? Hint:\nUse #check to check it.\n-/\n\n-- Prop → Prop\n\n\n/-****************************************-/\n/- ** PROOFS OF EQUALITY PROPOSITIONS ** --/\n/-****************************************-/\n\n\n/-\n# 1\n\nWrite a function that takes any type, \nT : Type, and any value, t : T, and that \nreturns a proof of t = t.\n-/\n\ndef myfunc (T : Type) (t: T) := eq.refl t\n\n/-\n#2a\n\nWrite a function that takes any type, T; \nthree values,  a, b, and c, of type T; a \nproof of a = b; and a proof of b = c; and that \nreturns a proof of c = a. We give you most of \nthe answer. Replace sorry with your answer.  \n-/\n\ndef aBbCCa \n    { T : Type } \n    (a b c : T)\n    (ab : a = b)\n    (bc: c = b) :\n    (c = a) \n    := eq.symm (eq.trans ab (eq.symm bc))\n\n-- Sullivan Note: Confusing name: bc\n\n/-\n#2b.\n\nDefine aBbCCa' to be the same function, but specify \nits type using ∀ and → connectives, and then provide\nthe function value using a lambda expression (λ). So\nyou will start with \"def\", then the name, then a :,\nthen the proposition, starting with ∀ and ending with\n→ (c = a), followed by :=, and finally follwed by a\nlambda expression.\n-/\n\ndef aBbCCa' : \n    ∀ T : Type, \n    ∀ a b c : T,\n    a = b → c = b → c = a \n    := \n        λ T a b c ab bc,\n            eq.symm (eq.trans ab (eq.symm bc))\n\n\n/-*******************************-/\n/- ** PROOFS OF CONJUNCTIONS ** --/\n/-*******************************-/\n\n/-\n#3\n\nWe assume P Q and R are propositions using the\nfollowing \"variables\" declaration. That means that\nwe can use P, Q, R, and S in the following theorems\nwithout having to use ∀ P Q R S : Prop to introduce\nthem again for each individual proposition.\n-/\n\nvariables P Q R S : Prop\n\n/-\n#4\n\nProve the following propositions by completing\nthe definitions (replace sorrys with your answers).\n-/\n\ntheorem t1 : P → Q → R → P := \n    λ pfP pfQ pfR, pfP\n\ntheorem t2 : Q → (Q ∧ Q) := \n    λ pfQ, and.intro pfQ pfQ\n\ntheorem t3 : (P ∧ Q) ∧ (Q ∧ R) → (P ∧ R) := \n    λ pqr, \n        and.intro pqr.left.left pqr.right.right\n\n\n\n/-*******************************-/\n/- ** PROOFS OF IMPLICATIONS ** --/\n/-*******************************-/\n\n/-\n#6\n\nProve the following theorem. It claims that\nimplication is transitive (which it is).\n-/\n\ntheorem t4 : ((P → Q) ∧ P) → Q := \n    λ pqp, pqp.left pqp.right\n\ntheorem t5 : \n(P → Q) → (Q → R) → (R → S) → (P → S) := \n    λ pq qr rs,\n        λ p,\n            rs (qr (pq p))\n        \n\n/-******************-/\n/- ** Functions ** --/\n/-******************-/\n\n\n/-\n#7\n\nComplete the following definition\nwith a value that makes the definition\ntype-check. You can answer with a\nlambda expression. You can also\nuse a tactic script if you prefer.\n-/\ndef n2n : ℕ → ℕ := \n    λ n, n -- or λ n, 0; etc.\n\n/-\n#8\n\nDefine a function called double \nthat takes any natural number, n, \nand returns two times n. \n-/\ndef double (n : ℕ) := 2 * n\n\n/-\n#9\n\nWrite a test case for double\nin the form of a theorem called\nd15is30, that asserts that the\ndouble of 15 is 30, and prove it.\n-/\n\ntheorem d15is30 : double 15 = 30 := rfl\n\n/-\n#10\n\nWrite a function, sum3, that takes three \nnatural numbers, a, b, c, and that returns\nthe sum of a, b, and c. Use a λ expression\nto express the function.\n-/\n\ndef sum3 /- ℕ → ℕ → ℕ → ℕ -/:=\n    λ a b c : ℕ, a + b + c\n\n\n/-*****************-/\n/- ** NEGATION ** --/\n/-*****************-/\n\n/-\n\n#11\n\nYou already know that double\nnegation elimination requires\nclassical reasoning (using the \nlaw of the excluded middle).\nGive a proof of the following\nproposition, which asserts that\nit's valid to introduce double\nnegatations. Note: You do not \nneed the law of the excluded\nmiddle to prove it.\n-/\n\ndef t6 : P → ¬ ¬ P := \nbegin\n    assume p : P,\n    assume np : ¬ P,\n    apply false.elim (np p),\nend\n\n\n/-\n\n# 12\n\nYou've learned a few important \nproof strategies. Explain in a \nfew words when might a proof\nby negation be attempted, and \nhow one proceeds to use it.\n\nKnow the answer to the same\nquestion about a proof by\ncontradiction. \n-/\n\n/-\nANSWER: Proof by negation can when used\nwhen the goal is to prove a proposition, \n¬ P. To prove ¬ P, one shows that assuming\nP provides a path to a proof of false.\n\nProof by contradiction can be used when\nthe goal is to prove P. To prove it, one\nshows that assuming ¬ P provides a path\nto a proof of false. This proves ¬ ¬ P.\nFrom this and by use of excluded middle\none obtains from this ¬ ¬ P, a proof of \nP. \n-/\n\n/-\n\n# 13\n\nExplain precisely why using a\nproof by contradiction relies\non classical reasoning using\nthe law of the excluded middle.\n-/\n\n/-\nAnswer: It's the law of the \nexcluded middle that enables \ndouble negation elimination, \nwhich is needed to deduce P \nfrom ¬ ¬ P.\n-/\n\n/-\n\n14\n\nEXTRA CREDIT: Write a function \nthat takes a function, f, of type\nℕ → ℕ, and that returns a function\nthat, for any value, n, returns \none more that what f returns. \n-/\n\ndef f_plus_one (f: ℕ → ℕ) : (ℕ → ℕ) :=\n    λ n,\n        1 + f n\n\n/-\nThat's the end of the practice test.\nHere's a partial inventory of inference\nrules we've covered. and related concepts.\nThis is not enough material for a complete\nreview. Reread all the notes and work any\nproblems that you're not yet sure you know\nhow to solve.\n-/\n\n\n/-\nPartial inventory of inference rules.\n\n* Equality\n-- eq.refl : given a type T and a value t : T, derives a proof of t = t\n-- eq.symm : given a type T, values a b : T, and a proof of a = b, derives a proof of b = a\n-- eq.trans : given a type T, values a b c : T, and proofs of a = b and b = c, derives a proof of a = c\n\n* Conjunction\n-- and.intro : given propositions, P Q : Prop, a proof P : P, and a proof q : Q, derives a proof of P ∧ Q\n-- and.elim_right : given propositions, P Q : Prop and a proof pq : P ∧ Q, derives a proof of P\n-- and.elim_right : given propositions, P Q : Prop and a proof pq : P ∧ Q, derives a proof of Q\n\n* Implication\n-- → introduction: given P Q : Prop and a derivation of a proof Q from a proof of P, conclude P → Q\n-- note : a derivation of a proof of Q from a proof of P is given as a function of type P → Q\n-- → elimination: given propositions, P and Q, a proof of P → Q, and a proof of P, derive a proof of Q\n-- note that → elimination is both a formal version of Aristotle's modus ponens rule and function application\n\n* Negation\n-- introduction : given a proposition P and a proof of P → false, conclude ¬ P\n-- elimination\n---- in constructive logic, showing that a proposition, ¬ P, is false proves only ¬ ¬ P, not that P is true\n---- try to derive a proof of P from the assumption of a proof for ¬ ¬ P and you will see the problem\n---- you can read ¬ ¬ P as \"there's no proof of ¬ P,\" or as \"¬ P is false,\" \n---- classical logic adds the axiom of the excluded middle (AEM), stating that ∀ P : Prop, P ∨ ¬ P\n---- if you accept this axiom and you know that ¬ P is false, then P must be true\n---- the AEM enables ¬ elimination\n---- given a proposition P and a proof of ¬ P → false (of ¬ ¬ P), derive a proof of P\n\n* Forall\n-- introduction : to prove ∀ p : P, Q, where P is a type and Q is a proposition that can involve be written in terms of p, show that Q holds for an any arbitrarily assumed value, p, of type P\n-- elimination : given a proof of ∀ p : P, Q, and a specific value x : P, conclude Q \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/exam1-practice-key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8688267830311354, "lm_q1q2_score": 0.7948904494867425}}
{"text": "import kb_real_defs\n\n/-\n# Chapter 1 : Sets\n\n## Level 9\n-/\n\n/- \nThis is a little more complicated example asking you to work with intervals of reals.\nThe result will be of help in the sup-inf world.\n-/\n\nnotation `[` a `,` b `]`  := set.Icc a b\n\ndef mem_prod_sets (A : set ℝ) (B : set ℝ) := { x : ℝ | ∃ y ∈ A, ∃ z ∈ B, x = y * z}\n\n\n/- Lemma\nIf $x = 0$, then `x ∈ mem_prod_sets [(-2:ℝ),-1] [(0:ℝ), 3]`\n-/\nlemma zero_in_prod : (0:ℝ) ∈ mem_prod_sets [(-2:ℝ), -1] [(0:ℝ), 3] :=\nbegin\n  rw mem_prod_sets,\n  dsimp,\n  use -2,\n  split, \n  { rw mem_Icc_iff,\n    split; linarith\n  },\n  use 0,\n  split,\n  { rw mem_Icc_iff,\n    split; linarith\n  },\n  norm_num\nend\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/sets/sets_level09.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7948893858776704}}
{"text": "/-\nCopyright (c) 2014 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\n\nimport data.int.cast.defs\n\n/-!\n# Characteristic zero\n\nA ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered\nas an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`\nexcept for the existence of `1` in this file characteristic zero is defined for additive monoids\nwith `1`.\n\n## Main definition\n\n`char_zero` is the typeclass of an additive monoid with one such that the natural homomorphism\nfrom the natural numbers into it is injective.\n\n## TODO\n\n* Unify with `char_p` (possibly using an out-parameter)\n-/\n\n/-- Typeclass for monoids with characteristic zero.\n  (This is usually stated on fields but it makes sense for any additive monoid with 1.)\n\n*Warning*: for a semiring `R`, `char_zero R` and `char_p R 0` need not coincide.\n* `char_zero R` requires an injection `ℕ ↪ R`;\n* `char_p R 0` asks that only `0 : ℕ` maps to `0 : R` under the map `ℕ → R`.\n\nFor instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that\n`char_zero {0, 1}` does not hold and yet `char_p {0, 1} 0` does.\nThis example is formalized in `counterexamples/char_p_zero_ne_char_zero`.\n -/\nclass char_zero (R : Type*) [add_monoid_with_one R] : Prop :=\n(cast_injective : function.injective (coe : ℕ → R))\n\ntheorem char_zero_of_inj_zero {R : Type*} [add_group_with_one R]\n  (H : ∀ n:ℕ, (n:R) = 0 → n = 0) : char_zero R :=\n⟨λ m n h, begin\n  induction m with m ih generalizing n, { rw H n, rw [← h, nat.cast_zero] },\n  cases n with n, { apply H, rw [h, nat.cast_zero], },\n  simp_rw [nat.cast_succ, add_right_cancel_iff] at h, rwa ih,\nend⟩\n\nnamespace nat\nvariables {R : Type*} [add_monoid_with_one R] [char_zero R]\n\ntheorem cast_injective : function.injective (coe : ℕ → R) :=\nchar_zero.cast_injective\n\n@[simp, norm_cast] theorem cast_inj {m n : ℕ} : (m : R) = n ↔ m = n :=\ncast_injective.eq_iff\n\n@[simp, norm_cast] theorem cast_eq_zero {n : ℕ} : (n : R) = 0 ↔ n = 0 :=\nby rw [← cast_zero, cast_inj]\n\n@[norm_cast] theorem cast_ne_zero {n : ℕ} : (n : R) ≠ 0 ↔ n ≠ 0 :=\nnot_congr cast_eq_zero\n\nlemma cast_add_one_ne_zero (n : ℕ) : (n + 1 : R) ≠ 0 :=\nby exact_mod_cast n.succ_ne_zero\n\n@[simp, norm_cast] \n\n@[norm_cast] theorem cast_ne_one {n : ℕ} : (n : R) ≠ 1 ↔ n ≠ 1 :=\ncast_eq_one.not\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/algebra/char_zero/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.7948586076644452}}
{"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.definitions\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\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\nnamespace polynomial\n\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 ≠ 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = ⊤`. -/\ndef trailing_degree {R : Type u} [semiring R] (p : polynomial R) : with_top ℕ :=\n  finset.inf (finsupp.support p) some\n\ntheorem trailing_degree_lt_wf {R : Type u} [semiring R] : well_founded fun (p q : polynomial R) => trailing_degree p < trailing_degree q :=\n  inv_image.wf trailing_degree (with_top.well_founded_lt nat.lt_wf)\n\n/-- `nat_trailing_degree p` forces `trailing_degree p` to `ℕ`, by defining\n`nat_trailing_degree ⊤ = 0`. -/\ndef nat_trailing_degree {R : Type u} [semiring R] (p : polynomial R) : ℕ :=\n  option.get_or_else (trailing_degree p) 0\n\n/-- `trailing_coeff p` gives the coefficient of the smallest power of `X` in `p`-/\ndef trailing_coeff {R : Type u} [semiring R] (p : polynomial R) : R :=\n  coeff p (nat_trailing_degree p)\n\n/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/\ndef trailing_monic {R : Type u} [semiring R] (p : polynomial R) :=\n  trailing_coeff p = 1\n\ntheorem trailing_monic.def {R : Type u} [semiring R] {p : polynomial R} : trailing_monic p ↔ trailing_coeff p = 1 :=\n  iff.rfl\n\nprotected instance trailing_monic.decidable {R : Type u} [semiring R] {p : polynomial R} [DecidableEq R] : Decidable (trailing_monic p) :=\n  eq.mpr sorry (_inst_2 (trailing_coeff p) 1)\n\n@[simp] theorem trailing_monic.trailing_coeff {R : Type u} [semiring R] {p : polynomial R} (hp : trailing_monic p) : trailing_coeff p = 1 :=\n  hp\n\n@[simp] theorem trailing_degree_zero {R : Type u} [semiring R] : trailing_degree 0 = ⊤ :=\n  rfl\n\n@[simp] theorem nat_trailing_degree_zero {R : Type u} [semiring R] : nat_trailing_degree 0 = 0 :=\n  rfl\n\ntheorem trailing_degree_eq_top {R : Type u} [semiring R] {p : polynomial R} : trailing_degree p = ⊤ ↔ p = 0 := sorry\n\ntheorem trailing_degree_eq_nat_trailing_degree {R : Type u} [semiring R] {p : polynomial R} (hp : p ≠ 0) : trailing_degree p = ↑(nat_trailing_degree p) := sorry\n\ntheorem trailing_degree_eq_iff_nat_trailing_degree_eq {R : Type u} [semiring R] {p : polynomial R} {n : ℕ} (hp : p ≠ 0) : trailing_degree p = ↑n ↔ nat_trailing_degree p = n := sorry\n\ntheorem trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos {R : Type u} [semiring R] {p : polynomial R} {n : ℕ} (hn : 0 < n) : trailing_degree p = ↑n ↔ nat_trailing_degree p = n := sorry\n\ntheorem nat_trailing_degree_eq_of_trailing_degree_eq_some {R : Type u} [semiring R] {p : polynomial R} {n : ℕ} (h : trailing_degree p = ↑n) : nat_trailing_degree p = n := sorry\n\n@[simp] theorem nat_trailing_degree_le_trailing_degree {R : Type u} [semiring R] {p : polynomial R} : ↑(nat_trailing_degree p) ≤ trailing_degree p := sorry\n\ntheorem nat_trailing_degree_eq_of_trailing_degree_eq {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] {q : polynomial S} (h : trailing_degree p = trailing_degree q) : nat_trailing_degree p = nat_trailing_degree q := sorry\n\ntheorem le_trailing_degree_of_ne_zero {R : Type u} {n : ℕ} [semiring R] {p : polynomial R} (h : coeff p n ≠ 0) : trailing_degree p ≤ ↑n :=\n  (fun (this : finset.inf (finsupp.support p) some ≤ some n) => this) (finset.inf_le (iff.mpr finsupp.mem_support_iff h))\n\ntheorem nat_trailing_degree_le_of_ne_zero {R : Type u} {n : ℕ} [semiring R] {p : polynomial R} (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n := sorry\n\ntheorem trailing_degree_le_trailing_degree {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : coeff q (nat_trailing_degree p) ≠ 0) : trailing_degree q ≤ trailing_degree p := sorry\n\ntheorem trailing_degree_ne_of_nat_trailing_degree_ne {R : Type u} [semiring R] {p : polynomial R} {n : ℕ} : nat_trailing_degree p ≠ n → trailing_degree p ≠ ↑n := sorry\n\ntheorem nat_trailing_degree_le_of_trailing_degree_le {R : Type u} [semiring R] {p : polynomial R} {n : ℕ} {hp : p ≠ 0} (H : ↑n ≤ trailing_degree p) : n ≤ nat_trailing_degree p :=\n  iff.mp with_top.coe_le_coe\n    (eq.mp (Eq._oldrec (Eq.refl (↑n ≤ trailing_degree p)) (trailing_degree_eq_nat_trailing_degree hp)) H)\n\ntheorem nat_trailing_degree_le_nat_trailing_degree {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} {hq : q ≠ 0} (hpq : trailing_degree p ≤ trailing_degree q) : nat_trailing_degree p ≤ nat_trailing_degree q := sorry\n\n@[simp] theorem trailing_degree_monomial {R : Type u} {a : R} {n : ℕ} [semiring R] (ha : a ≠ 0) : trailing_degree (coe_fn (monomial n) a) = ↑n := sorry\n\ntheorem nat_trailing_degree_monomial {R : Type u} {a : R} {n : ℕ} [semiring R] (ha : a ≠ 0) : nat_trailing_degree (coe_fn (monomial n) a) = n := sorry\n\ntheorem nat_trailing_degree_monomial_le {R : Type u} {a : R} {n : ℕ} [semiring R] : nat_trailing_degree (coe_fn (monomial n) a) ≤ n := sorry\n\ntheorem le_trailing_degree_monomial {R : Type u} {a : R} {n : ℕ} [semiring R] : ↑n ≤ trailing_degree (coe_fn (monomial n) a) := sorry\n\n@[simp] theorem trailing_degree_C {R : Type u} {a : R} [semiring R] (ha : a ≠ 0) : trailing_degree (coe_fn C a) = 0 :=\n  trailing_degree_monomial ha\n\ntheorem le_trailing_degree_C {R : Type u} {a : R} [semiring R] : 0 ≤ trailing_degree (coe_fn C a) :=\n  le_trailing_degree_monomial\n\ntheorem trailing_degree_one_le {R : Type u} [semiring R] : 0 ≤ trailing_degree 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 ≤ trailing_degree 1)) (Eq.symm C_1))) le_trailing_degree_C\n\n@[simp] theorem nat_trailing_degree_C {R : Type u} [semiring R] (a : R) : nat_trailing_degree (coe_fn C a) = 0 :=\n  iff.mp nonpos_iff_eq_zero nat_trailing_degree_monomial_le\n\n@[simp] theorem nat_trailing_degree_one {R : Type u} [semiring R] : nat_trailing_degree 1 = 0 :=\n  nat_trailing_degree_C 1\n\n@[simp] theorem nat_trailing_degree_nat_cast {R : Type u} [semiring R] (n : ℕ) : nat_trailing_degree ↑n = 0 := sorry\n\n@[simp] theorem trailing_degree_C_mul_X_pow {R : Type u} {a : R} [semiring R] (n : ℕ) (ha : a ≠ 0) : trailing_degree (coe_fn C a * X ^ n) = ↑n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (trailing_degree (coe_fn C a * X ^ n) = ↑n)) (C_mul_X_pow_eq_monomial a n)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (trailing_degree (coe_fn (monomial n) a) = ↑n)) (trailing_degree_monomial ha)))\n      (Eq.refl ↑n))\n\ntheorem le_trailing_degree_C_mul_X_pow {R : Type u} [semiring R] (n : ℕ) (a : R) : ↑n ≤ trailing_degree (coe_fn C a * X ^ n) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (↑n ≤ trailing_degree (coe_fn C a * X ^ n))) (C_mul_X_pow_eq_monomial a n)))\n    le_trailing_degree_monomial\n\ntheorem coeff_eq_zero_of_trailing_degree_lt {R : Type u} {n : ℕ} [semiring R] {p : polynomial R} (h : ↑n < trailing_degree p) : coeff p n = 0 :=\n  iff.mp not_not (mt le_trailing_degree_of_ne_zero (not_le_of_gt h))\n\ntheorem coeff_eq_zero_of_lt_nat_trailing_degree {R : Type u} [semiring R] {p : polynomial R} {n : ℕ} (h : n < nat_trailing_degree p) : coeff p n = 0 := sorry\n\n@[simp] theorem coeff_nat_trailing_degree_pred_eq_zero {R : Type u} [semiring R] {p : polynomial R} {hp : 0 < ↑(nat_trailing_degree p)} : coeff p (nat_trailing_degree p - 1) = 0 :=\n  coeff_eq_zero_of_lt_nat_trailing_degree\n    (nat.sub_lt (iff.mp (with_top.zero_lt_coe (nat_trailing_degree p)) hp) nat.one_pos)\n\ntheorem le_trailing_degree_X_pow {R : Type u} [semiring R] (n : ℕ) : ↑n ≤ trailing_degree (X ^ n) := sorry\n\ntheorem le_trailing_degree_X {R : Type u} [semiring R] : 1 ≤ trailing_degree X :=\n  le_trailing_degree_monomial\n\ntheorem nat_trailing_degree_X_le {R : Type u} [semiring R] : nat_trailing_degree X ≤ 1 :=\n  nat_trailing_degree_monomial_le\n\n@[simp] theorem trailing_coeff_eq_zero {R : Type u} [semiring R] {p : polynomial R} : trailing_coeff p = 0 ↔ p = 0 := sorry\n\ntheorem trailing_coeff_nonzero_iff_nonzero {R : Type u} [semiring R] {p : polynomial R} : trailing_coeff p ≠ 0 ↔ p ≠ 0 :=\n  not_congr trailing_coeff_eq_zero\n\ntheorem nat_trailing_degree_mem_support_of_nonzero {R : Type u} [semiring R] {p : polynomial R} : p ≠ 0 → nat_trailing_degree p ∈ finsupp.support p :=\n  iff.mpr mem_support_iff_coeff_ne_zero ∘ iff.mpr trailing_coeff_nonzero_iff_nonzero\n\ntheorem nat_trailing_degree_le_of_mem_supp {R : Type u} [semiring R] {p : polynomial R} (a : ℕ) : a ∈ finsupp.support p → nat_trailing_degree p ≤ a :=\n  nat_trailing_degree_le_of_ne_zero ∘ iff.mp mem_support_iff_coeff_ne_zero\n\ntheorem nat_trailing_degree_eq_support_min' {R : Type u} [semiring R] {p : polynomial R} (h : p ≠ 0) : nat_trailing_degree p = finset.min' (finsupp.support p) (iff.mpr nonempty_support_iff h) := sorry\n\n@[simp] theorem trailing_degree_one {R : Type u} [semiring R] [nontrivial R] : trailing_degree 1 = 0 :=\n  trailing_degree_C one_ne_zero\n\n@[simp] theorem trailing_degree_X {R : Type u} [semiring R] [nontrivial R] : trailing_degree X = 1 :=\n  trailing_degree_monomial one_ne_zero\n\n@[simp] theorem nat_trailing_degree_X {R : Type u} [semiring R] [nontrivial R] : nat_trailing_degree X = 1 :=\n  nat_trailing_degree_monomial one_ne_zero\n\n@[simp] theorem trailing_degree_neg {R : Type u} [ring R] (p : polynomial R) : trailing_degree (-p) = trailing_degree p := sorry\n\n@[simp] theorem nat_trailing_degree_neg {R : Type u} [ring R] (p : polynomial R) : nat_trailing_degree (-p) = nat_trailing_degree p := sorry\n\n@[simp] theorem nat_trailing_degree_int_cast {R : Type u} [ring R] (n : ℤ) : nat_trailing_degree ↑n = 0 := sorry\n\n/-- The second-lowest coefficient, or 0 for constants -/\ndef next_coeff_up {R : Type u} [semiring R] (p : polynomial R) : R :=\n  ite (nat_trailing_degree p = 0) 0 (coeff p (nat_trailing_degree p + 1))\n\n@[simp] theorem next_coeff_up_C_eq_zero {R : Type u} [semiring R] (c : R) : next_coeff_up (coe_fn C c) = 0 := sorry\n\ntheorem next_coeff_up_of_pos_nat_trailing_degree {R : Type u} [semiring R] (p : polynomial R) (hp : 0 < nat_trailing_degree p) : next_coeff_up p = coeff p (nat_trailing_degree p + 1) := sorry\n\ntheorem coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} (h : trailing_degree p < trailing_degree q) : coeff q (nat_trailing_degree p) = 0 :=\n  coeff_eq_zero_of_trailing_degree_lt (has_le.le.trans_lt nat_trailing_degree_le_trailing_degree h)\n\ntheorem ne_zero_of_trailing_degree_lt {R : Type u} [semiring R] {p : polynomial R} {n : with_top ℕ} (h : trailing_degree p < n) : p ≠ 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/degree/trailing_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7947245411151231}}
{"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\" (`∧`)\n\nWe learn about how to manipulate `P ∧ 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### The `cases` tactic\n\nIf `h : P ∧ Q` is a hypothesis, then `cases h with hP hQ,`\ndecomposes it into two hypotheses `hP : P` and `hQ : Q`.\n\n### The `split` tactic\n\nIf `⊢ P ∧ Q` is in the goal, The `split` tactic will turn it into\ntwo goals, `⊢ P` and `⊢ Q`. NB tactics operate on the first goal only.\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : P ∧ Q → P :=\nbegin\n  sorry\nend\n\nexample : P ∧ Q → Q :=\nbegin\n  sorry\nend\n\nexample : (P → Q → R) → (P ∧ Q → R) :=\nbegin\n  sorry\nend\n\nexample : P → Q → P ∧ Q :=\nbegin\n  sorry\nend\n\n/-- `∧` is symmetric -/\nexample : P ∧ Q → Q ∧ P :=\nbegin\n  sorry\nend\n\nexample : P → P ∧ true :=\nbegin\n  sorry\nend\n\nexample : false → P ∧ false :=\nbegin\n  sorry\nend\n\n/-- `∧` is transitive -/\nexample : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  sorry,\nend\n\nexample : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  sorry,\nend\n\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/2022/logic/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8652240947405565, "lm_q1q2_score": 0.7946912376738592}}
{"text": "/-\n- Data type -- inductive definition of a set of constructible terms\n- Abstract data type (ADT) -- data type plus set of basic operations on values of this type\n- Certified abstract data type (CADT) -- ADT with proofs of desired mathematical properties  \n\nIn this file, we see how to produce a CADT for Boolean algebra.\n-/\n\nnamespace hidden\n\n-- DATA TYPE\n\ninductive boo\n| ff \n| tt\n\nopen boo\n\n-- OPERATIONS\n\n-- unary operations\n\ndef id : boo → boo\n| b := b\n\ndef not : boo → boo\n| tt := ff\n| ff := tt\n\ndef fals : boo → boo\n| b := ff \n\ndef troo : boo → boo\n| b := tt \n\n-- binary operations\n\ndef and : boo → boo → boo\n| ff ff := ff\n| ff tt := ff\n| tt ff := ff\n| tt tt := tt\n\ndef or : boo → boo → boo\n| ff ff := ff\n| ff tt := tt\n| tt ff := tt\n| tt tt := tt\n\n-- a ternary operation\ndef ite : boo → boo → boo → boo\n|  ff t f := f\n|  tt t f := t\n\n-- PROOFS OF CRUCIAL PROPERTIES\n\n-- example \n\ntheorem demorgan1 : \n  ∀ (b1 b2 : boo), \n    not (and b1 b2) = or (not b1) (not b2) :=\n  begin\n    intros,\n    -- case analysis on b1\n    cases b1,\n    -- for each case for b1, case analysis on b2\n    repeat \n      { \n        cases b2,\n        exact rfl,\n        exact rfl\n      }\n  end\n\n/-\nAs we saw during the lecture, bugs in our \"code\"\nare revealed by an inability to prove that our\nimplementations of these operations have all the\nkey mathematical properties of the operations in\nthe Boolean algebra that we're trying to implement. \nTry slightly changing the definition of \"and\" or \n\"or\" for example, and see if, and if so how, the\nchanges break the proof(s).\n-/\n\n#reduce and tt ff\n\nnotation b1 * b2 := and b1 b2\nnotation b1 + b2 := or b1 b2\nprefix ! := not\n\n#reduce boo.tt * boo.ff\n#reduce boo.tt + boo.ff\n#reduce !(boo.tt + boo.ff)\n\nend hidden", "meta": {"author": "kevinsullivan", "repo": "cs6501s22", "sha": "c55d342145b127e7b7bf396c660966034e80a944", "save_path": "github-repos/lean/kevinsullivan-cs6501s22", "path": "github-repos/lean/kevinsullivan-cs6501s22/cs6501s22-c55d342145b127e7b7bf396c660966034e80a944/src/content/project_1/bool.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630935, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7946573417169459}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker, Alexey Soloyev, Junyan Xu\n-/\nimport data.real.irrational\nimport data.nat.fib\nimport data.nat.prime_norm_num\nimport data.fin.vec_notation\nimport tactic.ring_exp\nimport algebra.linear_recurrence\n\n/-!\n# The golden ratio and its conjugate\n\nThis file defines the golden ratio `φ := (1 + √5)/2` and its conjugate\n`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.\n\nAlong with various computational facts about them, we prove their\nirrationality, and we link them to the Fibonacci sequence by proving\nBinet's formula.\n-/\n\nnoncomputable theory\nopen_locale polynomial\n\n/-- The golden ratio `φ := (1 + √5)/2`. -/\n@[reducible] def golden_ratio := (1 + real.sqrt 5)/2\n\n/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/\n@[reducible] def golden_conj := (1 - real.sqrt 5)/2\n\nlocalized \"notation (name := golden_ratio) `φ` := golden_ratio\" in real\nlocalized \"notation (name := golden_conj) `ψ` := golden_conj\" in real\n\n/-- The inverse of the golden ratio is the opposite of its conjugate. -/\nlemma inv_gold : φ⁻¹ = -ψ :=\nbegin\n  have : 1 + real.sqrt 5 ≠ 0,\n    from ne_of_gt (add_pos (by norm_num) $ real.sqrt_pos.mpr (by norm_num)),\n  field_simp [sub_mul, mul_add],\n  norm_num\nend\n\n/-- The opposite of the golden ratio is the inverse of its conjugate. -/\nlemma inv_gold_conj : ψ⁻¹ = -φ :=\nbegin\n  rw [inv_eq_iff_eq_inv, ← neg_inv, ← neg_eq_iff_eq_neg],\n  exact inv_gold.symm,\nend\n\n@[simp] lemma gold_mul_gold_conj : φ * ψ = -1 :=\nby {field_simp, rw ← sq_sub_sq, norm_num}\n\n@[simp] lemma gold_conj_mul_gold : ψ * φ = -1 :=\nby {rw mul_comm, exact gold_mul_gold_conj}\n\n@[simp] lemma gold_add_gold_conj : φ + ψ = 1 := by {rw [golden_ratio, golden_conj], ring}\n\nlemma one_sub_gold_conj : 1 - φ = ψ := by linarith [gold_add_gold_conj]\n\nlemma one_sub_gold : 1 - ψ = φ := by linarith [gold_add_gold_conj]\n\n@[simp] lemma gold_sub_gold_conj : φ - ψ = real.sqrt 5 := by {rw [golden_ratio, golden_conj], ring}\n\n@[simp] lemma gold_sq : φ^2 = φ + 1 :=\nbegin\n  rw [golden_ratio, ←sub_eq_zero],\n  ring_exp,\n  rw real.sq_sqrt; norm_num,\nend\n\n@[simp] lemma gold_conj_sq : ψ^2 = ψ + 1 :=\nbegin\n  rw [golden_conj, ←sub_eq_zero],\n  ring_exp,\n  rw real.sq_sqrt; norm_num,\nend\n\nlemma gold_pos : 0 < φ :=\nmul_pos (by apply add_pos; norm_num) $ inv_pos.2 zero_lt_two\n\nlemma gold_ne_zero : φ ≠ 0 := ne_of_gt gold_pos\n\nlemma one_lt_gold : 1 < φ :=\nbegin\n  refine lt_of_mul_lt_mul_left _ (le_of_lt gold_pos),\n  simp [← sq, gold_pos, zero_lt_one]\nend\n\nlemma gold_conj_neg : ψ < 0 := by linarith [one_sub_gold_conj, one_lt_gold]\n\nlemma gold_conj_ne_zero : ψ ≠ 0 := ne_of_lt gold_conj_neg\n\nlemma neg_one_lt_gold_conj : -1 < ψ :=\nbegin\n  rw [neg_lt, ← inv_gold],\n  exact inv_lt_one one_lt_gold,\nend\n\n/-!\n## Irrationality\n-/\n\n/-- The golden ratio is irrational. -/\ntheorem gold_irrational : irrational φ :=\nbegin\n  have := nat.prime.irrational_sqrt (show nat.prime 5, by norm_num),\n  have := this.rat_add 1,\n  have := this.rat_mul (show (0.5 : ℚ) ≠ 0, by norm_num),\n  convert this,\n  field_simp\nend\n\n/-- The conjugate of the golden ratio is irrational. -/\ntheorem gold_conj_irrational : irrational ψ :=\nbegin\n  have := nat.prime.irrational_sqrt (show nat.prime 5, by norm_num),\n  have := this.rat_sub 1,\n  have := this.rat_mul (show (0.5 : ℚ) ≠ 0, by norm_num),\n  convert this,\n  field_simp\nend\n\n/-!\n## Links with Fibonacci sequence\n-/\n\nsection fibrec\n\nvariables {α : Type*} [comm_semiring α]\n\n/-- The recurrence relation satisfied by the Fibonacci sequence. -/\ndef fib_rec : linear_recurrence α :=\n{ order := 2,\n  coeffs := ![1, 1]}\n\nsection poly\n\nopen polynomial\n\n/-- The characteristic polynomial of `fib_rec` is `X² - (X + 1)`. -/\nlemma fib_rec_char_poly_eq {β : Type*} [comm_ring β] :\n  fib_rec.char_poly = X^2 - (X + (1 : β[X])) :=\nbegin\n  rw [fib_rec, linear_recurrence.char_poly],\n  simp [finset.sum_fin_eq_sum_range, finset.sum_range_succ', ← smul_X_eq_monomial]\nend\n\nend poly\n\n/-- As expected, the Fibonacci sequence is a solution of `fib_rec`. -/\nlemma fib_is_sol_fib_rec : fib_rec.is_solution (λ x, x.fib : ℕ → α) :=\nbegin\n  rw fib_rec,\n  intros n,\n  simp only,\n  rw [nat.fib_add_two, add_comm],\n  simp [finset.sum_fin_eq_sum_range, finset.sum_range_succ'],\nend\n\n/-- The geometric sequence `λ n, φ^n` is a solution of `fib_rec`. -/\nlemma geom_gold_is_sol_fib_rec : fib_rec.is_solution (pow φ) :=\nbegin\n  rw [fib_rec.geom_sol_iff_root_char_poly, fib_rec_char_poly_eq],\n  simp [sub_eq_zero]\nend\n\n/-- The geometric sequence `λ n, ψ^n` is a solution of `fib_rec`. -/\nlemma geom_gold_conj_is_sol_fib_rec : fib_rec.is_solution (pow ψ) :=\nbegin\n  rw [fib_rec.geom_sol_iff_root_char_poly, fib_rec_char_poly_eq],\n  simp [sub_eq_zero]\nend\n\nend fibrec\n\n/-- Binet's formula as a function equality. -/\ntheorem real.coe_fib_eq' : (λ n, nat.fib n : ℕ → ℝ) = λ n, (φ^n - ψ^n) / real.sqrt 5 :=\nbegin\n  rw fib_rec.sol_eq_of_eq_init,\n  { intros i hi,\n    fin_cases hi,\n    { simp },\n    { simp only [golden_ratio, golden_conj], ring_exp, rw mul_inv_cancel; norm_num } },\n  { exact fib_is_sol_fib_rec },\n  { ring_nf,\n    exact (@fib_rec ℝ _).sol_space.sub_mem\n            (submodule.smul_mem fib_rec.sol_space (real.sqrt 5)⁻¹ geom_gold_is_sol_fib_rec)\n            (submodule.smul_mem fib_rec.sol_space (real.sqrt 5)⁻¹ geom_gold_conj_is_sol_fib_rec) }\nend\n\n/-- Binet's formula as a dependent equality. -/\ntheorem real.coe_fib_eq : ∀ n, (nat.fib n : ℝ) = (φ^n - ψ^n) / real.sqrt 5 :=\nby rw [← function.funext_iff, real.coe_fib_eq']\n", "meta": {"author": "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/golden_ratio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7945797470045787}}
{"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.big_operators.basic\nimport ring_theory.polynomial.basic\n\n/-!\n# Lagrange interpolation\n\n## Main definitions\n\n* `lagrange.basis s x` where `s : finset F` and `x : F`: the Lagrange basis polynomial\n  that evaluates to `1` at `x` and `0` at other elements of `s`.\n* `lagrange.interpolate s f` where `s : finset F` and `f : F → F`: the Lagrange interpolant\n  that evaluates to `f x` at `x` for `x ∈ s`.\n-/\n\nnoncomputable theory\nopen_locale big_operators classical polynomial\n\nuniverse u\n\nnamespace lagrange\n\nvariables {F : Type u} [decidable_eq F] [field F] (s : finset F)\nvariables {F' : Type u} [field F'] (s' : finset F')\n\nopen polynomial\n\n/-- Lagrange basis polynomials that evaluate to 1 at `x` and 0 at other elements of `s`. -/\ndef basis (x : F) : F[X] :=\n∏ y in s.erase x, C (x - y)⁻¹ * (X - C y)\n\n@[simp] theorem basis_empty (x : F) : basis ∅ x = 1 :=\nrfl\n\n@[simp] theorem basis_singleton_self (x : F) : basis {x} x = 1 :=\nby rw [basis, finset.erase_singleton, finset.prod_empty]\n\n@[simp] theorem eval_basis_self (x : F) : (basis s x).eval x = 1 :=\nbegin\n  rw [basis, ← coe_eval_ring_hom, (eval_ring_hom x).map_prod, coe_eval_ring_hom,\n    finset.prod_eq_one],\n  intros y hy, simp_rw [eval_mul, eval_sub, eval_C, eval_X],\n  exact inv_mul_cancel (sub_ne_zero_of_ne (finset.ne_of_mem_erase hy).symm)\nend\n\n@[simp] theorem eval_basis_ne (x y : F) (h1 : y ∈ s) (h2 : y ≠ x) : (basis s x).eval y = 0 :=\nbegin\n  rw [basis,\n  ← coe_eval_ring_hom, (eval_ring_hom y).map_prod, coe_eval_ring_hom,\n    finset.prod_eq_zero (finset.mem_erase.2 ⟨h2, h1⟩)],\n  simp_rw [eval_mul, eval_sub, eval_C, eval_X, sub_self, mul_zero]\nend\n\ntheorem eval_basis (x y : F) (h : y ∈ s) : (basis s x).eval y = if y = x then 1 else 0 :=\nby { split_ifs with H, { subst H, apply eval_basis_self }, { exact eval_basis_ne s x y h H } }\n\n@[simp] theorem nat_degree_basis (x : F) (hx : x ∈ s) : (basis s x).nat_degree = s.card - 1 :=\nbegin\n  unfold basis, generalize hsx : s.erase x = sx,\n  have : x ∉ sx := hsx ▸ finset.not_mem_erase x s,\n  rw [← finset.insert_erase hx, hsx, finset.card_insert_of_not_mem this, add_tsub_cancel_right],\n  clear hx hsx s, revert this, apply sx.induction_on,\n  { intros hx, rw [finset.prod_empty, nat_degree_one], refl },\n  { intros y s hys ih hx, rw [finset.mem_insert, not_or_distrib] at hx,\n    have h1 : C (x - y)⁻¹ ≠ C 0 := λ h, hx.1 (eq_of_sub_eq_zero $ inv_eq_zero.1 $ C_inj.1 h),\n    have h2 : X ^ 1 - C y ≠ 0 := by convert X_pow_sub_C_ne_zero zero_lt_one y,\n    rw C_0 at h1, rw pow_one at h2,\n    rw [finset.prod_insert hys, nat_degree_mul (mul_ne_zero h1 h2), ih hx.2,\n        finset.card_insert_of_not_mem hys, nat_degree_mul h1 h2,\n        nat_degree_C, zero_add, nat_degree, degree_X_sub_C, add_comm], refl,\n    rw [ne, finset.prod_eq_zero_iff], rintro ⟨z, hzs, hz⟩,\n    rw mul_eq_zero at hz, cases hz with hz hz,\n    { rw [← C_0, C_inj, inv_eq_zero, sub_eq_zero] at hz, exact hx.2 (hz.symm ▸ hzs) },\n    { rw ← pow_one (X : F[X]) at hz, exact X_pow_sub_C_ne_zero zero_lt_one _ hz } }\nend\n\nvariables (f : F → F)\n\n/-- Lagrange interpolation: given a finset `s` and a function `f : F → F`,\n`interpolate s f` is the unique polynomial of degree `< s.card`\nthat takes value `f x` on all `x` in `s`. -/\ndef interpolate : F[X] :=\n∑ x in s, C (f x) * basis s x\n\n@[simp] theorem interpolate_empty (f) : interpolate (∅ : finset F) f = 0 :=\nrfl\n\n@[simp] theorem interpolate_singleton (f) (x : F) : interpolate {x} f = C (f x) :=\nby rw [interpolate, finset.sum_singleton, basis_singleton_self, mul_one]\n\n@[simp] theorem eval_interpolate (x) (H : x ∈ s) : eval x (interpolate s f) = f x :=\nbegin\n  rw [interpolate, ←coe_eval_ring_hom, ring_hom.map_sum, coe_eval_ring_hom, finset.sum_eq_single x],\n  { simp },\n  { intros y hy hxy, simp [eval_basis_ne s y x H hxy.symm] },\n  { intro h, exact (h H).elim }\nend\n\ntheorem degree_interpolate_lt : (interpolate s f).degree < s.card :=\nif H : s = ∅ then by { subst H, rw [interpolate_empty, degree_zero], exact with_bot.bot_lt_coe _ }\nelse (degree_sum_le _ _).trans_lt $ (finset.sup_lt_iff $ with_bot.bot_lt_coe s.card).2 $ λ b _,\ncalc  (C (f b) * basis s b).degree\n    ≤ (C (f b)).degree + (basis s b).degree : degree_mul_le _ _\n... ≤ 0 + (basis s b).degree : add_le_add_right degree_C_le _\n... = (basis s b).degree : zero_add _\n... ≤ (basis s b).nat_degree : degree_le_nat_degree\n... = (s.card - 1 : ℕ) : by { rwa nat_degree_basis }\n... < s.card : with_bot.coe_lt_coe.2 (nat.pred_lt $ mt finset.card_eq_zero.1 H)\n\ntheorem degree_interpolate_erase {x} (hx : x ∈ s) :\n  (interpolate (s.erase x) f).degree < (s.card - 1 : ℕ) :=\nbegin\n  convert degree_interpolate_lt (s.erase x) f,\n  rw finset.card_erase_of_mem hx,\nend\n\ntheorem interpolate_eq_of_eval_eq (f g : F → F) {s : finset F} (hs : ∀ x ∈ s, f x = g x) :\n  interpolate s f = interpolate s g :=\nbegin\n  rw [interpolate, interpolate],\n  refine finset.sum_congr rfl (λ x hx, _),\n  rw hs x hx,\nend\n\n/-- Linear version of `interpolate`. -/\ndef linterpolate : (F → F) →ₗ[F] polynomial F :=\n{ to_fun := interpolate s,\n  map_add' := λ f g, by { simp_rw [interpolate, ← finset.sum_add_distrib, ← add_mul, ← C_add],\n    refl },\n  map_smul' := λ c f, by { simp_rw [interpolate, finset.smul_sum, C_mul', smul_smul], refl } }\n\n@[simp] lemma interpolate_add (f g) : interpolate s (f + g) = interpolate s f + interpolate s g :=\n(linterpolate s).map_add f g\n\n@[simp] lemma interpolate_zero : interpolate s 0 = 0 :=\n(linterpolate s).map_zero\n\n@[simp] lemma interpolate_neg (f) : interpolate s (-f) = -interpolate s f :=\n(linterpolate s).map_neg f\n\n@[simp] lemma interpolate_sub (f g) : interpolate s (f - g) = interpolate s f - interpolate s g :=\n(linterpolate s).map_sub f g\n\n@[simp] lemma interpolate_smul (c : F) (f) : interpolate s (c • f) = c • interpolate s f :=\n(linterpolate s).map_smul c f\n\ntheorem eq_zero_of_eval_eq_zero {f : F'[X]} (hf1 : f.degree < s'.card)\n  (hf2 : ∀ x ∈ s', f.eval x = 0) : f = 0 :=\nby_contradiction $ λ hf3, not_le_of_lt hf1 $\ncalc  (s'.card : with_bot ℕ)\n    ≤ f.roots.to_finset.card : with_bot.coe_le_coe.2 $ finset.card_le_of_subset $ λ x hx,\n        (multiset.mem_to_finset).mpr $ (mem_roots hf3).2 $ hf2 x hx\n... ≤ f.roots.card : with_bot.coe_le_coe.2 $ f.roots.to_finset_card_le\n... ≤ f.degree : card_roots hf3\n\ntheorem eq_of_eval_eq {f g : F'[X]} (hf : f.degree < s'.card) (hg : g.degree < s'.card)\n  (hfg : ∀ x ∈ s', f.eval x = g.eval x) : f = g :=\neq_of_sub_eq_zero $ eq_zero_of_eval_eq_zero s'\n  (lt_of_le_of_lt (degree_sub_le f g) $ max_lt hf hg)\n  (λ x hx, by rw [eval_sub, hfg x hx, sub_self])\n\ntheorem eq_interpolate_of_eval_eq {g : F[X]} (hg : g.degree < s.card)\n  (hgf : ∀ x ∈ s, g.eval x = f x) : interpolate s f = g :=\neq_of_eval_eq s (degree_interpolate_lt _ _) hg $ λ x hx, begin\n  rw hgf x hx,\n  exact eval_interpolate _ _ _ hx,\nend\n\ntheorem eq_interpolate (f : F[X]) (hf : f.degree < s.card) :\n  interpolate s (λ x, f.eval x) = f :=\neq_of_eval_eq s (degree_interpolate_lt s _) hf $ λ x hx, eval_interpolate s _ x hx\n\n/-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials\nof degree less than `s.card`. -/\ndef fun_equiv_degree_lt : degree_lt F s.card ≃ₗ[F] (s → F) :=\n{ to_fun := λ f x, f.1.eval x,\n  map_add' := λ f g, funext $ λ x, eval_add,\n  map_smul' := λ c f, funext $ by simp,\n  inv_fun := λ f, ⟨interpolate s (λ x, if hx : x ∈ s then f ⟨x, hx⟩ else 0),\n    mem_degree_lt.2 $ degree_interpolate_lt _ _⟩,\n  left_inv := λ f, begin apply subtype.eq,\n    simp only [subtype.coe_mk, subtype.val_eq_coe, dite_eq_ite],\n    convert eq_interpolate s f (mem_degree_lt.1 f.2) using 1,\n    rw interpolate_eq_of_eval_eq,\n    intros x hx,\n    rw if_pos hx end,\n  right_inv := λ f, funext $ λ ⟨x, hx⟩, begin\n    convert eval_interpolate s _ x hx,\n    simp_rw dif_pos hx end }\n\ntheorem interpolate_eq_interpolate_erase_add {x y : F} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) :\n  interpolate s f =\n  C (y - x)⁻¹ * ((X - C x) * interpolate (s.erase x) f + (C y - X) * interpolate (s.erase y) f) :=\nbegin\n  refine eq_interpolate_of_eval_eq _ _ _ (λ z hz, _),\n  { rw [degree_mul, degree_C (inv_ne_zero (sub_ne_zero.2 hxy.symm)), zero_add],\n    refine lt_of_le_of_lt (degree_add_le _ _) (max_lt _ _),\n    { rw [degree_mul, degree_X_sub_C],\n      convert (with_bot.add_lt_add_iff_left (with_bot.coe_ne_bot _)).2\n        (degree_interpolate_erase s f hx),\n      simp [nat.one_add, nat.sub_one, nat.succ_pred_eq_of_pos (finset.card_pos.2 ⟨x, hx⟩)] },\n    { rw [degree_mul, ←neg_sub, degree_neg, degree_X_sub_C],\n      convert (with_bot.add_lt_add_iff_left (with_bot.coe_ne_bot _)).2\n        (degree_interpolate_erase s f hy),\n      simp [nat.one_add, nat.sub_one, nat.succ_pred_eq_of_pos (finset.card_pos.2 ⟨y, hy⟩)] } },\n  { by_cases hzx : z = x,\n    { simp [hzx, eval_interpolate (s.erase y) f x (finset.mem_erase_of_ne_of_mem hxy hx),\n            inv_mul_eq_iff_eq_mul₀ (sub_ne_zero_of_ne hxy.symm)] },\n    { by_cases hzy : z = y,\n      { simp [hzy, eval_interpolate (s.erase x) f y (finset.mem_erase_of_ne_of_mem hxy.symm hy),\n              inv_mul_eq_iff_eq_mul₀ (sub_ne_zero_of_ne hxy.symm)] },\n      { simp only [eval_interpolate (s.erase x) f z (finset.mem_erase_of_ne_of_mem hzx hz),\n                   eval_interpolate (s.erase y) f z (finset.mem_erase_of_ne_of_mem hzy hz),\n                   inv_mul_eq_iff_eq_mul₀ (sub_ne_zero_of_ne hxy.symm), eval_mul, eval_C, eval_add,\n                   eval_sub, eval_X],\n        ring } } }\nend\n\nend lagrange\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/lagrange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7945797316781974}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro h,\n  by_contra hp,\n  apply hp,\n  exact h,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro h,\n  by_contra hp,\n  apply h,\n  exact hp,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  intro h,\n  by_contra hp,\n  apply h,\n  exact hp,\n  \n  intro h1,\n  by_contra hp1,\n  apply hp1,\n  exact h1,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hPvQ,\n  cases hPvQ with hP hQ,\n  right,\n  assumption,\n  left,\n  assumption,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro hPeQ,\n  cases hPeQ with hP hQ,\n  split,\n  exact hQ,\n  exact hP,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro hPorQ,\n  intro hp,\n  cases hPorQ with hP hQ,\n  exfalso,\n  contradiction,\n  exact hQ,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro hPorQ,\n  intro hp,\n  cases hPorQ with hP hQ,\n  exfalso,\n  contradiction,\n  exact hQ,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros hpq hnq hp,\n  apply hnq,\n  apply hpq,\n  apply hp,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros h hp,\n  change (Q → false) → (P → false) at h,\n  by_contra hnq,\n  apply h,\n  exact hnq,\n  exact hp,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  intros hpq hnq hp,\n  apply hnq,\n  apply hpq,\n  apply hp,\n\n  intros h hp,\n  change (Q → false) → (P → false) at h,\n  by_contra hnq,\n  apply h,\n  exact hnq,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro hp,\n  apply hp,\n  right,\n  intro p,\n  have PorP : P ∨ ¬P,\n  left,\n  exact p,\n  apply hp,\n  exact PorP,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros h1 h2,\n  apply h2,\n  apply h1,\n  intro p,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro PorQ,\n  intro nPenQ,\n  cases nPenQ with nPnQ,\n  cases PorQ,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro PeQ,\n  intro nPonQ,\n  cases PeQ with PeQ,\n  cases nPonQ,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro PorQ,\n  split,\n  intro hp,\n  have PorQ : P ∨ Q,\n  left,\n  exact hp,\n  contradiction,\n  intro hq,\n  have PorQ : P ∨ Q,\n  right,\n  exact hq,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros nPenQ PorQ,\n  cases nPenQ with nP nQ,\n  cases PorQ,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro PeQ,\n  by_contra nQornP,\n  apply PeQ,\n  split,\n  by_contra nP,\n  apply nQornP,\n  right,\n  exact nP,\n  by_contra nQ,\n  apply nQornP,\n  left,\n  exact nQ,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro nQornP,\n  intro PeQ,\n  cases PeQ with hP hQ,\n  cases nQornP,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  intro PeQ,\n  by_contra nQornP,\n  apply PeQ,\n  split,\n  by_contra nP,\n  apply nQornP,\n  right,\n  exact nP,\n  by_contra nQ,\n  apply nQornP,\n  left,\n  exact nQ,\n\n  intro nQornP,\n  intro PeQ,\n  cases PeQ with hP hQ,\n  cases nQornP,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  intro PorQ,\n  split,\n  intro hp,\n  have PorQ : P ∨ Q,\n  left,\n  exact hp,\n  contradiction,\n  intro hq,\n  have PorQ : P ∨ Q,\n  right,\n  exact hq,\n  contradiction,\n\n  intros nPenQ PorQ,\n  cases nPenQ with nP nQ,\n  cases PorQ,\n  contradiction,\n  contradiction,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  sorry\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  sorry,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  sorry,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros PeQR hp hq,\n  apply PeQR,\n  split,\n  exact hp,\n  exact hq,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros pqr PeQ,\n  apply pqr,\n  cases PeQ with hp hq,\n  exact hp,\n  cases PeQ with hp hq,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hp,\n  exact hp,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hp,\n  left,\n  exact hp,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hq,\n  right,\n  exact hq,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro PeQ,\n  cases PeQ with hp hq,\n  exact hp,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro PeQ,\n  cases PeQ with hp hq,\n  exact hq,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro PeP,\n  cases PeP with hp,\n  exact hp,\n  intro hp1,\n  split,\n  exact hp1,\n  exact hp1,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro PorP,\n  cases PorP with hp1 hp2,\n  exact hp1,\n  exact hp2,\n  intro hp,\n  left,\n  exact hp,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  sorry,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "MarceloJoseVieira", "repo": "fmclean", "sha": "472617264b0cfb9e0a30001636d4bf2745469214", "save_path": "github-repos/lean/MarceloJoseVieira-fmclean", "path": "github-repos/lean/MarceloJoseVieira-fmclean/fmclean-472617264b0cfb9e0a30001636d4bf2745469214/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7945301585973095}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=   \n  Iff.intro\n    (fun h : p ∧ q => show q ∧ p from And.intro (And.right h) (And.left h))\n    (fun h : q ∧ p => show p ∧ q from And.intro (And.right h) (And.left h))\n\nexample : p ∨ q ↔ q ∨ p := \n  Iff.intro\n    (fun h : p ∨ q => show q ∨ p from \n      Or.elim h\n        (fun hp : p =>\n          show q ∨ p from Or.intro_right q hp)\n        (fun hq : q =>\n          show q ∨ p from Or.intro_left p hq))\n    (fun h : q ∨ p => show p ∨ q from \n      Or.elim h\n        (fun hq : q =>\n          show p ∨ q from Or.intro_right p hq)\n        (fun hp : p =>\n          show p ∨ q from Or.intro_left q hp))\n\n-- -- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := \n  Iff.intro\n    (fun h: (p ∧ q) ∧ r => show p ∧ (q ∧ r) from\n        have hpq : (p ∧ q) := h.left\n        have hr : r := h.right\n        And.intro (And.left hpq) (And.intro (And.right hpq) hr))\n    (fun h: p ∧ (q ∧ r) => show (p ∧ q) ∧ r from\n        have hp : p := h.left\n        have hqr : (q ∧ r) := h.right\n        And.intro (And.intro hp (And.left hqr)) hqr.right)\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := \n  Iff.intro\n    (fun h : (p ∨ q) ∨ r => show p ∨ (q ∨ r) from\n      h.elim \n      (fun hpq => show p ∨ (q ∨ r) from \n        hpq.elim\n        (fun hp : p => Or.inl hp)\n        (fun hq : q => Or.intro_right p (Or.intro_left r hq)))\n      (fun hr: r => Or.intro_right p (Or.intro_right q hr)))\n    (fun h: p ∨ (q ∨ r) => show (p ∨ q) ∨ r from\n      h.elim\n      (fun hp: p => Or.intro_left r (Or.intro_left q hp))\n      (fun hqr : q ∨ r => \n        hqr.elim\n        (fun hq => Or.intro_left r (Or.intro_right p hq))\n        (fun hr => Or.inr hr)))\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := \n  Iff.intro\n    (fun h : p ∧ (q ∨ r) => show (p ∧ q) ∨ (p ∧ r) from\n      have hp : p := h.left\n      Or.elim (h.right)\n      (fun hq : q => Or.inl ⟨hp, hq⟩) -- p ∧ q\n      (fun hr : r => Or.inr ⟨hp, hr⟩)) -- p ∧ r e Lean add ∨ \n    (fun h : (p ∧ q) ∨ (p ∧ r) => show p ∧ (q ∨ r) from\n      Or.elim h\n      (fun hpq => \n        have hp := hpq.left\n        have hq := hpq.right\n        ⟨hp, Or.inl hq⟩)\n      (fun hpr => \n        have hp := hpr.left\n        have hr := hpr.right\n        ⟨hp, Or.inr hr⟩))\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := \n  Iff.intro\n    (fun h: p ∨ (q ∧ r) => show (p ∨ q) ∧ (p ∨ r) from \n      h.elim\n      (fun hp : p => And.intro (Or.intro_left q hp) (Or.intro_left r hp))\n      (fun hqr => \n        have hq : q := hqr.left\n        have hr : r := hqr.right\n        ⟨Or.inr hq, Or.inr hr⟩))\n    (fun h: (p ∨ q) ∧ (p ∨ r) => show p ∨ (q ∧ r) from \n      have hpq := h.left \n      have hpr := h.right\n      hpq.elim\n      (fun hp => Or.inl hp)\n      (fun hq => \n        hpr.elim\n        (fun hp => Or.inl hp)\n        (fun hr => Or.inr (And.intro hq hr))))\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := \n  Iff.intro\n  (fun h : p → (q → r) => show p ∧ q → r from (fun hpq => (h hpq.left) hpq.right))\n  (fun h : p ∧ q → r => show p → (q → r) from (fun hp => fun hq => h (And.intro hp hq)))\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \n  Iff.intro\n  (fun h : (p ∨ q) → r => show (p → r) ∧ (q → r) from \n    And.intro (fun hp => h (Or.inl hp)) (fun hq => h (Or.inr hq)))\n  (fun h : (p → r) ∧ (q → r) => show (p ∨ q) → r from \n    (fun hpq => hpq.elim\n      (fun hp => h.left hp)\n      (fun hq => h.right hq)))\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \n  Iff.intro\n  (fun h : ¬(p ∨ q) => show ¬p ∧ ¬q from \n    And.intro (fun hp => h (Or.inl hp)) (fun hq => h (Or.inr hq)))\n  (fun h : ¬p ∧ ¬q => show ¬(p ∨ q) from \n  (fun hpq => hpq.elim \n    (fun hp => h.left hp)\n    (fun hq => h.right hq)))\n\n-- example : ¬p ∨ ¬q → ¬(p ∧ q) := sorry\nexample (h : ¬p ∨ ¬q) : ¬(p ∧ q) := \n  h.elim\n  (fun hnp => show ¬(p ∧ q) from (fun hp => hnp hp.left))\n  (fun hnq => show ¬(p ∧ q) from (fun hq => hnq hq.right))\n\nexample : ¬(p ∧ ¬p) := fun hp => absurd hp.left hp.right\n\n-- example : p ∧ ¬q → ¬(p → q) := sorry\nexample (h : p ∧ ¬q) : ¬(p → q) := fun hp => absurd (hp h.left) h.right\n\n-- example : ¬p → (p → q) := sorry\nexample (hnp : ¬p) : (p → q) := fun hp => False.elim (hnp hp)\n\n-- example : (¬p ∨ q) → (p → q) := sorry\nexample (h : ¬p ∨ q) : (p → q) := \n  fun hp : p => \n    h.elim\n    (fun hnp => show q from False.elim (hnp hp))\n    (fun hq => hq)\n\nexample : p ∨ False ↔ p := \n  Iff.intro\n    (fun hpf : p ∨ False => show p from \n      hpf.elim\n      (fun hp => hp)\n      (fun hf => False.elim hf))\n    (fun hp : p => show p ∨ False from Or.intro_left False hp)\n\nexample : p ∧ False ↔ False := \n  Iff.intro\n    (fun h : p ∧ False => show False from h.right)\n    (fun h : False => show p ∧ False from False.elim h)\n\nexample (h : p → q) : (¬q → ¬p) := fun hnq => fun hp => hnq (h hp)\n\nopen Classical\n\nexample (h : p → q ∨ r) : (p → q) ∨ (p → r) := Or.elim (em p)\n  (fun hp => (Or.elim (h hp) \n    (fun hq => Or.inl (fun _ => hq))\n    (fun hr => Or.inr (fun _ => hr))))\n  (fun hnp => Or.inl (fun hp => False.elim (hnp hp)))\n\nexample (h : ¬(p ∧ q)) : ¬p ∨ ¬q := \n  Or.elim (em p)\n    (fun hp => Or.inr (fun hq => h (And.intro hp hq)))\n    (fun hnp => Or.inl hnp)\n\nexample : ¬(p → q) → p ∧ ¬q := fun h => Or.elim (em p)\n  (fun hp => And.intro hp (fun hq => absurd (fun _ => hq) h))\n  (fun hnp => And.intro \n    (False.elim (h (fun hp => False.elim (absurd hp hnp)))) \n    (fun hq => absurd (fun _ => hq) h))\n\nexample (h : p → q) : ¬p ∨ q := Or.elim (em p) \n  (fun hp => Or.inr (h hp))\n  (fun hnp => Or.inl hnp)\n\nexample (h : ¬q → ¬p) : (p → q) := fun hp => Or.elim (em q)\n  (fun hq => hq)\n  (fun hnq => False.elim ((h hnq) hp))\n\nexample : p ∨ ¬p := em p\n\nexample (_ : p → q) (hp: p) : p := byContradiction (fun hnp => hnp hp)\n\nexample : ((p → q) → p) → p := fun h => Or.elim (em p)\n    (fun hp => hp)\n    (fun hnp => absurd (h (fun hp => byContradiction (fun _ => hnp hp))) hnp)\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/theorem_proving/exercises_chapter_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7944512207657805}}
{"text": "/- LoVe Homework 8: Operational Semantics -/\n\nimport .lovelib\n\nnamespace LoVe\n\n\n/- Question 1: Semantics of Regular Expressions\n\nRegular expression are a very popular tool for software development. Often, when\ntextual input needs to be analyzed it is matched against a regular expression.\nIn this homework, we define the syntax of regular expressions and what it means\nthat a regular expression matches a string.\n\nWe define `regex` to represent the following grammar:\n\n    R ::= c       — `char`: accepts one character `c`\n        | ∅       — `nothing`: accepts nothing\n        | ε       — `empty`: accepts the empty string\n        | R ⬝ R    — `concat`: accepts the concatenation of two regexes\n        | R + R   — `alt`: accepts either of two regexes\n        | R*      — `star`: accept arbitrary many repetitions of a regex\n\nNotice the rough correspondence with a WHILE language:\n\n  `char`   ~ assignment\n  `empty`  ~ `skip`\n  `concat` ~ sequential composition\n  `alt`    ~ conditional statement\n  `star`   ~ while loop -/\n\ninductive regex : Type\n| char    : char → regex\n| nothing : regex\n| empty   : regex\n| concat  : regex → regex → regex\n| alt     : regex → regex → regex\n| star    : regex → regex\n\n/- The `accept r s` predicate indicates that the regular expression `r` accepts\nthe string `s`. -/\n\ninductive accept : regex → list char → 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₁ r₂ : regex} (s₁ s₂ : list char) (h₁ : accept r₁ s₁)\n    (h₂ : accept r₂ s₂) :\n  accept (regex.concat r₁ r₂) (s₁ ++ s₂)\n/- accept the left alternative -/\n| alt_left {r₁ r₂ : regex} (s : list char) (h : accept r₁ s) :\n  accept (regex.alt r₁ r₂) s\n/- accept the right alternative -/\n| alt_right {r₁ r₂ : regex} (s : list char) (h : accept r₂ s) :\n  accept (regex.alt r₁ r₂) 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₁ : accept r s)\n    (h₂ : 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-- enter your answer here\n\n/- 1.2. Prove the following inversion rules.\n\nThese proofs are very similar to the inversion rules in the lecture and the\nexercise. -/\n\n@[simp] lemma accept_char {s : list char} {c : char} :\n  accept (regex.char c) s ↔ s = [c] :=\nsorry\n\n@[simp] lemma accept_nothing {s : list char} :\n  ¬ accept regex.nothing s :=\nsorry\n\n@[simp] lemma accept_empty {s : list char} :\n  accept regex.empty s ↔ s = [] :=\nsorry\n\n@[simp] lemma accept_concat {s : list char} {r₁ r₂  : regex} :\n  accept (regex.concat r₁ r₂) s\n  ↔ (∃s₁ s₂, accept r₁ s₁ ∧ accept r₂ s₂ ∧ s = s₁ ++ s₂) :=\nsorry\n\n@[simp] lemma accept_alt {s : list char} {r₁ r₂  : regex} :\n  accept (regex.alt r₁ r₂) s ↔ (accept r₁ s ∨ accept r₂ s) :=\nsorry\n\nlemma accept_star {s : list char} {r : regex} :\n  accept (regex.star r) s ↔\n  (s = [] ∨ (∃s₁ s₂, accept r s₁ ∧ accept (regex.star r) s₂ ∧ s = s₁ ++ s₂)) :=\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/love08_operational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7944512159164961}}
{"text": "-- La función identidad es menor o igual que la función de extracción\n-- ==================================================================\n\nimport data.real.basic\nopen nat\n\nvariable {φ : ℕ → ℕ}\n\nset_option pp.structure_projections false\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Para extraer una subsucesión se aplica una\n-- función de extracción que conserva el orden; por\n-- ejemplo, la subsucesión\n--    uₒ, u₂, u₄, u₆, ...\n-- se ha obtenido con la función de extracción φ tal\n-- que φ(n) = 2*n.\n--\n-- Definir la función\n--    extraccion : (ℕ → ℕ) → Prop\n-- tal que (extraccion φ) expresa que φ es una función\n-- de extracción\n-- ----------------------------------------------------\n\ndef extraccion : (ℕ → ℕ) → Prop\n| φ := ∀ n m, n < m → φ n < φ m\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que si φ es una función de\n-- extracción, entonces\n--    ∀ n, n ≤ φ n\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  extraccion φ → ∀ n, n ≤ φ n :=\nbegin\n  intros h n,\n  induction n with m HI,\n  { exact nat.zero_le (φ 0), },\n  { apply nat.succ_le_of_lt,\n    have h1 : m < succ m,\n      from lt_add_one m,\n    calc m ≤ φ m        : HI\n       ... < φ (succ m) : h m (succ m) h1, },\nend\n\n-- 2ª demostración\nexample :\n  extraccion φ → ∀ n, n ≤ φ n :=\nbegin\n  intros h n,\n  induction n with m HI,\n  { exact nat.zero_le _ },\n  { apply nat.succ_le_of_lt,\n    calc m ≤ φ m        : HI\n       ... < φ (succ m) : by linarith [h m (m+1) (by linarith)] },\nend\n\n-- 3ª demostración\nexample :\n  extraccion φ → ∀ n, n ≤ φ n :=\nbegin\n  intros h n,\n  induction n with m HI,\n  { linarith },\n  { apply nat.succ_le_of_lt,\n    linarith [h m (m+1) (by linarith)] },\nend\n\n-- 4ª demostración\nexample :\n  extraccion φ → ∀ n, n ≤ φ n :=\nbegin\n  intros h 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\n-- 5ª demostración\nexample :\n  extraccion φ → ∀ n, n ≤ φ n :=\nassume h : extraccion φ,\nassume n,\nnat.rec_on n\n  ( show 0 ≤ φ 0,\n      from nat.zero_le (φ 0) )\n  ( assume m,\n    assume HI : m ≤ φ m,\n    have h1 : m < succ m,\n      from lt_add_one m,\n    have h2 : m < φ (succ m), from\n      calc m ≤ φ m        : HI\n         ... < φ (succ m) : h m (succ m) h1,\n    show succ m ≤ φ (succ m),\n      from nat.succ_le_of_lt h2)\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/id_mne_extraccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.7944090991879708}}
{"text": "/-\n  Results about matrices, PSD, etc.\n-/\nimport data.real.basic\nimport data.matrix.basic\nimport linear_algebra.matrix\nimport linear_algebra.eigenspace\nimport to_mathlib.matrix\n\nvariables {γ : Type*} [fintype γ] [decidable_eq γ]\nvariables {μ : Type*} [fintype μ] [decidable_eq μ]\nvariables {R : Type*} \n\nopen_locale big_operators\nopen_locale matrix\n\nopen matrix module.End\n\n-- Positive semidefiniteness.\n\nvariable [linear_ordered_comm_ring R]\n\ndef pos_semidef (M : matrix γ γ R)  : Prop :=\n∀ (v : γ → R), 0 ≤ dot_product v (M.mul_vec v)\n\ntheorem pos_semidef_sum \n  {A B : matrix γ γ R}\n  (hApsd : pos_semidef A) (hBpsd : pos_semidef B)\n: pos_semidef (A + B) :=\nbegin\n  intros v, rw [matrix.add_mul_vec, dot_product_add],\n  exact add_nonneg (hApsd v) (hBpsd v),\nend \n\ntheorem pos_semidef_nonneg_diagonal {D : γ → R} (hD : 0 ≤ D) \n: pos_semidef (diagonal D) :=\nbegin \n  intros v, rw dot_product_comm, rw dot_product_diagonal_mul_vec_eq,\n  exact dot_product_of_nonneg hD (vec_mul_self_nonneg v),\nend \n\n-- Cholesky.\n\ndef cholesky_decomposition (M : matrix γ γ R) (h : symmetric M) : Prop :=\n∃ L : matrix μ γ R, M = Lᵀ ⬝ L\n\ntheorem pos_semidef_of_cholesky_decomposition (M : matrix γ γ R) (h : symmetric M) \n: @cholesky_decomposition γ _ _ μ _ _ R _ M h → pos_semidef M :=\nbegin \n  rintros ⟨L, hL⟩ v, rw hL, rw [dot_product_transpose],\n  exact dot_product_self_nonneg _,\nend \n\n-- LDLT.\n\n-- TODO: This is technically LTDL...\ndef LDLT_decomposition (M : matrix γ γ R) (h : symmetric M) : Prop :=\n∃ (L : matrix γ γ R) (D : γ → R), M = Lᵀ ⬝ (diagonal D) ⬝ L ∧ 0 ≤ D \n\ntheorem pos_semidef_of_LDLT_decomposition (M : matrix γ γ R) (h : symmetric M) \n: LDLT_decomposition M h → pos_semidef M :=\nbegin\n  rintros ⟨L, D, hLDLT, hD⟩ v, \n  rw [hLDLT, matrix.mul_assoc, dot_product_transpose], \n  rw [←mul_vec_mul_vec, dot_product_comm, dot_product_diagonal_mul_vec_eq],\n  exact (dot_product_of_nonneg hD (vec_mul_self_nonneg _)),\nend\n\n-- Nonnegative eigenvalues.\n\ndef nonneg_eigenvalues (M : matrix γ γ R) (h : symmetric M) : Prop :=\n∀ r, has_eigenvalue (mul_vec_lin M) r → r ≥ 0\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/lib/psd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750453562491, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7943875473115055}}
{"text": "/-\nIf P and Q are arbitrary propositions, then to prove \nP ∨ Q, you need to prove either P or Q and then use\none of the or introduction rules to form a proof of\nthe disjunction. \n-/\n\n-- Suppose P and Q are arbitrary propositions\naxioms (P Q : Prop)\n\n-- Suppose you have proofs of P and of Q\naxioms (p : P) (q : Q)\n\n-- You can now construct proofs of P ∨ Q\n\n#check or.intro_left Q p\n#check or.intro_right P q\n\n/-\nIf the type of the disjunction for which a\nproof is not provided can be inferred then\nthe shorthand form of these rules can be\nused.\n-/\n\nexample : P ∨ Q := or.inl p\nexample : P ∨ Q := or.inr q\n\n/-\nThe elimination rule for using a proof of\na disjunction requires a case analysis. If\nyou have a proof of P ∨ Q, and you can show\nthat P → R and Q → R, then you've shown that\nR is true *in either case* (whether P ∨ Q is\ntrue because P is or because Q is).\n-/\n\naxioms Raining Sprinkler StreetsWet: Prop\naxiom rw : Raining → StreetsWet\n\nexample : (Raining ∨ Sprinkler) → \n          (Raining → StreetsWet) → \n          (Sprinkler → StreetsWet) → \n          StreetsWet :=\nλ (rors : Raining ∨ Sprinkler), -- if you assume R ∨ S\nλ (rw : Raining → StreetsWet),   -- and you can prove R→W\nλ (sw : Sprinkler → StreetsWet), -- and also S→W\n   match rors with  -- then you can prove W \"by case analysis\"\n    | or.inl r := rw r  -- if it's raining the streets are wet\n    | or.inr s := sw s  -- if the sprinker's on, they're wet\n   end                  -- so they're wet in either case QED.", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/predicate_logic/intro_and_elim_rules/or.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.8705972667296309, "lm_q1q2_score": 0.794364429449482}}
{"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, Leonardo de Moura, Jeremy Avigad\n\nBasic operations on the natural numbers.\n-/\nimport ..num algebra.ring\nopen binary eq.ops\n\nnamespace nat\n\n/- a variant of add, defined by recursion on the first argument -/\n\ndefinition addl (x y : ℕ) : ℕ :=\nnat.rec y (λ n r, succ r) x\ninfix ` ⊕ `:65 := addl\n\ntheorem addl_succ_right (n m : ℕ) : n ⊕ succ m = succ (n ⊕ m) :=\nnat.induction_on n\n  rfl\n  (λ n₁ ih, calc\n    succ n₁ ⊕ succ m = succ (n₁ ⊕ succ m)   : rfl\n             ...     = succ (succ (n₁ ⊕ m)) : ih\n             ...     = succ (succ n₁ ⊕ m)   : rfl)\n\ntheorem add_eq_addl (x : ℕ) : ∀y, x + y = x ⊕ y :=\nnat.induction_on x\n  (λ y, nat.induction_on y\n    rfl\n    (λ y₁ ih, calc\n      0 + succ y₁ = succ (0 + y₁)  : rfl\n           ...    = succ (0 ⊕ y₁) : {ih}\n           ...    = 0 ⊕ (succ y₁) : rfl))\n  (λ x₁ ih₁ y, nat.induction_on y\n    (calc\n      succ x₁ + 0  = succ (x₁ + 0)  : rfl\n               ... = succ (x₁ ⊕ 0) : {ih₁ 0}\n               ... = succ x₁ ⊕ 0   : rfl)\n    (λ y₁ ih₂, calc\n      succ x₁ + succ y₁ = succ (succ x₁ + y₁) : rfl\n                   ...  = succ (succ x₁ ⊕ y₁) : {ih₂}\n                   ...  = succ x₁ ⊕ succ y₁   : addl_succ_right))\n\n/- successor and predecessor -/\n\ntheorem succ_ne_zero [simp] (n : ℕ) : succ n ≠ 0 :=\nby contradiction\n\ntheorem add_one_ne_zero [simp] (n : ℕ) : n + 1 ≠ 0 :=\nby contradiction\n\n-- add_rewrite succ_ne_zero\n\ntheorem pred_zero [simp] : pred 0 = 0 :=\nrfl\n\ntheorem pred_succ [simp] (n : ℕ) : pred (succ n) = n :=\nrfl\n\ntheorem eq_zero_or_eq_succ_pred (n : ℕ) : n = 0 ∨ n = succ (pred n) :=\nnat.induction_on n\n  (or.inl rfl)\n  (take m IH, or.inr\n    (show succ m = succ (pred (succ m)), from congr_arg succ !pred_succ⁻¹))\n\ntheorem exists_eq_succ_of_ne_zero {n : ℕ} (H : n ≠ 0) : ∃k : ℕ, n = succ k :=\nexists.intro _ (or_resolve_right !eq_zero_or_eq_succ_pred H)\n\ntheorem succ.inj {n m : ℕ} (H : succ n = succ m) : n = m :=\nnat.no_confusion H imp.id\n\nabbreviation eq_of_succ_eq_succ := @succ.inj\n\ntheorem succ_ne_self {n : ℕ} : succ n ≠ n :=\nnat.induction_on n\n  (take H : 1 = 0,\n    have ne : 1 ≠ 0, from !succ_ne_zero,\n    absurd H ne)\n  (take k IH H, IH (succ.inj H))\n\ntheorem discriminate {B : Prop} {n : ℕ} (H1: n = 0 → B) (H2 : ∀m, n = succ m → B) : B :=\nhave H : n = n → B, from nat.cases_on n H1 H2,\nH rfl\n\ntheorem two_step_induction_on {P : ℕ → Prop} (a : ℕ) (H1 : P 0) (H2 : P 1)\n    (H3 : ∀ (n : ℕ) (IH1 : P n) (IH2 : P (succ n)), P (succ (succ n))) : P a :=\nhave stronger : P a ∧ P (succ a), from\n  nat.induction_on a\n    (and.intro H1 H2)\n    (take k IH,\n      have IH1 : P k, from and.elim_left IH,\n      have IH2 : P (succ k), from and.elim_right IH,\n        and.intro IH2 (H3 k IH1 IH2)),\n  and.elim_left stronger\n\ntheorem sub_induction {P : ℕ → ℕ → Prop} (n m : ℕ) (H1 : ∀m, P 0 m)\n   (H2 : ∀n, P (succ n) 0) (H3 : ∀n m, P n m → P (succ n) (succ m)) : P n m :=\nhave general : ∀m, P n m, from nat.induction_on n H1\n  (take k : ℕ,\n    assume IH : ∀m, P k m,\n    take m : ℕ,\n    nat.cases_on m (H2 k) (take l, (H3 k l (IH l)))),\ngeneral m\n\n/- addition -/\n\nprotected theorem add_zero (n : ℕ) : n + 0 = n :=\nrfl\n\ntheorem add_succ (n m : ℕ) : n + succ m = succ (n + m) :=\nrfl\n\n/-\nRemark: we use 'local attributes' because in the end of the file\nwe show not is a comm_semiring, and we will automatically inherit\nthe associated [simp] lemmas from algebra\n-/\nlocal attribute nat.add_zero nat.add_succ [simp]\n\nprotected theorem zero_add (n : ℕ) : 0 + n = n :=\nby rec_simp\n\ntheorem succ_add (n m : ℕ) : (succ n) + m = succ (n + m) :=\nby rec_simp\n\nlocal attribute nat.zero_add nat.succ_add [simp]\n\nprotected theorem add_comm (n m : ℕ) : n + m = m + n :=\nby rec_simp\n\ntheorem succ_add_eq_succ_add (n m : ℕ) : succ n + m = n + succ m :=\nby simp\n\nprotected theorem add_assoc (n m k : ℕ) : (n + m) + k = n + (m + k) :=\nby rec_simp\n\nprotected theorem add_left_comm : Π (n m k : ℕ), n + (m + k) = m + (n + k) :=\nleft_comm nat.add_comm nat.add_assoc\n\nlocal attribute nat.add_comm nat.add_assoc nat.add_left_comm [simp]\n\nprotected theorem add_right_comm : Π (n m k : ℕ), n + m + k = n + k + m :=\nright_comm nat.add_comm nat.add_assoc\n\nprotected theorem add_left_cancel {n m k : ℕ} : n + m = n + k → m = k :=\nnat.induction_on n\n  (by simp)\n  (take a iH,\n    -- TODO(Leo): replace with forward reasoning after we add strategies for it.\n    have succ (a + m) = succ (a + k) → a + m = a + k, from !succ.inj,\n    by inst_simp)\n\nprotected theorem add_right_cancel {n m k : ℕ} (H : n + m = k + m) : n = k :=\nhave H2 : m + n = m + k, by simp,\nnat.add_left_cancel H2\n\ntheorem eq_zero_of_add_eq_zero_right {n m : ℕ} : n + m = 0 → n = 0 :=\nnat.induction_on n\n  (by simp)\n  (take k iH, assume H : succ k + m = 0,\n    absurd\n      (show succ (k + m) = 0, by simp)\n      !succ_ne_zero)\n\ntheorem eq_zero_of_add_eq_zero_left {n m : ℕ} (H : n + m = 0) : m = 0 :=\neq_zero_of_add_eq_zero_right (!nat.add_comm ⬝ H)\n\ntheorem eq_zero_and_eq_zero_of_add_eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=\nand.intro (eq_zero_of_add_eq_zero_right H) (eq_zero_of_add_eq_zero_left H)\n\ntheorem add_one (n : ℕ) : n + 1 = succ n := rfl\n\nlocal attribute add_one [simp]\n\ntheorem one_add (n : ℕ) : 1 + n = succ n :=\nby simp\n\ntheorem succ_eq_add_one (n : ℕ) : succ n = n + 1 :=\nrfl\n\n/- multiplication -/\n\nprotected theorem mul_zero (n : ℕ) : n * 0 = 0 :=\nrfl\n\ntheorem mul_succ (n m : ℕ) : n * succ m = n * m + n :=\nrfl\n\nlocal attribute nat.mul_zero nat.mul_succ [simp]\n\n-- commutativity, distributivity, associativity, identity\n\nprotected theorem zero_mul (n : ℕ) : 0 * n = 0 :=\nby rec_simp\n\ntheorem succ_mul (n m : ℕ) : (succ n) * m = (n * m) + m :=\nby rec_simp\n\nlocal attribute nat.zero_mul nat.succ_mul [simp]\n\nprotected theorem mul_comm (n m : ℕ) : n * m = m * n :=\nby rec_simp\n\nprotected theorem right_distrib (n m k : ℕ) : (n + m) * k = n * k + m * k :=\nby rec_simp\n\nprotected theorem left_distrib (n m k : ℕ) : n * (m + k) = n * m + n * k :=\nby rec_simp\n\nlocal attribute nat.mul_comm nat.right_distrib nat.left_distrib [simp]\n\nprotected theorem mul_assoc (n m k : ℕ) : (n * m) * k = n * (m * k) :=\nby rec_simp\n\nlocal attribute nat.mul_assoc [simp]\n\nprotected theorem mul_one (n : ℕ) : n * 1 = n :=\ncalc\n  n * 1 = n * 0 + n : mul_succ\n    ... = n         : by simp\n\nlocal attribute nat.mul_one [simp]\n\nprotected theorem one_mul (n : ℕ) : 1 * n = n :=\nby simp\n\nlocal attribute nat.one_mul [simp]\n\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero {n m : ℕ} : n * m = 0 → n = 0 ∨ m = 0 :=\nnat.cases_on n (by simp)\n  (take n',\n    nat.cases_on m\n      (by simp)\n      (take m', assume H,\n        absurd\n          (show succ (succ n' * m' + n') = 0, by simp)\n          !succ_ne_zero))\n\nprotected definition comm_semiring [trans_instance] : comm_semiring nat :=\n⦃comm_semiring,\n add            := nat.add,\n add_assoc      := nat.add_assoc,\n zero           := nat.zero,\n zero_add       := nat.zero_add,\n add_zero       := nat.add_zero,\n add_comm       := nat.add_comm,\n mul            := nat.mul,\n mul_assoc      := nat.mul_assoc,\n one            := nat.succ nat.zero,\n one_mul        := nat.one_mul,\n mul_one        := nat.mul_one,\n left_distrib   := nat.left_distrib,\n right_distrib  := nat.right_distrib,\n zero_mul       := nat.zero_mul,\n mul_zero       := nat.mul_zero,\n mul_comm       := nat.mul_comm⦄\n\nend nat\n\nsection\nopen nat\ndefinition iterate {A : Type} (op : A → A) : ℕ → A → A\n | 0 := λ a, a\n | (succ k) := λ a, op (iterate k a)\n\nnotation f`^[`n`]` := iterate f 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/data/nat/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8670357546485408, "lm_q1q2_score": 0.7942997901592859}}
{"text": "import game.limits.seq_bdd_iff_range_bdd\n\nnamespace xena --hide \n\n/- \nBounded monotone sequences converge\n-/\n\ndef is_increasing (a : ℕ → ℝ) := ∀ n : ℕ, a n ≤ a (n+1)\ndef is_decreasing (a : ℕ → ℝ) := ∀ n : ℕ, a (n + 1) ≤ a n\ndef is_monotone (a : ℕ → ℝ) := is_increasing a ∨ is_decreasing a\n\n-- begin hide\n-- Note: later we use (n ≤ k) → (a n ≤ a k) for `a` monotone increasing\n-- and (n ≤ k) → (a k ≤ a n) for decreasing. Should these be proved first,\n-- or use mathlib's versions of monotone? \n--https://leanprover-community.github.io/mathlib_docs/order/basic.html\n\ntheorem is_increasing' (a : ℕ → ℝ) : is_increasing a ↔ (∀ m n : ℕ, \n m ≤ n → a m ≤ a n) := \nbegin\nsplit,\nintros inc m n,\n{intro hyp,\ninduction hyp with k hyp ihyp,\nexact le_refl (a m),\nexact le_trans ihyp (inc k),},\nintros hyp p,\nexact (hyp p (p + 1)) (nat.le_succ p),\nend\n\ntheorem is_decreasing' (a : ℕ → ℝ) : is_decreasing a ↔ (∀ m n : ℕ, \n m ≤ n → a n ≤ a m) := \nbegin\nsplit,\nintros dec m n,\n{intro hyp,\ninduction hyp with k hyp ihyp,\nexact le_refl (a m),\nexact le_trans (dec k) ihyp,},\nintros hyp p,\nexact (hyp p (p + 1)) (nat.le_succ p),\nend\n-- end hide\n\n/- Lemma\nBounded monotone sequences converge. \n-/\n\ntheorem bdd_mono_converges (a : ℕ → ℝ) (h1 : is_bounded a) (h2 : is_monotone a): \nis_convergent a :=\nbegin\n-- As before, M is the set of terms of our sequence a\nlet M := set.range a,\n\n-- The increasing and the decreasing cases will be similar\ncases h2 with increasing decreasing,\n    \n    -- monotone increasing case\n    {\n    have fact1: has_lub M,\n    -- We use the completeness axiom (least upper bound property)\n    -- to show that M has a sup. refine produces two subgoals that we \n    -- will need to prove to show that the sup exists.\n    refine lub_property_reals M _,\n\n    split,\n        -- As our sequence `a` is a function from the nonempty set ℕ, \n        -- its range is nonempty\n        {\n        exact set.range_nonempty a,\n        },\n        -- We use the → (.mp) direction of our previous `trivial` lemma \n        -- to prove that M is bounded above\n        {exact ((seq_bdd_iff_range_bdd a).mp h1).left,\n        },\n\n    -- So M has a lub, call it s.\n    cases fact1 with s hyp_s,\n    \n    -- It seems reasonable to assume that s is the limit of a\n    use s,\n    intros e hype,\n\n    -- We show that s - e cannot be an upper bound for M (our set of terms)\n    have fact2: ¬ is_upper_bound M (s - e),\n    by_contradiction claim,\n    -- hyp_s.right says if y is any upper bound of M, then s ≤ y \n    -- (supremum condition)\n    let forcontra := hyp_s.right (s - e) claim,\n    --forcontra says that s ≤ s - e. But e is positive, so linarith closes.\n    linarith,\n    \n    -- we now unfold the fact that s - e is not an upper bound for M,\n    -- and prove that s is the limit of our increasing sequence\n    unfold is_upper_bound at fact2,\n    push_neg at fact2,\n    cases fact2 with l hypl,\n    -- hypl.right is a proof that s - e < l, for some l ∈ M\n    -- we want l expressed in the form a N0 for some N0,\n    cases hypl.left with N0 hypN0,\n    use N0,\n    intros k hypk,\n    -- applying the theorem proved above\n    rw is_increasing' at increasing, \n    have fact3:= (increasing N0 k) hypk,\n    refine abs_lt.mpr _,\n    split, \n    linarith,\n    have fact4: a k ≤ s, \n    exact hyp_s.left (a k) (set.mem_range_self k),\n    linarith,\n    },\n\n    --monotone decreasing case, using the same strategy\n    {\n    have fact3: has_glb M,\n    refine glb_property_reals M _,\n\n    split,\n        {\n        exact set.range_nonempty a,\n        },\n\n        {\n        exact ((seq_bdd_iff_range_bdd a).mp h1).right,\n        },\n\n    cases fact3 with i hyp_i,\n    use i,\n\n    intros e hype,\n\n    -- We show that i + e cannot be a lower bound for M (our set of terms)\n    have fact4: ¬ is_lower_bound M (i + e),\n    by_contradiction claim,\n    let forcontra := hyp_i.right (i + e) claim,\n    linarith,\n\n    unfold is_lower_bound at fact4,\n    push_neg at fact4,\n    cases fact4 with m hypm,\n \n    cases hypm.left with N0 hypN0,\n    use N0,\n    intros k hypk,\n    -- applying the theorem proved above\n    rw is_decreasing' at decreasing, \n    have fact5:= (decreasing N0 k) hypk,\n    refine abs_lt.mpr _,\n    split, \n    have fact4: i ≤ a k, \n    exact hyp_i.left (a k) (set.mem_range_self k),\n    linarith,\n    linarith,\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/limits/bdd_monos_converge.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7942089577165851}}
{"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) : (∀ x₁, x₁ < x → Nat → Nat) → Nat → Nat :=\n  match x with\n  | 0      => fun _ y => y\n  | succ x => fun f y => f (y % succ x) (mod_lt _ (zeroLtSucc  _)) (succ x)\n\n@[extern \"lean_nat_gcd\"]\ndef gcd (a b : @& Nat) : Nat :=\n  WellFounded.fix ltWf 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 <;> simp [gcd_succ]\n\n@[simp] theorem gcd_self (n : Nat) : gcd n n = n := by\n  cases n <;> simp [gcd_succ]\n\nend Nat", "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/stage0/src/Init/Data/Nat/Gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7942089561637664}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro h,\n  intro g,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  by_cases h : P,\n  intro g,\n  assumption,\n  intro g,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  by_cases h : P,\n  intro g,\n  assumption,\n  intro g,\n  contradiction,\n  intro h,\n  intro g,\n  contradiction,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hp,\n  cases hp,\n  right,\n  assumption,\n  left,\n  assumption,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro hp,\n  split,\n  cases hp,\n  assumption,\n  cases hp,\n  assumption,\n  \nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro hp,\n  intro g,\n  cases hp,\n  contradiction,\n  exact hp,\n\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro hp,\n  intro g,\n  cases hp,\n  contradiction,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro hp,\n  intro g,\n  intro p,\n  have q := hp p,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro hp,\n  intro p,\n  by_contra,\n  have np := hp h,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  intro hp,\n  intro q,\n  intro p,\n  have qo := hp p,\n  contradiction,\n  intro hp,\n  intro nq,\n  by_contra,\n  have qc := hp h,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro hp,\n  have LEM : P∨¬P,\n    right,\n    intro p,\n    have LEM2 : P∨¬P,\n      left,\n      assumption,\n    contradiction,\n  contradiction,\n    \nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro pqp,\n  intro np,\n  have novopq : (P → Q),\n  intro p,\n  contradiction,\n  have p := pqp  novopq,\n  contradiction,\n  \nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro pq,\n  intro npq,\n  cases npq,\n  cases pq,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro pq,\n  intro npq,\n  cases pq,\n  cases npq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro npq,\n  split,\n  intro p,\n  have peq : (P ∨ Q),\n  left,\n  assumption,\n  contradiction,\n  intro q,\n  have peq : (P ∨ Q),\n  right,\n  assumption,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro npnq,\n  intro pq,\n  cases pq,\n  cases npnq,\n  contradiction,\n  cases npnq,\n  contradiction,\n\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro npq,\n  by_contra nqp,\n  apply npq,\n  split,\n  by_contra np,\n  apply nqp,\n  right,\n  assumption,\n  by_contra nq,\n  apply nqp,\n  left,\n  assumption,\n  \nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro nqnp,\n  intro npq,\n  cases nqnp,\n  apply nqnp,\n  cases npq,\n  assumption,\n  apply nqnp,\n  cases npq,\n  assumption,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  intro npq,\n  by_contra nqp,\n  apply npq,\n  split,\n  by_contra np,\n  apply nqp,\n  right,\n  assumption,\n  by_contra nq,\n  apply nqp,\n  left,\n  assumption,\n  intro nqnp,\n  intro npq,\n  cases nqnp,\n  apply nqnp,\n  cases npq,\n  assumption,\n  apply nqnp,\n  cases npq,\n  assumption,\n\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  intro npq,\n  split,\n  intro p,\n  have peq : (P ∨ Q),\n  left,\n  assumption,\n  contradiction,\n  intro q,\n  have peq : (P ∨ Q),\n  right,\n  assumption,\n  contradiction,\n  intro npnq,\n  intro pq,\n  cases pq,\n  cases npnq,\n  contradiction,\n  cases npnq,\n  contradiction,\n\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro pqr,\n  cases pqr,\n  cases pqr_right,\n  left,\n  split,\n  assumption,\n  assumption,\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro pqpr,\n  split,\n  cases pqpr,\n  cases pqpr,\n  assumption,\n  cases pqpr,\n  assumption,\n  cases pqpr,\n  cases pqpr,\n  left,\n  assumption,\n  cases pqpr,\n  right,\n  assumption,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro pqr,\n  split,\n  cases pqr,\n  left,\n  assumption,\n  cases pqr,\n  right,\n  assumption,\n  cases pqr,\n  left,\n  assumption,\n  cases pqr,\n  right,\n  assumption,\n\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro pqpr,\n  cases pqpr,\n  cases pqpr_right,\n  left,\n  assumption,\n  cases pqpr_left,\n  left,\n  assumption,\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro pqr,\n  intro p,\n  intro q,\n  have pq : (P∧Q),\n  split,\n  assumption,\n  assumption,\n  have r :R := pqr pq,\n  assumption,\n\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro pqr,\n  intro pq,\n  cases pq,\n  have qr: (Q→R) := pqr pq_left, \n  have r : R := qr pq_right,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  assumption,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  assumption,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  assumption,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro pq,\n  cases pq,\n  assumption,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro pq,\n  cases pq,\n  assumption,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pp,\n  cases pp,\n  assumption,\n  intro p,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro pp,\n  cases pp,\n  assumption,\n  assumption,\n  intro p,\n  left,\n  assumption,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro expx,\n  intro axnpx,\n  intro np,\n  apply expx,\n  existsi axnpx,\n  assumption,\n\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro xAnpx,\n  intro nxEPx,\n  cases nxEPx with x px,\n  have npx : ¬P x := xAnpx x,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro xAPx,\n  by_contra xEnpx,\n  apply xAPx,\n  intro x,\n  by_contra npx,\n  apply xEnpx,\n  existsi x, \n  exact npx,\n\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro xEnPx, \n  intro xAPx,\n  cases xEnPx with  x npx,\n  have px : P x := xAPx x,\n  contradiction,\n\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  intro xAPx,\n  by_contra xEnpx,\n  apply xAPx,\n  intro x,\n  by_contra npx,\n  apply xEnpx,\n  existsi x, \n  exact npx,\n  intro xEnPx, \n  intro xAPx,\n  cases xEnPx with  x npx,\n  have px : P x := xAPx x,\n  contradiction,\n\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  intro expx,\n  intro axnpx,\n  intro np,\n  apply expx,\n  existsi axnpx,\n  assumption,\n  intro xAnpx,\n  intro nxEPx,\n  cases nxEPx with x px,\n  have npx : ¬P x := xAnpx x,\n  contradiction,\n\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro xEPx,\n  intro xAnPx,\n  cases xEPx with  x npx,\n  have npx : ¬P x := xAnPx x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro xAPx,\n  intro xnEnPx,\n  cases xnEnPx with  x npx,\n   have px : P x := xAPx x,\n   contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro xnEnPx,\n  intro xAPx,\n  by_cases pnp : P xAPx,\n  assumption,\n  have xEnPx : (∃x, ¬P x),\n    existsi xAPx,\n    assumption,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n    intro xnAnPx,\n  by_contra xnEPx,\n  have xAnPx : ∀x, ¬P x,\n    intro x,\n    intro px,\n    have xEPx: ∃x, P x,\n      existsi x,\n      exact px,\n    contradiction,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  intro xAPx,\n  intro xnEnPx,\n  cases xnEnPx with  x npx,\n   have px : P x := xAPx x,\n   contradiction,\n    intro xnEnPx,\n  intro xAPx,\n  by_cases pnp : P xAPx,\n  assumption,\n  have xEnPx : (∃x, ¬P x),\n    existsi xAPx,\n    assumption,\n  contradiction,\n\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n   intro xEPx,\n  intro xAnPx,\n  cases xEPx with  x npx,\n  have npx : ¬P x := xAnPx x,\n  contradiction,\n    intro xnAnPx,\n  by_contra xnEPx,\n  have xAnPx : ∀x, ¬P x,\n    intro x,\n    intro px,\n    have xEPx: ∃x, P x,\n      existsi x,\n      exact px,\n    contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro xEPxQx, \n  cases xEPxQx with a PaQa,\n  cases PaQa,\n  split,\n  existsi a,\n  assumption,\n  existsi a,\n  assumption,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro xEPxQx,\n  cases xEPxQx with a PaQa,\n  cases PaQa,\n  left,\n  existsi a,\n  exact PaQa,\n  right,\n  existsi a,\n  exact PaQa,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n    intro xEPxouxEQx,\n  cases xEPxouxEQx,\n  cases xEPxouxEQx with a Pa,\n  have PaQa : P a ∨ Q a,\n    left,\n    exact Pa,\n  existsi a,\n  exact PaQa,\n  cases xEPxouxEQx with a Qa,\n  have PaQa : P a ∨ Q a,\n    right,\n    exact Qa, \n  existsi a,\n  exact PaQa,\n\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro xAPxeQx,\n  split,\n  intro x,\n  have PxQx := xAPxeQx x,\n  cases PxQx with Px Qx,\n  assumption,\n  intro x,\n  have PxQx := xAPxeQx x,\n  cases PxQx with Px Qx,\n  assumption,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro xAPxxAQx,\n  cases xAPxxAQx,\n  intro a,\n  have Pa: P a := xAPxxAQx_left a,\n  have Qa: Q a := xAPxxAQx_right a,\n  split,\n  exact Pa,\n  exact Qa,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n   intro xAPxouxAQx,\n  intro x,\n  cases xAPxouxAQx with xAPx xAQx,\n  have Px := xAPx x,\n  left,\n  assumption,\n  have Qx := xAQx x,\n  right,\n  assumption,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "Arthur-Holanda", "repo": "fmclean", "sha": "e1397fcf45e5e434caa2520da318a0203dec9510", "save_path": "github-repos/lean/Arthur-Holanda-fmclean", "path": "github-repos/lean/Arthur-Holanda-fmclean/fmclean-e1397fcf45e5e434caa2520da318a0203dec9510/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7942089510598749}}
{"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\n! This file was ported from Lean 3 source module algebra.module.pointwise_pi\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.Set.Pointwise.SMul\nimport Mathlib.GroupTheory.GroupAction.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 Pointwise\n\nopen Set\n\nvariable {K ι : Type _} {R : ι → Type _}\n\n@[to_additive]\ntheorem smul_pi_subset [∀ i, SMul K (R i)] (r : K) (s : Set ι) (t : ∀ i, Set (R i)) :\n    r • pi s t ⊆ pi s (r • t) := by\n  rintro x ⟨y, h, rfl⟩ i hi\n  exact smul_mem_smul_set (h i hi)\n#align smul_pi_subset smul_pi_subset\n#align vadd_pi_subset vadd_pi_subset\n\n-- Porting note: Lean 4 can't synthesize `Set.mem_univ i`?\n@[to_additive]\ntheorem smul_univ_pi [∀ i, SMul K (R i)] (r : K) (t : ∀ i, Set (R i)) :\n    r • pi (univ : Set ι) t = pi (univ : Set ι) (r • t) :=\n  (Subset.antisymm (smul_pi_subset _ _ _)) fun x h ↦\n    by\n    refine' ⟨fun i ↦ Classical.choose (h i <| Set.mem_univ _), fun i _ ↦ _, funext fun i ↦ _⟩\n    · exact (Classical.choose_spec (h i <| Set.mem_univ i)).left\n    · exact (Classical.choose_spec (h i <| Set.mem_univ i)).right\n#align smul_univ_pi smul_univ_pi\n#align vadd_univ_pi vadd_univ_pi\n\n@[to_additive]\ntheorem smul_pi [Group K] [∀ i, MulAction K (R i)] (r : K) (S : Set ι) (t : ∀ i, Set (R i)) :\n    r • S.pi t = S.pi (r • t) :=\n  (Subset.antisymm (smul_pi_subset _ _ _)) fun x h ↦\n    ⟨r⁻¹ • x, fun i hiS ↦ mem_smul_set_iff_inv_smul_mem.mp (h i hiS), smul_inv_smul _ _⟩\n#align smul_pi smul_pi\n#align vadd_pi vadd_pi\n\ntheorem smul_pi₀ [GroupWithZero K] [∀ i, MulAction K (R i)] {r : K} (S : Set ι) (t : ∀ i, Set (R i))\n    (hr : r ≠ 0) : r • S.pi t = S.pi (r • t) :=\n  smul_pi (Units.mk0 r hr) S t\n#align smul_pi₀ smul_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/Algebra/Module/PointwisePi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7942022263338436}}
{"text": "import game.limits.shift_rule_seq\n\nnamespace xena --hide \n\n/- \nBounded monotone sequences converge\n-/\n\n/- Lemma\nIt is obvious that a sequence of real numbers is bounded if and only if \nthe set of its terms is bounded above and bounded below in ℝ. For that\nreason you may wish to skip the proof of the following proposition, which \nwe will use in our proof of the monotone convergence theorem.\n-/\n\ntheorem seq_bdd_iff_range_bdd (a : ℕ → ℝ) : is_bounded a ↔ \nis_bdd_above (set.range a) ∧ is_bdd_below (set.range a):=\nbegin\n-- first split the iff\nsplit,\n    -- Sequence bounded only if range bounded above and below (→)\n    {\n    -- let |a n| ≤ B for any n, from def of bounded sequence\n    intro hyp,\n    cases hyp with B hypB,\n    -- now split the conjunction\n    split,\n        -- first prove set of terms is bounded above\n        {\n        use B,\n        -- let s be any element in our set of terms\n        intros s hyp,\n        -- by definition of set.range, hyp proves ∃ (k : ℕ), a k = s,\n        cases hyp with k hypk,\n        specialize hypB k,\n        -- establish a simple fact and use linarith\n        have fact: a k ≤ |a k|, from le_abs_self (a k),\n        linarith,\n        },\n        -- set of terms is bounded below, similar proof\n        {\n        use -B,\n        intros s hyp,\n        cases hyp with k hypk,\n        specialize hypB k,\n        refine neg_le.mp _,   -- makes goal a litle clearer\n        have fact:= neg_le_abs_self (a k),\n        linarith,\n        }\n    },\n    -- Sequence bounded if range bounded above and below (←)\n    intro hyp,\n    -- set up our upper and lower bounds for the range\n    cases hyp.left with U hypU,\n    cases hyp.right with L hypL,\n    -- Use max and abs to define a term B to bound our sequence\n    let B := max U (|L|),\n    use B,\n    -- Now show that this B is a bound\n    intro k,\n    -- k defines an arbitrary term a k in our sequence\n    have fact: a k ∈ set.range a, exact set.mem_range_self k,\n    -- we know that U and L are upper and lower bounds for the range \n    have Upperbound: a k ≤ U, from hypU (a k) fact,\n    have Lowerbound: L ≤ a k, from hypL (a k) fact,\n    -- refine unfolds consequences of the `max` function hidden \n    -- inside `B` in our goal (I used `suggest` here)\n    refine le_max_iff.mpr _,\n    -- to prove |a k| ≤ B, we proceed by cases on the sign of a k \n    by_cases sign : 0 ≤ a k, \n    -- a k is non-negative, so the corresponding bound is U\n    {-- so choose `left`\n    left,\n    have: |a k| = a k, from abs_of_nonneg sign,\n    linarith,\n    },\n    -- a k is negative, so the corresponding bound is |L|\n    -- again, prepare simple facts about `abs` and use linarith\n    {\n    right,\n    simp at sign,\n    have fact1:= abs_of_neg sign,\n    have Lisneg:= lt_of_le_of_lt Lowerbound sign,\n    have fact2:= abs_of_neg Lisneg,\n    linarith,\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/limits/seq_bdd_iff_range_bdd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.7942022231152364}}
{"text": "/-\n# Proposition world. \n\n## Level 3: `have`.\n\nSay you have a whole bunch of propositions and implications between them,\nand your goal is to build a certain proof of a certain proposition.\nIf it helps, you can build intermediate proofs of other propositions\nalong the way, using the `have` command. `have q : Q := ...` is the Lean analogue\nof saying \"We now see that we can prove $Q$, because...\"\nin the middle of a proof.\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 up into smaller steps.\n\nIn the level below, we have a proof of $P$ and we want a proof\nof $U$; during the proof we will construct proofs of\nof some of the other propositions involved. The diagram of\npropositions and implications looks like this pictorially:\n\n![diagram](https://wwwf.imperial.ac.uk/~buzzard/xena/natural_number_game_images/implies_diag.jpg)\n\nand so it's clear how to deduce $U$ from $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 a proof of $Q$:\n\n`have q := h(p),`\n\nand then we note that $j(q)$ is a proof of $T$:\n\n`have t : T := j(q),`\n\n(note how we explicitly told Lean what proposition we thought $t$ was\na proof of, with that `: T` thing before the `:=`) \nand we could even define $u$ to be $l(t)$:\n\n`have u : U := l(t),`\n\nand then finish the level with\n\n`exact u,`\n\n. \n-/\n\n/- Lemma : no-side-bar\nIn the maze of logical implications above, if $P$ is true then so is $U$.\n-/\nlemma maze (P Q R S T U: Prop)\n(p : P)\n(h : P → Q)\n(i : Q → R)\n(j : Q → T)\n(k : S → T)\n(l : T → U)\n: U :=\nbegin\n  have q := h(p),\n  have t := j(q),\n  have u := l(t),\n  exact u,\n\n\nend\n\n/-\nIf you solved the level using `have`, then click on the last line of your proof\n(you do know you can move your cursor around with the arrow keys\nand explore your proof, right?) and note that the local context at that point\nis in something like the following mess:\n\n```\nP Q R S T U : Prop,\np : P,\nh : P → Q,\ni : Q → R,\nj : Q → T,\nk : S → T,\nl : T → U,\nq : Q,\nt : T,\nu : U\n⊢ 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-/", "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/level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8791467690927439, "lm_q1q2_score": 0.7941281856526308}}
{"text": "\nnamespace ex1\n    -- Prove these equivalences:\n    variables (α : Type) (p q : α → Prop)\n\n    def proof1 : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\n    have left : (∀ x, p x ∧ q x) → (∀ x, p x) ∧ (∀ x, q x), from\n        assume h : (∀ x, p x ∧ q x),\n        and.intro (λ z : α, (h z).left) (λ z : α, (h z).right),\n    have right : (∀ x, p x) ∧ (∀ x, q x) → (∀ x, p x ∧ q x), from\n        assume h : (∀ x, p x) ∧ (∀ x, q x),\n        λ z : α, and.intro (h.left z) (h.right z),\n    ⟨left, right⟩\n\n    def proof2 (h₁ : ∀ x, p x → q x) (h₂ : ∀ x, p x) : (∀ x, q x) :=\n    λ z : α, (h₁ z) (h₂ z)\n\n    def proof3 (h : (∀ x, p x) ∨ (∀ x, q x)) : ∀ x, p x ∨ q x :=\n    λ z : α, or.elim h (λ hp, or.inl $ hp z) (λ hq, or.inr $ hq z)\n\n    example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := @proof1 α p q\n    example : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := @proof2 α p q\n    example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := @proof3 α p q\n\n    -- You should also try to understand why the reverse implication\n    -- is not derivable in the last example.\n    --\n    -- Answer: difference between \"for any instance of the type, p or q holds\"\n    -- (less general, right), and \"p holds for any instance of the type, or q\n    -- holds for any instance of the type\" (more general, left). The xs could be\n    -- different instances of α, since they are bound separately.\nend ex1\n\nnamespace ex2\n\n    variables (α : Type) (p q : α → Prop)\n    variable r : Prop\n\n    def proof1 (a : α) : ((∀ x : α, r) ↔ r) :=\n    have left: ((∀ x : α, r) → r), from λ hx, hx a,\n    have right : (r → (∀ x : α, r)), from λ hr, λ z, hr,\n    ⟨left, right⟩\n\n    def proof2 : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=\n    have left : (∀ x, p x ∨ r) → (∀ x, p x) ∨ r, from\n        assume (h : ∀ x, p x ∨ r),\n        or.elim (classical.em r)\n            (λ hr, or.inr hr)\n            (λ hnr, or.intro_left r (\n                λ z : α, or.elim (classical.em (p z))\n                    (λ hpz, hpz)\n                    (λ hnpz, false.elim $ or.elim (h z) (λ hpz, absurd hpz hnpz) (λ hr, absurd hr hnr))\n                )),\n    have right : (∀ x, p x) ∨ r → (∀ x, p x ∨ r), from\n        assume (h : (∀ x, p x) ∨ r),\n        λ (z : α), or.elim h (λ hp, or.inl $ hp z) (λ hr, or.inr hr),\n    ⟨left, right⟩\n\n    def proof3 : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=\n    have left : (∀ x, r → p x) → (r → ∀ x, p x), from\n        assume (h : ∀ z : α, r → p z),\n        λ (hr : r), λ (zz : α), h zz hr,\n    have right : (r → ∀ x, p x) → (∀ x, r → p x), from\n        assume (h : r → ∀ x, p x),\n        λ (z : α), λ (hr :r), (h hr) z,\n    ⟨left, right⟩\n\n    example : α → ((∀ x : α, r) ↔ r) := proof1 α r\n    example : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r := proof2 α p r\n    example : (∀ x, r → p x) ↔ (r → ∀ x, p x) := proof3 α p r\n\nend ex2\n\nnamespace ex3\n\n    variables (men : Type) (barber : men)\n    variable  (shaves : men → men → Prop)\n\n    example (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\n    have h1 : shaves barber barber → ¬ shaves barber barber, from iff.elim_left $ h barber,\n    have h2 : ¬ shaves barber barber → shaves barber barber, from iff.elim_right $ h barber,\n    have nsbb : ¬shaves barber barber, from λ hsbb : shaves barber barber, absurd hsbb (h1 hsbb),\n    have sbb : shaves barber barber, from h2 nsbb,\n    absurd sbb nsbb\n\nend ex3\n\nnamespace ex4\n    namespace hidden\n\n        def divides (m n : ℕ) : Prop := ∃ k, m * k = n\n\n        instance : has_dvd nat := ⟨divides⟩\n\n        def even (n : ℕ) : Prop := 2 ∣ n -- You can enter the '∣' character by typing \\mid\n\n        section\n            variables m n : ℕ\n\n            #check m ∣ n\n            #check m^n\n            #check even (m^n + 3)\n        end\n\n    end hidden\n\n    def prime (n : ℕ) : Prop := n > 1 ∧ ¬   (∃ m : ℕ, m < n ∧ hidden.divides m n)\n\n    def infinitely_many_primes : Prop := ∀ n : ℕ,\n        prime n ∧ (∃ m : ℕ, prime m ∧ n < m)\n        ∨ ¬(prime n)\n\n    def Fermat_prime (n : ℕ) : Prop := prime n ∧ n > 2 ∧ (∃ k : ℕ , (2^k + 1) = n)\n\n    def infinitely_many_Fermat_primes : Prop := ∀ n : ℕ,\n        (Fermat_prime n ∧ (∃ m : ℕ, Fermat_prime m ∧ m > n))\n        ∨ ¬(Fermat_prime n)\n\n    def goldbach_conjecture : Prop := ∀ n : ℕ,\n    n < 2\n    ∨ ¬(hidden.even n)\n    ∨ ∃ a b : ℕ, prime a ∧ prime b ∧ (a + b = n)\n\n    -- Every odd number greater than 5 can be expressed as the sum of three primes. (A prime may be used more than once in the same sum.)\n    -- https://en.wikipedia.org/wiki/Goldbach%27s_weak_conjecture\n    def Goldbach's_weak_conjecture : Prop := ∀ n : ℕ,\n    n < 5\n    ∨ hidden.even n\n    ∨ (∃ a b c : ℕ, prime a ∧ prime b ∧ prime c ∧ a + b + c = n )\n\n    def Fermat's_last_theorem : Prop := ∀ n : ℕ,\n    n ≤ 2\n    ∨ ¬(∃ a b c : ℕ, a^n + b^n = c^n)\n\nend ex4\n\nnamespace ex5\n    open classical\n\n    variables (α : Type) (p q : α → Prop)\n    variable a : α\n    variable r : Prop\n\n    def pikachu (h : ∃ x : α, r) : r :=\n    match h with ⟨hx, hr⟩ := hr end\n\n    def raichu (hr : r) : (∃ x : α, r) := exists.intro a hr\n\n    def pichu : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r :=\n    have left : (∃ x, p x ∧ r) → (∃ x, p x) ∧ r, from\n        assume h : (∃ x, p x ∧ r),\n        match h with ⟨hx, h1⟩ :=\n            and.intro (⟨hx, h1.left⟩) h1.right\n        end,\n    have right : (∃ x, p x) ∧ r → (∃ x, p x ∧ r), from\n        assume h,\n        match h.left with ⟨hx, hpx⟩ :=\n            ⟨hx, and.intro hpx h.right⟩\n        end,\n    ⟨left, right⟩\n\n    def jesse : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=\n    have left : (∃ x, p x ∨ q x) → (∃ x, p x) ∨ (∃ x, q x),from\n        assume ⟨hx, h1⟩,\n        or.elim h1 (λ hpx, or.inl ⟨hx, hpx⟩) (λ hqx, or.inr ⟨hx, hqx⟩),\n    have right : (∃ x, p x) ∨ (∃ x, q x) → (∃ x, p x ∨ q x), from\n        assume h,\n        or.elim h (λ ⟨hx, hpx⟩, ⟨hx, or.inl hpx⟩) (λ ⟨hx, hqx⟩, ⟨hx, or.inr hqx⟩),\n    ⟨left, right⟩\n\n    -- May require classical reasoning\n    def james : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) :=\n    have left : (∀ x, p x) → ¬ (∃ x, ¬ p x), from\n        assume h1,\n        assume h2 : (∃ x, ¬ p x),\n        have ¬ (∀ x, p x), from\n            match h2 with ⟨hx, hnpx⟩ :=\n                absurd (h1 hx) hnpx\n            end,\n        absurd h1 this,\n    have right : ¬ (∃ x, ¬ p x) → (∀ x, p x), from\n        assume h1,\n        λ hx, by_contradiction (λ hnpx, h1 ⟨hx, hnpx⟩),\n    ⟨left, right⟩\n\n    theorem dne {p : Prop} (h : ¬¬p) : p :=\n    or.elim (em p)\n    (assume hp : p, hp)\n    (assume hnp : ¬p, absurd hnp h)\n\n\n    def team_rocket : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) :=\n    have left : (∃ x, p x) → ¬ (∀ x, ¬ p x), from\n        assume h1 h2,\n        match h1 with ⟨hx, hpx⟩ :=\n            absurd hpx (h2 hx)\n        end,\n    have right : ¬ (∀ x, ¬ p x) → (∃ x, p x), from\n        assume h,\n        by_contradiction (\n            λ hnex,\n            have (∀ x, ¬ p x), from (\n                λ x, by_contradiction (λ h2, absurd (⟨x, dne h2⟩ : (∃ x, p x)) hnex)\n            ),\n            absurd this h\n        ),\n    ⟨left, right⟩\n\n    def prepare_for_trouble : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) :=\n    have left : (¬ ∃ x, p x) → (∀ x, ¬ p x), from (\n        assume hne,\n        λ x, by_cases (λ (hpx : p x), absurd (⟨x, hpx⟩ : ∃ x, p x) hne) (λ hnpx, hnpx)\n    ),\n    have right : (∀ x, ¬ p x) → (¬ ∃ x, p x), from\n        assume h1 h2,\n        match h2 with ⟨hx, hpx⟩ := absurd hpx (h1 hx) end,\n    ⟨left, right⟩\n\n    def make_it_double : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) :=\n    have left : ¬(∀ x, p x) → (∃ x, ¬ p x), from\n        assume h,\n        by_contradiction (\n            λ hnex,\n            have (∀ x, p x), from (\n                λ hx, or.elim (em $p hx)\n                    (λ hphx, hphx)\n                    (λ hnphx, absurd (⟨hx, hnphx⟩ : ∃ x, ¬ p x) hnex)\n            ),\n            absurd this h\n        ),\n    have right : (∃ x, ¬ p x) → ¬(∀ x, p x), from\n        assume h,\n        match h with ⟨hx, hnpx⟩ :=\n            λ h2, absurd (h2 hx) hnpx\n        end,\n    ⟨left, right⟩\n\n    def to_protect_the_world : (∀ x, p x → r) ↔ (∃ x, p x) → r :=\n    have left : (∀ x, p x → r) → (∃ x, p x) → r, from\n        assume h hpx,\n        match hpx with ⟨hx, hpx⟩ := h _ hpx end,\n    have right : ((∃ x, p x) → r) → (∀ x, p x → r), from\n        assume h,\n        λ hx hpx, h $ ⟨hx, hpx⟩,\n    ⟨left, right⟩\n\n    -- See the book: we need the assumption that α is nonempty here (a)\n    def from_devastation : (∃ x, p x → r) ↔ ((∀ x, p x) → r) :=\n    have left : (∃ x, p x → r) → ((∀ x, p x) → r), from\n        assume h1 h2,\n            match h1 with ⟨hx, hpxtor⟩ :=\n                hpxtor (h2 hx)\n            end,\n    have right : ((∀ x : α, p x) → r) → (∃ x : α, p x → r), from\n        assume h,\n            -- Had too look up that part from the book\n            by_cases\n                (λ hap : (∀ x : α, p x), ⟨a, λ _hleft, h hap⟩)\n                (λ hnap : ¬(∀ x : α, p x),\n                    by_contradiction (\n                        λ hnex : ¬ ∃ x, p x → r,\n                        have hap : ∀ x, p x, from (\n                            assume x : α,\n                            by_contradiction (\n                                assume hnp : ¬ p x,\n                                    have hex : ∃ x, p x → r,\n                                    from ⟨x, (assume hp, absurd hp hnp)⟩,\n                                    show false, from hnex hex\n                            )\n                        ),\n                        show false, from hnap hap\n                    )\n                ),\n    ⟨left, right⟩\n\n    -- See the book: we need the assumption that α is nonempty here (a)\n    def to_unite_all_peoples : (∃ x, r → p x) ↔ (r → ∃ x, p x) :=\n    have left : (∃ x, r → p x) → (r → ∃ x, p x), from\n        assume h hr,\n        match h with ⟨hx, hrpx⟩ :=\n            ⟨hx, hrpx hr⟩\n        end,\n    have right : (r → ∃ x, p x) → (∃ x, r → p x), from\n        assume h,\n        by_contradiction (\n            λ (hnex : ¬∃ x, r → p x),\n            have hx : α, from a,\n            have h1 : ∀ x, ¬(r → p x), from λ hx h2, hnex ⟨hx, h2⟩,\n            have h2 : ¬∃ x, p x, from (\n                assume hn : ∃ x, p x,\n                match hn with ⟨hx, hpx⟩ :=\n                    absurd (λ hr, hpx) (h1 hx)\n                end\n            ),\n            have h3 : r → ¬∃ x, p x, from λ hr, h2,\n            have h4 : r → ∀ x, ¬ p x, from λ hr, forall_not_of_not_exists $ h3 hr,\n            have ¬(r → ∃ x, p x), from (\n                assume h,\n                or.elim (em r)\n                    (λ hr,\n                    absurd (h hr) (h3 hr)\n                    )\n                    (λ hnr,\n                    have ∃ x, r → p x, from ⟨hx, λ hr, absurd hr hnr⟩,\n                    show false, from absurd this hnex\n                    )\n            ),\n            show false, from absurd h this\n        ),\n    ⟨left, right⟩\n\n    -- =============\n    -- === Goals ===\n    -- =============\n\n    example : (∃ x : α, r) → r := pikachu α r\n    example : r → (∃ x : α, r) := raichu α a r\n    example : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := pichu α p r\n    example : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := jesse α p q\n\n    example : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := james α p\n    example : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := team_rocket α p\n    example : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := prepare_for_trouble α p\n    example : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := make_it_double α p\n\n    example : (∀ x, p x → r) ↔ (∃ x, p x) → r := to_protect_the_world α p r\n    -- See the book: we need the assumption that α is nonempty here (a)\n    example : (∃ x, p x → r) ↔ (∀ x, p x) → r := from_devastation α p a r\n    example : (∃ x, r → p x) ↔ (r → ∃ x, p x) := to_unite_all_peoples α p a r\n\nend ex5\n\nnamespace ex6\n\n    variables (real : Type) [ordered_ring real]\n    variables (log exp : real → real)\n    variable  log_exp_eq : ∀ x, log (exp x) = x\n    variable  exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x\n    variable  exp_pos    : ∀ x, exp x > 0\n    variable  exp_add    : ∀ 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    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\n                ... = log x + log y : by rw log_exp_eq\n\n    -- #print log_mul\n\nend ex6\n\nnamespace ex7\n\n    #check sub_self\n\n    def sub_is_add_neg (x y : ℤ) : x - y = x + (-y) := eq.refl (x - y)\n\n    def sub_assoc (x y z: ℤ) : (y + x) - z = y + (x - z) :=\n    calc\n        (y + x) - z = y + x + -z : by rw sub_is_add_neg\n                ... = y + (x + -z) : by rw add_assoc\n                ... = y + (x - z) : by rw sub_is_add_neg\n\n    -- See chap_5.lean for a shorter, cleaner solution\n    example (x : ℤ) : x * 0 = 0 := eq.symm $\n    calc\n        0   = x - x : eq.symm (sub_self x)\n        ... = (1 * x) - x : by rw one_mul\n        ... = (x * (1 + 0)) - x : by rw [mul_comm, add_zero]\n        ... = (x * 1 + x * 0) - x : by rw mul_add\n        ... = x + x * 0 - x : by rw [mul_one]\n        ... = (x * 0) + x - x : by rw [add_comm]\n        -- \"by simp\" also works, but I wanted to make sure I know how to prove it manually.\n        ... = x * 0 + (x - x) : by rw [sub_assoc]\n        ... = x * 0 : by rw [sub_self, add_zero]\n\nend ex7\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_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7940116431219841}}
{"text": "import data.rat.basic\nimport data.nat.parity\nimport tactic.basic\n\nopen nat\n\nnoncomputable theory -- definitions are allowed to not compute in this file\nopen_locale classical -- use classical logic in this file\n\n/-!\n## Structures and Classes\nIn this session we will discuss structures together,\nand then you can solve the exercises yourself.\nBefore we start, run the following in a terminal:\n```\n  cd /path/to/lftcm2020/\n  git pull\n  leanproject get-mathlib-cache\n```\nIf `git pull` didn't work because you edited one of the files in the repository,\nfirst copy the files to a backup version and then run `git checkout -- .`\n(this will remove all changes to files you edited, so be careful!)\n### Declaring a Structure\nStructures are a way to bundle information together.\nFor example, the first example below makes a new structure\n  `even_natural_number`, which consists of pairs, where the first\n  component is a natural number, and the second component is a\n  proof that the natural number is even. These are called the *fields* of the structure.\n-/\nstructure even_natural_number : Type :=\n  (n : ℕ)\n  (even_n : even n)\n\n/-! We can also group propositions together, for example this is a proposition\n  stating that `n` is an even cube greater than 100.\n  Note that this is a property of a natural number, while the previous structure\n  was a natural number with a property \"bundled\" together. -/\nstructure is_even_cube_above_100 (n : ℕ) : Prop :=\n  (even : even n)\n  (is_cube : ∃ k, n = k^3)\n  (gt_100 : n > 100)\n\n/-! Here we give the upper bounds for a function `f`. We can omit the type of the structure. -/\nstructure bounds (f : ℕ → ℕ) :=\n  (bound : ℕ)\n  (le_bound : ∀ (n : ℕ), f n ≤ bound)\n\n/-! You can use `#print` to print the type and all fields of a structure. -/\n#print even_natural_number\n#print is_even_cube_above_100\n#print bounds\n\n/-!\n  ### Exercise 1\n  * Define a structure of eventually constant sequences `ℕ → ℕ`. The first field will be\n    `seq : ℕ → ℕ`, and the second field will be the statement that `seq` is eventually constant.\n  * Define a structure of a type with 2 points that are unequal.\n    (hint: omit the type of the structure, Lean might complain if you give it explicitly)\n  Lean will not tell you if you got the right definition, but it will complain if you make a syntax\n  error. If you are unsure, ask a mentor to check whether your solution is correct.\n-/\n\nstructure const_seq := \n  (seq : ℕ → ℕ)\n  (tends_to : ∃ N v, ∀ n ≥ N, seq n = v) \n\nstructure bipoint :=\n  (A : Type*)\n  (x y : A)\n  (neq : x ≠ y)\n\n\n\n/-! ### Projections of a structure -/\n\n/-! The field names are declared in the namespace of the structure.\n  This means that their names have the form `<structure_name>.<field_name>`. -/\nexample (n : ℕ) (hn : is_even_cube_above_100 n) : n > 100 :=\nis_even_cube_above_100.gt_100 hn\n\n/-! You can also `open` the namespace, to use the abbreviated form.\n  We put this `open` command inside a section, so that the namespace\n  is closed at the end of the `section`. -/\nsection\nopen is_even_cube_above_100\nexample (n : ℕ) (hn : is_even_cube_above_100 n) : n > 100 :=\ngt_100 hn\nend\n\n/-! Another useful technique is to use *projection notation*. Instead of writing\n`is_even_cube_above_100.even hn` we can write `hn.even`.\n  Lean will look at the type of `hn` and see that it is `is_even_cube_above_100 n`.\n  Then it looks for the lemma with the name `is_even_cube_above_100.even` and apply it to `hn`. -/\nexample (n : ℕ) (hn : is_even_cube_above_100 n) : even n :=\nhn.even\n\nexample (n : ℕ) (hn : is_even_cube_above_100 n) : even n ∧ ∃ k, n = k^3 :=\n⟨ hn.even, hn.is_cube ⟩\n\n/-! You can also use `.1`, `.2`, `.3`, ... for the fields of a structure. -/\nexample (n : ℕ) (hn : is_even_cube_above_100 n) : even n ∧ n > 100 ∧ (∃ k, n = k^3) :=\n⟨ hn.1, hn.3, hn.2 ⟩\n\n/-! We could have alternatively stated `is_even_cube_above_100`\n  as a conjunction of three statements, as below.\n  That gives the same proposition, but doesn't give a name to the three components. -/\ndef is_even_cube_above_100' (n : ℕ) : Prop :=\neven n ∧ (∃ k, n = k^3) ∧ n > 100\n\n/-! If we have a structure that mixes data (elements of types, like `ℕ`, `ℝ`, and so on) and\n  properties of the data, we can alternatively declare them using *subtypes*.\n  This consists of pairs of a natural number and a proof that the natural number is even. -/\ndef even_natural_number' : Type :=\n{ n : ℕ // even n }\n\n/-! The notation for subtypes is almost the same as the notation for set comprehension.\n Note that `//` is used for subtypes, and `|` is used for sets. -/\ndef set_of_even_natural_numbers : set ℕ :=\n{ n : ℕ | even n }\n\n/-! We can construct objects of a structure using the *anonymous constructor* `⟨...⟩`.\n  This can construct an object of any structure, including conjunctions,\n  existential statements and subtypes. -/\nexample : even_natural_number → even_natural_number' :=\nλ n, ⟨n.1, n.2⟩\n\nexample (n : ℕ) : is_even_cube_above_100 n → is_even_cube_above_100' n :=\nλ hn, ⟨hn.even, hn.is_cube, hn.gt_100⟩\n\n/-! An alternative way is to use the *structure notation*. The syntax for this is\n  ```\n    { structure_name . field1_name := value, field2_name := value, ... }\n  ```\n  You can prove the fields in any order you want.\n-/\nexample : even_natural_number' → even_natural_number :=\nλ n,\n{ even_natural_number .\n  n      := n.1,\n  even_n := n.2 }\n\n/-! The structure name is optional if the structure in question is clear from context. -/\nexample (n : ℕ) : is_even_cube_above_100' n → is_even_cube_above_100 n :=\nλ ⟨h1n, h2n, h3n⟩,\n{ even    := h1n,\n  is_cube := h2n,\n  gt_100  := h3n }\n\n/-!\n  ### Exercise 2\n  * Define `bounds` (given above) again, but now using a the subtype notation `{ _ : _ // _ }`.\n  * Define functions back and forth from the structure `bounds` given above and `bounds` given here.\n    Try different variations using the anonymous constructor and the projection notation.\n-/\n#print bounds\n\ndef bounds' (f : ℕ → ℕ) : Type :=\n{ n : ℕ // ∀ m : ℕ, f m ≤ n}\n\nexample (f : ℕ → ℕ) : bounds f → bounds' f :=\n λ n, ⟨n.1, n.2⟩\n\n/- In the example below, replace the `sorry` by an underscore `_`.\n  A small yellow lightbulb will appear. Click it, and then select\n  `Generate skeleton for the structure under construction`.\n  This will automatically give an outline of the structure for you. -/\nexample (f : ℕ → ℕ) : bounds' f → bounds f :=\nλ n, { bound := n.1,\n  le_bound := n.2 }\n\n\n/-! Before you continue, watch the second pre-recorded video. -/\n\n/-! ### Classes\nClasses are special kind of types or propositions that Lean will automatically find inhabitants for.\nYou can declare a class by giving it the `@[class]` attribute.\nAs an example, in this section, we will implement square root on natural numbers, that can only be\napplied to natural numbers that are squares. -/\n@[class] def is_nat_square (n : ℕ) : Prop := ∃k : ℕ, k^2 = n\n\nnamespace is_nat_square\n\n/-! Hypotheses with a class as type should be written in square brackets `[...]`.\nThis tells Lean that they are implicit, and Lean will try to fill them in automatically.\nWe define the square root as the (unique) number `k` such that `k^2 = n`. Such `k` exists by the\n`is_nat_square n` hypothesis. -/\ndef sqrt (n : ℕ) [hn : is_nat_square n] : ℕ := classical.some hn\n\nprefix `√`:(max+1) := sqrt -- notation for `sqrt`\n\n/-! The following is the defining property of `√n`. Note that when we write `√n`,\nLean will automatically insert the implicit argument `hn` it found it the context.\nThis is called *type-class inference*.\nWe mark this lemma with the `@[simp]` attribute to tell `simp` to simplify using this lemma. -/\n@[simp] lemma square_sqrt (n : ℕ) [hn : is_nat_square n] : (√n) ^ 2 = n :=\nclassical.some_spec hn\n\n/-! ### Exercise:\n  Fill in all `sorry`s in the remainder of this section.\n-/\n\n/-! Prove this lemma. Again we mark it `@[simp]` so that `simp` can simplify\n  equalities involving `√`. Also, hypotheses in square brackets do not need a name.\n  Hint: use `pow_left_inj` -/\n@[simp] lemma sqrt_eq_iff (n k : ℕ) [is_nat_square n] : √n = k ↔ n = k^2 :=\nbegin\n  split, \n  { intro h, rw ←h, rw square_sqrt,},\n  { intro h, convert (pow_left_inj (by from zero_le √n) (by from zero_le k) (by norm_num : 0 < 2)).mp _, \n    rw square_sqrt, from h,} \nend\n\n/-! To help type-class inference, we have to tell it that some numbers are always squares.\n  Here we show that `n^2` is always a square. We mark it as `instance`, which is like\n  `lemma` or `def`, except that it is automatically used by type-class inference. -/\ninstance square_square (n : ℕ) : is_nat_square (n^2) :=\n⟨n, rfl⟩\n\nlemma sqrt_square (n : ℕ) : √(n ^ 2) = n :=\nby simp\n\n/-! Instances can depend on other instances: here we show that if `n` and `m` are squares, then\n`n * m` is one, too.\nWhen writing `√n`, Lean will use a simple search algorithm to find a proof that `n` is a square, by\nrepeatedly applying previously declared instances, and arguments in the local context. -/\ninstance square_mul (n m : ℕ) [is_nat_square n] [is_nat_square m] : is_nat_square (n*m) :=\n⟨√n * √m, by simp [mul_pow]⟩\n\n/-! Hint: use `mul_pow` -/\n#check mul_pow\nlemma sqrt_mul (n m : ℕ) [is_nat_square n] [is_nat_square m] : √(n * m) = √n * √m :=\nbegin\n   simp [mul_pow],\nend\n\n/-! Note that Lean automatically inserts the proof that `n * m ^ 2` is a square,\n  using the previously declared instances. -/\nexample (n m : ℕ) [is_nat_square n] : √(n * m ^ 2) = √n * m :=\nbegin\n  simp [mul_pow], \nend\n\n\n/-! Hint: use `nat.le_mul_self` and `pow_two` -/ \n#check nat.le_mul_self\n#check pow_two\nlemma sqrt_le (n : ℕ) [is_nat_square n] : √n ≤ n :=\nbegin\n  conv_rhs { rw [←square_sqrt n, pow_two], }, apply nat.le_mul_self,\nend\n\nend is_nat_square\n\n/- At this point, feel free do the remaining exercises in any order. -/\n\n\n/-! ### Exercise: Bijections and equivalences -/\n\nsection bijections\n\nopen function\n\nvariables {α β : Type*}\n\n/-\nAn important structure is the type of equivalences, which gives an equivalence (bijection)\nbetween two types:\n```\nstructure equiv (α β : Type*) :=\n(to_fun    : α → β)\n(inv_fun   : β → α)\n(left_inv  : left_inverse inv_fun to_fun)\n(right_inv : right_inverse inv_fun to_fun)\n```\nIn this section we show that this is the same as the bijections from `α` to `β`.\n-/\n#print equiv\n\nstructure bijection (α β : Type*) :=\n  (to_fun : α → β)\n  (injective : injective to_fun)\n  (surjective : surjective to_fun)\n\n/- We declare a *coercion*. This allows us to treat `f` as a function if `f : bijection α β`. -/\ninstance : has_coe_to_fun (bijection α β) (λ _, α → β) :=\n⟨λ f, f.to_fun⟩\n\n/-! To show that two bijections are equal, it is sufficient that the underlying functions are\n  equal on all inputs. We mark it as `@[ext]` so that we can later use the tactic `ext` to show that\n  two bijections are equal. -/\n@[ext] def bijection.ext {f g : bijection α β} (hfg : ∀ x, f x = g x) : f = g :=\nby { cases f, cases g, congr, ext, exact hfg x }\n\n/-! This lemma allows `simp` to reduce the application of a bijection to an argument. -/\n@[simp] lemma coe_mk {f : α → β} {h1f : injective f} {h2f : surjective f} {x : α} :\n  { bijection . to_fun := f, injective := h1f, surjective := h2f } x = f x := rfl\n\n/- There is a lemma in the library that almost states this.\n  You can use the tactic `suggest` to get suggested lemmas from Lean\n  (the one you want has `bijective` in the name). -/\ndef equiv_of_bijection (f : bijection α β) : α ≃ β :=\n  equiv.of_bijective f ⟨f.injective, f.surjective⟩\n\ndef bijection_of_equiv (f : α ≃ β) : bijection α β :=\n  {\n    to_fun := f,\n    injective := f.injective, \n    surjective := f.surjective,\n  }\n\n/-! Show that bijections are the same (i.e. equivalent) to equivalences. -/\ndef bijection_equiv_equiv : bijection α β ≃ (α ≃ β) :=\n{\n  to_fun := equiv_of_bijection,\n  inv_fun := bijection_of_equiv,\n  left_inv := by {intro f, ext, simp [bijection_of_equiv, equiv_of_bijection]},\n  right_inv := by {intro f, ext, simp [bijection_of_equiv, equiv_of_bijection]},\n}\nend bijections\n\n\n\n/-! ### Exercise: Bundled groups -/\n\n/-! Below is a possible definition of a group in Lean.\n  It's not the definition we use use in mathlib. The actual definition uses classes,\n  and will be explained in detail in the next session. -/\n\nstructure Group :=\n  (G : Type*)\n  (op : G → G → G)\n  (infix * := op) -- temporary notation `*` for `op`, just inside this structure declaration\n  (op_assoc' : ∀ (x y z : G), (x * y) * z = x * (y * z))\n  (id : G)\n  (notation 1 := id) -- temporary notation `1` for `id`, just inside this structure declaration\n  (id_op' : ∀ (x : G), 1 * x = x)\n  (inv : G → G)\n  (postfix ⁻¹ := inv) -- temporary notation `⁻¹` for `inv`, just inside this structure declaration\n  (op_left_inv' : ∀ (x : G), x⁻¹ * x = 1)\n\n/-! You can use the `extend` command to define a structure that adds fields\n  to one or more existing structures. -/\nstructure CommGroup extends Group :=\n  (infix * := op)\n  (op_comm : ∀ (x y : G), x * y = y * x)\n\n/- Here is an example: the rationals form a group under addition. -/\ndef rat_Group : Group :=\n{ G := ℚ,\n  op := (+), -- you can put parentheses around an infix operation to talk about the operation itself.\n  op_assoc' := add_assoc,\n  id := 0,\n  id_op' := zero_add,\n  inv := λ x, -x,\n  op_left_inv' := neg_add_self }\n\n/-- You can extend an object of a structure by using the structure notation and using\n  `..<existing object>`. -/\ndef rat_CommGroup : CommGroup :=\n{ G := ℚ, op_comm := add_comm, ..rat_Group }\n\nnamespace Group\n\nvariables {G : Group} /- Let `G` be a group -/\n\n/- The following line declares that if `G : Group`, then we can also view `G` as a type. -/\ninstance : has_coe_to_sort Group (Type*) := ⟨Group.G⟩\n/- The following lines declare the notation `*`, `⁻¹` and `1` for the fields of `Group`. -/\ninstance : has_mul G := ⟨G.op⟩\ninstance : has_inv G := ⟨G.inv⟩\ninstance : has_one G := ⟨G.id⟩\n\n/- the axioms for groups are satisfied -/\nlemma op_assoc (x y z : G) : (x * y) * z = x * (y * z) := G.op_assoc' x y z\n\nlemma id_op (x : G) : 1 * x = x := G.id_op' x\n\nlemma op_left_inv (x : G) : x⁻¹ * x = 1 := G.op_left_inv' x\n\n/- Use the axioms `op_assoc`, `id_op` and `op_left_inv` to prove the following lemma.\n  The fields `op_assoc'`, `id_op'` and `op_left_inv'` should not be used directly, nor can you use\n  any lemmas from the library about `mul`. -/\nlemma eq_id_of_op_eq_self {G : Group} {x : G} : x * x = x → x = 1 :=\nbegin\n  intro h, rw [←id_op x, ←op_left_inv x, op_assoc, h],\nend\n\n/- Apply the previous lemma to show that `⁻¹` is also a right-sided inverse. -/\nlemma op_right_inv {G : Group} (x : G) : x * x⁻¹ = 1 :=\nbegin\n  apply eq_id_of_op_eq_self,\n  rw [op_assoc, ←op_assoc x⁻¹, op_left_inv, id_op],\nend\n\n/- we can prove that `1` is also a right identity. -/\nlemma op_id {G : Group} (x : G) : x * 1 = x :=\nbegin\n  rw [←op_left_inv x, ←op_assoc, op_right_inv, id_op],\nend\n\n/-!\n  However, it is inconvenient to use this group instance directly.\n  One reason is that to use these group operations we now have to write\n  `(x y : rat_Group)` instead of `(x y : ℚ)`.\n  That's why in Lean we use classes for algebraic structures,\n  explained in the next lecture.\n-/\n\n/- show that the cartesian product of two groups is a group. The underlying type will be `G × H`. -/\n\ndef prod_Group (G H : Group) : Group :=\n{ \n  G := G × H,\n  op := λ p q, (G.op p.1 q.1, H.op p.2 q.2),\n  op_assoc' := by { dsimp, intros x y z, ext,\n                rw G.op_assoc', rw H.op_assoc',},\n  id := (G.id, H.id),\n  id_op' := by {dsimp, intro x, ext, \n                rw G.id_op', rw H.id_op'},\n  inv := λ p, (G.inv p.1, H.inv p.2),\n  op_left_inv' := by { dsimp, intro x, ext,\n                      rw G.op_left_inv', rw H.op_left_inv',},\n}\n\nend Group\n\n\n\n/-! ### Exercise: Pointed types -/\n\nstructure pointed_type :=\n(type : Type*)\n(point : type)\n\nnamespace pointed_type\nvariables {A B : pointed_type}\n\n/- The following line declares that if `A : pointed_type`, then we can also view `A` as a type. -/\ninstance : has_coe_to_sort pointed_type (Type* ):= ⟨pointed_type.type⟩\n\n/- The product of two pointed types is a pointed type.\n  The `@[simps point]` is a hint to `simp` that it can unfold the point of this definition. -/\n@[simps point]\ndef prod (A B : pointed_type) : pointed_type :=\n{ type := A × B,\n  point := (A.point, B.point) }\n\n\nend pointed_type\n\nstructure pointed_map (A B : pointed_type) :=\n(to_fun : A → B)\n(to_fun_point : to_fun A.point = B.point)\n\nnamespace pointed_map\n\ninfix ` →. `:25 := pointed_map\n\nvariables {A B C D : pointed_type}\nvariables {h : C →. D} {g : B →. C} {f f₁ f₂ : A →. B}\n\ninstance : has_coe_to_fun (A →. B) (λ _, A → B) := ⟨pointed_map.to_fun⟩\n\n@[simp] lemma coe_mk {f : A → B} {hf : f A.point = B.point} {x : A} :\n  { pointed_map . to_fun := f, to_fun_point := hf } x = f x := rfl\n@[simp] lemma coe_point : f A.point = B.point := f.to_fun_point\n\n@[ext] protected lemma ext (hf₁₂ : ∀ x, f₁ x = f₂ x) : f₁ = f₂ :=\nbegin\n  cases f₁ with f₁ h1, cases f₂ with f₂ h2, congr, ext x, from hf₁₂ x,\nend\n\n/-! Below we show that pointed types form a category. -/\n\ndef comp (g : B →. C) (f : A →. B) : A →. C :=\n{\n  to_fun := λ x, g.to_fun (f.to_fun x),\n  to_fun_point := by rw [f.to_fun_point, g.to_fun_point],\n}\n\ndef id : A →. A :=\n{\n  to_fun := λ x, x,\n  to_fun_point := by simp,\n}\n\n/-! You can use projection notation for any declaration declared in the same namespace as the\n  structure. For example, `g.comp f` means `pointed_map.comp g f` -/\nlemma comp_assoc : h.comp (g.comp f) = (h.comp g).comp f :=\nbegin \n  ext x, refl,\nend\n\nlemma id_comp : f.comp id = f :=\nbegin \n  ext x, refl,\nend\n\nlemma comp_id : id.comp f = f :=\nbegin \n  ext x, refl,\nend\n\n/-! Below we show that `A.prod B` (that is, `pointed_type.prod A B`) is a product in the category of\n  pointed types. -/\n\ndef fst : A.prod B →. A :=\n{\n  to_fun := λ p, p.1,\n  to_fun_point := by {simp [pointed_type.prod],},\n}\n\ndef snd : A.prod B →. B :=\n{\n  to_fun := λ p, p.2,\n  to_fun_point := by {simp [pointed_type.prod],},\n}\n\ndef pair (f : C →. A) (g : C →. B) : C →. A.prod B :=\n{\n  to_fun := λ c, (f.to_fun c, g.to_fun c),\n  to_fun_point := by {simp [pointed_type.prod, f.to_fun_point, g.to_fun_point],},\n}\n\nlemma fst_pair (f : C →. A) (g : C →. B) : fst.comp (f.pair g) = f :=\nbegin \n  ext x, refl,\nend\n\nlemma snd_pair (f : C →. A) (g : C →. B) : snd.comp (f.pair g) = g :=\nbegin \n  ext x, refl,\nend\n\nlemma pair_unique (f : C →. A) (g : C →. B) (u : C →. A.prod B) (h1u : fst.comp u = f)\n  (h2u : snd.comp u = g) : u = f.pair g :=\nbegin\n  ext x, \n  { have : fst (u x) = f x, { rw [←h1u], simpa [comp],}, simpa using this,},\n  { have : snd (u x) = g x, { rw [←h2u], simpa [comp],}, simpa using this,},\nend\n\n\nend pointed_map\n\n/-! As an advanced exercise, you can show that the category of pointed type has coproducts.\n  For this we need quotients, the basic interface is given with the declarations\n  `quot r`: the quotient of the equivalence relation generated by relation `r` on `A`\n  `quot.mk r : A → quot r`,\n  `quot.sound`\n  `quot.lift` (see below)\n  -/\n\n#print quot\n#print quot.mk\n#print quot.sound\n#print quot.lift\n\nopen sum\n\n/-! We want to define the coproduct of pointed types `A` and `B` as the coproduct `A ⊕ B` of the\n  underlying type, identifying the two basepoints.\n  First define a relation that *only* relates `inl A.point ~ inr B.point`.\n-/\ndef coprod_rel (A B : pointed_type) : (A ⊕ B) → (A ⊕ B) → Prop :=\n  λ x y, x = inl A.point ∧ y = inr B.point\n\nnamespace pointed_type\n\n-- @[simps point]\n\ndef coprod (A B : pointed_type) : pointed_type :=\n{ \n  type := quot (coprod_rel A B),\n  point := quot.mk _ (inl A.point),\n}\n\nend pointed_type\n\nnamespace pointed_map\n\nvariables {A B C D : pointed_type}\n\ndef inl : A →. A.coprod B :=\n{\n  to_fun := λ x, quot.mk _ (inl x),\n  to_fun_point := by {refl},\n}\n\ndef inr : B →. A.coprod B :=\n{\n  to_fun := quot.mk _ ∘ sum.inr,\n  to_fun_point := by { refine (quot.sound _).symm, from ⟨rfl, rfl⟩, }, \n}\n\n\nend pointed_map", "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/01_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.794011640174588}}
{"text": "open nat\n\ninductive ev : ℕ → Prop\n| ev_0 : ev 0\n| ev_SS : ∀ n : ℕ, ev n → ev (succ (succ n))\n\nopen ev\n\n-- Exercise: 1 star (ev_double)\ntheorem ev_double : ∀ n, ev (2 * n) :=\nλ n, nat.rec_on n  \n  (by rw mul_zero; constructor)\n  (λ k ih, \n    begin \n      rw [two_mul, add_succ, succ_add], \n      constructor, \n      rwa [←two_mul]\n    end)\n\ntheorem ev_minus2 : ∀ n, ev n → ev (pred (pred n)) := \nbegin\n  intros n h,\n  cases h with n h₁,\n    rwa [pred_zero, pred_zero],\n    rwa [pred_succ, pred_succ]\nend\n\n-- Exercise: 1 star (SSSSev__even)\ntheorem SSSSev_even : ∀ n, ev (succ (succ (succ (succ n)))) → ev n := \nbegin \n  introv h,\n  induction n with n' ih,\n    constructor,\n    cases h with _ h,\n    cases h with _ h,\n    assumption\nend\n\n-- Exercise: 4 stars, advanced (subsequence)\ninductive subseq {α : Type} : list α → list α → Prop\n| nil : ∀ (l : list α), subseq [] l\n| cons₁ : ∀ (x : α) (l₁ l₂ : list α), subseq l₁ l₂ → subseq (x :: l₁) (x :: l₂)\n| cons₂ : ∀ (x : α) (l₁ l₂ : list α), subseq l₁ l₂ → subseq l₁ (x :: l₂) \n\nsection subseq \nvariables {α : Type} (l₁ l₂ : list α)\n\ntheorem subseq_refl : reflexive (@subseq α) := \nbegin \n  unfold reflexive,\n  intro l,\n  induction l with a l' ih,\n    constructor,\n    exact (subseq.cons₁ a l' l' ih)\nend\n\nend subseq", "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/indprop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191259110588, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7940068499870606}}
{"text": "/-\nCS 2120 F22 Homework #4. Due Oct 13.\n-/\n\n/- #1A [10 points]\n\nWrite a formal proposition stating that \nlogical and (∧) is associative. That is, \nfor arbitrary propositions, P, Q, and R,\nP ∧ (Q ∧ R) is true *iff* (P ∧ Q) ∧ R is, \ntoo. Replace the placeholder (_) with your\nanswer.\n-/\n\ndef and_associative : Prop := \n  ∀ (P Q R : Prop), \n    (P ∧ Q) ∧ R ↔ P ∧ (Q ∧ R) \n\n\n/- #1B [10 points]\n\nGive an English language proof. Identify\nthe inference rules of predicate logic\nthat you use in your reasoning.\n-/\n\n/-\nAnswer: \n-/\n\n/- #1C [5 points]\n\nGive a formal proof of the proposition.\nHint: unfold and_associative to start.\n-/\n\ntheorem and_assoc_true : and_associative :=\nbegin\nunfold and_associative,\nassume P Q R,\napply iff.intro _ _,\n\n-- forward\nassume h,\n\n/-\nlet pq : P ∧ Q := and.elim_left h,\nlet r : R := and.elim_right h,\nlet p : P := and.elim_left pq,\nlet q : Q := and.elim_right pq,\n-/\n\ncases h with pq r,\ncases pq with p q,\n\n/-\napply and.intro _ _,\ncases h with pq r,\ncases pq with p q,\nexact p,\napply and.intro _ _,\nexact and.elim_right(and.elim_left h),\nexact (and.elim_right h),\n-/\n\n/-\ncases h with pq r,\ncases pq with p q,\n-/\napply and.intro p (and.intro q r),\n\n-- Reverse\nassume h,\ncases h with p qr,\ncases qr with q r,\nexact (and.intro (and.intro p q) r),\nend\n\n\n\n\n/- #2A [10 points]\n\nWrite the proposition that ∨ is associative.,\nanalogous to the proposition about ∧ in #1.\n-/\n\ndef or_associative : Prop := \n  ∀ (P Q R : Prop), P ∨ (Q ∨ R) ↔ (P ∨ Q) ∨ R\n\n\n/- #2B [10 points]\n\nWrite an English language proof of it, citing\nthe specific inference rules you use in your\nreasoning.\n-/\n\n\n/- #2C [5 points]\n\nComplete the following formal proof.\n-/\n\ntheorem or_associative_true : or_associative :=\nbegin\nunfold or_associative,\nassume P Q R,\n\n\napply iff.intro _ _,\n\n-- forward\nassume h,\napply or.elim h _ _,\n\n-- case P\nassume p,\napply or.inl _,\nexact (or.inl p), \n\n-- case Q or R\nassume qr,\napply or.elim qr _ _,\n\n-- case Q\nassume q,\napply or.inl _,\nexact (or.inr q),\n\n-- case R\nassume r,\napply or.inr r,\n\n-- reverse\n \n-- TO DO\n\nend\n\n\n/- #3A [10 points]\nWrite a formal statement of the proposition.\n-/\n\ndef arrow_transitive : Prop :=\n  ∀ (P Q R : Prop), (P → Q) → (Q → R) → (P → R)\n\n\n/- #3B [10 points]\n\nWrite an English language proof of the proposition\nthat for any propositions, X, Y, and X, it's the\ncase that (X → Y) → (Y → Z) → (X → Z). In other\nwords, implication is \"transitive.\" Hint: Recall\nthat if you have a proof of, say, X → Y, and you \nhave a proof of X, you can derive a proof of Y by\narrow elimination. Think of it as applying a proof\nof an implication to a proof of its premise to get\nyourself a proof of its conclusion.\n-/\n\n\n/- #3C [5 points]. \nWrite a formal proof of it.\n-/\n\nexample : arrow_transitive :=\nbegin\n  unfold arrow_transitive,\n  assume P Q R,\n  assume pq : P → Q,\n  assume qr : Q → R,\n  assume p : P,\n  let q : Q := (pq p),\n  let r : R := (qr q),\n  -- assumption,\n  -- apply r,\n  exact r,\nend \n\n\n/- #4\nSuppose that if it's raining then the streets\nare wet. This problem requires you to prove that\nif the streets are not wet then it's not raining.\n-/\n\n/- #4A [10 points]\n\nStart by writing the proposition in predicate\nlogic by completing the following answer.\n-/\n\ndef contrapositive : Prop :=\n  ∀ (Raining Wet : Prop), \n    (Raining → Wet) → (¬Raining → ¬Wet)\n\n/-\nThe proposition defined here isn't valid. It's\none of the classical fallacies, one that we saw\nstarting with propositional logic. Contrapositive\nsays if (R → W) → (¬W → ¬R). Consider a concrete\ncase: If whenever it rains R, the streets are wet\n(W), then if the streets are not wet (¬W) then it\nmust not be raining (¬R).\n-/\n\ndef contrapositive_corrected : Prop :=\n  ∀ (Raining Wet : Prop), \n    (Raining → Wet) → (¬Wet → ¬Raining)\n\n/- #4B [10 points]. \n-/\n\ntheorem contrapositive_valid : contrapositive_corrected :=\nbegin\nunfold contrapositive_corrected,\nassume R W h,\nassume nw,\nassume r,\nlet w := h r,\ncontradiction,\nend\n\n/- #4C [5 points]. \n\nGive an English language proof of it.\n-/\n\n\n/- #5. Extra credit.\n\nComplete the following formal proof of the \nproposition that if for any proposition P, \nP ∨ ¬P is true, then for any propositions, \nX and Y, if it's not the case that X or Y\nis true then it is the case that ¬X and ¬Y \nis true. \n-/\n\ntheorem demorgan1 : \n  (∀ (P : Prop), P ∨ ¬ P) → \n    ∀ (X Y : Prop), \n      ¬(X ∨ Y) → (¬X ∧ ¬Y) :=\nbegin\nassume em X Y nxory,\ncases (em X) with x nx,\n\n-- case where X is true\nlet xory : X ∨ Y := or.inl x,\ncontradiction,\n\n-- case where X is false\ncases (em Y) with y ny,\n\n  -- case where Y is true\nlet xory : X ∨ Y := or.inr y,\ncontradiction,\n\n  -- case where Y is false\napply and.intro nx ny,\n\nend\n\n/- OPTIONAL, NOT NECESSARY FOR MIDTERM EXAM\n\nA comment on or.intro_left and or.intro_right.\nIn Lean each of these takes two arguments: a\nproof of the disjunct -- the proposition on \none side of the ∨ -- that is to be proven true, \n*and* it takes as an argument the proposition \nthat is not being proven true. In applications \nof these rules the proposition argument (not \nbeing proven) comes first, while the proof \nargument comes second.\n\nThe reason is that Lean needs to know what \noverall proposition is being proved. From the\nproof argument it can infer the proposition \nbeing proved, but it needs the other proposition\nas well to know the full (X ∨ Y) disjunction to\nbe proved. \n\nHere's an example:\n-/\n\nexample : 0 = 0 ∨ 0 = 1 :=\nbegin\napply or.intro_left (0 = 1) rfl\n/-\nThe \"rfl\" serves as a proof of 0=0.\nBut in addition, as the first argument\nto or.intro, we need to provide the\n*proposition* that is not being proved.\nHere's that's (0 = 1). In contexts\nwhere Lean can infer both disuncts,\nyou can use the simpler or.inl or \nor.inr, each of which just takes one\nargument: a proof of the left or of \nthe right side, respectively.\n-/\nend\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/homeworks/hw4/hw4_key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.8902942217558213, "lm_q1q2_score": 0.7939742129714161}}
{"text": "-- vim: ts=2 sw=0 sts=-1 et ai tw=70\n\nimport .prime\nimport .induction\n\nnamespace hidden\n\nnamespace mynat\n\ndef even (m: mynat) := 2 ∣ m\ndef odd (m: mynat) := ¬even m\n\nvariables {m n k p: mynat}\n\ntheorem even_zero: even 0 :=\nbegin\n  existsi (0: mynat),\n  simp,\nend\n\ntheorem odd_one: odd 1 :=\nbegin\n  assume he1,\n  have h21 := dvd_one he1,\n  cases h21,\nend\n\ntheorem two_only_even_prime: prime m → 2 ∣ m → m = 2 :=\nbegin\n  assume hmpm h2dm,\n  cases h2dm with n hn,\n  cases m,\n  rw zz at *,\n  exfalso, from zero_nprime hmpm,\n  have hndvds: n ∣ succ m,\n    rw hn,\n    apply dvd_mul, refl,\n  cases hmpm with hsneq1 hdiv,\n  have h₂ := hdiv n hndvds,\n  cases h₂,\n    rw [h₂, one_mul] at hn,\n    assumption,\n  exfalso,\n  rw h₂ at hn,\n  have hcancel :=\n    mul_cancel_to_one succ_ne_zero,\n  cases hcancel hn,\nend\n\ntheorem even_add_even:\neven m → even n → even (m + n) :=\nbegin\n  assume hm hn,\n  from dvd_sum hm hn,\nend\n\ntheorem even_remainder (m k n : mynat):\neven m → even n → m + k = n → even k :=\nbegin\n  assume hm hn h,\n  from dvd_remainder _ _ _ _ hm hn h,\nend\n\ntheorem even_add_odd:\neven m → odd n → odd (m + n) :=\nbegin\n  assume hm hn heven,\n  have : even n, {\n    apply even_remainder m n (m + n) hm heven,\n    refl,\n  },\n  contradiction,\nend\n\ntheorem odd_add_even:\nodd m → even n → odd (m + n) :=\nbegin\n  assume hom hen,\n  rw add_comm,\n  from even_add_odd hen hom,\nend\n\ntheorem succ_even_is_odd: even m → odd (succ m) :=\nbegin\n  assume hem hesm,\n  cases hem with a ha,\n  cases hesm with b hb,\n  rw ha at hb,\n  have he1: even 1, {\n    have h2dvda2: 2 ∣ a * 2 := dvd_multiple,\n    have h2dvdb2: 2 ∣ b * 2 := dvd_multiple,\n    from dvd_remainder _ 1 _ _ h2dvda2 h2dvdb2 hb,\n  },\n  from odd_one he1,\nend\n\ntheorem odd_periodic: odd m ↔ odd (m + 2) :=\nbegin\n  split, {\n    assume hom hem2,\n    from hom (dvd_cancel hem2),\n  }, {\n    assume hom2 hem,\n    from hom2 (dvd_add hem),\n  },\nend\n\ntheorem even_periodic: even m ↔ even (m + 2) :=\nbegin\n  split, {\n    assume hem,\n    from dvd_add hem,\n  }, {\n    assume hem2,\n    from dvd_cancel hem2,\n  },\nend\n\n-- is this overkill?\ntheorem succ_odd_is_even: odd m → even (succ m) :=\nbegin\n  assume hom,\n  apply strong_induction  (λ m, odd m → even (succ m)), {\n    assume ho0,\n    exfalso,\n    from ho0 even_zero,\n  }, {\n    intro n,\n    assume h_ih,\n    assume hosn,\n    cases n, {\n      existsi (1: mynat),\n      refl,\n    }, {\n      have hon := odd_periodic.mpr hosn,\n      have hesn := h_ih n (le_to_add: n ≤ n + 1) hon,\n      from even_periodic.mp hesn,\n    },\n  },\n  assumption,\nend\n\ninstance even_decidable: ∀ m : mynat, decidable (even m) :=\nbegin\n  intro m,\n  induction m with m hm, {\n    from is_true even_zero,\n  }, {\n    cases hm, {\n      from is_true (succ_odd_is_even hm),\n    }, {\n      from is_false (succ_even_is_odd hm),\n    },\n  },\nend\n\ntheorem cancel_succ_even: even (succ m) → odd m :=\nbegin\n  assume hesm,\n  cases m, {\n    exfalso,\n    from odd_one hesm,\n  }, {\n    apply succ_even_is_odd,\n    rw even_periodic,\n    assumption,\n  },\nend\n\ntheorem cancel_succ_odd: odd (succ m) → even m :=\nbegin\n  assume hosm,\n  cases m, {\n    from even_zero,\n  }, {\n    apply succ_odd_is_even,\n    rw odd_periodic,\n    assumption,\n  },\nend\n\ntheorem odd_periodic_lots: even m → odd (n + m) → odd n :=\nbegin\n  assume hem honm hen,\n  from honm (even_add_even hen hem),\nend\n\ntheorem even_periodic_lots: even m → even (n + m) → even n :=\nbegin\n  assume hem honm,\n  cases hem with k hk,\n  rw hk at honm,\n  rw mul_comm at honm,\n  from dvd_cancel_lots honm,\nend\n\ntheorem odd_add_odd: odd m → odd n → even (m + n) :=\nbegin\n  assume hom hon,\n  have hesm := succ_odd_is_even hom,\n  have hesn := succ_odd_is_even hon,\n  have hesmsn := even_add_even hesm hesn,\n  simp at hesmsn,\n  rw even_periodic,\n  from hesmsn,\nend\n\ntheorem even_mul: even m → even (m * n) :=\nbegin\n  assume hm,\n  cases hm with a ha,\n  existsi a * n,\n  rw ha,\n  ac_refl,\nend\n\ntheorem even_mul_even: even m → even n → even (m * n) :=\nbegin\n  assume hem _,\n  from even_mul hem,\nend\n\ntheorem odd_mul_odd:\nodd m → odd n → odd (m*n) :=\nbegin\n  assume hom hon heven,\n  have hesm := succ_odd_is_even hom,\n  have hesn := succ_odd_is_even hon,\n  have hesmsn := even_mul_even hesm hesn,\n  rw mul_succ at hesmsn,\n  rw succ_mul at hesmsn,\n  rw succ_add at hesmsn,\n  have homn := cancel_succ_even hesmsn,\n  rw ←add_assoc at homn,\n  have hemn: even (m + n), {\n    have hesmpsn := even_add_even hesm hesn,\n    simp at hesmpsn,\n    from even_periodic.mpr hesmpsn,\n  },\n  rw add_comm m at homn,\n  rw add_assoc at homn,\n  have homn' := odd_periodic_lots hemn homn,\n  from homn' heven,\nend\n\n-- basically we can do excluded middle without any of the classical\ntheorem even_square: even (m * m) → even m :=\nbegin\n  by_cases (even m), {\n    assume _,\n    assumption,\n  }, {\n    assume hem2,\n    exfalso,\n    from odd_mul_odd h h hem2,\n  },\nend\n\n-- this is awful\ntheorem sqrt_2_irrational: ¬(m ≠ 0 ∧ ∃ n, n * n = 2 * m * m) :=\nbegin\n  -- for some reason this is a recurring lemma here\n  -- is there some way to just do this inline?\n  have h20: (2: mynat) ≠ 0, {\n    assume h, cases h,\n  },\n  apply infinite_descent (λ m, m ≠ 0 ∧ ∃ n, n * n = 2 * m * m),\n  intro k,\n  assume h_desc,\n  cases h_desc with hknz h_desc,\n  cases h_desc with n hn2k2,\n  -- this also comes up a lot\n  have hnn0: n ≠ 0, {\n    assume hn0,\n    simp [hn0] at hn2k2,\n    rw mul_comm at hn2k2,\n    rw mul_comm 2 at hn2k2,\n    from h20 (mul_integral hknz (mul_integral hknz hn2k2.symm)),\n  },\n  have h2dvdn: 2 ∣ n, {\n    have h2dvdn2: 2 ∣ n * n, {\n      existsi k * k,\n      rw hn2k2,\n      ac_refl,\n    },\n    from even_square h2dvdn2,\n  },\n  cases h2dvdn with k' hk',\n  existsi k',\n  split, split, {\n    assume hk'0,\n    simp [hk'0] at hk',\n    from hnn0 hk',\n  }, {\n    rw hk' at hn2k2,\n    existsi k,\n    apply mul_cancel h20,\n    rw [←mul_assoc, ←hn2k2],\n    rw mul_comm 2 _,\n    conv {\n      to_rhs,\n      rw mul_assoc,\n      congr,\n      rw mul_comm,\n    },\n  }, {\n    conv at hn2k2 {\n      rw hk',\n      congr,\n        rw mul_comm k',\n        rw mul_assoc,\n        skip,\n      rw mul_assoc,\n    },\n    have h₂ := mul_cancel h20 hn2k2,\n    conv at h₂ {\n      to_lhs,\n      rw [mul_comm, mul_assoc],\n    },\n    suffices : k'*k' < k*k, {\n      apply lt_sqrt this,\n    },\n    -- TODO: write a separate theorem here\n    assume hk2k'2,\n    cases hk2k'2 with d hd,\n    rw hd at h₂,\n    have hk2e0: k * k = 0, {\n      have h211: (2: mynat) = 1 + 1, refl,\n      rw [h211, add_mul, one_mul, add_assoc] at h₂,\n      have h' := add_cancel_to_zero h₂.symm,\n      rw [add_comm, add_assoc] at h',\n      from add_integral h',\n    },\n    from hknz (mul_integral hknz hk2e0),\n  },\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7939395047214735}}
{"text": "/-\nWe can import definitions from another\nfile. Here we import our definitions from\nthe mynat.lean file. The dot (.) tells \nLean to look for that file in the same\ndirectory  as this file.\n-/\nimport .mynat\n\n/-\nOpen the mynat namespace (in that file)\nso that we don't have to prefix names \nwith mynat.\n-/\nopen mynat\n\n\n-- Create a namespace for this file\nnamespace my_list_adt\n\n/-\nWe now introduce a type of \"lists that\ncontain objects of some other type, T.\"\nFor example, an object of type \"my_list \nℕ\" would represent a list of value of\ntype ℕ, while an object of type \"my_list\nbool\" would represent a list of values\nof type bool. Here's the \"inductive\" \ndeclaration. Notice that, in constrast\nto nat and bool, this declaration has\na parameter, T. \n-/\n\ninductive my_list (T: Type) : Type\n\n/-\nNow think about the type of my_list. Its\ntype is Type → Type. We call my_list a \ntype constructor or a polymorphic type. \nIt takes a type as an argument and then\nreturns a type, specialized for elements\nof the given type, as a result. \n\nGeneric types in Java and template types\nin C++ similarly take type parameters and\nyield new types specialized for handling\nof values of the specified argument type.\n\nNow we give the constructors for our \npolymorphic type. The first one, my_nil,\nis a constant term of type (my_list T). \nWe will interpret it as representing the \n\"empty list of values of type T.\"\"\n-/\n\n| nil: my_list\n\n/-\nAnd here's the interesting part. We now\nprovide my_cons as a constructor used to\nproduce a bigger list from a given list\nby tacking a new value onto its front. \n\nThe constructor takes a value, h (short \nfor \"head\"), of type T, the value to be \ntacked on; and then it takes a value, t \n(short for tail), the smaller list onto\nwhich h will be tacked. The result is a\nnew my_list, represented by the term, \n(my_cons h t), which we interpret as the\nlist starting with h as the value at its\nhead, wand ith the whole smaller list, \nt, as its tail (the rest of the list).\n-/\n\n| cons: T → my_list → my_list \n\nopen my_list\n\n\n/-\nEXAMPLES: \n* list of mynat\n* list of ℕ\n* list of bool\n-/\n\n-- some lists of mynat values\n\ndef empty_mynat_list : my_list mynat := \n    (nil mynat) -- []\n\n#reduce empty_mynat_list\n\ndef zero_mynat_list := \n    (cons zero empty_mynat_list) -- [0]\n\n#reduce zero_mynat_list\n\ndef one_mynat_list :=\n    (cons one zero_mynat_list) -- [1,0]\n\n#reduce one_mynat_list\n\ndef two_mynat_list :=\n    (cons two one_mynat_list) -- [2,1,0]\n\n-- A list of ℕ values! [2,1,0]\n\ndef two_nat_list :=\n    (cons 2 \n    (cons 1 \n    (cons 0 \n    (nil ℕ))))\n\n#reduce two_nat_list\n\n\n-- A list of bool values [tt,ff,tt]\n\ndef a_bool_list :=\n    (cons tt\n    (cons ff \n    (cons tt \n    (nil bool))))\n\n/-\nAdding functions to our algebra\n-/\n\n-- If list is empty return true else false\ndef isNil { T : Type } (l : my_list T) : bool :=\n    match l with\n    | (nil T) := tt\n    | _ := ff\n    end\n\n#reduce isNil a_bool_list\n#reduce isNil empty_mynat_list\n\n/-\nNote that T is an implicit parameter here. Lean\ncan infer T from l.\n-/\n\n-- Length of l. A recursive function.\ndef length : ∀ { T : Type }, my_list T → ℕ \n| _ (nil T) := 0\n| _ (cons h t) := 1 + (length t)\n\n/-\nIn the pattern matches here, Lean requires \nthat we match on both arguments, but we do\nnot want to give a new name to T, so we use\n_ as a wildcard. We can then use the T that\nis declared on the first line as a value in\nthe pattern for the nil list.\n-/\n\n#reduce length empty_mynat_list\n#reduce length a_bool_list\n\n-- Append two lists\n\ndef append : \n    ∀ { T : Type }, \n        my_list T → my_list T → my_list T\n| _ (nil T) l2 := l2\n| _ (cons h t) l2 := cons h (append t l2)\n\n\n#reduce a_bool_list\n#reduce append a_bool_list a_bool_list\n\n\n\n/-\nPROOFS!\n-/\n\n-- Here's one, no induction needed\ntheorem nil_append_left_zero :\n    ∀ { T : Type },\n    ∀ l2 : my_list T,\n    append (nil T) l2 = l2 := \nbegin\nintro T,\nintro l2,\n-- simplify using rules for append\nsimp [append],  \nend\n\n-- But this requires induction\ntheorem nil_append_right_zero :\n    ∀ { T : Type },\n    ∀ l1 : my_list T,\n    append l1 (nil T) = l1\n:=\nbegin\nintro T,\nintro l1,\ninduction l1,\n\n-- base case\nsimp [append],\n\n-- inductive case\nsimp [append],\nassumption,\nend\n\n\n-- A desired property of append!\n\ntheorem append_length :\n    ∀ { T : Type },\n    ∀ l1 l2 : my_list T,\n    length (append l1 l2) = \n    (length l1) + (length l2) :=\nbegin\nintros T l1 l2,\n--cases l1 with h l1' --no work!\ninduction l1 with h l1 ih, -- need ih\n\n/-\nbase case: simplify using \ndefinitions of length, append\n-/\nsimp [append, length],\n\n-- inductive case\n\n-- simplify goal as usual\nsimp [append, length],\n\n-- critical: rewrite using ih!!!\nrw ih,\n\n/-\nSee if Lean can figure out to\nfigure out to apply commutativity \nof addition.  \n-/\nsimp,\n\n-- yay, qed!\nend\n\nend my_list_adt", "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/14.Inductive_Definitions/Data_Types/mylist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8872046041554923, "lm_q1q2_score": 0.79386132660851}}
{"text": "-- Math 52: Cheatsheet\n\n--------------------------------\n-- BASIC GOAL TRANSFORMATIONS --\n--------------------------------\n\n-- Conjunctive Goal\n-- Use `split`:\nexample (P Q : Prop) : P ∧ Q :=\nbegin\nsplit,\n-- you can use braces to separate the two resulting goals\n{ sorry },\n{ sorry },\nend\n\n-- Conditional Goal\n-- Use `intro`:\nexample (P Q : Prop) : P → Q :=\nbegin\nintro H, -- you can give the hypothesis any name you want\nsorry,\nend\n\n-- Universal Goal\n-- Use `intro`:\nexample (U : Type) (P : U → Prop) : ∀ (x : U), P x :=\nbegin\nintro x, -- you can rename the variable x if necessary\nsorry,\nend\n\n-- Existential Goal\n-- Use `existsi`:\nexample (U : Type) (P : U → Prop) : ∃ (x : U), P x :=\nbegin\nexistsi (sorry : U), -- you need to figure out what to put in\nsorry,\nend\n\n---------------------------------\n-- BASIC GIVEN TRANSFORMATIONS --\n---------------------------------\n\n-- Conjunctive Hypothesis\n-- Use `cases`:\nexample (P Q R : Prop) (H : P ∧ Q) : R :=\nbegin\ncases H with H₁ H₂,\nsorry,\nend\n\n-- Disjunctive Hypothesis\n-- Use `cases`:\nexample (P Q R : Prop) (H : P ∨ Q) : R :=\nbegin\ncases H with H₁ H₂,\n-- you can use braces to separate the two resulting goals.\n{ sorry },\n{ sorry },\nend\n\n-- Existential Hypothesis\n-- Use `cases`:\nexample (U : Type) (P : U → Prop) (R : Prop)\n  (H : ∃ (x : U), P x) : R :=\nbegin\ncases H with x Hx, -- you can use any name you want for x\nsorry,\nend\n\n-----------------------\n-- COMMON IDENTITIES --\n-----------------------\n\n#check add_assoc -- (a + b) + c = a + (b + c)\n#check add_comm -- a + b = b + a\n#check add_zero -- a + 0 = a\n#check zero_add -- 0 + a = a\n#check mul_assoc -- (a * b) * c = a * (b * c)\n#check mul_comm -- a * b = b * a\n#check mul_one -- a * 1 = a\n#check one_mul -- 1 * a = a\n#check mul_zero -- a * 0 = 0\n#check zero_mul -- 0 * a = 0\n#check add_mul -- (a + b) * c = a * c + b * c\n#check mul_add -- a * (b + c) = a * b + a * c\n\n", "meta": {"author": "UVM-M52", "repo": "week04-anniekf0204", "sha": "f99265fbd49e5dac7c7ea578ca3f6f57289a7052", "save_path": "github-repos/lean/UVM-M52-week04-anniekf0204", "path": "github-repos/lean/UVM-M52-week04-anniekf0204/week04-anniekf0204-f99265fbd49e5dac7c7ea578ca3f6f57289a7052/src/cheatsheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7936849384765556}}
{"text": "import lib.m154\n\nopen m154\n/-\nNégations, raisonnements par l'absurde et contraposées.\n\nCette feuille introduit les principes logiques et commandes Lean liées\naux négations d'énoncés. Elle introduit de nombreuses nouvelles commandes :\n`Montrons une contradiction`, `Supposons par l'absurde`, `On contrapose`, \n`On discute selon que` et `On pousse la négation`.\nIl est donc important de bien s'accrocher à son aide-mémoire Lean.\n\nOn introduit l'idée de contradiction mathématique ou absurdité mathématique,\nsous la forme d'un énoncé spécial appelé « Faux » et noté `false` par Lean.\nPar définition, cet énoncé n'a pas de démonstration.\n\nPar conséquent, Faux entraîne n'importe quel autre énoncé : pour tout énoncé P,\n« Faux ⇒ P » est vrai : « si Faux alors P » ne coûte rien puisque Faux n'est\npas vrai. Une autre façon d'y penser est de se dire, comme Lean le fait,\nqu'une démonstration de « Faux ⇒ P » est une machine qui transforme toute\ndémonstration de Faux en démonstration de P, et la machine qui ne fait rien\nconvient car nous n'avons rien à lui donner en entrée.\n\nLes logiciens aiment appeler cette implication de son nom latin\n« ex falso quod libet » (du faux découle tout ce que l'on veut).\nLa commande pour invoquer ce principe est `Montrons une contradiction`.\n-/\n\n-- Montrons que si Faux alors 0 = 1\nexample : false → 0 = 1 :=\nbegin\n  -- Supposons Faux\n  Supposons h : false,\n  -- On veut montrer 0 = 1. Ex falso quod libet, donc il suffit de montrer Faux.\n  Montrons une contradiction,\n  -- Or c'est ce que nous avons supposé.\n  On conclut par h,\nend\n\n/-\nL'exemple précédent suggère que la définition de Faux n'est pas très utile.\nMais c'est sur elle que va s'appuyer la définition de la négation.\nSi P est un énoncé, sa négation est l'énoncé « non P » défini comme\n« P ⇒ Faux». Les logiciens et Lean le notent `¬ P` (mais en maths quotidiennes\non n'utilise pas de notation ici).\n\nAinsi l'affirmation « non P » se lit : « Si P était vrai, on aurait une\ncontradiction ». Par exemple, la définition de « a ≠ b » est « non (a = b) ».\n\nOn peut montrer que « non P » est vrai si et seulement si « P ⇔ Faux » est vrai,\nmais en pratique c'est vraiment la définition de « non P » qui est directement\nutile.\n-/\n\n-- Soit x un réel. Montrons que « non x < x ».\nlemma non_strictement_inferieur_soi {x : ℝ} : ¬ x < x :=\nbegin\n  -- Suppons x < x et démontrons une contradiction.\n  Supposons hyp : x < x,\n  -- L'hypothèse x < x signifie que x ≤ x et x ≠ x\n  On réécrit via lt_iff_le_and_ne dans hyp,\n  -- en particulier x ≠ x\n  Par hyp on obtient (hyp_inf : x ≤ x) (hyp_non : x ≠ x),\n  -- (l'autre condition ne servira pas).\n  On oublie hyp_inf, -- La commande \"On oublie\"\" oublie une hypothèse, \n  -- Lean n'en a pas besoin, c'est juste pour nous clarifier les idées.\n  -- Par définition de ≠, l'hypothèse hyp_non signifie que, pour obtenir une\n  -- contradiction, il suffit de montrer que x = x.\n  On reformule hyp_non en x = x → false,\n  -- (La commande \"On reformule\" transforme une hypothèse en un énoncé\n  --  équivalent par définition, Lean n'en a pas besoin ici, c'est juste\n  --  pour nous)\n  Par hyp_non il suffit de montrer que x = x,\n  -- Or cela découle de la réflexivité de l'égalité.\n  On calcule, \nend\n\n-- Soit n un entier. On suppose que n est pair et que n n'est pas pair.\n-- Montrons alors que 0 = 1.\nexample (n : ℤ) (h_pair : pair n) (h_non_pair : ¬ pair n) : 0 = 1 :=\nbegin\n  sorry\nend\n\n/-\nPour la suite, on rappelle les définitions suivantes :\n\n`def pair (n : ℤ) := ∃ k, n = 2*k`\n`def impair (n : ℤ) := ∃ k, n = 2*k + 1`\n\net on a les deux lemmes :\n\n`pair_ou_impair (n : ℤ) : pair n ∨ impair n`\n`non_pair_et_impair (n : ℤ) : ¬ (pair n ∧ impair n)`\n-/\n\n-- Sans utiliser la définition de pair et impair, mais en utilisant les\n-- deux lemmes, montrons qu'un nombre n'est pas pair ssi il est impair.\nlemma non_pair_ssi (n : ℤ) : ¬ pair n ↔ impair n :=\nbegin\n  sorry\nend\n\n/-\nMuni de la définition de la négation, on montre facilement que\ntout énoncé P implique sa double négation « non non P ».\n\nEn rajoutant l'axiome du tiers exclu, qui affirme que « P ou non P » est vrai\npour tout énoncé P, on montre facilement la réciproque : « non non P »\nimplique P.\n\nAu final on a alors l'équivalence entre « non non P » et P, une propriété\nconnue sous le nom de « principe d'élimination des doubles négations ».\n\nL'implication « non non P ⇒ P » est la base du raisonnement par l'absurde :\npour montrer P, il suffit de montrer « non non P », c'est-à-dire\n« non P ⇒ Faux » donc il suffit de supposer « non P » et de démontrer Faux.\nEn pratique on ne décompose pas ce petit raisonnement et on écrit directement\n« Par l'absurde, supposons non P » ou « Supposons par l'absurde non P ». \nDans Lean on écrit `Supposons par l'absurde Hyp : ¬ P`,\nqui transforme le but P en false et ajoute au contexte l'hypothèse Hyp : ¬ P.\n-/\n\n/-\nReprenons une démonstration de la feuille 8, l'unicité de la limite.\nOn ne peut pas démontrer ce résultat sans utiliser l'axiome du tiers exclu\nquelque part. Dans la feuille 8, cette utilisation était cachée dans le lemme\n\n`egal_si_abs_eps (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y`\n\n(dont on démontrera une variante plus bas à l'aide du tiers exclu).\n-/\nexample (u : ℕ → ℝ) (l l' : ℝ) : limite_suite u l → limite_suite u l' → l = l' :=\nbegin\n  -- Supposons que u tende vers l et vers l'\n  Supposons (hl : limite_suite u l) (hl' : limite_suite u l'),\n  -- Supposons par l'absurde que « non (l = l') », c'est à dire l ≠ l'.\n  Supposons par l'absurde H : l ≠ l',\n  -- En particulier |l-l'| > 0\n  Fait ineg : |l - l'| > 0,\n    -- (la démonstration ci-dessous n'est pas importante, il faut juste noter\n    -- qu'elle fait bien intervenir l'hypothèse H)\n    On réécrit via pos_abs,\n    On conclut par sub_ne_zero_of_ne appliqué à H,\n  -- On peut donc appliquer l'hypothèse de convergence vers l à ε = |l'-l|/4\n  -- pour obtenir N tel que ∀ n ≥ N, |u n - l| ≤ |l - l'|/4.\n  Fait quart_pos : |l - l'|/4 > 0,\n     On conclut par ineg,\n  Par hl appliqué à [|l - l'|/4, quart_pos] on obtient N \n      tel que hN : ∀ n ≥ N, |u n - l| ≤ |l - l'| / 4,\n  -- On obtient de même N' tel que ∀ n ≥ N', |u n - l'| ≤ |l - l'|/4.\n  Par hl' appliqué à [|l - l'|/4, quart_pos] on obtient N' \n      tel que hN' : ∀ n ≥ N', |u n - l'| ≤ |l - l'| / 4,\n  -- Ainsi, pour l'indice N₀ = max(N, N'), on a |u N₀ - l| ≤ |l - l'|/4\n  Posons N₀ := max N N', -- la commande « Posons » n'est jamais indispensable\n                         -- mais elle économise quelques caractères.\n  Par hN appliqué à [N₀, inferieur_max_gauche N N']\n     on obtient hN₁ : |u N₀ - l| ≤ |l - l'| / 4,\n  -- et |u N₀ - l'| ≤ |l - l'|/4.\n  Par hN' appliqué à [N₀, inferieur_max_droite N N']\n     on obtient hN'₁ : |u N₀ - l'| ≤ |l - l'| / 4,\n\n  -- On démontre alors par calcul que |l - l'| < |l - l'|\n  Fait clef : |l - l'| < |l - l'|,\n    calc\n    |l - l'| ≤ |l - u N₀| + |u N₀ - l'|   : by On applique ineg_triangle\n         ... = |u N₀ - l| + |u N₀ - l'|   : by On réécrit via abs_diff\n         ... ≤ |l - l'|/4 + |l - l'|/4    : by On combine [hN₁, hN'₁]\n         ... = |l - l'|/2                 : by On calcule\n         ... < |l - l'|                   : by On conclut par ineg,\n  -- ce qui est absurde.\n  On conclut par non_strictement_inferieur_soi appliqué à clef,\nend\n\n/-\nUne autre incarnation très utile de l'axiome du tiers exclu est le principe\nde contraposition : pour démontrer « P ⇒ Q », il suffit de démontrer\n« non Q ⇒ non P ».\n-/\n\n-- En utilisant un raisonnement par l'absurde, montrer le principe\n-- de contraposition\nexample (P Q : Prop) (h : ¬ Q → ¬ P) : P → Q :=\nbegin\n  sorry\nend\n\n/-\nEn fait la réciproque du principe de contraposition est vraie aussi (et se\ndémontre sans même utiliser l'axiome du tiers exclu). On a donc\n(P ⇒ Q) ⇔ (non Q ⇒ non P)\n\nOn prendra bien garde à ne pas confondre :\n  * la contraposée de « P ⇒ Q » qui est « non Q ⇒ non P »\n  * la réciproque de « P ⇒ Q » qui est « Q ⇒ P ».\n\nEn général la réciproque d'une implication n'a aucun lien logique avec\nl'implication de départ.\n\nComme pour le raisonnement par l'absurde, le principe de contraposition n'est\npas redécomposé à chaque fois, on se contente d'écrire `On contrapose` dans Lean\net « Montrons la contraposée » ou « Par contraposition, il suffit de montrer\nque » ou quelque chose d'analogue sur papier.\n-/\n\nexample (P Q : Prop) (h : ¬ Q → ¬ P) : P → Q :=\nbegin\n  On contrapose,\n  On conclut par h,\nend\n\n-- Dans l'exercice suivant, on raisonnera par contraposition pour une\n-- des implications, et on utilisera les définitions de pair et impair ainsi\n-- que le lemme `non_pair_ssi (n : ℤ ): ¬ pair n ↔ impair n` démontré plus\n-- haut.\nexample (n : ℤ) : pair (n^2) ↔ pair n :=\nbegin\n  sorry\nend\n\n/-\nOn termine ce tour d'horizon du tiers exclu en signalant qu'il est parfois utile\nd'utiliser l'axiome du tiers exclu sous sa forme d'origine : pour tout énoncé P, \nsoit P est vrai soit ¬ P est vrai. Plutôt que d'invoquer cet énoncé puis de faire une\ndisjonction de cas à l'aide de la commande `On discute en utilisant`, Lean introduit \nle raccourci\n\n`On discute selon que P,`\n\nqui combine les deux étapes et crée directement deux branches de la\ndémonstration : une dans laquelle il faut montrer `P → but initial` et \nl'autre dans laquelle il faut montrer `¬ P → but initial`.\n\nDans l'exemple suivant, il n'est pas utile de retenir les lemmes concernant\nla valeur absolue, on se contentera d'en observer les effets.\n-/\n\nexample (x y : ℝ) : |x + y| ≤ |x| + |y| :=\nbegin\n  Fait hx : x ≤ |x|,\n    On applique le_abs_self,\n  Fait hx' : -x ≤ |x|,\n    On applique neg_le_abs_self,\n  Fait hy : y ≤ |y|, \n    On applique le_abs_self,\n  Fait hy' : -y ≤ |y|, \n    On applique neg_le_abs_self,\n  \n  On discute selon que 0 ≤ x + y,\n    Supposons h : 0 ≤ x + y,\n    calc |x + y| = x + y : abs_of_nonneg h\n          ...    ≤ |x| + |y| : by On combine [hx, hy],\n  Supposons h : ¬ 0 ≤ x + y,\n  On réécrit via not_le dans h qui devient x + y < 0,\n  calc |x + y| = -(x + y) : abs_of_neg h\n           ... = -x + (-y) : by On calcule\n           ... ≤ |x| + |y| : by On combine [hx', hy'],\nend\n\nexample (n : ℤ) : pair (n*(n+1)) :=\nbegin\n  sorry\nend\n\n\n/-\nIl est crucial de comprendre les négations d'énoncés comportant des\nquantificateurs. Dans l'exercice suivant, on utilisera seulement la \ndéfinition de la négation.\n-/\n\nexample (n : ℤ) : ¬ (∃ k, n = 2*k) ↔ ∀ k, n ≠ 2*k :=\nbegin\n  sorry\nend\n\n\n/-\nL'exercice précédent cache en fait un résultat complètement général :\nPour tout prédicat P, `(¬ ∃ x, P x) ↔ (∀ x, ¬ P x)`, et la démonstration\nn'est pas plus difficile que dans l'exercice précédent.\n\nDe façon analogue, `(¬ ∀ x, P x) ↔ (∃ x, ¬ P x)`. La démonstration est\nplus délicate, et nécessite le tiers exclu pour une implication. \n\nEn pratique on ne redémontre pas constamment ces règles de négation des énoncés\nquantifiés (les démonstrations ne sont même pas si simples !), on les connait\npar cœur.\nDans Lean on utilise `On pousse la négation` pour pousser les négations le plus\npossible vers la droite (parfois elles disparaissent complètement\nsi l'énoncé le plus à droite a une négation qui s'exprime bien,\npar exemple si c'est une inégalité).\n-/\n\ndef paire (f : ℝ → ℝ) := ∀ x, f (-x) = f x\n\n-- Montrons que la fonction x ↦ 2x n'est pas paire.\nexample : ¬ paire (fct x ↦ 2*x) :=\nbegin\n  On déplie paire, -- On notera que, pour une fois, cette ligne de dépliage\n                   -- est importante car « On pousse la négation» ne déplie pas les définitions.\n  On pousse la négation,\n  Montrons que 42 convient,\n  Supposons hyp,\n  On conclut par hyp, -- Il faut avouer que cette ligne est un peu étrange, mais la commande `On conclut par`\n                      -- est capable de détecter ce type de contradiction dans une hypothèse\nend\n\nexample (f : ℝ → ℝ) : ¬ paire f ↔ ∃ x, f (-x) ≠ f x :=\nbegin\n  sorry\nend\n\ndef majoree (f : ℝ → ℝ) := ∃ M, ∀ x, f x ≤ M\n\n-- La fonction identité, x ↦ x, n'est pas majorée.\nexample : ¬ majoree (fct x ↦ x) :=\nbegin\n  sorry\nend\n/-\nLa combinaison « contraposition puis pousser la négation » est tellement courante \nque la commande `On contrapose,` essaie automatiquement de pousser la négation après\nla contraposition, comme vous le constaterez dans l'exercice suivant qui est la variante \npromise de egal_si_abs_eps.\n-/\n\nexample (x : ℝ) : (∀ ε > 0, x ≤ ε) → x ≤ 0 :=\nbegin\n  sorry\nend\n\n/-\nDans l'exercice suivant, on pourra utiliser le lemme\n`eq_or_lt_of_le : a ≤ b → a = b ∨ a < b`\nAinsi, en ayant l'hypothèse `hxy : x ≤ y`, la commande\n`On discute en utilisant eq_or_lt_of_le hxy` permet de scinder\nla discussion en deux branches, l'une supposant x = y et l'autre x < y.\n-/\n\nexample (f : ℝ → ℝ) : (∀ x y, x < y → f x < f y) ↔ (∀ x y, (x ≤ y ↔ f x ≤ f y)) :=\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/10_negations_elementaires.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7936849368515319}}
{"text": "import mynat.definition -- Imports the natural numbers.\n\n/- Here's what you get from the import:\n\n1) The following data:\n  * a type called `mynat`\n  * a term `0 : mynat`, interpreted as the number zero.\n  * a function `succ : mynat → mynat`, with `succ n` interpreted as \"the number after n\".\n  * Usual numerical notation 0,1,2,3,4,5 etc.\n\n2) The following axioms:\n  * `zero_ne_succ : ∀ (a : mynat), zero ≠ succ(a)`, the statement that zero isn't a successor.\n  -- this ensures that there is more than one natural number.\n  * `succ_inj : ∀ {a b : mynat}, succ(a) = succ(b) → a = b`, the statement that\n     if succ(a) = succ(b) then a = b.\n  -- this ensures that there are infinitely many natural numbers.\n\n3) The principle of mathematical induction.\n\n  * In practice this means that if you have `n : mynat` then you can use the tactic `induction n`.\n\n4) A few useful extra things:\n\n  * The theorem `one_eq_succ_zero : 1 = succ 0`\n  * The theorem `ne_iff_implies_false : a ≠ b ↔ (a = b) → false`\n\n-/\n\nimport mynat.add -- definition of addition\n\n/- Here's what you get from the import:\n\n1) The following data:\n  * a function called mynat.add, and notation a + b for this function\n\n2) The following axioms:\n\n  * `add_zero : ∀ a : mynat, a + 0 = a`\n  * `add_succ : ∀ a b : mynat, a + succ(b) = succ(a + b)`\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 `add_zero` or `add_succ` appropriately.\n-/\n\nnamespace mynat\n\n-- Summary:\n\n-- Naturals:\n-- 1) 0 and succ are constants\n-- 2) succ_inj and zero_ne_succ are axioms\n-- 3) Induction works.\n\n-- Addition:\n-- 1) add_zero and add_succ are the axioms\n-- 2) notation is a + b\n\n/-\n Collectibles in this level:\n\nadd_comm_monoid -- collectible_02\n  add_monoid [zero_add] -- collectible_01\n    (has_zero)\n    add_semigroup [add_assoc]\n      (has_add)\n  add_comm_semigroup [add_comm]\n    add_semigroup (see above)\n-/\n\n\n-- ADDITION WORLD\n\n--Level 1 :\nlemma zero_add (n : mynat) : 0 + n = n :=\nbegin [nat_num_game]\n  -- On fait une induction sur n :\n  induction n with d hd,\n\n  -- Le cas de base :\n  rw add_zero,\n  refl,\n\n  -- Le cas d'induction :\n  rw add_succ,\n  rw hd,\n  refl,\n  \nend\n\n--Level 2 :\nlemma add_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  rw add_zero,\n  rw add_zero,\n  refl,\n\n  -- Le cas d'induction :\n  rw add_succ,\n  rw add_succ,\n  rw add_succ,\n  rw hd,\n  refl,\nend\n\n-- first point: needs add_assoc, zero_add, add_zero\ndef collectible_01 : add_monoid mynat := by structure_helper\n--#print axioms collectible_01 -- prove you got this by uncommenting\n\n-- proving add_comm immediately is still tricky; trying it\n-- reveals a natural intermediate lemma which we prove first.\n\n--Level 3 :\nlemma succ_add (a b : mynat) : succ a + b = succ (a + b) :=\nbegin [nat_num_game]\n  -- On fait une induction sur b :\n  induction b with n hn,\n\n  -- Le cas de base :\n  rw add_zero,\n  rw add_zero,\n  refl,\n\n  -- Le cas d'induction :\n  rw add_succ,\n  rw add_succ,\n  rw hn,\n  refl,\nend\n\n--Level 4 :\nlemma add_comm (a b : mynat) : a + b = b + a :=\nbegin [nat_num_game]\n  -- On fait une induction sur b :\n  induction b with n hn,\n\n  -- Le cas de base :\n  rw zero_add,\n  rw add_zero,\n  refl,\n\n  -- Le cas d'induction :\n  rw add_succ,\n  rw succ_add,\n  rw hn,\n  refl,\nend\n\n-- level up\ndef collectible_02 : add_comm_monoid mynat := by structure_helper\n--#print axioms collectible_02\n\n-- no more collectibles beyond this point in this file, however\n-- stuff below is used in other collectibles in other files.\n\n--Level 5 :\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 :=\nbegin [nat_num_game]\n  -- Il suffit d'utiliser l'axiome '1 = succ 0' puis de simplifier :\n  rw one_eq_succ_zero,\n  rw add_succ,\n  rw add_zero,\n  refl,\nend\n\n--Level 6 :\nlemma add_right_comm (a b c : mynat) : a + b + c = a + c + b :=\nbegin [nat_num_game]\n  --Une combinaison d'associativité et de commutativité :\n  rw add_assoc,\n  rw add_comm b c,\n  rw add_assoc,\n  refl,\nend\n\n\n-- ADVANCED ADDITION WORLD\n\n--Level 1 :\ntheorem succ_inj' {a b : mynat} (hs : succ(a) = succ(b)) :  a = b := \nbegin [nat_num_game]\n  apply succ_inj,\n  exact hs,\nend\n\n--Level 2 :\ntheorem succ_succ_inj {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) :  a = b := \nbegin [nat_num_game]\n  apply succ_inj,\n  apply succ_inj,\n  exact h,\nend\n\n--Level 3 :\ntheorem succ_eq_succ_of_eq {a b : mynat} : a = b → succ(a) = succ(b) :=\nbegin [nat_num_game]\n  intro h,\n  rw h,\nend\n\n-- Level 4 :\ntheorem succ_eq_succ_iff (a b : mynat) : succ a = succ b ↔ a = b :=\nbegin [nat_num_game]\n  split,\n \n  -- → \n  exact succ_inj,\n \n  -- ← \n  exact succ_eq_succ_of_eq,\nend\n\n--Level 5 :\ntheorem add_right_cancel ⦃a b c : mynat⦄ : a + b = c + b → a = c :=\nbegin [nat_num_game]\n  intro h,\n\n  -- On fait une induction sur t :\n  induction b with n hn,\n\n  -- Le cas de base :\n  repeat {rw add_zero at h},\n  exact h,\n\n  -- Le cas d'induction :\n  apply hn,\n  repeat {rw add_succ at h},\n  apply succ_inj,\n  exact h,\nend\n\n--Level 6 :\ntheorem add_left_cancel ⦃ a b c : mynat⦄ : a + b = a + c → b = c :=\nbegin [nat_num_game]\n  --On utilise la commutativité de l'addition pour se ramener au cas précédent :\n  rw add_comm,\n  rw add_comm a c,\n  intro h,\n  exact add_right_cancel h,\nend\n\n--Level 7 :\ntheorem add_right_cancel_iff (t a b : mynat) :  a + t = b + t ↔ a = b :=\nbegin [nat_num_game]\n  split,\n\n  intro h,\n  exact add_right_cancel h,\n\n  cc,\nend\n\n-- this is used for antisymmetry of ≤\n--Level 8 :\nlemma eq_zero_of_add_right_eq_self {{a b : mynat}} : a + b = a → b = 0 :=\nbegin [nat_num_game]\n  intro h,\n  exact add_left_cancel h,\nend\n\n--Level 9 :\ntheorem succ_ne_zero : ∀ {{a : mynat}}, succ a ≠ 0 := \nbegin [nat_num_game]\n  intro a,\n  symmetry,\n  exact zero_ne_succ a,\nend\n\n-- now used for antisymmetry of ≤\n--Level 10 :\nlemma add_left_eq_zero {{a b : mynat}} : a + b = 0 → b = 0 :=\nbegin [nat_num_game]\n  intro H,\n  --On fait une distinction de cas 'b = 0' ou 'b = succ(d)' :\n  cases b with d,\n\n  --Cas 'b = 0' :\n  refl,\n\n  --Cas 'b = succ(d)' :\n  rw add_succ at H,\n  exfalso,\n  exact succ_ne_zero H,\nend\n\n--Level 11 :\nlemma add_right_eq_zero {{a b : mynat}} : a + b = 0 → a = 0 :=\nbegin [nat_num_game]\n  intro h,\n  rw add_comm at h,\n  exact add_left_eq_zero h,\nend\n\n--Level 12 :\ntheorem add_one_eq_succ (d : mynat) : d + 1 = succ d :=\nbegin [nat_num_game]\n  symmetry,\n  refl,\nend\n\ndef ne_succ_self (n : mynat) : n ≠ succ n :=\nbegin [nat_num_game]\n  -- On fait une induction sur n :\n  induction n with d hd,\n\n  -- Le cas de base :  \n  exact zero_ne_succ 0,\n\n  -- Le cas d'induction :\n  intro h,\n  apply hd,\n  apply succ_inj,\n  exact h,\nend\n\nend mynat", "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/world1_addition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8558511469672595, "lm_q1q2_score": 0.7936849350802087}}
{"text": "import .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 {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nsorry\n\n/-! 1.2. Prove its cousin. -/\n\nlemma monotone_restrict {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nsorry\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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing {} : regex\n| empty {}   : regex\n| atom       : α → regex\n| concat     : regex → regex → regex\n| alt        : regex → regex → regex\n| star       : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n-- enter the missing cases here\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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_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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.7936723295536494}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hp,\n  intro hnp,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro hnnp,\n  by_cases P,\n  assumption,\n  have hboom : false := hnnp h,\n  contradiction,\n\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  apply doubleneg_elim,\n  apply doubleneg_intro,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hor,\n  cases hor with hp hq,\n  right,\n  assumption,\n  left,\n  assumption,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro hand,\n  cases hand with hp hq,\n  split,\n  assumption,\n  assumption,\n\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro hor,\n  intro hp,\n  cases hor with hnp hq,\n  contradiction,\n  assumption,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro hor,\n  intro hnp,\n  cases hor with hp hq,\n  contradiction,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro hpq,\n  intro hnq,\n  intro hp,\n  have hq : Q := hpq hp,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro hnqnp,\n  intro hp,\n  by_contra hnq,\n  have hnp : ¬P := hnqnp hnq,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  apply impl_as_contrapositive,\n  apply impl_as_contrapositive_converse,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro hnor,\n  apply hnor,\n  right,\n  intro hp,\n  apply hnor,\n  left,\n  assumption,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro hpqp,\n  intro hnp,\n  apply hnp,\n  apply hpqp,\n  intro hp,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro hor,\n  intro hand,\n  cases hand with hnp hnq,\n  cases hor with hp hq,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro hand,\n  intro hor,\n  cases hand with hp hq,\n  cases hor with hnp hnq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro hnor,\n  split,\n  intro hp,\n  apply hnor,\n  left,\n  assumption,\n  intro hq,\n  apply hnor,\n  right,\n  assumption,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro hand,\n  intro hor,\n  cases hand with hnp hnq,\n  cases hor with hp hq,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro hnand,\n  by_contra hnor,\n  apply hnand,\n  split,\n  by_contra hnp,\n  apply hnor,\n  right,\n  assumption,\n  by_contra hnq,\n  apply hnor,\n  left,\n  assumption,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro hor,\n  intro hand,\n  cases hand with hp hq,\n  cases hor with hnq hnp,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  apply demorgan_conj,\n  apply demorgan_conj_converse,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  apply demorgan_disj,\n  apply demorgan_disj_converse,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro hand,\n  cases hand with hp hor,\n  cases hor with hq hr,\n  left,\n  split,\n  assumption,\n  assumption,\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro hor,\n  cases hor with handpq handpr,\n  split,\n  cases handpq with hp hq,\n  assumption,\n  cases handpq with hp hq,\n  left,\n  assumption,\n  split,\n  cases handpr with hp hr,\n  assumption,\n  cases handpr with hp hr,\n  right,\n  assumption,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro hor,\n  cases hor with hp handqr,\n  split,\n  left,\n  assumption,\n  left,\n  assumption,\n  cases handqr with hq hr,\n  split,\n  right,\n  assumption,\n  right,\n  assumption,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro hand,\n  cases hand with horpq horpr,\n  cases horpr with hp hr,\n  left,\n  assumption,\n  cases horpq with hp hq,\n  left,\n  assumption,\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro handr,\n  intro hp,\n  intro hq,\n  apply handr,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro hpqr,\n  intro hand,\n  cases hand with hp hq,\n  apply hpqr,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hp,\n  assumption,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hp,\n  left,\n  assumption,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hq,\n  right,\n  assumption,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro hand,\n  cases hand with hp hq,\n  assumption,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro hand,\n  cases hand with hp hq,\n  assumption,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  apply weaken_conj_right,\n  intro hp,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro hor,\n  cases hor with hp hp,\n  assumption,\n  assumption,\n  apply weaken_disj_right,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro hnepx,\n  intro x,\n  intro hpx,\n  apply hnepx,\n  existsi x,\n  assumption,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro hforallnpx,\n  intro hepx,\n  cases hepx with x hpx,\n  have hnpx : ¬P x := hforallnpx x,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro hnforallpx,\n  by_contra hnenpx,\n  apply hnforallpx,\n  intro x,\n  by_contra hnpx,\n  apply hnenpx,\n  existsi x,\n  assumption,\n  \nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro henpx,\n  intro hforallpx,\n  cases henpx with x hnpx,\n  have hpx : P x := hforallpx x,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_forall,\n  apply demorgan_forall_converse,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_exists,\n  apply demorgan_exists_converse,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro hepx,\n  intro hforallnpx,\n  cases hepx with x hpx,\n  have hnpx : ¬P x := hforallnpx x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro hforallpx,\n  intro henpx,\n  cases henpx with x hnpx,\n  have hpx : P x := hforallpx x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro hnenpx,\n  intro x,\n  by_contra hnpx,\n  apply hnenpx,\n  existsi x,\n  assumption,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro hnforallnpx,\n  by_contra hnepx,\n  apply hnforallnpx,\n  intro x,\n  by_contra hpx,\n  apply hnepx,\n  existsi x,\n  assumption,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro heand,\n  cases heand with x hand,\n  cases hand with hpx hqx,\n  split,\n  existsi x,\n  assumption,\n  existsi x,\n  assumption,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro heor,\n  cases heor with x hor,\n  cases hor with hpx hqx,\n  left,\n  existsi x,\n  assumption,\n  right,\n  existsi x,\n  assumption,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro hor,\n  cases hor with hepx heqx,\n  cases hepx with x hpx,\n  existsi x,\n  left,\n  assumption,\n  cases heqx with x hqx,\n  existsi x,\n  right,\n  assumption,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro hforalland,\n  split,\n  intro x,\n  have hand : P x ∧ Q x := hforalland x,\n  cases hand with hpx hqx,\n  assumption,\n  intro x,\n  have hand : P x ∧ Q x := hforalland x,\n  cases hand with hpx hqx,\n  assumption,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro hand,\n  cases hand with hforallpx hforallqx,\n  intro x,\n  split,\n  have hpx : P x := hforallpx x,\n  assumption,\n  have hqx : Q x := hforallqx x,\n  assumption,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro hor,\n  intro x,\n  cases hor with hforallpx hforallqx,\n  left,\n  have hpx : P x := hforallpx x,\n  assumption,\n  right,\n  have hqx : Q x := hforallqx x,\n  assumption,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "Minobarbarian", "repo": "fmclean", "sha": "455eb23d8a0374469d041294075b80e168184693", "save_path": "github-repos/lean/Minobarbarian-fmclean", "path": "github-repos/lean/Minobarbarian-fmclean/fmclean-455eb23d8a0374469d041294075b80e168184693/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760996, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7936610258418643}}
{"text": "import tactic.push_neg\nimport data.int.order.basic\nimport data.nat.basic\n\nexample (h : ∃ p: ℕ, ¬ ∀ n : ℕ, n > p) (h' : ∃ p: ℕ, ¬ ∃ n : ℕ, n < p) : ¬ ∀ n : ℕ, n = 0 :=\nbegin\n  push_neg at *,\n  guard_target_strict ∃ (n : ℕ), n ≠ 0,\n  guard_hyp_strict h : ∃ (p n : ℕ), n ≤ p,\n  guard_hyp_strict h' : ∃ (p : ℕ), ∀ (n : ℕ), p ≤ n,\n  use 1,\nend\n\n-- In the next example, ℤ should be ℝ in maths, but I don't want to import real numbers\n-- for testing only\n\nexample (a : ℕ → ℤ) (l : ℤ) (h : ¬ ∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε) : true :=\nbegin\n  push_neg at h,\n  guard_hyp_strict h : ∃ (ε : ℤ), ε > 0 ∧ ∀ (N : ℕ), ∃ (n : ℕ), n ≥ N ∧ ε ≤ |a n - l|,\n  trivial\nend\n\nexample (f : ℤ → ℤ) (x₀ y₀) (h : ¬ ∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - y₀| ≤ ε) : true :=\nbegin\n  push_neg at h,\n  guard_hyp_strict h : ∃ (ε : ℤ), ε > 0 ∧ ∀ δ > 0, (∃ (x : ℤ), |x - x₀| ≤ δ ∧ ε < |f x - y₀| ),\n  trivial\nend\n\nexample (n) : n*n ≠ 1 → n ≠ 1 :=\nbegin\n  contrapose,\n  rw [not_not, not_not],\n  intro h,\n  rw [h, one_mul]\nend\n\nexample (n) : n*n ≠ 1 → n ≠ 1 :=\nbegin\n  contrapose!,\n  intro h,\n  rw [h, one_mul]\nend\n\nexample (n) (h : n*n ≠ 1) : n ≠ 1 :=\nbegin\n  contrapose h,\n  rw not_not at *,\n  rw [h, one_mul]\nend\n\nexample (n) (h : n*n ≠ 1) : n ≠ 1 :=\nbegin\n  contrapose! h,\n  rw [h, one_mul]\nend\n\nexample (n) (h : n*n ≠ 1) : n ≠ 1 :=\nbegin\n  contrapose! h with newh,\n  rw [newh, one_mul]\nend\n\nexample : 0 = 0 :=\nbegin\n  success_if_fail_with_msg { contrapose }\n    \"The goal is not an implication, and you didn't specify an assumption\",\n  refl\nend\n\n-- Remember that ∀ is the same as Π which is a generalization of → so we need to make sure\n-- `contrapose` fails with a helpful error message in the next example.\nexample : ∀ x : ℕ, x = x :=\nbegin\n  success_if_fail_with_msg { contrapose }\n    \"contrapose only applies to nondependent arrows between props\",\n  intro, refl\nend\n\nopen tactic\nexample (X : Type) (f : X → ℕ) (h : ¬∀ x, f x = 0) (hf : false) : false :=\nbegin\n  have h1 := h,\n  -- h h1: ¬∀ (x : X), f x = 0\n  push_neg at h,\n  push_neg at h1,\n  (do ht ← get_local `h >>= infer_type,\n      h1t ← get_local `h1 >>= infer_type,\n      guard (ht = h1t) ),\n  exact hf\nend\n\n/-! Test the option `trace.push_neg.use_distrib` for changing the normal form of `¬(P ∧ Q)`. -/\n\nsection\n\nexample (a b : ℤ) (h : ¬ (∃ x, (a < x ∧ x < b))) : ∀ x, a < x → b ≤ x :=\nbegin\n  push_neg at h,\n  exact h,\nend\n\nset_option trace.push_neg.use_distrib true\n\nexample (a b : ℤ) (h : ¬ (∃ x, (a < x ∧ x < b))) : ∀ x, x ≤ a ∨ b ≤ x :=\nbegin\n  push_neg at h,\n  exact h,\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/test/push_neg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7936610088586719}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    f '' s ⊆ t ↔ s ⊆ f ⁻¹' t\n-- ----------------------------------------------------------------------\n\nimport data.set.function\n\nuniverses u v\nvariable  α : Type u\nvariable  β : Type v\nvariable  f : α → β\nvariables (s : set α) (t : set β)\n\nopen set\n\nexample : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=\nbegin\n  split,\n  { intros h x xs,\n    show f x ∈ t,\n      { calc f x ∈ f '' s : mem_image_of_mem f xs\n             ... ⊆ t      : h }},  \n  { intros h y hy,\n    rcases hy with ⟨x,xs,fxy⟩,\n    rw ← fxy,\n    apply h,\n    exact xs },  \nend\n\n-- Prueba\n-- ======\n\n/-\nα : Type u,\nβ : Type v,\nf : α → β,\ns : set α,\nt : set β\n⊢ f '' s ⊆ t ↔ s ⊆ f ⁻¹' t\n  >> split,\n| ⊢ f '' s ⊆ t → s ⊆ f ⁻¹' t\n|   >> { intros h x xs,\n| h : f '' s ⊆ t,\n| x : α,\n| xs : x ∈ s\n| ⊢ x ∈ f ⁻¹' t\n|   >>   show f x ∈ t,\n|   >>     { calc f x ∈ f '' s : mem_image_of_mem f xs\n|   >>            ... ⊆ t      : h }},\n⊢ s ⊆ f ⁻¹' t → f '' s ⊆ t  \n  >> { intros h y hy,\nh : s ⊆ f ⁻¹' t,\ny : β,\nhy : y ∈ f '' s\n⊢ y ∈ t\n  >>   rcases hy with ⟨x,xs,fxy⟩,\nx : α,\nxs : x ∈ s,\nfxy : f x = y\n⊢ y ∈ t\n  >>   rw ← fxy,\n⊢ f x ∈ t\n  >>   apply h,\n⊢ x ∈ s\n  >>   exact xs },\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/Inclusion_de_la_imagen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.7936327488298083}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n--    1. Importar la teoría de anillos.\n--    2. Crear el espacio de nombres my_ring\n--    3. Declarar R como una variable sobre anillos.\n--    4. Declarar a y b como variables sobre R.\n-- ----------------------------------------------------------------------\n\nimport algebra.ring            -- 1\nnamespace my_ring              -- 2\nvariables {R : Type*} [ring R] -- 3\nvariables (a b : R)            -- 4\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    a - b = a + -b\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\ntheorem sub_eq_add_neg  : a - b = a + -b :=\n-- by library_search\nsub_eq_add_neg a b\n\nend my_ring\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/Subtraccion_en_anillos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8577681013541611, "lm_q1q2_score": 0.7936327471477668}}
{"text": "import data.list.basic tactic.linarith\nimport list.lemmas.long_lemmas  misc_lemmas\n\n\nopen list\n/-- The minimum element of a non-empty list-/\ndef list.min {X : Type*} [decidable_linear_order X] :\nΠ (L : list X), (L ≠ []) → X\n| ([]) hL := false.elim $ hL rfl\n| (x :: []) hL := x\n| (x :: y :: L) _ := min x (list.min (y :: L) dec_trivial)\n\n/--extended version of list.min on lists of integers that maps the empty list to 0-/\ndef list.min' (L : list ℤ) : ℤ :=\nif h : L = [] then 0 else list.min L h\n\n\n/--If we have two non-empty lists of the same length and for each index, elements with the same\n   index differ by at most d, then their minimums differ by at most d-/\ntheorem list.min_change (L M : list ℤ) (hL : L ≠ []) (hLM : L.length = M.length) (hM : M ≠ []) (d : ℤ)\n(hdist : ∀ (i : ℕ) (hiL : i < L.length) (hiM : i < M.length), abs (L.nth_le i hiL - M.nth_le i hiM) ≤ d) :\n  abs (L.min hL - M.min hM) ≤ d :=\nbegin\n  -- if L = nil, that contradicts hL\n  cases L with n Ln,\n    contradiction,\n  -- L = (n :: Ln)\n  revert n M, -- so the inductive hypothesis does not depend on n or M\n  induction Ln with n1 Ln1 IH,\n    \n    -- base case : Ln = nil (so L = [n])\n    {\n      intros n M hM hL hLM hdist,\n      change 1 = length M at hLM, -- as L = [n], and length [n] = length (n :: nil) = 1 by definition\n      symmetry' at hLM, -- change 1 = length M to length M = 1\n      rw length_eq_one at hLM, -- now hLM implies M is a singleton\n      cases hLM with m hLM, -- say M = [m], for some a of type ℕ \n      simp only [hLM],\n      show abs (n - m) ≤ d, /- because by def of list.min the minimum of a singleton \n                               is its only element -/\n      convert hdist 0 (zero_lt_one) _, -- that is true because by hdist, abs (L.nth_le 0 hiL - M.nth_le 0 hiM) ≤ d\n      -- have already told Lean i is 0 and 0 < 1 (which is the length of [n] by def)\n      -- prove 0 < length M\n        swap,\n        {rw hLM,\n        exact zero_lt_one},\n      /- now prove m = nth_le M 0 _ (which convert reduced the goal to as it Lean noticed\n                                     all other similarities to hdist)-/\n      simp only [hLM], --\n      refl, -- by def of nth_le\n    },\n\n     --inductive step : Ln = (n1 :: Ln1)\n    { intros n M hM hL hLM hdist,\n      -- if M = nil, that contradicts hM\n      cases M with m Mm,\n        contradiction,\n      -- now M = (m :: Mm)\n      -- but if Mm = nil, then by hLM length (n :: n1 :: Ln1) = length (m :: nil). Contradiction!\n      cases Mm with m1 Mm1, \n        cases hLM,\n      -- so M = (m :: m1 :: Mm1)\n      unfold list.min, /- changes list.min (n :: n1 :: Ln1) hL to min n (list.min (n1 :: Ln1) _)\n                           and list.min (m :: m1 :: Mm1) hM to min m (list.min (m1 :: Mm1) _)\n                           (third constructor of list.min)-/\n      /- we want to use the inductive hypothesis with M being (m1 :: Mm1)-/\n      replace hLM := nat.succ_inj hLM, -- get : length (n1 :: Ln1) = length (m1 :: Mm1)\n      -- the following is the version of hdist for M being (m1 :: Mm1)\n      have hyp : (∀ (i : ℕ) (hiL : i < length (n1 :: Ln1)) (hiM : i < length (m1 :: Mm1)),\n                 abs (nth_le (n1 :: Ln1) i hiL - nth_le (m1 :: Mm1) i hiM) ≤ d),\n        intros i hiL hiM,\n        exact hdist (i + 1) (nat.succ_lt_succ hiL) (nat.succ_lt_succ hiM), -- follows from hdist\n      /- use the inductive hypothesis to get (h : abs (list.min (n1 :: Ln1) _ - list.min (m1 :: Mm1) _) ≤ d)\n         (the other hypotheses, that the lists are non-empty, are true by decidability)-/\n      have h := IH n1 (m1 :: Mm1) dec_trivial dec_trivial hLM hyp,\n      have hmn : abs (n - m) ≤ d,\n        exact hdist 0 dec_trivial dec_trivial, -- n, m are the 0th elements, so holds by hdist\n      exact abs_min_sub_min hmn h} -- (see misc_lemmas)\nend\n\n\n/--If we have two lists of the same length and for each index, elements with the same\n   index differ by at most some non-negative value d, then their extended minimums (min') differ by at most d-/\nlemma list.min'_change (L M : list ℤ) (hLM : L.length = M.length) (d : ℤ) (hd : 0 ≤ d)\n(hdist : ∀ (i : ℕ) (hiL : i < L.length) (hiM : i < M.length), abs (L.nth_le i hiL - M.nth_le i hiM) ≤ d) :\n  abs (L.min' - M.min') ≤ d := \n  begin\n  /- if M and L are non-empty, this is basically proven by the lemma above, because of\n     how list.min' is defined.\n     Therefore we prove the empty-list-case separately-/\n  cases M with m Mn,\n    -- M = nil (so hLM is : length L = length nil)\n    {rw length at hLM, -- length nil = 0 by def of length\n    rw length_eq_zero at hLM, -- length L = 0 ↔ L = nil\n    rw hLM,\n    -- now this is true by the definition of list.min' and hd\n    unfold list.min',\n    split_ifs,\n      {exact hd}, -- case where nil = nil\n      {contradiction},}, -- case where ¬ (nil = nil), a contradiction\n\n  -- M = (m :: Mn)  \n  /- now this is true by lis.min_change, but we first need to show M and N are non-empty-/\n  {have hM : ¬ (m :: Mn : list ℤ) = nil := by simp,\n  have hL : ¬ L = nil, \n    {apply ne_nil_of_length_pos, -- prove 0 < length L instead\n    rw hLM,\n    exact dec_trivial,}, -- true by decideability\n\n  unfold list.min',\n  split_ifs, -- (L = nil)-case killed immediately \n  exact list.min_change L (m :: Mn) hL hLM hM d hdist,}, \n\n  end\n  \n", "meta": {"author": "ImperialCollegeLondon", "repo": "dots_and_boxes", "sha": "f7bd0b1603674a657170c5395adb717c4f670220", "save_path": "github-repos/lean/ImperialCollegeLondon-dots_and_boxes", "path": "github-repos/lean/ImperialCollegeLondon-dots_and_boxes/dots_and_boxes-f7bd0b1603674a657170c5395adb717c4f670220/src/list/min/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8577680977182187, "lm_q1q2_score": 0.793632740246747}}
{"text": "import tactic.group\n\nvariables {G : Type} [group G]\n\nexample (a b c d : G) : c *(a*b)*(b⁻¹*a⁻¹)*c = c*c :=\nby group\n\nexample (a b c d : G) : (b*c⁻¹)*c *(a*b)*(b⁻¹*a⁻¹)*c = b*c :=\nby group\n\nexample (a b c d : G) : c⁻¹*(b*c⁻¹)*c *(a*b)*(b⁻¹*a⁻¹*b⁻¹)*c = 1 :=\nby group\n\n-- The following is known as the Hall-Witt identity,\n-- see e.g.\n-- https://en.wikipedia.org/wiki/Three_subgroups_lemma#Proof_and_the_Hall%E2%80%93Witt_identity\nexample (g h k : G) :\n  g * ⁅⁅g⁻¹, h⁆, k⁆ * g⁻¹ * k * ⁅⁅k⁻¹, g⁆, h⁆ * k⁻¹ * h *⁅⁅h⁻¹, k⁆, g⁆ * h⁻¹ = 1 :=\nby group\n\nexample (a : G) : a^2*a = a^3 :=\nby group\n\nexample (n m : ℕ) (a : G) : a^n*a^m = a^(n+m) :=\nby group\n\nexample (a b c d : G) : c *(a*b^2)*((b*b)⁻¹*a⁻¹)*c = c*c :=\nby group\n\nexample (n m : ℕ) (a : G) : a^n*(a⁻¹)^n = 1 :=\nby group\n\nexample (n m : ℕ) (a : G) : a^2*a⁻¹*a⁻¹ = 1 :=\nby group\n\nexample (n m : ℕ) (a : G) : a^n*a^m = a^(m+n) :=\nby group\n\nexample (n : ℕ) (a : G) : a^(n-n) = 1 :=\nby group\n\nexample (n : ℤ) (a : G) : a^(n-n) = 1 :=\nby group\n\nexample (n : ℤ) (a : G) (h : a^(n*(n+1)-n -n^2) = a) : a = 1 :=\nbegin\n group at h,\n exact h.symm,\n end\n\nexample (a b c d : G) (h : c = (a*b^2)*((b*b)⁻¹*a⁻¹)*d) : a*c*d⁻¹ = a :=\nbegin\n  group at h,\n  rw h,\n  group,\nend\n\n-- The next example can be expand to require an arbitrarily high number of alternation\n-- between simp and ring\n\nexample (n m : ℤ) (a b : G) : a^n*b^n*a^n*a^n*a^-n*a^-n*b^-n*a^-n = 1 :=\nby group\n\n-- Test that group deals with `1⁻¹` properly\n\nexample (x y : G) : (x⁻¹ * (x * y) * y⁻¹)⁻¹ = 1 :=\nby group\n\nexample (x : G) (h : x = 1) : x = 1 :=\nbegin\n  group,\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/test/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763573, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7935989187782188}}
{"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-/\n\nimport Mathlib.Init.Algebra.Order\n\nuniverse u\n\nsection\n\nvariable {α : Type u} [LinearOrder α]\n\nlemma min_def (a b : α) : min a b = if a ≤ b then a else b := LinearOrder.min_def ..\n\nlemma min_le_left (a b : α) : min a b ≤ a := by\n  if h : a ≤ b\n  then simp [min_def, if_pos h, le_refl]\n  else simp [min_def, if_neg h]; exact le_of_not_le h\n\nlemma min_le_right (a b : α) : min a b ≤ b := by\n  if h : a ≤ b\n  then simp [min_def, if_pos h]; exact h\n  else simp [min_def, if_neg h, le_refl]\n\nlemma le_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b := by\n  if h : a ≤ b\n  then simp [min_def, if_pos h]; exact h₁\n  else simp [min_def, if_neg h]; exact h₂\n\nlemma max_def (a b : α) : max a b = if a ≤ b then b else a := LinearOrder.max_def ..\n\nlemma le_max_left (a b : α) : a ≤ max a b := by\n  if h : a ≤ b\n  then simp [max_def, if_pos h]; exact h\n  else simp [max_def, if_neg h, le_refl]\n\nlemma le_max_right (a b : α) : b ≤ max a b := by\n  if h : a ≤ b\n  then simp [max_def, if_pos h]\n  else simp [max_def, if_neg h]; exact le_of_not_le h\n\nlemma max_le {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) : max a b ≤ c := by\n  if h : a ≤ b\n  then simp [max_def, if_pos h]; exact h₂\n  else simp [max_def, if_neg h]; exact h₁\n\nlemma eq_min {a b c : α} (h₁ : c ≤ a) (h₂ : c ≤ b) (h₃ : ∀{d}, d ≤ a → d ≤ b → d ≤ c) :\n  c = min a b :=\nle_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b))\n\nlemma min_comm (a b : α) : min a b = min b a :=\neq_min (min_le_right a b) (min_le_left a b) (λ {_} h₁ h₂ => le_min h₂ h₁)\n\nlemma min_assoc (a b c : α) : min (min a b) c = min a (min b c) :=\nby 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₁ h₂; apply le_min; apply le_min h₁; apply le_trans h₂; apply min_le_left;\n     apply le_trans h₂; apply min_le_right\n\nlemma min_left_comm : @LeftCommutative α α min :=\nleft_comm min (@min_comm α _) (@min_assoc α _)\n\n@[simp]\nlemma min_self (a : α) : min a a = a := by simp [min_def]\n\nlemma min_eq_left {a b : α} (h : a ≤ b) : min a b = a :=\nby apply Eq.symm; apply eq_min (le_refl _) h; intros; assumption\n\nlemma min_eq_right {a b : α} (h : b ≤ a) : min a b = b :=\nby rw [min_comm]\n   exact min_eq_left h\n\nlemma eq_max {a b c : α} (h₁ : a ≤ c) (h₂ : b ≤ c) (h₃ : ∀{d}, a ≤ d → b ≤ d → c ≤ d) :\n    c = max a b :=\nle_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂)\n\nlemma max_comm (a b : α) : max a b = max b a :=\neq_max (le_max_right a b) (le_max_left a b) (λ {_} h₁ h₂ => max_le h₂ h₁)\n\nlemma max_assoc (a b c : α) : max (max a b) c = max a (max b c) := by\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₁ h₂; apply max_le; apply max_le h₁; apply le_trans (le_max_left _ _) h₂;\n    apply le_trans (le_max_right _ _) h₂\n\nlemma max_left_comm : ∀ (a b c : α), max a (max b c) = max b (max a c) :=\nleft_comm max (@max_comm α _) (@max_assoc α _)\n\n@[simp] lemma max_self (a : α) : max a a = a := by simp [max_def]\n\nlemma max_eq_left {a b : α} (h : b ≤ a) : max a b = a :=\nby apply Eq.symm; apply eq_max (le_refl _) h; intros; assumption\n\nlemma max_eq_right {a b : α} (h : a ≤ b) : max a b = b :=\nby rw [←max_comm b a]; exact max_eq_left h\n\n/- these rely on lt_of_lt -/\n\nlemma min_eq_left_of_lt {a b : α} (h : a < b) : min a b = a :=\nmin_eq_left (le_of_lt h)\n\nlemma min_eq_right_of_lt {a b : α} (h : b < a) : min a b = b :=\nmin_eq_right (le_of_lt h)\n\nlemma max_eq_left_of_lt {a b : α} (h : b < a) : max a b = a :=\nmax_eq_left (le_of_lt h)\n\nlemma max_eq_right_of_lt {a b : α} (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 : α} (h₁ : a < b) (h₂ : a < c) : a < min b c :=\nOr.elim (le_or_gt b c)\n  (λ h : b ≤ c => by rwa [min_eq_left h])\n  (λ h : b > c => by rwa [min_eq_right_of_lt h])\n\nlemma max_lt {a b c : α} (h₁ : a < c) (h₂ : b < c) : max a b < c :=\nOr.elim (le_or_gt a b)\n  (λ h : a ≤ b => by rwa [max_eq_right h])\n  (λ h : a > b => by rwa [max_eq_left_of_lt h])\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/Init/Algebra/Functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8840392786908831, "lm_q1q2_score": 0.7935979033580101}}
{"text": "/-\nCopyright (c) 2020. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jalex Stark, Yury Kudryashov\n-/\nimport data.real.basic\n\n/-!\n# Sum of the Reciprocals of the Triangular Numbers\n\nThis file proves Theorem 42 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).\n\nWe interpret “triangular numbers” as naturals of the form $\\frac{k(k+1)}{2}$ for natural `k`.\nWe prove that the sum of the first `n` triangular numbers is equal to $2 - \\frac2n$.\n\n## Tags\n\ndiscrete_sum\n-/\n\nopen_locale big_operators\nopen finset\n\nlemma inverse_triangle_sum :\n  ∀ n, ∑ k in range n, (2 : ℚ) / (k * (k + 1)) = if n = 0 then 0 else 2 - (2 : ℚ) / n :=\nbegin\n  refine sum_range_induction _ _ (if_pos rfl) _,\n  rintro (_|n), { rw [if_neg, if_pos]; norm_num },\n  simp_rw [if_neg (nat.succ_ne_zero _), nat.succ_eq_add_one],\n  have A : (n + 1 + 1 : ℚ) ≠ 0, by { norm_cast, norm_num },\n  push_cast,\n  field_simp [nat.cast_add_one_ne_zero],\n  ring\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/42_inverse_triangle_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7935441624808265}}
{"text": "class myfld (f : Type) := \n(add : f -> f -> f)\n(mul : f -> f -> f)\n(negate : f -> f)\n(zero : f)\n(reciprocal : ∀ (x : f), (x ≠ zero) -> f) /- Reciprocal of zero is undefined.-/ \n(one : f)\n(add_assoc : ∀ (x y z : f), (add x (add y z)) = (add (add x y) z))\n(mul_assoc : ∀ (x y z : f), (mul x (mul y z)) = (mul (mul x y) z))\n(add_comm : ∀ (x y : f), (add x y) = (add y x))\n(mul_comm : ∀ (x y : f), (mul x y) = (mul y x))\n(add_zero : ∀ (x : f), x = (add x zero))\n(mul_one : ∀ (x : f), x = (mul x one))\n(add_negate : ∀ (x : f), (add x (negate x)) = zero)\n(mul_reciprocal : ∀ (x : f), ∀ (proof : x ≠ zero), (mul x (reciprocal x proof)) = one)\n(distrib : ∀ (x y z : f), (add (mul x z) (mul y z)) = (mul (add x y) z))\n(zero_distinct_one : one ≠ zero) /- By definition, 0 and 1 can't be the same element. -/ \n\ninfix ` .+ `:1000000 := myfld.add\ninfix ` .* `:1000001 := myfld.mul\nprefix ` .- `:1000002 := myfld.negate\n\ndef square (f : Type) [myfld f] : f -> f \n| x := x .* x \n\n@[simp] lemma add_comm (f : Type) [myfld f] (x y : f) : x .+ y = y .+ x := \nbegin \n  exact (myfld.add_comm : ∀ (x y : f), (x .+ y) = (y .+ x)) x y, \nend \n\n@[simp] lemma one_mul_simp (f : Type) [myfld f] (x : f) : myfld.one .* x = x := \nbegin \n  rw myfld.mul_comm, have h : x = x .* myfld.one, exact myfld.mul_one x, cc, \nend \n\n\n@[simp] lemma add_assoc (f : Type) [myfld f] (x y z : f) : ((x .+ y) .+ z) = (x .+ (y .+ z)) := \nbegin \n  symmetry, exact myfld.add_assoc x y z, \nend \n\n@[simp] lemma mul_comm (f : Type) [myfld f] (x y : f) : x .* y = y .* x := \nbegin \n  exact myfld.mul_comm x y, \nend \n\n@[simp] lemma mul_assoc (f : Type) [myfld f] (x y z : f) : ((x .* y) .* z) = (x .* (y .* z)) := \nbegin \n  symmetry, exact myfld.mul_assoc x y z, \nend \n\nlemma zero_add (f : Type) [myfld f] (x : f) : x = (myfld.zero : f) .+ x := \nbegin \n  rw add_comm f (myfld.zero : f) x, \n  exact (myfld.add_zero : ∀ (x : f), x = (x .+ myfld.zero)) x, \nend \n\n@[simp] lemma zero_simp (f : Type) [myfld f] (x : f) : (x .+ myfld.zero) = x := \nbegin \n  symmetry, exact myfld.add_zero x, \nend \n\n@[simp] lemma simp_zero (f : Type) [myfld f] (x : f) : (myfld.zero .+ x) = x := \nbegin \n  symmetry, exact zero_add f x, \nend \n\n@[simp] lemma distrib_simp (f : Type) [myfld f] (x y z : f) : ((x .+ y) .* z) = ((x .* z) .+ (y .* z)) := \nbegin \n  symmetry, exact myfld.distrib x y z, \nend \n\n@[simp] lemma distrib_simp_alt (f : Type) [myfld f] (x y z : f) : (x .* (y .+ z)) = (x .* y) .+ (x .* z) := \nbegin \n  rw myfld.mul_comm x (y .+ z), rw myfld.mul_comm x y, rw myfld.mul_comm x z, \n  exact distrib_simp f y z x, \nend \n\n@[simp] lemma one_mul (f : Type) [myfld f] (x : f) : (myfld.one : f) .* x = x := \nbegin \n  rw (myfld.mul_comm), symmetry, exact (myfld.mul_one) x, \nend \n\n@[simp] lemma simp_mul_one (f : Type) [myfld f] (x : f) : x .* (myfld.one : f) = x := \nbegin \n  rw myfld.mul_comm, exact one_mul f x, \nend \n\n@[simp] lemma add_negate_simp (f : Type) [myfld f] (x : f) : x .+ .-x = myfld.zero := \nbegin \n  exact myfld.add_negate x, \nend \n\n@[simp] lemma add_negate_simp_alt (f : Type) [myfld f] (x : f) : (.- x) .+ x = myfld.zero := \nbegin \n  rw myfld.add_comm (.- x) x, exact add_negate_simp f x, \nend \n\n@[simp] lemma mul_reciprocal (f : Type) [myfld f] (x : f) (proof : x ≠ myfld.zero) : \n                x .* (myfld.reciprocal x proof) = myfld.one := \nbegin \n  exact myfld.mul_reciprocal x proof, \nend \n\nlemma equal_ne_zero (f : Type) [myfld f] (x y : f) : (x = y) -> (x ≠ myfld.zero) -> (y ≠ myfld.zero) := \nbegin \n  intros h1 h2, rw h1 at h2, exact h2, \nend ", "meta": {"author": "anonymousLeanDocsHosting", "repo": "lean-polynomials", "sha": "361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613", "save_path": "github-repos/lean/anonymousLeanDocsHosting-lean-polynomials", "path": "github-repos/lean/anonymousLeanDocsHosting-lean-polynomials/lean-polynomials-361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613/non-mathlib/field_definition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7935033169724114}}
{"text": "/- Exercise 1.2: Basics — Proofs -/\n\n/- Question 1: Natural numbers -/\n\nnamespace my_nat\n\ndef add : ℕ → ℕ → ℕ\n| 0            n := n\n| (nat.succ m) n := nat.succ (add m n)\n\n\n-- def add : nat → nat → nat\n-- | m nat.zero     := m\n-- | m (nat.succ n) := nat.succ (add m n)\n\n\n\n-- lemma natzero (m : nat) : add m 0 = m:=\n-- begin\n-- induction m,\n-- simp[add],\n-- refl\n-- end\n\n\n-- lemma test (m : nat) :  add 0 m = m:=\n-- begin\n-- induction m,\n-- refl,\n-- simp[add]\n\n-- end\n\n\n-- lemma add_commm (m n : nat) : add m n = add n m :=\n-- begin\n-- induction m,\n-- simp[natzero, add],\n\n\n\n-- end\n\n/- We proved these properties already in the lecture, so we take them as axioms here. (We will often\nuse `sorry` like this to avoid clutter in exercise sheets. But keep in mind that `sorry` is a risky\nconstruct.) -/\n\nlemma add_zero : ∀m : ℕ, add m 0 = m\n| (nat.succ m) := by simp [add, add_zero m]\n| 0            := by refl\n\n\nlemma add_succ : ∀m n : ℕ, add m (nat.succ n) = nat.succ (add m n)\n| m 0 := by refl\n\nlemma add_comm : ∀m n : ℕ, add m n = add n m := sorry\nlemma add_assoc : ∀l m n : ℕ, add (add l m) n = add l (add m n) := sorry\n\ninstance : is_commutative ℕ add := ⟨add_comm⟩\ninstance : is_associative ℕ add := ⟨add_assoc⟩\n\ndef mul : ℕ → ℕ → ℕ\n| 0            _ := 0\n| (nat.succ m) n := add n (mul m n)\n\nlemma mul_add (m n : ℕ) : ∀l : ℕ, mul (add l m) n = add (mul l n) (mul m n) := sorry\n\n/- 1.1. Prove the following recursive equations on the second argument of `mul`. -/\n\nlemma mul_zero : ∀m : ℕ, mul m 0 = 0\n:= sorry\n\nlemma mul_succ : ∀m n : ℕ, mul m (nat.succ n) = add (mul m n) m\n:= sorry\n\n/- 1.2. Prove commutativity and associativity of multiplication by induction. Choose the induction\nvariable carefully. Use the pattern matching syntax. -/\n\nlemma mul_comm : ∀m n : ℕ, mul m n = mul n m\n:= sorry\n\nlemma mul_assoc : ∀l m n : ℕ, mul (mul l m) n = mul l (mul m n)\n:= sorry\n\n/- 1.3. Prove the same lemmas as in 1.2, but using the `induction` tactic instead. Try to reuse as\nmuch of the above proof as possible. -/\n\nexample (m n : ℕ) : mul m n = mul n m :=\nsorry\n\nexample : ∀l m n : ℕ, mul (mul l m) n = mul l (mul m n) :=\nsorry\n\n/- 1.4. Prove the symmetric variant of `mul_add` using `rw`. To apply commutativity at a specific\nposition instantiate the rule (e.g. `mul_comm n`). -/\n\nlemma add_mul (m n l : ℕ) : mul n (add l m) = add (mul n l) (mul n m) :=\nsorry\n\nend my_nat\n\n\n/- Question 2: Lists -/\n\ndef reverse {α : Type} : list α → list α\n| []        := []\n| (x :: xs) := reverse xs ++ [x]\n\n/- Another pesky `sorry`. -/\nlemma reverse_reverse {α : Type} (xs : list α) : reverse (reverse xs) = xs := sorry\n\n/- We define a new accumulator-based version of `reverse`. The first argument serves as the\naccumulator. This definition is *tail-recursive*, meaning that compilers and interpreters can easily\noptimize the recursion away, resulting in more efficient code. -/\n\ndef areverse {α : Type} : list α → list α → list α\n| ys []        := ys\n| ys (x :: xs) := areverse (x :: ys) xs\n\n/- 2.1. Our intention is that `areverse [] xs` should be equal to `reverse xs`. But if we start an\ninduction, we quickly see that the induction hypothesis is not strong enough. Start by proving the\nfollowing generalization (using pattern matching or the `induction` tactic): -/\n\n-- lemma areverse_eq_reverse_append {α : Type} : ∀ys xs : list α, areverse ys xs = reverse xs ++ ys\n-- | [] xs := begin simp[reverse], simp[areverse_eq_reverse] end\n\n/- 2.2. Derive the desired equation. -/\n\nlemma areverse_eq_reverse {α : Type} (xs : list α) : areverse [] xs = reverse xs:=\nbegin induction xs, simp[areverse], simp[reverse], simp[areverse], simp[reverse], rw[<-xs_ih],  end\n\n/- 2.3. Prove the following property. Hint: A one-line inductionless proof is possible. -/\n\nlemma areverse_areverse {α : Type} (xs : list α) : areverse [] (areverse [] xs) = xs :=\n:= sorry\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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7935033093711862}}
{"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 -- the reals\n\n/-!\n\n# Sets in Lean, sheet 6 : pushforward and pullback\n\n## Pushforward of a set along a map\n\nIf `f : X → Y` then given a subset `S : set X` of `X` we can push it\nforward to make a subset `f(S) : set Y` of `Y`. The definition\nof `f(S)` is `{y : Y | ∃ x : X, x ∈ S ∧ f x = y}`. \n\nHowever `f(S)` doesn't make sense in Lean, because `f` eats\nterms of type `X` and not `S`, which has type `set X`. \nIn Lean we use the notation `f '' S` for this. This is notation\nfor `set.image` and if you need any API for this, it's likely\nto use the word `image`.\n\n## Pullback of a set along a map\n\nIf `f : X → Y` then given a subset `T : set Y` of `Y` we can\npull it back to make a subset `f⁻¹(T) : set X` of `X`. The definition\nof `f⁻¹(T)` is `{x : X | f x ∈ T}`.\n\nHowever `f⁻¹(T)` doesn't make sense in Lean either, because\n`⁻¹` is notation for `has_inv.inv`, whose type in Lean\nis `α → α`. In other words, if `x` has a certain type, then\n`x⁻¹` *must* have the same type. The notation was basically designed\nfor group theory. In Lean we use the notation `f ⁻¹' T` for this pullback.\n\n-/\n\nvariables (X Y : Type) (f : X → Y) (S : set X) (T : set Y)\n\nexample : S ⊆ f ⁻¹' (f '' S) :=\nbegin\n  sorry\nend\n\nexample : f '' (f ⁻¹' T) ⊆ T :=\nbegin\n  sorry\nend\n\nexample : f '' S ⊆ T ↔ S ⊆ f ⁻¹' T :=\nbegin\n  sorry\nend\n\n-- image and preimage form a Galois connection\n-- look up Galois connections in the mathlib docs to learn about what these are\n-- right click on `galois_connection` or do `unfold galois_connection` to \n-- find out what this question's asking\n-- NB `≤` on subsets is defined to be `⊆` \nexample : galois_connection (λ S, f '' S) (λ T, f ⁻¹' T) :=\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/section05sets/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8757869965109765, "lm_q1q2_score": 0.7934540992170459}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nimport MultiplicationWorld.Level1 -- zero_mul\nimport MultiplicationWorld.Level4 -- mul_add\nnamespace MyNat\nopen MyNat\n\n/-!\n# Multiplication World\n\n## Level 5: `mul_assoc`\n\nWe now have enough to prove that multiplication is associative.\n\n## Random tactic hints\n\nDid you know you can [repeat](../Tactics/repeat.lean.md) a tactic as many times as necessary\nto complete the goal?\n\n## Lemma\n\nMultiplication is associative.\nIn other words, for all natural numbers `a`, `b` and `c`, we have\n` (ab)c = a(bc). `\n-/\nlemma mul_assoc (a b c : MyNat) : (a * b) * c = a * (b * c) := by\n  induction c with\n  | zero =>\n    rw [zero_is_0]\n    repeat\n      rw [mul_zero]\n  | succ c ih =>\n    rw [mul_succ]\n    rw [mul_succ]\n    rw [ih]\n    rw [mul_add]\n\n/-!\nA mathematician could now remark that you have proved that the natural\nnumbers form a monoid under multiplication.\n-/\n\n-- instance : AddMonoid MyNat where\n--   add_zero := add_zero\n--   zero_add := zero_add\n--   add_assoc := add_assoc\n--   nsmul :=  λ x y => (myNatFromNat x) * y\n--   nsmul_zero' := zero_mul\n--   nsmul_succ' n x := by\n--     simp\n\n-- BUGBUG: complete these instances...\n\n\n/-!\nNext up is [Multiplication Level 6](./Level6.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/MultiplicationWorld/Level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632234212402, "lm_q2_score": 0.8333245994514082, "lm_q1q2_score": 0.7932110393900313}}
{"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, Jeremy Avigad\n\n! This file was ported from Lean 3 source module init.data.nat.lemmas\n! leanprover-community/mathlib commit 38b59111b2b4e6c572582b27e8937e92fc70ac02\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.Basic\nimport Leanbin.Init.Data.Nat.Div\nimport Leanbin.Init.Meta.Default\nimport Leanbin.Init.Algebra.Functions\n\nuniverse u\n\nnamespace Nat\n\nattribute [pre_smt] nat_zero_eq_zero\n\n/-! addition -/\n\n\n#print Nat.add_comm /-\nprotected theorem add_comm : ∀ n m : ℕ, n + m = m + n\n  | n, 0 => Eq.symm (Nat.zero_add n)\n  | n, m + 1 =>\n    suffices succ (n + m) = succ (m + n) from Eq.symm (succ_add m n) ▸ this\n    congr_arg succ (add_comm n m)\n#align nat.add_comm Nat.add_comm\n-/\n\n#print Nat.add_assoc /-\nprotected theorem add_assoc : ∀ n m k : ℕ, n + m + k = n + (m + k)\n  | n, m, 0 => rfl\n  | n, m, succ k => by rw [add_succ, add_succ, add_assoc] <;> rfl\n#align nat.add_assoc Nat.add_assoc\n-/\n\n#print Nat.add_left_comm /-\nprotected theorem add_left_comm : ∀ n m k : ℕ, n + (m + k) = m + (n + k) :=\n  left_comm Nat.add Nat.add_comm Nat.add_assoc\n#align nat.add_left_comm Nat.add_left_comm\n-/\n\n#print Nat.add_left_cancel /-\nprotected theorem add_left_cancel : ∀ {n m k : ℕ}, n + m = n + k → m = k\n  | 0, m, k => by simp (config := { contextual := true }) [Nat.zero_add]\n  | succ n, m, k => fun h =>\n    have : n + m = n + k := by\n      simp [succ_add] at h\n      assumption\n    add_left_cancel this\n#align nat.add_left_cancel Nat.add_left_cancel\n-/\n\n#print Nat.add_right_cancel /-\nprotected theorem add_right_cancel {n m k : ℕ} (h : n + m = k + m) : n = k :=\n  have : m + n = m + k := by rwa [Nat.add_comm n m, Nat.add_comm k m] at h\n  Nat.add_left_cancel this\n#align nat.add_right_cancel Nat.add_right_cancel\n-/\n\n#print Nat.succ_ne_zero /-\ntheorem succ_ne_zero (n : ℕ) : succ n ≠ 0 := fun h => Nat.noConfusion h\n#align nat.succ_ne_zero Nat.succ_ne_zero\n-/\n\n#print Nat.succ_ne_self /-\ntheorem succ_ne_self : ∀ n : ℕ, succ n ≠ n\n  | 0, h => absurd h (Nat.succ_ne_zero 0)\n  | n + 1, h => succ_ne_self n (Nat.noConfusion h fun h => h)\n#align nat.succ_ne_self Nat.succ_ne_self\n-/\n\n#print Nat.one_ne_zero /-\nprotected theorem one_ne_zero : 1 ≠ (0 : ℕ) := fun h => Nat.noConfusion h\n#align nat.one_ne_zero Nat.one_ne_zero\n-/\n\n#print Nat.zero_ne_one /-\nprotected theorem zero_ne_one : 0 ≠ (1 : ℕ) := fun h => Nat.noConfusion h\n#align nat.zero_ne_one Nat.zero_ne_one\n-/\n\n#print Nat.eq_zero_of_add_eq_zero_right /-\nprotected theorem eq_zero_of_add_eq_zero_right : ∀ {n m : ℕ}, n + m = 0 → n = 0\n  | 0, m => by simp [Nat.zero_add]\n  | n + 1, m => fun h => by\n    exfalso\n    rw [add_one, succ_add] at h\n    apply succ_ne_zero _ h\n#align nat.eq_zero_of_add_eq_zero_right Nat.eq_zero_of_add_eq_zero_right\n-/\n\n#print Nat.eq_zero_of_add_eq_zero_left /-\nprotected theorem eq_zero_of_add_eq_zero_left {n m : ℕ} (h : n + m = 0) : m = 0 :=\n  @Nat.eq_zero_of_add_eq_zero_right m n (Nat.add_comm n m ▸ h)\n#align nat.eq_zero_of_add_eq_zero_left Nat.eq_zero_of_add_eq_zero_left\n-/\n\n#print Nat.add_right_comm /-\nprotected theorem add_right_comm : ∀ n m k : ℕ, n + m + k = n + k + m :=\n  right_comm Nat.add Nat.add_comm Nat.add_assoc\n#align nat.add_right_comm Nat.add_right_comm\n-/\n\n#print Nat.eq_zero_of_add_eq_zero /-\ntheorem eq_zero_of_add_eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=\n  ⟨Nat.eq_zero_of_add_eq_zero_right H, Nat.eq_zero_of_add_eq_zero_left H⟩\n#align nat.eq_zero_of_add_eq_zero Nat.eq_zero_of_add_eq_zero\n-/\n\n/-! multiplication -/\n\n\n#print Nat.mul_zero /-\nprotected theorem mul_zero (n : ℕ) : n * 0 = 0 :=\n  rfl\n#align nat.mul_zero Nat.mul_zero\n-/\n\n#print Nat.mul_succ /-\ntheorem mul_succ (n m : ℕ) : n * succ m = n * m + n :=\n  rfl\n#align nat.mul_succ Nat.mul_succ\n-/\n\n#print Nat.zero_mul /-\nprotected theorem zero_mul : ∀ n : ℕ, 0 * n = 0\n  | 0 => rfl\n  | succ n => by rw [mul_succ, MulZeroClass.zero_mul]\n#align nat.zero_mul Nat.zero_mul\n-/\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:330:4: warning: unsupported (TODO): `[tacs] -/\nprivate unsafe def sort_add :=\n  sorry\n#align nat.sort_add nat.sort_add\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.285555777.sort_add -/\n#print Nat.succ_mul /-\ntheorem succ_mul : ∀ n m : ℕ, succ n * m = n * m + m\n  | n, 0 => rfl\n  | n, succ m => by\n    simp [mul_succ, add_succ, succ_mul n m]\n    run_tac\n      sort_add\n#align nat.succ_mul Nat.succ_mul\n-/\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.285555777.sort_add -/\n#print Nat.right_distrib /-\nprotected theorem right_distrib : ∀ n m k : ℕ, (n + m) * k = n * k + m * k\n  | n, m, 0 => rfl\n  | n, m, succ k => by simp [mul_succ, right_distrib n m k];\n    run_tac\n      sort_add\n#align nat.right_distrib Nat.right_distrib\n-/\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic _private.285555777.sort_add -/\n#print Nat.left_distrib /-\nprotected theorem left_distrib : ∀ n m k : ℕ, n * (m + k) = n * m + n * k\n  | 0, m, k => by simp [Nat.zero_mul]\n  | succ n, m, k => by simp [succ_mul, left_distrib n m k];\n    run_tac\n      sort_add\n#align nat.left_distrib Nat.left_distrib\n-/\n\n#print Nat.mul_comm /-\nprotected theorem mul_comm : ∀ n m : ℕ, n * m = m * n\n  | n, 0 => by rw [Nat.zero_mul, Nat.mul_zero]\n  | n, succ m => by simp [mul_succ, succ_mul, mul_comm n m]\n#align nat.mul_comm Nat.mul_comm\n-/\n\n#print Nat.mul_assoc /-\nprotected theorem mul_assoc : ∀ n m k : ℕ, n * m * k = n * (m * k)\n  | n, m, 0 => rfl\n  | n, m, succ k => by simp [mul_succ, Nat.left_distrib, mul_assoc n m k]\n#align nat.mul_assoc Nat.mul_assoc\n-/\n\n#print Nat.mul_one /-\nprotected theorem mul_one : ∀ n : ℕ, n * 1 = n :=\n  Nat.zero_add\n#align nat.mul_one Nat.mul_one\n-/\n\n#print Nat.one_mul /-\nprotected theorem one_mul (n : ℕ) : 1 * n = n := by rw [Nat.mul_comm, Nat.mul_one]\n#align nat.one_mul Nat.one_mul\n-/\n\n#print Nat.succ_add_eq_succ_add /-\ntheorem succ_add_eq_succ_add (n m : ℕ) : succ n + m = n + succ m := by simp [succ_add, add_succ]\n#align nat.succ_add_eq_succ_add Nat.succ_add_eq_succ_add\n-/\n\n#print Nat.eq_zero_of_mul_eq_zero /-\ntheorem eq_zero_of_mul_eq_zero : ∀ {n m : ℕ}, n * m = 0 → n = 0 ∨ m = 0\n  | 0, m => fun h => Or.inl rfl\n  | succ n, m => by\n    rw [succ_mul]; intro h\n    exact Or.inr (Nat.eq_zero_of_add_eq_zero_left h)\n#align nat.eq_zero_of_mul_eq_zero Nat.eq_zero_of_mul_eq_zero\n-/\n\n/-! properties of inequality -/\n\n\n#print Nat.le_of_eq /-\nprotected theorem le_of_eq {n m : ℕ} (p : n = m) : n ≤ m :=\n  p ▸ le.refl\n#align nat.le_of_eq Nat.le_of_eq\n-/\n\n#print Nat.le_succ_of_le /-\ntheorem le_succ_of_le {n m : ℕ} (h : n ≤ m) : n ≤ succ m :=\n  Nat.le_trans h (le_succ m)\n#align nat.le_succ_of_le Nat.le_succ_of_le\n-/\n\n#print Nat.le_of_succ_le /-\ntheorem le_of_succ_le {n m : ℕ} (h : succ n ≤ m) : n ≤ m :=\n  Nat.le_trans (le_succ n) h\n#align nat.le_of_succ_le Nat.le_of_succ_le\n-/\n\n#print Nat.le_of_lt /-\nprotected theorem le_of_lt {n m : ℕ} (h : n < m) : n ≤ m :=\n  le_of_succ_le h\n#align nat.le_of_lt Nat.le_of_lt\n-/\n\n#print Nat.lt.step /-\ntheorem lt.step {n m : ℕ} : n < m → n < succ m :=\n  le.step\n#align nat.lt.step Nat.lt.step\n-/\n\n#print Nat.eq_zero_or_pos /-\nprotected theorem eq_zero_or_pos (n : ℕ) : n = 0 ∨ 0 < n :=\n  by\n  cases n\n  exact Or.inl rfl\n  exact Or.inr (succ_pos _)\n#align nat.eq_zero_or_pos Nat.eq_zero_or_pos\n-/\n\n#print Nat.pos_of_ne_zero /-\nprotected theorem pos_of_ne_zero {n : Nat} : n ≠ 0 → 0 < n :=\n  Or.resolve_left n.eq_zero_or_pos\n#align nat.pos_of_ne_zero Nat.pos_of_ne_zero\n-/\n\n#print Nat.lt_trans /-\nprotected theorem lt_trans {n m k : ℕ} (h₁ : n < m) : m < k → n < k :=\n  Nat.le_trans (le.step h₁)\n#align nat.lt_trans Nat.lt_trans\n-/\n\n#print Nat.lt_of_le_of_lt /-\nprotected theorem lt_of_le_of_lt {n m k : ℕ} (h₁ : n ≤ m) : m < k → n < k :=\n  Nat.le_trans (succ_le_succ h₁)\n#align nat.lt_of_le_of_lt Nat.lt_of_le_of_lt\n-/\n\n#print Nat.lt.base /-\ntheorem lt.base (n : ℕ) : n < succ n :=\n  Nat.le_refl (succ n)\n#align nat.lt.base Nat.lt.base\n-/\n\n#print Nat.lt_succ_self /-\ntheorem lt_succ_self (n : ℕ) : n < succ n :=\n  lt.base n\n#align nat.lt_succ_self Nat.lt_succ_self\n-/\n\n#print Nat.le_antisymm /-\nprotected theorem le_antisymm {n m : ℕ} (h₁ : n ≤ m) : m ≤ n → n = m :=\n  le.cases_on h₁ (fun a => rfl) fun a b c => absurd (Nat.lt_of_le_of_lt b c) (Nat.lt_irrefl n)\n#align nat.le_antisymm Nat.le_antisymm\n-/\n\n#print Nat.lt_or_ge /-\nprotected theorem lt_or_ge : ∀ a b : ℕ, a < b ∨ b ≤ a\n  | a, 0 => Or.inr a.zero_le\n  | a, b + 1 =>\n    match lt_or_ge a b with\n    | Or.inl h => Or.inl (le_succ_of_le h)\n    | Or.inr h =>\n      match Nat.eq_or_lt_of_le h with\n      | Or.inl h1 => Or.inl (h1 ▸ lt_succ_self b)\n      | Or.inr h1 => Or.inr h1\n#align nat.lt_or_ge Nat.lt_or_ge\n-/\n\n#print Nat.le_total /-\nprotected theorem le_total {m n : ℕ} : m ≤ n ∨ n ≤ m :=\n  Or.imp_left Nat.le_of_lt (Nat.lt_or_ge m n)\n#align nat.le_total Nat.le_total\n-/\n\nprotected theorem lt_of_le_and_ne {m n : ℕ} (h1 : m ≤ n) : m ≠ n → m < n :=\n  Or.resolve_right (Or.symm (Nat.eq_or_lt_of_le h1))\n#align nat.lt_of_le_and_ne Nat.lt_of_le_and_ne\n\n#print Nat.lt_iff_le_not_le /-\nprotected theorem lt_iff_le_not_le {m n : ℕ} : m < n ↔ m ≤ n ∧ ¬n ≤ m :=\n  ⟨fun hmn => ⟨Nat.le_of_lt hmn, fun hnm => Nat.lt_irrefl _ (Nat.lt_of_le_of_lt hnm hmn)⟩,\n    fun ⟨hmn, hnm⟩ => Nat.lt_of_le_and_ne hmn fun heq => hnm (HEq ▸ Nat.le_refl _)⟩\n#align nat.lt_iff_le_not_le Nat.lt_iff_le_not_le\n-/\n\ninstance : LinearOrder ℕ where\n  le := Nat.le\n  le_refl := @Nat.le_refl\n  le_trans := @Nat.le_trans\n  le_antisymm := @Nat.le_antisymm\n  le_total := @Nat.le_total\n  lt := Nat.lt\n  lt_iff_le_not_le := @Nat.lt_iff_le_not_le\n  decidableLt := Nat.decidableLt\n  decidableLe := Nat.decidableLe\n  DecidableEq := Nat.decidableEq\n\n#print Nat.eq_zero_of_le_zero /-\nprotected theorem eq_zero_of_le_zero {n : Nat} (h : n ≤ 0) : n = 0 :=\n  le_antisymm h n.zero_le\n#align nat.eq_zero_of_le_zero Nat.eq_zero_of_le_zero\n-/\n\n#print Nat.succ_lt_succ /-\ntheorem succ_lt_succ {a b : ℕ} : a < b → succ a < succ b :=\n  succ_le_succ\n#align nat.succ_lt_succ Nat.succ_lt_succ\n-/\n\n#print Nat.lt_of_succ_lt /-\ntheorem lt_of_succ_lt {a b : ℕ} : succ a < b → a < b :=\n  le_of_succ_le\n#align nat.lt_of_succ_lt Nat.lt_of_succ_lt\n-/\n\n#print Nat.lt_of_succ_lt_succ /-\ntheorem lt_of_succ_lt_succ {a b : ℕ} : succ a < succ b → a < b :=\n  le_of_succ_le_succ\n#align nat.lt_of_succ_lt_succ Nat.lt_of_succ_lt_succ\n-/\n\n#print Nat.pred_lt_pred /-\ntheorem pred_lt_pred : ∀ {n m : ℕ}, n ≠ 0 → n < m → pred n < pred m\n  | 0, _, h₁, h => absurd rfl h₁\n  | n, 0, h₁, h => absurd h n.not_lt_zero\n  | succ n, succ m, _, h => lt_of_succ_lt_succ h\n#align nat.pred_lt_pred Nat.pred_lt_pred\n-/\n\n#print Nat.lt_of_succ_le /-\ntheorem lt_of_succ_le {a b : ℕ} (h : succ a ≤ b) : a < b :=\n  h\n#align nat.lt_of_succ_le Nat.lt_of_succ_le\n-/\n\n#print Nat.succ_le_of_lt /-\ntheorem succ_le_of_lt {a b : ℕ} (h : a < b) : succ a ≤ b :=\n  h\n#align nat.succ_le_of_lt Nat.succ_le_of_lt\n-/\n\n#print Nat.le_add_right /-\nprotected theorem le_add_right : ∀ n k : ℕ, n ≤ n + k\n  | n, 0 => Nat.le_refl n\n  | n, k + 1 => le_succ_of_le (le_add_right n k)\n#align nat.le_add_right Nat.le_add_right\n-/\n\n#print Nat.le_add_left /-\nprotected theorem le_add_left (n m : ℕ) : n ≤ m + n :=\n  Nat.add_comm n m ▸ n.le_add_right m\n#align nat.le_add_left Nat.le_add_left\n-/\n\n#print Nat.le.dest /-\ntheorem le.dest : ∀ {n m : ℕ}, n ≤ m → ∃ k, n + k = m\n  | n, _, less_than_or_equal.refl => ⟨0, rfl⟩\n  | n, _, less_than_or_equal.step h =>\n    match le.dest h with\n    | ⟨w, hw⟩ => ⟨succ w, hw ▸ add_succ n w⟩\n#align nat.le.dest Nat.le.dest\n-/\n\n#print Nat.le.intro /-\nprotected theorem le.intro {n m k : ℕ} (h : n + k = m) : n ≤ m :=\n  h ▸ n.le_add_right k\n#align nat.le.intro Nat.le.intro\n-/\n\n#print Nat.add_le_add_left /-\nprotected theorem add_le_add_left {n m : ℕ} (h : n ≤ m) (k : ℕ) : k + n ≤ k + m :=\n  match le.dest h with\n  | ⟨w, hw⟩ => @le.intro _ _ w (by rw [Nat.add_assoc, hw])\n#align nat.add_le_add_left Nat.add_le_add_left\n-/\n\n#print Nat.add_le_add_right /-\nprotected theorem add_le_add_right {n m : ℕ} (h : n ≤ m) (k : ℕ) : n + k ≤ m + k := by\n  rw [Nat.add_comm n k, Nat.add_comm m k]; apply Nat.add_le_add_left h\n#align nat.add_le_add_right Nat.add_le_add_right\n-/\n\n#print Nat.le_of_add_le_add_left /-\nprotected theorem le_of_add_le_add_left {k n m : ℕ} (h : k + n ≤ k + m) : n ≤ m :=\n  match le.dest h with\n  | ⟨w, hw⟩ =>\n    @le.intro _ _ w\n      (by\n        rw [Nat.add_assoc] at hw\n        apply Nat.add_left_cancel hw)\n#align nat.le_of_add_le_add_left Nat.le_of_add_le_add_left\n-/\n\nprotected theorem le_of_add_le_add_right {k n m : ℕ} : n + k ≤ m + k → n ≤ m :=\n  by\n  rw [Nat.add_comm _ k, Nat.add_comm _ k]\n  apply Nat.le_of_add_le_add_left\n#align nat.le_of_add_le_add_right Nat.le_of_add_le_add_rightₓ\n\nprotected theorem add_le_add_iff_right {k n m : ℕ} : n + k ≤ m + k ↔ n ≤ m :=\n  ⟨Nat.le_of_add_le_add_right, fun h => Nat.add_le_add_right h _⟩\n#align nat.add_le_add_iff_right Nat.add_le_add_iff_right\n\n#print Nat.lt_of_add_lt_add_left /-\nprotected theorem lt_of_add_lt_add_left {k n m : ℕ} (h : k + n < k + m) : n < m :=\n  let h' := Nat.le_of_lt h\n  Nat.lt_of_le_and_ne (Nat.le_of_add_le_add_left h') fun heq =>\n    Nat.lt_irrefl (k + m) (by rw [HEq] at h; assumption)\n#align nat.lt_of_add_lt_add_left Nat.lt_of_add_lt_add_left\n-/\n\n#print Nat.lt_of_add_lt_add_right /-\nprotected theorem lt_of_add_lt_add_right {a b c : ℕ} (h : a + b < c + b) : a < c :=\n  Nat.lt_of_add_lt_add_left <| show b + a < b + c by rwa [Nat.add_comm b a, Nat.add_comm b c]\n#align nat.lt_of_add_lt_add_right Nat.lt_of_add_lt_add_right\n-/\n\n#print Nat.add_lt_add_left /-\nprotected theorem add_lt_add_left {n m : ℕ} (h : n < m) (k : ℕ) : k + n < k + m :=\n  lt_of_succ_le (add_succ k n ▸ Nat.add_le_add_left (succ_le_of_lt h) k)\n#align nat.add_lt_add_left Nat.add_lt_add_left\n-/\n\n#print Nat.add_lt_add_right /-\nprotected theorem add_lt_add_right {n m : ℕ} (h : n < m) (k : ℕ) : n + k < m + k :=\n  Nat.add_comm k m ▸ Nat.add_comm k n ▸ Nat.add_lt_add_left h k\n#align nat.add_lt_add_right Nat.add_lt_add_right\n-/\n\n#print Nat.lt_add_of_pos_right /-\nprotected theorem lt_add_of_pos_right {n k : ℕ} (h : 0 < k) : n < n + k :=\n  Nat.add_lt_add_left h n\n#align nat.lt_add_of_pos_right Nat.lt_add_of_pos_right\n-/\n\n#print Nat.lt_add_of_pos_left /-\nprotected theorem lt_add_of_pos_left {n k : ℕ} (h : 0 < k) : n < k + n := by\n  rw [Nat.add_comm] <;> exact Nat.lt_add_of_pos_right h\n#align nat.lt_add_of_pos_left Nat.lt_add_of_pos_left\n-/\n\n#print Nat.add_lt_add /-\nprotected theorem add_lt_add {a b c d : ℕ} (h₁ : a < b) (h₂ : c < d) : a + c < b + d :=\n  lt_trans (Nat.add_lt_add_right h₁ c) (Nat.add_lt_add_left h₂ b)\n#align nat.add_lt_add Nat.add_lt_add\n-/\n\n#print Nat.add_le_add /-\nprotected theorem add_le_add {a b c d : ℕ} (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d :=\n  le_trans (Nat.add_le_add_right h₁ c) (Nat.add_le_add_left h₂ b)\n#align nat.add_le_add Nat.add_le_add\n-/\n\n#print Nat.zero_lt_one /-\nprotected theorem zero_lt_one : 0 < (1 : Nat) :=\n  zero_lt_succ 0\n#align nat.zero_lt_one Nat.zero_lt_one\n-/\n\n#print Nat.mul_le_mul_left /-\nprotected theorem mul_le_mul_left {n m : ℕ} (k : ℕ) (h : n ≤ m) : k * n ≤ k * m :=\n  match le.dest h with\n  | ⟨l, hl⟩ =>\n    have : k * n + k * l = k * m := by rw [← Nat.left_distrib, hl]\n    le.intro this\n#align nat.mul_le_mul_left Nat.mul_le_mul_left\n-/\n\n#print Nat.mul_le_mul_right /-\nprotected theorem mul_le_mul_right {n m : ℕ} (k : ℕ) (h : n ≤ m) : n * k ≤ m * k :=\n  Nat.mul_comm k m ▸ Nat.mul_comm k n ▸ k.mul_le_mul_left h\n#align nat.mul_le_mul_right Nat.mul_le_mul_right\n-/\n\n#print Nat.mul_lt_mul_of_pos_left /-\nprotected theorem mul_lt_mul_of_pos_left {n m k : ℕ} (h : n < m) (hk : 0 < k) : k * n < k * m :=\n  Nat.lt_of_lt_of_le (Nat.lt_add_of_pos_right hk)\n    (mul_succ k n ▸ Nat.mul_le_mul_left k (succ_le_of_lt h))\n#align nat.mul_lt_mul_of_pos_left Nat.mul_lt_mul_of_pos_left\n-/\n\n#print Nat.mul_lt_mul_of_pos_right /-\nprotected theorem mul_lt_mul_of_pos_right {n m k : ℕ} (h : n < m) (hk : 0 < k) : n * k < m * k :=\n  Nat.mul_comm k m ▸ Nat.mul_comm k n ▸ Nat.mul_lt_mul_of_pos_left h hk\n#align nat.mul_lt_mul_of_pos_right Nat.mul_lt_mul_of_pos_right\n-/\n\n#print Nat.le_of_mul_le_mul_left /-\nprotected theorem le_of_mul_le_mul_left {a b c : ℕ} (h : c * a ≤ c * b) (hc : 0 < c) : a ≤ b :=\n  not_lt.1 fun h1 : b < a =>\n    have h2 : c * b < c * a := Nat.mul_lt_mul_of_pos_left h1 hc\n    not_le_of_gt h2 h\n#align nat.le_of_mul_le_mul_left Nat.le_of_mul_le_mul_left\n-/\n\n#print Nat.le_of_lt_succ /-\ntheorem le_of_lt_succ {m n : Nat} : m < succ n → m ≤ n :=\n  le_of_succ_le_succ\n#align nat.le_of_lt_succ Nat.le_of_lt_succ\n-/\n\n#print Nat.eq_of_mul_eq_mul_left /-\nprotected theorem eq_of_mul_eq_mul_left {m k n : ℕ} (Hn : 0 < n) (H : n * m = n * k) : m = k :=\n  le_antisymm (Nat.le_of_mul_le_mul_left (le_of_eq H) Hn)\n    (Nat.le_of_mul_le_mul_left (le_of_eq H.symm) Hn)\n#align nat.eq_of_mul_eq_mul_left Nat.eq_of_mul_eq_mul_left\n-/\n\n#print Nat.mul_pos /-\nprotected theorem mul_pos {a b : ℕ} (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=\n  by\n  have h : 0 * b < a * b := Nat.mul_lt_mul_of_pos_right ha hb\n  rwa [Nat.zero_mul] at h\n#align nat.mul_pos Nat.mul_pos\n-/\n\n#print Nat.le_succ_of_pred_le /-\ntheorem le_succ_of_pred_le {n m : ℕ} : pred n ≤ m → n ≤ succ m :=\n  Nat.casesOn n le.step fun a => succ_le_succ\n#align nat.le_succ_of_pred_le Nat.le_succ_of_pred_le\n-/\n\n#print Nat.le_lt_antisymm /-\ntheorem le_lt_antisymm {n m : ℕ} (h₁ : n ≤ m) (h₂ : m < n) : False :=\n  Nat.lt_irrefl n (Nat.lt_of_le_of_lt h₁ h₂)\n#align nat.le_lt_antisymm Nat.le_lt_antisymm\n-/\n\n#print Nat.lt_le_antisymm /-\ntheorem lt_le_antisymm {n m : ℕ} (h₁ : n < m) (h₂ : m ≤ n) : False :=\n  le_lt_antisymm h₂ h₁\n#align nat.lt_le_antisymm Nat.lt_le_antisymm\n-/\n\n#print Nat.lt_asymm /-\nprotected theorem lt_asymm {n m : ℕ} (h₁ : n < m) : ¬m < n :=\n  le_lt_antisymm (Nat.le_of_lt h₁)\n#align nat.lt_asymm Nat.lt_asymm\n-/\n\nprotected def ltGeByCases {a b : ℕ} {C : Sort u} (h₁ : a < b → C) (h₂ : b ≤ a → C) : C :=\n  Decidable.byCases h₁ fun h => h₂ (Or.elim (Nat.lt_or_ge a b) (fun a => absurd a h) fun a => a)\n#align nat.lt_ge_by_cases Nat.ltGeByCases\n\nprotected def ltByCases {a b : ℕ} {C : Sort u} (h₁ : a < b → C) (h₂ : a = b → C) (h₃ : b < a → C) :\n    C :=\n  Nat.ltGeByCases h₁ fun h₁ => Nat.ltGeByCases h₃ fun h => h₂ (Nat.le_antisymm h h₁)\n#align nat.lt_by_cases Nat.ltByCases\n\n#print Nat.lt_trichotomy /-\nprotected theorem lt_trichotomy (a b : ℕ) : a < b ∨ a = b ∨ b < a :=\n  Nat.ltByCases (fun h => Or.inl h) (fun h => Or.inr (Or.inl h)) fun h => Or.inr (Or.inr h)\n#align nat.lt_trichotomy Nat.lt_trichotomy\n-/\n\n#print Nat.eq_or_lt_of_not_lt /-\nprotected theorem eq_or_lt_of_not_lt {a b : ℕ} (hnlt : ¬a < b) : a = b ∨ b < a :=\n  (Nat.lt_trichotomy a b).resolve_left hnlt\n#align nat.eq_or_lt_of_not_lt Nat.eq_or_lt_of_not_lt\n-/\n\n#print Nat.lt_succ_of_lt /-\ntheorem lt_succ_of_lt {a b : Nat} (h : a < b) : a < succ b :=\n  le_succ_of_le h\n#align nat.lt_succ_of_lt Nat.lt_succ_of_lt\n-/\n\n#print Nat.one_pos /-\ntheorem one_pos : 0 < 1 :=\n  Nat.zero_lt_one\n#align nat.one_pos Nat.one_pos\n-/\n\n#print Nat.mul_le_mul_of_nonneg_left /-\nprotected theorem mul_le_mul_of_nonneg_left {a b c : ℕ} (h₁ : a ≤ b) : c * a ≤ c * b :=\n  by\n  by_cases hba : b ≤ a; · simp [le_antisymm hba h₁]\n  by_cases hc0 : c ≤ 0; · simp [le_antisymm hc0 c.zero_le, Nat.zero_mul]\n  exact\n    (le_not_le_of_lt\n        (Nat.mul_lt_mul_of_pos_left (lt_of_le_not_le h₁ hba) (lt_of_le_not_le c.zero_le hc0))).left\n#align nat.mul_le_mul_of_nonneg_left Nat.mul_le_mul_of_nonneg_left\n-/\n\n#print Nat.mul_le_mul_of_nonneg_right /-\nprotected theorem mul_le_mul_of_nonneg_right {a b c : ℕ} (h₁ : a ≤ b) : a * c ≤ b * c :=\n  by\n  by_cases hba : b ≤ a; · simp [le_antisymm hba h₁]\n  by_cases hc0 : c ≤ 0; · simp [le_antisymm hc0 c.zero_le, Nat.mul_zero]\n  exact\n    (le_not_le_of_lt\n        (Nat.mul_lt_mul_of_pos_right (lt_of_le_not_le h₁ hba) (lt_of_le_not_le c.zero_le hc0))).left\n#align nat.mul_le_mul_of_nonneg_right Nat.mul_le_mul_of_nonneg_right\n-/\n\nprotected theorem mul_lt_mul {a b c d : ℕ} (hac : a < c) (hbd : b ≤ d) (pos_b : 0 < b) :\n    a * b < c * d :=\n  calc\n    a * b < c * b := Nat.mul_lt_mul_of_pos_right hac pos_b\n    _ ≤ c * d := Nat.mul_le_mul_of_nonneg_left hbd\n    \n#align nat.mul_lt_mul Nat.mul_lt_mulₓ\n\nprotected theorem mul_lt_mul' {a b c d : ℕ} (h1 : a ≤ c) (h2 : b < d) (h3 : 0 < c) :\n    a * b < c * d :=\n  calc\n    a * b ≤ c * b := Nat.mul_le_mul_of_nonneg_right h1\n    _ < c * d := Nat.mul_lt_mul_of_pos_left h2 h3\n    \n#align nat.mul_lt_mul' Nat.mul_lt_mul'ₓ\n\n#print Nat.mul_le_mul /-\n-- TODO: there are four variations, depending on which variables we assume to be nonneg\nprotected theorem mul_le_mul {a b c d : ℕ} (hac : a ≤ c) (hbd : b ≤ d) : a * b ≤ c * d :=\n  calc\n    a * b ≤ c * b := Nat.mul_le_mul_of_nonneg_right hac\n    _ ≤ c * d := Nat.mul_le_mul_of_nonneg_left hbd\n    \n#align nat.mul_le_mul Nat.mul_le_mul\n-/\n\n/-! bit0/bit1 properties -/\n\n\n#print Nat.bit1_eq_succ_bit0 /-\nprotected theorem bit1_eq_succ_bit0 (n : ℕ) : bit1 n = succ (bit0 n) :=\n  rfl\n#align nat.bit1_eq_succ_bit0 Nat.bit1_eq_succ_bit0\n-/\n\n#print Nat.bit1_succ_eq /-\nprotected theorem bit1_succ_eq (n : ℕ) : bit1 (succ n) = succ (succ (bit1 n)) :=\n  Eq.trans (Nat.bit1_eq_succ_bit0 (succ n)) (congr_arg succ (Nat.bit0_succ_eq n))\n#align nat.bit1_succ_eq Nat.bit1_succ_eq\n-/\n\n#print Nat.bit1_ne_one /-\nprotected theorem bit1_ne_one : ∀ {n : ℕ}, n ≠ 0 → bit1 n ≠ 1\n  | 0, h, h1 => absurd rfl h\n  | n + 1, h, h1 => Nat.noConfusion h1 fun h2 => absurd h2 (succ_ne_zero _)\n#align nat.bit1_ne_one Nat.bit1_ne_one\n-/\n\n#print Nat.bit0_ne_one /-\nprotected theorem bit0_ne_one : ∀ n : ℕ, bit0 n ≠ 1\n  | 0, h => absurd h (Ne.symm Nat.one_ne_zero)\n  | n + 1, h =>\n    have h1 : succ (succ (n + n)) = 1 := succ_add n n ▸ h\n    Nat.noConfusion h1 fun h2 => absurd h2 (succ_ne_zero (n + n))\n#align nat.bit0_ne_one Nat.bit0_ne_one\n-/\n\n#print Nat.add_self_ne_one /-\nprotected theorem add_self_ne_one : ∀ n : ℕ, n + n ≠ 1\n  | 0, h => Nat.noConfusion h\n  | n + 1, h =>\n    have h1 : succ (succ (n + n)) = 1 := succ_add n n ▸ h\n    Nat.noConfusion h1 fun h2 => absurd h2 (Nat.succ_ne_zero (n + n))\n#align nat.add_self_ne_one Nat.add_self_ne_one\n-/\n\n#print Nat.bit1_ne_bit0 /-\nprotected theorem bit1_ne_bit0 : ∀ n m : ℕ, bit1 n ≠ bit0 m\n  | 0, m, h => absurd h (Ne.symm (Nat.add_self_ne_one m))\n  | n + 1, 0, h =>\n    have h1 : succ (bit0 (succ n)) = 0 := h\n    absurd h1 (Nat.succ_ne_zero _)\n  | n + 1, m + 1, h =>\n    have h1 : succ (succ (bit1 n)) = succ (succ (bit0 m)) :=\n      Nat.bit0_succ_eq m ▸ Nat.bit1_succ_eq n ▸ h\n    have h2 : bit1 n = bit0 m := Nat.noConfusion h1 fun h2' => Nat.noConfusion h2' fun h2'' => h2''\n    absurd h2 (bit1_ne_bit0 n m)\n#align nat.bit1_ne_bit0 Nat.bit1_ne_bit0\n-/\n\n#print Nat.bit0_ne_bit1 /-\nprotected theorem bit0_ne_bit1 : ∀ n m : ℕ, bit0 n ≠ bit1 m := fun n m : Nat =>\n  Ne.symm (Nat.bit1_ne_bit0 m n)\n#align nat.bit0_ne_bit1 Nat.bit0_ne_bit1\n-/\n\n#print Nat.bit0_inj /-\nprotected theorem bit0_inj : ∀ {n m : ℕ}, bit0 n = bit0 m → n = m\n  | 0, 0, h => rfl\n  | 0, m + 1, h => by contradiction\n  | n + 1, 0, h => by contradiction\n  | n + 1, m + 1, h =>\n    by\n    have : succ (succ (n + n)) = succ (succ (m + m)) :=\n      by\n      unfold bit0 at h\n      simp [add_one, add_succ, succ_add] at h\n      have aux : n + n = m + m := h\n      rw [aux]\n    have : n + n = m + m := by repeat injection this with this\n    have : n = m := bit0_inj this\n    rw [this]\n#align nat.bit0_inj Nat.bit0_inj\n-/\n\n#print Nat.bit1_inj /-\nprotected theorem bit1_inj : ∀ {n m : ℕ}, bit1 n = bit1 m → n = m := fun n m h =>\n  have : succ (bit0 n) = succ (bit0 m) := by simp [Nat.bit1_eq_succ_bit0] at h; rw [h]\n  have : bit0 n = bit0 m := by injection this\n  Nat.bit0_inj this\n#align nat.bit1_inj Nat.bit1_inj\n-/\n\n#print Nat.bit0_ne /-\nprotected theorem bit0_ne {n m : ℕ} : n ≠ m → bit0 n ≠ bit0 m := fun h₁ h₂ =>\n  absurd (Nat.bit0_inj h₂) h₁\n#align nat.bit0_ne Nat.bit0_ne\n-/\n\n#print Nat.bit1_ne /-\nprotected theorem bit1_ne {n m : ℕ} : n ≠ m → bit1 n ≠ bit1 m := fun h₁ h₂ =>\n  absurd (Nat.bit1_inj h₂) h₁\n#align nat.bit1_ne Nat.bit1_ne\n-/\n\n#print Nat.zero_ne_bit0 /-\nprotected theorem zero_ne_bit0 {n : ℕ} : n ≠ 0 → 0 ≠ bit0 n := fun h => Ne.symm (Nat.bit0_ne_zero h)\n#align nat.zero_ne_bit0 Nat.zero_ne_bit0\n-/\n\n#print Nat.zero_ne_bit1 /-\nprotected theorem zero_ne_bit1 (n : ℕ) : 0 ≠ bit1 n :=\n  Ne.symm (Nat.bit1_ne_zero n)\n#align nat.zero_ne_bit1 Nat.zero_ne_bit1\n-/\n\n#print Nat.one_ne_bit0 /-\nprotected theorem one_ne_bit0 (n : ℕ) : 1 ≠ bit0 n :=\n  Ne.symm (Nat.bit0_ne_one n)\n#align nat.one_ne_bit0 Nat.one_ne_bit0\n-/\n\n#print Nat.one_ne_bit1 /-\nprotected theorem one_ne_bit1 {n : ℕ} : n ≠ 0 → 1 ≠ bit1 n := fun h => Ne.symm (Nat.bit1_ne_one h)\n#align nat.one_ne_bit1 Nat.one_ne_bit1\n-/\n\n#print Nat.one_lt_bit1 /-\nprotected theorem one_lt_bit1 : ∀ {n : Nat}, n ≠ 0 → 1 < bit1 n\n  | 0, h => by contradiction\n  | succ n, h => by\n    rw [Nat.bit1_succ_eq]\n    apply succ_lt_succ\n    apply zero_lt_succ\n#align nat.one_lt_bit1 Nat.one_lt_bit1\n-/\n\n#print Nat.one_lt_bit0 /-\nprotected theorem one_lt_bit0 : ∀ {n : Nat}, n ≠ 0 → 1 < bit0 n\n  | 0, h => by contradiction\n  | succ n, h => by\n    rw [Nat.bit0_succ_eq]\n    apply succ_lt_succ\n    apply zero_lt_succ\n#align nat.one_lt_bit0 Nat.one_lt_bit0\n-/\n\n#print Nat.bit0_lt /-\nprotected theorem bit0_lt {n m : Nat} (h : n < m) : bit0 n < bit0 m :=\n  Nat.add_lt_add h h\n#align nat.bit0_lt Nat.bit0_lt\n-/\n\n#print Nat.bit1_lt /-\nprotected theorem bit1_lt {n m : Nat} (h : n < m) : bit1 n < bit1 m :=\n  succ_lt_succ (Nat.add_lt_add h h)\n#align nat.bit1_lt Nat.bit1_lt\n-/\n\n#print Nat.bit0_lt_bit1 /-\nprotected theorem bit0_lt_bit1 {n m : Nat} (h : n ≤ m) : bit0 n < bit1 m :=\n  lt_succ_of_le (Nat.add_le_add h h)\n#align nat.bit0_lt_bit1 Nat.bit0_lt_bit1\n-/\n\n#print Nat.bit1_lt_bit0 /-\nprotected theorem bit1_lt_bit0 : ∀ {n m : Nat}, n < m → bit1 n < bit0 m\n  | n, 0, h => absurd h n.not_lt_zero\n  | n, succ m, h =>\n    have : n ≤ m := le_of_lt_succ h\n    have : succ (n + n) ≤ succ (m + m) := succ_le_succ (Nat.add_le_add this this)\n    have : succ (n + n) ≤ succ m + m := by rw [succ_add]; assumption\n    show succ (n + n) < succ (succ m + m) from lt_succ_of_le this\n#align nat.bit1_lt_bit0 Nat.bit1_lt_bit0\n-/\n\n#print Nat.one_le_bit1 /-\nprotected theorem one_le_bit1 (n : ℕ) : 1 ≤ bit1 n :=\n  show 1 ≤ succ (bit0 n) from succ_le_succ (bit0 n).zero_le\n#align nat.one_le_bit1 Nat.one_le_bit1\n-/\n\n#print Nat.one_le_bit0 /-\nprotected theorem one_le_bit0 : ∀ n : ℕ, n ≠ 0 → 1 ≤ bit0 n\n  | 0, h => absurd rfl h\n  | n + 1, h =>\n    suffices 1 ≤ succ (succ (bit0 n)) from Eq.symm (Nat.bit0_succ_eq n) ▸ this\n    succ_le_succ (bit0 n).succ.zero_le\n#align nat.one_le_bit0 Nat.one_le_bit0\n-/\n\n/-! successor and predecessor -/\n\n\n#print Nat.pred_zero /-\n@[simp]\ntheorem pred_zero : pred 0 = 0 :=\n  rfl\n#align nat.pred_zero Nat.pred_zero\n-/\n\n#print Nat.pred_succ /-\n@[simp]\ntheorem pred_succ (n : ℕ) : pred (succ n) = n :=\n  rfl\n#align nat.pred_succ Nat.pred_succ\n-/\n\n#print Nat.add_one_ne_zero /-\ntheorem add_one_ne_zero (n : ℕ) : n + 1 ≠ 0 :=\n  succ_ne_zero _\n#align nat.add_one_ne_zero Nat.add_one_ne_zero\n-/\n\n#print Nat.eq_zero_or_eq_succ_pred /-\ntheorem eq_zero_or_eq_succ_pred (n : ℕ) : n = 0 ∨ n = succ (pred n) := by cases n <;> simp\n#align nat.eq_zero_or_eq_succ_pred Nat.eq_zero_or_eq_succ_pred\n-/\n\n#print Nat.exists_eq_succ_of_ne_zero /-\ntheorem exists_eq_succ_of_ne_zero {n : ℕ} (H : n ≠ 0) : ∃ k : ℕ, n = succ k :=\n  ⟨_, (eq_zero_or_eq_succ_pred _).resolve_left H⟩\n#align nat.exists_eq_succ_of_ne_zero Nat.exists_eq_succ_of_ne_zero\n-/\n\n/- warning: nat.discriminate clashes with [anonymous] -> [anonymous]\nwarning: nat.discriminate -> [anonymous] is a dubious translation:\nlean 3 declaration is\n  forall {B : Sort.{u}} {n : Nat}, ((Eq.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> B) -> (forall (m : Nat), (Eq.{1} Nat n (Nat.succ m)) -> B) -> B\nbut is expected to have type\n  forall {B : Type.{u}} {n : Type.{v}}, (Nat -> B -> n) -> Nat -> (List.{u} B) -> (List.{v} n)\nCase conversion may be inaccurate. Consider using '#align nat.discriminate [anonymous]ₓ'. -/\ndef [anonymous] {B : Sort u} {n : ℕ} (H1 : n = 0 → B) (H2 : ∀ m, n = succ m → B) : B := by\n  induction' h : n with <;> [exact H1 h, exact H2 _ h]\n#align nat.discriminate [anonymous]\n\ntheorem one_succ_zero : 1 = succ 0 :=\n  rfl\n#align nat.one_succ_zero Nat.one_succ_zero\n\n#print Nat.pred_inj /-\ntheorem pred_inj : ∀ {a b : Nat}, 0 < a → 0 < b → Nat.pred a = Nat.pred b → a = b\n  | succ a, succ b, ha, hb, h => by\n    have : a = b := h\n    rw [this]\n  | succ a, 0, ha, hb, h => absurd hb (lt_irrefl _)\n  | 0, succ b, ha, hb, h => absurd ha (lt_irrefl _)\n  | 0, 0, ha, hb, h => rfl\n#align nat.pred_inj Nat.pred_inj\n-/\n\n/-! subtraction\n\nMany lemmas are proven more generally in mathlib `algebra/order/sub` -/\n\n\n#print Nat.zero_sub /-\n@[simp]\nprotected theorem zero_sub : ∀ a : ℕ, 0 - a = 0\n  | 0 => rfl\n  | a + 1 => congr_arg pred (zero_sub a)\n#align nat.zero_sub Nat.zero_sub\n-/\n\n#print Nat.sub_lt_succ /-\ntheorem sub_lt_succ (a b : ℕ) : a - b < succ a :=\n  lt_succ_of_le (a.sub_le b)\n#align nat.sub_lt_succ Nat.sub_lt_succ\n-/\n\n#print Nat.sub_le_sub_right /-\nprotected theorem sub_le_sub_right {n m : ℕ} (h : n ≤ m) : ∀ k, n - k ≤ m - k\n  | 0 => h\n  | succ z => pred_le_pred (sub_le_sub_right z)\n#align nat.sub_le_sub_right Nat.sub_le_sub_right\n-/\n\n#print Nat.sub_zero /-\n@[simp]\nprotected theorem sub_zero (n : ℕ) : n - 0 = n :=\n  rfl\n#align nat.sub_zero Nat.sub_zero\n-/\n\n#print Nat.sub_succ /-\ntheorem sub_succ (n m : ℕ) : n - succ m = pred (n - m) :=\n  rfl\n#align nat.sub_succ Nat.sub_succ\n-/\n\n#print Nat.succ_sub_succ /-\ntheorem succ_sub_succ (n m : ℕ) : succ n - succ m = n - m :=\n  succ_sub_succ_eq_sub n m\n#align nat.succ_sub_succ Nat.succ_sub_succ\n-/\n\n#print Nat.sub_self /-\nprotected theorem sub_self : ∀ n : ℕ, n - n = 0\n  | 0 => by rw [Nat.sub_zero]\n  | succ n => by rw [succ_sub_succ, sub_self n]\n#align nat.sub_self Nat.sub_self\n-/\n\n#print Nat.add_sub_add_right /-\n/- TODO(Leo): remove the following ematch annotations as soon as we have\n   arithmetic theory in the smt_stactic -/\n@[ematch_lhs]\nprotected theorem add_sub_add_right : ∀ n k m : ℕ, n + k - (m + k) = n - m\n  | n, 0, m => by rw [Nat.add_zero, Nat.add_zero]\n  | n, succ k, m => by rw [add_succ, add_succ, succ_sub_succ, add_sub_add_right n k m]\n#align nat.add_sub_add_right Nat.add_sub_add_right\n-/\n\n#print Nat.add_sub_add_left /-\n@[ematch_lhs]\nprotected theorem add_sub_add_left (k n m : ℕ) : k + n - (k + m) = n - m := by\n  rw [Nat.add_comm k n, Nat.add_comm k m, Nat.add_sub_add_right]\n#align nat.add_sub_add_left Nat.add_sub_add_left\n-/\n\n#print Nat.add_sub_cancel /-\n@[ematch_lhs]\nprotected theorem add_sub_cancel (n m : ℕ) : n + m - m = n :=\n  by\n  suffices n + m - (0 + m) = n by rwa [Nat.zero_add] at this\n  rw [Nat.add_sub_add_right, Nat.sub_zero]\n#align nat.add_sub_cancel Nat.add_sub_cancel\n-/\n\n#print Nat.add_sub_cancel_left /-\n@[ematch_lhs]\nprotected theorem add_sub_cancel_left (n m : ℕ) : n + m - n = m :=\n  show n + m - (n + 0) = m by rw [Nat.add_sub_add_left, Nat.sub_zero]\n#align nat.add_sub_cancel_left Nat.add_sub_cancel_left\n-/\n\n#print Nat.sub_sub /-\nprotected theorem sub_sub : ∀ n m k : ℕ, n - m - k = n - (m + k)\n  | n, m, 0 => by rw [Nat.add_zero, Nat.sub_zero]\n  | n, m, succ k => by rw [add_succ, Nat.sub_succ, Nat.sub_succ, sub_sub n m k]\n#align nat.sub_sub Nat.sub_sub\n-/\n\n#print Nat.le_of_le_of_sub_le_sub_right /-\nprotected theorem le_of_le_of_sub_le_sub_right {n m k : ℕ} (h₀ : k ≤ m) (h₁ : n - k ≤ m - k) :\n    n ≤ m := by\n  revert k m\n  induction' n with n <;> intro k m h₀ h₁\n  · exact m.zero_le\n  · cases' k with k\n    · apply h₁\n    cases' m with m\n    · cases not_succ_le_zero _ h₀\n    · simp [succ_sub_succ] at h₁\n      apply succ_le_succ\n      apply n_ih _ h₁\n      apply le_of_succ_le_succ h₀\n#align nat.le_of_le_of_sub_le_sub_right Nat.le_of_le_of_sub_le_sub_right\n-/\n\nprotected theorem sub_le_sub_iff_right {n m k : ℕ} (h : k ≤ m) : n - k ≤ m - k ↔ n ≤ m :=\n  ⟨Nat.le_of_le_of_sub_le_sub_right h, fun h => Nat.sub_le_sub_right h k⟩\n#align nat.sub_le_sub_iff_right Nat.sub_le_sub_iff_right\n\n#print Nat.sub_self_add /-\nprotected theorem sub_self_add (n m : ℕ) : n - (n + m) = 0 :=\n  show n + 0 - (n + m) = 0 by rw [Nat.add_sub_add_left, Nat.zero_sub]\n#align nat.sub_self_add Nat.sub_self_add\n-/\n\nprotected theorem le_sub_iff_right {x y k : ℕ} (h : k ≤ y) : x ≤ y - k ↔ x + k ≤ y := by\n  rw [← Nat.add_sub_cancel x k, Nat.sub_le_sub_iff_right h, Nat.add_sub_cancel]\n#align nat.le_sub_iff_right Nat.le_sub_iff_right\n\n#print Nat.sub_lt_of_pos_le /-\nprotected theorem sub_lt_of_pos_le (a b : ℕ) (h₀ : 0 < a) (h₁ : a ≤ b) : b - a < b :=\n  by\n  apply Nat.sub_lt _ h₀\n  apply lt_of_lt_of_le h₀ h₁\n#align nat.sub_lt_of_pos_le Nat.sub_lt_of_pos_le\n-/\n\n#print Nat.sub_one /-\nprotected theorem sub_one (n : ℕ) : n - 1 = pred n :=\n  rfl\n#align nat.sub_one Nat.sub_one\n-/\n\n#print Nat.succ_sub_one /-\ntheorem succ_sub_one (n : ℕ) : succ n - 1 = n :=\n  rfl\n#align nat.succ_sub_one Nat.succ_sub_one\n-/\n\n#print Nat.succ_pred_eq_of_pos /-\ntheorem succ_pred_eq_of_pos : ∀ {n : ℕ}, 0 < n → succ (pred n) = n\n  | 0, h => absurd h (lt_irrefl 0)\n  | succ k, h => rfl\n#align nat.succ_pred_eq_of_pos Nat.succ_pred_eq_of_pos\n-/\n\n#print Nat.sub_eq_zero_of_le /-\nprotected theorem sub_eq_zero_of_le {n m : ℕ} (h : n ≤ m) : n - m = 0 :=\n  Exists.elim (Nat.le.dest h) fun k => fun hk : n + k = m => by rw [← hk, Nat.sub_self_add]\n#align nat.sub_eq_zero_of_le Nat.sub_eq_zero_of_le\n-/\n\n#print Nat.le_of_sub_eq_zero /-\nprotected theorem le_of_sub_eq_zero : ∀ {n m : ℕ}, n - m = 0 → n ≤ m\n  | n, 0, H => by rw [Nat.sub_zero] at H; simp [H]\n  | 0, m + 1, H => (m + 1).zero_le\n  | n + 1, m + 1, H =>\n    Nat.add_le_add_right (le_of_sub_eq_zero (by simp [Nat.add_sub_add_right] at H; exact H)) _\n#align nat.le_of_sub_eq_zero Nat.le_of_sub_eq_zero\n-/\n\n#print Nat.sub_eq_zero_iff_le /-\nprotected theorem sub_eq_zero_iff_le {n m : ℕ} : n - m = 0 ↔ n ≤ m :=\n  ⟨Nat.le_of_sub_eq_zero, Nat.sub_eq_zero_of_le⟩\n#align nat.sub_eq_zero_iff_le Nat.sub_eq_zero_iff_le\n-/\n\n#print Nat.add_sub_of_le /-\nprotected theorem add_sub_of_le {n m : ℕ} (h : n ≤ m) : n + (m - n) = m :=\n  Exists.elim (Nat.le.dest h) fun k => fun hk : n + k = m => by rw [← hk, Nat.add_sub_cancel_left]\n#align nat.add_sub_of_le Nat.add_sub_of_le\n-/\n\n#print Nat.sub_add_cancel /-\nprotected theorem sub_add_cancel {n m : ℕ} (h : m ≤ n) : n - m + m = n := by\n  rw [Nat.add_comm, Nat.add_sub_of_le h]\n#align nat.sub_add_cancel Nat.sub_add_cancel\n-/\n\n#print Nat.add_sub_assoc /-\nprotected theorem add_sub_assoc {m k : ℕ} (h : k ≤ m) (n : ℕ) : n + m - k = n + (m - k) :=\n  Exists.elim (Nat.le.dest h) fun l => fun hl : k + l = m => by\n    rw [← hl, Nat.add_sub_cancel_left, Nat.add_comm k, ← Nat.add_assoc, Nat.add_sub_cancel]\n#align nat.add_sub_assoc Nat.add_sub_assoc\n-/\n\n#print Nat.sub_eq_iff_eq_add /-\nprotected theorem sub_eq_iff_eq_add {a b c : ℕ} (ab : b ≤ a) : a - b = c ↔ a = c + b :=\n  ⟨fun c_eq => by rw [c_eq.symm, Nat.sub_add_cancel ab], fun a_eq => by\n    rw [a_eq, Nat.add_sub_cancel]⟩\n#align nat.sub_eq_iff_eq_add Nat.sub_eq_iff_eq_add\n-/\n\n#print Nat.lt_of_sub_eq_succ /-\nprotected theorem lt_of_sub_eq_succ {m n l : ℕ} (H : m - n = Nat.succ l) : n < m :=\n  not_le.1 fun H' : n ≥ m => by simp [Nat.sub_eq_zero_of_le H'] at H; contradiction\n#align nat.lt_of_sub_eq_succ Nat.lt_of_sub_eq_succ\n-/\n\n#print Nat.sub_le_sub_left /-\nprotected theorem sub_le_sub_left {n m : ℕ} (k) (h : n ≤ m) : k - m ≤ k - n := by\n  induction h <;> [rfl, exact le_trans (pred_le _) h_ih]\n#align nat.sub_le_sub_left Nat.sub_le_sub_left\n-/\n\n#print Nat.succ_sub_sub_succ /-\ntheorem succ_sub_sub_succ (n m k : ℕ) : succ n - m - succ k = n - m - k := by\n  rw [Nat.sub_sub, Nat.sub_sub, add_succ, succ_sub_succ]\n#align nat.succ_sub_sub_succ Nat.succ_sub_sub_succ\n-/\n\n#print Nat.sub.right_comm /-\nprotected theorem sub.right_comm (m n k : ℕ) : m - n - k = m - k - n := by\n  rw [Nat.sub_sub, Nat.sub_sub, Nat.add_comm]\n#align nat.sub.right_comm Nat.sub.right_comm\n-/\n\n#print Nat.succ_sub /-\ntheorem succ_sub {m n : ℕ} (h : n ≤ m) : succ m - n = succ (m - n) :=\n  Exists.elim (Nat.le.dest h) fun k => fun hk : n + k = m => by\n    rw [← hk, Nat.add_sub_cancel_left, ← add_succ, Nat.add_sub_cancel_left]\n#align nat.succ_sub Nat.succ_sub\n-/\n\n#print Nat.sub_pos_of_lt /-\nprotected theorem sub_pos_of_lt {m n : ℕ} (h : m < n) : 0 < n - m :=\n  have : 0 + m < n - m + m := by rw [Nat.zero_add, Nat.sub_add_cancel (le_of_lt h)]; exact h\n  Nat.lt_of_add_lt_add_right this\n#align nat.sub_pos_of_lt Nat.sub_pos_of_lt\n-/\n\n#print Nat.sub_sub_self /-\nprotected theorem sub_sub_self {n m : ℕ} (h : m ≤ n) : n - (n - m) = m :=\n  (Nat.sub_eq_iff_eq_add (Nat.sub_le _ _)).2 (Nat.add_sub_of_le h).symm\n#align nat.sub_sub_self Nat.sub_sub_self\n-/\n\n#print Nat.sub_add_comm /-\nprotected theorem sub_add_comm {n m k : ℕ} (h : k ≤ n) : n + m - k = n - k + m :=\n  (Nat.sub_eq_iff_eq_add (Nat.le_trans h (Nat.le_add_right _ _))).2\n    (by rwa [Nat.add_right_comm, Nat.sub_add_cancel])\n#align nat.sub_add_comm Nat.sub_add_comm\n-/\n\ntheorem sub_one_sub_lt {n i} (h : i < n) : n - 1 - i < n :=\n  by\n  rw [Nat.sub_sub]\n  apply Nat.sub_lt\n  apply lt_of_lt_of_le (Nat.zero_lt_succ _) h\n  rw [Nat.add_comm]\n  apply Nat.zero_lt_succ\n#align nat.sub_one_sub_lt Nat.sub_one_sub_ltₓ\n\n#print Nat.mul_pred_left /-\ntheorem mul_pred_left : ∀ n m : ℕ, pred n * m = n * m - m\n  | 0, m => by simp [Nat.zero_sub, pred_zero, Nat.zero_mul]\n  | succ n, m => by rw [pred_succ, succ_mul, Nat.add_sub_cancel]\n#align nat.mul_pred_left Nat.mul_pred_left\n-/\n\n#print Nat.mul_pred_right /-\ntheorem mul_pred_right (n m : ℕ) : n * pred m = n * m - n := by\n  rw [Nat.mul_comm, mul_pred_left, Nat.mul_comm]\n#align nat.mul_pred_right Nat.mul_pred_right\n-/\n\n#print Nat.mul_sub_right_distrib /-\nprotected theorem mul_sub_right_distrib : ∀ n m k : ℕ, (n - m) * k = n * k - m * k\n  | n, 0, k => by simp [Nat.sub_zero, Nat.zero_mul]\n  | n, succ m, k => by\n    rw [Nat.sub_succ, mul_pred_left, mul_sub_right_distrib, succ_mul, Nat.sub_sub]\n#align nat.mul_sub_right_distrib Nat.mul_sub_right_distrib\n-/\n\n#print Nat.mul_sub_left_distrib /-\nprotected theorem mul_sub_left_distrib (n m k : ℕ) : n * (m - k) = n * m - n * k := by\n  rw [Nat.mul_comm, Nat.mul_sub_right_distrib, Nat.mul_comm m n, Nat.mul_comm n k]\n#align nat.mul_sub_left_distrib Nat.mul_sub_left_distrib\n-/\n\n#print Nat.mul_self_sub_mul_self_eq /-\nprotected theorem mul_self_sub_mul_self_eq (a b : Nat) : a * a - b * b = (a + b) * (a - b) := by\n  rw [Nat.mul_sub_left_distrib, Nat.right_distrib, Nat.right_distrib, Nat.mul_comm b a,\n    Nat.add_comm (a * a) (a * b), Nat.add_sub_add_left]\n#align nat.mul_self_sub_mul_self_eq Nat.mul_self_sub_mul_self_eq\n-/\n\n#print Nat.succ_mul_succ_eq /-\ntheorem succ_mul_succ_eq (a b : Nat) : succ a * succ b = a * b + a + b + 1 :=\n  by\n  rw [← add_one, ← add_one]\n  simp [Nat.right_distrib, Nat.left_distrib, Nat.add_left_comm, Nat.mul_one, Nat.one_mul,\n    Nat.add_assoc]\n#align nat.succ_mul_succ_eq Nat.succ_mul_succ_eq\n-/\n\n/-! min -/\n\n\n/- warning: nat.zero_min -> Nat.zero_min is a dubious translation:\nlean 3 declaration is\n  forall (a : Nat), Eq.{1} Nat (LinearOrder.min.{0} Nat Nat.linearOrder (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) 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 (a : Nat), Eq.{1} Nat (Min.min.{0} Nat instMinNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) a) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align nat.zero_min Nat.zero_minₓ'. -/\nprotected theorem zero_min (a : ℕ) : min 0 a = 0 :=\n  min_eq_left a.zero_le\n#align nat.zero_min Nat.zero_min\n\n/- warning: nat.min_zero -> Nat.min_zero is a dubious translation:\nlean 3 declaration is\n  forall (a : Nat), Eq.{1} Nat (LinearOrder.min.{0} Nat Nat.linearOrder a (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))\nbut is expected to have type\n  forall (a : Nat), Eq.{1} Nat (Min.min.{0} Nat instMinNat a (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))\nCase conversion may be inaccurate. Consider using '#align nat.min_zero Nat.min_zeroₓ'. -/\nprotected theorem min_zero (a : ℕ) : min a 0 = 0 :=\n  min_eq_right a.zero_le\n#align nat.min_zero Nat.min_zero\n\n/- warning: nat.min_succ_succ -> Nat.min_succ_succ is a dubious translation:\nlean 3 declaration is\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (LinearOrder.min.{0} Nat Nat.linearOrder (Nat.succ x) (Nat.succ y)) (Nat.succ (LinearOrder.min.{0} Nat Nat.linearOrder x y))\nbut is expected to have type\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (Min.min.{0} Nat instMinNat (Nat.succ x) (Nat.succ y)) (Nat.succ (Min.min.{0} Nat instMinNat x y))\nCase conversion may be inaccurate. Consider using '#align nat.min_succ_succ Nat.min_succ_succₓ'. -/\n-- Distribute succ over min\ntheorem min_succ_succ (x y : ℕ) : min (succ x) (succ y) = succ (min x y) :=\n  have f : x ≤ y → min (succ x) (succ y) = succ (min x y) := fun p =>\n    calc\n      min (succ x) (succ y) = succ x := if_pos (succ_le_succ p)\n      _ = succ (min x y) := congr_arg succ (Eq.symm (if_pos p))\n      \n  have g : ¬x ≤ y → min (succ x) (succ y) = succ (min x y) := fun p =>\n    calc\n      min (succ x) (succ y) = succ y := if_neg fun eq => p (pred_le_pred Eq)\n      _ = succ (min x y) := congr_arg succ (Eq.symm (if_neg p))\n      \n  Decidable.byCases f g\n#align nat.min_succ_succ Nat.min_succ_succ\n\n/- warning: nat.sub_eq_sub_min -> Nat.sub_eq_sub_min is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (m : Nat), Eq.{1} Nat (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n m) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n (LinearOrder.min.{0} Nat Nat.linearOrder n m))\nbut is expected to have type\n  forall (n : Nat) (m : Nat), Eq.{1} Nat (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n m) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n (Min.min.{0} Nat instMinNat n m))\nCase conversion may be inaccurate. Consider using '#align nat.sub_eq_sub_min Nat.sub_eq_sub_minₓ'. -/\ntheorem sub_eq_sub_min (n m : ℕ) : n - m = n - min n m :=\n  if h : n ≥ m then by rw [min_eq_right h]\n  else by rw [Nat.sub_eq_zero_of_le (le_of_not_ge h), min_eq_left (le_of_not_ge h), Nat.sub_self]\n#align nat.sub_eq_sub_min Nat.sub_eq_sub_min\n\n/- warning: nat.sub_add_min_cancel -> Nat.sub_add_min_cancel is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (m : Nat), Eq.{1} Nat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n m) (LinearOrder.min.{0} Nat Nat.linearOrder n m)) n\nbut is expected to have type\n  forall (n : Nat) (m : Nat), Eq.{1} Nat (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n m) (Min.min.{0} Nat instMinNat n m)) n\nCase conversion may be inaccurate. Consider using '#align nat.sub_add_min_cancel Nat.sub_add_min_cancelₓ'. -/\n@[simp]\nprotected theorem sub_add_min_cancel (n m : ℕ) : n - m + min n m = n := by\n  rw [sub_eq_sub_min, Nat.sub_add_cancel (min_le_left n m)]\n#align nat.sub_add_min_cancel Nat.sub_add_min_cancel\n\n/-! induction principles -/\n\n\ndef twoStepInduction {P : ℕ → Sort u} (H1 : P 0) (H2 : P 1)\n    (H3 : ∀ (n : ℕ) (IH1 : P n) (IH2 : P (succ n)), P (succ (succ n))) : ∀ a : ℕ, P a\n  | 0 => H1\n  | 1 => H2\n  | succ (succ n) => H3 _ (two_step_induction _) (two_step_induction _)\n#align nat.two_step_induction Nat.twoStepInduction\n\ndef subInduction {P : ℕ → ℕ → Sort u} (H1 : ∀ m, P 0 m) (H2 : ∀ n, P (succ n) 0)\n    (H3 : ∀ n m, P n m → P (succ n) (succ m)) : ∀ n m : ℕ, P n m\n  | 0, m => H1 _\n  | succ n, 0 => H2 _\n  | succ n, succ m => H3 _ _ (sub_induction n m)\n#align nat.sub_induction Nat.subInduction\n\nprotected def strongRecOn {p : Nat → Sort u} (n : Nat) (h : ∀ n, (∀ m, m < n → p m) → p n) : p n :=\n  by\n  suffices ∀ n m, m < n → p m from this (succ n) n (lt_succ_self _)\n  intro n; induction' n with n ih\n  · intro m h₁\n    exact absurd h₁ m.not_lt_zero\n  · intro m h₁\n    apply Or.by_cases (Decidable.lt_or_eq_of_le (le_of_lt_succ h₁))\n    · intros\n      apply ih\n      assumption\n    · intros\n      subst m\n      apply h _ ih\n#align nat.strong_rec_on Nat.strongRecOn\n\n#print Nat.strong_induction_on /-\nprotected theorem strong_induction_on {p : Nat → Prop} (n : Nat)\n    (h : ∀ n, (∀ m, m < n → p m) → p n) : p n :=\n  Nat.strongRecOn n h\n#align nat.strong_induction_on Nat.strong_induction_on\n-/\n\n#print Nat.case_strong_induction_on /-\nprotected theorem case_strong_induction_on {p : Nat → Prop} (a : Nat) (hz : p 0)\n    (hi : ∀ n, (∀ m, m ≤ n → p m) → p (succ n)) : p a :=\n  Nat.strong_induction_on a fun n =>\n    match n with\n    | 0 => fun _ => hz\n    | n + 1 => fun h₁ => hi n fun m h₂ => h₁ _ (lt_succ_of_le h₂)\n#align nat.case_strong_induction_on Nat.case_strong_induction_on\n-/\n\n/-! mod -/\n\n\nprivate theorem mod_core_congr {x y f1 f2} (h1 : x ≤ f1) (h2 : x ≤ f2) :\n    Nat.modCore y f1 x = Nat.modCore y f2 x :=\n  by\n  cases y; · cases f1 <;> cases f2 <;> rfl\n  induction' f1 with f1 ih generalizing x f2;\n  · cases h1\n    cases f2 <;> rfl\n  cases x; · cases f1 <;> cases f2 <;> rfl\n  cases f2; · cases h2\n  refine' if_congr Iff.rfl _ rfl\n  simp only [succ_sub_succ]\n  exact\n    ih (le_trans (Nat.sub_le _ _) (le_of_succ_le_succ h1))\n      (le_trans (Nat.sub_le _ _) (le_of_succ_le_succ h2))\n#align nat.mod_core_congr nat.mod_core_congr\n\n/- warning: nat.mod_def -> Nat.mod_eq is a dubious translation:\nlean 3 declaration is\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) x y) (ite.{1} Nat (And (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) y) (LE.le.{0} Nat Nat.hasLe y x)) (And.decidable (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) y) (LE.le.{0} Nat Nat.hasLe y x) (Nat.decidableLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) y) (Nat.decidableLe y x)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) x y) y) x)\nbut is expected to have type\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) x y) (ite.{1} Nat (And (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) y) (LE.le.{0} Nat instLENat y x)) (instDecidableAnd (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) y) (LE.le.{0} Nat instLENat y x) (Nat.decLt (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) y) (Nat.decLe y x)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) x y) y) x)\nCase conversion may be inaccurate. Consider using '#align nat.mod_def Nat.mod_eqₓ'. -/\ntheorem mod_eq (x y : Nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x :=\n  by\n  cases x; · cases y <;> rfl\n  cases y; · rfl\n  refine' if_congr Iff.rfl (mod_core_congr _ _) rfl <;> simp [Nat.sub_le]\n#align nat.mod_def Nat.mod_eq\n\n#print Nat.mod_zero /-\n@[simp]\ntheorem mod_zero (a : Nat) : a % 0 = a := by\n  rw [mod_def]\n  have h : ¬(0 < 0 ∧ 0 ≤ a)\n  simp [lt_irrefl]\n  simp [if_neg, h]\n#align nat.mod_zero Nat.mod_zero\n-/\n\n#print Nat.mod_eq_of_lt /-\ntheorem mod_eq_of_lt {a b : Nat} (h : a < b) : a % b = a :=\n  by\n  rw [mod_def]\n  have h' : ¬(0 < b ∧ b ≤ a)\n  simp [not_le_of_gt h]\n  simp [if_neg, h']\n#align nat.mod_eq_of_lt Nat.mod_eq_of_lt\n-/\n\n#print Nat.zero_mod /-\n@[simp]\ntheorem zero_mod (b : Nat) : 0 % b = 0 := by\n  rw [mod_def]\n  have h : ¬(0 < b ∧ b ≤ 0) := by\n    intro hn\n    cases' hn with l r\n    exact absurd (lt_of_lt_of_le l r) (lt_irrefl 0)\n  simp [if_neg, h]\n#align nat.zero_mod Nat.zero_mod\n-/\n\n#print Nat.mod_eq_sub_mod /-\ntheorem mod_eq_sub_mod {a b : Nat} (h : b ≤ a) : a % b = (a - b) % b :=\n  Or.elim b.eq_zero_or_pos (fun b0 => by rw [b0, Nat.sub_zero]) fun h₂ => by\n    rw [mod_def, if_pos (And.intro h₂ h)]\n#align nat.mod_eq_sub_mod Nat.mod_eq_sub_mod\n-/\n\n#print Nat.mod_lt /-\ntheorem mod_lt (x : Nat) {y : Nat} (h : 0 < y) : x % y < y :=\n  by\n  induction' x using Nat.case_strong_induction_on with x ih\n  · rw [zero_mod]\n    assumption\n  · by_cases h₁ : succ x < y\n    · rwa [mod_eq_of_lt h₁]\n    · have h₁ : succ x % y = (succ x - y) % y := mod_eq_sub_mod (not_lt.1 h₁)\n      have : succ x - y ≤ x := le_of_lt_succ (Nat.sub_lt (succ_pos x) h)\n      have h₂ : (succ x - y) % y < y := ih _ this\n      rwa [← h₁] at h₂\n#align nat.mod_lt Nat.mod_lt\n-/\n\n#print Nat.mod_self /-\n@[simp]\ntheorem mod_self (n : Nat) : n % n = 0 := by rw [mod_eq_sub_mod (le_refl _), Nat.sub_self, zero_mod]\n#align nat.mod_self Nat.mod_self\n-/\n\n#print Nat.mod_one /-\n@[simp]\ntheorem mod_one (n : ℕ) : n % 1 = 0 :=\n  have : n % 1 < 1 := (mod_lt n) (succ_pos 0)\n  Nat.eq_zero_of_le_zero (le_of_lt_succ this)\n#align nat.mod_one Nat.mod_one\n-/\n\n#print Nat.mod_two_eq_zero_or_one /-\ntheorem mod_two_eq_zero_or_one (n : ℕ) : n % 2 = 0 ∨ n % 2 = 1 :=\n  match n % 2, @Nat.mod_lt n 2 (by decide) with\n  | 0, _ => Or.inl rfl\n  | 1, _ => Or.inr rfl\n  | k + 2, h => absurd h (by decide)\n#align nat.mod_two_eq_zero_or_one Nat.mod_two_eq_zero_or_one\n-/\n\n#print Nat.mod_le /-\ntheorem mod_le (x y : ℕ) : x % y ≤ x :=\n  Or.elim (lt_or_le x y) (fun xlty => by rw [mod_eq_of_lt xlty] <;> rfl) fun ylex =>\n    Or.elim y.eq_zero_or_pos (fun y0 => by rw [y0, mod_zero] <;> rfl) fun ypos =>\n      le_trans (le_of_lt (mod_lt _ ypos)) ylex\n#align nat.mod_le Nat.mod_le\n-/\n\n#print Nat.add_mod_right /-\n@[simp]\ntheorem add_mod_right (x z : ℕ) : (x + z) % z = x % z := by\n  rw [mod_eq_sub_mod (Nat.le_add_left _ _), Nat.add_sub_cancel]\n#align nat.add_mod_right Nat.add_mod_right\n-/\n\n#print Nat.add_mod_left /-\n@[simp]\ntheorem add_mod_left (x z : ℕ) : (x + z) % x = z % x := by rw [Nat.add_comm, add_mod_right]\n#align nat.add_mod_left Nat.add_mod_left\n-/\n\n#print Nat.add_mul_mod_self_left /-\n@[simp]\ntheorem add_mul_mod_self_left (x y z : ℕ) : (x + y * z) % y = x % y :=\n  by\n  induction' z with z ih\n  rw [Nat.mul_zero, Nat.add_zero]\n  rw [mul_succ, ← Nat.add_assoc, add_mod_right, ih]\n#align nat.add_mul_mod_self_left Nat.add_mul_mod_self_left\n-/\n\n#print Nat.add_mul_mod_self_right /-\n@[simp]\ntheorem add_mul_mod_self_right (x y z : ℕ) : (x + y * z) % z = x % z := by\n  rw [Nat.mul_comm, add_mul_mod_self_left]\n#align nat.add_mul_mod_self_right Nat.add_mul_mod_self_right\n-/\n\n#print Nat.mul_mod_right /-\n@[simp]\ntheorem mul_mod_right (m n : ℕ) : m * n % m = 0 := by\n  rw [← Nat.zero_add (m * n), add_mul_mod_self_left, zero_mod]\n#align nat.mul_mod_right Nat.mul_mod_right\n-/\n\n#print Nat.mul_mod_left /-\n@[simp]\ntheorem mul_mod_left (m n : ℕ) : m * n % n = 0 := by rw [Nat.mul_comm, mul_mod_right]\n#align nat.mul_mod_left Nat.mul_mod_left\n-/\n\n#print Nat.mul_mod_mul_left /-\ntheorem mul_mod_mul_left (z x y : ℕ) : z * x % (z * y) = z * (x % y) :=\n  if y0 : y = 0 then by rw [y0, Nat.mul_zero, mod_zero, mod_zero]\n  else\n    if z0 : z = 0 then by rw [z0, Nat.zero_mul, Nat.zero_mul, Nat.zero_mul, mod_zero]\n    else\n      x.strong_induction_on fun n IH =>\n        have y0 : y > 0 := Nat.pos_of_ne_zero y0\n        have z0 : z > 0 := Nat.pos_of_ne_zero z0\n        Or.elim (le_or_lt y n)\n          (fun yn => by\n            rw [mod_eq_sub_mod yn, mod_eq_sub_mod (Nat.mul_le_mul_left z yn), ←\n                Nat.mul_sub_left_distrib] <;>\n              exact IH _ (Nat.sub_lt (lt_of_lt_of_le y0 yn) y0))\n          fun yn => by rw [mod_eq_of_lt yn, mod_eq_of_lt (Nat.mul_lt_mul_of_pos_left yn z0)]\n#align nat.mul_mod_mul_left Nat.mul_mod_mul_left\n-/\n\n#print Nat.mul_mod_mul_right /-\ntheorem mul_mod_mul_right (z x y : ℕ) : x * z % (y * z) = x % y * z := by\n  rw [Nat.mul_comm x z, Nat.mul_comm y z, Nat.mul_comm (x % y) z] <;> apply mul_mod_mul_left\n#align nat.mul_mod_mul_right Nat.mul_mod_mul_right\n-/\n\n#print Nat.cond_decide_mod_two /-\ntheorem cond_decide_mod_two (x : ℕ) [d : Decidable (x % 2 = 1)] :\n    cond (@decide (x % 2 = 1) d) 1 0 = x % 2 :=\n  by\n  by_cases h : x % 2 = 1\n  · simp! [*]\n  · cases mod_two_eq_zero_or_one x <;> simp! [*, Nat.zero_ne_one] <;> contradiction\n#align nat.cond_to_bool_mod_two Nat.cond_decide_mod_two\n-/\n\n#print Nat.sub_mul_mod /-\ntheorem sub_mul_mod (x k n : ℕ) (h₁ : n * k ≤ x) : (x - n * k) % n = x % n :=\n  by\n  induction' k with k\n  · rw [Nat.mul_zero, Nat.sub_zero]\n  · have h₂ : n * k ≤ x := by\n      rw [mul_succ] at h₁\n      apply Nat.le_trans _ h₁\n      apply Nat.le_add_right _ n\n    have h₄ : x - n * k ≥ n := by\n      apply @Nat.le_of_add_le_add_right (n * k)\n      rw [Nat.sub_add_cancel h₂]\n      simp [mul_succ, Nat.add_comm] at h₁\n      simp [h₁]\n    rw [mul_succ, ← Nat.sub_sub, ← mod_eq_sub_mod h₄, k_ih h₂]\n#align nat.sub_mul_mod Nat.sub_mul_mod\n-/\n\n/-! div -/\n\n\nprivate theorem div_core_congr {x y f1 f2} (h1 : x ≤ f1) (h2 : x ≤ f2) :\n    Nat.divCore y f1 x = Nat.divCore y f2 x :=\n  by\n  cases y; · cases f1 <;> cases f2 <;> rfl\n  induction' f1 with f1 ih generalizing x f2;\n  · cases h1\n    cases f2 <;> rfl\n  cases x; · cases f1 <;> cases f2 <;> rfl\n  cases f2; · cases h2\n  refine' if_congr Iff.rfl _ rfl\n  simp only [succ_sub_succ]\n  refine' congr_arg (· + 1) _\n  exact\n    ih (le_trans (Nat.sub_le _ _) (le_of_succ_le_succ h1))\n      (le_trans (Nat.sub_le _ _) (le_of_succ_le_succ h2))\n#align nat.div_core_congr nat.div_core_congr\n\n/- warning: nat.div_def -> Nat.div_eq is a dubious translation:\nlean 3 declaration is\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) x y) (ite.{1} Nat (And (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) y) (LE.le.{0} Nat Nat.hasLe y x)) (And.decidable (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) y) (LE.le.{0} Nat Nat.hasLe y x) (Nat.decidableLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) y) (Nat.decidableLe y x)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) x y) y) (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 (x : Nat) (y : Nat), Eq.{1} Nat (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) x y) (ite.{1} Nat (And (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) y) (LE.le.{0} Nat instLENat y x)) (instDecidableAnd (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) y) (LE.le.{0} Nat instLENat y x) (Nat.decLt (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) y) (Nat.decLe y x)) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) x y) y) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align nat.div_def Nat.div_eqₓ'. -/\ntheorem div_eq (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 :=\n  by\n  cases x; · cases y <;> rfl\n  cases y; · rfl\n  refine' if_congr Iff.rfl (congr_arg (· + 1) _) rfl\n  refine' div_core_congr _ _ <;> simp [Nat.sub_le]\n#align nat.div_def Nat.div_eq\n\n#print Nat.mod_add_div /-\ntheorem mod_add_div (m k : ℕ) : m % k + k * (m / k) = m :=\n  by\n  apply Nat.strong_induction_on m\n  clear m\n  intro m IH\n  cases' Decidable.em (0 < k ∧ k ≤ m) with h h'\n  -- 0 < k ∧ k ≤ m\n  · have h' : m - k < m := by\n      apply Nat.sub_lt _ h.left\n      apply lt_of_lt_of_le h.left h.right\n    rw [div_def, mod_def, if_pos h, if_pos h]\n    simp [Nat.left_distrib, IH _ h', Nat.add_comm, Nat.add_left_comm]\n    rw [Nat.add_comm, ← Nat.add_sub_assoc h.right, Nat.mul_one, Nat.add_sub_cancel_left]\n  -- ¬ (0 < k ∧ k ≤ m)\n  · rw [div_def, mod_def, if_neg h', if_neg h', Nat.mul_zero, Nat.add_zero]\n#align nat.mod_add_div Nat.mod_add_div\n-/\n\n#print Nat.div_one /-\n@[simp]\nprotected theorem div_one (n : ℕ) : n / 1 = n :=\n  by\n  have : n % 1 + 1 * (n / 1) = n := mod_add_div _ _\n  rwa [mod_one, Nat.zero_add, Nat.one_mul] at this\n#align nat.div_one Nat.div_one\n-/\n\n#print Nat.div_zero /-\n@[simp]\nprotected theorem div_zero (n : ℕ) : n / 0 = 0 := by rw [div_def]; simp [lt_irrefl]\n#align nat.div_zero Nat.div_zero\n-/\n\n#print Nat.zero_div /-\n@[simp]\nprotected theorem zero_div (b : ℕ) : 0 / b = 0 :=\n  Eq.trans (div_eq 0 b) <| if_neg (And.ndrec not_le_of_gt)\n#align nat.zero_div Nat.zero_div\n-/\n\n#print Nat.div_le_of_le_mul /-\nprotected theorem div_le_of_le_mul {m n : ℕ} : ∀ {k}, m ≤ k * n → m / k ≤ n\n  | 0, h => by simp [Nat.div_zero, n.zero_le]\n  | succ k, h =>\n    suffices succ k * (m / succ k) ≤ succ k * n from Nat.le_of_mul_le_mul_left this (zero_lt_succ _)\n    calc\n      succ k * (m / succ k) ≤ m % succ k + succ k * (m / succ k) := Nat.le_add_left _ _\n      _ = m := by rw [mod_add_div]\n      _ ≤ succ k * n := h\n      \n#align nat.div_le_of_le_mul Nat.div_le_of_le_mul\n-/\n\n#print Nat.div_le_self /-\nprotected theorem div_le_self : ∀ m n : ℕ, m / n ≤ m\n  | m, 0 => by simp [Nat.div_zero, m.zero_le]\n  | m, succ n =>\n    have : m ≤ succ n * m :=\n      calc\n        m = 1 * m := by rw [Nat.one_mul]\n        _ ≤ succ n * m := m.mul_le_mul_right (succ_le_succ n.zero_le)\n        \n    Nat.div_le_of_le_mul this\n#align nat.div_le_self Nat.div_le_self\n-/\n\ntheorem div_eq_sub_div {a b : Nat} (h₁ : 0 < b) (h₂ : b ≤ a) : a / b = (a - b) / b + 1 :=\n  by\n  rw [div_def a, if_pos]\n  constructor <;> assumption\n#align nat.div_eq_sub_div Nat.div_eq_sub_divₓ\n\n#print Nat.div_eq_of_lt /-\ntheorem div_eq_of_lt {a b : ℕ} (h₀ : a < b) : a / b = 0 :=\n  by\n  rw [div_def a, if_neg]\n  intro h₁\n  apply not_le_of_gt h₀ h₁.right\n#align nat.div_eq_of_lt Nat.div_eq_of_lt\n-/\n\n/- warning: nat.le_div_iff_mul_le -> Nat.le_div_iff_mul_le is a dubious translation:\nlean 3 declaration is\n  forall {x : Nat} {y : Nat} {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) -> (Iff (LE.le.{0} Nat Nat.hasLe x (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) y k)) (LE.le.{0} Nat Nat.hasLe (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) x k) y))\nbut is expected to have type\n  forall {x : Nat} {y : Nat} {k : Nat}, (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) x) -> (Iff (LE.le.{0} Nat instLENat y (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) k x)) (LE.le.{0} Nat instLENat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) y x) k))\nCase conversion may be inaccurate. Consider using '#align nat.le_div_iff_mul_le Nat.le_div_iff_mul_leₓ'. -/\n-- this is a Galois connection\n--   f x ≤ y ↔ x ≤ g y\n-- with\n--   f x = x * k\n--   g y = y / k\ntheorem le_div_iff_mul_le {x y k : ℕ} (Hk : 0 < k) : x ≤ y / k ↔ x * k ≤ y :=\n  by\n  -- Hk is needed because, despite div being made total, y / 0 := 0\n  --     x * 0 ≤ y ↔ x ≤ y / 0\n  --   ↔ 0 ≤ y ↔ x ≤ 0\n  --   ↔ true ↔ x = 0\n  --   ↔ x = 0\n  revert x\n  apply Nat.strong_induction_on y _\n  clear y\n  intro y IH x\n  cases' lt_or_le y k with h h\n  -- base case: y < k\n  · rw [div_eq_of_lt h]\n    cases' x with x\n    · simp [Nat.zero_mul, y.zero_le]\n    · simp [succ_mul, not_succ_le_zero, Nat.add_comm]\n      apply lt_of_lt_of_le h\n      apply Nat.le_add_right\n  -- step: k ≤ y\n  · rw [div_eq_sub_div Hk h]\n    cases' x with x\n    · simp [Nat.zero_mul, Nat.zero_le]\n    ·\n      rw [← add_one, Nat.add_le_add_iff_right, IH (y - k) (Nat.sub_lt_of_pos_le _ _ Hk h), add_one,\n        succ_mul, Nat.le_sub_iff_right h]\n#align nat.le_div_iff_mul_le Nat.le_div_iff_mul_le\n\n/- warning: nat.div_lt_iff_lt_mul -> Nat.div_lt_iff_lt_mul is a dubious translation:\nlean 3 declaration is\n  forall {x : Nat} {y : Nat} {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) -> (Iff (LT.lt.{0} Nat Nat.hasLt (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) x k) y) (LT.lt.{0} Nat Nat.hasLt x (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) y k)))\nbut is expected to have type\n  forall {x : Nat} {y : Nat} {k : Nat}, (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) x) -> (Iff (LT.lt.{0} Nat instLTNat (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) y x) k) (LT.lt.{0} Nat instLTNat y (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) k x)))\nCase conversion may be inaccurate. Consider using '#align nat.div_lt_iff_lt_mul Nat.div_lt_iff_lt_mulₓ'. -/\ntheorem div_lt_iff_lt_mul {x y k : ℕ} (Hk : 0 < k) : x / k < y ↔ x < y * k := by\n  rw [← not_le, not_congr (le_div_iff_mul_le Hk), not_le]\n#align nat.div_lt_iff_lt_mul Nat.div_lt_iff_lt_mul\n\n#print Nat.sub_mul_div /-\ntheorem sub_mul_div (x n p : ℕ) (h₁ : n * p ≤ x) : (x - n * p) / n = x / n - p :=\n  by\n  cases' Nat.eq_zero_or_pos n with h₀ h₀\n  · rw [h₀, Nat.div_zero, Nat.div_zero, Nat.zero_sub]\n  · induction' p with p\n    · rw [Nat.mul_zero, Nat.sub_zero, Nat.sub_zero]\n    · have h₂ : n * p ≤ x := by\n        trans\n        · apply Nat.mul_le_mul_left\n          apply le_succ\n        · apply h₁\n      have h₃ : x - n * p ≥ n := by\n        apply Nat.le_of_add_le_add_right\n        rw [Nat.sub_add_cancel h₂, Nat.add_comm]\n        rw [mul_succ] at h₁\n        apply h₁\n      rw [sub_succ, ← p_ih h₂]\n      rw [@div_eq_sub_div (x - n * p) _ h₀ h₃]\n      simp [add_one, pred_succ, mul_succ, Nat.sub_sub]\n#align nat.sub_mul_div Nat.sub_mul_div\n-/\n\n#print Nat.div_mul_le_self /-\ntheorem div_mul_le_self : ∀ m n : ℕ, m / n * n ≤ m\n  | m, 0 => by simp [m.zero_le, Nat.zero_mul]\n  | m, succ n => (le_div_iff_mul_le <| Nat.succ_pos _).1 (le_refl _)\n#align nat.div_mul_le_self Nat.div_mul_le_self\n-/\n\n#print Nat.add_div_right /-\n@[simp]\ntheorem add_div_right (x : ℕ) {z : ℕ} (H : 0 < z) : (x + z) / z = succ (x / z) := by\n  rw [div_eq_sub_div H (Nat.le_add_left _ _), Nat.add_sub_cancel]\n#align nat.add_div_right Nat.add_div_right\n-/\n\n#print Nat.add_div_left /-\n@[simp]\ntheorem add_div_left (x : ℕ) {z : ℕ} (H : 0 < z) : (z + x) / z = succ (x / z) := by\n  rw [Nat.add_comm, add_div_right x H]\n#align nat.add_div_left Nat.add_div_left\n-/\n\n#print Nat.mul_div_right /-\n@[simp]\ntheorem mul_div_right (n : ℕ) {m : ℕ} (H : 0 < m) : m * n / m = n := by\n  induction n <;> simp [*, mul_succ, Nat.mul_zero]\n#align nat.mul_div_right Nat.mul_div_right\n-/\n\n#print Nat.mul_div_left /-\n@[simp]\ntheorem mul_div_left (m : ℕ) {n : ℕ} (H : 0 < n) : m * n / n = m := by\n  rw [Nat.mul_comm, mul_div_right _ H]\n#align nat.mul_div_left Nat.mul_div_left\n-/\n\n#print Nat.div_self /-\nprotected theorem div_self {n : ℕ} (H : 0 < n) : n / n = 1 :=\n  by\n  let t := add_div_right 0 H\n  rwa [Nat.zero_add, Nat.zero_div] at t\n#align nat.div_self Nat.div_self\n-/\n\n#print Nat.add_mul_div_left /-\ntheorem add_mul_div_left (x z : ℕ) {y : ℕ} (H : 0 < y) : (x + y * z) / y = x / y + z :=\n  by\n  induction' z with z ih\n  · rw [Nat.mul_zero, Nat.add_zero, Nat.add_zero]\n  · rw [mul_succ, ← Nat.add_assoc, add_div_right _ H, ih]\n    rfl\n#align nat.add_mul_div_left Nat.add_mul_div_left\n-/\n\n#print Nat.add_mul_div_right /-\ntheorem add_mul_div_right (x y : ℕ) {z : ℕ} (H : 0 < z) : (x + y * z) / z = x / z + y := by\n  rw [Nat.mul_comm, add_mul_div_left _ _ H]\n#align nat.add_mul_div_right Nat.add_mul_div_right\n-/\n\n#print Nat.mul_div_cancel /-\nprotected theorem mul_div_cancel (m : ℕ) {n : ℕ} (H : 0 < n) : m * n / n = m :=\n  by\n  let t := add_mul_div_right 0 m H\n  rwa [Nat.zero_add, Nat.zero_div, Nat.zero_add] at t\n#align nat.mul_div_cancel Nat.mul_div_cancel\n-/\n\n#print Nat.mul_div_cancel_left /-\nprotected theorem mul_div_cancel_left (m : ℕ) {n : ℕ} (H : 0 < n) : n * m / n = m := by\n  rw [Nat.mul_comm, Nat.mul_div_cancel _ H]\n#align nat.mul_div_cancel_left Nat.mul_div_cancel_left\n-/\n\nprotected theorem div_eq_of_eq_mul_left {m n k : ℕ} (H1 : 0 < n) (H2 : m = k * n) : m / n = k := by\n  rw [H2, Nat.mul_div_cancel _ H1]\n#align nat.div_eq_of_eq_mul_left Nat.div_eq_of_eq_mul_leftₓ\n\nprotected theorem div_eq_of_eq_mul_right {m n k : ℕ} (H1 : 0 < n) (H2 : m = n * k) : m / n = k := by\n  rw [H2, Nat.mul_div_cancel_left _ H1]\n#align nat.div_eq_of_eq_mul_right Nat.div_eq_of_eq_mul_rightₓ\n\nprotected theorem div_eq_of_lt_le {m n k : ℕ} (lo : k * n ≤ m) (hi : m < succ k * n) : m / n = k :=\n  have npos : 0 < n :=\n    n.eq_zero_or_pos.resolve_left fun hn => by\n      rw [hn, Nat.mul_zero] at hi lo <;> exact absurd lo (not_le_of_gt hi)\n  le_antisymm (le_of_lt_succ <| (Nat.div_lt_iff_lt_mul npos).2 hi)\n    ((Nat.le_div_iff_mul_le npos).2 lo)\n#align nat.div_eq_of_lt_le Nat.div_eq_of_lt_leₓ\n\n#print Nat.mul_sub_div /-\ntheorem mul_sub_div (x n p : ℕ) (h₁ : x < n * p) : (n * p - succ x) / n = p - succ (x / n) :=\n  by\n  have npos : 0 < n :=\n    n.eq_zero_or_pos.resolve_left fun n0 => by\n      rw [n0, Nat.zero_mul] at h₁ <;> exact Nat.not_lt_zero _ h₁\n  apply Nat.div_eq_of_lt_le\n  · rw [Nat.mul_sub_right_distrib, Nat.mul_comm]\n    apply Nat.sub_le_sub_left\n    exact (div_lt_iff_lt_mul npos).1 (lt_succ_self _)\n  · change succ (pred (n * p - x)) ≤ succ (pred (p - x / n)) * n\n    rw [succ_pred_eq_of_pos (Nat.sub_pos_of_lt h₁), succ_pred_eq_of_pos (Nat.sub_pos_of_lt _)]\n    · rw [Nat.mul_sub_right_distrib, Nat.mul_comm]\n      apply Nat.sub_le_sub_left\n      apply div_mul_le_self\n    · apply (div_lt_iff_lt_mul npos).2\n      rwa [Nat.mul_comm]\n#align nat.mul_sub_div Nat.mul_sub_div\n-/\n\n#print Nat.div_div_eq_div_mul /-\nprotected theorem div_div_eq_div_mul (m n k : ℕ) : m / n / k = m / (n * k) :=\n  by\n  cases' k.eq_zero_or_pos with k0 kpos; · rw [k0, Nat.mul_zero, Nat.div_zero, Nat.div_zero]\n  cases' n.eq_zero_or_pos with n0 npos; · rw [n0, Nat.zero_mul, Nat.div_zero, Nat.zero_div]\n  apply le_antisymm\n  · apply (le_div_iff_mul_le <| Nat.mul_pos npos kpos).2\n    rw [Nat.mul_comm n k, ← Nat.mul_assoc]\n    apply (le_div_iff_mul_le npos).1\n    apply (le_div_iff_mul_le kpos).1\n    rfl\n  · apply (le_div_iff_mul_le kpos).2\n    apply (le_div_iff_mul_le npos).2\n    rw [Nat.mul_assoc, Nat.mul_comm n k]\n    apply (le_div_iff_mul_le (Nat.mul_pos kpos npos)).1\n    rfl\n#align nat.div_div_eq_div_mul Nat.div_div_eq_div_mul\n-/\n\nprotected theorem mul_div_mul {m : ℕ} (n k : ℕ) (H : 0 < m) : m * n / (m * k) = n / k := by\n  rw [← Nat.div_div_eq_div_mul, Nat.mul_div_cancel_left _ H]\n#align nat.mul_div_mul Nat.mul_div_mul\n\n#print Nat.div_lt_self /-\ntheorem div_lt_self {n m : Nat} : 0 < n → 1 < m → n / m < n :=\n  by\n  intro h₁ h₂\n  have := Nat.mul_lt_mul h₂ (le_refl _) h₁\n  rw [Nat.one_mul, Nat.mul_comm] at this\n  exact (Nat.div_lt_iff_lt_mul <| lt_trans (by comp_val) h₂).2 this\n#align nat.div_lt_self Nat.div_lt_self\n-/\n\n/-! dvd -/\n\n\n#print Nat.dvd_mul_right /-\nprotected theorem dvd_mul_right (a b : ℕ) : a ∣ a * b :=\n  ⟨b, rfl⟩\n#align nat.dvd_mul_right Nat.dvd_mul_right\n-/\n\n#print Nat.dvd_trans /-\nprotected theorem dvd_trans {a b c : ℕ} (h₁ : a ∣ b) (h₂ : b ∣ c) : a ∣ c :=\n  match h₁, h₂ with\n  | ⟨d, (h₃ : b = a * d)⟩, ⟨e, (h₄ : c = b * e)⟩ =>\n    ⟨d * e, show c = a * (d * e) by simp [h₃, h₄, Nat.mul_assoc]⟩\n#align nat.dvd_trans Nat.dvd_trans\n-/\n\n#print Nat.eq_zero_of_zero_dvd /-\nprotected theorem eq_zero_of_zero_dvd {a : ℕ} (h : 0 ∣ a) : a = 0 :=\n  Exists.elim h fun c => fun H' : a = 0 * c => Eq.trans H' (Nat.zero_mul c)\n#align nat.eq_zero_of_zero_dvd Nat.eq_zero_of_zero_dvd\n-/\n\n#print Nat.dvd_add /-\nprotected theorem dvd_add {a b c : ℕ} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c :=\n  Exists.elim h₁ fun d hd => Exists.elim h₂ fun e he => ⟨d + e, by simp [Nat.left_distrib, hd, he]⟩\n#align nat.dvd_add Nat.dvd_add\n-/\n\n#print Nat.dvd_add_iff_right /-\nprotected theorem dvd_add_iff_right {k m n : ℕ} (h : k ∣ m) : k ∣ n ↔ k ∣ m + n :=\n  ⟨Nat.dvd_add h,\n    Exists.elim h fun d hd =>\n      match m, hd with\n      | _, rfl => fun h₂ =>\n        Exists.elim h₂ fun e he =>\n          ⟨e - d, by rw [Nat.mul_sub_left_distrib, ← he, Nat.add_sub_cancel_left]⟩⟩\n#align nat.dvd_add_iff_right Nat.dvd_add_iff_right\n-/\n\n#print Nat.dvd_add_iff_left /-\nprotected theorem dvd_add_iff_left {k m n : ℕ} (h : k ∣ n) : k ∣ m ↔ k ∣ m + n := by\n  rw [Nat.add_comm] <;> exact Nat.dvd_add_iff_right h\n#align nat.dvd_add_iff_left Nat.dvd_add_iff_left\n-/\n\n#print Nat.dvd_sub /-\ntheorem dvd_sub {k m n : ℕ} (H : n ≤ m) (h₁ : k ∣ m) (h₂ : k ∣ n) : k ∣ m - n :=\n  (Nat.dvd_add_iff_left h₂).2 <| by rw [Nat.sub_add_cancel H] <;> exact h₁\n#align nat.dvd_sub Nat.dvd_sub\n-/\n\n#print Nat.dvd_mod_iff /-\ntheorem dvd_mod_iff {k m n : ℕ} (h : k ∣ n) : k ∣ m % n ↔ k ∣ m :=\n  by\n  let t := @Nat.dvd_add_iff_left _ (m % n) _ (Nat.dvd_trans h (Nat.dvd_mul_right n (m / n)))\n  rwa [mod_add_div] at t\n#align nat.dvd_mod_iff Nat.dvd_mod_iff\n-/\n\n#print Nat.le_of_dvd /-\ntheorem le_of_dvd {m n : ℕ} (h : 0 < n) : m ∣ n → m ≤ n := fun ⟨k, e⟩ =>\n  by\n  revert h\n  rw [e]\n  refine' k.cases_on _ _\n  exact fun hn => absurd hn (lt_irrefl _)\n  exact fun k _ => by\n    let t := m.mul_le_mul_left (succ_pos k)\n    rwa [Nat.mul_one] at t\n#align nat.le_of_dvd Nat.le_of_dvd\n-/\n\n#print Nat.dvd_antisymm /-\ntheorem dvd_antisymm : ∀ {m n : ℕ}, m ∣ n → n ∣ m → m = n\n  | m, 0, h₁, h₂ => Nat.eq_zero_of_zero_dvd h₂\n  | 0, n, h₁, h₂ => (Nat.eq_zero_of_zero_dvd h₁).symm\n  | succ m, succ n, h₁, h₂ => le_antisymm (le_of_dvd (succ_pos _) h₁) (le_of_dvd (succ_pos _) h₂)\n#align nat.dvd_antisymm Nat.dvd_antisymm\n-/\n\n#print Nat.pos_of_dvd_of_pos /-\ntheorem pos_of_dvd_of_pos {m n : ℕ} (H1 : m ∣ n) (H2 : 0 < n) : 0 < m :=\n  Nat.pos_of_ne_zero fun m0 => by\n    rw [m0] at H1 <;> rw [Nat.eq_zero_of_zero_dvd H1] at H2 <;> exact lt_irrefl _ H2\n#align nat.pos_of_dvd_of_pos Nat.pos_of_dvd_of_pos\n-/\n\n#print Nat.eq_one_of_dvd_one /-\ntheorem eq_one_of_dvd_one {n : ℕ} (H : n ∣ 1) : n = 1 :=\n  le_antisymm (le_of_dvd (by decide) H) (pos_of_dvd_of_pos H (by decide))\n#align nat.eq_one_of_dvd_one Nat.eq_one_of_dvd_one\n-/\n\n#print Nat.dvd_of_mod_eq_zero /-\ntheorem dvd_of_mod_eq_zero {m n : ℕ} (H : n % m = 0) : m ∣ n :=\n  ⟨n / m, by\n    have t := (mod_add_div n m).symm\n    rwa [H, Nat.zero_add] at t⟩\n#align nat.dvd_of_mod_eq_zero Nat.dvd_of_mod_eq_zero\n-/\n\n#print Nat.mod_eq_zero_of_dvd /-\ntheorem mod_eq_zero_of_dvd {m n : ℕ} (H : m ∣ n) : n % m = 0 :=\n  Exists.elim H fun z H1 => by rw [H1, mul_mod_right]\n#align nat.mod_eq_zero_of_dvd Nat.mod_eq_zero_of_dvd\n-/\n\n#print Nat.dvd_iff_mod_eq_zero /-\ntheorem dvd_iff_mod_eq_zero {m n : ℕ} : m ∣ n ↔ n % m = 0 :=\n  ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩\n#align nat.dvd_iff_mod_eq_zero Nat.dvd_iff_mod_eq_zero\n-/\n\ninstance decidableDvd : @DecidableRel ℕ (· ∣ ·) := fun m n =>\n  decidable_of_decidable_of_iff (by infer_instance) dvd_iff_mod_eq_zero.symm\n#align nat.decidable_dvd Nat.decidableDvd\n\nprotected theorem mul_div_cancel' {m n : ℕ} (H : n ∣ m) : n * (m / n) = m :=\n  by\n  let t := mod_add_div m n\n  rwa [mod_eq_zero_of_dvd H, Nat.zero_add] at t\n#align nat.mul_div_cancel' Nat.mul_div_cancel'ₓ\n\nprotected theorem div_mul_cancel {m n : ℕ} (H : n ∣ m) : m / n * n = m := by\n  rw [Nat.mul_comm, Nat.mul_div_cancel' H]\n#align nat.div_mul_cancel Nat.div_mul_cancelₓ\n\nprotected theorem mul_div_assoc (m : ℕ) {n k : ℕ} (H : k ∣ n) : m * n / k = m * (n / k) :=\n  Or.elim k.eq_zero_or_pos (fun h => by rw [h, Nat.div_zero, Nat.div_zero, Nat.mul_zero]) fun h =>\n    by\n    have : m * n / k = m * (n / k * k) / k := by rw [Nat.div_mul_cancel H]\n    rw [this, ← Nat.mul_assoc, Nat.mul_div_cancel _ h]\n#align nat.mul_div_assoc Nat.mul_div_assocₓ\n\ntheorem dvd_of_mul_dvd_mul_left {m n k : ℕ} (kpos : 0 < k) (H : k * m ∣ k * n) : m ∣ n :=\n  Exists.elim H fun l H1 => by\n    rw [Nat.mul_assoc] at H1 <;> exact ⟨_, Nat.eq_of_mul_eq_mul_left kpos H1⟩\n#align nat.dvd_of_mul_dvd_mul_left Nat.dvd_of_mul_dvd_mul_leftₓ\n\ntheorem dvd_of_mul_dvd_mul_right {m n k : ℕ} (kpos : 0 < k) (H : m * k ∣ n * k) : m ∣ n := by\n  rw [Nat.mul_comm m k, Nat.mul_comm n k] at H <;> exact dvd_of_mul_dvd_mul_left kpos H\n#align nat.dvd_of_mul_dvd_mul_right Nat.dvd_of_mul_dvd_mul_rightₓ\n\n/-! iterate -/\n\n\n#print Nat.iterate /-\ndef iterate {α : Sort u} (op : α → α) : ℕ → α → α\n  | 0, a => a\n  | succ k, a => iterate k (op a)\n#align nat.iterate Nat.iterate\n-/\n\n-- mathport name: «expr ^[ ]»\nnotation f \"^[\" n \"]\" => iterate f n\n\n/-! find -/\n\n\nsection Find\n\nparameter {p : ℕ → Prop}\n\nprivate def lbp (m n : ℕ) : Prop :=\n  m = n + 1 ∧ ∀ k ≤ n, ¬p k\n#align nat.lbp nat.lbp\n\nparameter [DecidablePred p](H : ∃ n, p n)\n\nprivate def wf_lbp : WellFounded lbp :=\n  ⟨let ⟨n, pn⟩ := H\n    suffices ∀ m k, n ≤ k + m → Acc lbp k from fun a => this _ _ (Nat.le_add_left _ _)\n    fun m =>\n    Nat.recOn m\n      (fun k kn =>\n        ⟨_, fun y r =>\n          match y, r with\n          | _, ⟨rfl, a⟩ => absurd pn (a _ kn)⟩)\n      fun m IH k kn =>\n      ⟨_, fun y r =>\n        match y, r with\n        | _, ⟨rfl, a⟩ => IH _ (by rw [Nat.add_right_comm] <;> exact kn)⟩⟩\n#align nat.wf_lbp nat.wf_lbp\n\n#print Nat.findX /-\nprotected def findX : { n // p n ∧ ∀ m < n, ¬p m } :=\n  @WellFounded.fix _ (fun k => (∀ n < k, ¬p n) → { n // p n ∧ ∀ m < n, ¬p m }) lbp wf_lbp\n    (fun m IH al =>\n      if pm : p m then ⟨m, pm, al⟩\n      else\n        have : ∀ n ≤ m, ¬p n := fun n h =>\n          Or.elim (Decidable.lt_or_eq_of_le h) (al n) fun e => by rw [e] <;> exact pm\n        IH _ ⟨rfl, this⟩ fun n h => this n <| Nat.le_of_succ_le_succ h)\n    0 fun n h => absurd h (Nat.not_lt_zero _)\n#align nat.find_x Nat.findX\n-/\n\n#print Nat.find /-\n/-- If `p` is a (decidable) predicate on `ℕ` and `hp : ∃ (n : ℕ), p n` is a proof that\nthere exists some natural number satisfying `p`, then `nat.find hp` is the\nsmallest natural number satisfying `p`. Note that `nat.find` is protected,\nmeaning that you can't just write `find`, even if the `nat` namespace is open.\n\nThe API for `nat.find` is:\n\n* `nat.find_spec` is the proof that `nat.find hp` satisfies `p`.\n* `nat.find_min` is the proof that if `m < nat.find hp` then `m` does not satisfy `p`.\n* `nat.find_min'` is the proof that if `m` does satisfy `p` then `nat.find hp ≤ m`.\n-/\nprotected def find : ℕ :=\n  Nat.findX.1\n#align nat.find Nat.find\n-/\n\n#print Nat.find_spec /-\nprotected theorem find_spec : p Nat.find :=\n  Nat.findX.2.left\n#align nat.find_spec Nat.find_spec\n-/\n\n#print Nat.find_min /-\nprotected theorem find_min : ∀ {m : ℕ}, m < Nat.find → ¬p m :=\n  Nat.findX.2.right\n#align nat.find_min Nat.find_min\n-/\n\n#print Nat.find_min' /-\nprotected theorem find_min' {m : ℕ} (h : p m) : Nat.find ≤ m :=\n  le_of_not_lt fun l => find_min l h\n#align nat.find_min' Nat.find_min'\n-/\n\nend Find\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/Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7931882764339302}}
{"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 → Y` and `g : Y → Z`\n-- be functions\n\nvariables {X Y Z : Type} {f : X → Y} {g : Y → 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 ↔ ∀ a b : X, f a = f b → 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 → 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 → X) :=\nbegin\n  -- these rewrites are not necessary, but I'll\n  -- put them in just this once\n  -- ⊢ injective id\n  rw injective_def,\n  -- ⊢ ∀ (a b : X), id a = id b → a = b\n  intros a b hab,\n  -- hab: id a = id b\n  -- again another rewrite which isn't actually necessary\n  rw id_def at hab, \n  rw id_def at hab, \n  -- hab : a = b\n  exact hab,\nend\n\n-- function composition g ∘ f is satisfies (g ∘ f) (x) = g(f(x)). This\n-- is true by definition. Let's check this\n\nlemma comp_def : (g ∘ 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 ∘ f) :=\nbegin\n  -- I'll do this without any definitional rewrites\n  -- ⊢ injective (g ∘ f)\n  -- so goal is by definition \"for all a, b, ...\" and I can just intro\n  intros a b h,\n  -- `hf : injective f`, so `hf : ∀ a b : X, f a = f b → a = b`\n  -- and my goal is `a = b` so this will work\n  apply hf,\n  apply hg,\n  exact h, -- again `h` is not syntactically equal to the goal,\n  -- but it is definitionally equal to the goal\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 ↔ ∀ y : Y, ∃ 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 → X) :=\nbegin\n  -- you can start with `rw surjective_def` if you like.\n  intro x,\n  use x,\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 ∘ 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/-!\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 ↔ injective f ∧ 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 → X) :=\nbegin\n  exact ⟨injective_id, surjective_id⟩,\nend\n\n/-- A composite of bijective functions is bijective. -/\nlemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g ∘ f) :=\nbegin\n  cases hf with hf_inj hf_surj,\n  cases hg with hg_inj hg_surj,\n  exact ⟨injective_comp hf_inj hg_inj, surjective_comp hf_surj hg_surj⟩\nend\n\nend xena\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_C_functions_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7930609505206345}}
{"text": "theorem mul_eq_zero_iff (a b : mynat): a * b = 0 ↔ a = 0 ∨ b = 0 :=\nbegin\nsplit,\nexact eq_zero_or_eq_zero_of_mul_eq_zero a b,\nintro h,\ncases h,\nrw h,\nexact zero_mul b,\nrw h,\nexact mul_zero a,\n\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/7-advanced-multiplication-world/l3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9539661028358093, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7928822862843853}}
{"text": "import data.real.basic\n\nimport data.real.basic\n\n/-Lean is a programming language used for proof formalisation,\nmeaning the program checks that a given proof is actually correct.\nHere, we will give a brief summary of how to use Lean. We will then \nmove onto proving some results requiring the uses of axioms for the real \nnumbers -/\n\n/-We defined the axioms of addition for the real numbers as follows\n(A.1) Commutativity : a + b = b + a, ∀ a,b ∈ ℝ\nThe associated theorem in Lean is add_comm\n(A.2) Associativity : (a + b) + c = a + (b + c), ∀ a, b, c ∈ ℝ \nIn Lean, this is known as add_assoc\n(A.3) Existence of 0 : ∃ (0∈ℝ) such that 0 + a = a\nIn Lean, this is known as zero_add\n(A.4) Existence of the negative : ∀ a∈ℝ, ∃x∈ℝ such that a + x = 0-/\n\n/-Our axioms of multiplication for the real numbers are the following\n(M.1) Commutativity : a*b = b*a for all a, b ∈ ℝ.\nIn Lean, this is known as mul_comm\n(M.2) Associativity : (a * b) * c = a * (b * c) for all a, b, c ∈ ℝ.\nIn Lean, this is known as mul_assoc\n(M.3) Existence of 1 : There is a real number 1 ̸= 0 with 1 * a = a for all a ∈ ℝ.\nIn Lean, this is known as one_mul\n(M.4) Existence of the inverse : ∀ a ∈ R \\ {0} there is a unique x ∈ ℝ with a * x = 1.\n\n-/\n\n/-We also have distributivity\n(D.1) Distributivity : a * (b + c) = (a * b) + (a * c) for all a, b, c ∈ ℝ.\nIn Lean, this is known as left_distrib\n-/\n\n/-When using Lean, if we want to use a theorem involving an equals sign,\nwe use the rw tactic to tell Lean our intention. This will apply the said\ntheorem at all locations it can. If you only want to use it at a certain \nlocation, you can use nth_rewrite x, where x is a non-negative integer\nand specifies the location to apply the theorem\nWhen we want to use a theorem with an implication, you should use the apply\ntactic\n\n\nWe now provide a few examples on how to use Lean\n-/\n\nexample (a : ℝ) : 0 + a + 0 = a:=\nbegin\nrw add_zero,\nrw zero_add\nend\n\n/-In thenext example we use a backward arrow ← to use the backward version \nof the equality\n-/ \n\nexample (a b c : ℝ): a+c+b = a + b + c:=\nbegin\nrw add_assoc,\nrw add_comm c b,\nrw ← add_assoc,\nend\n\n/-When we specify where to change a statement with nth_rewrite, the first\nposition starts from 0-/\n\nexample (a b : ℝ):  a*1 + 1*a   =  a*1 + a*1 :=\nbegin\nnth_rewrite 3 mul_comm,\nend\n\n\nexample (a b : ℝ):  a*1 + 1*a   =  a*1 + a*1 :=\nbegin\nnth_rewrite 1 ← mul_comm,\nend\n\n\n\n\ntheorem neg_sub_pos_self1 : (-1 : ℝ) + 1 = 0 :=\nbegin\nexact neg_add_self 1,\nend\n\n\n\nexample:  2 * 2 = 4 :=\nbegin\nnth_rewrite 0 ← one_add_one_eq_two,\nnth_rewrite 0 ← one_add_one_eq_two,\nrw left_distrib,\nrw mul_comm,\nrw left_distrib,\nrw one_mul,\nend\n\n\ntheorem neg_one_a_inv (a b:ℝ): -a = (-1)*a:=\nbegin\nsuffices: (-1)*a +a = 0,\n{apply eq.symm at this,\nexact eq_neg_iff_add_eq_zero.mpr this,},\nnth_rewrite 1 ←one_mul a,\nrw mul_comm,\nrw mul_comm 1 a,\nrw ← left_distrib, \nrw neg_sub_pos_self1,\nrw mul_zero,\n\n\nend\n\n\n\nexample (a:ℝ): (-a)^2 = a^2:=\nbegin\nrw pow_two,\nrw neg_one_a_inv,\nrw mul_assoc,\nrw ← mul_assoc a,\nrw mul_comm a (-1),\nrw  mul_assoc (-1) a a,\nrw ←pow_two,\nrw ← mul_assoc,\nrw neg_one_mul,\nrw neg_neg,\nrw one_mul,\napply a,\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/Analysisexamplesolutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660976007597, "lm_q2_score": 0.8311430394931457, "lm_q1q2_score": 0.7928822819333103}}
{"text": "/- Yair Gueta : 208624908 : t2\n    Exercise 2\n-/\nopen classical\nvariables p q r s : Prop\n\n\n-- commutativity of ∧ and ∨\nexample : p ∨ q ↔ q ∨ p := \niff.intro\n  (assume hpq : p ∨ q,\n    or.elim hpq\n      (assume hp : p,\n        show q ∨ p, from or.inr hp)\n      (assume hq : q,\n        show q ∨ p,  from or.inl hq))\n  (assume hqp : q ∨ p,\n    or.elim hqp\n      (assume hq : q,\n        show p ∨ q, from or.inr hq)\n      (assume hp : p,\n        show p ∨ q, from or.inl hp))\n\n-- associativity of ∧ and ∨\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := \niff.intro\n  (assume hpq_r : (p ∨ q) ∨ r,\n    hpq_r.elim\n      (assume hpq : p ∨ q, \n        or.elim hpq\n          (assume hp : p,\n            show p ∨ (q ∨ r), from or.inl hp)\n          (assume hq : q,\n            have hqr : q ∨ r, from or.inl hq,\n            show p ∨ (q ∨ r), from or.inr hqr))\n      (assume hr : r,\n        have hqr : q ∨ r, from or.inr hr,\n        show p ∨ (q ∨ r), from or.inr hqr))\n  (assume hp_qr : p ∨ (q ∨ r),\n    hp_qr.elim\n      (assume hp : p,\n        have hpq : p ∨ q, from or.inl hp,\n        show (p ∨ q) ∨ r, from or.inl hpq)\n      (assume hqr : q ∨ r,\n        hqr.elim\n          (assume hq : q,\n            have hpq : p ∨ q, from or.inr hq,\n            show (p ∨ q) ∨ r, from or.inl hpq)\n          (assume hr : r,\n            show (p ∨ q) ∨ r, from or.inr hr)))\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := \niff.intro\n  (assume h : p ∧ (q ∨ r),\n    have hp : p, from h.left,\n    h.right.elim\n      (assume hq : q,\n        have hpq : p ∧ q, from ⟨hp, hq⟩,\n        show (p ∧ q) ∨ (p ∧ r), from or.inl hpq)\n      (assume hr : r,\n        have hpr : p ∧ r, from ⟨hp, hr⟩,\n        show (p ∧ q) ∨ (p ∧ r), from or.inr hpr)\n  )\n  (assume h : (p ∧ q) ∨ (p ∧ r),\n    h.elim\n      (assume hpq : p ∧ q,\n        have hp : p, from hpq.left,\n        have hq : q, from hpq.right,\n        show p ∧ (q ∨ r), from ⟨hp, or.inl hq⟩)\n      (assume hpr : p ∧ r,\n        have hp : p, from hpr.left,\n        have hr : r, from hpr.right,\n        show p ∧ (q ∨ r), from ⟨hp, or.inr hr⟩)\n  )\n\n-- other properties\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \niff.intro \n  (assume h : ¬(p ∨ q),\n    have np : ¬p, from \n      assume hp : p,\n      show false, from h (or.inl hp),\n    have nq : ¬q, from\n      assume hq : q, \n      show false, from h (or.inr hq),\n    show ¬p ∧ ¬q, from ⟨np, nq⟩)\n  (assume h : ¬p ∧ ¬q,\n    show ¬(p ∨ q), from\n      assume hpq : p ∨ q,\n      hpq.elim\n        (assume hp : p, \n          show false, from h.left hp)\n        (assume hq : q, \n          show false, from h.right hq)\n  )\n\nexample : p ∧ false ↔ false := \niff.intro\n  (assume h : p ∧ false,\n    show false, from h.right)\n  (assume h : false, \n    show p ∧ false, from ⟨false.elim(h) , h⟩)\n\nexample : (p → q) → (¬q → ¬p) := \nassume hpq : p → q,\n  assume hnq : ¬q,\n    assume hp : p,\n      have hq : q, from hpq hp,\n      show false, from hnq hq\n\n\n\n-- classical\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) := \nassume h : (p → r ∨ s),\n  by_cases\n    (assume hp : p, \n      have hrs : r ∨ s, from h hp,\n      show ((p → r) ∨ (p → s)), from \n        hrs.elim\n          (assume hr : r, \n            show ((p → r) ∨ (p → s)), from or.inl (λ hhp : p, hr))\n          (assume hs : s, \n            show ((p → r) ∨ (p → s)), from or.inr (λ hhp : p, hs))\n    )\n    (assume hnp : ¬p, \n      have hpr : p → r, from \n        (assume hp : p, \n        show r, from absurd hp hnp),\n      show ((p → r) ∨ (p → s)), from or.inl hpr)\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q := \nassume h : ¬(p ∧ q),\n  by_cases\n    (assume hp : p,\n      have hnq : ¬q, from \n        assume hq : q, \n        show false, from h ⟨hp, hq⟩,\n      show ¬p ∨ ¬q, from or.inr hnq)\n    (assume hnp : ¬p, or.inl hnp)\n\nexample : ¬(p → q) → p ∧ ¬q := \nassume h : ¬(p → q),\n  by_cases\n    (assume hp : p, \n      have hnq : ¬q, from \n        assume hq : q, \n        have hpq : p → q, from λ hhp : p, hq,\n        show false, from h hpq,\n      show p ∧ ¬q, from ⟨hp, hnq⟩)\n    (assume hnp : ¬p, \n      have hpq : p → q, from \n        assume hp : p, absurd hp hnp,\n      show p ∧ ¬q, from absurd hpq h)", "meta": {"author": "yairgueta", "repo": "Lean", "sha": "af8a4fa24f76edfdd0dd33f013db194e611e6a86", "save_path": "github-repos/lean/yairgueta-Lean", "path": "github-repos/lean/yairgueta-Lean/Lean-af8a4fa24f76edfdd0dd33f013db194e611e6a86/src/t2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176863577751, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7928573819430131}}
{"text": "import data.int.basic  tactic.linarith\n\n\n/- abs -/\n\n/-- any integer greater than or equal to some absolute value is non-negative-/\nlemma abs_le_nonneg {a b : ℤ } : abs(a) ≤ b → 0 ≤ b:=\nbegin \nhave h : 0 ≤ abs(a),\n  {show abs(a) ≥ 0, -- ≥ is defined via ≤ \n  exact abs_nonneg a}, -- absolute values are non-negative\nintro x,\nexact le_trans h x, -- using transitivity of ≤ \nend\n\n\n/--the absolute value of a difference of values is greater than or equal\n   to the the absolute value of the difference of their absolute values-/\ntheorem abs_abs_sub_abs_le (a b : ℤ) : abs (abs a - abs b) ≤ abs (a - b) :=\n-- proof in term mode\nabs_le.2 ⟨by rw [neg_le,neg_sub, abs_sub]; apply sub_abs_le_abs_sub, sub_abs_le_abs_sub a b⟩\n\n\n/-- For any a, b, x, y, d in ℤ,\n    if abs (a - b) ≤ d and abs (x - y) ≤ d, then abs (min a x - min b y) ≤ d-/\nlemma abs_min_sub_min {a b x y d : ℤ} (hab : abs (a - b) ≤ d)\n  (hxy : abs (x - y) ≤ d) : abs (min a x - min b y) ≤ d :=\nbegin\n  rw abs_le at *, -- abs (m - n) ≤ d ↔ d ≤ m - n ∧ m - n ≤ d, for any m,n in ℤ \n  cases hab,\n  cases hxy,\n  unfold min, -- min a x = if (a ≤ x), then a, else x\n              -- min b y = if (b ≤ y), then b, else y\n  split_ifs; split; linarith, -- all cases Lean can solve by itself using linarith\nend\n\n\n\n/- lt -/\n\n/--if there exists an element strictly between a and the sucessor of c in ℕ, then a is smaller than c -/\nlemma lt_trans_of_succ {a b c : ℕ}: a < b → b < nat.succ c → a < c :=\nbegin\nintros h1 h2,\nrw nat.lt_succ_iff at h2, -- b < nat.succ c ↔ b ≤ c\nexact lt_of_lt_of_le h1 h2, /- lt_of_lt_of_le says : for all x, y, z of some adequate type,\n                               x < y → y ≤ z → a < z-/\nend", "meta": {"author": "ImperialCollegeLondon", "repo": "dots_and_boxes", "sha": "f7bd0b1603674a657170c5395adb717c4f670220", "save_path": "github-repos/lean/ImperialCollegeLondon-dots_and_boxes", "path": "github-repos/lean/ImperialCollegeLondon-dots_and_boxes/dots_and_boxes-f7bd0b1603674a657170c5395adb717c4f670220/src/misc_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238083, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7928573772412529}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro p,\n  intro no_p,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro p,\n  by_cases new_p : P,\n  exact new_p,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P,\n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro p_or_q,\n  cases p_or_q with p q,\n  right,\n  exact p,\n  left,\n  exact q,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro p_and_q,\n  split,\n  cases p_and_q,\n  exact p_and_q_right,\n  cases p_and_q,\n  exact p_and_q_left,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro p,\n  intro h,\n  cases p with no_p q,\n  contradiction,\n  exact q,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro p_or_q,\n  intro no_p,\n  cases p_or_q with p q,\n  contradiction,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro p_q,\n  intro no_q,\n  intro p_boom,\n  have q : Q := p_q p_boom,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro nq_np,\n  intro p,\n  by_contradiction qboom,\n  have np : ¬P := nq_np qboom,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  exact impl_as_contrapositive P Q,\n  exact impl_as_contrapositive_converse P Q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro p_np,\n  have h : (P∨¬P),\n  right,\n  intro p,\n  have p_or_np : (P∨¬P),\n  left, \n  exact p,\n  contradiction,\n  contradiction,\n  \nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro p_q_p,\n  intro np,\n  have p_q : (P → Q),\n  intro p,\n  contradiction,\n  have p : P := p_q_p p_q,\n  contradiction,\n\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro p_or_q,\n  intro np_nq,\n  cases np_nq,\n  cases p_or_q,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro p_q,\n  intro np_or_nq,\n  cases np_or_nq,\n  cases p_q,\n  contradiction,\n  cases p_q,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro n_p_or_q,\n  split,\n  intro p,\n  have p_or_q :(P∨Q),\n  left,\n  exact p,\n  contradiction,\n  intro q,\n  have p_or_q :(P∨Q),\n  right,\n  exact q,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro np_nq,\n  intro p_or_q,\n  cases np_nq,\n  cases p_or_q,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro n_p_q,\n  by_cases p: P,\n  left,\n  intro q,\n  have p_q: (P∧Q),\n  split,\n  exact p,\n  exact q,\n  contradiction,\n  right,\n  exact p,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro n_q_or_n_p,\n  intro p_q,\n  cases p_q,\n  cases n_q_or_n_p,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\n\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n  exact demorgan_disj_converse P Q,\n\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro p_q_or_r,\n  cases p_q_or_r,\n  cases p_q_or_r_right,\n  left,\n  split,\n  exact p_q_or_r_left,\n  exact p_q_or_r_right,\n  right,\n  split,\n  exact p_q_or_r_left,\n  exact p_q_or_r_right,\n\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro pq_or_pr,\n  cases pq_or_pr,\n  cases pq_or_pr,\n  split,\n  exact pq_or_pr_left,\n  left,\n  exact pq_or_pr_right,\n  cases pq_or_pr,\n  split,\n  exact pq_or_pr_left,\n  right,\n  exact pq_or_pr_right,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro p_or_qr,\n  cases p_or_qr,\n  split,\n  left,\n  exact p_or_qr,\n  left,\n  exact p_or_qr,\n  cases p_or_qr,\n  split,\n  right,\n  exact p_or_qr_left,\n  right,\n  exact p_or_qr_right,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro p_or_q_p_or_r,\n  cases p_or_q_p_or_r,\n  cases p_or_q_p_or_r_left,\n  left, \n  exact p_or_q_p_or_r_left,\n  cases p_or_q_p_or_r_right,\n  left,\n  exact p_or_q_p_or_r_right,\n  right,\n  split,\n  exact p_or_q_p_or_r_left,\n  exact p_or_q_p_or_r_right,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro pqr,\n  intro p,\n  intro q,\n  have pq : (P∧Q),\n  split,\n  exact p,\n  exact q,\n  have r := pqr pq,\n  exact r,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro p_q_r,\n  intro pq,\n  cases pq,\n  have q_r := p_q_r pq_left,\n  have r := q_r pq_right,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro pq,\n  cases pq,\n  exact pq_left,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro pq,\n  cases pq,\n  exact pq_right,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pp,\n  cases pp,\n  exact pp_left,\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro p_or_p,\n  cases p_or_p,\n  exact p_or_p,\n  exact p_or_p,\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro ne_p,\n  intro u,\n  intro p_u,\n  apply ne_p,\n  existsi u,\n  exact p_u,\n\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro  fa_np,\n  intro eu,\n  cases eu with u pu,\n  exact fa_np u pu,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro np,\n  by_contradiction hboom,\n  apply np,\n  intro u,\n  by_contradiction h,\n  apply hboom,\n  existsi u,\n  intro pu,\n  contradiction, \nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro eu,\n  cases eu with u npu,\n  intro au,\n  have p : P u := au u,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n  exact demorgan_forall_converse U P,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro eu,\n  intro au,\n  cases eu with u pu,\n  exact au u pu,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro au,\n  intro eu,\n  cases eu with u npu,\n  have pu : P u := au u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro npu,\n  by_contradiction hboom,\n  apply hboom,\n  intro u,\n  by_contradiction pboom,\n  apply npu,\n  existsi u,\n  intro pu,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro au,\n  by_contradiction hboom,\n  apply au,\n  intro u, \n  intro pu,\n  apply hboom,\n  existsi u,\n  by_contradiction,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n  exact forall_as_neg_exists_converse U P,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro epq,\n  cases epq with hu hqp,\n  split,\n  existsi hu,\n  cases hqp with p q,\n  exact p,\n  cases hqp with p q,\n  existsi hu,\n  exact q,\n\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro ep_or_q,\n  cases ep_or_q with hu hpq,\n  cases hpq,\n  left,\n  existsi hu,\n  exact hpq,\n  right,\n  existsi hu,\n  exact hpq,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro p_or_q,\n  cases p_or_q,\n  cases p_or_q with u p,\n  existsi u,\n  left,\n  exact p,\n  cases p_or_q with u q,\n  existsi u,\n  right,\n  exact q,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro apq,\n  split,\n  intro u,\n  have pu: P u ∧ Q u := apq u,\n  cases pu with p q,\n  exact p,\n  intro u,\n  have pu: P u ∧ Q u := apq u,\n  cases pu with p q,\n  exact q,\n  \nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro apq,\n  cases apq with ap aq,\n  intro u,\n  split, \n  exact ap u,\n  exact aq u,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro ap_or_aq,\n  intro u,\n  cases ap_or_aq with ap aq,\n  left,\n  exact ap u,\n  right, \n  exact aq u,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "GusFreitasR", "repo": "fmclean", "sha": "4ab333312f05b4c1c468b5c0f078db058ae4e63b", "save_path": "github-repos/lean/GusFreitasR-fmclean", "path": "github-repos/lean/GusFreitasR-fmclean/fmclean-4ab333312f05b4c1c468b5c0f078db058ae4e63b/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7928263833077469}}
{"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.fdRep\nimport linear_algebra.trace\nimport representation_theory.basic\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ᘁ` and `ihom V W`.\n-/\n\nnoncomputable theory\n\nuniverses u\n\nopen linear_map category_theory.monoidal_category representation\n\nvariables {k G : Type u} [field k]\n\nnamespace fdRep\n\nsection monoid\n\nvariables [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.ρ g`.-/\ndef character (V : fdRep k G) (g : G) := linear_map.trace k V (V.ρ g)\n\nlemma char_mul_comm (V : fdRep k G) (g : G) (h : G) : V.character (h * g) = V.character (g * h) :=\nby simp only [trace_mul_comm, character, map_mul]\n\n@[simp] lemma char_one  (V : fdRep k G) : V.character 1 = finite_dimensional.finrank k V :=\nby simp only [character, map_one, trace_one]\n\n/-- The character is multiplicative under the tensor product. -/\n@[simp] lemma char_tensor (V W : fdRep k G) : (V ⊗ W).character = V.character * W.character :=\nby { ext g, convert trace_tensor_product' (V.ρ g) (W.ρ g) }\n\n/-- The character of isomorphic representations is the same. -/\nlemma char_iso  {V W : fdRep k G} (i : V ≅ W) : V.character = W.character :=\nby { ext g, simp only [character, fdRep.iso.conj_ρ i], exact (trace_conj' (V.ρ g) _).symm }\n\nend monoid\n\nsection group\n\nvariables [group G]\n\n/-- The character of a representation is constant on conjugacy classes. -/\n@[simp] lemma char_conj (V : fdRep k G) (g : G) (h : G) :\n  V.character (h * g * h⁻¹) = V.character g :=\nby rw [char_mul_comm, inv_mul_cancel_left]\n\n@[simp] lemma char_dual (V : fdRep k G) (g : G) : (of (dual V.ρ)).character g = V.character g⁻¹ :=\n  trace_transpose' (V.ρ g⁻¹)\n\n@[simp] lemma char_lin_hom (V W : fdRep k G) (g : G) :\n  (of (lin_hom V.ρ W.ρ)).character g = (V.character g⁻¹) * (W.character g) :=\nby { rw [←char_iso (dual_tensor_iso_lin_hom _ _), char_tensor, pi.mul_apply, char_dual], refl }\n\nend group\n\nend fdRep\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/character.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8688267626522814, "lm_q1q2_score": 0.792748947159009}}
{"text": "import data.nat.basic\n\nnamespace nat\n\nlemma lt_iff_add_one_le {m n : ℕ} :\n  m < n ↔ m + 1 ≤ n  := by rw succ_le_iff\n\nlemma add_lt_add_of_le_of_le_of_lt_or_lt {a b c d : nat} :\n  a ≤ b → c ≤ d → (a < b ∨ c < d) → a + c < b + d := \nbegin\n  intros h1 h2 h3, cases h3,\n  apply add_lt_add_of_lt_of_le; assumption,\n  apply add_lt_add_of_le_of_lt; assumption\nend\n\nlemma max_succ_succ {m n} : \n  max (succ m) (succ n) = succ (max m n) :=\nbegin\n  by_cases h1 : m ≤ 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": "omega", "sha": "715e384ed14e8eb177a326700066e7c98269e078", "save_path": "github-repos/lean/skbaek-omega", "path": "github-repos/lean/skbaek-omega/omega-715e384ed14e8eb177a326700066e7c98269e078/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7927086305761911}}
{"text": "/- Formalisation of Groups from the module Linear Algebra and Groups -/\nimport tactic\n/- Chapter 1. Groups and Subgroups -/\n\nnamespace M40004\n\n-- Definition of a group\n@[simp] def is_assoc (G : Type*) (operat : G → G → G) := \n∀ g h k : G, operat (operat g h) k = operat g (operat h k)\n\n@[simp] def is_identity (G : Type*) (operat : G → G → G) (e : G) :=\n∀ g : G, operat g e = operat e g ∧ operat g e = g\n\n@[simp] def has_identity (G : Type*) (operat : G → G → G) :=\n∃ e : G, is_identity G operat e\n\n@[simp] def is_inverse (G : Type*) (operat : G → G → G) (g h : G) :=\noperat g h = operat h g ∧ is_identity G operat (operat g h)\n\n@[simp] def has_inverse (G : Type*) (operat : G → G → G) :=\n∀ g : G, ∃ h : G, is_inverse G operat g h\n\nstructure is_group (G : Type*) (operat : G → G → G) :=\n(group_assoc : is_assoc G operat)\n(group_identity : has_identity G operat)\n(group_inverse : has_inverse G operat)\n\n-- A group has a unique identity\ntheorem unique_identity {G : Type*} {operat : G → G → G} :\n∀ e₁ e₂ : G, is_identity G operat e₁ ∧ is_identity G operat e₂ →  e₁ = e₂ :=\nbegin\n    rintros e₁ e₂ ⟨id₁, id₂⟩,\n    rw [←(id₂ e₁).right, (id₂ e₁).left],\n    from (id₁ e₂).right\nend\n\n-- An element in a group has an unique inverse\ntheorem unique_inverse {G : Type*} {operat : G → G → G} (hgp : is_group G operat) :\n∀ g h k : G, is_inverse G operat g h ∧ is_inverse G operat g k → h = k :=\nbegin\n    rintros g h k ⟨invh, invk⟩,\n    have : operat (operat k g) h = h :=\n        by {cases invk with heq hid,by \n            rw [←heq, ←(hid h).left, (hid h).right]\n        },\n    rw [←this, hgp.group_assoc],\n    repeat {swap, assumption},\n    suffices : is_identity G operat (operat g h),\n        rwa (this k).right,\n    from invh.right\nend\n\n-- Some lemmas that makes working easier\nlemma operat_both_sides {G : Type*} {operat : G → G → G} {hgp : is_group G operat} (a b c : G) :\nb = c → operat a b = operat a c := λ h, by {rw h}\n\n-- Some properties of a group\n\n-- If ab = ac then b = c\ntheorem left_operat_cancel {G : Type*} {operat : G → G → G} (hgp : is_group G operat) :\n∀ a b c : G, operat a b = operat a c → b = c :=\nbegin\n    intros a b c h,\n    cases hgp.group_inverse a with ainv hainv,\n    suffices : operat ainv (operat a b) = operat ainv (operat a c),\n        repeat {rw ←hgp.group_assoc at this},\n        sorry,\n    sorry\nend\n\nend M40004\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/Groups/groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630935, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7927086287077915}}
{"text": "import tactic --hide\nlemma not_iff_imp_false (P : Prop) : ¬ P ↔ P → false := iff.rfl -- hide\nlemma contra (P Q : Prop) : (P ∧ ¬ P) → Q := by {cc} --hide\n\n\n/-Lemma\nIf $P$ is a logical statement then $¬(¬P) \\implies P$.\n-/\nlemma not_not_P_imp_P (P : Prop) :¬ (¬ P) → P :=\nbegin\n  rw not_iff_imp_false,\n  intro hp,\n  by_cases hp2 : P,\n  exact hp2,\n  exfalso,\n  apply hp,\n  exact hp2,\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/logic3/notlogicb3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541643004809, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7927086226125878}}
{"text": "-- Pruebas de (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j)\n-- ============================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j)\n-- ----------------------------------------------------\n\nimport data.set\n\nopen set\n\nvariables {I J U : Type}\nvariables (A : I → J → set U)\n\n-- 1ª demostración\nexample : (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j) :=\nbegin\n  intros x h,\n  rw mem_Union at h,\n  cases h with i hi,\n  rw mem_Inter at hi,\n  apply mem_Inter.mpr,\n  intro j,\n  apply mem_Union.mpr,\n  use i,\n  exact (hi j),\nend\n\n-- 2ª demostración\nexample : (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j) :=\nbegin\n  intros x h,\n  simp * at *,\n  cases h with i hi,\n  intro j,\n  use i,\n  exact (hi j),\nend\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/Uniones_de_intersecciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7927065192080495}}
{"text": "/-\nJustin Ngo\njmn4fms\n5/4/20\nSullivan 2102-001\n-/\n\n/-\nCS2102 Spring 2020 Final Exam. You are\nto take this exam entirely on your own.\nYou may not discuss it with anyone but\nthe instructor and TAs. The exam has 6\nqustions, some with several parts. Read\nthe entire exam first to get a sense of\nthe easy and hard parts. Do the easier\nparts first while letting your mind work\nin the background on the harder parts.\nSubmit your completed exam on Collab.\nThe exam is due no later than 5PM sharp\n***EDT*** on May 8. Please set yourself\na reminder.\n-/\n\n\n/-\n1. You know from our study of the Boolean \nsatisfiability problem that there are 2^n\npossible combinations of Boolean values for\nn Boolean variables. \n\nYour task here is to give an English \nlanguage (quasi-formal) proof of this fact\n*by induction*.\n\nTo get started, let's make the property of\nnatural numbers that is at issue clear by\ndefining \"P n\" to be proposition that \"the\nnumber of possible combinations of values\nfor *n* Boolean variables is *2^n*.\"\n\nWhat you are to prove is the proposition\nthat this is true for any value of n. That\nis, you are to prove ∀ n, P n.\n\nNext, recall that a proof of a universal\ngeneralization (such as ∀ n, P n) *by induction*\nis based on the application of the *induction\nprinciple* for for the given data type. Here \nthe data type is ℕ, and the induction rule for\nℕ is as follows:\n\n∀ {P : ℕ → Prop}, \nP 0 → \n(∀ n', P n' → P (n' + 1)) → \n∀ n, P n.\n\n** You should assume that the number of\n** combinations of zero boolean variables\n** is 1.\n\nReading backwards, this says that if you\nwant to prove ∀ n, P n, it will *suffice*\nto prove P 0 and ∀ n', P n' → P (n' + 1)).\nThe reason is that you can then apply the\nrule to deduce that ∀ n, P n must be true.\nIn other words, you can reduce the task of\nproving ∀ n, P n to the tasks of proving\nthe two antecedents of this conclusion in\nthe induction rule.\n\nThis induction principles tells you exactly\nwhat needs to be done. We give you the start\nof a quasi-formal proof. You must complete it.\n-/\n\n-- Answer\n/-\nTheorem: For any natural number, n, the\nnumber of combinations of values for n\nBoolean variables is 2^n.\n\nProof: By induction. To prove ∀ n, P n,\nwhere P is defined to be the proposition,\n\"the number of possible combinations of\nvalues for n Boolean variables is 2^n,\"\nit will suffice ... <the rest of your\nanswer here>. \n-/\n\n/- **** ANSWER ****\nIt will suffice to show that \"∀ n, P n\" is true for \nall natural numbers.\n\nAssume that n is an arbitrary but specific natural number.\n\n1. It will sufffice to show that it is true for the base case\n    n = 0 or 0 (P 0 →)\n2. And to show that it is true for n+1 ((∀ n, P n → P (n + 1)) → ),\n    assuming it is true for n.\n\nFor any natural number n, if the number of combinations\nof n boolean variables is 2^n, then the number of combinations\nof n+1 boolean variables is 2^(n+1).\nAnd thus holds true for all natural numbers.\n\nPROOF:\nGiven\n-- Number of combinations of 0 boolean variables is 1\nAnd assumming\n-- P n = 2^n\n\n-- 2^n = 2^(n-1) * 2 [by property of exponents]\nTherefore,\n-- 2^(n+1) = 2^n * 2\n-- P (n+1) = (P n) * 2\n-- P (n+1) = 2^n * 2 \nand since\n-- 2^n * 2 = 2^(n+1), \nthe number of combinations of n+1 boolean variables is 2^(n+1)\n\nThus\nP (n+1) = 2^(n+1)\nQED\n-/\n\n/- 2.\nConsider the following proposition.\n-/\n\ndef aProp :=    ∀ (α : Type), ∀ (Heavy Charmed: α → Prop),\n                (∃ (a : α), Heavy a ∧ Charmed a) →\n                (∃ (a : α), Charmed a)\n\n/- 2a. Give an English language rendition \nof this proposition. In plain English, what\ndoes it say?\n-/\n\n/-  **** Answer ****\nSuppose we have an object of type α;\nSuppose \"heavy\" and \"charmed\" are objects/ properties\nof type alpha\nIf there exists an object \"a\" of this type\nand \"a\" is both heavy and charmed,\nTHEN there exists an object that is charmed \n-/\n\n/- 2b. Give a formal proof of it.\n-/\n\nexample : aProp := \n    λ a,\n        λ H C, -- Heavy, Charmed\n            λ heavy_and_charmed,\n                match heavy_and_charmed with\n                    | exists.intro fred pf_fred_charmed :=\n                        match pf_fred_charmed with\n                            | and.intro c h := (exists.intro fred pf_fred_charmed.right)\n                        end\n                end\n\n/- 2c. Give a quasi-formal, English-language\nproof of it. Try to be guided by your formal\nproof. Justify each step in your proof by\nnaming the inference rule that you're using.\n-/\n\n-- Your answer here\n/- **** Answer ****\nAssume we have an object a of type alpha \nAssume that the object a of type alpha has properties\nheavy and charmed. \nAssumming there exists an object a that is both heavy\nand charmed.\nDeconstruct this assumption to prove that there \nexists an object fred which is heavy and charmed\nby doing case analysis.\nAnd further deconstruct the assumption of a heavy\nand charmed object, fred, to get a proof that \nthere exists an object that is charmed.\n-/\n\n\n/- 3. \nConsider the following proposition.\n-/\n\ndef aProp2 :=   ∀ (α : Type), ∀ (Heavy Charmed: α → Prop),\n                (∃ (a : α), Heavy a ∨ Charmed a) →\n                (∃ (a : α), Heavy a) ∨ (∃ (a : α), Charmed a)\n\n\n\n/- 3a. Give an English language rendition \nof this proposition. In plain English, what\ndoes it say?\n-/\n\n/- **** Answer ****\nSuppose we have an object of type α;\nSuppose \"heavy\" and \"charmed\" are objects/ properties\nof type alpha\nIf there exists an object \"a\" of this type\nsuch that \"a\" is heavy or charmed,\nTHEN there either exists an object that is heavy OR\nthere exists an object that is charmed \n-/\n\n/- 3b. Give a formal proof of it.\n-/\n\nexample : aProp2 :=\n    λ a, \n        λ H C, -- Heavy, Charmed\n            λ heavy_or_charmed,\n                match heavy_or_charmed with\n                    | exists.intro fred pf_fred_either_heavy_or_charmed :=\n                        match pf_fred_either_heavy_or_charmed with\n                            | or.inl h := or.inl (exists.intro fred h)\n                            | or.inr c := or.inr (exists.intro fred c)\n                        end\n                end\n\n/- 3c. Give a quasi-formal, English-language\nproof of it. Try to be guided by your formal\nproof. Justify each step in your proof by\nnaming the inference rule that you're using.\n-/\n\n-- Your answer here\n/- **** Answer ****\nAssume we have an object a of type alpha \nAssume that the object a of type alpha has properties\nheavy and charmed. \nAssumming there exists an object a that is either heavy\nor an object a that is charmed.\nDeconstruct this assumption to prove that there \nexists an object fred which is heavy or there exists\nan object fred that is charmed by doing case analysis.\n\nAnd further deconstruct the assumption of a heavy\nor charmed object, fred, to get a proof that \nthere exists an object that is heavy or there exists\nan object that is charmed.\n-/\n\n/- 4.\nFormally specify the syntax and semantics\nof a language of *arithmetic* expressions that\ncan include variables, where the meaning of\nan expression is (reduces to) a natural number.\n\nHint: model your answer on our specification\nof the syntax and semantics of *propositional\nlogic* expressions.\n-/\n\n/- In this language, an interpretation will\nmap variables to natural numbers rather than\nto Boolean values. We'll give you a start on\na solution by defining \n\n(1) a type of variables that are distinguished \n    from one another by a ℕ-valued index, \n\n(2) specifying the type of an interpretation, and \n\n(3) giving an example of an interpretation \n    in which all variables have the value zero.\n-/\n\n-- our variable type\nstructure a_var : Type := mk :: (index : ℕ)\n\n\n-- friendly names for a few variables\ndef X_var := a_var.mk 0\ndef Y_var := a_var.mk 1\ndef Z_var := a_var.mk 2\n\n-- the type of an interpretation\ndef interp := a_var → ℕ \n\n-- one possible interpretation, \"all zero\"\ndef all_zero_interp : interp := \n    λ v, 0\n\n/-\n4a. Define an interpretation in which X has\nvalue 3, Y has value 7, and Z has value 1,\nand all other variables have value 0.\n-/\n\ndef an_interp : interp :=\n    λ (v : a_var),\n        match v with\n            | a_var.mk 0 := 3 -- X\n            | a_var.mk 1 := 7 -- Y\n            | a_var.mk 2 := 1 -- Z\n            | _ := 0\n        end\n\n/-\n4b. Define the syntax of your language to have\nthe following kinds of expressions. \n\n- ℕ literal expression\n- ℕ variable expression\n- expression + expression\n- expression * expression\n\nDo this by defining an inductive type, aexp, \nthe values of which are arithmetic expressions\nin our language. Call your constructors lit, \nvar, add, and mul. When you succeed, the test\nexpressions we give you should type check.\n-/\n\ninductive aexp : Type\n-- fill in constructors here\n| lit : ℕ → aexp\n| var : a_var → aexp\n| add : aexp → aexp → aexp\n| mul : aexp → aexp → aexp\nopen aexp\n\n-- These expressions should type-check\ndef X := aexp.var X_var\ndef Y := aexp.var Y_var\ndef Z := aexp.var Z_var\ndef l6 := aexp.lit 6\ndef e1 := aexp.add X Y\ndef e2 := aexp.mul X Z\ndef e3 := aexp.mul e1 l6\n\n/-\n4c. Define a semantics for your\nlanguage so that expressions evaluate\nto natural numbers as they would using\nthe standard notions of addition and\nmultiplication. Furthermore, literal\nexpressions should evaluate to their\nnatural numbers arguments, and variable\nexpressions should evaluate the natural\nnumbers according to an interpretation\ngiven to the evaluation function (call\nit aEval). Remember to put constructor\nexpressions in parentheses when using\npattern matching / destructuring. When\nyou've succeeded, the test cases we've\nprovided should all pass.\n-/\n\n-- Your answer here\ndef aEval : aexp → interp → ℕ \n-- fill in cases here\n| (lit v) i := v\n| (var v) i := i v\n| (add e1 e2) i := (aEval e1 i) + (aEval e2 i)  \n| (mul e1 e2) i := (aEval e1 i) * (aEval e2 i)\n\n-- Test cases that should pass when you've succeeded\nexample : aEval X an_interp = 3 := rfl\nexample : aEval Y an_interp = 7 := rfl\nexample : aEval Z an_interp = 1 := rfl\nexample : aEval l6 all_zero_interp = 6 := rfl\nexample : aEval e1 all_zero_interp = 0  := rfl\nexample : aEval e2 an_interp = 3 := rfl\nexample : aEval e3 an_interp = 60 := rfl\n\n\n/-\n5. Explain concisely but also precisely how a\nproof of a proposition, P, \"by contradiction\"\nwould be carried out. Be sure to point out\nexactly where negation elimination is involved.\n\nThen explain concisely and precisely how a\nproof of a proposition, ¬ P, would be carried\nout. \n-/\n\n/- **** Answer ****\nTo prove proposition P \"by contradiction\",\nAssume P is false which also assumes that ¬P\nis assumed to be true.\nProve that the results of these assumptions \ncontradict each other because it violates the \nlaw of the excluded middle: either P is true OR\n¬P is true. Once the proof is reduced to ¬ (¬ P),\nnegation elimination can be used to deduce that P\nis true.\n\nTo prove ¬ P, assume P is true and show that \nthis leads to a contradiction, then from that \nderive a proof of P being false, \nand use false.elim to finish the proof. \nThis is called a \"proof by negation\". \nThis shows ¬ (¬ P) is false. \nAnd then, according to the the classical principle of \nnegation elimination, ¬P can be deduced true.\n-/\n\n/- 6. A simplish proof. Give a formal proof\nof the following proposition. Then explain\nbriefly in English why the proposition must\nbe true no matter what propositions P and Q\nare.\n-/\n\nexample : ∀ (P Q R : Prop), ¬ ((P ∧ ¬ Q) ∧ (Q ∧ ¬ R)) :=\n    λ P Q R,\n        (λ wholeprop,\n           (let pandnq := wholeprop.left in\n            let qandnr := wholeprop.right in\n            let nq := pandnq.right in\n            let q := qandnr.left in\n            false.elim (nq q)\n            )\n        )\n           \n-- Your explanation\n/- **** Answer ****\nA proof of a negation is a proof that some proposition\nimplies false, in this case\n¬ ((P ∧ ¬ Q) ∧ (Q ∧ ¬ R)) where ((P ∧ ¬ Q) ∧ (Q ∧ ¬ R))\nmust be proven false.\nIf X = ((P ∧ ¬ Q) ∧ (Q ∧ ¬ R)),\nIn order to prove a proposition ¬X, we have to prove\nX implies false. So assume X can lead to a contradiction.\n\nIsolating Q and ¬Q in this proof X, the two contradict\neach other and both Q and ¬Q cannot be true because of\nthe law of the excluded middle. Q and ¬Q are isolated\nusing let...in statements to retrieve the separated\nQ and ¬Q in the proof.\nThus, Q ∧ ¬Q will always be false \nno matter what P and R are. \nAnd by appyling false.elim, the proof of a \nnegation Q and ¬Q evaluates to false,\nand the entire proof is deduced to be true.\n-/\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/final_exam/final_exam.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.916109614162018, "lm_q1q2_score": 0.792640100453341}}
{"text": "import topology.basic\nimport topology.bases\nopen topological_space\nopen set filter classical\nvariables {X : Type} [topological_space X] {A E F U V : set X} {B C : set(set X)}\n\n\n-- some terms from the lectures\ndef cond_pt (A : set X) (x : X) := ∀ (N ∈ nhds x), (N ∩ A).nonempty\ndef cond_points (A : set X) := { x : X | cond_pt A x}\ndef limit_pt (A : set X) (x : X) := cond_pt (A ∩ {x}ᶜ) x\ndef limit_points (A : set X) := { x : X | limit_pt A x}\n\n\ndef lecture_closure (A : set X) := A ∪ limit_points A\ndef lecture_interior (A : set X) := {x : X | ∃ (N ∈ nhds x) (H: is_open N), N ⊆ A}\n\n\n-- Bullet point 1\nlemma subset_closed_subset_lecture_closure\n  (A F : set X) (hAF : A ⊆ F) (hF : is_closed F) :\n  lecture_closure A ⊆ F:=\nbegin\n  intros x hA,\n  cases hA,\n  {exact hAF hA},\n  {\n    -- Re-using the complement neiborhood arguement used in proving lecture_closure_to_lean_closure\n\n    -- since A is subset of F,\n    have obvious_fact : A ∩ Fᶜ= ∅ := diff_eq_empty.mpr hAF,\n\n    have more_specifically : Fᶜ ∩ (A ∩ {x}ᶜ) = ∅ ,\n    -- since this is definately smaller than A ∩ Fᶜ\n      rw set.inter_comm,\n      apply diff_eq_empty.mpr,\n      exact subset.trans (by finish) hAF,\n\n    -- if x not in F, Fᶜ is an open neiborhood of x.\n    -- Since x is a limit point of A,\n    -- Fᶜ must contain an element of A but A ⊆ F. Contradiction.\n    by_contradiction,\n\n    have : Fᶜ ∈ nhds x := is_open.mem_nhds hF.is_open_compl h,\n    cases hA Fᶜ this with N bad,\n    finish,\n  },\nend\n\n-- Bullet point 2\nlemma open_subset_subset_interior \n  (U A : set X) (Uopen : is_open U) (UsubA : U ⊆ A) : U ⊆ lecture_interior A :=\nbegin\n  intros x xinU,\n  use U,\n  apply and.intro,\n  exact is_open.mem_nhds Uopen xinU,\n  exact exists.intro Uopen UsubA,\nend\n\n-- Basis question\n-- Exercise 2.1.6 part 2\n-- Interestingly basis in Lean is defined 'using' B1 and B2 (and one other)\nexample (B : set(set X)) : is_topological_basis B → B.sUnion = set.univ ∧\n  ∀ B1 B2 ∈ B, ∀ x ∈ B1 ∩ B2, (∃ B3 ∈ B, x ∈ B3 ∧ B3 ⊆ B1 ∩ B2):=\nbegin\n  intros basis,\n  split,\n  exact basis.sUnion_eq,\n  exact basis.exists_subset_inter,\nend\n\n-- Well, that was boring\n\nstructure is_lecture_basis (B : set(set X)) : Prop :=\n  (open_sets : ∀ Bi ∈ B, is_open Bi)\n  (construcable : ∀ (s : set X), is_open s → ∃ C ⊆ B, s = C.sUnion)\n\n-- The real deal\nexample (B : set(set X)) : is_lecture_basis B → B.sUnion = set.univ ∧\n  ∀ B1 B2 ∈ B, ∀ x ∈ B1 ∩ B2, (∃ B3 ∈ B, x ∈ B3 ∧ B3 ⊆ B1 ∩ B2):=\nbegin\n  intros basis,\n  split,\n  {\n    have Xisopen : is_open set.univ,      finish,\n    have henceConstrucable :=             basis.construcable set.univ Xisopen,\n    rcases henceConstrucable with ⟨ C, CinB, CconstX ⟩,\n\n    -- univ = ⋃₀C ⊆ ⋃₀B ⊆ univ → ⋃₀B = univ\n    have UCinUB : ⋃₀C ⊆ ⋃₀B :=          sUnion_mono CinB,\n    have : ⋃₀B ⊆ set.univ :=            (⋃₀ B).subset_univ,\n    rw ← CconstX at UCinUB,\n    exact set.subset.antisymm this UCinUB,\n  },\n  {\n    intros B1 hB1 B2 hB2 x hx,\n    have Biopen := basis.open_sets,\n    have B1open : is_open B1 :=           Biopen B1 hB1,\n    have B2open : is_open B2 :=           Biopen B2 hB2,\n    have inter_open :=                    is_open.inter B1open B2open,\n    have henceConstrucable :=             basis.construcable (B1 ∩ B2) inter_open,\n    rcases henceConstrucable with ⟨ C, CinB, CconstInter ⟩,\n    rw CconstInter at hx,\n    have Done : ∃ C1 ∈ C, x ∈ C1 :=          mem_sUnion.mp hx,\n\n    rcases Done with ⟨ C1, C1inC, xinC1 ⟩,\n    use C1,\n    split,\n    exact CinB C1inC,\n    split,\n    exact xinC1,\n    rw CconstInter,\n    exact subset_sUnion_of_mem C1inC,\n  },\nend\n\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/Top bases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.79263043481634}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a y b números reales. Demostrar que\n--    min a b = min b a\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : ℝ\n\n-- 1ª demostración\n-- ===============\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  { show min a b ≤ min b a,\n    apply le_min,\n    { apply min_le_right },\n    { apply min_le_left }},\n  { show min b a ≤ min a b,\n    apply le_min,\n    { apply min_le_right },\n    { apply min_le_left }},\nend\n\n-- Nota: Se usa \"show\" para indicar lo que se demuestra en cada bloque.\n\n-- El desarrollo de la prueba es\n--\n--    ⊢ min a b = min b a\n-- apply le_antisymm,\n-- |    ⊢ min a b ≤ min b a\n-- | apply le_min,\n-- | |    ⊢ min a b ≤ b\n-- | | { apply min_le_right },\n-- | |    ⊢ min a b ≤ a\n-- | apply min_le_left,\n-- |    ⊢ min b a ≤ min a b\n-- | apply le_min,\n-- | |    ⊢ min b a ≤ a\n-- | { apply min_le_right },\n-- | |    ⊢ min b a ≤ b\n-- | apply min_le_left }\n--    no goals\n\n-- 2ª demostración (con lema local)\n-- ================================\n\nexample : min a b = min b a :=\nbegin\n  have h : ∀ x y : ℝ, min x y ≤ min y x,\n  { intros x y,\n    apply le_min,\n    { apply min_le_right },\n    { apply min_le_left }},\n  apply le_antisymm,\n  apply h,\n  apply h,\nend\n\n-- Nota: La táctica \"intros\" introduce las variables en el contexto. Ver\n-- https://bit.ly/2UF1EdL\n\n-- 3ª demostración\n-- ===============\n\nexample : min a b = min b a :=\nbegin\n  have h : ∀ {x y : ℝ}, min x y ≤ min y x,\n  { intros x y,\n    exact le_min (min_le_right x y) (min_le_left x y) },\n  exact le_antisymm h h,\nend\n\n-- 4ª demostración (con repeat)\n-- ============================\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left },\nend\n\n-- Nota. La táctica \"repeat\" aplica una táctica recursivamente a todos los\n-- subobjetivos. Ver https://bit.ly/2YuO5P9\n\n-- Lemas usados\n-- ============\n\n-- #check (le_antisymm : a ≤ b → b ≤ a → a = b)\n-- #check (le_min : c ≤ a → c ≤ b → c ≤ min a b)\n-- #check (min_le_left a b : min a b ≤ a)\n-- #check (min_le_right a b : min 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/Conmutatividad_del_minimo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.9032942047513692, "lm_q1q2_score": 0.7926196969361956}}
{"text": "import Mathlib.Algebra.BigOperators.Basic\n\n/-!\n# IMO 2018 Q3\n\nAn anti-Pascal triangle is an equilateral triangular array of numbers such that,\nexcept for the numbers in the bottom row, each number is the absolute value\nof the difference of the two numbers immediately below it. For example,\nthe following array is an anti-Pascal triangle with four rows\nwhich contains every integer from 1 to 10:\n\n                  4\n                2   6\n              5   7   1\n            8   3  10   9\n\nDoes there exist an anti-Pascal triangle with 2018 rows which contains every\ninteger from 1 to 1 + 2 + ... + 2018?\n\n# Solution\nNo.\n\n-/\n\nopen BigOperators\n\nstructure Coords where\n(row : Nat) (col : Nat)\n\ndef left_child (c : Coords) : Coords :=\n ⟨c.row.succ, c.col⟩\n\ndef right_child (c : Coords) : Coords :=\n  ⟨c.row.succ, c.col.succ⟩\n\n/--\nantipascal triangle with n rows\n-/\nstructure antipascal_triangle (n : Nat) where\n(f : Coords → Nat)\n(antipascal : ∀ x: Coords, x.row.succ < n ∧ x.col ≤ x.row →\n  f x + f (left_child x) = f (right_child x) ∨\n  f x + f (right_child x) = f (left_child x))\n\nstructure a_and_b where\n(a : Coords) (b : Coords)\n\ntheorem imo2018_q3 (t : antipascal_triangle 2018)\n    (h_contains_all : ∀ n, n ≤ ∑ i in Finset.range 2018, (i + 1) →\n                      ∃ r, r ≤ 2018 ∧ ∃ c, c < r ∧ t.f ⟨r,c⟩ = n) :\n    False := by sorry\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/Imo2018Q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533126145179, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7925584348250689}}
{"text": "import analysis.real tactic.norm_num\nlocal infix ` ^ ` := monoid.pow\n\n\ntheorem Q1 : 1=1 := sorry\ntheorem Q2 : 1=1 := sorry\n\nlemma avg_lt_max {mn mx: ℝ} (H : mn < mx) : (mn+mx) / 2 < mx :=\nbegin\n  apply (mul_lt_mul_right (show (0:ℝ)<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: ℝ} (H : mn < mx) : mn < (mn+mx) / 2 :=\nbegin\n  apply (mul_lt_mul_right (show (0:ℝ)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_ne_zero)],\n  simp [H,mul_two],\nend\n\nlemma lub_open (y : ℝ) : is_lub {x : ℝ | 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 ∈ {x : ℝ | 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 ℝ := {x : ℝ | x<0}\n\ntheorem Q3a : is_lub (S3a) 0 := lub_open 0\n\ndef S3b : set ℝ := {x : ℝ | ∃ y : ℚ, x = ↑y}\n\ntheorem Q3b : ∀ b : ℝ, ¬ (is_lub (S3b) b) :=\nbegin\nintros b Hlub,\nhave Hbub : b ∈ upper_bounds S3b := Hlub.left,\nhave H : b < (b+1) := calc b = b+0 : (add_zero _).symm\n                         ... < b+1 : add_lt_add_left zero_lt_one _,\n--have H2 := exists_rat_btwn H,\n--cases H2 with q Hq,\ncases (exists_rat_btwn H) with q Hq,\nhave Hwrong := Hbub ↑q,\nhave Hqin : ↑q ∈ S3b := ⟨q,rfl⟩,\nexact not_lt.2 (Hwrong Hqin) (Hq.left),\nend\n\nlemma pow_two_eq_mul_self {x : ℝ} : x^2=x*x :=\nbegin\nunfold monoid.pow,simp,\nend\n\ndef S3c : set ℝ := {x : ℝ | (x+1)^2 < x^2} -- x<-0.5\n\ntheorem Q3c : is_lub (S3c) (-1/2) :=\nbegin\nhave : S3c = {x : ℝ | x < -1/2},\n{ apply set.ext,\n  intro x,\n  show (x+1)^2 < x^2 ↔ x < -1/2,\n  rw [←add_zero (x^2),pow_two_eq_mul_self,mul_add,add_mul,add_mul,pow_two_eq_mul_self,mul_one,one_mul],\n  rw [add_assoc],\n  -- ask Mario why I can't do this -- I only want\n  -- to change one thing\n  exact calc\n    x * x + (x + (x + 1 * 1)) < x * x + 0 ↔ (x + (x + 1 * 1)) < 0 : add_lt_add_iff_left (x*x)\n    ... ↔ x * 2 + 1 < 0 : by rw [mul_one,←add_assoc,←mul_two]\n    ... ↔ x * 2 < -1 : by rw[←lt_sub_right_iff_add_lt,zero_sub]\n    ... ↔ x < (-1) / 2 : (lt_div_iff (show (0:ℝ) < 2, by norm_num)).symm },\nrw this,\nexact lub_open ((-1)/2),\nend\n\ndef S3d : set ℝ := {x : ℝ | (∃ q : ℚ, x=↑q) ∧ 1 < x ∧ x < 2}\n\ntheorem Q3d : is_lub S3d 2 :=\nbegin\nsplit,\n{ intros z Hz,\n  exact le_of_lt Hz.right.right },\nintros y Hy,\nrefine le_of_not_gt _,\nintro Hylt2,\nhave onelt2 : (1:ℝ) < 2 := by norm_num,\nhave := max_lt onelt2 Hylt2,\ncases (exists_rat_btwn this) with q Hq,\nhave := Hy ↑q,\nhave Hq_in : ↑q ∈ S3d,\n{ split,\n  { existsi q,refl},\n  split,\n  { exact lt_of_le_of_lt (le_max_left _ _) Hq.left },\n  exact Hq.right,\n},\nhave this2 := this Hq_in,\n\nunfold upper_bounds at Hy,\napply (not_lt.2 this2),\nexact lt_of_le_of_lt (le_max_right 1 y) Hq.left,\nend\n\ntheorem Q4 (S : set ℝ) (x : ℝ) (H1 : x ∈ upper_bounds S) (H2 : x ∈ S) : is_lub S x :=\nbegin\nsplit,exact H1,\nintro y,\nintro H,\nhave := H x,\nexact this H2,\nend\n\ntheorem Q5a1 (S : set ℝ) : (∃ x : ℝ, x ∈ lower_bounds S) \n    ↔ (∃ y : ℝ, y ∈ upper_bounds {t : ℝ | ∃ s ∈ S, t = -s }) :=\nbegin\nsplit,\n{ intros H,\n  cases H with x Hx,\n  existsi (-x),\n  intro w,\n  have Hmw := Hx (-w),\n  intro Hw,\n  cases Hw with t Ht,\n  cases Ht with u Hu,\n  refine le_neg_of_le_neg _,\n  apply Hmw _,\n  rw [Hu],\n  rwa neg_neg },\n{ intros H,\n  cases H with y Hy,\n  existsi (-y),\n  intro mt,\n  have Ht := Hy (-mt),\n  intro Hmt,\n  refine neg_le_of_neg_le _,\n  apply Ht _,\n  existsi mt,\n  existsi Hmt,\n  refl\n}\nend \n\ntheorem Q5a2 (S : set ℝ) (x : ℝ) : is_glb S x ↔ \n    is_lub {t : ℝ | ∃ s ∈ S, t = -s} (-x) :=\nbegin\nsplit,\n{ intro HSx,\n  split,\n  { intros ms Hms,\n    refine le_neg_of_le_neg _,\n    refine HSx.left _ _,\n    cases Hms with s Hs,\n    cases Hs with H1 H2,\n    rw H2,\n    rwa neg_neg },\n  { intros b Hb,\n    apply neg_le_of_neg_le _,\n    apply HSx.2 (-b),\n    intros c Hc,\n    apply neg_le_of_neg_le _,\n    apply Hb (-c),\n    existsi c,\n    existsi Hc,\n    refl },\n},\n{ intro HSx,\n  split,\n  { intros ms Hms,\n    refine le_of_neg_le_neg _,\n    refine HSx.left _ _,\n    existsi [ms,Hms],\n    refl },\n  { intros b Hb,\n    apply le_of_neg_le_neg _,\n    apply HSx.2 (-b),\n    intros c Hc,\n    cases Hc with mc Hmc,\n    cases Hmc with H1 H2,\n    apply le_neg_of_le_neg _,\n    apply Hb (-c),\n    rw H2,\n    rwa neg_neg },\n},\nend\n\nlemma Q5bhelper (S : set ℝ) (x₁ x₂ : ℝ) : is_glb S x₁ ∧ is_glb S x₂ → x₁ ≤ x₂ :=\nbegin\nintro H,\nhave Hglb1 := H.left,\nhave Hlb1 := Hglb1.left,\nhave Hglb2 := H.right,\nhave H1 := Hglb2.right,\nexact H1 _ Hlb1,\nend\n\ntheorem Q5b (S : set ℝ) (x₁ x₂ : ℝ) : is_glb S x₁ ∧ is_glb S x₂ → x₁ = x₂ :=\nbegin\nintro H,\nhave H1 := Q5bhelper _ _ _ H,\nhave H2 := Q5bhelper _ _ _ ⟨H.right,H.left⟩,\n--exact eq_iff_le_and_le. 2 ⟨H1,H2⟩,\n-- TODO : did this used to work? What do I do now??\nexact le_antisymm H1 H2,\nend\n\ntheorem Q5c :  (∀ S : set ℝ, (∃ w : ℝ, w ∈ S) → (∃ x : ℝ, x ∈ upper_bounds S) → ∃ y : ℝ, is_lub S y) \n   →   (∀ T : set ℝ, (∃ w₁ : ℝ, w₁ ∈ T) → (∃ x₁ : ℝ, x₁ ∈ lower_bounds T) → ∃ y₁ : ℝ, is_glb T y₁) :=\nbegin\nintro H,\nintro T,\nhave H1 := H {x : ℝ | ∃ y : ℝ, y ∈ T ∧ x = -y},\nclear H,\nintro J2,\ncases J2 with w2 Jw2,\nhave H2 := H1 _,\n{ intro J3,\n  clear H1,\n  cases J3 with w3 Jw3,\n  have H3 := H2 _,\n  { clear H2,\n    cases H3 with y3 Hy3,\n    existsi (-y3),\n    split,\n    { intro t,\n      have H4 := Hy3.left (-t),\n      intro J5,\n      rw neg_le,\n      apply H4,\n      clear H4,\n      existsi t,\n      simp [J5]\n    },\n    intros t Ht,\n    have H4 := Hy3.right (-t),\n    rw le_neg,\n    apply H4,\n    clear H4,\n    intros u Hu,\n    cases Hu with v Hv,\n    rw [Hv.right],\n    refine neg_le_neg _,\n    apply Ht,\n    exact Hv.left,\n  },\n  existsi (-w3),\n  intros z Hz,\n  rw le_neg,\n  apply Jw3,\n  cases Hz with u Hu,\n  rw Hu.right,\n  rw neg_neg,\n  exact Hu.left\n},\nexistsi (-w2),\nexistsi w2,\nsimp [Jw2],\nend \n\ndef S (a : {n : ℕ // n ≥ 1} → ℝ) \n  (n : ℕ) (H : n ≥ 1) := { r: ℝ | ∃ (m : ℕ) (Hm : m ≥ n), r = a ⟨m,ge_trans Hm H⟩ }\n\n/- HORRIBLE ERROR \ntheorem Q6a1 (a : {n : ℕ // n ≥ 1} → ℝ) \n  (HB : ∃ B : ℝ, ∀ n : ℕ, ∀ H : n ≥ 1, a ⟨n,H⟩ ≤ B) : ∀ (n : ℕ) (H : n ≥ 1), \n  (∃ r : ℝ, r ∈ S a HB n H) ∧ (∃ B : ℝ, ∀ x : ℝ, x ∈ S a HB n H → x ≤ B) :=\nbegin\nintros n Hn,\nsplit,\n{ existsi a ⟨n Hn⟩,\n\n}\nend\n-/\n\n--set_option trace.class_instances true\n\ntheorem Q6a1 (a : {n : ℕ // n ≥ 1} → ℝ) \n  (HB : ∃ B : ℝ, ∀ n : ℕ, ∀ H : n ≥ 1, a ⟨n,H⟩ ≤ B) : ∀ (n : ℕ) (H : n ≥ 1), \n  (∃ r : ℝ, r ∈ S a n H) ∧ (∃ B : ℝ, ∀ x : ℝ, x ∈ S a n H → x ≤ B) :=\nbegin\nintros n Hn,\nsplit,\n{ existsi a ⟨n,Hn⟩,\n  existsi n,\n  existsi (le_of_eq (refl n)),\n  refl },\ncases HB with B H,\nexistsi B,\nintro x,\nintro Hx,\ncases Hx with m Hm,\ncases Hm with H1 Hx,\nrw Hx,\nrefine H _ _,\nend\n\ntheorem Q6a2 (a : {n : ℕ // n ≥ 1} → ℝ) \n  (HB : ∃ B : ℝ, ∀ n : ℕ, ∀ H : n ≥ 1, a ⟨n,H⟩ ≤ B) (n : ℕ) (H : n ≥ 1) : \n  ∃ x : ℝ, is_lub (S a n H) x :=\nbegin\nhave H1 := Q6a1 a HB n H,\ncases H1.left with y Hy,\ncases H1.right with B H2,\nrefine exists_supremum_real Hy H2\nend \n\ntheorem Q6b1 (a : {n : ℕ // n ≥ 1} → ℝ) \n  (HB : ∃ B : ℝ, ∀ n : ℕ, ∀ H : n ≥ 1, a ⟨n,H⟩ ≤ B) (n : ℕ) (H : n ≥ 1) :\n  ∀ bnp1 bn : ℝ, is_lub (S a n H) bn ∧ is_lub (S a (n+1) (le_trans H (nat.le_succ _))) bnp1\n  → bnp1 ≤ bn :=\nbegin\nintrov H1,\nsuffices : bn ∈ upper_bounds (S a (n+1) (le_trans H (nat.le_succ _))),\nrefine (H1.right).right bn this,\nintros x Hx,\nsuffices : x ∈ (S a n H),\nexact H1.left.left x this,\ncases Hx with m Hm,\ncases Hm with H2 H3,\nexistsi m,\nexistsi (le_trans (nat.le_succ _) H2),\nassumption\nend \n\ndef limsup (a : {n : ℕ // n ≥ 1} → ℝ) (lsup : ℝ) : Prop :=\n  ∃ b : { n : ℕ // n ≥ 1} → ℝ, is_glb { x : ℝ | ∃ (n : ℕ) (H : n ≥ 1), x = b ⟨n,H⟩} lsup \n  ∧ ∀ (n : ℕ) (H : n ≥ 1), is_lub (S a n H) (b ⟨n,H⟩) \n\ndef a1 : {n : ℕ // n ≥ 1} → ℝ := λ _, 1\ntheorem Q6c1 : limsup a1 1 :=\nbegin\nexistsi (λ _,(1:ℝ)),\nsplit,\n{ split,\n  { intros y Hy,\n    cases Hy with n Hn,\n    cases Hn with H1 H2,\n    rw H2,\n    show (1:ℝ) ≤ 1,\n    norm_num\n  },\n  intros y Hy,\n  have H1 := Hy 1,\n  refine H1 _,\n  existsi 1,\n  existsi (show 1 ≤ 1, by norm_num),\n  simp\n\n},\nintros n Hn,\nshow is_lub (S a1 n Hn) 1,\nsplit,\n{ intros x Hx,\n  cases Hx with m Hm,\n  cases Hm with H1 H2,\n  rw H2,\n  show (1:ℝ)≤1,\n  norm_num\n},\n{ intros x Hx,\n  have H1 := Hx 1,\n  apply H1,\n  clear H1, -- ask Mario how to do apply then clear\n  existsi n,\n  existsi _,\n  {refl},\n  show n≤n,\n  refl,\n\n\n}\nend\n\n--set_option pp.all true\n\nnoncomputable def a2 : {n : ℕ // n ≥ 1} → ℝ := λ N, 1/N.val \ntheorem Q6c2 : limsup a2 0 :=\nbegin\nexistsi a2,\nsplit,\n{ split,\n  { \n  intros x Hx,\n  cases Hx with m Hm,\n  cases Hm with H1 H2,\n  rw H2,\n  show (0:ℝ) ≤ 1/m,\n  refine div_nonneg_of_nonneg_of_pos _ _,\n  {norm_num},\n  refine lt_of_lt_of_le zero_lt_one _,\n  rwa [←nat.cast_one,nat.cast_le] },\n  { intros y Hy,\n    refine not_lt.1 _,\n    intro Hny,\n    cases (exists_lt_nat (1/y)) with m Hm,\n    have H1 := Hy (1/m),\n    rw ←inv_eq_one_div at Hm,\n    have H2 : m ≥ 1,\n    { have H3 : ↑0 < ↑m := lt_trans (inv_pos Hny) Hm,\n      rw [nat.cast_lt] at H3,\n      exact nat.succ_le_of_lt H3 },\n    have H4 : 1 / (↑m:ℝ) ∈ {x : ℝ | ∃ (n : ℕ) (H : n ≥ 1), x = a2 ⟨n, H⟩},\n    { existsi [m,H2],\n      refl },\n    have H5 := H1 H4,\n    have H6 := inv_le_inv _ _ Hny H5,\n    rw [←inv_eq_one_div,inv_inv'] at H6,\n    apply lt_irrefl (m:ℝ),\n    exact lt_of_le_of_lt H6 Hm,\n  }\n},\n{\nintros n H,\nsplit,\n{ intros x Hx,\n  cases Hx with d Hd,\n  cases Hd with Hm H1,\n  rw H1,\n  show 1/(d:ℝ) ≤ 1/n,\n  rw [←inv_eq_one_div,←inv_eq_one_div],\n  refine inv_le_inv _ _ _ _,\n  { rw [←nat.cast_zero,nat.cast_lt], exact lt_of_lt_of_le zero_lt_one H},\n  rwa [nat.cast_le]\n  },\nintros x Hx,\nhave := Hx (1/(n:ℝ)),\napply this,\nexistsi n,\nexistsi _,\nrefl,\nshow n ≤ n,\nrefl\n}\nend\n\n\nnoncomputable def a3 : {n : ℕ // n ≥ 1} → ℝ := λ N, 1 - ((((N.val % (2:ℕ))):ℤ):ℝ)\n--#eval a3 ⟨1,dec_trivial⟩\n\ntheorem Q6c3 : limsup a3 1 :=\nbegin\nexistsi (λ _, (1:ℝ)),\nsplit,\n{ split,\n  { intros x Hx,\n    cases Hx with m Hm,\n    cases Hm with H1 H2,\n    rw H2,\n    simp [le_refl],\n  },\n  intros x Hx,\n  apply Hx,\n  existsi 2,\n  existsi _,\n  refl,\n  exact dec_trivial,\n\n},\nintros n Hn,\nsplit,\n{ intros y Hy,\n  cases Hy with m Hm,\n  show y ≤ 1,\n  cases Hm with H1 H2,\n  rw H2,\n  unfold a3,\n  refine sub_le_self _ _,\n  rw [←int.cast_zero],\n  unfold ge,\n  rw int.cast_le,\n  refine int.mod_nonneg _ _,\n  exact dec_trivial,\n},\nintros x Hx,\nshow 1 ≤ x,\napply Hx,\nexistsi (2*n),\nexistsi _,\n{ unfold a3,\n  simp,\n},\nrw [mul_comm,mul_two],\nexact nat.le_add_left _ _,\nend\n\n/-\nSay we have a sequence of real numbers a 1 , a 2 , a 3 , . . ., which is\n bounded above in the sense\nthat there exists some real number B such that a i ≤ B for all i.\nNow let’s define some sets S 1 , S 2 , S 3 , . . . by\nS n = {a n , a n+1 , a n+2 , . . .}.\nFor example S 3 = {a 3 , a 4 , a 5 , . . .}.\na) Prove that for all n ≥ 1, S n is a non-empty set which is bounded above, and hence has a\nleast upper bound b n .\nb) Prove that b n+1 ≤ b n and hence b 1 , b 2 , b 3 is a decreasing sequence.\nIf the set {b 1 , b 2 , b 3 , . . .} is bounded below, then its greatest lower bound ` is called the limsup\nof the sequence (a 1 , a 2 , a 3 , . . .) (this is an abbreviation for Limit Superior).\nc) Find the limsup of the following sequences (they do exist).\ni) 1, 1, 1, 1, 1, . . .\nii) 1, 2 1 , 13 , 14 , . . .\niii) 0, 1, 0, 1, 0, 1, 0, 1, . . .\nd) If you like, then guess the definition of liminf (Limit Inferior) and compute it for examples\n(i) to (iii) of (c) above. Which of these sequences converges? Can you tell just from looking at\nthe limsup and liminf?-/\n\ndef liminf (a : {n : ℕ // n ≥ 1} → ℝ) (linf : ℝ) : Prop :=\n  ∃ c : { n : ℕ // n ≥ 1} → ℝ, is_lub { x : ℝ | ∃ (n : ℕ) (H : n ≥ 1), x = c ⟨n,H⟩} linf \n  ∧ ∀ (n : ℕ) (H : n ≥ 1), is_glb (S a n H) (c ⟨n,H⟩) \n\ntheorem Q6c1' : liminf a1 1 :=\nbegin\nexistsi (λ _,(1:ℝ)),\nsplit,\n{ split,\n  { intros y Hy,\n    cases Hy with n Hn,\n    cases Hn with H1 H2,\n    rw H2,\n    show (1:ℝ) ≤ 1,\n    exact le_refl _,\n  },\n  intros y Hy,\n  have H1 := Hy 1,\n  refine H1 _,\n  existsi 1,\n  existsi (show 1 ≤ 1, by exact le_refl _),\n  simp\n},\nintros n Hn,\nshow is_glb (S a1 n Hn) 1,\nsplit,\n{ intros x Hx,\n  cases Hx with m Hm,\n  cases Hm with H1 H2,\n  rw H2,\n  show (1:ℝ)≤1,\n  exact le_refl _,\n},\n{ intros x Hx,\n  have H1 := Hx 1,\n  apply H1,\n  clear H1, -- ask Mario how to do apply then clear\n  existsi n,\n  existsi _,\n  {refl},\n  show n≤n,\n  refl,\n}\nend \n\ntheorem Q6c2' : liminf a2 0 :=\nbegin\nexistsi (λ _,(0:ℝ)),\nsplit,\n{ split,\n  { \n  intros x Hx,\n  cases Hx with m Hm,\n  cases Hm with H1 H2,\n  rw H2,\n  exact le_refl _,\n  },\n  intros y Hy,\n  apply Hy,\n  existsi 1,\n  existsi _,refl,\n  show 1 ≤ 1,\n  exact le_refl _\n},\nintros n Hn,\nsplit,\n{ intros x Hx,\n  cases Hx with m Hm,\n  cases Hm with H1 H2,\n  show 0 ≤ x,\n  rw H2,\n  unfold a2,\n  show 0 ≤ 1/(↑m:ℝ),\n  rw [←inv_eq_one_div],\n  apply le_of_lt _,\n  apply inv_pos,\n  rw [←nat.cast_zero,nat.cast_lt],\n  exact calc 0 < 1 : zero_lt_one ... ≤ n : Hn ... ≤ m : H1\n},\nintros x Hx,\nshow x ≤ 0,\n    refine not_lt.1 _,\n    intro Hny,\n    cases (exists_lt_nat (max (1/x) n)) with m Hm,\n    have H1 := Hx (1/m),\n    rw ←inv_eq_one_div at Hm,\n    have H2 : n ≤ m,\n    { suffices : ↑n < (↑m:ℝ),exact le_of_lt (nat.cast_lt.1 this), exact lt_of_le_of_lt (le_max_right _ _) Hm },\n    have H4 : 1 / (↑m:ℝ) ∈ {x : ℝ | ∃ (m : ℕ) (H : m ≥ n), x = a2 ⟨m, (le_trans Hn H)⟩},\n    { existsi [m,H2],\n      refl },\n    have H5 := H1 H4,\n    have H6 := inv_le_inv _ _ Hny H5,\n    rw [←inv_eq_one_div,inv_inv'] at H6,\n    apply lt_irrefl (m:ℝ),\n    refine lt_of_le_of_lt H6 _,\n    refine lt_of_le_of_lt (le_max_left _ _) Hm,\nend\n\n\n--noncomputable def a3 : {n : ℕ // n ≥ 1} → ℝ := λ N, 1 - ((((N.val % (2:ℕ))):ℤ):ℝ)\ntheorem Q6c3' : liminf a3 0 :=\nbegin\nexistsi (λ _,(0:ℝ)),\nsplit,\n{ split,\n  { intros x₁ Hx₁,\n    cases Hx₁ with n₁ Hn₁,\n    cases Hn₁ with H1 H2,\n    rw H2,\n    exact le_refl 0 },\n  intros x₂ Hx₂,\n  apply Hx₂,\n  existsi 1,\n  existsi _,refl,\n  exact le_refl 1 },\nintros n H,\nsplit,\n{ intro x₁,\n  intro H1,\n  show 0 ≤ x₁,\n  cases H1 with n₁ Hn₁,\n  cases Hn₁ with H1 H2,\n  rw H2,\n  unfold a3,\n  rw [sub_nonneg],\n  show ↑((↑n₁:ℤ) % (↑2:ℤ)) ≤ (1:ℝ),\n  have H3 : (1:ℝ) = ↑(1:ℤ), rw [←int.cast_one],\n  rw [H3],\n  rw [int.cast_le],\n  apply int.le_of_lt_add_one,\n  show ↑n₁ % ↑2 < (2:ℤ),\n  refine int.mod_lt_of_pos ↑n₁ _,\n  norm_num },\nintros x₁ Hx₁,\nshow x₁ ≤ 0,\napply Hx₁,\nexistsi (2*n+1),\nexistsi _,\n{ unfold a3,\n  apply eq.symm,\n  apply sub_eq_zero_of_eq,\n  rw ←int.cast_one,\n  rw int.cast_inj,\n  show (1:ℤ) = ↑((2*n+1) % 2),\n  suffices : 1 = 1 % 2,simpa,\n  refl },\nrw [mul_comm,mul_two,add_assoc],\napply nat.le_add_right\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_06/solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7925584321633165}}
{"text": "-- La_suma_de_no_negativos_es_expansiva.lean\n-- La suma de no negativos es expansiva\n-- José A. Alonso Jiménez\n-- Sevilla, 21 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1.. Demostrar si a y b son números reales y a es no\n-- negativo, entonces b ≤ a + b\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nvariables {a b : ℝ}\n\n-- 1ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nbegin\n  calc b = 0 + b : by rw zero_add\n     ... ≤ a + b : by exact add_le_add_right ha b,\nend\n\n-- Comentario: Se ha usado el lema\n-- + zero_add : 0 + a = a  \n\n-- 2ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nbegin\n  calc b = 0 + b : (zero_add b).symm\n     ... ≤ a + b : add_le_add_right ha b,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nbegin\n  calc b = 0 + b : by ring\n     ... ≤ a + b : by exact add_le_add_right ha b,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nby simp [ha]\n\n-- 5ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nby linarith\n\n-- 6ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nby finish\n\n-- 7ª demostración\n-- ===============\n\nexample  \n  (ha : 0 ≤ a) \n  : b ≤ a + b :=\nle_add_of_nonneg_left ha\n\n-- Comentario: Se ha usado el lema\n-- + le_add_of_nonneg_left : 0 ≤ b → a ≤ b + a \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar si a y b son números reales y b es no\n-- negativo, entonces a ≤ a + b\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nbegin\n  calc a = a + 0 : by rw add_zero\n     ... ≤ a + b : by exact add_le_add_left hb a,\nend\n\n-- Comentario: Se ha usado el lema\n-- + add_le_add_left : a ≤ b → ∀ (c : ℝ), c + a ≤ c + b \n\n-- 2ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nbegin\n  calc a = a + 0 : (add_zero a).symm\n     ... ≤ a + b : add_le_add_left hb a,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nbegin\n  calc a = a + 0 : by ring\n     ... ≤ a + b : add_le_add_left hb a,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nby simp [hb]\n\n-- 5ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nby linarith\n\n-- 6ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nby finish\n\n-- 7ª demostración\n-- ===============\n\nexample  \n  (hb : 0 ≤ b) \n  : a ≤ a + b :=\nle_add_of_nonneg_right hb\n\n-- Comentario: Se usa el lema\n-- + le_add_of_nonneg_right : 0 ≤ b → a ≤ a + b \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/La_suma_de_no_negativos_es_expansiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8933094145755219, "lm_q1q2_score": 0.7925482108937375}}
{"text": "import .src_04_theorems\n\nvariables p q r : Prop \n\nnamespace mth1001\n\nsection if_and_only_if\n\n/-\nThe symbol `↔`, written `\\iff` is read 'if and only if'. From `p ↔ q`, one can deduce `p → q` and\n`p → q`. Likewise, from `p → q` and `q → p`, one can deduce `p ↔ q`.\n\nGiven propositions `p` and `q`, if `p ↔ q`, we say that `p` is _equivalent_ to `q`.\n-/\n\n-- Here is a term-style derivation of `p ↔ q` from `h₁ : p → q` and `h₂ : q → p`. \nexample (h₁ : p → q) (h₂ : q → p) : p ↔ q :=\niff.intro h₁ h₂ \n\n/-\nEqually, we can use the `split` tactic to decompose the goal `p ↔ q` into two goals: one\nto prove `p → q` and the other to prove `q → p`.\n-/\nexample (h₁ : p → q) (h₂ : q → p) : p ↔ q :=\nbegin \n  split,\n  { exact h₁, },\n  { exact h₂, },\nend\n\n-- Exercise 033:\n-- We combine the previous results `and_assoc` and `and_assoc2`. \ntheorem and_assoc : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\nbegin \n  split,\n  { sorry}, \n  { sorry, }, \nend \n\n\n/-\nBelow is a tactic mode proof of `p → q` from `h : p ↔ q`. Note how `cases` is used to decompose\nthe premise `h` into two new premises, `hpq : p → q` and `hqp : q → p`.\n-/\nexample (h : p ↔ q) : p → q :=\nbegin \n  cases h with hpq hqp,\n  exact hpq,\nend \n\n-- Exercise 034:\nexample (h : p ↔ q) : q → p :=\nbegin \n  sorry  \nend \n\n/-\nAlternatively, we can give a term-style proof. If `h : p ↔ q`, then `h.mp` is a proof of `p → q`\nand `h.mpr` is a proof of `q → p`. Here `mp` is an abbreviation of 'modus ponens', the Latin name\nfor implication elimination.\n-/\n\nexample (h : p ↔ q) : p → q :=\nh.mp\n\nexample (h : p ↔ q) : q → p :=\nh.mpr\n\n-- Exercise 035:\n-- We prove `p ∧ q ↔ q ∧ p` using the theorem `and_of_and` from the previous section.\ntheorem and_iff_and : p ∧ q ↔ q ∧ p :=\nbegin \n  split, \n  { exact and_of_and p q },\n  { sorry, }, \nend \n\nend if_and_only_if\n\n/-\nSUMMARY:\n\n* Iff introduction.\n* Term-style introduction using `iff.intro`.\n* Tactic-style introduction using `split`.\n\n* Iff elimination.\n* Tactic-style elimination using `cases`.\n* Term-style elimination using `.mp` or `.mpr`.\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_05_if_and_only_if.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8872045817875224, "lm_q1q2_score": 0.7925482005253165}}
{"text": "import data.real.basic\n\nopen_locale classical\n\n/-\nTheoretical negations.\n\nThis file is for people interested in logic who want to fully understand\nnegations.\n\nHere we don't use `contrapose` or `push_neg`. The goal is to prove lemmas\nthat are used by those tactics. Of course we can use\n`exfalso`, `by_contradiction` and `by_cases`.\n\nIf this doesn't sound like fun then skip ahead to the next file.\n-/\n\nsection negation_prop\n\nvariables P Q : Prop\n\n-- 0055\nexample : (P → Q) ↔ (¬ Q → ¬ P) :=\nbegin\n  sorry\nend\n\n-- 0056\nlemma non_imp (P Q : Prop) : ¬ (P → Q) ↔ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\n-- In the next one, let's use the axiom\n-- propext {P Q : Prop} : (P ↔ Q) → P = Q\n\n-- 0057\nexample (P : Prop) : ¬ P ↔ P = false :=\nbegin\n  sorry\nend\n\nend negation_prop\n\nsection negation_quantifiers\nvariables (X : Type) (P : X → Prop)\n\n-- 0058\nexample : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x :=\nbegin\n  sorry\nend\n\n-- 0059\nexample : ¬ (∃ x, P x) ↔ ∀ x, ¬ P x :=\nbegin\n  sorry\nend\n\n-- 0060\nexample (P : ℝ → Prop) : ¬ (∃ ε > 0, P ε) ↔ ∀ ε > 0, ¬ P ε :=\nbegin\n  sorry\nend\n\n-- 0061\nexample (P : ℝ → Prop) : ¬ (∀ x > 0, P x) ↔ ∃ x > 0, ¬ P x :=\nbegin\n  sorry\nend\n\nend negation_quantifiers\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/07bis_abstract_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7923369706813769}}
{"text": "\n/-\nConjunctions, disjunctions, implication, iff,\nnegation\n-/\n\n/-\n1. Prove that 3 + 3 = 6 and 2 + 6 = 8 implies\nthat 1 + 1 = 2.\n-/\n\n-- answer:\nexample : 3 + 3 = 6 ∧ 2 + 6 = 8 → 1 + 1 = 2 :=\nbegin\n     assume ttts,\n\n     exact rfl,\nend\n/-\n2. Prove that 2 + 5 = 3 or 9 + 1 = 5 implies\nthat 2 + 3 = 9.\n-/\n\n-- answer:\nexample : 2 + 5 = 0 ∨ 9 + 1 = 0 → 2 + 3 = 9 :=\nbegin\n     assume tof,\n     cases tof,\n          have contra : 2 + 5 ≠ 0 :=\n          begin\n               apply nat.no_confusion,\n          end,\n          contradiction,\n          have contra : 9 + 1 ≠ 0 :=\n          begin\n               apply nat.no_confusion,\n          end,\n          contradiction,\nend\n/-\n3. Prove that ¬(A ∧ B ∧ C) ↔ (¬A ∨ ¬B ∨ ¬C).\nYou may use the axiom of the excluded middle.\n-/\nopen classical\n--axiom em: ∀(P: Prop), P ∨ ¬P\n\n-- answer:\nexample : ∀ (A B C : Prop), ¬(A ∧ B ∧ C) ↔ (¬A ∨ ¬B ∨ ¬C) :=\nbegin\n     intros A B C,\n     apply iff.intro,\n     /- forward -/\n          assume nabc,\n          cases em A with a na,\n          cases em B with b nb,\n          cases em C with c nc,\n          have f : false := nabc (and.intro a (and.intro b c)),\n          exact false.elim f,\n          exact or.inr (or.inr nc),\n          exact or.inr (or.inl nb),\n          exact or.inl na,\n     /- backward -/\n          assume nanbnc,\n          assume abc,\n          cases nanbnc with na nbnc,\n          have f : false := na abc.1,\n          exact f,\n          cases nbnc with nb nc,\n          have f : false := nb abc.2.1,\n          exact f,\n          have f : false := nc abc.2.2,\n          exact f,\nend\n\n/-\n4. Prove that ¬(A ∨ B ∨ C) ↔ (¬A ∧ ¬B ∧ ¬C).\nYou may *NOT* use the axiom of the excluded middle.\n-/\nexample : ∀ (A B C : Prop), ¬(A ∨ B ∨ C) ↔ (¬A ∧ ¬B ∧ ¬C) :=\nbegin\n     intros,\n     split,\n          assume nabc,\n          split,\n          assume a,\n          exact nabc (or.inl a),\n          split,\n          assume b,\n          exact nabc (or.inr (or.inl b)),\n          assume c,\n          exact nabc (or.inr (or.inr c)),\n          assume nabc,\n          assume abc,\n          cases abc with a bc,\n          exact (nabc.1 a),\n          cases bc with b c,\n          exact (nabc.2.1 b),\n          exact (nabc.2.2 c),\nend\n-- answer:\nexample : ∀ (A B C : Prop), ¬(A ∨ B ∨ C) ↔ (¬A ∧ ¬B ∧ ¬C) :=\nbegin\n     intros A B C,\n     apply iff.intro,\n     /- forward -/\n          assume nabc,\n          apply and.intro,\n          assume a,\n          have f : false := nabc (or.inl a),\n          exact f,\n          apply and.intro,\n          assume b,\n          have f : false := nabc (or.inr (or.inl b)),\n          exact f,\n          assume c,\n          have f : false := nabc (or.inr (or.inr c)),\n          exact f,\n     /-backward-/\n          assume nanbnc,\n          assume abc,\n          cases abc with a bc,\n          have na := nanbnc.1,\n          exact false.elim (na a),\n          cases bc with b c,\n          have nb := nanbnc.2.1,\n          exact false.elim (nb b),\n          have nc := nanbnc.2.2,\n          exact false.elim (nc c),\nend\n/-\n5a. Prove that ¬(A ∨ ¬B) ↔ (¬A ∧ B).\nYou may use the axiom of the excluded middle.\n-/\n\n-- answer:\nexample : ∀ (A B : Prop), ¬(A ∨ ¬B) ↔ (¬A ∧ B) :=\nbegin\n     intros A B,\n     apply iff.intro,\n     /- forward-/\n          assume nanb,\n          apply and.intro,\n          assume a,\n          have f : false := nanb (or.inl a),\n          exact f,\n          cases em B with b nb,\n          exact b,\n          have f : false := nanb (or.inr nb),\n          exact false.elim f,\n     /-backward-/\n          assume nab,\n          assume anb,\n          cases anb with a nb,\n          have na := nab.1,\n          exact false.elim (na a),\n          have b := nab.2,\n          exact false.elim (nb b),\nend\n/-\n5b. Prove that ¬(A ∧ ¬B) ↔ (¬A ∨ B).\nYou may use the axiom of the excluded middle.\n-/\n\n-- answer:\nexample : ∀ (A B : Prop), ¬(A ∧ ¬B) ↔ (¬A ∨ B) :=\nbegin\n     intros A B,\n     apply iff.intro,\n     /-forward-/\n          assume nanb,\n          cases em A with a na,\n          cases em B with b nb,\n          apply or.inr b,\n          have f : false := nanb (and.intro a nb),\n          exact false.elim f,\n          apply or.inl na,\n     /-backward-/\n          assume nab,\n          assume anb,\n          cases nab with na b,\n          have a := anb.1,\n          exact na a,\n          have nb := anb.2,\n          exact nb b,\nend\n/-\n6. Prove that ¬P ∨ ¬Q ∨ R is true if and only\nif P → Q → R. You may use the axiom of the\nexcluded middle.\n-/\n-- answer:\nexample : ∀ (P Q R : Prop ), (P → Q → R) ↔ (¬P ∨ ¬Q ∨ R) :=\nbegin\n     intros P Q R,\n     split,\n          assume pqr,\n          cases em P with p np,\n          have QR := pqr p,\n          cases em Q with q nq,\n          have r := QR q,\n          exact or.inr (or.inr r),\n          exact or.inr (or.inl nq),\n          exact or.inl np,\n\n          assume npnqr,\n          assume p,\n          assume q,\n          cases npnqr with np nqr,\n               contradiction,\n               cases nqr with nq r,\n               contradiction,\n               exact r,     \nend\n/-\n7. Prove that ¬¬¬P → ¬P. You may use the axiom\nof the excluded middle.\n-/\n\n-- answer:\nexample : ∀ P : Prop, ¬¬¬P → ¬P :=\nbegin\n     intro P,\n     assume nnnp,\n     assume p,\n     cases em ¬P with p np,\n          contradiction,\n          exact nnnp np,\nend\n/-\nUniversal Quantifiers, Existential Quantifiers, and\nSatisfiability.\n-/\n\n/-\n8. Prove the following statements are satisfiable\nor prove that they are not. You may use the axiom\nof the excluded middle to prove cases where the\nstatements are not satisfiable.\n-/\n\n/-\n8a. (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q)\n-/\nexample : ∃ P Q : Prop, (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) :=\nbegin\n     apply exists.intro true,\n     apply exists.intro true,\n     simp,\nend\n-- answer:\nexample : ∃ P Q : Prop, (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) := \nbegin\n     apply exists.intro true,\n     apply exists.intro true,\n     split,\n          exact or.inl true.intro,\n          split,\n          exact or.inr true.intro,\n          exact or.inl true.intro,\nend\n\n/-\n8b. (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) ∧ (¬P ∨ ¬Q)\n-/\n\n-- answer:\nexample : ¬∃ (P Q : Prop), (P ∨ Q) ∧ (¬P ∨ Q) ∧ (P ∨ ¬Q) ∧ (¬P ∨ ¬Q) :=\nbegin\n     assume func,\n     apply exists.elim func,\n     assume P,\n     assume Pf,\n     apply exists.elim Pf,\n     assume Q,\n     assume Qf,\n     cases em P with p np,\n          cases em Q with q nq,\n               have npnq := Qf.2.2.2,\n               cases npnq with np nq,\n               contradiction,\n               contradiction,\n               have npq := Qf.2.1,\n               cases npq with np q,\n               contradiction,\n               contradiction,\n               cases em Q with q nq,\n               have pnq := Qf.2.2.1,\n               cases pnq with p nq,\n               contradiction,\n               contradiction,\n               have pq := Qf.1,\n               cases pq with p q,\n               contradiction,\n               contradiction,\nend\n/-\n8c. (P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ R) ∧\n     (P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ ¬Q ∨ ¬R)\n-/\nexample : ∃ P Q R: Prop, (P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ R) ∧\n     (P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ ¬Q ∨ ¬R) :=\nbegin\n     apply exists.intro true,\n     apply exists.intro true,\n     apply exists.intro false,\n     simp,\nend\n-- answer:\nexample : ∃ (P Q R : Prop), (P ∨ Q ∨ R) ∧ (¬P ∨ Q ∨ R) ∧\n     (P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ ¬Q ∨ ¬R) :=\nbegin\n     apply exists.intro true,\n     apply exists.intro true,\n     apply exists.intro false,\n     split,\n     exact or.inl true.intro,\n     split,\n     exact or.inr (or.inl true.intro),\n     split,\n     exact or.inl true.intro,\n     exact or.inr (or.inr false.elim),\n\n\nend\n/-\n9. Prove that exists a number such that\nit is both even and a multiple of 3.\nUse the supplied definitions of even and prime.\n-/\ndef isEven' (n: ℕ ) := ∃ m :ℕ, n = m*2\ndef isMult3' (n: ℕ ) := ∃ m: ℕ, n = m*3\n\nexample : ∃ (n: ℕ ), isEven' n ∧ isMult3' n :=\nbegin\n     apply exists.intro 6,\n     split,\n     unfold isEven',\n     apply exists.intro 3,\n     trivial,\n     unfold isMult3',\n     apply exists.intro 2,\n     trivial,\nend\n\ndef isEven(n: ℕ) := (∃(m: ℕ), m * 2 = n)\n\ndef isMult3(n: ℕ) := (∃(m: ℕ), m * 3 = n)\n\n-- answer\nexample : ∃ (n: ℕ ), isEven n ∧ isMult3 n :=\nbegin\n     have isEven6 : isEven 6 := ⟨3, rfl⟩,\n     have isPrime6 : isMult3 6 := ⟨ 2, rfl ⟩ ,\n     have both := and.intro isEven6 isPrime6,\n     exact ⟨ 6, both ⟩ , \nend\n/-\n10a. Write the lemma that if there exists \n someone that you can fool all of the time, \n then there always exists someone you can fool.\n Use the supplied axioms, and make sure you use\n at least as many parentheses as needed. (It's\n okay to use more than you need.)\n10b. Prove the above lemma.\n-/\n\naxioms Person Time: Type\naxiom fool: Person → Time → Prop\nexample : (∃ p: Person, ∀ t: Time, fool p t) → \n     (∀ t : Time, ∃ p : Person, fool p t):=\nbegin\n     assume foolish,\n     assume T,\n     apply exists.elim foolish,\n     assume P,\n     assume func,\n     have ifunc := func T,\n     apply exists.intro P,\n     assumption,\nend\n\n-- answers:\nexample : (∃(p : Person), ∀ (t : Time), fool p t) → \n          (∀ (t : Time), ∃ (p : Person), fool p t) := \nbegin\n     assume idiot,\n     assume t,\n     apply exists.elim idiot,\n     assume p,\n     assume tpfunc,\n     have idiotfunc := tpfunc t,\n     exact ⟨ p, idiotfunc ⟩ ,\nend\n", "meta": {"author": "justinqcai", "repo": "CS2102", "sha": "d309f0db3f1df52eb77206ee1e8665a3b49d7a0c", "save_path": "github-repos/lean/justinqcai-CS2102", "path": "github-repos/lean/justinqcai-CS2102/CS2102-d309f0db3f1df52eb77206ee1e8665a3b49d7a0c/practice-exam2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951552333004, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7923369634272769}}
{"text": "/-\nCPDT Chapter 2, Introducing Inductive Types\n-/\nimport mini_crush\nuniverse variable u\n\nexport nat (succ)\n\ndef is_zero : ℕ → bool\n| 0        := tt\n| (succ _) := ff\n\ndef plus : ℕ → ℕ → ℕ\n| 0 m         := m\n| (succ n') m := succ (plus n' m)\n\ntheorem n_plus_0 (n : ℕ) : plus n 0 = n :=\nby mini_crush\n\nlemma plus_S (n1 n2 : nat) : plus n1 (succ n2) = succ (plus n1 n2) :=\nby mini_crush\n\ninductive nat_list : Type\n| NNil  : nat_list\n| NCons : nat → nat_list → nat_list\n\nopen nat_list\n\ndef nlength : nat_list → ℕ\n| NNil          := 0\n| (NCons _ ls') := succ (nlength ls')\n\ndef napp : nat_list → nat_list → nat_list\n| NNil ls2 := ls2\n| (NCons n ls1') ls2 := NCons n (napp ls1' ls2)\n\ntheorem nlength_napp (ls1 ls2 : nat_list) : nlength (napp ls1 ls2) = plus (nlength ls1) (nlength ls2) :=\nby mini_crush\n\ninductive nat_btree : Type\n| NLeaf : nat_btree\n| NNode : nat_btree → ℕ → nat_btree → nat_btree\n\nopen nat_btree\n\ndef nsize : nat_btree → ℕ\n| NLeaf             := succ 0\n| (NNode tr1 _ tr2) := plus (nsize tr1) (nsize tr2)\n\ndef nsplice : nat_btree → nat_btree → nat_btree\n| NLeaf tr2               := NNode tr2 0 NLeaf\n| (NNode tr1' n tr2') tr2 := NNode (nsplice tr1' tr2) n tr2'\n\n@[simp] theorem plus_assoc (n1 n2 n3 : nat) : plus (plus n1 n2) n3 = plus n1 (plus n2 n3) :=\nby mini_crush\n\ntheorem nsize_nsplice (tr1 tr2 : nat_btree) : nsize (nsplice tr1 tr2) = plus (nsize tr2) (nsize tr1) :=\nby mini_crush\n\nexport list (nil cons)\n\ndef length {α : Type u} : list α → ℕ\n| nil          := 0\n| (cons _ ls') := succ (length ls')\n\ndef app {α : Type u} : list α → list α → list α\n| nil ls2           := ls2\n| (cons x ls1') ls2 := cons x (app ls1' ls2)\n\ntheorem length_app {α : Type u} (ls1 ls2 : list α) : length (app ls1 ls2) = plus (length ls1) (length ls2) :=\nby mini_crush\n\ninductive pformula : Type\n| Truth : pformula\n| Falsehood : pformula\n| Conjunction : pformula → pformula → pformula.\n\nopen pformula\n\ndef pformula_denote : pformula → Prop\n| Truth               := true\n| Falsehood           := false\n| (Conjunction f1 f2) := pformula_denote f1 ∧ pformula_denote f2\n\nopen pformula\n\ninductive formula : Type\n| Eq     : nat → nat → formula\n| And    : formula → formula → formula\n| Forall : (nat → formula) → formula\n\nopen formula\n\nexample : formula := Forall (λ x, Eq x x)\n\ndef formula_denote : formula → Prop\n| (Eq n1 n2)  := n1 = n2\n| (And f1 f2) := formula_denote f1 ∧ formula_denote f2\n| (Forall f') := ∀ n : nat, formula_denote (f' n)\n\ndef swapper : formula → formula\n| (Eq n1 n2)  := Eq n2 n1\n| (And f1 f2) := And (swapper f2) (swapper f1)\n| (Forall f') := Forall (λ n, swapper (f' n))\n\ntheorem swapper_preserves_truth (f) : formula_denote f → formula_denote (swapper f) :=\nby mini_crush\n", "meta": {"author": "leanprover", "repo": "mini_crush", "sha": "cea4166b1b2970fba47907798e7fe0511e426cfd", "save_path": "github-repos/lean/leanprover-mini_crush", "path": "github-repos/lean/leanprover-mini_crush/mini_crush-cea4166b1b2970fba47907798e7fe0511e426cfd/test/cpdt2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642531177793, "lm_q2_score": 0.8615382112085969, "lm_q1q2_score": 0.7923071812622621}}
{"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 Mathbin.Data.Nat.Basic\nimport Mathbin.Order.Monotone.Basic\n\n/-!\n# Basic instances on 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:\n* instances on `ℤ`. The stronger one is `int.comm_ring`.\n  See `data/int/defs/order` for `int.linear_ordered_comm_ring`.\n* basic lemmas about the integers, but which do not use the ordered algebra hierarchy.\n-/\n\n\nopen Nat\n\nnamespace Int\n\ninstance : Inhabited ℤ :=\n  ⟨Int.zero⟩\n\ninstance : Nontrivial ℤ :=\n  ⟨⟨0, 1, Int.zero_ne_one⟩⟩\n\ninstance : CommRing ℤ where\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.mul_add\n  right_distrib := Int.add_mul\n  mul_comm := Int.mul_comm\n  natCast := Int.ofNat\n  natCast_zero := rfl\n  natCast_succ n := rfl\n  intCast n := n\n  intCast_ofNat n := rfl\n  intCast_negSucc n := rfl\n  zsmul := (· * ·)\n  zsmul_zero' := Int.zero_mul\n  zsmul_succ' n x := by\n    rw [Nat.succ_eq_add_one, Nat.add_comm, of_nat_add, Int.add_mul, of_nat_one, Int.one_mul]\n  zsmul_neg' n x := Int.neg_mul_eq_neg_mul_symm (n.succ : ℤ) x\n\n/-! ### Extra instances to short-circuit type class resolution\n\nThese also prevent non-computable instances like `int.normed_comm_ring` being used to construct\nthese instances non-computably.\n-/\n\n\n-- instance : has_sub int            := by apply_instance -- This is in core\ninstance : AddCommMonoid ℤ := by infer_instance\n\ninstance : AddMonoid ℤ := by infer_instance\n\ninstance : Monoid ℤ := by infer_instance\n\ninstance : CommMonoid ℤ := by infer_instance\n\ninstance : CommSemigroup ℤ := by infer_instance\n\ninstance : Semigroup ℤ := by infer_instance\n\ninstance : AddCommGroup ℤ := by infer_instance\n\ninstance : AddGroup ℤ := by infer_instance\n\ninstance : AddCommSemigroup ℤ := by infer_instance\n\ninstance : AddSemigroup ℤ := by infer_instance\n\ninstance : CommSemiring ℤ := by infer_instance\n\ninstance : Semiring ℤ := by infer_instance\n\ninstance : Ring ℤ := by infer_instance\n\ninstance : Distrib ℤ := by infer_instance\n\nend Int\n\nnamespace Int\n\n#print Int.add_neg_one /-\n@[simp]\ntheorem add_neg_one (i : ℤ) : i + -1 = i - 1 :=\n  rfl\n#align int.add_neg_one Int.add_neg_one\n-/\n\n#print Int.sign_coe_add_one /-\n@[simp]\ntheorem sign_coe_add_one (n : ℕ) : Int.sign (n + 1) = 1 :=\n  rfl\n#align int.sign_coe_add_one Int.sign_coe_add_one\n-/\n\n#print Int.sign_negSucc /-\n@[simp]\ntheorem sign_negSucc (n : ℕ) : Int.sign -[n+1] = -1 :=\n  rfl\n#align int.sign_neg_succ_of_nat Int.sign_negSucc\n-/\n\n#print Int.default_eq_zero /-\n@[simp]\ntheorem default_eq_zero : default = (0 : ℤ) :=\n  rfl\n#align int.default_eq_zero Int.default_eq_zero\n-/\n\nunsafe instance : has_to_format ℤ :=\n  ⟨fun z => toString z⟩\n\nsection\n\n-- Note that here we are disabling the \"safety\" of reflected, to allow us to reuse `int.mk_numeral`.\n-- The usual way to provide the required `reflected` instance would be via rewriting to prove that\n-- the expression we use here is equivalent.\nattribute [local semireducible] reflected\n\nunsafe instance reflect : has_reflect ℤ :=\n  int.mk_numeral q(ℤ) q((by infer_instance : Zero ℤ)) q((by infer_instance : One ℤ))\n    q((by infer_instance : Add ℤ)) q((by infer_instance : Neg ℤ))\n#align int.reflect int.reflect\n\nend\n\nattribute [simp] Int.bodd\n\n#print Int.add_def /-\n@[simp]\ntheorem add_def {a b : ℤ} : Int.add a b = a + b :=\n  rfl\n#align int.add_def Int.add_def\n-/\n\n#print Int.mul_def /-\n@[simp]\ntheorem mul_def {a b : ℤ} : Int.mul a b = a * b :=\n  rfl\n#align int.mul_def Int.mul_def\n-/\n\n#print Int.negSucc_not_nonneg /-\n@[simp]\ntheorem negSucc_not_nonneg (n : ℕ) : 0 ≤ -[n+1] ↔ False :=\n  by\n  simp only [not_le, iff_false_iff]\n  exact Int.negSucc_lt_zero n\n#align int.neg_succ_not_nonneg Int.negSucc_not_nonneg\n-/\n\n#print Int.negSucc_not_pos /-\n@[simp]\ntheorem negSucc_not_pos (n : ℕ) : 0 < -[n+1] ↔ False := by simp only [not_lt, iff_false_iff]\n#align int.neg_succ_not_pos Int.negSucc_not_pos\n-/\n\n#print Int.negSucc_sub_one /-\n@[simp]\ntheorem negSucc_sub_one (n : ℕ) : -[n+1] - 1 = -[n + 1+1] :=\n  rfl\n#align int.neg_succ_sub_one Int.negSucc_sub_one\n-/\n\n#print Int.ofNat_mul_negSucc /-\n@[simp]\ntheorem ofNat_mul_negSucc (m n : ℕ) : (m : ℤ) * -[n+1] = -(m * succ n) :=\n  rfl\n#align int.coe_nat_mul_neg_succ Int.ofNat_mul_negSucc\n-/\n\n#print Int.negSucc_mul_ofNat /-\n@[simp]\ntheorem negSucc_mul_ofNat (m n : ℕ) : -[m+1] * n = -(succ m * n) :=\n  rfl\n#align int.neg_succ_mul_coe_nat Int.negSucc_mul_ofNat\n-/\n\n#print Int.negSucc_mul_negSucc /-\n@[simp]\ntheorem negSucc_mul_negSucc (m n : ℕ) : -[m+1] * -[n+1] = succ m * succ n :=\n  rfl\n#align int.neg_succ_mul_neg_succ Int.negSucc_mul_negSucc\n-/\n\n/- warning: int.coe_nat_le clashes with int.coe_nat_le_coe_nat_iff -> Int.ofNat_le\nCase conversion may be inaccurate. Consider using '#align int.coe_nat_le Int.ofNat_leₓ'. -/\n#print Int.ofNat_le /-\ntheorem ofNat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n :=\n  ofNat_le m n\n#align int.coe_nat_le Int.ofNat_le\n-/\n\n/- warning: int.coe_nat_lt clashes with int.coe_nat_lt_coe_nat_iff -> Int.ofNat_lt\nCase conversion may be inaccurate. Consider using '#align int.coe_nat_lt Int.ofNat_ltₓ'. -/\n#print Int.ofNat_lt /-\ntheorem ofNat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n :=\n  ofNat_lt m n\n#align int.coe_nat_lt Int.ofNat_lt\n-/\n\n#print Int.coe_nat_inj' /-\ntheorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n :=\n  Int.ofNat_inj m n\n#align int.coe_nat_inj' Int.coe_nat_inj'\n-/\n\n/- warning: int.coe_nat_strict_mono -> Int.coe_nat_strictMono is a dubious translation:\nlean 3 declaration is\n  StrictMono.{0, 0} Nat Int (PartialOrder.toPreorder.{0} Nat (LinearOrder.toPartialOrder.{0} Nat Nat.linearOrder)) (PartialOrder.toPreorder.{0} Int (LinearOrder.toPartialOrder.{0} Int Int.linearOrder)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))))\nbut is expected to have type\n  StrictMono.{0, 0} Nat Int (PartialOrder.toPreorder.{0} Nat (LinearOrder.toPartialOrder.{0} Nat Nat.linearOrder)) (PartialOrder.toPreorder.{0} Int (LinearOrder.toPartialOrder.{0} Int Int.instLinearOrderInt)) (fun (x._@.Mathlib.Data.Int.Basic._hyg.840 : Nat) => Nat.cast.{0} Int instNatCastInt x._@.Mathlib.Data.Int.Basic._hyg.840)\nCase conversion may be inaccurate. Consider using '#align int.coe_nat_strict_mono Int.coe_nat_strictMonoₓ'. -/\ntheorem coe_nat_strictMono : StrictMono (coe : ℕ → ℤ) := fun _ _ => Int.ofNat_lt.2\n#align int.coe_nat_strict_mono Int.coe_nat_strictMono\n\n#print Int.coe_nat_nonneg /-\ntheorem coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) :=\n  ofNat_le.2 (Nat.zero_le _)\n#align int.coe_nat_nonneg Int.coe_nat_nonneg\n-/\n\n#print Int.negSucc_ne_zero /-\n@[simp]\ntheorem negSucc_ne_zero (n : ℕ) : -[n+1] ≠ 0 := fun h => Int.noConfusion h\n#align int.neg_of_nat_ne_zero Int.negSucc_ne_zero\n-/\n\n#print Int.zero_ne_negSucc /-\n@[simp]\ntheorem zero_ne_negSucc (n : ℕ) : 0 ≠ -[n+1] := fun h => Int.noConfusion h\n#align int.zero_ne_neg_of_nat Int.zero_ne_negSucc\n-/\n\n/-! ### succ and pred -/\n\n\n#print Int.succ /-\n/-- Immediate successor of an integer: `succ n = n + 1` -/\ndef succ (a : ℤ) :=\n  a + 1\n#align int.succ Int.succ\n-/\n\n#print Int.pred /-\n/-- Immediate predecessor of an integer: `pred n = n - 1` -/\ndef pred (a : ℤ) :=\n  a - 1\n#align int.pred Int.pred\n-/\n\n#print Int.nat_succ_eq_int_succ /-\ntheorem nat_succ_eq_int_succ (n : ℕ) : (Nat.succ n : ℤ) = Int.succ n :=\n  rfl\n#align int.nat_succ_eq_int_succ Int.nat_succ_eq_int_succ\n-/\n\n#print Int.pred_succ /-\ntheorem pred_succ (a : ℤ) : pred (succ a) = a :=\n  add_sub_cancel _ _\n#align int.pred_succ Int.pred_succ\n-/\n\n#print Int.succ_pred /-\ntheorem succ_pred (a : ℤ) : succ (pred a) = a :=\n  sub_add_cancel _ _\n#align int.succ_pred Int.succ_pred\n-/\n\n#print Int.neg_succ /-\ntheorem neg_succ (a : ℤ) : -succ a = pred (-a) :=\n  neg_add _ _\n#align int.neg_succ Int.neg_succ\n-/\n\n#print Int.succ_neg_succ /-\ntheorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a := by rw [neg_succ, succ_pred]\n#align int.succ_neg_succ Int.succ_neg_succ\n-/\n\n#print Int.neg_pred /-\ntheorem neg_pred (a : ℤ) : -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-/\n\n#print Int.pred_neg_pred /-\ntheorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a := by rw [neg_pred, pred_succ]\n#align int.pred_neg_pred Int.pred_neg_pred\n-/\n\n#print Int.pred_nat_succ /-\ntheorem pred_nat_succ (n : ℕ) : pred (Nat.succ n) = n :=\n  pred_succ n\n#align int.pred_nat_succ Int.pred_nat_succ\n-/\n\n#print Int.neg_nat_succ /-\ntheorem neg_nat_succ (n : ℕ) : -(Nat.succ n : ℤ) = pred (-n) :=\n  neg_succ n\n#align int.neg_nat_succ Int.neg_nat_succ\n-/\n\n#print Int.succ_neg_nat_succ /-\ntheorem succ_neg_nat_succ (n : ℕ) : succ (-Nat.succ n) = -n :=\n  succ_neg_succ n\n#align int.succ_neg_nat_succ Int.succ_neg_nat_succ\n-/\n\n#print Int.add_one_le_iff /-\ntheorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b :=\n  Iff.rfl\n#align int.add_one_le_iff Int.add_one_le_iff\n-/\n\n#print Int.coe_pred_of_pos /-\n@[norm_cast]\ntheorem coe_pred_of_pos {n : ℕ} (h : 0 < n) : ((n - 1 : ℕ) : ℤ) = (n : ℤ) - 1 :=\n  by\n  cases n\n  cases h\n  simp\n#align int.coe_pred_of_pos Int.coe_pred_of_pos\n-/\n\n#print Int.induction_on /-\n@[elab_as_elim]\nprotected theorem induction_on {p : ℤ → Prop} (i : ℤ) (hz : p 0) (hp : ∀ i : ℕ, p i → p (i + 1))\n    (hn : ∀ i : ℕ, p (-i) → p (-i - 1)) : p i :=\n  by\n  induction i\n  · induction i\n    · exact hz\n    · exact hp _ i_ih\n  · have : ∀ n : ℕ, p (-n) := by\n      intro n\n      induction n\n      · simp [hz]\n      · convert hn _ n_ih using 1\n        simp [sub_eq_neg_add]\n    exact this (i + 1)\n#align int.induction_on Int.induction_on\n-/\n\n/-! ### nat abs -/\n\n\nvariable {a b : ℤ} {n : ℕ}\n\nattribute [simp] nat_abs_of_nat nat_abs_zero nat_abs_one\n\n#print Int.natAbs_add_le /-\ntheorem natAbs_add_le (a b : ℤ) : natAbs (a + b) ≤ natAbs a + natAbs b :=\n  by\n  have : ∀ a b : ℕ, nat_abs (sub_nat_nat a (Nat.succ b)) ≤ Nat.succ (a + b) :=\n    by\n    refine' fun a b : ℕ =>\n      sub_nat_nat_elim a b.succ (fun m n i => n = b.succ → nat_abs i ≤ (m + b).succ) _\n        (fun i n e => _) rfl\n    · rintro i n rfl\n      rw [add_comm _ i, add_assoc]\n      exact Nat.le_add_right i (b.succ + b).succ\n    · apply succ_le_succ\n      rw [← succ.inj e, ← add_assoc, add_comm]\n      apply Nat.le_add_right\n  cases a <;> cases' b with b b <;> simp [nat_abs, Nat.succ_add] <;> try rfl <;> [skip,\n      rw [add_comm a b]] <;>\n    apply this\n#align int.nat_abs_add_le Int.natAbs_add_le\n-/\n\n#print Int.natAbs_sub_le /-\ntheorem natAbs_sub_le (a b : ℤ) : natAbs (a - b) ≤ natAbs a + natAbs b :=\n  by\n  rw [sub_eq_add_neg, ← Int.natAbs_neg b]\n  apply nat_abs_add_le\n#align int.nat_abs_sub_le Int.natAbs_sub_le\n-/\n\n#print Int.natAbs_negOfNat /-\ntheorem natAbs_negOfNat (n : ℕ) : natAbs (negOfNat n) = n := by cases n <;> rfl\n#align int.nat_abs_neg_of_nat Int.natAbs_negOfNat\n-/\n\n#print Int.natAbs_mul /-\ntheorem natAbs_mul (a b : ℤ) : natAbs (a * b) = natAbs a * natAbs b := by\n  cases a <;> cases b <;>\n    simp only [← Int.mul_def, Int.mul, nat_abs_neg_of_nat, eq_self_iff_true, Int.natAbs]\n#align int.nat_abs_mul Int.natAbs_mul\n-/\n\n#print Int.natAbs_mul_natAbs_eq /-\ntheorem natAbs_mul_natAbs_eq {a b : ℤ} {c : ℕ} (h : a * b = (c : ℤ)) : a.natAbs * b.natAbs = c := by\n  rw [← nat_abs_mul, h, nat_abs_of_nat]\n#align int.nat_abs_mul_nat_abs_eq Int.natAbs_mul_natAbs_eq\n-/\n\n#print Int.natAbs_mul_self' /-\ntheorem natAbs_mul_self' (a : ℤ) : (natAbs a * natAbs a : ℤ) = a * a := by\n  rw [← Int.ofNat_mul, nat_abs_mul_self]\n#align int.nat_abs_mul_self' Int.natAbs_mul_self'\n-/\n\n#print Int.negSucc_eq' /-\ntheorem negSucc_eq' (m : ℕ) : -[m+1] = -m - 1 := by simp [neg_succ_of_nat_eq, sub_eq_neg_add]\n#align int.neg_succ_of_nat_eq' Int.negSucc_eq'\n-/\n\n#print Int.natAbs_ne_zero_of_ne_zero /-\ntheorem natAbs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.natAbs ≠ 0 := fun h =>\n  hz <| Int.eq_zero_of_natAbs_eq_zero h\n#align int.nat_abs_ne_zero_of_ne_zero Int.natAbs_ne_zero_of_ne_zero\n-/\n\n#print Int.natAbs_eq_zero /-\n@[simp]\ntheorem natAbs_eq_zero {a : ℤ} : a.natAbs = 0 ↔ a = 0 :=\n  ⟨Int.eq_zero_of_natAbs_eq_zero, fun h => h.symm ▸ rfl⟩\n#align int.nat_abs_eq_zero Int.natAbs_eq_zero\n-/\n\n#print Int.natAbs_ne_zero /-\ntheorem natAbs_ne_zero {a : ℤ} : a.natAbs ≠ 0 ↔ a ≠ 0 :=\n  not_congr Int.natAbs_eq_zero\n#align int.nat_abs_ne_zero Int.natAbs_ne_zero\n-/\n\n#print Int.natAbs_lt_natAbs_of_nonneg_of_lt /-\ntheorem natAbs_lt_natAbs_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) :\n    a.natAbs < b.natAbs := by\n  lift b to ℕ using le_trans w₁ (le_of_lt w₂)\n  lift a to ℕ using w₁\n  simpa [coe_nat_lt] using w₂\n#align int.nat_abs_lt_nat_abs_of_nonneg_of_lt Int.natAbs_lt_natAbs_of_nonneg_of_lt\n-/\n\n#print Int.natAbs_eq_natAbs_iff /-\ntheorem natAbs_eq_natAbs_iff {a b : ℤ} : a.natAbs = b.natAbs ↔ a = b ∨ a = -b :=\n  by\n  constructor <;> intro h\n  ·\n    cases' Int.natAbs_eq a with h₁ h₁ <;> cases' Int.natAbs_eq b with h₂ h₂ <;> rw [h₁, h₂] <;>\n      simp [h]\n  · cases h <;> rw [h]\n    rw [Int.natAbs_neg]\n#align int.nat_abs_eq_nat_abs_iff Int.natAbs_eq_natAbs_iff\n-/\n\n#print Int.natAbs_eq_iff /-\ntheorem natAbs_eq_iff {a : ℤ} {n : ℕ} : a.natAbs = n ↔ a = n ∨ a = -n := by\n  rw [← Int.natAbs_eq_natAbs_iff, Int.natAbs_ofNat]\n#align int.nat_abs_eq_iff Int.natAbs_eq_iff\n-/\n\n/-! ### `/`  -/\n\n\n#print Int.ofNat_div /-\n@[simp]\ntheorem ofNat_div (m n : ℕ) : ofNat (m / n) = ofNat m / ofNat n :=\n  rfl\n#align int.of_nat_div Int.ofNat_div\n-/\n\n#print Int.coe_nat_div /-\n@[simp, norm_cast]\ntheorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n :=\n  rfl\n#align int.coe_nat_div Int.coe_nat_div\n-/\n\n#print Int.negSucc_ediv /-\ntheorem negSucc_ediv (m : ℕ) {b : ℤ} (H : 0 < b) : -[m+1] / b = -(m / b + 1) :=\n  match b, eq_succ_of_zero_lt H with\n  | _, ⟨n, rfl⟩ => rfl\n#align int.neg_succ_of_nat_div Int.negSucc_ediv\n-/\n\n#print Int.zero_div /-\n-- Will be generalized to Euclidean domains.\n@[local simp]\nprotected theorem zero_div : ∀ b : ℤ, 0 / b = 0\n  | (n : ℕ) => show ofNat _ = _ by simp\n  | -[n+1] => show -ofNat _ = _ by simp\n#align int.zero_div Int.zero_div\n-/\n\n#print Int.div_zero /-\n-- Will be generalized to Euclidean domains.\n@[local simp]\nprotected theorem div_zero : ∀ a : ℤ, a / 0 = 0\n  | (n : ℕ) => show ofNat _ = _ by simp\n  | -[n+1] => rfl\n#align int.div_zero Int.div_zero\n-/\n\n@[simp]\nprotected theorem div_neg : ∀ a b : ℤ, a / -b = -(a / b)\n  | (m : ℕ), 0 => show ofNat (m / 0) = -(m / 0 : ℕ) by rw [Nat.div_zero] <;> rfl\n  | (m : ℕ), (n + 1 : ℕ) => rfl\n  | (m : ℕ), -[n+1] => (neg_neg _).symm\n  | -[m+1], 0 => rfl\n  | -[m+1], (n + 1 : ℕ) => rfl\n  | -[m+1], -[n+1] => rfl\n#align int.div_neg Int.div_negₓ\n\n#print Int.ediv_of_neg_of_pos /-\ntheorem ediv_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) :=\n  match a, b, eq_negSucc_of_lt_zero Ha, eq_succ_of_zero_lt Hb with\n  | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by\n    change (- -[m+1] : ℤ) with (m + 1 : ℤ) <;> rw [add_sub_cancel] <;> rfl\n#align int.div_of_neg_of_pos Int.ediv_of_neg_of_pos\n-/\n\nprotected theorem div_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a / b :=\n  match a, b, eq_ofNat_of_zero_le Ha, eq_ofNat_of_zero_le Hb with\n  | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => ofNat_zero_le _\n#align int.div_nonneg Int.div_nonnegₓ\n\n#print Int.ediv_neg' /-\ntheorem ediv_neg' {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 :=\n  match a, b, eq_negSucc_of_lt_zero Ha, eq_succ_of_zero_lt Hb with\n  | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => negSucc_lt_zero _\n#align int.div_neg' Int.ediv_neg'\n-/\n\n@[simp]\nprotected theorem div_one : ∀ a : ℤ, a / 1 = a\n  | (n : ℕ) => congr_arg ofNat (Nat.div_one _)\n  | -[n+1] => congr_arg negSucc (Nat.div_one _)\n#align int.div_one Int.div_oneₓ\n\ntheorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 :=\n  match a, b, eq_ofNat_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with\n  | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 => congr_arg ofNat <| Nat.div_eq_of_lt <| lt_of_ofNat_lt_ofNat H2\n#align int.div_eq_zero_of_lt Int.div_eq_zero_of_ltₓ\n\n/-! ### mod -/\n\n\n#print Int.ofNat_mod_ofNat /-\ntheorem ofNat_mod_ofNat (m n : Nat) : (m % n : ℤ) = ofNat (m % n) :=\n  rfl\n#align int.of_nat_mod Int.ofNat_mod_ofNat\n-/\n\n#print Int.coe_nat_mod /-\n@[simp, norm_cast]\ntheorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n :=\n  rfl\n#align int.coe_nat_mod Int.coe_nat_mod\n-/\n\n#print Int.negSucc_emod /-\ntheorem negSucc_emod (m : ℕ) {b : ℤ} (bpos : 0 < b) : -[m+1] % b = b - 1 - m % b := by\n  rw [sub_sub, add_comm] <;>\n    exact\n      match b, eq_succ_of_zero_lt bpos with\n      | _, ⟨n, rfl⟩ => rfl\n#align int.neg_succ_of_nat_mod Int.negSucc_emod\n-/\n\n@[simp]\ntheorem mod_neg : ∀ a b : ℤ, a % -b = a % b\n  | (m : ℕ), n => @congr_arg ℕ ℤ _ _ (fun i => ↑(m % i)) (natAbs_neg _)\n  | -[m+1], n => @congr_arg ℕ ℤ _ _ (fun i => subNatNat i (Nat.succ (m % i))) (natAbs_neg _)\n#align int.mod_neg Int.mod_negₓ\n\n-- Will be generalized to Euclidean domains.\n@[local simp]\ntheorem zero_mod (b : ℤ) : 0 % b = 0 :=\n  rfl\n#align int.zero_mod Int.zero_modₓ\n\n-- Will be generalized to Euclidean domains.\n@[local simp]\ntheorem mod_zero : ∀ a : ℤ, a % 0 = a\n  | (m : ℕ) => congr_arg ofNat <| Nat.mod_zero _\n  | -[m+1] => congr_arg negSucc <| Nat.mod_zero _\n#align int.mod_zero Int.mod_zeroₓ\n\n-- Will be generalized to Euclidean domains.\n@[local simp]\ntheorem mod_one : ∀ a : ℤ, a % 1 = 0\n  | (m : ℕ) => congr_arg ofNat <| Nat.mod_one _\n  | -[m+1] => show (1 - (m % 1).succ : ℤ) = 0 by rw [Nat.mod_one] <;> rfl\n#align int.mod_one Int.mod_oneₓ\n\n#print Int.emod_eq_of_lt /-\ntheorem emod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a :=\n  match a, b, eq_ofNat_of_zero_le H1, eq_ofNat_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with\n  | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 => congr_arg ofNat <| Nat.mod_eq_of_lt (lt_of_ofNat_lt_ofNat H2)\n#align int.mod_eq_of_lt Int.emod_eq_of_lt\n-/\n\ntheorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[m+1] :=\n  by\n  rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n : ℤ), eq_comm, neg_eq_iff_eq_neg, neg_sub,\n    sub_sub_self, add_right_comm]\n  exact @congr_arg ℕ ℤ _ _ (fun i => (i + 1 : ℤ)) (Nat.mod_add_div _ _).symm\n#align int.mod_add_div_aux Int.mod_add_div_aux\n\n#print Int.emod_add_ediv /-\ntheorem emod_add_ediv : ∀ a b : ℤ, a % b + b * (a / b) = a\n  | (m : ℕ), (n : ℕ) => congr_arg ofNat (Nat.mod_add_div _ _)\n  | (m : ℕ), -[n+1] =>\n    show (_ + -(n + 1) * -(m / (n + 1) : ℕ) : ℤ) = _ by\n      rw [neg_mul_neg] <;> exact congr_arg of_nat (Nat.mod_add_div _ _)\n  | -[m+1], 0 => by rw [mod_zero, Int.div_zero] <;> rfl\n  | -[m+1], (n + 1 : ℕ) => mod_add_div_aux m n.succ\n  | -[m+1], -[n+1] => mod_add_div_aux m n.succ\n#align int.mod_add_div Int.emod_add_ediv\n-/\n\ntheorem div_add_mod (a b : ℤ) : b * (a / b) + a % b = a :=\n  (add_comm _ _).trans (emod_add_ediv _ _)\n#align int.div_add_mod Int.div_add_modₓ\n\ntheorem mod_add_div' (m k : ℤ) : m % k + m / k * k = m :=\n  by\n  rw [mul_comm]\n  exact mod_add_div _ _\n#align int.mod_add_div' Int.mod_add_div'ₓ\n\ntheorem div_add_mod' (m k : ℤ) : m / k * k + m % k = m :=\n  by\n  rw [mul_comm]\n  exact div_add_mod _ _\n#align int.div_add_mod' Int.div_add_mod'ₓ\n\ntheorem mod_def (a b : ℤ) : a % b = a - b * (a / b) :=\n  eq_sub_of_add_eq (emod_add_ediv _ _)\n#align int.mod_def Int.mod_defₓ\n\n/-! ### properties of `/` and `%` -/\n\n\n#print Int.mul_ediv_mul_of_pos /-\n@[simp]\ntheorem mul_ediv_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b / (a * c) = b / c :=\n  suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k from\n    match a, eq_succ_of_zero_lt H, c, eq_nat_or_neg c with\n    | _, ⟨m, rfl⟩, _, ⟨k, Or.inl rfl⟩ => this _ _ _\n    | _, ⟨m, rfl⟩, _, ⟨k, Or.inr rfl⟩ => by\n      rw [mul_neg, Int.div_neg, Int.div_neg] <;> apply congr_arg Neg.neg <;> apply this\n  fun m k b =>\n  match b, k with\n  | (n : ℕ), k => congr_arg ofNat (Nat.mul_div_mul _ _ m.succ_pos)\n  | -[n+1], 0 => by rw [Int.ofNat_zero, MulZeroClass.mul_zero, Int.div_zero, Int.div_zero]\n  | -[n+1], k + 1 =>\n    congr_arg negSucc <|\n      show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ\n        by\n        apply Nat.div_eq_of_lt_le\n        · refine' le_trans _ (Nat.le_add_right _ _)\n          rw [← Nat.mul_div_mul _ _ m.succ_pos]\n          apply Nat.div_mul_le_self\n        · change m.succ * n.succ ≤ _\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#align int.mul_div_mul_of_pos Int.mul_ediv_mul_of_pos\n-/\n\n/- warning: int.mul_div_mul_of_pos_left -> Int.mul_ediv_mul_of_pos_left is a dubious translation:\nlean 3 declaration is\n  forall (a : Int) {b : Int}, (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) b) -> (forall (c : Int), Eq.{1} Int (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.hasDiv) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a b) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) c b)) (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.hasDiv) a c))\nbut is expected to have type\n  forall (a : Int) {b : Int} (H : Int), (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) b) -> (Eq.{1} Int (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.instDivInt_1) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a b) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) H b)) (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.instDivInt_1) a H))\nCase conversion may be inaccurate. Consider using '#align int.mul_div_mul_of_pos_left Int.mul_ediv_mul_of_pos_leftₓ'. -/\n@[simp]\ntheorem mul_ediv_mul_of_pos_left (a : ℤ) {b : ℤ} (H : 0 < b) (c : ℤ) : a * b / (c * b) = a / c := by\n  rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H]\n#align int.mul_div_mul_of_pos_left Int.mul_ediv_mul_of_pos_left\n\n/- warning: int.mul_mod_mul_of_pos -> Int.mul_emod_mul_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {a : Int}, (LT.lt.{0} Int Int.hasLt (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) a) -> (forall (b : Int) (c : Int), Eq.{1} Int (HMod.hMod.{0, 0, 0} Int Int Int (instHMod.{0} Int Int.hasMod) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a b) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a c)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a (HMod.hMod.{0, 0, 0} Int Int Int (instHMod.{0} Int Int.hasMod) b c)))\nbut is expected to have type\n  forall {a : Int} (H : Int) (b : Int), (LT.lt.{0} Int Int.instLTInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) a) -> (Eq.{1} Int (HMod.hMod.{0, 0, 0} Int Int Int (instHMod.{0} Int Int.instModInt_1) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a H) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a (HMod.hMod.{0, 0, 0} Int Int Int (instHMod.{0} Int Int.instModInt_1) H b)))\nCase conversion may be inaccurate. Consider using '#align int.mul_mod_mul_of_pos Int.mul_emod_mul_of_posₓ'. -/\n@[simp]\ntheorem mul_emod_mul_of_pos {a : ℤ} (H : 0 < a) (b c : ℤ) : a * b % (a * c) = a * (b % c) := by\n  rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc]\n#align int.mul_mod_mul_of_pos Int.mul_emod_mul_of_pos\n\ntheorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a := by\n  have := mod_add_div a b <;> rwa [H, zero_add] at this\n#align int.mul_div_cancel_of_mod_eq_zero Int.mul_div_cancel_of_mod_eq_zeroₓ\n\ntheorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a := by\n  rw [mul_comm, mul_div_cancel_of_mod_eq_zero H]\n#align int.div_mul_cancel_of_mod_eq_zero Int.div_mul_cancel_of_mod_eq_zeroₓ\n\n/- warning: int.nat_abs_sign -> Int.natAbs_sign is a dubious translation:\nlean 3 declaration is\n  forall (z : Int), Eq.{1} Nat (Int.natAbs (Int.sign z)) (ite.{1} Nat (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (Int.decidableEq z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))\nbut is expected to have type\n  forall (z : Int), Eq.{1} Nat (Int.natAbs (Int.sign z)) (ite.{1} Nat (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (Int.instDecidableEqInt z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))\nCase conversion may be inaccurate. Consider using '#align int.nat_abs_sign Int.natAbs_signₓ'. -/\ntheorem natAbs_sign (z : ℤ) : z.sign.natAbs = if z = 0 then 0 else 1 := by\n  rcases z with ((_ | _) | _) <;> rfl\n#align int.nat_abs_sign Int.natAbs_sign\n\n#print Int.natAbs_sign_of_nonzero /-\ntheorem natAbs_sign_of_nonzero {z : ℤ} (hz : z ≠ 0) : z.sign.natAbs = 1 := by\n  rw [Int.natAbs_sign, if_neg hz]\n#align int.nat_abs_sign_of_nonzero Int.natAbs_sign_of_nonzero\n-/\n\n#print Int.sign_coe_nat_of_nonzero /-\ntheorem sign_coe_nat_of_nonzero {n : ℕ} (hn : n ≠ 0) : Int.sign n = 1 :=\n  by\n  obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn\n  exact Int.sign_of_succ n\n#align int.sign_coe_nat_of_nonzero Int.sign_coe_nat_of_nonzero\n-/\n\n#print Int.sign_neg /-\n@[simp]\ntheorem sign_neg (z : ℤ) : Int.sign (-z) = -Int.sign z := by rcases z with ((_ | _) | _) <;> rfl\n#align int.sign_neg Int.sign_neg\n-/\n\n/- warning: int.div_sign -> Int.div_sign is a dubious translation:\nlean 3 declaration is\n  forall (a : Int) (b : Int), Eq.{1} Int (HDiv.hDiv.{0, 0, 0} Int Int Int (instHDiv.{0} Int Int.hasDiv) a (Int.sign b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) a (Int.sign b))\nbut is expected to have type\n  forall (a : Int) (b : Int), Eq.{1} Int (Int.div a (Int.sign b)) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) a (Int.sign b))\nCase conversion may be inaccurate. Consider using '#align int.div_sign Int.div_signₓ'. -/\ntheorem div_sign : ∀ a b, a / sign b = a * sign b\n  | a, (n + 1 : ℕ) => by unfold SignType.sign <;> simp\n  | a, 0 => by simp [SignType.sign]\n  | a, -[n+1] => by simp [SignType.sign]\n#align int.div_sign Int.div_sign\n\n#print Int.sign_mul /-\n@[simp]\ntheorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b\n  | a, 0 => by simp\n  | 0, b => by simp\n  | (m + 1 : ℕ), (n + 1 : ℕ) => rfl\n  | (m + 1 : ℕ), -[n+1] => rfl\n  | -[m+1], (n + 1 : ℕ) => rfl\n  | -[m+1], -[n+1] => rfl\n#align int.sign_mul Int.sign_mul\n-/\n\n#print Int.mul_sign /-\ntheorem mul_sign : ∀ i : ℤ, i * sign i = natAbs i\n  | (n + 1 : ℕ) => mul_one _\n  | 0 => MulZeroClass.mul_zero _\n  | -[n+1] => mul_neg_one _\n#align int.mul_sign Int.mul_sign\n-/\n\n#print Int.ofNat_add_negSucc_of_lt /-\ntheorem ofNat_add_negSucc_of_lt {m n : ℕ} (h : m < n.succ) : ofNat m + -[n+1] = -[n - m+1] :=\n  by\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]\n#align int.of_nat_add_neg_succ_of_nat_of_lt Int.ofNat_add_negSucc_of_lt\n-/\n\n/- warning: int.neg_add_neg clashes with int.neg_succ_of_nat_add_neg_succ_of_nat -> Int.negSucc_add_negSucc\nCase conversion may be inaccurate. Consider using '#align int.neg_add_neg Int.negSucc_add_negSuccₓ'. -/\n#print Int.negSucc_add_negSucc /-\n@[simp]\ntheorem negSucc_add_negSucc (m n : ℕ) : -[m+1] + -[n+1] = -[Nat.succ (m + n)+1] :=\n  rfl\n#align int.neg_add_neg Int.negSucc_add_negSucc\n-/\n\n/-! ### to_nat -/\n\n\n/- warning: int.to_nat_eq_max -> Int.toNat_eq_max is a dubious translation:\nlean 3 declaration is\n  forall (a : Int), Eq.{1} Int ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Int.toNat a)) (LinearOrder.max.{0} Int Int.linearOrder a (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))\nbut is expected to have type\n  forall (a : Int), Eq.{1} Int (Nat.cast.{0} Int instNatCastInt (Int.toNat a)) (Max.max.{0} Int Int.instMaxInt a (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))\nCase conversion may be inaccurate. Consider using '#align int.to_nat_eq_max Int.toNat_eq_maxₓ'. -/\ntheorem toNat_eq_max : ∀ a : ℤ, (toNat a : ℤ) = max a 0\n  | (n : ℕ) => (max_eq_left (ofNat_zero_le n)).symm\n  | -[n+1] => (max_eq_right (le_of_lt (negSucc_lt_zero n))).symm\n#align int.to_nat_eq_max Int.toNat_eq_max\n\n#print Int.toNat_zero /-\n@[simp]\ntheorem toNat_zero : (0 : ℤ).toNat = 0 :=\n  rfl\n#align int.to_nat_zero Int.toNat_zero\n-/\n\n#print Int.toNat_one /-\n@[simp]\ntheorem toNat_one : (1 : ℤ).toNat = 1 :=\n  rfl\n#align int.to_nat_one Int.toNat_one\n-/\n\n#print Int.toNat_of_nonneg /-\n@[simp]\ntheorem toNat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (toNat a : ℤ) = a := by\n  rw [to_nat_eq_max, max_eq_left h]\n#align int.to_nat_of_nonneg Int.toNat_of_nonneg\n-/\n\n#print Int.toNat_coe_nat /-\n@[simp]\ntheorem toNat_coe_nat (n : ℕ) : toNat ↑n = n :=\n  rfl\n#align int.to_nat_coe_nat Int.toNat_coe_nat\n-/\n\n#print Int.toNat_coe_nat_add_one /-\n@[simp]\ntheorem toNat_coe_nat_add_one {n : ℕ} : ((n : ℤ) + 1).toNat = n + 1 :=\n  rfl\n#align int.to_nat_coe_nat_add_one Int.toNat_coe_nat_add_one\n-/\n\n#print Int.self_le_toNat /-\ntheorem self_le_toNat (a : ℤ) : a ≤ toNat a := by rw [to_nat_eq_max] <;> apply le_max_left\n#align int.le_to_nat Int.self_le_toNat\n-/\n\n#print Int.le_toNat /-\n@[simp]\ntheorem le_toNat {n : ℕ} {z : ℤ} (h : 0 ≤ z) : n ≤ z.toNat ↔ (n : ℤ) ≤ z := by\n  rw [← Int.ofNat_le, Int.toNat_of_nonneg h]\n#align int.le_to_nat_iff Int.le_toNat\n-/\n\n#print Int.toNat_add /-\ntheorem toNat_add {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : (a + b).toNat = a.toNat + b.toNat :=\n  by\n  lift a to ℕ using ha\n  lift b to ℕ using hb\n  norm_cast\n#align int.to_nat_add Int.toNat_add\n-/\n\n#print Int.toNat_add_nat /-\ntheorem toNat_add_nat {a : ℤ} (ha : 0 ≤ a) (n : ℕ) : (a + n).toNat = a.toNat + n :=\n  by\n  lift a to ℕ using ha\n  norm_cast\n#align int.to_nat_add_nat Int.toNat_add_nat\n-/\n\n#print Int.pred_toNat /-\n@[simp]\ntheorem pred_toNat : ∀ i : ℤ, (i - 1).toNat = i.toNat - 1\n  | (0 : ℕ) => rfl\n  | (n + 1 : ℕ) => by simp\n  | -[n+1] => rfl\n#align int.pred_to_nat Int.pred_toNat\n-/\n\n#print Int.toNat_sub_toNat_neg /-\n@[simp]\ntheorem toNat_sub_toNat_neg : ∀ n : ℤ, ↑n.toNat - ↑(-n).toNat = n\n  | (0 : ℕ) => rfl\n  | (n + 1 : ℕ) => show ↑(n + 1) - (0 : ℤ) = n + 1 from sub_zero _\n  | -[n+1] => show 0 - (n + 1 : ℤ) = _ from zero_sub _\n#align int.to_nat_sub_to_nat_neg Int.toNat_sub_toNat_neg\n-/\n\n#print Int.toNat_add_toNat_neg_eq_natAbs /-\n@[simp]\ntheorem toNat_add_toNat_neg_eq_natAbs : ∀ n : ℤ, n.toNat + (-n).toNat = n.natAbs\n  | (0 : ℕ) => rfl\n  | (n + 1 : ℕ) => show n + 1 + 0 = n + 1 from add_zero _\n  | -[n+1] => show 0 + (n + 1) = n + 1 from zero_add _\n#align int.to_nat_add_to_nat_neg_eq_nat_abs Int.toNat_add_toNat_neg_eq_natAbs\n-/\n\n#print Int.toNat' /-\n/-- If `n : ℕ`, then `int.to_nat' n = some n`, if `n : ℤ` is negative, then `int.to_nat' n = none`.\n-/\ndef toNat' : ℤ → Option ℕ\n  | (n : ℕ) => some n\n  | -[n+1] => none\n#align int.to_nat' Int.toNat'\n-/\n\n#print Int.mem_toNat' /-\ntheorem mem_toNat' : ∀ (a : ℤ) (n : ℕ), n ∈ toNat' a ↔ a = n\n  | (m : ℕ), n => Option.some_inj.trans coe_nat_inj'.symm\n  | -[m+1], n => by constructor <;> intro h <;> cases h\n#align int.mem_to_nat' Int.mem_toNat'\n-/\n\n#print Int.toNat_neg_nat /-\n@[simp]\ntheorem toNat_neg_nat : ∀ n : ℕ, (-(n : ℤ)).toNat = 0\n  | 0 => rfl\n  | n + 1 => rfl\n#align int.to_nat_neg_nat Int.toNat_neg_nat\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/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7923071807368074}}
{"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 topology.continuous_on\n\n/-!\n# Left and right continuity\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 lemmas about left and right continuous functions:\n\n* `continuous_within_at_Ioi_iff_Ici`: two definitions of right continuity\n  (with `(a, ∞)` and with `[a, ∞)`) are equivalent;\n* `continuous_within_at_Iio_iff_Iic`: two definitions of left continuity\n  (with `(-∞, a)` and with `(-∞, a]`) are equivalent;\n* `continuous_at_iff_continuous_left_right`, `continuous_at_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\nopen set filter\nopen_locale topology\n\nsection partial_order\n\nvariables {α β : Type*} [topological_space α] [partial_order α] [topological_space β]\n\nlemma continuous_within_at_Ioi_iff_Ici {a : α} {f : α → β} :\n  continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a :=\nby simp only [← Ici_diff_left, continuous_within_at_diff_self]\n\nlemma continuous_within_at_Iio_iff_Iic {a : α} {f : α → β} :\n  continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a :=\n@continuous_within_at_Ioi_iff_Ici αᵒᵈ _ ‹topological_space α› _ _ _ f\n\nlemma nhds_left'_le_nhds_ne (a : α) :\n  𝓝[<] a ≤ 𝓝[≠] a :=\nnhds_within_mono a (λ y hy, ne_of_lt hy)\n\nlemma nhds_right'_le_nhds_ne (a : α) :\n  𝓝[>] a ≤ 𝓝[≠] a :=\nnhds_within_mono a (λ y hy, ne_of_gt hy)\n\nend partial_order\n\nsection topological_space\n\nvariables {α β : Type*} [topological_space α] [linear_order α] [topological_space β]\n\nlemma nhds_left_sup_nhds_right (a : α) :\n  𝓝[≤] a ⊔ 𝓝[≥] a = 𝓝 a :=\nby rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ]\n\nlemma nhds_left'_sup_nhds_right (a : α) :\n  𝓝[<] a ⊔ 𝓝[≥] a = 𝓝 a :=\nby rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ]\n\nlemma nhds_left_sup_nhds_right' (a : α) :\n  𝓝[≤] a ⊔ 𝓝[>] a = 𝓝 a :=\nby rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ]\n\nlemma nhds_left'_sup_nhds_right' (a : α) :\n  𝓝[<] a ⊔ 𝓝[>] a = 𝓝[≠] a :=\nby rw [← nhds_within_union, Iio_union_Ioi]\n\nlemma continuous_at_iff_continuous_left_right {a : α} {f : α → β} :\n  continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a :=\nby simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right]\n\nlemma continuous_at_iff_continuous_left'_right' {a : α} {f : α → β} :\n  continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a :=\nby rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic,\n  continuous_at_iff_continuous_left_right]\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/algebra/order/left_right.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8670357666736773, "lm_q1q2_score": 0.7921902208937225}}
{"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# `finset X` is a lattice\n\nRecall that a lattice is just a partially ordered set where every pair {a,b} of elements has\nan inf `a ⊓ b` and a sup `a ⊔ b`. The type of finite subsets of `X`, ordered by inclusion,\nhas this property (because the union or intersection of two finite sets is finite).\nThis lattice structure is inbuilt in Lean. \n\n-/\n\n-- Let X be a type\nvariables (X : Type)\n\n-- Assume the law of the excluded middle\nopen_locale classical\n\n-- Don't worry about whether functions are computable\nnoncomputable theory\n\n-- Then, finally, the type of finite subsets of X has a lattice structure \nexample : lattice (finset X) := infer_instance -- the square bracket system knows this\n\nexample (a b : finset X) : finset X := a ⊔ b -- sups (and infs) make sense \n\n-- The lattice also has a `⊥`, the smallest finite subset of `X`, namely the empty set.\n\nexample : finset X := ⊥ \n\n-- But for general `X` it does not have a `⊤`, because if `X` is infinite then it doesn't\n-- have a largest finite subset\n\n-- example : finset X := ⊤ -- error\n\n-- If `Y` is another type, then you can push finsets forward along maps from X to Y\nvariables (Y : Type) (f : X → Y)\n\nexample (S : finset X) : finset Y := finset.image f S \n\n-- See if you can prove these. You'll have to figure out the basic API\n-- for `finset.image`.\n\nexample (S : finset X) (y : Y) : y ∈ S.image f ↔ ∃ x ∈ S, f x = y :=\nbegin\n  apply finset.mem_image,\nend\n\nexample (S : finset X) (x : X) (hx : x ∈ S) : f x ∈ S.image f :=\nbegin\n  apply finset.mem_image_of_mem,\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/section08finiteness/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7921609955603859}}
{"text": "/-\nCopyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Chambert-Loir, María Inés de Frutos-Fernández\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 Mathlib.Algebra.GradedMonoid\nimport Mathlib.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 : σ → M`,\nwhere `σ` are the indeterminates.\n\nA multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials\noccuring in `φ` have the same weighted degree `m`.\n\n## Main definitions/lemmas\n\n* `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect\nto the weights `w`, taking values in `with_bot M`.\n\n* `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree\nof a multivariate polynomial as a function taking values in `M`.\n\n* `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous\nof weighted degree `m` with respect to the weights `w`.\n\n* `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials\nof weighted degree `m`.\n\n* `weightedHomogeneousComponent 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_weightedHomogeneousComponent`: 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 {σ : Type _}\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid M]\n\n/-! ### `weightedDegree'` -/\n\n\n/-- The `weightedDegree'` of the finitely supported function `s : σ →₀ ℕ` is the sum\n  `∑(s i)•(w i)`. -/\ndef weightedDegree' (w : σ → M) : (σ →₀ ℕ) →+ M :=\n  (Finsupp.total σ M ℕ w).toAddMonoidHom\n#align mv_polynomial.weighted_degree' MvPolynomial.weightedDegree'\n\nsection SemilatticeSup\n\nvariable [SemilatticeSup M]\n\n/-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/\ndef weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M :=\n  p.support.sup fun s => weightedDegree' w s\n#align mv_polynomial.weighted_total_degree' MvPolynomial.weightedTotalDegree'\n\n/-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/\ntheorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) :\n    weightedTotalDegree' w p = ⊥ ↔ p = 0 := by\n  simp only [weightedTotalDegree', 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/-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/\ntheorem weightedTotalDegree'_zero (w : σ → M) : weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ :=\n  by simp only [weightedTotalDegree', 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/-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate\n  polynomial as a function taking values in `M`. -/\ndef weightedTotalDegree (w : σ → M) (p : MvPolynomial σ R) : M :=\n  p.support.sup fun s => weightedDegree' w s\n#align mv_polynomial.weighted_total_degree MvPolynomial.weightedTotalDegree\n\n/-- This lemma relates `weightedTotalDegree` and `weightedTotalDegree'`. -/\ntheorem weightedTotalDegree_coe (w : σ → M) (p : MvPolynomial σ R) (hp : p ≠ 0) :\n    weightedTotalDegree' w p = ↑(weightedTotalDegree w p) := by\n  rw [Ne.def, ← weightedTotalDegree'_eq_bot_iff w p, ← Ne.def, WithBot.ne_bot_iff_exists] at hp\n  obtain ⟨m, hm⟩ := hp\n  apply le_antisymm\n  · simp only [weightedTotalDegree, weightedTotalDegree', Finset.sup_le_iff, WithBot.coe_le_coe]\n    intro b\n    exact Finset.le_sup\n  · simp only [weightedTotalDegree]\n    have hm' : weightedTotalDegree' w p ≤ m := le_of_eq hm.symm\n    rw [← hm]\n    simpa [weightedTotalDegree'] using hm'\n#align mv_polynomial.weighted_total_degree_coe MvPolynomial.weightedTotalDegree_coe\n\n/-- The `weightedTotalDegree` of the zero polynomial is `⊥`. -/\ntheorem weightedTotalDegree_zero (w : σ → M) : weightedTotalDegree w (0 : MvPolynomial σ R) = ⊥ :=\n  by simp only [weightedTotalDegree, support_zero, Finset.sup_empty]\n#align mv_polynomial.weighted_total_degree_zero MvPolynomial.weightedTotalDegree_zero\n\ntheorem le_weightedTotalDegree (w : σ → M) {φ : MvPolynomial σ R} {d : σ →₀ ℕ}\n    (hd : d ∈ φ.support) : weightedDegree' w d ≤ φ.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/-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials\n  occuring in `φ` have weighted degree `m`. -/\ndef IsWeightedHomogeneous (w : σ → M) (φ : MvPolynomial σ R) (m : M) : Prop :=\n  ∀ ⦃d⦄, coeff d φ ≠ 0 → weightedDegree' w d = m\n#align mv_polynomial.is_weighted_homogeneous MvPolynomial.IsWeightedHomogeneous\n\nvariable (R)\n\n/-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/\ndef weightedHomogeneousSubmodule (w : σ → M) (m : M) : Submodule R (MvPolynomial σ R) 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 ≠ 0 ∨ coeff c b ≠ 0 := by\n      contrapose! hc\n      simp only [hc, add_zero]\n    · exact ha h\n    · exact hb h\n#align mv_polynomial.weighted_homogeneous_submodule MvPolynomial.weightedHomogeneousSubmodule\n\n@[simp]\ntheorem mem_weightedHomogeneousSubmodule (w : σ → M) (m : M) (p : MvPolynomial σ R) :\n    p ∈ weightedHomogeneousSubmodule R w m ↔ p.IsWeightedHomogeneous w m :=\n  Iff.rfl\n#align mv_polynomial.mem_weighted_homogeneous_submodule MvPolynomial.mem_weightedHomogeneousSubmodule\n\n/-- The submodule `weightedHomogeneousSubmodule R w m` of homogeneous `MvPolynomial`s of\n  degree `n` is equal to the `R`-submodule of all `p : (σ →₀ ℕ) →₀ R` such that\n  `p.support ⊆ {d | weightedDegree' w d = m}`. While equal, the former has a\n  convenient definitional reduction. -/\n\n\nvariable {R}\n\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 : σ → M) (m n : M) :\n    weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n ≤\n      weightedHomogeneousSubmodule R w (m + n) := by\n  rw [Submodule.mul_le]\n  intro φ hφ ψ hψ c hc\n  rw [coeff_mul] at hc\n  obtain ⟨⟨d, e⟩, hde, H⟩ := Finset.exists_ne_zero_of_sum_ne_zero hc\n  have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0 := by\n    contrapose! H\n    by_cases h : coeff d φ = 0 <;>\n      simp_all only [Ne.def, not_false_iff, MulZeroClass.zero_mul, MulZeroClass.mul_zero]\n  rw [← Finsupp.mem_antidiagonal.mp hde, ← hφ aux.1, ← hψ aux.2, map_add]\n#align mv_polynomial.weighted_homogeneous_submodule_mul MvPolynomial.weightedHomogeneousSubmodule_mul\n\n/-- Monomials are weighted homogeneous. -/\ntheorem isWeightedHomogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M}\n    (hm : weightedDegree' w d = m) : IsWeightedHomogeneous w (monomial d r) m := by\n  intro c hc\n  rw [coeff_monomial] at hc\n  split_ifs at hc with h\n  · subst c\n    exact hm\n  · contradiction\n#align mv_polynomial.is_weighted_homogeneous_monomial MvPolynomial.isWeightedHomogeneous_monomial\n\n/-- A polynomial of weightedTotalDegree `⊥` is weighted_homogeneous of degree `⊥`. -/\ntheorem isWeightedHomogeneous_of_total_degree_zero [SemilatticeSup M] [OrderBot M] (w : σ → M)\n    {p : MvPolynomial σ R} (hp : weightedTotalDegree w p = (⊥ : M)) :\n    IsWeightedHomogeneous w p (⊥ : M) := by\n  intro d hd\n  have h := weightedTotalDegree_coe w p (MvPolynomial.ne_zero_iff.mpr ⟨d, hd⟩)\n  simp only [weightedTotalDegree', hp] at h\n  rw [eq_bot_iff, ← WithBot.coe_le_coe, ← h]\n  apply 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/-- Constant polynomials are weighted homogeneous of degree 0. -/\ntheorem isWeightedHomogeneous_C (w : σ → M) (r : R) :\n    IsWeightedHomogeneous w (C r : MvPolynomial σ R) 0 :=\n  isWeightedHomogeneous_monomial _ _ _ (map_zero _)\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.is_weighted_homogeneous_C MvPolynomial.isWeightedHomogeneous_C\n\nvariable (R)\n\n/-- 0 is weighted homogeneous of any degree. -/\ntheorem isWeightedHomogeneous_zero (w : σ → M) (m : M) :\n    IsWeightedHomogeneous w (0 : MvPolynomial σ R) m :=\n  (weightedHomogeneousSubmodule R w m).zero_mem\n#align mv_polynomial.is_weighted_homogeneous_zero MvPolynomial.isWeightedHomogeneous_zero\n\n/-- 1 is weighted homogeneous of degree 0. -/\ntheorem isWeightedHomogeneous_one (w : σ → M) : IsWeightedHomogeneous w (1 : MvPolynomial σ R) 0 :=\n  isWeightedHomogeneous_C _ _\n#align mv_polynomial.is_weighted_homogeneous_one MvPolynomial.isWeightedHomogeneous_one\n\n/-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/\ntheorem isWeightedHomogeneous_X (w : σ → M) (i : σ) :\n    IsWeightedHomogeneous w (X i : MvPolynomial σ R) (w i) := by\n  apply isWeightedHomogeneous_monomial\n  simp only [weightedDegree', LinearMap.toAddMonoidHom_coe, total_single, one_nsmul]\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.is_weighted_homogeneous_X MvPolynomial.isWeightedHomogeneous_X\n\nnamespace IsWeightedHomogeneous\n\nvariable {R}\n\nvariable {φ ψ : MvPolynomial σ R} {m n : M}\n\n/-- The weighted degree of a weighted homogeneous polynomial controls its support. -/\ntheorem coeff_eq_zero {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (d : σ →₀ ℕ)\n    (hd : weightedDegree' w d ≠ n) : coeff d φ = 0 := by\n  have aux := mt (@hφ 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/-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/\ntheorem inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : IsWeightedHomogeneous w φ m)\n    (hn : IsWeightedHomogeneous w φ n) : m = n := by\n  obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ\n  rw [← hm hd, ← hn hd]\n#align mv_polynomial.is_weighted_homogeneous.inj_right MvPolynomial.IsWeightedHomogeneous.inj_right\n\n/-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\ntheorem add {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (hψ : IsWeightedHomogeneous w ψ n) :\n    IsWeightedHomogeneous w (φ + ψ) n :=\n  (weightedHomogeneousSubmodule R w n).add_mem hφ hψ\n#align mv_polynomial.is_weighted_homogeneous.add MvPolynomial.IsWeightedHomogeneous.add\n\n/-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\ntheorem sum {ι : Type _} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : M) {w : σ → M}\n    (h : ∀ i ∈ s, IsWeightedHomogeneous w (φ i) n) : IsWeightedHomogeneous w (∑ i in s, φ i) n :=\n  (weightedHomogeneousSubmodule R w n).sum_mem h\n#align mv_polynomial.is_weighted_homogeneous.sum MvPolynomial.IsWeightedHomogeneous.sum\n\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 : σ → M} (hφ : IsWeightedHomogeneous w φ m) (hψ : IsWeightedHomogeneous w ψ n) :\n    IsWeightedHomogeneous w (φ * ψ) (m + n) :=\n  weightedHomogeneousSubmodule_mul w m n <| Submodule.mul_mem_mul hφ hψ\n#align mv_polynomial.is_weighted_homogeneous.mul MvPolynomial.IsWeightedHomogeneous.mul\n\n/-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree\n  equal to the sum of the weighted degrees. -/\ntheorem prod {ι : Type _} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → M) {w : σ → M} :\n    (∀ i ∈ s, IsWeightedHomogeneous w (φ i) (n i)) →\n      IsWeightedHomogeneous w (∏ i in s, φ i) (∑ i in s, n i) := by\n  refine Finset.induction_on s ?_ ?_\n  · intro\n    simp only [isWeightedHomogeneous_one, Finset.sum_empty, Finset.prod_empty]\n  · 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/-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree\n  `n`. -/\ntheorem weighted_total_degree [SemilatticeSup M] {w : σ → M} (hφ : IsWeightedHomogeneous w φ n)\n    (h : φ ≠ 0) : weightedTotalDegree' w φ = n := by\n  simp only [weightedTotalDegree']\n  apply le_antisymm\n  · simp only [Finset.sup_le_iff, mem_support_iff, WithBot.coe_le_coe]\n    exact fun d hd => le_of_eq (hφ hd)\n  · obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h\n    simp only [← hφ hd, Finsupp.sum]\n    replace hd := Finsupp.mem_support_iff.mpr hd\n    apply Finset.le_sup hd\n#align mv_polynomial.is_weighted_homogeneous.weighted_total_degree MvPolynomial.IsWeightedHomogeneous.weighted_total_degree\n\n/-- The weighted homogeneous submodules form a graded monoid. -/\ninstance WeightedHomogeneousSubmodule.gcomm_monoid {w : σ → M} :\n    SetLike.GradedMonoid (weightedHomogeneousSubmodule R w) where\n  one_mem := isWeightedHomogeneous_one R w\n  mul_mem _ _ _ _ := IsWeightedHomogeneous.mul\n#align mv_polynomial.is_weighted_homogeneous.weighted_homogeneous_submodule.gcomm_monoid MvPolynomial.IsWeightedHomogeneous.WeightedHomogeneousSubmodule.gcomm_monoid\n\nend IsWeightedHomogeneous\n\nvariable {R}\n\n/-- `weightedHomogeneousComponent w n φ` is the part of `φ` that is weighted homogeneous of\n  weighted degree `n`, with respect to the weights `w`.\n  See `sum_weightedHomogeneousComponent` for the statement that `φ` is equal to the sum\n  of all its weighted homogeneous components. -/\ndef weightedHomogeneousComponent (w : σ → M) (n : M) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R :=\n  (Submodule.subtype _).comp <| Finsupp.restrictDom _ _ { d | weightedDegree' w d = n }\n#align mv_polynomial.weighted_homogeneous_component MvPolynomial.weightedHomogeneousComponent\n\nsection WeightedHomogeneousComponent\n\nvariable {w : σ → M} (n : M) (φ ψ : MvPolynomial σ R)\n\ntheorem coeff_weightedHomogeneousComponent (d : σ →₀ ℕ) :\n    coeff d (weightedHomogeneousComponent w n φ) =\n      if weightedDegree' w d = n then coeff d φ else 0 :=\n  Finsupp.filter_apply (fun d : σ →₀ ℕ => weightedDegree' w d = n) φ d\n#align mv_polynomial.coeff_weighted_homogeneous_component MvPolynomial.coeff_weightedHomogeneousComponent\n\ntheorem weightedHomogeneousComponent_apply :\n    weightedHomogeneousComponent w n φ =\n      ∑ d in φ.support.filter fun d => weightedDegree' w d = n, monomial d (coeff d φ) :=\n  Finsupp.filter_eq_sum (fun d : σ →₀ ℕ => weightedDegree' w d = n) φ\n#align mv_polynomial.weighted_homogeneous_component_apply MvPolynomial.weightedHomogeneousComponent_apply\n\n/-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of\nweighted degree `n`. -/\ntheorem weightedHomogeneousComponent_isWeightedHomogeneous :\n    (weightedHomogeneousComponent w n φ).IsWeightedHomogeneous w n := by\n  intro d hd\n  contrapose! hd\n  rw [coeff_weightedHomogeneousComponent, if_neg hd]\n#align mv_polynomial.weighted_homogeneous_component_is_weighted_homogeneous MvPolynomial.weightedHomogeneousComponent_isWeightedHomogeneous\n\n@[simp]\ntheorem weightedHomogeneousComponent_C_mul (n : M) (r : R) :\n    weightedHomogeneousComponent w n (C r * φ) = C r * weightedHomogeneousComponent w n φ := by\n  simp only [C_mul', LinearMap.map_smul]\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.weighted_homogeneous_component_C_mul MvPolynomial.weightedHomogeneousComponent_C_mul\n\ntheorem weightedHomogeneousComponent_eq_zero'\n    (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → weightedDegree' w d ≠ n) :\n    weightedHomogeneousComponent w n φ = 0 := by\n  rw [weightedHomogeneousComponent_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\ntheorem weightedHomogeneousComponent_eq_zero [SemilatticeSup M] [OrderBot M]\n    (h : weightedTotalDegree w φ < n) : weightedHomogeneousComponent w n φ = 0 := by\n  rw [weightedHomogeneousComponent_apply, sum_eq_zero]\n  intro d hd\n  have := @Finset.mem_filter _ _\n      (fun a => propDecidable ((fun d => weightedDegree' w d = n) a)) (support φ)\n  rw [this] at hd\n  exfalso\n  apply lt_irrefl n\n  nth_rw 1 [← hd.2]\n  exact lt_of_le_of_lt (le_weightedTotalDegree w hd.1) h\n#align mv_polynomial.weighted_homogeneous_component_eq_zero MvPolynomial.weightedHomogeneousComponent_eq_zero\n\ntheorem weightedHomogeneousComponent_finsupp :\n    (Function.support fun m => weightedHomogeneousComponent w m φ).Finite := by\n  suffices\n    (Function.support fun m => weightedHomogeneousComponent w m φ) ⊆\n      (fun d => weightedDegree' w d) '' φ.support by\n    exact Finite.subset ((fun d : σ →₀ ℕ => (weightedDegree' w) d) '' ↑(support φ)).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 weightedHomogeneousComponent_eq_zero' m φ hm'\n#align mv_polynomial.weighted_homogeneous_component_finsupp MvPolynomial.weightedHomogeneousComponent_finsupp\n\nvariable (w)\n\n/-- Every polynomial is the sum of its weighted homogeneous components. -/\ntheorem sum_weightedHomogeneousComponent :\n    (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by\n  rw [finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)]\n  ext1 d\n  simp only [coeff_sum, coeff_weightedHomogeneousComponent]\n  rw [Finset.sum_eq_single (weightedDegree' w d)]\n  · rw [if_pos rfl]\n  · intro m _ hm'\n    rw [if_neg hm'.symm]\n  · intro hm\n    rw [if_pos rfl]\n    simp only [Finite.mem_toFinset, mem_support, Ne.def, Classical.not_not] at hm\n    have := coeff_weightedHomogeneousComponent (w := w) (weightedDegree' w d) φ 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/-- The weighted homogeneous components of a weighted homogeneous polynomial. -/\ntheorem weightedHomogeneousComponent_weighted_homogeneous_polynomial (m n : M)\n    (p : MvPolynomial σ R) (h : p ∈ weightedHomogeneousSubmodule R w n) :\n    weightedHomogeneousComponent w m p = if m = n then p else 0 := by\n  simp only [mem_weightedHomogeneousSubmodule] at h\n  ext x\n  rw [coeff_weightedHomogeneousComponent]\n  by_cases zero_coeff : coeff x p = 0\n  · split_ifs\n    all_goals simp only [zero_coeff, coeff_zero]\n  · rw [h zero_coeff]\n    simp only [show n = m ↔ m = n from eq_comm]\n    split_ifs with h1\n    · rfl\n    · 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 : σ → M} (φ : MvPolynomial σ R)\n\n/-- If `M` is a `CanonicallyOrderedAddMonoid`, then the `weightedHomogeneousComponent`\n  of weighted degree `0` of a polynomial is its constant coefficient. -/\n@[simp]\ntheorem weightedHomogeneousComponent_zero [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) :\n    weightedHomogeneousComponent w 0 φ = C (coeff 0 φ) := by\n  ext1 d\n  rcases Classical.em (d = 0) with (rfl | hd)\n  · simp only [coeff_weightedHomogeneousComponent, if_pos, map_zero, coeff_zero_C]\n  · rw [coeff_weightedHomogeneousComponent, if_neg, coeff_C, if_neg (Ne.symm hd)]\n    simp only [weightedDegree', 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 [FunLike.ext_iff, Finsupp.coe_zero, Pi.zero_apply, not_forall] at hd\n    obtain ⟨i, hi⟩ := hd\n    exact ⟨i, hi, hw i⟩\n#align mv_polynomial.weighted_homogeneous_component_zero MvPolynomial.weightedHomogeneousComponent_zero\n\nend CanonicallyOrderedAddMonoid\n\nend MvPolynomial\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/MvPolynomial/WeightedHomogeneous.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480347, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7920432234143958}}
{"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.nat.choose\nimport algebra.prod_equiv\nimport tactic.squeeze\n\n/-\n Consider the identity\n (choose n k) =  (choose k-1 k-1) + (choose k k-1) + ... + (choose n-1 k-1)\n\n or \n (choose n+1 k+1) = (choose k k) + (choose k+1 k) + ... + (choose n k)\n This can be proved algebraically by induction.   \n Alternatively, we can consider the set (P n k) of \n subsets A of size k in {0,..,n-1}, so |(P n k)| = (choose n k).\n We can split this set up according to the value of (max A),\n and recover a combinatorial proof of the identity.\n\n-/\n\nlemma choose_sum' (k m : ℕ) : \n nat.choose (k + m) (k + 1) = \n  (finset.range m).sum (λ i, nat.choose (k + i) k) := \nbegin\n induction m with m ih,\n {rw[finset.range_zero,finset.sum_empty,add_zero,nat.choose_succ_self]},\n {rw[finset.sum_range_succ,← ih,nat.add_succ,nat.choose, add_comm],}\nend\n\nlemma choose_sum (n k : ℕ) : \n nat.choose n.succ k.succ = (finset.Ico k n.succ).sum (λ i, nat.choose i k) :=\nbegin\n by_cases h : k ≤ n.succ,\n { let m := n.succ - k,\n   have : n.succ = k + m := by rw [add_comm, nat.sub_add_cancel h],\n   rw [this] at h ⊢, \n   rw [choose_sum' k m],\n   let f : ℕ → ℕ := λ p, nat.choose p k,\n   let g : ℕ → ℕ := has_add.add k,\n   change (finset.range m).sum (λ i, f (g i)) = (finset.Ico k (k + m)).sum f,\n   rw [← @finset.sum_image ℕ ℕ ℕ f _ _ (finset.range m) g\n       (λ _ _ _ _, nat.add_left_cancel)],\n   have : finset.range m = finset.Ico 0 m := \n   begin\n     ext i,\n     simp only [finset.mem_range, finset.mem_Ico, nat.zero_le i, true_and]\n   end,\n   rw [this], \n   have := finset.image_add_left_Ico 0 m k,\n   rw[add_zero] at this, rw[← this]},\n  { have : finset.Ico k n.succ = ∅ := \n     finset.Ico_eq_empty_iff.mpr (λ h₀, h (le_of_lt h₀)),\n    rw[this, finset.sum_empty],\n    rw [nat.choose_eq_zero_of_lt (lt_trans (lt_of_not_ge h) k.lt_succ_self)] }\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/combinatorics/binomial_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850057480346, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7920432215961524}}
{"text": "/-\nCopyright (c) 2022 Georgi Kocharyan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.txt.\nAuthor: Georgi Kocharyan.\n-/\n\nimport .quasiisometry\nimport tactic\nimport data.real.basic \nimport topology.metric_space.isometry\n\nvariables {X : Type*} [pseudo_metric_space X]\n\ndef geodesic {X : Type*} [pseudo_metric_space X] (L : ℝ) (Lnonneg : L ≥ 0) (f: ((set.Icc) (0 : ℝ) L) → X) (x : X) (y: X) :=\n f (⟨0, le_rfl, Lnonneg⟩) = x ∧ f (⟨L, Lnonneg, le_rfl⟩) = y ∧ isometry f\n\ndef conn_by_geodesic {X : Type*} [pseudo_metric_space X] (x : X) (y: X) : Prop :=\n∃ (L : ℝ) (Lpos : L ≥ 0) (f: ((set.Icc) (0 : ℝ) L) → X), geodesic L Lpos f x y\n\nclass geodesic_space (β : Type*)  extends pseudo_metric_space β := \n(geodesics: ∀ x y : β, conn_by_geodesic x y)\n\n-- def quasigeodesic {X : Type*} [pseudo_metric_space X] (L : ℝ) (Lnonneg : L ≥ 0) (f: ((set.Icc) (0 : ℝ) L) → X)\n--  (x : X) (y: X) (c : ℝ) (b : ℝ) :=\n--  f (⟨0, le_rfl, Lnonneg⟩) = x ∧ f (⟨L, Lnonneg, le_rfl⟩) = y ∧ is_QIE' f c b\n\ndef quasigeodesic {X : Type*} [pseudo_metric_space X] (L : ℝ) (Lnonneg : L ≥ 0) (f: ℝ → X)\n (x : X) (y: X) (c : ℝ) (b : ℝ) :=\n f 0 = x ∧ f L = y ∧ (∀ m n  ∈ {x : ℝ| 0 ≤ x ∧ x ≤ L}, (1/c)*(abs (m-n)) - b ≤ dist (f m) (f n) ∧ dist (f m) (f n) ≤ c * (abs (m-n)) + b)\n\n-- any segment of a quasigeodesic is also a quasigeodesic\n\nlemma trunc_quasigeodesic {X : Type*} [pseudo_metric_space X] (L : ℝ) (Lnonneg : L ≥ 0) (f: ℝ → X)\n (x : X) (y: X) (c : ℝ) (b : ℝ) {L' : ℝ} (hL' : L' ≤ L) (L'nonneg : L' ≥ 0) (hf : quasigeodesic L Lnonneg f x y c b)\n  : quasigeodesic L' L'nonneg f x (f L') c b :=\nbegin\nsplit,\nexact hf.1,\nsplit, refl,\nintros a ha b hb,\nhave ha' : a ∈ {x : ℝ| 0 ≤ x ∧ x ≤ L},\n  { exact ⟨ha.1, le_trans ha.2 hL'⟩, },\nhave hb' : b ∈ {x : ℝ| 0 ≤ x ∧ x ≤ L},\n  { exact ⟨hb.1, le_trans hb.2 hL'⟩,},\napply (hf.2).2 a ha' b hb',\nend\n\n-- if a geodesic has length 0, the endpoints are the same\n\nlemma degenerate_quasigeodesic {X : Type*} [pseudo_metric_space X] (f: ℝ → X)\n (x : X) (y: X) (c : ℝ) (b : ℝ) (hf : quasigeodesic 0 (le_refl 0) f x y c b) : x = y :=\n eq.trans (hf.1.symm) hf.2.1\n\n\ndefinition fpi (L : ℝ) (Lpos : L ≥ 0) (f: ((set.Icc) (0 : ℝ) L) → X) : Π (a : ℝ),(a ≥ 0 ∧ a ≤ L) → X :=\nbegin\nintros a ha,\ncases ha with h1 h2,\nexact f(⟨a, h1, h2 ⟩),\nend\n\n\ndef conn_by_quasigeodesic {X : Type*} [pseudo_metric_space X] (x : X) (y: X) : Prop :=\n∃ (L : ℝ) (Lnonneg : L ≥ 0) (f: ℝ → X) (c : ℝ) (b : ℝ), quasigeodesic L Lnonneg f x y c b\n\ndef conn_by_quasigeodesic' {X : Type*} [pseudo_metric_space X] (x : X) (y: X) (c : ℝ) (b : ℝ) : Prop :=\n∃ (L : ℝ) (Lnonneg : L ≥ 0) (f: ℝ → X) , quasigeodesic L Lnonneg f x y c b\n\nclass quasigeodesic_space (β : Type*) (c : ℝ) (b : ℝ) (cpos: c > 0) (bnonneg: b ≥ 0)  extends pseudo_metric_space β := \n(quasigeodesics: ∀ x y : β, conn_by_quasigeodesic' x y c b)\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/geodesicspace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642019, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7919914194134978}}
{"text": "import ..prooflab\nimport lectures.lec6_proposition\n\n\n/-! # Homework 5: ...\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 -/\n\n\nnamespace PROOFS\n\n/-! ## Question 1 (20 points): \n(**Part I**) Give a proof of the following propositional formula. \n-/\n\n\ntheorem  disj_conj {P Q R : Prop} : \n  (P ∨ Q → R) ↔ (P → R) ∧ (Q → R) :=\nbegin\n  sorry,\nend \n\n/-\n(**Part II**) In `lec6_proposition` we proved that \n`P ∨ Q → ¬ P → Q`. The proof was `resolve_right`. \n\nUse the previous theorem (`disj_conj`) to give a new proof of `P ∨ Q → ¬ P → Q`. \n-/\n\ntheorem resolve_right_alt {P Q : Prop} : \n P ∨ Q → ¬ P → Q :=\nbegin\n  sorry,  \nend \n\n\n\n\n\n/-! ## Question 2 (20 points): \nGive a proof of the following statement. \n-/\nexample (a b c : ℝ) (h₁ : c * a ≤ c * b) (h₂ : ¬ b ≤ a) : \n  c * a ≤ c * b ∧ a ≠ b :=\nbegin\n  sorry, \nend\n\n\n\n\n\n\n/-! ## Question 3 (20 points): \nGive a proof of the following statements using only lemmas `neg_neg`, `neg_lt`, `neg_le`. The first one states that negation flips the strict order (<) , and the second one states that negation flips the order (≤).\n-/\n\nlemma lt_rev_of_neg {x y : ℝ} (h : x < y) \n  : - y < - x := \nbegin\n  sorry,  \nend   \n\n\n\nlemma le_rev_of_neg {x y : ℝ} (h : x ≤ y) \n  : - y ≤ - x := \nbegin\n  sorry, \nend \n\n\n\n\n\n\n/-! ## Question 4 (20 points): \nUse the two lemmas `lt_rev_of_neg` and `le_rev_of_neg` above together with some/all of the following lemmas to prove the following statement. \n-/\n\n#check le_or_gt\n#check abs_of_nonneg\n#check abs_of_neg \n#check neg_neg\n#check lt_of_lt_of_le\n#check lt_of_le_of_lt\n#check le_trans\n#check lt_trans\n\n\nexample (x y : ℝ ) : \n  abs x < y ↔ - y < x ∧ x < y :=\nbegin\n  sorry, \nend\n\n\n\n\n\n\n/-! ## Question 5 (20 points): -/\n\n\ndef EM (P : Prop) := \nP ∨ ¬ P\n\n#check EM \n\ndef DN (P : Prop) :=\n(¬ P → false) → P \n\n#check DN \n\n\n\ntheorem excluded_implies_double_negation  {P : Prop} : EM P → DN P := \nbegin \n unfold EM, \n unfold DN, \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/hw5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7919914158493807}}
{"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\" (`∧`)\n\nWe learn about how to manipulate `P ∧ 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### The `cases` tactic\n\nIf `h : P ∧ Q` is a hypothesis, then `cases h with hP hQ,`\ndecomposes it into two hypotheses `hP : P` and `hQ : Q`.\n\n### The `split` tactic\n\nIf `⊢ P ∧ Q` is in the goal, The `split` tactic will turn it into\ntwo goals, `⊢ P` and `⊢ Q`. NB tactics operate on the first goal only.\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : P ∧ Q → P :=\nbegin\n  sorry\nend\n\nexample : P ∧ Q → Q :=\nbegin\n  sorry\nend\n\nexample : (P → Q → R) → (P ∧ Q → R) :=\nbegin\n  sorry\nend\n\nexample : P → Q → P ∧ Q :=\nbegin\n  sorry\nend\n\n/-- `∧` is symmetric -/\nexample : P ∧ Q → Q ∧ P :=\nbegin\n  sorry\nend\n\nexample : P → P ∧ true :=\nbegin\n  sorry\nend\n\nexample : false → P ∧ false :=\nbegin\n  sorry\nend\n\n/-- `∧` is transitive -/\nexample : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  sorry,\nend\n\nexample : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  sorry,\nend\n\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/2021/logic/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426831, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.791991410673067}}
{"text": "-- BOTH:\nimport data.real.basic\n\n/- TEXT:\nCalculating\n-----------\n\nWe generally learn to carry out mathematical calculations\nwithout thinking of them as proofs.\nBut when we justify each step in a calculation,\nas Lean requires us to do,\nthe net result is a proof that the left-hand side of the calculation\nis equal to the right-hand side.\n\n.. index:: rewrite, rw, tactics ; rw and rewrite\n\nIn Lean, stating a theorem is tantamount to stating a goal,\nnamely, the goal of proving the theorem.\nLean provides the ``rewrite`` tactic, abbreviated ``rw``,\nto replace the left-hand side of an identity by the right-hand side\nin the goal. If ``a``, ``b``, and ``c`` are real numbers,\n``mul_assoc a b c``  is the identity ``a * b * c = a * (b * c)``\nand ``mul_comm a b`` is the identity ``a * b = b * a``.\nLean provides automation that generally eliminates the need\nto refer the facts like these explicitly,\nbut they are useful for the purposes of illustration.\nIn Lean, multiplication associates to the left,\nso the left-hand side of ``mul_assoc`` could also be written ``(a * b) * c``.\nHowever, it is generally good style to be mindful of Lean's\nnotational conventions and leave out parentheses when Lean does as well.\n\nLet's try out ``rw``.\n\n.. index:: real numbers\nTEXT. -/\n/- An example. -/\n\n-- QUOTE:\nimport data.real.basic\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c\nend\n-- QUOTE.\n\n/- TEXT:\nThe ``import`` line at the beginning of the example\nimports the theory of the real numbers from ``mathlib``.\nFor the sake of brevity,\nwe generally suppress information like this when it\nis repeated from example to example.\nClicking the ``try it!`` button displays the full\nexample as it is meant to be processed and checked by Lean.\n\nYou are welcome to make changes to see what happens.\nYou can type the ``ℝ`` character as ``\\R`` or ``\\real``\nin VS Code.\nThe symbol doesn't appear until you hit space or the tab key.\nIf you hover over a symbol when reading a Lean file,\nVS Code will show you the syntax that can be used to enter it.\nIf your keyboard does not have an easily accessible backslash,\nyou can change the leading character by changing the\n``lean.input.leader`` setting.\n\n.. index:: proof state, local context, goal\n\nWhen a cursor is in the middle of a tactic proof,\nLean reports on the current *proof state* in the\n*Lean infoview* window.\nAs you move your cursor past each step of the proof,\nyou can see the state change.\nA typical proof state in Lean might look as follows:\n\n.. code-block::\n\n    1 goal\n    x y : ℕ,\n    h₁ : prime x,\n    h₂ : ¬even x,\n    h₃ : y > x\n    ⊢ y ≥ 4\n\nThe lines before the one that begins with ``⊢`` denote the *context*:\nthey are the objects and assumptions currently at play.\nIn this example, these include two objects, ``x`` and ``y``,\neach a natural number.\nThey also include three assumptions,\nlabelled ``h₁``, ``h₂``, and ``h₃``.\nIn Lean, everything in a context is labelled with an identifier.\nYou can type these subscripted labels as ``h\\1``, ``h\\2``, and ``h\\3``,\nbut any legal identifiers would do:\nyou can use ``h1``, ``h2``, ``h3`` instead,\nor ``foo``, ``bar``, and ``baz``.\nThe last line represents the *goal*,\nthat is, the fact to be proved.\nSometimes people use *target* for the fact to be proved,\nand *goal* for the combination of the context and the target.\nIn practice, the intended meaning is usually clear.\n\nTry proving these identities,\nin each case replacing ``sorry`` by a tactic proof.\nWith the ``rw`` tactic, you can use a left arrow (``\\l``)\nto reverse an identity.\nFor example, ``rw ← mul_assoc a b c``\nreplaces ``a * (b * c)`` by ``a * b * c`` in the current goal.\nTEXT. -/\n/- Try these.-/\n\n-- QUOTE:\nexample (a b c : ℝ) : (c * b) * a = b * (a * c) :=\nbegin\n  sorry\nend\n\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (a b c : ℝ) : (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 : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ←mul_assoc a b c,\n  rw mul_comm a b,\n  rw mul_assoc b a c\nend\n\n/- TEXT:\nYou can also use identities like ``mul_assoc`` and ``mul_comm`` without arguments.\nIn this case, the rewrite tactic tries to match the left-hand side with\nan expression in the goal,\nusing the first pattern it finds.\nTEXT. -/\n/- An example. -/\n\n-- QUOTE:\nexample (a b c : ℝ) : a * b * c = b * c * a :=\nbegin\n  rw mul_assoc,\n  rw mul_comm\nend\n-- QUOTE.\n\n/- TEXT:\nYou can also provide *partial* information.\nFor example, ``mul_comm a`` matches any pattern of the form\n``a * ?`` and rewrites it to ``? * a``.\nTry doing the first of these examples without\nproviding any arguments at all,\nand the second with only one argument.\nTEXT. -/\n/- Try doing the first of these without providing any arguments at all,\n   and the second with only one argument. -/\n\n-- QUOTE:\nexample (a b c : ℝ) : a * (b * c) = b * (c * a) :=\nbegin\n  sorry\nend\n\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (a b c : ℝ) : a * (b * c) = b * (c * a) :=\nbegin\n  rw mul_comm,\n  rw mul_assoc\nend\n\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ←mul_assoc,\n  rw mul_comm a,\n  rw mul_assoc\nend\n\n/- TEXT:\nYou an also use ``rw`` with facts from the local context.\nTEXT. -/\n/- Using facts from the local context. -/\n\n-- QUOTE:\nexample (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :\n  a * (b * e) = c * (d * f) :=\nbegin\n  rw h',\n  rw ←mul_assoc,\n  rw h,\n  rw mul_assoc\nend\n-- QUOTE.\n\n/- TEXT:\nTry these:\nTEXT. -/\n/- Try these. For the second one, use the theorem `sub_self`. -/\n\n-- QUOTE:\nexample (a b c d e f : ℝ) (h : b * c = e * f) :\n  a * b * c * d = a * e * f * d :=\nbegin\n  sorry\nend\n\nexample (a b c d : ℝ) (hyp : c = b * a - d) (hyp' : d = a * b) : c = 0 :=\nbegin\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (a b c d e f : ℝ) (h : b * c = e * f) :\n  a * b * c * d = a * e * f * d :=\nbegin\n  rw mul_assoc a,\n  rw h,\n  rw ←mul_assoc\nend\n\nexample (a b c d : ℝ) (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\n/- TEXT:\nFor the second one, you can use the theorem ``sub_self``,\nwhere ``sub_self a`` is the identity ``a - a = 0``.\n\nWe now introduce some useful features of Lean.\nFirst, multiple rewrite commands can be carried out\nwith a single command,\nby listing the relevant identities within square brackets.\nSecond, when a tactic proof is just a single command,\nwe can replace the ``begin ... end`` block with a ``by``.\nTEXT. -/\n/- Examples. -/\n\n-- QUOTE:\nexample (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :\n  a * (b * e) = c * (d * f) :=\nby rw [h', ←mul_assoc, h, mul_assoc]\n-- QUOTE.\n\n/- TEXT:\nYou still see the incremental progress by placing the cursor after\na comma in any list of rewrites.\n\nAnother trick is that we can declare variables once and for all outside\nan example or theorem.\nWhen Lean sees them mentioned in the statement of the theorem,\nit includes them automatically.\nTEXT. -/\nsection\n\n-- QUOTE:\nvariables a b c d e f g : ℝ\n\nexample (h : a * b = c * d) (h' : e = f) :\n  a * (b * e) = c * (d * f) :=\nby rw [h', ←mul_assoc, h, mul_assoc]\n-- QUOTE.\n\nend\n\n/- TEXT:\nInspection of the tactic state at the beginning of the above proof\nreveals that Lean indeed included the relevant variables, leaving out\n`g` that doesn't feature in the statement.\nWe can delimit the scope of the declaration by putting it\nin a ``section ... end`` block.\nFinally, recall from the introduction that Lean provides us with a\ncommand to determine the type of an expression:\nTEXT. -/\n-- QUOTE:\nsection\nvariables a b c : ℝ\n\n#check a\n#check a + b\n#check (a : ℝ)\n#check mul_comm a b\n#check (mul_comm a b : a * b = b * a)\n#check mul_assoc c a b\n#check mul_comm a\n#check mul_comm\n#check @mul_comm\n\nend\n-- QUOTE.\n\n/- TEXT:\nThe ``#check`` command works for both objects and facts.\nIn response to the command ``#check a``, Lean reports that ``a`` has type ``ℝ``.\nIn response to the command ``#check mul_comm a b``,\nLean reports that ``mul_comm a b`` is a proof of the fact ``a * b = b * a``.\nThe command ``#check (a : ℝ)`` states our expectation that the\ntype of ``a`` is ``ℝ``,\nand Lean will raise an error if that is not the case.\nWe will explain the output of the last three ``#check`` commands later,\nbut in the meanwhile, you can take a look at them,\nand experiment with some ``#check`` commands of your own.\n\nLet's try some more examples. The theorem ``two_mul a`` says\nthat ``2 * a = a + a``. The theorems ``add_mul`` and ``mul_add``\nexpress the distributivity of multiplication over addition,\nand the theorem ``add_assoc`` expresses the associativity of addition.\nUse the ``#check`` command to see the precise statements.\n\n.. index:: calc, tactics ; calc\nTEXT. -/\nsection\nvariables a b : ℝ\n\n-- QUOTE:\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw [mul_add, add_mul, add_mul],\n  rw [←add_assoc, add_assoc (a * a)],\n  rw [mul_comm b a, ←two_mul]\nend\n-- QUOTE.\n\n/- TEXT:\nWhereas it is possible to figure out what it going on in this proof\nby stepping through it in the editor,\nit is hard to read on its own.\nLean provides a more structured way of writing proofs like this\nusing the ``calc`` keyword.\nTEXT. -/\n-- QUOTE:\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 [←add_assoc, add_assoc (a * a)]\n  ... = a * a + 2 * (a * b) + b * b     :\n          by rw [mul_comm b a, ←two_mul]\n-- QUOTE.\n\n/- TEXT:\nNotice that there is no more ``begin ... end`` block:\nan expression that begins with ``calc`` is a *proof term*.\nA ``calc`` expression can also be used inside a tactic proof,\nbut Lean interprets it as the instruction to use the resulting\nproof term to solve the goal.\n\nThe ``calc`` syntax is finicky: the dots and colons and justification\nhave to be in the format indicated above.\nLean ignores whitespace like spaces, tabs, and returns,\nso you have some flexibility to make the calculation look more attractive.\nOne way to write a ``calc`` proof is to outline it first\nusing the ``sorry`` tactic for justification,\nmake sure Lean accepts the expression modulo these,\nand then justify the individual steps using tactics.\nTEXT. -/\n\n-- QUOTE:\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    begin\n      sorry\n    end\n  ... = a * a + (b * a + a * b) + b * b : by sorry\n  ... = a * a + 2 * (a * b) + b * b     : by sorry\n-- QUOTE.\nend\n\n/- TEXT:\nTry proving the following identity using both a pure ``rw`` proof\nand a more structured ``calc`` proof:\nTEXT. -/\n/- Try these. For the second, use the theorems listed underneath. -/\n\nsection\nvariables a b c d : ℝ\n\n-- QUOTE:\nexample : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=\nsorry\n-- QUOTE.\n\n/- TEXT:\nThe following exercise is a little more challenging.\nYou can use the theorems listed underneath.\nTEXT. -/\n-- QUOTE:\nexample (a b : ℝ) : (a + b) * (a - b) = a^2 - b^2 :=\nbegin\n  sorry\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-- QUOTE.\n\nend\n\n/- TEXT:\n.. index:: rw, tactics ; rw and rewrite\n\nWe can also perform rewriting in an assumption in the context.\nFor example, ``rw mul_comm a b at hyp`` replaces ``a * b`` by ``b * a``\nin the assumption ``hyp``.\nTEXT. -/\n/- Examples. -/\n\nsection\nvariables a b c d : ℝ\n\n-- QUOTE:\nexample (a b c d : ℝ) (hyp : c = d * a + b) (hyp' : b = a * d) :\n  c = 2 * a * d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a * d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp\nend\n-- QUOTE.\n\n/- TEXT:\n.. index:: exact, tactics ; exact\n\nIn the last step, the ``exact`` tactic can use ``hyp`` to solve the goal\nbecause at that point ``hyp`` matches the goal exactly.\n\n.. index:: ring (tactic), tactics ; ring\n\nWe close this section by noting that ``mathlib`` provides a\nuseful bit of automation with a ``ring`` tactic,\nwhich is designed to prove identities in any commutative ring.\nTEXT. -/\n-- QUOTE:\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-- QUOTE.\n\nend\n\n/- TEXT:\nThe ``ring`` tactic is imported indirectly when we\nimport ``data.real.basic``,\nbut we will see in the next section that it can be used\nfor calculations on structures other than the real numbers.\nIt can be imported explicitly with the command\n``import tactic``.\nWe will see there are similar tactics for other common kind of algebraic\nstructures.\n\nThere is a variation of ``rw`` called ``nth_rewrite`` that allows you to replace only particular instances of an expression in the goal.\nPossible matches are enumerated starting with zero,\nso in the following example, ``nth_rewrite 1 h`` replaces the *second*\noccurrence of ``a + b`` with ``c``.\nEXAMPLES: -/\n-- QUOTE:\nexample (a b c : ℕ) (h : a + b = c) : (a + b) * (a + b) = a * c + b * c :=\nbegin\n  nth_rewrite 1 h,\n  rw add_mul\nend\n-- QUOTE.\n\n/- TEXT:\nSee also ``nth_rewrite_lhs`` and ``nth_rewrite_rhs``.\nFor a more sophisticed means of rewriting particular subexpressions,\nsee the `documentation for the conversion tactic <https://leanprover-community.github.io/extras/conv.html>`_.\nTEXT. -/", "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/02_Basics/source_01_Calculating.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898305367525, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.7919050772474888}}
{"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.zmod.basic\nimport ring_theory.int.basic\n\n/-!\n# Coprimality and vanishing\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe show that for prime `p`, the image of an integer `a` in `zmod p` vanishes if and only if\n`a` and `p` are not coprime.\n-/\n\nnamespace zmod\n\n/-- If `p` is a prime and `a` is an integer, then `a : zmod p` is zero if and only if\n`gcd a p ≠ 1`. -/\nlemma eq_zero_iff_gcd_ne_one {a : ℤ} {p : ℕ} [pp : fact p.prime] : (a : zmod p) = 0 ↔ a.gcd p ≠ 1 :=\nby rw [ne, int.gcd_comm, int.gcd_eq_one_iff_coprime,\n       (nat.prime_iff_prime_int.1 pp.1).coprime_iff_not_dvd, not_not, int_coe_zmod_eq_zero_iff_dvd]\n\n/-- If an integer `a` and a prime `p` satisfy `gcd a p = 1`, then `a : zmod p` is nonzero. -/\nlemma ne_zero_of_gcd_eq_one {a : ℤ} {p : ℕ} (pp : p.prime) (h : a.gcd p = 1) :\n  (a : zmod p) ≠ 0 :=\nmt (@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mp (not_not.mpr h)\n\n/-- If an integer `a` and a prime `p` satisfy `gcd a p ≠ 1`, then `a : zmod p` is zero. -/\nlemma eq_zero_of_gcd_ne_one {a : ℤ} {p : ℕ} (pp : p.prime) (h : a.gcd p ≠ 1) :\n  (a : zmod p) = 0 :=\n(@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mpr h\n\nend zmod\n", "meta": {"author": "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/zmod/coprime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.874077222043951, "lm_q1q2_score": 0.791905063182147}}
{"text": "variables p q r : Prop \n\nnamespace mth1001\n\nsection false_and_negation \n\n/-\n`false` is the name of a special proposition from which we can derive anything.\nIn ordinary mathematics, `false` is written `⊥` and is referred to as an\n'arbitrary contradiction' or sometimes just 'contradiction'.\n\nThe tactic `exfalso` is used to turn any goal into a proof of `false`.\n\nSide note: `exfalso` is short for the Latin 'ex falso sequitur quodlibet', \nwhich translates to, 'from a contradiction, whatever you please follows'.\n-/\n\nexample : false → p :=\nbegin\n  assume h : false, -- I could equally have written `intro h`.\n  exfalso, \n  exact h,\nend\n\n/-\nIn term style, `false.elim h` provides a proof of anything, given that `h` is\na proof of `false`.`\n-/\nexample : false → p :=\nassume h, false.elim h\n\n/-\nAn more powerful tactic is `contradiction`. This tactic looks in the context and goal for a\ncontradition and closes the goal if it finds one.\n-/\nexample : false → p :=\nbegin \n  contradiction,\nend\n\n-- Exercise 057:\n-- Use `exfalso` in proving the following result. Try another proof using `contradiction`.\nexample : (¬p ∨ q) → (p → q) :=\nbegin\n  intros h hp,  /- `intros h hp` is equivalent to `intro h, intro hp`. -/\n\n  sorry  \nend\n\n\n/-\n`false` may seem bizzare, but it's just what we need for formalising the notion\nof 'not'. The notation `¬p` is an abbreviation for `p → false`. The symbol\n`¬` is written `\\n`. We read `¬p` as 'not p'. \n\nIn general, to prove `a → b` is to assume `a` and deduce `b`. Thus, to prove\n`¬p` is to assume `p` and deduce `false`.\n-/\n\n/-\nThe first thing to observe is that we may derive `false` from `¬p` and `p` by\nimplication elimination, as `¬p` means `p → false`.\n-/\nexample (h₁ : ¬p) (h₂ : p) : false :=\nh₁ h₂\n\n/-\nGiven it's not the case that you like tea or coffe, one can deduce it's not\nthe case that you like tea.\n-/\nexample (h : ¬(p ∨ q)) : ¬p :=\nbegin \n  intro hp, -- Assume hp : p. It remains to prove `false`.\n  have hpq : p ∨ q, from or.inl hp,\n  show false, from h hpq, -- Or just `h hpq` or `contradiction`.\nend\n\n-- Exercise 058:\n-- Given `p`, we can derive `¬¬p`. This is part of the law of double negation.\ntheorem not_not_of_self : p → ¬¬p :=\nbegin\n  intros hp hnp,\n  sorry  \nend\n\n/-\nBritish mathematician Augustus De Morgan is famous in part for several laws of\nlogic. We'll build them up from scratch.\n-/\n\n-- Exercise 059:\ntheorem not_or_of_not_and_not : ¬p ∧ ¬q →  ¬(p ∨ q) :=\nbegin\n  intros h hpq, \n  cases hpq with hp hq,\n  { sorry, }, \n  { sorry, }, \nend \n\n-- Exercise 060:\ntheorem not_and_of_not_or_not : ¬p ∨ ¬q → ¬(p ∧ q) :=\nbegin\n  sorry  \nend \n\n-- Exercise 061:\ntheorem not_and_not_of_not_or : ¬(p ∨ q) → ¬p ∧ ¬q :=\nbegin \n  sorry  \nend\n\n/-\nWe'll later see that `p → q` is equivalent to `¬q → ¬p`, the so-called 'contrapositive' of\n`p → q`. We prove one direction of this equivalence below.\n-/\n\n-- Exercise 062:\nexample : (p → q) → (¬q → ¬p) :=\nbegin \n  intros hpq hnq hp,\n  sorry  \nend \n\nend false_and_negation \n\n/-\nSUMMARY:\n\n* `false`, the name for an arbitrary contradiction.\n* Anything can be proved from false, using `exfalso` (tactic-style) or `false.elim` (term-style).\n* The `contradiction` tactic to automate contradiction finding.\n* Introducing multiple assumptions with `intros`.\n* `¬p` as a shortcut for `p → false`.\n* The law of double negation.\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_10_false_and_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.791859114882984}}
{"text": "axiom excluded_middle : ∀ P: Prop, P ∨ ¬ P\n#check excluded_middle\n\ntheorem double_neg_elim: ∀ P: Prop, ¬ ¬ P → P := \nbegin\n  assume P : Prop,\n  assume pfNotNotP : ¬ ¬ P,\n  cases excluded_middle P,\n    -- case 1: \n    show P, from h,\n\n    have f: false := pfNotNotP h,\n    exact false.elim f\nend\n\ntheorem nat_eq : ∀ (n : nat), ∀ (m : nat), \n    m = n ∨ m ≠ n := \nbegin\n    assume n m: nat,\n    cases excluded_middle (m=n) with h1 h2,\n        exact or.inl h1,\n        exact or.inr h2\nend\n\nopen classical\ntheorem nat_eq' : ∀ (n : nat), ∀ (m : nat), \n    m = n ∨ m ≠ n := \nbegin\n    assume n m: nat,\n    cases em (m=n),\n        exact or.inl h,\n        exact or.inr h\nend\n\n\ntheorem double_neg_elim'': ∀ {P}, (P ∨ ¬P) → ¬¬P → P :=\nbegin\n    assume P: Prop,\n    assume h: P ∨ ¬P,\n    assume notnotP: ¬¬P,\n    cases h with a b,\n        show P, from a,\n        show P, from false.elim (notnotP b),\nend\n\ntheorem p_b_c' : ∀ P: Prop, (¬P → false) → P :=\nbegin\n    intro P,\n    assume nnp: ¬P → false,\n    have a := double_neg_elim P nnp,\n    exact a\nend\n\ntheorem p_b_c'' : ∀ P: Prop, (¬P → false) → P := double_neg_elim", "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/lesson6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216356, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7918393613678735}}
{"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 levels 1 and 2\nimport complex.Level_02_I\n\n/-! # Level 3: Complex conjugation -/\n\nnamespace complex\n\n-- First complete the definition using `complex.mk` or `⟨x, y⟩` notation\n\n/-- The complex conjugate of a complex number -/\ndef conj (z : ℂ) : ℂ := sorry\n\n-- Now prove how it interacts with everything else\n\n/-! ## Real and imaginary parts -/\n\n@[simp] lemma conj_re (z : ℂ) : re(conj z) = re(z) := sorry\n@[simp] lemma conj_im (z : ℂ) : im(conj z) = -im(z) := sorry\n\n/-! ## Behaviour with respect to 0, 1 and I -/\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@[simp] lemma conj_neg_I : conj (-I) = I := sorry\n\n/-! ## Behaviour with respect to +, - and * -/\n\n@[simp] lemma conj_add (z w : ℂ) : conj (z + w) = conj z + conj w :=\nsorry\n\n@[simp] lemma conj_neg (z : ℂ) : conj (-z) = -conj z := sorry\n\n\n@[simp] lemma conj_mul (z w : ℂ) : conj (z * w) = conj z * conj w :=\nsorry\n\n/-! ## Behaviour with respect to real numbers -/\n\n@[simp] lemma conj_of_real (r : ℝ) : conj r = r := sorry\n\nlemma im_eq_zero_of_eq_conj {z : ℂ} : conj z = z → im z = 0 := sorry\n\nlemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=\nsorry\n\nlemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=\nsorry\n\ntheorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=\nsorry\n\n\n/-! ## Properties of the `conj` map -/\n\n@[simp] lemma conj_conj (z : ℂ) : conj (conj z) = z :=\nsorry\n\nlemma conj_inj {z w : ℂ} : conj z = conj w ↔ z = w :=\nsorry\n\n@[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 :=\nsorry\n\n/-\n\nA ring homomorphism in Lean is the following collection\nof data: a map, and the proof that it commutes with\nthe ring structures in the obvious way. Here we observe\nthat the work we've done is enough to define the\nring homomorphism complex conjugation.\n\n-/\n\n/-- the ring homomorphism complex conjugation -/\ndef Conj : ℂ →+* ℂ :=\n{ to_fun := conj,\n  map_zero' := conj_zero,\n  map_one' := conj_one,\n  map_add' := conj_add,\n  map_mul' := conj_mul\n}\n\n-- Two optional lemmas which computer scientists like,\n-- giving us easy access to some basic properties\n-- of conj\n\nopen function\n\nlemma conj_involutive : involutive conj := sorry\n\nlemma conj_bijective : bijective conj := sorry\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_03_conj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7917535634627947}}
{"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.div\n! leanprover-community/mathlib commit ee0c179cd3c8a45aa5bffbf1b41d8dbede452865\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.Order.Lemmas\nimport Mathlib.Algebra.Ring.Regular\n\n/-!\n# Lemmas relating `/` in `ℤ` with the ordering.\n-/\n\n\nopen Nat\n\nnamespace Int\n\ntheorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hbc : b ∣ c)\n    (h : b * a = c * d) : a = c / b * d := by\n  cases' hbc with k hk\n  subst hk\n  rw [Int.mul_ediv_cancel_left _ hb]\n  rw [mul_assoc] at h\n  apply mul_left_cancel₀ hb h\n#align int.eq_mul_div_of_mul_eq_mul_of_dvd_left Int.eq_mul_div_of_mul_eq_mul_of_dvd_left\n\n/-- If an integer with larger absolute value divides an integer, it is\nzero. -/\ntheorem eq_zero_of_dvd_of_natAbs_lt_natAbs {a b : ℤ} (w : a ∣ b) (h : natAbs b < natAbs a) :\n    b = 0 := by\n  rw [← natAbs_dvd, ← dvd_natAbs, coe_nat_dvd] at w\n  rw [← natAbs_eq_zero]\n  exact eq_zero_of_dvd_of_lt w h\n#align int.eq_zero_of_dvd_of_nat_abs_lt_nat_abs Int.eq_zero_of_dvd_of_natAbs_lt_natAbs\n\ntheorem eq_zero_of_dvd_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) (h : b ∣ a) : a = 0 :=\n  eq_zero_of_dvd_of_natAbs_lt_natAbs h (natAbs_lt_natAbs_of_nonneg_of_lt w₁ w₂)\n#align int.eq_zero_of_dvd_of_nonneg_of_lt Int.eq_zero_of_dvd_of_nonneg_of_lt\n\n/-- If two integers are congruent to a sufficiently large modulus,\nthey are equal. -/\ntheorem eq_of_mod_eq_of_natAbs_sub_lt_natAbs {a b c : ℤ} (h1 : a % b = c)\n    (h2 : natAbs (a - c) < natAbs b) : a = c :=\n  eq_of_sub_eq_zero (eq_zero_of_dvd_of_natAbs_lt_natAbs (dvd_sub_of_emod_eq h1) h2)\n#align int.eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs Int.eq_of_mod_eq_of_natAbs_sub_lt_natAbs\n\ntheorem ofNat_add_negSucc_of_ge {m n : ℕ} (h : n.succ ≤ m) :\n    ofNat m + -[n+1] = ofNat (m - n.succ) := by\n  rw [negSucc_eq, ofNat_eq_cast, ofNat_eq_cast, ← Nat.cast_one, ← Nat.cast_add,\n    ← sub_eq_add_neg, ← Nat.cast_sub h]\n#align int.of_nat_add_neg_succ_of_nat_of_ge Int.ofNat_add_negSucc_of_ge\n\ntheorem natAbs_le_of_dvd_ne_zero {s t : ℤ} (hst : s ∣ t) (ht : t ≠ 0) : natAbs s ≤ natAbs t :=\n  not_lt.mp (mt (eq_zero_of_dvd_of_natAbs_lt_natAbs hst) ht)\n#align int.nat_abs_le_of_dvd_ne_zero Int.natAbs_le_of_dvd_ne_zero\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/Div.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7917535634627947}}
{"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\nFormalization of Theorem 1 from the following paper:\n\"The inconsistency of a Brouwerian continuity\nprinciple with the Curry–Howard interpretation\"\nby Martín Escardó and Chuangjie Xu\n-/\nimport data.nat\nopen nat sigma.ops\n\n/- Bounded equality: α and β agree in the first n positions. -/\ndefinition beq (α β : nat → nat) (n : nat) : Prop :=\n∀ a, a < n → α a = β a\n\nnotation α `=[`:50 n:50 `]` β:50 := beq α β n\n\nlemma pred_beq {α β : nat → nat} {n : nat} : α =[n+1] β → α =[n] β :=\nλ h a altn, h a (lt.step altn)\n\ndefinition continuous (f : (nat → nat) → nat) : Type₁ :=\n∀ α, Σ n, ∀ β, α =[n] β → f α = f β\n\ndefinition zω : nat → nat :=\nλ x, zero\n\ndefinition znkω (n : nat) (k : nat) : nat → nat :=\nλ x, if x < n then 0 else k\n\nlemma znkω_succ (n : nat) (k : nat) : znkω (n+1) k 0 = 0 :=\nrfl\n\nlemma znkω_bound (n : nat) (k : nat) : znkω n k n = k :=\nif_neg !nat.lt_irrefl\n\nlemma zω_eq_znkω (n : nat) (k : nat) : zω =[n] znkω n k :=\nλ a altn, begin esimp [zω, znkω], rewrite [if_pos altn] end\n\nsection\nhypothesis all_continuous : ∀ f, continuous f\n\ndefinition M (f : (nat → nat) → nat) : nat :=\n(all_continuous f zω).1\n\nlemma M_spec (f : (nat → nat) → nat) : ∀ β, zω =[M f] β → f zω = f β :=\n(all_continuous f zω).2\n\ndefinition m := M (λα, zero)\n\ndefinition f β :=  M (λα, β (α m))\n\nlemma β0_eq (β : nat → nat) : ∀ α, zω =[f β] α → β 0 = β (α m) :=\nλ α, M_spec (λα, β (α m)) α\n\nlemma not_all_continuous : false :=\nlet β := znkω (M f + 1) 1 in\nlet α := znkω m (M f + 1) in\nhave βeq₁ : zω =[M f + 1] β, from\n  λ (a : nat) (h : a < M f + 1), begin unfold zω, unfold znkω, rewrite [if_pos h] end,\nhave βeq₂    : zω =[M f] β,                    from pred_beq βeq₁,\nhave m_eq_fβ : m = f β,                        from M_spec f β βeq₂,\nhave aux     : ∀ α, zω =[m] α → β 0 = β (α m), by rewrite m_eq_fβ at {1}; exact (β0_eq β),\nhave zero_eq_one : 0 = 1, from calc\n  0   = β 0         : by rewrite znkω_succ\n  ... = β (α m)     : aux α (zω_eq_znkω m (M f + 1))\n  ... = β (M f + 1) : by rewrite znkω_bound\n  ... = 1           : by rewrite znkω_bound,\nby contradiction\nend\n\n/-\nAdditional remarks:\nBy using the slightly different definition of continuous\n  ∀ α, ∃ n, ∀ β, α =[n] β → f α = f β\ni.e., using ∃ instead of Σ, we can assume the following axiom\n  all_continuous : ∀ f, continuous f\nHowever, the system becomes inconsistent again if we also assume Hilbert's choice,\nbecause with Hilbert's choice we can convert ∃ into Σ\n-/\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/cont.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741308615412, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.79172536842736}}
{"text": "--#check list.reverse\n--#check list\nnamespace z\n\ninductive nt: Type\n| zero : nt\n| succ : nt → nt\n\ndefinition add_n : nt → nt → nt\n| nt.zero x := x\n| (nt.succ x) y := nt.succ (add_n x y)\n\ndefinition product_n : nt → nt → nt\n| x (nt.succ nt.zero) := x\n| _ nt.zero := nt.zero\n| x (nt.succ y) := add_n x (product_n x y)\n\ndefinition eq_n : nt → nt → bool\n| nt.zero nt.zero := tt\n| (nt.succ a) (nt.succ b) := eq_n a b\n| _ _ := ff\n\n\n\n\ninductive nat_pair : Type \n| p : nat → nat → nat_pair\n\nopen nat_pair\nnotation a ; b := p a b\n\n#check p 5 5 \n\ndef fst : nat_pair → nat\n| (p x _) := x\n\ndef snd : nat_pair → nat\n| (p _ x) := x\n\ndef first_or_second : nat_pair → bool → nat\n| (p x _) ff := x\n| (p _ x) tt := x\n\ndef swap : nat_pair → nat_pair\n| (x;y)  := y;x\n\n\n\ntheorem surjective_pairing : ∀ (n m : nat), (n;m) = \n((first_or_second (n;m) ff) ; (first_or_second (n;m) tt)) := begin\n\nintros n m,\n\nhave H₁ : ∀ n m : ℕ, first_or_second (n;m) ff = n,\n{\n    unfold first_or_second,\n    intro h,\n    intro g,\n    refl\n},\n{\n    rw H₁,\n    have H₂ : ∀ n m : ℕ, first_or_second (n;m) tt = m,\n    {\n        unfold first_or_second,\n        intro h, intro g, refl\n    },\n    rw H₂\n}\n\nend\n\n\ntheorem snd_fst_is_swap : ∀ (p : nat_pair),\n  (snd p ; fst p) = swap p := begin\n\n  intro p,\n  cases p with x y,\n  refl\n\n  end\n\ntheorem fst_swap_is_snd : ∀ (p : nat_pair),\n  fst (swap p) = snd p := begin\n\n  intro p,\n  cases p,\n  refl\n\n  end\n\n\ninductive natlist : Type \n| emp : natlist\n| ap : nat → natlist → natlist\n\nopen natlist\nnotation {} := emp\nnotation x :: y := ap x y\n\n\ndef repeat : ℕ → ℕ → natlist\n|  0 _ := {}\n| (n+1) x := ap x (repeat n x)\n\ndef len : natlist → ℕ \n| {} := 0\n| (ap _ x) := 1 + len x\n\ndef append : natlist → natlist → natlist \n| {} x := x\n| (ap n L) x := ap n (append L x)\n\ndef ap_r : natlist → nat → natlist := λ L n,\nappend L (ap n {})\n\ndef reverse : natlist → natlist\n| {} := {}\n| (ap n L) := append (reverse L) (n::{})\n--ap_r changed to append\n--n changed to (n::{})\n\ndef first_element : natlist → ℕ\n| {} := 0\n| (n::L) := n\n\ndef last_element : natlist → ℕ\n| {} := 0\n| (a::{}) := a\n| (a::b) := last_element b\n\ndef up_to_last : natlist → natlist\n| {} := {}\n| (a::{}) := {}\n| (a::L) := a::(up_to_last L)\n\ndef is_odd : ℕ → bool\n| 1 := tt\n| 0 := ff\n| (n+2) := is_odd n\n\ndef append_if_odd : ℕ → bool → natlist → natlist\n| x tt L := ap x L\n| x ff L := L \n\ndef oddmembers : natlist → natlist\n| {} := {}\n| (ap n L) := append_if_odd n (is_odd n) (oddmembers L)\n\ndef count_odd_members : natlist → ℕ\n| {} := 0\n| L := len (oddmembers L)\n\ndef list_zip : natlist → natlist → natlist\n| {} {} := {}\n-- at least one not empty\n| {} L := L\n| L {} := L\n-- neither empty\n| (ap n₁ L₁) (ap n₂ L₂) := ap n₁ (ap n₂ (list_zip L₁ L₂))\n\ndef one_if_equal_else_zero : ℕ → ℕ → ℕ\n| x y := if x=y then 1 else 0\n\ndef count : natlist → ℕ → ℕ\n| {} _ := 0\n| (ap n L) x := one_if_equal_else_zero x n + (count L x)\n\ndef sum_of_list : natlist → ℕ\n| {} := 0\n| (ap n L) := n + sum_of_list L\n\ndef sum := append\ndef add := ap\n\ndef member : natlist → ℕ → bool\n| {} _ := false\n| (ap n L) x := if n=x then tt else member L x\n\ndef remove_one : natlist → ℕ → natlist\n| {} _ := {}\n| (ap n L) x := if n=x then L else ap n (remove_one L x)\n\ndef remove_all : natlist → ℕ → natlist\n| {} _ := {}\n| (ap n L) x := if n=x then remove_all L x else ap n (remove_all L x)\n\ndef to_set : natlist → natlist\n| {} := {}\n| (ap n L) := if count L n = 0 then ap n (to_set L) else to_set L\n\ndef is_a_subset_of_b : natlist → natlist → bool\n| {} _ := tt\n| (a::L) x := if count L a < count x a then is_a_subset_of_b L x else ff\n\n-- ascending order\ndefinition sort_into_list : natlist → ℕ → natlist\n| {} x := x::{}\n| (n::L) x := if n>=x then (x::n::L) else append (n::{}) (sort_into_list L x)\n\n-- sort             a   into  b={}\ndefinition SORT : natlist → natlist → natlist\n| {} x := x\n| (n::L) x := SORT L (sort_into_list x n)\n\ndefinition sort_list : natlist → natlist := λ n, SORT n {}\n\n-- only equal if same values in same places\ndefinition list_equality : natlist → natlist → bool\n| {} {} := tt\n| (ap a L1) (ap b L2) := if a=b then list_equality L1 L2 else ff\n| _ _ := ff\n\ndefinition same_values : natlist → natlist → bool := \nλ a b, list_equality (sort_list a) (sort_list b)\n\n\n@[derive decidable_eq] inductive nat_error : Type\n| Some : nat → nat_error\n| None : nat_error\nopen nat_error\n\ndefinition nth_in_list : natlist → ℕ → nat_error\n| {} _ := None\n| (x::L) 0 := Some x\n| (x::L) (nat.succ n) := nth_in_list L n\n\ntheorem a : ∀ n y:ℕ, count (repeat n y) y = n := begin intros n y,\ninduction n with d Hd,\n{\n    refl\n},\n{\n    unfold repeat,\n    unfold count,\n    unfold one_if_equal_else_zero,\n    rw Hd,\n    simp\n} end\n\ntheorem b : ∀ a b : ℕ, sum_of_list (repeat a b) = a*b := begin intros a b,\ninduction a with d Hd,\n{\n    simp,\n    cases b;refl\n},\n{\n    unfold repeat,\n    unfold sum_of_list,\n    rw Hd,\n    simp,\n\n    rw mul_add b d 1, simp\n} end\n\n@[simp] theorem count_append (a L : natlist) (n : ℕ) : \ncount (append a L) n = count a n + count L n :=begin induction a with new L₂ Hd,\n{\n    unfold count append,\n    simp\n},\n{\n    unfold append count one_if_equal_else_zero ,\n    by_cases (n=new),\n    {\n        simp [h],\n        --clear h,\n        congr,\n        rw h at Hd,\n        rw Hd,\n        simp\n    },\n    {\n        simp [h],\n        rw Hd,\n        simp\n    }\n} end\n\n@[simp] theorem c : ∀ L : natlist, ∀ n:ℕ, count (reverse L) n = count L n := begin\nintros L n,\ninduction L with new L₂ H₁, {refl},\n{\n    by_cases (n=new),\n    {\n        unfold reverse ap_r count one_if_equal_else_zero,\n        subst h, simp,\n        unfold count one_if_equal_else_zero,\n        simp, congr,\n        rw H₁\n    },\n    {\n        unfold reverse count ap_r one_if_equal_else_zero,\n        simp [h],\n        unfold reverse count ap_r one_if_equal_else_zero,\n        simp [h],\n        rw H₁\n    }\n}\nend\n\n@[simp] theorem append_unchanged : ∀ a : natlist, append a {} = a := begin\nintro a,\ninduction a,{refl},\n{\n    unfold append,\n    rw ih_1\n} end\n\n\n@[simp] theorem append_ass : ∀ a b c : natlist, \nappend (append a b) c = append a (append b c) := begin\nintros a b c,\ninduction a,\n{\n    refl\n},\n{\n    unfold append,\n    rw ih_1\n} end \n\n\n@[simp]theorem d: ∀ L₁ L₂ : natlist,\n  reverse (append L₁ L₂) = append (reverse L₂) (reverse L₁) := begin\n  intros L₁ L₂,\n  induction L₁ with new L H,\n  {\n      unfold reverse,\n      unfold append,\n      simp\n  },\n  {\n      unfold append reverse ap_r,\n      rw H,\n      exact append_ass (reverse L₂) (reverse L)(new :: {})\n  } end\n\n\n-- [1,2,3] [4,5,6]\n-- [3,2,1] [6,5,4]\n-- [3,2,1,6,5,4]\n-- [4,5,6,1,2,3]\n\ntheorem e : ∀ L : natlist, reverse (reverse L) = L := begin\nintro L,\ninduction L with new L_shorter H,{refl},\n{\n    unfold reverse,\n    simp,\n    rw H, refl\n}\nend\n\n@[simp]theorem same_eq : ∀ x : natlist, list_equality x x = tt := begin\nintro x,\ninduction x,{refl},\n{\n    unfold list_equality,\n    simp, rw ih_1\n}\nend\n\n@[simp]theorem same_eq2 : ∀ x : natlist, same_values x x = tt := begin\nintro x, unfold same_values, simp\nend\n\ntheorem g (L : natlist) (n : ℕ) : same_values (append (n::{}) L) (append L (n::{})) := sorry\n\n\ntheorem t : 1=1 := begin\n\nby_cases (Some 5 = None),\n{\n    admit\n},\n{\n    admit\n}\n\nend\n\n\n\ntheorem f : ∀ L : natlist, same_values L (reverse L) = tt := begin\n\nintro L,\ninduction L with new L_shorter H,{refl},\n{\n    unfold reverse,\n    \n    -- new + L == L_r + new\n    --unfold same_values sort_into_list\n    --list_equality sort_into_list,\n    --unfold same_values sort_into_list\n    --list_equality sort_into_list at H,\n\n    admit\n\n}\n\nend \n\nend z\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_stuff_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7917162887499382}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a y b números reales. Demostrar que\n--    abs (a*b) ≤ (a^2 + b^2) / 2\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nimport tactic\n\nvariables a b : ℝ\n\n-- 1ª demostración\nexample : abs (a*b) ≤ (a^2 + b^2) / 2 :=\nbegin\n  apply abs_le.mpr,\n  split,\n  { have h1 : 0 ≤ a^2 + 2*a*b + b^2,\n      calc 0 ≤ (a+b)^2                : by exact pow_two_nonneg (a + b)\n         ... = a^2+2*a*b+b^2          : by ring,\n    have h2 : -2*(a*b) ≤ a^2 + b^2,\n      calc -2*(a*b)\n           ≤ -2*(a*b)+(a^2+2*a*b+b^2) : by exact le_add_of_nonneg_right h1\n       ... = a^2 + b^2                : by ring,\n    show -((a^2 + b^2) / 2) ≤ a*b,      by linarith [h2] },\n  { have h3 : 0 ≤ a^2 - 2*a*b + b^2,\n      calc 0 ≤ (a-b)^2                : by exact pow_two_nonneg (a - b)\n         ... = a^2-2*a*b+b^2          : by ring,\n    have h4 : 2*(a*b) ≤ a^2 + b^2,\n      calc 2*(a*b)\n           ≤ 2*(a*b)+(a^2-2*a*b+b^2)  : by exact le_add_of_nonneg_right h3\n       ... = a^2 + b^2                : by ring,\n    show a * b ≤ (a^2 + b^2)/2,         by linarith [h4] },\nend\n\n-- 2ª demostración\nexample : abs (a*b) ≤ (a^2 + b^2) / 2 :=\nbegin\n  apply abs_le.mpr,\n  split,\n  { have h1 : 0 ≤ a^2 + 2*a*b + b^2,\n      calc 0 ≤ (a+b)^2                : by exact pow_two_nonneg (a + b)\n         ... = a^2+2*a*b+b^2          : by ring,\n    have h2 : -2*(a*b) ≤ a^2 + b^2,\n      calc -2*(a*b)\n           ≤ -2*(a*b)+(a^2+2*a*b+b^2) : by exact le_add_of_nonneg_right h1\n       ... = a^2 + b^2                : by ring,\n    show -((a^2 + b^2) / 2) ≤ a*b,      by linarith [h2] },\n  { have h4 : 2*a*b ≤ a^2 + b^2       := two_mul_le_add_sq a b,\n    show a * b ≤ (a^2 + b^2)/2,         by linarith [h4] },\nend\n\n-- 3ª demostración\nexample : abs (a*b) ≤ (a^2 + b^2) / 2 :=\nbegin\n  apply abs_le.mpr,\n  split,\n  { have h1 : 0 ≤ a^2 + 2*a*b + b^2,\n      calc 0 ≤ (a+b)^2                : by exact pow_two_nonneg (a + b)\n         ... = a^2+2*a*b+b^2          : by ring,\n    have h2 : -2*(a*b) ≤ a^2 + b^2,\n      calc -2*(a*b)\n           ≤ -2*(a*b)+(a^2+2*a*b+b^2) : by exact le_add_of_nonneg_right h1\n       ... = a^2 + b^2                : by ring,\n    show -((a^2 + b^2) / 2) ≤ a*b,      by linarith [h2] },\n  { show a * b ≤ (a^2 + b^2)/2,         by linarith [two_mul_le_add_sq a b] },\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/Ejercicio_desigualdades_absolutas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7917162855156562}}
{"text": "-- *  Level 1\nimport game.world3.level9\n\ntheorem mul_pos (a b : mynat) : a ≠ 0 → b ≠ 0 → a * b ≠ 0 :=\n\n\nbegin\n\nintro h,\nintro g,\nintro f,\ncases b,\nrw mul_zero at f,\napply g,\nexact f,\napply h,\nrw mul_succ at f,\nhave foo := add_left_eq_zero(f),\nexact foo,\n\nend\n\n-- * Level 2\n\ntheorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : mynat) (h : a * b = 0) :  a = 0 ∨ b = 0 :=\n\nbegin\n\ncases b,\nright,\nrw mul_zero at h,\nexact h,\nleft,\nrw mul_succ at h,\nhave foo := add_left_eq_zero(h),\nexact foo,\n\nend\n-- * Level 3\ntheorem mul_eq_zero_iff (a b : mynat): a * b = 0 ↔ a = 0 ∨ b = 0 :=\n\n\nbegin\n\nsplit,\napply eq_zero_or_eq_zero_of_mul_eq_zero,\nintro g,\ncases g,\nrw g,\nrw zero_mul,\nrefl,\nrw g,\nrw mul_zero,\nrefl\n\nend\n-- * Level 4\n-- Couldn't do it lol\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/advanced_multiplication_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7917162735843776}}
{"text": "import Mathlib.Algebra.Group.Defs\n\n/-\nSource: https://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group\n-/\n\nnamespace Group\n\nvariable {G : Type _} [Group G] (x y z : G)\n\n-- the group axioms\n\nattribute [simp] one_mul\n\nattribute [simp] mul_left_inv\n\nattribute [simp] mul_assoc\n\nattribute [simp] mul_one\n\n@[simp] theorem left_inv_cancel : x⁻¹ * (x * y) = y := by rw [← mul_assoc]; simp\n\n@[simp] theorem one_inv : (1 : G)⁻¹ = (1 : G) := by\n  have := left_inv_cancel (1 : G) (1 : G)\n  rw [mul_one, mul_one] at this; assumption\n\n@[simp] theorem inv_inv : (x⁻¹)⁻¹ = x := by\n  have := left_inv_cancel (x⁻¹) x\n  rw [mul_left_inv, mul_one] at this; assumption\n\n@[simp] theorem mul_right_inv : x * x⁻¹ = 1 := by\n  have := left_inv_cancel (x⁻¹) (1 : G)\n  rw [inv_inv, mul_one] at this; assumption\n\n@[simp] theorem left_cancel_inv : x * (x⁻¹ * y) = y := by\n  have := left_inv_cancel (x⁻¹) y\n  rw [inv_inv] at this; assumption\n\n@[simp] theorem prod_inv : (x * y)⁻¹ = y⁻¹ * x⁻¹ := by\n  have := left_cancel_inv (x * y)⁻¹ (y⁻¹ * x⁻¹)\n  simp at this; assumption\n\nend Group\n\n\nvariable {G : Type _} [Group G] (a b c : G)\n\nexample : ((a⁻¹ * a) * (b * b⁻¹))⁻¹ = (1 : G) := by simp\n\nexample : b * ((a * b)⁻¹ * a) = 1 := by simp\n\nexample : a * (c⁻¹ * b) * (((b⁻¹ * c) * b) * (a * b)⁻¹) = (1 : G) := by simp\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/KnuthBendix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7916782678395268}}
{"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 -- imports the theory of subgroups\n\n/-!\n\n# Subgroups\n\nIn Lean, a subgroup is not a group. This is for the same reason that a subset\nis not a type. The way subgroups work is that if `G` is a group:\n\n`variables (G : Type) [group G]`\n\nthen the type of *all* subgroups of `G` is called `subgroup G`. So if you want\none subgroup of G:\n\n`variable (H : subgroup G)`\n\nthen, as you can see, `H` is not a type (we don't write `H : Type`), it's a term.\nSo how do we do elements of `H` then? It's just the same as sets: an element `x` of\n`H` is a term `x` of type `G`, such that the proposition `x ∈ H` holds.\n\nHere's the basic API for subgroups.\n\n-/\n\n-- Let `G` be a group, let `a` and `b` be elements of `H`, and let `H` and `K` be subgroups of `G`.\nvariables (G : Type) [group G] (a b : G) (H K : subgroup G)\n\n-- The basic API for subgroups\nexample : (1 : G) ∈ H := one_mem H\nexample (ha : a ∈ H) : a⁻¹ ∈ H := inv_mem ha\nexample (ha : a ∈ H) (hb : b ∈ H) : a * b ∈ H := mul_mem ha hb\n\n-- Let's use these axioms to make more API for subgroups.\n\n-- First, see if you can put the axioms together to prove subgroups are closed under \"division\".\nexample (ha : a ∈ H) (hb : b ∈ H) : a * b⁻¹ ∈ H :=\nbegin\n  sorry,\nend\n\n-- Now try these. You might want to remind yourself of the API for groups as explained\n-- in an earlier section, or make use of the `group` tactic.\n\n-- This lemma is called `inv_mem_iff` but try proving it yourself\nexample : a⁻¹ ∈ H ↔ a ∈ H := \nbegin\n  sorry,\nend\n\n-- this is `mul_mem_cancel_left` but see if you can do it from the axioms of subgroups.\n-- Again feel free to use the `group` tactic.\nexample (ha : a ∈ H) : a * b ∈ H ↔ b ∈ H :=\nbegin\n  sorry,\nend\n\n/-\n\n## Complete lattice structure on subgroups of G\n\nSubgroups of a group form a complete lattice. Let's just check this:\n\n-/\n\nexample : complete_lattice (subgroup G) := infer_instance\n\n/-\n\nThe \"type class inference system\" (the system which deals with square bracket inputs to\nfunctions) already knows this. `infer_instance` means \"find this construction in the\ndatabase\".\n\nBecause subgroups are a complete lattice, there will be a smallest subgroup `⊥` of `G`\nand a largest subgroup `⊤`. You can guess what these are (note that `⊥` isn't the empty set,\nthis isn't a subgroup). Let's get the hang of these subgroups. Here's their API\n(by the way, I don't have a clue about these APIs, I don't have them all committed to memory,\nI just write down the natural statements and then either guess the names of the proofs or\nuse `library_search`):\n\n-/\n\nexample : a ∈ (⊥ : subgroup G) ↔ a = 1 := subgroup.mem_bot\nexample : a ∈ (⊤ : subgroup G) := subgroup.mem_top a\n\n/-\n\n# Conjugating a subgroup by an element.\n\nLet's define the conjugate `xHx⁻¹` of a subgroup `H` by an element `x`. To do this we\nare going to have to know how to *make* subgroups, not just prove things about subgroups.\n\nTo create a subgroup of `G`, you need to give a subset of `G` and then a proof\nthat the subset satisfies the three axioms `one_mem`, `inv_mem` and `mul_mem` for subgroups. \nIf `H : subgroup G` and `x : G` then the *conjugate* of `H` by `x` is\nthe set `{a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹}`. So let's show that this set\nsatisfies the axioms for a subgroup.\n\n-/\n\nvariables {G H} {x : G}\n\nvariables (y z : G)\n\nlemma conjugate.one_mem : (1 : G) ∈ {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹} :=\nbegin\n  sorry,\nend\n\nlemma conjugate.inv_mem (hy : y ∈ {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹}) :\n  y⁻¹ ∈ {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹} :=\nbegin\n  sorry,\nend\n\nlemma conjugate.mul_mem (hy : y ∈ {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹})\n  (hz : z ∈ {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹}) : \n  y * z ∈ {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹} :=\nbegin\n  sorry,\nend\n\n-- Now here's the way to put everything together:\ndef conjugate (H : subgroup G) (x : G) : subgroup G :=\n{ carrier := {a : G | ∃ h, h ∈ H ∧ a = x * h * x⁻¹},\n  one_mem' := conjugate.one_mem,\n  inv_mem' := conjugate.inv_mem,\n  mul_mem' := conjugate.mul_mem, }\n\n/-\n\n## The cost of a definition\n\nYou might think \"we're done, we made conjugates\"! But not so fast!\n\nIf we were putting the definition of `conjugate` into mathlib then the next thing we would have to\ndo would be to prove a whole bunch of things about it. Every definition in a formalised system\ncomes with a cost. If you just make the definition and don't prove theorems about it,\nthen other people can't use your definition easily in their theorems. \n\nWhat kind of theorems would we want to prove about conjugates? We might want to prove\nthat if `H ≤ K` then `conjugate H x ≤ conjugate K x`. We might want to prove\nthat `conjugate ⊥ x = ⊥` and `conjugate ⊤ x = ⊤`. And we might want to prove\nthat if `G` is abelian then `conjugate H x = H` for all `H`. Before we embark on this,\nI had better tell you how to prove that two subgroups of a group are equal in Lean. \nTo check two subgroups are equal it suffices to prove they have the same elements:\nthis is called \"extensionality\" for subgroups, and you can make this step using the `ext`\ntactic. I'll show you below.\n\nLet's make some API for conjugates. I'll suggest some names for the lemmas.\n\n-/\n\n-- This one is always handy: you will be able to `rw` it when faced with goals\n-- of the form `a ∈ conjugate H x`.\n\nlemma mem_conjugate_iff : a ∈ conjugate H x ↔ ∃ h, h ∈ H ∧ a = x * h * x⁻¹ :=\nbegin\n  -- true by definition!\n  refl,\nend\n\nlemma conjugate_mono (H K : subgroup G) (h : H ≤ K) : conjugate H x ≤ conjugate K x :=\nbegin\n  -- start with `intro g` because the goal is definitionally \n  -- `∀ g, g ∈ conjugate H x → g ∈ conjugate K x`\n  sorry,\nend\n\nlemma conjugate_bot : conjugate ⊥ x = ⊥ :=\nbegin\n  -- recall that ⊥ is the trivial subgroup and I showed you the basic API for it above.\n  -- Start this proof with `ext a`.\n  sorry,\nend\n\nlemma conjugate_top : conjugate ⊤ x = ⊤ :=\nbegin\n  sorry,\nend\n\nlemma conjugate_eq_of_abelian (habelian : ∀ a b : G, a * b = b * a) : conjugate H x = H :=\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/section07subgroups_and_homomorphisms/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947132556618, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7915464351520932}}
{"text": "import SciLean\nopen SciLean\n\n/-!\n==========================\nDifferentiation in SciLean\n==========================\n\nThe backbone of any numerical/scientific/machine learing software is \nan automatic and/or symbolic differentiation. In SciLean, automatic and \nsymbolic differentiation is build on top of these two operators:\n\n1. Differential `∂ : (X → Y) → (X → X → Y)` \n\n2. Adjoint `†: (X → Y) → (Y → X)`\n\nThe differential `∂` tells us how much does the function `f : X → Y`\nchanges in the direction `dx : X` at the point `x : X`. The usual \nmathematical definition is:\n\n.. math:: \n\n  \\partial \\texttt{f x dx} := \\lim_{h \\rightarrow 0} \\frac{f(x + dx) - f(x)}{h}\n\n.. \n\nBecause mathlib is not yet ported to Lean 4 this definition is not used\nin SciLean. Right now, the differential `∂` is just postulated to exist.\n\n\nThe adjoint `†` is just well known matrix transposition. Thus for real\nvalued matrix `A`\n\n.. math:: (A^\\dagger)_{ij} = A_{ji}\n\n.. \n\nFor a general linear map `A : X → Y` between two Hilbert spaces `X` and `Y`, \nthe adjoint is defined via\n\n.. math :: \\langle A x, y \\rangle = \\langle x, A^\\dagger y \\rangle  \\qquad \\, \\forall x \\in X, \\,y \\in Y\n\n-/ \n\n/-!\n\nWe will show that these two operators give a rise to a whole zoo of operators\n\n1. Differential `∂ : (X → Y) → (X → X → Y)` \n\n2. Adjoint `†: (X → Y) → (Y → X)`\n\n3. Adjoint Differantial `∂† : (X → Y) → (X → Y → X)` \n\n4. Derivative `ⅆ : (ℝ → X) → (ℝ → X)` \n\n5. Gradient `∇ : (X → ℝ) → (X → X)`\n\n6. Divergence `∇· : (X → X) → (X → ℝ)`\n\n7. Forward Mode AD `fwdDiff : (X → Y) → (X → X×(X → Y))`\n\n8. Reverse Mode AD `revDiff : (X → Y) → (X → X×(Y → X))`\n\n9. Dual Number AD `dualDiff : (X → Y) → (X×X → Y×Y)`\n\n -/\n\n/-!\n\nDifferential\n============\n\n -/\n\nsection Differential\n\n/-!\n\nThe simples possible example: What is the differential of identity function?\n\n -/ \n\n  #check (∂ λ x : ℝ => x) \n    rewrite_by (simp; trace_state /- .unfold -/ )\n\n/-!\n\nAs expected the change of identity function is just `dx` and it does not depend\non the position `x`.\n\n\n(Note: The SciLean's custom notation `x:term rewrite_by t:convSeq` \napplies tactic `t` on the term `x`. This notation confuses the `#check` \ncommand. To see the actual result it is better to use the `trace_state` \ntactic. TODO: Add a document explaining the technical detail of `rewrite_by`\nnotation. TODO: Add delaborator for terms created with `AutoImpl`)\n\nAnother way to check that the differential is computed correctly\n\n -/\n\n example : (∂ λ x : ℝ => x) = (λ x dx => dx) := by simp\n\n/-!\n\nThis has the disadvantages that we need to know the result beforehand.\n\n\nFew more basic derivatives: of a constant, quadratic function, sine\n\n -/\n\n  #check (∂ λ x : ℝ => (1 : ℝ)) \n    rewrite_by \n    (simp; trace_state) /- .unfold -/\n\n  #check (∂ λ x : ℝ => x * x) \n    rewrite_by \n    (simp; trace_state) /- .unfold -/ \n\n  #check (∂ λ x : ℝ => Math.sin x) \n    rewrite_by \n    (simp; trace_state) /- .unfold -/ \n\n\n/-!\n\nThe result `fun x dx => dx * x + x * dx` is slightly undesirable. We \nwould like to get `fun x dx => 2 * dx * x`. Such algebraic manipulation\nis within the scope of mathlib's tactics so we will wait for mathlib\nport to Lean 4.\n\n -/\n\n/-!\n\nLet's introduce few generic functions  to demonstrate some general differentiation \nresults\n\n -/\n  variable {X Y Z : Type} [Vec X] [Vec Y] [Vec Z]\n  variable (f : Y → Z) [IsSmooth f]\n  variable (g : X → Y) [IsSmooth g]\n\n/-!\n\nThe most crucial tool when computing derivatives is the chain rule, as a proof\n\n -/ \n\n  example : (∂ λ x => f (g x)) = (λ x dx => ∂ f (g x) (∂ g x dx)) := \n    by simp\n\n/-!\n\nOr as a symbolic computation\n\n -/\n\n  #check (∂ λ x => f (g x)) \n    rewrite_by \n    (simp; trace_state) /- .unfold -/\n\n\n/-!\n\nAnother common rule is the product rule\n\n -/ \n\n  variable (ϕ ψ : ℝ → ℝ) [IsSmooth ϕ] [IsSmooth ψ]\n\n  #check (∂ λ x => ϕ x * ψ x) \n    rewrite_by \n    (simp; trace_state) /- .unfold -/\n\n/-!\n\nDerivative\n----------\n\nThe standard notion of derivative takes a function from reals to reals, `f : ℝ → ℝ`,\nand produces again a function from, usually denoted with `f' : ℝ → ℝ`. \n\nThe differential `∂` does not fit this. The well know result that \nderivative of exponential is exponential `exp' = exp` can't be expressed as \neasily with differential.\n\nThe naive statement does not even typecheck\n\n -/\n\n  #check_failure ∂ Math.exp = Math.exp \n\n/-!\n\nThe `exp' = exp` is this slightly cumbersome statement\n\n -/\n\n  example : (λ t => ∂ Math.exp t 1) = Math.exp := by simp\n\n/-!\n\nFor this reason we introduce a new operator, derivative `ⅆ : (ℝ → X) → (ℝ → X)`.\nWhich is defines as follows\n\n -/\n\n  example (f : ℝ → X) : ⅆ f = λ t => ∂ f t 1 := \n    by simp\n\n/-!\n\nNow we have \n\n -/\n\n  example : ⅆ Math.exp = Math.exp := by simp\n\n/-!\n\n(TODO: Right now simplifier needs to unfold `derivative`. Fix it!)\n\nWe provide convenient notation, `ⅆ t, f t` and `ⅆ (t:=t₀), f t`, for\ntaking derivative with a respect to an explicit variable.\n\n -/\n  section DerivativeNotation\n\n    variable (f : ℝ → X) (t₀ : ℝ)\n\n    -- effectively translates `t,` to `λ t =>`\n    example : (ⅆ t, f t) = ⅆ (λ t => f t ) := by rfl\n\n    -- similar as above but also applies `t₀` \n    example : (ⅆ (t:=t₀), f t) = ⅆ (λ t => f t) t₀ := by rfl\n\n  end DerivativeNotation\n\n/-!\n\n..\n\nThe notation `ⅆ (t:=t₀), f t` tries to mimick the mathematical notation\n\n.. math:: \\frac{d}{dt}\\bigg\\rvert_{t=t_0} f(t)\n\n -/ \n\n/-!\n\nDebugging Differentiation\n-------------------------\n\nSometimes the differentiation is not doing what we expect. It is crucial\nto know how to figure out what went wrong.\n\nTo demonstrate this, let's introduce a function `h` but without the smoothenss\nproof i.e. we do not introduce `[IsSmooth h]`\n\n -/\n\n  variable (h : X → Y)\n\n/-!\n\nNow the chain rule for `f` and `h` fails\n\n -/\n\n  example : (∂ λ x => f (h x)) = (λ x dx => ∂ f (h x) (∂ h x dx)) := \n    by simp   -- no progress\n       admit  -- we have to give up\n\n/-!\n\nWe have to use the `admit` tactic to close the goal as `simp` is unable \nto do it right now.\n\nThe problem is that `simp` can't apply chain rule because it is missing\nthe proof of smoothenss of `h`. To figure this out, we turn on the option\n`trace.Meta.Tactic.simp.discharge`\n\n -/\n\n  set_option trace.Meta.Tactic.simp.discharge true in\n  example : (∂ λ x => f (h x)) = (λ x dx => ∂ f (h x) (∂ h x dx)) := \n    by simp; admit\n\n/-!\n\nIf you click on `simp`, one of the messages will be\n\n::\n\n  [Meta.Tactic.simp.discharge] SciLean.diff_of_comp, failed to synthesize instance\n      SciLean.IsSmooth fun x => h x\n\n(TODO: currently there is tons of crap that should not be there)\n\nIf we provide the smoothenss proof we can observe all rewrites by turning on\n`trace.Meta.Tactic.simp.rewrite`\n\n-/\n\n  variable [IsSmooth h]\n\n  set_option trace.Meta.Tactic.simp.rewrite true in\n  example : (∂ λ x => f (h x)) = (λ x dx => ∂ f (h x) (∂ h x dx)) := \n    by simp\n\n/-!\n\nNow `simp` shows the application of the chain rule\n\n::\n\n  [Meta.Tactic.simp.rewrite] SciLean.diff_of_comp:99, ∂fun x =>\n        f (h x) ==> fun x dx => SciLean.differential f (h x) (SciLean.differential (fun x => h x) x dx)\n\n\nA bit more complicated computation\n\n -/\n\n  set_option trace.Meta.Tactic.simp.rewrite true in\n  #check (∂ λ x : ℝ => x * Math.exp (x*x) + x) \n    rewrite_by \n    (simp; trace_state) /- .unfold -/\n\n/-!\n\nClicking on `simp` reveals fairly long list of rewrites.\n\n -/ \n\nend Differential\n\n\n\n/-!\n\nDefining Differentiable Function\n================================\n\nSometimes we want to define our own differentiable functions\n\n -/\n\ndef square (x : ℝ) := x * x\n\n/-!\n\nWe might be surprized that differentiating this function does not work \n\n -/\n\nexample : (∂ square) = (λ x dx => dx * x + x * dx) :=\nby \n  simp  -- this does nothing as we know nothing about `square`\n  unfold square  -- unfold definition of `square`\n  simp  -- now it works\n\n/-!\n\nManually unfolding every definition can get tedious. To circumvent that, \nwe can anotate the definition of `square` to indicate that it is \ndifferentiable.\n\n -/ \n\ndef square_v1 (x : ℝ) : ℝ := x * x\nargument x\n  isSmooth, diff\n\n/-!\n\n(TODO: When using `def` with annotations, we **have to** explicitely specify \nthe return type. Remove this limitation or add a warrning when the\nreturn type is missing.)\n\nThe `argument x` specifies that everything that follows concerns the \nargument `x`. The `isSmooth` generates proof that `square_v1` is \nsmooth in the argument `x` and `diff` defines a new function \n`square_v1.arg_x.diff` that is the function's differential.\n\nThere are few variants that are usefull when full automation fails or\nproduces undesirable results.\n\n -/ \n\ndef square_v2 (x : ℝ) : ℝ := x * x\nargument x\n  -- specify how to prove smoothenss\n  isSmooth := by unfold square_v2; infer_instance,\n  -- specify what the differential is and how to prove it\n  diff := 2 * dx * x by simp[diff, square_v2]; funext x dx; ring\n\ndef square_v3 (x : ℝ) : ℝ := x * x\nargument x\n  -- proof is done automatically\n  isSmooth,\n  -- specify how to compute differential\n  diff by simp[square_v3]\n\n/-! \n\nDefining a new function, `square_v1.arg_x.diff` for the differential \ncan be undesirable. Sometimes we want `∂ square` to directly simplify\nto `λ x dx => dx * x + x * dx`. To achieve this, we use `diff_simp`\ninstead of `diff`.\n\n -/ \n\ndef square_v4 (x : ℝ) : ℝ := x * x\nargument x\n  isSmooth,\n  diff_simp by simp[square_v4]\n\n/-!\n\nThe `diff_simp` annotation allows the same variants as `diff`.\n\nProof that the second derivative is `2`. We have to do manual unfolding \nwhen working with `square_v3` but with `square_v4` the proof is immediate\n\n -/\n\nexample : (λ x => ∂ ∂ square_v2 x 1 1) = (λ x => 2) := \nby \n  simp  -- simp gets stopped on `square_v3.arg_x.diff`\n  unfold square_v2.arg_x.diff -- manually unfold definition\n  simp  -- we can continue with computation\n\nexample : (λ x => ∂ ∂ square_v4 x 1 1) = (λ x => 2) := \nby \n  simp  -- done immediately\n\n/-!\n\nWe missed our chance to add annotations to the original function `square`.\nWe can add additional annotations later on with `function_properties`. \n\n-/\n\nfunction_properties square (x : ℝ) : ℝ  \nargument x\n  isSmooth, diff_simp\n\n-- now we can differentiate `square`\nexample : ∂ square = λ x dx => dx * x + x * dx := by simp\n\n/-!\n\nThe keyword `function_properties` works exactly like `def` with annotations\nbut you do not provide the function definition `:= ...`. Argument types \nand order have to match exactly the original definition but the argument \nnames do not have to be the same.\n\n -/\n\n/-!\n\nMultiple Arguments\n------------------\n\n(TODO: Explain how annotations work with multiple arguments. The current\nbehavior is a bit limiting, so I should rewrite how they work before \nI write this section.)\n\n -/\n\n/-!\n\nHow Do Annotations Work?\n------------------------\n\nThe `isSmooth` and `diff` annotations might appear misterious but they\nare simple macros.\n\nThis definition \n -/\n\ndef cube (x : ℝ) : ℝ := x * x * x\nargument x\n  isSmooth := by unfold cube; infer_instance,\n  diff := 3 * dx * x * x by simp[diff,cube]; funext x dx; ring\n\n/-!\n\nIs unfolded to (we have to use a new identifier `cube_v1` as `cube` is \nalready defined)\n\n -/\n\ndef cube_v1 (x : ℝ) : ℝ := x * x * x\n\n-- proof of smoothness\ninstance cube_v1.arg_x.isSmooth : IsSmooth (λ x => cube_v1 x) := \nby unfold cube_v1; infer_instance\n\n-- differential definition\ndef cube_v1.arg_x.diff (x dx : ℝ) : ℝ := 3 * dx * x * x\n\n-- simplifier rule\n@[simp]\ntheorem cube_v1.arg_x.diff_simp \n  : ∂ cube_v1 = cube_v1.arg_x.diff :=\nby simp[diff,cube_v1]; funext x dx; ring\n\n/-! \n\nUsing `diff_simp` annotation does not define `cube_v1.arg_x.diff` and \nthe simp theorem states directly `∂ cube_v1 = λ x dx => 3 * dx * x * x`.\n\n -/\n\n/-!\n\nAdjoint Differential\n====================\n\nFinding the minimum of a function `f : X → ℝ` with gradient descent \nrequires function's gradient `∇ f : X → X`.\n\nHowever, can we compute the gradient just with the differential `∂`? \nNo we can't! We need an adjoint `†` too!\n\nThe differential `∂ f x` at point `x` is a linear function `X → R`.\nWhen we take an adjoint and apply one we get an element of `X`. That \nis the gradient of `f` at `x`!\n\nIn finite dimension, we can think about differential `∂ f x` is a row vector.\nTo get a column vector we have to transpose it i.e. take its adjoint.\n\nFor general function `f : X → Y`, we define adjoint differential \n`∂† : (X → Y) → (X → Y → X)` as `∂† f x dy := (∂ f x)† dy`\n\nTaking adjoint makes sense only for functions between Hilberts spaces.\nLet's introduce few of those\n\n -/ \n\nsection AdjointDifferential\n\n  variable {X Y Z} [Hilbert X] [Hilbert Y] [Hilbert Z]\n\n/-!\n\nTo stress the definition of adjoint differential\n\n -/\n\n  example (f : X → Y) : ∂† f = λ x dy => (∂ f x)† dy := by rfl\n\n/-!\n\nSimilarly to derivative `ⅆ`, we define a specialized operator gradient `∇`\nfor real valued functions over any Hilbert space\n\n -/\n\n  example (f : X → ℝ) : ∇ f = λ x => (∂ f x)† 1 := by rfl\n\n/-!\n\nThe important result is that the gradient of squared norm `∥x∥²` is `2*x`\n\n -/\n\n\n  #check (∇ (x : X), ∥x∥²) \n    rewrite_by \n    (simp; trace_state)  /- .unfold -/\n\n/-!\n\n(TODO: Make sure we do not need to unfold gradient and hold here`)\n\nAnother fun result is that the gradient of `⟪A x, x⟫` is `(A† + A) x`\n\n -/\n\n  variable (A : X → X) [HasAdjDiff A] [IsLin A]\n\n  #check (∇ x, ⟪A x, x⟫) \n    rewrite_by \n    (simp[adjointDifferential]; trace_state) /- .unfold -/\n\n/-!\n\n(TODO: Ughh, this requires too many assumptions on A and too many unfolding`)\n\nSimilar to chain rule for differential, we have a chain rule for the adjoint \ndifferential but the composition is in reverse\n\n -/\n\n  variable (f : Y → Z) [HasAdjDiff f]\n  variable (g : X → Y) [HasAdjDiff g]\n\n  example : (∂† λ x => f (g x)) = (λ x dz => ∂† g x (∂† f (g x) dz)) := \n    by simp\n\n/-!\n\n(TODO: Explain what `HasAdjDiff f` is)\n\n -/ \n\n\n/-!\n\nEuler-Lagrange Equations\n------------------------\n\nLet's write down Euler-Lagrange equations to demonstrate SciLean's notation\nin a bit complicated scenario.\n\nThey are usally written in the following way\n\n.. math:: \\frac{d}{dt} \\frac{\\partial}{\\partial \\dot x} L(x(t),\\dot x(t)) - \\frac{\\partial}{\\partial x} L(x(t),\\dot x(t)) = 0\n\nHowever, the partial derivative notation is really ambigous. Thus a bit\nmore explicit form is\n\n.. math:: \\frac{d}{ds}\\bigg\\rvert_{s=t} \\frac{\\partial}{\\partial v}\\bigg\\rvert_{v=\\dot y(s)} L(y(s),v) - \\frac{\\partial}{\\partial x}\\bigg\\rvert_{x=y(t)} L(x, \\dot y(t)) = 0\n\nAnd this form can be written in SciLean relativelly nicely.\n \n -/\n\n  variable (L : X → X → ℝ)  -- Lagrangian \n  variable (y : ℝ → X)      -- trajectory \n  variable (t : ℝ)          -- time\n\n  #check \n    ⅆ (s:=t), ∇ (v:=ⅆ y s), L (y s) v - ∇ (x:=y t), L x (ⅆ y t) = 0\n\n/-!\n\nLet's plug in a Lagrangian for a particle in a potential field and hopefully \nwe get the correct equations of motion.\n\n -/\n  def L' (ϕ : X → ℝ) (m : ℝ) (x v : X) := 1/2*m*∥v∥² - ϕ x\n   \n  variable [IsSmooth y]  -- trajectory is smooth\n  variable (ϕ : X → ℝ)  [HasAdjDiff ϕ]\n  variable (m : ℝ) -- mass\n\n  #check \n    (ⅆ (s:=t), ∇ (v:=ⅆ y s), L' ϕ m (y s) v \n     - \n     ∇ (x:=y t), L' ϕ m x (ⅆ y t))\n    rewrite_by \n    (-- Currently broken :(\n     -- simp\n     -- simp[gradient,hold]\n     -- simp[derivative]\n     trace_state) /- .unfold -/\n\n/-!\n\n(TODO: Make sure we get these rewrite to make the result look nicer\n\n  `2 * (1/2) = 1`\n \n  `differential (∂y) t 1 1 = ⅆ (ⅆ y) t` \n\n  `adjointDifferential (fun x => ϕ x) (y t) (-1) = - ∇ ϕ (y t)`)\n\nThe result is (with the TODO rewrites) `m * ⅆ (ⅆ y) t + ∇ ϕ (y t)` which \nexacly corresponts to the equation of a particle in a potential field `ϕ`\n\n.. math:: m \\ddot y(t) = - \\nabla \\phi (y(t))\n\n -/\n\nend AdjointDifferential\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/doc/literate/differentiation_in_scilean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7915212627197634}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\n# Function world.\n\n## Level 7: `(P → Q) → ((Q → R) → (P → R))`\n\nIf you start with `intro hpq` and then `intro hqr`\nthe dust will clear a bit and the level will look like this:\n```\nP Q R : Prop,\nhpq : P → Q,\nhqr : Q → R\n⊢ P → R\n```\nSo this level is really about showing transitivity of `⟹`,\nif you like that sort of language.\n\n## Lemma : imp_trans\n\nFrom `P ⟹ Q` and `Q ⟹ R` we can deduce `P ⟹ R`.\n-/\nlemma imp_trans (P Q R : Prop) : (P → Q) → ((Q → R) → (P → R)) := by\n  intros hpq hqr\n  intro p\n  apply hqr\n  apply hpq\n  assumption\n\n/-!\nHere we finish this proof with a new tactic `assumption` instead of `exact p`.\nThe `assumption` tactic tries to solve the goal using a\nhypothesis of compatible type.  Since we have the hypothesis named `p` it finds\nit and completes the proof.\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/PropositionWorld/Level7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067228145364, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7914549099068101}}
{"text": "import data.real.basic\nimport tactic\n/-\nQ2. The functions f , g : ℝ → ℝ are defined as follows:\nf(x) = 2x if 0 ≤ x ≤ 1, and f (x) = 1 otherwise;\ng(x) = x^2 if 0 ≤ x ≤ 1, and g(x) = 0 otherwise.\n\nGive formulae describing the functions `g ∘ f` and\n`f ∘ g`. (Draw the graphs of these functions.)\n-/\n\nnoncomputable theory\n\ndef f (x : ℝ) := if 0 ≤ x ∧ x ≤ 1 then 2 * x else 1\n\ndef g (x : ℝ) := if 0 ≤ x ∧ x ≤ 1 then x ^ 2 else 0\n\nexample (x : ℝ) : (g ∘ f) x = if 0 ≤ x ∧ x ≤ 1/2 then 4 * x ^ 2 else if 1/2 < x ∧ x ≤ 1 then 0 else 1 -- replace with formula for g ∘ f\n:= \nbegin\n  change g (f x) = _,\n  unfold f,\n  unfold g,\n  split_ifs;\n  try {simp};\n  try {rw not_and_distrib at *};\n  try {cases h};\n  try {cases h_1};\n  try {cases h_2};\n  try {cases h_3};\n  try {linarith},\nend\n\nexample (x : ℝ) : (f ∘ g) x = if 0 ≤ x ∧ x ≤ 1 then 2 * x ^ 2 else 0 \n:= \nbegin\n  change f (g x) = _,\n  unfold f,\n  unfold g,\n  split_ifs;\n  try {simp};\n  try {rw not_and_distrib at *};\n  try {cases h};\n  try {cases h_1};\n  try {nlinarith},\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/chapter19/exercises/exercise02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.791454908550705}}
{"text": "/-\nCopyright (c) 2019 Yury Kudriashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudriashov, Yaël Dillies\n\n! This file was ported from Lean 3 source module analysis.convex.complex\n! leanprover-community/mathlib commit 15730e8d0af237a2ebafeb8cfbbcf71f6160c2e9\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.Basic\nimport Mathbin.Data.Complex.Module\n\n/-!\n# Convexity of half spaces in ℂ\n\nThe open and closed half-spaces in ℂ given by an inequality on either the real or imaginary part\nare all convex over ℝ.\n-/\n\n\ntheorem convex_halfspace_re_lt (r : ℝ) : Convex ℝ { c : ℂ | c.re < r } :=\n  convex_halfspace_lt (IsLinearMap.mk Complex.add_re Complex.smul_re) _\n#align convex_halfspace_re_lt convex_halfspace_re_lt\n\ntheorem convex_halfspace_re_le (r : ℝ) : Convex ℝ { c : ℂ | c.re ≤ r } :=\n  convex_halfspace_le (IsLinearMap.mk Complex.add_re Complex.smul_re) _\n#align convex_halfspace_re_le convex_halfspace_re_le\n\ntheorem convex_halfspace_re_gt (r : ℝ) : Convex ℝ { c : ℂ | r < c.re } :=\n  convex_halfspace_gt (IsLinearMap.mk Complex.add_re Complex.smul_re) _\n#align convex_halfspace_re_gt convex_halfspace_re_gt\n\ntheorem convex_halfspace_re_ge (r : ℝ) : Convex ℝ { c : ℂ | r ≤ c.re } :=\n  convex_halfspace_ge (IsLinearMap.mk Complex.add_re Complex.smul_re) _\n#align convex_halfspace_re_ge convex_halfspace_re_ge\n\ntheorem convex_halfspace_im_lt (r : ℝ) : Convex ℝ { c : ℂ | c.im < r } :=\n  convex_halfspace_lt (IsLinearMap.mk Complex.add_im Complex.smul_im) _\n#align convex_halfspace_im_lt convex_halfspace_im_lt\n\ntheorem convex_halfspace_im_le (r : ℝ) : Convex ℝ { c : ℂ | c.im ≤ r } :=\n  convex_halfspace_le (IsLinearMap.mk Complex.add_im Complex.smul_im) _\n#align convex_halfspace_im_le convex_halfspace_im_le\n\ntheorem convex_halfspace_im_gt (r : ℝ) : Convex ℝ { c : ℂ | r < c.im } :=\n  convex_halfspace_gt (IsLinearMap.mk Complex.add_im Complex.smul_im) _\n#align convex_halfspace_im_gt convex_halfspace_im_gt\n\ntheorem convex_halfspace_im_ge (r : ℝ) : Convex ℝ { c : ℂ | r ≤ c.im } :=\n  convex_halfspace_ge (IsLinearMap.mk Complex.add_im Complex.smul_im) _\n#align convex_halfspace_im_ge convex_halfspace_im_ge\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/Complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7912493162864117}}
{"text": "import Mynat.Add\n\nnamespace mynat\n\ndef mymul (m n : mynat) : mynat :=\n  match n with\n  | zero => zero\n  | succ n' => myadd (mymul m n') m\n\ninstance : Mul mynat where\n  mul := mymul\n\ntheorem mul_zero (a : mynat) : a * 0 = 0 := rfl\ntheorem mul_succ (a b : mynat) : a * (succ b) = a * b + a := rfl\n\ntheorem zero_mul (m : mynat) : 0 * m = 0 := by\n  cases m\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rfl\n  case succ m' =>\n    rw [mul_succ]\n    rw [zero_mul m']\n    rfl\n\ntheorem mul_one (m : mynat) : m * 1 = m := by\n  rw [one_eq_succ_zero]\n  rw [mul_succ]\n  rw [mul_zero]\n  rw [zero_add]\n\ntheorem one_mul (m : mynat) : 1 * m = m := by\n  cases m\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [mul_zero]\n  case succ m' =>\n    rw [mul_succ]\n    rw [one_mul m']\n    rw [succ_eq_add_one]\n\ntheorem mul_add (t a b : mynat) : t * (a + b) = t * a + t * b := by\n  cases b\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [add_zero]\n    rw [mul_zero]\n    rw [add_zero]\n  case succ b' =>\n    rw [add_succ]\n    rw [mul_succ]\n    rw [mul_succ]\n    rw [mul_add t a b']\n    rw [add_assoc]\n\ntheorem mul_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    rw [mul_zero]\n    rw [mul_zero]\n    rw [mul_zero]\n  case succ c' =>\n    rw [mul_succ]\n    rw [mul_succ]\n    rw [mul_assoc a b c', mul_add]\n\ntheorem succ_mul (a b : mynat) : succ a * b = a * b + b := by\n  cases b\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [mul_zero]\n    rw [mul_zero]\n    rfl\n  case succ b' =>\n    rw [mul_succ]\n    rw [mul_succ]\n    rw [succ_mul a b']\n    rw [add_succ]\n    rw [add_succ]\n    rw [add_assoc]\n    rw [add_comm b' a]\n    rw [add_assoc]\n\ntheorem add_mul (a b t : mynat) : (a + b) * t = a * t + b * t := by\n  cases t\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    repeat {rw [mul_zero]}\n    rfl\n  case succ t' =>\n    rw [mul_succ]\n    rw [mul_succ]\n    rw [mul_succ]\n    rw [add_mul a b t']\n    rw [← add_assoc]\n    rw [← add_assoc]\n    rw [add_assoc (a * t') (b * t') a]\n    rw [add_comm (b * t') a]\n    rw [add_assoc (a * t') a (b * t')]\n\ntheorem mul_comm (a b : mynat) : a * b = b * a := by\n  cases b\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [mul_zero]\n    rw [zero_mul]\n  case succ b' =>\n    rw [mul_succ]\n    rw [succ_mul]\n    rw [mul_comm a b']\n\ntheorem mul_left_comm (a b c : mynat) : a * (b * c) = b * (a * c) := by\n  rw [← mul_assoc]\n  rw [← mul_assoc]\n  rw [mul_comm a b]\n\nattribute [simp] mul_assoc mul_comm mul_left_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/Mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7912493126535701}}
{"text": "import Mathlib\n\n/-!\n# Propositions as Types\n\n* We can represent propositions as types, or interpret (slightly restricted) types as propositions. \n* A proof of a proposition is a term of the corresponding type.\n* Defining and proving are essentially the same thing.\n* The same foundational rules let us construct propostions and proofs as well as terms and types.\n-/\n\n/-!\n## Main correspondence\n\n* `A → B` is functions from `A` to `B` as well as `A` implies `B`.\n* Function application is the same as *modus ponens*.\n* So if we have propositions `A` and `B`, we can construct a proposition `A → B` corresponding to implication.\n-/\n\nuniverse u\n\ndef functionApplication {A B : Type u} (f : A → B) (a : A) : B := f a\n\ndef modus_ponens {A B : Prop} (h₁ : A → B) (h₂ : A) : B := h₁ h₂\n\n/-!\n## Other Combination\n\n* `A ∧ B` is the conjunction of `A` and `B`.\n* `A ∨ B` is the disjunction of `A` and `B`.\n* `¬ A` is the negation of `A`.\n\nAll these can be constructed by our rules.\n\n\n-/\n\n#check And\n#check Prod\n\n/-!\n## Conjuction and Product\n\n```lean\nstructure And (a b : Prop) : Prop where\n  /-- `And.intro : a → b → a ∧ b` is the constructor for the And operation. -/\n  intro ::\n  /-- Extract the left conjunct from a conjunction. `h : a ∧ 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 ∧ b` then\n  `h.right`, also notated as `h.2`, is a proof of `b`. -/\n  right : b\n```\n\nThis is the same as the product type:\n\n```lean\nstructure Prod (α : Type u) (β : Type v) where\n  /-- The first projection out of a pair. if `p : α × β` then `p.1 : α`. -/\n  fst : α\n  /-- The second projection out of a pair. if `p : α × β` then `p.2 : β`. -/\n  snd : β\n```\n-/\n\ninductive MyOr (A B : Prop) : Prop\n| inl : A → MyOr A B\n| inr : B → MyOr A B\n\n#check Or\n#check Sum\n\n/-!\n# Disjunction and Sum\n\n```lean\ninductive Or (a b : Prop) : Prop where\n  /-- `Or.inl` is \"left injection\" into an `Or`. If `h : a` then `Or.inl h : a ∨ 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 ∨ b`. -/\n  | inr (h : b) : Or a b\n```\n\nThis is the same as the sum type:\n\n```lean\ninductive Sum (α : Type u) (β : Type v) where\n  /-- Left injection into the sum type `α ⊕ β`. If `a : α` then `.inl a : α ⊕ β`. -/\n  | inl (val : α) : Sum α β\n  /-- Right injection into the sum type `α ⊕ β`. If `b : β` then `.inr b : α ⊕ β`. -/\n  | inr (val : β) : Sum α β\n```\n-/\n\n#check True\n#check False\n\n/-!\n## True and False\n\nThese are analogues of `Unit` and `Empty`:\n\n```lean\ninductive True : Prop where\n  /-- `True` is true, and `True.intro` (or more commonly, `trivial`)\n  is the proof. -/\n  | intro : True\n\ninductive False : Prop\n```\n-/\n\n/-!\n## Negation\n\nThe negation of a type (or proposition) `A` is `¬ A`, which is the type (or proposition) `A → False`.\n\n-/\n\ntheorem everything_implies_true (A : Prop) : A → True := fun _ => True.intro\n\ntheorem false_implies_everything (A : Prop) : False → A := fun h => nomatch h\n\n#check False.rec -- False.rec.{u} (motive : False → Sort u) (t : False) : motive t\n\n#check False.rec (motive := fun _ => 1 = 2) -- False → 1 = 2\n\nexample {A B : Prop}: A → B → A :=\n  fun a _ ↦ a\n\n#check Iff\n\n/-!\n## If and only if\n\n```lean\nstructure Iff (a b : Prop) : Prop where\n  /-- If `a → b` and `b → a` then `a` and `b` are equivalent. -/\n  intro ::\n  /-- Modus ponens for if and only if. If `a ↔ b` and `a`, then `b`. -/\n  mp : a → b\n  /-- Modus ponens for if and only if, reversed. If `a ↔ b` and `b`, then `a`. -/\n  mpr : b → a\n```\n-/\n\nexample {A B : Prop}: (A ↔  B) =\n      ((A → B) ∧ (B → A)) := by\n  apply propext\n  apply Iff.intro\n  case a.mp => \n    intro h\n    apply And.intro\n    · exact h.mp\n    · exact h.mpr\n  case a.mpr => \n    intro h\n    apply Iff.intro\n    · exact h.left\n    · exact h.right\n\n/-!\n## Universal Quantifiers\n\n* A proposition associated to each term of a type `A` is a function `A → Prop`.\n* The propostion `∀ x : A, P x` is the proposition that `P x` is true for all `x : A`, which is the dependent function type\n`(x: A) → P x`.\n\n-/\n\n\n#check Exists\n\n/-!\n## Existential Quantifiers\n\n```lean\ninductive Exists {α : Sort u} (p : α → Prop) : Prop where\n  /-- Existential introduction. If `a : α` and `h : p a`,\n  then `⟨a, h⟩` is a proof that `∃ x : α, p x`. -/\n  | intro (w : α) (h : p w) : Exists p\n```\n-/\n\n#check Nat.le\n#check Eq\n\n/-! \n## Basic types\n\nWe have seen `≤` can be constructed as indexed inductive type:\n\n```lean\ninductive Nat.le (n : Nat) : Nat → Prop\n  /-- Less-equal is reflexive: `n ≤ n` -/\n  | refl     : Nat.le n n\n  /-- If `n ≤ m`, then `n ≤ m + 1`. -/\n  | step {m} : Nat.le n m → Nat.le n (succ m)\n```\n\nThe equality type is also indexed inductive type:\n\n```lean\ninductive Eq : α → α → Prop where\n  /-- `Eq.refl a : a = a` is reflexivity, the unique constructor of the\n  equality type. See also `rfl`, which is usually used instead. -/\n  | refl (a : α) : Eq a a\n```\n-/\n\nexample {α β : Type}{f g : α → β} (x y : α ): \n  f = g → x = y → f x = g y := by\n  intro hfg hxy\n  match f, g, hfg, x, y, hxy with\n  | f, .(f), rfl, x, .(x), rfl => rfl", "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_02_15/PropsAsTypes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7912492995813163}}
{"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\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 `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 : ℕ) (s : set ℕ) : Prop :=\nis_greatest {k | k ∉ add_submonoid.closure (s)} n\n\nvariables {m n : ℕ}\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 ≤ 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 ⊢,\n    rw [← sub_eq_zero] at h ⊢, rw ← 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 ≤ k,\n    { obtain ⟨a, ha⟩ := modeq_zero_iff_dvd.mp x.2.1,\n      obtain ⟨b, hb⟩ := (modeq_iff_dvd' key).mp x.2.2,\n      exact ⟨a, b, by rw [mul_comm, ←ha, mul_comm, ←hb, nat.add_sub_of_le key]⟩, },\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": "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/frobenius_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7912431672867486}}
{"text": "import init.meta.well_founded_tactics\nimport tactic.norm_num\nopen well_founded\nopen nat\ndef euclid_n : nat → nat → nat\n| 0        b:= 0\n| (succ c) b := have b % succ c < succ c, from mod_lt _ $ succ_pos _,\n                succ (euclid_n (b % succ c) (succ c))\n                --copied from mathlib gcd definition\ndef euclid_r: ℕ→ℕ→ℕ→ℕ\n    | b c 0        := b\n    | b c (succ n) := euclid_r b c n\ntheorem r_gcd: ∀ b c n:ℕ,euclid_n c b= succ n→euclid_r b c n = gcd c b:=begin\n    assume b c n,\n    induction c with c1 Hi,\n    cases n with n1,unfold euclid_r,\nend\ntheorem decreasingd: ∀ b c n:ℕ ,euclid_n c b =n → euclid_r b c n=gcd b c\n| b 0 0                 :=by {unfold euclid_r euclid_n,simp}\n| b (succ c) 0          :=by {unfold euclid_n,simp [succ_ne_zero]}\n| b 0 (succ n)          :=by {unfold euclid_n,rw eq_comm,simp [succ_ne_zero]}\n| b (succ c) (succ n)   :=by{unfold euclid_r euclid_n,intro, rw gcd exact decreasingd (succ c) (b%succ c) n (succ_inj a)}\ndef euclid_q: ℕ→ℕ→ℕ→ℕ\n    | b c 0     := 0\n    | b c (succ n) := euclid_r c (b%c) n / euclid_r b c n\ndef euclid_x: ℕ→ℕ→ℕ→ℤ\n    | b c 0     := 0\n    | b c (succ n) := euclid_x c (b%c) n - euclid_q b c (succ n) * euclid_x b c n\n\ntheorem bezout: ∀ b c:ℕ,∃x y:ℤ, ↑b*x+↑c*y = ↑(gcd b c):=begin\n    assume b c,\n    apply gcd.induction b c,\n    unfold gcd,intro n,existsi (10909301:int),existsi (1:int),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,cc,\n    unfold gcd,rw ←Hxy,existsi -↑(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,\n    rw H,rw [int.coe_nat_sub,mul_add,add_assoc,add_comm (↑(succ m) * y1) (↑n * x1),←add_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\n#print gcd.induction", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/bezout.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7912431669114484}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nimport AdditionWorld.Level1 -- zero_add\nimport AdditionWorld.Level5 -- one_eq_succ_zero\nnamespace MyNat\nopen MyNat\n\n/-!\n# Multiplication World\n\n## Level 2: `mul_one`\n\nIn this level we'll need to use\n\n* `one_eq_succ_zero : 1 = succ 0`\n\nwhich was mentioned back in [Addition World Level 5](../AdditionWorld/Level5.lean.md) and which will\nbe a useful thing to rewrite right now, as we begin to prove a couple of lemmas about how `1`\nbehaves with respect to multiplication.\n\n## Lemma\n\nFor any natural number `m`, we have `m * 1 = m.`\n-/\nlemma mul_one (m : MyNat) : m * 1 = m := by\n  rw [one_eq_succ_zero]\n  rw [mul_succ]\n  rw [mul_zero]\n  rw [zero_add]\n\n/-!\nNotice how all our theorems are nicely building on each other.\n\nNext up is [Multiplication Level 3](./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/MultiplicationWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799586, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7911345046219844}}
{"text": "/-\n| REESE ALLEN (rga2uz)\n| CS2102 S20 Sullivan\n| Final Exam\n-/\n\n\n/-\n1. You know from our study of the Boolean \nsatisfiability problem that there are 2^n\npossible combinations of Boolean values for\nn Boolean variables. \n\nLet's make the property of\nnatural numbers that is at issue clear by\ndefining \"P n\" to be proposition that \"the\nnumber of possible combinations of values\nfor *n* Boolean variables is *2^n*.\"\n\nWhat your are to prove is the proposition\nthat this is true for any value of n. That\nis, you are to prove ∀ n, P n.\n\nMext, recall that a proof of a universal\ngeneralization (such as ∀ n, P n) *by induction*\nis based on the application of the *induction\nprinciple* for for the given data type. Here \nthe data type is ℕ, and the induction rule for\nℕ is as follows:\n\n∀ {P : Prop}, \nP 0 → \n(∀ n', P n' → P (n' + 1)) → \n∀ n, P n.\n\nReading backwards, this says that if you\nwant to prove ∀ n, P n, it will *suffice*\nto prove P 0 and ∀ n', P n' → P (n' + 1)).\nThe reason is that you can then apply the\nrule to deduce that ∀ n, P n must be true.\nIn other words, you can reduce the task of\nproving ∀ n, P n to the tasks of proving\nthe two antecedents of this conclusion in\nthe induction rule.\n-/\n\n\n/-\n*ANSWER* \n\nTheorem: For any natural number, n, the\nnumber of combinations of values for n\nBoolean variables is 2^n.\n\nProof: By induction. To prove ∀ n, P n,\nwhere P is defined to be the proposition,\n\"the number of possible combinations of\nvalues for n Boolean variables is 2^n,\"\nit will suffice to prove P 0 and \n∀ n', P n' → (n' + 1)\n\n\nHere is a more complete quasi-formal version \nof the proof with algebra: \n\nOur aim is to prove the predicate [P(n)], which \nsays that for any ℕ n, the number of possible \ncombinations of values, i.e. interpretations, for \nn Boolean variables is 2^n. We do so inductively \nand must first prove / show two things: [1] The \nproposition P is true for n = 0, our base case. \n[2] If we assume the number of combinations for n' \nBoolean variables is 2^n' for some arbitrary but \nspecific ℕ n', our induction hypothesis, then the \nnumber of combinations of (n' + 1) Boolean \nvariables is 2^(n' + 1). \n\nBy the principle of induction, through assuming \nP(n') is true and using it to prove that P(n' + 1) \nis true, we can conclude that P(n) is true for \nall ℕs n. \n\n[1] This is easy. Our base case says that for zero \nBoolean variables, there is one combination. \nWe treat P(0) = 1 almost like an axiom. We have \ndefined the number of combinations of values for \n0 Boolean variables to be 1. This is certainly true. \n\n[2] We can prove this second step algebraically. I'm \ngoing to use k here to represent n' because it is a\nbit cleaner to read. Assuming P(k) = 2^k is true,\nwe want to show P(k + 1) = 2^(k + 1) is true.\n2^(k + 1) is equivalent to (2^k) + (2^1) by our\nrules of exponents, which is equivalent to \n(2^k) * 2; it follows that P(k + 1) = P(k) * 2. \nBecause P(k) is true for any k, it must be that \nP(n) is true for any n. \n-/\n\n\n\n\n/-  2  -/\n\ndef aProp :=    ∀ (α : Type), ∀ (Heavy Charmed: α → Prop),\n                (∃ (a : α), Heavy a ∧ Charmed a) →\n                (∃ (a : α), Charmed a)\n\n\n/- \n2a. English language rendition of this proposition:\n\nThe proposition aProp says suppose that you have \nojects of some type α and that Heavy and Charmed \nare properties of type α. If there exists an \nobject a of type α that is both Heavy and Charmed,\nthen there exists some object that is only Charmed. \n-/\n\n\n/- 2b. Give a formal proof of it. -/\n\nexample : aProp := \nλ α : Type, \n    λ H C : α → Prop,\n        λ hac : ∃ (a : α), H a ∧ C a,\n        match hac with \n        | exists.intro obj pf := let Cobj := pf.right in\n            exists.intro obj Cobj \n        end \n\n\n/- \n2c. Quasi-formal, English-language proof:\n\nTo prove the proposition aProp, we suppose that objects \nof type α exist and that Heavy and Charmed are predicates \nthat take an object of type α as an argument and return a \nproposition, which could be true or false. We will just \nsay that heavy and charmed are properties of these \nobjects. Denoting an object of type α as a and the \npredicates Heavy and Charmed as H and C, respectively,\nwhen we say that there is a proof of heavy and charmed,\nfor example, what we mean is that there is a proof that \nthe conjunction of H(a) and C(a) is true. \n\nIn this context, we want to prove an implication by \nshowing that if there is an object that is both heavy \nand charmed, then there is an object that is charmed. \nGiven a proof that objects of type α exist that are both \nheavy and charmed, which we call hac, we can deduce that \nthere is an object that has the properties of heavy and \ncharmed. We assume this by reasoning through case analysis \nand with existential instantiation, i.e. the exists \nintroduction rule. We call our single arbitrary but \nspecific object of type α obj. The only case in which our \nproof hac could have been constructed is by applying the \nexists introduction rule to obj and a proof that heavy \nand charmed is true, i.e. that obj has the properties of \nheavy and charmed, which we call pf. The proof pf is \nconstructed through conjunction introduction, another rule \nof inference. We can destructure pf with the right \nelimination rule; given a proof of heavy and charmed, we \ncan derive a proof of just charmed, which we call Cobj. \nWe can then use instantiation again by applying the exists \nintroduction rule to our object obj and our proof of \ncharmed Cobj. By showing that a proof that an object of \ntype α can be constructed from a proof that objects of \ntype α exist with the properties of heavy and charmed, \nwe have proved aProp.\n-/\n\n\n\n/-  3  -/\n\ndef aProp2 :=   ∀ (α : Type), ∀ (Heavy Charmed: α → Prop),\n                (∃ (a : α), Heavy a ∨ Charmed a) →\n                (∃ (a : α), Heavy a) ∨ (∃ (a : α), Charmed a)\n\n\n/- \n3a. English language rendition of this proposition:\n\nThe proposition aProp2 says suppose that you have \nobjects of some type α and that Heavy and Charmed \nare properties of type α. If there exists an \nobject a of type α that is Heavy or Charmed, then \nthere exists an object that is just Heavy or there\nexists an object that is just Charmed. \n-/\n\n\n/- 3b. Give a formal proof of it. -/\n\nexample : aProp2 := \nλ α : Type,\n    λ H C : α → Prop, \n        λ hoc : ∃ (a : α), H a ∨ C a, \n        match hoc with\n        | exists.intro obj pf := \n            match pf with \n            | or.inl h := or.inl (exists.intro obj h)\n            | or.inr c := or.inr (exists.intro obj c)\n            end \n\n        end \n\n\n/- \n3c. Quasi-formal, English-language proof:\n\nTo prove the proposition aProp2, we suppose that objects \nof type α exist and that Heavy and Charmed are predicates \nthat take an object of type α as an argument and return a \nproposition, which could be true or false. We will just \nsay that heavy and charmed are properties of these objects. \n\nWhen we say that there is a proof of heavy or charmed, \nfor example, what we mean is that there is a proof that \nthe disjunction of the predicates Heavy and Charmed, when \neach is given an object of type α, is true. This is \nanalogous to saying that the object has the property of \nheavy, the property of charmed, or both.   \n\nIn this context, we want to prove an implication \nby showing that if there is an object that is heavy or \ncharmed, then there is an object that is heavy or there \nis an object that is charmed. Given a proof that objects of \ntype α exist that are heavy or charmed, which we call hoc, \nwe can deduce that there is an object that has the properties\nof heavy or charmed. We assume this by reasoning through \ncase analysis and with existential instantiation, i.e. the \nexists introduction rule. We call our single arbitrary but \nspecific object of type α obj. The only case in which our \nproof hoc could have been constructed is by applying the \nexists introduction rule of inference to obj and a proof \nthat obj is heavy or charmed, which we call pf. The proof \npf is constructed through disjunction introduction. Using \ncase analysis again, we can destructure pf to show the two\nways in which it could have been formed. A proof of a \ndisjunction is constructed either from a proof of the left\ndisjunct or a proof of the right disjunct. We assume that \nour object obj has the property of heavy in the first case, \nthe proof of which we denote as h, and that obj has the \nproperty of charmed in the second case, which we denote as c. \nTo prove the first case, we use the left elimination rule \napplied to a proof that there exists an object that is heavy, \nwhich is given through instantiation by applying the exists \nintroduction rule to our object obj and our proof h. Similarly, \nto prove the second case, we use the right elimination rule \napplied to a proof that there exists an object that is charmed, \nwhich is given through instantiation by applying the exists \nintroduction rule to our object obj and our proof c. By showing \nthat a proof that an object of type α has the property of heavy\nand a proof that an object of type α has the property of \ncharmed can be constructed from a proof that objects of type \nα exists that are heavy or charmed, we have proved aProp2.\n-/\n\n\n\n\n/- 4.\nFormally specify the syntax and semantics\nof a language of *arithmetic* expressions that\ncan include variables, where the meaning of\nan expression is (reduces to) a natural number.\n\nHint: model your answer on our specification\nof the syntax and semantics of *propositional\nlogic* expressions.\n-/\n\n/- In this language, an interpretation will\nmap variables to natural numbers rather than\nto Boolean values. We'll give you a start on\na solution by defining (1) a type of variables\nthat are distinguished from one another by a\nℕ-valued index, (2) specifying the type of an\ninterpretation, and (3) giving an example of\nan interpretation in which all variables have\nthe value zero.\n-/\n\n-- our variable type\nstructure a_var : Type := mk :: (index : ℕ)\n\n\n-- friendly names for a few variables\ndef X_var := a_var.mk 0\ndef Y_var := a_var.mk 1\ndef Z_var := a_var.mk 2\n\n-- the type of an interpretation\ndef interp := a_var → ℕ \n\n-- one possible interpretation, \"all zero\"\ndef all_zero_interp : interp := λ v, 0\n\n/-\n4a. Define an interpretation in which X has\nvalue 3, Y has value 7, and Z has value 1,\nand all other variables have value 0.\n-/\n\ndef an_interp : interp := λ v,\nmatch v with \n| a_var.mk 0 := 3\n| a_var.mk 1:= 7\n| a_var.mk 2 := 1\n| _ := 0\nend \n    \n\n/-\n4b. Define the syntax of your language to have\nthe following kinds of expressions. \n\n- ℕ literal expression\n- ℕ variable expression\n- expression + expression\n- expression * expression\n\nDo this by defining an inductive type, aexp, \nthe values of which are arithmetic expressions\nin our language. Call your constructors lit, \nvar, add, and mul. When you succeed, the test\nexpressions we give you should type check.\n-/\n\ninductive aexp : Type\n| lit : ℕ → aexp\n| var : a_var → aexp \n| add : aexp → aexp → aexp \n| mul : aexp → aexp → aexp \n\nopen aexp\n\n-- These expressions should type-check\ndef X := aexp.var X_var\ndef Y := aexp.var Y_var\ndef Z := aexp.var Z_var\ndef l6 := aexp.lit 6\ndef e1 := aexp.add X Y\ndef e2 := aexp.mul X Z\ndef e3 := aexp.mul e1 l6\n\n\n/-\n4c. Define a semantics for your\nlanguage so that expressions evaluate\nto natural numbers as they would using\nthe standard notions of addition and\nmultiplication. Furthermore, literal\nexpressions should evaluate to their\nnatural numbers arguments, and variable\nexpressions should evaluate the natural\nnumbers according to an interpretation\ngiven to the evaluation function (call\nit aEval). Remember to put constructor\nexpressions in parentheses when using\npattern matching / destructuring. When\nyou've succeeded, the test cases we've\nprovided should all pass.\n-/\n\n-- Your answer here\ndef aEval : aexp → interp → ℕ \n| (lit n) _ := n \n| (var av) i  := i av\n| (add ae1 ae2) i := (aEval ae1 i) + (aEval ae2 i)\n| (mul ae1 ae2) i := (aEval ae1 i) * (aEval ae2 i )\n\n\n-- Test cases that should pass when you've succeeded\nexample : aEval X an_interp = 3 := rfl\nexample : aEval Y an_interp = 7 := rfl\nexample : aEval Z an_interp = 1 := rfl\nexample : aEval l6 all_zero_interp = 6 := rfl\nexample : aEval e1 all_zero_interp = 0  := rfl\nexample : aEval e2 an_interp = 3 := rfl\nexample : aEval e3 an_interp = 60 := rfl\n\n\n\n/-\n5. Explain concisely but also precisely how a\nproof of a proposition, P, \"by contradiction\"\nwould be carried out. Be sure to point out\nexactly where negation elimination is involved.\n\nThen explain concisely and precisely how a\nproof of a proposition, ¬ P, would be carried\nout. \n\nTo carry out a proof of a proposition P by contradiction,\nwe assume ¬P and show that this leads to a contradiction.\nNegation elimination essentially allows us to delete \ndouble-negatives and is given by the law of the excluded\nmiddle, which we treat as an axiom in Lean. Specifically, \nclassical.em : ∀ (P : Prop), P ∨ ¬ P. It allows us to \nassume that for any proposition, either that proposition\nis true or its negation is true \n\n\nIn order to carry out a proof of a proposition ¬ P, we \nuse proof by negation. We start by assuming that there is \na proof that the proposition is true and show that this \nenables us to construct a proof of false. A proof of false \ndoes not exist, so if assuming P allows us to construct one, \nthen the assumption that P is true must be wrong, i.e. ¬ P\nis true. ¬ P is equivalent to P → false. To prove ¬P, we just \nshow that if P is true then false is true. An example would \nbe to use case analysis to prove the implication P → false. \nAssuming P, we match the proof of P with a constructor, which \nis an empty match statement (there are no cases). This shows \nthat P implies false, so we have proved that ¬ P, the negation \nof P, must be true.  \n\n-/\n\n\n\n/- 6. A simplish proof. Give a formal proof\nof the following proposition. Then explain\nbriefly in English why the proposition must\nbe true no matter what propositions P and Q\nare.\n-/\n\nexample : ∀ (P Q R : Prop), ¬ ((P ∧ ¬ Q) ∧ (Q ∧ ¬ R)) :=\nλ P Q R, \n    λ h,\n    match h with \n    | and.intro panq qanr := \n        let nq := panq.right in \n        let q := qanr.left in\n        nq q \n    end \n\n/-\nOur goal is to prove that for any propositions P, Q, and R, \nit is not the case that the conjunction of P and not Q, the \nleft conjunct, and Q and not R, the right conjunct, is true.\nThis is to show that (P ∧ ¬ Q) ∧ (Q ∧ ¬ R) implies false. We \nstart by assuming that we have propositions P, Q, and R and \na proof, which we call h, that (P ∧ ¬ Q) ∧ (Q ∧ ¬ R) is true. \nWe reason by case analysis and show that to construct h, the \nand introduction rule is applied to the left and right conjuncts.\nUsing the left and right elimination rules applied to the \nleft and right conjuncts of h respectively, we arrive at a proof,\nor a construction, of ¬ Q ∧ Q, which is false. By showing that \n(P ∧ ¬ Q) ∧ (Q ∧ ¬ R) leads to a contradiction, we have proved \nthat h implies false, i.e. ¬ ((P ∧ ¬ Q) ∧ (Q ∧ ¬ R)) is true. \n\n-/\n", "meta": {"author": "reesegrayallen", "repo": "Lean-Discrete-Mathematics", "sha": "00c875284613ea12e0a729f519738aab8599456b", "save_path": "github-repos/lean/reesegrayallen-Lean-Discrete-Mathematics", "path": "github-repos/lean/reesegrayallen-Lean-Discrete-Mathematics/Lean-Discrete-Mathematics-00c875284613ea12e0a729f519738aab8599456b/final_exam.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.9086178963141963, "lm_q1q2_score": 0.7910402494061455}}
{"text": "/-\nProof strategies.\n\n- DIRECT PROOF: from established facts\n\n- BY NEGATION: to prove ¬ P, assume P;\n  show that this yields a contradiction.\n  From this a proof of false can then \n  be derived. This shows P → false. And\n  that is the definition of ¬P.\n\n  Example: Prove that the square root of\n  two is irrational.\n\n  It sounds like we're trying to prove P,\n  where P := \"sqrt(2) is irrational\". But\n  it's better to take P to be the proposition\n  that \"sqrt(2) is rational\", and to view\n  the goal as to prove ¬ P.\n\n  Prove that the square root two is NOT\n  rational.\n\n  Prove \"¬ sqrt(2) is rational\".\n\n  Proof: BY NEGATION. assume sqrt(2) is \n  rational. In this case, we can write\n  sqrt(2) as some fraction, a/b (for that\n  is what it means for a number to be \n  rational). We now want to show that\n  this leads to a contradiction so that\n  we can conclude that our assumption is\n  false, thus ¬ P is true. Details left\n  as an exercise.\n\n\n\n  - BY CONTRADICTION : to prove P, assume\n    ¬ P and show that this leads to a\n    contradiction, from which a proof of\n    false can be derived. This proves\n    ¬ P → false, which is equivalent to\n    ¬ ¬ P. The apply the *classical* rule\n    of negation elimination to deduce P.\n\n    Classical rule of negation elimination:\n    ∀ (P : Prop), ¬ ¬ P → P.\n\n    Prove 0 = 0 by contradiction.\n\n    We want to prove P (0 = 0). Assume\n    ¬ (0 = 0), and show that this leads\n    to a contradiction. But by the\n    reflexive property of equality, which\n    says everything is equal to itself, \n    we know immediate that 0 = 0. That\n    gives us a direct contradiction, \n    between ¬ (0=0) and (0=0). From\n    such a contradiction we can derive\n    a proof of false, showing that\n    ¬ (0=0) → false. And this just means\n    ¬ (¬ 0=0). The by classical negation\n    elimination, this implies 0 = 0.\n\n    BY CASE ANALYSIS. Show that for any\n    possible form that an assumed value\n    can take (e.g., nat.zero or nat.succ\n    n' for some n'), i.e., for each of \n    its possible constructors, that the\n    goal must be true. Then in must be \n    true in ALL cases, which proves that\n    it is valid.\n\n    - Today: proof BY INDUCTION.\n-/\n\n-- Answer to question about why contradictions imply false\naxiom P : Prop\naxiom p : P\naxiom np : ¬ P  /- P → false -/\n#check (np p)\n\n/-\nProve this: ∀ (m : ℕ), my_add 0 m = m\n-/\n\ndef my_add : ℕ → ℕ → ℕ \n| nat.zero m := m\n| (nat.succ n') m := nat.succ (my_add n' m)\n\n-- 0 + m = m\n-- (1 + n') + m = 1 + (n' + m)\n\n/-\nProof: By the definition of addition,\nand specifically by the first of the\ntwo cases, which tells us that for any\nm, 0 + m = m. \n-/\n\n\n/-\nMany proofs are accomplished by mere\nsimplification of both sides of some\nequation *using function definitions*\nthat are already known. \n-/\n\n/-\nIf one is being precise, however, there\nare some unexpected consequences. One is\nthat sometimes something that looks easy\nturns out to be a bit more complicated.\n\nFor example, try to prove this (using)\nonly what we know so far.\n-/\n\nexample : ∀ (n : ℕ), my_add n 0 = n := _\n\n/-\nWe have no rule (yet) for adding zero \non the right, so simplifying using the\ndefinition of my_add doesn't work.\nInstead, we need to try a whole different\nproof strategy.\n-/\n\n/-\nHere's the idea: \n\n- every inductively defined type has a\n  corresponding induction rule, which  is\n  a rule for showing that some predicate\n  is true for *every* value of that type\n\n- Here's induction principle for the ℕ type:\n  ∀ P : (ℕ → Prop),\n  P 0 → \n  ((∀ n' : ℕ), P n' → P (nat.succ n')) → \n  ∀ n, P n\n\nIn other words, for any property of natural\nnumbers (a predicate that takes a natural\nnumber as an argument), *if* 0 satisfies \nthe predicate and whenever any n' satisfies\nit, so does n'+1, then the predicate is\ntrue/satisfied by *all* natural numbers.\n\nThink of the a proof of (P 0) as \"showing that\nthe first domino falls\", and (P n' → P (n' + 1))\nas showing that \"whenever *any* domino falls, so\ndoes the next one.\"\" Together these proofs show\nthat all the dominos fall. \n\n[THIS IS THE KEY THING TO REMEMBER: The\ninduction principle. Mathematical induction\nis nothing but the induction principle for\nℕ. There is a corresponding induction rule\nfor every inductively defined type.]\n\nIn other words, for any predicate/property\nP, to show that ∀ (n : ℕ), P n, it suffices \nto show the following: \n    (1) P 0, \n    (2) (∀ n' : ℕ), P n' → P (nat.succ n')\n-/\n\n/-\nThe next key idea in a proof by induction \nis that when proving (2), you get to *assume*\nthat P holds for some arbitrary n' and all you\nhave to do is to show that in this context it\nmust also hold for n'+1.\n-/\n\n/-\nExample: We want to prove ∀ n, n + 0 = n.\nProof by induction. If suffices to show that\n(1) Case: n = 0. We need to show 0 + 0 = 0. \n    This is trivially proved by applying the first rule of my_add.\n    So we have now proved (P 0).\n(2) Case: n = nat.succ n': \n    Show P n' → P (nat.succ n').\n    In other words, show n'+ 0 =n' → (n' + 1) + 0 = (n' +1). \n    Assume P n'? I.e., assume that: my_add n' 0 = n'\n    Now show P (nat.succ n'): that my_add (nat.succ n') 0 = (nat.succ n').\n    *** simplify: my_add (nat.succ n' 0) = \n                  nat.succ (my_add n' 0) = --2nd rule of my_add\n    *** apply induction hypothesis, that my_add n' 0 = n'.\n    Now we have my_add (nat.succ n' 0) = nat.succ n'.\n    We have thus now proved (2), that P n' → P (nat.succ n').\n    Applying the induction principle to these proofs yields a proof\n    of ∀ n, n + 0 = n.\n    QED.\n\ndef my_add : ℕ → ℕ → ℕ \n| nat.zero m := m\n| (nat.succ n') m := nat.succ (my_add n' m)\n-/\n\n/-\n∀ n, Sum numbers from 0 to n = n * (succ n) / 2.\n\nProof by induction. We will apply the principle of\ninduction for the natural numbers to two smaller\nproofs: one for n = 0, and one that shows that if\nthe formula is true for some n' > 0, then it must\nalso be true succ n'.\n\nBase case: prove (P 0): show sum from 0 to 0 = (0 * 1)/2 = 0.\nInductive case: Show  P n' → P (n' + 1)\nAssume P n'. The sum from 0 to n' = n' * (n' + 1) / 2.\nShow (P (n' + 1)): The sum from 0 to n'+1 = (n'+1)((n'+1)+1)/2.\nDo some algebra!\n\n--- intuition\n1+2+3+4+5 if we assume this is 5*6/2\n(1+2+3+4+5)+6 show this is 6*7/2\nsum 0 to 5 + 6! = 5*6/2 + 6\n\nThe sum from 0 to (n' + 1) = sum from 0 to n' + (n' + 1)\n                           = (n'*(n'+1)/2) + (n' + 1)\n                           ...\n                           = (n'+1)((n'+1)+1)/2.\n\n-/", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/predicate_logic/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8947894611926921, "lm_q1q2_score": 0.791029027119275}}
{"text": "/-\nIf P is a proposition then so is ¬P.\n-/\n\naxiom excl_middle : ∀ (P : Prop), P ∨ ¬ P\n\naxiom KevinIsFromCville : Prop\n\nexample : KevinIsFromCville ∨ ¬ KevinIsFromCville :=\nexcl_middle KevinIsFromCville\n\n/-\nTo construct a proof of Π for some proposition P,\nwe need to show that there can be no proof of P.\nTo show there can be no proof of P we assume that\nthere is a proof of P and show that this leads to\na contradition.\n\nWhat do we mean by a contradiction.\n-/\n\n#check false\n\nnamespace hidden\n\ndef not (P : Prop) : Prop := P → false \n\nend hidden\n\n#check not\n\nexample : ¬ 0 = 1 := \nbegin\n  show not (0 = 1),\n  -- the result of this application\n  -- is the proposition (0=1) → false.\n  assume h,\n  cases h,\nend\n\nexample : false → KevinIsFromCville :=\nbegin\n  assume f,\n  cases f,\nend\n\n/-\nFor any proposition at all, if false is\ntrue then that proposition, P, is true. \nOne way to understand this is that if false\nis true, then anything is true, because if\nit's true, it's true, and if it's false it's\nalso true.\n-/\ntheorem exfalso : ∀ (P : Prop), false → P :=\nbegin\n  intro P,\n  assume f,\n  cases f,\nend\n\ntheorem non_contradition : ∀ (P : Prop), ¬ (P ∧ ¬P) :=\nbegin \n  intro P,\n  assume h,\n  cases h with p np,\n  have f := _,\nend\n\n/-\nIs the following proposition valid in Lean\n-/\n\nexample : ∀ (P : Prop), ¬ ¬ P → P :=\nbegin\n  intro P,\n  assume h,\n  -- no use of classical reasoning allowed.\n  -- stuck! this is not a theorem in\n  -- the constructive logic of Lean\n  -- or Coq, or ...\nend\n\n#check classical.em\n\n/-\n∀ (p : Prop), p ∨ ¬p\n-/\n\nexample : ∀ (P : Prop), ¬¬ P → P :=\nbegin\n  intro P,\n  assume h,\n  /-\n  At this point we're stuck! All we\n  have to work with is our assumed\n  proof of ¬¬P, but all that tells \n  us is that *if* we have a proof \n  of ¬P we can derive a proof of \n  false (which which we could deduce\n  P); but we have no proof of ¬P to\n  use. The bottom line is that ¬¬P→ P\n  is *not* valid in the constructive\n  logic of Lean. On the other hand, as\n  we now show, if we accept the law of\n  the excluded middle, we can finish\n  the proof. The steps are (1)use em\n  to derive a proof of P ∨ ¬P, then\n  (2) show that in either case, P is\n  true, in the first case by assumption\n  and in the second case by contradiction.\n  -/\n  have o := classical.em P,\n  cases o,\n  assumption,     -- case #1: P is true  \n  contradiction,  -- case #2: ¬P is true\n  /-\n  If you're not sure what \"contradiction \n  is doing here, comment it out and then\n  uncomment the following two lines, which\n  make clear that from a contradiciton we\n  can derive a proof of false, and then we\n  can use false elimination (case analysis\n  where to prove the conclusion follows in\n  all cases requires no proofs at all as \n  there are no possible cases for a proof\n  of false to consider).\"\n  \n  have f := h o,    -- <<< understand this!\n  cases f,\n  -/\nend\n\n/-\nIf we assume the law of the excluded middle,\nthen negation elimination, ¬¬P → P, is valid.\n\nThat ¬¬P → P is valid is the essence of proof\nby contradiction. \n\nLet's start by noting that we have now seen\ntwo different proof techniques involving\ncontradictions.\n\nIn \"proof by negation,\" we prove ¬P by \nproving P → false, assuming P and showing\nthat from that assumption we can derive \na proof false. That is, to prove ¬P we \nprove P → false.\n\nBy contrast, proof by contradiction seeks\nto prove P (rather than ¬ P) by assuming \n¬P and showing that *that* assumption leads \nto a contradiction. That is, we seek to \nshow ¬P → false, which is just what we mean \nby ¬¬P. *THEN*, having shown ¬¬P, we apply \n(classical) negation elimination (¬¬P → P)\nto derive a proof of P, our overall goal. \n\nWhat we've seen today, then, is that while\nproof by negation is \"constructively valid\"\nproof by contradiction is *not*. However it\nis valid if we assume the classical axiom \nof the excluded middle. That axiom is what \nallows us to infer P from ¬¬P, which is the\nlast step in a proof by contradiction, as\nwe have just seen.\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/S_02_PredicateLogic/L_03_Not.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.790982568420126}}
{"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-/\n\nimport data.int.basic\nimport algebra.field\n\n/-!\n# Euclidean domains\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 `ℕ` 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\n* `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains.\n* `int.euclidean_domain`: shows that `ℤ` is a Euclidean domain.\n* `field.to_euclidean_domain`: shows that any field is a Euclidean domain.\n\n## Notation\n\n`≺` denotes the well founded relation on the Euclidean domain, e.g. in the example of the polynomial\nring over a field, `p ≺ 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 `ℤ` would correspond to\nsetting `i ≺ 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 à valeurs finies*]\n  [MR399081]\n* [M. Nagata, *On Euclid algorithm*][MR541021]\n\n\n## Tags\n\nEuclidean domain, transfinite Euclidean domain, Bézout's lemma\n-/\n\nuniverse u\n\nsection old_structure_cmd\nset_option old_structure_cmd true\n\n/-- A `euclidean_domain` is an `integral_domain` with a division and a remainder, satisfying\n  `b * (a / b) + a % b = a`. The definition of a euclidean domain usually includes a valuation\n  function `R → ℕ`. 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 → R → R)\n(quotient_zero : ∀ a, quotient a 0 = 0)\n(remainder : R → R → R)\n(quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a)\n(r : R → R → Prop)\n(r_well_founded : well_founded r)\n(remainder_lt : ∀ a {b}, b ≠ 0 → r (remainder a b) b)\n(mul_left_not_lt : ∀ a {b}, b ≠ 0 → ¬r (a * b) a)\nend old_structure_cmd\n\nnamespace euclidean_domain\nvariable {R : Type u}\nvariables [euclidean_domain R]\n\nlocal infix ` ≺ `:50 := euclidean_domain.r\n\n@[priority 70] -- see Note [lower instance priority]\ninstance : has_div R := ⟨euclidean_domain.quotient⟩\n\n@[priority 70] -- see Note [lower instance priority]\ninstance : has_mod R := ⟨euclidean_domain.remainder⟩\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 : ∀ a {b : R}, b ≠ 0 → (a % b) ≺ b :=\neuclidean_domain.remainder_lt\n\ntheorem mul_right_not_lt {a : R} (b) (h : a ≠ 0) : ¬(a * b) ≺ b :=\nby rw mul_comm; exact mul_left_not_lt b h\n\nlemma mul_div_cancel_left {a : R} (b) (a0 : a ≠ 0) : a * b / a = b :=\neq.symm $ eq_of_sub_eq_zero $ classical.by_contradiction $ λ 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 : R} (b0 : b ≠ 0) : a * b / b = a :=\nby rw mul_comm; exact mul_div_cancel_left a b0\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\n@[simp] lemma mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a :=\n⟨λ h, by rw [← div_add_mod a b, h, add_zero]; exact dvd_mul_right _ _,\n λ ⟨c, e⟩, begin\n  rw [e, ← 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⟩\n\n@[simp] lemma mod_self (a : R) : a % a = 0 :=\nmod_eq_zero.2 (dvd_refl _)\n\nlemma dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a :=\nby rw [dvd_add_iff_right (dvd_mul_of_dvd_left h _), div_add_mod]\n\nlemma lt_one (a : R) : a ≺ (1:R) → a = 0 :=\nby haveI := classical.dec; exact\nnot_imp_not.1 (λ h, by simpa only [one_mul] using mul_left_not_lt 1 h)\n\nlemma val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b\n| _ b ⟨d, rfl⟩ ha := mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha)\n\n@[simp] lemma mod_one (a : R) : a % 1 = 0 :=\nmod_eq_zero.2 (one_dvd _)\n\n@[simp] lemma zero_mod (b : R) : 0 % b = 0 :=\nmod_eq_zero.2 (dvd_zero _)\n\n@[simp, priority 900] lemma div_zero (a : R) : a / 0 = 0 :=\neuclidean_domain.quotient_zero a\n\n@[simp, priority 900] lemma zero_div {a : R} : 0 / a = 0 :=\nclassical.by_cases\n  (λ a0 : a = 0, a0.symm ▸ div_zero 0)\n  (λ a0, by simpa only [zero_mul] using mul_div_cancel 0 a0)\n\n@[simp, priority 900] lemma div_self {a : R} (a0 : a ≠ 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 : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b :=\nby rw [← h, mul_div_cancel _ hb]\n\nlemma eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a :=\nby rw [← h, mul_div_cancel_left _ ha]\n\ntheorem mul_div_assoc (x : R) {y z : R} (h : z ∣ 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 ⟨p, rfl⟩,\n  rw [mul_div_cancel_left _ hz, mul_left_comm, mul_div_cancel_left _ hz]\nend\n\nsection\nopen_locale classical\n\n@[elab_as_eliminator]\ntheorem gcd.induction {P : R → R → Prop} : ∀ a b : R,\n  (∀ x, P 0 x) →\n  (∀ a b, a ≠ 0 → P (b % a) a → P a b) →\n  P a b\n| a := λ 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 := λ _ _, `[exact ⟨_, r_well_founded⟩]}\n\nend\n\nsection gcd\nvariable [decidable_eq R]\n\n/-- `gcd a b` is a (non-unique) element such that `gcd a b ∣ a` `gcd a b ∣ b`, and for\n  any element `c` such that `c ∣ a` and `c ∣ b`, then `c ∣ gcd a b` -/\ndef gcd : R → R → R\n| a := λ 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 := λ _ _, `[exact ⟨_, r_well_founded⟩]}\n\n@[simp] theorem gcd_zero_left (a : R) : gcd 0 a = a :=\nby rw gcd; exact if_pos rfl\n\n@[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a :=\nby rw gcd; split_ifs; simp only [h, zero_mod, gcd_zero_left]\n\ntheorem gcd_val (a b : R) : gcd a b = gcd (b % a) a :=\nby rw gcd; split_ifs; [simp only [h, mod_zero, gcd_zero_right], refl]\n\ntheorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b :=\ngcd.induction a b\n  (λ b, by rw [gcd_zero_left]; exact ⟨dvd_zero _, dvd_refl _⟩)\n  (λ a b aneq ⟨IH₁, IH₂⟩, by rw gcd_val;\n    exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩)\n\ntheorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left\n\ntheorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right\n\nprotected theorem gcd_eq_zero_iff {a b : R} :\n  gcd a b = 0 ↔ a = 0 ∧ b = 0 :=\n⟨λ h, by simpa [h] using gcd_dvd a b,\n by rintro ⟨rfl, rfl⟩; simp⟩\n\ntheorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b :=\ngcd.induction a b\n  (λ _ _ H, by simpa only [gcd_zero_left] using H)\n  (λ 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 : R} : gcd a b = a ↔ a ∣ b :=\n⟨λ h, by rw ← h; apply gcd_dvd_right,\n λ h, by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩\n\n@[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 :=\ngcd_eq_left.2 (one_dvd _)\n\n@[simp] theorem gcd_self (a : R) : gcd a a = a :=\ngcd_eq_left.2 (dvd_refl _)\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 → R → R → R → R → R → R × R × R\n| r := λ s t r' s' t',\nif hr : r = 0 then (r', s', t')\n  else\n  have r' % r ≺ 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 := λ _ _, `[exact ⟨_, r_well_founded⟩]}\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 ≠ 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 × 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\n@[simp] theorem xgcd_aux_fst (x y : R) : ∀ 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(λ x y h IH s t s' t', by simp only [xgcd_aux_rec h, if_neg h, IH]; rw ← gcd_val)\n\ntheorem xgcd_aux_val (x y : R) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1, prod.mk.eta]\n\ntheorem xgcd_val (x y : R) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nprod.mk.eta.symm\n\nprivate def P (a b : R) : R × R × R → Prop | (r, s, t) := (r : R) = a * s + b * t\n\ntheorem xgcd_aux_P (a b : R) {r r' : R} : ∀ {s t s' t'}, P a b (r, s, t) →\n  P a b (r', s', t') → P a b (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by intros; simpa only [xgcd_zero_left]) $ λ 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' ⊢,\n  rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub,\n    mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p,\n    mod_eq_sub_mul_div]\nend\n\n/-- An explicit version of Bézout's lemma for Euclidean domains. -/\ntheorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = 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\n@[priority 70] -- see Note [lower instance priority]\ninstance (R : Type*) [e : euclidean_domain R] : integral_domain R :=\nby haveI := classical.dec_eq R; exact\n{ eq_zero_or_eq_zero_of_mul_eq_zero :=\n    λ a b h, (or_iff_not_and_not.2 $ λ h0,\n      h0.1 $ by rw [← mul_div_cancel a h0.2, h, zero_div]),\n  zero := 0, add := (+), mul := (*), ..e }\n\nend gcd\n\nsection lcm\nvariables [decidable_eq R]\n\n/-- `lcm a b` is a (non-unique) element such that `a ∣ lcm a b` `b ∣ lcm a b`, and for\n  any element `c` such that `a ∣ c` and `b ∣ c`, then `lcm a b ∣ c` -/\ndef lcm (x y : R) : R :=\nx * y / gcd x y\n\ntheorem dvd_lcm_left (x y : R) : x ∣ lcm x y :=\nclassical.by_cases\n  (assume hxy : gcd x y = 0, by rw [lcm, hxy, div_zero]; exact dvd_zero _)\n  (λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).2 in ⟨z, eq.symm $ eq_div_of_mul_eq_left hxy $\n    by rw [mul_right_comm, mul_assoc, ← hz]⟩)\n\ntheorem dvd_lcm_right (x y : R) : y ∣ lcm x y :=\nclassical.by_cases\n  (assume hxy : gcd x y = 0, by rw [lcm, hxy, div_zero]; exact dvd_zero _)\n  (λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).1 in ⟨z, eq.symm $ eq_div_of_mul_eq_right hxy $\n    by rw [← mul_assoc, mul_right_comm, ← hz]⟩)\n\ntheorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ 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 ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,\n  suffices : x * y ∣ z * gcd x y,\n  { cases this with p hp, use p,\n    generalize_hyp : gcd x y = g at hxy hs hp ⊢, subst hs,\n    rw [mul_left_comm, mul_div_cancel_left _ hxy, ← mul_left_inj' hxy, hp],\n    rw [← 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 : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z :=\n⟨λ hz, ⟨dvd_trans (dvd_lcm_left _ _) hz, dvd_trans (dvd_lcm_right _ _) hz⟩,\nλ ⟨hxz, hyz⟩, lcm_dvd hxz hyz⟩\n\n@[simp] lemma lcm_zero_left (x : R) : lcm 0 x = 0 :=\nby rw [lcm, zero_mul, zero_div]\n\n@[simp] lemma lcm_zero_right (x : R) : lcm x 0 = 0 :=\nby rw [lcm, mul_zero, zero_div]\n\n@[simp] lemma lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ 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 ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,\n      generalize_hyp : gcd x y = g at hr hs hy hgxy ⊢, 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 : R) : 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 ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,\n  generalize_hyp : gcd x y = g at h hr ⊢, subst hr,\n  rw [mul_assoc, mul_div_cancel_left _ h]\nend\n\nend lcm\n\nend euclidean_domain\n\ninstance int.euclidean_domain : euclidean_domain ℤ :=\n{ add := (+),\n  mul := (*),\n  one := 1,\n  zero := 0,\n  neg := has_neg.neg,\n  quotient := (/),\n  quotient_zero := int.div_zero,\n  remainder := (%),\n  quotient_mul_add_remainder_eq := λ a b, int.div_add_mod _ _,\n  r := λ a b, a.nat_abs < b.nat_abs,\n  r_well_founded := measure_wf (λ a, int.nat_abs a),\n  remainder_lt := λ a b b0, int.coe_nat_lt.1 $\n    by rw [int.nat_abs_of_nonneg (int.mod_nonneg _ b0), ← int.abs_eq_nat_abs];\n    exact int.mod_lt _ b0,\n  mul_left_not_lt := λ a b b0, not_lt_of_ge $\n    by rw [← 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  .. int.comm_ring,\n  .. int.nontrivial }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_euclidean_domain {K : Type u} [field K] : euclidean_domain K :=\n{ add := (+),\n  mul := (*),\n  one := 1,\n  zero := 0,\n  neg := has_neg.neg,\n  quotient := (/),\n  remainder := λ a b, a - a * b / b,\n  quotient_zero := div_zero,\n  quotient_mul_add_remainder_eq := λ a b,\n    by classical; by_cases b = 0; simp [h, mul_div_cancel'],\n  r := λ a b, a = 0 ∧ b ≠ 0,\n  r_well_founded := well_founded.intro $ λ a, acc.intro _ $ λ b ⟨hb, hna⟩,\n    acc.intro _ $ λ c ⟨hc, hnb⟩, false.elim $ hnb hb,\n  remainder_lt := λ a b hnb, by simp [hnb],\n  mul_left_not_lt := λ a b hnb ⟨hab, hna⟩, or.cases_on (mul_eq_zero.1 hab) hna hnb,\n  .. ‹field K› }\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/euclidean_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7909825614865076}}
{"text": "import .aux.ncard\nimport .aux.helpers \n\n-- noncomputable theory \nopen_locale classical \nopen_locale big_operators\n\nopen set \n\nvariables {E : Type*}\n\n/-- A predicate `P` on sets satisfies the exchange property if, for all `X` and `Y` satisfying `P`\n  and all `a ∈ X \\ Y`, there exists `b ∈ Y \\ X` so that swapping `a` for `b` in `X` maintains `P`.-/\ndef exchange_property (P : set E → Prop) : Prop :=\n  ∀ X Y, P X → P Y → ∀ a ∈ X \\ Y, ∃ b ∈ Y \\ X, P (insert b (X \\ {a})) \n\n/-- A `matroid` is a nonempty collection of sets satisfying the exchange property. Each such set \n  is called a `base` of the matroid. -/\n\n@[ext] structure matroid (E : Type*) :=\n  (base : set E → Prop)\n  (exists_base' : ∃ B, base B) \n  (base_exchange' : exchange_property base)\n\ninstance {E : Type*} [finite E] : \n  finite (matroid E) := \nfinite.of_injective (λ M, M.base) (λ M₁ M₂ h, (by {ext, dsimp only at h, rw h}))  \n\ninstance {E : Type*} : nonempty (matroid E) := \n  ⟨⟨λ B, B = univ, ⟨_,rfl⟩, λ B B' hB hB' a ha, (ha.2 (by convert mem_univ a)).elim⟩⟩ \n\nnamespace matroid \n/- None of these definitions require finiteness -/\n\nsection defs\n\n/-- A set is independent if it is contained in a base.  -/\ndef indep (M : matroid E) (I : set E) : Prop := \n  ∃ B, M.base B ∧ I ⊆ B   \n\n/-- A basis for a set `X` is a maximal independent subset of `X`\n  (Often in the literature, the word 'basis' is used to refer to what we call a 'base')-/\ndef basis (M : matroid E) (I X : set E) : Prop := \n  M.indep I ∧ I ⊆ X ∧ ∀ J, M.indep J → I ⊆ J → J ⊆ X → I = J \n\n/-- A circuit is a minimal dependent set -/\ndef circuit (M : matroid E) (C : set E) : Prop := \n  ¬M.indep C ∧ ∀ I ⊂ C, M.indep I \n\n/-- A flat is a maximal set having a given basis  -/\ndef flat (M : matroid E) (F : set E) : Prop := \n  ∀ I X, M.basis I F → M.basis I X → X ⊆ F    \n\n/-- The closure of a set is the intersection of the flats containing it -/\ndef cl (M : matroid E) (X : set E) : set E :=\n  ⋂₀ {F | M.flat F ∧ X ⊆ F}\n\n/-- A hyperplane is a maximal proper subflat -/\ndef hyperplane (M : matroid E) (H : set E) : Prop :=\n  M.flat H ∧ H ⊂ univ ∧ (∀ F, H ⊂ F → M.flat F → F = univ)  \n\n/-- A cocircuit is the complement of a hyperplane -/\ndef cocircuit (M : matroid E) (K : set E) : Prop := \n  M.hyperplane Kᶜ  \n\n/-- A coindependent set is one that contains no cocircuit -/\ndef coindep (M : matroid E) (I : set E) : Prop := \n  ¬ ∃ K ⊆ I, M.cocircuit K     \n\n/-- A loop is a singleton circuit -/\ndef loop (M : matroid E) (e : E) : Prop :=\n  M.circuit {e}\n\n/-- A coloop is an element contained in every basis -/\ndef coloop (M : matroid E) (e : E) : Prop :=\n  ∀ B, M.base B → e ∈ B\n\n/-- The set of nonloops of `M` is the complement of the set `M.cl ∅` of loops -/\ndef nonloops (M : matroid E) : set E :=\n  (M.cl ∅)ᶜ \n\nend defs \n\nsection base\n\nvariables {B B₁ B₂ I : set E} {M : matroid E} {e f x y : E}\n\nlemma exists_base (M : matroid E) : ∃ B, M.base B := M.exists_base'\n\nlemma base.exchange (hB₁ : M.base B₁) (hB₂ : M.base B₂) (hx : x ∈ B₁ \\ B₂) : \n  ∃ y ∈ B₂ \\ B₁, M.base (insert y (B₁ \\ {x}))  :=\nM.base_exchange' B₁ B₂ hB₁ hB₂ _ hx\n\nlemma base.exchange_mem (hB₁ : M.base B₁) (hB₂ : M.base B₂) (hxB₁ : x ∈ B₁) (hxB₂ : x ∉ B₂) : \n  ∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.base (insert y (B₁ \\ {x})) := \nby simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩ \n\nvariables [finite E]\n\nlemma base.card_eq_card_of_base (hB₁ : M.base B₁) (hB₂ : M.base B₂) :\n  B₁.ncard = B₂.ncard := \nbegin\n  suffices h : ∀ i B B', M.base B → M.base B' → (B' \\ B).ncard ≤ i → \n    B'.ncard ≤ B.ncard, from \n      (h _ _ _ hB₂ hB₁ rfl.le).antisymm (h _ _ _ hB₁ hB₂ rfl.le), \n  clear hB₁ B₁ hB₂ B₂, \n  intro i, \n  induction i with i IH, \n  { rintros B B' - - h, \n    rw [le_zero_iff, ncard_eq_zero, diff_eq_empty] at h, \n    exact ncard_le_of_subset h, },  \n  refine λ B B' hB hB' hcard, le_of_not_lt (λ hlt, _ ) , \n  obtain ⟨x, hxB', hxB⟩ := exists_mem_not_mem_of_ncard_lt_ncard hlt,  \n  have := hB'.exchange hB ⟨hxB',hxB⟩,\n  obtain ⟨y, hy, hB''⟩ := hB'.exchange hB ⟨hxB',hxB⟩, \n\n  have hcard := IH B (insert y (B' \\ {x}))  hB (by simpa using hB'') _, \n  { apply hlt.not_le, \n    rwa [ncard_insert_of_not_mem, ncard_diff_singleton_add_one hxB'] at hcard,\n    simpa using hy.2},\n  \n  suffices hss : (insert y (B' \\ {x})) \\ B ⊂ B' \\ B, \n  { exact nat.le_of_lt_succ ((ncard_lt_ncard hss).trans_le hcard)},\n\n  refine (ssubset_iff_of_subset (λ a, _) ).mpr ⟨x,  _⟩, \n  { rw [mem_diff, mem_insert_iff, and_imp, mem_diff_singleton],\n    rintro (rfl | ⟨haB',hax⟩) haB,\n    { exact (haB hy.1).elim}, \n    exact ⟨haB',haB⟩},\n  \n  rw [exists_prop, mem_diff, mem_diff, not_and, not_not_mem, mem_insert_iff, mem_diff, \n    mem_singleton_iff, ne_self_iff_false, and_false, or_false], \n  exact ⟨⟨hxB', hxB⟩, by {rintro rfl, exact hy.1}⟩, \nend \n\nlemma base.eq_of_subset_base (hB₁ : M.base B₁) (hB₂ : M.base B₂) (hB₁B₂ : B₁ ⊆ B₂) : \n  B₁ = B₂ :=\nbegin\n  suffices : B₂ \\ B₁ = ∅, from hB₁B₂.antisymm (diff_eq_empty.mp this),\n  by_contra' h, \n  obtain ⟨e,he⟩ := set.nonempty_iff_ne_empty.mpr h, \n  obtain ⟨y,hy,-⟩:=  hB₂.exchange hB₁ he, \n  exact hy.2 (hB₁B₂ hy.1), \nend \n\nend base \n\nend matroid \n\n-- TODO : prove strong basis exchange (and hence define duality) in this file. \n\n-- lemma base.indep (hB : M.base B) : \n--   M.indep B := \n-- sorry \n\n-- lemma base.insert_dep (hB : M.base B) (h : e ∉ B) : \n--   ¬M.indep (insert e B) := sorry  \n\n-- lemma base_iff_maximal_indep : \n--   M.base B ↔ M.indep B ∧ ∀ I, M.indep I → B ⊆ I → B = I := \n-- sorry \n\n-- lemma indep.unique_circuit_of_insert {e : E} (hI : M.indep I) (hI' : ¬M.indep (insert e I)) : \n--   ∃! C, C ⊆ insert e I ∧ M.circuit C ∧ e ∈ C := sorry \n\n-- lemma subset_cl (M : matroid E) (X : set E) :\n--   X ⊆ M.cl X := sorry  \n\n-- -- lemma base_iff_indep_card :\n-- --   M.base B ↔ M.indep B ∧ B.ncard =  \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/matroid.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7909825597492567}}
{"text": "import data.set\nimport algebra.pi_instances\n\nimport .topology\n\nsection negative_sets\n\ndef negative_set (S: set ℝ): set ℝ := { x : ℝ | -x ∈ S}\n\nlemma negative_set.negative_set_eq_set\n  (S: set ℝ): negative_set (negative_set S) = S :=\n  begin\n  rw negative_set,\n  rw negative_set,\n  simp,\n  end\n\nlemma negative_set.mem_iff {S: set ℝ} (x: ℝ):\n  x ∈ S ↔ -x ∈ negative_set S := begin\n  split,\n  intro h,\n  rw negative_set,\n  finish,\n  intro h,\n  rw negative_set at h,\n  finish,\nend\n\nlemma negative_set.nonempty {S: set ℝ}: \n  S.nonempty → (negative_set S).nonempty := begin\n  intro hne,\n  obtain ⟨ x, h ⟩ := hne,\n  use (-x),\n  rw negative_set,\n  finish,\nend\n\nlemma negative_set.bdd_above {S: set ℝ}:\n  bdd_below S → bdd_above (negative_set S) := begin\n  intro bdd,\n  obtain ⟨ M, hm ⟩ := bdd,\n  rw lower_bounds at hm,\n  simp at hm,\n  use (-M),\n  rw negative_set,\n  rw upper_bounds,\n  simp,\n  intros a ha,\n  apply le_neg.2,\n  exact hm ha,\nend\n\n\nlemma negative_set.bdd_below {S: set ℝ}: \n  bdd_above S → bdd_below (negative_set S) :=\nbegin\n  intro bdd,\n  obtain ⟨ M, hm ⟩ := bdd,\n  rw upper_bounds at hm,\n  simp at hm,\n  use (-M),\n  rw negative_set,\n  rw lower_bounds,\n  simp,\n  intros a ha,\n  apply neg_le.1,\n  exact hm ha,\nend\n\nlemma negative_set.bdd_above_iff {S: set ℝ}:\n  bdd_below S ↔ bdd_above (negative_set S) := begin\n  split,\n  exact negative_set.bdd_above,\n  set S' := negative_set S with hs,\n  have Seq := negative_set.negative_set_eq_set S,\n  rw ← Seq,\n  rw ← hs,\n  exact negative_set.bdd_below,\nend\n\nlemma negative_set.bdd_below_iff {S: set ℝ}:\n  bdd_above S ↔ bdd_below (negative_set S) := begin\n  split,\n  exact negative_set.bdd_below,\n  set S' := negative_set S with hs,\n  have Seq := negative_set.negative_set_eq_set S,\n  rw ← Seq,\n  rw ← hs,\n  exact negative_set.bdd_above,\nend\n\nlemma negative_set.adhere_ens {S: set ℝ} {l: ℝ}:\n  adhere_ens S l → adhere_ens (negative_set S) (-l) :=\n  begin\n  intro adh,\n  rw adhere_ens at adh,\n  obtain ⟨ x, hx ⟩ := adh,\n  use (-x),\n  split,\n  simp,\n  intro n,\n  exact (negative_set.mem_iff (x n)).1 (hx.1 n),\n  exact neg_converge hx.2,\n  end\n\nlemma negative_set.adhere_ens_iff {S: set ℝ} {l: ℝ}:\n  adhere_ens S l ↔ adhere_ens (negative_set S) (-l) :=\nbegin\n  split,\n  exact negative_set.adhere_ens,\n  set S' := negative_set S with hs,\n  have Seq := negative_set.negative_set_eq_set S,\n  have leq: l = - -l := by simp,\n  rw ← Seq,\n  rw ← hs,\n  set l' := -l with hl,\n  rw leq,\n  exact negative_set.adhere_ens,\nend\n\nend negative_sets", "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/negative_sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8633916187614823, "lm_q1q2_score": 0.7909613661949352}}
{"text": "/- Definition of a Group -/\n\nclass Group (G : Type u) :=\n  mul : G → G → G\n  mul_assoc : ∀ a b c : G, mul (mul a b) c = mul a (mul b c)\n  one : G\n  one_mul : ∀ a : G, mul one a = a\n  mul_one : ∀ a : G, mul a one = a\n  inv : G → G\n  inv_mul : ∀ a : G, mul (inv a) a = one\n  mul_inv : ∀ a : G, mul a (inv a) = one\n\nclass Abelian_Group (G : Type u) extends Group G :=\n  mul_com : ∀ a b : G, mul a b = mul b a\n\ninfixl:70    \" * \"   => Group.mul\nnotation:max \" e \"   => Group.one\npostfix:max  \" ⁻¹ \"  => Group.inv\n\n/- Some Examples of Groups -/\n\nnamespace Examples\n\ninductive pm : Type :=\n  | p : pm\n  | m : pm\n\ndef pm.mul : pm → pm → pm \n  | p, p => p\n  | p, m => m\n  | m, p => m\n  | m, m => p\n\ntheorem pm.mul_assoc : ∀ a b c : pm, mul (mul a b) c = mul a (mul b c) \n  | p, p, p => by simp [pm.mul]\n  | p, p, m => by simp [pm.mul]\n  | p, m, p => by simp [pm.mul]\n  | p, m, m => by simp [pm.mul]\n  | m, p, p => by simp [pm.mul]\n  | m, p, m => by simp [pm.mul]\n  | m, m, p => by simp [pm.mul]\n  | m, m, m => by simp [pm.mul]\n\ntheorem pm.one_mul : ∀ a : pm, mul p a = a \n  | p => by simp [pm.mul]\n  | m => by simp [pm.mul]\n\ntheorem pm.mul_one : ∀ a : pm, mul a p = a \n  | p => by simp [pm.mul]\n  | m => by simp [pm.mul]\n\ndef pm.inv : pm → pm \n  | p => p\n  | m => m\n\ntheorem pm.inv_mul : ∀ a : pm, mul (inv a) a = p\n  | p => by simp [pm.inv, pm.mul]\n  | m => by simp [pm.inv, pm.mul]\n\ntheorem pm.mul_inv : ∀ a : pm, mul a (inv a) = p\n  | p => by simp [pm.inv, pm.mul]\n  | m => by simp [pm.inv, pm.mul]\n\ntheorem pm.mul_com : ∀ a b : pm, mul a b = mul b a\n  | p, p => by simp [pm.mul]\n  | p, m => by simp [pm.mul]\n  | m, p => by simp [pm.mul]\n  | m, m => by simp [pm.mul]\n\ninstance : Abelian_Group pm where\n    mul := pm.mul\n    mul_assoc := pm.mul_assoc\n    one := pm.p\n    one_mul := pm.one_mul\n    mul_one := pm.mul_one\n    inv := pm.inv\n    inv_mul := pm.inv_mul\n    mul_inv := pm.mul_inv\n    mul_com := pm.mul_com\n\nend Examples\n\nnamespace Examples\n\ninductive nat : Type :=\n  | zero : nat\n  | succ : nat → nat\n\ndef nat.add : nat → nat → nat \n  | a, nat.zero   => a\n  | a, nat.succ b => nat.succ (add a b)\n\ntheorem nat.add_assoc : ∀ a b c : nat, add (add a b) c = add a (add b c)\n  | a, b, zero   => by rw [add, add]\n  | a, b, succ n => by simp [add, add_assoc]\n\ntheorem nat.zero_add : ∀ a : nat, add zero a = a \n  | zero   => by simp [add]\n  | succ n => by simp [add, zero_add]\n\ntheorem nat.succ_add : ∀ a b : nat, add (succ a) b = succ (add a b)\n  | a, zero   => by simp [add]\n  | a, succ n => by simp [add, succ_add]\n\ntheorem nat.add_com : ∀ a b : nat, add a b = add b a \n  | a, zero => by simp [add, zero_add]\n  | a, succ n => by simp [add, succ_add, add_com a n]\n\ndef nat.pred : nat → nat \n  | nat.zero   => nat.zero\n  | nat.succ n => n\n\ndef nat.sub : nat → nat → nat \n  | a, nat.zero   => a\n  | a, nat.succ b => pred (sub a b)\n\ninductive int : Type :=\n  | ofnat : nat → int\n  | nsucc : nat → int\n\ndef int.sub_nat (m n : nat) : int :=\n  match (nat.sub n m : nat) with \n  | nat.zero   => int.ofnat (nat.sub m n)\n  | nat.succ k => int.nsucc k\n\ndef int.add : int → int → int\n  | ofnat m, ofnat n => int.ofnat (nat.add m n)\n  | ofnat m, nsucc n => int.sub_nat m (nat.succ n)\n  | nsucc m, ofnat n => int.sub_nat n (nat.succ m)\n  | nsucc m, nsucc n => int.nsucc (nat.add m n)\n\n\n\n\nend Examples\n\n\n\n/- Some Preliminary Lemmas -/\n\nnamespace Group\nvariable {G : Type u} [Group G]\n\ntheorem unique_one_l {e' : G} (h : ∀ x : G, e' * x = x) : e' = e := calc\n  e' = e' * e := by rw [mul_one]\n  _  = e      := by rw [h]\n\n\ntheorem unique_one_r {e' : G} (h : ∀ x : G, x * e' = x) : e' = e := calc\n  e' = e * e' := by rw [one_mul]\n  _  = e      := by rw [h]\n\ntheorem unique_inv_l {a b : G} (h : b * a = e) : b = a⁻¹ := calc\n  b = b * e         := by rw [mul_one]\n  _ = b * (a * a⁻¹) := by rw [mul_inv]\n  _ = (b * a) * a⁻¹ := by rw [mul_assoc]\n  _ = e * a⁻¹       := by rw [h]\n  _ = a⁻¹           := by rw [one_mul]\n\ntheorem unique_inv_r {a b : G} (h : a * b = e) : b = a⁻¹ := calc\n  b = e * b         := by rw [one_mul]\n  _ = (a⁻¹ * a) * b := by rw [inv_mul]\n  _ = a⁻¹ * (a * b) := by rw [mul_assoc]\n  _ = a⁻¹ * e       := by rw [h]\n  _ = a⁻¹           := by rw [mul_one] \n\ntheorem inv_inv (a : G) : (a⁻¹)⁻¹ = a :=\n  have h₁ : a * a⁻¹ = e := mul_inv a\n  have h₂ : a = (a⁻¹)⁻¹ := unique_inv_l h₁\n  show (a⁻¹)⁻¹ = a from h₂.symm  \n\ntheorem prod_inv (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\n  have h₁ : (a * b) * (b⁻¹ * a⁻¹) = e := calc\n    (a * b) * (b⁻¹ * a⁻¹) = a * (b * b⁻¹) * a⁻¹ := by simp [mul_assoc]\n    _                     = e                   := by simp [mul_inv, mul_one, mul_inv]\n  have h₂ : (b⁻¹ * a⁻¹) = (a * b)⁻¹ := unique_inv_r h₁\n  show (a * b)⁻¹ = b⁻¹ * a⁻¹ from h₂.symm\n\ntheorem left_cancel {a b x : G} (h : a * x = b) : x = a⁻¹ * b := calc\n  x = e * x         := by rw [one_mul]\n  _ = (a⁻¹ * a) * x := by rw [inv_mul]\n  _ = a⁻¹ * (a * x) := by rw [mul_assoc]\n  _ = a⁻¹ * b       := by rw [h]\n\ntheorem right_cancel {a b x : G} (h : x * a = b) : x = b * a⁻¹ := calc\n  x = x * e         := by rw [mul_one]\n  _ = x * (a * a⁻¹) := by rw [mul_inv]\n  _ = (x * a) * a⁻¹ := by rw [mul_assoc]\n  _ = b * a⁻¹       := by rw [h]\n\nend Group\n\n", "meta": {"author": "hikarimusic", "repo": "MyLean", "sha": "e42dc138addf5ad80dc3e5dbdbc329b90d9531b0", "save_path": "github-repos/lean/hikarimusic-MyLean", "path": "github-repos/lean/hikarimusic-MyLean/MyLean-e42dc138addf5ad80dc3e5dbdbc329b90d9531b0/Algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.7909613597545367}}
{"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 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.SMulWithZero\nimport Mathlib.Algebra.Regular.Basic\n\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 `IsSMulRegular`.\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 ∈ R` is `M`-regular if the smultiplication map\n`M → M`, defined by `m ↦ a • m`, is injective.\n\nThis property is the direct generalization to modules of the property `IsLeftRegular` defined in\n`Algebra/Regular`.  Lemma `isLeftRegular_iff` shows that indeed the two notions\ncoincide.\n-/\n\n\nvariable {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 → M`. -/\ndef IsSMulRegular [SMul R M] (c : R) :=\n  Function.Injective ((c • ·) : M → M)\n#align is_smul_regular IsSMulRegular\n\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/-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/\ntheorem isLeftRegular_iff [Mul R] {a : R} : IsLeftRegular a ↔ IsSMulRegular R a :=\n  Iff.rfl\n#align is_left_regular_iff isLeftRegular_iff\n\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/-- Right-regular multiplication on `R` is equivalent to `Rᵐᵒᵖ`-regularity of `R` itself. -/\ntheorem isRightRegular_iff [Mul R] {a : R} :\n    IsRightRegular a ↔ IsSMulRegular R (MulOpposite.op a) :=\n  Iff.rfl\n#align is_right_regular_iff isRightRegular_iff\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/-- The product of `M`-regular elements is `M`-regular. -/\ntheorem smul (ra : IsSMulRegular M a) (rs : IsSMulRegular M s) : IsSMulRegular M (a • s) :=\n  fun _ _ ab => rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _))))\n#align is_smul_regular.smul IsSMulRegular.smul\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. -/\ntheorem of_smul (a : R) (ab : IsSMulRegular M (a • s)) : IsSMulRegular M s :=\n  @Function.Injective.of_comp _ _ _ (fun m : M => a • m) _ fun c d cd => by\n  dsimp only [Function.comp] at cd\n  rw [←smul_assoc, ←smul_assoc] at cd\n  exact ab cd\n#align is_smul_regular.of_smul IsSMulRegular.of_smul\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]\ntheorem smul_iff (b : S) (ha : IsSMulRegular M a) : IsSMulRegular M (a • b) ↔ IsSMulRegular M b :=\n  ⟨of_smul _, ha.smul⟩\n#align is_smul_regular.smul_iff IsSMulRegular.smul_iff\n\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\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\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\ntheorem of_mul [Mul R] [IsScalarTower R R M] (ab : IsSMulRegular M (a * b)) :\n    IsSMulRegular M b := by\n  rw [← smul_eq_mul] at ab\n  exact ab.of_smul _\n#align is_smul_regular.of_mul IsSMulRegular.of_mul\n\n@[simp]\ntheorem mul_iff_right [Mul R] [IsScalarTower R R M] (ha : IsSMulRegular M a) :\n    IsSMulRegular M (a * b) ↔ IsSMulRegular M b :=\n  ⟨of_mul, ha.mul⟩\n#align is_smul_regular.mul_iff_right IsSMulRegular.mul_iff_right\n\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) ∧ IsSMulRegular M (b * a) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by\n  refine' ⟨_, _⟩\n  · rintro ⟨ab, ba⟩\n    refine' ⟨ba.of_mul, ab.of_mul⟩\n  · rintro ⟨ha, hb⟩\n    exact ⟨ha.mul hb, hb.mul ha⟩\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/-- One is always `M`-regular. -/\n@[simp]\ntheorem one : IsSMulRegular M (1 : R) := fun a b ab => by\n  dsimp only [Function.comp] at ab\n  rw [one_smul, one_smul] at ab\n  assumption\n#align is_smul_regular.one IsSMulRegular.one\n\nvariable {M}\n\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/-- Any power of an `M`-regular element is `M`-regular. -/\ntheorem pow (n : ℕ) (ra : IsSMulRegular M a) : IsSMulRegular M (a ^ n) := by\n  induction' n with n hn\n  · rw [pow_zero]; simp only [one]\n  · rw [pow_succ]\n    exact (ra.smul_iff (a ^ n)).mpr hn\n#align is_smul_regular.pow IsSMulRegular.pow\n\n/-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/\ntheorem pow_iff {n : ℕ} (n0 : 0 < n) : IsSMulRegular M (a ^ n) ↔ IsSMulRegular M a := by\n  refine' ⟨_, pow n⟩\n  rw [← Nat.succ_pred_eq_of_pos n0, pow_succ', ← 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/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/\ntheorem of_smul_eq_one (h : a • 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/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\nprotected theorem subsingleton (h : IsSMulRegular M (0 : R)) : Subsingleton M :=\n  ⟨fun a b => h (by dsimp only [Function.comp]; repeat' rw [MulActionWithZero.zero_smul])⟩\n#align is_smul_regular.subsingleton IsSMulRegular.subsingleton\n\n/-- The element `0` is `M`-regular if and only if `M` is trivial. -/\n\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\ntheorem not_zero_iff : ¬IsSMulRegular M (0 : R) ↔ Nontrivial M := 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/-- 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/-- The `0` element is not `M`-regular, on a non-trivial module. -/\ntheorem not_zero [nM : Nontrivial M] : ¬IsSMulRegular 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/-- A product is `M`-regular if and only if the factors are. -/\ntheorem mul_iff : IsSMulRegular M (a * b) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by\n  rw [← mul_and_mul_iff]\n  exact ⟨fun ab => ⟨ab, by rwa [mul_comm]⟩, fun rab => rab.1⟩\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/-- 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 `LeftCancelSMul` typeclass. -/\ntheorem isSMulRegular_of_group [MulAction G R] (g : G) : IsSMulRegular R g := by\n  intro x y h\n  convert congr_arg (g⁻¹ • ·) h using 1 <;> simp [← smul_assoc]\n#align is_smul_regular_of_group isSMulRegular_of_group\n\nend Group\n\nsection Units\n\nvariable [Monoid R] [MulAction R M]\n\n/-- Any element in `Rˣ` is `M`-regular. -/\ntheorem Units.isSMulRegular (a : Rˣ) : IsSMulRegular M (a : R) :=\n  IsSMulRegular.of_mul_eq_one a.inv_val\n#align units.is_smul_regular Units.isSMulRegular\n\n/-- A unit is `M`-regular. -/\ntheorem IsUnit.isSMulRegular (ua : IsUnit a) : IsSMulRegular M a := by\n  rcases ua with ⟨a, rfl⟩\n  exact a.isSMulRegular M\n#align is_unit.is_smul_regular IsUnit.isSMulRegular\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/Regular/SMul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7909613586523209}}
{"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\" (`∧`)\n\nWe learn about how to manipulate `P ∧ 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 ∧ Q → P :=\nbegin\n  intro q,cases q,assumption,\nend\n\nexample : P ∧ Q → Q :=\nbegin\n  intro q,cases q,assumption,\nend\n\nexample : (P → Q → R) → (P ∧ Q → R) :=\nbegin\n  intros q w,apply q,cases w,assumption,cases w, assumption,\nend\n\nexample : P → Q → P ∧ Q :=\nbegin\n  intros q w, split, assumption,assumption,\nend\n\n/-- `∧` is symmetric -/\nexample : P ∧ Q → Q ∧ P :=\nbegin\n  intro q,cases q,split ,assumption, assumption,\nend\n\nexample : P → P ∧ true :=\nbegin\n  intro q,split,assumption,triv,\nend\n\nexample : false → P ∧ false :=\nbegin\n  intro q,split ,by_contra,triv,triv,\nend\n\n/-- `∧` is transitive -/\nexample : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  intros q w,split, cases q,assumption,cases w,assumption,\nend\n\nexample : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  intros q w e,apply q,split, assumption ,assumption,\nend\n\n\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/section01logic/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7909604893027483}}
{"text": "import data.nat data.set\nopen nat set\n\nvariable {T : Type}\n\n/-\nLemma 2: A Δ B ⊆ (A ∪ B) – (A ∩ B)\nProof of Lemma 2: We will show that for any x ∈ A Δ B, x ∈ (A ∪ B) – (A ∩ B). Consider any\nx ∈ A Δ B. Then either x ∈ A and x ∉ B, or x ∈ B and x ∉ A. Assume without loss of generality that\nx ∈ A and x ∉ B. Since x ∈ A, x ∈ A ∪ B. Since x ∉ B, x ∉ A ∩ B, so x ∈ (A ∪ B) – (A ∩ B). Since our\nchoice of x was arbitrary, we have that A Δ B ⊆ (A ∪ B) – (A ∩ B). ■\n-/\n\ndefinition set_minus [reducible] (A B : set T) := \n  λ x, x ∈ A ∧ ¬ x ∈ B\n\nnotation a - b := set_minus a b\n\nexample : ∀ (A B : set T) (x : T), (x ∈ A ∧ x ∉ B) ∨ (x ∈ B ∧ x ∉ A) → x ∈ A ∪ B - A ∩ B := sorry\n\n/-\nTheorem: If m and n have opposite parity, m + n is odd\nProof: Without loss of generality, assume that m is odd and n is even. Since m is odd, there exists an\ninteger r such that m = 2r + 1. Since n is even, there exists an integer s such that n = 2s. Then\nm + n = 2r + 1 + 2s = 2(r + s) + 1. Consequently, m + n is odd. ■\n-/\n\ndefinition even (x : nat) := ∃ k, x = 2 * k.\ndefinition odd (x : nat) := ∃ k, x = 2 * k + 1.\n\nexample : ∀ (m n : nat), (odd m ∧ even n) ∨ (odd n ∧ even n) → odd (m + n) := sorry\n\n/-\nTheorem: Let G be an undirected graph and let C1 and C2 be connected components of G. If C1 ≠ C2,\nthen C1 ∩ C2 = Ø.\nProof: By contradiction. Suppose that C1 and C2 are connected components of some undirected\ngraph G, that C1 ≠ C2, but that C1 ∩ C2 ≠ Ø. Since C1 ∩ C2 ≠ Ø, there must be some node v such that\nv ∈ C1 and v ∈ C2. Furthermore, since C1 ≠ C2, there must be some node u that either u ∈ C1 or\nu ∈ C2, but not both. Without loss of generality, assume that u ∈ C1 and u ∉ C2.\nBy the definition of a connected component, since u ∈ C1 and v ∈ C1, we know u ↔ v. Similarly, by\nthe definition of a connected component, since v ∈ C2 and u ∉ C2, we know that u ↮ v, contradicting\nour previous assertion. We have reached a contradiction, so our assumption must have been wrong.\nThus C1 ∩ C2 = Ø, as required. ■\n-/\n\n-- similar to the first one\nexample : ∀ (C1 C2 : set T) (u : T), (u ∈ C1 ∧ u ∉ C2) ∨ (u ∈ C2 ∧ u ∉ C1) → true := sorry\n\n/-\nTheorem: Let G = (V, E) be any graph containing a simple cycle C. Let u, v ∈ V be nodes in G. If\nu ↔ v, then after deleting any single edge in C from graph G, it is still the case that u ↔ v.\nProof: Consider any graph G = (V, E) with a simple cycle C = (x1, x2, …, xn, x1). Consider any u, v ∈\nV such that u ↔ v. This means that there must be some simple path (u, y1, y2, …, ym, v) from u to v.\n*\nNow, suppose that we remove the edge {xi, xi+1} from G.\n†\n We need to show that u ↔ v in this modified\ngraph. We consider two cases. First, it might be the case that the edge {xi, xi+1} does not appear\non the path (u, y1, …, ym, v). In that case, the path (u, y1, …, ym, v) is a valid path from u to v in the\nnew graph, so u ↔ v still holds.\nSecond, it might be the case that the edge {xi, xi+1} appears somewhere in our original path (u, y1, …,\nym, v). Since the graph is undirected, the edge might appear as {xi, xi+1} or as {xi+1, xi} when it occurs\nin the path. Assume without loss of generality that it appears as {xi, xi+1} (otherwise, we can just reverse\nthe ordering of the nodes in the original cycle so as to relabel the edges). This means that we\ncan split the original path into three smaller paths – a path from u to xi, then the edge {xi, xi+1}, and finally\na path from xi+1 to v. Thus u ↔ xi and xi+1 ↔ v. Now, since the edge {xi, xi+1} lies on the cycle\nC, after deleting the edge from the cycle, there is still a path from xi to xi+1. Specifically, we can follow\nthe edges of the cycle in reverse from xi until we reach xi+1. In other words, in this new graph, we\nmust have that xi ↔ xi+1.\nSince in this new graph u ↔ xi, xi ↔ xi+1, and xi+1 ↔ v, we thus have that u ↔ v in the new graph, as\nrequired. ■\n\n* We have not formally proven that u ↔ v iff there is a simple path from u to v. It's a good exercise to try to prove this result. As a hint, try using\nthe well-ordering principle by considering the shortest path from u to v and proving that it must be a simple path.\n† It might be the case that this edge is the last edge on the cycle, which goes from xn to x1. In proofs such as this one, it is typical to allow for a\nslight abuse of notation by letting xi+1 mean “the next node on the cycle,” which might not necessarily have the next index.\n-/\n\n-- Not sure why he needs a directionality of the edge at all...weird\n\n/-\nTheorem: Let G be a tree with at least one edge. If any edge is removed from G, the resulting graph\nconsists of two connected components that are each trees over their respective nodes.\nProof: Let G = (V, E) be a tree with at least one edge, and let {u, v} ∈ E be an arbitrary edge of G.\nBy our lemma, if we remove {u, v} from G, we are left with two connected components; call them Cu\nand Cv, with u ∈ Cu and v ∈ Cv. Since Cu and Cv are connected components, they are connected. Consequently,\nif we can show that Cu and Cv are acyclic, then we can conclude that Cu and Cv are trees.\nTo show that Cu and Cv are acyclic, assume for the sake of contradiction that at least one of them is\nnot; without loss of generality, let it be Cu. This means that there is a simple cycle contained purely\nwithin Cu. But since all of the edges in Cu are also present in G, this means that there is a simple cycle\nin G, contradicting the fact that G is a tree. We have reached a contradiction, so our assumption\nmust have been wrong. Thus Cu and Cv must be acyclic, and therefore are trees. ■\n-/\n\n-- example acyclic Cu ∨ acyclic Cv → false\n\n/-\nTheorem: Let T = (V, E) be a tree. If |V| = 1, then V has exactly one leaf node. Otherwise, V has at\nleast two leaf nodes.\nProof: By induction. Let P(n) be “any tree with n nodes has exactly one leaf if n = 1 and at least two\nleaves if n ≥ 2.” We prove P(n) is true for all n ∈ ℕ⁺ by induction on n.\nAssume that for some n ∈ ℕ⁺, that for all n' ∈ ℕ⁺ with n' < n, that P(n') holds and any tree with n'\nnodes either has one node and exactly one leaf, or has at least two nodes and at least two leaves. We\nwill prove that P(n) holds in this case.\nFirst, if n = 1, then the only tree with n nodes is one with a single isolated node. This node has no\nedges connected to it, so it is a leaf. Thus P(n) holds.\nOtherwise, assume that n ≥ 2 and consider any tree T with n nodes. Choose any edge of T and remove\nit; this splits T into two subtrees T1 and T2. We now consider three cases about the relative\nsizes of T1 and T2.\nCase 1: T1 and T2 each have one node. This means that the tree T has exactly two nodes, so it has exactly\none edge. Thus each of the nodes in T are leaves, since they are incident to just one edge each,\nand so T has at least two leaves.\nCase 2: Both T1 and T2 have at least two nodes. By the inductive hypothesis, this means that T1 and\nT2 each have two leaf nodes, meaning that there are at least four nodes in the graph that have at most\none edge touching them. When we add back to T the initial edge that we deleted, this new edge can\nbe incident to at most two of these nodes. Consequently, the other two nodes must still have at most\none edge incident to them, and so they are still leaves in the overall graph T. Thus T has at least two\nleaves.\nCase 3: One of T1 and T2 has exactly one node, and the other has at least two. Without loss of generality,\nassume that T1 has one node u, and that T2 has at least two. By the inductive hypothesis, T2 has\nat least two leaves. Also by the inductive hypothesis, T1's sole node u must be a leaf, and moreover it\nmust have no edges incident to it, because any one-node graph must have no edges. When we add\nback to T the initial edge that we deleted, this edge will be incident to u and incident to at most one\nof the at least two leaves from T2. This means that there are now at least two leaves in T: first, the\nnode u, which now has exactly one edge incident to it, and second, one of the leaves from T2 that is\nnot incident to the new edge. Thus T has at least two leaves.\nThus in all three cases T has at least two leaves, so P(n) holds, completing the induction. ■ \n-/\n\n-- Another simple binary disjunction, binary commutative relation one.\n\n/-\nLemma: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. Then for any two sets [x]R,\n[y]R ∈ X, if [x]R ≠ [y]R, then [x]R ∩ [y]R = Ø.\nProof: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. We proceed by contrapositive\nand show that for any [x]R, [y]R ∈ X, that if [x]R ∩ [y]R ≠ Ø, then [x]R = [y]R.\nConsider any [x]R, [y]R ∈ X such that [x]R ∩ [y]R ≠ Ø. Then there must be some element w such that\nw ∈ [x]R and w ∈ [y]R. By definition, this means w ∈ { z ∈ A | xRz } and w ∈ { z ∈ A | yRz }. Consequently,\nxRw and yRw. Since R is symmetric, this means that xRw and wRy. Since R is transitive,\nthis means that xRy. By symmetry, we also have that yRx.\nWe will now use this fact to show that [x]R ⊆ [y]R. Without loss of generality, we can use this same\nargument to show that [y]R ⊆ [x]R, from which we can conclude that [x]R = [y]R, as required.\nTo show that [x]R ⊆ [y]R, consider any z ∈ [x]R. This means that xRz. Since yRx and xRz, by transitivity\nwe have that yRz. Consequently, z ∈ [y]R. Since our choice of z was arbitrary, we have that any\nz ∈ [x]R satisfies z ∈ [y]R. Thus [x]R ⊆ [y]R, as required. ■\n-/\n\n-- This one is a bit more subtle. \n\n--Goal: (R x y → P x y) ∧ (R y x → P y x)\n--no special knowledge of x and y\n--wlog assume R x y\n-- this is a weird one\n\n/-\nTheorem: | is a partial order over ℕ.\nProof: We will show that | is reflexive, antisymmetric, and transitive. To see that | is reflexive, we will\nprove that for any n ∈ ℕ, that n | n (that there exists some q ∈ ℕ such that n = nq). So let n be any\nnatural number, and take q = 1. Then nq = n · 1 = n, so n | n.\nTo see that | is antisymmetric, we will prove that for any m, n ∈ ℕ, that if m | n and n | m, that m = n.\nConsider any m, n ∈ ℕ where m | n and n | m. This means that there exists q, r ∈ ℕ such that n = mq\nand m = nr. Consequently:\nm = nr = (mq)r = mqr\nn = mq = (nr)q = nqr\nWe now consider two cases. First, if m = n = 0, then we are done, since m = n. Otherwise, at least\none of m or n is nonzero; without loss of generality, assume m ≠ 0. Then since m = mqr, we know\nthat 1 = qr. Since q, r ∈ ℕ, this is only possible if q = r = 1. Consequently, m = nr = n · 1 = n, so\nm = n, as required.\nTo see that | is transitive, we will prove that for any m, n, p ∈ ℕ, that if m | n and n | p, then m | p.\nConsider any m, n, p ∈ ℕ where m | n and n | p; then there must exist q, r ∈ ℕ such that n = qm and\np = rn. Consequently, p = rn = r(qm) = qrm = (qr)m. Since qr ∈ ℕ, this means that there is some\nk ∈ ℕ (namely, qr) such that p = km. Thus m | p, as required.\nSince | is reflexive, antisymmetric, and transitive over ℕ, | is a partial order over ℕ.\n-/\n\n--standard case: \n--m = n vs n = m\n\n------------------------------------\n\n--Either: \n--have an OR (wlog, assume _)\n--or want to show an AND (wlog, we'll show that _) -- this one is sketchier, I am okay ignoring it for now\n\n\n\nexample : ∀ (A B : set T) (x : T), (x ∈ A ∧ x ∉ B) ∨ (x ∈ B ∧ x ∉ A) → x ∈ A ∪ B - A ∩ B := \n  assume A B x x_or_and,\n  wlog x_or_and\n       (assume x_in_A_nin_B : x ∈ A ∧ x ∉ B,\n        show x ∈ A ∪ B - A ∩ B, from sorry)\n\nopen prod.ops\n\nexample : ∀ (A B : set T) (x : T), \n  let R := λ UV, x ∈ UV.1 ∧ x ∉ UV.2 in\n  let Goal := λ \n  let Pi := _ in -- permutations on pairs\n  have can_assume_generic : R (A,B) ∨ R (B,A) ↔ ∀ (pi : Pi), R (pi (A,B)),\n  have suffices : ∀ pi, Goal (pi (A,B)) → Goal (A,B),\n  -- replace assumption,\n  assume pi RpiAB,\n  show Goal (pi (A,B)),\n  show Goal (A,B)\n  \n  \n-- Binary wlog\ncheck @or.elim\ncheck @bool.rec\n\n-- or.elim : ∀ {a b c : Prop}, a ∨ b → (a → c) → (b → c) → c\n-- bool.rec : Π {C : bool → Type}, C bool.ff → C bool.tt → (Π (n : bool), C n)\n-- or.rec : ∀ {a b C : Prop}, (a → C) → (b → C) → a ∨ b → C\n\n-- wlog : Π (disj : ?A ∨ ?B) (?A → ?G) : ?G\n-- wlog : Π (disj : ?A ∨ ?B) (a_to_G : @?F ?T ?A) {Aok : ?F ?A = G} {Bok : ?F ?B → G} :=\n  or.elim disj (eq.rec a_to_G Aok)\n               (Bok ?)\n\n-- hmm...this is confusing\n-- I provide a proof of (A → C), which we can \"generalize\" to a proof of (∀ {?T}, ?T → ?G)\n-- and then `Aok` and `Bok` can handle the conversions.\n\n\n       (assume x_in_A_nin_B : x ∈ A ∧ x ∉ B,\n        show x ∈ A ∪ B - A ∩ B, from sorry)\nwlog := or.elim disj (F \n\ndefinition wlog : ∀ {A B C : Prop} { MysteryType1 MysteryType2 : Type } { F : Π {M1 : MysteryType1}  (M2 : M1), M2 → C }\n  (disj : A ∨ B) (pf1 : F A) : C :=\n  or.rec pf1 (λ b, \n      @or.elim a b c disj (@\n  C a → c :=\n\n----------------\nlemma opposite_parity_sum_odd : ∀ (m n : nat), opposite_parity m n → odd (m + n) :=\n  assume m n : nat,\n\n  -- Without loss of generality, assume that m is odd and n is even.\n  suffices_to_show (∀ (m n : nat), odd m ∧ even n → odd (m + n))\n\n    (assume (lem : ∀ (m n : nat), odd m ∧ even n → odd (m + n)) \n            (m n : nat) (opp_mn : opposite_parity m n),\n      or.elim opp_mn (assume H : odd m ∧ even n, lem m n H) (assume H : odd n ∧ even m, (add_comm n m) ▸ (lem n m H)))\n\n    (take (m n : nat),\n", "meta": {"author": "dselsam", "repo": "cs103", "sha": "31ab9784a6f65f226efb702a0da52f907c616a71", "save_path": "github-repos/lean/dselsam-cs103", "path": "github-repos/lean/dselsam-cs103/cs103-31ab9784a6f65f226efb702a0da52f907c616a71/wlog.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087946129328, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7909604791772645}}
{"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: `𝔠`, localized in `cardinal`) to be `2 ^ ω`.\nWe also prove some `simp` lemmas about cardinal arithmetic involving `𝔠`.\n\n## Notation\n\n- `𝔠` : 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 ^ omega.{u}\n\nlocalized \"notation `𝔠` := cardinal.continuum\" in cardinal\n\n@[simp] lemma two_power_omega : (2 ^ omega.{u} : cardinal.{u}) = 𝔠 := rfl\n\n@[simp] lemma lift_continuum : lift.{v} continuum.{u} = 𝔠 :=\nby rw [← two_power_omega, lift_two_power, lift_omega, two_power_omega]\n\n/-!\n### Inequalities\n-/\n\nlemma omega_lt_continuum : ω < 𝔠 := cantor ω\n\nlemma omega_le_continuum : ω ≤ 𝔠 := omega_lt_continuum.le\n\nlemma nat_lt_continuum (n : ℕ) : ↑n < 𝔠 := (nat_lt_omega n).trans omega_lt_continuum\n\nlemma mk_set_nat : #(set ℕ) = 𝔠 := by simp\n\nlemma continuum_pos : 0 < 𝔠 := nat_lt_continuum 0\n\nlemma continuum_ne_zero : 𝔠 ≠ 0 := continuum_pos.ne'\n\n/-!\n### Addition\n-/\n\n@[simp] lemma omega_add_continuum : ω + 𝔠 = 𝔠 :=\nadd_eq_right omega_le_continuum omega_le_continuum\n\n@[simp] lemma continuum_add_omega : 𝔠 + ω = 𝔠 :=\n(add_comm _ _).trans omega_add_continuum\n\n@[simp] lemma continuum_add_self : 𝔠 + 𝔠 = 𝔠 :=\nadd_eq_right omega_le_continuum le_rfl\n\n@[simp] lemma nat_add_continuum (n : ℕ) : ↑n + 𝔠 = 𝔠 :=\nadd_eq_right omega_le_continuum (nat_lt_continuum n).le\n\n@[simp] lemma continuum_add_nat (n : ℕ) : 𝔠 + n = 𝔠 :=\n(add_comm _ _).trans (nat_add_continuum n)\n\n/-!\n### Multiplication\n-/\n\n@[simp] lemma continuum_mul_self : 𝔠 * 𝔠 = 𝔠 :=\nmul_eq_left omega_le_continuum le_rfl continuum_ne_zero\n\n@[simp] lemma continuum_mul_omega : 𝔠 * ω = 𝔠 :=\nmul_eq_left omega_le_continuum omega_le_continuum omega_ne_zero\n\n@[simp] lemma omega_mul_continuum : ω * 𝔠 = 𝔠 :=\n(mul_comm _ _).trans continuum_mul_omega\n\n@[simp] lemma nat_mul_continuum {n : ℕ} (hn : n ≠ 0) :\n  ↑n * 𝔠 = 𝔠 :=\nmul_eq_right omega_le_continuum (nat_lt_continuum n).le (nat.cast_ne_zero.2 hn)\n\n@[simp] lemma continuum_mul_nat {n : ℕ} (hn : n ≠ 0) :\n  𝔠 * n = 𝔠 :=\n(mul_comm _ _).trans (nat_mul_continuum hn)\n\n/-!\n### Power\n-/\n\n@[simp] lemma omega_power_omega : omega.{u} ^ omega.{u} = 𝔠 :=\npower_self_eq le_rfl\n\n@[simp] lemma nat_power_omega {n : ℕ} (hn : 2 ≤ n) : (n ^ omega.{u} : cardinal.{u}) = 𝔠 :=\nnat_power_eq le_rfl hn\n\n@[simp] lemma continuum_power_omega : continuum.{u} ^ omega.{u} = 𝔠 :=\nby rw [← two_power_omega, ← power_mul, mul_eq_left le_rfl le_rfl omega_ne_zero]\n\nend cardinal\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/continuum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7909278329238602}}
{"text": "import tactic\nvariables (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 ∧ Q`. This is true iff P and Q are both true.\n\n# cases \n\n Given `h : P ∧ 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 ∧ Q` -/ \n\n-- 01\nexample (h : P ∧ Q) : P:=\nbegin\n  cases h with hp hq, \n  -- Now have \n  -- hp : P, \n  -- hq : Q\n  exact hp,\nend\n\n/- If our goal is `⊢ P ∧ Q` then we can use `split` to create two new goals\none `⊢ P` and the other `⊢ Q` -/\n\n-- 02\nexample (hp : P) (hq : Q) : P ∧ Q :=\nbegin\n  split,\n/-\n2 goals\nPQ: Prop\nhp: P\nhq: Q\n⊢ P\nPQ: Prop\nhp: P\nhq: Q\n⊢ Q-/\n  { -- Inside `{ }` we only see the 1st goal\n    exact hp,\n  },\n  { -- Inside `{ }` we only see the 2nd goal\n    exact hq,\n  },\nend\n\n/- \nDot notation: if we have `(hpq : P ∧ 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 `⟨hp,hq⟩ : P ∧ Q` \ni.e. `⟨hp,hq⟩` is a term of type `P ∧ Q`. \n\nThe angled brackets are typed `\\<` and `\\>` -/\n-- 03\nexample (hpq : P ∧ Q) : Q ∧ P :=\nbegin\n  cases hpq with hp hq, \n  split, \n  {\n    exact hq,\n  }, \n  { \n    exact hp,\n  },\n  -- or more simply `exact ⟨hpq.2,hpq.1⟩,`\nend\n\n-- Having introduced `→` and `∧` we get `iff` (written `↔`) for free\n-- `P ↔ Q` is:  `P → Q` and `Q → P`\n-- 04\nexample : P ∧ Q ↔ Q ∧ P := \nbegin\n  split,\n  {\n    intro hpq, cases hpq with hp hq,\n    split, \n    {\n      exact hq,\n    },\n    {\n      exact hp,\n    },\n  },\n  {\n    sorry,\n  }\nend\n\n-- 05 \nexample : P ∧ Q → Q :=\nbegin\n  sorry,\nend\n\n-- in Lean `P ∧ Q ∧ R` means `P ∧ (Q ∧ R)` (∧ 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 ∧ Q ∧ R ∧ S ) : R :=\nbegin\n  sorry,\nend\n\n-- 07\nexample : P → Q → P ∧ Q :=\nbegin\n  sorry,\nend\n\n-- 08\nexample : P ∧ Q → Q ∧ R → P ∧ R :=\nbegin\n  sorry,\nend\n\n-- 09\nexample :  P ∧ R ∧ Q → Q ∧ P ∧ R := \nbegin\n  sorry,\nend\n\n/-\n   # Or (disjunction)\n\nThe proposition `P or Q` is written  `P ∨ Q`. \n \n `P ∨ Q` is true iff P is true or Q is true.\n\nIf our goal is `⊢ P ∨ 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 ∨ P :=\nbegin\n  right, -- Goal is now `⊢ P`\n  exact hp,\nend\n\n/-\nGiven `(hpq : P ∨ 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 ∨ Q) : Q ∨ P :=\nbegin\n  cases hpq with hp hq, \n  /-\n2 goals\ncase or.inl\nPQ: Prop\nhp: P\n⊢ Q ∨ P\ncase or.inr\nPQ: Prop\nhq: Q\n⊢ Q ∨ P-/\n{\n  right, exact hp,\n},\n{\n  left, exact hq,\n}\nend\n\n-- 12 \nexample : (P ∨ Q) ∧ (P → Q) → Q :=\nbegin\n  sorry,\nend\n\n-- 13 \nexample : (P ∨ Q) ∧ (P ∨ R) → P ∨ (Q ∧ R):=\nbegin \n  sorry,\nend\n\n-- 14 \nexample : (P ∨ Q) ∧ (R ∨ S) → (P ∧ R) ∨ (P ∧ S) ∨ (Q ∧ R) ∨ (Q ∧ S):=\nbegin\n  sorry, \nend\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\n-- 15\nexample : true := \nbegin\n  triv, \nend\n\n-- 16\nexample: P → true :=\nbegin\n  sorry\nend\n\n-- 17\nexample : false → P:=\nbegin\n  intro f, \n  contradiction,\nend\n\n-- 18\nexample : false → true:=\nbegin\n  sorry, \nend\n\n-- 19 \nexample : true → false → true → false → true :=\nbegin\n  sorry,\nend\n\n/- \n# Negation\n\nIf `P : Prop` then `not P` is denoted `¬ P` this is defined to be `P → false`  -/\n-- 20\nexample : ¬ P ↔ (P → false):=\nbegin \n  refl,\nend\n\n-- 21\nexample : ¬ true → false :=\nbegin\n  sorry,\nend\n\n-- 22\nexample : ¬ false → true :=\nbegin\n  sorry,\nend\n\n-- 23\nexample : P → ¬¬P :=\nbegin\n  sorry,\nend\n\n-- 24\nexample (hp : P) (hnp : ¬ P) : Q ∧ R → ¬ Q  :=\nbegin\n  sorry,\nend\n\n-- Can you explain how the following proof works?\n-- 25\nexample (hp : P) (hnp : ¬ P) : Q :=\nbegin\n  cases (hnp hp), -- Hint: what is `(hnp hp)`?\nend\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/2_logic/more_basics_and_or_not.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7909278261282549}}
{"text": "/-\nCS 2120 F22 Homework #4. Due Oct 13.\n-/\n\n/- #1A [10 points]\n\nWrite a formal proposition stating that \nlogical and (∧) is associative. That is, \nfor arbitrary propositions, P, Q, and R,\nP ∧ (Q ∧ R) is true *iff* (P ∧ Q) ∧ R is, \ntoo. Replace the placeholder (_) with your\nanswer.\n-/\n\ndef and_associative : Prop := ∀ (P Q R), P ∧ Q ∧ R ↔ (P ∧ Q) ∧ R\n\n-- and is right associative\n\n\n\n\n/- #1B [10 points]\n\nGive an English language proof. Identify\nthe inference rules of predicate logic\nthat you use in your reasoning.\n-/\n\n/-\nAnswer: \n-/\n\n/- #1C [5 points]\n\nGive a formal proof of the proposition.\nHint: unfold and_associative to start.\n-/\n\ntheorem and_assoc_true : and_associative :=\nbegin\nunfold and_associative,     -- expand definition of and_associative\nassume P Q R,               -- ∀ intro\napply iff.intro _ _,        -- iff intro \n\n-- forward\nassume pqr,                 -- assume premise \ncases pqr with p qr,        -- \"unbox\" proofs of P and of Q ∧ R\ncases qr with q r,          -- \"unbox\" proofs of Q and R\nlet pq := (and.intro p q),  -- \"rebox\" proofs of P and of Q to prove P ∧ Q\napply (and.intro pq r),     -- \"box\" that up with a proof of r\n-- that complete the proof in the forward direction\n\n-- reverse \n\n\nend\n\n\n\n/- #2A [10 points]\n\nWrite the proposition that ∨ is associative.,\nanalogous to the proposition about ∧ in #1.\n-/\n\ndef or_associative : Prop := \n  _\n\n\n/- #2B [10 points]\n\nWrite an English language proof of it, citing\nthe specific inference rules you use in your\nreasoning.\n-/\n\n\n/- #2C [5 points]\n\nComplete the following formal proof.\n-/\n\ntheorem or_associative_true : or_associative :=\nbegin\nend\n\n\n/- #3A [10 points]\nWrite a formal statement of the proposition.\n-/\n\ndef arrow_transitive : Prop :=\n  _\n\n\n/-\nIf there smoke there's fire\nIf there's fire there's light\nIf there's light, everything's good\nAnd there's smoke. So everything's good.\nRight?\n-/\n\n-- The basic propositions\nvariables (Smoke Fire Light Good : Prop)\n-- The implications\nvariables (sf : Smoke → Fire) (fl : Fire → Light) (lg : Light → Good)\n-- The premise\nvariable (s : Smoke)\n\nexample : ∀ (S F L G : Prop), (S → F) → (F → L) → (L → G) → S → G:=\nbegin\nassume S F L G,   -- assume the basic propositions\nassume sf fl lg,  -- assume the implication hypotheses\nassume s,         -- assume there's smoke, now show everything good\n\n/- this works\napply lg,\napply fl,\napply sf,\nexact s\n-/\n\n-- so does this\nexact lg (fl (sf s)),\n-- make sure you understand it both ways\n-- understand arrow elimination\n-- arrow elimination is like function application!\nend\n\n\n/-\nEercise with negation\n-/\n\nexample :0 ≠ 1 :=\nbegin\nassume p,\ncases p,\nend \n\n\nexample : ∀ P, ¬(P ∧ ¬P) :=\nbegin\nassume P,\nassume pandnp,\ncases pandnp with p np,\napply false.elim (np p),\nend\n\n/- #3B [10 points]\n\nWrite an English language proof of the proposition\nthat for any propositions, X, Y, and X, it's the\ncase that (X → Y) → (Y → Z) → (X → Z). In other\nwords, implication is \"transitive.\" Hint: Recall\nthat if you have a proof of, say, X → Y, and you \nhave a proof of X, you can derive a proof of Y by\narrow elimination. Think of it as applying a proof\nof an implication to a proof of its premise to get\nyourself a proof of its conclusion.\n-/\n\n\n/- #3C [5 points]. \nWrite a formal proof of it.\n-/\n\n\n/- #4\nSuppose that if it's raining then the streets\nare wet. This problem requires you to prove that\nif the streets are not wet then it's not raining.\n-/\n\n/- #4A [10 points]\n\nStart by writing the proposition in predicate\nlogic by completing the following answer.\n-/\n\ndef contrapositive : Prop :=\n  ∀ (Raining Wet : Prop), \n    (Raining → Wet) → (¬Raining → ¬Wet)\n\n\n/- #4B [10 points]. \n-/\n\ntheorem contrapositive_valid : contrapositive :=\nbegin\n\n/- #4C [5 points]. \n\nGive an English language proof of it.\n-/\n\n\n/- #5. Extra credit.\n\nComplete the following formal proof of the \nproposition that if for any proposition P, \nP ∨ ¬P is true, then for any propositions, \nX and Y, if it's not the case that X or Y\nis true then it is the case that ¬X and ¬Y \nis true. \n-/\n\ntheorem demorgan1 : \n  (∀ (P : Prop), P ∨ ¬ P) → \n    ∀ (X Y : Prop), \n      ¬(X ∨ Y) → (¬X ∧ ¬Y) :=\nbegin\nassume em X Y nxory,\ncases (em X) with x nx,\nlet foo := or.intro_left Y x,\n_\nend\n\n/-\nA comment on or.intro_left and or.intro_right.\nIn Lean each of these takes two arguments: a\nproof of the disjunct -- the proposition on \none side of the ∨ -- that is to be proven true, \n*and* it takes as an argument the proposition \nthat is not being proven true. In applications \nof these rules the proposition argument (not \nbeing proven) comes first, while the proof \nargument comes second.\n\nThe reason is that Lean needs to know what \noverall proposition is being proved. From the\nproof argument it can infer the proposition \nbeing proved, but it needs the other proposition\nas well to know the full (X ∨ Y) disjunction to\nbe proved. \n\nHere's an example:\n-/\n\nexample : 0 = 0 ∨ 0 = 1 :=\nbegin\napply or.intro_left (0 = 1) rfl\n/-\nThe \"rfl\" serves as a proof of 0=0.\nBut in addition, as the first argument\nto or.intro, we need to provide the\n*proposition* that is not being proved.\nHere's that's (0 = 1). In contexts\nwhere Lean can infer both disuncts,\nyou can use the simpler or.inl or \nor.inr, each of which just takes one\nargument: a proof of the left or of \nthe right side, respectively.\n-/\nend\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/homeworks/hw4/hw4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8962513807543223, "lm_q1q2_score": 0.7908771937259284}}
{"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.list.range\n\nopen list function nat\n\nnamespace list\nnamespace nat\n\n/-- The antidiagonal of a natural number `n` is the list of pairs `(i,j)` such that `i+j = n`. -/\ndef antidiagonal (n : ℕ) : list (ℕ × ℕ) :=\n(range (n+1)).map (λ i, (i, n - i))\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 : ℕ} {x : ℕ × ℕ} :\n  x ∈ antidiagonal n ↔ x.1 + x.2 = n :=\nbegin\n  rw [antidiagonal, mem_map], split,\n  { rintros ⟨i, hi, rfl⟩, rw [mem_range, lt_succ_iff] at hi, exact add_sub_of_le hi },\n  { rintro rfl, refine ⟨x.fst, _, _⟩,\n    { rw [mem_range, add_assoc, lt_add_iff_pos_right], exact zero_lt_succ _ },\n    { exact prod.ext rfl (nat.add_sub_cancel_left _ _) } }\nend\n\n/-- The length of the antidiagonal of `n` is `n+1`. -/\n@[simp] lemma length_antidiagonal (n : ℕ) : (antidiagonal n).length = n+1 :=\nby rw [antidiagonal, length_map, length_range]\n\n/-- The antidiagonal of `0` is the list `[(0,0)]` -/\n@[simp] lemma antidiagonal_zero : antidiagonal 0 = [(0, 0)] :=\nrfl\n\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\nlemma nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) :=\nnodup_map (@left_inverse.injective ℕ (ℕ × ℕ) prod.fst (λ i, (i, n-i)) $ λ i, rfl) (nodup_range _)\n\n@[simp] lemma antidiagonal_succ {n : ℕ} :\n  antidiagonal (n + 1) = (0, n + 1) :: ((antidiagonal n).map (prod.map nat.succ id) ) :=\nbegin\n  simp only [antidiagonal, range_succ_eq_map, map_cons, true_and, nat.add_succ_sub_one, add_zero, \n    id.def, eq_self_iff_true, nat.sub_zero, map_map, prod.map_mk],\n  apply congr (congr rfl _) rfl,\n  ext; simp,\nend\n\nend nat\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/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.7908771879786672}}
{"text": "def chℕ := Π X : Type, (X → X) → X → X\n\nnamespace chnat \n\nopen nat\n\ndefinition to_nat (m : chℕ) : ℕ := m ℕ nat.succ 0 \n\ndef of_nat : ℕ → chℕ \n| (zero) X f x := x\n| (succ n) X f x := f (of_nat n X f x) -- f (f^n x)\n\ndef pow : chℕ → chℕ → chℕ :=\nλ m n, λ X f x, n (X → X) (m X) f x\n\n#print chnat.pow\n\ndef pow' (m n : chℕ) : chℕ\n| X f x := n (X → X) (m X) f x\n\n#print chnat.pow'\n\ntheorem of_nat_pow (m n : ℕ) : of_nat (m ^ n) = pow (of_nat m) (of_nat n) := begin\ninduction n with n H;funext,refl,\nunfold has_pow.pow,\nunfold nat.pow,\nunfold has_pow.pow at H,\n\nend \n\n\nend chnat", "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_numeral_puzzle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7908659355893776}}
{"text": "/- LoVe Exercise 11: Logical Foundations of Mathematics -/\n\nimport .love11_logical_foundations_of_mathematics_demo\n\nnamespace LoVe\n\nuniverse variable u\n\nset_option pp.beta true\n\n\n/- Question 1: Subtypes -/\n\nnamespace my_vector\n\n/- Recall the definition of vectors from the lecture: -/\n\n#check vector\n\n/- The following function adds two lists of integers elementwise. If one\nfunction is longer than the other, the tail of the longer function is\ntruncated. -/\n\ndef list_add : list ℤ → list ℤ → list ℤ\n| []        []        := []\n| (x :: xs) (y :: ys) := (x + y) :: list_add xs ys\n| []        (y :: ys) := []\n| (x :: xs) []        := []\n\n/- 1.1. Show that if the lists have the same length, the resulting list also has\nthat length. -/\n\nlemma length_list_add :\n  ∀(xs : list ℤ) (ys : list ℤ) (h : list.length xs = list.length ys),\n    list.length (list_add xs ys) = list.length xs\n| []        []        :=\n  by simp [list_add]\n| (x :: xs) (y :: ys) :=\n  begin\n    simp [list_add, length],\n    intro h,\n    rw length_list_add xs ys h\n  end\n| []        (y :: ys) :=\n  begin\n    intro h,\n    cases h\n  end\n| (x :: xs) []        :=\n  begin\n    intro h,\n    cases h\n  end\n\n/- 1.2. Define componentwise addition on vectors using `list_add` and\n`length_list_add`. -/\n\ndef add {n : ℕ} : vector ℤ n → vector ℤ n → vector ℤ n :=\nλx y, subtype.mk (list_add (subtype.val x) (subtype.val y))\n  begin\n    rw length_list_add,\n    { exact subtype.property x },\n    { rw [subtype.property x, subtype.property y] }\n  end\n\n/- 1.3. Show that `list_add` and `add` are commutative. -/\n\nlemma list_add_comm :\n  ∀(xs : list ℤ) (ys : list ℤ), list_add xs ys = list_add ys xs\n| []        []        := by refl\n| (x :: xs) (y :: ys) := by simp [list_add]; rw list_add_comm\n| []        (y :: ys) := by refl\n| (x :: xs) []        := by refl\n\nlemma add_comm {n : ℕ} (x y : vector ℤ n) :\n  add x y = add y x :=\nbegin\n  apply subtype.eq,\n  simp [add],\n  apply list_add_comm\nend\n\nend my_vector\n\n\n/- Question 2: Integers as Quotients -/\n\n/- Recall the construction of integers from the lecture: -/\n\n#check myℤ.rel\n#check rel_iff\n#check myℤ\n\n/- 2.1. Define negation using `quotient.lift`. -/\n\ndef neg : myℤ → myℤ :=\nquotient.lift (λpn, ⟦(prod.snd pn, prod.fst pn)⟧)\n  begin\n    intros a b h,\n    cases a,\n    cases b,\n    apply quotient.sound,\n    simp [rel_iff] at h ⊢,\n    linarith\n  end\n\n/- 2.2. Prove the following lemmas. -/\n\nlemma neg_mk (p n : ℕ) :\n  neg ⟦(p, n)⟧ = ⟦(n, p)⟧ :=\nby refl\n\nlemma myℤ.neg_neg (a : myℤ) :\n  neg (neg a) = a :=\nbegin\n  apply quotient.induction_on a,\n  intro a,\n  cases a,\n  simp [neg_mk]\nend\n\n\n/- Question 3: Nonempty Types -/\n\n/- In the lecture, we saw the inductive predicate `nonempty` that states that a\ntype has at least one element: -/\n\n#print nonempty\n\n/- 3.1. The purpose of this exercise 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 (α : Sort u) :\n  nonempty α\n\n/- This axiom gives us a fact `sort_nonempty` without having to prove it. It\nresembles a lemma proved by sorry, just without the warning. -/\n\n#check sort_nonempty\n\n/- Prove that this axiom leads to a contradiction, i.e., lets us derive\n`false`. -/\n\nlemma proof_of_false :\n  false :=\nby exact classical.choice (sort_nonempty false)\n\n-- alternative proof:\nlemma proof_of_false' :\n  false :=\nbegin\n  cases sort_nonempty false with h,\n  exact h\nend\n\n/- 3.2 (**optional**). 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 all_nonempty_Type (α : Type u) :\n  nonempty α\n\nlemma proof_of_false₂ : false :=\nbegin\n  let t : Type := {a : ℕ // false},\n  have h : nonempty t := sort_nonempty t,\n  let x : t := classical.choice h,\n  exact subtype.property x\nend\n\n-- alternative proof:\nlemma proof_of_false₂' : false :=\nbegin\n  let t : Type := {a : ℕ // false},\n  cases all_nonempty_Type t with x,\n  exact subtype.property x\nend\n\n\n/- Question 4 (**optional**): Hilbert Choice -/\n\n/- The following command enables noncomputable decidability on every `Prop`. The\n`priority 0` attribute ensures this is used only when necessary; otherwise, it\nwould make some computable definitions noncomputable for Lean. -/\n\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n/- 4.1 (**optional**). Prove the following lemma. -/\n\nlemma exists_minimal_arg.aux (f : ℕ → ℕ) :\n  ∀x n, f n = x → ∃n, ∀i, f n ≤ f i\n| x n eq :=\n  begin\n    -- this works thanks to `classical.prop_decidable`\n    by_cases (∃n', f n' < x),\n    { cases h with n' h,\n      exact exists_minimal_arg.aux _ n' rfl },\n    { have h' : ∀n', x ≤ f n',\n      { intro n',\n        apply le_of_not_gt _,\n        intro h',\n        apply h,\n        use n',\n        exact h' },\n      apply exists.intro n,\n      rw eq,\n      exact h' }\n  end\n\n/- Now this interesting lemma falls off: -/\n\nlemma exists_minimal_arg (f : ℕ → ℕ) :\n  ∃n : ℕ, ∀i : ℕ, f n ≤ f i :=\nexists_minimal_arg.aux f _ 0 rfl\n\n/- 4.2 (**optional**). Use what you learned in the lecture notes to define the\nfollowing function, which returns the (or an) index of the minimal element in\n`f`'s image. -/\n\nnoncomputable def minimal_arg (f : ℕ → ℕ) : ℕ :=\nclassical.some (exists_minimal_arg f)\n\n/- 4.3 (**optional**). Prove the following characteristic lemma about your\ndefinition. -/\n\nlemma minimal_arg_spec (f : ℕ → ℕ) :\n  ∀i : ℕ, f (minimal_arg f) ≤ f i :=\nclassical.some_spec (exists_minimal_arg f)\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/love11_logical_foundations_of_mathematics_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.7908626918895224}}
{"text": "import data.nat.gcd\nimport data.real.irrational\nimport tactic\n\n\n\n#print nat.coprime \n\nexample (m n : nat) (h : m.coprime n) : m.gcd n = 1 := h \n\nexample : nat.coprime 12 7 := by norm_num\nexample : nat.gcd 12 8 = 4 := by norm_num\n\n\n#check @nat.prime_def_lt\n\nexample (p : ℕ) (prime_p : nat.prime p) : 2 ≤ p ∧ ∀ (m : ℕ), m < p → m ∣ p → m = 1 :=\nby rwa nat.prime_def_lt at prime_p\n\n#check @nat.prime.eq_one_or_self_of_dvd\n\nexample (p : ℕ) (prime_p : nat.prime p) : ∀ (m : ℕ), m ∣ p → m = 1 ∨ m = p :=\nprime_p.eq_one_or_self_of_dvd\n\nexample : nat.prime 17 := by norm_num\n\n-- commonly used\nexample : nat.prime 2 := nat.prime_two\nexample : nat.prime 3 := nat.prime_three\n\n\n\n#check @nat.prime.dvd_mul\n#check @nat.prime.dvd_mul \n#check nat.prime_two.dvd_mul\n\nlemma even_of_even_sqr {m : ℕ} (h : 2 ∣ m^2) : 2 ∣ m :=\nbegin\n  rw [pow_two, nat.prime_two.dvd_mul] at h,\n  cases h; assumption,\nend\n\nexample {m n : ℕ} (coprime_mn : m.coprime n) : m^2 ≠ 2 * n^2 :=\nbegin\n  intro sqreq,\n  have : 2 ∣ m,\n    apply even_of_even_sqr,\n    use [n^2, sqreq],\n  \n  obtain ⟨k, meq⟩ := dvd_iff_exists_eq_mul_left.mp this,\n\n  have : 2 * (2 * k^2) = 2 * n^2,\n    rw [←sqreq, meq], ring,\n\n  have : 2 * k^2 = n^2,\n    apply (mul_right_inj' _).mp,\n    from this, norm_num,\n  \n  have : 2 ∣ n,\n    apply even_of_even_sqr,\n    use [k^2, this.symm],\n\n  have : 2 ∣ m.gcd n,\n    apply (dvd_gcd_iff 2 m n).mpr,\n    split, assumption',\n  \n  have : 2 ∣ 1,\n    convert this,\n    from (nat.coprime_iff_gcd_eq_one.mp coprime_mn).symm,\n  \n  norm_num at this,\nend\n\n\nlemma dvd_of_dvd_sq {p m : ℕ} (pp : p.prime) (h : p ∣ m^2) : p ∣ m := \nbegin \n  rw [pow_two, nat.prime.dvd_mul pp] at h,\n  cases h, assumption',\nend\n\nexample {m n p : ℕ} (coprime_mn : m.coprime n) (prime_p : p.prime) : m^2 ≠ p * n^2 :=\nbegin \n  intro heq,\n  have : p ∣ m,\n    apply dvd_of_dvd_sq prime_p,\n    use [n^2, heq],\n\n  obtain ⟨k, meq⟩ := dvd_iff_exists_eq_mul_left.mp this,\n\n  have : p * (p * k^2) = p * n^2,\n    rw [←heq, meq], ring,\n\n  have : p * k^2 = n^2,\n    apply (mul_right_inj' _).mp,\n    from this, exact nat.prime.ne_zero prime_p,\n\n  have : p ∣ n,\n    apply dvd_of_dvd_sq prime_p,\n    use [k^2, this.symm],\n\n  have : p ∣ m.gcd n,\n    apply (dvd_gcd_iff p m n).mpr,\n    split, assumption',\n\n  have : p ∣ 1,\n    convert this,\n    rw nat.coprime_iff_gcd_eq_one.mp,\n    assumption,\n  \n  from nat.prime.not_dvd_one prime_p this,\nend\n\n\n#check nat.factors\n#check nat.prime_of_mem_factors\n#check nat.prod_factors\n#check nat.factors_unique\n\n\n#check @nat.factors_prime\n#eval (12 : ℕ).factors.count 2 -- 2\n\n\ntheorem nat.count_factors_mul_of_pos (m n p : ℕ) (mpos : 0 ≠ m) (npos : 0 ≠ n) :\n  (m * n).factors.count p = m.factors.count p + n.factors.count p :=\nbegin \n  dsimp,\n  repeat {rw nat.factors_count_eq,},\n  rw nat.factorization_mul,\n    refl,\n    from mpos.symm,\n    from npos.symm,\nend\n\ntheorem nat.factors_count_pow (n k p : ℕ) : (n^k).factors.count p = k * n.factors.count p :=\nbegin \n  repeat {rw nat.factors_count_eq,},\n  rw nat.factorization_pow,\n  refl,\nend\n\ntheorem nat.prime_one_factor (p : ℕ) (prime_p : p.prime) : p.factors.count p = 1 :=\nbegin \n  rw nat.factors_prime prime_p,\n  simp,\nend\n\nexample {m n p : ℕ} (nnz : n ≠ 0) (prime_p : p.prime) : m^2 ≠ p * n^2 :=\nbegin\n  intro heq,\n  have nsq_nez : n^2 ≠ 0,\n    by simpa,\n  \n  have eq1 : (m^2).factors.count p = 2 * m.factors.count p,\n    apply nat.factors_count_pow,\n\n  have eq2 : (p * n^2).factors.count p = 2 * n.factors.count p + 1,\n    rw nat.count_factors_mul_of_pos p (n^2),\n    rw nat.prime_one_factor p prime_p,\n    rw nat.factors_count_pow, linarith,\n    from ne_of_lt (nat.prime.pos prime_p),\n    from nsq_nez.symm,\n\n  have : (2 * m.factors.count p) % 2 = (2 * n.factors.count p + 1) % 2,\n    rw [←eq1, heq, eq2],\n  \n  rw [add_comm, nat.add_mul_mod_self_left, nat.mul_mod_right] at this,\n  norm_num at this,\nend\n\n\nexample {m n k r : ℕ} (nnz : n ≠ 0) (pow_eq : m^k = r * n^k) :\n  ∀ p : ℕ, p.prime → k ∣ r.factors.count p :=\nbegin \n  intros p prime_p,\n  cases r with r,\n  { simp,},\n\n  have npow_nz : n^k ≠ 0,\n    intro npowz, from nnz (pow_eq_zero npowz),\n  \n  have eq1 : (m^k).factors.count p = k * m.factors.count p,\n    apply nat.factors_count_pow,\n\n  have eq2 : (r.succ * n^k).factors.count p = \n      k * n.factors.count p + r.succ.factors.count p,\n    rw [nat.count_factors_mul_of_pos, nat.factors_count_pow, add_comm],\n    show 0 ≠ r.succ, intro, contradiction,\n    show 0 ≠ n^k, from npow_nz.symm,\n\n  have : r.succ.factors.count p = k * m.factors.count p - k * n.factors.count p,\n    rw [←eq1, pow_eq, eq2], simp,\n\n  rw this,\n  apply nat.dvd_sub',\n  repeat {apply dvd_mul_right,},\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/05_Number_Theory/01_Irrational_Roots.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.790861392959514}}
{"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 group_theory.quotient_group -- import Lean's quotient groups\n\n/-\n\n# Quotient groups\n\nmathlib has quotient groups. Here's how they work.\n\n-/\n\n-- let G be a group and let N be a normal subgroup\nvariables (G : Type) [group G] (N : subgroup G) [subgroup.normal N]\n\n-- The underlying type (or set) of the quotient group. Note that `⧸` is `\\quot`, not the slash\n-- character `/` in your keyboard.\n\nexample : Type := G ⧸ N\n\n-- Let's check that the typeclass inference system can find the group structure on the quotient\nexample : group (G ⧸ N) := infer_instance\n\n-- The group homomorphism from `G` to `G ⧸ N`\n\nexample : G →* G ⧸ N := quotient_group.mk' N\n\n-- Remarks:\n-- (1) Why `quotient_group.mk'` and not `quotient_group.mk`? Because the version without the `'`\n-- is just the function, the version with the `'` is the group homomorphism.\n-- (2) Why does `quotient_group.mk' N` want to have `N` as an input but not `G`? It's because\n-- the type of `N` is `subgroup G` so Lean can figure out `G` from `N`: if you like, `N` \"knows\n-- which group it's a subgroup of\".\n\n-- Here is the basic API you need for quotient groups.\n\n-- the map G → G ⧸ N is surjective\nexample : function.surjective (quotient_group.mk' N) := quotient_group.mk'_surjective N \n\n-- Two elements of G have the same image in `G ⧸ N` iff they differ by an element of `N`\nexample (x y : G) : quotient_group.mk' N x = quotient_group.mk' N y ↔ ∃ n ∈ N, x * n = y :=\nquotient_group.mk'_eq_mk' N\n\n-- There is of course much more API, but if you want to get some practice you can\n-- just develop some of it yourself from these two functions.\n\nexample : (quotient_group.mk' N).ker = N :=\nbegin\n  ext a,\n  rw monoid_hom.mem_ker,\n  have h : quotient_group.mk' N 1 = 1 := monoid_hom.map_one _,\n  rw [← h, eq_comm, quotient_group.mk'_eq_mk'],\n  -- now it's just `one_mul` and logic\n  simp,\nend\n\n-- The \"universal property\" of quotients says that if you have a group homomorphism `φ : G →* H`\n-- whose kernel contains `N` then it \"extends\" to a group homomorphism `ψ : G ⧸ N →* H`\n-- such that the composite map `ψ ∘ (quotient_group.mk' N)` equals `φ`. Given `φ`, the `ψ` with\n-- this property is called `quotient_group.lift N φ h`, where `h` is a proof of `∀ x, x ∈ N → φ x = 1`.\n\nvariables (H : Type) [group H] (φ : G →* H) (h : ∀ x, x ∈ N → φ x = 1)\n\nexample : G ⧸ N →* H := quotient_group.lift N φ h\n\n-- The proof that if `x : G` then `(quotient_group.lift N φ h) ((quotient_group.mk' N) x) = φ x`\n-- is, amazingly, `refl`. \n\nexample (x : G) : (quotient_group.lift N φ h) ((quotient_group.mk' N) x) = φ x :=\nbegin\n  refl,\nend\n\n-- Technical remark: this would not be the case if quotient groups were *defined* to \n-- be cosets. In Lean quotient groups are an *opaque definition*. What do I mean by this? \n-- You probably learnt in algebra that if G is a group and H is a normal subgroup then the \n-- quotient G⧸H has elements which are *equal* to cosets of H. In Lean this is not true.\n-- A term of the quotient type G⧸H cannot be taken apart with `cases` because it is not *equal* to\n-- a coset. But the universal property `quotient_group.lift` is all we need; we don't\n-- need to worry about the underlying definition of the quotient.\n\n-- Example. Let's use `quotient_group.lift` to define the following map. Say `φ : G →* H` is a \n-- group hom and we have normal subgroups `N : subgroup G` and `P : subgroup H` such that `φ N ≤ P`.\n-- Then the induced map `G →* H ⧸ P` has `N` in the kernel, so it \"lifts\" to a group hom\n-- `ρ : G ⧸ N →* H ⧸ P` with the property that for all `x : G`, \n-- `ρ (quotient_group.mk' N x) = quotient_group.mk' P (φ x)`. Let's define `ρ` and prove\n-- this equality.\n\nvariables {G H φ N} {P : subgroup H} \nvariable [P.normal]\n\ndef ρ (h : N.map φ ≤ P) : G ⧸ N →* H ⧸ P := \nquotient_group.lift N ((quotient_group.mk' P).comp φ) \nbegin\n  -- we are using `quotient_group.lift` so we need to supply the proof that `(mk' P).comp φ` kills `N`\n  intros g hg,\n  -- the simplifier can help out with this mess:\n  suffices : φ g ∈ P,\n  { simpa, },\n  apply h,\n  use g,\n  exact ⟨hg, rfl⟩,\nend\n\n-- Now let's prove that `ρ ∘ mk' N = mk' P ∘ φ`\n\n/-\n    G ----φ----> H\n    |            |\n    |            |\n   mk'           mk' \n    |            |\n    \\/           \\/\n  G ⧸ N --ρ--> H ⧸ P\n\n-/\nopen quotient_group -- no idea why I didn't do this earlier\n\nexample (h : N.map φ ≤ P) (x : G) : ρ h (mk' N x) = mk' P (φ x) :=\nbegin\n  -- this proof does my head in\n  refl,\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/section07subgroups_and_homomorphisms/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9441768541530197, "lm_q2_score": 0.8376199613065411, "lm_q1q2_score": 0.7908613800421841}}
{"text": "/-\nProofs:\n- very structured, logical\n\nPropositions can formalized as types and proofs are values of those types.\nTo Prove a Proposition : We assert there is a value at play. \n-/\n-- review: we define day to be a type. [Computation type when capital t in type : Type]\ninductive day : Type\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-/\nopen day\ndef l: day := _ -- hole : placeholder, := - turnstyle\ndef d: day := \nbegin\n    --sccripting terms\n    exact tue,  -- exact must give value which is required by goal\nend\n\n/-\nemily_from_cville\n-/\n\ninductive emily_from_cville: Prop -- logical type, not computational\n/-\nConstructors define the values, which we now accept as proofs of the proposition. Proofs in lean are values of *logical* types. \n-/\n| drivers_license\n| passport\n| utility_bill\n\ninductive empty_data_type : Type\ninductive myfalse : Prop \n\nopen emily_from_cville \n\ndef a_proof : emily_from_cville := _ \n-- waiting for a constructor\n\ndef a_proof': emily_from_cville :=\nbegin\n    exact utility_bill, \nend\n\ntheorem a_proof'' : emily_from_cville := \nbegin\n    exact passport\nend\n\ninductive person :Type\n|mari\n|jose\n|jane\n|bill \n\nopen person \n-- proposition with a parameter is a predicate \n\n-- is_from_cville is a predicate \n-- a predicate can be thought of defining a property of the parameter to which it applies. \n\ninductive is_from_cville : person → Prop \n|proof_for:\n    ∀ (p: person)\n        p = mari → is_from_cville mari \n\nopen 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\n#check proof_for mari  -- proof for is a constructor, all that is required is that mari == mari\n\ntheorem mari_is_from_cville : is_from_cville mari :=\nbegin \n    --scripting command\n    apply proof_for _  _,\n    --proof for is a constructor, given any person p that if you can prove p = mari, then you have a proof that mari is from cville. \n    exact mari,\n    exact (eq.refl mari),   \nend  \n\ntheorem jose_is_from_cville : is_from_cville jose :=\nbegin \n    --scripting command\n    apply proof_for _  _,\n    --proof for is a constructor, given any person p that if you can prove p = mari, then you have a proof that mari is from cville. \n    exact jose,\n    exact (eq.refl jose),   \nend\n -- equality is just a predicate \n /-\n eq     a           b\n\n is the same as\n\n a = b\n\n eq     1       3\n 1 = 3 - a false proposition, but a proposition nevertheless\n\n eq 1   1\n 1 = 1\n\n eq is a proof constructor where there is an inductive def of eq which is nat → nat → prop where | refl ℕ → eq n n\n\n equality as a binary relation is reflexive\n\n relation : a set of pairs \n\n Symetry : if a,b is in, then so is b,a \n\n equality is symetric and reflexive \n\n Property of relations:\n\n Binary relation is transitive if a likes b, b likes c then a likes c.\n\n \n -/\n\n def evenb (n : nat) : bool :=\n    n %2 = 0 -- computational predicate yields a bool. Logical predicate yields a proposition. \n\ninductive is_zero : ℕ → Prop \n| zmk : ∀ (n:ℕ ), n = 0 → is_zero n \n\nopen is_zero \n\n\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/Notes/10.31.2019.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768541530198, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7908613800421841}}
{"text": "/-Please allow me to make some statements. This is problem sheet 1\nof an introductory course, none of which belongs to me.-/\n\n/-\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 1 : \"implies\" (`→`)\n\nWe learn about propositions, and implications `P → Q` between them. You can get\nthis arrow by typing `\\to` or `\\r`. Mathematicians usually write the\nimplication arrow as `P ⇒ 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 `⊢` 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\n### The `intro` tactic\n\nMathematical background: `intro h,` says \"To prove `P → Q`, you can assume\nthat `P` is true (call this assumption `h`) and then it\nsuffices to prove `Q`.\"\n\nLean: If your goal is `⊢ P → Q` then `intro h,` will introduce a\nhypothesis `h : P` (i.e. a hypothesis that `P` is true)\nand change the goal to `⊢ Q`. \n\n### The `exact` tactic\n\nMathematics: If you have an assumption `h` that `P` is true,\nand your goal is to prove that `P` is true, then `exact h,`\nwill solve this goal.\n\nLean: If your goal is `⊢ P` and you have a hypothesis `h : P`\nthen `exact h,` will solve it.\n\n### The `apply` tactic\n\nMathematics: `apply` is *arguing backwards*. It is like \"it suffices to...\".\nIf you're trying to prove `Q`, and you know `h : P → Q` is true, then it\nsuffices to prove `P`. So `apply h,` *changes the goal* from `Q` to `P`. The key\npoint to remember is that `apply h` will only work when `h` is an implication,\nand it will only work when the *conclusion* of `h` *matches the goal*.\n\nLean: If your goal is `⊢ Q` and you have `h : P → Q` then `apply h,` will\nchange the goal to `⊢ P`.\n\n-/\n\n/-\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-/ \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 → Q`. \nexample (hQ : Q) : P → Q :=\nbegin\n  -- The goal is of the form `X → Y` so we can use `intro`\n  intro h, -- 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,\nend\n\n-- Assume `P → Q` and `P` is true. Deduce `Q`.\nexample (h : P → Q) (hP : P) : Q :=\nbegin\n  -- our goal is `⊢ 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 → P :=\nbegin\n  intro hP,\n  exact hP,\nend\n\n/-\n\nNote that `→` is not associative: in general `P → (Q → R)` and `(P → Q) → 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 → Q → R` then we'd better know what this means.\nThe convention in Lean is that it means `P → (Q → 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 → P2 → P3 → ... 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 → (Q → P)`.\n\n-/\nexample : P → Q → P :=\nbegin\n  intros hP hQ,\n  exact hP\nend\n\n/-- If we know `P`, and we also know `P → Q`, we can deduce `Q`. \nThis is called \"Modus Ponens\" by logicians. -/\nexample : P → (P → Q) → Q :=\nbegin\n  intros hP hPQ,\n  apply hPQ,\n  exact hP\nend\n\n/-- `→` is transitive. That is, if `P → Q` and `Q → R` are true, then\n  so is `P → R`. -/\nexample : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  intros hPQ hQR hP,\n  apply hQR,\n  apply hPQ hP,\nend\n\n-- If `h : P → Q → R` with goal `⊢ R` and you `apply h`, you'll get\n-- two goals! Note that tactics operate on only the first goal.\nexample : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  intros hPQR hPQ hP,\n  apply hPQR,\n  exact hP,\n  apply hPQ hP,\nend\n\n-- Now they get a little harder. You can skip these if\n-- you feel like you know what you're doing.\n\nvariables (S T : Prop)\n\nexample : (P → R) → (S → Q) → (R → T) → (Q → R) → S → T :=\nbegin\n  intros hPR hSQ hRT hQR hS,\n  exact hRT (hQR (hSQ hS)),\nend\n\nexample : (P → Q) → ((P → Q) → P) → Q :=\nbegin\n  intros hPQ hPQP,\n  have hP: P, by exact hPQP hPQ,\n  exact hPQ hP,\nend\n\nexample : ((P → Q) → R) → ((Q → R) → P) → ((R → P) → Q) → P :=\nbegin\n  intros hPQR hQRP hRPQ,\n  apply hQRP,\n  intro hQ,\n  have hPQ : P → Q, {intro hP, exact hQ,},\n  exact hPQR hPQ,\nend\n\nexample : ((Q → P) → P) → (Q → R) → (R → P) → P :=\nbegin\n  intros hQPP hQR hRP,\n  apply hQPP,\n  intro hQ, \n  exact hRP (hQR hQ),\nend\n\nexample : (((P → Q) → Q) → Q) → (P → Q) :=\nbegin\n  intros hPQQQ hP,\n  apply hPQQQ,\n  intro hPQ,\n  exact hPQ hP,\nend\n\nexample :\n  (((P → Q → Q) → ((P → Q) → Q)) → R) →\n  ((((P → P) → Q) → (P → P → Q)) → R) →\n  (((P → P → Q) → ((P → P) → Q)) → R) → R :=\nbegin\n  intros h₁ h₂ h₃,\n  apply h₂,\n  intros hPPQ hPQ,\n  have hPP: P → P, {intro hP, exact hP,},\n  have hQ: Q, exact hPPQ hPP,\n  intro hP,\n  exact hQ,\nend", "meta": {"author": "Siesta233", "repo": "LeanPractice", "sha": "3795eeb8763edacf2c74b9c8925f642d6cc56daf", "save_path": "github-repos/lean/Siesta233-LeanPractice", "path": "github-repos/lean/Siesta233-LeanPractice/LeanPractice-3795eeb8763edacf2c74b9c8925f642d6cc56daf/src/PS1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7907951539409159}}
{"text": "import tactic\n\nopen_locale classical -- def of max a b is \"if a <= b then b else a\"\nnoncomputable theory -- same reason\n\n-- A linear order is a reflexive, transitive, antisymmetric and total relation `≤`\n\nvariables {X : Type} [linear_order X] {a b c : X}\n\n-- Note in the below that sometimes we have to supply the variable names and other times not.\n-- I am scared after my NNG experience to break with tradition and start\n-- changing mathlib conventions. They are there for a reason (you don't need\n-- them when there are implications involved, because you can guess the\n-- variables from the hypotheses)\n\n-- I think that the user would be happy to accept all of these as axioms,\n-- even though strictly speaking one could define a < b to be a ≤ b ∧ a ≠ b\n-- and then prove the last two. \n\nexample : a ≤ a := le_refl a\n\nexample : a ≤ b → b ≤ c → a ≤ c := le_trans\n\nexample : a ≤ b → b ≤ a → a = b := le_antisymm\n\n-- I think this is more useful in practice than trichotomy\nexample : a ≤ b ∨ b ≤ a := le_total a b\n\nexample : a < b ↔ a ≤ b ∧ a ≠ b := lt_iff_le_and_ne\n\nexample : a ≤ b → b < c → a < c := lt_of_le_of_lt\n\nexample : a < b → b ≤ c → a < c := lt_of_lt_of_le\n\n-- max is already defined so we work in a namespace\n\nnamespace test\n\n-- I think this definition might be hard to work with\ndef max (a b : X) := if a ≤ b then b else a\n\n-- need if_pos to do this one\ntheorem max_eq_right (hab : a ≤ b) : max a b = b :=\nbegin\n  unfold max,\n  rw if_pos hab,  \nend\n\n-- need if_neg to do this one\ntheorem max_eq_left (hba : b ≤ a) : max a b = a :=\nbegin\n  by_cases hab : a ≤ b,\n  { rw max_eq_right hab,\n    exact le_antisymm hba hab,\n  },\n  { unfold max,\n    rw if_neg hab,\n  }\nend\n\n-- but now things work really nicely. Proposal: tell them that\n-- max_eq_left and max_eq_right are axioms of max, and don't\n-- tell them the definition. Note that max_eq_left and max_eq_right\n-- together are enough to deduce that max a b is what it is,\n-- because of le_antisymm\n\n-- level 1\ntheorem max_choice (a b : X) : max a b = a ∨ max a b = b :=\nbegin\n  cases le_total a b with hab hba,\n  { right,\n    exact max_eq_right hab\n  },\n  { left,\n    exact max_eq_left hba\n  }\nend\n\n-- level 2\ntheorem max_comm (a b : X) : max a b = max b a :=\nbegin\n  cases le_total a b with hab hba,\n  { rw max_eq_right hab,\n    rw max_eq_left hab,\n  },\n  { rw max_eq_left hba,\n    rw max_eq_right hba\n  }  \nend\n\n-- level 3\ntheorem le_max_left (a b : X) : a ≤ max a b :=\nbegin\n  cases le_total a b with hab hba,\n  { rw max_eq_right hab,\n    assumption\n  },\n  { rw max_eq_left hba,\n    -- Lean closes a ≤ a automatically because ≤ is reflexive\n  }  \nend\n\n-- level 4\ntheorem le_max_right (a b : X) : b ≤ max a b :=\nbegin\n  rw max_comm,\n  apply le_max_left\nend\n\n-- this comes out nicely\n-- level 5\ntheorem max_le (hac : a ≤ c) (hbc : b ≤ c) : max a b ≤ c :=\nbegin\n  cases max_choice a b with ha hb,\n  { rw ha,\n    assumption\n  },\n  { rw hb,\n    assumption\n  }\nend\n\n-- and this, if we can teach `apply le_trans _ habc`\n-- level 6\ntheorem max_le_iff : a ≤ c ∧ b ≤ c ↔ max a b ≤ c :=\nbegin\n  split,\n  { intro h,\n    cases h with hac hbc,\n    exact max_le hac hbc\n  },\n  { intro habc,\n    split,\n    { apply le_trans _ habc,\n      apply le_max_left},\n    { apply le_trans _ habc,\n      apply le_max_right\n    }\n  },\nend\n\n\n-- so does this\n-- level 7\ntheorem max_lt (hac : a < c) (hbc : b < c) : max a b < c :=\nbegin\n  cases max_choice a b with ha hb,\n  { rw ha,\n    assumption\n  },\n  { rw hb,\n    assumption\n  }\nend\n\n\n-- level 8\ntheorem max_lt_iff : a < c ∧ b < c ↔ max a b < c :=\nbegin\n  split,\n  { intro h,\n    cases h with hac hbc,\n    exact max_lt hac hbc\n  },\n  { intro habc,\n    split,\n    { apply lt_of_le_of_lt _ habc,\n      apply le_max_left},\n    { apply lt_of_le_of_lt _ habc,\n      apply le_max_right\n    }\n  },\nend\n\n-- level 9\ntheorem le_max_iff : a ≤ max b c ↔ a ≤ b ∨ 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 le_trans hab,\n      apply le_max_left},\n    { apply le_trans hac,\n      apply le_max_right},\n  }\nend\n\n-- same as previous one\ntheorem lt_max_iff : a < max b c ↔ a < b ∨ 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\n-- I think that's a good API for max. Let's test this hypothesis\n-- by seeing how easy it is to make a good API for abs. \n\nend test", "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/max_API_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7907951524289708}}
{"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 8631e2d5ea77f6c13054d9151d82b83069680cb1\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.Parity\nimport Mathlib.Data.List.Chain\n\n/-!\n# List of booleans\n\nIn this file we prove lemmas about the number of `false`s and `true`s in a list of booleans. First\nwe prove that the number of `false`s plus the number of `true` equals the length of the list. Then\nwe prove that in a list with alternating `true`s and `false`s, the number of `true`s differs from\nthe number of `false`s by at most one. We provide several versions of these statements.\n-/\n\n\nnamespace List\n\n@[simp]\ntheorem count_not_add_count (l : List Bool) (b : Bool) : count (!b) l + count b l = length l := by\n  -- Porting note: Proof re-written\n  -- Old proof: simp only [length_eq_countp_add_countp (Eq (!b)), Bool.not_not_eq, count]\n  simp only [length_eq_countp_add_countp (· == !b), count, add_right_inj]\n  suffices : (fun x => x == b) = (fun a => decide ¬(a == !b) = true); rw [this]\n  ext x; cases x <;> cases b <;> rfl\n#align list.count_bnot_add_count List.count_not_add_count\n\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_not_add_count]\n#align list.count_add_count_bnot List.count_add_count_not\n\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@[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\ntheorem Chain.count_not :\n    ∀ {b : Bool} {l : List Bool}, Chain (· ≠ ·) b l → count (!b) l = count b l + length l % 2\n  | b, [], _h => rfl\n  | b, x :: l, h => 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.not_ne_self,\n      Chain.count_not (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\nnamespace Chain'\n\nvariable {l : List Bool}\n\ntheorem count_not_eq_count (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) (b : Bool) :\n    count (!b) l = count b l := by\n  cases' l with x l\n  · 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    -- Porting note: old proof is\n    -- cases b <;> cases x <;> try exact this;\n    cases b <;> cases x <;>\n    revert this <;> simp only [Bool.not_false, Bool.not_true] <;> intro this <;>\n    (try exact this) <;> exact this.symm\n  rw [count_cons_of_ne x.not_ne_self, hl.count_not, h2, count_cons_self]\n#align list.chain'.count_bnot_eq_count List.Chain'.count_not_eq_count\n\ntheorem count_false_eq_count_true (hl : Chain' (· ≠ ·) 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\ntheorem count_not_le_count_add_one (hl : Chain' (· ≠ ·) l) (b : Bool) :\n    count (!b) l ≤ count b l + 1 := by\n  cases' l with x l\n  · exact zero_le _\n  obtain rfl | rfl : b = x ∨ b = !x := by simp only [Bool.eq_not_iff, em]\n  · rw [count_cons_of_ne b.not_ne_self, count_cons_self, hl.count_not, add_assoc]\n    exact add_le_add_left (Nat.mod_lt _ two_pos).le _\n  · rw [Bool.not_not, count_cons_self, count_cons_of_ne x.not_ne_self, hl.count_not]\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\ntheorem count_false_le_count_true_add_one (hl : Chain' (· ≠ ·) l) :\n    count false l ≤ 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\ntheorem count_true_le_count_false_add_one (hl : Chain' (· ≠ ·) l) :\n    count true l ≤ 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\ntheorem two_mul_count_bool_of_even (hl : Chain' (· ≠ ·) l) (h2 : Even (length l)) (b : Bool) :\n    2 * count b l = length l := by\n  rw [← count_not_add_count l b, hl.count_not_eq_count h2, two_mul]\n#align list.chain'.two_mul_count_bool_of_even List.Chain'.two_mul_count_bool_of_even\n\ntheorem two_mul_count_bool_eq_ite (hl : Chain' (· ≠ ·) l) (b : Bool) :\n    2 * count b l =\n      if Even (length l) then length l else\n      if Option.some b == l.head? then length l + 1 else length l - 1 := by\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\n    · 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' (· ≠ ·) := hl.tail\n    rw [hl.two_mul_count_bool_of_even h2]\n    cases b <;> cases x <;> split_ifs <;> simp <;> contradiction\n#align list.chain'.two_mul_count_bool_eq_ite List.Chain'.two_mul_count_bool_eq_ite\n\ntheorem length_sub_one_le_two_mul_count_bool (hl : Chain' (· ≠ ·) l) (b : Bool) :\n    length l - 1 ≤ 2 * count b l := 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\ntheorem length_div_two_le_count_bool (hl : Chain' (· ≠ ·) l) (b : Bool) :\n    length l / 2 ≤ count b l := by\n  rw [Nat.div_le_iff_le_mul_add_pred two_pos, ← 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\ntheorem two_mul_count_bool_le_length_add_one (hl : Chain' (· ≠ ·) l) (b : Bool) :\n    2 * count b l ≤ length l + 1 := 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\nend Chain'\n\nend List\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/Bool/Count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7907951474008887}}
{"text": "import tactic.linarith\nimport .src_05_if_and_only_if\n\nvariables p q r : Prop \n\nnamespace mth1001\n\nsection rewriting \n/-\nStatements of the form `p ↔ q` play a cruicial role in logic. Given `h : p ↔ q`, we can\nreplace `p`, wherever it appears, with `q`. This is called rewriting.\n-/\n\n\n/-\nHere, the `rewrite` tactic (abbreviated to `rw`) is invoked with `h : (p ∧ q) ↔ r`. This\ncases Lean to replace `p ∧ q`, wherever it appears in the goal, with `r`.\n\nThe goal is reduced to `r ∧ q ∧ r ↔ r ∧ q ∧ r`, which Lean immediately closes.\n\nNote that a one-line tactic proof can be written using `by` rather than enclosing the proof in\na `begin` … `end` block.\n-/\nexample (h : (p ∧ q) ↔ r) : (p ∧ q) ∧ (q ∧ (p ∧ q)) ↔ r ∧ (q ∧ r) :=\nby rw h\n\n/-\nBelow, we use `and_iff_and` (the commutativity of `∧`) together with `and_assoc`\n(the associativity of `∧`). Note that `and_iff_and r (q ∧ r)` is the result\n`r ∧ (q ∧ r) ↔ (q ∧ r) ∧ r`. \n-/\nexample (h : (p ∧ q) ↔ r) : (p ∧ q) ∧ (q ∧ (p ∧ q)) ↔ q ∧ (r ∧ r) :=\nbegin \n  rw h,\n  rw and_iff_and r (q ∧ r),\n  rw and_assoc q r r,\nend\n\n/-\nThe `rw` tactic can often infer arguments to theorems. In the example above, we can omit\nthe arguments, leading to the simplified proof below.\n-/\nexample (h : (p ∧ q) ↔ r) : (p ∧ q) ∧ (q ∧ (p ∧ q)) ↔ q ∧ (r ∧ r) :=\nbegin \n  rw h,\n  rw and_iff_and,\n  rw and_assoc,\nend\n\n-- Several applications of `rw` can be written on one line.\nexample (h : (p ∧ q) ↔ r) : (p ∧ q) ∧ (q ∧ (p ∧ q)) ↔ q ∧ (r ∧ r) :=\nbegin \n  rw [h, and_iff_and, and_assoc],\nend\n\n#check and_assoc \n\n/-\nWe've seen how `rw` can rewrite a goal given a double implication. It can also rewrite a goal\ngiven an equation.\n\nHere, `ℤ` represents the type of integers and is written `\\Z`.\n-/\nexample (a b : ℤ) (h : a = b) : a + 2 = b + 2 :=\nbegin \n  rw h,\nend \n\n/-\nGiven `h : a = b` or `h : a ↔ b`, we've seen that `rw h` replaces every occurrence of `a` in the\ngoal with `b`. We can ask for rewriting in the other direction by issuing `rw ←h`, where `←` is\nwritten `\\l`. This replaces every occurrence of `b` in the goal with `a`.\n-/\n\n/-\nHere, we use `rw` with `←`. The `linarith` tactic can solve linear equations and inequalities.\n\nIn fact, `linarith` is clever enough to perform the rewriting *without* needing you to specify\nit explicitly, so we could omit the line `rw ←h` below.\n-/\nexample (a b : ℤ) (h : 3 + a = b) : b + 3 = a + 6 :=\nbegin \n  rw ←h,\n  linarith,\nend\n\n\n-- Exercise 036:\n-- Use `rw` with `←` and the theorems we've proved to solve the following.\nexample : r ∧ (p ∧ q) ↔ (p ∧ r) ∧ q :=\nbegin\n  sorry  \nend \n\nend rewriting\n\n\nsection implicit_arguments\n\n-- Exercise 037:\n/-\nOften, it's easier to write a theorem in a form that doesn't require arguments to be specified when\nthe theorem is applied. We do this by enclosing implicit arguments in braces `{` and `}`.\n-/\ntheorem imp_trans {a b c : Prop} : (a → b) → (b → c) → (a → c) :=\nbegin \n  sorry  \nend\n\n-- Note how the proof of the following complicated result is simply `imp_trans`.\nexample : (p ∧ q → r) → (r → r ∧ q) → (p ∧ q → r ∧ q) :=\nimp_trans \n\n-- In tactic-form, the proof is `exact imp_trans`.\nexample : (p ∧ q → r) → (r → r ∧ q) → (p ∧ q → r ∧ q) :=\nbegin \n  exact imp_trans \nend\n\n/-\nAs a practical example, we'll use the following result, `add_left_cancel`, which has type\n  `∀ {a b c : ℤ}, a + b = a + c → b = c`.\n-/\nlemma add_left_cancel : ∀ {a b c : ℤ}, a + b = a + c → b = c :=\nbegin\n  intros a b c,\n  exact (add_right_inj a).mp\nend\n\n/-\nWe use this result below.\n-/\nexample (x y : ℤ) (h : 2 + x = 2 + y) : x = y :=\nadd_left_cancel h\n\n-- Exercise 038:\n-- Check what the theorem `int.add_comm` asserts. You can prove the following use only this,\n-- `int.add_left_cancel`, `have`, `exact`, `rw`, and `apply`.\nexample (s t u a b : ℤ) (h₁ : s + u = t + u) (h₂ : s + a = t + b) : a = b :=\nbegin\n  have h₃ : u + s =  u + t,\n  { sorry, }, \n  sorry    \nend \n\nend implicit_arguments\n\n/-\nSUMMARY:\n\n* Using the `rw` tactic to rewrite a goal using an equation or iff.\n* Using `←` to use an equation or iff in the opposite direction.\n\n* Implicit arguments to theorems using `{ … }`\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_06_rewriting_implicit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.790734441521632}}
{"text": "--- Implement my own mynat from the built-in natural numbers\nopen nat\n\n-- add zero is used in the game\ntheorem add_zero (m : nat) : m + 0 = m := rfl\ntheorem one_eq_succ_zero : 1 = succ 0 := rfl\nlemma mul_zero (m : ℕ) : m * 0 = 0 := rfl\n\n-- tutorial world\nlemma example1 (x y z : ℕ) : x * y + z = x * y + z :=\nbegin\nrefl,\nend\n\nlemma example2 (x y : ℕ) (h : y = x + 7) : 2 * y = 2 * (x + 7) :=\nbegin\nrw h,\nend\n\nlemma example3 (a b : ℕ) (h : succ a = b) : succ(succ(a)) = succ(b) :=\nbegin\nrw h,\nend\n\n-- addition world\nlemma add_succ_zero (a : ℕ) : a + succ(0) = succ(a) :=\nbegin\nrw add_succ,\nrw add_zero,\nend\n\nlemma zero_add (n : ℕ) : 0 + n = n :=\nbegin\ninduction n with h hd,\nrw add_zero,\nrw add_succ,\nrw hd,\nend\n\nlemma add_assoc (a b c : ℕ) : (a + b) + c = a + (b + c) :=\nbegin\ninduction c with h hd,\nrepeat {rw add_zero},\nrepeat {rw add_succ},\nrw hd,\nend\n\nlemma succ_add' (a b : ℕ) : succ a + b = succ (a + b) :=\nbegin\ninduction b with h hd,\nrepeat {rw add_zero},\nrw add_succ,\nrw hd,\nrw add_succ,\nend\n\nlemma add_comm (a b : ℕ) : a + b = b + a :=\nbegin\ninduction b with h hd,\nrw add_zero,\nrw zero_add,\nrw add_succ,\nrw hd,\nrw succ_add',\nend\n\ntheorem succ_eq_add_one' (n : ℕ) : succ n = n + 1 :=\nbegin\nrw one_eq_succ_zero,\nend\n\nlemma add_right_comm (a b c : ℕ) : a + b + c = a + c + b :=\nbegin\ninduction a with h hd,\nrepeat {rw zero_add},\nrw add_comm,\nrepeat {rw succ_add},\nrw hd,\nrepeat {rw succ_add},\nend\n\n-- function world\nexample (P Q : Type) (p : P) (h : P → Q) : Q :=\nbegin\nexact h(p),\nend\n\nexample : ℕ → ℕ :=\nbegin\nintro n,\nexact n,\nend\n\nexample (P Q R S T U: Type)\n(p : P)\n(h : P → Q)\n(i : Q → R)\n(j : Q → T)\n(k : S → T)\n(l : T → U)\n: U :=\nbegin\nhave q := h(p),\nhave t : T := j(q),\nhave u : U := l(t),\nexact u,\nend\n\nexample (P Q R S T U: Type)\n(p : P)\n(h : P → Q)\n(i : Q → R)\n(j : Q → T)\n(k : S → T)\n(l : T → U)\n: U :=\nbegin\nhave q := h(p),\nhave t : T := j(q),\nhave u : U := l(t),\nexact u,\nend\n\nexample (P Q : Type) : P → (Q → P) :=\nbegin\nintros p q,\nexact p,\nend\n\nexample (P Q R : Type) : (P → (Q → R)) → ((P → Q) → (P → R)) :=\nbegin\nintros p q r,\nexact p(r)(q(r)),\nend\n\nexample (P Q F : Type) : (P → Q) → ((Q → F) → (P → F)) :=\nbegin\nintros p q r,\nexact q(p(r)),\nend\n\nexample (P Q : Type) : (P → Q) → ((Q → empty) → (P → empty)) :=\nbegin\nintros p q r,\nexact q(p(r)),\nend\n\nexample (A B C D E F G H I J K L : Type)\n(f1 : A → B) (f2 : B → E) (f3 : E → D) (f4 : D → A) (f5 : E → F)\n(f6 : F → C) (f7 : B → C) (f8 : F → G) (f9 : G → J) (f10 : I → J)\n(f11 : J → I) (f12 : I → H) (f13 : E → H) (f14 : H → K) (f15 : I → L)\n : A → L :=\nbegin\nintro f,\napply f15,\napply f11,\napply f9,\napply f8,\napply f5,\napply f2,\napply f1,\nexact f,\nend\n\n-- multiplication world\nlemma zero_mul (m : ℕ) : 0 * m = 0 :=\nbegin\ninduction m with h hd,\nrw mul_zero,\nrw mul_succ,\nrw add_zero,\nrw hd,\nend\n\nlemma mul_one (m : ℕ) : m * 1 = m :=\nbegin\nrw one_eq_succ_zero,\nrw mul_succ,\nrw mul_zero,\nrw zero_add,\nend\n\nlemma one_mul (m : ℕ) : 1 * m = m :=\nbegin\ninduction m with h hd,\nrw mul_zero,\nrw mul_succ,\nrw hd,\nend\n\nlemma mul_add (t a b : ℕ) : t * (a + b) = t * a + t * b :=\nbegin\ninduction b with h hd,\ninduction a with j jd,\ninduction t with k kd,\nrw mul_zero,\nrw add_zero,\nrw mul_zero,\nrw add_zero,\nrw mul_zero,\nrw add_zero,\nrw add_succ,\nrw mul_succ,\nrw hd,\nrw mul_succ,\nrw add_assoc,\nend\n\nlemma mul_assoc (a b c : ℕ) : (a * b) * c = a * (b * c) :=\nbegin\ninduction c with h hd,\nrw mul_zero,\nrw mul_zero,\nrw mul_zero,\nrw mul_succ,\nrw mul_succ,\nrw hd,\nrw mul_add,\nend\n\nlemma succ_mul' (a b : ℕ) : succ a * b = a * b + b :=\nbegin\ninduction b with h hd,\nsimp,\nrefl,\nrw mul_succ,\nrw hd,\nrw mul_succ,\nrw succ_eq_add_one',\nrw succ_eq_add_one',\nsimp,\nend\n\nlemma add_mul (a b t : ℕ) : (a + b) * t = a * t + b * t :=\nbegin\ninduction t with h hd,\nrw mul_zero,\nrw mul_zero,\nrefl,\nrw mul_succ,\nrw hd,\nrw succ_eq_add_one,\nrw mul_add,\nrw mul_add,\nrw mul_one,\nrw mul_one,\nsimp,\nend\n\nlemma mul_comm (a b : ℕ) : a * b = b * a :=\nbegin\ninduction a with h hd,\nrw mul_zero,\nrw zero_mul,\nrw succ_mul',\nrw hd,\nrw mul_succ,\nend\n\nlemma mul_left_comm (a b c : ℕ) : a * (b * c) = b * (a * c) :=\nbegin\ninduction c with h hd,\nrw mul_zero,\nrw mul_zero,\nrw mul_zero,\nrw mul_succ,\nrw mul_add,\nrw hd,\nrw succ_eq_add_one,\nrw mul_add,\nrw mul_add,\nrw mul_one,\nrw mul_comm,\nrefl,\nend\n", "meta": {"author": "EthanJamesLew", "repo": "natural-numbers-lean", "sha": "ca39a6a5372096c8766fb3cdd41539119d849d73", "save_path": "github-repos/lean/EthanJamesLew-natural-numbers-lean", "path": "github-repos/lean/EthanJamesLew-natural-numbers-lean/natural-numbers-lean-ca39a6a5372096c8766fb3cdd41539119d849d73/games.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8740772433654401, "lm_q1q2_score": 0.7907344414360985}}
{"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# Natural number logarithm\n\nThis file defines `log b n`, the logarithm of `n` with base `b`, to be the largest `k` such that\n`b ^ k ≤ n`.\n\n-/\nnamespace nat\n\n/-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : ℕ`\nsuch that `b^k ≤ n`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def log (b : ℕ) : ℕ → ℕ\n| n :=\n  if h : b ≤ n ∧ 1 < b then\n    have n / b < n,\n      from div_lt_self\n        (nat.lt_of_lt_of_le (lt_trans zero_lt_one h.2) h.1) h.2,\n    log (n / b) + 1\n  else 0\n\nlemma log_eq_zero {b n : ℕ} (hnb : n < b ∨ b ≤ 1) : log b n = 0 :=\nbegin\n  rw [or_iff_not_and_not, not_lt, not_le] at hnb,\n  rw [log, ←ite_not, if_pos hnb],\nend\n\nlemma log_eq_zero_of_lt {b n : ℕ} (hn : n < b) : log b n = 0 :=\nlog_eq_zero $ or.inl hn\n\nlemma log_eq_zero_of_le {b n : ℕ} (hb : b ≤ 1) : log b n = 0 :=\nlog_eq_zero $ or.inr hb\n\nlemma log_zero_eq_zero {b : ℕ} : log b 0 = 0 :=\nby { rw log, cases b; refl }\n\nlemma log_one_eq_zero {b : ℕ} : log b 1 = 0 :=\nif h : b ≤ 1 then\n  log_eq_zero_of_le h\nelse\n  log_eq_zero_of_lt (not_le.mp h)\n\nlemma log_b_zero_eq_zero {n : ℕ} : log 0 n = 0 :=\nlog_eq_zero_of_le zero_le_one\n\nlemma log_b_one_eq_zero {n : ℕ} : log 1 n = 0 :=\nlog_eq_zero_of_le rfl.ge\n\nlemma pow_le_iff_le_log (x y : ℕ) {b} (hb : 1 < b) (hy : 1 ≤ y) :\n  b^x ≤ y ↔ x ≤ log b y :=\nbegin\n  induction y using nat.strong_induction_on with y ih\n    generalizing x,\n  rw [log], split_ifs,\n  { have h'' : 0 < b := lt_of_le_of_lt (zero_le _) hb,\n    cases h with h₀ h₁,\n    rw [← nat.sub_le_right_iff_le_add,← ih (y / b),\n          le_div_iff_mul_le _ _ h'',← pow_succ'],\n    { cases x; simp [h₀,hy] },\n    { apply div_lt_self; assumption },\n    { rwa [le_div_iff_mul_le _ _ h'',one_mul], } },\n  { replace h := lt_of_not_ge (not_and'.1 h hb),\n    split; intros h',\n    { have := lt_of_le_of_lt h' h,\n      apply le_of_succ_le_succ,\n      change x < 1, rw [← pow_lt_iff_lt_right hb,pow_one],\n      exact this },\n    { replace h' := le_antisymm h' (zero_le _),\n      rw [h',pow_zero], exact hy} },\nend\n\nlemma log_pow (b x : ℕ) (hb : 1 < b) : log b (b ^ x) = x :=\neq_of_forall_le_iff $ λ z,\nby { rwa [← pow_le_iff_le_log _ _ hb,pow_le_iff_le_right],\n     rw ← pow_zero b, apply pow_le_pow_of_le_right,\n     apply lt_of_le_of_lt (zero_le _) hb, apply zero_le }\n\nlemma pow_succ_log_gt_self (b x : ℕ) (hb : 1 < b) (hy : 1 ≤ x) :\n  x < b ^ succ (log b x) :=\nbegin\n  apply lt_of_not_ge,\n  rw [(≥),pow_le_iff_le_log _ _ hb hy],\n  apply not_le_of_lt, apply lt_succ_self,\nend\n\nlemma pow_log_le_self (b x : ℕ) (hb : 1 < b) (hx : 1 ≤ x) : b ^ log b x ≤ x :=\nby rw [pow_le_iff_le_log _ _ hb hx]\n\nlemma log_le_log_of_le {b n m : ℕ} (h : n ≤ m) : log b n ≤ log b m :=\nbegin\n  cases le_or_lt b 1 with hb hb,\n  { rw log_eq_zero_of_le hb, exact zero_le _ },\n  { cases eq_zero_or_pos n with hn hn,\n    { rw [hn, log_zero_eq_zero], exact zero_le _ },\n    { rw ←pow_le_iff_le_log _ _ hb (lt_of_lt_of_le hn h),\n      exact (pow_log_le_self b n hb hn).trans h } }\nend\n\nlemma log_le_log_succ {b n : ℕ} : log b n ≤ log b n.succ :=\nlog_le_log_of_le $ le_succ n\n\nlemma log_mono {b : ℕ} : monotone (λ n : ℕ, log b n) :=\nmonotone_of_monotone_nat $ λ n, log_le_log_succ\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/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.7907344362644254}}
{"text": "import tactic.interactive tactic.ring\n\ninductive is_even : ℕ → Prop\n| zero : is_even 0\n| step {n} : is_even n → is_even (n + 2)\n\nexample : is_even 4 :=\nbegin\nrepeat { apply is_even.step },\napply is_even.zero,\nend\n\nexample : ¬ is_even 5 :=\nbegin\nintro even_five,\ncases even_five with _ even_three,\ncases even_three with _ even_one,\ncases even_one,\nend\n\nlemma even_if_double {n} : is_even (2*n) :=\nbegin\ninduction n with d hd,\n{ exact is_even.zero },\n{ show is_even (2 * (d + 1)),\n  rw mul_add,\n  apply is_even.step,\n  assumption,\n },\nend\n\nlemma double_if_even {n} : is_even n → ∃ m, n = 2*m :=\nbegin\nintro h, induction h with d Hd ih,\n{ use 0,\n  refl\n},\n{ cases ih with n Hn,\n  use (n + 1),\n  rw Hn,\n  refl,\n }\nend\n\nlemma even_iff_double {n} : is_even n ↔ ∃ m, n = 2*m :=\nbegin\nsplit, apply double_if_even,\nintro h, cases h with d Hd, rw Hd, \n  apply even_if_double\nend\n\ninductive is_odd : ℕ → Prop\n| one : is_odd 1\n| step {n} : is_odd n → is_odd (n + 2)\n\nlemma odd_iff_double_add_one {n} : is_odd n ↔ ∃ m, n = 2*m + 1 :=\nsorry\n\nlemma even_of_not_odd : ∀ n, \n¬ is_odd n → is_even n\n| 0 h := is_even.zero\n| 1 h := begin exfalso, apply h, constructor end\n| (n+2) h :=\n  have ih : _, from even_of_not_odd n,\n  begin\n  constructor,\n  apply ih,\n  intro hn,\n  apply h,\n  constructor, assumption,\n  end\n\n#print even_of_not_odd\n\nlemma not_odd_of_even : ∀ n, is_even n → ¬ is_odd n :=\nbegin\nintros n h,\ninduction h with m m hm,\n{intro h, cases h},\n{intro h, apply hm, cases h, assumption},\nend\n\nlemma even_iff_not_odd : ∀ n, is_even n ↔ ¬ is_odd n :=\nbegin\nintro n, split, apply not_odd_of_even, apply even_of_not_odd\nend\n\nlemma odd_square (n : ℕ) : is_odd n → is_odd (n*n) :=\nbegin\nsimp [odd_iff_double_add_one],\nintro m,\nintros  h,\nuse 2*m + 2*m*m, subst h, ring,\nend\n\nlemma even_square (n : ℕ) : is_even (n*n) → is_even n :=\nbegin\nconv in (is_even (n*n)) { simp [even_iff_not_odd] },\nsimp [even_iff_not_odd],\nintros h1 h2, apply h1,\napply odd_square, assumption\nend\n\n--set_option pp.all true\n#check (7 : ℤ)\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/experiments/evenodd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.7907344303722696}}
{"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ébastien Gouëzel, Rémy Degenne\n\n! This file was ported from Lean 3 source module analysis.mean_inequalities\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 Mathbin.Analysis.Convex.SpecificFunctions\nimport Mathbin.Data.Real.ConjugateExponents\n\n/-!\n# Mean value inequalities\n\nIn this file we prove several inequalities for finite sums, including AM-GM inequality,\nYoung's inequality, Hölder inequality, and Minkowski inequality. Versions for integrals of some of\nthese inequalities are available in `measure_theory.mean_inequalities`.\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} ≤ \\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### 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 ≤ \\frac{a^p}{p} + \\frac{b^q}{q}.\n$$\n\nThis inequality is a special case of the AM-GM inequality. It is then used to prove Hölder's\ninequality (see below).\n\n### Hölder'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 ≤ \\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 `ℝ`, `ℝ≥0` and `ℝ≥0∞`.\n\nThere are at least two short proofs of this inequality. In our proof we prenormalize both vectors,\nthen apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this\ninequality from the generalized mean inequality for well-chosen vectors and weights.\n\n### Minkowski's inequality\n\nThe inequality says that for `p ≥ 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`, `ℝ≥0` and `ℝ≥0∞`.\n\nWe deduce this inequality from Hölder's inequality. Namely, Hölder 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\n## TODO\n\n- each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them\n  is to define `strict_convex_on` functions.\n- generalized mean inequality with any `p ≤ q`, including negative numbers;\n- prove that the power mean tends to the geometric mean as the exponent tends to zero.\n\n-/\n\n\nuniverse u v\n\nopen Finset\n\nopen Classical BigOperators NNReal ENNReal\n\nnoncomputable section\n\nvariable {ι : Type u} (s : Finset ι)\n\nsection GeomMeanLeArithMean\n\n/-! ### AM-GM inequality -/\n\n\nnamespace Real\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 (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)\n    (hw' : (∑ i in s, w i) = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :\n    (∏ i in s, z i ^ w i) ≤ ∑ i in s, w i * z i :=\n  by\n  -- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative.\n  by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0\n  · rcases A with ⟨i, his, hzi, hwi⟩\n    rw [prod_eq_zero his]\n    · exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj)\n    · rw [hzi]\n      exact zero_rpow hwi\n  -- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality\n  -- for `exp` and numbers `log (z i)` with weights `w i`.\n  · simp only [not_exists, not_and, Ne.def, Classical.not_not] at A\n    have := convex_on_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i)\n    simp only [exp_sum, (· ∘ ·), smul_eq_mul, mul_comm (w _) (log _)] at this\n    convert this using 1 <;> [apply prod_congr rfl, apply sum_congr rfl] <;> intro i hi\n    · cases' eq_or_lt_of_le (hz i hi) with hz hz\n      · simp [A i hi hz.symm]\n      · exact rpow_def_of_pos hz _\n    · cases' eq_or_lt_of_le (hz i hi) with hz hz\n      · simp [A i hi hz.symm]\n      · rw [exp_log hz]\n#align real.geom_mean_le_arith_mean_weighted Real.geom_mean_le_arith_mean_weighted\n\ntheorem geom_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)\n    (hw' : (∑ i in s, w i) = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) :\n    (∏ i in s, z i ^ w i) = x :=\n  calc\n    (∏ i in s, z i ^ w i) = ∏ i in s, x ^ w i :=\n      by\n      refine' prod_congr rfl fun i hi => _\n      cases' eq_or_ne (w i) 0 with h₀ h₀\n      · rw [h₀, rpow_zero, rpow_zero]\n      · rw [hx i hi h₀]\n    _ = x := by\n      rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one]\n      have : (∑ i in s, w i) ≠ 0 := by\n        rw [hw']\n        exact one_ne_zero\n      obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this\n      rw [← hx i his hi]\n      exact hz i his\n    \n#align real.geom_mean_weighted_of_constant Real.geom_mean_weighted_of_constant\n\ntheorem arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw' : (∑ i in s, w i) = 1)\n    (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : (∑ i in s, w i * z i) = x :=\n  calc\n    (∑ i in s, w i * z i) = ∑ i in s, w i * x :=\n      by\n      refine' sum_congr rfl fun i hi => _\n      cases' eq_or_ne (w i) 0 with hwi hwi\n      · rw [hwi, MulZeroClass.zero_mul, MulZeroClass.zero_mul]\n      · rw [hx i hi hwi]\n    _ = x := by rw [← sum_mul, hw', one_mul]\n    \n#align real.arith_mean_weighted_of_constant Real.arith_mean_weighted_of_constant\n\ntheorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)\n    (hw' : (∑ i in s, w i) = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) :\n    (∏ i in s, z i ^ w i) = ∑ i in s, w i * z i := by\n  rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption\n#align real.geom_mean_eq_arith_mean_weighted_of_constant Real.geom_mean_eq_arith_mean_weighted_of_constant\n\nend Real\n\nnamespace NNReal\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 (w z : ι → ℝ≥0) (hw' : (∑ i in s, w i) = 1) :\n    (∏ i in s, z i ^ (w i : ℝ)) ≤ ∑ i in s, w i * z i := by\n  exact_mod_cast\n    Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg)\n      (by assumption_mod_cast) fun i _ => (z i).coe_nonneg\n#align nnreal.geom_mean_le_arith_mean_weighted NNReal.geom_mean_le_arith_mean_weighted\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₁ w₂ p₁ p₂ : ℝ≥0) :\n    w₁ + w₂ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by\n  simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,\n    Fintype.univ_of_isEmpty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using\n    geom_mean_le_arith_mean_weighted univ ![w₁, w₂] ![p₁, p₂]\n#align nnreal.geom_mean_le_arith_mean2_weighted NNReal.geom_mean_le_arith_mean2_weighted\n\ntheorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) :\n    w₁ + w₂ + w₃ = 1 →\n      p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ :=\n  by\n  simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,\n    Fintype.univ_of_isEmpty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc,\n    mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃] ![p₁, p₂, p₃]\n#align nnreal.geom_mean_le_arith_mean3_weighted NNReal.geom_mean_le_arith_mean3_weighted\n\ntheorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) :\n    w₁ + w₂ + w₃ + w₄ = 1 →\n      p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) * p₄ ^ (w₄ : ℝ) ≤\n        w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ :=\n  by\n  simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,\n    Fintype.univ_of_isEmpty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc,\n    mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃, w₄] ![p₁, p₂, p₃, p₄]\n#align nnreal.geom_mean_le_arith_mean4_weighted NNReal.geom_mean_le_arith_mean4_weighted\n\nend NNReal\n\nnamespace Real\n\ntheorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)\n    (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ :=\n  NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ <|\n    NNReal.coe_eq.1 <| by assumption\n#align real.geom_mean_le_arith_mean2_weighted Real.geom_mean_le_arith_mean2_weighted\n\ntheorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)\n    (hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) :\n    p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ :=\n  NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩\n      ⟨p₃, hp₃⟩ <|\n    NNReal.coe_eq.1 hw\n#align real.geom_mean_le_arith_mean3_weighted Real.geom_mean_le_arith_mean3_weighted\n\ntheorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁)\n    (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃)\n    (hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) :\n    p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ :=\n  NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩\n      ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ <|\n    NNReal.coe_eq.1 <| by assumption\n#align real.geom_mean_le_arith_mean4_weighted Real.geom_mean_le_arith_mean4_weighted\n\nend Real\n\nend GeomMeanLeArithMean\n\nsection Young\n\n/-! ### Young's inequality -/\n\n\nnamespace Real\n\n/-- Young's inequality, a version for nonnegative real numbers. -/\ntheorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b)\n    (hpq : p.IsConjugateExponent q) : a * b ≤ a ^ p / p + b ^ q / q := by\n  simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, div_eq_inv_mul] using\n    geom_mean_le_arith_mean2_weighted hpq.one_div_nonneg hpq.symm.one_div_nonneg\n      (rpow_nonneg_of_nonneg ha p) (rpow_nonneg_of_nonneg hb q) hpq.inv_add_inv_conj\n#align real.young_inequality_of_nonneg Real.young_inequality_of_nonneg\n\n/-- Young's inequality, a version for arbitrary real numbers. -/\ntheorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.IsConjugateExponent q) :\n    a * b ≤ |a| ^ p / p + |b| ^ q / q :=\n  calc\n    a * b ≤ |a * b| := le_abs_self (a * b)\n    _ = |a| * |b| := (abs_mul a b)\n    _ ≤ |a| ^ p / p + |b| ^ q / q :=\n      Real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq\n    \n#align real.young_inequality Real.young_inequality\n\nend Real\n\nnamespace NNReal\n\n/-- Young's inequality, `ℝ≥0` version. We use `{p q : ℝ≥0}` in order to avoid constructing\nwitnesses of `0 ≤ p` and `0 ≤ q` for the denominators.  -/\ntheorem young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hp : 1 < p) (hpq : 1 / p + 1 / q = 1) :\n    a * b ≤ a ^ (p : ℝ) / p + b ^ (q : ℝ) / q :=\n  Real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg ⟨hp, NNReal.coe_eq.2 hpq⟩\n#align nnreal.young_inequality NNReal.young_inequality\n\n/-- Young's inequality, `ℝ≥0` version with real conjugate exponents. -/\ntheorem young_inequality_real (a b : ℝ≥0) {p q : ℝ} (hpq : p.IsConjugateExponent q) :\n    a * b ≤ a ^ p / Real.toNNReal p + b ^ q / Real.toNNReal q :=\n  by\n  nth_rw 1 [← Real.coe_toNNReal p hpq.nonneg]\n  nth_rw 1 [← Real.coe_toNNReal q hpq.symm.nonneg]\n  exact young_inequality a b hpq.one_lt_nnreal hpq.inv_add_inv_conj_nnreal\n#align nnreal.young_inequality_real NNReal.young_inequality_real\n\nend NNReal\n\nnamespace ENNReal\n\n/-- Young's inequality, `ℝ≥0∞` version with real conjugate exponents. -/\ntheorem young_inequality (a b : ℝ≥0∞) {p q : ℝ} (hpq : p.IsConjugateExponent q) :\n    a * b ≤ a ^ p / ENNReal.ofReal p + b ^ q / ENNReal.ofReal q :=\n  by\n  by_cases h : a = ⊤ ∨ b = ⊤\n  · refine' le_trans le_top (le_of_eq _)\n    repeat' rw [div_eq_mul_inv]\n    cases h <;> rw [h] <;> simp [h, hpq.pos, hpq.symm.pos]\n  push_neg  at h\n  -- if a ≠ ⊤ and b ≠ ⊤, use the nnreal version: nnreal.young_inequality_real\n  rw [← coe_to_nnreal h.left, ← coe_to_nnreal h.right, ← coe_mul, coe_rpow_of_nonneg _ hpq.nonneg,\n    coe_rpow_of_nonneg _ hpq.symm.nonneg, ENNReal.ofReal, ENNReal.ofReal, ←\n    @coe_div (Real.toNNReal p) _ (by simp [hpq.pos]), ←\n    @coe_div (Real.toNNReal q) _ (by simp [hpq.symm.pos]), ← coe_add, coe_le_coe]\n  exact NNReal.young_inequality_real a.to_nnreal b.to_nnreal hpq\n#align ennreal.young_inequality ENNReal.young_inequality\n\nend ENNReal\n\nend Young\n\nsection HolderMinkowski\n\n/-! ### Hölder's and Minkowski's inequalities -/\n\n\nnamespace NNReal\n\nprivate theorem inner_le_Lp_mul_Lp_of_norm_le_one (f g : ι → ℝ≥0) {p q : ℝ}\n    (hpq : p.IsConjugateExponent q) (hf : (∑ i in s, f i ^ p) ≤ 1) (hg : (∑ i in s, g i ^ q) ≤ 1) :\n    (∑ i in s, f i * g i) ≤ 1 :=\n  by\n  have hp_ne_zero : Real.toNNReal p ≠ 0 := (zero_lt_one.trans hpq.one_lt_nnreal).Ne.symm\n  have hq_ne_zero : Real.toNNReal q ≠ 0 := (zero_lt_one.trans hpq.symm.one_lt_nnreal).Ne.symm\n  calc\n    (∑ i in s, f i * g i) ≤ ∑ i in s, f i ^ p / Real.toNNReal p + g i ^ q / Real.toNNReal q :=\n      Finset.sum_le_sum fun i his => young_inequality_real (f i) (g i) hpq\n    _ = (∑ i in s, f i ^ p) / Real.toNNReal p + (∑ i in s, g i ^ q) / Real.toNNReal q := by\n      rw [sum_add_distrib, sum_div, sum_div]\n    _ ≤ 1 / Real.toNNReal p + 1 / Real.toNNReal q :=\n      by\n      refine' add_le_add _ _\n      · rwa [div_le_iff hp_ne_zero, div_mul_cancel _ hp_ne_zero]\n      · rwa [div_le_iff hq_ne_zero, div_mul_cancel _ hq_ne_zero]\n    _ = 1 := hpq.inv_add_inv_conj_nnreal\n    \n#align nnreal.inner_le_Lp_mul_Lp_of_norm_le_one nnreal.inner_le_Lp_mul_Lp_of_norm_le_one\n\nprivate theorem inner_le_Lp_mul_Lp_of_norm_eq_zero (f g : ι → ℝ≥0) {p q : ℝ}\n    (hpq : p.IsConjugateExponent q) (hf : (∑ i in s, f i ^ p) = 0) :\n    (∑ i in s, f i * g i) ≤ (∑ i in s, f i ^ p) ^ (1 / p) * (∑ i in s, g i ^ q) ^ (1 / q) :=\n  by\n  simp only [hf, hpq.ne_zero, one_div, sum_eq_zero_iff, zero_rpow, MulZeroClass.zero_mul,\n    inv_eq_zero, Ne.def, not_false_iff, le_zero_iff, mul_eq_zero]\n  intro i his\n  left\n  rw [sum_eq_zero_iff] at hf\n  exact (rpow_eq_zero_iff.mp (hf i his)).left\n#align nnreal.inner_le_Lp_mul_Lp_of_norm_eq_zero nnreal.inner_le_Lp_mul_Lp_of_norm_eq_zero\n\n/-- Hölder 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 `ℝ≥0`-valued functions. -/\ntheorem inner_le_Lp_mul_Lq (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjugateExponent q) :\n    (∑ i in s, f i * g i) ≤ (∑ i in s, f i ^ p) ^ (1 / p) * (∑ i in s, g i ^ q) ^ (1 / q) :=\n  by\n  by_cases hF_zero : (∑ i in s, f i ^ p) = 0\n  · exact inner_le_Lp_mul_Lp_of_norm_eq_zero s f g hpq hF_zero\n  by_cases hG_zero : (∑ i in s, g i ^ q) = 0\n  ·\n    calc\n      (∑ i in s, f i * g i) = ∑ i in s, g i * f i :=\n        by\n        congr with i\n        rw [mul_comm]\n      _ ≤ (∑ i in s, g i ^ q) ^ (1 / q) * (∑ i in s, f i ^ p) ^ (1 / p) :=\n        (inner_le_Lp_mul_Lp_of_norm_eq_zero s g f hpq.symm hG_zero)\n      _ = (∑ i in s, f i ^ p) ^ (1 / p) * (∑ i in s, g i ^ q) ^ (1 / q) := mul_comm _ _\n      \n  let f' i := f i / (∑ i in s, f i ^ p) ^ (1 / p)\n  let g' i := g i / (∑ i in s, g i ^ q) ^ (1 / q)\n  suffices (∑ i in s, f' i * g' i) ≤ 1\n    by\n    simp_rw [f', g', div_mul_div_comm, ← sum_div] at this\n    rwa [div_le_iff, one_mul] at this\n    refine' mul_ne_zero _ _\n    · rw [Ne.def, rpow_eq_zero_iff, not_and_or]\n      exact Or.inl hF_zero\n    · rw [Ne.def, rpow_eq_zero_iff, not_and_or]\n      exact Or.inl hG_zero\n  refine' inner_le_Lp_mul_Lp_of_norm_le_one s f' g' hpq (le_of_eq _) (le_of_eq _)\n  ·\n    simp_rw [f', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel hpq.ne_zero, rpow_one,\n      div_self hF_zero]\n  ·\n    simp_rw [g', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel hpq.symm.ne_zero,\n      rpow_one, div_self hG_zero]\n#align nnreal.inner_le_Lp_mul_Lq NNReal.inner_le_Lp_mul_Lq\n\n/-- Hölder 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. A version for `nnreal`-valued\nfunctions. For an alternative version, convenient if the infinite sums are already expressed as\n`p`-th powers, see `inner_le_Lp_mul_Lq_has_sum`. -/\ntheorem inner_le_Lp_mul_Lq_tsum {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjugateExponent q)\n    (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :\n    (Summable fun i => f i * g i) ∧\n      (∑' i, f i * g i) ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) :=\n  by\n  have H₁ :\n    ∀ s : Finset ι, (∑ i in s, f i * g i) ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) :=\n    by\n    intro s\n    refine' le_trans (inner_le_Lp_mul_Lq s f g hpq) (mul_le_mul _ _ bot_le bot_le)\n    · rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.pos)]\n      exact sum_le_tsum _ (fun _ _ => zero_le _) hf\n    · rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.symm.pos)]\n      exact sum_le_tsum _ (fun _ _ => zero_le _) hg\n  have bdd : BddAbove (Set.range fun s => ∑ i in s, f i * g i) :=\n    by\n    refine' ⟨(∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q), _⟩\n    rintro a ⟨s, rfl⟩\n    exact H₁ s\n  have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_csupᵢ bdd)).Summable\n  exact ⟨H₂, tsum_le_of_sum_le H₂ H₁⟩\n#align nnreal.inner_le_Lp_mul_Lq_tsum NNReal.inner_le_Lp_mul_Lq_tsum\n\ntheorem summable_mul_of_Lp_Lq {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjugateExponent q)\n    (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :\n    Summable fun i => f i * g i :=\n  (inner_le_Lp_mul_Lq_tsum hpq hf hg).1\n#align nnreal.summable_mul_of_Lp_Lq NNReal.summable_mul_of_Lp_Lq\n\ntheorem inner_le_Lp_mul_Lq_tsum' {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.IsConjugateExponent q)\n    (hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :\n    (∑' i, f i * g i) ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) :=\n  (inner_le_Lp_mul_Lq_tsum hpq hf hg).2\n#align nnreal.inner_le_Lp_mul_Lq_tsum' NNReal.inner_le_Lp_mul_Lq_tsum'\n\n/-- Hölder 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. A version for `nnreal`-valued\nfunctions. For an alternative version, convenient if the infinite sums are not already expressed as\n`p`-th powers, see `inner_le_Lp_mul_Lq_tsum`.  -/\ntheorem inner_le_Lp_mul_Lq_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p q : ℝ}\n    (hpq : p.IsConjugateExponent q) (hf : HasSum (fun i => f i ^ p) (A ^ p))\n    (hg : HasSum (fun i => g i ^ q) (B ^ q)) : ∃ C, C ≤ A * B ∧ HasSum (fun i => f i * g i) C :=\n  by\n  obtain ⟨H₁, H₂⟩ := inner_le_Lp_mul_Lq_tsum hpq hf.summable hg.summable\n  have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hpq.ne_zero]\n  have hB : B = (∑' i : ι, g i ^ q) ^ (1 / q) := by\n    rw [hg.tsum_eq, rpow_inv_rpow_self hpq.symm.ne_zero]\n  refine' ⟨∑' i, f i * g i, _, _⟩\n  · simpa [hA, hB] using H₂\n  · simpa only [rpow_self_rpow_inv hpq.ne_zero] using H₁.has_sum\n#align nnreal.inner_le_Lp_mul_Lq_has_sum NNReal.inner_le_Lp_mul_Lq_hasSum\n\n/-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the\nsum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0`-valued functions.\n-/\ntheorem rpow_sum_le_const_mul_sum_rpow (f : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) :\n    (∑ i in s, f i) ^ p ≤ card s ^ (p - 1) * ∑ i in s, f i ^ p :=\n  by\n  cases' eq_or_lt_of_le hp with hp hp\n  · simp [← hp]\n  let q : ℝ := p / (p - 1)\n  have hpq : p.is_conjugate_exponent q := by rw [Real.isConjugateExponent_iff hp]\n  have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero\n  have hq : 1 / q * p = p - 1 := by\n    rw [← hpq.div_conj_eq_sub_one]\n    ring\n  simpa only [NNReal.mul_rpow, ← NNReal.rpow_mul, hp₁, hq, one_mul, one_rpow, rpow_one,\n    Pi.one_apply, sum_const, Nat.smul_one_eq_coe] using\n    NNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg\n#align nnreal.rpow_sum_le_const_mul_sum_rpow NNReal.rpow_sum_le_const_mul_sum_rpow\n\n/-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product\n`∑ i in s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/\ntheorem isGreatest_Lp (f : ι → ℝ≥0) {p q : ℝ} (hpq : p.IsConjugateExponent q) :\n    IsGreatest ((fun g : ι → ℝ≥0 => ∑ i in s, f i * g i) '' { g | (∑ i in s, g i ^ q) ≤ 1 })\n      ((∑ i in s, f i ^ p) ^ (1 / p)) :=\n  by\n  constructor\n  · use fun i => f i ^ p / f i / (∑ i in s, f i ^ p) ^ (1 / q)\n    by_cases hf : (∑ i in s, f i ^ p) = 0\n    · simp [hf, hpq.ne_zero, hpq.symm.ne_zero]\n    · have A : p + q - q ≠ 0 := by simp [hpq.ne_zero]\n      have B : ∀ y : ℝ≥0, y * y ^ p / y = y ^ p :=\n        by\n        refine' fun y => mul_div_cancel_left_of_imp fun h => _\n        simpa [h, hpq.ne_zero]\n      simp only [Set.mem_setOf_eq, div_rpow, ← sum_div, ← rpow_mul,\n        div_mul_cancel _ hpq.symm.ne_zero, rpow_one, div_le_iff hf, one_mul, hpq.mul_eq_add, ←\n        rpow_sub' _ A, _root_.add_sub_cancel, le_refl, true_and_iff, ← mul_div_assoc, B]\n      rw [div_eq_iff, ← rpow_add hf, hpq.inv_add_inv_conj, rpow_one]\n      simpa [hpq.symm.ne_zero] using hf\n  · rintro _ ⟨g, hg, rfl⟩\n    apply le_trans (inner_le_Lp_mul_Lq s f g hpq)\n    simpa only [mul_one] using\n      mul_le_mul_left' (NNReal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) _\n#align nnreal.is_greatest_Lp NNReal.isGreatest_Lp\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 (f g : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) :\n    (∑ i in s, (f i + g i) ^ p) ^ (1 / p) ≤\n      (∑ i in s, f i ^ p) ^ (1 / p) + (∑ i in s, g i ^ p) ^ (1 / p) :=\n  by\n  -- The result is trivial when `p = 1`, so we can assume `1 < p`.\n  rcases eq_or_lt_of_le hp with (rfl | hp);\n  · simp [Finset.sum_add_distrib]\n  have hpq := Real.isConjugateExponent_conjugateExponent hp\n  have := is_greatest_Lp s (f + g) hpq\n  simp only [Pi.add_apply, add_mul, sum_add_distrib] at this\n  rcases this.1 with ⟨φ, hφ, H⟩\n  rw [← H]\n  exact\n    add_le_add ((is_greatest_Lp s f hpq).2 ⟨φ, hφ, rfl⟩) ((is_greatest_Lp s g hpq).2 ⟨φ, hφ, rfl⟩)\n#align nnreal.Lp_add_le NNReal.Lp_add_le\n\n/-- Minkowski inequality: the `L_p` seminorm of the infinite sum of two vectors is less than or\nequal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both\nexist. A version for `nnreal`-valued functions. For an alternative version, convenient if the\ninfinite sums are already expressed as `p`-th powers, see `Lp_add_le_has_sum_of_nonneg`. -/\ntheorem Lp_add_le_tsum {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p)\n    (hg : Summable fun i => g i ^ p) :\n    (Summable fun i => (f i + g i) ^ p) ∧\n      (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) :=\n  by\n  have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp\n  have H₁ :\n    ∀ s : Finset ι,\n      (∑ i in s, (f i + g i) ^ p) ≤ ((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p :=\n    by\n    intro s\n    rw [← NNReal.rpow_one_div_le_iff Pos]\n    refine' le_trans (Lp_add_le s f g hp) (add_le_add _ _) <;>\n        rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr Pos)] <;>\n      refine' sum_le_tsum _ (fun _ _ => zero_le _) _\n    exacts[hf, hg]\n  have bdd : BddAbove (Set.range fun s => ∑ i in s, (f i + g i) ^ p) :=\n    by\n    refine' ⟨((∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p)) ^ p, _⟩\n    rintro a ⟨s, rfl⟩\n    exact H₁ s\n  have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_csupᵢ bdd)).Summable\n  refine' ⟨H₂, _⟩\n  rw [NNReal.rpow_one_div_le_iff Pos]\n  refine' tsum_le_of_sum_le H₂ H₁\n#align nnreal.Lp_add_le_tsum NNReal.Lp_add_le_tsum\n\ntheorem summable_Lp_add {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p)\n    (hg : Summable fun i => g i ^ p) : Summable fun i => (f i + g i) ^ p :=\n  (Lp_add_le_tsum hp hf hg).1\n#align nnreal.summable_Lp_add NNReal.summable_Lp_add\n\ntheorem Lp_add_le_tsum' {f g : ι → ℝ≥0} {p : ℝ} (hp : 1 ≤ p) (hf : Summable fun i => f i ^ p)\n    (hg : Summable fun i => g i ^ p) :\n    (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) :=\n  (Lp_add_le_tsum hp hf hg).2\n#align nnreal.Lp_add_le_tsum' NNReal.Lp_add_le_tsum'\n\n/-- Minkowski inequality: the `L_p` seminorm of the infinite sum of two vectors is less than or\nequal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both\nexist. A version for `nnreal`-valued functions. For an alternative version, convenient if the\ninfinite sums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`.  -/\ntheorem Lp_add_le_hasSum {f g : ι → ℝ≥0} {A B : ℝ≥0} {p : ℝ} (hp : 1 ≤ p)\n    (hf : HasSum (fun i => f i ^ p) (A ^ p)) (hg : HasSum (fun i => g i ^ p) (B ^ p)) :\n    ∃ C, C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) :=\n  by\n  have hp' : p ≠ 0 := (lt_of_lt_of_le zero_lt_one hp).ne'\n  obtain ⟨H₁, H₂⟩ := Lp_add_le_tsum hp hf.summable hg.summable\n  have hA : A = (∑' i : ι, f i ^ p) ^ (1 / p) := by rw [hf.tsum_eq, rpow_inv_rpow_self hp']\n  have hB : B = (∑' i : ι, g i ^ p) ^ (1 / p) := by rw [hg.tsum_eq, rpow_inv_rpow_self hp']\n  refine' ⟨(∑' i, (f i + g i) ^ p) ^ (1 / p), _, _⟩\n  · simpa [hA, hB] using H₂\n  · simpa only [rpow_self_rpow_inv hp'] using H₁.has_sum\n#align nnreal.Lp_add_le_has_sum NNReal.Lp_add_le_hasSum\n\nend NNReal\n\nnamespace Real\n\nvariable (f g : ι → ℝ) {p q : ℝ}\n\n/-- Hölder 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 (hpq : IsConjugateExponent p q) :\n    (∑ i in s, f i * g i) ≤ (∑ i in s, |f i| ^ p) ^ (1 / p) * (∑ i in s, |g i| ^ q) ^ (1 / q) :=\n  by\n  have :=\n    NNReal.coe_le_coe.2\n      (NNReal.inner_le_Lp_mul_Lq s (fun i => ⟨_, abs_nonneg (f i)⟩) (fun i => ⟨_, abs_nonneg (g i)⟩)\n        hpq)\n  push_cast at this\n  refine' le_trans (sum_le_sum fun i hi => _) this\n  simp only [← abs_mul, le_abs_self]\n#align real.inner_le_Lp_mul_Lq Real.inner_le_Lp_mul_Lq\n\n/-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the\nsum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ`-valued functions. -/\ntheorem rpow_sum_le_const_mul_sum_rpow (hp : 1 ≤ p) :\n    (∑ i in s, |f i|) ^ p ≤ card s ^ (p - 1) * ∑ i in s, |f i| ^ p :=\n  by\n  have :=\n    NNReal.coe_le_coe.2\n      (NNReal.rpow_sum_le_const_mul_sum_rpow s (fun i => ⟨_, abs_nonneg (f i)⟩) hp)\n  push_cast at this\n  exact this\n#align real.rpow_sum_le_const_mul_sum_rpow Real.rpow_sum_le_const_mul_sum_rpow\n\n-- for some reason `exact_mod_cast` can't replace this argument\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 (hp : 1 ≤ p) :\n    (∑ i in s, |f i + g i| ^ p) ^ (1 / p) ≤\n      (∑ i in s, |f i| ^ p) ^ (1 / p) + (∑ i in s, |g i| ^ p) ^ (1 / p) :=\n  by\n  have :=\n    NNReal.coe_le_coe.2\n      (NNReal.Lp_add_le s (fun i => ⟨_, abs_nonneg (f i)⟩) (fun i => ⟨_, abs_nonneg (g i)⟩) hp)\n  push_cast at this\n  refine' le_trans (rpow_le_rpow _ (sum_le_sum fun i hi => _) _) this <;>\n    simp [sum_nonneg, rpow_nonneg_of_nonneg, abs_nonneg, le_trans zero_le_one hp, abs_add,\n      rpow_le_rpow]\n#align real.Lp_add_le Real.Lp_add_le\n\nvariable {f g}\n\n/-- Hölder 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 (hpq : IsConjugateExponent p q) (hf : ∀ i ∈ s, 0 ≤ f i)\n    (hg : ∀ i ∈ s, 0 ≤ g i) :\n    (∑ i in s, f i * g i) ≤ (∑ i in s, f i ^ p) ^ (1 / p) * (∑ i in s, g i ^ q) ^ (1 / q) := by\n  convert inner_le_Lp_mul_Lq s f g hpq using 3 <;> apply sum_congr rfl <;> intro i hi <;>\n    simp only [abs_of_nonneg, hf i hi, hg i hi]\n#align real.inner_le_Lp_mul_Lq_of_nonneg Real.inner_le_Lp_mul_Lq_of_nonneg\n\n/-- Hölder 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. A version for `ℝ`-valued functions.\nFor an alternative version, convenient if the infinite sums are already expressed as `p`-th powers,\nsee `inner_le_Lp_mul_Lq_has_sum_of_nonneg`. -/\ntheorem inner_le_Lp_mul_Lq_tsum_of_nonneg (hpq : p.IsConjugateExponent q) (hf : ∀ i, 0 ≤ f i)\n    (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) :\n    (Summable fun i => f i * g i) ∧\n      (∑' i, f i * g i) ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) :=\n  by\n  lift f to ι → ℝ≥0 using hf\n  lift g to ι → ℝ≥0 using hg\n  norm_cast  at *\n  exact NNReal.inner_le_Lp_mul_Lq_tsum hpq hf_sum hg_sum\n#align real.inner_le_Lp_mul_Lq_tsum_of_nonneg Real.inner_le_Lp_mul_Lq_tsum_of_nonneg\n\ntheorem summable_mul_of_Lp_Lq_of_nonneg (hpq : p.IsConjugateExponent q) (hf : ∀ i, 0 ≤ f i)\n    (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) :\n    Summable fun i => f i * g i :=\n  (inner_le_Lp_mul_Lq_tsum_of_nonneg hpq hf hg hf_sum hg_sum).1\n#align real.summable_mul_of_Lp_Lq_of_nonneg Real.summable_mul_of_Lp_Lq_of_nonneg\n\ntheorem inner_le_Lp_mul_Lq_tsum_of_nonneg' (hpq : p.IsConjugateExponent q) (hf : ∀ i, 0 ≤ f i)\n    (hg : ∀ i, 0 ≤ g i) (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ q) :\n    (∑' i, f i * g i) ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) :=\n  (inner_le_Lp_mul_Lq_tsum_of_nonneg hpq hf hg hf_sum hg_sum).2\n#align real.inner_le_Lp_mul_Lq_tsum_of_nonneg' Real.inner_le_Lp_mul_Lq_tsum_of_nonneg'\n\n/-- Hölder 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. A version for `nnreal`-valued\nfunctions. For an alternative version, convenient if the infinite sums are not already expressed as\n`p`-th powers, see `inner_le_Lp_mul_Lq_tsum_of_nonneg`.  -/\ntheorem inner_le_Lp_mul_Lq_hasSum_of_nonneg (hpq : p.IsConjugateExponent q) {A B : ℝ} (hA : 0 ≤ A)\n    (hB : 0 ≤ B) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i)\n    (hf_sum : HasSum (fun i => f i ^ p) (A ^ p)) (hg_sum : HasSum (fun i => g i ^ q) (B ^ q)) :\n    ∃ C : ℝ, 0 ≤ C ∧ C ≤ A * B ∧ HasSum (fun i => f i * g i) C :=\n  by\n  lift f to ι → ℝ≥0 using hf\n  lift g to ι → ℝ≥0 using hg\n  lift A to ℝ≥0 using hA\n  lift B to ℝ≥0 using hB\n  norm_cast  at hf_sum hg_sum\n  obtain ⟨C, hC, H⟩ := NNReal.inner_le_Lp_mul_Lq_hasSum hpq hf_sum hg_sum\n  refine' ⟨C, C.prop, hC, _⟩\n  norm_cast\n  exact H\n#align real.inner_le_Lp_mul_Lq_has_sum_of_nonneg Real.inner_le_Lp_mul_Lq_hasSum_of_nonneg\n\n/-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the\nsum of the `p`-th powers of `f i`. Version for sums over finite sets, with nonnegative `ℝ`-valued\nfunctions. -/\ntheorem rpow_sum_le_const_mul_sum_rpow_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) :\n    (∑ i in s, f i) ^ p ≤ card s ^ (p - 1) * ∑ i in s, f i ^ p := by\n  convert rpow_sum_le_const_mul_sum_rpow s f hp using 2 <;> apply sum_congr rfl <;> intro i hi <;>\n    simp only [abs_of_nonneg, hf i hi]\n#align real.rpow_sum_le_const_mul_sum_rpow_of_nonneg Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg\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 `ℝ`-valued nonnegative\nfunctions. -/\ntheorem Lp_add_le_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) :\n    (∑ i in s, (f i + g i) ^ p) ^ (1 / p) ≤\n      (∑ i in s, f i ^ p) ^ (1 / p) + (∑ i in s, g i ^ p) ^ (1 / p) :=\n  by\n  convert Lp_add_le s f g hp using 2 <;> [skip, congr 1, congr 1] <;> apply sum_congr rfl <;>\n      intro i hi <;>\n    simp only [abs_of_nonneg, hf i hi, hg i hi, add_nonneg]\n#align real.Lp_add_le_of_nonneg Real.Lp_add_le_of_nonneg\n\n/-- Minkowski inequality: the `L_p` seminorm of the infinite sum of two vectors is less than or\nequal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both\nexist. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite\nsums are already expressed as `p`-th powers, see `Lp_add_le_has_sum_of_nonneg`. -/\ntheorem Lp_add_le_tsum_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i)\n    (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) :\n    (Summable fun i => (f i + g i) ^ p) ∧\n      (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) :=\n  by\n  lift f to ι → ℝ≥0 using hf\n  lift g to ι → ℝ≥0 using hg\n  norm_cast  at *\n  exact NNReal.Lp_add_le_tsum hp hf_sum hg_sum\n#align real.Lp_add_le_tsum_of_nonneg Real.Lp_add_le_tsum_of_nonneg\n\ntheorem summable_Lp_add_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i)\n    (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) :\n    Summable fun i => (f i + g i) ^ p :=\n  (Lp_add_le_tsum_of_nonneg hp hf hg hf_sum hg_sum).1\n#align real.summable_Lp_add_of_nonneg Real.summable_Lp_add_of_nonneg\n\ntheorem Lp_add_le_tsum_of_nonneg' (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i)\n    (hf_sum : Summable fun i => f i ^ p) (hg_sum : Summable fun i => g i ^ p) :\n    (∑' i, (f i + g i) ^ p) ^ (1 / p) ≤ (∑' i, f i ^ p) ^ (1 / p) + (∑' i, g i ^ p) ^ (1 / p) :=\n  (Lp_add_le_tsum_of_nonneg hp hf hg hf_sum hg_sum).2\n#align real.Lp_add_le_tsum_of_nonneg' Real.Lp_add_le_tsum_of_nonneg'\n\n/-- Minkowski inequality: the `L_p` seminorm of the infinite sum of two vectors is less than or\nequal to the infinite sum of the `L_p`-seminorms of the summands, if these infinite sums both\nexist. A version for `ℝ`-valued functions. For an alternative version, convenient if the infinite\nsums are not already expressed as `p`-th powers, see `Lp_add_le_tsum_of_nonneg`. -/\ntheorem Lp_add_le_hasSum_of_nonneg (hp : 1 ≤ p) (hf : ∀ i, 0 ≤ f i) (hg : ∀ i, 0 ≤ g i) {A B : ℝ}\n    (hA : 0 ≤ A) (hB : 0 ≤ B) (hfA : HasSum (fun i => f i ^ p) (A ^ p))\n    (hgB : HasSum (fun i => g i ^ p) (B ^ p)) :\n    ∃ C, 0 ≤ C ∧ C ≤ A + B ∧ HasSum (fun i => (f i + g i) ^ p) (C ^ p) :=\n  by\n  lift f to ι → ℝ≥0 using hf\n  lift g to ι → ℝ≥0 using hg\n  lift A to ℝ≥0 using hA\n  lift B to ℝ≥0 using hB\n  norm_cast  at hfA hgB\n  obtain ⟨C, hC₁, hC₂⟩ := NNReal.Lp_add_le_hasSum hp hfA hgB\n  use C\n  norm_cast\n  exact ⟨zero_le _, hC₁, hC₂⟩\n#align real.Lp_add_le_has_sum_of_nonneg Real.Lp_add_le_hasSum_of_nonneg\n\nend Real\n\nnamespace ENNReal\n\nvariable (f g : ι → ℝ≥0∞) {p q : ℝ}\n\n/-- Hölder 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 `ℝ≥0∞`-valued functions. -/\ntheorem inner_le_Lp_mul_Lq (hpq : p.IsConjugateExponent q) :\n    (∑ i in s, f i * g i) ≤ (∑ i in s, f i ^ p) ^ (1 / p) * (∑ i in s, g i ^ q) ^ (1 / q) :=\n  by\n  by_cases H : (∑ i in s, f i ^ p) ^ (1 / p) = 0 ∨ (∑ i in s, g i ^ q) ^ (1 / q) = 0\n  · replace H : (∀ i ∈ s, f i = 0) ∨ ∀ i ∈ s, g i = 0\n    ·\n      simpa [ENNReal.rpow_eq_zero_iff, hpq.pos, hpq.symm.pos, asymm hpq.pos, asymm hpq.symm.pos,\n        sum_eq_zero_iff_of_nonneg] using H\n    have : ∀ i ∈ s, f i * g i = 0 := fun i hi => by cases H <;> simp [H i hi]\n    have : (∑ i in s, f i * g i) = ∑ i in s, 0 := sum_congr rfl this\n    simp [this]\n  push_neg  at H\n  by_cases H' : (∑ i in s, f i ^ p) ^ (1 / p) = ⊤ ∨ (∑ i in s, g i ^ q) ^ (1 / q) = ⊤\n  · cases H' <;> simp [H', -one_div, H]\n  replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ ∀ i ∈ s, g i ≠ ⊤\n  ·\n    simpa [ENNReal.rpow_eq_top_iff, asymm hpq.pos, asymm hpq.symm.pos, hpq.pos, hpq.symm.pos,\n      ENNReal.sum_eq_top_iff, not_or] using H'\n  have :=\n    ENNReal.coe_le_coe.2\n      (@NNReal.inner_le_Lp_mul_Lq _ s (fun i => ENNReal.toNNReal (f i))\n        (fun i => ENNReal.toNNReal (g i)) _ _ hpq)\n  simp [← ENNReal.coe_rpow_of_nonneg, le_of_lt hpq.pos, le_of_lt hpq.one_div_pos,\n    le_of_lt hpq.symm.pos, le_of_lt hpq.symm.one_div_pos] at this\n  convert this using 1 <;> [skip, congr 2] <;> [skip, skip, simp, skip, simp] <;>\n    · apply Finset.sum_congr rfl fun i hi => _\n      simp [H'.1 i hi, H'.2 i hi, -WithZero.coe_mul, with_top.coe_mul.symm]\n#align ennreal.inner_le_Lp_mul_Lq ENNReal.inner_le_Lp_mul_Lq\n\n/-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the\nsum of the `p`-th powers of `f i`. Version for sums over finite sets, with `ℝ≥0∞`-valued functions.\n-/\ntheorem rpow_sum_le_const_mul_sum_rpow (hp : 1 ≤ p) :\n    (∑ i in s, f i) ^ p ≤ card s ^ (p - 1) * ∑ i in s, f i ^ p :=\n  by\n  cases' eq_or_lt_of_le hp with hp hp\n  · simp [← hp]\n  let q : ℝ := p / (p - 1)\n  have hpq : p.is_conjugate_exponent q := by rw [Real.isConjugateExponent_iff hp]\n  have hp₁ : 1 / p * p = 1 := one_div_mul_cancel hpq.ne_zero\n  have hq : 1 / q * p = p - 1 := by\n    rw [← hpq.div_conj_eq_sub_one]\n    ring\n  simpa only [ENNReal.mul_rpow_of_nonneg _ _ hpq.nonneg, ← ENNReal.rpow_mul, hp₁, hq, coe_one,\n    one_mul, one_rpow, rpow_one, Pi.one_apply, sum_const, Nat.smul_one_eq_coe] using\n    ENNReal.rpow_le_rpow (inner_le_Lp_mul_Lq s 1 f hpq.symm) hpq.nonneg\n#align ennreal.rpow_sum_le_const_mul_sum_rpow ENNReal.rpow_sum_le_const_mul_sum_rpow\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 `ℝ≥0∞` valued nonnegative\nfunctions. -/\ntheorem Lp_add_le (hp : 1 ≤ p) :\n    (∑ i in s, (f i + g i) ^ p) ^ (1 / p) ≤\n      (∑ i in s, f i ^ p) ^ (1 / p) + (∑ i in s, g i ^ p) ^ (1 / p) :=\n  by\n  by_cases H' : (∑ i in s, f i ^ p) ^ (1 / p) = ⊤ ∨ (∑ i in s, g i ^ p) ^ (1 / p) = ⊤\n  · cases H' <;> simp [H', -one_div]\n  have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp\n  replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ ∀ i ∈ s, g i ≠ ⊤\n  · simpa [ENNReal.rpow_eq_top_iff, asymm Pos, Pos, ENNReal.sum_eq_top_iff, not_or] using H'\n  have :=\n    ENNReal.coe_le_coe.2\n      (@NNReal.Lp_add_le _ s (fun i => ENNReal.toNNReal (f i)) (fun i => ENNReal.toNNReal (g i)) _\n        hp)\n  push_cast [← ENNReal.coe_rpow_of_nonneg, le_of_lt Pos, le_of_lt (one_div_pos.2 Pos)] at this\n  convert this using 2 <;> [skip, congr 1, congr 1] <;>\n    · apply Finset.sum_congr rfl fun i hi => _\n      simp [H'.1 i hi, H'.2 i hi]\n#align ennreal.Lp_add_le ENNReal.Lp_add_le\n\nend ENNReal\n\nend HolderMinkowski\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/MeanInequalities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.8740772351648677, "lm_q1q2_score": 0.7907344295234878}}
{"text": "import data.real.basic\nimport algebra.pi_instances\n\nset_option pp.beta true\n\n/-\nIn this file, we'll learn about the ∀ quantifier, and the disjunction \noperator ∨ (logical OR).\n\nLet P be a predicate on a type X. This means for every mathematical\nobject x with type X, we get a mathematical statement P x. \nIn Lean, P x has type Prop.\n\nLean sees a proof h of `∀ x, P x` as a function sending any `x : X` to\na proof `h x` of `P x`. \nThis already explains the main way to use an assumption or lemma which\nstarts with a ∀. \n\nIn order to prove `∀ x, P x`, we use `intros x` to fix an arbitrary object\nwith type X, and call it x.\n\nNote also we don't need to give the type of x in the expression `∀ x, P x`\nas long as the type of P is clear to Lean, which can then infer the type of x.\n\nLet's define two predicates to play with ∀.\n-/\n\ndef even_fun (f : ℝ → ℝ) := ∀ x, f (-x) = f x\n\ndef odd_fun (f : ℝ → ℝ) := ∀ x, f (-x) = -f x\n\n/-\nIn the next proof, we also take the opportunity to introduce the \n`unfold` tactic, which simply unfolds definitions. Here this is purely\nfor didactic reason, Lean doesn't need those `unfold` invocations. \nWe will also use `rfl` which is a term proving equalities that are true \nby definition (in a very strong sense to be discussed later).\n-/\n\nexample (f g : ℝ → ℝ) : even_fun f → even_fun g →  even_fun (f + g) :=\nbegin\n  -- Assume f is even\n  intros hf,\n  -- which means ∀ x, f (-x) = f x\n  unfold even_fun at hf,\n  -- and the same for g\n  intros hg,\n  unfold even_fun at hg,\n  -- We need to prove ∀ x, (f+g)(-x) = (f+g)(x)\n  unfold even_fun,\n  -- Let x be any real number\n  intros x,\n  -- and let's compute\n  calc (f + g) (-x) = f (-x) + g (-x) : rfl\n  ... = f x + g (-x) : by rw hf x \n  ... = f x + g x : by rw hg x \n  ... = (f + g) x : rfl\nend\n\n/-\nIn the preceding proof, all `unfold` lines are purely for\npsychological comfort.\n\nSometimes unfolding is necessary because we want to apply a tactic\nthat operates purely on the syntactical level.\nThe main such tactic is `rw`.\n\nThe same property of `rw` explain why the first computation line\nis necessary, although its proof is simply `rfl`.\nBefore that line, `rw hf x` won't find anything like `f (-x)` hence\nwill give up.\nThe last line is not necessary however, since it only proves \nsomething that is true by definition, and is not followed by\na `rw`.\n\nAlso, Lean doesn't need to be told that hf should be specialized to \nx before rewriting, exactly as in the first file 01_equality_rewriting.\nWe can also gather several rewrites using a list of expressions.\n\nHence we can compress the above proof to:\n-/\n\nexample (f g : ℝ → ℝ) : even_fun f → even_fun g →  even_fun (f + g) :=\nbegin\n  intros hf hg x,\n  calc (f + g) (-x) = f (-x) + g (-x) : rfl\n  ... = f x + g x : by rw [hf, hg] \nend\n\n/-\nNote that the tactic state displays changes when we\nmove the cursor inside the list of expressions given to `rw`.\n\nNow let's practice.\n-/\n\n-- 0023\nexample (f g : ℝ → ℝ) : even_fun f → even_fun (g ∘ f) :=\nbegin\n  -- sorry\n  intros hf x,\n  calc (g ∘ f) (-x) = g (f (-x)) : rfl\n  ... = g (f x) : by rw hf\n  -- sorry\nend\n\n-- 0024\nexample (f g : ℝ → ℝ) : odd_fun f → odd_fun g →  odd_fun (g ∘ f) :=\nbegin\n  -- sorry\n  intros hf hg x,\n  calc (g ∘ f) (-x) = g (f (-x)) : rfl\n  ... = - (g ∘ f) x : by rw [hf, hg],\n  -- sorry\nend\n\n/-\nLet's have more quantifiers, and play with forward and backward reasoning. \n\nIn the next definitions, note how `∀ x₁, ∀ x₂` is abreviated to `∀ x₁ x₂`. \n-/\n\ndef non_decreasing (f : ℝ → ℝ) := ∀ x₁ x₂, x₁ ≤ x₂ → f x₁ ≤ f x₂\n\ndef non_increasing (f : ℝ → ℝ) := ∀ x₁ x₂, x₁ ≤ x₂ → f x₁ ≥ f x₂\n\n/- Let's be very explicit and use forward reasonning first. -/\nexample (f g : ℝ → ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) :=\nbegin\n  -- Let x₁ and x₂ be real numbers such that x₁ ≤ x₂\n  intros x₁ x₂ h,\n  -- Since f is non-decreasing, f x₁ ≤ f x₂.\n  have step₁ :  f x₁ ≤ f x₂,\n    exact hf x₁ x₂ h,\n  -- Since g is non-decreasing, we then get g (f x₁) ≤ g (f x₂).\n  exact hg (f x₁) (f x₂) step₁,\nend\n\n/-\nIn the above proof, note how inconvenient it is to specify x₁ and x₂ in `hf x₁ x₂ h` since\nthey could be inferred from the type of h. \nWe could have written `hf _ _ h` and Lean would have filled the holes denoted by _. \n\nEven better we could have written the definition\nof `non_decreasing` as: ∀ {x₁ x₂}, x₁ ≤ x₂ → f x₁ ≤ f x₂, with curly braces to denote\nimplicit arguments.\n \nBut let's leave that aside for now. One possible variation on the above proof is to\nuse the `specialize` tactic to replace hf by its specialization to the relevant value.\n -/\n\nexample (f g : ℝ → ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) :=\nbegin\n  intros x₁ x₂ h,\n  specialize hf x₁ x₂ h,\n  exact hg (f x₁) (f x₂) hf,\nend\n\n/-\nThis `specialize` tactic is mostly useful for exploration, or in preparation for rewriting \nin the assumption. One can very often replace its use by using more complicated expressions\ndirectly involving the original assumption, as in the next variation:\n-/\nexample (f g : ℝ → ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) :=\nbegin\n  intros x₁ x₂ h,\n  exact hg (f x₁) (f x₂) (hf x₁ x₂ h),\nend\n\n/-\nSince the above proof uses only `intros` and `exact`, we could very easily replace it by the\nraw proof term:\n-/\nexample (f g : ℝ → ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) :=\nλ x₁ x₂ h, hg (f x₁) (f x₂) (hf x₁ x₂ h)\n\n/-\nOf course the above proof is difficult to decipher. The principle in mathlib is to use\nsuch a proof when the result is obvious and you don't want to read the proof anyway. \n\nInstead of pursuing this style, let's see how backward reasoning would look like here.\nAs usual with this style, we use `apply` and enjoy Lean specializing assumptions for us\nusing unification.\n-/\n\nexample (f g : ℝ → ℝ) (hf : non_decreasing f) (hg : non_decreasing g) : non_decreasing (g ∘ f) :=\nbegin\n  -- Let x₁ and x₂ be real numbers such that x₁ ≤ x₂\n  intros x₁ x₂ h,\n  -- We need to prove (g ∘ f) x₁ ≤ (g ∘ f) x₂.\n  -- Since g is non-decreasing, it suffices to prove f x₁ ≤ f x₂\n  apply hg,\n  -- which follows from our assumption on f\n  apply hf,\n  -- and on x₁ and x₂\n  exact h\nend\n\n-- 0025\nexample (f g : ℝ → ℝ) (hf : non_decreasing f) (hg : non_increasing g) : non_increasing (g ∘ f) :=\nbegin\n  -- sorry\n  intros x₁ x₂ h,\n  apply hg,\n  exact hf x₁ x₂ h\n  -- sorry\nend\n\n/-\nLet's switch to disjunctions now. Lean denotes by ∨ the\nlogical OR operator.\n\nIn order to make use of an assumption\n  hyp : P ∨ Q\nwe use the cases tactic:\n  cases hyp with hP hQ\nwhich creates two proof branches: one branch assuming hP : P,\nand one branch assuming hQ : Q.\n\nIn order to directly prove a goal P ∨ Q,\nwe use either the `left` tactic and prove P or the `right`\ntactic and prove Q.\n\nIn the next proof we use `ring` and `linarith` to get rid of \neasy computations or inequalities, as well as one lemma:\n\n  mul_eq_zero : a*b = 0 ↔ a = 0 ∨ b = 0\n-/\n\nexample (a b : ℝ) : a = a*b → a = 0 ∨ b = 1 :=\nbegin\n  intro hyp,\n  have H : a*(1 - b) = 0,\n  { calc a*(1 - b) = a - a*b : by ring\n               ... = 0       : by linarith, },\n  rw mul_eq_zero at H,\n  cases H with Ha Hb,\n  { left,\n    exact Ha, },\n  { right,\n    linarith, },\nend\n\n-- 0026\nexample (x y : ℝ) : x^2 = y^2 → x = y ∨ x = -y :=\nbegin\n  -- sorry\n  intros hyp,\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 hyp\n    ... = 0 : by ring,\n  rw mul_eq_zero at H,\n  cases H with h1 h2,\n  { left,\n    linarith, },\n  { right,\n    linarith, },\n  -- sorry\nend\n\n/-\nIn the next exercise, we can use:\n  eq_or_lt_of_le : x ≤ y → x = y ∨ x < y\n-/\n\n-- 0027\nexample (f : ℝ → ℝ) : non_decreasing f ↔ ∀ x y, x < y → f x ≤ f y :=\nbegin\n  -- sorry\n  split,\n  { intros hf x y hxy,\n    apply hf,\n    linarith, },\n  { intros hf x y hxy,\n    have clef : x = y ∨ x < y,\n    { exact eq_or_lt_of_le hxy },\n    cases clef with hxy hxy,\n    rw hxy,\n    exact hf x y hxy, },\n  -- sorry\nend\n\n/-\nIn the next exercise, we can use:\n  le_total x y : x ≤ y ∨ y ≤ x\n-/\n\n-- 0028\nexample (f : ℝ → ℝ) (h : non_decreasing f) (h' : ∀ x, f (f x) = x) : ∀ x, f x = x :=\nbegin\n  -- sorry\n  intro x,\n  have : f (f x) = x,\n  { rw h' },\n  have : (f x ≤ x) ∨ (x ≤ f x),\n  { exact le_total (f x) x },\n  cases this with hx hx,\n  { have f1: f (f x) ≤ f x,\n    { exact h (f x) x hx, },\n    rw h' at f1,\n    linarith, },\n  { have f1: f x ≤ f (f x),\n    { exact h x (f x) hx, },\n    rw h' x at f1,\n    linarith, },\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/03_forall_or.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291502, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7906903427050462}}
{"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 finite commutative ring `R`\niff it does not divide the characteristic. -/\nlemma is_unit_iff_not_dvd_char (R : Type*) [comm_ring R] [fintype R] (p : ℕ) [fact p.prime] :\n  is_unit (p : R) ↔ ¬ p ∣ ring_char R :=\nbegin\n  have hch := char_p.cast_eq_zero R (ring_char R),\n  split,\n  { rintros h₁ ⟨q, hq⟩,\n    rcases is_unit.exists_left_inv h₁ with ⟨a, ha⟩,\n    have h₃ : ¬ ring_char R ∣ q :=\n    begin\n      rintro ⟨r, hr⟩,\n      rw [hr, ← mul_assoc, mul_comm p, mul_assoc] at hq,\n      nth_rewrite 0 ← mul_one (ring_char R) at hq,\n      exact nat.prime.not_dvd_one (fact.out p.prime)\n             ⟨r, mul_left_cancel₀ (char_p.char_ne_zero_of_fintype R (ring_char R)) hq⟩,\n    end,\n    have h₄ := mt (char_p.int_cast_eq_zero_iff R (ring_char R) q).mp,\n    apply_fun (coe : ℕ → R) at hq,\n    apply_fun ((*) a) at hq,\n    rw [nat.cast_mul, hch, mul_zero, ← mul_assoc, ha, one_mul] at hq,\n    norm_cast at h₄,\n    exact h₄ h₃ hq.symm, },\n  { intro h,\n    rcases nat.is_coprime_iff_coprime.mpr ((nat.prime.coprime_iff_not_dvd (fact.out _)).mpr h)\n      with ⟨a, b, hab⟩,\n    apply_fun (coe : ℤ → 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/-- 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 : ℕ) [fact p.prime] :\n  p ∣ ring_char R ↔ p ∣ fintype.card R :=\nbegin\n  refine ⟨λ 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, λ h, _⟩,\n  by_contra h₀,\n  rcases exists_prime_add_order_of_dvd_card p h with ⟨r, hr⟩,\n  have hr₁ := add_order_of_nsmul_eq_zero r,\n  rw [hr, nsmul_eq_mul] at hr₁,\n  rcases is_unit.exists_left_inv ((is_unit_iff_not_dvd_char R p).mpr h₀) with ⟨u, hu⟩,\n  apply_fun ((*) u) at hr₁,\n  rw [mul_zero, ← mul_assoc, hu, one_mul] at hr₁,\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₁,\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 : ℕ) [fact p.prime]\n (hp : p ∣ fintype.card R) : ¬ 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": "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/char_and_card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.790690340115463}}
{"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 `∅`. 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 `∅ : set ℕ` and `∅ : set ℤ` 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 ∅ and univ\n\n`x ∈ ∅` is *by definition* equal to `false` and `x ∈ 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 ∈ (univ : set X) := \nbegin\n  sorry\nend\n\nexample : x ∈ (∅ : set X) → false :=\nbegin\n  sorry\nend\n\nexample : A ⊆ univ :=\nbegin\n  sorry\nend\n\nexample : ∅ ⊆ A :=\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/section05sets/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8807970779778824, "lm_q1q2_score": 0.7906873950241345}}
{"text": "/- LoVe Homework 10: Denotational Semantics -/\n\nimport .love10_denotational_semantics_demo\n\nnamespace LoVe\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\n/- The `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 by\n`fail`, and nondeterministic choice between two alternatives (identified by the\n`bool` values `tt` and `ff`) is represented by `choice`. -/\n\ninductive nondet (α : Type) : Type\n| pure    : α → nondet\n| fail {} : nondet\n| choice  : (bool → nondet) → nondet\n\nnamespace nondet\n\n\n/- Question 1: The `nondet` Monad -/\n\n/- The `nondet` inductive type forms a monad. The `pure` operator is\n`nondet.pure`; `bind` is as follows: -/\n\ndef bind {α β : Type} : nondet α → (α → nondet β) → nondet β\n| (pure x)   f := f x\n| fail       f := fail\n| (choice k) f := choice (λb, bind (k b) f)\n\ninstance : has_pure nondet := { pure := @pure }\ninstance : has_bind nondet := { bind := @bind }\n\n/- 1.1. Prove the monadic laws (lecture 6) for `nondet`.\n\nHint: To prove `f = g` from `∀x, f x = g x`, use the theorem `funext`. -/\n\nlemma pure_bind {α β : Type} (x : α) (f : α → nondet β) :\n  pure x >>= f = f x :=\nsorry\n\nlemma bind_pure {α : Type} :\n  ∀mx : nondet α, mx >>= pure = mx\n:= sorry\n\nlemma bind_assoc {α β γ : Type} :\n  ∀(mx : nondet α) (f : α → nondet β) (g : β → nondet γ),\n    ((mx >>= f) >>= g) = (mx >>= (λa, f a >>= g))\n:= sorry\n\n/- The function `portmanteau` computes a portmanteau of two lists: A portmanteau\nof `xs` and `ys` has `xs` as a prefix and `ys` as a suffix, and they overlap. We\nuse `starts_with xs ys` to test that `ys` has `xs` as a prefix. -/\n\ndef starts_with : list ℕ → list ℕ → 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 ℕ → list ℕ → list (list ℕ)\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 (**optional**). Translate the `portmanteau` program from the `list` monad\nto the `nondet` monad. -/\n\ndef nondet_portmanteau : list ℕ → list ℕ → nondet (list ℕ)\n:= sorry\n\n\n/- Question 2: Nondeterminism, Denotationally -/\n\n/- 2.1. Give a denotational semantics for `nondet`, mapping it into a `list` of\nall results. `pure` returns one result, `fail` returns zero, and `choice`\ncombines the results of either alternative. -/\n\ndef list_sem {α : Type} : nondet α → list α\n:= sorry\n\n/- Check that the following lines give the same output as for `portmanteau`: -/\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. Often, we are not interested in getting all outcomes, just the first\nsuccessful one. Give a semantics for `nondet` that produces the first successful\nresult, if any. -/\n\ndef option_sem {α : Type} : nondet α → option α\n:= sorry\n\n/- 2.3. Prove the theorem `list_option_compat` below, showing that the two\nsemantics you defined are compatible. -/\n\nlemma head'_orelse_eq_head'_append {α : Type} (xs ys : list α) :\n  (list.head' xs <|> list.head' ys) = list.head' (xs ++ ys) :=\nby induction xs; simp\n\ntheorem list_option_compat {α : Type} :\n  ∀mx : nondet α, option_sem mx = list.head' (list_sem mx)\n:= sorry\n\n\n/- Question 3 (**optional**). Nondeterminism, Operationally -/\n\n/- We can define the following big-step operational semantics for `nondet`: -/\n\ninductive big_step {α : Type} : nondet α → α → Prop\n| pure {x : α} :\n  big_step (pure x) x\n| choice_l {k : bool → nondet α} {x : α} :\n  big_step (k ff) x → big_step (choice k) x\n| choice_r {k : bool → nondet α} {x : α} :\n  big_step (k tt) x → big_step (choice k) x\n-- there is no case for `fail`\n\nnotation mx `⟹` x := big_step mx x\n\n/- 3.1 (**optional**). Prove the following lemma.\n\nThe lemma states that `choice` has the semantics of \"angelic nondeterminism\": If\nthere is a computational path that leads to some `x`, the `choice` operator will\nproduce this `x`. -/\n\nlemma choice_existential {α : Type} (x : α) (k : bool → nondet α) :\n  nondet.choice k ⟹ x ↔ ∃b, k b ⟹ x :=\nsorry\n\n/- 3.2 (**optional**). Prove the compatibility between denotational and\noperational semantics. -/\n\ntheorem den_op_compat {α : Type} :\n  ∀(x : α) (mx : nondet α), x ∈ list_sem mx ↔ mx ⟹ x\n:= sorry\n\nend nondet\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_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8807970654616711, "lm_q1q2_score": 0.7906873693239448}}
{"text": "import data.real.basic\nopen classical\nopen tactic\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    ∀ ε > 0, ∃ N, n ≥ N → |x_n - l| < ε\n-/\n\ndef lim_to_inf (x : ℕ → ℝ) (l : ℝ) :=\n  ∀ ε > 0, ∃ N, ∀ n ≥ N, abs (x n - l) < ε\n\ntheorem help (x y z : ℝ) (h1 : x ≤ y) (h2 : y ≤ z) :  abs (y - x) ≤ abs (z - x) :=\nbegin\n    have key : (y - x) ≤ (z - x),\n        exact sub_le_sub_right h2 x,\n    have h1 : 0 ≤ (y - x),\n        linarith,\n    apply abs_le_abs key _,\n    linarith\nend\n\ntheorem help' (x y z : ℝ) (h1 : x ≤ y) (h2 : y ≤ z) :  abs (z - y) ≤ abs (z - x) :=\nbegin\n    have key : (-x ≥ -y) ∧ (-y ≥ -z) := ⟨by linarith, by linarith⟩,\n    have key' : abs (-y - (-z)) ≤ abs (-x - (-z)),\n        exact help _ _ _ key.2 key.1,\n    simp only [neg_sub_neg] at key',\n    assumption,\nend\n\ntheorem exercise_1p2 (x y : ℕ → ℝ) (l : ℝ)\n  (h₁ : ∀ n, x n ≤ l ∧ l ≤ y n)\n  (h₂ : lim_to_inf (λ n, x n - y n) 0) :\n  lim_to_inf x l ∧ lim_to_inf y l := \nbegin\n    split,\n    {\n        intros ε ε_pos,\n        rcases h₂ ε ε_pos with ⟨N, hN⟩,\n        use N,\n        intros n hn,\n        have key : abs (l - x n) ≤ abs (y n - x n),\n            exact help _ _ _ (h₁ n).1 (h₁ n).2,\n        specialize hN n hn,\n        simp only [sub_zero] at hN,\n        calc \n        abs (x n - l) = abs (l - x n) : abs_sub (x n) l\n        ... ≤ abs (y n - x n)         : key\n        ... = abs (x n - y n)         : abs_sub (y n) (x n)\n        ... < ε                       : hN,\n    },\n    {\n    intros ε ε_pos,\n        rcases h₂ ε ε_pos with ⟨N, hN⟩,\n        use N,\n        intros n hn,\n        have key : abs (y n - l) ≤ abs (y n - x n),\n            exact help' _ _ _ (h₁ n).1 (h₁ n).2,\n        specialize hN n hn,\n        simp only [sub_zero] at hN,\n        calc \n        abs (y n - l) ≤ abs (y n - x n) : key\n        ... = abs (x n - y n)           : abs_sub (y n) (x n)\n        ... < ε                         : hN,\n    }\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_seq1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7905833507872277}}
{"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\n! This file was ported from Lean 3 source module data.int.nat_prime\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.Data.Nat.Prime\n\n/-!\n# Lemmas about `Nat.Prime` using `Int`s\n-/\n\n\nopen Nat\n\nnamespace Int\n\ntheorem not_prime_of_int_mul {a b : ℤ} {c : ℕ} (ha : 1 < a.natAbs) (hb : 1 < b.natAbs)\n    (hc : a * b = (c : ℤ)) : ¬Nat.Prime c :=\n  not_prime_mul' (natAbs_mul_natAbs_eq hc) ha hb\n#align int.not_prime_of_int_mul Int.not_prime_of_int_mul\n\ntheorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : Nat.Prime p) {m n : ℤ}\n    {k l : ℕ} (hpm : ↑(p ^ k) ∣ m) (hpn : ↑(p ^ l) ∣ n) (hpmn : ↑(p ^ (k + l + 1)) ∣ m * n) :\n    ↑(p ^ (k + 1)) ∣ m ∨ ↑(p ^ (l + 1)) ∣ n :=\n  have hpm' : p ^ k ∣ m.natAbs := Int.coe_nat_dvd.1 <| Int.dvd_natAbs.2 hpm\n  have hpn' : p ^ l ∣ n.natAbs := Int.coe_nat_dvd.1 <| Int.dvd_natAbs.2 hpn\n  have hpmn' : p ^ (k + l + 1) ∣ m.natAbs * n.natAbs := by\n    rw [← Int.natAbs_mul]; apply Int.coe_nat_dvd.1 <| Int.dvd_natAbs.2 hpmn\n  let hsd := Nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn'\n  hsd.elim (fun hsd1 => Or.inl (by apply Int.dvd_natAbs.1; apply Int.coe_nat_dvd.2 hsd1))\n    fun hsd2 => Or.inr (by apply Int.dvd_natAbs.1; apply Int.coe_nat_dvd.2 hsd2)\n#align int.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul Int.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul\n\ntheorem Prime.dvd_natAbs_of_coe_dvd_sq {p : ℕ} (hp : p.Prime) (k : ℤ) (h : (p : ℤ) ∣ k ^ 2) :\n    p ∣ k.natAbs := by\n  apply @Nat.Prime.dvd_of_dvd_pow _ _ 2 hp\n  rwa [sq, ← natAbs_mul, ← coe_nat_dvd_left, ← sq]\n#align int.prime.dvd_nat_abs_of_coe_dvd_sq Int.Prime.dvd_natAbs_of_coe_dvd_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/Data/Int/NatPrime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7905833444143145}}
{"text": "import .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 `α` stored in the tree and\notherwise preserve the tree's structure. -/\n\ndef map_btree {α β : Type} (f : α → β) : btree α → btree β\n| btree.empty        := btree.empty\n| (btree.node a l r) := btree.node (f a) (map_btree l) (map_btree r)\n\n/-! 1.2 (1 point). Prove the following lemma about your `map_btree` function. -/\n\nlemma map_btree_iden {α : Type} :\n  ∀t : btree α, map_btree (λa, a) t = t\n| btree.empty        := by refl\n| (btree.node a l r) := by simp [map_btree, map_btree_iden l, map_btree_iden r]\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 : ℕ → ℕ → ℕ\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 : ℕ) :\n  accufact 1 n = fact n :=\nhave accufact_eq_fact_mul : ∀m a, accufact a m = fact m * a :=\n  begin\n    intros m a,\n    induction' m,\n    case zero {\n      simp [fact, accufact] },\n    case succ {\n      simp [fact, accufact, ih],\n      cc }\n  end,\nby simp [accufact_eq_fact_mul n 1]\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/-! The generalized lemma we prove is `∀n a, accufact a n = fact n * a`.\n\nWe perform the proof by structural (mathematical) induction on `n`,\ngeneralizing `a`.\n\nCase 0: The goal is `accufact a 0 = fact 0 * a`. The left-hand side is `a` by\ndefinition of `accufact`. The right-hand side is `a` by definition of `fact` and\n`*`.\n\nCase `m + 1`: The goal is `accufact a (m + 1) = fact (m + 1) * a`. The induction\nhypothesis is `∀a, accufact a m = fact m * a`.\n\nLet us simplify the goal's left-hand side:\n\n      accufact a (m + 1)\n    = accufact ((m + 1) * a) m   -- by definition of `accufact`\n    = fact m * ((m + 1) * a)     -- by the induction hypothesis\n    = fact m * (m + 1) * a       -- by associativity of `*`\n\nNow let us massage the right-hand side so that it matches the simplified\nleft-hand side:\n\n      fact (m + 1) * a\n    = (m + 1) * fact m * a       -- by definition of `fact`\n    = fact m * (m + 1) * a       -- by commutativity of `*`\n\nThe two sides are equal.\n\nThe desired property follows from the generalized lemma by setting `a` to be `1`\nand by simplifying away `* 1`. QED -/\n\n\n/-! ## Question 3 (3 points): Gauss's Summation Formula -/\n\n-- `sum_upto f n = f 0 + f 1 + ⋯ + f n`\ndef sum_upto (f : ℕ → ℕ) : ℕ → ℕ\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  ∀m : ℕ, 2 * sum_upto (λi, i) m = m * (m + 1)\n| 0       := by refl\n| (m + 1) :=\n  begin\n    simp [sum_upto, sum_upto_eq m, add_mul, mul_add],\n    linarith\n  end\n\n/-! 3.2 (1 point). Prove the following property of `sum_upto`. -/\n\nlemma sum_upto_mul (f g : ℕ → ℕ) :\n  ∀n : ℕ, sum_upto (λi, f i + g i) n = sum_upto f n + sum_upto g n\n| 0       := by refl\n| (n + 1) :=\n  begin\n    simp [sum_upto, sum_upto_mul n],\n    cc\n  end\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/love04_functional_programming_homework_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7905349238046}}
{"text": "/-\nCopyright (c) 2021 Matt Kempster. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Matt Kempster\n-/\nimport geometry.euclidean.triangle\n\n/-!\n# Freek № 57: Heron's Formula\n\nThis file proves Theorem 57 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/),\nalso known as Heron's formula, which gives the area of a triangle based only on its three sides'\nlengths.\n\n## References\n\n* https://en.wikipedia.org/wiki/Herons_formula\n\n-/\n\nopen real euclidean_geometry\nopen_locale real euclidean_geometry\n\nlocal notation `√` := real.sqrt\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space ℝ V] [metric_space P] [normed_add_torsor V P]\n\ninclude V\n\n/-- **Heron's formula**: The area of a triangle with side lengths `a`, `b`, and `c` is\n  `√(s * (s - a) * (s - b) * (s - c))` where `s = (a + b + c) / 2` is the semiperimeter.\n  We show this by equating this formula to `a * b * sin γ`, where `γ` is the angle opposite\n  the side `c`.\n -/\ntheorem heron {p1 p2 p3 : P} (h1 : p1 ≠ p2) (h2 : p3 ≠ p2) :\n  let a := dist p1 p2, b := dist p3 p2, c := dist p1 p3, s := (a + b + c) / 2 in\n  1/2 * a * b * sin (∠ p1 p2 p3) = √(s * (s - a) * (s - b) * (s - c)) :=\nbegin\n  intros a b c s,\n  let γ := ∠ p1 p2 p3,\n  obtain := ⟨(dist_pos.mpr h1).ne', (dist_pos.mpr h2).ne'⟩,\n  have cos_rule : cos γ = (a * a + b * b - c * c) / (2 * a * b) := by field_simp [mul_comm, a,\n    dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle p1 p2 p3],\n  let numerator := (2*a*b)^2 - (a*a + b*b - c*c)^2,\n  let denominator := (2*a*b)^2,\n  have split_to_frac : 1 - cos γ ^ 2 = numerator / denominator := by field_simp [cos_rule],\n  have numerator_nonneg : 0 ≤ numerator,\n  { have frac_nonneg: 0 ≤ numerator / denominator := by linarith [split_to_frac, cos_sq_le_one γ],\n    cases div_nonneg_iff.mp frac_nonneg,\n    { exact h.left },\n    { simpa [h1, h2] using le_antisymm h.right (sq_nonneg _) } },\n  have ab2_nonneg : 0 ≤ (2 * a * b) := by norm_num [mul_nonneg, dist_nonneg],\n  calc  1/2 * a * b * sin γ\n      = 1/2 * a * b * (√numerator / √denominator) : by rw [sin_eq_sqrt_one_sub_cos_sq,\n                                                          split_to_frac, sqrt_div numerator_nonneg];\n                                                      simp [angle_nonneg, angle_le_pi]\n  ... = 1/4 * √((2*a*b)^2 - (a*a + b*b - c*c)^2)  : by { field_simp [ab2_nonneg], ring }\n  ... = 1/4 * √(s * (s-a) * (s-b) * (s-c) * 4^2)  : by { simp only [s], ring_nf }\n  ... = √(s * (s-a) * (s-b) * (s-c))              : by rw [sqrt_mul', sqrt_sq, div_mul_eq_mul_div,\n                                                          one_mul, mul_div_cancel];\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/archive/100-theorems-list/57_herons_formula.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7904951817431854}}
{"text": "\nimport order.boolean_algebra \nimport tactic \nopen boolean_algebra \n\nvariables {α : Type*}[boolean_algebra α]\n\n\n@[simp] def symm_diff (X Y : α) : α := (X \\ Y) ⊔ (Y \\ X) \n@[simp] lemma sdiff_def {X Y : α} : X \\ Y = X ⊓ Yᶜ := sdiff_eq \n\n-- commutativity/associativity with explicit arguments for easier rewriting \nlemma inf_comm' (X Y : α) : X ⊓ Y = Y ⊓ X := by apply inf_comm \nlemma inf_assoc' (X Y Z : α) : X ⊓ Y ⊓ Z = X ⊓ (Y ⊓ Z) := by apply inf_assoc  \n\nlemma inf_right_comm (X Y Z : α) : X ⊓ Y ⊓ Z = X ⊓ Z ⊓ Y := \n  by rw [inf_assoc, inf_comm' Y, ←inf_assoc]\n\nlocal attribute [simp] symm_diff sdiff_eq \n\nlemma symm_diff_comm (X Y : α) : symm_diff X Y = symm_diff Y X := \n  by simp [sup_comm] \n\n-- 'Normal form' for associativity \nlemma symm_diff_three (X Y Z : α) : \n  symm_diff (symm_diff X Y) Z = X ⊓ Yᶜ ⊓ Zᶜ ⊔ Y ⊓ Xᶜ ⊓ Zᶜ ⊔ (Z ⊓ (Xᶜ ⊓ Yᶜ) ⊔ Z ⊓ (Y ⊓ X)) :=\nbegin\n  simp only [symm_diff, sdiff_def, inf_sup_right, compl_sup,compl_inf,compl_compl'],\n  repeat {rw inf_sup_left},\n  repeat {rw inf_sup_right},\n  rw [inf_compl_eq_bot, inf_comm' Xᶜ X, inf_compl_eq_bot], \n  simp, \nend\n\nlemma symm_diff_assoc (X Y Z : α) : 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 [inf_comm' Y Xᶜ, inf_comm' Z, inf_comm' Z, inf_comm' Y X, inf_right_comm Y, \n      inf_assoc' Z, inf_comm' Y, inf_comm' Z, inf_comm' Yᶜ, inf_comm' Z Y],\n    nth_rewrite 1 ←sup_assoc, \n    nth_rewrite 4 sup_comm,  \n    repeat {rw ←sup_assoc},\n    repeat {rw ←inf_assoc},\nend\n\nlemma inf_distrib_diff (X Y Z : α) : X ⊓ (Y \\ Z) = (X ⊓ Y) \\ (X ⊓ Z) := \n  by {simp only [sdiff_def, compl_inf, inf_sup_left], rw [inf_right_comm _ Y, ←inf_assoc], simp,  }\n\nlemma symm_diff_distrib_inf_left (X Y Z : α): X ⊓ (symm_diff Y Z)  = symm_diff (X ⊓ Y) (X ⊓ Z) := \n  by simp only [symm_diff, inf_sup_left, inf_sup_right, inf_distrib_diff] \n    \nlemma symm_diff_distrib_inf_right (X Y Z : α): (symm_diff X Y) ⊓ Z  = symm_diff (X ⊓ Z) (Y ⊓ Z) := \n  by {rw [inf_comm', inf_comm' X, inf_comm' Y], apply symm_diff_distrib_inf_left}\n\nlemma symm_diff_inter (X Y : α) : \n  symm_diff X (X ⊓ Y) = X \\ Y := \n  by simp [inf_right_comm X Y, ←inf_assoc' _ Xᶜ, inf_sup_left]\n\nlemma sup_sdiff (X Y : α) : \n  X ⊔ (X \\ Y) = X :=\n  by simp  \n\nlemma top_symm_diff (X : α) : \n  symm_diff ⊤ X = Xᶜ := \n  by simp \n\nlemma symm_diff_self (X : α) : \n  symm_diff X X = ⊥ := \n  by simp \n\n@[simp] lemma bot_diff (X : α) :\n  ⊥ \\ X = ⊥ := \n  by simp\n\n@[simp] lemma diff_bot (X : α) :\n  X \\ ⊥ = X := \n  by simp  \n\n@[simp] lemma le_iff_inf (X Y : α) : \n  X ≤ Y ↔ X ⊓ Y = X := \n  inf_eq_left.symm\n\n-----------------------------------------------\n\n@[simp] instance to_comm_ring : comm_ring α := \n{ \n  add := λ X Y, symm_diff X Y, \n  add_assoc := λ X Y Z, symm_diff_assoc X Y Z,\n  zero := ⊥,\n  zero_add := λ X, by simp [has_add.add],\n  add_zero := λ X, by simp [has_add.add],\n  neg := λ X, X, \n  add_left_neg := λ X, symm_diff_self X, \n  add_comm := λ X Y, symm_diff_comm X Y, \n  mul := λ X Y, X ⊓ Y,\n  mul_assoc := λ X Y Z, inf_assoc,\n  one := ⊤,\n  one_mul := λ X, top_inf_eq,\n  mul_one := λ X, inf_top_eq,\n  left_distrib := λ X Y Z, symm_diff_distrib_inf_left X Y Z,\n  right_distrib := λ X Y Z, symm_diff_distrib_inf_right X Y Z, \n  mul_comm := λ X Y, inf_comm, \n}\n\nlemma one_add (X : α) : 1 + X = Xᶜ := \n  top_symm_diff X \n\nlemma add_one (X : α) : X + 1 = Xᶜ := \n  by {rw add_comm, from top_symm_diff X} \n\n------------------------------- Translate to ring notation --------------------------------\n\nlemma top_to_ring: (⊤ : α) = (1 : α) := rfl\n\nlemma bot_to_ring : (⊥ : α) = (0 : α):= rfl\n\nlemma symm_diff_to_ring {X Y : α} : (X \\ Y) ⊔ (Y \\ X) = X + Y := rfl \n\nlemma inf_to_ring {X Y : α} : X ⊓ Y = X * Y := rfl \n\nlemma sup_to_ring {X Y : α} : X ⊔ Y = (X + Y) + X*Y := \nbegin \n  rw [add_assoc], \n  nth_rewrite 1 ←one_mul Y, \n  rw [←right_distrib, one_add, ←symm_diff_to_ring, ←inf_to_ring],\n  rw [sdiff_def, sdiff_def, inf_right_comm, compl_inf, inf_sup_left], \n  simp only [compl_compl', inf_idem],\n  rw [←sdiff_def, inf_comm' Xᶜ, ←sdiff_def, sup_sdiff, sup_sdiff_same], \nend \n\nlemma compl_to_ring {X : α} : \n  Xᶜ = X + 1 := \n  (add_one X).symm \n\nlemma le_to_ring {X Y : α} : \n  X ≤ Y ↔ X*Y = X := \n  by {rw ←inf_to_ring, from inf_eq_left.symm} \n\nlemma diff_to_ring {X Y : α} : \n  X \\ Y = X*(Y + 1) := \n  by rw [add_one, ←inf_to_ring, sdiff_def]\n\n-------------------------------------------------------------------------------------------\n\n\n@[simp] lemma mul_idem (X : α): \n  X*X = X := \n  inf_idem \n\n@[simp] lemma two_eq_zero : \n  (2 : α) = (0 : α) := \n  let h : (2:α) = (1:α) + (1:α) := rfl in\n  by rw [h, one_add, ←top_to_ring, ←bot_to_ring, compl_top]\n\n@[simp] lemma add_self (X : α): \n  X + X = 0 := \n  by {ring SOP, rw two_eq_zero, from mul_zero X}\n\n\n@[simp] lemma prod_comp_cancel (X : α) : X*(X+1) = 0 := \n  by {ring SOP, simp}\n\nlemma no_inverses_left {X Y : α} : \n  X*Y = 1 → X = 1 :=\n  λ h, by {rw [←(mul_one X)] , nth_rewrite 0 ←h, rw [←mul_assoc, mul_idem, h]}\n\n\n-------------------------------- Needed to make freealg tick ---------------------------------\n\nlemma expand_product {X₁ X₂ Y₁ Y₂ S : α} : \n  (X₁ * S + X₂ * (S+1)) * (Y₁ * S + Y₂ * (S+1)) = X₁ * Y₁ * S + X₂ * Y₂ * (S+1):=\n  begin\n    simp only [←mul_assoc, mul_comm _ S, prod_comp_cancel, mul_idem, left_distrib, \n                right_distrib, mul_one],\n    ring SOP, \n    simp [mul_comm, two_eq_zero, (by ring : (3:α) = (2:α) + (1:α)), mul_left_comm],\n  end\n\nlemma add_self_left (X Y : α):\n   X + (X + Y) = Y :=  \n   by rw [←add_assoc, add_self, zero_add]\n\n-----------------------------------------------------------------------------------------------\n\n------------------------------- Needed for internal tactic stuff ------------------------------\n\nlemma no_inverses (X Y : α) : \n  X * Y = 1 → (X = 1) ∧ (Y = 1) := \n  λ h, ⟨no_inverses_left h, by {rw mul_comm at h, from no_inverses_left h}⟩\n\nlemma bring_to_left {α : Type}[boolean_algebra α]{X Y : α} : \n  (X = Y) = (X + Y + 1 = 1) :=\n  begin\n    ext, split,\n    from λ h, by {rw [h, add_self], exact zero_add 1}, \n    intro h, \n    nth_rewrite 1 ←(add_self_left Y (1 :α)) at h, \n    rw add_assoc at h, \n    from (add_left_inj (Y + 1)).mp h\n  end\n\n------------------------------------------------------------------------------------------------", "meta": {"author": "apnelson1", "repo": "lean-set-tactic", "sha": "9f79d8adb5bc946d67831b3495ce723a60510ce0", "save_path": "github-repos/lean/apnelson1-lean-set-tactic", "path": "github-repos/lean/apnelson1-lean-set-tactic/lean-set-tactic-9f79d8adb5bc946d67831b3495ce723a60510ce0/old/make_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7904951803066959}}
{"text": "\nimport tactic --hide\n\nlemma not_iff_imp_false (P : Prop) : ¬ P ↔ P → false := iff.rfl -- hide\n\n/-\n##  Proof by contradiction. \n\nIn this level we will see why proofs by contradiction are valid. The key is to note that for any\nlogical statements `P,Q`, we have that ` P ∧ (¬ P) → Q` is true.\n\n-/\n\n/-Hint : Why is this true?\nWe have just seen that `P ∧ (¬ P)`is always false and `false → Q` is always true.\n-/\n\n/- Hint : Hint\nStart by introducing your assumption and then using `exfalso`.\n-/\n\n/- Lemma \nIf $P$ and $Q$ are logical statements, then\n$(P\\land(\\lnot P))\\implies Q.$\n-/\nlemma contra (P Q : Prop) : (P ∧ ¬ P) → Q :=\nbegin\n  intro h,\n  exfalso,\n  cases h with p np,\n  rw not_iff_imp_false at np,\n  apply np,\n  exact p,\n\n\nend\n\n/-Hint : Tip\nIf you want to use to use this result later on then you can type <mark style =\"background-color : #ebdef0 \">`apply (contra P Q)`</mark> where `P,Q` are\nthe assumptions you want to use. You can also use the tactic <mark style =\"background-color : #ebdef0 \">`by_contra`</mark>  \nto achieve similar results. \n\n-/\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/logic3/notlogic1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248123094437, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7904951741340449}}
{"text": "\n/--\nFrom Sets to Relations\n\nTake-away message. Whereas we represent a set\nas a one-place predicate, we will represent a\nbinary relation as a two-place predicate. Just\nas a set is a collection of individual objects\nthat satisfy a predicate, a relation is a set\nof *pairs* of objects, each of which satisfies\nthe pair membership predicate for the relation. \n--/\n\n/-\nExample: negation_as_a_binary_relation on bool.\n-/\n\ndef negation : bool → bool → Prop\n| tt ff := true\n| ff tt := true\n| _ _ := false\n\n/-\nThis predicate specifies the binary \nrelation, {(tt, ff), (ff, tt)}. Each\nmember of the relation is an ordered\npair of Boolean values. The relation\ncomprises the set of all of the pairs \nthat satisfy the predicate: make the\nresulting proposition true. Other pairs \nof Booleans do not satisfy the predicate\nand so are not in the relation that it\nspecifies. \n-/\n\n/-\n\nNote that unlike with the Boolean\nnegation function, bnot, we cannot\n\"compute\" with predicates; we can\nonly try to prove that a pair of \nvalues (in this case) satisfy them.\n-/\n\n-- functions compute\n#eval bnot tt   -- (tt, ff)\n#eval bnot ff   -- (ff, tt)\n-- takes a single bool, returns a bool\n\nexample : negation tt ff := \nbegin\nunfold negation,\nend \n\nexample : negation ff tt := by unfold negation -- Lean syntax\n\n-- takes two bools, returns a proposition\n-- that proposition then has to be proved \n-- can use \"by\" when script is a single tactic\n\nexample : ¬ negation tt tt :=\nbegin\nassume h,\ncases h,\nend \n\n/-\nExercise: Formally state and prove the proposition\nthat for all Boolean values, b1 and b2, negation b1 \nb2 ↔ bnot b1 = b2. This proposition claims that the\nbnot function applied to a Boolean value, b1, equals\nb2, if and only if the pair, (b1,b2), is \"in\" the\nnegation relation.   \n-/\n\n\nexample : ∀ (b1 b2), negation b1 b2 ↔ bnot b1 = b2 :=\nbegin\nassume b1 b2,\nsplit,\n\n-- forwards\nintro h,\n\ncases b1,\ncases b2,\n\n-- ff ff\ncases h,\n\n-- tt ff\nexact rfl,\n\ncases b2,\n\n-- tt ff\nexact rfl,\n\n-- tt tt\ncases h,\n\n-- backwards\n\nassume h,\n\n-- again by case analysis on b1 b2\n\ncases b1,\ncases b2,\n\ncases h,\nunfold negation,\n\ncases b2,\nunfold negation,\n\ncases h,\n\n\nend\n\n\n\nexample: ∀ (b1 b2), negation b1 b2 ↔ bnot b1 = b2 :=\nbegin\nassume b1 b2,\nsplit,\n-- What should be our proof strategy from here?\n-- Exercise: complete this proof.\nend \n\n\n/-\nNext idea: A binary relation can relate objects of \ndifferent types types. The last example was of a\nbinary relation relating bools to bools. Not let's\nintroduce a new data type, call it bit, with values\nbit.zero and bit.one, and the consider a relation\n\"between\" bools and bits, where a bool is either\ntt or ff and a bit is either zero or one. \n-/\n\ninductive bit \n| zero \n| one \n\n/-\nHere for fun is a function that takes a bit\nand returns the other bit. It's like bnot but\nfor bits.\n-/\n\ndef bit_flip : bit → bit \n| bit.zero := bit.one\n| bit.one := bit.zero\n\n/-\nNow let's define a relation from bool to bit\nthat associates tt with one and ff with zero.\n-/\n\ndef bool_to_bit_relation : bool → bit → Prop\n| tt bit.one := true\n| ff bit.zero := true\n| _ _ := false\n\n/-\nExercise: Draw a picture of this relation.\nExercise: Draw an adjacency matrix for this relation\n-/\n\n/-\nAs another concrete example, let's define the relation\nbetween natural numbers and their squares. We'll start\nby defining the square function. Then we'll define the\ncorresponding relation. They represent the same set of\nordered pairs, but the first computes and the second is\n\"declarative\" (computational vs. logical).\n-/\n\ndef square (n : ℕ) := n * n\n#eval square 25\n\n/-\nNow we specific the relevant set of pairs.\n-/\ndef squares (n m : ℕ) : Prop := square n = m \n\n/-\nWe can prove pairs that bear this relationship and\nnot ones that don't.\n-/\n\nexample : squares 0 0 := rfl\nexample : squares 1 1 := rfl\nexample : squares 2 3 := rfl    -- no can, dude\nexample : squares 2 4 := rfl\nexample : squares 25 625 := rfl\n\n/-\nExercise: define a predicate, call it \nstring2len,on strings and nats, such \nthat (s, n) ∈ string2len iff length \nof s is n.\n-/\n\ndef string2len : string → nat → Prop := \n  λ s n,          -- arguments\n  s.length = n    -- result (here a proposition)\n\n/-\nExercise: prove the proposition that the pair of\narguments, \"Lean!\" and 5, taken together, satisfy\nthe string2len predicate, and are thus considered\nto be a pair that in (a member of) the string2len\nrelation.  \n-/\nexample : string2len \"Lean!\" 5 :=   \nbegin\nunfold string2len,\nexact rfl,\nend\n/-\nThese ideas are prominent in database theory and\npractice. For example, the SELECT statement in a\nSQL database, e.g., mySQL, MariaDB, or PostgreSQL,\nselects the subset of records from a database with\nfield values that satisfy such a selection predicate.\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/03_relations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7904445222163893}}
{"text": "/-\nCopyright (c) 2022 Hans Parshall. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hans Parshall\n-/\nimport analysis.matrix\nimport analysis.normed_space.basic\nimport data.is_R_or_C.basic\nimport linear_algebra.unitary_group\n\n/-!\n# Unitary matrices\n\nThis file collects facts about the unitary matrices over `𝕜` (either `ℝ` or `ℂ`).\n-/\n\nopen_locale big_operators matrix\n\nvariables {𝕜 m n E : Type*}\n\nsection entrywise_sup_norm\nvariables [is_R_or_C 𝕜] [fintype n] [decidable_eq n]\n\nlemma entry_norm_bound_of_unitary {U : matrix n n 𝕜} (hU : U ∈ matrix.unitary_group n 𝕜) (i j : n):\n  ‖U i j‖ ≤ 1 :=\nbegin\n  -- The norm squared of an entry is at most the L2 norm of its row.\n  have norm_sum : ‖ U i j ‖^2 ≤ (∑ x, ‖ U i x ‖^2),\n  { apply multiset.single_le_sum,\n    { intros x h_x,\n      rw multiset.mem_map at h_x,\n      cases h_x with a h_a,\n      rw ← h_a.2,\n      apply sq_nonneg },\n    { rw multiset.mem_map,\n      use j,\n      simp only [eq_self_iff_true, finset.mem_univ_val, and_self, sq_eq_sq] } },\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ\n  have diag_eq_norm_sum : (U ⬝ Uᴴ) i i = ∑ (x : n), ‖ U i x ‖^2,\n  { simp only [matrix.mul_apply, matrix.conj_transpose_apply, ←star_ring_end_apply,\n               is_R_or_C.mul_conj, is_R_or_C.norm_sq_eq_def', is_R_or_C.of_real_pow] },\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ, real part\n  have re_diag_eq_norm_sum : is_R_or_C.re ((U ⬝ Uᴴ) i i) = ∑ (x : n), ‖ U i x ‖^2,\n  { rw is_R_or_C.ext_iff at diag_eq_norm_sum,\n    rw diag_eq_norm_sum.1,\n    norm_cast },\n  -- Since U is unitary, the diagonal entries of U ⬝ Uᴴ are all 1\n  have mul_eq_one : (U ⬝ Uᴴ) = 1, from unitary.mul_star_self_of_mem hU,\n  have diag_eq_one : is_R_or_C.re ((U ⬝ Uᴴ) i i) = 1,\n  { simp only [mul_eq_one, eq_self_iff_true, matrix.one_apply_eq, is_R_or_C.one_re] },\n  -- Putting it all together\n  rw [← sq_le_one_iff (norm_nonneg (U i j)), ← diag_eq_one, re_diag_eq_norm_sum],\n  exact norm_sum,\nend\n\nlocal attribute [instance] matrix.normed_add_comm_group\n\n/-- The entrywise sup norm of a unitary matrix is at most 1. -/\nlemma entrywise_sup_norm_bound_of_unitary {U : matrix n n 𝕜} (hU : U ∈ matrix.unitary_group n 𝕜) :\n  ‖ U ‖ ≤ 1 :=\nbegin\n  simp_rw pi_norm_le_iff_of_nonneg zero_le_one,\n  intros i j,\n  exact entry_norm_bound_of_unitary hU _ _\nend\n\nend entrywise_sup_norm\n", "meta": {"author": "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/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7903378480210486}}
{"text": "/-\n  Results about multivariate polynomials.\n-/\nimport data.mv_polynomial.basic\nimport data.matrix.basic \nimport lib.psd\n\nopen mv_polynomial matrix\n\nvariables {γ : Type*} [fintype γ]\nvariables {μ : Type*} [fintype μ]\nvariables {R : Type*} [linear_ordered_comm_ring R]\n\nnamespace poly\n\ninstance {σ R} [comm_semiring R] [has_le R] : has_le (mv_polynomial σ R) :=\n{ le := λ p q, ∀ v, eval v p ≤ eval v q }\n\n-- 1. eval of dot product is dot product of eval.\nlemma eval_dot_product (p q : γ → mv_polynomial ℕ R) (e : ℕ → R) \n: eval e (dot_product p q) = dot_product (λ i, eval e (p i)) (λ i, eval e (q i)) :=\nbegin \n  simp [dot_product], rw [eval_sum], congr, ext i, rw [(eval e).map_mul],\nend \n\nlemma eval_mul_vec (p : γ → mv_polynomial ℕ R) (M : matrix γ γ (mv_polynomial ℕ R)) \n  (e : ℕ → R) (i : γ)\n: eval e (mul_vec M p i) = mul_vec (λ i j, eval e (M i j)) (λ i, eval e (p i)) i :=\nbegin \n  simp [mul_vec, dot_product], rw [eval_sum], congr, ext l, rw [(eval e).map_mul],\nend \n\n-- 2. thus dot product same of poly is bigger than zero. \nlemma dot_product_self_nonneg (p : γ → mv_polynomial ℕ R)\n: 0 ≤ dot_product p p := \nbegin \n  intros e, rw [eval_dot_product p p e], simp [eval_C 0],\n  exact matrix.dot_product_self_nonneg _,\nend \n\nnoncomputable def matrix.to_poly (Q : matrix γ γ R) : matrix γ γ (mv_polynomial ℕ R) :=\nλ i j, C (Q i j)\n\n-- 3. thus cholesky of polynomial means poly is nonneg. \nlemma nonneg_of_cholesky \n  (p : mv_polynomial ℕ R) \n  (ms : γ → mv_polynomial ℕ R)\n  (Q : matrix γ γ R)\n  (hQ : symmetric Q)\n  (hp : p = dot_product ms (mul_vec (matrix.to_poly Q) ms))\n  (hcholesky : @cholesky_decomposition γ _ μ _ R _ Q hQ)\n: C 0 ≤ p := \nbegin \n  intros e, rw [hp, eval_dot_product _ _ e],\n  have : (λ i, (eval e) (mul_vec (λ i j, C (Q i j)) ms i)) = \n         λ i, mul_vec Q (λ i, eval e (ms i)) i,\n  { funext i, rw eval_mul_vec ms _ e i, congr, ext l m, exact eval_C _, },\n  simp [eval_C 0, matrix.to_poly], rw this, \n  obtain ⟨L, hL⟩ := hcholesky,\n  rw hL,\n  rw dot_product_transpose,\n  exact matrix.dot_product_self_nonneg _,\nend\n\nend poly \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/lib/poly.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813457476621, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7903210493596196}}
{"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.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## Tags\nwalks, trails, paths, circuits, cycles\n\n-/\n\nuniverses u\n\nnamespace simple_graph\nvariables {V : Type u} (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 → V → 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) := ⟨by refl⟩\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 : Π {u v : V} (hne : u ≠ v) (p : G.walk u v),\n  ∃ (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') := ⟨_, h, p', rfl⟩\n\n/-- The length of a walk is the number of edges/darts along it. -/\ndef length : Π {u v : V}, G.walk u v → ℕ\n| _ _ nil := 0\n| _ _ (cons _ q) := q.length.succ\n\n/-- The concatenation of two compatible walks. -/\n@[trans]\ndef append : Π {u v w : V}, G.walk u v → G.walk v w → 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 : Π {u v w : V}, G.walk u v → G.walk u w → 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 : Π {u v : V} (p : G.walk u v) (n : ℕ), 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 : ℕ} (hi : w.length ≤ 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 : ℕ} (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 : Π {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 : Π {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 : Π {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 : Π {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 : Π {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 : Π {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 : Π {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 : Π {u v : V} {p : G.walk u v}, p.length = 0 → u = v\n| _ _ nil _ := rfl\n\n@[simp] lemma exists_length_eq_zero_iff {u v : V} : (∃ (p : G.walk u v), p.length = 0) ↔ u = v :=\nbegin\n  split,\n  { rintro ⟨p, hp⟩,\n    exact eq_of_length_eq_zero hp, },\n  { rintro rfl,\n    exact ⟨nil, rfl⟩, },\nend\n\n/-- The `support` of a walk is the list of vertices it visits in order. -/\ndef support : Π {u v : V}, G.walk u v → 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 : Π {u v : V}, G.walk u v → list G.dart\n| u v nil := []\n| u v (cons h p) := ⟨(u, _), h⟩ :: 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 ≠ [] :=\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 ∈ p.support :=\nby cases p; simp\n\n@[simp] lemma end_mem_support {u v : V} (p : G.walk u v) : v ∈ p.support :=\nby induction p; simp [*]\n\nlemma mem_support_iff {u v w : V} (p : G.walk u v) :\n  w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail :=\nby cases p; simp\n\nlemma mem_support_nil_iff {u v : V} : u ∈ (nil : G.walk v v).support ↔ 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 ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ 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 ≠ v) (p : G.walk u v) :\n  v ∈ p.support.tail :=\nby { obtain ⟨_, _, _, rfl⟩ := 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 ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ 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, ←multiset.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, ←multiset.coe_add],\n  simp only [coe_support],\n  rw add_comm {v},\n  simp only [← add_assoc, add_tsub_cancel_right],\nend\n\nlemma chain_adj_support : Π {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 : Π {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 : Π {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 : Π {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 `⊆`) to avoid unsightly coercions. -/\nlemma edges_subset_edge_set : Π {u v : V} (p : G.walk u v) ⦃e : sym2 V⦄\n  (h : e ∈ p.edges), e ∈ G.edge_set\n| _ _ (cons h' p') e h := by rcases h with ⟨rfl, h⟩; 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 = ⟨(u, v), h⟩ :: 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 = ⟦(u, v)⟧ :: 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  Π {u v : V} (p : G.walk u v) {d : G.dart}, d ∈ p.darts → d.fst ∈ p.support\n| u v (cons h p') d hd := begin\n  simp only [support_cons, darts_cons, list.mem_cons_iff] at hd ⊢,\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  Π {u v : V} (p : G.walk u v) {d : G.dart}, d ∈ p.darts → d.snd ∈ p.support\n| u v (cons h p') d hd := begin\n  simp only [support_cons, darts_cons, list.mem_cons_iff] at hd ⊢,\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 : ⟦(t, u)⟧ ∈ p.edges) :\n  t ∈ p.support :=\nbegin\n  obtain ⟨d, hd, he⟩ := list.mem_map.mp he,\n  rw dart_edge_eq_mk_iff' at he,\n  rcases he with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩,\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 ⊢,\n    refine ⟨λ h', h.1 (dart_fst_mem_support_of_mem_darts p_p h'), p_ih h.2⟩, }\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 ⊢,\n    exact ⟨λ h', h.1 (mem_support_of_mem_edges p_p h'), p_ih h.2⟩, }\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 ≠ 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 ↔ p.edges.nodup :=\n⟨is_trail.edges_nodup, λ h, ⟨h⟩⟩\n\nlemma is_path.mk' {u v : V} {p : G.walk u v} (h : p.support.nodup) : is_path p :=\n⟨⟨edges_nodup_of_support_nodup h⟩, h⟩\n\nlemma is_path_def {u v : V} (p : G.walk u v) : p.is_path ↔ p.support.nodup :=\n⟨is_path.support_nodup, is_path.mk'⟩\n\nlemma is_cycle_def {u : V} (p : G.walk u u) :\n  p.is_cycle ↔ is_trail p ∧ p ≠ nil ∧ p.support.tail.nodup :=\niff.intro (λ h, ⟨h.1.1, h.1.2, h.2⟩) (λ h, ⟨⟨h.1, h.2.1⟩, h.2.2⟩)\n\n@[simp] lemma is_trail.nil {u : V} : (nil : G.walk u u).is_trail :=\n⟨by simp [edges]⟩\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 → 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 ↔ p.is_trail ∧ ⟦(u, v)⟧ ∉ 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 ↔ 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 ⟨h.1⟩ }\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 ⟨h.2.1⟩ }\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 ≤ 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 ∈ 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 → 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 ↔ p.is_path ∧ u ∉ 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 ↔ 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 → 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 ←is_path_reverse_iff at h ⊢,\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 : Π {v w : V} (p : G.walk v w) (u : V) (h : u ∈ 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 (λ 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 : Π {v w : V} (p : G.walk v w) (u : V) (h : u ∈ 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 (λ 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 ∈ 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 ∈ 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 ∈ p.support) (x : V) :\n  (p.take_until u h).edges.count ⟦(u, x)⟧ ≤ 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 (⟨rfl,rfl⟩|⟨rfl,rfl⟩) := 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 ∈ p.support) :\n  (p.take_until u h).support ⊆ p.support :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.drop_until u h).support ⊆ p.support :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.take_until u h).darts ⊆ p.darts :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.drop_until u h).darts ⊆ p.darts :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.take_until u h).edges ⊆ 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 ∈ p.support) :\n  (p.drop_until u h).edges ⊆ 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 ∈ p.support) :\n  (p.take_until u h).length ≤ 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 ∈ p.support) :\n  (p.drop_until u h).length ≤ 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 ∈ p.support) :\n  (p.take_until u h).is_trail :=\nis_trail.of_append_left (by rwa ← 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 ∈ p.support) :\n  (p.drop_until u h).is_trail :=\nis_trail.of_append_right (by rwa ← 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 ∈ p.support) :\n  (p.take_until u h).is_path :=\nis_path.of_append_left (by rwa ← 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 ∈ p.support) :\n  (p.drop_until u h).is_path :=\nis_path.of_append_right (by rwa ← 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 ∈ 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 ∈ 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 [←tail_support_append, take_spec],\nend\n\nlemma rotate_darts {u v : V} (c : G.walk v v) (h : u ∈ 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 [←darts_append, take_spec],\nend\n\nlemma rotate_edges {u v : V} (c : G.walk v v) (h : u ∈ 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 ∈ 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 ∈ c.support) :\n  (c.rotate h).is_circuit :=\nbegin\n  refine ⟨hc.to_trail.rotate _, _⟩,\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, ← 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 ∈ c.support) :\n  (c.rotate h).is_cycle :=\nbegin\n  refine ⟨hc.to_circuit.rotate _, _⟩,\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 : Π {u v : V}, G.walk u v → 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 ∈ 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 ≤ 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 := ⟨p.bypass, p.bypass_is_path⟩\n\nlemma support_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.support ⊆ 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 ⊆ p.support :=\nsupport_bypass_subset _\n\nlemma darts_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.darts ⊆ 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 ⊆ 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 ⊆ 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 ⊆ p.edges :=\nedges_bypass_subset _\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 ↔ (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 → 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 → p) : p :=\nbegin\n  classical,\n  exact h.elim (λ q, hp q.to_path),\nend\n\n@[refl] protected lemma reachable.refl {u : V} : G.reachable u u := by { fsplit, refl }\n\n@[symm] protected lemma reachable.symm {u v : V} (huv : G.reachable u v) : G.reachable v u :=\nhuv.elim (λ p, ⟨p.reverse⟩)\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 (λ puv, hvw.elim (λ pvw, ⟨puv.append pvw⟩))\n\nlemma reachable_iff_refl_trans_gen (u v : V) :\n  G.reachable u v ↔ relation.refl_trans_gen G.adj u v :=\nbegin\n  split,\n  { rintro ⟨h⟩,\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 ⟨walk.cons ha walk.nil⟩, }, },\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 := ∀ (u v : V), G.reachable u v\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 (λ _, Π (u v : V), G.reachable u v) :=\n⟨λ h, h.preconnected⟩\n\n/-- A subgraph is connected if it is connected as a simple graph. -/\nabbreviation subgraph.connected {G : simple_graph V} (H : G.subgraph) : Prop := H.coe.connected\n\nvariables {G}\n\nlemma preconnected.set_univ_walk_nonempty (hconn : G.preconnected) (u v : V) :\n  (set.univ : set (G.walk u v)).nonempty :=\nby { rw ← 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\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/connectivity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7901263317711279}}
{"text": "/-\nlayout: post\ntitle: \"Graph Coloring Basics\"\ndate: 2022-01-09\ncategories: graph\n\nPrelude:\n\n* [Graph homomorphism](https://en.wikipedia.org/wiki/Graph_homomorphism)\n* [NP-hardness](https://en.wikipedia.org/wiki/NP-hardness)\n\n# Graph Coloring Basics\n\nIn Graph Theory, finding a proper coloring of a graph consists of attributing \"colors\"\nto its vertices in a way that adjacent vertices have different colors.\n\n[In Lean](https://github.com/leanprover-community/mathlib/pull/10287), a coloring (short\nfor \"proper coloring\") is represented as a homomorphism from the graph being colored to\nthe complete graph of available colors. Let's seen an example of how this works.\n\nSuppose we have a graph `G` that we want to color with three colors: `c₁`, `c₂` and `c₃`.\n\n```\n      G            Complete graph of colors\n  D-------A                   c₁\n  |       | \\                /  \\\n  |       |  C              c₂---c₃\n  |       | /\n  E-------B\n```\n\nThe following mapping can be seen as a coloring of `G`:\n\n```\nA → c₁\nB → c₂\nC → c₃\nD → c₂\nE → c₃\n```\n\nNow note that this mapping is in fact a homomorphism. And you may wonder, why does such\na homomorphism represent a coloring?\n\nInformally, consider two adjacent vertices in G. Since our mapping is a homomorphism,\nthose vertices must be mapped to adjacent vertices in the complete graph of colors.\nAnd such adjacent vertices represent different colors.\n\nYou can check Mathlib's formalization of the above [here](https://leanprover-community.github.io/mathlib_docs/combinatorics/simple_graph/coloring.html#simple_graph.coloring.valid).\n\nLet's play with the API a bit.\n-/\n\nimport combinatorics.simple_graph.coloring\nimport tactic.derive_fintype\n\n/-\nDeriving `decidable_eq` and `fintype` will allow us to prove some results\nwith `dec_trivial`.\n-/\n\n@[derive [decidable_eq, fintype]]\ninductive verts : Type\n| A | B | C | D | E\n\nopen verts\n\ndef edges : list (verts × verts) :=\n[ (A, B), (B, C), (A, C), (A, D), (D, E), (B, E) ]\n\n/- This function tells whether two vertices are adjacent. -/\n\ndef adj (v w : verts) : bool := edges.mem (v, w) || edges.mem (w, v)\n\n/-\nThe `simple_graph` API requires a `Prop` for adjacency. So we need to coerce\nour `bool` function to a `Prop` one:\n-/\n\ndef adj_prop (v w : verts) : Prop := adj v w\n\n/- The following proofs are required to construct a `simple_graph`: -/\n\nlemma adj_symmetric : ∀ (x y : verts), adj x y → adj y x := dec_trivial\nlemma adj_loopless : ∀ (x : verts), ¬adj x x := dec_trivial\n\ndef G : simple_graph verts := ⟨adj_prop, adj_symmetric, adj_loopless⟩\n\n/- Now we can color `G`.-/\n\n@[derive decidable_eq]\ninductive colors : Type\n| c₁ | c₂ | c₃\n\nopen colors\n\ndef color_fn : verts → colors\n  | A := c₁\n  | B := c₂\n  | C := c₃\n  | D := c₂\n  | E := c₃\n\n/-\nWe must prove our coloring is proper, which `dec_trivial` is able to do easily for\nour finite graph.\n-/\n\nlemma color_fn_is_valid : ∀ (v w : verts), adj v w → color_fn v ≠ color_fn w :=\ndec_trivial\n\ndef my_coloring : G.coloring colors := ⟨color_fn, color_fn_is_valid⟩\n\n/-\nNotice that `color_fn_is_valid` wouldn't have been accepted by Lean if `color_fn`\nweren't in fact a proper coloring function.\n\n## The real challenge\n\nColoring graphs would be a trivial task if we could use as many colors as we wanted.\nJust color each vertex with a different color! This is done in [Mathlib](https://leanprover-community.github.io/mathlib_docs/combinatorics/simple_graph/coloring.html#simple_graph.self_coloring)\nby coloring vertices using themselves as colors.\n\nHowever, the interesting question is: what is the **minimum** number of colors required\nto color a certain graph? This quantity is called *chromatic number* and finding it\nfor any given graph is an NP-Hard problem, although Mathlib does provide proofs for some\nknown results:\n\n* If `G` is a subgraph of `G'`, the chromatic number of `G'` is at least the\nchromatic number of `G`\n\n    [`simple_graph.chromatic_number_le_of_le_colorable`](https://leanprover-community.github.io/mathlib_docs/combinatorics/simple_graph/coloring.html#simple_graph.chromatic_number_le_of_le_colorable)\n\n* The chromatic number of a complete graph is the number of vertices it has:\n\n    [`simple_graph.chromatic_number_complete_graph`](https://leanprover-community.github.io/mathlib_docs/combinatorics/simple_graph/coloring.html#simple_graph.chromatic_number_complete_graph)\n\n* The chromatic number of a complete bipartite graph is 2:\n\n    [`simple_graph.complete_bipartite_graph.chromatic_number`](https://leanprover-community.github.io/mathlib_docs/combinatorics/simple_graph/coloring.html#simple_graph.complete_bipartite_graph.chromatic_number)\n\n## Conclusion\n\nGraph coloring is an important problem in Computer Science, with\n[applications](https://en.wikipedia.org/wiki/Graph_coloring#Applications) in different\nareas of study. This is an ongoing field of research and finding lower/upper bounds for\nthe chromatic number, as well as potent coloring heuristics for graphs of certain shapes,\nis of immense value for the academic community and for the industry in general.\n-/\n", "meta": {"author": "Julian", "repo": "lftim", "sha": "49325ccd107f75f3ef98474cf255345c0e73b9ea", "save_path": "github-repos/lean/Julian-lftim", "path": "github-repos/lean/Julian-lftim/lftim-49325ccd107f75f3ef98474cf255345c0e73b9ea/lean/2022-01-09-Graph-Coloring-Basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7900697478090336}}
{"text": "/-\nCopyright (c) 2021 Yaël Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël 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 : α → α → α → Prop` forms a `circular_order` if it is\n  - reflexive: `btw a a a`\n  - cyclic: `btw a b c → btw b c a`\n  - antisymmetric: `btw a b c → btw c b a → a = b ∨ b = c ∨ c = a`\n  - total: `btw a b c ∨ btw c b a`\n  along with a strict betweenness relation `sbtw : α → α → α → Prop` which respects\n  `sbtw a b c ↔ btw a b c ∧ ¬ btw c b a`, analogously to how `<` and `≤` are related, and is\n  - transitive: `sbtw a b c → sbtw b d c → 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 α` here. The instances `has_le α → has_btw αᵒᵈ` and\n`has_lt α → has_sbtw αᵒᵈ` can each be inferred in two ways:\n* `has_le α` → `has_btw α` → `has_btw αᵒᵈ` vs\n  `has_le α` → `has_le αᵒᵈ` → `has_btw αᵒᵈ`\n* `has_lt α` → `has_sbtw α` → `has_sbtw αᵒᵈ` vs\n  `has_lt α` → `has_lt αᵒᵈ` → `has_sbtw αᵒᵈ`\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 `α × β` and\n`β × α` where `α` is a circular order and `β` 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 →c months_of_the_year` which relates the circular order of days\nand the circular order of months. Is `α →c β` 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 (α : Type*) :=\n(btw : α → α → α → Prop)\n\nexport has_btw (btw)\n\n/-- Syntax typeclass for a strict betweenness relation. -/\nclass has_sbtw (α : Type*) :=\n(sbtw : α → α → α → Prop)\n\nexport has_sbtw (sbtw)\n\n/-- A circular preorder is the analogue of a preorder where you can loop around. `≤` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive.\n-/\nclass circular_preorder (α : Type*) extends has_btw α, has_sbtw α :=\n(btw_refl (a : α) : btw a a a)\n(btw_cyclic_left {a b c : α} : btw a b c → btw b c a)\n(sbtw := λ a b c, btw a b c ∧ ¬btw c b a)\n(sbtw_iff_btw_not_btw {a b c : α} : sbtw a b c ↔ (btw a b c ∧ ¬btw c b a) . order_laws_tac)\n(sbtw_trans_left {a b c d : α} : sbtw a b c → sbtw b d c → 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. `≤` and\n`<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and\nantisymmetric. `sbtw` is transitive. -/\nclass circular_partial_order (α : Type*) extends circular_preorder α :=\n(btw_antisymm {a b c : α} : btw a b c → btw c b a → a = b ∨ b = c ∨ 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. `≤` and `<` are\nreplaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total.\n`sbtw` is transitive. -/\nclass circular_order (α : Type*) extends circular_partial_order α :=\n(btw_total : ∀ a b c : α, btw a b c ∨ btw c b a)\n\nexport circular_order (btw_total)\n\n/-! ### Circular preorders -/\n\nsection circular_preorder\nvariables {α : Type*} [circular_preorder α]\n\nlemma btw_rfl {a : α} : btw a a a :=\nbtw_refl _\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_cyclic_left        ← has_btw.btw.cyclic_left\nlemma has_btw.btw.cyclic_left {a b c : α} (h : btw a b c) : btw b c a :=\nbtw_cyclic_left h\n\nlemma btw_cyclic_right {a b c : α} (h : btw a b c) : btw c a b :=\nh.cyclic_left.cyclic_left\n\nalias btw_cyclic_right ← has_btw.btw.cyclic_right\n\n/-- The order of the `↔` has been chosen so that `rw btw_cyclic` cycles to the right while\n`rw ←btw_cyclic` cycles to the left (thus following the prepended arrow). -/\nlemma btw_cyclic {a b c : α} : btw a b c ↔ btw c a b :=\n⟨btw_cyclic_right, btw_cyclic_left⟩\n\nlemma sbtw_iff_btw_not_btw {a b c : α} : sbtw a b c ↔ btw a b c ∧ ¬btw c b a :=\ncircular_preorder.sbtw_iff_btw_not_btw\n\nlemma btw_of_sbtw {a b c : α} (h : sbtw a b c) : btw a b c :=\n(sbtw_iff_btw_not_btw.1 h).1\n\nalias btw_of_sbtw ← has_sbtw.sbtw.btw\n\nlemma not_btw_of_sbtw {a b c : α} (h : sbtw a b c) : ¬btw c b a :=\n(sbtw_iff_btw_not_btw.1 h).2\n\nalias not_btw_of_sbtw ← has_sbtw.sbtw.not_btw\n\nlemma not_sbtw_of_btw {a b c : α} (h : btw a b c) : ¬sbtw c b a :=\nλ h', h'.not_btw h\n\nalias not_sbtw_of_btw ← has_btw.btw.not_sbtw\n\nlemma sbtw_of_btw_not_btw {a b c : α} (habc : btw a b c) (hcba : ¬btw c b a) : sbtw a b c :=\nsbtw_iff_btw_not_btw.2 ⟨habc, hcba⟩\n\nalias sbtw_of_btw_not_btw ← has_btw.btw.sbtw_of_not_btw\n\nlemma sbtw_cyclic_left {a b c : α} (h : sbtw a b c) : sbtw b c a :=\nh.btw.cyclic_left.sbtw_of_not_btw (λ h', h.not_btw h'.cyclic_left)\n\nalias sbtw_cyclic_left ← has_sbtw.sbtw.cyclic_left\n\nlemma sbtw_cyclic_right {a b c : α} (h : sbtw a b c) : sbtw c a b :=\nh.cyclic_left.cyclic_left\n\nalias sbtw_cyclic_right ← has_sbtw.sbtw.cyclic_right\n\n/-- The order of the `↔` has been chosen so that `rw sbtw_cyclic` cycles to the right while\n`rw ←sbtw_cyclic` cycles to the left (thus following the prepended arrow). -/\nlemma sbtw_cyclic {a b c : α} : sbtw a b c ↔ sbtw c a b :=\n⟨sbtw_cyclic_right, sbtw_cyclic_left⟩\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_trans_left        ← has_btw.btw.trans_left\nlemma has_sbtw.sbtw.trans_left {a b c d : α} (h : sbtw a b c) : sbtw b d c → sbtw a d c :=\nsbtw_trans_left h\n\nlemma sbtw_trans_right {a b c d : α} (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 ← has_sbtw.sbtw.trans_right\n\nlemma sbtw_asymm {a b c : α} (h : sbtw a b c) : ¬ sbtw c b a :=\nh.btw.not_sbtw\n\nalias sbtw_asymm ← has_sbtw.sbtw.not_sbtw\n\nlemma sbtw_irrefl_left_right {a b : α} : ¬ sbtw a b a := λ h, h.not_btw h.btw\nlemma sbtw_irrefl_left {a b : α} : ¬ sbtw a a b := λ h, sbtw_irrefl_left_right h.cyclic_left\nlemma sbtw_irrefl_right {a b : α} : ¬ sbtw a b b := λ h, sbtw_irrefl_left_right h.cyclic_right\nlemma sbtw_irrefl (a : α) : ¬ sbtw a a a := sbtw_irrefl_left_right\n\nend circular_preorder\n\n/-! ### Circular partial orders -/\n\nsection circular_partial_order\nvariables {α : Type*} [circular_partial_order α]\n\n-- TODO: `alias` creates a def instead of a lemma.\n-- alias btw_antisymm        ← has_btw.btw.antisymm\nlemma has_btw.btw.antisymm {a b c : α} (h : btw a b c) : btw c b a → a = b ∨ b = c ∨ c = a :=\nbtw_antisymm h\n\nend circular_partial_order\n\n/-! ### Circular orders -/\n\nsection circular_order\nvariables {α : Type*} [circular_order α]\n\nlemma btw_refl_left_right (a b : α) : btw a b a :=\n(or_self _).1 (btw_total a b a)\n\nlemma btw_rfl_left_right {a b : α} : btw a b a :=\nbtw_refl_left_right _ _\n\nlemma btw_refl_left (a b : α) : btw a a b :=\nbtw_rfl_left_right.cyclic_right\n\nlemma btw_rfl_left {a b : α} : btw a a b :=\nbtw_refl_left _ _\n\nlemma btw_refl_right (a b : α) : btw a b b :=\nbtw_rfl_left_right.cyclic_left\n\nlemma btw_rfl_right {a b : α} : btw a b b :=\nbtw_refl_right _ _\n\nlemma sbtw_iff_not_btw {a b c : α} : sbtw a b c ↔ ¬ 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 : α} : btw a b c ↔ ¬ 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 {α : Type*} [circular_preorder α]\n\n/-- Closed-closed circular interval -/\ndef cIcc (a b : α) : set α := {x | btw a x b}\n\n/-- Open-open circular interval -/\ndef cIoo (a b : α) : set α := {x | sbtw a x b}\n\n@[simp] lemma mem_cIcc {a b x : α} : x ∈ cIcc a b ↔ btw a x b := iff.rfl\n@[simp] lemma mem_cIoo {a b x : α} : x ∈ cIoo a b ↔ sbtw a x b := iff.rfl\n\nend circular_preorder\n\nsection circular_order\nvariables {α : Type*} [circular_order α]\n\nlemma left_mem_cIcc (a b : α) : a ∈ cIcc a b := btw_rfl_left\nlemma right_mem_cIcc (a b : α) : b ∈ cIcc a b := btw_rfl_right\n\nlemma compl_cIcc {a b : α} : (cIcc a b)ᶜ = cIoo b a :=\nbegin\n  ext,\n  rw [set.mem_cIoo, sbtw_iff_not_btw],\n  refl,\nend\n\nlemma compl_cIoo {a b : α} : (cIoo a b)ᶜ = 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\" `≤`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef has_le.to_has_btw (α : Type*) [has_le α] : has_btw α :=\n{ btw := λ a b c, (a ≤ b ∧ b ≤ c) ∨ (b ≤ c ∧ c ≤ a) ∨ (c ≤ a ∧ a ≤ b) }\n\n/-- The strict betweenness relation obtained from \"looping around\" `<`.\nSee note [reducible non-instances]. -/\n@[reducible]\ndef has_lt.to_has_sbtw (α : Type*) [has_lt α] : has_sbtw α :=\n{ sbtw := λ a b c, (a < b ∧ b < c) ∨ (b < c ∧ c < a) ∨ (c < a ∧ 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 (α : Type*) [preorder α] : circular_preorder α :=\n{ btw := λ a b c, (a ≤ b ∧ b ≤ c) ∨ (b ≤ c ∧ c ≤ a) ∨ (c ≤ a ∧ a ≤ b),\n  sbtw := λ a b c, (a < b ∧ b < c) ∨ (b < c ∧ c < a) ∨ (c < a ∧ a < b),\n  btw_refl := λ a, or.inl ⟨le_rfl, le_rfl⟩,\n  btw_cyclic_left := λ a b c h, begin\n    unfold btw at ⊢ h,\n    rwa [←or.assoc, or_comm],\n  end,\n  sbtw_trans_left := λ a b c d, begin\n    rintro (⟨hab, hbc⟩ | ⟨hbc, hca⟩ | ⟨hca, hab⟩) (⟨hbd, hdc⟩ | ⟨hdc, hcb⟩ | ⟨hcb, hbd⟩),\n    { exact or.inl ⟨hab.trans hbd, hdc⟩ },\n    { exact (hbc.not_lt hcb).elim },\n    { exact (hbc.not_lt hcb).elim },\n    { exact or.inr (or.inl ⟨hdc, hca⟩) },\n    { exact or.inr (or.inl ⟨hdc, hca⟩) },\n    { exact (hbc.not_lt hcb).elim },\n    { exact or.inr (or.inl ⟨hdc, hca⟩) },\n    { exact or.inr (or.inl ⟨hdc, hca⟩) },\n    { exact or.inr (or.inr ⟨hca, hab.trans hbd⟩) }\n  end,\n  sbtw_iff_btw_not_btw := λ a b c, begin\n    simp_rw lt_iff_le_not_le,\n    set x₀ := a ≤ b,\n    set x₁ := b ≤ c,\n    set x₂ := c ≤ a,\n    have : x₀ → x₁ → a ≤ c := le_trans,\n    have : x₁ → x₂ → b ≤ a := le_trans,\n    have : x₂ → x₀ → c ≤ b := le_trans,\n    clear_value x₀ x₁ x₂,\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 (α : Type*) [partial_order α] :\n  circular_partial_order α :=\n{ btw_antisymm := λ a b c, begin\n    rintro (⟨hab, hbc⟩ | ⟨hbc, hca⟩ | ⟨hca, hab⟩) (⟨hcb, hba⟩ | ⟨hba, hac⟩ | ⟨hac, hcb⟩),\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 α }\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 (α : Type*) [linear_order α] :\n  circular_order α :=\n{ btw_total := λ 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 ⟨hab, hbc⟩) },\n    { exact or.inl (or.inl ⟨hab, hbc⟩) },\n    { exact or.inl (or.inr $ or.inr ⟨hca, hab⟩) },\n    { exact or.inr (or.inr $ or.inr ⟨hac, hcb⟩) },\n    { exact or.inl (or.inr $ or.inl ⟨hbc, hca⟩) },\n    { exact or.inr (or.inr $ or.inl ⟨hba, hac⟩) },\n    { exact or.inr (or.inl ⟨hcb, hba⟩) },\n    { exact or.inr (or.inr $ or.inl ⟨hba, hac⟩) }\n  end,\n  .. partial_order.to_circular_partial_order α }\n\n/-! ### Dual constructions -/\n\nsection order_dual\n\ninstance (α : Type*) [has_btw α] : has_btw αᵒᵈ := ⟨λ a b c : α, btw c b a⟩\ninstance (α : Type*) [has_sbtw α] : has_sbtw αᵒᵈ := ⟨λ a b c : α, sbtw c b a⟩\n\ninstance (α : Type*) [h : circular_preorder α] : circular_preorder αᵒᵈ :=\n{ btw_refl := btw_refl,\n  btw_cyclic_left := λ a b c, btw_cyclic_right,\n  sbtw_trans_left := λ a b c d habc hbdc, hbdc.trans_right habc,\n  sbtw_iff_btw_not_btw := λ a b c, @sbtw_iff_btw_not_btw α _ c b a,\n  .. order_dual.has_btw α,\n  .. order_dual.has_sbtw α }\n\ninstance (α : Type*) [circular_partial_order α] : circular_partial_order αᵒᵈ :=\n{ btw_antisymm := λ a b c habc hcba, @btw_antisymm α _ _ _ _ hcba habc,\n  .. order_dual.circular_preorder α }\n\ninstance (α : Type*) [circular_order α] : circular_order αᵒᵈ :=\n{ btw_total := λ a b c, btw_total c b a, .. order_dual.circular_partial_order α }\n\nend order_dual\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/circular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.7900656649741097}}
{"text": "open Classical\n\n-- 1\nvariable (α : Type) (p q : α → Prop)\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := \n  Iff.intro\n  (fun h: (∀ x, p x ∧ q x) => show (∀ x, p x) ∧ (∀ x, q x) from \n    And.intro (fun y: α => (h y).left) (fun y: α => (h y).right))\n  (fun h: (∀ x, p x) ∧ (∀ x, q x) => show (∀ x, p x ∧ q x) from \n    (fun y : α => And.intro (h.left y) (h.right y)))\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := \n  fun h : (∀ x, p x → q x) => fun h1 : (∀ x, p x) => (fun x : α => (h x) (h1 x))\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := \n  fun h : (∀ x, p x) ∨ (∀ x, q x) => \n    h.elim\n    (fun h1 => fun x : α => Or.inl (h1 x))\n    (fun h2 => fun x : α => Or.inr (h2 x))\n\n-- 2\nvariable (α : Type) (p q : α → Prop)\nvariable (r : Prop)\n\nexample : α → ((∀ _ : α, r) ↔ r) := \n  fun h : α => Iff.intro\n    (fun h1 => h1 h)\n    (fun hr => fun _ : α => hr)\n\nexample : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r := \n  Iff.intro\n  (fun h : (∀ x, p x ∨ r) => (Or.elim (em r) \n    (fun hr => Or.inr hr) \n    (fun hnr => Or.inl (fun α => \n      have h1 := (h α)\n      h1.elim \n        (fun h2 => h2)\n        (fun hr => False.elim (absurd hr hnr))))))\n  (fun h : (∀ x, p x) ∨ r => h.elim \n    (fun h1 => fun α => Or.inl (h1 α))\n    (fun h1 => fun _ => Or.inr h1))\n\nexample : (∀ x, r → p x) ↔ (r → ∀ x, p x) := \n  Iff.intro\n  (fun h : ∀ x, r → p x => fun hr => fun α => (h α) hr)\n  (fun h : r → ∀ x, p x => fun α => fun hr => (h hr) α) \n\n-- 3\nvariable (men : Type) (barber : men)\nvariable (shaves : men → men → Prop)\n\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : False :=\n  match (h barber) with\n    | ⟨w, hw⟩ =>\n      let l := shaves barber barber\n      Or.elim (em l)\n        (fun h1 => absurd h1 (w h1))\n        (fun h1 => absurd (hw h1) h1)\n\n-- 4\ndef even (n : Nat) : Prop := ∃ m, n = 2 * m\n\n-- I would like knowing a way that allows me to check if this is correct\ndef prime (n : Nat) : Prop := ¬∃ m, (Nat.mod n m = 0) ∧ ¬(m = 1) ∧ ¬(m = n) \n\ndef infinitely_many_primes : Prop := ∀ n, ∃ m, (prime n) ∧ (prime m) ∧ (m > n) \n\ndef Fermat_prime (n : Nat) : Prop := ∃ m, m < 5 ∧ (Nat.pow 4 m) = n ∧ prime n\n\ndef infinitely_many_Fermat_primes : Prop := ∀ n, ∃ m, (Fermat_prime n) ∧ (Fermat_prime m) ∧ (m > n) \n\ndef goldbach_conjecture : Prop := ∀ n, ∃ m, ∃ s, n > 2 ∧ prime m ∧ prime s ∧ n = (m + s)\n\ndef Goldbach's_weak_conjecture : Prop := ∀ n: Nat, ∃ x, ∃ y, ∃ z, n > 5 ∧ (Nat.mod n 2) = 1 ∧ n = x + y + z ∧ prime x ∧ prime y ∧ prime z\n\ndef Fermat's_last_theorem : Prop := ∀ n : Nat, ¬∃ x, ¬∃ y, ¬∃ z,  n > 2 ∧ (Nat.pow x n) + (Nat.pow y n) = (Nat.pow z n)\n\n-- 5\nvariable (r : Prop)\n\nexample : (∃ x : α, r) → r := fun h => \n  Exists.elim h\n  (fun _ => fun r => r)\nexample : (∃ x : α, r) → r := fun h => \n  match h with\n  | ⟨_, hw⟩ => hw\n\nexample (a : α) : r → (∃ x : α, r) := fun hr => Exists.intro a hr\n\nexample : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := \n  Iff.intro \n  (fun h => match h with \n    | ⟨w,hw⟩ => And.intro (Exists.intro w hw.left) hw.right)\n  (fun h => match h with \n    | ⟨w,hw⟩ => w.elim (fun α => fun h1 => Exists.intro α (And.intro h1 hw)))\n\nexample : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := \n  Iff.intro \n  (fun h => match h with\n  | ⟨w,hw⟩ => (hw.elim\n      (fun h1 => Or.inl (Exists.intro w h1))\n      (fun h1 => Or.inr (Exists.intro w h1))))\n  (fun h => h.elim\n    (fun h1 => match h1 with\n      | ⟨w,hw⟩ => Exists.intro w (Or.inl hw))\n    (fun h1 => match h1 with\n      | ⟨w,hw⟩ => Exists.intro w (Or.inr hw)))\n\nexample : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := \n  Iff.intro\n  (fun h => fun h1 => match h1 with\n    | ⟨w,hw⟩ => absurd (h w) hw)\n  (fun h => fun α => byContradiction (fun h1 => absurd (Exists.intro α h1) h))\n\nexample : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := \n  Iff.intro\n  (fun h => match h with \n    | ⟨w, hw⟩ => fun h1 => \n      have hp := h1 w\n      absurd hw hp)\n  (fun h => byContradiction (fun h1 => absurd \n    (fun α => byCases \n      (fun h2 : p α => False.elim (absurd ⟨α,h2⟩ h1))\n      (fun h2 => h2)) h))\n\nexample : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := \n  Iff.intro\n  (fun h => fun α => fun hpa => absurd (Exists.intro α hpa) h)\n  (fun h => fun h1 => match h1 with \n    | ⟨w, hw⟩ => absurd hw (h w))\n\nexample : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := \n  Iff.intro \n  (fun h => byContradiction \n  (fun h1 => absurd \n      (fun α => byCases \n      (fun hpa : p α => hpa)\n      (fun hnp => False.elim (absurd (Exists.intro α hnp) h1))) h)) \n  (fun h => match h with \n    | ⟨w, hw⟩ => fun h1 => absurd (h1 w) hw)\n\nexample : (∀ x, p x → r) ↔ (∃ x, p x) → r := \n  Iff.intro\n  (fun h => fun h1 => match h1 with\n  | ⟨w,hw⟩ => (h w) hw)\n  (fun h => fun α => fun h1 => h (Exists.intro α h1))\n\nexample (a : α) : (∃ x, p x → r) ↔ (∀ x, p x) → r := \n  Iff.intro\n  (fun ⟨b, (hb : p b → r)⟩ => fun h1 => hb (h1 b)) -- removed the exists already ?\n  (fun h => byCases\n    (fun hap : ∀ x, p x => Exists.intro a (fun _ => h hap))\n    (fun hnap : ¬ ∀ x, p x =>\n    byContradiction\n      (fun hnex : ¬ ∃ x, p x → r =>\n        have hap : ∀ x, p x :=\n          fun x =>\n          byContradiction\n            (fun hnp : ¬ p x =>\n              have hex : ∃ x, p x → r := ⟨x, (fun hp => absurd hp hnp)⟩\n              show False from hnex hex)\n        show False from hnap hap)))\n\nexample (a : α) : (∃ x, r → p x) ↔ (r → ∃ x, p x) := \n  Iff.intro\n  (fun h => match h with\n    | ⟨w,hw⟩ => fun hr => Exists.intro w (hw hr))\n(fun h => Or.elim (em r) \n  (fun hr => match (h hr) with \n    | ⟨x,px⟩ => Exists.intro x (fun _ => px))\n  (fun hnr => Exists.intro a (fun hr => False.elim (hnr hr))))\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/theorem_proving/exercises_chapter_4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.790065661656319}}
{"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.multiset.nat_antidiagonal\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.Nodup\nimport Mathlib.Data.List.NatAntidiagonal\n\n/-!\n# Antidiagonals in ℕ × ℕ as multisets\n\nThis file defines the antidiagonals of ℕ × ℕ as multisets: the `n`-th antidiagonal is the multiset\nof pairs `(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 file `Data.List.NatAntidiagonal` and is further refined by file\n`Data.Finset.NatAntidiagonal`.\n-/\n\nnamespace Multiset\n\nnamespace Nat\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 : ℕ) : Multiset (ℕ × ℕ) :=\n  List.Nat.antidiagonal n\n#align multiset.nat.antidiagonal Multiset.Nat.antidiagonal\n\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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := by\n  rw [antidiagonal, mem_coe, List.Nat.mem_antidiagonal]\n#align multiset.nat.mem_antidiagonal Multiset.Nat.mem_antidiagonal\n\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp]\ntheorem card_antidiagonal (n : ℕ) : card (antidiagonal n) = n + 1 := by\n  rw [antidiagonal, coe_card, List.Nat.length_antidiagonal]\n#align multiset.nat.card_antidiagonal Multiset.Nat.card_antidiagonal\n\n/-- The antidiagonal of `0` is the list `[(0, 0)]` -/\n@[simp]\ntheorem antidiagonal_zero : antidiagonal 0 = {(0, 0)} :=\n  rfl\n#align multiset.nat.antidiagonal_zero Multiset.Nat.antidiagonal_zero\n\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\n@[simp]\ntheorem nodup_antidiagonal (n : ℕ) : Nodup (antidiagonal n) :=\n  coe_nodup.2 <| List.Nat.nodup_antidiagonal n\n#align multiset.nat.nodup_antidiagonal Multiset.Nat.nodup_antidiagonal\n\n@[simp]\ntheorem antidiagonal_succ {n : ℕ} :\n    antidiagonal (n + 1) = (0, n + 1) ::ₘ (antidiagonal n).map (Prod.map Nat.succ id) := by\n  simp only [antidiagonal, List.Nat.antidiagonal_succ, coe_map, cons_coe]\n#align multiset.nat.antidiagonal_succ Multiset.Nat.antidiagonal_succ\n\ntheorem antidiagonal_succ' {n : ℕ} :\n    antidiagonal (n + 1) = (n + 1, 0) ::ₘ (antidiagonal n).map (Prod.map id Nat.succ) := by\n  rw [antidiagonal, List.Nat.antidiagonal_succ', ← coe_add, add_comm, antidiagonal, coe_map,\n    coe_add, List.singleton_append, cons_coe]\n#align multiset.nat.antidiagonal_succ' Multiset.Nat.antidiagonal_succ'\n\ntheorem antidiagonal_succ_succ' {n : ℕ} :\n    antidiagonal (n + 2) =\n      (0, n + 2) ::ₘ (n + 2, 0) ::ₘ (antidiagonal n).map (Prod.map Nat.succ Nat.succ) :=\n  by\n  rw [antidiagonal_succ, antidiagonal_succ', map_cons, map_map, Prod_map]\n  rfl\n#align multiset.nat.antidiagonal_succ_succ' Multiset.Nat.antidiagonal_succ_succ'\n\ntheorem map_swap_antidiagonal {n : ℕ} : (antidiagonal n).map Prod.swap = antidiagonal n := by\n  rw [antidiagonal, coe_map, List.Nat.map_swap_antidiagonal, coe_reverse]\n#align multiset.nat.map_swap_antidiagonal Multiset.Nat.map_swap_antidiagonal\n\nend Nat\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/NatAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.79006565805398}}
{"text": "/-\n# References\n\n1. Avigad, Jeremy. ‘Theorem Proving in Lean’, n.d.\n-/\n\n-- Exercise 1\n--\n-- Prove the following identities, replacing the \"sorry\" placeholders with\n-- actual proofs.\nnamespace ex1\n\nopen or\n\nvariable (p q r : Prop)\n\n-- Commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=\n  Iff.intro\n    (fun ⟨hp, hq⟩ => show q ∧ p from ⟨hq, hp⟩)\n    (fun ⟨hq, hp⟩ => show p ∧ q from ⟨hp, hq⟩)\n\nexample : p ∨ q ↔ q ∨ p :=\n  Iff.intro\n    (fun h => h.elim Or.inr Or.inl)\n    (fun h => h.elim Or.inr Or.inl)\n\n-- Associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  Iff.intro\n    (fun ⟨⟨hp, hq⟩, hr⟩ => ⟨hp, hq, hr⟩)\n    (fun ⟨hp, hq, hr⟩ => ⟨⟨hp, hq⟩, hr⟩)\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n  Iff.intro\n    (fun h₁ => h₁.elim\n      (fun h₂ => h₂.elim Or.inl (Or.inr ∘ Or.inl))\n      (Or.inr ∘ Or.inr))\n    (fun h₁ => h₁.elim\n      (Or.inl ∘ Or.inl)\n      (fun h₂ => h₂.elim (Or.inl ∘ Or.inr) Or.inr))\n\n-- Distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n  Iff.intro\n    (fun ⟨hp, hqr⟩ => hqr.elim (Or.inl ⟨hp, ·⟩) (Or.inr ⟨hp, ·⟩))\n    (fun h₁ => h₁.elim\n      (fun ⟨hp, hq⟩ => ⟨hp, Or.inl hq⟩)\n      (fun ⟨hp, hr⟩ => ⟨hp, Or.inr hr⟩))\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\n  Iff.intro\n    (fun h => h.elim\n      (fun hp => ⟨Or.inl hp, Or.inl hp⟩)\n      (fun ⟨hq, hr⟩ => ⟨Or.inr hq, Or.inr hr⟩))\n    (fun ⟨h₁, h₂⟩ => h₁.elim\n      Or.inl\n      (fun hq => h₂.elim Or.inl (fun hr => Or.inr ⟨hq, hr⟩)))\n\n-- Other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) :=\n  Iff.intro\n    (fun h ⟨hp, hq⟩ => h hp hq)\n    (fun h hp hq => h ⟨hp, hq⟩)\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\n  Iff.intro\n    (fun h =>\n      have h₁ : p → r := h ∘ Or.inl\n      have h₂ : q → r := h ∘ Or.inr\n      show (p → r) ∧ (q → r) from ⟨h₁, h₂⟩)\n    (fun ⟨h₁, h₂⟩ h => h.elim h₁ h₂)\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  Iff.intro\n    (fun h => ⟨h ∘ Or.inl, h ∘ Or.inr⟩)\n    (fun h₁ h₂ => h₂.elim (absurd · h₁.left) (absurd · h₁.right))\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\n  fun h₁ h₂ => h₁.elim (absurd h₂.left ·) (absurd h₂.right ·)\n\nexample : ¬(p ∧ ¬p) :=\n  fun h => absurd h.left h.right\n\nexample : p ∧ ¬q → ¬(p → q) :=\n  fun ⟨hp, nq⟩ hpq => absurd (hpq hp) nq\n\nexample : ¬p → (p → q) :=\n  fun np hp => absurd hp np\n\nexample : (¬p ∨ q) → (p → q) :=\n  fun npq hp => npq.elim (absurd hp ·) id\n\nexample : p ∨ False ↔ p :=\n  Iff.intro (fun hpf => hpf.elim id False.elim) Or.inl\n\nexample : p ∧ False ↔ False :=\n  Iff.intro (fun ⟨_, hf⟩ => hf) False.elim\n\nexample : (p → q) → (¬q → ¬p) :=\n  fun hpq nq hp => absurd (hpq hp) nq\n\nend ex1\n\n-- Example 2\n--\n-- Prove the following identities, replacing the “sorry” placeholders with\n-- actual proofs. These require classical reasoning.\nnamespace ex2\n\nopen Classical\n\nvariable (p q r s : Prop)\n\nexample (hp : p) : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n  fun h => (h hp).elim\n    (fun hr => Or.inl (fun _ => hr))\n    (fun hs => Or.inr (fun _ => hs))\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n  fun npq => (em p).elim\n    (fun hp => (em q).elim\n      (fun hq => False.elim (npq ⟨hp, hq⟩))\n      Or.inr)\n    Or.inl\n\nexample : ¬(p → q) → p ∧ ¬q :=\n  fun h =>\n    have lhs : p := byContradiction\n      fun np => h (fun (hp : p) => absurd hp np)\n    ⟨lhs, fun hq => h (fun _ => hq)⟩\n\nexample : (p → q) → (¬p ∨ q) :=\n  fun hpq => (em p).elim (fun hp => Or.inr (hpq hp)) Or.inl\n\nexample : (¬q → ¬p) → (p → q) :=\n  fun h hp => byContradiction\n    fun nq => absurd hp (h nq)\n\nexample : p ∨ ¬p := em p\n\nexample : (((p → q) → p) → p) :=\n  fun h => byContradiction\n    fun np =>\n      suffices hp : p from absurd hp np\n      h (fun (hp : p) => absurd hp np)\n\nend ex2\n\n-- Example 3\n--\n-- Prove `¬(p ↔ ¬p)` without using classical logic.\nnamespace ex3\n\nvariable (p : Prop)\n\nexample (hp : p) : ¬(p ↔ ¬p) :=\n  fun h => absurd hp (Iff.mp h hp)\n\nend ex3\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/Exercises3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7900656580133302}}
{"text": "/-\nCopyright (c) 2020 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey\n-/\nimport data.fintype.basic\nimport group_theory.order_of_element\nimport tactic.zify\nimport data.nat.totient\nimport data.zmod.basic\n\n/-!\n# The Lucas test for primes.\n\nThis file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for\nMersenne primes). A number `a` witnesses that `n` is prime if `a` has order `n-1` in the\nmultiplicative group of integers mod `n`. This is checked by verifying that `a^(n-1) = 1 (mod n)`\nand `a^d ≠ 1 (mod n)` for any divisor `d | n - 1`. This test is the basis of the Pratt primality\ncertificate.\n\n## TODO\n\n- Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness.\n  Use `units.is_cyclic` from `ring_theory/integral_domain` to show the group is cyclic.\n- Write a tactic that uses this theorem to generate Pratt primality certificates\n- Integrate Pratt primality certificates into the norm_num primality verifier\n\n## Implementation notes\n\nNote that the proof for `lucas_primality` relies on analyzing the multiplicative group\nmodulo `p`. Despite this, the theorem still holds vacuously for `p = 0` and `p = 1`: In these\ncases, we can take `q` to be any prime and see that `hd` does not hold, since `a^((p-1)/q)` reduces\nto `1`.\n-/\n\n/--\nIf `a^(p-1) = 1 mod p`, but `a^((p-1)/q) ≠ 1 mod p` for all prime factors `q` of `p-1`, then `p`\nis prime. This is true because `a` has order `p-1` in the multiplicative group mod `p`, so this\ngroup must itself have order `p-1`, which only happens when `p` is prime.\n-/\ntheorem lucas_primality (p : ℕ) (a : zmod p) (ha : a^(p-1) = 1)\n  (hd : ∀ q : ℕ, q.prime → q ∣ (p-1) → a^((p-1)/q) ≠ 1) : p.prime :=\nbegin\n  have h0 : p ≠ 0, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },\n  have h1 : p ≠ 1, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },\n  have hp1 : 1 < p := lt_of_le_of_ne h0.bot_lt h1.symm,\n  have order_of_a : order_of a = p-1,\n  { apply order_of_eq_of_pow_and_pow_div_prime _ ha hd,\n    exact tsub_pos_of_lt hp1, },\n  haveI fhp0 : fact (0 < p) := ⟨h0.bot_lt⟩,\n  rw nat.prime_iff_card_units,\n  -- Prove cardinality of `units` of `zmod p` is both `≤ p-1` and `≥ p-1`\n  refine le_antisymm (nat.card_units_zmod_lt_sub_one hp1) _,\n  have hp' : p - 2 + 1 = p - 1 := tsub_add_eq_add_tsub hp1,\n  let a' : units (zmod p) := units.mk_of_mul_eq_one a (a ^ (p-2)) (by rw [←pow_succ, hp', ha]),\n  calc p - 1 = order_of a : order_of_a.symm\n  ... = order_of a' : order_of_injective (units.coe_hom (zmod p)) units.ext a'\n  ... ≤ fintype.card (units (zmod p)) : order_of_le_card_univ,\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/lucas_primality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7900656562121602}}
{"text": "/-\nUVa CS Discrete Math (Sullivan) Homework #2\n-/\n\n/-\nNote: We distribute homework assignments and\neven exams as Lean files, as we do now for this\nassignment. You will answer the questions in one \nof two ways: by writing an answer in a comment block \n(such as this one), or by writing mathematical logic \n(which is what \"Lean code\" is). For this assignment\nyou will write all your answers as simple comments.\n-/\n\n/-\nThis assignment has three questions, each with several \nparts. Be sure to read and answer all parts of all of\nthe questions.\n\nMake a copy of this file in your \"mywork\" directory\nthe read and answer the questions by editing this fie.\nWhen you are done, *save it*, then upload it to Collab. \nThat is how you will submit work in this class. Be sure \nto double check your submission to be sure you uploaded the right file.\n-/\n\n/-\nQUESTION #1 (7 Parts, A - G)\n\nA. How many functions are there that take one\nargument of type Boolean (one bit, if you prefer)\nand that return one value, also of type Boolean?\nHint: We discussed this in class.\n\nAnswer here (inside this comment block): 4\n\nB. How many functions are there that take two\narguments of type Boolean and that return\none value of type Boolean? Hint: we discussed\nthis in class, too. \n\nAnswer here: 16\n\nC. How many functions are there that take three\nbits of input and that return a one bit result?\nHint: We discussed this, too.\n\nAnswer here: 256\n\nD. Give a general formula that you believe to\nbe valid describing the number of functions\nthat take n bits, for any natural number, n,\nand that return one bit. Use the ^ character\nto represent exponentiation.\n\nAnswer:(2^(n))^2\n\nE. How many functions are there that take three\nbits of input and that return *two* bits as a\nresult? Hint: think about both how many possible \ncombinations of input bits there are. To define\na function, you need to specify which two-bit\nreturn value is associated with each combination\nof input values. The number of functions will be\nthe number of ways in which you can assign output\nvalues for each combination of input values. Give\nyour answer in a form that involves 3 (inputs)\nand 2 (output bits).\n\nAnswer here: 4096\n\n\nF. How many functions are there that take 64 bits\nof input and return a 64 bit result? Give your \nanswer as an algebraic expression. The number is\ntoo big to write it out explicitly.\n\nAnswer here: (2^(64))^(2^(64))\n\nG. How many functions are there that take n bits of\ninput and return m bits of output, where n and m are\nnatural numbers? Give an algebraic expression as your\nanswer, involving the variables m and n.\n\nAnswer here: (2^n)^(2^m)\n-/\n\n/- \nQUESTION #2 (Three parts, A - C)\n\nSuppose you are asked to write a program, P(x), taking \none argument, x, a \"natural number\", and that it must \nsatisfy a specification, S(x), that defines a function \nin a pure functional programming language. \n\nA. Using simple English to express your answer, what \nproposition that must be true for P to be accepted as a \ncorrect implementation of S. Hint: We discussed this in \nclass.\n\nAnswer: P must satisfy specification s for every possible value of x.\n\nB. Why is testing alone generally inadequate to prove \npthe correctness of such a program, P?\n\nAnswer: There are often too many testing variations to prove by testing alone\n\nC. What kind of mathematical \"thing\" would be needed to \nshow beyond a reasonable doubt that P satisfies S? You \ncan give a one-word answer.\n\nAnswer: proof\n\n-/\n\n\n\n/- \nQUESTION #3 (Four parts, A - D)\n\nConsider a new data type, cool, that has three possible\nvalues: true (T), false (F), and don't know (D). And now\nconsider the following conjecture:\n\nFor any natural number, n, the number of combinations \nof values of n variables of type cool is 3^n.\n\nGive a proof of this conjecture by induction.\n\nA. What is the first conjecture you must prove? Hint:\nsubstitute a specific value for n into the conjecture\nand rewrite it with that value in place of n.\n\nAnswer: You have to prove the base case. In our situation that would be n=0. \nWhen n = 0, the number of combinations should be 1. If we plug 0 into the equation 3^n we get\nthe value 1 out. The base case is established.\n\nB. Prove it. Hint: One approach to proving that two\nterms are equal is simply to reduce each term to its\nsimplest form, and then show that the reduced terms\nare exactly the same. In other words, just simplify\nthe expressions on each side of an equals to to show\nthat the values are identical.\n\nAnswer here: We know that in mathematics the number of variations of zero variables is 1. \nIf we have n = 0, the number of variables should be 1. When we plug n = 0 into 3^n it evaluates\nto 1. We can see that our base case meets our expected output.\n\nC. What is the second conjecture that you must prove\nto complete your proof by induction?\n\nAnswer here: If the states of n variables is 3^n then the states of (n+1) is equal to 3^(n+1). In \nsimpler terms, adding another variable should increase the number of possible combinations \nby 3 times. \n\n\nD. Prove it. Hint, to prove a proposition of the form,\nP → Q, or P implies Q, you start by *assuming* that P\nis true (whatever proposition it happens to be), and \nthen you show that in the context of this assumption,\nthat proposition Q must be true. In other words, you\nwant to prove that IF P is true THEN Q must be true,\ntoo.\n\nAnswer here: If we assume that 3^n equals the number of combinations, then \nit must be true for 3^(n+1). 3^(n+1) is equal to (3^n)*3. We can use use another example in \nwhich we know the expected output to demonstrate this. The combinations with 1 variable should \nbe 3. 3^(1) = 3^(0)*3, 3^(0)=1, therefore, 3^1 = 3. \n\n-/\n\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/hw2_a_few_easy_pieces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.9111797172476385, "lm_q1q2_score": 0.7900254078518992}}
{"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 d6814c584384ddf2825ff038e868451a7c956f31\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.Coeff\nimport Mathlib.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 = ∑ (ij : ℕ × ℕ) 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/-- Vandermonde's identity -/\ntheorem Nat.add_choose_eq (m n k : ℕ) :\n    (m + n).choose k = ∑ ij : ℕ × ℕ in antidiagonal k, m.choose ij.1 * n.choose ij.2 := by\n  calc\n    (m + n).choose k = ((X + 1) ^ (m + n)).coeff k := by rw [coeff_X_add_one_pow, Nat.cast_id]\n    _ = ((X + 1) ^ m * (X + 1) ^ n).coeff k := by rw [pow_add]\n    _ = ∑ ij : ℕ × ℕ in antidiagonal k, m.choose ij.1 * n.choose ij.2 := by\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]\n#align nat.add_choose_eq Nat.add_choose_eq\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/Vandermonde.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897475985937, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7900131093830014}}
{"text": "\n\nimport algebra.big_operators data.set.finite\n\ndefinition matrix (R: Type) (n m : nat)[ring R] :=  fin n →( fin m → R ) \n \n namespace 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λ 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λ I J, - A I J\n\ndefinition zero ( R : Type) [ring R] {m n: nat }: (matrix R m n):= \nλ  I J , 0 \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λ I J, finset.sum finset.univ (λ 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 (λ (K : fin n), A x K * finset.sum finset.univ (λ (J : fin l), B K J * C J y)) =\n     finset.sum finset.univ (λ (J : fin l), finset.sum finset.univ (λ (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 : (λ (J : fin l), finset.sum finset.univ (λ (K : fin n), A x K * B K J) * C J y)\n        = (λ (J : fin l), finset.sum finset.univ (λ (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 (λ (K : fin n), A x K * finset.sum finset.univ (λ (K_1 : fin l), B K K_1 * C K_1 y)) =\n    finset.sum finset.univ (λ (K : fin n), finset.sum finset.univ (λ (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 (λ (K : fin n), A x K * B K y) + finset.sum finset.univ (λ (K : fin n), A x K * C K y)\n            = finset.sum finset.univ (λ (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 (λ (K : fin n), A x K * C K y) + finset.sum finset.univ (λ (K : fin n), B x K * C K y)\n            = finset.sum finset.univ (λ (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\n\n\n\n\ndefinition identity_matrix ( R : Type) [ring R] { n: nat }: (matrix R n n):= \nλ  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 (λ (K : fin n), ite (x = K) 1 0 * A K y)\n            = finset.sum xfinset (λ t, A t y),\n  simp [this],\n--  exact finset.sum_singleton,\n  apply eq.symm,\n  have H1 : finset.sum xfinset (λ (t : fin n), A t y) = finset.sum xfinset (λ (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 ⊆ finset.univ) _),\n  exact finset.subset_univ xfinset,\n  intros K H H2,\n  have H3 : ¬ (x = K),\n    intro H4,\n    apply H2,\n    rw ←H4,\n    apply finset.mem_singleton.2,\n    refl,\n  simp [H3],  \n\nend\n--#check @finset.sum_subset\n--finset.sum_subset :\n--  ∀ {α : Type u_1} {β : Type u_2} {s₁ s₂ : finset α} {f : α → β} [_inst_1 : add_comm_monoid β],\n--    s₁ ⊆ s₂ → (∀ (x : α), x ∈ s₂ → x ∉ s₁ → f x = 0) → finset.sum s₁ f = finset.sum s₂ 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 (λ (K : fin n), A x K * ite (K = y) 1 0 )\n           = finset.sum yfinset (λ t, A x t),  \nsimp [this],\napply eq.symm,\nhave H1 : finset.sum yfinset (λ (t : fin n), A x t) = finset.sum yfinset (λ (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 ⊆ finset.univ) _),\nexact finset.subset_univ yfinset,\nintros K H H2,\nhave H3 : ¬ (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 := λ 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/-\n\ndec_trivial\nfinset.range\nI.val \n-/\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/Ellen_Arlt_matrix_rings.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7900131074125599}}
{"text": "/-\nCopyright (c) 2021 Benjamin Davidson. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Benjamin Davidson\n-/\n\nimport analysis.special_functions.integrals\nopen interval_integral real\nopen_locale real\n\n/-! ### Simple functions -/\n\n/- constants -/\nexample : ∫ x : ℝ in 8..11, (1 : ℝ) = 3 := by norm_num\nexample : ∫ x : ℝ in 5..19, (12 : ℝ) = 168 := by norm_num\n\n/- the identity function -/\nexample : ∫ x : ℝ in (-1)..4, x = 15 / 2 := by norm_num\nexample : ∫ x : ℝ in 4..5, x * 2 = 9 := by norm_num\n\n/- inverse -/\nexample : ∫ x : ℝ in 2..3, x⁻¹ = log (3 / 2) := by norm_num\n\n/- natural powers -/\nexample : ∫ x : ℝ in 2..4, x ^ (3 : ℕ) = 60 := by norm_num\n\n/- trigonometric functions -/\nexample : ∫ x in 0..π, sin x = 2 := by norm_num\nexample : ∫ x in 0..π/4, cos x = sqrt 2 / 2 := by simp\nexample : ∫ x in 0..π, 2 * sin x = 4 := by norm_num\nexample : ∫ x in 0..π/2, cos x / 2 = 1 / 2 := by simp\nexample : ∫ x : ℝ in 0..1, 1 / (1 + x ^ 2) = π / 4 := by simp\nexample : ∫ x in 0..2*π, sin x ^ 2 = π := by simp [mul_div_cancel_left]\nexample : ∫ x in 0..π/2, cos x ^ 2 / 2 = π / 8 := by norm_num [div_div]\nexample : ∫ x in 0..π, cos x ^ 2 - sin x ^ 2 = 0 := by simp [integral_cos_sq_sub_sin_sq]\nexample : ∫ x in 0..π/2, sin x ^ 3 = 2 / 3 := by norm_num\nexample : ∫ x in 0..π/2, cos x ^ 3 = 2 / 3 := by norm_num\nexample : ∫ x in 0..π, sin x * cos x = 0 := by simp\nexample : ∫ x in 0..π, sin x ^ 2 * cos x ^ 2 = π / 8 := by simpa using sin_nat_mul_pi 4\n\n/- the exponential function -/\nexample : ∫ x in 0..2, -exp x = 1 - exp 2 := by simp\n\n/- the logarithmic function -/\nexample : ∫ x in 1..2, log x = 2 * log 2 - 1 := by { norm_num, ring }\n\n/- linear combinations (e.g. polynomials) -/\nexample : ∫ x : ℝ in 0..2, 6*x^5 + 3*x^4 + x^3 - 2*x^2 + x - 7 = 1048 / 15 := by norm_num\nexample : ∫ x : ℝ in 0..1, exp x + 9 * x^8 + x^3 - x/2 + (1 + x^2)⁻¹ = exp 1 + π / 4 := by norm_num\n\n/-! ### Functions composed with multiplication by and/or addition of a constant -/\n\n/- many examples are computable by `norm_num` -/\nexample : ∫ x in 0..2, -exp (-x) = exp (-2) - 1 := by norm_num\nexample : ∫ x in 1..2, exp (5*x - 5) = 1/5 * (exp 5 - 1) := by norm_num\nexample : ∫ x in 0..π, cos (x/2) = 2 := by norm_num\nexample : ∫ x in 0..π/4, sin (2*x) = 1/2 := by norm_num [mul_div_left_comm, mul_one_div]\nexample (ω φ : ℝ) : ω * ∫ θ in 0..π, sin (ω*θ + φ) = cos φ - cos (ω*π + φ) := by simp\n\n/- some examples may require a bit of algebraic massaging -/\nexample {L : ℝ} (h : L ≠ 0) : ∫ x in 0..2/L*π, sin (L/2 * x) = 4 / L :=\nbegin\n  norm_num [div_ne_zero h, ← mul_assoc],\n  field_simp [h, mul_div_cancel],\n  norm_num,\nend\n\n/- you may need to provide `norm_num` with the composition lemma you are invoking if it has a\n  difficult time recognizing the function you are trying to integrate -/\nexample : ∫ x : ℝ in 0..2, 3 * (x + 1) ^ 2 = 26 :=\n  by norm_num [integral_comp_add_right (λ x, x ^ 2)]\nexample : ∫ x : ℝ in -1..0, (1 + (x + 1) ^ 2)⁻¹ = π / 4 :=\n  by simp [integral_comp_add_right (λ x, (1 + x ^ 2)⁻¹)]\n\n/-! ### Compositions of functions (aka \"change of variables\" or \"integration by substitution\") -/\n\n/- `interval_integral.integral_comp_mul_deriv` can be used to simplify integrals of the form\n  `∫ x in a..b, (g ∘ f) x * f' x`, where `f'` is the derivative of `f`, to `∫ x in f a..f b, g x` -/\nexample {a b : ℝ} : ∫ x in a..b, exp (exp x) * exp x = ∫ x in exp a..exp b, exp x :=\nintegral_comp_mul_deriv (λ x hx, has_deriv_at_exp x) continuous_on_exp continuous_exp\n\n/- if it is known (to mathlib), the integral of `g` can then be evaluated using `simp`/`norm_num` -/\nexample : ∫ x in 0..1, exp (exp x) * exp x = exp (exp 1) - exp 1 :=\nby rw integral_comp_mul_deriv (λ x hx, has_deriv_at_exp x) continuous_on_exp continuous_exp; simp\n\n/- a more detailed example -/\nexample : ∫ x in 0..2, exp (x ^ 2) * (2 * x) = exp 4 - 1 :=\nbegin                                                    -- let g := exp x, f := x ^ 2, f' := 2 * x\n  rw integral_comp_mul_deriv (λ x hx, _),                -- simplify to ∫ x in f 0..f 2, g x\n  { norm_num },                                          -- compute the integral\n  { exact continuous_on_const.mul continuous_on_id },    -- show that f' is continuous on [0, 2]\n  { exact continuous_exp },                              -- show that g is continuous\n  { simpa using has_deriv_at_pow 2 x },                  -- show that f' = derivative of f on [0, 2]\nend\n\n/- alternatively, `interval_integral.integral_deriv_comp_mul_deriv` can be used to compute integrals\n  of this same form, provided that you also know that `g` is the derivative of some function -/\nexample : ∫ x : ℝ in 0..1, exp (x ^ 2) * (2 * x) = exp 1 - 1 :=\nbegin\n  rw integral_deriv_comp_mul_deriv (λ x hx, _) (λ x hx, has_deriv_at_exp (x^2)) _ continuous_exp,\n  { simp },\n  { simpa using has_deriv_at_pow 2 x },\n  { exact continuous_on_const.mul continuous_on_id },\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/integration.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7899975507564497}}
{"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\n! This file was ported from Lean 3 source module data.int.parity\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.Nat.Parity\nimport Mathlib.Tactic.Abel\n\n/-!\n# Parity of integers\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\nvariable {m n : ℤ}\n\n@[simp]\ntheorem emod_two_ne_one : ¬n % 2 = 1 ↔ n % 2 = 0 := by\n  cases' emod_two_eq_zero_or_one n with h h <;> simp [h]\n#align int.mod_two_ne_one Int.emod_two_ne_one\n\n-- Porting note: This comment from mathlib3 refers to a future file, revisit it once ported:\n-- euclidean_domain.mod_eq_zero uses (2 ∣ n) as normal form\n@[local simp]\ntheorem emod_two_ne_zero : ¬n % 2 = 0 ↔ n % 2 = 1 := by\n  cases' emod_two_eq_zero_or_one n with h h <;> simp [h]\n#align int.mod_two_ne_zero Int.emod_two_ne_zero\n\ntheorem even_iff : Even n ↔ n % 2 = 0 :=\n  ⟨fun ⟨m, hm⟩ => by simp [← two_mul, hm],\n    fun h => ⟨n / 2, (emod_add_ediv n 2).symm.trans (by simp [← two_mul, h])⟩⟩\n#align int.even_iff Int.even_iff\n\ntheorem odd_iff : Odd n ↔ n % 2 = 1 :=\n  ⟨fun ⟨m, hm⟩ => (by rw [hm, add_emod]; norm_num),\n    fun h => ⟨n / 2, (emod_add_ediv n 2).symm.trans (by rw [h]; abel)⟩⟩\n#align int.odd_iff Int.odd_iff\n\ntheorem not_even_iff : ¬Even n ↔ n % 2 = 1 := by rw [even_iff, emod_two_ne_zero]\n#align int.not_even_iff Int.not_even_iff\n\ntheorem not_odd_iff : ¬Odd n ↔ n % 2 = 0 := by rw [odd_iff, emod_two_ne_one]\n#align int.not_odd_iff Int.not_odd_iff\n\ntheorem even_iff_not_odd : Even n ↔ ¬Odd n := by rw [not_odd_iff, even_iff]\n#align int.even_iff_not_odd Int.even_iff_not_odd\n\n@[simp]\ntheorem odd_iff_not_even : Odd n ↔ ¬Even n := by rw [not_even_iff, odd_iff]\n#align int.odd_iff_not_even Int.odd_iff_not_even\n\ntheorem isCompl_even_odd : IsCompl { n : ℤ | Even n } { n | Odd n } := by\n  simp [← Set.compl_setOf, isCompl_compl]\n#align int.is_compl_even_odd Int.isCompl_even_odd\n\ntheorem even_or_odd (n : ℤ) : Even n ∨ Odd n :=\n  Or.imp_right odd_iff_not_even.2 <| em <| Even n\n#align int.even_or_odd Int.even_or_odd\n\ntheorem even_or_odd' (n : ℤ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 := by\n  simpa only [two_mul, exists_or, Odd, Even] using even_or_odd n\n#align int.even_or_odd' Int.even_or_odd'\n\ntheorem even_xor'_odd (n : ℤ) : Xor' (Even n) (Odd n) := by\n  cases even_or_odd n with\n  | inl h => exact Or.inl ⟨h, even_iff_not_odd.mp h⟩\n  | inr h => exact Or.inr ⟨h, odd_iff_not_even.mp h⟩\n#align int.even_xor_odd Int.even_xor'_odd\n\ntheorem even_xor'_odd' (n : ℤ) : ∃ k, Xor' (n = 2 * k) (n = 2 * k + 1) := by\n  rcases even_or_odd n with (⟨k, rfl⟩ | ⟨k, rfl⟩) <;> use k\n  · simpa only [← two_mul, Xor', true_and_iff, eq_self_iff_true, not_true, or_false_iff,\n      and_false_iff] using (succ_ne_self (2 * k)).symm\n  · simp only [Xor', add_right_eq_self, false_or_iff, eq_self_iff_true, not_true, not_false_iff,\n      one_ne_zero, and_self_iff]\n#align int.even_xor_odd' Int.even_xor'_odd'\n\n@[simp]\ntheorem two_dvd_ne_zero : ¬2 ∣ n ↔ n % 2 = 1 :=\n  even_iff_two_dvd.symm.not.trans not_even_iff\n#align int.two_dvd_ne_zero Int.two_dvd_ne_zero\n\ninstance : DecidablePred (Even : ℤ → Prop) := fun _ => decidable_of_iff _ even_iff.symm\n\ninstance : DecidablePred (Odd : ℤ → Prop) := fun _ => decidable_of_iff _ odd_iff_not_even.symm\n\n@[simp]\ntheorem not_even_one : ¬Even (1 : ℤ) := by\n  rw [even_iff]\n  norm_num\n#align int.not_even_one Int.not_even_one\n\n@[parity_simps]\ntheorem even_add : Even (m + n) ↔ (Even m ↔ Even n) := by\n  cases' emod_two_eq_zero_or_one m with h₁ h₁ <;>\n  cases' emod_two_eq_zero_or_one n with h₂ h₂ <;>\n  simp [even_iff, h₁, h₂, Int.add_emod]\n#align int.even_add Int.even_add\n\ntheorem even_add' : Even (m + n) ↔ (Odd m ↔ Odd n) := by\n  rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n#align int.even_add' Int.even_add'\n\nset_option linter.deprecated false in\n\n@[simp, deprecated]\ntheorem not_even_bit1 (n : ℤ) : ¬Even (bit1 n) := by simp [bit1, parity_simps]\n#align int.not_even_bit1 Int.not_even_bit1\n\ntheorem two_not_dvd_two_mul_add_one (n : ℤ) : ¬2 ∣ 2 * n + 1 := by\n  simp [add_emod]\n#align int.two_not_dvd_two_mul_add_one Int.two_not_dvd_two_mul_add_one\n\n@[parity_simps]\ntheorem even_sub : Even (m - n) ↔ (Even m ↔ Even n) := by\n  simp [sub_eq_add_neg, parity_simps]\n#align int.even_sub Int.even_sub\n\ntheorem even_sub' : Even (m - n) ↔ (Odd m ↔ Odd n) := by\n  rw [even_sub, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n#align int.even_sub' Int.even_sub'\n\n@[parity_simps]\ntheorem even_add_one : Even (n + 1) ↔ ¬Even n := by\n  simp [even_add]\n#align int.even_add_one Int.even_add_one\n\n@[parity_simps]\ntheorem even_mul : Even (m * n) ↔ Even m ∨ Even n := by\n  cases' emod_two_eq_zero_or_one m with h₁ h₁ <;>\n  cases' emod_two_eq_zero_or_one n with h₂ h₂ <;>\n  simp [even_iff, h₁, h₂, Int.mul_emod]\n#align int.even_mul Int.even_mul\n\ntheorem odd_mul : Odd (m * n) ↔ Odd m ∧ Odd n := by simp [not_or, parity_simps]\n#align int.odd_mul Int.odd_mul\n\ntheorem Odd.of_mul_left (h : Odd (m * n)) : Odd m :=\n  (odd_mul.mp h).1\n#align int.odd.of_mul_left Int.Odd.of_mul_left\n\ntheorem Odd.of_mul_right (h : Odd (m * n)) : Odd n :=\n  (odd_mul.mp h).2\n#align int.odd.of_mul_right Int.Odd.of_mul_right\n\n@[parity_simps]\ntheorem even_pow {n : ℕ} : Even (m ^ n) ↔ Even m ∧ n ≠ 0 := by\n  induction' n with n ih <;> simp [*, even_mul, pow_succ]\n  tauto\n#align int.even_pow Int.even_pow\n\ntheorem even_pow' {n : ℕ} (h : n ≠ 0) : Even (m ^ n) ↔ Even m :=\n  even_pow.trans <| and_iff_left h\n#align int.even_pow' Int.even_pow'\n\n@[parity_simps]\ntheorem odd_add : Odd (m + n) ↔ (Odd m ↔ Even n) := by\n  rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even]\n#align int.odd_add Int.odd_add\n\ntheorem odd_add' : Odd (m + n) ↔ (Odd n ↔ Even m) := by\n  rw [add_comm, odd_add]\n#align int.odd_add' Int.odd_add'\n\ntheorem ne_of_odd_add (h : Odd (m + n)) : m ≠ n :=\n  fun hnot => by simp [hnot, parity_simps] at h\n#align int.ne_of_odd_add Int.ne_of_odd_add\n\n@[parity_simps]\ntheorem odd_sub : Odd (m - n) ↔ (Odd m ↔ Even n) := by\n  rw [odd_iff_not_even, even_sub, not_iff, odd_iff_not_even]\n#align int.odd_sub Int.odd_sub\n\ntheorem odd_sub' : Odd (m - n) ↔ (Odd n ↔ Even m) := by\n  rw [odd_iff_not_even, even_sub, not_iff, not_iff_comm, odd_iff_not_even]\n#align int.odd_sub' Int.odd_sub'\n\ntheorem even_mul_succ_self (n : ℤ) : Even (n * (n + 1)) := by\n  simpa [even_mul, parity_simps] using n.even_or_odd\n#align int.even_mul_succ_self Int.even_mul_succ_self\n\n@[simp, norm_cast]\ntheorem even_coe_nat (n : ℕ) : Even (n : ℤ) ↔ Even n := by\n  rw_mod_cast [even_iff, Nat.even_iff]\n#align int.even_coe_nat Int.even_coe_nat\n\n-- Porting note: was simp. simp can prove this.\n@[norm_cast]\ntheorem odd_coe_nat (n : ℕ) : Odd (n : ℤ) ↔ Odd n := by\n  rw [odd_iff_not_even, Nat.odd_iff_not_even, even_coe_nat]\n#align int.odd_coe_nat Int.odd_coe_nat\n\n@[simp]\ntheorem natAbs_even : Even n.natAbs ↔ Even n := by\n  simp [even_iff_two_dvd, dvd_natAbs, coe_nat_dvd_left.symm]\n#align int.nat_abs_even Int.natAbs_even\n\n-- Porting note: was simp. simp can prove this.\n--@[simp]\ntheorem natAbs_odd : Odd n.natAbs ↔ Odd n := by\n  rw [odd_iff_not_even, Nat.odd_iff_not_even, natAbs_even]\n#align int.nat_abs_odd Int.natAbs_odd\n\nalias natAbs_even ↔ _ _root_.Even.natAbs\n#align even.nat_abs Even.natAbs\n\nalias natAbs_odd ↔ _ _root_.Odd.natAbs\n#align odd.nat_abs Odd.natAbs\n\n-- Porting note: \"protected\"-attribute not implemented yet.\n-- mathlib3 had:\n-- `attribute [protected] Even.natAbs Odd.natAbs`\n\ntheorem four_dvd_add_or_sub_of_odd {a b : ℤ} (ha : Odd a) (hb : Odd b) :\n    4 ∣ a + b ∨ 4 ∣ a - b := by\n  obtain ⟨m, rfl⟩ := ha\n  obtain ⟨n, rfl⟩ := hb\n  obtain h | h := Int.even_or_odd (m + n)\n  · right\n    rw [Int.even_add, ← Int.even_sub] at h\n    obtain ⟨k, hk⟩ := h\n    convert dvd_mul_right 4 k using 1\n    rw [eq_add_of_sub_eq hk, mul_add, add_assoc, add_sub_cancel, ← two_mul, ← mul_assoc]\n    rfl\n  · left\n    obtain ⟨k, hk⟩ := h\n    convert dvd_mul_right 4 (k + 1) using 1\n    rw [eq_sub_of_add_eq hk, add_right_comm, ← add_sub, mul_add, mul_sub, add_assoc, add_assoc,\n      sub_add, add_assoc, ← sub_sub (2 * n), sub_self, zero_sub, sub_neg_eq_add, ← mul_assoc,\n      mul_add]\n    rfl\n#align int.four_dvd_add_or_sub_of_odd Int.four_dvd_add_or_sub_of_odd\n\ntheorem two_mul_ediv_two_of_even : Even n → 2 * (n / 2) = n :=\n  fun h => Int.mul_ediv_cancel' (even_iff_two_dvd.mp h)\n#align int.two_mul_div_two_of_even Int.two_mul_ediv_two_of_even\n\ntheorem ediv_two_mul_two_of_even : Even n → n / 2 * 2 = n :=\n  fun h => Int.ediv_mul_cancel (even_iff_two_dvd.mp h)\n#align int.div_two_mul_two_of_even Int.ediv_two_mul_two_of_even\n\ntheorem two_mul_ediv_two_add_one_of_odd : Odd n → 2 * (n / 2) + 1 = n := by\n  rintro ⟨c, rfl⟩\n  rw [mul_comm]\n  convert Int.ediv_add_emod' (2 * c + 1) 2\n  simp [Int.add_emod]\n#align int.two_mul_div_two_add_one_of_odd Int.two_mul_ediv_two_add_one_of_odd\n\ntheorem ediv_two_mul_two_add_one_of_odd : Odd n → n / 2 * 2 + 1 = n := by\n  rintro ⟨c, rfl⟩\n  convert Int.ediv_add_emod' (2 * c + 1) 2\n  simp [Int.add_emod]\n#align int.div_two_mul_two_add_one_of_odd Int.ediv_two_mul_two_add_one_of_odd\n\ntheorem add_one_ediv_two_mul_two_of_odd : Odd n → 1 + n / 2 * 2 = n := by\n  rintro ⟨c, rfl⟩\n  rw [add_comm]\n  convert Int.ediv_add_emod' (2 * c + 1) 2\n  simp [Int.add_emod]\n#align int.add_one_div_two_mul_two_of_odd Int.add_one_ediv_two_mul_two_of_odd\n\ntheorem two_mul_ediv_two_of_odd (h : Odd n) : 2 * (n / 2) = n - 1 :=\n  eq_sub_of_add_eq (two_mul_ediv_two_add_one_of_odd h)\n#align int.two_mul_div_two_of_odd Int.two_mul_ediv_two_of_odd\n\n-- Here are examples of how `parity_simps` can be used with `int`.\nexample (m n : ℤ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by\n  simp [*, (by decide : ¬2 = 0), parity_simps]\n\nexample : ¬Even (25394535 : ℤ) := by simp\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/Parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948495, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7899975407890198}}
{"text": "import tactic\n\n-- Let `Ω` be a \"big underlying set\" and let `X` and `Y` and `Z` be subsets\n\nvariables (Ω : Type) (X Y Z : set Ω) (a b c x y z : Ω)\n\nnamespace xena\n\n/-!\n\n# subsets\n\nLet's think about `X ⊆ Y`. Typeset `⊆` with `\\sub` or `\\ss`\n-/\n\n-- `X ⊆ Y` is the same as `∀ a, a ∈ X → a ∈ Y` , by definition.\n\nlemma subset_def : X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y :=\nbegin\n  -- true by definition\n  refl\nend\n\nlemma subset_refl : X ⊆ X :=\nbegin\n  rw subset_def,\n  -- goal now \"for all a, ...\" and `intro` makes progress with this.\n  intros a ha,\n  exact ha,\nend\n\nlemma subset_trans (hXY : X ⊆ Y) (hYZ : Y ⊆ Z) : X ⊆ Z :=\nbegin\n  rw subset_def at *,\n  intros a ha,\n  -- ⊢ a ∈ Z\n  -- hYZ says: a ∈ Y → a ∈ Z. So... \n  apply hYZ,\n  -- ⊢ a ∈ Y\n  apply hXY,\n  exact ha,\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 ↔ (∀ a, a ∈ X ↔ a ∈ Y) :=\nbegin\n  exact set.ext_iff\nend\n\n-- In practice, you often have a goal `⊢ X = Y` and you want to reduce\n-- it to `a ∈ X ↔ a ∈ Y` for an arbitary `a : Ω`. This can be done with\n-- the `ext` tactic. \n\n\nlemma subset.antisymm (hXY : X ⊆ Y) (hYX : Y ⊆ X) : X = Y :=\nbegin\n  ext a,\n  split,\n  { apply hXY },\n  { apply hYX }\nend\n\n/-!\n\n### Unions and intersections\n\nType `\\cup` or `\\un` for `∪`, and `\\cap` or `\\i` for `∩`\n\n-/\n\nlemma mem_union_iff : a ∈ X ∪ Y ↔ a ∈ X ∨ a ∈ Y :=\nbegin\n  -- true by definition\n  refl,\nend\n\nlemma mem_inter_iff : a ∈ X ∩ Y ↔ a ∈ X ∧ a ∈ 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-- if you want to use `mem_union_iff` you should start with `ext`\n\nlemma union_self : X ∪ X = X :=\nbegin\n  ext a,\n  rw mem_union_iff,\n  split,\n  { intro h,\n    cases h with ha ha;\n    exact ha },\n  { intro ha,\n    left,\n    exact ha }\nend\n\nlemma subset_union_left : X ⊆ X ∪ Y :=\nbegin\n  rw subset_def,\n  intros a haX,\n  rw mem_union_iff,\n  left,\n  assumption,\nend\n\nlemma subset_union_right : Y ⊆ X ∪ Y :=\nbegin\n  -- don't need to rewrite subset_def or mem_union_iff\n  -- as they're both true by definition\n  intros a haY,\n  right,\n  assumption,\nend\n\nlemma union_subset_iff : X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nbegin\n  -- NB Lean's simplifier `simp` solves this (and many others)\n  -- as do the tactics `finish` and `tidy`\n  -- We will talk a bit more about `simp` in week 2.\n  split,\n  { intro h,\n    split,\n    { intros a haX,\n      apply h,\n      left,\n      assumption },\n    { intros a haY,\n      apply h,\n      right,\n      assumption },\n  },\n  { rintros ⟨hXZ, hYZ⟩ a (haX | haY),\n    { exact hXZ haX },\n    { exact hYZ haY } }\nend\n\nvariable (W : set Ω)\n\nlemma union_subset_union (hWX : W ⊆ X) (hYZ : Y ⊆ Z) : W ∪ Y ⊆ X ∪ 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 ⊆ Y) : X ∪ Z ⊆ Y ∪ Z :=\nbegin\n  rintros a (haX | haZ),\n  { left, \n    exact hXY haX },\n  { right,\n    assumption }\nend\n\n-- etc etc\n\n-- intersection lemmas\n\nlemma inter_subset_left : X ∩ Y ⊆ X :=\nbegin\n  rintro a ⟨haX, haY⟩,\n  assumption,\nend\n\n-- don't forget `ext` to make progress with equalities of sets\n\nlemma inter_self : X ∩ X = X :=\nbegin\n  ext a,\n  split,\n  { rintro ⟨ha, -⟩,\n    assumption },\n  { intro ha,\n    exact ⟨ha, ha⟩ }\nend\n\nlemma inter_comm : X ∩ Y = Y ∩ X :=\nbegin\n  ext a,\n  split;\n  { rintro ⟨h1, h2⟩,\n    exact ⟨h2, h1⟩ }\nend\n\nlemma inter_assoc : X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z :=\nbegin\n--  finish,\n  -- tidy works too,\n  ext a,\n  split,\n  { rintro ⟨hx, hy, hz⟩, -- try `rintro?` to see the syntax\n    exact ⟨⟨hx, hy⟩, hz⟩ },\n  { rintro ⟨⟨hx, hy⟩, hz⟩,\n    exact ⟨hx, hy, hz⟩ },\nend\n\n/-!\n\n### Forall and exists\n\n-/\n\nlemma not_exists_iff_forall_not : ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X) :=\nbegin\n  split,\n  { intros h b hb,\n    apply h,\n    use b,\n    assumption },\n  { rintro h ⟨a, ha⟩,\n    exact h a ha },\nend\n\n\n\nexample : ¬ (∀ a, a ∈ X) ↔ ∃ b, ¬ (b ∈ X) :=\nbegin\n  split,\n  { -- you need classical logic to do this part\n    -- `contrapose!` is a way of making progress\n    -- `finish` does it completely.\n    -- We use `by_contra`, which\n    -- turns a goal `⊢ P` into \n    -- a hypothesis `h : ¬ P` and\n    -- a goal of `false`\n    intro h,\n    by_contra hnX,\n    apply h,\n    intro a,\n    by_contra hXa,\n    apply hnX,\n    use a, }, \n  { intro h,\n    cases h with b hb,\n    intro h,\n    apply hb,\n    apply 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_B_sets_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7899178149298395}}
{"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.nat\nopen nat\n\ndefinition fib : nat → nat\n| 0     := 1\n| 1     := 1\n| (n+2) := fib (n+1) + fib n\n\nprivate definition fib_fast_aux : nat → (nat × nat)\n| 0     := (0, 1)\n| 1     := (1, 1)\n| (n+2) :=\n  match fib_fast_aux (n+1) with\n  | (fn, fn1) := (fn1, fn1 + fn)\n  end\n\nopen prod.ops -- Get .1 .2 notation for pairs\n\ndefinition fib_fast (n : nat) := (fib_fast_aux n).2\n\n-- We now prove that fib_fast and fib are equal\n\nlemma fib_fast_aux_lemma : ∀ n, (fib_fast_aux (succ n)).1 = (fib_fast_aux n).2\n| 0               := rfl\n| 1               := rfl\n| (succ (succ n)) :=\n  begin\n    unfold fib_fast_aux at {1},\n    rewrite [-prod.eta (fib_fast_aux _)],\n  end\n\ntheorem fib_eq_fib_fast : ∀ n, fib_fast n = fib n\n| 0               := rfl\n| 1               := rfl\n| (succ (succ n)) :=\n  begin\n    have feq  : fib_fast n = fib n,               from fib_eq_fib_fast n,\n    have f1eq : fib_fast (succ n) = fib (succ n), from fib_eq_fib_fast (succ n),\n    unfold [fib, fib_fast, fib_fast_aux],\n    rewrite [-prod.eta (fib_fast_aux _)],\n    fold fib_fast (succ n), rewrite f1eq,\n    rewrite fib_fast_aux_lemma,\n    fold fib_fast n, rewrite feq,\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/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8705972801594707, "lm_q1q2_score": 0.7899035521720068}}
{"text": "namespace hidden\n\n-- BEGIN\ninductive nat : Type\n| zero : nat\n| succ : nat → nat\n-- END\n\ndef Z := nat.zero\ndef S := nat.succ\n\ndef K₁ := S Z\ndef K₂ := S K₁\ndef K₃ := S K₂\ndef K₄ := S K₃\ndef K₅ := S K₄\n\ndef pred (n: nat): nat := begin\ncases n,\ncase nat.zero: { exact Z },\ncase nat.succ: m { exact m }\nend\n\ntheorem pr₀ : pred Z = Z := rfl.\ntheorem pr₁ : pred K₁ = Z := rfl.\ntheorem pr₂ : pred K₂ = K₁ := rfl.\n\ntheorem pred_succ_zero (n: nat): pred (S n) = n := rfl.\n\ndef sub (n m: nat): nat := nat.rec_on m n (λ m n_sub_m, pred n_sub_m).\n\n#reduce sub Z K₂\n#reduce sub K₅ K₂\n\n\nexample: sub nat.zero K₅ = nat.zero := rfl\ntheorem sub_n_0 (n: nat): sub n Z = n := rfl\ntheorem sub_0_m (m: nat): sub Z m = Z := begin\ninduction m,\ncase nat.zero: { reflexivity },\ncase nat.succ: m ih {\n  calc sub Z (S m) = pred (sub Z m): rfl\n   ... = pred Z: by rw ih\n}\nend\n\nlemma sub_succ (n m: nat): sub (S n) (S m) = sub n m := begin\ninduction m,\ncase nat.zero: {\n  reflexivity\n},\ncase nat.succ: m ih {\n  have: sub (S n) (S (S m)) = pred (sub (S n) (S m)), from rfl,\n  have: sub (S n) (S (S m)) = pred (sub n m), by rw[this, ih],\n  have: pred (sub n m) = sub n (S m), by reflexivity,\n  assumption\n}\nend\n\ntheorem sub_n_n (n: nat): sub n n = Z := begin\ninduction n,\ncase nat.zero: { reflexivity },\ncase nat.succ: n ih {\n  have: sub (nat.succ n) (nat.succ n) = sub n n, from sub_succ n n,\n  rw [this], assumption\n}\nend\n\ndef add (m n : nat) : nat := nat.rec_on n m (λ n add_m_n, S add_m_n)\n\nlemma add_n_succ (m n: nat): add m (nat.succ n) = nat.succ (add m n) := rfl.\nlemma add_m_succ (m n: nat): add (nat.succ m) n = nat.succ (add m n) := begin\ninduction n, reflexivity,\ncase nat.succ: n ih {\n  simp[add_n_succ], assumption\n}\nend\n\nlemma add_m_0 (m: nat): add m Z = m := rfl. \nlemma add_0_n (n: nat): add Z n = n := begin\ninduction n, reflexivity,\ncase nat.succ: n ih {\n  simp[add_n_succ], assumption\n}\nend\n\ntheorem add_assoc (a b c: nat): add (add a b) c = add a (add b c) := begin\ninduction c, reflexivity,\ncase nat.succ: c ih {\n  simp [add_n_succ], assumption,\n}\nend\n\ntheorem add_comm (m n : nat) : add m n = add n m :=\nbegin\n  induction n,\n  case nat.zero : { rw[<-Z, add_m_0, add_0_n] },\n  case nat.succ : n ih { rw [add_n_succ, add_m_succ, ih] }\nend\n\n#reduce add K₁ K₂\n\ndef mul (m n: nat): nat := nat.rec_on n Z (λ n acc, add m acc)\n\n#reduce mul Z K₂\n#reduce mul K₂ Z\n#reduce mul K₁ K₂\n#reduce mul K₂ K₂\n#reduce mul K₅ K₂\n\nlemma mul_succ_n (m n: nat): mul m (nat.succ n) = add m (mul m n) := rfl.\nlemma mul_succ_m (m n: nat): mul (nat.succ m) n = add (mul m n) n := begin\ninduction n, reflexivity,\ncase nat.succ: n ih {\n  simp [mul_succ_n],\n  rw ih,\n  simp [add_n_succ, add_m_succ],\n  simp [add_assoc],\n}\nend\n\ntheorem mul_m_0 (m: nat): mul m Z = Z := rfl.\ntheorem mul_0_n (n: nat): mul Z n = Z := begin\ninduction n,\n  case nat.zero: {reflexivity},\n  case nat.succ: n ih {\n    rw [mul_succ_n Z n],\n    rw ih, reflexivity\n  }\nend\n\ntheorem mul_m_1 (m: nat): mul m K₁ = m := rfl\ntheorem mul_1_n (n: nat): mul K₁ n = n := begin\n  rw [K₁, S, Z],\n  simp [mul_succ_m], \n  rw [<-Z, mul_0_n n, add_0_n] \nend\n\ntheorem mul_comm (m n: nat): mul m n = mul n m := begin\ninduction m, \ncase nat.zero { \n  rw [<-Z, mul_m_0, mul_0_n],\n},\ncase nat.succ: m ih {\n  rw [mul_succ_n, mul_succ_m, ih, add_comm],\n}\nend\n\ntheorem mul_dist (a b c: nat): mul a (add b c) = add (mul a b) (mul a c) := begin\ninduction a,\ncase nat.zero {\n  rw [<-Z, mul_0_n, mul_0_n, mul_0_n], reflexivity\n},\ncase nat.succ: a ih {\n  rw [mul_succ_m, mul_succ_m, mul_succ_m, ih],\n  repeat { rw [add_assoc] },\n  repeat { rw [<-add_assoc]},\n  repeat { rw [add_assoc] },\n  rw [<-add_assoc (mul a c), <-add_assoc b, add_comm (mul a c)],\n}\nend\n\ntheorem mul_assoc (a b c: nat): mul (mul a b) c = mul a (mul b c) := begin\ninduction c, reflexivity,\ncase nat.succ: c ih {\n  rw [mul_succ_n, ih, mul_succ_n, mul_dist]\n}\nend\n\ntheorem succ_nonzero (n: nat): S n ≠ Z := by trivial.\ndef nonzero := {n: nat // n ≠ Z}\ndef nonzero.mk (n: nat) (h: n ≠ Z): nonzero := ⟨n,h⟩\ndef nz := nonzero.mk.\n#check nz K₂ (by apply succ_nonzero)\n\ndef pow (m: nonzero) (n: nat): nat := nat.rec_on n K₁ (λ n acc, mul m.val acc)\n\ndef nzK₁ := nz (S Z) (by apply succ_nonzero)\ndef nzK₂ := nz (S K₁) (by apply succ_nonzero)\ndef nzK₃ := nz (S K₂) (by apply succ_nonzero)\ndef nzK₄ := nz (S K₃) (by apply succ_nonzero)\ndef nzK₅ := nz (S K₄) (by apply succ_nonzero)\n\n#reduce pow nzK₂ Z\n#reduce pow nzK₁ K₂\n#reduce pow nzK₂ K₂\n#reduce pow nzK₅ K₂\n\ntheorem pow_by_0 (m: nonzero): pow m Z = K₁ := rfl.\ntheorem pow_by_1 (m: nonzero): pow m K₁ = m.val := rfl.\ntheorem pow_by_succ (m: nonzero) (n: nat): pow m (nat.succ n) = mul m.val (pow m n) := rfl.\ntheorem pow_of_1 (n: nat): pow nzK₁ n = K₁ := begin\ninduction n, reflexivity,\ncase nat.succ: n ih {\n  have o: nzK₁.val = K₁, from rfl,\n  have: pow nzK₁ (nat.succ n) = mul nzK₁.val (pow nzK₁ n), by rw [pow_by_succ],\n  rw [o, mul_1_n] at this,\n  rw [this, ih]\n}\nend\n\ntheorem pow_by_add (m: nonzero) (a b: nat): pow m (add a b) = mul (pow m a) (pow m b) := begin\ninduction b, reflexivity,\ncase nat.succ: b ih {\n  have sab: add a (nat.succ b) = nat.succ (add a b), by reflexivity,\n  calc pow m (add a (nat.succ b)) = pow m (nat.succ (add a b)): by rw sab\n    ... = mul m.val (pow m (add a b)): by rw pow_by_succ\n    ... = mul m.val (mul (pow m a) (pow m b)): by rw ih\n    ... = mul (mul m.val (pow m b)) (pow m a): by rw [mul_comm (pow m a), mul_assoc]\n    ... = mul (pow m (nat.succ b)) (pow m a): by rw <-pow_by_succ\n    ... = mul (pow m a) (pow m (nat.succ b)): by rw mul_comm\n}\nend\n\nend hidden", "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/7.10.1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7899035436920406}}
{"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 17ef379e997badd73e5eabb4d38f11919ab3c4b3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Analysis.Normed.Group.Basic\n\n/-!\n# Hamming spaces\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* `hammingDist x y`: the Hamming distance between `x` and `y`, the number of entries which differ.\n* `hammingNorm x`: the Hamming norm of `x`, the number of non-zero entries.\n* `Hamming β`: a type synonym for `Π i, β i` with `dist` and `norm` provided by the above.\n* `Hamming.toHamming`, `Hamming.ofHamming`: functions for casting between `Hamming β` and\n`Π i, β i`.\n* the Hamming norm forms a normed group on `Hamming β`.\n-/\n\n\nsection HammingDistNorm\n\nopen Finset Function\n\nvariable {α ι : Type _} {β : ι → Type _} [Fintype ι] [∀ i, DecidableEq (β i)]\n\nvariable {γ : ι → Type _} [∀ i, DecidableEq (γ i)]\n\n/-- The Hamming distance function to the naturals. -/\ndef hammingDist (x y : ∀ i, β i) : ℕ :=\n  (univ.filter fun i => x i ≠ y i).card\n#align hamming_dist hammingDist\n\n/-- Corresponds to `dist_self`. -/\n@[simp]\ntheorem hammingDist_self (x : ∀ i, β i) : hammingDist x x = 0 := 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/-- Corresponds to `dist_nonneg`. -/\ntheorem hammingDist_nonneg {x y : ∀ i, β i} : 0 ≤ hammingDist x y :=\n  zero_le _\n#align hamming_dist_nonneg hammingDist_nonneg\n\n/-- Corresponds to `dist_comm`. -/\ntheorem hammingDist_comm (x y : ∀ i, β i) : hammingDist x y = hammingDist y x := by\n  simp_rw [hammingDist, ne_comm]\n#align hamming_dist_comm hammingDist_comm\n\n/-- Corresponds to `dist_triangle`. -/\ntheorem hammingDist_triangle (x y z : ∀ i, β i) :\n    hammingDist x z ≤ hammingDist x y + hammingDist y z := by\n  classical\n    unfold hammingDist\n    refine le_trans (card_mono ?_) (card_union_le _ _)\n    rw [← filter_or]\n    exact monotone_filter_right _ fun i h ↦ (h.ne_or_ne _).imp_right Ne.symm\n#align hamming_dist_triangle hammingDist_triangle\n\n/-- Corresponds to `dist_triangle_left`. -/\ntheorem hammingDist_triangle_left (x y z : ∀ i, β i) :\n    hammingDist x y ≤ hammingDist z x + hammingDist z y := by\n  rw [hammingDist_comm z]\n  exact hammingDist_triangle _ _ _\n#align hamming_dist_triangle_left hammingDist_triangle_left\n\n/-- Corresponds to `dist_triangle_right`. -/\ntheorem hammingDist_triangle_right (x y z : ∀ i, β i) :\n    hammingDist x y ≤ hammingDist x z + hammingDist y z := by\n  rw [hammingDist_comm y]\n  exact hammingDist_triangle _ _ _\n#align hamming_dist_triangle_right hammingDist_triangle_right\n\n/-- Corresponds to `swap_dist`. -/\ntheorem swap_hammingDist : swap (@hammingDist _ β _ _) = hammingDist := by\n  funext x y\n  exact hammingDist_comm _ _\n#align swap_hamming_dist swap_hammingDist\n\n/-- Corresponds to `eq_of_dist_eq_zero`. -/\ntheorem eq_of_hammingDist_eq_zero {x y : ∀ i, β i} : hammingDist x y = 0 → 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/-- Corresponds to `dist_eq_zero`. -/\n@[simp]\ntheorem hammingDist_eq_zero {x y : ∀ i, β i} : hammingDist x y = 0 ↔ x = y :=\n  ⟨eq_of_hammingDist_eq_zero, fun H => by\n    rw [H]\n    exact hammingDist_self _⟩\n#align hamming_dist_eq_zero hammingDist_eq_zero\n\n/-- Corresponds to `zero_eq_dist`. -/\n@[simp]\ntheorem hamming_zero_eq_dist {x y : ∀ i, β i} : 0 = hammingDist x y ↔ x = y := by\n  rw [eq_comm, hammingDist_eq_zero]\n#align hamming_zero_eq_dist hamming_zero_eq_dist\n\n/-- Corresponds to `dist_ne_zero`. -/\ntheorem hammingDist_ne_zero {x y : ∀ i, β i} : hammingDist x y ≠ 0 ↔ x ≠ y :=\n  hammingDist_eq_zero.not\n#align hamming_dist_ne_zero hammingDist_ne_zero\n\n/-- Corresponds to `dist_pos`. -/\n@[simp]\ntheorem hammingDist_pos {x y : ∀ i, β i} : 0 < hammingDist x y ↔ x ≠ y := by\n  rw [← hammingDist_ne_zero, iff_not_comm, not_lt, le_zero_iff]\n#align hamming_dist_pos hammingDist_pos\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem hammingDist_lt_one {x y : ∀ i, β i} : hammingDist x y < 1 ↔ x = y := by\n  rw [Nat.lt_one_iff, hammingDist_eq_zero]\n#align hamming_dist_lt_one hammingDist_lt_one\n\ntheorem hammingDist_le_card_fintype {x y : ∀ i, β i} : hammingDist x y ≤ Fintype.card ι :=\n  card_le_univ _\n#align hamming_dist_le_card_fintype hammingDist_le_card_fintype\n\ntheorem hammingDist_comp_le_hammingDist (f : ∀ i, γ i → β i) {x y : ∀ i, γ i} :\n    (hammingDist (fun i => f i (x i)) fun i => f i (y i)) ≤ 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\ntheorem hammingDist_comp (f : ∀ i, γ i → β i) {x y : ∀ i, γ i} (hf : ∀ i, Injective (f i)) :\n    (hammingDist (fun i => f i (x i)) fun i => f i (y i)) = hammingDist x y :=\n  le_antisymm (hammingDist_comp_le_hammingDist _) <|\n    card_mono (monotone_filter_right _ fun i H1 H2 => H1 <| hf i H2)\n#align hamming_dist_comp hammingDist_comp\n\ntheorem hammingDist_smul_le_hammingDist [∀ i, SMul α (β i)] {k : α} {x y : ∀ i, β i} :\n    hammingDist (k • x) (k • y) ≤ hammingDist x y :=\n  hammingDist_comp_le_hammingDist fun i => (k • · : β i → β i)\n#align hamming_dist_smul_le_hamming_dist hammingDist_smul_le_hammingDist\n\n/-- Corresponds to `dist_smul` with the discrete norm on `α`. -/\ntheorem hammingDist_smul [∀ i, SMul α (β i)] {k : α} {x y : ∀ i, β i}\n    (hk : ∀ i, IsSMulRegular (β i) k) : hammingDist (k • x) (k • y) = hammingDist x y :=\n  hammingDist_comp (fun i => (k • · : β i → β i)) hk\n#align hamming_dist_smul hammingDist_smul\n\nsection Zero\n\nvariable [∀ i, Zero (β i)] [∀ i, Zero (γ i)]\n\n/-- The Hamming weight function to the naturals. -/\ndef hammingNorm (x : ∀ i, β i) : ℕ :=\n  (univ.filter (x · ≠ 0)).card\n#align hamming_norm hammingNorm\n\n/-- Corresponds to `dist_zero_right`. -/\n@[simp]\ntheorem hammingDist_zero_right (x : ∀ i, β i) : hammingDist x 0 = hammingNorm x :=\n  rfl\n#align hamming_dist_zero_right hammingDist_zero_right\n\n/-- Corresponds to `dist_zero_left`. -/\n@[simp]\ntheorem hammingDist_zero_left : hammingDist (0 : ∀ i, β i) = hammingNorm :=\n  funext fun x => by rw [hammingDist_comm, hammingDist_zero_right]\n#align hamming_dist_zero_left hammingDist_zero_left\n\n/-- Corresponds to `norm_nonneg`. -/\n-- @[simp] -- Porting note: simp can prove this\ntheorem hammingNorm_nonneg {x : ∀ i, β i} : 0 ≤ hammingNorm x :=\n  zero_le _\n#align hamming_norm_nonneg hammingNorm_nonneg\n\n/-- Corresponds to `norm_zero`. -/\n@[simp]\ntheorem hammingNorm_zero : hammingNorm (0 : ∀ i, β i) = 0 :=\n  hammingDist_self _\n#align hamming_norm_zero hammingNorm_zero\n\n/-- Corresponds to `norm_eq_zero`. -/\n@[simp]\ntheorem hammingNorm_eq_zero {x : ∀ i, β i} : hammingNorm x = 0 ↔ x = 0 :=\n  hammingDist_eq_zero\n#align hamming_norm_eq_zero hammingNorm_eq_zero\n\n/-- Corresponds to `norm_ne_zero_iff`. -/\ntheorem hammingNorm_ne_zero_iff {x : ∀ i, β i} : hammingNorm x ≠ 0 ↔ x ≠ 0 :=\n  hammingNorm_eq_zero.not\n#align hamming_norm_ne_zero_iff hammingNorm_ne_zero_iff\n\n/-- Corresponds to `norm_pos_iff`. -/\n@[simp]\ntheorem hammingNorm_pos_iff {x : ∀ i, β i} : 0 < hammingNorm x ↔ x ≠ 0 :=\n  hammingDist_pos\n#align hamming_norm_pos_iff hammingNorm_pos_iff\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem hammingNorm_lt_one {x : ∀ i, β i} : hammingNorm x < 1 ↔ x = 0 :=\n  hammingDist_lt_one\n#align hamming_norm_lt_one hammingNorm_lt_one\n\ntheorem hammingNorm_le_card_fintype {x : ∀ i, β i} : hammingNorm x ≤ Fintype.card ι :=\n  hammingDist_le_card_fintype\n#align hamming_norm_le_card_fintype hammingNorm_le_card_fintype\n\ntheorem hammingNorm_comp_le_hammingNorm (f : ∀ i, γ i → β i) {x : ∀ i, γ i} (hf : ∀ i, f i 0 = 0) :\n    (hammingNorm fun i => f i (x i)) ≤ hammingNorm x := by\n  simpa only [← hammingDist_zero_right, hf] using hammingDist_comp_le_hammingDist f (y := fun _ ↦ 0)\n#align hamming_norm_comp_le_hamming_norm hammingNorm_comp_le_hammingNorm\n\ntheorem hammingNorm_comp (f : ∀ i, γ i → β i) {x : ∀ i, γ i} (hf₁ : ∀ i, Injective (f i))\n    (hf₂ : ∀ i, f i 0 = 0) : (hammingNorm fun i => f i (x i)) = hammingNorm x := by\n  simpa only [← hammingDist_zero_right, hf₂] using hammingDist_comp f hf₁ (y := fun _ ↦ 0)\n#align hamming_norm_comp hammingNorm_comp\n\ntheorem hammingNorm_smul_le_hammingNorm [Zero α] [∀ i, SMulWithZero α (β i)] {k : α}\n    {x : ∀ i, β i} : hammingNorm (k • x) ≤ hammingNorm x :=\n  hammingNorm_comp_le_hammingNorm (fun i (c : β i) => k • c) fun i => by simp_rw [smul_zero]\n#align hamming_norm_smul_le_hamming_norm hammingNorm_smul_le_hammingNorm\n\ntheorem hammingNorm_smul [Zero α] [∀ i, SMulWithZero α (β i)] {k : α}\n    (hk : ∀ i, IsSMulRegular (β i) k) (x : ∀ i, β i) : hammingNorm (k • x) = hammingNorm x :=\n  hammingNorm_comp (fun i (c : β i) => k • c) hk fun i => by simp_rw [smul_zero]\n#align hamming_norm_smul hammingNorm_smul\n\nend Zero\n\n/-- Corresponds to `dist_eq_norm`. -/\ntheorem hammingDist_eq_hammingNorm [∀ i, AddGroup (β i)] (x y : ∀ i, β 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/-- Type synonym for a Pi type which inherits the usual algebraic instances, but is equipped with\nthe Hamming metric and norm, instead of `Pi.normedAddCommGroup` which uses the sup norm. -/\ndef Hamming {ι : Type _} (β : ι → Type _) : Type _ :=\n  ∀ i, β i\n#align hamming Hamming\n\nnamespace Hamming\n\nvariable {α ι : Type _} {β : ι → Type _}\n\n/-! Instances inherited from normal Pi types. -/\n\ninstance [∀ i, Inhabited (β i)] : Inhabited (Hamming β) :=\n  ⟨fun _ => default⟩\n\ninstance [DecidableEq ι] [Fintype ι] [∀ i, Fintype (β i)] : Fintype (Hamming β) :=\n  Pi.fintype\n\ninstance [Inhabited ι] [∀ i, Nonempty (β i)] [Nontrivial (β default)] : Nontrivial (Hamming β) :=\n  Pi.nontrivial\n\ninstance [Fintype ι] [∀ i, DecidableEq (β i)] : DecidableEq (Hamming β) :=\n  Fintype.decidablePiFintype\n\ninstance [∀ i, Zero (β i)] : Zero (Hamming β) :=\n  Pi.instZero\n\ninstance [∀ i, Neg (β i)] : Neg (Hamming β) :=\n  Pi.instNeg\n\ninstance [∀ i, Add (β i)] : Add (Hamming β) :=\n  Pi.instAdd\n\ninstance [∀ i, Sub (β i)] : Sub (Hamming β) :=\n  Pi.instSub\n\ninstance [∀ i, SMul α (β i)] : SMul α (Hamming β) :=\n  Pi.instSMul\n\ninstance [Zero α] [∀ i, Zero (β i)] [∀ i, SMulWithZero α (β i)] : SMulWithZero α (Hamming β) :=\n  Pi.smulWithZero _\n\ninstance [∀ i, AddMonoid (β i)] : AddMonoid (Hamming β) :=\n  Pi.addMonoid\n\ninstance [∀ i, AddCommMonoid (β i)] : AddCommMonoid (Hamming β) :=\n  Pi.addCommMonoid\n\ninstance [∀ i, AddCommGroup (β i)] : AddCommGroup (Hamming β) :=\n  Pi.addCommGroup\n\ninstance (α) [Semiring α] (β : ι → Type _) [∀ i, AddCommMonoid (β i)] [∀ i, Module α (β i)] :\n    Module α (Hamming β) :=\n  Pi.module _ _ _\n\n/-! API to/from the type synonym. -/\n\n\n/-- `Hamming.toHamming` is the identity function to the `Hamming` of a type.  -/\n@[match_pattern]\ndef toHamming : (∀ i, β i) ≃ Hamming β :=\n  Equiv.refl _\n#align hamming.to_hamming Hamming.toHamming\n\n/-- `Hamming.ofHamming` is the identity function from the `Hamming` of a type.  -/\n@[match_pattern]\ndef ofHamming : Hamming β ≃ ∀ i, β i :=\n  Equiv.refl _\n#align hamming.of_hamming Hamming.ofHamming\n\n@[simp]\ntheorem toHamming_symm_eq : (@toHamming _ β).symm = ofHamming :=\n  rfl\n#align hamming.to_hamming_symm_eq Hamming.toHamming_symm_eq\n\n@[simp]\ntheorem ofHamming_symm_eq : (@ofHamming _ β).symm = toHamming :=\n  rfl\n#align hamming.of_hamming_symm_eq Hamming.ofHamming_symm_eq\n\n@[simp]\ntheorem toHamming_ofHamming (x : Hamming β) : toHamming (ofHamming x) = x :=\n  rfl\n#align hamming.to_hamming_of_hamming Hamming.toHamming_ofHamming\n\n@[simp]\ntheorem ofHamming_toHamming (x : ∀ i, β i) : ofHamming (toHamming x) = x :=\n  rfl\n#align hamming.of_hamming_to_hamming Hamming.ofHamming_toHamming\n\n--@[simp] --Porting note: removing `simp`, `simp` can prove it and `dsimp` cannot use `Iff.rfl`\ntheorem toHamming_inj {x y : ∀ i, β i} : toHamming x = toHamming y ↔ x = y :=\n  Iff.rfl\n#align hamming.to_hamming_inj Hamming.toHamming_inj\n\n--@[simp] --Porting note: removing `simp`, `simp` can prove it and `dsimp` cannot use `Iff.rfl`\ntheorem ofHamming_inj {x y : Hamming β} : ofHamming x = ofHamming y ↔ x = y :=\n  Iff.rfl\n#align hamming.of_hamming_inj Hamming.ofHamming_inj\n\n@[simp]\ntheorem toHamming_zero [∀ i, Zero (β i)] : toHamming (0 : ∀ i, β i) = 0 :=\n  rfl\n#align hamming.to_hamming_zero Hamming.toHamming_zero\n\n@[simp]\ntheorem ofHamming_zero [∀ i, Zero (β i)] : ofHamming (0 : Hamming β) = 0 :=\n  rfl\n#align hamming.of_hamming_zero Hamming.ofHamming_zero\n\n@[simp]\ntheorem toHamming_neg [∀ i, Neg (β i)] {x : ∀ i, β i} : toHamming (-x) = -toHamming x :=\n  rfl\n#align hamming.to_hamming_neg Hamming.toHamming_neg\n\n@[simp]\ntheorem ofHamming_neg [∀ i, Neg (β i)] {x : Hamming β} : ofHamming (-x) = -ofHamming x :=\n  rfl\n#align hamming.of_hamming_neg Hamming.ofHamming_neg\n\n@[simp]\ntheorem toHamming_add [∀ i, Add (β i)] {x y : ∀ i, β i} :\n    toHamming (x + y) = toHamming x + toHamming y :=\n  rfl\n#align hamming.to_hamming_add Hamming.toHamming_add\n\n@[simp]\ntheorem ofHamming_add [∀ i, Add (β i)] {x y : Hamming β} :\n    ofHamming (x + y) = ofHamming x + ofHamming y :=\n  rfl\n#align hamming.of_hamming_add Hamming.ofHamming_add\n\n@[simp]\ntheorem toHamming_sub [∀ i, Sub (β i)] {x y : ∀ i, β i} :\n    toHamming (x - y) = toHamming x - toHamming y :=\n  rfl\n#align hamming.to_hamming_sub Hamming.toHamming_sub\n\n@[simp]\ntheorem ofHamming_sub [∀ i, Sub (β i)] {x y : Hamming β} :\n    ofHamming (x - y) = ofHamming x - ofHamming y :=\n  rfl\n#align hamming.of_hamming_sub Hamming.ofHamming_sub\n\n@[simp]\ntheorem toHamming_smul [∀ i, SMul α (β i)] {r : α} {x : ∀ i, β i} :\n    toHamming (r • x) = r • toHamming x :=\n  rfl\n#align hamming.to_hamming_smul Hamming.toHamming_smul\n\n@[simp]\ntheorem ofHamming_smul [∀ i, SMul α (β i)] {r : α} {x : Hamming β} :\n    ofHamming (r • x) = r • ofHamming x :=\n  rfl\n#align hamming.of_hamming_smul Hamming.ofHamming_smul\n\nsection\n\n/-! Instances equipping `Hamming` with `hammingNorm` and `hammingDist`. -/\n\nvariable [Fintype ι] [∀ i, DecidableEq (β i)]\n\ninstance : Dist (Hamming β) :=\n  ⟨fun x y => hammingDist (ofHamming x) (ofHamming y)⟩\n\n@[simp, push_cast]\ntheorem dist_eq_hammingDist (x y : Hamming β) :\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 β) where\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  edist_dist _ _ := by exact ENNReal.coe_nnreal_eq _\n  toUniformSpace := ⊥\n  uniformity_dist := uniformity_dist_of_mem_uniformity _ _ fun s => by\n    push_cast\n    constructor\n    · refine' fun hs => ⟨1, zero_lt_one, fun hab => _⟩\n      rw_mod_cast [hammingDist_lt_one]  at hab\n      rw [ofHamming_inj, ← mem_idRel] at hab\n      exact hs hab\n    · rintro ⟨_, hε, hs⟩ ⟨_, _⟩ hab\n      rw [mem_idRel] at hab\n      rw [hab]\n      refine' hs (lt_of_eq_of_lt _ hε)\n      exact_mod_cast hammingDist_self _\n  toBornology := ⟨⊥, bot_le⟩\n  cobounded_sets := by\n    ext\n    push_cast\n    refine' iff_of_true (Filter.mem_sets.mpr Filter.mem_bot) ⟨Fintype.card ι, fun _ _ _ _ => _⟩\n    exact_mod_cast hammingDist_le_card_fintype\n\n@[simp, push_cast]\ntheorem nndist_eq_hammingDist (x y : Hamming β) :\n    nndist x y = hammingDist (ofHamming x) (ofHamming y) :=\n  rfl\n#align hamming.nndist_eq_hamming_dist Hamming.nndist_eq_hammingDist\n\n-- porting note: new\ninstance : DiscreteTopology (Hamming β) := ⟨rfl⟩\n\ninstance : MetricSpace (Hamming β) := .ofT0PseudoMetricSpace _\n\ninstance [∀ i, Zero (β i)] : Norm (Hamming β) :=\n  ⟨fun x => hammingNorm (ofHamming x)⟩\n\n@[simp, push_cast]\ntheorem norm_eq_hammingNorm [∀ i, Zero (β i)] (x : Hamming β) : ‖x‖ = hammingNorm (ofHamming x) :=\n  rfl\n#align hamming.norm_eq_hamming_norm Hamming.norm_eq_hammingNorm\n\n-- porting note: merged `SeminormedAddCommGroup` and `NormedAddCommGroup` instances\n\ninstance [∀ i, AddCommGroup (β i)] : NormedAddCommGroup (Hamming β) where\n  dist_eq := by push_cast; exact_mod_cast hammingDist_eq_hammingNorm\n\n@[simp, push_cast]\ntheorem nnnorm_eq_hammingNorm [∀ i, AddCommGroup (β i)] (x : Hamming β) :\n    ‖x‖₊ = hammingNorm (ofHamming x) :=\n  rfl\n#align hamming.nnnorm_eq_hamming_norm Hamming.nnnorm_eq_hammingNorm\n\nend\n\nend Hamming\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/InformationTheory/Hamming.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7899035432386916}}
{"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.convex.star\nimport 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\nvariables {E : Type*} [add_comm_group E] [module ℝ E] [topological_space E]\n  [has_continuous_add E] [has_continuous_smul ℝ E] {s : set E} {x : E}\n\n/-- A non-empty star convex set is a contractible space. -/\nprotected lemma star_convex.contractible_space (h : star_convex ℝ x s) (hne : s.nonempty) :\n  contractible_space s :=\nbegin\n  refine (contractible_iff_id_nullhomotopic _).2 ⟨⟨x, h.mem hne⟩,\n    ⟨⟨⟨λ p, ⟨p.1.1 • x + (1 - p.1.1) • p.2, _⟩, _⟩, λ x, _, λ x, _⟩⟩⟩,\n  { exact h p.2.2 p.1.2.1 (sub_nonneg.2 p.1.2.2) (add_sub_cancel'_right _ _) },\n  { exact continuous_subtype_mk _\n      (((continuous_subtype_val.comp continuous_fst).smul continuous_const).add\n        ((continuous_const.sub $ continuous_subtype_val.comp continuous_fst).smul\n          (continuous_subtype_val.comp continuous_snd))) },\n  { ext1, simp },\n  { ext1, simp }\nend\n\n/-- A non-empty convex set is a contractible space. -/\nprotected lemma convex.contractible_space (hs : convex ℝ s) (hne : s.nonempty) :\n  contractible_space s :=\nlet ⟨x, hx⟩ := hne in (hs.star_convex hx).contractible_space hne\n\n@[priority 100] instance real_topological_vector_space.contractible_space : contractible_space E :=\n(homeomorph.set.univ E).contractible_space_iff.mp $ convex_univ.contractible_space set.univ_nonempty\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/contractible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.8887588008585925, "lm_q1q2_score": 0.7898921890821362}}
{"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-/\nimport analysis.locally_convex.basic\nimport topology.bornology.basic\n\n/-!\n# Von Neumann Boundedness\n\nThis file defines natural or von Neumann bounded sets and proves elementary properties.\n\n## Main declarations\n\n* `bornology.is_vonN_bounded`: A set `s` is von Neumann-bounded if every neighborhood of zero\nabsorbs `s`.\n* `bornology.vonN_bornology`: The bornology made of the von Neumann-bounded sets.\n\n## Main results\n\n* `bornology.is_vonN_bounded_of_topological_space_le`: A coarser topology admits more\nvon Neumann-bounded sets.\n\n## References\n\n* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]\n\n-/\n\nvariables {𝕜 E ι : Type*}\n\nopen_locale topological_space pointwise\n\nnamespace bornology\n\nsection semi_normed_ring\n\nsection has_zero\n\nvariables (𝕜)\nvariables [semi_normed_ring 𝕜] [has_scalar 𝕜 E] [has_zero E]\nvariables [topological_space E]\n\n/-- A set `s` is von Neumann bounded if every neighborhood of 0 absorbs `s`. -/\ndef is_vonN_bounded (s : set E) : Prop := ∀ ⦃V⦄, V ∈ 𝓝 (0 : E) → absorbs 𝕜 V s\n\nvariables (E)\n\n@[simp] lemma is_vonN_bounded_empty : is_vonN_bounded 𝕜 (∅ : set E) :=\nλ _ _, absorbs_empty\n\nvariables {𝕜 E}\n\nlemma is_vonN_bounded_iff (s : set E) : is_vonN_bounded 𝕜 s ↔ ∀ V ∈ 𝓝 (0 : E), absorbs 𝕜 V s :=\niff.rfl\n\nlemma _root_.filter.has_basis.is_vonN_bounded_basis_iff {q : ι → Prop} {s : ι → set E} {A : set E}\n  (h : (𝓝 (0 : E)).has_basis q s) :\n  is_vonN_bounded 𝕜 A ↔ ∀ i (hi : q i), absorbs 𝕜 (s i) A :=\nbegin\n  refine ⟨λ hA i hi, hA (h.mem_of_mem hi), λ hA V hV, _⟩,\n  rcases h.mem_iff.mp hV with ⟨i, hi, hV⟩,\n  exact (hA i hi).mono_left hV,\nend\n\n/-- Subsets of bounded sets are bounded. -/\nlemma is_vonN_bounded.subset {s₁ s₂ : set E} (h : s₁ ⊆ s₂) (hs₂ : is_vonN_bounded 𝕜 s₂) :\n  is_vonN_bounded 𝕜 s₁ :=\nλ V hV, (hs₂ hV).mono_right h\n\n/-- The union of two bounded sets is bounded. -/\n\n\nend has_zero\n\nend semi_normed_ring\n\nsection multiple_topologies\n\nvariables [semi_normed_ring 𝕜] [add_comm_group E] [module 𝕜 E]\n\n/-- If a topology `t'` is coarser than `t`, then any set `s` that is bounded with respect to\n`t` is bounded with respect to `t'`. -/\nlemma is_vonN_bounded.of_topological_space_le {t t' : topological_space E} (h : t ≤ t') {s : set E}\n  (hs : @is_vonN_bounded 𝕜 E _ _ _ t s) : @is_vonN_bounded 𝕜 E _ _ _ t' s :=\nλ V hV, hs $ (le_iff_nhds t t').mp h 0 hV\n\nend multiple_topologies\n\nsection normed_field\n\nvariables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E]\nvariables [topological_space E] [has_continuous_smul 𝕜 E]\n\n/-- Singletons are bounded. -/\nlemma is_vonN_bounded_singleton (x : E) : is_vonN_bounded 𝕜 ({x} : set E) :=\nλ V hV, (absorbent_nhds_zero hV).absorbs\n\n/-- The union of all bounded set is the whole space. -/\nlemma is_vonN_bounded_covers : ⋃₀ (set_of (is_vonN_bounded 𝕜)) = (set.univ : set E) :=\nset.eq_univ_iff_forall.mpr (λ x, set.mem_sUnion.mpr\n  ⟨{x}, is_vonN_bounded_singleton _, set.mem_singleton _⟩)\n\nvariables (𝕜 E)\n\n/-- The von Neumann bornology defined by the von Neumann bounded sets.\n\nNote that this is not registered as an instance, in order to avoid diamonds with the\nmetric bornology.-/\n@[reducible] -- See note [reducible non-instances]\ndef vonN_bornology : bornology E :=\nbornology.of_bounded (set_of (is_vonN_bounded 𝕜)) (is_vonN_bounded_empty 𝕜 E)\n  (λ _ hs _ ht, hs.subset ht) (λ _ hs _, hs.union) is_vonN_bounded_singleton\n\nvariables {E}\n\n@[simp] lemma is_bounded_iff_is_vonN_bounded {s : set E} :\n  @is_bounded _ (vonN_bornology 𝕜 E) s ↔ is_vonN_bounded 𝕜 s :=\nis_bounded_of_bounded_iff _\n\nend normed_field\n\nend bornology\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/locally_convex/bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8887587817066391, "lm_q1q2_score": 0.7898921877727927}}
{"text": "import .love02_backward_proofs_demo\n\n\n/-! # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nsorry\n\nlemma K (a b : Prop) :\n  a → b → b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nsorry\n\n/-! Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nsorry\n\n/-! 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nsorry\n\n/-! 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nsorry\n\n\n/-! ## Question 2: Natural Numbers\n\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nsorry\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nsorry\n\n/-! 2.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nsorry\n\n/-! 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nsorry\n\n\n/-! ## Question 3 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle : Prop :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce : Prop :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation : Prop :=\n∀a : Prop, (¬¬ a) → a\n\n/-! For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, as this would defeat the purpose of the exercise.\n\n3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nsorry\n\n/-! 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nsorry\n\n/-! We leave the remaining implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\n\nend backward_proofs\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/love02_backward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8757870046160257, "lm_q1q2_score": 0.7898904123167512}}
{"text": "-- Section 3.1: Propositions as Types\nnamespace s31\n    constant and : Prop → Prop → Prop\n    constant or : Prop → Prop → Prop\n    constant not : Prop → Prop\n    constant implies : Prop → Prop → Prop\n\n    variables p q r A B: 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    constant Proof : Prop → Type\n\n    constant and_comm : Π 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\n    constant modus_ponens :\n    Π p q : Prop, Proof (implies p q) →  Proof p → Proof q\n\n    constant implies_intro :\n    Π p q : Prop, (Proof p → Proof q) → Proof (implies p q).\n\n\nend s31\n\n-- Section 3.2: Working with P. as T.\nnamespace s32\n\n    constants p q r s: Prop\n    -- Similar to 'def' but for Prop, not Type\n    theorem t1_ : p → q → p := λ hp : p, λ hq : q, hp\n    #print t1_\n\n    -- Written with other syntax for readability\n    theorem t1' : p → q → p :=\n    assume hp : p,\n    assume hq : q,\n    show p, from hp\n\n    -- Can also say \"lemma\" instead of theorem\n    lemma t1'' : p → q → p := λ hp : p, λ hq : q, hp\n\n    -- Can also move arguments to left of colon, like with defs\n    lemma t1'''  (hp : p) (hq : q):  p := hp\n\n    axiom hp : p -- same as constant\n\n    theorem t2' : q → p := t1' hp\n    #print t2'\n\n    -- Want our theorem to be true for any p q, not just those particular constants\n\n    theorem t1 (p q : Prop) (hp : p) (hq : q) : p := hp\n    -- Apply to other constants\n    #check t1 p q                -- p → q → p\n    #check t1 r s                -- r → s → r\n    #check t1 (r → s) (s → r)    -- (r → s) → (s → r) → r → s\n\n    variable h : r → s\n    #check t1 (r → s) (s → r) h  -- (s → r) → r → s\n\n    -- Function composition says that \"implies\" is transitive\n    theorem t2 (h₁ : q → r) (h₂ : p → q) : p → r :=\n    assume h₃ : p,\n    show r, from h₁ (h₂ h₃)\n\nend s32\n\n-- Section 3.3: Propositional logic\nnamespace s33\n    variables p q r : Prop\n\n    #check p → q → p ∧ q\n    #check ¬p → p ↔ false\n    #check p ∨ q → q ∨ p\n\n    -- Conjunction\n    --------------\n\n    -- 'example' states a theorem without naming/storing it. Essentially is just a typecheck\n    example (hp : p) (hq : q) : p ∧ q := and.intro hp hq\n\n    #check assume (hp : p) (hq : q), and.intro hp hq\n\n    example (h : p ∧ q) : p := and.elim_left h\n    example (h : p ∧ q) : q := and.elim_right h\n\n    -- Common abbreviation for elim_left/right\n    example (h : p ∧ q) : q ∧ p :=\n    and.intro (and.right h) (and.left h)\n\n    -- Anonymous constructor\n\n    variables  (hp : p) (hq : q)\n    #check (⟨hp, hq⟩ : p ∧ q)\n    example : p ∧ q := (|hp, hq|) -- ascii version\n\n\n    -- Dot syntax\n    variable l : list ℕ\n\n    #check list.head l\n    #check l.head -- equivalent, easier to write\n\n    -- Dot syntax for propositions\n    example (h : p ∧ q) : q ∧ p :=\n    ⟨h.right, h.left⟩\n\n    -- Disjunction\n    --------------\n    --intro\n    example (hp : p) : p ∨ q := or.intro_left q hp\n    example (hq : q) : p ∨ q := or.intro_right p hq\n    --elim\n    example (h : p ∨ q) : q ∨ p :=\n    or.elim h\n    (λ hp : p,\n        show q ∨ p, from or.intro_right q hp)\n    (assume hq : q,\n        show q ∨ p, from or.intro_left p hq)\n\n    -- intro\n    example (h : p ∨ q) : q ∨ p :=\n    or.elim h (λ hp, or.inr hp) (λ hq, or.inl hq)\n\n    -- or has two constructors,so can't use anonymous constructor\n    -- still write h.elim instead of or.elim h:\n    example (h : p ∨ q) : q ∨ p :=\n    h.elim\n    (assume hp : p, or.inr hp)\n    (assume hq : q, or.inl hq)\n\n\n    -- Negation/falsity\n    example (hpq : p → q) (hnq : ¬q) : ¬p :=\n    assume hp : p,\n    show false, from hnq (hpq hp)\n    -- explosion (q is implicit argument in false.elim)\n    example (hp : p) (hnp : ¬p) : q := false.elim (hnp hp)\n    -- Shorthand for explosion\n    example (hp : p) (hnp : ¬p) : q := absurd hp hnp\n\n    -- proof of ¬p → q → (q → p) → r:\n\n\n    example (hnp : ¬p) (hq : q) (hqp : q → p) : r :=\n    absurd (hqp hq) hnp\n\n    -- Logical equivalence\n    -----------------------\n    theorem and_swap : p ∧ q ↔ q ∧ p :=\n    iff.intro\n    (assume h : p ∧ q,\n        show q ∧ p, from and.intro (and.right h) (and.left h))\n    (assume h : q ∧ p,\n        show p ∧ q, from and.intro (and.right h) (and.left h))\n\n    #check and_swap p q    -- p ∧ q ↔ q ∧ p\n\n    -- Modus ponens\n    variable h : p ∧ q\n    example : q ∧ p := iff.mp (and_swap p q) h\n\nend s33\n\n-- Section 3.4: Auxiliary Subgoals\nnamespace s34\n    variables p q : Prop\n\n    example (h : p ∧ q) : q ∧ p :=\n    have hp : p, from and.left h,\n    have hq : q, from and.right h,\n    show q ∧ p, from and.intro hq hp\n\n    -- suffices for backwards reasoning from a goal\n    example (h : p ∧ q) : q ∧ p :=\n    have hp : p, from and.left h,\n    suffices hq : q, from and.intro hq hp,\n    show q, from and.right h\n    -- suffices hq : q leaves us with two goals.\n    --- show that it indeed suffices to show q, by proving the original goal of q ∧ p with the additional hypothesis hq : q.\n    --- show q.\n\n\nend s34\n\n-- Section 3.5: Classical logic\nnamespace s35\n    open classical\n    -- Excluded middle\n    variables p q : Prop\n    #check em p\n    -- Double negation as consequence\n    theorem dne {p : Prop} (h : ¬¬p) : p :=\n    or.elim (em p)\n    (assume hp : p, hp)\n    (assume hnp : ¬p, absurd hnp h)\n    -- This allows us to construct proofs by contradiction\n    example (h : ¬¬p) : p :=\n    by_cases\n    (assume h1 : p, h1)\n    (assume h1 : ¬p, absurd h1 h)\n    example (h : ¬¬p) : p :=\n    by_contradiction\n    (assume h1 : ¬p,\n        show false, from h h1)\n\n\n    example (h : ¬(p ∧ q)) : ¬p ∨ ¬q :=\n    or.elim (em p)\n    (assume hp : p,\n        or.inr\n        (show ¬q, from\n            assume hq : q,\n            h ⟨hp, hq⟩))\n    (assume hp : ¬p,\n        or.inl hp)\n\nend s35\n\n-- Section 3.6: Examples of propositional validities\nnamespace s36\n    open classical\n    -- We can use sorry or an underscore to allow us to incrementally build up a proof (with warnings, not errors) to make sure the large structure is correct before tackling subgoals.\n    variables p q r : Prop\n\n    -- distributivity\n    example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n    iff.intro\n    (assume h : p ∧ (q ∨ r),\n        have hp : p, from h.left,\n        or.elim (h.right)\n        (assume hq : q,\n            show (p ∧ q) ∨ (p ∧ r), from or.inl ⟨hp, hq⟩)\n        (assume hr : r,\n            show (p ∧ q) ∨ (p ∧ r), from or.inr ⟨hp, hr⟩))\n    (assume h : (p ∧ q) ∨ (p ∧ r),\n        or.elim h\n        (assume hpq : p ∧ q,\n            have hp : p, from hpq.left,\n            have hq : q, from hpq.right,\n            show p ∧ (q ∨ r), from ⟨hp, or.inl hq⟩)\n        (assume hpr : p ∧ r,\n            have hp : p, from hpr.left,\n            have hr : r, from hpr.right,\n            show p ∧ (q ∨ r), from ⟨hp, or.inr hr⟩))\n\n    -- an example that requires classical reasoning\n    example : ¬(p ∧ ¬q) → (p → q) :=\n    assume h : ¬(p ∧ ¬q),\n    assume hp : p,\n    show q, from\n    or.elim (em q)\n        (assume hq : q, hq)\n        (assume hnq : ¬q, absurd (and.intro hp hnq) h)\n\nend s36\n\n-- Exercises\nnamespace s3x\n-- 1\n\nvariables p q r s : Prop\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p := iff.intro\n    (λ hpq, and.intro hpq.right hpq.left)\n    (λ hpq, and.intro hpq.right hpq.left)\n\n\nexample : p ∨ q ↔ q ∨ p := iff.intro\n    (λ hporq, or.elim hporq\n        (assume hp: p, or.inr hp)\n        (assume hq: q, or.inl hq))\n    (λ hqorp, or.elim hqorp\n        (assume hq: q, or.inr hq)\n        (assume hp: p, or.inl hp))\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := iff.intro\n    (assume hpq_r : (p ∧ q) ∧ r,\n        and.intro hpq_r.left.left (and.intro hpq_r.left.right hpq_r.right))\n    (assume hp_qr : p ∧ (q ∧ r),\n        and.intro (and.intro hp_qr.left hp_qr.right.left) hp_qr.right.right)\n\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := iff.intro\n    (assume hpq_r : (p ∨ q) ∨ r, or.elim hpq_r\n        (assume hpq: (p ∨ q), 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 hp_qr : p ∨ (q ∨ r), or.elim hp_qr\n        (assume hp : p, or.inl (or.inl hp))\n        (assume hqr: (q ∨ r), 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 ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := iff.intro\n(assume hpqr : p ∧ (q ∨ r),\n    have hp:p, from and.left hpqr,\n        show (p ∧ q) ∨ (p ∧ r), from or.elim\n            (and.right hpqr)\n            (assume hq : q, or.inl (and.intro hp hq))\n            (assume hr : r, or.inr (and.intro hp hr)))\n(assume hpqpr : (p ∧ q) ∨ (p ∧ r), or.elim hpqpr\n    (assume hpq : p ∧ q, and.intro\n        hpq.left\n        (or.inl hpq.right))\n    (assume hpr : p ∧ r, and.intro\n        hpr.left\n        (or.inr hpr.right)))\n\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := iff.intro\n(assume hpqr : p ∨ (q ∧ r), or.elim hpqr\n    (assume hp : p, and.intro\n        (or.inl hp)\n        (or.inl hp))\n    (assume hqr : q ∧ r, and.intro\n        (or.inr hqr.left)\n        (or.inr hqr.right)))\n(assume hpqpr: (p ∨ q) ∧ (p ∨ r),\n    show p ∨ (q ∧ r), from or.elim hpqpr.left\n    (assume hp: p, or.inl hp)\n    (assume hq: q,\n        or.elim hpqpr.right\n        (assume hp: p, or.inl hp)\n        (assume hr: r, or.inr (and.intro hq hr))))\n\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := iff.intro\n(assume hpqr : p → (q → r),\n    (assume hpr : p ∧ q, hpqr hpr.left hpr.right))\n(assume hpqr : p ∧ q → r,\n    (assume hp : p,\n        (assume hq : q,\n            have hpq : p ∧ q, from and.intro hp hq,\n            hpqr hpq)))\n\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := iff.intro\n(assume hpqr : (p ∨ q) → r,\n    have hpr : p → r, from\n        (assume hp: p, hpqr (or.inl hp)),\n    have hqr : q → r, from\n        (assume hq : q, hpqr (or.inr hq)),\n    and.intro hpr hqr)\n(assume hprqr : (p → r) ∧ (q → r),\n    (assume hpq : p ∨ q, or.elim hpq\n     (assume hp: p, hprqr.left hp)\n     (assume hq: q, hprqr.right hq)))\n\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := iff.intro\n(assume hnpq : ¬(p ∨ q),\n    have hnp: ¬p, from\n        (assume hp: p, hnpq (or.inl hp)),\n    have hnq: ¬q, from\n        (assume hq: q, hnpq (or.inr hq)),\n    and.intro hnp hnq)\n(assume hnpnq : ¬p ∧ ¬q,\n    (assume hpq : p ∨ q, or.elim hpq\n        (assume hp :p, hnpnq.left hp)\n        (assume hq: q, hnpnq.right hq)))\n\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\n    (assume hnpnq : ¬p ∨ ¬q,\n        (assume hpq : p ∧ q, or.elim hnpnq\n            (assume hnp :¬p, hnp hpq.left)\n            (assume hnq :¬q, hnq hpq.right)))\n\n\nexample : ¬(p ∧ ¬p) :=\n    (assume hpnp: p ∧ ¬p, hpnp.right hpnp.left)\n\n\nexample : p ∧ ¬q → ¬(p → q) :=\n    assume hpnq : p ∧ ¬q,\n        assume hpq : p → q,\n            have hp : p, from hpnq.left,\n            have hq : q, from hpq hp,\n            have hnq : ¬ q, from hpnq.right,\n            hnq hq\n\n\nexample : ¬p → (p → q) :=\n    assume hnp : ¬p,\n    assume hp : p,\n    absurd hp hnp\n\n\nexample : (¬p ∨ q) → (p → q) :=\n    assume hnpq : ¬p ∨ q,\n        assume hp : p,\n        or.elim hnpq\n            (assume hnp : ¬p, absurd hp hnp)\n            id\n\n\nexample : p ∨ false ↔ p := iff.intro\n(assume hpf : p ∨ false, or.elim hpf\n    (assume hp : p, hp)\n    (assume f: false,\n    false.elim f))\n(assume hp : p, or.inl hp)\n\n\nexample : p ∧ false ↔ false := iff.intro\n(assume hpf: p ∧ false, hpf.right)\n(assume hf : false, false.elim hf)\n\n\nexample : (p → q) → (¬q → ¬p) :=\n    assume hpq : p → q,\n    assume hnq : ¬q,\n    assume hp : p,\n    absurd (hpq hp) hnq\n\n\n-- 3\n\n--2 (use classical reasoning)\nopen classical\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n    assume hprs: p → r ∨ s,\n    have hpnp : p ∨ ¬ p, from em p,\n    or.elim hpnp\n    (assume hp : p,\n        have hrs : r ∨ s, from hprs hp,\n        or.elim hrs\n        (assume hr : r, or.inl (assume _ : p, hr))\n        (assume hs: s, or.inr (assume _ : p, hs)))\n    (assume hnp : ¬ p, or.inl\n        (assume hp : p, absurd hp hnp))\n\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n    assume hnpq : ¬(p ∧ q) ,\n    have emp : p ∨ ¬p , from em p ,\n    or.elim emp\n    (assume hp : p,\n        have emq : q ∨ ¬q , from em q ,\n        or.elim emq\n        (assume hq : q, absurd (and.intro hp hq) hnpq)\n        (assume hnq : ¬q, or.inr hnq))\n    (assume hnp : ¬p, or.inl hnp)\n\nexample : ¬(p → q) → p ∧ ¬q :=\n    assume h : ¬(p → q),\n    have emp : p ∨ ¬p , from em p ,\n    or.elim emp\n        (assume hp : p,\n            have emq : q ∨ ¬q , from em q ,\n            or.elim emq\n                (assume hq : q,\n                    have imp: p → q, from (λ x: p, hq ),\n                    absurd imp h)\n                (assume hnq : ¬q, and.intro hp hnq))\n        (assume hnp : ¬p,\n            have imp : p → q, from (λ x: p, absurd x hnp),\n            absurd imp h)\n\n\nexample : (p → q) → (¬p ∨ q) :=\n    assume hpq : p → q,\n    have emp : p ∨ ¬p , from em p ,\n    or.elim emp\n    (assume hp : p, or.inr (hpq hp))\n    (assume hnp : ¬p, or.inl hnp)\n\n\nexample : (¬q → ¬p) → (p → q) :=\n    assume hnqnp : ¬q → ¬p,\n    assume hp: p,\n    have emq : q ∨ ¬q , from em q ,\n    or.elim emq\n    id\n    (assume hnq : ¬q, absurd hp (hnqnp hnq))\n\n\nexample : p ∨ ¬p := em p\n\n\nexample : (((p → q) → p) → p) :=\n    assume hpqp : (p → q) → p,\n    have hem : p ∨ ¬p, from em p,\n    or.elim hem\n        (assume hp: p, id hp)\n        (assume hnp: ¬p,\n            absurd\n            (have hpq: p → q, from\n                (assume hp: p, absurd hp hnp),\n            hpqp hpq)\n            hnp)\n\n\n\nend s3x", "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/src/ch3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8757870013740061, "lm_q1q2_score": 0.7898904024661777}}
{"text": "import data.real.basic\n\n/-\nOne of the earliest kind of proofs one encounters while learning mathematics is proving by\na calculation. It may not sound like a proof, but this is actually using lemmas expressing \nproperties of operations on numbers. It also uses the fundamental property of equality: if two\nmathematical objects A and B are equal then, in any statement involving A, one can replace A \nby B. This operation is called rewriting, and the Lean \"tactic\" for this is `rw`.\n\nIn the following exercises, we will use the following two lemmas:\n  mul_assoc a b c : a * b * c = a * (b * c)\n  mul_comm a b : a*b = b*a\n\nHence the command \n  rw mul_assoc a b c,\nwill replace a*b*c by a*(b*c) in the current goal.\n\nIn order to replace backward, we use\n  rw ← mul_assoc a b c,\nreplacing a*(b*c) by a*b*c in the current goal.\n\nOf course we don't want to constantly invoke those lemmas, and we will eventually introduce\nmore powerful solutions.\n-/\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 0001\nexample (a b c : ℝ) : (c * b) * a = b * (a * c) :=\nbegin\n  -- sorry\n  rw mul_comm c b,\n  rw mul_assoc b c a,\n  rw mul_comm c a,\n  -- sorry\nend\n\n-- 0002\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  -- sorry\n  rw ← mul_assoc a b c,\n  rw mul_comm a b,\n  rw mul_assoc b a c,\n  -- sorry\nend\n\n/-\nNow let's return to the preceding example to experiment with what happens\nif we don't give arguments to mul_assoc or mul_comm.\nFor instance, you can start the next proof with\n  rw ← mul_assoc,\nTry to figure out what happens.\n-/\n\n-- 0003\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  -- sorry\n  rw ← mul_assoc,\n  -- \"rw mul_comm,\" doesn't do what we want.\n  rw mul_comm a b,\n  rw mul_assoc,\n  -- sorry\nend\n\n/-\nWe can also perform rewriting in an assumption of the local context, using for instance\n  rw mul_comm a b at hyp,\nin order to replace a*b by b*a in assumption hyp.\n\nThe next example will use a third lemma:\n  two_mul a : 2*a = a + a\n\nAlso we use the `exact` tactic, which allows to provide a direct proof term.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a*d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp, -- Our assumption hyp is now exactly what we have to prove\nend\n\n/-\nAnd the next one can use:\n  sub_self x : x - x = 0\n-/\n\n-- 0004\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  -- sorry\n  rw hyp' at hyp,\n  rw mul_comm b a at hyp,\n  rw sub_self (a*b) at hyp,\n  exact hyp,\n  -- sorry\nend\n\n/-\nWhat is written in the two preceding example is very far away from what we would write on\npaper. Let's now see how to get a more natural layout.\nInside each pair of curly braces below, the goal is to prove equality with the preceding line.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b : by { rw hyp }\n  ... = d*a + a*d  : by { rw hyp' }\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\n/-\nLet's note there is no comma at the end of each line of calculation. `calc` is really one\ncommand, and the comma comes only after it's fully done.\n\nFrom a practical point of view, when writing such a proof, it is convenient to:\n* pause the tactic state view update in VScode by clicking the Pause icon button\n  in the top right corner of the Lean Goal buffer\n* write the full calculation, ending each line with \": by {}\"\n* resume tactic state update by clicking the Play icon button and fill in proofs between \n  curly braces.\n\nLet's return to the other example using this method. \n-/\n\n-- 0005\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  -- sorry\n  calc c = b*a - d : by { rw hyp }\n  ... = b*a - a*b : by { rw hyp' }\n  ... = a*b - a*b : by { rw mul_comm a b }\n  ... = 0 : by { rw sub_self (a*b) },\n  -- sorry\nend\n\n/-\nThe preceding proofs have exhausted our supply of \"mul_comm\" patience. Now it's time\nto get the computer to work harder. The `ring` tactic will prove any goal that follows by\napplying only the axioms of commutative (semi-)rings, in particular commutativity and \nassociativity of addition and multiplication, as well as distributivity.\n\nWe also note that curly braces are not necessary when we write a single tactic proof, so \nlet's get rid of them.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b   : by rw hyp\n     ... = d*a + a*d : by rw hyp'\n     ... = 2*a*d     : by ring,\nend\n\n/-\nOf course we can use `ring` outside of `calc`. Let's do the next one in one line.\n-/\n\n-- 0006\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  -- sorry\n  ring,\n  -- sorry\nend\n\n/-\nThis is too much fun. Let's do it again.\n-/\n\n-- 0007\nexample (a b : ℝ) : (a + b) + a = 2*a + b :=\nbegin\n  -- sorry\n  ring,\n  -- sorry\nend\n\n/-\nMaybe this is cheating. Let's try to do the next computation without ring.\nWe could use:\npow_two x : x^2 = x*x\nmul_sub a b c : a*(b-c) = a*b - a*c\nadd_mul a b c : (a+b)*c = a*c + b*c\nadd_sub a b c : a + (b - c) = (a + b) - c\nsub_sub a b c : a - b - c = a - (b + c)\nadd_zero a : a + 0 = a\n-/\n\n-- 0008\nexample (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 :=\nbegin\n  -- sorry\n  rw pow_two a,\n  rw pow_two b,\n  rw mul_sub (a+b) a b,\n  rw add_mul a b a,\n  rw add_mul a b b,\n  rw mul_comm b a,\n  rw ← sub_sub,\n  rw ← add_sub,\n  rw sub_self,\n  rw add_zero,\n  -- sorry\nend\n\n/- Let's stick to ring in the end. -/\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/01_equality_rewriting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8757869884059266, "lm_q1q2_score": 0.7898903907699987}}
{"text": "import data.real.basic\nimport data.int.parity\n\n/-  \nIn this file, we learn how to handle the ∃ quantifier.\n\nIn order to prove `∃ x, P x`, we give some x₀ using tactic `use x₀` and\nthen prove `P x₀`. This x₀ can be an object from the local context\nor a more complicated expression.\n-/\nexample : ∃ n : ℕ, 8 = 2*n :=\nbegin\n  use 4,\n  refl,  -- this is the tactic analogue of the rfl proof term\nend\n\n/-\nIn order to use `h : ∃ x, P x`, we use the `cases` tactic to fix \none x₀ that works.\n\nAgain h can come straight from the local context or can be a more \ncomplicated expression.\n-/\nexample (n : ℕ) (h : ∃ k : ℕ, n = k + 1) : n > 0 :=\nbegin\n  -- Let's fix k₀ such that n = k₀ + 1.\n  cases h with k₀ hk₀,\n  -- It now suffices to prove k₀ + 1 > 0.\n  rw hk₀,\n  -- and we have a lemma about this\n  exact nat.succ_pos k₀,\nend\n\n/-\nThe next exercises use divisibility in ℤ (beware the ∣ symbol which is\nnot ASCII).\n\nBy definition, a ∣ b ↔ ∃ k, b = a*k, so you can prove a ∣ b using the\n`use` tactic.\n-/\n\n-- Until the end of this file, a, b and c will denote integers, unless\n-- explicitly stated otherwise\nvariables (a b c : ℤ)\n\n-- 0029\nexample (h₁ : a ∣ b) (h₂ : b ∣ c) : a ∣ c :=\nbegin\n  cases h₁ with k₁ hk₁,\n  cases h₂ with k₂ hk₂,\n  use k₁ * k₂,\n  rw hk₁ at hk₂,\n  linarith,\nend\n\n/-\nA very common pattern is to have an assumption or lemma asserting\n  h : ∃ x, y = ...\nand this is used through the combo:\n  cases h with x hx,\n  rw hx at ...\nThe tactic `rcases` allows us to do recursive `cases`, as indicated by its name,\nand also simplifies the above combo when the name hx is replaced by the special\nname `rfl`, as in the following example. \nIt uses the anonymous constructor angle brackets syntax.\n-/\n\n\nexample (h1 : a ∣ b) (h2 : a ∣ c) : a ∣ b+c :=\nbegin\n  rcases h1 with ⟨k, rfl⟩,\n  rcases h2 with ⟨l, rfl⟩,\n  use k+l,\n  ring,\nend\n\n/-\nYou can use the same `rfl` trick with the `rintros` tactic.\n-/\n\nexample : a ∣ b → a ∣ c → a ∣ b+c :=\nbegin\n  rintros ⟨k, rfl⟩ ⟨l, rfl⟩,\n  use k+l,\n  ring,\nend\n\n-- 0030\nexample : 0 ∣ a ↔ a = 0 :=\nbegin\n  split,\n  {\n    -- intros h, cases h with k hk, -- k:Z, hk:a=0*k, |- a=0\n    rintros ⟨k, rfl⟩, -- k:Z, |- 0*k=0\n    ring,\n  },\n  {\n    intros h,\n    rw h,\n  }\nend\n\n/-\nWe can now start combining quantifiers, using the definition\n\n  surjective (f : X → Y) := ∀ y, ∃ x, f x = y\n\n-/\nopen function\n\n-- In the remaining of this file, f and g will denote functions from\n-- ℝ to ℝ.\nvariables (f g : ℝ → ℝ)\n\n\n-- 0031\nexample (h : surjective (g ∘ f)) : surjective g :=\nbegin\n  -- intros c,\n  -- specialize h c,\n  -- cases h with a ha,\n  -- use (f a),\n  -- linarith,\n\n  intros c,\n  cases (h c) with a ha,\n  use (f a),\n  linarith,\nend\n\n/- \nThe above exercise can be done in three lines. Try to do the\nnext exercise in four lines.\n-/\n\n-- 0032\nexample (hf : surjective f) (hg : surjective g) : surjective (g ∘ f) :=\nbegin\n  intro c,\n  rcases (hg c) with ⟨b, rfl⟩,\n  rcases (hf b) with ⟨a, rfl⟩,\n  use a,\nend\n\n", "meta": {"author": "fzyzcjy", "repo": "learn_lean", "sha": "3d47e1641bb7d7afb590d18a73fa0c562e51e733", "save_path": "github-repos/lean/fzyzcjy-learn_lean", "path": "github-repos/lean/fzyzcjy-learn_lean/learn_lean-3d47e1641bb7d7afb590d18a73fa0c562e51e733/src/tutorial/exercises/04_exists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7898501772733119}}
{"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 group_theory.subgroup\nimport algebra.archimedean\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 (α) [ordered_add_comm_monoid α] : Prop :=`\n`(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • 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 `ℤ`\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 `ℝ`.\n-/\n\nvariables {G : Type*} [linear_ordered_add_comm_group G] [archimedean G]\nopen linear_ordered_add_comm_group\n\n/-- Given a subgroup `H` of a decidable linearly ordered archimedean abelian group `G`, if there\nexists a minimal element `a` of `H ∩ G_{>0}` then `H` is generated by `a`. -/\nlemma add_subgroup.cyclic_of_min {H : add_subgroup G} {a : G}\n  (ha : is_least {g : G | g ∈ H ∧ 0 < g} a) : H = add_subgroup.closure {a} :=\nbegin\n  obtain ⟨⟨a_in, a_pos⟩, a_min⟩ := ha,\n  refine le_antisymm _ (H.closure_le.mpr $ by simp [a_in]),\n  intros g g_in,\n  obtain ⟨k, nonneg, lt⟩ : ∃ k, 0 ≤ g - k • a ∧ g - k • a < a :=\n    exists_int_smul_near_of_pos' a_pos g,\n  have h_zero : g - k • a = 0,\n  { by_contra h,\n    have h : a ≤ g - k • a,\n    { refine a_min ⟨_, _⟩,\n      { exact add_subgroup.sub_mem H g_in (add_subgroup.gsmul_mem H a_in k) },\n      { exact lt_of_le_of_ne nonneg (ne.symm h) } },\n    have h' : ¬ (a ≤ g - k • a) := not_le.mpr lt,\n    contradiction },\n  simp [sub_eq_zero.mp h_zero, add_subgroup.mem_closure_singleton],\nend\n\n/-- Every subgroup of `ℤ` is cyclic. -/\nlemma int.subgroup_cyclic (H : add_subgroup ℤ) : ∃ a, H = add_subgroup.closure {a} :=\nbegin\n  cases add_subgroup.bot_or_exists_ne_zero H with h h,\n  { use 0,\n    rw h,\n    exact add_subgroup.closure_singleton_zero.symm },\n  let s := {g : ℤ | g ∈ H ∧ 0 < g},\n  have h_bdd : ∀ g ∈ s, (0 : ℤ) ≤ g := λ _ h, le_of_lt h.2,\n  obtain ⟨g₀, g₀_in, g₀_ne⟩ := h,\n  obtain ⟨g₁, g₁_in, g₁_pos⟩ : ∃ g₁ : ℤ, g₁ ∈ H ∧ 0 < g₁,\n  { cases lt_or_gt_of_ne g₀_ne with Hg₀ Hg₀,\n    { exact ⟨-g₀, H.neg_mem g₀_in, neg_pos.mpr Hg₀⟩ },\n    { exact ⟨g₀, g₀_in, Hg₀⟩ } },\n  obtain ⟨a, ha, ha'⟩ := int.exists_least_of_bdd ⟨(0 : ℤ), h_bdd⟩ ⟨g₁, g₁_in, g₁_pos⟩,\n  exact ⟨a, add_subgroup.cyclic_of_min ⟨ha, ha'⟩⟩,\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/group_theory/archimedean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7898501688545806}}
{"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\" (`→`)\n\nWe learn about propositions, and implications `P → Q` between them. You can get\nthis arrow by typing `\\to` or `\\r`. Mathematicians usually write the\nimplication arrow as `P ⇒ 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 `⊢` 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 → Q`. \nexample (hQ : Q) : P → Q :=\nbegin\n  -- The goal is of the form `X → 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 → Q` and `P` is true. Deduce `Q`.\nexample (h : P → Q) (hP : P) : Q :=\nbegin\n  -- our goal is `⊢ 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 → P :=\nbegin\n  sorry\nend\n\n/-\n\nNote that `→` is not associative: in general `P → (Q → R)` and `(P → Q) → 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 → Q → R` then we'd better know what this means.\nThe convention in Lean is that it means `P → (Q → 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 → P2 → P3 → ... 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 → (Q → P)`.\n\n-/\nexample : P → Q → P :=\nbegin\n  sorry\nend\n\n/-- If we know `P`, and we also know `P → Q`, we can deduce `Q`. \nThis is called \"Modus Ponens\" by logicians. -/\nexample : P → (P → Q) → Q :=\nbegin\n  sorry\nend\n\n/-- `→` is transitive. That is, if `P → Q` and `Q → R` are true, then\n  so is `P → R`. -/\nexample : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  sorry,\nend\n\n-- If `h : P → Q → R` with goal `⊢ R` and you `apply h`, you'll get\n-- two goals! Note that tactics operate on only the first goal.\nexample : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  sorry\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 → R) → (S → Q) → (R → T) → (Q → R) → S → T :=\nbegin\n  sorry\nend\n\nexample : (P → Q) → ((P → Q) → P) → Q :=\nbegin\n  sorry\nend\n\nexample : ((P → Q) → R) → ((Q → R) → P) → ((R → P) → Q) → P :=\nbegin\n  sorry\nend\n\nexample : ((Q → P) → P) → (Q → R) → (R → P) → P :=\nbegin\n  sorry\nend\n\nexample : (((P → Q) → Q) → Q) → (P → Q) :=\nbegin\n  sorry\nend\n\nexample :\n  (((P → Q → Q) → ((P → Q) → Q)) → R) →\n  ((((P → P) → Q) → (P → P → Q)) → R) →\n  (((P → P → Q) → ((P → P) → Q)) → R) → R :=\nbegin\n  sorry\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/section01logic/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.8918110440002045, "lm_q1q2_score": 0.7898159292652377}}
{"text": "constants a b c: int\nconstants  x y z m: nat\nconstant modus_ponens {p q : Prop} : implies p q → p → q\n\n-- a congruent to b modulo m\ndef cong (a:int) (b: int) (m: int): Prop := ∃ x: int, a-b = m*x\n\n-- p is prime\ndef is_prime (p:nat): Prop := ∀ x y: int, cong (x*y) 0 p → cong x 0 p ∨ cong y 0 p\n\n-- f is the floor of a/b\ndef floor (a:int) (b:int) (f:int): Prop  := (f*b ≤ a ∧ ∀  y: int, y*b ≤ a → y≤f)\n\n-- g is the gcd of a and b\ndef gcd (a:int) (b:int) (g:int): Prop := g > 0 ∧ cong a 0 g ∧ cong b 0 g ∧ \n    (∀ y:nat, cong a 0 y ∧ cong b 0 y → g ≥ y) \n\n-- Solution to linear diophantine equation with constants a b k\ndef LDE (a:int) (b:int) (k:int): Prop := ∃ x y: int, a*x + b*y = k\n\n\n\n-- existence of floor, gcd, and a solution to LDEs.\naxiom Efloor (a: int) (b:int): ∃ x:int, floor a b x\n\naxiom Egcd (a:int) (b: int): ∃ x: nat, gcd a b x\n\naxiom ELDE (a:int) (b: int): ∃ k: int, LDE a b k ∧ k > 0 ∧ (∀ y: int, LDE a b y → y ≥ k)  \n\n-- All of the above can be proven from Wop, but are temporarily axiomatised\n\naxiom WOP {k: nat} (p:nat → Prop) (H: p k): ∃ n: nat, p n ∧ (∀ y:nat, p y → y ≥ x)\n\n--\n\n-- Division algorithm\n\ntheorem DivAlgo (a : int) (b : int): ∃ q r : int, a = b*q + r ∧ 0 ≤ r ∧ b > r :=\nbegin \nhave Q: ∃ q r: int, a = b*q + r ∧ 0 ≤ r ∧ b > r, \n    from exists.elim (Efloor a b) (fun (x:int) (H: x*b ≤ a ∧ ∀  y: int, y*b ≤ a → y≤x),\nhave Hl: x*b ≤ a, from and.elim_left H, \nhave Hr: ∀  y: int, y*b ≤ a → y≤x, from and.elim_right H,\nhave L1: 0 = b*x - b*x, from eq.symm (sub_eq_zero_of_eq (eq.refl (b*x))), \nhave G1: a = b*x + (a-x*b), from calc \n     a = 0 + a: eq.symm (zero_add a)\n    ... = b*x - b*x + a: by rw [L1] \n    ... = b*x - x*b + a: by rw [mul_comm]\n    ... = b*x + a - x*b: sub_add_eq_add_sub (b*x) (x*b) a\n    ... = b*x + (a - x*b): add_sub_assoc (b*x) a (x*b),\nhave G2: 0 ≤ (a - x*b), from sub_nonneg_of_le Hl,\nhave Trich: b ≤ (a - x*b) ∨ b > (a - x*b), from le_or_gt b (a - x*b),\nhave G3: b > (a - x*b), from or.cases_on Trich\n(assume ass: b ≤ (a - x*b),\nhave  L2: a ≥ b + x*b, from add_le_of_le_sub_right ass,\nhave L3:  b + (x*b) = 1*b + (x*b), from by rw [one_mul],\nhave L4: (x+1)*b = (1+x)*b, from by rw [add_comm],\nhave C: (x+1)*b ≤ a, from calc\n a ≥ b + (x*b) : L2\n ... ≥ 1*b + (x*b): le_of_eq (eq.symm L3)\n ... ≥ (1+x)*b : le_of_eq (add_mul 1 x b)\n ... ≥ (x+1)*b : le_of_eq L4,\n have F: x+1 ≤ x, from Hr (x+1) C,\n have T: x+1 > x, from int.lt_add_one_of_le (le_of_eq (eq.refl x)),\n have will: b > (a - x*b), from absurd F (not_le_of_gt T),\n will)\n (assume ass: b > (a - x*b),\n ass),\n    have final: ∃ q r: int, a = b*q + r ∧ 0 ≤ r ∧ b > r, \n        from exists.intro x (exists.intro (a - x*b) (and.intro G1 (and.intro G2 G3))),\n    final),\n    exact Q\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 ∧ p > 0) ∧ (∀ (q: int), LDE a b q → q ≥ p)) : cong a 0 p:=\nbegin\nexact exists.elim (and.elim_left (and.elim_left W1))\n        (fun (x : int) (W2: ∃ y:int, a*x + b*y  = p),\n            exists.elim W2\n            (fun (y : int) (W3: a*x + b*y = p),\n                have App: ∃ m n: int, a = p*m + n ∧ 0 ≤ n ∧ p > n, from DivAlgo a p,\n                exists.elim (App)\n                (fun (m : int) (D1: ∃ n: int, a = p*m + n ∧ 0 ≤ n ∧ p > n),\n                    exists.elim D1\n                    (fun (n : int) (D: a = p*m + n ∧ (0 ≤ n ∧ p > n)),\n                    \n                        have Ntest: 0 ≤ n, from and.elim_left (and.elim_right D),\n                        have UB: p > n, from and.elim_right (and.elim_right D),\n\n                        have A1: a = p*m + n, from and.elim_left D,\n                        have A2: a = (a*x + b*y)*m + n, from eq.subst (eq.symm W3) A1,\n                        have A3: n = a - (a*x + b*y)*m, from eq_sub_of_add_eq' (eq.symm A2),\n                        have A: a*(1-x*m) + b*(-(y*m))  = n, from eq.symm (calc\n                            n = a - (a*x + b*y)*m : A3\n                            ... = a - (a*x*m + b*y*m) : by rw [add_mul (a*x) (b*y) m]\n                            ... = a - a*x*m - b*y*m : sub_add_eq_sub_sub a (a*x*m) (b*y*m)\n                            ... = a*1 - a*x*m - b*y*m : by rw [mul_one]\n                            ... = a*1 - a*(x*m) - b*y*m : by rw [mul_assoc]\n                            ... = a*(1 - x*m) - (b*y*m) : by rw [eq.symm (mul_sub a 1 (x*m))]\n                            ... = a*(1-x*m) + -(b*y*m) : by rw [sub_eq_add_neg] \n                            ... = a*(1-x*m) + -(b*(y*m)) : by rw [mul_assoc] \n                            ... = a*(1-x*m) + b*(-(y*m)) : by rw [neg_mul_eq_mul_neg]\n                        ),\n                        have Z1: n = 0, from or.by_cases (lt_or_eq_of_le Ntest)\n                        (assume H1: n > 0,\n                        have C0: LDE a b n, from exists.intro (1-x*m) (exists.intro (-(y*m)) A),\n                        have C1: ∀ q: int, LDE a b q → q ≥ p, from  (and.elim_right W1),\n                        have C2: n ≥ p, from C1 n C0,\n                        have C4: ¬ n < p, from not_lt_of_ge C2,\n                        have E: n = 0, from absurd UB C4,\n                        E)\n                        (assume H: 0 = n,\n                        eq.symm H),\n                        have P1: a = (p*m) + 0, from eq.subst Z1 A1,\n                        have P2: a = (p*m), from calc a = (p*m) + 0 : P1 ... = (p*m) : by rw [add_zero],\n                        have P3: a - 0 = p*m, from eq.trans (sub_zero a) P2,\n                        have P4: cong a 0 p, from exists.intro m P3,\n                        P4\n                    )\n                )\n            )\n        )\nend\n\n\n--WIP\n\n\nlemma LDEcomm (a: int) (b: int) (p: int) : LDE a b p ↔ LDE b a p :=\nbegin\nhave H:LDE a b p ↔ LDE b a p, from sorry,\nexact H\nend\n\ntheorem IntegersFormPID (a : int) (b : int): ∃ g:int, LDE a b g ∧ gcd a b g :=\nbegin\nhave H1: ∃ g:int, LDE a b g ∧ gcd a b g, from exists.elim (ELDE a b) \n    (fun (p:int) (W1: (LDE a b p ∧ p > 0) ∧  (∀ q: int, LDE a b q → q ≥ p)), \n    have H: cong a 0 p, from LDEsimp W1,\n    have W11: LDE a b p, from (and.elim_left (and.elim_left W1)),\n    have W12: LDE b a p, from iff.elim_left (LDEcomm a b p) W11,\n    have W2: p > 0, from and.elim_right (and.elim_left W1),\n    have W31: LDE a b p → LDE b a p, from iff.elim_left (LDEcomm a b p),\n    have W3: (∀ q: int, LDE b a q → q ≥ p), from iff_subst (LDEcomm a b p) (and.elim_right (and.elim_right W1)),\n    have W2: (LDE b a p ∧ p > 0) ∧  (∀ q: int, LDE b a q → q ≥ p), from iff_subst (LDEcomm a b p) W1,\n    have Hb: cong b 0 p, from LDEsimp W1,\n    )\nend\n\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/Chain_Of_Reasoning.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7897368654735575}}
{"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-/\nimport algebra.char_p.basic\nimport data.nat.factorization.prime_pow\nimport ring_theory.ideal.local_ring\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/-- In a local ring the characteristics is either zero or a prime power. -/\ntheorem char_p_zero_or_prime_power (R : Type*) [comm_ring R] [local_ring R] (q : ℕ)\n  [char_R_q : char_p R q] : q = 0 ∨ is_prime_pow q :=\nbegin\n  /- Assume `q := char(R)` is not zero. -/\n  apply or_iff_not_imp_left.2,\n  intro q_pos,\n  let K := local_ring.residue_field R,\n  haveI RM_char := ring_char.char_p K,\n\n  let r := ring_char K,\n  let n := (q.factorization) r,\n  /- `r := char(R/m)` is either prime or zero: -/\n  cases char_p.char_is_prime_or_zero K r with r_prime r_zero,\n  { 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.pow_factorization_dvd q r),\n    have r_ne_dvd_a := nat.not_dvd_div_pow_factorization r_prime q_pos,\n\n    have rn_dvd_q: r ^ n ∣ q := ⟨a, q_eq_a_mul_rn⟩,\n    rw mul_comm at q_eq_a_mul_rn,\n    have a_dvd_q : a ∣ q := ⟨r ^ n, q_eq_a_mul_rn⟩,\n    /- ... where `a` is a unit. -/\n    have a_unit : is_unit (a : R) :=\n    begin\n      by_contradiction g,\n      rw ←mem_nonunits_iff at g,\n      rw ←local_ring.mem_maximal_ideal at g,\n      have a_cast_zero := (ideal.quotient.eq_zero_iff_mem).2 g,\n      rw map_nat_cast at a_cast_zero,\n      have r_dvd_a := (ring_char.spec K a).1 a_cast_zero,\n      exact absurd r_dvd_a r_ne_dvd_a,\n    end,\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 : ↑(r ^ n) = (0 : R) :=\n    begin\n      rw [nat.cast_pow, ←@mul_one R _ (r ^ n), mul_comm,\n        ←(classical.some_spec a_unit.exists_left_inv), mul_assoc, ←nat.cast_pow, ←nat.cast_mul,\n        ←q_eq_a_mul_rn, char_p.cast_eq_zero R q],\n      simp,\n    end,\n    have q_eq_rn := nat.dvd_antisymm ((char_p.cast_eq_zero_iff R q (r ^ n)).mp rn_cast_zero)\n      rn_dvd_q,\n    have n_pos : n ≠ 0 :=\n    begin\n      by_contradiction n_zero,\n      simp [n_zero] at q_eq_rn,\n      exact absurd q_eq_rn (char_p.char_ne_one R q),\n    end,\n\n    /- Definition of prime power: `∃ r n, prime r ∧ 0 < n ∧ r ^ n = q`. -/\n    exact ⟨r, ⟨n, ⟨nat.prime_iff.mp r_prime, ⟨pos_iff_ne_zero.mpr n_pos, q_eq_rn.symm⟩⟩⟩⟩},\n  { haveI K_char_p_0 := ring_char.of_eq r_zero,\n    haveI K_char_zero: char_zero K := char_p.char_p_to_char_zero K,\n    haveI R_char_zero := ring_hom.char_zero (local_ring.residue R),\n    /- Finally, `r = 0` would lead to a contradiction: -/\n    have q_zero := char_p.eq R char_R_q (char_p.of_char_zero R),\n    exact absurd q_zero q_pos}\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/char_p/local_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7897368563305988}}
{"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 `∅`. 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 `∅ : set ℕ` and `∅ : set ℤ` 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 ∅ and univ\n\n`x ∈ ∅` is *by definition* equal to `false` and `x ∈ 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 ∈ (univ : set X) := \nbegin\n  sorry\nend\n\nexample : x ∈ (∅ : set X) → false :=\nbegin\n  sorry\nend\n\nexample : A ⊆ univ :=\nbegin\n  sorry\nend\n\nexample : ∅ ⊆ A :=\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/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.7897206088708103}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level2 -- add_assoc\nimport AdvancedAdditionWorld.Level8 -- eq_zero_of_add_right_eq_self\nimport AdvancedAdditionWorld.Level11 -- add_right_eq_zero\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 6: `le_antisymm`\n\nIn Advanced Addition World you proved\n\n`eq_zero_of_add_right_eq_self (a b : MyNat) : a + b = a → b = 0`.\n\nThis might be useful in this level.\n\nAnother tip: if you want to create a new hypothesis, you can use the `have` tactic.\nFor example, if you have a hypothesis `hd : a + (c + d) = a` and you want\na hypothesis `h : c + d = 0` then you can write\n\n`have h := eq_zero_of_add_right_eq_self hd`\n\n## Lemma : le_antisymm\n`≤` is antisymmetric. In other words, if `a ≤ b` and `b ≤ a` then `a = b`.\n-/\ntheorem le_antisymm (a b : MyNat) (hab : a ≤ b) (hba : b ≤ a) : a = b := by\n  cases hab with\n  | _ c hc =>\n    cases hba with\n    | _ d hd =>\n      rw [hc, add_assoc] at hd\n      have hd := hd.symm\n      have h := eq_zero_of_add_right_eq_self hd\n      have h2 := add_right_eq_zero h\n      rw [h2] at hc\n      rw [hc]\n      exact add_zero a\n\n/-!\nThis proved that the natural numbers are a partial order!\n-/\n-- BUGBUG : collectibles\n-- instance : partial_order MyNat := by structure_helper\n\n/-!\nNext up [Level 7](./Level7.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/Level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7896287319618992}}
{"text": "-- Natural numbers\n\n-- data type\n#eval nat.zero \n#eval (nat.succ nat.zero)\n#eval nat.succ (nat.succ nat.zero)\n\n-- notation\n#eval 0\n#eval 1\n#eval 2 \n\n-- operators\n#eval nat.add 1 2   -- addition\n#eval nat.mul 2 3   -- multiplication\n#eval nat.pow 2 3   -- exponentiation\n#eval nat.sub 4 1   -- subtraction\n#eval nat.div 4 3   -- quotient\n#eval nat.mod 4 3   -- remainder\n\n-- notation\n#eval 1 + 2\n#eval 2 * 3\n#eval 4 - 1 \n#eval 4 / 3\n#eval 4 % 3\n\n-- a theorem and its already Lean-defined proof\ndef add_commutes : ∀ (n m : ℕ), n + m = m + n := nat.add_comm", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/objects/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.960361157495521, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7895984987919631}}
{"text": "import data.real.basic\n\nvariables{u v: ℕ → ℝ }{l a b: ℝ}\n\nnotation`|`x`|` := abs x\n\ndef limite (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\ndef sucesion_cauchy (u : ℕ → ℝ) := \n∀ ε > 0, ∃ N, ∀ p q, p ≥ N → q ≥ N → |u p - u q| ≤ ε\n\n/-\nDEMOSTRACIÓN 1\n-/\n\nexample : (∃ l, limite u l) → sucesion_cauchy u :=\nbegin\n  intro h,\n  unfold sucesion_cauchy,\n  intros ε hε,\n  have hε2 : 0 < ε/2,\n    { linarith },\n  cases h with l hl,\n  cases hl (ε /2) hε2 with N hN,\n  clear hε hl hε2,\n  use N,\n  intros p q hp hq,\n  calc |u p - u q| = |(u p - l)+(l - u q)| : by ring_nf\n               ... ≤ |u p - l| + |l - u q| : abs_add (u p - l) (l - u q)\n               ... = |u p - l| + |u q - l| : by rw abs_sub l (u q)\n               ... ≤ ε /2 + ε /2           : add_le_add (hN p hp) (hN q hq)\n               ... = ε                     : add_halves ε,\nend\n\n/-\nDEMOSTRACIÓN 2\n-/\n\nexample : (∃ l, limite u l) → sucesion_cauchy u :=\nbegin\n  intro h,\n  intros ε hε,\n  cases h with l hl,\n  cases hl (ε /2) (by linarith) with N hN,\n  clear hε hl,\n  use N,\n  intros p q hp hq,\n  calc |u p - u q| = |(u p - l)+(l - u q)| : by ring_nf\n               ... ≤ |u p - l| + |l - u q| : abs_add (u p - l) (l - u q)\n               ... = |u p - l| + |u q - l| : by rw abs_sub l (u q)\n               ... ≤ ε /2 + ε /2           : add_le_add (hN p hp) (hN q hq)\n               ... = ε                     : add_halves ε,\nend\n\n/-\nDEMOSTRACIÓN 3\n-/\n\nexample : (∃ l, limite u l) → sucesion_cauchy u :=\nbegin\n  intros h ε hε,\n  cases h with l hl,\n  cases hl (ε /2) (by linarith) with N hN,\n  clear hε hl,\n  use N,\n  intros p q hp hq,\n  have cota1 : |u p - l| ≤ ε / 2 := hN p hp, \n  have cota2 : |u q - l| ≤ ε / 2 := hN q hq, \n  clear hN hp hq,\n  calc |u p - u q| = |(u p - l)+(l - u q)| : by ring_nf\n               ... ≤ |u p - l| + |l - u q| : abs_add (u p - l) (l - u q)\n               ... = |u p - l| + |u q - l| : by rw abs_sub l (u q)\n               ... ≤ ε                     : by linarith,\nend\n\n\n/-\nDEMOSTRACIÓN 4\n-/\n\nexample : (∃ l, limite u l) → sucesion_cauchy u :=\nbegin\n  intros h ε hε,\n  cases h with l hl,\n  cases hl (ε /2) (by linarith) with N hN,\n  clear hε hl,\n  use N,\n  intros p q hp hq,\n  calc |u p - u q| = |(u p - l)+(l - u q)| : by ring_nf\n               ... ≤ |u p - l| + |l - u q| : abs_add (u p - l) (l - u q)\n               ... = |u p - l| + |u q - l| : by rw abs_sub l (u q)\n               ... ≤ ε                     : by linarith [hN p (by linarith), hN q (by linarith)],\nend\n\n\n", "meta": {"author": "saradiazr11", "repo": "Formalizations_in_Lean", "sha": "a1fae92c3246cdd0d4fc68a105d25fdb40691ffe", "save_path": "github-repos/lean/saradiazr11-Formalizations_in_Lean", "path": "github-repos/lean/saradiazr11-Formalizations_in_Lean/Formalizations_in_Lean-a1fae92c3246cdd0d4fc68a105d25fdb40691ffe/cauchy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7894759228709497}}
{"text": "import lib.m154\n\n\n/-\n# Disjonctions\n\nCe fichier est consacré au connecteur logique de disjonction, noté simplement « ou » \nsur papier et `∨` dans Lean ainsi que dans les livres de logique pure (attention\nce symbole n'est pas la lettre v). \n\nPour *démontrer* un but de la forme `P ∨ Q`, on utilise \n`Montrons que P` et on démontre P ou `Montrons que Q` et\non démontre Q (il faut donc faire un choix stratégique).\n-/\n\nexample : 2^3 = 3 ∨ 2^3 = 8 :=\nbegin\n  Montrons que 2^3 = 8,\n  On calcule,\nend\n\nexample : 1 + 1 = 2 ∨ 1 + 3 = 17 :=\nbegin\n  sorry\nend\n\n\n/-\nPour *utiliser* une hypothèse de la forme `hyp : P ∨ Q`\nlors de la démonstration d'un but `R`, on tape\n`On discute en utilisant hyp,`\n(ou bien `On discute en utilisant (hyp : P ∨ Q),` pour plus de clarté)\nqui crée deux branches dans la démonstration :\nune branche où il faut démontrer `P → R`\net l'autre où il faut démontrer `Q → R`.\n-/\n\nexample {a : ℝ} (h : a = 2 ∨ a = -2) : a^2 = 4 :=\nbegin\n  On discute en utilisant h,\n  Supposons ha : a = 2,\n    calc \n      a^2 = 2^2 : by On réécrit via ha\n      ... = 4   : by On calcule,\n  Supposons ha : a = -2,\n    calc \n      a^2 = (-2)^2 : by On réécrit via ha\n      ... = 4   : by On calcule,\nend\n\nexample {a : ℝ} (h : a = 2 ∨ a = -3) : a^2 + a = 6 :=\nbegin\n  sorry\nend\n\n\n/-\nVoyons maintenant des énoncés qui successivement utilisent et démontrent\nune disjonction. L'utilisation d'une disjonction crée un embranchement \ndans la démonstration et la décision stratégique pour démontrer la disjonction\nbut dépend de la branche courante.\n\nDans l'exemple suivant, on utilise aussi\nla commande `On combine` suivie d'une liste d'hypothèses,\nqui cherche à démontrer une égalité ou une inégalité \npar combinaison linéaire de ces hypothèses. \nSi la liste ne consiste qu'en une seule hypothèse,\nil est plus naturel d'utiliser `On conclut par`.\nCette commande permet aussi de déduire `a ≤ b` de `a < b`\nou d'autres trivialités de ce genre.\n\nEnfin on utilise le lemme\n`mul_eq_zero : a*b = 0 ↔ a = 0 ∨ b = 0`\nqui servira aussi dans l'exercice suivant.\n-/\n\nexample (a b : ℝ) : a = a*b → a = 0 ∨ 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éécrit via mul_eq_zero dans H qui devient a = 0 ∨ 1 - b = 0,\n  On discute en utilisant (H : a = 0 ∨ 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 : ℝ) : x^2 = y^2 → x = y ∨ x = -y :=\nbegin\n  sorry\nend\n\n/-\nOn va maintenant combiner le quantificateur universel\net la disjonction dans deux exercices plus intéressants.\n\nOn rappelle la définition de fonction croissante :\n-/\n\ndef croissante (f : ℝ → ℝ) := ∀ x₁, (∀ x₂, x₁ ≤ x₂ → f x₁ ≤ f x₂)\n\n/-\nDans l'exercice suivant, on pourra utiliser le lemme\n`eq_or_lt_of_le : x ≤ y → x = y ∨ x < y`\n-/\nexample (f : ℝ → ℝ) : croissante f ↔ ∀ x y, x < y → f x ≤ f y :=\nbegin\n  sorry\nend\n\n/-\nDans l'exercice suivant, on pourra utiliser le lemme\n`le_total x y : x ≤ y ∨ y ≤ x`\n\nCet exercice nécessite de réfléchir un peu plus que les\nprécédents, l'énoncé n'étant pas complètement évident.\n-/\nexample (f : ℝ → ℝ) (h : croissante f) (h' : ∀ x, f (f x) = x) : ∀ 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/06_ou.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8688267796346598, "lm_q1q2_score": 0.7894315613105667}}
{"text": "-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar\n--    ∃ x, ¬(P x) ⊢ ¬(∀ x, P x)\n-- ----------------------------------------------------\n\nimport tactic\n\nvariable (U : Type)\nvariable (P : U -> Prop)\n\n-- 1ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\nbegin\n  intro h1,\n  cases h with a h2,\n  apply h2,\n  exact h1 a,\nend\n\n-- 2ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\nbegin\n  intro h1,\n  cases h with a h2,\n  exact h2 (h1 a),\nend\n\n-- 3ª demostración\nexample :\n  (∃ x, ¬(P x)) → ¬(∀ x, P x) :=\nbegin\n  rintro ⟨a, h2⟩ h1,\n  exact h2 (h1 a),\nend\n\n-- 4ª demostración\nexample :\n  (∃ x, ¬(P x)) → ¬(∀ x, P x) :=\nλ ⟨a, h2⟩ h1, h2 (h1 a)\n\n-- 5ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\nassume h1 : ∀ x, P x,\nexists.elim h\n  ( assume a,\n    assume h2 : ¬(P a),\n    have h3 : P a,\n      from h1 a,\n    show false,\n      from h2 h3 )\n\n-- 6ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\nassume h1 : ∀ x, P x,\nexists.elim h\n  ( assume a,\n    assume h2 : ¬(P a),\n    h2 (h1 a) )\n\n-- 7ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\nassume h1 : ∀ x, P x,\nexists.elim h\n  (λ a h2, h2 (h1 a) )\n\n-- 8ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\nλ h1, exists.elim h (λ a h2, h2 (h1 a) )\n\n-- 9ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\n-- by library_search\nnot_forall.mpr h\n\n-- 10ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\n-- by hint\nby tauto\n\n-- 11ª demostración\nexample\n  (h: ∃ x, ¬(P x))\n  : ¬(∀ x, P x) :=\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/2_LPO/Ejercicios/∃x,¬(Px)⊢¬(∀x.Px).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.7894156059619267}}
{"text": "/-\nCopyright (c) 2022 James Gallicchio.\n\nAuthors: James Gallicchio\n-/\n\nimport Mathlib.Data.Nat.Basic\nimport Mathlib.Init.Data.Int.Basic\nimport Mathlib.Order.Basic\nimport Mathlib.Data.UInt\n\nnamespace Nat\n  theorem sub_dist (x y z : Nat) : x - (y + z) = x - y - z := by\n    induction z\n    simp\n    case succ z z_ih =>\n    simp [Nat.sub_succ, Nat.add_succ, z_ih]\n\n  theorem sub_lt_of_lt_add {x y z : Nat}\n    : x < y + z → x ≥ z → x - z < y\n    := by\n    intro h h_z\n    apply Nat.le_of_add_le_add_right\n    rw [succ_add, Nat.sub_add_cancel h_z]\n    assumption\n\n  theorem add_mul_div {x y z : Nat} (h_x : 0 < x)\n    : (x * y + z) / x = y + z / x\n    := by\n    induction y generalizing z with\n    | zero => simp\n    | succ y ih =>\n      simp [mul_succ, Nat.add_assoc]\n      rw [ih]\n      simp [HDiv.hDiv, Div.div]\n      rw [Nat.div]\n      simp [h_x, Nat.le_add_right]\n      rw [Nat.add_comm x z, Nat.add_sub_cancel,\n        Nat.add_comm _ 1, ←Nat.add_assoc, Nat.add_one]\n\n  theorem mul_div_with_rem_cancel (x : Nat) {q r : Nat} (h_r : r < q)\n    : (x * q + r) / q = x\n    := by\n    induction x with\n    | zero =>\n      rw [div_eq]\n      have : 0 < q := zero_lt_of_lt h_r\n      simp [this, Nat.not_le_of_gt h_r]\n    | succ x ih =>\n      rw [div_eq]\n      simp [zero_lt_of_lt h_r]\n      have : q ≤ (x + 1) * q + r := by\n        simp [succ_mul]\n        rw [Nat.add_comm _ q, Nat.add_assoc]\n        apply Nat.le_add_right\n      simp [this]\n      rw [succ_mul, Nat.add_assoc, Nat.add_comm q,\n          ←Nat.add_assoc, Nat.add_sub_cancel]\n      assumption\n  \n  theorem le_of_mul_of_div { x y : Nat }\n    : x * (y / x) ≤ y\n    := by\n    apply Nat.le_of_add_le_add_right (b := y % x)\n    rw [div_add_mod]\n    apply Nat.le_add_right\n\n  /-\n  theorem lt_of_mul_lt {x y z : Nat} (h_z : 0 < z)\n    : x < y * z → x / z < y\n    := by\n    intro h\n    by_cases x / z < y\n    case pos h_res =>\n      assumption\n    case neg h_res =>\n      rw [←div_add_mod x z] at h\n      apply False.elim $ Nat.not_le_of_gt h _\n      clear h h_z\n      rw [Nat.mul_comm]\n      suffices z * y ≤ z * (x / z) from\n        Nat.le_trans this $ Nat.le_add_right _ (x % z)\n      apply Nat.mul_le_mul_left z\n      exact Nat.ge_of_not_lt h_res\n  -/\n\n  theorem lt_of_lt_le {x y z : Nat} : x < y → y ≤ z → x < z := by\n    intro h h'\n    induction h'\n    assumption\n    apply Nat.le_step\n    assumption\n\n  theorem min_le_right {x y : Nat} : min x y ≤ y := by\n    simp [min]\n    split\n    assumption\n    simp\n\n  theorem min_symm (x y : Nat) : min x y = min y x := by\n    simp [min]\n    split\n    case inl h =>\n      cases h <;> simp\n      case step h => simp [Nat.not_le.mpr (Nat.succ_le_succ h)]\n    case inr h =>\n      simp [Nat.le_of_lt <| Nat.gt_of_not_le h]\n\n  @[simp]\n  theorem min_zero_left {x} : min 0 x = 0 := by\n    rw [←Nat.le_zero_eq]\n    exact min_le_left _ _\n\n  @[simp]\n  theorem min_zero_right {x} : min x 0 = 0 := by\n    rw [←Nat.le_zero_eq]\n    exact min_le_right\n\n  def toUSize! (n : Nat) : USize :=\n    if n < USize.size then\n      n.toUSize\n    else\n      panic! s!\"Integer {n} is to larget for usize\"\n\n  theorem mod_lt_of_lt {x y z : Nat}\n    : x < y → z > 0 → x % z < y\n    := by\n    intro h h_z\n    match h_y : decide (y ≤ z) with\n    | true =>\n      have := of_decide_eq_true h_y\n      rw [Nat.mod_eq_of_lt (Nat.lt_of_lt_le h this)]\n      assumption\n    | false =>\n      have := of_decide_eq_false h_y\n      apply Nat.lt_trans _ (Nat.gt_of_not_le this)\n      apply Nat.mod_lt\n      assumption\n\n  @[inline]\n  def square (n : Nat) := n * n\n\n  def sqrt (n : Nat) : Nat :=\n    let guess := n / 2\n    if guess = 0 then n else\n    let rec iter (guess : Nat) : Nat :=\n      let next := (guess + n / guess) / 2\n      if h : guess ≤ next then\n        guess\n      else\n        have : next < guess := Nat.gt_of_not_le h\n        iter next\n    iter guess\n  termination_by iter guess => guess\n\n  theorem square_sqrt_le (n)\n    : square (sqrt n) ≤ n\n    :=\n    match n with\n    | 0 | 1 => by simp\n    | n+2 =>\n    let rec iter n (guess) (g_pos : guess > 0) (g_le_n : guess ≤ n)\n      : square (sqrt.iter n guess) ≤ n\n      :=\n      let next := (guess + n / guess) / 2\n      if h : guess ≤ next then by\n        unfold sqrt.iter\n        simp [h, square]\n        apply (le_div_iff_mul_le g_pos).mp\n        apply Nat.le_of_add_le_add_left (a := guess)\n        rw [(by simp [succ_mul] : guess + guess = 2 * guess)]\n        rw [mul_comm]\n        apply (le_div_iff_mul_le (by decide)).mp\n        exact h\n      else\n        have : next < guess := Nat.gt_of_not_le h\n        have next_pos : next > 0 := by\n          have : n / guess = succ _ := by\n            conv => lhs; simp [Div.div, HDiv.hDiv]; unfold Nat.div\n            simp [g_pos, g_le_n]\n            rfl\n          cases guess <;> simp at this\n          simp [this, succ_add, add_succ]\n          simp [succ_eq_add_one, add_assoc]\n          rw [(by decide : 1 + 1 = 2)]\n          simp [←add_assoc]\n          apply succ_le_succ (zero_le _)\n        have next_le_n : next ≤ n := by\n          simp\n          apply Nat.div_le_of_le_mul\n          simp [succ_mul]\n          apply Nat.add_le_add\n          assumption\n          apply Nat.div_le_self\n        have := iter n next next_pos next_le_n\n        by unfold sqrt.iter; simp [h, this]\n    have := iter (n+2) ((n+2)/2)\n      (by simp; apply succ_le_succ; simp)\n      (Nat.div_le_self _ _)\n    by simp [sqrt] at this ⊢; exact this\n  termination_by iter guess _ _ => guess\n\n  theorem square_succ_sqrt_gt (n)\n    : n < square ((sqrt n)+1)\n    :=\n    match n with\n    | 0 | 1 => by simp\n    | n+2 =>\n    let rec iter n (guess) (g_succ_gt_n : square (guess+1) > n)\n      : n < square (sqrt.iter n guess + 1)\n      :=\n      let next := (guess + n / guess) / 2\n      if h : guess ≤ next then by\n        unfold sqrt.iter\n        simp [h, g_succ_gt_n]\n      else\n        have : next < guess := Nat.gt_of_not_le h\n        have : square (next + 1) > n := by\n          have : square (next + 1) ≤ square guess := by sorry\n          have : n < square guess := by sorry\n          sorry\n        have := iter n next this\n        by unfold sqrt.iter; simp [h, this]\n    have := iter (n+2) ((n+2)/2) (by\n      simp [square]\n      have : n ≤ 2 * (n / 2) + 1 := by\n        apply Nat.le_trans (m := 2 * (n / 2) + n % 2)\n        rw [Nat.div_add_mod]; apply Nat.le_refl\n        apply Nat.add_le_add; apply Nat.le_refl\n        apply Nat.le_of_succ_le_succ\n        simp [(by decide : succ 1 = 2)]\n        apply Nat.mod_lt\n        decide\n      simp [succ_mul, mul_succ] at this ⊢\n      simp [succ_add, add_succ]\n      apply succ_le_succ; apply succ_le_succ; apply succ_le_succ\n      apply Nat.le_trans this\n      apply succ_le_succ\n      simp\n      apply Nat.add_le_add_right\n      apply Nat.le_add_left)\n    by simp [sqrt] at this ⊢; exact this\n  termination_by iter guess _ _ => guess\n\n\n#eval sqrt 0\n#eval (7 + 15 / 7) / 2\n\nend Nat\n\nnamespace Fin\n\n@[simp]\ndef embed_add_right : Fin n → Fin (n+m)\n| ⟨i, h⟩ => ⟨i, Nat.lt_of_lt_le h (Nat.le_add_right _ _)⟩\n\n@[simp]\ndef embed_add_left : Fin n → Fin (m+n)\n| ⟨i, h⟩ => ⟨i, Nat.lt_of_lt_le h (Nat.le_add_left _ _)⟩\n\n@[simp]\ndef embed_succ : Fin n → Fin n.succ\n| ⟨i, h⟩ => ⟨i, Nat.lt_of_lt_le h (Nat.le_step $ Nat.le_refl _)⟩\n\n@[simp]\ndef last (n : Nat) : Fin n.succ := ⟨n, Nat.lt_succ_self _⟩\n\nend Fin\n\nnamespace Int\n\ntheorem ofNat_natAbs_eq_neg_of_nonpos (a : Int) (h : a ≤ 0)\n  : ofNat (natAbs a) = -a\n  := by\n  rw [←Int.natAbs_neg]\n  apply Int.ofNat_natAbs_eq_of_nonneg\n  apply Int.neg_le_neg h\n\nend Int\n\nnamespace USize\n\ntheorem usize_bounded : USize.size ≤ UInt64.size := by\n  cases usize_size_eq <;> (\n    rw [(by assumption : USize.size = _)]\n    decide\n  )\n\nend USize\n\nnamespace List\n  def front? : List τ → Option (τ × List τ)\n  | [] => none\n  | t::ts => some (t,ts)\n\n  @[simp]\n  theorem front_cons (ts : List τ)\n    : (ts.cons t).front? = some (t,ts)\n    := by\n    cases ts\n    repeat {simp [front?]}\n\n  def back? : List τ → Option (List τ × τ)\n  | [] => none\n  | t::ts => some (match ts.back? with | none => ([],t) | some (ts',t') => (t::ts',t'))\n\n  @[simp]\n  theorem back_concat (ts : List τ)\n    : (ts.concat t).back? = some (ts,t)\n    := by\n    induction ts\n    simp [back?]\n    case cons t' ts' ih =>\n    simp at ih ⊢\n    simp [back?, ih]\n\n  theorem concat_nonempty (L : List τ)\n    : L.concat x ≠ []\n    := by\n    induction L\n    simp [concat]\n    simp [concat]\n\n  theorem back_some_iff_concat (L : List τ)\n    : L.back? = some (ts,t) ↔ L = ts.concat t\n    := by\n    apply Iff.intro\n    case mpr =>\n      intro h; rw [h, back_concat]\n    case mp =>\n    induction ts generalizing L\n    case nil =>\n      simp [concat]\n      intro h\n      match L with\n      | [] => contradiction\n      | [t] => simp [back?] at h; simp [h]\n      | _::_::_ => simp [back?] at h\n    case cons head tail ih =>\n      simp [concat]\n      intro h\n      match L with\n      | [] => contradiction\n      | [x] => simp [back?] at h\n      | x::y::z =>\n        have ihh : back? (y::z) = some (tail, t) := by\n          simp [back?] at h\n          cases h; case intro l r =>\n          simp [back?]\n          match h:back? z with\n          | none =>\n            simp [h] at l r\n            simp [l,r]\n          | some (ts',t') =>\n            simp [h] at l r ⊢\n            simp [l,r]\n        have := ih _ ihh\n        rw [this]; simp; clear this\n        unfold back? at h\n        simp [ihh] at h\n        assumption\n\n  @[simp]\n  theorem concat_append (L₁ L₂ : List τ)\n    : (L₁ ++ L₂).concat x = L₁ ++ L₂.concat x\n    := by\n    induction L₁ <;> simp\n\n  @[simp]\n  theorem map_concat (L : List τ) (f : τ → α)\n    : (L.concat x).map f = (L.map f).concat (f x)\n    := by\n    induction L <;> simp [concat,map]\n\n  @[simp]\n  theorem join_concat (L : List (List τ))\n    : (L.concat x).join = L.join ++ x\n    := by\n    simp [concat]\n    induction L <;> simp [concat,join]\n    assumption\n  \n  @[simp]\n  theorem get_of_set_eq (L : List τ) (i : Fin L.length) (x : τ)\n    : (L.set i x).get ⟨i, by rw [length_set]; exact i.isLt⟩ = x\n    := by\n      induction L\n      simp at i; exact Fin.elim0 i\n      case cons hd tl ih =>\n      cases i; case mk i h_i =>\n      cases i\n      simp [set,get]\n      case succ i =>\n      simp at h_i\n      have h_i := Nat.lt_of_succ_lt_succ h_i\n      have := ih ⟨i,h_i⟩\n      simp at this\n      simp [set,get]\n  \n  @[simp]\n  theorem get_of_set_ne (L : List τ) (i : Nat) (x : τ) (j : Fin L.length)\n    : i ≠ j → (L.set i x).get ⟨j, by rw [length_set]; exact j.isLt⟩ = L.get j\n    := by\n      intro h\n      induction L generalizing i\n      simp at j; exact Fin.elim0 j\n      case cons hd tl ih =>\n      cases j; case mk j h_j =>\n      cases j\n      simp at h\n      cases i; contradiction\n      simp [set,get]\n      case succ j =>\n      simp at h_j\n      simp\n      cases i\n      simp [set,get]\n      case succ i =>\n      simp [set,get]\n      simp at h\n      have h_j := Nat.lt_of_succ_lt_succ h_j\n      have := ih i ⟨j,h_j⟩ h\n      exact this\n  \n  theorem set_of_ge_length (L : List α) (i x) (h : ¬i < L.length)\n    : L.set i x = L\n    := by\n    induction L generalizing i\n    simp\n    case cons hd tl ih =>\n    cases i\n    simp at h\n    simp at h\n    simp\n    apply ih\n    apply Nat.not_lt_of_le\n    apply Nat.le_of_succ_le_succ h\n  \n  theorem set_append_left (L1 L2 : List α) (i x) (h : i < L1.length)\n    : (L1 ++ L2).set i x = L1.set i x ++ L2\n    := by\n    induction L1 generalizing i with\n    | nil => simp at h; contradiction\n    | cons hd tl ih =>\n    match i with\n    | 0 =>\n      simp at h\n      simp [set]\n    | i+1 =>\n      simp at h\n      simp [set]\n      apply ih\n      apply Nat.le_of_succ_le_succ h\n\n  theorem set_append_right (L1 L2 : List α) (i x) (h : L1.length ≤ i)\n    : (L1 ++ L2).set i x = L1 ++ L2.set (i - L1.length) x\n    := by\n    induction L1 generalizing i with\n    | nil => simp [set]\n    | cons hd tl ih =>\n    match i with\n    | 0 =>\n      simp at h\n    | i+1 =>\n      simp at h\n      simp [set]\n      rw [Nat.succ_sub_succ]\n      apply ih\n      apply Nat.le_of_succ_le_succ h\n  \n  theorem map_set {L : List τ} {i x} {f : τ → τ'}\n    : (L.set i x).map f = (L.map f).set i (f x)\n    := by\n    induction L generalizing i with\n    | nil => simp\n    | cons y ys ih =>\n      cases i\n      simp [set]\n      simp [ih]\n  \n  theorem set_map {L : List τ} (x') (h : x = f x')\n    : (L.map f).set i x = (L.set i x').map f\n    := by\n    induction L generalizing i with\n    | nil => simp\n    | cons y ys ih =>\n      cases i\n      simp [set]; assumption\n      simp [set, ih]\n\n  def subtypeByMem (L : List α) : List {a // a ∈ L} :=\n    let rec aux (rest : List α) (h : ∀ a, a ∈ rest → a ∈ L)\n      : List {a // a ∈ L} :=\n      match rest, h with\n      | [], _ => []\n      | (x::xs), h =>\n        ⟨x, h _ (List.Mem.head _ _)⟩ ::\n        aux xs (by intros; apply h; apply List.Mem.tail; assumption)\n    aux L (by intros; assumption)\n\n  theorem length_subtypeByMemAux (L rest : List α) (h)\n    : (List.subtypeByMem.aux L rest h).length = rest.length\n    := by\n      induction rest\n      simp [subtypeByMem.aux]\n      case cons hd tl ih =>\n      simp [subtypeByMem.aux]\n      apply ih\n\n  @[simp]\n  theorem length_subtypeByMem (L : List α)\n    : L.subtypeByMem.length = L.length\n    := by apply length_subtypeByMemAux\n\n  @[simp]\n  theorem get_subtypeByMem (L : List α) (i : Fin L.subtypeByMem.length)\n    : L.subtypeByMem.get i = L.get ⟨i, by cases i; case mk _ h => simp at h; assumption⟩\n    := by\n    simp [subtypeByMem]\n    suffices ∀ L' hL' i (hi : i < length L'),\n      (get (subtypeByMem.aux L L' hL') ⟨i, by\n        simp [length_subtypeByMemAux] at hi ⊢\n        exact hi⟩).val =\n      get L' ⟨i, hi⟩\n      from this L (by simp) i (by cases i; case mk _ h => simp at h; assumption)\n    intro L' hL' i hi\n    induction L' generalizing i with\n    | nil =>\n      simp [subtypeByMem.aux]\n      unfold get\n      split <;> split <;> contradiction\n    | cons x xs ih =>\n      simp [subtypeByMem.aux]\n      unfold get\n      split\n      case h_1 a b c d e f g =>\n        simp at f\n        cases f; case intro f1 f2 =>\n        cases f1\n        cases f2\n        simp at g\n        split\n        case h_1 h i j k l m n o =>\n          cases n\n          rfl\n        case h_2 h i j k l m n o =>\n          cases n\n          cases o\n          contradiction\n      case h_2 a b c d e f g =>\n        simp at f\n        cases f; case intro f1 f2 =>\n        cases f1\n        cases f2\n        simp at g\n        split\n        case h_1 h i j k l m n o =>\n          cases n\n          cases o\n          contradiction\n        case h_2 h i j k l m n o =>\n          cases n\n          cases o\n          cases g\n          simp at e\n          apply ih\n\n  def index_of_mem (L : List α) (x) (h : x ∈ L) : ∃ i, L.get i = x := by\n    induction L\n    cases h <;> contradiction\n    case cons hd tl ih =>\n    cases h\n    apply Exists.intro ⟨0,by apply Nat.succ_le_succ; exact Nat.zero_le _⟩\n    simp [get]\n    cases ih (by assumption)\n    case intro w h =>\n    apply Exists.intro w.succ\n    simp [get]\n    exact h\n  \n  theorem get_of_take (L : List α) (n i) (h : n ≤ L.length)\n    : (L.take n).get i = L.get ⟨i.val, by\n        apply Nat.le_trans i.isLt\n        simp [length_take]\n        rw [Nat.min_symm]\n        exact Nat.min_le_left _ _\n      ⟩\n    := by\n    induction L generalizing n\n    case nil =>\n      cases n <;> (\n        simp [length, take] at i\n        exact Fin.elim0 i\n      )\n    case cons hd tl ih =>\n    cases n\n    case zero =>\n      simp [length, take] at i\n      exact Fin.elim0 i\n    case succ n =>\n      cases i; case mk i h_i =>\n      cases i\n      case zero =>\n        simp [get, take]\n      case succ i =>\n        simp [get, take]\n        apply ih\n        simp [length] at h\n        exact Nat.le_of_succ_le_succ h\n\n  theorem get_map_reverse (f : α → β) {l n}\n    : f (get l n) = get (map f l) ⟨n, by simp [n.isLt]⟩\n    := by simp\n\n  @[simp]\n  theorem length_rangeAux : (rangeAux n L).length = L.length + n := by\n    induction n generalizing L <;> simp [length, rangeAux, *]\n    case succ n ih =>\n    rw [←Nat.add_one, Nat.add_comm n 1, Nat.add_assoc]\n\n  @[simp]\n  theorem length_range : (range n).length = n := by\n    simp [range]\n\n  theorem rangeAux_eq_append\n    : rangeAux n (x :: L) = rangeAux n [] ++ (x :: L)\n    := by\n    suffices ∀ L, rangeAux n L = rangeAux n [] ++ L from\n      this (cons x L)\n    intro L\n    induction n generalizing L\n    simp [rangeAux]\n    case succ n ih =>\n    simp [get, rangeAux]\n    rw [@ih (n :: L), @ih [n]]\n    simp [List.append_assoc]\n  \n  theorem get?_range (n) (i : Nat) (h : i < n) : (range n).get? i = some i := by\n    induction n with\n    | zero => cases h\n    | succ n ih =>\n      unfold range\n      simp [rangeAux]\n      rw [rangeAux_eq_append]\n      have : i < length (rangeAux n [] ++ [n]) := by\n        simp; assumption\n      rw [get?_eq_get this, Option.some_inj]\n      match h_i:Nat.beq i n with\n      | true =>\n        simp at h_i\n        rw [List.get_append_right]\n        simp [get, h_i]\n        simp [h_i]\n        simp [h_i]\n      | false =>\n        have h := Nat.le_of_succ_le_succ h\n        have h_i := Nat.ne_of_beq_eq_false h_i\n        have : i < n := Nat.lt_of_le_of_ne h h_i\n        rw [List.get_append_left]\n        case h => simp [this]\n        rw [←Option.some_inj]\n        rw [←get?_eq_get]\n        exact ih this\n\n  theorem get_range' (n) (i : Nat) (h) : (range n).get ⟨i, h⟩ = i := by\n    rw [←Option.some_inj, ← get?_eq_get]\n    exact get?_range _ _ (by simp at h; exact h)\n\n  @[simp]\n  theorem get_range (i : Fin n) : (range n).get (cast (by simp) i) = i := by\n    have : ∀ m (h : m = n) h', (cast (h ▸ rfl) i : Fin m) = ⟨i, h'⟩ := by\n      intros m h h'; cases h; rfl\n    rw [this]; apply get_range'; simp; simp [i.2]\n\n\n  theorem foldl_acc_cons (L : List τ) (f : _ → _) (x') (acc : List τ')\n    : L.foldl (fun acc x => acc ++ f x) (x' :: acc)\n      = x' :: L.foldl (fun acc x => acc ++ f x) acc\n    := by\n    induction L generalizing acc with\n    | nil => simp [foldl]\n    | cons x xs ih =>\n      unfold foldl\n      rw [List.cons_append, ih]\n\n  theorem foldl_eq_reverseAux (L : List τ) (acc)\n    : L.foldl (fun acc x => x :: acc) acc = L.reverseAux acc\n    := by\n    induction L generalizing acc with\n    | nil => simp [foldl]\n    | cons x xs ih =>\n      unfold foldl\n      apply ih\n\n  theorem foldl_eq_map (L : List τ) (f : τ → τ')\n    : L.foldl (fun acc x => acc ++ [f x]) [] = L.map f\n    := by\n    induction L with\n    | nil => simp [foldl]\n    | cons x xs ih =>\n      unfold foldl\n      simp [foldl_acc_cons]\n      apply ih\n\n  theorem foldl_eq_filter (L : List τ) (f : τ → Bool)\n    : L.foldl (fun acc x => acc ++ if f x then [x] else []) [] = L.filter f\n    := by\n    induction L with\n    | nil => simp [filter, foldl]\n    | cons x xs ih =>\n      unfold foldl\n      apply Eq.symm\n      simp [filter]\n      split <;> (\n        simp [(by assumption : f x = _)]\n        simp [foldl_acc_cons]\n        apply ih.symm\n      )\n\n  theorem foldl_filter (L : List τ) (f : τ → Bool) (foldF) (foldAcc : β)\n    : (L.filter f).foldl foldF foldAcc =\n      L.foldl (fun acc x => if f x then foldF acc x else acc) foldAcc\n    := by\n    induction L generalizing foldAcc with\n    | nil => simp [foldl]\n    | cons x xs ih =>\n      unfold filter\n      split\n      case cons.h_1 h =>\n        simp [h, foldl, ih]\n      case cons.h_2 h =>\n        simp [h, foldl, ih]\n  \n  theorem foldr_eq_map (L : List τ) (f : τ → τ')\n    : L.foldr (f · :: ·) [] = L.map f\n    := by induction L <;> simp; assumption\n  \n  theorem foldr_eq_filter (L : List τ) (f : τ → Bool)\n    : L.foldr (fun x acc => if f x then x :: acc else acc) [] = L.filter f\n    := by\n      induction L <;> simp [filter]\n      split <;> split\n      case h_1 =>\n        simp; assumption\n      case h_2 h _ h' =>\n        rw [h] at h'; contradiction\n      case h_1 =>\n        contradiction\n      case h_2 =>\n        simp; assumption\n\n  theorem foldr_cons_eq_foldl_append (L : List τ) (f : _ → β)\n    : L.foldr (f · :: ·) [] = L.foldl (· ++ [f ·]) []\n    := by rw [foldr_eq_map, foldl_eq_map]\n\n  theorem mem_of_map_iff (L : List τ) (f : τ → τ')\n    : ∀ y, y ∈ L.map f ↔ ∃ x, x ∈ L ∧ f x = y\n    := by\n    intro y\n    induction L with\n    | nil => simp\n    | cons x xs ih =>\n      simp\n      constructor\n      case mp =>\n        intro h; cases h\n        case inl h =>\n          exact .inl h.symm\n        case inr h =>\n          cases ih.mp h; case intro x' h =>\n          exact .inr ⟨x', h.1, h.2⟩\n      case mpr =>\n        intro h; cases h\n        case inl h' =>\n          exact .inl h'.symm\n        case inr h' =>\n          exact Or.inr (ih.mpr h')\n\nend List\n\ninductive Vector (α : Type u) : Nat → Type u where\n  | nil  : Vector α 0\n  | cons : α → Vector α n → Vector α (n+1)\n\nnamespace Vector\n  def ofList : (L : List τ) → Vector τ L.length\n  | [] => nil\n  | x::xs => cons x (ofList xs)\n\n  def toList : (V : Vector τ n) → List τ\n  | nil => []\n  | cons x xs => x :: toList xs\n\n  theorem length_toList (V : Vector τ n)\n  : V.toList.length = n\n  := by induction V <;> simp [toList]; assumption\nend Vector\n\nnamespace Function  \n  def update' {α α' : Sort u} {β : α → Sort u} (f : (a : α) → β a) (i : α) (x : α') [D : DecidableEq α]\n    : (a : α) → update β i α' a\n    := λ a =>\n    if h:a = i\n    then cast (by simp [h, update]) x\n    else cast (by simp [h]) (f a)\nend Function\n\ndef Cached {α : Type _} (a : α) := { b // b = a }\n\nnamespace Cached\n\ninstance {a : α} : DecidableEq (Cached a) :=\n  fun ⟨x, hx⟩ ⟨y, hy⟩ => Decidable.isTrue (by cases hx; cases hy; rfl)\n\ninstance {a : α} [Repr α] : Repr (Cached a) where\n  reprPrec x := Repr.addAppParen <| \"cached \" ++ repr x.val\n\ninstance {a : α} : Subsingleton (Cached a) :=\n  ⟨by intro ⟨x, h⟩; cases h; intro ⟨y, h⟩; cases h; rfl⟩\n\ninstance {a : α} : CoeHead (Cached a) α where\n  coe x := x.1\n\ndef cached (a : α) : Cached a :=\n  ⟨a, rfl⟩\n\ndef cached' (a : α) (h : a = b) : Cached b :=\n  ⟨a, h⟩\n\ninstance {a : α} : Inhabited (Cached a) where\n  default := cached a\n\n@[simp] theorem cached_val (a : α) (b : Cached a) : (b : α) = a := b.2\n\nend Cached\n\nexport Cached (cached)\nexport Cached (cached')\n\ndef time (f : IO α) : IO (Nat × α) := do\n  let pre ← IO.monoMsNow\n  let ret ← f\n  let post ← IO.monoMsNow\n  pure (post-pre, ret)\n", "meta": {"author": "JamesGallicchio", "repo": "LeanColls", "sha": "9cb0a0c9a838bea24be80eace168bcc5f9481596", "save_path": "github-repos/lean/JamesGallicchio-LeanColls", "path": "github-repos/lean/JamesGallicchio-LeanColls/LeanColls-9cb0a0c9a838bea24be80eace168bcc5f9481596/LeanColls/AuxLemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7893343455607775}}
{"text": "import tactic\n\nvariables (p q r : Prop)\n\n-- 1ª demostración\nexample : ((p ∨ q) → r) ↔ ((p → r) ∧ (q → r)) :=\nor_imp_distrib\n\n-- 2ª demostración\nexample : ((p ∨ q) → r) ↔ ((p → r) ∧ (q → r)) :=\n⟨λ h, ⟨λ hp, h (or.inl hp), \n       λ hq, h (or.inr hq)⟩, \n λ ⟨hpr, hqr⟩ hpq, hpq.elim hpr hqr⟩\n\n-- 3ª demostración\nexample : ((p ∨ q) → r) ↔ ((p → r) ∧ (q → r)) :=\nbegin\n  split,\n  { intro h,\n    split,\n    { intro hp,\n      exact h (or.inl hp), },\n    { intro hq,\n      exact h (or.inr hq), }},\n  { rintros ⟨hpr, hqr⟩ hpq,\n    cases hpq with hp hq,\n    { exact hpr hp, },\n    { exact hqr hq, }},\nend    \n\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/Formula_proposicional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7892771627476615}}
{"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\n! This file was ported from Lean 3 source module algebra.ring.regular\n! leanprover-community/mathlib commit 2f3994e1b117b1e1da49bcfb67334f33460c3ce4\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Regular.Basic\nimport Mathlib.Algebra.Ring.Defs\n\n/-!\n# Lemmas about regular elements in rings.\n-/\n\n\nvariable {α : Type _}\n\n/-- Left `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor.\nThe typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/\ntheorem isLeftRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α)\n    (h : ∀ x : α, k * x = 0 → x = 0) : IsLeftRegular k := by\n  refine' fun x y (h' : k * x = k * y) => sub_eq_zero.mp (h _ _)\n  rw [mul_sub, sub_eq_zero, h']\n#align is_left_regular_of_non_zero_divisor isLeftRegular_of_non_zero_divisor\n\n/-- Right `Mul` by a `k : α` over `[Ring α]` is injective, if `k` is not a zero divisor.\nThe typeclass that restricts all terms of `α` to have this property is `NoZeroDivisors`. -/\ntheorem isRightRegular_of_non_zero_divisor [NonUnitalNonAssocRing α] (k : α)\n    (h : ∀ x : α, x * k = 0 → x = 0) : IsRightRegular k := by\n  refine' fun x y (h' : x * k = y * k) => sub_eq_zero.mp (h _ _)\n  rw [sub_mul, sub_eq_zero, h']\n#align is_right_regular_of_non_zero_divisor isRightRegular_of_non_zero_divisor\n\ntheorem isRegular_of_ne_zero' [NonUnitalNonAssocRing α] [NoZeroDivisors α] {k : α} (hk : k ≠ 0) :\n    IsRegular k :=\n  ⟨isLeftRegular_of_non_zero_divisor k fun _ h =>\n      (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_left hk,\n    isRightRegular_of_non_zero_divisor k fun _ h =>\n      (NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h).resolve_right hk⟩\n#align is_regular_of_ne_zero' isRegular_of_ne_zero'\n\ntheorem isRegular_iff_ne_zero' [Nontrivial α] [NonUnitalNonAssocRing α] [NoZeroDivisors α]\n    {k : α} : IsRegular k ↔ k ≠ 0 :=\n  ⟨fun h => by\n    rintro rfl\n    exact not_not.mpr h.left not_isLeftRegular_zero, isRegular_of_ne_zero'⟩\n#align is_regular_iff_ne_zero' isRegular_iff_ne_zero'\n\n/-- A ring with no zero divisors is a `CancelMonoidWithZero`.\n\nNote this is not an instance as it forms a typeclass loop. -/\n@[reducible]\ndef NoZeroDivisors.toCancelMonoidWithZero [Ring α] [NoZeroDivisors α] : CancelMonoidWithZero α :=\n  { (by infer_instance : MonoidWithZero α) with\n    mul_left_cancel_of_ne_zero := fun ha =>\n      @IsRegular.left _ _ _ (isRegular_of_ne_zero' ha) _ _,\n    mul_right_cancel_of_ne_zero := fun hb =>\n      @IsRegular.right _ _ _ (isRegular_of_ne_zero' hb) _ _ }\n#align no_zero_divisors.to_cancel_monoid_with_zero NoZeroDivisors.toCancelMonoidWithZero\n\n/-- A commutative ring with no zero divisors is a `CancelCommMonoidWithZero`.\n\nNote this is not an instance as it forms a typeclass loop. -/\n@[reducible]\ndef NoZeroDivisors.toCancelCommMonoidWithZero [CommRing α] [NoZeroDivisors α] :\n    CancelCommMonoidWithZero α :=\n  { NoZeroDivisors.toCancelMonoidWithZero, ‹CommRing α› with }\n#align no_zero_divisors.to_cancel_comm_monoid_with_zero NoZeroDivisors.toCancelCommMonoidWithZero\n\nsection IsDomain\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsDomain.toCancelMonoidWithZero [Semiring α] [IsDomain α] :\n    CancelMonoidWithZero α :=\n  { }\n#align is_domain.to_cancel_monoid_with_zero IsDomain.toCancelMonoidWithZero\n\nvariable [CommSemiring α] [IsDomain α]\n\n-- see Note [lower instance priority]\ninstance (priority := 100) IsDomain.toCancelCommMonoidWithZero : CancelCommMonoidWithZero α :=\n  { mul_left_cancel_of_ne_zero := IsLeftCancelMulZero.mul_left_cancel_of_ne_zero }\n#align is_domain.to_cancel_comm_monoid_with_zero IsDomain.toCancelCommMonoidWithZero\n\nend IsDomain\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/Regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.789263439391269}}
{"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 {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nsorry\n\n/-! 1.2. Prove its cousin. -/\n\nlemma monotone_restrict {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nsorry\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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing : regex\n| empty   : regex\n| atom    : α → regex\n| concat  : regex → regex → regex\n| alt     : regex → regex → regex\n| star    : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n-- enter the missing cases here\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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": "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_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.789263434161127}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  -- Arithmetic Mean is Never Less than Harmonic Mean\n  have h1 : ∀ a b : ℝ, (a + b) / 2 ≥ 2 / (1/a + 1/b), from by {apply arithmean_harmmean,},\n\n  -- $\\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 + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from by {\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 obviously\n    ... = ((a + b + c) / (b + c) + (a + b + c) / (a + c)) + ((a + b + c) / (a + b)) : by obviously\n    ... ≥ 2 * ((a + b + c) / (b + c) + (a + b + c) / (a + c)) : by {apply mul_le_mul_of_nonneg_right,\n                                                               apply le_add_right,\n                                                               apply nonneg_of_pos_div,\n                                                               apply add_pos hb hc,\n                                                               apply nonneg_of_pos_div,\n                                                               apply add_pos ha hc,} \n    ... = 2 * (a + b + c) / ((a + b + c) / 2) : by {rw [div_add_div_same,div_add_div_same,div_mul_eq_mul_div],\n                                                           rw mul_comm 2 (a + b + c),\n                                                           rw add_mul,reflexivity,\n                                                           apply div_pos,apply add_pos ha hb,\n                                                           apply div_pos,apply add_pos ha hb,} \n    ... ≥ 2 * 2 / (1/(a + b + c) + 1/(a + b + c)) : by {rw ← div_eq_mul_inv,\n                                                       apply h1,\n                                                       apply div_pos,apply add_pos ha hb,\n                                                       apply div_pos,apply add_pos ha hb,}\n    ... = 2 / (1/2 + 1/2) : by {rw [add_inv_self,mul_one],}\n    ... = 2 / 1 : by {rw [add_inv_self,div_one],}\n    ... = 2 : by {apply mul_one,}\n    ... ≥ 9 / 2 : by apply dec_trivial,\n  },\n  -- $\\dfrac {a + b + c} {b + c} + \\dfrac {a + b + c} {a + c} + \\dfrac {a + b + c} {a + b}\n  --     = \\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } + \\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } + \\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } \\ge \\dfrac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }$\n  have h3 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)\n           ≥ 3 / ((b + c) + (a + c) + (a + b)), from by {\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 obviously\n    ... = ((a + b + c) / (b + c) + (a + b + c) / (a + c)) + ((a + b + c) / (a + b)) : by obviously\n    ... = (a + b + c) / ((b + c) + (a + c)) + ((a + b + c) / (a + b)) : by {rw div_add_div_same,}\n    ... = (a + b + c) / ((b + c) + (a + c)) + (a + b + c) / ((a + b) + (b + c) + (a + c)) : by {rw add_assoc (a+b),\n                                                                                              rw add_assoc (a+c),\n                                                                                              rw add_comm (b+c) (a+c),\n                                                                                              rw add_assoc (b+c) (a+c),\n                                                                                              rw div_add_div_same,}\n    ... = (a + b + c) / ((b + c) + (a + c) + (b + c) + (a + c)) + (a + b + c) / ((a + b) + (b + c) + (a + c)) : by {rw add_assoc (a+b) (b+c),\n                                                                                                             rw add_assoc (a+c) (b+c),\n                                                                                                             rw add_comm (a+b) (a+c),\n                                                                                                             rw add_assoc (a+b) (a+c),\n                                                                                                             rw div_add_div_same,}\n    ... = (a + b + c) / ((b + c) + (a + c) + (b + c) + (a + c) + (a + b)) + (a + b + c) / ((a + b) + (b + c) + (a + c)) : by {rw add_assoc (b+c) (a+c),\n                                                                                                                             rw add_assoc (b+c) (a+c),\n                                                                                                                             rw add_assoc (a+b) (b+c),\n                                                                                                                             rw add_assoc (a+c) (b+c),\n                                                                                                                             rw add_comm (b+c) (a+c),\n                                                                                                                             rw add_assoc (b+c) (a+c),\n                                                                                                                             rw add_comm (a+b) (b+c),\n                                                                                                                             rw add_assoc (a+b) (b+c),\n                                                                                                                             rw add_comm (a+c) (b+c),\n                                                                                                                             rw add_assoc (a+c) (b+c),\n                                                                                                                             rw div_add_div_same,}\n    ... = (a + b + c) / ((b + c) + (a + c) + (b + c) + (a + c) + (a + b) + (a + b)) + (a + b + c) / ((a + b) + (b + c) + (a + c) + (a + b) + (a + b)) : by {rw add_assoc (a+b) (a+b),\n                                                                                                                                                             rw add_comm (a+b) (a+b),\n                                                                                                                                                             rw add_assoc (a+b) (a+b),\n                                                                                                                                                             rw add_assoc (\nend --Needs more than 2000 tokens!\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have habc : 0 < a + b + c, from add_pos (add_pos ha hb) hc,\n  let f : ℝ → ℝ → ℝ := (λ x y, x + y),\n  let g : ℝ → ℝ := (λ x, 1 / x),\n  let H : ℝ := (g ∘ f) (g b + c) (g a + c) (g a + b),\n  let A : ℝ := (g ∘ f) (a / (b + c)) (b / (a + c)) (c / (a + b)),\n  have h1 : A = H, from by {rw [div_eq_mul_inv_comm,div_eq_mul_inv_comm,div_eq_mul_inv_comm,div_eq_mul_inv_comm],\n  rw [mul_add, mul_add, mul_add,mul_add,add_mul,add_mul,add_mul,add_mul,add_mul,add_mul,mul_comm 3 H,mul_assoc,@mul_comm 3,@mul_comm 3,← mul_assoc],\n  rw [mul_left_comm (a + b + c) 3,div_eq_mul_inv_comm],\n  },\n  -- arithmetic mean and harmonic mean of $\\dfrac 1 {b + c}$, $\\dfrac 1 {a + c}$ and $\\dfrac 1 {a + b}$\n  have h2 : (3 / 2) * H = A * H, from by rw mul_comm,\n  have h3 : (3 / 2) * H ≥ H * H, from by apply arithmetic_mean_is_never_less_than_harmonic_mean,\n  have h4 : A * H ≥ H * H, from by rw h1 at h3,\n  have h5 : A ≥ H, from by {\n    rw mul_comm at h4,\n    rw mul_left_cancel H h2,\n    assumption\n  },\n  have h6 : (3 / 2) ≥ H, from by {rw h1 at h5},\n  have h7 : A ≥ (3 / 2), from by {rw h1 at h6},\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by assumption,\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : (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)), \n  {suffices : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from by linarith,\n  rw add_comm (a + b + c) (a + b + c),\n  repeat {rw add_assoc},\n  rw add_assoc,\n  rw add_comm (b + c) (a + c),\n  repeat {rw add_assoc},\n  rw add_comm (a + c) (a + b),\n  repeat {rw add_assoc},\n  have h2 : (a + b + c) / (b + c + a + c + a + b) ≥ 3 / 2, from by {apply arithmetic_mean_is_never_less_than_harmonic_mean},\n  rw ← div_eq_mul_inv,\n  rw ← div_eq_mul_inv,\n  exact h2,\n  },\n  have h2 : (b + c) + (a + c) + (a + b) > 0, from by {repeat {rw add_comm}, linarith},\n  have h3 : 3 * (a + b + c) > 0, from by {simp, linarith},\n  rw mul_comm at h1,\n  rw mul_comm at h3,\n  have h3 : (3/2) * (a + b + c) ≥ (9/2) * (a + b + c), from by {apply mul_le_mul h2 h1 h3},\n  rw ← div_eq_mul_inv at h3,\n  rw ← div_eq_mul_inv at h3,\n  rw div_eq_mul_inv at h3,\n  exact h3,\nend\n\n--OUTPUT 4\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  -- :$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) : by {\n    -- $\\leadstoandfrom$\n    simp only [],\n    -- :$\\dfrac {a + b + c} {b + c} + \\dfrac {a + b + c} {a + c} + \\dfrac {a + b + c} {a + b} \\ge \\dfrac 9 2$\n    have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from\n      by { rw add_assoc a (b + c) (a + c), rw add_assoc a (b + c) (a + b), apply add_lt_add ha hb hc, },\n    -- :$\\dfrac {a + b + c} {b + c} + \\dfrac {a + b + c} {a + c} + \\dfrac {a + b + c} {a + b} \\ge \\dfrac {9 \\paren {a + b + c} } {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }$\n    have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2 * ((a + b + c) / (b + c + a + c + a + b)), from\n      by {simp only [],ring,apply div_le_div_right,ring},\n    -- :$\\dfrac {\\frac 1 {b + c} + \\frac 1 {a + c} + \\frac 1 {a + b} } 3 \\ge \\dfrac 3 {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} }$\n    have h3 : (1 / (b + c) + 1 / (a + c) + 1 / (a + b)) / 3 ≥ 3 / ((b + c) + (a + c) + (a + b)), from\n      by {simp only [],ring,apply div_le_div_right,apply ha,apply hb,apply hc, 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    -- From Arithmetic Mean is Never Less than Harmonic Mean the last inequality is true.\n    apply arithmetic_mean_is_never_less_than_harmonic_mean h3, \n  },\nend\n\n--OUTPUT 5\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  -- :$\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b} \\ge \\dfrac 3 2$\n  suffices : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (9 / (2 * (b + c + a))) : 3 ≥ 2, from by linarith,\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 linarith\n    ... = (9 * (a + b + c)) / (2 * (b + c + a)) : by {rw [div_mul_eq_mul_div,div_mul_eq_mul_div],linarith}\n    ... ≥ (9 * (a + b + c)) / (2 * (b + c + a)) : by {linarith,linarith,linarith}\n    ... ≥ (9 / (2 * (b + c + a))) : by {rw [← @add_le_iff_nonneg_left _ _ _ b c,← @add_le_iff_nonneg_right _ _ _ a],linarith,linarith,linarith}\nend\n\n--OUTPUT 6\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  -- \n  have h1 : a + b + c ≥ 3, from by {simp, linarith},\n  have h2 : (a + b + c) / 3 ≥ 1, from h1,\n  have h3 : (a + b + c) / 3 = 3 / 3, from by {rw mul_inv_cancel, simp, exact h1},\n  have h4 : (a + b + c) / 3 = 1, from by {rw h3, simp},\n  have h5 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ 1, from by {rw ← h4, linarith},\n  have h6 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ 3 / 2, from by {rw ← h4, linarith},\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ 3 / 2, from h6,\nend\n\n--OUTPUT 7\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  -- $a + b + c$ is of course non-zero\n  have habc : 0 < a + b + c, from by {dsimp at *, linarith},\n\n  have h1 : (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 ring,\n  have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) =\n    9 * (a + b + c) /  ((b + c) + (a + c) + (a + b)), from by {rw add_div_cancel, ring,ring},\n  have h3 : 9 * (a + b + c) /  ((b + c) + (a + c) + (a + b)) ≥\n    3 / ((b + c) + (a + c) + (a + b)), from by {apply arithmetic_mean_never_less_than_harmonic_mean,ring},\n\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by {\n    rw ← h2, rw ← h1, apply h3,\n  },\nend\n\n--OUTPUT 8\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  -- ${\\frac a {b + c} + \\frac b {a + c} + \\frac c {a + b}}$\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 by\n    {ring},\n  -- ${\\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} {a + b}}$\n  have h2 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) ≥ (9/2), from by\n    {rw h1,norm_num,},\n  -- ${\\frac {a + b + c} {b + c} + \\frac {a + b + c} {a + c} + \\frac {a + b + c} / {a + b} }$\n  have h3 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) ≥ 9 / ((b + c) + (a + c) + (a + b)), from by\n    {rw ← one_div_mul_cancel (ne_of_gt (show (a + b + c) > 0, from 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 h4 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) ≥ 3 / ((a + b + c) * ((b + c) + (a + c) + (a + b))), from by\n    {rw ← one_div_mul_cancel (ne_of_gt (show (a + b + c) > 0, from by norm_num)),ring,},\n  -- ${\\frac {1/(b + c) + 1/(a + c) + 1/(a + b) } 3}$\n  have h5 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) ≥ 3 / (((b + c) + (a + c) + (a + b))), from by\n    {rw ← one_div_mul_cancel (ne_of_gt (show (a + b + c) > 0, from by norm_num)),ring,},\n\n  -- $\\dfrac a {b + c} + \\dfrac b {a + c} + \\dfrac c {a + b}$\n  show (a/(b + c)) + (b/(a + c)) + (c/(a + b)) ≥ (3 / 2), from by\n    {rw ← h5,apply arithmetic_mean_greater_than_harmonic_mean,},\nend\n\n--OUTPUT 9\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have hab : 0 < a + b, from add_pos ha hb,\n  have habc : 0 < a + b + c, from add_pos_pos hab hc,\n  have hbc : 0 < b + c, from add_pos hb hc,\n  have hac : 0 < a + c, from add_pos ha hc,\n  have habac : a + b + c ≠ 0, from ne_of_gt habc,\n  have hbcac : b + c ≠ 0, from ne_of_gt hbc,\n  have hacab : a + c ≠ 0, from ne_of_gt hac,\n\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b))\n      = (a + b + c)/(b + c) + (b + c)/(a + c) + (a + c)/(a + b) : \n        by rw [←add_div habc hbc,←add_div habc hac,←add_div habc hab,←mul_one a,←mul_one b,←mul_one c]\n      ... ≥ (9*(a + b + c))/((b + c) + (a + c) + (a + b)) :\n        by apply div_le_div_of_le_of_pos (by from add_le_add (add_le_add (le_div_of_mul_le_mul_left habc habc)\n        (le_div_of_mul_le_mul_left habc hac)) (le_div_of_mul_le_mul_left habc hab)) habc\n      ... = (9/((b + c) + (a + c) + (a + b)))*(a + b + c) :\n        by rw ←mul_div_assoc 9 habc habc\n      ... = (3/((b + c) + (a + c) + (a + b)))/2 :\n        by {rw ←one_mul (a + b + c), rw mul_div_assoc (3 : ℝ) habc (2:ℝ), rw div_self (2 : ℝ) (by norm_num),\n          rw div_self habc habc}\n      ... = (3 / 2) : by rw div_div_eq_div_mul (3: ℝ) habc (2: ℝ),\nend\n\n--OUTPUT 10\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) := \nbegin\n  -- \\leadstoandfrom\n  {\n    calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :\n    -- by adding $3$\n    ... = ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) : by {ring}\n    -- as $\\dfrac {a + b + c} {\\paren {b + c} + \\paren {a + c} + \\paren {a + b} } = \\dfrac 1 2$\n    ... = (9 * (a + b + c) / (2 * ((b + c) + (a + c) + (a + b)))) : by {simp [div_mul_cancel _ (ne_of_gt (add_pos hb hc)),mul_comm _ 2,mul_assoc,mul_comm 2 _]}\n    -- dividing by $3 \\paren {a + b + c}$\n    ... ≥ (3 / ((b + c) + (a + c) + (a + b))) : by {apply arithmetic_mean_greater_than_harmonic_mean}\n  },\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 {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=\nbegin\n  -- $A$ and $B$ are sets. $A$ and $B$ belong to power set of $S$\n  assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),\n  -- Then $A ⊆ S$ and $B ⊆ S$, by power set definition\n  have h1 : (A ⊆ S) ∧ (B ⊆ S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},\n  -- Then $(A ∩ B) ⊆ A$, by intersection of set is a subset\n  have h2 : (A ∩ B) ⊆ A, from by apply set.inter_subset_left,\n  -- Then $(A ∩ B) ⊆ S$, by subset relation is transitive \n  have h3 : (A ∩ B) ⊆ S, from by {apply set.subset.trans h2 h1.left},\n  -- Hence $(A ∩ B) ∈  𝒫 S$, by power set definition\n  show (A ∩ B) ∈  𝒫 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 : ℝ) : (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 ← 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] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=\nbegin\n  -- Group has Latin Square Property\n  have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by {\n    assume a b : G, use a⁻¹ * b, obviously, },\n  have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by {\n    assume a b : G, use b * a⁻¹, obviously, }, \n\n  -- Setting $b = a$, this becomes:\n  have h3 : ∀ a : G, ∃! x : G, a * x = a, from \n    assume a : G, h1 a a,\n  have h4 : ∀ a : G, ∃! 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 : ∀ 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 : ∀ 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 ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by {\n    use (1 : G),\n    have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by {\n      assume (e : G) (hident : ∀ a : G, e * a = a ∧ a * e = a),\n      have h8 : ∀ 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 : ∀ 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 ⟨by obviously, h7⟩,\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 : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (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.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.9572778036723354, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7892391020932262}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from by {\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) + 3 : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by ring\n    ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) + (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b\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 {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=\nbegin\n  assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),\n  have h1 : (A ⊆ S) ∧ (B ⊆ S), from by {split,apply set.subset_of_mem_powerset,exact hA,apply set.subset_of_mem_powerset,exact hB},\n  have h2 : (A ∩ B) ⊆ A, from by apply set.inter_subset_left,\n  have h3 : (A ∩ B) ⊆ S, from by {apply set.subset.trans h2 h1.left},\n  show (A ∩ B) ∈  𝒫 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 : ℝ) : (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 ← 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] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=\nbegin\n  have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by {\n    assume a b : G, use a⁻¹ * b, obviously, },\n  have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by {\n    assume a b : G, use b * a⁻¹, obviously, }, \n\n  have h3 : ∀ a : G, ∃! x : G, a * x = a, from \n    assume a : G, h1 a a,\n  have h4 : ∀ a : G, ∃! y : G, y * a = a, from\n    assume a : G, h2 a a,\n\n  have h5 : ∀ 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 : ∀ 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 ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a, from by {\n    use (1 : G),\n    have h7 : ∀ e : G, (∀ a : G, e * a = a ∧ a * e = a) → e = 1, from by {\n      assume (e : G) (hident : ∀ a : G, e * a = a ∧ a * e = a),\n      have h8 : ∀ 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 : ∀ 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 ⟨by obviously, h7⟩,\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 : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (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_max_tokens_2000_n_1/clean_files/Nesbitt inequality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474168650673, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7892182827772856}}
{"text": "import algebra.group.basic\nimport tactic\nimport group_theory.subgroup.basic\nimport data.set_like.basic\nimport chapter2.set_theory_cosets\nimport chapter2.set_theory_cosets_continued_w_semigroups\nimport chapter2.set_theory_cosets_continued_w_monoids\n\nvariables {A:Type} [group A]\n\nlemma inv_lcoset_lcoset (a:A) (S:set A) : lcoset (A) (a⁻¹) (lcoset (A) (a) (S)) = S :=\nbegin\next x, \nunfold lcoset,\nsplit, \n{intro hx,\n simp at hx, \n exact hx, },\n{intro hx, \n simp, \n exact hx,}\n-- because the a⁻¹*a = 1 proof is part of the simp tactic for a Type that is an instance of a group the simp tactic is really all you need here. It makes sense. \nend\n\nlemma lcoset_inv_lcoset (a:A) (S:set A) : lcoset (A) (a) (lcoset (A) (a⁻¹) (S)) = S :=\nbegin \next x, \nunfold lcoset, \nsplit, \n{intro hx, simp at hx, exact hx,},\n{intro hx, simp, exact hx,}\nend\n\nlemma inv_rcoset_rcoset (a:A) (S:set A) : rcoset (A) (rcoset (A) (S) (a)) (a⁻¹) = S := \nbegin\next x, \nunfold rcoset, \nsplit, \n{intro hx, simp at hx, exact hx,},\n{intro hx, simp, exact hx,}\nend\n\nlemma rcoset_inv_rcoset (a:A) (S:set A) : rcoset (A) (rcoset (A) (S) (a⁻¹)) (a) = S:=\nbegin \next x, \nunfold rcoset, \nsplit, \n{intro hx, simp at hx, exact hx,},\n{intro hx, simp, exact hx,} \nend \n\nlemma eq_of_lcoset_eq_lcoset (a:A) (S T : set A) (hST : lcoset (A) (a) (S) = (lcoset (A) (a) (T))) : S = T :=\nbegin\nhave hS : lcoset (A) (a⁻¹) (lcoset (A) (a) (S)) = S,\nexact inv_lcoset_lcoset a S,\nrw hST at hS,\nhave hT : lcoset (A) (a⁻¹) (lcoset (A) (a) (T)) = T, \nexact inv_lcoset_lcoset a T,\nrw ← hS,\nrw hT,\nend\n\nlemma eq_of_rcoset_eq_rcoset (a:A) (S T : set A) (hST : rcoset (A) (S) (a) = rcoset (A) (T) (a)) : S = T :=\nbegin\nhave hS : rcoset (A) (rcoset (A) (S) (a)) (a⁻¹) = S,\nexact inv_rcoset_rcoset a S,\nrw hST at hS, \nhave hT : rcoset (A) (rcoset (A) (T) (a)) (a⁻¹) = T, \nexact inv_rcoset_rcoset a T, \nrw hS at hT,\nexact hT, \nend\n\nlemma mem_of_mul_mem_lcoset (a b : A) (S : set A) (Hab : a*b ∈ (lcoset (A) (a) (S))) : b ∈ S :=\nbegin\nunfold lcoset at Hab,\n--the simp takes care of the fact that a*b = a*c → b = c if  a b c : G and G is an instance of a group. Try proving this for a monoid if there is skepticism.  \nsimp at Hab,\nexact Hab, \nend\n\nlemma mul_mem_lcoset_iff (a b : A) (S: set A) : (a*b ∈ (lcoset (A) (a) (S)) ↔ b ∈ S) := \nbegin\nunfold lcoset, \nsplit, \n{intro ha, exact mem_of_mul_mem_lcoset a b S ha,},\n{intro ha, simp, exact ha,} -- could use definition of appling a function over an input that is known to be in the set that is being mapped over. Instead the group instance is used to rewrite the goal.\nend\n\nlemma mem_of_mul_mem_rcoset (a b : A) (S : set A) (Hab : a * b ∈ rcoset (A) (S) (b)) : a ∈ S := \nbegin\nunfold rcoset at Hab, \nsimp at Hab, \nexact Hab,\nend\n\nlemma mul_mem_rcoset_iff (a b : A) (S : set A) : (a * b ∈ rcoset (A) (S) (b) ↔ a ∈ S) := \nbegin \nunfold rcoset, \nsplit,\n{intro ha, exact mem_of_mul_mem_rcoset a b S ha,},\n{intro ha, simp, exact ha,}\nend \n\nlemma mem_lcoset_of_inv_mul_mem {a b : A} {S : set A} (H: a⁻¹*b ∈ S) : b ∈ lcoset (A) (a) (S) :=\nbegin\nunfold lcoset,\nuse (a⁻¹ * b), split, exact H, dsimp, --notice how this applies the lambda expression\n--simp will essentially solve this entire proof for you. I'm just doing this somewhat explicitly to test my understanding.#check\nsimp,    \nend\n\nlemma mem_lcoset_iff {a b : A} {S : set A} : a⁻¹*b ∈ S ↔ b ∈ lcoset (A) (a) (S) :=\nbegin\nsplit, \n{intro h1, exact mem_lcoset_of_inv_mul_mem h1,}, \n{intro h1, unfold lcoset at h1, cases h1 with c hc, cases hc with hc1 hc2, dsimp at hc2,\nhave h2 : a*a⁻¹*b = b, simp, \nrw ← h2 at hc2, rw mul_assoc at hc2, \nhave h3: c = (a⁻¹*b) := mul_left_cancel hc2, rw h3 at hc1, exact hc1,} -- simp probably would have done a lot of the heavy lifting but I wanted to be explicit once. \nend\n\nlemma mem_rcoset_of_inv_mul_mem {a b : A} {S : set A} (H: b*a⁻¹ ∈ S) : b ∈ rcoset (A) (S) (a) := \nbegin\nunfold rcoset, simp, exact H, --here I did not do it explicitly. Damn lean is powerful...\nend\n\nlemma mem_rcoset_iff {a b : A} {S : set A} : b*a⁻¹ ∈ S ↔ b ∈ rcoset (A) (S) (a) :=\nbegin\nsplit, \n{intro h1, exact mem_rcoset_of_inv_mul_mem h1,},\n{intro h1, unfold rcoset at h1, simp at h1, exact h1,} --like I said, simp will do a lot of heavy lifting!\nend\n\nlemma lcoset_eq_iff_eq_inv_lcoset {a:A} {S T : set A} : lcoset A a S = T ↔ lcoset A a⁻¹ T = S :=\nbegin\nunfold lcoset, split, \n{intro h1, rw ← h1, ext x, simp,}, --if it is not clear do dsimp first. The group structure simplifies a⁻¹*a*x = x for x, thereofore any x is in S,\n{intro h1, rw ← h1, ext x, simp,}\nend\n\nlemma rcoset_eq_iff_eq_inv_rcoset {a:A} {S T : set A} : rcoset A S a = T ↔ rcoset A T a⁻¹ = S :=\nbegin\nunfold rcoset, split,\n{intro h1, rw ← h1, ext x, simp,},\n{intro h1, rw ← h1, ext x, simp,}\nend\n\nlemma lcoset_inter (a:A) (S T : subgroup A) : lcoset (A) (a) (S ∩ T) = lcoset (A) (a) (S) ∩ lcoset (A) (a) (T) :=\nbegin\nunfold lcoset, \next x, split, \n{intro hx, simp at hx, simp, exact hx,},\n{intro hx, simp at hx ⊢, exact hx,} -- the definition of intersection gets us pretty far here.  \nend\n\n--also convenient that lcoset can take subgroup as an input because it is ultimately a set with additionally properties\nlemma rcoset_inter (a:A) (S T : subgroup A) : rcoset (A) (S ∩ T) (a) = rcoset (A) (S) (a) ∩ rcoset (A) (T) (a) :=\nbegin\nunfold rcoset, ext x, split, \n{intro hx, simp at hx ⊢, exact hx,},\n{intro hx, simp at hx ⊢, exact hx,} \nend\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_cosets_continued_w_groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.7891670585207252}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport tactic \nimport data.real.basic\n\n/-\n# Límites de secuencias en Lean\nEscribimos la definicón `ε` - `N` del límite de una secuencia de\nnúmeros reales y demostramos resultados sobre límites.\n\nNOTA: adaptado de los cursos de formalización de Kevin Buzzard.\n-/\n\n/- ### Notación lambda (λ) para funciones\nRecordatorio: para representar una función `f` en Lean, utilizamos notación lambda:\n`λ x, f x` es la función que asigna a `x` el valor `f (x)`. -/\n\ndef f : ℕ → ℝ := λ n, n^2 + 3 -- `f(n) = n^2 + 3`\n\nexample : f 3 = 12 :=\nbegin\n  rw f,\n  dsimp only, -- Para simplificar la aplicación de funciones\n  norm_num, -- Normaliza expresiones numéricas\nend\n\n/-\n## Límite de una secuencia\n-/\n\n/-- Si `a(n)` es una secuencia de números reales y `L` es un real,\n `tends_to a L` dice que el límite de `a(n)` cuando `n → ∞` es `L`. -/\ndef tends_to (a : ℕ → ℝ) (L : ℝ) : Prop :=\n∀ ε > 0, ∃ N : ℕ, ∀ n, N ≤ n → |a n - L| < ε\n\n/-- Este lema nos permite reescribir la definición de `tends_to` en nuestras pruebas. -/\ntheorem tends_to_def {a : ℕ → ℝ} {t : ℝ} :\n  tends_to a t ↔ ∀ ε, 0 < ε → ∃ B : ℕ, ∀ n, B ≤ n → |a n - t| < ε :=\nbegin\n  refl\nend\n\n/-\n## Ejercicios\n-/\n\n/-- El límite de la secuencia constante con valor `c` es `c`. -/\ntheorem tends_to_const (c : ℝ) : tends_to (λ n, c) c :=\nbegin\n  rw tends_to_def,\n  intros ε hε,\n  use 0,\n  intros n hn,\n  simp only [sub_self, abs_zero],\n  exact hε,\nend\n\n/-- Si `a(n)` tiende a `L` entonces `a(n) + c` tiende a `t + c` -/\ntheorem tends_to_add_const {a : ℕ → ℝ} {L : ℝ} (c : ℝ)\n  (h : tends_to a L) :\n  tends_to (λ n, a n + c) (L + c) :=\nbegin\n  intros ε hε,\n  specialize h ε hε,\n  cases h with N hN,\n  use N,\n  intros n hn,\n  dsimp only,\n  convert hN n hn using 1,\n  simp only [add_sub_add_right_eq_sub],\nend\n\n/-- Si `a(n)` tiende a `L`, entonces `-a(n)` tiende a `-L`.\nSi simplificar la expresión dentro del valor absoluto te está\ndando problemas, ve a la hoja `reales.lean`.\n-/\ntheorem tends_to_neg {a : ℕ → ℝ} {L : ℝ} (ha : tends_to a L) :\n  tends_to (λ n, - a n) (-L) :=\nbegin\n  intros ε hε,\n  obtain ⟨N, hN⟩ := ha ε hε,\n  use N,\n  intros n hn,\n  dsimp only,\n  rw [neg_sub_neg, abs_sub_comm],\n  exact hN n hn,\nend\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) + b(n)`\ntiende a `La + Lb`.\nEsta demostración es más complicada que las anteriores.\n-/\ntheorem tends_to_add {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n + b n) (La + Lb) :=\nbegin\n  intros ε hε,\n  obtain ⟨Na, hNa⟩ := ha (ε/2) (by linarith),\n  obtain ⟨Nb, hNb⟩ := hb (ε/2) (by linarith),\n  use max Na Nb,\n  intros n hn,\n  dsimp only,\n  rw max_le_iff at hn,\n  specialize hNa n hn.1,\n  specialize hNb n hn.2,\n  rw abs_lt at hNa hNb ⊢,\n  split; -- El `;` en lugar de `,` hace que la siguiente instrucción se aplique a todas las metas.\n  linarith,\nend\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) - b(n)`\ntiende a `La - Lb`. -/\ntheorem tends_to_sub {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n - b n) (La - Lb) :=\nbegin\n  exact tends_to_add ha (tends_to_neg hb),\nend\n\n/-- Si `a(n)` tiende a `L`, entonces `c*a(n)` tiende a `c*L`.\nPista: tratad el caso `c = 0` por separado, utilizando `by_cases hc : c = 0`.\n-/\nlemma tends_to_mul_const_left {a : ℕ → ℝ} {L c : ℝ} (h : tends_to a L) :\n  tends_to (λ n, c * (a n)) (c * L) := \nbegin\n  intros ε hε,\n  by_cases hc : c = 0,\n  { use 0,\n    intros n hn,\n    simp only [hc, zero_mul, tsub_zero, abs_zero],\n    exact hε },\n  { have hε' : 0 < ε/|c|,\n    { apply div_pos hε (abs_pos.mpr hc) },  \n    obtain ⟨N, hN⟩ := h (ε/|c|) hε',\n    use N,\n    intros n hn,\n    dsimp only,\n    rw [← mul_sub, abs_mul, ← lt_div_iff' (abs_pos.mpr hc)],\n    exact hN n hn,\n  }\nend\n\n/- Lema del sandwich. -/\ntheorem sandwich (a b c : ℕ → ℝ) (L : ℝ) (ha : tends_to a L) (hc : tends_to c L) \n  (hab : ∀ n, a n ≤ b n) (hbc : ∀ n, b n ≤ c n) : \n  tends_to b L :=\nbegin\n  intros ε hε,\n  obtain ⟨Na, hNa⟩ := ha ε hε,  \n  obtain ⟨Nc, hNc⟩ := hc ε hε, \n  use max Na Nc,\n  intros n hn,\n  rw max_le_iff at hn,\n  specialize hNa n hn.1,\n  specialize hNc n hn.2,\n  rw abs_lt at hNa hNc ⊢,\n  specialize hab n,\n  specialize hbc n,\n  split;\n  linarith,\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_4/soluciones/limites.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7891364943374803}}
{"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 order.filter.basic\n\n/-!\n\n# The order (≤) on filters\n\nWe think of filters as generalised subsets, and just as subsets are partially ordered\nby `⊆`, filters are partially ordered too, by `≤`. Recall that a subset `X : set α`\nof `α` gives rise to a principal filter `𝓟 X : filter α`, and we definitely\nwant `X ⊆ Y ↔ 𝓟 X ≤ 𝓟 Y` so let's think about how this should work. If `F` and `G`\nare filters, then `F ≤ G` should mean \"the generalised subset `F` is contained\nin the generalised subset `G`\", so it should mean \"if a normal subset of α contains\n`G` then it contains `F`\", so it should mean `G.sets ⊆ F.sets`, which is in fact\nthe definition. Note that the smaller the filter `F`, the bigger the collection\n`F.sets`, because `F` is contained in more sets!\n\nIn the `filter` namespace there's a lemma\n\n\nLet's formalise this. Show that 𝓟 S ≤ 𝓟 T ↔ S ⊆ T.\nNote that this is called `principal_mono` in mathlib but \nthere's no harm in proving it yourself.\n\nSome helpful lemmas (all in the `filter` namespace):\n\n`mem_principal : T ∈ 𝓟 S ↔ S ⊆ T`\n`mem_principal_self S : S ∈ 𝓟 S`\n`le_def : F ≤ G ↔ ∀ (S : set α), S ∈ G → S ∈ F`\n\n-/\n\nvariable {α : Type}\n\nopen filter set -- so we don't keep having to type `filter.le_def` and `set.subset.trans` etc\n\nopen_locale filter -- for 𝓟 notation\n\nexample (S T : set α) : 𝓟 S ≤ 𝓟 T ↔ S ⊆ T :=\nbegin\n  split,\n  { intro h,\n    rw le_def at h,\n    have hT : T ∈ 𝓟 T := mem_principal_self T,\n    specialize h T hT,\n    rwa mem_principal at h },\n  { intro hST,\n    rw le_def,\n    intros X hX,\n    rw mem_principal at hX ⊢,\n    exact subset.trans hST hX }\nend\n\n-- Here's another useful lemma about principal filters.\n-- It's called `le_principal_iff` in mathlib but why\n-- not try proving it yourself?\n\nexample (F : filter α) (S : set α) : F ≤ 𝓟 S ↔ S ∈ F :=\nbegin\n  rw le_def,\n  split,\n  { intro h,\n    apply h,\n    exact mem_principal_self S },\n  { intros hSF X hX,\n    rw mem_principal at hX,\n    exact mem_of_superset hSF hX },\nend\n\n\n\n/-\n\n## Filters are a complete lattice\n\nFirst I claim that if Fᵢ are a bunch of filters, indexed by `i : I`, then\nthe intersection of `Fᵢ.sets` is also a filter. Let's check this.\n\n-/\n\ndef LUB {I : Type} (F : I → filter α) : filter α :=\n{ sets := {X | ∀ i, X ∈ F i},\n  univ_sets := begin\n    intro i,\n    apply univ_mem,\n  end,\n  sets_of_superset := begin\n    intros S T hS hST i,\n    apply mem_of_superset _ hST,\n    apply hS,\n  end,\n  inter_sets := begin\n    intros S T hS hT i,\n    exact inter_mem (hS i) (hT i),\n  end }\n\n/-\n\nNow let's check that this is a least upper bound for the Fᵢ! We check the\ntwo axioms.\n\n-/\n\n-- it's an upper bound\nexample (I : Type) (F : I → filter α) (i : I) : F i ≤ LUB F :=\nbegin\n  intros S hS,\n  apply hS,\nend\n\n-- it's ≤ all other upper bounds\nexample (I : Type) (F : I → filter α) (G : filter α) (hG : ∀ i, F i ≤ G) : LUB F ≤ G :=\nbegin\n  intros S hS i,\n  apply hG,\n  exact hS,\nend\n\n\n/-\n\nJust like it's possible to talk about the topological space generated\nby a collection of subsets of `α` -- this is the smallest topology\nfor which the given subsets are all open -- it's also possible to talk\nabout the filter generated by a collection of subsets of `α`. One\ncan define it as the intersection of all the filters that contain your\ngiven collection of subsets (we just proved above that this is a filter).\nThis gives us a definition of greatest lower bound for filters too.\n\n-/\n\n-- greatest lower bound of filters Fᵢ is the least upper bound of the filters G whose `sets`\n-- contain all of the `Fᵢ.sets`\ndef GLB {I : Type} (F : I → filter α) : filter α := LUB (λ (G : {G : filter α | ∀ i, (F i).sets ⊆ G.sets}), G.1)\n\n-- it's a lower bound\nexample (I : Type) (F : I → filter α) (i : I) : GLB F ≤ F i :=\nbegin\n  rintros S hS ⟨G, hG⟩,\n  dsimp,\n  apply hG _ hS,\nend\n\n-- it's ≥ all other lower bounds\nexample (I : Type) (F : I → filter α) (G : filter α) (hG : ∀ i, G ≤ F i) : G ≤ GLB F :=\nbegin\n  intros S hS,\n  unfold GLB at hS,\n  dsimp at hS,\n  unfold LUB at hS,\n  dsimp at hS,\n  specialize hS ⟨G, _⟩,\n  { exact hG },\n  { exact hS },\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/section11_and_a_half_filters/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7891364924872472}}
{"text": "import kb_real_defs\n\n/-\n# Chapter 1 : Sets\n\n## Level 9\n-/\n\n/- \nThis is a little more complicated example asking you to work with intervals of reals.\nThe result will be of help in the sup-inf world.\n-/\n\nnotation `[` a `,` b `]`  := set.Icc a b\n\ndef mem_prod_sets (A : set ℝ) (B : set ℝ) := { x : ℝ | ∃ y ∈ A, ∃ z ∈ B, x = y * z}\n\n\n/- Lemma\nIf $x = 0$, then `x ∈ mem_prod_sets [(-2:ℝ),-1] [(0:ℝ), 3]`\n-/\nlemma zero_in_prod : (0:ℝ) ∈ mem_prod_sets [(-2:ℝ), -1] [(0:ℝ), 3] :=\nbegin\n  rw mem_prod_sets,\n  dsimp,\n  use -2,\n  split,\n  norm_num,\n  use 0,\n  split,\n  norm_num,\n  norm_num,\nend\n\n\n\n\n/-\nrw mem_prod_sets,\n  dsimp,\n  use -2,\n  split, \n  { rw mem_Icc_iff,\n    split; linarith\n  },\n  use 0,\n  split,\n  { rw mem_Icc_iff,\n    split; linarith\n  },\n  norm_num\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_level09.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7891364873998985}}
{"text": "-- We import all of Lean's standard tactics\nimport tactic\n\n/-\n Since it's the easiest thing to start with, we first develop basic logic.\n \n # The logical symbols that Lean understands :\n\n * `→` (\"implies\" -- type with `\\l`)\n * `¬` (\"not\" -- type with `\\not` or `\\n`)\n * `∧` (\"and\" -- type with `\\and` or `\\an`)\n * `↔` (\"iff\" -- type with `\\iff` or `\\lr`)\n * `∨` (\"or\" -- type with `\\or` or `\\v`)\n\n # Useful tactics : \n\n * `intro`\n * `exact`\n * `apply`\n * `rw`\n * `cases`\n * `split`\n * `left`\n * `right`\n\n\n-/\n\nnamespace mbl\n\n\nvariables (P Q R : Prop)\n--We define three variables, each is a ' term of type `Prop` '\n\n-- ### Introductory examples with implies (→)\n\ntheorem id : P → 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\n--This one is immediate from definition.\n-- in Lean, `P → Q → R` is _defined_ to mean `P → (Q → R)`\nexample : (P → Q → R) ↔ (P → (Q → R)) :=\nbegin\n  -- look at the goal!\n  refl -- true because ↔ is reflexive\nend\n\ntheorem imp_intro : P → Q → P :=\nbegin\n  -- remember that by definition the goal is P → (Q → 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\nlemma modus_ponens : P → (P → Q) → 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 → 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-- ### First independent steps\n\nlemma imp_trans : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  -- The tactics you know should be enough\n  sorry,\nend\n\nlemma forall_imp : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  -- `intros hPQR hPQ hP,` would be a fast way to start.\n  sorry,\nend\n\n/-\n### not\n\n`not P`, with notation `¬ P`, is *defined* to mean `P → false` in Lean,\ni.e., the proposition that P implies false. You can easily check with\na truth table that P → false and ¬ P are equivalent.\n\n\n-/\n\ntheorem not_iff_imp_false : ¬ P ↔ (P → false) :=\nbegin\n  -- true by definition\n  refl\nend\n\ntheorem not_not_intro : P → ¬ (¬ P) :=\nbegin\n  --You can do it in a few ways. One of them is particularly short and slick\n  sorry,\nend\n\n-- This is \"modus tollens\". Some mathematicians think of it as\n-- \"proof by contradiction\".\ntheorem modus_tollens : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  sorry,\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 : ¬ (¬ P) → P :=\nbegin\n  sorry,\nend\n\n/-\n\n### and\n\nThe hypothesis `hPaQ : P ∧ 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 `⊢ P ∧ Q` as a goal, and want to turn the goal\ninto two goals `⊢ P` and `⊢ 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 ∧ Q :=\nbegin\n  split,\n  { exact hP },\n  { exact hQ }\nend\n\n-/\n\ntheorem and.elim_left : P ∧ Q → P :=\nbegin\n  -- if `h : P ∧ Q` then `h.1 : P` and `h.2 : Q`\n  sorry,\nend\n\ntheorem and.elim_right : P ∧ Q → Q :=\nbegin\n  sorry,\nend\n\ntheorem and.intro : P → Q → P ∧ Q :=\nbegin\n  -- remember the `split` tactic.\n  sorry,\nend\n\n/-- the eliminator for `∧` -/ \ntheorem and.elim : P ∧ Q → (P → Q → R) → R :=\nbegin\n  sorry,\nend\n\n/-- The recursor for `∧` -/\ntheorem and.rec : (P → Q → R) → P ∧ Q → R :=\nbegin\n  sorry,\nend\n\n/-- `∧` is symmetric -/\ntheorem and.symm : P ∧ Q → Q ∧ P :=\nbegin\n  --Useful fact:\n  -- `intro hPQ`\n  -- `cases hPQ with hP hQ`\n  --can be replaced with\n  -- `rintro ⟨hP, hQ⟩`\n  sorry,\nend\n\n\n/-- `∧` is transitive -/\ntheorem and.trans : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  -- The `rintro` tactic will do `intro` and `cases` all in one go.\n  -- If you like, try starting this proof with `rintro ⟨hP, hQ⟩` if you want\n  -- to experiment with it. Get the pointy brackets with `\\<` and `\\>`,\n  -- or both at once with `\\<>`.\n\n  sorry,\n\nend\n\n/-\nRecall that the convention for the implies sign →\nis that it is _right associative_, by which\nI mean that `P → Q → R` means `P → (Q → R)` by definition.\nNow note that if `P` implies `Q → R`\nthen this means that `P` and `Q` together, imply `R`,\nso `P → Q → R` is logically equivalent to `(P ∧ Q) → R`.\n\nWe proved that `P → Q → R` implied `(P ∧ Q) → R`; this was `and.rec`.\nLet's go the other way.\n-/\n\nlemma imp_imp_of_and_imp : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  sorry,\nend\n\n\n/-!\n\n### iff\n\nThe basic theory of `iff`.\n\nIn Lean, to prove `P ∧ Q` you have to prove `P` and `Q`.\nSimilarly, to prove `P ↔ Q` in Lean, you have to prove `P → Q`\nand `Q → P`. Just like `∧`, you can uses `cases h` if you have\na hypothesis `h : P ↔ Q`, and `split` if you have a goal `⊢ P ↔ Q`.\n-/\n\n/-- `P ↔ P` is true for all propositions `P`, i.e. `↔` is reflexive. -/\ntheorem iff.refl : P ↔ P :=\nbegin\n  split,\n  apply id,\n  apply id,\n  /- or tauto, tauto-/\nend\n\n-- If you get stuck, there is always the \"truth table\" tactic `tauto!`\n-- This literally solves everything above. It's a cool thing\n-- but overrelying on it today would be pointless\nexample : P ↔ P :=\nbegin\n  tauto!, -- the \"truth table\" tactic.\nend\n\n-- refl tactic also works\nexample : P ↔ P :=\nbegin\n  refl -- `refl` knows that `=` and `↔` are reflexive.\nend\n\n/-- `↔` is symmetric -/\ntheorem iff.symm : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  sorry,\nend\n\n/-- `↔` is commutative -/\ntheorem iff.comm : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  sorry,\n\nend\n\n-- without rw or cc this is painful!\n/-- `↔` is transitive -/\ntheorem iff.trans :  (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  sorry,\n\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 : ¬ (P ↔ ¬ P) :=\nbegin\n  sorry,\nend\n\n-- Now we have iff we can go back to and.\n\n/-!\n### ↔ and ∧\n-/\n\n/-- `∧` is commutative -/\ntheorem and.comm : P ∧ Q ↔ Q ∧ P :=\nbegin\n  sorry,\nend\n\n\n-- Note that ∧ is \"right associative\" in Lean, which means\n-- that `P ∧ Q ∧ R` is _defined to mean_ `P ∧ (Q ∧ R)`.\n-- Associativity can hence be written like this:\n/-- `∧` is associative -/\ntheorem and_assoc : ((P ∧ Q) ∧ R) ↔ (P ∧ Q ∧ R) :=\nbegin\n  sorry,\nend\n\n\n\n/-!\n\n## Or\n\n`P ∨ Q` is true when at least one of `P` and `Q` are true.\nHere is how to work with `∨` in Lean.\n\nIf you have a hypothesis `hPoQ : P ∨ 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 `⊢ P ∨ 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 → P ∨ Q :=\nbegin\n  intro hP,\n  left,\n  exact hP,\nend\n\ntheorem or.intro_right : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\n/-- the eliminator for `∨`. -/\ntheorem or.elim : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  sorry,\nend\n\n/-- `∨` is symmetric -/\ntheorem or.symm : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n/-- `∨` is commutative -/\ntheorem or.comm : P ∨ Q ↔ Q ∨ P :=\nbegin\n  sorry,\nend\n\n/-- `∨` is associative -/\ntheorem or.assoc : (P ∨ Q) ∨ R ↔ P ∨ Q ∨ R :=\nbegin\n  sorry,\nend\n\n/-!\n### More about → and ∨\n-/\n\ntheorem or.imp : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\ntheorem or.imp_left : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\ntheorem or.imp_right : (P → Q) → R ∨ P → R ∨ Q :=\nbegin\n  sorry,\nend\n\ntheorem or.left_comm : P ∨ Q ∨ R ↔ Q ∨ P ∨ R :=\nbegin\n  -- Try rewriting `or.comm` and `or.assoc` to do this one quickly.\n  sorry,\nend\n\n/-- the recursor for `∨` -/\ntheorem or.rec : (P → R) → (Q → R) → P ∨ Q → R :=\nbegin\n  sorry,\nend\n\ntheorem or_congr : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\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 ∧ 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 → P :=\nbegin\n  intro h,\n  cases h,\n\n\nend\n\ntheorem and_true_iff : P ∧ true ↔ P :=\nbegin\n  sorry,\n\n\nend\n\ntheorem or_false_iff : P ∨ false ↔ P :=\nbegin\n  sorry,\nend\n\n-- false.elim is handy for this one\ntheorem or.resolve_left : P ∨ Q → ¬P → Q :=\nbegin\n  sorry,\nend\n\n-- this one you can't do constructively\ntheorem or_iff_not_imp_left : P ∨ Q ↔ ¬P → Q :=\nbegin\n    \n    sorry,\n  \nend\n\nend mbl\n", "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_1/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7891207196989527}}
{"text": "/-\nIf you understand the introduction and elimination\nrules for ∀, then you understand these rules for\nproving, and using proofs of implications. Consider\nan implication, P → Q. To construct a proof, pq, of \nP → Q, you simply *assume* you're given an arbitrary\nbut specific value/proof of P and in this context you\nmust show that you can construct and return a proof of\nQ. What this shows is that *if* P is true (because\nthere is a proof of it) then so is Q. \n\nIn other words, prove P → Q by showing that you can \ndefine a total function of type P → Q!\n\nFor an example, see the second step (after the ∀\nintroduction) in our proof of the commutativity of\n∨. What's left to prove there is an implication,\nP ∨ Q → Q ∨ P. The way it is proved is just the\nway that the overall ∀ proposition is proved: by\nassuming that we're given a proof/value, but now\nof type P ∨ Q, and showing that in this context \nwe can construct and return a value of Q ∨ P.\n\nIn fact, P ∨ Q is really just a shorthand in Lean\nfor ∀ (p : P), Q! You can see it clearly in the \nfollowing code, where we first assume that P and \nQ are arbitrary propositions, and then check the\ntype of ∀ (p : P), Q. It's Prop, of course, as\n∀ (p : P), Q is a proposition; but what is key\nhere is that Lean uses → notation to print out\nthis proposition! We can even prove that they're\nexactly the same proposition.\n-/\n\naxioms P Q : Prop\n#check ∀ (p : P), Q\nexample : (P → Q) = ∀ (p : P), Q := rfl \n\n/-\nOf course it's now obvious that the elimination\nrule for → is the same as it is for ∀: *apply* a \nproof of P → Q to a proof of P to obtain a proof\nof Q.\n-/\n\ntheorem modus_ponens: \n    (P → Q) →  \n    P →                  \n    Q :=\nλ (pq : P → Q), -- suppose you have a proof of P → Q\nλ (p : P),      -- and that you have a proof of P \npq p            -- *apply* former to latter; QED.", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/predicate_logic/intro_and_elim_rules/implies.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7891207182568144}}
{"text": "-- Suma_de_potencias_de_dos.lean\n-- Suma de potencias de dos\n-- José A. Alonso Jiménez\n-- Sevilla, 25 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    1 + 2 + 2² + 2³ + ... + 2⁽ⁿ⁻¹⁾ = 2ⁿ - 1\n-- ---------------------------------------------------------------------\n\nimport algebra.big_operators\nimport tactic\nopen finset nat\n\nopen_locale big_operators\nset_option pp.structure_projections false\n\nvariable (n : ℕ)\n\nexample :\n  ∑ k in range n, 2^k = 2^n - 1 :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { calc ∑ k in range (succ n), 2^k\n         = ∑ k in range n, 2^k + 2^n\n             : sum_range_succ (λ x, 2 ^ x) n\n     ... = (2^n - 1) + 2^n\n             : congr_arg2 (+) HI rfl\n     ... = (2^n + 2^n) - 1\n             : by omega\n     ... = 2^n * 2 - 1\n             : by {congr; simp}\n     ... = 2^(succ n) - 1\n             : by {congr' 1; ring_nf}, },\nend\n\n-- Referencia: \"El método de la inducción matemática\" de I.S. Sominski\n-- p. 20.\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_potencias_de_dos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799586, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7890363760426388}}
{"text": "theorem demorgans_law (p q : Prop) : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\nbegin\n  split,\n  { intro hnpq,\n    -- superficial\n    change (p ∨ q) → false at hnpq,\n    split,\n    { intro hp,\n      apply hnpq,\n      left,\n      assumption\n    },\n    { intro hq,\n      apply hnpq,\n      right,\n      assumption\n    }\n  },\n  intro hnpnq,\n  intro hpq,\n  cases hnpnq with hnp hnq,\n  cases hpq,\n    contradiction,\n  contradiction\nend\n\ntheorem demorgans_law' (p q : Prop): ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  iff.intro\n    (assume h, \n      and.intro (assume hp, h (or.inl hp)) (assume hq, h (or.inr hq)))\n    (assume h : ¬p ∧ ¬q,\n      not_or h.left h.right)\n\ntheorem demorgans_law'' (p q : Prop) : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n⟨λ h, ⟨λ hp, h $ or.inl hp, λ hq, h $ or.inr hq⟩,\n  λ ⟨hnp, hnq⟩ hn, or.elim hn hnp hnq⟩\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/Examples/demorgan_teaching.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359676, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7890278603395618}}
{"text": "import data.real.basic\nvariables (x y : ℝ)\n\ntheorem add_law (a b x y : ℝ) (h₁: x<y) (h₂:a<b): x+a < y + b :=\nbegin\nhave h₃: x + a < y + a,\nexact add_lt_add_right h₁ a,\nhave h₄: y + a < y + b,\nexact add_lt_add_left h₂ y,\nexact lt_trans h₃ h₄,\nend\n\nlemma real_le_mul (a b c d :ℝ) (h₁:0<a) (h₂:0<b) (h₃:0<c) (h₄:0<d)\n(h₅: a<b) (h₆:c<d): a * c < b * d:=\nbegin\nhave h₇: a * c < b * c, --We prove an auxiliary statement\nexact (mul_lt_mul_right h₃).mpr h₅, --We use monotonicity of multiplication\nhave h₈: b*c < b*d, --We prove another auxiliary statement\nrw mul_comm b c, --We use commutativity of multiplication so our goal is in the required form to use monotonicity \nrw mul_comm b d, --We use commutativity again\nexact (mul_lt_mul_right h₂).mpr h₆, --Monotonicity shows our auxiliary statement\napply lt_trans h₇ h₈, --We use transitivity to close the goal \nend\n\nexample (n: nat)  (h:x>0) : (1+x)^n ≥ 1 + x*n :=\nbegin\n  induction n with d hd,\n  norm_num,\n  have h₁:d.succ = ↑d+1,\n  norm_num,\n  rw h₁,\n  norm_num,\n  rw mul_add,\n  rw pow_succ,\n  rw add_mul,\n  rw ← add_assoc,\n  rw one_mul,\n  rw mul_one,\n  norm_num at hd,\n  apply add_le_add hd,\n  nth_rewrite 0 ← mul_one x,\n  apply mul_le_mul,\n  refl,\n  clear hd,\n  induction d with d hd,\n  rw pow_zero,\n  nth_rewrite 0 ← mul_one (1:ℝ),\n  apply mul_le_mul,\n  linarith,\n  finish,\n  repeat{linarith},\nend\n\nexample {x : ℝ} {n : ℕ} (h : 0 < x) : 1 + x * n ≤ (1 + x) ^ n :=\nbegin\n  induction n with n hn,\n  { norm_num },\n  { change n.succ with n + 1, norm_num,\n    simp [pow_succ, mul_add, ←add_assoc, add_mul],\n    apply add_le_add hn, clear hn, nth_rewrite 0 ←mul_one x,\n    apply mul_le_mul; try {linarith},\n    induction n with n hn; simp [pow_zero, pow_succ],\n    nth_rewrite 0 ←mul_one (1 : ℝ), apply mul_le_mul; linarith },\nend\n\n", "meta": {"author": "HarryPacitti", "repo": "LeanAnalysisTutorial1", "sha": "a1d39999c13f33aecd808d72961c94edc10c54a8", "save_path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1", "path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1/LeanAnalysisTutorial1-a1d39999c13f33aecd808d72961c94edc10c54a8/Examples/Numbers and Inequalities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.788998609503793}}
{"text": "/-*** def ***-/\n\n/-\nThe def keyword in Lean establishes a new definition: a binding\nof a variable to a value of a specified type. First, let's look\nat binding names to values of a few data types.\n-/\n\ndef five : ℕ := 5\n\n/-\nThis definition declares five to be a variable name, to be bound\nto a value of type ℕ, and in particular now bound to the value, 5.\nWe can now use #check to see that we've got what we expect here.\n-/\n\n#check five\n\n/-\n#check tells us that five is a correct expression and that it is\nan expression of type ℕ.\n-/\n\n/-\nNote that when Lean can infer the type of a variable from the \nvalue bound to it, you can elide the explicit \"type judgment\"\n-/\n\ndef six := 6      -- type inference\n#check 6\n#check six\n\n\n\n/-\nOk, now let's look at the case where we're working now with \ndata values but with proofs of propositions. We'll start with\nthe proposition, true.\n-/\n\ndef proof_of_true : true := true.intro\n\n/-\nHere we define proof_of_true to be a variable, meant to be \nbound to a \"proof\" (or proof value, or proof object) because \n\"true\" is a proposition not a data type. We then bind it to \nthe proof value, true.intro, which, as you will recall, is the \none and only proof of true in our logic. Proofs are mathematical\nobjects/values, just like data values.\n-/\n\n/-\nIt's worthwhile at this point to think hard again about types.\nThe type of proof_of_true in our logic is *true*. That's what\nthe \"type judgement\", (proof_of_true : true), expresses. And\nof course the type of true is Prop.\n-/\n\n/-\nWhen assigning proof values to variables, it's often beneficial\nto work out the proof value a bit at a time. That's what proof\n\"scripts\" are for. We could have written the previous example \nusing a proof script just as well. \n-/\n\ndef proof_of_true2        : true := true.intro\ndef another_proof_of_true : true := begin exact true.intro end\n\n/-\nThe script, :begin exact true.intro end\", results in exactly the\nproof value, true.intro, which is then bound to the variable, \nanother_proof_of_true.\n-/\n\n#check proof_of_true\n#check another_proof_of_true\n#check true\n\n\n/-\nThere's a deep parallel in our higher-order logic between data \nvalues and proof values, and between data types and propositions. \nLet's make this clear by examples.\n\n- The type of \"five\" is ℕ, and the type of ℕ is Type\n- The type of \"Hi\" is string, and the type of string is Type\n- The type of tt is bool (in Lean), and the type of bool is Type.\n\n- The type of true.intro is true, and the type of true is Prop \n- The type of proof_of_true is true, and the type of true is Prop\n- The type of another_proof_of_true is true, and its type is Prop\n-/\n\n/-\nHere's another example\n-/\n\ndef a_fact : ∀ (P Q : Prop), P ∧ Q → P :=\nbegin\n  assume P Q h,\n  exact (and.elim_left h),\nend \n\ndef a_fact' : ∀ (P Q : Prop), P ∧ Q → P :=\n  λ P Q h, and.elim_left h\n\n\n/-\nHere we declare a_fact to be a variable that is meant to be bound\n(to have as its value) of proof of ∀ (P Q : Prop), P ∧ Q → P. The\nproof script produces such a \"proof\" value, which is then bound to\nthe variable a_fact. The #check command reports that the \"type\" of\na_fact is ∀ (P Q : Prop), P ∧ Q → P. Propositions are types in our\nhigher-order logic, and just as Lean type checks the values you try\nto bind to variables, giving errors if the types don't match, so in\nthe same way Lean checks the types of proof values to be sure they\nmatch the propositions they're intended to be proofs of!\n-/\n\ndef oops : ℕ := \"Hi\"       -- type error (read the error message)\ndef argh : ∀ (P Q : Prop), P ∧ Q → P := true.intro -- type error!\n\n/-\nPlease read the error messages: in both cases we have a type error.\nIn the first example, we try to bind a string value, \"Hi,\"  to a \nvariable declared to be of type ℕ, and that produces a type error. \nSimilarly, when we try to bind a proof value, true.intro (a proof \nof true) to the variable, argh, we get a type error, because argh\nis meant to be bound to a proof of ∀ (P Q : Prop), P ∧ Q → P.\n-/\n\n/-\nWe can clearly distinguish the use of the #check command to check \nthe syntax and type of an expression you provide, from the use of\n*type checking* in Lean (as in Java), which checks whether the type\nof a value being bound to a variable is the same as the type that\nthe variable expects.\n-/\n\n/-\nWhereas \"def\" binds a variable to a value in the \"global\nenvironment\", the let keyword supports binding of values\nto local variables, followed by evaluation of an expression\nthat uses that local variable.\n-/\n\ndef x := 1\n#eval x\n\n#eval let a := 1 in a   --evaluates to 1\n\n#check a                -- not defined in global environment\n\n\n-- You can \"nest\" let expressions\n#reduce  let a := 3 in \n          let b := 4 in\n            let c := 5 in\n              a*a + b*b = c*c\n\n\n-- Within tactic scripts you leave off the \"in\" part\ntheorem pythag_25 : 3*3 + 4*4 = 5*5 :=\nbegin\n  let a := 3,   \n  let b := 4,\n  let c := 5,\n  show a * a + b * b = c * c,\n  exact rfl,\nend\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/01_Basic_Keywords/02_def_let.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7889985998448078}}
{"text": "import data.real.basic\n\nexample : ∀ P Q : Prop, P → Q → P := \n\n/- In Lean, the implication arrow → is right-associative. \n  P → Q → P in fact refers to P → (Q → P). -/\n\n/- A paper-pencil proof of P → (Q → P) would be the following:\n  - let P and Q be propositions;\n  - assume that the hypothesis of P (hp) and the hypothesis of Q (hq)are true;\n  - to prove P, we use hypothesis hp. -/\n\n/- A Lean proof-/\nbegin \n  intros P Q, \n  /- The 'intros P Q' tactic introduces two free variables P and Q in the local \n  context. The tactic mimics how mathematicians work on paper: To prove a \n  universally quantified proposition, it suffices to prove it for some arbitrary \n  but fixed value of the bound variable. -/\n\n  intros hp hq,\n  /- The 'intros hp hq' tactic introduces the proof of P called hp and \n  the proof of Q called hq to the local context. In other words, we assume that \n  P is true and Q is true, and we want to prove P is true. Indeed, to prove an \n  implication, it suffices to take its left-hand side as the hypothesis and prove \n  its right-hand side true. -/\n  \n  exact hp,\n  /- hp suffices to prove P because hp is the proof of P. The 'exact hp' tactic \n  tells Lean that hp is exactly needed to achieve and close the goal. -/\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/0_Introduction/demos/A simple example p_q_p.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107843878722, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7889680788976369}}
{"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 ℕ × ℕ as finsets\n\nThis file defines the antidiagonals of ℕ × ℕ 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 : ℕ) : finset (ℕ × ℕ) :=\n⟨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] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :\n  x ∈ antidiagonal n ↔ 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 : ℕ) : (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 : ℕ} :\n  antidiagonal (n + 1) = insert (0, n + 1) ((antidiagonal n).map\n  (function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ (function.embedding.refl _))) :=\nbegin\n  apply eq_of_veq,\n  rw [insert_val_of_not_mem, map_val],\n  {apply multiset.nat.antidiagonal_succ},\n  { intro con, rcases mem_map.1 con with ⟨⟨a,b⟩, ⟨h1, h2⟩⟩,\n    simp only [prod.mk.inj_iff, function.embedding.coe_prod_map, prod.map_mk] at h2,\n    apply nat.succ_ne_zero a h2.1, }\nend\n\nlemma map_swap_antidiagonal {n : ℕ} :\n  (antidiagonal n).map ⟨prod.swap, prod.swap_right_inverse.injective⟩ = antidiagonal n :=\nbegin\n  ext,\n  simp only [exists_prop, mem_map, mem_antidiagonal, prod.exists],\n  rw add_comm,\n  split,\n  { rintro ⟨b, c, ⟨rfl, rfl⟩⟩,\n    simp },\n  { rintro rfl,\n    use [a.snd, a.fst],\n    simp }\nend\n\n/-- A point in the antidiagonal is determined by its first co-ordinate. -/\nlemma antidiagonal_congr {n : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)\n  (hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=\nbegin\n  refine ⟨congr_arg prod.fst, (λ h, prod.ext h ((add_right_inj q.fst).mp _))⟩,\n  rw mem_antidiagonal at hp hq,\n  rw [hq, ← h, hp],\nend\n\nlemma antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.1 ≤ 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 : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.2 ≤ 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 : ℕ) :\n  filter (λ x : ℕ × ℕ, x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ :=\nbegin\n  ext ⟨x, y⟩,\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 λ 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 : ℕ) :\n  filter (λ x : ℕ × ℕ, x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ :=\nbegin\n  have : (λ (x : ℕ × ℕ), x.snd = m) ∘ prod.swap = (λ (x : ℕ × ℕ), x.fst = m),\n  { ext, simp },\n  rw ←map_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 `Σ (n : ℕ), antidiagonal n` is equivalent to the product\n    `ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps] def sigma_antidiagonal_equiv_prod : (Σ (n : ℕ), antidiagonal n) ≃ ℕ × ℕ :=\n{ to_fun := λ x, x.2,\n  inv_fun := λ x, ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩,\n  left_inv :=\n    begin\n      rintros ⟨n, ⟨k, l⟩, h⟩,\n      rw mem_antidiagonal at h,\n      exact sigma.subtype_ext h rfl,\n    end,\n  right_inv := λ x, rfl }\n\nend equiv_prod\n\nend nat\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/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.7888606336395929}}
{"text": "import MyNat\nimport MyNat.addition_world\n\nopen MyNat\n\nlemma mul_zero (a : ℕ) : a * zero = zero := by rfl\nlemma mul_succ (a b : ℕ) : a * succ b = a + (a * b) := by rfl\n\nlemma zero_mul (m : ℕ) : zero * m = zero :=\n  by induction m with \n  | zero => rewrite [mul_zero] rfl\n  | succ m' ih => rewrite [mul_succ, ih, zero_add] rfl\n\nlemma mul_one (m : ℕ) : m * 1 = m := \n  by rewrite [one_eq_succ_zero, mul_succ, mul_zero, add_zero] rfl\n\nlemma one_mul (m : ℕ) : 1 * m = m :=\n  by induction m with\n  | zero => rewrite [mul_zero] rfl\n  | succ m' ih => rewrite [mul_succ, ih, add_comm, succ_eq_add_one] rfl\n\nlemma mul_add (t a b : ℕ) : t * (a + b) = t * a + t * b :=\n  by induction b with \n  | zero => rewrite [mul_zero, add_zero, add_zero] rfl\n  | succ b' ih => rewrite [add_comm, succ_add, mul_succ, add_comm b' a, ih, ←add_assoc, add_right_comm, ← mul_succ, add_comm] rfl\n\nlemma mul_assoc (a b c : ℕ) : (a * b) * c = a * (b * c) := \n  by induction c with\n  | zero => rewrite [mul_zero, mul_zero, mul_zero] rfl\n  | succ c' ih => rewrite [mul_succ, mul_succ, mul_add, ih] rfl\n\nlemma succ_mul (a b : ℕ) : (succ a) * b = a * b + b := \n  by induction b with \n  | zero => rewrite [mul_zero, mul_zero, add_zero] rfl\n  | succ b' ih => rewrite [mul_succ, mul_succ, ih, ←add_assoc, add_right_comm, succ_add, add_comm a b', ←succ_add, add_comm (succ b') a, add_right_comm] rfl\n\nlemma add_mul (a b t : ℕ) : (a + b) * t = a * t + b * t :=\n  by induction t with\n  | zero => rewrite [mul_zero, mul_zero, mul_zero, add_zero] rfl\n  | succ t' ih => rewrite [mul_succ, ih, add_right_comm, ←add_assoc, ←mul_succ, add_right_comm, add_assoc, ←mul_succ] rfl\n\nlemma add_same (m : ℕ) : m + m = 2 * m :=\n  by rewrite [←one_mul m, ←add_mul, one_eq_succ_zero, succ_add, zero_add, ←one_eq_succ_zero, ←two_eq_succ_one, one_mul] rfl\n\nlemma mul_comm (a b : ℕ) : a * b = b * a := \n  by induction b with\n  | zero => rewrite [mul_zero, zero_mul] rfl\n  | succ b' ih => rewrite [mul_succ, succ_mul, ih, add_comm] rfl\n\nlemma mul_left_comm (a b c : ℕ) : a * (b * c) = b * (a * c) :=\n  by rewrite [mul_comm, mul_assoc, mul_comm c a] 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/multiplication_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.7888442261852193}}
{"text": "variables (α : Type) (p q : α → Prop)\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\n    iff.intro\n        (\n            assume h: ∀ x, (p x ∧ q x),\n            have ∀ x, p x, from (\n                assume x: α,\n                show p x, from (h x).left\n            ),\n            have ∀ x, q x, from (\n                assume x: α ,\n                show q x, from (h x).right\n            ),\n            and.intro ‹ ∀ x, p x › ‹ ∀ x, q x › \n        )\n        (\n            assume h: (∀ x, p x) ∧ (∀ x, q x),\n            assume y: α,\n            have p y, from h.left y,\n            have q y, from h.right y,\n            show p y ∧ q y, from and.intro ‹ p y › ‹ q y › \n        )\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\n    assume h: (∀ x, p x → q x),\n    assume hp: (∀ x, p x),\n    assume y: α,\n    show q y, from (h y) (hp y)\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\n    assume h: (∀ x, p x) ∨ (∀ x, q x),\n    or.elim\n        h\n        (\n            assume hl: ∀ x, p x,\n            assume y: α,\n            have p y, from hl y,\n            or.intro_left (q y) this\n        )\n        (\n            assume hr: ∀ x, q x,\n            assume y: α,\n            have q y, from hr y,\n            or.intro_right (p y) this\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_exercise1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7888442210051696}}
{"text": "/-\nHOMEWORK #9 \n\nThere is no need to import our previous definitions.\nFor this homework you will just use Lean's built-in\nnotations and definitions. \n-/\n\n\n\n/-\nProve the following. Note that you can read each of \nthe propositions to be proved as either a logical\nstatement or as simply a function definition. Use\nwhat you already know about the latter to arrive\nat a proof, and then understand the proof as one\nthat shows that the logical statement is true.\n-/\n\ntheorem t1 {P Q : Prop} (p2q : P → Q) (p : P) : Q :=\n  p2q p\n\n\ntheorem t2 {P Q R : Prop} (p2q : P → Q) (q2r : Q → R): P → R :=\n  λ (p : P), q2r (p2q p)\n\n/-\nUse \"example\" to state and prove the preceding two \ntheorems but using \"cases\" style notation rather\nthan C-style. Remember, \"example\" is a way to state\na proposition/type and give an example of a value.\nHere's an example of the use of \"example\". Give\nyour answers following this example.\n-/\n\n-- example\nexample : ℕ := 5\n\n-- Your two answers here\n\n-- HINT: use ∀ {P Q : Prop}, ... for the first one\n\nexample : ∀ {P Q : Prop}, (P → Q) → P → Q\n|  P Q p2q p := p2q p\n\nexample : ∀ {P Q R : Prop}, (P → Q) → (Q → R) → (P → R)\n|  P Q R p2q q2r := λ (p : P), q2r (p2q p)\n\n\n  -- HINT: YOU JUST PROVED THAT → is *transitive* !!!\n\n\n\n/-\nNow give English-language versions of your two proofs.\n-/\n\n\n\n/-\n1. Suppose P and Q are arbitrary propositions and that\nwe know that P → Q and also P are true. To show that\nQ is true, it suffices to apply → elimination rule of\nnatural deduction: apply the assumed proof of P → Q\nto the assumed proof of P to obtain a proof of Q. QED.\n-/\n\n/-\n2. Suppose P and Q are arbitrary propositions and that\nwe know that P → Q and also Q → R are true. To show\nthat P → R in this context, suppose P is true. Apply\nP → Q to deduce the truth of Q, then apply Q → R to\ndeduce the truth of R. QED.\n-/\n\n\n/-\nProve the following using case analysis on one\nof the arguments (i.e., use match...with...end\nat a key point in your proof). Use \"cases\" style\nnotation. \n-/\n\ntheorem t3 : ∀ (P : Prop), false → P\n| P f := false.elim f\n\n\n/-\nProve false → true by applying t3 to a proposition.\nYou have to figure out which one.\n-/\ntheorem t4 : false → true := t3 true\n\n/-\nDefine t5 to be the same as t3 but with P taken as\nan implicit argument.\n-/\n\ntheorem t5 : ∀ {P : Prop}, false → P\n| P f := false.elim f\n\n\n/-\nDefine t6 to be a proof of false → true by\napplying t5 to the right argument(s). \n-/\n\ntheorem t6 : false → true := t5\n\n/-\nThat is almost magic. In English, t3 proves \nthat false implies *any* proposition, so just\n*apply* t3 to *true* in particular, but use t5 \ninstead of t3.\n\nWhat you see here is really important: Once \nwe've proved a general theorem (a ∀ proposition)\nwe can *apply the proof* to any *particular* case \nto yield a proof for that specific case. This is \nthe elimination rule for ∀. It is also known as\nuniversal instantiation (UI). \n-/\n\n\n/-\nNext we see the idea that test cases are really\njust equality propositions to be proved. Here, \nfor example, is a definition of the factorial\nfunction.\n-/\n\ndef fac : ℕ → ℕ \n| 0 := 1\n| (n' + 1) := (n' + 1) * fac n'\n\n/-\nUse \"example\" to write test cases for the\nfirst ten natural number arguments to this\nfunction.\n-/\n\nexample : fac 0 = 1 := eq.refl 1\nexample : fac 1 = 1 := eq.refl _  -- Inferred\nexample : fac 2 = 2 := rfl        -- Shorthand\nexample : fac 3 = 6 := rfl\nexample : fac 4 = 24 := rfl\nexample : fac 5 = 125 := rfl\n#check @rfl           -- infers type and value\n\n\n-- The rest of your answers here\n\n/-\nInsight: A test case is an equality proposition.\nIt is proved by \"running\" the program under test\nto reduce the application of the function to input\narguments to produce an output that is then asserted\nto be equal to an expected output. \n\nIn many cases, all we have to do is to simplify\nthe expressions on each side of the eq to see if\nthey reduce to exactly the same value. If so, we\ncan *apply* eq.refl (a universal generalization!)\nto that value. Using rfl we can avoid even having\nto type that value in cases where Lean can infer\nit.\n-/\n\n\n/-\nThe next problem requires thave you give a proof of \na bi-implication, a proposition whose connective is \n↔. To prove a bi-implication requires that one prove\nan implication in each direction. \n\nHere you are asked to prove P ∧ Q ↔ Q ∧ P. What this\nformula asserts is that ∧ is commutative. To construct\na proof of this proposition you will have to apply \niff.intro to two smaller proofs, one of P → Q and \nand of Q → P. \n\nStart by \"assuming\" that P and Q are arbitary but \nspecific propositions (∀ introduction), then apply \niff.intro to two \"stubbed out\" arguments (underscores). \nWe suggest that you put the underscores in parentheses \non different lines. Then recursively fill in each of\nthese stubs with the required types of proofs. Study\nthe context that Lean shows you in its Messages panel\nto see what you have to work with at each point in \nyour proof constructions.\n-/\ntheorem t7 : ∀ {P Q : Prop}, P ∧ Q ↔ Q ∧ P :=\nλ P Q,\n    iff.intro \n    (λ pq, and.intro pq.right pq.left)\n    (λ qp, and.intro qp.right qp.left)\n\n\n/-\nIn English, when asked to prove P ↔ Q, one says, \"it\nwill suffice to show P → Q and then to show Q → P.\" One\nthen goes on to give a proof of each implication. It\nthen follows from iff.intro that a proof of P ↔ Q can\nbe constructed, proving the bi-implication.\n-/\n\n\n/-\nThe trick here is to do case analysis on porq\n(use match ... with ... end) and to show that \na proof of R can be constructed *in either case*.\n-/\ntheorem t8 {P Q R : Prop} (p2r : P → R) (q2r : Q → R) (porq : P ∨ Q) : R := \nmatch porq with\n| or.inl p := p2r p\n| or.inr q := q2r q\nend\n\n\n\n/-\nWe suggest that you use  \"let ... in\" to give\nnames to intermediate results that you then combine\nin a final expression to finish the proof.\n-/\ntheorem t9 : ∀ (P Q: Prop), (P → Q) → ¬ (P ∧ ¬ Q) :=\nλ P Q p2q pandnotq,\nlet p := pandnotq.left in\nlet q := p2q p in\nlet notq := pandnotq.right in\nfalse.elim (notq q)\n\n\n\ntheorem neg_elim' : ∀ (P : Prop), ¬ ¬ P → P :=\nλ P,\nλ nnp,\n_           -- STUCK!!\n\n\ntheorem neg_elim : ∀ (P : Prop), (P ∨ ¬ P) → (¬ ¬ P → P):= \nλ P,\n    λ h, \n        λ nnp,\n            match h with\n            | or.inl p := p\n            | or.inr np := false.elim (nnp np)  -- false elimination\n            end\n\n-- nnp : (¬ P) → false\n-- np : ¬ P\n-- nnp np = false!\n\n-- Let's use H to mean There is a sub-exponential time algorithm for Boolean sat.\n-- ¬ H means that there's not one.\n-- H ∨ ¬H\n\n-- make Lean into a classical logic\n-- axiom em : ∀ (P : Prop), P ∨ ¬ P\n#check classical.em\n\n\n\ntheorem t10 : ∀ (P : Prop), P ∨ ¬ P :=\nclassical.em\n\n\n#check @or.inl\n#check @or.inr\n\ntheorem t11 : ∀ (P Q : Prop), ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nλ P Q, \n    iff.intro \n        (λ not_porq,\n            match (classical.em P) with\n            | or.inl p := false.elim (not_porq (or.inl p))\n            | or.inr np := match (classical.em Q) with\n                           | or.inl q := false.elim (not_porq (or.inr q))\n                           | or.inr nq := and.intro np nq\n                           end\n            end    \n        )\n        -- ANSWER\n        (λ notpandnotq, \n            λ porq,\n                match porq with\n                | or.inl p := false.elim (notpandnotq.left p)\n                | or.inr q := false.elim (notpandnotq.right q)\n                end\n        )\n\ntheorem t12 : ∀ (P Q : Prop), ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\nλ P Q,\n    iff.intro \n    (λ not_pandq,\n        match (classical.em P) with\n        | or.inl p := match (classical.em Q) with\n                        | or.inl q := false.elim (not_pandq (and.intro p q))\n                        | or.inr nq := or.inr nq\n                      end\n        | or.inr np := or.inl np\n        end\n    )\n    (λ b, \n      λ c, \n        match b with\n        |or.inl np := np c.1\n        |or.inr nq := nq c.2\n        end\n    )\n\n/-\nFor the following exercises, we assume that there is \na type called Person and a binary relation, Likes, on\npairs of people.\n-/\naxiom Person : Type\naxiom Likes : Person → Person → Prop\n\n\n/-\nProve the following\n-/\ntheorem t13 : \n  (∃ (p : Person), ∀ (q : Person), Likes q p) → \n  (∀ (p : Person), ∃ (q : Person), Likes p q) :=\nλ h, \n    match h with\n    | exists.intro p pf := \n        λ q, \n            (exists.intro p (pf q))\n    end\n\n\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/hw9/hw9_key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.9196425262224018, "lm_q1q2_score": 0.7888400336736358}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández Palacios\n-/\n\nimport data.complex.basic\nimport data.real.cardinality\n\n/-!\n# The cardinality of the complex numbers\n\nThis file shows that the complex numbers have cardinality continuum, i.e. `#ℂ = 𝔠`.\n-/\n\nopen cardinal set\n\nopen_locale cardinal\n\n/-- The cardinality of the complex numbers, as a type. -/\n@[simp] theorem mk_complex : #ℂ = 𝔠 :=\nby rw [mk_congr complex.equiv_real_prod, mk_prod, lift_id, mk_real, continuum_mul_self]\n\n/-- The cardinality of the complex numbers, as a set. -/\n@[simp] lemma mk_univ_complex : #(set.univ : set ℂ) = 𝔠 :=\nby rw [mk_univ, mk_complex]\n\n/-- The complex numbers are not countable. -/\nlemma not_countable_complex : ¬ (set.univ : set ℂ).countable :=\nby { rw [← mk_set_le_aleph_0, not_le, mk_univ_complex], apply cantor }\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/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682086, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7888400270238647}}
{"text": "section propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro h,\n  intro g,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  by_cases h: P,\n  {intro g,\n  exact h,\n  },\n  {intro g,\n  have q:= g h,\n  contradiction,}\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  have k := doubleneg_elim P,\n  exact k,\n  have k := doubleneg_intro P,\n  exact k,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  right,\n  assumption,\n  left,\n  assumption,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ 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ções de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h,\n  intro p,\n  cases h with hnp hq,\n  contradiction,\n  exact hq,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro h,\n  intro np,\n  cases h with p q,\n  contradiction,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro h,\n  intro nq,\n  intro p,\n  have q := h p,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro h,\n  intro p,\n  by_cases lemQ: Q,\n  exact lemQ,\n  have np := h lemQ,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  have k := impl_as_contrapositive P Q,\n  exact k,\n  have k := impl_as_contrapositive_converse P Q,\n  exact k,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro nLEM,\n  have LEM : P ∨ ¬P,\n    right,\n    intro p,\n    have re_LEM : P ∨ ¬P,\n      left,\n      exact p,\n      contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro h,\n  intro np,\n  have h_contraposer := impl_as_contrapositive (P → Q) P,\n  have contrapos_h := h_contraposer h,\n  have n_ptoq := contrapos_h np,\n  have ptoq : P → Q,\n    intro p,\n    contradiction,\n  contradiction,\nend\n\n-------------------\n-- Estou ciente de que o jeito acima é mais trabalhoso do que o ideal. Fiz-lhe assim e assim manter-lhe-ei por fins científicos somente.\n-------------------\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro porq,\n  intro npnq,\n  cases npnq with np nq,\n  cases porq with p q,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro pq,\n  intro npRnq,\n  cases pq with p q,\n  cases npRnq with np nq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro npRq,\n  split,\n  intro p,\n  have pRq : P ∨ Q,\n    left,\n    exact p,\n  contradiction,\n  intro q,\n  have pRq : P ∨ Q,\n    right,\n    exact q,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro npnq,\n  intro pRq,\n  cases npnq with np nq,\n  cases pRq with p q,\n    contradiction,\n    contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro npq,\n  by_cases lemp : P,\n  left,\n  by_contradiction nnq,\n  have cont :P∧Q,\n    split,\n    exact lemp,\n    exact nnq,\n  contradiction,\n  right,\n  exact lemp,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro nqRnp,\n  intro pq,\n  cases pq with p q,\n  cases nqRnp with nq np,\n    contradiction,\n    contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  have k := demorgan_conj P Q,\n  exact k,\n  have k := demorgan_conj_converse P Q,\n  exact k,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  have k := demorgan_disj P Q,\n  exact k,\n  have k := demorgan_disj_converse P Q,\n  exact k,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro pqRr,\n  cases pqRr with p qRr,\n  cases qRr with q r,\n  left,\n  have pq : P ∧ Q,\n    split,\n    exact p,\n    exact q,\n  exact pq,\n  right,\n  have pr : P ∧ R,\n    split,\n    exact p,\n    exact r,\n  exact pr,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro pqRpr,\n  cases pqRpr with pq pr,\n    cases pq with p q,\n    split,\n    exact p,\n    left,\n    exact q,\n    cases pr with p r,\n    split,\n    exact p,\n    right,\n    exact r,\n  \nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro pRqr,\n  cases pRqr with p qr,\n  split,\n  left,\n  exact p,\n  left,\n  exact p,\n  cases qr with q r,\n  split,\n  right,\n  exact q,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro pRqpRr,\n  cases pRqpRr with pRq pRr,\n  cases pRq with p q,\n  left,\n  exact p,\n  cases pRr with p r,\n  left,\n  exact p,\n  right,\n  have qr : Q∧R,\n    split,\n    exact q,\n    exact r,\n  exact qr,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro pqTr,\n  intro p,\n  intro q,\n  have pq : P∧Q,\n    split,\n    exact p,\n    exact q,\n  have r := pqTr pq,\n  exact r,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro pTqTr,\n  intro pq,\n  cases pq with p q,\n  have qTr := pTqTr p,\n  have r := qTr q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro pq,\n  cases pq with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro pq,\n  cases pq with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pp,\n  cases pp with p1 p2,\n  exact p1,\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro pRp,\n  cases pRp with p1 p2,\n  exact p1,\n  exact p2,\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro nEpx,\n  intro x,\n  intro px,\n  have cont : (∃x, P x),\n    existsi x,\n    exact px,\n  contradiction,\n    \nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro xp,\n  intro nxp,\n  cases nxp with x,\n  have cont := xp x,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  apply impl_as_contrapositive_converse  (¬(∀x, P x)) (∃x, ¬P x),\n  intro nEnpx,\n  apply doubleneg_intro (∀x, P x),\n  intro x,\n  by_contra,\n  have Enpx : ∃x, ¬P x,\n    existsi x,\n    exact h,\n  contradiction,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro Exnpx,\n  intro Fxpx,\n  cases Exnpx with x npx,\n  have px := Fxpx x,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  have k := demorgan_forall U P,\n  exact k,\n  have k := demorgan_forall_converse U P,\n  exact k,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  have k := demorgan_exists U P,\n  exact k,\n  have k := demorgan_exists_converse U P,\n  exact k,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro Epx,\n  intro nFnpx,\n  cases Epx with x px,\n  have npx := nFnpx x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro Fxpx,\n  intro Exnpx,\n  cases Exnpx with x npx,\n  have px := Fxpx x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro nEnpx,\n  intro x,\n  by_contra npx,\n  have Enpx : ∃x, ¬P x,\n    existsi x,\n    exact npx,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro nFnpx,\n  by_contra nEpx,\n  have nFnpx : ∀x, ¬P x,\n    intro x,\n    intro px,\n    have Epx: ∃x, P x,\n      existsi x,\n      exact px,\n    contradiction,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  have k := forall_as_neg_exists U P,\n  exact k,\n  have k := forall_as_neg_exists_converse U P,\n  exact k,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  have k := exists_as_neg_forall U P,\n  exact k,\n  have k := exists_as_neg_forall_converse U P,\n  exact k,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro Expxqx,\n  cases Expxqx with x pxqx,\n  cases pxqx with px qx,\n  split,\n  existsi x,\n  exact px,\n  existsi x,\n  exact qx,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro ExpxRqx,\n  cases ExpxRqx with x pxRqx,\n  cases pxRqx with px qx,\n  left,\n  existsi x,\n  exact px,\n  right,\n  existsi x,\n  exact qx,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro ExpxRExqx,\n  cases ExpxRExqx with Expx Exqx,\n  cases Expx with x px,\n  existsi x,\n  left,\n  exact px,\n  cases Exqx with x qx,\n  existsi x,\n  right,\n  exact qx,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro Fpxqx,\n  split,\n  intro x,\n  have pxqx := Fpxqx x,\n  cases pxqx with px qx,\n  exact px,\n  intro x,\n  have pxqx := Fpxqx x,\n  cases pxqx with px qx,\n  exact qx,\n  \nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro FxpxFxqx,\n  intro x,\n  cases FxpxFxqx with Fxpx Fxqx,\n  split,\n  have px := Fxpx x,\n  exact px,\n  have qx := Fxqx x,\n  exact qx,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro FxpxRFxqx,\n  intro x,\n  cases FxpxRFxqx with Fxpx Fxqx,\n  have px := Fxpx x,\n  left,\n  exact px,\n  have qx := Fxqx x,\n  right,\n  exact qx,\nend\n\n\n/- NOT THEOREMS --------------------------------\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n---------------------------------------------- -/\n\nend predicate", "meta": {"author": "gabrielmds222", "repo": "fmclean", "sha": "a4985ff6b3aadb630ed26a75f6733e1adb69d24b", "save_path": "github-repos/lean/gabrielmds222-fmclean", "path": "github-repos/lean/gabrielmds222-fmclean/fmclean-a4985ff6b3aadb630ed26a75f6733e1adb69d24b/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7888400205535915}}
{"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 measure_theory.group.prod\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.Constructions.Prod\nimport Mathbin.MeasureTheory.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 `μ(t) = c * μ(s)`\nfor two sets `s` and `t`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be\nthe characteristic functions of `s` and `t`.\nAssume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`\npreserves the measure `μ × ν`, which means that\n```\n  ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ\n```\nIf we apply this to `h x y := e x * f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' s)`, we can rewrite the RHS to\n`μ(t)`, and the LHS to `c * μ(s)`, where `c = c(ν)` does not depend on `μ`.\nApplying this to `μ` and to `ν` gives `μ (t) / μ (s) = ν (t) / ν (s)`, which is the uniqueness up to\nscalar multiplication.\n\nThe proof in [Halmos] seems to contain an omission in §60 Th. A, see\n`measure_theory.measure_lintegral_div_measure`.\n\n-/\n\n\nnoncomputable section\n\nopen Set hiding prod_eq\n\nopen Function MeasureTheory\n\nopen Filter hiding map\n\nopen Classical ENNReal Pointwise MeasureTheory\n\nvariable (G : Type _) [MeasurableSpace G]\n\nvariable [Group G] [HasMeasurableMul₂ G]\n\nvariable (μ ν : Measure G) [SigmaFinite ν] [SigmaFinite μ] {s : Set G}\n\n/-- The map `(x, y) ↦ (x, xy)` as a `measurable_equiv`. -/\n@[to_additive \"The map `(x, y) ↦ (x, x + y)` as a `measurable_equiv`.\"]\nprotected def MeasurableEquiv.shearMulRight [HasMeasurableInv G] : G × G ≃ᵐ G × G :=\n  {\n    Equiv.prodShear (Equiv.refl _)\n      Equiv.mulLeft with\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#align measurable_equiv.shear_mul_right MeasurableEquiv.shearMulRight\n#align measurable_equiv.shear_add_right MeasurableEquiv.shearAddRight\n\n/-- The map `(x, y) ↦ (x, y / x)` as a `measurable_equiv` with as inverse `(x, y) ↦ (x, yx)` -/\n@[to_additive\n      \"The map `(x, y) ↦ (x, y - x)` as a `measurable_equiv` with as inverse `(x, y) ↦ (x, y + x)`.\"]\nprotected def MeasurableEquiv.shearDivRight [HasMeasurableInv G] : G × G ≃ᵐ G × G :=\n  {\n    Equiv.prodShear (Equiv.refl _)\n      Equiv.divRight with\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#align measurable_equiv.shear_div_right MeasurableEquiv.shearDivRight\n#align measurable_equiv.shear_sub_right MeasurableEquiv.shearSubRight\n\nvariable {G}\n\nnamespace MeasureTheory\n\nopen Measure\n\nsection LeftInvariant\n\n/-- The multiplicative shear mapping `(x, y) ↦ (x, xy)` preserves the measure `μ × ν`.\nThis condition is part of the definition of a measurable group in [Halmos, §59].\nThere, the map in this lemma is called `S`. -/\n@[to_additive measure_preserving_prod_add\n      \" The shear mapping `(x, y) ↦ (x, x + y)` preserves the measure `μ × ν`. \"]\ntheorem measurePreservingProdMul [IsMulLeftInvariant ν] :\n    MeasurePreserving (fun z : G × G => (z.1, z.1 * z.2)) (μ.Prod ν) (μ.Prod ν) :=\n  (MeasurePreserving.id μ).skewProduct measurable_mul <|\n    Filter.eventually_of_forall <| map_mul_left_eq_self ν\n#align measure_theory.measure_preserving_prod_mul MeasureTheory.measurePreservingProdMul\n#align measure_theory.measure_preserving_prod_add MeasureTheory.measure_preserving_prod_add\n\n/-- The map `(x, y) ↦ (y, yx)` sends the measure `μ × ν` to `ν × μ`.\nThis is the map `SR` in [Halmos, §59].\n`S` is the map `(x, y) ↦ (x, xy)` and `R` is `prod.swap`. -/\n@[to_additive measure_preserving_prod_add_swap\n      \" The map `(x, y) ↦ (y, y + x)` sends the measure `μ × ν` to `ν × μ`. \"]\ntheorem measurePreservingProdMulSwap [IsMulLeftInvariant μ] :\n    MeasurePreserving (fun z : G × G => (z.2, z.2 * z.1)) (μ.Prod ν) (ν.Prod μ) :=\n  (measurePreservingProdMul ν μ).comp measurePreservingSwap\n#align measure_theory.measure_preserving_prod_mul_swap MeasureTheory.measurePreservingProdMulSwap\n#align measure_theory.measure_preserving_prod_add_swap MeasureTheory.measure_preserving_prod_add_swap\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[to_additive]\ntheorem measurable_measure_mul_right (hs : MeasurableSet s) :\n    Measurable fun x => μ ((fun y => y * x) ⁻¹' s) :=\n  by\n  suffices\n    Measurable fun y =>\n      μ ((fun x => (x, y)) ⁻¹' ((fun z : G × G => ((1 : G), z.1 * z.2)) ⁻¹' univ ×ˢ s))\n    by\n    convert this\n    ext1 x\n    congr 1 with y : 1\n    simp\n  apply measurable_measure_prod_mk_right\n  exact measurable_const.prod_mk measurable_mul (measurable_set.univ.prod hs)\n#align measure_theory.measurable_measure_mul_right MeasureTheory.measurable_measure_mul_right\n#align measure_theory.measurable_measure_add_right MeasureTheory.measurable_measure_add_right\n\nvariable [HasMeasurableInv G]\n\n/-- The map `(x, y) ↦ (x, x⁻¹y)` is measure-preserving.\nThis is the function `S⁻¹` in [Halmos, §59],\nwhere `S` is the map `(x, y) ↦ (x, xy)`. -/\n@[to_additive measure_preserving_prod_neg_add\n      \"The map `(x, y) ↦ (x, - x + y)` is measure-preserving.\"]\ntheorem measurePreservingProdInvMul [IsMulLeftInvariant ν] :\n    MeasurePreserving (fun z : G × G => (z.1, z.1⁻¹ * z.2)) (μ.Prod ν) (μ.Prod ν) :=\n  (measurePreservingProdMul μ ν).symm <| MeasurableEquiv.shearMulRight G\n#align measure_theory.measure_preserving_prod_inv_mul MeasureTheory.measurePreservingProdInvMul\n#align measure_theory.measure_preserving_prod_neg_add MeasureTheory.measure_preserving_prod_neg_add\n\nvariable [IsMulLeftInvariant μ]\n\n/-- The map `(x, y) ↦ (y, y⁻¹x)` sends `μ × ν` to `ν × μ`.\nThis is the function `S⁻¹R` in [Halmos, §59],\nwhere `S` is the map `(x, y) ↦ (x, xy)` and `R` is `prod.swap`. -/\n@[to_additive measure_preserving_prod_neg_add_swap\n      \"The map `(x, y) ↦ (y, - y + x)` sends `μ × ν` to `ν × μ`.\"]\ntheorem measurePreservingProdInvMulSwap :\n    MeasurePreserving (fun z : G × G => (z.2, z.2⁻¹ * z.1)) (μ.Prod ν) (ν.Prod μ) :=\n  (measurePreservingProdInvMul ν μ).comp measurePreservingSwap\n#align measure_theory.measure_preserving_prod_inv_mul_swap MeasureTheory.measurePreservingProdInvMulSwap\n#align measure_theory.measure_preserving_prod_neg_add_swap MeasureTheory.measure_preserving_prod_neg_add_swap\n\n/-- The map `(x, y) ↦ (yx, x⁻¹)` is measure-preserving.\nThis is the function `S⁻¹RSR` in [Halmos, §59],\nwhere `S` is the map `(x, y) ↦ (x, xy)` and `R` is `prod.swap`. -/\n@[to_additive measure_preserving_add_prod_neg\n      \"The map `(x, y) ↦ (y + x, - x)` is measure-preserving.\"]\ntheorem measurePreservingMulProdInv [IsMulLeftInvariant ν] :\n    MeasurePreserving (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.Prod ν) (μ.Prod ν) :=\n  by\n  convert(measure_preserving_prod_inv_mul_swap ν μ).comp (measure_preserving_prod_mul_swap μ ν)\n  ext1 ⟨x, y⟩\n  simp_rw [Function.comp_apply, mul_inv_rev, inv_mul_cancel_right]\n#align measure_theory.measure_preserving_mul_prod_inv MeasureTheory.measurePreservingMulProdInv\n#align measure_theory.measure_preserving_add_prod_neg MeasureTheory.measure_preserving_add_prod_neg\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n@[to_additive]\ntheorem quasiMeasurePreservingInv : QuasiMeasurePreserving (Inv.inv : G → G) μ μ :=\n  by\n  refine' ⟨measurable_inv, absolutely_continuous.mk fun s hsm hμs => _⟩\n  rw [map_apply measurable_inv hsm, inv_preimage]\n  have hf : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) :=\n    (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv\n  suffices map (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (s⁻¹ ×ˢ s⁻¹) = 0 by\n    simpa only [(measure_preserving_mul_prod_inv μ μ).map_eq, prod_prod, mul_eq_zero,\n      or_self_iff] using this\n  have hsm' : MeasurableSet (s⁻¹ ×ˢ s⁻¹) := 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μs, lintegral_zero]\n#align measure_theory.quasi_measure_preserving_inv MeasureTheory.quasiMeasurePreservingInv\n#align measure_theory.quasi_measure_preserving_neg MeasureTheory.quasi_measure_preserving_neg\n\n@[to_additive]\ntheorem measure_inv_null : μ s⁻¹ = 0 ↔ μ s = 0 :=\n  by\n  refine' ⟨fun hs => _, (quasi_measure_preserving_inv μ).preimage_null⟩\n  rw [← inv_inv s]\n  exact (quasi_measure_preserving_inv μ).preimage_null hs\n#align measure_theory.measure_inv_null MeasureTheory.measure_inv_null\n#align measure_theory.measure_neg_null MeasureTheory.measure_neg_null\n\n@[to_additive]\ntheorem invAbsolutelyContinuous : μ.inv ≪ μ :=\n  (quasiMeasurePreservingInv μ).AbsolutelyContinuous\n#align measure_theory.inv_absolutely_continuous MeasureTheory.invAbsolutelyContinuous\n#align measure_theory.neg_absolutely_continuous MeasureTheory.neg_absolutely_continuous\n\n@[to_additive]\ntheorem absolutelyContinuousInv : μ ≪ μ.inv :=\n  by\n  refine' absolutely_continuous.mk fun s hs => _\n  simp_rw [inv_apply μ s, measure_inv_null, imp_self]\n#align measure_theory.absolutely_continuous_inv MeasureTheory.absolutelyContinuousInv\n#align measure_theory.absolutely_continuous_neg MeasureTheory.absolutely_continuous_neg\n\n@[to_additive]\ntheorem lintegral_lintegral_mul_inv [IsMulLeftInvariant ν] (f : G → G → ℝ≥0∞)\n    (hf : AeMeasurable (uncurry f) (μ.Prod ν)) :\n    (∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ) = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ :=\n  by\n  have h : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) :=\n    (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv\n  have h2f : AeMeasurable (uncurry fun x y => f (y * x) x⁻¹) (μ.prod ν) :=\n    hf.comp_quasi_measure_preserving (measure_preserving_mul_prod_inv μ ν).QuasiMeasurePreserving\n  simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf]\n  conv_rhs => rw [← (measure_preserving_mul_prod_inv μ ν).map_eq]\n  symm\n  exact\n    lintegral_map' (hf.mono' (measure_preserving_mul_prod_inv μ ν).map_eq.AbsolutelyContinuous)\n      h.ae_measurable\n#align measure_theory.lintegral_lintegral_mul_inv MeasureTheory.lintegral_lintegral_mul_inv\n#align measure_theory.lintegral_lintegral_add_neg MeasureTheory.lintegral_lintegral_add_neg\n\n@[to_additive]\ntheorem measure_mul_right_null (y : G) : μ ((fun x => x * y) ⁻¹' s) = 0 ↔ μ s = 0 :=\n  calc\n    μ ((fun x => x * y) ⁻¹' s) = 0 ↔ μ ((fun x => y⁻¹ * x) ⁻¹' s⁻¹)⁻¹ = 0 := by\n      simp_rw [← inv_preimage, preimage_preimage, mul_inv_rev, inv_inv]\n    _ ↔ μ s = 0 := by simp only [measure_inv_null μ, measure_preimage_mul]\n    \n#align measure_theory.measure_mul_right_null MeasureTheory.measure_mul_right_null\n#align measure_theory.measure_add_right_null MeasureTheory.measure_add_right_null\n\n@[to_additive]\ntheorem measure_mul_right_ne_zero (h2s : μ s ≠ 0) (y : G) : μ ((fun x => x * y) ⁻¹' s) ≠ 0 :=\n  (not_congr (measure_mul_right_null μ y)).mpr h2s\n#align measure_theory.measure_mul_right_ne_zero MeasureTheory.measure_mul_right_ne_zero\n#align measure_theory.measure_add_right_ne_zero MeasureTheory.measure_add_right_ne_zero\n\n@[to_additive]\ntheorem absolutelyContinuousMapMulRight (g : G) : μ ≪ map (· * g) μ :=\n  by\n  refine' absolutely_continuous.mk fun s hs => _\n  rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null]; exact id\n#align measure_theory.absolutely_continuous_map_mul_right MeasureTheory.absolutelyContinuousMapMulRight\n#align measure_theory.absolutely_continuous_map_add_right MeasureTheory.absolutely_continuous_map_add_right\n\n@[to_additive]\ntheorem absolutelyContinuousMapDivLeft (g : G) : μ ≪ map (fun h => g / h) μ :=\n  by\n  simp_rw [div_eq_mul_inv]\n  rw [← map_map (measurable_const_mul g) measurable_inv]\n  conv_lhs => rw [← map_mul_left_eq_self μ g]\n  exact (absolutely_continuous_inv μ).map (measurable_const_mul g)\n#align measure_theory.absolutely_continuous_map_div_left MeasureTheory.absolutelyContinuousMapDivLeft\n#align measure_theory.absolutely_continuous_map_sub_left MeasureTheory.absolutely_continuous_map_sub_left\n\n/-- This is the computation performed in the proof of [Halmos, §60 Th. A]. -/\n@[to_additive \"This is the computation performed in the proof of [Halmos, §60 Th. A].\"]\ntheorem measure_mul_lintegral_eq [IsMulLeftInvariant ν] (sm : MeasurableSet s) (f : G → ℝ≥0∞)\n    (hf : Measurable f) : (μ s * ∫⁻ y, f y ∂ν) = ∫⁻ x, ν ((fun z => z * x) ⁻¹' s) * f x⁻¹ ∂μ :=\n  by\n  rw [← set_lintegral_one, ← lintegral_indicator _ sm, ←\n    lintegral_lintegral_mul (measurable_const.indicator sm).AeMeasurable hf.ae_measurable, ←\n    lintegral_lintegral_mul_inv μ ν]\n  swap\n  ·\n    exact\n      (((measurable_const.indicator sm).comp measurable_fst).mul\n          (hf.comp measurable_snd)).AeMeasurable\n  have ms :\n    ∀ x : G, Measurable fun y => ((fun z => z * x) ⁻¹' s).indicator (fun z => (1 : ℝ≥0∞)) y :=\n    fun x => measurable_const.indicator (measurable_mul_const _ sm)\n  have :\n    ∀ x y,\n      s.indicator (fun z : G => (1 : ℝ≥0∞)) (y * x) =\n        ((fun z => z * x) ⁻¹' s).indicator (fun b : G => 1) y :=\n    by\n    intro x y\n    symm\n    convert indicator_comp_right fun y => y * x\n    ext1 z\n    rfl\n  simp_rw [this, lintegral_mul_const _ (ms _), lintegral_indicator _ (measurable_mul_const _ sm),\n    set_lintegral_one]\n#align measure_theory.measure_mul_lintegral_eq MeasureTheory.measure_mul_lintegral_eq\n#align measure_theory.measure_add_lintegral_eq MeasureTheory.measure_add_lintegral_eq\n\n/-- Any two nonzero left-invariant measures are absolutely continuous w.r.t. each other. -/\n@[to_additive\n      \" Any two nonzero left-invariant measures are absolutely continuous w.r.t. each\\nother. \"]\ntheorem absolutelyContinuousOfIsMulLeftInvariant [IsMulLeftInvariant ν] (hν : ν ≠ 0) : μ ≪ ν :=\n  by\n  refine' absolutely_continuous.mk fun s sm hνs => _\n  have h1 := measure_mul_lintegral_eq μ ν sm 1 measurable_one\n  simp_rw [Pi.one_apply, lintegral_one, mul_one, (measure_mul_right_null ν _).mpr hνs,\n    lintegral_zero, mul_eq_zero, measure_univ_eq_zero.not.mpr hν, or_false_iff] at h1\n  exact h1\n#align measure_theory.absolutely_continuous_of_is_mul_left_invariant MeasureTheory.absolutelyContinuousOfIsMulLeftInvariant\n#align measure_theory.absolutely_continuous_of_is_add_left_invariant MeasureTheory.absolutely_continuous_of_is_add_left_invariant\n\n@[to_additive]\ntheorem ae_measure_preimage_mul_right_lt_top [IsMulLeftInvariant ν] (sm : MeasurableSet s)\n    (hμs : μ s ≠ ∞) : ∀ᵐ x ∂μ, ν ((fun y => y * x) ⁻¹' s) < ∞ :=\n  by\n  refine' ae_of_forall_measure_lt_top_ae_restrict' ν.inv _ _\n  intro A hA h2A h3A\n  simp only [ν.inv_apply] at h3A\n  apply ae_lt_top (measurable_measure_mul_right ν sm)\n  have h1 := measure_mul_lintegral_eq μ ν sm (A⁻¹.indicator 1) (measurable_one.indicator hA.inv)\n  rw [lintegral_indicator _ hA.inv] at h1\n  simp_rw [Pi.one_apply, set_lintegral_one, ← image_inv, indicator_image inv_injective, image_inv, ←\n    indicator_mul_right _ fun x => ν ((fun y => y * x) ⁻¹' s), Function.comp, Pi.one_apply,\n    mul_one] at h1\n  rw [← lintegral_indicator _ hA, ← h1]\n  exact ENNReal.mul_ne_top hμs h3A.ne\n#align measure_theory.ae_measure_preimage_mul_right_lt_top MeasureTheory.ae_measure_preimage_mul_right_lt_top\n#align measure_theory.ae_measure_preimage_add_right_lt_top MeasureTheory.ae_measure_preimage_add_right_lt_top\n\n@[to_additive]\ntheorem ae_measure_preimage_mul_right_lt_top_of_ne_zero [IsMulLeftInvariant ν]\n    (sm : MeasurableSet s) (h2s : ν s ≠ 0) (h3s : ν s ≠ ∞) :\n    ∀ᵐ x ∂μ, ν ((fun y => y * x) ⁻¹' s) < ∞ :=\n  by\n  refine' (ae_measure_preimage_mul_right_lt_top ν ν sm h3s).filter_mono _\n  refine' (absolutely_continuous_of_is_mul_left_invariant μ ν _).ae_le\n  refine' mt _ h2s\n  intro hν\n  rw [hν, measure.coe_zero, Pi.zero_apply]\n#align measure_theory.ae_measure_preimage_mul_right_lt_top_of_ne_zero MeasureTheory.ae_measure_preimage_mul_right_lt_top_of_ne_zero\n#align measure_theory.ae_measure_preimage_add_right_lt_top_of_ne_zero MeasureTheory.ae_measure_preimage_add_right_lt_top_of_ne_zero\n\n/-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A].\n  Note that if `f` is the characteristic function of a measurable set `t` this states that\n  `μ t = c * μ s` for a constant `c` that does not depend on `μ`.\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⁻¹)ν(sx⁻¹) = f(x)` holds if we can prove that\n  `0 < ν(sx⁻¹) < ∞`. The first inequality follows from §59, 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\n      \"A technical lemma relating two different measures. This is basically\\n[Halmos, §60 Th. A]. Note that if `f` is the characteristic function of a measurable set `t` this\\nstates that `μ t = c * μ s` for a constant `c` that does not depend on `μ`.\\n\\nNote: There is a gap in the last step of the proof in [Halmos]. In the last line, the equality\\n`g(-x) + ν(s - x) = f(x)` holds if we can prove that `0 < ν(s - x) < ∞`. The first inequality\\nfollows from §59, 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`.\"]\ntheorem measure_lintegral_div_measure [IsMulLeftInvariant ν] (sm : MeasurableSet s) (h2s : ν s ≠ 0)\n    (h3s : ν s ≠ ∞) (f : G → ℝ≥0∞) (hf : Measurable f) :\n    (μ s * ∫⁻ y, f y⁻¹ / ν ((fun x => x * y⁻¹) ⁻¹' s) ∂ν) = ∫⁻ x, f x ∂μ :=\n  by\n  set g := fun y => f y⁻¹ / ν ((fun x => x * y⁻¹) ⁻¹' s)\n  have hg : Measurable g :=\n    (hf.comp measurable_inv).div ((measurable_measure_mul_right ν sm).comp measurable_inv)\n  simp_rw [measure_mul_lintegral_eq μ ν sm g hg, g, inv_inv]\n  refine' lintegral_congr_ae _\n  refine' (ae_measure_preimage_mul_right_lt_top_of_ne_zero μ ν sm h2s h3s).mono fun x hx => _\n  simp_rw [ENNReal.mul_div_cancel' (measure_mul_right_ne_zero ν h2s _) hx.ne]\n#align measure_theory.measure_lintegral_div_measure MeasureTheory.measure_lintegral_div_measure\n#align measure_theory.measure_lintegral_sub_measure MeasureTheory.measure_lintegral_sub_measure\n\n@[to_additive]\ntheorem measure_mul_measure_eq [IsMulLeftInvariant ν] {s t : Set G} (hs : MeasurableSet s)\n    (ht : MeasurableSet t) (h2s : ν s ≠ 0) (h3s : ν s ≠ ∞) : μ s * ν t = ν s * μ t :=\n  by\n  have h1 :=\n    measure_lintegral_div_measure ν ν hs h2s h3s (t.indicator fun x => 1)\n      (measurable_const.indicator ht)\n  have h2 :=\n    measure_lintegral_div_measure μ ν hs h2s h3s (t.indicator fun x => 1)\n      (measurable_const.indicator ht)\n  rw [lintegral_indicator _ ht, set_lintegral_one] at h1 h2\n  rw [← h1, mul_left_comm, h2]\n#align measure_theory.measure_mul_measure_eq MeasureTheory.measure_mul_measure_eq\n#align measure_theory.measure_add_measure_eq MeasureTheory.measure_add_measure_eq\n\n/-- Left invariant Borel measures on a measurable group are unique (up to a scalar). -/\n@[to_additive\n      \" Left invariant Borel measures on an additive measurable group are unique\\n  (up to a scalar). \"]\ntheorem measure_eq_div_smul [IsMulLeftInvariant ν] (hs : MeasurableSet s) (h2s : ν s ≠ 0)\n    (h3s : ν s ≠ ∞) : μ = (μ s / ν s) • ν := by\n  ext1 t ht\n  rw [smul_apply, smul_eq_mul, mul_comm, ← mul_div_assoc, mul_comm,\n    measure_mul_measure_eq μ ν hs ht h2s h3s, mul_div_assoc, ENNReal.mul_div_cancel' h2s h3s]\n#align measure_theory.measure_eq_div_smul MeasureTheory.measure_eq_div_smul\n#align measure_theory.measure_eq_sub_vadd MeasureTheory.measure_eq_sub_vadd\n\nend LeftInvariant\n\nsection RightInvariant\n\n@[to_additive measure_preserving_prod_add_right]\ntheorem measurePreservingProdMulRight [IsMulRightInvariant ν] :\n    MeasurePreserving (fun z : G × G => (z.1, z.2 * z.1)) (μ.Prod ν) (μ.Prod ν) :=\n  (MeasurePreserving.id μ).skewProduct (measurable_snd.mul measurable_fst) <|\n    Filter.eventually_of_forall <| map_mul_right_eq_self ν\n#align measure_theory.measure_preserving_prod_mul_right MeasureTheory.measurePreservingProdMulRight\n#align measure_theory.measure_preserving_prod_add_right MeasureTheory.measure_preserving_prod_add_right\n\n/-- The map `(x, y) ↦ (y, xy)` sends the measure `μ × ν` to `ν × μ`. -/\n@[to_additive measure_preserving_prod_add_swap_right\n      \" The map `(x, y) ↦ (y, x + y)` sends the measure `μ × ν` to `ν × μ`. \"]\ntheorem measurePreservingProdMulSwapRight [IsMulRightInvariant μ] :\n    MeasurePreserving (fun z : G × G => (z.2, z.1 * z.2)) (μ.Prod ν) (ν.Prod μ) :=\n  (measurePreservingProdMulRight ν μ).comp measurePreservingSwap\n#align measure_theory.measure_preserving_prod_mul_swap_right MeasureTheory.measurePreservingProdMulSwapRight\n#align measure_theory.measure_preserving_prod_add_swap_right MeasureTheory.measure_preserving_prod_add_swap_right\n\n/-- The map `(x, y) ↦ (xy, y)` preserves the measure `μ × ν`. -/\n@[to_additive measure_preserving_add_prod\n      \" The map `(x, y) ↦ (x + y, y)` preserves the measure `μ × ν`. \"]\ntheorem measurePreservingMulProd [IsMulRightInvariant μ] :\n    MeasurePreserving (fun z : G × G => (z.1 * z.2, z.2)) (μ.Prod ν) (μ.Prod ν) :=\n  measurePreservingSwap.comp <| by apply measure_preserving_prod_mul_swap_right μ ν\n#align measure_theory.measure_preserving_mul_prod MeasureTheory.measurePreservingMulProd\n#align measure_theory.measure_preserving_add_prod MeasureTheory.measure_preserving_add_prod\n\nvariable [HasMeasurableInv G]\n\n/-- The map `(x, y) ↦ (x, y / x)` is measure-preserving. -/\n@[to_additive measure_preserving_prod_sub \"The map `(x, y) ↦ (x, y - x)` is measure-preserving.\"]\ntheorem measurePreservingProdDiv [IsMulRightInvariant ν] :\n    MeasurePreserving (fun z : G × G => (z.1, z.2 / z.1)) (μ.Prod ν) (μ.Prod ν) :=\n  (measurePreservingProdMulRight μ ν).symm (MeasurableEquiv.shearDivRight G).symm\n#align measure_theory.measure_preserving_prod_div MeasureTheory.measurePreservingProdDiv\n#align measure_theory.measure_preserving_prod_sub MeasureTheory.measure_preserving_prod_sub\n\n/-- The map `(x, y) ↦ (y, x / y)` sends `μ × ν` to `ν × μ`. -/\n@[to_additive measure_preserving_prod_sub_swap\n      \"The map `(x, y) ↦ (y, x - y)` sends `μ × ν` to `ν × μ`.\"]\ntheorem measurePreservingProdDivSwap [IsMulRightInvariant μ] :\n    MeasurePreserving (fun z : G × G => (z.2, z.1 / z.2)) (μ.Prod ν) (ν.Prod μ) :=\n  (measurePreservingProdDiv ν μ).comp measurePreservingSwap\n#align measure_theory.measure_preserving_prod_div_swap MeasureTheory.measurePreservingProdDivSwap\n#align measure_theory.measure_preserving_prod_sub_swap MeasureTheory.measure_preserving_prod_sub_swap\n\n/-- The map `(x, y) ↦ (x / y, y)` preserves the measure `μ × ν`. -/\n@[to_additive measure_preserving_sub_prod\n      \" The map `(x, y) ↦ (x - y, y)` preserves the measure `μ × ν`. \"]\ntheorem measurePreservingDivProd [IsMulRightInvariant μ] :\n    MeasurePreserving (fun z : G × G => (z.1 / z.2, z.2)) (μ.Prod ν) (μ.Prod ν) :=\n  measurePreservingSwap.comp <| by apply measure_preserving_prod_div_swap μ ν\n#align measure_theory.measure_preserving_div_prod MeasureTheory.measurePreservingDivProd\n#align measure_theory.measure_preserving_sub_prod MeasureTheory.measure_preserving_sub_prod\n\n/-- The map `(x, y) ↦ (xy, x⁻¹)` is measure-preserving. -/\n@[to_additive measure_preserving_add_prod_neg_right\n      \"The map `(x, y) ↦ (x + y, - x)` is measure-preserving.\"]\ntheorem measurePreservingMulProdInvRight [IsMulRightInvariant μ] [IsMulRightInvariant ν] :\n    MeasurePreserving (fun z : G × G => (z.1 * z.2, z.1⁻¹)) (μ.Prod ν) (μ.Prod ν) :=\n  by\n  convert(measure_preserving_prod_div_swap ν μ).comp (measure_preserving_prod_mul_swap_right μ ν)\n  ext1 ⟨x, y⟩\n  simp_rw [Function.comp_apply, div_mul_eq_div_div_swap, div_self', one_div]\n#align measure_theory.measure_preserving_mul_prod_inv_right MeasureTheory.measurePreservingMulProdInvRight\n#align measure_theory.measure_preserving_add_prod_neg_right MeasureTheory.measure_preserving_add_prod_neg_right\n\nend RightInvariant\n\nsection QuasiMeasurePreserving\n\nvariable [HasMeasurableInv G]\n\n@[to_additive]\ntheorem quasiMeasurePreservingInvOfRightInvariant [IsMulRightInvariant μ] :\n    QuasiMeasurePreserving (Inv.inv : G → G) μ μ :=\n  by\n  rw [← μ.inv_inv]\n  exact\n    (quasi_measure_preserving_inv μ.inv).mono (inv_absolutely_continuous μ.inv)\n      (absolutely_continuous_inv μ.inv)\n#align measure_theory.quasi_measure_preserving_inv_of_right_invariant MeasureTheory.quasiMeasurePreservingInvOfRightInvariant\n#align measure_theory.quasi_measure_preserving_neg_of_right_invariant MeasureTheory.quasi_measure_preserving_neg_of_right_invariant\n\n@[to_additive]\ntheorem quasiMeasurePreservingDivLeft [IsMulLeftInvariant μ] (g : G) :\n    QuasiMeasurePreserving (fun h : G => g / h) μ μ :=\n  by\n  simp_rw [div_eq_mul_inv]\n  exact\n    (measure_preserving_mul_left μ g).QuasiMeasurePreserving.comp (quasi_measure_preserving_inv μ)\n#align measure_theory.quasi_measure_preserving_div_left MeasureTheory.quasiMeasurePreservingDivLeft\n#align measure_theory.quasi_measure_preserving_sub_left MeasureTheory.quasi_measure_preserving_sub_left\n\n@[to_additive]\ntheorem quasiMeasurePreservingDivLeftOfRightInvariant [IsMulRightInvariant μ] (g : G) :\n    QuasiMeasurePreserving (fun h : G => g / h) μ μ :=\n  by\n  rw [← μ.inv_inv]\n  exact\n    (quasi_measure_preserving_div_left μ.inv g).mono (inv_absolutely_continuous μ.inv)\n      (absolutely_continuous_inv μ.inv)\n#align measure_theory.quasi_measure_preserving_div_left_of_right_invariant MeasureTheory.quasiMeasurePreservingDivLeftOfRightInvariant\n#align measure_theory.quasi_measure_preserving_sub_left_of_right_invariant MeasureTheory.quasi_measure_preserving_sub_left_of_right_invariant\n\n@[to_additive]\ntheorem quasiMeasurePreservingDivOfRightInvariant [IsMulRightInvariant μ] :\n    QuasiMeasurePreserving (fun p : G × G => p.1 / p.2) (μ.Prod ν) μ :=\n  by\n  refine' quasi_measure_preserving.prod_of_left measurable_div (eventually_of_forall fun y => _)\n  exact (measure_preserving_div_right μ y).QuasiMeasurePreserving\n#align measure_theory.quasi_measure_preserving_div_of_right_invariant MeasureTheory.quasiMeasurePreservingDivOfRightInvariant\n#align measure_theory.quasi_measure_preserving_sub_of_right_invariant MeasureTheory.quasi_measure_preserving_sub_of_right_invariant\n\n@[to_additive]\ntheorem quasiMeasurePreservingDiv [IsMulLeftInvariant μ] :\n    QuasiMeasurePreserving (fun p : G × G => p.1 / p.2) (μ.Prod ν) μ :=\n  (quasiMeasurePreservingDivOfRightInvariant μ.inv ν).mono\n    ((absolutelyContinuousInv μ).Prod AbsolutelyContinuous.rfl) (invAbsolutelyContinuous μ)\n#align measure_theory.quasi_measure_preserving_div MeasureTheory.quasiMeasurePreservingDiv\n#align measure_theory.quasi_measure_preserving_sub MeasureTheory.quasi_measure_preserving_sub\n\n/-- A *left*-invariant measure is quasi-preserved by *right*-multiplication.\nThis should not be confused with `(measure_preserving_mul_right μ g).quasi_measure_preserving`. -/\n@[to_additive\n      \"A *left*-invariant measure is quasi-preserved by *right*-addition.\\nThis should not be confused with `(measure_preserving_add_right μ g).quasi_measure_preserving`. \"]\ntheorem quasiMeasurePreservingMulRight [IsMulLeftInvariant μ] (g : G) :\n    QuasiMeasurePreserving (fun h : G => h * g) μ μ :=\n  by\n  refine' ⟨measurable_mul_const g, absolutely_continuous.mk fun s hs => _⟩\n  rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null]; exact id\n#align measure_theory.quasi_measure_preserving_mul_right MeasureTheory.quasiMeasurePreservingMulRight\n#align measure_theory.quasi_measure_preserving_add_right MeasureTheory.quasi_measure_preserving_add_right\n\n/-- A *right*-invariant measure is quasi-preserved by *left*-multiplication.\nThis should not be confused with `(measure_preserving_mul_left μ g).quasi_measure_preserving`. -/\n@[to_additive\n      \"A *right*-invariant measure is quasi-preserved by *left*-addition.\\nThis should not be confused with `(measure_preserving_add_left μ g).quasi_measure_preserving`. \"]\ntheorem quasiMeasurePreservingMulLeft [IsMulRightInvariant μ] (g : G) :\n    QuasiMeasurePreserving (fun h : G => g * h) μ μ :=\n  by\n  have :=\n    (quasi_measure_preserving_mul_right μ.inv g⁻¹).mono (inv_absolutely_continuous μ.inv)\n      (absolutely_continuous_inv μ.inv)\n  rw [μ.inv_inv] at this\n  have :=\n    (quasi_measure_preserving_inv_of_right_invariant μ).comp\n      (this.comp (quasi_measure_preserving_inv_of_right_invariant μ))\n  simp_rw [Function.comp, mul_inv_rev, inv_inv] at this\n  exact this\n#align measure_theory.quasi_measure_preserving_mul_left MeasureTheory.quasiMeasurePreservingMulLeft\n#align measure_theory.quasi_measure_preserving_add_left MeasureTheory.quasi_measure_preserving_add_left\n\nend QuasiMeasurePreserving\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/Prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7888018252195435}}
{"text": "import data.real.basic\n\nvariables a b c d : ℝ\n\n#check mul_comm d c\n#check mul_assoc d c a\n#check two_mul d\n#check two_mul (a + d)\n\n-- BEGIN\n/- The rewrite tactic affects only the goal. The notation rw t at h \napplies the rewrite t at hypothesis h. -/\n\nexample (a b c d : ℝ) (h : c = d * a + b) (h' : b = a * d) :\n  c = 2 * a * d :=\nbegin\n  rw h' at h,\n  rw mul_comm d a at h,\n  rw ← two_mul (a * d) at h,\n  rw ← mul_assoc 2 a d at h,\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/1_rw/ex14_rw_at_h.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7888018193413243}}
{"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. `⅟2` in a ring\nlike `ℤ[1/2]` where some inverses exist but there is no general `⁻¹` operator;\nor to specify that a field has characteristic `≠ 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 * `⅟a` 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 `⅟a` to `a ⁻¹`. Otherwise, it pushes\n`⅟` inside the expression as much as possible.\n\n## Tags\n\ninvertible, inverse element, inv_of, a half, one half, a third, one third, ½, ⅓\n\n-/\n\nuniverses u\n\nvariables {α : Type u}\n\n/-- `invertible a` gives a two-sided multiplicative inverse of `a`. -/\nclass invertible [has_mul α] [has_one α] (a : α) : Type u :=\n(inv_of : α) (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 `⅟`:1034 := invertible.inv_of\n\n@[simp]\nlemma inv_of_mul_self [has_mul α] [has_one α] (a : α) [invertible a] : ⅟a * a = 1 :=\ninvertible.inv_of_mul_self\n\n@[simp]\nlemma mul_inv_of_self [has_mul α] [has_one α] (a : α) [invertible a] : a * ⅟a = 1 :=\ninvertible.mul_inv_of_self\n\n@[simp]\nlemma inv_of_mul_self_assoc [monoid α] (a b : α) [invertible a] : ⅟a * (a * b) = b :=\nby rw [←mul_assoc, inv_of_mul_self, one_mul]\n\n@[simp]\nlemma mul_inv_of_self_assoc [monoid α] (a b : α) [invertible a] : a * (⅟a * b) = b :=\nby rw [←mul_assoc, mul_inv_of_self, one_mul]\n\n@[simp]\nlemma mul_inv_of_mul_self_cancel [monoid α] (a b : α) [invertible b] : a * ⅟b * b = a :=\nby simp [mul_assoc]\n\n@[simp]\nlemma mul_mul_inv_of_self_cancel [monoid α] (a b : α) [invertible b] : a * b * ⅟b = a :=\nby simp [mul_assoc]\n\nlemma inv_of_eq_right_inv [monoid α] {a b : α} [invertible a] (hac : a * b = 1) : ⅟a = b :=\nleft_inv_eq_right_inv (inv_of_mul_self _) hac\n\nlemma invertible_unique {α : Type u} [monoid α] (a b : α) (h : a = b)\n  [invertible a] [invertible b] :\n  ⅟a = ⅟b :=\nby { apply inv_of_eq_right_inv, rw [h, mul_inv_of_self], }\n\ninstance [monoid α] (a : α) : subsingleton (invertible a) :=\n⟨ λ ⟨b, hba, hab⟩ ⟨c, hca, hac⟩, by { congr, exact left_inv_eq_right_inv hba hac } ⟩\n\n/-- An `invertible` element is a unit. -/\ndef unit_of_invertible [monoid α] (a : α) [invertible a] : units α :=\n{ val     := a,\n  inv     := ⅟a,\n  val_inv := by simp,\n  inv_val := by simp, }\n\n@[simp] lemma unit_of_invertible_val [monoid α] (a : α) [invertible a] :\n  (unit_of_invertible a : α) = a := rfl\n\n@[simp] lemma unit_of_invertible_inv [monoid α] (a : α) [invertible a] :\n  (↑(unit_of_invertible a)⁻¹ : α) = ⅟a := rfl\n\nlemma is_unit_of_invertible [monoid α] (a : α) [invertible a] : is_unit a :=\n⟨unit_of_invertible a, rfl⟩\n\n/-- Each element of a group is invertible. -/\ndef invertible_of_group [group α] (a : α) : invertible a :=\n⟨a⁻¹, inv_mul_self a, mul_inv_self a⟩\n\n@[simp] lemma inv_of_eq_group_inv [group α] (a : α) [invertible a] : ⅟a = a⁻¹ :=\ninv_of_eq_right_inv (mul_inv_self a)\n\n/-- `1` is the inverse of itself -/\ndef invertible_one [monoid α] : invertible (1 : α) :=\n⟨ 1, mul_one _, one_mul _ ⟩\n\n@[simp] lemma inv_of_one [monoid α] [invertible (1 : α)] : ⅟(1 : α) = 1 :=\ninv_of_eq_right_inv (mul_one _)\n\n/-- `-⅟a` is the inverse of `-a` -/\ndef invertible_neg [ring α] (a : α) [invertible a] : invertible (-a) :=\n⟨ -⅟a, by simp, by simp ⟩\n\n@[simp] lemma inv_of_neg [ring α] (a : α) [invertible a] [invertible (-a)] : ⅟(-a) = -⅟a :=\ninv_of_eq_right_inv (by simp)\n\n@[simp] lemma one_sub_inv_of_two [ring α] [invertible (2:α)] : 1 - (⅟2:α) = ⅟2 :=\n(is_unit_of_invertible (2:α)).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 `⅟a`. -/\ninstance invertible_inv_of [has_one α] [has_mul α] {a : α} [invertible a] : invertible (⅟a) :=\n⟨ a, mul_inv_of_self a, inv_of_mul_self a ⟩\n\n@[simp] lemma inv_of_inv_of [monoid α] {a : α} [invertible a] [invertible (⅟a)] :\n  ⅟(⅟a) = a :=\ninv_of_eq_right_inv (inv_of_mul_self _)\n\n/-- `⅟b * ⅟a` is the inverse of `a * b` -/\ndef invertible_mul [monoid α] (a b : α) [invertible a] [invertible b] : invertible (a * b) :=\n⟨ ⅟b * ⅟a, by simp [←mul_assoc], by simp [←mul_assoc] ⟩\n\n@[simp]\nlemma inv_of_mul [monoid α] (a b : α) [invertible a] [invertible b] [invertible (a * b)] :\n  ⅟(a * b) = ⅟b * ⅟a :=\ninv_of_eq_right_inv (by simp [←mul_assoc])\n\n/--\nIf `r` is invertible and `s = r`, then `s` is invertible.\n-/\ndef invertible.copy [monoid α] {r : α} (hr : invertible r) (s : α) (hs : s = r) : invertible s :=\n{ inv_of := ⅟r,\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\ntheorem commute.inv_of_right [monoid α] {a b : α} [invertible b] (h : commute a b) :\n  commute a (⅟b) :=\ncalc a * (⅟b) = (⅟b) * (b * a * (⅟b)) : by simp [mul_assoc]\n... = (⅟b) * (a * b * ((⅟b))) : by rw h.eq\n... = (⅟b) * a : by simp [mul_assoc]\n\ntheorem commute.inv_of_left [monoid α] {a b : α} [invertible b] (h : commute b a) :\n  commute (⅟b) a :=\ncalc (⅟b) * a = (⅟b) * (a * b * (⅟b)) : by simp [mul_assoc]\n... = (⅟b) * (b * a * (⅟b)) : by rw h.eq\n... = a * (⅟b) : by simp [mul_assoc]\n\nlemma commute_inv_of {M : Type*} [has_one M] [has_mul M] (m : M) [invertible m] :\n  commute m (⅟m) :=\ncalc m * ⅟m = 1       : mul_inv_of_self m\n        ... = ⅟ m * m : (inv_of_mul_self m).symm\n\nsection group_with_zero\n\nvariable [group_with_zero α]\n\nlemma nonzero_of_invertible (a : α) [invertible a] : a ≠ 0 :=\nλ ha, zero_ne_one $ calc   0 = ⅟a * a : by simp [ha]\n                         ... = 1 : inv_of_mul_self a\n\n/-- `a⁻¹` is an inverse of `a` if `a ≠ 0` -/\ndef invertible_of_nonzero {a : α} (h : a ≠ 0) : invertible a :=\n⟨ a⁻¹, inv_mul_cancel h, mul_inv_cancel h ⟩\n\n@[simp] lemma inv_of_eq_inv (a : α) [invertible a] : ⅟a = a⁻¹ :=\ninv_of_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a))\n\n@[simp] lemma inv_mul_cancel_of_invertible (a : α) [invertible a] : a⁻¹ * a = 1 :=\ninv_mul_cancel (nonzero_of_invertible a)\n\n@[simp] lemma mul_inv_cancel_of_invertible (a : α) [invertible a] : a * a⁻¹ = 1 :=\nmul_inv_cancel (nonzero_of_invertible a)\n\n@[simp] lemma div_mul_cancel_of_invertible (a b : α) [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 : α) [invertible b] : a * b / b = a :=\nmul_div_cancel a (nonzero_of_invertible b)\n\n@[simp] lemma div_self_of_invertible (a : α) [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 : α) [invertible a] [invertible b] : invertible (a / b) :=\n⟨b / a, by simp [←mul_div_assoc], by simp [←mul_div_assoc]⟩\n\n@[simp] lemma inv_of_div (a b : α) [invertible a] [invertible b] [invertible (a / b)] :\n  ⅟(a / b) = b / a :=\ninv_of_eq_right_inv (by simp [←mul_div_assoc])\n\n/-- `a` is the inverse of `a⁻¹` -/\ndef invertible_inv {a : α} [invertible a] : invertible (a⁻¹) :=\n⟨ a, by simp, by simp ⟩\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 →* S)\n  (r : R) [invertible r] :\n  invertible (f r) :=\n{ inv_of := f (⅟r),\n  inv_of_mul_self := by rw [← f.map_mul, inv_of_mul_self, f.map_one],\n  mul_inv_of_self := by rw [← f.map_mul, mul_inv_of_self, f.map_one] }\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/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.7886722681908999}}
{"text": "def injective1 (f : nat -> nat) : Prop :=\n  forall m n, f m = f n -> m = n.\n\ndef injective2 (f : nat -> nat) : Prop :=\n  forall m n, m ≠ n -> f m ≠ f n.\n\nexample : ∀ f, injective1 f ↔ injective2 f :=\nbegin\n  intro f,\n  unfold injective1,\n  unfold injective2,\n  split; intros HI m n H,\n    intros Hinv,\n    apply H,\n    apply HI,\n    assumption,\n  cases nat.decidable_eq m n,\n    have Hcontra := HI m n h,\n    contradiction,\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/na4zagin3/top-13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9591542864252023, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7886062350607846}}
{"text": "import game.series.L01defs\n\nnamespace xena \n\n-- begin hide\n-- if we want to use sigma notation, use \n-- import algebra.big_operators\n-- open_locale big_operators \n-- https://leanprover-community.github.io/mathlib_docs/algebra/big_operators.html\n-- end hide\n\n/- \nIf $\\sum a_n$ converges, then $a_n \\to 0$.\n\nWe take the approach of showing that $(S_n) → M$ then $(S_{n+1}) → M$,\nand then using the fact that $a_{n+1} = S_{n+1} - S_n$.\n-/\n\ndef kth_partial_sum (a : ℕ → ℝ) (k : ℕ) := (finset.range (k+1)).sum a\n\ndef seq_partials_over (a : ℕ → ℝ ) : ℕ → ℝ := (λ (n : ℕ), kth_partial_sum a n )\n\ndef series_converges (a : ℕ → ℝ) := is_convergent (seq_partials_over a)\n\n/- Lemma\nIf partial sum sequence of $a_n$ convergent, $a_n → 0$.\n-/\n\nlemma seqlim_0_if_sum_converges (a : ℕ → ℝ) : \n      series_converges a → is_limit a 0 :=\n\nbegin\n\nintro h,\ncases h with M Mislimit,\n\n-- shift_rule to show that shifted sequence of partial sums also tends to M\nhave fact := shift_rule (seq_partials_over a) 1 M,\nhave fact2 := iff.mp fact Mislimit,\n\n-- express `a (m+1)` using partial sums, sum_range_succ seems best way\nhave fact3 : ∀ m : ℕ, kth_partial_sum a (m+1) \n= a (m+1) +  kth_partial_sum a (m),\nintro m, from finset.sum_range_succ a (m+1),\n\n--we really want fact4, but sum_range_succ couldn't do it directly?\nhave fact4 : ∀ (m : ℕ), a (m + 1) = kth_partial_sum a (m+1) - kth_partial_sum a (m),\nintro n,              \nspecialize fact3 n,   -- do I need to do this to reorganise inside quantiifer?\nlinarith,       \n\n-- we can rewrite our goal in terms of `a` shifted by +1\nhave fact5 : is_limit a 0 ↔ is_limit (λ (m : ℕ), a (m+1)) 0,\n     from shift_rule a 1 0,\nrw fact5,\n\nhave fact6: \n(λ (n : ℕ), a (n + 1)) = λ (n: ℕ), (kth_partial_sum a (n + 1) - kth_partial_sum a n),\nexact funext fact4,  -- suggest gave me this!\n\nrw fact6,\n\nunfold seq_partials_over at Mislimit fact2, -- just for clarity\n\nhave fact7 := lim_linear \n(λ (n : ℕ), kth_partial_sum a (n + 1))\n(λ (n : ℕ), kth_partial_sum a n)\nM M 1 (-1) fact2 Mislimit,\n\nsimp at fact7,\nexact fact7,\n\nend\n\nend xena\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/series/tempLevel01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118213, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.7883746381576343}}
{"text": "import analysis.normed_space.basic\n\nuniverse u\n\nvariables {E : Type u} [add_comm_group E] [vector_space ℝ E]\n\n-- Definition of convex modified from Lean library analysis.convex\n\ndef contains_entire_segment (s: set E) (x y : E) :=\n    ∀ (a b : ℝ),\n    0 ≤ a →\n    0 ≤ b →\n    a + b = 1 →\n    a • x + b • y ∈ s\n\ndef convex (s : set E) :=\n    ∀ (x y : E),\n    x ∈ s →\n    y ∈ s →\n    contains_entire_segment s x y\n\n-- Lemma: Given sets s1 and s2 and x where x ∈ s1 ∩ s2,\n--        x ∈ s1.\nlemma intersection_left (s1 s2: set E) (x : E) : x ∈ s1 ∩ s2 → x ∈ s1 :=\nbegin\n    intro h,\n    cases h with hleft hright,\n    exact hleft\nend\n\n-- Lemma: Given sets s1 and s2 and x where x ∈ s1 ∩ s2,\n--        x ∈ s2.\nlemma intersection_right (s1 s2: set E) (x : E) : x ∈ s1 ∩ s2 → x ∈ s2 :=\nbegin\n    intro h,\n    cases h with hleft hright,\n    exact hright\nend\n\n-- Lemma: Given sets s1 and s2 and points x and y where\n--        s1 contains the entire segment between x and y and\n--        s2 contains the entire segment between x and y,\n--        s1 ∩ s2 contains the entire segment between x and y.\nlemma intersection_contains_entire_segment (s1 s2 : set E) (x y : E) :\n    contains_entire_segment s1 x y ∧ contains_entire_segment s2 x y →\n    contains_entire_segment (s1 ∩ s2) x y :=\nbegin\n    intros h a b nna nnb ab1,\n    cases h with h1 h2,\n    split,\n    {\n        exact h1 a b nna nnb ab1,\n    },\n    {\n        exact h2 a b nna nnb ab1,\n    }\nend\n\n-- Theorem: Given sets s1 and s2 where s1 and s2 are convex,\n--          s1 ∩ s2 is convex.\ntheorem intersection_convex (s1 s2 : set E) :\n    convex s1 → convex s2 → convex (s1 ∩ s2) :=\nbegin\n    -- Given convex sets s1 and s2,\n    intros hs1 hs2,\n    -- Given points p1 and p2 in s1 ∩ s2,\n    intros p1 p2 p1inter p2inter,\n    -- We want to show that every point on the path between p1 and p2 are\n    -- in s1 ∩ s2.\n    apply intersection_contains_entire_segment,\n    split,\n    -- First we show that every point on the path is in s1.\n    {\n        -- Since p1 is in s1 ∩ s2, p1 is in s1.\n        have p1s1 := intersection_left s1 s2 p1 p1inter,\n        -- Since p2 is in s1 ∩ s2, p2 is in s1.\n        have p2s1 := intersection_left s1 s2 p2 p2inter,\n        -- By the definition of convex, since s1 is convex,\n        apply hs1,\n        -- And p1 and p2 are in s1,\n        exact p1s1,\n        exact p2s1,\n        -- We have that every point on the path between p1 and p2 are in s1.\n    },\n    {\n        -- Since p1 is in s1 ∩ s2, p1 is in s2.\n        have p1s2 := intersection_right s1 s2 p1 p1inter,\n        -- Since p2 is in s1 ∩ s2, p2 is in s2.\n        have p2s2 := intersection_right s1 s2 p2 p2inter,\n        -- By the definition of convex, since s2 is convex,\n        apply hs2,\n        -- And p1 and p2 are in s2,\n        exact p1s2,\n        exact p2s2,\n        -- We have that every point on the path between p1 and p2 are in s2.\n    },\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/convex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7882522596439484}}
{"text": "/-\n  https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/barber.20paradox/near/206937100\n-/\n\nimport tactic\n\nvariables (Man : Type) (shaves : Man → Man → Prop)\n\ntheorem NoSuchBarber ( h : ∃ barber : Man,  ∀ m : Man, shaves barber m ↔ ¬ shaves m m )\n: false :=\nbegin\n  -- from the existence of such a barber, we obtain a barber and the associated hypothesis\n  obtain ⟨barber, barber_shaves_only_who_doesnt_self_shave⟩ := h, \n  -- apply the associated hypothesis to the barber (as a customer)\n  have self_shaving_dilemma := barber_shaves_only_who_doesnt_self_shave barber,\n  -- apply `(a ↔ ¬a) → false` to `shaves barber barber` as `a`\n  have dilemma_implies_false := (iff_not_self (shaves barber barber)).mp,\n  -- -- apply the theorem \"dilemma implies false\" to the fact that\n  -- -- we have proven the self-shaving dilemma\n  exact dilemma_implies_false self_shaving_dilemma,\n  -- solve_by_elim,\nend\n\n", "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/zulip/barber.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7881887388201474}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport topology.basic\n\nnoncomputable theory\n\n/-!\n# Espacios topológicos en Lean\n\nPara cualquier tipo `α : Type`,una topología en `α` está definida en la clase `topological_space`. \nEl conjunto `univ` contiene todos los elementos de un tipo.\n\n```\n@[protect_proj] class topological_space (α : Type u) :=\n(is_open        : set α → Prop) -- Qué conjuntos son abiertos en esta topología.\n(is_open_univ   : is_open univ) -- univ es abierto.\n(is_open_inter  : ∀s t, is_open s → is_open t → is_open (s ∩ t))\n-- la intersección de dos abiertos es un conjunto abierto.\n(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))\n-- la unión arbitraria de abiertos es un abierto.\n```\n-/\n\nuniverse u\n\nnamespace topological_space\n\nopen set\n\nopen_locale classical\n\nvariables (X : Type u)\n\n/-- La topología discreta es aquella en la que todo subconjunto de `X` (es decir, todo término de\n  tipo `set X`) es abierto. -/\ndef discreta : topological_space X :=\n{ is_open        := λ _ , true ,\n  is_open_univ   := trivial,\n  is_open_inter  := λ _ _ _ _, trivial,\n  is_open_sUnion := λ _ _, trivial }\n\n/-- La topología indiscreta o trivial es aquella en la que los únicos abiertos son `X` y `∅`. -/\ndef indiscreta : topological_space X :=\n{ is_open        := λ S, S = set.univ ∨ S = ∅,\n  is_open_univ   := or.inl rfl,\n  is_open_inter  := begin\n    rintros S T hS hT, \n    cases hS with hSu hSe,\n    { cases hT with hTu hTe,\n      { left,\n        rw [hSu, hTu, univ_inter] },\n      { right,\n        rw [hSu, hTe, inter_empty ], }},\n    { right,\n      rw [hSe, empty_inter] }\n  end,\n  is_open_sUnion := λ F hF,\n  begin\n    by_cases h : univ ∈ F,\n    { left,\n      rw sUnion_eq_univ_iff,\n      intros x,\n      exact ⟨univ, h, mem_univ _⟩ },\n    { right,\n      rw sUnion_eq_empty,\n      intros S hSF,\n      cases hF S hSF with hSu hSe,\n      { rw hSu at hSF,\n        exact absurd hSF h },\n      { exact hSe }}\n  end }\n\n/-- La función `id : (X, discreta) ----->  (X, indiscreta)` es continuais continuous . -/\nexample : @continuous X X (discreta X) (indiscreta X) id :=\n{ is_open_preimage := λ _ _, trivial }\n\n/-- Sin embargo, `id : (X, indiscreta) ------> (X, discreta)` no lo es. -/\nexample (x y : X) (h : x ≠ y) : ¬ @continuous X X (indiscreta X) (discreta X) id :=\nbegin\n  rw [continuous_def, not_forall],\n  use ({x} : set X) ,\n  rw [not_imp, preimage_id_eq, id.def],\n  refine ⟨trivial, _⟩,\n  change ¬ ({x} = univ ∨ {x} = ∅),\n  rw push_neg.not_or_eq,\n  refine ⟨_, singleton_ne_empty _⟩,\n  { rw [eq_univ_iff_forall, not_forall],\n    use y,\n    exact h.symm, },\nend\n\nend topological_space\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/soluciones/ejemplos_topologias.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993027, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.7881513670909485}}
{"text": "import analysis.specific_limits\nimport data.int.parity\nimport algebra.ordered_group\nattribute [instance] classical.prop_decidable\n\n/-\nLemmas from that file were hidden in my course, or restating things which\nwere proved without name in previous files.\n-/\n\nnotation `|`x`|` := abs x\n\n-- The mathlib version is unusable because it is stated in terms of ≤\nlemma ge_max_iff {α : Type*} [decidable_linear_order α] {p q r : α} : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\n/- No idea why this is not in mathlib-/\nlemma eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h,\n  apply eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\nlemma unique_limit {u l l'} : seq_limit u l → seq_limit u l' → l = l' :=\nbegin\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros ε ε_pos,\n  specialize hl (ε/2) (by linarith),\n  cases hl with N hN,\n  specialize hl' (ε/2) (by linarith),\n  cases hl' with N' hN',\n  specialize hN (max N N') (le_max_left _ _),\n  specialize hN' (max N N') (le_max_right _ _),\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring\n  ... ≤ |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  ... ≤ ε/2 + ε/2 : by linarith\n  ... = ε : by ring,\nend\n\ndef pair (n : ℤ) := ∃ k, n = 2*k\n\ndef int.odd (n : ℤ) := ∃ k, n = 2*k + 1\n\nlemma int.not_even_iff_odd {n : ℤ} : ¬ int.even n ↔ int.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 ← h },\n  exact (int.mod_add_div n 2).symm,\n  rcases h with ⟨k, rfl⟩,\n  simp [add_comm],\n  refl,\nend\n\nlemma le_of_le_add_all {x y : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\ndef upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y\n\nlemma lt_sup {A : set ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\nlemma squeeze {u v w : ℕ → ℝ} {l} (hu : seq_limit u l) (hw : seq_limit w l)\n(h : ∀ n, u n ≤ v n)\n(h' : ∀ n, v n ≤ w n) : seq_limit v l :=\nbegin\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases hw ε ε_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 ; linarith\nend\n\ndef extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m\n\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\nlemma lim_le {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\n/-\nlemma limite_infinie_pas_finie {u : ℕ → ℝ} :\n  limite_infinie_suite u → ∀ x, ¬ seq_limit u x :=\nbegin\n  -- sorry\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (inferieur_max_gauche _ _),\n  specialize hN' N₀ (inferieur_max_droite _ _),\n  rw abs_inferieur_ssi at hN,\n  linarith',\n  -- sorry\nend -/\n\nlemma inv_succ_le_all :  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    intros h ε ε_pos,\n    cases h (ε/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n    specialize hN n hn,\n    linarith,\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\nlemma limit_const (x : ℝ) : seq_limit (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\nlemma limit_of_sub_le_inv_succ {u : ℕ → ℝ} {x : ℝ} (h : ∀ n, |u n - x| ≤ 1/(n+1)) :\nseq_limit u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\nlemma limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ; linarith [@nat.one_div_pos_of_nat ℝ _ n])\n\nlemma limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\nlemma id_le_extraction {φ}: extraction φ → ∀ n, n ≤ φ 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\nlemma seq_limit_id : tendsto_infinity (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N, exact_mod_cast hn,\n  linarith,\nend\n\nlemma extraction_machine (ψ : ℕ → ℕ) (hψ : ∀ n, ψ n ≥ n) : ∃ f : ℕ → ℕ, extraction (ψ ∘ f) ∧ ∀ n, f n ≥ n :=\nbegin\n  refine ⟨λ n, nat.rec_on n 0 (λ n ih, ψ ih + 1), λ m n h, _, λ n, _⟩,\n  { induction h; dsimp [(∘)],\n    { exact hψ _ },\n    { exact lt_trans h_ih (hψ _) } },\n  { induction n, {apply le_refl},\n    exact nat.succ_le_succ (le_trans n_ih (hψ _)) }\nend\n\nvariables {u : ℕ → ℝ} {l : ℝ} {φ : ℕ → ℕ}\n\nlemma limite_extraction_si_limite (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  -- sorry\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn\n     ... ≤ φ n : id_le_extraction hφ n,\n  -- sorry\nend\n\ndef segment (a b : ℝ) := {x | a ≤ x ∧ x ≤ b}\n\nopen set filter\n\ndef cluster_point (u : ℕ → ℝ) (a : ℝ) :=\n∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a\n\nlemma bolzano_weierstrass {a b : ℝ} {u : ℕ → ℝ} (h : ∀ n, u n ∈ Icc a b) :\n∃ c ∈ Icc a b, cluster_point u c :=\nbegin\n  have cpct : compact (Icc a b),\n    exact compact_Icc,\n  have :  map u at_top ≤ principal (Icc a b),\n  { change tendsto u _ _,\n    rw tendsto_principal,\n    filter_upwards [univ_mem_sets],\n    intros n hn,\n    exact h n },\n  rcases cpct (map u at_top) (map_ne_bot at_top_ne_bot) this with ⟨c, h, h'⟩,\n  clear this,\n  use [c, h],\n  unfold cluster_point,\n  have : ∀ N, ∃ n ≥ N, |u n -c| ≤ 1/(N+1),\n    intro N,\n    rw ← forall_sets_nonempty_iff_ne_bot at h',\n    specialize h' (u '' {n | n ≥ N} ∩ {x | |x-c| ≤ 1/(N+1)}) _,\n    { simp only [set.nonempty,\n                set.mem_image,\n                set.mem_inter_eq,\n                ne.def,\n                set.mem_set_of_eq] at h',\n      rcases h' with ⟨_, ⟨n, ⟨hn, rfl⟩⟩, ineg⟩,\n      use [n, hn, ineg] },\n    { apply inter_mem_inf_sets,\n      { apply image_mem_map,\n        apply mem_at_top },\n      { have fact: (0 : ℝ) < 1/(N+2),\n          exact_mod_cast (nat.one_div_pos_of_nat : 1/((N+1 : ℕ) + 1 : ℝ) > 0),\n        apply mem_sets_of_superset (metric.ball_mem_nhds c fact),\n        intros x x_in,\n        rw [metric.mem_ball, real.dist_eq] at x_in,\n        exact le_of_lt (\n          calc |x - c| < 1 / (N + 2) : x_in\n                   ... = 1/((N+1)+1) : by { congr' 1, norm_cast }\n                   ... ≤ 1 / (N + 1) : nat.one_div_le_one_div (nat.le_succ N)),\n\n       } },\n  choose ψ hψ using this,\n  cases forall_and_distrib.mp hψ with hψ_id hψ', clear hψ,\n  rcases extraction_machine ψ hψ_id with ⟨f, hf, hf'⟩,\n  use [ψ ∘ f, hf],\n  apply limit_of_sub_le_inv_succ,\n  intros n,\n  transitivity 1/(f n + 1 : ℝ),\n  apply hψ',\n  exact nat.one_div_le_one_div (hf' n),\nend\n\nlemma not_seq_limit_of_tendstoinfinity {u : ℕ → ℝ} :\n  tendsto_infinity u → ∀ x, ¬ seq_limit u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\nopen real\n\nlemma sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :\n  ∃ x ∈ Icc a b, is_sup A x :=\nbegin\n  have b_maj :  ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : upper_bound A (Sup A),\n  { intro x,\n    apply real.le_Sup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply Sup_le_ub A hnonvide b_maj } },\n  { use Sup_maj,\n    intros y y_in,\n    rwa real.Sup_le _ hnonvide ⟨b, b_maj⟩ },\nend\n\nlemma subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn\n     ... ≤ φ n : id_le_extraction hφ n,\nend\nnamespace tactic.interactive\nopen tactic\n\nmeta def check_me : tactic unit :=\n`[ { repeat { unfold seq_limit},\n   repeat { unfold continue_en },\n   push_neg,\n   try { simp only [exists_prop] },\n   try { exact iff.rfl },\n   done } <|> fail \"Ce n'est pas cela. Essayez encore.\" ]\n\nend tactic.interactive", "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/tuto_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8807970826714614, "lm_q1q2_score": 0.7881279414635151}}
{"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 207cfac9fcd06138865b5d04f7091e46d9320432\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.Data.Int.Units\nimport Mathlib.Data.Int.Basic\n/-!\n# Associated elements and the integers\n\nThis file contains some results on equality up to units in the integers.\n\n## Main results\n\n * `Int.natAbs_eq_iff_associated`: the absolute value is equal iff integers are associated\n-/\n\n\ntheorem Int.natAbs_eq_iff_associated {a b : ℤ} : a.natAbs = b.natAbs ↔ Associated a b := by\n  refine' Int.natAbs_eq_natAbs_iff.trans _\n  constructor\n  · rintro (rfl | rfl)\n    · rfl\n    · exact ⟨-1, by simp⟩\n  · rintro ⟨u, rfl⟩\n    obtain rfl | rfl := Int.units_eq_one_or u\n    · exact Or.inl (by simp)\n    · exact Or.inr (by simp)\n#align int.nat_abs_eq_iff_associated Int.natAbs_eq_iff_associated\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/Associated.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.788058900394496}}
{"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-/\nimport data.matrix.pequiv\nimport data.matrix.block\nimport data.matrix.notation\nimport data.fintype.big_operators\nimport group_theory.perm.fin\nimport group_theory.perm.sign\nimport algebra.algebra.basic\nimport tactic.ring\nimport linear_algebra.alternating\nimport linear_algebra.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 ⬝ 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\nuniverses u v w z\nopen equiv equiv.perm finset function\n\nnamespace matrix\nopen_locale matrix big_operators\n\nvariables {m n : Type*} [decidable_eq n] [fintype n] [decidable_eq m] [fintype m]\nvariables {R : Type v} [comm_ring R]\n\nlocal notation `ε ` σ:max := ((sign σ : ℤ) : R)\n\n\n/-- `det` is an `alternating_map` in the rows of the matrix. -/\ndef det_row_alternating : alternating_map R (n → R) R n :=\n((multilinear_map.mk_pi_algebra R n R).comp_linear_map (linear_map.proj)).alternatization\n\n/-- The determinant of a matrix given by the Leibniz formula. -/\nabbreviation det (M : matrix n n R) : R :=\ndet_row_alternating M\n\nlemma det_apply (M : matrix n n R) :\n  M.det = ∑ σ : perm n, σ.sign • ∏ i, M (σ i) i :=\nmultilinear_map.alternatization_apply _ M\n\n-- This is what the old definition was. We use it to avoid having to change the old proofs below\nlemma det_apply' (M : matrix n n R) :\n  M.det = ∑ σ : perm n, ε σ * ∏ i, M (σ i) i :=\nby simp [det_apply, units.smul_def]\n\n@[simp] lemma det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i :=\nbegin\n  rw det_apply',\n  refine (finset.sum_eq_single 1 _ _).trans _,\n  { intros σ h1 h2,\n    cases not_forall.1 (mt equiv.ext h2) with x h3,\n    convert mul_zero _,\n    apply finset.prod_eq_zero,\n    { change x ∈ _, simp },\n    exact if_neg h3 },\n  { simp },\n  { simp }\nend\n\n@[simp] lemma det_zero (h : nonempty n) : det (0 : matrix n n R) = 0 :=\n(det_row_alternating : alternating_map R (n → R) R n).map_zero\n\n@[simp] lemma det_one : det (1 : matrix n n R) = 1 :=\nby rw [← diagonal_one]; simp [-diagonal_one]\n\nlemma det_is_empty [is_empty n] {A : matrix n n R} : det A = 1 :=\nby simp [det_apply]\n\n@[simp] lemma coe_det_is_empty [is_empty n] : (det : matrix n n R → R) = function.const _ 1 :=\nby { ext, exact det_is_empty, }\n\nlemma det_eq_one_of_card_eq_zero {A : matrix n n R} (h : fintype.card n = 0) : det A = 1 :=\nbegin\n  haveI : is_empty n := fintype.card_eq_zero_iff.mp h,\n  exact det_is_empty,\nend\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]\nlemma det_unique {n : Type*} [unique n] [decidable_eq n] [fintype n] (A : matrix n n R) :\n  det A = A default default :=\nby simp [det_apply, univ_unique]\n\nlemma det_eq_elem_of_subsingleton [subsingleton n] (A : matrix n n R) (k : n) :\n  det A = A k k :=\nbegin\n  convert det_unique _,\n  exact unique_of_subsingleton k\nend\n\nlemma 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 :=\nbegin\n  haveI : subsingleton n := fintype.card_le_one_iff_subsingleton.mp h.le,\n  exact det_eq_elem_of_subsingleton _ _\nend\n\nlemma det_mul_aux {M N : matrix n n R} {p : n → n} (H : ¬bijective p) :\n  ∑ σ : perm n, (ε σ) * ∏ x, (M (σ x) (p x) * N (p x) x) = 0 :=\nbegin\n  obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j,\n  { rw [← finite.injective_iff_bijective, injective] at H,\n    push_neg at H,\n    exact H },\n  exact sum_involution\n    (λ σ _, σ * swap i j)\n    (λ σ _,\n      have ∏ x, M (σ x) (p x) = ∏ x, M ((σ * swap i j) x) (p x),\n        from fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]),\n      by simp [this, sign_swap hij, prod_mul_distrib])\n    (λ σ _ _, (not_congr mul_swap_eq_iff).mpr hij)\n    (λ _ _, mem_univ _)\n    (λ σ _, mul_swap_involutive i j σ)\nend\n\n@[simp] lemma det_mul (M N : matrix n n R) : det (M ⬝ N) = det M * det N :=\ncalc det (M ⬝ N) = ∑ p : n → n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :\n  by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum,\n    fintype.pi_finset_univ]; rw [finset.sum_comm]\n... = ∑ p in (@univ (n → n) _).filter bijective, ∑ σ : perm n,\n    ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :\n  eq.symm $ sum_subset (filter_subset _ _)\n    (λ f _ hbij, det_mul_aux $ by simpa only [true_and, mem_filter, mem_univ] using hbij)\n... = ∑ τ : perm n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (τ i) * N (τ i) i) :\n  sum_bij (λ p h, equiv.of_bijective p (mem_filter.1 h).2) (λ _ _, mem_univ _)\n    (λ _ _, rfl) (λ _ _ _ _ h, by injection h)\n    (λ b _, ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩)\n... = ∑ σ : perm n, ∑ τ : perm n, (∏ i, N (σ i) i) * ε τ * (∏ j, M (τ j) (σ j)) :\n  by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]\n... = ∑ σ : perm n, ∑ τ : perm n, (((∏ i, N (σ i) i) * (ε σ * ε τ)) * ∏ i, M (τ i) i) :\n  sum_congr rfl (λ σ _, fintype.sum_equiv (equiv.mul_right σ⁻¹) _ _\n    (λ τ,\n      have ∏ j, M (τ j) (σ j) = ∏ j, M ((τ * σ⁻¹) j) j,\n        by { rw ← (σ⁻¹ : _ ≃ _).prod_comp, simp only [equiv.perm.coe_mul, apply_inv_self] },\n      have h : ε σ * ε (τ * σ⁻¹) = ε τ :=\n        calc ε σ * ε (τ * σ⁻¹) = ε ((τ * σ⁻¹) * σ) :\n          by { rw [mul_comm, sign_mul (τ * σ⁻¹)], simp only [int.cast_mul, units.coe_mul] }\n        ... = ε τ : by simp only [inv_mul_cancel_right],\n      by { simp_rw [equiv.coe_mul_right, h], simp only [this] }))\n... = det M * det N : by simp only [det_apply', finset.mul_sum, mul_comm, mul_left_comm]\n\n/-- The determinant of a matrix, as a monoid homomorphism. -/\ndef det_monoid_hom : matrix n n R →* R :=\n{ to_fun := det,\n  map_one' := det_one,\n  map_mul' := det_mul }\n\n@[simp] lemma coe_det_monoid_hom : (det_monoid_hom : matrix n n R → R) = det := rfl\n\n/-- On square matrices, `mul_comm` applies under `det`. -/\nlemma det_mul_comm (M N : matrix m m R) : det (M ⬝ N) = det (N ⬝ M) :=\nby rw [det_mul, det_mul, mul_comm]\n\n/-- On square matrices, `mul_left_comm` applies under `det`. -/\nlemma det_mul_left_comm (M N P : matrix m m R) : det (M ⬝ (N ⬝ P)) = det (N ⬝ (M ⬝ P)) :=\nby rw [←matrix.mul_assoc, ←matrix.mul_assoc, det_mul, det_mul_comm M N, ←det_mul]\n\n/-- On square matrices, `mul_right_comm` applies under `det`. -/\nlemma det_mul_right_comm (M N P : matrix m m R) :\n  det (M ⬝ N ⬝ P) = det (M ⬝ P ⬝ N) :=\nby rw [matrix.mul_assoc, matrix.mul_assoc, det_mul, det_mul_comm N P, ←det_mul]\n\nlemma det_units_conj (M : (matrix m m R)ˣ) (N : matrix m m R) :\n  det (↑M ⬝ N ⬝ ↑M⁻¹ : matrix m m R) = det N :=\nby rw [det_mul_right_comm, ←mul_eq_mul, ←mul_eq_mul, units.mul_inv, one_mul]\n\nlemma det_units_conj' (M : (matrix m m R)ˣ) (N : matrix m m R) :\n  det (↑M⁻¹ ⬝ N ⬝ ↑M : matrix m m R) = det N := det_units_conj M⁻¹ N\n\n/-- Transposing a matrix preserves the determinant. -/\n@[simp] lemma det_transpose (M : matrix n n R) : Mᵀ.det = M.det :=\nbegin\n  rw [det_apply', det_apply'],\n  refine fintype.sum_bijective _ inv_involutive.bijective _ _ _,\n  intros σ,\n  rw sign_inv,\n  congr' 1,\n  apply fintype.prod_equiv σ,\n  intros,\n  simp\nend\n\n\n/-- Permuting the columns changes the sign of the determinant. -/\nlemma det_permute (σ : perm n) (M : matrix n n R) : matrix.det (λ i, M (σ i)) = σ.sign * M.det :=\n((det_row_alternating : alternating_map R (n → R) R n).map_perm M σ).trans\n  (by simp [units.smul_def])\n\n/-- Permuting rows and columns with the same equivalence has no effect. -/\n@[simp]\nlemma det_submatrix_equiv_self (e : n ≃ m) (A : matrix m m R) :\n  det (A.submatrix e e) = det A :=\nbegin\n  rw [det_apply', det_apply'],\n  apply fintype.sum_equiv (equiv.perm_congr e),\n  intro σ,\n  rw equiv.perm.sign_perm_congr e σ,\n  congr' 1,\n  apply fintype.prod_equiv e,\n  intro i,\n  rw [equiv.perm_congr_apply, equiv.symm_apply_apply, submatrix_apply],\nend\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-/\nlemma det_reindex_self (e : m ≃ n) (A : matrix m m R) : det (reindex e e A) = det A :=\ndet_submatrix_equiv_self e.symm A\n\n/-- The determinant of a permutation matrix equals its sign. -/\n@[simp] lemma det_permutation (σ : perm n) :\n  matrix.det (σ.to_pequiv.to_matrix : matrix n n R) = σ.sign :=\nby rw [←matrix.mul_one (σ.to_pequiv.to_matrix : matrix n n R), pequiv.to_pequiv_mul_matrix,\n  det_permute, det_one, mul_one]\n\nlemma det_smul (A : matrix n n R) (c : R) : det (c • A) = c ^ fintype.card n * det A :=\ncalc det (c • A) = det (matrix.mul (diagonal (λ _, c)) A) : by rw [smul_eq_diagonal_mul]\n             ... = det (diagonal (λ _, c)) * det A        : det_mul _ _\n             ... = c ^ fintype.card n * det A             : by simp [card_univ]\n\n@[simp] lemma det_smul_of_tower {α} [monoid α] [distrib_mul_action α R] [is_scalar_tower α R R]\n  [smul_comm_class α R R] (c : α) (A : matrix n n R) :\n  det (c • A) = c ^ fintype.card n • det A :=\nby rw [←smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul]\n\nlemma det_neg (A : matrix n n R) : det (-A) = (-1) ^ fintype.card n * det A :=\nby rw [←det_smul, neg_one_smul]\n\n/-- A variant of `matrix.det_neg` with scalar multiplication by `units ℤ` instead of multiplication\nby `R`. -/\nlemma det_neg_eq_smul (A : matrix n n R) : det (-A) = (-1 : units ℤ) ^ fintype.card n • det A :=\nby rw [←det_smul_of_tower, units.neg_smul, one_smul]\n\n/-- Multiplying each row by a fixed `v i` multiplies the determinant by\nthe product of the `v`s. -/\nlemma det_mul_row (v : n → R) (A : matrix n n R) :\n  det (of $ λ i j, v j * A i j) = (∏ i, v i) * det A :=\ncalc  det (of $ λ i j, v j * A i j)\n    = det (A ⬝ diagonal v) : congr_arg det $ by { ext, simp [mul_comm] }\n... = (∏ i, v i) * det A : by rw [det_mul, det_diagonal, mul_comm]\n\n/-- Multiplying each column by a fixed `v j` multiplies the determinant by\nthe product of the `v`s. -/\nlemma det_mul_column (v : n → R) (A : matrix n n R) :\n  det (of $ λ i j, v i * A i j) = (∏ i, v i) * det A :=\nmultilinear_map.map_smul_univ _ v A\n\n@[simp] \n\nsection hom_map\n\nvariables {S : Type w} [comm_ring S]\n\nlemma _root_.ring_hom.map_det (f : R →+* S) (M : matrix n n R) :\n  f M.det = matrix.det (f.map_matrix M) :=\nby simp [matrix.det_apply', f.map_sum, f.map_prod]\n\nlemma _root_.ring_equiv.map_det (f : R ≃+* S) (M : matrix n n R) :\n  f M.det = matrix.det (f.map_matrix M) :=\nf.to_ring_hom.map_det _\n\nlemma _root_.alg_hom.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T]\n  (f : S →ₐ[R] T) (M : matrix n n S) :\n  f M.det = matrix.det (f.map_matrix M) :=\nf.to_ring_hom.map_det _\n\nlemma _root_.alg_equiv.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T]\n  (f : S ≃ₐ[R] T) (M : matrix n n S) :\n  f M.det = matrix.det (f.map_matrix M) :=\nf.to_alg_hom.map_det _\n\nend hom_map\n\n@[simp] lemma det_conj_transpose [star_ring R] (M : matrix m m R) : det (Mᴴ) = star (det M) :=\n((star_ring_end R).map_det _).symm.trans $ congr_arg star M.det_transpose\n\nsection det_zero\n/-!\n### `det_zero` section\n\nProve that a matrix with a repeated column has determinant equal to zero.\n-/\n\nlemma det_eq_zero_of_row_eq_zero {A : matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 :=\n(det_row_alternating : alternating_map R (n → R) R n).map_coord_zero i (funext h)\n\nlemma det_eq_zero_of_column_eq_zero {A : matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 :=\nby { rw ← det_transpose, exact det_eq_zero_of_row_eq_zero j h, }\n\nvariables {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 ≠ j) (hij : M i = M j) : M.det = 0 :=\n(det_row_alternating : alternating_map R (n → R) R n).map_eq_zero_of_eq M hij i_ne_j\n\n/-- If a matrix has a repeated column, the determinant will be zero. -/\ntheorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 :=\nby { rw [← det_transpose, det_zero_of_row_eq i_ne_j], exact funext hij }\n\nend det_zero\n\nlemma det_update_row_add (M : matrix n n R) (j : n) (u v : n → R) :\n  det (update_row M j $ u + v) = det (update_row M j u) + det (update_row M j v) :=\n(det_row_alternating : alternating_map R (n → R) R n).map_add M j u v\n\nlemma det_update_column_add (M : matrix n n R) (j : n) (u v : n → R) :\n  det (update_column M j $ u + v) = det (update_column M j u) + det (update_column M j v) :=\nbegin\n  rw [← det_transpose, ← update_row_transpose, det_update_row_add],\n  simp [update_row_transpose, det_transpose]\nend\n\nlemma det_update_row_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :\n  det (update_row M j $ s • u) = s * det (update_row M j u) :=\n(det_row_alternating : alternating_map R (n → R) R n).map_smul M j s u\n\nlemma det_update_column_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :\n  det (update_column M j $ s • u) = s * det (update_column M j u) :=\nbegin\n  rw [← det_transpose, ← update_row_transpose, det_update_row_smul],\n  simp [update_row_transpose, det_transpose]\nend\n\nlemma det_update_row_smul' (M : matrix n n R) (j : n) (s : R) (u : n → R) :\n  det (update_row (s • M) j u) = s ^ (fintype.card n - 1) * det (update_row M j u) :=\nmultilinear_map.map_update_smul _ M j s u\n\nlemma det_update_column_smul' (M : matrix n n R) (j : n) (s : R) (u : n → R) :\n  det (update_column (s • M) j u) = s ^ (fintype.card n - 1) * det (update_column M j u) :=\nbegin\n  rw [← det_transpose, ← update_row_transpose, transpose_smul, det_update_row_smul'],\n  simp [update_row_transpose, det_transpose]\nend\n\nsection det_eq\n\n/-! ### `det_eq` section\n\nLemmas showing the determinant is invariant under a variety of operations.\n-/\nlemma det_eq_of_eq_mul_det_one {A B : matrix n n R}\n  (C : matrix n n R) (hC : det C = 1) (hA : A = B ⬝ C) : det A = det B :=\ncalc det A = det (B ⬝ C) : congr_arg _ hA\n       ... = det B * det C : det_mul _ _\n       ... = det B : by rw [hC, mul_one]\n\nlemma det_eq_of_eq_det_one_mul {A B : matrix n n R}\n  (C : matrix n n R) (hC : det C = 1) (hA : A = C ⬝ B) : det A = det B :=\ncalc det A = det (C ⬝ B) : congr_arg _ hA\n       ... = det C * det B : det_mul _ _\n       ... = det B : by rw [hC, one_mul]\n\nlemma det_update_row_add_self (A : matrix n n R) {i j : n} (hij : i ≠ j) :\n  det (update_row A i (A i + A j)) = det A :=\nby simp [det_update_row_add,\n    det_zero_of_row_eq hij ((update_row_self).trans (update_row_ne hij.symm).symm)]\n\nlemma det_update_column_add_self (A : matrix n n R) {i j : n} (hij : i ≠ j) :\n  det (update_column A i (λ k, A k i + A k j)) = det A :=\nby { rw [← det_transpose, ← update_row_transpose, ← det_transpose A],\n     exact det_update_row_add_self Aᵀ hij }\n\nlemma det_update_row_add_smul_self (A : matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :\n  det (update_row A i (A i + c • A j)) = det A :=\nby 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\nlemma det_update_column_add_smul_self (A : matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :\n  det (update_column A i (λ k, A k i + c • A k j)) = det A :=\nby { rw [← det_transpose, ← update_row_transpose, ← det_transpose A],\n      exact det_update_row_add_smul_self Aᵀ hij c }\n\nlemma det_eq_of_forall_row_eq_smul_add_const_aux\n  {A B : matrix n n R} {s : finset n} : ∀ (c : n → R) (hs : ∀ i, i ∉ s → c i = 0)\n  (k : n) (hk : k ∉ s) (A_eq : ∀ i j, A i j = B i j + c i * B k j),\n  det A = det B :=\nbegin\n  revert B,\n  refine s.induction_on _ _,\n  { intros A c hs k hk A_eq,\n    have : ∀ i, c i = 0,\n    { intros i,\n      specialize hs i,\n      contrapose! hs,\n      simp [hs] },\n    congr,\n    ext i j,\n    rw [A_eq, this, zero_mul, add_zero], },\n  { intros i s hi ih B c hs k hk A_eq,\n    have hAi : A i = B i + c i • B k := funext (A_eq i),\n    rw [@ih (update_row B i (A i)) (function.update c i 0), hAi,\n        det_update_row_add_smul_self],\n    { exact mt (λ h, show k ∈ insert i s, from h ▸ finset.mem_insert_self _ _) hk },\n    { intros i' hi',\n      rw function.update_apply,\n      split_ifs with hi'i, { refl },\n      { exact hs i' (λ h, hi' ((finset.mem_insert.mp h).resolve_left hi'i)) } },\n    { exact λ h, hk (finset.mem_insert_of_mem h) },\n    { intros i' j',\n      rw [update_row_apply, function.update_apply],\n      split_ifs with hi'i,\n      { simp [hi'i] },\n      rw [A_eq, update_row_ne (λ (h : k = i), hk $ h ▸ finset.mem_insert_self k s)] } }\nend\n\n/-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/\nlemma det_eq_of_forall_row_eq_smul_add_const\n  {A B : matrix n n R} (c : n → R) (k : n) (hk : c k = 0)\n  (A_eq : ∀ i j, A i j = B i j + c i * B k j) :\n  det A = det B :=\ndet_eq_of_forall_row_eq_smul_add_const_aux c\n  (λ i, not_imp_comm.mp $ λ hi, finset.mem_erase.mpr\n    ⟨mt (λ (h : i = k), show c i = 0, from h.symm ▸ hk) hi, finset.mem_univ i⟩)\n  k (finset.not_mem_erase k finset.univ) A_eq\n\nlemma det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : fin (n + 1)) :\n  ∀ (c : fin n → R) (hc : ∀ (i : fin n), k < i.succ → c i = 0)\n    {M N : matrix (fin n.succ) (fin n.succ) R}\n    (h0 : ∀ j, M 0 j = N 0 j)\n    (hsucc : ∀ (i : fin n) j, M i.succ j = N i.succ j + c i * M i.cast_succ j),\n    det M = det N :=\nbegin\n  refine fin.induction _ (λ k ih, _) k;\n    intros c hc M N h0 hsucc,\n  { congr,\n    ext i j,\n    refine fin.cases (h0 j) (λ i, _) i,\n    rw [hsucc, hc i (fin.succ_pos _), zero_mul, add_zero] },\n\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 • M k.cast_succ),\n  { ext i j,\n    by_cases hi : i = k.succ,\n    { simp [hi, hM', hsucc, update_row_self] },\n    rw [update_row_ne hi, hM', update_row_ne hi] },\n\n  have k_ne_succ : k.cast_succ ≠ k.succ := (fin.cast_succ_lt_succ k).ne,\n  have M_k : M k.cast_succ = M' k.cast_succ := (update_row_ne k_ne_succ).symm,\n\n  rw [hM, M_k, det_update_row_add_smul_self M' k_ne_succ.symm, ih (function.update c k 0)],\n  { intros i hi,\n    rw [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff] at hi,\n    rw function.update_apply,\n    split_ifs with hik, { refl },\n    exact hc _ (fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (ne.symm hik))) },\n  { rwa [hM', update_row_ne (fin.succ_ne_zero _).symm] },\n  intros i j,\n  rw function.update_apply,\n  split_ifs with hik,\n  { rw [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  { 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_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff, ← not_lt]\nend\n\n/-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/\nlemma det_eq_of_forall_row_eq_smul_add_pred {n : ℕ}\n  {A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n → R)\n  (A_zero : ∀ j, A 0 j = B 0 j)\n  (A_succ : ∀ (i : fin n) j, A i.succ j = B i.succ j + c i * A i.cast_succ j) :\n  det A = det B :=\ndet_eq_of_forall_row_eq_smul_add_pred_aux (fin.last _) c\n  (λ i hi, absurd hi (not_lt_of_ge (fin.le_last _)))\n  A_zero A_succ\n\n/-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/\nlemma det_eq_of_forall_col_eq_smul_add_pred {n : ℕ}\n  {A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n → R)\n  (A_zero : ∀ i, A i 0 = B i 0)\n  (A_succ : ∀ i (j : fin n), A i j.succ = B i j.succ + c j * A i j.cast_succ) :\n  det A = det B :=\nby { rw [← det_transpose A, ← det_transpose B],\n     exact det_eq_of_forall_row_eq_smul_add_pred c A_zero (λ i j, A_succ j i) }\n\nend det_eq\n\n@[simp] lemma det_block_diagonal {o : Type*} [fintype o] [decidable_eq o] (M : o → matrix n n R) :\n  (block_diagonal M).det = ∏ k, (M k).det :=\nbegin\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 × o)) :=\n    finset.univ.filter (λ σ, ∀ x, (σ x).snd = x.snd),\n  have mem_preserving_snd : ∀ {σ : equiv.perm (n × o)},\n    σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd :=\n    λ σ, finset.mem_filter.trans ⟨λ h, h.2, λ h, ⟨finset.mem_univ _, h⟩⟩,\n  rw ← finset.sum_subset (finset.subset_univ preserving_snd) _,\n  -- And that these are in bijection with `o → equiv.perm m`.\n  rw (finset.sum_bij (λ (σ : ∀ (k : o), k ∈ finset.univ → equiv.perm n) _,\n                        prod_congr_left (λ k, σ k (finset.mem_univ k))) _ _ _ _).symm,\n  { intros σ _,\n    rw mem_preserving_snd,\n    rintros ⟨k, x⟩,\n    simp only [prod_congr_left_apply] },\n  { intros σ _,\n    rw [finset.prod_mul_distrib, ←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  { intros σ σ' _ _ eq,\n    ext x hx k,\n    simp only at eq,\n    have : ∀ k x, prod_congr_left (λ k, σ k (finset.mem_univ _)) (k, x) =\n                  prod_congr_left (λ k, σ' k (finset.mem_univ _)) (k, x) :=\n      λ 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  { intros σ hσ,\n    rw mem_preserving_snd at hσ,\n    have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd,\n    { intro x, conv_rhs { rw [← perm.apply_inv_self σ x, hσ] } },\n    have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k),\n    { intros k x,\n      ext,\n      { simp only},\n      { simp only [hσ] } },\n    have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k),\n    { intros k x,\n      conv_lhs { rw ← perm.apply_inv_self σ (x, k) },\n      ext,\n      { simp only [apply_inv_self] },\n      { simp only [hσ'] } },\n    refine ⟨λ k _, ⟨λ x, (σ (x, k)).fst, λ x, (σ⁻¹ (x, k)).fst, _, _⟩, _, _⟩,\n    { intro x,\n      simp only [mk_apply_eq, inv_apply_self] },\n    { intro x,\n      simp only [mk_inv_apply_eq, apply_inv_self] },\n    { apply finset.mem_univ },\n    { ext ⟨k, x⟩,\n      { simp only [coe_fn_mk, prod_congr_left_apply] },\n      { simp only [prod_congr_left_apply, hσ] } } },\n  { intros σ _ hσ,\n    rw mem_preserving_snd at hσ,\n    obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ,\n    rw [finset.prod_eq_zero (finset.mem_univ (k, x)), mul_zero],\n    rw [← @prod.mk.eta _ _ (σ (k, x)), block_diagonal_apply_ne],\n    exact hkx }\nend\n\n/-- The determinant of a 2×2 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] lemma det_from_blocks_zero₂₁\n  (A : matrix m m R) (B : matrix m n R) (D : matrix n n R) :\n  (matrix.from_blocks A B 0 D).det = A.det * D.det :=\nbegin\n  classical,\n  simp_rw det_apply',\n  convert\n    (sum_subset (subset_univ ((sum_congr_hom m n).range : set (perm (m ⊕ n))).to_finset) _).symm,\n  rw sum_mul_sum,\n  simp_rw univ_product_univ,\n  rw (sum_bij (λ (σ : perm m × perm n) _, equiv.sum_congr σ.fst σ.snd) _ _ _ _).symm,\n  { intros σ₁₂ h,\n    simp only [],\n    erw [set.mem_to_finset, monoid_hom.mem_range],\n    use σ₁₂,\n    simp only [sum_congr_hom_apply] },\n  { simp only [forall_prop_of_true, prod.forall, mem_univ],\n    intros σ₁ σ₂,\n    rw fintype.prod_sum_type,\n    simp_rw [equiv.sum_congr_apply, sum.map_inr, sum.map_inl, from_blocks_apply₁₁,\n      from_blocks_apply₂₂],\n    rw mul_mul_mul_comm,\n    congr,\n    rw [sign_sum_congr, units.coe_mul, int.cast_mul] },\n  { intros σ₁ σ₂ h₁ h₂,\n    dsimp only [],\n    intro h,\n    have h2 : ∀ x, perm.sum_congr σ₁.fst σ₁.snd x = perm.sum_congr σ₂.fst σ₂.snd x,\n    { intro x, 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    { exact h2.left x },\n    { exact h2.right x }},\n  { intros σ hσ,\n    erw [set.mem_to_finset, monoid_hom.mem_range] at hσ,\n    obtain ⟨σ₁₂, hσ₁₂⟩ := hσ,\n    use σ₁₂,\n    rw ←hσ₁₂,\n    simp },\n  { intros σ hσ hσn,\n    have h1 : ¬ (∀ x, ∃ y, sum.inl y = σ (sum.inl x)),\n    { by_contradiction,\n      rw set.mem_to_finset at hσn,\n      apply absurd (mem_sum_congr_hom_range_of_perm_maps_to_inl _) hσn,\n      rintros x ⟨a, ha⟩,\n      rw [←ha], exact h a },\n    obtain ⟨a, ha⟩ := not_forall.mp h1,\n    cases hx : σ (sum.inl a) with a2 b,\n    { have hn := (not_exists.mp ha) a2,\n      exact absurd hx.symm hn },\n    { rw [finset.prod_eq_zero (finset.mem_univ (sum.inl a)), mul_zero],\n      rw [hx, from_blocks_apply₂₁], refl }}\nend\n\n/-- The determinant of a 2×2 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] lemma det_from_blocks_zero₁₂\n  (A : matrix m m R) (C : matrix n m R) (D : matrix n n R) :\n  (matrix.from_blocks A 0 C D).det = A.det * D.det :=\nby rw [←det_transpose, from_blocks_transpose, transpose_zero, det_from_blocks_zero₂₁,\n  det_transpose, det_transpose]\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column 0. -/\nlemma det_succ_column_zero {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) :\n  det A = ∑ i : fin n.succ, (-1) ^ (i : ℕ) * A i 0 *\n    det (A.submatrix i.succ_above fin.succ) :=\nbegin\n  rw [matrix.det_apply, finset.univ_perm_fin_succ, ← finset.univ_product_univ],\n  simp only [finset.sum_map, equiv.to_embedding_apply, finset.sum_product, matrix.submatrix],\n  refine finset.sum_congr rfl (λ i _, fin.cases _ (λ i, _) i),\n  { simp only [fin.prod_univ_succ, matrix.det_apply, finset.mul_sum,\n        equiv.perm.decompose_fin_symm_apply_zero, fin.coe_zero, one_mul,\n        equiv.perm.decompose_fin.symm_sign, equiv.swap_self, if_true, id.def, eq_self_iff_true,\n        equiv.perm.decompose_fin_symm_apply_succ, fin.succ_above_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 : ℕ) = i.cycle_range.sign,\n  { simp [fin.sign_cycle_range] },\n  rw [fin.coe_succ, pow_succ, this, mul_assoc, mul_assoc, mul_left_comm ↑(equiv.perm.sign _),\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 (λ σ _, _),\n  rw [equiv.perm.decompose_fin.symm_sign, if_neg (fin.succ_ne_zero i)],\n  calc ((-1) * σ.sign : ℤ) • ∏ i', A (equiv.perm.decompose_fin.symm (fin.succ i, σ) i') i'\n      = ((-1) * σ.sign : ℤ) • (A (fin.succ i) 0 *\n        ∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (σ i'))) i'.succ) :\n    by simp only [fin.prod_univ_succ, fin.succ_above_cycle_range,\n      equiv.perm.decompose_fin_symm_apply_zero, equiv.perm.decompose_fin_symm_apply_succ]\n  ... = (-1) * (A (fin.succ i) 0 * (σ.sign : ℤ) •\n        ∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (σ i'))) i'.succ) :\n    by simp only [mul_assoc, mul_comm, _root_.neg_mul, one_mul, zsmul_eq_mul, neg_inj,\n      neg_smul, fin.succ_above_cycle_range],\nend\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row 0. -/\nlemma det_succ_row_zero {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) :\n  det A = ∑ j : fin n.succ, (-1) ^ (j : ℕ) * A 0 j *\n    det (A.submatrix fin.succ j.succ_above) :=\nby { rw [← det_transpose A, det_succ_column_zero],\n     refine finset.sum_congr rfl (λ i _, _),\n     rw [← det_transpose],\n     simp only [transpose_apply, transpose_submatrix, transpose_transpose] }\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row `i`. -/\nlemma det_succ_row {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) (i : fin n.succ) :\n  det A = ∑ j : fin n.succ, (-1) ^ (i + j : ℕ) * A i j *\n    det (A.submatrix i.succ_above j.succ_above) :=\nbegin\n  simp_rw [pow_add, mul_assoc, ← mul_sum],\n  have : det A = (-1 : R) ^ (i : ℕ) * (i.cycle_range⁻¹).sign * det A,\n  { calc det A = ↑((-1 : ℤˣ) ^ (i : ℕ) * (-1 : ℤˣ) ^ (i : ℕ) : ℤˣ) * det A :\n             by simp\n           ... = (-1 : R) ^ (i : ℕ) * (i.cycle_range⁻¹).sign * det A :\n             by simp [-int.units_mul_self] },\n  rw [this, mul_assoc],\n  congr,\n  rw [← det_permute, det_succ_row_zero],\n  refine finset.sum_congr rfl (λ j _, _),\n  rw [mul_assoc, matrix.submatrix, matrix.submatrix],\n  congr,\n  { rw [equiv.perm.inv_def, fin.cycle_range_symm_zero] },\n  { ext i' j',\n    rw [equiv.perm.inv_def, fin.cycle_range_symm_succ] },\nend\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column `j`. -/\nlemma det_succ_column {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) (j : fin n.succ) :\n  det A = ∑ i : fin n.succ, (-1) ^ (i + j : ℕ) * A i j *\n    det (A.submatrix i.succ_above j.succ_above) :=\nby { rw [← det_transpose, det_succ_row _ j],\n     refine finset.sum_congr rfl (λ i _, _),\n     rw [add_comm, ← det_transpose, transpose_apply, transpose_submatrix, transpose_transpose] }\n\n\n/-- Determinant of 0x0 matrix -/\n@[simp] lemma det_fin_zero {A : matrix (fin 0) (fin 0) R} : det A = 1 :=\ndet_is_empty\n\n/-- Determinant of 1x1 matrix -/\nlemma det_fin_one (A : matrix (fin 1) (fin 1) R) : det A = A 0 0  := det_unique A\n\nlemma det_fin_one_of (a : R) : det !![a] = a := det_fin_one _\n\n/-- Determinant of 2x2 matrix -/\nlemma det_fin_two (A : matrix (fin 2) (fin 2) R) :\n  det A = A 0 0 * A 1 1 - A 0 1 * A 1 0 :=\nbegin\n  simp [matrix.det_succ_row_zero, fin.sum_univ_succ],\n  ring\nend\n\n@[simp] lemma det_fin_two_of (a b c d : R) :\n  matrix.det !![a, b; c, d] = a * d - b * c :=\ndet_fin_two _\n\n/-- Determinant of 3x3 matrix -/\nlemma det_fin_three (A : matrix (fin 3) (fin 3) R) :\n  det A = 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 + A 0 2 * A 1 0 * A 2 1 - A 0 2 * A 1 1 * A 2 0 :=\nbegin\n  simp [matrix.det_succ_row_zero, fin.sum_univ_succ],\n  ring\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/determinant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7880588985341636}}
{"text": "import data.int.basic data.nat.basic data.nat.prime tactic\n\nopen int nat\n\n/- \n## Definition 1.1\nA prime number is a natural number p > 1, which is divisible only\nby the natural numbers 1 and p.\n-/\n\n/-\n## Definition 1.2\nLet m, n ∈ ℤ.\nThen n is divisible by m (m ∣ n) if there exists a ∈ ℤ such that n = ma.\n-/\n\nexample : 7 ∣ 91 := begin use 13, tauto end\nexample : (-5 : ℤ) ∣ 45 := begin use -9, tauto end\nexample : ¬ (11 ∣ 87) := begin\n  unfold has_dvd.dvd, push_neg,\n  intro c,\n  sorry\nend\nexample : ∀ x : ℤ, 1 ∣ x := begin -- Every number is dvisible by 1.\n  intro x,\n  use x, \n  simp, \nend\nexample (x : ℤ) : 2 ∣ x ↔ even x := begin -- A number is divisible by 2 iff it is even.\n  split,\n   repeat {intro h, \n           cases h with k hk,\n           use k, \n           exact hk},\nend\n\n/-\n## Theorem 1.4\nLet n : ℕ with n > 1.\nThen n has a prime factor p.\n-/\n\ntheorem prime_fact (n : ℕ) (H: 1 < n) : ∃ p, prime p → p ∣ n := begin\n  sorry, -- # Add strong induction proof from notes\nend\n\n/-\n## Theorem 1.5 - Euclid\nThere are infitely many primes.\n-/\n\ntheorem Euclid : ∀ N, ∃ p ≥ N, prime p := begin\n  intro N,\n\n  let M := factorial N + 1,\n  let p := min_fac M,\n\n  have hp : 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 H,\n    have h₁ : p ∣ factorial N + 1 := min_fac_dvd M,\n    have h₂ : p ∣ factorial N :=\n      begin\n        refine hp.dvd_factorial.mpr _,\n        exact le_of_not_ge H,\n    end,\n    have h : p ∣ 1 := (nat.dvd_add_right h₂).mp h₁,\n    \n    exact prime.not_dvd_one hp h},\n   {exact hp},\nend\n\n/-\n## Theorem 1.7\nIf n : ℕ, with n > 1, then either n is prime, or is a product of a\n(finite) sequence of primes.\n-/\n\ntheorem prime_or_product (n : ℕ) (H : n > 1) : prime n ∨ sorry /- finite sequence of primes -/ :=\nbegin\n  sorry, -- # Add strong induction proof from notes\nend\n\n/-\n## Theorem 1.8\nLet n have the prime factorisations\n      n = p₁ × ... × p_r = q₁ × ... × q_s\nThen every prime occurs equally often in both factorisations (and so r = s)\n-/\n\n-- # No clue how to put this into code", "meta": {"author": "amos578", "repo": "Lean", "sha": "30de0075bd0e7310604a574921b9f1a59cb60b14", "save_path": "github-repos/lean/amos578-Lean", "path": "github-repos/lean/amos578-Lean/Lean-30de0075bd0e7310604a574921b9f1a59cb60b14/src/1001 Term 2/101 Prime Numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897475985937, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7880242757946122}}
{"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\n/-\n\n# Commutative algebra\n\nI find this quite a joy to do in Lean.\n\nKeith Conrad has some notes on Noetherian rings here:\n\nhttps://kconrad.math.uconn.edu/blurbs/ringtheory/noetherian-ring.pdf\n\nIn this section I prove some of the results which he discusses.\n\n## Noetherian rings\n\nA commutative ring is Noetherian if every ideal is finitely-generated.\nNoetherian-ness is a very weak finiteness condition which is satisfied by\nmany rings which show up naturally in algebra, number theory and and geometry.\nLean has several equivalent standard criteria for being Noetherian. Let's\nuse one of them to prove Theorem 3.2 in Conrad's notes: a surjective\nmap from a Noetherian ring to itself is injective (note that this\nis a ring-theoretic analogue of the set-theoretic result that a surjective\nmap from a finite set to itself is injective.)\n\n-/\n\nopen function\n\nexample (R : Type) [comm_ring R] [is_noetherian_ring R]\n  (φ : R →+* R) (hφsurj : surjective φ) : injective φ :=\nbegin\n  -- Here's the proof in Conrad's notes.\n  -- For `n` a natural number, define `Kₙ` to be the kernel of `φ ∘ φ ∘ φ ∘ ⋯ φ : R →+* R`,\n  -- where we iterate `φ` `n` times. Of course in Lean `K` is a function `ℕ → ideal R`.  \n  -- The ideals Kₙ satisfy Kₙ ⊆ Kₙ₊₁.\n  -- (for if x ∈ Kₙ\n  -- then φⁿ(x) = 0\n  -- so φⁿ⁺¹(x) = φ(0)=0\n  -- so x ∈ Kₙ₊₁)\n  -- Hence K is a monotone function.\n  -- So by Noetherian-ness of `R`, there exists `n` such that `Kₙ=Kₙ₊₁=Kₙ₊₂=…` \n  -- It suffices to prove that every element of ker(φ) is 0\n  -- so say r ∈ ker(φ)\n  -- and let's prove r=0\n  -- For all naturals m, The map φ^m is surjective\n  -- (by an easy induction)\n  -- so r = φ^n r' for some r' ∈ R\n  -- Thus 0 = φ(r)=φ^{n+1}(r')\n  -- Therefore r' ∈ ker(φ^{n+1})\n  -- ...=ker(φ^n)\n  -- and hence r=φ^n(r')=0 as required\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/section16commutative_algebra/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7879636670237737}}
{"text": "import data.real.basic\n\n/-\nOne of the earliest kind of proofs one encounters while learning mathematics is proving by\na calculation. It may not sound like a proof, but this is actually using lemmas expressing\nproperties of operations on numbers. It also uses the fundamental property of equality: if two\nmathematical objects A and B are equal then, in any statement involving A, one can replace A\nby B. This operation is called rewriting, and the Lean \"tactic\" for this is `rw`.\n\nIn the following exercises, we will use the following two lemmas:\n  mul_assoc a b c : a * b * c = a * (b * c)\n  mul_comm a b : a*b = b*a\n\nHence the command\n  rw mul_assoc a b c,\nwill replace a*b*c by a*(b*c) in the current goal.\n\nIn order to replace backward, we use\n  rw ← mul_assoc a b c,\nreplacing a*(b*c) by a*b*c in the current goal.\n\nOf course we don't want to constantly invoke those lemmas, and we will eventually introduce\nmore powerful solutions.\n-/\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 0001\nexample (a b c : ℝ) : (c * b) * a = b * (a * c) :=\nbegin\n  rw mul_comm c b,\n  rw mul_assoc b c a,\n  rw mul_comm a c\nend\n\n-- 0002\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw <- mul_assoc a b c,\n  rw mul_comm a b,\n  rw mul_assoc b a c\nend\n\n/-\nNow let's return to the preceding example to experiment with what happens\nif we don't give arguments to mul_assoc or mul_comm.\nFor instance, you can start the next proof with\n  rw ← mul_assoc,\nTry to figure out what happens.\n-/\n\n-- 0003\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw <- mul_assoc,\n  rw mul_comm a b,\n  rw mul_assoc\nend\n\n/-\nWe can also perform rewriting in an assumption of the local context, using for instance\n  rw mul_comm a b at hyp,\nin order to replace a*b by b*a in assumption hyp.\n\nThe next example will use a third lemma:\n  two_mul a : 2*a = a + a\n\nAlso we use the `exact` tactic, which allows to provide a direct proof term.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a*d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp, -- Our assumption hyp is now exactly what we have to prove\nend\n\n/-\nAnd the next one can use:\n  sub_self x : x - x = 0\n-/\n\n-- 0004\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  rw mul_comm a b at hyp',\n  rw ← hyp' at hyp,\n  rw sub_self d at hyp,\n  exact hyp\nend\n\n/-\nWhat is written in the two preceding example is very far away from what we would write on\npaper. Let's now see how to get a more natural layout.\nInside each pair of curly braces below, the goal is to prove equality with the preceding line.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b    : by { rw hyp }\n     ... = d*a + a*d  : by { rw hyp' }\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\n/-\nLet's note there is no comma at the end of each line of calculation. `calc` is really one\ncommand, and the comma comes only after it's fully done.\n\nFrom a practical point of view, when writing such a proof, it is convenient to:\n* pause the tactic state view update in VScode by clicking the Pause icon button\n  in the top right corner of the Lean Goal buffer\n* write the full calculation, ending each line with \": by {}\"\n* resume tactic state update by clicking the Play icon button and fill in proofs between\n  curly braces.\n\nLet's return to the other example using this method.\n-/\n\n-- 0005\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  calc c = b*a - d : by {rw hyp}\n      ... = b*a - a*b : by {rw hyp'}\n      ... = b*a - b*a : by {rw mul_comm b a}\n      ... = 0 : by {rw sub_self (b*a)}\nend\n\n/-\nThe preceding proofs have exhausted our supply of \"mul_comm\" patience. Now it's time\nto get the computer to work harder. The `ring` tactic will prove any goal that follows by\napplying only the axioms of commutative (semi-)rings, in particular commutativity and\nassociativity of addition and multiplication, as well as distributivity.\n\nWe also note that curly braces are not necessary when we write a single tactic proof, so\nlet's get rid of them.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b   : by rw hyp\n     ... = d*a + a*d : by rw hyp'\n     ... = 2*a*d     : by ring,\nend\n\n/-\nOf course we can use `ring` outside of `calc`. Let's do the next one in one line.\n-/\n\n-- 0006\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) := by ring\n\n/-\nThis is too much fun. Let's do it again.\n-/\n\n-- 0007\nexample (a b : ℝ) : (a + b) + a = 2*a + b := by ring\n\n/-\nMaybe this is cheating. Let's try to do the next computation without ring.\nWe could use:\npow_two x : x^2 = x*x\nmul_sub a b c : a*(b-c) = a*b - a*c\nadd_mul a b c : (a+b)*c = a*c + b*c\nadd_sub a b c : a + (b - c) = (a + b) - c\nsub_sub a b c : a - b - c = a - (b + c)\nadd_zero a : a + 0 = a\n-/\n\n-- 0008\nexample (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 := by ring\n\n/- Let's stick to ring in the end. -/\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/01_equality_rewriting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8791467548438126, "lm_q1q2_score": 0.7879364910872536}}
{"text": "-- Encadenamiento_de_ecuaciones.lean\n-- Encadenamiento de ecuaciones.\n-- José A. Alonso Jiménez\n-- Sevilla, 12 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- En esta relación comentan distintas pruebas con Lean de una igualdad\n-- con productos de números reales. La primera es por reescritura usando\n-- las propiedades asociativa y conmutativa, La segunda es con\n-- encadenamiento de ecuaciones. Las restantes son automáticas. \n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a, b, c y d números reales. Demostrar que si \n--    c = d * a + b  \n--    b = a + d\n-- entonces c = 2 * a * d. \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables (a b c d : ℝ)\n\n-- 1ª demostración (reescribiendo las hipótesis)\n-- =============================================\n\nexample \n  (h1 : c = d * a + b) \n  (h2 : b = a * d) \n  : c = 2 * a * d :=\nbegin\n  rw h2 at h1,\n  rw mul_comm at h1,\n  rw ← two_mul (a * d) at h1,\n  rw ← mul_assoc at h1,\n  exact h1,\nend\n\n-- Prueba:\n/-\n  a b c d : ℝ,\n  h1 : c = d * a + b,\n  h2 : b = a * d\n  ⊢ c = 2 * a * d\nrw h2 at h1,\n  h1 : c = d * a + a * d\n  ⊢ c = 2 * a * d\nrw mul_comm at h1,\n  h1 : c = a * d + a * d\n  ⊢ c = 2 * a * d\nrw ← two_mul (a * d) at h1,\n  h1 : c = 2 * (a * d)\n  ⊢ c = 2 * a * d\nrw ← mul_assoc at h1,\n  h1 : c = 2 * a * d\n  ⊢ c = 2 * a * d\nexact h1,\n  no goals\n-/\n\n-- Comentarios:\n-- + Se han usado los siguientes lemas\n--   + mul_comm : ∀ (a b : ℝ), a * b = b * a \n--   + mul_assoc : ∀ (a b c : ℝ), a * b * c = a * (b * c)   \n--   + two_mul : 2 * a = a + a\n\n-- 2ª demostración (encadenamiento de ecuaciones)\n-- ==============================================\n\nexample \n  (h1 : c = d * a + b) \n  (h2 : b = a * d) \n  : c = 2 * a * d :=\nbegin\n  calc\n    c   = d * a + b     : by exact h1 \n    ... = d * a + a * d : by rw h2 \n    ... = a * d + a * d : by rw mul_comm \n    ... = 2 * (a * d)   : by rw two_mul (a * d) \n    ... = 2 * a * d     : by rw mul_assoc,\nend\n\n-- 3ª demostración (encadenamiento de ecuaciones)\n-- ==============================================\n\nexample \n  (h1 : c = d * a + b) \n  (h2 : b = a * d) \n  : c = 2 * a * d :=\nbegin\n  calc\n    c   = d * a + b     : by exact h1 \n    ... = d * a + a * d : by rw h2\n    ... = 2 * a * d     : by ring,\nend\n\n-- 4ª demostración (automática con linarith)\n-- =========================================\n\nexample \n  (h1 : c = d * a + b) \n  (h2 : b = a * d) \n  : c = 2 * a * d :=\nby 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/1_Igualdad/Encadenamiento_de_ecuaciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.7878042156581322}}
{"text": "import data.real.basic data.set.basic\nopen set \n/-5. Let S = R be the real numbers, and let G be a subset of R. Define a binary relation ∼ on S by a ∼ b if and only if b − a ∈ G.\n(i) Say 0 ∈ G. Prove that ∼ is reflexive.\n(ii) Say G has the property that g ∈ G implies −g ∈ G. Check that ∼ symmetric.\n(iii) Say G has the property that if g ∈ G and h ∈ G then g+h ∈ G. Check that ∼ is transitive. \n(iv) If you can be bothered, also check that the converse to all these statements are true as\nwell (i.e. check that if ∼ is reflexive then 0 ∈ G, if ∼ is symmetric then g ∈ G implies −g ∈ G etc).\nRemark: Subsets G of R with these three properties in parts (i)–(iii) are called subgroups of R, or, more precisely, additive subgroups (the group law being addition). So this question really proves that the binary relation defined in the question is an equivalence relation if and only if G is a subgroup of R. You’ll learn about groups and subgroups next term in M1P2.-/\n\n-- really unsure on equivalence relations\nvariable {G : set ℝ}\nvariables {g h a b : G}\n\ndef r1 (a b : ℝ): Prop := b - a ∈ G\n\nlocal notation `∼` := r1\n\n--theorem Q0901i : (0 : ℝ) ∈ G → reflexive ∼ := sorry \n\n--theorem Q0901ii (hp : g ∈ G → (-1)*g ∈ G) : symmetric ∼ := sorry \n\n--theorem Q0901iii (hp : g ∈ G ∧ h ∈ G → h + g ∈ G) : transitive ∼ := sorry\n\n--theorem Q0901iva (hp : reflexive ∼) : (0 : ℝ) ∈ G := sorry \n\n--theorem Q0901ivb (hp : symmetric ∼) : g ∈ G → (-1)*g ∈ G:= sorry\n\n--theorem Q0901ivc (hp : transitive ∼) : g ∈ G ∧ h ∈ G → h + g ∈ G := 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/PB0901/Q0901.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7875862967124574}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones\n--    1. Importar la teoría de exponeciales y logaritmos.\n--    2. Abrir la teoría de los reales\n--    3. Declarar a, b, c, d y e como variables sobre los reales.\n-- ----------------------------------------------------------------------\n\nimport analysis.special_functions.log.basic -- 1\nopen real                                   -- 2\nvariables a b c d e : ℝ                     -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que si\n--    d ≤ e\n-- entonces\n--    c + exp (a + d) ≤ c + exp (a + e)\n-- ----------------------------------------------------------------------\n\nexample\n  (h₀ : d ≤ e)\n  : c + exp (a + d) ≤ c + exp (a + e) :=\nbegin\n  apply add_le_add,\n   apply le_refl,\n  apply exp_le_exp.mpr,\n  apply add_le_add,\n   apply le_refl,\n  exact h₀,\nend\n\n-- El desarrollo de la prueba es\n--\n--    a c d e : ℝ,\n--    h₀ : d ≤ e\n--    ⊢ c + (a + d).exp ≤ c + (a + e).exp\n-- apply add_le_add,\n-- |   ⊢ c ≤ c\n-- | apply le_refl,\n--    ⊢ (a + d).exp ≤ (a + e).exp\n-- apply exp_le_exp.mpr,\n--    ⊢ a + d ≤ a + e\n-- apply add_le_add,\n-- |    ⊢ a ≤ a\n-- | apply le_refl,\n--    ⊢ d ≤ e\n-- exact h₀,\n--    no goals\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que\n--    0 < 1\n-- ----------------------------------------------------------------------\n\nexample : (0 : ℝ) < 1 :=\nby norm_num\n\n-- Nota: La táctica norm_num normaliza expresiones numéricas. Ver\n-- https://bit.ly/3hoJMgQ\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que si\n--    a ≤ b\n-- entonces\n--    log (1 + exp a) ≤ log (1 + exp b) :=\n-- ----------------------------------------------------------------------\n\nexample\n  (h : a ≤ b)\n  : log (1 + exp a) ≤ log (1 + exp b) :=\nbegin\n  have h₀ : 0 < 1 + exp a,\n  { apply add_pos,\n    norm_num,\n    apply exp_pos, },\n  have h₁ : 0 < 1 + exp b,\n  { apply add_pos,\n    norm_num,\n    apply exp_pos },\n  apply (log_le_log h₀ h₁).mpr,\n  apply add_le_add,\n   apply le_refl,\n  apply exp_le_exp.mpr h,\nend\n\n-- El desarrollo de la prueba es\n--\n--    a b : ℝ,\n--    h : a ≤ b\n--    ⊢ (1 + a.exp).log ≤ (1 + b.exp).log\n-- have h₀ : 0 < 1 + exp a,\n-- |    ⊢ 0 < 1 + a.exp\n-- | apply add_pos,\n-- |    ⊢ 0 < 1\n-- | norm_num,\n-- |    ⊢ 0 < a.exp\n-- | apply exp_pos },\n--    a b : ℝ,\n--    h : a ≤ b,\n--    h₀ : 0 < 1 + a.exp\n--    ⊢ (1 + a.exp).log ≤ (1 + b.exp).log\n-- have h₁ : 0 < 1 + exp b,\n--    ⊢ 0 < 1 + b.exp\n-- | apply add_pos,\n-- |    ⊢ 0 < 1\n-- | norm_num,\n-- |    0 < b.exp\n-- | apply exp_pos },\n--    a b : ℝ,\n--    h : a ≤ b,\n--    h₀ : 0 < 1 + a.exp,\n--    h₁ : 0 < 1 + b.exp\n--    ⊢ (1 + a.exp).log ≤ (1 + b.exp).log\n-- apply (log_le_log h₀ h₁).mpr,\n--    ⊢ 1 + a.exp ≤ 1 + b.exp\n-- apply add_le_add,\n-- |    ⊢ 1 ≤ 1\n-- | apply le_refl,\n--    ⊢ a.exp ≤ b.exp\n-- apply exp_le_exp.mpr h,\n--    no goals\n\n-- Comentario. Los lemas empleados son\n-- #check (add_le_add : a ≤ b → c ≤ d → a + c ≤ b + d)\n-- #check (le_refl : ∀ (a : real), a ≤ a)\n-- #check (exp_le_exp : exp a ≤ exp b ↔ a ≤ b)\n-- #check (add_pos : 0 < a → 0 < b → 0 < a + b)\n-- #check (exp_pos : ∀ a, 0 < exp a)\n-- #check (log_le_log : 0 < a → 0 < b → (log a ≤ log b ↔ a ≤ 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/Ejercicio_sobre_desigualdades.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7875462269406136}}
{"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.martingale.upcrossing\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.Probability.Process.HittingTime\nimport Mathbin.Probability.Martingale.Basic\n\n/-!\n\n# Doob's upcrossing estimate\n\nGiven a discrete real-valued submartingale $(f_n)_{n \\in \\mathbb{N}}$, denoting $U_N(a, b)$ the\nnumber of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing\nestimate (also known as Doob's inequality) states that\n$$(b - a) \\mathbb{E}[U_N(a, b)] \\le \\mathbb{E}[(f_N - a)^+].$$\nDoob's upcrossing estimate is an important inequality and is central in proving the martingale\nconvergence theorems.\n\n## Main definitions\n\n* `measure_theory.upper_crossing_time a b f N n`: is the stopping time corresponding to `f`\n  crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is\n  taken to be `N`).\n* `measure_theory.lower_crossing_time a b f N n`: is the stopping time corresponding to `f`\n  crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is\n  taken to be `N`).\n* `measure_theory.upcrossing_strat a b f N`: is the predictable process which is 1 if `n` is\n  between a consecutive pair of lower and upper crossing and is 0 otherwise. Intuitively\n  one might think of the `upcrossing_strat` as the strategy of buying 1 share whenever the process\n  crosses below `a` for the first time after selling and selling 1 share whenever the process\n  crosses above `b` for the first time after buying.\n* `measure_theory.upcrossings_before a b f N`: is the number of times `f` crosses from below `a` to\n  above `b` before time `N`.\n* `measure_theory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above\n  `b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`.\n\n## Main results\n\n* `measure_theory.adapted.is_stopping_time_upper_crossing_time`: `upper_crossing_time` is a\n  stopping time whenever the process it is associated to is adapted.\n* `measure_theory.adapted.is_stopping_time_lower_crossing_time`: `lower_crossing_time` is a\n  stopping time whenever the process it is associated to is adapted.\n* `measure_theory.submartingale.mul_integral_upcrossings_before_le_integral_pos_part`: Doob's\n  upcrossing estimate.\n* `measure_theory.submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality\n  obtained by taking the supremum on both sides of Doob's upcrossing estimate.\n\n### References\n\nWe mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021]\n\n-/\n\n\nopen TopologicalSpace Filter\n\nopen NNReal ENNReal MeasureTheory ProbabilityTheory BigOperators Topology\n\nnamespace MeasureTheory\n\nvariable {Ω ι : Type _} {m0 : MeasurableSpace Ω} {μ : Measure Ω}\n\n/-!\n\n## Proof outline\n\nIn this section, we will denote $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to\nabove $b$ before time $N$.\n\nTo define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses\nbelow $a$ and above $b$. Namely, we define\n$$\n  \\sigma_n := \\inf \\{n \\ge \\tau_n \\mid f_n \\le a\\} \\wedge N;\n$$\n$$\n  \\tau_{n + 1} := \\inf \\{n \\ge \\sigma_n \\mid f_n \\ge b\\} \\wedge N.\n$$\nThese are `lower_crossing_time` and `upper_crossing_time` in our formalization which are defined\nusing `measure_theory.hitting` allowing us to specify a starting and ending time.\nThen, we may simply define $U_N(a, b) := \\sup \\{n \\mid \\tau_n < N\\}$.\n\nFixing $a < b \\in \\mathbb{R}$, we will first prove the theorem in the special case that\n$0 \\le f_0$ and $a \\le f_N$. In particular, we will show\n$$\n  (b - a) \\mathbb{E}[U_N(a, b)] \\le \\mathbb{E}[f_N].\n$$\nThis is `measure_theory.integral_mul_upcrossings_before_le_integral` in our formalization.\n\nTo prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$\n(i.e. $(C_{n + 1})$ is adapted), $(C \\bullet f)_n := \\sum_{k \\le n} C_{k + 1}(f_{k + 1} - f_k)$ is\na submartingale if $(f_n)$ is.\n\nDefine $C_n := \\sum_{k \\le n} \\mathbf{1}_{[\\sigma_k, \\tau_{k + 1})}(n)$. It is easy to see that\n$(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$,\n$(1 - C) \\bullet f$ is also a submartingale. Thus, by the submartingale property,\n$0 \\le \\mathbb{E}[((1 - C) \\bullet f)_0] \\le \\mathbb{E}[((1 - C) \\bullet f)_N]$ implying\n$$\n  \\mathbb{E}[(C \\bullet f)_N] \\le \\mathbb{E}[(1 \\bullet f)_N] = \\mathbb{E}[f_N] - \\mathbb{E}[f_0].\n$$\n\nFurthermore,\n\\begin{align}\n    (C \\bullet f)_N & =\n      \\sum_{n \\le N} \\sum_{k \\le N} \\mathbf{1}_{[\\sigma_k, \\tau_{k + 1})}(n)(f_{n + 1} - f_n)\\\\\n    & = \\sum_{k \\le N} \\sum_{n \\le N} \\mathbf{1}_{[\\sigma_k, \\tau_{k + 1})}(n)(f_{n + 1} - f_n)\\\\\n    & = \\sum_{k \\le N} (f_{\\sigma_k + 1} - f_{\\sigma_k} + f_{\\sigma_k + 2} - f_{\\sigma_k + 1}\n      + \\cdots + f_{\\tau_{k + 1}} - f_{\\tau_{k + 1} - 1})\\\\\n    & = \\sum_{k \\le N} (f_{\\tau_{k + 1}} - f_{\\sigma_k})\n      \\ge \\sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b)\n\\end{align}\nwhere the inequality follows since for all $k < U_N(a, b)$,\n$f_{\\tau_{k + 1}} - f_{\\sigma_k} \\ge b - a$ while for all $k > U_N(a, b)$,\n$f_{\\tau_{k + 1}} = f_{\\sigma_k} = f_N$ and\n$f_{\\tau_{U_N(a, b) + 1}} - f_{\\sigma_{U_N(a, b)}} = f_N - a \\ge 0$. Hence, we have\n$$\n  (b - a) \\mathbb{E}[U_N(a, b)] \\le \\mathbb{E}[(C \\bullet f)_N]\n  \\le \\mathbb{E}[f_N] - \\mathbb{E}[f_0] \\le \\mathbb{E}[f_N],\n$$\nas required.\n\nTo obtain the general case, we simply apply the above to $((f_n - a)^+)_n$.\n\n-/\n\n\n/-- `lower_crossing_time_aux a f c N` is the first time `f` reached below `a` after time `c` before\ntime `N`. -/\nnoncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) :\n    Ω → ι :=\n  hitting f (Set.Iic a) c N\n#align measure_theory.lower_crossing_time_aux MeasureTheory.lowerCrossingTimeAux\n\n/-- `upper_crossing_time a b f N n` is the first time before time `N`, `f` reaches\nabove `b` after `f` reached below `a` for the `n - 1`-th time. -/\nnoncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)\n    (N : ι) : ℕ → Ω → ι\n  | 0 => ⊥\n  | n + 1 => fun ω =>\n    hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upper_crossing_time n ω) N ω) N ω\n#align measure_theory.upper_crossing_time MeasureTheory.upperCrossingTime\n\n/-- `lower_crossing_time a b f N n` is the first time before time `N`, `f` reaches\nbelow `a` after `f` reached above `b` for the `n`-th time. -/\nnoncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)\n    (N : ι) (n : ℕ) : Ω → ι := fun ω => hitting f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω\n#align measure_theory.lower_crossing_time MeasureTheory.lowerCrossingTime\n\nsection\n\nvariable [Preorder ι] [OrderBot ι] [InfSet ι]\n\nvariable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω}\n\n@[simp]\ntheorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ :=\n  rfl\n#align measure_theory.upper_crossing_time_zero MeasureTheory.upperCrossingTime_zero\n\n@[simp]\ntheorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hitting f (Set.Iic a) ⊥ N :=\n  rfl\n#align measure_theory.lower_crossing_time_zero MeasureTheory.lowerCrossingTime_zero\n\ntheorem upperCrossingTime_succ :\n    upperCrossingTime a b f N (n + 1) ω =\n      hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω :=\n  by rw [upper_crossing_time]\n#align measure_theory.upper_crossing_time_succ MeasureTheory.upperCrossingTime_succ\n\ntheorem upperCrossingTime_succ_eq (ω : Ω) :\n    upperCrossingTime a b f N (n + 1) ω =\n      hitting f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω :=\n  by\n  simp only [upper_crossing_time_succ]\n  rfl\n#align measure_theory.upper_crossing_time_succ_eq MeasureTheory.upperCrossingTime_succ_eq\n\nend\n\nsection ConditionallyCompleteLinearOrderBot\n\nvariable [ConditionallyCompleteLinearOrderBot ι]\n\nvariable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω}\n\ntheorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≤ N :=\n  by\n  cases n\n  · simp only [upper_crossing_time_zero, Pi.bot_apply, bot_le]\n  · simp only [upper_crossing_time_succ, hitting_le]\n#align measure_theory.upper_crossing_time_le MeasureTheory.upperCrossingTime_le\n\n@[simp]\ntheorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ :=\n  eq_bot_iff.2 upperCrossingTime_le\n#align measure_theory.upper_crossing_time_zero' MeasureTheory.upperCrossingTime_zero'\n\ntheorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≤ N := by\n  simp only [lower_crossing_time, hitting_le ω]\n#align measure_theory.lower_crossing_time_le MeasureTheory.lowerCrossingTime_le\n\ntheorem upperCrossingTime_le_lowerCrossingTime :\n    upperCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N n ω := by\n  simp only [lower_crossing_time, le_hitting upper_crossing_time_le ω]\n#align measure_theory.upper_crossing_time_le_lower_crossing_time MeasureTheory.upperCrossingTime_le_lowerCrossingTime\n\ntheorem lowerCrossingTime_le_upperCrossingTime_succ :\n    lowerCrossingTime a b f N n ω ≤ upperCrossingTime a b f N (n + 1) ω :=\n  by\n  rw [upper_crossing_time_succ]\n  exact le_hitting lower_crossing_time_le ω\n#align measure_theory.lower_crossing_time_le_upper_crossing_time_succ MeasureTheory.lowerCrossingTime_le_upperCrossingTime_succ\n\ntheorem lowerCrossingTime_mono (hnm : n ≤ m) :\n    lowerCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N m ω :=\n  by\n  suffices Monotone fun n => lower_crossing_time a b f N n ω by exact this hnm\n  exact\n    monotone_nat_of_le_succ fun n =>\n      le_trans lower_crossing_time_le_upper_crossing_time_succ\n        upper_crossing_time_le_lower_crossing_time\n#align measure_theory.lower_crossing_time_mono MeasureTheory.lowerCrossingTime_mono\n\ntheorem upperCrossingTime_mono (hnm : n ≤ m) :\n    upperCrossingTime a b f N n ω ≤ upperCrossingTime a b f N m ω :=\n  by\n  suffices Monotone fun n => upper_crossing_time a b f N n ω by exact this hnm\n  exact\n    monotone_nat_of_le_succ fun n =>\n      le_trans upper_crossing_time_le_lower_crossing_time\n        lower_crossing_time_le_upper_crossing_time_succ\n#align measure_theory.upper_crossing_time_mono MeasureTheory.upperCrossingTime_mono\n\nend ConditionallyCompleteLinearOrderBot\n\nvariable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω}\n\ntheorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) :\n    stoppedValue f (lowerCrossingTime a b f N n) ω ≤ a :=\n  by\n  obtain ⟨j, hj₁, hj₂⟩ :=\n    (hitting_le_iff_of_lt _ (lt_of_le_of_ne lower_crossing_time_le h)).1 le_rfl\n  exact stopped_value_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lower_crossing_time_le⟩, hj₂⟩\n#align measure_theory.stopped_value_lower_crossing_time MeasureTheory.stoppedValue_lowerCrossingTime\n\ntheorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) :\n    b ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω :=\n  by\n  obtain ⟨j, hj₁, hj₂⟩ :=\n    (hitting_le_iff_of_lt _ (lt_of_le_of_ne upper_crossing_time_le h)).1 le_rfl\n  exact stopped_value_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩\n#align measure_theory.stopped_value_upper_crossing_time MeasureTheory.stoppedValue_upperCrossingTime\n\ntheorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b)\n    (hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) :\n    upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω :=\n  by\n  refine'\n    lt_of_le_of_ne upper_crossing_time_le_lower_crossing_time fun h =>\n      not_le.2 hab <| le_trans _ (stopped_value_lower_crossing_time hn)\n  simp only [stopped_value]\n  rw [← h]\n  exact stopped_value_upper_crossing_time (h.symm ▸ hn)\n#align measure_theory.upper_crossing_time_lt_lower_crossing_time MeasureTheory.upperCrossingTime_lt_lowerCrossingTime\n\ntheorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b)\n    (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) :\n    lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω :=\n  by\n  refine'\n    lt_of_le_of_ne lower_crossing_time_le_upper_crossing_time_succ fun h =>\n      not_le.2 hab <| le_trans (stopped_value_upper_crossing_time hn) _\n  simp only [stopped_value]\n  rw [← h]\n  exact stopped_value_lower_crossing_time (h.symm ▸ hn)\n#align measure_theory.lower_crossing_time_lt_upper_crossing_time MeasureTheory.lowerCrossingTime_lt_upperCrossingTime\n\ntheorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) :\n    upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω :=\n  lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime\n    (lowerCrossingTime_lt_upperCrossingTime hab hn)\n#align measure_theory.upper_crossing_time_lt_succ MeasureTheory.upperCrossingTime_lt_succ\n\ntheorem lowerCrossingTime_stabilize (hnm : n ≤ m) (hn : lowerCrossingTime a b f N n ω = N) :\n    lowerCrossingTime a b f N m ω = N :=\n  le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm))\n#align measure_theory.lower_crossing_time_stabilize MeasureTheory.lowerCrossingTime_stabilize\n\ntheorem upperCrossingTime_stabilize (hnm : n ≤ m) (hn : upperCrossingTime a b f N n ω = N) :\n    upperCrossingTime a b f N m ω = N :=\n  le_antisymm upperCrossingTime_le (le_trans (le_of_eq hn.symm) (upperCrossingTime_mono hnm))\n#align measure_theory.upper_crossing_time_stabilize MeasureTheory.upperCrossingTime_stabilize\n\ntheorem lowerCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ lowerCrossingTime a b f N n ω) :\n    lowerCrossingTime a b f N m ω = N :=\n  lowerCrossingTime_stabilize hnm (le_antisymm lowerCrossingTime_le hn)\n#align measure_theory.lower_crossing_time_stabilize' MeasureTheory.lowerCrossingTime_stabilize'\n\ntheorem upperCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ upperCrossingTime a b f N n ω) :\n    upperCrossingTime a b f N m ω = N :=\n  upperCrossingTime_stabilize hnm (le_antisymm upperCrossingTime_le hn)\n#align measure_theory.upper_crossing_time_stabilize' MeasureTheory.upperCrossingTime_stabilize'\n\n-- `upper_crossing_time_bound_eq` provides an explicit bound\ntheorem exists_upperCrossingTime_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) :\n    ∃ n, upperCrossingTime a b f N n ω = N :=\n  by\n  by_contra h; push_neg  at h\n  have : StrictMono fun n => upper_crossing_time a b f N n ω :=\n    strictMono_nat_of_lt_succ fun n => upper_crossing_time_lt_succ hab (h _)\n  obtain ⟨_, ⟨k, rfl⟩, hk⟩ :\n    ∃ (m : _)(hm : m ∈ Set.range fun n => upper_crossing_time a b f N n ω), N < m :=\n    ⟨upper_crossing_time a b f N (N + 1) ω, ⟨N + 1, rfl⟩,\n      lt_of_lt_of_le N.lt_succ_self (StrictMono.id_le this (N + 1))⟩\n  exact not_le.2 hk upper_crossing_time_le\n#align measure_theory.exists_upper_crossing_time_eq MeasureTheory.exists_upperCrossingTime_eq\n\ntheorem upperCrossingTime_lt_bddAbove (hab : a < b) :\n    BddAbove { n | upperCrossingTime a b f N n ω < N } :=\n  by\n  obtain ⟨k, hk⟩ := exists_upper_crossing_time_eq f N ω hab\n  refine' ⟨k, fun n (hn : upper_crossing_time a b f N n ω < N) => _⟩\n  by_contra hn'\n  exact hn.ne (upper_crossing_time_stabilize (not_le.1 hn').le hk)\n#align measure_theory.upper_crossing_time_lt_bdd_above MeasureTheory.upperCrossingTime_lt_bddAbove\n\ntheorem upperCrossingTime_lt_nonempty (hN : 0 < N) :\n    { n | upperCrossingTime a b f N n ω < N }.Nonempty :=\n  ⟨0, hN⟩\n#align measure_theory.upper_crossing_time_lt_nonempty MeasureTheory.upperCrossingTime_lt_nonempty\n\ntheorem upperCrossingTime_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) :\n    upperCrossingTime a b f N N ω = N :=\n  by\n  by_cases hN' : N < Nat.find (exists_upper_crossing_time_eq f N ω hab)\n  · refine' le_antisymm upper_crossing_time_le _\n    have hmono :\n      StrictMonoOn (fun n => upper_crossing_time a b f N n ω)\n        (Set.Iic (Nat.find (exists_upper_crossing_time_eq f N ω hab)).pred) :=\n      by\n      refine' strictMonoOn_Iic_of_lt_succ fun m hm => upper_crossing_time_lt_succ hab _\n      rw [Nat.lt_pred_iff] at hm\n      convert Nat.find_min _ hm\n    convert StrictMonoOn.Iic_id_le hmono N (Nat.le_pred_of_lt hN')\n  · rw [not_lt] at hN'\n    exact\n      upper_crossing_time_stabilize hN' (Nat.find_spec (exists_upper_crossing_time_eq f N ω hab))\n#align measure_theory.upper_crossing_time_bound_eq MeasureTheory.upperCrossingTime_bound_eq\n\ntheorem upperCrossingTime_eq_of_bound_le (hab : a < b) (hn : N ≤ n) :\n    upperCrossingTime a b f N n ω = N :=\n  le_antisymm upperCrossingTime_le\n    (le_trans (upperCrossingTime_bound_eq f N ω hab).symm.le (upperCrossingTime_mono hn))\n#align measure_theory.upper_crossing_time_eq_of_bound_le MeasureTheory.upperCrossingTime_eq_of_bound_le\n\nvariable {ℱ : Filtration ℕ m0}\n\ntheorem Adapted.isStoppingTime_crossing (hf : Adapted ℱ f) :\n    IsStoppingTime ℱ (upperCrossingTime a b f N n) ∧\n      IsStoppingTime ℱ (lowerCrossingTime a b f N n) :=\n  by\n  induction' n with k ih\n  · refine' ⟨is_stopping_time_const _ 0, _⟩\n    simp [hitting_is_stopping_time hf measurableSet_Iic]\n  · obtain ⟨ih₁, ih₂⟩ := ih\n    have : is_stopping_time ℱ (upper_crossing_time a b f N (k + 1)) :=\n      by\n      intro n\n      simp_rw [upper_crossing_time_succ_eq]\n      exact\n        is_stopping_time_hitting_is_stopping_time ih₂ (fun _ => lower_crossing_time_le)\n          measurableSet_Ici hf _\n    refine' ⟨this, _⟩\n    · intro n\n      exact\n        is_stopping_time_hitting_is_stopping_time this (fun _ => upper_crossing_time_le)\n          measurableSet_Iic hf _\n#align measure_theory.adapted.is_stopping_time_crossing MeasureTheory.Adapted.isStoppingTime_crossing\n\ntheorem Adapted.isStoppingTime_upperCrossingTime (hf : Adapted ℱ f) :\n    IsStoppingTime ℱ (upperCrossingTime a b f N n) :=\n  hf.isStoppingTime_crossing.1\n#align measure_theory.adapted.is_stopping_time_upper_crossing_time MeasureTheory.Adapted.isStoppingTime_upperCrossingTime\n\ntheorem Adapted.isStoppingTime_lowerCrossingTime (hf : Adapted ℱ f) :\n    IsStoppingTime ℱ (lowerCrossingTime a b f N n) :=\n  hf.isStoppingTime_crossing.2\n#align measure_theory.adapted.is_stopping_time_lower_crossing_time MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime\n\n/-- `upcrossing_strat a b f N n` is 1 if `n` is between a consecutive pair of lower and upper\ncrossings and is 0 otherwise. `upcrossing_strat` is shifted by one index so that it is adapted\nrather than predictable. -/\nnoncomputable def upcrossingStrat (a b : ℝ) (f : ℕ → Ω → ℝ) (N n : ℕ) (ω : Ω) : ℝ :=\n  ∑ k in Finset.range N,\n    (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator 1 n\n#align measure_theory.upcrossing_strat MeasureTheory.upcrossingStrat\n\ntheorem upcrossingStrat_nonneg : 0 ≤ upcrossingStrat a b f N n ω :=\n  Finset.sum_nonneg fun i hi => Set.indicator_nonneg (fun ω hω => zero_le_one) _\n#align measure_theory.upcrossing_strat_nonneg MeasureTheory.upcrossingStrat_nonneg\n\ntheorem upcrossingStrat_le_one : upcrossingStrat a b f N n ω ≤ 1 :=\n  by\n  rw [upcrossing_strat, ← Set.indicator_finset_bunionᵢ_apply]\n  · exact Set.indicator_le_self' (fun _ _ => zero_le_one) _\n  · intro i hi j hj hij\n    rw [Set.Ico_disjoint_Ico]\n    obtain hij' | hij' := lt_or_gt_of_ne hij\n    · rw [min_eq_left\n          (upper_crossing_time_mono (Nat.succ_le_succ hij'.le) :\n            upper_crossing_time a b f N _ ω ≤ upper_crossing_time a b f N _ ω),\n        max_eq_right\n          (lower_crossing_time_mono hij'.le :\n            lower_crossing_time a b f N _ _ ≤ lower_crossing_time _ _ _ _ _ _)]\n      refine'\n        le_trans upper_crossing_time_le_lower_crossing_time\n          (lower_crossing_time_mono (Nat.succ_le_of_lt hij'))\n    · rw [gt_iff_lt] at hij'\n      rw [min_eq_right\n          (upper_crossing_time_mono (Nat.succ_le_succ hij'.le) :\n            upper_crossing_time a b f N _ ω ≤ upper_crossing_time a b f N _ ω),\n        max_eq_left\n          (lower_crossing_time_mono hij'.le :\n            lower_crossing_time a b f N _ _ ≤ lower_crossing_time _ _ _ _ _ _)]\n      refine'\n        le_trans upper_crossing_time_le_lower_crossing_time\n          (lower_crossing_time_mono (Nat.succ_le_of_lt hij'))\n#align measure_theory.upcrossing_strat_le_one MeasureTheory.upcrossingStrat_le_one\n\ntheorem Adapted.upcrossingStrat_adapted (hf : Adapted ℱ f) : Adapted ℱ (upcrossingStrat a b f N) :=\n  by\n  intro n\n  change\n    strongly_measurable[ℱ n] fun ω =>\n      ∑ k in Finset.range N,\n        ({ n | lower_crossing_time a b f N k ω ≤ n } ∩\n              { n | n < upper_crossing_time a b f N (k + 1) ω }).indicator\n          1 n\n  refine'\n    Finset.stronglyMeasurable_sum _ fun i hi =>\n      strongly_measurable_const.indicator ((hf.is_stopping_time_lower_crossing_time n).inter _)\n  simp_rw [← not_le]\n  exact (hf.is_stopping_time_upper_crossing_time n).compl\n#align measure_theory.adapted.upcrossing_strat_adapted MeasureTheory.Adapted.upcrossingStrat_adapted\n\ntheorem Submartingale.sumUpcrossingStratMul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ)\n    (N : ℕ) :\n    Submartingale\n      (fun n : ℕ => ∑ k in Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)) ℱ μ :=\n  hf.sumMulSub hf.Adapted.upcrossingStrat_adapted (fun _ _ => upcrossingStrat_le_one) fun _ _ =>\n    upcrossingStrat_nonneg\n#align measure_theory.submartingale.sum_upcrossing_strat_mul MeasureTheory.Submartingale.sumUpcrossingStratMul\n\ntheorem Submartingale.sumSubUpcrossingStratMul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)\n    (a b : ℝ) (N : ℕ) :\n    Submartingale\n      (fun n : ℕ => ∑ k in Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)) ℱ\n      μ :=\n  by\n  refine'\n    hf.sum_mul_sub (fun n => (adapted_const ℱ 1 n).sub (hf.adapted.upcrossing_strat_adapted n))\n      (_ : ∀ n ω, (1 - upcrossing_strat a b f N n) ω ≤ 1) _\n  · exact fun n ω => sub_le_self _ upcrossing_strat_nonneg\n  · intro n ω\n    simp [upcrossing_strat_le_one]\n#align measure_theory.submartingale.sum_sub_upcrossing_strat_mul MeasureTheory.Submartingale.sumSubUpcrossingStratMul\n\ntheorem Submartingale.sum_mul_upcrossingStrat_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) :\n    μ[∑ k in Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] ≤ μ[f n] - μ[f 0] :=\n  by\n  have h₁ :\n    (0 : ℝ) ≤ μ[∑ k in Finset.range n, (1 - upcrossing_strat a b f N k) * (f (k + 1) - f k)] :=\n    by\n    have := (hf.sum_sub_upcrossing_strat_mul a b N).set_integral_le (zero_le n) MeasurableSet.univ\n    rw [integral_univ, integral_univ] at this\n    refine' le_trans _ this\n    simp only [Finset.range_zero, Finset.sum_empty, integral_zero']\n  have h₂ :\n    μ[∑ k in Finset.range n, (1 - upcrossing_strat a b f N k) * (f (k + 1) - f k)] =\n      μ[∑ k in Finset.range n, f (k + 1) - f k] -\n        μ[∑ k in Finset.range n, upcrossing_strat a b f N k * (f (k + 1) - f k)] :=\n    by\n    simp only [sub_mul, one_mul, Finset.sum_sub_distrib, Pi.sub_apply, Finset.sum_apply,\n      Pi.mul_apply]\n    refine'\n      integral_sub\n        (integrable.sub (integrable_finset_sum _ fun i hi => hf.integrable _)\n          (integrable_finset_sum _ fun i hi => hf.integrable _))\n        _\n    convert(hf.sum_upcrossing_strat_mul a b N).Integrable n\n    ext\n    simp\n  rw [h₂, sub_nonneg] at h₁\n  refine' le_trans h₁ _\n  simp_rw [Finset.sum_range_sub, integral_sub' (hf.integrable _) (hf.integrable _)]\n#align measure_theory.submartingale.sum_mul_upcrossing_strat_le MeasureTheory.Submartingale.sum_mul_upcrossingStrat_le\n\n/-- The number of upcrossings (strictly) before time `N`. -/\nnoncomputable def upcrossingsBefore [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)\n    (N : ι) (ω : Ω) : ℕ :=\n  supₛ { n | upperCrossingTime a b f N n ω < N }\n#align measure_theory.upcrossings_before MeasureTheory.upcrossingsBefore\n\n@[simp]\ntheorem upcrossingsBefore_bot [Preorder ι] [OrderBot ι] [InfSet ι] {a b : ℝ} {f : ι → Ω → ℝ}\n    {ω : Ω} : upcrossingsBefore a b f ⊥ ω = ⊥ := by simp [upcrossings_before]\n#align measure_theory.upcrossings_before_bot MeasureTheory.upcrossingsBefore_bot\n\ntheorem upcrossingsBefore_zero : upcrossingsBefore a b f 0 ω = 0 := by simp [upcrossings_before]\n#align measure_theory.upcrossings_before_zero MeasureTheory.upcrossingsBefore_zero\n\n@[simp]\ntheorem upcrossingsBefore_zero' : upcrossingsBefore a b f 0 = 0 :=\n  by\n  ext ω\n  exact upcrossings_before_zero\n#align measure_theory.upcrossings_before_zero' MeasureTheory.upcrossingsBefore_zero'\n\ntheorem upperCrossingTime_lt_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b)\n    (hn : n ≤ upcrossingsBefore a b f N ω) : upperCrossingTime a b f N n ω < N :=\n  haveI : upper_crossing_time a b f N (upcrossings_before a b f N ω) ω < N :=\n    (upper_crossing_time_lt_nonempty hN).cSup_mem\n      ((OrderBot.bddBelow _).finite_of_bddAbove (upper_crossing_time_lt_bdd_above hab))\n  lt_of_le_of_lt (upper_crossing_time_mono hn) this\n#align measure_theory.upper_crossing_time_lt_of_le_upcrossings_before MeasureTheory.upperCrossingTime_lt_of_le_upcrossingsBefore\n\ntheorem upperCrossingTime_eq_of_upcrossingsBefore_lt (hab : a < b)\n    (hn : upcrossingsBefore a b f N ω < n) : upperCrossingTime a b f N n ω = N :=\n  by\n  refine' le_antisymm upper_crossing_time_le (not_lt.1 _)\n  convert not_mem_of_csupₛ_lt hn (upper_crossing_time_lt_bdd_above hab)\n#align measure_theory.upper_crossing_time_eq_of_upcrossings_before_lt MeasureTheory.upperCrossingTime_eq_of_upcrossingsBefore_lt\n\ntheorem upcrossingsBefore_le (f : ℕ → Ω → ℝ) (ω : Ω) (hab : a < b) :\n    upcrossingsBefore a b f N ω ≤ N := by\n  by_cases hN : N = 0\n  · subst hN\n    rw [upcrossings_before_zero]\n  · refine' csupₛ_le ⟨0, zero_lt_iff.2 hN⟩ fun n (hn : _ < _) => _\n    by_contra hnN\n    exact hn.ne (upper_crossing_time_eq_of_bound_le hab (not_le.1 hnN).le)\n#align measure_theory.upcrossings_before_le MeasureTheory.upcrossingsBefore_le\n\ntheorem crossing_eq_crossing_of_lowerCrossingTime_lt {M : ℕ} (hNM : N ≤ M)\n    (h : lowerCrossingTime a b f N n ω < N) :\n    upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω ∧\n      lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω :=\n  by\n  have h' : upper_crossing_time a b f N n ω < N :=\n    lt_of_le_of_lt upper_crossing_time_le_lower_crossing_time h\n  induction' n with k ih\n  · simp only [Nat.zero_eq, upper_crossing_time_zero, bot_eq_zero', eq_self_iff_true,\n      lower_crossing_time_zero, true_and_iff, eq_comm]\n    refine' hitting_eq_hitting_of_exists hNM _\n    simp only [lower_crossing_time, hitting_lt_iff] at h\n    obtain ⟨j, hj₁, hj₂⟩ := h\n    exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩\n  · specialize\n      ih (lt_of_le_of_lt (lower_crossing_time_mono (Nat.le_succ _)) h)\n        (lt_of_le_of_lt (upper_crossing_time_mono (Nat.le_succ _)) h')\n    have : upper_crossing_time a b f M k.succ ω = upper_crossing_time a b f N k.succ ω :=\n      by\n      simp only [upper_crossing_time_succ_eq, hitting_lt_iff] at h'⊢\n      obtain ⟨j, hj₁, hj₂⟩ := h'\n      rw [eq_comm, ih.2]\n      exact hitting_eq_hitting_of_exists hNM ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩\n    refine' ⟨this, _⟩\n    simp only [lower_crossing_time, eq_comm, this]\n    refine' hitting_eq_hitting_of_exists hNM _\n    rw [lower_crossing_time, hitting_lt_iff _ le_rfl] at h\n    swap\n    · infer_instance\n    obtain ⟨j, hj₁, hj₂⟩ := h\n    exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩\n#align measure_theory.crossing_eq_crossing_of_lower_crossing_time_lt MeasureTheory.crossing_eq_crossing_of_lowerCrossingTime_lt\n\ntheorem crossing_eq_crossing_of_upperCrossingTime_lt {M : ℕ} (hNM : N ≤ M)\n    (h : upperCrossingTime a b f N (n + 1) ω < N) :\n    upperCrossingTime a b f M (n + 1) ω = upperCrossingTime a b f N (n + 1) ω ∧\n      lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω :=\n  by\n  have :=\n    (crossing_eq_crossing_of_lower_crossing_time_lt hNM\n        (lt_of_le_of_lt lower_crossing_time_le_upper_crossing_time_succ h)).2\n  refine' ⟨_, this⟩\n  rw [upper_crossing_time_succ_eq, upper_crossing_time_succ_eq, eq_comm, this]\n  refine' hitting_eq_hitting_of_exists hNM _\n  simp only [upper_crossing_time_succ_eq, hitting_lt_iff] at h\n  obtain ⟨j, hj₁, hj₂⟩ := h\n  exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩\n#align measure_theory.crossing_eq_crossing_of_upper_crossing_time_lt MeasureTheory.crossing_eq_crossing_of_upperCrossingTime_lt\n\ntheorem upperCrossingTime_eq_upperCrossingTime_of_lt {M : ℕ} (hNM : N ≤ M)\n    (h : upperCrossingTime a b f N n ω < N) :\n    upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω :=\n  by\n  cases n\n  · simp\n  · exact (crossing_eq_crossing_of_upper_crossing_time_lt hNM h).1\n#align measure_theory.upper_crossing_time_eq_upper_crossing_time_of_lt MeasureTheory.upperCrossingTime_eq_upperCrossingTime_of_lt\n\ntheorem upcrossingsBefore_mono (hab : a < b) : Monotone fun N ω => upcrossingsBefore a b f N ω :=\n  by\n  intro N M hNM ω\n  simp only [upcrossings_before]\n  by_cases hemp : { n : ℕ | upper_crossing_time a b f N n ω < N }.Nonempty\n  · refine' csupₛ_le_csupₛ (upper_crossing_time_lt_bdd_above hab) hemp fun n hn => _\n    rw [Set.mem_setOf_eq, upper_crossing_time_eq_upper_crossing_time_of_lt hNM hn]\n    exact lt_of_lt_of_le hn hNM\n  · rw [Set.not_nonempty_iff_eq_empty] at hemp\n    simp [hemp, csupₛ_empty, bot_eq_zero', zero_le']\n#align measure_theory.upcrossings_before_mono MeasureTheory.upcrossingsBefore_mono\n\ntheorem upcrossingsBefore_lt_of_exists_upcrossing (hab : a < b) {N₁ N₂ : ℕ} (hN₁ : N ≤ N₁)\n    (hN₁' : f N₁ ω < a) (hN₂ : N₁ ≤ N₂) (hN₂' : b < f N₂ ω) :\n    upcrossingsBefore a b f N ω < upcrossingsBefore a b f (N₂ + 1) ω :=\n  by\n  refine' lt_of_lt_of_le (Nat.lt_succ_self _) (le_csupₛ (upper_crossing_time_lt_bdd_above hab) _)\n  rw [Set.mem_setOf_eq, upper_crossing_time_succ_eq, hitting_lt_iff _ le_rfl]\n  swap\n  · infer_instance\n  · refine' ⟨N₂, ⟨_, Nat.lt_succ_self _⟩, hN₂'.le⟩\n    rw [lower_crossing_time, hitting_le_iff_of_lt _ (Nat.lt_succ_self _)]\n    refine' ⟨N₁, ⟨le_trans _ hN₁, hN₂⟩, hN₁'.le⟩\n    by_cases hN : 0 < N\n    · have : upper_crossing_time a b f N (upcrossings_before a b f N ω) ω < N :=\n        Nat.supₛ_mem (upper_crossing_time_lt_nonempty hN) (upper_crossing_time_lt_bdd_above hab)\n      rw [upper_crossing_time_eq_upper_crossing_time_of_lt (hN₁.trans (hN₂.trans <| Nat.le_succ _))\n          this]\n      exact this.le\n    · rw [not_lt, le_zero_iff] at hN\n      rw [hN, upcrossings_before_zero, upper_crossing_time_zero]\n      rfl\n#align measure_theory.upcrossings_before_lt_of_exists_upcrossing MeasureTheory.upcrossingsBefore_lt_of_exists_upcrossing\n\ntheorem lowerCrossingTime_lt_of_lt_upcrossingsBefore (hN : 0 < N) (hab : a < b)\n    (hn : n < upcrossingsBefore a b f N ω) : lowerCrossingTime a b f N n ω < N :=\n  lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ\n    (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn)\n#align measure_theory.lower_crossing_time_lt_of_lt_upcrossings_before MeasureTheory.lowerCrossingTime_lt_of_lt_upcrossingsBefore\n\ntheorem le_sub_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b)\n    (hn : n < upcrossingsBefore a b f N ω) :\n    b - a ≤\n      stoppedValue f (upperCrossingTime a b f N (n + 1)) ω -\n        stoppedValue f (lowerCrossingTime a b f N n) ω :=\n  sub_le_sub\n    (stoppedValue_upperCrossingTime (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn).Ne)\n    (stoppedValue_lowerCrossingTime (lowerCrossingTime_lt_of_lt_upcrossingsBefore hN hab hn).Ne)\n#align measure_theory.le_sub_of_le_upcrossings_before MeasureTheory.le_sub_of_le_upcrossingsBefore\n\ntheorem sub_eq_zero_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) :\n    stoppedValue f (upperCrossingTime a b f N (n + 1)) ω -\n        stoppedValue f (lowerCrossingTime a b f N n) ω =\n      0 :=\n  by\n  have : N ≤ upper_crossing_time a b f N n ω :=\n    by\n    rw [upcrossings_before] at hn\n    rw [← not_lt]\n    exact fun h => not_le.2 hn (le_csupₛ (upper_crossing_time_lt_bdd_above hab) h)\n  simp [stopped_value, upper_crossing_time_stabilize' (Nat.le_succ n) this,\n    lower_crossing_time_stabilize' le_rfl\n      (le_trans this upper_crossing_time_le_lower_crossing_time)]\n#align measure_theory.sub_eq_zero_of_upcrossings_before_lt MeasureTheory.sub_eq_zero_of_upcrossingsBefore_lt\n\ntheorem mul_upcrossingsBefore_le (hf : a ≤ f N ω) (hab : a < b) :\n    (b - a) * upcrossingsBefore a b f N ω ≤\n      ∑ k in Finset.range N, upcrossingStrat a b f N k ω * (f (k + 1) - f k) ω :=\n  by\n  classical\n    by_cases hN : N = 0\n    · simp [hN]\n    simp_rw [upcrossing_strat, Finset.sum_mul, ← Set.indicator_mul_left, Pi.one_apply, Pi.sub_apply,\n      one_mul]\n    rw [Finset.sum_comm]\n    have h₁ :\n      ∀ k,\n        (∑ n in Finset.range N,\n            (Set.Ico (lower_crossing_time a b f N k ω)\n                  (upper_crossing_time a b f N (k + 1) ω)).indicator\n              (fun m => f (m + 1) ω - f m ω) n) =\n          stopped_value f (upper_crossing_time a b f N (k + 1)) ω -\n            stopped_value f (lower_crossing_time a b f N k) ω :=\n      by\n      intro k\n      rw [Finset.sum_indicator_eq_sum_filter,\n        (_ :\n          Finset.filter\n              (fun i =>\n                i ∈\n                  Set.Ico (lower_crossing_time a b f N k ω) (upper_crossing_time a b f N (k + 1) ω))\n              (Finset.range N) =\n            Finset.Ico (lower_crossing_time a b f N k ω) (upper_crossing_time a b f N (k + 1) ω)),\n        Finset.sum_Ico_eq_add_neg _ lower_crossing_time_le_upper_crossing_time_succ,\n        Finset.sum_range_sub fun n => f n ω, Finset.sum_range_sub fun n => f n ω, neg_sub,\n        sub_add_sub_cancel]\n      · rfl\n      · ext i\n        simp only [Set.mem_Ico, Finset.mem_filter, Finset.mem_range, Finset.mem_Ico,\n          and_iff_right_iff_imp, and_imp]\n        exact fun _ h => lt_of_lt_of_le h upper_crossing_time_le\n    simp_rw [h₁]\n    have h₂ :\n      (∑ k in Finset.range (upcrossings_before a b f N ω), b - a) ≤\n        ∑ k in Finset.range N,\n          stopped_value f (upper_crossing_time a b f N (k + 1)) ω -\n            stopped_value f (lower_crossing_time a b f N k) ω :=\n      by\n      calc\n        (∑ k in Finset.range (upcrossings_before a b f N ω), b - a) ≤\n            ∑ k in Finset.range (upcrossings_before a b f N ω),\n              stopped_value f (upper_crossing_time a b f N (k + 1)) ω -\n                stopped_value f (lower_crossing_time a b f N k) ω :=\n          by\n          refine'\n            Finset.sum_le_sum fun i hi => le_sub_of_le_upcrossings_before (zero_lt_iff.2 hN) hab _\n          rwa [Finset.mem_range] at hi\n        _ ≤\n            ∑ k in Finset.range N,\n              stopped_value f (upper_crossing_time a b f N (k + 1)) ω -\n                stopped_value f (lower_crossing_time a b f N k) ω :=\n          by\n          refine'\n            Finset.sum_le_sum_of_subset_of_nonneg\n              (Finset.range_subset.2 (upcrossings_before_le f ω hab)) fun i _ hi => _\n          by_cases hi' : i = upcrossings_before a b f N ω\n          · subst hi'\n            simp only [stopped_value]\n            rw [upper_crossing_time_eq_of_upcrossings_before_lt hab (Nat.lt_succ_self _)]\n            by_cases heq : lower_crossing_time a b f N (upcrossings_before a b f N ω) ω = N\n            · rw [HEq, sub_self]\n            · rw [sub_nonneg]\n              exact le_trans (stopped_value_lower_crossing_time HEq) hf\n          · rw [sub_eq_zero_of_upcrossings_before_lt hab]\n            rw [Finset.mem_range, not_lt] at hi\n            exact lt_of_le_of_ne hi (Ne.symm hi')\n        \n    refine' le_trans _ h₂\n    rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_comm]\n#align measure_theory.mul_upcrossings_before_le MeasureTheory.mul_upcrossingsBefore_le\n\ntheorem integral_mul_upcrossingsBefore_le_integral [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ)\n    (hfN : ∀ ω, a ≤ f N ω) (hfzero : 0 ≤ f 0) (hab : a < b) :\n    (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[f N] :=\n  calc\n    (b - a) * μ[upcrossingsBefore a b f N] ≤\n        μ[∑ k in Finset.range N, upcrossingStrat a b f N k * (f (k + 1) - f k)] :=\n      by\n      rw [← integral_mul_left]\n      refine' integral_mono_of_nonneg _ ((hf.sum_upcrossing_strat_mul a b N).Integrable N) _\n      · exact eventually_of_forall fun ω => mul_nonneg (sub_nonneg.2 hab.le) (Nat.cast_nonneg _)\n      · refine' eventually_of_forall fun ω => _\n        simpa using mul_upcrossings_before_le (hfN ω) hab\n    _ ≤ μ[f N] - μ[f 0] := hf.sum_mul_upcrossingStrat_le\n    _ ≤ μ[f N] := (sub_le_self_iff _).2 (integral_nonneg hfzero)\n    \n#align measure_theory.integral_mul_upcrossings_before_le_integral MeasureTheory.integral_mul_upcrossingsBefore_le_integral\n\ntheorem crossing_pos_eq (hab : a < b) :\n    upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = upperCrossingTime a b f N n ∧\n      lowerCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = lowerCrossingTime a b f N n :=\n  by\n  have hab' : 0 < b - a := sub_pos.2 hab\n  have hf : ∀ ω i, b - a ≤ (f i ω - a)⁺ ↔ b ≤ f i ω :=\n    by\n    intro i ω\n    refine' ⟨fun h => _, fun h => _⟩\n    ·\n      rwa [← sub_le_sub_iff_right a, ←\n        LatticeOrderedCommGroup.pos_eq_self_of_pos_pos (lt_of_lt_of_le hab' h)]\n    · rw [← sub_le_sub_iff_right a] at h\n      rwa [LatticeOrderedCommGroup.pos_of_nonneg _ (le_trans hab'.le h)]\n  have hf' : ∀ ω i, (f i ω - a)⁺ ≤ 0 ↔ f i ω ≤ a :=\n    by\n    intro ω i\n    rw [LatticeOrderedCommGroup.pos_nonpos_iff, sub_nonpos]\n  induction' n with k ih\n  · refine' ⟨rfl, _⟩\n    simp only [lower_crossing_time_zero, hitting, Set.mem_Icc, Set.mem_Iic]\n    ext ω\n    split_ifs with h₁ h₂ h₂\n    · simp_rw [hf']\n    · simp_rw [Set.mem_Iic, ← hf' _ _] at h₂\n      exact False.elim (h₂ h₁)\n    · simp_rw [Set.mem_Iic, hf' _ _] at h₁\n      exact False.elim (h₁ h₂)\n    · rfl\n  · have :\n      upper_crossing_time 0 (b - a) (fun n ω => (f n ω - a)⁺) N (k + 1) =\n        upper_crossing_time a b f N (k + 1) :=\n      by\n      ext ω\n      simp only [upper_crossing_time_succ_eq, ← ih.2, hitting, Set.mem_Ici, tsub_le_iff_right]\n      split_ifs with h₁ h₂ h₂\n      · simp_rw [← sub_le_iff_le_add, hf ω]\n      · simp_rw [Set.mem_Ici, ← hf _ _] at h₂\n        exact False.elim (h₂ h₁)\n      · simp_rw [Set.mem_Ici, hf _ _] at h₁\n        exact False.elim (h₁ h₂)\n      · rfl\n    refine' ⟨this, _⟩\n    ext ω\n    simp only [lower_crossing_time, this, hitting, Set.mem_Iic]\n    split_ifs with h₁ h₂ h₂\n    · simp_rw [hf' ω]\n    · simp_rw [Set.mem_Iic, ← hf' _ _] at h₂\n      exact False.elim (h₂ h₁)\n    · simp_rw [Set.mem_Iic, hf' _ _] at h₁\n      exact False.elim (h₁ h₂)\n    · rfl\n#align measure_theory.crossing_pos_eq MeasureTheory.crossing_pos_eq\n\ntheorem upcrossingsBefore_pos_eq (hab : a < b) :\n    upcrossingsBefore 0 (b - a) (fun n ω => (f n ω - a)⁺) N ω = upcrossingsBefore a b f N ω := by\n  simp_rw [upcrossings_before, (crossing_pos_eq hab).1]\n#align measure_theory.upcrossings_before_pos_eq MeasureTheory.upcrossingsBefore_pos_eq\n\ntheorem mul_integral_upcrossingsBefore_le_integral_pos_part_aux [IsFiniteMeasure μ]\n    (hf : Submartingale f ℱ μ) (hab : a < b) :\n    (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] :=\n  by\n  refine'\n    le_trans (le_of_eq _)\n      (integral_mul_upcrossings_before_le_integral (hf.sub_martingale (martingale_const _ _ _)).Pos\n        (fun ω => LatticeOrderedCommGroup.pos_nonneg _)\n        (fun ω => LatticeOrderedCommGroup.pos_nonneg _) (sub_pos.2 hab))\n  simp_rw [sub_zero, ← upcrossings_before_pos_eq hab]\n  rfl\n#align measure_theory.mul_integral_upcrossings_before_le_integral_pos_part_aux MeasureTheory.mul_integral_upcrossingsBefore_le_integral_pos_part_aux\n\n/-- **Doob's upcrossing estimate**: given a real valued discrete submartingale `f` and real\nvalues `a` and `b`, we have `(b - a) * 𝔼[upcrossings_before a b f N] ≤ 𝔼[(f N - a)⁺]` where\n`upcrossings_before a b f N` is the number of times the process `f` crossed from below `a` to above\n`b` before the time `N`. -/\ntheorem Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part [IsFiniteMeasure μ]\n    (a b : ℝ) (hf : Submartingale f ℱ μ) (N : ℕ) :\n    (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] :=\n  by\n  by_cases hab : a < b\n  · exact mul_integral_upcrossings_before_le_integral_pos_part_aux hf hab\n  · rw [not_lt, ← sub_nonpos] at hab\n    exact\n      le_trans (mul_nonpos_of_nonpos_of_nonneg hab (integral_nonneg fun ω => Nat.cast_nonneg _))\n        (integral_nonneg fun ω => LatticeOrderedCommGroup.pos_nonneg _)\n#align measure_theory.submartingale.mul_integral_upcrossings_before_le_integral_pos_part MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part\n\n/-!\n\n### Variant of the upcrossing estimate\n\nNow, we would like to prove a variant of the upcrossing estimate obtained by taking the supremum\nover $N$ of the original upcrossing estimate. Namely, we want the inequality\n$$\n  (b - a) \\sup_N \\mathbb{E}[U_N(a, b)] \\le \\sup_N \\mathbb{E}[f_N].\n$$\nThis inequality is central for the martingale convergence theorem as it provides a uniform bound\nfor the upcrossings.\n\nWe note that on top of taking the supremum on both sides of the inequality, we had also used\nthe monotone convergence theorem on the left hand side to take the supremum outside of the\nintegral. To do this, we need to make sure $U_N(a, b)$ is measurable and integrable. Integrability\nis easy to check as $U_N(a, b) ≤ N$ and so it suffices to show measurability. Indeed, by\nnoting that\n$$\n  U_N(a, b) = \\sum_{i = 1}^N \\mathbf{1}_{\\{U_N(a, b) < N\\}}\n$$\n$U_N(a, b)$ is measurable as $\\{U_N(a, b) < N\\}$ is a measurable set since $U_N(a, b)$ is a\nstopping time.\n\n-/\n\n\ntheorem upcrossingsBefore_eq_sum (hab : a < b) :\n    upcrossingsBefore a b f N ω =\n      ∑ i in Finset.Ico 1 (N + 1), { n | upperCrossingTime a b f N n ω < N }.indicator 1 i :=\n  by\n  by_cases hN : N = 0\n  · simp [hN]\n  rw [←\n    Finset.sum_Ico_consecutive _ (Nat.succ_le_succ zero_le')\n      (Nat.succ_le_succ (upcrossings_before_le f ω hab))]\n  have h₁ :\n    ∀ k ∈ Finset.Ico 1 (upcrossings_before a b f N ω + 1),\n      { n : ℕ | upper_crossing_time a b f N n ω < N }.indicator 1 k = 1 :=\n    by\n    rintro k hk\n    rw [Finset.mem_Ico] at hk\n    rw [Set.indicator_of_mem]\n    · rfl\n    ·\n      exact\n        upper_crossing_time_lt_of_le_upcrossings_before (zero_lt_iff.2 hN) hab\n          (Nat.lt_succ_iff.1 hk.2)\n  have h₂ :\n    ∀ k ∈ Finset.Ico (upcrossings_before a b f N ω + 1) (N + 1),\n      { n : ℕ | upper_crossing_time a b f N n ω < N }.indicator 1 k = 0 :=\n    by\n    rintro k hk\n    rw [Finset.mem_Ico, Nat.succ_le_iff] at hk\n    rw [Set.indicator_of_not_mem]\n    simp only [Set.mem_setOf_eq, not_lt]\n    exact (upper_crossing_time_eq_of_upcrossings_before_lt hab hk.1).symm.le\n  rw [Finset.sum_congr rfl h₁, Finset.sum_congr rfl h₂, Finset.sum_const, Finset.sum_const,\n    smul_eq_mul, mul_one, smul_eq_mul, MulZeroClass.mul_zero, Nat.card_Ico, Nat.add_succ_sub_one,\n    add_zero, add_zero]\n#align measure_theory.upcrossings_before_eq_sum MeasureTheory.upcrossingsBefore_eq_sum\n\ntheorem Adapted.measurable_upcrossingsBefore (hf : Adapted ℱ f) (hab : a < b) :\n    Measurable (upcrossingsBefore a b f N) :=\n  by\n  have :\n    upcrossings_before a b f N = fun ω =>\n      ∑ i in Finset.Ico 1 (N + 1), { n | upper_crossing_time a b f N n ω < N }.indicator 1 i :=\n    by\n    ext ω\n    exact upcrossings_before_eq_sum hab\n  rw [this]\n  exact\n    Finset.measurable_sum _ fun i hi =>\n      Measurable.indicator measurable_const <|\n        ℱ.le N _ (hf.is_stopping_time_upper_crossing_time.measurable_set_lt_of_pred N)\n#align measure_theory.adapted.measurable_upcrossings_before MeasureTheory.Adapted.measurable_upcrossingsBefore\n\ntheorem Adapted.integrableUpcrossingsBefore [IsFiniteMeasure μ] (hf : Adapted ℱ f) (hab : a < b) :\n    Integrable (fun ω => (upcrossingsBefore a b f N ω : ℝ)) μ :=\n  haveI : ∀ᵐ ω ∂μ, ‖(upcrossings_before a b f N ω : ℝ)‖ ≤ N :=\n    by\n    refine' eventually_of_forall fun ω => _\n    rw [Real.norm_eq_abs, Nat.abs_cast, Nat.cast_le]\n    refine' upcrossings_before_le _ _ hab\n  ⟨Measurable.aeStronglyMeasurable\n      (measurable_from_top.comp (hf.measurable_upcrossings_before hab)),\n    has_finite_integral_of_bounded this⟩\n#align measure_theory.adapted.integrable_upcrossings_before MeasureTheory.Adapted.integrableUpcrossingsBefore\n\n/-- The number of upcrossings of a realization of a stochastic process (`upcrossing` takes value\nin `ℝ≥0∞` and so is allowed to be `∞`). -/\nnoncomputable def upcrossings [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ)\n    (ω : Ω) : ℝ≥0∞ :=\n  ⨆ N, (upcrossingsBefore a b f N ω : ℝ≥0∞)\n#align measure_theory.upcrossings MeasureTheory.upcrossings\n\ntheorem Adapted.measurable_upcrossings (hf : Adapted ℱ f) (hab : a < b) :\n    Measurable (upcrossings a b f) :=\n  measurable_supᵢ fun N => measurable_from_top.comp (hf.measurable_upcrossingsBefore hab)\n#align measure_theory.adapted.measurable_upcrossings MeasureTheory.Adapted.measurable_upcrossings\n\ntheorem upcrossings_lt_top_iff :\n    upcrossings a b f ω < ∞ ↔ ∃ k, ∀ N, upcrossingsBefore a b f N ω ≤ k :=\n  by\n  have : upcrossings a b f ω < ∞ ↔ ∃ k : ℝ≥0, upcrossings a b f ω ≤ k :=\n    by\n    constructor\n    · intro h\n      lift upcrossings a b f ω to ℝ≥0 using h.ne with r hr\n      exact ⟨r, le_rfl⟩\n    · rintro ⟨k, hk⟩\n      exact lt_of_le_of_lt hk ENNReal.coe_lt_top\n  simp_rw [this, upcrossings, supᵢ_le_iff]\n  constructor <;> rintro ⟨k, hk⟩\n  · obtain ⟨m, hm⟩ := exists_nat_ge k\n    refine' ⟨m, fun N => Nat.cast_le.1 ((hk N).trans _)⟩\n    rwa [← ENNReal.coe_nat, ENNReal.coe_le_coe]\n  · refine' ⟨k, fun N => _⟩\n    simp only [ENNReal.coe_nat, Nat.cast_le, hk N]\n#align measure_theory.upcrossings_lt_top_iff MeasureTheory.upcrossings_lt_top_iff\n\n/-- A variant of Doob's upcrossing estimate obtained by taking the supremum on both sides. -/\ntheorem Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part [IsFiniteMeasure μ] (a b : ℝ)\n    (hf : Submartingale f ℱ μ) :\n    (ENNReal.ofReal (b - a) * ∫⁻ ω, upcrossings a b f ω ∂μ) ≤\n      ⨆ N, ∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ :=\n  by\n  by_cases hab : a < b\n  · simp_rw [upcrossings]\n    have : ∀ N, (∫⁻ ω, ENNReal.ofReal ((f N ω - a)⁺) ∂μ) = ENNReal.ofReal (∫ ω, (f N ω - a)⁺ ∂μ) :=\n      by\n      intro N\n      rw [of_real_integral_eq_lintegral_of_real]\n      · exact (hf.sub_martingale (martingale_const _ _ _)).Pos.Integrable _\n      · exact eventually_of_forall fun ω => LatticeOrderedCommGroup.pos_nonneg _\n    rw [lintegral_supr']\n    · simp_rw [this, ENNReal.mul_supᵢ, supᵢ_le_iff]\n      intro N\n      rw [(by simp :\n          (∫⁻ ω, upcrossings_before a b f N ω ∂μ) = ∫⁻ ω, ↑(upcrossings_before a b f N ω : ℝ≥0) ∂μ),\n        lintegral_coe_eq_integral, ← ENNReal.ofReal_mul (sub_pos.2 hab).le]\n      · simp_rw [NNReal.coe_nat_cast]\n        exact\n          (ENNReal.ofReal_le_ofReal\n                (hf.mul_integral_upcrossings_before_le_integral_pos_part a b N)).trans\n            (le_supᵢ _ N)\n      · simp only [NNReal.coe_nat_cast, hf.adapted.integrable_upcrossings_before hab]\n    ·\n      exact fun n =>\n        measurable_from_top.comp_ae_measurable\n          (hf.adapted.measurable_upcrossings_before hab).AeMeasurable\n    · refine' eventually_of_forall fun ω N M hNM => _\n      rw [Nat.cast_le]\n      exact upcrossings_before_mono hab hNM ω\n  · rw [not_lt, ← sub_nonpos] at hab\n    rw [ENNReal.ofReal_of_nonpos hab, MulZeroClass.zero_mul]\n    exact zero_le _\n#align measure_theory.submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part\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/Upcrossing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096158798117, "lm_q2_score": 0.8596637451167995, "lm_q1q2_score": 0.7875462233247515}}
{"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.commute\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.Semiconj\nimport Mathlib.Algebra.Group.Commute\nimport Mathlib.Tactic.Nontriviality\n\n/-!\n# Lemmas about commuting elements in a `MonoidWithZero` or a `GroupWithZero`.\n\n-/\n\n\nvariable {α M₀ G₀ M₀' G₀' F F' : Type _}\n\nvariable [MonoidWithZero M₀]\n\nnamespace Ring\n\nopen Classical\n\ntheorem mul_inverse_rev' {a b : M₀} (h : Commute a b) :\n    inverse (a * b) = inverse b * inverse a := by\n  by_cases hab : IsUnit (a * b)\n  · obtain ⟨⟨a, rfl⟩, b, rfl⟩ := h.isUnit_mul_iff.mp hab\n    rw [← Units.val_mul, inverse_unit, inverse_unit, inverse_unit, ← Units.val_mul, mul_inv_rev]\n  obtain ha | hb := not_and_or.mp (mt h.isUnit_mul_iff.mpr hab)\n  · rw [inverse_non_unit _ hab, inverse_non_unit _ ha, mul_zero]\n  · rw [inverse_non_unit _ hab, inverse_non_unit _ hb, zero_mul]\n#align ring.mul_inverse_rev' Ring.mul_inverse_rev'\n\ntheorem mul_inverse_rev {M₀} [CommMonoidWithZero M₀] (a b : M₀) :\n    Ring.inverse (a * b) = inverse b * inverse a :=\n  mul_inverse_rev' (Commute.all _ _)\n#align ring.mul_inverse_rev Ring.mul_inverse_rev\n\nend Ring\n\ntheorem Commute.ring_inverse_ring_inverse {a b : M₀} (h : Commute a b) :\n    Commute (Ring.inverse a) (Ring.inverse b) :=\n  (Ring.mul_inverse_rev' h.symm).symm.trans <| (congr_arg _ h.symm.eq).trans <|\n    Ring.mul_inverse_rev' h\n#align commute.ring_inverse_ring_inverse Commute.ring_inverse_ring_inverse\n\nnamespace Commute\n\n@[simp]\ntheorem zero_right [MulZeroClass G₀] (a : G₀) : Commute a 0 :=\n  SemiconjBy.zero_right a\n#align commute.zero_right Commute.zero_right\n\n@[simp]\n\n\nvariable [GroupWithZero G₀] {a b c : G₀}\n\n@[simp]\ntheorem inv_left_iff₀ : Commute a⁻¹ b ↔ Commute a b :=\n  SemiconjBy.inv_symm_left_iff₀\n#align commute.inv_left_iff₀ Commute.inv_left_iff₀\n\ntheorem inv_left₀ (h : Commute a b) : Commute a⁻¹ b :=\n  inv_left_iff₀.2 h\n#align commute.inv_left₀ Commute.inv_left₀\n\n@[simp]\ntheorem inv_right_iff₀ : Commute a b⁻¹ ↔ Commute a b :=\n  SemiconjBy.inv_right_iff₀\n#align commute.inv_right_iff₀ Commute.inv_right_iff₀\n\ntheorem inv_right₀ (h : Commute a b) : Commute a b⁻¹ :=\n  inv_right_iff₀.2 h\n#align commute.inv_right₀ Commute.inv_right₀\n\n@[simp]\ntheorem div_right (hab : Commute a b) (hac : Commute a c) : Commute a (b / c) :=\n  SemiconjBy.div_right hab hac\n#align commute.div_right Commute.div_right\n\n@[simp]\ntheorem div_left (hac : Commute a c) (hbc : Commute b c) : Commute (a / b) c := by\n  rw [div_eq_mul_inv]\n  exact hac.mul_left hbc.inv_left₀\n#align commute.div_left Commute.div_left\n\nend Commute\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/Commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.7875462118330226}}
{"text": "import data.real.basic tactic.norm_num tactic.ring\n\nnamespace real \nnoncomputable theory \n\ndef α := (sqrt 5 + 1) / 2\ndef β := 1 - α \n\ntheorem root_5_squared : (sqrt 5) ^ 2 = 5 := \n  by simp [sqr_sqrt,(by norm_num : (0:ℝ) <= 5)]\n\nlemma αβsum : α + β = 1 := begin\n  unfold β,\n  unfold α,\n  norm_num, -- ;-)\nend \n\nlemma αβprod : α * β = -1 := begin\n  unfold α β,\n  ring,\n  rw sqr_sqrt; norm_num\nend\n\n-- √ is \\surd\n\n--#check sqrt_prop -- ∀ (x : ℝ), 0 ≤ sqrt x ∧ sqrt x * sqrt x = max 0 x\n\n\nend real\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/real_alpha.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067228145365, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7874488543816976}}
{"text": "import data.real.basic\n\nimport algebra.ne_zero\nimport algebra.group_with_zero.basic\nimport algebra.ring.defs\nimport data.int.cast.defs\n\n\n/-\n Russian Mathematical Olympiad 1998, problem 42\n\n A binary operation ⋆ on real numbers has the property that (a ⋆ b) ⋆ c = a + b + c.\n Prove that a ⋆ b = a + b.\n\n-/\n\nvariable star : ℝ → ℝ → ℝ\nlocal infixl ` ⋆ `:80 := star\n\ntheorem russia1998_q42\n  (stardef : ∀ a b c, a ⋆ b ⋆ c = a + b + c) :\n  (∀ a b, a ⋆ b = a + b) :=\nbegin\n  have lemma2 : ∀ a b d, a ⋆ b = d ⋆ b → a = d,\n  { intros a b d hab,\n    have := calc a + b + a = a ⋆ b ⋆ a : (stardef _ _ _).symm\n                       ... = d ⋆ b ⋆ a : by rw [hab]\n                       ... = d + b + a : stardef _ _ _,\n    have : a + b = d + b := (add_left_inj a).mp this,\n    have : a = d := (add_left_inj b).mp this,\n    exact this },\n\n  have lemma3 : ∀ a b, a ⋆ b = b ⋆ a,\n  { intros a b,\n    let d1 := a ⋆ b,\n    let d2 := b ⋆ a,\n    have h1 := calc d1 ⋆ 1 = a + b + 1 : stardef _ _ _\n                       ... = b + a + 1 : by rw [add_comm a b]\n                       ... = d2 ⋆ 1 : (stardef _ _ _).symm,\n\n    exact lemma2 d1 1 d2 h1 },\n\n  have lemma4 : ∀ a, a ⋆ 0 = a,\n  { intro a,\n    let x := a ⋆ 0,\n    have h1 := calc x ⋆ 0 = a + 0 + 0 : stardef a 0 0\n                      ... = a : by rw [add_zero, add_zero],\n\n    have h2 := calc 2 * x = x + x : two_mul x\n                      ... = x + 0 + x : by rw [add_zero]\n                      ... = x ⋆ 0 ⋆ x : (stardef _ _ _).symm\n                      ... = a ⋆ x : by rw [h1]\n                      ... = x ⋆ a : lemma3 _ _\n                      ... = a ⋆ 0 ⋆ a : rfl\n                      ... = a + 0 + a : stardef _ _ _\n                      ... = a + a : by rw [add_zero]\n                      ... = 2 * a : (two_mul a).symm,\n\n    have h3 : (2:ℝ) ≠ 0 := two_ne_zero,\n    have h4 : x = a := (mul_right_inj' h3).mp h2,\n    exact h4 },\n\n  intros a b,\n\n  have := calc a + b = a + b + 0 : by rw [add_zero]\n                 ... = a ⋆ b ⋆ 0 : (stardef _ _ _).symm\n                 ... = a ⋆ b : lemma4 _,\n\n  exact this.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/russia1998_q42.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7874388037582327}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_succ\nimport MyNat.Multiplication -- mul_succ\nimport AdvancedAdditionWorld.Level9 -- succ_ne_zero\nnamespace MyNat\nopen MyNat\n/-!\n# Advanced Multiplication World\n\n## Level 1: `mul_pos`\n\nRecall that if `b : MyNat` is a hypothesis and you do `cases b with`,\nyour one goal will split into two goals,\nnamely the cases `b = 0` and `b = succ n`. So `cases` here is like\na weaker version of induction (you don't get the inductive hypothesis).\n\n## Tricks\n\n1) if your goal is `⊢ X ≠ Y` then `intro h` will give you `h : X = Y` and\na goal of `⊢ false`. This is because `X ≠ Y` *means* `(X = Y) → false`.\nConversely if your goal is `false` and you have `h : X ≠ Y` as a hypothesis\nthen `apply h` will work backwards and turn the goal into `X = Y`.\n\n2) if `hab : succ (3 * x + 2 * y + 1) = 0` is a hypothesis and your goal is `⊢ false`,\nthen `exact succ_ne_zero _ hab` will solve the goal, because Lean will figure\nout that `_` is supposed to be `3 * x + 2 * y + 1`.\n\n# Theorem\nThe product of two non-zero natural numbers is non-zero.\n-/\ntheorem mul_pos (a b : MyNat) : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by\n  intros ha hb\n  intro hab\n  cases b with\n  | zero =>\n    apply hb\n    rfl\n  | succ b' =>\n    rw [mul_succ] at hab\n    apply ha\n    cases a with\n    | zero =>\n      rfl\n    | succ a' =>\n      rw [add_succ] at hab\n      exfalso\n      exact succ_ne_zero _ hab\n/-!\n\nNext up [Level 2](./Level2.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/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7873986889764386}}
{"text": "/-\nCopyright (c) 2021 Matt Kempster. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Matt Kempster\n-/\nimport geometry.euclidean.triangle\nimport analysis.special_functions.trigonometric\n\n/-!\n# Freek № 57: Heron's Formula\n\nThis file proves Theorem 57 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/),\nalso known as Heron's formula, which gives the area of a triangle based only on its three sides'\nlengths.\n\n## References\n\n* https://en.wikipedia.org/wiki/Herons_formula\n\n-/\n\nopen real euclidean_geometry\nopen_locale real euclidean_geometry\n\nlocal notation `√` := real.sqrt\n\nvariables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P]\n  [normed_add_torsor V P]\n\ninclude V\n\n/-- Heron's formula: The area of a triangle with side lengths `a`, `b`, and `c` is\n  `√(s * (s - a) * (s - b) * (s - c))` where `s = (a + b + c) / 2` is the semiperimeter.\n  We show this by equating this formula to `a * b * sin γ`, where `γ` is the angle opposite\n  the side `c`.\n -/\ntheorem heron {p1 p2 p3 : P} (h1 : p1 ≠ p2) (h2 : p3 ≠ p2) :\n  let a := dist p1 p2, b := dist p3 p2, c := dist p1 p3, s := (a + b + c) / 2 in\n  1/2 * a * b * sin (∠ p1 p2 p3) = √(s * (s - a) * (s - b) * (s - c)) :=\nbegin\n  intros a b c s,\n  let γ := ∠ p1 p2 p3,\n  obtain := ⟨(dist_pos.mpr h1).ne', (dist_pos.mpr h2).ne'⟩,\n  have cos_rule : cos γ = (a * a + b * b - c * c) / (2 * a * b) := by field_simp [mul_comm, a,\n    dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle p1 p2 p3],\n  let numerator := (2*a*b)^2 - (a*a + b*b - c*c)^2,\n  let denominator := (2*a*b)^2,\n  have split_to_frac : 1 - cos γ ^ 2 = numerator / denominator := by field_simp [cos_rule],\n  have numerator_nonneg : 0 ≤ numerator,\n  { have frac_nonneg: 0 ≤ numerator / denominator := by linarith [split_to_frac, cos_sq_le_one γ],\n    cases div_nonneg_iff.mp frac_nonneg,\n    { exact h.left },\n    { simpa [h1, h2] using le_antisymm h.right (sq_nonneg _) } },\n  have ab2_nonneg : 0 ≤ (2 * a * b) := by norm_num [mul_nonneg, dist_nonneg],\n  calc  1/2 * a * b * sin γ\n      = 1/2 * a * b * (√numerator / √denominator) : by rw [sin_eq_sqrt_one_sub_cos_sq,\n                                                          split_to_frac, sqrt_div numerator_nonneg];\n                                                      simp [angle_nonneg, angle_le_pi]\n  ... = 1/4 * √((2*a*b)^2 - (a*a + b*b - c*c)^2)  : by { field_simp [ab2_nonneg], ring }\n  ... = 1/4 * √(s * (s-a) * (s-b) * (s-c) * 4^2)  : by { simp only [s], ring_nf }\n  ... = √(s * (s-a) * (s-b) * (s-c))              : by rw [sqrt_mul', sqrt_sq, div_mul_eq_mul_div,\n                                                          one_mul, mul_div_cancel];\n                                                      norm_num,\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/57_herons_formula.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505204, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7873986815529018}}
{"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\n\n/-\n\n# Representation theory\n\nHomomorphisms between representations; representations as modules.\n\n-/\n\n-- Let ρ and σ be representations of G on V and W\nvariables {k : Type} [field k] {G : Type} [group G] \n  {V : Type} [add_comm_group V] [module k V]\n  {W : Type} [add_comm_group W] [module k W]\n  (ρ : representation k G V) (σ : representation k G W)\n\n-- According to one of my PhD students yesterday, there is no \"G-linear map\" class!\n-- So let's make one.\n\n/-- The G-equivariant linear maps between two representations. -/\n@[ext] -- this makes the `ext` tactic work on rep_maps, i.e. it shows that two rep_maps are \n-- the same if they are the same underlying function\nstructure rep_map (ρ : representation k G V) (σ : representation k G W) : Type :=\n(to_linear_map : V →ₗ[k] W)\n(map_apply : ∀ (g : G) (v : V), to_linear_map (ρ g v) = σ g (to_linear_map v))\n\n-- What should be now prove about it? \n\n/-\n\n## Categories\n\nA category is a collection of objects, and between any pair of objects there's a collection\nof maps or morphisms. Technical point: these maps/morphisms *don't actually have to be functions*,\nthe definition is more abstract than that. But let's not dwell on this right now.\n\nThat's not the end of the definition of a category -- there is a bit more structure, \nand some axioms, but let's just give some examples first:\n\nExample: in set theory the collection of all sets is a category; the morphisms between two sets\nare just the functions between the sets. \n\nExample: In type theory the collection of all types is a category; the morphisms are again just\nthe functions between the types. \n\nExample: if we fix a field `k` and a group `G` then we can make a category whose objects\nare `k`-vector spaces equipped with an action of `G` (i.e. representations of `G`) and\nwhose morphisms are the `G`-linear maps. Note that here the morphisms are *certain* maps\nbetween the objects, but not *all* the maps.\n\nLet's get back to the definition of a category. I need to explain the extra\nstructure and the axioms of a category. The extra structure is:\n\nS1) For every object `X` of the category, there has to be an identity morphism `id_X : X → X`\nS2) If we have three objects `X`, `Y`, and `Z` in the category, and two morphisms\n`f : X → Y` and `g : Y → Z` then there's a way of composing them to get `g ∘ f : X → Z`.\n\nFor example, in the representation theory example above, the category theoretic composition\nis just defined to be function composition, and ensuring that this gives a valid morphism\nboils down to checking that the composite of two `G`-linear maps is `G`-linear. \n\nThe axioms are:\n\nA1) If `f : X → Y` then `id_Y ∘ f = f` and `f ∘ id_X = f`\nA2) If `f : W → X`, `g : X → Y` and `h : Y → Z` then `(f ∘ g) ∘ h = f ∘ (g ∘ h)`\n\nThe reason I mention these is that they inform us about what we should be proving\nabout `rep_map`!\n\n-/\n\nnamespace rep_map\n\ndef id (ρ : representation k G V) : rep_map ρ ρ := \n{ to_linear_map := linear_map.id,\n  map_apply := λ g v, rfl }\n\nvariables {X : Type} [add_comm_group X] [module k X]\n\nvariables {ρ σ}\n\ndef comp {τ : representation k G X}\n  (ψ : rep_map σ τ) (φ : rep_map ρ σ) : rep_map ρ τ :=\n{ to_linear_map := ψ.to_linear_map.comp φ.to_linear_map,\n  map_apply := begin\n    intros,\n    simp [φ.map_apply, ψ.map_apply],\n  end }\n\nlemma comp_id (φ : rep_map ρ σ) : φ.comp (id ρ) = φ :=\nbegin\n  ext,\n  refl,\nend\n\nlemma id_comp (φ : rep_map ρ σ) : (id σ).comp φ = φ :=\nbegin\n  ext,\n  refl,\nend\n\nlemma comp_assoc {τ : representation k G X} {Y : Type} [add_comm_group Y] [module k Y]\n  {υ : representation k G Y} (ξ : rep_map τ υ) (ψ : rep_map σ τ) (φ : rep_map ρ σ) : \n  (ξ.comp ψ).comp φ = ξ.comp (ψ.comp φ) := \nbegin\n  refl,\nend\n\nend rep_map\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/section20representation_theory/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7873986813905449}}
{"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 data.nat.prime_fin\nimport ring_theory.polynomial.cyclotomic.eval\n\n/-!\n# Primes congruent to one\n\nWe prove that, for any positive `k : ℕ`, there are infinitely many primes `p` such that\n`p ≡ 1 [MOD k]`.\n-/\n\nnamespace nat\n\nopen polynomial nat filter\nopen_locale nat\n\n/-- For any positive `k : ℕ` there exists an arbitrarily large prime `p` such that\n`p ≡ 1 [MOD k]`. -/\nlemma exists_prime_gt_modeq_one {k : ℕ} (n : ℕ) (hk0 : k ≠ 0) :\n  ∃ (p : ℕ), nat.prime p ∧ n < p ∧ p ≡ 1 [MOD k] :=\nbegin\n  rcases (one_le_iff_ne_zero.2 hk0).eq_or_lt with rfl | hk1,\n  { rcases exists_infinite_primes (n + 1) with ⟨p, hnp, hp⟩,\n    exact ⟨p, hp, hnp, modeq_one⟩ },\n  let b := k * n!,\n  have hgt : 1 < (eval ↑b (cyclotomic k ℤ)).nat_abs,\n  { rcases le_iff_exists_add'.1 hk1.le with ⟨k, rfl⟩,\n    have hb : 2 ≤ b := le_mul_of_le_of_one_le hk1 n.factorial_pos,\n    calc 1 ≤ b - 1 : le_tsub_of_add_le_left hb\n    ... < (eval (b : ℤ) (cyclotomic (k + 1) ℤ)).nat_abs :\n      sub_one_lt_nat_abs_cyclotomic_eval hk1 (succ_le_iff.1 hb).ne' },\n  let p := min_fac (eval ↑b (cyclotomic k ℤ)).nat_abs,\n  haveI hprime : fact p.prime := ⟨min_fac_prime (ne_of_lt hgt).symm⟩,\n  have hroot : is_root (cyclotomic k (zmod p)) (cast_ring_hom (zmod p) b),\n  { rw [is_root.def, ← map_cyclotomic_int k (zmod p), eval_map, coe_cast_ring_hom,\n      ← int.cast_coe_nat, ← int.coe_cast_ring_hom, eval₂_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 ↑b (cyclotomic k ℤ)).nat_abs },\n  have hpb : ¬(p ∣ b) :=\n    hprime.1.coprime_iff_not_dvd.1 (coprime_of_root_cyclotomic hk0.bot_lt hroot).symm,\n  refine ⟨p, hprime.1, not_le.1 $ λ habs, _, _⟩,\n  { exact hpb (dvd_mul_of_dvd_right (dvd_factorial (min_fac_pos _) habs) _) },\n  { have hdiv : order_of (b : zmod p) ∣ p - 1 :=\n      zmod.order_of_dvd_card_sub_one (mt (char_p.cast_eq_zero_iff _ _ _).1 hpb),\n    haveI : ne_zero (k : zmod p) :=\n      ne_zero.of_not_dvd (zmod p) (λ hpk, hpb (dvd_mul_of_dvd_left hpk _)),\n    have : k = order_of (b : zmod p) := (is_root_cyclotomic_iff.mp hroot).eq_order_of,\n    rw [← this] at hdiv,\n    exact ((modeq_iff_dvd' hprime.1.pos).2 hdiv).symm }\nend\n\nlemma frequently_at_top_modeq_one {k : ℕ} (hk0 : k ≠ 0) :\n  ∃ᶠ p in at_top, nat.prime p ∧ p ≡ 1 [MOD k] :=\nbegin\n  refine frequently_at_top.2 (λ n, _),\n  obtain ⟨p, hp⟩ := exists_prime_gt_modeq_one n hk0,\n  exact ⟨p, ⟨hp.2.1.le, hp.1, hp.2.2⟩⟩\nend\n\n/-- For any positive `k : ℕ` there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`. -/\nlemma infinite_set_of_prime_modeq_one {k : ℕ} (hk0 : k ≠ 0) :\n  set.infinite {p : ℕ | nat.prime p ∧ p ≡ 1 [MOD k]} :=\nfrequently_at_top_iff_infinite.1 (frequently_at_top_modeq_one hk0)\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/primes_congruent_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.787398679873366}}
{"text": "import .love05_inductive_predicates_demo\n\n\n/-! # LoVe Demo 12: Basic Mathematical Structures\n\nWe introduce definitions and proofs about basic mathematical structures such as\ngroups, fields, and linear orders. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Type Classes over a Single Binary Operator\n\nMathematically, a __group__ is a set `G` with a binary operator `• : G × G → G`\nwith the following properties, called __group axioms__:\n\n* Associativity: For all `a, b, c ∈ G`, we have `(a • b) • c = a • (b • c)`.\n* Identity element: There exists an element `e ∈ G` such that for all `a ∈ G`,\n  we have `e • a = a`.\n* Inverse element: For each `a ∈ G`, there exists an inverse element\n  `inv(a) ∈ G` such that `inv(a) • a = e`.\n\nExamples of groups are\n* `ℤ` with `+`;\n* `ℝ` with `+`;\n* `ℝ \\ {0}` with `*`.\n\nIn Lean, a type class for groups can be defined as follows: -/\n\nnamespace monolithic_group\n\n@[class] structure group (α : Type) :=\n(mul          : α → α → α)\n(one          : α)\n(inv          : α → α)\n(mul_assoc    : ∀a b c, mul (mul a b) c = mul a (mul b c))\n(one_mul      : ∀a, mul one a = a)\n(mul_left_inv : ∀a, mul (inv a) a = one)\n\nend monolithic_group\n\n/-! In Lean, however, group is part of a larger hierarchy of algebraic\nstructures:\n\nType class               | Properties                               | Examples\n------------------------ | -----------------------------------------|-------------------\n`semigroup`              | associativity of `*`                     | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`monoid`                 | `semigroup` with unit `1`                | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`left_cancel_semigroup`  | `semigroup` with `c * a = c * b → a = b` |\n`right_cancel_semigroup` | `semigroup` with `a * c = b * c → a = b` |\n`group`                  | `monoid` with inverse `⁻¹`               |\n\nMost of these structures have commutative versions: `comm_semigroup`,\n`comm_monoid`, `comm_group`.\n\nThe __multiplicative__ structures (over `*`, `1`, `⁻¹`) are copied to produce\n__additive__ versions (over `+`, `0`, `-`):\n\nType class                   | Properties                                   | Examples\n---------------------------- | ---------------------------------------------|-------------------\n`add_semigroup`              | associativity of `+`                         | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_monoid`                 | `add_semigroup` with unit `0`                | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_left_cancel_semigroup`  | `add_semigroup` with `c + a = c + b → a = b` | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_right_cancel_semigroup` | `add_semigroup` with `a + c = b + c → a = b` | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_group`                  | `add_monoid` with inverse `-`                | `ℝ`, `ℚ`, `ℤ` -/\n\n#print group\n#print add_group\n\n/-! Let us define our own type, of integers modulo 2, and register it as an\nadditive group. -/\n\ninductive int2 : Type\n| zero\n| one\n\ndef int2.add : int2 → int2 → int2\n| int2.zero a         := a\n| a         int2.zero := a\n| int2.one  int2.one  := int2.zero\n\n@[instance] def int2.add_group : add_group int2 :=\n{ add          := int2.add,\n  add_assoc    :=\n    by intros a b c; cases' a; cases' b; cases' c; refl,\n  zero         := int2.zero,\n  zero_add     := by intro a; cases' a; refl,\n  add_zero     := by intro a; cases' a; refl,\n  neg          := λa, a,\n  add_left_neg := by intro a; cases' a; refl }\n\n#reduce int2.one + 0 - 0 - int2.one\n\nlemma int2.add_right_neg:\n  ∀a : int2, a + - a = 0 :=\nadd_right_neg\n\n/-! Another example: Lists are an `add_monoid`: -/\n\n@[instance] def list.add_monoid {α : Type} :\n  add_monoid (list α) :=\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/-! ## Type Classes with Two Binary Operators\n\nMathematically, a __field__ is a set `F` such that\n\n* `F` forms a commutative group under an operator `+`, called addition, with\n  identity element `0`.\n* `F\\{0}` forms a commutative group under an operator `*`, called\n  multiplication.\n* Multiplication distributes over addition—i.e.,\n  `a * (b + c) = a * b + a * c` for all `a, b, c ∈ F`.\n\nIn Lean, fields are also part of a larger hierarchy:\n\nType class       |  Properties                                         | Examples\n-----------------|-----------------------------------------------------|-------------------\n`semiring`       | `monoid` and `add_comm_monoid` with distributivity  | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`comm_semiring`  | `semiring` with commutativity of `*`                | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`ring`           | `monoid` and `add_comm_group` with distributivity   | `ℝ`, `ℚ`, `ℤ`\n`comm_ring`      | `ring` with commutativity of `*`                    | `ℝ`, `ℚ`, `ℤ`\n`division_ring`  | `ring` with multiplicative inverse `⁻¹`             | `ℝ`, `ℚ`\n`field`          | `division_ring` with commutativity of `*`           | `ℝ`, `ℚ`\n`discrete_field` | `field` with decidable equality and `∀n, n / 0 = 0` | `ℝ`, `ℚ` -/\n\n#print field\n\n/-! Let us continue with our example: -/\n\ndef int2.mul : int2 → int2 → int2\n| int2.one  a         := a\n| a         int2.one  := a\n| int2.zero int2.zero := int2.zero\n\n@[instance] def int2.field : field int2 :=\n{ one            := int2.one,\n  mul            := int2.mul,\n  inv            := λa, a,\n  add_comm       := by intros a b; cases' a; cases' b; refl,\n  exists_pair_ne :=\n    by apply exists.intro int2.zero;\n      apply exists.intro int2.one; finish,\n  one_mul        := by intros a; cases' a; refl,\n  mul_one        := by intros a; cases' a; refl,\n  mul_inv_cancel := by intros a h; cases' a; finish,\n  inv_zero       := by refl,\n  mul_assoc      :=\n    by intros a b c; cases' a; cases' b; cases' c; refl,\n  mul_comm       := by intros a b; cases' a; cases' b; refl,\n  left_distrib   :=\n    by intros a b c; cases' a; cases' b; cases' c; refl,\n  right_distrib  :=\n    by intros a b c; cases' a; cases' b; cases' c; refl,\n  ..int2.add_group }\n\n#reduce (1 : int2) * 0 / (0 - 1)\n\n#reduce (3 : int2)\n\nlemma ring_example (a b : int2) :\n  (a + b) ^ 3 = a ^ 3 + 3 * a ^ 2 * b + 3 * a * b ^ 2 + b ^ 3 :=\nby ring\n\nlemma ring_exp_example (a b : int2) (n : ℕ):\n  (a + b) ^ (2 + n) =\n  (a + b) ^ n * (a ^ 2 + 2 * a * b + b ^ 2) :=\nby ring_exp\n\n/-! `ring` and `ring_exp` prove equalities over commutative rings and semirings\nby normalizing expressions. The `ring_exp` variant also normalizes exponents. -/\n\nlemma abel_example (a b : ℤ) :\n  a + b + 0 - (b + a + a) = - a :=\nby abel\n\n/-! `abel` proves equalities over additive commutative monoids and groups by\nnormalizing expressions.\n\n\n## Coercions\n\nWhen combining numbers form `ℕ`, `ℤ`, `ℚ`, and `ℝ`, we might want to cast from\none type to another. Lean has a mechanism to automatically introduce coercions,\nrepresented by `coe` (syntactic sugar: `↑`). `coe` can be set up to provide\nimplicit coercions between arbitrary types.\n\nMany coercions are already in place, including the following:\n\n* `coe : ℕ → α` casts `ℕ` to another semiring `α`;\n* `coe : ℤ → α` casts `ℤ` to another ring `α`;\n* `coe : ℚ → α` casts `ℚ` to another division ring `α`.\n\nFor example, this works, although negation `- n` is not defined on natural\nnumbers: -/\n\nlemma neg_mul_neg_nat (n : ℕ) (z : ℤ) :\n  (- z) * (- n) = z * n :=\nneg_mul_neg z n\n\n/-! Notice how Lean introduced a `↑` coercion: -/\n\n#print neg_mul_neg_nat\n\n/-! Another example: -/\n\nlemma neg_nat_mul_neg (n : ℕ) (z : ℤ) :\n  (- n : ℤ) * (- z) = n * z :=\nneg_mul_neg n z\n\n#print neg_nat_mul_neg\n\n/-! In proofs involving coercions, the tactic `norm_cast` can be convenient. -/\n\nlemma norm_cast_example_1 (m n : ℕ) (h : (m : ℤ) = (n : ℤ)) :\n  m = n :=\nbegin\n  norm_cast at h,\n  exact h\nend\n\nlemma norm_cast_example_2 (m n : ℕ) :\n  (m : ℤ) + (n : ℤ) = ((m + n : ℕ) : ℤ) :=\nby norm_cast\n\n/-! `norm_cast` moves coercions towards the inside of expressions, as a form of\nsimplification. Like `simp`, it will generally produce a subgoal.\n\n`norm_cast` relies on lemmas such as the following: -/\n\n#check nat.cast_add\n#check int.cast_add\n#check rat.cast_add\n\n\n/-! ### Lists, Multisets and Finite Sets\n\nFor finite collections of elements different structures are available:\n\n* lists: order and duplicates matter;\n* multisets: only duplicates matter;\n* finsets: neither order nor duplicates matter. -/\n\nlemma list_duplicates_example :\n  [2, 3, 3, 4] ≠ [2, 3, 4] :=\ndec_trivial\n\nlemma list_order_example :\n  [4, 3, 2] ≠ [2, 3, 4] :=\ndec_trivial\n\nlemma multiset_duplicates_example :\n  ({2, 3, 3, 4} : multiset ℕ) ≠ {2, 3, 4} :=\ndec_trivial\n\nlemma multiset_order_example :\n  ({2, 3, 4} : multiset ℕ) = {4, 3, 2} :=\ndec_trivial\n\nlemma finset_duplicates_example :\n  ({2, 3, 3, 4} : finset ℕ) = {2, 3, 4} :=\ndec_trivial\n\nlemma finsetorder_example :\n  ({2, 3, 4} : finset ℕ) = {4, 3, 2} :=\ndec_trivial\n\n/-! `dec_trivial` is a special lemma that can be used on trivial decidable\ngoals (e.g., true closed executable expressions). -/\n\ndef list.elems : btree ℕ → list ℕ\n| btree.empty        := []\n| (btree.node a l r) := a :: list.elems l ++ list.elems r\n\ndef multiset.elems : btree ℕ → multiset ℕ\n| btree.empty        := ∅\n| (btree.node a l r) :=\n  {a} ∪ (multiset.elems l ∪ multiset.elems r)\n\ndef finset.elems : btree ℕ → finset ℕ\n| btree.empty        := ∅\n| (btree.node a l r) := {a} ∪ (finset.elems l ∪ finset.elems r)\n\n#eval list.sum [2, 3, 4]                          -- result: 9\n#eval multiset.sum ({2, 3, 4} : multiset ℕ)       -- result: 9\n#eval finset.sum ({2, 3, 4} : finset ℕ) (λn, n)   -- result: 9\n\n#eval list.prod [2, 3, 4]                         -- result: 24\n#eval multiset.prod ({2, 3, 4} : multiset ℕ)      -- result: 24\n#eval finset.prod ({2, 3, 4} : finset ℕ) (λn, n)  -- result: 24\n\n\n/-! ## Order Type Classes\n\nMany of the structures introduced above can be ordered. For example, the\nwell-known order on the natural numbers can be defined as follows: -/\n\ninductive nat.le : ℕ → ℕ → Prop\n| refl : ∀a : ℕ, nat.le a a\n| step : ∀a b : ℕ, nat.le a b → nat.le a (b + 1)\n\n/-! This is an example of a linear order. A __linear order__ (or\n__total order__) is a binary relation `≤` such that for all `a`, `b`, `c`, the\nfollowing properties hold:\n\n* Reflexivity: `a ≤ a`.\n* Transitivity: If `a ≤ b` and `b ≤ c`, then `a ≤ c`.\n* Antisymmetry: If `a ≤ b` and `b ≤ a`, then `a = b`.\n* Totality: `a ≤ b` or `b ≤ a`.\n\nIf a relation has the first three properties, it is a __partial order__. An\nexample is `⊆` on sets, finite sets, or multisets. If a relation has the first\ntwo properties, it is a __preorder__. An example is comparing lists by their\nlength.\n\nIn Lean, there are type classes for these different kinds of orders:\n`linear_order`, `partial_order`, and `preorder`. The `preorder` class has the\nfields\n\n    `le       : α → α → Prop`\n    `le_refl  : ∀a : α, le a a`\n    `le_trans : ∀a b c : α, le a b → le b c → le a c`\n\nThe `partial_order` class also has\n\n    `le_antisymm : ∀a b : α, le a b → le b a → a = b`\n\nand `linear_order` also has\n\n    `le_total : ∀a b : α, le a b ∨ le b a`\n\nWe can declare the preorder on lists that compares lists by their length as\nfollows: -/\n\n@[instance] def list.length.preord {α : Type} :\n  preorder (list α) :=\n{ le       := λxs ys, list.length xs ≤ list.length ys,\n  le_refl  := by intro xs; exact nat.le_refl _,\n  le_trans := by intros xs ys zs; exact nat.le_trans }\n\n/-! This instance introduces the infix syntax `≤` and the relations `≥`, `<`,\nand `>`: -/\n\nlemma list.length.preord_example {α : Type} (c : α) :\n  [c] > [] :=\ndec_trivial\n\n/-! Complete lattices (lecture 10) are formalized as another type class,\n`complete_lattice`, which inherits from `partial_order`.\n\nType classes combining orders and algebraic structures are also available:\n\n    `ordered_cancel_comm_monoid`\n    `ordered_comm_group ordered_semiring`\n    `linear_ordered_semiring`\n    `linear_ordered_comm_ring`\n    `linear_ordered_field`\n\nAll these mathematical structures relate `≤` and `<` with `0`, `1`, `+`, and `*`\nby monotonicity rules (e.g., `a ≤ b → c ≤ d → a + c ≤ b + d`) and cancellation\nrules (e.g., `c + a ≤ c + b → a ≤ b`). -/\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/love12_basic_mathematical_structures_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7873252095162452}}
{"text": "open Nat\n\ntheorem zero_add (n : Nat) : 0 + n = n :=\nNat.recOn (motive := fun x : Nat => 0 + x = x) n\n(show 0 + 0 = 0 from rfl)\n(fun (n : Nat) (ih : 0 + n = n) => show 0 + succ n = succ n from\ncalc 0 + succ n = succ (0 + n) := rfl\n              _ = succ n := by rw [ih])\n\nopen List\n\ndef append (as bs : List α) : List α :=\nmatch as with\n| nil       => bs\n| cons head tail => cons head (append tail bs)\n\ntheorem append_nil (as : List α) : append as nil = as :=\nList.recOn (motive := fun t : List α => append t nil = t) as\n(show append nil nil = nil from rfl)\n(fun (head : α) (tail : List α) (ih : append tail nil = tail) => show append (cons head tail) nil = cons head tail from\ncalc append (cons head tail) nil = cons head (append tail nil) := rfl\n    _ = cons head tail := by rw [ih])\n\ntheorem append_assoc (as bs cs : List α) : append (append as bs) cs = append as (append bs cs) :=\nList.recOn (motive := fun as : List α => append (append as bs) cs = append as (append bs cs)) as\n(show append (append nil bs) cs = append nil (append bs cs) from rfl)\n(fun (head : α) (tail : List α) (ih : append (append tail bs) cs = append tail (append bs cs)) =>\nshow append (append (cons head tail) bs) cs = append (cons head tail) (append bs cs) from\ncalc append (append (cons head tail) bs) cs = append (cons head (append tail bs)) cs := rfl\n    _ = cons head (append (append tail bs) cs) := rfl\n    _ = cons head (append tail (append bs cs)) := by rw [ih])\n\ndef len (as : List α) : Nat :=\nmatch as with\n| nil => 0\n| cons _ tail => succ (length tail)\n\ntheorem len_distrib (as bs : List α) : length (append as bs) = length as + length bs :=\nList.recOn (motive := fun as : List α => length (append as bs) = length as + length bs) as\n(show length (append nil bs) = length nil + length bs from\ncalc length (append nil bs) = length bs := rfl\n     _ = 0 + length bs := by rw [Nat.zero_add])\n(fun (head : α) (tail : List α) (ih : length (append tail bs) = length tail + length bs) =>\nshow length (append (cons head tail) bs) = length (cons head tail) + length bs from\ncalc length (append (cons head tail) bs) = length (cons head (append tail bs)) := rfl\n     _ = succ (length (append tail bs)) := rfl\n     _ = succ (length tail + length bs) := by rw [ih]\n     _ = succ (length tail) + length bs := by rw [Nat.succ_add])\n\nnamespace Hidden\n\ntheorem trans {α : Type u} {a b c : α} (h₁ : Eq a b) (h₂ : Eq b c) : Eq a c := by rw [h₁,h₂]\n\ntheorem congr {α β : Type u} {a b : α} (f : α → β) (h : Eq a b) : Eq (f a) (f b) := by rw [h]\n\ndef subtract (n m : Nat) : Nat :=\nmatch m with\n| zero => n\n| succ k => pred (subtract n k)\n\ntheorem pred_sub_eq_sub_pred : pred (subtract n k) = subtract (pred n) k :=\nNat.recOn (motive := fun x : Nat => pred (subtract n x) = subtract (pred n) x) k\n(show pred (subtract n zero) = subtract (pred n) zero from rfl)\n(fun (r : Nat) (ih : pred (subtract n r) = subtract (pred n) r) =>\nshow pred (subtract n (succ r)) = subtract (pred n) (succ r) from\nby rw [subtract,ih,subtract])\n\ntheorem left_sub_cancel : subtract (n+k) n = k :=\nNat.recOn (motive := fun x : Nat => subtract (x+k) x = k) n\n(show subtract (zero + k) zero = k from by rw [Nat.zero_add k,subtract])\n(fun (r : Nat) (ih : subtract (r+k) r = k) =>\nshow subtract ((succ r)+k) (succ r) = k from\nby rw [Nat.succ_add,subtract,pred_sub_eq_sub_pred, Nat.pred_succ,ih])", "meta": {"author": "Euctemon", "repo": "learning-lean", "sha": "bf93d5996f53f3b874cfd049d03e7d9a7beee46e", "save_path": "github-repos/lean/Euctemon-learning-lean", "path": "github-repos/lean/Euctemon-learning-lean/learning-lean-bf93d5996f53f3b874cfd049d03e7d9a7beee46e/proving/prove_chap7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.787290191827769}}
{"text": "import .helpers\nimport .circuit\n\n/-\nThis is correct and uses only mathlib, but I am leaving it as is for now and doing stuff in the \nncard folder, which uses nonconstructive cardinalities. I've just made a PR with an API for ncard, \nso hopefully this will only be temporary. \n-/\n\n-- noncomputable theory \nopen_locale classical \n\nopen set \n\nvariables {E : Type*}\n\n/-- \n  A predicate `P` on sets satisfies the exchange property if, for all `X` and `Y` satisfying `P`\n  and all `a ∈ X \\ Y`, there is some `b ∈ Y \\ X` so that swapping `a` for `b` in `X` maintains `P`.\n-/\ndef exchange_property (P : set E → Prop) : Prop :=\n  ∀ X Y, P X → P Y → ∀ a, a ∈ X \\ Y → ∃ b, b ∈ Y \\ X ∧ P (X \\ {a} ∪ {b}) \n\n/-- \n  A `matroid` is a nonempty collection of sets satisfying the exchange property. Each such set \n  is called a `base` of the matroid. \n-/\n@[ext] structure matroid (E : Type*) :=\n  (base : set E → Prop)\n  (exists_base' : ∃ B, base B) \n  (base_exchange' : exchange_property base)\n\nnamespace matroid \n\nvariables [fintype E] {B B' B₁ B₂ I I' J I₁ I₂ J' X Y Z : set E} {M M₁ M₂ : matroid E}\n\nlemma exists_base (M : matroid E) : ∃ B, M.base B := M.exists_base'\n\nlemma base_exchange {M : matroid E} {B₁ B₂ : set E} {x : E} \n(hB₁ : M.base B₁) (hB₂ : M.base B₂) (hxB₁ : x ∈ B₁) (hxB₂ : x ∉ B₂) : \n  ∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.base (B₁ \\ {x} ∪ {y})   := \nM.base_exchange' B₁ B₂ hB₁ hB₂ x ⟨hxB₁,hxB₂⟩\n  \nlemma base.card_eq_card_of_base (hB₁ : M.base B₁) (hB₂ : M.base B₂) :\n  B₁.to_finset.card = B₂.to_finset.card := \nbegin\n  suffices h : ∀ i (B B' : finset E), M.base B → M.base B' → (B' \\ B).card ≤ i → \n    B'.card ≤ B.card, \n  { exact (h _ B₂.to_finset B₁.to_finset (by simpa) (by simpa) rfl.le).antisymm \n          (h _ B₁.to_finset B₂.to_finset (by simpa) (by simpa) rfl.le), }, \n  clear hB₁ B₁ hB₂ B₂, \n  intro i, \n  induction i with i IH, \n  { rintros B B' - - h, \n    simp only [le_zero_iff, finset.card_eq_zero, finset.sdiff_eq_empty_iff_subset] at h, \n    apply finset.card_mono, exact finset.le_iff_subset.mpr h},  \n  refine λ B B' hB hB' hcard, le_of_not_lt (λ hlt, _ ) , \n  obtain ⟨x, hxB', hxB⟩ := finset.exists_mem_sdiff_of_card_lt_card hlt,  \n\n  obtain ⟨y, ⟨(hyB : y ∈ B), (hyB' : y ∉ B')⟩, hB''⟩ := base_exchange hB' hB hxB' hxB, \n\n  have hcard := IH B (B' \\ {x} ∪ {y})  hB (by simpa using hB'') _, \n  { apply hlt.not_le, \n    rwa [finset.union_comm, ← finset.insert_eq, finset.card_insert_of_not_mem, \n      finset.sdiff_singleton_eq_erase, finset.card_erase_add_one hxB'] at hcard,\n    simpa using hyB'},\n  \n  suffices hss : (B' \\ {x} ∪ {y}) \\ B ⊂ B' \\ B, \n  { exact nat.le_of_lt_succ ((finset.card_lt_card hss).trans_le hcard)},\n\n  refine (finset.ssubset_iff_of_subset (λ a, _) ).mpr ⟨x,  _⟩, \n  { simp only [finset.mem_sdiff, finset.mem_union, finset.mem_singleton, and_imp],\n    rintros (⟨haB',hax⟩ | rfl) haB,  tauto, tauto},\n  \n  simp only [finset.mem_sdiff, finset.mem_union, finset.mem_singleton, eq_self_iff_true, not_true, \n    and_false, false_or, not_and, not_not, exists_prop], \n  \n  refine ⟨⟨hxB', hxB⟩, _⟩, \n  rintro rfl, exact hyB, \nend \n\nsection indep \n\n/-- A set is independent in a matroid if it is contained in a base.  -/\ndef indep {E : Type*} (M : matroid E) : set E → Prop := λ I, ∃ B, M.base B ∧ I ⊆ B   \n\nlemma indep_iff_subset_base :\n  M.indep I ↔ ∃ B, M.base B ∧ I ⊆ B :=\niff.rfl \n\nlemma empty_indep (M : matroid E) : M.indep ∅ := \n  exists.elim M.exists_base (λ B hB, ⟨_, hB, B.empty_subset⟩)\n\nlemma indep_mono {M : matroid E} {I J : set E} (hIJ : I ⊆ J) (hJ : M.indep J) : M.indep I :=\nby {obtain ⟨B, hB, hJB⟩ := hJ, exact ⟨B, hB, hIJ.trans hJB⟩}\n\nlemma indep.subset (hJ : M.indep J) (hIJ : I ⊆ J) : M.indep I :=\nby {obtain ⟨B, hB, hJB⟩ := hJ, exact ⟨B, hB, hIJ.trans hJB⟩}\n\n/-- The independence augmentation axiom; given independent sets `I,J` with `I` smaller than `J`, \n  there is an element `e` of `J \\ I` whose insertion into `e` is an independent set.  -/\nlemma indep.augment (hI : M.indep I) (hJ : M.indep J) (hIJ : I.to_finset.card < J.to_finset.card) : \n  ∃ x ∈ J, x ∉ I ∧ M.indep (insert x I) :=\nbegin\n  suffices h_mod : ∀ {p} {I₁ I₂ B₁ B₂}, M.base B₁ → M.base B₂ → I₁ ⊆ B₁ → I₂ ⊆ B₂ →\n    I₁.to_finset.card < I₂.to_finset.card → (B₂ \\ (I₂ ∪ B₁)).to_finset.card = p →  \n      ∃ x ∈ I₂, x ∉ I₁ ∧ M.indep (insert x I₁), \n  { obtain ⟨⟨BI,hBI,hIBI⟩,⟨BJ, hBJ, hJBJ⟩⟩ := ⟨hI,hJ⟩,\n    exact h_mod hBI hBJ hIBI hJBJ hIJ rfl },         \n  clear hI hJ hIJ I J,\n  intro p, induction p with p IH, \n  all_goals \n  { intros _ _ _ _ hB₁ hB₂ hI₁B₁ hI₂B₂ h_lt h_le} , \n  { simp only [to_finset_diff, finset.card_eq_zero, finset.sdiff_eq_empty_iff_subset, \n      to_finset_subset, coe_to_finset] at h_le, \n    \n    by_contradiction h_con, push_neg at h_con, \n\n    have h₁₂ : B₂ \\ B₁ = I₂ \\ I₁, \n    { apply subset_antisymm, \n      {  calc _ ⊆ _  : diff_subset_diff_left h_le  \n            ... = _  : union_diff_right\n             ... ⊆ _ : diff_subset_diff_right hI₁B₁}, \n      rintros x ⟨hxI₂, hxI₁⟩,  \n      exact ⟨mem_of_mem_of_subset hxI₂ hI₂B₂, \n        λ hxB₁, h_con _ hxI₂ hxI₁ ⟨B₁, hB₁, insert_subset.mpr ⟨ hxB₁,hI₁B₁⟩⟩⟩}, \n\n    have hB₁ss : B₁ ⊆ I₁ ∪ B₂,\n    { intros y hyB₁, \n      rw [mem_union, or_iff_not_imp_right],   \n      intro hyB₂, \n      obtain ⟨x,⟨hxB₂, hxB₁⟩, hB'⟩ := base_exchange hB₁ hB₂ hyB₁ hyB₂,  \n      obtain (hxI₂ | hxB₁') := mem_of_mem_of_subset hxB₂ h_le, \n      swap, exact (hxB₁ hxB₁').elim,\n      by_contradiction hyI₁, \n      refine h_con x hxI₂ (not_mem_subset hI₁B₁ hxB₁) \n        ⟨_, hB', insert_subset.mpr ⟨by simp, subset_union_of_subset_left _ _⟩⟩,  \n      apply subset_diff_singleton hI₁B₁ hyI₁},\n    have hss₁ := calc B₁ \\ B₂ ⊆ _       : diff_subset_diff_left hB₁ss  \n                          ... = _       : union_diff_right\n                          ... ⊆ I₁ \\ I₂ : diff_subset_diff_right hI₂B₂,   \n\n    rw [← to_finset_subset_to_finset, to_finset_diff, to_finset_diff] at hss₁, \n\n    have hle₁ := finset.card_mono hss₁, \n    simp_rw [finset.card_sdiff_eq_card_sdiff_iff_card_eq_card.mp (hB₁.card_eq_card_of_base hB₂), \n      ← to_finset_diff, h₁₂, to_finset_diff, ← finset.card_le_card_iff_card_sdiff_le_card_sdiff] \n      at hle₁, \n    exact h_lt.not_le hle₁},\n  have h_ne : (B₂ \\ (I₂ ∪ B₁)).nonempty, \n  { rw [← set.to_finset_nonempty, ←finset.card_pos, h_le], apply nat.succ_pos _},\n  obtain ⟨x, hxB₂, hx'⟩ := h_ne, \n  rw [set.mem_union, not_or_distrib] at hx', obtain ⟨hxI₂, hxB₁⟩:= hx',  \n  obtain ⟨y, ⟨hyB₁, hyB₂⟩, hB'⟩ := base_exchange hB₂ hB₁ hxB₂ hxB₁,  \n  have hI₂B' : I₂ ⊆ B₂ \\ {x} ∪ {y}, \n  { apply set.subset_union_of_subset_left, apply subset_diff_singleton hI₂B₂ hxI₂},\n\n  refine IH hB₁ hB' hI₁B₁ hI₂B' h_lt _, \n  suffices h_set_eq : (B₂ \\ {x} ∪ {y}) \\ (I₂ ∪ B₁) = (B₂ \\ (I₂ ∪ B₁)) \\ {x},   \n  { simp_rw h_set_eq,  rw [to_finset_diff, finset.card_sdiff, h_le], \n    { simp},\n    simp only [to_finset_subset, coe_to_finset, singleton_subset_iff, mem_diff, mem_union], \n    tauto},\n  rw [union_singleton, insert_diff_of_mem _ (mem_union_right _ hyB₁)],\n  rw [diff_diff_comm], \nend \n\n/-- The independence augmentation axiom in a form that finds a strict superset -/\nlemma indep.ssubset_indep_of_card_lt (hI : M.indep I) (hJ : M.indep J) \n(hIJ : I.to_finset.card < J.to_finset.card) : \n  ∃ I', M.indep I' ∧ I ⊂ I' ∧ I' ⊆ I ∪ J := \nbegin\n  obtain ⟨e, heJ, heI, hI'⟩ := hI.augment hJ hIJ, \n  exact ⟨_, hI', ssubset_insert heI, insert_subset.mpr ⟨or.inr heJ,subset_union_left _ _⟩⟩,  \nend \n\nlemma base.indep (hB : M.base B) : M.indep B := ⟨B, hB, subset_rfl⟩ \n\nlemma base.subset_indep (hB : M.base B) (hIB : I ⊆ B) : M.indep I := hB.indep.subset hIB\n\nlemma base.eq_of_subset_indep (hB : M.base B) (hI : M.indep I) (hBI : B ⊆ I) : \n  B = I :=\nbegin\n  refine to_finset_inj.mp (finset.eq_of_subset_of_card_le (by simpa) _), \n  obtain ⟨B', hB', hIB'⟩ := hI, \n  rw hB.card_eq_card_of_base hB', \n  apply finset.card_mono, \n  simpa, \nend \n\nlemma base.eq_of_subset_base (hB₁ : M.base B₁) (hB₂ : M.base B₂) (hB₁B₂ : B₁ ⊆ B₂) : \n  B₁ = B₂ :=\nhB₁.eq_of_subset_indep (hB₂.indep) hB₁B₂\n\nlemma base_iff_maximal_indep : M.base B ↔ M.indep B ∧ ∀ I, M.indep I → B ⊆ I → B = I :=\nbegin\n  refine ⟨λ h, ⟨h.indep, λ _, h.eq_of_subset_indep ⟩,λ h, _⟩, \n  obtain ⟨⟨B', hB', hBB'⟩, h⟩ := h, \n  rwa h _ hB'.indep hBB', \nend  \n\nlemma eq_of_indep_iff_indep_forall (h : ∀ I, (M₁.indep I ↔ M₂.indep I)) : \n  M₁ = M₂ := \nbegin\n  ext B,\n  have hI : M₁.indep = M₂.indep, by { ext ,apply h},\n  simp_rw [base_iff_maximal_indep, hI],  \nend \n\n\nend indep \n\nsection basis\n\n/-- A `basis` of a set `X` is a maximal independent subset of `X` -/\ndef basis {E : Type*} (M : matroid E) (I X : set E) := \nM.indep I ∧ I ⊆ X ∧ ∀ J, M.indep J → I ⊆ J → J ⊆ X → I = J \n\nlemma basis.indep (hI : M.basis I X) : M.indep I := hI.1\n\nlemma basis.subset (hI : M.basis I X) : I ⊆ X := hI.2.1\n\nlemma basis_iff : \n  M.basis I X ↔ M.indep I ∧ I ⊆ X ∧ ∀ J, M.indep J → I ⊆ J → J ⊆ X → I = J := \niff.rfl \n\nlemma basis.eq_of_subset_indep (hI : M.basis I X) {J : set E} (hJ : M.indep J) (hIJ : I ⊆ J) \n(hJX : J ⊆ X) : \n  I = J := \nhI.2.2 J hJ hIJ hJX\n\nlemma indep.subset_basis_of_subset (hI₁ : M.indep I₁) (hI₁X : I₁ ⊆ X) : \n  ∃ I, I₁ ⊆ I ∧ M.basis I X := \nbegin\n  set inds_of : finset (set E) := {I | M.indep I ∧ I₁ ⊆ I ∧ I ⊆ X}.to_finset with hbdef,\n  have hne : inds_of.nonempty, \n    from to_finset_nonempty.mp ⟨I₁,by {simp only [finset.mem_val, mem_to_finset, mem_set_of_eq],\n      exact ⟨hI₁, subset_refl _, hI₁X⟩}⟩,\n  have h' := inds_of.exists_max_image (λ I, I.to_finset.card) hne, \n  simp only [mem_to_finset, mem_set_of_eq, and_imp, exists_prop] at h', \n  obtain ⟨I, ⟨hI, hI₁I, hIX⟩,hJ⟩ := h',   \n  refine ⟨I, hI₁I, hI, hIX, λ I' hI' hII' hI'X, _⟩,  \n  simpa using finset.eq_of_subset_of_card_le _ (hJ _ hI' (hI₁I.trans hII') hI'X),\n  simpa,  \nend \n\nlemma indep.le_card_basis (hI : M.indep I) (hIX : I ⊆ X) (hJX : M.basis J X) : \n  I.to_finset.card ≤ J.to_finset.card :=\nbegin\n  refine le_of_not_lt (λ hlt, _), \n  obtain ⟨I', hI'⟩ := hJX.indep.ssubset_indep_of_card_lt hI hlt, \n  have := hJX.eq_of_subset_indep hI'.1 hI'.2.1.subset (hI'.2.2.trans (union_subset hJX.subset hIX)),\n  subst this, \n  exact hI'.2.1.ne rfl, \nend \n\nlemma exists_basis (M : matroid E) (X : set E) : \n  ∃ I, M.basis I X :=\nby {obtain ⟨I, -, hI⟩ := M.empty_indep.subset_basis_of_subset (empty_subset X), exact ⟨_,hI⟩, }\n\nlemma base_iff_basis_univ : \n  M.base B ↔ M.basis B univ := \nby {rw [base_iff_maximal_indep, basis], simp}\n\nend basis\n\nsection rank \n\n/-- The rank function of a matroid. This is defined using `nat.card`, to avoid a fintype instance \n  so as not to carry around data (it has the junk value `0` if `X` is infinite) -/\nnoncomputable def r {E : Type*} (M : matroid E) : set E → ℕ := \n  λ X, nat.find_greatest (λ n, ∃ I, I ⊆ X ∧ M.indep I ∧ n = nat.card I) (nat.card X)\n\n/-- The rank `M.rk` of a matroid `M` is the rank of its ground set -/\n@[reducible] noncomputable def rk (M : matroid E) := M.r univ  \n\n/-- This is the useful definition of rank -/\nlemma eq_r_iff {n : ℕ} : M.r X = n ↔ ∃ I, M.basis I X ∧ I.to_finset.card = n :=\nbegin\n  simp_rw [matroid.r, nat.find_greatest_eq_iff, nat.card_eq_to_finset_card, ne.def, \n    ←or_iff_not_imp_left, not_exists], push_neg, \n  split, \n  { rintros ⟨hnX, rfl | ⟨I, hIX, hI, rfl⟩, h⟩, \n    { simp_rw [pos_iff_ne_zero, ←or_iff_not_imp_left] at h, \n      obtain ⟨I, hI⟩ := M.exists_basis X, \n      refine ⟨I, hI, (@h I.to_finset.card).elim id (λ h', _)⟩,   \n      exact (h' (finset.card_mono (by simpa using hI.subset)) I hI.subset hI.indep rfl).elim}, \n    refine ⟨I, ⟨hI, hIX, λ J hJ hIJ hJX,  \n      (eq_or_ssubset_of_subset hIJ).elim id (λ hIssJ, false.elim _)⟩, rfl⟩, \n    exact h (finset.card_lt_card (to_finset_ssubset_to_finset.mpr hIssJ))\n      (finset.card_le_of_subset (to_finset_subset_to_finset.mpr hJX)) J hJX hJ rfl}, \n  rintros ⟨I, ⟨hIX, rfl⟩⟩,\n  refine ⟨finset.card_mono (by simpa using hIX.subset),or.inr ⟨I,hIX.subset,hIX.indep,rfl⟩,_⟩,\n  rintro n hIn hnX J hJX hJ rfl,    \n  exact hIn.not_le (hJ.le_card_basis hJX hIX),\nend \n\nlemma le_r_iff {X : set E} {n : ℕ} : n ≤ M.r X ↔ ∃ I, M.indep I ∧ I ⊆ X ∧ I.to_finset.card = n :=\nbegin\n  obtain ⟨J, hJ⟩ := eq_r_iff.mp (@rfl _ (M.r X)), \n  refine ⟨λ h, _, λ h, _⟩,\n  { obtain ⟨I', hI', rfl⟩ := finset.exists_smaller_set _ _ (h.trans_eq hJ.2.symm), \n    rw [subset_to_finset] at hI', \n    exact ⟨I', hJ.1.indep.subset hI', hI'.trans hJ.1.subset, by simp⟩},\n  obtain ⟨I, hI, hIX, rfl⟩ := h,\n  rw ←hJ.2, \n  exact hI.le_card_basis hIX hJ.1,  \nend    \n\nlemma r_le_iff {X : set E} {n : ℕ} : \n  M.r X ≤ n ↔ (∀ I, M.indep I → I ⊆ X → I.to_finset.card ≤ n) :=\nbegin\n  obtain ⟨I, hIX, hI⟩ := eq_r_iff.mp (@rfl _ (M.r X)), \n  refine ⟨λ h J hJ hJX, (hJ.le_card_basis hJX hIX).trans (by rwa hI), λ h, _⟩,\n  have := h I hIX.indep hIX.subset, rwa ←hI, \nend \n\nlemma basis.card (hIX : M.basis I X) : \n  I.to_finset.card = M.r X := \nby {rw [eq_comm, eq_r_iff], exact ⟨_, hIX, rfl⟩}\n\nlemma indep.r (hI : M.indep I) : \n  M.r I = I.to_finset.card := \neq_r_iff.mpr ⟨I, ⟨hI, subset_refl _, λ _ _, subset_antisymm⟩, rfl⟩\n\nlemma basis.r (hIX : M.basis I X) : \n  M.r I = M.r X := \nby rw [←hIX.card, hIX.indep.r]\n\nlemma indep_iff_r_eq_card : \n  M.indep I ↔ M.r I = I.to_finset.card := \nbegin\n  refine ⟨indep.r ,λ h, _⟩, \n  obtain ⟨J, hJ, hJI, hJcard⟩ := le_r_iff.mp h.symm.le, \n  suffices hIJ : J = I, rwa ←hIJ, \n  rw ← to_finset_inj, \n  exact finset.eq_of_subset_of_card_le (by simpa) hJcard.symm.le,\nend \n\n@[simp] lemma r_empty (M : matroid E) : \n  M.r ∅ = 0 :=\nby rw [M.empty_indep.r, to_finset_empty, finset.card_empty] \n\nlemma r_le_card (M : matroid E) (X : set E) : \n  M.r X ≤ X.to_finset.card :=\nr_le_iff.mpr (λ I hI hIX, finset.card_mono (by simpa))\n\nlemma r_mono (M : matroid E) {X Y : set E} (hXY : X ⊆ Y) : \n  M.r X ≤ M.r Y :=\nby {simp_rw [r_le_iff, le_r_iff], exact λ I hI hIX, ⟨I,hI,hIX.trans hXY,rfl⟩}\n\nlemma base.r (hB : M.base B) : \n  M.r B = M.rk := \nby {rw [base_iff_basis_univ] at hB, rw hB.r}\n\nlemma base_iff_indep_r : \n  M.base B ↔ M.indep B ∧ M.r B = M.rk :=\nbegin\n  refine ⟨λ h, ⟨h.indep, h.r⟩, λ h, base_iff_maximal_indep.mpr ⟨h.1, λ I hI hBI, _⟩⟩, \n  refine eq_of_le_of_not_lt hBI (λ hBI' : B ⊂ I, _), \n  cases h with hB hB', \n  rw [hB.r] at hB', \n  have := finset.card_lt_card (to_finset_ssubset_to_finset.mpr hBI'), \n  rw [←hI.r, hB'] at this, \n  exact (M.r_mono (subset_univ _)).not_lt this, \nend\n\nlemma basis.r_eq_r_union (hIX : M.basis I X) (Y : set E) :\n  M.r (I ∪ Y) = M.r (X ∪ Y) := \nbegin\n  refine (M.r_mono (union_subset_union_left _ hIX.subset)).antisymm _, \n  obtain ⟨I', hII', hI'⟩ := \n    hIX.indep.subset_basis_of_subset (hIX.subset.trans (subset_union_left _ Y)), \n  rw [←hI'.r], \n  refine M.r_mono (λ z hz, by_contra (λ hz', _)), \n  rw [mem_union, decidable.not_or_iff_and_not] at hz', \n  have hzX : z ∈ X, {cases (mem_of_mem_of_subset hz hI'.subset); tauto},\n  \n  have := hIX.eq_of_subset_indep \n    (hI'.indep.subset (insert_subset.mpr ⟨hz,hII'⟩)) \n    (subset_insert z I) (insert_subset.mpr ⟨hzX, hIX.subset⟩), \n  rw [eq_comm, insert_eq_self] at this, \n  exact hz'.1 this, \nend\n\n/-- The submodularity axiom for the rank function -/\nlemma r_inter_add_r_union_le_r_add_r (M : matroid E) (X Y : set E) : \n  M.r (X ∩ Y) + M.r (X ∪ Y) ≤ M.r X + M.r Y :=\nbegin\n  obtain ⟨Ii, hIi⟩ := M.exists_basis (X ∩ Y), \n  obtain ⟨IX, hIX, hIX'⟩ := \n    hIi.indep.subset_basis_of_subset (hIi.subset.trans (inter_subset_left _ _)),  \n  obtain ⟨IY, hIY, hIY'⟩ := \n    hIi.indep.subset_basis_of_subset (hIi.subset.trans (inter_subset_right _ _)),  \n  rw [←hIX'.r_eq_r_union, union_comm, ←hIY'.r_eq_r_union, ←hIi.card, ←hIX'.card, ←hIY'.card, \n    ←finset.card_inter_add_card_union, ←to_finset_inter, ←to_finset_union, union_comm], \n  refine add_le_add \n    (finset.card_mono (to_finset_subset_to_finset.mpr (subset_inter hIX hIY))) _, \n  convert M.r_le_card (IX ∪ IY), \nend  \n\nlemma eq_of_r_eq_r_forall (h : ∀ X, M₁.r X = M₂.r X) : \n  M₁ = M₂ := \neq_of_indep_iff_indep_forall (λ I, by simp_rw [indep_iff_r_eq_card,h I])\n  \nend rank \n\nend matroid \n\nsection constructions\n\n/-- Constructions of matroids from other descriptions -/\n\nvariables [finite E]\n\n/-- A collection of sets satisfying the independence axioms determines a matroid -/\ndef matroid_of_indep (indep : set E → Prop) \n(exists_ind : ∃ I, indep I)\n(ind_mono : ∀ I J, I ⊆ J → indep J → indep I)\n(ind_aug : ∀ I J, indep I → indep J → nat.card I < nat.card J →\n  ∃ e ∈ J, e ∉ I ∧ indep (insert e I)) : \n  matroid E :=\n{ base := λ B, indep B ∧ ∀ X, indep X → B ⊆ X → X = B,\n  exists_base' := \n    by exact \n      (@set.finite.exists_maximal_wrt (set E) (set E) _ id indep (to_finite _) exists_ind).imp \n      (λ B hB, exists.elim hB (λ hB h, ⟨hB, λ X hX hBX, (h X hX hBX).symm⟩)), \n  base_exchange' := \n  begin\n    haveI := fintype.of_finite E, \n    simp_rw nat.card_eq_to_finset_card at ind_aug, \n    set is_base := λ (B : set E), indep B ∧ ∀ X, indep X → B ⊆ X → X = B with hbase, \n    rintro B₁ B₂ hB₁ hB₂ x ⟨hxB₁,hxB₂⟩,\n\n    have h_base_iff : ∀ B B' (hB' : is_base B'),\n      is_base B ↔ indep B ∧ B'.to_finset.card ≤ B.to_finset.card, \n    { intros B B' hB', split, \n      { refine λ hB, ⟨hB.1, le_of_not_lt (λ hlt, _)⟩, \n        obtain ⟨e,heB,heB',he⟩ := ind_aug B B' hB.1 hB'.1 hlt, \n        exact heB' (by simpa using hB.2 _ he (subset_insert _ _))},  \n      rintros ⟨hBI, hB'B⟩ , \n      refine ⟨hBI, λ J hJ hBJ, (hBJ.antisymm (by_contra (λhJB, _))).symm⟩, \n      have hss := ssubset_of_subset_not_subset hBJ hJB, \n      obtain ⟨e,heJ,heB',he⟩ := \n        ind_aug B' J hB'.1 hJ (hB'B.trans_lt (finset.card_lt_card (by simpa))), \n      exact heB' (by simpa using hB'.2 _ he (subset_insert _ _))},\n    \n    simp_rw [h_base_iff _ _ hB₁, mem_diff, union_singleton], \n    have hcard : (B₁ \\ {x}).to_finset.card < B₂.to_finset.card, \n    { rw [nat.lt_iff_add_one_le, to_finset_diff, to_finset_singleton, \n      finset.sdiff_singleton_eq_erase, finset.card_erase_add_one (mem_to_finset.mpr hxB₁)],\n      exact ((h_base_iff _ _ hB₁).mp hB₂).2},\n\n    obtain ⟨e,heB₂,heB₁,he⟩ := \n      ind_aug (B₁ \\ {x}) B₂ (ind_mono _ _ (diff_subset _ _) hB₁.1) hB₂.1 (by convert hcard), \n    \n    have hex : e ≠ x := by {rintro rfl, simpa using heB₁}, \n    have heB₁ : e ∉ B₁,\n    { simp only [mem_diff, mem_singleton_iff, not_and, not_not] at heB₁, \n      exact λ h, hex (heB₁ h)},\n\n    refine ⟨e,⟨heB₂,heB₁⟩,he,_⟩, \n    rw [to_finset_insert, finset.card_insert_of_not_mem, to_finset_diff, to_finset_singleton, \n      finset.sdiff_singleton_eq_erase, finset.card_erase_add_one];\n    simpa,\n  end  }\n\n@[simp] lemma matroid_of_indep_base_iff {indep : set E → Prop} \n  (exists_ind : ∃ I, indep I)\n  (ind_mono : ∀ I J, I ⊆ J → indep J → indep I)\n  (ind_aug : ∀ I J, indep I → indep J → nat.card I < nat.card J →\n    ∃ e ∈ J, e ∉ I ∧ indep (insert e I)) {B : set E }: \n(matroid_of_indep indep exists_ind ind_mono ind_aug).base B ↔ \n  indep B ∧ ∀ X, indep X → B ⊆ X → X = B :=\niff.rfl \n\n@[simp] lemma matroid_of_indep_apply {indep : set E → Prop} \n  (exists_ind : ∃ I, indep I)\n  (ind_mono : ∀ I J, I ⊆ J → indep J → indep I)\n  (ind_aug : ∀ I J, indep I → indep J → nat.card I < nat.card J →\n    ∃ e ∈ J, e ∉ I ∧ indep (insert e I)) : \n  (matroid_of_indep indep exists_ind ind_mono ind_aug).indep = indep :=\nbegin\n  haveI := fintype.of_finite E, \n  ext I,\n  simp_rw [matroid.indep_iff_subset_base, matroid_of_indep], \n  split, \n  { rintro ⟨B, ⟨hBi,hB⟩, hIB⟩, \n    exact ind_mono _ _ hIB hBi},\n  intro hI, \n  obtain ⟨B,hBi, hB⟩ := \n    @set.finite.exists_maximal_wrt (set E) (set E) _ id {J | I ⊆ J ∧ indep J} (to_finite _)\n    ⟨I, subset_refl I, hI⟩, \n  simp only [mem_set_of_eq, id.def, le_eq_subset, and_imp] at hB hBi, \n  exact ⟨B, ⟨hBi.2, λ X hX hBX, (hB _ (hBi.1.trans hBX) hX hBX).symm⟩, hBi.1⟩, \nend \n\nlemma r_eq_card_of_subset_of_r_le_card_submod (r : set E → ℕ) (r_le_card : ∀ X, r X ≤ nat.card X) \n(r_submod : ∀ X Y, r (X ∩ Y) + r (X ∪ Y) ≤ r X + r Y) \n{I J : set E} (hIJ : I ⊆ J) (hJ : r J = nat.card J) :\n  r I = nat.card I := \nbegin\n  haveI := fintype.of_finite E, \n  refine le_antisymm (r_le_card I) _,  \n  have rdiff := r_le_card (J \\ I), \n  rw [nat.card_eq_to_finset_card] at ⊢ hJ rdiff, \n  rw [to_finset_diff] at rdiff, \n\n  have h := r_submod I (J \\ I), \n  have r_empt : r ∅ = 0, simpa using ((r_le_card ∅).antisymm (by simp)), \n  rw [inter_diff_self, r_empt, zero_add, union_diff_cancel hIJ, hJ] at h,\n  have := finset.card_sdiff_add_card_eq_card (to_finset_subset_to_finset.mpr hIJ), \n  linarith, \nend \n \nlemma extend_to_basis_of_r (r : set E → ℕ) (r_le_card : ∀ X, r X ≤ nat.card X)\n(r_mono : ∀ X Y, X ⊆ Y → r X ≤ r Y) (r_submod : ∀ X Y, r (X ∩ Y) + r (X ∪ Y) ≤ r X + r Y) \n(I X : set E) (hI : r I = nat.card I) (hIX : I ⊆ X) :\n  ∃ J, I ⊆ J ∧ J ⊆ X ∧ r J = nat.card J ∧ r J = r X :=  \nbegin\n  haveI := fintype.of_finite E, \n  obtain ⟨J, ⟨hIJ, hJX, hJ₀⟩, hJ'⟩ := \n   finite.exists_maximal (λ J, I ⊆ J ∧ J ⊆ X ∧ nat.card J ≤ r J) (⟨I, rfl.subset, hIX, hI.symm.le⟩), \n  have hJ := hJ₀.antisymm' (r_le_card _), \n  refine ⟨J, hIJ, hJX, hJ, hJX.ssubset_or_eq.elim (λ hJX', _) (congr_arg _)⟩,  \n  obtain ⟨Y, ⟨hJY,hYX,hYr⟩, hYmax⟩ :=\n   finite.exists_maximal (λ Y, J ⊆ Y ∧ Y ⊆ X ∧ r Y ≤ r J) ⟨J, rfl.subset, hJX, rfl.le⟩,\n  refine hYX.ssubset_or_eq.elim (λ hYX, false.elim _) \n    (by {rintro rfl, exact (r_mono _  _ hJX).antisymm hYr,}),  \n  obtain ⟨e,heX,heY⟩ := exists_of_ssubset hYX,  \n  have heJ : e ∉ J := λ heJ, heY (mem_of_mem_of_subset heJ hJY), \n  have hsm := r_submod (J ∪ {e}) Y, \n  \n  rw [inter_distrib_right, singleton_inter_eq_empty.mpr heY, union_empty, \n    inter_eq_self_of_subset_left hJY, union_right_comm, union_eq_self_of_subset_left hJY] at hsm, \n  \n  have hYe : r Y < r (Y ∪ {e}), \n  { rw [lt_iff_not_le],\n    intro hYe, \n    rw  hYmax (Y ∪ {e}) \n     ⟨hJY.trans (subset_union_left _ _),union_subset hYX.subset (singleton_subset_iff.mpr heX), \n     (hYe.trans hYr)⟩ (subset_union_left _ _) at heY,\n    simpa using heY},\n  have hJe : r (J ∪ {e}) ≤ r J, \n  { refine le_of_not_lt (λ h',  h'.ne _),\n    rw ←(hJ' (J ∪ {e}) ⟨subset_union_of_subset_left hIJ _,union_subset hJX (by simpa),_⟩ \n      (subset_union_left _ _)),\n    rwa [union_singleton, nat.card_eq_to_finset_card, to_finset_insert, \n      finset.card_insert_of_not_mem (by simpa : e ∉ J.to_finset), nat.add_one_le_iff, \n      ←nat.card_eq_to_finset_card, ←hJ, ←union_singleton ]},\n  linarith, \nend \n\n/-- A function `r` satisfying the rank axioms determines a matroid -/\ndef matroid_of_r (r : set E → ℕ) (r_le_card : ∀ X, r X ≤ nat.card X) \n(r_mono : ∀ X Y, X ⊆ Y → r X ≤ r Y) (r_submod : ∀ X Y, r (X ∩ Y) + r (X ∪ Y) ≤ r X + r Y) :\n  matroid E :=\nmatroid_of_indep (λ I, r I = nat.card I)\n⟨∅, (r_le_card _).antisymm (by simp)⟩  \n(λ _ _, r_eq_card_of_subset_of_r_le_card_submod r r_le_card r_submod) \n(begin\n  haveI := fintype.of_finite E,\n  intros I J hI hJ hIJ, \n  obtain ⟨K,hIK, hKIJ, hK, hrK⟩ :=\n   extend_to_basis_of_r r r_le_card r_mono r_submod _ _ hI (subset_union_left _ J), \n  refine (ssubset_or_eq_of_subset hIK).elim (λ hss, _) _, \n  { refine (exists_of_ssubset hss).imp _,\n    rintro e ⟨heK,heI⟩,\n    simp only [nat.card_eq_fintype_card, fintype.card_of_finset, exists_prop, \n      nat.card_eq_to_finset_card], \n    have heJ : e ∈ J, { by_contra, cases (hKIJ heK); tauto },  \n    refine ⟨heJ, heI, _⟩, \n    rw ←nat.card_eq_to_finset_card,   \n    exact r_eq_card_of_subset_of_r_le_card_submod r r_le_card r_submod \n      (insert_subset.mpr ⟨heK, hIK⟩) hK},\n  rintro rfl, \n  simp_rw [←hI, ←hJ, hrK] at hIJ, \n  exact (hIJ.not_le (r_mono _ _ (subset_union_right _ _))).elim, \nend) \n\n@[simp] lemma matroid_of_r_apply (r : set E → ℕ) (r_le_card : ∀ X, r X ≤ nat.card X)\n(r_mono : ∀ X Y, X ⊆ Y → r X ≤ r Y) (r_submod : ∀ X Y, r (X ∩ Y) + r (X ∪ Y) ≤ r X + r Y) : \n  (matroid_of_r r r_le_card r_mono r_submod).r = r :=\nbegin\n  ext X, \n  haveI := fintype.of_finite E, \n  simp_rw [matroid_of_r, matroid.eq_r_iff, matroid.basis_iff, matroid_of_indep_apply], \n  obtain ⟨I,-,hIX,hI,hIX'⟩ :=\n   extend_to_basis_of_r r r_le_card r_mono r_submod ∅ X (by simpa using r_le_card ∅) \n    (empty_subset _), \n  refine ⟨I, ⟨⟨hI,hIX,λJ hJ hIJ hJX, \n    (ssubset_or_eq_of_subset hIJ).elim (λ hIJ',false.elim _) id⟩,\n      by rwa [←hIX', eq_comm, ←nat.card_eq_to_finset_card]⟩⟩, \n  -- rw [nat.card_eq_to_finset_card] at hI hJ, \n  have h' := r_mono _ _ hJX, \n  have hlt := finset.card_lt_card (to_finset_ssubset_to_finset.mpr hIJ'), \n  rw [←nat.card_eq_to_finset_card, ←nat.card_eq_to_finset_card, ←hI, ←hJ] at hlt,\n  linarith, \nend \n\n\nend constructions\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.7872734682438929}}
{"text": "import BrownCs22.Library.Tactics\n\n/-\n\nIn this file, we'll prove some of the identities from\nhttps://brown-cs22.github.io/resources/math-resources/logic.pdf \n\nNote that these identities are stated with the symbol `≡`,\nmeaning \"the formula on the left is equivalent to the formula on the right.\"\nIn Lean, we can use iff (bi-implication, `↔`) to mean the same thing.\n\nRemember the tactics we learned in Lecture 4. \nWe'll see a bit of new Lean syntax along the way.\n\nAlso remember that it doesn't matter what we name our hypotheses.\nIn our examples, we use patterns like `hp` for the hypothesis `p`,\n`hnpq` for the hypothesis `¬ p ∧ q` (hnpq for \"hypothesis not p q\"), etc.\nBut this is just a custom. You can choose any names you want.\nAs they say, the hardest problem in computer science is naming variables.\n\nYour task: fill in all the `sorry`s with proofs!\n\n-/\n\nvariable (p q r : Prop)\n\n-- ## Commutative Laws\n\n-- We'll do the first for you, as an example.\n-- Notice two things.\n-- One, must of these problems will start with `split_goal`,\n-- to turn the `iff` goal into two `implies` goals.\n-- Two, we structure our proof by putting each *subproof* in `{...}`.\n-- This isn't necessary but it helps with organization!\nexample : p ∧ q ↔ q ∧ p := by \n  split_goal \n  { intro hpq \n    eliminate hpq with hp hq \n    split_goal \n    assumption \n    assumption }\n  { intro hqp \n    eliminate hqp with hq hp \n    split_goal \n    assumption \n    assumption }\n\nexample : p ∨ q ↔ q ∨ p := by \n  sorry\n\n-- ## Associative laws \n\n-- Notice that Lean doesn't print parentheses unless it needs to.\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := by \n  sorry \n\n\n-- This is getting a little repetitive. \n-- To mix it up, we'll only do one direction of the iff this time.\n-- You won't start with `split_goal`, but instead, ... what?\nexample : (p ∨ q) ∨ r → p ∨ (q ∨ r) := by \n  sorry \n\n-- ## Distributive laws \n\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := by \n  sorry \n\n-- Again, let's just do one direction. \n-- When we're proving an implication `→`, we'll always start with `intro`. \n-- This is such a common pattern that Lean gives us special syntax for it:\n-- we can do the intro \"in advance,\" before we start the proof,\n-- by naming the hypothesis to the left of the `:`.\n-- Notice that at the beginning of our proof, we already have the \n-- hypothesis `hpqr` in our context.\nexample (hpqr : p ∨ (q ∧ r)) : (p ∨ q) ∧ (p ∨ r) := by \n  sorry \n\n\n-- ## Identity laws \n\n/-\n\nWe'll do a few more together.\n\nLet's sneak a new tactic in. \nTo prove a goal `True`, you can use the tactic `trivial`. \nThis is a sensible proof rule: trivially, you can always show `True` is true!\n-/\n\nexample : p ∧ True ↔ p := by\n  split_goal\n  { intro hpT \n    eliminate hpT \n    assumption }\n  { intro hpT \n    split_goal\n    assumption \n    trivial }\n\n-- Before, we saw `contradiction` would work if we had hypotheses \n-- `p` and `¬ p` at the same time. \n-- It also works if we have a hypothesis `False`!\nexample : p ∨ False ↔ p := by \n  split_goal \n  { intro hpF \n    eliminate hpF with hp hF \n    assumption \n    contradiction }\n  { intro hp \n    left\n    assumption }\n\n/-\n\n## Negation laws\n\nIf you're following along with the list of identities, you'll see that\nwe've come to some laws like `(p ∨ ¬ p) ↔ True`.\n\nUnfortunately, we don't have the tools to prove these in Lean yet.\n\nBut, you can do the **Idempotent laws** and **Universal bound laws**.\nTry stating and proving these yourself!\n\n-/\n\n\n\n\n/-\n\n## De Morgan's Laws \n\nThese can be a bit of a challenge! Like the negation laws,\na few of the implications here will require some new tools. \nBut try out these directions.\n\nRemember that to prove a negation `¬ X`, you can use a *proof by contradiction*:\nadd a hypothesis `h : X` using `intro h`, and then show a contradiction.\n\n-/\n\nexample (hnpnq : ¬ p ∨ ¬ q) : ¬(p ∧ q) := by \n  sorry \n\nexample (hnpnq : ¬ p ∧ ¬ q) : ¬ (p ∨ q) := by \n  sorry\n\n\n/- \n\nThat's it for the moment! \nTry the **Absorption laws** and **Negation of True and False**\non your own, if you want to. Skip the definition laws for now.\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/Exercises/LogicIdentities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.7872734555951314}}
{"text": "-- Introducción del cuantificador existencial\n-- ==========================================\n\nimport tactic\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que\n--    ∃ k : ℕ, 8 = 2*k\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : ∃ k : ℕ, 8 = 2*k :=\nbegin\n  use 4,\n  refl,\nend\n\n-- 2ª demostración\nexample : ∃ k : ℕ, 8 = 2*k :=\nexists.intro 4\n  ( show 8 = 2 * 4,\n      from rfl)\n\n\n-- 3ª demostración\nexample : ∃ k : ℕ, 8 = 2*k :=\nexists.intro 4 rfl\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/Introduccion_del_cuantificador_existencial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7872607346081276}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intros P P',\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  by_cases h : P,\n  {\n    intro P'',\n    exact h,\n  }, \n  {\n    intro P',\n    contradiction,\n  },\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  by_cases h : P,\n  {\n    intro P'',\n    exact h,\n  }, \n  {\n    intro P',\n    contradiction,\n  },\n  intros P P',\n  contradiction,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro D,\n  cases D,\n  right,\n  apply D,\n  left,\n  apply D, \nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro D,\n  cases D,\n  split,\n  apply D_right,\n  apply D_left,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro D,\n  intro P,\n  cases D,\n  contradiction,\n  apply D,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intros D P',\n  cases D,\n  contradiction,\n  apply D,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros D Q' P,\n  have Q := D  P,\n  contradiction, \nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros D P,\n  by_contra Q,\n  have P' := D Q,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  intros D Q' P,\n  have Q := D  P,\n  contradiction,\n  intros D P,\n  by_contra Q,\n  have P' := D Q,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro D,\n  by_cases h : P,\n  {\n    apply D,\n    left,\n    exact h,\n  },\n  {\n    apply D,\n    right,\n    exact h,\n  },\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros h1 np,\n  by_cases h : (P→Q),\n  have p : P := h1 h,\n  contradiction,\n  have h2 : (P → Q),\n  intro P,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intros ha hb,\n  cases hb,\n  cases ha,\n  apply hb_left,\n  contradiction,\n  apply hb_right,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intros ha hb,\n  cases ha,\n  cases hb,\n  have boom := hb ha_left,\n  exact boom,\n  have boom := hb ha_right,\n  exact boom,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro D,\n  split,\n  intro P,\n  apply D,\n  left,\n  exact P,\n  intro Q,\n  apply D,\n  right,\n  exact Q,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros ha hb,\n  cases ha with ha_l ha_r,\n  cases hb,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h1,\n  by_contradiction h2,\n  have hp : (P∧Q),\n  split,\n  by_contradiction h3,\n  apply h2,\n  right,\n  assumption,\n  by_contradiction h3,\n  apply h2,\n  left,\n  assumption,\n  apply h1,\n  contradiction,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros h1 h2,\n  cases h2,\n  cases h1,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  {\n    intro h1,\n    by_contradiction h2,\n    have hp : (P∧Q),\n    split,\n    by_contradiction h3,\n    apply h2,\n    right,\n    assumption,\n    by_contradiction h3,\n    apply h2,\n    left,\n    assumption,\n    apply h1,\n    contradiction,\n  },\n  {\n    intros h1 h2,\n    cases h2,\n    cases h1,\n    contradiction,\n    contradiction,\n  }\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  {\n    intro D,\n    split,\n    intro P,\n    apply D,\n    left,\n    exact P,\n    intro Q,\n    apply D,\n    right,\n    exact Q,\n  },\n  {\n    intros ha hb,\n    cases ha with ha_l ha_r,\n    cases hb,\n    contradiction,\n    contradiction,\n  }\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h1,\n  cases h1,\n  cases h1_right,\n  left,\n  split,\n  assumption,\n  assumption,\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h1,\n  cases h1,\n  {\n    cases h1,\n    split,\n    assumption,\n    left,\n    assumption,\n  },\n  {\n    cases h1,\n    split,\n    assumption,\n    right,\n    assumption,\n  }\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h1,\n  cases h1,\n  {\n    split,\n    left,\n    assumption,\n    left,\n    assumption,\n  },\n  {\n    cases h1,\n    split,\n    right,\n    assumption,\n    right,\n    assumption,\n  }\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  cases h with hl hr,\n  cases hl,\n  left,\n  assumption,\n  cases hr,\n  left,\n  assumption,\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros h1 h2 h3,\n  apply h1,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros h1 h2,\n  cases h2,\n  apply h1,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro P,\n  exact P,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro P,\n  left,\n  exact P,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro Q,\n  right,\n  exact Q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro h,\n  cases h,\n  assumption,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro h,\n  cases h,\n  assumption,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  {\n    intro PD,\n    cases PD,\n    assumption,\n  },\n  {\n    intro P,\n    split,\n    assumption,\n    assumption,\n  }\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  {\n    intro P2,\n    cases P2,\n    assumption,\n    assumption,\n  },\n  {\n    intro P,\n    left,\n    assumption,\n  }\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros h1 x p,\n  apply h1,\n  existsi x,\n  exact p,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros h1 h2,\n  cases h2 with x px,\n  have h : ¬P x := h1 x,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intros h1,\n  by_contradiction h2,\n  apply h1,\n  intro u,\n  by_contradiction h3,\n  apply h2,\n  existsi u,\n  assumption,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intros h1 h2,\n  cases h1 with x npx,\n  have px : P x := h2 x,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  {\n    intros h1,\n    by_contradiction h2,\n    apply h1,\n    intro u,\n    by_contradiction h3,\n    apply h2,\n    existsi u,\n    assumption,\n  },\n  {\n    intros h1 h2,\n    cases h1 with x npx,\n    have px : P x := h2 x,\n    contradiction,\n  }\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  {\n    intros h1 x p,\n    apply h1,\n    existsi x,\n    exact p,\n  },\n  {\n    intros h1 h2,\n    cases h2 with x px,\n    have h : ¬P x := h1 x,\n    contradiction,\n  }\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros h1 h2,\n  cases h1 with x px,\n  have npx : ¬P x := h2 x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros h1 h2,\n  cases h2 with x npx,\n  have px : P x := h1 x,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intros h1 x,\n  by_contradiction npu,\n  apply h1,\n  existsi x,\n  assumption,  \nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro h1,\n  by_contradiction nepx,\n  apply h1,\n  intros x,\n  by_contradiction px,\n  apply nepx,\n  existsi x,\n  assumption,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  {\n    intros h1 h2,\n    cases h2 with x npx,\n    have px : P x := h1 x,\n    contradiction,\n  },\n  {\n    intros h1 x,\n    by_contradiction npu,\n    apply h1,\n    existsi x,\n    assumption,\n  }\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  {\n    intros h1 h2,\n    cases h1 with x px,\n    have npx : ¬P x := h2 x,\n    contradiction,\n  },\n  {\n    intro h1,\n    by_contradiction nepx,\n    apply h1,\n    intros x,\n    by_contradiction px,\n    apply nepx,\n    existsi x,\n    assumption,\n  }\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro h1,\n  split,\n  {\n    cases h1 with x pqx,\n    cases pqx,\n    existsi x,\n    assumption,\n  },\n  {\n    cases h1 with x pqx,\n    cases pqx,\n    existsi x,\n    assumption,\n  }\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro h1,\n  cases h1 with x pqx,\n  cases pqx,\n  {\n    left,\n    existsi x,\n    assumption,\n  },\n  {\n    right,\n    existsi x,\n    assumption,\n  }\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro h1,\n  cases h1,\n  {\n    cases h1 with x px,\n    existsi x,\n    left,\n    assumption,\n  },\n  {\n    cases h1 with x qx,\n    existsi x,\n    right,\n    assumption,\n  }\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro h1,\n  split,\n  {\n    intro x,\n    have h : P x ∧ Q x := h1 x,\n    cases h,\n    assumption,\n  },\n  {\n    intro x,\n    have h : P x ∧ Q x := h1 x,\n    cases h,\n    assumption,\n  }\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro h1,\n  intro x,\n  cases h1,\n  split,\n  {\n    have h : P x := h1_left x,\n    assumption,\n  },\n  {\n    have h : Q x := h1_right x,\n    assumption,\n  }\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intros h1 x,\n  cases h1,\n  {\n    left,\n    have h : P x := h1 x,\n    assumption,\n  },\n  {\n    right,\n    have h : Q x := h1 x,\n    assumption,\n  }\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "paulo0301", "repo": "fmclean", "sha": "09afe5264ac6be4a850bede9a40f3f8871b149fe", "save_path": "github-repos/lean/paulo0301-fmclean", "path": "github-repos/lean/paulo0301-fmclean/fmclean-09afe5264ac6be4a850bede9a40f3f8871b149fe/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693659780479, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.7872177865133183}}
{"text": "import data.set\nimport data.nat.basic\n\nsection question1and2\n/-\nSuppose < is a strict partial order on a domain A, \nand define a≤b to mean that a<b or a=b.\n\nShow that ≤ is a partial order.\nShow that if < is moreover a strict total order, then ≤ is a total order.\n-/\n\nparameters {A : Type} {R : A → A → Prop}\nparameter (irreflR : irreflexive R)\nparameter (transR : transitive R)\n\nlocal infix < := R\n\ndef R' (a b : A) : Prop := R a b ∨ a = b\nlocal infix ≤ := R'\n\ninclude transR irreflR\ntheorem partialR : reflexive R' ∧ transitive R' ∧ anti_symmetric R' :=\nbegin\n    split,\n        assume a,\n        right,\n        trivial,\n\n        split,\n            assume a b c,\n            assume ab,\n            assume bc,\n            cases ab,\n                cases bc,\n                    left,\n                    exact transR ab bc,\n\n                    left, \n                    rw ←bc,\n                    assumption,\n\n                    rw ab,\n                    assumption,\n            \n            assume a b,\n            assume h1 h2,\n            cases h1,\n                cases h2,\n                    apply false.elim,\n                        apply irreflR,\n                            apply transR,\n                                exact h1,\n                                exact h2,\n                            \n                    exact eq.symm h2,\n                assumption,\nend\n\nexample : ∀ a b : A, (a < b) ∨ (a = b) ∨ (b < a) → a ≤ b ∨ b ≤ a :=\nbegin\n    assume a b,\n    assume h,\n    cases h,\n        left, left, assumption,\n        cases h,\n            left, right, assumption,\n            right, left, assumption\nend\n\n/-\nSuppose < is a strict partial order on a domain A. \n(In other words, it is transitive and asymmetric.) \nSuppose that ≤ is defined so that a≤b if and only if a<b or a=b. \nWe saw in class that ≤ is a partial order on a domain A, \ni.e.~it is reflexive, transitive, and antisymmetric.\n\nProve that for every a and b in A, \nwe have a<b iff a≤b and a≠b, using the facts above.\n-/\n\nexample : ∀ a b, a < b ↔ a ≤ b ∧ a ≠ b :=\nbegin\n    have partR := partialR,\n    assume a b,\n    split,\n        assume h,\n        split,\n            left, assumption,\n\n            assume ne,\n            apply irreflR,\n                rw ne at h,\n                exact h,\n        \n        assume h,\n        cases h.1,\n            assumption,\n            exact absurd h_1 h.2,\nend\n\nend question1and2\n\nsection question4\n    parameters (T : Type) (R : T → T → Prop)\n    parameter (reflR : reflexive R)\n    parameter (symmR : symmetric R)\n    parameter (transR : transitive R)\n\n    local infix ≡ := R\n\n    def equiv_class : T → set T := λ a, {c | R a c}\n\n    local notation `[`a`]` : 50 := (equiv_class a)\n\n    include reflR symmR transR\n    theorem equiv' : ∀ a b, [a] = [b] ↔ a ≡ b :=\n    begin\n        assume a b,\n        split,\n            assume h,\n            \n            have : ∀ x : T, (x ∈ equiv_class a) ↔ (x ∈ equiv_class b),\n                apply (set.ext_iff (equiv_class a) (equiv_class b)).1, assumption,\n\n            apply (this b).2,\n            apply reflR,\n            \n            assume h,\n            apply set.ext,\n                assume x,\n                split,\n                    assume h1,\n                    apply transR,\n                    exact symmR h,\n                    assumption,\n\n                    assume h1,\n                    apply transR,\n                    assumption,\n                    assumption,\n    end\n\n    example : ∀ a b, [a] = [b] ↔ a ≡ b :=\n        assume a b : T,\n        iff.intro \n            (\n                assume h : [a] = [b],\n                have this : ∀ x : T, (x ∈ [a]) ↔ (x ∈ [b]), from\n                    (set.ext_iff [a] [b]).1 h,\n                show a ≡ b, from (this b).2 (reflR b)\n            )\n            (\n            assume h : a ≡ b,\n            show [a] = [b], from set.ext (\n                assume x : T,\n                iff.intro \n                    (\n                        assume h1 : x ∈ [a],\n                        show x ∈ [b], from transR (symmR h) h1\n                    )\n                    (\n                        assume h1 : x ∈ [b],\n                        show x ∈ [a], from transR h h1\n                    )\n                )\n            )\n\nend question4\n\n\nsection question7\n\n/-\nA binary relation ≤ on a domain A is said to be a preorder it is is reflexive and transitive. \nThis is weaker than saying it is a partial order; \nwe have removed the requirement that the relation is asymmetric. \nAn example is the ordering on people currently alive on the planet defined by setting x≤y if and only if x ‘s birth date is earlier than y ‘s. \nAsymmetry fails, because different people can be born on the same day.\n But, prove that the following theorem holds:\n\nTheorem. Let ≤ be a preorder on a domain A. \nDefine the relation ≡, where x≡y holds if and only if x≤y and y≤x. \nThen ≡ is an equivalence relation on A.\n-/\n\nparameter {A : Type}\nparameter {R : A → A → Prop}\nparameter (transR : transitive R)\nparameter (reflR : reflexive R)\nlocal infix ≤ := R\n\ndef R'' (a b : A) : Prop := a ≤ b ∧ b ≤ a\n\nlocal infix ≡ := R''\n\ninclude reflR transR\nexample : reflexive R'' ∧ symmetric R'' ∧ transitive R'' :=\nbegin\n    split,\n        assume a,\n        split,\n            apply reflR,\n            apply reflR,\n        \n        split,\n            assume a b,\n            assume h,\n            cases h with ab ba,\n            split,\n                assumption,\n                assumption,\n            \n            assume a b c,\n            assume ab bc,\n            cases ab with ab ba,\n            cases bc with bc cb,\n            split,\n                apply transR,\n                    exact ab,\n                    assumption,\n                apply transR,\n                    exact cb,\n                    assumption,\nend\n\nend question7\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/other/relations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7871672372041725}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Importar la teoría de anillos.\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Crear el espacio de nombre my_ring.\n-- ----------------------------------------------------------------------\n\nnamespace my_ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Declara R una variable sobre anillos.\n-- ----------------------------------------------------------------------\n\nvariables {R : Type*} [ring R]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Declarar a y b como variables sobre R.\n-- ----------------------------------------------------------------------\n\nvariables a b : R\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que\n--     (a + b) + -b = a\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\ntheorem neg_add_cancel_right : (a + b) + -b = a :=\ncalc\n  (a + b) + -b\n      = a + (b + -b) : by rw add_assoc\n  ... = a + 0        : by rw add_right_neg\n  ... = a            : by rw add_zero\n\n-- 2ª demostración\n-- ===============\n\nexample : (a + b) + -b = a :=\nbegin\n  rw add_assoc,\n  rw add_right_neg,\n  rw add_zero,\nend\n\n-- El desarrollo de la prueba es\n--\n--    R : Type u_1,\n--    _inst_1 : ring R,\n--    a b : R\n--    ⊢ a + b + -b = a\n-- rw add_assoc,\n--    ⊢ a + (b + -b) = a\n-- rw add_right_neg,\n--    ⊢ a + 0 = a\n-- rw add_zero,\n--    no goals\n\n-- 3ª demostración\n-- ===============\n\nexample : (a + b) + -b = a :=\nby rw [add_assoc, add_right_neg, add_zero]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Cerrar la teoría my_ring\n-- ----------------------------------------------------------------------\n\nend my_ring\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/neg_add_cancel_right.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787536, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7871325853976331}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport AdvancedAdditionWorld.Level11 -- add_right_eq_zero\nimport Mathlib.Tactic.LeftRight\nimport InequalityWorld.Level4 -- zero_le\nimport InequalityWorld.Level8 -- succ_le_succ\nnamespace MyNat\nopen MyNat\n/-!\n# Inequality world.\n\n## Level 9: `le_total`\n\n## Lemma : le_total\nFor all naturals `a` and `b`, either `a ≤ b` or `b ≤ a`.\n-/\ntheorem le_total (a b : MyNat) : a ≤ b ∨ b ≤ a := by\n  revert a\n  induction b with\n  | zero =>\n    intro a\n    right\n    exact zero_le a\n  | succ d hd =>\n    intro a\n    cases a with\n    | zero =>\n      left\n      exact zero_le _\n    | succ a =>\n      have h2 := hd a\n      cases h2 with\n      | inl h =>\n        left\n        exact succ_le_succ a d h\n      | inr h =>\n        right\n        exact succ_le_succ d a h\n\n/-!\nSee the [revert tactic](../Tactics/revert.lean.md)\n\nNote in the above proof that `exact succ_le_succ a d h`\nis just shorthand for:\n`\napply succ_le_succ a d\nexact h\n`\n\nAnother collectible: the naturals are a linear order.\n\n-- BUGBUG: collectibles\n-- instance : linear_order MyNat := by structure_helper\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/InequalityWorld/Level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7870077468734061}}
{"text": "/-\nCopyright (c) 2019 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel\n\n! This file was ported from Lean 3 source module topology.metric_space.completion\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.Completion\nimport Mathlib.Topology.MetricSpace.Isometry\nimport Mathlib.Topology.Instances.Real\n\n/-!\n# The completion of a metric space\n\nCompletion of uniform spaces are already defined in `Topology.UniformSpace.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 {α : Type u} {β : Type v} [PseudoMetricSpace α]\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 α) :=\n  ⟨Completion.extension₂ dist⟩\n\n/-- The new distance is uniformly continuous. -/\nprotected theorem uniformContinuous_dist :\n    UniformContinuous fun p : Completion α × Completion α ↦ dist p.1 p.2 :=\n  uniformContinuous_extension₂ dist\n#align uniform_space.completion.uniform_continuous_dist UniformSpace.Completion.uniformContinuous_dist\n\n/-- The new distance is continuous. -/\nprotected theorem continuous_dist [TopologicalSpace β] {f g : β → Completion α} (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/-- The new distance is an extension of the original distance. -/\n@[simp]\nprotected theorem dist_eq (x y : α) : dist (x : Completion α) y = dist x y :=\n  Completion.extension₂_coe_coe uniformContinuous_dist _ _\n#align uniform_space.completion.dist_eq UniformSpace.Completion.dist_eq\n\n/- Let us check that the new distance satisfies the axioms of a distance, by starting from the\nproperties on α and extending them to `Completion α` by continuity. -/\nprotected theorem dist_self (x : Completion α) : dist x x = 0 := by\n  refine' induction_on x _ _\n  · refine' isClosed_eq _ continuous_const\n    exact Completion.continuous_dist continuous_id continuous_id\n  · intro a\n    rw [Completion.dist_eq, dist_self]\n#align uniform_space.completion.dist_self UniformSpace.Completion.dist_self\n\nprotected theorem dist_comm (x y : Completion α) : dist x y = dist y x := by\n  refine' induction_on₂ x y _ _\n  · exact isClosed_eq (Completion.continuous_dist continuous_fst continuous_snd)\n        (Completion.continuous_dist continuous_snd continuous_fst)\n  · 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\nprotected theorem dist_triangle (x y z : Completion α) : dist x z ≤ dist x y + dist y z := by\n  refine' induction_on₃ x y z _ _\n  · refine' isClosed_le _ (Continuous.add _ _) <;>\n      apply_rules [Completion.continuous_dist, Continuous.fst, Continuous.snd, continuous_id]\n  · 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/-- Elements of the uniformity (defined generally for completions) can be characterized in terms\nof the distance. -/\nprotected theorem mem_uniformity_dist (s : Set (Completion α × Completion α)) :\n    s ∈ 𝓤 (Completion α) ↔ ∃ ε > 0, ∀ {a b}, dist a b < ε → (a, b) ∈ s := by\n  constructor\n  · /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in `α` is an\n      entourage, so it contains an `ε`-neighborhood of the diagonal by definition of the entourages\n      in metric spaces. Then `t` contains an `ε`-neighborhood of the diagonal in `Completion α`, as\n      closed properties pass to the completion. -/\n    intro hs\n    rcases mem_uniformity_isClosed hs with ⟨t, ht, ⟨tclosed, ts⟩⟩\n    have A : { x : α × α | (↑x.1, ↑x.2) ∈ t } ∈ uniformity α :=\n      uniformContinuous_def.1 (uniformContinuous_coe α) t ht\n    rcases mem_uniformity_dist.1 A with ⟨ε, εpos, hε⟩\n    refine' ⟨ε, εpos, @fun x y hxy ↦ _⟩\n    have : ε ≤ dist x y ∨ (x, y) ∈ t := by\n      refine' induction_on₂ x y _ _\n      · have : { x : Completion α × Completion α | ε ≤ dist x.fst x.snd ∨ (x.fst, x.snd) ∈ t } =\n               { p : Completion α × Completion α | ε ≤ dist p.1 p.2 } ∪ t := by ext; simp\n        rw [this]\n        apply IsClosed.union _ tclosed\n        exact isClosed_le continuous_const Completion.uniformContinuous_dist.continuous\n      · intro x y\n        rw [Completion.dist_eq]\n        by_cases h : ε ≤ dist x y\n        · exact Or.inl h\n        · have Z := hε (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  · /- Start from a set `s` containing an ε-neighborhood of the diagonal in `Completion α`. To show\n        that it is an entourage, we use the fact that `dist` is uniformly continuous on\n        `Completion α × Completion α` (this is a general property of the extension of uniformly\n        continuous functions). Therefore, the preimage of the ε-neighborhood of the diagonal in ℝ\n        is an entourage in `Completion α × Completion α`. Massaging this property, it follows that\n        the ε-neighborhood of the diagonal is an entourage in `Completion α`, and therefore this is\n        also the case of `s`. -/\n    rintro ⟨ε, εpos, hε⟩\n    let r : Set (ℝ × ℝ) := { p | dist p.1 p.2 < ε }\n    have : r ∈ uniformity ℝ := Metric.dist_mem_uniformity εpos\n    have T := uniformContinuous_def.1 (@Completion.uniformContinuous_dist α _) 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 ⟨t1, ht1, t2, ht2, ht⟩\n    refine' mem_of_superset ht1 _\n    have A : ∀ a b : Completion α, (a, b) ∈ t1 → dist a b < ε := by\n      intro a b hab\n      have : ((a, b), (a, a)) ∈ t1 ×ˢ t2 := ⟨hab, refl_mem_uniformity ht2⟩\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 ⊆ s\n    · rintro ⟨a, b⟩ hp\n      have : dist a b < ε := A a b hp\n      exact hε this\n#align uniform_space.completion.mem_uniformity_dist UniformSpace.Completion.mem_uniformity_dist\n\n/-- If two points are at distance 0, then they coincide. -/\nprotected theorem eq_of_dist_eq_zero (x y : Completion α) (h : dist x y = 0) : x = y := by\n  /- This follows from the separation of `Completion α` and from the description of\n    entourages in terms of the distance. -/\n  have : SeparatedSpace (Completion α) := by infer_instance\n  refine' separated_def.1 this x y fun s hs ↦ _\n  rcases (Completion.mem_uniformity_dist s).1 hs with ⟨ε, εpos, hε⟩\n  rw [← h] at εpos\n  exact hε εpos\n#align uniform_space.completion.eq_of_dist_eq_zero UniformSpace.Completion.eq_of_dist_eq_zero\n\n/-- Reformulate `Completion.mem_uniformity_dist` in terms that are suitable for the definition\nof the metric space structure. -/\nprotected theorem uniformity_dist' :\n    𝓤 (Completion α) = ⨅ ε : { ε : ℝ // 0 < ε }, 𝓟 { p | dist p.1 p.2 < ε.val } := by\n  ext s; rw [mem_infᵢ_of_directed]\n  · simp [Completion.mem_uniformity_dist, subset_def]\n  · rintro ⟨r, hr⟩ ⟨p, hp⟩\n    use ⟨min r p, lt_min hr hp⟩\n    simp (config := { contextual := true }) [lt_min_iff]\n#align uniform_space.completion.uniformity_dist' UniformSpace.Completion.uniformity_dist'\n\nprotected theorem uniformity_dist : 𝓤 (Completion α) = ⨅ ε > 0, 𝓟 { p | dist p.1 p.2 < ε } := by\n  simpa [infᵢ_subtype] using @Completion.uniformity_dist' α _\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 α) 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  edist_dist := fun x y ↦ rfl\n\n/-- The embedding of a metric space in its completion is an isometry. -/\ntheorem coe_isometry : Isometry ((↑) : α → Completion α) :=\n  Isometry.of_dist_eq Completion.dist_eq\n#align uniform_space.completion.coe_isometry UniformSpace.Completion.coe_isometry\n\n@[simp]\nprotected theorem edist_eq (x y : α) : edist (x : Completion α) 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\nopen UniformSpace Completion NNReal\n\ntheorem LipschitzWith.completion_extension [MetricSpace β] [CompleteSpace β] {f : α → β}\n    {K : ℝ≥0} (h : LipschitzWith K f) : LipschitzWith K (Completion.extension f) :=\n  LipschitzWith.of_dist_le_mul fun x y => induction_on₂ x y\n    (isClosed_le (by continuity) (by continuity)) <| by\n      simpa only [extension_coe h.uniformContinuous, Completion.dist_eq] using h.dist_le_mul\n\ntheorem LipschitzWith.completion_map [PseudoMetricSpace β] {f : α → β} {K : ℝ≥0}\n    (h : LipschitzWith K f) : LipschitzWith K (Completion.map f) :=\n  one_mul K ▸ (coe_isometry.lipschitz.comp h).completion_extension\n\ntheorem Isometry.completion_extension [MetricSpace β] [CompleteSpace β] {f : α → β}\n    (h : Isometry f) : Isometry (Completion.extension f) :=\n  Isometry.of_dist_eq fun x y => induction_on₂ x y\n    (isClosed_eq (by continuity) (by continuity)) fun _ _ ↦ by\n      simp only [extension_coe h.uniformContinuous, Completion.dist_eq, h.dist_eq]\n\ntheorem Isometry.completion_map [PseudoMetricSpace β] {f : α → β}\n    (h : Isometry f) : Isometry (Completion.map f) :=\n  (coe_isometry.comp h).completion_extension\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/Completion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107878954106, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.787007727826161}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hP,\n  intro hnnP,\n  contradiction, \nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro  hnnP,\n  by_cases hP : P,\n  exact hP,\n  contradiction,\n  \nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  apply doubleneg_elim,\n  apply doubleneg_intro, \nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ 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 ∧ Q) → (Q ∧ 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ções de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intros h hp,\n  cases h with hnP hQ,\n    contradiction,\n    exact hQ,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intros h hnP,\n  cases h with hnP hQ,\n    contradiction,\n    exact hQ,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros h hnQ hP,\n  apply hnQ,\n  apply h,\n  exact hP,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros h hP,\n  by_contra hQ,\n    apply h,\n    exact hQ,\n    exact hP, \nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  apply impl_as_contrapositive,\n  apply impl_as_contrapositive_converse,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h,\n  apply h,\n  \n  by_cases hP : P,\n    left,\n    exact hP,\n    right,\n    exact hP,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro h,\n  intro hnP,\n  apply hnP,\n  apply h,\n  intro hp,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro h,\n  intro hnPnQ,\n  cases h with hP,\n    cases hnPnQ with hnP hnQ,\n      contradiction,\n    cases hnPnQ with hnP hnQ,\n      contradiction,\n\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro h,\n  intro hnPnQ,\n  cases hnPnQ with hnP hnQ,\n    cases h with hP hQ,\n      contradiction,\n    cases h with hP hQ,\n      contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\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,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro h,\n  intro hPQ,\n  cases h with hnP hnQ,\n    cases hPQ with hP hQ,\n      contradiction,\n      contradiction,\nend\n-- Prove de Morgan's.\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro hnPQ,\n  by_cases hP : P,\n    left,\n    intro hQ,\n    have hPQ : P ∧ Q, from and.intro hP hQ,\n      contradiction,\n  right,\n  exact hP,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros hOr hAnd,\n  cases hOr,\n  cases hAnd,\n  apply hOr,\n  exact hAnd_right,\n  cases hAnd,\n  apply hOr,\n  exact hAnd_left,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  apply demorgan_conj,\n  apply demorgan_conj_converse,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  apply demorgan_disj,\n  apply demorgan_disj_converse,\n\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\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∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h,\n  cases h with hPQ hPR,\n    cases hPQ with hP hQ,\n      split,\n      exact hP,\n      left,\n      exact hQ,\n    cases hPR with hP hR,\n      split,\n      exact hP,\n      right,\n      exact hR,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h,\n  split,\n  cases h with hP hQR,\n    left, \n    exact hP,\n    cases hQR with hQ hR,\n      right,\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∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h,\n  cases h with hPQ hPR, \n    cases hPR with hP hR,\n      left,\n      exact hP,\n    cases hPQ with hP hQ,\n        left,\n        exact hP,\n    have hQR : Q ∧ R, from and.intro hQ hR,\n       right,\n       exact hQR,\n  \nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros h hP hQ,\n  apply h,\n  split,\n  exact hP,\n  exact hQ,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros h hPQ,\n  cases hPQ with hP hQ,\n    apply h,\n    exact hP,\n    exact hQ,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hP,\n  exact hP,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hP,\n  left,\n  exact hP,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hQ,\n  right,\n  exact hQ,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n    exact hP,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n    exact hQ,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro hPP,\n  cases hPP with hP,\n    exact hP,\n    intro hP,\n    split,\n    exact hP,\n    exact hP,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro hPP,\n  cases hPP with hP,\n    exact hP,\n    exact hPP,\n    intro hP,\n    left,\n    exact hP,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro hnE,\n  intro k,\n  intro hP,\n  apply hnE,\n  existsi k,\n  exact hP,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro hfAll,\n  intro hE,\n  cases hE with k hP,\n    have hnPk : ¬P k := hfAll k,\n      apply hnPk,\n      exact hP,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro hnfAll,\n  by_contra hnE,\n    apply hnfAll,\n    intro k,\n  by_contra hnPk,\n    apply hnE,\n    existsi k,\n  exact hnPk,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro hE,\n  intro hnfAll,\n  cases hE with k hnP,\n    have hP : P k := hnfAll k,\n      contradiction,\n\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_forall,\n  apply demorgan_forall_converse,\n\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_exists,\n  apply demorgan_exists_converse,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro hE,\n  intro hnfAll,\n  cases hE with k hP,\n    have hnP : ¬P k := hnfAll k,\n      contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro hfAll,\n  intro hE,\n  cases hE with k hnP,\n    apply hnP,\n    apply hfAll,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro hnE,\n  intro k,\n  by_contra hnP,\n    apply hnE,\n    existsi k,\n    exact hnP,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intros hnfAll,\n  by_contra hnE,\n    apply hnfAll,\n  intro k,\n  intro hP,\n  apply hnE,\n  existsi k,\n  exact hP,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intros hEAnd,\n  cases hEAnd with k hPQ,\n    cases hPQ with hP hQ,\n      split,\n      existsi k,\n      exact hP,\n      existsi k,\n      exact hQ,\n\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intros hEOr,\n  cases hEOr with k hPQ,\n    cases hPQ with hP hQ,\n      left,\n      existsi k,\n      exact hP,\n    right,\n    existsi k,\n    exact hQ,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro hEOr,\n  cases hEOr with hEP hEQ,\n    cases hEP with k hP,\n      existsi k,\n      left,\n      exact hP,\n    cases hEQ with k hQ,\n      existsi k,\n      right,\n      exact hQ,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro hfAll,\n  split,\n  intro k,\n  have hPQ : P k ∧ Q k := hfAll k,\n    cases hPQ with hP hQ,\n    exact hP,\n  intro k,\n  have hPQ : P k ∧ Q k := hfAll k,\n    cases hPQ with hP hQ,\n    exact hQ,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro hfAllAnd,\n  cases hfAllAnd with hfP hfQ,\n    intro k,\n    split,\n    apply hfP,\n    apply hfQ,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro hfAllOr,\n  intro k,\n  cases hfAllOr with hfP hfQ,\n    left,\n    apply hfP,\n    right,\n    apply hfQ,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n\n", "meta": {"author": "Ipojuca", "repo": "fmclean", "sha": "30553a5e0e4287373d7ae060ad695ed433af8523", "save_path": "github-repos/lean/Ipojuca-fmclean", "path": "github-repos/lean/Ipojuca-fmclean/fmclean-30553a5e0e4287373d7ae060ad695ed433af8523/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7868329709573221}}
{"text": "variable { α β γ : Type }\n-- variable (f : α → β) (g : β → γ) \n\ndef Injective (f : α → β) : Prop := ∀ a₁ a₂, f a₁ = f a₂ → a₁ = a₂ \n\ndef Surjective (f : α → β) : Prop := ∀ b, ∃ a, f a = b \n\ndef Bijective (f : α → β) : Prop :=  Injective f ∧ Surjective f \n\ntheorem comp_inj (f : α → β) (g : β → γ) (h : Injective (g ∘ f)) : Injective f := by \n  intro a₁ a₂ h₁ \n  have : g (f a₁) = g (f a₂) := congrArg g h₁ \n  exact h a₁ a₂ this \n\ntheorem comp_surj (f : α → β) (g : β → γ) (h : Surjective (g ∘ f)) : Surjective g := by \n  intro c \n  have ⟨a,h₁⟩ : ∃ a, g (f a) = c := h c \n  exact ⟨f a, h₁⟩ \n\ndef IsLeftInverse (f : α → β) (g : β → α) : Prop := g ∘ f = @id α \n\ndef IsRightInverse (f : α → β) (g : β → α) : Prop := f ∘ g = @id β \n\ndef IsInverse (f : α → β) (g : β → α) : Prop := IsLeftInverse f g ∧ IsRightInverse f g \n\ntheorem left_inv_right_inv (f: α → β) (g : β → α) (h : IsLeftInverse f g) : IsRightInverse g f := by \n  exact h\n\ndef hasLeftInverse (f : α → β) : Prop := ∃ (g: β → α), IsLeftInverse f g \n\ndef hasRightInverse (f : α → β) : Prop := ∃ (g : β → α), IsRightInverse f g \n\ntheorem has_left_inv_injective (f : α → β) (h : hasLeftInverse f) : Injective f := by \n  intro a₁ a₂ l₁ \n  have ⟨g,l₂⟩ := h \n  have : (g ∘ f) a₁ = (g ∘ f) a₂ := congrArg g l₁\n  rw [congrFun l₂] at this\n  calc\n    a₁ = id a₁        := by rfl \n    _  = (g  ∘ f) a₂  := this \n    _  = id a₂        := by rw [congrFun l₂] \n\n#check Classical.propDecidable\n\n#check dif_pos \n\ntheorem injective_has_left_inv (f : α → β) [l : Nonempty α] (h : Injective f) : hasLeftInverse f := by \n  have (a₀ : α) := Classical.choice l  \n  let (g : β → α) := by \n    intro b \n    have : Decidable (∃ a, f a = b) := Classical.propDecidable (∃ a, f a = b)\n    exact if s : ∃ a, f a = b then Classical.choose s else a₀  \n  have : IsLeftInverse f g := by \n    apply funext \n    intro a \n    sorry \n  exists g \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_24-notes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768635777511, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7868058027439049}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hd,\n  intro hd,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro d1,\n  by_contradiction hboom,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P,\n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro h1,\n  cases h1 with hp hq,\n  \n  right,\n  exact hp,\n\n  left,\n  exact hq,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro d1,\n  cases d1 with dp dq,\n  split,\n  exact dq,\n  exact dp,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro d1,\n  cases d1 with dnp dq,\n  \n  intro d2,\n  \n  contradiction,\n  intro d2,\n  exact dq,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro d1,\n  cases d1 with dp dq,\n  intro d2,\n  contradiction,\n  intro d2,\n  exact dq,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro d1,\n  intro d2,\n  intro d3,\n  have dq : Q := d1 d3,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro left,\n  intro p,\n  by_contradiction hboom,\n  have np : ¬P := left hboom,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  \n  intro left,\n  intro nq,\n  intro np,\n  have q : Q := left np,\n  contradiction, \n\n  intro left,\n  intro p,\n  by_contradiction hboom,\n  have np : ¬P := left hboom,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro hl,\n  have g: (P∨¬P),\n  right,\n  intro p,\n  have ll: (P∨¬P),\n  left,\n  exact p,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro hl,\n  intro np,\n  have g: (P → Q),\n  intro p,\n  contradiction,\n  have p : P := hl g,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro hl,\n  intro npenq,\n  cases npenq with np nq,\n  cases hl with p q,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro peq,\n  intro npounq,\n  cases peq with p q,\n  cases npounq with np nq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro npouq,\n  split,\n  intro p,\n  have pouq: (P∨Q),\n  left,\n  exact p,\n  contradiction,\n  intro q,\n  have pouq: (P∨Q),\n  right,\n  exact q,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro npenq,\n  intro peq,\n  cases npenq with np nq,\n  cases peq with p q,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro npeq,\n  by_cases vq: Q, --- lem sobre Q\n  right,\n  intro p,\n  have peq: (P∧Q),\n  split,\n  exact p,\n  exact vq,\n  contradiction,\n  left,\n  exact vq,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro nqounp,\n  intro peq,\n  cases nqounp with nq np,\n  cases peq with p q,\n  contradiction,\n  cases peq with p q,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n  exact demorgan_disj_converse P Q,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro peqour,\n  cases peqour with p qour,\n  cases qour with q r,\n  left,\n  split,\n  exact p,\n  exact q,\n  right,\n  split,\n  exact p,\n  exact r, \nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro hl,\n  cases hl with peq per,\n  cases peq with p q,\n  split,\n  exact p,\n  left,\n  exact q,\n  cases per with p r,\n  split,\n  exact p,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro hl,\n  cases hl with p qer,\n  split,\n  left,\n  exact p,\n  left,\n  exact p,\n  cases qer with q r,\n  split,\n  right,\n  exact q,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro hl,\n  cases hl with pouq pour,\n  cases pouq with p q,\n  left,\n  exact p,\n  cases pour with p r,\n  left,\n  exact p,\n  right,\n  split,\n  exact q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro hl,\n  intro p,\n  intro q,\n  have peq: (P∧Q),\n  split,\n  exact p,\n  exact q,\n  have r: R := hl peq,\n  exact r,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro left,\n  intro peq,\n  cases peq with p q,\n  have qtor: Q→R := left p,\n  have r: R := qtor q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left, \n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pep,\n  cases pep with pl pr,\n  exact pl,\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro poup,\n  cases poup with pl pr,\n  exact pl,\n  exact pr,\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro hl,\n  intro x,\n  intro pdex,\n  apply hl,\n  existsi x,\n  exact pdex,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro hl,\n  intro d2,\n  cases d2 with x pdex,\n  exact hl x pdex,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro hl,\n  by_contradiction hc,\n  apply hl,\n  intro u,\n  by_contradiction hc',\n  apply hc,\n  existsi u,\n  exact hc',\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro hl,\n  intro hp,\n  cases hl with h ha,\n  have pdeh : P h := hp h, --- proposicao universal \n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_forall,\n  apply demorgan_forall_converse,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_exists,\n  apply demorgan_exists_converse,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro hl,\n  intro hq,\n  cases hl with h ha,\n  have npdeh : ¬P h := hq h,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro hl,\n  intro he,\n  cases he with a ha,\n  have pdex : P a := hl a,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro hl,\n  intro e,\n  by_contradiction,\n  apply hl,\n  existsi e,\n  exact h,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro hl,\n  by_contradiction he,\n  apply hl,\n  intro a,\n  intro ha,\n  apply he,\n  existsi a,\n  exact ha,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro hl,\n  split,\n  cases hl with u hu,\n  cases hu with hup huq,\n  existsi u,\n  exact hup,\n  cases hl with u hu,\n  cases hu with hup huq,\n  existsi u,\n  exact huq,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro hl,\n  cases hl with u hu,\n  cases hu,\n  left,\n  existsi u,\n  exact hu,\n  right,\n  existsi u,\n  exact hu,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro hl,\n  cases hl,\n  cases hl with u hu,\n  existsi u,\n  left,\n  exact hu,\n  cases hl with u hu,\n  existsi u,\n  right,\n  exact hu,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro hl,\n  split,\n  intro u,\n  have pxeqx : P u ∧ Q u := hl u,\n  cases pxeqx with pu qu,\n  exact pu,\n  intro u,\n  have pxeqx : P u ∧ Q u := hl u,\n  cases pxeqx with pu qu,\n  exact qu,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro hl,\n  intro u,\n  split,\n  cases hl,\n  have pu : P u := hl_left u,\n  exact pu,\n  cases hl,\n  have qu : Q u := hl_right u,\n  exact qu,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro hl,\n  intro u,\n  cases hl,\n  have pu : P u := hl u,\n  left,\n  exact pu,\n  have qu : Q u := hl u,\n  right,\n  exact qu,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "lucandes", "repo": "fmclean", "sha": "01764a5ae1afcac3065fc39868c8775b4c341bbd", "save_path": "github-repos/lean/lucandes-fmclean", "path": "github-repos/lean/lucandes-fmclean/fmclean-01764a5ae1afcac3065fc39868c8775b4c341bbd/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541626630937, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7867365505499365}}
{"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.nat\nopen nat\n\ndefinition partial_sum : nat → nat\n| 0        := 0\n| (succ n) := succ n + partial_sum n\n\nexample : partial_sum 5 = 15 :=\nrfl\n\nexample : partial_sum 6 = 21 :=\nrfl\n\nlemma two_mul_partial_sum_eq : ∀ n, 2 * partial_sum n = (succ n) * n\n| 0        := by reflexivity\n| (succ n) := calc\n   2 * (succ n + partial_sum n) = 2 * succ n + 2 * partial_sum n  : left_distrib\n                   ...   = 2 * succ n + succ n * n  : two_mul_partial_sum_eq\n                   ...   = 2 * succ n + n * succ n  : mul.comm\n                   ...   = (2 + n) * succ n         : right_distrib\n                   ...   = (n + 2) * succ n         : add.comm\n                   ...   = (succ (succ n)) * succ n : rfl\n\ntheorem partial_sum_eq : ∀ n, partial_sum n = ((n + 1) * n) / 2 :=\ntake n,\nhave h₁ : (2 * partial_sum n) / 2 = ((succ n) * n) / 2, by rewrite two_mul_partial_sum_eq,\nhave h₂ : (2:nat) > 0, from dec_trivial,\nby rewrite [nat.mul_div_cancel_left _ h₂ at h₁]; exact h₁\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/partial_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.786736549495907}}
{"text": "import data.set.basic\nimport data.real.basic\n\n/-\nAlso see LFTCM 2020 lecture:\n\n  https://www.youtube.com/watch?v=qlJrCtYiEkI\n-/\n\n/- Sets versus Types\n\nLean distinguishes different notions of \"set\" and \"containment\"\nwhich are often treated as the same in informal mathematics.\n\nLean            math\n====            ====\nX : Type        X is a set (e.g., a metric space or a vector space)\ns : set X       s is a subset of X (e.g., an open ball)\nx : X           x is an element/point of X\nx ∈ s           x belongs to s\nt ⊆ s           t is contained in s\n\n-/\n\n-- A `set α` is specified by its membership predicate:\n-- for each element of α, we need to say whether it is in the set.\n\ndef myset (α : Type*) := α → Prop\n\n-- Example: Unit interval [0, 1] as a subset of ℝ\n\n-- def unit_interval : set ℝ := λ r, 0 ≤ r ∧ r ≤ 1\ndef unit_interval : set ℝ := {r : ℝ | 0 ≤ r ∧ r ≤ 1}\n\n-- #check @set.mem_def\n\nexample : (1/2 : ℝ) ∈ unit_interval :=\nbegin\n  unfold unit_interval,\n  norm_num,\nend\n\nexample : (2 : ℝ) ∉ unit_interval :=\nbegin\n  unfold unit_interval,\n  norm_num,\nend\n\n\n\n\n\n\n\n\n\n\n\n\n/- Operations on sets\n\n  s ∩ t        set.inter s t\n  s ∪ t        set.union s t\n  s \\ t        set.diff s t\n  sᶜ           set.compl s\n  ∅            set.empty\n               set.univ\n  s.prod t     set.prod s t\n\n-/\n\nvariables {α β : Type*}\n\ndef myinter (s t : set α) : set α := {x | x ∈ s ∧ x ∈ t}\n\ndef myuniv : set α := {x | true}\n\ndef myprod (s : set α) (t : set β) : set (α × β) :=\n{p : α × β | p.fst ∈ s ∧ p.snd ∈ t}\n\n\n\n\n/- Set extensionality\n\nTwo sets `s t : set α` are equal if and only if they have the same members,\nthat is, `∀ x, x ∈ s ↔ x ∈ t`.\n\nThe `ext` tactic will automatically apply extensionality theorems like this one.\n\n-/\n\nexample (s t : set α) : s ∩ t = t ∩ s := begin\n  ext,\n  finish,\nend\n\nlemma set.ne_empty_iff_exists_mem (s : set α) : s ≠ ∅ ↔ ∃ x, x ∈ s := begin\n  sorry\nend\n\n\n\n\n\n/- Set containment: s ⊆ t -/\ndef mysubset (s t : set α) : Prop := ∀ x, x ∈ s → x ∈ t\n\n\n/- Let's prove commutativity of ∩ again, using `set.subset.antisymm` this time. -/\n\nlemma inter_comm_subset (s t : set α) : s ∩ t ⊆ t ∩ s := sorry\n\nexample (s t : set α) : s ∩ t = t ∩ s := begin\n  apply set.subset.antisymm;\n    apply inter_comm_subset,\nend\n\n\n\n\n/- Exercises: From Lean for the Curious Mathematician 2020.\nSee https://leanprover-community.github.io/lftcm2020/exercises.html\nThis lecture: tuesday/sets.lean\n-/\n\n\n/- Bonus exercises -/\n\n#check @set.range\n\ndef diag (α : Type*) : set (α × α) := {p : α × α | p.fst = p.snd}\n\nexample : diag α = set.range (λ x, (x, x)) := begin\n  sorry\nend\n\nexample (s t : set α) : s.prod t ∩ diag α ≠ ∅ ↔ s ∩ t ≠ ∅ :=\nbegin\n  sorry\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/sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7867365398525376}}
{"text": "-- * Level 1\n\ntheorem succ_inj' {a b : mynat} (hs : succ(a) = succ(b)) :  a = b :=\n\nbegin\n\ninduction b,\napply succ_inj,\nexact hs,\napply succ_inj,\nexact hs,\n\nend\n\n\n-- * Level 2\n\ntheorem succ_succ_inj {a b : mynat} (h : succ(succ(a)) = succ(succ(b))) :  a = b :=\n\nbegin\n\napply succ_inj,\napply succ_inj,\nexact h,\n\nend\n-- * Level 3\n\ntheorem succ_eq_succ_of_eq {a b : mynat} : a = b → succ(a) = succ(b) :=\n\nbegin\n\nintro,\nrw a_1,\nrefl,\n\n\nend\n-- * Level 4\n\ntheorem succ_eq_succ_iff (a b : mynat) : succ a = succ b ↔ a = b :=\n\nbegin\n\nsplit,\nexact succ_inj,\nexact succ_eq_succ_of_eq,\n\n\nend\n\n-- * Level 5\n\ntheorem add_right_cancel (a t b : mynat) : a + t = b + t → a = b :=\n\n\nbegin\n\nintro h,\ninduction t,\nrepeat{rw add_zero at h},\nexact h,\nrepeat {rw add_succ at h},\nrw succ_eq_succ_iff at h,\nexact t_ih(h),\n\nend\n-- * Level 6\n\ntheorem add_left_cancel (t a b : mynat) : t + a = t + b → a = b :=\n\nbegin\n\nintro h,\nrw add_comm at h,\nrw add_comm t b at h,\napply add_right_cancel,\nexact h,\n\n\nend\n\n-- * Level 7\ntheorem add_right_cancel_iff (t a b : mynat) :  a + t = b + t ↔ a = b :=\n\n\nbegin\n\nintro h,\napply add_right_cancel,\nexact h,\n\nintro g,\nrw g,\nrefl,\n\n\nsplit,\n\nend\n\n-- * Level 8\n\nlemma eq_zero_of_add_right_eq_self {a b : mynat} : a + b = a → b = 0 :=\n\nbegin\n\nintro g,\nrw <- add_zero (a) at g,\nrw add_assoc at g,\nrw zero_add b at g,\napply add_left_cancel,\nexact g,\n\nend\n\n-- * Level 9\ntheorem succ_ne_zero (a : mynat) : succ a ≠ 0 :=\nbegin\n\n\nsymmetry,\nexact zero_ne_succ a,\n\nend\n-- * Level 10\n\nlemma add_left_eq_zero {{a b : mynat}} (H : a + b = 0) : b = 0 :=\n\nbegin\n\ncases b,\nrw add_zero at H,\nrefl,\nrw add_succ at H,\nexfalso,\napply succ_ne_zero,\nexact H,\n\nend\n\n-- * Level 11\nlemma add_right_eq_zero {a b : mynat} : a + b = 0 → a = 0 :=\n\n\nbegin\n\nintro h,\nrw add_comm at h,\nexact add_left_eq_zero(h),\n\nend\n-- * Level 12\n\ntheorem add_one_eq_succ (d : mynat) : d + 1 = succ d :=\n\nbegin\n\nsymmetry,\nrw succ_eq_add_one,\nrefl\n\nend\n\n-- * Level 13\nlemma ne_succ_self (n : mynat) : n ≠ succ n :=\n\nbegin\n\nsymmetry at g,\nhave h := eq_zero_of_add_right_eq_self(g),\nrw one_eq_succ_zero at h,\nhave h2 := succ_ne_zero(0),\nintro g,\nrw succ_eq_succ_iff at g,\nrw <- add_one_eq_succ at g,\ncases n,\napply zero_ne_succ 0,\nexact h2(h)\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/advanced_addition_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521252, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.786704901586003}}
{"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-/\nimport analysis.normed_space.basic\nimport analysis.normed.group.hom\nimport ring_theory.ideal.quotient_operations\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 ⧸ S`.\nIf `S` is closed, we provide `normed_add_comm_group (M ⧸ 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 ⧸ 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 ⧸ S`.\n\n* `lift S f hf`: implements the universal property of `M ⧸ S`. Here\n    `(f : normed_add_group_hom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and\n    `lift S f hf : normed_add_group_hom (M ⧸ 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 `ε`, there exists `m` such that `f m = n ∧ ‖m‖ < ‖n‖ + ε`.\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 ⧸ S` by\n`‖x‖ = 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 ⧸ 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 | ‖x‖ < ε}` for positive `ε`.\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\nnoncomputable theory\n\n\nopen quotient_add_group metric set\nopen_locale topology nnreal\n\nvariables {M N : Type*} [seminormed_add_comm_group M] [seminormed_add_comm_group N]\n\n/-- The definition of the norm on the quotient by an additive subgroup. -/\nnoncomputable\ninstance norm_on_quotient (S : add_subgroup M) : has_norm (M ⧸ S) :=\n{ norm := λ x, Inf (norm '' {m | mk' S m = x}) }\n\nlemma add_subgroup.quotient_norm_eq {S : add_subgroup M} (x : M ⧸ S) :\n  ‖x‖ = Inf (norm '' {m : M | (m : M ⧸ S) = x}) :=\nrfl\n\nlemma image_norm_nonempty {S : add_subgroup M} :\n  ∀ x : M ⧸ S, (norm '' {m | mk' S m = x}).nonempty :=\nbegin\n  rintro ⟨m⟩,\n  rw set.nonempty_image_iff,\n  use m,\n  change mk' S m = _,\n  refl\nend\n\nlemma bdd_below_image_norm (s : set M) : bdd_below (norm '' s) :=\nbegin\n  use 0,\n  rintro _ ⟨x, hx, rfl⟩,\n  apply norm_nonneg\nend\n\n/-- The norm on the quotient satisfies `‖-x‖ = ‖x‖`. -/\nlemma quotient_norm_neg {S : add_subgroup M} (x : M ⧸ S) : ‖-x‖ = ‖x‖ :=\nbegin\n  suffices : norm '' {m | mk' S m = x} = norm '' {m | mk' S m = -x},\n    by simp only [this, norm],\n  ext r,\n  split,\n  { rintros ⟨m, rfl : mk' S m = x, rfl⟩,\n    rw ← norm_neg,\n    exact ⟨-m, by simp only [(mk' S).map_neg, set.mem_set_of_eq], rfl⟩ },\n  { rintros ⟨m, hm : mk' S m = -x, rfl⟩,\n    exact ⟨-m, by simpa using neg_eq_iff_eq_neg.mpr ((mk'_apply _ _).symm.trans hm)⟩ }\nend\n\nlemma quotient_norm_sub_rev {S : add_subgroup M} (x y : M ⧸ S) : ‖x - y‖ = ‖y - x‖ :=\nby rw [show x - y = -(y - x), by abel, quotient_norm_neg]\n\n/-- The norm of the projection is smaller or equal to the norm of the original element. -/\nlemma quotient_norm_mk_le (S : add_subgroup M) (m : M) :\n  ‖mk' S m‖ ≤ ‖m‖ :=\nbegin\n  apply cInf_le,\n  use 0,\n  { rintros _ ⟨n, h, rfl⟩,\n    apply norm_nonneg },\n  { apply set.mem_image_of_mem,\n    rw set.mem_set_of_eq }\nend\n\n/-- The norm of the projection is smaller or equal to the norm of the original element. -/\nlemma quotient_norm_mk_le' (S : add_subgroup M) (m : M) :\n  ‖(m : M ⧸ S)‖ ≤ ‖m‖ := quotient_norm_mk_le S m\n\n/-- The norm of the image under the natural morphism to the quotient. -/\nlemma quotient_norm_mk_eq (S : add_subgroup M) (m : M) :\n  ‖mk' S m‖ = Inf ((λ x, ‖m + x‖) '' S) :=\nbegin\n  change Inf _ = _,\n  congr' 1,\n  ext r,\n  simp_rw [coe_mk', eq_iff_sub_mem],\n  split,\n  { rintros ⟨y, h, rfl⟩,\n    use [y - m, h],\n    simp },\n  { rintros ⟨y, h, rfl⟩,\n    use m + y,\n    simpa using h },\nend\n\n/-- The quotient norm is nonnegative. -/\nlemma quotient_norm_nonneg (S : add_subgroup M) : ∀ x : M ⧸ S, 0 ≤ ‖x‖ :=\nbegin\n  rintros ⟨m⟩,\n  change 0 ≤ ‖mk' S m‖,\n  apply le_cInf (image_norm_nonempty _),\n  rintros _ ⟨n, h, rfl⟩,\n  apply norm_nonneg\nend\n\n/-- The quotient norm is nonnegative. -/\nlemma norm_mk_nonneg (S : add_subgroup M) (m : M) : 0 ≤ ‖mk' S m‖ :=\nquotient_norm_nonneg S _\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`. -/\nlemma quotient_norm_eq_zero_iff (S : add_subgroup M) (m : M) :\n  ‖mk' S m‖ = 0 ↔ m ∈ closure (S : set M) :=\nbegin\n  have : 0 ≤ ‖mk' S m‖ := norm_mk_nonneg S m,\n  rw [← this.le_iff_eq, quotient_norm_mk_eq, real.Inf_le_iff],\n  simp_rw [zero_add],\n  { calc (∀ ε > (0 : ℝ), ∃ r ∈ (λ x, ‖m + x‖) '' (S : set M), r < ε) ↔\n        (∀ ε > 0, (∃ x ∈ S, ‖m + x‖ < ε)) : by simp [set.bex_image_iff]\n     ... ↔ ∀ ε > 0, (∃ x ∈ S, ‖m + -x‖ < ε) : _\n     ... ↔ ∀ ε > 0, (∃ x ∈ S, x ∈ metric.ball m ε) : by simp [dist_eq_norm, ← sub_eq_add_neg,\n                                                              norm_sub_rev]\n     ... ↔ m ∈ closure ↑S : by simp [metric.mem_closure_iff, dist_comm],\n    refine forall₂_congr (λ ε ε_pos, _),\n    rw [← S.exists_neg_mem_iff_exists_mem],\n    simp },\n  { use 0,\n    rintro _ ⟨x, x_in, rfl⟩,\n    apply norm_nonneg },\n  rw set.nonempty_image_iff,\n  use [0, S.zero_mem]\nend\n\n/-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x`\nand `‖m‖ < ‖x‖ + ε`. -/\nlemma norm_mk_lt {S : add_subgroup M} (x : M ⧸ S) {ε : ℝ} (hε : 0 < ε) :\n  ∃ (m : M), mk' S m = x ∧ ‖m‖ < ‖x‖ + ε :=\nbegin\n  obtain ⟨_, ⟨m : M, H : mk' S m = x, rfl⟩, hnorm : ‖m‖ < ‖x‖ + ε⟩ :=\n    real.lt_Inf_add_pos (image_norm_nonempty x) hε,\n  subst H,\n  exact ⟨m, rfl, hnorm⟩,\nend\n\n/-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m + s‖ < ‖mk' S m‖ + ε`. -/\nlemma norm_mk_lt' (S : add_subgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) :\n  ∃ s ∈ S, ‖m + s‖ < ‖mk' S m‖ + ε :=\nbegin\n  obtain ⟨n : M, hn : mk' S n = mk' S m, hn' : ‖n‖ < ‖mk' S m‖ + ε⟩ :=\n    norm_mk_lt (quotient_add_group.mk' S m) hε,\n  erw [eq_comm, quotient_add_group.eq] at hn,\n  use [- m + n, hn],\n  rwa [add_neg_cancel_left]\nend\n\n/-- The quotient norm satisfies the triangle inequality. -/\nlemma quotient_norm_add_le (S : add_subgroup M) (x y : M ⧸ S) : ‖x + y‖ ≤ ‖x‖ + ‖y‖ :=\nbegin\n  refine le_of_forall_pos_le_add (λ ε hε, _),\n  replace hε := half_pos hε,\n  obtain ⟨m, rfl, hm : ‖m‖ < ‖mk' S m‖ + ε / 2⟩ := norm_mk_lt x hε,\n  obtain ⟨n, rfl, hn : ‖n‖ < ‖mk' S n‖ + ε / 2⟩ := norm_mk_lt y hε,\n  calc ‖mk' S m + mk' S n‖ = ‖mk' S (m +  n)‖ : by rw (mk' S).map_add\n  ... ≤ ‖m + n‖ : quotient_norm_mk_le S (m + n)\n  ... ≤ ‖m‖ + ‖n‖ : norm_add_le _ _\n  ... ≤ ‖mk' S m‖ + ‖mk' S n‖ + ε : by linarith\nend\n\n/-- The quotient norm of `0` is `0`. -/\nlemma norm_mk_zero (S : add_subgroup M) : ‖(0 : M ⧸ S)‖ = 0 :=\nbegin\n  erw quotient_norm_eq_zero_iff,\n  exact subset_closure S.zero_mem\nend\n\n/-- If `(m : M)` has norm equal to `0` in `M ⧸ S` for a closed subgroup `S` of `M`, then\n`m ∈ S`. -/\nlemma norm_zero_eq_zero (S : add_subgroup M) (hS : is_closed (S : set M)) (m : M)\n  (h : ‖mk' S m‖ = 0) : m ∈ S :=\nby rwa [quotient_norm_eq_zero_iff, hS.closure_eq] at h\n\nlemma quotient_nhd_basis (S : add_subgroup M) :\n  (𝓝 (0 : M ⧸ S)).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {x | ‖x‖ < ε}) :=\n⟨begin\n  intros U,\n  split,\n  { intros U_in,\n    rw ← (mk' S).map_zero at U_in,\n    have := preimage_nhds_coinduced U_in,\n    rcases metric.mem_nhds_iff.mp this with ⟨ε, ε_pos, H⟩,\n    use [ε/2, half_pos ε_pos],\n    intros x x_in,\n    dsimp at x_in,\n    rcases norm_mk_lt x (half_pos ε_pos) with ⟨y, rfl, ry⟩,\n    apply H,\n    rw ball_zero_eq,\n    dsimp,\n    linarith },\n  { rintros ⟨ε, ε_pos, h⟩,\n    have : (mk' S) '' (ball (0 : M) ε) ⊆ {x | ‖x‖ < ε},\n    { rintros _ ⟨x, x_in, rfl⟩,\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 is_open.mem_nhds,\n    { change is_open ((mk' S) ⁻¹' _),\n      erw quotient_add_group.preimage_image_coe,\n      apply is_open_Union,\n      rintros ⟨s, s_in⟩,\n      exact (continuous_add_right s).is_open_preimage _ is_open_ball },\n    { exact ⟨(0 : M), mem_ball_self ε_pos, (mk' S).map_zero⟩ } },\nend⟩\n\n/-- The seminormed group structure on the quotient by an additive subgroup. -/\nnoncomputable\ninstance add_subgroup.seminormed_add_comm_group_quotient (S : add_subgroup M) :\n  seminormed_add_comm_group (M ⧸ S) :=\n{ dist               := λ x y, ‖x - y‖,\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,\n  begin\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  end,\n  dist_eq := λ x y, rfl,\n  to_uniform_space   := topological_add_group.to_uniform_space (M ⧸ S),\n  uniformity_dist    :=\n  begin\n    rw uniformity_eq_comap_nhds_zero',\n    have := (quotient_nhd_basis S).comap (λ (p : (M ⧸ S) × M ⧸ S), p.2 - p.1),\n    apply this.eq_of_same_basis,\n    have : ∀ ε : ℝ, (λ (p : (M ⧸ S) × M ⧸ S), p.snd - p.fst) ⁻¹' {x | ‖x‖ < ε} =\n      {p : (M ⧸ S) × M ⧸ S | ‖p.fst - p.snd‖ < ε},\n    { intro ε,\n      ext x,\n      dsimp,\n      rw quotient_norm_sub_rev },\n    rw funext this,\n    refine filter.has_basis_binfi_principal _ set.nonempty_Ioi,\n    rintros ε (ε_pos : 0 < ε) η (η_pos : 0 < η),\n    refine ⟨min ε η, lt_min ε_pos η_pos, _, _⟩,\n    { suffices : ∀ (a b : M ⧸ S), ‖a - b‖ < ε → ‖a - b‖ < η → ‖a - b‖ < ε, by simpa,\n      exact λ a b h h', h },\n    { simp }\n  end }\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 : add_subgroup M) : (quotient.topological_space : topological_space $ M ⧸ S) =\nS.seminormed_add_comm_group_quotient.to_uniform_space.to_topological_space :=\nrfl\n\n/-- The quotient in the category of normed groups. -/\nnoncomputable\ninstance add_subgroup.normed_add_comm_group_quotient (S : add_subgroup M) [is_closed (S : set M)] :\n  normed_add_comm_group (M ⧸ S) :=\n{ eq_of_dist_eq_zero :=\n  begin\n    rintros ⟨m⟩ ⟨m'⟩ (h : ‖mk' S m - mk' S m'‖ = 0),\n    erw [← (mk' S).map_sub, quotient_norm_eq_zero_iff, ‹is_closed _›.closure_eq,\n         ← quotient_add_group.eq_iff_sub_mem] at h,\n    exact h\n  end,\n  .. add_subgroup.seminormed_add_comm_group_quotient S }\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 : add_subgroup M) [is_closed (S : set M)] :\n  S.seminormed_add_comm_group_quotient = normed_add_comm_group.to_seminormed_add_comm_group := rfl\n\n\nnamespace add_subgroup\n\nopen normed_add_group_hom\n\n/-- The morphism from a seminormed group to the quotient by a subgroup. -/\nnoncomputable\ndef normed_mk (S : add_subgroup M) : normed_add_group_hom M (M ⧸ S) :=\n{ bound' := ⟨1, λ m, by simpa [one_mul] using quotient_norm_mk_le  _ m⟩,\n  .. quotient_add_group.mk' S }\n\n/-- `S.normed_mk` agrees with `quotient_add_group.mk' S`. -/\n@[simp]\nlemma normed_mk.apply (S : add_subgroup M) (m : M) : normed_mk S m = quotient_add_group.mk' S m :=\nrfl\n\n/-- `S.normed_mk` is surjective. -/\nlemma surjective_normed_mk (S : add_subgroup M) : function.surjective (normed_mk S) :=\nsurjective_quot_mk _\n\n/-- The kernel of `S.normed_mk` is `S`. -/\nlemma ker_normed_mk (S : add_subgroup M) : S.normed_mk.ker = S :=\nquotient_add_group.ker_mk  _\n\n/-- The operator norm of the projection is at most `1`. -/\nlemma norm_normed_mk_le (S : add_subgroup M) : ‖S.normed_mk‖ ≤ 1 :=\nnormed_add_group_hom.op_norm_le_bound _ zero_le_one (λ m, by simp [quotient_norm_mk_le'])\n\n/-- The operator norm of the projection is `1` if the subspace is not dense. -/\nlemma norm_normed_mk (S : add_subgroup M) (h : (S.topological_closure : set M) ≠ univ) :\n  ‖S.normed_mk‖ = 1 :=\nbegin\n  obtain ⟨x, hx⟩ := set.nonempty_compl.2 h,\n  let y := S.normed_mk x,\n  have hy : ‖y‖ ≠ 0,\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 (λ ε hε, _)),\n  suffices : 1 ≤ ‖S.normed_mk‖ + min ε ((1 : ℝ)/2),\n  { exact le_add_of_le_add_left this (min_le_left ε ((1 : ℝ)/2)) },\n  have hδ := sub_pos.mpr (lt_of_le_of_lt (min_le_right ε ((1 : ℝ)/2)) one_half_lt_one),\n  have hδpos : 0 < min ε ((1 : ℝ)/2) := lt_min hε one_half_pos,\n  have hδnorm := mul_pos (div_pos hδpos hδ) (lt_of_le_of_ne (norm_nonneg y) hy.symm),\n  obtain ⟨m, hm, hlt⟩ := norm_mk_lt y hδnorm,\n  have hrw : ‖y‖ + min ε (1 / 2) / (1 - min ε (1 / 2)) * ‖y‖ =\n    ‖y‖ * (1 + min ε (1 / 2) / (1 - min ε (1 / 2))) := by ring,\n  rw [hrw] at hlt,\n  have hm0 : ‖m‖ ≠ 0,\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₁ : ‖y‖ * (1 + min ε (1 / 2) / (1 - min ε (1 / 2))) / ‖m‖ =\n    (‖y‖ / ‖m‖) * (1 + min ε (1 / 2) / (1 - min ε (1 / 2))) := by ring,\n  rw [hrw₁] at hlt,\n  replace hlt := (inv_pos_lt_iff_one_lt_mul (lt_trans (div_pos hδpos hδ) (lt_one_add _))).2 hlt,\n  suffices : ‖S.normed_mk‖ ≥ 1 - min ε (1 / 2),\n  { exact sub_le_iff_le_add.mp this },\n  calc ‖S.normed_mk‖ ≥ ‖(S.normed_mk) m‖ / ‖m‖ : ratio_le_op_norm S.normed_mk m\n  ...  = ‖y‖ / ‖m‖ : by rw [normed_mk.apply, hm]\n  ... ≥ (1 + min ε (1 / 2) / (1 - min ε (1 / 2)))⁻¹ : le_of_lt hlt\n  ... = 1 - min ε (1 / 2) : by field_simp [(ne_of_lt hδ).symm]\nend\n\n/-- The operator norm of the projection is `0` if the subspace is dense. -/\nlemma norm_trivial_quotient_mk (S : add_subgroup M)\n  (h : (S.topological_closure : set M) = set.univ) : ‖S.normed_mk‖ = 0 :=\nbegin\n  refine le_antisymm (op_norm_le_bound _ le_rfl (λ x, _)) (norm_nonneg _),\n  have hker : x ∈ (S.normed_mk).ker.topological_closure,\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, zero_mul],\nend\n\nend add_subgroup\n\nnamespace normed_add_group_hom\n\n/-- `is_quotient f`, for `f : M ⟶ N` means that `N` is isomorphic to the quotient of `M`\nby the kernel of `f`. -/\nstructure is_quotient (f : normed_add_group_hom M N) : Prop :=\n(surjective : function.surjective f)\n(norm : ∀ x, ‖f x‖ = Inf ((λ m, ‖x + m‖) '' f.ker))\n\n/-- Given  `f : normed_add_group_hom M N` such that `f s = 0` for all `s ∈ S`, where,\n`S : add_subgroup M` is closed, the induced morphism `normed_add_group_hom (M ⧸ S) N`. -/\nnoncomputable\ndef lift {N : Type*} [seminormed_add_comm_group N] (S : add_subgroup M)\n  (f : normed_add_group_hom M N) (hf : ∀ s ∈ S, f s = 0) :\n  normed_add_group_hom (M ⧸ S) N :=\n{ bound' :=\n  begin\n    obtain ⟨c : ℝ, hcpos : (0 : ℝ) < c, hc : ∀ x, ‖f x‖ ≤ c * ‖x‖⟩ := f.bound,\n    refine ⟨c, λ mbar, le_of_forall_pos_le_add (λ ε hε, _)⟩,\n    obtain ⟨m : M, rfl : mk' S m = mbar, hmnorm : ‖m‖ < ‖mk' S m‖ + ε/c⟩ :=\n      norm_mk_lt mbar (div_pos hε hcpos),\n    calc ‖f m‖ ≤ c * ‖m‖ : hc m\n    ... ≤ c*(‖mk' S m‖ + ε/c) : ((mul_lt_mul_left hcpos).mpr hmnorm).le\n    ... = c * ‖mk' S m‖ + ε : by rw [mul_add, mul_div_cancel' _ hcpos.ne.symm]\n  end,\n  .. quotient_add_group.lift S f.to_add_monoid_hom hf }\n\nlemma lift_mk {N : Type*} [seminormed_add_comm_group N] (S : add_subgroup M)\n  (f : normed_add_group_hom M N) (hf : ∀ s ∈ S, f s = 0) (m : M) :\n  lift S f hf (S.normed_mk m) = f m := rfl\n\nlemma lift_unique {N : Type*} [seminormed_add_comm_group N] (S : add_subgroup M)\n  (f : normed_add_group_hom M N) (hf : ∀ s ∈ S, f s = 0)\n  (g : normed_add_group_hom (M ⧸ S) N) :\n  g.comp (S.normed_mk) = f → g = lift S f hf :=\nbegin\n  intro h,\n  ext,\n  rcases add_subgroup.surjective_normed_mk _ x with ⟨x,rfl⟩,\n  change (g.comp (S.normed_mk) x) = _,\n  simpa only [h]\nend\n\n/-- `S.normed_mk` satisfies `is_quotient`. -/\nlemma is_quotient_quotient (S : add_subgroup M) : is_quotient (S.normed_mk) :=\n⟨S.surjective_normed_mk, λ m, by simpa [S.ker_normed_mk] using quotient_norm_mk_eq _ m⟩\n\nlemma is_quotient.norm_lift {f : normed_add_group_hom M N} (hquot : is_quotient f) {ε : ℝ}\n  (hε : 0 < ε) (n : N) : ∃ (m : M), f m = n ∧ ‖m‖ < ‖n‖ + ε :=\nbegin\n  obtain ⟨m, rfl⟩ := hquot.surjective n,\n  have nonemp : ((λ m', ‖m + m'‖) '' f.ker).nonempty,\n  { rw set.nonempty_image_iff,\n    exact ⟨0, f.ker.zero_mem⟩ },\n  rcases real.lt_Inf_add_pos nonemp hε with\n    ⟨_, ⟨⟨x, hx, rfl⟩, H : ‖m + x‖ < Inf ((λ (m' : M), ‖m + m'‖) '' f.ker) + ε⟩⟩,\n  exact ⟨m+x, by rw [map_add,(normed_add_group_hom.mem_ker f x).mp hx, add_zero],\n               by rwa hquot.norm⟩,\nend\n\nlemma is_quotient.norm_le {f : normed_add_group_hom M N} (hquot : is_quotient f) (m : M) :\n  ‖f m‖ ≤ ‖m‖ :=\nbegin\n  rw hquot.norm,\n  apply cInf_le,\n  { use 0,\n    rintros _ ⟨m', hm', rfl⟩,\n    apply norm_nonneg },\n  { exact ⟨0, f.ker.zero_mem, by simp⟩ }\nend\n\nlemma lift_norm_le {N : Type*} [seminormed_add_comm_group N] (S : add_subgroup M)\n  (f : normed_add_group_hom M N) (hf : ∀ s ∈ S, f s = 0)\n  {c : ℝ≥0} (fb : ‖f‖ ≤ c) :\n  ‖lift S f hf‖ ≤ c :=\nbegin\n  apply op_norm_le_bound _ c.coe_nonneg,\n  intros x,\n  by_cases hc : c = 0,\n  { simp only [hc, nnreal.coe_zero, zero_mul] at fb ⊢,\n    obtain ⟨x, rfl⟩ := surjective_quot_mk _ x,\n    show ‖f x‖ ≤ 0,\n    calc ‖f x‖ ≤ 0 * ‖x‖ : f.le_of_op_norm_le fb x\n          ... = 0 : zero_mul _ },\n  { replace hc : 0 < c := pos_iff_ne_zero.mpr hc,\n    apply le_of_forall_pos_le_add,\n    intros ε hε,\n    have aux : 0 < (ε / c) := div_pos hε hc,\n    obtain ⟨x, rfl, Hx⟩ : ∃ x', S.normed_mk x' = x ∧ ‖x'‖ < ‖x‖ + (ε / c) :=\n      (is_quotient_quotient _).norm_lift aux _,\n    rw lift_mk,\n    calc ‖f x‖ ≤ c * ‖x‖ : f.le_of_op_norm_le fb x\n          ... ≤ c * (‖S.normed_mk x‖ + ε / c) : (mul_le_mul_left _).mpr Hx.le\n          ... = c * _ + ε : _,\n    { exact_mod_cast hc },\n    { rw [mul_add, mul_div_cancel'], exact_mod_cast hc.ne' } },\nend\n\nlemma lift_norm_noninc {N : Type*} [seminormed_add_comm_group N] (S : add_subgroup M)\n  (f : normed_add_group_hom M N) (hf : ∀ s ∈ S, f s = 0)\n  (fb : f.norm_noninc) :\n  (lift S f hf).norm_noninc :=\nλ x,\nbegin\n  have fb' : ‖f‖ ≤ (1 : ℝ≥0) := norm_noninc.norm_noninc_iff_norm_le_one.mp fb,\n  simpa using le_of_op_norm_le _ (f.lift_norm_le _ _ fb') _,\nend\n\nend normed_add_group_hom\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\nsection submodule\n\nvariables {R : Type*} [ring R] [module R M] (S : submodule R M)\n\ninstance submodule.quotient.seminormed_add_comm_group :\n  seminormed_add_comm_group (M ⧸ S) :=\nadd_subgroup.seminormed_add_comm_group_quotient S.to_add_subgroup\n\ninstance submodule.quotient.normed_add_comm_group [hS : is_closed (S : set M)] :\n  normed_add_comm_group (M ⧸ S) :=\n@add_subgroup.normed_add_comm_group_quotient _ _ S.to_add_subgroup hS\n\ninstance submodule.quotient.complete_space [complete_space M] : complete_space (M ⧸ S) :=\nquotient_add_group.complete_space M S.to_add_subgroup\n\n/-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `submodule.quotient.mk m = x`\nand `‖m‖ < ‖x‖ + ε`. -/\nlemma submodule.quotient.norm_mk_lt {S : submodule R M} (x : M ⧸ S) {ε : ℝ} (hε : 0 < ε) :\n  ∃ m : M, submodule.quotient.mk m = x ∧ ‖m‖ < ‖x‖ + ε :=\nnorm_mk_lt x hε\n\nlemma submodule.quotient.norm_mk_le (m : M) :\n  ‖(submodule.quotient.mk m : M ⧸ S)‖ ≤ ‖m‖ :=\nquotient_norm_mk_le S.to_add_subgroup m\n\ninstance submodule.quotient.normed_space (𝕜 : Type*) [normed_field 𝕜] [normed_space 𝕜 M]\n  [has_smul 𝕜 R] [is_scalar_tower 𝕜 R M] : normed_space 𝕜 (M ⧸ S) :=\n{ norm_smul_le := λ k x, le_of_forall_pos_le_add $ λ ε hε,\n  begin\n    have := (nhds_basis_ball.tendsto_iff nhds_basis_ball).mp\n      ((@real.uniform_continuous_const_mul (‖k‖)).continuous.tendsto (‖x‖)) ε hε,\n    simp only [mem_ball, exists_prop, dist, abs_sub_lt_iff] at this,\n    rcases this with ⟨δ, hδ, h⟩,\n    obtain ⟨a, rfl, ha⟩ := submodule.quotient.norm_mk_lt x hδ,\n    specialize h (‖a‖) (⟨by linarith, by linarith [submodule.quotient.norm_mk_le S a]⟩),\n    calc _ ≤ ‖k‖ * ‖a‖ : (quotient_norm_mk_le S.to_add_subgroup (k • a)).trans_eq (norm_smul k a)\n    ...    ≤ _ : (sub_lt_iff_lt_add'.mp h.1).le\n  end,\n  .. submodule.quotient.module' S, }\n\nend submodule\n\nsection ideal\n\nvariables {R : Type*} [semi_normed_comm_ring R] (I : ideal R)\n\nlemma ideal.quotient.norm_mk_lt {I : ideal R} (x : R ⧸ I) {ε : ℝ} (hε : 0 < ε) :\n  ∃ r : R, ideal.quotient.mk I r = x ∧ ‖r‖ < ‖x‖ + ε :=\nnorm_mk_lt x hε\n\nlemma ideal.quotient.norm_mk_le (r : R) :\n  ‖ideal.quotient.mk I r‖ ≤ ‖r‖ :=\nquotient_norm_mk_le I.to_add_subgroup r\n\ninstance ideal.quotient.semi_normed_comm_ring : semi_normed_comm_ring (R ⧸ I) :=\n{ mul_comm := mul_comm,\n  norm_mul := λ x y, le_of_forall_pos_le_add $ λ ε hε,\n  begin\n    have := ((nhds_basis_ball.prod_nhds nhds_basis_ball).tendsto_iff nhds_basis_ball).mp\n      (real.continuous_mul.tendsto (‖x‖, ‖y‖)) ε hε,\n    simp only [set.mem_prod, mem_ball, and_imp, prod.forall, exists_prop, prod.exists] at this,\n    rcases this with ⟨ε₁, ε₂, ⟨h₁, h₂⟩, h⟩,\n    obtain ⟨⟨a, rfl, ha⟩, ⟨b, rfl, hb⟩⟩ :=\n      ⟨ideal.quotient.norm_mk_lt x h₁, ideal.quotient.norm_mk_lt y h₂⟩,\n    simp only [dist, abs_sub_lt_iff] at h,\n    specialize h (‖a‖) (‖b‖) (⟨by linarith, by linarith [ideal.quotient.norm_mk_le I a]⟩)\n      (⟨by linarith, by linarith [ideal.quotient.norm_mk_le I b]⟩),\n    calc _ ≤ ‖a‖ * ‖b‖ : (ideal.quotient.norm_mk_le I (a * b)).trans (norm_mul_le a b)\n    ...    ≤ _        : (sub_lt_iff_lt_add'.mp h.1).le\n  end,\n  .. submodule.quotient.seminormed_add_comm_group I }\n\ninstance ideal.quotient.normed_comm_ring [is_closed (I : set R)] :\n  normed_comm_ring (R ⧸ I) :=\n{ .. ideal.quotient.semi_normed_comm_ring I,\n  .. submodule.quotient.normed_add_comm_group I }\n\nvariables (𝕜 : Type*) [normed_field 𝕜]\n\ninstance ideal.quotient.normed_algebra [normed_algebra 𝕜 R] :\n  normed_algebra 𝕜 (R ⧸ I) :=\n{ .. submodule.quotient.normed_space I 𝕜,\n  .. ideal.quotient.algebra 𝕜 }\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/group/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7865978177406838}}
{"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.\n\n\nIn this unit, we formalize the syntax\nand semantics of our first example of\na complete logic: a simple logic called\npropositional logic.\n\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 (∧), or (∨), not (¬), and so forth.\n\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 ∨ Y             -- application: or X Y\n- (X ∨ Y) ∧ (X ∧ Z) -- etc.\n- (X ∨ Y) ∧ (X ∧ pTrue)\n- etc\n\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. \n\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).\n\nHere are the rules for how eval works:\n\nLITERAL TERMS\n\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.\n\nVARIABLE TERMS\n\nTo evaluate a variable expression, such\nas X, or to evaluate an expression with\nseveral variables, such as X ∧ 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).\n\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?\n\nAPPLICATION TERMS\n\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.\n\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.\n\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 ¬ pTrue\n#check ¬ pFalse\n#check X\n#check ¬ X\n#check Y\n#check X ∧ Y\n#check X ∨ Y\n#check ¬ (X ∧ Y)\n-- Will be equal to the line above\n#check (unOpExp notOp) ((binOpExp andOp) \n            (varExp (mkVar 0)) \n            (varExp (mkVar 1)))\n#check ¬ (X ∧ Y) ∨ (¬ X ∨ ¬ 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 ¬ (X ∧ Y) ∨ (X ∨ Z) -- correct\n#check ¬ (X ∧ Y) ∨ (X ∨ )  -- error\n#check ¬ X ¬ Y             -- error\n#check pTrue pFalse        -- error\n\n\n/-\n    *****************\n    *** SEMANTICS ***\n    *****************\n-/\n\n-- Interpretations\n\ndef allFalse : var → bool\n| _ := ff\n\ndef allTrue : var → bool\n| _ := tt\n\ndef anInterp: var → 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 ∧ Y) allTrue\n#eval pEval (X ∧ Y) allFalse\n#eval pEval (X ∧ Y) anInterp\n#eval pEval (X ∨ Y) anInterp\n#eval pEval (X ∧ Z) anInterp\n#eval pEval (¬ (X ∧ Z)) anInterp\n#eval pEval (¬ (X ∧ Y) ∨ (¬ X ∨ ¬ Y)) anInterp\n#eval pEval (¬ (X ∧ Y) ∨ (¬ X ∨ ¬ 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.\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 → 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.\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 ∧, ∨, \nand ¬. 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.\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-/\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 ∧ Y)\n-- A predicate for set {X,Y}\n\n/-\nAnother example\n-/\n#reduce vars_in_exp (X ∧ 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.\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∀ e : pExp, \n∀ i : pInterp,\n∀ v1 v2 : bool,\nv1 = pEval e i → v2 = pEval e i → 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 ∧ (¬ X_exp)) is \nfalse under any interpretation. We\ncan easily prove this proposition.\n-/\n\ntheorem contra :\n∀ V : pVar,\n∀ i : pInterp,\npEval \n    ((mk_var_pexp V) ∧ ¬ (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 → 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) ∨ (¬ (mk_var_exp V))\nalways evaluates to true.\n-/\n\ndef valid (e : pExp) : Prop :=\n    ∀ 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    ∀ 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    ∃ i, isModel i e\n\n/-\nExample: X ∧ ¬ X is unsatisfiable.\n-/\n\nexample : unsatisfiable (X_exp ∧ (¬ (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 ∨ (¬ X)\nis valid.\n\nEXERCISE: Prove the proposition\nthat (X ∨ Y) ∧ 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: ℕ → ℕ → 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: ℕ) : pInterp :=\n    if (m >= 2^n)\n    then falseInterp \n    else\n    λ 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 : ℕ) : pInterp :=\nλ 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": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/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.9343951607140232, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7865978072488227}}
{"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-/\n\nimport data.nat.prime\nimport data.nat.totient\nimport algebra.periodic\nimport data.finset.locally_finite\nimport data.nat.count\n\n\n/-!\n# The Prime Counting Function\n\nIn this file we define the prime counting function: the function on natural numbers that returns\nthe number of primes less than or equal to its input.\n\n## Main Results\n\nThe main definitions for this file are\n\n- `nat.prime_counting`: The prime counting function π\n- `nat.prime_counting'`: π(n - 1)\n\nWe then prove that these are monotone in `nat.monotone_prime_counting` and\n`nat.monotone_prime_counting'`. The last main theorem `nat.prime_counting'_add_le` is an upper\nbound on `π'` which arises by observing that all numbers greater than `k` and not coprime to `k`\nare not prime, and so only at most `φ(k)/k` fraction of the numbers from `k` to `n` are prime.\n\n## Notation\n\nWe use the standard notation `π` to represent the prime counting function (and `π'` to represent\nthe reindexed version).\n\n-/\n\nnamespace nat\nopen finset\n\n/--\nA variant of the traditional prime counting function which gives the number of primes\n*strictly* less than the input. More convenient for avoiding off-by-one errors.\n-/\ndef prime_counting' : ℕ → ℕ := nat.count prime\n\n/-- The prime counting function: Returns the number of primes less than or equal to the input. -/\ndef prime_counting (n : ℕ) : ℕ := prime_counting' (n + 1)\n\nlocalized \"notation `π` := nat.prime_counting\" in nat\nlocalized \"notation `π'` := nat.prime_counting'\" in nat\n\nlemma monotone_prime_counting' : monotone prime_counting' := count_monotone prime\n\nlemma monotone_prime_counting : monotone prime_counting :=\nλ a b a_le_b, monotone_prime_counting' (add_le_add_right a_le_b 1)\n\n/-- A linear upper bound on the size of the `prime_counting'` function -/\nlemma prime_counting'_add_le {a k : ℕ} (h0 : 0 < a) (h1 : a < k) (n : ℕ) :\n  π' (k + n) ≤ π' k + nat.totient a * (n / a + 1) :=\ncalc π' (k + n)\n    ≤ ((range k).filter (prime)).card + ((Ico k (k + n)).filter (prime)).card :\n        begin\n          rw [prime_counting', count_eq_card_filter_range, range_eq_Ico,\n              ←Ico_union_Ico_eq_Ico (zero_le k) (le_self_add), filter_union],\n          apply card_union_le,\n        end\n... ≤ π' k + ((Ico k (k + n)).filter (prime)).card :\n        by rw [prime_counting', count_eq_card_filter_range]\n... ≤ π' k + ((Ico k (k + n)).filter (coprime a)).card :\n        begin\n          refine add_le_add_left (card_le_of_subset _) k.prime_counting',\n          simp only [subset_iff, and_imp, mem_filter, mem_Ico],\n          intros p succ_k_le_p p_lt_n p_prime,\n          split,\n          { exact ⟨succ_k_le_p, p_lt_n⟩, },\n          { rw coprime_comm,\n            exact coprime_of_lt_prime h0 (gt_of_ge_of_gt succ_k_le_p h1) p_prime, },\n        end\n... ≤ π' k + totient a * (n / a + 1) :\n        begin\n          rw [add_le_add_iff_left],\n          exact Ico_filter_coprime_le k n h0,\n        end\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/prime_counting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7865459312482078}}
{"text": "import topology.metric_space.basic\n\nvariables {X : Type*} [metric_space X]\nvariables x y z : X\n\n#check dist_self\n#check dist_self y\n#check dist_comm\n#check dist_comm y x\n#check dist_triangle \n#check dist_triangle x y z\n#check two_mul\n#check @le_trans\n#check @div_le_div_of_le\n\n-- BEGIN\nexample (x y : X) : 0 ≤ dist x y := \nbegin \n  have h := dist_triangle x y x,\n  /- have h : dist x x ≤ dist x y + dist y x -/\n  rw dist_comm y x at h,\n  linarith [dist_self x],\nend\n\nexample (x y : X) : 0 ≤ dist x y := \nbegin \n  have h := dist_triangle x y x,\n  /- have h : dist x x ≤ dist x y + dist y x -/\n  rw dist_comm y x at h,\n  rw ← two_mul (dist x y) at h,\n  rw dist_self at h,\n  have h' : 0 / 2 ≤ (2 * dist x y) / 2 := div_le_div_of_le zero_le_two h,\n  rw ← div_mul_eq_mul_div at h',\n  norm_num at h',\n  exact h',\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/7_have/ex6_have_dist_nonneg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248174286374, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7865459255309567}}
{"text": "import lib.m154\n\nnamespace m154\nopen nat\n/-\n# Implications \n\nCe fichier aborde l'étude du connecteur logique  `→` (implication, notée `⇒` sur papier).\nLes exercices proposés, basés purement sur ce connecteur et les outils du fichier 01 sont un\npeu artificiels. Il s'agit d'être patient, les exercices naturels arriveront dans le fichier \nconcernant le quantificateur universel.\n\nUn énoncé `P → Q` se lit `si P alors Q`. \nCet énoncé permet de démontrer l'énoncé `Q` dès que on peut produire une preuve de `P`.\nC'est donc une justification de `Q` sous l'hypothèse que `P` est vérifié.\n\nPar exemple l'énoncé\n`carre_pos {a : ℝ} : a > 0 → a^2 > 0`\naffirme que si un nombre `a` est strictement positif alors son carré l'est aussi.\nOn dit que `a > 0` est la prémisse de l'implication et `a^2 > 0` sa conclusion.\n\nOn peut utiliser un tel énoncé pour démontrer la conclusion de l'implication en lui\nfournissant une démonstration de la prémisse. \nLa commande correspondante est `On conclut par ... appliqué à ...,`.\nDans l'exemple  qui suit, l'hypothèse `ha` est une démonstration de la prémisse.\n-/\n\n-- Dans toute la suite, x, a, b, c et d désignent des nombres réels.\nvariables {x a b c d : ℝ}\n\n\nexample (ha : a > 0) : a^2 > 0:=\nbegin\n  On conclut par carre_pos appliqué à ha,\nend\n\n/-\nEntraînez-vous en utilisant le théorème\n`non_zero_abs_pos {a : ℝ} : a ≠ 0 → |a| > 0`\n-/\n\nexample (h : x ≠ 0) : |x| > 0:=\nbegin\n  sorry\nend\n\n/-\nLes implications permettent aussi de faire du « raisonnement vers l'arrière » :\nsi le but à montrer est `Q` et que l'on a une hypothèse ou un théorème `nom` de la \nforme `P → Q`, alors on peut appliquer ce théorème pour transformer le but à prouver \nen `P`.\nLa commande correspondante est `Par ... il suffit de montrer que ...,`. \nReprenons l'exemple du carré de cette façon.\n-/\n\nexample (ha : a > 0) : a^2 > 0:=\nbegin\n  Par carre_pos il suffit de montrer que a > 0,\n  On conclut par ha,\nend\n\n/-\nBien sûr dans l'exemple ci-dessus on ne gagne rien à raisonner vers l'arrière.\nCe n'est intéressant que quand la prémisse n'est pas immédiatement disponible, comme\ndans l'exemple suivant qui commence par un pas vers l'arrière pour passer\nde `(a^2)^2` à `a^2` avant de conclure en appliquant vers l'avant le même résultat \npour `a` lui-même.\n-/\n\nexample (ha : a > 0) : (a^2)^2 > 0:=\nbegin\n  Par carre_pos il suffit de montrer que a^2 > 0,\n  On conclut par carre_pos appliqué à ha,\nend\n\n/-\nOn peut aussi conserver un mode de raisonnement vers l'avant du début à la fin en \nintroduisant un énoncé intermédiaire. Pour cela, on utilise\n`Fait nom : énoncé,`\nCela entraîne l'apparition d'un nouveau but à démontrer avant de reprendre le fil \nde la démonstration principale avec `nom : énoncé` disponible comme résultat \nsupplémentaire. Dans l'exemple ci-dessous, le nom choisi est `F`.\n-/\n\nexample (ha : a > 0) : (a^2)^2 > 0:=\nbegin\n  Fait F : a^2 > 0,\n    On conclut par carre_pos appliqué à ha,\n  On conclut par carre_pos appliqué à F,\nend\n\nexample (ha : a ≠ 0) : |a|^2 > 0:=\nbegin\n  sorry\nend\n\n/-\nPour démontrer une implication `P → Q`, la commande `Supposons hyp,`\npermet d'inclure `P` dans nos hypothèses sous le nom `hyp` et de remplacer le but \npar `Q`.\n-/\n\nexample : a > 0 → (a^2)^2 > 0 :=\nbegin\n  Supposons ha : a > 0, -- Ici on introduit l'hypothèse\n  Montrons que (a^2)^2 > 0, -- Cette ligne est optionelle car Lean sait où nous en sommes, \n                            -- mais elle améliore la lisibilité pour nous.\n  Fait F : a^2 > 0,\n    On conclut par carre_pos appliqué à ha,\n  On conclut par carre_pos appliqué à F,\nend\n\n\n/-\nDans la suite, on pourra utiliser les énoncés suivants qui font le lien \nentre une comparaison générale de deux éléments `x ≤ y` et une comparaison \nde leur différence à `0`.\n\n`inferieur_diff_pos {x y : ℝ} : x ≤ y → 0 ≤ y - x`\n`diff_pos_inferieur {x y : ℝ} : 0 ≤ y - x → x ≤ y`\n\n`inferieur_diff_neg {x y : ℝ} : x ≤ y → x - y ≤ 0`\n`diff_neg_inferieur {x y : ℝ} : x - y ≤ 0 → x ≤ y`\n\nVoyons un exemple qui démontre une implication en utilisant deux implications connues\n(`diff_pos_inferieur` et `inferieur_diff_pos`) et un calcul.\n-/\n\nlemma inferieur_add_gauche : a ≤ b → c + a ≤ c + b :=\nbegin\n  Supposons hab : a ≤ b, \n  Montrons que c + a ≤ c + b, \n  Par diff_pos_inferieur il suffit de montrer que 0 ≤ (c+b) - (c+a),  \n  calc \n    (c+b) - (c+a) = b - a : by On calcule\n              ... ≥ 0     : by On conclut par inferieur_diff_pos appliqué à hab,\nend\n\n/- A vous de jouer ! -/\n\nlemma inferieur_add_droite : a ≤ b →  a + c ≤ b + c :=\nbegin\n  sorry\nend\n\nlemma inferieur_simpl_gauche : c + a ≤ c + b → a ≤ b :=\nbegin\n  sorry\nend\n\n\n/- \nOn rencontre aussi des théorèmes ayant plusieurs hypothèses. \nPar exemple les deux énoncés suivants donnent les règles de signes pour la multiplication\n\n`pos_pos {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : 0 ≤ x*y`\n\n`neg_neg {x y : ℝ} (hx : x ≤ 0) (hy : y ≤ 0) : 0 ≤ x*y`\n\nChacun de ces énoncés déduit la conclusion `0 ≤ x*y` de deux prémisses portant sur `x` et `y`. \n\nL'application de ces théorèmes nécessite de justifier chacune des hypothèses, il y aura \ndonc autant de buts à montrer que d'hypothèses. La commande à utiliser est alors\n`Par nom il suffit de montrer que [P, Q],`\noù `P` et `Q` sont les prémisses à démontrer.\n-/\n\nexample (hc : 0 ≤ c) (hab : a ≤ b) : 0 ≤ (b - a) * c :=\nbegin\n  Par pos_pos il suffit de montrer que [0 ≤ b - a, 0 ≤ c], \n    On conclut par inferieur_diff_pos appliqué à hab,\n  On conclut par hc,\nend\n\nexample (hc : c ≤ 0) (hab : b ≤ a) : 0 ≤ (b - a) * c :=\nbegin\n  sorry\nend\n\n/-\nVoyons comment insérer ces exemples comme faits intermédiaires dans des contextes plus \ncompliqués.\n-/\n\nlemma inferieur_mul_droite (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=\nbegin\n  Par diff_pos_inferieur il suffit de montrer que 0 ≤ b*c - a*c,\n  Fait clef : 0 ≤ (b - a)*c,\n    Par pos_pos il suffit de montrer que [0 ≤ b - a, 0 ≤ c], \n      On conclut par inferieur_diff_pos appliqué à hab,\n    On conclut par hc,\n  calc \n    b*c - a*c = (b - a)*c : by On calcule\n          ... ≥ 0 : by On conclut par clef,\nend\n\n/-\nLa démonstration ci-dessus est un peu tortueuse. Nous allons la simplifier en \nfaisant travailler plus l'ordinateur. La commande `On applique` se charge de \ncomprendre quels sont les buts restants puis cherche chacun de ces buts parmi\nles hypothèses, ne laissant à démontrer que ce qui nécessite un nouvel argument.\nDans l'exemple de base, les deux prémisses sont déjà des hypothèses et il ne \nreste rien à faire.\n-/\n\nexample (hc : 0 ≤ c) (hab : 0 ≤ b - a) : 0 ≤ (b - a) * c :=\nbegin\n  On applique pos_pos, \nend\n\n/-\nDans l'exemple plus compliqué, on veut justifier `(b - a) * c ≥ 0` à partir\ndes hypothèses `hc : 0 ≤ c` et `hab : a ≤ b` donc il reste un peu de travail.\n-/\n\nexample (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=\nbegin\n  Par diff_pos_inferieur il suffit de montrer que 0 ≤ b*c - a*c,\n  calc \n    b*c - a*c = (b - a)*c : by On calcule\n          ... ≥ 0         : by { On applique pos_pos,\n                                 On conclut par inferieur_diff_pos appliqué à hab }\nend\n\n/-\nAdaptez cet exemple en utilisant `neg_neg` et `inferieur_diff_neg`.\n-/\n\nexample (hc : c ≤ 0) (hab :  a ≤ b) : b*c ≤ a*c :=\nbegin\n  sorry\nend\n\n/- \nOn peut aussi fournir les justifications de plusieurs prémisses en raisonnant \nvers l'avant. La commande `On conclut par ...` peut aussi être complétée en fournissant un\nune liste d'arguments, comme dans :\n`On conclut par pos_pos appliqué à [hab', hc],`\nde la démonstration suivante (où l'énoncé est toujours le même que `inferieur_mul_droite`).\n-/\nexample (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=\nbegin\n  Fait hab' : 0 ≤ b - a,\n    On conclut par inferieur_diff_pos appliqué à hab,\n  Fait H : b*c - a*c ≥ 0,\n    calc \n      b*c - a*c = (b - a) * c : by On calcule\n      ...       ≥ 0           : by On conclut par pos_pos appliqué à [hab', hc],\n  On conclut par diff_pos_inferieur appliqué à H,\nend\n\n/-\nAdoptez maintenant le style de la démonstration précédente pour montrer l'énoncé suivant.\n-/\n\nexample (hc : c ≤ 0) (hab :  a ≤ b) : b*c ≤ a*c :=\nbegin\n  sorry\nend\n\n/-\nOn peut se demander à quel connecteur logique correspondent tous ces énoncés ayant \ndeux prémisses et une conclusion. Il est possible de les voir comme des implications emboîtées.\nL'énoncé `inferieur_mul_droite` peut se lire : « si `0 ≤ c` alors si `a ≤ b` alors `a*c ≤ b*c` ».\n\nVérifions que Lean y pense bien de cette façon.\n-/\n\nexample : 0 ≤ c → (a ≤ b → a*c ≤ b*c) :=\nbegin\n  On conclut par inferieur_mul_droite,\nend\n\n/-\nCe type d'implications emboitées est en fait si courant que les parenthèses de l'énoncé ci-dessus\nne sont pas nécessaires : par défaut, Lean interprète `P → Q → R` comme `P → (Q → R)`.\n\nNous verrons plus tard que l'on peut aussi utiliser le connecteur logique `et` pour\nécrire de tels énoncés, mais cela se révèlera moins commode en pratique. \n-/\nend m154\n\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/02_implique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8774767970940975, "lm_q1q2_score": 0.7864397818568435}}
{"text": "/- Induction and Recursion -/ \n\nsection ex1\n\n/-\nUse the equation compiler to define addition multiplication and exponentiation on\nthe natural numbers.\nThen use the equation compiler to derive some of their basic properties.\n-/\nnamespace Hidden\nopen Nat\n\ndef add : Nat → Nat → Nat\n  | n, zero   => n\n  | n, succ m => succ $ add n m\n\n#print add\n\ndef mul : Nat → Nat → Nat\n  | _, zero   => zero\n  | n, succ m => add (mul n m) n\n\ndef pow : Nat → Nat → Nat\n  | _, zero   => succ zero\n  | n, succ m => mul (pow n m) n\n\ntheorem zero_add : ∀ m : Nat, add zero m = m\n  | zero => by rfl\n  | succ m' => sorry\n\nend Hidden\nend ex1\n\n\nsection ex2 \nnamespace Hidden2\nopen List\n\ndef reverse {α : Type} : List α → List α\n  | nil => nil\n  | x :: xs => reverse xs ++ [x]\n\n#eval reverse ([] : List Int)\n#eval reverse [1,2,3]\n\nend Hidden2\nend ex2\n\n\nsection ex5\n\n/- \nConsider following type of arithmetic expressions \n-/\n\ninductive Expr where\n  | const   : Nat → Expr\n  | var     : Nat → Expr\n  | plus    : Expr → Expr → Expr\n  | times   : Expr → Expr → Expr\n  deriving Repr \n\nopen Expr\n\ndef sampleExpr :=\n  plus (times (var 0) (const 7)) (times (const 2) (var 1))\n\n/- \nWrite a function that evaluates such an expression \n-/\n\ndef eval (v : Nat → Nat) : Expr → Nat\n  | const n     => n\n  | var n       => v n\n  | plus e₁ e₂  => eval v e₁ + eval v e₂\n  | times e₁ e₂ => eval v e₁ * eval v e₂\n\ndef sampleVal : Nat → Nat\n  | 0 => 5\n  | 1 => 6\n  | _ => 0\n\n#eval eval sampleVal sampleExpr\n\n\n/- \nImplement \"constant fustion\", fuse, a procedure that simplifies subterms like 5 + 7 to 12\n-/\n\ndef simpConst : Expr → Expr\n  | plus (const n₁) (const n₂)    => const $ n₁ + n₂\n  | times (const n₁) (const n₂)   => const $ n₁ * n₂\n  | e                             => e\n\ndef fuse : Expr → Expr\n  | plus e₁ e₂  => simpConst $ plus (fuse e₁) (fuse e₂)\n  | times e₁ e₂ => simpConst $ times (fuse e₁) (fuse e₂)\n  | e           => simpConst e\n\n#eval fuse $ const 2\n#eval fuse $ plus (const 2) (const 3)\n#eval fuse $ plus (var 1) (const 2)\n#eval fuse $ plus (times (const 2) (const 3)) (var 0)\n\n\ntheorem simpConst_eq (v : Nat → Nat)\n        : ∀ e : Expr, eval v (simpConst e) = eval v e := by\n  intro e\n  cases e with \n  | plus e₁ e₂  => \n    cases e₁ with\n    | const n =>\n      cases e₂ <;> rfl\n    | _       => rfl\n  | times e₁ e₂ => \n    cases e₁ with\n    | const n => \n      cases e₂ <;> rfl\n    | _       => rfl\n  | _     => rfl\n\ntheorem fuse_eq (v : Nat → Nat)\n  : ∀ e : Expr, eval v (fuse e) = eval v e := by \n  intro e\n  induction e with\n  | const n => rfl\n  | var n => rfl\n  | plus e₁ e₂ ih₁ ih₂ => \n    -- show eval v (fuse (plus e1 e2)) = eval v (plus e₁ e₂) from\n    calc\n      eval v (fuse (plus e₁ e₂)) \n        = eval v (simpConst $ plus (fuse e₁) (fuse e₂)) := by rfl\n      _ = eval v (plus (fuse e₁) (fuse e₂)) := by rw [simpConst_eq]\n      _ = eval v (fuse e₁) + eval v (fuse e₂) := by rfl \n      _ = eval v e₁ + eval v e₂ := by rw [ih₁, ih₂]\n  | times e₁ e₂ ih₁ ih₂ =>\n    -- show eval v (fuse (times e₁ e₂)) = eval v (times e₁ e₂) from\n    calc \n      eval v (fuse (times e₁ e₂)) \n        = eval v (simpConst $ times (fuse e₁) (fuse e₂)) := by rfl\n      _ = eval v (times (fuse e₁) (fuse e₂)) := by rw [simpConst_eq]\n      _ = eval v (fuse e₁) * eval v (fuse e₂) := by rfl\n      _ = eval v e₁ * eval v e₂ := by rw [ih₁, ih₂]\n\n/-\nThe lase two theorems show that the definitions preserve the value.\n-/\nend ex5", "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/sec08_ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.7864397757892092}}
{"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 α` 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 `α`, it requires `α` to belong\nto the `decidable_eq` type class. For this reason, the definitions and lemmas\nbelow all take `[decidable_eq α]` as type class argument.\n\n1.1 (1 point). Provide the missing proof below. -/\n\n@[instance] def multiset.rel (α : Type) [decidable_eq α] : setoid (list α) :=\n{ r     := λas bs, ∀x, list.count x as = list.count x bs,\n  iseqv :=\n    begin\n      repeat { apply and.intro },\n      { intros as x,\n        refl },\n      { intros as bs h x,\n        simp * },\n      { intros as bs cs hab hbc x,\n        simp * }\n    end }\n\n/-! 1.2 (1 point). Define the type of multisets as the quotient over the\nrelation `multiset.rel`. -/\n\ndef multiset (α : Type) [decidable_eq α] : Type :=\nquotient (multiset.rel α)\n\n/-! 1.3 (3 points). Now we have a type `multiset α` but no operations on it.\nBasic operations on multisets include the empty multiset (`∅`), the singleton\nmultiset (`{x} `for any element `x`), and the sum of two multisets (`A ⊎ B` for\nany multisets `A` and `B`). The sum should be defined so that the multiplicities\nof elements are added; thus, `{2} ⊎ {2, 2} = {2, 2, 2}`.\n\nFill in the `sorry` placeholders below to implement the basic multiset\noperations. -/\n\ndef multiset.empty {α : Type} [decidable_eq α] : multiset α :=\n⟦[]⟧\n\ndef multiset.singleton {α : Type} [decidable_eq α] (a : α) : multiset α :=\n⟦[a]⟧\n\ndef multiset.union {α : Type} [decidable_eq α] :\n  multiset α → multiset α → multiset α :=\nquotient.lift₂\n  (λas bs, ⟦as ++ bs⟧)\n  begin\n    intros as bs as' bs' ha hb,\n    apply quotient.sound,\n    intro x,\n    simp [ha x, hb x]\n  end\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 {α : Type} [decidable_eq α] (A B : multiset α) :\n  multiset.union A B = multiset.union B A :=\nbegin\n  apply quotient.induction_on A,\n  apply quotient.induction_on B,\n  intros bs as,\n  apply quotient.sound,\n  intro x,\n  simp [add_comm]\nend\n\nlemma multiset.union_assoc {α : Type} [decidable_eq α] (A B C : multiset α) :\n  multiset.union (multiset.union A B) C =\n  multiset.union A (multiset.union B C) :=\nbegin\n  apply quotient.induction_on A,\n  apply quotient.induction_on B,\n  apply quotient.induction_on C,\n  intros cs bs as,\n  apply quotient.sound,\n  intro x,\n  simp\nend\n\nlemma multiset.union_iden_left {α : Type} [decidable_eq α] (A : multiset α) :\n  multiset.union multiset.empty A = A :=\nbegin\n  apply quotient.induction_on A,\n  intro as,\n  apply quotient.sound,\n  intro x,\n  simp\nend\n\nlemma multiset.union_iden_right {α : Type} [decidable_eq α] (A : multiset α) :\n  multiset.union A multiset.empty = A :=\nbegin\n  rw multiset.union_comm,\n  rw multiset.union_iden_left\nend\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 (α : Sort _) :\n  nonempty α\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 :=\nclassical.choice (Sort_nonempty false)\n\n-- Alternative proof:\nlemma proof_of_false' :\n  false :=\nbegin\n  cases' Sort_nonempty false with h,\n  exact h\nend\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 (α : Type _) :\n  nonempty α\n\nlemma proof_of_false₂ :\n  false :=\nbegin\n  let t : Type := {a : ℕ // false},\n  have h : nonempty t :=\n    Type_nonempty t,\n  let x : t := classical.choice h,\n  exact subtype.property x\nend\n\n-- Alternative proof:\nlemma proof_of_false₂' :\n  false :=\nbegin\n  let t : Type := {a : ℕ // false},\n  cases' Type_nonempty t with x,\n  exact subtype.property x\nend\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_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.896251371055247, "lm_q1q2_score": 0.7864397738497535}}
{"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.group_power.lemmas\n\n/-!  # Squares, even and odd elements\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves some general facts about squares, even and odd elements of semirings.\n\nIn the implementation, we define `is_square` and we let `even` be the notion transported by\n`to_additive`.  The definition are therefore as follows:\n```lean\nis_square a ↔ ∃ r, a = r * r\neven a ↔ ∃ r, a = r + r\n```\n\nOdd elements are not unified with a multiplicative notion.\n\n## Future work\n\n* TODO: Try to generalize further the typeclass assumptions on `is_square/even`.\n  For instance, in some cases, there are `semiring` assumptions that I (DT) am not convinced are\n  necessary.\n* TODO: Consider moving the definition and lemmas about `odd` to a separate file.\n* TODO: The \"old\" definition of `even a` asked for the existence of an element `c` such that\n  `a = 2 * c`.  For this reason, several fixes introduce an extra `two_mul` or `← two_mul`.\n  It might be the case that by making a careful choice of `simp` lemma, this can be avoided.\n -/\n\nopen mul_opposite\nvariables {F α β R : Type*}\n\nsection has_mul\nvariables [has_mul α]\n\n/--  An element `a` of a type `α` with multiplication satisfies `is_square a` if `a = r * r`,\nfor some `r : α`. -/\n@[to_additive\n\"An element `a` of a type `α` with addition satisfies `even a` if `a = r + r`,\nfor some `r : α`.\"]\ndef is_square (a : α) : Prop := ∃ r, a = r * r\n\n@[simp, to_additive] lemma is_square_mul_self (m : α) : is_square (m * m) := ⟨m, rfl⟩\n\n@[to_additive] lemma is_square_op_iff (a : α) : is_square (op a) ↔ is_square a :=\n⟨λ ⟨c, hc⟩, ⟨unop c, by rw [← unop_mul, ← hc, unop_op]⟩, λ ⟨c, hc⟩, by simp [hc]⟩\n\nend has_mul\n\n@[simp, to_additive]\nlemma is_square_one [mul_one_class α] : is_square (1 : α) := ⟨1, (mul_one _).symm⟩\n\n@[to_additive]\nlemma is_square.map [mul_one_class α] [mul_one_class β] [monoid_hom_class F α β] {m : α} (f : F) :\n  is_square m → is_square (f m) :=\nby { rintro ⟨m, rfl⟩, exact ⟨f m, by simp⟩ }\n\nsection monoid\nvariables [monoid α] {n : ℕ} {a : α}\n\n@[to_additive even_iff_exists_two_nsmul]\nlemma is_square_iff_exists_sq (m : α) : is_square m ↔ ∃ c, m = c ^ 2 :=\nby simp [is_square, pow_two]\n\nalias is_square_iff_exists_sq ↔ is_square.exists_sq is_square_of_exists_sq\n\nattribute [to_additive even.exists_two_nsmul \"Alias of the forwards direction of\n`even_iff_exists_two_nsmul`.\"] is_square.exists_sq\n\nattribute [to_additive even_of_exists_two_nsmul \"Alias of the backwards direction of\n`even_iff_exists_two_nsmul`.\"] is_square_of_exists_sq\n\n@[to_additive even.nsmul] lemma is_square.pow (n : ℕ) : is_square a → is_square (a ^ n) :=\nby { rintro ⟨a, rfl⟩, exact ⟨a ^ n, (commute.refl _).mul_pow _⟩ }\n\n@[simp, to_additive even.nsmul']\nlemma even.is_square_pow : even n → ∀ a : α, is_square (a ^ n) :=\nby { rintro ⟨n, rfl⟩ a, exact ⟨a ^ n, pow_add _ _ _⟩ }\n\n@[simp, to_additive even_two_nsmul]\nlemma is_square_sq (a : α) : is_square (a ^ 2) := ⟨a, pow_two _⟩\n\nvariables [has_distrib_neg α]\n\nlemma even.neg_pow : even n → ∀ a : α, (-a) ^ n = a ^ n :=\nby { rintro ⟨c, rfl⟩ a, simp_rw [←two_mul, pow_mul, neg_sq] }\n\nlemma even.neg_one_pow (h : even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow]\n\nend monoid\n\n@[to_additive] lemma is_square.mul [comm_semigroup α] {a b : α} :\n  is_square a → is_square b → is_square (a * b) :=\nby { rintro ⟨a, rfl⟩ ⟨b, rfl⟩, exact ⟨a * b, mul_mul_mul_comm _ _ _ _⟩ }\n\nvariables (α)\n\n@[simp] lemma is_square_zero [mul_zero_class α] : is_square (0 : α) := ⟨0, (mul_zero _).symm⟩\n\nvariables {α}\n\nsection division_monoid\nvariables [division_monoid α] {a : α}\n\n@[simp, to_additive] lemma is_square_inv : is_square a⁻¹ ↔ is_square a :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { rw [← is_square_op_iff, ← inv_inv a],\n    exact h.map (mul_equiv.inv' α) },\n  { exact ((is_square_op_iff a).mpr h).map (mul_equiv.inv' α).symm }\nend\n\nalias is_square_inv ↔ _ is_square.inv\n\nattribute [to_additive] is_square.inv\n\n@[to_additive even.zsmul] lemma is_square.zpow (n : ℤ) : is_square a → is_square (a ^ n) :=\nby { rintro ⟨a, rfl⟩, exact ⟨a ^ n, (commute.refl _).mul_zpow _⟩ }\n\nvariables [has_distrib_neg α] {n : ℤ}\n\nlemma even.neg_zpow : even n → ∀ a : α, (-a) ^ n = a ^ n :=\nby { rintro ⟨c, rfl⟩ a, exact zpow_bit0_neg _ _ }\n\nlemma even.neg_one_zpow (h : even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow]\n\nend division_monoid\n\nlemma even_abs [subtraction_monoid α] [linear_order α] {a : α} : even (|a|) ↔ even a :=\nby cases abs_choice a; simp only [h, even_neg]\n\n@[to_additive]\nlemma is_square.div [division_comm_monoid α] {a b : α} (ha : is_square a) (hb : is_square b) :\n  is_square (a / b) :=\nby { rw div_eq_mul_inv, exact ha.mul hb.inv }\n\n@[simp, to_additive even.zsmul']\nlemma even.is_square_zpow [group α] {n : ℤ} : even n → ∀ a : α, is_square (a ^ n) :=\nby { rintro ⟨n, rfl⟩ a, exact ⟨a ^ n, zpow_add _ _ _⟩ }\n\n-- `odd.tsub` requires `canonically_linear_ordered_semiring`, which we don't have\nlemma even.tsub [canonically_linear_ordered_add_monoid α] [has_sub α] [has_ordered_sub α]\n  [contravariant_class α α (+) (≤)] {m n : α} (hm : even m) (hn : even n) : even (m - n) :=\nbegin\n  obtain ⟨a, rfl⟩ := hm,\n  obtain ⟨b, rfl⟩ := hn,\n  refine ⟨a - b, _⟩,\n  obtain h | h := le_total a b,\n  { rw [tsub_eq_zero_of_le h, tsub_eq_zero_of_le (add_le_add h h), add_zero] },\n  { exact (tsub_add_tsub_comm h h).symm }\nend\n\nlemma even_iff_exists_bit0 [has_add α] {a : α} : even a ↔ ∃ b, a = bit0 b := iff.rfl\n\nalias even_iff_exists_bit0 ↔ even.exists_bit0 _\n\nsection semiring\nvariables [semiring α] [semiring β] {m n : α}\n\nlemma even_iff_exists_two_mul (m : α) : even m ↔ ∃ c, m = 2 * c :=\nby simp [even_iff_exists_two_nsmul]\n\nlemma even_iff_two_dvd {a : α} : even a ↔ 2 ∣ a := by simp [even, has_dvd.dvd, two_mul]\n\nalias even_iff_two_dvd ↔ even.two_dvd _\n\ntheorem even.trans_dvd (hm : even m) (hn : m ∣ n) : even n :=\neven_iff_two_dvd.2 $ hm.two_dvd.trans hn\n\ntheorem has_dvd.dvd.even (hn : m ∣ n) (hm : even m) : even n :=\nhm.trans_dvd hn\n\n@[simp] lemma range_two_mul (α : Type*) [semiring α] :\n  set.range (λ x : α, 2 * x) = {a | even a} :=\nby { ext x, simp [eq_comm, two_mul, even] }\n\n@[simp] lemma even_bit0 (a : α) : even (bit0 a) :=\n⟨a, rfl⟩\n\n@[simp] lemma even_two : even (2 : α) := ⟨1, rfl⟩\n\n@[simp] lemma even.mul_left (hm : even m) (n) : even (n * m) :=\nhm.map (add_monoid_hom.mul_left n)\n\n@[simp] lemma even.mul_right (hm : even m) (n) : even (m * n) :=\nhm.map (add_monoid_hom.mul_right n)\n\nlemma even_two_mul (m : α) : even (2 * m) := ⟨m, two_mul _⟩\n\nlemma even.pow_of_ne_zero (hm : even m) : ∀ {a : ℕ}, a ≠ 0 → even (m ^ a)\n| 0       a0 := (a0 rfl).elim\n| (a + 1) _  := by { rw pow_succ, exact hm.mul_right _ }\n\nsection with_odd\n\n/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/\ndef odd (a : α) : Prop := ∃ k, a = 2*k + 1\n\nlemma odd_iff_exists_bit1 {a : α} : odd a ↔ ∃ b, a = bit1 b :=\nexists_congr $ λ b, by { rw two_mul, refl }\n\nalias odd_iff_exists_bit1 ↔ odd.exists_bit1 _\n\n@[simp] lemma odd_bit1 (a : α) : odd (bit1 a) := odd_iff_exists_bit1.2 ⟨a, rfl⟩\n\n@[simp] lemma range_two_mul_add_one (α : Type*) [semiring α] :\n  set.range (λ x : α, 2 * x + 1) = {a | odd a} :=\nby { ext x, simp [odd, eq_comm] }\n\nlemma even.add_odd : even m → odd n → odd (m + n) :=\nby { rintro ⟨m, rfl⟩ ⟨n, rfl⟩, exact ⟨m + n, by rw [mul_add, ← two_mul, add_assoc]⟩ }\n\nlemma odd.add_even (hm : odd m) (hn : even n) : odd (m + n) :=\nby { rw add_comm, exact hn.add_odd hm }\n\nlemma odd.add_odd : odd m → odd n → even (m + n) :=\nbegin\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩,\n  refine ⟨n + m + 1, _⟩,\n  rw [two_mul, two_mul],\n  ac_refl\nend\n\n@[simp] lemma odd_one : odd (1 : α) :=\n⟨0, (zero_add _).symm.trans (congr_arg (+ (1 : α)) (mul_zero _).symm)⟩\n\n@[simp] lemma odd_two_mul_add_one (m : α) : odd (2 * m + 1) := ⟨m, rfl⟩\n\nlemma odd.map [ring_hom_class F α β] (f : F) : odd m → odd (f m) :=\nby { rintro ⟨m, rfl⟩, exact ⟨f m, by simp [two_mul]⟩ }\n\n@[simp] lemma odd.mul : odd m → odd n → odd (m * n) :=\nbegin\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩,\n  refine ⟨2 * m * n + n + m, _⟩,\n  rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc,\n    ← nat.cast_two, ← nat.cast_comm],\nend\n\nlemma odd.pow (hm : odd m) : ∀ {a : ℕ}, odd (m ^ a)\n| 0       := by { rw pow_zero, exact odd_one }\n| (a + 1) := by { rw pow_succ, exact hm.mul odd.pow }\n\nend with_odd\nend semiring\n\nsection monoid\nvariables [monoid α] [has_distrib_neg α] {a : α} {n : ℕ}\n\nlemma odd.neg_pow : odd n → ∀ a : α, (-a) ^ n = - a ^ n :=\nby { rintro ⟨c, rfl⟩ a, simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] }\nlemma odd.neg_one_pow (h : odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow]\n\nend monoid\n\nsection canonically_ordered_comm_semiring\n\nvariables [canonically_ordered_comm_semiring α]\n\n-- this holds more generally in a `canonically_ordered_add_monoid` if we refactor `odd` to use\n-- either `2 • t` or `t + t` instead of `2 * t`.\nlemma odd.pos [nontrivial α] {n : α} (hn : odd n) : 0 < n :=\nbegin\n  obtain ⟨k, rfl⟩ := hn,\n  rw [pos_iff_ne_zero, ne.def, add_eq_zero_iff, not_and'],\n  exact λ h, (one_ne_zero h).elim\nend\n\nend canonically_ordered_comm_semiring\n\nsection ring\nvariables [ring α] {a b : α} {n : ℕ}\n\n@[simp] lemma even_neg_two : even (- 2 : α) := by simp only [even_neg, even_two]\n\nlemma odd.neg (hp : odd a) : odd (-a) :=\nbegin\n  obtain ⟨k, hk⟩ := hp,\n  use -(k + 1),\n  rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add,\n    neg_add_cancel_right, ←neg_add, hk],\nend\n\n@[simp] lemma odd_neg : odd (-a) ↔ odd a := ⟨λ h, neg_neg a ▸ h.neg, odd.neg⟩\n\n@[simp] lemma odd_neg_one : odd (- 1 : α) := by simp\n\nlemma odd.sub_even (ha : odd a) (hb : even b) : odd (a - b) :=\nby { rw sub_eq_add_neg, exact ha.add_even hb.neg }\n\nlemma even.sub_odd (ha : even a) (hb : odd b) : odd (a - b) :=\nby { rw sub_eq_add_neg, exact ha.add_odd hb.neg }\n\nlemma odd.sub_odd (ha : odd a) (hb : odd b) : even (a - b) :=\nby { rw sub_eq_add_neg, exact ha.add_odd hb.neg }\n\nlemma odd_abs [linear_order α] : odd (abs a) ↔ odd a :=\nby cases abs_choice a with h h; simp only [h, odd_neg]\n\nend ring\n\nsection powers\nvariables [linear_ordered_ring R] {a : R} {n : ℕ}\n\nlemma even.pow_nonneg (hn : even n) (a : R) : 0 ≤ a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_nonneg a k\n\nlemma even.pow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_pos ha k\n\nlemma odd.pow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_nonpos_iff.mpr ha\n\nlemma odd.pow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_neg_iff.mpr ha\n\nlemma odd.pow_nonneg_iff (hn : odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=\n⟨λ h, le_of_not_lt (λ ha, h.not_lt $ hn.pow_neg ha), λ ha, pow_nonneg ha n⟩\n\nlemma odd.pow_nonpos_iff (hn : odd n) : a ^ n ≤ 0 ↔ a ≤ 0 :=\n⟨λ h, le_of_not_lt (λ ha, h.not_lt $ pow_pos ha _), hn.pow_nonpos⟩\n\nlemma odd.pow_pos_iff (hn : odd n) : 0 < a ^ n ↔ 0 < a :=\n⟨λ h, lt_of_not_le (λ ha, h.not_le $ hn.pow_nonpos ha), λ ha, pow_pos ha n⟩\n\nlemma odd.pow_neg_iff (hn : odd n) : a ^ n < 0 ↔ a < 0 :=\n⟨λ h, lt_of_not_le (λ ha, h.not_le $ pow_nonneg ha _), hn.pow_neg⟩\n\nlemma even.pow_pos_iff (hn : even n) (h₀ : 0 < n) : 0 < a ^ n ↔ a ≠ 0 :=\n⟨λ h ha, by { rw [ha, zero_pow h₀] at h, exact lt_irrefl 0 h }, hn.pow_pos⟩\n\nlemma even.pow_abs {p : ℕ} (hp : even p) (a : R) : |a| ^ p = a ^ p :=\nbegin\n  rw [←abs_pow, abs_eq_self],\n  exact hp.pow_nonneg _\nend\n\n@[simp] lemma pow_bit0_abs (a : R) (p : ℕ) : |a| ^ bit0 p = a ^ bit0 p := (even_bit0 _).pow_abs _\n\nlemma odd.strict_mono_pow (hn : odd n) : strict_mono (λ a : R, a ^ n) :=\nby cases hn with k hk; simpa only [hk, two_mul] using strict_mono_pow_bit1 _\n\nend powers\n", "meta": {"author": "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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7864054780238163}}
{"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 data.zmod.coprime\n! leanprover-community/mathlib commit 4b4975cf92a1ffe2ddfeff6ff91b0c46a9162bf5\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.ZMod.Basic\nimport Mathlib.RingTheory.Int.Basic\n\n/-!\n# Coprimality and vanishing\n\nWe show that for prime `p`, the image of an integer `a` in `ZMod p` vanishes if and only if\n`a` and `p` are not coprime.\n-/\n\n\nnamespace ZMod\n\n/-- If `p` is a prime and `a` is an integer, then `a : ZMod p` is zero if and only if\n`gcd a p ≠ 1`. -/\ntheorem eq_zero_iff_gcd_ne_one {a : ℤ} {p : ℕ} [pp : Fact p.Prime] :\n    (a : ZMod p) = 0 ↔ a.gcd p ≠ 1 := by\n  rw [Ne, Int.gcd_comm, Int.gcd_eq_one_iff_coprime,\n    (Nat.prime_iff_prime_int.1 pp.1).coprime_iff_not_dvd, Classical.not_not,\n    int_cast_zmod_eq_zero_iff_dvd]\n#align zmod.eq_zero_iff_gcd_ne_one ZMod.eq_zero_iff_gcd_ne_one\n\n/-- If an integer `a` and a prime `p` satisfy `gcd a p = 1`, then `a : ZMod p` is nonzero. -/\ntheorem ne_zero_of_gcd_eq_one {a : ℤ} {p : ℕ} (pp : p.Prime) (h : a.gcd p = 1) : (a : ZMod p) ≠ 0 :=\n  mt (@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mp (Classical.not_not.mpr h)\n#align zmod.ne_zero_of_gcd_eq_one ZMod.ne_zero_of_gcd_eq_one\n\n/-- If an integer `a` and a prime `p` satisfy `gcd a p ≠ 1`, then `a : ZMod p` is zero. -/\ntheorem eq_zero_of_gcd_ne_one {a : ℤ} {p : ℕ} (pp : p.Prime) (h : a.gcd p ≠ 1) : (a : ZMod p) = 0 :=\n  (@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mpr h\n#align zmod.eq_zero_of_gcd_ne_one ZMod.eq_zero_of_gcd_ne_one\n\nend ZMod\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/ZMod/Coprime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.7864054553104699}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world2.level2 -- hide\nnamespace mynat -- hide\n\n/- \n# Addition World\n\n## Level 3: `succ_add`\n\nOh no! On the way to `add_comm`, a wild `succ_add` appears. `succ_add`\nis the proof that `succ(a) + b = succ(a + b)` for `a` and `b` in your\nnatural number type. We need to prove this now, because we will need\nto use this result in our proof that `a + b = b + a` in the next level.\n\nNB: think about why computer scientists called this result `succ_add` .\nThere is a logic to all the names.\n\nNote that if you want to be more precise about exactly where you want\nto rewrite something like `add_succ` (the proof you already have),\nyou can do things like `rw add_succ (succ a)` or\n`rw add_succ (succ a) d`, telling Lean explicitly what to use for\nthe input variables for the function `add_succ`. Indeed, `add_succ`\nis a function -- it takes as input two variables `a` and `b` and outputs a proof\nthat `a + succ(b) = succ(a + b)`. The tactic `rw add_succ` just says to Lean \"guess\nwhat the variables are\". \n-/\n\n/- Lemma\nFor all natural numbers $a, b$, we have\n$$ \\operatorname{succ}(a) + b = \\operatorname{succ}(a + b). $$\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    refl\n  }, \n  { rw add_succ,\n    rw hd,\n    rw add_succ,\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/world2/level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9591542817548989, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7864042100554268}}
{"text": "/-\nCopyright (c) 2022 Yaël Dillies, Ella Yu. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël Dillies, Ella Yu\n\n! This file was ported from Lean 3 source module combinatorics.additive.energy\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.Prod\nimport Mathlib.Data.Fintype.Prod\n\n/-!\n# Additive energy\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 ×ˢ s) ×ᶠ t ×ᶠ t).filter (λ x : (α × α) × α × α, x.1.1 * x.2.1 = x.1.2 * x.2.2)` (whose `card` is\n`multiplicativeEnergy s t`) as a standalone definition.\n-/\n\n\nsection\n\nvariable {α : Type _} [PartialOrder α] {x y : α}\n\nend\n\nvariable {α : Type _} [DecidableEq α]\n\nnamespace Finset\n\nsection Mul\n\nvariable [Mul α] {s s₁ s₂ t t₁ t₂ : Finset α}\n-- porting note: replaced `xˢ` by `xᶠ`\n/-- The multiplicative energy of two finsets `s` and `t` in a group is the number of quadruples\n`(a₁, a₂, b₁, b₂) ∈ s × s × t × t` such that `a₁ * b₁ = a₂ * b₂`. -/\n@[to_additive additiveEnergy\n      \"The additive energy of two finsets `s` and `t` in a group is the\n      number of quadruples `(a₁, a₂, b₁, b₂) ∈ s × s × t × t` such that `a₁ + b₁ = a₂ + b₂`.\"]\ndef multiplicativeEnergy (s t : Finset α) : ℕ :=\n  (((s ×ᶠ s) ×ᶠ t ×ᶠ t).filter fun x : (α × α) × α × α => 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@[to_additive additiveEnergy_mono]\ntheorem multiplicativeEnergy_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) :\n    multiplicativeEnergy s₁ t₁ ≤ multiplicativeEnergy s₂ t₂ :=\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@[to_additive additiveEnergy_mono_left]\ntheorem multiplicativeEnergy_mono_left (hs : s₁ ⊆ s₂) :\n    multiplicativeEnergy s₁ t ≤ multiplicativeEnergy s₂ 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@[to_additive additiveEnergy_mono_right]\ntheorem multiplicativeEnergy_mono_right (ht : t₁ ⊆ t₂) :\n    multiplicativeEnergy s t₁ ≤ multiplicativeEnergy s t₂ :=\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@[to_additive le_additiveEnergy]\ntheorem le_multiplicativeEnergy : s.card * t.card ≤ multiplicativeEnergy s t := by\n  rw [← card_product]\n  refine'\n    card_le_card_of_inj_on (@fun x => ((x.1, x.1), x.2, x.2)) (by\n    -- porting note: changed this from a `simp` proof without `only` because of a timeout\n      simp only [ ← and_imp, mem_product, and_imp, Prod.forall, mem_filter,\n        and_self, and_true, imp_self, implies_true]) 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@[to_additive additiveEnergy_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\nvariable (s t)\n\n@[to_additive (attr := simp) additiveEnergy_empty_left]\ntheorem multiplicativeEnergy_empty_left : multiplicativeEnergy ∅ t = 0 := by\n  simp [multiplicativeEnergy]\n#align finset.multiplicative_energy_empty_left Finset.multiplicativeEnergy_empty_left\n#align finset.additive_energy_empty_left Finset.additiveEnergy_empty_left\n\n@[to_additive (attr := simp) additiveEnergy_empty_right]\ntheorem multiplicativeEnergy_empty_right : multiplicativeEnergy s ∅ = 0 := by\n  simp [multiplicativeEnergy]\n#align finset.multiplicative_energy_empty_right Finset.multiplicativeEnergy_empty_right\n#align finset.additive_energy_empty_right Finset.additiveEnergy_empty_right\n\nvariable {s t}\n\n@[to_additive (attr := simp) additiveEnergy_pos_iff]\ntheorem multiplicativeEnergy_pos_iff : 0 < multiplicativeEnergy s t ↔ s.Nonempty ∧ t.Nonempty :=\n  ⟨fun 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 <;> simp [Nat.not_lt_zero] at h,\n    fun h => multiplicativeEnergy_pos h.1 h.2⟩\n#align finset.multiplicative_energy_pos_iff Finset.multiplicativeEnergy_pos_iff\n#align finset.additive_energy_pos_iff Finset.additiveEnergy_pos_iff\n\n@[to_additive (attr := simp) additive_energy_eq_zero_iff]\ntheorem multiplicativeEnergy_eq_zero_iff : multiplicativeEnergy s t = 0 ↔ s = ∅ ∨ t = ∅ := by\n  simp [← (Nat.zero_le _).not_gt_iff_eq, not_and_or, imp_iff_or_not, or_comm]\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\nend Mul\n\nsection CommMonoid\n\nvariable [CommMonoid α]\n\n@[to_additive additiveEnergy_comm]\ntheorem multiplicativeEnergy_comm (s t : Finset α) :\n    multiplicativeEnergy s t = multiplicativeEnergy t s := by\n  rw [multiplicativeEnergy, ← Finset.card_map (Equiv.prodComm _ _).toEmbedding, map_filter]\n  simp [-Finset.card_map, eq_comm, multiplicativeEnergy, 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 α] [Fintype α] (s t : Finset α)\n\n-- porting note: replaced `xˢ` by `xᶠ`\n@[to_additive (attr := simp) additiveEnergy_univ_left]\ntheorem multiplicativeEnergy_univ_left :\n    multiplicativeEnergy univ t = Fintype.card α * t.card ^ 2 := by\n  simp only [multiplicativeEnergy, univ_product_univ, Fintype.card, sq, ← card_product]\n  let f : α × α × α → (α × α) × α × α := fun x => ((x.1 * x.2.2, x.1 * x.2.1), x.2)\n  have : (↑((univ : Finset α) ×ᶠ t ×ᶠ t) : Set (α × α × α)).InjOn f := by\n    rintro ⟨a₁, b₁, c₁⟩ _ ⟨a₂, b₂, c₂⟩ h₂ h\n    simp_rw [Prod.ext_iff] at h\n    obtain ⟨h, rfl, rfl⟩ := h\n    rw [mul_right_cancel h.1]\n  rw [← card_image_of_injOn this]\n  congr with a\n  simp only [mem_filter, mem_product, mem_univ, true_and_iff, mem_image, exists_prop,\n    Prod.exists]\n  refine' ⟨fun h => ⟨a.1.1 * a.2.2⁻¹, _, _, h.1, by simp [mul_right_comm, h.2]⟩, _⟩\n  rintro ⟨b, c, d, hcd, rfl⟩\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@[to_additive (attr := simp) additiveEnergy_univ_right]\ntheorem multiplicativeEnergy_univ_right :\n    multiplicativeEnergy s univ = Fintype.card α * s.card ^ 2 := by\n  rw [multiplicativeEnergy_comm, multiplicativeEnergy_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", "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/Energy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7863858076285742}}
{"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 : ℕ → ℝ} {t : ℝ} (ha : tends_to a t) :\n  tends_to (λ n, - a n) (-t) :=\nbegin\n  rw tends_to_def at *,\n  have h : ∀ n, |a n - t| = | -a n - -t|,\n  { intro n,\n    rw abs_sub_comm,\n    congr' 1,\n    ring },\n  simpa [h] using ha,\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 : ℕ → ℝ} {t u : ℝ}\n  (ha : tends_to a t) (hb : tends_to b u) :\n  tends_to (λ n, a n + b n) (t + u) :=\nbegin\n  rw tends_to_def at *,\n  -- let ε > 0 be arbitrary\n  intros ε hε,\n  --  There's a bound X such that if n≥X then a(n) is within ε/2 of t\n  specialize ha (ε/2) (by linarith),\n  cases ha with X hX,\n  --  There's a bound Y such that if n≥Y then b(n) is within ε/2 of u\n  obtain ⟨Y, hY⟩ := hb (ε/2) (by linarith),\n  --  use max(X,Y),\n  use max X Y,\n  -- now say n ≥ max(X,Y)\n  intros n hn,\n  rw max_le_iff at hn,\n  specialize hX n hn.1,\n  specialize hY n hn.2,\n  --  Then easy.\n  rw abs_lt at *,\n  split; -- semicolon means \"do next tactic to all goals produced by this tactic\"\n  linarith,\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 : ℕ → ℝ} {t u : ℝ}\n  (ha : tends_to a t) (hb : tends_to b u) :\n  tends_to (λ n, a n - b n) (t - u) :=\nbegin\n  simpa [sub_eq_add_neg] using tends_to_add ha (tends_to_neg hb),\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/section02reals/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.786374178574412}}
{"text": "-- Caracterizacion_de_maximo_comun_divisor_igual_al_primer_numero.lean\n-- Caracterización de máximo común divisor igual al primer número.\n-- José A. Alonso Jiménez\n-- Sevilla, 25 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a y b son números naturales, entonces\n--    a ∣ b ↔ gcd a b = a\n-- ----------------------------------------------------------------------\n\nimport data.nat.gcd\n\nopen nat\n\nvariables (a b : ℕ)\n\n-- 1ª demostración\n-- ===============\n\nexample : a ∣ b ↔ gcd a b = a :=\nbegin\n  have h1 : gcd a b ∣ a ∧ gcd a b ∣ b,\n  { exact gcd_dvd a b, },\n  split,\n  { intro h2,\n    apply dvd_antisymm h1.left,\n    rw dvd_gcd_iff,\n    exact ⟨dvd_refl a, h2⟩, },\n  { intro h3,\n    rw ← h3,\n    exact h1.right, },\nend\n\n-- Comentarios: \n-- + La orden (open nat) abre el es espacio de nombre de los naturales. \n-- + La relación (a ∣ b) se verifica si a divide a b.\n-- + (gcd a b) es el máximo común divisor de a y b.  \n-- + Si h es la conjunción (P ∧ Q), entonces h.letf es P y h.right es\n--   Q. \n-- + Se han usado los lemas\n--   + dvd_refl : a ∣ a\n--   + dvd_antisymm : a ∣ b → b ∣ a → a = b \n--   + dvd_gcd_iff : c ∣ gcd a b ↔ c ∣ a ∧ c ∣ b\n--   + gcd_dvd : gcd a b ∣ a ∧ gcd a b ∣ b\n\n-- 2ª demostración\n-- ===============\n\nexample : a ∣ b ↔ gcd a b = a :=\ngcd_eq_left_iff_dvd\n\n-- Comentario: Se ha usado el lema\n-- + gcd_eq_left_iff_dvd : a ∣ b ↔ gcd a b = a \n\n\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/Caracterizacion_de_maximo_comun_divisor_igual_al_primer_numero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7863741714484248}}
{"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\" (`∧`)\n\nWe learn about how to manipulate `P ∧ 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 ∧ Q → P :=\nbegin\n  intro hPaQ,\n  cases hPaQ with hP hQ,\n  exact hP,\nend\n\nexample : P ∧ Q → Q :=\nbegin\n  rintro ⟨hP, hQ⟩,\n  assumption,\nend\n\nexample : (P → Q → R) → (P ∧ Q → R) :=\nbegin\n  rintro hPQR ⟨hP, hQ⟩,\n  apply hPQR;\n  assumption,\nend\n\nexample : P → Q → P ∧ Q :=\nbegin\n  intro hP,\n  intro hQ,\n  split,\n  { exact hP },\n  { exact hQ }\nend\n\n/-- `∧` is symmetric -/\nexample : P ∧ Q → Q ∧ P :=\nbegin\n  rintro ⟨hP, hQ⟩,\n  exact ⟨hQ, hP⟩,\nend\n\nexample : P → P ∧ true :=\nbegin\n  intro hP,\n  split,\n  { exact hP },\n  { triv },\nend\n\nexample : false → P ∧ false :=\nbegin\n  intro h,\n  exfalso,\n  exact h,\nend\n\n/-- `∧` is transitive -/\nexample : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  rintro ⟨hP, hQ⟩ ⟨-, hR⟩,\n  exact ⟨hP, hR⟩,\nend\n\nexample : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  intros h hP hQ,\n  apply h,\n  split; assumption,\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/solutions/section01logic/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242073, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7863741699045255}}
{"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 algebra.order.archimedean\nimport group_theory.subgroup.basic\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 (α) [ordered_add_comm_monoid α] : Prop :=`\n`(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y)`\n\nThey are placed here in a separate file (rather than incorporated as a continuation of\n`algebra.order.archimedean`) because they rely on some imports from `group_theory` -- bundled\nsubgroups in 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 `ℤ`\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 `ℝ`.\n-/\n\nvariables {G : Type*} [linear_ordered_add_comm_group G] [archimedean G]\nopen linear_ordered_add_comm_group\n\n/-- Given a subgroup `H` of a decidable linearly ordered archimedean abelian group `G`, if there\nexists a minimal element `a` of `H ∩ G_{>0}` then `H` is generated by `a`. -/\nlemma add_subgroup.cyclic_of_min {H : add_subgroup G} {a : G}\n  (ha : is_least {g : G | g ∈ H ∧ 0 < g} a) : H = add_subgroup.closure {a} :=\nbegin\n  obtain ⟨⟨a_in, a_pos⟩, a_min⟩ := ha,\n  refine le_antisymm _ (H.closure_le.mpr $ by simp [a_in]),\n  intros g g_in,\n  obtain ⟨k, ⟨nonneg, lt⟩, _⟩ : ∃! k, 0 ≤ g - k • a ∧ g - k • a < a :=\n    exists_unique_zsmul_near_of_pos' a_pos g,\n  have h_zero : g - k • a = 0,\n  { by_contra h,\n    have h : a ≤ g - k • a,\n    { refine a_min ⟨_, _⟩,\n      { exact add_subgroup.sub_mem H g_in (add_subgroup.zsmul_mem H a_in k) },\n      { exact lt_of_le_of_ne nonneg (ne.symm h) } },\n    have h' : ¬ (a ≤ g - k • a) := not_le.mpr lt,\n    contradiction },\n  simp [sub_eq_zero.mp h_zero, add_subgroup.mem_closure_singleton],\nend\n\n/-- Every subgroup of `ℤ` is cyclic. -/\nlemma int.subgroup_cyclic (H : add_subgroup ℤ) : ∃ a, H = add_subgroup.closure {a} :=\nbegin\n  cases add_subgroup.bot_or_exists_ne_zero H with h h,\n  { use 0,\n    rw h,\n    exact add_subgroup.closure_singleton_zero.symm },\n  let s := {g : ℤ | g ∈ H ∧ 0 < g},\n  have h_bdd : ∀ g ∈ s, (0 : ℤ) ≤ g := λ _ h, le_of_lt h.2,\n  obtain ⟨g₀, g₀_in, g₀_ne⟩ := h,\n  obtain ⟨g₁, g₁_in, g₁_pos⟩ : ∃ g₁ : ℤ, g₁ ∈ H ∧ 0 < g₁,\n  { cases lt_or_gt_of_ne g₀_ne with Hg₀ Hg₀,\n    { exact ⟨-g₀, H.neg_mem g₀_in, neg_pos.mpr Hg₀⟩ },\n    { exact ⟨g₀, g₀_in, Hg₀⟩ } },\n  obtain ⟨a, ha, ha'⟩ := int.exists_least_of_bdd ⟨(0 : ℤ), h_bdd⟩ ⟨g₁, g₁_in, g₁_pos⟩,\n  exact ⟨a, add_subgroup.cyclic_of_min ⟨ha, ha'⟩⟩,\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/archimedean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7862740541650408}}
{"text": "import .love12_basic_mathematical_structures_demo\n\n\n/-! # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Type Classes\n\nRecall the inductive type `btree` we introduced earlier: -/\n\n#check btree\n\n/-! The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/-! 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [btree.graft, ih_l, ih_r] }\nend\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [btree.graft, ih_l, ih_r] }\nend\n\n/-! 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\n{ add       := btree.graft,\n  add_assoc := btree.graft_assoc,\n  zero      := btree.empty,\n  add_zero  := btree.graft_empty,\n  zero_add  := by intro x; refl }\n\n/-! 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/-! No matter how we define `neg` (`-`), we will not be able to prove\n`add_left_neg`, which amounts to the following property:\n\n    `∀t, btree.graft (btree.neg t) t = btree.empty`\n\nHowever, if `t` is a nonempty tree, `btree.graft _ t` cannot possibly be equal\nto `btree.empty`, no matter what the first argument is. -/\n\n/-! 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀y : btree ℕ, btree.graft y x ≠ btree.empty :=\nbegin\n  apply exists.intro (btree.node 0 btree.empty btree.empty),\n  intros y hy,\n  cases' y,\n  { cases' hy },\n  { cases' hy }\nend\n\n\n/-! ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/-! 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    rw multiset.elems,\n    rw mirror,\n    rw ←ih_l,\n    rw ←ih_r,\n    rw multiset.elems,\n    cc }\nend\n\n/-! 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    rw finset.elems,\n    rw mirror,\n    rw ←ih_l,\n    rw ←ih_r,\n    rw finset.elems,\n    cc }\nend\n\n/-! 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nbtree.node 0 (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\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/love12_basic_mathematical_structures_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8539127585282745, "lm_q1q2_score": 0.7862740503082998}}
{"text": "import data.real.basic tactic\n\nnamespace OSN2015_P4\n\n\n\n-- We represent a function ℝ+ → ℝ+ as a function ℝ → ℝ that takes positive values at positive inputs\ndef fn_pos (f : ℝ → ℝ) := ∀ x : ℝ, 0 < x -> 0 < f x\ndef fn_eq (f g : ℝ → ℝ) (c : ℝ) (_ : 0 < c) := ∀ x y : ℝ, 0 < x → 0 < y → f(g x * y + f x) = (y + c) * f x\n\n\n\n---- Part a: We generalize, replacing 2015 by an arbitrary positive real number c\nlemma lem1_1 : ∀ (f g : ℝ → ℝ) (c : ℝ) (X : 0 < c) (_ : fn_pos f) (_ : fn_pos g),\n  fn_eq f g c X → ∀ x y : ℝ, 0 < x → f x < y → f y = f x * (g x)⁻¹ * y + (c - f x * (g x)⁻¹) * f x :=\nbegin\n  intros f g c X h h0 h1 x y h2 h3,\n  have h4 := (h0 x h2),\n  calc f y = f(g x * ((y - f x) * (g x)⁻¹) + f x) : _\n  ... = ((y - f x) * (g x)⁻¹ + c) * f x : _\n  ... = f x * (g x)⁻¹ * y + (c - f x * (g x)⁻¹) * f x : by ring,\n  { apply congr_arg,\n    rw [mul_comm, mul_assoc, (mul_comm _ (g x)), mul_inv_cancel, mul_one, sub_add_cancel],\n    apply (ne_of_gt h4), },\n  { rwa h1,\n    apply real.mul_pos,\n    { rwa sub_pos, },\n    { rwa inv_pos, }, },\nend\n\nlemma lem1_2 : ∀ a b c d : ℝ, (∃ M : ℝ, ∀ y : ℝ, M < y → a * y + b = c * y + d) → a = c ∧ b = d :=\nbegin\n  intros a b c d h,\n  cases h with M h,\n  have h1 : M < M + 1 := by norm_num,\n  have h2 : M < M + 2 := by norm_num,\n  have h3 := (h (M + 1) h1),\n  have h4 : a = c,\n  { calc a = (a * (M + 2) + b) - (a * (M + 1) + b) : by ring\n    ... = (c * (M + 2) + d) - (c * (M + 1) + d) : by rw [h3, (h (M + 2) h2)]\n    ... = c : by ring, },\n  rw [h4, add_right_inj] at h3,\n  split; assumption,\nend\n\nlemma lem1_3 : ∀ (f g : ℝ → ℝ) (c : ℝ) (X : 0 < c), fn_pos f → fn_pos g → fn_eq f g c X →\n  ∃ m1 m2 : ℝ, ∀ a : ℝ, 0 < a → f a * (g a)⁻¹ = m1 ∧ (c - m1) * f a = m2 :=\nbegin\n  intros f g c X h h0 h1,\n  suffices : (∃ m1 m2 : ℝ, ∀ a : ℝ, 0 < a → f a * (g a)⁻¹ = m1 ∧ (c - f a * (g a)⁻¹) * f a = m2),\n  { cases this with m1 this,\n    cases this with m2 this,\n    use [m1, m2],\n    intros a h2,\n    split,\n    exact and.left (this a h2),\n    rwa ← and.left (this a h2),\n    exact and.right (this a h2), },\n  use [f 1 * (g 1)⁻¹, (c - f 1 * (g 1)⁻¹) * f 1],\n  intros a h2,\n  apply lem1_2; use [max (f 1) (f a)],\n  intros y h3,\n  rw [←lem1_1 f g c X h h0 h1 1 y zero_lt_one, ←lem1_1 f g c X h h0 h1 a y h2],\n  all_goals {apply lt_of_le_of_lt _ h3},\n  exact le_max_right (f 1) (f a),\n  exact le_max_left (f 1) (f a),\nend\n\ntheorem osn2015_4a : ∀ (f g : ℝ → ℝ) (c : ℝ) (X : 0 < c), fn_pos f → fn_pos g → fn_eq f g c X →\n  ∀ x : ℝ, 0 < x → f x = c * g x :=\nbegin\n  intros f g c X h h0 h1,\n  cases (lem1_3 f g c X h h0 h1) with m1 h2; cases h2 with m2 h2,\n\n  suffices : (m1 = c),\n  { intros x h3,\n    rw [← this, ← and.left (h2 x h3), mul_assoc, inv_mul_cancel, mul_one],\n    apply ne_of_gt,\n    exact (h0 x h3), },\n\n  suffices : (∃ a b : ℝ, 0 < a ∧ 0 < b ∧ f a ≠ f b),\n  { cases this with a this; cases this with b this,\n    have h3 := and.right (h2 a (and.left this)),\n    rw [← and.right (h2 b (and.left (and.right this))), ← sub_eq_zero, ← mul_sub] at h3,\n    rw [mul_eq_zero, sub_eq_zero, sub_eq_zero] at h3,\n    cases h3,\n    { rw h3, },\n    { have h4 := and.right (and.right this),\n      contradiction, }, },\n\n  use [g 1 * 1 + f 1, g 1 * 2 + f 1],\n  repeat {split},\n  -- For the two inequalities\n  any_goals {\n    apply add_pos,\n    apply mul_pos,\n    apply h0,\n    any_goals { apply h, },\n    all_goals { norm_num, },\n  },\n\n  rw [h1, h1],\n  norm_num,\n  apply ne_of_gt,\n  apply h,\n  all_goals { norm_num, },\nend\n\n\n\n---- Part b: to implement the solution, we need to provide a proof that 0 < 2015\n---- Also note that in this solution, f and g are defined on ℝ, not just on ℝ+\nlemma zero_lt_2015 : 0 < (2015 : ℝ) :=\nbegin\n  by norm_num,\nend\n\ntheorem osn2015_4b : fn_eq (λ x, 2015 * max x 1) (λ x, max x 1) 2015 zero_lt_2015 :=\nbegin\n  intros x y h h0,\n  simp,\n  rw [mul_comm (y + 2015), mul_assoc, mul_comm 2015 (max x 1), ← mul_add],\n  apply congr_arg,\n  apply max_eq_left,\n  have h1 : 1 ≤ max x 1 * 1 := by rw mul_one; apply le_max_right,\n  apply le_trans h1,\n  rw mul_le_mul_left,\n  { apply le_of_lt,\n    apply lt_trans _ (lt_add_of_pos_left 2015 h0),\n    norm_num, },\n  { rw mul_one at h1,\n    exact lt_of_lt_of_le zero_lt_one h1, },\nend\n\n\n\nend OSN2015_P4 \n", "meta": {"author": "Faris999", "repo": "indonesian-mo-formalization", "sha": "7191b73028675adf5b1fe73151d88d0bb1967797", "save_path": "github-repos/lean/Faris999-indonesian-mo-formalization", "path": "github-repos/lean/Faris999-indonesian-mo-formalization/indonesian-mo-formalization-7191b73028675adf5b1fe73151d88d0bb1967797/src/2015/osn/4-2015-osn.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305639, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7862530943675935}}
{"text": "-- Exercise 1\n-- Define the function Do_Twice, as described in Section 2.4.\ndef double_ (a : ℕ) : ℕ := a + a\ndef double : ℕ → ℕ := λ x, x + x\ndef square : ℕ → ℕ := λ x, x * x\n\ndef times2plus1 : ℕ → ℕ := λ x, x * 2 + 1\n\ndef do_twice_ (f : ℕ → ℕ) (x : ℕ) : ℕ := f (f x)\ndef do_twice : (ℕ → ℕ) → ℕ → ℕ := λ f x, f (f x)\ndef do_three_times : (ℕ → ℕ) → ℕ → ℕ := λ f x, f (f (f x))\n\n#check do_twice\n#reduce do_three_times square 2 -- 256\n#reduce do_twice square 2 -- 16\n\ndef quadruple : ℕ → ℕ := λ x, do_twice double x\n\n#reduce quadruple 2 -- 8\n\n-- Do_Twice\n-- if (f: (ℕ → ℕ) → (ℕ → ℕ)) is a function that applies \n-- (g : ℕ → ℕ) on its argument x A times, \n-- then (Do_Twice f g) applies g on its argument A² times. \ndef Do_Twice (f : (ℕ → ℕ) → (ℕ → ℕ)) (x : ℕ → ℕ) : ℕ → ℕ := f (f x)\ndef Do_Twice_ : ((ℕ → ℕ) → (ℕ → ℕ)) → (ℕ → ℕ) → (ℕ → ℕ) := \n    λ f x, f (f x)\n\n-- Another version of Do_Twice\n-- if (f: (ℕ → ℕ) → (ℕ → ℕ))\n-- is a function that applies (g : ℕ → ℕ) on its argument A times, \n-- then (Do_Twice f g) applies g on its argument 2A times. \ndef Do_Twice' : ((ℕ → ℕ) → (ℕ → ℕ)) → (ℕ → ℕ) → (ℕ → ℕ) := \n    λ f g x, f g (f g x)\ndef Do_Twice'_ (f: (ℕ → ℕ) → (ℕ → ℕ)) (g: ℕ → ℕ) (x : ℕ) : ℕ := \n    f g (f g x)\n\n-- count the number of ℕ → ℕ being applied, you'll find that there're 3^2=9 of them.\n#reduce Do_Twice do_three_times\n\n-- count the number of ℕ → ℕ being applied, you'll find that there're 3*2=6 of them.\n#reduce Do_Twice' do_three_times\n\n\n#reduce Do_Twice do_twice double 2 -- 32\n#eval Do_Twice do_twice times2plus1 2 -- 47\n#eval Do_Twice do_three_times times2plus1 2 -- 1535\n#eval (((((((((2*2)+1)*2+1)*2+1)*2+1)*2+1)*2+1)*2+1)*2+1)*2+1 -- 1535 : (x*2+1) being applied (3^3=9) times\n#eval Do_Twice do_twice square 2 -- 65536\n\n#reduce do_three_times square 2 -- 256\n#eval Do_Twice' do_three_times square 2 -- 18446744073709551616\n#eval (((((2^2)^2)^2)^2)^2)^2 -- 18446744073709551616 \n#eval Do_Twice do_twice square 2 -- 65536\n\n-- Exercise 2\n-- Define the functions curry and uncurry, as described in Section 2.4.\ndef compose (α β γ : Type) (g : β → γ) (f : α → β) (x : α) : γ := g (f x)\n\ndef curry (α β γ : Type): (α × β → γ) → α → β → γ := λ f a b, f (a, b)\n\ndef uncurry (α β γ : Type): (α → β → γ) → α × β → γ := λ f ⟨a, b⟩, f a b\n\n\n-- Exercise 3\n-- Above, we used the example vec α n for vectors of elements \n-- of type α of length n. Declare a constant vec_add that could \n-- represent a function that adds two vectors of natural numbers \n-- of the same length, and a constant vec_reverse that can represent \n-- a function that reverses its argument. \n-- Use implicit arguments for parameters that can be inferred. \n-- Declare some variables and check some expressions involving \n-- the constants that you have declared.\n\nuniverse u\nconstant vec : Type u → ℕ → Type u\n\nnamespace vec\n    constant empty : Π α : Type u, vec α 0\n    constant cons :\n        Π {α : Type u} {n : ℕ}, α → vec α n → vec α (n + 1)\n    constant append :\n        Π (α : Type u) (n m : ℕ),  vec α m → vec α n → vec α (n + m)\nend vec\n\nconstant vec_add :\n    Π {m : ℕ},  vec ℕ m → vec ℕ m → vec ℕ m\n\nconstant vec_reverse :\n    Π {α : Type u} {m : ℕ}, vec α m → vec α m\n\nvariable vecA : vec ℕ 4\nvariable vecB : vec ℕ 4\nvariable vecC : vec ℕ 5\n#check vec_add vecA vecB\n#check vec_reverse vecA\n#check vec_add (vec.cons 1 vecA) vecC\n\n\n-- Exercise 4\n-- Similarly, declare a constant matrix so that matrix α m n could \n-- represent the type of m by n matrices. Declare some constants \n-- to represent functions on this type, such as matrix addition and \n-- multiplication, and (using vec) multiplication of a matrix by a vector. \n-- Once again, declare some variables and check some expressions involving \n-- the constants that you have declared.\n\nconstant matrix : Type u → ℕ → ℕ → Type u\n\nnamespace matrix\n    constant empty : Π α : Type u, matrix α 0 0\n    constant add : \n        Π {α : Type u} {m n : ℕ}, \n            matrix α m n → matrix α m n → matrix α m n\n    constant multiply : \n        Π {α : Type u} {m n p: ℕ}, \n            matrix α m n → matrix α n p → matrix α m p\n    constant multiply_by_vec :\n        Π {α : Type u} {m n: ℕ}, \n            matrix α m n → vec α n → vec α m\nend matrix\n\nvariable matA : matrix ℕ 5 4\nvariable matB : matrix ℕ 4 3\nvariable matC : matrix ℕ 4 3\n\n#check matrix.add matB matC\n#check matrix.multiply matA matB\n#check matrix.multiply_by_vec matA vecA\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/chap2_exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7862530736177001}}
{"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 6 : \"or\" (∨`)\n\nWe learn about how to manipulate `P ∨ 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 `⊢ P ∨ Q` then `left,` will change it to `⊢ P`\nand `right,` will change it to `⊢ Q`.\n\n### The `cases` tactic again\n\nIf we have `h : P ∨ 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 → P ∨ Q :=\nbegin\n  sorry\nend\n\nexample : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\nexample : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  sorry\nend\n\n-- symmetry of `or`\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n-- associativity of `or`\nexample : (P ∨ Q) ∨ R ↔ P ∨ (Q ∨ R) :=\nbegin\n  sorry,\nend\n\nexample : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\nexample : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\nexample : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\nend\n\n-- de Morgan's laws\nexample : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\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/logic/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7862303223641237}}
{"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.fdRep\nimport linear_algebra.trace\nimport representation_theory.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ᘁ` and `ihom V W`.\n-/\n\nnoncomputable theory\n\nuniverses u\n\nopen category_theory linear_map category_theory.monoidal_category representation finite_dimensional\nopen_locale big_operators\n\nvariables {k : Type u} [field k]\n\nnamespace fdRep\n\nsection monoid\n\nvariables {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.ρ g`.-/\ndef character (V : fdRep k G) (g : G) := linear_map.trace k V (V.ρ g)\n\nlemma char_mul_comm (V : fdRep k G) (g : G) (h : G) : V.character (h * g) = V.character (g * h) :=\nby simp only [trace_mul_comm, character, map_mul]\n\n@[simp] lemma char_one  (V : fdRep k G) : V.character 1 = finite_dimensional.finrank k V :=\nby simp only [character, map_one, trace_one]\n\n/-- The character is multiplicative under the tensor product. -/\n@[simp] lemma char_tensor (V W : fdRep k G) : (V ⊗ W).character = V.character * W.character :=\nby { ext g, convert trace_tensor_product' (V.ρ g) (W.ρ g) }\n\n/-- The character of isomorphic representations is the same. -/\nlemma char_iso  {V W : fdRep k G} (i : V ≅ W) : V.character = W.character :=\nby { ext g, simp only [character, fdRep.iso.conj_ρ i], exact (trace_conj' (V.ρ g) _).symm }\n\nend monoid\n\nsection group\n\nvariables {G : Type u} [group G]\n\n/-- The character of a representation is constant on conjugacy classes. -/\n@[simp] lemma char_conj (V : fdRep k G) (g : G) (h : G) :\n  V.character (h * g * h⁻¹) = V.character g :=\nby rw [char_mul_comm, inv_mul_cancel_left]\n\n@[simp] lemma char_dual (V : fdRep k G) (g : G) : (of (dual V.ρ)).character g = V.character g⁻¹ :=\n  trace_transpose' (V.ρ g⁻¹)\n\n@[simp] lemma char_lin_hom (V W : fdRep k G) (g : G) :\n  (of (lin_hom V.ρ W.ρ)).character g = (V.character g⁻¹) * (W.character g) :=\nby rw [←char_iso (dual_tensor_iso_lin_hom _ _), char_tensor, pi.mul_apply, char_dual]\n\nvariables [fintype G] [invertible (fintype.card G : k)]\n\ntheorem average_char_eq_finrank_invariants (V : fdRep k G) :\n  ⅟(fintype.card G : k) • ∑ g : G, V.character g = finrank k (invariants V.ρ) :=\nby { rw ←(is_proj_average_map V.ρ).trace, simp [character, group_algebra.average, _root_.map_sum], }\n\nend group\n\nsection orthogonality\n\nvariables {G : Group.{u}} [is_alg_closed k]\n\nopen_locale classical\n\nvariables [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. -/\nlemma char_orthonormal (V W : fdRep k G) [simple V] [simple W] :\n  ⅟(fintype.card G : k) • ∑ g : G, V.character g * W.character g⁻¹ =\n  if nonempty (V ≅ W) then ↑1 else ↑0 :=\nbegin\n  -- First, we can rewrite the summand `V.character g * W.character g⁻¹` as the character\n  -- of the representation `V ⊗ W* ≅ Hom(W, V)` applied to `g`.\n  conv in (V.character _ * W.character _)\n  { rw [mul_comm, ←char_dual, ←pi.mul_apply, ←char_tensor],\n    rw [char_iso (fdRep.dual_tensor_iso_lin_hom W.ρ V)], } ,\n\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.ρ V.ρ)).ρ = lin_hom W.ρ V.ρ, from fdRep.of_ρ (lin_hom W.ρ V.ρ)],\n\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\n  -- By Schur's Lemma, the dimension of `Hom_G(W, V)` is `1` is `V ≅ W` and `0` otherwise.\n  rw_mod_cast [finrank_hom_simple_simple W V, iso.nonempty_iso_symm],\nend\n\nend orthogonality\n\nend fdRep\n", "meta": {"author": "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/character.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.865224091265267, "lm_q1q2_score": 0.7861580898990204}}
{"text": "/-\n# Proposition world. \n\n## Level 5 : `P → (Q → P)`.\n\nIn this level, our goal is to construct an implication, like in level 2.\n\n```\n⊢ P → (Q → P)\n```\n\nSo $P$ and $Q$ are propositions, and our goal is to prove\nthat $P\\implies(Q\\implies P)$.\nWe don't know whether $P$, $Q$ are true or false, so initially\nthis seems like a bit of a tall order. But let's give it a go. Delete\nthe `sorry` and let's think about how to proceed.\n\nOur goal is `P → X` for some true/false statement $X$, and if our\ngoal is to construct an implication then we almost always want to use the\n`intro` tactic from level 2, Lean's version of \"assume $P$\", or more precisely\n\"assume $p$ is a proof of $P$\". So let's start with\n\n`intro p,`\n\nand we then find ourselves in this state:\n\n```\nP Q : Prop,\np : P\n⊢ Q → P\n```\n\nWe now have a proof $p$ of $P$ and we are supposed to be constructing\na proof of $Q\\implies P$. So let's assume that $Q$ is true and try\nand prove that $P$ is true. We assume $Q$ like this:\n\n`intro q,`\n\nand now we have to prove $P$, but have a proof handy:\n\n`exact p,`\n-/\n\n/- Lemma : no-side-bar\nFor any propositions $P$ and $Q$, we always have\n$P\\implies(Q\\implies P)$. \n-/\nexample (P Q : Prop) : P → (Q → P) :=\nbegin\n  intro p,\n  intro q,\n  exact p,\n\n\nend\n\n/-\nA mathematician would treat the proposition $P\\implies(Q\\implies P)$\nas the same as the proposition $P\\land Q\\implies P$,\nbecause to give a proof of either of these is just to give a method which takes\na proof of $P$ and a proof of $Q$, and returns a proof of $P$. Thinking of the\ngoal as $P\\land Q\\implies P$ we see why it is provable.\n\n## Did you notice?\n\nI wrote `P → (Q → P)` but Lean just writes `P → Q → P`. This is because\ncomputer scientists adopt the convention that `→` is *right associative*,\nwhich is a fancy way of saying \"when we write `P → Q → R`, we mean `P → (Q → R)`.\nMathematicians would never dream of writing something as ambiguous as\n$P\\implies Q\\implies R$ (they are not really interested in proving abstract\npropositions, they would rather work with concrete ones such as Fermat's Last Theorem),\nso they do not have a convention for where the brackets go. It's important to\nremember Lean's convention though, or else you will get confused. If your goal\nis `P → Q → R` then you need to know whether `intro h` will create `h : P` or `h : P → Q`. \nMake sure you understand which one. \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/level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7861580762514909}}
{"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 algebra.big_operators.intervals\nimport algebra.geom_sum\nimport data.nat.bitwise\nimport data.nat.log\nimport data.nat.parity\nimport ring_theory.int.basic\n\n/-!\n# Natural number multiplicity\n\nThis file contains lemmas about the multiplicity function (the maximum prime power dividing a\nnumber) when applied to naturals, in particular calculating it for factorials and binomial\ncoefficients.\n\n## Multiplicity calculations\n\n* `nat.multiplicity_factorial`: Legendre's Theorem. The multiplicity of `p` in `n!` is\n  `n/p + ... + n/p^b` for any `b` such that `n/p^(b + 1) = 0`.\n* `nat.multiplicity_factorial_mul`: The multiplicity of `p` in `(p * n)!` is `n` more than that of\n  `n!`.\n* `nat.multiplicity_choose`: The multiplicity of `p` in `n.choose k` is the number of carries when\n  `k` and`n - k` are added in base `p`.\n\n## Other declarations\n\n* `nat.multiplicity_eq_card_pow_dvd`: The multiplicity of `m` in `n` is the number of positive\n  natural numbers `i` such that `m ^ i` divides `n`.\n* `nat.multiplicity_two_factorial_lt`: The multiplicity of `2` in `n!` is strictly less than `n`.\n* `nat.prime.multiplicity_something`: Specialization of `multiplicity.something` to a prime in the\n  naturals. Avoids having to provide `p ≠ 1` and other trivialities, along with translating between\n  `prime` and `nat.prime`.\n\n## Tags\n\nLegendre, p-adic\n-/\n\nopen finset nat multiplicity\nopen_locale big_operators nat\n\nnamespace nat\n\n/-- The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i`\ndivides `n`. This set is expressed by filtering `Ico 1 b` where `b` is any bound greater than\n`log m n`. -/\nlemma multiplicity_eq_card_pow_dvd {m n b : ℕ} (hm : m ≠ 1) (hn : 0 < n) (hb : log m n < b):\n  multiplicity m n = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card :=\ncalc\n  multiplicity m n = ↑(Ico 1 $ ((multiplicity m n).get (finite_nat_iff.2 ⟨hm, hn⟩) + 1)).card\n    : by simp\n... = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card\n    : congr_arg coe $ congr_arg card $ finset.ext $ λ i,\n      begin\n        rw [mem_filter, mem_Ico, mem_Ico, lt_succ_iff, ←@enat.coe_le_coe i, enat.coe_get,\n          ←pow_dvd_iff_le_multiplicity, and.right_comm],\n        refine (and_iff_left_of_imp (λ h, _)).symm,\n        cases m,\n        { rw [zero_pow, zero_dvd_iff] at h,\n          exact (hn.ne' h.2).elim,\n          { exact h.1 } },\n        exact ((pow_le_iff_le_log (succ_lt_succ $ nat.pos_of_ne_zero $ succ_ne_succ.1 hm) hn).1 $\n          le_of_dvd hn h.2).trans_lt hb,\n      end\n\nnamespace prime\n\n\n\nlemma multiplicity_mul {p m n : ℕ} (hp : p.prime) :\n  multiplicity p (m * n) = multiplicity p m + multiplicity p n :=\nmultiplicity.mul $ prime_iff.mp hp\n\nlemma multiplicity_pow {p m n : ℕ} (hp : p.prime) :\n  multiplicity p (m ^ n) = n • (multiplicity p m) :=\nmultiplicity.pow $ prime_iff.mp hp\n\nlemma multiplicity_self {p : ℕ} (hp : p.prime) : multiplicity p p = 1 :=\nmultiplicity_self (prime_iff.mp hp).not_unit hp.ne_zero\n\nlemma multiplicity_pow_self {p n : ℕ} (hp : p.prime) : multiplicity p (p ^ n) = n :=\nmultiplicity_pow_self hp.ne_zero (prime_iff.mp hp).not_unit n\n\n/-- **Legendre's Theorem**\n\nThe multiplicity of a prime in `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed\nover the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/\nlemma multiplicity_factorial {p : ℕ} (hp : p.prime) :\n  ∀ {n b : ℕ}, log p n < b → multiplicity p n! = (∑ i in Ico 1 b, n / p ^ i : ℕ)\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  ... = (∑ i in Ico 1 b, n / p ^ i : ℕ) + ((finset.Ico 1 b).filter (λ i, p ^ i ∣ n+1)).card :\n    by rw [multiplicity_factorial ((log_le_log_of_le $ le_succ _).trans_lt hb),\n      ← multiplicity_eq_card_pow_dvd hp.ne_one (succ_pos _) hb]\n  ... = (∑ i in Ico 1 b, (n / p ^ i + if p^i ∣ n+1 then 1 else 0) : ℕ) :\n    by { rw [sum_add_distrib, sum_boole], simp }\n  ... = (∑ i in Ico 1 b, (n + 1) / p ^ i : ℕ) :\n    congr_arg coe $ finset.sum_congr rfl $ λ _ _, (succ_div _ _).symm\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 : ℕ} (hp : p.prime) :\n  multiplicity p (p * (n + 1))! = multiplicity p (p * n)! + multiplicity p (n + 1) + 1 :=\nbegin\n  have hp' := prime_iff.mp hp,\n  have h0 : 2 ≤ p := hp.two_le,\n  have h1 : 1 ≤ p * n + 1 := nat.le_add_left _ _,\n  have h2 : p * n + 1 ≤ p * (n + 1), linarith,\n  have h3 : p * n + 1 ≤ p * (n + 1) + 1, linarith,\n  have hm : multiplicity p (p * n)! ≠ ⊤,\n  { rw [ne.def, eq_top_iff_not_finite, not_not, finite_nat_iff],\n    exact ⟨hp.ne_one, factorial_pos _⟩ },\n  revert hm,\n  have h4 : ∀ m ∈ Ico (p * n + 1) (p * (n + 1)), multiplicity p m = 0,\n  { intros m hm, apply multiplicity_eq_zero_of_not_dvd,\n    rw [← exists_lt_and_lt_iff_not_dvd _ (pos_iff_ne_zero.mpr hp.ne_zero)], rw [mem_Ico] at hm,\n    exact ⟨n, lt_of_succ_le hm.1, hm.2⟩ },\n  simp_rw [← prod_Ico_id_eq_factorial, multiplicity.finset.prod hp', ← 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 `(p * n)!` is `n` more than that of `n!`. -/\nlemma multiplicity_factorial_mul {n p : ℕ} (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.mp hp, ih,\n      multiplicity_factorial_mul_succ, ←add_assoc, nat.cast_one, nat.cast_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 : ℕ} {n r b : ℕ} (hp : p.prime) (hbn : log p n < b) :\n   p ^ r ∣ n! ↔ r ≤ ∑ i in Ico 1 b, n / p ^ i :=\nby rw [← enat.coe_le_coe, ← hp.multiplicity_factorial hbn, ← pow_dvd_iff_le_multiplicity]\n\nlemma multiplicity_factorial_le_div_pred {p : ℕ} (hp : p.prime) (n : ℕ) :\n  multiplicity p n! ≤ (n/(p - 1) : ℕ) :=\nbegin\n  rw [hp.multiplicity_factorial (lt_succ_self _), enat.coe_le_coe],\n  exact nat.geom_sum_Ico_le hp.two_le _ _,\nend\n\nlemma multiplicity_choose_aux {p n b k : ℕ} (hp : p.prime) (hkn : k ≤ n) :\n  ∑ i in finset.Ico 1 b, n / p ^ i =\n  ∑ i in finset.Ico 1 b, k / p ^ i + ∑ i in finset.Ico 1 b, (n - k) / p ^ i +\n  ((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card :=\ncalc ∑ i in finset.Ico 1 b, n / p ^ i\n    = ∑ i in finset.Ico 1 b, (k + (n - k)) / p ^ i :\n    by simp only [add_tsub_cancel_of_le hkn]\n... = ∑ i in finset.Ico 1 b, (k / p ^ i + (n - k) / p ^ i +\n      if p ^ i ≤ 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 multiplicity 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 : ℕ} (hp : p.prime) (hkn : k ≤ n) (hnb : log p n < b) :\n  multiplicity p (choose n k) =\n  ((Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card :=\nhave h₁ : multiplicity p (choose n k) + multiplicity p (k! * (n - k)!) =\n    ((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card +\n    multiplicity p (k! * (n - k)!),\n  begin\n    rw [← hp.multiplicity_mul, ← 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 tsub_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      ⟨ne_of_gt hp.one_lt, mul_pos (factorial_pos k) (factorial_pos (n - k))⟩)).1\n  h₁\n\n/-- A lower bound on the multiplicity of `p` in `choose n k`. -/\nlemma multiplicity_le_multiplicity_choose_add {p : ℕ} (hp : p.prime) (n k : ℕ) :\n  multiplicity p n ≤ 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    ← nat.cast_add, enat.coe_le_coe],\n  calc ((Ico 1 (log p n).succ).filter (λ i, p ^ i ∣ n)).card\n      ≤ ((Ico 1 (log p n).succ).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i) ∪\n        (Ico 1 (log p n).succ).filter (λ i, p ^ i ∣ k) ).card :\n    card_le_of_subset $ λ i, begin\n      have := @le_mod_add_mod_of_dvd_add_of_not_dvd k (n - k) (p ^ i),\n      simp [add_tsub_cancel_of_le (le_of_not_gt hkn)] at * {contextual := tt},\n      tauto\n    end\n  ... ≤ ((Ico 1 (log p n).succ).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card +\n        ((Ico 1 (log p n).succ).filter (λ i, p ^ i ∣ k)).card :\n    card_union_le _ _\nend\n\nlemma multiplicity_choose_prime_pow {p n k : ℕ} (hp : p.prime)\n  (hkn : k ≤ 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 (λ i, p ^ i ≤ k % p ^ i + (p ^ n - k) % p ^ i))\n      ((Ico 1 n.succ).filter (λ i, p ^ i ∣ 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      ← nat.cast_add, enat.coe_le_coe, log_pow hp.one_lt,\n      ← card_disjoint_union hdisj, filter_union_right],\n    have filter_le_Ico := (Ico 1 n.succ).card_filter_le _,\n    rwa card_Ico 1 n.succ at filter_le_Ico,\n  end)\n  (by rw [← hp.multiplicity_pow_self];\n    exact multiplicity_le_multiplicity_choose_add hp _ _)\n\nend prime\n\nlemma multiplicity_two_factorial_lt : ∀ {n : ℕ} (h : n ≠ 0), multiplicity 2 n! < n :=\nbegin\n  have h2 := prime_iff.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 : ℕ),\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)! < ↑(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": "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/multiplicity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7861147313887487}}
{"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 all positive integers n we have that \n# 169 | 3^{3n+3}-26n-27\n\nThis is the fourth question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nProof: note that n=0 also works :-) In general use induction on n.\n\nBase case n=0 works fine.\n\nInductive step: we assume `169 ∣ 3^{3d+3}-26d-27`\nSo it divides 27 times this\nwhich is `3^{3(d+1)+3}-26*27*d-27*27`\nand we want it to divide `3^{3(d+1)+3}-26(d+1)-27`\n\nso we're done if it divides the difference, which is\n`-26d-26-27+26*27d+27*27`\nwhich is `26*26n+26*26 = 13*13*something`\n-/\n\n-- The statement has subtraction in, so we use integers.\nexample (n : ℕ) (hn : 0 < n) : -- remark; not going to use hn\n(169 : ℤ) ∣ 3^(3*n+3)-26*n-27 := \nbegin\n  clear hn, -- told you\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/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475683211323, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7861147247524706}}
{"text": "/-\nCopyright (c) 2023 Devon Tuma. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Devon Tuma\n-/\nimport crypto_foundations.primitives.symm_enc\nimport computational_monads.constructions.repeat\nimport computational_monads.coercions.instances\n\nimport data.vector.zip\n\n/-!\n# Symmetric-Key Encryption Schemes\n\nThis file defines the one time pad encryption scheme,\nand proves that it satisfies perfect secrecy.\n-/\n\nopen oracle_comp oracle_spec\n\ndef one_time_pad (n : ℕ) : symm_enc_alg (vector bool n) (vector bool n) (vector bool n) :=\n{ keygen := λ _, oracle_comp.repeat coin n,\n  encrypt := λ ⟨m, k⟩, vector.zip_with bxor m k,\n  decrypt := λ ⟨c, k⟩, vector.zip_with bxor c k,\n  complete := λ m k _, (vector.ext (λ i, by simp only [vector.zip_with_nth, bool.bxor_assoc,\n    bxor_self, bool.bxor_ff_right]) : vector.zip_with bxor (vector.zip_with bxor m k) k = m) }\n\nnamespace one_time_pad\n\nvariables {n : ℕ}\n\n@[simp] lemma keygen_apply (u : unit) :\n  (one_time_pad n).keygen u = oracle_comp.repeat coin n := rfl\n\n@[simp] lemma encrypt_apply (m k : vector bool n) :\n  (one_time_pad n).encrypt (m, k) = m.zip_with bxor k := rfl\n\n@[simp] lemma decrypt_apply (c k : vector bool n) :\n  (one_time_pad n).decrypt (c, k) = c.zip_with bxor k := rfl\n\ntheorem perfect_secrecy (n : ℕ) : (one_time_pad n).perfect_secrecy :=\nbegin\n  refine ((one_time_pad n).perfect_secrecy_iff_of_equal_card rfl rfl).2 ⟨λ v, _, λ m c, _⟩,\n  { calc ⁅= v | (one_time_pad n).keygen ()⁆ = (list.map ⁅coin⁆ v.to_list).prod :\n        by rw [keygen_apply, eval_dist_repeat_apply, vector.to_list_map, eval_dist_coe_sub_spec]\n      ... = 2⁻¹ ^ (list.map ⁅coin⁆ v.to_list).length :\n        list.prod_eq_pow_card _ 2⁻¹ (λ x hx, let ⟨y, hy⟩ := list.mem_map.1 hx in\n          by simp only [← hy.2, eval_dist_query, pmf.uniform_of_fintype_apply, coin_spec_range,\n            fintype.card_bool, nat.cast_bit0, algebra_map.coe_one])\n      ... = (fintype.card (vector bool n))⁻¹ : by simp_rw [card_vector, fintype.card_bool,\n        nat.cast_pow, nat.cast_two, ennreal.inv_pow, list.length_map, vector.to_list_length] },\n  { refine ⟨vector.zip_with bxor m c, ⟨_, _⟩, λ k hk, _⟩,\n    { simp only [keygen_apply, mem_support_repeat_iff_forall, support_coe_sub_spec, coin,\n        support_query, set.top_eq_univ, set.mem_univ, imp_true_iff] },\n    { exact vector.ext (λ i, by simp only [encrypt_apply, vector.zip_with_nth,\n        ← bool.bxor_assoc, bxor_self, bool.bxor_ff_left]) },\n    { exact vector.ext (λ i, by simp only [hk.2.symm, ← bool.bxor_assoc, encrypt_apply,\n        vector.zip_with_nth, bxor_self, bool.bxor_ff_left]) } }\nend\n\n\nend one_time_pad", "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/crypto_constructions/hhs_signatures/one_time_pad.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7860986187317593}}
{"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\nSubtraction on the natural numbers, as well as min, max, and distance.\n-/\nimport .order\nopen eq.ops\n\nnamespace nat\n\n/- subtraction -/\n\nprotected theorem sub_zero [simp] (n : ℕ) : n - 0 = n :=\nrfl\n\ntheorem sub_succ [simp] (n m : ℕ) : n - succ m = pred (n - m) :=\nrfl\n\nprotected theorem zero_sub [simp] (n : ℕ) : 0 - n = 0 :=\nnat.induction_on n (by simp) (by simp)\n\ntheorem succ_sub_succ [simp] (n m : ℕ) : succ n - succ m = n - m :=\nsucc_sub_succ_eq_sub n m\n\nprotected theorem sub_self [simp] (n : ℕ) : n - n = 0 :=\nnat.induction_on n (by simp) (by simp)\n\nlocal attribute nat.add_succ [simp]\n\nprotected theorem add_sub_add_right [simp] (n k m : ℕ) : (n + k) - (m + k) = n - m :=\nnat.induction_on k (by simp) (by simp)\n\nprotected theorem add_sub_add_left [simp] (k n m : ℕ) : (k + n) - (k + m) = n - m :=\nnat.induction_on k (by simp) (by simp)\n\nprotected theorem add_sub_cancel [simp] (n m : ℕ) : n + m - m = n :=\nnat.induction_on m (by simp) (by simp)\n\nprotected theorem add_sub_cancel_left [simp] (n m : ℕ) : n + m - n = m :=\nnat.induction_on n (by simp) (by simp)\n\nprotected theorem sub_sub [simp] (n m k : ℕ) : (: n - m - k :) = (: n - (m + k) :) :=\nnat.induction_on k (by simp) (by simp)\n\ntheorem succ_sub_sub_succ [simp] (n m k : ℕ) : succ n - m - succ k = n - m - k :=\nby simp\n\ntheorem sub_self_add [simp] (n m : ℕ) : n - (n + m) = 0 :=\nby inst_simp\n\nprotected theorem sub.right_comm (m n k : ℕ) : m - n - k = m - k - n :=\nby simp\n\ntheorem sub_one (n : ℕ) : n - 1 = pred n :=\nrfl\n\ntheorem succ_sub_one [simp] (n : ℕ) : succ n - 1 = n :=\nrfl\n\nlocal attribute nat.succ_mul nat.mul_succ [simp]\n\n/- interaction with multiplication -/\n\ntheorem mul_pred_left [simp] (n m : ℕ) : pred n * m = n * m - m :=\nnat.induction_on n (by simp) (by simp)\n\ntheorem mul_pred_right [simp] (n m : ℕ) : n * pred m = n * m - n :=\nby inst_simp\n\nprotected theorem mul_sub_right_distrib [simp] (n m k : ℕ) : (n - m) * k = n * k - m * k :=\nnat.induction_on m (by simp) (by simp)\n\nprotected theorem mul_sub_left_distrib [simp] (n m k : ℕ) : n * (m - k) = n * m - n * k :=\nby inst_simp\n\nprotected theorem mul_self_sub_mul_self_eq (a b : nat) : a * a - b * b = (a + b) * (a - b) :=\nby rewrite [nat.mul_sub_left_distrib, *right_distrib, mul.comm b a, add.comm (a*a) (a*b),\n            nat.add_sub_add_left]\n\nlocal attribute succ_eq_add_one right_distrib left_distrib [simp]\n\ntheorem succ_mul_succ_eq (a : nat) : succ a * succ a = a*a + a + a + 1 :=\nby simp\n\n/- interaction with inequalities -/\n\ntheorem succ_sub {m n : ℕ} : m ≥ n → succ m - n  = succ (m - n) :=\nsub_induction n m\n  (take k, assume H : 0 ≤ k, rfl)\n   (take k,\n    assume H : succ k ≤ 0,\n    absurd H !not_succ_le_zero)\n  (take k l,\n    assume IH : k ≤ l → succ l - k = succ (l - k),\n    take H : succ k ≤ succ l,\n    calc\n      succ (succ l) - succ k = succ l - k             : succ_sub_succ\n                         ... = succ (l - k)           : IH (le_of_succ_le_succ H)\n                         ... = succ (succ l - succ k) : succ_sub_succ)\n\ntheorem sub_eq_zero_of_le {n m : ℕ} (H : n ≤ m) : n - m = 0 :=\nobtain (k : ℕ) (Hk : n + k = m), from le.elim H, Hk ▸ !sub_self_add\n\ntheorem add_sub_of_le {n m : ℕ} : n ≤ m → n + (m - n) = m :=\nsub_induction n m\n  (take k,\n    assume H : 0 ≤ k,\n    calc\n      0 + (k - 0) = k - 0 : zero_add\n              ... = k     : nat.sub_zero)\n  (take k, assume H : succ k ≤ 0, absurd H !not_succ_le_zero)\n  (take k l,\n    assume IH : k ≤ l → k + (l - k) = l,\n    take H : succ k ≤ succ l,\n    calc\n      succ k + (succ l - succ k) = succ k + (l - k)   : succ_sub_succ\n                             ... = succ (k + (l - k)) : succ_add\n                             ... = succ l             : IH (le_of_succ_le_succ H))\n\ntheorem add_sub_of_ge {n m : ℕ} (H : n ≥ m) : n + (m - n) = n :=\ncalc\n  n + (m - n) = n + 0 : sub_eq_zero_of_le H\n          ... = n     : add_zero\n\nprotected theorem sub_add_cancel {n m : ℕ} : n ≥ m → n - m + m = n :=\n!add.comm ▸ !add_sub_of_le\n\ntheorem sub_add_of_le {n m : ℕ} : n ≤ m → n - m + m = m :=\n!add.comm ▸ add_sub_of_ge\n\ntheorem sub.cases {P : ℕ → Prop} {n m : ℕ} (H1 : n ≤ m → P 0) (H2 : ∀k, m + k = n -> P k)\n  : P (n - m) :=\nor.elim !le.total\n  (assume H3 : n ≤ m, (sub_eq_zero_of_le H3)⁻¹ ▸ (H1 H3))\n  (assume H3 : m ≤ n, H2 (n - m) (add_sub_of_le H3))\n\ntheorem exists_sub_eq_of_le {n m : ℕ} (H : n ≤ m) : ∃k, m - k = n :=\nobtain (k : ℕ) (Hk : n + k = m), from le.elim H,\nexists.intro k\n  (calc\n    m - k = n + k - k : by rewrite Hk\n      ... = n         : nat.add_sub_cancel)\n\nprotected theorem add_sub_assoc {m k : ℕ} (H : k ≤ m) (n : ℕ) : n + m - k = n + (m - k) :=\nhave l1 : k ≤ m → n + m - k = n + (m - k), from\n  sub_induction k m\n    (by simp)\n    (take k : ℕ, assume H : succ k ≤ 0, absurd H !not_succ_le_zero)\n    (take k m,\n      assume IH : k ≤ m → n + m - k = n + (m - k),\n      take H : succ k ≤ succ m,\n      calc\n        n + succ m - succ k = succ (n + m) - succ k : add_succ\n                        ... = n + m - k             : succ_sub_succ\n                        ... = n + (m - k)           : IH (le_of_succ_le_succ H)\n                        ... = n + (succ m - succ k) : succ_sub_succ),\nl1 H\n\ntheorem le_of_sub_eq_zero {n m : ℕ} : n - m = 0 → n ≤ m :=\nsub.cases\n  (assume H1 : n ≤ m, assume H2 : 0 = 0, H1)\n  (take k : ℕ,\n    assume H1 : m + k = n,\n    assume H2 : k = 0,\n    have H3 : n = m, from !add_zero ▸ H2 ▸ H1⁻¹,\n    H3 ▸ !le.refl)\n\ntheorem sub_sub.cases {P : ℕ → ℕ → Prop} {n m : ℕ} (H1 : ∀k, n = m + k -> P k 0)\n  (H2 : ∀k, m = n + k → P 0 k) : P (n - m) (m - n) :=\nor.elim !le.total\n  (assume H3 : n ≤ m,\n    (sub_eq_zero_of_le H3)⁻¹ ▸  (H2 (m - n) (add_sub_of_le H3)⁻¹))\n  (assume H3 : m ≤ n,\n    (sub_eq_zero_of_le H3)⁻¹ ▸ (H1 (n - m) (add_sub_of_le H3)⁻¹))\n\nprotected theorem sub_eq_of_add_eq {n m k : ℕ} (H : n + m = k) : k - n = m :=\nhave H2 : k - n + n = m + n, from\n  calc\n    k - n + n = k     : nat.sub_add_cancel (le.intro H)\n          ... = n + m : H⁻¹\n          ... = m + n : !add.comm,\nadd.right_cancel H2\n\nprotected theorem eq_sub_of_add_eq {a b c : ℕ} (H : a + c = b) : a = b - c :=\n(nat.sub_eq_of_add_eq (!add.comm ▸ H))⁻¹\n\nprotected theorem sub_eq_of_eq_add {a b c : ℕ} (H : a = c + b) : a - b = c :=\nnat.sub_eq_of_add_eq (!add.comm ▸ H⁻¹)\n\nprotected theorem sub_le_sub_right {n m : ℕ} (H : n ≤ m) (k : ℕ) : n - k ≤ m - k :=\nobtain (l : ℕ) (Hl : n + l = m), from le.elim H,\nor.elim !le.total\n  (assume H2 : n ≤ k, (sub_eq_zero_of_le H2)⁻¹ ▸ !zero_le)\n  (assume H2 : k ≤ n,\n    have H3 : n - k + l = m - k, from\n      calc\n        n - k + l = l + (n - k) : by simp\n              ... = l + n - k   : nat.add_sub_assoc H2 l\n              ... = m - k       : by simp,\n    le.intro H3)\n\nprotected theorem sub_le_sub_left {n m : ℕ} (H : n ≤ m) (k : ℕ) : k - m ≤ k - n :=\nobtain (l : ℕ) (Hl : n + l = m), from le.elim H,\nsub.cases\n  (assume H2 : k ≤ m, !zero_le)\n  (take m' : ℕ,\n    assume Hm : m + m' = k,\n    have H3 : n ≤ k, from le.trans H (le.intro Hm),\n    have H4 : m' + l + n = k - n + n, by simp,\n    le.intro (add.right_cancel H4))\n\nprotected theorem sub_pos_of_lt {m n : ℕ} (H : m < n) : n - m > 0 :=\nhave H1 : n = n - m + m, from (nat.sub_add_cancel (le_of_lt H))⁻¹,\nhave H2 : 0 + m < n - m + m, begin rewrite [zero_add, -H1], exact H end,\n!lt_of_add_lt_add_right H2\n\nprotected theorem lt_of_sub_pos {m n : ℕ} (H : n - m > 0) : m < n :=\nlt_of_not_ge\n  (take H1 : m ≥ n,\n    have H2 : n - m = 0, from sub_eq_zero_of_le H1,\n    !lt.irrefl (H2 ▸ H))\n\nprotected theorem lt_of_sub_lt_sub_right {n m k : ℕ} (H : n - k < m - k) : n < m :=\nlt_of_not_ge\n  (assume H1 : m ≤ n,\n    have H2 : m - k ≤ n - k, from nat.sub_le_sub_right H1 _,\n    not_le_of_gt H H2)\n\nprotected theorem lt_of_sub_lt_sub_left {n m k : ℕ} (H : n - m < n - k) : k < m :=\nlt_of_not_ge\n  (assume H1 : m ≤ k,\n    have H2 : n - k ≤ n - m, from nat.sub_le_sub_left H1 _,\n    not_le_of_gt H H2)\n\nprotected theorem sub_lt_sub_add_sub (n m k : ℕ) : n - k ≤ (n - m) + (m - k) :=\nsub.cases\n  (assume H : n ≤ m, (zero_add (m - k))⁻¹ ▸ nat.sub_le_sub_right H k)\n  (take mn : ℕ,\n    assume Hmn : m + mn = n,\n    sub.cases\n      (assume H : m ≤ k,\n        have   H2 : n - k ≤ n - m, from nat.sub_le_sub_left H n,\n        have H3 : n - k ≤ mn, from nat.sub_eq_of_add_eq Hmn ▸ H2,\n        show   n - k ≤ mn + 0,  begin rewrite add_zero, assumption end)\n      (take km : ℕ,\n        assume Hkm : k + km = m,\n        have H : k + (mn + km) = n, from\n          calc\n            k + (mn + km) = k + km + mn  : by simp\n                      ... = m + mn       : Hkm\n                      ... = n            : Hmn,\n        have H2 : n - k = mn + km, from nat.sub_eq_of_add_eq H,\n        H2 ▸ !le.refl))\n\nprotected theorem sub_lt_self {m n : ℕ} (H1 : m > 0) (H2 : n > 0) : m - n < m :=\ncalc\n  m - n = succ (pred m) - n             : succ_pred_of_pos H1\n    ... = succ (pred m) - succ (pred n) : succ_pred_of_pos H2\n    ... = pred m - pred n               : succ_sub_succ\n    ... ≤ pred m                        : sub_le\n    ... < succ (pred m)                 : lt_succ_self\n    ... = m                             : succ_pred_of_pos H1\n\nprotected theorem le_sub_of_add_le {m n k : ℕ} (H : m + k ≤ n) : m ≤ n - k :=\ncalc\n  m = m + k - k : nat.add_sub_cancel\n    ... ≤ n - k : nat.sub_le_sub_right H k\n\nprotected theorem lt_sub_of_add_lt {m n k : ℕ} (H : m + k < n) (H2 : k ≤ n) : m < n - k :=\nlt_of_succ_le (nat.le_sub_of_add_le (calc\n    succ m + k = succ (m + k) : succ_add_eq_succ_add\n           ... ≤ n            : succ_le_of_lt H))\n\nprotected theorem sub_lt_of_lt_add {v n m : nat} (h₁ : v < n + m) (h₂ : n ≤ v) : v - n < m :=\nhave succ v ≤ n + m,   from succ_le_of_lt h₁,\nhave succ (v - n) ≤ m, from\n  calc succ (v - n) = succ v - n : succ_sub h₂\n        ...     ≤ n + m - n      : nat.sub_le_sub_right this n\n        ...     = m              : nat.add_sub_cancel_left,\nlt_of_succ_le this\n\n/- distance -/\n\ndefinition dist [reducible] (n m : ℕ) := (n - m) + (m - n)\n\ntheorem dist.comm (n m : ℕ) : dist n m = dist m n :=\nby simp\n\ntheorem dist_self (n : ℕ) : dist n n = 0 :=\nby simp\n\ntheorem eq_of_dist_eq_zero {n m : ℕ} (H : dist n m = 0) : n = m :=\nhave H2 : n - m = 0, from eq_zero_of_add_eq_zero_right H,\nhave H3 : n ≤ m, from le_of_sub_eq_zero H2,\nhave H4 : m - n = 0, from eq_zero_of_add_eq_zero_left H,\nhave H5 : m ≤ n, from le_of_sub_eq_zero H4,\nle.antisymm H3 H5\n\ntheorem dist_eq_zero {n m : ℕ} (H : n = m) : dist n m = 0 :=\nby substvars; rewrite [↑dist, *nat.sub_self, add_zero]\n\ntheorem dist_eq_sub_of_le {n m : ℕ} (H : n ≤ m) : dist n m = m - n :=\ncalc\n  dist n m = 0 + (m - n) : {sub_eq_zero_of_le H}\n       ... = m - n       : zero_add\n\ntheorem dist_eq_sub_of_lt {n m : ℕ} (H : n < m) : dist n m = m - n :=\ndist_eq_sub_of_le (le_of_lt H)\n\ntheorem dist_eq_sub_of_ge {n m : ℕ} (H : n ≥ m) : dist n m = n - m :=\n!dist.comm ▸ dist_eq_sub_of_le H\n\ntheorem dist_eq_sub_of_gt {n m : ℕ} (H : n > m) : dist n m = n - m :=\ndist_eq_sub_of_ge (le_of_lt H)\n\ntheorem dist_zero_right (n : ℕ) : dist n 0 = n :=\ndist_eq_sub_of_ge !zero_le ⬝ !nat.sub_zero\n\ntheorem dist_zero_left (n : ℕ) : dist 0 n = n :=\ndist_eq_sub_of_le !zero_le ⬝ !nat.sub_zero\n\ntheorem dist.intro {n m k : ℕ} (H : n + m = k) : dist k n = m :=\ncalc\n  dist k n = k - n : dist_eq_sub_of_ge (le.intro H)\n           ... = m : nat.sub_eq_of_add_eq H\n\ntheorem dist_add_add_right (n k m : ℕ) : 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))   : nat.add_sub_add_right\n                   ... = (n - m) + (m - n)               : nat.add_sub_add_right\n\ntheorem dist_add_add_left (k n m : ℕ) : dist (k + n) (k + m) = dist n m :=\nbegin rewrite [add.comm k n, add.comm k m]; apply dist_add_add_right end\n\ntheorem dist_add_eq_of_ge {n m : ℕ} (H : n ≥ m) : dist n m + m = n :=\ncalc\n  dist n m + m = n - m + m : {dist_eq_sub_of_ge H}\n           ... = n         : nat.sub_add_cancel H\n\ntheorem dist_eq_intro {n m k l : ℕ} (H : n + m = k + l) : dist n k = dist l m :=\ncalc\n  dist n k = dist (n + m) (k + m) : dist_add_add_right\n       ... = dist (k + l) (k + m) : H\n       ... = dist l m             : dist_add_add_left\n\ntheorem dist_sub_eq_dist_add_left {n m : ℕ} (H : n ≥ m) (k : ℕ) :\n  dist (n - m) k = dist n (k + m) :=\nhave H2 : n - m + (k + m) = k + n, from\n  calc\n    n - m + (k + m) = n - m + m + k   : by simp\n                ... = n + k           : nat.sub_add_cancel H\n                ... = k + n           : by simp,\ndist_eq_intro H2\n\ntheorem dist_sub_eq_dist_add_right {k m : ℕ} (H : k ≥ m) (n : ℕ) :\n  dist n (k - m) = dist (n + m) k :=\ndist.comm (k - m) n ▸ dist.comm k (n + m) ▸ dist_sub_eq_dist_add_left H n\n\ntheorem dist.triangle_inequality (n m k : ℕ) : dist n k ≤ dist n m + dist m k :=\nhave (n - m) + (m - k) + ((k - m) + (m - n)) = (n - m) + (m - n) + ((m - k) + (k - m)), by simp,\nthis ▸ add_le_add !nat.sub_lt_sub_add_sub !nat.sub_lt_sub_add_sub\n\ntheorem dist_add_add_le_add_dist_dist (n m k l : ℕ) : dist (n + m) (k + l) ≤ dist n k + dist m l :=\nhave H : dist (n + m) (k + m) + dist (k + m) (k + l) = dist n k + dist m l,\n  by rewrite [dist_add_add_left, dist_add_add_right],\nby rewrite -H; apply dist.triangle_inequality\n\ntheorem dist_mul_right (n k m : ℕ) : dist (n * k) (m * k) = dist n m * k :=\nhave ∀ n m, dist n m = n - m + (m - n), from take n m, rfl,\nby rewrite [this, this n m, right_distrib, *nat.mul_sub_right_distrib]\n\ntheorem dist_mul_left (k n m : ℕ) : dist (k * n) (k * m) = k * dist n m :=\nbegin rewrite [mul.comm k n, mul.comm k m, dist_mul_right, mul.comm] end\n\ntheorem dist_mul_dist (n m k l : ℕ) : dist n m * dist k l = dist (n * k + m * l) (n * l + m * k) :=\nhave aux : ∀k l, k ≥ l → dist n m * dist k l = dist (n * k + m * l) (n * l + m * k), from\n  take k l : ℕ,\n  assume H : k ≥ l,\n  have H2 : m * k ≥ m * l, from !mul_le_mul_left H,\n  have H3 : n * l + m * k ≥ m * l, from le.trans H2 !le_add_left,\n  calc\n    dist n m * dist k l = dist n m * (k - l)       : dist_eq_sub_of_ge H\n      ... = dist (n * (k - l)) (m * (k - l))       : dist_mul_right\n      ... = dist (n * k - n * l) (m * k - m * l)   : by rewrite [*nat.mul_sub_left_distrib]\n      ... = dist (n * k) (m * k - m * l + n * l)   : dist_sub_eq_dist_add_left (!mul_le_mul_left H)\n      ... = dist (n * k) (n * l + (m * k - m * l)) : add.comm\n      ... = dist (n * k) (n * l + m * k - m * l)   : nat.add_sub_assoc H2 (n * l)\n      ... = dist (n * k + m * l) (n * l + m * k)   : dist_sub_eq_dist_add_right H3 _,\nor.elim !le.total\n  (assume H : k ≤ l, !dist.comm ▸ !dist.comm ▸ aux l k H)\n  (assume H : l ≤ k, aux k l H)\n\nlemma dist_eq_max_sub_min {i j : nat} : dist i j = (max i j) - min i j :=\nor.elim (lt_or_ge i j)\n  (suppose i < j,\n    by rewrite [max_eq_right_of_lt this, min_eq_left_of_lt this, dist_eq_sub_of_lt this])\n  (suppose i ≥ j,\n    by rewrite [max_eq_left this , min_eq_right this, dist_eq_sub_of_ge this])\n\nlemma dist_succ {i j : nat} : dist (succ i) (succ j) = dist i j :=\nby rewrite [↑dist, *succ_sub_succ]\n\nlemma dist_le_max {i j : nat} : dist i j ≤ max i j :=\nbegin rewrite dist_eq_max_sub_min, apply sub_le end\n\nlemma dist_pos_of_ne {i j : nat} : i ≠ j → dist i j > 0 :=\nassume Pne, lt.by_cases\n  (suppose i < j, begin rewrite [dist_eq_sub_of_lt this], apply nat.sub_pos_of_lt this end)\n  (suppose i = j, by contradiction)\n  (suppose i > j, begin rewrite [dist_eq_sub_of_gt this], apply nat.sub_pos_of_lt this end)\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/sub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.786098614628944}}
{"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 ℕ × ℕ as finsets\n\nThis file defines the antidiagonals of ℕ × ℕ 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 : ℕ) : finset (ℕ × ℕ) :=\n⟨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] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :\n  x ∈ antidiagonal n ↔ 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 : ℕ) : (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 : ℕ} :\n  antidiagonal (n + 1) = insert (0, n + 1) ((antidiagonal n).map\n  (function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ (function.embedding.refl _))) :=\nbegin\n  apply eq_of_veq,\n  rw [insert_val_of_not_mem, map_val],\n  { apply multiset.nat.antidiagonal_succ },\n  { intro con, rcases mem_map.1 con with ⟨⟨a,b⟩, ⟨h1, h2⟩⟩,\n    simp only [prod.mk.inj_iff, function.embedding.coe_prod_map, prod.map_mk] at h2,\n    apply nat.succ_ne_zero a h2.1, }\nend\n\nlemma antidiagonal_succ' {n : ℕ} :\n  antidiagonal (n + 1) = insert (n + 1, 0) ((antidiagonal n).map\n  (function.embedding.prod_map (function.embedding.refl _) ⟨nat.succ, nat.succ_injective⟩)) :=\nbegin\n  apply eq_of_veq,\n  rw [insert_val_of_not_mem, map_val],\n  { apply multiset.nat.antidiagonal_succ' },\n  { simp },\nend\n\nlemma antidiagonal_succ_succ' {n : ℕ} :\n  antidiagonal (n + 2) = insert (0, n + 2) (insert (n + 2, 0) ((antidiagonal n).map\n  (function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ ⟨nat.succ, nat.succ_injective⟩))) :=\nby { rw [antidiagonal_succ, antidiagonal_succ', map_insert, map_map], refl }\n\nlemma map_swap_antidiagonal {n : ℕ} :\n  (antidiagonal n).map ⟨prod.swap, prod.swap_right_inverse.injective⟩ = 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 : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)\n  (hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=\nbegin\n  refine ⟨congr_arg prod.fst, (λ h, prod.ext h ((add_right_inj q.fst).mp _))⟩,\n  rw mem_antidiagonal at hp hq,\n  rw [hq, ← h, hp],\nend\n\nlemma antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.1 ≤ 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 : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.2 ≤ 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 : ℕ) :\n  filter (λ x : ℕ × ℕ, x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ :=\nbegin\n  ext ⟨x, y⟩,\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 λ 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 : ℕ) :\n  filter (λ x : ℕ × ℕ, x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ :=\nbegin\n  have : (λ (x : ℕ × ℕ), x.snd = m) ∘ prod.swap = (λ (x : ℕ × ℕ), x.fst = m),\n  { ext, simp },\n  rw ←map_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 `Σ (n : ℕ), antidiagonal n` is equivalent to the product\n    `ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps] def sigma_antidiagonal_equiv_prod : (Σ (n : ℕ), antidiagonal n) ≃ ℕ × ℕ :=\n{ to_fun := λ x, x.2,\n  inv_fun := λ x, ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩,\n  left_inv :=\n    begin\n      rintros ⟨n, ⟨k, l⟩, h⟩,\n      rw mem_antidiagonal at h,\n      exact sigma.subtype_ext h rfl,\n    end,\n  right_inv := λ x, rfl }\n\nend equiv_prod\n\nend nat\n\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/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7860986138660256}}
{"text": "-- Estructuras algebraicas\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Importar las librerías\n-- + data.rat.basic (que contiene los números racionales) y\n-- + tactic (que contiene las tácticas)\n-- ----------------------------------------------------------------------\n\nimport data.rat.basic\nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Iniciar el espacio de nombres lftcm (para evitar\n-- conflictos de nombres) de forma que cuando se defina `group` su\n-- nombre será `lftcm.group`.\n-- ----------------------------------------------------------------------\n\nnamespace lftcm\n\n-- Comentario sobre notación de clases de tipos:\n-- + Para definir un término de tipo `has_mul G` hay que definir una\n--   función `has_mul.mul : G → G → G`.\n-- + La notación `g * h` representa `has_mul.mul g h`.\n-- + `has_mul` es una clase.\n-- + Al escribir `[has_mul G]` se dispone de una multiplicación llamada\n--   `*` que verifica los axiomas de grupo.\n-- + Al escribir `[has_one G]` se dispone de un elemento neutro\n--   `has_one.one : G` que se representa por `1`.\n-- + Al escribir `[has_inv G]` se dispone de una operación\n--   `has_inv.inv : G → G` de forma que `inv g` es el inverso de `g` y\n--    se representa por `g⁻¹`\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los grupos\n-- ----------------------------------------------------------------------\n\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))\n(one_mul : ∀ (a : G), 1 * a = a)\n(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Iniciar el espacio de nombres group.\n-- ----------------------------------------------------------------------\n\nnamespace group\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar G como una variable sobre grupos\n-- ----------------------------------------------------------------------\n\nvariables {G : Type} [group G]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar a, b y c elementos de G.\n-- ----------------------------------------------------------------------\n\nvariables  (a b c : G)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    a * b = a * c\n-- entonces\n--    b = c\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nlemma mul_left_cancel\n  (Habac : a * b = a * c)\n  : b = c :=\n calc b = 1 * b         : by rw one_mul\n    ... = (a⁻¹ * a) * b : by rw mul_left_inv\n    ... = a⁻¹ * (a * b) : by rw mul_assoc\n    ... = a⁻¹ * (a * c) : by rw Habac\n    ... = (a⁻¹ * a) * c : by rw mul_assoc\n    ... = 1 * c         : by rw mul_left_inv\n    ... = c             : by rw one_mul\n\n-- 2ª demostración\n-- ===============\n\nlemma mul_left_cancel2\n  (Habac : a * b = a * c)\n  : b = c :=\nbegin\n  rw ←one_mul b,\n  rw ←mul_left_inv a,\n  rw mul_assoc,\n  rw Habac,\n  rw ←mul_assoc,\n  rw mul_left_inv,\n  rw one_mul,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Type,\n_inst_1 : group G,\na b c : G,\nHabac : a * b = a * c\n⊢ b = c\n  >> rw ←one_mul b,\n⊢ 1 * b = c\n  >> rw ←mul_left_inv a,\n⊢ (a⁻¹ * a) * b = c\n  >> rw mul_assoc,\n⊢ a⁻¹ * (a * b) = c\n  >> rw Habac,\n⊢ a⁻¹ * (a * c) = c\n  >> rw ←mul_assoc,\n⊢ (a⁻¹ * a) * c = c\n  >> rw mul_left_inv,\n⊢ 1 * c = c\n  >> rw one_mul,\nno goals\n-/\n\n-- 3ª demostración\n-- ===============\n\nlemma mul_left_cancel3\n  (Habac : a * b = a * c)\n  : b = c :=\nbegin\n  rw [←one_mul b, ←mul_left_inv a, mul_assoc, Habac, ←mul_assoc,\n      mul_left_inv, one_mul],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    x = a⁻¹ * y\n-- entonces\n--    a * x = y\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nlemma mul_eq_of_eq_inv_mul\n  {a x y : G}\n  (h : x = a⁻¹ * y)\n  : a * x = y :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  rw ←mul_assoc,\n  rw mul_left_inv,\n  rw one_mul,\n  exact h,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Type,\n_inst_1 : group G,\na x y : G,\nh : x = a⁻¹ * y\n⊢ a * x = y\n  >> apply mul_left_cancel a⁻¹,\n⊢ a⁻¹ * (a * x) = a⁻¹ * y\n  >> rw ←mul_assoc,\n⊢ (a⁻¹ * a) * x = a⁻¹ * y\n  >> rw mul_left_inv,\n⊢ 1 * x = a⁻¹ * y\n  >> rw one_mul,\n⊢ x = a⁻¹ * y\n  >> exact h,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nlemma mul_eq_of_eq_inv_mul2\n  {a x y : G}\n  (h : x = a⁻¹ * y)\n  : a * x = y :=\nmul_left_cancel a⁻¹ _ _ $ by rwa [←mul_assoc, mul_left_inv, one_mul]\n\n-- Comentario: La táctica `rwa hs` rescribe la conclusión con las reglas\n-- de hs y al final aplica assumption.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar los axiomas y one_mul mul_left_inv como reglas de\n-- simplificación.\n-- ----------------------------------------------------------------------\n\nattribute [simp] one_mul mul_left_inv\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar, y declarar como regla de simplificación, que el\n-- 1 es elemento neutro por la derecha.\n-- ----------------------------------------------------------------------\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (a : G)\n  : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  apply eq.symm,\n  exact mul_left_inv a,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Type,\n_inst_1 : group G,\na : G\n⊢ a * 1 = a\n  >> apply mul_eq_of_eq_inv_mul,\n⊢ 1 = a⁻¹ * a\n  >> apply eq.symm,\n⊢ a⁻¹ * a = 1\n  >> exact mul_left_inv a,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (a : G)\n  : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  simp,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Type,\n_inst_1 : group G,\na : G\n⊢ a * 1 = a\n  >> apply mul_eq_of_eq_inv_mul\n⊢ 1 = a⁻¹ * a\n  >> simp,\nno goals\n-/\n\n-- Comentario: El simplificador demuestra que `1 = a⁻¹ * a` porque se ha\n-- declarado mul_left_inv como regla de simplificación\n\n-- 3ª demostración\n-- ===============\n\n@[simp]\ntheorem mul_one\n  (a : G)\n  : a * 1 = a :=\nmul_eq_of_eq_inv_mul $ by simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar, y declarar como regla de simplificación, que\n--    a * a⁻¹ = 1\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (a : G)\n  : a * a⁻¹ = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Type,\n_inst_1 : group G,\na : G\n⊢ a * a⁻¹ = 1\n  >> apply mul_eq_of_eq_inv_mul,\n⊢ a⁻¹ = a⁻¹ * 1\n  >> rw mul_one,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\n@[simp]\ntheorem mul_right_inv\n  (a : G)\n  : a * a⁻¹ = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  simp\nend\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (a : G)\n  : a * a⁻¹ = 1 :=\nmul_eq_of_eq_inv_mul $ by simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el inverso de 1 es 1.\n-- ----------------------------------------------------------------------\n\n@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=\nbegin\n  apply mul_left_cancel (1 : G),\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a⁻¹⁻¹ = a\n-- ----------------------------------------------------------------------\n\n@[simp] lemma inv_inv (a : G) : a⁻¹⁻¹ = a :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar la propiedad asociativa como regla de\n-- simplificación.\n-- ----------------------------------------------------------------------\n\nattribute [simp] mul_assoc\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a⁻¹ * (a * b) = b\n-- ----------------------------------------------------------------------\n\n@[simp] lemma inv_mul_cancel_left\n  (a b : G)\n  : a⁻¹ * (a * b) = b :=\nbegin\n  rw ←mul_assoc,\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a * (a⁻¹ * b) = b\n-- ----------------------------------------------------------------------\n\n@[simp] lemma mul_inv_cancel_left (a b : G) : a * (a⁻¹ * b) = b :=\nbegin\n  rw ←mul_assoc,\n  simp,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (a * b)⁻¹ = b⁻¹ * a⁻¹\n-- ----------------------------------------------------------------------\n\n@[simp] lemma mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv,\n  simp,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Type,\n_inst_1 : group G,\na b : G\n⊢ (a * b)⁻¹ = b⁻¹ * a⁻¹\n  apply mul_left_cancel (a * b),\n⊢ (a * b) * (a * b)⁻¹ = (a * b) * (b⁻¹ * a⁻¹)\n  rw mul_right_inv,\n⊢ 1 = a * b * (b⁻¹ * a⁻¹)\n  simp,\nno goals\n-/\n\n-- Comentario: Con las reglas de simplificación de grupo que se han\n-- añadido se tiene un sistema de reescritura normalizador confluente;\n-- es decir, el simplificador transforma cualquier expresión de grupo en\n-- su forma canónica.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    ((a * b)⁻¹ * a * 1⁻¹⁻¹⁻¹ * b⁻¹ * b * b * 1 * 1⁻¹)⁻¹\n--    = (c⁻¹⁻¹ * d * d⁻¹ * 1⁻¹⁻¹ * c⁻¹⁻¹⁻¹)⁻¹⁻¹\n-- ----------------------------------------------------------------------\n\nexample\n  (a b c d : G)\n  : ((a * b)⁻¹ * a * 1⁻¹⁻¹⁻¹ * b⁻¹ * b * b * 1 * 1⁻¹)⁻¹\n    = (c⁻¹⁻¹ * d * d⁻¹ * 1⁻¹⁻¹ * c⁻¹⁻¹⁻¹)⁻¹⁻¹ :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el producto de dos grupos.\n-- ----------------------------------------------------------------------\n\ninstance (G : Type) [group G] (H : Type) [group H] : group (G × H) :=\n{ mul := λ k l, (k.1*l.1, k.2*l.2),\n  one := (1,1),\n  inv := λ k, (k.1⁻¹, k.2⁻¹),\n  mul_assoc :=\n  begin\n    rintros ⟨a1,a2⟩ ⟨b1,b2⟩ ⟨c1,c2⟩,\n    ext;\n    simp,\n  end,\n  one_mul :=\n  begin\n    rintros ⟨a1,a2⟩,\n    ext;\n    simp,\n  end,\n  mul_left_inv :=\n  begin\n    rintros ⟨a1,a2⟩,\n    ext;\n    simp\n  end }\n\n-- Prueba de mul_assoc\n-- ===================\n\n/-\nG : Type,\n_inst_2 : group G,\nH : Type,\n_inst_3 : group H\n⊢ ∀ (a b c : G × H), a * b * c = a * (b * c)\n    >> rintros ⟨a1,a2⟩ ⟨b1,b2⟩ ⟨c1,c2⟩,\na1 : G,\na2 : H,\nb1 : G,\nb2 : H,\nc1 : G,\nc2 : H\n⊢ (a1, a2) * (b1, b2) * (c1, c2) = (a1, a2) * ((b1, b2) * (c1, c2))\n    >> ext;\n⊢ ((a1, a2) * (b1, b2) * (c1, c2)).fst = ((a1, a2) * ((b1, b2) * (c1,c2))).fst\n⊢ ((a1, a2) * (b1, b2) * (c1, c2)).snd = ((a1, a2) * ((b1, b2) * (c1, c2))).snd\n    >> simp,\nno goals\n-/\n\n-- Prueba de one_mul\n-- =================\n\n/-\nG : Type,\n_inst_2 : group G,\nH : Type,\n_inst_3 : group H\n⊢ ∀ (a : G × H), 1 * a = a\n  >> rintros ⟨a1,a2⟩,\na1 : G,\na2 : H\n⊢ 1 * (a1, a2) = (a1, a2)\n  >> ext;\n⊢ (1 * (a1, a2)).fst = (a1, a2).fst\n⊢ (1 * (a1, a2)).snd = (a1, a2).snd\n  >> simp,\nno goals\n-/\n\n-- Prueba de mul_left_inv\n-- ======================\n\n/-\nG : Type,\n_inst_2 : group G,\nH : Type,\n_inst_3 : group H\n⊢ ∀ (a : G × H), a⁻¹ * a = 1\n  >> rintros ⟨a1,a2⟩,\na1 : G,\na2 : H\n⊢ (a1, a2)⁻¹ * (a1, a2) = 1\n  >> ext;\n⊢ ((a1, a2)⁻¹ * (a1, a2)).fst = 1.fst\n⊢ ((a1, a2)⁻¹ * (a1, a2)).snd = 1.snd\n  >> simp\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si G, H y K son grupos, entonces G × H × K\n-- también lo es.\n-- ----------------------------------------------------------------------\n\nexample (G H K : Type) [group G] [group H] [group K] : group (G × H × K) :=\nby apply_instance\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Cerrar el espacio de nombres group.\n-- ----------------------------------------------------------------------\n\nend group\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el tipo mu2 con dos elementos p1 y m1 (que\n-- representarán a +1 y -1).\n-- ----------------------------------------------------------------------\n\ninductive mu2\n| p1 : mu2\n| m1 : mu2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el espacio de nombres mu2.\n-- ----------------------------------------------------------------------\n\nnamespace mu2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la igualdad en mu2 es decidible.\n-- ----------------------------------------------------------------------\n\nattribute [derive decidable_eq] mu2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que mu2 es un tipo finito.\n-- ----------------------------------------------------------------------\n\ninstance : fintype mu2 :=\n⟨⟨[mu2.p1, mu2.m1], by simp⟩,\n λ x, by cases x; simp⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la función\n--    mul : mu2 → mu2 → mu2\n-- tal que (mul x y) es el producto de x por y.\n-- ----------------------------------------------------------------------\n\ndef mul : mu2 → mu2 → mu2\n| p1 p1 := p1\n| p1 m1 := m1\n| m1 p1 := m1\n| m1 m1 := p1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar mu2 una instancia de has_mul con la operación mul.\n-- ----------------------------------------------------------------------\n\ninstance : has_mul mu2 := ⟨mul⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir one como p1.\n-- ----------------------------------------------------------------------\n\ndef one : mu2 := p1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar mu2 una instancia de has_one con elemento neutro\n-- one.\n-- ----------------------------------------------------------------------\n\ninstance : has_one mu2 := ⟨one⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la función\n--    inv : mu2 → mu2\n-- como la identidad.\n-- ----------------------------------------------------------------------\n\ndef inv : mu2 → mu2 := id\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar mu2 una instancia de has_inv con inv.\n-- ----------------------------------------------------------------------\n\ninstance : has_inv mu2 := ⟨inv⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    p1 * m1 * m1 = p1⁻¹ * p1\n-- ----------------------------------------------------------------------\n\nexample : p1 * m1 * m1 = p1⁻¹ * p1 := rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar mu2 una instancia de group.\n-- ----------------------------------------------------------------------\n\ninstance : group mu2 :=\nbegin\n  refine_struct { mul := mul, one := one, inv := inv },\n  all_goals {exact dec_trivial}\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Cerrar el espacio de nombre mu2.\n-- ----------------------------------------------------------------------\n\nend mu2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los monoides (ver\n-- https://bit.ly/30NfvAZ )\n-- ----------------------------------------------------------------------\n\nclass monoid (M : Type) extends has_mul M, has_one M :=\n(mul_assoc : ∀ (a b c : M), a * b * c = a * (b * c))\n(one_mul : ∀ (a : M), 1 * a = a)\n(mul_one : ∀ (a : M), a * 1 = a)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los grupos conmutativos con sumas.\n-- ----------------------------------------------------------------------\n\nclass add_comm_group (A : Type) extends has_add A, has_zero A, has_neg A :=\n(add_assoc : ∀ (a b c : A), a + b + c = a + (b + c))\n(zero_add : ∀ (a : A), 0 + a = a)\n(add_left_neg : ∀ (a : A), -a + a = 0)\n(add_comm : ∀ a b : A, a + b = b + a)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la resta en los grupos conmutativos con sumas.\n-- ----------------------------------------------------------------------\n\ninstance (A : Type) [add_comm_group A] : has_sub A :=\n⟨λ a b, a + -b⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los anillos.\n-- ----------------------------------------------------------------------\n\nclass ring (R : Type) extends monoid R, add_comm_group R :=\n(mul_add : ∀ (a b c : R), a * (b + c) = a * b + a * c)\n(add_mul : ∀ (a b c : R), (a + b) * c = a * c + b * c)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los anillos conmutativos.\n-- ----------------------------------------------------------------------\n\nclass comm_ring (R : Type) extends ring R :=\n(mul_comm : ∀ a b : R, a * b = b * a)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los tipos con una multiplicación por\n-- un escalar.\n-- ----------------------------------------------------------------------\n\nclass has_scalar (R : Type) (M : Type) :=\n(smul : R → M → M)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar • como la multiplicación por un escalar.\n-- ----------------------------------------------------------------------\n\ninfixr ` • `:73 := has_scalar.smul\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los módulos (ver\n-- https://bit.ly/3hBPZW7 )\n-- ----------------------------------------------------------------------\n\nclass module (R : Type) [ring R] (M : Type) [add_comm_group M]\nextends has_scalar R M :=\n(smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y)\n(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)\n(mul_smul : ∀ (r s : R) (x : M), (r * s) • x = r • s • x)\n(one_smul : ∀ x : M, (1 : R) • x = x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los cuerpos.\n-- ----------------------------------------------------------------------\n\nclass field (K : Type) extends comm_ring K, has_inv K :=\n(zero_ne_one : (0 : K) ≠ 1)\n(mul_inv_cancel : ∀ {a : K}, a ≠ 0 → a * a⁻¹ = 1)\n(inv_zero : (0 : K)⁻¹ = 0)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase de los espacios vectoriales.\n-- ----------------------------------------------------------------------\n\ndef vector_space (K : Type) [field K] (V : Type) [add_comm_group V] :=\nmodule K V\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que los racionales son un cuerpo.\n-- ----------------------------------------------------------------------\n\ninstance : field ℚ :=\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,\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,\n  zero_ne_one := rat.zero_ne_one,\n  mul_inv_cancel := rat.mul_inv_cancel,\n  inv_zero := inv_zero\n  }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar A como un grupo conmutativo con suma.\n-- ----------------------------------------------------------------------\n\nvariables {A : Type} [add_comm_group A]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar a, b y c como variables sobre elementos de A.\n-- ----------------------------------------------------------------------\n\nvariables (a b c : A)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    a + b = a + c\n-- entonces\n--    b = c\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (Habac : a + b = a + c)\n  : b = c :=\ncalc b = 0 + b        : (add_comm_group.zero_add b).symm\n   ... = (-a + a) + b : congr_arg (+ b) (add_comm_group.add_left_neg a).symm\n   ... = -a + (a + b) : add_comm_group.add_assoc (-a) a b\n   ... = -a + (a + c) : congr_arg ((+) (-a)) Habac\n   ... = (-a + a) + c : (add_comm_group.add_assoc (-a) a c).symm\n   ... = 0 + c        : congr_arg (+ c) (add_comm_group.add_left_neg a)\n   ... = c            : add_comm_group.zero_add c\n\n-- 2ª demostración\n-- ===============\n\nlemma add_comm_group.add_left_cancel\n  (Habac : a + b = a + c)\n  : b = c :=\nbegin\n  rw ←add_comm_group.zero_add b,\n  rw ←add_comm_group.add_left_neg a,\n  rw add_comm_group.add_assoc,\n  rw Habac,\n  rw ←add_comm_group.add_assoc,\n  rw add_comm_group.add_left_neg,\n  rw add_comm_group.zero_add,\nend\n\n-- Prueba\n-- ======\n\n/-\nA : Type,\n_inst_1 : add_comm_group A,\na b c : A,\nHabac : a + b = a + c\n⊢ b = c\n  >> rw ←add_comm_group.zero_add b,\n⊢ 0 + b = c\n  >> rw ←add_comm_group.add_left_neg a,\n⊢ (-a + a) + b = c\n  >> rw add_comm_group.add_assoc,\n⊢ -a + (a + b) = c\n  >> rw Habac,\n⊢ -a + (a + c) = c\n  >> rw ←add_comm_group.add_assoc,\n⊢ (-a + a) + c = c\n  >> rw add_comm_group.add_left_neg,\n⊢ 0 + c = c\n  >> rw add_comm_group.zero_add,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a + -a = 0\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample :\n  a + -a = 0 :=\ncalc a + -a\n     = -a + a : add_comm_group.add_comm a (-a)\n ... = 0      : add_comm_group.add_left_neg a\n\n-- 2ª demostración\n-- ===============\n\nexample :\n  a + -a = 0 :=\ncalc a + -a\n     = -a + a : by rw add_comm_group.add_comm\n ... = 0      : by rw add_comm_group.add_left_neg\n\n-- 3ª demostración\n-- ===============\n\nlemma add_comm_group.add_right_neg :\n  a + -a = 0 :=\nbegin\n  rw add_comm_group.add_comm,\n  rw add_comm_group.add_left_neg,\nend\n\n-- Prueba\n-- ======\n\n/-\nA : Type,\n_inst_1 : add_comm_group A,\na : A\n⊢ a + -a = 0\n  >> rw add_comm_group.add_comm,\n⊢ -a + a = 0\n  >> rw add_comm_group.add_left_neg,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a - b = a + -b\n-- ----------------------------------------------------------------------\n\nlemma add_comm_group.sub_eq_add_neg :\n  a - b = a + -b :=\nrfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a - a = 0\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample :\n  a - a = 0 :=\ncalc a - a\n     = a + (-a) : add_comm_group.sub_eq_add_neg a a\n ... = -a + a   : add_comm_group.add_comm a (-a)\n ... = 0        : add_comm_group.add_left_neg a\n\n-- 2ª demostración\n-- ===============\n\nexample :\n  a - a = 0 :=\ncalc a - a\n     = a + (-a) : by rw add_comm_group.sub_eq_add_neg\n ... = -a + a   : by rw add_comm_group.add_comm\n ... = 0        : by rw add_comm_group.add_left_neg\n\n-- 3ª demostración\n-- ===============\n\nexample :\n  a - a = 0 :=\nby rw [add_comm_group.sub_eq_add_neg,\n       add_comm_group.add_comm,\n       add_comm_group.add_left_neg]\n\n-- 4ª demostración\n-- ===============\n\nlemma add_comm_group.sub_self :\n  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\n-- Prueba\n-- ======\n\n/-\nA : Type,\n_inst_1 : add_comm_group A,\na : A\n⊢ a - a = 0\n  >> rw add_comm_group.sub_eq_add_neg,\n⊢ a + -a = 0\n  >> rw add_comm_group.add_comm,\n⊢ -a + a = 0\n  >> rw add_comm_group.add_left_neg,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    a + b = 0\n-- entonces\n--    -a = b\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (h : a + b = 0)\n  : -a = b :=\ncalc -a\n     = 0 + (-a)       : (add_comm_group.zero_add (-a)).symm\n ... = (a + b) + (-a) : congr_arg (+ (-a)) h.symm\n ... = (b + a) + (-a) : congr_arg (+ (-a)) (add_comm_group.add_comm a b)\n ... = b + (a + (-a)) : add_comm_group.add_assoc b a (-a)\n ... = b + 0          : congr_arg ((+) b) (add_comm_group.add_right_neg a)\n ... = 0 + b          : add_comm_group.add_comm b 0\n ... = b              : add_comm_group.zero_add b\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (h : a + b = 0)\n  : -a = b :=\ncalc -a\n     = 0 + (-a)       : by rw add_comm_group.zero_add\n ... = (a + b) + (-a) : by rw h.symm\n ... = (b + a) + (-a) : congr_arg (+ (-a)) (add_comm_group.add_comm a b)\n ... = b + (a + (-a)) : by rw add_comm_group.add_assoc\n ... = b + 0          : congr_arg ((+) b) (add_comm_group.add_right_neg a)\n ... = 0 + b          : by rw add_comm_group.add_comm\n ... = b              : by rw add_comm_group.zero_add\n\n-- 3ª demostración\n-- ===============\n\nlemma add_comm_group.neg_eq_of_add_eq_zero\n  (h : a + b = 0)\n  : -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\n-- Prueba\n-- ======\n\n/-\nA : Type,\n_inst_1 : add_comm_group A,\na b : A,\nh : a + b = 0\n⊢ -a = b\n  >> apply add_comm_group.add_left_cancel a,\n⊢ a + -a = a + b\n  >> rw h,\n⊢ a + -a = 0\n  >> rw add_comm_group.add_right_neg,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    a + 0 = a\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : a + 0 = a :=\ncalc a + 0\n     = 0 + a : add_comm_group.add_comm a 0\n ... = a     : add_comm_group.zero_add a\n\n-- 2ª demostración\n-- ===============\n\nexample : a + 0 = a :=\ncalc a + 0\n     = 0 + a : by rw add_comm_group.add_comm\n ... = a     : by rw add_comm_group.zero_add\n\n-- 3ª demostración\n-- ===============\n\nexample : a + 0 = a :=\nbegin\n  rw add_comm_group.add_comm,\n  rw add_comm_group.zero_add,\nend\n\n-- 3ª demostración\n-- ===============\n\nlemma add_comm_group.add_zero : a + 0 = a :=\nby rw [add_comm_group.add_comm,\n       add_comm_group.zero_add]\n\n-- Prueba\n-- ======\n\n/-\nA : Type,\n_inst_1 : add_comm_group A,\na : A\n⊢ a + 0 = a\n  >> rw add_comm_group.add_comm,\n⊢ 0 + a = a\n  >> rw add_comm_group.zero_add,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar R como una variable implícita sobre los anillos.\n-- ----------------------------------------------------------------------\n\nvariables {R : Type} [ring R]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que, para todo r de R,\n--    r * 0 = 0\n-- ----------------------------------------------------------------------\n\nlemma ring.mul_zero\n  (r : R)\n  : r * 0 = 0 :=\nbegin\n  apply add_comm_group.add_left_cancel (r * 0),\n  rw ←ring.mul_add,\n  rw add_comm_group.add_zero,\n  rw add_comm_group.add_zero,\nend\n\n-- Prueba\n-- ======\n\n/-\nR : Type,\n_inst_2 : ring R,\nr : R\n⊢ r * 0 = 0\n  >> apply add_comm_group.add_left_cancel (r * 0),\n⊢ r * 0 + r * 0 = r * 0 + 0\n  >> rw ←ring.mul_add,\n⊢ r * (0 + 0) = r * 0 + 0\n  >> rw add_comm_group.add_zero,\n⊢ r * 0 = r * 0 + 0\n  >> rw add_comm_group.add_zero,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que, para todo a y b de R,\n--    a * -b = -(a * b)\n-- ----------------------------------------------------------------------\n\nlemma ring.mul_neg\n  (a b : R) :\n  a * -b = -(a * b) :=\nbegin\n  symmetry,\n  apply add_comm_group.neg_eq_of_add_eq_zero,\n  rw ←ring.mul_add,\n  rw add_comm_group.add_right_neg,\n  rw ring.mul_zero,\nend\n\n-- Prueba\n-- ======\n\n/-\nR : Type,\n_inst_2 : ring R,\na b : R\n⊢ a * -b = -(a * b)\n  >> symmetry,\n⊢ -(a * b) = a * -b\n  >> apply add_comm_group.neg_eq_of_add_eq_zero,\n⊢ a * b + a * -b = 0\n  >> rw ←ring.mul_add,\n⊢ a * (b + -b) = 0\n  >> rw add_comm_group.add_right_neg,\n⊢ a * 0 = 0\n  >> rw ring.mul_zero,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sea R un anillo conmutativo. Demostrar que, para todo r, a\n-- y b de R,\n--    r * (a - b) = r * a - r * b\n-- ----------------------------------------------------------------------\n\nlemma ring.mul_sub\n  (R : Type)\n  [comm_ring R]\n  (r a b : R) :\n  r * (a - b) = r * a - r * b :=\nbegin\n  rw add_comm_group.sub_eq_add_neg,\n  rw ring.mul_add,\n  rw ring.mul_neg,\n  refl,\nend\n\n-- Prueba\n-- ======\n\n/-\nR : Type,\n_inst_3 : comm_ring R,\nr a b : R\n⊢ r * (a - b) = r * a - r * b\n  >> rw add_comm_group.sub_eq_add_neg,\n⊢ r * (a + -b) = r * a - r * b\n  >> rw ring.mul_add,\n⊢ r * a + r * -b = r * a - r * b\n  >> rw ring.mul_neg,\n⊢ r * a + -(r * b) = r * a - r * b\n  >> refl,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sea R un anillo conmutativo. Demostrar que, para todo r, a\n-- y b de R,\n--    (a - b) * r = a * r - b * r\n-- ----------------------------------------------------------------------\n\nlemma comm_ring.sub_mul\n  (R : Type)\n  [comm_ring R]\n  (r a b : R)\n  : (a - b) * r = a * r - b * r :=\nbegin\n  rw comm_ring.mul_comm (a - b),\n  rw comm_ring.mul_comm a,\n  rw comm_ring.mul_comm b,\n  apply ring.mul_sub,\nend\n\n-- Prueba\n-- ======\n\n/-\nR : Type,\n_inst_3 : comm_ring R,\nr a b : R\n⊢ (a - b) * r = a * r - b * r\n  >> rw comm_ring.mul_comm (a - b),\n⊢ r * (a - b) = a * r - b * r\n  >> rw comm_ring.mul_comm a,\n⊢ r * (a - b) = r * a - b * r\n  >> rw comm_ring.mul_comm b,\n⊢ r * (a - b) = r * a - r * b\n  >> apply ring.mul_sub,\nno goals\n-/\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Cerrar el espacio de nombres lftcm.\n-- ----------------------------------------------------------------------\n\nend lftcm\n\n------------------------------------------------------------------------\n-- § Referencia                                                       --\n------------------------------------------------------------------------\n\n-- Basado en la teoría algebraic_hierarchy.lean de Kevin Buzzard que se\n-- encuentra en https://bit.ly/32S8vFr y se comenta en el vídeo\n-- \"Building an algebraic hierarchy\" que se encuentra en\n-- https://youtu.be/ATlAQPAtiTY\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/Estructuras_algebraicas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7860823734715152}}
{"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 number_theory.primes_congruent_one\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.PrimeFin\nimport Mathbin.RingTheory.Polynomial.Cyclotomic.Eval\n\n/-!\n# Primes congruent to one\n\nWe prove that, for any positive `k : ℕ`, there are infinitely many primes `p` such that\n`p ≡ 1 [MOD k]`.\n-/\n\n\nnamespace Nat\n\nopen Polynomial Nat Filter\n\nopen Nat\n\n/-- For any positive `k : ℕ` there exists an arbitrarily large prime `p` such that\n`p ≡ 1 [MOD k]`. -/\ntheorem exists_prime_gt_modEq_one {k : ℕ} (n : ℕ) (hk0 : k ≠ 0) :\n    ∃ p : ℕ, Nat.Prime p ∧ n < p ∧ p ≡ 1 [MOD k] :=\n  by\n  rcases(one_le_iff_ne_zero.2 hk0).eq_or_lt with (rfl | hk1)\n  · rcases exists_infinite_primes (n + 1) with ⟨p, hnp, hp⟩\n    exact ⟨p, hp, hnp, modeq_one⟩\n  let b := k * n !\n  have hgt : 1 < (eval (↑b) (cyclotomic k ℤ)).natAbs :=\n    by\n    rcases le_iff_exists_add'.1 hk1.le with ⟨k, rfl⟩\n    have hb : 2 ≤ b := le_mul_of_le_of_one_le hk1 n.factorial_pos\n    calc\n      1 ≤ b - 1 := le_tsub_of_add_le_left hb\n      _ < (eval (b : ℤ) (cyclotomic (k + 1) ℤ)).natAbs :=\n        sub_one_lt_nat_abs_cyclotomic_eval hk1 (succ_le_iff.1 hb).ne'\n      \n  let p := min_fac (eval (↑b) (cyclotomic k ℤ)).natAbs\n  haveI hprime : Fact p.prime := ⟨min_fac_prime (ne_of_lt hgt).symm⟩\n  have hroot : is_root (cyclotomic k (ZMod p)) (cast_ring_hom (ZMod p) b) :=\n    by\n    rw [is_root.def, ← map_cyclotomic_int k (ZMod p), eval_map, coe_cast_ring_hom, ← Int.cast_ofNat,\n      ← Int.coe_castRingHom, eval₂_hom, Int.coe_castRingHom, ZMod.int_cast_zmod_eq_zero_iff_dvd _ _]\n    apply Int.dvd_natAbs.1\n    exact_mod_cast min_fac_dvd (eval (↑b) (cyclotomic k ℤ)).natAbs\n  have hpb : ¬p ∣ b :=\n    hprime.1.coprime_iff_not_dvd.1 (coprime_of_root_cyclotomic hk0.bot_lt hroot).symm\n  refine' ⟨p, hprime.1, not_le.1 fun habs => _, _⟩\n  · exact hpb (dvd_mul_of_dvd_right (dvd_factorial (min_fac_pos _) habs) _)\n  · have hdiv : orderOf (b : ZMod p) ∣ p - 1 :=\n      ZMod.orderOf_dvd_card_sub_one (mt (CharP.cast_eq_zero_iff _ _ _).1 hpb)\n    haveI : NeZero (k : ZMod p) :=\n      NeZero.of_not_dvd (ZMod p) fun hpk => hpb (dvd_mul_of_dvd_left hpk _)\n    have : k = orderOf (b : ZMod p) := (is_root_cyclotomic_iff.mp hroot).eq_orderOf\n    rw [← this] at hdiv\n    exact ((modeq_iff_dvd' hprime.1.Pos).2 hdiv).symm\n#align nat.exists_prime_gt_modeq_one Nat.exists_prime_gt_modEq_one\n\ntheorem frequently_atTop_modEq_one {k : ℕ} (hk0 : k ≠ 0) :\n    ∃ᶠ p in atTop, Nat.Prime p ∧ p ≡ 1 [MOD k] :=\n  by\n  refine' frequently_at_top.2 fun n => _\n  obtain ⟨p, hp⟩ := exists_prime_gt_modeq_one n hk0\n  exact ⟨p, ⟨hp.2.1.le, hp.1, hp.2.2⟩⟩\n#align nat.frequently_at_top_modeq_one Nat.frequently_atTop_modEq_one\n\n/-- For any positive `k : ℕ` there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`. -/\ntheorem infinite_setOf_prime_modEq_one {k : ℕ} (hk0 : k ≠ 0) :\n    Set.Infinite { p : ℕ | Nat.Prime p ∧ p ≡ 1 [MOD k] } :=\n  frequently_atTop_iff_infinite.1 (frequently_atTop_modEq_one hk0)\n#align nat.infinite_set_of_prime_modeq_one Nat.infinite_setOf_prime_modEq_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/PrimesCongruentOne.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7860823703158052}}
{"text": "/- by Li Xiang, Laraia Thomas, Pratt Johns Joe, Yu Ella -/\n/- GNU General Public License v3.0 -/\n\nimport tactic\nnoncomputable theory\n\n/- 1 Basic Definitions-/\n\n/- There are two ways to define the equivalence relation -/\n/- Approach I: Set Theory-/\n\ndef is_refl_set {X:Type}(S: set (X× X)):=\n∀ a: X, (a,a)∈ S\n\ndef is_symm_set {X:Type}(S: set (X× X)):=\n∀ a b:X, (a,b)∈ S→ (b,a)∈S \n\ndef is_trans_set {X:Type}(S:set (X× X)):=\n∀ a b c:X, (a,b)∈ S→ (b,c)∈ S→ (a,c)∈ S \n\ndef is_equiv_set {X:Type}(S:set (X× X)):=\nis_refl_set S ∧ is_symm_set S \n∧ is_trans_set S\n\ndef equiv_class_set {X:Type}(S:set (X× X))(a:X):=\n{x:X | (x,a)∈ S}\n\ndef quotient_set {X:Type}(S:set (X× X)):=\n{e:set X | ∃ a:X, e=equiv_class_set S a}\n\n/- Approach II: Type Theory-/\n/- I will use this approach in the follwing files. -/\n\ndef is_refl_type {X:Type}(S: X→ X→ Prop):= -- Def 1 --\n∀ a:X, S a a\n\ndef is_symm_type {X:Type}(S: X→ X→ Prop):= -- Def 2 --\n∀ a b:X, S a b→ S b a\n\ndef is_trans_type {X:Type}(S:X→ X→ Prop):= -- Def 3 --\n∀ a b c:X, S a b→ S b c→ S a c \n\ndef is_equiv_type {X:Type}(S:X→ X→ Prop):= -- Def 4--\nis_refl_type S ∧ is_symm_type S \n∧ is_trans_type S\n\ndef equiv_class_type {X:Type}(S:X→ X→ Prop)(a:X):= -- Def 5 --\n{x:X | S x a}\n\ndef quotient_type {X:Type}(S:X→ X→ Prop):= --Def 6 --\n{e:set X | ∃ a:X, e=equiv_class_type S a}\n\n/- 2 Properties -/\n\ndef convert_to_set(X:Type):set X:={x:X | true}\n\nlemma in_equiv_class {X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X):\na∈ equiv_class_type S a:= -- Lemma 7 --\nbegin\n  cases h with p q,\n  apply p a,\nend\n\nlemma equiv_class_is_subset{X:Type}(S:X→ X→ Prop)(a:X):\n(equiv_class_type S a)⊆convert_to_set(X)\n:= -- Lemma 8 --\nbegin\n  intros x f,\n  rw convert_to_set,\n  rw set.mem_set_of_eq,\n  cc,\nend\n\nlemma equiv_iff_same_class {X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X)(b:X):\nS a b ↔ equiv_class_type S a=equiv_class_type S b\n:=  -- Lemma 9 --\nbegin\n  have rfl:=h.1,\n  have sym:=h.2.1,\n  have tran:=h.2.2,\n  split,\n\n  /- → -/\n  intro f,\n  --cases h with rfl st,\n  --cases st with sym tran,\n  rw set.subset.antisymm_iff,\n  split,\n  /- → ⊆-/\n  intros x g,\n  apply tran x a b g f,\n  /- → ⊇ -/\n  intros x g,\n  have t:=sym a b f,\n  apply tran x b a g t,\n\n  /- ← -/\n  intro f,\n  have u:=in_equiv_class h a,\n  rw f at u,\n  exact u,\nend\n\nlemma equiv_iff_class_intersect{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X)(b:X):\nS a b ↔ (equiv_class_type S a ∩ equiv_class_type S b).nonempty\n:= --Lemma 10 --\nbegin\n  have rfl:=h.1,\n  have sym:=h.2.1,\n  have tran:=h.2.2,\n  split,\n\n  /- → -/\n  intro f,\n  rw set.nonempty,\n  use a,\n  rw set.mem_inter_eq,\n  split,\n  have t:=in_equiv_class h a,\n  exact t,\n  exact f,\n\n  /- ← -/\n  intro f,\n  cases f with x fx,\n  rw set.mem_inter_eq at fx,\n  cases fx with fxp fxq,\n  have t:=sym x a fxp,\n  apply tran a x b t fxq,\nend \n\nlemma same_class_iff_intersect{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X)(b:X): -- Lemma 11 --\nequiv_class_type S a = equiv_class_type S b ↔ \n(equiv_class_type S a ∩ equiv_class_type S b).nonempty:=\nbegin\n  have p:=equiv_iff_same_class h a b,\n  have q:=equiv_iff_class_intersect h a b,\n  rw p at q,\n  exact q,\nend \n\nlemma contrapose_iff {P:Prop}{Q:Prop}:(P↔Q)↔(¬P↔¬Q):=\nbegin\n  split,\n  intro f,\n  cc,\n  intro f,\n  split,\n  cc,\n  cc,\nend\n\nlemma equiv_class_disjoint{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X)(b:X):\nequiv_class_type S a ≠ equiv_class_type S b ↔ \n(equiv_class_type S a ∩ equiv_class_type S b)=∅ \n:= -- Lemma 12 --\nbegin\n  have q:=same_class_iff_intersect h a b,\n  rw contrapose_iff at q,\n  rw set.not_nonempty_iff_eq_empty at q,\n  cc,\nend\n\nlemma equiv_class_union{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S):\n(⋃ (ind:X), (equiv_class_type S ind))=convert_to_set(X)\n:= -- Lemma 13 --\nbegin\n  rw set.subset.antisymm_iff,\n  split,\n  \n  /- ⊆ -/\n  intros x f,\n  rw convert_to_set,\n  rw set.mem_set_of_eq,\n  cc,\n\n  /- ⊇ -/\n  intros x f,\n  have t:=in_equiv_class h x,\n  rw set.mem_Union,\n  use x,\n  exact t,\nend\n\n/- 3 Canonical Map and Section -/\n\nlemma equiv_class_type_in_quotient_type{X:Type}\n(S:X→ X→ Prop)(a:X): \nequiv_class_type S a ∈ quotient_type S:= -- Lemma 14 --\nbegin\n  use a,\nend\n\ndef can{X:Type}(S:X→ X→ Prop):X→ quotient_type S:= -- Def 15 --\nλa,⟨equiv_class_type S a, equiv_class_type_in_quotient_type S a⟩\n\nlemma in_can{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X):\na∈ (can S a).val:=\nbegin\n  exact in_equiv_class h a,\nend\n\nlemma can_be_repres{X:Type}{S:X→ X→ Prop}\n(e:quotient_type S):∃ a:X, e.val=equiv_class_type S a\n:= -- Lemma 16 pre --\nbegin\n  have t:=subtype.mem e,\n  cases t with a ta,\n  use a,\n  exact ta,\nend\n\nlemma equiv_class_nonempty{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(e:quotient_type S):e.val.nonempty\n:= -- Lemma 16 --\nbegin\n  rw set.nonempty_def,\n  have t:=can_be_repres e,\n  cases t with a ta,\n  use a,\n  rw ta,\n  apply in_equiv_class h a,  \nend\n\ndef particular_sec{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S):quotient_type S→ X:= -- Def 17 --\nλe, set.nonempty.some (equiv_class_nonempty h e)\n\ndef can_sec{X:Type}{S:X→ X→ Prop}(sec:(quotient_type S)→ X):\nquotient_type S→ quotient_type S := -- Def 18 --\nλe, can S (sec e)\n\nlemma sec_equiv{X:Type}{S:X→ X→ Prop}(h: is_equiv_type S)\n{sec:(quotient_type S)→ X}{sec':(quotient_type S)→ X}\n(hs: can_sec sec=id)(hs': can_sec sec'=id)(e:quotient_type S):\nS (sec e) (sec' e):= -- Lemma 19 --\nbegin\n  rw equiv_iff_same_class h,\n  unfold can_sec at *,\n  have t:=(congr_fun (eq.symm hs) e).symm,\n  have u:=(congr_fun (eq.symm hs') e).symm,\n  unfold can at *,\n  rw ← t at u,\n  simp at *,\n  symmetry,\n  exact u,\nend\n\nlemma par_sec_in{X:Type}{S:X→ X→ Prop}(h: is_equiv_type S)\n(x:quotient_type S):\n(particular_sec h x) ∈ x.val:= -- Lemma 20 --\nbegin\n  unfold particular_sec,\n  exact (equiv_class_nonempty h x).some_mem,\nend\n\n@[simp] lemma can_par_sec_id{X:Type}{S:X→ X→ Prop}(h: is_equiv_type S):\ncan_sec (particular_sec h)=id:= -- Lemma 21 --\nbegin\n  unfold can_sec,\n  ext1,\n  unfold id,\n  ext1,\n  unfold can,\n  simp,\n  have t:=in_equiv_class h (particular_sec h x),\n  have u:=par_sec_in h x,\n  have v:∃a:X, x.val=equiv_class_type S a:=can_be_repres x,\n  cases v with a,\n  simp at *,\n  rw v_h at *,\n  have ne_empty:((equiv_class_type S (particular_sec h x))∩ \n  (equiv_class_type S a)).nonempty:=begin\n    rw set.nonempty_def,\n    use particular_sec h x,\n    simp,\n    split,\n    exact t,\n    exact u,\n  end,\n  rw same_class_iff_intersect h _ _,\n  exact ne_empty,\nend\n\n@[simp] lemma can_par_sec{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(e:quotient_type S):\ncan_sec (particular_sec h) e=e:= -- Lemma 21' --\nbegin\n  rw can_par_sec_id,\n  rwa id,\nend\n\n@[simp] lemma can_par_sec_expand{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(e:quotient_type S):\ncan S (particular_sec h e)=e:= -- Lemma 21'' --\nbegin\n  have t:can S(particular_sec h e)=can_sec (particular_sec h) e:=\n    by unfold can_sec,\n  rw t,\n  exact can_par_sec h e,\nend\n\nlemma par_sec_can{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X):\nS (particular_sec h (can S a)) a:= -- Lemma 22 --\nbegin\n  have t:=par_sec_in h (can S a),\n  unfold can at t,\n  unfold equiv_class_type at t,\n  simp at *,\n  exact t,\nend\n\nlemma equiv_iff_same_image_under_can{X:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(a:X)(b:X):\nS a b ↔ can S a=can S b:= -- Lemma 23 --\nbegin\n  unfold can,\n  simp,\n  exact equiv_iff_same_class h a b,\nend\n\n/- 4 Operations -/\n\ndef induced_op_by_sec{X:Type}{Y:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(sec:(quotient_type S)→ X)(op:X→ Y):\nquotient_type S→ Y:= -- Def 24, one argument --\nλ e, op (sec e)\n\ndef induced_op{X:Type}{Y:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(op:X→ Y):= -- Def 25, one argument --\ninduced_op_by_sec h (particular_sec h) op\n\ndef op_is_well_defined{X:Type}{Y:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(op:X→ Y):= -- Def 26, one argument --\n∀ a b:X, S a b → op a=op b \n\nlemma op_reduction{X:Type}{Y:Type}{S:X→ X→ Prop}\n{h: is_equiv_type S}{op:X→ Y}\n(hw: op_is_well_defined h op)\n{e :quotient_type S}{a:X}{c:Y}\n(h1: can S a=e)(ho: op a=c):\ninduced_op h op e=c:= -- Lemma 27, one argument --\nbegin\n  unfold induced_op,\n  unfold induced_op_by_sec,\n  rw ← h1,\n  have t:=par_sec_can h a,\n  have u:=hw _ _ t,\n  rw u,\n  exact ho,\nend\n\ndef induced_op2_by_sec{X:Type}{Y:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(sec:(quotient_type S)→ X)(op:X→ X→ Y):\nquotient_type S→ quotient_type S→ Y:= -- Def 24', two arguments --\nλe1,λe2, op (sec e1) (sec e2)\n\ndef induced_op2{X:Type}{Y:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(op:X→ X→ Y):= -- Def 25', two arguments --\ninduced_op2_by_sec h (particular_sec h) op\n\ndef op2_is_well_defined{X:Type}{Y:Type}{S:X→ X→ Prop}\n(h: is_equiv_type S)(op:X→ X→ Y):= -- Def 26', two arguments --\n∀ a b c d:X, S a c→ S b d→ op a b=op c d \n\nlemma op2_reduction{X:Type}{Y:Type}{S:X→ X→ Prop}\n{h: is_equiv_type S}{op:X→ X→ Y}\n(hw: op2_is_well_defined h op)\n{e1 e2 :quotient_type S}{a b:X}{c:Y}\n(h1: can S a=e1)(h2:can S b=e2)(ho: op a b=c):\ninduced_op2 h op e1 e2=c:= -- Lemma 27', two arguments --\nbegin\n  unfold induced_op2,\n  unfold induced_op2_by_sec,\n  rw ← h1,\n  rw ← h2,\n  have t1:=par_sec_can h a,\n  have t2:=par_sec_can h b,\n  have u:=hw _ _ _ _ t1 t2,\n  rw u,\n  exact ho,\nend\n\n/- 5 Partition -/\n\nlemma Enonempty{X:Type}{S:X→ X→ Prop}(h: is_equiv_type S):\n∀ e∈ quotient_type S, (e:set X).nonempty:=\nbegin\n  intros e f,\n  unfold quotient_type at f,\n  simp at *,\n  cases f with a,\n  use a,\n  rw f_h,\n  exact in_equiv_class h a,\nend\n\nlemma Ecover{X:Type}{S:X→ X→ Prop}(h: is_equiv_type S):\n∀ a:X, ∃ e ∈ quotient_type S, a ∈ e:=\nbegin\n  intro a,\n  use (equiv_class_type S a),\n  split,\n  exact equiv_class_type_in_quotient_type _ _,\n  exact in_equiv_class h a,\nend\n\nlemma Edisjoint{X:Type}{S:X→ X→ Prop}(h: is_equiv_type S):\n∀ e1 e2 ∈ quotient_type S, (e1 ∩ e2 : set X).nonempty → e1=e2:=\nbegin\n  intros e1 e2 f g s,\n  unfold quotient_type at *,\n  simp at *,\n  cases f with a,\n  cases g with b,\n  rw f_h at *,\n  rw g_h at *,\n  rw (same_class_iff_intersect h a b),\n  exact s,\nend\n", "meta": {"author": "ourlean", "repo": "Equivalence-Relation", "sha": "19971ce2f89f1cda582dd1bcecc3d1af90be5eb9", "save_path": "github-repos/lean/ourlean-Equivalence-Relation", "path": "github-repos/lean/ourlean-Equivalence-Relation/Equivalence-Relation-19971ce2f89f1cda582dd1bcecc3d1af90be5eb9/CatA_equiv_relation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7860823671600948}}
{"text": "import data.real.basic data.set.basic\n\nnamespace M1F\n\ndef is_ub (b : ℝ) (S : set ℝ) := ∀ s ∈ S, s ≤ b\n\n-- in _root_ already\ndef is_lub (l : ℝ) (S : set ℝ) :=\n  is_ub l S ∧ ∀ b : ℝ, is_ub b S → l ≤ b\n\nlemma Q2b (S : set ℝ) (l₁ l₂ : ℝ) (h₁ : is_lub l₁ S)\n  (h₂ : is_lub l₂ S) : l₁ = l₂ :=\nbegin\n  have hub₁ : is_ub l₁ S := h₁.1,\n  have hub₂ : is_ub l₂ S := h₂.1,\n  have h12 : l₁ ≤ l₂ := h₁.2 l₂ hub₂,\n  have h21 : l₂ ≤ l₁ := h₂.2 l₁ hub₁,\n  exact le_antisymm h12 h21\nend\n\nlemma Q2ci (S T : set ℝ) (a b : ℝ) (hS : is_lub a S)\n  (hT : is_lub b T) :\nis_lub (max a b) (S ∪ T) :=\nbegin\n  split,\n  { intro u,\n    intro hu,\n    cases hu with hs ht,\n    { apply le_trans _ (le_max_left a b),\n      exact hS.1 _ hs\n    },\n     { apply le_trans _ (le_max_right a b),\n      exact hT.1 _ ht\n    }\n  },\n  { intro x,\n    intro hx,\n    apply max_le,\n    { \n      apply hS.2,\n      intros s hs,\n      apply hx,\n      left,\n      assumption\n    },\n    {\n      apply hT.2,\n      intros t ht,\n      apply hx,\n      right,\n      assumption\n    }\n  }\nend\n\n-- preparatory lemmas for c(ii)\nopen set\nlemma ub_singleton_iff {a b : ℝ} : is_ub a {b} ↔ b ≤ a :=\n⟨λ h, h _ $ mem_singleton b, λ h c hc, (mem_singleton_iff.1 hc).symm ▸ h⟩\n\nlemma lub_singleton (a : ℝ) : is_lub a {a} :=\n⟨ub_singleton_iff.2 $ le_refl a, λ b, ub_singleton_iff.1⟩\n\nlemma set.mem_pair {a b c : ℝ} : c ∈ ({a, b} : set ℝ) ↔ c = a ∨ c = b :=\n⟨λ h, h.rec or.inr (λ H, or.inl $ mem_singleton_iff.1 H), λ h, or.elim h\n(λ h, by simp [h]) (λ h, by simp [h])⟩\n\nlemma ub_pair {a b c : ℝ} : is_ub c {a, b} ↔ max a b ≤ c :=\n⟨λ h, max_le (h _ $ by simp) (h _ $ by simp),\n λ h s hs, begin cases set.mem_pair.1 hs with h2 h2; rw h2,\n   exact le_trans (le_max_left _ _) h, \n   exact le_trans (le_max_right _ _) h, end⟩\n\nlemma lub_pair {a b : ℝ} : is_lub (max a b) {a, b} :=\n⟨ub_pair.2 $ le_refl _,λ _, ub_pair.1⟩\n\nlemma Q2cii :\n∃ (S : set ℝ) (T : set ℝ) (a b : ℝ),\nis_lub a S ∧ is_lub b T ∧ \n  ∃ x : ℝ, is_lub x (S ∩ T) ∧ x ≠ min a b :=\nbegin\n  -- S\n  use {1, 2},\n  -- T\n  use {1, 3},\n  -- a\n  use 2,\n  -- b\n  use 3,\n  -- 2 is LUB of {1, 2}\n  split, convert lub_pair, norm_num,\n  -- 3 is LUB of {1, 3}\n  split, convert lub_pair, norm_num,\n  -- 1 is LUB of the intersection\n  use 1,\n  split, \n  { -- {1, 2} ∩ {1, 3} = {1}\n    convert lub_singleton 1,\n    ext,\n    split,\n      intro h, cases h with h1 h2,\n      cases h1, rw h1 at h2, revert h2, norm_num,\n      assumption,\n    intro h, rw mem_singleton_iff at h, rw h,\n    simp,\n  },\n  norm_num\nend\n\nlemma Q2di (S : ℕ → set ℝ) (s : ℝ) (hs : is_lub s (Union S))\n  (b : ℕ → ℝ) (h : ∀ n, is_lub (b n) (S n))\n  : is_lub s (set.range b) :=\nbegin\n  split,\n  { \n    intros t h2,\n    rcases mem_range.1 h2 with ⟨n, rfl⟩,\n    apply (h n).2,\n    intros t ht,\n    apply hs.1,\n    rw mem_Union,\n    use n,\n    exact ht\n  },\n  {\n    intros c hc,\n    apply hs.2,\n    intros s hs,\n    rw mem_Union at hs,\n    cases hs with n hn,\n    apply le_trans ((h n).1 _ hn),\n    apply hc,\n    use n\n  }\nend\n\nend M1F ", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/2018-19/M1F1819examQ2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7860566547116039}}
{"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 data.real.basic\n\n/-!\n# IMO 2011 Q3\n\nLet f : ℝ → ℝ be a function that satisfies\n\n   f(x + y) ≤ y * f(x) + f(f(x))\n\nfor all x and y. Prove that f(x) = 0 for all x ≤ 0.\n\n# Solution\n\nDirect translation of the solution found in https://www.imo-official.org/problems/IMO2011SL.pdf\n-/\n\ntheorem imo2011_q3 (f : ℝ → ℝ) (hf : ∀ x y, f (x + y) ≤ y * f x + f (f x)) :\n  ∀ x ≤ 0, f x = 0 :=\nbegin\n  -- reparameterize\n  have hxt : ∀ x t, f t ≤ t * f x - x * f x + f (f x),\n  { intros x t,\n    calc f t = f (x + (t - x))             : by rw (add_eq_of_eq_sub' rfl)\n         ... ≤ (t - x) * f x + f (f x)     : hf x (t - x)\n         ... = t * f x - x * f x + f (f x) : by rw sub_mul },\n\n  have h_ab_combined : ∀ a b, a * f a + b * f b ≤ 2 * f a * f b,\n  { intros a b,\n    linarith [hxt b (f a), hxt a (f b)] },\n\n  have h_f_nonneg_of_pos : ∀ a < 0, 0 ≤ f a,\n  { intros a han,\n    suffices : a * f a ≤ 0, from nonneg_of_mul_nonpos_right this han,\n    exact add_le_iff_nonpos_left.mp (h_ab_combined a (2 * f a)) },\n\n  have h_f_nonpos : ∀ x, f x ≤ 0,\n  { intros x,\n    by_contra h_suppose_not,\n    -- If we choose a small enough argument for f, then we get a contradiction.\n    let s := (x * f x - f (f x)) / (f x),\n    have hm : min 0 s - 1 < s := (sub_one_lt _).trans_le (min_le_right 0 s),\n    have hml : min 0 s - 1 < 0 := (sub_one_lt _).trans_le (min_le_left 0 s),\n\n    suffices : f (min 0 s - 1) < 0, from not_le.mpr this (h_f_nonneg_of_pos (min 0 s - 1) hml),\n\n    have hp : 0 < f x := not_le.mp h_suppose_not,\n    calc f (min 0 s - 1)\n           ≤ (min 0 s - 1) * f x - x * f x + f (f x) : hxt x (min 0 s - 1)\n      ...  < s * f x - x * f x + f (f x) : by linarith [(mul_lt_mul_right hp).mpr hm]\n      ...  = 0 : by { rw [(eq_div_iff hp.ne.symm).mp rfl], linarith } },\n\n  have h_fx_zero_of_neg : ∀ x < 0, f x = 0,\n  { intros x hxz,\n    exact (h_f_nonpos x).antisymm (h_f_nonneg_of_pos x hxz) },\n\n  intros x hx,\n  obtain (h_x_neg : x < 0) | (rfl : x = 0) := hx.lt_or_eq,\n  { exact h_fx_zero_of_neg _ h_x_neg },\n  { suffices : 0 ≤ f 0, from le_antisymm (h_f_nonpos 0) this,\n    have hno : f (-1) = 0 := h_fx_zero_of_neg (-1) neg_one_lt_zero,\n    have hp := hxt (-1) (-1),\n    rw hno at hp,\n    linarith },\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/imo2011_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8688267745399465, "lm_q1q2_score": 0.7859846064975433}}
{"text": "/-\nCopyright (c) 2021 Yaël Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël Dillies\n-/\nimport data.finset.locally_finite\nimport data.fintype.card\n\n/-!\n# Intervals in a pi type\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 {ι : Type*} {α : ι → Type*} [decidable_eq ι] [fintype ι] [Π i, decidable_eq (α i)]\n  [Π i, partial_order (α i)] [Π i, locally_finite_order (α i)]\n\nnamespace pi\n\ninstance : locally_finite_order (Π i, α i) :=\nlocally_finite_order.of_Icc _\n  (λ a b, pi_finset $ λ i, Icc (a i) (b i))\n  (λ a b x, by { simp_rw [mem_pi_finset, mem_Icc], exact forall_and_distrib })\n\nvariables (a b : Π i, α i)\n\nlemma card_Icc : (Icc a b).card = ∏ i, (Icc (a i) (b i)).card := card_pi_finset _\n\nlemma card_Ico : (Ico a b).card = (∏ 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 = (∏ 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 = (∏ i, (Icc (a i) (b i)).card) - 2 :=\nby rw [card_Ioo_eq_card_Icc_sub_two, card_Icc]\n\nend pi\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/pi/interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8688267660487573, "lm_q1q2_score": 0.7859846032829478}}
{"text": "import data.nat.gcd data.nat.prime algebra.group_power \n\nopen nat\n\nvariables {a b p q r n : ℕ}\nvariables {N x y : ℤ}\n\ntheorem Q0805i (hp : gcd a b = 1) : N % a = 0 ∧ N % b = 0 → N % (a*b) = 0 := sorry\n\ntheorem Q0805ii (hp : prime p ∧ prime q ∧ prime r) (hq : p ≠ q) (h : q ≠ r) : x % (p*q*r) = y ↔ (x % p = y) ∧ (x % q = y) ∧ (x % r = y) := sorry\n\n--(iii) (tough) Consider the set of positive integers {2^7 − 2, 3^7 − 3, 4^7 − 4, . . . , 1000^7 − 1000}. What is the greatest common divisor of all the elements of this set? Feel free to use a calculator to get the hang of this; feel free to use Fermat’s Little Theorem and the previous part to nail it.\n\n--theorem Q0805iii \n\ntheorem Q0805iv : n^(561) % 561 = n := \nbegin \ninduction n,\ntrivial,\n\n\nend\n\ntheorem Q0805iv_cor  : (x^p % p = 1 → prime p) → ff := sorry\n\n\n#eval 2^7 -2 --126\n#eval 3^7-3 --2184\n#eval 4^7-4 --16380\n#eval gcd 16380 126", "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/PB0805/Q0805.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750440288019, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7859389853340877}}
{"text": "\ntheorem ExF002{X : Type}{P Q : X → Prop}{a : X}: (∀x , (P x → Q x)) → P a → Q a :=\n  assume H1: (∀x , (P x → Q x)),\n    take (a:X),\n    assume H2: P a,\n    have A: P a → Q a, from H1 a,\n    show Q a, from A H2\n", "meta": {"author": "SvenWille", "repo": "LeanLogicExercises", "sha": "2dbc920feadd63bbc50f87e69646c0081db26eba", "save_path": "github-repos/lean/SvenWille-LeanLogicExercises", "path": "github-repos/lean/SvenWille-LeanLogicExercises/LeanLogicExercises-2dbc920feadd63bbc50f87e69646c0081db26eba/src/FOL/ExF002.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377225508371, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7858986951595567}}
{"text": "open nat\n\ndef mod2 : nat → nat\n| 0 := 0\n| (succ n) := \n  match mod2 n with\n  | 0 := 1\n  | (succ n) := 0\n  end\n\nlemma add2 : ∀ (n : nat), mod2 (n + 2) = mod2 n :=\nbegin\n  intros,\n  unfold mod2,\n  induction n,\n    simp [mod2],\n  simp [mod2, n_ih]\nend\n\nlemma lem : ∀ (k n: nat), mod2 (n + k + k) = mod2 n :=\nbegin\n    intro k, induction k,\n        simp [mod2],\n    intros,\n    show mod2 (n + succ k_n + succ k_n) = mod2 n, from calc\n    mod2 (n + succ k_n + succ k_n)\n        = mod2 (n + (k_n + 1) + (k_n + 1)) : by refl\n    ... = mod2 ((n + k_n + k_n) + 2) : by simp [add_comm, add_assoc]\n    ... = mod2 (n + k_n + k_n) : by rw add2\n    ... = mod2 n : by rw k_ih\nend\n\nexample : ∀ (n : nat), mod2 n = mod2 (n * n) :=\nbegin\n    intros,\n    induction n,\n        simp,\n    simp [mul_succ, succ_mul],\n    rw (add_comm (succ n_n)),\n    rw ←(add_assoc n_n),\n    rw add_succ,\n    unfold mod2,\n    have: mod2 (n_n + n_n * n_n + n_n) = mod2 n_n, from calc\n    mod2 (n_n + n_n * n_n + n_n) = mod2 (n_n * n_n + n_n + n_n) : by simp [add_assoc, add_comm]\n    ... = mod2 (n_n * n_n) : by rw (lem n_n (n_n * n_n))\n    ... = mod2 n_n : by simp [n_ih],\n    simp only [this],\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/14.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7857914037971518}}
{"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\nElegant pairing function.\n-/\nimport data.nat.sqrt data.nat.div\nopen prod decidable\n\nnamespace nat\ndefinition mkpair (a b : nat) : nat :=\nif a < b then b*b + a else a*a + a + b\n\ndefinition unpair (n : nat) : nat × nat :=\nlet s := sqrt n in\nif n - s*s < s then (n - s*s, s) else (s, n - s*s - s)\n\ntheorem mkpair_unpair (n : nat) : mkpair (pr1 (unpair n)) (pr2 (unpair n)) = n :=\nlet s := sqrt n in\nby_cases\n  (suppose n - s*s < s,\n    begin\n      esimp [unpair],\n      rewrite [if_pos this],\n      esimp [mkpair],\n      rewrite [if_pos this, add_sub_of_le (sqrt_lower n)]\n    end)\n  (suppose h₁ : ¬ n - s*s < s,\n    have s ≤ n - s*s,                  from le_of_not_gt h₁,\n    have s + s*s ≤ n - s*s + s*s,      from add_le_add_right this (s*s),\n    have s*s + s ≤ n,                  by rewrite [nat.sub_add_cancel (sqrt_lower n) at this,\n                                              add.comm at this]; assumption,\n    have n ≤ s*s + s + s,              from sqrt_upper n,\n    have n - s*s ≤ s + s,              from calc\n        n - s*s ≤ (s*s + s + s) - s*s    : nat.sub_le_sub_right this (s*s)\n            ... = (s*s + (s+s)) - s*s    : by rewrite add.assoc\n            ... = s + s                  : by rewrite nat.add_sub_cancel_left,\n    have   n - s*s - s ≤ s,              from calc\n        n - s*s - s ≤ (s + s) - s        : nat.sub_le_sub_right this s\n                ... = s                  : by rewrite nat.add_sub_cancel_left,\n    have h₂ : ¬ s < n - s*s - s,       from not_lt_of_ge this,\n    begin\n      esimp [unpair],\n      rewrite [if_neg h₁], esimp,\n      esimp [mkpair],\n      rewrite [if_neg h₂, nat.sub_sub, add_sub_of_le `s*s + s ≤ n`],\n    end)\n\ntheorem unpair_mkpair (a b : nat) : unpair (mkpair a b) = (a, b) :=\nby_cases\n (suppose a < b,\n  have a ≤ b + b, from calc\n    a   ≤ b   : le_of_lt this\n    ... ≤ b+b : !le_add_right,\n  begin\n    esimp [mkpair],\n    rewrite [if_pos `a < b`],\n    esimp [unpair],\n    rewrite [sqrt_offset_eq `a ≤ b + b`, nat.add_sub_cancel_left, if_pos `a < b`]\n  end)\n (suppose ¬ a < b,\n  have   b ≤ a,           from le_of_not_gt this,\n  have a + b ≤ a + a,   from add_le_add_left this a,\n  have   a + b ≥ a,       from !le_add_right,\n  have ¬ a + b < a,     from not_lt_of_ge this,\n  begin\n    esimp [mkpair],\n    rewrite [if_neg `¬ a < b`],\n    esimp [unpair],\n    rewrite [add.assoc (a * a) a b, sqrt_offset_eq `a + b ≤ a + a`, *nat.add_sub_cancel_left,\n             if_neg `¬ a + b < a`]\n  end)\n\nopen prod.ops\n\ntheorem unpair_lt_aux {n : nat} : n ≥ 1 → (unpair n).1 < n :=\nsuppose n ≥ 1,\nor.elim (eq_or_lt_of_le this)\n  (suppose 1 = n, by subst n; exact dec_trivial)\n  (suppose n > 1,\n   let s := sqrt n in\n   by_cases\n    (suppose h : n - s*s < s,\n      have n > 0, from lt_of_succ_lt `n > 1`,\n      have sqrt n > 0, from sqrt_pos_of_pos this,\n      have sqrt n * sqrt n > 0, from mul_pos this this,\n      begin unfold unpair, rewrite [if_pos h], esimp, exact sub_lt `n > 0` `sqrt n * sqrt n > 0` end)\n    (suppose ¬ n - s*s < s, begin unfold unpair, rewrite [if_neg this], esimp, apply sqrt_lt `n > 1` end))\n\ntheorem unpair_lt : ∀ (n : nat), (unpair n).1 < succ n\n| 0        := dec_trivial\n| (succ n) :=\n  have (unpair (succ n)).1 < succ n, from unpair_lt_aux dec_trivial,\n  lt.step this\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/pairing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7857913995421661}}
{"text": "import interior_world.level1 --hide\n\n\n/-\n\n# Level 2: Second definition of the interior\n\nBefore we keep proving properties of the iterior of an arbitrary set, we will prove an alternative definition of it.\n\n-/\nvariables {X : Type} -- hide\nvariables [topological_space X] (x : X)  (A : set X) -- hide\n\nnamespace topological_space -- hide\n\n\n/- Lemma\nThe interior of a set A is the union of all the open sets that it contains:\n$ \\operatorname{int}(A) = \\bigcup_{U \\subseteq A, U\\text{ open}} U$\n-/\nlemma interior_def' : interior A = ⋃₀ {U : set X | is_open U ∧ U ⊆ A} :=\nbegin\n  simp only [interior, is_neighborhood, set.sUnion],\n  ext,\n  norm_num,\n  tauto,\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/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7857859945142313}}
{"text": "-- Reflexive\n-- Does A ↔ A?\nexample: ∀(A: Prop), A ↔ A :=\nbegin\n  assume A,\n  split,\n    assume pf_A,\n    assumption,\n    assume pf_A,\n    assumption,\nend\n\n-- Symmetric (exercise)\n-- Does (A ↔ B) → (B ↔ A)?\nexample: ∀(A B: Prop),\n  (A ↔ B) → (B ↔ A) :=\nbegin\n  assume A B,\n  assume pf_A_iff_B,\n  have pf_A_to_B := (iff.elim_left pf_A_iff_B),\n  have pf_B_to_A := (iff.elim_right pf_A_iff_B),\n  exact iff.intro pf_B_to_A pf_A_to_B,\nend\n\naxiom em: ∀(P: Prop), P ∨ ¬P\n\n-- Uses axiom of the excluded middle (classical)\ntheorem implicationToDisjunction{P Q: Prop}:\n  (P → Q) → (¬P ∨ Q) :=\nbegin\n  assume pf_P_to_Q,\n  cases (em P) with pf_P pf_not_P,\n    -- pf_P\n    have pf_Q := pf_P_to_Q pf_P,\n    exact or.inr pf_Q,\n    -- pf_not_P\n    exact or.inl pf_not_P,\nend\n\n-- constructive\ntheorem modusTollens{P Q: Prop}:\n  (P → Q) → (¬Q → ¬P) :=\nbegin\n  assume pf_P_to_Q,\n  assume pf_not_Q,\n  assume pf_P,\n  have pf_Q := pf_P_to_Q pf_P,\n  exact pf_not_Q pf_Q,\nend\n\n-- Associative\n-- Does ((A ↔ B) ↔ C) ↔ (A ↔ (B ↔ C))?\nexample: ∀(A B C: Prop), \n  ((A ↔ B) ↔ C) ↔ (A ↔ (B ↔ C)) :=\nbegin\n  assume A B C,\n  split,\n    -- ((A ↔ B) ↔ C) → (A ↔ (B ↔ C))\n    assume pf_A_iff_B_iff_C,\n    split,\n      -- A → (B ↔ C)\n      assume pf_A,\n      split,\n        -- B → C\n        assume pf_B,\n        have pf_A_iff_B_to_C := \n          (iff.elim_left pf_A_iff_B_iff_C),\n        have pf_A_to_B: A → B :=\n          begin\n            assume pf_A',\n            assumption,\n          end,\n        have pf_B_to_A :=\n          λ(pf_B: B), pf_A,\n        have pf_A_iff_B :=\n          (iff.intro pf_A_to_B pf_B_to_A),\n        exact pf_A_iff_B_to_C pf_A_iff_B,\n        \n        -- C → B\n        assume pf_C,\n        have pf_C_to_A_iff_B := \n          (iff.elim_right pf_A_iff_B_iff_C),\n        have pf_A_iff_B := pf_C_to_A_iff_B pf_C,\n        have pf_A_to_B := (iff.elim_left pf_A_iff_B),\n        exact pf_A_to_B pf_A,\n      -- (B ↔ C) → A\n      assume pf_B_iff_C,\n      have pf_C_to_A_iff_B := \n        (iff.elim_right pf_A_iff_B_iff_C),\n      cases (em C) with pf_C pf_not_C,\n        -- pf_C\n        have pf_A_iff_B := pf_C_to_A_iff_B pf_C,\n        have pf_B_to_A := (iff.elim_right pf_A_iff_B),\n        cases (em B) with pf_B pf_not_B,\n          -- pf_B\n          exact pf_B_to_A pf_B,\n          -- pf_not_B\n          have pf_C_to_B := (iff.elim_right pf_B_iff_C),\n          have pf_B := pf_C_to_B pf_C,\n          exact false.elim (pf_not_B pf_B),\n        -- pf_not_C\n        cases (em B) with pf_B pf_not_B,\n          -- pf_B\n          have pf_B_to_C := (iff.elim_left pf_B_iff_C),\n          have pf_C := pf_B_to_C pf_B,\n          exact false.elim (pf_not_C pf_C),\n          -- pf_not_B\n          cases (em A) with pf_A pf_not_A,\n            -- pf_A\n            assumption,\n            -- pf_not_A,\n            have pf_A_iff_B_to_C := (iff.elim_left pf_A_iff_B_iff_C),\n            have pf_A_to_B: A → B :=\n              λ(pf_A: A), false.elim (pf_not_A pf_A),\n            have pf_B_to_A: B → A :=\n              λ(pf_B: B), false.elim (pf_not_B pf_B),\n            have pf_A_iff_B := iff.intro pf_A_to_B pf_B_to_A,\n            have pf_C := pf_A_iff_B_to_C pf_A_iff_B,\n            exact false.elim (pf_not_C pf_C),\n    -- (A ↔ (B ↔ C)) → ((A ↔ B) ↔ C)\n    assume pf_A_iff__B_iff_C,\n    split,\n      -- (A ↔ B) → C\n      assume pf_A_iff_B,\n      cases (em A) with pf_A pf_not_A,\n        -- pf_A\n        -- Note the shorthand used here\n        have pf_B := (iff.elim_left pf_A_iff_B) pf_A,\n        have pf_B_iff_C := (iff.elim_left pf_A_iff__B_iff_C) pf_A,\n        exact (iff.elim_left pf_B_iff_C) pf_B,\n        -- pf_not_A\n        cases (em B) with pf_B pf_not_B,\n          -- pf_B\n          -- Note the shorthand used here\n          have pf_A := (iff.elim_right pf_A_iff_B) pf_B,\n          exact false.elim (pf_not_A pf_A),\n          -- pf_not_B\n          cases (em C) with pf_C pf_not_C,\n            -- pf_C\n            assumption,\n            -- pf_not_C\n            have pf_B_to_C: B → C :=\n              λ(pf_B: B), false.elim (pf_not_B pf_B),\n            have pf_C_to_B: C → B :=\n              λ(pf_C: C), false.elim (pf_not_C pf_C),\n            have pf_B_iff_C := iff.intro pf_B_to_C pf_C_to_B,\n            have pf_A := (iff.elim_right pf_A_iff__B_iff_C) pf_B_iff_C,\n            exact false.elim (pf_not_A pf_A),\n      -- C → (A ↔ B)\n      assume pf_C,\n      split,\n        -- A → B\n        assume pf_A,\n        have pf_B_iff_C := (iff.elim_left pf_A_iff__B_iff_C) pf_A,\n        have pf_C_to_B := (iff.elim_right pf_B_iff_C),\n        exact pf_C_to_B pf_C,\n        -- B → A\n        assume pf_B,\n        have pf_B_iff_C__to_A := (iff.elim_right pf_A_iff__B_iff_C),\n        -- Note the shorthand used here\n        have pf_B_iff_C := (iff.intro (λ(pfB: B), pf_C) (λ(pfC: C), pf_B)),\n        exact pf_B_iff_C__to_A pf_B_iff_C,\nend\n\n-- Transitive (exercise)\n-- Does (A ↔ B) → (B ↔ C) → (A ↔ C)?\nexample: ∀(A B C: Prop),\n  (A ↔ B) → (B ↔ C) → (A ↔ C) :=\nbegin\n  assume A B C,\n  assume pf_A_iff_B pf_B_iff_C,\n  split,\n    -- prove A → C\n    have pf_A_to_B := (iff.elim_left pf_A_iff_B),\n    have pf_B_to_C := (iff.elim_left pf_B_iff_C),\n    assume pf_A,\n    have pf_B := pf_A_to_B pf_A,\n    exact pf_B_to_C pf_B,\n    -- prove C → A\n    have pf_C_to_B := (iff.elim_right pf_B_iff_C),\n    have pf_B_to_A := (iff.elim_right pf_A_iff_B),\n    assume pf_C,\n    have pf_B := pf_C_to_B pf_C,\n    exact pf_B_to_A pf_B,\nend\n\n-- Connected\n-- Does (A ≠ B) → ((A ↔ B) ∨ (B ↔ A))?\n-- No\nexample: ¬∀(A B: Prop),\n  (A ≠ B) → ((A ↔ B) ∨ (B ↔ A)) :=\nbegin\n  assume pf_forall,\n  have pf_false_true := pf_forall false true,\n  have pf_false_neq_true: false ≠ true :=\n    begin\n      assume pf_false_is_true,\n      have t := true.intro,\n      have pf_true_is_false := eq.symm pf_false_is_true,\n      rewrite pf_true_is_false at t,\n      assumption,\n    end,\n  have pf_false_iff_true := pf_false_true pf_false_neq_true,\n  cases pf_false_iff_true,\n    -- false ↔ true\n    have pf_true_to_false := (iff.elim_right pf_false_iff_true),\n    exact pf_true_to_false true.intro,\n    -- true ↔ false\n    have pf_true_to_false := (iff.elim_left pf_false_iff_true),\n    exact pf_true_to_false true.intro,\nend\n\n-- Exercise\nexample: ∀(P Q: Prop),\n   P ∧ Q ↔ Q ∧ P :=\nbegin\n  assume P Q,\n  split,\n    -- P ∧ Q → Q ∧ P\n    assume pf_P_and_Q,\n    have pf_Q := pf_P_and_Q.right,\n    have pf_P := pf_P_and_Q.left,\n    exact and.intro pf_Q pf_P,\n    -- Q ∧ P → P ∧ Q\n    assume pf_Q_and_P,\n    have pf_P := pf_Q_and_P.right,\n    have pf_Q := pf_Q_and_P.left,\n    exact and.intro pf_P pf_Q,\nend\n\n-- Exercise\nlemma a_imp_b_imp_c_iff_a_and_b_imp_c:\n  ∀(A B C: Prop), A → B → C ↔ A ∧ B → C :=\nbegin\n  assume A B C,\n  split,\n    -- (A → B → C) → A ∧ B → C\n    assume pf_A_to_B_to_C,\n    assume pf_A_and_B,\n    have pf_A := pf_A_and_B.left,\n    have pf_B_to_C := pf_A_to_B_to_C pf_A,\n    have pf_B := pf_A_and_B.right,\n    exact pf_B_to_C pf_B,\n    -- (A ∧ B → C) → A → B → C \n    assume pf_A_and_B_to_C,\n    assume pf_A,\n    assume pf_B,\n    have pf_A_and_B := and.intro pf_A pf_B,\n    exact pf_A_and_B_to_C pf_A_and_B,\nend\n\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/examples/biimplication_properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7857859879853468}}
{"text": "/-\nCopyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Chambert-Loir, María Inés de Frutos-Fernández\n-/\nimport algebra.graded_monoid\nimport data.mv_polynomial.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 : σ → M`,\nwhere `σ` are the indeterminates.\n\nA multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials\noccuring in `φ` have the same weighted degree `m`.\n\n## Main definitions/lemmas\n\n* `weighted_total_degree' w φ` : 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 φ` : When `M` has a `⊥` 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 φ m`: a predicate that asserts that `φ` 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\nnoncomputable theory\n\nopen_locale classical big_operators\n\nopen set function finset finsupp add_monoid_algebra\n\nvariables {R M : Type*} [comm_semiring R]\n\nnamespace mv_polynomial\nvariables {σ : Type*}\n\nsection add_comm_monoid\nvariables [add_comm_monoid M]\n\n/-! ### `weighted_degree'` -/\n\n/-- The `weighted degree'` of the finitely supported function `s : σ →₀ ℕ` is the sum\n  `∑(s i)•(w i)`. -/\ndef weighted_degree' (w : σ → M) : (σ →₀ ℕ) →+ M :=\n(finsupp.total σ M ℕ w).to_add_monoid_hom\n\nsection semilattice_sup\nvariable [semilattice_sup M]\n\n/-- The weighted total degree of a multivariate polynomial, taking values in `with_bot M`. -/\ndef weighted_total_degree' (w : σ → M) (p : mv_polynomial σ R) : with_bot M :=\np.support.sup (λ s, weighted_degree' w s)\n\n/-- The `weighted_total_degree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/\nlemma weighted_total_degree'_eq_bot_iff (w : σ → M) (p : mv_polynomial σ R) :\n  weighted_total_degree' w p = ⊥ ↔ p = 0 :=\nbegin\n  simp only [weighted_total_degree',finset.sup_eq_bot_iff, mem_support_iff, with_bot.coe_ne_bot,\n    mv_polynomial.eq_zero_iff ],\n  exact forall_congr (λ _, not_not)\nend\n\n/-- The `weighted_total_degree'` of the zero polynomial is `⊥`. -/\nlemma weighted_total_degree'_zero (w : σ → M) :\n  weighted_total_degree' w (0 : mv_polynomial σ R) = ⊥ :=\nby simp only [weighted_total_degree', support_zero, finset.sup_empty]\n\nsection order_bot\nvariable [order_bot M]\n\n/-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate\n  polynomial as a function taking values in `M`. -/\ndef weighted_total_degree (w : σ → M) (p : mv_polynomial σ R) : M :=\np.support.sup (λ s, weighted_degree' w s)\n\n/-- This lemma relates `weighted_total_degree` and `weighted_total_degree'`. -/\nlemma weighted_total_degree_coe (w : σ → M) (p : mv_polynomial σ R) (hp : p ≠ 0):\n  weighted_total_degree' w p = ↑(weighted_total_degree w p) :=\nbegin\n  rw [ne.def, ← weighted_total_degree'_eq_bot_iff w p, ← ne.def, with_bot.ne_bot_iff_exists] at hp,\n  obtain ⟨m, hm⟩ := hp,\n  apply le_antisymm,\n  { simp only [weighted_total_degree, weighted_total_degree', finset.sup_le_iff,\n      with_bot.coe_le_coe],\n    intro b,\n    exact finset.le_sup },\n  { simp only [weighted_total_degree],\n    have hm' : weighted_total_degree' w p ≤ m := le_of_eq hm.symm,\n    rw ← hm,\n    simpa [weighted_total_degree'] using hm' }\nend\n\n/-- The `weighted_total_degree` of the zero polynomial is `⊥`. -/\nlemma weighted_total_degree_zero (w : σ → M) :\n  weighted_total_degree w (0 : mv_polynomial σ R) = ⊥ :=\nby simp only [weighted_total_degree, support_zero, finset.sup_empty]\n\nlemma le_weighted_total_degree (w : σ → M) {φ : mv_polynomial σ R} {d : σ →₀ ℕ}\n  (hd : d ∈ φ.support) : weighted_degree' w d ≤ φ.weighted_total_degree w :=\nle_sup hd\n\nend order_bot\nend semilattice_sup\n\n/-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials\n  occuring in `φ` have weighted degree `m`. -/\ndef is_weighted_homogeneous (w : σ → M) (φ : mv_polynomial σ R) (m : M) : Prop :=\n∀ ⦃d⦄, coeff d φ ≠ 0 → weighted_degree' w d = m\n\nvariable (R)\n\n/-- The submodule of homogeneous `mv_polynomial`s of degree `n`. -/\ndef weighted_homogeneous_submodule (w : σ → M) (m : M) :\n  submodule R (mv_polynomial σ R) :=\n{ carrier := { x | x.is_weighted_homogeneous w m },\n  smul_mem' := λ r a ha c hc, begin\n    rw coeff_smul at hc,\n    exact ha (right_ne_zero_of_mul hc),\n  end,\n  zero_mem' := λ d hd, false.elim (hd $ coeff_zero _),\n  add_mem' := λ a b ha hb c hc, begin\n    rw coeff_add at hc,\n    obtain h|h : coeff c a ≠ 0 ∨ coeff c b ≠ 0,\n    { contrapose! hc, simp only [hc, add_zero] },\n    { exact ha h },\n    { exact hb h },\n  end }\n\n@[simp] lemma mem_weighted_homogeneous_submodule (w : σ → M) (m : M) (p : mv_polynomial σ R) :\n  p ∈ weighted_homogeneous_submodule R w m ↔ p.is_weighted_homogeneous w m := iff.rfl\n\nvariables (R)\n\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 : (σ →₀ ℕ) →₀ R` such that\n  `p.support ⊆ {d | weighted_degree' w d = m}`. While equal, the former has a\n  convenient definitional reduction. -/\nlemma weighted_homogeneous_submodule_eq_finsupp_supported (w : σ → M) (m : M) :\n  weighted_homogeneous_submodule R w m =\n  finsupp.supported _ R {d | weighted_degree' w d = m} :=\nbegin\n  ext,\n  simp only [mem_supported, set.subset_def, finsupp.mem_support_iff, mem_coe],\n  refl,\nend\n\nvariables {R}\n\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`. -/\nlemma weighted_homogeneous_submodule_mul (w : σ → M) (m n : M) :\n  weighted_homogeneous_submodule R w m * weighted_homogeneous_submodule R w n ≤\n    weighted_homogeneous_submodule R w (m + n) :=\nbegin\n  rw submodule.mul_le,\n  intros φ hφ ψ hψ c hc,\n  rw [coeff_mul] at hc,\n  obtain ⟨⟨d, e⟩, hde, H⟩ := finset.exists_ne_zero_of_sum_ne_zero hc,\n  have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0,\n  { contrapose! H,\n    by_cases h : coeff d φ = 0;\n    simp only [*, ne.def, not_false_iff, zero_mul, mul_zero] at * },\n  rw [← (finsupp.mem_antidiagonal.mp hde), ← hφ aux.1, ← hψ aux.2, map_add],\nend\n\n/-- Monomials are weighted homogeneous. -/\nlemma is_weighted_homogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M}\n  (hm : weighted_degree' w d = m) : is_weighted_homogeneous w (monomial d r) m :=\nbegin\n  intros c hc,\n  rw coeff_monomial at hc,\n  split_ifs at hc with h,\n  { subst c, exact hm },\n  { contradiction }\nend\n\n/-- A polynomial of weighted_total_degree `⊥` is weighted_homogeneous of degree `⊥`. -/\nlemma is_weighted_homogeneous_of_total_degree_zero [semilattice_sup M] [order_bot M]\n  (w : σ → M) {p : mv_polynomial σ R} (hp : weighted_total_degree w p = (⊥ : M)) :\n  is_weighted_homogeneous w p (⊥ : M) :=\nbegin\n  intros d hd,\n  have h := weighted_total_degree_coe w p (mv_polynomial.ne_zero_iff.mpr ⟨d, hd⟩),\n  simp only [weighted_total_degree', hp] at h,\n  rw [eq_bot_iff, ← with_bot.coe_le_coe, ← h],\n  exact finset.le_sup (mem_support_iff.mpr hd),\nend\n\n/-- Constant polynomials are weighted homogeneous of degree 0. -/\nlemma is_weighted_homogeneous_C (w : σ → M) (r : R) :\n  is_weighted_homogeneous w (C r : mv_polynomial σ R) 0 :=\nis_weighted_homogeneous_monomial _ _ _ (map_zero _)\n\nvariables (R)\n\n/-- 0 is weighted homogeneous of any degree. -/\nlemma is_weighted_homogeneous_zero (w : σ → M) (m : M) :\n  is_weighted_homogeneous w (0 : mv_polynomial σ R) m :=\n(weighted_homogeneous_submodule R w m).zero_mem\n\n/-- 1 is weighted homogeneous of degree 0. -/\nlemma is_weighted_homogeneous_one (w : σ → M) :\n  is_weighted_homogeneous w (1 : mv_polynomial σ R) 0 :=\nis_weighted_homogeneous_C _ _\n\n/-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/\nlemma is_weighted_homogeneous_X (w : σ → M) (i : σ) :\n  is_weighted_homogeneous w (X i : mv_polynomial σ R) (w i) :=\nbegin\n  apply is_weighted_homogeneous_monomial,\n  simp only [weighted_degree', linear_map.to_add_monoid_hom_coe, total_single, one_nsmul],\nend\n\nnamespace is_weighted_homogeneous\nvariables {R} {φ ψ : mv_polynomial σ R} {m n : M}\n\n/-- The weighted degree of a weighted homogeneous polynomial controls its support. -/\nlemma coeff_eq_zero {w : σ → M} (hφ : is_weighted_homogeneous w φ n) (d : σ →₀ ℕ)\n  (hd : weighted_degree' w d ≠ n) : coeff d φ = 0 :=\nby { have aux := mt (@hφ d) hd, rwa not_not at aux }\n\n/-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/\nlemma inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : is_weighted_homogeneous w φ m)\n  (hn : is_weighted_homogeneous w φ n) : m = n :=\nbegin\n  obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ,\n  rw [← hm hd, ← hn hd]\nend\n\n/-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\nlemma add {w : σ → M} (hφ : is_weighted_homogeneous w φ n) (hψ : is_weighted_homogeneous w ψ n) :\n  is_weighted_homogeneous w (φ + ψ) n :=\n(weighted_homogeneous_submodule R w n).add_mem hφ hψ\n\n/-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\nlemma sum  {ι : Type*} (s : finset ι)  (φ : ι → mv_polynomial σ R) (n : M) {w : σ → M}\n  (h : ∀ i ∈ s, is_weighted_homogeneous w (φ i) n) :\n  is_weighted_homogeneous w (∑ i in s, φ i) n :=\n(weighted_homogeneous_submodule R w n).sum_mem h\n\n/-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted\n  homogeneous of weighted degree `m + n`. -/\nlemma mul {w : σ → M} (hφ : is_weighted_homogeneous w φ m) (hψ : is_weighted_homogeneous w ψ n) :\n  is_weighted_homogeneous w (φ * ψ) (m + n) :=\nweighted_homogeneous_submodule_mul w m n $ submodule.mul_mem_mul hφ hψ\n\n/-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree\n  equal to the sum of the weighted degrees. -/\nlemma prod {ι : Type*} (s : finset ι) (φ : ι → mv_polynomial σ R) (n : ι → M) {w : σ → M} :\n  (∀ i ∈ s, is_weighted_homogeneous w (φ i) (n i)) →\n  is_weighted_homogeneous w (∏ i in s, φ i) (∑ i in s, n i) :=\nbegin\n  apply finset.induction_on s,\n  { intro, simp only [is_weighted_homogeneous_one, finset.sum_empty, finset.prod_empty] },\n  { intros 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    intros j hjs,\n    exact h j (finset.mem_insert_of_mem hjs) }\nend\n\n/-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree\n  `n`. -/\nlemma weighted_total_degree [semilattice_sup M] {w : σ → M} (hφ : is_weighted_homogeneous w φ n)\n  (h : φ ≠ 0) : weighted_total_degree' w φ = n :=\nbegin\n  simp only [weighted_total_degree'],\n  apply le_antisymm,\n  { simp only [finset.sup_le_iff, mem_support_iff, with_bot.coe_le_coe],\n    exact λ d hd, le_of_eq (hφ hd), },\n  { obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h,\n    simp only [← hφ hd, finsupp.sum],\n    replace hd := finsupp.mem_support_iff.mpr hd,\n    exact finset.le_sup hd, }\nend\n\n/-- The weighted homogeneous submodules form a graded monoid. -/\ninstance weighted_homogeneous_submodule.gcomm_monoid {w : σ → M} :\n  set_like.graded_monoid (weighted_homogeneous_submodule R w) :=\n{ one_mem := is_weighted_homogeneous_one R w,\n  mul_mem := λ i j xi xj, is_weighted_homogeneous.mul }\n\nend is_weighted_homogeneous\n\nvariables {R}\n\n/-- `weighted_homogeneous_component w n φ` is the part of `φ` 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 `φ` is equal to the sum\n  of all its weighted homogeneous components. -/\ndef weighted_homogeneous_component (w : σ → M) (n : M) :\n  mv_polynomial σ R →ₗ[R] mv_polynomial σ R :=\n(submodule.subtype _).comp $ finsupp.restrict_dom _ _ {d | weighted_degree' w d = n}\n\nsection weighted_homogeneous_component\n\nvariables {w : σ → M} (n : M) (φ ψ : mv_polynomial σ R)\n\nlemma coeff_weighted_homogeneous_component (d : σ →₀ ℕ) :\n  coeff d (weighted_homogeneous_component w n φ) =\n    if weighted_degree' w d = n then coeff d φ else 0 :=\nfinsupp.filter_apply (λ d : σ →₀ ℕ, weighted_degree' w d = n) φ d\n\nlemma weighted_homogeneous_component_apply :\n  weighted_homogeneous_component w n φ =\n  ∑ d in φ.support.filter (λ d, weighted_degree' w d = n), monomial d (coeff d φ) :=\nfinsupp.filter_eq_sum (λ d : σ →₀ ℕ, weighted_degree' w d = n) φ\n\n/-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of\nweighted degree `n`. -/\nlemma weighted_homogeneous_component_is_weighted_homogeneous :\n  (weighted_homogeneous_component w n φ).is_weighted_homogeneous w n :=\nbegin\n  intros d hd,\n  contrapose! hd,\n  rw [coeff_weighted_homogeneous_component, if_neg hd]\nend\n\n@[simp] \n\nlemma weighted_homogeneous_component_eq_zero' (h : ∀ d : σ →₀ ℕ, d ∈ φ.support →\n  weighted_degree' w d ≠ n) : weighted_homogeneous_component w n φ = 0 :=\nbegin\n  rw [weighted_homogeneous_component_apply, sum_eq_zero],\n  intros d hd, rw mem_filter at hd,\n  exfalso, exact h _ hd.1 hd.2\nend\n\nlemma weighted_homogeneous_component_eq_zero [semilattice_sup M] [order_bot M]\n  (h : weighted_total_degree w φ < n) : weighted_homogeneous_component w n φ = 0 :=\nbegin\n  rw [weighted_homogeneous_component_apply, sum_eq_zero],\n  intros d hd, rw mem_filter at hd,\n  exfalso,\n  apply lt_irrefl n,\n  nth_rewrite 0 ← hd.2,\n  exact lt_of_le_of_lt (le_weighted_total_degree w hd.1) h,\nend\n\nlemma weighted_homogeneous_component_finsupp :\n  (function.support (λ m, weighted_homogeneous_component w m φ)).finite :=\nbegin\n  suffices : function.support (λ m, weighted_homogeneous_component w m φ) ⊆\n    (λ d, weighted_degree' w d) '' φ.support,\n  { exact finite.subset ((λ (d : σ →₀ ℕ), (weighted_degree' w) d) '' ↑(support φ)).to_finite this },\n  intros m hm,\n  by_contradiction hm', 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 φ hm',\nend\n\nvariable (w)\n\n/-- Every polynomial is the sum of its weighted homogeneous components. -/\nlemma sum_weighted_homogeneous_component :\n  finsum (λ m, weighted_homogeneous_component w m φ) = φ :=\nbegin\n  rw finsum_eq_sum _ (weighted_homogeneous_component_finsupp φ),\n  ext1 d,\n  simp only [coeff_sum, coeff_weighted_homogeneous_component],\n  rw finset.sum_eq_single (weighted_degree' w d),\n  { rw if_pos rfl, },\n  { intros m hm hm', rw if_neg hm'.symm, },\n  { intro hm, rw if_pos rfl,\n    simp only [finite.mem_to_finset, mem_support, ne.def, not_not] at hm,\n    have := coeff_weighted_homogeneous_component _ φ d,\n    rw [hm, if_pos rfl, coeff_zero] at this,\n    exact this.symm, },\nend\n\nvariable {w}\n\n/-- The weighted homogeneous components of a weighted homogeneous polynomial. -/\nlemma weighted_homogeneous_component_weighted_homogeneous_polynomial (m n : M)\n  (p : mv_polynomial σ R) (h : p ∈ weighted_homogeneous_submodule R w n) :\n  weighted_homogeneous_component w m p = if m = n then p else 0 :=\nbegin\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  { split_ifs,\n    all_goals { simp only [zero_coeff, coeff_zero], }, },\n  { rw h zero_coeff,\n    simp only [show n = m ↔ m = n, from eq_comm],\n    split_ifs with h1,\n    { refl },\n    { simp only [coeff_zero] } }\nend\n\nend weighted_homogeneous_component\n\nend add_comm_monoid\n\nsection canonically_ordered_add_monoid\n\nvariables [canonically_ordered_add_monoid M] {w : σ → M} (φ : mv_polynomial σ R)\n\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] lemma weighted_homogeneous_component_zero [no_zero_smul_divisors ℕ M]\n  (hw : ∀ i : σ, w i ≠ 0) : weighted_homogeneous_component w 0 φ = C (coeff 0 φ) :=\nbegin\n  ext1 d,\n  rcases em (d = 0) with (rfl|hd),\n  { simp only [coeff_weighted_homogeneous_component, if_pos, map_zero, coeff_zero_C] },\n  { rw [coeff_weighted_homogeneous_component, if_neg, coeff_C, if_neg (ne.symm hd)],\n    simp only [weighted_degree', linear_map.to_add_monoid_hom_coe, finsupp.total_apply,\n      finsupp.sum, sum_eq_zero_iff, finsupp.mem_support_iff, ne.def, smul_eq_zero,\n      not_forall, not_or_distrib, and_self_left, exists_prop],\n    simp only [finsupp.ext_iff, finsupp.coe_zero, pi.zero_apply, not_forall] at hd,\n    obtain ⟨i, hi⟩ := hd,\n    exact ⟨i, hi, hw i⟩ }\nend\n\nend canonically_ordered_add_monoid\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/weighted_homogeneous.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430803622103, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7857859867195622}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones:\n-- 1. Importar la teoría Definicion_de_funciones_acotadas\n-- 2. Habilitar la lógica clásica.\n-- 3. Declarar f como una variable de ℝ en ℝ.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_funciones_acotadas   -- 1\nopen_locale classical                      -- 2\nvariable (f : ℝ → ℝ)                       -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que si\n--    ¬ ∀ a, ∃ x, f x > a\n-- entonces f está acotada superiormente.\n-- ----------------------------------------------------------------------\n\nexample \n  (h : ¬ ∀ a, ∃ x, f x > a) \n  : fn_has_ub f :=\nbegin\n  push_neg at h,\n  exact h,\nend\n\n-- Prueba\n-- ======\n\n/-\nf : ℝ → ℝ,\nh : ¬∀ (a : ℝ), ∃ (x : ℝ), f x > a\n⊢ fn_has_ub f\n  >> push_neg at h,\nh : ∃ (a : ℝ), ∀ (x : ℝ), f x ≤ a\n⊢ fn_has_ub f\n  >> exact h,\nno goals\n-/\n\n-- Comentario. La táctica (push_neg at h) interioriza las negaciones de\n-- la hipótesis h.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que si f no tiene cota superior, entonces para\n-- cada a existe un x tal que f(x) > a.\n-- ----------------------------------------------------------------------\n\nexample \n  (h : ¬ fn_has_ub f) \n  : ∀ a, ∃ x, f x > a :=\nbegin\n  simp only [fn_has_ub, fn_ub] at h,\n  push_neg at h,\n  exact h,\nend\n\n-- Prueba\n-- ======\n\n/-\nf : ℝ → ℝ,\nh : ¬fn_has_ub f\n⊢ ∀ (a : ℝ), ∃ (x : ℝ), f x > a\n  >> simp only [fn_has_ub, fn_ub] at h,\nh : ¬∃ (a : ℝ), ∀ (x : ℝ), f x ≤ a\n⊢ ∀ (a : ℝ), ∃ (x : ℝ), f x > a\n  >> push_neg at h,\nh : ∀ (a : ℝ), ∃ (x : ℝ), a < f x\n⊢ ∀ (a : ℝ), ∃ (x : ℝ), f x > a\n  >> exact h,\nno goals\n-/\n\n-- Comentario: La táctica (simp only [h₁, ..., hₙ] at h) simplifica la\n-- hipótesis h usando sólo los lemas h₁, ..., hₙ. (Ver \n-- https://bit.ly/38O60EV)\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/CNS_de_acotada_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.8856314851380441, "lm_q1q2_score": 0.7857363325201908}}
{"text": "/- Let α be a type. We can represent a predicate p on α by an object of type\nα → Prop. Likewise an object r : α → a → Prop represent a binary relation\non α. The universal quantifier  ∀ x:α, p x denotes \"for every x of type α, the\nproposition p x is True.\" It is associated with elim/intro rules based on\nnatural deduction: given a proof of p x where x is arbitrary, then we have \n∀ x, p x. Likewise, given a proof ∀ x, p x, if t:α, then we have a proof of p t.\n\nIn the calculus of constructions, ∀ x, p x ↔ x:α → p x, so proving a universal\nquantifier is really just constructing an ordinary function (albeit between\ndependent function spaces).  -/\n\nexample (α : Type) (p q : α → Prop) : (∀ x : α, p x ∧ q x) → ∀ y : α, p y :=\n  fun h : ∀ x : α, p x ∧ q x =>\n    fun y : α =>\n      show p y from (h y).left\n\n-- I prefer the more functional way:\nexample (α : Type) (p q : α → Prop) (proof : ((x : α) → p x ∧ q x)) \n  : ((y : α) → p y) :=\n    (fun y:α => (proof y).left)\n\n-- Another example, expressing that a relation is transitive:\n\nvariable (α : Type) (r : α → α → Prop)\nvariable (trans_r : ∀ x y z, r x y → r y z → r x z)\n\nvariable (a b c : α)\nvariable (hab : r a b) (hbc : r b c)\n\n#check trans_r    -- ∀ (x y z : α), r x y → r y z → 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\nvariable (α : Type) (r : α → α → Prop)\n\nvariable (refl_r : ∀ x, r x x)\nvariable (symm_r : ∀ {x y}, r x y → r y x)\nvariable (trans_r : ∀ {x y z}, r x y → r y z → r x z)\n\nexample (a b c d : α) (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\n-- Equality --\n\n-- Equality in Lean is an equivalence relation:\n\n#check Eq.refl\n#check Eq.symm\n#check Eq.trans\n\n-- The output is ugly because Lean is throwing in implicit metavariables. We can\n-- clean it up by making things more explicit:\n\nuniverse u\n-- The inscription .{u} tells Lean to instantiate the constants at the universe u.\n#check @Eq.refl.{u}\n#check @Eq.symm.{u}\n#check @Eq.trans.{u}\n\n-- In particular this means we can specialize the above example to equality:\n\nvariable (α : Type) (a b c d : α)\nvariable (hab : a = b) (hcb : c = b) (hcd : c = d)\n\nexample : a = d :=\n  Eq.trans (Eq.trans hab (Eq.symm hcb)) hcd\n\n-- We can also use the projection relations (NL - ??? Just properties I guess.)\n\nexample : a = d := (hab.trans hcb.symm).trans hcd\n\n/- Since all terms in CoC have computational interpretation and Lean treats all\nCoC-equivalent objects as equal reflexivity can be used to prove nontrivial\nidentities: -/\n\nvariable (α β : Type)\n\nexample (f : α→β) (a:α) : (fun x => f x) a = f a := Eq.refl _ -- really Eq.refl (f a)\nexample (a:α) (b:α) : (a,b).1 = a := Eq.refl _\nexample : 2 + 3 = 5 := Eq.refl _\n\n-- The library defines the shortcut \"rfl\" for Eq.refl _\n\nexample : 5 + 4 = 9 := rfl\n\n/- One important structure equality has distinguishing it from other equivalence\nrelations is that every assertion respects the equivalence: given hxy : x = y and\nhpx : p x, we have a proof of p y using substitution: -/\n\nexample (α:Type) (a b : α) (p: α -> Prop) (h1 : a = b) (h2 : p a) : p b :=\n  Eq.subst h1 h2\n\nexample (α : Type) (a b : α) (p : α → Prop)\n    (h1 : a = b) (h2 : p a) : p b :=\n      h1 ▸ h2 -- ▸ is a macro for applying Eq.symm and Eq.subst, by typing `\\t`.\n\n/- There are auxillary rules defined with Eq.subst: congrArg can be used to \nreplace the argument, congrFun can be used to replace the term that is being \napplied, and congr can be used to replace both at once: -/\n\nvariable (α : Type)\nvariable (a b : α)\nvariable (f g : α → Nat)\nvariable (h₁ : a = b)\nvariable (h₂ : f = g)\n\nexample : f a = f b := congrArg f h₁\nexample : f a = g a := congrFun h₂ a\nexample : f a = g b := congr h₂ h₁\n\nvariable (a b c d : Nat)\n\nexample : a + 0 = a := Nat.add_zero a\nexample : 0 + a = a := Nat.zero_add a\nexample : a * 1 = a := Nat.mul_one a\nexample : 1 * a = a := Nat.one_mul a\nexample : a + b = b + a := Nat.add_comm a b\nexample : a + b + c = a + (b + c) := Nat.add_assoc a b c\nexample : a * b = b * a := Nat.mul_comm a b\nexample : a * b * c = a * (b * c) := Nat.mul_assoc a b c\nexample : a * (b + c) = a * b + a * c := Nat.mul_add a b c\nexample : a * (b + c) = a * b + a * c := Nat.left_distrib a b c\nexample : (a + b) * c = a * c + b * c := Nat.add_mul a b c\nexample : (a + b) * c = a * c + b * c := Nat.right_distrib a b c\n\nexample (x y z : Nat) : x * (y + z) = x * y + x * z := Nat.mul_add x y z\nexample (x y z : Nat) : (x + y) * z = x * z + y * z := Nat.add_mul x y z\nexample (x y z : Nat) : x + y + z = x + (y + z) := Nat.add_assoc x y z\n\nexample (x y : Nat) : (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n  let pf1 : (x + y) * (x + y) = (x + y) * x + (x + y) * y\n    := Nat.mul_add (x + y) x y\n  let pf2 : (x + y) * (x + y) = x * x + y * x + (x * y + y * y) := \n    (Nat.add_mul x y x) ▸ (Nat.add_mul x y y ) ▸ pf1 \n  pf2.trans (Nat.add_assoc (x*x + y*x) (x*y) (y*y)).symm\n\n/- Note the signature for subst:\nEq.subst : ∀ {α : Sort u} {motive : α → Prop} {a b : α}, \n  a = b → motive a → motive b\n\nIf motive is implicit then Lean often has trouble figuring out what it is - \nit is an instance of the higher-order unification problem which is in fact\nundecidable. The macro ▸ uses certain heuristics behind the scenes and often\nsucceeds when Eq.subst fails. \n-/\n\n\n\n-- Exercises --\n\n-- 1. Prove these equivalences:\n\n variable (α : Type) (p q : α → Prop)\n\n example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := \n  ⟨fun pfpaq => ⟨fun x => (pfpaq x).1,fun x => (pfpaq x).2⟩,\n  fun ⟨pfp,pfq⟩ => fun x => ⟨pfp x,pfq x⟩⟩\n\n example : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := fun f =>\n  fun fp => (fun px => (f px) (fp px))\n \n example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := fun pOr =>\n  Or.elim pOr (fun forallP => (fun px => Or.inl (forallP px))) (fun forallQ => (fun px => Or.inr (forallQ px)))\n\n/-2. It is often possible to bring a component of a formula outside a universal \nquantifier, when it does not depend on the quantified variable. Try proving \nthese (one direction of the second of these requires classical logic):-/\n\nvariable (α : Type) (p q : α → Prop)\nvariable (r : Prop)\nopen Classical\n\nexample : α → ((∀ x : α, r) ↔ r) := fun a =>\n  ⟨fun pxr => pxr a, fun pXr => (fun pX => pXr)⟩\n\nexample : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r := \n  ⟨fun pXO => byContradiction (fun contra => \n                                -- need to rewrite the contradition to ¬(∀ x, px) ∧ ¬ r,\n                                -- then use Or.elim to get the contradiction\n                                let ⟨rwp,rwr⟩ : ¬(∀ x, p x) ∧ ¬ r := sorry\n                                sorry),\n   fun ppOR => Or.elim ppOR \n                       (fun fX => (fun pX => Or.inl (fX pX))) \n                       (fun fR => fun fX => Or.inr fR)⟩ \n\nexample : (∀ x, r → p x) ↔ (r → ∀ x, p x) := \n  ⟨fun pf => (fun pR => (fun pX => (pf pX) pR)),\n   fun pf => fun pX => fun pR => (pf pR) pX⟩ \n\n/- 3. Consider the \"barber paradox,\" that is, the claim that in a certain town \nthere is a (male) barber that shaves all and only the men who do not shave \nthemselves. Prove that this is a contradiction: -/\n\nvariable (men : Type) (barber : men)\nvariable  (shaves : men → men → Prop)\n\n-- presumably this is in the standard library...\ntheorem noSelfCont {p:Prop} : ¬(p ↔ ¬p) := \n  fun ⟨c,d⟩ => \n    let r := (fun hp:p => (c hp) hp)\n    r (d r)\n\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : False := \n  noSelfCont (h barber)\n\n/- 4. Remember that, without any parameters, an expression of type Prop is just \nan assertion. Fill in the definitions of prime and Fermat_prime below, and \nconstruct each of the given assertions. -/\n\ndef even (n : Nat) : Prop := n % 2 = 0\n\ndef prime (n : Nat) : Prop := ∀a b, a*b=n → a = 1 ∨ b = 1\n\ndef infinitely_many_primes : Prop := ∀ n:Nat, prime n → ∃ k, prime k ∧ k > n\n\ndef Fermat_prime (n : Nat) : Prop := prime n ∧ ∃ k, n = (Nat.pow 2 k) + 1\n\ndef infinitely_many_Fermat_primes : Prop :=\n   ∀ n:Nat, Fermat_prime n → ∃ k, Fermat_prime k ∧ k > n\n\ndef goldbach_conjecture : Prop := \n  ∀ n:Nat, even n ∧ n > 2 -> ∃ k j, prime k ∧ prime j ∧ n = k+j\n\ndef Goldbach's_weak_conjecture : Prop := \n  ∀ n:Nat, (¬(even n)) ∧ n > 5 -> ∃ j k l, prime k ∧ prime j ∧ prime l ∧ n = k+j+l\n\ndef Fermat's_last_theorem : Prop := \n  ∀ a b c n :Nat, (Nat.pow a n) + (Nat.pow b n) = (Nat.pow c n) -> n = 1 ∨ n = 2\n\n/- 5. Prove as many of the identities listed in the Existential Quantifier \nsection as you can. We also leave it to you to determine which are \nnonconstructive, and hence require some form of classical reasoning.-/\n\nopen Classical\n\nvariable (α : Type) (p q : α → Prop)\nvariable (r : Prop)\n\nexample : (∃ x : α, r) → r := \n  fun pf => Exists.elim pf (fun _ => (fun prf => prf))\n\nexample (a : α) : r → (∃ x : α, r) := \n  fun prf => Exists.intro a prf\n\nexample : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := \n  ⟨fun prf => Exists.elim prf (fun y => fun ⟨py,pr⟩ => ⟨Exists.intro y py,pr⟩),\n   fun ⟨pxPx,pr⟩ => Exists.elim pxPx (fun y => fun px => Exists.intro y ⟨px, pr⟩)⟩\n\nexample : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := \n  ⟨fun prf => Exists.elim prf (fun y => \n    fun pf => Or.elim pf (fun py => Or.inl (Exists.intro y py)) \n                          (fun pq => Or.inr (Exists.intro y pq))),\n   fun prf => Or.elim prf \n                (fun pp => Exists.elim pp (fun y => fun pf => \n                                            (Exists.intro y (Or.inl pf))))\n                (fun pq => Exists.elim pq (fun y => fun pf => \n                                            (Exists.intro y (Or.inr pf))))⟩   \n\n-- Pretty sure ← requires classical reasoning.\nexample : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := \n  ⟨fun pf => fun ePf => Exists.elim ePf (fun y => fun c => c (pf y)),\n   fun contra => fun y => sorry⟩ \n\n-- Pretty sure ← requires classical reasoning.\nexample : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := \n  ⟨fun pf => Exists.elim pf (fun y => fun pr => (fun ow => (ow y) pr)),\n  fun contra => \n    byCases\n      (fun hp:  ∃ x, p x => hp)\n      (fun hnp => sorry)⟩  \n\nexample : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := \n  ⟨fun prf => (fun x => fun (pr:p x) => prf (Exists.intro x pr)),\n  fun prf => (fun ePf => Exists.elim ePf (fun y => fun pf => (prf y) pf))⟩ \n\nexample : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := \n  ⟨fun contra => Exists.intro sorry sorry,\n   fun prf => fun contra => Exists.elim prf (fun y => fun c => c (contra y))⟩   \n\nexample : (∀ x, p x → r) ↔ (∃ x, p x) → r := \n  ⟨fun prf => fun ePrf => Exists.elim ePrf prf,\n   fun prf => fun y => sorry⟩   \n\nexample (a : α) : (∃ x, p x → r) ↔ (∀ x, p x) → r := \n  ⟨fun pf => fun allPf => Exists.elim pf sorry,\n   fun pf => sorry⟩ \n\nexample (a : α) : (∃ x, r → p x) ↔ (r → ∃ x, p x) := sorry", "meta": {"author": "nicklecompte", "repo": "LeanLearning", "sha": "cb1a51f159569194b951441bb1940650e09ccc34", "save_path": "github-repos/lean/nicklecompte-LeanLearning", "path": "github-repos/lean/nicklecompte-LeanLearning/LeanLearning-cb1a51f159569194b951441bb1940650e09ccc34/src/QuantifiersAndEquality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8856314738181875, "lm_q1q2_score": 0.7857363066293399}}
{"text": "-- #4\n\nimport data.nat.basic\nimport data.nat.pow\n\n#check pow\n#check pow 2 3\n#check 2 ^ 3\n\n#check even\n\ndef prime (n : ℕ) : Prop := \nn > 1 ∧ ∀ a b : ℕ, n = a * b → a = 1 ∧ b = n ∨ a = n ∧ b = 1\n\ndef infinitely_many_primes : Prop := ∀ n : ℕ, ∃ p : ℕ, prime p ∧ p > n\n\ndef two_pow : ℕ → ℕ\n| 0 := 1\n| (n + 1) := 2 * two_pow n\n\ndef two_pow' (n : ℕ) : ℕ := 2 ^ n\n\ndef pow' (b n : ℕ ) : ℕ := b ^ n\n\n#eval 2 ^ 3\n#eval 0 ^ 3\n#eval 3 ^ 0\n#eval 0 ^ 0\n\ndef Fermat_number (n : ℕ) : ℕ := 2 ^ (2 ^ n) + 1\n\ndef Fermat_prime (n : ℕ) : Prop := prime n ∧ ∃ m : ℕ, n = Fermat_number m\n\ndef infinitely_many_Fermat_primes : Prop := ∀ n : ℕ, ∃ m : ℕ, m > n ∧ Fermat_prime m\n\ndef goldbach_conjecture : Prop :=\n∀ n : ℕ, even n ∧ n > 2 → ∃ a b : ℕ, prime a ∧ prime b ∧ n = a + b\n\ndef Goldbach's_weak_conjecture : Prop :=\n∀ n : ℕ, odd n ∧ n > 5 → ∃ a b c : ℕ, prime a ∧ prime b ∧ prime c ∧ n = a + b + c \n\ndef Fermat's_last_theorem : Prop :=\n∀ x y z n : ℕ, x > 0 ∧ y > 0 ∧ n > 1 ∧ x ^ n + y ^ n = z ^ n → n = 2\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/04-Quantifiers-and-Equality/example-4.6-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109770159683, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7857159598555882}}
{"text": "namespace nat\n\n/-\n  Part 1. Summation.\n-/\n-- define summation up to (but not including) n\ndef sum_upto (n : ℕ) (f : ℕ → ℕ) : ℕ :=\nnat.rec_on n 0 (λ n recval, recval + f n)\n\n-- the computation rules\ntheorem sum_upto_zero (f : ℕ → ℕ) : sum_upto 0 f = 0 := rfl\ntheorem sum_upto_succ (f : ℕ → ℕ) (n : ℕ) : sum_upto (succ n) f = sum_upto n f + f n := rfl\n\n-- fill in the next two proofs\ntheorem sum_upto_mul (n m : ℕ) (f : ℕ → ℕ) : sum_upto n (λ x, m * f x) = m * (sum_upto n f) :=\nnat.induction_on n rfl \n(take n,\n assume ih: sum_upto n (λ x, m * f x) = m * (sum_upto n f),\n show sum_upto (succ n) (λ x, m * f x) = m * (sum_upto (succ n) f), from\ncalc\n  sum_upto (succ n) (λ x, m * f x) = sum_upto n (λ x, m * f x) + (λ x, m * f x) n : by rw sum_upto_succ\n          ...                      = m * (sum_upto n f) + (λ x, m * f x) n        : by rw ih\n          ...                      = m * (sum_upto n f) + m * ((λ x, f x ) n)     : rfl\n          ...                      = m * (sum_upto n f + (λ x, f x) n)            : by rw mul_add\n          ...                      = m * (sum_upto n f + f n)                     : rfl\n          ...                      = m * (sum_upto (succ n) f)                    : by rw sum_upto_succ)\n\ntheorem sum_upto_id (n : ℕ) : 2 * sum_upto (succ n) id = n * (n + 1) :=\nnat.induction_on n rfl\n(take n,\n  assume ih: 2 * sum_upto (succ n) id = n * (n + 1),\n  show 2 * sum_upto (succ (succ n)) id = (succ n) * ((succ n) + 1), from\n  calc \n    2 * sum_upto (succ (succ n)) id = 2 * (sum_upto (succ n) id + id (succ n)) : by rw sum_upto_succ\n            ...                     = 2 * (sum_upto (succ n) id) + 2 * id(succ n) : by rw mul_add\n            ...                     = n * (n + 1) + 2 * id (succ n)          : by rw ih\n            ...                     = n * (n + 1) + 2 * (succ n)             : rfl\n            ...                     = n * (succ n) + 2 * (succ n)            : rfl\n            ...                     = (succ n) * n + 2 * (succ n)            : by rw mul_comm\n            ...                     = (succ n) * n + (succ n) * 2            : by simp --by rw mul_comm\n            ...                     = (succ n) * (n + 2)                     : by rw mul_add \n            ...                     = (succ n) * (n + 1 + 1)                 : rfl\n            ...                     = (succ n) * ((succ n) + 1)              : rfl)\n\n/-\n   Part 2. Exponentiation on nat.\n-/\n\n-- the definition\ndef pow : ℕ → ℕ → ℕ\n| m 0 := 1\n| m (succ n) := m * pow m n\n\n-- declare the notation\ninfix ^ := pow\n\n-- the computation rules\ntheorem pow_zero (m : ℕ) : m ^ 0 = 1 := rfl\ntheorem pow_succ (m n : ℕ) : m ^ (succ n) = m * m ^ n := rfl\n\n-- fill in the next four proofs\ntheorem zero_pow_succ (n : ℕ) : 0^(succ n) = 0 := \nnat.induction_on n rfl \n( take n,\n  assume ih,\n  show 0^(succ (succ n)) = 0, from \n  calc\n      0^(succ (succ n)) = 0 * 0^(succ n)  : by rw pow_succ\n          ...           = 0 * 0           : by rw ih\n          ...           = 0               : by rw mul_zero)\n\ntheorem pow_add (m n k : ℕ) : m ^ (n + k) = m ^ n * m ^ k :=\nnat.induction_on n \n  (calc \n      m ^ (0 + k) = m ^ k         : by rw zero_add\n          ...     = 1 * m ^ k     : by rw one_mul\n          ...     = m ^ 0 * m ^ k : rfl) \n  (take n,\n    assume ih,\n    show m ^ ((succ n) + k) = m ^ (succ n) * m ^ k, from \n    calc\n     m ^ ((succ n) + k) = m ^ ((n + 1) + k)    : rfl\n          ...          = m ^ (k + (n + 1))    : by rw add_comm\n          ...          = m ^ ((k + n) + 1)    : by rw add_assoc\n          ...          = m ^ ((n + k) + 1)    : by simp\n          ...          = m ^ (succ (n + k))   : rfl\n          ...          = m * m ^ (n + k)      : by rw pow_succ\n          ...          = m * (m ^ n * m ^ k)  : by rw ih\n          ...          = (m * m ^ n) * m ^ k  : by rw mul_assoc\n          ...          = m ^ (succ n) * m ^ k : by rw pow_succ)\n\n\ntheorem pow_mul (m n k : ℕ) : m ^ (n * k) = (m ^ n) ^ k :=\nnat.induction_on k \n(calc\n  m ^ (n * 0) = m ^ (0)     : by rw mul_zero\n      ...     = 1           : by rw pow_zero\n      ...     = (m ^ n) ^ 0 : by rw pow_zero) \n(take k,\n assume ih,\n show  m ^ (n * (succ k)) = (m ^ n) ^ (succ k), from \n calc\n      m ^ (n * (succ k)) = m ^ (n * (k + 1))      : rfl\n            ...          = m ^ (n * k + n * 1)    : by rw mul_add\n            ...          = m ^ (n * k) * m ^ (n * 1) : sorry\n            ...          = (m ^ n) ^ k * m ^ (n * 1) : by rw ih\n            ...          = (m ^ n) ^ k * (m ^ n) : by rw mul_one\n            ...          = (m ^ n) * (m ^ n) ^ k : by rw mul_comm\n            ...          = (m ^ n) ^ (succ k)     : by rw pow_succ)\n\ncheck zero_lt_one\ncheck @mul_pos\n\ntheorem pow_pos {m : ℕ} (h : m > 0) {n : ℕ} : m^n > 0 :=\nnat.induction_on n \n( have H1: m^0 = 1, from rfl, \n  show m^0 > 0, from zero_lt_one)\n( take n,\n  assume ih,\n  have H1: m^ (succ n) = m * m^n, from rfl,\n  show m^(succ n) > 0, from mul_pos h ih)\n\n/- The last one is pow_le, below. It is not easy, so just give it your best\n   shot. The next few examples might be helpful. -/\n\n-- By the way, this is a useful trick. I will explain it in class.\nexample : 3 < 7 := dec_trivial\n\ncheck @mul_le_mul\ncheck @mul_le_mul_left\ncheck @nat.zero_le\n\nexample (m : ℕ) (h : m > 0) : m ≥ 1 := succ_le_of_lt h\n-- actually, on ℕ, x < y is defined to mean succ x < y\nexample (m : ℕ) (h : m > 0) : m ≥ 1 := h\n\nexample (m n : ℕ) (h : m ≤ n) : ∃ k, m + k = n := le.dest h\n\nlemma le_mul_self (m n : ℕ) (h : m = 0 ∨ n > 0) : m ≤ m * n :=\nor.elim h\n  (suppose m = 0,\n    begin simp [this] end)\n  (suppose n > 0,\n    have m * 1 ≤ m * n,\n      from mul_le_mul_left _ this,\n    begin\n      rw mul_one at this, exact this\n    end)\ncheck @mul_le_mul_left\n-- Be careful! The following theorem is false without the hypotheses m > 0 (why?)\ntheorem pow_le (m : ℕ) {n k : ℕ} (h : n ≤ k) (mpos : m > 0) : m^n ≤ m^k :=\nhave H1: m*n ≤ m*k, from (mul_le_mul_left m h),\nsorry\n--Are you supposed to use induction? Because I couldn't figure out what I \n--was supposed to induct on.\n--Without induction, I do not know how to expand m ^ n since ^ is defined for\n--m ^ succ n\n\n\ncheck le_of_eq\n\n/-\n  Part 3. Division on the Natural Numbers.\n\n  These have nothing to do with inductive types (except for the fact that\n  the existential quantifier is really an inductive type).\n-/\n\nprotected def dvd (m n : ℕ) : Prop := ∃ k, n = m * k\n\ninstance : has_dvd nat := ⟨nat.dvd⟩\n\n-- type \"dvd\" with \\|\n\ntheorem dvd_rfl (m : ℕ) : m ∣ m :=\nexists.intro 1 (by rw [(mul_one m)])\n\ntheorem dvd_trans : ∀ {m n k : ℕ}, m ∣ n → n ∣ k → m ∣ k :=\ntake m n k,\nassume h1 h2,\nhave H1: ∃ a, n = m * a, from h1,\nhave H2: ∃ b, k = n * b, from h2,\nexists.elim H1\n(take a,\n  assume H3: n = m * a,\n  exists.elim H2 \n  (take b,\n    assume H4: k = n * b,\n    show ∃ c, k = m * c, from \n      (have H5: k = m * a * b, from (by rw [-H3, H4]), \n       have H6: k = m * (a * b), from (by rw [H5, mul_assoc]),\n      exists.intro (a * b) H6)))\n\n\ntheorem dvd_mul_left (m n : ℕ) : m ∣ m * n :=\nhave H1: m ∣ m, from (dvd_rfl m),\nhave H2: ∃ a, m = m * a, from H1,\nexists.elim H2\n(take a,\n  assume H3: m = m * a,\n  have H4: m * n = m * a * n, from (by rw [-H3]),\n  have H5: m * n = m * (a * n), from (by rw [H4, mul_assoc]),\n  show m ∣ m * n , from exists.intro (a * n) H5)\n\ntheorem dvd_mul_right (m n : ℕ) : m ∣ n * m :=\nhave H1: m ∣ m * n, from (dvd_mul_left m n),\nhave H2: ∃ a, m * n = m * a, from H1,\nexists.elim H2 \n(take a,\n  assume H3: m * n = m * a,\n  have H4: n * m = m * a, from (by rw [-H3, mul_comm]),\n  show m ∣ n * m, from exists.intro a H4) \n\ntheorem dvd_add : ∀ {m n k : ℕ}, m ∣ n → m ∣ k → m ∣ (n + k) :=\ntake m n k,\ntake h₁ h₂,\nhave H1: ∃ a, n = m * a, from h₁,\nhave H2: ∃ b, k = m * b, from h₂,\nexists.elim H1\n(take a,\n  assume H3: n = m * a,\n  exists.elim H2 \n  (take b,\n   assume H4: k = m * b,\n   have H5: n + k = m * (a + b), from (by rw [H3, H4, mul_add]),\n   show m ∣ (n + k), from exists.intro (a + b) H5))\n\nend nat\n\n/-\n  Part 4. The size of a binary tree.\n\n  This one is really optional, for those of you who said you want something\n  more challenging.\n-/\n\nopen nat\n\ninductive btree : Type\n| leaf : btree\n| node : btree → btree → btree\n\nnamespace btree\n\ndef size : btree → ℕ\n| leaf := 1\n| (node b₁ b₂) := size b₁ + size b₂ + 1\n\ntheorem size_pos (b : btree) : size b > 0 :=\nbtree.induction_on b\n  dec_trivial\n  (take b₁ b₂,\n    assume ih₁ ih₂,\n     succ_pos _)\n\ndef depth : btree → ℕ\n| leaf := 1\n| (node b₁ b₂) := max (depth b₁) (depth b₂) + 1\n\n-- This is a scandal. I promise, eventually the simplifier will do this.\nlemma add_self_eq_two_mul (m : ℕ) : m + m = 2 * m :=\ncalc\n  m + m = (1 + 1) * m : by simp [add_mul, one_mul]\n    ... = 2 * m       : rfl\n\n-- these might be useful.\ncheck @nat.sub_add_cancel\ncheck @nat.add_sub_assoc\n\n-- prove this by induction on binary trees\ntheorem size_le' : ∀ b : btree, size b + 1 ≤ 2 ^ depth b :=\ntake b,\nbtree.induction_on b \ndec_trivial \n(take b₁ b₂,\n assume ih₁ ih₂,\n have H1: (size b₁ + 1) + (size b₂ + 1) ≤ (2 ^ depth b₁) + (2 ^ depth b₂), from (add_le_add ih₁ ih₂), \n have H2: 2 ^ (max (depth b₁) (depth b₂) + 1) = 2 ^ depth (node b₁ b₂), from rfl,\n have H3:  2 ^ (max (depth b₁) (depth b₂) + 1) ≤ 2 ^ depth (node b₁ b₂), from (le_of_eq H2),\n calc\n    size (node b₁ b₂) + 1 = (size b₁ + size b₂ + 1) + 1 : rfl\n          ...             = (size b₁ + 1) + (size b₂ + 1) : by simp\n          ...             ≤ (2 ^ depth b₁) + (2 ^ depth b₂) : H1\n          ...             ≤ 2 ^ (max (depth b₁) (depth b₂) + 1) : sorry\n          ...             = 2 ^ depth (node b₁ b₂) : rfl\n          ...             ≤ 2 ^ depth (node b₁ b₂) : H3)\ncheck @add_le_add\n\n\ntheorem size_le : ∀ b : btree, size b ≤ 2 ^ depth b - 1:=\ntake b,\nhave size b = size b + 1 - 1, from rfl,\ncalc\n  size b = size b + 1 - 1 : this\n     ... ≤ 2 ^ depth b - 1 : nat.sub_le_sub_right (size_le' b) _\n\nend btree\n", "meta": {"author": "mtegene", "repo": "homework-mtegene-master", "sha": "5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5", "save_path": "github-repos/lean/mtegene-homework-mtegene-master", "path": "github-repos/lean/mtegene-homework-mtegene-master/homework-mtegene-master-5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5/homework3/solutions3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220294, "lm_q2_score": 0.8824278680004706, "lm_q1q2_score": 0.7856204358499912}}
{"text": "import .love10_denotational_semantics_demo\n\n\n/-! # LoVe Exercise 10: Denotational Semantics -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Question 1: Monotonicity\n\n1.1. Prove the following lemma from the lecture. -/\n\nlemma monotone_comp {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nsorry\n\n/-! 1.2. Prove its cousin. -/\n\nlemma monotone_restrict {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nsorry\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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing {} : regex\n| empty {}   : regex\n| atom       : α → regex\n| concat     : regex → regex → regex\n| alt        : regex → regex → regex\n| star       : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n-- enter the missing cases here\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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": "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/love10_denotational_semantics_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7856060658533439}}
{"text": "/-\nCopyright (c) 2019 Chris Hughes. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Hughes, Anne Baanen\n-/\nimport linear_algebra.dimension\n\n/-!\n# Finite dimension of vector spaces\n\nDefinition of the rank of a module, or dimension of a vector space, as a natural number.\n\n## Main definitions\n\nDefined is `finite_dimensional.finrank`, the dimension of a finite dimensional space, returning a\n`nat`, as opposed to `module.rank`, which returns a `cardinal`. When the space has infinite\ndimension, its `finrank` is by convention set to `0`.\n\nThe definition of `finrank` does not assume a `finite_dimensional` instance, but lemmas might.\nImport `linear_algebra.finite_dimensional` to get access to these additional lemmas.\n\nFormulas for the dimension are given for linear equivs, in `linear_equiv.finrank_eq`\n\n## Implementation notes\n\nMost results are deduced from the corresponding results for the general dimension (as a cardinal),\nin `dimension.lean`. Not all results have been ported yet.\n\nYou should not assume that there has been any effort to state lemmas as generally as possible.\n-/\n\nuniverses u v v' w\nopen_locale classical cardinal\n\nopen cardinal submodule module function\n\nvariables {K : Type u} {V : Type v}\n\nnamespace finite_dimensional\n\nopen is_noetherian\n\nsection division_ring\n\nvariables [division_ring K] [add_comm_group V] [module K V]\n{V₂ : Type v'} [add_comm_group V₂] [module K V₂]\n\n/-- The rank of a module as a natural number.\n\nDefined by convention to be `0` if the space has infinite rank.\n\nFor a vector space `V` over a field `K`, this is the same as the finite dimension\nof `V` over `K`.\n-/\nnoncomputable def finrank (R V : Type*) [semiring R]\n  [add_comm_group V] [module R V] : ℕ :=\n(module.rank R V).to_nat\n\nlemma finrank_eq_of_dim_eq {n : ℕ} (h : module.rank K V = ↑ n) : finrank K V = n :=\nbegin\n  apply_fun to_nat at h,\n  rw to_nat_cast at h,\n  exact_mod_cast h,\nend\n\nlemma finrank_le_of_dim_le {n : ℕ} (h : module.rank K V ≤ ↑ n) : finrank K V ≤ n :=\nbegin\n  rwa [← cardinal.to_nat_le_iff_le_of_lt_aleph_0, to_nat_cast] at h,\n  { exact h.trans_lt (nat_lt_aleph_0 n) },\n  { exact nat_lt_aleph_0 n },\nend\n\nlemma finrank_lt_of_dim_lt {n : ℕ} (h : module.rank K V < ↑ n) : finrank K V < n :=\nbegin\n  rwa [← cardinal.to_nat_lt_iff_lt_of_lt_aleph_0, to_nat_cast] at h,\n  { exact h.trans (nat_lt_aleph_0 n) },\n  { exact nat_lt_aleph_0 n },\nend\n\nlemma dim_lt_of_finrank_lt {n : ℕ} (h : n < finrank K V) : ↑n < module.rank K V :=\nbegin\n  rwa [← cardinal.to_nat_lt_iff_lt_of_lt_aleph_0, to_nat_cast],\n  { exact nat_lt_aleph_0 n },\n  { contrapose! h,\n    rw [finrank, cardinal.to_nat_apply_of_aleph_0_le h],\n    exact n.zero_le },\nend\n\n/-- If a vector space has a finite basis, then its dimension is equal to the cardinality of the\nbasis. -/\nlemma finrank_eq_card_basis {ι : Type w} [fintype ι] (h : basis ι K V) :\n  finrank K V = fintype.card ι :=\nfinrank_eq_of_dim_eq (dim_eq_card_basis h)\n\n/-- If a vector space has a finite basis, then its dimension is equal to the cardinality of the\nbasis. This lemma uses a `finset` instead of indexed types. -/\nlemma finrank_eq_card_finset_basis {ι : Type w} {b : finset ι}\n  (h : basis.{w} b K V) :\n  finrank K V = finset.card b :=\nby rw [finrank_eq_card_basis h, fintype.card_coe]\n\n/-- A finite dimensional space is nontrivial if it has positive `finrank`. -/\nlemma nontrivial_of_finrank_pos (h : 0 < finrank K V) : nontrivial V :=\ndim_pos_iff_nontrivial.mp (dim_lt_of_finrank_lt h)\n\n/-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a\nnatural number. -/\nlemma nontrivial_of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) : nontrivial V :=\nnontrivial_of_finrank_pos (by rw hn; exact n.succ_pos)\n\n/-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/\nlemma finrank_zero_of_subsingleton [h : subsingleton V] :\n  finrank K V = 0 :=\nbegin\n  by_contra h0,\n  obtain ⟨x, y, hxy⟩ := (nontrivial_of_finrank_pos (nat.pos_of_ne_zero h0)),\n  exact hxy (subsingleton.elim _ _)\nend\n\nlemma basis.subset_extend {s : set V} (hs : linear_independent K (coe : s → V)) :\n  s ⊆ hs.extend (set.subset_univ _) :=\nhs.subset_extend _\n\nvariable (K)\n/-- A division_ring is one-dimensional as a vector space over itself. -/\n@[simp] lemma finrank_self : finrank K K = 1 :=\nfinrank_eq_of_dim_eq (by simp)\n\n/-- The vector space of functions on a fintype ι has finrank equal to the cardinality of ι. -/\n@[simp] lemma finrank_fintype_fun_eq_card {ι : Type v} [fintype ι] :\n  finrank K (ι → K) = fintype.card ι :=\nfinrank_eq_of_dim_eq dim_fun'\n\n/-- The vector space of functions on `fin n` has finrank equal to `n`. -/\n@[simp] lemma finrank_fin_fun {n : ℕ} : finrank K (fin n → K) = n :=\nby simp\n\nend division_ring\n\nend finite_dimensional\n\nvariables {K V}\n\nsection zero_dim\n\nvariables [division_ring K] [add_comm_group V] [module K V]\n\nopen finite_dimensional\n\nlemma finrank_eq_zero_of_basis_imp_not_finite\n  (h : ∀ s : set V, basis.{v} (s : set V) K V → ¬ s.finite) : finrank K V = 0 :=\ndif_neg (λ dim_lt, h _ (basis.of_vector_space K V)\n  ((basis.of_vector_space K V).finite_index_of_dim_lt_aleph_0 dim_lt))\n\nlemma finrank_eq_zero_of_basis_imp_false\n  (h : ∀ s : finset V, basis.{v} (s : set V) K V → false) : finrank K V = 0 :=\nfinrank_eq_zero_of_basis_imp_not_finite (λ s b hs, h hs.to_finset (by { convert b, simp }))\n\nlemma finrank_eq_zero_of_not_exists_basis\n  (h : ¬ (∃ s : finset V, nonempty (basis (s : set V) K V))) : finrank K V = 0 :=\nfinrank_eq_zero_of_basis_imp_false (λ s b, h ⟨s, ⟨b⟩⟩)\n\nlemma finrank_eq_zero_of_not_exists_basis_finite\n  (h : ¬ ∃ (s : set V) (b : basis.{v} (s : set V) K V), s.finite) : finrank K V = 0 :=\nfinrank_eq_zero_of_basis_imp_not_finite (λ s b hs, h ⟨s, b, hs⟩)\n\nlemma finrank_eq_zero_of_not_exists_basis_finset\n  (h : ¬ ∃ (s : finset V), nonempty (basis s K V)) : finrank K V = 0 :=\nfinrank_eq_zero_of_basis_imp_false (λ s b, h ⟨s, ⟨b⟩⟩)\n\nvariables (K V)\n\n@[simp] lemma finrank_bot : finrank K (⊥ : submodule K V) = 0 :=\nfinrank_eq_of_dim_eq (dim_bot _ _)\n\nend zero_dim\n\nnamespace linear_equiv\nopen finite_dimensional\n\nvariables [division_ring K] [add_comm_group V] [module K V]\n{V₂ : Type v'} [add_comm_group V₂] [module K V₂]\n\nvariables {R M M₂ : Type*} [ring R] [add_comm_group M] [add_comm_group M₂]\nvariables [module R M] [module R M₂]\n\n/-- The dimension of a finite dimensional space is preserved under linear equivalence. -/\ntheorem finrank_eq (f : M ≃ₗ[R] M₂) : finrank R M = finrank R M₂ :=\nby { unfold finrank, rw [← cardinal.to_nat_lift, f.lift_dim_eq, cardinal.to_nat_lift] }\n\n/-- Pushforwards of finite-dimensional submodules along a `linear_equiv` have the same finrank. -/\nlemma finrank_map_eq (f : M ≃ₗ[R] M₂) (p : submodule R M) :\n  finrank R (p.map (f : M →ₗ[R] M₂)) = finrank R p :=\n(f.submodule_map p).finrank_eq.symm\n\nend linear_equiv\n\nnamespace linear_map\nopen finite_dimensional\n\nsection division_ring\nvariables [division_ring K] [add_comm_group V] [module K V]\n{V₂ : Type v'} [add_comm_group V₂] [module K V₂]\n\n/-- The dimensions of the domain and range of an injective linear map are equal. -/\nlemma finrank_range_of_inj {f : V →ₗ[K] V₂} (hf : function.injective f) :\n  finrank K f.range = finrank K V :=\nby rw (linear_equiv.of_injective f hf).finrank_eq\n\nend division_ring\n\nend linear_map\n\nopen module finite_dimensional\n\nsection\nvariables [division_ring K] [add_comm_group V] [module K V]\n\n@[simp]\ntheorem finrank_top : finrank K (⊤ : submodule K V) = finrank K V :=\nby { unfold finrank, simp [dim_top] }\n\nend\n\nnamespace submodule\n\nsection division_ring\nvariables [division_ring K] [add_comm_group V] [module K V]\n{V₂ : Type v'} [add_comm_group V₂] [module K V₂]\n\nlemma lt_of_le_of_finrank_lt_finrank {s t : submodule K V}\n  (le : s ≤ t) (lt : finrank K s < finrank K t) : s < t :=\nlt_of_le_of_ne le (λ h, ne_of_lt lt (by rw h))\n\nlemma lt_top_of_finrank_lt_finrank {s : submodule K V}\n  (lt : finrank K s < finrank K V) : s < ⊤ :=\nbegin\n  rw ← @finrank_top K V at lt,\n  exact lt_of_le_of_finrank_lt_finrank le_top lt\nend\n\nend division_ring\n\nend submodule\n\nsection span\n\nopen submodule\n\nsection division_ring\nvariables [division_ring K] [add_comm_group V] [module K V]\n\nvariable (K)\n\n/-- The rank of a set of vectors as a natural number. -/\nprotected noncomputable def set.finrank (s : set V) : ℕ := finrank K (span K s)\n\nvariable {K}\n\nlemma finrank_span_le_card (s : set V) [fintype s] :\n  finrank K (span K s) ≤ s.to_finset.card :=\nfinrank_le_of_dim_le (by simpa using dim_span_le s)\n\nlemma finrank_span_finset_le_card (s : finset V)  :\n  (s : set V).finrank K ≤ s.card :=\ncalc (s : set V).finrank K ≤ (s : set V).to_finset.card : finrank_span_le_card s\n                                ... = s.card : by simp\n\nlemma finrank_range_le_card {ι : Type*} [fintype ι] {b : ι → V} :\n  (set.range b).finrank K ≤ fintype.card ι :=\n(finrank_span_le_card _).trans $ by { rw set.to_finset_range, exact finset.card_image_le }\n\nlemma finrank_span_eq_card {ι : Type*} [fintype ι] {b : ι → V}\n  (hb : linear_independent K b) :\n  finrank K (span K (set.range b)) = fintype.card ι :=\nfinrank_eq_of_dim_eq\nbegin\n  have : module.rank K (span K (set.range b)) = #(set.range b) := dim_span hb,\n  rwa [←lift_inj, mk_range_eq_of_injective hb.injective, cardinal.mk_fintype, lift_nat_cast,\n       lift_eq_nat_iff] at this,\nend\n\nlemma finrank_span_set_eq_card (s : set V) [fintype s]\n  (hs : linear_independent K (coe : s → V)) :\n  finrank K (span K s) = s.to_finset.card :=\nfinrank_eq_of_dim_eq\nbegin\n  have : module.rank K (span K s) = #s := dim_span_set hs,\n  rwa [cardinal.mk_fintype, ←set.to_finset_card] at this,\nend\n\nlemma finrank_span_finset_eq_card (s : finset V)\n  (hs : linear_independent K (coe : s → V)) :\n  finrank K (span K (s : set V)) = s.card :=\nbegin\n  convert finrank_span_set_eq_card ↑s hs,\n  ext,\n  simp,\nend\n\nlemma span_lt_of_subset_of_card_lt_finrank {s : set V} [fintype s] {t : submodule K V}\n  (subset : s ⊆ t) (card_lt : s.to_finset.card < finrank K t) : span K s < t :=\nlt_of_le_of_finrank_lt_finrank\n  (span_le.mpr subset)\n  (lt_of_le_of_lt (finrank_span_le_card _) card_lt)\n\nlemma span_lt_top_of_card_lt_finrank {s : set V} [fintype s]\n  (card_lt : s.to_finset.card < finrank K V) : span K s < ⊤ :=\nlt_top_of_finrank_lt_finrank (lt_of_le_of_lt (finrank_span_le_card _) card_lt)\n\nend division_ring\n\nend span\n\nsection basis\n\nsection division_ring\nvariables [division_ring K] [add_comm_group V] [module K V]\n\nlemma linear_independent_of_top_le_span_of_card_eq_finrank {ι : Type*} [fintype ι] {b : ι → V}\n  (spans : ⊤ ≤ span K (set.range b)) (card_eq : fintype.card ι = finrank K V) :\n  linear_independent K b :=\nlinear_independent_iff'.mpr $ λ s g dependent i i_mem_s,\nbegin\n  by_contra gx_ne_zero,\n  -- We'll derive a contradiction by showing `b '' (univ \\ {i})` of cardinality `n - 1`\n  -- spans a vector space of dimension `n`.\n  refine not_le_of_gt (span_lt_top_of_card_lt_finrank\n    (show (b '' (set.univ \\ {i})).to_finset.card < finrank K V, from _)) _,\n  { calc (b '' (set.univ \\ {i})).to_finset.card = ((set.univ \\ {i}).to_finset.image b).card\n      : by rw [set.to_finset_card, fintype.card_of_finset]\n    ... ≤ (set.univ \\ {i}).to_finset.card : finset.card_image_le\n    ... = (finset.univ.erase i).card : congr_arg finset.card (finset.ext (by simp [and_comm]))\n    ... < finset.univ.card : finset.card_erase_lt_of_mem (finset.mem_univ i)\n    ... = finrank K V : card_eq },\n\n  -- We already have that `b '' univ` spans the whole space,\n  -- so we only need to show that the span of `b '' (univ \\ {i})` contains each `b j`.\n  refine spans.trans (span_le.mpr _),\n  rintros _ ⟨j, rfl, rfl⟩,\n  -- The case that `j ≠ i` is easy because `b j ∈ b '' (univ \\ {i})`.\n  by_cases j_eq : j = i,\n  swap,\n  { refine subset_span ⟨j, (set.mem_diff _).mpr ⟨set.mem_univ _, _⟩, rfl⟩,\n    exact mt set.mem_singleton_iff.mp j_eq },\n\n  -- To show `b i ∈ span (b '' (univ \\ {i}))`, we use that it's a weighted sum\n  -- of the other `b j`s.\n  rw [j_eq, set_like.mem_coe, show b i = -((g i)⁻¹ • (s.erase i).sum (λ j, g j • b j)), from _],\n  { refine neg_mem (smul_mem _ _ (sum_mem (λ k hk, _))),\n    obtain ⟨k_ne_i, k_mem⟩ := finset.mem_erase.mp hk,\n    refine smul_mem _ _ (subset_span ⟨k, _, rfl⟩),\n    simpa using k_mem },\n\n  -- To show `b i` is a weighted sum of the other `b j`s, we'll rewrite this sum\n  -- to have the form of the assumption `dependent`.\n  apply eq_neg_of_add_eq_zero_left,\n  calc b i + (g i)⁻¹ • (s.erase i).sum (λ j, g j • b j)\n      = (g i)⁻¹ • (g i • b i + (s.erase i).sum (λ j, g j • b j))\n    : by rw [smul_add, ←mul_smul, inv_mul_cancel gx_ne_zero, one_smul]\n  ... = (g i)⁻¹ • 0 : congr_arg _ _\n  ... = 0           : smul_zero _,\n  -- And then it's just a bit of manipulation with finite sums.\n  rwa [← finset.insert_erase i_mem_s, finset.sum_insert (finset.not_mem_erase _ _)] at dependent\nend\n\n/-- A finite family of vectors is linearly independent if and only if\nits cardinality equals the dimension of its span. -/\nlemma linear_independent_iff_card_eq_finrank_span {ι : Type*} [fintype ι] {b : ι → V} :\n  linear_independent K b ↔ fintype.card ι = (set.range b).finrank K :=\nbegin\n  split,\n  { intro h,\n    exact (finrank_span_eq_card h).symm },\n  { intro hc,\n    let f := (submodule.subtype (span K (set.range b))),\n    let b' : ι → span K (set.range b) :=\n      λ i, ⟨b i, mem_span.2 (λ p hp, hp (set.mem_range_self _))⟩,\n    have hs : ⊤ ≤ span K (set.range b'),\n    { intro x,\n      have h : span K (f '' (set.range b')) = map f (span K (set.range b')) := span_image f,\n      have hf : f '' (set.range b') = set.range b, { ext x, simp [set.mem_image, set.mem_range] },\n      rw hf at h,\n      have hx : (x : V) ∈ span K (set.range b) := x.property,\n      conv at hx { congr, skip, rw h },\n      simpa [mem_map] using hx },\n    have hi : f.ker = ⊥ := ker_subtype _,\n    convert (linear_independent_of_top_le_span_of_card_eq_finrank hs hc).map' _ hi }\nend\n\nlemma linear_independent_iff_card_le_finrank_span {ι : Type*} [fintype ι] {b : ι → V} :\n  linear_independent K b ↔ fintype.card ι ≤ (set.range b).finrank K :=\nby rw [linear_independent_iff_card_eq_finrank_span, finrank_range_le_card.le_iff_eq]\n\n/-- A family of `finrank K V` vectors forms a basis if they span the whole space. -/\nnoncomputable def basis_of_top_le_span_of_card_eq_finrank {ι : Type*} [fintype ι] (b : ι → V)\n  (le_span : ⊤ ≤ span K (set.range b)) (card_eq : fintype.card ι = finrank K V) :\n  basis ι K V :=\nbasis.mk (linear_independent_of_top_le_span_of_card_eq_finrank le_span card_eq) le_span\n\n@[simp] lemma coe_basis_of_top_le_span_of_card_eq_finrank {ι : Type*} [fintype ι] (b : ι → V)\n  (le_span : ⊤ ≤ span K (set.range b)) (card_eq : fintype.card ι = finrank K V) :\n   ⇑(basis_of_top_le_span_of_card_eq_finrank b le_span card_eq) = b :=\nbasis.coe_mk _ _\n\n/-- A finset of `finrank K V` vectors forms a basis if they span the whole space. -/\n@[simps]\nnoncomputable def finset_basis_of_top_le_span_of_card_eq_finrank {s : finset V}\n  (le_span : ⊤ ≤ span K (s : set V)) (card_eq : s.card = finrank K V) :\n  basis (s : set V) K V :=\nbasis_of_top_le_span_of_card_eq_finrank (coe : (s : set V) → V)\n  ((@subtype.range_coe_subtype _ (λ x, x ∈ s)).symm ▸ le_span)\n  (trans (fintype.card_coe _) card_eq)\n\n/-- A set of `finrank K V` vectors forms a basis if they span the whole space. -/\n@[simps]\nnoncomputable def set_basis_of_top_le_span_of_card_eq_finrank {s : set V} [fintype s]\n  (le_span : ⊤ ≤ span K s) (card_eq : s.to_finset.card = finrank K V) :\n  basis s K V :=\nbasis_of_top_le_span_of_card_eq_finrank (coe : s → V)\n  ((@subtype.range_coe_subtype _ s).symm ▸ le_span)\n  (trans s.to_finset_card.symm card_eq)\n\nend division_ring\n\nend basis\n\n/-!\nWe now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`.\n-/\nsection finrank_eq_one\n\nvariables [division_ring K] [add_comm_group V] [module K V]\n\n/-- If there is a nonzero vector and every other vector is a multiple of it,\nthen the module has dimension one. -/\nlemma finrank_eq_one (v : V) (n : v ≠ 0) (h : ∀ w : V, ∃ c : K, c • v = w) :\n  finrank K V = 1 :=\nbegin\n  obtain ⟨b⟩ := (basis.basis_singleton_iff punit).mpr ⟨v, n, h⟩,\n  rw [finrank_eq_card_basis b, fintype.card_punit]\nend\n\n/--\nIf every vector is a multiple of some `v : V`, then `V` has dimension at most one.\n-/\nlemma finrank_le_one (v : V) (h : ∀ w : V, ∃ c : K, c • v = w) :\n  finrank K V ≤ 1 :=\nbegin\n  rcases eq_or_ne v 0 with rfl | hn,\n  { haveI := subsingleton_of_forall_eq (0 : V) (λ w, by { obtain ⟨c, rfl⟩ := h w, simp }),\n    rw finrank_zero_of_subsingleton,\n    exact zero_le_one },\n  { exact (finrank_eq_one v hn h).le }\nend\n\nend finrank_eq_one\n\nsection subalgebra_dim\nopen module\nvariables {F E : Type*} [field F] [ring E] [algebra F E]\n\n@[simp] lemma subalgebra.dim_bot [nontrivial E] : module.rank F (⊥ : subalgebra F E) = 1 :=\n((subalgebra.to_submodule_equiv (⊥ : subalgebra F E)).symm.trans $\n  linear_equiv.of_eq _ _ algebra.to_submodule_bot).dim_eq.trans $\n  by { rw dim_span_set, exacts [mk_singleton _, linear_independent_singleton one_ne_zero] }\n\n@[simp] lemma subalgebra.dim_to_submodule (S : subalgebra F E) :\n  module.rank F S.to_submodule = module.rank F S := rfl\n\n@[simp] lemma subalgebra.finrank_to_submodule (S : subalgebra F E) :\n  finrank F S.to_submodule = finrank F S := rfl\n\nlemma subalgebra_top_dim_eq_submodule_top_dim :\n  module.rank F (⊤ : subalgebra F E) = module.rank F (⊤ : submodule F E) :=\nby { rw ← algebra.top_to_submodule, refl }\n\nlemma subalgebra_top_finrank_eq_submodule_top_finrank :\n  finrank F (⊤ : subalgebra F E) = finrank F (⊤ : submodule F E) :=\nby { rw ← algebra.top_to_submodule, refl }\n\nlemma subalgebra.dim_top : module.rank F (⊤ : subalgebra F E) = module.rank F E :=\nby { rw subalgebra_top_dim_eq_submodule_top_dim, exact dim_top F E }\n\n@[simp]\nlemma subalgebra.finrank_bot [nontrivial E] : finrank F (⊥ : subalgebra F E) = 1 :=\nfinrank_eq_of_dim_eq (by simp)\n\nend subalgebra_dim\n", "meta": {"author": "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/finrank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7856060637440069}}
{"text": "import data.real.basic\n\n/-\nOne of the earliest kind of proofs one encounters while learning mathematics is proving by\na calculation. It may not sound like a proof, but this is actually using lemmas expressing \nproperties of operations on numbers. It also uses the fundamental property of equality: if two\nmathematical objects A and B are equal then, in any statement involving A, one can replace A \nby B. This operation is called rewriting, and the Lean \"tactic\" for this is `rw`.\n\nIn the following exercises, we will use the following two lemmas:\n  mul_assoc a b c : a * b * c = a * (b * c)\n  mul_comm a b : a*b = b*a\n\nHence the command \n  rw mul_assoc a b c,\nwill replace a*b*c by a*(b*c) in the current goal.\n\nIn order to replace backward, we use\n  rw ← mul_assoc a b c,\nreplacing a*(b*c) by a*b*c in the current goal.\n\nOf course we don't want to constantly invoke those lemmas, and we will eventually introduce\nmore powerful solutions.\n-/\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 0001\nexample (a b c : ℝ) : (c * b) * a = b * (a * c) :=\nbegin\n  rw mul_comm c b,\n  rw mul_comm a c,\n  rw mul_assoc b c a,\nend\n\n-- 0002\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw <- mul_assoc a b c,\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n/-\nNow let's return to the preceding example to experiment with what happens\nif we don't give arguments to mul_assoc or mul_comm.\nFor instance, you can start the next proof with\n  rw ← mul_assoc,\nTry to figure out what happens.\n-/\n\n-- 0003\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw <- mul_assoc,\n  rw mul_comm a b,\n  rw mul_assoc,\nend\n\n/-\nWe can also perform rewriting in an assumption of the local context, using for instance\n  rw mul_comm a b at hyp,\nin order to replace a*b by b*a in assumption hyp.\n\nThe next example will use a third lemma:\n  two_mul a : 2*a = a + a\n\nAlso we use the `exact` tactic, which allows to provide a direct proof term.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a*d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp, -- Our assumption hyp is now exactly what we have to prove\nend\n\n/-\nAnd the next one can use:\n  sub_self x : x - x = 0\n-/\n\n-- 0004\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  rw mul_comm b a at hyp,\n  rw hyp' at hyp,\n  rw sub_self (a * b) at hyp,\n  exact hyp,\nend\n\n/-\nWhat is written in the two preceding example is very far away from what we would write on\npaper. Let's now see how to get a more natural layout.\nInside each pair of curly braces below, the goal is to prove equality with the preceding line.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b : by { rw hyp }\n  ... = d*a + a*d  : by { rw hyp' }\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\n/-\nLet's note there is no comma at the end of each line of calculation. `calc` is really one\ncommand, and the comma comes only after it's fully done.\n\nFrom a practical point of view, when writing such a proof, it is convenient to:\n* pause the tactic state view update in VScode by clicking the Pause icon button\n  in the top right corner of the Lean Goal buffer\n* write the full calculation, ending each line with \": by {}\"\n* resume tactic state update by clicking the Play icon button and fill in proofs between \n  curly braces.\n\nLet's return to the other example using this method. \n-/\n\n-- 0005\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  calc c = b * a - d  : by { rw hyp }\n  ... = a * b - d     : by { rw mul_comm a b }\n  ... = a * b - a * b : by { rw hyp' }\n  ... = 0             : by { rw sub_self (a * b) },\nend\n\n/-\nThe preceding proofs have exhausted our supply of \"mul_comm\" patience. Now it's time\nto get the computer to work harder. The `ring` tactic will prove any goal that follows by\napplying only the axioms of commutative (semi-)rings, in particular commutativity and \nassociativity of addition and multiplication, as well as distributivity.\n\nWe also note that curly braces are not necessary when we write a single tactic proof, so \nlet's get rid of them.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b   : by rw hyp\n     ... = d*a + a*d : by rw hyp'\n     ... = 2*a*d     : by ring,\nend\n\n/-\nOf course we can use `ring` outside of `calc`. Let's do the next one in one line.\n-/\n\n-- 0006\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  calc a * (b * c) = b * (a * c) : by ring,\nend\n\n/-\nThis is too much fun. Let's do it again.\n-/\n\n-- 0007\nexample (a b : ℝ) : (a + b) + a = 2*a + b :=\nbegin\n  calc (a + b) + a = 2 * a + b : by ring,\nend\n\n/-\nMaybe this is cheating. Let's try to do the next computation without ring.\nWe could use:\npow_two x : x^2 = x*x\nmul_sub a b c : a*(b-c) = a*b - a*c\nadd_mul a b c : (a+b)*c = a*c + b*c\nadd_sub a b c : a + (b - c) = (a + b) - c\nsub_sub a b c : a - b - c = a - (b + c)\nadd_zero a : a + 0 = a\n-/\n\n-- 0008\nexample (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 :=\nbegin\n  calc (a + b) * (a - b) = (a + b) * a - (a + b) * b  : by rw mul_sub\n  ... = a * a + b * a - (a + b) * b                   : by rw add_mul\n  ... = a * a + b * a - (a * b + b * b)               : by rw add_mul\n  ... = a * a + b * a - a * b - b * b                 : by rw sub_sub\n  ... = a * a + (b * a - a * b) - b * b               : by rw <- add_sub\n  ... = a * a + (a * b - a * b) - b * b               : by rw mul_comm a b\n  ... = a * a + 0 - b * b                             : by rw sub_self\n  ... = a * a - b * b                                 : by rw add_zero\n  ... = a^2 - b * b                                   : by rw <- pow_two a\n  ... = a^2 - b^2                                     : by rw <- pow_two b,\nend\n\n/- Let's stick to ring in the end. -/\n\n", "meta": {"author": "sanjitdp", "repo": "lean-projects", "sha": "05b9a58e8bda3baebd4269536db39815a73cb123", "save_path": "github-repos/lean/sanjitdp-lean-projects", "path": "github-repos/lean/sanjitdp-lean-projects/lean-projects-05b9a58e8bda3baebd4269536db39815a73cb123/src/real-analysis/01_equality_rewriting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.8723473614033683, "lm_q1q2_score": 0.7855747921002509}}
{"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.hom.iterate\nimport algebra.regular.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\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 : ℕ) (rla : is_left_regular a) : is_left_regular (a ^ n) :=\nby simp only [is_left_regular, ← mul_left_iterate, rla.iterate n]\n\n/--  Any power of a right-regular element is right-regular. -/\nlemma is_right_regular.pow (n : ℕ) (rra : is_right_regular a) : is_right_regular (a ^ n) :=\nby { rw [is_right_regular, ← mul_right_iterate], exact rra.iterate n }\n\n/--  Any power of a regular element is regular. -/\nlemma is_regular.pow (n : ℕ) (ra : is_regular a) : is_regular (a ^ n) :=\n⟨is_left_regular.pow n ra.left, is_right_regular.pow n ra.right⟩\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 : ℕ} (n0 : 0 < n) :\n  is_left_regular (a ^ n) ↔ is_left_regular a :=\nbegin\n  refine ⟨_, is_left_regular.pow n⟩,\n  rw [← 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 : ℕ} (n0 : 0 < n) :\n  is_right_regular (a ^ n) ↔ is_right_regular a :=\nbegin\n  refine ⟨_, is_right_regular.pow n⟩,\n  rw [← 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 : ℕ} (n0 : 0 < n) :\n  is_regular (a ^ n) ↔ is_regular a :=\n⟨λ h, ⟨(is_left_regular.pow_iff n0).mp h.left, (is_right_regular.pow_iff n0).mp h.right⟩,\n  λ h, ⟨is_left_regular.pow n h.left, is_right_regular.pow n h.right⟩⟩\n\nend monoid\n", "meta": {"author": "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/pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8723473697001441, "lm_q1q2_score": 0.7855747855989932}}
{"text": "-- Lista 8\n\n-- Lucas Machado Moschen\n\nopen nat\n\n--1.a.\nexample : ∀ 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\n--1.b.\ntheorem mul_zero_left : ∀ n : nat, 0 * n = 0 := \nassume n,\nnat.rec_on n\n    (show 0*0 = 0, by rw mul_zero)\n    (assume n,\n    assume ih: 0*n = 0,\n    show 0*(succ n) = 0, from calc \n    0*(succ n) = 0*n + 0 : by rw mul_succ\n         ...   = 0 + 0 : by rw ih  \n         ...   = 0 : by rw add_zero\n    )\n\n\n--1.c.\ntheorem mul_one_left : ∀ n : nat, 1 * n = n := \nassume n,\nnat.rec_on n \n    (show 1*0 = 0, from mul_zero 1)\n    (assume n, \n    assume ih: 1*n = n,\n    show 1*(succ n) = succ n, from calc\n    1*(succ n) = 1*n + 1 : by rw mul_succ\n           ... = n + 1 : by rw ih \n           ... = succ n : by simp \n    )\n\n--1.d.\nexample : ∀ m n k : nat, (m * n) * k = m * (n * k) := \nassume m n k, \nnat.rec_on k\n    (show (m*n)*0 = m*(n*0), by rw\n    [mul_zero,mul_zero,mul_zero])\n    (assume k, \n    assume ih : (m * n) * k = m * (n * k),\n    show (m * n) * (succ k) = m * (n * (succ k)), from calc\n    (m * n) * (succ k) = (m*n)*k + (m*n) : by rw mul_succ\n                   ... = m * (n * k) + m * n : by rw ih \n                   ... = m * (n*k + n) : by rw left_distrib \n                   ... = m * (n*(succ k)) : by rw mul_succ\n                   ... = m * (n * succ k) : by simp \n    )\n\n--1.e.\nexample : ∀ m n : nat, m * n= n * m := \nassume m n, \nnat.rec_on n\n    (show m*0 = 0*m, by rw [mul_zero,mul_zero_left])\n    (assume n, \n    assume ih : m*n = n*m,\n    show m*(succ n) = (succ n)*m, from calc\n    m*(succ n) = m*n + m : by rw mul_succ\n           ... = n*m + m : by rw ih\n           ... = n*m + 1*m : by rw mul_one_left \n           ... = (n + 1)*m : by rw right_distrib \n           ... = (succ n)*m : by simp \n    )\n\n--2.a.\ntheorem summing_k: ∀ m n k : nat, n ≤ m → n + k ≤ m + k := \nbegin \n    assume m n k, \n    intro h1,\n    apply nat.rec_on k,\n    exact h1,\n    intro k, \n    intro h2, \n    have h3: m+k < succ(m + k), from lt_succ_self (m + k),\n    apply lt_of_le_of_lt h2 h3\nend\n\n--2.b.\nexample : ∀ m n k : nat, n + k ≤ m + k → n ≤ m := \nbegin \n    assume m n k, \n    apply nat.rec_on k, \n    intro h, exact h,\n    assume k',\n    intros ih h, \n    repeat {rw add_succ at h},\n    have h1: n + k' ≤ m + k', from le_of_succ_le_succ h,\n    apply ih h1,\nend\n\n--2.c.\nexample : ∀ m n k : nat, n ≤ m → n * k ≤ m * k := \nbegin\n    assume m n k, \n    intro h, \n    apply nat.rec_on k, \n        apply less_than_or_equal.refl, \n    assume k',\n    intro ih, \n        repeat {rw mul_succ},\n        have h1: n*k' + n ≤ m*k' + n, from summing_k _ _ _ ih, \n        have h2: m*k' + n ≤ m*k' + m, from add_le_add_left h (m*k'), \n        apply le_trans h1 h2, \nend\n\n--2.d.\nexample : ∀ m n : nat, m ≥ n → m = n ∨ m ≥ n+1 :=  \nassume m n, \nbegin\n    assume h, \n    cases lt_or_eq_of_le h with h1 h2,\n    have h3: succ n ≤ m, from h1, \n    apply or.inr h3, \n    apply or.inl (eq.symm h2)\nend                \n\n--2.e.\n\nexample : ∀ n : nat, 0 ≤ n := \nbegin \n    assume n, \n    apply nat.rec_on n, \n        apply less_than_or_equal.refl 0,\n        assume n h,\n        have h1: n < succ n, from lt_succ_self n,\n        apply le_of_lt (lt_of_le_of_lt h h1), \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/cap17-LucasMoschen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.7855747849391878}}
{"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-/\nimport analysis.normed_space.conformal_linear_map\nimport analysis.inner_product_space.basic\n\n/-!\n# Conformal maps between inner product spaces\n\nIn an inner product space, a map is conformal iff it preserves inner products up to a scalar factor.\n-/\n\nvariables {E F : Type*} [inner_product_space ℝ E] [inner_product_space ℝ F]\n\nopen linear_isometry continuous_linear_map\nopen_locale real_inner_product_space\n\nlemma is_conformal_map_iff (f' : E →L[ℝ] F) :\n  is_conformal_map f' ↔ ∃ (c : ℝ), 0 < c ∧\n  ∀ (u v : E), ⟪f' u, f' v⟫ = (c : ℝ) * ⟪u, v⟫ :=\nbegin\n  split,\n  { rintros ⟨c₁, hc₁, li, h⟩,\n    refine ⟨c₁ * c₁, mul_self_pos hc₁, λ u v, _⟩,\n    simp only [h, pi.smul_apply, inner_map_map,\n               real_inner_smul_left, real_inner_smul_right, mul_assoc], },\n  { rintros ⟨c₁, hc₁, huv⟩,\n    let c := real.sqrt c₁⁻¹,\n    have hc : c ≠ 0 := λ w, by {simp only [c] at w;\n      exact (real.sqrt_ne_zero'.mpr $ inv_pos.mpr hc₁) w},\n    let f₁ := c • f',\n    have minor : (f₁ : E → F) = c • f' := rfl,\n    have minor' : (f' : E → F) = c⁻¹ • f₁ := by ext;\n      simp_rw [minor, pi.smul_apply]; rw [smul_smul, inv_mul_cancel hc, one_smul],\n    refine ⟨c⁻¹, inv_ne_zero hc, f₁.to_linear_map.isometry_of_inner (λ u v, _), minor'⟩,\n    simp_rw [to_linear_map_eq_coe, continuous_linear_map.coe_coe, minor, pi.smul_apply],\n    rw [real_inner_smul_left, real_inner_smul_right,\n        huv u v, ← mul_assoc, ← mul_assoc,\n        real.mul_self_sqrt $ le_of_lt $ inv_pos.mpr hc₁,\n        inv_mul_cancel $ ne_of_gt hc₁, one_mul], },\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/inner_product_space/conformal_linear_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.7855255769583137}}
{"text": "import tactic data.vector\n\n\nnamespace exlean \n\nopen nat\n\nsection induction_on_nat\n\n@[elab_as_eliminator, reducible]\ndef nat.ind (P : ℕ → Prop) (n : ℕ) (h₀ : P 0) (h₁ : ∀ (k : ℕ), P k → P k.succ) : P n :=\nnat.rec_on n h₀ h₁\n\nlemma add_zero (a : ℕ) : a + 0 = a := rfl\n\nlemma add_succ (a b : ℕ) : a + succ b = succ (a + b) := rfl\n\ndef P := λ k, 0 + k = k\n\nexample : (P 0) = (0 = 0 + 0) := rfl\n\nlemma base : P 0 := add_zero 0\n\nlemma ind_step : ∀ k, P k → P k.succ :=\nbegin\n  unfold P,\n  intros k ih, -- k : ℕ, ih : 0 + k = k, ⊢ 0 + (succ k) = succ k\n  rw add_succ, -- ⊢ succ (0 + k) = succ k\n  rw ih, -- ⊢ succ k = succ k\nend\n\nexample : ℕ := succ (succ zero)\n\nlemma zero_add (a : ℕ) : 0 + a = a := nat.ind P a base ind_step\n\nlemma zero_add' (a : ℕ) : 0 + a = a :=\nbegin\n  let P := λ k, 0 + k = k,\n  have h₀ : P 0, { dsimp [P], refl, },\n  have h₁ : ∀ (k : ℕ), P k → P k.succ,\n  { dsimp [P], intros k ih, rw add_succ, rw ih, },\n  exact nat.ind P a h₀ h₁\nend\n\nlemma zero_add'' (a : ℕ) : 0 + a = a :=\nbegin\n  apply nat.ind (λ k, 0 + k = k),\n  { refl, },\n  { intros k ih, rw [add_succ, ih], },\nend\n\nlemma zero_add_apply_placeholder (a : ℕ) : 0 + a = a :=\nbegin\n  apply nat.ind _ a,\n  { refl, },\n  { intros k ih, rw [add_succ, ih], },\nend\n\nlemma zero_add_refine (a : ℕ) : 0 + a = a :=\nbegin\n  refine nat.ind _ a rfl _,\n  { intros k ih, rw [add_succ, ih], },\nend\n\nlemma zero_add''' : ∀ a : ℕ, 0 + a = a := @nat.rec (λ k, 0 + k = k) rfl (λ k ih, \n  have h₂ : 0 + succ k = succ (0 + k) := add_succ 0 k,\n  have h₃ : succ (0 + k) = succ k := ih.symm ▸ rfl,\n  eq.trans h₂ h₃)\n\nlemma zero_add'''' (a : ℕ) : 0 + a = a := nat.ind _ a rfl\n(λ k ih, eq.trans (add_succ 0 k) (ih.symm ▸ rfl))\n\nlemma zero_add''''' (a : ℕ) : 0 + a = a := nat.rec_on a rfl (λ k ih, \n  have h₂ : 0 + succ k = succ (0 + k) := add_succ 0 k,\n  have h₃ : succ (0 + k) = succ k := ih.symm ▸ rfl,\n  eq.trans h₂ h₃)\n\nend induction_on_nat\n\nsection recursively_defined_sequences_of_ints\n\n-- Here is recursion principle for defining sequences of integers.\n/- def nat.int_seq (n : ℕ) (h₀ : ℤ) (h₁ : ∀ (k : ℕ), ℤ → ℤ) : ℤ :=\nnat.rec_on n h₀ h₁ -/\n\ndef nat.int_seq (n : ℕ) (a₀ : ℤ) (h : ∀ (k : ℕ) (ak : ℤ), ℤ) : ℤ :=\nnat.rec_on n a₀ h\n\n-- The following is a sequence of integers with `a₀ = 6` and `aₙ₊₁ = 5 + 2 * aₙ`.\ndef seq1 (n : ℕ) : ℤ := nat.int_seq n (6 : ℤ) (λ k ak, 5 + 2 * ak)\n\nlemma seq1_succ (k : ℕ) : seq1 (succ k) = 5 + 2 * (seq1 k) := rfl\n\nexample : seq1 2 = 39 := dec_trivial\n\n-- We can easily prove a formula for the n-th term of the sequence.\n\n-- First using the `induction` tactic\nlemma seq1_formula (n : ℕ) : seq1 n = 11 * 2 ^ n - 5 :=\nbegin\n  induction n with k ih,\n  { refl, },\n  { rw [seq1_succ, ih], ring_exp, }\nend\n\n-- Second, using `apply nat.ind`.\nlemma seq1_formula' (n : ℕ) : seq1 n = 11 * 2 ^ n - 5 :=\nbegin\n  apply nat.ind (λ n, seq1 n = 11 * 2 ^ n - 5),\n  { refl, },\n  { intros k ih, rw [seq1_succ, ih], ring_exp, },\nend\n\nlemma seq1_formula''' (n : ℕ) : seq1 n = 11 * 2 ^ n - 5 :=\nbegin\n  refine nat.ind _ n rfl _,\n  { intros k ih, rw [seq1_succ, ih], ring_exp, },\nend\n\n-- Third, using `nat.ind` term-style.\nlemma seq1_formula'' (n : ℕ) : seq1 n = 11 * 2 ^ n - 5 :=\nnat.ind _ n rfl (λ k ih, by {rw [seq1_succ, ih], ring_exp })\n\n-- Here's another sequence.\ndef triangle (n : ℕ) : ℤ := nat.int_seq n 0 (λ k ak, k + ak)\n\nlemma triangle_succ (n : ℕ) : triangle (succ n) = n + triangle n := rfl\n\n-- We prove the formula for the sum of the triangle numbers.\nlemma triangle_formula (n : ℕ) : 2 * triangle (succ n) = n * (succ n) :=\nbegin\n  refine nat.ind _ n rfl _,\n  { intros k ih, rw [triangle_succ, mul_add, ih], ring, }\nend\n\nlemma triangle_formula' (n : ℕ) : 2 * triangle (succ n) = n * (succ n) :=\nnat.ind _ n rfl (λ k ih, by { rw [triangle_succ, mul_add, ih], ring })\n\nend recursively_defined_sequences_of_ints\n\nsection recursively_defined_sequences_of_nats\n\n-- Here's a principle for defining sequences of natural numbers.\ndef nat.nat_seq (n : ℕ) (h₀ : ℕ) (h₁ : Π (k : ℕ), ℕ → ℕ) : ℕ :=\nnat.rec_on n h₀ h₁\n\n-- The following sequence is `a₀ = 6` and `aₙ₊₁ = 5 + 2 * aₙ`.\ndef seq2 (n : ℕ) : ℕ := nat.nat_seq n 6 (λ k seq_k, 5 + 2 * seq_k)\n\nlemma seq2_succ (n : ℕ) : seq2 (succ n) = 5 + 2 * (seq2 n) := rfl\n\n-- Proving a formula is tricker in the ℕ case than in the ℤ case.\n-- One approach is to use an auxiliary result.\nlemma seq2_formula' (n : ℕ) : 5 + seq2 n = 11 * 2 ^ n :=\nbegin\n  induction n with n ih,\n  { refl, },\n  { have h : ∀ a, 5 + (5 + 2 * a) = 2 * (5 + a), { intro a, ring },\n    simp only [seq2_succ, h, ih], ring_exp, }\nend\n\nlemma seq2_formula (n : ℕ) : seq2 n = 11 * 2 ^ n - 5 :=\nbegin\n  symmetry,\n  apply nat.sub_eq_of_eq_add,\n  rw ←seq2_formula',\nend\n\nend recursively_defined_sequences_of_nats\n\nsection sequences_of_vectors\n\ndef natvec (k : ℕ) := vector ℕ (succ k)\n\n-- A principle for defining sequences of vectors of natural numbers. The `n`th term in the sequence\n-- is a vector of length `n + 1`.\ndef nat.vec_seq (n : ℕ) (a₀ : natvec 0) (h : Π (k : ℕ) (ak : natvec k), natvec (succ k)) :\n  natvec n := nat.rec_on n a₀ h\n\n-- A sequence of triangular numbers.\ndef vseq_triangle (n : ℕ) : natvec n :=\n  nat.vec_seq n ⟨[0], rfl⟩ (λ k ak, vector.cons (k + ak.head) ak)\n\nexample : vseq_triangle 5 = ⟨[10, 6, 3, 1, 0, 0], _⟩ := rfl\n\n-- A principle for defining sequences of vectors. The `n`th term in the sequence is a vector of\n-- length `n`.\ndef nat.vec_seq_simple (n : ℕ) (h : Π (k : ℕ) (ak : vector ℕ k), vector ℕ (k+1)) : vector ℕ n :=\n  nat.rec_on n vector.nil h\n\ndef vseq (n : ℕ) : vector ℕ n := nat.vec_seq_simple n (λ k ak, vector.cons (k*k) ak)\n\n/--\nA slighly different definition of a sequence of triangular numbers. We begin with an auxiliary function.\n**Note** this is a bit of a cheat as pattern matching of course involves recursion. We'll redo this\nin the next section.\n-/\ndef next_vec : Π (k : ℕ), vector ℕ k → vector ℕ (k+1)\n| 0       _   := ⟨[0], rfl⟩\n| m@(a+1) am  := vector.cons (m + am.head) am\n\ndef vseq_triangle' (n : ℕ) : vector ℕ n :=\n  nat.vec_seq_simple n next_vec\n\ndef vseq_triangle'' (n : ℕ) : vector ℕ n :=\n  nat.vec_seq_simple n (λ k,\n  match k with\n  | 0       := λ ak, ⟨[0], rfl⟩\n  | m@(a+1) := λ am, vector.cons (m + am.head) am\n  end )\n\nexample : vseq_triangle' 6 = ⟨[15, 10, 6, 3, 1, 0], _⟩ := rfl\n\n/-\nUsing the above idea, we can define the Fibonacci sequence. Again, we can do this with `nat.rec_on`\nas we'll see later.\n-/\ndef next_fib_cheat : Π (k : ℕ), vector ℕ k → vector ℕ (k+1)\n| 0       _   := ⟨[1], rfl⟩\n| 1       _   := ⟨[1,1], rfl⟩\n| m@(a+2) am  := vector.cons (am.head + am.tail.head) am\n\ndef vseq_fib_cheat (n : ℕ) : vector ℕ n :=\n  nat.vec_seq_simple n next_fib_cheat\n\nexample : vseq_fib_cheat 7 = ⟨[13, 8, 5, 3, 2, 1, 1], _⟩ := rfl\n\nend sequences_of_vectors\n\nuniverse u\n\nsection recursion_in_general\n\n@[elab_as_eliminator, reducible]\ndef nat.rec_on' {C : ℕ → Sort u} (n : ℕ) (h₀ : C 0) (h₁ : Π (k : ℕ), C k → C k.succ) : C n :=\nnat.rec_on n h₀ h₁\n\nexample (P : ℕ → Prop) (n : ℕ) (h₀ : P 0) (h₁ : ∀ (k : ℕ), P k → P k.succ) : \n  @nat.ind P n h₀ h₁ = @nat.rec_on P n h₀ h₁ := rfl\n\nexample (n : ℕ) (a₀ : ℤ) (h : ∀ (k : ℕ) (ak : ℤ), ℤ) :\n  nat.int_seq n a₀ h = @nat.rec_on' (λ (k : ℕ), ℤ) n a₀ h := rfl\n\nexample (n : ℕ) (a₀ : natvec 0) (h : Π (k : ℕ) (ak : natvec k), natvec (succ k)) : \n  nat.vec_seq n a₀ h = @nat.rec_on' natvec n a₀ h := rfl\n\ndef next_vec' : Π (k : ℕ), vector ℕ k → vector ℕ (k+1) :=\nbegin\n  intro k,\n  refine nat.rec_on' k _ _,\n  { intro am, exact ⟨[0], rfl⟩, },\n  { intros m h am, exact vector.cons (m + am.head) am },\nend\n\ndef next_vec'' : Π (k : ℕ), vector ℕ k → vector ℕ (k+1) :=\nλ k, nat.rec_on k (λ am, ⟨[0], rfl⟩) (λ m h am, vector.cons (m + am.head) am)\n\ndef next_vec''' : Π (k : ℕ), vector ℕ k → vector ℕ (k+1) :=\nλ k, nat.rec_on k (λ am, ⟨[0], rfl⟩) (λ m h am, vector.cons (m + am.head) am)\n\ndef vseq_triangle''' (n : ℕ) : vector ℕ n :=\n  nat.vec_seq_simple n (λ k, nat.rec_on k (λ am, ⟨[0], rfl⟩) (λ m h am, vector.cons (m + am.head) am))\n\ndef vseq_triangle'''' (n : ℕ) : vector ℕ n :=\n  nat.rec_on n vector.nil next_vec''\n\ndef next_fib : Π (k : ℕ), vector ℕ k → vector ℕ (k+1) :=\nbegin\n  intro k,\n  refine nat.rec_on' k _ _,\n  { intro am, exact ⟨[1], rfl⟩, },\n  { intros m h am,\n    refine nat.rec_on' m _ _,\n    { exact ⟨[1, 1], rfl⟩ },\n    { intros c ac, exact vector.cons (ac.head + ac.tail.head) ac }, },\nend\n\ndef next_fibbum : Π (k : ℕ), vector ℕ k → vector ℕ (k+1) :=\nshow Π (k : ℕ), vector ℕ k → vector ℕ (k+1),\n{\n  intro k,\n  refine nat.rec_on' k _ _,\n  { intro am, exact ⟨[1], rfl⟩, },\n  { intros m h am,\n    refine nat.rec_on' m _ _,\n    { exact ⟨[1, 1], rfl⟩ },\n    { intros c ac, exact vector.cons (ac.head + ac.tail.head) ac }, },\n}\n\n\ndef next_fib'' : Π (k : ℕ), vector ℕ k → vector ℕ (k+1) :=\nλ k, nat.rec_on' k (λ _, ⟨[1], rfl⟩) (λ m _ _, nat.rec_on' m ⟨[1,1], rfl⟩\n  (λ _ ac, vector.cons (ac.head + ac.tail.head) ac))\n\ndef vfib (n : ℕ) : vector ℕ n :=\n  nat.rec_on n vector.nil next_fib\n\nlemma vfib_succ (n : ℕ) : vfib (succ (succ (succ n))) =\n  vector.cons ( (vfib (succ (succ n))).head + (vfib (succ (succ n))).tail.head)\n    (vfib (succ (succ n))) := rfl\n\nlemma vfib_succ_tail (n : ℕ) : (vfib (succ n)).tail = vfib n :=\nbegin\n  refine nat.rec_on n rfl _,\n  intro k,\n  refine nat.rec_on k _ _,\n  { intro h, refl, },\n  { intros m ih, rw vfib_succ, simp, },\nend\n  \nlemma vfib_formula (n : ℕ) :\n  (vfib (n+3)).head = (vfib (n+2)).head + (vfib (n+1)).head :=\nby simp [vfib_succ, vfib_succ_tail]\n\ndef vseq1 (n : ℕ) : vector ℕ n := nat.rec_on' n vector.nil (λ k seq_k, vector.cons (k*k) seq_k)\n\ndef seq (n : ℕ) : ℕ := nat.rec_on' n 6 (λ k seq_k, 5 + 2 * seq_k)\n\ndef add_one (n : ℕ) : ℕ := nat.rec_on n 1 (λ k h, succ h)\n\ndef add_one' (n : ℕ) : ℕ := @nat.rec_on (λ x, ℕ) n 1 (λ k h, succ h)\n\ndef add_two (n : ℕ) : ℕ := nat.rec_on n 2 (λ k h, succ h)\n\ndef add_two' (n : ℕ) : ℕ := @nat.rec_on (λ x, ℕ) n 2 (λ k h, succ h)\n\nexample (n : ℕ) : add_two n = add_two' n := rfl\n\nexample : add_one 4 = 5 := rfl\n\nexample : add_two 4 = 6 := rfl\n\ndef myadd (m n : ℕ) : ℕ := nat.rec_on n m (λ k h, succ h)\n\nexample : myadd 11 5 = 16 := rfl\n\nexample : ∀ n, add_two n = myadd 2 n := λ n, rfl\n\nlemma myadd_eq_add (m n : ℕ) : myadd m n = nat.add m n :=\nbegin\n  apply nat.rec_on n,\n  { refl, },\n  { intros k ih,\n    dsimp [myadd, nat.add] at *, rw ih, },\nend\n\ndef mymul (m n : ℕ) : ℕ := nat.rec_on n 0 (λ k h, myadd h m)\n\nlemma mymul_zero (m : ℕ) : mymul m 0 = 0 := rfl\n\nlemma mymul_succ (m n : ℕ) : mymul m (succ n) = myadd (mymul m n) m := rfl\n\nlemma mymul_eq_mul  (m n : ℕ) : mymul m n = nat.mul m n :=\nbegin\n  induction n with k ih,\n  { refl, },\n  { dsimp [mymul, nat.mul] at *, rw ih, rw myadd_eq_add, refl, }\nend\n\nend recursion_in_general\n\nend exlean", "meta": {"author": "gihanmarasingha", "repo": "exleanblog", "sha": "aa6dc06cb64376dc87ba680815b9d14a904ad2ff", "save_path": "github-repos/lean/gihanmarasingha-exleanblog", "path": "github-repos/lean/gihanmarasingha-exleanblog/exleanblog-aa6dc06cb64376dc87ba680815b9d14a904ad2ff/src/2021/06/what_the_rec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.89181104831338, "lm_q1q2_score": 0.7855045626722935}}
{"text": "/-\nTo prove that (∃ (p : P), Q) we show that there\nis a specific value, p, in the context of which\nwe can prove Q. \n-/\n\n/-\nHere's a silly example. We want to show that\nwe can pick some natural number in the context\nof which we can construct a proof of 1=1. Of\ncourse it doesn't matter what number we pick\nbecause 1=1 is true in any case. So in the\nfollowing example, we pick 524. But any value\nwill do. \n-/\n\nlemma silly : ∃ (n : ℕ), 1 = 1 :=\nexists.intro 524 rfl\n\n/-\nThe identifier, silly, is now bound to a\nproof of ∃ (n : ℕ), 1 = 1, and we can see\nthat this proof is actually an ordered pair,\nlabelled by the exists.intro constructor, the\nfirst element of which is a specific value of\ntype P and the second of which is a proof of Q.\n-/\n\n#reduce silly\n\n/-\nIn practice, Q will almost always be a\npredicate taking a value of type P. In\nthis case, ∃ (p : P), Q p asserts that\nthere is some value, p : P, that makes\nthe predicate, Q p true. In other words,\n∃ (p : P), Q p asserts that there is some\np with propery Q.\n-/\n\naxiom Ball : Type   -- assume there are Balls\naxioms b1 b2 : Ball -- b1 and b2 are balls\naxiom Blue : Ball → Prop -- Blue is a property\naxiom b1_is_blue : Blue b1 -- b1 is blue\n\n-- Prove there exists a blue ball\nexample : ∃ (b : Ball), Blue b :=\n-- use exists.intro\nexists.intro \n    b1          -- here's the ball we picked \n    b1_is_blue  -- here's a proof it's Blue\n\n/-\nHere's another example. We'll define ev to be\na predicate specifying a property of natural\nnumbers of \"being even\". Then we'll show that\nthere exists a number that has this property.\n-/\n\ndef even : ℕ → bool := λ n, n%2 = 0\n\nexample : exists (n : ℕ), even n :=\nexists.intro 6 rfl\n\n/-\nThe elimination rule for ∃ tells us what we\ncan do with a a proof of an existentially\nquanitified proposition.\n\nSuppose for example that we're given a proof\nthat there exists an even natural number. What\ncan we deduce from this fact? We can deduce\ntwo things: first, there is a specific number\nand *we can give it a name*, such as n, for \nwhich, second, there is a proof, that we can\nalso name, e.g., pf, that *that specific n* \nis even. This is the elimination rule. \n\nIt sounds complicated but it's not really.\nCompare exists.intro and exists.elim to \nand.intro and and.elim. The and.intro rule\ntakes two proofs and forms a pair. The and\nelimination rule takes such a pair and lets\nus get back (and give names to) the component\nproofs. Similarly, exists.intro forms a pair,\nof a value and a proof (usually a proof that\nthat specific value has some property); and\nthe exists.elimination rule, given a proof\nthat such a value exists, let's us then give\nnames to that value and the associated proof.\n*We can then use those two values in building\nother proofs*. And, as you might expect, we\nbind names to the component elements of a\nproof of ∃ (p : P), Q by case analysis, and\nspecifically by pattern matching.\n-/\n\n/-\nExample: Assume there are people and a binary\npredicate/relation called Likes.\n-/\naxiom Person : Prop\naxiom Likes : Person → Person → Prop\n\n/-\nShow that if there exists someone everyone\nlikes then everyone likes someone.\n-/\nexample :   (∃ (p : Person), ∀ (q : Person), Likes q p) →  \n            (∀ (p : Person), ∃ (q : Person), Likes p q):=\nλ h,                -- assume proof of ∃ (n : ℕ), even n\n    match h with    -- destructure this proof\n    -- there's only one constructor, exists.intro\n    -- give names to arguments to which it must have been applied \n    | exists.intro beloved liked_by_all := \n    -- now use *these* (now named) values to constructed needed proof\n        λ anyone, \n            exists.intro beloved (liked_by_all beloved)\n    end\n\n/-\nHere it is in plain English.\n\nSuppose there's someone everyone likes. Show that everyone\nlikes someone. \n\nProof: From the fact that there exists someone that everyone\nlikes, we can deduce that (1) there is a specific person, who\neveryone likes; let's call that person \"beloved\"; and (2) it\nis the case that everyone likes beloved. Now we must show that \neveryone likes someone. Pick an arbitrary but specific person,\ncall this person \"anyone\". We must show that there is someone\nthat \"anyone\" likes. But everyone likes beloved, so \"anyone\",\nin particular, likes \"beloved\". Note: \"anyone\" might or might\nnot like other people, but we can be sure that \"anyone\" likes\nbeloved, and all we needed to show was that there is someone\nthat \"anyone\" likes. QED.\n-/\n\n/-\nIn Lean, if you already have a proof of some existentially\nquantified proposition in your context, do case analysis on\nit to assign names to its two components: first a value and\nthen a proof that that value makes the rest of the proposition\ntrue. By the way, we call such a value a \"witness\" to the\ngiven proposition.\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/predicate_logic/intro_and_elim_rules/exists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7854939092609309}}
{"text": "\n/-\nTHIS ASSIGNMENT IS DUE BEFORE NEXT CLASS.\nWE WILL THEN REVIEW IT IN CLASS. FOLLOWING\nTHAT REVIEW WE WILL GIVE A BRIEF IN-CLASS,\nGRADED EXERCISE TO TEST YOUR UNDERSTANDING.\n\nThis file comes in two parts. The first\npart presents an example that you are to\nread and understand. It's an example of \na proof of a bi-implication between two\nequivalent disjunctions. The key lesson \nit teaches is proof by *case analysis*.\n\nWhen you are asked to prove that P ∨ Q \nimplies some conclusion, you do it by \ncase analysis. The idea is that if P ∨ Q \nis true, there are two ways in which it\ncan be true: either P is true, or Q is \ntrue. You have prove the goal follows \nin either case. If the goal follows in \neither case,  then it follows from the \ndisjunction, P ∨ Q, as a whole. \n\nWe use the \"cases\" tactic in lean to \nreason about the two possible cases of\na proof of P ∨ Q. Using this tactic \nproduces two subgoals. In one case, P \nis assumed to have a proof, p. In the\nother case, Q is assumed to have a proof,\nq. The aim then is to show that the main\ngoal follows in each case, as that will\nthen prove that the goal follows from \nthe disjunction as a whole.\n\nThe second part of this file presents a\nproblem for you to solve. One again it's\na bi-implication involving a disjunction\nas a premise (in one direction but not in\nthe other direction). \n\nIn both of these parts, we, or you will, \nstart by applying iff.intro to split the \nbi-implication into two implications to be proved. \n\nThen in the subproblems with disjunctions \nas premises, you will use case analysis. \nA hint: Remember that ¬ X means X → false,\nand the way to prove this is to assume X\nand show this leads to a contradiction. It\nis this maneuver that gets you a disjunction \nas a premise in the problem you're to solve.\n-/\n\n\n-- PART I: A WORKED EXAMPLE\n\n/-\nWe first show you how to prove P ∨ Q ↔ Q ∨ P.\nAt the highest level, the proof is by showing\nthe implication in each direction. Within each\ndirection, the proof is by case analysis for \nthe disjunction that forms the premise of the\nimplication. These ideas are explained in more\ndetail in the proof that follows.\n-/\n\ntheorem \nor_commutes :  \n    ∀ P Q: Prop, P ∨ Q ↔ Q ∨ P \n:=\nbegin\n\n/-\nIntroduce the assumptions that P and Q\nare arbitrary propositions.\n-/\nassume P Q: Prop,\n\n/-\nTo prove a bi-implication, we prove the\nimplications in each direction. That is, \nwe break the overall goal into subgoals, \none for the forward implication and one\nfor its converse (in the other direction).\n-/\napply iff.intro,\n\n    -- now we prove the forward implication\n    assume pq : P ∨ Q,\n    show Q ∨ P,\n    from\n        begin\n        /-\n        The key proof technique for reasoning \n        from a proof of a disjunction, P ∨ Q,\n        is to consider two possible cases for \n        this proof, that either P is true or \n        Q is, and to show that the goal is\n        true in either case. This shows that\n        no matter why P ∨ Q is true, the goal\n        follows.\n    \n        So, the proof strategy is first to \n        assumes that P ∨ Q is true because P \n        is true, which is to say you assume \n        you have a proof of P, and then show \n        that the goal follows. Then you assume \n        P ∨ Q is true because Q is true, and \n        you show that given an assumed proof\n        of Q, the goal follows. The goal thus\n        follows in either case. \n\n        The tactic that we use in Lean to \n        reason by cases from a disjunction is \n        called \"cases.\" As arguments you give \n        it (1) the name of the disjunction to \n        reason from, and (2) names to use for \n        the assumed proofs of P and Q in the \n        respective cases (after keyword \"with\").  \n\n        So here we go. Make sure you have the \n        Lean Messages window open so that you \n        can see how \"cases\" changes your tactic \n        state. Note that it introduces two new \n        subgoals. In the first, there is an \n        assumed proof, p : P. In the second, \n        there is an an assumed proof q : Q.\n        -/\n        cases pq with p q,\n        -- now prove each case separately\n\n            -- proof for case where P is true\n            show Q ∨ P,\n            from or.intro_right Q p,\n\n            -- proof for case where Q is true\n            show Q ∨ P,\n            from or.intro_left P q,\n        end,\n    \n    -- and now we prove the converse\n    assume qp : Q ∨ P,\n    show P ∨ Q,\n    from \n        begin\n        cases qp with q p,\n            show P ∨ Q,\n            from or.intro_right P q,\n            show P ∨ Q,\n            from or.intro_left Q p,\n        end,\nend\n\n\n\n-- PART II: YOUR HOMEWORK ASSIGNMENT\n\n/-\nHomework: \n\nProve, ∀ P Q: Prop, ¬ P ∧ ¬ Q ↔ ¬ (P ∨ Q) \n\n-/\n\ntheorem aDemorganLaw : \n    ∀ P Q: Prop, ¬ P ∧ ¬ Q ↔ ¬ (P ∨ Q) :=\nbegin\n\n    assume P Q : Prop,\n    apply iff.intro, \n    -- forward\n    assume npnq : ¬ P ∧ ¬ Q,\n    show ¬ (P ∨ Q),\n    from\n        begin\n            assume pq : (P ∨ Q),\n            cases pq with p q, \n\n            show false,\n            from npnq.1 p, \n\n            show false,\n            from npnq.2 q,\n        end,\n\n    --backwards\n    assume nporq : ¬ (P ∨ Q),\n    --show not p\n    have np : ¬ P,\n    from\n        begin\n        assume p : P, \n\n        have  pq : (P ∨ Q),\n        from\n            begin\n            apply or.intro_left,\n            show P,\n            from p,\n            end,\n<<<<<<< HEAD\n        \n        --left side\n        -- to get a proof of ¬ P ∧ ¬ Q we need \n        -- both ¬ P and ¬ Q and then use and.intro\n        -- Show a contratradiction by first assuming\n        -- P and Q are true, then show they must be \n        -- false, then use and.intro\n        assume nporq : ¬ (P ∨ Q),\n\n        have np : ¬ P,\n        from\n            begin\n            assume p : P,\n\n            have porq : P ∨ Q,\n            from\n                begin\n                apply or.intro_left,\n                show P,\n                from p,\n                end,\n            \n            show false,\n            from nporq porq,\n            end,\n        \n        have nq : ¬ Q,\n        from\n            begin\n            assume q : Q,\n\n            have porq : P ∨ Q,\n            from\n                begin\n                apply or.intro_right,\n                show Q,\n                from q,\n                end,\n            \n            show false,\n            from nporq porq,\n            end,\n        \n        exact and.intro np nq         \n=======\n\n        show false,\n        from nporq pq,\n        end,\n    --show not\n    have nq : ¬ Q,\n    from\n        begin\n        assume q : Q,\n\n        have pq : (P ∨ Q),\n        from\n            begin\n            apply or.intro_right,\n            show Q,\n            from q,\n            end,\n        \n        show false,\n        from nporq pq,\n        end,\n\n>>>>>>> 7bf877fc487881e7123ecc6a6cc372d320cd5eed\nend", "meta": {"author": "Mnormansell", "repo": "Discrete-Notes", "sha": "61f13b98be590269fc4822be7b47924a6ddc1261", "save_path": "github-repos/lean/Mnormansell-Discrete-Notes", "path": "github-repos/lean/Mnormansell-Discrete-Notes/Discrete-Notes-61f13b98be590269fc4822be7b47924a6ddc1261/HW/HW4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7854939091226651}}
{"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 α] : Trans (α := α) (· < ·) (· < ·) (· < ·) 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\n-- same-line `calc <first relation>` with normal indent afterwards\ntheorem foo₂ : t1 < t5 :=\n  calc t1 = t2 := pf12\n    _  < t3 := pf23'\n    _  = t4 := pf34\n    _  < t5 := pf45'\n\n-- `calc <first relation LHS>\\n<indent><relation and relation RHS>`\ntheorem foo₃ : t1 < t5 :=\n  calc t1\n      = t2 := pf12\n    _ < t3 := pf23'\n    _ = t4 := pf34\n    _ < t5 := pf45'\n\n-- `calc <first relation LHS>\\n<indent><relation and relation RHS>`\ntheorem foo₄ : t1 < t5 :=\n  calc t1 = t2 := pf12\n       _  < t3 := pf23'\n       _  = t4 := pf34\n       _  < t5 := pf45'\n\n-- `by` with indented sequence of tactics in `calc`-item RHS\ntheorem foo₅ : t1 = t4 :=\n  calc\n    t1 = t2 := pf12\n    _  = t3 := by\n      skip\n      skip\n      exact pf23\n    _  = t4 := pf34\n\n-- function application with indented argument in `calc`-item RHS\ntheorem foo₆ : t1 = t4 :=\n  calc\n    t1 = t2 := pf12\n    _  = t3 := id\n      pf23\n    _  = t4 := pf34\n\n-- `calc <first relation LHS>\\n<indent>_ <rel> <rhs> := <proof>` (term)\ntheorem foo₇ : t1 < t5 :=\n  calc t1\n    _ = t2 := pf12\n    _ < t3 := pf23'\n    _ = t4 := pf34\n    _ < t5 := pf45'\n\n-- `calc <first relation LHS>\\n<indent>_ <rel> <rhs> := <proof>` (tactic)\ntheorem foo₈ : t1 < t5 := by\n  calc t1\n    _ = t2 := pf12\n    _ < t3 := pf23'\n    _ = t4 := pf34\n    _ < t5 := pf45'\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/calc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973294, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7854757064887705}}
{"text": "-- El_producto_por_un_par_es_par.lean\n-- El producto por un par es par.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 21-agosto-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que los productos de los números naturales por números\n-- pares son pares.\n-- ---------------------------------------------------------------------\n\nimport data.nat.parity\nimport tactic\n\nopen nat\n\n-- 1ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  intros m n hn,\n  unfold even at *,\n  cases hn with k hk,\n  use m * k,\n  calc m * n\n       = m * (k + k)   : congr_arg (has_mul.mul m) hk\n   ... = m * k + m * k : mul_add m k k\nend\n\n-- 2ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  intros m n hn,\n  cases hn with k hk,\n  use m * k,\n  calc m * n\n       = m * (k + k)   : congr_arg (has_mul.mul m) hk\n   ... = m * k + m * k : mul_add m k k\nend\n\n-- 3ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  rintros m n ⟨k, hk⟩,\n  use m * k,\n  calc m * n\n       = m * (k + k)   : congr_arg (has_mul.mul m) hk\n   ... = m * k + m * k : mul_add m k k\nend\n\n-- 4ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  rintros m n ⟨k, hk⟩,\n  use m * k,\n  rw hk,\n  exact mul_add m k k,\nend\n\n-- 5ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  rintros m n ⟨k, hk⟩,\n  use m * k,\n  rw [hk, mul_add]\nend\n\n-- 6ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  rintros m n ⟨k, hk⟩,\n  exact ⟨m * k, by rw [hk, mul_add]⟩\nend\n\n-- 7ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\nλ m n ⟨k, hk⟩, ⟨m * k, by rw [hk, mul_add]⟩\n\n-- 8ª demostración\nexample : ∀ m n : ℕ, even n → even (m * n) :=\n  assume m n ⟨k, (hk : n = k + k)⟩,\n  have hmn : m * n = m * k + m * k,\n    by rw [hk, mul_add],\n  show ∃ l, m * n = l + l,\n    from ⟨_, hmn⟩\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_producto_por_un_par_es_par.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7854757029841535}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.trace\n! leanprover-community/mathlib commit 32b08ef840dd25ca2e47e035c5da03ce16d2dc3c\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# Trace of a matrix\n\nThis file defines the trace of a matrix, the map sending a matrix to the sum of its diagonal\nentries.\n\nSee also `linear_algebra.trace` for the trace of an endomorphism.\n\n## Tags\n\nmatrix, trace, diagonal\n\n-/\n\n\nopen BigOperators Matrix\n\nnamespace Matrix\n\nvariable {ι m n p : Type _} {α R S : Type _}\n\nvariable [Fintype m] [Fintype n] [Fintype p]\n\nsection AddCommMonoid\n\nvariable [AddCommMonoid R]\n\n/-- The trace of a square matrix. For more bundled versions, see:\n* `matrix.trace_add_monoid_hom`\n* `matrix.trace_linear_map`\n-/\ndef trace (A : Matrix n n R) : R :=\n  ∑ i, diag A i\n#align matrix.trace Matrix.trace\n\nvariable (n R)\n\n@[simp]\ntheorem trace_zero : trace (0 : Matrix n n R) = 0 :=\n  (Finset.sum_const (0 : R)).trans <| smul_zero _\n#align matrix.trace_zero Matrix.trace_zero\n\nvariable {n R}\n\n@[simp]\ntheorem trace_add (A B : Matrix n n R) : trace (A + B) = trace A + trace B :=\n  Finset.sum_add_distrib\n#align matrix.trace_add Matrix.trace_add\n\n@[simp]\ntheorem trace_smul [Monoid α] [DistribMulAction α R] (r : α) (A : Matrix n n R) :\n    trace (r • A) = r • trace A :=\n  Finset.smul_sum.symm\n#align matrix.trace_smul Matrix.trace_smul\n\n@[simp]\ntheorem trace_transpose (A : Matrix n n R) : trace Aᵀ = trace A :=\n  rfl\n#align matrix.trace_transpose Matrix.trace_transpose\n\n@[simp]\ntheorem trace_conjTranspose [StarAddMonoid R] (A : Matrix n n R) : trace Aᴴ = star (trace A) :=\n  (star_sum _ _).symm\n#align matrix.trace_conj_transpose Matrix.trace_conjTranspose\n\nvariable (n α R)\n\n/-- `matrix.trace` as an `add_monoid_hom` -/\n@[simps]\ndef traceAddMonoidHom : Matrix n n R →+ R\n    where\n  toFun := trace\n  map_zero' := trace_zero n R\n  map_add' := trace_add\n#align matrix.trace_add_monoid_hom Matrix.traceAddMonoidHom\n\n/-- `matrix.trace` as a `linear_map` -/\n@[simps]\ndef traceLinearMap [Semiring α] [Module α R] : Matrix n n R →ₗ[α] R\n    where\n  toFun := trace\n  map_add' := trace_add\n  map_smul' := trace_smul\n#align matrix.trace_linear_map Matrix.traceLinearMap\n\nvariable {n α R}\n\n@[simp]\ntheorem trace_list_sum (l : List (Matrix n n R)) : trace l.Sum = (l.map trace).Sum :=\n  map_list_sum (traceAddMonoidHom n R) l\n#align matrix.trace_list_sum Matrix.trace_list_sum\n\n@[simp]\ntheorem trace_multiset_sum (s : Multiset (Matrix n n R)) : trace s.Sum = (s.map trace).Sum :=\n  map_multiset_sum (traceAddMonoidHom n R) s\n#align matrix.trace_multiset_sum Matrix.trace_multiset_sum\n\n@[simp]\ntheorem trace_sum (s : Finset ι) (f : ι → Matrix n n R) :\n    trace (∑ i in s, f i) = ∑ i in s, trace (f i) :=\n  map_sum (traceAddMonoidHom n R) f s\n#align matrix.trace_sum Matrix.trace_sum\n\nend AddCommMonoid\n\nsection AddCommGroup\n\nvariable [AddCommGroup R]\n\n@[simp]\ntheorem trace_sub (A B : Matrix n n R) : trace (A - B) = trace A - trace B :=\n  Finset.sum_sub_distrib\n#align matrix.trace_sub Matrix.trace_sub\n\n@[simp]\ntheorem trace_neg (A : Matrix n n R) : trace (-A) = -trace A :=\n  Finset.sum_neg_distrib\n#align matrix.trace_neg Matrix.trace_neg\n\nend AddCommGroup\n\nsection One\n\nvariable [DecidableEq n] [AddCommMonoidWithOne R]\n\n@[simp]\ntheorem trace_one : trace (1 : Matrix n n R) = Fintype.card n := by\n  simp_rw [trace, diag_one, Pi.one_def, Finset.sum_const, nsmul_one, Finset.card_univ]\n#align matrix.trace_one Matrix.trace_one\n\nend One\n\nsection Mul\n\n@[simp]\ntheorem trace_transpose_mul [AddCommMonoid R] [Mul R] (A : Matrix m n R) (B : Matrix n m R) :\n    trace (Aᵀ ⬝ Bᵀ) = trace (A ⬝ B) :=\n  Finset.sum_comm\n#align matrix.trace_transpose_mul Matrix.trace_transpose_mul\n\ntheorem trace_mul_comm [AddCommMonoid R] [CommSemigroup R] (A : Matrix m n R) (B : Matrix n m R) :\n    trace (A ⬝ B) = trace (B ⬝ A) := by rw [← trace_transpose, ← trace_transpose_mul, transpose_mul]\n#align matrix.trace_mul_comm Matrix.trace_mul_comm\n\ntheorem trace_mul_cycle [NonUnitalCommSemiring R] (A : Matrix m n R) (B : Matrix n p R)\n    (C : Matrix p m R) : trace (A ⬝ B ⬝ C) = trace (C ⬝ A ⬝ B) := by\n  rw [trace_mul_comm, Matrix.mul_assoc]\n#align matrix.trace_mul_cycle Matrix.trace_mul_cycle\n\ntheorem trace_mul_cycle' [NonUnitalCommSemiring R] (A : Matrix m n R) (B : Matrix n p R)\n    (C : Matrix p m R) : trace (A ⬝ (B ⬝ C)) = trace (C ⬝ (A ⬝ B)) := by\n  rw [← Matrix.mul_assoc, trace_mul_comm]\n#align matrix.trace_mul_cycle' Matrix.trace_mul_cycle'\n\n@[simp]\ntheorem trace_col_mul_row [NonUnitalNonAssocSemiring R] (a b : n → R) :\n    trace (col a ⬝ row b) = dotProduct a b := by simp [dot_product, trace]\n#align matrix.trace_col_mul_row Matrix.trace_col_mul_row\n\nend Mul\n\nsection Fin\n\nvariable [AddCommMonoid R]\n\n/-! ### Special cases for `fin n`\n\nWhile `simp [fin.sum_univ_succ]` can prove these, we include them for convenience and consistency\nwith `matrix.det_fin_two` etc.\n-/\n\n\n@[simp]\ntheorem trace_fin_zero (A : Matrix (Fin 0) (Fin 0) R) : trace A = 0 :=\n  rfl\n#align matrix.trace_fin_zero Matrix.trace_fin_zero\n\ntheorem trace_fin_one (A : Matrix (Fin 1) (Fin 1) R) : trace A = A 0 0 :=\n  add_zero _\n#align matrix.trace_fin_one Matrix.trace_fin_one\n\ntheorem trace_fin_two (A : Matrix (Fin 2) (Fin 2) R) : trace A = A 0 0 + A 1 1 :=\n  congr_arg ((· + ·) _) (add_zero (A 1 1))\n#align matrix.trace_fin_two Matrix.trace_fin_two\n\ntheorem trace_fin_three (A : Matrix (Fin 3) (Fin 3) R) : trace A = A 0 0 + A 1 1 + A 2 2 :=\n  by\n  rw [← add_zero (A 2 2), add_assoc]\n  rfl\n#align matrix.trace_fin_three Matrix.trace_fin_three\n\nend Fin\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/Trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7854757029298479}}
{"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 ring_theory.mv_polynomial.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.Ideal\nimport Mathbin.Data.MvPolynomial.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\n\nvariable {σ R : Type _}\n\nnamespace MvPolynomial\n\nvariable [CommSemiring R]\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 ≤ xi` is analogous to saying that the monomial corresponding to `si`\ndivides the monomial corresponding to `xi`. -/\ntheorem mem_ideal_span_monomial_image {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} :\n    x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔ ∀ xi ∈ x.support, ∃ si ∈ s, si ≤ xi :=\n  by\n  refine' add_monoid_algebra.mem_ideal_span_of'_image.trans _\n  simp_rw [le_iff_exists_add, add_comm]\n  rfl\n#align mv_polynomial.mem_ideal_span_monomial_image MvPolynomial.mem_ideal_span_monomial_image\n\ntheorem mem_ideal_span_monomial_image_iff_dvd {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} :\n    x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔\n      ∀ xi ∈ x.support, ∃ si ∈ s, monomial si 1 ∣ monomial xi (x.coeff xi) :=\n  by\n  refine' mem_ideal_span_monomial_image.trans (forall₂_congr fun xi hxi => _)\n  simp_rw [monomial_dvd_monomial, one_dvd, and_true_iff, mem_support_iff.mp hxi, false_or_iff]\n#align mv_polynomial.mem_ideal_span_monomial_image_iff_dvd MvPolynomial.mem_ideal_span_monomial_image_iff_dvd\n\n/-- `x` is in a monomial ideal generated by variables `X` iff every element of of its support\nhas a component in `s`. -/\ntheorem mem_ideal_span_x_image {x : MvPolynomial σ R} {s : Set σ} :\n    x ∈ Ideal.span (MvPolynomial.X '' s : Set (MvPolynomial σ R)) ↔\n      ∀ m ∈ x.support, ∃ i ∈ s, (m : σ →₀ ℕ) i ≠ 0 :=\n  by\n  have := @mem_ideal_span_monomial_image σ R _ _ ((fun 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]\n#align mv_polynomial.mem_ideal_span_X_image MvPolynomial.mem_ideal_span_x_image\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/Ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7854545916684331}}
{"text": "/-\nLet X, Y, Z be sets, and let f : X → Y and g : Y → Z be functions.\n(a) Given that g ∘ f is onto, can you deduce that f is onto? Give a proof\nor a counterexample.\n(b) Given that g ∘ f is onto, can you deduce that g is onto?\n(c) Given that g ∘ f is 1-1, can you deduce that f is 1-1?\n(d) Given that g ∘ f is 1-1, can you deduce that g is 1-1?\n-/\nimport tactic\n\nopen function -- so we can write `injective`/`surjective` instead of `function.injective`/`function.surjective`\n\n-- For each of the parts below, if you think it's false then stick `¬` in front of it before you start proving it.\n\n\n-- The below is for counterexamples\n-- Let X be {a}\ninductive X : Type\n| a : X\n\n-- Let Y be {b,c}\ninductive Y : Type\n| b : Y\n| c : Y\n\n-- Let Z be {d}\ninductive Z : Type\n| d : Z\n\n-- Define f by f(X.a)=Y.b\ndef f : X → Y\n| X.a := Y.b\n\n-- define g by g(Y.b)=g(Y.c)=Z.d\ndef g : Y → Z\n| Y.b := Z.d\n| Y.c := Z.d\n\nlemma parta : ¬ (∀ (X Y Z : Type) (f : X → Y) (g : Y → Z), surjective (g ∘ f) → surjective f) :=\nbegin\n  by_contra,\n  specialize h X Y Z f g,\n  have hgf : surjective (g ∘ f),\n  { rintro z,\n    cases z,\n    use X.a,\n    refl },\n  obtain ⟨⟨⟩, ⟨⟩⟩ := h hgf Y.c,\nend\n\nlemma partb : ∀ (X Y Z : Type) (f : X → Y) (g : Y → Z), surjective (g ∘ f) → surjective g :=\nbegin\n  intros X Y Z f g hgf b,\n  obtain ⟨a, hgf⟩ := hgf b,\n  exact ⟨f a, hgf⟩,\nend\n\nlemma gf_injective : injective (g ∘ f) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ _,\n  refl,\nend\n\nlemma partc : ∀ (X Y Z : Type) (f : X → Y) (g : Y → Z), injective (g ∘ f) → injective f :=\nbegin\n  intros X Y Z f g hgf a b hf,\n  have hg : g (f a) = g (f b),\n  { rw hf },\n  exact hgf hg,\nend\n\nlemma partd : ¬ (∀ (X Y Z : Type) (f : X → Y) (g : Y → Z), injective (g ∘ f) → injective g) :=\nbegin\n  by_contra,\n  specialize h X Y Z f g,\n  specialize h gf_injective,\n  have hy : g Y.b = g Y.c,\n  { unfold g },\n  specialize h hy,\n  simpa using h,\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/chapter19/exercises/exercise04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620468, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7854545857361969}}
{"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\n\nThe power function on the natural numbers.\n-/\nimport data.nat.basic data.nat.order data.nat.div data.nat.gcd algebra.ring_power\n\nnamespace nat\n\ndefinition nat_has_pow_nat [instance] [priority nat.prio] : has_pow_nat nat :=\nhas_pow_nat.mk has_pow_nat.pow_nat\n\ntheorem pow_le_pow_of_le {x y : ℕ} (i : ℕ) (H : x ≤ y) : x^i ≤ y^i :=\npow_le_pow_of_le i !zero_le H\n\ntheorem eq_zero_of_pow_eq_zero {a m : ℕ} (H : a^m = 0) : a = 0 :=\nor.elim (eq_zero_or_pos m)\n  (suppose m = 0,\n    by rewrite [`m = 0` at H, pow_zero at H]; contradiction)\n  (suppose m > 0,\n    have h₁ : ∀ m, a^succ m = 0 → a = 0,\n      begin\n        intro m,\n        induction m with m ih,\n          {krewrite pow_one; intros; assumption},\n        rewrite pow_succ,\n        intro H,\n        cases eq_zero_or_eq_zero_of_mul_eq_zero H with h₃ h₄,\n          assumption,\n        exact ih h₄\n      end,\n    obtain m' (h₂ : m = succ m'), from exists_eq_succ_of_pos `m > 0`,\n    show a = 0, by rewrite h₂ at H; apply h₁ m' H)\n\n-- generalize to semirings?\ntheorem le_pow_self {x : ℕ} (H : x > 1) : ∀ i, i ≤ x^i\n| 0        := !zero_le\n| (succ j) := have x > 0,        from lt.trans zero_lt_one H,\n              have h₁ : x^j ≥ 1, from succ_le_of_lt (pow_pos_of_pos _ this),\n              have x ≥ 2,        from succ_le_of_lt H,\n              calc\n                succ j = j + 1         : rfl\n                   ... ≤ x^j + 1       : add_le_add_right (le_pow_self j)\n                   ... ≤ x^j + x^j     : add_le_add_left h₁\n                   ... = x^j * (1 + 1) : by rewrite [left_distrib, *mul_one]\n                   ... = x^j * 2       : rfl\n                   ... ≤ x^j * x       : mul_le_mul_left _ `x ≥ 2`\n                   ... = x^(succ j)    : pow_succ'\n\n-- TODO: eventually this will be subsumed under the algebraic theorems\n\ntheorem mul_self_eq_pow_2 (a : nat) : a * a = a ^ 2 :=\nshow a * a = a ^ (succ (succ zero)), from\nby krewrite [*pow_succ, *pow_zero, mul_one]\n\ntheorem pow_cancel_left : ∀ {a b c : nat}, a > 1 → a ^ b = a ^ c → b = c\n| a 0        0        h₁ h₂ := rfl\n| a (succ b) 0        h₁ h₂ :=\n  have a = 1, by rewrite [pow_succ at h₂, pow_zero at h₂]; exact (eq_one_of_mul_eq_one_right h₂),\n  have (1:nat) < 1, by rewrite [this at h₁]; exact h₁,\n  absurd `1 <[nat] 1` !lt.irrefl\n| a 0        (succ c) h₁ h₂ :=\n  have a = 1, by rewrite [pow_succ at h₂, pow_zero at h₂]; exact (eq_one_of_mul_eq_one_right (eq.symm h₂)),\n  have (1:nat) < 1, by rewrite [this at h₁]; exact h₁,\n  absurd `1 <[nat] 1` !lt.irrefl\n| a (succ b) (succ c) h₁ h₂ :=\n  have a ≠ 0, from assume aeq0, by rewrite [aeq0 at h₁]; exact (absurd h₁ dec_trivial),\n  have a^b = a^c, by rewrite [*pow_succ at h₂]; exact (eq_of_mul_eq_mul_left (pos_of_ne_zero this) h₂),\n  by rewrite [pow_cancel_left h₁ this]\n\ntheorem pow_div_cancel : ∀ {a b : nat}, a ≠ 0 → (a ^ succ b) / a = a ^ b\n| a 0        h := by rewrite [pow_succ, pow_zero, mul_one, nat.div_self (pos_of_ne_zero h)]\n| a (succ b) h := by rewrite [pow_succ, nat.mul_div_cancel_left _ (pos_of_ne_zero h)]\n\nlemma dvd_pow : ∀ (i : nat) {n : nat}, n > 0 → i ∣ i^n\n| i 0        h := absurd h !lt.irrefl\n| i (succ n) h := by rewrite [pow_succ']; apply dvd_mul_left\n\nlemma dvd_pow_of_dvd_of_pos : ∀ {i j n : nat}, i ∣ j → n > 0 → i ∣ j^n\n| i j 0        h₁ h₂ := absurd h₂ !lt.irrefl\n| i j (succ n) h₁ h₂ := by rewrite [pow_succ']; apply dvd_mul_of_dvd_right h₁\n\nlemma pow_mod_eq_zero (i : nat) {n : nat} (h : n > 0) : (i ^ n) % i = 0 :=\niff.mp !dvd_iff_mod_eq_zero (dvd_pow i h)\n\nlemma pow_dvd_of_pow_succ_dvd {p i n : nat} : p^(succ i) ∣ n → p^i ∣ n :=\nsuppose p^(succ i) ∣ n,\nhave p^i ∣ p^(succ i),\n  by rewrite [pow_succ']; apply nat.dvd_of_eq_mul; apply rfl,\ndvd.trans `p^i ∣ p^(succ i)` `p^(succ i) ∣ n`\n\nlemma dvd_of_pow_succ_dvd_mul_pow {p i n : nat} (Ppos : p > 0) :\n  p^(succ i) ∣ (n * p^i) → p ∣ n :=\nby rewrite [pow_succ]; apply nat.dvd_of_mul_dvd_mul_right; apply pow_pos_of_pos _ Ppos\n\nlemma coprime_pow_right {a b} : ∀ n, coprime b a → coprime b (a^n)\n| 0        h := !comprime_one_right\n| (succ n) h :=\n  begin\n    rewrite [pow_succ'],\n    apply coprime_mul_right,\n      exact coprime_pow_right n h,\n      exact h\n  end\n\nlemma coprime_pow_left {a b} : ∀ n, coprime b a → coprime (b^n) a :=\ntake n, suppose coprime b a,\ncoprime_swap (coprime_pow_right n (coprime_swap this))\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/power.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7854545856063576}}
{"text": "import data.equiv.basic\n\n/-\n\ndata.equiv.basic  is the import which gives you the type `equiv X Y`, the type of\nbijections from X to Y.\n\nHere's the definition of equiv from that file.\n\nstructure equiv (α : Sort*) (β : Sort*) :=\n(to_fun    : α → β)\n(inv_fun   : β → α)\n(left_inv  : left_inverse inv_fun to_fun)\n(right_inv : right_inverse inv_fun to_fun)\n\nTo make a term of type `equiv α β` you have to supply a function α → β,\na function β → α, and proofs that both composites are the identity function.\n\nLet's see how to create the bijection ℤ → ℤ sending x to -x.\n-/\n-- let's prove that x ↦ -x can be extended to\nexample : equiv ℤ ℤ :=\n{ to_fun := λ x, -x, -- this is data\n  inv_fun := λ x, -x,  -- this is data\n  left_inv := begin -- this is a proof\n    change ∀ (x : ℤ), - -x = x, -- that's the question\n    exact neg_neg, -- note: I guessed what this function was called.\n                   -- If it had been called \"lemma 12\" I would not have been able to guess\n  end,\n  right_inv := neg_neg -- another proof, this time in term mode\n}\n\n/-\nQ1 Define the type of partitions of a type.\nA partition of X is a set of subsets of X with the property that each subset\nis non-empty and each element of X is in precisely one of the subsets.\nNB : this is one of the harder questions here.\n-/\n\nstructure partition (X : Type*) :=\n(ℱ : set (set X))\n(disjoint : ∀ A B ∈ ℱ, A ≠ B → A ∩ B = ∅)\n(cover : ∀ x : X, ∃ A ∈ ℱ, x ∈ A)\n(nonempty : ∀ A ∈ ℱ, A ≠ ∅)\n\n\n/-\nEquivalence relations are in core Lean -- we don't need any imports.\nHere's an example: I'll prove that the \"always true\" relation on a set is\nan equivalence relation.\n\n-/\n\ndef always_true (X : Type*) : X → X → Prop := λ a b, true\n\n-- and now here's the proof that it's an equivalence relation.\n\ntheorem always_true_refl (X) : reflexive (always_true X) :=\nbegin\n  intro x,\n  trivial\nend\n\ntheorem always_true_symm (X) : symmetric (always_true X) :=\nbegin\n  intros a b H,\n  trivial\nend\n\ntheorem always_true_trans (X) : transitive (always_true X) :=\nbegin\n  intros a b c Hab Hbc,\n  trivial\nend\n\n-- note pointy brackets to make a term of type \"A ∧ B ∧ C\"\ntheorem always_true_equiv (X): equivalence (always_true X) :=\n⟨always_true_refl X, always_true_symm X, always_true_trans X⟩\n-- autocomplete made that proof really easy to type. It's really\n-- lucky that I didn't call these lemmas lemma 12, lemma 13 and lemma 14.\n\n-- if X is a type, then `setoid X` is is the type of equivalence relations on X.\n-- I'll now make a term of type `setoid X` corresponding to that equivalence\n-- relation above.\n\n-- note squiggly brackets and commas at the end of each definition to make a structure\ndef always_true_setoid (X : Type*) : setoid X :=\n{ r := always_true X,\n  iseqv := always_true_equiv X }\n\n/-\nQ2 : If X is a type then `setoid X` is the type of equivalence relations on X,\nand `partitions X` is the type of partitions of X. These two concepts are in\nsome sort of \"canonical\" bijection with each other (interesting exercise: make\nthis statement mathematically meaningful -- I know we all say it, but what\ndoes it *mean*?).\n\nLet's prove that these sets biject with each other by defining\na term of type equiv (setoid X) (partitions X)\n-/\n\nvariable {X : Type*}\n\ndef F (S : setoid X) : partition X := sorry\n\n/-\nQ3 : now define a map the other way\n-/\n\ndef G (P : partition X) : setoid X := sorry\n\n/-\nQ4 : now finally prove that the composite of maps in both directions\nis the identity\n-/\n\ntheorem FG_eq_id (P : partition X) : F (G P) = P := sorry\ntheorem GF_eq_id (S : setoid X) : G (F S) = S := sorry\n\n/-\nQ5 : now finally construct the term we seek.\n-/\n\ndef partitions_biject_with_equivalence_relations :\n  equiv (setoid X) (partition X) := sorry\n", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/partitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7854545819431441}}
{"text": "/-\nCopyright (c) 2020 David Wärn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: David Wärn\n-/\nimport order.basic\nimport data.equiv.encodable.basic\nimport order.atoms\n\n/-!\n# Order ideals, cofinal sets, and the Rasiowa–Sikorski 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- `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 𝒟`, where `p : P`, and `𝒟` is a countable family of cofinal\n  subsets of P: an ideal in `P` which contains `p` and intersects every set in `𝒟`. (This a form\n  of the Rasiowa–Sikorski 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–Sikorski 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 (≤) carrier)\n(mem_of_le : ∀ {x y : P}, x ≤ y → y ∈ carrier → x ∈ 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 (≤) I)\n(mem_of_le : ∀ {x y : P}, x ≤ y → y ∈ I → x ∈ 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⟨I, h.1, h.2, h.3⟩\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 (P) [preorder P] : Prop :=\n(inter_nonempty : ∀ (I J : ideal P), (I.carrier ∩ J.carrier).nonempty)\n\nlemma inter_nonempty [preorder P] [ideal_inter_nonempty P] :\n∀ (I J : ideal P), (I.carrier ∩ J.carrier).nonempty :=\nideal_inter_nonempty.inter_nonempty\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 ≤ p },\n  nonempty  := ⟨p, le_refl _⟩,\n  directed  := λ x hx y hy, ⟨p, le_refl _, hx, hy⟩,\n  mem_of_le := λ x y hxy hy, le_trans hxy hy, }\n\ninstance [inhabited P] : inhabited (ideal P) :=\n⟨ideal.principal $ default P⟩\n\n/-- An ideal of `P` can be viewed as a subset of `P`. -/\ninstance : has_coe (ideal P) (set P) := ⟨carrier⟩\n\n/-- For the notation `x ∈ I`. -/\ninstance : has_mem P (ideal P) := ⟨λ x I, x ∈ (I : set P)⟩\n\n@[simp] lemma mem_coe : x ∈ (I : set P) ↔ x ∈ I := iff_of_eq rfl\n\n@[simp] lemma mem_principal : x ∈ principal y ↔ x ≤ y := by refl\n\n/-- Two ideals are equal when their underlying sets are equal. -/\n@[ext] lemma ext : ∀ (I J : ideal P), (I : set P) = J → I = J\n| ⟨_, _, _, _⟩ ⟨_, _, _, _⟩ rfl := rfl\n\n@[simp, norm_cast] lemma ext_set_eq {I J : ideal P} : (I : set P) = J ↔ I = J :=\n⟨by ext, congr_arg _⟩\n\nlemma ext'_iff {I J : ideal P} : I = J ↔ (I : set P) = J := ext_set_eq.symm\n\nlemma is_ideal (I : ideal P) : is_ideal (I : set P) := ⟨I.2, I.3, I.4⟩\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 ∈ I → I ≤ J → x ∈ J :=\n@set.mem_of_mem_of_subset P x I J\n\n@[simp] lemma principal_le_iff : principal x ≤ I ↔ x ∈ I :=\n⟨λ (h : ∀ {y}, y ≤ x → y ∈ I), h (le_refl x),\n λ h_mem y (h_le : y ≤ x), I.mem_of_le h_le h_mem⟩\n\nlemma mem_compl_of_ge {x y : P} : x ≤ y → x ∈ (I : set P)ᶜ → y ∈ (I : set P)ᶜ :=\nλ 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) ≠ set.univ)\n\nlemma is_proper_of_not_mem {I : ideal P} {p : P} (nmem : p ∉ I) : is_proper I :=\n⟨λ hp, begin\n  change p ∉ ↑I at nmem,\n  rw hp at nmem,\n  exact nmem (set.mem_univ p),\nend⟩\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 : ∀ ⦃J : ideal P⦄, I < J → J.carrier = set.univ)\n\nend preorder\n\nsection order_bot\nvariables [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 : ⊥ ∈ 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 ⊥,\n  bot_le := by simp,\n  .. ideal.partial_order }\n\nend order_bot\n\nsection order_top\n\nvariables [order_top P]\n\n/-- There is a top ideal when `P` has a top element. -/\ninstance : order_top (ideal P) :=\n{ top := principal ⊤,\n  le_top := λ I x h, le_top,\n  .. ideal.partial_order }\n\n@[simp] lemma top_carrier : (⊤ : ideal P).carrier = set.univ :=\nset.univ_subset_iff.1 (λ p _, le_top)\n\n@[simp] lemma top_coe : ((⊤ : ideal P) : set P) = set.univ := top_carrier\n\nlemma top_of_mem_top {I : ideal P} (mem_top : ⊤ ∈ I) : I = ⊤ :=\nbegin\n  ext,\n  change x ∈ I.carrier ↔ x ∈ (⊤ : ideal P).carrier,\n  split,\n  { simp [top_carrier] },\n  { exact λ _, I.mem_of_le le_top mem_top }\nend\n\nlemma is_proper_of_ne_top {I : ideal P} (ne_top : I ≠ ⊤) : is_proper I :=\nis_proper_of_not_mem (λ h, ne_top (top_of_mem_top h))\n\nlemma is_proper.ne_top {I : ideal P} (hI : is_proper I) : I ≠ ⊤ :=\nbegin\n  intro h,\n  rw [ext'_iff, top_coe] at h,\n  apply hI.ne_univ,\n  assumption,\nend\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 ↔ I ≠ ⊤ :=\n⟨λ h, h.ne_top, λ h, is_proper_of_ne_top h⟩\n\nlemma is_maximal.is_coatom {I : ideal P} (h : is_maximal I) : is_coatom I :=\n⟨is_maximal.to_is_proper.ne_top,\n λ _ _, by { rw [ext'_iff, top_coe], exact is_maximal.maximal_proper ‹_› }⟩\n\nlemma is_maximal.is_coatom' {I : ideal P} [is_maximal I] : is_coatom I :=\nis_maximal.is_coatom ‹_›\n\nlemma _root_.is_coatom.is_maximal {I : ideal P} (hI : is_coatom I) : is_maximal I :=\n{ maximal_proper := λ _ _, by simp [hI.2 _ ‹_›],\n  ..is_coatom.is_proper ‹_› }\n\nlemma is_maximal_iff_is_coatom {I : ideal P} : is_maximal I ↔ is_coatom I :=\n⟨λ h, h.is_coatom, λ h, h.is_maximal⟩\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 ∈ I) : x ⊔ y ∈ I :=\nlet ⟨z, h_mem, hx, hy⟩ := I.directed x ‹_› y ‹_› in\nI.mem_of_le (sup_le hx hy) h_mem\n\n@[simp] lemma sup_mem_iff : x ⊔ y ∈ I ↔ x ∈ I ∧ y ∈ I :=\n⟨λ h, ⟨I.mem_of_le le_sup_left h, I.mem_of_le le_sup_right h⟩,\n λ h, sup_mem x y h.left h.right⟩\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 ∩ J,\n  nonempty  := inter_nonempty I J,\n  directed  := λ x ⟨_, _⟩ y ⟨_, _⟩, ⟨x ⊔ y, ⟨sup_mem x y ‹_› ‹_›, sup_mem x y ‹_› ‹_›⟩, by simp⟩,\n  mem_of_le := λ x y h ⟨_, _⟩, ⟨mem_of_le I h ‹_›, mem_of_le J h ‹_›⟩ }\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 | ∃ (i ∈ I) (j ∈ J), x ≤ i ⊔ j},\n  nonempty  := by { cases inter_nonempty I J, exact ⟨w, w, h.1, w, h.2, le_sup_left⟩ },\n  directed  := λ x ⟨xi, _, xj, _, _⟩ y ⟨yi, _, yj, _, _⟩,\n    ⟨x ⊔ y,\n     ⟨xi ⊔ yi, sup_mem xi yi ‹_› ‹_›,\n      xj ⊔ yj, sup_mem xj yj ‹_› ‹_›,\n      sup_le\n        (calc x ≤ xi ⊔ xj               : ‹_›\n         ...    ≤ (xi ⊔ yi) ⊔ (xj ⊔ yj) : sup_le_sup le_sup_left le_sup_left)\n        (calc y ≤ yi ⊔ yj               : ‹_›\n         ...    ≤ (xi ⊔ yi) ⊔ (xj ⊔ yj) : sup_le_sup le_sup_right le_sup_right)⟩,\n     le_sup_left, le_sup_right⟩,\n  mem_of_le := λ x y _ ⟨yi, _, yj, _, _⟩, ⟨yi, ‹_›, yj, ‹_›, le_trans ‹x ≤ y› ‹_›⟩ }\n\nlemma sup_le : I ≤ K → J ≤ K → sup I J ≤ K :=\nλ hIK hJK x ⟨i, hiI, j, hjJ, hxij⟩,\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  := λ I J (i ∈ I), by { cases nonempty J, exact ⟨i, ‹_›, w, ‹_›, le_sup_left⟩ },\n  le_sup_right := λ I J (j ∈ J), by { cases nonempty I, exact ⟨w, ‹_›, j, ‹_›, le_sup_right⟩ },\n  sup_le       := @sup_le _ _ _,\n  inf          := inf,\n  inf_le_left  := λ I J, set.inter_subset_left I J,\n  inf_le_right := λ I J, set.inter_subset_right I J,\n  le_inf       := λ I J K, set.subset_inter,\n  .. ideal.partial_order }\n\n@[simp] lemma mem_inf : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J := iff_of_eq rfl\n\n@[simp] lemma mem_sup : x ∈ I ⊔ J ↔ ∃ (i ∈ I) (j ∈ J), x ≤ i ⊔ j := iff_of_eq rfl\n\nlemma lt_sup_principal_of_not_mem (hx : x ∉ I) : I < I ⊔ 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 semilattice_sup_bot\nvariables [semilattice_sup_bot P]\n\n@[priority 100]\ninstance semilattice_sup_bot.ideal_inter_nonempty : ideal_inter_nonempty P :=\n{ inter_nonempty := λ _ _, ⟨⊥, ⟨bot_mem, bot_mem⟩⟩ }\n\nend semilattice_sup_bot\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 := λ I J, begin\n    cases I.nonempty with i _,\n    cases J.nonempty with j _,\n    exact ⟨i ⊓ j, I.mem_of_le inf_le_left ‹_›, J.mem_of_le inf_le_right ‹_›⟩\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 ∈ I) (hj : j ∈ J) (hx : x ≤ i ⊔ j):\n∃ (i' ∈ I) (j' ∈ J), x = i' ⊔ j' :=\nbegin\n  refine ⟨x ⊓ i, I.mem_of_le inf_le_right hi, x ⊓ j, J.mem_of_le inf_le_right hj, _⟩,\n  calc\n  x    = x ⊓ (i ⊔ j)       : left_eq_inf.mpr hx\n  ...  = (x ⊓ i) ⊔ (x ⊓ j) : inf_sup_left,\nend\n\nlemma coe_sup_eq : ↑(I ⊔ J) = {x | ∃ i ∈ I, ∃ j ∈ J, x = i ⊔ j} :=\nbegin\n  ext,\n  rw [mem_coe, mem_sup],\n  exact ⟨λ ⟨_, _, _, _, _⟩, eq_sup_of_le_sup ‹_› ‹_› ‹_›,\n  λ ⟨i, _, j, _, _⟩, ⟨i, ‹_›, j, ‹_›, le_of_eq ‹_›⟩⟩\nend\n\nend distrib_lattice\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  : ∀ x : P, ∃ y ∈ carrier, x ≤ y)\n\nnamespace cofinal\n\nvariables [preorder P]\n\ninstance : inhabited (cofinal P) :=\n⟨{ carrier := set.univ, mem_gt := λ x, ⟨x, trivial, le_refl _⟩ }⟩\n\ninstance : has_mem P (cofinal P) := ⟨λ x D, x ∈ D.carrier⟩\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 ∈ D :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ λ a _, a\n\nlemma le_above : x ≤ D.above x :=\nexists.elim (classical.some_spec $ D.mem_gt x) $ λ _ b, b\n\nend cofinal\n\nsection ideal_of_cofinals\n\nvariables [preorder P] (p : P) {ι : Type*} [encodable ι] (𝒟 : ι → 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 : ℕ → P\n| 0 := p\n| (n+1) := match encodable.decode ι n with\n           | none   := sequence_of_cofinals n\n           | some i := (𝒟 i).above (sequence_of_cofinals n)\n           end\n\nlemma sequence_of_cofinals.monotone : monotone (sequence_of_cofinals p 𝒟) :=\nby { apply monotone_of_monotone_nat, intros n, dunfold sequence_of_cofinals,\n  cases encodable.decode ι n, { refl }, { apply cofinal.le_above }, }\n\nlemma sequence_of_cofinals.encode_mem (i : ι) :\n  sequence_of_cofinals p 𝒟 (encodable.encode i + 1) ∈ 𝒟 i :=\nby { dunfold sequence_of_cofinals, rw encodable.encodek, apply cofinal.above_mem, }\n\n/-- Given an element `p : P` and a family `𝒟` of cofinal subsets of a preorder `P`,\n  indexed by a countable type, `ideal_of_cofinals p 𝒟` is an ideal in `P` which\n  - contains `p`, according to `mem_ideal_of_cofinals p 𝒟`, and\n  - intersects every set in `𝒟`, according to `cofinal_meets_ideal_of_cofinals p 𝒟`.\n\n  This proves the Rasiowa–Sikorski lemma. -/\ndef ideal_of_cofinals : ideal P :=\n{ carrier   := { x : P | ∃ n, x ≤ sequence_of_cofinals p 𝒟 n },\n  nonempty  := ⟨p, 0, le_refl _⟩,\n  directed  := λ x ⟨n, hn⟩ y ⟨m, hm⟩,\n               ⟨_, ⟨max n m, le_refl _⟩,\n               le_trans hn $ sequence_of_cofinals.monotone p 𝒟 (le_max_left _ _),\n               le_trans hm $ sequence_of_cofinals.monotone p 𝒟 (le_max_right _ _) ⟩,\n  mem_of_le := λ x y hxy ⟨n, hn⟩, ⟨n, le_trans hxy hn⟩, }\n\nlemma mem_ideal_of_cofinals : p ∈ ideal_of_cofinals p 𝒟 := ⟨0, le_refl _⟩\n\n/-- `ideal_of_cofinals p 𝒟` is `𝒟`-generic. -/\nlemma cofinal_meets_ideal_of_cofinals (i : ι) : ∃ x : P, x ∈ 𝒟 i ∧ x ∈ ideal_of_cofinals p 𝒟 :=\n⟨_, sequence_of_cofinals.encode_mem p 𝒟 i, _, le_refl _⟩\n\nend ideal_of_cofinals\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/ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620468, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.785454579166111}}
{"text": "/-\nSome useful facts about distances \n(this helps us avoid reasoning about negative numbers)\n-/\n\ndef dist : ℕ → ℕ → ℕ\n| 0     m     := m\n| n     0     := n\n| (n+1) (m+1) := dist n m\n\nlemma dist_rfl (n : ℕ) : dist n n = 0 :=\nbegin\ninduction n with n ih,\n{ reflexivity },\n{ simp [dist, ih] }\nend\n\nlemma dist_zero_left (m : ℕ) : dist 0 m = m := by cases m; reflexivity\nlemma dist_zero_right (n : ℕ) : dist n 0 = n := by cases n; reflexivity\n\nlemma dist_add (n m : ℕ) : dist n (n+m) = m :=\nbegin induction n with n ih,\n  { by simp [dist_zero_left] },\n  { from calc dist (nat.succ n) (nat.succ n + m) \n            = dist (nat.succ n) (nat.succ (n + m)) : by simp\n        ... = dist n (n + m)                       : by simp [dist]\n        ... = m                                    : ih\n  }\nend\n\nlemma add_dist (n m : ℕ) : dist (n+m) n = m :=\nbegin induction n with n ih,\n  { by simp [dist_zero_right] },\n  { from calc dist (nat.succ n + m) (nat.succ n) \n            = dist (nat.succ (n + m)) (nat.succ n) : by simp\n        ... = dist (n + m) n                       : by simp [dist]\n        ... = m                                    : ih\n  }\nend\n\nlemma dist_sum (n m k : ℕ) (h : n = m + k) : dist n m = k :=\nby rw [h]; simp [add_dist]\n\nlemma dist_iden (m n : ℕ) : dist m n = 0 ↔ m = n :=\niff.intro\n(begin\nrevert n, induction m with m ih,\n{ intro n, simp [dist_zero_left]; from eq.symm },\n{ intro n, cases n with n,\n  { simp [dist]; intro; assumption },\n  { simp [dist]; intro h; rw [(ih n) h] } } \nend)\n(by intro h; simp [h, dist_rfl] )\n\nlemma dist_symm (m n : ℕ) : dist m n = dist n m :=\nbegin\nrevert n, induction m with m ih,\n{ intro n; induction n; reflexivity },\n{ intro n, cases n with n,\n  { simp [dist_zero_left, dist_zero_right] },\n  { simp [dist, ih n] } }\nend\n\nlemma dist_cancel (n m k : ℕ) : dist (n+k) (m+k) = dist n m :=\nbegin revert n m, induction k with k ih,\n{ intros, simp },\n{ intros, apply ih }\nend\n\nlemma dist_mul (n m k : ℕ) : dist (n*k) (m*k) = (dist n m)*k :=\nbegin\nrevert n, induction m with m ih,\n{ intro n; simp [dist_zero_right] },\n{ intro n; cases n with n,\n  { simp [dist_zero_left] },\n  { simp [dist, nat.succ_mul]; \n    repeat { rw [nat.add_comm k] }; \n    rw [dist_cancel]; \n    repeat { rw [nat.mul_comm k] }; \n    apply ih\n  }\n}\nend\n\nlemma bounded_dist {n m k : ℕ} (hn : n < k) (hm : m < k) : dist n m < k :=\nbegin\nrevert n m, induction k with k ih,\n{ intros, from absurd (nat.eq_zero_of_le_zero hn) (nat.succ_ne_zero n) },\n{ intros, cases n with n,\n  { cases m with m; simp [dist]; assumption },\n  { cases m with m,\n    { simp [dist]; assumption },\n    { simp [dist];\n      have hnk : n < k, from nat.lt_of_succ_lt_succ hn,\n      have hmk : m < k, from nat.lt_of_succ_lt_succ hm,\n      apply nat.lt.step; apply ih hnk hmk; assumption\n    }\n  }\n}\nend\n\nlemma dist_sub {n m : ℕ} (hm : m ≤ n) : dist n (n - m) = m :=\ncalc dist n (n - m) = dist (n+m) ((n - m) + m) : by rw [dist_cancel]\n                ... = dist (n+m) n             : by rw [nat.sub_add_cancel hm]\n                ... = m                        : by rw [add_dist]\n\nlemma dist_cancel_sub {n m k : ℕ} (hm : m ≤ n) (hk : k ≤ n) : dist (n - m) (n - k) = dist m k :=\ncalc dist (n - m) (n - k) = dist (n - m + m) ((n - k) + m) : by rw [dist_cancel]\n                      ... = dist n (n - k + m)             : by rw [nat.sub_add_cancel hm]\n                      ... = dist (n+k) (n - k + m + k)     : by rw [dist_cancel]\n                      ... = dist (n+k) (n - k + (m + k))   : by rw [nat.add_assoc]\n                      ... = dist (n+k) (n - k + (k + m))   : by rw [nat.add_comm k]\n                      ... = dist (n+k) ((n - k + k) + m)   : by rw [nat.add_assoc]\n                      ... = dist (n+k) (n+m)               : by rw [nat.sub_add_cancel hk]\n                      ... = dist (k+n) (m+n)               : by rw [nat.add_comm k, nat.add_comm m]\n                      ... = dist k m                       : by rw [dist_cancel]\n                      ... = dist m k                       : by rw [dist_symm]", "meta": {"author": "jthickstun", "repo": "lean", "sha": "8254b987f06be1f98ef2e0cc33b7d4655d77dc85", "save_path": "github-repos/lean/jthickstun-lean", "path": "github-repos/lean/jthickstun-lean/lean-8254b987f06be1f98ef2e0cc33b7d4655d77dc85/distance.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7854422400354896}}
{"text": "theorem mul_eq_zero_iff (a b : mynat): a * b = 0 ↔ a = 0 ∨ b = 0 :=\nbegin\nsplit,\napply eq_zero_or_eq_zero_of_mul_eq_zero,\nintro h,\ncases h,\nrwa [h, zero_mul],\nrwa [h, mul_zero],\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/3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7854422354952627}}
{"text": "-- Euler's proof of the infinitude of primes.\n-- Uses the product of all primes up to n.\n\nimport data.nat.basic\nimport data.nat.prime\n\ndef prod_primes : ℕ → ℕ\n| 0 := 1\n| (nat.succ n) := (if nat.prime n.succ then n.succ else 1) * prod_primes n\n\nlemma dvd_prod {n p : ℕ} : p ≤ n → nat.prime p → p ∣ prod_primes n :=\nbegin\n  induction n with k hk,\n    simp,\n    intro hp,\n    rw hp,\n    simp [nat.not_prime_zero],\n  intro hn,\n  generalize hm : prod_primes k.succ = m,\n  rw prod_primes at hm, rw ite_mul at hm, rw ite_eq_iff at hm, simp at hm,\n  cases nat.of_le_succ hn,\n    cases hm,\n      intro hp,\n      rw ← hm.right,\n      apply dvd_trans (hk h hp) (dvd_mul_left _ _),\n    rw ← hm.right,\n    apply hk h,\n  rw ← h at hm,\n  cases hm,\n    intro hp,\n    rw ← hm.right,\n    apply dvd_mul_right,\n  intro hp,\n  exfalso, apply hm.left, assumption,\nend\n\nlemma not_dvd_succ_prod {n p : ℕ} : nat.prime p → p ≤ n → ¬ p ∣ (prod_primes n).succ :=\nbegin\n  intro h_prime,\n  intro hn,\n  rw ← nat.not_dvd_iff_between_consec_multiples,\n    have h := dvd_prod hn h_prime,\n    cases h with c hc,\n    apply exists.intro c,\n    simp [mul_add],\n    rw hc,\n    simp [nat.lt_succ_self, ← nat.add_one],\n    apply lt_of_le_of_lt' (nat.prime.two_le h_prime), simp,\n  apply lt_of_le_of_lt' (nat.prime.two_le h_prime), simp,\nend\n\nlemma zero_lt_prod {n : ℕ} : 0 < prod_primes n :=\nbegin\n  induction n with k hk,\n    rw prod_primes, simp,\n  generalize hm : prod_primes k.succ = m,\n  rw prod_primes at hm,\n  rw ite_mul at hm,\n  rw ite_eq_iff at hm,\n  simp at hm,\n  cases hm,\n    rw ← hm.right,\n    rw zero_lt_iff,\n    simp,\n    intro h,\n    rw h at hk,\n    simp at hk, contradiction,\n  rw ← hm.right,\n  assumption,\nend\n\ntheorem infinite_primes (n : ℕ) : ∃ (p : ℕ), nat.prime p ∧ n < p :=\nbegin\n  -- Let x be product of primes up to n.\n  generalize hx : prod_primes n = x,\n  have h_prime := @nat.min_fac_prime x.succ _,\n    apply exists.intro x.succ.min_fac,\n    cases decidable.em (x.succ.min_fac ≤ n),\n      exfalso,\n      apply not_dvd_succ_prod h_prime h,\n      rw hx,\n      apply nat.min_fac_dvd,\n    apply and.intro, exact h_prime,\n    rw not_le at h, exact h,\n  simp,\n  rw nat.succ_eq_add_one, simp,\n  rw ← hx,\n  rw ← le_zero_iff,\n  apply has_lt.lt.not_le,\n  apply zero_lt_prod,\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_euler.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067260443809, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.7854140438625902}}
{"text": "/-\nhttps://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/rewrite.20le.2Eantisymm.20from.20Lean.202\n-/\n\nimport tactic\nimport tactic.lint\n\nopen int\n\ntheorem le.antisymm : ∀ {a b : ℤ}, a ≤ b → b ≤ a → a = b :=\nbegin\nassume a b : ℤ, assume (H₁ : a ≤ b) (H₂ : b ≤ a),\nobtain ⟨n, Hn⟩ : ∃ n : ℕ, a + n = b := int.le.dest H₁,\nobtain ⟨m, Hm⟩ : ∃ m : ℕ, b + m = a := int.le.dest H₂,\nhave H₃ : a + of_nat (n + m) = a + 0, from\n  calc\n    a + of_nat (n + m) = a + (of_nat n + m) : rfl\n      ... = a + (n + m)                     : by rw of_nat_eq_coe\n      ... = a + n + m                       : by rw add_assoc\n      ... = b + m                           : by rw Hn\n      ... = a                               : Hm\n      ... = a + 0                           : by rw add_zero,\nhave H₄ : of_nat (n + m) = of_nat 0, from add_left_cancel H₃,\nhave H₅ : n + m = 0,                 from of_nat.inj H₄,\nhave h₆ : n = 0,                     from nat.eq_zero_of_add_eq_zero_right H₅,\nshow a = b, from\n  calc\n    a = a + 0    : by simp_rw [add_zero]\n  ... = a + n    : by simp_rw [h₆, int.coe_nat_zero]\n  ... = b        : Hn\nend\n\n", "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/zulip/le_antisymm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957912273285902, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7853858871490795}}
{"text": "-- Suma de los primeros números de Fibonacci\n-- =========================================\n\nimport data.nat.basic\nimport tactic\n\ndef fibonacci : ℕ → ℕ\n| 0       := 0\n| 1       := 1\n| (n + 2) := fibonacci n + fibonacci (n + 1)\n\ndef fibonacci_sum : ℕ → ℕ\n| 0       := 0\n| (n + 1) := fibonacci_sum n + fibonacci (n + 1)\n\nlemma fibonacci_succ_pos\n  (n : ℕ)\n  : 0 < fibonacci (n + 1) :=\nbegin\n  induction n with n HI,\n  { exact nat.one_pos, },\n  { dsimp [fibonacci],\n    apply nat.lt_add_left,\n    exact HI, },\nend\n\nlemma closed_form\n  {n : ℕ}\n  : fibonacci_sum n = fibonacci (n + 2) - 1 :=\nbegin\n  induction n with n HI,\n  { refl, },\n  { dsimp [fibonacci_sum],\n    rw HI,\n    dsimp [fibonacci],\n    have h := fibonacci_succ_pos n,\n    omega, },\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/Suma_de_los_primeros_numeros_de_Fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810421953309, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7853209161472807}}
{"text": "/-\nCopyright (c) 2019 Jared Corduan. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Jared Corduan.\n-/\n\nimport logic.basic\n\n/-!\n# The Infinite Ramsey Theorem\n\nThe main theorem, `infinite_ramsey_pairs_two_colors`, states that given\na function from the unordered pairs of natural numbers to a set\nwith two elements (often named `red` and `blue`), there exists an\ninfinite set of natural numbers whose unordered pairs are all given\nthe same color.\n\nThe proof given here follows a very standard proof, such as the one\ngiven in chapter 1, theorem 5, of Graham, et al.\n\nThe proof roughly goes as follows:\n\nGiven a function `f` of unordered pairs into the colors `red` and `blue`,\ndefine a sequence `(Sᵢ, xᵢ)` so that:\n\n* (S₀, x₀) = (ℕ, 0)\n* Sᵢ₊₁ ⊆ Sᵢ\n* xᵢ₊₁ ∈ Sᵢ\n* xᵢ < xᵢ₊₁\n* f {xᵢ, y} = f {xᵢ, z} for all xᵢ < y < z in Sₓ\n\nThen the set {xᵢ | i ∈ ℕ} has the property that\nf {xᵢ, xⱼ} = f {xᵢ, xₖ} for all i < j < k.\nIf we color singletons in this set by f' xᵢ = f {xᵢ, xᵢ₊₁},\nthen by the pigeon hole principle there is an infinite subset\nof the xᵢ's whose unordered pairs are all colored the same.\n\n## Notation\n\nThis file uses `[S]²` to denote the set of unordered pairs of\nthe given set `S`.\n\n## Implementation notes\n\nThe set of two colors is defined as an emumeration.\nThis definition is easy to work with, and easy to read,\nbut comes at the cost of not generalizing.\n\nUnordered pairs are implemented as ordered pairs with the condition\nthat the second element is strictly greater than the first.\nThis definition is also easy to work with but does not generalize.\n\n## References\n\n*  [Graham, R.L. and Rothschild, B.L. and Spencer, J.H., *Ramsey Theory*][graham1990]\n-/\n\nopen set\nopen classical\nopen nat\n\nsection infinite_ramsey_pairs\n\n/--\nA set of natural numbers H is infinite if for any natural\nnumber there is a larger number in H.\n-/\ndef infinite (H : set ℕ) := ∀ x : ℕ, ∃ y : ℕ, x < y ∧ y ∈ H\n\n/--\nThere are two colors, red and blue.\n-/\ninductive color\n| red : color\n| blue : color\n\n/--\nAn infinite set of natural numbers.\n-/\nstructure Inf :=\n(s : set ℕ)\n(pf : infinite s)\n\ninstance : has_coe Inf (set ℕ) := ⟨Inf.s⟩\ninstance : has_mem ℕ Inf := ⟨λ n H, n ∈ H.s⟩\ninstance : has_subset Inf := ⟨λ H₁ H₂, H₁.s ⊆ H₂.s⟩\n\nopen color\n\n/--\nGiven a function from natural numbers to colors,\nthis property describes the numbers which are mapped to red.\n-/\ndef reds (f : ℕ → color) (H : set ℕ) := (λ n : ℕ, f n = red ∧ n ∈ H )\n\n/--\nGiven a function from natural numbers to colors,\nthis property describes the numbers which are mapped to blue.\n-/\ndef blues (f : ℕ → color) (H : set ℕ) := (λ n : ℕ, f n = blue ∧ H n)\n\nlemma lt_succ_sum : forall x y : ℕ, x < x + y + 1 :=\nλ x y : ℕ, lt_add_of_pos_right x (succ_pos y)\n\n/--\nUnordered pairs are defined as ordered pairs with the condition\nthat the second element is strictly greater than the first.\n-/\ndef unordered_pairs (S : set ℕ) :=\n  {p : ℕ × ℕ // p.fst < p.snd ∧ S p.fst ∧ S p.snd}\n\nnotation `[ℕ]²` := unordered_pairs univ\nnotation `[` S `]²` := unordered_pairs S\n\n/--\nGiven a number m and a coloring f, the projection of a coloring\nof unordered_pairs to a coloring of numbers is given by fixing\nthe first element as m. Note that red is arbitrarily chosen\nas the color assigned to any number below m.\n-/\ndef project (f : [ℕ]² → color) (m : ℕ) : ℕ → color :=\n  λ n : ℕ,\n    dite (m < n)\n      (λ h : m < n, f (subtype.mk (m, n) ⟨h, trivial, trivial⟩))\n      (λ _, red)\n\n/--\nThe coloring of an unordered pair {a, b}, where a < b,\nagrees with the projection of a applied to b.\n-/\nlemma project_eq (f : [ℕ]² → color) (p : [ℕ]²):\n  f p = project f p.val.fst p.val.snd :=\nbegin\n  unfold project,\n  simp [p.property.left]\nend\n\n/--\nGiven coloring of natural numbers, a homogeneous set is\none which is always mapped to the same color.\n-/\ndef homogeneous (f : ℕ → color) (H : Inf) :=\n  ∃ c : color, ∀ n, n ∈ H → f n = c\n\n/--\nGiven a coloring f, a homogeneous projection is a set of natural numbers\ntogether with a single natural number.\nThe intended use is a set which is homogeneous when projected\nwith the given number and coloring.\n-/\nstructure homogeneous_proj (f : [ℕ]² → color) extends Inf := (pt : ℕ)\n\ninstance (f : [ℕ]² → color) : has_coe (homogeneous_proj f) Inf := ⟨λ c, c.to_Inf⟩\n\n/--\nA homogeneous projection p is refined by another homogeneous projection q if:\nthe number given by q is greater than the number given by p,\nthe number given by q is an elment of the set given by p,\nthe set given by q is contained in the set given by p,\nand the projection using the number given by q is homogeneous\non the set given by q.\n-/\ndef refines {f : [ℕ]² → color} (p q: homogeneous_proj f) :=\np.pt < q.pt ∧ q.pt ∈ p.s ∧ q.s ⊆ p.s ∧ homogeneous (project f q.pt) q\n\ninfix `<<`:50 := refines\n\nlocal attribute [instance] prop_decidable\n\n/--\nA version of the infinite pigeon hole principle, tailored to our use case.\n-/\nlemma pigeon_hole_principle (f : ℕ → color) (H : Inf):\n  infinite (reds f H) ∨ infinite (blues f H) :=\nbegin\n  rw or_iff_not_imp_left,\n  intros redFin,\n  simp [infinite, not_forall, not_exists] at redFin,\n  cases redFin with w Hw,\n  intros x,\n  have x_lt_a : x < x + w + 1, exact lt_succ_sum x w,\n  have w_lt_a : w < x + w + 1,\n    { simp, exact lt_succ_sum w x },\n  let a : ℕ := x + w + 1,\n    cases (H.pf a) with b Hb,\n  have w_lt_b : w < b, exact lt_trans w_lt_a Hb.left,\n  have hrb : f b = red ∨ f b = blue,\n    { cases f b, simp, simp },\n  apply exists.intro b,\n  constructor,\n  { exact lt_trans x_lt_a Hb.left },\n  {\n    cases hrb with hRed hBlue,\n    { exact absurd (and.intro hRed Hb.right) (Hw b w_lt_b) },\n    { exact ⟨hBlue, Hb.right⟩ }\n  }\nend\n\n/--\nThis is the key lemma, reducing the Ramsey Theorem for pairs\nto the pigeon hole principle. It shows how to refine one homogeneous\nprojection to get another homogeneous projection.\n-/\nlemma refine_homo_proj (f : [ℕ]² → color) :\n  ∀ (p : homogeneous_proj f), ∃ q : homogeneous_proj f, p << q :=\nbegin\n  intros p,\n  cases p.pf p.pt with x Hx,\n  have Hinf :\n    infinite (reds (project f x) p.s) ∨ infinite (blues (project f x) p.s),\n    apply pigeon_hole_principle,\n  cases Hinf,\n  any_goals { -- Red Case\n    apply exists.intro (homogeneous_proj.mk f ⟨reds (project f x) p.s, Hinf⟩ x),\n  },\n  any_goals { -- Blue Case\n    apply exists.intro (homogeneous_proj.mk f ⟨blues (project f x) p.s, Hinf⟩ x)\n  },\n  all_goals\n  {\n    constructor,\n    { exact Hx.left },\n    constructor,\n    { exact Hx.right },\n    constructor,\n    { intros n Hn, exact Hn.right },\n    { apply exists.intro, intros n Hn, exact Hn.left },\n  }\nend\n\n/--\nThe natural numbers, as an infinite set.\n-/\ndef NatInf : Inf := Inf.mk univ\nbegin\n  intro x, apply exists.intro (x+1),\n  constructor, exact lt_succ_sum x 0, trivial,\nend\n\n/--\nThe initial set and number used to define\nall the homogeneous projections.\n-/\ndef init (f : [ℕ]² → color) := (⟨f, NatInf, 0⟩ : homogeneous_proj f)\n\n/--\nIterate the procedure of refining a homogeneous projection.\nTODO is is possible to remove this definition?\n-/\ndef iterate_refinement (f : [ℕ]² → color)\n    (cf : Π (x : homogeneous_proj f), (λ (x : homogeneous_proj f), homogeneous_proj f) x) :\n  ℕ → homogeneous_proj f\n| 0 := cf (init f)\n| (n+1) := let p := iterate_refinement n in cf ⟨f, p, p.pt⟩\n\n/--\nThere exists an infinet sequence of homogeneous projections,\neach a refinement of the previous one.\n-/\nlemma exists_homo_proj_seq (f : [ℕ]² → color) :\n∃ (g : ℕ → homogeneous_proj f), init f << g 0 ∧ ∀ n, g n << g (n+1) :=\nbegin\n  have ac : ∃ (cf : Π (x : homogeneous_proj f), (λ (x : homogeneous_proj f), homogeneous_proj f) x),\n    ∀ (p : homogeneous_proj f), (λ (p q : homogeneous_proj f), p<<q) p (cf p),\n    exact axiom_of_choice (refine_homo_proj f),\n  cases ac with cf Hcf,\n  let g := λ m : ℕ, (iterate_refinement f cf m),\n  apply exists.intro g,\n  constructor,\n  {\n    exact Hcf (init f)\n  },\n  {\n    intro n,\n    have h1 : (g n) << cf (g n),\n      exact Hcf (g n),\n    have h2 : ∀ p : homogeneous_proj f, p = ⟨f, ↑p, p.pt⟩,\n      intro p, cases p with H n, cases H with s pf, refl,\n    have h3 : cf (g n) = iterate_refinement f cf (n+1),\n      unfold iterate_refinement, simp, rw ← (h2 (g n)),\n    simp * at *\n  }\nend\n\n/--\nThe sets in a sequence of refined homogeneous projections are\nclosed upward under inclusion.\n-/\nlemma homo_proj_seq_mono_sets\n  (f : [ℕ]² → color)\n  (g : ℕ → homogeneous_proj f)\n  (h : ∀ n, g n << g (n+1))\n  (x y : ℕ) :\n  (g (x+y)).s ⊆ (g x).s :=\nbegin\n  induction y with y ih,\n  {\n    intros y hy, exact hy,\n  },\n  {\n    intros a ha,\n    exact ih ((h (x+y)).right.right.left ha),\n  }\nend\n\n/--\nThe points in a sequence of refined homogeneous projections are\ncontained in the previous sets.\n-/\nlemma homo_proj_seq_mono_pts\n  (f : [ℕ]² → color)\n  (g : ℕ → homogeneous_proj f)\n  (h : ∀ n, g n << g (n+1))\n  (x y : ℕ) :\n  (g (x+y+1)).pt ∈ (g x).s :=\nby exact (homo_proj_seq_mono_sets f g h x y) ((h (x+y)).right.left)\n\n/--\nThe points in a sequence of refined homogeneous projections have\nthe property that f {xᵢ, y} = f {xᵢ, z} for all xᵢ < y < z in Sₓ.\n-/\nlemma homo_proj_seq_stable_colors\n  (f : [ℕ]² → color)\n  (g : ℕ → homogeneous_proj f)\n  (h0 : (init f) << g 0)\n  (hn : ∀ n, g n << g (n+1))\n  (x y : ℕ) :\n  (project f (g x).pt) (g (x+1)).pt = (project f (g x).pt) (g (x+y+1)).pt :=\nbegin\n  cases x,\n  {\n    have h : homogeneous (project f (g 0).pt) (g 0),\n      exact h0.right.right.right,\n    cases h with c hm,\n    simp,\n    rw hm ((g 1).pt) (homo_proj_seq_mono_pts f g hn 0 0),\n    have hzy : y + 1 = 0 + y + 1, simp,\n    rw hzy,\n    rw hm ((g (0+y+1)).pt) (homo_proj_seq_mono_pts f g hn 0 y),\n  },\n  {\n    have hgx : g x << g (x+1), exact (hn x),\n    have hm : homogeneous (project f (g (x+1)).pt) (g (x+1)),\n      exact hgx.right.right.right,\n    cases hm with c Hm',\n    rw Hm' ((g (x + 1 + 1)).pt) (homo_proj_seq_mono_pts f g hn (x+1) 0),\n    rw Hm' ((g (x + 1 + y + 1)).pt) (homo_proj_seq_mono_pts f g hn (x+1) y),\n  }\nend\n\nsection increasing_functions\n\n--TODO are the results of this section proved elsewhere in mathlib?\n\ndef increasing (f : ℕ → ℕ) := ∀ x y : ℕ, x < y → f x < f y\n\nlemma increasing_by_step (f : ℕ → ℕ) :\n  (∀ n : ℕ, f n < f (n+1)) → increasing f :=\nλ (hf : ∀ n : ℕ, f n < f (n+1)) (x y : ℕ), nat.rec_on y\n(λ (contr : x < 0), absurd contr (not_succ_le_zero x))\n(λ (z : ℕ) (ih : x < z → f x < f z) (h : x < succ z),\nor.cases_on (nat.eq_or_lt_of_le (le_of_lt_succ h))\n(λ hxz : x = z, hxz ▸ (hf x))\n(λ (hxz : x < z), lt_trans (ih hxz) (hf z)))\n\nlemma x_le_fx_incr (f : ℕ → ℕ) (x : ℕ): increasing f → x ≤ f x :=\nλ (incr : increasing f),\n  nat.rec_on x (zero_le (f 0))\n  (λ (n : ℕ) (ih : n ≤ f n),\n  le_trans (succ_le_succ ih) (incr n (succ n) (lt_succ_self n)))\n\nlemma incr_range_inf (H : Inf) (g : ℕ → ℕ) (hg : increasing g) :\n  infinite (image g H) :=\nbegin\n  intros x,\n  have h : ∃ h, x < h ∧ h ∈ H, exact H.pf x,\n  cases h with h Hh,\n  apply exists.intro (g h),\n  constructor,\n  exact (lt_of_lt_of_le Hh.left (x_le_fx_incr g h hg)),\n  unfold image,\n  apply exists.intro h, constructor, exact Hh.right, refl,\nend\n\nlemma incr_dom (g : ℕ → ℕ) (hg : increasing g) (x y : ℕ) (h : g x < g y):\n  x < y :=\nbegin\n  cases (lt_trichotomy x y) with hlt hlte,\n    exact hlt,\n    cases hlte with hlt he, rw hlt at h,\n    exact absurd h (lt_irrefl (g y)),\n    exact absurd (lt_trans (hg y x he) h) (lt_irrefl (g y)),\nend\n\nend increasing_functions\n\n/--\nTrivial lemma needed below.\n-/\nlemma domain_dist_rw (x y : ℕ) (h : x < y): y = x + (y - (x+1)) + 1 :=\nby rw [ add_assoc x (y - (x+1)) 1\n      , add_comm (y - (x+1)) 1\n      , ←add_assoc x 1 (y - (x+1))\n      , add_sub_of_le (succ_le_of_lt h)]\n\n/--\nThe points in a sequence of refined homogeneous projections\nare increasing.\n-/\nlemma homo_proj_seq_incr\n(f : [ℕ]² → color)\n(g : ℕ → homogeneous_proj f)\n(h : ∀ n, g n << g (n+1)) :\nincreasing (λ n : ℕ, (g n).pt) :=\nbegin\nhave h : ∀ n : ℕ, (g n).pt < (g (n+1)).pt,\nintro, exact (h n).left,\nexact increasing_by_step (λ n : ℕ, (g n).pt) h,\nend\n\n/--\nRestrict a coloring of unordered pairs of all natural numbers\nto unordered pairs of a given infinite set H.\n-/\ndef restrict (f : [ℕ]² → color) (H : set ℕ) : [H]² → color :=\n  λ h, f (⟨h.val, ⟨h.property.left, ⟨true.intro, true.intro⟩⟩⟩)\n\n/--\nThe main theorem, stating that given a function from the unordered pairs of\nnatural numbers to a set with two elements, there exists an infinite set of\nnatural numbers whose unordered pairs are all given the same color.\n-/\ntheorem infinite_ramsey_pairs_two_colors (f : [ℕ]² → color) :\n  ∃ H : Inf, ∃ c : color,\n  ∀ h : [H]²,\n  (restrict f H) h = c :=\nbegin\n  have hseq : ∃ (g : ℕ → homogeneous_proj f), init f << g 0 ∧ ∀ n, g n << g (n+1),\n    exact exists_homo_proj_seq f,\n  cases hseq with g Hg,\n  cases Hg with HgInit HgSeq,\n  let g' := (λ n, (g n).pt),\n  let f' := (λ n, project f (g' n) (g' (n+1))),\n  have HgIncr : increasing g', exact homo_proj_seq_incr f g HgSeq,\n  let preH := (⟨image g' NatInf, incr_range_inf NatInf g' HgIncr⟩ : Inf),\n  cases (pigeon_hole_principle f' preH) with Hred Hblue,\n\n  any_goals { -- Red Case\n    let H := (⟨reds f' preH, Hred⟩ : Inf),\n    apply exists.intro (⟨image g' H, incr_range_inf H g' HgIncr⟩ : Inf),\n    apply exists.intro red,\n    intros p,\n  },\n  any_goals { -- Blue Case\n    let H := (⟨blues f' preH, Hblue⟩ : Inf),\n    apply exists.intro (⟨image g' H, incr_range_inf H g' HgIncr⟩ : Inf),\n    apply exists.intro blue,\n    intros p,\n  },\n  all_goals {\n    have hp1 : p.val.fst ∈ image g' H, exact p.property.right.left,\n    cases hp1 with h₁ Hh₁,\n    have hfh₁ : f' h₁ = _, exact Hh₁.left.left,\n    have hfgh₁ : project f (g' h₁) (g' (h₁+1)) = _, rw ←hfh₁,\n    have hp2 : p.val.snd ∈ image g' H, exact p.property.right.right,\n    cases hp2 with h₂ Hgh₂,\n    have hg : p.val.fst < p.val.snd, exact p.property.left,\n    rw [←Hh₁.right, ←Hgh₂.right] at hg,\n    let d := h₂ - (h₁ + 1),\n    have hd : h₂ = h₁ + d + 1,\n      exact domain_dist_rw h₁ h₂ (incr_dom g' HgIncr h₁ h₂ hg),\n    have stable :\n      (project f (g' h₁)) (g' (h₁+1)) = (project f (g' h₁)) (g' (h₁+d+1)),\n      exact homo_proj_seq_stable_colors f g HgInit HgSeq h₁ d,\n    rw [hfgh₁, ←hd, Hh₁.right, Hgh₂.right] at stable,\n    have hproj : f ⟨p.val, _⟩ = project f p.val.fst p.val.snd,\n      exact project_eq f ⟨p.val, ⟨p.property.left, trivial, trivial⟩⟩,\n    rw [←stable, hproj] at hproj,\n    rw ←hproj, refl,\n  }\nend\n\nend infinite_ramsey_pairs\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/rt22.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7852944841623595}}
{"text": "theorem le_succ (a b : mynat) : a ≤ b → a ≤ (succ b) :=\nbegin\nintro h,\nrw le_iff_exists_add at h,\ncases h with c hc,\nrw hc,\nuse c + 1,\nrw succ_eq_add_one,\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/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133464597459, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7852821234206998}}
{"text": "/-\nCopyright (c) 2014 Parikshit Khanna. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn\n\n! This file was ported from Lean 3 source module init.data.list.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.List.Basic\nimport Leanbin.Init.Function\nimport Leanbin.Init.Meta.Default\nimport Leanbin.Init.Data.Nat.Lemmas\nimport Leanbin.Init.Meta.Interactive\nimport Leanbin.Init.Meta.Smt.Rsimp\n\nuniverse u v w w₁ w₂\n\nvariable {α : Type u} {β : Type v} {γ : Type w}\n\nnamespace List\n\nopen Nat\n\n/-! append -/\n\n\n#print List.nil_append /-\n@[simp]\ntheorem nil_append (s : List α) : [] ++ s = s :=\n  rfl\n#align list.nil_append List.nil_append\n-/\n\n#print List.cons_append /-\n@[simp]\ntheorem cons_append (x : α) (s t : List α) : x :: s ++ t = x :: (s ++ t) :=\n  rfl\n#align list.cons_append List.cons_append\n-/\n\n#print List.append_nil /-\n@[simp]\ntheorem append_nil (t : List α) : t ++ [] = t := by induction t <;> simp [*]\n#align list.append_nil List.append_nil\n-/\n\n#print List.append_assoc /-\n@[simp]\ntheorem append_assoc (s t u : List α) : s ++ t ++ u = s ++ (t ++ u) := by induction s <;> simp [*]\n#align list.append_assoc List.append_assoc\n-/\n\n/-! length -/\n\n\n#print List.length_cons /-\ntheorem length_cons (a : α) (l : List α) : length (a :: l) = length l + 1 :=\n  rfl\n#align list.length_cons List.length_cons\n-/\n\n#print List.length_append /-\n@[simp]\ntheorem length_append (s t : List α) : length (s ++ t) = length s + length t :=\n  by\n  induction s\n  · show length t = 0 + length t\n    · rw [Nat.zero_add]\n  · simp [*, Nat.add_comm, Nat.add_left_comm]\n#align list.length_append List.length_append\n-/\n\n@[simp]\ntheorem length_repeat (a : α) (n : ℕ) : length (repeat a n) = n := by\n  induction n <;> simp [*] <;> rfl\n#align list.length_repeat List.length_repeat\n\n#print List.length_tail /-\n@[simp]\ntheorem length_tail (l : List α) : length (tail l) = length l - 1 := by cases l <;> rfl\n#align list.length_tail List.length_tail\n-/\n\n#print List.length_drop /-\n-- TODO(Leo): cleanup proof after arith dec proc\n@[simp]\ntheorem length_drop : ∀ (i : ℕ) (l : List α), length (drop i l) = length l - i\n  | 0, l => rfl\n  | succ i, [] => Eq.symm (Nat.zero_sub (succ i))\n  | succ i, x :: l =>\n    calc\n      length (drop (succ i) (x :: l)) = length l - i := length_drop i l\n      _ = succ (length l) - succ i := (Nat.succ_sub_succ_eq_sub (length l) i).symm\n      \n#align list.length_drop List.length_drop\n-/\n\n/-! map -/\n\n\n/- warning: list.map_cons -> List.map_cons is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (f : α -> β) (a : α) (l : List.{u1} α), Eq.{succ u2} (List.{u2} β) (List.map.{u1, u2} α β f (List.cons.{u1} α a l)) (List.cons.{u2} β (f a) (List.map.{u1, u2} α β f l))\nbut is expected to have type\n  forall {α : Type.{u2}} {β : Type.{u1}} (f : α -> β) (a : α) (l : List.{u2} α), Eq.{succ u1} (List.{u1} β) (List.map.{u2, u1} α β f (List.cons.{u2} α a l)) (List.cons.{u1} β (f a) (List.map.{u2, u1} α β f l))\nCase conversion may be inaccurate. Consider using '#align list.map_cons List.map_consₓ'. -/\ntheorem map_cons (f : α → β) (a l) : map f (a :: l) = f a :: map f l :=\n  rfl\n#align list.map_cons List.map_cons\n\n/- warning: list.map_append -> List.map_append is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (f : α -> β) (l₁ : List.{u1} α) (l₂ : List.{u1} α), Eq.{succ u2} (List.{u2} β) (List.map.{u1, u2} α β f (Append.append.{u1} (List.{u1} α) (List.hasAppend.{u1} α) l₁ l₂)) (Append.append.{u2} (List.{u2} β) (List.hasAppend.{u2} β) (List.map.{u1, u2} α β f l₁) (List.map.{u1, u2} α β f l₂))\nbut is expected to have type\n  forall {α : Type.{u2}} {β : Type.{u1}} (f : α -> β) (l₁ : List.{u2} α) (l₂ : List.{u2} α), Eq.{succ u1} (List.{u1} β) (List.map.{u2, u1} α β f (HAppend.hAppend.{u2, u2, u2} (List.{u2} α) (List.{u2} α) (List.{u2} α) (instHAppend.{u2} (List.{u2} α) (List.instAppendList.{u2} α)) l₁ l₂)) (HAppend.hAppend.{u1, u1, u1} (List.{u1} β) (List.{u1} β) (List.{u1} β) (instHAppend.{u1} (List.{u1} β) (List.instAppendList.{u1} β)) (List.map.{u2, u1} α β f l₁) (List.map.{u2, u1} α β f l₂))\nCase conversion may be inaccurate. Consider using '#align list.map_append List.map_appendₓ'. -/\n@[simp]\ntheorem map_append (f : α → β) : ∀ l₁ l₂, map f (l₁ ++ l₂) = map f l₁ ++ map f l₂ := by\n  intro l₁ <;> induction l₁ <;> intros <;> simp [*]\n#align list.map_append List.map_append\n\n/- warning: list.map_singleton -> List.map_singleton is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (f : α -> β) (a : α), Eq.{succ u2} (List.{u2} β) (List.map.{u1, u2} α β f (List.cons.{u1} α a (List.nil.{u1} α))) (List.cons.{u2} β (f a) (List.nil.{u2} β))\nbut is expected to have type\n  forall {α : Type.{u2}} {β : Type.{u1}} (f : α -> β) (a : α), Eq.{succ u1} (List.{u1} β) (List.map.{u2, u1} α β f (List.cons.{u2} α a (List.nil.{u2} α))) (List.cons.{u1} β (f a) (List.nil.{u1} β))\nCase conversion may be inaccurate. Consider using '#align list.map_singleton List.map_singletonₓ'. -/\ntheorem map_singleton (f : α → β) (a : α) : map f [a] = [f a] :=\n  rfl\n#align list.map_singleton List.map_singleton\n\n#print List.map_id /-\n@[simp]\ntheorem map_id (l : List α) : map id l = l := by induction l <;> simp [*]\n#align list.map_id List.map_id\n-/\n\n/- warning: list.map_map -> List.map_map is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (g : β -> γ) (f : α -> β) (l : List.{u1} α), Eq.{succ u3} (List.{u3} γ) (List.map.{u2, u3} β γ g (List.map.{u1, u2} α β f l)) (List.map.{u1, u3} α γ (Function.comp.{succ u1, succ u2, succ u3} α β γ g f) l)\nbut is expected to have type\n  forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (g : α -> β) (f : γ -> α) (l : List.{u1} γ), Eq.{succ u2} (List.{u2} β) (List.map.{u3, u2} α β g (List.map.{u1, u3} γ α f l)) (List.map.{u1, u2} γ β (Function.comp.{succ u1, succ u3, succ u2} γ α β g f) l)\nCase conversion may be inaccurate. Consider using '#align list.map_map List.map_mapₓ'. -/\n@[simp]\ntheorem map_map (g : β → γ) (f : α → β) (l : List α) : map g (map f l) = map (g ∘ f) l := by\n  induction l <;> simp [*]\n#align list.map_map List.map_map\n\n/- warning: list.length_map -> List.length_map is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (f : α -> β) (l : List.{u1} α), Eq.{1} Nat (List.length.{u2} β (List.map.{u1, u2} α β f l)) (List.length.{u1} α l)\nbut is expected to have type\n  forall {α : Type.{u1}} {β : Type.{u2}} (f : List.{u1} α) (l : α -> β), Eq.{1} Nat (List.length.{u2} β (List.map.{u1, u2} α β l f)) (List.length.{u1} α f)\nCase conversion may be inaccurate. Consider using '#align list.length_map List.length_mapₓ'. -/\n@[simp]\ntheorem length_map (f : α → β) (l : List α) : length (map f l) = length l := by\n  induction l <;> simp [*]\n#align list.length_map List.length_map\n\n/-! bind -/\n\n\n/- warning: list.nil_bind -> List.nil_bind is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (f : α -> (List.{u2} β)), Eq.{succ u2} (List.{u2} β) (List.bind.{u1, u2} α β (List.nil.{u1} α) f) (List.nil.{u2} β)\nbut is expected to have type\n  forall {α : Type.{u2}} {β : Type.{u1}} (f : α -> (List.{u1} β)), Eq.{succ u1} (List.{u1} β) (List.bind.{u2, u1} α β (List.nil.{u2} α) f) (List.nil.{u1} β)\nCase conversion may be inaccurate. Consider using '#align list.nil_bind List.nil_bindₓ'. -/\n@[simp]\ntheorem nil_bind (f : α → List β) : List.bind [] f = [] := by simp [join, List.bind]\n#align list.nil_bind List.nil_bind\n\n/- warning: list.cons_bind -> List.cons_bind is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (x : α) (xs : List.{u1} α) (f : α -> (List.{u2} β)), Eq.{succ u2} (List.{u2} β) (List.bind.{u1, u2} α β (List.cons.{u1} α x xs) f) (Append.append.{u2} (List.{u2} β) (List.hasAppend.{u2} β) (f x) (List.bind.{u1, u2} α β xs f))\nbut is expected to have type\n  forall {α : Type.{u2}} {β : Type.{u1}} (x : α) (xs : List.{u2} α) (f : α -> (List.{u1} β)), Eq.{succ u1} (List.{u1} β) (List.bind.{u2, u1} α β (List.cons.{u2} α x xs) f) (HAppend.hAppend.{u1, u1, u1} (List.{u1} β) (List.{u1} β) (List.{u1} β) (instHAppend.{u1} (List.{u1} β) (List.instAppendList.{u1} β)) (f x) (List.bind.{u2, u1} α β xs f))\nCase conversion may be inaccurate. Consider using '#align list.cons_bind List.cons_bindₓ'. -/\n@[simp]\ntheorem cons_bind (x xs) (f : α → List β) : List.bind (x :: xs) f = f x ++ List.bind xs f := by\n  simp [join, List.bind]\n#align list.cons_bind List.cons_bind\n\n/- warning: list.append_bind -> List.append_bind is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} (xs : List.{u1} α) (ys : List.{u1} α) (f : α -> (List.{u2} β)), Eq.{succ u2} (List.{u2} β) (List.bind.{u1, u2} α β (Append.append.{u1} (List.{u1} α) (List.hasAppend.{u1} α) xs ys) f) (Append.append.{u2} (List.{u2} β) (List.hasAppend.{u2} β) (List.bind.{u1, u2} α β xs f) (List.bind.{u1, u2} α β ys f))\nbut is expected to have type\n  forall {α : Type.{u2}} {β : Type.{u1}} (xs : List.{u2} α) (ys : List.{u2} α) (f : α -> (List.{u1} β)), Eq.{succ u1} (List.{u1} β) (List.bind.{u2, u1} α β (HAppend.hAppend.{u2, u2, u2} (List.{u2} α) (List.{u2} α) (List.{u2} α) (instHAppend.{u2} (List.{u2} α) (List.instAppendList.{u2} α)) xs ys) f) (HAppend.hAppend.{u1, u1, u1} (List.{u1} β) (List.{u1} β) (List.{u1} β) (instHAppend.{u1} (List.{u1} β) (List.instAppendList.{u1} β)) (List.bind.{u2, u1} α β xs f) (List.bind.{u2, u1} α β ys f))\nCase conversion may be inaccurate. Consider using '#align list.append_bind List.append_bindₓ'. -/\n@[simp]\ntheorem append_bind (xs ys) (f : α → List β) :\n    List.bind (xs ++ ys) f = List.bind xs f ++ List.bind ys f := by\n  induction xs <;> [rfl, simp [*, cons_bind]]\n#align list.append_bind List.append_bind\n\n/-! mem -/\n\n\n#print List.mem_nil_iff /-\ntheorem mem_nil_iff (a : α) : a ∈ ([] : List α) ↔ False :=\n  Iff.rfl\n#align list.mem_nil_iff List.mem_nil_iff\n-/\n\n#print List.not_mem_nil /-\n@[simp]\ntheorem not_mem_nil (a : α) : a ∉ ([] : List α) :=\n  not_false\n#align list.not_mem_nil List.not_mem_nil\n-/\n\n#print List.mem_cons_self /-\ntheorem mem_cons_self (a : α) (l : List α) : a ∈ a :: l :=\n  Or.inl rfl\n#align list.mem_cons_self List.mem_cons_self\n-/\n\n#print List.mem_cons /-\n@[simp]\ntheorem mem_cons (a y : α) (l : List α) : a ∈ y :: l ↔ a = y ∨ a ∈ l :=\n  Iff.rfl\n#align list.mem_cons_iff List.mem_cons\n-/\n\n@[rsimp]\ntheorem mem_cons_eq (a y : α) (l : List α) : (a ∈ y :: l) = (a = y ∨ a ∈ l) :=\n  rfl\n#align list.mem_cons_eq List.mem_cons_eq\n\n#print List.mem_cons_of_mem /-\ntheorem mem_cons_of_mem (y : α) {a : α} {l : List α} : a ∈ l → a ∈ y :: l := fun H => Or.inr H\n#align list.mem_cons_of_mem List.mem_cons_of_mem\n-/\n\n#print List.eq_or_mem_of_mem_cons /-\ntheorem eq_or_mem_of_mem_cons {a y : α} {l : List α} : a ∈ y :: l → a = y ∨ a ∈ l := fun h => h\n#align list.eq_or_mem_of_mem_cons List.eq_or_mem_of_mem_cons\n-/\n\n#print List.mem_append /-\n@[simp]\ntheorem mem_append {a : α} {s t : List α} : a ∈ s ++ t ↔ a ∈ s ∨ a ∈ t := by\n  induction s <;> simp [*, or_assoc']\n#align list.mem_append List.mem_append\n-/\n\n#print List.mem_append_eq /-\n@[rsimp]\ntheorem mem_append_eq (a : α) (s t : List α) : (a ∈ s ++ t) = (a ∈ s ∨ a ∈ t) :=\n  propext mem_append\n#align list.mem_append_eq List.mem_append_eq\n-/\n\n#print List.mem_append_left /-\ntheorem mem_append_left {a : α} {l₁ : List α} (l₂ : List α) (h : a ∈ l₁) : a ∈ l₁ ++ l₂ :=\n  mem_append.2 (Or.inl h)\n#align list.mem_append_left List.mem_append_left\n-/\n\n#print List.mem_append_right /-\ntheorem mem_append_right {a : α} (l₁ : List α) {l₂ : List α} (h : a ∈ l₂) : a ∈ l₁ ++ l₂ :=\n  mem_append.2 (Or.inr h)\n#align list.mem_append_right List.mem_append_right\n-/\n\ntheorem not_bex_nil (p : α → Prop) : ¬∃ x ∈ @nil α, p x := fun ⟨x, hx, px⟩ => hx\n#align list.not_bex_nil List.not_bex_nil\n\n/- warning: list.ball_nil clashes with list.forall_mem_nil -> List.forall_mem_nil\nCase conversion may be inaccurate. Consider using '#align list.ball_nil List.forall_mem_nilₓ'. -/\n#print List.forall_mem_nil /-\ntheorem forall_mem_nil (p : α → Prop) : ∀ x ∈ @nil α, p x := fun x => False.elim\n#align list.ball_nil List.forall_mem_nil\n-/\n\ntheorem bex_cons (p : α → Prop) (a : α) (l : List α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=\n  ⟨fun ⟨x, h, px⟩ => by\n    simp at h\n    cases' h with h h\n    · cases h\n      exact Or.inl px\n    · exact Or.inr ⟨x, h, px⟩, fun o =>\n    o.elim (fun pa => ⟨a, mem_cons_self _ _, pa⟩) fun ⟨x, h, px⟩ => ⟨x, mem_cons_of_mem _ h, px⟩⟩\n#align list.bex_cons List.bex_cons\n\ntheorem forall_mem_cons (p : α → Prop) (a : α) (l : List α) :\n    (∀ x ∈ a :: l, p x) ↔ p a ∧ ∀ x ∈ l, p x :=\n  ⟨fun al => ⟨al a (mem_cons_self _ _), fun x h => al x (mem_cons_of_mem _ h)⟩, fun ⟨pa, al⟩ x o =>\n    o.elim (fun e => e.symm ▸ pa) (al x)⟩\n#align list.ball_cons List.forall_mem_consₓ\n\n/-! list subset -/\n\n\n#print List.Subset /-\nprotected def Subset (l₁ l₂ : List α) :=\n  ∀ ⦃a : α⦄, a ∈ l₁ → a ∈ l₂\n#align list.subset List.Subset\n-/\n\ninstance : HasSubset (List α) :=\n  ⟨List.Subset⟩\n\n#print List.nil_subset /-\n@[simp]\ntheorem nil_subset (l : List α) : [] ⊆ l := fun b i => False.elim (Iff.mp (mem_nil_iff b) i)\n#align list.nil_subset List.nil_subset\n-/\n\n#print List.Subset.refl /-\n@[refl, simp]\ntheorem Subset.refl (l : List α) : l ⊆ l := fun b i => i\n#align list.subset.refl List.Subset.refl\n-/\n\n#print List.Subset.trans /-\n@[trans]\ntheorem Subset.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := fun b i =>\n  h₂ (h₁ i)\n#align list.subset.trans List.Subset.trans\n-/\n\n#print List.subset_cons /-\n@[simp]\ntheorem subset_cons (a : α) (l : List α) : l ⊆ a :: l := fun b i => Or.inr i\n#align list.subset_cons List.subset_cons\n-/\n\n#print List.subset_of_cons_subset /-\ntheorem subset_of_cons_subset {a : α} {l₁ l₂ : List α} : a :: l₁ ⊆ l₂ → l₁ ⊆ l₂ := fun s b i =>\n  s (mem_cons_of_mem _ i)\n#align list.subset_of_cons_subset List.subset_of_cons_subset\n-/\n\n#print List.cons_subset_cons /-\ntheorem cons_subset_cons {l₁ l₂ : List α} (a : α) (s : l₁ ⊆ l₂) : a :: l₁ ⊆ a :: l₂ := fun b hin =>\n  Or.elim (eq_or_mem_of_mem_cons hin) (fun e : b = a => Or.inl e) fun i : b ∈ l₁ => Or.inr (s i)\n#align list.cons_subset_cons List.cons_subset_cons\n-/\n\n#print List.subset_append_left /-\n@[simp]\ntheorem subset_append_left (l₁ l₂ : List α) : l₁ ⊆ l₁ ++ l₂ := fun b => mem_append_left _\n#align list.subset_append_left List.subset_append_left\n-/\n\n#print List.subset_append_right /-\n@[simp]\ntheorem subset_append_right (l₁ l₂ : List α) : l₂ ⊆ l₁ ++ l₂ := fun b => mem_append_right _\n#align list.subset_append_right List.subset_append_right\n-/\n\n#print List.subset_cons_of_subset /-\ntheorem subset_cons_of_subset (a : α) {l₁ l₂ : List α} : l₁ ⊆ l₂ → l₁ ⊆ a :: l₂ :=\n  fun (s : l₁ ⊆ l₂) (a : α) (i : a ∈ l₁) => Or.inr (s i)\n#align list.subset_cons_of_subset List.subset_cons_of_subset\n-/\n\n#print List.eq_nil_of_length_eq_zero /-\ntheorem eq_nil_of_length_eq_zero {l : List α} : length l = 0 → l = [] :=\n  by\n  induction l <;> intros\n  rfl\n  contradiction\n#align list.eq_nil_of_length_eq_zero List.eq_nil_of_length_eq_zero\n-/\n\n#print List.ne_nil_of_length_eq_succ /-\ntheorem ne_nil_of_length_eq_succ {l : List α} : ∀ {n : Nat}, length l = succ n → l ≠ [] := by\n  induction l <;> intros <;> contradiction\n#align list.ne_nil_of_length_eq_succ List.ne_nil_of_length_eq_succ\n-/\n\n/- warning: list.length_map₂ -> List.length_zipWith is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} {γ : Type.{u3}} (f : α -> β -> γ) (l₁ : List.{u1} α) (l₂ : List.{u2} β), Eq.{1} Nat (List.length.{u3} γ (List.zipWith.{u1, u2, u3} α β γ f l₁ l₂)) (LinearOrder.min.{0} Nat Nat.linearOrder (List.length.{u1} α l₁) (List.length.{u2} β l₂))\nbut is expected to have type\n  forall {α : Type.{u3}} {β : Type.{u2}} {γ : Type.{u1}} (f : α -> β -> γ) (l₁ : List.{u3} α) (l₂ : List.{u2} β), Eq.{1} Nat (List.length.{u1} γ (List.zipWith.{u3, u2, u1} α β γ f l₁ l₂)) (Min.min.{0} Nat instMinNat (List.length.{u3} α l₁) (List.length.{u2} β l₂))\nCase conversion may be inaccurate. Consider using '#align list.length_map₂ List.length_zipWithₓ'. -/\n@[simp]\ntheorem length_zipWith (f : α → β → γ) (l₁) :\n    ∀ l₂, length (zipWith f l₁ l₂) = min (length l₁) (length l₂) := by\n  induction l₁ <;> intro l₂ <;> cases l₂ <;>\n    simp [*, add_one, min_succ_succ, Nat.zero_min, Nat.min_zero]\n#align list.length_map₂ List.length_zipWith\n\n/- warning: list.length_take -> List.length_take is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} (i : Nat) (l : List.{u1} α), Eq.{1} Nat (List.length.{u1} α (List.take.{u1} α i l)) (LinearOrder.min.{0} Nat Nat.linearOrder i (List.length.{u1} α l))\nbut is expected to have type\n  forall {α : Type.{u1}} (i : Nat) (l : List.{u1} α), Eq.{1} Nat (List.length.{u1} α (List.take.{u1} α i l)) (Min.min.{0} Nat instMinNat i (List.length.{u1} α l))\nCase conversion may be inaccurate. Consider using '#align list.length_take List.length_takeₓ'. -/\n@[simp]\ntheorem length_take : ∀ (i : ℕ) (l : List α), length (take i l) = min i (length l)\n  | 0, l => by simp [Nat.zero_min]\n  | succ n, [] => by simp [Nat.min_zero]\n  | succ n, a :: l => by simp [*, Nat.min_succ_succ, add_one]\n#align list.length_take List.length_take\n\n#print List.length_take_le /-\ntheorem length_take_le (n) (l : List α) : length (take n l) ≤ n := by simp [min_le_left]\n#align list.length_take_le List.length_take_le\n-/\n\n#print List.length_removeNth /-\ntheorem length_removeNth :\n    ∀ (l : List α) (i : ℕ), i < length l → length (removeNth l i) = length l - 1\n  | [], _, h => rfl\n  | x :: xs, 0, h => by simp [remove_nth]\n  | x :: xs, i + 1, h => by\n    have : i < length xs := lt_of_succ_lt_succ h\n    dsimp [remove_nth] <;>\n        rw [length_remove_nth xs i this,\n          Nat.sub_add_cancel (lt_of_le_of_lt (Nat.zero_le _) this)] <;>\n      rfl\n#align list.length_remove_nth List.length_removeNth\n-/\n\n@[simp]\ntheorem partition_eq_filter_filter (p : α → Prop) [DecidablePred p] :\n    ∀ l : List α, partition p l = (filter p l, filter (Not ∘ p) l)\n  | [] => rfl\n  | a :: l => by by_cases pa : p a <;> simp [partition, Filter, pa, partition_eq_filter_filter l]\n#align list.partition_eq_filter_filter List.partitionₓ_eq_filterₓ_filterₓ\n\n/-! sublists -/\n\n\n#print List.Sublist /-\ninductive Sublist : List α → List α → Prop\n  | slnil : sublist [] []\n  | cons (l₁ l₂ a) : sublist l₁ l₂ → sublist l₁ (a :: l₂)\n  | cons2 (l₁ l₂ a) : sublist l₁ l₂ → sublist (a :: l₁) (a :: l₂)\n#align list.sublist List.Sublist\n-/\n\n-- mathport name: «expr <+ »\ninfixl:50 \" <+ \" => Sublist\n\n#print List.length_le_of_sublist /-\ntheorem length_le_of_sublist : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → length l₁ ≤ length l₂\n  | _, _, sublist.slnil => le_refl 0\n  | _, _, sublist.cons l₁ l₂ a s => le_succ_of_le (length_le_of_sublist s)\n  | _, _, sublist.cons2 l₁ l₂ a s => succ_le_succ (length_le_of_sublist s)\n#align list.length_le_of_sublist List.length_le_of_sublist\n-/\n\n/-! filter -/\n\n\n/- warning: list.filter_nil -> List.filter_nil is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} (p : α -> Prop) [h : DecidablePred.{succ u1} α p], Eq.{succ u1} (List.{u1} α) (List.filterₓ.{u1} α p (fun (a : α) => h a) (List.nil.{u1} α)) (List.nil.{u1} α)\nbut is expected to have type\n  forall {α : Type.{u1}} (p : α -> Bool), Eq.{succ u1} (List.{u1} α) (List.filter.{u1} α p (List.nil.{u1} α)) (List.nil.{u1} α)\nCase conversion may be inaccurate. Consider using '#align list.filter_nil List.filter_nilₓ'. -/\n@[simp]\ntheorem filter_nil (p : α → Prop) [h : DecidablePred p] : filter p [] = [] :=\n  rfl\n#align list.filter_nil List.filter_nil\n\n/- warning: list.filter_cons_of_pos -> List.filter_cons_of_pos is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {p : α -> Prop} [h : DecidablePred.{succ u1} α p] {a : α} (l : List.{u1} α), (p a) -> (Eq.{succ u1} (List.{u1} α) (List.filterₓ.{u1} α p (fun (a : α) => h a) (List.cons.{u1} α a l)) (List.cons.{u1} α a (List.filterₓ.{u1} α p (fun (a : α) => h a) l)))\nbut is expected to have type\n  forall {α : Type.{u1}} {p : α -> Bool} {h : α} (a : List.{u1} α), (Eq.{1} Bool (p h) Bool.true) -> (Eq.{succ u1} (List.{u1} α) (List.filter.{u1} α p (List.cons.{u1} α h a)) (List.cons.{u1} α h (List.filter.{u1} α p a)))\nCase conversion may be inaccurate. Consider using '#align list.filter_cons_of_pos List.filter_cons_of_posₓ'. -/\n@[simp]\ntheorem filter_cons_of_pos {p : α → Prop} [h : DecidablePred p] {a : α} :\n    ∀ l, p a → filter p (a :: l) = a :: filter p l := fun l pa => if_pos pa\n#align list.filter_cons_of_pos List.filter_cons_of_pos\n\n/- warning: list.filter_cons_of_neg -> List.filter_cons_of_neg is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {p : α -> Prop} [h : DecidablePred.{succ u1} α p] {a : α} (l : List.{u1} α), (Not (p a)) -> (Eq.{succ u1} (List.{u1} α) (List.filterₓ.{u1} α p (fun (a : α) => h a) (List.cons.{u1} α a l)) (List.filterₓ.{u1} α p (fun (a : α) => h a) l))\nbut is expected to have type\n  forall {α : Type.{u1}} {p : α -> Bool} {h : α} (a : List.{u1} α), (Not (Eq.{1} Bool (p h) Bool.true)) -> (Eq.{succ u1} (List.{u1} α) (List.filter.{u1} α p (List.cons.{u1} α h a)) (List.filter.{u1} α p a))\nCase conversion may be inaccurate. Consider using '#align list.filter_cons_of_neg List.filter_cons_of_negₓ'. -/\n@[simp]\ntheorem filter_cons_of_neg {p : α → Prop} [h : DecidablePred p] {a : α} :\n    ∀ l, ¬p a → filter p (a :: l) = filter p l := fun l pa => if_neg pa\n#align list.filter_cons_of_neg List.filter_cons_of_neg\n\n/- warning: list.filter_append -> List.filter_append is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {p : α -> Prop} [h : DecidablePred.{succ u1} α p] (l₁ : List.{u1} α) (l₂ : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.filterₓ.{u1} α p (fun (a : α) => h a) (Append.append.{u1} (List.{u1} α) (List.hasAppend.{u1} α) l₁ l₂)) (Append.append.{u1} (List.{u1} α) (List.hasAppend.{u1} α) (List.filterₓ.{u1} α p (fun (a : α) => h a) l₁) (List.filterₓ.{u1} α p (fun (a : α) => h a) l₂))\nbut is expected to have type\n  forall {α : Type.{u1}} {p : α -> Bool} (h : List.{u1} α) (l₁ : List.{u1} α), Eq.{succ u1} (List.{u1} α) (List.filter.{u1} α p (HAppend.hAppend.{u1, u1, u1} (List.{u1} α) (List.{u1} α) (List.{u1} α) (instHAppend.{u1} (List.{u1} α) (List.instAppendList.{u1} α)) h l₁)) (HAppend.hAppend.{u1, u1, u1} (List.{u1} α) (List.{u1} α) (List.{u1} α) (instHAppend.{u1} (List.{u1} α) (List.instAppendList.{u1} α)) (List.filter.{u1} α p h) (List.filter.{u1} α p l₁))\nCase conversion may be inaccurate. Consider using '#align list.filter_append List.filter_appendₓ'. -/\n@[simp]\ntheorem filter_append {p : α → Prop} [h : DecidablePred p] :\n    ∀ l₁ l₂ : List α, filter p (l₁ ++ l₂) = filter p l₁ ++ filter p l₂\n  | [], l₂ => rfl\n  | a :: l₁, l₂ => by by_cases pa : p a <;> simp [pa, filter_append]\n#align list.filter_append List.filter_append\n\n/- warning: list.filter_sublist -> List.filter_sublist is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {p : α -> Prop} [h : DecidablePred.{succ u1} α p] (l : List.{u1} α), List.Sublist.{u1} α (List.filterₓ.{u1} α p (fun (a : α) => h a) l) l\nbut is expected to have type\n  forall {α : Type.{u1}} {p : α -> Bool} (h : List.{u1} α), List.Sublist.{u1} α (List.filter.{u1} α p h) h\nCase conversion may be inaccurate. Consider using '#align list.filter_sublist List.filter_sublistₓ'. -/\n@[simp]\ntheorem filter_sublist {p : α → Prop} [h : DecidablePred p] : ∀ l : List α, filter p l <+ l\n  | [] => Sublist.slnil\n  | a :: l =>\n    if pa : p a then by simp [pa] <;> apply sublist.cons2 <;> apply filter_sublist l\n    else by simp [pa] <;> apply sublist.cons <;> apply filter_sublist l\n#align list.filter_sublist List.filter_sublist\n\n/-! map_accumr -/\n\n\nsection MapAccumr\n\nvariable {φ : Type w₁} {σ : Type w₂}\n\n/- warning: list.map_accumr -> List.mapAccumr is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} {σ : Type.{u3}}, (α -> σ -> (Prod.{u3, u2} σ β)) -> (List.{u1} α) -> σ -> (Prod.{u3, u2} σ (List.{u2} β))\nbut is expected to have type\n  forall {α : Type.{u1}} {β : Type.{u2}} {σ : Type.{u3}}, (β -> α -> (Prod.{u1, u3} α σ)) -> (List.{u2} β) -> α -> (Prod.{u1, u3} α (List.{u3} σ))\nCase conversion may be inaccurate. Consider using '#align list.map_accumr List.mapAccumrₓ'. -/\n-- This runs a function over a list returning the intermediate results and a\n-- a final result.\ndef mapAccumr (f : α → σ → σ × β) : List α → σ → σ × List β\n  | [], c => (c, [])\n  | y :: yr, c =>\n    let r := map_accumr yr c\n    let z := f y r.1\n    (z.1, z.2 :: r.2)\n#align list.map_accumr List.mapAccumr\n\n/- warning: list.length_map_accumr -> List.length_mapAccumr is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} {σ : Type.{u3}} (f : α -> σ -> (Prod.{u3, u2} σ β)) (x : List.{u1} α) (s : σ), Eq.{1} Nat (List.length.{u2} β (Prod.snd.{u3, u2} σ (List.{u2} β) (List.mapAccumr.{u1, u2, u3} α β σ f x s))) (List.length.{u1} α x)\nbut is expected to have type\n  forall {α : Type.{u3}} {β : Type.{u2}} {σ : Type.{u1}} (f : β -> α -> (Prod.{u3, u1} α σ)) (x : List.{u2} β) (s : α), Eq.{1} Nat (List.length.{u1} σ (Prod.snd.{u3, u1} α (List.{u1} σ) (List.mapAccumr.{u3, u2, u1} α β σ f x s))) (List.length.{u2} β x)\nCase conversion may be inaccurate. Consider using '#align list.length_map_accumr List.length_mapAccumrₓ'. -/\n@[simp]\ntheorem length_mapAccumr :\n    ∀ (f : α → σ → σ × β) (x : List α) (s : σ), length (mapAccumr f x s).2 = length x\n  | f, a :: x, s => congr_arg succ (length_map_accumr f x s)\n  | f, [], s => rfl\n#align list.length_map_accumr List.length_mapAccumr\n\nend MapAccumr\n\nsection MapAccumr₂\n\nvariable {φ : Type w₁} {σ : Type w₂}\n\n/- warning: list.map_accumr₂ -> List.mapAccumr₂ is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} {φ : Type.{u3}} {σ : Type.{u4}}, (α -> β -> σ -> (Prod.{u4, u3} σ φ)) -> (List.{u1} α) -> (List.{u2} β) -> σ -> (Prod.{u4, u3} σ (List.{u3} φ))\nbut is expected to have type\n  forall {α : Type.{u1}} {β : Type.{u2}} {φ : Type.{u3}} {σ : Type.{u4}}, (φ -> σ -> β -> (Prod.{u2, u1} β α)) -> (List.{u3} φ) -> (List.{u4} σ) -> β -> (Prod.{u2, u1} β (List.{u1} α))\nCase conversion may be inaccurate. Consider using '#align list.map_accumr₂ List.mapAccumr₂ₓ'. -/\n-- This runs a function over two lists returning the intermediate results and a\n-- a final result.\ndef mapAccumr₂ (f : α → β → σ → σ × φ) : List α → List β → σ → σ × List φ\n  | [], _, c => (c, [])\n  | _, [], c => (c, [])\n  | x :: xr, y :: yr, c =>\n    let r := map_accumr₂ xr yr c\n    let q := f x y r.1\n    (q.1, q.2 :: r.2)\n#align list.map_accumr₂ List.mapAccumr₂\n\n/- warning: list.length_map_accumr₂ -> List.length_mapAccumr₂ is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} {β : Type.{u2}} {φ : Type.{u3}} {σ : Type.{u4}} (f : α -> β -> σ -> (Prod.{u4, u3} σ φ)) (x : List.{u1} α) (y : List.{u2} β) (c : σ), Eq.{1} Nat (List.length.{u3} φ (Prod.snd.{u4, u3} σ (List.{u3} φ) (List.mapAccumr₂.{u1, u2, u3, u4} α β φ σ f x y c))) (LinearOrder.min.{0} Nat Nat.linearOrder (List.length.{u1} α x) (List.length.{u2} β y))\nbut is expected to have type\n  forall {α : Type.{u3}} {β : Type.{u4}} {φ : Type.{u2}} {σ : Type.{u1}} (f : φ -> σ -> β -> (Prod.{u4, u3} β α)) (x : List.{u2} φ) (y : List.{u1} σ) (c : β), Eq.{1} Nat (List.length.{u3} α (Prod.snd.{u4, u3} β (List.{u3} α) (List.mapAccumr₂.{u3, u4, u2, u1} α β φ σ f x y c))) (Min.min.{0} Nat instMinNat (List.length.{u2} φ x) (List.length.{u1} σ y))\nCase conversion may be inaccurate. Consider using '#align list.length_map_accumr₂ List.length_mapAccumr₂ₓ'. -/\n@[simp]\ntheorem length_mapAccumr₂ :\n    ∀ (f : α → β → σ → σ × φ) (x y c), length (mapAccumr₂ f x y c).2 = min (length x) (length y)\n  | f, a :: x, b :: y, c =>\n    calc\n      succ (length (mapAccumr₂ f x y c).2) = succ (min (length x) (length y)) :=\n        congr_arg succ (length_map_accumr₂ f x y c)\n      _ = min (succ (length x)) (succ (length y)) := Eq.symm (min_succ_succ (length x) (length y))\n      \n  | f, a :: x, [], c => rfl\n  | f, [], b :: y, c => rfl\n  | f, [], [], c => rfl\n#align list.length_map_accumr₂ List.length_mapAccumr₂\n\nend MapAccumr₂\n\nend List\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/List/Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.785209679650878}}
{"text": "-- based on Lean Tutorial / 05_sequence_limits.lean\nimport resources\n\n/- \nUseful lemmata:\n\n`le_max_left  p q` says `p ≤ max p q`\n`le_max_right p q` says `q ≤ max p q`\n\n`eq_of_abs_sub_le_all_pos x y` says `(∀ ε > 0, |x - y| ≤ ε) → x = y`\n-/\n\n-- This is the definition of limit we will work with in all exercises here.\ndef seq_limit (s : ℕ → ℝ) (a : ℝ) : Prop :=\n∀ ε : ℝ, ε > 0 → ∃ n₀ : ℕ, ∀ n : ℕ, n ≥ n₀ → |s n - a| ≤ ε\n\n\n-- Arithmetic of limits ... the sum law:\n-- If [`u` approaches `a`] and [`v` approaches `b`],\n-- then [`u + v` approaches `a + b`].\nexample (u v : ℕ → ℝ) (a b : ℝ) (hu : seq_limit u a) (hv : seq_limit v b) :\n  seq_limit (u + v) (a + b) :=\nbegin\n  intros ε epp,\n  cases hu (ε / 2) (half_pos epp) with Nᵤ ha,\n  cases hv (ε / 2) (half_pos epp) with Nᵥ hb,\n  use max Nᵤ Nᵥ,\n  intros n n_large,\n\n  specialize ha n (by calc\n    n   ≥ max Nᵤ Nᵥ : n_large\n    ... ≥ Nᵤ        : le_max_left Nᵤ Nᵥ\n  ),\n  specialize hb n (by calc\n    n   ≥ max Nᵤ Nᵥ : n_large\n    ... ≥ Nᵥ        : le_max_right Nᵤ Nᵥ\n  ),\n\n  calc  |(u + v) n - (a + b)|\n      = |u n + v n - (a + b)|   : rfl\n  ... = |(u n - a) + (v n - b)| : by ring_nf\n  ... ≤  |u n - a| + |v n - b|  : abs_add (u n - a) (v n - b)\n  ... ≤    (ε / 2) + (ε / 2)    : add_le_add ha hb\n  ... =            ε            : add_halves ε,\nend\n\n-- Squeeze theorem (a.k.a. \"Sandwich rule\" or \"Two policemen and a drunk\"):\n-- If [`u` approaches `z`] and [`v` approaches `z`],\n-- then [`w` such that `u ≤ w ≤ v` approaches `z` as well].\nexample (u v w : ℕ → ℝ) (z : ℝ) (hu : seq_limit u z) (hv : seq_limit v z)\n        (below : ∀ n, u n ≤ w n) (above : ∀ n, w n ≤ v n) :\n  seq_limit w z :=\nbegin\n  intros ε epp,\n  cases hu ε epp with Nᵤ huz,\n  cases hv ε epp with Nᵥ hvz,\n  use max Nᵤ Nᵥ,\n  intros n n_large,\n  specialize huz n (le_of_max_le_left  n_large),\n  specialize hvz n (le_of_max_le_right n_large),\n  specialize below n,\n  specialize above n,\n  cases abs_sub_le_iff.mp huz with hu_left hu_right,\n  cases abs_sub_le_iff.mp hvz with hv_left hv_right,\n  rw abs_sub_le_iff,\n  split;\n  linarith,\nend\n\n-- A sequence admits at most one limit.\nexample (w : ℕ → ℝ) (a b : ℝ) (ha : seq_limit w a) (hb : seq_limit w b) :\n  a = b :=\nbegin\n  apply eq_of_abs_sub_le_all_pos,\n  intros ε epp,\n  cases ha (ε / 2) (half_pos epp) with N₁ hwa,\n  cases hb (ε / 2) (half_pos epp) with N₂ hwb,\n  specialize hwa (max N₁ N₂) (le_max_left  N₁ N₂),\n  specialize hwb (max N₁ N₂) (le_max_right N₁ N₂),\n  cases abs_sub_le_iff.mp hwa with ha_left ha_right,\n  cases abs_sub_le_iff.mp hwb with hb_left hb_right,\n  rw abs_sub_le_iff,\n  split;\n  linarith,\nend\n", "meta": {"author": "madvorak", "repo": "lean-showcase", "sha": "d405796deef7a7903befa438d5d7ac2873960a98", "save_path": "github-repos/lean/madvorak-lean-showcase", "path": "github-repos/lean/madvorak-lean-showcase/lean-showcase-d405796deef7a7903befa438d5d7ac2873960a98/src/sequence_limits_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7852091687951539}}
{"text": "import plane_separation_world.level07 --hide\nopen IncidencePlane --hide\n\n/-\n# Plane Separation World\n\n## Level 8: on the way to the final level (V).\n\nThis is the last of the 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 the segments A·B and B·C are on the same side of the line ℓ, there exists a point P, which satisfies that `(P = A ∨ P = C ∨ A*P*C) ∧ P ∈ ℓ`, \nsuch that A * P * C. \n\n**Proof:** \n\n**(i)** By the lemma `same_side_of_noncollinear_ne_line`, since the segments A·B and B·C are on the same side of ℓ, then `A ∉ ℓ ∧ B ∉ ℓ ∧ C ∉ ℓ`.\n\nNow we proceed with the proof by cases: \n\n**Case 1:** Let us assume that `P ≠ A`. That is, `(P = A) → false`. Then, let us assume that `P = A`. Now, we want to prove that this is false. In (i) we proved \nthat `A ∉ ℓ`. That is, `(A ∈ ℓ) → false`. Because we want to prove `false`, it suffices to prove that `A ∈ ℓ`. Because we assumed that `P = A` and we know \nthat `P ∈ ℓ`, then `A ∈ ℓ`. Therefore, we have shown that `P ≠ A`.\n\n**Case 2:** Let us assume that `P ≠ C`. That is, `(P = C) → false`. Then, let us assume that `P = C`. Now, we want to prove that this is false. In (i) we proved \nthat `C ∉ ℓ`. That is, `(C ∈ ℓ) → false`. Because we want to prove `false`, it suffices to prove that `C ∈ ℓ`. Because we assumed that `P = C` and we know that `P ∈ ℓ`,\nthen `C ∈ ℓ`. Therefore, we have shown that `P ≠ C`.\n\n**Case 3:** Let us assume that `A * P * C`. Given that the point P either satisfies `P = A ∨ P = C ∨ A*P*C`, because we proved that `P ≠ A` in Case 1 and \nthat `P ≠ C` in Case 2, then P must satisfy that `A * P * C`. [In Lean, the `tauto` tactic should close this case automatically.] \n \n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nIf you have a theorem statement called `theorem1`, which shows `x` by using the hypothesis `h : P`, then `have htheorem := theorem1 h` \nwill add the hypothesis `htheorem : x` to the local context. 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 {Ω : Type} [IncidencePlane Ω] --hide\nvariables {A B C P Q R : Ω} --hide\nvariables {ℓ r s t : Line Ω} --hide\n\n/- Lemma :\nIf the segments A·B and B·C are on the same side of the line ℓ, there exists a point P, which satisfies that `(P = A ∨ P = C ∨ A*P*C) ∧ P ∈ ℓ`, such that A * P * C. \n-/\nlemma not_same_side_point_in_between (hlAB : same_side ℓ A B) (hlBC : same_side ℓ B C) (hPAC: (P = A ∨ P = C ∨ A*P*C) ∧ P ∈ ℓ) : A * P * C :=\nbegin \n  have c := same_side_of_noncollinear_ne_line hlAB hlBC,\n  have hPA : P ≠ A,\n  {\n    intro hc,\n    apply c.1,\n    rw hc at hPAC,\n    exact hPAC.2,\n  },\n  have hPA : P ≠ C,\n  {\n    intro hc,\n    apply c.2.2,\n    rw hc at hPAC,\n    exact hPAC.2,\n  },\n  tauto,\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/level08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7852091562087449}}
{"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.multiset.nodup\nimport data.list.nat_antidiagonal\n\n/-!\n# The \"antidiagonal\" {(0,n), (1,n-1), ..., (n,0)} as a multiset.\n-/\n\nnamespace multiset\nnamespace nat\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 : ℕ) : multiset (ℕ × ℕ) :=\nlist.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] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :\n  x ∈ antidiagonal n ↔ x.1 + x.2 = n :=\nby rw [antidiagonal, mem_coe, list.nat.mem_antidiagonal]\n\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp] lemma card_antidiagonal (n : ℕ) : (antidiagonal n).card = n+1 :=\nby rw [antidiagonal, coe_card, list.nat.length_antidiagonal]\n\n/-- The antidiagonal of `0` is the list `[(0,0)]` -/\n@[simp] lemma antidiagonal_zero : antidiagonal 0 = {(0, 0)} :=\nrfl\n\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\n@[simp] lemma nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) :=\ncoe_nodup.2 $ list.nat.nodup_antidiagonal n\n\n@[simp] lemma antidiagonal_succ {n : ℕ} :\n  antidiagonal (n + 1) = (0, n + 1) ::ₘ ((antidiagonal n).map (prod.map nat.succ id)) :=\nby simp only [antidiagonal, list.nat.antidiagonal_succ, coe_map, cons_coe]\n\nend nat\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/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7851569925454894}}
{"text": "/- NATURAL NUMBERS\n\nWe saw the definition of the natural numbers `Nat` and the addition on them on the slides.\nSince we want to define it ourselves and not use Lean's built-in version, we will call ours `Nat'`.\n -/\ninductive Nat' : Type\n  | zero : Nat'\n  | succ : Nat' → Nat'\n\nopen Nat'\n\ndef add (m n : Nat') : Nat' :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\n-- Let us now try to recursively define multiplication on the `Nat'`.\ndef mul (m n : Nat') : Nat' := \n  match n with\n  | zero   => zero\n  | succ n => add (mul m n) m\n\n-- Next, check your definition of `mul` by evaluating a few examples. This can be done with the\n-- command `#eval`.\n\n-- Let's define `≤` as an inductive predicate on `Nat'`s!\ninductive LE' : Nat' → Nat' → Prop where\n  | refl (n : Nat') : LE' n n\n  -- TODO: We're off to a good start since `≤` is certainly reflexive, but something is still\n  -- missing (or else we'd just redefine `Eq` for `Nat'`s). Can you think of one more constructor\n  -- that makes it so `LE' n m` holds whenever we would intuitively expect `n ≤ m` to hold?\n  -- hint: it remains to be shown that `LE' n m` should hold when `m` is *greater* than `n`, so\n  -- the new constructor should probably involve `Nat'`'s `succ` constructor to reach those greater numbers.\n  -- hint: it should be an *inductive* case, meaning using another `LE'` application as an assumption\n  -- note: `LE'` could also be defined in terms of `add`, but that makes working with it awkward,\n  -- so let's not do that.\n  | succ : LE' m n → LE' m (succ n)\n\n-- Now let's prove some things about `LE'`. But first we'll give it the standard notation.\ninfix:50 \" ≤ \" => LE'\n\nexample (n : Nat') : n ≤ succ (succ n) := \n  LE'.succ (LE'.succ LE'.refl)\n\n-- This one is a bit harder: we will need induction!\n-- As described on the slides, induction is just a special case of recursion\ntheorem le_add (m n : Nat') : m ≤ add m n :=\n  match n with\n  -- This is the base case\n  | zero => LE'.refl\n  -- This is the inductive case. You probably want to use `le_add m n` (the inductive hypothesis) somewhere inside of it!\n  | succ n =>\n    -- Lean automatically converts `add m (succ n)` to `succ (add m n)` for us when necessary, but it can help\n    -- to make the conversion explicit. `show` simply lets us restate the goal, using any definitionally equal type.\n    show m ≤ succ (add m n) from\n    LE'.succ (le_add m n)\n\n-- Now try proving this theorem on `add` using the same induction scheme\ntheorem zero_add (n : Nat') : add zero n = add n zero := \n  match n with\n  | zero => rfl\n  | succ n =>\n    show succ (add zero n) = succ (add n zero) from\n    zero_add n ▸ rfl\n\n/-\nLISTS\n\nThe type `List α` of lists on a Type α is defined to be the type on the constructors\n`nil : List α`\nand\n`cons : α → List α → List α`.\n\nWe can use `[]` as a notation for `nil` and `x :: xs` as a notation for `cons x xs`.\n-/\nopen List\n\n\n-- Let's define something we can't in most other functional languages:\n-- a function returning the first element of a list given a proof that is is non-empty! (`xs ≠ []` is shorthand for `¬ (xs = [])`)\ndef hd (xs : List α) : xs ≠ [] → α := \n  fun hf =>\n    match xs with\n    | []      => False.elim (hf rfl)\n    | x :: xs => x\n-- Did you notice that `hd` is a dependent function? The *type/proposition* of the second parameter depends on the *value* of the first.\n-- We can write `hd`s type as `∀ (xs : List α), xs ≠ [] → α` or, equivalently, `(xs : List α) → xs ≠ [] → α`.\n\n/- \nTREES\n\nDefine a type `Tree α` of binary trees with node labels of type `α`. Each tree is either a labelled leaf or a labelled inner node with two trees attached to it.\n -/\n\ninductive Tree (α : Type) : Type where\n  | leaf : α → Tree α\n  | node : α → Tree α → Tree α → Tree α\n\nopen Tree\n\n-- Now, let us define the depth and the size of a tree. You can use the function `Nat.max` to get the maximum of two natural numbers. The depth of a leaf is 1.\ndef depth (t : Tree α) : Nat := \n  match t with\n  | leaf a     => 1\n  | node a l r => Nat.max (depth l) (depth r) + 1 \n\ndef size (t : Tree α) : Nat := \n  match t with\n  | leaf a     => 1\n  | node a l r => 1 + size l + size r\n\n-- We can turn a tree into a list by traversing it in various ways, depending on whether we add the root\n-- before its subtrees (preOrder), between its subtrees (inOrder) or after its subtrees (postOrder).\n-- Define preOrder, inOrder, and postOrder as functions `Tree α → List α`.\ndef preOrder (t : Tree α) : List α := \n  match t with\n  | leaf a     => [a]\n  | node a l r => a :: preOrder l ++ preOrder r\n\ndef inOrder (t : Tree α) : List α := \n  match t with\n  | leaf a     => [a]\n  | node a l r => inOrder l ++ a :: inOrder r\n\ndef postOrder (t : Tree α) : List α := \n  match t with\n  | leaf a     => [a]\n  | node a l r => postOrder l ++ postOrder r ++ [a]\n\n-- Define a function which returns the mirror image of a given tree.\ndef mirror (t : Tree α) : Tree α := \n  match t with\n  | leaf a     => leaf a\n  | node a l r => node a (mirror r) (mirror l)\n\n-- Now we prove to facts about this function:\n-- First, we prove that it is involutive (mirroring a tree twice returns the original tree).\n-- Then, we prove that the mirror image of two trees is equal, if and only if the trees themselves are.\n\n-- Useful lemmas, if you don't want to use ▸ as much (but it is also just as doable with some `have`s and ▸):\n#check @Eq.trans\n#check @Eq.symm\n#check @congrArg\n\ntheorem mirror_involutive (t : Tree α) : mirror (mirror t) = t := \n  match t with\n  | leaf _     => rfl\n  | node _ l r =>\n    show node .. = _ from  -- `..` is syntax sugar for an appropriate number of `_`s\n      Eq.symm (mirror_involutive l) ▸ Eq.symm (mirror_involutive r) ▸ rfl\n\n-- hint: try using `mirror_involutive`\ntheorem mirror_eq (s t : Tree α) : mirror s = mirror t ↔ s = t := \n  Iff.intro\n    (fun h => \n      have mmsmmt : mirror (mirror s) = mirror (mirror t) := h ▸ rfl\n      mirror_involutive s ▸ mirror_involutive t ▸ mmsmmt)\n    (fun h => congrArg mirror h)\n\n/- STRUCTURES -/\n\n-- Define the structure `Semigroup α` for a semigroup on a type `α`.\n-- Reminder: A semigroup is an algebraic structure with an associative binary operation `mul`.\nstructure Semigroup (α : Type) where \n  mul : α → α → α\n  assoc : mul (mul a b) c = mul a (mul b c) \n\n-- Now extend the structure to one for a monoid on α.\n-- Reminder : A monoid is a semigroup with an element which acts as the left and right identity on `mul`.\nstructure Monoid (α : Type) extends Semigroup α where \n  e : α\n  e_mul : mul e a = a\n  mul_e : mul a e = a \n\n-- Now try to instantiate the type `Nat'` as a monoid.\n-- Leave out the three proofs (associativity, left and right inverse), we'll learn better ways to write such proofs next week.\ndef Nat'Monoid : Monoid Nat' := \n  { mul := mul,\n    assoc := sorry,\n    e := succ zero,\n    e_mul := sorry,\n    mul_e := sorry }\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/Solutions/Exercise3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669373100424, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7851028772916905}}
{"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-- the next import will be enough for this sheet\nimport topology.basic\n\n/-!\n\n# Topology : making the API for `interior`.\n\n(I'll assume you know the mathematics behind the interior of a subset of a topological space\nin this sheet). \n\nThe way to make a type `X` into a topological space is to \ntell the type class inference system that you'd like it to\nkeep track of a topological space structure on `X`. So it's\n\n`variables (X : Type) [topological_space X]`\n\nLean has interiors of topological spaces, but let's\nmake our own, as warm-up.\n\n-/\n\n-- Here's the notation we'll use in this sheet\nvariables {X : Type} [topological_space X] (S : set X)\n\n/-\n\n## The API for topological spaces\n\n`is_open S : Prop` is the predicate that `S : set X` is open.\n\nNow here's some standard facts from topology. I'll tell you the names\nof the proofs, you can guess what they're proofs of\n(and then check with `#check`, which tells you the type of a term, so\nif you give it a theorem proof it will tell you the theorem statement). \n\n* is_open_univ\n* is_open_Union, is_open_bUnion, is_open_sUnion (note the capital U)\n* is_open.inter (note the small i) (and the dot to enable dot notation)\n\n-/\n\n/-\n\n## Interiors\n\nLean has interior of a set, but let's make them ourselves\nbecause it's a nice exercise.\n\n-/\n\n-- Got to call it `interior'` with a dash, because Lean already has `interior`\n-- The following would work for the definition -- a \"bUnion\".\ndef interior' (S : set X) : set X := ⋃ (U ∈ {V : set X | is_open V ∧ V ⊆ S}), U\n\n-- useful for rewrites; saves you having to unfold `interior'` (a good Lean\n-- proof should never use `unfold` unless you're making API).\nlemma mem_interior' (x : X) : x ∈ interior' S ↔ ∃ (U : set X) (hU : is_open U) (hUS : U ⊆ S), x ∈ U :=\nbegin\n  unfold interior',\n  rw set.mem_bUnion_iff,\n  finish,\nend\n\n\n\n/-\nTwo alternative definitions: a Union of a Union, Union of a Union of a Union, or a sUnion.\n\n-- Union of Union\ndef interior'' (S : set X) : set X := ⋃ (U : set X) (h : is_open U ∧ U ⊆ S), U\n\n-- Union of Union of Union\ndef interior'' (S : set X) : set X := ⋃ (U : set X) (hU : is_open U) (hUS : U ⊆ S), U\n\n-- sUnion\ndef interior''' (S : set X) : set X := ⋃₀ ({V : set X | is_open V ∧ V ⊆ S})\n\nYou can try one of those if you'd rather. Then in the above proof you might end up\nrewriting set.mem_Union_iff or set.mem_sUnion_iff.\n-/\n\n-- Lean has `is_open_Union` and `is_open_bUnion` and `is_open_sUnion`.\n-- Because our definition is a `bUnion`, we could start with `apply is_open_bUnion`,\n-- the \"correct form\" of the assertion that an arbitrary \n\nlemma interior'_open : is_open (interior' S) := \nbegin\n  sorry\nend\n\nlemma interior'_subset : interior' S ⊆ S :=\nbegin\n  sorry,\nend\n\n-- Lean can work out S from hUS so let's make S a {} input for this one\n\nvariable {S}\n\nlemma subset_interior' {U : set X} (hU : is_open U) (hUS : U ⊆ S) : U ⊆ interior' S :=\nbegin\n  sorry,\nend\n\n\n-- Similarly here I put S and T in squiggly brackets because Lean can figure them out\n-- when it sees hST\nlemma interior'_mono {S T : set X} (hST : S ⊆ T) : interior' S ⊆ interior' T :=\nbegin\n  sorry,\nend\n\n-- instead of starting this with `ext`, you could `apply set.subset.antisymm`,\n-- which is the statement that if S ⊆ T and T ⊆ S then S = T.\nlemma interior'_interior' : interior' (interior' S) = interior' S :=\nbegin\n  sorry,\nend\n\n-- Some examples of interiors\nlemma interior'_empty : interior' (∅ : set X) = ∅ :=\nbegin\n  sorry,\nend\n\nlemma interior'_univ : interior' (set.univ : set X) = set.univ :=\nbegin\n  sorry,\nend\n\nlemma interior'_inter (S T : set X) : interior' (S ∩ T) = interior' S ∩ interior' T :=\nbegin\n  sorry,\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/section07topology/sheet2interiors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7850745333225563}}
{"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.sphere.basic\n\n/-!\n# Second intersection of a sphere and a line\n\nThis file defines and proves basic results about the second intersection of a sphere with a line\nthrough a point on that sphere.\n\n## Main definitions\n\n* `euclidean_geometry.sphere.second_inter` is the second intersection of a sphere with a line\n  through a point on that sphere.\n\n-/\n\nnoncomputable theory\nopen_locale real_inner_product_space\n\nnamespace euclidean_geometry\n\nvariables {V : Type*} {P : Type*}\n  [normed_add_comm_group V] [inner_product_space ℝ V] [metric_space P] [normed_add_torsor V P]\ninclude V\n\n/-- The second intersection of a sphere with a line through a point on that sphere; that point\nif it is the only point of intersection of the line with the sphere. The intended use of this\ndefinition is when `p ∈ s`; the definition does not use `s.radius`, so in general it returns\nthe second intersection with the sphere through `p` and with center `s.center`. -/\ndef sphere.second_inter (s : sphere P) (p : P) (v : V) : P :=\n(-2 * ⟪v, p -ᵥ s.center⟫ / ⟪v, v⟫) • v +ᵥ p\n\n/-- The distance between `second_inter` and the center equals the distance between the original\npoint and the center. -/\n@[simp] lemma sphere.second_inter_dist (s : sphere P) (p : P) (v : V) :\n  dist (s.second_inter p v) s.center = dist p s.center :=\nbegin\n  rw sphere.second_inter,\n  by_cases hv : v = 0, { simp [hv] },\n  rw dist_smul_vadd_eq_dist _ _ hv,\n  exact or.inr rfl\nend\n\n/-- The point given by `second_inter` lies on the sphere. -/\n@[simp] \n\nvariables (V)\n\n/-- If the vector is zero, `second_inter` gives the original point. -/\n@[simp] lemma sphere.second_inter_zero (s : sphere P) (p : P) :\n  s.second_inter p (0 : V) = p :=\nby simp [sphere.second_inter]\n\nvariables {V}\n\n/-- The point given by `second_inter` equals the original point if and only if the line is\northogonal to the radius vector. -/\nlemma sphere.second_inter_eq_self_iff {s : sphere P} {p : P} {v : V} :\n  s.second_inter p v = p ↔ ⟪v, p -ᵥ s.center⟫ = 0 :=\nbegin\n  refine ⟨λ hp, _, λ hp, _⟩,\n  { by_cases hv : v = 0, { simp [hv] },\n    rwa [sphere.second_inter, eq_comm, eq_vadd_iff_vsub_eq, vsub_self, eq_comm, smul_eq_zero,\n         or_iff_left hv, div_eq_zero_iff, inner_self_eq_zero, or_iff_left hv, mul_eq_zero,\n         or_iff_right (by norm_num : (-2 : ℝ) ≠ 0)] at hp },\n  { rw [sphere.second_inter, hp, mul_zero, zero_div, zero_smul, zero_vadd] }\nend\n\n/-- A point on a line through a point on a sphere equals that point or `second_inter`. -/\nlemma sphere.eq_or_eq_second_inter_of_mem_mk'_span_singleton_iff_mem {s : sphere P} {p : P}\n  (hp : p ∈ s) {v : V} {p' : P} (hp' : p' ∈ affine_subspace.mk' p (ℝ ∙ v)) :\n  (p' = p ∨ p' = s.second_inter p v) ↔ p' ∈ s :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { rcases h with h | h,\n    { rwa h },\n    { rwa [h, sphere.second_inter_mem] } },\n  { rw [affine_subspace.mem_mk'_iff_vsub_mem, submodule.mem_span_singleton] at hp',\n    rcases hp' with ⟨r, hr⟩,\n    rw [eq_comm, ←eq_vadd_iff_vsub_eq] at hr,\n    subst hr,\n    by_cases hv : v = 0, { simp [hv] },\n    rw sphere.second_inter,\n    rw mem_sphere at h hp,\n    rw [←hp, dist_smul_vadd_eq_dist _ _ hv] at h,\n    rcases h with h | h;\n      simp [h] }\nend\n\n/-- `second_inter` is unchanged by multiplying the vector by a nonzero real. -/\n@[simp] lemma sphere.second_inter_smul (s : sphere P) (p : P) (v : V) {r : ℝ}\n  (hr : r ≠ 0) : s.second_inter p (r • v) = s.second_inter p v :=\nbegin\n  simp_rw [sphere.second_inter, real_inner_smul_left, inner_smul_right, smul_smul,\n           div_mul_eq_div_div],\n  rw [mul_comm, ←mul_div_assoc, ←mul_div_assoc, mul_div_cancel_left _ hr, mul_comm, mul_assoc,\n      mul_div_cancel_left _ hr, mul_comm]\nend\n\n/-- `second_inter` is unchanged by negating the vector. -/\n@[simp] lemma sphere.second_inter_neg (s : sphere P) (p : P) (v : V) :\n  s.second_inter p (-v) = s.second_inter p v :=\nby rw [←neg_one_smul ℝ v, s.second_inter_smul p v (by norm_num : (-1 : ℝ) ≠ 0)]\n\n/-- Applying `second_inter` twice returns the original point. -/\n@[simp] lemma sphere.second_inter_second_inter (s : sphere P) (p : P) (v : V) :\n  s.second_inter (s.second_inter p v) v = p :=\nbegin\n  by_cases hv : v = 0, { simp [hv] },\n  have hv' : ⟪v, v⟫ ≠ 0 := inner_self_ne_zero.2 hv,\n  simp only [sphere.second_inter, vadd_vsub_assoc, vadd_vadd, inner_add_right, inner_smul_right,\n             div_mul_cancel _ hv'],\n  rw [←@vsub_eq_zero_iff_eq V, vadd_vsub, ←add_smul, ←add_div],\n  convert zero_smul ℝ _,\n  convert zero_div _,\n  ring\nend\n\n/-- If the vector passed to `second_inter` is given by a subtraction involving the point in\n`second_inter`, the result of `second_inter` may be expressed using `line_map`. -/\nlemma sphere.second_inter_eq_line_map (s : sphere P) (p p' : P) :\n  s.second_inter p (p' -ᵥ p) =\n    affine_map.line_map p p' (-2 * ⟪p' -ᵥ p, p -ᵥ s.center⟫ / ⟪p' -ᵥ p, p' -ᵥ p⟫) :=\nrfl\n\n/-- If the vector passed to `second_inter` is given by a subtraction involving the point in\n`second_inter`, the result lies in the span of the two points. -/\nlemma sphere.second_inter_vsub_mem_affine_span (s : sphere P) (p₁ p₂ : P) :\n  s.second_inter p₁ (p₂ -ᵥ p₁) ∈ line[ℝ, p₁, p₂] :=\nsmul_vsub_vadd_mem_affine_span_pair _ _ _\n\n/-- If the vector passed to `second_inter` is given by a subtraction involving the point in\n`second_inter`, the three points are collinear. -/\nlemma sphere.second_inter_collinear (s : sphere P) (p p' : P) :\n  collinear ℝ ({p, p', s.second_inter p (p' -ᵥ p)} : set P) :=\nbegin\n  rw [set.pair_comm, set.insert_comm],\n  exact (collinear_insert_iff_of_mem_affine_span (s.second_inter_vsub_mem_affine_span _ _)).2\n    (collinear_pair ℝ _ _)\nend\n\n/-- If the vector passed to `second_inter` is given by a subtraction involving the point in\n`second_inter`, and the second point is not outside the sphere, the second point is weakly\nbetween the first point and the result of `second_inter`. -/\nlemma sphere.wbtw_second_inter {s : sphere P} {p p' : P} (hp : p ∈ s)\n  (hp' : dist p' s.center ≤ s.radius) : wbtw ℝ p p' (s.second_inter p (p' -ᵥ p)) :=\nbegin\n  by_cases h : p' = p, { simp [h] },\n  refine wbtw_of_collinear_of_dist_center_le_radius (s.second_inter_collinear p p')\n    hp hp' ((sphere.second_inter_mem _).2 hp) _,\n  intro he,\n  rw [eq_comm, sphere.second_inter_eq_self_iff, ←neg_neg (p' -ᵥ p), inner_neg_left,\n      neg_vsub_eq_vsub_rev, neg_eq_zero, eq_comm] at he,\n  exact ((inner_pos_or_eq_of_dist_le_radius hp hp').resolve_right (ne.symm h)).ne he\nend\n\n/-- If the vector passed to `second_inter` is given by a subtraction involving the point in\n`second_inter`, and the second point is inside the sphere, the second point is strictly between\nthe first point and the result of `second_inter`. -/\nlemma sphere.sbtw_second_inter {s : sphere P} {p p' : P} (hp : p ∈ s)\n  (hp' : dist p' s.center < s.radius) : sbtw ℝ p p' (s.second_inter p (p' -ᵥ p)) :=\nbegin\n  refine ⟨sphere.wbtw_second_inter hp hp'.le, _, _⟩,\n  { rintro rfl, rw mem_sphere at hp, simpa [hp] using hp' },\n  { rintro h,\n    rw [h, mem_sphere.1 ((sphere.second_inter_mem _).2 hp)] at hp',\n    exact lt_irrefl _ hp' }\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/sphere/second_inter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7850745330740115}}
{"text": "\nimport tactic \nimport .num_lemmas \nimport data.set.basic \n\nopen_locale classical \nnoncomputable theory \n\nuniverses u v w\n\nopen finset\n\nnamespace set \n\nsection basic \n\nvariables {α β : Type*} {s s' t t' r r': set α}\n\n\n@[simp] lemma absorb_union_inter (s t : set α) : s ∪ (s ∩ t) = s := \nby calc s ∪ (s ∩ t) = (s ∩ univ) ∪ (s ∩ t) : by rw inter_univ  \n                ... = s : by rw [←inter_distrib_left, union_comm, union_univ, inter_univ ]\n\n@[simp] lemma absorb_inter_union (s t : set α) : s ∩ (s ∪ t) = s := \nby {rw [inter_comm, union_inter_cancel_left], }\n\nlemma inter_distrib_inter_left (s t r : set α) : (s ∩ t) ∩ r = (s ∩ r) ∩ (t ∩ r) := \nby rw [inter_assoc s r, inter_comm r, inter_assoc t, inter_self, inter_assoc] \n\nlemma union_distrib_union_left (s t r : set α) : (s ∪ t) ∪ r = (s ∪ r) ∪ (t ∪ r) := \nby rw [union_assoc s r, union_comm r, union_assoc t, union_self, union_assoc]\n\nlemma union_distrib_union_right (s t r : set α) : s ∪ (t ∪ r) = (s ∪ t) ∪ (s ∪ r) := \nby rw [union_comm s, union_distrib_union_left t r s, union_comm s, union_comm s]   \n\n@[simp] lemma inter_right_self (s t : set α) : s ∩ t ∩ t = s ∩ t :=\nby rw [inter_assoc, inter_self] \n\n@[simp] lemma union_right_self (s t : set α) : s ∪ t ∪ t = s ∪ t :=\nby rw [union_assoc, union_self] \n\nlemma subset_iff_union_eq_left : (s ⊆ t) ↔ (s ∪ t = t) := \nby rw [←compl_subset_compl, subset_iff_inter_eq_left, ←compl_union, \n            compl_inj_iff, union_comm t s]\n\nlemma subset_iff_union_eq_right : (t ⊆ s) ↔ (s ∪ t = s) := \nby rw [subset_iff_union_eq_left, union_comm]\n\nlemma subset_refl (s : set α) : s ⊆ s :=\nby rw [subset_iff_inter_eq_left, inter_self]\n\nlemma subset_ssubset_or_eq : (s ⊆ t) → (s ⊂ t) ∨ s = t :=\nλ hst, by {rw or_comm, apply eq_or_ssubset_of_subset hst}\n\nlemma subset_iff_ssubset_or_eq : (s ⊆ t) ↔ (s ⊂ t) ∨ s = t :=\n⟨λ h, subset_ssubset_or_eq h, λ h, by {cases h, from h.1, rw h}⟩\n\nlemma ssubset_iff_subset_not_supset : s ⊂ t ↔ s ⊆ t ∧ ¬(t ⊆ s) :=\niff.rfl\n\nlemma ssubset_of_subset_ne : s ⊆ t → s ≠ t → s ⊂ t := \n@lt_of_le_of_ne _ _ s t \n\nlemma ne_of_ssubset : s ⊂ t → s ≠ t := \nne_of_irrefl\n\nlemma ssubset_irrefl (s : set α) : ¬(s ⊂ s) :=\nλ h, by {rw ssubset_iff_subset_ne at h, from h.2 rfl}\n\nlemma univ_subset  (hs : univ ⊆ s) : s = univ := \nsubset.antisymm (subset_univ s) hs\n \ninstance subset_subtype_nonempty : nonempty {t : set α // t ⊆ s} := \nby {apply nonempty_subtype.mpr, from ⟨_,empty_subset _⟩,  }\n\ninstance subtype_coe : has_coe {t : set α // t ⊆ s} (set α) := coe_subtype\n\nlemma subset_empty : s ⊆ ∅ → s = ∅ := \nλ hs, subset.antisymm hs (empty_subset s)  \n\nlemma ssubset_empty (s : set α) : ¬ s ⊂ ∅ := \nλ h, by {rw ssubset_iff_subset_ne at h, from h.2 (subset_empty h.1)}\n\nlemma empty_of_subset_compl (h : s ⊆ sᶜ) : s = ∅ := \nby rwa [subset_iff_inter_eq_left, inter_compl_self, eq_comm] at h\n\nlemma disjoint_compl_subset (h : s ∩ t = ∅) : s ⊆ tᶜ := \nby rw [subset_iff_inter_eq_left, ← empty_union (s ∩ tᶜ), ←h, \n            ←inter_distrib_left, union_compl_self, inter_univ]\n\nlemma subset_compl_disjoint (h : s ⊆ tᶜ) : s ∩ t = ∅ := \nby {rw subset_iff_inter_eq_left at h, rw [←h, inter_assoc], simp}\n\nlemma disjoint_iff_subset_compl : s ∩ t = ∅ ↔ s ⊆ tᶜ := \n⟨λ h, disjoint_compl_subset h, λ h, subset_compl_disjoint h⟩   \n\nlemma disjoint_iff_inter_compl_eq_left : s ∩ t = ∅ ↔ s ∩ tᶜ = s := \nby rw [disjoint_iff_subset_compl, subset_iff_inter_eq_left]\n\nlemma disjoint_iff_inter_compl_eq_right : s ∩ t = ∅ ↔ sᶜ ∩ t = t := \nby rw [inter_comm, disjoint_iff_inter_compl_eq_left, inter_comm]\n\nlemma disjoint_iff_diff_eq_left : s ∩ t = ∅ ↔ s \\ t = s := \ndisjoint_iff_inter_compl_eq_left\n\nlemma subset_iff_diff_empty (s t : set α) : s ⊆ t ↔ s \\ t = ∅ :=\nby {rw [←compl_compl t, ←disjoint_iff_subset_compl], simp [diff_eq],}\n\nlemma subset_iff_partition (s t : set α) : s ⊆ t ↔ t = s ∪ (t \\ s) := \nbegin\n  refine ⟨λ h, _, λ h, _⟩, \n  { nth_rewrite 0 ←(subset_iff_union_eq_left.mp h),\n    rw [diff_eq, union_distrib_left], simp,},\n  rw h, simp,  \nend \n\nlemma subset_iff_disjoint_compl : s ⊆ t ↔ s ∩ tᶜ = ∅ :=\nby rw [subset_iff_diff_empty, diff_eq]\n\nlemma disjoint_of_subset_left' (hst : s ⊆ t) (htr : t ∩ r = ∅) : s ∩ r = ∅ :=\nby {rw ←disjoint_iff_inter_eq_empty at *, exact disjoint_of_subset_left hst htr}\n\nlemma disjoint_of_subset_right' (hst : s ⊆ t) (hrt : r ∩ t = ∅) : r ∩ s = ∅ :=\nby {rw ←disjoint_iff_inter_eq_empty at *, exact disjoint_of_subset_right hst hrt, }\n\nlemma disjoint_of_subsets (hss' : s ⊆ s') (htt' : t ⊆ t') (hst : s' ∩ t' = ∅) :\n  s ∩ t = ∅ :=\nby {rw ←disjoint_iff_inter_eq_empty at *, exact disjoint_of_subset hss' htt' hst, }\n\nlemma cover_compl_subset :  s ∪ t = univ → sᶜ ⊆ t := \nλ h, by rw [subset_iff_union_eq_left, ←univ_inter (sᶜ ∪ t), ←h, \n              ←union_distrib_right, inter_compl_self, empty_union]\n\nlemma compl_inj (h : sᶜ = tᶜ) : s = t := \nby rw [←compl_compl s, ←compl_compl t, h]\n\nlemma compl_compl_inter_left (s t : set α) : (sᶜ ∩ t)ᶜ = s ∪ tᶜ := \nby {nth_rewrite 0 ←(compl_compl t), rw [compl_inter, compl_compl, compl_compl] }\n\nlemma compl_compl_inter_right (s t : set α) : (s ∩ tᶜ)ᶜ = sᶜ ∪ t := \nby {nth_rewrite 0 ←(compl_compl s), rw [compl_inter, compl_compl, compl_compl] }\n\nlemma compl_compl_union_left (s t : set α) : (sᶜ ∪ t)ᶜ = s ∩ tᶜ := \nby {nth_rewrite 0 ←(compl_compl t), rw [compl_union, compl_compl, compl_compl] }\n\nlemma compl_compl_union_right (s t : set α) : (s ∪ tᶜ)ᶜ = sᶜ ∩ t := \nby {nth_rewrite 0 ←(compl_compl s), rw [compl_union, compl_compl, compl_compl] }\n\n\nlemma compl_partition (s t : set α) : (s ∩ t) ∪ (sᶜ ∩ t) = t := \nby rw [←inter_distrib_right, union_compl_self, univ_inter]\n\nlemma compl_partition_subset  (hst : s ⊆ t) : s ∪ (sᶜ ∩ t) = t := \nby {nth_rewrite 0 ←(subset_iff_inter_eq_left.mp hst), exact compl_partition s t}\n\nlemma compl_pair (h : sᶜ = t) : (s = tᶜ) := \nby rw [←h, compl_compl]\n\nlemma compl_pair_iff : (sᶜ = t) ↔ (s = tᶜ) := \n⟨λ h, compl_pair h, λ h, by {rw eq_comm at h, from (compl_pair h).symm}⟩\n\nlemma compl_diff (s t : set α) : (s \\ t)ᶜ = sᶜ ∪ t := \nby rw [diff_eq, compl_inter, compl_compl]\n\n@[simp] lemma union_union_compl_self (s t : set α) : (s ∪ t) ∪ tᶜ = univ := \nby rw [union_assoc, union_compl_self, union_univ]\n\n@[simp] lemma inter_inter_compl_self (s t : set α) : (s ∩ t) ∩ tᶜ = ∅ := \nby rw [inter_assoc, inter_compl_self, inter_empty]\n\n@[simp] lemma union_union_compl_right (s t : set α) : s ∪ (t ∪ sᶜ) = univ := \nby rw [←union_assoc, union_comm s, union_union_compl_self]\n\n@[simp] lemma inter_inter_compl_right (s t : set α) : s ∩ (t ∩ sᶜ) = ∅ := \nby rw [←inter_assoc, inter_comm s, inter_inter_compl_self]\n\nlemma inter_union_compl_self (s t : set α) : s ∩ (t ∪ tᶜ) = s :=\nby rw [union_compl_self, inter_univ]\n\nlemma subset_own_compl : s ⊆ sᶜ → s = ∅ := \n  λ h, by {rw [subset_iff_union_eq_left,union_compl_self, ←compl_empty, compl_inj_iff] at h, \n                rw ←h }\n\nlemma inter_subset_union (s t : set α) : s ∩ t ⊆ s ∪ t := \n  subset.trans (inter_subset_left s t) (subset_union_left s t)\n\nlemma subset_of_inter_mp : s ⊆ t ∩ r → s ⊆ t ∧ s ⊆ r := \n  λ h, ⟨subset.trans h (inter_subset_left _ _), subset.trans h (inter_subset_right _ _)⟩  \n\nlemma subset_of_set_and_compl : s ⊆ t → s ⊆ tᶜ → s = ∅ :=\n  λ h1 h2, by {have := subset_inter h1 h2, rw inter_compl_self at this, \n  exact subset_empty this}\n\n@[trans] lemma subset.lt_of_le_of_lt (_ : s ⊆ t) (_ : t ⊂ r) : s ⊂ r := \nlt_of_le_of_lt ‹s ≤ t› ‹t < r› \n\n@[trans] lemma subset.lt_of_lt_of_le (_ : s ⊂ t) (_ : t ⊆ r) : s ⊂ r := \nlt_of_lt_of_le ‹s < t› ‹t ≤ r›\n\nlemma ssubset_not_supset (h : s ⊂ t) : ¬(t ⊆ s) :=\nλ h', ssubset_irrefl _ (subset.lt_of_lt_of_le h h') \n\nlemma subset_not_ssupset (h: s ⊆ t) : ¬(t ⊂ s) := \nλ h', ssubset_irrefl _ (subset.lt_of_le_of_lt h h')\n\nlemma eq_of_subset_not_ssubset  : s ⊆ t → ¬(s ⊂ t) → s = t := \nλ h h', by {simp only [not_and, not_not, ssubset_iff_subset_ne] at h', exact h' h}\n\n@[trans] lemma ssubset.trans {s t r : set α} : s ⊂ t → t ⊂ r → s ⊂ r := \nλ hst htr, subset.lt_of_le_of_lt hst.1 htr\n\nlemma ssubset_inter : s ≠ t → s ∩ t ⊂ s ∨ s ∩ t ⊂ t :=\nbegin\n  intro h, \n  by_contra a, push_neg at a, simp_rw [ssubset_iff_subset_ne, not_and', not_imp_not] at a, \n  exact h (eq.trans (a.1 (inter_subset_left s t)).symm (a.2 (inter_subset_right s t)) ),\nend \n\nlemma union_union_diff (s t r : set α) : (s ∪ r) ∪ (t \\ r) = s ∪ t ∪ r :=\nby {rw [diff_eq, union_distrib_left, union_right_comm, union_assoc _ r], simp,}\n\nlemma union_diff_absorb (s t : set α) : s ∪ (t \\ s) = s ∪ t :=\nby {nth_rewrite 0 ←union_self s, rw [union_union_diff, union_right_comm, union_self]}\n\n@[simp] lemma union_union_inter_compl_self (s t r : set α) : (s ∪ r) ∪ (t ∩ rᶜ) = s ∪ t ∪ r :=\nby rw [←diff_eq, union_union_diff] \n\nlemma union_inter_diff (s t r : set α) : (s ∪ r) ∩ (t \\ r) = (s ∩ t) \\ r :=\nby {rw [diff_eq, diff_eq, inter_distrib_right], simp [←inter_assoc, inter_right_comm r t rᶜ] }\n\nlemma subset_of_subset_diff (h : s ⊆ t \\ r) : s ⊆ t :=\nλ x hx, by {have := h hx, rw mem_diff at this, exact this.1,  }\n\nlemma eq_of_union_eq_inter : s ∪ t = s ∩ t → s = t := \nbegin\n  intro h, apply subset.antisymm, \n  calc s ⊆ (s ∪ t) : subset_union_left _ _ ... = s ∩ t : h ... ⊆ t : inter_subset_right _ _,  \n  calc t ⊆ (s ∪ t) : subset_union_right _ _ ... = s ∩ t : h ... ⊆ s : inter_subset_left _ _,  \nend \n\nlemma union_of_disjoint : s ∩ t = ∅ → s ∩ r = ∅ → s ∩ (t ∪ r) = ∅ :=\n  λ ht hr, by {rw [inter_distrib_left, ht, hr], simp }\n\n@[simp] lemma diff_union (s t : set α) : (s ∩ t) ∪ (s \\ t) = s := \nby rw [diff_eq, ←inter_distrib_left, union_compl_self, inter_univ]\n\n@[simp] lemma inter_diff (s t : set α) : s ∩ (t \\ s)  = ∅ := \nby rw [diff_eq, ←inter_assoc, inter_right_comm, inter_compl_self, empty_inter]\n\n@[simp] lemma partition_inter (s t : set α) : (s ∩ t) ∩ (s \\ t) = ∅ := \nby rw [inter_assoc, inter_diff, inter_empty]\n\n@[simp] lemma inter_diffs_eq_empty (s t : set α) : (s \\ t) ∩ (t \\ s) = ∅ := \nby {simp only [diff_eq], rw [inter_assoc, ←inter_assoc tᶜ], simp}\n\nlemma pair_move {s r : set α} (t : set α) (hst : r ⊆ s) : (s \\ r) ∪ (t ∪ r) = s ∪ t := \nby {ext, simp, tauto, }\n\nlemma diff_empty_subset (s t : set α) : s \\ t = ∅ → s ⊆ t := \nλ hst, by {rw [←diff_union s t, hst, union_empty], apply inter_subset_right}\n\nlemma subset_diff_empty (s t : set α) : s ⊆ t → s \\ t = ∅ := \nλ hst, by {rw diff_eq, rw subset_iff_inter_eq_left at hst, \n           rw [←hst, inter_assoc, inter_compl_self, inter_empty]}\n\nlemma diff_empty_iff_subset (s t : set α) : s \\ t = ∅ ↔ s ⊆ t := \nby {split, apply diff_empty_subset, apply subset_diff_empty}\n\nlemma subset_diff_disjoint (s t r : set α) : s ⊆ t → s ∩ r = ∅ → s ⊆ t \\ r := \nλ hst hsr, by {rw [disjoint_iff_subset_compl, subset_iff_inter_eq_left] at hsr, \n                rw [diff_eq, subset_iff_inter_eq_left, inter_comm t, ←inter_assoc, hsr, \n                      subset_iff_inter_eq_left.mp hst], }\n\nlemma ssubset_diff_nonempty : s ⊂ t → (t \\ s).nonempty :=\nλ hst, set.nonempty_of_ssubset hst\n\nlemma union_diff_of_subset  : s ⊆ t → s ∪ (t \\ s) = t := \nλ h, by {rw [subset_iff_inter_eq_left, inter_comm] at h, have := diff_union t s, rwa h at this}\n\nlemma diff_eq_self_of_subset_diff (h : s ⊆ r \\ t) : s \\ t = s :=\nby {rw [←disjoint_iff_diff_eq_left, disjoint_iff_subset_compl], \n        refine subset.trans h _, simp [diff_eq],  }\n\n@[simp] lemma diff_inter_right_eq_empty (s t : set α) : (t \\ s) ∩ s = ∅ := \nby rw [inter_comm, inter_diff]\n\n@[simp] lemma union_diff (s t : set α) : s ∪ (t \\ s) = s ∪ t := \nby {rw [diff_eq, union_distrib_left, union_compl_self, inter_univ]}\n\n@[simp] lemma union_diff_diff (s t : set α) : (s ∪ t) \\ (t \\ s) = s := \nby rw [diff_eq, diff_eq, compl_inter,compl_compl,union_comm, \n          ←union_distrib_right, inter_compl_self, empty_union]\n\nlemma diff_self_diff (s t : set α) : s \\ (s \\ t) = s ∩ t := \nby rw [diff_eq, compl_diff, inter_distrib_left, inter_compl_self, empty_union]\n\nlemma inter_distrib_diff (s t r : set α) : s ∩ (t \\ r) = (s ∩ t) \\ (s ∩ r) := \nby {rw [diff_eq, diff_eq, compl_inter, inter_distrib_left, inter_right_comm, \n                        inter_compl_self, empty_inter, empty_union, ←inter_assoc]}\n\nlemma diff_inter_diff_right (s t r : set α) : (s \\ r) ∩ (t \\ r) = (s ∩ t) \\ r := \nby {ext, tidy,  }\n\nlemma diff_right_comm (s t r : set α) : s \\ t \\ r = s \\ r \\ t := \nby simp [diff_eq, inter_right_comm]\n\n\n\n@[simp] lemma univ_diff (s : set α) : univ \\ s = sᶜ := \n  (compl_eq_univ_diff s).symm\n\nlemma empty_ssubset_nonempty : s.nonempty → ∅ ⊂ s := \nλ h, by {rw ←set.ne_empty_iff_nonempty at h, \n          exact ssubset_of_subset_ne (empty_subset s) (ne.symm h)}\n\nlemma nonempty_iff_empty_subset: s.nonempty ↔ ∅ ⊂ s := \n⟨ λ h, empty_ssubset_nonempty h, \n  λ h, by {rw ←set.ne_empty_iff_nonempty, exact (ne_of_ssubset h).symm, }⟩\n\nlemma ssubset_compl_commpl.mpr : s ⊂ t → tᶜ ⊂ sᶜ := \nλ h, ssubset_of_subset_ne (compl_subset_compl.mpr h.1) \n      (λ h', by {rw (compl_inj h') at h, from ssubset_irrefl _ h}) \n\nlemma compl_to_ssubset : sᶜ ⊂ tᶜ → t ⊂ s := \nλ h, by {have := ssubset_compl_commpl.mpr h, repeat {rw compl_compl at this}, exact this }\n\nlemma compl_ssubset_compl_iff : sᶜ ⊂ tᶜ ↔ t ⊂ s := \nby tidy \n\nlemma ssubset_compl_comm : s ⊂ tᶜ ↔ t ⊂ sᶜ := \nby {convert compl_ssubset_compl_iff, rw compl_compl}\n\nlemma compl_ssubset_comm : sᶜ ⊂ t ↔ tᶜ ⊂ s := \nby {convert @compl_ssubset_compl_iff _ s tᶜ, rw compl_compl}\n\n--lemma ssubset_compl_iff_compl_ssubset : s ⊂ tᶜ ↔ sᶜ ⊂ t := \n--by {nth_rewrite 0 ← compl_compl s, rw compl_ssubset_compl_iff,  }\n\nlemma ssubset_univ_of_ne_univ: s ≠ univ → s ⊂ univ := \nλ h, ssubset_of_subset_ne (subset_univ _) h\n\nlemma pairwise_disjoint_inter_sUnion {S S₁ S₂: set (set α)} \n(hdj : pairwise_disjoint S) (h₁ : S₁ ⊆ S) (h₂ : S₂ ⊆ S) :\n  sUnion (S₁ ∩ S₂) = sUnion S₁ ∩ sUnion S₂ := \nbegin\n  ext, simp only [mem_inter_iff, mem_sUnion], split, \n  { rintros ⟨t,hT,hxt⟩, rw mem_inter_iff at hT, refine ⟨⟨t,hT.1,hxt⟩,⟨t,hT.2,hxt⟩⟩, },\n  rintros ⟨⟨t,h,hxt⟩,⟨t',h',hxt'⟩⟩,\n  have := (pairwise_disjoint.elim hdj \n    (mem_of_mem_of_subset h h₁) \n    ((mem_of_mem_of_subset h' h₂)) x hxt hxt'), \n  subst this, use t, tidy, \nend\n\nlemma infinite_of_finite_diff (hs : s.finite) (ht : t.infinite) :\n  (t \\ s).infinite := \nλ h, ht (by {refine (hs.union h).subset _, rw set.union_diff_self, apply set.subset_union_right, })\n\nlemma infinite_of_union (hs : s.infinite) (t : set α) : \n  (s ∪ t).infinite := \nset.infinite_mono (set.subset_union_left _ _) hs \n\nlemma finite.diff (hs : s.finite) (t : set α) : (s \\ t).finite :=  \n  set.finite.subset hs (set.diff_subset _ _)\n\nlemma finite.inter_left (hs : s.finite) (t : set α) : (s ∩ t).finite := \n  set.finite.subset hs (set.inter_subset_left _ _)\n\nlemma finite.inter_right (ht : t.finite) (s : set α ) : (s ∩ t).finite := \n  set.finite.subset ht (set.inter_subset_right _ _)\n\n\n\nlemma subset_insert_iff_subset_or_eq_insert {s t : set α} {a : α}: \n  s ⊆ insert a t ↔ (s ⊆ t) ∨ ∃ s' ⊆ t, s = insert a s' := \nbegin\n  refine ⟨λ h, _, _⟩, \n  by_cases ha : a ∈ s, \n  { refine or.inr ⟨s \\ {a}, λ x, _, _⟩, \n    {specialize @h x, tidy, tauto, }, \n    simp [set.insert_eq_of_mem ha]},\n  refine or.inl (λ x hx, _), \n  specialize h hx, \n  rw set.mem_insert_iff at h, \n  rcases h with (rfl | h), \n    exact false.elim (ha hx), \n    assumption, \n  rintros (hst | ⟨s', hs't, rfl⟩), \n  { exact subset.trans hst (set.subset_insert _ _)},\n  exact set.insert_subset_insert hs't, \nend\n\nlemma insert_inj_subset_iff {s t t' : set α} {a : α} (ht : t ⊆ s) (ht' : t' ⊆ s) (hat : a ∉ s ):\n  insert a t = insert a t' ↔ t = t' :=\nbegin\n  refine ⟨λ h, _, by {rintro rfl, refl}⟩, \n  simp_rw [ext_iff, mem_insert_iff] at h, \n  ext x, \n  specialize h x, split, \n  { intro h', \n    obtain (rfl | hx) := h.mp (or.intro_right _ h'), \n      exact false.elim (hat (mem_of_mem_of_subset h' ht)),\n    assumption, },\n  { intro h', \n    obtain (rfl | hx) := h.mpr (or.intro_right _ h'), \n      exact false.elim (hat (mem_of_mem_of_subset h' ht')),\n    assumption, },\nend\n\nlemma remove_insert (s : set α) (e : α) : \n  insert e (s \\ {e})  = insert e s := \nby rw [← union_singleton, diff_union_self, union_singleton]\n\nlemma finite.iff_of_bij_on {s : set α} {t : set β} {f : α → β} (h : bij_on f s t) : \n  s.finite ↔ t.finite := \nbegin\n  refine ⟨λ hs, _, λ ht, _⟩,\n  { convert finite.image f hs, rw h.image_eq},\n  apply finite_of_finite_image h.inj_on, rwa h.image_eq, \nend\n\n\nend basic \n\n\nsection symm_diff\n\nvariables {α : Type*}\n/-- the symmetric difference of two sets -/\ndef symm_diff (s t : set α) : set α := (s \\ t) ∪ (t \\ s)\n\nlemma symm_diff_assoc (s t r : set α) : \n  (s.symm_diff t).symm_diff r = s.symm_diff (t.symm_diff r) :=\nby {ext, simp [symm_diff], tauto}\n\n\n@[simp] lemma symm_diff_self (s : set α): s.symm_diff s = ∅ := by simp [symm_diff]\n\n@[simp] lemma symm_diff_univ (s : set α) : s.symm_diff univ = sᶜ := by simp [symm_diff]\n\n@[simp] lemma symm_diff_empty (s : set α) : s.symm_diff ∅ = s := by simp [symm_diff]\n\nlemma symm_diff_comm (s t : set α) : symm_diff s t = symm_diff t s := \nby {ext, simp [symm_diff], tauto}\n\nlemma symm_diff_alt (s t : set α) : symm_diff s t = (s ∪ t) \\ (s ∩ t) := \nby {ext, simp only [symm_diff, mem_inter_eq, mem_union_eq, not_and, mem_diff], tauto}\n\n@[simp] lemma symm_diff_self_right (s t : set α) : (s.symm_diff t).symm_diff t = s := \nby simp [symm_diff_assoc]\n\nlemma symm_diff_eq_iff {s t r: set α} : \n  s.symm_diff t = r ↔ s = t.symm_diff r := \nbegin\n  split, {rintro rfl, rw symm_diff_comm, simp, },\n  rintro rfl, simp [symm_diff_comm t], \nend\n\nlemma symm_diff_subset_union (s t : set α) : s.symm_diff t ⊆ s ∪ t := \nby {rw symm_diff_alt, apply diff_subset}\n\nlemma diff_subset_symm_diff (s t : set α) : s \\ t ⊆ s.symm_diff t := \nλ x hx, by {rw symm_diff_alt, simp at ⊢ hx, tauto}\n\nlemma symm_diff_singleton_mem_eq {s : set α} {x : α} (h : x ∈ s) : \n  s.symm_diff {x} = s \\ {x} := \nbegin\n  ext, \n  simp only [symm_diff,and_imp, mem_singleton_iff, mem_union_eq, or_iff_left_iff_imp, mem_diff], \n  rintros rfl h',\n  exact false.elim (h' h), \nend\n \nlemma symm_diff_singleton_nonmem_eq {s : set α} {x : α} (h : x ∉ s) : \n  s.symm_diff {x} = insert x s := \nbegin\n  ext y, \n  simp only [symm_diff, mem_singleton_iff, mem_union_eq, mem_insert_iff, mem_diff], \n  rcases em (y = x) with (rfl | _); tauto, \nend\n \n@[simp] lemma symm_diff_eq_self_iff {s t : set α } :\n  s.symm_diff t = s ↔ t = ∅ := \n⟨λ h, by rwa [symm_diff_comm, symm_diff_eq_iff, symm_diff_self] at h, by {rintro rfl, simp}⟩\n  \nend symm_diff\n\nend set \nsection sigma \n\nvariables {α : Type*} {β : α → Type*} \n\n/-- the set of all pairs `(x,y)` where `x ∈ s` and `y ∈ β x` -/\ndef set.sigma (s : set α) (t : Π (a : α), set (β a)) : set (sigma β) :=\n  set_of (λ x : sigma β, x.1 ∈ s ∧ x.2 ∈ t x.1)\n\ndef set.sigma_swap {α β : Type*}: (Σ (a : α), β) → (Σ (b : β), α) := \n  λ p, ⟨p.2, p.1⟩ \n\nlemma set.sigma_inter_sigma (s s' : set α) (t t' : Π (a : α), set (β a)) : \n  (s.sigma t) ∩ (s'.sigma t') = (s ∩ s').sigma (λ a, (t a) ∩ (t' a)) := \nby {ext, simp [set.sigma], tauto}\n\nlemma set.sigma_inter (s : set α) (t : Π (a : α), set (β a)) (r : set (sigma β)) : \n  (s.sigma t) ∩ r = s.sigma (λ a, (t a) ∩ { b ∈ t a | (⟨a,b⟩ : sigma β) ∈ r}) := \nby {ext, simp [set.sigma], tauto} \n\n  \nlemma set.sigma_singleton_eq  (a : α) (t : Π (a : α), set (β a)) : \n  ({a} : set α).sigma t = sigma.mk a '' t a :=\nbegin\n  ext x, \n  simp only [set.sigma, set.mem_image, set.mem_singleton_iff, set.mem_set_of_eq],\n  split, \n  { cases x, dsimp only at *,  rintro ⟨rfl, h⟩, exact ⟨_, h, rfl⟩},\n  rintro ⟨b, hb, rfl⟩, \n  exact ⟨rfl, hb⟩, \nend \n\nlemma set.sigma_finite_iff {s : set α} {t : Π a, set (β a)}:\n  (s.sigma t).finite ↔ {a ∈ s | (t a).nonempty}.finite ∧ ∀ a ∈ s, (t a).finite := \nbegin\n  refine ⟨λ hf, ⟨_, λ a ha, _⟩, λ h, _⟩, \n  { convert set.finite.image (λ (p : sigma β), p.1) hf, \n    ext p, \n    simp [set.sigma, set.nonempty_def]}, \n\n  { refine @set.finite_of_finite_image _ _ _ \n      (λ x, (⟨a, x⟩ : sigma β)) \n      _ \n      (set.finite.subset hf _), \n    { intros x hx y hy hxy, simpa using hxy},\n    simp only [set.image_subset_iff], \n    exact λ x hx, ⟨ha, hx⟩},\n  convert @set.finite.bUnion _ _ _ (λ a _, ({a} : set α).sigma t) h.1 _, \n  { ext, \n    simp only [set.nonempty_def, exists_prop, set.mem_Union, set.mem_sep_eq, \n     set.mem_singleton_iff, set.mem_set_of_eq, set.sigma], \n    refine ⟨λ h, ⟨x.1, ⟨⟨h.1, _, h.2⟩, rfl , h.2⟩⟩, λ h, _⟩,\n    obtain ⟨a, ⟨has, b, hba⟩, ⟨rfl, ha'⟩⟩ := h,  \n    exact ⟨has, ha'⟩},\n  intros a ha, \n  simp only, \n  convert set.finite.image (λ (b : β a), (⟨a,b⟩ : sigma β)) (h.2 a ha.1), \n  rw set.sigma_singleton_eq, \nend\n\n\nlemma set.sigma_to_finset {s : set α} {t : Π a, set (β a)} \n(h : (s.sigma t).finite) : \n  h.to_finset = finset.sigma (set.sigma_finite_iff.mp h).1.to_finset \n                (λ a : α, dite (a ∈ s) (λ ha, ((set.sigma_finite_iff.mp h).2 a ha).to_finset) \n                                       (λ _, finset.empty)) :=                      \nbegin\n  ext x, \n  simp only [set.mem_sep_eq, set.finite.mem_to_finset, finset.mem_sigma, set.nonempty_def], \n  split_ifs with h h', \n  { simp only [set.finite.mem_to_finset, set.sigma, set.mem_set_of_eq], cases x, tauto}, \n  rw [set.sigma, set.mem_set_of_eq],  \n  exact ⟨λ h₁, false.elim (h h₁.1), λ h₁, false.elim (finset.not_mem_empty _ h₁.2)⟩,\nend\n\nlemma set.sigma_eq_univ_sigma (s : set α) (t : Π a, set (β a) ): \n  s.sigma t = (set.univ : set α).sigma (λ a, ite (a ∈ s) (t a) ∅) :=\nbegin\n  ext x, cases x with a b,\n  simp only [set.sigma, true_and, set.mem_univ, set.mem_set_of_eq], \n  split_ifs; \n  tauto,\nend\n\n\nlemma set.sigma_univ_invert {α β : Type*} (t : α → set β) :\n  set.bij_on (set.sigma_swap) \n    ((set.univ : set α).sigma t) \n    ((set.univ : set β).sigma (λ b, {a : α | b ∈ t a}) ):= \nbegin\n  refine ⟨ λ x hx, _, λ x hx y hy hxy , _, λ x hx, _⟩, \n  { rw [set.sigma] at *, simpa using hx}, \n  { cases x, cases y, simp only [heq_iff_eq, set.sigma_swap] at ⊢ hxy, rwa and_comm,}, \n  simp only [set.mem_image, sigma.exists], \n  rw [set.sigma] at hx ⊢, \n  simp only [true_and, set.mem_univ, set.mem_set_of_eq] at hx ⊢, \n  exact ⟨x.2, x.1, hx, by {simp only [sigma.eta, set.sigma_swap], }⟩, \nend\n\nlemma set.sigma_invert {α β : Type*} (s : set α) (t : α → set β) :\n  set.bij_on (set.sigma_swap) \n    (s.sigma t)\n    ((set.univ : set β).sigma (λ b, {a ∈ s | b ∈ t a}) ) := \nbegin\n  rw set.sigma_eq_univ_sigma, \n  convert set.sigma_univ_invert _ using 1,\n  ext x, repeat {rw set.sigma}, \n  cases x, \n  simp only [true_and, set.mem_sep_eq, set.mem_univ, set.mem_set_of_eq],  \n  split_ifs; \n  tauto, \nend\n\nend sigma \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/set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7850745272693911}}
{"text": "import ..lectures.love01_definitions_and_statements_demo\n\n/-! # LoVe Homework 5: Inductive Predicates\n\nHomework must be done individually. \n\nThis homework combines material from Ch. 5 and part of Ch. 8 of the Hitchhiker's Guide. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1 (3 points): A Type of λ-Terms\n\nIn the Ch 4 lab, we defined the type of untyped lambda terms: -/\n\ninductive term : Type\n| var : string → term\n| lam : string → term → term\n| app : term → term → term\n\n/-!\nFor instance, this expression represents the term `λ x, λ f, f x`:\n-/\n\n#check term.lam \"x\" (term.lam \"f\" (term.app (term.var \"f\") (term.var \"x\")))\n\n/-! 1.1 (1 point). Define an inductive predicate `is_app` that is `true` if\nits argument is of the form `term.app …` and that is false otherwise. -/\n\n-- enter your definition here\n\n/-! 1.2 (2 points). Define an inductive predicate `is_abs_free` that is true if\nand only if its argument is a λ-term that contains no λ-expressions.\n(\"abs\" stands for \"abstraction\" here.) -/\n\n-- enter your definition here\n\n/-! ## Question 2 (4 points): Even and Odd\n\nConsider the following inductive definition of even numbers: -/\n\ninductive even : ℕ → Prop\n| zero            : even 0\n| add_two {n : ℕ} : even n → even (n + 2)\n\n/-! 2.1 (1 point). Define a similar predicate for odd numbers, by completing the\nLean definition below. The definition should distinguish two cases, like `even`,\nand should not rely on `even`. -/\n\ninductive odd : ℕ → Prop\n-- supply the missing cases here\n\n/-! 2.2 (1 point). Give proof terms for the following propositions, based on\nyour answer to question 2.1. -/\n\nlemma odd_3 :\n  odd 3 :=\nsorry\n\nlemma odd_5 :\n  odd 5 :=\nsorry\n\n\n/-! 2.3 (1 point). Prove the following lemma in Lean: -/\n\nlemma even_odd {n : ℕ} (heven : even n) :\n  odd (n + 1) :=\nsorry\n\n/-! 2.4 (1 point). Prove the following lemma in Lean.\n\nHint: Recall that `¬ a` is defined as `a → false`. -/\n\nlemma even_not_odd {n : ℕ} (heven : even n) :\n  ¬ odd n :=\nsorry\n\n\nnamespace nodup_lists\n\n/-! ## Question 3 (4 points): Duplicate-Free Sublists\n\nIn this problem, we'll use inductive predicates to prove that the sublist of a\nlist that contains no duplicates also contains no duplicates. (Informally, a\n*sublist* of a list `ys` is a list `xs` such that every element of `xs` appears\nin the same order in `ys`.)\n\nThe predicate `list.sublist : ∀ {α : Type}, list α → list α → Prop`, which\nformally specifies the notion of a sublist, is defined as follows:\n\n  inductive sublist : list α → list α → Prop\n  | slnil : sublist [] []\n  | cons (l₁ l₂ a) : sublist l₁ l₂ → sublist l₁ (a::l₂)\n  | cons2 (l₁ l₂ a) : sublist l₁ l₂ → sublist (a::l₁) (a::l₂)\n\nThere is also syntactic sugar for the sublist predicate: we can write `xs <+ ys`\ninstead of `list.sublist xs ys`.\n\nHere are some examples:\n* `[] <+ [1, 2, 3]`\n* `[2, 3] <+ [2, 3, 4]`\n* `[2, 3] <+ [1, 2, 4, 3]`\n\nAnd here are some non-examples:\n* `¬([1] <+ [2, 3])`\n* `¬([2, 2] <+ [2, 3])`\n* `¬([2, 2, 3, 3] <+ [2, 3, 2, 3])`\n\nWe'll also need a couple of additional predicates in order to state the desired\ntheorem.\n\n3.1 (1 point). Define a predicate `is_in` such that `is_in x xs` holds precisely\nwhen `x` is an element of the list `xs`.\n\nNote: you may not use the equality operator `=` in your solution. -/\n\n-- Fill this in:\ninductive is_in {α : Type} : α → list α → Prop\n-- ...\n\n\n\n-- For the rest of this problem, we'll redefine the `∈` notation to use your\n-- `is_in` predicate instead of the default.\nlocal notation (name := list_in_predicate) x ` ∈ ` xs := is_in x xs\n\n/-! 3.2 (1 point). Define a predicate `no_duplicates` such that\n`no_duplicates xs` holds precisely when the list `xs` does not contain any\nduplicate elements.\n\nHere are some examples:\n* `no_duplicates []`\n* `no_duplicates [tt]`\n* `no_duplicates [2, 1, 3]`\n\nAnd here are some non-examples:\n* `¬(no_duplicates [tt, tt])`\n* `¬(no_duplicates [1, 9, 5, 1])`\n* `¬(no_duplicates [3, 1, 4, 1, 5])`\n\nNote: you may not use the equality operator `=` in your solution.\n\nHint: you may find the `is_in` (`∈`) predicate you defined above useful! -/\n\n-- Fill this in:\ninductive no_duplicates {α : Type} : list α → Prop\n-- ...\n\n\n\n\n/-! 3.3 (2 points). Equipped with these definitions, prove the theorem we stated\nat the beginning: the sublist of a duplicate-free list is also duplicate-free.\n\nHint: choose what to induct on wisely! -/\n\n-- You may find this helper lemma useful when writing your proof.\naxiom not_in_of_not_in_sublist {α : Type} {x : α} {xs ys : list α} :\n  xs <+ ys → ¬(x ∈ ys) → ¬(x ∈ xs)\n\n\ntheorem no_dups_sublist_of_no_dups {α : Type} (xs ys : list α) :\n  no_duplicates ys → xs <+ ys → no_duplicates xs :=\nsorry\n\n\nend nodup_lists\n\n\n\n\n/-! ## Question 4 (2 points): 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 → (state → ℕ) → stmt\n| seq    : stmt → stmt → stmt\n| unless : (state → Prop) → stmt → stmt\n| repeat : ℕ → stmt → 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—i.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\n4.1 (2 points). Complete the following definition of a big-step\nsemantics: -/\n\ninductive big_step : stmt × state → state → Prop\n| skip {s} :\n  big_step (stmt.skip, s) s\n-- enter the missing cases 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/love05_inductive_predicates_and_big_step_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8757869965109765, "lm_q1q2_score": 0.784925305476381}}
{"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.modeq\nimport algebra.parity\n\n/-!\n# Parity of natural numbers\n\nThis file contains theorems about the `even` and `odd` predicates on the natural numbers.\n\n## Tags\n\neven, odd\n-/\n\nnamespace nat\n\nvariables {m n : ℕ}\n\n@[simp] theorem mod_two_ne_one : ¬ n % 2 = 1 ↔ n % 2 = 0 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\n@[simp] theorem mod_two_ne_zero : ¬ n % 2 = 0 ↔ n % 2 = 1 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\ntheorem even_iff : even n ↔ n % 2 = 0 :=\n⟨λ ⟨m, hm⟩, by simp [← two_mul, hm],\n  λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by simp [← two_mul, h])⟩⟩\n\ntheorem odd_iff : odd n ↔ n % 2 = 1 :=\n⟨λ ⟨m, hm⟩, by norm_num [hm, add_mod],\n λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by rw [h, add_comm])⟩⟩\n\nlemma not_even_iff : ¬ even n ↔ n % 2 = 1 :=\nby rw [even_iff, mod_two_ne_zero]\n\nlemma not_odd_iff : ¬ odd n ↔ n % 2 = 0 :=\nby rw [odd_iff, mod_two_ne_one]\n\nlemma even_iff_not_odd : even n ↔ ¬ odd n :=\nby rw [not_odd_iff, even_iff]\n\n@[simp] lemma odd_iff_not_even : odd n ↔ ¬ even n :=\nby rw [not_even_iff, odd_iff]\n\nlemma is_compl_even_odd : is_compl {n : ℕ | even n} {n | odd n} :=\nby simp only [←set.compl_set_of, is_compl_compl, odd_iff_not_even]\n\nlemma even_or_odd (n : ℕ) : even n ∨ odd n :=\nor.imp_right odd_iff_not_even.2 $ em $ even n\n\nlemma even_or_odd' (n : ℕ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 :=\nby simpa only [← two_mul, exists_or_distrib, ← odd, ← even] using even_or_odd n\n\nlemma even_xor_odd (n : ℕ) : xor (even n) (odd n) :=\nbegin\n  cases even_or_odd n with h,\n  { exact or.inl ⟨h, even_iff_not_odd.mp h⟩ },\n  { exact or.inr ⟨h, odd_iff_not_even.mp h⟩ },\nend\n\nlemma even_xor_odd' (n : ℕ) : ∃ k, xor (n = 2 * k) (n = 2 * k + 1) :=\nbegin\n  rcases even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩;\n  use k,\n  { simpa only [← 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\nlemma odd_gt_zero (h : odd n) : 0 < n :=\nby { obtain ⟨k, rfl⟩ := h, exact succ_pos' }\n\n@[simp] theorem two_dvd_ne_zero : ¬ 2 ∣ n ↔ n % 2 = 1 :=\neven_iff_two_dvd.symm.not.trans not_even_iff\n\ninstance : decidable_pred (even : ℕ → Prop) :=\nλ n, decidable_of_decidable_of_iff (by apply_instance) even_iff.symm\n\ninstance decidable_pred_odd : decidable_pred (odd : ℕ → Prop) :=\nλ n, decidable_of_decidable_of_iff (by apply_instance) odd_iff_not_even.symm\n\nmk_simp_attribute parity_simps \"Simp attribute for lemmas about `even`\"\n\n@[simp] theorem not_even_one : ¬ even 1 :=\nby rw even_iff; norm_num\n\n@[parity_simps] theorem even_add : even (m + n) ↔ (even m ↔ even n) :=\nby cases mod_two_eq_zero_or_one m with h₁ h₁;\n   cases mod_two_eq_zero_or_one n with h₂ h₂;\n   simp [even_iff, h₁, h₂, nat.add_mod];\n   norm_num\n\ntheorem even_add' : even (m + n) ↔ (odd m ↔ 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 : ℕ) : ¬ even (bit1 n) :=\nby simp [bit1] with parity_simps\n\nlemma two_not_dvd_two_mul_add_one (n : ℕ) : ¬(2 ∣ 2 * n + 1) :=\nby simp [add_mod]\n\nlemma two_not_dvd_two_mul_sub_one : Π {n} (w : 0 < n), ¬(2 ∣ 2 * n - 1)\n| (n + 1) _ := two_not_dvd_two_mul_add_one n\n\n@[parity_simps] theorem even_sub (h : n ≤ m) : even (m - n) ↔ (even m ↔ even n) :=\nbegin\n  conv { to_rhs, rw [←tsub_add_cancel_of_le h, even_add] },\n  by_cases h : even n; simp [h]\nend\n\ntheorem even.sub_even (hm : even m) (hn : even n) : even (m - n) :=\n(le_total n m).elim\n  (λ h, by simp only [even_sub h, *])\n  (λ h, by simp only [tsub_eq_zero_iff_le.mpr h, even_zero])\n\ntheorem even_sub' (h : n ≤ m) : even (m - n) ↔ (odd m ↔ odd n) :=\nby rw [even_sub h, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\ntheorem odd.sub_odd (hm : odd m) (hn : odd n) : even (m - n) :=\n(le_total n m).elim\n  (λ h, by simp only [even_sub' h, *])\n  (λ h, by simp only [tsub_eq_zero_iff_le.mpr h, even_zero])\n\n@[parity_simps] theorem even_succ : even (succ n) ↔ ¬ even n :=\nby rw [succ_eq_add_one, even_add]; simp [not_even_one]\n\n@[parity_simps] theorem even_mul : even (m * n) ↔ even m ∨ even n :=\nby cases mod_two_eq_zero_or_one m with h₁ h₁;\n   cases mod_two_eq_zero_or_one n with h₂ h₂;\n   simp [even_iff, h₁, h₂, nat.mul_mod];\n   norm_num\n\ntheorem odd_mul : odd (m * n) ↔ odd m ∧ 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/-- If `m` and `n` are natural numbers, then the natural number `m^n` is even\nif and only if `m` is even and `n` is positive. -/\n@[parity_simps] theorem even_pow : even (m ^ n) ↔ even m ∧ n ≠ 0 :=\nby { induction n with n ih; simp [*, pow_succ', even_mul], tauto }\n\ntheorem even_pow' (h : n ≠ 0) : even (m ^ n) ↔ even m :=\neven_pow.trans $ and_iff_left h\n\ntheorem even_div : even (m / n) ↔ m % (2 * n) / n = 0 :=\nby rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, nat.div_mod_eq_mod_mul_div, mul_comm]\n\n@[parity_simps] theorem odd_add : odd (m + n) ↔ (odd m ↔ even n) :=\nby rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even]\n\ntheorem odd_add' : odd (m + n) ↔ (odd n ↔ even m) :=\nby rw [add_comm, odd_add]\n\nlemma ne_of_odd_add (h : odd (m + n)) : m ≠ n :=\nλ hnot, by simpa [hnot] with parity_simps using h\n\n@[parity_simps] theorem odd_sub (h : n ≤ m) : odd (m - n) ↔ (odd m ↔ even n) :=\nby rw [odd_iff_not_even, even_sub h, not_iff, odd_iff_not_even]\n\ntheorem odd.sub_even (h : n ≤ m) (hm : odd m) (hn : even n) : odd (m - n) :=\n(odd_sub h).mpr $ iff_of_true hm hn\n\ntheorem odd_sub' (h : n ≤ m) : odd (m - n) ↔ (odd n ↔ even m) :=\nby rw [odd_iff_not_even, even_sub h, not_iff, not_iff_comm, odd_iff_not_even]\n\ntheorem even.sub_odd (h : n ≤ m) (hm : even m) (hn : odd n) : odd (m - n) :=\n(odd_sub' h).mpr $ iff_of_true hn hm\n\nlemma even_mul_succ_self (n : ℕ) : even (n * (n + 1)) :=\nbegin\n  rw even_mul,\n  convert n.even_or_odd,\n  simp with parity_simps\nend\n\nlemma even_mul_self_pred (n : ℕ) : even (n * (n - 1)) :=\nbegin\n  cases n,\n  { exact even_zero },\n  { rw mul_comm,\n    apply even_mul_succ_self }\nend\n\nlemma even_sub_one_of_prime_ne_two {p : ℕ} (hp : prime p) (hodd : p ≠ 2) : even (p - 1) :=\nodd.sub_odd (odd_iff.2 $ hp.eq_two_or_odd.resolve_left hodd) (odd_iff.2 rfl)\n\nvariables {R : Type*} [ring R]\n\ntheorem neg_one_pow_eq_one_iff_even (h1 : (-1 : R) ≠ 1) : (-1 : R) ^ n = 1 ↔ even n :=\nbegin\n  rcases n.even_or_odd' with ⟨n, rfl | rfl⟩,\n  { simp [neg_one_pow_eq_pow_mod_two, pow_zero] },\n  { rw [← not_iff_not, neg_one_pow_eq_pow_mod_two, not_even_iff, add_mod],\n    simp only [h1, mul_mod_right, one_mod, pow_one, not_false_iff, eq_self_iff_true] }\nend\n\n@[simp] theorem neg_one_sq : (-1 : R) ^ 2 = 1 := by simp\n\nalias nat.neg_one_sq ← nat.neg_one_pow_two\n\ntheorem neg_one_pow_of_even : even n → (-1 : R) ^ n = 1 :=\nby { rintro ⟨c, rfl⟩, simp [← two_mul, pow_mul] }\n\ntheorem neg_one_pow_of_odd : odd n → (-1 : R) ^ n = -1 :=\nby { rintro ⟨c, rfl⟩, simp [pow_add, pow_mul] }\n\nlemma two_mul_div_two_of_even : even n → 2 * (n / 2) = n :=\n λ h, nat.mul_div_cancel_left' (even_iff_two_dvd.mp h)\n\nlemma div_two_mul_two_of_even : even n → n / 2 * 2 = n := --nat.div_mul_cancel\nλ h, nat.div_mul_cancel (even_iff_two_dvd.mp h)\n\nlemma two_mul_div_two_add_one_of_odd (h : odd n) : 2 * (n / 2) + 1 = n :=\nby { rw mul_comm, convert nat.div_add_mod' n 2, rw odd_iff.mp h }\n\nlemma div_two_mul_two_add_one_of_odd (h : odd n) : n / 2 * 2 + 1 = n :=\nby { convert nat.div_add_mod' n 2, rw odd_iff.mp h }\n\nlemma one_add_div_two_mul_two_of_odd (h : odd n) : 1 + n / 2 * 2 = n :=\nby { rw add_comm, convert nat.div_add_mod' n 2, rw odd_iff.mp h }\n\n-- Here are examples of how `parity_simps` can be used with `nat`.\n\nexample (m n : ℕ) (h : even m) : ¬ even (n + 3) ↔ even (m^2 + m + n) :=\nby simp [*, (dec_trivial : ¬ 2 = 0)] with parity_simps\n\nexample : ¬ even 25394535 :=\nby simp\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.7849252967426993}}
{"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.basic\n\n/-!\n# Definitions and properties of `gcd`, `lcm`, and `coprime`\n\n-/\n\nnamespace nat\n\n/-! ### `gcd` -/\n\ntheorem gcd_dvd (m n : ℕ) : (gcd m n ∣ m) ∧ (gcd m n ∣ n) :=\ngcd.induction m n\n  (λn, by rw gcd_zero_left; exact ⟨dvd_zero n, dvd_refl n⟩)\n  (λm n npos, by rw ←gcd_rec; exact λ ⟨IH₁, IH₂⟩, ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩)\n\ntheorem gcd_dvd_left (m n : ℕ) : gcd m n ∣ m := (gcd_dvd m n).left\n\ntheorem gcd_dvd_right (m n : ℕ) : gcd m n ∣ n := (gcd_dvd m n).right\n\ntheorem gcd_le_left {m} (n) (h : 0 < m) : gcd m n ≤ m := le_of_dvd h $ gcd_dvd_left m n\n\ntheorem gcd_le_right (m) {n} (h : 0 < n) : gcd m n ≤ n := le_of_dvd h $ gcd_dvd_right m n\n\ntheorem dvd_gcd {m n k : ℕ} : k ∣ m → k ∣ n → k ∣ gcd m n :=\ngcd.induction m n (λn _ kn, by rw gcd_zero_left; exact kn)\n  (λn 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 : ℕ} : k ∣ gcd m n ↔ k ∣ m ∧ k ∣ n :=\niff.intro (λ h, ⟨dvd_trans h (gcd_dvd m n).left, dvd_trans h (gcd_dvd m n).right⟩)\n          (λ h, dvd_gcd h.left h.right)\n\ntheorem gcd_comm (m n : ℕ) : 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 : ℕ} : m ∣ n ↔ gcd m n = m :=\n⟨λ h, by rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left],\n λ h, h ▸ gcd_dvd_right m n⟩\n\ntheorem gcd_eq_right_iff_dvd {m n : ℕ} : m ∣ n ↔ gcd n m = m :=\nby rw gcd_comm; apply gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m n k : ℕ) : gcd (gcd m n) k = gcd m (gcd n k) :=\ndvd_antisymm\n  (dvd_gcd\n    (dvd.trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_left m n))\n    (dvd_gcd (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)) (dvd.trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_left n k)))\n    (dvd.trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_right n k)))\n\n@[simp] theorem gcd_one_right (n : ℕ) : gcd n 1 = 1 :=\neq.trans (gcd_comm n 1) $ gcd_one_left n\n\ntheorem gcd_mul_left (m n k : ℕ) : gcd (m * n) (m * k) = m * gcd n k :=\ngcd.induction n k\n  (λk, by repeat {rw mul_zero <|> rw gcd_zero_left})\n  (λk n H IH, by rwa [←mul_mod_mul_left, ←gcd_rec, ←gcd_rec] at IH)\n\ntheorem gcd_mul_right (m n k : ℕ) : 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 : ℕ} (n : ℕ) (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 : ℕ) {n : ℕ} (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 : ℕ} (H : gcd m n = 0) : m = 0 :=\nor.elim (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 : ℕ} (H : gcd m n = 0) : n = 0 :=\nby rw gcd_comm at H; exact eq_zero_of_gcd_eq_zero_left H\n\ntheorem gcd_div {m n k : ℕ} (H1 : k ∣ m) (H2 : k ∣ n) :\n  gcd (m / k) (n / k) = gcd m n / k :=\nor.elim (eq_zero_or_pos k)\n  (λk0, by rw [k0, nat.div_zero, nat.div_zero, nat.div_zero, gcd_zero_right])\n  (λH3, nat.eq_of_mul_eq_mul_right H3 $ by rw [\n    nat.div_mul_cancel (dvd_gcd H1 H2), ←gcd_mul_right,\n    nat.div_mul_cancel H1, nat.div_mul_cancel H2])\n\ntheorem gcd_dvd_gcd_of_dvd_left {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd m n ∣ gcd k n :=\ndvd_gcd (dvd.trans (gcd_dvd_left m n) H) (gcd_dvd_right m n)\n\ntheorem gcd_dvd_gcd_of_dvd_right {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd n m ∣ gcd n k :=\ndvd_gcd (gcd_dvd_left n m) (dvd.trans (gcd_dvd_right n m) H)\n\ntheorem gcd_dvd_gcd_mul_left (m n k : ℕ) : gcd m n ∣ gcd (k * m) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (m n k : ℕ) : gcd m n ∣ gcd (m * k) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (m n k : ℕ) : gcd m n ∣ gcd m (k * n) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (m n k : ℕ) : gcd m n ∣ gcd m (n * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {m n : ℕ} (H : m ∣ n) : gcd m n = m :=\ndvd_antisymm (gcd_dvd_left _ _) (dvd_gcd (dvd_refl _) H)\n\ntheorem gcd_eq_right {m n : ℕ} (H : n ∣ m) : gcd m n = n :=\nby rw [gcd_comm, gcd_eq_left H]\n\n@[simp] lemma gcd_mul_left_left (m n : ℕ) : gcd (m * n) n = n :=\ndvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (dvd_mul_left _ _) (dvd_refl _))\n\n@[simp] lemma gcd_mul_left_right (m n : ℕ) : gcd n (m * n) = n :=\nby rw [gcd_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_left (m n : ℕ) : gcd (n * m) n = n :=\nby rw [mul_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_right (m n : ℕ) : gcd n (n * m) = n :=\nby rw [gcd_comm, gcd_mul_right_left]\n\n@[simp] lemma gcd_gcd_self_right_left (m n : ℕ) : gcd m (gcd m n) = gcd m n :=\ndvd_antisymm (gcd_dvd_right _ _) (dvd_gcd (gcd_dvd_left _ _) (dvd_refl _))\n\n@[simp] lemma gcd_gcd_self_right_right (m n : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ} : gcd i j = 0 ↔ i = 0 ∧ j = 0 :=\nbegin\n  split,\n  { intro h,\n    exact ⟨eq_zero_of_gcd_eq_zero_left h, eq_zero_of_gcd_eq_zero_right h⟩, },\n  { intro h,\n    rw [h.1, h.2],\n    exact nat.gcd_zero_right _ }\nend\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m n : ℕ) : lcm m n = lcm n m :=\nby delta lcm; rw [mul_comm, gcd_comm]\n\n@[simp]\ntheorem lcm_zero_left (m : ℕ) : lcm 0 m = 0 :=\nby delta lcm; rw [zero_mul, nat.zero_div]\n\n@[simp]\ntheorem lcm_zero_right (m : ℕ) : lcm m 0 = 0 := lcm_comm 0 m ▸ lcm_zero_left m\n\n@[simp]\ntheorem lcm_one_left (m : ℕ) : lcm 1 m = m :=\nby delta lcm; rw [one_mul, gcd_one_left, nat.div_one]\n\n@[simp]\ntheorem lcm_one_right (m : ℕ) : lcm m 1 = m := lcm_comm 1 m ▸ lcm_one_left m\n\n@[simp]\ntheorem lcm_self (m : ℕ) : lcm m m = m :=\nor.elim (eq_zero_or_pos m)\n  (λh, by rw [h, lcm_zero_left])\n  (λh, by delta lcm; rw [gcd_self, nat.mul_div_cancel _ h])\n\ntheorem dvd_lcm_left (m n : ℕ) : m ∣ 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 : ℕ) : n ∣ lcm m n :=\nlcm_comm n m ▸ dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m n : ℕ) : gcd m n * lcm m n = m * n :=\nby delta lcm; rw [nat.mul_div_cancel' (dvd.trans (gcd_dvd_left m n) (dvd_mul_right m n))]\n\ntheorem lcm_dvd {m n k : ℕ} (H1 : m ∣ k) (H2 : n ∣ k) : lcm m n ∣ k :=\nor.elim (eq_zero_or_pos k)\n  (λh, by rw h; exact dvd_zero _)\n  (λkpos, 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, ←gcd_mul_right, mul_comm n k];\n       exact dvd_gcd (mul_dvd_mul_left _ H2) (mul_dvd_mul_right H1 _))\n\ntheorem lcm_assoc (m n k : ℕ) : 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.trans (dvd_lcm_left n k) (dvd_lcm_right m (lcm n k))))\n    (dvd.trans (dvd_lcm_right n k) (dvd_lcm_right m (lcm n k))))\n  (lcm_dvd\n    (dvd.trans (dvd_lcm_left m n) (dvd_lcm_left (lcm m n) k))\n    (lcm_dvd (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 : ℕ} (hm : m ≠ 0) (hn : n ≠ 0) : lcm m n ≠ 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 : ℕ) : decidable (coprime m n) := by unfold coprime; apply_instance\n\ntheorem coprime_iff_gcd_eq_one {m n : ℕ} : coprime m n ↔ gcd m n = 1 := iff.rfl\n\ntheorem coprime.gcd_eq_one {m n : ℕ} : coprime m n → gcd m n = 1 := id\n\ntheorem coprime.symm {m n : ℕ} : coprime n m → coprime m n := (gcd_comm m n).trans\n\ntheorem coprime_comm {m n : ℕ} : coprime n m ↔ coprime m n := ⟨coprime.symm, coprime.symm⟩\n\ntheorem coprime.dvd_of_dvd_mul_right {m n k : ℕ} (H1 : coprime k n) (H2 : k ∣ m * n) : k ∣ 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\ntheorem coprime.dvd_of_dvd_mul_left {m n k : ℕ} (H1 : coprime k m) (H2 : k ∣ m * n) : k ∣ n :=\nby rw mul_comm at H2; exact H1.dvd_of_dvd_mul_right H2\n\ntheorem coprime.gcd_mul_left_cancel {k : ℕ} (m : ℕ) {n : ℕ} (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 : ℕ) {k n : ℕ} (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 : ℕ} (n : ℕ) (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 : ℕ} (n : ℕ) (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 : ℕ} (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 : ℕ} (dgt1 : 1 < d) (Hm : d ∣ m) (Hn : d ∣ n) :\n  ¬ coprime m n :=\nλ co, not_lt_of_ge (le_of_dvd zero_lt_one $ by rw [←co.gcd_eq_one]; exact dvd_gcd Hm Hn) dgt1\n\ntheorem exists_coprime {m n : ℕ} (H : 0 < gcd m n) :\n  ∃ m' n', coprime m' n' ∧ m = m' * gcd m n ∧ n = n' * gcd m n :=\n⟨_, _, 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⟩\n\ntheorem exists_coprime' {m n : ℕ} (H : 0 < gcd m n) :\n  ∃ g m' n', 0 < g ∧ coprime m' n' ∧ m = m' * g ∧ n = n' * g :=\nlet ⟨m', n', h⟩ := exists_coprime H in ⟨_, m', n', H, h⟩\n\ntheorem coprime.mul {m n k : ℕ} (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 : ℕ} (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 : ℕ} (H1 : m ∣ k) (H2 : coprime k n) : coprime m n :=\neq_one_of_dvd_one (by delta coprime at H2; rw ← H2; exact gcd_dvd_gcd_of_dvd_left _ H1)\n\ntheorem coprime.coprime_dvd_right {m k n : ℕ} (H1 : n ∣ 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 : ℕ} (H : coprime (k * m) n) : coprime m n :=\nH.coprime_dvd_left (dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right {k m n : ℕ} (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 : ℕ} (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 : ℕ} (H : coprime m (n * k)) : coprime m n :=\nH.coprime_dvd_right (dvd_mul_right _ _)\n\ntheorem coprime.coprime_div_left {m n a : ℕ} (cmn : coprime m n) (dvd : a ∣ 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 ⟨k, rfl⟩,\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 : ℕ} (cmn : coprime m n) (dvd : a ∣ n) :\n  coprime m (n / a) :=\n(coprime.coprime_div_left cmn.symm dvd).symm\n\nlemma coprime_mul_iff_left {k m n : ℕ} : coprime (m * n) k ↔ coprime m k ∧ coprime n k :=\n⟨λ h, ⟨coprime.coprime_mul_right h, coprime.coprime_mul_left h⟩,\n  λ ⟨h, _⟩, by rwa [coprime_iff_gcd_eq_one, coprime.gcd_mul_left_cancel n h]⟩\n\nlemma coprime_mul_iff_right {k m n : ℕ} : coprime k (m * n) ↔ coprime k m ∧ coprime k n :=\nby simpa only [coprime_comm] using coprime_mul_iff_left\n\nlemma coprime.gcd_left (k : ℕ) {m n : ℕ} (hmn : coprime m n) : coprime (gcd k m) n :=\nhmn.coprime_dvd_left $ gcd_dvd_right k m\n\nlemma coprime.gcd_right (k : ℕ) {m n : ℕ} (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 : ℕ) {m n : ℕ} (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 : ℕ} (hmn : coprime m n)\n  (hm : m ∣ a) (hn : n ∣ a) : m * n ∣ a :=\nlet ⟨k, hk⟩ := hm in hk.symm ▸ mul_dvd_mul_left _ (hmn.symm.dvd_of_dvd_mul_left (hk ▸ hn))\n\ntheorem coprime_one_left : ∀ n, coprime 1 n := gcd_one_left\n\ntheorem coprime_one_right : ∀ n, coprime n 1 := gcd_one_right\n\ntheorem coprime.pow_left {m k : ℕ} (n : ℕ) (H1 : coprime m k) : coprime (m ^ n) k :=\nnat.rec_on n (coprime_one_left _) (λn IH, H1.mul IH)\n\ntheorem coprime.pow_right {m k : ℕ} (n : ℕ) (H1 : coprime k m) : coprime k (m ^ n) :=\n(H1.symm.pow_left n).symm\n\ntheorem coprime.pow {k l : ℕ} (m n : ℕ) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n(H1.pow_left _).pow_right _\n\ntheorem coprime.eq_one_of_dvd {k m : ℕ} (H : coprime k m) (d : k ∣ m) : k = 1 :=\nby rw [← H.gcd_eq_one, gcd_eq_left d]\n\n@[simp] theorem coprime_zero_left (n : ℕ) : coprime 0 n ↔ n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_zero_right (n : ℕ) : coprime n 0 ↔ n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_left_iff (n : ℕ) : coprime 1 n ↔ true :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_right_iff (n : ℕ) : coprime n 1 ↔ true :=\nby simp [coprime]\n\n@[simp] theorem coprime_self (n : ℕ) : coprime n n ↔ 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 : ℕ} (H : k ∣ m * n) :\n  { d : {m' // m' ∣ m} × {n' // n' ∣ n} // k = d.1 * d.2 } :=\nbegin\ncases h0 : (gcd k m),\ncase nat.zero {\n  have : k = 0 := eq_zero_of_gcd_eq_zero_left h0, subst this,\n  have : m = 0 := eq_zero_of_gcd_eq_zero_right h0, subst this,\n  exact ⟨⟨⟨0, dvd_refl 0⟩, ⟨n, dvd_refl n⟩⟩, (zero_mul n).symm⟩ },\ncase nat.succ : tmp {\n  have hpos : 0 < gcd k m := h0.symm ▸ 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 ⟨⟨⟨gcd k m,  gcd_dvd_right k m⟩, ⟨k / gcd k m, _⟩⟩, hd.symm⟩,\n  apply dvd_of_mul_dvd_mul_left hpos,\n  rw [hd, ← gcd_mul_right],\n  exact dvd_gcd (dvd_mul_right _ _) H }\nend\n\ntheorem gcd_mul_dvd_mul_gcd (k m n : ℕ) : gcd k (m * n) ∣ gcd k m * gcd k n :=\nbegin\nrcases (prod_dvd_and_dvd_of_dvd_prod $ gcd_dvd_right k (m * n)) with ⟨⟨⟨m', hm'⟩, ⟨n', hn'⟩⟩, h⟩,\nreplace h : gcd k (m * n) = m' * n' := h,\nrw h,\nhave hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _,\napply mul_dvd_mul,\n  { have hm'k : m' ∣ k := dvd_trans (dvd_mul_right m' n') hm'n',\n    exact dvd_gcd hm'k hm' },\n  { have hn'k : n' ∣ k := dvd_trans (dvd_mul_left n' m') hm'n',\n    exact dvd_gcd hn'k hn' }\nend\n\ntheorem coprime.gcd_mul (k : ℕ) {m n : ℕ} (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 : ℕ} (n0 : 0 < n) : a ^ n ∣ b ^ n ↔ a ∣ b :=\nbegin\n  refine ⟨λ h, _, λ h, pow_dvd_pow_of_dvd h _⟩,\n  cases 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 ⟨g, a', b', g0', co, rfl, rfl⟩,\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 : ℕ} (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 ← 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\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/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7847728610623401}}
{"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, Mario Carneiro\n\n\n! This file was ported from Lean 3 source module init.data.nat.gcd\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.Nat.Lemmas\nimport Leanbin.Init.Meta.WellFoundedTactics\n\n/-!\n# Definitions and properties of gcd, lcm, and coprime\n-/\n\n\nopen WellFounded\n\nnamespace Nat\n\n/-! gcd -/\n\n\n#print Nat.gcd /-\ndef gcd : Nat → Nat → Nat\n  | 0, y => y\n  | succ x, y =>\n    have : y % succ x < succ x := mod_lt _ <| succ_pos _\n    gcd (y % succ x) (succ x)\n#align nat.gcd Nat.gcd\n-/\n\n#print Nat.gcd_zero_left /-\n@[simp]\ntheorem gcd_zero_left (x : Nat) : gcd 0 x = x := by simp [gcd]\n#align nat.gcd_zero_left Nat.gcd_zero_left\n-/\n\n#print Nat.gcd_succ /-\n@[simp]\ntheorem gcd_succ (x y : Nat) : gcd (succ x) y = gcd (y % succ x) (succ x) := by simp [gcd]\n#align nat.gcd_succ Nat.gcd_succ\n-/\n\n#print Nat.gcd_one_left /-\n@[simp]\ntheorem gcd_one_left (n : ℕ) : gcd 1 n = 1 := by simp [gcd]\n#align nat.gcd_one_left Nat.gcd_one_left\n-/\n\n/- warning: nat.gcd_def -> Nat.gcd_def is a dubious translation:\nlean 3 declaration is\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (Nat.gcd x y) (ite.{1} Nat (Eq.{1} Nat x (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) (Nat.decidableEq x (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) y (Nat.gcd (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) y x) x))\nbut is expected to have type\n  forall (x : Nat) (y : Nat), Eq.{1} Nat (Nat.gcd x y) (ite.{1} Nat (Eq.{1} Nat x (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) (instDecidableEqNat x (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) y (Nat.gcd (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) y x) x))\nCase conversion may be inaccurate. Consider using '#align nat.gcd_def Nat.gcd_defₓ'. -/\ntheorem gcd_def (x y : ℕ) : gcd x y = if x = 0 then y else gcd (y % x) x := by\n  cases x <;> simp [gcd, succ_ne_zero]\n#align nat.gcd_def Nat.gcd_def\n\n#print Nat.gcd_self /-\n@[simp]\ntheorem gcd_self (n : ℕ) : gcd n n = n := by cases n <;> simp [gcd, mod_self]\n#align nat.gcd_self Nat.gcd_self\n-/\n\n#print Nat.gcd_zero_right /-\n@[simp]\ntheorem gcd_zero_right (n : ℕ) : gcd n 0 = n := by cases n <;> simp [gcd]\n#align nat.gcd_zero_right Nat.gcd_zero_right\n-/\n\n#print Nat.gcd_rec /-\ntheorem gcd_rec (m n : ℕ) : gcd m n = gcd (n % m) m := by cases m <;> simp [gcd]\n#align nat.gcd_rec Nat.gcd_rec\n-/\n\n#print Nat.gcd.induction /-\n@[elab_as_elim]\ntheorem gcd.induction {P : ℕ → ℕ → Prop} (m n : ℕ) (H0 : ∀ n, P 0 n)\n    (H1 : ∀ m n, 0 < m → P (n % m) m → P m n) : P m n :=\n  @induction _ _ lt_wfRel (fun m => ∀ n, P m n) m\n    (fun k IH => by\n      induction' k with k ih\n      exact H0\n      exact fun n => H1 _ _ (succ_pos _) (IH _ (mod_lt _ (succ_pos _)) _))\n    n\n#align nat.gcd.induction Nat.gcd.induction\n-/\n\n#print Nat.lcm /-\ndef lcm (m n : ℕ) : ℕ :=\n  m * n / gcd m n\n#align nat.lcm Nat.lcm\n-/\n\n#print Nat.coprime /-\n@[reducible]\ndef coprime (m n : ℕ) : Prop :=\n  gcd m n = 1\n#align nat.coprime Nat.coprime\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/Gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900945711678, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7847728537832869}}
{"text": "import Mathlib.Data.Nat.Basic\nimport Mathlib.Data.Rat.Cast\nimport Std.Data.Rat\nimport Mathlib.Tactic.NormNum\nimport Mathlib.Tactic.FieldSimp\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.Ring\nimport Mathlib.Data.Finset.Basic\nimport Mathlib.Algebra.BigOperators.Basic\n\n\nopen Nat Rat Finset  BigOperators\n\n\n/- If we want to talk about finite sums then we need to use `finsets`\n\nIf `n : ℕ` then `range n` is the finset consisting of {0,1,..,n-1}`\nSo in particular `range n.succ = {0,1,...,n}`\n-/\n\n/-  \nDivision (and subtraction) over ℕ can be painful in Lean.  \nClearing denominators can be be very helpful. -/\n\nlemma clear_denom {n k m: ℕ} (hnz : 0 < m): m * n = k → n = k / m :=\nby\n  intro h\n  rw [←h,mul_div_right n hnz]\n\n\n\nlemma sum1 (n : ℕ) :  ∑ i in range n.succ, i  = (n * (n+1))/2:=by\n  apply clear_denom (by norm_num :0 < 2)\n  induction' n with n hn\n  rfl\n  rw [sum_range_succ, mul_add, hn,succ_eq_add_one]\n  ring\n\n\nlemma sum2 (n : ℕ ) : ∑ i in range n.succ, i^2  = (n * (n+1)*(2*n+1))/6:=by\n  apply clear_denom (by norm_num : 0 < 6)\n  induction' n with n hn\n  rfl\n  rw [sum_range_succ, mul_add, hn,succ_eq_add_one] \n  ring   \n\n\n\nlemma sum3 (n : ℕ ) : ∑ i in range n.succ, i^3  = ((n * (n+1))^2)/4:=by\n  apply clear_denom (by norm_num : 0 < 4)\n  induction' n with n hn\n  rfl\n  rw [sum_range_succ, mul_add, hn,succ_eq_add_one]\n  ring\n\n\n\n-- Unfortunately as soon as subtraction enters the picture things are more complicated\nlemma sum4 (n : ℕ ) : ∑ i in range n.succ, i^4  = (n*(n + 1)*(2*n + 1)*(3*n^2 + 3*n - 1))/30:=by\n  apply clear_denom (by norm_num : 0 < 30)\n  induction' n with n hn\n  rfl\n  cases' n with n hn \n  rfl\n  -- this next intermediate result will allow us to remove all subtraction\n  have h3: ∀(m:ℕ),3 *m.succ - 1 = 3 * m + 2:=\n  by intro m; rw [mul_succ]; rfl\n\n  rw [sum_range_succ, mul_add, hn, succ_eq_add_one,succ_eq_add_one]\n    -- the next line banishes all subtraction\n  rw [Nat.add_sub_assoc, Nat.add_sub_assoc, h3,h3]\n    -- no more subtraction!\n  ring -- solves the main goal \n    --leaving us to justify the two uses of nat.add_sub_assoc\n  rw [mul_succ]\n  linarith\n  rw [mul_succ]\n  linarith\n  \n\n\n\n\n/- \n# Coercions and casts\nLean understands the type ℚ and allows us to coerce naturals into rationals \nOnce we coerce the LHS of an equality Lean automatically coerces the RHS \nsince only terms of the same type can be compared with `=` so there is no other option.\n\nYou will see `↑0`,`↑n` etc in the Infoview during the next proof.\n\nThese are the results of coercing 0 and n respectively, from ℕ to ℚ, \n\nLean knows that `↑0` is just `0` in ℚ  but you need to tell it to use this fact \nwith  `cast_zero` -/\n\nlemma asdsa (a : ℕ) (b : ℚ) : a= 0 → a*b= 0:=by \nintro h\nrw [h]\nsimp only [Nat.cast_zero, zero_mul]\n\n\n\nlemma sum4Q (n : ℕ ) : ∑ i in range n.succ, (i^4 : ℚ)  = (n*(n + 1)*(2*n + 1)*(3*n^2 + 3*n - 1))/30:=by\n  induction' n with n hn\n  rw [range_one,sum_singleton,Nat.cast_zero,zero_mul,zero_mul,\n        zero_mul,zero_div,zero_pow zero_lt_four]\n  rw [sum_range_succ, hn ] \n  field_simp \n  ring\n\n\n-- lemma sum6Q (n : ℕ ) : (∑ i in range n.succ, i^6 : ℚ)  = (n*(n + 1)*(2*n + 1)*(3*n^4 + 6*n^3 - 3*n + 1))/42:=\n-- by\n--   induction n with n hn,\n--   { \n--     rw [range_one,sum_singleton,cast_zero,zero_mul,zero_mul,\n--         zero_mul,zero_div,zero_pow],\n--     norm_num,\n--   },\n--   {\n--     rw [sum_range_succ, hn], \n--     field_simp, ring,\n--   },\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/4_numbers/nats_sums_casts.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768620069626, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7847460308566678}}
{"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.complex.circle\nimport analysis.inner_product_space.l2_space\nimport measure_theory.function.continuous_map_dense\nimport measure_theory.function.l2_space\nimport measure_theory.measure.haar\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 results on 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 : ℤ`, `fourier n` is the monomial `λ z, z ^ n`, bundled as a continuous map from `circle`\n  to `ℂ`\n* for `n : ℤ` and `p : ℝ≥0∞`, `fourier_Lp p n` is an abbreviation for the monomial `fourier n`\n  considered as an element of the Lᵖ-space `Lp ℂ p haar_circle`, via the embedding\n  `continuous_map.to_Lp`\n* `fourier_series` is the canonical isometric isomorphism from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`\n  induced by taking Fourier series\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, ℂ)`, i.e. that its `submodule.topological_closure` is `⊤`.  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 ≤ p < ∞` the span of the monomials\n`fourier_Lp` is dense in `Lp ℂ p haar_circle`, i.e. that its `submodule.topological_closure` is\n`⊤`.  This follows from the previous theorem using general theory on approximation of Lᵖ functions\nby continuous functions.\n\nThe theorem `orthonormal_fourier` states that the monomials `fourier_Lp 2 n` form an orthonormal\nset (in the L² space of the circle).\n\nThe last two results together provide that the functions `fourier_Lp 2 n` form a Hilbert basis for\nL²; this is named as `fourier_series`.\n\nParseval's identity, `tsum_sq_fourier_series_repr`, is a direct consequence of the construction of\nthis Hilbert basis.\n-/\n\nnoncomputable theory\nopen_locale ennreal complex_conjugate classical\nopen topological_space continuous_map measure_theory measure_theory.measure algebra submodule set\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 := ⟨rfl⟩\n\n/-- Haar measure on the circle, normalized to have total measure 1. -/\n@[derive is_haar_measure]\ndef haar_circle : measure circle := haar_measure positive_compacts_univ\n\ninstance : is_probability_measure haar_circle := ⟨haar_measure_self⟩\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 monomials\n\n/-- The family of monomials `λ z, z ^ n`, parametrized by `n : ℤ` and considered as bundled\ncontinuous maps from `circle` to `ℂ`. -/\n@[simps] def fourier (n : ℤ) : C(circle, ℂ) :=\n{ to_fun := λ z, z ^ n,\n  continuous_to_fun := continuous_subtype_coe.zpow n $ λ z, or.inl (ne_zero_of_mem_circle z) }\n\n@[simp] lemma fourier_zero {z : circle} : fourier 0 z = 1 := rfl\n\n@[simp] lemma fourier_neg {n : ℤ} {z : circle} : fourier (-n) z = conj (fourier n z) :=\nby simp [← coe_inv_circle_eq_conj z]\n\n@[simp] lemma fourier_add {m n : ℤ} {z : circle} :\n  fourier (m + n) z = (fourier m z) * (fourier n z) :=\nby simp [zpow_add₀ (ne_zero_of_mem_circle z)]\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ`; equivalently, polynomials in\n`z` and `conj z`. -/\ndef fourier_subalgebra : subalgebra ℂ C(circle, ℂ) := algebra.adjoin ℂ (range fourier)\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ` is in fact the linear span of\nthese functions. -/\nlemma fourier_subalgebra_coe : fourier_subalgebra.to_submodule = span ℂ (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 (λ _, id) ⟨0, rfl⟩,\n  rintros _ _ ⟨m, rfl⟩ ⟨n, rfl⟩,\n  refine ⟨m + n, _⟩,\n  ext1 z,\n  exact fourier_add,\nend\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ` separates points. -/\nlemma fourier_subalgebra_separates_points : fourier_subalgebra.separates_points :=\nbegin\n  intros x y hxy,\n  refine ⟨_, ⟨fourier 1, _, rfl⟩, _⟩,\n  { exact subset_adjoin ⟨1, rfl⟩ },\n  { simp [hxy] }\nend\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ` is invariant under complex\nconjugation. -/\nlemma fourier_subalgebra_conj_invariant :\n  conj_invariant_subalgebra (fourier_subalgebra.restrict_scalars ℝ) :=\nbegin\n  rintros _ ⟨f, hf, rfl⟩,\n  change _ ∈ fourier_subalgebra,\n  change _ ∈ fourier_subalgebra at hf,\n  apply adjoin_induction hf,\n  { rintros _ ⟨n, rfl⟩,\n    suffices : fourier (-n) ∈ fourier_subalgebra,\n    { convert this,\n      ext1,\n      simp },\n    exact subset_adjoin ⟨-n, rfl⟩ },\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, ℂ)` generated by `z ^ n` for `n ∈ ℤ` is dense. -/\nlemma fourier_subalgebra_closure_eq_top : fourier_subalgebra.topological_closure = ⊤ :=\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, ℂ)`. -/\nlemma span_fourier_closure_eq_top : (span ℂ (range fourier)).topological_closure = ⊤ :=\nbegin\n  rw ← fourier_subalgebra_coe,\n  exact congr_arg subalgebra.to_submodule fourier_subalgebra_closure_eq_top,\nend\n\n/-- The family of monomials `λ z, z ^ n`, parametrized by `n : ℤ` and considered as elements of\nthe `Lp` space of functions on `circle` taking values in `ℂ`. -/\nabbreviation fourier_Lp (p : ℝ≥0∞) [fact (1 ≤ p)] (n : ℤ) : Lp ℂ p haar_circle :=\nto_Lp p haar_circle ℂ (fourier n)\n\nlemma coe_fn_fourier_Lp (p : ℝ≥0∞) [fact (1 ≤ p)] (n : ℤ) :\n  ⇑(fourier_Lp p n) =ᵐ[haar_circle] fourier n :=\ncoe_fn_to_Lp haar_circle (fourier n)\n\n/-- For each `1 ≤ p < ∞`, the linear span of the monomials `z ^ n` is dense in\n`Lp ℂ p haar_circle`. -/\nlemma span_fourier_Lp_closure_eq_top {p : ℝ≥0∞} [fact (1 ≤ p)] (hp : p ≠ ∞) :\n  (span ℂ (range (fourier_Lp p))).topological_closure = ⊤ :=\nbegin\n  convert (continuous_map.to_Lp_dense_range ℂ hp haar_circle ℂ).topological_closure_map_submodule\n    span_fourier_closure_eq_top,\n  rw [map_span, range_comp],\n  simp\nend\n\n/-- For `n ≠ 0`, a rotation by `n⁻¹ * real.pi` negates the monomial `z ^ n`. -/\nlemma fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (z : circle) :\n  fourier n ((exp_map_circle (n⁻¹ * real.pi) * z)) = - fourier n z :=\nbegin\n  have : ↑n * ((↑n)⁻¹ * ↑real.pi * complex.I) = ↑real.pi * complex.I,\n  { have : (n:ℂ) ≠ 0 := by exact_mod_cast hn,\n    field_simp,\n    ring },\n  simp [mul_zpow₀, ← 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 ℂ (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, ← fourier_neg, ← fourier_add, -fourier_to_fun] },\n  simp only [← fourier_add, ← fourier_neg],\n  have hij : -i + j ≠ 0,\n  { rw add_comm,\n    exact sub_ne_zero.mpr (ne.symm h) },\n  exact integral_zero_of_mul_left_eq_neg (fourier_add_half_inv_index hij)\nend\n\nend monomials\n\nsection fourier\n\n/-- We define `fourier_series` to be a `ℤ`-indexed Hilbert basis for `Lp ℂ 2 haar_circle`, which by\ndefinition is an isometric isomorphism from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`. -/\ndef fourier_series : hilbert_basis ℤ ℂ (Lp ℂ 2 haar_circle) :=\nhilbert_basis.mk orthonormal_fourier (span_fourier_Lp_closure_eq_top (by norm_num))\n\n/-- The elements of the Hilbert basis `fourier_series` for `Lp ℂ 2 haar_circle` are the functions\n`fourier_Lp 2`, the monomials `λ z, z ^ n` on the circle considered as elements of `L2`. -/\n@[simp] lemma coe_fourier_series : ⇑fourier_series = fourier_Lp 2 := hilbert_basis.coe_mk _ _\n\n/-- Under the isometric isomorphism `fourier_series` from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`, the\n`i`-th coefficient is the integral over the circle of `λ t, t ^ (-i) * f t`. -/\nlemma fourier_series_repr (f : Lp ℂ 2 haar_circle) (i : ℤ) :\n  fourier_series.repr f i = ∫ t : circle, t ^ (-i) * f t ∂ haar_circle :=\nbegin\n  transitivity ∫ t : circle, conj ((fourier_Lp 2 i : circle → ℂ) t) * f t ∂ haar_circle,\n  { simp [fourier_series.repr_apply_apply f i, measure_theory.L2.inner_def] },\n  apply integral_congr_ae,\n  filter_upwards [coe_fn_fourier_Lp 2 i] with _ ht,\n  rw [ht, ← fourier_neg],\n  simp [-fourier_neg]\nend\n\n/-- The Fourier series of an `L2` function `f` sums to `f`, in the `L2` topology on the circle. -/\nlemma has_sum_fourier_series (f : Lp ℂ 2 haar_circle) :\n  has_sum (λ i, fourier_series.repr f i • fourier_Lp 2 i) f :=\nby simpa using hilbert_basis.has_sum_repr fourier_series f\n\n/-- **Parseval's identity**: the sum of the squared norms of the Fourier coefficients equals the\n`L2` norm of the function. -/\nlemma tsum_sq_fourier_series_repr (f : Lp ℂ 2 haar_circle) :\n  ∑' i : ℤ, ∥fourier_series.repr f i∥ ^ 2 = ∫ t : circle, ∥f t∥ ^ 2 ∂ haar_circle :=\nbegin\n  have H₁ : ∥fourier_series.repr f∥ ^ 2 = ∑' i, ∥fourier_series.repr f i∥ ^ 2,\n  { exact_mod_cast lp.norm_rpow_eq_tsum _ (fourier_series.repr f),\n    norm_num },\n  have H₂ : ∥fourier_series.repr f∥ ^ 2 = ∥f∥ ^2 := by simp,\n  have H₃ := congr_arg is_R_or_C.re (@L2.inner_def circle ℂ ℂ _ _ _ _ _ _ _ f f),\n  rw ← integral_re at H₃,\n  { simp only [← norm_sq_eq_inner] at H₃,\n    rw [← H₁, H₂],\n    exact H₃ },\n  { exact L2.integrable_inner f f },\nend\n\nend fourier\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/fourier.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7847035672027287}}
{"text": "/- TACTICS -/\n\n-- example (n m k : Nat) : (n + m) * k = (m + n) * k := by \n--   have t := Nat.add_comm n -- Ao substituir n + m por m + n as equacoes ficam iguais\n--   rw [t]\n\nnamespace TBA\n\n-- definitions from last week\n-- NOTE: We renamed it from `Nat'` for consistency. The new namespace makes sure we don't use the\n-- standard library `Nat`.\ninductive Nat : Type where\n  | zero : Nat\n  | succ (n : Nat) : Nat\n\nopen Nat\n\ndef add (m n : Nat) : Nat :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\n-- With this command we add a notation for `add`. From now on we will be able to write `m + n` for\n-- `add m n`. The 65 denotes how strongly the operator should bind to what's adjacent to it.\n-- The `priority` means that Lean will prefer it over the built-in `+`.\ninfix:65 (priority := high) \" + \" => add\n\ndef mul (m n : Nat) : Nat :=\n  match n with\n  | zero   => zero\n  | succ n => (mul m n) + m\n\n-- We also want a notation for `mul`, with a higher binding strength than addition so that\n-- `a + b * c` means `a + (b * c`)`.\ninfix:70 (priority := high) \" * \" => mul\n\ninductive LE : Nat → Nat → Prop where\n  | refl (n : Nat) : LE n n\n  | succ : LE m n → LE m (succ n)\n\n-- lower binding strength than either addition or multiplication\ninfix:50 (priority := high) \" ≤ \" => LE\n\n-- Let's start by reproving some theorems from last week, but this time with tactics!\n-- useful tactics:\n-- * `induction ... with ...`\n-- * `rw [f]` to unfold applications of a function `f`\n-- * `rw [h]` to rewrite every `a` to `b` if `h : a = b`\n-- * `apply/exact`\n-- * `simp/simp_all`... are powerful and basically always useful, though make sure that you could also\n--   do the proof without them\ntheorem zero_add : zero + n = n := by\n  induction n with\n  | zero      => rfl\n  | succ n ih => -- rw [add, ih]\n    induction n \n    case succ.zero => \n      rfl \n    case succ.succ => \n      simp_all [add]\n\ntheorem add_zero : n + zero = n := by\n  rfl\n\ntheorem le_add : m ≤ m + n := by \n  induction n  \n  case zero => \n    exact LE.refl _ \n  case succ n h => \n    apply LE.succ \n    simp_all\n\n-- Alright, let's start automating more!\nattribute [simp] add mul\n-- These definitions will now automatically be unfolded when you use `simp/simp_all`\n\ntheorem succ_add : (succ n) + m = succ (n + m) := by\n  induction m \n  case zero => rfl\n  case succ h => simp [h]\n\n-- This one is a bit more tricky, you might need to prove a helper lemma!\ntheorem add_comm : n + m = m + n := by \n  induction n \n  case zero => \n    exact zero_add\n  case succ n h => \n    simp [h, succ_add]\n\n-- Associativity can be proven in a similar way.\ntheorem add_assoc : (m + n) + k = m + (n + k) := by \n  induction k \n  case zero => \n    rfl \n  case succ n h => \n    simp [h]\n\ndef one := succ zero\n\ntheorem mul_one : m * one = m := by \n  induction m <;> simp_all\n\ntheorem one_mul : one * m = m := by \n  induction m <;> simp_all\n\n-- To prove associativity of multiplication, you might have to come up with\n-- some more lemmas about multiplication first. Some are similar to the above laws of\n-- addition, some use both addition and multiplication (\"distributivity\" is the keyword).\n\ntheorem mul_zero : n * zero = zero := by \n  induction n <;> simp\n\n@[simp]theorem zero_mul : zero * n = zero := by \n  induction n <;> simp_all\n\ntheorem mul_distr : a * (b + c) = (a * b) + (a * c) := by \n  induction c\n  case zero => simp\n  case succ a h => \n    rw [add, mul, mul, h, add_assoc]\n  -- simp [add_assoc, h] -- would be a loop if Lean was not smart enough\n\ntheorem mul_assoc : (m * n) * k = m * (n * k) := by \n  induction k \n  case zero => simp\n  case succ n h => simp [mul_distr, h]\n\n-- Remember the structures for semigroups and monoids which we defined last week?\nstructure Semigroup (α : Type) where\n  mul   : α → α → α\n  assoc : mul (mul a b) c = mul a (mul b c)\n\nstructure Monoid (α : Type) extends Semigroup α where\n  e     : α\n  e_mul : mul e a = a\n  mul_e : mul a e = a\n\n-- You should now be able to instantiate two of them, including proofs!\ndef Nat_add_Monoid : Monoid Nat := \n  {\n    mul := add,\n    assoc := add_assoc,\n    e := zero,\n    e_mul := zero_add,\n    mul_e := add_zero\n  }\n\ndef Nat_mul_Monoid : Monoid Nat := \n  {\n    mul := mul,\n    assoc := mul_assoc,\n    e := succ zero,\n    e_mul := one_mul,\n    mul_e := mul_one\n  }\n\nend TBA\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/Exercise4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.8740772236840657, "lm_q1q2_score": 0.7846550158164921}}
{"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\" (∨`)\n\nWe learn about how to manipulate `P ∨ 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 `⊢ P ∨ Q` then `left,` will change it to `⊢ P`\nand `right,` will change it to `⊢ Q`.\n\n### The `cases` tactic again\n\nIf we have `h : P ∨ 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 → P ∨ Q :=\nbegin\n  sorry\nend\n\nexample : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\nexample : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  sorry\nend\n\n-- symmetry of `or`\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n-- associativity of `or`\nexample : (P ∨ Q) ∨ R ↔ P ∨ (Q ∨ R) :=\nbegin\n  sorry,\nend\n\nexample : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\nexample : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\nexample : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\nend\n\n-- de Morgan's laws\nexample : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\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/logic/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7846433628357807}}
{"text": "section propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n   intro p, \n   intro q, \n   apply q, \n   exact p, \n  \nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro h1,\n  by_cases p : P, -- pegando P e partindo em dois positivo e negativo\n  exact p,\n  contradiction, -- Opa! temos uma contradição :p\n  \n  \nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P, --Pegamos o caso --P -> P ALVO(P -> --P) --\n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\n\nbegin\n  intro pq, -- Ganhamos P V Q como dado, nosso alvo é Q V P --\n  cases pq with hp hq, --Separamos em dois --\n  right, -- chame a da direita --\n  exact hp, -- Portanto é hp --\n  left, -- chame a da esquerca --\n  exact hq, -- retorne que é hq -- \n\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro pq,\n  cases pq with p q,\n  split,\n  exact q,\n  exact p,\n  \n  \n\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h1,\n  intro h2,\n  cases h1 with p q,\n  contradiction,\n  exact q,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro h1,\n  intro h2,\n  cases h1 with p q,\n  contradiction,\n  exact q,\n\n\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros h1 h2 h3,\n  have h4 := h1 h3,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro h1,\n  intro h_p,\n  by_cases h_q : Q, --Caso sim e caso não\n  exact h_q,\n  exfalso,\n  have new_q := h1 h_q, --Opa! -q e -p estão no mesmo barco\n  contradiction,\n\n\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  apply impl_as_contrapositive,\n  apply impl_as_contrapositive_converse,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h1,\n  apply h1,\n  right,\n  intro p,\n  have h1p : P ∨ ¬P,\n  left,\n  exact p,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros h1 h2,\n  have h1 : P,\n  apply h1,\n  intro p,\n  exfalso,\n  contradiction,\n  contradiction,\n  \n  \nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intros h1 h2,\n  cases h2 with h_p h_q,\n  cases h1,\n  contradiction,\n  contradiction,\n  \nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intros h1 h2,\n  cases h2 with p q,\n  cases h1,\n  contradiction,\n  cases h1 with p q,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_ndisj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro h1,\n  split,\n  intro h_p,\n  have h1 : P ∨ Q,\n  left,\n  exact h_p,\n  contradiction,\n  intro h_q,\n  have h1 : P ∨ Q,\n  right,\n  exact h_q,\n  contradiction,\n  \nend\n\ntheorem demorgan_ndisj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros h1 h2,\n  cases h1 with p q,\n  cases h2 with pp qq,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_nconj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro h1,\n  intro h2,\n  cases h1 with h_np h_nq,\n  cases h2 with p q,\n  contradiction,\n  cases h2 with p q,\n  contradiction,\n  \nend\n\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h,\n  cases h with p h2,\n  cases h2 with q r,\n  left,\n  split,\n  exact p,\n  exact q,\n  right,\n  split,\n  exact p,\n  exact r,\n  \n  \n\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h1,\n  split,\n  cases h1 with p_q p_r,\n  cases p_q with p q,\n  exact p,\n  cases p_r with p r,\n  exact p,\n  cases h1 with p_q p_r,\n  cases p_q with p q,\n  left,\n  exact q,\n  right,\n  cases p_r with p r,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h1,\n  split,\n  cases h1 with h_p h_qr,\n  left,\n  exact h_p,\n  cases h_qr with q r,\n  right,\n  exact q,\n  cases h1 with h_p h_qr,\n  left,\n  exact h_p,\n  cc,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h1,\n  cases h1 with h_pq h_pr,\n  cases h_pr with p qr,\n  left,\n  exact p,\n  cases h_pq with p q,\n  left,\n  exact p,\n  right,\n  split,\n  exact q,\n  exact qr,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro h1,\n  intro h2_p,\n  intro h3_q,\n  apply h1,\n  split,\n  exact h2_p,\n  exact h3_q,\n  \n  \nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro h1,\n  intro h_pq,\n  apply h1,\n  cases h_pq with p q,\n  exact p,\n  cases h_pq with p q,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p, \n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro pq,\n  cases pq with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro pq,\n  cases pq with  p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pp1,\n  cases pp1 with p1 p2,\n  exact p1,\n  intro pp2,\n  split,\n  repeat {exact pp2},\n  \nend\n\ntheorem disj_idemp :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro pp1,\n  cases pp1 with p1 p2,\n  exact p1,\n  exact p2,\n  intro p,\n  right,\n  exact p,\n\n\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists_neg :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro exits,\n  cases exits with x h_not_P,\n  intro all,\n  apply h_not_P,\n  have hx: P x := all x,--no fim\n  --Olha eu tenho P x no para todo x e ele será minha hipotese Pu\n  exact hx,\nend\n\ntheorem demorgan_neg_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro exits,\n  intro u,\n  intro pb,\n  apply exits, --Ficou falso então... o que na nossa prop é falso tbm :p\n  existsi u,\n  exact pb,\n\nend\n\ntheorem demorgan_forall_neg :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro all,\n  intro exist,\n  cases exist with x exist_x, \n  have hneg := all  x, --pegue o -p no all (ai sera minha hipotese hneg)\n  contradiction, -- :p\n  \n  \nend\n\ntheorem demorgan_neg_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n intro all,\n by_contra ne,\n apply all, --blz peguei o all sem neg,\n intro u,\n by_contra no_u,\n apply ne, --hehehe peguei o exist\n existsi u,\n intro prop_u,\n apply no_u,\n exact prop_u,\n\nend\n\ntheorem demorgan_exists_law :\n  (∃x, ¬P x) ↔ ¬(∀x, P x)  :=\nbegin\n  split,\n  apply demorgan_exists_neg,\n  apply demorgan_neg_forall,\nend\n\ntheorem demorgan_forall_law :\n  (∀x, ¬P x) ↔ ¬(∃x, P x)  :=\nbegin\n  split,\n  apply demorgan_forall_neg,\n  apply demorgan_neg_exists,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro exist,\n  intro all,\n  cases exist with x,\n  apply all,\n  have npx := all x,\n  contradiction,\n  exact x,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro all,\n  intro exist,\n  cases exist with x,\n  apply exist_h,\n  have h_x_all : P x := all x,\n  exact h_x_all,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro exist_neg,\n  by_contra all_neg,\n  apply all_neg,\n  intro x,\n  by_contra x_neg,\n  apply exist_neg,\n  existsi x,\n  exact x_neg,\n  \nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro neg_all,\n  by_contra exist_neg, --mudando as pontas\n  apply neg_all,\n  intro x,\n  by_contra p_x,\n  apply exist_neg,\n  existsi x,\n  exact p_x,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\n\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  --intro exist_one_disj,\n  --split,\n  --cases exist_one_disj with x,\n  --existsi x,\n\n  intro exist_one_disj,\n  cases exist_one_disj with xu px_and_qx,\n  cases px_and_qx with px qx,\n  split,\n  existsi xu,\n  exact px,\n  existsi xu,\n  exact qx,\n  \n  \n  \nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  --intro pro_e_one,\n  --right,\n  --cases pro_e_one with x px_or_qx,\n  --existsi x,\n\n  intro pro_e_one,\n  cases pro_e_one with x px_or_qx,\n  cases px_or_qx with px qx,\n  left,\n  existsi x,\n  exact px,\n  right,\n  existsi x,\n  exact qx,\n  \nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro exist_one,\n  cases exist_one with exist_one exist_two,\n  cases exist_one with x px,\n  existsi x,\n  left,\n  exact px,\n  cases exist_two with x qx,\n  existsi x,\n  right,\n  exact qx,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro prop_all_one,\n  split,\n  intro px,\n  have h_px_and_qx := prop_all_one px,\n  cases h_px_and_qx with px qx,\n  exact px,\n  intro q,\n  have h_px_and_qx := prop_all_one q,\n  cases h_px_and_qx with px qx,\n  exact qx,\n  \nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro all_prop,\n  intro x,\n  cases all_prop with apx aqx,\n  split,\n  have hapx := apx x,\n  exact hapx,\n  have haqx := aqx x,\n  exact haqx,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro all_prop,\n  intro x,\n  cases all_prop with all_p all_q,\n  have px := all_p x,\n  left,\n  exact px,\n  have qx := all_q x,\n  right,\n  exact qx,\n  \nend\n\n-- WWWEEEE ON THE CHAMPIONS....\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\n  sorry,\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "StefWolf", "repo": "fmc1repo", "sha": "3538859890021c196ed00e524d57ad08f0341d0c", "save_path": "github-repos/lean/StefWolf-fmc1repo", "path": "github-repos/lean/StefWolf-fmc1repo/fmc1repo-3538859890021c196ed00e524d57ad08f0341d0c/fmclean/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7846433616413939}}
{"text": "-- Generated by KMB and students, following on from a 342 session\n-- on rational powers\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 : ∀ 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\nnoncomputable definition natural_power : real → nat → real\n| x 0 := 1\n| x (succ n) := (natural_power x n) * x\n\n-- Proof by Eduard Oravkin\ntheorem T1 : ∀ x:real, ∀ m n:nat, natural_power x (m+n) = natural_power x m *natural_power x n :=\nbegin\nintro x, intro m, intro n,\ninduction n with s H1,\nhave H : natural_power x 0 = 1,\n  refl,\nrw [add_zero, H , mul_one],\nunfold natural_power,\nrw [← mul_assoc, H1],\nend\n\n-- Proof by Chris Hughes \ntheorem T2 : ∀ x: real, ∀ 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 [T1,H]\nend\n\n-- Proof by Ali Barkhordarian\ntheorem T3 : ∀ x y: real, ∀ 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,\nexact one_mul 1,\nunfold natural_power,\nrw [mul_assoc],\nrw [← mul_assoc x],\nrw [mul_comm x],\nrw [mul_assoc, ←mul_assoc],\nrw [H]\nend\n\n\nconstant nth_root (x : real) (n : nat) : (x>0) → (n>0) → 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", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/M1F/room_342_group_projects/rational_powers/rational_powers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7846433543212071}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a, b, c y números reales. Demostrar, con la táctica\n-- ring, que\n--    (c * b) * a = b * (a * c)\n--    (a + b) * (a + b) = a * a + 2 * (a * b) + b * b\n--    (a + b) * (a - b) = a^2 - b^2\n-- Además, si\n--    c = d * a + b\n--    b = a * d\n-- entonces\n--    c = 2 * a * d\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b c d : ℝ\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\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/Demostraciones_con_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.784643352272164}}
{"text": "\n-- textbook: expressions\n#check 2 + 2\n#check -5\n#check [1, 2, 3]\n#check #[1, 2, 3]\n#check (1, 2, 3)\n#check \"hello world\"\n#check true\n#check fun x => x + 1\n#check fun x => if x = 1 then \"yes\" else \"no\"\n-- end: expressions\n\n\n-- textbook: types\n#check Nat\n#check Int\n#check List Nat\n#check Array Nat\n#check Nat × Nat × Nat\n#check String\n#check Bool\n#check Nat → Nat\n#check Nat → String\n-- end: types\n\n\n-- textbook: asserting types\n#check (2 + 2 : Nat)\n#check ([1, 2, 3] : List Nat)\n-- end: asserting types\n\n\n-- textbook: some definitions\ndef four : Nat := 2 + 2\n\ndef isOne (x : Nat) : String := if x = 1 then \"yes\" else \"no\"\n\n#check four\n#print four\n\n#check isOne\n#print isOne\n-- end: some definitions\n\n\n-- textbook: definitions without type ascriptions\ndef four' := 2 + 2\n\ndef isOne' x := if x = 1 then \"yes\" else \"no\"\n-- end: definitions without type ascriptions\n\n\n-- textbook: evaluating expressions\n#eval four\n#eval isOne 3\n#eval isOne 1\n-- end: evaluating expressions\n\n\n-- textbook: using IO\n#eval IO.println \"Hello, world!\"\n-- end: using IO\n\n\n\n-- textbook: some propositions\n#check 2 + 2 = 4\n#check 2 + 2 < 5\n#check isOne 3 = \"no\"\n#check 2 + 2 < 5 ∧ isOne 3 = \"no\"\n-- end: some propositions\n\n\n-- textbook: Fermat's last theorem\ndef Fermat_statement : Prop :=\n∀ a b c n : Nat, a * b * c ≠ 0 ∧ n > 2 → a^n + b^n ≠ c^n\n-- end: Fermat's last theorem\n\n-- textbook: an easy proof\ntheorem two_plus_two_is_four : 2 + 2 = 4 := rfl\n-- end: an easy proof\n\n-- textbook: harder to prove\ntheorem Fermat_last_theorem : Fermat_statement := sorry\n-- end: harder to prove\n\n\n", "meta": {"author": "avigad", "repo": "lamr", "sha": "b2795a17fb01b7e45aaa1940d4c4200f46800e16", "save_path": "github-repos/lean/avigad-lamr", "path": "github-repos/lean/avigad-lamr/lamr-b2795a17fb01b7e45aaa1940d4c4200f46800e16/LAMR/Examples/using_lean_as_a_programming_language/examples1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.784643352272164}}
{"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.kb_solutions.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 : ℂ := ⟨0, 1⟩\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  refl\nend\n\n/-- im(I) = 1 -/\n@[simp] lemma I_im : im(I) = 1 := rfl\n\n--local attribute [simp] ext_iff\n\n/-- I*I = -1 -/\n@[simp] lemma I_mul_I : I * I = -1 :=\nbegin\n  ext;\n  simp\nend\n\n\nlemma mk_eq_add_mul_I (a b : ℝ) : (⟨a, b⟩ : ℂ) = a + b * I :=\nbegin\n  ext;\n  simp\nend\n\n@[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=\nbegin\n  ext; simp\nend\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 : ∀ {z w : ℂ}, z = w ↔ z.re = w.re ∧ z.im = w.im\n-/\n\n/-- I is non-zero -/\nlemma I_ne_zero : (I : ℂ) ≠ 0 :=\nbegin\n  simp [ext_iff]\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/kb_solutions/Level_02_I.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.784565167367152}}
{"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.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 `Λ`.\n\nWe then prove the classical summation property of the von Mangoldt function in\n`nat.arithmetic_function.von_mangoldt_sum`, that `∑ i in n.divisors, Λ i = real.log n`, and use this\nto deduce alternative expressions for the von Mangoldt function via Möbius inversion, see\n`nat.arithmetic_function.sum_moebius_mul_log_eq`.\n\n## Notation\n\nWe use the standard notation `Λ` 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 `ℕ → ℝ`. 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 ℝ :=\n⟨λ n, real.log n, by simp⟩\n\n@[simp] lemma log_apply {n : ℕ} : 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 `Λ` for this function.\n-/\nnoncomputable def von_mangoldt : arithmetic_function ℝ :=\n⟨λ n, if is_prime_pow n then real.log (min_fac n) else 0, if_neg not_is_prime_pow_zero⟩\n\nlocalized \"notation (name := von_mangoldt)\n  `Λ` := nat.arithmetic_function.von_mangoldt\" in arithmetic_function\n\nlemma von_mangoldt_apply {n : ℕ} :\n  Λ n = if is_prime_pow n then real.log (min_fac n) else 0 := rfl\n\n@[simp] lemma von_mangoldt_apply_one : Λ 1 = 0 := by simp [von_mangoldt_apply]\n\n@[simp] lemma von_mangoldt_nonneg {n : ℕ} : 0 ≤ Λ 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 : ℕ} (hk : k ≠ 0) : Λ (n ^ k) = Λ n :=\nby simp only [von_mangoldt_apply, is_prime_pow_pow_iff hk, pow_min_fac hk]\n\nlemma von_mangoldt_apply_prime {p : ℕ} (hp : p.prime) : Λ p = real.log p :=\nby rw [von_mangoldt_apply, prime.min_fac_eq hp, if_pos hp.prime.is_prime_pow]\n\nlemma von_mangoldt_ne_zero_iff {n : ℕ} : Λ n ≠ 0 ↔ is_prime_pow n :=\nbegin\n  rcases eq_or_ne n 1 with rfl | hn, { simp [not_is_prime_pow_one] },\n  exact (real.log_pos (one_lt_cast.2 (min_fac_prime hn).one_lt)).ne'.ite_ne_right_iff\nend\n\nlemma von_mangoldt_pos_iff {n : ℕ} : 0 < Λ n ↔ is_prime_pow n :=\nvon_mangoldt_nonneg.lt_iff_ne.trans (ne_comm.trans von_mangoldt_ne_zero_iff)\n\nlemma von_mangoldt_eq_zero_iff {n : ℕ} : Λ n = 0 ↔ ¬is_prime_pow n :=\nvon_mangoldt_ne_zero_iff.not_right\n\nopen_locale big_operators\n\nlemma von_mangoldt_sum {n : ℕ} :\n  ∑ i in n.divisors, Λ 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, ←sum_filter] at ha hb ⊢,\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')],\nend\n\n@[simp] lemma von_mangoldt_mul_zeta : Λ * ζ = log :=\nby { ext n, rw [coe_mul_zeta_apply, von_mangoldt_sum], refl }\n\n@[simp] lemma zeta_mul_von_mangoldt : (ζ : arithmetic_function ℝ) * Λ = log :=\nby { rw [mul_comm], simp }\n\n@[simp] \n\n@[simp] lemma moebius_mul_log_eq_von_mangoldt : (μ : arithmetic_function ℝ) * log = Λ :=\nby { rw [mul_comm], simp }\n\nlemma sum_moebius_mul_log_eq {n : ℕ} :\n  ∑ d in n.divisors, (μ d : ℝ) * log d = - Λ n :=\nbegin\n  simp only [←log_mul_moebius_eq_von_mangoldt, mul_comm log, mul_apply, log_apply, int_coe_apply,\n    ←finset.sum_neg_distrib, neg_mul_eq_mul_neg],\n  rw sum_divisors_antidiagonal (λ i j, (μ i : ℝ) * -real.log j),\n  have : ∑ (i : ℕ) in n.divisors, (μ i : ℝ) * -real.log (n / i : ℕ) =\n         ∑ (i : ℕ) in n.divisors, ((μ i : ℝ) * real.log i - μ 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 : ℝ) ≠ 0,\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, ←sum_mul, ←int.cast_sum, ←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;\n  simp [hn],\nend\n\nlemma von_mangoldt_le_log : ∀ {n : ℕ}, Λ n ≤ real.log (n : ℝ)\n| 0 := by simp\n| (n+1) :=\n  begin\n    rw ←von_mangoldt_sum,\n    exact single_le_sum (λ _ _, von_mangoldt_nonneg) (mem_divisors_self _ n.succ_ne_zero),\n  end\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/von_mangoldt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7845566907227758}}
{"text": "theorem mul_eq_zero_iff (a b : mynat): a * b = 0 ↔ a = 0 ∨ b = 0 :=\nbegin\nsplit,\napply eq_zero_or_eq_zero_of_mul_eq_zero,\nintro h,\ncases h,\nrw h,\nrwa zero_mul,\nrw h,\nrwa mul_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/world09/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8354835330070838, "lm_q1q2_score": 0.7845397734722771}}
{"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 5 : \"iff\" (`↔`)\n\nWe learn about how to manipulate `P ↔ Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following two new tactics:\n\n* `refl`\n* `rw`\n\n-/\n\nvariables (P Q R S : Prop)\n\nexample : P ↔ P :=\nbegin\nrefl,\nend\n\nexample : (P ↔ Q) → (Q ↔ P) :=\nbegin\nintro q,rw q,\nend\n\nexample : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  split,intro q, rw q,intro q,rw q,\nend\n\nexample : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  intros q w,\n  rwa q, \nend\n\nexample : P ∧ Q ↔ Q ∧ P :=\nbegin\n  split;\n  {rintro ⟨q, w⟩,exact ⟨w, q⟩\n  }\nend\n\nexample : ((P ∧ Q) ∧ R) ↔ (P ∧ (Q ∧ R)) :=\nbegin\n  split,intro q,cases q,cases q_left,split,assumption,split,assumption,assumption,\n  intro q,cases q,cases q_right,split,split,assumption,assumption,assumption,\nend\n\nexample : P ↔ (P ∧ true) :=\nbegin\n  split,\n  {intro q,split,assumption,triv,},\n  {intro q,cases q,assumption,}\nend\n\nexample : false ↔ (P ∧ false) :=\nbegin\n  split,\n  {intro q,split,by_contra,triv,triv,},\n  {intro q,cases q, assumption}\nend\n\nexample : (P ↔ Q) → (R ↔ S) → (P ∧ R ↔ Q ∧ S) :=\nbegin\n  intros q w,split,\n  {intro e,split,cases q,apply q_mp,cases e,assumption,cases w,apply w_mp,cases e,assumption,},\n  {intro e,split,cases q,apply q_mpr,cases e,assumption,cases w,cases e,apply w_mpr,assumption,},\nend\n\nexample : ¬ (P ↔ ¬ P) :=\nbegin\nintro q,cases q,change (P->(P->false)) at q_mp,apply q_mp,apply q_mpr,change P ->false,intro e,apply q_mp,assumption,assumption,apply q_mpr,change P->false,intro q, apply q_mp,exact q,exact q,\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/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363299661721, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7844959717872203}}
{"text": "open Classical\n\n----------------------------------LOGIC-----------------------------------------\ntheorem Or.distrib_and : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := \n  Iff.intro\n  (fun hpqr : p ∨ (q ∧ r) =>\n    Or.elim hpqr\n    (fun hp:p => show (p ∨ q) ∧ (p ∨ r) from ⟨(Or.intro_left q hp), (Or.intro_left r hp)⟩)\n    (fun hqr: (q ∧ r) => show (p ∨ q) ∧ (p ∨ r) from ⟨(Or.intro_right p hqr.left), (Or.intro_right p hqr.right)⟩))\n  (fun hpqpr: (p ∨ q) ∧ (p ∨ r) => \n    have hpq := hpqpr.left\n    have hpr := hpqpr.right\n    Or.elim hpq\n    (fun hp:p => show p ∨ (q ∧ r) from Or.intro_left (q ∧ r) hp)\n    (fun hq:q =>\n    Or.elim hpr\n    (fun hp:p => show p ∨ (q ∧ r) from Or.intro_left (q ∧ r) hp)\n    (fun hr:r => show p ∨ (q ∧ r) from Or.intro_right p ⟨hq, hr⟩))\n )\n\ntheorem And.assoc : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) := by\n  constructor\n  case mp => intro ⟨⟨ha, hb⟩, hc⟩; exact ⟨ha, ⟨hb, hc⟩⟩\n  case mpr => intro ⟨ha, ⟨hb, hc⟩⟩; exact ⟨⟨ha, hb⟩, hc⟩\n\ntheorem And.distrib_or : a ∧ (b ∨ c) ↔ (a ∧ b) ∨ (a ∧ c) := by\n  constructor\n\n  case mp =>\n    intro ⟨ha, hor⟩\n    cases hor with\n    | inl hl => exact Or.inl ⟨ha, hl⟩\n    | inr hr => exact Or.inr ⟨ha, hr⟩\n\n  case mpr =>\n    intro h\n    match h with\n    | Or.inl ⟨ha, hb⟩ => exact ⟨ha, Or.inl hb⟩\n    | Or.inr ⟨ha, hc⟩ => exact ⟨ha, Or.inr hc⟩\n\ntheorem Or.morgan : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  Iff.intro\n  (fun hnpq: ¬(p ∨ q) => \n    ⟨fun hp:p => hnpq (Or.intro_left q hp), fun hq:q => hnpq (Or.intro_right p hq)⟩ \n )\n  (fun hnpq : ¬p ∧ ¬q =>\n    fun hpq : (p ∨ q) =>\n      Or.elim hpq\n      (fun hp:p => hnpq.left hp)\n      (fun hq:q => hnpq.right hq)\n )\n\ntheorem And.morgan : ¬(p ∧ q) ↔ ¬p ∨ ¬q :=\n  Iff.intro\n  (fun hpq : ¬(p ∧ q) =>\n    Or.elim (em p)\n    (fun hp:p =>\n      Or.elim (em q)\n      (fun hq : q => show ¬p ∨ ¬q from False.elim (hpq ⟨hp, hq⟩))\n      (fun nq : ¬q => (Or.intro_right (¬p) nq)))\n    (fun np:¬p => (Or.intro_left (¬q) np)))\n  (fun hpoq : ¬p ∨ ¬q =>\n    Or.elim hpoq\n    (fun hp:¬p =>\n      fun hpnq : p ∧ q => hp hpnq.left)\n    (fun hp:¬q =>\n      fun hpnq : p ∧ q => hp hpnq.right))\n\ntheorem not_or_eq_implication: (¬p ∨ q) ↔ (p → q) :=\n  Iff.intro\n  ( fun hpq : ¬p ∨ q =>\n    Or.elim hpq\n    (fun hnp: ¬p => \n      fun hp:p => show q from False.elim (hnp hp))\n    (fun hq: q => \n      fun _:p => hq))\n  ( fun hpq : (p → q) =>\n    Or.elim (em q)\n    (fun hq:q => Or.intro_right (¬p) hq)\n    (fun nq:¬q =>\n      Or.elim (em p)\n      (fun hp:p => show (¬p ∨ q) from False.elim (nq (hpq hp)))\n      (fun np:¬p => show (¬p ∨ q) from Or.intro_left q np)\n   ))\n\ntheorem And.elimination : p ∧ (¬p ∨ q) ↔ p ∧ q := by\n  apply Iff.intro\n  intro pnpq\n  rw [not_or_eq_implication] at pnpq\n  exact ⟨pnpq.left, pnpq.right pnpq.left⟩ \n  intro pq\n  exact ⟨pq.left, Or.intro_right (¬p) pq.right⟩ \n\ntheorem np_and_p_imp_false {p : Prop}: ¬p ∧ p → False := by\n  intro npp\n  exact npp.left npp.right\n\ntheorem not_not_p {p : Prop}: (¬¬p) ↔ p := by\n  apply Iff.intro\n  intro nnp\n  cases (Classical.em p) with \n  | inl hp => \n    exact hp\n  | inr hr => \n    apply False.elim (nnp hr)\n  intro hp \n  cases (Classical.em ¬ p) with \n  | inl hl => \n    apply False.elim (hl hp)\n  | inr hr =>\n    exact hr \n\ntheorem Or.comm (a b:Prop) : a ∨ b ↔ b ∨ a := by\n  constructor\n  intro ab\n  apply Or.elim ab\n  intro ha\n  exact Or.intro_right b ha\n  intro hb\n  exact Or.intro_left a hb\n  intro ba \n  apply Or.elim ba \n  intro hb \n  exact Or.intro_right a hb\n  intro ha \n  exact Or.intro_left b ha\n\n\ntheorem notAllEqExists (p : α → Prop) (h: ¬ ∀ x, ¬ p x) : ∃ x, p x :=\n  byContradiction\n    (fun h1 : ¬ ∃ x, p x =>\n      have h2 : ∀ x, ¬ p x :=\n        fun x =>\n        fun h3 : p x =>\n        have h4 : ∃ x, p x := ⟨x, h3⟩\n        show False from h1 h4\n      show False from h h2)\n\ntheorem notExistsEqAll (p : α → Prop) : (¬∃ x, p x) → (∀ x, ¬p x) := by\n  intro h2\n  intro x\n  intro px\n  have existsY : ∃y, p y := by exists x\n  exact h2 existsY\n\n----------------------------------LISTS-----------------------------------------\ntheorem list_concat_empty {α :Type u} (as : List α) : as ++ [] = as := by\nsimp [List.cons]\n\ntheorem EmptyNotFull : (∀ x xs, list ≠ (x::xs)) → list = [] := by\n      intro h\n      cases (list) with\n      | nil => rfl\n      | cons x1 xs1 => \n        exact absurd rfl (h x1 xs1)\n\n----------------------------------SETS------------------------------------------\ndef Set (α : Type u) := α -> Prop\n\nnamespace Set\ndef element {α : Type u} (e : α) (X : Set α) : Prop := X e\ninfixr:75 \" ∈ \" => element\n\ndef union {α : Type u} (X Y : Set α) : Set α := fun a => a ∈ X ∨ a ∈ Y\ninfixr:65 \" ∪ \" => union\n\ndef subset {α : Type u} (X Y : Set α) : Prop := ∀ e : α, e ∈ X → e ∈ Y\ninfixr:50 \" ⊆ \" => subset\n\ndef intersection {α : Type u} (X Y : Set α) : Set α := fun (e: α) => e ∈ X ∧ e ∈ Y\ninfixr:80 \" ∩ \" => intersection\n\ndef diff {α : Type u} (X Y : Set α) : Set α := fun (e: α) => e ∈ X ∧ ¬(e ∈ Y)\n--infixr:80 \" \\\\ \" => intersection\n\ndef empty {α :Type u}: Set α := fun _ => False\n\nnotation (priority := high) \"∅\" => empty\n\n\ntheorem setext {α :Type u} {a b : Set α} (h : ∀ x, x ∈ a ↔ x ∈ b) : a = b :=\n funext (fun x => propext (h x))\n\ntheorem inter_self {α :Type u} (a : Set α) : a ∩ a = a := by\n  apply setext\n  intro x\n  constructor\n  intro n \n  rw [element, intersection] at n\n  exact n.left \n  intro n \n  exact ⟨n,n⟩ \n\ntheorem inter_empty {α :Type u} (X : Set α) : X ∩ ∅ = ∅ := by \n  apply setext\n  intro n\n  constructor\n  intro x \n  rw [element, intersection] at x\n  exact x.right \n  intro x \n  rw [element] at x \n  rw [empty] at x \n  exact False.elim x \n\ntheorem inter_comm {α : Type u} (X Y:Set α) : X ∩ Y = Y ∩ X := by \n  apply setext \n  intro x \n  constructor \n  intro n \n  rw [element, intersection] at n\n  rw [element, intersection]\n  exact ⟨n.right, n.left⟩ \n  intro n \n  rw [element, intersection] at n\n  rw [element, intersection]\n  exact ⟨n.right, n.left⟩ \n\ntheorem union_or {α : Type u} (X Y : Set α) (e : α) : (e ∈ (X ∪ Y)) = (e ∈ X ∨ e ∈ Y) := by rfl\n\ntheorem union_comm {α :Type u} (X Y : Set α) : X ∪ Y = Y ∪ X :=\n  by\n  apply funext\n  intro f\n  rw [union]\n  rw [union]\n  rw [Or.comm]\n\ntheorem empty_inter {α :Type u} (a : Set α) : ∅ ∩ a = ∅ := by \n  rw [inter_comm]\n  apply inter_empty\n\ntheorem intersection_and {α : Type u} (X Y : Set α) (e:α) : (e ∈ (X ∩ Y)) = (e ∈ X ∧ e ∈ Y) := by rfl\n\ntheorem union_dist_intersection {α : Type u} (X Y Z : Set α) : X ∪ (Y ∩ Z) = (X ∪ Y) ∩ (X ∪ Z) := by\n  apply funext\n  intro x\n  rw [union, intersection]\n  repeat rw [element]\n  rw [union, union, intersection]\n  rw [Or.distrib_and]\n  rfl\n\ntheorem intersection_dist_union {α : Type u} (X Y Z : Set α) : X ∩ (Y ∪ Z) = (X ∩ Y) ∪ (X ∩ Z) := by\n  apply funext\n  intro x\n  rw [intersection, union]\n  repeat rw [element]\n  rw [union, intersection, intersection,And.distrib_or]\n  rfl\n\nend Set\n\n----------------------------------WORDS------------------------------------------\nstructure Word (α : Type u) where\n  data : List α\n  deriving Repr\n\ndef Word.concat {α : Type u} (x y : Word α) : Word α := {data := x.data ++ y.data}\ninfixr:70 \" ∘ \" => Word.concat\n\ndef Word.epsilon {α : Type u} : Word α := Word.mk List.nil\nnotation (priority := high) \"ε\" => Word.epsilon\n\ndef Word.len {α : Type u} (w:Word α) : Nat :=\n  match w with \n  | Word.mk List.nil => 0\n  | Word.mk (x::xs) => 1 + Word.len (Word.mk (xs))\n\ntheorem Word.objects_equal {α : Type u} (w :Word α): Word.mk w.data = w := by rfl \n\n@[simp] theorem Word.epsilon_eq_epsilon {α : Type u} : (@ε α)= (Word.mk List.nil) := by rfl \n\ndef Word.AllElementsOfWordInSet {α : Type u} (w: Word α) (S: Set α) :=\n  match w with \n  | Word.mk (a::as)=> a ∈ S ∧ Word.AllElementsOfWordInSet (Word.mk as) S\n  | _ => True\n\n----------------------------------LANGUAGES---------------------------------------\ndef Language (α : Type u) := Set (Word α)\n\ndef Language.concat {α : Type u} (X Y : Language α) : Language α := fun w : Word α => ∃ u v : Word α, u ∈ X ∧ v ∈ Y ∧ w = u ∘ v\ninfixr:70 \" ∘ₗ \" => Language.concat\n\ndef Language.epsilon {α:Type u} : Language α :=\n  fun w =>\n  match w with\n  | Word.mk List.nil => True\n  | Word.mk (_::_) => False\n\ndef Language.power {α : Type u} (n:Nat) (X: Language α) : Language α := \n  match n with\n  | 0 => \n    Language.epsilon\n  | (Nat.succ m) => \n    fun (w:Word α)=> \n      ∃ w1 w2 : Word α, w2 ∈ (Language.power m X) ∧ w1 ∈ X ∧ w = w1 ∘ w2\n\ndef Language.kleene {α :Type u} (X: Language α) : Language α :=\n  fun w: Word α =>\n    ∃ n : Nat, w ∈ Language.power n X\n\ndef Language.plus {α :Type u} (X :Language α) : Language α :=\n  fun w: Word α => ∃ n:Nat, ¬ (n = 0) ∧ w ∈ Language.power n X\n\ndef Sigma.language {α : Type u}: Language α := \n  fun w: Word α =>\n    match w with\n    | (Word.mk (_::[])) => True\n    | _ => False\n\ndef Sigma.kleene {α :Type u}: Language α :=\n  fun w: Word α => (@Language.kleene _ Sigma.language) w\n      \ndef Language.complement {α :Type u} (X: Language α) : Language α :=\n  fun w: Word α =>\n    ¬(w ∈ X)\n\n\ntheorem Lanuage.eps_element_only_element_in_eps_lang_il {α :Type u} (w : Word α) : Language.epsilon w -> w = {data := []} := by\nintro n\nrw [← Word.objects_equal w] at n\ncases h:w.data with\n| nil =>\n  rw [h] at n \n  rw [← Word.objects_equal w]\n  rw [h]\n| cons a as =>\n  rw [h] at n\n  simp [Language.epsilon] at n\n\ntheorem Language.eps_element_only_element_in_eps_lang {α :Type u} {w: Word α} : w ∈ Language.epsilon ↔ (w = Word.mk []) := by\nconstructor\nexact Lanuage.eps_element_only_element_in_eps_lang_il w\nintro n \nsimp [Set.element,n, Language.epsilon]\n\ntheorem Language.kleene_eq_plus_eps {α :Type u} {X: Language α} : Language.plus X ∪ Language.epsilon = Language.kleene X := by \n  apply funext\n  intro w\n  apply propext\n  constructor\n  intro x\n  simp [Set.union] at x\n  rw[Set.element] at x \n  rw [Language.kleene]\n  cases x with \n  |inl p => \n    rw [Language.plus] at p \n    cases p with\n    | intro n r =>\n      exists n \n      exact r.right \n  |inr e => \n    exists 0\n  intro n \n  rw [Set.union]\n  simp [Language.kleene] at n \n  cases n with \n  | intro nn r => \n    cases nn with \n    | succ m => \n      apply Or.inl \n      simp [Set.element, Language.plus]\n      exists (Nat.succ m)\n      rw [Set.element] at r\n      exact ⟨Nat.succ_ne_zero m, r⟩ \n    | zero => \n      apply Or.inr\n      simp [Set.element] at r\n      simp [Language.power] at r\n      simp [Set.element]\n      exact r \n\ntheorem Language.lan_eps_eq_lan {α : Type u} (L : Language α): L ∘ₗ Language.epsilon = L := by\n  apply funext\n  intro w\n  apply propext\n  constructor\n  rw [Language.concat]\n  intro ⟨u,v, h1, h2, h3⟩\n  rw [Word.concat] at h3\n  rw [Set.element] at h1\n  rw [Language.eps_element_only_element_in_eps_lang] at h2\n  simp [h2] at h3\n  rw [(Word.objects_equal u)] at h3\n  simp [*]\n  intro n \n  rw [Language.concat]\n  exists w \n  exists Word.mk []\n  apply And.intro \n  exact n \n  apply And.intro \n  rw [Set.element]\n  simp [Word.epsilon, Language.epsilon]\n  simp [Word.concat]\n\ntheorem Language.eps_lan_eq_lan {α : Type u} (L : Language α): Language.epsilon ∘ₗ L = L := by\n  apply funext\n  intro w\n  apply propext\n  constructor\n  rw [Language.concat]\n  intro ⟨u,v, h1, h2, h3⟩\n  rw [Word.concat] at h3\n  rw [Language.eps_element_only_element_in_eps_lang] at h1\n  simp [h2] at h3\n  rw [Set.element] at h2\n  simp [h1,Word.objects_equal] at h3\n  simp [*]\n  intro n \n  rw [Language.concat]\n  exists (Word.mk [])\n  exists w\n\ntheorem Language.empty_lan_eq_empty {α :Type u} (L : Language α) : L ∘ₗ ∅ = ∅ := by\n  apply Set.setext \n  intro w \n  constructor\n  intro n \n  rw [Set.element, Language.concat] at n \n  match n with \n  | ⟨u,v,_,h2,h3⟩ =>\n    rw [Set.element, Set.empty] at h2\n    apply False.elim h2 \n  intro n \n  rw [Set.element, Set.empty] at n\n  apply False.elim n \n\ntheorem Language.lan_empty_eq_empty {α :Type u} (L : Language α) : ∅ ∘ₗ L = ∅ := by\n  apply Set.setext \n  intro w \n  constructor\n  intro n \n  rw [Set.element, Language.concat] at n\n  match n with \n  | ⟨u,v, h1,h2,h3⟩ => \n    rw [Set.element, Set.empty] at h1\n    apply False.elim h1 \n  intro n \n  rw [Set.element, Set.empty] at n \n  apply False.elim n \n\ntheorem Language.concat_dist_union_r {α : Type u} (L1 L2 L3 : Language α) : (L1 ∪ L2) ∘ₗ L3 = (L1 ∘ₗ L3) ∪ (L2 ∘ₗ L3) := by\n  apply Set.setext \n  intro w \n  constructor \n  intro n \n  rw [Set.element, Language.concat] at n\n  match n with \n  | ⟨u,v,h1,h2,h3⟩ => \n    rw [Set.element,Set.union, Set.element]\n    rw [Set.element, Set.union] at h1\n    cases h1 with \n    | inl hl => \n      apply Or.inl\n      rw [Language.concat]\n      exists u\n      exists v \n    | inr hr =>\n      apply Or.inr \n      rw [Set.element, Language.concat]\n      exists u\n      exists v\n  intro n \n  rw [Set.element, Set.union] at n\n  cases n with \n  | inl hl =>\n    rw [Set.element, Language.concat]\n    rw [Set.element, Language.concat] at hl\n    match hl with \n    | ⟨u,v,h1,h2,h3⟩ =>\n      exists u\n      exists v \n      rw [Set.element,Set.union]\n      exact ⟨Or.inl h1, h2,h3⟩ \n  |inr hr => \n    rw [Set.element, Language.concat]\n    rw [Set.element, Language.concat] at hr \n    match hr with \n    | ⟨u,v,h1,h2,h3⟩ => \n      exists u\n      exists v\n      exact ⟨Or.inr h1, h2, h3⟩ \n      \ntheorem Language.morgan_union {α : Type u} (L1 L2 : Language α) : (L1 ∪ L2) = Language.complement (Language.complement L1 ∩ Language.complement L2):= by\n  apply Set.setext\n  intro w \n  repeat (first | rw [Set.element] | rw [Set.union] | rw [Set.intersection] | rw [Set.union] |rw [Language.complement] )\n  rw [← Or.morgan, not_not_p]constructor\n  repeat (first | intro n | exact n)\n\ntheorem Language.morgan_inter {α : Type u} (L1 L2: Language α) : (L1 ∩ L2) = Language.complement (Language.complement L1 ∪ Language.complement L2) := by \n  apply Set.setext \n  intro w \n  repeat (first | rw [Set.element] | rw [Set.union] | rw [Set.intersection] | rw [Set.union] |rw [Language.complement] )\n  rw [← And.morgan, not_not_p]\n  constructor\n  repeat (first | intro n | exact n)\n\ntheorem Language.concat_dist_union_l {α : Type u} (L1 L2 L3 : Language α) :\nL1 ∘ₗ (L2 ∪ L3) = (L1 ∘ₗ L2) ∪ (L1 ∘ₗ L3) :=\n  by\n    apply funext\n    intro w\n    apply propext\n    constructor\n\n    case mp =>\n      intro h\n      cases h with | intro u pu => cases pu with | intro v pv =>\n        rw [@And.comm (v ∈ (L2 ∪ L3)), ← And.assoc, Set.union_or, And.distrib_or] at pv\n\n        cases pv with\n        | inl _ =>\n          apply Or.inl\n          exists u, v\n          rw [@And.comm (v ∈ L2), ← And.assoc]\n          assumption\n        | inr _ =>\n          apply Or.inr\n          exists u, v\n          rw [@And.comm (v ∈ L3), ← And.assoc]\n          assumption\n\n    case mpr =>\n      intro h\n      cases h with\n        | inl hl => cases hl with | intro u pu => cases pu with | intro v pv =>\n          match pv with\n          | ⟨h1, h2, h3⟩ =>\n            exists u, v\n            exact ⟨h1, Or.inl h2, h3⟩\n        | inr hr => cases hr with | intro u pu => cases pu with | intro v pv =>\n          match pv with\n          | ⟨h1, h2, h3⟩ =>\n            exists u, v\n            exact ⟨h1, Or.inr h2, h3⟩\n\n@[simp] theorem eq_rfl {a : Type α} : (a = a) ↔ True := by simp[]\n  \n\n----------------------------------GRAMMARS---------------------------------------\nstructure Grammar {α : Type u} where\n  V : Set α \n  E : Set α \n  S: α \n  P : Set ((Word α) × (Word α))\n  bed_VEdisj : V ∩ E = ∅\n  bed_SinV: S ∈ V \n  bed_VarInLeft: \n    ∀ pair : (Word α) × (Word α),\n    P pair -> (\n      ∃ v1 v2 v3 : Word α, \n        ((pair.fst) = (v1 ∘ v2 ∘ v3)) ∧ \n        (∃ t: α, (Word.mk ([t]) = v2 ∧ t ∈ V))\n   )\n\nstructure RegularGrammar {α : Type u} extends (@Grammar α) where\n  bed_reg: ∀ pair : ((Word α) × (Word α)), \n    (pair ∈ P) -> \n    (\n      (∃ t: α, (Word.mk [t] = pair.fst) ∧ t ∈ V) ∧ (\n        (∃ t1 t2 : α, (Word.mk [t1, t2] = pair.snd) ∧ t1 ∈ E ∧ t2 ∈ V) ∨ \n        (∃ t: α, Word.mk [t] = pair.snd ∧ t ∈ E) ∨ \n        pair.snd = Word.mk []\n     )\n   )\n\nstructure EpsilonFreeRegularGrammar {α : Type u} extends (@RegularGrammar α) where\n  epsilonFree : ∀ pair : (Word α) × (Word α), \n  ¬ (pair ∈ P) ∨ (\n    pair.fst = Word.mk ([S]) ∨ ¬ (pair.snd = Word.epsilon)\n )\n\ndef OneStepDerivation {α : Type u} (G : @Grammar α) (w : Word α) (v : Word α) : Prop :=\n    ∃ w1 w2 w3: Word α,\n      ∃ v1 v2 v3: Word α,\n      have p1 := w = w1 ∘ w2 ∘ w3\n      have p2 := v = v1 ∘ v2 ∘ v3\n      (v1 = w1) ∧ (v3 = w3) ∧ p1 ∧ p2 ∧ G.P ⟨w2, v2⟩\n        \ndef NstepDerivation {α : Type u} (G : @Grammar α) (w : Word α) (v : Word α) (n:Nat) : Prop :=\n  match n with\n  | 0 => \n    w = v\n  | (Nat.succ m) => \n      ∃ w1 : Word α, (OneStepDerivation G w w1) ∧ (NstepDerivation G w1 v m) ∧ (Word.AllElementsOfWordInSet v G.E)\n\ndef StarDerivation {α : Type u} (G : @Grammar α) (w : Word α) (v : Word α) : Prop :=\n  ∃ n : Nat, NstepDerivation G w v n\n  \ndef GeneratedLanguageGrammar {α : Type u} (G : @Grammar α): Language α :=\n  fun w: Word α => \n    StarDerivation G (Word.mk [G.S]) w\n\ndef RunRegularGrammarSub {α : Type u} (ql qg : α) (G : @RegularGrammar α) (run: List (Word α × Word α))(w : Word α) : Prop :=\n    match w with \n    | (Word.mk (word::ws1)) =>\n      match run with \n      | (p1::xs) =>\n          p1 ∈ G.P ∧ \n          p1.fst = (Word.mk [ql]) ∧ \n          (∃ t1 : α, (Word.mk [word, t1] = p1.snd)\n                  ∧ RunRegularGrammarSub t1 qg G xs (Word.mk ws1) \n           )\n      | _ => False \n    | _ => \n      ql = qg\n\ndef LanguageRegularGrammar {α : Type u} (G : @RegularGrammar α) : Language α :=\n  fun w => ∃ qn run, (RunRegularGrammarSub G.S qn G run w ∧ ⟨Word.mk [qn], Word.mk []⟩ ∈ G.P\n    ∨ ∃ w1, ∃ z : α, (w = w1 ∘ Word.mk [z]) ∧ RunRegularGrammarSub G.S qn G run w1 ∧ ⟨Word.mk [qn], Word.mk [z]⟩ ∈ G.P)\n\n----------------------------------AUTOMATA------------------------------------------\nstructure NFA {α : Type u} where \n  Q : Set α \n  E : Set α \n  δ : Set ((α × α) × α)\n  Q0 : Set α \n  F: Set α\n  QEdisj: Q ∩ E = ∅ \n  Q0subset: Q0 ⊆ Q \n  Fsubset: F ⊆ Q\n  Tfunction: \n    ∀ t : ((α × α) × α),\n       ¬ (t ∈ δ) ∨ (\n          t.fst.fst ∈ Q ∧ \n          t.fst.snd ∈ E ∧ \n          t.snd ∈ Q\n      ) \n  \nstructure DFA {α : Type u} extends (@ NFA α) where \n  q0 : α \n  bed_Q0:\n  (Q0 = \n    (fun a : α => \n       (q0 = a)\n     )\n ) \n  uniqueness:\n      ∀ t1 t2 : ((α × α) × α),\n       ¬ ((t1 ∈ δ) ∧ (t2 ∈ δ)) ∨ \n        (¬ (t1.fst = t2.fst) ∨ t1.snd = t2.snd)\n\ndef nfaDerivation {α : Type u} (nfa: @ NFA α) (q1 qf: α) (w: Word α) : Prop :=\n  match w with \n  | Word.mk (x::xs) => ∃ qn, nfa.δ ⟨⟨q1, x⟩,qn⟩ ∧ nfaDerivation nfa qn qf (Word.mk xs) \n  | Word.mk [] => q1 = qf\n\ndef nfaLanguage {α : Type u} (nfa: @ NFA α) : Language α :=\n  fun w => ∃ qs qf, qs ∈ nfa.Q0 ∧ qf ∈ nfa.F ∧ nfaDerivation nfa qs qf w\n\nstructure TotalDFA {α : Type u} extends (@ DFA α) where \n  tot: ∀ t : ((α × α) × α),\n  (¬ (t.fst.snd ∈ E ∧ t.fst.fst ∈ Q) ∨ \n    ∃ q2 : α, ⟨⟨t.fst.fst, t.fst.snd⟩, q2⟩ ∈ δ\n )\n\ndef TotalDFAConstruct {α : Type u} (dfa: @ DFA α) (fang: α) (p1: ¬fang ∈ dfa.Q ∧ ¬fang ∈ dfa.E) : @TotalDFA α :=\n  let Q2: Set α := fun w => (w ∈ dfa.Q) ∨ (w=fang) \n  let δ2: Set ((α × α) × α) := fun ⟨⟨w1, w2⟩, w3⟩ => ⟨⟨w1, w2⟩, w3⟩ ∈ dfa.δ ∨ (¬ (∃ a : α,⟨⟨w1, w2⟩, a⟩ ∈ dfa.δ)∧ Q2 w1 ∧ dfa.E w2 ∧ w3 = fang)\n  \n  have delta_def_rfl : (fun ⟨⟨w1, w2⟩, w3⟩ => ⟨⟨w1, w2⟩, w3⟩ ∈ dfa.δ ∨ (¬ (∃ a : α,⟨⟨w1, w2⟩, a⟩ ∈ dfa.δ)∧ Q2 w1 ∧ dfa.E w2 ∧ w3 = fang)) = δ2 := \n    by rfl\n\n  have Q2_def_rfl : ((fun w => (w ∈ dfa.Q) ∨ (w=fang)): (Set α)) = Q2 := \n    by rfl\n\n  have setEmpty_rfl : Set.empty = (fun _ => False) := by rfl\n\n  have QSubsetQ2: (dfa.Q ⊆ Q2) := by\n    intro n\n    intro w \n    simp [Set.element]\n    apply Or.inl \n    exact w\n\n  have Q2Edisj : Q2 ∩ dfa.E = Set.empty:= by\n    rw [setEmpty_rfl]\n    simp [Set.intersection]\n    apply funext\n    intro x\n    simp [And.distrib_or, Set.element]\n    have hq := dfa.QEdisj\n    simp [Set.intersection, setEmpty_rfl] at hq\n    have hp : ((fun e => e ∈ dfa.Q ∧ e ∈ dfa.E) = fun _ => False) → (∀e : α, (e ∈ dfa.Q ∧ e ∈ dfa.E) = False):= by\n      intro _\n      intro n\n      rw [←Set.intersection, dfa.QEdisj, Set.empty]\n    have hl := hp hq\n    have hll := hl x\n    simp [Set.element] at hll\n    rw [And.comm] at hll\n    simp [Set.intersection, Set.element]\n    cases (Classical.em (x = fang)) with \n    | inl xfang => \n      have p2 := p1.right\n      simp [xfang]\n      have hv : dfa.E fang ↔ False := by\n        constructor\n        intro x\n        apply p2\n        rw [Set.element]\n        exact x\n        intro x\n        apply False.elim x\n      simp [hv]\n    | inr xNotFang =>\n      simp [xNotFang]\n      apply propext \n      constructor \n      intro x1\n      rw [And.comm, hll] at x1\n      exact x1\n      intro x\n      apply False.elim x\n\n  have Q0SubsetQ2: (dfa.Q0 ⊆ Q2) := by\n    have dfa_subset := dfa.Q0subset\n    simp [Set.subset]\n    intro n \n    have hl := QSubsetQ2\n    rw [Set.subset] at hl \n    have hll := hl n \n    rw [Set.subset] at dfa_subset\n    have hrr := dfa_subset n \n    intro x \n    exact hll (hrr x)\n\n  have FSubsetQ2: (dfa.F ⊆ Q2) := by\n    have dfa_subset := dfa.Fsubset\n    simp [Set.subset]\n    intro n \n    have hl := QSubsetQ2\n    rw [Set.subset] at hl \n    have hll := hl n \n    rw [Set.subset] at dfa_subset\n    have hrr := dfa_subset n \n    intro x \n    exact hll (hrr x)\n\n  have Tfunction2: (∀ t : ((α × α) × α),\n       ¬ (t ∈ δ2) ∨ (\n          t.fst.fst ∈ Q2 ∧ \n          t.fst.snd ∈ dfa.E ∧ \n          t.snd ∈ Q2\n      )) := by\n       intro triple\n       rw [not_or_eq_implication]\n       intro triple_in_delta2\n       have triple_in_delta2_old := triple_in_delta2\n       rw [Set.element,←delta_def_rfl] at triple_in_delta2\n       match triple with \n       | ⟨⟨qs,b⟩, qz⟩ => \n          have hsorry2 : ⟨⟨qs, b⟩, qz⟩ ∈ dfa.toNFA.δ ∨ ((¬ (∃ a : α,⟨⟨qs, b⟩, a⟩ ∈ dfa.δ))∧ Q2 qs ∧ NFA.E dfa.toNFA b ∧  (qz = fang)) := by \n            simp [Set.element, ← delta_def_rfl] at triple_in_delta2\n            exact triple_in_delta2\n          have hsorry : ⟨⟨qs, b⟩, qz⟩ ∈ dfa.toNFA.δ ∨ (Q2 qs ∧ NFA.E dfa.toNFA b ∧ (qz = fang)):= by \n            apply Or.elim hsorry2\n            intro x \n            apply Or.inl\n            exact x\n            intro x \n            apply Or.inr \n            simp [x]\n          simp[Set.element]\n          have dfa_tfun := dfa.Tfunction\n          have dfa_tfun_w := dfa_tfun ⟨⟨qs, b⟩, qz⟩ \n          simp [Set.element] at dfa_tfun_w \n          repeat rw [←Set.element] at dfa_tfun_w\n          simp [not_or_eq_implication] at dfa_tfun_w\n          have k1 : Q2 qs := by\n            cases (Classical.em (dfa.δ ⟨⟨qs,b⟩, qz⟩)) with \n            | inl hl =>\n                have dfa_tfun_conjunctions := dfa_tfun_w hl\n                have kk1 := dfa_tfun_conjunctions.left\n                apply QSubsetQ2\n                rw [Set.element]\n                exact kk1\n            | inr hr =>\n              apply Or.elim (hsorry)\n              intro f\n              apply False.elim (hr f)\n              intro rdef\n              have g := rdef.left\n              exact g\n          have k2 : dfa.E b := by\n            cases (Classical.em (dfa.δ ⟨⟨qs,b⟩, qz⟩)) with \n            | inl hl =>\n              have dfa_tfun_conjunctions := dfa_tfun_w hl\n              have kk1 := dfa_tfun_conjunctions.right.left\n              exact kk1\n            | inr hr =>\n              apply Or.elim (hsorry)\n              intro f\n              apply False.elim (hr f)\n              intro rdef\n              have g := rdef.right.left\n              exact g\n          have k3: Q2 qz := by\n            cases (Classical.em (dfa.δ ⟨⟨qs,b⟩, qz⟩)) with \n            | inl hl =>\n              have dfa_tfun_conjunctions := dfa_tfun_w hl\n              have kk1 := dfa_tfun_conjunctions.right.right\n              apply QSubsetQ2\n              exact kk1\n            | inr hr =>\n              apply Or.elim (hsorry)\n              intro f\n              apply False.elim (hr f)\n              intro rdef\n              have gh := rdef.right.right\n              rw [gh]\n              have q2_fang : Q2 fang := by\n                rw [← Q2_def_rfl]\n                have hqq : (fun w => w ∈ dfa.toNFA.Q ∨ w = fang) fang = (fang ∈ dfa.toNFA.Q ∨ fang = fang) := by rfl\n                rw [hqq]\n                apply Or.inr\n                have aea : fang = fang := by rfl\n                exact aea \n              exact q2_fang\n          exact ⟨k1, k2, k3⟩\n\n  have tot2: ∀ t : ((α × α) × α),\n  (¬ (t.fst.snd ∈ dfa.E ∧ t.fst.fst ∈ Q2) ∨ \n    ∃ q2 : α, ⟨⟨t.fst.fst, t.fst.snd⟩, q2⟩ ∈ δ2\n ):= by \n        intro triple\n        match triple with \n       | ⟨⟨qs,b⟩, qz⟩ => \n          simp [not_or_eq_implication]\n          intro x\n          simp [Set.element, ← delta_def_rfl]\n          cases (Classical.em (∃y, dfa.δ ⟨⟨qs,b⟩, y⟩)) with \n          | inl hl =>\n            match hl with \n            | ⟨y, hy⟩ => \n              exists y \n              apply Or.inl \n              exact hy \n          | inr hr => \n            exists fang\n            have hfang : fang = fang := rfl \n            apply Or.inr \n            exact ⟨hr, x.right, x.left, hfang⟩\n\n  have uniqueness2 :\n      ∀ t1 t2 : ((α × α) × α),\n       ¬ ((t1 ∈ δ2) ∧ (t2 ∈ δ2)) ∨ \n        (¬ (t1.fst = t2.fst) ∨ t1.snd = t2.snd) := by \n        intro triple1\n        intro triple2 \n        rw [not_or_eq_implication]\n        intro bed1\n        rw [not_or_eq_implication]\n        intro bed2 \n        simp[] at bed2 \n        have bed11 := bed1.left \n        have bed12 := bed1.right\n        have dfa_uniqueness := dfa.uniqueness triple1 triple2\n        repeat rw [not_or_eq_implication] at dfa_uniqueness\n        match triple1 with \n        | ⟨first1, qz1⟩ => \n          match triple2 with \n          |⟨first2, qz2⟩ => \n            simp [] at bed2\n            simp [Set.element] at dfa_uniqueness\n            simp [Set.element, ← delta_def_rfl] at bed11\n            simp [bed2, Set.element, ← delta_def_rfl] at bed12\n            simp []\n            cases bed11 with \n            | inl hl1 =>\n              cases bed12 with \n              | inl hl2 =>\n                exact dfa_uniqueness ⟨hl1, hl2⟩ bed2 \n              | inr hr2 => \n                rw [bed2] at hl1\n                have hNEtransition := hr2.left\n                have exa :∃ a, dfa.δ ⟨first2,a⟩ := by\n                  exists qz1\n                have hfalse := hNEtransition exa\n                apply False.elim hfalse\n            | inr hr1 => \n              cases bed12 with \n              | inl hl1 =>\n                have hNEtransition := hr1.left\n                rw [← bed2] at hl1\n                have exa :∃ a, dfa.δ ⟨first1,a⟩ := by\n                  exists qz2\n                have hfalse := hNEtransition exa\n                apply False.elim hfalse\n \n              | inr hr2 => \n                have h_right := hr1.right.right.right\n                have h_left := hr2.right.right.right\n                simp [h_left, h_right]\n\n    {tot := tot2, uniqueness := uniqueness2, Tfunction := Tfunction2, Q0 := dfa.Q0, Q:= Q2, E := dfa.E, δ := δ2, QEdisj := Q2Edisj, F := dfa.F, Q0subset := Q0SubsetQ2, Fsubset := FSubsetQ2, q0 := dfa.q0, bed_Q0 := dfa.bed_Q0 : TotalDFA}\n\n\n----------------------------------GRAMMARS & AUTOMATA------------------------------\ndef ConstructRegularGrammarFromDFA {α : Type u} (dfa: @ DFA α) : @RegularGrammar α:= \n  let E : Set α := dfa.E\n  have E_def_refl : E = dfa.E := by rfl\n  \n  let V : Set α := dfa.Q\n  have V_def_refl : V = dfa.Q := by rfl\n  \n  let S : α := dfa.q0\n  have S_def_refl : S = dfa.q0 := by rfl\n  \n  let P : Set ((Word α) × (Word α)) := \n    fun rule : (Word α) × (Word α) => \n      (∃ql a qr : α, rule.fst = Word.mk [ql] ∧ rule.snd = Word.mk [a] ∘ Word.mk [qr] ∧ ⟨⟨ql,a⟩,qr⟩ ∈ dfa.δ)\n      ∨ (∃ q, rule.fst = Word.mk [q] ∧ rule.snd = Word.epsilon ∧ (q ∈ dfa.F))\n  have P_def_refl : P = fun rule : (Word α) × (Word α) => \n      (∃ql a qr : α, rule.fst = Word.mk [ql] ∧ rule.snd = Word.mk [a] ∘ Word.mk [qr] ∧ ⟨⟨ql,a⟩,qr⟩ ∈ dfa.δ)\n      ∨ (∃ q, rule.fst = Word.mk [q] ∧ rule.snd = Word.epsilon ∧ (q ∈ dfa.F)) := by rfl\n  \n  have bed_VEdisj : V ∩ E = ∅ := by\n    have QEdisj := dfa.QEdisj\n    simp [E_def_refl, V_def_refl]\n    exact QEdisj\n  \n  have bed_SinV: S ∈ V := by\n    simp [S_def_refl, V_def_refl, Set.element]\n    have q0inQ0 : dfa.q0 ∈ dfa.Q0 := by \n      simp [Set.element]\n      have bed_Q0 := dfa.bed_Q0\n      rw [bed_Q0]\n    have q0inQ := dfa.Q0subset dfa.q0 q0inQ0\n    rw [Set.element] at q0inQ\n    exact q0inQ \n  \n  have bed_VarInLeft: \n    ∀ pair : (Word α) × (Word α),\n    P pair -> (\n      ∃ v1 v2 v3 : Word α, \n        ((pair.fst) = (v1 ∘ v2 ∘ v3)) ∧ \n        (∃ t: α, (Word.mk ([t]) = v2 ∧ t ∈ V))\n   ) := by\n    intro pair\n    intro pairInP\n    simp [P_def_refl] at pairInP\n    cases pairInP with \n    | inl disj1 => \n      match disj1 with\n      | ⟨ql, a, qr, disj1woE⟩ => \n        exists Word.mk []\n        exists Word.mk [ql]\n        exists Word.mk []\n        simp [Word.concat]\n        have k1 := disj1woE.left\n        have k2 : ∃ t, t = ql ∧ t ∈ V := by\n          exists ql\n          simp []\n          have disj3 := disj1woE.right.right\n          rw [Set.element] at disj3\n          have Tfunction := dfa.Tfunction\n          have Tfunction2 := Tfunction ⟨⟨ql, a⟩,qr⟩\n          rw [not_or_eq_implication] at Tfunction2\n          have Tfunction3 := Tfunction2 disj3\n          simp [] at Tfunction3\n          have Tfunction31 := Tfunction3.left\n          exact Tfunction31\n        have k1Andk2 := And.intro k1 k2\n        exact k1Andk2\n    | inr disjB => \n        match disjB with\n        | ⟨q, disjB2⟩ =>\n\n          exists Word.mk []\n          exists Word.mk [q]\n          exists Word.mk []\n          simp [Word.concat]\n          have k2 : ∃ t, t = q ∧ t ∈ dfa.toNFA.Q := by\n            exists q\n            have qInQ : q ∈ dfa.Q := by\n              have FsbQ := dfa.Fsubset\n              have qInQ2 := FsbQ q disjB2.right.right \n              exact qInQ2\n            simp [qInQ]\n          simp [disjB2.left, k2]\n  have bed_reg: ∀ pair : ((Word α) × (Word α)), \n    (pair ∈ P) -> \n    (\n      (∃ t: α, (Word.mk [t] = pair.fst) ∧ t ∈ V) ∧ (\n        (∃ t1 t2 : α, (Word.mk [t1, t2] = pair.snd) ∧ t1 ∈ E ∧ t2 ∈ V) ∨ \n        (∃ t: α, Word.mk [t] = pair.snd ∧ t ∈ E) ∨ \n        pair.snd = Word.mk []\n     )\n   ) := by \n      intro pair\n      intro pairInP\n      simp [P_def_refl] at pairInP\n      cases pairInP with \n      | inl disj1 => \n        match disj1 with\n        | ⟨ql, a, qr, disj1woE⟩ => \n          simp [Word.concat]\n          have k1 : ∃ t, t = ql ∧ t ∈ V := by\n            exists ql\n            simp []\n            have disj3 := disj1woE.right.right\n            rw [Set.element] at disj3\n            have Tfunction := dfa.Tfunction\n            have Tfunction2 := Tfunction ⟨⟨ql, a⟩,qr⟩\n            rw [not_or_eq_implication] at Tfunction2\n            have Tfunction3 := Tfunction2 disj3\n            simp [] at Tfunction3\n            have Tfunction31 := Tfunction3.left\n            exact Tfunction31\n          have k2 : ∃ t1 t2 : α, (Word.mk [t1, t2] = pair.snd) ∧ t1 ∈ E ∧ t2 ∈ V := by\n            exists a\n            exists qr\n            simp [Word.concat] at disj1woE\n            have k21 := disj1woE.right.left\n            have Tfunction := dfa.Tfunction\n            have k22 : a ∈ E ∧ qr ∈ V := by\n              have pInQ := disj1woE.right.right\n              have Tfunction2 := Tfunction ⟨⟨ql, a⟩,qr⟩\n              rw [not_or_eq_implication] at Tfunction2\n              have Tfunction3 := Tfunction2 pInQ\n              simp [] at Tfunction3\n              have Tfunction31 := Tfunction3.right\n              rw [V_def_refl, E_def_refl]\n              simp [Tfunction31]\n            simp [k21, k22]\n          simp [k2]\n          exists ql\n          simp [disj1woE.left]\n          match k1 with \n          | ⟨qrr, k1woE⟩ =>\n          simp [←k1woE.left]\n          exact k1woE.right\n      | inr disjB =>\n          match disjB with\n          | ⟨q, disjB2⟩ =>\n            have k1 : (∃ t, {data := [t]} = pair.fst ∧ t ∈ V) := by\n              exists q\n              have qInQ : q ∈ dfa.Q := by\n                have FsbQ := dfa.Fsubset\n                have qInQ2 := FsbQ q disjB2.right.right \n                exact qInQ2\n              simp [qInQ, disjB2.left]\n            have k2: ((∃ t1 t2, {data := [t1, t2]} = pair.snd ∧ t1 ∈ E ∧ t2 ∈ V) ∨ (∃ t, {data := [t]} = pair.snd ∧ t ∈ E) ∨ pair.snd = {data := []}) := by\n              apply Or.inr\n              apply Or.inr\n              simp [disjB2.right]\n            simp [k1, k2]\n\n    {V := V, E := E, S := S, P := P, bed_VEdisj := bed_VEdisj, bed_SinV := bed_SinV, bed_VarInLeft := bed_VarInLeft, bed_reg := bed_reg : RegularGrammar}\n       \ntheorem deriviationsEQ1 {α : Type u} (dfa: @ DFA α)(w: Word α) : \n     ∀ q1 q2 :α, (nfaDerivation dfa.toNFA q1 q2 w) -> (\n      (∃ run, RunRegularGrammarSub q1 q2 (ConstructRegularGrammarFromDFA dfa) run w)):= by\n  have hp := Word.objects_equal w \n  rw [← hp] \n  induction w.data with\n  | nil => \n    intro q1\n    intro q2\n    intro deriviation \n    simp [nfaDerivation] at deriviation \n    exists []\n  | cons x xs iv => \n    intro q11\n    intro q22\n    intro deriviation \n    simp [nfaDerivation] at deriviation\n    match deriviation with\n    | ⟨qn, abl1⟩ =>\n      have hh := iv qn q22 abl1.right \n      simp [Word.concat]\n      match hh with \n      | ⟨run, hhz1⟩ =>\n        exists ⟨Word.mk [q11], Word.mk [x,qn]⟩::run\n        simp [Word.concat]\n        simp [RunRegularGrammarSub]\n        have hll : ∃ t1, (t1 = qn) ∧ (RunRegularGrammarSub t1 q22 (ConstructRegularGrammarFromDFA dfa) run {data := xs}) := \n          by exists qn\n        simp [hll]\n        have inDelta := abl1.left\n        simp [Set.element, ConstructRegularGrammarFromDFA]\n        apply Or.inl\n        exists q11 \n        exists x \n        exists qn\n\ntheorem notExistsEqAllSpecial : (¬∃ (runx : Word α × Word α) (runxs : List (Word α × Word α)), run2 = runx::runxs) → ∀ (runx : Word α × Word α) (runxs : List (Word α × Word α)), ¬run2 = runx::runxs := by\n  intro h1\n  intro h2\n  intro h3\n  intro ab\n  have existsS : ∃ (runx : Word α × Word α) (runxs : List (Word α × Word α)), run2 = runx::runxs := by \n    exists h2 \n    exists h3\n  exact h1 existsS\n\ntheorem deriviationsEQ2 {α : Type u} (dfa: @ DFA α) (w: Word α) : \n     ∀ q1 q2,(∃ run,\n      (RunRegularGrammarSub q1 q2 (ConstructRegularGrammarFromDFA dfa) run w))-> (nfaDerivation dfa.toNFA q1 q2 w) := by\n  have hp := Word.objects_equal w \n  rw [← hp] \n  induction w.data with\n  | nil => \n    intro q1\n    intro q2\n    intro runex\n    match runex with \n    | ⟨run, runwo⟩ =>\n      simp [RunRegularGrammarSub] at runwo \n      simp [nfaDerivation, runwo]\n  | cons x xs iv => \n    intro q11\n    intro q22\n    intro runex\n    match runex with \n    | ⟨run2, runwo⟩ =>\n      cases (Classical.em (∃ runx runxs, run2 = runx::runxs)) with \n      | inl runwoH =>\n        match runwoH with \n        | ⟨runx, runxs, runwoH2⟩ =>\n          simp [runwoH2, RunRegularGrammarSub] at runwo \n          simp [nfaDerivation]\n          have runwo2 := runwo.right.right \n          match runwo2 with\n          | ⟨qn, runwo3⟩ =>\n            exists qn\n            have runwo4ex : ∃ run, RunRegularGrammarSub qn q22 (ConstructRegularGrammarFromDFA dfa) run {data := xs} := by\n              exists runxs \n              exact runwo3.right\n            have iv2 := iv qn q22 runwo4ex\n            simp [iv2]\n            have pinG := runwo.left\n            have runFirst := runwo.right.left \n            have runRight := runwo3.left\n            simp [Set.element, ConstructRegularGrammarFromDFA] at pinG \n            cases pinG with \n            | inl hll =>\n              match hll with \n              | ⟨q_1, w_1, q_r, pingnoE⟩ => \n                simp [Word.concat, runFirst, ←runRight] at pingnoE\n                simp [pingnoE]\n            | inr hrr =>\n              match hrr with\n              | ⟨q, hrr2⟩ =>\n                have falseelimarg := hrr2.right.left\n                simp [← runRight] at falseelimarg\n      | inr hnexrun => \n        have runeqempty : run2 = [] := by\n          apply EmptyNotFull\n          have hn : (¬∃ runx runxs, run2 = runx::runxs) → (∀ runx runxs, ¬(run2 = runx::runxs)) := by\n            intro h\n            apply notExistsEqAllSpecial\n            exact h\n          apply hn\n          exact hnexrun\n        simp [runeqempty] at runwo\n        simp [RunRegularGrammarSub] at runwo\n\ntheorem languageDFAeqConstructedRegularGrammar2 {α : Type u} (dfa : @DFA α) : (@nfaLanguage α dfa.toNFA) = (@LanguageRegularGrammar α (ConstructRegularGrammarFromDFA dfa)) := by \n  apply Set.setext\n  intro w\n  apply Iff.intro\n  intro wInNFALanguage\n  simp [Set.element, nfaLanguage] at wInNFALanguage\n  match wInNFALanguage with\n  | ⟨qs, qn, wInNFALanguage2⟩ =>\n    simp [Set.element, LanguageRegularGrammar]\n    exists qn\n    have runExists := deriviationsEQ1 dfa w qs qn wInNFALanguage2.right.right\n    match runExists with\n    | ⟨run, runExists2⟩ =>\n      exists run \n      have qsEqConstructedGrammarS : (ConstructRegularGrammarFromDFA dfa).toGrammar.S = qs := by\n        simp [ConstructRegularGrammarFromDFA]\n        have bedQ0 := dfa.bed_Q0\n        have h := wInNFALanguage2.left\n        rw [bedQ0] at h\n        exact h\n      rw [qsEqConstructedGrammarS]\n      simp [runExists2]\n      have qnToEpsilon : Grammar.P (ConstructRegularGrammarFromDFA dfa).toGrammar ({data := [qn]}, {data := []}) := by\n        have qnInF := wInNFALanguage2.right.left\n        simp [ConstructRegularGrammarFromDFA] \n        apply Or.inr\n        exists qn\n      simp [qnToEpsilon]\n  intro wInGrammarLanguage\n  simp [Set.element, LanguageRegularGrammar] at wInGrammarLanguage\n  match wInGrammarLanguage with\n  | ⟨qn, run, wInGrammarLanguage2⟩ =>\n    have kfalse : (∃ w1 z,\n    w = w1 ∘ {data := [z]} ∧\n      RunRegularGrammarSub (ConstructRegularGrammarFromDFA dfa).toGrammar.S qn (ConstructRegularGrammarFromDFA dfa)\n          run w1 ∧\n        Grammar.P (ConstructRegularGrammarFromDFA dfa).toGrammar ({data := [qn]}, {data := [z]})) -> False := by\n      \n      intro kfalse2\n      match kfalse2 with\n      | ⟨w1, z, kfalse3⟩ =>\n        have kfalse4 := kfalse3.right.right \n        simp [ConstructRegularGrammarFromDFA] at kfalse4\n        cases (kfalse4) with\n        | inl hl =>\n          match hl with\n          | ⟨ql, a, qr, hl2⟩ =>\n            have hl3 := hl2.right.left\n            simp [Word.concat] at hl3 \n        | inr hr => \n          match hr with\n          | ⟨_, hr2⟩ =>\n            exact hr2\n    cases (wInGrammarLanguage2) with \n    | inl hl =>\n      simp [Set.element, nfaLanguage]\n      have bed : (∃ run, (RunRegularGrammarSub (ConstructRegularGrammarFromDFA dfa).toGrammar.S qn (ConstructRegularGrammarFromDFA dfa) run  w)) := by\n        exists run\n        simp [hl.left]\n      have q2 := deriviationsEQ2 dfa w (ConstructRegularGrammarFromDFA dfa).toGrammar.S qn bed\n      exists (ConstructRegularGrammarFromDFA dfa).toGrammar.S \n      exists qn\n      simp [q2]\n      simp [ConstructRegularGrammarFromDFA]\n      have hlr := hl.right\n      simp [ConstructRegularGrammarFromDFA] at hlr\n      cases hlr with\n      | inl hl5 =>\n        match hl5 with \n        | ⟨ql, a, qr, hl51⟩ => \n          have q0InQ0 := dfa.bed_Q0\n          rw [q0InQ0]\n          simp [hl51.left]\n          have hfalse := hl51.right.left\n          simp [Word.concat] at hfalse\n      | inr hl6 =>\n        match hl6 with\n        | ⟨qz, hl7⟩ => \n          rw [Set.element] at hl7\n          simp [hl7.left, hl7.right]\n          have q0InQ0 := dfa.bed_Q0\n          rw [q0InQ0]\n    | inr hr =>\n      have kfalse2 := kfalse hr\n      apply False.elim\n      exact kfalse2\n    ", "meta": {"author": "knowsys", "repo": "Formale-Systeme-in-LEAN", "sha": "5e7a8fe205ac0ee4c7abe472c2534f4d4660561f", "save_path": "github-repos/lean/knowsys-Formale-Systeme-in-LEAN", "path": "github-repos/lean/knowsys-Formale-Systeme-in-LEAN/Formale-Systeme-in-LEAN-5e7a8fe205ac0ee4c7abe472c2534f4d4660561f/Main.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7844693411801332}}
{"text": "-- Suma_constante_es_inyectiva.lean\n-- Para todo c ∈ ℝ, la función f(x) = x+c es inyectiva.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 22-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que, para todo c la función\n--    f(x) = x + c\n-- es inyectiva\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nopen function\n\nvariable {c : ℝ}\n\n-- 1ª demostración\n-- ===============\n\nexample : injective (λ x, x + c) :=\nbegin\n  assume x1 : ℝ,\n  assume x2 : ℝ,\n  assume h1 : (λ x, x + c) x1 = (λ x, x + c) x2,\n  have h2 : x1 + c = x2 + c := h1,\n  show x1 = x2,\n    by exact (add_left_inj c).mp h2,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : injective (λ x, x + c) :=\nbegin\n  intros x1 x2 h,\n  change x1 + c = x2 + c at h,\n  apply add_right_cancel h,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : injective (λ x, x + c) :=\nbegin\n  intros x1 x2 h,\n  apply (add_left_inj c).mp,\n  exact h,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample : injective (λ x, x + c) :=\nλ x1 x2 h, (add_left_inj c).mp h\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_constante_es_inyectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7844693408163519}}
{"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.separable\nimport ring_theory.trace\nimport ring_theory.norm\n\n/-\n\n# Separable extensions\n\nWith infinite fields of characteristic `p`, weird things can happen with extensions, where\nan irreducible polynomial can pick up repeated roots in an extension. A separable extension\nis an extension where this pathology isn't occurring. Note that in examples like extensions\nof number fields, this never happens, because number fields are characteristic zero.\n\n\n-/\n\n-- Let E ⊆ F be a field extension\nvariables (E F : Type) [field E] [field F] [algebra E F]\n\nsection separable_assumption\n\n-- Here's how you say it's separable\nvariable [is_separable E F]\n\n-- Separable extensions are algebraic by definition in Lean\nexample (f : F) : is_algebraic E f :=\nbegin\n  apply is_integral.is_algebraic, -- suffices to prove f is integral over E\n  apply is_separable.is_integral, -- follows from separability\nend\n\nend separable_assumption\n\n-- finite-dimensional char 0 extensions are separable\nexample [finite_dimensional E F] [char_zero E] :\n  is_separable E F := infer_instance -- typeclass inference can solve this as everything's a typeclass!\n\n-- In the separable case, the minimum polynomial of `f : F` is guaranteed to have distinct roots in\n-- a splitting field, and we can define traces and norms as sums or products of conjugates.\n-- Let `Ω` be an algebraically closed extension of `E` (note: `Ω` doesn't have to contain `F`)\n\nvariables (Ω : Type) [field Ω] [algebra E Ω] [is_alg_closed Ω]\n\nopen_locale big_operators\n\nexample [is_separable E F] [finite_dimensional E F] (f : F) : \n  algebra_map E Ω (algebra.norm E f) = ∏ σ : F →ₐ[E] Ω, σ f := \nalgebra.norm_eq_prod_embeddings E Ω\n\nexample [is_separable E F] [finite_dimensional E F] (f : F) :\n  algebra_map E Ω (algebra.trace E F f) = ∑ σ : F →ₐ[E] Ω, σ f := \ntrace_eq_sum_embeddings Ω\n\n-- Note the inconsistencies in both `algebra.trace/norm` inputs \n-- and `trace/norm_eq_sum/prod_embeddings` inputs. \n\n-- Now say we have a tower E ⊆ F ⊆ K\nvariables (K : Type) [field K] [algebra E K] [algebra F K] [is_scalar_tower E F K]\n\n-- If the big extension is separable then so are the two smaller ones\nexample [is_separable E K] : is_separable E F := is_separable_tower_bot_of_is_separable E F K\nexample [is_separable E K] : is_separable F K := is_separable_tower_top_of_is_separable E F K\n\n-- I can't find the claim that if F/E and K/F are separable then so is K/E. The proof I know\n-- uses separable degree and I'm not sure we have that in Lean either.\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/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7844693372338947}}
{"text": "import order.galois_connection\nimport exercise4\n\nuniverse u\n\n-- exercise 5(a)\n-- Show that in a galois connection fg the right adjoint g preserves meets\n\nlemma gPreservesMeets {A B : Type u} {f: A → B} {g: B → A} [partial_order A] [partial_order B] [gc : galois_connection f g] \n      (M : set B) (m : B) (h : isMeet M m) : (isMeet (g '' M) (g m) ) :=\nbegin\n  split,\n  {\n    intros n hn,\n    cases hn with b hb,\n    cases hb with b_in_M gb_is_n,\n    have b_ge_n : b ≥ m := begin\n      apply h.left,\n      exact b_in_M,\n    end,\n    have gb_ge_gn : g b ≥ g m := begin\n      apply gc.monotone_u,\n      assumption,\n    end,\n    calc n  = g b : by rw gb_is_n\n        ... ≥ g m : by exact gb_ge_gn\n  },\n  {\n    intro a',\n    intro ha',\n    change a' ≤ g m,\n    rw ← gc,\n    apply h.right,\n    intros b b_in_M,\n    change f a' ≤ b,\n    rw gc,\n    apply ha',\n    use b,\n    use b_in_M,\n  }\nend\n\n-- exercise 5(b)\n-- Show that in a galois connection fg the left adjoint f preserves joins\nlemma fPreservesJoins {A B : Type u} {f: A → B} {g: B → A} [partial_order A] [partial_order B] [gc : galois_connection f g] \n      (N : set A) (n : A) (h : isJoin N n) : (isJoin (f '' N) (f n) ) :=\nbegin\n  split,\n  {\n    intros m hm,\n    cases hm with a ha,\n    cases ha with a_in_N fa_is_m,\n    have a_le_n : a ≤ n := begin\n      apply h.left,\n      exact a_in_N,\n    end,\n    have fa_le_fn : f a ≤ f n := begin\n      apply gc.monotone_l,\n      assumption,\n    end,\n    calc m  = f a : by rw fa_is_m\n        ... ≤ f n : by exact fa_le_fn\n  },\n  {\n    intro b',\n    intro hb',\n    rw gc,\n    apply h.right,\n    intros a a_in_N,\n    rw ← gc,\n    apply hb',\n    use a,\n    use a_in_N,\n  }\nend\n", "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/exercise5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7844693337726981}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    s ∩ t = t ∩ s\n-- ----------------------------------------------------------------------\n\nimport tactic\n\nopen set\n\nvariable {α : Type*}\nvariables (s t u : set α)\n\n-- 1ª demostración\n-- ===============\n\nexample : s ∩ t = t ∩ s :=\nbegin\n  ext x,\n  simp only [mem_inter_eq],\n  split,\n  { rintros ⟨xs, xt⟩,\n    exact ⟨xt, xs⟩ },\n  { rintros ⟨xt, xs⟩,\n    exact ⟨xs, xt⟩ },\nend\n\n-- Prueba\n-- ======\n\n/-\nα : Type u_1,\ns t : set α\n⊢ s ∩ t = t ∩ s\n  >> ext x,\nx : α\n⊢ x ∈ s ∩ t ↔ x ∈ t ∩ s\n  >> simp only [mem_inter_eq],\n⊢ x ∈ s ∧ x ∈ t ↔ x ∈ t ∧ x ∈ s\n  >> split,\n| ⊢ x ∈ s ∧ x ∈ t → x ∈ t ∧ x ∈ s\n|   >> { rintros ⟨xs, xt⟩,\n| xs : x ∈ s,\n| xt : x ∈ t\n| ⊢ x ∈ t ∧ x ∈ s\n|   >>   exact ⟨xt, xs⟩ },\n⊢ x ∈ t ∧ x ∈ s → x ∈ s ∧ x ∈ t\n  >> { rintros ⟨xt, xs⟩,\nxt : x ∈ t,\nxs : x ∈ s\n⊢ x ∈ s ∧ x ∈ t\n  >>   exact ⟨xs, xt⟩ },\nno goals\n-/\n\n-- Comentarios:\n-- 1. La táctica (ext x) transforma la conclusión (s = t) en\n--    (x ∈ s ↔ x ∈ t).\n-- 2. Se ha usado el lema\n--    + mem_inter_eq x s t : x ∈ s ∩ t = (x ∈ s ∧ x ∈ t)\n\n-- Comprobación:\nvariable (x : α)\n-- #check @mem_inter_eq _ x s t\n\n-- 2ª demostración\n-- ===============\n\nexample : s ∩ t = t ∩ s :=\next $ λ x, ⟨λ ⟨xs, xt⟩, ⟨xt, xs⟩, λ ⟨xt, xs⟩, ⟨xs, xt⟩⟩\n\n-- Comentario: La notación `f $ ...`  es equivalente a `f (...)`.\n\n-- 3ª demostración\n-- ===============\n\nexample : s ∩ t = t ∩ s :=\nby ext x; simp [and.comm]\n\n-- 4ª demostración\n-- ===============\n\nexample : s ∩ t = t ∩ s :=\ninf_comm\n\n-- 5ª demostración\n-- ===============\n\nexample : s ∩ t = t ∩ s :=\nbegin\n  apply subset.antisymm,\n  { rintros x ⟨xs, xt⟩,\n    exact ⟨xt, xs⟩ },\n  { rintros x ⟨xt, xs⟩,\n    exact ⟨xs, xt⟩ },\nend\n\n-- Prueba\n-- ======\n\n/-\nα : Type u_1,\ns t : set α\n⊢ s ∩ t = t ∩ s\n  >> apply subset.antisymm,\n| ⊢ s ∩ t ⊆ t ∩ s\n|   >> { rintros x ⟨xs, xt⟩,\n| x : α,\n| xs : x ∈ s,\n| xt : x ∈ t\n| ⊢ x ∈ t ∩ s\n|   >>   exact ⟨xt, xs⟩ },\n⊢ t ∩ s ⊆ s ∩ t\n  >> { rintros x ⟨xt, xs⟩,\nx : α,\nxt : x ∈ t,\nxs : x ∈ s\n⊢ x ∈ s ∩ t\n  >>   exact ⟨xs, xt⟩ },\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/Conmutativa_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8670357477770336, "lm_q1q2_score": 0.7843643487203389}}
{"text": "-- 4.6 Exercises\n\n-- #1\n\nvariables (α : Type*) (p q : α → Prop)\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\niff.intro\n(assume h: ∀ x, p x ∧ q x,\n  have hp: ∀ x, p x := (assume a: α, (h a).left),\n  have hq: ∀ x, q x := (assume a: α, (h a).right),\n  show (∀ x, p x) ∧ (∀ x, q x),\n  from ⟨hp, hq⟩ \n)\n(assume h: (∀ x, p x) ∧ (∀ x, q x),\n  have hp: ∀ x, p x := h.left,\n  have hq: ∀ x, q x := h.right,\n  show ∀ x, p x ∧ q x,\n  from assume a: α, ⟨hp a, hq a⟩ \n)\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\nassume hapq: ∀ x, p x → q x,\nassume hap: ∀ x, p x,\nassume a: α, show q a, from (hapq a) (hap a)\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\nassume h: (∀ x, p x) ∨ (∀ x, q x),\nassume a: α, show p a ∨ q a, from\nor.elim h\n(assume hap: ∀ x, p x, show p a ∨ q a, from or.inl (hap a))\n(assume haq: ∀ x, q x, show p a ∨ q a, from or.inr (haq a))\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/04-Quantifiers-and-Equality/example-4.6-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037782, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7843501997706223}}
{"text": "/- QUICK NOTE: -/\n/-\nThis was made by Charlie and Ben with no\nconsultation with Professor Sullivan.\n\nThis is just some review that we thought you should have\nwhile Professor Sullivan is finishing HW9.\n\nWhile most of these proofs were not written to be difficult,\nsome turned out to be particularly challenging (which I've marked below).\n\nThis is not necessarily representative of what you will see on your\nexam, unlike homework 9.\n\nAs always -- if we've made any mistakes or you have any questions\nplease post on Piazza. :)\n-/\n\n-- For all proofs, please use provablesystems.com\n-- for a reference guide on how to start these proofs\n\n-- Also, you may see the same proofs written two different ways:\nexample {P : Prop} : P → P :=\nbegin\n    assume p,\n    exact p,\nend\n\n-- Prof. Sullivan likes forall more \n-- so almost all proofs onward will appear with a forall\n-- like this:\nexample : ∀ P : Prop, P → P :=\nbegin\n    assume P,\n    assume p,\n    exact p,\nend\n\n/- START OF REVIEW -/\n\n/- IMPLICATION -/\nexample : ∀ P, P → P :=\nbegin\n    assume P,\n    assume p,\n    exact p,\nend\nexample : ∀ P Q, P → Q → P := \nbegin\n    assume P Q,\n    assume p q,\n    exact p,\nend\nexample : (0 = 1) → (0 = 1) :=\nbegin\n    assume pf,\n    exact pf,\nend\n\n-- You will use implication extensively throughout\n-- the remainder of this review\n\n\n/- TRUE -/\n-- intro\nexample : true :=\nbegin\n    exact true.intro,\nend\nexample : ∀ P Q R : Prop, true :=\nbegin\n    assume P Q R,\n    exact true.intro,\nend\nexample : (0 = 1) → true :=\nbegin\n    assume pf,\n    exact true.intro,\nend\n\n\n/- FALSE -/\nexample : false → (0 = 1) :=\nbegin\n    assume f,\n    exact false.elim f,\nend\nexample : ∀ P : Prop, false → P :=\nbegin\n    assume P,\n    assume f,\n    exact false.elim f,\nend \nexample : ∀ P Q, P → Q → false → (P ∧ Q) :=\nbegin\n    assume P Q,\n    assume p q f,\n    exact false.elim f,\nend\n\n\n/- EQUALITY -/\nexample : 3 = 3 :=\nbegin\n    exact eq.refl 3,\nend\nexample : ∀ n : nat, n = n :=\nbegin\n    assume n,\n    exact eq.refl n,\nend\n\n\n/- AND -/\n-- intro (and.intro _ _)\nexample : ∀ P Q : Prop, P → Q → (P ∧ Q) :=\nbegin\n    assume P Q,\n    assume p q,\n    exact and.intro p q,\nend\nexample {P Q : Prop} : P → Q → (Q ∧ P) :=\nbegin\n    assume p q,\n    exact and.intro q p,\nend\nexample : (0 = 0) ∧ (1 = 1) :=\nbegin\n    apply and.intro,\n    exact eq.refl 0,\n    exact rfl, -- shortcut\nend\n\n-- elim (and.elim_left _ and and.right _ )\nexample : ∀ P Q : Prop, P ∧ Q → P :=\nbegin\n    intros, -- shortcut for all assumptions (except negation assumptions)\n    exact and.elim_left a,\nend\nexample : ∀ P Q : Prop, P ∧ Q → Q :=\nbegin\n    intros,\n    exact and.elim_right a,\nend\nexample : ∀ P Q R : Prop, P ∧ Q ∧ R → Q :=\nbegin\n    intros,\n    apply and.elim_left (and.elim_right a),\nend\n\n-- both\nexample : ∀ P Q R : Prop, P ∧ Q ∧ R → (P ∧ R) :=\nbegin\n    intros,\n    apply and.intro,\n    exact and.elim_left a,\n    exact and.elim_right (and.elim_right a),\nend\nexample : ∀ P Q R : Prop, Q ∧ R ∧ P → (R ∧ P ∧ Q) :=\nbegin\n    assume P Q R,\n    assume qrp,\n    apply and.intro,\n    exact qrp.2.1, -- shortcut for and.elim_left (and.elim_right qrp)\n    apply and.intro,\n    exact qrp.2.2,\n    exact qrp.1,\nend\n\n\n/- OR -/\n-- intro (or.intro_left _ _, shortcut: or.inl _ and the associated right-side variant)\nexample : ∀ P Q, P → (P ∨ Q) :=\nbegin\n    assume P Q,\n    assume p,\n    exact or.intro_left Q p,\nend\nexample : ∀ P Q R, (P ∧ R) → (P ∨ Q) :=\nbegin\n    assume P Q R,\n    assume pr,\n    exact or.inl (and.elim_left pr), -- or.inl shortcut for or.intro_left (doesn't require Prop argument)\nend\nexample : (0 = 1) ∨ (1 = 1) :=\nbegin\n    right, -- shortcut for or.inr (also left works for or.inl)\n    refl, -- shortcut for apply/exact rfl,\nend\n\n--elim (or.elim _ _ _ )\n--remember you can use the 'cases' keyword\nexample : ∀ P Q R, (P → R) → (Q → R) → (P ∨ Q) → R :=\nbegin\n    assume P Q R,\n    assume pr,\n    assume qr,\n    assume porq,\n    exact or.elim porq pr qr,\nend\nexample : ∀ P Q, (P → Q) → (P ∨ Q) → Q :=\nbegin\n    intros,\n    cases a_1,\n        -- case 1\n        apply a,\n        exact a_1,\n        -- case 2\n        exact a_1,\nend\n\n\n/- BI-IMPLICATION -/\n-- intro\nexample : ∀ P Q, (P → Q) → (Q → P) → (P ↔ Q) :=\nbegin\n    assume P Q,\n    assume pq qp,\n    exact iff.intro pq qp,\nend\n\n-- elim (iff.elim _ )\nexample : ∀ P Q : Prop, (P ↔ Q) → (P → Q) :=\nbegin\n    assume P Q,\n    assume piffq,\n    assume p,\n    exact (iff.elim_left piffq) p,\nend\nexample : ∀ P Q : Prop, (P ↔ Q) → ((P → Q) ∧ (Q → P)) :=\nbegin\n    intros,\n    apply and.intro,\n    exact iff.elim_left a,\n    exact iff.elim_right a,\nend\n\n-- both\n-- this is a particularly challenging proof\nexample : ∀ P Q R : Prop, (P ↔ Q) → (Q ↔ R) → (R ↔ P) :=\nbegin\n    intros,\n    apply iff.intro,\n    assume r,\n    -- One line solution:\n    -- exact (iff.elim_right a) ((iff.elim_right a_1) r),\n    -- OR you can do it with 'have' statements\n    have pimpq : Q → P := iff.elim_right a,\n    have rimpq : R → Q := iff.elim_right a_1,\n    exact pimpq (rimpq r),\n    assume p,\n    exact (iff.elim_left a_1) ((iff.elim_left a) p),\nend\n\n/- NEGATION -/\nexample : ∀ P : Prop, ¬ P → (P → false) :=\nbegin\n    assume P,\n    assume np,\n    exact np,\nend\nexample : ∀ P Q : Prop, (P ∧ Q) → ¬ P → false :=\nbegin\n    intros,\n    exact a_1 (and.elim_left a),\nend\n\n/- FORALL -/ -- which we've been using extensively up until this point already\nexample : ∀ P Q : Prop, (∀ p : P, Q) → (P → Q) :=\nbegin\n    assume P Q,\n    assume funcPtoQ,\n    -- exact funcPtoQ, OR you can try...\n    assumption, -- shortcut if your proof statement is in your context menu\nend\n\n/- EXISTS -/\n-- intro\nexample : ∀ n : nat, ∃ m, n = m :=\nbegin\n    assume n,\n    apply exists.intro n,\n    refl,\nend\n\n-- Below is the property isEven.\n-- A natural number is even if there exists\n-- another natural number k such that 2k = n\n\ndef isEven : ℕ → Prop := \n    λ n, ∃ k, 2 * k = n\n\n-- Define isOdd below.\n-- A natural number is odd if there exists\n-- another natural number k such that 2k + 1 = n\n\ndef isOdd : ℕ → Prop :=\n    λ n : nat, ∃ k : nat, (2 * k + 1) = n\n\n-- elim/both\n-- this is a particularly challenging proof\nexample : ∀ n : nat, (isEven n) → (isEven (2*n)) :=\nbegin\n    unfold isEven, -- \"desugars\" isEven to its definition above\n    intros,\n    apply exists.elim a,\n    assume witness,\n    assume proof_that_n_is_even_with_witness,\n    rewrite<- proof_that_n_is_even_with_witness,\n    apply exists.intro (2*witness),\n    refl,\nend\n\n-- Alternatively, because we know that 2*<any number> is even\n-- you can shorten the proof:\nexample : ∀ n : nat, (isEven n) → (isEven (2*n)) :=\nbegin\n    unfold isEven, -- \"desugars\" isEven to its definition above\n    intros,\n    apply exists.intro n,\n    refl,\nend", "meta": {"author": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/ExamPractice/final_review_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.8723473846343393, "lm_q1q2_score": 0.7843461724979722}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones:\n-- 1. Importar la librería data.set.lattice\n-- 2. Abrir el espacio de nombres set.\n-- 3. Declarar α una variable de tipos.\n-- 4. Declarar s una vabiable sobre conjuntos de conjuntos de elementos\n--    de α.\n-- ----------------------------------------------------------------------\n\nimport data.set.lattice      -- 1\nopen set                     -- 2 \nvariable {α : Type*}         -- 3\nvariable (s : set (set α))   -- 4\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    ⋃₀ s = ⋃ t ∈ s, t\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : ⋃₀ s = ⋃ t ∈ s, t :=\nbegin\n  ext x,\n  rw mem_bUnion_iff,\n  refl,\nend\n\n-- Prueba\n-- ======\n\n/-\nα : Type u_1,\ns : set (set α)\n⊢ ⋃₀ s = ⋃ (t : set α) (H : t ∈ s), t\n  >> ext x,\nx : α\n⊢ x ∈ ⋃₀ s ↔ x ∈ ⋃ (t : set α) (H : t ∈ s), t\n  >> rw mem_bUnion_iff,\n⊢ x ∈ ⋃₀ s ↔ ∃ (x_1 : set α) (H : x_1 ∈ s), x ∈ x_1\n  >> refl,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + mem_bUnion_iff: y ∈ (⋃ x ∈ s, t x) ↔ ∃ x ∈ s, y ∈ t x\n\n-- 2ª demostración\n-- ===============\n\nexample : ⋃₀ s = ⋃ t ∈ s, t :=\nsUnion_eq_bUnion\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    ⋂₀ s = ⋂ t ∈ s, t\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : ⋂₀ s = ⋂ t ∈ s, t :=\nbegin\n  ext x,\n  rw mem_bInter_iff,\n  refl,\nend\n\n-- Prueba\n-- ======\n\n/-\nα : Type u_1,\ns : set (set α)\n⊢ ⋂₀ s = ⋂ (t : set α) (H : t ∈ s), t\n  >> ext x,\nx : α\n⊢ x ∈ ⋂₀ s ↔ x ∈ ⋂ (t : set α) (H : t ∈ s), t\n  >> rw mem_bInter_iff,\n⊢ x ∈ ⋂₀ s ↔ ∀ (x_1 : set α), x_1 ∈ s → x ∈ x_1\n  >> refl,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + mem_bInter_iff : y ∈ (⋂ x ∈ s, t x) ↔ ∀ x ∈ s, y ∈ t x \n\n-- 2ª demostración\n-- ===============\n\nexample : ⋂₀ s = ⋂ t ∈ s, t :=\nsInter_eq_bInter\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/Ejemplos_de_uniones_e_intersecciones_generales_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.7843237023785387}}
{"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 topology.continuous_on\n\n/-!\n# Left and right continuity\n\nIn this file we prove a few lemmas about left and right continuous functions:\n\n* `continuous_within_at_Ioi_iff_Ici`: two definitions of right continuity\n  (with `(a, ∞)` and with `[a, ∞)`) are equivalent;\n* `continuous_within_at_Iio_iff_Iic`: two definitions of left continuity\n  (with `(-∞, a)` and with `(-∞, a]`) are equivalent;\n* `continuous_at_iff_continuous_left_right`, `continuous_at_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\nopen set filter\nopen_locale topological_space\n\nsection partial_order\n\nvariables {α β : Type*} [topological_space α] [partial_order α] [topological_space β]\n\nlemma continuous_within_at_Ioi_iff_Ici {a : α} {f : α → β} :\n  continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a :=\nby simp only [← Ici_diff_left, continuous_within_at_diff_self]\n\nlemma continuous_within_at_Iio_iff_Iic {a : α} {f : α → β} :\n  continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a :=\n@continuous_within_at_Ioi_iff_Ici (order_dual α) _ ‹topological_space α› _ _ _ f\n\nend partial_order\n\nvariables {α β : Type*} [topological_space α] [linear_order α] [topological_space β]\n\nlemma nhds_left_sup_nhds_right (a : α) :\n  𝓝[≤] a ⊔ 𝓝[≥] a = 𝓝 a :=\nby rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ]\n\nlemma nhds_left'_sup_nhds_right (a : α) :\n  𝓝[<] a ⊔ 𝓝[≥] a = 𝓝 a :=\nby rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ]\n\nlemma nhds_left_sup_nhds_right' (a : α) :\n  𝓝[≤] a ⊔ 𝓝[>] a = 𝓝 a :=\nby rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ]\n\nlemma continuous_at_iff_continuous_left_right {a : α} {f : α → β} :\n  continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a :=\nby simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right]\n\nlemma continuous_at_iff_continuous_left'_right' {a : α} {f : α → β} :\n  continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a :=\nby rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic,\n  continuous_at_iff_continuous_left_right]\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/ordered/left_right.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347107, "lm_q2_score": 0.8840392741081574, "lm_q1q2_score": 0.7843237023785385}}
{"text": "/- Lecture 1.2: Basics — Proofs -/\n\n/- Computation -/\n\n-- β-reduction (reduce λ-abstraction + application)\nexample {α β : Type} (f : α → β) (a : α) :\n  (λx, f x) a = f a :=\nby refl\n\n-- δ-reduction (unfold definition)\nsection\n\ndef f (n : ℕ) : ℕ := n + n\n\nexample (m : ℕ) : f m = m + m :=\nby refl\n\nend\n\n-- ι-reduction (projection)\nexample {α β : Type} (a : α) (b : β) :\n  prod.fst (a, b) = a :=\nby refl\n\n-- ζ-reduction (`let`-unfolding)\nexample : (let x : ℕ := 2 in 2 + 2) = 4 :=\nby refl\n\n-- η-reduction\nexample {α β : Type} (f : α → β) : (λx, f x) = f :=\nby refl\n\n/- Natural numbers -/\n\nnamespace my_nat\n\ndef add : nat → nat → nat\n| m 0            := m\n| m (nat.succ n) := nat.succ (add m n)\n\n/- Commutativity of `add` -/\n\nlemma add_zero : ∀n : ℕ, add 0 n = n\n| 0            := by refl\n| (nat.succ m) := by simp [add, add_zero m]\n\nexample (n : ℕ) : add 0 n = n :=\nbegin\n  induction n,\n  { refl },\n  { simp [add, n_ih] }\nend\n\nexample (n : ℕ) : add 0 n = n :=\nby induction n; simp [add, *]\n\nlemma add_succ : ∀m n : ℕ, 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 : ∀m n : ℕ, 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\nexample : ∀m n : ℕ, add m n = add n m\n| m 0            := by simp [add, add_zero]\n| m (nat.succ n) :=\n  have add_succ : ∀m n : ℕ, add (nat.succ m) n = nat.succ (add m n) :=\n    by intros m n; induction n; simp [add, *],\n  by simp [add, add_succ, add_comm m n]\n\nexample : ∀m n : ℕ, add m n = add n m\n| m 0            := by simp [add, add_zero]\n| m (nat.succ n) :=\n  have ih : _ := add_comm m n,\n  by simp [add, add_succ, ih]\n\n/- Associativity of `add` -/\n\nlemma add_assoc : ∀l m n : ℕ, 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\ninstance : is_commutative ℕ add := ⟨add_comm⟩\ninstance : is_associative ℕ add := ⟨add_assoc⟩\n\ndef mul : ℕ → ℕ → ℕ\n| _ 0            := 0\n| m (nat.succ n) := add m (mul m n)\n\n/- Distributivity -/\n\nlemma mul_add (l m : ℕ) : ∀n : ℕ, mul l (add m n) = add (mul l m) (mul l n)\n| 0            := by refl\n| (nat.succ l) := begin simp [add, mul, mul_add l], ac_refl end\n\nend my_nat\n\n\n/- Lists -/\n\ndef reverse {α : Type} : list α → list α\n| []        := []\n| (x :: xs) := reverse xs ++ [x]\n\n/- `reverse` of `reverse` is identity -/\nlemma reverse_append {α : Type} :\n  ∀xs ys : list α, reverse (xs ++ ys) = reverse ys ++ reverse xs\n| [] ys := by simp[reverse]\n| (x :: xs) ys := begin simp[reverse, reverse_append] end\n\n\n\nlemma reverse_reverse {α : Type} : ∀xs : list α, reverse (reverse xs) = xs\n| [] := by simp[reverse]\n| (x :: xs) := begin simp[reverse], simp[reverse_append], rw[reverse_reverse], rw[reverse], rw[reverse], refl  end\n\ndef map {α : Type} {β : Type} (f : α → β) : list α → list β\n| [] := []\n| (x :: xs) :=  f x :: map xs\n\n\n-- lemma reverse_append {α : Type} :\n--   ∀xs ys : list α, reverse (xs ++ ys) = reverse ys ++ reverse xs\n-- | []        ys := by simp [reverse]\n-- | (x :: xs) ys := begin simp [reverse, reverse_append xs] end\n\n-- lemma reverse_reverse {α : Type} : ∀xs : list α, reverse (reverse xs) = xs\n-- | []        := by refl\n-- | (x :: xs) := by simp [reverse, reverse_append, reverse_reverse xs]\n\n-- def map {α : Type} {β : Type} (f : α → β) : list α → list β\n-- | []        := []\n-- | (x :: xs) := f x :: map xs\n\n/- Functorial properties of `map` -/\n\nlemma map_ident {α : Type} : ∀xs : list α, map (λx, x) xs = xs\n| []        := by refl\n| (x :: xs) := begin rw[map],  end\n\nexample {α : Type} : ∀xs : list α, map (λx, x) xs = xs\n| []        := by refl\n| (x :: xs) :=\n  have ih : map (λx, x) xs = xs := _example xs,\n  begin rw map, rw ih end\n\nexample {α : Type} : ∀xs : list α, xs = map (λx, x) xs\n| []        := by refl\n| (x :: xs) :=\n  have ih : _ := _example xs,\n  begin rw [map, ←ih] end\n\nlemma map_comp {α β γ : Type} (f : α → β) (g : β → γ) :\n  ∀xs : list α, map (λx, g (f x)) xs = map g (map f xs)\n| []        := by refl\n| (x :: xs) := begin rw[map], rw[map_comp], rw[map], rw[map] end\n\nlemma map_append {α β : Type} (f : α → β) :\n  ∀xs ys : list α, map f (xs ++ ys) = map f xs ++ map f ys\n| []        ys := by refl\n| (x :: xs) ys := begin rw[map], rw[map_append], end\n\nlemma map_reverse {α β : Type} (f : α → β) :\n  ∀xs : list α, map f (reverse xs) = reverse (map f xs)\n| []        := by refl\n| (x :: xs) := by simp [map, reverse, map_append, map_reverse xs]\n\n\n/- RGB values -/\n\nstructure rgb :=\n(red green blue : ℕ)\n\ndef shuffle (c : rgb) : rgb :=\n{red := c.green, green := c.blue, blue := c.red}\n\nlemma shuffle_shuffle_shuffle (c : rgb) : shuffle (shuffle (shuffle c)) = c :=\nby cases c; refl\n\nexample (c : rgb) : shuffle (shuffle (shuffle c)) = c :=\nbegin cases c, refl end\n\nexample : ∀c : rgb, shuffle (shuffle (shuffle c)) = c\n| ⟨_, _, _⟩ := by refl\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/12_lecture.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.784301999225593}}
{"text": "import data.nat.prime\nimport algebra.big_operators\nimport tactic\n\n\nexample (n : ℕ) : n.succ ≠ 0 := n.succ_ne_zero \n\nexample (m n : ℕ) (h : m.succ = n.succ) : m = n := nat.succ.inj h\n\n\ndef fac : ℕ → ℕ\n| 0  := 1\n| (n + 1) := (n + 1) * fac n\n\nexample : fac 0 = 1 := rfl\nexample : fac 0 = 1 := by rw fac\nexample : fac 0 = 1 := by simp [fac]\n\nexample (n : ℕ) : fac (n + 1) = (n + 1) * fac n := rfl\nexample (n : ℕ) : fac (n + 1) = (n + 1) * fac n := by rw fac\nexample (n : ℕ) : fac (n + 1) = (n + 1) * fac n := by simp [fac]\n\ntheorem fac_pos (n : ℕ) : 0 < fac n := \nbegin \n  induction n with n ih,\n  { from zero_lt_one,},\n    rw fac,\n    apply mul_pos,\n    from n.succ_pos,\n    from ih,\nend\n\n\ntheorem dvd_fac {i n : ℕ} (ipos : 0 < i) (ile : i ≤ n) : i ∣ fac n :=\nbegin\n  induction n with n ih,\n  { linarith,},\n    rw fac,\n    cases nat.of_le_succ ile with h h,\n    { apply dvd_mul_of_dvd_right, from ih h,},\n      rw h,\n      apply dvd_mul_right,\nend\n\ntheorem pow_two_le_fac (n : ℕ) : 2^(n-1) ≤ fac n :=\nbegin \n  cases n with n,\n  { simp [fac],},\n    induction n with n ih,\n    { simp [fac],},\n      rw fac,\n      simp, simp at ih,\n      apply mul_le_mul',\n      { rw nat.succ_eq_add_one,\n        linarith,},\n      from ih,\nend\n\n\nsection \nvariables {α : Type*} (s : finset ℕ) (f : ℕ → ℕ) (n : ℕ)\n\n\n\n#check finset.sum s f\n#check finset.prod s f\n\nopen_locale big_operators\nopen finset\n\nexample : s.sum f = ∑ x in s, f x := rfl\nexample : s.prod f = ∏ x in s, f x := rfl\n\nexample : (range n).sum f = ∑ x in range n, f x := rfl\nexample : (range n).prod f = ∏ x in range n, f x := rfl\n\nexample (f : ℕ → ℕ) : ∑ x in range 0, f x = 0 :=\nfinset.sum_range_zero f\n\nexample (f : ℕ → ℕ) (n : ℕ): ∑ x in range n.succ, f x = (∑ x in range n, f x) + f n :=\nfinset.sum_range_succ f n\n\nexample (f : ℕ → ℕ) : ∏ x in range 0, f x = 1 :=\nfinset.prod_range_zero f\n\nexample (f : ℕ → ℕ) (n : ℕ): ∏ x in range n.succ, f x = (∏ x in range n, f x) * f n :=\nfinset.prod_range_succ f n\n\n\nexample (n : ℕ) : fac n = ∏ i in range n, (i + 1) :=\nbegin \n  induction n with n ih,\n  { simp [fac],},\n  { rw [fac, prod_range_succ, ih, mul_comm],},\nend\n\n\ntheorem sum_id (n : ℕ) : ∑ i in range (n + 1), i = n * (n + 1) / 2 :=\nbegin\n  symmetry, apply nat.div_eq_of_eq_mul_right (by norm_num : 0 < 2),\n  induction n with n ih,\n  { simp,},\n  { rw [sum_range_succ, mul_add 2, ←ih, nat.succ_eq_add_one],\n    ring_nf,}\nend\n\ntheorem sum_sqr (n : ℕ) : ∑ i in range (n + 1), i^2 = n * (n + 1) * (2 *n + 1) / 6 :=\nbegin \n  symmetry, apply nat.div_eq_of_eq_mul_right (by norm_num : 0 < 6),\n  induction n with n ih,\n  { simp,},\n  { rw [sum_range_succ, mul_add 6, ←ih, nat.succ_eq_add_one],\n    ring,},\nend\n\nend\n\n\n\nsection \ninductive my_nat\n| zero : my_nat\n| succ : my_nat → my_nat\n\nnamespace my_nat\n\ndef add : my_nat → my_nat → my_nat\n| x zero     := x\n| x (succ y) := succ (add x y)\n\ndef mul : my_nat → my_nat → my_nat\n| x zero     := zero\n| x (succ y) := add (mul x y) x\n\ndef pred : my_nat → my_nat\n| zero := zero \n| (succ x) := x\n\ndef tsub : my_nat → my_nat → my_nat\n| n zero := n \n| n (succ m) := tsub (n.pred) m \n\n\ntheorem zero_add (n : my_nat) : add zero n = n :=\nbegin\n  induction n with n ih,\n  { refl },\n  rw [add, ih]\nend\n\ntheorem succ_add (m n : my_nat) : add (succ m) n = succ (add m n) :=\nbegin\n  induction n with n ih,\n  { refl },\n  rw [add, ih],\n  refl\nend\n\ntheorem add_comm (m n : my_nat) : add m n = add n m :=\nbegin\n  induction n with n ih,\n  { rw zero_add, refl },\n  rw [add, succ_add, ih]\nend\n\ntheorem add_assoc (m n k : my_nat) : add (add m n) k = add m (add n k) :=\nbegin \n  induction k with k ih,\n  { simp only [add],},\n  { rw [add, ih, ←add, ←add],}\nend\n\ntheorem mul_add  (m n k : my_nat) : mul m (add n k) = add (mul m n) (mul m k) :=\nbegin \n  induction k with k ih,\n  { simp only [add, mul],},\n  { rw [add, mul, ih, add_assoc, ←mul],},\nend\n\ntheorem zero_mul (n : my_nat) : mul zero n = zero :=\nbegin \n  induction n with n ih,\n  { simp [mul]},\n  { rw [mul, add, ih],},\nend\n\ntheorem succ_mul (m n : my_nat) : mul (succ m) n = add (mul m n) n :=\nbegin \n  induction n with n ih,\n  { simp only [mul, add],},\n  { rw [mul, ih, add, mul, add_assoc, ←add, add_comm n m, ←add, ←add_assoc],}\nend\n\ntheorem mul_comm (m n : my_nat) : mul m n = mul n m :=\nbegin \n  induction n with n ih,\n  { simp only [mul, zero_mul],},\n  { rw [succ_mul, ←ih, mul],},\nend\n\ntheorem succ_pred_self (n : my_nat) : n.succ.pred = n := \nbegin \n  rw pred,\nend\n\n\ntheorem sub_self (n : my_nat) : tsub n n = zero :=\nbegin\n  induction n with n ih,\n  { simp only [tsub],},\n  { rw [tsub, succ_pred_self, ih],}\nend\n\nend my_nat\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/05_Number_Theory/02_Induction_and_Recursion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7843019896983705}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que para todo número real c, la función\n--    f(x) x  + c\n-- es suprayectiva. \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariable {c : ℝ} \n\nopen function\n\n-- 1ª demostración\n-- ===============\n\nexample : surjective (λ x, x + c) :=\nbegin\n  intro x,\n  use x - c,\n  dsimp, \n  ring,\nend\n\n-- Su desarrollo es\n-- \n-- c : ℝ\n-- ⊢ surjective (λ (x : ℝ), x + c)\n--    >> intro x,\n-- ⊢ ∃ (a : ℝ), (λ (x : ℝ), x + c) a = x\n--    >> use x - c,\n-- ⊢ (λ (x : ℝ), x + c) (x - c) = x\n--    >> dsimp,\n-- ⊢ x - c + c = x \n--    >> ring,\n-- no goals\n\n-- 2ª demostración\n-- ===============\n\nexample : surjective (λ x, x + c) :=\nbegin\n  intro x,\n  use x - c,\n  change (x - c) + c = x,\n  ring,\nend\n\n-- Su desarrollo es\n-- \n-- c : ℝ\n-- ⊢ surjective (λ (x : ℝ), x + c)\n--    >> intro x,\n-- ⊢ ∃ (a : ℝ), (λ (x : ℝ), x + c) a = x\n--    >> use x - c,\n-- ⊢ (λ (x : ℝ), x + c) (x - c) = x\n--    >> change (x - c) + c = x,\n-- ⊢ x - c + c = x\n--    >> ring,\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/Suma_constante_es_suprayectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7843019864818455}}
{"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_sumkexp3eqsumksq\n  (n : ℕ) :\n  ∑ k in finset.range n, k^3 = (∑ k in finset.range n, k)^2 :=\nbegin\n  symmetry,\n  induction n with j IH,\n  {\n    refl,\n  },\n  {\n    calc (∑ (k : ℕ) in finset.range j.succ, k)^2 = ((∑ (k : ℕ) in finset.range j, k) + j)^2 : by rw finset.sum_range_succ\n   ... = (∑ (k : ℕ) in finset.range j, k)^2 + 2 * (∑ (k : ℕ) in finset.range j, k) * j + j^2 : by rw add_sq _ _\n   ... = (∑ (k : ℕ) in finset.range j, k)^2 +  (∑ (k : ℕ) in finset.range j, k) * 2 * j + j^2 : by ring\n   ... = (∑ (k : ℕ) in finset.range j, k)^2 + (j * (j-1)) * j + j^2 : by rw finset.sum_range_id_mul_two j\n   ... = (∑ (k : ℕ) in finset.range j, k^3) + (j * (j-1)) * j + j^2 : by rw IH\n   ... = (∑ (k : ℕ) in finset.range j, k^3) + j^2 * (j-1) + j^2 : by ring_nf\n   ... = (∑ (k : ℕ) in finset.range j, k^3) + j^3 : by cases j ; [norm_num, ring_nf]\n   ... = (∑ (k : ℕ) in finset.range j.succ, k^3) : by rw ← finset.sum_range_succ,\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/sumkexp3eqsumksq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7842510193661973}}
{"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\nThis file contains a few simple lemmas about `set.indicator` and `norm`.\n\n## Tags\nindicator, norm\n-/\n\nvariables {α E : Type*} [semi_normed_group E] {s t : set α} (f : α → E) (a : α)\n\nopen set\n\nlemma norm_indicator_eq_indicator_norm :\n  ∥indicator s f a∥ = indicator s (λa, ∥f a∥) a :=\nflip congr_fun a (indicator_comp_of_zero norm_zero).symm\n\nlemma nnnorm_indicator_eq_indicator_nnnorm :\n  ∥indicator s f a∥₊ = indicator s (λa, ∥f a∥₊) a :=\nflip congr_fun a (indicator_comp_of_zero nnnorm_zero).symm\n\nlemma norm_indicator_le_of_subset (h : s ⊆ t) (f : α → E) (a : α) :\n  ∥indicator s f a∥ ≤ ∥indicator t f a∥ :=\nbegin\n  simp only [norm_indicator_eq_indicator_norm],\n  exact indicator_le_indicator_of_subset ‹_› (λ _, norm_nonneg _) _\nend\n\nlemma indicator_norm_le_norm_self : indicator s (λa, ∥f a∥) a ≤ ∥f a∥ :=\nindicator_le_self' (λ _ _, norm_nonneg _) a\n\nlemma norm_indicator_le_norm_self : ∥indicator s f a∥ ≤ ∥f a∥ :=\nby { rw norm_indicator_eq_indicator_norm, apply indicator_norm_le_norm_self }\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/indicator_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8918110504699677, "lm_q1q2_score": 0.7840328078976625}}
{"text": "import game.world3.level1 -- hide\nimport mynat.mul -- hide\n\nnamespace mynat -- hide\n\n/-\n# Multiplication World\n\n## Level 2: `mul_one`\n\nRemember that you can see everything you have proved so far about multiplication in\nthe drop-down box on the left (and that this list will grow as we proceed).\n\nIn this level we'll need to use\n\n* `one_eq_succ_zero : 1 = succ(0)`\n\nwhich was mentioned back in Addition World and\nwhich will be a useful thing to rewrite right now, as we\nbegin to prove a couple of lemmas about how `1` behaves\nwith respect to multiplication.\n-/\n\n/- Lemma\nFor any natural number $m$, we have\n$$ m \\times 1 = m. $$\n-/\nlemma mul_one (m : mynat) : m * 1 = m :=\nbegin [nat_num_game]\n  rw one_eq_succ_zero,\n  rw mul_succ,\n  rw mul_zero,\n  rw zero_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/world3/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.945801271704518, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7840113750787162}}
{"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 exercises, which can be solved in term mode\nor tactic mode. . \na lot of stuff we don't need for this one precise result. As an appendix\nWe leave as exercises\nthe API extraction for the stuff we skipped, namely the following\ncomplex conjugation and the norm function.\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 : ℝ) (im : ℝ)\n\n-- Let's use the usual notation for the complex numbers\nnotation `ℂ` := complex\n\n-- You make the complex number with real part 3 and imaginary part 4 like this:\nexample : ℂ :=\n{ re := 3,\n  im := 4 }\n\n-- Or like this:\nexample : ℂ := complex.mk 3 4\n\n-- or like this:\nexample : ℂ := ⟨3, 4⟩\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 : ℝ := complex.re(complex.mk 3 4) -- this term is (3 : ℝ)\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 : ℂ) : 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-- 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 : ∀ z : ℂ, 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-- It's important we give this theorem a name, because 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-- `⟨z.re, z.im⟩ = 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@[simp] theorem eta : ∀ z : ℂ, complex.mk z.re z.im = z\n| ⟨x, y⟩ := rfl\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 : ℂ) : z.re = w.re → z.im = w.im → 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 : ∀ z w : ℂ, z.re = w.re → z.im = w.im → z = w :=\nbegin\n  rintros ⟨zr, zi⟩ ⟨_, _⟩ ⟨rfl⟩ ⟨rfl⟩,\n  refl,\nend\n\n-- `rintros` does `cases` as many times as you like using this cool `⟨, ⟩` 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 : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w\n| ⟨zr, zi⟩ ⟨_, _⟩ 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 : ℂ) : z = w ↔ z.re = w.re ∧ z.im = w.im :=\nbegin\n  split,\n  { intro H,\n    simp [H]},\n  {\n    rintro ⟨hre, him⟩,\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 : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=\n⟨λ H, by simp [H], and.rec ext⟩\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 : ℂ).\n\n/-- notation: `0`, or (0 : ℂ), will mean the complex number with\n  real and imaginary part equal to (0 : ℝ). -/\ninstance : has_zero ℂ := ⟨⟨0, 0⟩⟩\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 : ℂ).re = 0 := rfl\n@[simp] lemma zero_im : (0 : ℂ).im = 0 := rfl\n\n/-! ## 1 -/\n\n-- Now let's do the same thing for 1.\n\n/-- Notation `1` or `(1 : ℂ)`, means `⟨(1 : ℝ), (0 : ℝ)⟩`. -/\ninstance : has_one ℂ := ⟨⟨1, 0⟩⟩ \n\n-- name basic properties and tag them appropriately\n@[simp] lemma one_re : (1 : ℂ).re = 1 := rfl\n@[simp] lemma one_im : (1 : ℂ).im = 0 := rfl\n\n/-! ## + -/\n\n-- Now let's define addition\n\n/-- Notation `+` for usual addition of complex numbers-/\ninstance : has_add ℂ := ⟨λ z w, ⟨z.re + w.re, z.im + w.im⟩⟩\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 : ℂ) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl\n\n\n\ninstance : has_neg ℂ := ⟨λ z, ⟨-z.re, -z.im⟩⟩\n\n@[simp] lemma neg_re (z : ℂ) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : ℂ) : (-z).im = -z.im := rfl\n\ninstance : has_mul ℂ := ⟨λ z w, ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩\n\n@[simp] lemma mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : ℂ) : (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 : ℂ) : 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 ℂ :=\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\nA worked example of how coercions work from the reals to the complexes.\n\n-/\n\n-- Let's define a \"canonical\" map from ℝ to ℂ. Instead of making it a definition, we will\n-- make it a coercion instance, which means that if `(r : ℝ)` is a real\n-- number, then `(r : ℂ)` or `(↑r : ℂ)` will indicate the corresponding\n-- complex number with no imaginary part\n\n/-- The coercion from ℝ to ℂ sending `r` to the complex number `⟨r, 0⟩` -/\ninstance : has_coe ℝ ℂ := ⟨λ r, ⟨r, 0⟩⟩\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 : ℝ) : (r : ℂ).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : ℝ) : (r : ℂ).im = 0 := rfl\n\n-- The `simp` tactic will now simplify `re(↑r)` to `r` and `im(↑r)` to `0`\n-- and 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 : ℝ} : (z : ℂ) = w ↔ z = w :=\n⟨congr_arg re, congr_arg _⟩\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 : ℝ) : ℂ) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr of_real_eq_zero\n\n/-! ## 1 -/\n@[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 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 ℝ to ℂ commutes with addition.\n-- We should prove this and tag it appropriately.\n\nexample (r s : ℝ) : ((r + s : ℝ) : ℂ) = 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 : ℝ) : ((r + s : ℝ) : ℂ) = r + s := ext_iff.2 $ by simp\n\n/-! ## - -/\n@[simp, norm_cast] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 $ by simp\n\n/-! ## * -/\n\n@[simp, norm_cast] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = 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 : ℝ) (z : ℂ) : (↑r * z).re = r * z.re := by simp -- or by squeeze_simp\nlemma smul_im (r : ℝ) (z : ℂ) : (↑r * z).im = r * z.im := by simp -- or by squeeze_simp\n\n/-! ## Numerals\n\nFeel free to skip 15 lines down to `I` if you are a mathematician.\n\nThese last two are to do with the canonical map from numerals into the complexes, e.g. `(23 : ℂ)`.\nLean stores the numeral in binary. See for example\n\nset_option pp.numerals false\n#check (37 : ℂ)-- bit1 (bit0 (bit1 (bit0 (bit0 has_one.one)))) : ℂ\n-/\n\n@[simp, norm_cast] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r := ext_iff.2 $ by simp [bit0]\n@[simp, norm_cast] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r := ext_iff.2 $ by simp [bit1]\n\n-- I find it unbelievable that we have written 331 lines of code about the complex numbers\n-- and we've still never defined i, or j, or I, or $$\\sqrt{-1}$$, or whatever it's called. \n-- Why don't you try this one?\n\n/-! # I -/\n\n-- TODO: leave definition, sorry all proofs.\n\n/-- complex.I is the square root of -1 above the imaginary axis -/\ndef I : ℂ := ⟨0, 1⟩\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\n\nlemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : ℝ) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=\next_iff.2 $ by simp\n\n/-! # Complex conjugation -/\n\n-- TODO: leave definition, sorry all proofs.\n\ndef conj (z : ℂ) : ℂ := ⟨z.re, -z.im⟩\n\n@[simp] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : ℂ) : (conj z).im = -z.im := rfl\n\n@[simp] lemma conj_of_real (r : ℝ) : 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\n@[simp] lemma conj_add (z w : ℂ) : conj (z + w) = conj z + conj w :=\next_iff.2 $ by simp [add_comm]\n\n@[simp] lemma conj_neg (z : ℂ) : conj (-z) = -conj z := rfl\n\n@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp\n\n@[simp] lemma conj_mul (z w : ℂ) : conj (z * w) = conj z * conj w :=\next_iff.2 $ by simp [add_comm]\n\n@[simp] lemma conj_conj (z : ℂ) : 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 : ℂ} : conj z = conj w ↔ z = w :=\nconj_bijective.1.eq_iff\n\n@[simp] lemma conj_eq_zero {z : ℂ} : conj z = 0 ↔ z = 0 :=\nby simpa using @conj_inj z 0\n\nlemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=\n⟨λ h, ⟨z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)⟩,\n λ ⟨h, e⟩, e.symm ▸ rfl⟩\n\nlemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=\neq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩\n\ntheorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=\next_iff.2 $ by simp [two_mul]\n\n/-- the ring homomorphism complex conjugation -/\ndef Conj : ℂ →+* ℂ :=\n{ to_fun := conj,\n  map_one' := begin ext; simp, end,\n  map_mul' := begin intros, ext; simp end,\n  map_zero' := begin ext; simp end,\n  map_add' := begin intros, ext; simp end}\n\n/-! # Norms -/\n\n-- TODO: leave definition, sorry all proofs.\n\ndef norm_sq (z : ℂ) : ℝ := z.re * z.re + z.im * z.im\n\n@[simp] lemma norm_sq_of_real (r : ℝ) : 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 : ℂ) : 0 ≤ norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\n@[simp] lemma norm_sq_eq_zero {z : ℂ} : norm_sq z = 0 ↔ z = 0 :=\n⟨λ 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 λ h, h.symm ▸ norm_sq_zero⟩\n\n@[simp] lemma norm_sq_pos {z : ℂ} : 0 < norm_sq z ↔ z ≠ 0 :=\nby rw [lt_iff_le_and_ne, ne, eq_comm]; simp [norm_sq_nonneg]\n\n@[simp] lemma norm_sq_neg (z : ℂ) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : ℂ) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mul (z w : ℂ) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nby dsimp [norm_sq]; ring\n\nlemma norm_sq_add (z w : ℂ) : 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 : ℂ) : z.re * z.re ≤ norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : ℂ) : z.im * z.im ≤ norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : ℂ) : z * conj z = norm_sq z :=\next_iff.2 $ by simp [norm_sq, mul_comm, sub_eq_neg_add, add_comm]\n\nend complex\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_solns.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.7839987732003469}}
{"text": "import Basics.TypesAndTerms\n/-!\n## Type Definitions\n\nA distinguishing feature of Lean’s calculus of inductive constructions is its built-in\nsupport for inductive types. An _inductive type_ is a type whose values are built by\napplying special constants called _constructors_. Inductive types are a concise way\nof representing acyclic data in a program. You may know them under some other,\nlargely synonymous names, including algebraic data types, inductive data types,\nfreely generated data types, recursive data types, and data types.\n\n### Natural Numbers\n\nThe “Hello, World!” example of inductive types is the type `Nat` natural numbers.\nIn Lean, it can be defined as follows:\n-/\nnamespace my_nat\n\ninductive Nat where\n| zero : Nat\n| succ : Nat → Nat\n\nend my_nat\n/-!\nNote: we are placing this in a new nameapce `my_nat` so it does not conflict with the\nbuilt-in type.\n\nThe first line of the `inductive` type announces to the world that we are introducing a new type\ncalled `Nat`, intended to represent the natural numbers. The second and third line declare two new\nconstructors, `Nat.zero` which is of type `Nat` and `Nat.succ` which has the function type `Nat →\nNat`, that can be used to build values of type `Nat`. Following an established convention in\ncomputer science and logic, counting starts at zero. The second constructor is what makes this\ninductive definition interesting—it requires an argument of type `Nat` to produce a value of type\n`Nat`. The terms\n```lean\nNat.zero\nNat.succ Nat.zero\nNat.succ (Nat.succ Nat.zero)\n...\n```\ndenote the different values of type nat—zero, its successor, its successor’s successor, and so on.\nThis notation is called _unary_, or _Peano_, after the logician Giuseppe Peano. For an alternative\nexplanation of Peano numbers in Lean (and some groovy video game graphics), see Kevin Buzzard’s\narticle [Can computers prove theorems?](http://chalkdustmagazine.com/features/can-computers-prove-theorems/).\n\nThe general format of type declarations is\n```lean\ninductive type-name (params₁ : type₁) . . . (paramsₖ : typeₖ) : Type\n| constructor-name₁ : constructor-type₁\n.\n.\n.\n| constructor-nameₙ : constructor-typeₙ\n```\n\nYou can also use literals `0, 1, 2, . . .` and Lean will be able to infer that they are of type `Nat`\nwhen they are used in that context.\n\nWe can inspect an earlier definition at any point in Lean by using the `#print` command. For example,\n`#print Nat` within the `my_nat` namespace displays the following information:\n-/\n#print my_nat.Nat\n/-!\n```\ninductive my_nat.Nat : Type\nnumber of parameters: 0\nconstructors:\nmy_nat.Nat.zero : my_nat.Nat\nmy_nat.Nat.succ : my_nat.Nat → my_nat.Nat\n```\n\nThe focus on natural numbers is one of the many features of this guide that reveal a bias towards\ncomputer science. Number theorists would be more interested in the integers `ℤ` and the rational\nnumbers `ℚ`; analysts would want to work with the real numbers `ℝ` and the complex numbers `ℂ`. But the\nnatural numbers are ubiquitous in computer science and enjoy a very simple definition as an\ninductive type. They can also be used to build other types, as we will see in Chapter 13.\n\n### Arithmetic Expressions\n\nIf we were to specify a calculator program or a programming language, we would\nlikely need to define a type to represent arithmetic expressions. The next example\nshows how this could be done in Lean:\n-/\ninductive aexp  where\n| num : Int → aexp\n| var : String → aexp\n| add : aexp → aexp → aexp\n| sub : aexp → aexp → aexp\n| mul : aexp → aexp → aexp\n| div : aexp → aexp → aexp\n\n#check aexp.num 1     -- aexp.num 1 : aexp\n\n/-!\nMathematically, this definition is equivalent to defining the type `aexp` inductively\nby the following formation rules:\n\n1. For every integer `i`, we have that `aexp.num i` is an `aexp` value.\n2. For every character string `x`, we have that `aexp.var x` is an `aexp` value.\n3. If `e1` and `e2` are `aexp` values, then so are `aexp.add e1 e2`, `aexp.sub e1 e2`,\n`aexp.mul e1 e2`, and `aexp.div e1 e2`.\n\nThe above definition is exhaustive. The only possible values for `aexp` are those built using\nformation rules 1 to 3. Moreover, `aexp` values built using different formation rules are distinct.\nThese two properties of inductive types are captured by the motto “No junk, no confusion,” due to\nJoseph Goguen.\n\n### Comparison with Java\n\nIt may be instructive to compare the concise Lean specification of `aexp` above with a Java program\nthat achieves the same. The program consists of one interface and six classes that implement it,\ncorresponding to the `aexp` type and its six constructors:\n\n```java\npublic interface AExp { }\npublic class Num implements AExp {\n  public int num;\n  public Num(int num) { this.num = num; }\n}\npublic class Var implements AExp {\n  public String var;\n  public Var(String var) { this.var = var; }\n}\npublic class Add implements AExp {\n  public AExp left;\n  public AExp right;\n  public Add(AExp left, AExp right)\n  { this.left = left; this.right = right; }\n}\npublic class Sub implements AExp {\n  public AExp left;\n  public AExp right;\n  public Sub(AExp left, AExp right)\n  { this.left = left; this.right = right; }\n}\npublic class Mul implements AExp {\n  public AExp left;\n  public AExp right;\n  public Mul(AExp left, AExp right)\n  { this.left = left; this.right = right; }\n}\npublic class Div implements AExp {\n  public AExp left;\n  public AExp right;\n  public Div(AExp left, AExp right)\n  { this.left = left; this.right = right; }\n}\n```\n\n### Comparison with C\n\nIn C, the natural counterpart of an inductive type is a tagged union. The type\ndeclarations would be as follows:\n\n```C\n#include <stddef.h>\n#include <stdlib.h>\nenum AExpKind {\n  AET_NUM, AET_VAR, AET_ADD, AET_SUB, AET_MUL, AET_DIV\n};\nstruct aexp;\nstruct aexp_num {\n  int num;\n};\nstruct aexp_var {\n  char var[1024];\n};\nstruct aexp_binop {\n  struct aexp *left;\n  struct aexp *right;\n};\nstruct aexp {\n  enum AExpKind kind;\n  union {\n    struct aexp_num anum;\n    struct aexp_var avar;\n    struct aexp_binop abinop;\n  } data;\n};\n```\nCorresponding to each constructor in Lean, we would need to write a function\nto allocate an `aexp` object of the right size in memory. Here is the definition of the\nfunction corresponding to the first constructor, `aexp.num`:\n\n```C\nstruct aexp *create_num(int num)\n{\n  struct aexp *res = malloc(offsetof(struct aexp, data) +\n  sizeof(struct aexp_num));\n  res->kind = AET_NUM;\n  res->data.anum.num = num;\n  return res;\n}\n```\n\nThe subtle pointer arithmetic for the `malloc` call is needed to allocate exactly the\nright amount of memory.\n\n### Lists\n\nThe next type we consider is that of finite lists (shown here in a temporary namespace\nso it doesn't conflict with the same built-in type):\n-/\nnamespace my_list\n\ninductive List (α : Type) where\n  | nil : List α\n  | cons (head : α) (tail : List α) : List α\n\nend my_list\n/-!\nThe type is _polymorphic_: It is parameterized by a type α, which we can instantiate with concrete\ntypes. For example, `List ℤ`  is the type of lists over integers, and `List (List ℝ)` is the type of\nlists of lists of real numbers. The type constructor `List` takes a type as argument and returns a\ntype. Polymorphism is related to generics (in Java) and templates (in C++). The general idea in all\ncases is to have parameterized types.\n\nThe following commands display the constructors’ types:\n-/\n#check List.nil       -- [] : List ?m.6639\n#check List.cons      -- List.cons : ?m.6641 → List ?m.6641 → List ?m.6641\n\n/-!\nInformally:\n- The `nil` constructor takes a type α as argument and produces a result of type\n`List α`. The type was not defined here so you see `?m.6639` which represents\nan unresolved metavariable in the Lean compilation.\n- The `cons` constructor takes an element (the _head_) of some arbitrary type\n`?m.6641` as argument and a list over `?m.6641` (the tail) and produces a result of\ntype list `?m.6641`. Unlike for nil, there is no need to pass a type argument to\ncons—the type is inferred from the first argument. If we want to pass the type\nargument explicitly, we need to write an at sign (@) in front of the constant:\n`@List.cons`.\n-/\n#check @List.cons Nat   -- List.cons : ℕ → List ℕ → List ℕ\n/-!\nEven if we try to restrict ourselves to a fragment of Lean’s language, Lean often\nexposes us to more advanced constructs in the output, such as `?m.6641` above, `Sort u`,\nor `Type 1`. Our advice is to adopt a sporty attitude: Do not worry if you do not\nalways understand everything the first time. Use your common sense and your\nimagination. And, above all, do not hesitate to ask.\n\nLean’s built-in lists offer syntactic sugar for writing lists:\n\n- `[]` for `List.nil`\n- `x :: xs` for `List.cons x xs`\n- `[x₁, . . ., xₙ]` for `x₁ :: . . . :: xₙ :: []`\n\nThe `::` operator, like all other binary operators, binds less tightly than function\napplication. Thus, `f x :: reverse ys` is parsed as `(f x) :: (reverse ys)`. It is good\npractice to avoid needless parentheses. They can quickly impair readability. In\naddition, it is important to put spaces around infix operators, to suggest the right\nprecedence; it is all too easy to misread `f x::reverse ys` as `f (x::reverse) ys` otherwise.\n\nFunctional programmers often use plural names such as `xs`, `ys`, `zs` for lists\n(or more generally collections). A list contains many elements, so a plural form is natural.\nA list of `cat` objects might be called `cats`; a list of list of `cat` objects, `catss`.\nWhen a nonempty list is presented as a head and a tail, we usually write, say, `x :: xs` or `cat :: cats`.\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/Basics/TypeDefinitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7839987713282305}}
{"text": "\nimport logic.relation\n\nnamespace hidden \n\n/- Equality Propositions and Equality Relations\n\nWe will now shift focus to the specific binary \nrelation on any type, α, that we call equality.\nEquality in Lean is polymorphic: Given any type\n(in any type universe), we have a binary relation \non values of that type, of type α → α → Prop.\n-/\n\n-- Let's inspect the type of eq\n#check @eq\n-- eq : Π {α : Sort u_1}, α → α → Prop\n-- infix ` = `:50 := eq\n\n/-\nIn English, given any (Π) type, α, eq\ntakes two values of this type and reduces\nto the proposition that these two values\nare equal. So eq x y is the proposition,\nx = y, and in fact Lean provides = as an\ninfix notation: the one you're accustomed\nto from school days.\n-/\n\n-- These expressions mean the same thing\n#check eq 0 0\n#check 0 = 0\n\n\n/- PROOFS \n\nUp until now, all we've talked about is a mechanism,\neq, for generating propositions. What are the rules \nfor constructing and using proofs of equality? \n-/\n\n/- Inference rules\n\nEquality has two inference rules: an introduction rule, \neq.refl, and an elimination rule, eq.subst. All other \nproperties of equality come from these two rules and \nthe meaning of \"inductive definitions\" in Lean (as we'll \nsee in a bit). \n-/\n\n/- Introduction rule: eq.refl\n\nThe introduction rule establishes the fact (constructs\nproofs) that every object of any given type is equal to\nitself.\n-/\n\n#check @eq.refl\n-- ∀ {α : Sort u} (a : α), eq a a\n\n#check eq.refl 0\n-- eq 0 0, i.e., proof of 0 = 0\n\nexample : 0 = 0 := eq.refl 0\n\n-- When Lean can infer \"a\" you can use rfl.\nexample : 0 = 0 := rfl\n\n#check @rfl\n-- ∀ {α : Sort u_1} {a : α}, a = a\n\n/-\nNote: in our logic you can't form a proposition that \ntwo things of different types are equal. It's just a \ntype error, given the definition of eq.\n-/\n\n#check tt = \"hi\"    -- type error\n\n\n/- Elimination rule: eq.subst\n\nThe second axiom of equality defines its elimination \nrule: that is, how we can *use* a proof of an equality.\nIf you have a predicate, P : α → Prop, for some type, \nα, and if you know P a, and you know a = b, then you\ncan deduce P b.\n\nFor example Tom is from New York (FromNY Tom), and \nBob = Tom, the by eq.subst you can deduce FromNY Bob. \nHere's the rule formally.\n-/\n\n#check @eq.subst\n/- eq.subst : \n  ∀ {α : Sort u_1} \n  {P : α → Prop} \n  {a b : α}, \n  a = b →           -- if you know a = b\n  P a →             -- and if you know P a\n  P b               -- you can deduce P b\n-- in reverse, \n-- to show P b \n-- suffices P a and a = b\n-/\n\n/-\nWhat this rule really says is that if you \nhave a goal, P b, and you know a = b, you\ncan rewrite the goal as P a and the result\nwill be equivalent.\n\nThe following example sets up the use of \neq.subst. There are balls, balls can be \nblue, a and b are balls, a is b, and a is\nblue. The goal is to show that b is Blue.\nThat is done by applying eq.subst to the\nproof of equality of a and b, and to the\nproof that a is Blue. \n-/\n\nexample \n  (Ball : Type)\n  (Blue : Ball → Prop)\n  (a b : Ball)\n  (eq_balls : a = b)\n  (a_is_Blue : Blue a) :\n  Blue b := \neq.subst eq_balls a_is_Blue\n\n/-\nThis next example show that applying\neq.subst to a proof of a = b reduces\nthe goal of showing Blue b to that of\nshowing Blue a. In a sense, applying \neq.subst to an equality proof effects\na *rewriting* of the current goal. \n-/\nexample \n  (Ball : Type)\n  (Blue : Ball → Prop)\n  (a b : Ball)\n  (eq_balls : a = b)\n  (a_is_Blue : Blue a) :\n  Blue b :=\nbegin\n  -- Study the sequents before and after this step\n  apply eq.subst eq_balls,\n  assumption,  -- now we can use *this* proof!\nend\n\n/-\nLean provides a useful tactic called\nrewrite that automates application of\neq.subst to effect such rewritings. The\nfollowing two example illustate use of\ntwo different forms of the tactic. In\nshort, given h : a = b, \"rw h\" changes\na's in the goal to b's and rw<-h changes\nb's in the goal to a's.\n-/\n\nexample \n  (Ball : Type)\n  (Blue : Ball → Prop)\n  (a b : Ball)\n  (eq_balls : a = b)\n  (a_is_Blue : Blue a) :\n  Blue b := \nbegin\nrw<-eq_balls, -- rewrite b to a (right to left)\nassumption,\nend\n\n\n-- Exercise: complete the proof\nexample (α : Type) (a b : α) (P : α → Prop) : a = b → P b → P a :=\nbegin\nintros ab Pb,\nrw ab,\nassumption,\nend\n\n\n/- Properties of The Equality Relation -/\n\n/- Reflexivity \n\nIn English you can say a relation, r, is reflexive \nif it relates *every* value, x in its \"domain\" to x \nitself: that is ∀ x, r x x. Remember the relation r \nis specified by a two-place predicate. So ∀ x, r x x \nsays that *every* value, x, is related to itself by r.    \n-/\n\n#check @reflexive\n/-\nreflexive : Π {β : Sort v}, (β → β → Prop) → Prop\n\nΠ (capital Pi) means universal quantification. So, \nwhat reflexive says is that \"for any type, β (even \na propositional type), reflexive defines a property \nof any binary relation on β. \n\nPut another way, if you apply reflexive to any binary \nrelation on any type, β (inferred), you will get a \nproposition: the one that precisely expresses what \nit means for such a relation to be reflexive: that \nevery element of the domain is related to itself *in \nthat relation*.  \n\nFor example, the reflexive predicate applied to the \nequality relation yields the proposition that every\nvalue of a given type is related to itself by equality\nin this relation.\n-/\n\n#reduce reflexive (@eq nat)\n\n/- \nOf course, the introduction rule, refl, for equality\n*makes* the equality relation reflexive. It's reflexive\nby definition and so should be easy to prove.\n-/\n\nexample : ∀ (X : Type), reflexive (@eq X) :=\nbegin\nassume X,\nunfold reflexive,\n/- First axiom of equality: \n   X : Type ⊢ ∀ (x : X), x = x\n-/\nassume x,\n-- all the following are equivalent\n-- exact @eq.refl X x,  -- no arguments inferred\n-- exact eq.refl x,     -- one argument inferred\nexact rfl,              -- both arguments inferred\nend\n\n/-\nCongratulations, you have earned another sticker: \nthis one to recognize that you are now working with\nproperties of relations that in turn express \nproperties of sets of ordered pairs of values. \nThat's sorta cool!\n-/\n\n/- Symetric -/\n\n/-\nA relation is said to be symmetric if whenever\nany object a is related to some object b, then b\nis also related to a. The \"friends\" relation on\nFacebook is symmetric in this sense. \n-/\n\n#check @symmetric\n-- Π {β : Sort u_1}, (β → β → Prop) → Prop\n#reduce @symmetric\n-- ∀ ⦃x y : β⦄, x = y → y = x\n\n/-\nThere's the generalized, formal definition: if x and\ny are values (here of type nat), then if r x y then\nr y x. If r is eq, then this says if x = y then y = x.\n-/\n\n#check @symmetric\n#reduce @symmetric \n\n/-\nExercise: prove that = is symmetric. And\nanswer the question, is ≤ symmetric, and\ngive a brief defense of your answer. If \nyour answer is no, provide a counter-example\nto show that you are correct.\n-/\n\nexample (α : Type): symmetric (@eq α) :=\nbegin\nunfold symmetric,\nassume x y e,\nrw e,\nend \n\nexample (α : Type) : transitive (@eq α) :=\nbegin\nunfold transitive,\nassume x y z xy yz,\nrw <- yz,\nassumption,\nend \n\n\nend hidden\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/04_equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.9005297794439688, "lm_q1q2_score": 0.783998766104303}}
{"text": "import data.set.basic data.set.lattice data.nat.parity\nimport tactic.linarith\n\nopen set nat function\n\nopen_locale classical\n\nvariables {α : Type*} {β : Type*} {γ : Type*} {I : Type*}\n\n/-!\n## Set exercises\n\nThese are collected from *Mathematics in Lean*.\n\nWe will go over the examples together, and then let you\nwork on the exercises.\n\nThere is more material here than can fit in the sessions,\nbut we will pick and choose as we go.\n-/\n\nsection set_variables\n\nvariable  x : α\nvariables s t u : set α\n\n/-!\n### Notation\n-/\n\n#check s ⊆ t        -- \\sub\n#check x ∈ s        -- \\in or \\mem\n#check x ∉ s        -- \\notin\n#check s ∩ t        -- \\i or \\cap\n#check s ∪ t        -- \\un or \\cup\n#check (∅ : set α)  -- \\empty\n\n/-!\n### Examples\n-/\n\n-- Three proofs of the same fact.\n-- The first two expand definitions explicitly,\n-- while the third forces Lean to do the unfolding.\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  rw [subset_def, inter_def, inter_def],\n  rw subset_def at h,\n  dsimp,\n  rintros x ⟨xs, xu⟩,\n  exact ⟨h _ xs, xu⟩,\nend\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  simp only [subset_def, mem_inter_iff] at *,\n  rintros x ⟨xs, xu⟩,\n  exact ⟨h _ xs, xu⟩,\nend\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  intros x xsu,\n  exact ⟨h xsu.1, xsu.2⟩\nend\n\n-- Use `cases` or `rcases` or `rintros` with union.\n-- Two proofs of the same fact, one longer and one shorter.\n\nexample : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) :=\nbegin\n  intros x hx,\n  have xs : x ∈ s := hx.1,\n  have xtu : x ∈ t ∪ u := hx.2,\n  cases xtu with xt xu,\n  { left,\n    show x ∈ s ∩ t,\n    exact ⟨xs, xt⟩ },\n  right,\n  show x ∈ s ∩ u,\n  exact ⟨xs, xu⟩\nend\n\nexample : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) :=\nbegin\n  rintros x ⟨xs, xt | xu⟩,\n  { left, exact ⟨xs, xt⟩ },\n  right, exact ⟨xs, xu⟩\nend\n\n-- Two examples with set difference.\n-- Type it as ``\\\\``.\n-- ``x ∈ s \\ t`` expands to ``x ∈ s ∧ x ∉ t``.\n\nexample : s \\ t \\ u ⊆ s \\ (t ∪ u) :=\nbegin\n  intros x xstu,\n  have xs : x ∈ s := xstu.1.1,\n  have xnt : x ∉ t := xstu.1.2,\n  have xnu : x ∉ u := xstu.2,\n  split,\n  { exact xs }, dsimp,\n  intro xtu, -- x ∈ t ∨ x ∈ u\n  cases xtu with xt xu,\n  { show false, from xnt xt },\n  show false, from xnu xu\nend\n\nexample : s \\ t \\ u ⊆ s \\ (t ∪ u) :=\nbegin\n  rintros x ⟨⟨xs, xnt⟩, xnu⟩,\n  use xs,\n  rintros (xt | xu); contradiction\nend\n\n/-!\n### Exercises\n-/\n\nexample : (s ∩ t) ∪ (s ∩ u) ⊆ s ∩ (t ∪ u):=\nsorry\n\nexample : s \\ (t ∪ u) ⊆ s \\ t \\ u :=\nsorry\n\n/-!\n### Proving two sets are equal\n-/\n\n-- the ext tactic\n\nexample : s ∩ t = t ∩ s :=\nbegin\n  ext x,\n  -- simp only [mem_inter_iff],  -- optional.\n  split,\n  { rintros ⟨xs, xt⟩, exact ⟨xt, xs⟩ },\n  rintros ⟨xt, xs⟩, exact ⟨xs, xt⟩\nend\n\nexample : s ∩ t = t ∩ s :=\nby ext x; simp [and.comm]\n\n/-!\n### Exercises\n-/\n\nexample : s ∩ (s ∪ t) = s :=\nsorry\n\nexample : s ∪ (s ∩ t) = s :=\nsorry\n\nexample : (s \\ t) ∪ t = s ∪ t :=\nsorry\n\nexample : (s \\ t) ∪ (t \\ s) = (s ∪ t) \\ (s ∩ t) :=\nsorry\n\n/-!\n### Set-builder notation\n-/\n\ndef evens : set ℕ := {n | even n}\ndef odds :  set ℕ := {n | ¬ even n}\n\nexample : evens ∪ odds = univ :=\nbegin\n  rw [evens, odds],\n  ext n,\n  simp,\n  apply classical.em\nend\n\nexample : s ∩ t = {x | x ∈ s ∧ x ∈ t} := rfl\nexample : s ∪ t = {x | x ∈ s ∨ x ∈ t} := rfl\nexample : (∅ : set α) = {x | false} := rfl\nexample : (univ : set α) = {x | true} := rfl\n\nexample (x : ℕ) (h : x ∈ (∅ : set ℕ)) : false :=\nh\n\nexample (x : ℕ) : x ∈ (univ : set ℕ) :=\ntrivial\n\n/-!\n### Exercise\n-/\n\n-- Use `intro n` to unfold the definition of subset,\n-- and use the simplifier to reduce the\n-- set-theoretic constructions to logic.\n-- We also recommend using the theorems\n-- ``prime.eq_two_or_odd`` and ``even_iff``.\n\nexample : { n | nat.prime n } ∩ { n | n > 2} ⊆ { n | ¬ even n } :=\nsorry\n\n/-!\nIndexed unions\n-/\n\n-- See *Mathematics in Lean* for a discussion of\n-- bounded quantifiers, which we will skip here.\n\nsection\n\n-- We can use any index type in place of ℕ\nvariables A B : ℕ → set α\n\nexample : s ∩ (⋃ i, A i) = ⋃ i, (A i ∩ s) :=\nbegin\n  ext x,\n  simp only [mem_inter_iff, mem_Union],\n  split,\n  { rintros ⟨xs, ⟨i, xAi⟩⟩,\n    exact ⟨i, xAi, xs⟩ },\n  rintros ⟨i, xAi, xs⟩,\n  exact ⟨xs, ⟨i, xAi⟩⟩\nend\n\nexample : (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_iff, 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 ⟨h1, h2⟩ i,\n  split,\n  { exact h1 i },\n  exact h2 i\nend\n\nend\n\n/-!\n### Exercise\n-/\n\n-- One direction requires classical logic!\n-- We recommend using ``by_cases xs : x ∈ s``\n-- at an appropriate point in the proof.\n\nsection\n\nvariables A B : ℕ → set α\n\nexample : s ∪ (⋂ i, A i) = ⋂ i, (A i ∪ s) :=\nsorry\n\nend\n\n/-\nMathlib also has bounded unions and intersections,\n`⋃ x ∈ s, f x` and `⋂ x ∈ s, f x`,\nand set unions and intersections, `⋃₀ s` and `⋂₀ s`,\nwhere `s : set α`.\n\nSee *Mathematics in Lean* for details.\n-/\n\nend set_variables\n\n/-!\n### Functions\n-/\n\nsection function_variables\n\nvariable  f : α → β\nvariables s t : set α\nvariables u v : set β\nvariable  A : I → set α\nvariable  B : I → set β\n\n#check f '' s\n#check image f s\n#check f ⁻¹' u    -- type as \\inv' and then hit space or tab\n#check preimage f u\n\nexample : f '' s = {y | ∃ x, x ∈ s ∧ f x = y} := rfl\nexample : f ⁻¹' u = {x | f x ∈ u } := rfl\n\nexample : f ⁻¹' (u ∩ v) = f ⁻¹' u ∩ f ⁻¹' v :=\nby { ext, refl }\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y, split,\n  { rintros ⟨x, xs | xt, rfl⟩,\n    { left, use [x, xs] },\n    right, use [x, xt] },\n  rintros (⟨x, xs, rfl⟩ | ⟨x, xt, rfl⟩),\n  { use [x, or.inl xs] },\n  use [x, or.inr xt]\nend\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nbegin\n  intros x xs,\n  show f x ∈ f '' s,\n  use [x, xs]\nend\n\n/-!\n### Exercises\n-/\n\nexample : f '' s ⊆ u ↔ s ⊆ f ⁻¹' u :=\nsorry\n\nexample (h : injective f) : f ⁻¹' (f '' s) ⊆ s :=\nsorry\n\nexample : f '' (f⁻¹' u) ⊆ u :=\nsorry\n\nexample (h : surjective f) : u ⊆ f '' (f⁻¹' u) :=\nsorry\n\nexample (h : s ⊆ t) : f '' s ⊆ f '' t :=\nsorry\n\nexample (h : u ⊆ v) : f ⁻¹' u ⊆ f ⁻¹' v :=\nsorry\n\nexample : f ⁻¹' (u ∪ v) = f ⁻¹' u ∪ f ⁻¹' v :=\nsorry\n\nexample : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=\nsorry\n\nexample (h : injective f) : f '' s ∩ f '' t ⊆ f '' (s ∩ t) :=\nsorry\n\nexample : f '' s \\ f '' t ⊆ f '' (s \\ t) :=\nsorry\n\nexample : f ⁻¹' u \\ f ⁻¹' v ⊆ f ⁻¹' (u \\ v) :=\nsorry\n\nexample : f '' s ∩ v = f '' (s ∩ f ⁻¹' v) :=\nsorry\n\nexample : f '' (s ∩ f ⁻¹' u) ⊆ f '' s ∪ u :=\nsorry\n\nexample : s ∩ f ⁻¹' u ⊆ f ⁻¹' (f '' s ∩ u) :=\nsorry\n\nexample : s ∪ f ⁻¹' u ⊆ f ⁻¹' (f '' s ∪ u) :=\nsorry\n\nexample : f '' (⋃ i, A i) = ⋃ i, f '' A i :=\nsorry\n\nexample : f '' (⋂ i, A i) ⊆ ⋂ i, f '' A i :=\nsorry\n\nexample (i : I) (injf : injective f) : (⋂ i, f '' A i) ⊆ f '' (⋂ i, A i) :=\nsorry\n\nexample : f ⁻¹' (⋃ i, B i) = ⋃ i, f ⁻¹' (B i) :=\nsorry\n\nexample : f ⁻¹' (⋂ i, B i) = ⋂ i, f ⁻¹' (B i) :=\nsorry\n\n/-\nThere is a lot more in *Mathematics in Lean* that we will not have time for!\nThere is a discussion of injectivity, more exercises on images and ranges,\nand a discussion of inverses.\n\nBut we will close with on last exercise. Remember that `surjective f`\nsays `∀ y, ∃ x, f x = y`.\n\nSee if you can understand the proof of Cantor's famous theorem that there is no\nsurjective function from its set to its powerset, and\nfill in the two lines that are missing.\n-/\n\ntheorem Cantor : ∀ f : α → set α, ¬ surjective f :=\nbegin\n  intros f surjf,\n  let S := { i | i ∉ f i},\n  rcases surjf S with ⟨j, h⟩,\n  have h₁ : j ∉ f j,\n  { intro h',\n    have : j ∉ f j,\n      { by rwa h at h' },\n    contradiction },\n  have h₂ : j ∈ S,\nsorry\n    ,\n  have h₃ : j ∉ S,\nsorry\n    ,\n  contradiction\nend\n\nend function_variables\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/tuesday/sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7839196580704145}}
{"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 :=\nbegin\n  cases a,\n  cases b,\n  rw fraction.mk.inj_eq,\n  exact and.intro h h'\nend\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    begin\n      intros,\n      apply fraction.ext,\n      repeat {\n        simp [fraction.mul_num, fraction.mul_denom],\n        ac_refl }\n    end,\n  ..fraction.has_mul }\n\n/- 1.3. Extending the `myℚ.has_mul` instance from the lecture, declare `myℚ` an\ninstance of `semigroup`.\n\nHint: The lemma `quotient.induction_on₃` might be useful. -/\n\n#check quotient.induction_on₃\n\ninstance myℚ.semigroup : semigroup myℚ :=\n{ mul_assoc :=\n    begin\n      intros a b c,\n      apply quotient.induction_on₃ a b c,\n      intros x y z,\n      apply quotient.sound,\n      rw mul_assoc,\n    end,\n  ..myℚ.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 (α : Type) : Type\n    | empty {} : btree\n    | node     : α → btree → btree → btree\n\nWe defined a function `mirror` on these binary trees as follows:\n\n    def mirror {α : Type} : btree α → btree α\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 {α : Type} :\n      ∀t : btree α, mirror (mirror t) = t -/\n\n/- We perform the proof by structural induction on `t`.\n\nCase `empty`: The goal is `mirror (mirror empty) = empty`. This holds by the\ndefinition of `mirror`.\n\nCase `node a l r`: The induction hyptheses are `mirror (mirror l) = l` and\n`mirror (mirror r) = r`. The goal is\n`mirror (mirror (node a l r)) = node a l r`.\n\nWe have:\n\n    mirror (mirror (node a l r))\n    = mirror (node a (mirror r) (mirror l))           -- by definition of mirror\n    = node a (mirror (mirror l)) (mirror (mirror r))) -- by definition of mirror\n    = node a l r                                      -- by the IHs\n\nQED -/\n\n/- 2.2. Prove the same lemma in Lean and compare it with your paper proof. -/\n\nlemma mirror_mirror₂ {α : Type} :\n  ∀t : btree α, mirror (mirror t) = t :=\nbegin\n  intro t,\n  induction t with a l r ihl ihr,\n  { rw mirror,\n    rw mirror },\n  { rw mirror,\n    rw mirror,\n    rw ihl,\n    rw ihr }\nend\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 : ℕ → Prop\n    | zero    : even 0\n    | add_two : ∀n, even n → 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 : ℕ) (h : even n) :\n      ∃k : ℕ, n = 2 * k -/\n\n/- We perform the proof by rule induction on `h`.\n\nCase `zero`: The goal is `∃k : ℕ, 0 = 2 * k`. We use k = 0. The remaining goal\nis `0 = 2 * 0`, which is obviously true.\n\nCase `add_two`: The induction hypothesis is `∃k : ℕ, n = 2 * k`.  The goal is\n`∃k : ℕ, n + 2 = 2 * k`.\n\nThe induction hypothesis gives us a number `k`, such that `n = 2 * k`. We use\n`k + 1` to instantiate the existential quantifier in the goal. This yields the\ngoal `n + 2 = 2 * (k + 1)`.\n\nUsing the fact `n = 2 * k`, we can rewrite the goal into\n`(2 * k) + 2 = 2 * (k + 1)`, which is obviously true. QED -/\n\n/- 3.2. Prove the same lemma in Lean and compare it with your paper proof. -/\n\nlemma exists_of_even (n : ℕ) (h : even n) :\n  ∃k : ℕ, n = 2 * k :=\nbegin\n  induction h with n h ih,\n  { use 0,\n    refl },\n  { cases ih with k hk,\n    use k + 1,\n    rw hk,\n    refl }\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/love13_rational_and_real_numbers_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7838842067729405}}
{"text": "import combinatorics.simple_graph.basic\nimport combinatorics.simple_graph.subgraph\nimport simple_graph_aux\nimport finset_fintype_aux\n\nnamespace complete_graph\n\nopen simple_graph\n\nuniverse u\n\nvariables {V : Type u} [fintype V] [decidable_eq V]  \nvariable (G : simple_graph V)\n\nlemma edge_to_finset_powerset_len_two_surj : \n∀ s, ∃ e, ∃ e_in, \n  (complete_graph V).edge_to_finset_powerset_len_two e e_in = s :=\nbegin\n  rintro ⟨s, s_in⟩,\n  rw finset.mem_powerset_len at s_in,\n  cases s_in with s_subset card_s,\n  rw finset.card_eq_two at card_s,\n  rcases card_s with ⟨v₁, v₂, v₁_ne_v₂, hs⟩,\n  use ⟦(v₁, v₂)⟧,\n  simp only [mem_edge_set, complete_graph_eq_top, top_adj],\n  use v₁_ne_v₂,\n  unfold edge_to_finset_powerset_len_two,\n  simp only [sym2.lift_mk, subtype.coe_mk, subtype.mk_eq_mk],\n  exact hs.symm,\nend\n\nlemma card_edge_finset : \n(complete_graph V).edge_finset.card = (fintype.card V).choose 2 :=\nbegin\n  suffices : (complete_graph V).edge_finset.card = \n    (finset.powerset_len 2 (finset.univ : finset V)).card,\n  { rw this,\n    exact finset.card_powerset_len _ _, },\n  unfold simple_graph.edge_finset,\n  refine finset.card_congr \n    (λ e, λ e_in, \n      ((complete_graph V).edge_to_finset_powerset_len_two \n        e (by rwa ← set.mem_to_finset)).val) _ _ _,\n  { simp only [subtype.val_eq_coe, finset.coe_mem, implies_true_iff], },\n  { simp_rw set.mem_to_finset,\n    simp_rw subtype.val_inj,\n    exact (complete_graph V).edge_to_finset_powerset_len_two_inj, },\n  { intros s s_in,\n    have h_surj := edge_to_finset_powerset_len_two_surj ⟨s, s_in⟩,\n    simp_rw ← subtype.val_inj at h_surj,\n    simp_rw set.mem_to_finset,\n    exact h_surj, },\nend\n\ntheorem edge_set_nonempty (hV : fintype.card V ≥ 2) : \n((complete_graph V).edge_set).nonempty :=\nbegin\n  unfold set.nonempty,\n  unfold simple_graph.edge_set,\n  rcases fintype.ex_x_ne_y_of_card_ge_two hV with ⟨v₁, v₂, v₁_ne_v₂⟩,\n  use ⟦(v₁, v₂)⟧, \n  -- Lean infers that ⟦(x, y)⟧ is an edge using hxy and closes the goal early\nend\n\ntheorem edge_finset_nonempty (hV : fintype.card V ≥ 2) :\n((complete_graph V).edge_finset).nonempty :=\nbegin\n  unfold edge_finset,\n  rw ← finset.coe_nonempty,\n  rw set.coe_to_finset,\n  exact edge_set_nonempty hV,\nend\n\nend complete_graph", "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/complete_graph_aux.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7838841989014979}}
{"text": "import game.sup_inf.infSumSets\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 7\n\nAnother level that showcases the infimum.\n-/\n\ndef sum_set_const (A : set ℝ) (c : ℝ) := { x : ℝ | ∃ y ∈ A, x = y + c}\n\n\n/- Lemma\nIf $A$ is a set of reals, then\n$$ \\textrm{inf} (c + A) = c + \\textrm{inf} (A)$$\n-/\nlemma inf_sum_set_const (A : set ℝ) (h1A : A.nonempty)\n  (h2A : bdd_below A) (a : ℝ) (c : ℝ): \n  (is_glb A a) → is_glb (sum_set_const A c) (c + a) :=\nbegin\n  intro h,\n  cases h with hA hB,\n  split,\n  -- prove that (c+a) is a lower bound\n  intros x h0,\n  cases h0 with y h1,\n  cases h1 with yA h2,\n  { have h2 := hA yA, linarith, },\n  -- prove that (c+a) is the GLB\n  intros L hL,\n  have h3 : L - c ∈ lower_bounds A,\n    intros y hy,\n    set x := y + c with hx,\n    have h31 : x ∈ sum_set_const A c,\n      unfold sum_set_const, \n      split, swap, use y, split, exact hy, exact hx,\n    have h32 := hL h31, rw hx at h32, linarith,\n  have h4 := hB h3, linarith,\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/infSumConst.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661945, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7837871682609788}}
{"text": "/- Recursive functions -/\n\n#print Nat -- Nat is an inductive datatype\n\ndef fib (n : Nat) : Nat :=\n  match n with\n  | 0 => 1\n  | 1 => 1\n  | n+2 => fib (n+1) + fib n\n\nexample : fib 5 = 8 := rfl\n\nexample : fib (n+2) = fib (n+1) + fib n := rfl\n\n#print fib\n/-\ndef fib : Nat → Nat :=\nfun n =>\n  Nat.brecOn n fun n f =>\n    (match (motive := (n : Nat) → Nat.below n → Nat) n with\n      | 0 => fun x => 1\n      | 1 => fun x => 1\n      | Nat.succ (Nat.succ n) => fun x => x.fst.fst + x.fst.snd.fst.fst)\n      f\n-/\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/doc/examples/NFM2022/nfm7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750413739076, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.783772373262141}}
{"text": "import tutorial_world.incidenceplane --hide\nopen IncidencePlane --hide\n\n/- Axiom :\nincidence (P Q : Point) (ℓ : Line) : P ≠ Q → P ∈ ℓ → Q ∈ ℓ → ℓ = line_through P Q\n-/\n\n/- Tactic : intro\n\n## Summary:\n\n`intro p` will turn a goal `⊢ P → Q` into a hypothesis `p : P`\nand goal `⊢ 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 `⊢ P → Q` then `intro`\nwill always make progress. `intro p` turns\n\n`⊢ P → Q`\n\ninto \n\n```\np : P\n⊢ Q\n```\n\nThe opposite tactic to intro is `revert`; given the situation\njust above, `revert p` turns the goal back into `⊢ P → Q`.\n\n**Variant:** Instead of calling `intro` multiple times, you can use\n`intros`. That is, `intros h₁ h₂` is equivalent to `intro h₁, intro h₂`.\n\n## Example\n\nIf your goal is an implication $P\\implies Q$ then Lean writes\nthis as `⊢ P → 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 `⊢ Q` and the hypothesis `p : P`\nappears in the local context.\n\n-/\n\n/-\n#Tutorial World\n\n## Level 6: the `intro` tactic.\n\nThis level introduces the `intro` tactic. This allows you to create\na new hypothesis in the local context, just above the goal with the `⊢` symbol, whenever you see\nthe **`→`** symbol in the \"goal\" section. [**Remember:** the **`→`** symbol refers to the idea of \nan **implication**. `P → Q` is read as \"P implies Q\" and interpreted as \"If P happens, then Q also happens\".]  \nIn Lean, if we have the goal `⊢ IT RAINS → I GET WET`, by typing `intro h` we will get a new hypothesis in \nthe local context of the type `h : IT RAINS` and the goal will just change into  `⊢ I GET WET`.\n\nTo solve this level, you will need to use a new statement that has been added to the list of \"Theorem statements\": \n\n* incidence (P Q : Point) (ℓ : Line) : P ≠ Q → P ∈ ℓ → Q ∈ ℓ → ℓ = line_through P Q\n\nNow, delete the `sorry` and note how the goal changes into a list of implications. [**Pro tip:** instead of writing \nseveral lines of code with the `intro` tactic, try to use the `intros` tactic. This will make the computer understand \nthat you want to create more than one hypothesis at the same time.] For example, if you type `intros h1 h2 h3 h4,`, four \nnew hypotheses will be added to your local context. Once you've added all the possible hypotheses to it, try to compare\nthe goal with the `incidence` statement. Did you notice that we can `rewrite` that statement? Because we have the first\nthree **hypotheses** of the statement, we can change the line `r` into `line_through A B`! Type `rewrite h1 h2 h4,` and \nsee how the goal changes. To close the goal, try to apply the same argument to the line `s`. \n\nBewildered? Click on the box right below for a hint.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nIn case you wrote `intros h1 h2 h3 h4 h5,` in the first line, after typing `rewrite h1 h2 h4,`, click on enter and\nwrite `rewrite h1 h3 h5,`. Now, the goal should change into `⊢ line_through A B = line_through A B`, but Lean finishes the \nproof for us because it realises that automatically!\n-/\n\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\nvariables {A B : Ω} {r s : Line Ω} -- hide\n\n/- Lemma :\nIf two lines contain two distinct points, then they are the same line.\n-/\nlemma equal_lines_of_contain_two_points :\nA ≠ B → A ∈ r → A ∈ s → B ∈ r → B ∈ s → r = s :=\nbegin\n\n  intros h1 h2 h3 h4 h5,\n  rewrite incidence h1 h2 h4,\n  rewrite incidence h1 h3 h5,\n\nend\n\n/-\n## Another proof for the same level\n\nMathematics is not \"black or white\". We can provide different proofs to solve the same lemma. In the explanation showed above, \nwe've seen how we the goal changes into `⊢ line_through A B = s` after writing `rewrite h1 h2 h4`. But, what would happen if we type\n`rewrite h1 h3 h5` just before that line? If you try it, you will see that the goal changes into `⊢ r = line_through A B`. Make an\neffort to understand why that happens so that you're ready to face the next level with ease! \n \n-/\n\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/level06_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8757869997529962, "lm_q1q2_score": 0.783644984385664}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar si a es el límite de s, entonces\n--     ∃ N b, ∀ n, N ≤ n → abs (s n) < b :=\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_convergencia\n\nvariables {s : ℕ → ℝ} {a : ℝ}\n\ntheorem exists_abs_le_of_converges_to\n  (cs : converges_to s a)\n  : ∃ N b, ∀ n, N ≤ n → 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  calc abs (s n)\n           = abs (s n - a + a)     : by ring\n       ... ≤ abs (s n - a) + abs a : abs_add (s n - a) a\n       ... < 1 + abs a             : by exact add_lt_add_right h (abs a)\n       ... = abs a + 1             : by exact add_comm 1 (abs a),\nend\n\n-- Prueba\n-- ======\n\n/-\ns : ℕ → ℝ,\na : ℝ,\ncs : converges_to s a\n⊢ ∃ (N : ℕ) (b : ℝ), ∀ (n : ℕ), N ≤ n → abs (s n) < b\n  >> cases cs 1 zero_lt_one with N h,\nN : ℕ,\nh : ∀ (n : ℕ), n ≥ N → abs (s n - a) < 1\n⊢ ∃ (N : ℕ) (b : ℝ), ∀ (n : ℕ), N ≤ n → abs (s n) < b\n  >> use [N, abs a + 1],\n⊢ ∀ (n : ℕ), N ≤ n → abs (s n) < abs a + 1\n  >> intros n hn,\nn : ℕ,\nhn : N ≤ n\n⊢ abs (s n) < abs a + 1\n  >> specialize h n hn,\nh : abs (s n - a) < 1\n⊢ abs (s n) < abs a + 1\n  >> calc abs (s n)\n  >>          = abs (s n - a + a)     : by ring\n  >>      ... ≤ abs (s n - a) + abs a : by apply abs_add_le_abs_add_abs\n  >>      ... < 1 + abs a             : by exact add_lt_add_right h (abs a)\n  >>      ... = abs a + 1             : by exact add_comm 1 (abs a),\nno goals\n-/\n\n-- Comentario: Se usan los lemas\n-- + zero_lt_one : 0 < 1\n-- + abs_add_le_abs_add_abs a b : abs (a + b) ≤ abs a + abs b\n-- + add_lt_add_right : a < b → ∀ (c : ℝ), a + c < b + c\n-- + add_comm a b : a + b = b + a\n\n-- Comprobación:\n-- variable (b : ℝ)\n-- #check @zero_lt_one _ _\n-- #check @abs_add_le_abs_add_abs _ _ a b\n-- #check @add_lt_add_right _ _ a b\n-- #check @add_comm _ _ a 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/Logica/Acotacion_de_convergentes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.7836449757342933}}
{"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 data.finsupp.defs\n\n/-!\n# Locus of unequal values of finitely supported functions\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nLet `α N` be two Types, assume that `N` has a `0` and let `f g : α →₀ N` be finitely supported\nfunctions.\n\n## Main definition\n\n* `finsupp.ne_locus f g : finset α`, the finite subset of `α` where `f` and `g` differ.\n\nIn the case in which `N` is an additive group, `finsupp.ne_locus f g` coincides with\n`finsupp.support (f - g)`.\n-/\n\nvariables {α M N P : Type*}\n\nnamespace finsupp\nvariable [decidable_eq α]\n\nsection N_has_zero\nvariables [decidable_eq N] [has_zero N] (f g : α →₀ N)\n\n/--  Given two finitely supported functions `f g : α →₀ 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 : α →₀ N) : finset α :=\n(f.support ∪ g.support).filter (λ x, f x ≠ g x)\n\n@[simp] lemma mem_ne_locus {f g : α →₀ N} {a : α} : a ∈ f.ne_locus g ↔ f a ≠ 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 : α →₀ N} {a : α} : a ∉ f.ne_locus g ↔ f a = g a :=\nmem_ne_locus.not.trans not_ne_iff\n\n@[simp] lemma coe_ne_locus : ↑(f.ne_locus g) = {x | f x ≠ g x} :=\nby { ext, exact mem_ne_locus }\n\n@[simp] lemma ne_locus_eq_empty {f g : α →₀ N} : f.ne_locus g = ∅ ↔ f = g :=\n⟨λ h, ext (λ a, not_not.mp (mem_ne_locus.not.mp (finset.eq_empty_iff_forall_not_mem.mp h a))),\n  λ h, h ▸ by simp only [ne_locus, ne.def, eq_self_iff_true, not_true, finset.filter_false]⟩\n\n@[simp] lemma nonempty_ne_locus_iff {f g : α →₀ N} : (f.ne_locus g).nonempty ↔ f ≠ 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 : α →₀ N).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\nlemma subset_map_range_ne_locus [decidable_eq N] [has_zero N] [decidable_eq M] [has_zero M]\n  (f g : α →₀ N) {F : N → M} (F0 : F 0 = 0) :\n  (f.map_range F F0).ne_locus (g.map_range F F0) ⊆ f.ne_locus g :=\nλ x, by simpa only [mem_ne_locus, map_range_apply, not_imp_not] using congr_arg F\n\nlemma zip_with_ne_locus_eq_left [decidable_eq N] [has_zero M] [decidable_eq P] [has_zero P]\n  [has_zero N] {F : M → N → P} (F0 : F 0 0 = 0)\n  (f : α →₀ M) (g₁ g₂ : α →₀ N) (hF : ∀ f, function.injective (λ g, F f g)) :\n  (zip_with F F0 f g₁).ne_locus (zip_with F F0 f g₂) = g₁.ne_locus g₂ :=\nby { ext, simpa only [mem_ne_locus] using (hF _).ne_iff }\n\nlemma zip_with_ne_locus_eq_right [decidable_eq M] [has_zero M] [decidable_eq P] [has_zero P]\n  [has_zero N] {F : M → N → P} (F0 : F 0 0 = 0)\n  (f₁ f₂ : α →₀ M) (g : α →₀ N) (hF : ∀ g, function.injective (λ f, F f g)) :\n  (zip_with F F0 f₁ g).ne_locus (zip_with F F0 f₂ g) = f₁.ne_locus f₂ :=\nby { ext, simpa only [mem_ne_locus] using (hF _).ne_iff }\n\nlemma map_range_ne_locus_eq [decidable_eq N] [decidable_eq M] [has_zero M] [has_zero N]\n  (f g : α →₀ N) {F : N → M} (F0 : F 0 = 0) (hF : function.injective F) :\n  (f.map_range F F0).ne_locus (g.map_range F F0) = f.ne_locus g :=\nby { ext, simpa only [mem_ne_locus] using hF.ne_iff }\n\nend ne_locus_and_maps\n\nvariables [decidable_eq N]\n\n@[simp] lemma ne_locus_add_left [add_left_cancel_monoid N] (f g h : α →₀ N) :\n  (f + g).ne_locus (f + h) = g.ne_locus h :=\nzip_with_ne_locus_eq_left _ _ _ _ add_right_injective\n\n@[simp] lemma ne_locus_add_right [add_right_cancel_monoid N] (f g h : α →₀ N) :\n  (f + h).ne_locus (g + h) = f.ne_locus g :=\nzip_with_ne_locus_eq_right _ _ _ _ add_left_injective\n\nsection add_group\nvariables [add_group N] (f f₁ f₂ g g₁ g₂ : α →₀ N)\n\n@[simp] lemma ne_locus_neg_neg : ne_locus (-f) (-g) = f.ne_locus g :=\nmap_range_ne_locus_eq _ _ neg_zero neg_injective\n\nlemma ne_locus_neg : ne_locus (-f) g = f.ne_locus (-g) := by rw [←ne_locus_neg_neg, neg_neg]\n\nlemma ne_locus_eq_support_sub : f.ne_locus g = (f - g).support :=\nby rw [←ne_locus_add_right _ _ (-g), add_right_neg, ne_locus_zero_right, sub_eq_add_neg]\n\n@[simp] lemma ne_locus_sub_left : ne_locus (f - g₁) (f - g₂) = ne_locus g₁ g₂ :=\nby simp only [sub_eq_add_neg, ne_locus_add_left, ne_locus_neg_neg]\n\n@[simp] lemma ne_locus_sub_right : ne_locus (f₁ - g) (f₂ - g) = ne_locus f₁ f₂ :=\nby simpa only [sub_eq_add_neg] using ne_locus_add_right _ _ _\n\n@[simp] lemma ne_locus_self_add_right : ne_locus f (f + g) = g.support :=\nby rw [←ne_locus_zero_left, ←ne_locus_add_left 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] \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 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/ne_locus.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7836128231180712}}
{"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, α, is reflexive, we\nmean that for any value, a, of type, α, _______.\n\nANSWER: a = a\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    1 = 1\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: reflexive, binary, 1\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 := eq.refl 1\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 : 4 = 2 + 2 := eq.refl 4\n\n-- ANSWER Does eq.refl work as suggested? Yes\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• 2 is even\n• To prove that two is even, *it will suffice* to show that 0 is even, because if 0 is even then, given that 2 is two more than 0, if 0 is even then so is 2 by rule (2). We can prove that 0 is even by applying rule (1).\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α → Prop, where α 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 ℕ → 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 ∀ 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 : ℕ → Prop\n| pf_zero_is_even : (is_even 0)\n| pf_even_plus_two_is_even : \n    ∀ (n : ℕ), is_even n → 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    is_even.pf_zero_is_even\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    is_even.pf_even_plus_two_is_even (0) pf_zero_is_even --wtf\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    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 pf_zero_is_even,\n      -- 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\n\ninductive is_odd : ℕ → Prop\n| pf_one_is_odd : (is_odd 1)\n| pf_odd_plus_two_is_odd : \n    ∀ (n : ℕ), is_odd n → is_odd (nat.succ (nat.succ n))\n\n \n-- ANSWER\n\ntheorem one_odd : is_odd 1 := is_odd.pf_one_is_odd\n\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 : ℕ | 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 : ℕ, n : ℕ) | m = n }\n\nWe formalize binary relations as predicates with \n*two* arguments. The type of such a predicate in \nLean is thus α → β → Prop, where α and β 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 : ℕ → ℕ → Prop\n| mk : ∀ (n m : ℕ), n = m → 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 3 3 (eq.refl 3)\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\nThis is because there is no proof for 3 = 5.\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 {α : Type} (r : α → α → Prop) :=\n    ∀ (a : α), 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 : ℕ)\". Remember that to prove a ∀\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 : ℕ),\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": "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/hw8_intro_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7836069929865708}}
{"text": "-- 课程仓库\n-- https://github.com/ImperialCollegeLondon/formalising-mathematics\n\n-- 本答案\n-- https://github.com/LeyangGuo/Formalizing_Mathmetics_zh\n\n-- 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* `→` (\"implies\" -- type with `\\l`)\n* `¬` (\"not\" -- type with `\\not` or `\\n`)\n* `∧` (\"and\" -- type with `\\and` or `\\an`)\n* `↔` (\"iff\" -- type with `\\iff` or `\\lr`)\n* `∨` (\"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 (→)\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 → P :=\nbegin\n  -- Prove this using `intro` and `exact`\n  intro h, exact h,\nend\n\n/-\nNote that → isn't associative!\nTry working out `false → (false → false) and (false → false) → false\n-/\n\nexample : (false → (false → false)) ↔ true := by simp\nexample : ((false → false) → false) ↔ false := by simp\n\n-- in Lean, `P → Q → R` is _defined_ to mean `P → (Q → R)`\n-- Here's a proof of what I just said.\nexample : (P → Q → R) ↔ (P → (Q → R)) :=\nbegin\n  -- look at the goal!\n  refl -- true because ↔ is reflexive\nend\n\ntheorem imp_intro : P → Q → P :=\nbegin\n  -- remember that by definition the goal is P → (Q → P).\n  -- Prove this proposition using `intro` and `exact`.\n  -- Experiment. Can you prove it using `intros` and `assumption`?\n\n  intro p, intro q,\n  --exact p,\n  assumption\nend\n\n/-- If we know `P`, and we also know `P → Q`, we can deduce `Q`. -/\nlemma modus_ponens : P → (P → Q) → Q :=\nbegin\n  -- You might find the `apply` tactic useful here.\n  intro p, intro p_to_q,\n  apply p_to_q,\n  apply p\nend\n\n/-- implication is transitive -/\nlemma imp_trans : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  -- The tactics you know should be enough\n  intro p_q, intro q_r, intro p,\n  apply q_r, apply p_q, \n  exact p\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 → Q → R) → (P → Q) → (P → R) :=\nbegin\n  -- `intros hPQR hPQ hP,` would be a fast way to start.\n  -- Make sure you understand what is going on there, if you use it.\n  -- 用 introS 引入假设，去掉goal中的->\n  intros p_q_r p_q p,\n  \n  --apply适用于多个推出且最后一个是目标命题的假设\n  apply p_q_r, \n\n  apply p,\n\n  apply p_q,\n  apply p,\nend\n\n/-\n\n### not\n\n`not P`, with notation `¬ P`, is *defined* to mean `P → false` in Lean,\ni.e., the proposition that P implies false. You can easily check with\na truth table that P → false and ¬ P are equivalent.\n\nWe develop a basic interface for `¬`.\n-/\n\n\n-- I'll prove this one for you\ntheorem not_iff_imp_false : ¬ P ↔ (P → false) :=\nbegin\n  -- true by definition\n  refl\nend\n\ntheorem not_not_intro : P → ¬ (¬ P) :=\nbegin\n              -- 求证 P → ¬ ¬ P\n              -- 思路 (P → ¬ ¬ P) ↔ P → ((P → false) → false) \nintro hP,     -- 1 . P\nintro h_not_P,-- 2 | .P → false\n              -- 3 | | false     (1,2 → _)\napply h_not_P,-- 4 | (P → false) → false     (2,3 → _)\nexact hP,     -- 5 P → ((P → false) → false)     (1,4 → _)\nend           -- QED.\n\n\n-- Here is a funny alternative proof! Can you work out how it works?\nexample : P → ¬ (¬ P) :=\nbegin\n  apply modus_ponens,   -- 上面证明过\n  -- 可以理解为在apply会自动进行多次intro直到后边的证明可以匹配\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 → ¬ (¬ P) :=\n-- 类型是 P → (P → false) → false\nλ hP hnP, hnP hP\n\n-- This is \"modus tollens\". Some mathematicians think of it as\n-- \"proof by contradiction\".\ntheorem modus_tollens : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  intro hPQ,  -- 1 .(P → Q)\n  intro hnQ,  -- 2 |  .(Q → false)\n  intro hP,   -- 3 |  |   . P\n  apply hnQ,  -- 4 |  |   | Q         3,1 → _\n  apply hPQ,  -- 5 |  |   | false     4,2 → _\n  exact hP,   -- 6 |  | (P → false)   3,5 → _\n              -- 7 |(P → Q) → (¬ Q → ¬ P)   1,2,6 → _\n\n  -- 无需使用`by_contra`，因为目标是 ¬ P, 可以`intro hP`\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 : ¬ (¬ P) → P :=\nbegin\n  -- tauto!,\n  intro hnnP, \n  by_contra hnP,\n  apply hnnP,\n  exact hnP,\nend\n\n/-!\n\n### and\n\nThe hypothesis `hPaQ : P ∧ 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 `⊢ P ∧ Q` as a goal, and want to turn the goal\ninto two goals `⊢ P` and `⊢ 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 ∧ 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 ∧ Q :=\nbegin\n  split,\n    exact hP,\n  exact hQ\nend\n```\n\n-/\n\ntheorem and.elim_left : P ∧ Q → P :=\nbegin\n  -- I would recommend starting with\n  -- `intro hPaQ,` and then `cases hPaQ with hP hQ`.\n  intro hPQ,\n  cases hPQ with hP hQ,\n  exact hP\nend\n\ntheorem and.elim_right : P ∧ Q → Q :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n  exact hQ\nend\n\n-- fancy term mode proof\nexample : P ∧ Q → Q := λ hPaQ, hPaQ.2\n\ntheorem and.intro : P → Q → P ∧ Q :=\nbegin\n  -- remember the `split` tactic.\n  intros hP hQ,\n  split,\n  exact hP,\n  exact hQ,\nend\n\n/-- the eliminator for `∧` -/ \ntheorem and.elim : P ∧ Q → (P → Q → R) → R :=\nbegin\n  intro hPaQ,\n  intro hPQR,\n  apply hPQR,\n  \n  cases hPaQ with hP hQ,\n  exact hP,\n\n  cases hPaQ with hP hQ,\n  exact hQ,\nend\n\n/-- The recursor for `∧` -/\ntheorem and.rec : (P → Q → R) → P ∧ Q → R :=\nbegin\n  intro hPQR,\n  intro hPaQ,\n  apply hPQR,\n\n  cases hPaQ with hP hQ,\n  exact hP,\n\n  cases hPaQ with hP hQ,\n  exact hQ,\nend\n\n/-- `∧` is symmetric -/\ntheorem and.symm : P ∧ Q → Q ∧ P :=\nbegin\n  intro hPaQ,\n  cases hPaQ with hP hQ,\n  split,\n  {exact hQ},\n  {exact hP}\nend\n\n-- term mode proof\nexample : P ∧ Q → Q ∧ P :=\nλ ⟨hP, hQ⟩, ⟨hQ, hP⟩\n\n/-- `∧` is transitive -/\ntheorem and.trans : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  -- The `rintro` tactic will do `intro` and `cases` all in one go.\n  -- If you like, try starting this proof with `rintro ⟨hP, hQ⟩` if you want\n  -- to experiment with it. Get the pointy brackets with `\\<` and `\\>`,\n  -- or both at once with `\\<>`.\n  rintro ⟨ hP,hQ ⟩ ,\n  rintro ⟨ hQ,hR ⟩ ,\n  split,\n  exact hP,\n  exact hR\nend\n\n/-\nRecall that the convention for the implies sign →\nis that it is _right associative_, by which\nI mean that `P → Q → R` means `P → (Q → R)` by definition.\nNow note that if `P` implies `Q → R`\nthen this means that `P` and `Q` together, imply `R`,\nso `P → Q → R` is logically equivalent to `(P ∧ Q) → R`.\n\nWe proved that `P → Q → R` implied `(P ∧ Q) → R`; this was `and.rec`.\nLet's go the other way.\n-/\n\nlemma imp_imp_of_and_imp : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  intro hPaQiR,\n  intros hP hQ,\n  apply hPaQiR,\n\n  split,\n  {exact hP},\n  {exact hQ}\nend\n\n\n/-!\n\n### iff\n\nThe basic theory of `iff`.\n\nIn Lean, to prove `P ∧ Q` you have to prove `P` and `Q`.\nSimilarly, to prove `P ↔ Q` in Lean, you have to prove `P → Q`\nand `Q → P`. Just like `∧`, you can uses `cases h` if you have\na hypothesis `h : P ↔ Q`, and `split` if you have a goal `⊢ P ↔ Q`.\n-/\n\n/-- `P ↔ P` is true for all propositions `P`, i.e. `↔` is reflexive. -/\ntheorem iff.refl : P ↔ P :=\nbegin\n  -- start with `split`\n  split,\n  -- P → P\n  {intro hP,\n    exact hP},\n  -- P → P\n  {intro hP,\n    exact hP}\nend\n\n-- If you get stuck, there is always the \"truth table\" tactic `tauto!`\nexample : P ↔ P :=\nbegin\n  tauto!, -- the \"truth table\" tactic.\nend\n\n-- refl tactic also works\nexample : P ↔ P :=\nbegin\n  refl -- `refl` knows that `=` and `↔` are reflexive.\nend\n\n/-- `↔` is symmetric -/\ntheorem iff.symm : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  intro hPiffQ,\n  split,\n  -- Q → P\n  {cases hPiffQ with hPiQ hQiP,\n    exact hQiP},\n  -- P → Q\n  {cases hPiffQ with hPiQ hQiP,\n    exact hPiQ}\nend\n\n-- NB there is quite a devious proof of this using `rw`.\n\n-- show-off term mode proof\nexample : (P ↔ Q) → (Q ↔ P) :=\nλ ⟨hPQ, hQP⟩, ⟨hQP, hPQ⟩\n\n/-- `↔` is commutative -/\ntheorem iff.comm : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  split,\n  -- (P ↔ Q) → (Q ↔ P)\n  apply iff.symm,\n  -- (Q ↔ P) → (P ↔ Q)\n  apply iff.symm,\nend\n\n-- without rw or cc this is painful!\n/-- `↔` is transitive -/\ntheorem iff.trans :  (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  intro hPiffQ,\n  intro hQiffR,\n  split,\n  -- P → R\n  {rw hPiffQ, rw hQiffR,\n  intro hR, exact hR},\n  -- R → P\n  {rw hPiffQ, rw hQiffR,\n  intro hR, exact hR},\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 : ¬ (P ↔ ¬ P) :=\nbegin\n  intro h,\n  cases h with hR hL,\n\n  have sel_imp : P → P,{\n    intro hP, exact hP,\n    },\n  \n  have hnP : P → false, {\n    intro hP,\n    apply hR,\n    exact hP,\n    exact hP,\n  },\n\n  apply hR,\n  apply hL,\n  exact hnP,\n\n  apply hL,\n  exact hnP,\nend\n\n-- 上面的证明中用到如下引理\nlemma not_imp_nSelf : (P → (P → false)) → (P → P) → (P → false) :=\nbegin\n  -- `intros hPQR hPQ hP,` would be a fast way to start.\n  -- Make sure you understand what is going on there, if you use it.\n  -- 用 introS 引入假设，去掉goal中的->\n  intros p_q_r p_q p,\n  \n  --apply适用于多个推出且最后一个是目标命题的假设\n  apply p_q_r, \n\n  apply p,\n\n  apply p_q,\n  apply p,\nend\n\n-- \nexample : ¬ (P ↔ ¬ P) :=\nbegin\n    by_cases h : P,\n  -- P为真时\n  {\n    intro hPiffnP,\n    cases hPiffnP with hPinP hnPiP,\n    apply hPinP,\n    exact h,\n    exact h\n    },\n  -- P为假时\n  {\n  intro hPiffnP,\n  cases hPiffnP with hPinP hnPiP,\n  apply hPinP,\n  apply hnPiP, exact h,\n  apply hnPiP, exact h\n  }\nend\n\n-- Now we have iff we can go back to and.\n\n/-!\n### ↔ and ∧\n-/\n\n-- 引理 and.comm 的证明，写在这里供参考\nexample : P ∧ Q → Q ∧ P :=\nbegin\n  rintro ⟨ hP, hQ ⟩ ,\n  split,\n  exact hQ,\n  exact hP,\nend\n\n/-- `∧` is commutative -/\ntheorem and.comm : P ∧ Q ↔ Q ∧ P :=\nbegin\n  split,\n  apply and.symm,\n  apply and.symm,\nend\n\n-- fancy term-mode proof\nexample : P ∧ Q ↔ Q ∧ P :=\n⟨and.symm _ _, and.symm _ _⟩\n\n-- Note that ∧ is \"right associative\" in Lean, which means\n-- that `P ∧ Q ∧ R` is _defined to mean_ `P ∧ (Q ∧ R)`.\n-- Associativity can hence be written like this:\n/-- `∧` is associative -/\ntheorem and_assoc : ((P ∧ Q) ∧ R) ↔ (P ∧ Q ∧ R) :=\nbegin\n  split,\n  -- (P ∧ Q) ∧ R → P ∧ (Q ∧ R)\n  {\n    rintro ⟨hPaQ,hR⟩ ,\n    cases hPaQ with hP hQ,\n\n    split,\n      exact hP,\n      split,\n        exact hQ,\n        exact hR,\n  },\n  -- P ∧ Q ∧ R → (P ∧ Q) ∧ R\n  {\n    rintro ⟨hP,hQaR⟩ ,\n    cases hQaR with hQ hR,\n\n    split,\n      split,\n        exact hP,\n        exact hQ,\n      exact hR,\n    }\nend\n\n\n\n/-!\n\n## Or\n\n`P ∨ Q` is true when at least one of `P` and `Q` are true.\nHere is how to work with `∨` in Lean.\n\nIf you have a hypothesis `hPoQ : P ∨ 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 `⊢ P ∨ 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 → P ∨ Q :=\nbegin\n  intro hP,\n  left,\n  exact hP,\nend\n\ntheorem or.intro_right : Q → P ∨ Q :=\nbegin\n  intro hQ,\n  right,\n  exact hQ,\nend\n\n/-- the eliminator for `∨`. -/\ntheorem or.elim : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  intros hPoQ hPR hQR,\n  cases hPoQ with hP hQ,\n  { -- P → R\n    apply hPR,\n    exact hP\n  },\n  { -- Q → R\n    apply hQR,\n    exact hQ,\n  }\nend\n\n/-- `∨` is symmetric -/\ntheorem or.symm : P ∨ Q → Q ∨ P :=\nbegin\n  intro hPoQ,\n  cases hPoQ with hP hQ,\n  -- P → Q ∨ P\n  apply or.intro_right, \n  exact hP,\n  -- Q → Q ∨ P\n  apply or.intro_left, \n  exact hQ,\nend\n\n/-- `∨` is commutative -/\ntheorem or.comm : P ∨ Q ↔ Q ∨ P :=\nbegin\n  split,\n  { -- left imp right\n    apply or.symm,\n  },\n  { -- right imp left\n    apply or.symm,\n  }\nend\n\n/-- `∨` is associative -/\ntheorem or.assoc : (P ∨ Q) ∨ R ↔ P ∨ Q ∨ R :=\nbegin\n  split,\n  { -- (P ∨ Q) ∨ R → P ∨ Q ∨ R\n    intro hLeft,\n    cases hLeft with hPoQ hR,\n    cases hPoQ with hP hQ,\n    -- known: P \n    apply or.intro_left,\n    exact hP,\n    -- known: Q or R\n      -- known Q\n      apply or.intro_right,\n      apply or.intro_left,\n      exact hQ,\n      -- known R\n      apply or.intro_right,\n      apply or.intro_right,\n      exact hR,\n  },\n  {\n    intro hRight,\n    cases hRight with hP hQoR,\n      { -- known P\n        apply or.intro_left,\n        apply or.intro_left,\n        exact hP,\n      },\n    cases hQoR with hQ hR,\n      { -- known Q,\n        apply or.intro_left,\n        apply or.intro_right,\n        exact hQ,\n      },\n      { -- known R\n        apply or.intro_right,\n        exact hR,\n      },\n  },\nend\n\n/-!\n### More about → and ∨\n-/\n\ntheorem or.imp : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  intros hPR hQS hPoQ,\n  cases hPoQ with hP hQ,\n  { --known P,\n    left,\n    apply hPR,\n    exact hP,\n  },\n  { -- known Q,\n    right,\n    apply hQS,\n    exact hQ,\n  }\nend\n\ntheorem or.imp_left : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  intros hPQ hPoR,\n  cases hPoR with hP hR,\n  { -- known P\n    left,\n    apply hPQ,\n    exact hP,\n  },\n  { -- known Q\n    right,\n    exact hR,\n  }\nend\n\ntheorem or.imp_right : (P → Q) → R ∨ P → R ∨ Q :=\nbegin\n  intros hPQ hRoP,\n  cases hRoP with hR hP,\n  { --known R\n    left,\n    exact hR,\n  },\n  { --known P\n    right,\n    apply hPQ,\n    exact hP, \n  }\nend\n\ntheorem or.left_comm : P ∨ Q ∨ R ↔ Q ∨ P ∨ R :=\nbegin\n  -- Try rewriting `or.comm` and `or.assoc` to do this one quickly.\n  -- https://stackoverflow.com/questions/69047508/rw-expression-in-expression\n  -- 利用comm和assoc将 ↔ 左右化为相同，最后用refl \n  rw ← or.assoc,\n  nth_rewrite 1 or.comm,  -- rewrite 第二次匹配到的内容\n  rw or.assoc,\nend\n\nexample : P ∨ Q ∨ R ↔ Q ∨ P ∨ R :=\nbegin\n  rw ← or.assoc,\n  conv{\n    to_lhs,\n    congr,\n    rw or.comm,\n  },\n  rw or.assoc,\nend\n\n\n/-- the recursor for `∨` -/\ntheorem or.rec : (P → R) → (Q → R) → P ∨ Q → R :=\nbegin\n  intros hPR hQR hPoQ,\n  cases hPoQ with hP hQ,\n  -- known P\n  apply hPR,\n  exact hP,\n  -- known Q\n  apply hQR,\n  exact hQ,\nend\n\ntheorem or_congr : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  intros hPR hQS,\n  rw hPR,\n  rw hQS,\n  -- rw 会自动尝试refl\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 ∧ 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 → P :=\nbegin\n  intro hF,\n  cases hF,\nend\n\ntheorem and_true_iff : P ∧ true ↔ P :=\nbegin\n  split,\n  { -- P ∧ true → P\n    intro hPaT,\n    cases hPaT with hP hT,\n    exact hP,\n  },\n  { -- P → P ∧ true\n    intro hP,\n    have hT : true,\n      trivial,\n    \n    split,\n    exact hP,\n    exact hT,\n  }, \nend\n\ntheorem or_false_iff : P ∨ false ↔ P :=\nbegin\n  split,\n  { -- ⊢ P ∨ false → P\n    intro h,\n    cases h with hP hF,\n    exact hP,\n    cases hF,\n  },\n  { -- ⊢ P → P ∨ false\n    intro h,\n    left,\n    exact h,\n  },\nend\n\n-- false.elim is handy for this one\ntheorem or.resolve_left : P ∨ Q → ¬P → Q :=\nbegin\n  intros hPoQ hnP,\n  \n  have hPiffF : P ↔ false, {\n    split,\n    exact hnP,\n    apply false.elim,\n  },\n\n  rw hPiffF at hPoQ,\n  rw or.comm at hPoQ,\n  rw or_false_iff at hPoQ,\n  exact hPoQ,\nend\n\n-- this one you can't do constructively\ntheorem or_iff_not_imp_left : P ∨ Q ↔ ¬P → Q :=\nbegin\n  split,\n  { -- ⊢ P ∨ Q → ¬P → Q\n    -- Done constructively\n    apply or.resolve_left,\n  },\n  { -- ⊢ (¬P → Q) → P ∨ Q\n    intro hnPQ,\n    by_cases hP : P,\n    { -- have P\n      left,\n      exact hP,\n    },\n    { -- have ¬ P\n      right,\n      apply hnPQ,\n      exact hP,\n    },\n  },\nend\n\nend xena\n\n", "meta": {"author": "LeyangGuo", "repo": "Formalizing_Mathmetics_zh", "sha": "e03a0f2b6fa3bef45d704bd5b53c66fa57ce3262", "save_path": "github-repos/lean/LeyangGuo-Formalizing_Mathmetics_zh", "path": "github-repos/lean/LeyangGuo-Formalizing_Mathmetics_zh/Formalizing_Mathmetics_zh-e03a0f2b6fa3bef45d704bd5b53c66fa57ce3262/Part_A_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7835996442093096}}
{"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 1 : ∪ ∩ ⊆ and all that\n\nLean doesn't have \"abstract\" sets, it only has *subsets* of a type. If `X : Type` is a type\nthen the type of subsets of `X` is called `set X`. A term `A : set X`\ncan be thought of in three ways:\n\n1) A set of elements of `X` (i.e. a set of elements all of which have type `X`);\n2) A subset of `X`;\n3) An element of the power set of `X`;\n4) A function from `X` to `Prop` (sending the elements of `A` to `true` and the other ones to `false`)\n\nSo `set X` could have been called `subset X` or `powerset X`; I guess they chose `set X`\nbecause it was the shortest.\n\nNote that `X` is a type, but `A` is a term; the type of `A` is `set X`. This means\nthat `a : A` doesn't make sense. What we say instead is `a : X` and `a ∈ A`. \nOf course `a ∈ A` is a true-false statement, so `a ∈ A : Prop`. \n\nAll the sets `A`, `B`, `C` etc we consider will be subsets of `X`. \nIf `x : X` then `x` may or may not be an element of `A`, `B`, `C`,\nbut it will always be a term of type `X`.\n\n-/\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D : set X) -- A,B,C,D 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\n# subset (`⊆`), union (`∪`) and intersection (`∩`)\n\nHere are some mathematical facts:\n\n`A ⊆ B` is equivalent to `∀ x, x ∈ A → x ∈ B`;\n`x ∈ A ∪ B` is equivalent to `x ∈ A ∨ x ∈ B`;\n`x ∈ A ∩ B` is equivalent to `x ∈ A ∧ x ∈ B`. \n\nAll of these things are true *by definition* in Lean. Let's\ncheck this.\n\n-/\n\nlemma subset_def : A ⊆ B ↔ ∀ x, x ∈ A → x ∈ B :=\nbegin\n  -- ↔ is reflexive so `refl` works because LHS is defined to be equal to RHS\n  refl\nend\n\nlemma mem_union_iff : x ∈ A ∪ B ↔ x ∈ A ∨ x ∈ B :=\nbegin\n  refl\nend\n\nlemma mem_inter_iff : x ∈ A ∩ B ↔ x ∈ A ∧ x ∈ B :=\niff.rfl -- you don't even have to go into tactic mode to prove this stuff\n\n/-\n\nSo now to change one side of these `↔`s to the other, you can\n`rw` the appropriate lemma, or you can just use `change`. Or\nyou can ask yourself whether you need to do this at all.\n\nLet's prove some theorems.\n\n-/\n\nexample : A ⊆ A :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → B ⊆ C → A ⊆ C :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ A ∪ B :=\nbegin\n  sorry,\nend\n\nexample : A ∩ B ⊆ A :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → A ⊆ C → A ⊆ (B ∩ C) :=\nbegin\n  sorry,\nend\n\nexample : B ⊆ A → C ⊆ A → B ∪ C ⊆ A :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → C ⊆ D → A ∪ C ⊆ B ∪ D :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → C ⊆ D → A ∩ C ⊆ B ∩ D :=\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/section05sets/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7835996405337653}}
{"text": "section\nvariable (α : Type) (p q : α → Prop) (r : α → α → Prop)\n\n/- UNIVERSAL QUANTIFICATION -/\n\n-- We can leave off `: α` if Lean can infer it (here via `p`/`q`)\nexample : (∀ x, p x) → (∀ x, p x → q x) → (∀ x, q x) := _\n\n-- The reverse direction of the slides example\nexample : (∀ x, p x ∧ q x) → (∀ x, p x) ∧ (∀ x, q x) := _\n\n-- TODO: Prove the corresponding forward/reverse lemma(s) for `∨` (that hold)!\n-- hint: input `∀` as `\\all`\n\n-- We can bind multiple variables in a single `∀`\nexample : (∀ x y, r x y) → (∀ y x, r 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 : α → Prop) : Prop where\n  | intro (w : α) (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 `∃ x, p x` (input `∃` as `\\ex`).\n-/\n\nexample : (∃ x, p x ∧ q x) → (∃ x, p x) ∧ (∃ x, q x) := _\n\nexample : ¬(∃ x, p x) → (∀ x, ¬ p x) := _\n\nexample : (∀ x, ¬ p x) → ¬(∃ x, p x) := _\n\nexample : (∃ x, ¬ p x) → ¬ (∀ x, p x) := _\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 : ¬(∀ x, p x) → (∃ x, ¬ p x) := _\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\n\nend Drinker\n\n/- EQUALITY -/\n\nexample : ∀ a b c : α, a = b → b = c → a = c := _\n\nexample : ∀ a : α, ∃ b : α, b = a := _\n\n-- \"`Eq` is the least reflexive relation\"\nexample : (∀ a, r a a) → (∀ a b, a = b → r a b) := _\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/Exercises/Exercise2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7835996355263072}}
{"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 algebra.group.pi\nimport algebra.group.prod\nimport algebra.hom.iterate\nimport logic.equiv.set\n\n/-!\n# The group of permutations (self-equivalences) of a 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 the `group` structure on `equiv.perm α`.\n-/\nuniverses u v\n\nnamespace equiv\n\nvariables {α : Type u} {β : Type v}\n\nnamespace perm\n\ninstance perm_group : group (perm α) :=\n{ mul := λ f g, equiv.trans g f,\n  one := equiv.refl α,\n  inv := equiv.symm,\n  mul_assoc := λ f g h, (trans_assoc _ _ _).symm,\n  one_mul := trans_refl,\n  mul_one := refl_trans,\n  mul_left_inv := self_trans_symm }\n\n@[simp] lemma default_eq : (default : perm α) = 1 := rfl\n\n/-- The permutation of a type is equivalent to the units group of the endomorphisms monoid of this\ntype. -/\n@[simps] def equiv_units_End : perm α ≃* units (function.End α) :=\n{ to_fun := λ e, ⟨e, e.symm, e.self_comp_symm, e.symm_comp_self⟩,\n  inv_fun := λ u, ⟨(u : function.End α), (↑u⁻¹ : function.End α), congr_fun u.inv_val,\n    congr_fun u.val_inv⟩,\n  left_inv := λ e, ext $ λ x, rfl,\n  right_inv := λ u, units.ext rfl,\n  map_mul' := λ e₁ e₂, rfl }\n\n/-- Lift a monoid homomorphism `f : G →* function.End α` to a monoid homomorphism\n`f : G →* equiv.perm α`. -/\n@[simps] def _root_.monoid_hom.to_hom_perm {G : Type*} [group G] (f : G →* function.End α) :\n  G →* perm α :=\nequiv_units_End.symm.to_monoid_hom.comp f.to_hom_units\n\ntheorem mul_apply (f g : perm α) (x) : (f * g) x = f (g x) :=\nequiv.trans_apply _ _ _\n\ntheorem one_apply (x) : (1 : perm α) x = x := rfl\n\n@[simp] lemma inv_apply_self (f : perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x\n\n@[simp] lemma apply_inv_self (f : perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x\n\nlemma one_def : (1 : perm α) = equiv.refl α := rfl\n\nlemma mul_def (f g : perm α) : f * g = g.trans f := rfl\n\nlemma inv_def (f : perm α) : f⁻¹ = f.symm := rfl\n\n@[simp, norm_cast] lemma coe_one : ⇑(1 : perm α) = id := rfl\n@[simp, norm_cast] lemma coe_mul (f g : perm α) : ⇑(f * g) = f ∘ g := rfl\n@[norm_cast] lemma coe_pow (f : perm α) (n : ℕ) : ⇑(f ^ n) = (f^[n]) :=\nhom_coe_pow _ rfl (λ _ _, rfl) _ _\n@[simp] lemma iterate_eq_pow (f : perm α) (n : ℕ) : (f^[n]) = ⇑(f ^ n) := (coe_pow _ _).symm\n\nlemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply\n\nlemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq\n\nlemma zpow_apply_comm {α : Type*} (σ : perm α) (m n : ℤ) {x : α} :\n  (σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) :=\nby rw [←equiv.perm.mul_apply, ←equiv.perm.mul_apply, zpow_mul_comm]\n\n@[simp] lemma image_inv (f : perm α) (s : set α) : ⇑f⁻¹ '' s = f ⁻¹' s := f⁻¹.image_eq_preimage _\n@[simp] lemma preimage_inv (f : perm α) (s : set α) : ⇑f⁻¹ ⁻¹' s = f '' s :=\n(f.image_eq_preimage _).symm\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] lemma trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : perm β) = e :=\nequiv.trans_refl e\n\n@[simp] lemma mul_refl (e : perm α) : e * equiv.refl α = e := equiv.trans_refl e\n\n@[simp] lemma one_symm : (1 : perm α).symm = 1 := equiv.refl_symm\n\n@[simp] lemma refl_inv : (equiv.refl α : perm α)⁻¹ = 1 := equiv.refl_symm\n\n@[simp] lemma one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : perm α).trans e = e :=\nequiv.refl_trans e\n\n@[simp] lemma refl_mul (e : perm α) : equiv.refl α * e = e := equiv.refl_trans e\n\n@[simp] lemma inv_trans_self (e : perm α) : e⁻¹.trans e = 1 := equiv.symm_trans_self e\n\n@[simp] lemma mul_symm (e : perm α) : e * e.symm = 1 := equiv.symm_trans_self e\n\n@[simp] lemma self_trans_inv (e : perm α) : e.trans e⁻¹ = 1 := equiv.self_trans_symm e\n\n@[simp] lemma symm_mul (e : perm α) : e.symm * e = 1 := equiv.self_trans_symm e\n\n/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/\n\n@[simp] lemma sum_congr_mul {α β : Type*} (e : perm α) (f : perm β) (g : perm α) (h : perm β) :\n  sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=\nsum_congr_trans g h e f\n\n@[simp] lemma sum_congr_inv {α β : Type*} (e : perm α) (f : perm β) :\n  (sum_congr e f)⁻¹ = sum_congr e⁻¹ f⁻¹ :=\nsum_congr_symm e f\n\n@[simp] lemma sum_congr_one {α β : Type*} :\n  sum_congr (1 : perm α) (1 : perm β) = 1 :=\nsum_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 `α` and `β`. -/\n@[simps]\ndef sum_congr_hom (α β : Type*) :\n  perm α × perm β →* perm (α ⊕ β) :=\n{ to_fun := λ a, sum_congr a.1 a.2,\n  map_one' := sum_congr_one,\n  map_mul' := λ a b, (sum_congr_mul _ _ _ _).symm}\n\nlemma sum_congr_hom_injective {α β : Type*} :\n  function.injective (sum_congr_hom α β) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ h,\n  rw prod.mk.inj_iff,\n  split; ext i,\n  { simpa using equiv.congr_fun h (sum.inl i), },\n  { simpa using equiv.congr_fun h (sum.inr i), },\nend\n\n@[simp] lemma sum_congr_swap_one {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : α) :\n  sum_congr (equiv.swap i j) (1 : perm β) = equiv.swap (sum.inl i) (sum.inl j) :=\nsum_congr_swap_refl i j\n\n@[simp] lemma sum_congr_one_swap {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : β) :\n  sum_congr (1 : perm α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=\nsum_congr_refl_swap i j\n\n/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/\n\n@[simp] lemma sigma_congr_right_mul {α : Type*} {β : α → Type*}\n  (F : Π a, perm (β a)) (G : Π a, perm (β a)) :\n  sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=\nsigma_congr_right_trans G F\n\n@[simp] lemma sigma_congr_right_inv {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) :\n  (sigma_congr_right F)⁻¹ = sigma_congr_right (λ a, (F a)⁻¹) :=\nsigma_congr_right_symm F\n\n@[simp] lemma sigma_congr_right_one {α : Type*} {β : α → Type*} :\n  (sigma_congr_right (1 : Π a, equiv.perm $ β a)) = 1 :=\nsigma_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. -/\n@[simps]\ndef sigma_congr_right_hom {α : Type*} (β : α → Type*) :\n  (Π a, perm (β a)) →* perm (Σ a, β a) :=\n{ to_fun := sigma_congr_right,\n  map_one' := sigma_congr_right_one,\n  map_mul' := λ a b, (sigma_congr_right_mul _ _).symm }\n\nlemma sigma_congr_right_hom_injective {α : Type*} {β : α → Type*} :\n  function.injective (sigma_congr_right_hom β) :=\nbegin\n  intros x y h,\n  ext a b,\n  simpa using equiv.congr_fun h ⟨a, b⟩,\nend\n\n/-- `equiv.perm.subtype_congr` as a `monoid_hom`. -/\n@[simps] def subtype_congr_hom (p : α → Prop) [decidable_pred p] :\n  (perm {a // p a}) × (perm {a // ¬ p a}) →* perm α :=\n{ to_fun := λ pair, perm.subtype_congr pair.fst pair.snd,\n  map_one' := perm.subtype_congr.refl,\n  map_mul' := λ _ _, (perm.subtype_congr.trans _ _ _ _).symm }\n\nlemma subtype_congr_hom_injective (p : α → Prop) [decidable_pred p] :\n  function.injective (subtype_congr_hom p) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ h,\n  rw prod.mk.inj_iff,\n  split;\n  ext i;\n  simpa using equiv.congr_fun h i\nend\n\n/-- If `e` is also a permutation, we can write `perm_congr`\ncompletely in terms of the group structure. -/\n@[simp] lemma perm_congr_eq_mul (e p : perm α) :\n  e.perm_congr p = e * p * e⁻¹ := rfl\n\nsection extend_domain\n\n/-! Lemmas about `equiv.perm.extend_domain` re-expressed via the group structure. -/\n\nvariables (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p)\n\n@[simp] lemma extend_domain_one : extend_domain 1 f = 1 :=\nextend_domain_refl f\n\n@[simp] lemma extend_domain_inv : (e.extend_domain f)⁻¹ = e⁻¹.extend_domain f := rfl\n\n@[simp] lemma extend_domain_mul (e e' : perm α) :\n  (e.extend_domain f) * (e'.extend_domain f) = (e * e').extend_domain f :=\nextend_domain_trans _ _ _\n\n/-- `extend_domain` as a group homomorphism -/\n@[simps] def extend_domain_hom : perm α →* perm β :=\n{ to_fun := λ e, extend_domain e f,\n  map_one' := extend_domain_one f,\n  map_mul' := λ e e', (extend_domain_mul f e e').symm }\n\nlemma extend_domain_hom_injective : function.injective (extend_domain_hom f) :=\n(injective_iff_map_eq_one (extend_domain_hom f)).mpr (λ e he, ext (λ x, f.injective (subtype.ext\n  ((extend_domain_apply_image e f x).symm.trans (ext_iff.mp he (f x))))))\n\n@[simp] \n\n@[simp] lemma extend_domain_pow (n : ℕ) : (e ^ n).extend_domain f = e.extend_domain f ^ n :=\nmap_pow (extend_domain_hom f) _ _\n\n@[simp] lemma extend_domain_zpow (n : ℤ) : (e ^ n).extend_domain f = e.extend_domain f ^ n :=\nmap_zpow (extend_domain_hom f) _ _\n\nend extend_domain\n\nsection subtype\nvariables {p : α → Prop} {f : perm α}\n\n/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation\n  on `{x // p x}` induced by `f`. -/\ndef subtype_perm (f : perm α) (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} :=\n⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩,\n  λ _, by simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk],\n  λ _, by simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk]⟩\n\n@[simp] lemma subtype_perm_apply (f : perm α) (h : ∀ x, p x ↔ p (f x))\n  (x : {x // p x}) : subtype_perm f h x = ⟨f x, (h _).1 x.2⟩ := rfl\n\n@[simp] lemma subtype_perm_one (p : α → Prop) (h := λ _, iff.rfl) : @subtype_perm α p 1 h = 1 :=\nequiv.ext $ λ ⟨_, _⟩, rfl\n\n@[simp] lemma subtype_perm_mul (f g : perm α) (hf hg) :\n  (f.subtype_perm hf * g.subtype_perm hg : perm {x // p x}) =\n    (f * g).subtype_perm (λ x, (hg _).trans $ hf _) := rfl\n\nprivate lemma inv_aux : (∀ x, p x ↔ p (f x)) ↔ ∀ x, p x ↔ p (f⁻¹ x) :=\nf⁻¹.surjective.forall.trans $ by simp_rw [f.apply_inv_self, iff.comm]\n\n/-- See `equiv.perm.inv_subtype_perm`-/\nlemma subtype_perm_inv (f : perm α) (hf) :\n  f⁻¹.subtype_perm hf = (f.subtype_perm $ inv_aux.2 hf : perm {x // p x})⁻¹ := rfl\n\n/-- See `equiv.perm.subtype_perm_inv`-/\n@[simp] lemma inv_subtype_perm (f : perm α) (hf) :\n  (f.subtype_perm hf : perm {x // p x})⁻¹ = f⁻¹.subtype_perm (inv_aux.1 hf) := rfl\n\nprivate lemma pow_aux (hf : ∀ x, p x ↔ p (f x)) : ∀ {n : ℕ} x, p x ↔ p ((f ^ n) x)\n| 0 x := iff.rfl\n| (n + 1) x := (pow_aux _).trans (hf _)\n\n@[simp] lemma subtype_perm_pow (f : perm α) (n : ℕ) (hf) :\n  (f.subtype_perm hf : perm {x // p x}) ^ n = (f ^ n).subtype_perm (pow_aux hf) :=\nbegin\n  induction n with n ih,\n  { simp },\n  { simp_rw [pow_succ', ih, subtype_perm_mul] }\nend\n\nprivate lemma zpow_aux (hf : ∀ x, p x ↔ p (f x)) : ∀ {n : ℤ} x, p x ↔ p ((f ^ n) x)\n| (int.of_nat n) := pow_aux hf\n| (int.neg_succ_of_nat n) := by { rw zpow_neg_succ_of_nat, exact inv_aux.1 (pow_aux hf) }\n\n@[simp] lemma subtype_perm_zpow (f : perm α) (n : ℤ) (hf) :\n  (f.subtype_perm hf ^ n : perm {x // p x}) = (f ^ n).subtype_perm (zpow_aux hf) :=\nbegin\n  induction n with n ih,\n  { exact subtype_perm_pow _ _ _ },\n  { simp only [zpow_neg_succ_of_nat, subtype_perm_pow, subtype_perm_inv] }\nend\n\nvariables [decidable_pred p] {a : α}\n\n/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,\n  fixing the other points. -/\ndef of_subtype : perm (subtype p) →* perm α :=\n{ to_fun := λ f, extend_domain f (equiv.refl (subtype p)),\n  map_one' := equiv.perm.extend_domain_one _,\n  map_mul' := λ f g, (equiv.perm.extend_domain_mul _ f g).symm, }\n\nlemma of_subtype_subtype_perm {f : perm α} (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) :\n  of_subtype (subtype_perm f h₁) = f :=\nequiv.ext $ λ x, begin\n  by_cases hx : p x,\n  { exact (subtype_perm f h₁).extend_domain_apply_subtype _ hx, },\n  { rw [of_subtype, monoid_hom.coe_mk, equiv.perm.extend_domain_apply_not_subtype],\n    { exact not_not.mp (λ h, hx (h₂ x (ne.symm h))),  },\n    { exact hx, }, }\nend\n\nlemma of_subtype_apply_of_mem (f : perm (subtype p)) (ha : p a) : of_subtype f a = f ⟨a, ha⟩ :=\nextend_domain_apply_subtype _ _ _\n\n@[simp] lemma of_subtype_apply_coe (f : perm (subtype p)) (x : subtype p) : of_subtype f x = f x :=\nsubtype.cases_on x $ λ _, of_subtype_apply_of_mem f\n\nlemma of_subtype_apply_of_not_mem (f : perm (subtype p)) (ha : ¬ p a) : of_subtype f a = a :=\nextend_domain_apply_not_subtype _ _ ha\n\nlemma mem_iff_of_subtype_apply_mem (f : perm (subtype p)) (x : α) :\n  p x ↔ p ((of_subtype f : α → α) x) :=\nif h : p x then\nby simpa only [h, true_iff, monoid_hom.coe_mk, of_subtype_apply_of_mem f h] using (f ⟨x, h⟩).2\nelse by simp [h, of_subtype_apply_of_not_mem f h]\n\n@[simp] lemma subtype_perm_of_subtype (f : perm (subtype p)) :\n  subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f :=\nequiv.ext $ λ x, subtype.coe_injective (of_subtype_apply_coe f x)\n\n/-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise\nthe rest. -/\n@[simps] protected def subtype_equiv_subtype_perm (p : α → Prop) [decidable_pred p] :\n  perm (subtype p) ≃ {f : perm α // ∀ a, ¬p a → f a = a} :=\n{ to_fun := λ f, ⟨f.of_subtype, λ a, f.of_subtype_apply_of_not_mem⟩,\n  inv_fun := λ f, (f : perm α).subtype_perm\n    (λ a, ⟨decidable.not_imp_not.1 $ λ hfa, (f.val.injective (f.prop _ hfa) ▸ hfa),\n    decidable.not_imp_not.1 $ λ ha hfa, ha $ f.prop a ha ▸ hfa⟩),\n  left_inv := equiv.perm.subtype_perm_of_subtype,\n  right_inv := λ f,\n    subtype.ext (equiv.perm.of_subtype_subtype_perm _ $ λ a, not.decidable_imp_symm $ f.prop a) }\n\nlemma subtype_equiv_subtype_perm_apply_of_mem (f : perm (subtype p)) (h : p a) :\n  perm.subtype_equiv_subtype_perm p f a = f ⟨a, h⟩ :=\nf.of_subtype_apply_of_mem h\n\nlemma subtype_equiv_subtype_perm_apply_of_not_mem (f : perm (subtype p)) (h : ¬ p a) :\n  perm.subtype_equiv_subtype_perm p f a = a :=\nf.of_subtype_apply_of_not_mem h\n\nend subtype\nend perm\n\nsection swap\nvariables [decidable_eq α]\n\n@[simp] lemma swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl\n\n@[simp] lemma swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j\n\nlemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=\nequiv.ext $ λ z, begin\n  simp only [perm.mul_apply, swap_apply_def],\n  split_ifs;\n  simp only [perm.apply_inv_self, *, perm.eq_inv_iff_eq, eq_self_iff_true, not_true] at *\nend\n\nlemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f :=\nby rw [swap_mul_eq_mul_swap, perm.inv_apply_self, perm.inv_apply_self]\n\nlemma swap_apply_apply (f : perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ :=\nby rw [mul_swap_eq_swap_mul, mul_inv_cancel_right]\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]\nlemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ :=\nby rw [←mul_assoc, swap_mul_self, one_mul]\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]\nlemma mul_swap_mul_self (i j : α) (σ : perm α) : (σ * equiv.swap i j) * equiv.swap i j = σ :=\nby rw [mul_assoc, swap_mul_self, mul_one]\n\n/-- A stronger version of `mul_right_injective` -/\n@[simp]\nlemma swap_mul_involutive (i j : α) : function.involutive ((*) (equiv.swap i j)) :=\nswap_mul_self_mul i j\n\n/-- A stronger version of `mul_left_injective` -/\n@[simp]\nlemma mul_swap_involutive (i j : α) : function.involutive (* (equiv.swap i j)) :=\nmul_swap_mul_self i j\n\n@[simp] lemma swap_eq_one_iff {i j : α} : swap i j = (1 : perm α) ↔ i = j :=\nswap_eq_refl_iff\n\nlemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j :=\n⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm),\n  by {rw [←swap_apply_right i j, swap_id], refl}),\n(assume h, by erw [h, swap_self, one_mul])⟩\n\nlemma mul_swap_eq_iff {i j : α} {σ : perm α} : σ * swap i j = σ ↔ i = j :=\n⟨(assume h, have swap_id : swap i j = 1 := mul_left_cancel (trans h (one_mul σ).symm),\n  by {rw [←swap_apply_right i j, swap_id], refl}),\n(assume h, by erw [h, swap_self, mul_one])⟩\n\nlemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) :\n  swap y z * swap x y * swap y z = swap z x :=\nequiv.ext $ λ n, by { simp only [swap_apply_def, perm.mul_apply], split_ifs; cc }\n\nend swap\n\nsection add_group\nvariables [add_group α] (a b : α)\n\n@[simp] lemma add_left_zero : equiv.add_left (0 : α) = 1 := ext zero_add\n@[simp] lemma add_right_zero : equiv.add_right (0 : α) = 1 := ext add_zero\n\n@[simp] lemma add_left_add : equiv.add_left (a + b) = equiv.add_left a * equiv.add_left b :=\next $ add_assoc _ _\n\n@[simp] lemma add_right_add : equiv.add_right (a + b) = equiv.add_right b * equiv.add_right a :=\next $ λ _, (add_assoc _ _ _).symm\n\n@[simp] lemma inv_add_left : (equiv.add_left a)⁻¹ =  equiv.add_left (-a) := equiv.coe_inj.1 rfl\n@[simp] lemma inv_add_right : (equiv.add_right a)⁻¹ =  equiv.add_right (-a) := equiv.coe_inj.1 rfl\n\n@[simp] lemma pow_add_left (n : ℕ) : equiv.add_left a ^ n = equiv.add_left (n • a) :=\nby { ext, simp [perm.coe_pow] }\n\n@[simp] lemma pow_add_right (n : ℕ) : equiv.add_right a ^ n = equiv.add_right (n • a) :=\nby { ext, simp [perm.coe_pow] }\n\n@[simp] lemma zpow_add_left (n : ℤ) : equiv.add_left a ^ n = equiv.add_left (n • a) :=\n(map_zsmul (⟨equiv.add_left, add_left_zero, add_left_add⟩ : α →+ additive (perm α)) _ _).symm\n\n@[simp] lemma zpow_add_right (n : ℤ) : equiv.add_right a ^ n = equiv.add_right (n • a) :=\n@zpow_add_left αᵃᵒᵖ _ _ _\n\nend add_group\n\nsection group\nvariables [group α] (a b : α)\n\n@[simp, to_additive] lemma mul_left_one : equiv.mul_left (1 : α) = 1 := ext one_mul\n@[simp, to_additive] lemma mul_right_one : equiv.mul_right (1 : α) = 1 := ext mul_one\n\n@[simp, to_additive]\nlemma mul_left_mul : equiv.mul_left (a * b) = equiv.mul_left a * equiv.mul_left b :=\next $ mul_assoc _ _\n\n@[simp, to_additive]\nlemma mul_right_mul : equiv.mul_right (a * b) = equiv.mul_right b * equiv.mul_right a :=\next $ λ _, (mul_assoc _ _ _).symm\n\n@[simp, to_additive inv_add_left]\nlemma inv_mul_left : (equiv.mul_left a)⁻¹ = equiv.mul_left a⁻¹ := equiv.coe_inj.1 rfl\n@[simp, to_additive inv_add_right]\nlemma inv_mul_right : (equiv.mul_right a)⁻¹ = equiv.mul_right a⁻¹ := equiv.coe_inj.1 rfl\n\n@[simp, to_additive pow_add_left]\nlemma pow_mul_left (n : ℕ) : equiv.mul_left a ^ n = equiv.mul_left (a ^ n)  :=\nby { ext, simp [perm.coe_pow] }\n\n@[simp, to_additive pow_add_right]\nlemma pow_mul_right (n : ℕ) : equiv.mul_right a ^ n = equiv.mul_right (a ^ n) :=\nby { ext, simp [perm.coe_pow] }\n\n@[simp, to_additive zpow_add_left]\nlemma zpow_mul_left (n : ℤ) : equiv.mul_left a ^ n = equiv.mul_left (a ^ n) :=\n(map_zpow (⟨equiv.mul_left, mul_left_one, mul_left_mul⟩ : α →* perm α) _ _).symm\n\n@[simp, to_additive zpow_add_right]\nlemma zpow_mul_right : ∀ n : ℤ, equiv.mul_right a ^ n = equiv.mul_right (a ^ n)\n| (int.of_nat n) := by simp\n| (int.neg_succ_of_nat n) := by simp\n\nend group\nend equiv\n\nopen equiv function\n\nnamespace set\nvariables {α : Type*} {f : perm α} {s t : set α}\n\n@[simp] lemma bij_on_perm_inv : bij_on ⇑f⁻¹ t s ↔ bij_on f s t := equiv.bij_on_symm\n\nalias bij_on_perm_inv ↔ bij_on.of_perm_inv bij_on.perm_inv\n\nlemma maps_to.perm_pow : maps_to f s s → ∀ n : ℕ, maps_to ⇑(f ^ n) s s :=\nby { simp_rw equiv.perm.coe_pow, exact maps_to.iterate }\nlemma surj_on.perm_pow : surj_on f s s → ∀ n : ℕ, surj_on ⇑(f ^ n) s s :=\nby { simp_rw equiv.perm.coe_pow, exact surj_on.iterate }\nlemma bij_on.perm_pow : bij_on f s s → ∀ n : ℕ, bij_on ⇑(f ^ n) s s :=\nby { simp_rw equiv.perm.coe_pow, exact bij_on.iterate }\n\nlemma bij_on.perm_zpow (hf : bij_on f s s) : ∀ n : ℤ, bij_on ⇑(f ^ n) s s\n| (int.of_nat n) := hf.perm_pow _\n| (int.neg_succ_of_nat n) := by { rw zpow_neg_succ_of_nat, exact (hf.perm_pow _).perm_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/group_theory/perm/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.783492042060489}}
{"text": "import algebra.big_operators.ring algebra.big_operators.order tactic.ring\n\n/-! # IMO 2010 A2 -/\n\nnamespace IMOSL\nnamespace IMO2010A2\n\nopen finset\n\nsection comm_ring_ineq\n\nvariables {R : Type*} [linear_ordered_comm_ring R]\n\nprivate theorem special_identity (x : R) :\n  4 * x ^ 3 - x ^ 4 = 6 * x ^ 2 - 4 * x + 1 - ((x - 1) ^ 2) ^ 2 :=\n  by ring\n\nvariables {ι : Type*} [decidable_eq ι] \n\ntheorem sq_sum_le_sum_sq {s : finset ι} {x : ι → R} (h : ∀ i : ι, i ∈ s → 0 ≤ x i) :\n  s.sum (λ i, x i ^ 2) ≤ s.sum x ^ 2 :=\nbegin\n  induction s using finset.induction with j s s_ih1 s_ih2,\n  rw [sum_empty, sum_empty, zero_pow two_pos],\n  rw [sum_insert s_ih1, sum_insert s_ih1],\n  replace h : 0 ≤ x j ∧ ∀ i : ι, i ∈ s → 0 ≤ x i :=\n    ⟨h j (mem_insert_self j s), λ i h0, h i (mem_insert_of_mem h0)⟩,\n  refine le_trans (add_le_add_left (s_ih2 h.2) _) _; clear s_ih1 s_ih2,\n  rw [add_sq', le_add_iff_nonneg_right],\n  exact mul_nonneg (mul_nonneg zero_le_two h.1) (sum_nonneg h.2)\nend\n\ntheorem QM_AM (s : finset ι) (x : ι → R) : s.sum x ^ 2 ≤ s.card • s.sum (λ i, x i ^ 2) :=\nbegin\n  induction s using finset.induction with j s s_ih1 s_ih2,\n  rw [sum_empty, zero_pow two_pos, card_empty, zero_nsmul],\n  rw [sum_insert s_ih1, sum_insert s_ih1, card_insert_of_not_mem s_ih1, succ_nsmul,\n      add_sq, add_assoc, add_assoc, add_le_add_iff_left, nsmul_add, ← add_assoc,\n      ← sum_const, ← sum_add_distrib, mul_sum],\n  refine add_le_add (sum_le_sum (λ i _, _)) s_ih2,\n  rw mul_right_comm; exact two_mul_le_add_sq (x i) (x j)\nend\n\nend comm_ring_ineq\n\n\n\n\n\nvariables {F : Type*} [linear_ordered_field F]\n\n/-- An intermediate result that is more convenient to manipulate around than the main result -/\ntheorem final_solution_general' {ι : Type*} [decidable_eq ι] {s : finset ι} {a : ι → F}\n    {σ₁ σ₂ B C S : F} (hσ₁ : s.sum a = σ₁) (hσ₂ : s.sum (λ i, a i ^ 2) = σ₂)\n    (hB : 6 * σ₂ - 4 * σ₁ + s.card = B) (hC : (σ₂ - 2 * σ₁ + s.card) ^ 2 = C)\n    (hS : 4 * s.sum (λ i, a i ^ 3) - s.sum (λ i, a i ^ 4) = S) :\n  B - C ≤ S ∧ S ≤ B - C / s.card :=\nbegin\n  ---- Some setups\n  have X := λ (i : ι) (_ : i ∈ s), special_identity (a i),\n  rw [mul_sum, ← sum_sub_distrib, sum_congr rfl X] at hS; clear X,\n  rw [sum_sub_distrib, sum_add_distrib, sum_const, nsmul_one,\n      sum_sub_distrib, ← mul_sum, hσ₂, ← mul_sum, hσ₁, hB] at hS,\n  replace hC : s.sum (λ i, (a i - 1) ^ 2) ^ 2 = C :=\n  begin\n    conv_lhs {congr, congr, skip, funext, rw [sub_sq, one_pow, mul_one] },\n    rw [sum_add_distrib, sum_const, nsmul_one, sum_sub_distrib, hσ₂, ← mul_sum, hσ₁, hC]\n  end,\n  \n  ---- Now we are ready to finish proving both inequalities\n  subst hS; subst hC; split; rw sub_le_sub_iff_left,\n  exact sq_sum_le_sum_sq (λ i _, sq_nonneg (a i - 1)),\n  rcases s.eq_empty_or_nonempty with rfl | h,\n  rw [sum_empty, sum_empty, zero_pow two_pos, zero_div],\n  replace h : 0 < (s.card : F) := by rwa [nat.cast_pos, card_pos],\n  rw [div_le_iff' h, ← nsmul_eq_mul]; exact QM_AM s _\nend\n\n\n\n/-- Final solution, general version -/\ntheorem final_solution_general {ι : Type*} [decidable_eq ι] {s : finset ι} {a : ι → F}\n    {σ₁ σ₂ : F} (h : s.sum a = σ₁) (h0 : s.sum (λ i, a i ^ 2) = σ₂) :\n  let B := 6 * σ₂ - 4 * σ₁ + s.card, C := (σ₂ - 2 * σ₁ + s.card) ^ 2,\n    S := 4 * s.sum (λ i, a i ^ 3) - s.sum (λ i, a i ^ 4) in\n  B - C ≤ S ∧ S ≤ B - C / s.card :=\nfinal_solution_general' h h0 rfl rfl rfl\n\n/-- Final solution -/\ntheorem final_solution {a : fin 4 → F} (h : univ.sum a = 6) (h0 : univ.sum (λ i, a i ^ 2) = 12) :\n  let S := 4 * univ.sum (λ i, a i ^ 3) - univ.sum (λ i, a i ^ 4) in 36 ≤ S ∧ S ≤ 48 :=\n  by intros S; convert final_solution_general h h0; norm_num\n\nend IMO2010A2\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/A2/A2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7834920332703825}}
{"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 analysis.calculus.conformal.inner_product\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.Analysis.InnerProductSpace.ConformalLinearMap\n\n/-!\n# Conformal maps between inner product spaces\n\nA function between inner product spaces is which has a derivative at `x`\nis conformal at `x` iff the derivative preserves inner products up to a scalar multiple.\n-/\n\n\nnoncomputable section\n\nvariable {E F : Type _}\n\nvariable [NormedAddCommGroup E] [NormedAddCommGroup F]\n\nvariable [InnerProductSpace ℝ E] [InnerProductSpace ℝ F]\n\nopen RealInnerProductSpace\n\n/-- A real differentiable map `f` is conformal at point `x` if and only if its\n    differential `fderiv ℝ f x` at that point scales every inner product by a positive scalar. -/\ntheorem conformalAt_iff' {f : E → F} {x : E} :\n    ConformalAt f x ↔ ∃ c : ℝ, 0 < c ∧ ∀ u v : E, ⟪fderiv ℝ f x u, fderiv ℝ f x v⟫ = c * ⟪u, v⟫ :=\n  by rw [conformalAt_iff_isConformalMap_fderiv, isConformalMap_iff]\n#align conformal_at_iff' conformalAt_iff'\n\n/-- A real differentiable map `f` is conformal at point `x` if and only if its\n    differential `f'` at that point scales every inner product by a positive scalar. -/\ntheorem conformalAt_iff {f : E → F} {x : E} {f' : E →L[ℝ] F} (h : HasFderivAt f f' x) :\n    ConformalAt f x ↔ ∃ c : ℝ, 0 < c ∧ ∀ u v : E, ⟪f' u, f' v⟫ = c * ⟪u, v⟫ := by\n  simp only [conformalAt_iff', h.fderiv]\n#align conformal_at_iff conformalAt_iff\n\n/-- The conformal factor of a conformal map at some point `x`. Some authors refer to this function\n    as the characteristic function of the conformal map. -/\ndef conformalFactorAt {f : E → F} {x : E} (h : ConformalAt f x) : ℝ :=\n  Classical.choose (conformalAt_iff'.mp h)\n#align conformal_factor_at conformalFactorAt\n\ntheorem conformalFactorAt_pos {f : E → F} {x : E} (h : ConformalAt f x) : 0 < conformalFactorAt h :=\n  (Classical.choose_spec <| conformalAt_iff'.mp h).1\n#align conformal_factor_at_pos conformalFactorAt_pos\n\ntheorem conformalFactorAt_inner_eq_mul_inner' {f : E → F} {x : E} (h : ConformalAt f x) (u v : E) :\n    ⟪(fderiv ℝ f x) u, (fderiv ℝ f x) v⟫ = (conformalFactorAt h : ℝ) * ⟪u, v⟫ :=\n  (Classical.choose_spec <| conformalAt_iff'.mp h).2 u v\n#align conformal_factor_at_inner_eq_mul_inner' conformalFactorAt_inner_eq_mul_inner'\n\ntheorem conformalFactorAt_inner_eq_mul_inner {f : E → F} {x : E} {f' : E →L[ℝ] F}\n    (h : HasFderivAt f f' x) (H : ConformalAt f x) (u v : E) :\n    ⟪f' u, f' v⟫ = (conformalFactorAt H : ℝ) * ⟪u, v⟫ :=\n  H.DifferentiableAt.HasFderivAt.unique h ▸ conformalFactorAt_inner_eq_mul_inner' H u v\n#align conformal_factor_at_inner_eq_mul_inner conformalFactorAt_inner_eq_mul_inner\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/Conformal/InnerProduct.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7834796419306329}}
{"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ölzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.nat.with_bot\nimport data.polynomial.induction\nimport data.polynomial.monomial\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\nnoncomputable theory\n\nopen finsupp finset\nopen_locale big_operators classical polynomial\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}\n\nsection semiring\nvariables [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 ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise\n`degree 0 = ⊥`. -/\ndef degree (p : R[X]) : with_bot ℕ := p.support.sup some\n\nlemma degree_lt_wf : well_founded (λp q : R[X], degree p < degree q) :=\ninv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)\n\ninstance : has_well_founded R[X] := ⟨_, degree_lt_wf⟩\n\n/-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/\ndef nat_degree (p : R[X]) : ℕ := (degree p).get_or_else 0\n\n/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/\ndef leading_coeff (p : R[X]) : R := coeff p (nat_degree p)\n\n/-- a polynomial is `monic` if its leading coefficient is 1 -/\ndef monic (p : R[X]) := leading_coeff p = (1 : R)\n\n@[nontriviality] lemma monic_of_subsingleton [subsingleton R] (p : R[X]) : monic p :=\nsubsingleton.elim _ _\n\nlemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl\n\ninstance monic.decidable [decidable_eq R] : decidable (monic p) :=\nby unfold monic; apply_instance\n\n@[simp] lemma monic.leading_coeff {p : R[X]} (hp : p.monic) :\n  leading_coeff p = 1 := hp\n\nlemma monic.coeff_nat_degree {p : R[X]} (hp : p.monic) : p.coeff p.nat_degree = 1 := hp\n\n@[simp] lemma degree_zero : degree (0 : R[X]) = ⊥ := rfl\n\n@[simp] lemma nat_degree_zero : nat_degree (0 : R[X]) = 0 := rfl\n\n@[simp] lemma coeff_nat_degree : coeff p (nat_degree p) = leading_coeff p := rfl\n\nlemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=\n⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h;\n  exact support_eq_empty.1 (max_eq_none.1 h),\nλ h, h.symm ▸ rfl⟩\n\n@[nontriviality] lemma degree_of_subsingleton [subsingleton R] : degree p = ⊥ :=\nby rw [subsingleton.elim p 0, degree_zero]\n\n@[nontriviality] lemma nat_degree_of_subsingleton [subsingleton R] : nat_degree p = 0 :=\nby rw [subsingleton.elim p 0, nat_degree_zero]\n\nlemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=\nlet ⟨n, hn⟩ :=\n  not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in\nhave hn : degree p = some n := not_not.1 hn,\nby rw [nat_degree, hn]; refl\n\nlemma degree_eq_iff_nat_degree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :\n  p.degree = n ↔ p.nat_degree = n :=\nby rw [degree_eq_nat_degree hp, with_bot.coe_eq_coe]\n\nlemma degree_eq_iff_nat_degree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :\n  p.degree = n ↔ p.nat_degree = n :=\nbegin\n  split,\n  { intro H, rwa ← degree_eq_iff_nat_degree_eq, rintro rfl,\n    rw degree_zero at H, exact option.no_confusion H },\n  { intro H, rwa degree_eq_iff_nat_degree_eq, rintro rfl,\n    rw nat_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }\nend\n\nlemma nat_degree_eq_of_degree_eq_some {p : R[X]} {n : ℕ}\n  (h : degree p = n) : nat_degree p = n :=\nhave hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,\noption.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,\n  by rwa [← degree_eq_nat_degree hp0]\n\n@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=\nwith_bot.gi_get_or_else_bot.gc.le_u_l _\n\nlemma nat_degree_eq_of_degree_eq [semiring S] {q : S[X]} (h : degree p = degree q) :\n  nat_degree p = nat_degree q :=\nby unfold nat_degree; rw h\n\nlemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=\nshow @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),\nfrom finset.le_sup (mem_support_iff.2 h)\n\nlemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p :=\nbegin\n  rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],\n  exact le_degree_of_ne_zero h,\n  { assume h, subst h, exact h rfl }\nend\n\nlemma le_nat_degree_of_mem_supp (a : ℕ) :\n  a ∈ p.support → a ≤ nat_degree p:=\nle_nat_degree_of_ne_zero ∘ mem_support_iff.mp\n\nlemma degree_mono [semiring S] {f : R[X]} {g : S[X]}\n  (h : f.support ⊆ g.support) : f.degree ≤ g.degree := finset.sup_mono h\n\nlemma supp_subset_range (h : nat_degree p < m) : p.support ⊆ finset.range m :=\nλ n hn, mem_range.2 $ (le_nat_degree_of_mem_supp _ hn).trans_lt h\n\nlemma supp_subset_range_nat_degree_succ : p.support ⊆ finset.range (nat_degree p + 1) :=\nsupp_subset_range (nat.lt_succ_self _)\n\nlemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q :=\nbegin\n  by_cases hp : p = 0,\n  { rw hp, exact bot_le },\n  { rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h }\nend\n\nlemma degree_ne_of_nat_degree_ne {n : ℕ} :\n  p.nat_degree ≠ n → degree p ≠ n :=\nmt $ λ h, by rw [nat_degree, h, option.get_or_else_coe]\n\ntheorem nat_degree_le_iff_degree_le {n : ℕ} : nat_degree p ≤ n ↔ degree p ≤ n :=\nwith_bot.get_or_else_bot_le_iff\n\nalias polynomial.nat_degree_le_iff_degree_le ↔ . .\n\nlemma nat_degree_le_nat_degree [semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :\n  p.nat_degree ≤ q.nat_degree :=\nwith_bot.gi_get_or_else_bot.gc.monotone_l hpq\n\n@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=\nby { rw [degree, ← monomial_zero_left, support_monomial 0 _ ha, sup_singleton], refl }\n\nlemma degree_C_le : degree (C a) ≤ 0 :=\nby by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_rfl]\n\nlemma degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt $ with_bot.coe_lt_coe.mpr zero_lt_one\n\nlemma degree_one_le : degree (1 : R[X]) ≤ (0 : with_bot ℕ) :=\nby rw [← C_1]; exact degree_C_le\n\n@[simp] lemma nat_degree_C (a : R) : nat_degree (C a) = 0 :=\nbegin\n  by_cases ha : a = 0,\n  { have : C a = 0, { rw [ha, C_0] },\n    rw [nat_degree, degree_eq_bot.2 this],\n    refl },\n  { rw [nat_degree, degree_C ha], refl }\nend\n\n@[simp] lemma nat_degree_one : nat_degree (1 : R[X]) = 0 := nat_degree_C 1\n\n@[simp] lemma nat_degree_nat_cast (n : ℕ) : nat_degree (n : R[X]) = 0 :=\nby simp only [←C_eq_nat_cast, nat_degree_C]\n\n@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n :=\nby rw [degree, support_monomial _ _ ha]; refl\n\n@[simp] lemma degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=\nby rw [← monomial_eq_C_mul_X, degree_monomial n ha]\n\nlemma degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 :=\nby simpa only [pow_one] using degree_C_mul_X_pow 1 ha\n\nlemma degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=\nif h : a = 0 then by rw [h, (monomial n).map_zero]; exact bot_le else le_of_eq (degree_monomial n h)\n\nlemma degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n :=\nby { rw C_mul_X_pow_eq_monomial, apply degree_monomial_le }\n\nlemma degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 :=\nby simpa only [pow_one] using degree_C_mul_X_pow_le 1 a\n\n@[simp] lemma nat_degree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : nat_degree (C a * X ^ n) = n :=\nnat_degree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)\n\n@[simp] lemma nat_degree_C_mul_X (a : R) (ha : a ≠ 0) : nat_degree (C a * X) = 1 :=\nby simpa only [pow_one] using nat_degree_C_mul_X_pow 1 a ha\n\n@[simp] lemma nat_degree_monomial [decidable_eq R] (i : ℕ) (r : R)  :\n  nat_degree (monomial i r) = if r = 0 then 0 else i :=\nbegin\n  split_ifs with hr,\n  { simp [hr] },\n  { rw [← C_mul_X_pow_eq_monomial, nat_degree_C_mul_X_pow i r hr] }\nend\n\nlemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=\nnot_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))\n\nlemma coeff_eq_zero_of_nat_degree_lt {p : R[X]} {n : ℕ} (h : p.nat_degree < n) :\n  p.coeff n = 0 :=\nbegin\n  apply coeff_eq_zero_of_degree_lt,\n  by_cases hp : p = 0,\n  { subst hp, exact with_bot.bot_lt_coe n },\n  { rwa [degree_eq_nat_degree hp, with_bot.coe_lt_coe] }\nend\n\n@[simp] lemma coeff_nat_degree_succ_eq_zero {p : R[X]} : p.coeff (p.nat_degree + 1) = 0 :=\ncoeff_eq_zero_of_nat_degree_lt (lt_add_one _)\n\n-- We need the explicit `decidable` argument here because an exotic one shows up in a moment!\nlemma ite_le_nat_degree_coeff (p : R[X]) (n : ℕ) (I : decidable (n < 1 + nat_degree p)) :\n  @ite _ (n < 1 + nat_degree p) I (coeff p n) 0 = coeff p n :=\nbegin\n  split_ifs,\n  { refl },\n  { exact (coeff_eq_zero_of_nat_degree_lt (not_le.1 (λ w, h (nat.lt_one_add_iff.2 w)))).symm, }\nend\n\nlemma as_sum_support (p : R[X]) :\n  p = ∑ i in p.support, monomial i (p.coeff i) :=\n(sum_monomial_eq p).symm\n\nlemma as_sum_support_C_mul_X_pow (p : R[X]) :\n  p = ∑ i in p.support, C (p.coeff i) * X^i :=\ntrans p.as_sum_support $ by simp only [C_mul_X_pow_eq_monomial]\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-/\nlemma sum_over_range' [add_comm_monoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0)\n  (n : ℕ) (w : p.nat_degree < n) :\n  p.sum f = ∑ (a : ℕ) in range n, f a (coeff p a) :=\nbegin\n  rcases p,\n  have := supp_subset_range w,\n  simp only [polynomial.sum, support, coeff, nat_degree, degree] at ⊢ this,\n  exact finsupp.sum_of_support_subset _ this _ (λ n hn, h n)\nend\n\n/--\nWe can reexpress a sum over `p.support` as a sum over `range (p.nat_degree + 1)`.\n-/\nlemma sum_over_range [add_comm_monoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) :\n  p.sum f = ∑ (a : ℕ) in range (p.nat_degree + 1), f a (coeff p a) :=\nsum_over_range' p h (p.nat_degree + 1) (lt_add_one _)\n\nlemma as_sum_range' (p : R[X]) (n : ℕ) (w : p.nat_degree < n) :\n  p = ∑ i in range n, monomial i (coeff p i) :=\np.sum_monomial_eq.symm.trans $ p.sum_over_range' monomial_zero_right _ w\n\nlemma as_sum_range (p : R[X]) :\n  p = ∑ i in range (p.nat_degree + 1), monomial i (coeff p i) :=\np.sum_monomial_eq.symm.trans $ p.sum_over_range $ monomial_zero_right\n\nlemma as_sum_range_C_mul_X_pow (p : R[X]) :\n  p = ∑ i in range (p.nat_degree + 1), C (coeff p i) * X ^ i :=\np.as_sum_range.trans $ by simp only [C_mul_X_pow_eq_monomial]\n\nlemma coeff_ne_zero_of_eq_degree (hn : degree p = n) :\n  coeff p n ≠ 0 :=\nλ h, mem_support_iff.mp (mem_of_max hn) h\n\nlemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) :\n  p = C (p.coeff 1) * X + C (p.coeff 0) :=\next (λ n, nat.cases_on n (by simp)\n  (λ n, nat.cases_on n (by simp [coeff_C])\n    (λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial,\n      by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X,\n        nat.succ_inj', @eq_comm ℕ 0])))\n\nlemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) :\n  p = C (p.leading_coeff) * X + C (p.coeff 0) :=\n(eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_rfl)).trans\n  (by simp [leading_coeff, nat_degree_eq_of_degree_eq_some h])\n\nlemma eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :\n  p = C (p.coeff 1) * X + C (p.coeff 0) :=\neq_X_add_C_of_degree_le_one $ degree_le_of_nat_degree_le h\n\nlemma exists_eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :\n  ∃ a b, p = C a * X + C b :=\n⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_nat_degree_le_one h⟩\n\ntheorem degree_X_pow_le (n : ℕ) : degree (X^n : R[X]) ≤ n :=\nby simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1:R)\n\ntheorem degree_X_le : degree (X : R[X]) ≤ 1 :=\ndegree_monomial_le _ _\n\nlemma nat_degree_X_le : (X : R[X]).nat_degree ≤ 1 :=\nnat_degree_le_of_degree_le degree_X_le\n\nlemma support_C_mul_X_pow (c : R) (n : ℕ) : (C c * X ^ n).support ⊆ singleton n :=\nbegin\n  rw [C_mul_X_pow_eq_monomial],\n  exact support_monomial' _ _\nend\n\nlemma mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ (C c * X ^ n).support) : a = n :=\nmem_singleton.1 $ support_C_mul_X_pow _ _ h\n\nlemma card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : (C c * X ^ n).support.card ≤ 1 :=\nbegin\n  rw ← card_singleton n,\n  apply card_le_of_subset (support_C_mul_X_pow c n),\nend\n\nlemma card_supp_le_succ_nat_degree (p : R[X]) : p.support.card ≤ p.nat_degree + 1 :=\nbegin\n  rw ← finset.card_range (p.nat_degree + 1),\n  exact finset.card_le_of_subset supp_subset_range_nat_degree_succ,\nend\n\nlemma le_degree_of_mem_supp (a : ℕ) :\n  a ∈ p.support → ↑a ≤ degree p :=\nle_degree_of_ne_zero ∘ mem_support_iff.mp\n\nlemma nonempty_support_iff : p.support.nonempty ↔ p ≠ 0 :=\nby rw [ne.def, nonempty_iff_ne_empty, ne.def, ← support_eq_empty]\n\nlemma support_C_mul_X_pow_nonzero {c : R} {n : ℕ} (h : c ≠ 0) :\n  (C c * X ^ n).support = singleton n :=\nbegin\n  rw [C_mul_X_pow_eq_monomial],\n  exact support_monomial _ _ h\nend\n\nend semiring\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma degree_one : degree (1 : R[X]) = (0 : with_bot ℕ) :=\ndegree_C (show (1 : R) ≠ 0, from zero_ne_one.symm)\n\n@[simp] lemma degree_X : degree (X : R[X]) = 1 :=\ndegree_monomial _ one_ne_zero\n\n@[simp] lemma nat_degree_X : (X : R[X]).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some degree_X\n\nend nonzero_semiring\n\nsection ring\nvariables [ring R]\n\nlemma coeff_mul_X_sub_C {p : R[X]} {r : R} {a : ℕ} :\n  coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r :=\nby simp [mul_sub]\n\n@[simp] lemma degree_neg (p : R[X]) : degree (-p) = degree p :=\nby unfold degree; rw support_neg\n\n@[simp] lemma nat_degree_neg (p : R[X]) : nat_degree (-p) = nat_degree p :=\nby simp [nat_degree]\n\n@[simp] lemma nat_degree_int_cast (n : ℤ) : nat_degree (n : R[X]) = 0 :=\nby simp only [←C_eq_int_cast, nat_degree_C]\n\nend ring\n\nsection semiring\nvariables [semiring R]\n\n/-- The second-highest coefficient, or 0 for constants -/\ndef next_coeff (p : R[X]) : R :=\nif p.nat_degree = 0 then 0 else p.coeff (p.nat_degree - 1)\n\n@[simp]\nlemma next_coeff_C_eq_zero (c : R) :\n  next_coeff (C c) = 0 := by { rw next_coeff, simp }\n\nlemma next_coeff_of_pos_nat_degree (p : R[X]) (hp : 0 < p.nat_degree) :\n  next_coeff p = p.coeff (p.nat_degree - 1) :=\nby { rw [next_coeff, if_neg], contrapose! hp, simpa }\n\nvariables {p q : R[X]} {ι : Type*}\n\nlemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) :\n  coeff p (nat_degree q) = 0 :=\ncoeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)\n\nlemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=\nmt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))\n\nlemma ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 :=\npolynomial.ne_zero_of_degree_gt (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr\n  (by rwa [ne.def, polynomial.degree_eq_bot])) hpq : q.degree > ⊥)\n\nlemma ne_zero_of_nat_degree_gt {n : ℕ} (h : n < nat_degree p) : p ≠ 0 :=\nλ H, by simpa [H, nat.not_lt_zero] using h\n\nlemma degree_lt_degree (h : nat_degree p < nat_degree q) : degree p < degree q :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp],\n    rw bot_lt_iff_ne_bot,\n    intro hq,\n    simpa [hp, degree_eq_bot.mp hq, lt_irrefl] using h },\n  { rw [degree_eq_nat_degree hp, degree_eq_nat_degree $ ne_zero_of_nat_degree_gt h],\n    exact_mod_cast h }\nend\n\nlemma nat_degree_lt_nat_degree_iff (hp : p ≠ 0) :\n  nat_degree p < nat_degree q ↔ degree p < degree q :=\n⟨degree_lt_degree, begin\n  intro h,\n  have hq : q ≠ 0 := ne_zero_of_degree_gt h,\n  rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq] at h,\n  exact_mod_cast h\nend⟩\n\nlemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) :=\nbegin\n  ext (_|n), { simp },\n  rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt],\n  exact h.trans_lt (with_bot.some_lt_some.2 n.succ_pos),\nend\n\nlemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=\neq_C_of_degree_le_zero (h ▸ le_rfl)\n\nlemma degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) :=\n⟨eq_C_of_degree_le_zero, λ h, h.symm ▸ degree_C_le⟩\n\nlemma degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) :=\ncalc degree (p + q) = ((p + q).support).sup some : rfl\n  ... ≤ (p.support ∪ q.support).sup some : sup_mono support_add\n  ... = p.support.sup some ⊔ q.support.sup some : sup_union\n\nlemma degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n)\n  (hq : degree q ≤ n) : degree (p + q) ≤ n :=\n(degree_add_le p q).trans $ max_le hp hq\n\nlemma nat_degree_add_le (p q : R[X]) :\n  nat_degree (p + q) ≤ max (nat_degree p) (nat_degree q) :=\nbegin\n  cases le_max_iff.1 (degree_add_le p q);\n  simp [nat_degree_le_nat_degree h]\nend\n\nlemma nat_degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : nat_degree p ≤ n)\n  (hq : nat_degree q ≤ n) : nat_degree (p + q) ≤ n :=\n(nat_degree_add_le p q).trans $ max_le hp hq\n\n@[simp] lemma leading_coeff_zero : leading_coeff (0 : R[X]) = 0 := rfl\n\n@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=\n⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1\n  (not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),\nλ h, h.symm ▸ leading_coeff_zero⟩\n\nlemma leading_coeff_ne_zero : leading_coeff p ≠ 0 ↔ p ≠ 0 :=\nby rw [ne.def, leading_coeff_eq_zero]\n\nlemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ :=\nby rw [leading_coeff_eq_zero, degree_eq_bot]\n\nlemma nat_degree_mem_support_of_nonzero (H : p ≠ 0) : p.nat_degree ∈ p.support :=\nby { rw mem_support_iff, exact (not_congr leading_coeff_eq_zero).mpr H }\n\nlemma nat_degree_eq_support_max' (h : p ≠ 0) :\n  p.nat_degree = p.support.max' (nonempty_support_iff.mpr h) :=\n(le_max' _ _ $ nat_degree_mem_support_of_nonzero h).antisymm $\n  max'_le _ _ _ le_nat_degree_of_mem_supp\n\nlemma nat_degree_C_mul_X_pow_le (a : R) (n : ℕ) : nat_degree (C a * X ^ n) ≤ n :=\nnat_degree_le_iff_degree_le.2 $ degree_C_mul_X_pow_le _ _\n\nlemma degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p :=\nle_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $\n  begin\n    rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, add_zero],\n    exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)\n  end\n\nlemma degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=\nby rw [add_comm, degree_add_eq_left_of_degree_lt h]\n\nlemma nat_degree_add_eq_left_of_nat_degree_lt (h : nat_degree q < nat_degree p) :\n  nat_degree (p + q) = nat_degree p :=\nnat_degree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt (degree_lt_degree h))\n\nlemma nat_degree_add_eq_right_of_nat_degree_lt (h : nat_degree p < nat_degree q) :\n  nat_degree (p + q) = nat_degree q :=\nnat_degree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt (degree_lt_degree h))\n\nlemma degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=\nadd_comm (C a) p ▸ degree_add_eq_right_of_degree_lt $ lt_of_le_of_lt degree_C_le hp\n\nlemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :\n  degree (p + q) = max p.degree q.degree :=\nle_antisymm (degree_add_le _ _) $\n  match lt_trichotomy (degree p) (degree q) with\n  | or.inl hlt :=\n    by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_rfl\n  | or.inr (or.inl heq) :=\n    le_of_not_gt $\n      assume hlt : max (degree p) (degree q) > degree (p + q),\n      h $ show leading_coeff p + leading_coeff q = 0,\n      begin\n        rw [heq, max_self] at hlt,\n        rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add],\n        exact coeff_nat_degree_eq_zero_of_degree_lt hlt\n      end\n  | or.inr (or.inr hlt) :=\n    by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_rfl\n  end\n\nlemma degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p :=\nby { rcases p, simp only [erase, degree, coeff, support], convert sup_mono (erase_subset _ _) }\n\nlemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=\nbegin\n  apply lt_of_le_of_ne (degree_erase_le _ _),\n  rw [degree_eq_nat_degree hp, degree, support_erase],\n  exact λ h, not_mem_erase _ _ (mem_of_max h),\nend\n\nlemma degree_update_le (p : R[X]) (n : ℕ) (a : R) :\n  degree (p.update n a) ≤ max (degree p) n :=\nbegin\n  simp only [degree, coeff_update_apply, le_max_iff, finset.sup_le_iff, mem_support_iff],\n  intros b hb,\n  split_ifs at hb with h,\n  { subst b,\n    exact or.inr le_rfl },\n  { exact or.inl (le_degree_of_ne_zero hb) }\nend\n\nlemma degree_sum_le (s : finset ι) (f : ι → R[X]) :\n  degree (∑ i in s, f i) ≤ s.sup (λ b, degree (f b)) :=\nfinset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $\n  assume a s has ih,\n  calc degree (∑ i in insert a s, f i) ≤ max (degree (f a)) (degree (∑ i in s, f i)) :\n    by rw sum_insert has; exact degree_add_le _ _\n  ... ≤ _ : by rw [sup_insert, sup_eq_max]; exact max_le_max le_rfl ih\n\nlemma degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q :=\ncalc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) :\n    begin\n      simp only [monomial_eq_C_mul_X.symm],\n      convert degree_sum_le _ _,\n      exact mul_eq_sum_sum\n    end\n  ... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) :\n    finset.sup_mono_fun (assume i hi,  degree_sum_le _ _)\n  ... ≤ degree p + degree q :\n    begin\n      refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_C_mul_X_pow_le _ _) _)),\n      rw [with_bot.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    end\n\nlemma degree_pow_le (p : R[X]) : ∀ (n : ℕ), degree (p ^ n) ≤ n • (degree p)\n| 0     := by rw [pow_zero, zero_nsmul]; exact degree_one_le\n| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :\n    by rw pow_succ; exact degree_mul_le _ _\n  ... ≤ _ : by rw succ_nsmul; exact add_le_add le_rfl (degree_pow_le _)\n\n@[simp] lemma leading_coeff_monomial (a : R) (n : ℕ) : leading_coeff (monomial n a) = a :=\nbegin\n  by_cases ha : a = 0,\n  { simp only [ha, (monomial n).map_zero, leading_coeff_zero] },\n  { rw [leading_coeff, nat_degree_monomial, if_neg ha, coeff_monomial], simp }\nend\n\nlemma leading_coeff_C_mul_X_pow (a : R) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=\nby rw [C_mul_X_pow_eq_monomial, leading_coeff_monomial]\n\nlemma leading_coeff_C_mul_X (a : R) : leading_coeff (C a * X) = a :=\nby simpa only [pow_one] using leading_coeff_C_mul_X_pow a 1\n\n@[simp] \n\n@[simp] lemma leading_coeff_X_pow (n : ℕ) : leading_coeff ((X : R[X]) ^ n) = 1 :=\nby simpa only [C_1, one_mul] using leading_coeff_C_mul_X_pow (1 : R) n\n\n@[simp] lemma leading_coeff_X : leading_coeff (X : R[X]) = 1 :=\nby simpa only [pow_one] using @leading_coeff_X_pow R _ 1\n\n@[simp] lemma monic_X_pow (n : ℕ) : monic (X ^ n : R[X]) := leading_coeff_X_pow n\n\n@[simp] lemma monic_X : monic (X : R[X]) := leading_coeff_X\n\n@[simp] lemma leading_coeff_one : leading_coeff (1 : R[X]) = 1 :=\nleading_coeff_C 1\n\n@[simp] lemma monic_one : monic (1 : R[X]) := leading_coeff_C _\n\nlemma monic.ne_zero {R : Type*} [semiring R] [nontrivial R] {p : R[X]} (hp : p.monic) :\n  p ≠ 0 :=\nby { rintro rfl, simpa [monic] using hp }\n\nlemma monic.ne_zero_of_ne (h : (0:R) ≠ 1) {p : R[X]} (hp : p.monic) :\n  p ≠ 0 :=\nby { nontriviality R, exact hp.ne_zero }\n\nlemma monic.ne_zero_of_polynomial_ne {r} (hp : monic p) (hne : q ≠ r) : p ≠ 0 :=\nby { haveI := nontrivial.of_polynomial_ne hne, exact hp.ne_zero }\n\nlemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :\n  leading_coeff (p + q) = leading_coeff q :=\nhave coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h,\nby simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h),\n  this, coeff_add, zero_add]\n\nlemma leading_coeff_add_of_degree_eq (h : degree p = degree q)\n  (hlc : leading_coeff p + leading_coeff q ≠ 0) :\n  leading_coeff (p + q) = leading_coeff p + leading_coeff q :=\nhave nat_degree (p + q) = nat_degree p,\n  by apply nat_degree_eq_of_degree_eq;\n    rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],\nby simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add]\n\n@[simp] lemma coeff_mul_degree_add_degree (p q : R[X]) :\n  coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=\ncalc coeff (p * q) (nat_degree p + nat_degree q) =\n    ∑ x in nat.antidiagonal (nat_degree p + nat_degree q),\n    coeff p x.1 * coeff q x.2 : coeff_mul _ _ _\n... = coeff p (nat_degree p) * coeff q (nat_degree q) :\n  begin\n    refine finset.sum_eq_single (nat_degree p, nat_degree q) _ _,\n    { rintro ⟨i,j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁,\n      by_cases H : nat_degree p < i,\n      { rw [coeff_eq_zero_of_degree_lt\n          (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 H)), zero_mul] },\n      { rw not_lt_iff_eq_or_lt at H, cases H,\n        { subst H, rw add_left_cancel_iff at h₁, dsimp at h₁, subst h₁, exfalso, exact h₂ rfl },\n        { suffices : nat_degree q < j,\n          { rw [coeff_eq_zero_of_degree_lt\n              (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 this)), mul_zero] },\n          { by_contra H', rw not_lt at H',\n            exact ne_of_lt (nat.lt_of_lt_of_le\n              (nat.add_lt_add_right H j) (nat.add_le_add_left H' _)) h₁ } } } },\n    { intro H, exfalso, apply H, rw nat.mem_antidiagonal }\n  end\n\nlemma degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  degree (p * q) = degree p + degree q :=\nhave hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul],\nhave hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero],\nle_antisymm (degree_mul_le _ _)\nbegin\n  rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],\n  refine le_degree_of_ne_zero _,\n  rwa coeff_mul_degree_add_degree\nend\n\nlemma monic.degree_mul (hq : monic q) : degree (p * q) = degree p + degree q :=\nif hp : p = 0 then by simp [hp]\nelse degree_mul' $ by rwa [hq.leading_coeff, mul_one, ne.def, leading_coeff_eq_zero]\n\nlemma nat_degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  nat_degree (p * q) = nat_degree p + nat_degree q :=\nhave hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]),\nhave hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]),\nnat_degree_eq_of_degree_eq_some $\n  by rw [degree_mul' h, with_bot.coe_add, degree_eq_nat_degree hp, degree_eq_nat_degree hq]\n\nlemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  leading_coeff (p * q) = leading_coeff p * leading_coeff q :=\nbegin\n  unfold leading_coeff,\n  rw [nat_degree_mul' h, coeff_mul_degree_add_degree],\n  refl\nend\n\nlemma monomial_nat_degree_leading_coeff_eq_self (h : p.support.card ≤ 1) :\n  monomial p.nat_degree p.leading_coeff = p :=\nbegin\n  rcases card_support_le_one_iff_monomial.1 h with ⟨n, a, rfl⟩,\n  by_cases ha : a = 0;\n  simp [ha]\nend\n\nlemma C_mul_X_pow_eq_self (h : p.support.card ≤ 1) :\n  C p.leading_coeff * X^p.nat_degree = p :=\nby rw [C_mul_X_pow_eq_monomial, monomial_nat_degree_leading_coeff_eq_self h]\n\nlemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →\n  leading_coeff (p ^ n) = leading_coeff p ^ n :=\nnat.rec_on n (by simp) $\nλ n ih h,\nhave h₁ : leading_coeff p ^ n ≠ 0 :=\n  λ h₁, h $ by rw [pow_succ, h₁, mul_zero],\nhave h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=\n  by rwa [pow_succ, ← ih h₁] at h,\nby rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]\n\nlemma degree_pow' : ∀ {n : ℕ}, leading_coeff p ^ n ≠ 0 →\n  degree (p ^ n) = n • (degree p)\n| 0     := λ h, by rw [pow_zero, ← C_1] at *;\n  rw [degree_C h, zero_nsmul]\n| (n+1) := λ h,\nhave h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $\n  by rw [pow_succ, h₁, mul_zero],\nhave h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=\n  by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,\nby rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁]\n\nlemma nat_degree_pow' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) :\n  nat_degree (p ^ n) = n * nat_degree p :=\nif hp0 : p = 0 then\n  if hn0 : n = 0 then by simp *\n  else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp\nelse\nhave hpn : p ^ n ≠ 0, from λ hpn0,  have h1 : _ := h,\n  by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h;\n  exact h rfl,\noption.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ),\n  by rw [← degree_eq_nat_degree hpn, degree_pow' h, degree_eq_nat_degree hp0,\n    ← with_bot.coe_nsmul]; simp\n\ntheorem leading_coeff_monic_mul {p q : R[X]} (hp : monic p) :\n  leading_coeff (p * q) = leading_coeff q :=\nbegin\n  rcases eq_or_ne q 0 with rfl|H,\n  { simp },\n  { rw [leading_coeff_mul', hp.leading_coeff, one_mul],\n    rwa [hp.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero] }\nend\n\ntheorem leading_coeff_mul_monic {p q : R[X]} (hq : monic q) :\n  leading_coeff (p * q) = leading_coeff p :=\ndecidable.by_cases\n  (λ H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero])\n  (λ H : leading_coeff p ≠ 0,\n    by rw [leading_coeff_mul', hq.leading_coeff, mul_one];\n      rwa [hq.leading_coeff, mul_one])\n\n@[simp] theorem leading_coeff_mul_X_pow {p : R[X]} {n : ℕ} :\n  leading_coeff (p * X ^ n) = leading_coeff p :=\nleading_coeff_mul_monic (monic_X_pow n)\n\n@[simp] theorem leading_coeff_mul_X {p : R[X]} :\n  leading_coeff (p * X) = leading_coeff p :=\nleading_coeff_mul_monic monic_X\n\nlemma nat_degree_mul_le {p q : R[X]} : nat_degree (p * q) ≤ nat_degree p + nat_degree q :=\nbegin\n  apply nat_degree_le_of_degree_le,\n  apply le_trans (degree_mul_le p q),\n  rw with_bot.coe_add,\n  refine add_le_add _ _; apply degree_le_nat_degree,\nend\n\nlemma nat_degree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).nat_degree ≤ n * p.nat_degree :=\nbegin\n  induction n with i hi,\n  { simp },\n  { rw [pow_succ, nat.succ_mul, add_comm],\n    apply le_trans nat_degree_mul_le,\n    exact add_le_add_left hi _ }\nend\n\n@[simp] lemma coeff_pow_mul_nat_degree (p : R[X]) (n : ℕ) :\n  (p ^ n).coeff (n * p.nat_degree) = p.leading_coeff ^ n :=\nbegin\n  induction n with i hi,\n  { simp },\n  { rw [pow_succ', pow_succ', nat.succ_mul],\n    by_cases hp1 : p.leading_coeff ^ i = 0,\n    { rw [hp1, zero_mul],\n      by_cases hp2 : p ^ i = 0,\n      { rw [hp2, zero_mul, coeff_zero] },\n      { apply coeff_eq_zero_of_nat_degree_lt,\n        have h1 : (p ^ i).nat_degree < i * p.nat_degree,\n        { apply lt_of_le_of_ne nat_degree_pow_le (λ h, hp2 _),\n          rw [←h, hp1] at hi,\n          exact leading_coeff_eq_zero.mp hi },\n        calc (p ^ i * p).nat_degree ≤ (p ^ i).nat_degree + p.nat_degree : nat_degree_mul_le\n                                ... < i * p.nat_degree + p.nat_degree : add_lt_add_right h1 _ } },\n    { rw [←nat_degree_pow' hp1, ←leading_coeff_pow' hp1],\n      exact coeff_mul_degree_add_degree _ _ } }\nend\n\nlemma subsingleton_of_monic_zero (h : monic (0 : R[X])) :\n  (∀ p q : R[X], p = q) ∧ (∀ a b : R, a = b) :=\nby rw [monic.def, leading_coeff_zero] at h;\n  exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero],\n    λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩\n\nlemma zero_le_degree_iff {p : R[X]} : 0 ≤ degree p ↔ p ≠ 0 :=\nby rw [ne.def, ← degree_eq_bot];\n  cases degree p; exact dec_trivial\n\nlemma degree_nonneg_iff_ne_zero : 0 ≤ degree p ↔ p ≠ 0 :=\n⟨λ h0p hp0, absurd h0p (by rw [hp0, degree_zero]; exact dec_trivial),\n  λ hp0, le_of_not_gt (λ h, by simp [gt, degree_eq_bot, *] at *)⟩\n\nlemma nat_degree_eq_zero_iff_degree_le_zero : p.nat_degree = 0 ↔ p.degree ≤ 0 :=\nby rw [← nonpos_iff_eq_zero, nat_degree_le_iff_degree_le, with_bot.coe_zero]\n\ntheorem degree_le_iff_coeff_zero (f : R[X]) (n : with_bot ℕ) :\n  degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 :=\n⟨λ (H : finset.sup (f.support) some ≤ n) m (Hm : n < (m : with_bot ℕ)), decidable.of_not_not $ λ H4,\n  have H1 : m ∉ f.support,\n    from λ H2, not_lt_of_ge ((finset.sup_le_iff.1 H) m H2 : ((m : with_bot ℕ) ≤ n)) Hm,\n  H1 $ mem_support_iff.2 H4,\nλ H, finset.sup_le $ λ b Hb, decidable.of_not_not $ λ Hn,\n  mem_support_iff.1 Hb $ H b $ lt_of_not_ge Hn⟩\n\ntheorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :\n  degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 :=\nbegin\n  refine ⟨λ hf m hm, coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hf (with_bot.coe_le_coe.2 hm)), _⟩,\n  simp only [degree, finset.sup_lt_iff (with_bot.bot_lt_coe n), mem_support_iff,\n    with_bot.some_eq_coe, with_bot.coe_lt_coe, ← @not_le ℕ],\n  exact λ h m, mt (h m),\nend\n\nlemma degree_smul_le (a : R) (p : R[X]) : degree (a • p) ≤ degree p :=\nbegin\n  apply (degree_le_iff_coeff_zero _ _).2 (λ m hm, _),\n  rw degree_lt_iff_coeff_zero at hm,\n  simp [hm m le_rfl],\nend\n\nlemma nat_degree_smul_le (a : R) (p : R[X]) : nat_degree (a • p) ≤ nat_degree p :=\nnat_degree_le_nat_degree (degree_smul_le a p)\n\nlemma degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree :=\nby haveI := nontrivial.of_polynomial_ne hp; exact\nhave leading_coeff p * leading_coeff X ≠ 0, by simpa,\nby erw [degree_mul' this, degree_eq_nat_degree hp,\n    degree_X, ← with_bot.coe_one, ← with_bot.coe_add, with_bot.coe_lt_coe];\n  exact nat.lt_succ_self _\n\nlemma nat_degree_pos_iff_degree_pos :\n  0 < nat_degree p ↔ 0 < degree p :=\nlt_iff_lt_of_le_iff_le nat_degree_le_iff_degree_le\n\nlemma eq_C_of_nat_degree_le_zero (h : nat_degree p ≤ 0) : p = C (coeff p 0) :=\neq_C_of_degree_le_zero $ degree_le_of_nat_degree_le h\n\nlemma eq_C_of_nat_degree_eq_zero (h : nat_degree p = 0) : p = C (coeff p 0) :=\neq_C_of_nat_degree_le_zero h.le\n\nlemma ne_zero_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : p ≠ 0 :=\nby rw ← degree_nonneg_iff_ne_zero; exact trans (by exact_mod_cast n.zero_le) hdeg\n\nlemma le_nat_degree_of_coe_le_degree (hdeg : ↑n ≤ p.degree) :\n  n ≤ p.nat_degree :=\nwith_bot.coe_le_coe.mp ((degree_eq_nat_degree $ ne_zero_of_coe_le_degree hdeg) ▸ hdeg)\n\nlemma degree_sum_fin_lt {n : ℕ} (f : fin n → R) :\n  degree (∑ i : fin n, C (f i) * X ^ (i : ℕ)) < n :=\nbegin\n  haveI : is_commutative (with_bot ℕ) max := ⟨max_comm⟩,\n  haveI : is_associative (with_bot ℕ) max := ⟨max_assoc⟩,\n  calc  (∑ i, C (f i) * X ^ (i : ℕ)).degree\n      ≤ finset.univ.fold (⊔) ⊥ (λ i, (C (f i) * X ^ (i : ℕ)).degree) : degree_sum_le _ _\n  ... = finset.univ.fold max ⊥ (λ i, (C (f i) * X ^ (i : ℕ)).degree) : rfl\n  ... < n : (finset.fold_max_lt (n : with_bot ℕ)).mpr ⟨with_bot.bot_lt_coe _, _⟩,\n\n  rintros ⟨i, hi⟩ -,\n  calc (C (f ⟨i, hi⟩) * X ^ i).degree\n      ≤ (C _).degree + (X ^ i).degree : degree_mul_le _ _\n  ... ≤ 0 + i : add_le_add degree_C_le (degree_X_pow_le i)\n  ... = i : zero_add _\n  ... < n : with_bot.some_lt_some.mpr hi,\nend\n\nlemma degree_linear_le : degree (C a * X + C b) ≤ 1 :=\ndegree_add_le_of_degree_le (degree_C_mul_X_le _) $ le_trans degree_C_le nat.with_bot.coe_nonneg\n\nlemma degree_linear_lt : degree (C a * X + C b) < 2 :=\ndegree_linear_le.trans_lt $ with_bot.coe_lt_coe.mpr one_lt_two\n\nlemma degree_C_lt_degree_C_mul_X (ha : a ≠ 0) : degree (C b) < degree (C a * X) :=\nby simpa only [degree_C_mul_X ha] using degree_C_lt\n\n@[simp] lemma degree_linear (ha : a ≠ 0) : degree (C a * X + C b) = 1 :=\nby rw [degree_add_eq_left_of_degree_lt $ degree_C_lt_degree_C_mul_X ha, degree_C_mul_X ha]\n\nlemma nat_degree_linear_le : nat_degree (C a * X + C b) ≤ 1 :=\nnat_degree_le_of_degree_le degree_linear_le\n\n@[simp] lemma nat_degree_linear (ha : a ≠ 0) : nat_degree (C a * X + C b) = 1 :=\nnat_degree_eq_of_degree_eq_some $ degree_linear ha\n\n@[simp] lemma leading_coeff_linear (ha : a ≠ 0): leading_coeff (C a * X + C b) = a :=\nby rw [add_comm, leading_coeff_add_of_degree_lt (degree_C_lt_degree_C_mul_X ha),\n       leading_coeff_C_mul_X]\n\nlemma degree_quadratic_le : degree (C a * X ^ 2 + C b * X + C c) ≤ 2 :=\nby simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 2 a)\n  (le_trans degree_linear_le $ with_bot.coe_le_coe.mpr one_le_two)\n\nlemma degree_quadratic_lt : degree (C a * X ^ 2 + C b * X + C c) < 3 :=\ndegree_quadratic_le.trans_lt $ with_bot.coe_lt_coe.mpr $ lt_add_one 2\n\nlemma degree_linear_lt_degree_C_mul_X_sq (ha : a ≠ 0) :\n  degree (C b * X + C c) < degree (C a * X ^ 2) :=\nby simpa only [degree_C_mul_X_pow 2 ha] using degree_linear_lt\n\n@[simp] lemma degree_quadratic (ha : a ≠ 0) : degree (C a * X ^ 2 + C b * X + C c) = 2 :=\nbegin\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  refl\nend\n\nlemma nat_degree_quadratic_le : nat_degree (C a * X ^ 2 + C b * X + C c) ≤ 2 :=\nnat_degree_le_of_degree_le degree_quadratic_le\n\n@[simp] lemma nat_degree_quadratic (ha : a ≠ 0) : nat_degree (C a * X ^ 2 + C b * X + C c) = 2 :=\nnat_degree_eq_of_degree_eq_some $ degree_quadratic ha\n\n@[simp] lemma leading_coeff_quadratic (ha : a ≠ 0) :\n  leading_coeff (C a * X ^ 2 + C b * X + C c) = a :=\nby rw [add_assoc, add_comm, leading_coeff_add_of_degree_lt $\n         degree_linear_lt_degree_C_mul_X_sq ha, leading_coeff_C_mul_X_pow]\n\nlemma degree_cubic_le : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 :=\nby simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 3 a)\n  (le_trans degree_quadratic_le $ with_bot.coe_le_coe.mpr $ nat.le_succ 2)\n\nlemma degree_cubic_lt : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) < 4 :=\ndegree_cubic_le.trans_lt $ with_bot.coe_lt_coe.mpr $ lt_add_one 3\n\nlemma degree_quadratic_lt_degree_C_mul_X_cb (ha : a ≠ 0) :\n  degree (C b * X ^ 2 + C c * X + C d) < degree (C a * X ^ 3) :=\nby simpa only [degree_C_mul_X_pow 3 ha] using degree_quadratic_lt\n\n@[simp] lemma degree_cubic (ha : a ≠ 0) : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 :=\nbegin\n  rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), degree_add_eq_left_of_degree_lt $\n        degree_quadratic_lt_degree_C_mul_X_cb ha, degree_C_mul_X_pow 3 ha],\n  refl\nend\n\nlemma nat_degree_cubic_le : nat_degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 :=\nnat_degree_le_of_degree_le degree_cubic_le\n\n@[simp] lemma nat_degree_cubic (ha : a ≠ 0) :\n  nat_degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 :=\nnat_degree_eq_of_degree_eq_some $ degree_cubic ha\n\n@[simp] lemma leading_coeff_cubic (ha : a ≠ 0):\n  leading_coeff (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = a :=\nby rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), add_comm, leading_coeff_add_of_degree_lt $\n         degree_quadratic_lt_degree_C_mul_X_cb ha, leading_coeff_C_mul_X_pow]\n\nend semiring\n\n\nsection nontrivial_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma degree_X_pow (n : ℕ) : degree ((X : R[X]) ^ n) = n :=\nby rw [X_pow_eq_monomial, degree_monomial _ (@one_ne_zero R _ _)]\n\n@[simp] lemma nat_degree_X_pow (n : ℕ) : nat_degree ((X : R[X]) ^ n) = n :=\nnat_degree_eq_of_degree_eq_some (degree_X_pow n)\n\ntheorem not_is_unit_X : ¬ is_unit (X : R[X]) :=\nλ ⟨⟨_, g, hfg, hgf⟩, rfl⟩, @zero_ne_one R _ _ $\nby { change g * monomial 1 1 = 1 at hgf, rw [← coeff_one_zero, ← hgf], simp }\n\n@[simp] lemma degree_mul_X : degree (p * X) = degree p + 1 := by simp [monic_X.degree_mul]\n\n@[simp] lemma degree_mul_X_pow : degree (p * X ^ n) = degree p + n :=\nby simp [(monic_X_pow n).degree_mul]\n\nend nontrivial_semiring\n\nsection ring\nvariables [ring R] {p q : R[X]}\n\nlemma degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) :=\nby simpa only [sub_eq_add_neg, degree_neg q] using degree_add_le p (-q)\n\nlemma degree_sub_lt (hd : degree p = degree q)\n  (hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :\n  degree (p - q) < degree p :=\nhave hp : monomial (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=\n  monomial_add_erase _ _,\nhave hq : monomial (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=\n  monomial_add_erase _ _,\nhave hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,\nhave hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),\ncalc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :\n  by conv { to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg] }\n... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))\n  : degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _\n... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩\n\n\nlemma nat_degree_X_sub_C_le {r : R} : (X - C r).nat_degree ≤ 1 :=\nnat_degree_le_iff_degree_le.2 $ le_trans (degree_sub_le _ _) $ max_le degree_X_le $\nle_trans degree_C_le $ with_bot.coe_le_coe.2 zero_le_one\n\nlemma degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p :=\nby { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h] }\n\nlemma degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q :=\nby { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg] }\n\nend ring\n\nsection nonzero_ring\nvariables [nontrivial R]\n\nsection semiring\nvariable [semiring R]\n\n@[simp] lemma degree_X_add_C (a : R) : degree (X + C a) = 1 :=\nhave degree (C a) < degree (X : R[X]),\nfrom calc degree (C a) ≤ 0 : degree_C_le\n                   ... < 1 : with_bot.some_lt_some.mpr zero_lt_one\n                   ... = degree X : degree_X.symm,\nby rw [degree_add_eq_left_of_degree_lt this, degree_X]\n\n@[simp] lemma nat_degree_X_add_C (x : R) : (X + C x).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some $ degree_X_add_C x\n\n@[simp]\nlemma next_coeff_X_add_C [semiring S] (c : S) : next_coeff (X + C c) = c :=\nbegin\n  nontriviality S,\n  simp [next_coeff_of_pos_nat_degree]\nend\n\nlemma degree_X_pow_add_C {n : ℕ} (hn : 0 < n) (a : R) :\n  degree ((X : R[X]) ^ n + C a) = n :=\nhave degree (C a) < degree ((X : R[X]) ^ n),\n  from calc degree (C a) ≤ 0 : degree_C_le\n  ... < degree ((X : R[X]) ^ n) : by rwa [degree_X_pow];\n    exact with_bot.coe_lt_coe.2 hn,\nby rw [degree_add_eq_left_of_degree_lt this, degree_X_pow]\n\nlemma X_pow_add_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :\n  (X : R[X]) ^ n + C a ≠ 0 :=\nmt degree_eq_bot.2 (show degree ((X : R[X]) ^ n + C a) ≠ ⊥,\n  by rw degree_X_pow_add_C hn a; exact dec_trivial)\n\ntheorem X_add_C_ne_zero (r : R) : X + C r ≠ 0 :=\npow_one (X : R[X]) ▸ X_pow_add_C_ne_zero zero_lt_one r\n\ntheorem zero_nmem_multiset_map_X_add_C {α : Type*} (m : multiset α) (f : α → R) :\n  (0 : R[X]) ∉ m.map (λ a, X + C (f a)) :=\nλ mem, let ⟨a, _, ha⟩ := multiset.mem_map.mp mem in X_add_C_ne_zero _ ha\n\nlemma nat_degree_X_pow_add_C {n : ℕ} {r : R} :\n  (X ^ n + C r).nat_degree = n :=\nbegin\n  by_cases hn : n = 0,\n  { rw [hn, pow_zero, ←C_1, ←ring_hom.map_add, nat_degree_C] },\n  { exact nat_degree_eq_of_degree_eq_some (degree_X_pow_add_C (pos_iff_ne_zero.mpr hn) r) },\nend\n\n@[simp] lemma leading_coeff_X_pow_add_C {n : ℕ} (hn : 0 < n) {r : R} :\n  (X ^ n + C r).leading_coeff = 1 :=\nby rw [leading_coeff, nat_degree_X_pow_add_C, coeff_add, coeff_X_pow_self,\n  coeff_C, if_neg (pos_iff_ne_zero.mp hn), add_zero]\n\n@[simp] lemma leading_coeff_X_add_C [semiring S] (r : S) :\n  (X + C r).leading_coeff = 1 :=\nbegin\n  nontriviality,\n  rw [←pow_one (X : S[X]), leading_coeff_X_pow_add_C zero_lt_one],\n  apply_instance\nend\n\n@[simp] lemma leading_coeff_X_pow_add_one {n : ℕ} (hn : 0 < n) :\n  (X ^ n + 1 : R[X]).leading_coeff = 1 :=\nleading_coeff_X_pow_add_C hn\n\n@[simp] lemma leading_coeff_pow_X_add_C (r : R) (i : ℕ) :\n  leading_coeff ((X + C r) ^ i) = 1 :=\nby { nontriviality, rw leading_coeff_pow'; simp }\n\nend semiring\n\nvariables [ring R]\n\n@[simp] lemma degree_X_sub_C (a : R) : degree (X - C a) = 1 :=\nby rw [sub_eq_add_neg, ←map_neg C a, degree_X_add_C]\n\n@[simp] lemma nat_degree_X_sub_C (x : R) : (X - C x).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some $ degree_X_sub_C x\n\n@[simp]\nlemma next_coeff_X_sub_C [ring S] (c : S) : next_coeff (X - C c) = - c :=\nby rw [sub_eq_add_neg, ←map_neg C c, next_coeff_X_add_C]\n\nlemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :\n  degree ((X : R[X]) ^ n - C a) = n :=\nby rw [sub_eq_add_neg, ←map_neg C a, degree_X_pow_add_C hn]; apply_instance\n\nlemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :\n  (X : R[X]) ^ n - C a ≠ 0 :=\nby { rw [sub_eq_add_neg, ←map_neg C a], exact X_pow_add_C_ne_zero hn _ }\n\ntheorem X_sub_C_ne_zero (r : R) : X - C r ≠ 0 :=\npow_one (X : R[X]) ▸ X_pow_sub_C_ne_zero zero_lt_one r\n\ntheorem zero_nmem_multiset_map_X_sub_C {α : Type*} (m : multiset α) (f : α → R) :\n  (0 : R[X]) ∉ m.map (λ a, X - C (f a)) :=\nλ mem, let ⟨a, _, ha⟩ := multiset.mem_map.mp mem in X_sub_C_ne_zero _ ha\n\nlemma nat_degree_X_pow_sub_C {n : ℕ} {r : R} :\n  (X ^ n - C r).nat_degree = n :=\nby rw [sub_eq_add_neg, ←map_neg C r, nat_degree_X_pow_add_C]\n\n@[simp] lemma leading_coeff_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} :\n  (X ^ n - C r).leading_coeff = 1 :=\nby rw [sub_eq_add_neg, ←map_neg C r, leading_coeff_X_pow_add_C hn]; apply_instance\n\n@[simp] lemma leading_coeff_X_sub_C [ring S] (r : S) :\n  (X - C r).leading_coeff = 1 :=\nby rw [sub_eq_add_neg, ←map_neg C r, leading_coeff_X_add_C]\n\n@[simp] lemma leading_coeff_X_pow_sub_one {n : ℕ} (hn : 0 < n) :\n  (X ^ n - 1 : R[X]).leading_coeff = 1 :=\nleading_coeff_X_pow_sub_C hn\n\nend nonzero_ring\n\nsection no_zero_divisors\nvariables [semiring R] [no_zero_divisors R] {p q : R[X]}\n\n@[simp] lemma degree_mul : degree (p * q) = degree p + degree q :=\nif hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add]\nelse if hq0 : q = 0 then  by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot]\nelse degree_mul' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)\n    (mt leading_coeff_eq_zero.1 hq0)\n\n/-- `degree` as a monoid homomorphism between `R[X]` and `multiplicative (with_bot ℕ)`.\n  This is useful to prove results about multiplication and degree. -/\ndef degree_monoid_hom [nontrivial R] : R[X] →* multiplicative (with_bot ℕ) :=\n{ to_fun := degree,\n  map_one' := degree_one,\n  map_mul' := λ _ _, degree_mul }\n\n@[simp] lemma degree_pow [nontrivial R] (p : R[X]) (n : ℕ) :\n  degree (p ^ n) = n • (degree p) :=\nmap_pow (degree_monoid_hom : R[X] →* _) _ _\n\n@[simp] lemma leading_coeff_mul (p q : R[X]) : leading_coeff (p * q) =\n  leading_coeff p * leading_coeff q :=\nbegin\n  by_cases hp : p = 0,\n  { simp only [hp, zero_mul, leading_coeff_zero] },\n  { by_cases hq : q = 0,\n    { simp only [hq, mul_zero, leading_coeff_zero] },\n    { rw [leading_coeff_mul'],\n      exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }\nend\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[X] →* R :=\n{ to_fun := leading_coeff,\n  map_one' := by simp,\n  map_mul' := leading_coeff_mul }\n\n@[simp] lemma leading_coeff_hom_apply (p : R[X]) :\n  leading_coeff_hom p = leading_coeff p := rfl\n\n@[simp] lemma leading_coeff_pow (p : R[X]) (n : ℕ) :\n  leading_coeff (p ^ n) = leading_coeff p ^ n :=\n(leading_coeff_hom : R[X] →* R).map_pow p n\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/definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7834796416288988}}
{"text": "open Nat\n\ndef even (n : Nat) : Prop := ∃ d, n=2*d\n\nexample (n : Nat) : (even n) → (even (n+2)) := by\nintro h1\napply Exists.elim h1\nintro a h2\nrw [h2,← Nat.mul_one 2,← Nat.left_distrib, Nat.mul_one]\napply Exists.intro (a+1)\nrfl\n\ntheorem leq_eq_exist_nat_add {n m : Nat} : n ≤ m → ∃ k, m = n + k := by\nintro h\ninduction h with\n| refl => exact (Exists.intro 0 (Nat.add_zero n))\n| step _ ih => apply Exists.elim ih\n               intro x hx\n               rw [hx,← Nat.add_comm, ← Nat.succ_add, Nat.add_comm]\n               exact Exists.intro (succ x) rfl\n\ndef subtract (n m : Nat) : Nat :=\nmatch m with\n| zero => n\n| succ k => pred (subtract n k)\n\ntheorem zero_sub : subtract zero k = zero := by\ninduction k with\n| zero => rfl\n| succ l ih => rw [subtract,ih,Nat.pred_zero]\n\ntheorem pred_sub_eq_sub_pred : pred (subtract n k) = subtract (pred n) k := by\ninduction k with\n| zero => rw [subtract,subtract]\n| succ k ih => rw [subtract,ih,subtract]\n\ntheorem left_sub_cancel : subtract (n+k) n = k := by\ninduction n with\n| zero => rw [Nat.zero_add,subtract]\n| succ n ih => rw [Nat.succ_add,subtract,pred_sub_eq_sub_pred,Nat.pred_succ,ih]\n\ntheorem sub_add_eq_sub_diff (h1 : n ≤ m) (h2 : k ≤ n) : subtract m n + subtract n k = subtract m k := by\ncases n with\n| zero => rw [subtract,zero_sub,Nat.add_zero,Nat.eq_zero_of_le_zero h2,subtract]\n| succ l => have : ∃ r, m = succ l + r := leq_eq_exist_nat_add h1\n            apply Exists.elim this\n            intro x hx\n            rw [hx]\n            have : ∃ r, succ l = k + r := leq_eq_exist_nat_add h2\n            apply Exists.elim this\n            intro y hy\n            rw [hy]\n            rw [left_sub_cancel,left_sub_cancel]\n            rw [Nat.add_assoc,left_sub_cancel,Nat.add_comm]\n\ntheorem sub_add_eq_sub_sub : subtract n (k+l) = subtract (subtract n k) l := by\ninduction l with\n| zero => rw [Nat.add_zero,subtract]\n| succ s ih => rw [Nat.add_succ,subtract,ih,← subtract]\n\ntheorem sub_mul_eq_mul_sub : subtract (k*n) (k*m) = k*(subtract n m) := by\ninduction m with\n| zero => rw [Nat.mul_zero,subtract,subtract]\n| succ s ih => rw [Nat.mul_succ,sub_add_eq_sub_sub,ih,subtract]\n               cases (subtract n s) with\n               | zero => rw [Nat.mul_zero,Nat.pred_zero,Nat.mul_zero,zero_sub]\n               | succ r => rw [Nat.mul_succ,Nat.add_comm,left_sub_cancel,Nat.pred_succ]\n\n-- simple lemma for even numbers\nexample {n m k : Nat} : (even n) → (even m) → subtract n m = k → even k := by\nintro h1 h2 h3\napply Exists.elim h1\nintro s hs\napply Exists.elim h2\nintro r hr\nrw [hs,hr] at h3\nhave : subtract (2*s) (2*r) = 2*(subtract s r) := sub_mul_eq_mul_sub\nrw [this] at h3\nexact Exists.intro (subtract s r) (Eq.symm h3)", "meta": {"author": "Euctemon", "repo": "proofs-in-lean", "sha": "2a6d10e17ae1c15e814ad9ab24a76e937f95586a", "save_path": "github-repos/lean/Euctemon-proofs-in-lean", "path": "github-repos/lean/Euctemon-proofs-in-lean/proofs-in-lean-2a6d10e17ae1c15e814ad9ab24a76e937f95586a/subtraction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7834796366140399}}
{"text": "import tactic\n\n#check setoid\n#check @quotient\n#check prod\n\ndef int_relation : ℕ × ℕ → ℕ × ℕ → Prop\n| (a, b) (c, d) := a + d = c + b\n\nlemma int_relation_reflexive : reflexive int_relation :=\nbegin\n  rintro ⟨a, b⟩,\n  unfold int_relation\nend\n\nlemma int_relation_symmetric : symmetric int_relation :=\nbegin\n  rintros ⟨a, b⟩ ⟨c, d⟩ h,\n  unfold int_relation at h ⊢,\n  symmetry,\n  assumption\nend\n\nlemma int_relation_transitive : transitive int_relation :=\nbegin\n  rintros ⟨a, b⟩ ⟨c, d⟩ ⟨m, n⟩ h₁ h₂,\n  unfold int_relation at h₁ h₂ ⊢,\n  linarith\nend\n\nlemma int_relation_equivalence : equivalence int_relation :=\nbegin\n  refine ⟨_, _, _⟩,\n  { exact int_relation_reflexive },\n  { exact int_relation_symmetric },\n  { exact int_relation_transitive }\nend\n\n#check int\n\ninstance int_setoid : setoid (ℕ × ℕ) := ⟨int_relation, int_relation_equivalence⟩\n\ndef int' : Type := quotient int_setoid\n\ndef int'_of_nat (n : ℕ) : int' := quotient.mk (n, 0)\n\n#check has_add\n\ndef int_add : ℕ × ℕ → ℕ × ℕ → int'\n| (a, b) (c, d) := quotient.mk (a + c, b + d)\n\ninstance : has_add int' :=\nbegin\n  constructor,\n  apply quotient.lift₂ int_add,\n  rintros ⟨a₁₁, a₁₂⟩ ⟨a₂₁, a₂₂⟩ ⟨b₁₁, b₁₂⟩ ⟨b₂₁, b₂₂⟩ h₁ h₂,\n  apply quotient.sound,\n  change _ = _,\n  change _ = _ at h₁,\n  change _ = _ at h₂,\n  linarith\nend\n\ndef int_le : ℕ × ℕ → ℕ × ℕ → Prop\n| (a, b) (c, d) := a + d ≤ b + c\n\ninstance : has_le int' :=\nbegin\n  constructor,\n  apply quotient.lift₂ int_le,\n  rintros ⟨a₁₁, a₁₂⟩ ⟨a₂₁, a₂₂⟩ ⟨b₁₁, b₁₂⟩ ⟨b₂₁, b₂₂⟩ h₁ h₂,\n  change _ = _ at h₁,\n  change _ = _ at h₂,\n  unfold int_le,\n  ext,\n  split; intro h; linarith\nend\n\n-- Problem 6.1. Show that (m + n)_ℤ = m_ℤ + n_ℤ and m ≤ n ↔ m_ℤ ≤ n_ℤ, for any\n-- m, n ∈ ℕ.\nlemma problem_6_1_a (m n : ℕ) : int'_of_nat (m + n) = int'_of_nat m + int'_of_nat n :=\nbegin\n  unfold int'_of_nat,\n  apply quotient.sound,\n  refl\nend\n\nlemma problem_6_1_b (m n : ℕ) : m ≤ n ↔ int'_of_nat m ≤ int'_of_nat n :=\nbegin\n  unfold int'_of_nat,\n  change _ ↔ int_le _ _,\n  unfold int_le,\n  rw [add_zero, zero_add]\nend\n\n-- Problem 6.2. Show that ∽ is an equivalence relation.\n--\n-- Note: ∽ is the equivalence relation that is used to define ℚ, definition on\n-- page 75.\nexample : sorry := sorry", "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/06_arithmetization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7833657547655226}}
{"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\nPorted by: Joël Riou\n\n! This file was ported from Lean 3 source module algebra.divisibility.units\n! leanprover-community/mathlib commit e574b1a4e891376b0ef974b926da39e05da12a06\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.Divisibility.Basic\nimport Mathlib.Algebra.Group.Units\n\n/-!\n# Lemmas about divisibility and units\n-/\n\nvariable {α : Type _}\n\nnamespace Units\n\nsection Monoid\n\nvariable [Monoid α] {a b : α} {u : αˣ}\n\n/-- Elements of the unit group of a monoid represented as elements of the monoid\n    divide any element of the monoid. -/\ntheorem coe_dvd : ↑u ∣ a :=\n  ⟨↑u⁻¹ * a, by simp⟩\n#align units.coe_dvd Units.coe_dvd\n\n/-- In a monoid, an element `a` divides an element `b` iff `a` divides all\n    associates of `b`. -/\ntheorem dvd_mul_right : a ∣ b * u ↔ a ∣ b :=\n  Iff.intro (fun ⟨c, Eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← Eq, Units.mul_inv_cancel_right]⟩)\n    fun ⟨c, Eq⟩ ↦ Eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _\n#align units.dvd_mul_right Units.dvd_mul_right\n\n/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/\ntheorem mul_right_dvd : a * u ∣ b ↔ a ∣ b :=\n  Iff.intro (fun ⟨c, Eq⟩ => ⟨↑u * c, Eq.trans (mul_assoc _ _ _)⟩) fun h =>\n    dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h\n#align units.mul_right_dvd Units.mul_right_dvd\n\nend Monoid\n\nsection CommMonoid\n\nvariable [CommMonoid α] {a b : α} {u : αˣ}\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\ntheorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by\n  rw [mul_comm]\n  apply dvd_mul_right\n#align units.dvd_mul_left 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`.-/\ntheorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by\n  rw [mul_comm]\n  apply mul_right_dvd\n#align units.mul_left_dvd Units.mul_left_dvd\n\nend CommMonoid\n\nend Units\n\nnamespace IsUnit\n\nsection Monoid\n\nvariable [Monoid α] {a b u : α} (hu : IsUnit u)\n\n/-- Units of a monoid divide any element of the monoid. -/\n@[simp]\ntheorem dvd : u ∣ a := by\n  rcases hu with ⟨u, rfl⟩\n  apply Units.coe_dvd\n#align is_unit.dvd IsUnit.dvd\n\n@[simp]\ntheorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := by\n  rcases hu with ⟨u, rfl⟩\n  apply Units.dvd_mul_right\n#align is_unit.dvd_mul_right IsUnit.dvd_mul_right\n\n/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/\n@[simp]\ntheorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := by\n  rcases hu with ⟨u, rfl⟩\n  apply Units.mul_right_dvd\n#align is_unit.mul_right_dvd IsUnit.mul_right_dvd\n\nend Monoid\n\nsection CommMonoid\n\nvariable [CommMonoid α] (a b u : α) (hu : IsUnit u)\n\n/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left\n    associates of `b`. -/\n@[simp]\ntheorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by\n  rcases hu with ⟨u, rfl⟩\n  apply Units.dvd_mul_left\n#align is_unit.dvd_mul_left IsUnit.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]\ntheorem mul_left_dvd : u * a ∣ b ↔ a ∣ b := by\n  rcases hu with ⟨u, rfl⟩\n  apply Units.mul_left_dvd\n#align is_unit.mul_left_dvd IsUnit.mul_left_dvd\n\nend CommMonoid\n\nend IsUnit\n\nsection CommMonoid\n\nvariable [CommMonoid α]\n\ntheorem isUnit_iff_dvd_one {x : α} : IsUnit x ↔ x ∣ 1 :=\n  ⟨IsUnit.dvd, fun ⟨y, h⟩ => ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩\n#align is_unit_iff_dvd_one isUnit_iff_dvd_one\n\ntheorem isUnit_iff_forall_dvd {x : α} : IsUnit x ↔ ∀ y, x ∣ y :=\n  isUnit_iff_dvd_one.trans ⟨fun h _ => h.trans (one_dvd _), fun h => h _⟩\n#align is_unit_iff_forall_dvd isUnit_iff_forall_dvd\n\ntheorem isUnit_of_dvd_unit {x y : α} (xy : x ∣ y) (hu : IsUnit y) : IsUnit x :=\n  isUnit_iff_dvd_one.2 <| xy.trans <| isUnit_iff_dvd_one.1 hu\n#align is_unit_of_dvd_unit isUnit_of_dvd_unit\n\ntheorem isUnit_of_dvd_one {a : α} (h : a ∣ 1) : IsUnit (a : α) :=\n  isUnit_iff_dvd_one.mpr h\n#align is_unit_of_dvd_one isUnit_of_dvd_one\n\ntheorem not_isUnit_of_not_isUnit_dvd {a b : α} (ha : ¬IsUnit a) (hb : a ∣ b) : ¬IsUnit b :=\n  mt (isUnit_of_dvd_unit hb) ha\n#align not_is_unit_of_not_is_unit_dvd not_isUnit_of_not_isUnit_dvd\n\nend CommMonoid\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/Divisibility/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679976, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7832964434231013}}
{"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\nimport algebra.ring.basic\nimport algebra.algebra.basic\nimport algebra.group_power.basic\nimport algebra.field_power\nimport algebra.opposites\n\n/-!  # Squares, even and odd elements\n\nThis file proves some general facts about squares, even and odd elements of semirings.\n\nIn the implementation, we define `is_square` and we let `even` be the notion transported by\n`to_additive`.  The definition are therefore as follows:\n```lean\nis_square a ↔ ∃ r, a = r * r\neven a ↔ ∃ r, a = r + r\n```\n\nOdd elements are not unified with a multiplicative notion.\n\n## Future work\n\n* TODO: Try to generalize further the typeclass assumptions on `is_square/even`.\n  For instance, in some cases, there are `semiring` assumptions that I (DT) am not convinced are\n  necessary.\n* TODO: Consider moving the definition and lemmas about `odd` to a separate file.\n* TODO: The \"old\" definition of `even a` asked for the existence of an element `c` such that\n  `a = 2 * c`.  For this reason, several fixes introduce an extra `two_mul` or `← two_mul`.\n  It might be the case that by making a careful choice of `simp` lemma, this can be avoided.\n -/\n\nopen mul_opposite\nvariables {F α β R : Type*}\n\nsection has_mul\nvariables [has_mul α]\n\n/--  An element `a` of a type `α` with multiplication satisfies `square a` if `a = r * r`,\nfor some `r : α`. -/\n@[to_additive\n\"An element `a` of a type `α` with addition satisfies `even a` if `a = r + r`,\nfor some `r : α`.\"]\ndef is_square (a : α) : Prop := ∃ r, a = r * r\n\n@[simp, to_additive] lemma is_square_mul_self (m : α) : is_square (m * m) := ⟨m, rfl⟩\n\n@[to_additive] lemma is_square_op_iff (a : α) : is_square (op a) ↔ is_square a :=\n⟨λ ⟨c, hc⟩, ⟨unop c, by rw [← unop_mul, ← hc, unop_op]⟩, λ ⟨c, hc⟩, by simp [hc]⟩\n\n/-- Create a decidability instance for `is_square` on `fintype`s. -/\ninstance is_square_decidable [fintype α] [decidable_eq α] : decidable_pred (is_square : α → Prop) :=\nλ a, fintype.decidable_exists_fintype\n\nend has_mul\n\n@[simp, to_additive]\nlemma is_square_one [mul_one_class α] : is_square (1 : α) := ⟨1, (mul_one _).symm⟩\n\n@[to_additive]\nlemma is_square.map [mul_one_class α] [mul_one_class β] [monoid_hom_class F α β] {m : α} (f : F) :\n  is_square m → is_square (f m) :=\nby { rintro ⟨m, rfl⟩, exact ⟨f m, by simp⟩ }\n\nsection monoid\nvariables [monoid α]\n\n@[to_additive even_iff_exists_two_nsmul]\nlemma is_square_iff_exists_sq (m : α) : is_square m ↔ ∃ c, m = c ^ 2 :=\nby simp [is_square, pow_two]\n\nalias is_square_iff_exists_sq ↔ is_square.exists_sq is_square_of_exists_sq\n\nattribute [to_additive even.exists_two_nsmul \"Alias of the forwards direction of\n`even_iff_exists_two_nsmul`.\"] is_square.exists_sq\n\nattribute [to_additive even_of_exists_two_nsmul \"Alias of the backwards direction of\n`even_iff_exists_two_nsmul`.\"] is_square_of_exists_sq\n\n@[simp, to_additive even_two_nsmul]\nlemma is_square_sq (a : α) : is_square (a ^ 2) := ⟨a, pow_two _⟩\n\nvariables [has_distrib_neg α] {n : ℕ}\n\nlemma even.neg_pow : even n → ∀ a : α, (-a) ^ n = a ^ n :=\nby { rintro ⟨c, rfl⟩ a, simp_rw [←two_mul, pow_mul, neg_sq] }\n\nlemma even.neg_one_pow (h : even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow]\n\nend monoid\n\n/-- `0` is always a square (in a monoid with zero). -/\nlemma is_square_zero (M : Type*) [monoid_with_zero M] : is_square (0 : M) :=\nby { use 0, simp only [mul_zero] }\n\n@[to_additive] lemma is_square.mul [comm_semigroup α] {a b : α} :\n  is_square a → is_square b → is_square (a * b) :=\nby { rintro ⟨a, rfl⟩ ⟨b, rfl⟩, exact ⟨a * b, mul_mul_mul_comm _ _ _ _⟩ }\n\nsection division_monoid\nvariables [division_monoid α] {a : α}\n\n@[simp, to_additive] lemma is_square_inv : is_square a⁻¹ ↔ is_square a :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { rw [← is_square_op_iff, ← inv_inv a],\n    exact h.map (mul_equiv.inv' α) },\n  { exact ((is_square_op_iff a).mpr h).map (mul_equiv.inv' α).symm }\nend\n\nalias is_square_inv ↔ _ is_square.inv\n\nattribute [to_additive] is_square.inv\n\nvariables [has_distrib_neg α] {n : ℤ}\n\nlemma even.neg_zpow : even n → ∀ a : α, (-a) ^ n = a ^ n :=\nby { rintro ⟨c, rfl⟩ a, exact zpow_bit0_neg _ _ }\n\nlemma even.neg_one_zpow (h : even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow]\n\nend division_monoid\n\nlemma even_abs [subtraction_monoid α] [linear_order α] {a : α} : even (|a|) ↔ even a :=\nby cases abs_choice a; simp only [h, even_neg]\n\n@[to_additive]\nlemma is_square.div [division_comm_monoid α] {a b : α} (ha : is_square a) (hb : is_square b) :\n  is_square (a / b) :=\nby { rw div_eq_mul_inv, exact ha.mul hb.inv }\n\n-- `odd.tsub` requires `canonically_linear_ordered_semiring`, which we don't have\nlemma even.tsub [canonically_linear_ordered_add_monoid α] [has_sub α] [has_ordered_sub α]\n  [contravariant_class α α (+) (≤)] {m n : α} (hm : even m) (hn : even n) : even (m - n) :=\nbegin\n  obtain ⟨a, rfl⟩ := hm,\n  obtain ⟨b, rfl⟩ := hn,\n  refine ⟨a - b, _⟩,\n  obtain h | h := le_total a b,\n  { rw [tsub_eq_zero_of_le h, tsub_eq_zero_of_le (add_le_add h h), add_zero] },\n  { exact (tsub_add_tsub_comm h h).symm }\nend\n\nlemma even_iff_exists_bit0 [has_add α] {a : α} : even a ↔ ∃ b, a = bit0 b := iff.rfl\n\nalias even_iff_exists_bit0 ↔ even.exists_bit0 _\n\nsection semiring\nvariables [semiring α] [semiring β] {m n : α}\n\nlemma even_iff_exists_two_mul (m : α) : even m ↔ ∃ c, m = 2 * c :=\nby simp [even_iff_exists_two_nsmul]\n\nlemma even_iff_two_dvd {a : α} : even a ↔ 2 ∣ a := by simp [even, has_dvd.dvd, two_mul]\n\n@[simp] lemma range_two_mul (α : Type*) [semiring α] :\n  set.range (λ x : α, 2 * x) = {a | even a} :=\nby { ext x, simp [eq_comm, two_mul, even] }\n\n@[simp] lemma even_bit0 (a : α) : even (bit0 a) :=\n⟨a, rfl⟩\n\n@[simp] lemma even_two : even (2 : α) := ⟨1, rfl⟩\n\n@[simp] lemma even.mul_left (hm : even m) (n) : even (n * m) :=\nhm.map (add_monoid_hom.mul_left n)\n\n@[simp] lemma even.mul_right (hm : even m) (n) : even (m * n) :=\nhm.map (add_monoid_hom.mul_right n)\n\nlemma even_two_mul (m : α) : even (2 * m) := ⟨m, two_mul _⟩\n\nlemma even.pow_of_ne_zero (hm : even m) : ∀ {a : ℕ}, a ≠ 0 → even (m ^ a)\n| 0       a0 := (a0 rfl).elim\n| (a + 1) _  := by { rw pow_succ, exact hm.mul_right _ }\n\nsection with_odd\n\n/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/\ndef odd (a : α) : Prop := ∃ k, a = 2*k + 1\n\nlemma odd_iff_exists_bit1 {a : α} : odd a ↔ ∃ b, a = bit1 b :=\nexists_congr $ λ b, by { rw two_mul, refl }\n\nalias odd_iff_exists_bit1 ↔ odd.exists_bit1 _\n\n@[simp] lemma odd_bit1 (a : α) : odd (bit1 a) := odd_iff_exists_bit1.2 ⟨a, rfl⟩\n\n@[simp] lemma range_two_mul_add_one (α : Type*) [semiring α] :\n  set.range (λ x : α, 2 * x + 1) = {a | odd a} :=\nby { ext x, simp [odd, eq_comm] }\n\nlemma even.add_odd : even m → odd n → odd (m + n) :=\nby { rintro ⟨m, rfl⟩ ⟨n, rfl⟩, exact ⟨m + n, by rw [mul_add, ← two_mul, add_assoc]⟩ }\n\nlemma odd.add_even (hm : odd m) (hn : even n) : odd (m + n) :=\nby { rw add_comm, exact hn.add_odd hm }\n\nlemma odd.add_odd : odd m → odd n → even (m + n) :=\nbegin\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩,\n  refine ⟨n + m + 1, _⟩,\n  rw [← two_mul, ←add_assoc, add_comm _ (2 * n), ←add_assoc, ←mul_add, add_assoc, mul_add _ (n + m),\n    mul_one],\n  refl\nend\n\n@[simp] lemma odd_one : odd (1 : α) :=\n⟨0, (zero_add _).symm.trans (congr_arg (+ (1 : α)) (mul_zero _).symm)⟩\n\n@[simp] lemma odd_two_mul_add_one (m : α) : odd (2 * m + 1) := ⟨m, rfl⟩\n\nlemma odd.map [ring_hom_class F α β] (f : F) : odd m → odd (f m) :=\nby { rintro ⟨m, rfl⟩, exact ⟨f m, by simp [two_mul]⟩ }\n\n@[simp] lemma odd.mul : odd m → odd n → odd (m * n) :=\nbegin\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩,\n  refine ⟨2 * m * n + n + m, _⟩,\n  rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc,\n    ← nat.cast_two, ← nat.cast_comm],\nend\n\nlemma odd.pow (hm : odd m) : ∀ {a : ℕ}, odd (m ^ a)\n| 0       := by { rw pow_zero, exact odd_one }\n| (a + 1) := by { rw pow_succ, exact hm.mul odd.pow }\n\nend with_odd\nend semiring\n\nsection monoid\nvariables [monoid α] [has_distrib_neg α] {a : α} {n : ℕ}\n\nlemma odd.neg_pow : odd n → ∀ a : α, (-a) ^ n = - a ^ n :=\nby { rintro ⟨c, rfl⟩ a, simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] }\nlemma odd.neg_one_pow (h : odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow]\n\nend monoid\n\nsection ring\nvariables [ring α] {a b : α} {n : ℕ}\n\n@[simp] lemma even_neg_two : even (- 2 : α) := by simp only [even_neg, even_two]\n\nlemma odd.neg (hp : odd a) : odd (-a) :=\nbegin\n  obtain ⟨k, hk⟩ := hp,\n  use -(k + 1),\n  rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add,\n    neg_add_cancel_right, ←neg_add, hk],\nend\n\n@[simp] lemma odd_neg : odd (-a) ↔ odd a := ⟨λ h, neg_neg a ▸ h.neg, odd.neg⟩\n\n@[simp] lemma odd_neg_one : odd (- 1 : α) := by simp\n\nlemma odd.sub_even (ha : odd a) (hb : even b) : odd (a - b) :=\nby { rw sub_eq_add_neg, exact ha.add_even hb.neg }\n\nlemma even.sub_odd (ha : even a) (hb : odd b) : odd (a - b) :=\nby { rw sub_eq_add_neg, exact ha.add_odd hb.neg }\n\nlemma odd.sub_odd (ha : odd a) (hb : odd b) : even (a - b) :=\nby { rw sub_eq_add_neg, exact ha.add_odd hb.neg }\n\nlemma odd_abs [linear_order α] : odd (abs a) ↔ odd a :=\nby cases abs_choice a with h h; simp only [h, odd_neg]\n\nend ring\n\nsection powers\nvariables [linear_ordered_ring R] {a : R} {n : ℕ}\n\nlemma even.pow_nonneg (hn : even n) (a : R) : 0 ≤ a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_nonneg a k\n\nlemma even.pow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_pos ha k\n\nlemma odd.pow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_nonpos_iff.mpr ha\n\nlemma odd.pow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_neg_iff.mpr ha\n\nlemma odd.pow_nonneg_iff (hn : odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=\n⟨λ h, le_of_not_lt (λ ha, h.not_lt $ hn.pow_neg ha), λ ha, pow_nonneg ha n⟩\n\nlemma odd.pow_nonpos_iff (hn : odd n) : a ^ n ≤ 0 ↔ a ≤ 0 :=\n⟨λ h, le_of_not_lt (λ ha, h.not_lt $ pow_pos ha _), hn.pow_nonpos⟩\n\nlemma odd.pow_pos_iff (hn : odd n) : 0 < a ^ n ↔ 0 < a :=\n⟨λ h, lt_of_not_le (λ ha, h.not_le $ hn.pow_nonpos ha), λ ha, pow_pos ha n⟩\n\nlemma odd.pow_neg_iff (hn : odd n) : a ^ n < 0 ↔ a < 0 :=\n⟨λ h, lt_of_not_le (λ ha, h.not_le $ pow_nonneg ha _), hn.pow_neg⟩\n\nlemma even.pow_pos_iff (hn : even n) (h₀ : 0 < n) : 0 < a ^ n ↔ a ≠ 0 :=\n⟨λ h ha, by { rw [ha, zero_pow h₀] at h, exact lt_irrefl 0 h }, hn.pow_pos⟩\n\nlemma even.pow_abs {p : ℕ} (hp : even p) (a : R) : |a| ^ p = a ^ p :=\nbegin\n  rw [←abs_pow, abs_eq_self],\n  exact hp.pow_nonneg _\nend\n\n@[simp] lemma pow_bit0_abs (a : R) (p : ℕ) : |a| ^ bit0 p = a ^ bit0 p := (even_bit0 _).pow_abs _\n\nlemma odd.strict_mono_pow (hn : odd n) : strict_mono (λ a : R, a ^ n) :=\nby cases hn with k hk; simpa only [hk, two_mul] using strict_mono_pow_bit1 _\n\nend powers\n\n/-- The cardinality of `fin (bit0 k)` is even, `fact` version.\nThis `fact` is needed as an instance by `matrix.special_linear_group.has_neg`. -/\nlemma fintype.card_fin_even {k : ℕ} : fact (even (fintype.card (fin (bit0 k)))) :=\n⟨by { rw [fintype.card_fin], exact even_bit0 k }⟩\n\nsection field_power\nvariable {K : Type*}\n\nsection division_ring\nvariables [division_ring K] {n : ℤ}\n\nlemma odd.neg_zpow (h : odd n) (a : K) : (-a) ^ n = - a ^ n :=\nby { obtain ⟨k, rfl⟩ := h.exists_bit1, exact zpow_bit1_neg _ _ }\n\nlemma odd.neg_one_zpow (h : odd n) : (-1 : K) ^ n = -1 := by rw [h.neg_zpow, one_zpow]\n\nend division_ring\n\nvariables [linear_ordered_field K] {n : ℤ} {a : K}\n\nprotected lemma even.zpow_nonneg (hn : even n) (a : K) : 0 ≤ a ^ n :=\nbegin\n  cases le_or_lt 0 a with h h,\n  { exact zpow_nonneg h _ },\n  { exact (hn.neg_zpow a).subst (zpow_nonneg (neg_nonneg_of_nonpos h.le) _) }\nend\n\ntheorem even.zpow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit0_pos ha k\n\nprotected lemma odd.zpow_nonneg (hn : odd n) (ha : 0 ≤ a) : 0 ≤ a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_nonneg_iff.mpr ha\n\ntheorem odd.zpow_pos (hn : odd n) (ha : 0 < a) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_pos_iff.mpr ha\n\ntheorem odd.zpow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_nonpos_iff.mpr ha\n\ntheorem odd.zpow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_neg_iff.mpr ha\n\nlemma even.zpow_abs {p : ℤ} (hp : even p) (a : K) : |a| ^ p = a ^ p :=\nbegin\n  cases abs_choice a with h h;\n  simp only [h, hp.neg_zpow _],\nend\n\n@[simp] lemma zpow_bit0_abs (a : K) (p : ℤ) : |a| ^ bit0 p = a ^ bit0 p :=\n(even_bit0 _).zpow_abs _\n\nlemma even.abs_zpow {p : ℤ} (hp : even p) (a : K) : |a ^ p| = a ^ p :=\nbegin\n  rw [abs_eq_self],\n  exact hp.zpow_nonneg _\nend\n\n@[simp] lemma abs_zpow_bit0 (a : K) (p : ℤ) :\n  |a ^ bit0 p| = a ^ bit0 p :=\n(even_bit0 _).abs_zpow _\n\nend field_power\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.783019024964529}}
{"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.order.monoid_lemmas\nimport algebra.group_with_zero.basic\nimport logic.embedding\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 `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 `ℕ`.\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*} {a b : R}\n\nsection has_mul\n\nvariable [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) := function.injective ((*) c)\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) := function.injective (* c)\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 : ∀ b, commute a b)\n  (h : is_left_regular a) : is_right_regular a :=\nλ x y xy, h $ (ca x).trans $ xy.trans $ (ca y).symm\n\nlemma commute.is_regular_iff {a : R} (ca : ∀ b, commute a b) :\n  is_regular a ↔ is_left_regular a :=\n⟨λ h, h.left, λ h, ⟨h, h.right_of_commute ca⟩⟩\n\nend has_mul\n\nsection semigroup\n\nvariable [semigroup 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) ▸ 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) ▸ 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) ↔ is_left_regular b :=\n⟨λ ab, is_left_regular.of_mul ab, λ ab, is_left_regular.mul ha ab⟩\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 λ x y xy, ab (_ : x * (b * a) = y * (b * a)),\n  rw [← mul_assoc, ← mul_assoc],\n  exact congr_fun (congr_arg has_mul.mul 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) ↔ is_right_regular b :=\n⟨λ ab, is_right_regular.of_mul ab, λ ab, is_right_regular.mul ab ha⟩\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) ∧ is_regular (b * a) ↔ is_regular a ∧ is_regular b :=\nbegin\n  refine ⟨_, _⟩,\n  { rintros ⟨ab, ba⟩,\n    exact ⟨⟨is_left_regular.of_mul ba.left, is_right_regular.of_mul ab.right⟩,\n      ⟨is_left_regular.of_mul ab.left, is_right_regular.of_mul ba.right⟩⟩ },\n  { rintros ⟨ha, hb⟩,\n    exact ⟨⟨(mul_is_left_regular_iff _ ha.left).mpr hb.left,\n        (mul_is_right_regular_iff _ hb.right).mpr ha.right⟩,\n      ⟨(mul_is_left_regular_iff _ hb.left).mpr ha.left,\n        (mul_is_right_regular_iff _ ha.right).mpr hb.right⟩⟩ }\nend\n\n/--  The \"most used\" implication of `mul_and_mul_iff`, with split hypotheses, instead of `∧`. -/\n@[to_additive \"The \\\"most used\\\" implication of `add_and_add_iff`, with split hypotheses,\ninstead of `∧`.\"]\nlemma is_regular.and_of_mul_of_mul (ab : is_regular (a * b)) (ba : is_regular (b * a)) :\n  is_regular a ∧ is_regular b :=\nis_regular_mul_and_mul_iff.mp ⟨ab, ba⟩\n\nend semigroup\n\nsection mul_zero_class\n\nvariables [mul_zero_class 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⟨λ a b, h $ eq.trans (zero_mul a) (zero_mul b).symm⟩\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⟨λ a b, h $ eq.trans (mul_zero a) (mul_zero b).symm⟩\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) ↔ subsingleton R :=\nbegin\n  refine ⟨λ h, h.subsingleton, _⟩,\n  intros H a b h,\n  exact @subsingleton.elim _ H a b\nend\n\n/--  In a non-trivial `mul_zero_class`, the `0` element is not left-regular. -/\nlemma not_is_left_regular_zero_iff : ¬ is_left_regular (0 : R) ↔ 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) ↔ subsingleton R :=\nbegin\n  refine ⟨λ h, h.subsingleton, _⟩,\n  intros H a b h,\n  exact @subsingleton.elim _ H a b\nend\n\n/--  In a non-trivial `mul_zero_class`, the `0` element is not right-regular. -/\nlemma not_is_right_regular_zero_iff : ¬ is_right_regular (0 : R) ↔ 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) ↔ subsingleton R :=\n⟨λ h, h.left.subsingleton,\n λ h, ⟨is_left_regular_zero_iff_subsingleton.mpr h, is_right_regular_zero_iff_subsingleton.mpr h⟩⟩\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 ≠ 0 :=\nbegin\n  rintro rfl,\n  rcases exists_pair_ne R with ⟨x, y, xy⟩,\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 ≠ 0 :=\nbegin\n  rintro rfl,\n  rcases exists_pair_ne R with ⟨x, y, xy⟩,\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 ≠ 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] : ¬ 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] : ¬ 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] : ¬ is_regular (0 : R) :=\nλ h, is_regular.ne_zero h rfl\n\nend mul_zero_class\n\nsection comm_semigroup\n\nvariable [comm_semigroup 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) ↔ is_regular a ∧ is_regular b :=\nbegin\n  refine iff.trans _ is_regular_mul_and_mul_iff,\n  refine ⟨λ ab, ⟨ab, by rwa mul_comm⟩, λ rab, rab.1⟩\nend\n\nend comm_semigroup\n\nsection monoid\n\nvariables [monoid R]\n\n/--  In a monoid, `1` is regular. -/\n@[to_additive \"In an additive monoid, `0` is regular.\"]\nlemma is_regular_one : is_regular (1 : R) :=\n⟨λ a b ab, (one_mul a).symm.trans (eq.trans ab (one_mul b)),\n  λ a b ab, (mul_one a).symm.trans (eq.trans ab (mul_one b))⟩\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 _ a _ (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 :=\n@is_right_regular.of_mul R _ a _ (by { rw h, exact is_regular_one.right })\n\n/-- If `R` is a monoid, an element in `Rˣ` 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ˣ) : is_regular (a : R) :=\n⟨is_left_regular_of_mul_eq_one a.inv_mul, is_right_regular_of_mul_eq_one a.mul_inv⟩\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 ⟨a, rfl⟩,\n  exact units.is_regular a,\nend\n\nend monoid\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 ↪ G :=\n{ to_fun := λ 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 ↪ G :=\n{ to_fun := λ 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\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\nend left_or_right_cancel_semigroup\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⟨mul_right_injective g, mul_left_injective g⟩\n\nend cancel_monoid\n\nsection cancel_monoid_with_zero\n\nvariables  [cancel_monoid_with_zero R]\n\n/--  Non-zero elements of an integral domain are regular. -/\nlemma is_regular_of_ne_zero (a0 : a ≠ 0) : is_regular a :=\n⟨λ b c, (mul_right_inj' a0).mp, λ b c, (mul_left_inj' a0).mp⟩\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 ↔ a ≠ 0 :=\n⟨is_regular.ne_zero, is_regular_of_ne_zero⟩\n\nend cancel_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/regular/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7830127286332518}}
{"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\n\nopen function polynomial finsupp finset\nopen_locale big_operators classical polynomial\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}\n\nsection semiring\nvariables [semiring R] {p q r : R[X]}\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 ≠ 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = ⊤`. -/\ndef trailing_degree (p : R[X]) : with_top ℕ := p.support.inf some\n\nlemma trailing_degree_lt_wf : well_founded\n(λp q : R[X], 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 `ℕ`, by defining\n`nat_trailing_degree ⊤ = 0`. -/\ndef nat_trailing_degree (p : R[X]) : ℕ := (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 : R[X]) : R := coeff p (nat_trailing_degree p)\n\n/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/\ndef trailing_monic (p : R[X]) := trailing_coeff p = (1 : R)\n\nlemma trailing_monic.def : trailing_monic p ↔ 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 : R[X]} (hp : p.trailing_monic) :\n  trailing_coeff p = 1 := hp\n\n@[simp] lemma trailing_degree_zero : trailing_degree (0 : R[X]) = ⊤ := rfl\n\n@[simp] lemma trailing_coeff_zero : trailing_coeff (0 : R[X]) = 0 := rfl\n\n@[simp] lemma nat_trailing_degree_zero : nat_trailing_degree (0 : R[X]) = 0 := rfl\n\nlemma trailing_degree_eq_top : trailing_degree p = ⊤ ↔ p = 0 :=\n⟨λ h, by rw [trailing_degree, ← min_eq_inf_with_top] at h;\n  exact support_eq_empty.1 (min_eq_none.1 h),\nλ h, by simp [h]⟩\n\nlemma trailing_degree_eq_nat_trailing_degree (hp : p ≠ 0) :\n  trailing_degree p = (nat_trailing_degree p : with_top ℕ) :=\nlet ⟨n, hn⟩ :=\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 : R[X]} {n : ℕ} (hp : p ≠ 0) :\n  p.trailing_degree = n ↔ 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 : R[X]} {n : ℕ} (hn : 0 < n) :\n  p.trailing_degree = n ↔ p.nat_trailing_degree = n :=\nbegin\n  split,\n  { intro H, rwa ← 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 : R[X]} {n : ℕ}\n  (h : trailing_degree p = n) : nat_trailing_degree p = n :=\nhave hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,\noption.some_inj.1 $ show (nat_trailing_degree p : with_top ℕ) = n,\n  by rwa [← trailing_degree_eq_nat_trailing_degree hp0]\n\n@[simp] lemma nat_trailing_degree_le_trailing_degree :\n  ↑(nat_trailing_degree p) ≤ trailing_degree p :=\nbegin\n  by_cases hp : p = 0, { rw [hp, trailing_degree_zero], exact le_top },\n  rw [trailing_degree_eq_nat_trailing_degree hp],\n  exact le_rfl\nend\n\nlemma nat_trailing_degree_eq_of_trailing_degree_eq [semiring S] {q : S[X]}\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 ≠ 0) : trailing_degree p ≤ n :=\nshow @has_le.le (with_top ℕ) _ (p.support.inf some : with_top ℕ) (some n : with_top ℕ),\nfrom finset.inf_le (mem_support_iff.2 h)\n\nlemma nat_trailing_degree_le_of_ne_zero (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n :=\nbegin\n  rw [← with_top.coe_le_coe, ← 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) ≠ 0) :\n  trailing_degree q ≤ 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 : ℕ} :\n  p.nat_trailing_degree ≠ n → trailing_degree p ≠ n :=\nmt $ λ h, by rw [nat_trailing_degree, h, option.get_or_else_coe]\n\ntheorem nat_trailing_degree_le_of_trailing_degree_le {n : ℕ} {hp : p ≠ 0}\n  (H : (n : with_top ℕ) ≤ trailing_degree p) : n ≤ 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 ≠ 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 ≠ 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) ≤ n :=\nif ha : a = 0 then by simp [ha] else (nat_trailing_degree_monomial ha).le\n\nlemma le_trailing_degree_monomial : ↑n ≤ 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 ≠ 0) : trailing_degree (C a) = (0 : with_top ℕ) :=\ntrailing_degree_monomial ha\n\nlemma le_trailing_degree_C : (0 : with_top ℕ) ≤ trailing_degree (C a) :=\nle_trailing_degree_monomial\n\nlemma trailing_degree_one_le : (0 : with_top ℕ) ≤ trailing_degree (1 : R[X]) :=\nby rw [← 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 : R[X]) = 0 :=\nnat_trailing_degree_C 1\n\n@[simp] lemma nat_trailing_degree_nat_cast (n : ℕ) : nat_trailing_degree (n : R[X]) = 0 :=\nby simp only [←C_eq_nat_cast, nat_trailing_degree_C]\n\n@[simp] lemma trailing_degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 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 : ℕ) (a : R) :\n  (n : with_top ℕ) ≤ 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 ℕ) < 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 : R[X]} {n : ℕ}\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  { rw [hp, trailing_degree_zero], 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 : R[X]}\n  {hp : (0 : with_top ℕ) < 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 : ℕ) :\n  (n : with_top ℕ) ≤ trailing_degree (X^n : R[X]) :=\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 ℕ) ≤ trailing_degree (X : R[X]) :=\nle_trailing_degree_monomial\n\nlemma nat_trailing_degree_X_le : (X : R[X]).nat_trailing_degree ≤ 1 :=\nnat_trailing_degree_monomial_le\n\n@[simp] lemma trailing_coeff_eq_zero : trailing_coeff p = 0 ↔ p = 0 :=\n⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1\n  (not_not.2 h) (mem_of_min (trailing_degree_eq_nat_trailing_degree hp)),\nλ h, h.symm ▸ leading_coeff_zero⟩\n\nlemma trailing_coeff_nonzero_iff_nonzero : trailing_coeff p ≠ 0 ↔ p ≠ 0 :=\nnot_congr trailing_coeff_eq_zero\n\nlemma nat_trailing_degree_mem_support_of_nonzero : p ≠ 0 → nat_trailing_degree p ∈ p.support :=\n(mem_support_iff.mpr ∘ trailing_coeff_nonzero_iff_nonzero.mpr)\n\nlemma nat_trailing_degree_le_of_mem_supp (a : ℕ) :\n  a ∈ p.support → nat_trailing_degree p ≤ a:=\nnat_trailing_degree_le_of_ne_zero ∘ mem_support_iff.mp\n\nlemma nat_trailing_degree_eq_support_min' (h : p ≠ 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 : R[X]) :\n  p.nat_trailing_degree ≤ 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 : R[X]} (hp : p ≠ 0) (n : ℕ) :\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 (λ h, mt trailing_coeff_eq_zero.mp hp _),\n    rwa [trailing_coeff, ←coeff_mul_X_pow] },\n  { rw [nat_trailing_degree_eq_support_min' (λ h, hp (mul_X_pow_eq_zero h)), finset.le_min'_iff],\n    intros y hy,\n    have key : n ≤ y,\n    { rw [mem_support_iff, coeff_mul_X_pow'] at hy,\n      exact by_contra (λ 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) },\nend\n\nend semiring\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma trailing_degree_one : trailing_degree (1 : R[X]) = (0 : with_top ℕ) :=\ntrailing_degree_C one_ne_zero\n\n@[simp] lemma trailing_degree_X : trailing_degree (X : R[X]) = 1 :=\ntrailing_degree_monomial one_ne_zero\n\n@[simp] lemma nat_trailing_degree_X : (X : R[X]).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 : R[X]) : trailing_degree (-p) = trailing_degree p :=\nby unfold trailing_degree; rw support_neg\n\n@[simp] lemma nat_trailing_degree_neg (p : R[X]) :\n  nat_trailing_degree (-p) = nat_trailing_degree p :=\nby simp [nat_trailing_degree]\n\n@[simp] lemma nat_trailing_degree_int_cast (n : ℤ) : nat_trailing_degree (n : R[X]) = 0 :=\nby simp only [←C_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 : R[X]) : 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 : R[X]) (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 : R[X]} {ι : 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 ℕ} (h : trailing_degree p < n) : p ≠ 0 :=\nλ h₀, h.not_le (by simp [h₀])\n\nend semiring\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/trailing_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7830127241982343}}
{"text": "section pred_logic\n\nvariables X Y Z : Prop\n\n/- *** NOT *** -/\n\n\n-- ¬ \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 ¬P, is also a proposition. when is ¬P 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 are no proofs of P*. \n\nNow here's the slightly tricky way that we show that there can\nbe no proof of P. We show (P → false). What this proposition\nsays is that \"If there is a proof of P, then from it we can\nderive an impossibility, so there must be no proof of P. This\nis the rule of false introduction: prove P → false, conclude\n¬P. ¬P is true iff P → false. Indeed, in our logic we simply\n*define* ¬P to mean P → false.  \n-/\n\n/- \nRight click on not and click \"go to definition\" to see the\ndefinition of (not P) and the definition of ¬P as a notation\nfor (not P).\n-/\n\n#check not \n\n/-\nExamples\n-/\n\n\nexample : 0 = 1 → false :=\nbegin\nassume h,   -- assume 0 = 1; this can't happen, of course\ncases h,    -- there's no way to prove 0 = 1, so NOT (0=1)\nend \n\n/-\nHere's exactly the same proposition but using ¬ notation\n-/\nexample : ¬(0 = 1) :=\nbegin \nassume h,\ncases h,\n\n/-\nRemember!  0 ≠ 1 means ¬(0 = 1) means 0 = 1 → false. You \nmust remember that when you want to prove ¬P, that means \nyou need to prove P → false: that a proof of P is an \nimpossibility.  Remember this, because it tells you how\nto prove ¬P. To show it, assume the premise, 0 = 1, then\nshow that this assumption gives rise to an impossibility\n(a proof of false). \n-/\nend\n\n/- PROOF BY NEGATION \n\nWhat we've now seen is a crucial \"proof strategy\" often \ncalled \"proof by negation.\"\" To show ¬P (that P is false), \nwe prove P → false. How? assume P is true and show that from \nthis assumption you can derive a contradiction, something \nthat cannot be, such as proof of false. \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\n/-\nEnglish. Prove ¬(X ∧ ¬X), where X is any proposition.\nThis theorem states that it cannot be the case that \nboth X and ¬X are true.\n\nProof by negation: Assume that (X ∧ ¬X) is true. By\nuse of and elimination deduce X and ¬X separately. \nBut this is a contradiction, so the assumption must\nhave been false. Therefore ¬(X ∧ ¬X) is proved. QED.\n-/\n\ntheorem no_contradiction : ¬(X ∧ ¬X) :=\nbegin\nassume h,           -- where h proves (X ∧ ¬X)\ncases h with x nx,  -- applies and elimination \nexact (nx x),       -- (nx x) is a proof of false\nend\n\n\n/- PROOF BY CONTRADICTION \n\nFirst, recall that in proof by negation, we prove ¬P by \nassuming that P is true, deriving an impossibility, and\nthen concluding ¬P.\n\nProof by contradiction is just a tad more complicated. In\nthis proof strategy we prove P (rather than ¬P) by assuming\n¬P (rather than P) and showing that *this* assumption leads\nto an impossibility, a contradiction. What that proves is \nthat ¬P must be false, which is to say, ¬¬P. Finally, from\nthere, we conclude P using *negation elimination*. This rule\nis simply this (recall that we introduced X as an arbitrary \npropostion above):\n-/\n\ndef neg_elim          := ¬¬X → X\n\n/-\nAs a silly but simple example, let's prove that 0 = 0 using\nthe strategy of proof by contradiction.\n\nGoal: Prove 0 = 0.\nProof (by contradiction). Assume h: ¬(0 = 0). Recall that \nthis means h is a proof of (0 = 0) → false. But 0 = 0 is\ntrue, so there is a proof of it, let's call it pf. Now we\nsimply apply h to pf (arrow elimination) to derive a proof\nof false. By ¬ introduction, this proves ¬¬(0 = 1). Finally\nwe apply negation elimination to deduce that (0 = 1) is true. \n-/\n\n\n/-\nIn Lean, \"by_contradiction\" is the name of the negation \nelimination rule. Because it relies on a non-constructive\nassumption, it's tucked away in a module called classical. \nWe can use it by referring to classical.by_contradiction.\nThe @ sign here is a detail you can ignore for now. It\njust tells Lean to report the rule as its' written where\nit's defined.\n\n-/\n#check @classical.by_contradiction\n-- ∀ {p : Prop}, (¬p → false) → p\n-- in other words, ∀ (P : Prop), ¬(¬P) → P\n-- Proof by contradiction is application of ¬ elimination!\n\n-- Here's a formal proof\nexample : 0 = 0 :=\nbegin\napply classical.by_contradiction,\nassume h,               -- assume ¬ 0 = 0\nlet k := eq.refl 0,     -- but we can have k a proof of 0 = 0\nlet f := h k,           -- that's an impossibility (here a proof of false)\napply false.elim f,     -- ex falso quodlibet! QED.\nend\n\n\n-- We can't prove negation elimination to be valid in constructive logic!\nexample : ∀ (P : Prop), ¬¬P → P :=\nbegin\nassume P,\nassume nnp,\n-- stuck!!!\nend\n\n/-\nBut as a real wonder, it turns out that if you assume \nthat the law of the excluded middle is valid, then that\nis sufficient to make negation elimination valid again.\n-/\n\n/- \nThe axiom of the excluded middle says that any and\nevery proposition has a Boolean truth value: it is\neither true, or false, and there's nothing else it\ncould be. \n\nIn constructive logic, by contrast, if you don't \nhave either a proof of P or of ¬P, then you can't\nbuild a proof of P ∨ ¬P. By contrast, in \"classical\"\nlogic for any proposition, P, you have have a proof\nof P ∨ ¬P \"for free,\" just by applying em to P.\n-/\n\n-- In Lean, classical.em is a proof of ∀ P, P ∨ ¬P.\n#check @classical.em\n-- em : ∀ (p : Prop), p ∨ ¬p\n\n/-\nThe crucial point about the law of the excluded\nmiddle is that (because it's a universal generalization)\nyou can *apply* it to any proposition, P, to get a \"free\" \nproof of P ∨ ¬P; *and on that you can do case analysis,*\nwith just two cases: in one case P is true because you\nhave a proof of it; and in the other case you have a \nproof of ¬P. As long as you can show that your goal\nfollows \"in either case\", you've proved your goal.\n-/\n\n/-\nSo let's see exactly how accepting the law of the \nexcluded middle (em) suffices to prove the validity \nof negation elimination, ¬¬P → P. Remember that proof\nby contradiction is used to prove P by assuming ¬P\nand showing that that yeilds an impossibility, thus\nproving ¬(¬P), from which, by negation elimination\nyou can deduce P, which was the original goal.\n\nHere's the final secret. Read negation elimination\nrule backwards. What is says is that if you want\nto prove P, it will *suffice* to prove ¬¬P, for if\nyou do that, you just apply negation elimination\nto prove P.\n\nIn other words. if your goal is P, and you apply\nnegation elimination, your new goal is to prove\n¬¬P. Now recall that ¬¬P just means (¬P) → false.\nTo prove this, assume ¬P! And then show that this\nassumption leads to a situation that can't happen,\nand where therefore there is nothing else to be\nconsidered. False elimination really means that\nyou can ignore the consequences of situations\nthat can never even happen in the first place.\n-/\n\n-- If we assume em, then negation elimination is valid\nexample : \n  ∀ (P : Prop),   -- for any proposition P\n    (P ∨ ¬P) →    -- ***if we assume em is valid**\n    (¬¬P → P)     -- ***then neg elim is valid***\n  := \nbegin\nassume P,\nassume em_P,\nassume nnp,\ncases em_P with p np,\n-- case P\nexact p,\n-- \"assumption\" also works heew\n-- case ¬P\napply false.elim (nnp np)\n-- \"contradiction\" also works here\nend\n\n/-\nExercises: Prove that the following propositions are theorems\n(that they have proofs). Express your proofs in English. For\nextra credit, provide formal proofs in Lean. Hint: Working out\nthe proofs in Lean can be a big help to expressing them in \nEnglish.\n-/\n\n-- prove that these propositions are \ndef contrapostitive   := (X → Y) → (¬Y → ¬X)\ndef demorgan1         := ¬(X ∨ Y) ↔ ¬X ∧ ¬Y\ndef demorgan2         := ¬(X ∧ Y) ↔ ¬X ∨ ¬Y\n\n\n/- EXTRA MATERIAL/CREDIT\n\nIt also turns out that if you assume that negation \nelimination, (¬¬P → P) is valid, then you can prove\nthat excluded middle is, too: (∀ (P : Prop), P ∨ ¬P). \n\nIndeed, in our logic, the two axioms are equivalent.\nHere's a formal statement of that proposition, with\nan extra credit opportunity for you to prove it in\nboth directions.\n-/\n\ntheorem em_equiv_pbc : \n  ∀ (P : Prop), (P ∨ ¬P) ↔ (¬¬P → P) := \nbegin\n_         -- challenge problem, on your own\nend\n\n/-\nAssume P is a proposition then see that you can\n\"apply iff.intro _ _\") to construct a proof for\nyour overall goal. You're done, with you nidge:\nyou \"borrowed\" proofsfrom the future and now you\nhave to pay them back. You're thus left with two\nremaining sub-goals. In this way, you provide a\ncomplete proof but with some \"blanks\" that still\nneed to be filled in. Lean typechecks such proofs \nwith holes and knows the types of proofs/values\nneeded for each one. These are the subgoals that\nremain.\n\nThis is the vitally important computer science\n\"strategy\" of top-down, structured, type-guided \ndecomposition of a problem. You apply to a hard\nproblem by producing a complete solution pending\ncompletion of remaining holes; then you apply\nthe same strategy to fill each hole; until you\nfill holes with values that themselfes have no\nremaining holes! Then you're done.\n\nWhat's saddening, always a little at least, is\nwhen you've expanded a whole tree of holes and\nthen filled in many only to find that you're\nstuck. Yeah, that can make it hard to *find*\nproofs. You must back up, undo some assumptions,\nand then move forward ahead. This is called a\nback-tracking search strategy. Mathematicians\n*search* for proofs. Those who are especially\ngoodhave uncanny senses for unpromising paths\nto avoid. \n\nEven so, the complete formalization of a proof\nof the Four-Color Theorem took G.Gonthier six \nyears to complete at Microsoft Research. Along\nthe way he had to build a significant formal\ntheory of a lot of the underlying mathematics,\ne.g., in such areas as topology.\n\nMain take-away message: when a proof of Q is\nneeded, we can often apply an inference rule\nor theorem, to assumed arguments, to constrct\na proof of Q *even if we don't have values for\nthe arguments yet*. In this way, we build a\ncomplete solution \"modulo\" remaining \"proof\nobligations,\" or \"subgoals.\" This approach\nis top-down, structured (read hierarchical), \ntype-guided decomposition. It reduces a hard\nproblem to a complete solution in one step,\npending the satisfaction of zero or more \nremaining subproblems. If it's zero, QED; if\nnot, keep going, consider backtracking, etc. \n-/\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/01_Inference_Rules_and_Proofs/07_rules_for_not.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.888758786126321, "lm_q1q2_score": 0.782816136285287}}
{"text": "/-\n\n-/\n\n#check @or.elim\n\nexample : ∀ (P Q R: Prop), P ∨ Q → R :=\nbegin\n  assume P Q R,     -- forall introduction\n  assume h : P ∨ Q,\n  apply or.elim h _ _,\n  assume P,\n   -- end of example,\nend\n\nexample : ∀ (P Q R: Prop), P ∨ Q → ((P → R) → (Q → R) → R) :=\nbegin\nassume P Q R,     -- forall introduction, assume PQR, show rest\nassume (h : P ∨ Q),         -- arrow introduction\napply or.elim h,  -- or elimination (cases)\n\n-- First case: assume P\nassume (p : P),   -- arrow intro\nassume pr,        -- arrow intro\nassume qr,        -- arrow intro\nexact (pr p),     -- arrow elimination\n\n-- Second case: assuming Q is true\nassume q pr qr,   \nexact (qr q),\nend\n\n#check @or.inl\n#check @or.inr\n\n-- What does unfold do\n\ndef x := 0 = 1\n\ndef m := ∀ P, P ∨ ¬P\n\ntheorem foo : m  :=\nbegin\nunfold m,\n-- quit\nend\n\n-- What about iff\n\nexample : ∀ (P Q : Prop), P ↔ Q :=\nbegin\nassume P Q,\napply iff.intro,\nend \n\nvariables (P Q : Prop)\nvariables (pq : P → Q) (qp : Q → P)\n\n-- what I want is a proof that P ↔ Q\n\n/-\nWe prove P ↔ Q from P → Q and Q → P by iff introduction\n-/\nexample : P ↔ Q := (iff.intro pq qp)\n\nvariable piffq : P ↔ Q\n\nexample : P → Q := iff.mp piffq   -- weird name for elim_left (modus ponens)\nexample : Q → P := iff.mpr piffq   -- weird name for elim_right (modus ponens reverse)\n-- don't worry about these details\n\ntheorem my_and_elim : ∀ (P Q), P ∧ Q → P :=\nbegin\n  assume P Q,\n  assume (pq : P ∧ Q),\n  apply and.elim_left pq,\nend \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/review/22_10_16_review.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7828090327502544}}
{"text": "import tactic\nimport data.real.basic\nvariables (P Q R S : Prop)\nvariables (A B C D : Type)\nvariables (a b c d k m n x: ℕ)\nopen function set\n/-\n# Logic\n\nIn Lean a `Prop` is any true/false statement. \n\nFor example: `3 = 2`  or `x = 7 → x is prime` or \n`∀ (n:ℕ), 2 ∣ n` or `∃ (k:ℕ), even k ∧ ¬ prime k` -/\n\n--#check 3 = 2\n--#check x = 7 → prime x\n--#check ∀ (n:ℕ), 2 ∣ n\n--#check ∃ (k:ℕ), even k ∧ ¬ prime k\n\n/-\nIf we have `(P : Prop)` then `P` is a proposition, so it is\na statement that is either true or false. \n\nSo what is `(hp : P)`? It is simply a proof that P is true.\nOr equivalently `hp` is the hypothesis that P is true.\n\n# Tactics\n\nWe will use the three basic tactics from last time: `exact`, `intro`, `apply`\n\n# exact\nIf our goal is `⊢ P` and we have a term `hp : P` then \nwe can close it with `exact hp`\n\n# intro(s)\nIf our goal is `⊢ P → Q` then `intro hp` introduces a term `(hp : P)`\ninto our local context and our goal changes to `⊢ Q`.\n\n# apply\nIf our goal is `⊢ Q` and we have a term `(hpq : P → Q)` then\n`apply hpq` changes our goal to `⊢ P`\n\n(We think of this as : we know `P implies Q`, so if our goal is `Q` it\nsuffices to prove `P` and then `Q` follows.) \n\n# New tactic: refl\n\n# refl \nIf our goal can be proved by `reflexivity` then `refl` will close it.\nFor example  `P = P` or `P ↔ P` -/\n\n-- 01 `if and only if` `↔` is reflexive so refl works here\nexample : P ↔ P :=\nbegin\n  refl,\nend\n\n-- 02 Equality is also reflexive so again `refl` will work\nexample : P = P := \nbegin\n  sorry,\nend\n\n/- Unless told otherwise, Lean assumes numerals refer to natural\nnumbers i.e. ℕ = {0, 1, 2,...} also known as `nats`.\n\nIf we do operations such as ` + - / * ^ % ` with nats then the result is\nalso a nat. -/\n\n-- 03\nexample : 1 + 1 = 2 :=\nbegin\n  sorry,\nend\n\n-- 04 \nexample : 12 * 25 = 300 :=\nbegin\n  sorry,\nend\n\n-- 05\nexample : 7 - 3 = 2 ^ 2 :=\nbegin\n  sorry,\nend\n\n-- 06\nexample : 2 - 3 = 0 := -- yes 2 - 3 = 0 in Lean\nbegin\n  sorry,\nend\n\n-- 07  `a % b` is the remainder of `a` after division by `b`.\nexample : 18 % 7 = 4:=\nbegin\n  sorry,\nend\n\n-- 08  Remember everything here is a natural number\nexample (n : ℕ): (12 / 5)^4  = 4^(5 / 2) * n^ (3 - 4) :=\nbegin\n  sorry,\nend\n\n-- 09 `refl` can also see through definitions \nexample  (f : A → B) : injective f ↔ ∀ (x y : A), f x = f y → x = y :=\nbegin\n  refl,\nend\n\n-- 10 \nexample (f : A → B) : surjective f ↔ ∀ (b:B), ∃ (a:A), f a = b:=\nbegin\n  sorry,\nend\n\n/- We give the next example a name because it captures one of the fundmental \n   properties of `Prop` in Lean: \n           `Any two proofs of the same Prop are equal` -/\n-- 11 \nlemma proof_irrelevance (P : Prop) (h1 : P) (h2 : P) : h1 = h2:=\nbegin\n  sorry,\nend\n\n/- The same isn't true for most Types. \n   [Qu: what can you say about types for which this is true?] -/\n-- 12\nexample (A : Type) (a1 : A) (a2 : A) : a1 = a2:=\nbegin \n  sorry -- don't try to prove this it isn't true without further assumptions about A!\nend\n\n-- 13 Any proposition implies itself\nexample  : P → P :=\nbegin\n  intro hp, -- introduce the hypothesis `hp : P` in the local context\n            -- our goal is now `⊢ P` so we can accomplish this with\n  exact hp,\nend\n\n-- 14 If P is true and P → Q is true then Q is true\nexample (hp : P) (hpq : P → Q) : Q :=\nbegin\n  sorry,\nend\n\n\n/-  # There is no special `implies` symbol in Lean\n\nAs we have just seen we don't have a different symbol for `implies` we just reuse `→` \nthat was introduced earlier for functions. \n\nSo if `(A B : Type)` and `(P Q : Prop)` what is the difference between\n `f : A → B` and `hpq : P → Q` ?\n\n`f` is a function mapping terms of type `A` to terms of type `B`, while `hpq` is a \nfunction mapping terms of type `P` to terms of type `Q`. \n\nThe crucial difference is that `A` and `B` have type `Type` while `P` and `Q` have \ntype `Prop`\n\nInterpreting a term of type `P` as a proof of `P` then we can think of `hpq : P → Q` as \na function mapping proofs of P to proofs of Q. -/\n\n\n-- 15\nexample : P → Q → P :=\nbegin\n  sorry\nend\n\n-- 16\nexample : P → (P → Q) → (Q → R) → R :=\nbegin\n  sorry,\nend\n\n-- 17\nexample  : (P → Q → R) → (Q → R → P) → (R → Q → P) :=\nbegin\n  sorry,\nend\n\n/-\n# New tactic: rw\n\n# rw\nrw is short for rewrite, it allows us to rewrite using equations and equivalences.\n\nFor example if we have `h : a = b` and our goal is `⊢ a + c = b + c` then `rw h` will replace\n`a` by `b` in the goal so it becomes `⊢ b + c = b + c`  (which we can then close with `refl`) \n\nWe can tell `rw` to do the rewrite on a term in our local context.\nFor example if we have `h1 : a = b` and `h2 : a = c` we can use `rw h1 at h2` to convert h2\ninto `h2 : b = c`\n\nrw works from left to right, so given `h : a = b`, `rw h` will replace each `a` in the goal by `b`.\nIf we want to instead replace each `b` by `a` we can use `rw ← h` to rewrite from right to left.  -/\n\n-- 18 We can do this be rewriting \nexample (h1 : a = b) (h2 : b = c) (h3: c = d) : a = d:=\nbegin\n  rw h1,\n  sorry,\nend\n\n-- 19 We start with a rewrite in the local context\nexample (h1 : a = b) (h2 : b = c) (h3: c = d) : a = d :=\nbegin\n  rw h2 at h1, \n  sorry,\nend\n\n-- 20 We can start by rewriting from right to left using `hqr : Q ↔ R`\nexample  (hpq : P ↔ Q) (hqr : Q ↔ R) : P ↔ R:=\nbegin\n  rw ← hqr,\n  sorry,\nend\n\n-- 21\nexample  (f g : A → B) (hfg : injective f ↔ injective g) (hg : ∀ (x y: A), g x = g y → x = y)  : injective f:=\nbegin\n  sorry,\nend\n\n-- 22 -- symmetry may be useful here..\nexample (f: A → ℕ) (x y : A) (hf : f x = f y → x = y) \n(hfx: f x = n) (hfy: f y = m) (heq: m = n) : x = y:=\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/2_logic/basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7828090284864517}}
{"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-/\nprelude\nimport init.logic\n\nnotation `ℕ` := nat\n\nnamespace nat\n\ninductive less_than_or_equal (a : ℕ) : ℕ → Prop\n| refl : less_than_or_equal a\n| step : Π {b}, less_than_or_equal b → less_than_or_equal (succ b)\n\ninstance : has_le ℕ :=\n⟨nat.less_than_or_equal⟩\n\n@[reducible] protected def le (n m : ℕ) := nat.less_than_or_equal n m\n@[reducible] protected def lt (n m : ℕ) := nat.less_than_or_equal (succ n) m\n\ninstance : has_lt ℕ :=\n⟨nat.lt⟩\n\ndef pred : ℕ → ℕ\n| 0     := 0\n| (a+1) := a\n\nprotected def sub : ℕ → ℕ → ℕ\n| a 0     := a\n| a (b+1) := pred (sub a b)\n\nprotected def mul : nat → nat → nat\n| a 0     := 0\n| a (b+1) := (mul a b) + a\n\ninstance : has_sub ℕ :=\n⟨nat.sub⟩\n\ninstance : has_mul ℕ :=\n⟨nat.mul⟩\n\n-- defeq to the instance provided by comm_semiring\ninstance : has_dvd ℕ :=\nhas_dvd.mk (λ a b, ∃ c, b = a * c)\n\ninstance : decidable_eq ℕ\n| zero     zero     := is_true rfl\n| (succ x) zero     := is_false (λ h, nat.no_confusion h)\n| zero     (succ y) := is_false (λ h, nat.no_confusion h)\n| (succ x) (succ y) :=\n    match decidable_eq x y with\n    | is_true xeqy := is_true (xeqy ▸ eq.refl (succ x))\n    | is_false xney := is_false (λ h, nat.no_confusion h (λ xeqy, absurd xeqy xney))\n    end\n\ndef {u} repeat {α : Type u} (f : ℕ → α → α) : ℕ → α → α\n| 0         a := a\n| (succ n)  a := f n (repeat n a)\n\ninstance : inhabited ℕ :=\n⟨nat.zero⟩\n\n@[simp] lemma nat_zero_eq_zero : nat.zero = 0 :=\nrfl\n\n/- properties of inequality -/\n/-* For any natural number $a$, $a \\leq a$. *-/\n@[refl] protected lemma le_refl (a : ℕ) : a ≤ a :=\nless_than_or_equal.refl\n\n/-* For any natural number $n$, it is lower or equal to its succession. *-/\nlemma le_succ (n : ℕ) : n ≤ succ n :=\nless_than_or_equal.step (nat.le_refl n)\n\n/-* Let $n, m$ be two natural numbers, then the succession of $n$ is lower or equal to the succession of $m$. *-/\nlemma succ_le_succ {n m : ℕ} : n ≤ m → succ n ≤ succ m :=\nλ h, less_than_or_equal.rec (nat.le_refl (succ n)) (λ a b, less_than_or_equal.step) h\n\n/-* If $n$ is a natural number, then $0 \\leq n$. *-/\nprotected lemma zero_le : ∀ (n : ℕ), 0 ≤ n\n| 0     := nat.le_refl 0\n| (n+1) := less_than_or_equal.step (zero_le n)\n\n/-* If $n$ is a natural number, then 0 is lower than the succession of $n$. *-/\n\n\nlemma succ_pos (n : ℕ) : 0 < succ n := zero_lt_succ n\n\nlemma not_succ_le_zero : ∀ (n : ℕ), succ n ≤ 0 → false\n.\n\nprotected lemma not_lt_zero (a : ℕ) : ¬ a < 0 := not_succ_le_zero a\n\nlemma pred_le_pred {n m : ℕ} : n ≤ m → pred n ≤ pred m :=\nλ h, less_than_or_equal.rec_on h\n  (nat.le_refl (pred n))\n  (λ n, nat.rec (λ a b, b) (λ a b c, less_than_or_equal.step) n)\n\n/-* Let $n, m$ be natural numbers, then that the succession of $n$ is lower or equal to the succession of $m$ implies $n \\leq m$. *-/\nlemma le_of_succ_le_succ {n m : ℕ} : succ n ≤ succ m → n ≤ m :=\npred_le_pred\n\ninstance decidable_le : ∀ a b : ℕ, decidable (a ≤ b)\n| 0     b     := is_true b.zero_le\n| (a+1) 0     := is_false (not_succ_le_zero a)\n| (a+1) (b+1) :=\n  match decidable_le a b with\n  | is_true h  := is_true (succ_le_succ h)\n  | is_false h := is_false (λ a, h (le_of_succ_le_succ a))\n  end\n\ninstance decidable_lt : ∀ a b : ℕ, decidable (a < b) :=\nλ a b, nat.decidable_le (succ a) b\n\n/-* Let $a, b$ be two natural numbers, and $a \\leq b$, then $a = b$ or $a < b$. *-/\nprotected lemma eq_or_lt_of_le {a b : ℕ} (h : a ≤ b) : a = b ∨ a < b :=\nless_than_or_equal.cases_on h (or.inl rfl) (λ n h, or.inr (succ_le_succ h))\n\n/-* Let $a, b$ be two natural numbers, then $a \\leq b$ implies $a$ is lower than the succesion of $b$. *-/\nlemma lt_succ_of_le {a b : ℕ} : a ≤ b → a < succ b :=\nsucc_le_succ\n\n/-* Let $a, b$ be two natural numbers, then the subtraction of the successions of $a$ and $b$ equals to $a - b$. *-/\n@[simp] lemma succ_sub_succ_eq_sub (a b : ℕ) : succ a - succ b = a - b :=\nnat.rec_on b\n  (show succ a - succ zero = a - zero, from (eq.refl (succ a - succ zero)))\n  (λ b, congr_arg pred)\n\nlemma not_succ_le_self : ∀ n : ℕ, ¬succ n ≤ n :=\nλ n, nat.rec (not_succ_le_zero 0) (λ a b c, b (le_of_succ_le_succ c)) n\n\nprotected lemma lt_irrefl (n : ℕ) : ¬n < n :=\nnot_succ_le_self n\n\n/-* Let $n, m, k$ be natural numbers, and $n \\leq m$, then $m \\leq k$ implies $n \\leq k$. *-/\nprotected lemma le_trans {n m k : ℕ} (h1 : n ≤ m) : m ≤ k → n ≤ k :=\nless_than_or_equal.rec h1 (λ p h2, less_than_or_equal.step)\n\nlemma pred_le : ∀ (n : ℕ), pred n ≤ n\n| 0        := less_than_or_equal.refl\n| (succ a) := less_than_or_equal.step less_than_or_equal.refl\n\nlemma pred_lt : ∀ {n : ℕ}, n ≠ 0 → pred n < n\n| 0        h := absurd rfl h\n| (succ a) h := lt_succ_of_le less_than_or_equal.refl\n\n/-* Let $a, b$ be natural numbers, then $a - b \\leq b$. *-/\nprotected lemma sub_le (a b : ℕ) : a - b ≤ a :=\nnat.rec_on b (nat.le_refl (a - 0)) (λ b₁, nat.le_trans (pred_le (a - b₁)))\n\n/-* Let $a, b$ be natural numbers, then $0 < a$ and $0 < b$ imply $a - b < a$. *-/\nprotected lemma sub_lt : ∀ {a b : ℕ}, 0 < a → 0 < b → 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) ▸\n    show a - b < succ a, from\n    lt_succ_of_le (a.sub_le b)\n\n/-* Let $n, m, k$ be naturla numbers, then $n < m$ and $m \\leq k$ imply $n < k$. *-/\nprotected lemma lt_of_lt_of_le {n m k : ℕ} : n < m → m ≤ k → n < k :=\nnat.le_trans\n\n/- Basic nat.add lemmas -/\nprotected lemma zero_add : ∀ n : ℕ, 0 + n = n\n| 0     := rfl\n| (n+1) := congr_arg succ (zero_add n)\n\n/-* Let $n, m$ be natural numbers, then the succession of $n$ plus $m$ equals to the succession of $(n + m)$. *-/\nlemma succ_add : ∀ n m : ℕ, (succ n) + m = succ (n + m)\n| n 0     := rfl\n| n (m+1) := congr_arg succ (succ_add n m)\n\n/-* Let $n, m$ be natural numbers, then $n$ plus the succession of $m$ equals to the succession of $(n + m)$. *-/\nlemma add_succ (n m : ℕ) : n + succ m = succ (n + m) :=\nrfl\n\nprotected lemma add_zero (n : ℕ) : n + 0 = n :=\nrfl\n\n/-* Let $n$ be a natural number, then $n + 1$ equals to its succession. *-/\nlemma add_one (n : ℕ) : n + 1 = succ n :=\nrfl\n\n/-* Let $n$ be a natural number, then the succesion of $n$ equals to $n + 1$. *-/\nlemma succ_eq_add_one (n : ℕ) : succ n = n + 1 :=\nrfl\n\n/- Basic lemmas for comparing numerals -/\n\nprotected lemma bit0_succ_eq (n : ℕ) : bit0 (succ n) = succ (succ (bit0 n)) :=\nshow succ (succ n + n) = succ (succ (n + n)), from\ncongr_arg succ (succ_add n n)\n\nprotected lemma zero_lt_bit0 : ∀ {n : nat}, n ≠ 0 → 0 < bit0 n\n| 0        h := absurd rfl h\n| (succ n) h :=\n  calc 0 < succ (succ (bit0 n)) : zero_lt_succ _\n     ... = bit0 (succ n)        : (nat.bit0_succ_eq n).symm\n\nprotected lemma zero_lt_bit1 (n : nat) : 0 < bit1 n :=\nzero_lt_succ _\n\nprotected lemma bit0_ne_zero : ∀ {n : ℕ}, n ≠ 0 → bit0 n ≠ 0\n| 0     h := absurd rfl h\n| (n+1) h :=\n  suffices (n+1) + (n+1) ≠ 0, from this,\n  suffices succ ((n+1) + n) ≠ 0, from this,\n  λ h, nat.no_confusion h\n\nprotected lemma bit1_ne_zero (n : ℕ) : bit1 n ≠ 0 :=\nshow succ (n + n) ≠ 0, from\nλ h, nat.no_confusion h\n\nend nat\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/nat/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.7827254321619784}}
{"text": "import SciLean\nimport SciLean.Tactic.ConvIf\nopen SciLean\n\n\n/-!\n\n==============\nApproximations\n==============\n\nScientific computing is full of approximations. SciLean attempts to provide\ntools to manage these approximations and easity swap between them.\n\nAs a starting example we will look into computing the square root function. \nLooking at wikipedia there are two basic methods: Babylonian_  and Bakhshali_.\n\n.. _Babylonian: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method\n.. _Bakhshali: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Bakhshali_method\n\nThe Babylonian method computes :math:`\\sqrt{y}` from an initial guess :math:`x_0`\nwith an iterative process\n\n.. math:: x_{n+1} = \\frac{x_n + \\frac{y}{x_n}}{2}\n\nIn code\n\n-/\n\ndef sqrtBabylonian (n : Nat) (x₀ : ℝ) (y : ℝ) : ℝ := \nmatch n with\n| 0   => x₀ \n| n+1 => sqrtBabylonian n ((x₀ + y/x₀)/2) y\n\n/-!\n\nThe Bakhshali method computes :math:`\\sqrt{y}` from an initial guess :math:`x_0`\nwith an iterative process\n\n.. raw:: html\n\n  \\begin{align}\n    a_n &= \\frac{y - x_n^2}{2 x_n} \\\\\n    b_n &= x_n + a_n \\\\\n    x_{n+1} &= b_n - \\frac{a_n^2}{2b_n}\n  \\end{align}\n\n\nIn code\n\n-/\n\ndef sqrtBakhshali (n : Nat) (x₀ : ℝ) (y : ℝ) : ℝ :=\n  match n with\n  | 0 => x₀\n  | n+1 => \n    let aₙ := (y - x₀*x₀)/(2*x₀)\n    let bₙ := x₀ + aₙ \n    let x₁ := bₙ - aₙ*aₙ/(2*bₙ)\n    sqrtBakhshali n x₁ y\n\n/-! \nLet's test it out to compute :math:`\\sqrt{2} = 1.41421356237\\dots`\n-/\n#eval sqrtBabylonian 2 1 2 -- 1.416667\n#eval sqrtBakhshali 2 1 2  -- 1.414214\n\n/-!\n\nAlready at two steps Bakhshali method computes :math:`\\sqrt{2}` correctly to\nall the digits that are displayed.\n\n\nSqrt Specification\n------------------\n\nBecause Lean is a proof assistant it allows us to define the square root\nfunction precisely. The downside is that such function will be noncomputable. \nThis might sound completely pointless, how it is useful to define a function \nthat we can not run? The advantage is that we can disentangle the program\nspecification from its implementation. \n\nThe square root function is defined in mathlib_, we do not provide the \nfull definition here just \n\n.. _mathlib: https://leanprover-community.github.io/mathlib_docs/data/real/sqrt.html#real.sqrt\n\n -/\nnoncomputable\ndef real.sqrt (x : ℝ) : ℝ := sorry\n  --Possible noncomputable definition\n  -- if x > 0 then\n  --   inf { y // x < y * y }     -- infimum of a set is noncomputable\n  -- else\n  --   0\n\n/-!\n\n(TODO: Note somewhere that we assume that we have reals with computable + - * / <\n  This either opens up a can of worms about consistency or floating point arithmetics.\n  And I do not want to get into that right now ...)\n\nThe `real.sqrt` function satisfies two main properties. The first one, \ncalled `real.mul_self_sqrt`_, for non-negative :math:`x` we have \n:math:`\\sqrt{x} \\sqrt{x} = x`. The second one, called `real.sqrt_eq_zero_of_nonpos`_, \nfor negative :math:`x` the :math:`\\sqrt{x}` is defined to be zero. In math class\nsquare root of negative number is usually not defined, however in type theory\nthis does not work so well. This is similar to division by zero, in \nLean we have `1/0 = 0`, you can read about this more on Kevin Buzzard's page_.\n\n.. _page: https://xenaproject.wordpress.com/2020/07/05/division-by-zero-in-type-theory-a-faq/\n\n.. _`real.sqrt_eq_zero_of_nonpos`: https://leanprover-community.github.io/mathlib_docs/data/real/sqrt.html#real.sqrt_eq_zero_of_nonpos\n\n.. _`real.mul_self_sqrt`:  https://leanprover-community.github.io/mathlib_docs/data/real/sqrt.html#real.mul_self_sqrt\n\n -/\n\ntheorem real.mul_self_sqrt {x : ℝ} (h : 0 ≤ x) \n  : real.sqrt x * real.sqrt x = x := sorry\n\n@[simp]\ntheorem real.sqrt_eq_zero_of_nonpos {x : ℝ} (h : ¬(0 ≤ x)) \n  : real.sqrt x = 0 := sorry\n\n/-!\n\nIn particular, we can proof that the Babylonian and Bakhshali method \nconverge to the square root. Again we omit the proofs here again, but \nit is well in the capability of Lean and mathlib to do so.\n\n -/\n\ntheorem sqrtBabylonian.limit {x : ℝ} (y₀ : ℝ) (hy : y₀ ≥ 0) (hx : 0 ≤ x)\n  : real.sqrt x = limit λ n => sqrtBabylonian n y₀ x := sorry\n\ntheorem sqrtBakhshali.limit {x : ℝ} (y₀ : ℝ) (hy : y₀ ≥ 0) (hx : 0 ≤ x)\n  : real.sqrt y = limit λ n => sqrtBakhshali n x₀ y := sorry\n\n/-!\n\nTo build an approximation, we state `approx sqrtApprox := real.sqrt` followed\nby instructions how to construct such approximation. The type of `sqrtApprox` is \n`Approx real.sqrt`, which is an object holding couple of useful informations\nabout the approximation:\n\n  1. Parameters to controll the accuracy of the approximation.\n  2. Options to switch between different approximations.\n  3. Under what conditions this approximation is actually valid.\n\nHere is the Lean code to generate the approximation\n -/\n\napprox sqrtApprox := real.sqrt\nby \n  conv => \n    trace_state\n    enter [1] -- Step into `Approx ...`\n    enter [x] -- introduce the argument `x`\n\n    if h : 0 ≤ x then \n      -- For positive `x` we apply the Babylonian method\n      rw [sqrtBabylonian.limit (x/2) (sorry) h]\n    else\n      -- For negative `x` we know the result is zero\n      rw [real.sqrt_eq_zero_of_nonpos h]\n  \n  -- We pick 4 steps as default\n  approx_limit 4; intro n\n\n/-!\n\n(TODO: Add parameter to switch between Babylonian and Bakhshali.)\n\nTo get the value of an approximation we need to call `.val!` \n\n -/\n\n#eval sqrtApprox.val 2\n", "meta": {"author": "lecopivo", "repo": "SciLean", "sha": "e4fe5962c862f9854a6c88a4082eb01bc1147086", "save_path": "github-repos/lean/lecopivo-SciLean", "path": "github-repos/lean/lecopivo-SciLean/SciLean-e4fe5962c862f9854a6c88a4082eb01bc1147086/doc/literate/approximations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.782725431242276}}
{"text": "-- Teorema_de_Cantor.lean\n-- Teorema de Cantor.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 6-mayo-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar el teorema de Cantor:\n--    ∀ f : α → set α, ¬ surjective f\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nopen function\n\nvariables {α : Type}\n\n-- 1ª demostración\n-- ===============\n\nexample : ∀ f : α → set α, ¬ surjective f :=\nbegin\n  intros f hf,\n  let S := {i | i ∉ f i},\n  cases hf S with j hj,\n  by_cases jS : j ∈ S,\n  { apply jS,\n    rwa hj, },\n  { apply jS,\n    rwa ← hj at jS, },\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : ∀ f : α → set α, ¬ surjective f :=\ncantor_surjective\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/Teorema_de_Cantor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7827074457302121}}
{"text": "/- LoVe Exercise 2: Tactical Proofs -/\n\nimport .love02_tactical_proofs_demo\n\nnamespace LoVe\n\n\n/- Question 1: Connectives and Quantifiers -/\n\n/- 1.1. Carry out the following proofs using basic tactics. -/\n\nlemma I (a : Prop) :\n  a → a :=\nbegin\n  intro ha,\n  exact ha\nend\n\nlemma K (a b : Prop) :\n  a → b → b :=\nbegin\n  intros ha hb,\n  exact hb\nend\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nbegin\n  intros hg hb ha,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha\nend\n\n-- please give a different answer than for `proj_1st`\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha'\nend\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nbegin\n  intros hg ha hf hb,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\n/- 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nbegin\n  intros hab hnb ha,\n  apply hnb,\n  apply hab,\n  apply ha\nend\n\n/- 1.3. Prove the distributivity of `∀` over `∧` using basic tactics. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    apply and.intro,\n    { intro x,\n      apply and.elim_left,\n      apply h },\n    { intro x,\n      apply and.elim_right,\n      apply h } },\n  { intros h x,\n    apply and.intro,\n    { apply and.elim_left h },\n    { apply and.elim_right h } }\nend\n\n\n/- Question 2: Natural Numbers -/\n\n/- 2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nbegin\n  induction n,\n  { refl },\n  { simp [add, mul, n_ih] }\nend\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nbegin\n  induction n,\n  { refl },\n  { simp [add, add_succ, add_assoc, mul, n_ih] }\nend\n\n/- 2.2. Prove commutativity and associativity of multiplication using the\n`induction` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nbegin\n  induction m,\n  { simp [mul, mul_zero] },\n  { simp [mul, mul_succ, m_ih], ac_refl }\nend\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nbegin\n  induction n,\n  { refl },\n  { simp [mul, mul_add, n_ih] }\nend\n\n/- 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nbegin\n  rw mul_comm _ n,\n  rw mul_add\nend\n\n\n/- Question 3 (**optional**): Intuitionistic Logic -/\n\n/- Intuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle := ∀a : Prop, a ∨ ¬ a\ndef peirce := ∀a b : Prop, ((a → b) → a) → a\ndef double_negation := ∀a : Prop, ¬¬ a → a\n\n/- For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, because this would defeat the purpose of the exercise. -/\n\n/- 3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nbegin\n  simp [excluded_middle, peirce],\n  dunfold not,\n  intro hem,\n  intros a b haba,\n  apply or.elim (hem a),\n  { intro,\n    assumption },\n  { intro hna,\n    apply haba,\n    intro ha,\n    apply false.elim,\n    apply hna,\n    assumption }\nend\n\n/- 3.2 (**optional**). Prove the following implication using tactics.\n\nHint: Try instantiating `b` with `false` in Peirce's law. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nbegin\n  simp [peirce, double_negation],\n  intros hpeirce a hnna,\n  apply hpeirce a false,\n  intro hna,\n  apply false.elim,\n  apply hnna,\n  exact hna\nend\n\n/- We leave the missing implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544446, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.7826992902474937}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la teoría Definicion_de_funciones_acotadas\n-- 2. Declarar f y g como variables de funciones de ℝ en ℝ.\n-- 3. Declarar a y b como variables sobre ℝ.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_funciones_acotadas -- 1\n\nvariables {f g : ℝ → ℝ}                  -- 2\nvariables {a b : ℝ}                      -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que si a es una cota superior de f y b lo es\n-- de g, entonces a + b lo es de f + g.\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (hfa : fn_ub f a)\n  (hgb : fn_ub g b)\n  : fn_ub (f + g) (a + b) :=\nbegin\n  assume x : ℝ,\n  have h1 : f x ≤ a := hfa x,\n  have h2 : g x ≤ b := hgb x,\n  calc (f + g) x\n       = f x + g x : rfl\n   ... ≤ a + b     : add_le_add h1 h2\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (hfa : fn_ub f a)\n  (hgb : fn_ub g b)\n  : fn_ub (f + g) (a + b) :=\nbegin\n  intro x,\n  change f x + g x ≤ a + b,\n  apply add_le_add,\n  apply hfa,\n  apply hgb\nend\n\n-- Su desarrollo es\n--\n-- f g : ℝ → ℝ,\n-- a b : ℝ,\n-- hfa : fn_ub f a,\n-- hgb : fn_ub g b\n-- ⊢ fn_ub (λ (x : ℝ), f x + g x) (a + b)\n--    >> intro x,\n-- x : ℝ\n-- ⊢ (λ (x : ℝ), f x + g x) x ≤ a + b\n--    >> change f x + g x ≤ a + b,\n-- ⊢ f x + g x ≤ a + b\n--    >> apply add_le_add,\n-- | ⊢ f x ≤ a\n-- |    >> apply hfa,\n-- | ⊢ g x ≤ b\n-- |    >> apply hgb\n-- no goals\n\n-- 3ª demostración\n-- ===============\n\ntheorem fn_ub_add\n  (hfa : fn_ub f a)\n  (hgb : fn_ub g b)\n  : fn_ub (f + g) (a + b) :=\nλ x, add_le_add (hfa x) (hgb x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que la suma de dos funciones acotadas\n-- superiormente también lo está.\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (ubf : fn_has_ub f)\n  (ubg : fn_has_ub g)\n  : fn_has_ub (f + g) :=\nbegin\n  cases ubf with a ha,\n  have h1 : ∀ x, f x ≤ a := ha,\n  cases ubg with b hb,\n  have h2 : ∀ x, g x ≤ b := hb,\n  have h3 : ∀ x, (f + g) x ≤ a + b :=\n    λ x, add_le_add (h1 x) (h2 x),\n  have h4 : ∃ z, ∀ x, (f + g) x ≤ z,\n    by exact Exists.intro (a + b) h3,\n  show fn_has_ub (f + g),\n    by exact h4,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (ubf : fn_has_ub f)\n  (ubg : fn_has_ub g)\n  : fn_has_ub (f + g) :=\nbegin\n  cases ubf with a ubfa,\n  cases ubg with b ubfb,\n  use a + b,\n  apply fn_ub_add ubfa ubfb,\nend\n\n-- Su desarrollo es\n--\n-- f g : ℝ → ℝ,\n-- ubf : fn_has_ub f,\n-- ubg : fn_has_ub g\n-- ⊢ fn_has_ub (λ (x : ℝ), f x + g x)\n--    >> cases ubf with a ubfa,\n-- f g : ℝ → ℝ,\n-- ubg : fn_has_ub g,\n-- a : ℝ,\n-- ubfa : fn_ub f a\n-- ⊢ fn_has_ub (λ (x : ℝ), f x + g x)\n--    >> cases ubg with b ubfb,\n-- f g : ℝ → ℝ,\n-- a : ℝ,\n-- ubfa : fn_ub f a,\n-- b : ℝ,\n-- ubfb : fn_ub g b\n-- ⊢ fn_has_ub (λ (x : ℝ), f x + g x)\n--    >> use a + b,\n-- ⊢ fn_ub (λ (x : ℝ), f x + g x) (a + b)\n--    >> apply fn_ub_add ubfa ubfb\n-- no goals\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (ubf : fn_has_ub f)\n  (ubg : fn_has_ub g)\n  : fn_has_ub (f + g) :=\nbegin\n  rcases ubf with ⟨a, ubfa⟩,\n  rcases ubg with ⟨b, ubfb⟩,\n  exact ⟨a + b, fn_ub_add ubfa ubfb⟩\nend\n\n-- 4ª demostración\n-- ===============\n\nexample :\n  fn_has_ub f → fn_has_ub g → fn_has_ub (f + g) :=\nbegin\n  rintros ⟨a, ubfa⟩ ⟨b, ubfb⟩,\n  exact ⟨a + b, fn_ub_add ubfa ubfb⟩,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample :\n  fn_has_ub f → fn_has_ub g → fn_has_ub (f + g) :=\nλ ⟨a, ubfa⟩ ⟨b, ubfb⟩, ⟨a + b, fn_ub_add ubfa ubfb⟩\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.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.89029422102812, "lm_q1q2_score": 0.7826992893683395}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hp,\n  intro hpn,\n  apply hpn,\n  assumption,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro hnp,\n  by_contra hboom, --como usar o (RAA)\n  apply hnp,\n  assumption,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  -- separando a conjunção\n  intro hnp,\n  by_contra hboom,\n  apply hnp,\n  assumption,\n  -- organizando cada uma das demonstrações separadamente\n  intro hp,\n  intro hpn,\n  apply hpn,\n  assumption,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro p_q,\n  cases p_q,\n  -- Caso P\n  right,\n  assumption,\n  -- Caso Q\n  left,\n  assumption,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro peq,\n  cases peq,\n  split,\n  -- Demonstre Q\n  assumption,\n  -- Demonstre P\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro Hp_q,\n  intro Hp,\n  cases Hp_q,\n  -- Caso ¬P\n  have Hboom : false := Hp_q Hp,\n  contradiction,\n\n  -- Caso Q\n  assumption,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro Hp_q,\n  intro Np,\n  cases Hp_q,  \n  -- Caso P\n  have Hp : false := Np Hp_q,\n  contradiction,\n  \n  -- Caso Q\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro Hpq,\n  intro Nq,\n  intro Hp,\n  have Hq : Q := Hpq Hp,\n  contradiction, \nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro HNqp,\n  intro Hp,\n  by_contra Hboom,\n  have HNp : ¬P := HNqp Hboom,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  -- Demonstrar Right\n  intro Hpq,\n  intro Nq,\n  intro Hp,\n  have Hq : Q := Hpq Hp,\n  contradiction,\n\n  -- Demonstrar Left\n  intro HNqp,\n  intro Hp,\n  by_contra Hboom,\n  have HNp : ¬P := HNqp Hboom,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro NT,\n  have p_or_p : P ∨ ¬P,  \n  right,\n  intro Hp,\n  apply NT,\n  left,\n  assumption,\n  apply NT,\n  assumption,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro Hpqp,\n  intro HNp,\n  apply HNp,\n  have Hpq: P → Q,\n  intro Hp,\n  contradiction,\n  apply Hpqp,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro Hp_or_q,\n  intro Hnot_p_and_q,\n  cases Hnot_p_and_q,\n  cases Hp_or_q,\n  -- Caso P\n  have Hp : false := Hnot_p_and_q_left Hp_or_q,\n  assumption,\n  -- Caso Q\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro Hp_and_q,\n  intro HNp_or_q,\n  cases Hp_and_q,\n  cases HNp_or_q,\n  -- Caso ¬P\n  contradiction,\n  -- Caso ¬Q\n  have Hp : false := HNp_or_q Hp_and_q_right,\n  assumption,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro HNp_or_q,\n  split,\n  -- Demonstre ¬P\n  intro Hp,\n  have p_or_q : P ∨ Q,\n  left,\n  assumption,\n  have Np_or_q : false := HNp_or_q p_or_q,\n  assumption,\n\n  -- Demonstre ¬Q\n  intro Hq,\n  have p_or_q : P ∨ Q,\n  right,\n  assumption,\n  apply HNp_or_q,\n  assumption,\n\n  -- Duas formas diferente de fechar essa demonstração, também poderia ser usado o contradiction\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro Hnp_and_nq,\n  intro Hp_or_q,\n  cases Hnp_and_nq,\n  cases Hp_or_q,\n  -- Caso P\n  apply Hnp_and_nq_left,\n  assumption,\n  -- Caso Q\n  have Hboom : false := Hnp_and_nq_right Hp_or_q,\n  assumption,\n\n  -- Também com duas formas de fechar além do contradiction\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro HNp_and_q,\n  by_cases Hp : P,\n  -- Caso P\n  left, -- Demonstre ¬Q\n  intro Hq,\n  apply HNp_and_q,\n  split,\n  -- Demonstre P\n  assumption,\n  -- Demonstre Q\n  assumption,\n  \n  -- Caso ¬P\n  right,\n  assumption,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro Hnq_or_np,\n  intro Hp_and_q,\n  cases Hp_and_q,\n  cases Hnq_or_np,\n  -- Caso ¬Q\n  apply Hnq_or_np,\n  assumption,\n\n  -- Caso ¬P\n  have hboom : false := Hnq_or_np Hp_and_q_left,\n  assumption,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  intro HNp_and_q,\n  by_cases Hp : P,\n  -- Caso P\n  left, -- Demonstre ¬Q\n  intro Hq,\n  apply HNp_and_q,\n  split,\n  -- Demonstre P\n  assumption,\n  -- Demonstre Q\n  assumption,\n  \n  -- Caso ¬P\n  right,\n  assumption,\n\n  intro Hnq_or_np,\n  intro Hp_and_q,\n  cases Hp_and_q,\n  cases Hnq_or_np,\n  -- Caso ¬Q\n  apply Hnq_or_np,\n  assumption,\n\n  -- Caso ¬P\n  have hboom : false := Hnq_or_np Hp_and_q_left,\n  assumption,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n\n  intro HNp_or_q,\n  split,\n  -- Demonstre ¬P\n  intro Hp,\n  have p_or_q : P ∨ Q,\n  left,\n  assumption,\n  have Np_or_q : false := HNp_or_q p_or_q,\n  assumption,\n\n  -- Demonstre ¬Q\n  intro Hq,\n  have p_or_q : P ∨ Q,\n  right,\n  assumption,\n  apply HNp_or_q,\n  assumption,\n\n  intro Hnp_and_nq,\n  intro Hp_or_q,\n  cases Hnp_and_nq,\n  cases Hp_or_q,\n  -- Caso P\n  apply Hnp_and_nq_left,\n  assumption,\n  -- Caso Q\n  have Hboom : false := Hnp_and_nq_right Hp_or_q,\n  assumption,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro Hp_and__q_or_r,\n  cases Hp_and__q_or_r,\n  cases Hp_and__q_or_r_right,\n  -- Caso Q\n  left,\n  split,\n  assumption,\n  assumption,\n  -- Caso R\n  right,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro Hand_or_and,\n  split,\n  -- Demonstre P\n  cases Hand_or_and,\n\n  -- Caso P ∧ Q\n  cases Hand_or_and,\n  assumption,\n\n  -- Caso P ∧ R\n  cases Hand_or_and,\n  assumption,\n  \n  -- Demonstre Q ∨ R\n  cases Hand_or_and,\n  -- Caso P ∧ Q\n  cases Hand_or_and,\n  left,\n  assumption,\n\n  -- Caso P ∧ R\n  cases Hand_or_and,\n  right,\n  assumption,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro HP_or_and,\n  split,\n  -- Demonstre P ∨ Q\n  cases HP_or_and,\n  -- Caso P\n  left,\n  assumption,\n  -- Caso Q ∧ R\n  cases HP_or_and,\n  right,\n  assumption,\n\n  -- Demonstre P ∨ R\n  cases HP_or_and,\n  -- Caso P\n  left,\n  assumption,\n  -- Caso Q ∧ R\n  cases HP_or_and,\n  right,\n  assumption,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro Hor_and_or,\n  cases Hor_and_or,\n  cases Hor_and_or_left,\n  -- Caso P\n  left,\n  assumption,\n  -- Caso Q\n  cases Hor_and_or_right,\n    -- Caso P\n    left,\n    assumption,\n  right,\n  split,\n  -- Demonstre Q\n  assumption,\n  -- Demonstre R\n  assumption,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro Hp_and_q_imp_r,\n  intro Hp,\n  intro Hq,\n  apply Hp_and_q_imp_r,\n  split,\n  -- Demonstre P\n  assumption,\n  -- Demonstre Q\n  assumption,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro Hp_imp_q_imp_r,\n  intro Hp_and_q,\n  cases Hp_and_q,\n  apply Hp_imp_q_imp_r,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro Hp,\n  assumption,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro Hp,\n  left,\n  assumption,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro Hq,\n  right,\n  assumption,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro Hp_and_q,\n  cases Hp_and_q, \n  assumption,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro Hp_and_q,\n  cases Hp_and_q, \n  assumption,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro p_and_p,\n  cases p_and_p,\n  assumption,\n\n  intro Hp,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro Hp_or_p,\n  cases Hp_or_p,\n  assumption,\n  assumption,\n\n  intro Hp,\n  right,\n  assumption,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro Hn_exist_P,\n  intro x,\n  intro Hnp,\n  apply Hn_exist_P,\n  existsi x,\n  assumption,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro H_all_np,\n  intro H_exist_P,\n  cases H_exist_P with u hu,\n  apply H_all_np u,\n  assumption,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro Hn_all_p,\n  by_contradiction H_exist_nP,\n  exfalso,\n  apply Hn_all_p,\n  intro u,\n  by_contradiction HnP,\n  apply H_exist_nP,\n  existsi u,\n  assumption,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro H_exist_nP,\n  cases H_exist_nP with u HnP,\n  intro H_all_P,\n  have Hu := H_all_P u,\n  apply HnP,\n  assumption,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  intro Hn_all_p,\n  by_contradiction H_exist_nP,\n  exfalso,\n  apply Hn_all_p,\n  intro u,\n  by_contradiction HnP,\n  apply H_exist_nP,\n  existsi u,\n  assumption,\n\n  intro H_exist_nP,\n  cases H_exist_nP with u HnP,\n  intro H_all_P,\n  have Hu := H_all_P u,\n  apply HnP,\n  assumption,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  intro Hn_exist_P,\n  intro x,\n  intro Hnp,\n  apply Hn_exist_P,\n  existsi x,\n  assumption,\n\n  intro H_all_np,\n  intro H_exist_P,\n  cases H_exist_P with u hu,\n  apply H_all_np u,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro H_exist_P,\n  cases H_exist_P with u HP,\n  intro H_all_nP,\n  have Hu := H_all_nP u,\n  apply Hu,\n  assumption,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro H_all_P,\n  intro H_exist_nP,\n  cases H_exist_nP with u HP,\n  have Hu := H_all_P u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro Hn_exist_nP,\n  intro u,\n  by_contradiction Hboom,\n  apply Hn_exist_nP,\n  existsi u,\n  assumption,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro Hn_forall_nP,\n  by_contradiction Hboom,\n  apply Hn_forall_nP,\n  intro u,\n  intro Hu,\n  apply Hboom,\n  existsi u,\n  assumption,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  intro H_all_P,\n  intro H_exist_nP,\n  cases H_exist_nP with u HP,\n  have Hu := H_all_P u,\n  contradiction,\n\n   intro Hn_exist_nP,\n  intro u,\n  by_contradiction Hboom,\n  apply Hn_exist_nP,\n  existsi u,\n  assumption,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  intro H_exist_P,\n  cases H_exist_P with u HP,\n  intro H_all_nP,\n  have Hu := H_all_nP u,\n  apply Hu,\n  assumption,\n\n  intro Hn_forall_nP,\n  by_contradiction Hboom,\n  apply Hn_forall_nP,\n  intro u,\n  intro Hu,\n  apply Hboom,\n  existsi u,\n  assumption,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro H_exist_p_and_q,\n  \nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  sorry,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "CarlosTertuliano", "repo": "fmclean", "sha": "897c035aadb5095252e4000e6ccb71d832d94527", "save_path": "github-repos/lean/CarlosTertuliano-fmclean", "path": "github-repos/lean/CarlosTertuliano-fmclean/fmclean-897c035aadb5095252e4000e6ccb71d832d94527/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.7826912813270545}}
{"text": "/-\nGive a natural deduction proof of ¬𝐴∨𝐵 from 𝐴→𝐵.\nYou may use the law of the excluded middle.\n-/\n\nopen classical\n\nvariables (A B: Prop)\n\nexample (h: A → B) : ¬ A ∨ B :=\n  or.elim(em(A))(\n    λ hA: A,\n    have hB: B, from h(hA),\n    show ¬ A ∨ B, from or.inr(hB)\n  )(\n    λ hnA: ¬ A,\n    show ¬ A ∨ B, from or.inl(hnA)\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/ex5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7826680425895323}}
{"text": "#exit -- remove this to runq\nnamespace xena\n\ninductive xnat\n| zero : xnat\n| succ : xnat → xnat\n\nopen xnat \n\ndefinition add : xnat → xnat → xnat\n| n zero := n\n| n (succ p) := succ (add n p)\n\nnotation a + b := add a b \ndefinition one := succ zero\ndefinition two := succ one \n\nexample : one + one = two :=\nbegin\nrefl\nend\n\ntheorem add_assoc (a b c : xnat) : (a + b) + c = a + (b + c) :=\nbegin\nadmit\nend\n\ntheorem add_zero (n : xnat) : n + zero = n := by unfold add\n\ntheorem zero_add (n : xnat) : zero + n = n := \nbegin\nadmit\nend\n\n#check zero_add\n#check add_zero\n\ntheorem zero_add_eq_add_zero (n : xnat) : zero + n = n + zero :=\nbegin\nrewrite [zero_add],\nadmit,\nend\n\ntheorem one_add_eq_succ (n : xnat) : one + n = succ n :=\nbegin\nadmit\nend\n\ntheorem add_one_eq_succ (n : xnat) : n + one = succ n :=\nbegin\nunfold one,\nunfold add,\nend\n\n\ntheorem add_comm (a b : xnat) : a + b = b + a :=\nbegin \nadmit\nend\n\ndefinition mul : xnat → xnat → xnat\n| n zero := zero\n| n (succ p) := (mul n p) + n\n\nnotation a * b := mul a b\n\nexample : one * one = one := \nbegin\nrefl\nend\n\ntheorem mul_zero (a : xnat) : a * zero = zero := rfl\n\ntheorem zero_mul (a : xnat) : zero * a = zero := sorry\n\ntheorem mul_one (a : xnat) : a * (succ zero) = a := sorry\n\ntheorem one_mul (a : xnat) : (succ zero) * a = a := sorry\n\ntheorem right_distrib (a b c : xnat) : a * (b + c) = a* b + a * c := sorry\n\ntheorem left_distrib (a b c : xnat) : (a + b) * c = a * c + b * c := sorry\n\ntheorem mul_assoc (a b c : xnat) : (a * b) * c = a * (b * c) := sorry\n\ntheorem mul_comm (a b : xnat) : a * b = b * a := sorry\n\ndefinition lt : xnat → xnat → Prop -- less than\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 \nnotation b > a := lt a b\n\ntheorem add_succ_equals_succ (a b : xnat) : a + (succ b) = succ (a + b) := sorry\n\ntheorem inequality_A1 (a b t : xnat) : a < b → a + t < b + t := sorry\n\ntheorem inequality_A2 (a b c : xnat) : a < b → b < c → a < c := sorry\n\ntheorem inequality_A3 (a b : xnat) : (a < b ∨ a = b ∨ b < a) \n                                   ∧ (a < b → ¬ (a = b)) \n                                   ∧ (a < b → ¬ (b < a)) \n                                   ∧ (a = b → ¬ (b < a)) := sorry\n\ntheorem inequality_A4 (a b : xnat) : a > zero → b > zero  → (a*b) > zero := sorry\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/naturals_addition_etc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.782668038801965}}
{"text": "import data.real.basic\nimport tactic.ring\n\nstructure complex : Type := (re : ℝ) (im : ℝ)\n\nnotation `ℂ` := complex\n\ndef z : ℂ := ⟨5,6⟩ \n\nnamespace complex\n\ntheorem ext (z w : ℂ) : z.re = w.re ∧ z.im = w.im → z = w := begin\n    cases z,\n    cases w, \n    intros,\n    simp * at *\nend\n\ninstance : has_coe ℝ ℂ := ⟨λ x, {re := x, im := 0}⟩ \n\ndef I : ℂ := ⟨0, 1⟩\n\ndef add : ℂ → ℂ → ℂ := λ z w, {re := z.re + w.re, im := z.im + w.im}\n\ninstance : has_add ℂ := ⟨complex.add⟩\n\n@[simp] theorem add_re : ∀ z w : ℂ, (z + w).re = z.re + w.re := λ z w, rfl\n@[simp] theorem add_im : ∀ z w : ℂ, (z + w).im = z.im + w.im := λ z w, rfl\n\ntheorem add_comm : ∀ z w : ℂ, z + w = w + z := begin\n    intros,\n    apply ext, \n    split; simp\nend\n\ntheorem add_assoc : ∀ a b c : ℂ, a + (b + c) = (a + b) + c := begin\n    intros, \n    apply ext, \n    split; simp\nend\n\ndef neg : ℂ → ℂ := λ z, ⟨-z.re,z.im⟩\n\ninstance : has_neg ℂ := ⟨complex.neg⟩\n\n@[simp] theorem neg_re (z : ℂ) : (-z).re = -z.re := _\n@[simp] theorem neg_im (z : ℂ) : (-z).im = -z.im := rfl\n\n\n\n\nend complex", "meta": {"author": "AlexandruBosinta", "repo": "MyLeanPlayground", "sha": "5dc50a590d784bfc27e7fb37b6361a6dcc1b2790", "save_path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground", "path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground/MyLeanPlayground-5dc50a590d784bfc27e7fb37b6361a6dcc1b2790/complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509314, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7826493106401144}}
{"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.multiset.basic\nimport order.well_founded\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 `α`, 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 `α`. 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 `α`, and the\nvalid \"moves\" of the game are modelled by the relation `cut_expand r` on `multiset α`:\n`cut_expand r s' s` is true iff `s'` is obtained by removing one head `a ∈ s` and\nadding back an arbitrary multiset `t` of heads such that all `a' ∈ t` satisfy `r a' a`.\n\nTo prove this theorem, we follow the proof by Peter LeFanu Lumsdaine at\nhttps://mathoverflow.net/a/229084/3332, and along the way we introduce the notion of `fibration`\nof relations, and a new operation `game_add` that combines to relations to form a relation on the\nproduct type, which is used to define addition of games in combinatorial game theory.\n\nTODO: formalize the relations corresponding to more powerful (e.g. Kirby–Paris and Buchholz)\nhydras, and prove their well-foundedness.\n-/\n\nnamespace relation\n\nvariables {α β : Type*}\n\nsection two_rels\nvariables (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β)\n\n/-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all\n  `a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image\n  of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/\ndef fibration := ∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b\n\nvariables {rα rβ}\n\n/-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is\n  accessible under `rα`, then `f a` is accessible under `rβ`. -/\nlemma _root_.acc.of_fibration (fib : fibration rα rβ f) {a} (ha : acc rα a) : acc rβ (f a) :=\nbegin\n  induction ha with a ha ih,\n  refine acc.intro (f a) (λ b hr, _),\n  obtain ⟨a', hr', rfl⟩ := fib hr,\n  exact ih a' hr',\nend\n\nlemma _root_.acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → b ∈ set.range f)\n  (a : α) (ha : acc (inv_image rβ f) a) : acc rβ (f a) :=\nha.of_fibration f (λ a b h, let ⟨a', he⟩ := dc h in ⟨a', he.substr h, he⟩)\n\nvariables (rα rβ)\n\n/-- The \"addition of games\" relation in combinatorial game theory, on the product type: if\n  `rα a' a` means that `a ⟶ a'` is a valid move in game `α`, and `rβ b' b` means that `b ⟶ b'`\n  is a valid move in game `β`, then `game_add rα rβ` specifies the valid moves in the juxtaposition\n  of `α` and `β`: the player is free to choose one of the games and make a move in it,\n  while leaving the other game unchanged. -/\ninductive game_add : α × β → α × β → Prop\n| fst {a' a b} : rα a' a → game_add (a',b) (a,b)\n| snd {a b' b} : rβ b' b → game_add (a,b') (a,b)\n\n/-- `game_add` is a `subrelation` of `prod.lex`. -/\nlemma game_add_le_lex : game_add rα rβ ≤ prod.lex rα rβ :=\nλ _ _ h, h.rec (λ _ _ b, prod.lex.left b b) (λ a _ _, prod.lex.right a)\n\n/-- `prod.rprod` is a subrelation of the transitive closure of `game_add`. -/\nlemma rprod_le_trans_gen_game_add : prod.rprod rα rβ ≤ trans_gen (game_add rα rβ) :=\nλ _ _ h, h.rec begin\n  intros _ _ _ _ hα hβ,\n  exact trans_gen.tail (trans_gen.single $ game_add.fst hα) (game_add.snd hβ),\nend\n\nvariables {rα rβ}\n\n/-- If `a` is accessible under `rα` and `b` is accessible under `rβ`, then `(a, b)` is\n  accessible under `relation.game_add rα rβ`. Notice that `prod.lex_accessible` requires the\n  stronger condition `∀ b, acc rβ b`. -/\nlemma _root_.acc.game_add {a b} (ha : acc rα a) (hb : acc rβ b) : acc (game_add rα rβ) (a, b) :=\nbegin\n  induction ha with a ha iha generalizing b,\n  induction hb with b hb ihb,\n  refine acc.intro _ (λ h, _),\n  rintro (⟨_,_,_,ra⟩|⟨_,_,_,rb⟩),\n  exacts [iha _ ra (acc.intro b hb), ihb _ rb],\nend\n\n/-- The sum of two well-founded games is well-founded. -/\nlemma _root_.well_founded.game_add (hα : well_founded rα) (hβ : well_founded rβ) :\n  well_founded (game_add rα rβ) := ⟨λ ⟨a,b⟩, (hα.apply a).game_add (hβ.apply b)⟩\n\nend two_rels\n\nsection hydra\nopen game_add multiset\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 ∈ s` and adding back an arbitrary\n  multiset `t` of heads such that all `a' ∈ 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 α`, 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 ∈ s` because `s' + {a} = s + t` already\n  guarantees `a ∈ s + t`, and if `r` is irreflexive then `a ∉ 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 : α → α → Prop) (s' s : multiset α) : Prop :=\n∃ (t : multiset α) (a : α), (∀ a' ∈ t, r a' a) ∧ s' + {a} = s + t\n\nvariable {r : α → α → Prop}\n\ntheorem cut_expand_singleton {s x} (h : ∀ x' ∈ s, r x' x) : cut_expand r s {x} :=\n⟨s, x, h, add_comm s _⟩\n\ntheorem cut_expand_singleton_singleton {x' x} (h : r x' x) : cut_expand r {x'} {x} :=\ncut_expand_singleton (λ a h, by rwa mem_singleton.1 h)\n\ntheorem cut_expand_add_left {t u} (s) : cut_expand r (s + t) (s + u) ↔ cut_expand r t u :=\nexists₂_congr $ λ _ _, and_congr iff.rfl $ by rw [add_assoc, add_assoc, add_left_cancel_iff]\n\nlemma cut_expand_iff [decidable_eq α] (hr : irreflexive r) {s' s : multiset α} :\n  cut_expand r s' s ↔ ∃ (t : multiset α) a, (∀ a' ∈ t, r a' a) ∧ a ∈ s ∧ s' = s.erase a + t :=\nbegin\n  simp_rw [cut_expand, add_singleton_eq_iff],\n  refine exists₂_congr (λ t a, ⟨_, _⟩),\n  { rintro ⟨ht, ha, rfl⟩,\n    obtain (h|h) := mem_add.1 ha,\n    exacts [⟨ht, h, t.erase_add_left_pos h⟩, (hr a $ ht a h).elim] },\n  { rintro ⟨ht, h, rfl⟩,\n    exact ⟨ht, mem_add.2 (or.inl h), (t.erase_add_left_pos h).symm⟩ },\nend\n\ntheorem not_cut_expand_zero (hr : irreflexive r) (s) : ¬ cut_expand r s 0 :=\nby { classical, rw cut_expand_iff hr, rintro ⟨_, _, _, ⟨⟩, _⟩ }\n\n/-- For any relation `r` on `α`, multiset addition `multiset α × multiset α → multiset α` is a\n  fibration between the game sum of `cut_expand r` with itself and `cut_expand r` itself. -/\nlemma cut_expand_fibration (r : α → α → Prop) :\n  fibration (game_add (cut_expand r) (cut_expand r)) (cut_expand r) (λ s, s.1 + s.2) :=\nbegin\n  rintro ⟨s₁, s₂⟩ s ⟨t, a, hr, he⟩, dsimp at he ⊢,\n  classical, obtain ⟨ha, rfl⟩ := add_singleton_eq_iff.1 he,\n  rw [add_assoc, mem_add] at ha, obtain (h|h) := ha,\n  { refine ⟨(s₁.erase a + t, s₂), fst ⟨t, a, hr, _⟩, _⟩,\n    { rw [add_comm, ← add_assoc, singleton_add, cons_erase h] },\n    { rw [add_assoc s₁, erase_add_left_pos _ h, add_right_comm, add_assoc] } },\n  { refine ⟨(s₁, (s₂ + t).erase a), snd ⟨t, a, hr, _⟩, _⟩,\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 (hi : irreflexive r) {s : multiset α} :\n  (∀ a ∈ s, acc (cut_expand r) {a}) → acc (cut_expand r) s :=\nbegin\n  refine multiset.induction _ _ s,\n  { exact λ _, acc.intro 0 $ λ s h, (not_cut_expand_zero hi s h).elim },\n  { intros a s ih hacc, rw ← s.singleton_add a,\n    exact ((hacc a $ s.mem_cons_self a).game_add $ ih $ λ 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 (hi : irreflexive r)\n  {a : α} (hacc : acc r a) : acc (cut_expand r) {a} :=\nbegin\n  induction hacc with a h ih,\n  refine acc.intro _ (λ s, _),\n  classical, rw cut_expand_iff hi,\n  rintro ⟨t, a, hr, rfl|⟨⟨⟩⟩, rfl⟩,\n  refine acc_of_singleton hi (λ a', _),\n  rw [erase_singleton, zero_add],\n  exact ih a' ∘ 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⟨λ s, acc_of_singleton hr.is_irrefl.1 $ λ a _, (hr.apply a).cut_expand hr.is_irrefl.1⟩\n\nend hydra\n\nend relation\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/hydra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7826446813071221}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la teoría de los números reales.\n-- 2. Declarar x e y como variables sobre los reales.\n-- 3. Iniciar el espacio de nombre my_abs.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic   -- 1\nvariables {x y z : ℝ}    -- 2\nnamespace my_abs         -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    x < abs y ↔ x < y ∨ x < -y\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\ntheorem lt_abs : x < abs y ↔ x < y ∨ x < -y :=\nbegin\n  unfold abs,\n  exact lt_max_iff,\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : ℝ\n⊢ x < abs y ↔ x < y ∨ x < -y\n  >> unfold abs,\n⊢ x < max y (-y) ↔ x < y ∨ x < -y\n  >> exact lt_max_iff,\nno goals\n-/\n\n-- Comentarios:\n-- 1. La táctica (unfold e) despliega la definición de e.\n-- 2. La definición de abs\n--    + abs (a : α) : α := max a (-a)\n-- 3. Se ha usado el lema\n--    + lt_max_iff : x < max y z ↔ x < y ∨ x < z\n\n-- Comprobación\n-- #check (@lt_max_iff ℝ _ x y z)\n\n-- 2ª demostración\n-- ===============\n\nexample : x < abs y ↔ x < y ∨ x < -y :=\nlt_max_iff\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    abs x < y ↔ - y < x ∧ x < y\n-- ----------------------------------------------------------------------\n\ntheorem abs_lt : abs x < y ↔ -y < x ∧ x < y :=\nbegin\n  unfold abs,\n  split,\n    { intro h1,\n      rw max_lt_iff at h1,\n      cases h1 with h2 h3,\n      split,\n        { exact neg_lt.mp h3 },\n        { exact h2 }},\n    { intro h4,\n      apply max_lt_iff.mpr,\n      cases h4 with h5 h6,\n      split,\n       { exact h6 },\n       { exact neg_lt.mp h5 }},\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : ℝ\n⊢ abs x < y ↔ -y < x ∧ x < y\n  unfold abs,\n⊢ max x (-x) < y ↔ -y < x ∧ x < y\n  >> split,\n| ⊢ max x (-x) < y → -y < x ∧ x < y\n|   >>   { intro h1,\n| h1 : max x (-x) < y\n| ⊢ -y < x ∧ x < y\n|   >>     rw max_lt_iff at h1,\n| h1 : x < y ∧ -x < y\n| ⊢ -y < x ∧ x < y\n|   >>     cases h1 with h2 h3,\n| h2 : x < y,\n| h3 : -x < y\n| ⊢ -y < x ∧ x < y\n|   >>     split,\n| | ⊢ -y < x\n|   >>       { exact neg_lt.mp h3 },\n| ⊢ x < y\n|   >>       { exact h2 }},\n⊢ -y < x ∧ x < y → max x (-x) < y\n  >>   { intro h4,\nh4 : -y < x ∧ x < y\n⊢ max x (-x) < y\n  >>     apply max_lt_iff.mpr,\n⊢ x < y ∧ -x < y\n  >>     cases h4 with h5 h6,\nh5 : -y < x,\nh6 : x < y\n⊢ x < y ∧ -x < y\n  >>     split,\n| ⊢ x < y\n  >>      { exact h6 },\n⊢ -x < y\n  >>      { exact neg_lt.mp h5 }},\nno goals\n-/\n\n-- Comentarios: Se han usado los siguientes lemas:\n-- + max_lt_iff : max x y < z ↔ x < z ∧ y < z\n-- + neg_lt : -x < y ↔ -y < x\n\n-- Comprobación:\n-- #check (@max_lt_iff ℝ _ x y z)\n-- #check (@neg_lt ℝ _ x y)\n\nend my_abs\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/Cotas_del_valor_absoluto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.891811053345418, "lm_q1q2_score": 0.7825435095600896}}
{"text": "import data.real.basic\n\nvariables {x y : ℝ}\n\n#check le_refl\n#check le_refl y\n#check @le_abs \n#check @abs_le\n#check neg_add\n#check add_le_add\n\nnamespace my_abs\n\n-- BEGIN\ntheorem le_abs_self : x ≤ abs x :=\nbegin\n  rw le_abs,\n  left,\n  apply le_refl,\nend\n\ntheorem neg_le_abs_self : -x ≤ abs x :=\nbegin\n  rw le_abs,\n  right,\n  apply le_refl,\nend\n\n/- with le_abs_self and neg_le_abs_self, now we can proof abs_add \nusing the split tactic-/\nexample : abs (x + y) ≤ abs x + abs y :=\nbegin\n  rw abs_eq_max_neg,\n  rw max_le_iff,\n  split,\n  { apply add_le_add,\n    exact le_abs_self,\n    exact le_abs_self, },\n  { rw neg_add,\n    apply add_le_add,\n    exact neg_le_abs_self,\n    exact neg_le_abs_self, },\nend\n\n-- END\n\n#check @le_abs_self\n#check @neg_le_abs_self\n#check @abs_add\n\nend my_abs", "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.1_conjunc/ex5_split_inequal_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7825124696196784}}
{"text": "import .love12_basic_mathematical_structures_demo\n\n\n/-! # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Type Classes\n\nRecall the inductive type `btree` we introduced earlier: -/\n\n#check btree\n\n/-! The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/-! 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nsorry\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nsorry\n\n/-! 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\nsorry\n\n/-! 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/-! 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀y : btree ℕ, btree.graft y x ≠ btree.empty :=\nsorry\n\n\n/-! ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/-! 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nsorry\n\n/-! 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nsorry\n\n/-! 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nsorry\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\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/love12_basic_mathematical_structures_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7825018229782755}}
{"text": "import topology.definitions tactic\n\n/-\nA topological space (X, 𝒯) consists of a non-empty set X \ntogether with a collection 𝒯 of subsets of X that satisfy \n- ∅ ∈ 𝒯, X ∈ 𝒯\n- U, V ∈ 𝒯 → U ∩ V ∈ 𝒯 \n- Uᵢ ∈ 𝒯 → ⋃ᵢ U ∈ 𝒯\nElements of 𝒯 are called open sets in (X, 𝒯) and 𝒯 is \ncalled a topology on X.\n\nIn Lean this is represented by:\n\nstructure topological_space (α : Type u) :=\n(is_open        : set α → Prop)\n(is_open_univ   : is_open univ)\n(is_open_inter  : ∀s t, is_open s → is_open t → is_open (s ∩ t))\n(is_open_sUnion : ∀s, (∀ t ∈ s, is_open t) → is_open (⋃₀ s))\n-/\n\nvariables {X : Type*} [topological_space X]\nvariables {Y : Type*} [topological_space Y] \nvariables {Z : Type*} [topological_space Z]\n\n/- We allow excluded middle since we are not computer scientists -/\nlocal attribute [instance] classical.prop_decidable\n\nopen definitions set function\n\n/- We'll prove the axiom left out in Lean's version - ∅ is open -/\ntheorem empty_is_open : is_open (∅ : set X) :=\nbegin\n  rw ←sUnion_empty, apply is_open_sUnion, intros _ h,\n  exfalso, exact h\nend\n\n/-\nIf X is a topological space, then U ⊆ X is open iff for all x ∈ U,\nthere exists an open set Nₓ with x ∈ Nₓ and Nₓ ⊆ U\n\nThis theorem will be useful when we want to prove that a particular \nset is open or closed\n-/\n-- The forward direction is trivial enough\nlemma has_smaller_of_open {U : set X} (h : is_open U) : \n∀ x ∈ U, ∃ (Nₓ : set X) (h₀ : is_open Nₓ), x ∈ Nₓ ∧ Nₓ ⊆ U := λ x hx,\n⟨U, h, hx, subset.refl U⟩\n\n/- The backwards direction is easy once we see that we can make U \n  from the suitable union of Nₓ  -/\nlemma open_of_has_smaller {U : set X} \n(h : ∀ x ∈ U, ∃ (Nₓ : set X) (h₀ : is_open Nₓ), x ∈ Nₓ ∧ Nₓ ⊆ U) :\nis_open U :=\nbegin\n  choose f hfo hf using h,\n  have : is_open ⋃ (x ∈ U), f x H := \n    is_open_Union (λ x, is_open_Union $ λ h, hfo x h), \n  convert this, ext, \n  refine ⟨λ h, mem_Union.2 ⟨x, mem_Union.2 ⟨h, (hf x h).1⟩⟩, λ h, _⟩,\n    cases mem_Union.1 h with y hy, cases mem_Union.1 hy with hy₀ hy₁,\n    exact (hf y hy₀).2 hy₁\nend\n\ntheorem open_iff_has_smaller {U : set X} : is_open U ↔ \n∀ x ∈ U, ∃ (Nₓ : set X) (h₀ : is_open Nₓ), x ∈ Nₓ ∧ Nₓ ⊆ U :=\n⟨has_smaller_of_open, open_of_has_smaller⟩\n\nnamespace mapping\n\nopen function equiv\n\n/- The composition of two continuous functions is also continuous -/\ntheorem comp_contin {f : X → Y} {g : Y → Z} \n(hf : is_continuous f) (hg : is_continuous g) : \nis_continuous (g ∘ f) := λ U hU, hf _ (hg _ hU)\n\n/- A function is continuous iff. it is continuous at every point -/\nlemma contin_at_all_of_contin {f : X → Y} (h : is_continuous f) : \n∀ x : X, is_continuous_at f x := λ _ U _ hU, h U hU\n\nlemma contin_of_contin_at_all {f : X → Y} \n(h : ∀ x : X, is_continuous_at f x) : is_continuous f := λ U hU,\nbegin\n  cases (classical.em $ f ⁻¹' U = ∅) with hempt hnempt,\n    { rw hempt, exact empty_is_open },\n    { cases ne_empty_iff_nonempty.1 hnempt with x hx,\n      exact h _ _ (mem_preimage.1 hx) hU }\nend\n\ntheorem contin_iff_contin_at_all (f : X → Y) : \nis_continuous f ↔ ∀ x : X, is_continuous_at f x :=\n  ⟨contin_at_all_of_contin, contin_of_contin_at_all⟩\n\n/- \nA bijection of sets f : X → Y gives a homeomorphism of topological \nspaces X → Y iff. it induces a bijection 𝒯(X) → 𝒯(Y) : U → f(U)\n-/\ntheorem topo_contin_biject_of_equiv (hequiv : X ≃* Y) : \n∃ (f : X → Y) (h₀ : bijective f) (h₁ : is_continuous f), \n∀ U : set X, is_open U → is_open (f '' U) := \nbegin\n  refine ⟨hequiv.to_fun, _, hequiv.contin, λ U hU, _⟩,\n  refine ⟨hequiv.left_inv.injective, hequiv.right_inv.surjective⟩,\n  convert hequiv.inv_contin U hU, \n  ext, split; intro hx,\n    { rcases (mem_image _ _ _).1 hx with ⟨y, hy₀, hy₁⟩,\n      rw ←hy₁, simp [hy₀] },\n    { refine ⟨(hequiv.to_equiv.symm) x, hx, _⟩, simp }\nend\n\nlemma preimage_eq_inv {f : X → Y} {U : set X} (hf : bijective f) : \nf '' U = (of_bijective _ hf).inv_fun ⁻¹' U :=\nbegin\n  ext, split; intro hx,\n    { rcases (mem_image _ _ _).1 hx with ⟨y, hy₀, hy₁⟩,\n      rw [←hy₁, mem_preimage], \n      have : left_inverse (of_bijective _ hf).inv_fun f := \n        (of_bijective _ hf).left_inv, \n      rwa this y },\n    { refine ⟨(of_bijective _ hf).inv_fun x, hx, _⟩,\n      have : right_inverse (of_bijective _ hf).inv_fun f := \n        (of_bijective _ hf).right_inv,\n      rwa this x\n    }\nend\n\nnoncomputable theorem equiv_of_topo_contin_biject {f : X → Y} \n(hf₀ : bijective f) (hf₁ : ∀ U : set X, is_open U → is_open (f '' U)) \n(hf₂ : is_continuous f) : X ≃* Y :=\n{ contin := hf₂,\n  inv_contin := λ U hU, by rw ←preimage_eq_inv hf₀; exact hf₁ U hU,\n  .. of_bijective _ hf₀ }\n\nend mapping\n\nnamespace closed\n\n/- Giving closure the attribute reducible so lean will automatically \nunfold the definition instead of us manually telling it do so -/\nattribute [reducible] closure\n\n/- The closure of a set is the smallest closed set continaing it -/\ntheorem closure_is_min {U U' : set X} (hle : U ⊆ U') (hc : is_closed U') :\nclosure U ⊆ U' := \nbegin\n  intros x hx, rw mem_sInter at hx,\n  exact hx U' ⟨hc, hle⟩\nend\n\n/- The closure of a set is the set of limit points -/\nlemma limit_points_is_closed {U : set X}: \nis_closed $ limit_points U := \nbegin\n  refine open_iff_has_smaller.2 (λ x hx, _),\n  simp at hx, rcases hx with ⟨U', hU'₀, hU'₁, hU'₂⟩,\n  exact ⟨U', hU'₀, hU'₁, λ y hy, by simp; exact ⟨U', hU'₀, hy, hU'₂⟩⟩,\nend\n\nlemma limit_points_ge {U : set X} : U ⊆ limit_points U := \nλ x hx _ _ hU', ne_empty_iff_nonempty.2 ⟨x, hU', hx⟩\n\nlemma closure_le_limit_points (U : set X) :\nclosure U ⊆ limit_points U := \n  closure_is_min limit_points_ge limit_points_is_closed\n\nlemma limit_points_le_closure (U : set X) :\nlimit_points U ⊆ closure U := λ x hx U' hU',\nclassical.by_contradiction $ λ hf,\n  let ⟨y, hy⟩ := ne_empty_iff_nonempty.1 (hx (U'ᶜ) (hU'.1) hf) in\nnot_subset.2 ⟨y, hy.2, hy.1⟩ hU'.2\n\ntheorem closure_eq_limit_points (U : set X) : \nclosure U = limit_points U :=\nle_antisymm (closure_le_limit_points U) (limit_points_le_closure U)\n\n/- A set is smaller than its closure -/\ntheorem set_le_closure (U : set X) : U ⊆ closure U := \nλ x hx, mem_sInter.1 $ λ U' hU', hU'.2 hx\n\n/- If A ⊆ B then the closure of A is smaller than the closure of B -/\ntheorem closure_mono' {U V : set X} (hle : U ⊆ V) :\nclosure U ⊆ closure V := λ x hx A hA, hx _ ⟨hA.1, subset.trans hle hA.2⟩\n\n/- The closure of a closed set is itself-/\ntheorem closure_of_closed {U : set X} (h : is_closed U) :\nclosure U = U := ext $ λ x, \n  ⟨λ hx, hx U ⟨h, subset.refl U⟩, λ hx, set_le_closure U hx⟩\n\n/- The intersection of closed sets is closed -/\ntheorem is_closed_Inter {ι} {f : ι → set X} (hf : ∀ i : ι, is_closed (f i)) : \nis_closed (⋂ ι, f ι) :=\nby unfold is_closed; rw compl_Inter; refine is_open_Union hf\n\n/- The closure of a set is closed -/\ntheorem closure_is_closed (U : set X) : is_closed $ closure U := \nbegin\n  unfold is_closed, rw compl_sInter,\n  refine is_open_sUnion (λ _ hU', _),\n  rcases hU' with ⟨_, ⟨hU'₀, _⟩, hU'₁⟩,\n  exact hU'₁ ▸ hU'₀\nend\n\nend closed\n\nnamespace interior\n\nopen closed\n\n/- The interior of a set equals the set of its interior points -/\ntheorem interior_eq_interior_points {U : set X} :\ninterior U = interior_points U := ext $ λ x,\n  ⟨λ hx, let ⟨U', ⟨hU'₀, hU'₁⟩, hU'₂⟩ := hx in ⟨U', hU'₀, hU'₁, hU'₂⟩,\n   λ hx, let ⟨U', hU'₀, hU'₁, hU'₂⟩ := hx in ⟨U', ⟨hU'₀, hU'₁⟩, hU'₂⟩⟩\n\n/- The closure of -U equals the complement of the interior of U -/\ntheorem closure_compl_eq_compl_interior {U : set X} :\nclosure Uᶜ = (interior U)ᶜ := \nbegin\n  ext, split; rw [closure_eq_limit_points, interior_eq_interior_points],\n    { intros hx₀ hx₁,\n      rcases hx₁ with ⟨U', hU'₀, hU'₁, hU'₂⟩,\n      exact hx₀ U' hU'₀ hU'₂ (diff_eq_empty.2 hU'₁) },\n    { intros hx U' hU'₀ hU'₁ hU'₂,\n      simp at hx, exact hx U' hU'₀ (diff_eq_empty.1 hU'₂) hU'₁ }\nend\n\ntheorem interior_eq_compl_closure_compl {U : set X} :\ninterior U = (closure Uᶜ)ᶜ := by simp [closure_compl_eq_compl_interior]\n\n/- With the above theorem in place, we can straightaway analougous theorems \nto the ones we've proved for closure -/\n\n/- The interior of a set is smaller than the set -/\ntheorem interior_le_set (U : set X) : interior U ⊆ U := \nby rw [interior_eq_compl_closure_compl, compl_subset_comm]; exact set_le_closure Uᶜ\n\n/- If A ⊆ B, then the interior of A ⊆ interior of B -/\ntheorem interior_mono {U V : set X} (hle : U ⊆ V) : \ninterior U ⊆ interior V := \nbegin \n  repeat { rw [interior_eq_compl_closure_compl] },\n  rw [compl_subset_comm, compl_compl],\n  exact closure_mono' (compl_subset_compl.mpr hle)\nend\n\n/- The interior of an open set is itself -/\ntheorem interior_of_open {U : set X} (h : is_open U) :\ninterior U = U := \nbegin\n  rw interior_eq_compl_closure_compl,\n  suffices : closure Uᶜ = Uᶜ, simp [this],\n  exact closure_of_closed (by simp [compl_compl, h])\nend\n\n/- The interior of a set is open -/\ntheorem interior_is_open (U : set X) : is_open $ interior U :=\nby rw interior_eq_compl_closure_compl; simp [closure_is_closed]\n\n/- The interior of the interior is the interior -/\ntheorem interior_of_interior (U : set X) :\n(interior $ interior U) = interior U := \ninterior_of_open $ interior_is_open U\n\n/- The interior of a set is the larges open set contained in \nthe set -/\ntheorem interior_is_max {U U' : set X} (hle : U' ⊆ U) (hc : is_open U') :\nU' ⊆ interior U := \nby rw [interior_eq_compl_closure_compl, subset_compl_comm];\n  exact closure_is_min (compl_subset_compl.2 hle) (by simp [hc])\n\nend interior\n\nnamespace mapping\n\nvariables {U : set X} {V : set Y} {f : X → Y}\n\n/- A mapping f : X → Y is continuous iff f⁻¹(U) is closed whenever \nU is closed-/\nlemma preimage_closed_of_closed (h : is_closed V)\n(hcontin : is_continuous f) : is_closed (f ⁻¹' V) :=\nby unfold is_closed; rw ←preimage_compl; exact hcontin _ h\n\nlemma contin_of_preimage_closed_of_closed \n(h : ∀ V, is_closed V → is_closed (f ⁻¹' V)) : is_continuous f :=\nbegin\n  intros U hU,\n  suffices : is_closed (f ⁻¹' U)ᶜ,\n    { unfold is_closed at this, rwa compl_compl at this },\n  rw ←preimage_compl,\n  refine h _ _, unfold is_closed, rwa compl_compl\nend\n\ntheorem contin_iff_preimage_closed_of_closed : is_continuous f ↔ \n∀ V, is_closed V → is_closed (f ⁻¹' V) :=\n⟨λ h V hV, preimage_closed_of_closed hV h, \n  λ h, contin_of_preimage_closed_of_closed h⟩\n\nopen closed\n\n/- A mapping f : X → Y is continuous imples f(closure A) ⊆ closure f(A) -/\ntheorem map_closure_le_closure_map (hcontin : is_continuous f) :\nf '' closure U ⊆ closure (f '' U) := \nbegin\n  rw contin_iff_preimage_closed_of_closed at hcontin,\n  suffices : closure U ⊆ f ⁻¹' closure (f '' U),\n    intros _ hy,\n    rcases (mem_image _ _ _).1 hy with ⟨_, hx₀, hx₁⟩,\n    rw ←hx₁, exact mem_preimage.1 (this hx₀),\n  exact closure_is_min (λ _ hu, mem_preimage.2 (set_le_closure _ (mem_image_of_mem f hu)))\n   (hcontin _ (closure_is_closed $ f '' U)),\nend\n\nend mapping\n\nnamespace subspaces\n\nopen mapping\n\n/- The inclusion map is continuous -/\ntheorem inclusion_is_continuous (A : set X) : is_continuous 𝒾 A :=\nbegin\n  intros U hU, refine ⟨U, hU, _⟩,\n  ext, split; intro hx,\n    { rw preimage, use x, \n      exact hx.1, refine ⟨hx.2, rfl⟩ },\n    { rcases hx with ⟨x', hx'₀, hx'₁⟩,\n      rw ←hx'₁, split,\n        exact subtype.val_prop x',\n        simp at hx'₀, assumption }\nend\n\n/- (Universal Property) -/\nlemma comp_inclusion_is_contin_of_is_contin {A : set X} {f : Z → A}\n(h : is_continuous f) : is_continuous $ (𝒾 A) ∘ f := \ncomp_contin h (inclusion_is_continuous A)\n\n-- There has to be a better way to deal with type conversions :/\ntheorem is_contin_of_comp_inclusion_is_contin {A : set X} {f : Z → A}\n(h : is_continuous $ (𝒾 A) ∘ f) : is_continuous f := \nbegin\n  intros U hU, rcases hU with ⟨V, hV₀, hV₁⟩,\n  suffices : f ⁻¹' U = (𝒾 A) ∘ f ⁻¹' V,\n    rw this, exact h _ hV₀,\n  ext, split; intro hx,\n    { show ↑(f x) ∈ V, suffices : ↑U ⊆ V,\n        apply this, exact mem_image_of_mem coe hx,\n      rw ←hV₁, exact inter_subset_right A V },\n    { rw mem_preimage at *,\n      replace hx : ↑(f x) ∈ V, exact hx,\n      have : ↑(f x) ∈ ↑U,\n        rw ←hV₁, exact mem_inter (subtype.coe_prop _) hx,\n      cases f x with fx₀ _,\n      rcases this with ⟨y, hy₀, hy₁⟩, \n      convert hy₀, cases y, \n      suffices : fx₀ = y_val, simp only [subtype.mk_eq_mk], assumption,\n      simp only [subtype.coe_mk] at hy₁, rw hy₁ }\nend\n\ntheorem is_contin_iff_comp_inclusion_is_contin {A : set X} {f : Z → A} :\nis_continuous f ↔ (is_continuous $ (𝒾 A) ∘ f) := \n⟨ λ h, comp_inclusion_is_contin_of_is_contin h, \n  λ h, is_contin_of_comp_inclusion_is_contin h ⟩\n\nend subspaces\n\nnamespace Hausdorff_spaces\n\n/- Sequence in a topological space have unique limits if that topological \nspace is Hausdorff (the inverse is in general not true) -/\ntheorem unique_limit_of_Hausdorff {x : ℕ → X} {l k : X} (h : is_Hausdorff X)\n(hl : converge_to x l) (hk : converge_to x k) : l = k :=\nclassical.by_contradiction $ λ hne,\n  let ⟨U, V, hU, hV, hlU, hkV, hdisj⟩ := h l k hne in\n  let ⟨N₁, hN₁⟩ := hl _ hU hlU in let ⟨N₂, hN₂⟩ := hk _ hV hkV in\nnot_mem_empty (x (max N₁ N₂)) \n  (hdisj ▸ ⟨hN₁ _ (le_max_left N₁ N₂), hN₂ _ (le_max_right N₁ N₂)⟩)\n\n/- If Y is Hausdorff and there exists a continuous injective map from \nX to Y then X is also Hausdorff -/\ntheorem Hausdorff_of_continuous_inj (f : X → Y) (h : is_Hausdorff Y)\n(hcontin : is_continuous f) (hinj : injective f) : is_Hausdorff X :=\nbegin\n  intros x y hxy,\n  rcases h _ _ (λ hf, hxy (hinj hf)) with ⟨U, V, hU₀, hV₀, hU₁, hV₁, hdisj⟩,\n  refine ⟨f ⁻¹' U, f ⁻¹' V, hcontin U hU₀, hcontin V hV₀, hU₁, hV₁, _⟩,\n  ext z, split; intro hz,\n    { cases hz with hz₀ hz₁,\n      rw mem_preimage at *,\n      exfalso, refine @not_mem_empty Y (f z) _,\n      rw ←hdisj, exact ⟨hz₀, hz₁⟩ },\n    { exfalso, exact (not_mem_empty z) hz },\nend\n\n/- A subspace of a Hausdorff space is Hausdorff -/\ntheorem subspace_Hausdorff {A : set X} (h : is_Hausdorff X) : is_Hausdorff A := \nHausdorff_of_continuous_inj (𝒾 A) h (subspaces.inclusion_is_continuous A) \n  (λ _ _ hxy, subtype.eq hxy)\n\n/- If X ≃* Y, then X is Hausdorff ⇔ Y is Hausdorff -/\nlemma Hausdorff_of_equiv (h : is_Hausdorff Y) (hequiv : X ≃* Y) : \nis_Hausdorff X :=\nHausdorff_of_continuous_inj hequiv.to_fun h hequiv.contin (equiv.injective hequiv.1)\n\nlemma equiv_symm (hequiv : X ≃* Y) : Y ≃* X := \n{ contin := hequiv.inv_contin,\n  inv_contin := hequiv.contin,\n  .. equiv.symm hequiv.1 }\n\ntheorem Hausdorff_equiv (hequiv : X ≃* Y) : \nis_Hausdorff X ↔ is_Hausdorff Y :=\niff.intro (λ h, Hausdorff_of_equiv h (equiv_symm hequiv)) \n  (λ h, Hausdorff_of_equiv h hequiv)\n\nend Hausdorff_spaces", "meta": {"author": "JasonKYi", "repo": "learn_mspaces", "sha": "54083e81da420d2d362a7024a8c86bea8529fe66", "save_path": "github-repos/lean/JasonKYi-learn_mspaces", "path": "github-repos/lean/JasonKYi-learn_mspaces/learn_mspaces-54083e81da420d2d362a7024a8c86bea8529fe66/src/topology/theorems.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7825018212520177}}
{"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 `ℚ>₀` be the positive rational numbers. Let `f : ℚ>₀ → ℝ` be a function satisfying\nthe conditions\n\n1. `f(x) * f(y) ≥ f(x * y)`\n2. `f(x + y) ≥ f(x) + f(y)`\n\nfor all `x, y ∈ ℚ>₀`. Given that `f(a) = a` for some rational `a > 1`, prove that `f(x) = x` for\nall `x ∈ ℚ>₀`.\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 : ℝ} (hx : 1 < x) (hy : 1 < y)\n  (h : ∀ n : ℕ, 0 < n → x^n - 1 < y^n) :\n  x ≤ y :=\nbegin\n  by_contra' hxy,\n  have hxmy : 0 < x - y := sub_pos.mpr hxy,\n  have hn : ∀ n : ℕ, 0 < n → (x - y) * (n : ℝ) ≤ x^n - y^n,\n  { intros n hn,\n    have hterm : ∀ i : ℕ, i ∈ finset.range n → 1 ≤ x^i * y^(n - 1 - i),\n    { intros i hi,\n      have hx' : 1 ≤ x ^ i := one_le_pow_of_one_le hx.le i,\n      have hy' : 1 ≤ y ^ (n - 1 - i) := one_le_pow_of_one_le hy.le (n - 1 - i),\n      calc 1 ≤ x^i             : hx'\n         ... = x^i * 1         : (mul_one _).symm\n         ... ≤ x^i * y^(n-1-i) : mul_le_mul_of_nonneg_left hy' (zero_le_one.trans hx') },\n\n    calc (x - y) * (n : ℝ)\n            = (n : ℝ) * (x - y) : mul_comm _ _\n        ... = (∑ (i : ℕ) in finset.range n, (1 : ℝ)) * (x - y) :\n                                  by simp only [mul_one, finset.sum_const, nsmul_eq_mul,\n                                    finset.card_range]\n        ... ≤ (∑ (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₂_mul x y n, },\n\n  -- Choose n larger than 1 / (x - y).\n  obtain ⟨N, hN⟩ := 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             ... ≤ 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 : ℝ} (hx : 1 < x) (hy : 0 < y)\n  (h : ∀ n : ℕ, 0 < n → x^n - 1 < y^n) :\n  x ≤ y :=\nbegin\n  refine le_of_all_pow_lt_succ hx _ h,\n  by_contra' hy'' : y ≤ 1,\n\n  -- Then there exists y' such that 0 < y ≤ 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 : ∀ n, 0 < n → x^n - 1 < y'^n,\n  { intros n hn,\n    calc x^n - 1 < y^n  : h n hn\n            ...  ≤ 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 : ℚ → ℝ} {q : ℚ} (hq : 0 < q)\n  (H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)\n  (H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ 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 : ℝ) < q.num   : int.cast_pos.mpr num_pos\n      ... = ((q.num.nat_abs : ℤ) : ℝ) : congr_arg coe (int.nat_abs_of_nonneg num_pos.le).symm\n      ... ≤ 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 ←int.nat_abs_of_nonneg num_pos.le, norm_cast }\n      ... = f (q * q.denom) : by rw ←rat.mul_denom_eq_num\n      ... ≤ 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 : ℝ) < q.denom : nat.cast_pos.mpr q.pos\n      ... ≤ 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 : ℚ → ℝ} {x : ℚ} (hx : 1 ≤ x)\n  (H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)\n  (H2 : ∀ x y, 0 < x → 0 < y → f x + f y ≤ f (x + y))\n  (H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n) :\n  (x - 1 : ℝ) < f x :=\nbegin\n  have hx0 :=\n    calc (x - 1 : ℝ)\n          < ⌊x⌋₊   : by exact_mod_cast nat.sub_one_lt_floor x\n      ... ≤ f ⌊x⌋₊ : 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 : ℝ) < f ⌊x⌋₊ : hx0\n    ... < f (x - ⌊x⌋₊) + f ⌊x⌋₊ : lt_add_of_pos_left _ (f_pos_of_pos (sub_pos.mpr h_lt) H1 H4)\n    ... ≤ f (x - ⌊x⌋₊ + ⌊x⌋₊)   : 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 : ℚ → ℝ} {n : ℕ} (hn : 0 < n) {x : ℚ} (hx : 1 < x)\n  (H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)\n  (H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n) :\n  f (x^n) ≤ (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          ≤ f (x ^ (pn+1)) * f x : H1 (x ^ (pn+1)) x (pow_pos hxp (pn+1)) hxp\n      ... ≤ (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 : ℚ → ℝ} {n : ℕ} (hn : 0 < n)\n  (H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)\n  (H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n)\n  (H5 : ∀ x : ℚ, 1 < x → (x : ℝ) ≤ f x)\n  {a : ℚ} (ha1 : 1 < a) (hae : f a = a) :\n  f (a^n) = a^n :=\nbegin\n  have hh0 : (a : ℝ) ^ n ≤ f (a ^ n),\n  { exact_mod_cast H5 (a ^ n) (one_lt_pow ha1 hn.ne') },\n\n  have hh1 := calc f (a^n) ≤ (f a)^n   : pow_f_le_f_pow hn ha1 H1 H4\n                       ... = (a : ℝ)^n : by rw ← hae,\n\n  exact hh1.antisymm hh0\nend\n\nlemma fixed_point_of_gt_1 {f : ℚ → ℝ} {x : ℚ} (hx : 1 < x)\n  (H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)\n  (H2 : ∀ x y, 0 < x → 0 < y → f x + f y ≤ f (x + y))\n  (H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n)\n  (H5 : ∀ x : ℚ, 1 < x → (x : ℝ) ≤ f x)\n  {a : ℚ} (ha1 : 1 < a) (hae : f a = a) :\n  f x = x :=\nbegin\n  -- Choose n such that 1 + x < a^n.\n  obtain ⟨N, hN⟩ := pow_unbounded_of_one_lt (1 + x) ha1,\n  have h_big_enough : (1:ℚ) < a^N - x := lt_sub_iff_add_lt.mpr hN,\n\n  have h1 := calc (x : ℝ) + ((a^N - x) : ℚ)\n                        ≤ f x + ((a^N - x) : ℚ) : add_le_add_right (H5 x hx) _\n                    ... ≤ 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, rw [nat.le_zero_iff.mp H] at hN, linarith },\n\n  have h2 := calc f x + f (a^N - x)\n                        ≤ 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 : ℚ → ℝ)\n  (H1 : ∀ x y, 0 < x → 0 < y → f (x * y) ≤ f x * f y)\n  (H2 : ∀ x y, 0 < x → 0 < y → f x + f y ≤ f (x + y))\n  (H_fixed_point : ∃ a, 1 < a ∧ f a = a) :\n  ∀ x, 0 < x → f x = x :=\nbegin\n  obtain ⟨a, ha1, hae⟩ := H_fixed_point,\n  have H3 : ∀ x : ℚ, 0 < x → ∀ n : ℕ, 0 < n → ↑n * f x ≤ 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 (↑pn + 1 + 1) * f x\n          = ((pn : ℝ) + 1) * f x + 1 * f x : add_mul (↑pn + 1) 1 (f x)\n      ... = (↑pn + 1) * f x + f x          : by rw one_mul\n      ... ≤ f ((↑pn.succ) * x) + f x       : by exact_mod_cast add_le_add_right\n                                                  (hpn pn.succ_pos) (f x)\n      ... ≤ f ((↑pn + 1) * x + x)          : by exact_mod_cast H2 _ _\n                                                  (mul_pos pn.cast_add_one_pos hx) hx\n      ... = f ((↑pn + 1) * x + 1 * x)      : by rw one_mul\n      ... = f ((↑pn + 1 + 1) * x)          : congr_arg f (add_mul (↑pn + 1) 1 x).symm },\n  have H4 : ∀ n : ℕ, 0 < n → (n : ℝ) ≤ f n,\n  { intros n hn,\n    have hf1 : 1 ≤ f 1,\n    { have a_pos : (0 : ℝ) < a := rat.cast_pos.mpr (zero_lt_one.trans ha1),\n      suffices : ↑a * 1 ≤ ↑a * f 1, from (mul_le_mul_left a_pos).mp this,\n      calc ↑a * 1 = ↑a        : mul_one ↑a\n              ... = f a       : hae.symm\n              ... = f (a * 1) : by rw mul_one\n              ... ≤ f a * f 1 : (H1 a 1) (zero_lt_one.trans ha1) zero_lt_one\n              ... = ↑a * f 1  : by rw hae },\n\n    calc (n : ℝ) = (n : ℝ) * 1   : (mul_one _).symm\n             ... ≤ (n : ℝ) * f 1 : mul_le_mul_of_nonneg_left hf1 (nat.cast_nonneg _)\n             ... ≤ f (n * 1)     : H3 1 zero_lt_one n hn\n             ... = f n           : by rw mul_one },\n\n  have H5 : ∀ x : ℚ, 1 < x → (x : ℝ) ≤ f x,\n  { intros x hx,\n    have hxnm1 : ∀ n : ℕ, 0 < n → (x : ℝ)^n - 1 < (f x)^n,\n    { intros n hn,\n      calc (x : ℝ)^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                     ... ≤ (f x)^n : pow_f_le_f_pow hn hx H1 H4 },\n    have hx' : 1 < (x : ℝ) := 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 : ∀ n : ℕ, 0 < n → ∀ x : ℚ, 0 < x → f (n * x) = n * f x,\n  { intros n hn x hx,\n    have h2 : f (n * x) ≤ 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 ← hfneq,\n      exact H1 (n.succ.succ : ℚ) 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 : ℚ) ≠ (0 : ℚ) := ne_of_gt (nat.cast_pos.mpr x.pos),\n  have hx2cnezr : (x2denom : ℝ) ≠ (0 : ℝ) := 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 : ℝ) * 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 : ℚ) < (2 * x.num : ℤ),\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 ←(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 : ℚ) / (x2denom : ℚ) : ℚ) : ℝ) : by norm_cast\n       ... = x                                       : by rw ←hrat_expand2\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/2013/p5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8519527982093668, "lm_q1q2_score": 0.7825018120962892}}
{"text": "namespace xena\n\ninductive xnat\n| zero : xnat\n| succ : xnat → xnat\n\nopen xnat \n\ndefinition add : xnat → xnat → xnat\n| n zero := n\n| n (succ p) := succ (add n p)\n\nnotation a + b := add a b \ndefinition one := succ zero\ndefinition two := succ one \ndefinition three := succ two \ndefinition four := succ three\n\nexample : one + one = two :=\nbegin\nrefl\nend\n\nexample : two + two = four :=\nbegin\ndunfold two,\ndunfold add,\nrefl,\nend \n\n\ntheorem add_assoc (a b c : xnat) : (a + b) + c = a + (b + c) :=\n\nbegin\ninduction c with n Hn,\n  unfold add,\nunfold add,\nrw [Hn],\nend\n\ntheorem add_zero (n : xnat) : n + zero = n := by unfold add\n\ntheorem zero_add (n : xnat) : zero + n = n := \nbegin\ninduction n with t Ht,\n  refl,\nunfold add,\nrw [Ht],\nend\n\ntheorem zero_add_eq_add_zero (n : xnat) : zero + n = n + zero :=\nbegin\nrewrite [zero_add,add_zero]\nend\n\n\n\ntheorem one_add_eq_succ (n : xnat) : (succ zero) + n = succ n :=\nbegin\ninduction n with a Ha,\n  refl,\n  unfold add,\n  rw [Ha],\nend\n\ntheorem add_one_eq_succ (n : xnat) : n + (succ zero) = succ n :=\nbegin\nunfold add\nend\n\ntheorem add_comm (a b : xnat) : a + b = b + a :=\nbegin \ninduction a with m Hm,\n  exact zero_add_eq_add_zero b,\nunfold add,\nrewrite ←one_add_eq_succ,\nrewrite ←one_add_eq_succ (b+m),\nrewrite add_assoc,\nrewrite Hm\nend\n\ntheorem eq_iff_succ_eq_succ (a b : xnat) : succ a = succ b ↔ 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 ↔ a+t = b+t :=\nbegin\nsplit,\n  assume H : a=b,\n  induction t with n Hn,\n    unfold add,\n    exact H,\n  unfold add,\n  rw [Hn],\n\ninduction t with n Hn,\n  unfold add,\n  assume H : a=b,\n  exact H,\nunfold add,\nrwa [eq_iff_succ_eq_succ],\nend\n\ndefinition mul : xnat → xnat → xnat\n| n zero := zero\n| n (succ p) := (mul n p) + n\n\nnotation a * b := mul a b\n\ntheorem mul_zero (a : xnat) : a * zero = zero := rfl\n\ntheorem zero_mul (a : xnat) : zero * a = zero :=\nbegin\ninduction a with n Hn,\n  refl,\nunfold mul,\nrw Hn,\nrefl\nend\n\ntheorem mul_one (a : xnat) : a * (succ zero) = a := \nbegin\nunfold mul,\nexact zero_add a,\nend\n\ntheorem one_mul (a : xnat) : (succ zero) * a = a :=\nbegin\ninduction a with n Hn,\n  refl,\nunfold mul,\nrewrite Hn,\nexact add_one_eq_succ n\nend\n\ntheorem right_distrib (a b c : xnat) : a * (b + c) = a* b + a * c :=\nbegin\ninduction c with n Hn,\n  unfold add,\n  unfold mul,\n  unfold add,\nunfold add,\nunfold mul,\nrewrite Hn,\nrewrite add_assoc\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 [←add_one_eq_succ,right_distrib,Hn,right_distrib,right_distrib],\nrw [mul_one,mul_one,mul_one],\nrw [add_assoc,←add_assoc (b*n),add_comm (b*n),←add_assoc,←add_assoc,←add_assoc],\nend\n\n\ntheorem mul_assoc (a b c : xnat) : (a * b) * c = a * (b * c) :=\nbegin\ninduction c with n Hn,\n  unfold mul,\nunfold mul,\nrewrite right_distrib,\nrewrite Hn,\nend\n\ntheorem mul_comm (a b : xnat) : a * b = b * a :=\nbegin\ninduction b with n Hn,\n  rewrite zero_mul,\n  exact mul_zero a,\nunfold mul,\nrewrite Hn,\nrewrite ←add_one_eq_succ,\nrewrite left_distrib,\nrewrite one_mul,\nend\n\ndefinition less_than : xnat → xnat → Prop \n| n zero := false\n| zero (succ p) := true \n| (succ m) (succ p) := less_than m p\n\nnotation a < b := less_than a b \n\nnotation b > a := less_than a b\n\ntheorem add_succ_equals_succ (a b : xnat) : a + (succ b) = succ (a + b) :=\nbegin\n  rw [←add_one_eq_succ,←add_one_eq_succ (a+b)],\n  rw add_assoc,\nend\n\ntheorem inequality_A1 (a b t : xnat) : a < b → a + t < b + t :=\nbegin\nassume H : a < b,\ninduction t with n Hn,\n  unfold add,\n  exact H,\nrepeat {rw [add_succ_equals_succ]},\nunfold less_than,\nexact Hn\nend\n\n-- set_option pp.notation false \n\ntheorem not_less_than_zero (a : xnat) : ¬ (a < zero) :=\nbegin\nassume H : a < zero,\n  cases a,\n  exact H,\nexact H,\nend\n\n-- set_option pp.notation false\n\ndefinition less_than_or_equal (a b : xnat) := a=b ∨ a<b\n\nnotation a ≤ b := less_than_or_equal a b\nnotation b ≤ a := a ≤ b \n\ntheorem zero_leq (a : xnat) : zero ≤ a :=\nbegin\ncases a,\n  unfold less_than_or_equal,\n  left,\n  refl,\nunfold less_than_or_equal,\nright,\nunfold less_than,\nend\n\ntheorem zero_lt_succ (a : xnat) : zero < succ a := trivial\n\n\ntheorem not_succ_le_zero (a : xnat) : ¬ (succ a ≤ zero) :=\nbegin\nassume H : succ a ≤ zero,\ncases H with H1 H2,\n  exact xnat.no_confusion H1,\n  exact H2,\nend\n\ntheorem lt_succ (a : xnat) : a < succ a :=\nbegin\ninduction a with n Hn,\n  unfold less_than,\nunfold less_than,\nexact Hn,\nend\n\ntheorem succ_lt_succ_of_lt (a b : xnat) : a < b → succ a < succ b :=\nbegin\nassume H : a < b,\nunfold less_than,\nexact H,\nend\n\ntheorem le_of_succ_le_succ (a b : xnat) : succ a ≤ succ b → a ≤ b :=\nbegin\nassume H : succ a ≤ succ b,\ncases H with H1 H2,\n  left,\n  rwa [←eq_iff_succ_eq_succ],\nright,\nunfold less_than at H2,\nassumption,\nend\n\n\n\n\ntheorem lt_or_eq_or_gt' (a : xnat) : ∀ b, a < b ∨ a = b ∨ b < a :=\nbegin\ninduction a with n Hn,\n  intro b,\n  cases b,\n    right,left,\n    trivial,\n  left,\n  trivial,\nintro b,\ncases b with m, \n  cases n,\n    right,right,\n    trivial,\n  right,right,\n  trivial,\nunfold less_than,\nrw [eq_iff_succ_eq_succ],\nexact Hn m,\nend\n\ntheorem lt_or_eq_or_gt (a b : xnat) : a < b ∨ a = b ∨ b < a :=\nbegin\nexact lt_or_eq_or_gt' a b,\nend\n\ntheorem lt_irrefl (a : xnat) : ¬ (a < a) :=\nbegin\n  induction a with n Hn,\n  unfold less_than,\n  trivial,\nunfold less_than,\nassumption,\nend\n\ntheorem ne_of_lt (a b : xnat) : a < b → ¬ (a=b) :=\nbegin\nassume Hlt : a < b,\nassume Heq : a = b,\nrw Heq at Hlt,\nexact lt_irrefl b Hlt,\nend\n\ntheorem lt_antisymm' (b : xnat) : ∀ a, a < b → ¬ (b < a) :=\nbegin\ninduction b with n Hn,\n  intro a,\n  assume H : a < zero,\n  exfalso,\n  exact not_less_than_zero a H,\nintro a,\ncases a with m Hm,\n  intro,\n  exact not_less_than_zero (succ n),\nunfold less_than,\nexact Hn m,\nend\n\ntheorem lt_antisymm (a b : xnat) : a < b → ¬  (b < a) :=\nbegin\nexact lt_antisymm' b a\nend\n\n\ntheorem inequality_A2' (a : xnat) : ∀ b c, a < b → b < c → a < c :=\nbegin\ninduction a with n Hn,\n  intros b c,\n  assume H1 : zero < b,\n  assume H2 : b < c,\n  induction c with m Hm,\n    exfalso,\n    exact not_less_than_zero b H2,\n  unfold less_than,\nintros b c,\ncases b with m,\n  unfold less_than,\n  intro H,\n  exfalso,\n  exact H,\ncases c,\n  intro H1,\n  unfold less_than,\n  intro,assumption,\nunfold less_than,\nexact Hn m c,\nend\n\ntheorem inequality_A2 (a b c : xnat) : a<b → b<c → a<c :=\nbegin\nexact inequality_A2' a b c,\nend\n\ntheorem inequality_A3 (a b : xnat) : (a<b ∨ a=b ∨ b < a) \n                                   ∧ (a<b → ¬ (a=b))\n                                   ∧ (a<b → ¬ (b<a))\n                                   ∧ ((a=b)→ ¬ (b<a)) :=\nbegin\nsplit,\n  exact lt_or_eq_or_gt a b,\nsplit,\n  exact ne_of_lt a b,\nsplit,\n  exact lt_antisymm a b,\nintro H1,\nintro H2,\nexact ne_of_lt b a H2 (eq.symm H1),\nend\n\ntheorem inequality_A4 (a b : xnat) : a>zero → b>zero → a*b > zero :=\nbegin\nassume Ha : a > zero,\nassume Hb : b > zero,\ncases a with n,\n  exfalso,\n  exact Ha,\ncases b with m,\n  exfalso,\n  exact Hb,\ndunfold mul,\ndunfold add,\ndunfold less_than,\ntrivial,\nend\n\ntheorem lt_succ_of_lt (a b : xnat) : a < b → a < succ b :=\nbegin\nadmit,\nend\n\ntheorem le_iff_add (a b : xnat) : a < b ↔ ∃ t : xnat, b = a + succ t :=\nbegin\nsplit,\n  assume H : a < b,\n  induction b with n Hn,\n    exfalso,\n    exact not_less_than_zero a H,\n  admit,admit\nend\n\ntheorem lt_succ_iff_leq (a b : xnat) : a < succ b ↔ a ≤ b :=\nbegin\nsplit,\n  assume H : a < succ b,\n  induction b with n Hn,\n    cases a,\n      left,\n      refl,\n    exfalso,\n    unfold less_than at H,\n    cases a,\n      exact H,\n    exact H,\n  admit,\nadmit,\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/Build_Maths/build_math_levels.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.7824044055840192}}
{"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# Lists\n\nAn example of a list of naturals is [1,5,8,1]. More generally, given a\ntype `X`, a term of type `mylist X` is a finite list of terms of type `X`,\nwith repeats allowed.\n\n## The definition of a list\n\nThe empty list is traditionally called `nil`, and the constructor which\ntakes a list and adds an element to the beginning is called `cons`,\nso `cons 3 [1,5,4] = [3,1,5,4]`. \n\nWe don't set up the `[a,b,c]` notation in this file.\n\n-/\n\n/-- `mylist X` is the type of (finite) lists of elements of `X`. -/\ninductive mylist (X : Type) : Type\n| nil : mylist -- empty list\n| cons (x : X) (l : mylist) : mylist -- \"put `(x : X)` at the beginning of `(l : mylist X)`\"\n\nnamespace mylist\n\nvariables (a b c : ℕ)\n\n-- list [a,b,c] of naturals\nexample : mylist ℕ := cons a (cons b (cons c nil))\n\nvariable {X : Type} -- make X implicit\n\n-- joining lists together: [1,5,4] + [2,1] = [1,5,4,2,1]. Defined \n-- by induction on the left list.\n\n/-- Addition of lists. Often called `append` in the literature. -/\ndef add : mylist X → mylist X → mylist X\n| nil l := l\n| (cons x m) l := cons x (add m l)\n\n-- Enable `+` notation for addition of lists.\ninstance : has_add (mylist X) := \n{ add := add }\n\n@[simp] lemma nil_add (a : mylist X) : nil + a = a :=\nbegin\n  sorry\nend\n\n@[simp] lemma cons_add (x : X) (m l) : cons x m + l = cons x (m + l) :=\nbegin\n  sorry\nend\n\n-- You might want to start this one with `induction a with h t IH`,\n@[simp] lemma add_nil (a : mylist X) : a + nil = a :=\nbegin\n  sorry\nend\n\nlemma add_assoc (a b c : mylist X) : (a + b) + c = a + (b + c) :=\nbegin\n  sorry\nend\n\n-- singleton list\ndef singleton (x : X) : mylist X := cons x nil\n\n@[simp] lemma singleton_def (x : X) : singleton x = cons x nil :=\nbegin\n  sorry\nend\n\n/-- The reverse of a list. -/\ndef reverse : mylist X → mylist X\n| nil := nil\n| (cons x m) := (reverse m) + (singleton x)\n\n-- surprisingly difficult question. Geometrically obvious, but so\n-- is a + b = b + a for naturals, and this takes some preliminary work.\n-- Don't just jump in! Prove things like `reverse_add` and even more basic things first\n-- (and consider tagging them with `@[simp]` if you want to train Lean's\n-- simplifier to do the work)\n\ntheorem reverse_reverse (l : mylist X) : reverse (reverse l) = l :=\nbegin\n  sorry,\nend\n\nend mylist\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/section11inductivetypes/sheet2mylist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.9005297847831081, "lm_q1q2_score": 0.7824043898195738}}
{"text": "import Mathlib.Data.Real.Basic\n\nvariable {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 s 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 :=  \nby \n/-\nIf you place your cursor anywhere within this comment \nthe Infoview should display:\n1 goal\nA : Type\nx : A\n⊢ A\n-/\nexact x\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 ∈ A` \n\nThe final line of the Infoview is our goal: `⊢ 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 bys with `by` and s with ``. 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 :=\nby\n/- \n1 goal\nA B C : Type\nx : A\ny : B\nz : C\n⊢ B\n-/\nexact y\n\n/-\nIf A and B are types,  then `A → 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 `→` is `\\to`.)  \n\nIf `f : A → 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 → B) (a : A) : B :=\nby\n/-\n1 goal\nA B : Type\nf : A → B\na : A\n⊢ B\n-/\n  exact f a -- Note that `exact f(a)` or `exact (f a)` or `exact (f(a))` will also work.\n\n\n-- A different way to achieve the same goal is to use the `apply` tactic\n-- 04\nexample (f : A → B) (a : A) : B :=\nby\n/-\n1 goal\nA B : Type\nf : A → B\na : A\n⊢ B\n-/\napply f \n/-\nNotice that our goal has changed from `⊢ B` to `⊢ A`. \n  \nThink of this as saying if we have a function `f: A → B`\nand our goal is `⊢ 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-/ \nexact a  -- since our goal is now `⊢ A` we can close it with `a` since this is a term of type `A`.\n\n-- 05\nexample  (f : A  → B) (g : B → C) (a : A) : C :=\nby\n-- goal `⊢ C`\n  apply g -- goal changes from `⊢ C` to `⊢ B` \n  apply f -- goal changes from `⊢ B` to `⊢ A`\n  exact a -- done!\n\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  → B) (g : B → C) (h : C → D) (a : A): D := \nby\n  apply h;  apply g;  apply f; exact a\n\n-- 07\nexample (f :A → B) (g: B → C) (h: D → E) (i : C → E) (x : A) : E:=\nby\n  sorry\n\n\n-- 08 Can you work out what `f: A → B → C` means and complete this example?\nexample (f : A → B → C)  (x : A) (y : B): C:=\nby\n  sorry\n\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 × B → C`    Comp Sci: `g : A → B → 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 → B → C` ? We need to know where the brackets should go.\n\nWe need to know whether  `A → B → C` is `A → (B → C)` or `(A → B) → C`\n\nLets see how we can use Lean's `#check`  command to work this out.  -/\n\n--variable (f : A → (B → C))\n--variable (g : (A → B) → C) \n--#check f  -- f : A → B → C    Lean has removed our unnecessary brackets from f.\n--#check g  -- g : (A → B) → C  The brackets in g are required!\n\n-- 09  What is f?\nexample (f : A → B → C → D) (g : A → B) (x : A)(z : C): D :=\nby\n  apply f; exact x; apply g;exact x;exact z\n\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 → A :=\nby\n/-\n1 goal\nA : Type\n⊢ A → A \n-/\n  intro x -- Now we have a `x : A`, a term x of type A and our goal is now `⊢ A`\n/-\n1 goal\nA : Type\nx : A\n⊢ A\n-/\n  exact x \n\n\n-- 11 \nexample (b : B) : A → B :=\nby\n  sorry\n\n\n-- 12 [Tip: Rather than `intro a, intro b` you can just use `intros a b`]\nexample (c : C) : A → B → C → A → B →  C → A :=\nby \n  sorry\n\n\n-- 13 \nexample (f : (A → B) → (C → D) → E) (b : B) (d : D) : E :=\nby\n  sorry\n\n\n-- 14   \nexample (f : (A → B → C) → D → (E → C) → B) (g : B → A → C) (h : (B → C) → D) (c : C): A → B:=\nby\n  sorry\n\n\n-- 15 Can you find a two line proof of this? (Hint: first find a longer proof and then shorten it)\nexample : ((A → D) → ((B → E) → (C → F))) → (((A → D) → (B → E)) → ((A → D) → (C → F))) :=\nby\n  intro f g ad c; apply f ad (g ad) c;\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/1_types_and_functions/functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.7823487521778626}}
{"text": "-- En los naturales: mcd(a,b) = a syss a divide a b\n-- ================================================\n\n-- Sean a y b son números naturales. Entonces, \n--    a ∣ b ↔ gcd a b = a\n\n-- Lemas auxiliares:\n-- + dvd_refl:      a ∣ a\n-- + dvd_antisymm : a ∣ b → b ∣ a → a = b \n-- + dvd_gcd_iff :  c ∣ gcd a b ↔ c ∣ a ∧ c ∣ b\n-- + gcd_dvd :      gcd a b ∣ a ∧ gcd a b ∣ b\n\nimport data.nat.gcd\n\nopen nat\n\nvariables (a b : ℕ)\n\n-- 1ª demostración\n-- ===============\n\nexample : a ∣ b ↔ gcd a b = a :=\nbegin\n  have h1 : gcd a b ∣ a ∧ gcd a b ∣ b,\n  { exact gcd_dvd a b, },\n  split,\n  { intro h2,\n    apply dvd_antisymm h1.left,\n    rw dvd_gcd_iff,\n    exact ⟨dvd_refl a, h2⟩, },\n  { intro h3,\n    rw ← h3,\n    exact h1.right, },\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : a ∣ b ↔ gcd a b = a :=\ngcd_eq_left_iff_dvd", "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/Caracterizacion_de_maximo_comun_divisor_igual_al_primer_numero_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214138, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7823461635172958}}
{"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 an earlier module while the third is in this one. \n\nHere we subtract natural numbers only when given a proof that the second is less than or equal to the first. Note that as any two terms whose type is the same proposition are equal by definition, the value will not depend on the specific proof.\n-/\n\nnamespace Nat\n\n/-- Subtract `m` and `n` in the presence of a proof that `n ≤ m`. -/\ndef minus (m n : ℕ)(hyp : n ≤ m) : ℕ := \n  match m, n, hyp with\n  | m, 0, _ => m\n  | 0, _ +1, pf => nomatch pf\n  | m + 1, n + 1 , pf =>\n    minus m n (le_of_succ_le_succ pf)\n\n/-!\nAn example using `minus` (using `decide` for the proof).\n\n```lean\n#eval minus 5 3 (by decide) -- 2\n```\n\n-/\n\n#eval minus 5 3 (by decide) -- 2\n\n\n/-- Subtraction (when valid) and addition are inverses\n-/\ntheorem minus_add_cancel \n  (m n : ℕ)(hyp : n ≤ m) : \n    minus m n hyp + n = m := by\n  match m, n, hyp with\n  | m, 0, _ => simp [minus]\n  | 0, _ +1, pf => contradiction\n  | m + 1, n + 1 , pf =>\n    simp [minus]\n    rw [← add_assoc]\n    simp [minus_add_cancel]\n    \n#check Nat.sub_add_cancel -- Nat.sub_add_cancel {n m : ℕ} (h : m ≤ n) : n - m + m = n\n\n/-!\nNote that in `Lean 4` there is a result `Nat.sub_add_cancel` which is analogous to `minus_add_cancel` above. However the statement of the result requires that the subtraction is valid.\n\n```lean\n#check Nat.sub_add_cancel -- Nat.sub_add_cancel {n m : ℕ} (h : m ≤ n) : n - m + m = n\n```\n-/\n    \n\nend Nat", "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_20/NatMinus.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7822507072861955}}
{"text": "import data.set.basic\nimport data.list.basic\nimport tactic\n\nopen set list\n\n-- Будем рассматривать языкы над алфавитом α\n-- Язык это просто set (list α)\nnamespace languages\n\nvariables {α : Type} {L M : set (list α)}\n\n\n-- Несколько удобных сокращений: ε = пустой список, 0 = ∅, 1 = {ε}, A + B = A ∪ B \ndef ε {α} : list α := [] \ninstance : has_zero (set (list α)) := ⟨(∅ : set _)⟩\ninstance : has_one (set (list α)) := ⟨({[]} : set _)⟩\ninstance : has_add (set (list α)) := ⟨set.union⟩\n\n-- Конкатенация языков состоит из таких слов `w`, что существуют слова `left ∈ L` и `right ∈ M`, что `w = left ++ right`)\ndef append (L M: set (list α)) := \n    { w : list α | ∃ (left ∈ L) (right ∈ M), w = left ++ right}\n\n-- Будем обозначать умножение как `L * M`\ninstance : has_mul (set (list α)) := ⟨append⟩\n\n-- И вспомогательные леммы\ndef zero_def : (0 : set (list α)) = ∅ := rfl\ndef one_def : (1 : set (list α)) = {[]} := rfl\n@[simp] def mem_zero {w : list α} : w ∉ (0 : set (list α)) := by simp\n@[simp] def mem_one {w : list α} : w ∈ (1 : set (list α)) ↔ w = [] := by refl\n@[simp] def nil_mem_one : [] ∈ (1 : set (list α)) := by simp\n\n\n-- Умелое использование `rcases` и `rintro` сильно вам поможет!\n@[simp] lemma zero_mul (L : set (list α)) : 0 * L = 0 :=\nbegin\n  sorry,\nend\n\n@[simp] lemma mul_zero (L : set (list α)) : L * 0 = 0 :=\nbegin\n  sorry,\nend\n\n@[simp] lemma append_one (A : set (list α)) : A * 1 = A :=\nbegin\n  apply subset.antisymm, {\n    sorry,\n  }, {\n    sorry,\n  },\nend\n\n@[simp] lemma one_append (A : set (list α)) : 1 * A = A :=\nbegin\n  sorry,\nend\n\nlemma append_assoc (A B C : set (list α)): \n    (A * B) * C = A * (B * C) :=\nbegin\n  sorry,\nend\n\nlemma left_distrib (A B C : set (list α)) : A * (B + C) = A * B + A * C :=\nbegin\n  sorry,\nend\n\nlemma right_distrib (A B C : set (list α)) : (A + B) * C = A * C + B * C :=\nbegin\n  sorry,\nend\n\n-- Докажем, что множество языков с операциями + = ∪ и * = append образуют полукольцо:\n-- A + B - коммутативный моноид: 0, ассоциативность, коммутативность\n-- A * B - полугруппа: 1, ассоциативность\n-- Дистрибутивность и умножение на 0\n-- Свойства (+) можно достать из стандартной библиотеки про `set.union`, а свойства (*) пришлось доказать\ninstance : semiring (set (list α)) := {\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-- Теперь можно использовать L^n = L * L * ... * L (n раз)\n-- Полезные леммы: `pow_zero`, `pow_succ`, `pow_add`, ...\n\nlemma append_subset_of_subset {A B C D : set (list α)} : A ⊆ C → B ⊆ D → A * B ⊆ C * D :=\nbegin\n  sorry,\nend\n\nlemma pow_subset_of_subset {A B : set (list α)} {n : ℕ} : A ⊆ B → A^n ⊆ B^n :=\nbegin\n  sorry,\nend\n\nlemma contain_eps_subset_power {A : set (list α)} {n : ℕ} (h : 1 ⊆ A) : A ⊆ A^(n.succ) :=\nbegin\n  sorry,\nend\n\n-- Замыкание Клини языка L равно объединению L^n по всем натуральным n\ndef star (L : set (list α)) := {w : list α | ∃ (n : ℕ), w ∈ L^n}\n\n@[simp] lemma mem_star {w : list α} : w ∈ star L ↔ ∃ (n : ℕ), w ∈ L^n := by refl\n\nlemma star_eq_Union : star L = ⋃ (n : ℕ), L^n :=\nbegin\n  ext w, simp only [mem_Union, mem_star],\nend\n\n@[simp] lemma nil_mem_star : [] ∈ star L :=\nbegin\n  sorry,\nend\n\n@[simp] lemma one_subset_star : 1 ⊆ star L :=\nbegin    \n  simp,\nend\n\n@[simp] lemma pow_subset_star (n : ℕ) : L^n ⊆ star L :=\nbegin\n  sorry,\nend\n\n@[simp] lemma subset_star : L ⊆ star L :=\nbegin\n  sorry,\nend\n\nlemma star_subset_star : L ⊆ M → star L ⊆ star M :=\nbegin\n  sorry,\nend\n\nlemma append_subset_star {A B L : set (list α)} : \n    A ⊆ star L → B ⊆ star L → (A * B) ⊆ star L :=\nbegin\n  sorry,\nend\n\nlemma star_append_star_eq_star : star L * star L = star L :=\nbegin\n  sorry,\nend \n\nlemma pow_star_eq_star (n : ℕ) : (star L)^n.succ = star L :=\nbegin\n  sorry,\nend\n\n-- Это было в ДЗ по дискретке!                \ntheorem star_star_eq_star : star (star L) = star L :=\nbegin\n  sorry,\nend\n\n-- L^n равен множеству слов, которые можно получить, как конкатенацию `n` слов из `L`. \n-- Как записать, что `w` представляется как конкатенация `n` слов из `L`?\n-- `∃ (l : list (list α)) (h : ∀ x ∈ l, x ∈ L), w = list.join l ∧ l.length = n`\n-- Буквально: существует список слов `l`, что все слова в `l` принадлежат `L`, `w` равен `list.join l`, и длина `l` равна `n`\n-- Начались сложные задания! Изучите подробнее API `list`, `list.has_mem`, `list.join` и прочие полезные вещи, или увереннее используйте `simp` :)\n#check list.mem\n#check mem_cons_self\n#check list.join\n#check join_eq_nil\n\nlemma pow_eq_list_join {n : ℕ} : \n    L^n = {w | ∃ (l : list (list α)) (h : ∀ x ∈ l, x ∈ L), w = list.join l ∧ l.length = n} :=\nbegin\n  sorry,\nend\n\nlemma mem_pow_iff_list_join {w : list α} {n : ℕ} \n  : w ∈ L^n ↔ ∃ l (h : ∀ x ∈ l, x ∈ L), w = list.join l ∧ l.length = n :=\nbegin\n  rw pow_eq_list_join,\n  refl,\nend\n\n-- Замыкание Клини - все слова, которые можно представить как конкатенацию слов из L (без ограничения на количество)\nlemma star_eq_list_join : \n  star L = {w | ∃ l (h : ∀ x, x ∈ l → x ∈ L), w = list.join l} :=\nbegin\n  sorry,\nend\n\nlemma mem_star_iff_list_join {w : list α} :\n  w ∈ star L ↔ ∃ l (h : ∀ x ∈ l, x ∈ L), w = list.join l :=\nbegin\n  rw star_eq_list_join,\n  refl,\nend\n\n-- Еще одно ДЗ из курса формальных языков\nlemma union_star_eq_star_mul_star_star : star (L + M) = star (star L * star M) :=\nbegin\n  sorry,\nend\n\nlemma mul_star_subset_star : L * star L ⊆ star L :=\nbegin\n  sorry,\nend\n\n-- Решаем уравнения в языках: если [] ∉ A, то L = A * L + B ↔ L = star A * b\nlemma linear_eq_iff {A B : set (list α)} (hnil : [] ∉ A) : L = A * L + B ↔ L = star A * B :=\nbegin\n  sorry,\nend\n\nend languages", "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/e01-languages.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8633916205190225, "lm_q1q2_score": 0.7822240191945857}}
{"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 combinatorics.simple_graph.basic -- definition of graph\n/-\n\n# Graph theory\n\nA year ago Lean's graph theory was a bit patchy, but now I think\nit's robust enough to be taken seriously as a topic for a final project.\n\nSo, how do graphs work in Lean? Actually it took a long time\nto come up with a definition people were happy with. One issue\nis that different people mean different things by \"graph\". In this\nsection we're going to stick to \"simple graphs\", which means\nthat you have a type of vertices `V`, and edges go between two\ndistinct vertices in `V`. The rules for a simple graph:\n\n1) Edges are undirected (so they don't have a source and a target, they\njust have two ends, which are vertices)\n2) You can't have more than one edge between two distinct vertices.\n3) You can't have an edge going from a vertex to itself.\n\nBecause of rule 2, you can represent an edge as a yes/no question:\n\"is there an edge between `v` and `w` or not?\". In other words\nyou can represent edges as a function `adj: V → V → Prop`, and you\ndon't need a separate set or type `E` for edges. `adj` is short\nfor \"adjacent\", so `adj v w` means \"there's an edge between `v` and `w`,\ni.e. \"`v` is adjacent to `w`\".\n\nRule 1 means that `adj` is symmetric (if `v` is adjacent to `w` then\n`w` is adjacent to `v`), and rule 3 means that it is irreflexive,\ni.e. `∀ v, ¬ adj v v`.\n\nHere's how to say \"let `G` be a (simple) graph with vertex set `V`\"\n\n-/\n\nvariables (V : Type) (G : simple_graph V)\n\n-- Here's how to say two edges are adjacent\n\nexample (v w : V) : Prop := G.adj v w\n\n-- If v is adjacent to w then w is adjacent to v\nexample (v w : V) : G.adj v w → G.adj w v := G.adj_symm\n\n-- v isn't adjacent to itself\nexample (v : V) : ¬ G.adj v v := G.irrefl\n\n/-\n\nLongish interlude: here's how to make a square graph. It's quite laborious. \nLean is better at proving theorems than making explicit examples!\n\nv1 -- v2\n|     |\n|     |\nv3 -- v4\n-/\n\nsection square_graph\n\n-- the vertex set of the square graph; we make it a type with four terms\ninductive sqV : Type\n| v1 : sqV\n| v2 : sqV\n| v3 : sqV\n| v4 : sqV\n\nopen sqV -- so I can write `v1` not `sqV.v1`\n\n-- here's one boring way of making the edges -- an inductive proposition\ninductive sqE : sqV → sqV → Prop\n| e12 : sqE v1 v2\n| e21 : sqE v2 v1\n| e24 : sqE v2 v4\n| e42 : sqE v4 v2\n| e34 : sqE v3 v4\n| e43 : sqE v4 v3\n| e13 : sqE v1 v3\n| e31 : sqE v3 v1\n\n-- Now let's make the graph\ndef sqG : simple_graph sqV :=\n{ adj := sqE,\n  symm := begin\n    -- do all the cases for the two vertices and the edge\n    rintro (_ | _ | _ | _) (_ | _ | _ | _) (_ | _ | _ | _ | _ | _ | _ | _),\n    -- now 8 goals; find the right constructor for sqE in all cases\n    repeat {constructor}, \n  end,\n  loopless := begin\n    rintro (_ | _ | _ | _) (_ | _ | _ | _ | _ | _ | _ | _),\n  end }\n\nend square_graph\n\n-- Here's how to make a triangle graph; it's rather easier\n\n-- Here `fin 3` is the \"canonical\" type with 3 terms; to give a term of type `fin 3`\n-- is to give a pair consisting of a natural `n` and a proof that `n < 3`.\n-- Here the `complete_graph` function is doing all the work for you.\nexample : simple_graph (fin 3) := complete_graph (fin 3)\n\n-- The collection of all simple graphs on a fixed vertex set `V` form a Boolean algebra\n-- (whatever that is)\nexample : boolean_algebra (simple_graph V) := by apply_instance\n\n-- and in particular they form a lattice, so you can do stuff like this:\n\nexample : simple_graph V := ⊥ -- empty graph\nexample : simple_graph V := ⊤ -- complete graph\nexample (G H : simple_graph V) : simple_graph V := G ⊔ H -- union of vertices\n-- etc etc, and you can even do this\nexample (G : simple_graph V) : simple_graph V := Gᶜ -- complement, i.e. an edge exists in `Gᶜ` between\n                                                    -- distinct vertices `v` and `w` iff it doesn't\n                                                    -- exist in `G`\n\n-- The *support* of a graph is the vertices that have an edge coming from them.\n\nexample (v : V) : v ∈ G.support ↔ ∃ w, G.adj v w := \nbegin\n  refl, -- true by definition\nend\n\n\n\n-- The `neighbor_set` of a vertex is all the vertices connected to it by an edge.\n\nexample (v : V) : set V := G.neighbor_set v\n\nexample (v w : V) : w ∈ G.neighbor_set v ↔ G.adj v w := iff.rfl -- true by defn\n\n-- The type `sym2 V` is the type of unordered pairs of elements of `V`, i.e. `V × V`\n-- modulo the equivalence relation generated by `(v,w)~(w,v)`.\n-- So you can regard the edges as a subset of `sym2 V`, and that's `G.edge_set`\n\nexample : set (sym2 V) := G.edge_set\n\n-- You can use `v ∈ e` notation if `e : sym2 v`\n-- For example, `G.incidence_set v` is the set of edges coming out of `v`,\n-- regarded as elements of `sym2 V`\n\nexample (v : V) : G.incidence_set v = {e ∈ G.edge_set | v ∈ e} := rfl\n\n-- You can delete a set of edges from `G` using `G.delete_edges`\n\nexample (E : set (sym2 V)) : simple_graph V := G.delete_edges E \n\n-- if E contains edges not in G then this doesn't matter, they're just ignored.\n\n-- You can push a graph forward along an injection\n\nexample (W : Type) (f : V ↪ W) : simple_graph W := G.map f \n\n-- and pull it back along an arbitrary map\n\nexample (U : Type) (g : U → V) : simple_graph U := G.comap g \n\n-- The degree of a vertex is the size of its neighbor_set.\n-- Better assume some finiteness conditions to make this work.\n\nvariable [G.locally_finite]\n\n-- now we have `finset` versions of some `set` things. For example\nexample (v : V) : G.degree v = finset.card (G.neighbor_finset v) := rfl \n\n-- If `H` is another graph on a vertex set `W` \nvariables (W : Type) (H : simple_graph W)\n\n-- then we can consider types of various maps between graphs\n\nexample : Type := G →g H -- maps f:V → W such that v₁~v₂ -> f(v₁)~f(v₂)\nexample : Type := G ↪g H -- injections f : V → W such that v₁~v₂ ↔ f(v₁)~f(v₂)\nexample : Type := G ≃g H -- isomorphisms of graphs", "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/section18graph_theory/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8633916047011595, "lm_q1q2_score": 0.782224002672189}}
{"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` (= `ℕ`): -/\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` (= `ℕ`):\n\n* \"No junk\" means that there are no special values, say, `–1` or `ε`, that\n  cannot be expressed using a finite combination of `zero` and `succ`.\n\n* \"No confusion\" is what ensures that `zero` ≠ `succ x`.\n\nIn addition, terms of inductive types are always finite. `succ (succ (succ …))` \nis not a value.\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    `∀k, P[k] → P[k + 1]`\n\nFor lists, the base case is\n\n    `P[[]]`\n\nand the induction step is\n\n    `∀y ys, P[ys] → 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 : ℕ) :\n  nat.succ n ≠ 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₂ (n : ℕ) :\n  nat.succ n ≠ 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 : ℕ → ℕ\n| 0       := 1\n| (n + 1) := (n + 1) * fact n\n\ndef fact₂ : ℕ → ℕ\n| 0       := 1\n| 1       := 1\n| (n + 1) := (n + 1) * fact₂ 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 : ℕ → ℕ\n| n := illegal n + 1\n\nconstant immoral : ℕ → ℕ\n\naxiom immoral_eq (n : ℕ) :\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₁_, …, _termM_ `with`\n    | _pattern₁₁_, …, _pattern₁M_ := _result₁_\n        ⋮\n    | _patternN₁_, …, _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 {α : Type} (p : α → bool) : list α → ℕ\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 : ℕ) : ℕ :=\nif a ≤ 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. -/\nstructure rgb :=\n(red green blue : ℕ)\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 : ℕ → ℕ → ℕ → rgb\n\ndef rgb.red : rgb → ℕ\n| (rgb.mk r _ _) := r\n\ndef rgb.green : rgb → ℕ\n| (rgb.mk _ g _) := g\n\ndef rgb.blue : rgb → ℕ\n| (rgb.mk _ _ b) := b\n\nend rgb_as_inductive\n\nstructure rgba extends rgb :=\n(alpha : ℕ)\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₂ (c : rgb) :\n  shuffle (shuffle (shuffle c)) = c :=\nmatch c with\n| rgb.mk _ _ _ := eq.refl _\nend\n\n\nstructure Group :=\n(carrier : Type)\n(zero : carrier)\n(add : carrier → carrier → carrier)\n(add_zero : ∀ x : carrier, add x zero = x)\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#check inhabited.default\n\n@[instance] def nat.inhabited : inhabited ℕ :=\n{ default := 0 }\n\n@[instance] def list.inhabited {α : Type} :\n  inhabited (list α) :=\n{ default := [] }\n\n#eval inhabited.default ℕ          -- result: 0\n#eval inhabited.default (list ℤ)   -- result: []\n\ndef head {α : Type} [inhabited α] : list α → α\n| []       := inhabited.default α\n| (x :: _) := x\n\nlemma head_head {α : Type} [inhabited α] (xs : list α) :\n  head [head xs] = head xs :=\nbegin\n  cases' xs,\n  { refl },\n  { refl }\nend\n\n#eval head ([] : list ℕ)   -- result: 0\n\n#check list.head\n\n@[instance] def fun.inhabited {α β : Type} [inhabited β] :\n  inhabited (α → β) :=\n{ default := λa : α, inhabited.default β }\n\ninductive empty : Type\n\n@[instance] def fun_empty.inhabited {β : Type} :\n  inhabited (empty → β) :=\n{ default := λa : empty, match a with end }\n\n@[instance] def prod.inhabited {α β : Type}\n    [inhabited α] [inhabited β] :\n  inhabited (α × β) :=\n{ default := (inhabited.default α, inhabited.default β) }\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 : ℕ)\n#check (1 : ℤ)\n#check (1 : ℝ)\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 {α : Type} (x y : α) (xs ys : list α)\n    (h : list.cons x xs = list.cons y ys) :\n  x = y ∧ 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 {α : Type} (y : α) (ys : list α)\n    (h : [] = y :: ys) :\n  false :=\nby cases' h\n\ndef map {α β : Type} (f : α → β) : list α → list β\n| []        := []\n| (x :: xs) := f x :: map xs\n\ndef map₂ {α β : Type} : (α → β) → list α → list β\n| _ []        := []\n| f (x :: xs) := f x :: map₂ f xs\n\n#check list.map\n\nlemma map_ident {α : Type} (xs : list α) :\n  map (λx, 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 {α β γ : Type} (f : α → β) (g : β → γ)\n    (xs : list α) :\n  map g (map f xs) = map (λx, 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 {α β : Type} (f : α → β) (xs ys : list α) :\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 {α : Type} : list α → list α\n| []        := []\n| (_ :: xs) := xs\n\n#check list.tail\n\ndef head_opt {α : Type} : list α → option α\n| []       := option.none\n| (x :: _) := option.some x\n\ndef head_pre {α : Type} : ∀xs : list α, xs ≠ [] → α\n| []       hxs := by cc\n| (x :: _) _   := x\n\n#eval head_opt [3, 1, 4]\n#eval head_pre [3, 1, 4] (by simp)\n-- fails\n#eval head_pre ([] : list ℕ) sorry\n\ndef zip {α β : Type} : list α → list β → list (α × β)\n| (x :: xs) (y :: ys) := (x, y) :: zip xs ys\n| []        _         := []\n| (_ :: _)  []        := []\n\n#check list.zip\n\ndef length {α : Type} : list α → ℕ\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 : ℕ) :\n  min (m + l) (n + l) = min m n + l :=\nbegin\n  cases' classical.em (m ≤ n),\n  case inl {\n    simp [min, h] },\n  case inr {\n    simp [min, h] }\nend\n\nlemma min_add_add₂ (l m n : ℕ) :\n  min (m + l) (n + l) = min m n + l :=\nmatch classical.em (m ≤ n) with\n| or.inl h := by simp [min, h]\n| or.inr h := by simp [min, h]\nend\n\nlemma min_add_add₃ (l m n : ℕ) :\n  min (m + l) (n + l) = min m n + l :=\nif h : m ≤ n then\n  by simp [min, h]\nelse\n  by simp [min, h]\n\nlemma length_zip {α β : Type} (xs : list α) (ys : list β) :\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 {α α' β β' : Type} (f : α → α') (g : β → β') :\n  ∀xs ys,\n    map (λab : α × β, (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 (α : Type) : Type\n| empty {} : btree\n| node     : α → btree → btree → 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 {α : Type} : btree α → btree α\n| btree.empty        := btree.empty\n| (btree.node a l r) := btree.node a (mirror r) (mirror l)\n\nlemma mirror_mirror {α : Type} (t : btree α) :\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₂ {α : Type} :\n  ∀t : btree α, 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₂ l\n  ... = btree.node a l r :\n    by rw mirror_mirror₂ r\n\nlemma mirror_eq_empty_iff {α : Type} :\n  ∀t : btree α, mirror t = btree.empty ↔ 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 (α : Type) : ℕ → Type\n| nil {}                           : vec 0\n| cons (a : α) {n : ℕ} (v : vec n) : vec (n + 1)\n\n#check vec.nil\n#check vec.cons\n\ndef list_of_vec {α : Type} : ∀{n : ℕ}, vec α n → list α\n| _ vec.nil        := []\n| _ (vec.cons a v) := a :: list_of_vec v\n\ndef vec_of_list {α : Type} :\n  ∀xs : list α, vec α (list.length xs)\n| []        := vec.nil\n| (x :: xs) := vec.cons x (vec_of_list xs)\n\nlemma length_list_of_vec {α : Type} :\n  ∀{n : ℕ} (v : vec α 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": "BrownCS1951x", "repo": "fpv2021", "sha": "10bdbd92e64fb34115b68794b8ff480468f4dcaa", "save_path": "github-repos/lean/BrownCS1951x-fpv2021", "path": "github-repos/lean/BrownCS1951x-fpv2021/fpv2021-10bdbd92e64fb34115b68794b8ff480468f4dcaa/src/lectures/love04_functional_programming_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.7822240014736682}}
{"text": "import MyNat\nimport MyNat.addition_world\n\nopen MyNat\n\nlemma succ_inj (a b : ℕ) : succ a = succ b → a = b := by\n  intro h\n  cases h\n  rfl\n  \nlemma zero_ne_succ (a : ℕ) : zero ≠ succ a := by\n  intro h\n  cases h\n\ntheorem succ_succ_inj (a b : ℕ) (h : succ (succ a) = succ (succ b)) : a = b := by\n  apply succ_inj\n  apply succ_inj\n  exact h\n\ntheorem succ_eq_succ_of_eq (a b : ℕ) : \n  a = b → succ a = succ b := by\n  intro h\n  rewrite [h]\n  rfl\n\ntheorem succ_eq_succ_iff (c d : ℕ) :\n  succ c = succ d ↔ c = d := by\n  constructor \n  exact succ_inj c d\n  exact succ_eq_succ_of_eq c d\n\ntheorem add_right_cancel (a t b : ℕ) :\n  a + t = b + t → a = b := by\n  intro h\n  induction t with \n  | zero => \n    rewrite [add_zero, add_zero] at h\n    exact h\n  | succ t' ih => \n    rewrite [add_succ, add_succ] at h\n    let h' := (succ_inj (a + t') (b + t') h)\n    apply (ih h')\n\ntheorem add_left_cancel (t a b : ℕ) :\n  t + a = t + b → a = b := by\n  rewrite [add_comm, add_comm t b]\n  exact add_right_cancel a t b\n\ntheorem add_right_cancel_iff (t a b : ℕ) :\n  a + t = b + t ↔ a = b := by\n  constructor \n  exact add_right_cancel _ _ _\n  intro h\n  rewrite [h]\n  rfl\n\nlemma eq_zero_of_add_right_eq_self (a b : ℕ) :\n  a + b = a → b = 0 := by\n  rewrite [←add_zero a, add_assoc, zero_add]\n  intro h\n  exact add_left_cancel _ _ _ h\n\ntheorem succ_ne_zero (a : ℕ) : succ a ≠ 0 := by\n  intro h\n  exact zero_ne_succ a h.symm\n\nlemma add_left_eq_zero \n  (a b : ℕ) (H : a + b = 0) : b = 0 := by\n  cases b with \n  | zero => rfl\n  | succ b' => \n    rewrite [add_succ] at H\n    exact False.elim (succ_ne_zero (a + b') H)\n\nlemma add_right_eq_zero (a b : ℕ) : \n  a + b = 0 → a = 0 := by\n  rewrite [add_comm]\n  exact add_left_eq_zero _ _\n\nlemma add_one_eq_succ (d : ℕ) : d + 1 = succ d := by\n  apply Eq.symm _\n  exact succ_eq_add_one _\n\nlemma ne_succ_self (n : ℕ) : n ≠ succ n := by\n  rewrite [succ_eq_add_one, ←add_zero n, add_assoc, zero_add]\n  intro h\n  let f := add_left_cancel _ _ _ h\n  rewrite [one_eq_succ_zero] at f\n  exact zero_ne_succ zero f\n  ", "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_addition_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7822140656899434}}
{"text": "import analysis.real tactic.norm_num algebra.group_power\n\ntheorem Q5a1 (S : set ℝ) : (∃ x : ℝ, x ∈ lower_bounds S) \n    ↔ (∃ y : ℝ, y ∈ upper_bounds {t : ℝ | ∃ s ∈ S, t = -s }) := sorry\n\ntheorem Q5a2 (S : set ℝ) (x : ℝ) : is_glb S x ↔ \n    is_lub {t : ℝ | ∃ s ∈ S, t = -s} (-x) := sorry\n\nlemma Q5bhelper (S : set ℝ) (x₁ x₂ : ℝ) : is_glb S x₁ ∧ is_glb S x₂ → x₁ ≤ x₂ :=\nbegin\nintro H,\nhave Hglb1 := H.left,\nhave Hlb1 := Hglb1.left,\nhave Hglb2 := H.right,\nhave H1 := Hglb2.right,\nexact H1 _ Hlb1,\nend\n\ntheorem Q5b (S : set ℝ) (x₁ x₂ : ℝ) : is_glb S x₁ ∧ is_glb S x₂ → x₁ = x₂ := sorry\n\ntheorem Q5c :  (∀ S : set ℝ, (∃ w : ℝ, w ∈ S) → (∃ x : ℝ, x ∈ upper_bounds S) → ∃ y : ℝ, is_lub S y) \n   →   (∀ T : set ℝ, (∃ w₁ : ℝ, w₁ ∈ T) → (∃ x₁ : ℝ, x₁ ∈ lower_bounds T) → ∃ y₁ : ℝ, is_glb T y₁) := sorry\n\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/PB0605/Q0605.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7821807077953808}}
{"text": "import automata.dfa\nimport data.list.basic\nimport regular.regex\nimport regular.list_lemmas\nimport regular.pumping_lemma \n\nopen DFA list pumping\n\ndef L0ⁿ1ⁿ := {w | ∃ n, w = (repeat bool.ff n) ++ (repeat bool.tt n)}\n\n@[simp] lemma mem_L0ⁿ1ⁿ_iff {w} : w ∈ L0ⁿ1ⁿ ↔ ∃ n, w = (repeat bool.ff n) ++ (repeat bool.tt n) := \n  iff.rfl\n\ntheorem not_regular_0ⁿ1ⁿ : ¬dfa_lang L0ⁿ1ⁿ :=\nbegin\n    apply pumping_lemma_negation,\n    intro n,\n    use [(repeat bool.ff n) ++ (repeat bool.tt n), n],\n    simp only [not_exists, true_and, length_repeat, zero_le, le_add_iff_nonneg_left, mem_L0ⁿ1ⁿ_iff,\n  length_append],\n    rintro x y z hxyz ynil hpref,\n    use 0,\n    simp only [join, repeat, append_nil],\n    rintro l hl,\n    rw [← length_repeat ff n, ← length_append] at hpref,\n    have tt_n_suffix := suffix_of_append_eq_append hpref hxyz,\n    have tt_eq_ff := repeat_suffix_of_append_repeat _ (is_suffix.trans tt_n_suffix ⟨x, hl⟩),\n    contradiction,\n    apply_fun length at hxyz hl,\n    simp only [length_repeat, length_append] at hpref hl hxyz,\n    rw [← length_pos_iff_ne_nil] at ynil,\n    linarith,\nend\n\n", "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/nonregular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9566342049451595, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7821197068908847}}
{"text": "import data.nat.basic\n\ndef is_even (a : nat) := ∃ b, a = 2 * b\n\ntheorem even_plus_even {a b : nat}\n  (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n  exists.elim h1 (assume w1, assume hw1 : a = 2 * w1,\n  exists.elim h2 (assume w2, assume hw2 : b = 2 * w2,\n    exists.intro (w1 + w2)\n      (calc\n        a + b = 2 * w1 + 2 * w2 : by rw [hw1, hw2]\n        ...   = 2 * (w1 + w2)   : by rw mul_add)))\n\ntheorem even_plus_even' {a b : nat}\n  (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\nmatch h1, h2 with\n  ⟨ w1, hw1⟩, ⟨ w2, hw2⟩ := ⟨ w1 + w2, by rw [hw1, hw2, mul_add]⟩\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/03-Propositions-and-Proofs/example-4.4-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9621075766298657, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7820658031055405}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que en un orden parcial\n--     a < b ↔ a ≤ b ∧ a ≠ b\n-- ----------------------------------------------------------------------\n\nimport tactic\n\nvariables {α : Type*} [partial_order α]\nvariables a b : α\n\nexample : a < b ↔ a ≤ b ∧ a ≠ b :=\nbegin\n  rw lt_iff_le_not_le,\n  split,\n    rintros ⟨h1, h2⟩,\n      split,\n        exact h1,\n        contrapose ! h2,\n        rw h2,\n    rintros ⟨h3, h4⟩,\n      split,\n        exact h3,\n        contrapose ! h4,\n        apply le_antisymm h3 h4,\nend\n\n-- Prueba\n-- ======\n\n/-α : Type u_1,\n_inst_1 : partial_order α,\na b : α\n⊢ a < b ↔ a ≤ b ∧ a ≠ b\n  >> rw lt_iff_le_not_le,\n⊢ a ≤ b ∧ ¬b ≤ a ↔ a ≤ b ∧ a ≠ b\n  >> split,\n| ⊢ a ≤ b ∧ ¬b ≤ a → a ≤ b ∧ a ≠ b\n|   >>   rintros ⟨h1, h2⟩,\n| h1 : a ≤ b,\n| h2 : ¬b ≤ a\n|   >>     split,\n| ⊢ a ≤ b ∧ a ≠ b\n| | ⊢ a ≤ b\n|   >>       exact h1,\n| ⊢ a ≠ b\n|   >>       contrapose ! h2,\n| h2 : a = b\n| ⊢ b ≤ a\n|   >>       rw h2,\nα : Type u_1,\n_inst_1 : partial_order α,\na b : α\n⊢ a ≤ b ∧ a ≠ b → a ≤ b ∧ ¬b ≤ a\n  >>   rintros ⟨h3, h4⟩,\nh3 : a ≤ b,\nh4 : a ≠ b\n⊢ a ≤ b ∧ ¬b ≤ a\n  >>     split,\n| ⊢ a ≤ b\n|   >>       exact h3,\n⊢ ¬b ≤ a\n  >>       contrapose ! h4,\nh4 : b ≤ a\n⊢ a = b\n  >>       apply le_antisymm h3 h4,\nno goals\n-/\n\n-- Comentario: Los lemas usados son\n-- + lt_iff_le_not_le : a < b ↔ a ≤ b ∧ ¬b ≤ a\n-- + le_antisymm : a ≤ b → b ≤ a → a = 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/Logica/Caracterizacion_de_menor_en_ordenes_parciales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.7819974791326986}}
{"text": "import MyNat.Addition\nnamespace MyNat\nopen MyNat\n/-!\n\n# Tutorial world\n\n## Level 4: addition\n\nWe have a new import -- the definition of addition.\n\nPeano defined addition `a + b` by induction on `b`, or, more precisely, by recursion on `b`. He first\nexplained how to add 0 to a number: this is the base case.\n\n- `add_zero (a : MyNat) : a + 0 = a`\n\nWe will call this theorem `add_zero`. More precisely, `add_zero` is the name of the _proof_ of the\ntheorem. Note the name of this proof. Mathematicians sometimes call it \"Lemma 2.1\" or \"Hypothesis\nP6\" or something. But computer scientists call it `add_zero` because it tells you what the answer to\n\"x add zero\" is. It's a much better name than \"Lemma 2.1\". Even better, you can use the `rewrite` tactic\nwith `add_zero`. If you ever see `x + 0` in your goal, `rewrite [add_zero]` should simplify it to `x`. This is\nbecause `add_zero` is a proof that `x + 0 = x` (more precisely, `add_zero x` is a proof that `x + 0 = x` but\nLean can figure out the `x` from the context).\n\nNow here's the inductive step. If you know how to add `d` to `a`, then Peano tells you how to add\n`succ d` to `a`. It looks like this:\n\n- `add_succ (a d : MyNat) : a + (succ d) = succ (a + d)`\n\nWhat's going on here is that we assume `a + d` is already defined, and we define `a + (succ d)` to\nbe the number after it. Note the name of this proof too -- `add_succ` tells you how to add a successor\nto something. If you ever see `... + succ ...` in your goal, you should be able to use `rewrite [add_succ]`, to\nmake progress.\n\n**Lemma**`\n\nFor all natural numbers `a`, we have `a + (succ 0`) = succ a`.\n-/\nlemma add_succ_zero (a : MyNat) : a + (succ 0) = succ a := by\n  rewrite [add_succ]\n  rewrite [add_zero]\n  rfl\n\n/-!\nDo you see that the goal at the end of the first `rewrite` now mentions `... + 0 ...`? So this\nmatches the `add_zero` theorem so you can now add the `rewrite [add_zero]`.\n\nAfter the `rfl` the proof is now complete: \"Goals accomplished 🎉\".\nNote that because `rewrite` takes a list, you can also write the above two lines in one\nusing `rewrite [add_succ, add_zero]`.\n\nAnd remember `rw` also does `rfl`, you can replace the whole proof with `rw [add_succ, add_zero]`.\n\n### Examining proofs.\n\nYou might want to review this proof now; at three lines long it is your current record.\nDon't worry there are much longer proofs, in fact, the\n[Liquid Tensor Experiment](https://xenaproject.wordpress.com/2022/09/12/beyond-the-liquid-tensor-experiment/)\ncontains 90,000 lines of Lean proofs! For this reason Lean is a real programming language\nwith support for abstraction and extension so that you can get as much reusability as\npossible in your Lean code.\n\nThe easiest way to see how the proof goal state progresses is to place your cursor at the\nbeginning of each line using the Up/Down arrow key to move down the proof and see the effect\nof the previous line on the goal shown in the InfoView.\n\n### Next\n\nYou have finished tutorial world! When you're happy, please move onto [Addition\nWorld](../AdditionWorld.lean.md), and learn about proof by induction.\n\n### Troubleshooting\n\n**Question**: why has the InfoView gone blank?\n\n**Answer**: try placing the cursor at different places in the file, the InfoView shows the\ncontext at the cursor location.  If the InfoView is not updating at all no matter what you\ndo then there might be a problem with your VS Code setup.\nSee the [Quick\nStart](https://leanprover.github.io/lean4/doc/quickstart.html) for more information.\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/TutorialWorld/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.901920681802153, "lm_q2_score": 0.8670357546485408, "lm_q1q2_score": 0.7819974789794562}}
{"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.finsupp_vector_space\n\n/-!\n\n# Rank of free modules\n\nThis is a basic API for the rank of free modules.\n\n-/\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\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]\nvariables [add_comm_group N] [module R N] [module.free R N]\n\n/-- The rank of a free module `M` over `R` is the cardinality of `choose_basis_index R M`. -/\nlemma rank_eq_card_choose_basis_index : module.rank R M = #(choose_basis_index R M) :=\n(choose_basis R M).mk_eq_dim''.symm\n\n/-- The rank of `(ι →₀ R)` is `(# ι).lift`. -/\n@[simp] lemma rank_finsupp {ι : Type v} : module.rank R (ι →₀ R) = (# ι).lift :=\nby simpa [lift_id', lift_umax] using\n  (basis.of_repr (linear_equiv.refl _ (ι →₀ R))).mk_eq_dim.symm\n\n/-- If `R` and `ι` lie in the same universe, the rank of `(ι →₀ R)` is `# ι`. -/\nlemma rank_finsupp' {ι : Type u} : module.rank R (ι →₀ R) = # ι := by simp\n\n/-- The rank of `M × N` is `(module.rank R M).lift + (module.rank R N).lift`. -/\n@[simp] lemma rank_prod :\n  module.rank R (M × N) = lift.{w v} (module.rank R M) + lift.{v w} (module.rank R N) :=\nby simpa [rank_eq_card_choose_basis_index R M, rank_eq_card_choose_basis_index R N,\n  lift_umax, lift_umax'] using ((choose_basis R M).prod (choose_basis R N)).mk_eq_dim.symm\n\n/-- If `M` and `N` lie in the same universe, the rank of `M × N` is\n  `(module.rank R M) + (module.rank R N)`. -/\nlemma rank_prod' (N : Type v) [add_comm_group N] [module R N] [module.free R N] :\n  module.rank R (M × N) = (module.rank R M) + (module.rank R N) := by simp\n\n/-- The rank of the direct sum is the sum of the ranks. -/\n@[simp] lemma rank_direct_sum  {ι : Type v} (M : ι → Type w) [Π (i : ι), add_comm_group (M i)]\n  [Π (i : ι), module R (M i)] [Π (i : ι), module.free R (M i)] :\n  module.rank R (⨁ i, M i) = cardinal.sum (λ i, module.rank R (M i)) :=\nbegin\n  let B := λ i, choose_basis R (M i),\n  let b : basis _ R (⨁ i, M i) := dfinsupp.basis (λ i, B i),\n  simp [← b.mk_eq_dim'', λ i, (B i).mk_eq_dim''],\nend\n\n/-- The rank of a finite product is the sum of the ranks. -/\n@[simp] lemma rank_pi_finite {ι : Type v} [finite ι] {M : ι → Type w}\n  [Π (i : ι), add_comm_group (M i)] [Π (i : ι), module R (M i)] [Π (i : ι), module.free R (M i)] :\n  module.rank R (Π i, M i) = cardinal.sum (λ i, module.rank R (M i)) :=\nby { casesI nonempty_fintype ι,\n  rw [←(direct_sum.linear_equiv_fun_on_fintype _ _ M).dim_eq, rank_direct_sum] }\n\n/-- If `m` and `n` are `fintype`, the rank of `m × n` matrices is `(# m).lift * (# n).lift`. -/\n@[simp] lemma rank_matrix (m : Type v) (n : Type w) [finite m] [finite n] :\n  module.rank R (matrix m n R) = (lift.{(max v w u) v} (# m)) * (lift.{(max v w u) w} (# n)) :=\nbegin\n  casesI nonempty_fintype m,\n  casesI nonempty_fintype n,\n  have h := (matrix.std_basis R m n).mk_eq_dim,\n  rw [← lift_lift.{(max v w u) (max v w)}, lift_inj] at h,\n  simpa using h.symm,\nend\n\n/-- If `m` and `n` are `fintype` that lie in the same universe, the rank of `m × n` matrices is\n  `(# n * # m).lift`. -/\n@[simp] lemma rank_matrix' (m n : Type v) [finite m] [finite n] :\n  module.rank R (matrix m n R) =  (# m * # n).lift :=\nby rw [rank_matrix, lift_mul, lift_umax]\n\n/-- If `m` and `n` are `fintype` that lie in the same universe as `R`, the rank of `m × n` matrices\n  is `# m * # n`. -/\n@[simp] lemma rank_matrix'' (m n : Type u) [finite m] [finite n] :\n  module.rank R (matrix m n R) =  # m * # n := by simp\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]\nvariables [add_comm_group N] [module R N] [module.free R N]\n\n/-- The rank of `M ⊗[R] N` is `(module.rank R M).lift * (module.rank R N).lift`. -/\n@[simp] lemma rank_tensor_product : module.rank R (M ⊗[R] N) = lift.{w v} (module.rank R M) *\n  lift.{v w} (module.rank R N) :=\nbegin\n  let ιM := choose_basis_index R M,\n  let ιN := choose_basis_index R N,\n\n  have h₁ := linear_equiv.lift_dim_eq (tensor_product.congr (repr R M) (repr R N)),\n  let b : basis (ιM × ιN) R (_ →₀ R) := finsupp.basis_single_one,\n  rw [linear_equiv.dim_eq (finsupp_tensor_finsupp' R ιM ιN), ← b.mk_eq_dim, mk_prod] at h₁,\n  rw [lift_inj.1 h₁, rank_eq_card_choose_basis_index R M, rank_eq_card_choose_basis_index R N],\nend\n\n/-- If `M` and `N` lie in the same universe, the rank of `M ⊗[R] N` is\n  `(module.rank R M) * (module.rank R N)`. -/\nlemma rank_tensor_product' (N : Type v) [add_comm_group N] [module R N] [module.free R N] :\n  module.rank R (M ⊗[R] N) = (module.rank R M) * (module.rank R N) := by simp\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/rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7819710948175757}}
{"text": "import ..lectures.love02_backward_proofs_demo\n\n\n/-! # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nsorry\n\nlemma K (a b : Prop) :\n  a → b → b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nsorry\n\n/-! Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nsorry\n\n/-! 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nsorry\n\n/-! 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nsorry\n\n\n/-! ## Question 2: Natural Numbers\n\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nsorry\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nsorry\n\n/-! 2.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nsorry\n\n/-! 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nsorry\n\n\n/-! ## Question 3 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle : Prop :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce : Prop :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation : Prop :=\n∀a : Prop, (¬¬ a) → a\n\n/-! For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, as this would defeat the purpose of the exercise.\n\n3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nsorry\n\n/-! 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nsorry\n\n/-! We leave the remaining implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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/exercises/love02_backward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7818425368664514}}
{"text": "/-\nIn this class, we introduce conjunction,\n∧ (and), as connective that combines any\ntwo propositions into a larger one; and\nwe show how we define the introduction and\nelimination rules for this connective *so\nthat* it behaves in Lean as it behaves in\npredicate logic: to prove P ∧ Q we need to\nprovide proofs of P and of Q, respectively\n(the introduction rule), and given a proof\nof P ∧ Q, we can *use* it to obtain a proof\nof P, and a proof of Q (the left and right\nelimination rules for ∧). \n\nOnce we've defined these rules as \"axioms\" \nthen we can use them to prove new theorems\nabout the properties of the ∧ connective:\nthat it's *commutative* and *associative*.\n\nThat's our agenda.\n-/\n\n/-\nTHE AXIOMS (INTRO & ELIM RULES) FOR ∧.\n-/\n\n/-\nTo get started, let assume that P and Q \nare arbitrary propositions. We'll use the\n\"axiom\" keyword in Lean, which introduces\nassumptions into the current environment,\nwhich is here the \"global\" environment of\nthis file.\n-/\naxioms P Q : Prop\n\n/- The syntax of predicate logic dictates that if\nP and Q are propositions, then P ∧ Q is one as well. \nFor this reason we use the term \"connective\" for \nlogical symbols such as ∧, in that they \"connect\"\ngive propositions (P, Q) into larger propositions\n(here, P ∧ Q). \n\nGiven thatwe propositions are types in the logic of\nLean, you can also say that ∧ is a \"type builder:\"\nit takes two types as arguments (P, Q) and returns \na new, type, P ∧ Q, as a result. What is the type of\nP ∧ Q? Try to answer yourself before leaning on the\nproof assistant (ha ha) to tell you.\n-/\n#check P ∧ Q\n\n/- \n∧ is just an infix notation for \"and\", with the\ncorrect precendence to work together correctly \nwith the other logical connectives Lean defines,\nand with *right* associativity. That means that\nLean will parse P ∧ Q ∧ R as P ∧ (Q ∧ R), not as\n(P ∧ Q) ∧ R.\n-/\n#check and P Q\n\n/-\n∧ is a logical \"connective.\" That means\nit \"connects\" (a better word is \"composes\")\ntwo propositions into a larger proposition. \nGiven the propositions are types in Lean, \n∧ is a *polymorphic type building function \nthat takes two propositions (types) as its\narguments and yields a proposition (type)\nas a result. \n\nWhat, then, is the type of \"and,\"\" viewed \nas a function? Try hard to answer yourself\nbefore using Lean to get the answer for you.\n-/\n#check @and \n\n/-\nRight. ∧ takes two propositions, P and Q, \nand gives us back a new proposition, P ∧ Q,\n(which \"desugars\" to \"and P Q\").\n-/\n\n/-\nWhat we are going to see now is that ∧ is\nimplemented in Lean as a polymorphic type.\nIt's implemented as an inductive type that\ntakes two propositions (types!) as arguments.\nThese type arguments are the propositions to \nbe connected.  \n\nThe constructor for this type then defines \nthe introduction rule (a way to build proof \nobjects) for this new type. \n\nFinally, the elimination rules allow us to \nuse a proof of P ∧ Q to derive proofs of P\nand of Q. We'll see later in this file how\nto implement these logical rules, again as\nfunctions, in Lean. \n-/\n\n/-\nFirst, though, we want to see exactly where\nthe and.intro rule comes from. Here's Lean's \ndefinition of and (∧). What you can see is \nthat and.intro is just a constructor of data\nvalues (proofs!) of *type* (and a b), where \na and b are themselves propositions.\n\nstructure and (a b : Prop) : Prop :=\nintro :: (left : a) (right : b)\n\nConstructors are introduction rules! Indeed,\nif you look back at the eq polymorphic type,\nyou will be reminded that eq.refl is just a\n(the only) constructor for building terms of\ntype (@eq α a b), the shorthand notation for\nwhich is a = b. Constructors are introduction\n\"axioms\" for their types.\n-/\n\n/-\nWe now use this example to explore a number\nof core concepts in the Lean language. First,\nand hew here, is the use of \"structure\"  as a\nkeywork. It can be used in place of inductive \nwhen a type has just exactly one constructor.\nThe main benefit of using \"structure\" is that\nit tells Lean to *synthesize* functions with\nthe same names as the fields for *accessing*\nthe field values in any instances of the type.\n\nIt allows the argument names, left and right, \nin this case, to be used as names of functions\nto \"access\" the field values of an object of \ntype P ∧ Q. So, if you have an object, pf, of \ntype P ∧ Q , then (and.left pf) and (and.right \npf) give you proofs of P and of Q. For these\nfunction calls you can also use the notation,\npf.left and pf.right. These functions are, of\ncourse, the two elimination rules for and! \n-/\n\n/-\nIn sum, the \"intro\" constructor for ∧ \nimplements the introduction rule for ∧,\nwhile the Lean-provided accessor functions,\nleft and right, implement the elimination\nrules for ∧: left and right, respectively. \n-/\n\n/-\nWith these \"rules\" in hand, we can now\nconstruct proofs of theorems about the\n*and* operator, just as we did for eq\n(proving symmetry and transitivity) once\nwe had the intro (refl) and elim (subst)\nrules for equality.  \n-/\n\n/-\nTo illustrate, beyond assuming that P and \nQ are propositions (above), we'll now also\nassume that we have proofs of P and of Q. \nRemember that the propositions P and Q are \n*types*. What we want now are values of \nthese types, which we now understand are\nproofs. Heres how we assume \"axiomatically\" \nthat p and q are proofs of P and of Q.respectively.\n-/\naxioms (p : P) (q : Q)\n\n/-\nGiven that we're now in a (global) context\nin which we have assumed P and Q are in Prop\nand that p and q are proofs of P and of Q,  \nwe can now claim that there must be a proof\nof P ∧ Q --- that P ∧ Q is true. Now we can\nproduce a proof to show that it is true. \n-/\nexample : P ∧ Q := and.intro p q\n\n/-\nYay. That's how we use the introduction \nrule for ∧ to prove propositions of the\nform P ∧ Q (conjunctions).\n-/\n\n/-\nHere's the equivalent formulation using \nordinary function definition notation. We\ndefine func (a name we're just making \nup) to be a function that takes P, Q, p, \nand q as arguments and returns a proof of \nP ∧ Q.\n-/\ndef func \n  (P Q : Prop) \n  (p : P) \n  (q : Q) : \n  P ∧ Q :=\nand.intro p q\n\n/-\nWe can also write our own functions that mimic\nthe elimination rules for and (by \"wrapping\" \nthem in an added layer of abstraction)\n-/\ndef and_elim_left \n  (P Q : Prop) \n  (pq : P ∧ Q) : \n  P \n  :=\nand.elim_left pq\n\n/- \nHomework #1: Define an analogous function,\nand_elim_right.\n-/ \n\n-- Here.\n\n/-\nFrom a proof of P ∧ Q we can derive a proof \nof P, and we can derive a proof of Q, using \nthe elimination rules for ∧:\n-/\n\n#check @and.elim_left\n#check @and.left \n#check @and.elim_right\n#check @and.right\n\n\n/-\nMental exercise: To what values do the following\nexpressions evaluate/reduce?\n\nand.elim_left (and.intro p q)\nand.elim_right (and.intro p q)\n-/\n#reduce and.elim_left (and.intro p q)\n#reduce and.elim_right (and.intro p q)\n\n/-\nand.left : ∀ {a b : Prop}, a ∧ b → a\nand.right : ∀ {a b : Prop}, a ∧ b → b\n\nConceptually, each elimination rules takes\na pair and returns either the first or the\nsecond of its two fields. They are what we \ncan call \"projection functions.\"\n-/\n\n/-\nTHEOREM CONCERNING ∧ \n-/\n\n/-\nWe now have the basic *axioms* for\ncreating and using proofs of *conjunctions*\n(propositions built using ∧). With them we\ncan state and prove new *theorems* about the\nbehavior of the ∧ connective. For example,\nwe can now prove (almost) that it's both\n\"commutative\" and \"associative.\"\n-/\n\n/-\nExample 1: From a proof of P ∧ Q we can\nconstruct/derive a proof of Q ∧ P. \n-/\ntheorem and_commutes \n  (P Q : Prop) (pq : P ∧ Q) : Q ∧ P :=\n  and.intro \n    (and.right pq)\n    (and.left pq)\n\n/-\nThe idea here is pretty simple. A proof of\nP ∧ Q is of the form (and.intro p q), which\nyou can think of as a labelled order pair of\nproofs. (The label is and.intro.) Given such\na proof, we use our elimination functions,\nleft and right, to extract p and q, then we\nuse and.intro to put them together again, in\nthe opposite order, to construct a proof,\n(and.intro q p), of Q ∧ P. \n\nHere's another version of our proof. We use\nexample to avoid giving it a name. We specify\nthe same arguments (before the colon) and the\nsame return type (just after the colon). We\nthen write the \"implementation\" (after the :=)\nusing both angle-bracket and dot notation for\nfield access. What's new here is the use of \n⟨...⟩ notation. It can be used whenever you\nare creating a value of structure (a type\nwith just one constructor and zero or more\narguments). This angle bracket notation calls\nthe single constructor with its arguments in\nthe comma separated list inside the angle\nbracket pair. Note that you have to type a\nbackslash before a less-than or greater-than\nkeyboard character to get these special angle\nbrackets.\n-/\n\nexample (P Q : Prop) (pq : P ∧ Q) : Q ∧ P :=\n  ⟨ pq.right, pq.left ⟩ \n\n/-\nAt this point, we've now seen the introduction\nand elimination \"rules\" for both = and ∧. The \nintroduction rules are eq.refl and and.intro,\nwhile the elimination rules are eq.subst, and\nand.left and and.right (aka and.elim_left and\nand.elim_right).\n\n/-\nSeeing the introduction and elimination\nrules for ∀ and →.\n-/\n\nWe've also seen, implicitly, the introduction\nand elimination rules for ∀ and →. The intro\nrule says \"assume the argument/premise and, in\nthat context, show that you can construct and\n\"return\" a proof of the conclusion/return type.\n\nTo prove P → Q, assume you're given a proof of \nP and in that context show that you can have a\nproof of Q. That proves P → Q. Similarly, to\nprove ∀ (p : P), Q, assume that you're given\nan arbitrary proof/value of P and show that\nin that context you can construct a proof/value\nof type Q.\n\nIn Lean these connectives, ∀ and →, are in fact\nessentially just notations for the same idea! To\nsee that this is the case, look at how Lean prints \nthe proposition, ∀ (p : P), Q. It's just P → Q! \n(Recall again that we defined P and Q above.)\n-/\n\n#check ∀ (p : P), Q\n\n/-\nHomework #2: NFormally state and prove the \nproposition that \"∧ is associative.\" \n\nOkay, any logic text or web page will tell you\nthat this statement, \"∧ is associative\", means\nthat for any three propositions, P, Q, and R,\nif (P ∧ Q) ∧ R is true then P ∧ (Q ∧ R) is too,\nand vice versa! We will just state and prove \nthe first of these.  \n-/\n\n-- theorem and_assoc (partial) ...\n\n-- TOP DOWN\nexample : ∀ (P Q R), (P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) := \nbegin\n  intros P Q R h,\n  apply and.intro \n    (and.intro \n      (and.elim_left h) \n      (h.right.left)\n    ) \n    (h.right.right),\nend\n\n/-\nBOTTOM UP\n-/\n\nexample : ∀ (P Q R), (P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) := \nbegin\n  intros P Q R h,\n  have p : P := h.left,       -- binds identifier, p, to h.left\n  have q : Q := h.right.left, -- scoped locally to this tactic script\n  have r : R := h.right.right,-- we're building objects to be assembled \n  have pq : P ∧ Q := and.intro p q, -- here's the final assembly\n  exact and.intro pq r,       -- exactly the proof term we needed\nend\n\n/-\nNote that we can move arguments to the left or right of\nthe colon. When to the left, we give them names. If on the\nright, if one or more needs names, then we use ∀ or Π to \nbind names, then a comma, then the rest of the type. In \nthis example, we move the ∀ (P Q R : Prop) in the last\nexample to the left of the colon in this example. In\nboth cases, the effect is to bind names, P, Q, and R,\nto assumed objects which enables us to use those names\nin the rest of the expression that specifies the overall\ntype of the function. \n-/\nexample (P Q R : Prop) : (P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) := \nbegin\n  intros h,\n  have p : P := h.left,\n  have q : Q := h.right.left,\n  have r : R := h.right.right,\n  have pq : P ∧ Q := and.intro p q,\n  exact and.intro pq r,\nend\n\nnamespace hidden\n\n#check and\n\n/-\nDEEP DIVE: Now let's take an even deeper\nlook at how the and elimination rules are \nactually implemented. In short, they are\njust functions. The first takes a proof\nof P ∧ Q, comprising a pair of proofs,\n⟨ p, q ⟩, takes apart this pair, and\nreturns its first element, p. The and\nelimination right rules takes the same\npair, takes it apart, and returns q.\n\nThe technical means for doing this kind\nof taking apart, or \"analysis\", of an\nobject is by \"pattern matching.\" (There\nis an even deeper level involving what\nLean calls recursors, but we can't go\nthere yet.)\n-/\n\n/-\nTo begin, recall Lean's actual definition\nof and (∧).\n\nstructure and (a b : Prop) : Prop :=\nintro :: (left : a) (right : b)\n\nLet's go ahead an implement this ourselves\nto make the details clear. The first point\nis that we could have used inductive instead \nof structure. The following definition is\nequivalent to Leans (almost).\n-/\n\ninductive and (P Q : Prop) : Prop\n| intro (p : P) (q : Q) : and \n\n#check and\n#check and P Q\n\n/-\nWhat about that almost? The definition \nabove is logically equivalent to Lean's,\nbut if we use inductive, we have to write\nour own \"accessor functions\" to get at \nthe fields of a proof of P ∧ Q.\n-/\n\ndef elim_left : (and P Q) → P\n| (and.intro x y) := x  -- pattern matching\n\n/-\nAfter the type signature, (and P Q) → P,\nwe give a list of cases, typically one per\nconstructor for the type of the argument,\n(and P Q). For ∧, there is only one case\nto consider: a proof ⟨ p, q ⟩ of P ∧ Q can\n*only* have been constructed by applying\nand.intro to two arguments, here we give\nthem arbitrary names, x and y; and what\npattern matching does is to match the term\nwe're given as an argument, (and.intro p q) \nwith the pattern (and.intro x y), *unifying*\nx with p and y with q. That is, if there's \na match, then x becomes bound to p and y\nbecomes bound to q. In this way, we get at\nthe fields of the object we were given and\nwe give the field values names, *so that \nwe can refer to these objects using these\nnames in the expression to the right of the\n:=, which gives the value that the function\nreturns \"in this case.\" A little further \non, we'll see examples of case analysis\nof objects of types with several constructors.\n-/\n\ndef elim_right : (and P Q) → Q\n| (and.intro x y) := y\n\n\n/-\nTo see that our functions appear to be doing\nthe right thing, let's assume h is bound to a\nproof of and P Q (using our definition of and),\nand then see that our elim_left and elim_right\nfunctions are returning values of the right\ntypes, namely proofs of P and Q, respectively.\n\n-/\naxiom h : and P Q\n#check elim_left h\n#check elim_right h\n\n/-\nWe can't really expect to use reduce here\nbecause h is assumed as an axiom, without\nspecified field values. What happens if you\ntry to reduce, say, (elim_left h)? The answer\nis that such terms are of the right types \nbut simply will not reduce any further.\n-/\n#reduce elim_left h\n#reduce elim_right h\n\n/-\nBASIC ABSTRACT DATA TYPES\n-/ \n\n/-\nAn abstract data type associates a type of\nobject with a set of fundamental operations\non values of that type.\n-/\n\n\n/-\nConsider the Boolean type, bool, in Lean. Here\nis how it's defined. It's a simple enumerated\ntype, with just two constant values, ff and tt.\n\ninductive bool : Type\n| ff : bool\n| tt : bool\n-/\n\n/-\nNow that we've defined our inductive data type,\nwe define fundamental operations on values of \nthis type, and the combination of the type and\nthis set of operations constitutes an abstract\ndata type, rudimentary but complete.\n\nHere's an example of a function that operates\non values of type bool: negate. It takes a bool\nvalue and returns one. It's interesting aspect\nis that it has to analyze the argument value to\nwhich it is applied in order to decice which of\ntwo possible return values to actually return.\n-/\n\ndef negate : bool → bool\n| ff := tt  -- if argument is ff reduce to tt\n| tt := ff  -- if argument is tt reduce to ff\n\n-- here are a few test cases\nexample : negate tt = ff := rfl\nexample : negate ff = tt := rfl\n\n/-\nWe discussed the option type. It has at least\nthree interesting features: it's polymorphic\n(in α); it has *two* constructors; and one of \nthem takes as an argument a value of type α.\n\ninductive option (α : Type u)\n| none : option\n| some (val : α) : option\n-/\n\n/-\nHere's the standard definition of the nat \ntype in Lean. There are two shapes that a\ngiven nat can have: it is either zero or\nit is succ applied to another term of type\nnat, we could call it n. And in this second\ncase, n, being just some nat, could also\nbe either zero or succ of an even \"smaller\"\nnat. What is guaranteed by the semantics\nof inductive definitions is that one will\neventually reach zero after some finite, even\nif large. number of steps.\n\ninductive nat\n| zero : nat\n| succ (n : nat) : nat\n-/\n\n/-\nWe can now put a few pieces together into a \nworking example. We represent a partial function\nfrom natural numbers to natural numbers as a\ntotal function (all functions in Lean are total)\nfrom nat to option nat. A value of type otion\nnat, in turn, is either \"none\" or \"some a.\" If\nthe value of the mathematical function on some\nargument, a, is defined, and has value b, then \nour total function would return (some b). In \nthe case where the mathematical function is \n*undefined*, e.g., at zero, then our total\nfunction applied to that view would return\noption.none.\n\nLet part_fun be a partial function of type\nℕ to ℕ, and suppose that at every value n\nit's defined to have the value n, except at\nzero, at which part_fun is simply undefined.\nHere's a standard solution using an option \nreturn type.\n-/\ndef posnat : nat → option nat \n/-\nCase analysis using pattern matching \non argument. For an argument of type\nnat, there are two basis cases: it's\neither zero or it's the successor of\nsome smaller nat.\n-/\n| nat.zero := none\n| n := n\n\n#reduce posnat 5\n#reduce posnat 4\n#reduce posnat 3\n#reduce posnat 2\n#reduce posnat 1\n#reduce posnat 0\n\nend hidden \n\n/-\nTo finish up, we started to compare and\ncontrast the definitions in Lean of = and\nof ∧. We've now seen that we implement each\nas a parameterized family of propositions. \n-/\n\n#check @eq\n/-\neq : Π {α : Sort u_1}, α → α → PropLean\n-/\n\n#check @and\n/-\nand : Prop → Prop → Prop\n-/\n\n/-\nFinally, and very briefly, the ↔ operator (if and only if,\noften written as iff): it's like a special case of and, in\nthat it has one intro rule, and it takes two arguments, but\nnow they are of type P → Q and Q → P. And with analogy with\nand, iff has two elimination rules, so if h is a proof of\nP ↔ Q, then h.left is a proof of P → Q, and h.right is a \nproof of Q → P.\n-/\n\n/-\nFor example, suppose h is a proof of P ↔ Q\n-/\naxiom h : P ↔ Q\n\n/-\nNow we can see that the elimination rules work\nas one should expect.\n-/\n#check iff.elim_left h\n#check iff.mp h   -- weird names but whatever\n\n#check iff.elim_right h\n#check iff.mpr h  -- weird names but whatever\n\n/-\nSimilarly, if we have proofs of P → Q and of\nQ → P, then we can compose them into a proof\nof P ↔ Q using iff.intro.\n-/\n\naxioms (pq : P → Q) (qp : Q → P)\n#check iff.intro pq qp\n\n/-\nCan you guess how iff is defined in Lean's libraries?\n-/\n\n#print iff\n\n/-\n`iff P Q`, with notation `P ↔ Q`, is the proposition \nasserting that `P` and `Q` are equivalent, that is, \nthat they have the same truth value.\n\nstructure iff (a b : Prop) : Prop :=\nintro :: (mp : a → b) (mpr : b → a)\n-/\n\n/-\nExample: ∧ is associative\n-/\n\nexample : ∀ ( P Q R : Prop), P ∧ Q ∧ R ↔ (P ∧ Q) ∧ R :=\nbegin\n  intros P Q R,\n  split,    -- does apply iff.intro _ _\n\n  -- forward\n  sorry,   -- skip proof, fill in later\n\n  -- reverse \n  sorry,   -- skip proof, fill in later\nend\n\n/-\nExample: P ∧ (P ↔ Q) → Q\n-/\n\nexample : P ∧ (P ↔ Q) → Q :=\nbegin\n  assume h,\n  cases h,\n  cases h_right,\n  exact h_right_mp h_left,\nend\n\n/-\nThe cases tactic does case analysis\non a value in the context, here h.\nFor each possible way in which h\ncould have been constructed, you'll\nneed to show that you can satisfy \nthe goal. In each case, Lean will \nalso provide values of the arguments\nthat that case's constructor would\nhave to have been given in that case.\n\nHere there is just one constructor,\nand.intro, with two arguments, a proof\nof P and a proof of P ↔ Q. So in the\ncase being analyzed, we can assume\nwe have such values. The rest is \nstraightforward.\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/S_02_PredicateLogic/L_01_And.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8723473763375644, "lm_q1q2_score": 0.7818425290572169}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones:\n-- 1. Importar la teoría data.set.lattice\n-- 2. Importar la teoría data.nat.prime\n-- 3. Abrir los espacios de nombre set y nat.\n-- ----------------------------------------------------------------------\n\nimport data.set.lattice   -- 1\nimport data.nat.prime     -- 2\nopen set nat              -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el conjunto de los números primos.\n-- ----------------------------------------------------------------------\n\ndef primes : set ℕ := {x | prime x}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (⋃ p ∈ primes, {x | p^2 ∣ x}) = {x | ∃ p ∈ primes, p^2 ∣ x} :=\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : (⋃ p ∈ primes, {x | p^2 ∣ x}) = {x | ∃ p ∈ primes, p^2 ∣ x} :=\nbegin\n  ext,\n  rw mem_bUnion_iff,\n  refl,\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ (⋃ (p : ℕ) (H : p ∈ primes), {x : ℕ | p ^ 2 ∣ x}) =\n    {x : ℕ | ∃ (p : ℕ) (H : p ∈ primes), p ^ 2 ∣ x}\n  >> ext,\nx : ℕ\n⊢ (x ∈ ⋃ (p : ℕ) (H : p ∈ primes), {x : ℕ | p ^ 2 ∣ x}) ↔\n    x ∈ {x : ℕ | ∃ (p : ℕ) (H : p ∈ primes), p ^ 2 ∣ x}\n  >> rw mem_bUnion_iff,\n⊢ (∃ (x_1 : ℕ) (H : x_1 ∈ primes), x ∈ {x : ℕ | x_1 ^ 2 ∣ x}) ↔\n    x ∈ {x : ℕ | ∃ (p : ℕ) (H : p ∈ primes), p ^ 2 ∣ x}\n  >> refl,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + mem_bUnion_iff : y ∈ (⋃ x ∈ s, t x) ↔ ∃ x ∈ s, y ∈ t x\n\n-- Comprobación:\nuniverses u v\nvariable α : Type u\nvariable β : Type v\nvariable s : set α\nvariable t : α → set β\nvariable y : β\n-- #check @mem_bUnion_iff α β s t y\n\nexample : y ∈ (⋃ x ∈ s, t x) ↔ ∃ x ∈ s, y ∈ t x :=\nmem_bUnion_iff\n\n-- 2ª demostración\n-- ===============\n\nexample : (⋃ p ∈ primes, {x | p^2 ∣ x}) = {x | ∃ p ∈ primes, p^2 ∣ x} :=\nby { ext, rw mem_bUnion_iff, refl }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (⋃ p ∈ primes, {x | p^2 ∣ x}) = {x | ∃ p ∈ primes, p^2 ∣ x}\n-- ----------------------------------------------------------------------\n\nexample : (⋃ p ∈ primes, {x | p^2 ∣ x}) = {x | ∃ p ∈ primes, p^2 ∣ x} :=\nby { ext, simp }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (⋂ p ∈ primes, {x | ¬ p ∣ x}) ⊆ {x | x < 2}\n-- ----------------------------------------------------------------------\n\nexample : (⋂ p ∈ primes, {x | ¬ p ∣ x}) ⊆ {x | x < 2} :=\nbegin\n  intro x,\n  contrapose!,\n  simp,\n  apply exists_prime_and_dvd,\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ (⋂ (p : ℕ) (H : p ∈ primes), {x : ℕ | ¬p ∣ x}) ⊆ {x : ℕ | x < 2}\n  >> intro x,\nx : ℕ\n⊢ (x ∈ ⋂ (p : ℕ) (H : p ∈ primes), {x : ℕ | ¬p ∣ x}) → x ∈ {x : ℕ | x < 2}\n  >> contrapose!,\n⊢ x ∉ {x : ℕ | x < 2} → (x ∉ ⋂ (p : ℕ) (H : p ∈ primes), {x : ℕ | ¬p ∣ x})\n  >> simp,\n⊢ 2 ≤ x → (∃ (x_1 : ℕ), x_1 ∈ primes ∧ x_1 ∣ x)\n  >> apply exists_prime_and_dvd,\nno goals\n-/\n\n-- Comentario: Se ha aplicado el lema\n-- + exists_prime_and_dvd : 2 ≤ n → (∃ (p : ℕ), p.prime ∧ p ∣ n)\n\nvariable n : ℕ\n-- #check @exists_prime_and_dvd n\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (⋃ p ∈ primes, {x | x ≤ p}) = univ\n-- ----------------------------------------------------------------------\n\nexample : (⋃ p ∈ primes, {x | x ≤ p}) = univ :=\nbegin\n  apply eq_univ_of_forall,\n  intro x,\n  simp,\n  rcases exists_infinite_primes x with ⟨p, pge, primep⟩,\n  use [p, primep, pge],\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ (⋃ (p : ℕ) (H : p ∈ primes), {x : ℕ | x ≤ p}) = univ\n  >> apply eq_univ_of_forall,\n⊢ ∀ (x : ℕ), x ∈ ⋃ (p : ℕ) (H : p ∈ primes), {x : ℕ | x ≤ p}\n  >> intro x,\nx : ℕ\n⊢ x ∈ ⋃ (p : ℕ) (H : p ∈ primes), {x : ℕ | x ≤ p}\n  >> simp,\n⊢ ∃ (i : ℕ), i ∈ primes ∧ x ≤ i\n  >> rcases exists_infinite_primes x with ⟨p, pge, primep⟩,\nx p : ℕ,\npge : x ≤ p,\nprimep : p.prime\n⊢ ∃ (i : ℕ), i ∈ primes ∧ x ≤ i\n  >> use [p, primep, pge],\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + eq_univ_of_forall : (∀ x, x ∈ s) → s = univ\n-- + exists_infinite_primes : ∀ (n : ℕ), ∃ (p : ℕ), n ≤ p ∧ p.prime\n\n-- variable α : Type*\n-- variable s : set α\n-- #check @eq_univ_of_forall α s\n-- #check exists_infinite_primes\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_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7817707818441675}}
{"text": "/- LoVe Exercise 11: Logical Foundations of Mathematics -/\n\nimport .love11_logical_foundations_of_mathematics_demo\n\nnamespace LoVe\n\nuniverse variable u\n\nset_option pp.beta true\n\n\n/- Question 1: Subtypes -/\n\nnamespace my_vector\n\n/- Recall the definition of vectors from the lecture: -/\n\n#check vector\n\n/- The following function adds two lists of integers elementwise. If one\nfunction is longer than the other, the tail of the longer function is\ntruncated. -/\n\ndef list_add : list ℤ → list ℤ → list ℤ\n| []        []        := []\n| (x :: xs) (y :: ys) := (x + y) :: list_add xs ys\n| []        (y :: ys) := []\n| (x :: xs) []        := []\n\n/- 1.1. Show that if the lists have the same length, the resulting list also has\nthat length. -/\n\nlemma length_list_add :\n  ∀(xs : list ℤ) (ys : list ℤ) (h : list.length xs = list.length ys),\n    list.length (list_add xs ys) = list.length xs\n| []        []        :=\n  sorry\n| (x :: xs) (y :: ys) :=\n  sorry\n| []        (y :: ys) :=\n  sorry\n| (x :: xs) []        :=\n  sorry\n\n/- 1.2. Define componentwise addition on vectors using `list_add` and\n`length_list_add`. -/\n\ndef add {n : ℕ} : vector ℤ n → vector ℤ n → vector ℤ n :=\nsorry\n\n/- 1.3. Show that `list_add` and `add` are commutative. -/\n\nlemma list_add_comm :\n  ∀(xs : list ℤ) (ys : list ℤ), list_add xs ys = list_add ys xs\nsorry\n\nlemma add_comm {n : ℕ} (x y : vector ℤ n) :\n  add x y = add y x :=\nsorry\n\nend my_vector\n\n\n/- Question 2: Integers as Quotients -/\n\n/- Recall the construction of integers from the lecture: -/\n\n#check myℤ.rel\n#check rel_iff\n#check myℤ\n\n/- 2.1. Define negation using `quotient.lift`. -/\n\ndef neg : myℤ → myℤ :=\nsorry\n\n/- 2.2. Prove the following lemmas. -/\n\nlemma neg_mk (p n : ℕ) :\n  neg ⟦(p, n)⟧ = ⟦(n, p)⟧ :=\nsorry\n\nlemma myℤ.neg_neg (a : myℤ) :\n  neg (neg a) = a :=\nsorry\n\n\n/- Question 3: Nonempty Types -/\n\n/- In the lecture, we saw the inductive predicate `nonempty` that states that a\ntype has at least one element: -/\n\n#print nonempty\n\n/- 3.1. The purpose of this exercise 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 (α : Sort u) :\n  nonempty α\n\n/- This axiom gives us a fact `sort_nonempty` without having to prove it. It\nresembles a lemma proved by sorry, just without the warning. -/\n\n#check sort_nonempty\n\n/- Prove that this axiom leads to a contradiction, i.e., lets us derive\n`false`. -/\n\nlemma proof_of_false : false := \nsorry\n\n/- 3.2 (**optional**). 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 all_nonempty_Type (α : Type u) : nonempty α\n\nlemma proof_of_false₂ : false := \nsorry\n\n\n/- Question 4 (**optional**): Hilbert Choice -/\n\n/- The following command enables noncomputable decidability on every `Prop`. The\n`priority 0` attribute ensures this is used only when necessary; otherwise, it\nwould make some computable definitions noncomputable for Lean. -/\n\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n/- 4.1 (**optional**). Prove the following lemma. -/\n\nlemma exists_minimal_arg.aux (f : ℕ → ℕ) :\n  ∀x n, f n = x → ∃n, ∀i, f n ≤ f i\n| x n eq :=\n  begin\n    -- this works thanks to `classical.prop_decidable`\n    by_cases (∃n', f n' < x),\n    repeat { sorry }\n  end\n\n/- Now this interesting lemma falls off: -/\n\nlemma exists_minimal_arg (f : ℕ → ℕ) :\n  ∃n : ℕ, ∀i : ℕ, f n ≤ f i :=\nexists_minimal_arg.aux f _ 0 rfl\n\n/- 4.2 (**optional**). Use what you learned in the lecture notes to define the\nfollowing function, which returns the (or an) index of the minimal element in\n`f`'s image. -/\n\nnoncomputable def minimal_arg (f : ℕ → ℕ) : ℕ :=\nsorry\n\n/- 4.3 (**optional**). Prove the following characteristic lemma about your\ndefinition. -/\n\nlemma minimal_arg_spec (f : ℕ → ℕ) :\n  ∀i : ℕ, f (minimal_arg f) ≤ f i :=\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/love11_logical_foundations_of_mathematics_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7817599935206936}}
{"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 section14polynomials.sheet01degree\n\n/-!\n\n# Noetherian rings\n\n`is_noetherian_ring R` is the predicate that `R` is Noetherian,\ni.e., that all ideals of `R` are finitely generated. The theorem\nsaying that a ring is Noetherian iff all ideals are finitely\ngenerated is called `is_noetherian_ring_iff_ideal_fg R`. \n\nLet me explain the definition of `gens` below. \n\n`is_noetherian_ring_iff_ideal_fg R` is the statement that R is \n  Noetherian ↔ all ideals are finitely generated. An `↔` statement\n  is made in Lean by giving two things; the `→` implication and the `←`\n  implication.\n\n`(is_noetherian_ring_iff_ideal_fg R).1` is the first implication,\nnamely that if `R` is Noetherian then all ideals are finitely generated.\n\nIf `hR : is_noetherian_ring R` then\n`(is_noetherian_ring_iff_ideal_fg R).1 hR` is thus the statement\nthat for all ideals of `R`, they're finitely generated. So it's\na function which eats an ideal of `R` and returns a proof that\nit's finitely generated.\n\nIf furthermore `J` is an ideal of `R` then\n`(is_noetherian_ring_iff_ideal_fg R).1 hR J` is thus the proof that `J`\nis finitely-generated. In other words, it's a proof there exists\na finite set `S : finset R` of elements of `R` such that `S` generates `J`\nas an ideal.\n\n`exists.some` is the function which takes a proof\nthat there exists something with a property, and spits out\na something. It moves from the `Prop` universe to the `Type` universe\nand is hence noncomputable. The proof that the something satisfies\nthe property is `exists.some_spec`.\n\nWith that in mind, I present `is_noetherian_ring.gens`, a function\nwhich eats an ideal of a Noetherian ring and produces a finite\ngenerating set.\n\n-/\n\nvariables {R : Type} [comm_ring R] (I : ideal (polynomial R))\n\nopen polynomial\n\n-- this definition and these lemmas should perhaps be in mathlib?\nnamespace is_noetherian_ring\n\n/-- If `hR : is_noetherian_ring R` and `J : ideal R` then `hR.gens J` is a finite generating set for `J`,\n  expressed as a term of type `finset R`. See `hR.span_gens J` for a proof that it spans. -/\nnoncomputable def gens (hR : is_noetherian_ring R) (J : ideal R) : finset R :=\n((is_noetherian_ring_iff_ideal_fg R).1 hR J).some\n\n/-\n\nThe `gens` function spits out a `finset`, which is the type of finite subsets\nof `R`. There's a coercion to `set R` of course. \n\nThe proof that the generating set does actually span is the same as the\ndefinition, except that you change `some` to `some_spec`.\n\n-/\n\nlemma span_gens (hR : is_noetherian_ring R) (J : ideal R) : ideal.span (hR.gens J : set R) = J :=\n((is_noetherian_ring_iff_ideal_fg R).1 hR J).some_spec\n\n/-\n\nSee if you can prove the useful lemma that the generators of `J` are a subset\nof `J`. The lemma you need from the library is called `ideal.subset_span`.\n-/\n\nlemma gens_subset (hR : is_noetherian_ring R) (J : ideal R) :\n  (hR.gens J : set R) ⊆ J :=\nbegin\n  sorry\nend\n\nend is_noetherian_ring\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/section14polynomials/sheet02noetherian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.7816841573556492}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Importar la librería de los números reales.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Enunciar, usando variables implícitas, el lema ej: \"para\n-- todos los números reales x, y, ε si\n--    0 < ε\n--    ε ≤ 1\n--    abs x < ε\n--    abs y < ε\n-- entonces\n--    abs (x * y) < ε\n-- ----------------------------------------------------------------------\n\nlemma ej :\n  ∀ {x y ε : ℝ},\n  0 < ε →\n  ε ≤ 1 →\n  abs x < ε →\n  abs y < ε →\n  abs (x * y) < ε :=\nsorry\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Crear una sección con las siguientes declaraciones\n--    a b δ : ℝ\n--    h₀ : 0 < δ\n--    h₁ : δ ≤ 1\n--    ha : abs a < δ\n--    hb : abs b < δ\n-- y calcular el tipo de las siguientes expresiones\n--    ej h₀ h₁ ha hb\n-- ----------------------------------------------------------------------\n\nsection\n\nvariables a b δ : ℝ\nvariables (h₀ : 0 < δ) (h₁ : δ ≤ 1)\nvariables (ha : abs a < δ) (hb : abs b < δ)\n\n-- #check ej h₀ h₁ ha hb\n\n-- Comentario: Al colocar el cursor sobre check se obtiene\n--    ej h₀ h₁ ha hb : abs (a * b) < δ\n\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/Lema_con_implicaciones_y_cuantificador_universal_implicitos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7816841487186302}}
{"text": "import analysis.specific_limits\nimport data.int.parity\n\nattribute [instance] classical.prop_decidable\n\n/- \nLemmas from that file were hidden in my course, or restating things which\nwere proved without name in previous files.\n-/\n\nnotation `|`x`|` := abs x\n\n-- The mathlib version is unusable because it is stated in terms of ≤\nlemma ge_max_iff {α : Type*} [decidable_linear_order α] {p q r : α} : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\n/- No idea why this is not in mathlib-/\nlemma eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h, \n  apply  decidable_linear_ordered_add_comm_group.eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\nlemma unique_limit {u l l'} : seq_limit u l → seq_limit u l' → l = l' :=\nbegin\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros ε ε_pos,\n  specialize hl (ε/2) (by linarith),\n  cases hl with N hN,\n  specialize hl' (ε/2) (by linarith),\n  cases hl' with N' hN',\n  specialize hN (max N N') (le_max_left _ _),\n  specialize hN' (max N N') (le_max_right _ _),\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring\n  ... ≤ |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  ... ≤ ε/2 + ε/2 : by linarith\n  ... = ε : by ring,\nend\n\ndef pair (n : ℤ) := ∃ k, n = 2*k\n\ndef int.odd (n : ℤ) := ∃ k, n = 2*k + 1\n\nlemma int.not_even_iff_odd {n : ℤ} : ¬ int.even n ↔ int.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 ← h },\n  exact (int.mod_add_div n 2).symm,\n  rcases h with ⟨k, rfl⟩,\n  simp [add_comm],\n  refl,\nend\n\nlemma le_of_le_add_all {x y : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\ndef upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y\n\nlemma lt_sup {A : set ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\nlemma squeeze {u v w : ℕ → ℝ} {l} (hu : seq_limit u l) (hw : seq_limit w l)\n(h : ∀ n, u n ≤ v n)\n(h' : ∀ n, v n ≤ w n) : seq_limit v l :=\nbegin\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases hw ε ε_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 ; linarith\nend\n\ndef extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m\n\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\nlemma lim_le {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\n/- \nlemma limite_infinie_pas_finie {u : ℕ → ℝ} :\n  limite_infinie_suite u → ∀ x, ¬ seq_limit u x :=\nbegin\n  -- sorry\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (inferieur_max_gauche _ _),\n  specialize hN' N₀ (inferieur_max_droite _ _),\n  rw abs_inferieur_ssi at hN,\n  linarith',\n  -- sorry\nend -/\n\nlemma inv_succ_le_all :  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    intros h ε ε_pos,\n    cases h (ε/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n    specialize hN n hn,\n    linarith,\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\nlemma limit_const (x : ℝ) : seq_limit (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\nlemma limit_of_sub_le_inv_succ {u : ℕ → ℝ} {x : ℝ} (h : ∀ n, |u n - x| ≤ 1/(n+1)) :\nseq_limit u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\nlemma limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ; linarith [@nat.one_div_pos_of_nat ℝ _ n])\n\nlemma limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\nlemma id_le_extraction {φ}: extraction φ → ∀ n, n ≤ φ 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\nlemma seq_limit_id : tendsto_infinity (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N, exact_mod_cast hn, \n  linarith,\nend\n\nlemma extraction_machine (ψ : ℕ → ℕ) (hψ : ∀ n, ψ n ≥ n) : ∃ f : ℕ → ℕ, extraction (ψ ∘ f) ∧ ∀ n, f n ≥ n :=\nbegin\n  refine ⟨λ n, nat.rec_on n 0 (λ n ih, ψ ih + 1), λ m n h, _, λ n, _⟩,\n  { induction h; dsimp [(∘)],\n    { exact hψ _ },\n    { exact lt_trans h_ih (hψ _) } },\n  { induction n, {apply le_refl},\n    exact nat.succ_le_succ (le_trans n_ih (hψ _)) }\nend\n\nvariables {u : ℕ → ℝ} {l : ℝ} {φ : ℕ → ℕ}\n\nlemma limite_extraction_si_limite (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  -- sorry\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn \n     ... ≤ φ n : id_le_extraction hφ n, \n  -- sorry\nend\n\ndef segment (a b : ℝ) := {x | a ≤ x ∧ x ≤ b}\n\nopen set filter\n\ndef cluster_point (u : ℕ → ℝ) (a : ℝ) :=\n∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a\n\nlemma bolzano_weierstrass {a b : ℝ} {u : ℕ → ℝ} (h : ∀ n, u n ∈ Icc a b) :\n∃ c ∈ Icc a b, cluster_point u c :=\nbegin\n  have cpct : compact (Icc a b),\n    exact compact_Icc,\n  have :  map u at_top ≤ principal (Icc a b),\n  { change tendsto u _ _,\n    rw tendsto_principal,\n    filter_upwards [univ_mem_sets],\n    intros n hn,\n    exact h n },\n  rcases cpct (map u at_top) (map_ne_bot at_top_ne_bot) this with ⟨c, h, h'⟩,\n  clear this,\n  use [c, h],\n  unfold cluster_point,\n  have : ∀ N, ∃ n ≥ N, |u n -c| ≤ 1/(N+1),\n    intro N,\n    rw ← forall_sets_nonempty_iff_ne_bot at h',\n    specialize h' (u '' {n | n ≥ N} ∩ {x | |x-c| ≤ 1/(N+1)}) _,\n    { simp only [set.nonempty,\n                set.mem_image,\n                set.mem_inter_eq,\n                ne.def,\n                set.mem_set_of_eq] at h',\n      rcases h' with ⟨_, ⟨n, ⟨hn, rfl⟩⟩, ineg⟩,\n      use [n, hn, ineg] },\n    { apply inter_mem_inf_sets,\n      { apply image_mem_map,\n        apply mem_at_top },\n      { have fact: (0 : ℝ) < 1/(N+2),\n          exact_mod_cast (nat.one_div_pos_of_nat : 1/((N+1 : ℕ) + 1 : ℝ) > 0),\n        apply mem_sets_of_superset (metric.ball_mem_nhds c fact),\n        intros x x_in,\n        rw [metric.mem_ball, real.dist_eq] at x_in,\n        exact le_of_lt (\n          calc |x - c| < 1 / (N + 2) : x_in\n                   ... = 1/((N+1)+1) : by { congr' 1, norm_cast }\n                   ... ≤ 1 / (N + 1) : nat.one_div_le_one_div (nat.le_succ N)),\n\n       } },\n  choose ψ hψ using this,\n  cases forall_and_distrib.mp hψ with hψ_id hψ', clear hψ,\n  rcases extraction_machine ψ hψ_id with ⟨f, hf, hf'⟩,\n  use [ψ ∘ f, hf],\n  apply limit_of_sub_le_inv_succ,\n  intros n,\n  transitivity 1/(f n + 1 : ℝ),\n  apply hψ',\n  exact nat.one_div_le_one_div (hf' n),\nend\n\nlemma not_seq_limit_of_tendstoinfinity {u : ℕ → ℝ} :\n  tendsto_infinity u → ∀ x, ¬ seq_limit u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\nopen real \n\nlemma sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :\n  ∃ x ∈ Icc a b, is_sup A x :=\nbegin\n  have b_maj :  ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : upper_bound A (Sup A),\n  { intro x,\n    apply real.le_Sup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply Sup_le_ub A hnonvide b_maj } },\n  { use Sup_maj,\n    intros y y_in,\n    rwa real.Sup_le _ hnonvide ⟨b, b_maj⟩ },\nend\n\nlemma subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn \n     ... ≤ φ n : id_le_extraction hφ n, \nend\nnamespace tactic.interactive\nopen tactic\n\nmeta def check_me : tactic unit :=\n`[ { repeat { unfold seq_limit},\n   repeat { unfold continue_en },\n   push_neg,\n   try { simp only [exists_prop] },\n   try { exact iff.rfl },\n   done } <|> fail \"Ce n'est pas cela. Essayez encore.\" ]\n\nend tactic.interactive", "meta": {"author": "pedrominicz", "repo": "learn", "sha": "b79b802a9846c86c21d4b6f3e17af36e7382f0ef", "save_path": "github-repos/lean/pedrominicz-learn", "path": "github-repos/lean/pedrominicz-learn/learn-b79b802a9846c86c21d4b6f3e17af36e7382f0ef/src/tutorials/tuto_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7816841390418114}}
{"text": "-- M40002 (Analysis I) Chapter 4. Series\n\nimport M40002.M40002_C3\n\nnamespace M40002\n\n-- Definition of convergent sums\ndef partial_sum_to (a : ℕ → ℝ) (n : ℕ) := finset.sum (finset.range n) a\nnotation `∑` a := partial_sum_to a\n\ndef sum_converges_to (a : ℕ → ℝ) (l : ℝ) := (partial_sum_to a) ⇒ l\nnotation a ` ∑⇒ ` l := sum_converges_to a l\n\n/- Maybe use this notation instead\ndef X (f : real ->Prop) (x : real) := f x\nnotation `∑` binders `, ` r:(scoped P, sum_converges_to P) := r\ninfixr ` ⇛ `: 50 := X  -/\n\ndef sum_convergent (a : ℕ → ℝ) := ∃ l : ℝ, a ∑⇒ l\nnotation ` ∑⇒ ` a := sum_convergent a\n\n-- s n - s (n - 1) = a n\nlemma successive_diff {a : ℕ → ℝ} {n : ℕ} : (partial_sum_to a (n + 1)) - (partial_sum_to a n) = a n :=\nby {unfold partial_sum_to,\n    rw finset.sum_range_succ,\n    simp\n}\n\n-- ∑ a is convergent implies a → 0\ntheorem test_trivial (a : ℕ → ℝ) : (∑⇒ a) → a ⇒ 0 :=\nbegin\n    intros h ε hε,\n    cases h with l hl,\n    have : cauchy (partial_sum_to a) :=\n        by {rwa cauchy_iff_conv,\n        use l, from hl\n        },\n    cases this ε hε with N hN,\n    use N, intros n hn,\n    rw sub_zero (a n),\n    suffices hα : abs (partial_sum_to a n - partial_sum_to a (n + 1)) < ε,\n        {rwa [abs_sub, successive_diff] at hα},\n    apply hN n (n + 1),\n    have : N ≤ n + 1 := by {linarith},\n    from ⟨hn, this⟩\nend\n\nlemma succ_sum_def {a : ℕ → ℝ} : ∀ k : ℕ, (∑ a) (nat.succ k) = (∑ a) k + a k := \nby {intro k, unfold partial_sum_to,\n    rw finset.sum_range_succ,\n    from add_comm (a k) (finset.sum (finset.range k) a)\n}\n\n-- If a ≥ 0, then ↑ (∑ a)\nlemma sum_mono_increasing {a : ℕ → ℝ} (h : ∀ n : ℕ, 0 ≤ a n) : (∑ a) ↑ :=\nbegin\n    intro n, rw succ_sum_def n,\n    have hβ : 0 ≤ a n := h n,\n    linarith\nend\n\n-- If a ≥ 0, then ∑ a is convergent if ∑ a is bounded above\ntheorem sum_bdd_abv_conv {a : ℕ → ℝ} (h : ∀ n : ℕ, 0 ≤ a n) : (seq_bounded_above (∑ a)) → (∑⇒ a) :=\nbegin\n    intro hα,\n    apply mono_increasing_means_conv (∑ a) _,\n    split, \n    {from hα},\n    {use 0, intro m,\n    induction m with k hk,\n        {unfold partial_sum_to, simp},\n            {rw succ_sum_def k,\n            from add_nonneg hk (h k)\n            },\n        },\n    from sum_mono_increasing h\nend\n\n-- Comparison Test. If 0 ≤ a ≤ b, and if ∑ b converges then so do ∑ a\ntheorem test_comparison {a b : ℕ → ℝ} : (∀ n : ℕ, 0 ≤ a n ∧ a n ≤ b n) ∧ (∑⇒ b) → ∑⇒ a := \nbegin\n    rintro ⟨hα, ⟨l, hl⟩⟩,\n    apply sum_bdd_abv_conv,\n        {intro n,\n        from (hα n).left\n        },\n        {rcases converge_is_bdd (∑ b) ⟨l, hl⟩ with ⟨⟨N, hN⟩, blw⟩,\n        use N, intro n,\n        have : (∑ a) n ≤ (∑ b) n :=\n            by {induction n with k hk,\n            unfold partial_sum_to, simp,\n            repeat {rw succ_sum_def},\n            have : a k ≤ b k := (hα k).right,\n            linarith\n            },\n        from le_trans this (hN n)\n        }\nend\n\n-- Algebra of limits for sums\nlemma sum_add_sum_split {a b : ℕ → ℝ} : (∑ a) + (∑ b) = (∑ a + b) :=\nbegin\n    rw [seq_add_seq, function.funext_iff], \n    intro n,\n    unfold partial_sum_to,\n    induction n with k hk,\n        {simp},\n        {repeat {rw finset.sum_range_succ},\n        rw [←hk, seq_add_seq], simp\n        }\nend\n\ntheorem add_sum_lim_conv {a b : ℕ → ℝ} {l m : ℝ} (h₁ : a ∑⇒ l) (h₂ : b ∑⇒ m) : (a + b) ∑⇒ (l + m) :=\nbegin\n    unfold sum_converges_to,\n    rw ←sum_add_sum_split,\n    apply add_lim_conv,\n    from ⟨h₁, h₂⟩\nend\n\nlemma scalar_mul_sum_split {a : ℕ → ℝ} {m : ℝ} : ((∑ a) × m) = ∑ (a × m) :=\nbegin\n    rw function.funext_iff,\n    intro n, rw seq_mul_real,\n    unfold partial_sum_to,\n    induction n with k hk,\n        {simp},\n        {rw [finset.sum_range_succ, add_mul, hk],\n        have : a k * m = (a × m) k := rfl,\n        rwa [this, ←finset.sum_range_succ]\n        }\nend\n\ntheorem scalar_sum_lim_conv {a : ℕ → ℝ} {l m : ℝ} (h₁ : a ∑⇒ l) : (a × m) ∑⇒ l * m :=\nbegin\n    unfold sum_converges_to,\n    rw ←scalar_mul_sum_split,\n    apply mul_lim_conv, \n    from h₁,\n    from cons_conv\nend\n\n-- Defining absolute convergence\nnoncomputable def abs_seq (a : ℕ → ℝ) (n : ℕ) := abs (a n)\ndef abs_sum_converge (a : ℕ → ℝ) := ∑⇒ abs_seq a\n\n-- Absolutely convergen implies normal convergence\nlemma sum_diff {a : ℕ → ℝ} {n m : ℕ} (h₁ : n < m) : (∑ a) m - (∑ a) n = finset.sum (finset.Ico n m) a :=\nbegin\n    unfold partial_sum_to, \n    induction m with k hk,\n        {exfalso, from nat.not_succ_le_zero n h₁},\n        {rw [finset.sum_range_succ, finset.sum_Ico_succ_top],\n        swap, from nat.lt_succ_iff.mp h₁,\n        simp,\n        cases nat.lt_succ_iff_lt_or_eq.mp h₁,\n            {rw [←sub_eq_add_neg, hk h]},\n            {rw h, simp}\n        }\nend\n\nlemma sum_le (a b : ℕ → ℝ) {n m : ℕ} (h₁ : ∀ n : ℕ, a n ≤ b n) : finset.sum (finset.Ico n m) a ≤ finset.sum (finset.Ico n m) b :=\nbegin\n    induction m with k hk,\n        {rw finset.Ico.eq_empty_iff.mpr (zero_le n), simp},\n        {cases le_or_lt n k,\n            {repeat {rw finset.sum_Ico_succ_top h},\n            apply add_le_add hk _,\n            from h₁ k\n            },\n            {rw finset.Ico.eq_empty_iff.mpr (nat.succ_le_iff.mpr h),\n            simp\n            }\n        }\nend\n\nlemma sum_pos {a : ℕ → ℝ} {n m : ℕ} (h₁ : ∀ k : ℕ, 0 ≤ a k) : 0 ≤ finset.sum (finset.Ico n m) a :=\nbegin\n    induction m with k hk,\n        {rw finset.Ico.eq_empty_iff.mpr (zero_le n), simp},\n        {cases le_or_lt n k,\n            {rw finset.sum_Ico_succ_top h,\n            from add_nonneg hk (h₁ k)\n            },\n            {rw finset.Ico.eq_empty_iff.mpr (nat.succ_le_iff.mpr h),\n            simp\n            }\n        }\nend\n\nlemma sum_triangle {a : ℕ → ℝ} {n m : ℕ} : abs (finset.sum (finset.Ico n m) a) ≤ finset.sum (finset.Ico n m) (abs_seq a) :=\nbegin\n    induction m with k hk,\n        {rw finset.Ico.eq_empty_iff.mpr (zero_le n), simp},\n        {cases le_or_lt n k,\n            {repeat {rw finset.sum_Ico_succ_top h},\n            apply le_trans (abs_add (finset.sum (finset.Ico n k) a) (a k)),\n            show abs (finset.sum (finset.Ico n k) a) + abs (a k) ≤ finset.sum (finset.Ico n k) (abs_seq a) + abs (a k),\n            suffices : abs (finset.sum (finset.Ico n k) a) ≤ finset.sum (finset.Ico n k) (abs_seq a),\n                simpa,\n            assumption\n            },\n            {rw finset.Ico.eq_empty_iff.mpr (nat.succ_le_iff.mpr h),\n            simp\n            }\n        }\nend\n\nlemma neg_sum {a : ℕ → ℝ} {n m : ℕ} : - finset.sum (finset.Ico n m) a = finset.sum (finset.Ico n m) (a × -1) :=\nbegin\n    induction m with k hk,\n        {rw finset.Ico.eq_empty_iff.mpr (zero_le n), simp},\n        {cases le_or_lt n k,\n            {repeat {rw finset.sum_Ico_succ_top h},\n            unfold seq_mul_real, simp\n            },\n            {rw finset.Ico.eq_empty_iff.mpr (nat.succ_le_iff.mpr h),\n            simp\n            }\n        }\nend\n\ntheorem abs_conv_to_conv {a : ℕ → ℝ} : abs_sum_converge a → ∑⇒ a :=\nbegin\n    intro h₁,\n    suffices : cauchy (∑ a),\n        cases cauchy_iff_conv.mp this with l hl,\n        use l, from hl,\n    have hcauchy : cauchy (∑ abs_seq a) := cauchy_iff_conv.mpr h₁,\n    unfold cauchy at hcauchy,\n    intros ε hε,\n    cases hcauchy ε hε with N hN,\n    use N, intros n m h₂,\n    replace hN : abs ((∑abs_seq a) n - (∑abs_seq a) m) < ε := hN n m h₂,\n    cases lt_trichotomy n m,\n        swap, cases h,\n        {rw h, simp, from hε},\n        {rw sum_diff h,\n        rw sum_diff h at hN,\n        apply lt_of_le_of_lt _ hN,\n        rw abs_le,\n        split, swap,\n            {have : ∀ k : ℕ, a k ≤ abs_seq a k := λ k : ℕ,\n                by {from le_max_left (a k) (- a k)},\n            apply le_trans (sum_le a (abs_seq a) this),\n            from le_max_left (finset.sum (finset.Ico m n) (abs_seq a)) (-finset.sum (finset.Ico m n) (abs_seq a))\n            },\n            {rw abs_of_nonneg, swap, \n                {apply sum_pos,\n                intro k, from abs_nonneg (a k)},\n                {rw neg_sum, apply sum_le,\n                intro n, unfold seq_mul_real,\n                simp, rw neg_le, from le_max_right (a n) (-a n)\n                }\n            }\n        },\n        {rw [abs_sub, sum_diff h],\n        rw [abs_sub, sum_diff h] at hN,\n        apply lt_of_le_of_lt _ hN,\n        rw abs_le,\n        split, swap,\n            {have : ∀ k : ℕ, a k ≤ abs_seq a k := λ k : ℕ,\n                by {from le_max_left (a k) (- a k)},\n            apply le_trans (sum_le a (abs_seq a) this),\n            from le_max_left (finset.sum (finset.Ico n m) (abs_seq a)) (-finset.sum (finset.Ico n m) (abs_seq a))\n            },\n            {rw abs_of_nonneg, swap, \n                {apply sum_pos,\n                intro k, from abs_nonneg (a k)},\n                {rw neg_sum, apply sum_le,\n                intro n, unfold seq_mul_real,\n                simp, rw neg_le, from le_max_right (a n) (-a n)\n                }\n            }\n        }\nend\n\n-- set_option trace.simplify.rewrite true\n-- Sandwich theorem for sums\ntheorem test_sum_sandwich {a b c : ℕ → ℝ} {h₁ : ∀ n : ℕ, c n ≤ a n ∧ a n ≤ b n} : (∑⇒ c) ∧ (∑⇒ b) → ∑⇒ a :=\nbegin\n    intro h₂,\n    have hcauchyb : cauchy ∑ b := conv_to_cauchy (∑ b) h₂.right,\n    have hcauchyc : cauchy ∑ c := conv_to_cauchy (∑ c) h₂.left,\n    suffices : cauchy (∑ a),\n        cases cauchy_iff_conv.mp this with l hl,\n        use l, from hl,\n    intros ε hε,\n    cases hcauchyb ε hε with N₁ hN₁,\n    cases hcauchyc ε hε with N₂ hN₂,\n    let N : ℕ := max N₁ N₂,\n    use N,\n    intros n m hnm,  \n    cases lt_trichotomy n m,\n        rw [abs_sub, abs_lt],\n        split,\n-- These parts are essentially the same\n            {have : N₂ ≤ n ∧ N₂ ≤ m :=\n                by {split,\n                apply le_trans _ hnm.left,\n                from le_max_right N₁ N₂,\n                apply le_trans _ hnm.right,\n                from le_max_right N₁ N₂\n                },\n            replace h₂ : -ε < (∑c) m - (∑c) n :=\n                by {have hα : abs ((∑c) n - (∑c) m) < ε := hN₂ n m this,\n                rw abs_sub at hα,\n                from (abs_lt.mp hα).left\n                },\n            apply lt_of_lt_of_le h₂,\n            repeat {rw sum_diff},\n            apply sum_le, intro n, from (h₁ n).left,\n            repeat {assumption}\n            },\n-- 1\n            {have : N₁ ≤ n ∧ N₁ ≤ m :=\n                by {split,\n                apply le_trans _ hnm.left,\n                from le_max_left N₁ N₂,\n                apply le_trans _ hnm.right,\n                from le_max_left N₁ N₂\n                },\n            replace h₂ : (∑b) m - (∑b) n < ε :=\n                by {have hα : abs ((∑b) n - (∑b) m) < ε := hN₁ n m this,\n                rw abs_sub at hα,\n                from (abs_lt.mp hα).right\n                },\n            apply lt_of_le_of_lt _ h₂,\n            repeat {rw sum_diff},\n            apply sum_le, intro n, from (h₁ n).right,\n            repeat {assumption}\n            },\n        cases h,\n            {rw h, simp, from hε},\n            {rw abs_lt,\n                split,\n-- 2\n                {have : N₂ ≤ n ∧ N₂ ≤ m :=\n                    by {split,\n                    apply le_trans _ hnm.left,\n                    from le_max_right N₁ N₂,\n                    apply le_trans _ hnm.right,\n                    from le_max_right N₁ N₂\n                    },\n                replace h₂ : -ε < (∑c) n - (∑c) m :=\n                    by {have hα : abs ((∑c) n - (∑c) m) < ε := hN₂ n m this,\n                    from (abs_lt.mp hα).left\n                    },\n                apply lt_of_lt_of_le h₂,\n                repeat {rw sum_diff},\n                apply sum_le, intro n, from (h₁ n).left,\n                repeat {assumption}\n                },\n-- 3\n                {have : N₁ ≤ n ∧ N₁ ≤ m :=\n                    by {split,\n                    apply le_trans _ hnm.left,\n                    from le_max_left N₁ N₂,\n                    apply le_trans _ hnm.right,\n                    from le_max_left N₁ N₂\n                    },\n                replace h₂ : (∑b) n - (∑b) m < ε :=\n                    by {have hα : abs ((∑b) n - (∑b) m) < ε := hN₁ n m this,\n                    from (abs_lt.mp hα).right\n                    },\n                apply lt_of_le_of_lt _ h₂,\n                repeat {rw sum_diff},\n                apply sum_le, intro n, from (h₁ n).right,\n                repeat {assumption}\n            }\n        }\nend\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_C4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8499711775577735, "lm_q1q2_score": 0.7816696489013463}}
{"text": "import data.quot -- equivalence relations and equivalence classes\nimport tactic.interactive -- for \"choose\" tactic\n\n-- Sian's definition of an equivalence relation on X corresponding to a function f : X → Y\n\n-- X and Y and f are fixed once and for all in this story, so let's make them parameters\n-- in a section.\n\nsection -- in this section X and Y and the surjection f will be fixed once and for all\n\nopen function -- so I can write \"surjective\" instead of \"function.surjective\"\n\nparameters {X : Type} {Y : Type} (f : X → Y) (hf : surjective f)\n\n-- now let's define the binary relation that Sian came up with\n\ndef R (x₁ x₂ : X) : Prop := f x₁ = f x₂\n\n-- top tip -- sometimes \"unfold R\" doesn't work. I don't know why. Try the tactic \"delta R\"? This always works.\n\ntheorem R.equivalence : equivalence R :=\nbegin\n  split,\n    delta R,\n    unfold reflexive,\n    intro,\n    refl, \n  split,\n    delta R,\n    unfold symmetric,\n    intros,\n    rw a,\n  delta R,\n  unfold transitive,\n  intros,\n  rw a,\n  assumption,    \nend\n\n-- A \"setoid\" is Lean's rather pretentious term for\n-- the data of a type and an equivalence relation on the type.\n-- More precisely, a term of type `setoid X` is a *pair*\n-- consisting of\n-- 1) a binary relation R on X\n-- 2) a proof that R is an equivalence relation.\n\n-- We just proved R was an equivalence relation on X so we can make a setoid.\n-- Note that we have to give both the relation and the proof that it's an equivalence relation.\n\ndef s : setoid X := ⟨R, R.equivalence⟩ -- pointy brackets is often a constructor for a type which is a pair.\n\n-- let's define Q to be the set of equivalence classes for this equivalence relation.\n\n-- Lean takes the \"quotient of the setoid\".\ndef Q := quotient s\n-- Now Q is the set of equivalence classes.\n\n-- when you left the office today Friday, I had challenged you to give maps from Q to Y\n-- You said \"Let S be an equivalence class. Define F(S) = f(x) where x is any element of S.\"\n\n-- I said \"yeah but you need to check that that is well-defined, because what if your definition\n-- of F(S) depends on the choice of x?\"\n\n-- If you try to make this definition in Lean, as below, then Lean makes precisely the\n-- same objection. It wants to know why two things in the same equivalence class give the same answer.\n\ndef F : Q → Y := λ q, quotient.lift_on' q (λ (x : X), f x) begin\n  show ∀ a b : X, R a b → f a = f b,\n  delta R,\n  intros,\n  assumption,\nend\n\ntheorem commutes' (x : X) : f x = F (quotient.mk' x) :=\nbegin\n  refl\nend\n\n-- technical note: I managed to define a function from Q to somewhere because I knew\n-- an \"eliminator\" for Q, namely quotient.lift_on'\n\n-- def G : Y → Q := sorry -- you never did that bit. How will you do it?\n\n-- you will need to know a \"constructor\" for Q, namely a way to make elements of Q.\n-- Here is a function from X to Q.\n\nexample : X → Q := quotient.mk'\n\n-- Using that function, can you make a function from Y to Q? Here's a hint.\n\ninclude hf -- need surjectivity for this one\nnoncomputable def G : Y → Q := λ y, quotient.mk' (classical.some (hf y))\n\n-- What shall we do next?\n\nlemma commutes (x : X) : G (f x) = quotient.mk' x :=\nbegin\n  let x' := classical.some (hf (f x)),\n  have xh' := classical.some_spec (hf (f x)),\n  change f x' = f x at xh',\n  change quotient.mk' (x') = _,\n  rw quotient.eq',\n  show R _ x,\n  exact xh',\nend\n\n\nend -- section", "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/equivalence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682085, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7816696394170108}}
{"text": "import ..prooflab\nimport lectures.lec2_algebraic_identities\nimport lectures.lec3_function\n\n/-! # Homework 2 \nHomework must be done individually.\nReplace the placeholders (e.g., `:= sorry`) with your solutions. -/\n\n/-\nTactics we have learned before Homework 2:\n1. `refl`\n2. `exact`\n3. `rw` and its variants\n4. `change` \n5. `calc` \n6. `ring`\n7. `linear_combination`\n-/\n\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace PROOFS \n\nvariable {X : Type}\n\n\n\n/-! ## Question 1 (10 points): \nUse `rw` tactic together the lemmas `mul_one` and `one_mul` to construct a proof to the statement below. You are only allowed to use `rw` tactic and no other tactic. \n-/\n\n#check (mul_one : ∀ (a : ℚ), a * 1 = a)\n#check (one_mul : ∀ (a : ℚ), 1 * a = a)\n\nexample (x y z : ℚ) (h₁ : x * 1 = 1 * y) (h₂ : y = z)  : \n  x = z := \nbegin \n  sorry,\nend \n\n\n\n\n\n\n/-! ## Question 2 (20 points): \nUse the tactic `calc` in conjunction with the following lemmas to prove that given rational numbers `a`, `b`, and `c`, if `b * a = 1` and `a * c = 1` then `b = c`.  \n-/\n\n#check mul_one\n#check one_mul\n#check mul_assoc \n\nexample (a b c : ℚ) (h₁ : b * a = 1) (h₂ : a * c = 1) :\n  b = c :=\nbegin\n  sorry,\nend \n\n\n\n\n\n/-! ## Question 3 (20 points)\nUse `rw` and the lemmas below to comeplete the proof the `example` below.\n-/ \n\n#check pow_two\n#check mul_add \n#check add_mul \n#check add_assoc\n#check add_comm\n#check one_mul\n#check mul_one\n#check two_mul \n#check mul_two\n\n\nexample (a : ℝ) : \n  (a + 1)^2 = a^2 + 2 * a + 1 :=\nbegin\n  calc (a + 1)^2 = (a + 1) * (a + 1) : by rw pow_two\n  ...            = (a + 1) * a + (a + 1) * 1 : sorry \n  ...            = (a * a + 1 * a) + (a * 1 + 1 * 1) : sorry\n  ...            = (a^2 + a) + (a + 1) : sorry\n  ...            = a^2 + 2 * a + 1 : by sorry\nend \n\n\n\n\n\n\n\n/-! ## Question 4 (25 points): \nConstruct a proof for the following statement using any tactics we heav learned (tactics 1-7 in the list at the top of this file) except `ring` and only the lemmas we have learned so far and possibly the lemma `pow_mul` below. \n-/\n\nsection \nvariable a : ℝ\n#check (pow_mul a : ∀ (m n : ℕ), a ^ (m * n) = (a ^ m) ^ n)\nend \n\nexample (a b : ℝ) : \n  a^4 - b^4 = (a^2 + b^2) * (a + b) * (a - b) :=\nbegin \n  sorry,\nend \n\n\n\n\n\n/-! ## Question 5 (25 points): \n1. For a type `X`, Define the function `triple_shuffle` which takes a triple `(a, b, c)` as in input, where `a b c : X`, and returns the triple `(b , c, a)` \n-/\n\ndef triple_shuffle  : X × X × X → X × X × X := \nsorry\n\n\n/-\n2. Evaluate the application of `triple_shuffle` to `(1,2,3)`. \n-/\n\n/-\n3. Evaluate the application of `triple_shuffle` to `triple_shuffle (1,2,3)`. \n-/\n\n\n/-\n4. Prove that third application of `triple_shuffle` to the triple `(1,2,3)` is equal to `(1,2,3)`. \n-/\nexample :  \ntriple_shuffle (triple_shuffle (triple_shuffle (1,2,3) )) = (1,2,3) := \nbegin\n  sorry, \nend \n\n\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/hw2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7815808985441536}}
{"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.nat.sqrt\nimport data.set.lattice\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 `⟦0, n^2 - 1⟧` to\n`⟦0, n - 1⟧²`.\n-/\n\nopen prod decidable function\n\nnamespace nat\n\n/-- Pairing function for the natural numbers. -/\n@[pp_nodot] def mkpair (a b : ℕ) : ℕ :=\nif a < b then b*b + a else a*a + a + b\n\n/-- Unpairing function for the natural numbers. -/\n@[pp_nodot] def unpair (n : ℕ) : ℕ × ℕ :=\nlet s := sqrt n in\nif n - s*s < s then (n - s*s, s) else (s, n - s*s - s)\n\n@[simp] theorem mkpair_unpair (n : ℕ) : mkpair (unpair n).1 (unpair n).2 = n :=\nbegin\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  { simp [mkpair, h, sm] },\n  { have hl : n - s*s - s ≤ s :=\n      tsub_le_iff_left.mpr (tsub_le_iff_left.mpr $\n      by rw ← 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] }\nend\n\ntheorem mkpair_unpair' {n a b} (H : unpair n = (a, b)) : mkpair a b = n :=\nby simpa [H] using mkpair_unpair n\n\n@[simp] theorem unpair_mkpair (a b : ℕ) : unpair (mkpair a b) = (a, b) :=\nbegin\n  dunfold mkpair, split_ifs,\n  { show unpair (b * b + a) = (a, b),\n    have be : sqrt (b * b + a) = b,\n      from sqrt_add_eq _ (le_trans (le_of_lt h) (nat.le_add_left _ _)),\n    simp [unpair, be, add_tsub_cancel_right, h] },\n  { show unpair (a * a + a + b) = (a, b),\n    have ae : sqrt (a * a + (a + b)) = a,\n    { rw sqrt_add_eq, exact add_le_add_left (le_of_not_gt h) _ },\n    simp [unpair, ae, nat.not_lt_zero, add_assoc] }\nend\n\n/-- An equivalence between `ℕ × ℕ` and `ℕ`. -/\n@[simps { fully_applied := ff }] def mkpair_equiv : ℕ × ℕ ≃ ℕ :=\n⟨uncurry mkpair, unpair, λ ⟨a, b⟩, unpair_mkpair a b, mkpair_unpair⟩\n\nlemma surjective_unpair : surjective unpair :=\nmkpair_equiv.symm.surjective\n\n@[simp] lemma mkpair_eq_mkpair {a b c d : ℕ} : mkpair a b = mkpair c d ↔ a = c ∧ b = d :=\nmkpair_equiv.injective.eq_iff.trans (@prod.ext_iff ℕ ℕ (a, b) (c, d))\n\ntheorem unpair_lt {n : ℕ} (n1 : 1 ≤ n) : (unpair n).1 < n :=\nlet s := sqrt n in begin\n  simp [unpair], change sqrt n with s,\n  by_cases h : n - s * s < s; simp [h],\n  { exact lt_of_lt_of_le h (sqrt_le_self _) },\n  { 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)) }\nend\n\n@[simp] lemma unpair_zero : unpair 0 = 0 :=\nby { rw unpair, simp }\n\ntheorem unpair_left_le : ∀ (n : ℕ), (unpair n).1 ≤ n\n| 0     := by simp\n| (n+1) := le_of_lt (unpair_lt (nat.succ_pos _))\n\ntheorem left_le_mkpair (a b : ℕ) : a ≤ mkpair a b :=\nby simpa using unpair_left_le (mkpair a b)\n\ntheorem right_le_mkpair (a b : ℕ) : b ≤ mkpair a b :=\nbegin\n  by_cases h : a < b; simp [mkpair, h],\n  exact le_trans (le_mul_self _) (nat.le_add_right _ _)\nend\n\ntheorem unpair_right_le (n : ℕ) : (unpair n).2 ≤ n :=\nby simpa using right_le_mkpair n.unpair.1 n.unpair.2\n\ntheorem mkpair_lt_mkpair_left {a₁ a₂} (b) (h : a₁ < a₂) : mkpair a₁ b < mkpair a₂ b :=\nbegin\n  by_cases h₁ : a₁ < b; simp [mkpair, h₁, add_assoc],\n  { by_cases h₂ : a₂ < b; simp [mkpair, h₂, h],\n    simp at h₂,\n    apply add_lt_add_of_le_of_lt,\n    exact mul_self_le_mul_self h₂,\n    exact lt_add_right _ _ _ h },\n  { simp at h₁,\n    simp [not_lt_of_gt (lt_of_le_of_lt h₁ h)],\n    apply add_lt_add,\n    exact mul_self_lt_mul_self h,\n    apply add_lt_add_right; assumption }\nend\n\ntheorem mkpair_lt_mkpair_right (a) {b₁ b₂} (h : b₁ < b₂) : mkpair a b₁ < mkpair a b₂ :=\nbegin\n  by_cases h₁ : a < b₁; simp [mkpair, h₁, add_assoc],\n  { simp [mkpair, lt_trans h₁ h, h],\n    exact mul_self_lt_mul_self h },\n  { by_cases h₂ : a < b₂; simp [mkpair, h₂, h],\n    simp at h₁,\n    rw [add_comm, add_comm _ a, add_assoc, add_lt_add_iff_left],\n    rwa [add_comm, ← sqrt_lt, sqrt_add_eq],\n    exact le_trans h₁ (nat.le_add_left _ _) }\nend\n\nend nat\nopen nat\n\nsection complete_lattice\n\nlemma supr_unpair {α} [complete_lattice α] (f : ℕ → ℕ → α) :\n  (⨆ n : ℕ, f n.unpair.1 n.unpair.2) = ⨆ i j : ℕ, f i j :=\nby rw [← (supr_prod : (⨆ i : ℕ × ℕ, f i.1 i.2) = _), ← nat.surjective_unpair.supr_comp]\n\nlemma infi_unpair {α} [complete_lattice α] (f : ℕ → ℕ → α) :\n  (⨅ n : ℕ, f n.unpair.1 n.unpair.2) = ⨅ i j : ℕ, f i j :=\nsupr_unpair (show ℕ → ℕ → order_dual α, from f)\n\nend complete_lattice\n\nnamespace set\n\nlemma Union_unpair_prod {α β} {s : ℕ → set α} {t : ℕ → set β} :\n  (⋃ n : ℕ, (s n.unpair.fst).prod (t n.unpair.snd)) = (⋃ n, s n).prod (⋃ n, t n) :=\nby { rw [← Union_prod], convert surjective_unpair.Union_comp _, refl }\n\nlemma Union_unpair {α} (f : ℕ → ℕ → set α) :\n  (⋃ n : ℕ, f n.unpair.1 n.unpair.2) = ⋃ i j : ℕ, f i j :=\nsupr_unpair f\n\nlemma Inter_unpair {α} (f : ℕ → ℕ → set α) :\n  (⋂ n : ℕ, f n.unpair.1 n.unpair.2) = ⋂ i j : ℕ, f i j :=\ninfi_unpair f\n\nend set\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/pairing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.841825655188238, "lm_q1q2_score": 0.781558343475075}}
{"text": "import tactic.push_neg\nimport tactic.suggest\n\nexample (a : Prop) : a ∨ true :=\nbegin\n  suggest,\n  -- exact or.inr trivial,\n  -- exact (or_true a).mpr trivial,\n  exact or.intro_right a trivial,\nend\n\nexample (a : Prop) : ¬(a ↔ ¬a) := (iff_not_self a).1\n\nexample (a b : Prop) : a ∧ b → a ∨ b :=\nbegin\n  intro h,\n    -- 3 lines below doing nothing\n    refine or.imp_left _ _,\n    exact a,\n    exact id,\n  sorry,\nend\n\nexample : 0 < 2 :=\nbegin\n  refine nat.lt.step _,\n  exact nat.lt.base 0,\nend\n\nexample : 0 < 5 :=\nbegin\n  exact (int.coe_nat_lt_coe_nat_iff 0 5).mp trivial, -- why this works?\nend\n\nexample (n : nat) : n < n + 2 :=\nbegin\n  -- refine n.lt_add_left 2 n _,\n  -- ⊢ n < 2 is not provable\n  refine nat.lt.step _,\n  -- exact nat.lt.base n, OK\n  -- exact nat.lt_succ_self n, OK\n  -- refine nat.lt.step _, -- ⊢ n < n is not provable\n  -- refine nat.lt_succ_of_lt _, -- same result\n  -- refine lt_iff_le_not_le.mpr _, -- ???\n\n  -- refine nat.lt_trans _ _,\n  -- exact n, -- ⊢ n < n not provable\n\n  have h : n < n + 1, sorry,\n  suggest, -- Try this: exact h\n  exact nat.lt.base n,\nend\n\nexample (n) : n*n ≠ 1 → n ≠ 1 := by {\n  contrapose,\n  -- refine mt _, -- undo contrapose\n  rw [not_not, not_not],\n  assume h : n = 1,\n  rw [h],\n  have h₂ := one_mul 1,\n  suggest, -- Try this: exact rfl, but expected h₂\n  exact h₂,\n}\n\nexample {a b c d: nat} (h₁ : a < c) (h₂ : b < d) : max (c + d) (a + b) = (c + d) :=\nbegin\n  suggest 50 [add_lt_add], -- Says: `exact max_eq_left_of_lt (add_lt_add h₁ h₂)`\n  exact max_eq_left_of_lt (add_lt_add h₁ h₂),\nend\n\nnamespace example2\n\nconstant lt : ℕ → ℕ → Prop\naxiom lt.base {n} : lt n n.succ\naxiom lt.base_false {n} : ¬ lt n n\naxiom lt.step {n m} : lt n m → lt n m.succ\n\nvariables {a b c d : ℕ}\n\nexample : lt 0 1 := lt.base\nexample : lt 0 2 := lt.step lt.base\nexample : lt 0 3 := lt.step (lt.step lt.base)\n\nexample : lt 0 3 := \nbegin\n  suggest 2, -- Try this: refine lt.step _\n  refine lt.step _,\n  suggest 2, -- Try this: refine lt.step _\n  refine lt.step _,\n  suggest 1, -- Try this: refine lt.step _\n  suggest 2, -- Try this: exact lt.base\n  exact lt.base,\nend\n\nexample : ¬ lt 1 0 :=\nbegin\n  refine not.intro _,\n  intro h,\n  have h₂ : ¬ lt 1 1, suggest 22, exact lt.base_false, \n  -- 22 is minimum number which produce exact word\n  have contraposed : ∀ (n m : ℕ), ¬ lt n m.succ → ¬ lt n m,\n  {\n    intros n m hyp,\n    suggest [lt.step, lt.base_false, lt.base],\n    -- Try this: exact id (λ (a : lt n m), false.rec false h.step.base_false)\n    exact id (λ (a : lt n m), false.rec false h.step.base_false),\n  },\n  suggest, -- Try this: exact contraposed 1 0 h₂ h\n  exact contraposed 1 0 h₂ h,\nend\n\nlemma lt.not_one_zero : ¬ lt 1 0 :=\nbegin\n  suggest [lt.step, lt.base_false, lt.base],\n  exact mt lt.step lt.base_false,\n  -- exact classical.not_imp_not.mpr lt.step lt.base_false\nend\n\nlemma lt.not_two_one : ¬ lt 2 1 := mt lt.step lt.base_false\n\nexample : ¬ lt 2 0 :=\nbegin\n  suggest 100 [lt.step, lt.base_false, lt.base, lt.not_one_zero, lt.not_two_one],\n  -- one of found terms: refine mt _ _\n  refine mt lt.step _, -- try to fill first hole manually\n  suggest 100 [lt.not_one_zero, lt.step, lt.base_false, lt.base],\n  -- exact mt lt.step lt.base_false\n  -- exact classical.not_imp_not.mpr lt.step lt.base_false\n  exact lt.not_two_one,\nend\n\nlemma lt.succ_not_less (n : ℕ) : ¬ lt n.succ n :=\nbegin\n  suggest 100 [lt.step, lt.base_false, lt.base, lt.not_one_zero, lt.not_two_one],\n  -- Try this: exact mt lt.step lt.base_false\n  -- Try this: exact classical.not_imp_not.mpr lt.step lt.base_false\n  exact mt lt.step lt.base_false,\nend\n\nexample : ¬ lt 5 4 :=\nbegin\n  suggest 23, -- Try this: exact lt.succ_not_less 4\n  exact lt.succ_not_less 4,\nend\n\nexample (a : Prop): false → a :=\nbegin\n  suggest 22,\n  exact false.elim,\n  -- exact false.rec a\n  -- exact false.drec (λ (n : false), a)\n  -- exact false.elim\n  -- exact false.rec_on a\nend\n\n\n\nexample : ¬ lt 0 0 :=\nbegin\n  -- refine imp_false.mp _,\n  refine (false_iff (lt 0 0)).mp _,\n  refine eq.to_iff _,\n  refine ((λ {α : Type} {x₁ x₂ y₁ y₂ : α} (h₁ : x₁ = y₁) (h₂ : x₂ = y₂), (h₁.congr h₂).mp) _ _ _).symm,\n  all_goals { sorry },\nend\n\nend example2", "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/suggest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.781551895217962}}
{"text": "import algebra.big_operators.ring\nimport data.real.basic\n\n/- TEXT:\n.. _section_structures:\n\nStructures\n----------\n\nIn the broadest sense of the term, a *structure* is a specification\nof a collection of data, possibly with contraints that the\ndata is required to satisfy.\nAn *instance* of the structure is a particular bundle of data satisfying\nthe constraints. For example, we can specify that a point is\na tuple of three real numbers:\nBOTH: -/\n-- QUOTE:\n@[ext] structure point := (x : ℝ) (y : ℝ) (z : ℝ)\n-- QUOTE.\n\n/- TEXT:\nThe ``@[ext]`` annotation tells Lean to automatically generate theorems\nthat can be used to prove that two instances of a structure are equal\nwhen their components are equal, a property known as *extensionality*.\nEXAMPLES: -/\n-- QUOTE:\n#check point.ext\n\nexample (a b : point) (hx : a.x = b.x) (hy : a.y = b.y) (hz : a.z = b.z) :\n  a = b :=\nbegin\n  ext,\n  repeat { assumption }\nend\n-- QUOTE.\n\n/- TEXT:\nWe can then define particular instances of the ``point`` structure.\nLean provides multiple ways of doing that.\nEXAMPLES: -/\n-- QUOTE:\ndef my_point1 : point :=\n{ x := 2,\n  y := -1,\n  z := 4 }\n\ndef my_point2 :=\n{ point .\n  x := 2,\n  y := -1,\n  z := 4 }\n\ndef my_point3 : point := ⟨2, -1, 4⟩\n\ndef my_point4 := point.mk 2 (-1) 4\n-- QUOTE.\n\n/- TEXT:\nIn the first two examples, the fields of the structure are named\nexplicitly.\nIn the first case, because Lean knows that the expected type of\n``my_point1`` is a ``point``, you can start the definition by\nwriting an underscore, ``_``. Clicking on the light bulb\nthat appears nearby in VS Code will then\ngive you the option of inserting a template definition\nwith the field names listed for you.\n\nThe function ``point.mk`` referred to in the definition of ``my_point4``\nis known as the *constructor* for the ``point`` structure, because\nit serves to construct elements.\nYou can specify a different name if you want, like ``build``.\nEXAMPLES: -/\n-- QUOTE:\nstructure point' := build :: (x : ℝ) (y : ℝ) (z : ℝ)\n\n#check point'.build 2 (-1) 4\n-- QUOTE.\n\n/- TEXT:\nThe next two examples show how to define functions on structures.\nWhereas the second example makes the ``point.mk``\nconstructor explicit, the first example uses anonymous constructors\nfor brevity.\nLean can infer the relevant constructor from the indicated type of\n``add``.\nIt is conventional to put definitions and theorems associated\nwith a structure like ``point`` in a namespace with the same name.\nIn the example below, because we have opened the ``point``\nnamespace, the full name of ``add`` is ``point.add``.\nWhen the namespace is not open, we have to use the full name.\nBut remember that it is often convenient to use\nanonymous projection notation,\nwhich allows us to write ``a.add b`` instead of ``point.add a b``.\nLean interprets the former as the latter because ``a`` has type ``point``.\nBOTH: -/\n-- QUOTE:\nnamespace point\n\ndef add (a b : point) : point := ⟨a.x + b.x, a.y + b.y, a.z + b.z⟩\n\n-- EXAMPLES:\ndef add' (a b : point) : point :=\n{ x := a.x + b.x,\n  y := a.y + b.y,\n  z := a.z + b.z }\n\n#check add my_point1 my_point2\n#check my_point1.add my_point2\n\nend point\n\n#check point.add my_point1 my_point2\n#check my_point1.add my_point2\n-- QUOTE.\n\n/- TEXT:\nBelow we will continue to put definitions in the relevant\nnamespace, but we will leave the namespacing commands out of the quoted\nsnippets. To prove properties of the addition function,\nwe can use ``rw`` to expand the definition and ``ext`` to\nreduce an equation between two elements of the structure to equations\nbetween the components.\nBelow we use the ``protected`` keyword so that the name of the\ntheorem is ``point.add_comm``, even when the namespace is open.\nThis is helpful when we want to avoid ambiguity with a generic\ntheorem like ``add_comm``.\nEXAMPLES: -/\nnamespace point\n\n-- QUOTE:\nprotected theorem add_comm (a b : point) : add a b = add b a :=\nbegin\n  rw [add, add],\n  ext; dsimp,\n  repeat { apply add_comm }\nend\n\nexample (a b : point) : add a b = add b a :=\nby simp [add, add_comm]\n-- QUOTE.\n\n/- TEXT:\nBecause Lean can unfold definitions and simplify projections\ninternally, sometimes the equations we want hold definitionally.\nEXAMPLES: -/\n-- QUOTE:\ntheorem add_x (a b : point) : (a.add b).x = a.x + b.x := rfl\n-- QUOTE.\n\n/- TEXT:\nIt is also possible to define functions on structures using\npattern matching,\nin a manner similar to the way we defined recursive functions in\n:numref:`section_induction_and_recursion`.\nThe definitions ``add_alt`` and ``add_alt'`` below are essentially the\nsame; the only difference is that we use anonymous constructor notation\nin the second.\nAlthough it is sometimes convenient to define functions this way,\nthe definitional properties are not as convenient.\nFor example, the expressions ``add_alt a b`` and ``add_alt' a b``\ncannot be simplified until we decompose ``a`` and ``b`` into\ncomponents, which we can do with ``cases``, ``rcases``, etc.\n\nEXAMPLES: -/\n-- QUOTE:\ndef add_alt : point → point → point\n| (point.mk x₁ y₁ z₁) (point.mk x₂ y₂ z₂) := ⟨x₁ + x₂, y₁ + y₂, z₁ + z₂⟩\n\ndef add_alt' : point → point → point\n| ⟨x₁, y₁, z₁⟩ ⟨x₂, y₂, z₂⟩ := ⟨x₁ + x₂, y₁ + y₂, z₁ + z₂⟩\n\ntheorem add_alt_x (a b : point) : (a.add_alt b).x = a.x + b.x :=\nby { cases a, cases b, refl }\n\ntheorem add_alt_comm (a b : point) : add_alt a b = add_alt b a :=\nbegin\n  rcases a with ⟨xa, ya, za⟩,\n  rcases b with ⟨xb, yb, zb⟩,\n  rw [add_alt, add_alt],\n  ext; dsimp,\n  apply add_comm,\n  repeat { apply add_comm },\nend\n\nexample (a b : point) : add_alt a b = add_alt b a :=\nbegin\n  rcases a with ⟨xa, ya, za⟩,\n  rcases b with ⟨xb, yb, zb⟩,\n  simp [add_alt, add_comm]\nend\n\nexample : ∀ a b : point, add_alt a b = add_alt b a :=\nbegin\n  rintros ⟨xa, ya, za⟩ ⟨xb, yb, zb⟩,\n  simp [add_alt, add_comm]\nend\n\nexample : ∀ a b : point, add a b = add b a :=\nλ ⟨xa, ya, za⟩ ⟨xb, yb, zb⟩, by simp [add, add_comm]\n-- QUOTE.\n\n/- TEXT:\nMathematical constructions often involve taking apart bundled information and\nputting it together again in different ways.\nIt therefore makes sense that Lean and mathlib offer so many ways\nof doing this efficiently.\nAs an exercise, try proving that ``point.add`` is associative.\nThen define scalar multiplication for a point and show that it\ndistributes over addition.\nBOTH: -/\n-- QUOTE:\nprotected theorem add_assoc (a b c : point) :\n  (a.add b).add c = a.add (b.add c) :=\n/- EXAMPLES:\nsorry\nSOLUTIONS: -/\nby { simp [add, add_assoc] }\n-- BOTH:\n\ndef smul (r : ℝ) (a : point) : point :=\n/- EXAMPLES:\nsorry\nSOLUTIONS: -/\n⟨r * a.x, r * a.y, r * a.z⟩\n-- BOTH:\n\ntheorem smul_distrib (r : ℝ) (a b : point) :\n  (smul r a).add (smul r b) = smul r (a.add b) :=\n/- EXAMPLES:\nsorry\nSOLUTIONS: -/\nby { simp [add, smul, mul_add] }\n-- BOTH:\n-- QUOTE.\n\nend point\n\n/- TEXT:\nUsing structures is only the first step on the road to\nalgebraic abstraction.\nWe don't yet have a way to link ``point.add`` to the generic ``+`` symbol,\nor to connect ``point.add_comm`` and ``point.add_assoc`` to\nthe generic ``add_comm`` and ``add_assoc`` theorems.\nThese tasks belong to the *algebraic* aspect of using structures,\nand we will explain how to do carry them out in the next section.\nFor now, just think of a structure as a way of bundling together objects\nand information.\n\nIt is especially useful that a structure can specify not only\ndata types but also constraints that the data must satisfy.\nIn Lean, the latter are represented as fields of type ``Prop``.\nFor example, the *standard 2-simplex* is defined to be the set of\npoints :math:`(x, y, z)` satisfying :math:`x ≥ 0`, :math:`y ≥ 0`, :math:`z ≥ 0`,\nand :math:`x + y + z = 1`.\nIf you are not familiar with the notion, you should draw a picture,\nand convince yourself that this set is\nthe equilateral triangle in three-space with vertices\n:math:`(1, 0, 0)`, :math:`(0, 1, 0)`, and :math:`(0, 0, 1)`,\ntogether with its interior.\nWe can represent it in Lean as follows:\nBOTH: -/\n-- QUOTE:\nstructure standard_two_simplex :=\n(x : ℝ)\n(y : ℝ)\n(z : ℝ)\n(x_nonneg : 0 ≤ x)\n(y_nonneg : 0 ≤ y)\n(z_nonneg : 0 ≤ z)\n(sum_eq   : x + y + z = 1)\n-- QUOTE.\n\n/- TEXT:\nNotice that the last four fields refer to ``x``, ``y``, and ``z``,\nthat is, the first three fields.\nWe can define a map from the two-simplex to itself that swaps ``x`` and ``y``:\nBOTH: -/\nnamespace standard_two_simplex\n\n-- EXAMPLES:\n-- QUOTE:\ndef swap_xy (a : standard_two_simplex) : standard_two_simplex :=\n{ x := a.y,\n  y := a.x,\n  z := a.z,\n  x_nonneg := a.y_nonneg,\n  y_nonneg := a.x_nonneg,\n  z_nonneg := a.z_nonneg,\n  sum_eq   := by rw [add_comm a.y a.x, a.sum_eq] }\n-- QUOTE.\n\n-- OMIT: (TODO) add a link when we have a good explanation of noncomputable theory.\n/- TEXT:\nMore interestingly, we can compute the midpoint of two points on\nthe simplex. We need to add ``noncomputable theory`` in order to\nuse division on the real numbers.\nBOTH: -/\n-- QUOTE:\nnoncomputable theory\n\n-- EXAMPLES:\ndef midpoint (a b : standard_two_simplex) : standard_two_simplex :=\n{ x        := (a.x + b.x) / 2,\n  y        := (a.y + b.y) / 2,\n  z        := (a.z + b.z) / 2,\n  x_nonneg := div_nonneg (add_nonneg a.x_nonneg b.x_nonneg) (by norm_num),\n  y_nonneg := div_nonneg (add_nonneg a.y_nonneg b.y_nonneg) (by norm_num),\n  z_nonneg := div_nonneg (add_nonneg a.z_nonneg b.z_nonneg) (by norm_num),\n  sum_eq   := by { field_simp, linarith [a.sum_eq, b.sum_eq]} }\n-- QUOTE.\n\n/- TEXT:\nHere we have established ``x_nonneg``, ``y_nonneg``, and ``z_nonneg``\nwith concise proof terms, but establish ``sum_eq`` in tactic mode,\nusing ``by``. You can just as well use a ``begin ... end`` block\nfor that purpose.\n\nGiven a parameter :math:`\\lambda` satisfying :math:`0 \\le \\lambda \\le 1`,\nwe can take the weighted average :math:`\\lambda a + (1 - \\lambda) b`\nof two points :math:`a` and :math:`b` in the standard 2-simplex.\nWe challenge you to define that function, in analogy to the ``midpoint``\nfunction above.\nBOTH: -/\n-- QUOTE:\ndef weighted_average (lambda : real)\n    (lambda_nonneg : 0 ≤ lambda) (lambda_le : lambda ≤ 1)\n    (a b : standard_two_simplex) :\n  standard_two_simplex :=\n/- EXAMPLES:\nsorry\nSOLUTIONS: -/\n{ x        := lambda * a.x + (1 - lambda) * b.x,\n  y        := lambda * a.y + (1 - lambda) * b.y,\n  z        := lambda * a.z + (1 - lambda) * b.z,\n  x_nonneg := add_nonneg (mul_nonneg lambda_nonneg a.x_nonneg)\n                (mul_nonneg (by linarith) b.x_nonneg),\n  y_nonneg := add_nonneg (mul_nonneg lambda_nonneg a.y_nonneg)\n                (mul_nonneg (by linarith) b.y_nonneg),\n  z_nonneg := add_nonneg (mul_nonneg lambda_nonneg a.z_nonneg)\n                (mul_nonneg (by linarith) b.z_nonneg),\n  sum_eq   :=\n    begin\n      transitivity (a.x + a.y + a.z) * lambda + (b.x + b.y + b.z) * (1 - lambda),\n      { ring },\n      simp [a.sum_eq, b.sum_eq]\n    end }\n-- QUOTE.\n-- BOTH:\n\nend standard_two_simplex\n\n/- TEXT:\nStructures can depend on parameters.\nFor example, we can generalize the standard 2-simplex to the standard\n:math:`n`-simplex for any :math:`n`.\nAt this stage, you don't have to know anything about the type `fin n`\nexcept that it has :math:`n` elements, and that Lean knows\nhow to sum over it.\nBOTH: -/\n-- QUOTE:\nopen_locale big_operators\n\nstructure standard_simplex (n : ℕ) :=\n(v          : fin n → ℝ)\n(nonneg     : ∀ i : fin n, 0 ≤ v i)\n(sum_eq_one : ∑ i, v i = 1)\n\nnamespace standard_simplex\n\ndef midpoint (n : ℕ) (a b : standard_simplex n) : standard_simplex n :=\n{ v := λ i, (a.v i + b.v i) / 2,\n  nonneg :=\n    begin\n      intro i,\n      apply div_nonneg,\n      { linarith [a.nonneg i, b.nonneg i] },\n      norm_num\n    end,\n  sum_eq_one :=\n    begin\n      simp [div_eq_mul_inv, ←finset.sum_mul, finset.sum_add_distrib,\n        a.sum_eq_one, b.sum_eq_one],\n      field_simp\n    end  }\n\nend standard_simplex\n-- QUOTE.\n\n/- TEXT:\nAs an exercise, see if you can define the weighted average of\ntwo points in the standard :math:`n`-simplex.\nYou can use ``finset.sum_add_distrib``\nand ``finset.mul_sum`` to manipulate the relevant sums.\n\nSOLUTIONS: -/\nnamespace standard_simplex\n\ndef weighted_average {n : ℕ} (lambda : real)\n    (lambda_nonneg : 0 ≤ lambda) (lambda_le : lambda ≤ 1)\n    (a b : standard_simplex n) : standard_simplex n :=\n{ v          := λ i, lambda * a.v i + (1 - lambda) * b.v i,\n  nonneg     := λ i, add_nonneg (mul_nonneg lambda_nonneg (a.nonneg i))\n                  (mul_nonneg (by linarith) (b.nonneg i)),\n  sum_eq_one :=\n    begin\n      transitivity lambda * (∑ i, a.v i) + (1 - lambda) * (∑ i, b.v i),\n      { rw [finset.sum_add_distrib, finset.mul_sum, finset.mul_sum] },\n      simp [a.sum_eq_one, b.sum_eq_one]\n    end }\n\nend standard_simplex\n\n/- TEXT:\nWe have seen that structures can be used to bundle together data\nand properties.\nInterestingly, they can also be used to bundle together properties\nwithout the data.\nFor example, the next structure, ``is_linear``, bundles together\nthe two components of linearity.\nEXAMPLES: -/\n-- QUOTE:\nstructure is_linear (f : ℝ → ℝ) :=\n(is_additive : ∀ x y, f (x + y) = f x + f y)\n(preserves_mul : ∀ x c, f (c * x) = c * f x)\n\nsection\nvariables (f : ℝ → ℝ) (linf : is_linear f)\n\n#check linf.is_additive\n#check linf.preserves_mul\n\nend\n-- QUOTE.\n\n/- TEXT:\nIt is worth pointing out that structures are not the only way to bundle\ntogether data.\nThe ``point`` data structure can be defined using the generic type product,\nand ``is_linear`` can be defined with a simple ``and``.\nEXAMPLES: -/\n-- QUOTE:\ndef point'' := ℝ × ℝ × ℝ\n\ndef is_linear' (f : ℝ → ℝ) :=\n(∀ x y, f (x + y) = f x + f y) ∧ (∀ x c, f (c * x) = c * f x)\n-- QUOTE.\n\n/- TEXT:\nGeneric type constructions can even be used in place of structures\nwith dependencies between their components.\nFor example, the *subtype* construction combines a piece of data with\na property.\nYou can think of the type ``preal`` in the next example as being\nthe type of positive real numbers.\nAny ``x : preal`` has two components: the value, and the property of being\npositive.\nYou can access these components as ``x.val``, which has type ``ℝ``,\nand ``x.property``, which represents the fact ``0 < x.val``.\nEXAMPLES: -/\n-- QUOTE:\ndef preal := { y : ℝ // 0 < y }\n\nsection\nvariable x : preal\n\n#check x.val\n#check x.property\n\n#check x.1\n#check x.2\n\nend\n-- QUOTE.\n\n/- TEXT:\nWe could have used subtypes to define the standard 2-simplex,\nas well as the standard :math:`n`-simplex for an arbitrary :math:`n`.\nEXAMPLES: -/\n-- QUOTE:\ndef standard_two_simplex' :=\n{ p : ℝ × ℝ × ℝ // 0 ≤ p.1 ∧ 0 ≤ p.2.1 ∧ 0 ≤ p.2.2 ∧ p.1 + p.2.1 + p.2.2 = 1 }\n\ndef standard_simplex' (n : ℕ) :=\n{ v : fin n → ℝ // (∀ i : fin n, 0 ≤ v i) ∧ (∑ i, v i = 1) }\n-- QUOTE.\n\n/- TEXT:\nSimilarly, *Sigma types* are generalizations of ordered pairs,\nwhereby the type of the second component depends on the type of\nthe first.\nEXAMPLES: -/\n-- QUOTE:\ndef std_simplex := Σ n : ℕ, standard_simplex n\n\nsection\nvariable s : std_simplex\n\n#check s.fst\n#check s.snd\n\n#check s.1\n#check s.2\n\nend\n-- QUOTE.\n\n/- TEXT:\nGiven ``s : std_simplex``, the first component ``s.fst`` is a natural\nnumber, and the second component is an element of the corresponding\nsimplex ``standard_simplex s.fst``.\nThe difference between a Sigma type and a subtype is that\nthe second component of a Sigma type is data rather than a proposition.\n\nBut even though we can use products, subtypes, and Sigma types\ninstead of structures, using structures has a number of advantages.\nDefining a structure abstracts away the underlying representation\nand provides custom names for the functions that access the components.\nThis makes proofs more robust:\nproofs that rely only on the interface to a structure\nwill generally continue to work when we change the definition,\nas long as we redefine the old accessors in terms of the new definition.\nMoreover, as we are about to see, Lean provides support for\nweaving structures together into a rich, interconnected hierarchy,\nand for managing the interactions between them.\nTEXT. -/\n\n/- OMIT: (TODO)\nComments from Patrick:\nWe could make this paragraph much less abstract by showing how to access the components of a point with the definition def point'' := ℝ × ℝ × ℝ. However if we do that it would probably be honest to also mention the possibility of using fin 3 → ℝ as the definition. This interesting anyhow, because I think very few mathematician realize that defining ℝ^n as an iterated cartesian product is a polite lie that would be a nightmare if taken seriously.\n\nBy the way, should be include some comment about similarities and differences with object-oriented programming? All the examples from that page would clearly fit very well with classes in python say. And we'll have to face the name-clash between classes in Lean and classes in C++ or python sooner or later. Life would be so much simpler if classes in Lean could use another name...\nOMIT. -/\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/06_Abstract_Algebra/source_01_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8976952900545976, "lm_q1q2_score": 0.7815310734125359}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\n-/\nimport order.lattice\nimport data.set.basic\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* `directed_order α`: Typeclass extending `preorder` for stating that `α` is `≤`-directed.\n-/\n\nuniverses u v w\n\nvariables {α : Type u} {β : Type v} {ι : Sort w} (r : α → α → Prop)\nlocal infix ` ≼ ` : 50 := r\n\n/-- A family of elements of α is directed (with respect to a relation `≼` on α)\n  if there is a member of the family `≼`-above any pair in the family.  -/\ndef directed (f : ι → α) := ∀ x y, ∃ z, f x ≼ f z ∧ f y ≼ f z\n\n/-- A subset of α is directed if there is an element of the set `≼`-above any\n  pair of elements in the set. -/\ndef directed_on (s : set α) := ∀ (x ∈ s) (y ∈ s), ∃ z ∈ s, x ≼ z ∧ y ≼ z\n\nvariables {r}\n\ntheorem directed_on_iff_directed {s} : @directed_on α r s ↔ directed r (coe : s → α) :=\nby simp [directed, directed_on]; refine ball_congr (λ x hx, by simp; refl)\n\nalias directed_on_iff_directed ↔ directed_on.directed_coe _\n\ntheorem directed_on_image {s} {f : β → α} :\n  directed_on r (f '' s) ↔ directed_on (f ⁻¹'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 α} (h : directed_on r s)\n  {r' : α → α → Prop} (H : ∀ {a b}, r a b → r' a b) :\n  directed_on r' s :=\nλ x hx y hy, let ⟨z, zs, xz, yz⟩ := h x hx y hy in ⟨z, zs, H xz, H yz⟩\n\ntheorem directed_comp {ι} {f : ι → β} {g : β → α} :\n  directed r (g ∘ f) ↔ directed (g ⁻¹'o r) f := iff.rfl\n\ntheorem directed.mono {s : α → α → Prop} {ι} {f : ι → α}\n  (H : ∀ a b, r a b → s a b) (h : directed r f) : directed s f :=\nλ a b, let ⟨c, h₁, h₂⟩ := h a b in ⟨c, H _ _ h₁, H _ _ h₂⟩\n\ntheorem directed.mono_comp {ι} {rb : β → β → Prop} {g : α → β} {f : ι → α}\n  (hg : ∀ ⦃x y⦄, x ≼ y → rb (g x) (g y)) (hf : directed r f) :\n  directed rb (g ∘ f) :=\ndirected_comp.2 $ hf.mono hg\n\n/-- A monotone function on a sup-semilattice is directed. -/\nlemma directed_of_sup [semilattice_sup α] {f : α → β} {r : β → β → Prop}\n  (H : ∀ ⦃i j⦄, i ≤ j → r (f i) (f j)) : directed r f :=\nλ a b, ⟨a ⊔ b, H le_sup_left, H le_sup_right⟩\n\nlemma monotone.directed_le [semilattice_sup α] [preorder β] {f : α → β} :\n  monotone f → directed (≤) f :=\ndirected_of_sup\n\n/-- An antitone function on an inf-semilattice is directed. -/\nlemma directed_of_inf [semilattice_inf α] {r : β → β → Prop} {f : α → β}\n  (hf : ∀ a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : directed r f :=\nλ x y, ⟨x ⊓ y, hf _ _ inf_le_left, hf _ _ 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 ≤ k` and `j ≤ k`. -/\nclass directed_order (α : Type u) extends preorder α :=\n(directed : ∀ i j : α, ∃ k, i ≤ k ∧ j ≤ k)\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance linear_order.to_directed_order (α) [linear_order α] : directed_order α :=\n⟨λ i j, or.cases_on (le_total i j) (λ hij, ⟨j, hij, le_refl j⟩) (λ hji, ⟨i, le_refl i, hji⟩)⟩\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/directed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8705972700870909, "lm_q1q2_score": 0.7815310682958658}}
{"text": "import data.set.basic data.set.lattice data.nat.parity\nimport tactic.linarith\n\nimport data.real.basic\n\nopen set nat function\n\nopen_locale classical\n\nvariables {α : Type*} {β : Type*} {γ : Type*} {I : Type*}\n\n/-!\n## Set exercises\n\nThese are collected from *Mathematics in Lean*.\n\nWe will go over the examples together, and then let you\nwork on the exercises.\n\nThere is more material here than can fit in the sessions,\nbut we will pick and choose as we go.\n-/\n\nsection set_variables\n\nvariable  x : α\nvariables s t u : set α\n\n/-!\n### Notation\n-/\n\n#check s ⊆ t        -- \\sub\n#check x ∈ s        -- \\in or \\mem\n#check x ∉ s        -- \\notin\n#check s ∩ t        -- \\i or \\cap\n#check s ∪ t        -- \\un or \\cup\n#check (∅ : set α)  -- \\empty\n\n/-!\n### Examples\n-/\n\n-- Three proofs of the same fact.\n-- The first two expand definitions explicitly,\n-- while the third forces Lean to do the unfolding.\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  rw [subset_def, inter_def, inter_def],\n  rw [subset_def] at h,\n  finish,\nend\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  simp only [subset_def, mem_inter_iff] at *,\n  rintros x ⟨xs, xu⟩,\n  exact ⟨h _ xs, xu⟩,\nend\n\nexample (h : s ⊆ t) : s ∩ u ⊆ t ∩ u :=\nbegin\n  intros x xsu,\n  exact ⟨h xsu.1, xsu.2⟩\nend\n\n-- Use `cases` or `rcases` or `rintros` with union.\n-- Two proofs of the same fact, one longer and one shorter.\n\nexample : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) :=\nbegin\n  intros x hx,\n  have xs : x ∈ s := hx.1,\n  have xtu : x ∈ t ∪ u := hx.2,\n  cases xtu with xt xu,\n  { left,\n    show x ∈ s ∩ t,\n    exact ⟨xs, xt⟩ },\n  right,\n  show x ∈ s ∩ u,\n  exact ⟨xs, xu⟩\nend\n\nexample : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) :=\nbegin\n  rintros x ⟨xs, xt | xu⟩,\n  { left, exact ⟨xs, xt⟩ },\n  right, exact ⟨xs, xu⟩\nend\n\n-- Two examples with set difference.\n-- Type it as ``\\\\``.\n-- ``x ∈ s \\ t`` expands to ``x ∈ s ∧ x ∉ t``.\n\nexample : s \\ t \\ u ⊆ s \\ (t ∪ u) :=\nbegin\n  intros x xstu,\n  have xs : x ∈ s := xstu.1.1,\n  have xnt : x ∉ t := xstu.1.2,\n  have xnu : x ∉ u := xstu.2,\n  split,\n  { exact xs }, dsimp,\n  intro xtu, -- x ∈ t ∨ x ∈ u\n  cases xtu with xt xu,\n  { show false, from xnt xt },\n  show false, from xnu xu\nend\n\nexample : s \\ t \\ u ⊆ s \\ (t ∪ u) :=\nbegin\n  rintros x ⟨⟨xs, xnt⟩, xnu⟩,\n  use xs,\n  rintros (xt | xu); contradiction\nend\n\n/-!\n### Exercises\n-/\n\nexample : (s ∩ t) ∪ (s ∩ u) ⊆ s ∩ (t ∪ u):=\nsorry\n\nexample : s \\ (t ∪ u) ⊆ s \\ t \\ u :=\nsorry\n\n/-!\n### Proving two sets are equal\n-/\n\n-- the ext tactic\n\nexample : s ∩ t = t ∩ s :=\nbegin\n  ext x,\n  -- simp only [mem_inter_eq],  -- optional.\n  split,\n  { rintros ⟨xs, xt⟩, exact ⟨xt, xs⟩ },\n  rintros ⟨xt, xs⟩, exact ⟨xs, xt⟩\nend\n\nexample : s ∩ t = t ∩ s :=\nby ext x; simp [and.comm]\n\n/-!\n### Exercises\n-/\n\nexample : s ∩ (s ∪ t) = s :=\nsorry\n\nexample : s ∪ (s ∩ t) = s :=\nsorry\n\nexample : (s \\ t) ∪ t = s ∪ t :=\nsorry\n\nexample : (s \\ t) ∪ (t \\ s) = (s ∪ t) \\ (s ∩ t) :=\nsorry\n\n/-!\n### Set-builder notation\n-/\n\ndef evens : set ℕ := {n | even n}\ndef odds :  set ℕ := {n | ¬ even n}\n\nexample : evens ∪ odds = univ :=\nbegin\n  rw [evens, odds],\n  ext n,\n  simp,\n  apply classical.em\nend\n\nexample : s ∩ t = {x | x ∈ s ∧ x ∈ t} := rfl\nexample : s ∪ t = {x | x ∈ s ∨ x ∈ t} := rfl\nexample : (∅ : set α) = {x | false} := rfl\nexample : (univ : set α) = {x | true} := rfl\n\nexample (x : ℕ) (h : x ∈ (∅ : set ℕ)) : false :=\nh\n\nexample (x : ℕ) : x ∈ (univ : set ℕ) :=\ntrivial\n\n/-!\n### Exercise\n-/\n\n-- Use `intro n` to unfold the definition of subset,\n-- and use the simplifier to reduce the\n-- set-theoretic constructions to logic.\n-- We also recommend using the theorems\n-- ``prime.eq_two_or_odd`` and ``even_iff``.\n\nexample : { n | nat.prime n } ∩ { n | n > 2} ⊆ { n | ¬ even n } :=\nsorry\n\n/-!\nIndexed unions\n-/\n\n-- See *Mathematics in Lean* for a discussion of\n-- bounded quantifiers, which we will skip here.\n\nsection\n\n-- We can use any index type in place of ℕ\nvariables A B : ℕ → set α\n\nexample : s ∩ (⋃ i, A i) = ⋃ i, (A i ∩ s) :=\nbegin\n  ext x,\n  simp only [mem_inter_iff, mem_Union],\n  split,\n  { rintros ⟨xs, ⟨i, xAi⟩⟩,\n    exact ⟨i, xAi, xs⟩ },\n  rintros ⟨i, xAi, xs⟩,\n  exact ⟨xs, ⟨i, xAi⟩⟩\nend\n\nexample : (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\nbegin\n  ext x,\n  simp only [mem_inter_iff, 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 ⟨h1, h2⟩ i,\n  split,\n  { exact h1 i },\n  exact h2 i\nend\n\nend\n\n/-!\n### Exercise\n-/\n\n-- One direction requires classical logic!\n-- We recommend using ``by_cases xs : x ∈ s``\n-- at an appropriate point in the proof.\n\nsection\n\nvariables A B : ℕ → set α\n\nexample : s ∪ (⋂ i, A i) = ⋂ i, (A i ∪ s) :=\nsorry\n\nend\n\n/-\nMathlib also has bounded unions and intersections,\n`⋃ x ∈ s, f x` and `⋂ x ∈ s, f x`,\nand set unions and intersections, `⋃₀ s` and `⋂₀ s`,\nwhere `s : set α`.\n\nSee *Mathematics in Lean* for details.\n-/\n\nend set_variables\n\n/-!\n### Functions\n-/\n\nsection function_variables\n\nvariable  f : α → β\nvariables s t : set α\nvariables u v : set β\nvariable  A : I → set α\nvariable  B : I → set β\n\n#check f '' s\n#check image f s\n#check f ⁻¹' u    -- type as \\inv' and then hit space or tab\n#check preimage f u\n\nexample : f '' s = {y | ∃ x, x ∈ s ∧ f x = y} := rfl\nexample : f ⁻¹' u = {x | f x ∈ u } := rfl\n\nexample : f ⁻¹' (u ∩ v) = f ⁻¹' u ∩ f ⁻¹' v :=\nby { ext, refl }\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y, split,\n  { rintros ⟨x, xs | xt, rfl⟩,\n    { left, use [x, xs] },\n    right, use [x, xt] },\n  rintros (⟨x, xs, rfl⟩ | ⟨x, xt, rfl⟩),\n  { use [x, or.inl xs] },\n  use [x, or.inr xt]\nend\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nbegin\n  intros x xs,\n  show f x ∈ f '' s,\n  use [x, xs]\nend\n\n/-!\n### Exercises\n-/\n\nexample : f '' s ⊆ u ↔ s ⊆ f ⁻¹' u :=\nsorry\n\nexample (h : injective f) : f ⁻¹' (f '' s) ⊆ s :=\nsorry\n\nexample : f '' (f⁻¹' u) ⊆ u :=\nsorry\n\nexample (h : surjective f) : u ⊆ f '' (f⁻¹' u) :=\nsorry\n\nexample (h : s ⊆ t) : f '' s ⊆ f '' t :=\nsorry\n\nexample (h : u ⊆ v) : f ⁻¹' u ⊆ f ⁻¹' v :=\nsorry\n\nexample : f ⁻¹' (u ∪ v) = f ⁻¹' u ∪ f ⁻¹' v :=\nsorry\n\nexample : f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=\nsorry\n\nexample (h : injective f) : f '' s ∩ f '' t ⊆ f '' (s ∩ t) :=\nsorry\n\nexample : f '' s \\ f '' t ⊆ f '' (s \\ t) :=\nsorry\n\nexample : f ⁻¹' u \\ f ⁻¹' v ⊆ f ⁻¹' (u \\ v) :=\nsorry\n\nexample : f '' s ∩ v = f '' (s ∩ f ⁻¹' v) :=\nsorry\n\nexample : f '' (s ∩ f ⁻¹' u) ⊆ f '' s ∪ u :=\nsorry\n\nexample : s ∩ f ⁻¹' u ⊆ f ⁻¹' (f '' s ∩ u) :=\nsorry\n\nexample : s ∪ f ⁻¹' u ⊆ f ⁻¹' (f '' s ∪ u) :=\nsorry\n\nexample : f '' (⋃ i, A i) = ⋃ i, f '' A i :=\nsorry\n\nexample : f '' (⋂ i, A i) ⊆ ⋂ i, f '' A i :=\nsorry\n\nexample (i : I) (injf : injective f) : (⋂ i, f '' A i) ⊆ f '' (⋂ i, A i) :=\nsorry\n\nexample : f ⁻¹' (⋃ i, B i) = ⋃ i, f ⁻¹' (B i) :=\nsorry\n\nexample : f ⁻¹' (⋂ i, B i) = ⋂ i, f ⁻¹' (B i) :=\nsorry\n\n/-\nThere is a lot more in *Mathematics in Lean* that we will not have time for!\nThere is a discussion of injectivity, more exercises on images and ranges,\nand a discussion of inverses.\n\nBut we will close with on last exercise. Remember that `surjective f`\nsays `∀ y, ∃ x, f x = y`.\n\nSee if you can understand the proof of Cantor's famous theorem that there is no\nsurjective function from its set to its powerset, and\nfill in the two lines that are missing.\n-/\n\ntheorem Cantor : ∀ f : α → set α, ¬ surjective f :=\nbegin\n  intros f surjf,\n  let S := { i | i ∉ f i},\n  rcases surjf S with ⟨j, h⟩,\n  have h₁ : j ∉ f j,\n  { intro h',\n    have : j ∉ f j,\n      { by rwa h at h' },\n    contradiction },\n  have h₂ : j ∈ S,\nsorry\n    ,\n  have h₃ : j ∉ S,\nsorry\n    ,\n  contradiction\nend\n\nend function_variables\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/lftcm2020_exercises_sources/tuesday/sets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8840392695254319, "lm_q1q2_score": 0.781525435464805}}
{"text": "-- La relación menor es irreflexiva en los reales\n-- ==============================================\n\nimport data.real.basic\nimport tactic\n\nvariable {x : ℝ}\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que la relación menor es\n-- irreflexiva en los reales.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : ¬ x < x :=\nbegin\n  intro h1,\n  rw lt_iff_le_and_ne at h1,\n  cases h1 with h2 h3,\n  -- clear h2,\n  -- change x = x → false at h3,\n  apply h3,\n  refl,\nend\n\n-- 2ª demostración\nexample : ¬ x < x :=\nbegin\n  intro h1,\n  rw lt_iff_le_and_ne at h1,\n  cases h1 with h2 h3,\n  apply h3,\n  refl,\nend\n\n-- 3ª demostración\nexample : ¬ x < x :=\nbegin\n  intro h1,\n  cases (lt_iff_le_and_ne.mp h1) with h2 h3,\n  apply h3,\n  refl,\nend\n\n-- 4ª demostración\nexample : ¬ x < x :=\nbegin\n  intro h1,\n  apply (lt_iff_le_and_ne.mp h1).2,\n  refl,\nend\n\n-- 5ª demostración\nexample : ¬ x < x :=\nbegin\n  intro h1,\n  exact absurd rfl (lt_iff_le_and_ne.mp h1).2,\nend\n\n-- 6ª demostración\nexample : ¬ x < x :=\nλ h, absurd rfl (lt_iff_le_and_ne.mp h).2\n\n-- 7ª demostración\nexample : ¬ x < x :=\nassume h1 : x < x,\nhave h2 : x ≤ x ∧ x ≠ x,\n  from lt_iff_le_and_ne.mp h1,\nhave h3 : x ≠ x,\n  from and.right h2,\nhave h4 : x = x,\n  from rfl,\nshow false,\n  from absurd h4 h3\n\n-- 8ª demostración\nexample : ¬ x < x :=\nassume h1 : x < x,\nhave h2 : x ≤ x ∧ x ≠ x,\n  from lt_iff_le_and_ne.mp h1,\nabsurd rfl (and.right h2)\n\n-- 9ª demostración\nexample : ¬ x < x :=\nassume h1 : x < x,\nabsurd rfl (and.right (lt_iff_le_and_ne.mp h1))\n\n-- 10ª demostración\nexample : ¬ x < x :=\nassume h1 : x < x,\nabsurd rfl (lt_iff_le_and_ne.mp h1).2\n\n-- 11ª demostración\nexample : ¬ x < x :=\nλ h, absurd rfl (lt_iff_le_and_ne.mp h).2\n\n-- 12ª demostración\nexample : ¬ x < x :=\n-- by library_search\nirrefl x\n\n-- 12ª demostración\nexample : ¬ x < x :=\n-- by hint\nby simp\n\n-- 13ª demostración\nexample : ¬ x < x :=\nby finish\n\n-- 14ª demostración\nexample : ¬ x < x :=\nby norm_num\n\n-- 15ª demostración\nexample : ¬ x < x :=\nby linarith\n\n-- 16ª demostración\nexample : ¬ x < x :=\nby nlinarith\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_relacion_menor_es_irreflexiva_en_los_reales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970811069351, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.7814472138638062}}
{"text": "-- Suma_de_cubos_de_impares.lean\n-- Suma de cubos de impares\n-- José A. Alonso Jiménez\n-- Sevilla, 26 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    1³ + 3³ + 5³ + ... + (2n-1)³ = n²(2n²-1)\n-- ---------------------------------------------------------------------\n\nimport algebra.big_operators\nimport tactic\nopen finset nat\n\nopen_locale big_operators\nset_option pp.structure_projections false\n\nvariable (n : ℕ)\n\nexample :\n  ∑ k in Ico 1 (n+1), (2*k-1)^3 = n^2*(2*n^2-1) :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { calc ∑ k in Ico 1 (succ n + 1), (2*k - 1)^3\n         = (∑ k in Ico 1 (succ n), (2*k - 1)^3) + (2 * succ n - 1)^3\n             : sum_Ico_succ_top (succ_pos n) (λ k, (2*k - 1)^3)\n     ... = n^2 * (2*n^2 - 1) + (2 * succ n - 1)^3\n             : by {congr; rw HI}\n     ... = n^2 * (2*n^2 - 1) + (2*n + 1)^3\n             : by congr\n     ... = n^2 * (2*n^2 - 1) + (1 + 6*n + 12*n^2 + 8*n^3)\n             : by nlinarith\n     ... = (2*n^4 - n^2) + (1 + 6*n + 12*n^2 + 8*n^3)\n             : by {congr' 1; zify; sorry}\n     ... = 2*n^4 + 8*n^3 + 11*n^2 + 6*n + 1\n             : sorry\n     ... = succ n ^ 2 * (2 * succ n ^ 2 - 1)\n             : sorry },\nend\n\nexample : n * (n - 1) = n^2 - n := sorry\nexample : n^2 * (2*n^2 - 1) = n^2*2*n^2 - n^2*1 := sorry\n\nexample : (n + 1) ^ 2 = n^2 + 2*n + 1 := by nlinarith\n\nexample : (2 * n + 1) ^ 3 = 1 + 6*n + 12*n^2 + 8*n^3 := by nlinarith\n\n-- Referencia: \"Sum of sequence of odd cubes\" https://bit.ly/3EPWocw en\n-- ProofWiki.\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_cubos_de_impares.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7813374098566899}}
{"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\nSome basic lemmas about integers.  I should check whether the\nnew coercion tactic makes them trivial.\n\n-/\n\nimport data.fintype.basic data.nat.sqrt\n\nlemma int.lt_succ_iff {n m : ℤ} : n < m + 1 ↔ n ≤ m := \n ⟨int.le_of_lt_add_one,int.lt_add_one_of_le⟩ \n\nlemma nat.square_le {n m : ℕ} : m ^ 2 ≤ n ↔ m ≤ n.sqrt := \n ⟨λ h0, le_of_not_gt (λ h1, not_le_of_gt ((pow_two m).symm.subst (nat.sqrt_lt.mp h1)) h0),\n  λ h0, le_of_not_gt (λ h1,not_le_of_gt (nat.sqrt_lt.mpr ((pow_two m).subst h1)) h0)⟩ \n\nlemma nat.square_lt {n m : ℕ} : m ^ 2 < n.succ ↔ m ≤ n.sqrt :=\n (@nat.lt_succ_iff (m ^ 2) n).trans (@nat.square_le n m)\n\nlemma int.abs_le {n m : ℤ} : abs m ≤ n ↔ (- n ≤ m ∧ m ≤ n) := \nbegin\n by_cases hm : 0 ≤ m,\n { rw[abs_of_nonneg hm],\n   exact ⟨ \n     λ hmn, ⟨le_trans (neg_nonpos_of_nonneg (le_trans hm hmn)) hm,hmn⟩,\n     λ hmn, hmn.right\n      ⟩ \n },{\n   let hma := le_of_lt (lt_of_not_ge hm),\n   let hmb := neg_nonneg_of_nonpos hma,\n   rw[abs_of_nonpos hma],\n   exact ⟨ \n     λ hmn, ⟨(neg_neg m) ▸ (neg_le_neg hmn),le_trans (le_trans hma hmb) hmn⟩,\n     λ hmn, (neg_neg n) ▸ (neg_le_neg hmn.left), \n    ⟩\n }\nend\n\nlemma int.abs_le' {n : ℕ} {m : ℤ} : m.nat_abs ≤ n ↔ (- (n : ℤ) ≤ m ∧ m ≤ n) := \nbegin\n let h := @int.abs_le n m,\n rw[int.abs_eq_nat_abs,int.coe_nat_le] at h,\n exact h,\nend\n\nlemma int.abs_square (n : ℤ) : n ^ 2 = (abs n) ^ 2 := begin\n by_cases h0 : n ≥ 0,\n {rw[abs_of_nonneg h0]},\n {rw[abs_of_neg (lt_of_not_ge h0),pow_two,pow_two,neg_mul_neg],}\nend\n\nlemma int.abs_square' (n : ℤ) : n ^ 2 = ((int.nat_abs n) ^ 2 : ℕ) :=\n calc \n   n ^ 2 = n * n : pow_two n\n   ... = ↑ (n.nat_abs * n.nat_abs) : int.nat_abs_mul_self.symm\n   ... = ↑ (n.nat_abs ^ 2 : ℕ) : by rw[(pow_two n.nat_abs).symm]\n\nlemma int.square_le {n : ℕ} {m : ℤ} : \n m ^ 2 ≤ n ↔ - (n.sqrt : ℤ) ≤ m ∧ m ≤ n.sqrt := \nbegin\n rw[int.abs_square',int.coe_nat_le,nat.square_le,int.abs_le'],\nend\n\nlemma int.square_lt {n : ℕ} {m : ℤ} : \n m ^ 2 < n.succ ↔ - (n.sqrt : ℤ) ≤ m ∧ m ≤ n.sqrt := \nbegin\n rw[int.abs_square',int.coe_nat_lt,nat.square_lt,int.abs_le'],\nend\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/int_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294588, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.781280406957952}}
{"text": "import .list ...mathlib.data.nat.gcd\n\nnamespace nat \n\ndef divides (m n : nat) : Prop := ∃ k, m * k = n \n\nlemma divisor_le (m n) : divides m n → n ≠ 0 → m ≤ n := \nbegin\n  intros h hn, cases h with k hk, cases k with k,\n  exfalso, apply hn, rewrite mul_zero at hk, rewrite hk,\n  rewrite eq.symm hk, rewrite nat.mul_succ,\n  apply nat.le_add_left\nend\n\nlemma ex_pred_of_neq_zero (m) : m ≠ 0 → ∃ m', m = nat.succ m' := \nbegin\n  intro hm, cases m with m', exfalso, apply hm, refl,\n  existsi m', refl\nend\n\nlemma gt_zero_of_neq_zero (n) : n ≠ 0 → n > 0 :=\nbegin\n  intro h, cases n, exfalso, apply h, refl, \n  apply nat.zero_lt_succ\nend\n\nlemma gcd_divides : ∀ (m n : nat), divides (nat.gcd m n) m ∧ divides (nat.gcd m n) n\n| 0 n := \n  begin \n    apply and.intro, existsi 0, rewrite mul_zero,\n    unfold nat.gcd, existsi 1, rewrite mul_one\n  end\n| (m+1) n :=\n  have (n % nat.succ m < nat.succ m), from (nat.mod_lt _ $ nat.succ_pos _),\n  begin\n    unfold nat.gcd, apply and.intro, \n    apply and.elim_right (gcd_divides _ _),\n    cases (gcd_divides (n % nat.succ m) (nat.succ m)) with h1 h2,\n    cases h1 with i hi, cases h2 with j hj,\n    existsi (j * (n/(m+1))) + i,\n    rewrite mul_add, rewrite hi,\n    rewrite eq.symm (mul_assoc _ _ _),\n    rewrite hj, rewrite add_comm,\n    apply nat.mod_add_div\n  end\n\nlemma mul_nonzero {m n : nat} : m ≠ 0 → n ≠ 0 → m * n ≠ 0 := \nbegin\n  intros hm hn hc, apply hm,\n  apply eq.trans, apply eq.symm, \n  apply nat.mul_div_cancel,\n  apply gt_zero_of_neq_zero, apply hn,\n  rewrite hc, apply nat.zero_div\nend\n\ntheorem gcd_neq_zero : ∀ (m n : nat), m ≠ 0 → n ≠ 0 → (nat.gcd m n) ≠ 0 \n| 0 n hm hn := begin exfalso, apply hm, refl end\n| (nat.succ m) n hm hn := \n  have (n % nat.succ m < nat.succ m), from (nat.mod_lt _ $ nat.succ_pos _),\n  begin\n    unfold nat.gcd, \n    apply (@classical.by_cases (n % nat.succ m ≠ 0) _ _ _); intro h,\n    apply gcd_neq_zero, apply h, intro hc, cases hc,\n    rewrite (classical.by_contradiction h), intro hc, cases hc \n  end\n\nlemma lcm_nonzero (m n : nat) : m ≠ 0 → n ≠ 0 → (nat.lcm m n) ≠ 0 :=\nbegin\n  intros hm hn hc,\n  have h := nat.gcd_mul_lcm m n,\n  rewrite hc at h, rewrite mul_zero at h,\n  apply nat.mul_nonzero hm hn, \n  apply eq.symm h\nend\n\nlemma of_nat_neq_zero (n : nat) : n ≠ 0 → int.of_nat n ≠ 0 :=\nbegin\n  intro hn, cases n, exfalso, apply hn, refl,\n  intro hc, cases hc\nend\n\nlemma neq_zero_of_of_nat_neq_zero {n : nat} : int.of_nat n ≠ 0 → n ≠ 0 :=\nbegin\n  cases n, intro hc, exfalso, apply hc, refl,\n  intros _ hc, cases hc \nend\n\n\nend nat\n\n", "meta": {"author": "avigad", "repo": "qelim", "sha": "b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60", "save_path": "github-repos/lean/avigad-qelim", "path": "github-repos/lean/avigad-qelim/qelim-b7d22864f1f0a2d21adad0f4fb3fc7ba665f8e60/common/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7812803983061329}}
{"text": "set_option trace.simplify.rewrite true\nopen nat\n\n\n-- 1.1.4\nuniverse u\nconstants α β γ : Type \n\n\ndef some_fun_of_type : (α → β → γ) → ((β → α) → β) → α → γ := \nλ f, λ g, λ a, f a (g(λ h, a))\n\n/-\ninductive type-name (params1 : type1) . . . (paramsk : typek) : Type\n| constructor-name1 : constructor-type1\n.\n.\n.\n| constructor-namen : constructor-typen\n-/\n\ninductive aexp : Type\n| num : ℤ → aexp\n| var : string → aexp\n| add : aexp → aexp → aexp\n| sub : aexp → aexp → aexp\n| mul : aexp → aexp → aexp\n| div : aexp → aexp → aexp\n\ndef eval (env : string → ℤ) : aexp → ℤ \n| (aexp.num i) := i\n| (aexp.var x) := env x\n| (aexp.add e1 e2) := eval e1 + eval e2\n| (aexp.sub e1 e2) := eval e1 - eval e2\n| (aexp.mul e1 e2) := eval e1 * eval e2\n| (aexp.div e1 e2) := eval e1 / eval e2\n\n-- 2.1\n\nlemma fst_of_two_props :\n∀a b : Prop, a → b → a :=\nbegin\nintros a b,\nintros ha hb,\nassumption,\nend\n\nlemma fst_of_two_props2 (a b : Prop) (ha : a) (hb : b) :\na :=\nbegin\nexact ha,\nend\n\nlemma fst_of_two_props3 (a b : Prop) (ha : a) (hb : b) :\na :=\nby apply ha\n\nlemma prop_comp (a b c : Prop) (hab : a → b) (hbc : b → c) :\na → c :=\nbegin\nintro ha,\napply hbc,\napply hab,\napply ha,\nend\n\n-- 2.3\nlemma and_swap (a b : Prop) :\na ∧ b → b ∧ a :=\nbegin\nintro hab,\napply and.intro,\napply and.elim_right,\nexact hab,\napply and.elim_left,\nexact hab,\nend\n\nlemma and_swap2 :\n∀a b : Prop, a ∧ b → b ∧ a :=\nbegin\nintros a b hab,\napply and.intro,\n{ exact and.elim_right hab },\n{ exact and.elim_left hab }\nend\n\nlemma nat_exists_double_iden :\n∃n : ℕ, n = n :=\nbegin\napply exists.intro 0,\nrefl,\nend\n\n-- 2.4\nlemma cong_fst_arg {α : Type} (a a' b : α)\n(f : α → α → α) (ha : a = a') :\nf a b = f a' b :=\nbegin\napply eq.subst ha,\napply eq.refl,\nend\n\nlemma cong_two_args {α : Type} (a a' b b' : α)\n(f : α → α → α) (ha : a = a') (hb : b = b') :\nf a b = f a' b' :=\nbegin\napply eq.subst ha,\napply eq.subst hb,\napply eq.refl\nend\n\nlemma cong_two_args2 {α : Type} (a a' b b' : α)\n(f : α → α → α) (ha : a = a') (hb : b = b') :\nf a b = f a' b' :=\nbegin\nrw ha,\nrw hb,\nend\n\nlemma cong_two_args3 {α : Type} (a a' b b' : α)\n(f : α → α → α) (ha : a = a') (hb : b = b') :\nf a b = f a' b' :=\nbegin\nsimp[*] at *,\nend\n \n-- 2.6\nnamespace myadd\n\ndef add : ℕ → ℕ → ℕ \n| m nat.zero := m\n| m (nat.succ n) := nat.succ (add m n)\n\nlemma add_zero (n : ℕ) :\nadd 0 n = n :=\nbegin\ninduction n,\n{ refl },\n{ simp [add, n_ih] }\nend\n\nlemma add_succ (m n : ℕ) :\nadd (nat.succ m) n = nat.succ (add m n) :=\nbegin\ninduction n,\n{ refl },\n{ simp [add, n_ih] }\nend\n\nlemma add_comm (m n : ℕ) :\nadd m n = add n m :=\nbegin\ninduction n,\n{ simp [add, add_zero] },\n{ simp [add, add_succ, n_ih] }\nend\n\nlemma add_assoc (l m n : ℕ) :\nadd (add l m) n = add l (add m n) :=\nbegin\ninduction n,\n{ refl },\n{ simp [add, n_ih] }\nend\n\n@[instance] def add.is_commutative : is_commutative ℕ add :=\n{ comm := add_comm }\n@[instance] def add.is_associative : is_associative ℕ add :=\n{ assoc := add_assoc }\n\n\nend myadd", "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/21_01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7812455985388937}}
{"text": "import .love05_inductive_predicates_demo\n\n\n/-! # LoVe Demo 12: Basic Mathematical Structures\n\nWe introduce definitions and proofs about basic mathematical structures such as\ngroups, fields, and linear orders. -/\n\n\nset_option pp.beta true\n\nnamespace LoVe\n\n\n/-! ## Type Classes over a Single Binary Operator\n\nMathematically, a __group__ is a set `G` with a binary operator `• : G × G → G`\nwith the following properties, called __group axioms__:\n\n* Associativity: For all `a, b, c ∈ G`, we have `(a • b) • c = a • (b • c)`.\n* Identity element: There exists an element `e ∈ G` such that for all `a ∈ G`,\n  we have `e • a = a`.\n* Inverse element: For each `a ∈ G`, there exists an inverse element\n  `inv(a) ∈ G` such that `inv(a) • a = e`.\n\nExamples of groups are\n* `ℤ` with `+`;\n* `ℝ` with `+`;\n* `ℝ \\ {0}` with `*`.\n\nIn Lean, a type class for groups can be defined as follows: -/\n\nnamespace monolithic_group\n\n@[class] structure group (α : Type) : Type :=\n(mul          : α → α → α)\n(one          : α)\n(inv          : α → α)\n(mul_assoc    : ∀a b c, mul (mul a b) c = mul a (mul b c))\n(one_mul      : ∀a, mul one a = a)\n(mul_left_inv : ∀a, mul (inv a) a = one)\n\nend monolithic_group\n\n/-! In Lean, however, group is part of a larger hierarchy of algebraic\nstructures:\n\nType class               | Properties                               | Examples\n------------------------ | -----------------------------------------|-------------------\n`semigroup`              | associativity of `*`                     | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`monoid`                 | `semigroup` with unit `1`                | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`left_cancel_semigroup`  | `semigroup` with `c * a = c * b → a = b` |\n`right_cancel_semigroup` | `semigroup` with `a * c = b * c → a = b` |\n`group`                  | `monoid` with inverse `⁻¹`               |\n\nMost of these structures have commutative versions: `comm_semigroup`,\n`comm_monoid`, `comm_group`.\n\nThe __multiplicative__ structures (over `*`, `1`, `⁻¹`) are copied to produce\n__additive__ versions (over `+`, `0`, `-`):\n\nType class                   | Properties                                   | Examples\n---------------------------- | ---------------------------------------------|-------------------\n`add_semigroup`              | associativity of `+`                         | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_monoid`                 | `add_semigroup` with unit `0`                | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_left_cancel_semigroup`  | `add_semigroup` with `c + a = c + b → a = b` | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_right_cancel_semigroup` | `add_semigroup` with `a + c = b + c → a = b` | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`add_group`                  | `add_monoid` with inverse `-`                | `ℝ`, `ℚ`, `ℤ` -/\n\n#print group\n#print add_group\n\n/-! Let us define our own type, of integers modulo 2, and register it as an\nadditive group. -/\n\ninductive ℤ₂ : Type\n| zero\n| one\n\ndef ℤ₂.add : ℤ₂ → ℤ₂ → ℤ₂\n| ℤ₂.zero a       := a\n| a       ℤ₂.zero := a\n| ℤ₂.one  ℤ₂.one  := ℤ₂.zero\n\n@[instance] def ℤ₂.add_group : add_group ℤ₂ :=\n{ add          := ℤ₂.add,\n  add_assoc    :=\n    by intros a b c; simp [(+)]; cases a; cases b; cases c;\n      refl,\n  zero         := ℤ₂.zero,\n  zero_add     := by intro a; cases a; refl,\n  add_zero     := by intro a; cases a; refl,\n  neg          := λa, a,\n  add_left_neg := by intro a; cases a; refl }\n\n#reduce ℤ₂.one + 0 - 0 - ℤ₂.one\n\nlemma ℤ₂.add_right_neg:\n  ∀a : ℤ₂, a + - a = 0 :=\nadd_right_neg\n\n/-! Another example: Lists are an `add_monoid`: -/\n\n@[instance] def list.add_monoid {α : Type} :\n  add_monoid (list α) :=\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/-! ## Type Classes with Two Binary Operators\n\nMathematically, a __field__ is a set `F` such that\n\n* `F` forms a commutative group under an operator `+`, called addition, with\n  identity element `0`.\n* `F\\{0}` forms a commutative group under an operator `*`, called\n  multiplication.\n* Multiplication distributes over addition—i.e.,\n  `a * (b + c) = a * b + a * c` for all `a, b, c ∈ F`.\n\nIn Lean, fields are also part of a larger hierarchy:\n\nType class       |  Properties                                         | Examples\n-----------------|-----------------------------------------------------|-------------------\n`semiring`       | `monoid` and `add_comm_monoid` with distributivity  | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`comm_semiring`  | `semiring` with commutativity of `*`                | `ℝ`, `ℚ`, `ℤ`, `ℕ`\n`ring`           | `monoid` and `add_comm_group` with distributivity   | `ℝ`, `ℚ`, `ℤ`\n`comm_ring`      | `ring` with commutativity of `*`                    | `ℝ`, `ℚ`, `ℤ`\n`division_ring`  | `ring` with multiplicative inverse `⁻¹`             | `ℝ`, `ℚ`\n`field`          | `division_ring` with commutativity of `*`           | `ℝ`, `ℚ`\n`discrete_field` | `field` with decidable equality and `∀n, n / 0 = 0` | `ℝ`, `ℚ` -/\n\n#print field\n\n/-! Let us continue with our example: -/\n\ndef ℤ₂.mul : ℤ₂ → ℤ₂ → ℤ₂\n| ℤ₂.one  a       := a\n| a       ℤ₂.one  := a\n| ℤ₂.zero ℤ₂.zero := ℤ₂.zero\n\n@[instance] def ℤ₂.field : field ℤ₂ :=\n{ one            := ℤ₂.one,\n  mul            := ℤ₂.mul,\n  inv            := λa, a,\n  add_comm       := by intros a b; cases a; cases b; refl,\n  zero_ne_one    := by finish,\n  one_mul        := by intros a; cases a; refl,\n  mul_one        := by intros a; cases a; refl,\n  mul_inv_cancel := by intros a h; cases a; finish,\n  inv_mul_cancel := by intros a h; cases a; finish,\n  mul_assoc      :=\n    by intros a b c; cases a; cases b; cases c; refl,\n  mul_comm       := by intros a b; cases a; cases b; refl,\n  left_distrib   :=\n    by intros a b c; by cases a; cases b; cases c; refl,\n  right_distrib  :=\n    by intros a b c; by cases a; cases b; cases c; refl,\n  ..ℤ₂.add_group }\n\n#reduce (1 : ℤ₂) * 0 / (0 - 1)\n\n#reduce (3 : ℤ₂)\n\nlemma ring_example (a b : ℤ₂) :\n  (a + b) ^ 3 = a ^ 3 + 3 * a ^ 2 * b + 3 * a * b ^ 2 + b ^ 3 :=\nby ring\n\nlemma ring_exp_example (a b : ℤ₂) (n : ℕ):\n  (a + b) ^ (2 + n) =\n  (a + b) ^ n * (a ^ 2 + 2 * a * b + b ^ 2) :=\nby ring_exp\n\n/-! `ring` and `ring_exp` prove equalities over commutative rings and semirings\nby normalizing expressions. The `ring_exp` variant also normalizes exponents. -/\n\nlemma abel_example (a b : ℤ) :\n  a + b + 0 - (b + a + a) = - a :=\nby abel\n\n/-! `abel` proves equalities over additive commutative monoids and groups by\nnormalizing expressions.\n\n\n## Coercions\n\nWhen combining numbers form `ℕ`, `ℤ`, `ℚ`, and `ℝ`, we might want to cast from\none type to another. Lean has a mechanism to automatically introduce coercions,\nrepresented by `coe` (syntactic sugar: `↑`). `coe` can be set up to provide\nimplicit coercions between arbitrary types.\n\nMany coercions are already in place, including the following:\n\n* `coe : ℕ → α` casts `ℕ` to another semiring `α`;\n* `coe : ℤ → α` casts `ℤ` to another ring `α`;\n* `coe : ℚ → α` casts `ℚ` to another division ring `α`.\n\nFor example, this works, although negation `- n` is not defined on natural\nnumbers: -/\n\nlemma neg_mul_neg_nat (n : ℕ) (z : ℤ) :\n  (- z) * (- n) = z * n :=\nneg_mul_neg z n\n\n/-! Notice how Lean introduced a `↑` coercion: -/\n\n#print neg_mul_neg_nat\n\n/-! Another example: -/\n\nlemma neg_nat_mul_neg (n : ℕ) (z : ℤ) :\n  (- n : ℤ) * (- z) = n * z :=\nneg_mul_neg n z\n\n#print neg_nat_mul_neg\n\n/-! In proofs involving coercions, the tactic `norm_cast` can be convenient. -/\n\nlemma norm_cast_example_1 (m n : ℕ) (h : (m : ℤ) = (n : ℤ)) :\n  m = n :=\nbegin\n  norm_cast at h,\n  exact h\nend\n\nlemma norm_cast_example_2 (m n : ℕ) :\n  (m : ℤ) + (n : ℤ) = ((m + n : ℕ) : ℤ) :=\nby norm_cast\n\n/-! `norm_cast` moves coercions towards the inside of expressions, as a form of\nsimplification. Like `simp`, it will generally produce a subgoal.\n\n`norm_cast` relies on lemmas such as the following: -/\n\n#check nat.cast_add\n#check int.cast_add\n#check rat.cast_add\n\n\n/-! ### Lists, Multisets and Finite Sets\n\nFor finite collections of elements different structures are available:\n\n* lists: order and duplicates matter;\n* multisets: only duplicates matter;\n* finsets: neither order nor duplicates matter. -/\n\nlemma list_duplicates_example :\n  [2, 3, 3, 4] ≠ [2, 3, 4] :=\ndec_trivial\n\nlemma list_order_example :\n  [4, 3, 2] ≠ [2, 3, 4] :=\ndec_trivial\n\nlemma multiset_duplicates_example :\n  ({2, 3, 3, 4} : multiset ℕ) ≠ {2, 3, 4} :=\ndec_trivial\n\nlemma multiset_order_example :\n  ({2, 3, 4} : multiset ℕ) = {4, 3, 2} :=\ndec_trivial\n\nlemma finset_duplicates_example :\n  ({2, 3, 3, 4} : finset ℕ) = {2, 3, 4} :=\ndec_trivial\n\nlemma finsetorder_example :\n  ({2, 3, 4} : finset ℕ) = {4, 3, 2} :=\ndec_trivial\n\ndef list.elems : btree ℕ → list ℕ\n| btree.empty        := []\n| (btree.node a l r) := a :: list.elems l ++ list.elems r\n\ndef multiset.elems : btree ℕ → multiset ℕ\n| btree.empty        := ∅\n| (btree.node a l r) :=\n  {a} ∪ (multiset.elems l ∪ multiset.elems r)\n\ndef finset.elems : btree ℕ → finset ℕ\n| btree.empty        := ∅\n| (btree.node a l r) := {a} ∪ (finset.elems l ∪ finset.elems r)\n\n#eval list.sum [2, 3, 4]                          -- result: 9\n#eval multiset.sum ({2, 3, 4} : multiset ℕ)       -- result: 9\n#eval finset.sum ({2, 3, 4} : finset ℕ) (λn, n)   -- result: 9\n\n#eval list.prod [2, 3, 4]                         -- result: 24\n#eval multiset.prod ({2, 3, 4} : multiset ℕ)      -- result: 24\n#eval finset.prod ({2, 3, 4} : finset ℕ) (λn, n)  -- result: 24\n\n\n/-! ## Order Type Classes\n\nMany of the structures introduced above can be ordered. For example, the\nwell-known order on the natural numbers can be defined as follows: -/\n\ninductive nat.le : ℕ → ℕ → Prop\n| refl : ∀a : ℕ, nat.le a a\n| step : ∀a b : ℕ, nat.le a b → nat.le a (b + 1)\n\n/-! This is an example of a linear order. A __linear order__ (or\n__total order__) is a binary relation `≤` such that for all `a`, `b`, `c`, the\nfollowing properties hold:\n\n* Reflexivity: `a ≤ a`.\n* Transitivity: If `a ≤ b` and `b ≤ c`, then `a ≤ c`.\n* Antisymmetry: If `a ≤ b` and `b ≤ a`, then `a = b`.\n* Totality: `a ≤ b` or `b ≤ a`.\n\nIf a relation has the first three properties, it is a __partial order__. An\nexample is `⊆` on sets, finite sets, or multisets. If a relation has the first\ntwo properties, it is a __preorder__. An example is comparing lists by their\nlength.\n\nIn Lean, there are type classes for these different kinds of orders:\n`linear_order`, `partial_order`, and `preorder`. The `preorder` class has the\nfields\n\n    `le       : α → α → Prop`\n    `le_refl  : ∀a : α, le a a`\n    `le_trans : ∀a b c : α, le a b → le b c → le a c`\n\nThe `partial_order` class also has\n\n    `le_antisymm : ∀a b : α, le a b → le b a → a = b`\n\nand `linear_order` also has\n\n    `le_total : ∀a b : α, le a b ∨ le b a`\n\nWe can declare the preorder on lists that compares lists by their length as\nfollows: -/\n\n@[instance] def list.length.preord {α : Type} :\n  preorder (list α) :=\n{ le       := λxs ys, list.length xs ≤ list.length ys,\n  le_refl  := by intro xs; exact nat.le_refl _,\n  le_trans := by intros xs ys zs; exact nat.le_trans }\n\n/-! This instance introduces the infix syntax `≤` and the relations `≥`, `<`,\nand `>`: -/\n\nlemma list.length.preord_example {α : Type} (c : α) :\n  [c] > [] :=\ndec_trivial\n\n/-! Complete lattices (lecture 10) are formalized as another type class,\n`complete_lattice`, which inherits from `partial_order`.\n\nType classes combining orders and algebraic structures are also available:\n\n    `ordered_cancel_comm_monoid`\n    `ordered_comm_group ordered_semiring`\n    `linear_ordered_semiring`\n    `linear_ordered_comm_ring`\n    `linear_ordered_field`\n\nAll these mathematical structures relate `≤` and `<` with `0`, `1`, `+`, and `*`\nby monotonicity rules (e.g., `a ≤ b → c ≤ d → a + c ≤ b + d`) and cancellation\nrules (e.g., `c + a ≤ c + b → a ≤ b`). -/\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/love12_basic_mathematical_structures_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7812455939982551}}
{"text": "import data.set.basic tactic.interactive\n\n/-\nHere's Kevin's problem:\n\n  Let’s say I tell two of my tutees secret non-negative integers, and then I wrote\n  two distinct non-negative integers on my whiteboard; one is the sum of the two\n  secret integers, and the other one is not. I then take it in turns asking my\n  tutees whether they know the other tutee’s number! Prove that eventually one of\n  them will (truthfully) say “yes”.\n\nTo model this problem, we use a modal framework. A frame is a set of possible\nworlds. Each world represents the way things could be. In this case, we\nwill allow evolution of the set of possible worlds by using a changing predicate\nof \"live\" worlds that represents all the worlds that have not yet been excluded\nby some reasoning from a declaration of ignorance.\n-/\n\nsection\nparameters (X Y : nat)\n\n/-- In this model, we will store the things that are not public information\n  in the set of possible worlds. So the numbers X,Y on the blackboard are\n  parameters because there is no \"possibility\" about it, everyone knows what\n  they are. -/\nstructure world :=\n(A : nat) -- the number given to Alice\n(B : nat) -- the number given to Bob\n(consistent : A + B = X ∨ A + B = Y) -- the numbers can't contradict the whiteboard\n\ninstance world.inhabited : inhabited world := ⟨⟨X, 0, or.inl rfl⟩⟩\n\n/-- Given a set of \"live\" worlds, we can figure out which numbers\n  A thinks are possible for B to have -/\ndef A_thinks (w : world) (live : set world) : set nat :=\n{B' | ∃ w':world, w' ∈ live ∧ w'.A = w.A ∧ w'.B = B'}\n\n/-- Given a set of \"live\" worlds, we can figure out which numbers\n  B thinks are possible for A to have -/\ndef B_thinks (w : world) (live : set world) : set nat :=\n{A' | ∃ w':world, w' ∈ live ∧ w'.B = w.B ∧ w'.A = A'}\n\n/-- A knows the answer if the possible values she has for B's number is a singleton -/\ndef A_knows (w : world) (live) := ∃ n, A_thinks w live = {n}\n\n/-- B knows the answer if the possible values he has for A's number is a singleton -/\ndef B_knows (w : world) (live) := ∃ n, B_thinks w live = {n}\n\n/-- This is where the action happens. The set of \"live\" worlds is a\n  representation of the possible worlds that are eliminated in each stage\n  assuming that A and B keep saying they don't know the answer. The game\n  ends when one says they know the answer, so we only have to worry about\n  this path; we're going to show that it can't continue forever. -/\ndef live : ℕ → set world\n| 0     := set.univ -- initially no one knows anything, all possibilities are live\n| (n+1) :=\n  -- At stage n+1, if we assume that A and B both pass, then neither knows the answer\n  -- so all worlds where they figured it out are excluded\n  {w ∈ live n | ¬ A_knows w (live n) ∧ ¬ B_knows w (live n)}\n\n/- because we're mathematicians: -/\nlocal attribute [instance] classical.prop_decidable\n\n/- At this point, the main theorem we want to prove is that there is some stage where\n  either A or B solves the problem -/\ntheorem A_or_B_knows (w : world) : ∃ n, w ∈ live n ∧ (A_knows w (live n) ∨ B_knows w (live n)) :=\nbegin\n  /- We'll prove that at each stage, the worlds at the \"ends\" are lost, sweeping from\n    both sides (we only need one side to know that eventually all worlds are excluded). -/\n  suffices : ∀ (n) (w':world), w' ∈ live n → w'.A + n ≤ max X Y + w'.B,\n  { by_contra H,\n    replace H : ∀ n, w ∈ live n,\n    { simp [not_exists, not_or_distrib] at H,\n      intro n,\n      induction n with n; simp [live, *] },\n    have : w.A + (max X Y + w.B) < max X Y + w.B := this _ w (H (max X Y + w.B + 1)),\n    exact not_le_of_gt this (nat.le_add_left _ _) },\n  clear w, intros n w wl,\n  induction n with n IH generalizing w,\n  { refine add_le_add _ (nat.zero_le _),\n    refine le_trans (nat.le_add_right w.A w.B) _,\n    cases w.consistent; simp [h, le_max_left, le_max_right] },\n  { rcases wl with ⟨wl, HA, HB⟩,\n    refine lt_of_le_of_ne (IH _ wl) _,\n    intro he,\n    have A_thinks_other : ¬ ∀ k ∈ A_thinks w (live n), k = w.B,\n    { have A_thinks_B : w.B ∈ A_thinks w (live n) := ⟨_, wl, rfl, rfl⟩,\n      refine λ h, HA ⟨w.B, _⟩,\n      simp [set.set_eq_def],\n      exact λ k, ⟨h k, λ e, e.symm ▸ A_thinks_B⟩ },\n    have B_thinks_other : ¬ ∀ k ∈ B_thinks w (live n), k = w.A,\n    { have B_thinks_A : w.A ∈ B_thinks w (live n) := ⟨_, wl, rfl, rfl⟩,\n      refine λ h, HB ⟨w.A, _⟩,\n      simp [set.set_eq_def],\n      exact λ k, ⟨h k, λ e, e.symm ▸ B_thinks_A⟩ },\n    rcases not_ball.1 A_thinks_other with ⟨B', A_thinks_B', hB'⟩,\n    rcases A_thinks_B' with ⟨w₁, w₁l, w₁A, rfl⟩,\n    rcases not_ball.1 B_thinks_other with ⟨A', B_thinks_A', hA'⟩,\n    rcases B_thinks_A' with ⟨w₂, w₂l, w₂B, rfl⟩,\n    have := IH _ w₁l,\n    rw [w₁A, he] at this,\n    have w₁B := lt_of_le_of_ne (le_of_add_le_add_left this) (ne.symm hB'),\n    have := IH _ w₂l,\n    rw [w₂B, ← he] at this,\n    have w₂A := lt_of_le_of_ne (le_of_add_le_add_right this) hA',\n    have lt₁ := add_lt_add_of_le_of_lt (le_of_eq w₁A.symm) w₁B,\n    have lt₂ := add_lt_add_of_lt_of_le w₂A (le_of_eq w₂B),\n    /- at this point, the contradiction is clear, since A+B of w₁ is\n      less than A+B at w, which is less than A+B at w₂, while A+B is\n      in the set {X,Y} for any world. But proving this requires a\n      lot of case analysis -/\n    cases w₁.consistent with w₁h w₁h; rw w₁h at lt₁;\n    cases w.consistent with wh wh; rw wh at lt₁ lt₂;\n    try { apply lt_irrefl _ lt₁ };\n    cases w₂.consistent with w₂h w₂h; rw w₂h at lt₂;\n    try { apply lt_irrefl _ lt₂ };\n    exact lt_asymm lt₁ lt₂ }\nend\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/random_projects_mostly_students/Cris_integer_question/Mario_Modal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7812455894741736}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function world.\n\n## Level 2: the `intro` tactic.\n\nLet's make a function. Let's define the function on the natural\nnumbers which sends a natural number `n` to `3n+2`. In the example\nbelow you will see that our goal is `⊢ MyNat → MyNat`. A mathematician\nmight denote this set with some exotic name such as `Hom(ℕ,ℕ)`,\nbut computer scientists use notation `X → Y` to denote the set of\nfunctions from `X` to `Y` and this name definitely has its merits.\nIn type theory, `X → Y` is a type (the type of all functions from `X` to `Y`),\nand `f : X → Y` means that `f` is a term\nof this type, i.e., `f` is a function from `X` to `Y`.\n\nTo define a function `X → Y` we need to choose an arbitrary\nelement `x ∈ X` and then, perhaps using `x`, make an element of `Y`.\nThe Lean tactic for \"let `x ∈ X` be arbitrary\" is `intro x`.\n\n## Rule of thumb:\n\nIf your goal is `P → Q` then `intro p` will make progress.\n\nTo solve the goal below, you have to come up with a function from `MyNat`\nto `MyNat`. We can start with `intro n`\n\n(i.e. \"let `n ∈ ℕ` be arbitrary\") and note that our\nlocal context now looks like this:\n\n```\nn : MyNat\n⊢ MyNat\n```\n\nOur job now is to construct a natural number, which is\nallowed to depend on `n`. We can do this using `exact` and\nwriting a formula for the function we want to define. For example\nwe imported addition and multiplication at the top of this file,\nso `exact 3*n+2`\nwill close the goal, ultimately defining the function `f(n)=3n+2`.\n\n\n## Definition\n\nWe define a function from MyNat to MyNat.\n-/\nexample : MyNat → MyNat := by\n  intro n\n  exact 3*n+2\n\n/-!\nYou can hover your mouse over the tactics `intro` and `exact`\nto the documentation on these tactics in case you need a\nreminder later on.\nSee also [intro tactic](../Tactics/intro.lean.md)\n\n\nNext up [Level 3](./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/FunctionWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7812382749754921}}
{"text": "import MyNat.Power\nimport MultiplicationWorld.Level2 -- mul_one\nimport MultiplicationWorld.Level9 -- simp additions\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Power World\n\n## Level 6: `mul_pow`\n\nHere we use the `attribute [simp]` additions we made in\n[level 9 of Multiplication World](../MultiplicationWorld/Level9.lean.md)\nso that the `simp` tactic can simplify expressions involving `*`.\n\n## Lemma\nFor all naturals `a`, `b`, `n`, we have `(ab) ^ n = a ^ nb ^ n`.\n-/\nlemma mul_pow (a b n : MyNat) : (a * b) ^ n = a ^ n * b ^ n := by\n  induction n with\n  | zero =>\n    rw [zero_is_0]\n    repeat rw [pow_zero]\n    rw [mul_one]\n  | succ n ih =>\n    repeat rw [pow_succ]\n    rw [ih]\n    simp\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/PowerWorld/Level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7812382714849073}}
{"text": "import Mathlib.Tactic.Basic\n\n/-!\n## The Curry–Howard Correspondence\n\nYou will likely have noticed that the same symbol `→` is used both for implication\n(e.g., `false → true`) and as the type constructor of functions (e.g., `ℤ → ℕ`).\nSimilarly, ∀ is used both as a quantifier and to specify dependent types. Without\ncontext, we cannot tell whether `a → b` refers to the type of a function with domain\n`a` and codomain `b` or to the proposition “`a` implies `b`,” and similarly,\n`∀x : a, b[x]` can denote a proposition or a dependent type.\n\nIt turns out that not only the two pairs of concepts look the same, they are the\nsame. This is called the _Curry–Howard correspondence_. It is also called the\n_PAT principle_, where PAT is a double mnemonic:\n\n> PAT = propositions as types&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAT = proofs as terms\n\nFurthermore, because types are also terms, we also have that propositions are\nterms. However, PAT is not a quadruple mnemonic (<span style=\"text-decoration:line-through\">PAT = proofs as types</span>).\n\nHaskell Curry and William Alvin Howard noticed that for some logics, propositions are isomorphic to\ntypes, and proofs are isomorphic to terms. Hence, in dependent type theory, we _identify_ proofs with\nterms as well as propositions with types, a considerable economy of concepts. The question “Is `H` a\nproof of `P`?” becomes equivalent to “Does the term `H` have type `P`?” As a result, inside of Lean, there\nis no proof checker, only a type checker.\n\nLet us go through the dramatis personae one by one. We use the metavariables `σ`, `τ` for types;\n`P`, `Q` for propositions; `t`, `u`, `x` for terms; and `h`, `G`, `H`, for proofs. Starting with\n“propositions as types,” for types, we have the following:\n\n1. `σ → τ` is the type of (total) functions from `σ` to `τ`.\n2. `∀x : σ, τ[x]` is the dependent function type from `x : σ` to `τ[x]`.\n\nIn contrast, for propositions, we have the following:\n1. `P → Q` can be read as “`P` implies `Q`,” or as the type of functions mapping proofs\nof `P` to proofs of `Q`.\n2. `∀x : σ, Q[x]` can be read as “for all `x, Q[x]`,” or as the type of functions\nmapping values `x` of type `σ` to proofs of `Q[x]`.\n\nContinuing with “proofs as terms,” for terms, we have the following:\n\n1. A constant is a term.\n2. A variable is a term.\n3. `t u` is the application of function `t` to argument `u`.\n4. `λ x => t[x]` is a function mapping `x` to `t[x]`.\n\nIn contrast, for proofs (i.e., proof terms), we have the following:\n\n1. The name of a lemma or hypothesis is a proof.\n2. `H t`, which instantiates the leading parameter or quantifier of proof `H`’s statement with term\n   `t`, is a proof.\n3. `H G`, which discharges the leading assumption of `H`’s statement with proof `G`, is a proof.\n   This operation is called modus ponens.\n4. `λ h : P => H[h]` is a proof of `P → Q`, assuming `H[h]` is a proof of `Q` for `h : P`.\n5. `λ x : σ => H[x]` is a proof of `∀x : σ, Q[x]`, assuming `H[x]` is a proof of `Q[x]` for `x : σ`.\n\nThe last two cases are justified by the LAM' rule. In a structured proof, as opposed to a raw proof\nterm, we would write assume or fix instead of λ, and we would probably want to repeat the conclusion\nusing show for readability, as follows:\n\n```lean\nlemma case_4 (H : P → Q):\n  P → Q :=\nλ h : P =>\n  show Q from\n  H h\n\nlemma case_5 :\n∀ x : σ, Q x :=\nλ x =>\n  show Q x from\n  H x\n```\nSome commands are provided in Lean under two different names but are really\nthe same as per the Curry–Howard correspondence. This is the case for\n`axiom`.\n\nThere are also pairs with slightly different behavior, such as `def` and `lemma` or\n`let` and `have`. The fundamental difference is this: When we define some function\nor data, we care not only about the type but also about the body—the behavior. On\nthe other hand, once we have proved a lemma, the proof becomes _irrelevant_. All\nthat matters is that there is a proof. We will return to the topic of proof irrelevance\nin Chapter 11.\n\nThe following correspondence table summarizes the differences between tactical proofs, structured\nproofs, and raw proof terms:\n\n| Tactical proofs | Structured proofs | Raw proof terms |\n|-----------------|-------------------|-----------------|\n| `intro x`         | `λ x =>`          | `λ x =>`          |\n| `intro h`         | `λ h =>`            | `λ h =>`          |\n| `have k := H`     | `have k := H`       | `(λ k => . . .) H`|\n| `let x := t`      | `let x := t`        | `let x := t`      |\n| `exact (H : P)`   | `show P from H`     | `H : P`          |\n| `calc . . .`      | `calc . . .`        | `calc . . .`      |\n\n-- BUGBUG: I made some changes to this table, it needs close review.\n\nThe terminology of dependent type theory can be quite confusing, because some words have a narrow\nand a broad sense. The following diagram captures the various meanings of important words:\n\n-- BUGBUG nice latex chart goes here...\n\nAccording to the broad senses, any expression is a term, any expression that may occur on the\nright-hand side of a typing judgment is a type, and any expression that may occur on the right-hand\nside of a typing judgment with a type on its left-hand side is a universe. This is consistent with the\nreading of `t : u` as “`t` has type `u`” and the notion that universes are types of types.\n\n\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/ForwardProofs/CurryHoward.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940974, "lm_q2_score": 0.8902942268497305, "lm_q1q2_score": 0.7812125266474673}}
{"text": "import data.real.basic\n\nlocal attribute [instance, priority 0] classical.prop_decidable\n\nnoncomputable theory\n\n-- Lean's definition of abs is: abs (x) = max x (-x)\n\nlocal notation `|` x `|` := abs x\n\ndefinition is_limit (f : ℕ → ℝ) (l : ℝ) : Prop := ∀ ε > 0, ∃ N, ∀ n ≥ N, | f n - l | < ε\n\ndefinition has_limit (f : ℕ → ℝ) : Prop := ∃ l : ℝ, is_limit f l\n\ndefinition limit (f : ℕ → ℝ) : ℝ := dite (has_limit f) classical.some (λ _, 0)\n\n\n\n\nexample : is_limit (λ x, 1/x) 0 :=\nbegin\n  unfold is_limit,\n  intros ε Hε,\n  let N0 := ceil (1 / ε), -- seems to me we want nat.ceil\n  let N := int.nat_abs N0,\n  use N,\n  intro n,\n  intro Hn,\n  rw sub_zero,\n  have H1 : 1 / ε > 0 := div_pos zero_lt_one Hε,\n  have H2 : N0 > 0 := lt_ceil.2 H1,\n  have H3 : 0 < N := int.nat_abs_pos_of_ne_zero (ne_of_gt H2),\n  have H4 : 0 < n := lt_of_lt_of_le H3 Hn,\n  have H5 : 0 < (n : ℝ) := by simp [H4],\n  have H6 : 0 < 1 / (n : ℝ) := div_pos zero_lt_one H5,\n  rw abs_of_nonneg (le_of_lt H6),\n  rw div_lt_iff H5,\n  rw int.div_lt_iff_lt_mul\nend\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/M1P1/limits_of_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7812024468638135}}
{"text": "import .simplify_eq .simplify_le .div_lemmas .lemmas\n\n\nnamespace nat\n\nlemma pow_add' (b m n : ℕ): b^(m+n) = b^m * b^n :=\nbegin\n  induction n,\n  case zero {\n    simp,\n  },\n  case succ n ind {\n    simp [add_succ, pow_succ, ind],\n  }\nend\n\ntheorem add_mod_self : ∀ m n : ℕ, (m + n) % n = m % n :=\nbegin\n  intros m n,\n  cases n,\n  case nat.zero { trivial, },\n  case nat.succ n { simp, },\nend\n\n/-- Congruence rule for `le` and `add`. -/\ndef add_le_add_both {a b x y : ℕ} (p : a ≤ b) (q : x ≤ y) : a + x ≤ b + y :=\nbegin\n  transitivity,\n  apply nat.add_le_add_right p,\n  apply nat.add_le_add_left q\nend\n\n/-- Congruence rule for `le` and `mul`. -/\ndef mul_le_mul_both {a b x y : ℕ} (p : a ≤ b) (q : x ≤ y) : a * x ≤ b * y :=\nbegin\n  transitivity,\n  apply nat.mul_le_mul_right x p,\n  apply nat.mul_le_mul_left b q\nend\n\nend nat\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/nat/default.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7812024409669114}}
{"text": "import .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 {α : Type} : list α → list α → list α\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 {α : Type} :\n  ∀as xs : list α, accurev as xs = reverse xs ++ as\n| as []        := by refl\n| as (x :: xs) := by simp [reverse, accurev, accurev_eq_reverse_append _ xs]\n\n/-! 1.2. Derive the desired equation. -/\n\nlemma accurev_eq_reverse {α : Type} (xs : list α) :\n  accurev [] xs = reverse xs :=\nby simp [accurev_eq_reverse_append]\n\n/-! 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {α : Type} (xs : list α) :\n  accurev [] (accurev [] xs) = xs :=\nby simp [accurev_eq_reverse, reverse_reverse]\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 {α : Type} :\n      ∀as xs : list α, 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/-! We perform the proof by structural induction on `xs` (generalizing `as`).\n\nCase `[]`: The goal is `accurev as [] = reverse [] ++ as`. The left-hand side\nis `as` by definition of `accurev`. The right-hand side is `as` by definition\nof `reverse` and `++`.\n\nCase `x :: xs`: The goal is `accurev as (x :: xs) = reverse (x :: xs) ++ as`.\nThe induction hypothesis is `∀as, accurev as xs = reverse xs ++ as`.\n\nLet us simplify the goal's left-hand side:\n\n      accurev as (x :: xs)\n    = accurev (x :: as) xs        -- by definition of `accurev`\n    = reverse xs ++ (x :: as)     -- by the induction hypothesis\n\nNow let us massage the right-hand side so that it matches the simplified\nleft-hand side:\n\n      reverse (x :: xs) ++ as\n    = (reverse xs ++ [x]) ++ as   -- by definition of `reverse`\n    = reverse xs ++ ([x] ++ as)   -- by associativity of `++`\n    = reverse xs ++ (x :: as)     -- by definition of `++`\n\nThe two sides are equal. QED -/\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 {α : Type} : ℕ → list α → list α\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 {α : Type} : ℕ → list α → list α\n| 0       _         := []\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := x :: take m xs\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 {α : Type} :\n  ∀n : ℕ, drop n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\n\n@[simp] lemma take_nil {α : Type} :\n  ∀n : ℕ, take n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\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, `←add_assoc` might be useful. -/\n\nlemma drop_drop {α : Type} :\n  ∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) _ []        := by simp [drop]\n| (m + 1) n (x :: xs) :=\n  by simp [drop, drop_drop m n xs, ←add_assoc]\n\nlemma take_take {α : Type} :\n  ∀(m : ℕ) (xs : list α), 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 {α : Type} :\n  ∀(n : ℕ) (xs : list α), 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/-! ## Question 3: A Type of λ-Terms\n\n3.1. Define an inductive type corresponding to the untyped λ-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- λ-expression (e.g., `λx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\ninductive term : Type\n| var : string → term\n| lam : string → term → term\n| app : term → term → term\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 → string\n| (term.var s)   := s\n| (term.lam s t) := \"(λ\" ++ s ++ \", \" ++ term.repr t ++ \")\"\n| (term.app t u) := \"(\" ++ term.repr t ++ \" \" ++ term.repr u ++ \")\"\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 `(λx, ((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": "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/love04_functional_programming_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7811807216689377}}
{"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\n-- import tactic -- imports all the Lean tactics\n\n/-!\n\n# Logic in Lean, example sheet 1 : \"implies\" (`→`)\n\nWe learn about propositions, and implications `P → Q` between them. You can get\nthis arrow by typing `\\to` or `\\r`. Mathematicians usually write the\nimplication arrow as `P ⇒ 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 `⊢` 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.\nvariable (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 := by\n  -- note that `exact P` does *not* work. `P` is the proposition, `hP` is the proof.\n  exact hP\n\n-- Assume `Q` is true. Prove that `P → Q`. \nexample (hQ : Q) : P → Q := by\n  -- The goal is of the form `X → 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.\n\n-- Assume `P → Q` and `P` is true. Deduce `Q`.\nexample (h : P → Q) (hP : P) : Q := by\n  -- our goal is `⊢ 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\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 → P := by\n  sorry\n\n/-\n\nNote that `→` is not associative: in general `P → (Q → R)` and `(P → Q) → 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 → Q → R` then we'd better know what this means.\nThe convention in Lean is that it means `P → (Q → 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 → P2 → P3 → ... 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 → (Q → P)`.\n\n-/\nexample : P → Q → P := by\n  sorry\n\n/-- If we know `P`, and we also know `P → Q`, we can deduce `Q`. \nThis is called \"Modus Ponens\" by logicians. -/\nexample : P → (P → Q) → Q := by\n  sorry\n\n/-- `→` is transitive. That is, if `P → Q` and `Q → R` are true, then\n  so is `P → R`. -/\nexample : (P → Q) → (Q → R) → (P → R) := by\n  sorry\n\n-- If `h : P → Q → R` with goal `⊢ R` and you `apply h`, you'll get\n-- two goals! Note that tactics operate on only the first goal.\nexample : (P → Q → R) → (P → Q) → (P → R) := by \n  sorry\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\nvariable (S T : Prop)\n\nexample : (P → R) → (S → Q) → (R → T) → (Q → R) → S → T := by\n  sorry\n\nexample : (P → Q) → ((P → Q) → P) → Q := by\n  sorry\n\nexample : ((P → Q) → R) → ((Q → R) → P) → ((R → P) → Q) → P := by\n  sorry\n\nexample : ((Q → P) → P) → (Q → R) → (R → P) → P := by\n  sorry\n\nexample : (((P → Q) → Q) → Q) → (P → Q) := by\n  sorry\n\nexample :\n  (((P → Q → Q) → ((P → Q) → Q)) → R) →\n  ((((P → P) → Q) → (P → P → Q)) → R) →\n  (((P → P → Q) → ((P → P) → Q)) → R) → R := by\n  sorry\n\n", "meta": {"author": "UofSC-Spring-2023-Math-768-001", "repo": "formalizing-mathematics-lean4", "sha": "38783ca5d1c81db4cc59c04474aefb18c181bff6", "save_path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalizing-mathematics-lean4", "path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalizing-mathematics-lean4/formalizing-mathematics-lean4-38783ca5d1c81db4cc59c04474aefb18c181bff6/Fm4/Sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7811058669304457}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a y b son números reales, entonces\n--    (a + b) * (a + b) = a * a + 2 * (a * b) + b * b\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : ℝ\n\n-- 1ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\ncalc\n  (a + b) * (a + b)\n      = (a + b) * a + (a + b) * b       : by rw mul_add\n  ... = a * a + b * a + (a + b) * b     : by rw add_mul\n  ... = a * a + b * a + (a * b + b * b) : by rw add_mul\n  ... = a * a + b * a + a * b + b * b   : by rw ← add_assoc\n  ... = a * a + (b * a + a * b) + b * b : by rw add_assoc (a * a)\n  ... = a * a + (a * b + a * b) + b * b : by rw mul_comm b a\n  ... = a * a + 2 * (a * b) + b * b     : by rw ← two_mul\n\n-- 2ª demostración\n-- ===============\n\nexample :\n  (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) : by rw [mul_add, add_mul, add_mul]\n  ... = a * a + (b * a + a * b) + b * b : by rw [←add_assoc, add_assoc (a * a)]\n  ... = a * a + 2 * (a * b) + b * b     : by rw [mul_comm b a, ←two_mul]\n\n-- 3ª demostración\n-- ===============\n\nexample :\n  (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) : by ring\n  ... = a * a + (b * a + a * b) + b * b : by ring\n  ... = a * a + 2 * (a * b) + b * b     : by ring\n\n-- 4ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nby ring\n\n-- 5ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw mul_add,\n  rw add_mul,\n  rw add_mul,\n  rw ← add_assoc,\n  rw add_assoc (a * a),\n  rw mul_comm b a,\n  rw ← two_mul,\nend\n\n-- El desarrollo de la prueba es\n--\n--    a b : ℝ\n--    ⊢ (a + b) * (a + b) = a * a + 2 * (a * b) + b * b\n-- rw mul_add,\n--    ⊢ (a + b) * a + (a + b) * b = a * a + 2 * (a * b) + b * b\n-- rw add_mul,\n--    ⊢ a * a + b * a + (a + b) * b = a * a + 2 * (a * b) + b * b\n-- rw add_mul,\n--    ⊢ a * a + b * a + (a * b + b * b) = a * a + 2 * (a * b) + b * b\n-- rw ← add_assoc,\n--    ⊢ a * a + b * a + a * b + b * b = a * a + 2 * (a * b) + b * b\n-- rw add_assoc (a * a),\n--    ⊢ a * a + (b * a + a * b) + b * b = a * a + 2 * (a * b) + b * b\n-- rw mul_comm b a,\n--    ⊢ a * a + (a * b + a * b) + b * b = a * a + 2 * (a * b) + b * b\n-- rw ← two_mul,\n--    no goals\n\n-- 6ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw [mul_add, add_mul, add_mul],\n  rw [←add_assoc, add_assoc (a * a)],\n  rw [mul_comm b a, ←two_mul],\nend\n\n-- El desarrollo de la prueba es\n--\n--    a b : ℝ\n--    ⊢ a * a + (a * b + a * b) + b * b = a * a + 2 * (a * b) + b * b\n-- rw [mul_add, add_mul, add_mul],\n--    ⊢ a * a + b * a + (a * b + b * b) = a * a + 2 * (a * b) + b * b\n-- rw [←add_assoc, add_assoc (a * a)],\n--    ⊢ a * a + (b * a + a * b) + b * b = a * a + 2 * (a * b) + b * b\n-- rw [mul_comm b a, ←two_mul]\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/Basicos/Demostracion_con_calc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7811058626759195}}
{"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\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 →+* 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 →+* 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 : ℕ) [char_p R p] : char_p A p :=\n{ cast_eq_zero_iff := λx,\n  begin\n    rw ←char_p.cast_eq_zero_iff R p x,\n    change algebra_map ℕ A x = 0 ↔ algebra_map ℕ R x = 0,\n    rw is_scalar_tower.algebra_map_apply ℕ R A x,\n    refine iff.trans _ h.eq_iff,\n    rw ring_hom.map_zero,\n  end }\n\n/-- If the algebra map `R →+* 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 := λ x y hxy,\n  begin\n    change algebra_map ℕ A x = algebra_map ℕ A y at hxy,\n    rw is_scalar_tower.algebra_map_apply ℕ R A x at hxy,\n    rw is_scalar_tower.algebra_map_apply ℕ 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\nsection\n\nvariables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]\n\nlemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=\n(algebra_map K L).char_p_iff_char_p p\n\nend\n\nnamespace free_algebra\n\nvariables {R X : Type*} [comm_semiring R] (p : ℕ)\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 : ℕ)\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": "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/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.863391602943619, "lm_q1q2_score": 0.7810676844825986}}
{"text": "import data.int.basic data.nat.basic data.nat.prime tactic algebra.floor\n\nopen int nat\n\n\nsection prime_numbers_and_divisibility\n  /- \n  ## Definition 1.1\n  A prime number is a natural number p > 1, which is divisible only\n  by the natural numbers 1 and p.\n  -/\n\n\n  /-\n  ## Definition 1.2\n  Let m, n ∈ ℤ.\n  Then n is divisible by m (m ∣ n) if there exists a ∈ ℤ such that n = ma.\n  -/\n  example : 7 ∣ 91 := by {use 13, tauto}\n\n  example : (-5 : ℤ) ∣ 45 := by {use -9, tauto}\n\n  example : ¬ (11 ∣ 87) := begin\n    have h₁ : 11 ≠ 3 := by norm_num, --\n    have h₂ : 11 ≠ 29 := by norm_num,\n    have h₃ : 87 = 3 * 29 := by norm_num,\n\n    intro h,\n\n    rw [← coprime_primes, prime.coprime_iff_not_dvd (show prime 11, by norm_num)] at h₁ h₂, repeat {norm_num},\n    rw [h₃, prime.dvd_mul] at h,\n\n    cases h with k₁ k₂,\n    repeat {contradiction},\n    norm_num,\n  end\n\n  example : ∀ x : ℤ, 1 ∣ x := begin -- Every number is dvisible by 1.\n    intro x,\n    use x, \n    simp, \n  end\n\n  example (x : ℤ) : 2 ∣ x ↔ even x := begin -- A number is divisible by 2 iff it is even.\n    split,\n    repeat {intro h, \n            cases h with k hk,\n            use k, \n            exact hk},\n  end\n\n\n  /-\n  ## Theorem 1.4\n  Let n : ℕ with n > 1.\n  Then n has a prime factor p.\n  -/\n  theorem prime_fact' : ∀ n : ℕ, 2 ≤ n → ∃ p, prime p → p ∣ n + 1 := begin\n    intros n hn,\n    use 0,\n    intro hp,\n    cases hp with k hk,\n    linarith,\n  end\n\n  theorem prime_fact : ∀ n : ℕ, 2 ≤ n → ∃ p, prime p ∧ p ∣ n := begin\n    intro n,\n    apply nat.strong_induction_on n,\n\n    intros a h₁ ha,\n    by_cases prime a,\n      {use a, tauto},\n\n      {unfold prime at h, push_neg at h,\n      specialize h ha,\n      rcases h with ⟨m, hm, h₁, h₂⟩,\n      use m, sorry}\n  end\n\n\n  /-\n  ## Theorem 1.5 - Euclid\n  There are infinitely many primes.\n  -/\n  theorem Euclid : ∀ N, ∃ p ≥ N, prime p := begin\n    intro N,\n\n    let M := factorial N + 1,\n    let p := min_fac M,\n\n    have hp : 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 H,\n      have h₁ : p ∣ factorial N + 1 := min_fac_dvd M,\n      have h₂ : p ∣ factorial N :=\n        begin\n          refine hp.dvd_factorial.mpr _,\n          exact le_of_not_ge H,\n      end,\n      have h : p ∣ 1 := (nat.dvd_add_right h₂).mp h₁,\n      \n      exact prime.not_dvd_one hp h},\n    {exact hp},\n  end\n\n\n  /-\n  ## Theorem 1.7\n  If n : ℕ, with n > 1, then either n is prime, or is a product of a\n  (finite) sequence of primes.\n  -/\n  theorem prime_or_product_1 (n : ℕ) (H : 2 ≤ n) : prime n ∨ ∃ m a: ℕ, 2 ≤ m ∧ m < n ∧ m * a = n := begin\n    -- Either prime n or n is product of 2 different naturals\n    by_cases prime n,\n      {left, exact h},\n      {right, unfold prime at h, push_neg at h,\n        specialize h H,\n        cases h with m hm,\n\n        use m,\n        use n/m,\n        rcases hm with ⟨h₂, h₃, h₄⟩,\n        split,\n          { sorry,},\n          sorry,\n      }\n  end\n\n\n  def list_prod : list ℕ → ℕ\n    | [] := 1\n    | (h :: t) := h * list_prod t\n\n  #eval list_prod [2, 5, 7, 10]\n\n\n  def list_prime : list ℕ → Prop\n    | [] := true\n    | (h :: t) := prime h ∧ list_prime t\n\n  lemma list_prime_2_3_5 : list_prime [2, 3, 5] := begin\n    split, norm_num,\n    split, norm_num,\n    split, norm_num,\n    triv,\n  end\n\n\n  def list_prod_prime_eq (n : ℕ) (P : list ℕ): Prop :=\n    list_prime P ∧ n = list_prod P\n\n  example : list_prod_prime_eq 30 [2,3,5] := begin\n    split, exact list_prime_2_3_5,\n    dsimp [list_prod],\n    norm_num,\n  end\n\n\n  theorem list_prime_append (P Q : list ℕ) (H : list_prime P) (G : list_prime Q) : list_prime (P ++ Q) := begin\n    sorry,\n  end\n\n\n  theorem list_prod_append (P Q : list ℕ) : list_prod P * list_prod Q = list_prod (P ++ Q) := begin\n    sorry,\n  end\n\n\n  theorem prime_or_product_2 (n : ℕ): 2 ≤ n → ∃ P : list ℕ, list_prod_prime_eq n P := begin\n    -- n is a product of a list of primes\n    apply nat.strong_induction_on n,\n    intros a ha ha₂,\n    have h := prime_or_product_1 a ha₂,\n\n    cases h with h₁ h₂,\n    { use ([a]),\n      split,\n      { dsimp [list_prime],\n        tauto},\n      { dsimp [list_prod],\n        norm_num}\n    },\n    { rcases h₂ with ⟨b, c, hb⟩,\n      rcases hb with ⟨kb₁, kb₂, kabc⟩,\n      \n      have Hb := ha b kb₂ kb₁,\n      have Hc := ha c,\n      have kc₁ : 1 < c, begin\n        rw [← kabc, ← mul_one b, mul_assoc, one_mul, mul_lt_mul_left (show 0 < b, by linarith)] at kb₂,\n          exact kb₂,\n      end,\n      have kc₂ : c < a, begin\n        by_contra kca,\n          push_neg at kca,\n          rw [← kabc, mul_le_iff_le_one_left] at kca;\n            linarith,\n      end,\n      \n      specialize Hc kc₂ kc₁,\n      rcases Hb with ⟨Q, primeQ, prodQb⟩,\n      rcases Hc with ⟨R, primeR, prodRc⟩,\n      \n      use Q ++ R,\n      split,\n      { exact list_prime_append Q R primeQ primeR,},\n      { rw [← kabc, prodQb, prodRc],\n        exact list_prod_append Q R}\n    }\n    \n  end\n\n  theorem prime_or_product_3 (n : ℕ): 2 ≤ n → ∃ P : list ℕ, list_prod_prime_eq n P := begin\n    apply nat.strong_induction_on n,\n    intros k hk h2k,\n\n    by_cases prime k,\n    { use ([k]),\n      dsimp [list_prod_prime_eq],\n      split,\n        { split,\n            exact h,\n            triv,},\n        { dsimp [list_prod],\n          norm_num,}},\n    { have h := prime_fact k h2k,\n      rcases h with ⟨p, hp₁, hp₂⟩,\n      cases hp₂ with c hc,\n\n      specialize hk c,\n      \n      have c_le_k : c < k := begin\n        by_contra kc,\n          push_neg at kc,\n          rw [hc, mul_le_iff_le_one_left] at kc,\n            { cases hp₁ with hp₂ hp₃,\n              linarith,},\n            { linarith,}\n      end,\n      have c_ge_2 : 2 ≤ c := begin\n        sorry,\n      end,\n\n      specialize hk c_le_k c_ge_2,\n      cases hk with Q hcQ,\n\n      dsimp [list_prod_prime_eq] at hcQ,\n      cases hcQ with Qprime Qprodc,\n\n      use ([p] ++ Q),\n      dsimp [list_prod_prime_eq],\n      split,\n      { split,\n        { exact hp₁},\n        { exact Qprime}},\n      { rw [hc, Qprodc],\n        dsimp [list_prod],\n        refl,}\n      }\n\n  end\n\n  #check le_mul_of_pos_right\n  #check mul_lt_mul_left\n\n\n\n  /-\n  ## Theorem 1.8\n  Let n have the prime factorisations\n        n = p₁ × ... × p_r = q₁ × ... × q_s\n  Then every prime occurs equally often in both factorisations (and so r = s)\n\n  This is what we are working up to proving, but we will first need modular arithmetic\n  -/\n\nend prime_numbers_and_divisibility\n\nsection modular_arithmetic\n  /-\n  ## Definition 1.9\n  For an integer n ≥ 1, we say that integers a and b are congruent modulo n, \n  whenever (a − b)/n is an integer. \n  -/\n  \n  def congModN (a b : ℤ) (n : ℕ) := ∃ m : ℤ, (a - b) = m * n\n  def congModNInt (a b n : ℤ) := ∃ m : ℤ, (a - b) = m * n\n\n  /-\n  ## Theorem 1.10\n  Congruence behaves like an equivalence relation, i.e. it satisfies\n    Reflexivity\n    Symmetry\n    Transitivity\n  -/\n\n  theorem cong_refl (a : ℤ) (n : ℕ): congModN a a n := begin\n    dsimp [congModN],\n    use 0,\n    simp,\n  end\n\n  theorem cong_symm (a b : ℤ) (n : ℕ): congModN a b n ↔ congModN b a n := begin\n    split;\n      { intro h,\n        cases h with m hm,\n        use (-m),\n        linarith},\n  end\n\n  theorem cong_trans (a b c : ℤ) (n : ℕ) (H₁ : congModN a b n) (H₂ : congModN b c n): congModN a c n := begin\n      cases H₁ with m hm,\n      cases H₂ with p hp,\n      \n      use (m + p),\n      rw [add_mul, ← hm, ← hp],\n      linarith,\n  end\n\n\n  /-\n  ## Theorem 1.11\n  Congruence preserves addition, subtraction and multiplication\n  -/\n\n  theorem cong_add (a b c d : ℤ) (n : ℕ) (H₁ : congModN a b n) (H₂ : congModN c d n): congModN (a + c) (b + d) n := begin\n    cases H₁ with m hm,\n    cases H₂ with p hp,\n\n    use (m + p),\n    rw [add_mul, ← hm, ← hp],\n    linarith,\n  end\n\n  theorem cong_sub (a b c d : ℤ) (n : ℕ) (H₁ : congModN a b n) (H₂ : congModN c d n): congModN (a - c) (b - d) n := begin\n    cases H₁ with m hm,\n    cases H₂ with p hp,\n\n    use (m - p),\n    rw [sub_mul, ← hm, ← hp],\n    linarith,   \n  end\n\n  theorem cong_mul (a b c d : ℤ) (n : ℕ) (H₁ : congModN a b n) (H₂ : congModN c d n): congModN (a * c) (b * d) n := begin\n    cases H₁ with m hm,\n    cases H₂ with p hp,\n\n    use (b*p + c*m),\n    rw add_mul,\n    rw [mul_assoc b p n, ← hp, mul_assoc c m n, ← hm, mul_sub, mul_sub],\n    linarith,\n  end\n\n\n  /-\n  ## Remark 1.12\n  We must be careful with division, i.e.\n  a/c is not always congruent to b/d (mod n)\n  -/\n\n\n  /-\n  ## Theorem 1.13\n  Let n ≥ 1 and a ∈ Z. There are unique q ∈ Z and r ∈ {0, 1, . . . , n − 1}, \n  with a = qn + r.\n  (We call q the quotient and r the remainder obtained by dividing a by n.)\n  -/\n\n  theorem quot_rem (a: ℤ) (n : ℕ) (H₁ : 1 ≤ n) : ∃ q r : ℤ, 0 ≤ r → r ≤ n - 1 → a = q*n + r := begin\n    let q := floor (a/n),\n    use q,\n    use (a - q*n),\n    intros h₁ h₂,\n    linarith,\n  end\n\n  theorem quot_rem_unique (a : ℤ) (n : ℕ) (H₁ : 1 ≤ n) : ∃! q r : ℤ, 0 ≤ r → r ≤ n - 1 → a = q*n + r := begin\n    rw exists_unique,\n    let q := floor (a/n),\n    have hqa₁ : q ≤ a/n := begin\n      dsimp [q],\n      tauto,\n    end,\n    have hqa₂ : (a/n) ≤ ceil (a/n) := begin\n      sorry,\n    end,\n    have hqa₃ : ceil (a/n) ≤ q + 1 := begin\n      dsimp [q],\n      exact ceil_le_floor_add_one (a/n),\n    end,\n    have hqa₄ : a/n ≤ q + 1 := begin\n      exact le_trans hqa₂ hqa₃,\n    end,\n    clear hqa₃ hqa₄,\n    use q,\n    split,\n      { rw exists_unique,\n        use (a - q * n),\n        split,\n          { intros h₁ h₂,\n            linarith,},\n          { intros r hr₁,\n            sorry},\n      },\n      {sorry}\n  end\n  #check nat.mod_add_div\n\n  lemma mod_le_n (a n : ℕ) (H₁ : 1 ≤ n) : a % n ≤ n := begin\n    induction a with k hk,\n      { rw nat.zero_mod,\n        linarith,},\n      { rw succ_eq_add_one,\n        rw nat.add_mod,\n        by_cases n = 1,\n          { -- For n = 1\n            rw h,\n            simp,},\n          { -- For n ≠ 1, i.e. 1 < n\n            have h₂ : 1 < n := by sorry,}}\n  end\n\n  theorem quot_rem_nat (a n : ℕ) (H₁ : 1 ≤ n) : ∃ q r : ℕ, 0 ≤ r ∧ r ≤ n - 1 ∧ a = q*n + r := begin\n    use a/n,\n    use a % n,\n    split,\n      { exact nat.zero_le (a % n)},\n      { split,\n        { sorry},\n        { sorry}}\n  end\n\n  theorem quot_rem_nat' (a n : ℕ) : ∃ q r : ℕ, 0 ≤ r ∧ r ≤ n ∧ a = q * (n + 1) - q + r := begin\n    use a/n,\n    use a % n,\n    split,\n      { exact nat.zero_le (a % n),},\n      { split,\n        { exact mod_le_n a n},\n        { rw mul_add,\n          rw mul_one,\n          simp,\n          have h₁ : a / n * n ≥ a - n := begin\n            sorry,\n          end,\n          have h₂ := mod_le_n a n,\n          sorry,}}\n  end\n-- a ≤ a < a - n\n\n  theorem quot_rem_unique' (a n q₁ q₂ r₁ r₂ : ℤ) (H₁ : 1 ≤ n) \n    (H1r₁ : 0 ≤ r₁) (H2r₁ : r₁ < n) \n    (H1r₂ : 0 ≤ r₂) (H2r₂ : r₂ < n) \n    (Ha₁ : a = q₁ * n + r₁) (Ha₂ : a = q₂ * n + r₂): r₁ = r₂ ∧ q₁ = q₂ := begin\n      split,\n        { have h₁ : congModNInt r₁ r₂ n := begin\n            use (q₂ - q₁),\n            rw ← sub_eq_iff_eq_add' at Ha₁ Ha₂,\n            rw [← Ha₁, ← Ha₂],\n            rw sub_mul,\n            simp,\n          end,\n\n          have hr₁ : (- n : ℤ) < r₁ - r₂ := begin\n            sorry,\n          end,\n          have hr₂ : r₁ - r₂ < n := begin\n            sorry,\n          end,\n\n          have hr₃ : -1 < (r₁ - r₂) / n := begin\n            sorry,\n          end,\n          have hr₄ : (r₁ - r₂) / n < 1 := begin\n            sorry,\n          end,\n\n          have hr₅ : (r₁ - r₂) / n = 0 := by sorry,\n\n          have hr₆ : r₁ - r₂ = 0 * n := by sorry,\n\n          rw [zero_mul, sub_eq_zero] at hr₆,\n          exact hr₆,\n          },\n        { sorry,}\n  end\n\n  #check nat.mod_le\n\nend modular_arithmetic", "meta": {"author": "gihanmarasingha", "repo": "mth1001_summer_2021", "sha": "fd168488a238c2e01800ebeeff2809adb3fa88b5", "save_path": "github-repos/lean/gihanmarasingha-mth1001_summer_2021", "path": "github-repos/lean/gihanmarasingha-mth1001_summer_2021/mth1001_summer_2021-fd168488a238c2e01800ebeeff2809adb3fa88b5/src/numberTheory/primeNumbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603709, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7810415007080841}}
{"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 ∩ B ⊆ 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 `subgp G`.\n\n/-- The type of subgroups of a group `G`. -/\nstructure subgp (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, ⁻¹)\n(mul_mem {a b : G} : a ∈ carrier → b ∈ carrier → a * b ∈ carrier)\n(one_mem : (1 : G) ∈ carrier)\n(inv_mem {a : G} : a ∈ carrier → a⁻¹ ∈ carrier)\n\nnamespace subgp\n\n/-\nNote in particular that we have a function `subgp.carrier : subgp G → 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 : subgp 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`∀ H J : subgp G, H.carrier = J.carrier → 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 : subgp 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 : subgp G} (h : ∀ (x : G), x ∈ H.carrier ↔ x ∈ 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 : subgp G} : H = J ↔ ∀ (x : G), x ∈ H.carrier ↔ x ∈ 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 `subgp G`. In other words, we will create a term of\n-- type `partial_order (subgp G)`.\n\n-- Let's define `H ≤ J` to mean `H.carrier ⊆ J.carrier`, using the `has_le` notation typeclass\ninstance : has_le (subgp G) := ⟨λ H J, H.carrier ⊆ J.carrier⟩\n\n-- \"tidy\" is a one-size-fits-all tactic which solves certain kinds of \"follow your nose\" goals.\ninstance : partial_order (subgp G) :=\n{ le := (≤),\n  le_refl := by tidy,\n  le_trans := by tidy,\n  le_antisymm := by tidy }\n\n/- Here is a second proof. If X → 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`subgp.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 (subgp G)`, and `partial_order (subgp 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 (subgp G) := partial_order.lift subgp.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 ≤ J ∧ ¬ (J ≤ H)`.\n\n# From partial orders to lattices.\n\nLet's now prove that `subgp G` is a `semilattice_inf` . This is a class\nwhich extends `partial_order` -- it is a partial order equipped with\na function `inf : subgp G → subgp G → subgp G` (called \"inf\" or \"meet\"\nor \"greatest lower bound\", satisfying some axioms. In our case, `inf` will\njust be intersection. The work we need to do is to check that these are\nsubgroups, and to prove the axioms for a `semilattice_inf`, which\nwe'll come to later.\n\nWe will also show that it is an `order_top`, i.e., it has a largest element.\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 ∈ univ`.\n\n-/\ndef top : subgp 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 `⊤` notation (typed with `\\top`) for this subgroup:\ninstance : has_top (subgp G) := ⟨top⟩\n\n-- Now `#check (⊤ : subgp 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 ⊓ K` (Lean's notation for `inf H K`).\n\n  The part of the interface for `∩` you'll need is that `a ∈ B ∩ C` is\n  definitionally equal to `a ∈ B ∧ a ∈ C`, so you can use `split`\n  if you have a goal `⊢ a ∈ B ∩ C`, and you can use `cases h` if you\n  have a hypothesis `h : a ∈ B ∩ C`. Don't forget `mul_mem H`, `one_mem H`\n  and `inv_mem H`, the axioms for `H` if `H : subgp G`.\n-/\n\n/-- \"Theorem\" : intersection of two subgps is a subgp -/\ndefinition inf (H K : subgp G) : subgp G :=\n{ carrier := H.carrier ∩ 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 `⊓` notation (type with `\\inf`) for the intersection (inf) of two subgroups:\ninstance : has_inf (subgp G) := ⟨inf⟩\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 : subgp G) : H ≤ ⊤ :=\nbegin\n  sorry\nend\n\nlemma inf_le_left (H K : subgp G) : H ⊓ K ≤ H :=\nbegin\n  -- by definition this says `H.carrier ∩ K.carrier ⊆ H.carrier`\n  change H.carrier ∩ K.carrier ⊆ 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 : subgp G) : H ⊓ K ≤ K :=\nsorry\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 ⊆ B → A ⊆ C → A ⊆ (B ∩ C)`?\nlemma le_inf (H J K : subgp G) (h1 : H ≤ J) (h2 : H ≤ K) : H ≤ J ⊓ K :=\nsorry\n\n-- Now we're ready to make the two instances.\ninstance : semilattice_inf (subgp G) :=\n{ inf := inf,\n  inf_le_left := inf_le_left,\n  inf_le_right := inf_le_right,\n  le_inf := le_inf,\n  .. subgp.partial_order } -- don't forget to inlude the partial order\n\ninstance : order_top (subgp G) :=\n{ top := top,\n  le_top := le_top }\n\n/- The logic behind `semilattice_inf` and `order_top` is that this 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` 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 `⋂₀ S` is notation for their intersection, and\nto work with it you'll need to know\n`set.mem_sInter : g ∈ ⋂₀ S ↔ ∀ (U : set G), U ∈ S → g ∈ U`.\n-/\n\ndef Inf (S : set (subgp G)) : subgp G :=\n{ carrier := ⋂₀ (subgp.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 `subgp G` with an Inf. I think the notation is `⨅`, or `\\Inf`,\n-- but I find it hard to use, and `#print notation ⨅` returns garbage.\ninstance : has_Inf (subgp G) := ⟨Inf⟩\n\n/- # Complete lattices\n\nLet's jump straight from `semilattice_inf` 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 `subgp G` into a complete lattice. We will do it in two ways.\nThe first way is to show that if our `Inf` satisfies\n`(∀ (S : set (subgp 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 (subgp G) := complete_lattice_of_Inf _ begin\n-- ⊢ ∀ (s : set (subgp 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 ≤ J and size 0 otherwise. In other words, a Galois\nconnection between two partial orders α and β is a pair of monotone functions\n`l : α → β` and `u : β → α` such that `∀ (a : α) (b : β), l a ≤ b ↔ a ≤ 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) α = subsets of G, β = subgroups of G, l = \"subgroup generated by\", u = `carrier`\n2) X : Type, α := set (set X), β := 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 : α) : a ≤ u (l a) := ...\n\nlemma l_u_le (b : β) : l (u b) ≤ b := ...\n\nlemma u_l_u_eq_u : u ∘ l ∘ u = u := ...\n\nlemma l_u_l_eq_l : l ∘ u ∘ 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 ∘ 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 subgps. 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) : subgp G := Inf {H : subgp G | S ⊆ H.carrier}\n\n-- Here are some theorems about it.\nlemma monotone_carrier : monotone (subgp.carrier : subgp G → set G) :=\nsorry\n\nlemma monotone_span : monotone (span : set G → subgp G) :=\nsorry\n\nlemma subset_span (S : set G) : S ≤ (span S).carrier :=\nbegin\n  sorry\nend\n\nlemma span_subgp (H : subgp 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_subgp : galois_insertion (span : set G → subgp G) (subgp.carrier : subgp G → set G) :=\ngalois_insertion.monotone_intro monotone_carrier monotone_span subset_span span_subgp\n\n-- Note that `set G` is already a complete lattice:\nexample : complete_lattice (set G) := by apply_instance\n\n-- and now `subgp 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 (subgp G) := galois_insertion.lift_complete_lattice gi_subgp\n\nend subgp\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 → Prop) -- why set X → Prop not set (set X)? former plays\n                           -- nicer with typeclasses later\n  (univ_mem : is_open univ)\n  (union : ∀ (B : set (set X)) (h : ∀ b ∈ B, is_open b), is_open (⋃₀ B))\n  (inter : ∀ (A B : set X) (hA : is_open A) (hB : is_open B), is_open (A ∩ B))\n\nnamespace topological_space\n\ndef forget {X : Type} : topological_space X → 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 → Prop\n| basic  : ∀ s ∈ g, generated_open s\n| univ   : generated_open univ\n| inter  : ∀s t, generated_open s → generated_open t → generated_open (s ∩ t)\n| sUnion : ∀k, (∀ s ∈  k, generated_open s) → generated_open (⋃₀ 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 τ₁ τ₂ h,\n  cases τ₁, cases τ₂,\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 → set (set X)) :=\nbegin\n  sorry\nend\n\nlemma monotone_span {X : Type} :\n  monotone (generate_from : set (set X) → topological_space X) :=\nbegin\n  sorry\nend\n\nlemma subset_forget {X : Type} (Us : set (set X)) :\n  Us ≤ forget (generate_from Us) :=\nbegin\n  sorry\nend\n\nlemma generate_forget {X : Type} (τ : topological_space X) :\n  generate_from (forget τ) = τ :=\nbegin\n  sorry\nend\n\ndef gi_top (X : Type) :\n  galois_insertion (generate_from : set (set X) → topological_space X)\n    (forget : topological_space X → 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\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/thursday/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8757869835428966, "lm_q1q2_score": 0.7810365129291673}}
{"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 → (state → ℕ) → stmt\n| seq      : stmt → stmt → stmt\n| unless   : stmt → (state → Prop) → stmt\n| while    : (state → Prop) → stmt → stmt\n| do_while : stmt → (state → Prop) → 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 { … } while (…)`\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 → set (state × state)\n| stmt.skip           := Id\n| (stmt.assign x a)   :=\n  {st | prod.snd st = (prod.fst st){x ↦ a (prod.fst st)}}\n| (stmt.seq S₁ S₂)    := denote S₁ ◯ denote S₂\n| (stmt.unless S b)   := (Id ⇃ b) ∪ (denote S ⇃ λs, ¬ b s)\n| (stmt.while b S)    := lfp (λX, ((denote S ◯ X) ⇃ b) ∪ (Id ⇃ λs, ¬ b s))\n| (stmt.do_while S b) :=\n  denote S ◯ lfp (λX, ((denote S ◯ X) ⇃ b) ∪ (Id ⇃ λs, ¬ b s))\n\nnotation `⟦` S `⟧`:= 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 → Prop) :\n  ⟦stmt.do_while S b⟧ = ⟦S⟧ ◯ ⟦stmt.while b S⟧ :=\nby refl\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 ⇃ (λx, false)` and `p ⇃ (λx, true)` mean.\nMake sure to simplify the expressions involving `⇃` before trying to figure out\nwhat to do about `lfp`. -/\n\nlemma lfp_const {α : Type} [complete_lattice α] (a : α) :\n  lfp (λX, a) = a :=\nbegin\n  rw lfp_eq,\n  apply monotone_const\nend\n\nlemma while_false (S : stmt) :\n  ⟦stmt.while (λ_, false) S⟧ = Id :=\nby simp [denote, restrict, lfp_const]\n\nlemma comp_Id {α : Type} (r : set (α × α)) :\n  r ◯ Id = r :=\nby simp [comp, Id]\n\nlemma do_while_false (S : stmt) :\n  ⟦stmt.do_while S (λ_, false)⟧ = ⟦S⟧ :=\nby simp [denote, restrict, lfp_const, comp_Id]\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 = ⋃i, (f ^^ i) ∅`\n\nwhere\n\n    `f ^^ i = f ∘ ⋯ ∘ 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 {α : Type} (f : α → α) : ℕ → α → α\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 `≤` works on lattices in general, including sets. On\nsets, it can be unfolded to `⊆` using `simp [(≤)]`. Moreover, when you see\n`h : A ⊆ B` in a goal, you can imagine that you have `?a ∈ A → ?a ∈ B` by\ndefinition, or unfold the definition using `simp [(⊆), set.subset]`. -/\n\ndef Union {α : Type} (s : ℕ → set α) : set α :=\n{a | ∃n, a ∈ s n}\n\nlemma Union_le {α : Type} {s : ℕ → set α} (A : set α) (h : ∀i, s i ≤ A) :\n  Union s ≤ A :=\nbegin\n  simp [(≤)],\n  simp [(⊆), set.subset],\n  intros x hx,\n  simp [Union] at hx,\n  cases' hx with i hi,\n  exact h i hi\nend\n\n/-! A continuous function `f` is a function that commutes with the union of any\nmonotone sequence `s`: -/\n\ndef continuous {α : Type} (f : set α → set α) : Prop :=\n∀s : ℕ → set α, monotone s → f (Union s) = Union (λi, 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 {α : Type} (A B : set α) : ℕ → set α\n| 0       := A\n| (n + 1) := B\n\n/-! For example, `bi_seq A B` is the sequence A, B, B, B, …. -/\n\nlemma monotone_bi_seq {α : Type} (A B : set α) (h : A ≤ 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 {α : Type} (A B : set α) (ha : A ≤ B) :\n  Union (bi_seq A B) = B :=\nbegin\n  apply le_antisymm,\n  { apply Union_le,\n    intros n a h,\n    cases' n,\n    { exact ha h },\n    { exact h } },\n  { intros a h,\n    simp [Union],\n    apply exists.intro 1,\n    exact h }\nend\n\nlemma monotone_of_continuous {α : Type} (f : set α → set α)\n    (hf : continuous f) :\n  monotone f :=\nbegin\n  intros A B ha,\n  rw ←Union_bi_seq A B ha,\n  rw hf _ (monotone_bi_seq A B ha),\n  intros a ha,\n  rw Union,\n  simp,\n  apply exists.intro 0,\n  exact ha\nend\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 {α : Type} (f : set α → set α) (hf : monotone f) :\n  monotone (λi, (f ^^ i) ∅)\n| 0       0       _   := le_refl _\n| 0       (m + 1) hle :=\n  begin\n    intros y hin,\n    simp [iterate] at hin,\n    cases' hin\n  end\n| (n + 1) (m + 1) hle :=\n  begin\n    apply hf,\n    simp,\n    apply monotone_iterate,\n    linarith\n  end\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 ≤ Union (λi, (f ^^ i) ∅)`: The key is to use the lemma `lfp_le`\ntogether with continuity of `f`.\n\nCase 2. `Union (λi, (f ^^ i) ∅) ≤ 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 {α : Type} (f : set α → set α) (hf : continuous f) :\n  lfp f = Union (λi, (f ^^ i) ∅) :=\nbegin\n  apply le_antisymm,\n  { apply lfp_le _ _ _,\n    rw hf,\n    { apply Union_le,\n      intros n a hn,\n      apply exists.intro (n + 1),\n      exact hn },\n    { exact monotone_iterate f (monotone_of_continuous f hf) } },\n  { apply Union_le (lfp f),\n    intro i,\n    induction' i,\n    { intros a,\n      exact false.elim },\n    { rw nat.succ_eq_add_one,\n      rw lfp_eq f (monotone_of_continuous f hf),\n      exact (monotone_of_continuous f hf) _ _ (ih f hf) } }\nend\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_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218864, "lm_q2_score": 0.891811044719067, "lm_q1q2_score": 0.7810365032991162}}
{"text": "import tactic                 \nimport data.nat.lattice       -- for well-ordering for naturals \nimport data.set.basic         -- for creating sets\n\n-- Define a set for the remainder of a/b :\n-- remainder_set takes a and b and returns set of all possible nonnegative remainders of a/b\n\ndef remainder_set : ℤ → ℤ → set ℕ := λ a, λ b, { y | ∃ x : ℤ, (y : ℤ) = a - b * x}\n\n-- lemma using the definition of remainder_set (to make it easier to work with)\n\nlemma mem_remainder_set_iff {a b : ℤ} {k : ℕ}  : (k ∈ remainder_set a b) ↔\n  ∃ x : ℤ, (k : ℤ) = a - b * x :=\n  begin\n    split, {\n      intro h,\n      rw set.mem_def at h,\n      exact h,\n    }, {\n      intro h,\n      rw set.mem_def,\n      exact h,\n    }\n  end\n\n/-       PROOF SKETCH\n\n  (1) Define remainder set, S\n      -- let S = {a - bx : x ∈ ℤ ∧ a - bx ≥ 0}\n\n  (2) Show S is nonempty\n      -- use x = -|a|, and a + b |a| ≥ 0 to show S nonempty\n\n  (3) Apply Well-ordering of naturals to show that S contains a minimum, r\n\n  (4) Show r satisfies conditions of division algorithm\n      -- show r < b, by contradiction if r - b ≥ 0 \n\n  (5) Show uniqueness \n\n-/\n\nlemma division_algorithm (a b : ℤ) (ha : a > 0) (hb : b > 0) : \n(∃ q r : ℤ, ((a = b * q + r) ∧ (0 ≤ r) ∧ (r < b))) :=\nbegin\n\n  have hr : has_Inf.Inf (remainder_set a b) ∈ (remainder_set a b),\n    {\n      have hns : (remainder_set a b).nonempty,\n        {\n          have h1 : a + b * |a| ≥ 0,\n            { \n              have h2 : |a| = a := abs_of_pos ha,\n              rw h2,\n              have h3 : b * a > 0 := mul_pos hb ha,\n              have h4 : a + b * a > 0,\n              {exact add_pos ha h3,},\n\n              exact le_of_lt h4,\n            },\n          \n          obtain ⟨k, hk⟩ := int.eq_coe_of_zero_le (h1),\n          have hk_mem : k ∈ (remainder_set a b),\n            {\n              rw mem_remainder_set_iff,\n              use (-|a|),\n              linarith,\n            },\n\n          exact set.nonempty_of_mem hk_mem,\n        },\n      exact Inf_mem hns,\n    },\n  rw mem_remainder_set_iff at hr,\n  cases hr with x hx,\n  use x,\n  use has_Inf.Inf (remainder_set a b),\n  split, {\n    finish,\n  }, {\n    split, {\n      exact int.of_nat_nonneg (Inf (remainder_set a b)),\n    }, {\n      by_contra,\n      simp only [not_lt, int.of_nat_eq_coe] at h,\n      have j : ((has_Inf.Inf (remainder_set a b) ) - int.to_nat(b)) ∈ (remainder_set a b),\n      { \n        rw mem_remainder_set_iff,\n        use (x+1),\n        have k : ↑(Inf (remainder_set a b)) - b = a - b * (x + 1) := by linarith,\n        rw ← k,\n        have hb2 : 0 ≤ b := le_of_lt hb,\n        have hb3 := int.to_nat_of_nonneg hb2,\n        nth_rewrite 3 ← hb3,\n        have h2 : b.to_nat ≤ Inf (remainder_set a b) := by finish,\n        rw int.coe_nat_sub h2,\n      },\n      have hle := nat.Inf_le j,\n      have hg : Inf (remainder_set a b) - b.to_nat < Inf (remainder_set a b),\n      { \n        have hb_nat : 0 < b.to_nat := by finish,\n        have h_inf_le_b : b.to_nat ≤ Inf (remainder_set a b),\n        {\n          have hb2 : 0 ≤ b := le_of_lt hb,\n          have hb3 := int.to_nat_of_nonneg hb2,\n          have h2 : b.to_nat ≤ Inf (remainder_set a b) := by finish,\n          exact h2,\n        },\n        exact nat.sub_lt_of_pos_le b.to_nat (Inf (remainder_set a b)) hb_nat h_inf_le_b,\n      },\n      exact nat.lt_le_antisymm hg hle,\n    },\n  },\nend\n \n#print division_algorithm\n\nlemma division_algorithm_uniqueness (a b q1 q2 r1 r2 : ℤ) (hr1 : (0 ≤ r1) ∧ (r1 < b)) (hr2 : (0 ≤ r2) ∧ (r2 < b)) \n(ha : a > 0) (hb : b > 0) (hd1 : a = b * q1 + r1) (hd2 : a = b * q2 + r2) : (q1 = q2 ∧ r1 = r2) :=\nbegin\n    have hq : q1 = q2,\n    { \n      rw hd2 at hd1,\n      have j : b * (q2 - q1) = r1 - r2 := by linarith,\n\n      have k : -b < -r2 ∧ -r2 ≤ 0,\n      { split, { linarith, }, { linarith, },},\n\n      have l : -b < r1 - r2 ∧ r1 - r2 < b,\n      { split, { linarith,}, { linarith,},},\n\n      have m : -b < b*(q2 - q1) ∧ b*(q2 - q1) < b,\n      { split, {linarith,}, {linarith,},},\n\n      have i : -1 < q2 - q1 ∧ q2 - q1 < 1,\n      {split, {\n        cases m,\n        --have hm2 : -b ≤ b * (q2 - q1) := le_of_lt m_left,\n        rw (show -b = b*(-1), by linarith) at m_left,\n        exact (mul_lt_mul_left hb).mp m_left,\n      }, {\n        cases m,\n        -- ?a < ?c → ?d ≤ ?b → 0 ≤ ?c → 0 < ?d → ?a / ?b < ?c / ?d\n        nth_rewrite 1 ← (mul_one b) at m_right,\n        exact (mul_lt_mul_left hb).mp m_right,\n      },},\n      linarith,\n  \n    },\n    split, {\n      assumption,\n    }, {\n      rw hq at hd1,\n      linarith,\n    },\n\n    \nend\n\ntheorem division_algorithm' (a b : ℤ) (ha : a > 0) (hb : b > 0) : \n(∃ q r : ℤ, ((a = b * q + r) ∧ (0 ≤ r) ∧ (r < b))) :=\nbegin\n  have h := euclidean_domain.quotient_mul_add_remainder_eq a b,\n  use euclidean_domain.quotient a b,\n  use euclidean_domain.remainder a b,\n  sorry,\nend\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/division_algorithm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642556, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7810008020330852}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Demostrar el teorema facil que afirma que 2 + 3 = 5.\n-- ---------------------------------------------------------------------\n\ntheorem facil : 2 + 3 = 5 := rfl\n\n-- Comentarios:\n-- 1. Para activar la ventana de objetivos (*Lean Goal*) se escribe\n--    C-c C-g\n-- 2. Se desactiva volviendo a escribir C-c C-g\n-- 3. La táctica rfl (ver https://bit.ly/2BYbiBH) comprueba que 2+3 y 5\n--    son iguales por definición.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Calcular el tipo de facil\n-- ---------------------------------------------------------------------\n\n-- #check facil\n\n-- Comentario: Colocando el cursor sobre check se obtiene\n--    facil : 2 + 3 = 5\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Enunciar el teorema dificil que afirma que se verifica\n-- el último teorema de Fermat, omitiendo la demostración.\n-- ---------------------------------------------------------------------\n\n/-\ndef ultimo_teorema_de_Fermat :=\n  ∀ x y z n : ℕ, n > 2 → x * y * z ≠ 0 → x^n + y^n ≠ z^n\n\ntheorem dificil : ultimo_teorema_de_Fermat :=\nsorry\n-/\n\n-- Comentarios:\n-- 1. La palabra sorry se usa para omitir la demostración.\n-- 2. Se puede verificar la teoría pulsando\n--       C-x ! l\n--    Se obtiene\n--       31   1 warning         declaration 'dificil' uses sorry\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Calcular el tipo de dificil.\n-- ---------------------------------------------------------------------\n\n-- #check dificil\n\n-- Comentario: Colocando el cursor sobre check se obtiene\n--    dificil : ultimo_teorema_de_Fermat\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/Introduccion/Ejemplo_de_teoremas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7810008015281853}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández Palacios\n\n! This file was ported from Lean 3 source module data.complex.cardinality\n! leanprover-community/mathlib commit 1c4e18434eeb5546b212e830b2b39de6a83c473c\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.Basic\nimport Mathbin.Data.Real.Cardinality\n\n/-!\n# The cardinality of the complex numbers\n\nThis file shows that the complex numbers have cardinality continuum, i.e. `#ℂ = 𝔠`.\n-/\n\n\nopen Cardinal Set\n\nopen Cardinal\n\n/-- The cardinality of the complex numbers, as a type. -/\n@[simp]\ntheorem mk_complex : (#ℂ) = 𝔠 := by\n  rw [mk_congr Complex.equivRealProd, mk_prod, lift_id, mk_real, continuum_mul_self]\n#align mk_complex mk_complex\n\n/-- The cardinality of the complex numbers, as a set. -/\n@[simp]\ntheorem mk_univ_complex : (#(Set.univ : Set ℂ)) = 𝔠 := by rw [mk_univ, mk_complex]\n#align mk_univ_complex mk_univ_complex\n\n/-- The complex numbers are not countable. -/\ntheorem not_countable_complex : ¬(Set.univ : Set ℂ).Countable :=\n  by\n  rw [← le_aleph_0_iff_set_countable, not_le, mk_univ_complex]\n  apply cantor\n#align not_countable_complex not_countable_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/Data/Complex/Cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7809095350745229}}
{"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 order.filter.basic\n\n/-!\n\n# The order (≤) on filters\n\nWe think of filters as generalised subsets, and just as subsets are partially ordered\nby `⊆`, filters are partially ordered too, by `≤`. Recall that a subset `X : set α`\nof `α` gives rise to a principal filter `𝓟 X : filter α`, and we definitely\nwant `X ⊆ Y ↔ 𝓟 X ≤ 𝓟 Y` so let's think about how this should work. If `F` and `G`\nare filters, then `F ≤ G` should mean \"the generalised subset `F` is contained\nin the generalised subset `G`\", so it should mean \"if a normal subset of α contains\n`G` then it contains `F`\", so it should mean `G.sets ⊆ F.sets`, which is in fact\nthe definition. Note that the smaller the filter `F`, the bigger the collection\n`F.sets`, because `F` is contained in more sets!\n\nIn the `filter` namespace there's a lemma\n\n\nLet's formalise this. Show that 𝓟 S ≤ 𝓟 T ↔ S ⊆ T.\nNote that this is called `principal_mono` in mathlib but \nthere's no harm in proving it yourself.\n\nSome helpful lemmas (all in the `filter` namespace):\n\n`mem_principal : T ∈ 𝓟 S ↔ S ⊆ T`\n`mem_principal_self S : S ∈ 𝓟 S`\n`le_def : F ≤ G ↔ ∀ (S : set α), S ∈ G → S ∈ F`\n\n-/\n\nvariable {α : Type}\n\nopen filter set -- so we don't keep having to type `filter.le_def` and `set.subset.trans` etc\n\nopen_locale filter -- for 𝓟 notation\n\nexample (S T : set α) : 𝓟 S ≤ 𝓟 T ↔ S ⊆ T :=\nbegin\n  sorry,\nend\n\n-- Here's another useful lemma about principal filters.\n-- It's called `le_principal_iff` in mathlib but why\n-- not try proving it yourself?\n\nexample (F : filter α) (S : set α) : F ≤ 𝓟 S ↔ S ∈ F :=\nbegin\n  sorry,\nend\n\n/-\n\n## Filters are a complete lattice\n\nFirst I claim that if Fᵢ are a bunch of filters, indexed by `i : I`, then\nthe intersection of `Fᵢ.sets` is also a filter. Let's check this.\n\n-/\n\ndef LUB {I : Type} (F : I → filter α) : filter α :=\n{ sets := {X | ∀ i, X ∈ F i},\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/-\n\nNow let's check that this is a least upper bound for the Fᵢ! We check the\ntwo axioms.\n\n-/\n\n-- it's an upper bound\nexample (I : Type) (F : I → filter α) (i : I) : F i ≤ LUB F :=\nbegin\n  sorry,\nend\n\n-- it's ≤ all other upper bounds\nexample (I : Type) (F : I → filter α) (G : filter α) (hG : ∀ i, F i ≤ G) : LUB F ≤ G :=\nbegin\n  sorry,\nend\n\n\n/-\n\nJust like it's possible to talk about the topological space generated\nby a collection of subsets of `α` -- this is the smallest topology\nfor which the given subsets are all open -- it's also possible to talk\nabout the filter generated by a collection of subsets of `α`. One\ncan define it as the intersection of all the filters that contain your\ngiven collection of subsets (we just proved above that this is a filter).\nThis gives us a definition of greatest lower bound for filters too.\n\n-/\n\n-- greatest lower bound of filters Fᵢ is the least upper bound of the filters G whose `sets`\n-- contain all of the `Fᵢ.sets`\ndef GLB {I : Type} (F : I → filter α) : filter α := LUB (λ (G : {G : filter α | ∀ i, (F i).sets ⊆ G.sets}), G.1)\n\n-- it's a lower bound\nexample (I : Type) (F : I → filter α) (i : I) : GLB F ≤ F i :=\nbegin\n  sorry,\nend\n\n-- it's ≥ all other lower bounds\nexample (I : Type) (F : I → filter α) (G : filter α) (hG : ∀ i, G ≤ F i) : G ≤ GLB F :=\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/section11_and_a_half_filters/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7808379932171802}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport data.matrix.basic\n\n/-!\n# Trace of a matrix\n\nThis file defines the trace of a matrix, the linear map\nsending a matrix to the sum of its diagonal entries.\n\nSee also `linear_algebra.trace` for the trace of an endomorphism.\n\n## Tags\n\nmatrix, trace, diagonal\n\n-/\n\nopen_locale big_operators\nopen_locale matrix\n\nnamespace matrix\n\nsection trace\n\nuniverses u v w\n\nvariables {m : Type*} (n : Type*) {p : Type*}\nvariables (R : Type*) (M : Type*) [semiring R] [add_comm_monoid M] [module R M]\n\n/--\nThe diagonal of a square matrix.\n-/\ndef diag : (matrix n n M) →ₗ[R] n → M :=\n{ to_fun    := λ A i, A i i,\n  map_add'  := by { intros, ext, refl, },\n  map_smul' := by { intros, ext, refl, } }\n\nvariables {n} {R} {M}\n\n@[simp] lemma diag_apply (A : matrix n n M) (i : n) : diag n R M A i = A i i := rfl\n\n@[simp] lemma diag_one [decidable_eq n] :\n  diag n R R 1 = λ i, 1 := by { dunfold diag, ext, simp [one_apply_eq] }\n\n@[simp] lemma diag_transpose (A : matrix n n M) : diag n R M Aᵀ = diag n R M A := rfl\n\n@[simp] lemma diag_col_mul_row (a b : n → R) : diag n R R (col a ⬝ row b) = a * b :=\nby { ext, simp [matrix.mul_apply] }\n\nvariables (n) (R) (M)\n\n/--\nThe trace of a square matrix.\n-/\ndef trace [fintype n] : (matrix n n M) →ₗ[R] M :=\n{ to_fun    := λ A, ∑ i, diag n R M A i,\n  map_add'  := by { intros, apply finset.sum_add_distrib, },\n  map_smul' := by { intros, simp [finset.smul_sum], } }\n\nvariables {n} {R} {M} [fintype n] [fintype m] [fintype p]\n\n@[simp] lemma trace_diag (A : matrix n n M) : trace n R M A = ∑ i, diag n R M A i := rfl\n\nlemma trace_apply (A : matrix n n M) : trace n R M A = ∑ i, A i i := rfl\n\n@[simp] lemma trace_one [decidable_eq n] :\n  trace n R R 1 = fintype.card n :=\nhave h : trace n R R 1 = ∑ i, diag n R R 1 i := rfl,\nby simp_rw [h, diag_one, finset.sum_const, nsmul_one]; refl\n\n@[simp] lemma trace_transpose (A : matrix n n M) : trace n R M Aᵀ = trace n R M A := rfl\n\n@[simp] lemma trace_transpose_mul (A : matrix m n R) (B : matrix n m R) :\n  trace n R R (Aᵀ ⬝ Bᵀ) = trace m R R (A ⬝ B) := finset.sum_comm\n\nlemma trace_mul_comm {S : Type v} [comm_semiring S] (A : matrix m n S) (B : matrix n m S) :\n  trace m S S (A ⬝ B) = trace n S S (B ⬝ A) :=\nby rw [←trace_transpose, ←trace_transpose_mul, transpose_mul]\n\nlemma trace_mul_cycle {S : Type v} [comm_semiring S]\n  (A : matrix m n S) (B : matrix n p S) (C : matrix p m S) :\n  trace _ S S (A ⬝ B ⬝ C) = trace p S S (C ⬝ A ⬝ B) :=\nby rw [trace_mul_comm, matrix.mul_assoc]\n\nlemma trace_mul_cycle' {S : Type v} [comm_semiring S]\n  (A : matrix m n S) (B : matrix n p S) (C : matrix p m S) :\n  trace _ S S (A ⬝ (B ⬝ C)) = trace p S S (C ⬝ (A ⬝ B)) :=\nby rw [←matrix.mul_assoc, trace_mul_comm]\n\n@[simp] lemma trace_col_mul_row (a b : n → R) : trace n R R (col a ⬝ row b) = dot_product a b :=\nby simp [dot_product]\n\n/-! ### Special cases for `fin n`\n\nWhile `simp [fin.sum_univ_succ]` can prove these, we include them for convenience and consistency\nwith `matrix.det_fin_two` etc.\n-/\n\n@[simp] lemma trace_fin_zero (A : matrix (fin 0) (fin 0) R) : trace _ R R A = 0 :=\nrfl\n\nlemma trace_fin_one (A : matrix (fin 1) (fin 1) R) : trace _ R R A = A 0 0 :=\nadd_zero _\n\nlemma trace_fin_two (A : matrix (fin 2) (fin 2) R) : trace _ R R A = A 0 0 + A 1 1 :=\ncongr_arg ((+) _) (add_zero (A 1 1))\n\nlemma trace_fin_three (A : matrix (fin 3) (fin 3) R) : trace _ R R A = A 0 0 + A 1 1 + A 2 2 :=\nby { rw [← add_zero (A 2 2), add_assoc], refl }\n\nend trace\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/trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8740772253241803, "lm_q1q2_score": 0.780821409482698}}
{"text": "\nimport tactic                 \nimport data.set.basic  \nimport data.real.basic\nimport algebra.order.floor\n\n-- proof based on\n-- https://math.stackexchange.com/questions/233670/nested-division-in-the-ceiling-function\n\n\ntheorem nested_ceil (m n : ℤ ) (hmpos : m > 0) (hnpos : n > 0) (x : ℝ) : ⌈x / (m * n)⌉ = ⌈(⌈x/m⌉ : ℝ) /(n : ℝ)⌉ :=\nbegin\n  set k := ⌈x/↑m⌉,\n  have h_le : ⌈x / ((m : ℝ)  * (n : ℝ)⌉  ≤ ⌈(k : ℝ) / (n : ℝ)⌉,\n  {\n    suffices h0 : x/(↑m * ↑n) ≤ k/↑n,\n    {\n      exact int.ceil_mono h0,\n    },\n    suffices h1 : x / ↑m ≤ ↑k,\n    {\n      rw ← div_div,\n      have hnpos' : 0 < (n : ℝ ) := int.cast_pos.mpr hnpos,\n      rwa div_le_div_right hnpos',\n    },\n    exact int.le_ceil (x / ↑m),\n\n  },\n\n  have h_ge : ⌈x / ((m : ℝ)  * (n : ℝ))⌉  ≥ ⌈(k : ℝ) / (n : ℝ)⌉,\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 : ↑l ≥ 0 := zero_le ↑l,\n    have hq1 :  ⌈x / (↑m * ↑n)⌉ ≤ ⌈x / (↑m * ↑n)⌉ + ↑l  := by linarith, \n    have hq2 :  ⌈x / (↑m * ↑n)⌉ + ↑l <  ⌈(k : ℝ)  / (n : ℝ)  ⌉ := by linarith,\n    set q := ⌈x / (↑m * ↑n)⌉ + ↑l,\n    have hq1' : x / (↑m * ↑n) ≤ q := int.ceil_le.mp hq1,\n    have hq2' : (q : ℝ)  < (k : ℝ)  / (n : ℝ)  := int.lt_ceil.mp hq2,\n    have hnpos' : 0 ≤ n := le_of_lt hnpos,\n    have hnpos'' : 0 ≤ (n : ℝ)  := int.cast_nonneg.mpr hnpos',\n    have hq'' : (x / (↑m * ↑n)) * ↑n  ≤ q * ↑n  := mul_le_mul_of_nonneg_right hq1' hnpos'',\n    rw div_mul at hq'',\n    have h_n_neq_zero : n  ≠ 0 := ne_of_gt hnpos,   \n    have h_n_neq_zero' : ( n : ℝ )  ≠ 0 := int.cast_ne_zero.mpr h_n_neq_zero, \n    rw ← mul_div at hq'',  \n    rw div_self h_n_neq_zero' at hq'',\n    rw mul_one at hq'',\n    have hqn : (q : ℝ) * (n : ℝ) = ↑(q * n) := (int.cast_mul q n).symm,\n    have hk : ⌈(x / ↑m)⌉ ≤ (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' : (⌈x / ↑m⌉ : ℝ)  ≤ ↑(q * n) := int.cast_le.mpr hk,\n    linarith,\n  },\n  exact le_antisymm h_le h_ge,\n\nend", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/Zachary/nested_ceil.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269985, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.780807826432741}}
{"text": "/-\n2. It is often possible to bring a component of a formula outside a universal quantifier, when it does not depend on the quantified variable. Try proving these (one direction of the second of these requires classical logic):\n-/\n\nopen classical\n\nvariables (α : Type) (p q : α → Prop)\nvariable r : Prop\n\nexample : α → ((∀ x : α, r) ↔ r) :=\n    assume a : α,\n    show (∀ x : α, r) ↔ r, from\n        iff.intro\n        (\n            assume h : (∀ x : α, r),\n            show r, from h a\n        )\n        (\n            assume h : r,\n            show ∀ x : α, r, from\n                assume hx : α,\n                show r, from h\n        )\n-- short version\nexample : α → ((∀ x : α, r) ↔ r) :=\n    λ a, iff.intro (λ h, h a) (λ h, λ hx, h)\n\n\n\nexample : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=\n    iff.intro\n    (\n        assume h : ∀ x, p x ∨ r,\n        or.elim (em r)\n        (\n            assume hr : r,\n            show (∀ x, p x) ∨ r, from or.inr hr\n        )\n        (\n            assume hnr : ¬r,\n            show (∀ x, p x) ∨ r, from\n                or.inl\n                (\n                    assume xx,\n                    or.elim (h xx)\n                    (\n                        assume hpxx : p xx,\n                        show p xx, from hpxx\n                    )\n                    (\n                        assume hr : r,\n                        false.elim (hnr hr)\n                    )\n                )\n        )\n    )\n    (\n        assume h : (∀ x, p x) ∨ r,\n        or.elim h\n        (\n            assume h1 : ∀ x, p x,\n            show ∀ x, p x ∨ r, from\n                assume x,\n                or.inl (h1 x)\n        )\n        (\n            assume h2 : r,\n            show ∀ x, p x ∨ r, from\n                assume x : α,\n                or.inr h2\n        )\n    )\n-- shor version\nexample : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=\n    iff.intro\n    (\n        λ h,\n        (em r).elim\n        (\n            λ hr : r,\n            or.inr hr\n        )\n        (\n            λ hnr : ¬r,\n            or.inl (λ xx, (h xx).elim id (λ hr, absurd hr hnr) )\n        )\n    )\n    (\n        λ h, or.elim h (λ h1, λ x, or.inl (h1 x)) (λ h2, λ x, or.inr h2)\n    )\n\n\n\nexample : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=\n    iff.intro\n    (\n        assume h : ∀ x, r → p x,\n        show r → ∀ x, p x, from\n            assume hr : r,\n            show ∀ x, p x, from\n                assume xx : α,\n                (h xx) hr\n    )\n    (\n        assume h : r → ∀ x, p x,\n        show ∀ x, r → p x, from\n            assume xx : α,\n            assume hr : r,\n            (h hr) xx\n    )\n-- short version\nexample : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=\n    ⟨(λ h, λ hr, λ xx, (h xx) hr), (λ h, λ xx, λ hr, (h hr) xx)⟩\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-ex02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7807999572540592}}
{"text": "import topology.metric_space.basic\n\n/-!\n\n# Pseudometric spaces\n\nA pseudometric on a set (or type) X is a distance function obeying\nall the axioms of a metric except possible d(x,y)=0 ↔ x = y.\n\n-/\n\n/-- A function d : X^2 → ℝ is a *pseudometric* if it satisfies the axioms\n  for a metric space apart from possibly the axiom saying d(x,y)=0 -> x=y -/ \nclass is_pseudometric {X : Type} (d : X → X → ℝ) :=\n(d_self : ∀ x : X, d x x = 0)\n(d_comm : ∀ x y : X, d x y = d y x)\n(d_triangle : ∀ x y z : X, d x z ≤ d x y + d y z)\n\n-- ignore this boilerplate code: it's restating the lemmas to make them easier to use\n\nvariable {X : Type}\n\nlemma d_self (d : X → X → ℝ) [is_pseudometric d] :\n  ∀ x : X, d x x = 0 := @is_pseudometric.d_self X d _\n\nlemma d_comm (d : X → X → ℝ) [is_pseudometric d] :\n  ∀ x y : X, d x y = d y x := @is_pseudometric.d_comm X d _\n\nlemma d_triangle (d : X → X → ℝ) [is_pseudometric d] :\n  ∀ x y z : X, d x z ≤ d x y + d y z := @is_pseudometric.d_triangle X d _\n\n-- fun fact: we never included the axiom that d x y ≥ 0, because it follows\n-- from the other axioms!\n\nvariables (d : X → X → ℝ) [is_pseudometric d]\n\ntheorem d_nonneg {x y : X} : 0 ≤ d x y :=\nbegin\n\n  -- First note 0 = d(x,x) ≤ d(x,y)+d(y,x) = 2d(x,y)\n\n  have h2 : 0 ≤ 2 * d x y,\n    calc 0 = d x x : by rw d_self d\n    ...    ≤ d x y + d y x : by refine d_triangle d _ _ _\n    ...    = d x y + d x y : by rw d_comm d\n    ...    = 2 * d x y : by ring,\n\n  -- and now the result is obvious\n\n  linarith\nend\n\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/pseudometric_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7807970224144951}}
{"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.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 → Y`, one can define `x_1 ≈ 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 → Z` such that `x_1 ≈ 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 → Y) (x_1 x_2 : X) : Prop :=\nf x_1 = f x_2\n\nlemma function.to_rel_equiv {X Y : Type} (f : X → Y) : equivalence (function.to_rel f) :=\nbegin\n  sorry\nend\n\ninstance function.to_setoid {X Y : Type} (f : X → 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 → Y) : ∃ (Z : Type) (g : X → Z), \nfunction.surjective g ∧ ∀ x x' : X, f x = f x' ↔ 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 → 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 → Y → Prop) (f : X → Y) \n  (x1 x2 : X) : Prop :=\nsorry\n\nlemma fun_rel.to_rel_def {X Y : Type} (S : Y → Y → Prop) (f : X → Y) \n(x_1 x_2 : X) : (fun_rel.to_rel S f) x_1 x_2 ↔ S (f x_1) (f x_2) :=\nbegin\n  sorry\nend\n\nlemma fun_rel.to_rel_refl {X Y : Type} {S : Y → Y → Prop} (hS : reflexive S) (f : X → 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 → Y → Prop} (hS : symmetric S) (f : X → 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 → Y → Prop} (hS : transitive S) (f : X → 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 → Y → Prop} (hS : equivalence S) (f : X → Y) : \n  equivalence (fun_rel.to_rel S f) :=\nbegin\n  sorry\nend\n\ninstance fun_rel.to_setoid {X Y : Type} {S : Y → Y → Prop} (hS : equivalence S) (f : X → 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 × 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 → X → Prop) (S : Y → Y → Prop) \n  (u v : X × Y) : Prop :=\nsorry\n\nlemma prod_rel_def {X Y : Type} {R : X → X → Prop} {S : Y → Y → Prop} (u v : X × Y) :\n  prod_rel R S u v ↔ R u.1 v.1 ∧ S u.2 v.2 := \nbegin\n  sorry\nend\n\nlemma prod_rel_refl {X Y : Type} {R : X → X → Prop} {S : Y → Y → 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 → X → Prop} {S : Y → Y → 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 → X → Prop} {S : Y → Y → 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 → X → Prop} {S : Y → Y → Prop} (hR : equivalence R)\n  (hS : equivalence S) : equivalence (prod_rel R S) :=\nbegin\n  sorry\nend", "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/sheet08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.7807915296693708}}
{"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.eval\n\n/-!\n# Primes congruent to one\n\nWe prove that, for any positive `k : ℕ`, there are infinitely many primes `p` such that\n`p ≡ 1 [MOD k]`.\n-/\n\nnamespace nat\n\nopen polynomial nat filter\n\n/-- For any positive `k : ℕ` there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`. -/\nlemma exists_prime_ge_modeq_one {k : ℕ} (n : ℕ) (hpos : 0 < k) :\n  ∃ (p : ℕ), nat.prime p ∧ n ≤ p ∧ p ≡ 1 [MOD k] :=\nbegin\n  let b := 3 * (k * n.factorial),\n  have hgt : 1 < (eval ↑b (cyclotomic k ℤ)).nat_abs,\n  { have hkey : ∀ l : ℕ, 2 < 3 * (l.succ * n.factorial) := λ l, lt_mul_of_lt_of_one_le\n          (2 : ℕ).lt_succ_self (le_mul_of_le_of_one_le (nat.succ_pos _) n.factorial_pos),\n    rcases k with _ | _ | k,\n    { simpa using hpos, },\n    { simp only [one_mul, int.coe_nat_mul, int.coe_nat_succ, int.coe_nat_zero, zero_add,\n        cyclotomic_one, eval_sub, eval_X, eval_one],\n      convert int.nat_abs_lt_nat_abs_of_nonneg_of_lt int.one_nonneg _,\n      rw lt_sub_iff_add_lt,\n      specialize hkey 0,\n      norm_cast,\n      rwa one_mul at hkey, },\n    calc 1 ≤ _ : by { rw le_tsub_iff_left (one_le_two.trans (hkey _).le), exact (hkey _).le, }\n       ... < _ : sub_one_lt_nat_abs_cyclotomic_eval (one_lt_succ_succ k)\n                   (one_lt_two.trans (hkey k.succ)).ne.symm, },\n  let p := min_fac (eval ↑b (cyclotomic k ℤ)).nat_abs,\n  haveI hprime : fact p.prime := ⟨min_fac_prime (ne_of_lt hgt).symm⟩,\n  have hroot : is_root (cyclotomic k (zmod p)) (cast_ring_hom (zmod p) b),\n  { rw [is_root.def, ← map_cyclotomic_int k (zmod p), eval_map, coe_cast_ring_hom,\n    ← int.cast_coe_nat, ← int.coe_cast_ring_hom, eval₂_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 ↑b (cyclotomic k ℤ)).nat_abs },\n  refine ⟨p, hprime.1, _, _⟩,\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 : ¬p ∣ 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 [←order_of_units, zmod.coe_unit_of_coprime, ←this] at hdiv,\n    exact ((modeq_iff_dvd' hprime.1.pos).2 hdiv).symm }\nend\n\nlemma frequently_at_top_modeq_one {k : ℕ} (hpos : 0 < k) :\n  ∃ᶠ p in at_top, nat.prime p ∧ p ≡ 1 [MOD k] :=\nbegin\n  refine frequently_at_top.2 (λ n, _),\n  obtain ⟨p, hp⟩ := exists_prime_ge_modeq_one n hpos,\n  exact ⟨p, ⟨hp.2.1, hp.1, hp.2.2⟩⟩\nend\n\nlemma infinite_set_of_prime_modeq_one {k : ℕ} (hpos : 0 < k) :\n  set.infinite {p : ℕ | nat.prime p ∧ p ≡ 1 [MOD k]} :=\nfrequently_at_top_iff_infinite.1 (frequently_at_top_modeq_one hpos)\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/primes_congruent_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.7807915296340527}}
{"text": "import algebra.comm_rings.basic\nimport algebra.comm_rings.ideals.basic\nimport algebra.comm_rings.ideals.instances\nimport algebra.comm_rings.ideals.identities\nimport algebra.comm_rings.instances.basic\n\nnamespace comm_ring\n\nuniverses u v w\n\nopen set\nopen classical\n\ndef in_same_coset {R : Type u} [comm_ring R] (I: ideal R) : R → R → Prop := λ x y, x + -y ∈ I.body\n\nnotation x ` ≡ ` y ` mod ` I := in_same_coset I x y\n\nlemma in_same_coset_refl {R : Type u} [comm_ring R] (I: ideal R) : ∀ x, x ≡ x mod I :=\nbegin\n  intros x,\n  have h : x + -x ∈ ↑I,\n    rw minus_inverse,\n    exact I.contains_zero,\n  exact h,\nend \n\nlemma in_same_coset_symm {R : Type u} [comm_ring R] (I: ideal R) : symmetric (in_same_coset I) :=\nbegin\n  intros x y hxy,\n  have h : y + -x ∈ ↑I,\n    rw ← minus_minus y,\n    rw ← minus_dis,\n    apply I.minus_closure,\n    rw add_comm,\n    exact hxy,\n  exact h,\nend\n\nlemma in_same_coset_trans {R : Type u} [comm_ring R] (I: ideal R) : transitive (in_same_coset I) :=\nbegin\n  intros x y z hxy hyz,\n  have hrw : x + -z = (x + -y) + (y + -z),\n    exact calc x + -z = (x + 0) + -z   : by rw add_zero x\n                  ... =  (x + -y) + (y +- z) : by {rw [←minus_inverse, add_comm y (-y)], simp [add_assoc]},\n  have h : x + -z ∈ ↑I,\n    rw hrw,\n    apply I.add_closure,\n    exact hxy,\n    exact hyz,\n  exact h,\nend\n\nlemma mod_respects_add {R : Type u} [comm_ring R] {I: ideal R} \n  : ∀ {x₁ x₂ y₁ y₂ : R} , (x₁ ≡ y₁ mod I) → (x₂ ≡ y₂ mod I) → ((x₁ + x₂) ≡ (y₁ + y₂) mod I) :=\nbegin\n  intros x₁ x₂ y₁ y₂ h₁ h₂,\n  have hrw : (x₁ + x₂) + -(y₁ + y₂) = (x₁ + -y₁) + (x₂ + -y₂),\n    exact calc (x₁ + x₂) + -(y₁ + y₂) = (x₁ + x₂) + (-y₁ + -y₂) : by rw minus_dis\n                                  ... =  x₁ + (x₂ + -y₁) + -y₂  : by simp [add_assoc]\n                                  ... =  x₁ + (-y₁ + x₂) + -y₂  : by simp [add_comm]\n                                  ... = (x₁ + -y₁) + (x₂ + -y₂) : by simp [add_assoc],\n  have h : (x₁ + x₂) + -(y₁ + y₂) ∈ ↑I,\n    rw hrw,\n    apply I.add_closure,\n    exact h₁,\n    exact h₂,\n  exact h,\nend\n\nlemma mod_respects_mul {R : Type u} [comm_ring R] {I: ideal R} \n  : ∀ {x₁ x₂ y₁ y₂ : R} , (x₁ ≡ y₁ mod I) → (x₂ ≡ y₂ mod I) → ((x₁ * x₂) ≡ (y₁ * y₂) mod I) :=\nbegin\n  intros x₁ x₂ y₁ y₂ h₁ h₂,\n  have hrw : x₁ * x₂ + -(y₁ * y₂) = x₁ * (x₂ + -y₂) + (x₁ + -y₁) * y₂,\n    symmetry,\n    exact calc x₁ * (x₂ + -y₂) + (x₁ + -y₁) * y₂ = (x₁ * x₂ + x₁ * (-y₂)) + y₂ * (x₁ + -y₁)       : by simp [mul_dis,mul_comm]\n                                             ... = (x₁ * x₂ + x₁ * (-y₂)) + (x₁ * y₂ + (-y₁) *y₂) : by simp [mul_dis,mul_comm]\n                                             ... = x₁ * x₂ + (x₁ * (-y₂) + x₁ * y₂) + (-y₁) * y₂  : by simp [add_assoc]\n                                             ... = x₁ * x₂ + (x₁ * (-y₂ + y₂)) + ((-y₁) *y₂)      : by simp [←mul_dis]\n                                             ... = x₁ * x₂ + (-y₁) * y₂                           : by simp [add_comm,minus_inverse,add_zero,mul_zero]\n                                             ... = x₁ * x₂ + - (y₁ * y₂)                          : by rw [←minus_mul],\n  have h : x₁ * x₂ + -(y₁ * y₂) ∈ ↑I,\n    rw hrw,\n    apply I.add_closure,\n    apply I.mul_absorb,\n    exact h₂,\n    rw mul_comm,\n    apply I.mul_absorb,\n    exact h₁,\n  exact h,\nend\n\nlemma mod_respects_minus {R : Type u} [comm_ring R] {I: ideal R}\n  : ∀ {x y : R}, (x ≡ y mod I) → (-x ≡ -y mod I) :=\nbegin\n  intros x y hxy,\n  have h : -x + (-(-y)) ∈ ↑I,\n    rw ← minus_dis,\n    apply I.minus_closure,\n    exact hxy,\n  exact h,\nend\n\ndef quotient_ring_setiod (R : Type u) [l:comm_ring R] (I: ideal R) : setoid R := \n  {\n    r := λ x y, x ≡ y mod I,\n    iseqv := ⟨in_same_coset_refl I, in_same_coset_symm I, in_same_coset_trans I⟩,\n  }\n\ndef quotient_ring (R :Type u) [comm_ring R] (I : ideal R) : Type u := quotient (comm_ring.quotient_ring_setiod R I)\n\ninfixr  `/ᵣ` : 25 := quotient_ring  \n\ndef quotient_ring_mk {R : Type u} [comm_ring R] (I: ideal R) : R → R /ᵣ I := @quotient.mk R (quotient_ring_setiod R I)\n\ninfixr ` +ᵣ ` : 50 := λ x I , quotient_ring_mk I x\n\ntheorem quotient_ring_exists_rep {R: Type u} [comm_ring R] (I : ideal R) : ∀ q : R/ᵣ I, ∃ a : R, (a +ᵣ I) = q := @quotient.exists_rep R (quotient_ring_setiod R I)\ntheorem quotient_ring_sound {R: Type u} [comm_ring R] (I : ideal R) : ∀ {a b : R}, (a ≡ b mod I) → (a +ᵣ I) = (b +ᵣ I) := @quotient.sound R (quotient_ring_setiod R I)\ntheorem quotient_ring_exact {R: Type u} [comm_ring R] (I : ideal R) : ∀ {a b : R}, (a +ᵣ I) = (b +ᵣ I) → (a ≡ b mod I) := @quotient.exact R (quotient_ring_setiod R I)\n\ndef quotient_ring_one {R: Type u} [l:comm_ring R] (I:ideal R) : R /ᵣ I := l.one +ᵣ I\n\ninstance quotient_ring_has_one {R: Type u} [comm_ring R] (I:ideal R) : has_one (R /ᵣ I) := ⟨quotient_ring_one I⟩ \n\ntheorem quotient_ring_concrete_char_of_one {R: Type u} [l:comm_ring R] (I:ideal R) : (l.one +ᵣ I) = 1 := rfl\n\ndef quotient_ring_zero {R: Type u} [l:comm_ring R] (I:ideal R) : R /ᵣ I := l.zero +ᵣ I\n\ninstance quotient_ring_has_zero {R: Type u} [comm_ring R] (I:ideal R) : has_zero (R /ᵣ I) := ⟨quotient_ring_zero I⟩ \n\ntheorem quotient_ring_concrete_char_of_zero {R: Type u} [l:comm_ring R] (I:ideal R) : (l.zero +ᵣ I) = 0 := rfl\n\ndef quotient_ring_pre_add {R: Type u} [comm_ring R] (I:ideal R) : R → R → R /ᵣ I :=\n  λ a b, (a + b) +ᵣ I\n\nlemma quotient_ring_pre_add_lifts {R: Type u} [comm_ring R] (I:ideal R) \n  : ∀ x₁ x₂ y₁ y₂, (x₁ ≡ y₁ mod I) → (x₂ ≡ y₂ mod I) →  quotient_ring_pre_add I x₁ x₂ = quotient_ring_pre_add I y₁ y₂ := \nbegin\n  intros x₁ x₂ y₁ y₂,\n  intros h₁ h₂,\n  apply quotient.sound,\n  apply mod_respects_add,\n  exact h₁,\n  exact h₂,\nend\n\ndef quotient_ring_add {R: Type u} [comm_ring R] (I : ideal R) : (R /ᵣ I) → (R /ᵣ I) → R /ᵣ I :=\nbegin\n  apply quotient.lift₂,\n  exact quotient_ring_pre_add_lifts I,\nend\n\ninstance quotient_ring_has_add {R: Type u} [comm_ring R] (I : ideal R) : has_add (R/ᵣI) := ⟨quotient_ring_add I⟩\n\ntheorem quotient_ring_concrete_char_of_add {R: Type u} [comm_ring R] (I : ideal R) : ∀ a b : R, (a +ᵣ I) + (b +ᵣ I) = ((a + b) +ᵣ I) :=\nbegin\n  intros a b,\n  refl,\nend \n\ndef quotient_ring_pre_mul {R: Type u} [comm_ring R] (I:ideal R) : R → R → R /ᵣ I :=\n  λ a b, (a * b) +ᵣ I\n\nlemma quotient_ring_pre_mul_lifts {R: Type u} [comm_ring R] (I:ideal R) \n  : ∀ x₁ x₂ y₁ y₂, (x₁ ≡ y₁ mod I) → (x₂ ≡ y₂ mod I) →  quotient_ring_pre_mul I x₁ x₂ = quotient_ring_pre_mul I y₁ y₂ := \nbegin\n  intros x₁ x₂ y₁ y₂,\n  intros h₁ h₂,\n  apply quotient.sound,\n  apply mod_respects_mul,\n  exact h₁,\n  exact h₂,\nend\n\ndef quotient_ring.mul {R: Type u} [comm_ring R] (I : ideal R) : (R /ᵣ I) → (R /ᵣ I) → R /ᵣ I :=\nbegin\n  apply quotient.lift₂,\n  exact quotient_ring_pre_mul_lifts I,\nend\n\ninstance quotient_ring_has_mul {R: Type u} [comm_ring R] (I : ideal R) : has_mul (R/ᵣI) := ⟨quotient_ring.mul I⟩\n\ntheorem quotient_ring_concrete_char_of_mul {R: Type u} [comm_ring R] (I : ideal R) : ∀ a b : R, (a +ᵣ I) * (b +ᵣ I) = ((a * b) +ᵣ I) :=\nbegin\n  intros a b,\n  refl,\nend\n\ndef quotient_ring_pre_minus {R: Type u} [comm_ring R] (I : ideal R) : R → (R/ᵣI) :=\n  λ x : R, (-x) +ᵣ I\n\nlemma quotient_ring_pre_minus_lifts {R: Type u} [comm_ring R] (I : ideal R) : ∀ x y, (x ≡ y mod I) → quotient_ring_pre_minus I x = quotient_ring_pre_minus I y :=\nbegin\n  intros x y hxy,\n  apply quotient.sound,\n  apply mod_respects_minus,\n  exact hxy,\nend\n\ndef quotient_ring_minus {R: Type u} [comm_ring R] (I : ideal R) : (R /ᵣ I) → (R /ᵣ I) :=\nbegin\n  apply quotient.lift,\n  exact quotient_ring_pre_minus_lifts I,\nend \n\ninstance quotient_ring_has_neg {R: Type u} [comm_ring R] (I : ideal R) : has_neg (R/ᵣI) := ⟨quotient_ring_minus I⟩  \n\ntheorem quotient_ring_concrete_char_of_minus {R: Type u} [comm_ring R] (I : ideal R) : ∀ a : R, -(a +ᵣ I)  = (-a +ᵣ I) :=\nbegin\n  intros a,\n  refl,\nend\n\ntheorem quotient_ring_add_assoc {R: Type u} [comm_ring R] (I : ideal R) : ∀ q₁ q₂ q₃ : (R /ᵣ I), q₁ + (q₂ + q₃) = (q₁ + q₂) +q₃ :=\nbegin\n  intros q₁ q₂ q₃,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  let r₃ := some (quotient_ring_exists_rep I q₃),\n  have hr₃ : (r₃ +ᵣ I) = q₃ := some_spec (quotient_ring_exists_rep I q₃),\n  rw [←hr₁,←hr₂,←hr₃],\n  simp [quotient_ring_concrete_char_of_add],\n  rw add_assoc,\nend\n\ntheorem quotient_ring_add_comm {R: Type u} [comm_ring R] (I : ideal R) : ∀ q₁ q₂ : (R /ᵣ I), q₁ + q₂ = q₂ + q₁ :=\nbegin\n  intros q₁ q₂,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  rw [←hr₁,←hr₂],\n  simp [quotient_ring_concrete_char_of_add],\n  rw add_comm,\nend\n\ntheorem quotient_ring_mul_assoc {R: Type u} [comm_ring R] (I : ideal R) : ∀ q₁ q₂ q₃ : (R /ᵣ I), q₁ * (q₂ * q₃) = (q₁ * q₂) * q₃ :=\nbegin\n  intros q₁ q₂ q₃,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  let r₃ := some (quotient_ring_exists_rep I q₃),\n  have hr₃ : (r₃ +ᵣ I) = q₃ := some_spec (quotient_ring_exists_rep I q₃),\n  rw [←hr₁,←hr₂,←hr₃],\n  simp [quotient_ring_concrete_char_of_mul],\n  rw mul_assoc,\nend\n\ntheorem quotient_ring_mul_comm {R: Type u} [comm_ring R] (I : ideal R) : ∀ q₁ q₂ : (R /ᵣ I), q₁ * q₂ = q₂ * q₁ :=\nbegin\n  intros q₁ q₂,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  rw [←hr₁,←hr₂],\n  simp [quotient_ring_concrete_char_of_mul],\n  rw mul_comm,\nend\n\ntheorem quotient_ring_mul_dis {R: Type u} [comm_ring R] (I : ideal R) : ∀ q₁ q₂ q₃ : (R /ᵣ I), q₁ * (q₂ + q₃) = (q₁ * q₂) + (q₁ * q₃) :=\nbegin\n  intros q₁ q₂ q₃,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  let r₃ := some (quotient_ring_exists_rep I q₃),\n  have hr₃ : (r₃ +ᵣ I) = q₃ := some_spec (quotient_ring_exists_rep I q₃),\n  rw [←hr₁,←hr₂,←hr₃],\n  simp [quotient_ring_concrete_char_of_mul,quotient_ring_concrete_char_of_add],\n  rw mul_dis,\nend\n\ntheorem quotient_ring_mul_one {R: Type u} [comm_ring R] (I : ideal R) : ∀ q : (R /ᵣ I), q * 1 = q :=\nbegin\n  intro q,\n  let r := some (quotient_ring_exists_rep I q),\n  have hr : (r +ᵣ I) = q := some_spec (quotient_ring_exists_rep I q),\n  rw [←hr,←quotient_ring_concrete_char_of_one],\n  simp [quotient_ring_concrete_char_of_mul],\n  rw mul_one,\nend\n\ntheorem quotient_ring_add_zero {R: Type u} [comm_ring R] (I : ideal R) : ∀ q : (R /ᵣ I), q + 0 = q :=\nbegin\n  intro q,\n  let r := some (quotient_ring_exists_rep I q),\n  have hr : (r +ᵣ I) = q := some_spec (quotient_ring_exists_rep I q),\n  rw [←hr,←quotient_ring_concrete_char_of_zero],\n  simp [quotient_ring_concrete_char_of_add],\n  rw add_zero,\nend\n\ntheorem quotient_ring_minus_inverse {R: Type u} [comm_ring R] (I : ideal R) : ∀ q : (R /ᵣ I), q + -q = 0 :=\nbegin\n  intro q,\n  let r := some (quotient_ring_exists_rep I q),\n  have hr : (r +ᵣ I) = q := some_spec (quotient_ring_exists_rep I q),\n  rw [←hr,←quotient_ring_concrete_char_of_zero],\n  simp [quotient_ring_concrete_char_of_add, quotient_ring_concrete_char_of_minus],\n  rw minus_inverse,\nend\n\ninstance quotient_ring_comm_ring {R: Type u} [comm_ring R] (I : ideal R) : comm_ring (R/ᵣI) :=\nbegin\n  split,\n  exact quotient_ring_add_assoc I,\n  exact quotient_ring_add_comm I,\n  exact quotient_ring_add_zero I,\n  exact quotient_ring_minus_inverse I,\n  exact quotient_ring_mul_assoc I,\n  exact quotient_ring_mul_comm I,\n  exact quotient_ring_mul_one I,\n  exact quotient_ring_mul_dis I,\nend\n\ndef quot_ring_hom {R: Type u} [comm_ring R] (I : ideal R) : R →ᵣ (R/ᵣI) :=\n  {\n    map := λ x, x +ᵣ I,\n    prevs_mul := λ _ _, rfl,\n    prevs_add := λ _ _, rfl,\n    prevs_one := rfl, \n  }\n\ntheorem quotient_ring_concrete_char_of_quot_map {R: Type u} [comm_ring R] (I : ideal R)\n  : ∀ x : R, quot_ring_hom I x = (x +ᵣ I) :=\nbegin\n  intro,\n  refl,\nend\n\ntheorem quotient_zero_implies_in_ideal {R: Type u} [comm_ring R] (I : ideal R) \n  : ∀ {x : R} , (x +ᵣ I) = 0 → x ∈ I.body := \nbegin\n  intros x hx,\n  rw [←add_zero x,← minus_zero_zero],\n  have hrw : (x ≡ 0 mod I) = ((x +-0) ∈ I.body) := rfl,\n  rw ← hrw,\n  apply quotient_ring_exact,\n  exact hx,\nend\n\ntheorem in_ideal_implies_quotient_zero {R: Type u} [comm_ring R] (I : ideal R) \n  : ∀ {x : R} , x ∈ I.body → (x +ᵣ I) = 0 :=\nbegin\n  intros x hx,\n  rw ← quotient_ring_concrete_char_of_zero,\n  apply quotient_ring_sound,\n  rw [←add_zero x,← minus_zero_zero] at hx,\n  exact hx,\nend\n\ntheorem quot_ring_hom_kernel {R: Type u} [l:comm_ring R] (I : ideal R) : ker (quot_ring_hom I) = I :=\nbegin\n  apply ideal_equality,\n  apply subset_antisymmetric,\n  split,\n  intros x hx,\n  apply quotient_zero_implies_in_ideal,\n  apply zero_ideal_is_just_zero,\n  exact hx,\n  intros x hx,\n  have h₁: (x +ᵣ I) = 0,\n    apply in_ideal_implies_quotient_zero,\n    exact hx,\n  have h: (x +ᵣ I) ∈ (zero_ideal (R/ᵣI)).body,\n    rw h₁,\n    exact linear_combination.empty_sum,\n  exact h,\nend\n\ndef quot_ring_universal_property {R: Type u} [lR:comm_ring R] (I : ideal R) \n  : (Σ (Q : Type u) [lQ:comm_ring Q], (@ring_hom R Q lR lQ)) → Prop \n  | ⟨Q,lQ,φ⟩ := (∀ r : R, r ∈ I.body → φ r = lQ.zero) ∧ \n    (∀ pair : (Σ (Q : Type u) [lQ:comm_ring Q], (@ring_hom R Q lR lQ)),\n    (∀ r : R, r ∈ I.body → pair.2.2 r = pair.2.1.zero) \n     → ∃! ψ : (@ring_hom Q pair.1 lQ pair.2.1) , pair.2.2 = (@ring_hom_comp R Q pair.1 lR lQ pair.2.1 ψ φ))\n\ndef quot_ring_app_lifts {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) (lQ:comm_ring Q) (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : ∀ r₁ r₂ : R, (r₁ ≡ r₂ mod I) →  φ r₁ =  φ r₂ :=\nbegin\n  intros r₁ r₂ h₁₂,\n  have hrw : r₁ = r₂ + (r₁ + -r₂),\n    rw [add_comm r₁ (-r₂),add_assoc,minus_inverse],\n    rw [add_comm,add_zero],\n  rw hrw,\n  have trv : φ.map = ⇑φ := rfl,\n  rw [←trv,φ.prevs_add,trv, hφvan (r₁ + -r₂) h₁₂,add_zero],\nend\n\ndef quot_ring_can_map {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) (lQ:comm_ring Q) (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : (R/ᵣI) → Q :=\nbegin\n  apply quotient.lift,\n  exact quot_ring_app_lifts I lQ φ hφvan,\nend\n\ntheorem quotient_ring_concrete_char_of_can_map {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) (lQ:comm_ring Q) (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : ∀ x : R, quot_ring_can_map I lQ φ hφvan (x +ᵣ I) = φ x :=\nbegin\n  intro,\n  refl,\nend\n\ntheorem quot_ring_can_map_prevs_add {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) (lQ:comm_ring Q) (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : ∀ q₁ q₂ : (R/ᵣI), quot_ring_can_map I lQ φ hφvan (q₁ + q₂) = (quot_ring_can_map I lQ φ hφvan q₁) + (quot_ring_can_map I lQ φ hφvan q₂) :=\nbegin\n  intros q₁ q₂,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  rw [←hr₁,←hr₂],\n  simp [quotient_ring_concrete_char_of_add I, quotient_ring_concrete_char_of_can_map],\n  exact φ.prevs_add r₁ r₂,\nend\n\ntheorem quot_ring_can_map_prevs_mul {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) (lQ:comm_ring Q) (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : ∀ q₁ q₂ : (R/ᵣI), quot_ring_can_map I lQ φ hφvan (q₁ * q₂) = (quot_ring_can_map I lQ φ hφvan q₁) * (quot_ring_can_map I lQ φ hφvan q₂) :=\nbegin\n  intros q₁ q₂,\n  let r₁ := some (quotient_ring_exists_rep I q₁),\n  have hr₁ : (r₁ +ᵣ I) = q₁ := some_spec (quotient_ring_exists_rep I q₁),\n  let r₂ := some (quotient_ring_exists_rep I q₂),\n  have hr₂ : (r₂ +ᵣ I) = q₂ := some_spec (quotient_ring_exists_rep I q₂),\n  rw [←hr₁,←hr₂],\n  simp [quotient_ring_concrete_char_of_mul I, quotient_ring_concrete_char_of_can_map],\n  exact φ.prevs_mul r₁ r₂,\nend\n\ntheorem quot_ring_can_map_prevs_one {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) (lQ:comm_ring Q) (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : quot_ring_can_map I lQ φ hφvan 1 = 1 :=\nbegin\n  simp [←quotient_ring_concrete_char_of_one,quotient_ring_concrete_char_of_can_map],\n  exact φ.prevs_one,\nend\n  \ndef quot_ring_can_hom {R : Type u} {Q : Type v} [comm_ring R] (I : ideal R) [lQ:comm_ring Q] (φ : R →ᵣ Q) (hφvan : ∀ r : R , r ∈ I.body → φ r = 0)\n  : ((R/ᵣI) →ᵣ Q) := \n  {\n    map := quot_ring_can_map I lQ φ hφvan,\n    prevs_add := quot_ring_can_map_prevs_add I lQ φ hφvan,\n    prevs_mul := quot_ring_can_map_prevs_mul I lQ φ hφvan,\n    prevs_one := quot_ring_can_map_prevs_one I lQ φ hφvan,\n  }\n\n\n\ntheorem quotient_ring_satisfies_its_universal_property {R : Type u} [comm_ring R] (I :ideal R) \n  : quot_ring_universal_property I ⟨(R/ᵣI),comm_ring.quotient_ring_comm_ring I,quot_ring_hom I⟩ :=\nbegin\n  split,\n  intros x hx,\n  rw ← quot_ring_hom_kernel I at hx,\n  apply zero_ideal_is_just_zero,\n  exact hx,\n  intros pair hpair,\n  cases pair with Q rest,\n  cases rest with lQ φ,\n  resetI,\n  existsi (quot_ring_can_hom I φ hpair),\n  split,\n  apply ring_hom_equality,\n  refl,\n  intros φ' hφ',\n  apply ring_hom_equality_hack,\n  have trv₁ : ∀ x : R , φ x = φ' (x +ᵣ I),\n    simp at hφ',\n    intros x,\n    rw hφ',\n    refl, \n  apply funext,\n  intro q,\n  let r := some (quotient_ring_exists_rep I q),\n  have hr : (r +ᵣ I) = q := some_spec (quotient_ring_exists_rep I q),\n  rw ← hr,\n  simp,\n  rw ← trv₁ r,\n  refl,\nend\n\nlemma quotient_ring_comp_hom_id {R Q: Type u} [comm_ring R] [lQ : comm_ring Q] {I : ideal R} {q : R →ᵣ Q} \n  (Qup : quot_ring_universal_property I ⟨Q,lQ,q⟩) : ∀ φ : Q →ᵣ Q, q = (φ  ∘ᵣ q) → φ = idᵣ :=\nbegin\n  intros φ hφ,\n  cases Qup with vanish abNon,\n  cases abNon ⟨Q,lQ,q⟩ vanish with ψ hψ,\n  dsimp at ψ,\n  dsimp at hψ,\n  cases hψ with hψ ψup,\n  have h₁ : φ = ψ,\n    apply ψup,\n    exact hφ,\n  have h₂ : idᵣ = ψ,\n    apply ψup,\n    symmetry,\n    exact id_hom_left_comp q,\n  rw [h₁,h₂],\nend\n\ntheorem universal_property_chars_quotient_ring {R Q Q': Type u} [lR:comm_ring R] [lQ : comm_ring Q] \n  [lQ' : comm_ring Q'] {I : ideal R} (q : R →ᵣ Q) (q' : R →ᵣ Q') \n  : quot_ring_universal_property I ⟨Q,lQ,q⟩ → quot_ring_universal_property I ⟨Q',lQ',q'⟩\n  → ∃! ψ : Q →ᵣ Q', q' = (ψ ∘ᵣ q) ∧ (ring_isomorphism ψ) := \nbegin\n  intros upQ upQ',\n  cases upQ with vanish abNon,\n  cases upQ' with vanish' abNon',\n  cases abNon ⟨Q',lQ',q'⟩ vanish' with ψ hψ,\n  dsimp at ψ,\n  dsimp at hψ,\n  cases abNon' ⟨Q,lQ,q⟩ vanish with ψ' hψ',\n  dsimp at ψ',\n  dsimp at hψ',\n  cases hψ with hψ ψup,\n  cases hψ' with hψ' ψ'up,\n  existsi ψ,\n  split,\n  split,\n  exact hψ,\n  existsi ψ',\n  split,\n  apply quotient_ring_comp_hom_id ⟨vanish,abNon⟩,\n  rw [← ring_comp_assoc,← hψ,← hψ'],\n  apply quotient_ring_comp_hom_id ⟨vanish',abNon'⟩,\n  rw [← ring_comp_assoc,← hψ',← hψ],\n  intros ψint hψint,\n  apply ψup,\n  exact and.left hψint,\nend\n\ntheorem first_ring_isomorphism_thm {R₁ : Type u} {R₂ : Type v} [comm_ring R₁] [comm_ring R₂] (φ : R₁ →ᵣ R₂)\n  : ∃ ψ : (R₁/ᵣ(ker φ)) →ᵣ Im φ, ring_isomorphism ψ :=\nbegin\n  have hφvanish : ∀ r : R₁, r ∈ (ker φ).body → im_trival_hom_in φ r = 0,\n    intros r hr,\n    apply val_injective,\n    apply zero_ideal_is_just_zero,\n    exact hr,  \n  let ψ : (R₁/ᵣ(ker φ)) →ᵣ Im φ := quot_ring_can_hom (ker φ) (im_trival_hom_in φ) hφvanish,\n  have trv : ∀ r : R₁, (ψ (r+ᵣ ((ker φ) : ideal R₁))).val = φ r,\n    intro r,\n    have subtrv₁ : ψ = quot_ring_can_hom (ker φ) (im_trival_hom_in φ) hφvanish := rfl,\n    rw subtrv₁,\n    simp,\n    have subtrv₂ : quot_ring_can_hom (ker φ) (im_trival_hom_in φ) hφvanish (r +ᵣ ((ker φ) : ideal R₁)) \n                    = im_trival_hom_in φ r,\n      simp,\n      apply quotient_ring_concrete_char_of_can_map (ker φ),\n      exact hφvanish,\n    rw subtrv₂,\n    refl,\n  existsi ψ,\n  apply bijective_ring_hom_ring_iso,\n  split,\n  apply zero_kernel_injective,\n  apply ideal_equality,\n  apply subset_antisymmetric,\n  split,\n  intros q hq,\n  let r : R₁ := some (quotient_ring_exists_rep (ker φ) q),\n  have hr : (r +ᵣ ((ker φ):ideal R₁) ) = q:= some_spec (quotient_ring_exists_rep (ker φ) q),\n  simp at hr,\n  rw ← hr,\n  rw ← hr at hq,\n  rw elements_of_kernel at hq,\n  have hrkφ : φ r = 0,\n    rw ← trv,\n    simp,\n    rw hq,\n    refl,\n  have hq0 : (r +ᵣ ((ker φ) :ideal R₁)) = 0,\n    apply in_ideal_implies_quotient_zero,\n    rw elements_of_kernel,\n    assumption,\n  simp at hq0,\n  rw hq0,\n  apply linear_combination.empty_sum,\n  intros q hq,\n  rw elements_of_kernel,\n  rw zero_ideal_is_just_zero hq,\n  apply ring_hom_preserves_zero ψ,\n  intro y,\n  cases y.property with x hx,\n  existsi (x +ᵣ ((ker φ) : ideal R₁)),\n  apply val_injective,\n  rw trv,\n  symmetry,\n  assumption,\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/instances/quotient_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7806817312384835}}
{"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# Bijections\n\nLike finiteness, there are two ways to say that a function is bijective in Lean.\nFurthermore, you will have heard of both of them, although it may well not\nhave occurred to you that these two ways were particularly different. It turns\nout that one of them is more constructive than the other. Let's talk about\nthe nonconstructive (propositional) way of talking about bijections.\n\nLet `X` and `Y` be types, and say `f : X → Y` is a function. \n\n-/\n\nvariables (X Y : Type) (f : X → Y)\n\n-- The `Prop`-valued way of saying that `f` is bijective is simply\n-- to say literally that `f` is bijective, i.e., injective and surjective.\n\nexample : Prop := function.bijective f\n\n-- Because `f` is a function type, a little Lean hack introduced recently\n-- actually enables you to use dot notation for this.\n\nexample : Prop := f.bijective \n\n-- The definition of `function.bijective f` is \n-- `function.injective f ∧ function.surjective f`, and the definitions of\n-- injective and surjective are what you think they are.\n\nexample : f.bijective ↔ f.injective ∧ f.surjective :=\nbegin\n  refl\nend\n\nexample : f.bijective ↔ (∀ x₁ x₂ : X, f x₁ = f x₂ → x₁ = x₂) ∧ \n  (∀ y : Y, ∃ x : X, f x = y) :=\nbegin\n  refl\nend\n\n-- It's a theorem that `f` is bijective if and only if it has a two-sided\n-- inverse. One way is not hard to prove: see if you can do it. Make\n-- sure you know the maths proof first! If you can't do this then\n-- please ask. There's lots of little Lean tricks which make this\n-- question not too bad, but there are lots of little pitfalls too.\n\nexample : (∃ g : Y → X, f ∘ g = id ∧ g ∘ f = id) → f.bijective :=\nbegin\n  sorry,\nend\n\n-- The other way is harder in Lean, unless you know about the `choose`\n-- tactic. Given `f` and a proof that it's a bijection, how do you\n-- prove the existence of a two-sided inverse `g`? You'll have to construct\n-- `g`, and the `choose` tactic does this for you.\n-- If `hfs` is a proof that `f` is surjective, try `choose g hg using hfs`.\nexample : f.bijective → ∃ g : Y → X, f ∘ g = id ∧ g ∘ f = id :=\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/section09bijections_and_isomorphisms/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7806817271424767}}
{"text": "open Classical\n\nvariable (p q r s : Prop)\n\n---------------------------------\n-- Double negation elimination --\n---------------------------------\nexample (h : ¬¬p) : p :=\n  Or.elim (em p) \n    (fun hp : p => hp)\n    (fun hnp : ¬p => absurd hnp h)\n\n\n------------------\n-- Modus Ponens --\n------------------\nexample : p → (p → q) → q := \n  fun (hp : p) (hpq : p → q) => hpq hp \n\n\n----------------------\n-- De Morgan's rules -\n----------------------\n\n-- ¬(p ∧ q) ↔ (¬p ∨ ¬q)\nexample : ¬(p ∧ q) ↔ (¬p ∨ ¬q):=\n  Iff.intro\n  (\n    fun h : ¬(p ∧ q) =>\n    Or.elim (em p)\n    (\n      fun hp : p =>\n      Or.elim (em q) \n      (\n        fun hq : q =>\n        have hpq : p ∧ q := And.intro hp hq \n        show ¬p ∨ ¬q from absurd hpq h\n      )\n      (fun hnq : ¬q => show ¬p ∨ ¬q from Or.inr hnq) \n    )\n    (fun hnp : ¬p => Or.inl hnp)\n  )\n  (\n    fun h : ¬p ∨ ¬q =>\n    Or.elim h\n    (\n      fun hnp : ¬p =>\n      fun hpq : p ∧ q =>\n      absurd (And.left hpq) hnp \n    )\n    (\n      fun hnq : ¬q =>\n      fun hpq : p ∧ q =>\n      absurd (And.right hpq) hnq\n    )\n  )\n\n-- ¬(p ∨ q) ↔ (¬p ∧ ¬q)\nexample : ¬(p ∨ q) ↔ (¬p ∧ ¬q):=\n  Iff.intro \n  (\n    fun h₀ : ¬(p ∨ q) =>\n    have hnp : ¬p := fun hp : p => h₀ (Or.inl hp)\n    have hnq : ¬q := fun hq : q => h₀ (Or.inr hq)\n    show ¬p ∧ ¬q from And.intro hnp hnq\n  )\n  (\n    fun h₀ : ¬p ∧ ¬q =>\n    fun h₁ : p ∨ q =>\n    Or.elim h₁ \n      (fun hp : p => absurd hp (And.left h₀))\n      (fun hq : q => absurd hq (And.right h₀))\n  )\n\n\n------------------------------\n-- Commutativity of ∧ and ∨ --\n------------------------------\n\n-- Commutativity of ∧\nexample : p ∧ q ↔ q ∧ p := \n  Iff.intro\n  (\n    fun hpq : p ∧ q =>\n    show q ∧ p from And.intro (And.right hpq) (And.left hpq)\n  )\n  (\n    fun hqp : q ∧ p =>\n    show p ∧ q from And.intro (And.right hqp) (And.left hqp)\n  )\n  \n  \n-- Commutativity of ∨ \nexample : p ∨ q ↔ q ∨ p :=\n  Iff.intro\n  (\n    fun hpq : p ∨ q =>\n    Or.elim hpq (fun hp => Or.inr hp) (fun hq => Or.inl hq)\n  )\n  (\n    fun hqp : q ∨ p =>\n    Or.elim hqp (fun hq => Or.inr hq) (fun hp => Or.inl hp)\n  )\n\n\n------------------------------\n-- Associativity of ∧ and ∨ --\n------------------------------\n\n-- Associativity of ∧\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := \n  Iff.intro\n  (\n    fun hpqr : (p ∧ q) ∧ r =>\n    have hp : p := And.left (And.left hpqr)\n    have hq : q := And.right (And.left hpqr)\n    have hr : r := And.right hpqr\n    show p ∧ (q ∧ r) from And.intro (And.left (And.left hpqr)) (And.intro hq hr)\n  )\n  (\n    fun hpqr : p ∧ (q ∧ r) =>\n    have hp : p := And.left hpqr\n    have hq : q := And.left (And.right hpqr)\n    have hr : r := And.right (And.right hpqr)\n    show (p ∧ q) ∧ r from And.intro (And.intro hp hq) hr\n  )\n\n\n-- Associativity of ∨ \nexample : (p ∨ q) ∨ r → p ∨ (q ∨ r) := \n  fun hpqr : (p ∨ q) ∨ r =>\n  Or.elim hpqr\n  (\n    fun hpq : p ∨ q =>\n    Or.elim hpq \n    (\n      fun hp : p => \n      show p ∨ (q ∨ r) from Or.inl hp\n    )\n    (\n      fun hq : q =>\n      have hqr : q ∨ r := Or.inl hq\n      show p ∨ (q ∨ r) from Or.inr hqr\n    )\n  )\n  (\n    fun hr : r => \n    have hqr : q ∨ r := Or.inr hr\n    show p ∨ (q ∨ r) from Or.inr hqr\n  )\n\n--------------------\n-- Distributivity --\n--------------------\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := \n  Iff.intro \n  (\n    fun hpqr : p ∧ (q ∨ r) =>\n    have hqr : q ∨ r := And.right hpqr\n    Or.elim hqr\n    (\n      fun hq : q =>\n      have hpq : p ∧ q := And.intro (And.left hpqr) hq \n      show (p ∧ q) ∨ (p ∧ r) from Or.inl hpq\n    )\n    (\n      fun hr : r =>\n      have hpr : p ∧ r := And.intro (And.left hpqr) hr \n      show (p ∧ q) ∨ (p ∧ r) from Or.inr hpr\n    )\n  )\n  (\n    fun h : (p ∧ q) ∨ (p ∧ r) =>\n    Or.elim h \n    (\n      fun hpq : p ∧ q =>\n      show p ∧ (q ∨ r) from And.intro (And.left hpq) (Or.inl (And.right hpq))\n    )\n    (\n      fun hpr : p ∧ r =>\n      show p ∧ (q ∨ r) from And.intro (And.left hpr) (Or.inr (And.right hpr))\n    )\n  )\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := \n  Iff.intro \n  (\n    fun hpqr : p ∨ (q ∧ r) =>\n    Or.elim hpqr \n    (\n      fun hp : p =>\n      have hpq : p ∨ q := Or.inl hp \n      have hpr : p ∨ r := Or.inl hp\n      show (p ∨ q) ∧ (p ∨ r) from And.intro hpq hpr\n    )\n    (\n      fun hqr : q ∧ r =>\n      have hpq : p ∨ q := Or.inr (And.left hqr)\n      have hpr : p ∨ r := Or.inr (And.right hqr)\n      show (p ∨ q) ∧ (p ∨ r) from And.intro hpq hpr\n    )\n  )\n  (\n    fun h : (p ∨ q) ∧ (p ∨ r) =>\n    have hpq : p ∨ q := And.left h\n    have hpr : p ∨ r := And.right h \n    Or.elim hpq\n    (fun hp : p => Or.inl hp)\n    (\n      fun hq : q =>\n      Or.elim hpr\n      (fun hp : p => Or.inl hp)\n      (\n        fun hr : r =>\n        have hqr : q ∧ r := And.intro hq hr\n        show p ∨ (q ∧ r) from Or.inr hqr\n      )\n    )\n  )\n\n\n----------------------\n-- Other properties --\n----------------------\nexample : (p → (q → r)) ↔ (p ∧ q → r) := \n  Iff.intro\n  (\n    fun hpqr : p → (q → r) =>\n    fun hpq : p ∧ q =>\n    have hqr : q → r := hpqr (And.left hpq)\n    show r from hqr (And.right hpq)\n  )\n  (\n    fun hpqr : p ∧ q → r =>\n    fun hp : p =>\n    fun hq : q =>\n    have hpq : p ∧ q := And.intro hp hq \n    show r from hpqr hpq \n  )\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \n  Iff.intro\n  (\n    fun h₀ : (p ∨ q) → r =>\n    have h₁ : p → r := fun hp : p => h₀ (Or.inl hp)\n    have h₂ : q → r := fun hq : q => h₀ (Or.inr hq)\n    show (p → r) ∧ (q → r) from And.intro h₁ h₂\n  )\n  (\n    fun h₀ : (p → r) ∧ (q → r) => \n    fun h₁ : p ∨ q =>\n    Or.elim h₁ \n      (fun hp : p => (And.left h₀) hp)\n      (fun hq : q => (And.right h₀) hq)\n  )\n\nexample : ¬(p ∧ ¬p) :=\n  fun h : p ∧ ¬p => absurd (And.left h) (And.right h)\n\nexample : p ∧ ¬q → ¬(p → q) := \n  fun h₀ : p ∧ ¬q =>\n  fun h₁ : p → q =>\n  absurd (h₁ (And.left h₀)) (And.right h₀)\n\nexample : ¬p → (p → q) := \n  fun h₀ : ¬p =>  \n  fun h₁ : p =>\n  show q from absurd h₁ h₀ \n\nexample : (¬p ∨ q) → (p → q) :=\n  fun h₀ : ¬p ∨ q =>\n  fun h₁ : p =>\n  Or.elim h₀ \n    (fun h₂ : ¬p => show q from absurd h₁ h₂)\n    (fun h₂ : q => show q from h₂)\n\nexample : p ∨ False ↔ p := \n  Iff.intro\n  (\n    fun h₀ : p ∨ False =>\n    Or.elim h₀ \n      (fun hp : p => hp)\n      (fun h₁ : False => show p from False.elim h₁)\n  )\n  (\n    fun hp : p =>\n    show p ∨ False from Or.inl hp\n  )\n\nexample : p ∧ False ↔ False := \n  Iff.intro\n  (\n    fun h₀ : p ∧ False =>\n    show False from And.right h₀\n  )\n  (\n    fun h₀ : False =>\n    show p ∧ False from False.elim h₀\n  )\n\n\nexample : (p → q) → (¬q → ¬p) :=\n  fun h₀ : p → q =>\n  fun h₁ : ¬q =>\n  fun h₂ : p =>\n  absurd (h₀ h₂) h₁ \n\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) := \n  fun h₀ : p → r ∨ s =>\n  Or.elim (em p)\n  (\n    fun hp : p =>\n    have hrs : r ∨ s := h₀ hp \n    Or.elim hrs \n    (\n      fun hr : r =>\n      have hpr : p → r := fun _ : p => hr\n      show (p → r) ∨ (p → s) from Or.inl hpr\n    )\n    (\n      fun hs : s =>\n      have hps : p → s := fun _ : p => hs\n      show (p → r) ∨ (p → s) from Or.inr hps\n    )\n  )\n  (\n    fun hnp : ¬p =>\n    have hpr : p → r :=  fun hp : p => absurd hp hnp     \n    show (p → r) ∨ (p → s) from Or.inl hpr\n  )\n\nexample : ¬(p → q) → p ∧ ¬q := \n  fun h₀ : ¬(p → q) => \n  Or.elim (em q) \n  (\n    fun hq : q =>\n    have hpq : p → q := fun _ : p => hq \n    show p ∧ ¬q from absurd hpq h₀\n  )\n  (\n    fun hnq : ¬q =>\n    Or.elim (em p)\n    (\n      fun hp : p =>\n      show p ∧ ¬q from And.intro hp hnq\n    )\n    (\n      fun hnp : ¬p =>\n      have hpq : p → q := fun hp : p => absurd hp hnp \n      show p ∧ ¬q from absurd hpq h₀\n    )\n  )\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/propositional_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7806782173352549}}
{"text": "example: 1 + 1 = 2 := rfl\n\ntheorem add_zero  (n: Nat):   n + 0 = n                  := rfl\ntheorem add_one   (n: Nat):   n + 1 = n.succ             := rfl\ntheorem add_succ  (n k: Nat): n + k.succ = (n + k).succ  := rfl\n\ntheorem zero_add (n: Nat): 0 + n = n := by\n  refine n.recOn rfl (λn (h: 0+n = n) => ?_)\n  show (0+n).succ = n.succ;  rw[h]\n\ntheorem succ_add {n k: Nat}: n.succ + k = (n + k).succ := by\n  refine k.recOn rfl (λk h => ?s)\n  show (n.succ + k).succ = (n + k.succ).succ\n  rw[h]; rfl\n\ntheorem add_assoc {n k p: Nat}: (n + k) + p = n + (k + p) := by\n  refine p.recOn rfl (λp ih => ?s)\n  calc\n    (n + k) + p.succ = (n + k + p).succ   :=  rfl\n                   _ = (n + (k + p)).succ :=  by rw[ih]\n\nexample {n k p: Nat}: (n + k) + p = n + (k + p) := by\n  refine p.recOn rfl (λp ih => ?s)\n  simp[add_succ, ih]\n\ntheorem add_comm {n k: Nat}: n + k = k + n :=\n  n.recOn (by rw[zero_add]; rfl) (λn ih => by simp[add_succ, succ_add, ih])\n\ntheorem add_left_comm (n k p: Nat) : n + (k + p) = k + (n + p) :=\ncalc  n + (k + p)\n    = (n + k) + p  := by rw[←add_assoc]\n  _ = (k + n) + p  := by rw[@add_comm k]\n  _ = k + (n + p)  := by rw[add_assoc]\n\nexample (a b c d e: Nat): (((a + b) + c) + d) + e = (c + ((b + e) + a)) + d :=\nby simp[add_assoc, add_comm, add_left_comm]\n\n-- Умножение\n\ntheorem mul_zero {n: Nat}:   n * 0 = 0               := rfl\ntheorem mul_succ {n k: Nat}: n * k.succ = n * k + n  := rfl\ntheorem mul_one {n: Nat}:    n * 1 = n :=\n  by rw[mul_succ, add_comm]; rfl\n\ntheorem zero_mul {n:Nat}: 0 * n = 0 := by\n  refine n.recOn rfl (λn h => ?_)\n  calc  0 * n.succ\n      = 0 * n + 0  := rfl\n    _ = 0 + 0      := by simp[h]\n\ntheorem succ_mul {n k: Nat}: n.succ * k = n * k + k := by\n  refine k.recOn rfl (λk h => ?_)\n  calc  n.succ * k.succ\n      = n.succ * k + n.succ  := by rw[mul_succ]\n    _ = n * k + k + n.succ   := by simp [h]\n    _ = n * k + n + k.succ   := by simp [add_assoc, add_comm, add_left_comm, add_succ]\n    _ = n * k.succ + k.succ  := by simp [mul_succ]\n\ntheorem one_mul {n:Nat}: 1*n = n := by\n  rw [succ_mul]\n  show 0*n + n = n;  rw [zero_mul, zero_add]\n\ntheorem mul_left_distr {n k p: Nat}: n * (k + p) = n * k + n * p := by\n  refine p.recOn rfl (λp h => ?_)\n  show n * (k + p.succ) = n * k + n * p.succ\n  simp [add_succ, mul_succ, h, add_assoc]\n\ntheorem mul_assoc {n k p: Nat}: (n * k) * p = n * (k * p) := by\n  refine p.recOn rfl (λp h => ?_)\n  show n * k * p.succ = n * (k * p.succ)\n  simp [mul_succ, h, ←mul_left_distr]\n\ntheorem mul_comm {n k: Nat}: n * k = k * n := by\n  refine k.recOn ?_ (λk h => ?_)\n  show n * 0 = 0 * n;            rw [mul_zero, zero_mul]\n  show n * k.succ = k.succ * n;  rw [mul_succ, h, ←succ_mul]\n\ntheorem mul_left_comm {n k p: Nat}: n * (k * p) = k * (n * p) :=\nby rw [←mul_assoc, @mul_comm n, mul_assoc]\n\ntheorem mul_right_distr {n k p: Nat}: (n + k) * p = n * p + k * p :=\nby simp [mul_comm, mul_left_distr]\n\n-- Больше умножения и сложения\n\n-- Сравнение\n\n-- Вычитание и деление\n\n#check Nat.sub\n#check Nat.div\n#check Nat.mod\n\n-- Конечные числа\n\n#check Fin\n#check Subtype\n\n-- Делимость\n\n#check Nat.gcd\n\n-- Целые числа\n\n#check Int\n", "meta": {"author": "suhr", "repo": "tmath", "sha": "60116239b291524c664e6fbefa4c6fb12f2547aa", "save_path": "github-repos/lean/suhr-tmath", "path": "github-repos/lean/suhr-tmath/tmath-60116239b291524c664e6fbefa4c6fb12f2547aa/Tmath/Numbers/Nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7806717796671049}}
{"text": "/- \n  The operator norm is the natural norm for linear operators between normed vector spaces. One can think of it as how much a map stretches unit vectors or as the smallest value that guarantees Cauchy-Schwarz (i.e. ∥L v∥ ≤ ∥L∥ * ∥v∥).\n\n  The derivative of f : E → F is f' : E → continuous_linear_map E F.\n\n  We need the operator norm both to define continuity for the definition of Caratheodory derivative and to take higher-order derivatives.\n-/\n\n-- TODO: We'd like op_norm to return an ennreal, but be able to restrict it to nonnegative reals when needed for a norm. Not sure how to do that yet. We can prove that the op_norm is finite for continuous/bounded linear maps. Should norm operate over nonnegative reals?\n\nimport differentiability.normed_space linear_algebra.linear_map_module analysis.ennreal order.complete_lattice\n\nopen lattice ennreal\n\nnoncomputable theory\n\nuniverses u v w x\n\n/- extended norm -/\n-- TODO: of_real or of_nonneg_real?\ndef op_norm {k : Type u} {E : Type v} {F : Type w} [normed_field k] [normed_space k E] [normed_space k F] : linear_map E F → ennreal := λ L, Inf { M : ennreal | ∀ v : E, (of_nonneg_real ∥L v∥ norm_nonneg) ≤ M * (of_nonneg_real ∥v∥ norm_nonneg) }\n\nsection op_norm\nvariables {k : Type u} {E : Type v} {F : Type w}\nvariables [normed_field k] [normed_space k E] [normed_space k F]\nvariables {L M : linear_map E F}\ninclude k\n\ntheorem op_norm_nonneg : op_norm L ≥ 0 := sorry\n\ntheorem op_norm_zero_iff_zero : op_norm L = 0 ↔ L = 0 := sorry\n\ntheorem op_norm_pos_homo : ∀ c (L : linear_map E F), op_norm (c•L) = (of_real ∥c∥) * op_norm L := sorry\n\ntheorem op_norm_triangle : op_norm (L + M) ≤ op_norm L + op_norm M := sorry\n\nend op_norm\n\ndef op_dist {k : Type u} {E : Type v} {F : Type w} [normed_field k] [normed_space k E] [normed_space k F] : linear_map E F → linear_map E F → ennreal := λ L M, op_norm (L - M)\n\nsection op_dist\nvariables {k : Type u} {E : Type v} {F : Type w}\nvariables [normed_field k] [normed_space k E] [normed_space k F]\nvariables {L M N : linear_map E F}\ninclude k\n\ntheorem op_dist_self : op_dist L L = 0 := sorry\n\ntheorem op_dist_eq_of_dist_eq_zero : op_dist L M = 0 → L = M := sorry\n\ntheorem op_dist_comm : op_dist L M = op_dist M L := sorry\n\ntheorem op_dist_triangle : op_dist L N ≤ op_dist L M + op_dist M N := sorry\n\nend op_dist\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/operator_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7805736813460347}}
{"text": "import algebra.ring.basic\nimport data.real.basic\nimport data.nat.parity\n\nopen nat\n\n--helper theorems\ntheorem num_odd_square_odd (a : ℕ): odd a ↔ odd (a^2) :=\nbegin\n  split,\n  {\n    intro h,\n    rw pow_two,\n    have h₁ : odd (a * a) ↔ odd a ∧ odd a, from nat.odd_mul,\n    rw h₁,\n    split,\n    {exact h},\n    {exact h}\n  },\n  {\n    rw pow_two,\n    intro h,\n    have h₁ : odd (a * a) ↔ (odd a ∧ odd a), from nat.odd_mul,\n    have h₂ : odd a ∧ odd a, by {\n      have h₃ : odd (a * a) → (odd a ∧ odd a), from iff.mp h₁,\n      show odd a ∧ odd a, from h₃ (h)\n    },\n    have h₄ : odd a, from and.left h₂,\n    exact h₄\n  }\nend\n\n-- the same but for even numbers\n-- such wow trick\ntheorem num_even_square_even (a : ℕ) : even a ↔ even (a^2) :=\nbegin\n  repeat {rw nat.even_iff_not_odd},\n  rw not_iff_not_of_iff,\n  rw num_odd_square_odd,\nend\n\n-- another helper theorem for casing the even difference \ntheorem even_diff_same_parity (a b : ℕ) (h₀ : a ≥ b) :\n  even (a - b) ↔ odd a ∧ odd b ∨ even a ∧ even b :=\nbegin\n  split,\n  {\n    intro h,\n    cases even_or_odd a with even_a odd_a,\n    {\n      have h₁ : even a ↔ even b, by {\n        rw ←nat.even_sub,\n        exact h,\n        exact h₀,\n      },\n      have even_b : even b, by {rw ←h₁, exact even_a},\n      have even_a_b : even a ∧ even b, by {\n        exact ⟨even_a, even_b⟩,\n      },\n      exact or.inr even_a_b,\n    },\n    {\n      have h₁ : odd a ↔ odd b, by {\n        rw ←nat.even_sub',\n        exact h,\n        exact h₀,\n      },\n      have odd_b : odd b, by {rw ←h₁, exact odd_a},\n      have odd_a_b : odd a ∧ odd b, by {\n        exact ⟨odd_a, odd_b⟩,\n      },\n      exact or.inl odd_a_b,\n    },\n  },\n  {\n    intro h,\n    cases h with odd_a_b even_a_b,\n    {\n      rw nat.even_sub',\n      {\n        cases odd_a_b with odd_a odd_b,\n        exact iff_of_true odd_a odd_b,\n      },\n      {exact h₀},\n    },\n    {\n      rw nat.even_sub,\n      {\n        cases even_a_b with even_a even_b,\n        exact iff_of_true even_a even_b,\n      },\n      {exact h₀},\n    }\n  }\nend\n\n-- definitions of a square number \ndef is_square (n : ℕ) :=\n  ∃ k : ℕ, k^2 = n\n\n-- useful theorem to rewrite the definition\ntheorem is_square_def {n : ℕ} : \n  is_square n ↔ ∃ k : ℕ, k^2 = n :=\nbegin\n  refl\nend\n\n-- couple of cases to test how squaring of numbers works\n-- case 1: 9 is a square, just using a substitution by definition\ntheorem nine_is_square : is_square 9 :=\nbegin\n  rw is_square_def,\n  use 3,\n  ring\nend\n\n-- case 2: 10 is not a square, here we have to use parity contradictions\ntheorem ten_is_not_square : ¬ is_square 10 :=\nbegin\n  rw is_square_def,\n  by_contradiction,\n  cases h with k h,\n  have h₁ : even 10, by {rw even, use 5, ring},\n  have h₂ : even k, by {rw num_even_square_even, rw h, exact h₁},\n  unfold even at h₂,\n  cases h₂ with m h₃,\n  have h₄ : (2 * m) ^ 2 = 10, by {rw ←h₃, exact h},\n  have h₅ : 4 * m ^ 2 = 10, by {rw ←h₄, ring},\n  have h₆ : 2 * m ^ 2 = 5, by linarith,\n  have h₇ : even (2 * m ^ 2), by {rw even, use (m ^ 2)},\n  have h₈ : even 5, by {rw ←h₆, exact h₇},\n  have h₉ : ¬ even 5, by {\n    rw nat.even_iff_not_odd, rw decidable.not_not_iff,\n    rw odd, use 2, ring\n  },\n  exact h₉ h₈,\nend\n\n-- trivial proof by substitution that 4 is not an odd number\ntheorem four_is_not_odd (n : ℕ) : ¬ odd 4 :=\nbegin\n  rw nat.odd_iff_not_even,\n  rw decidable.not_not_iff,\n  rw even,\n  use 2,\n  ring,\nend\n\n-- solving the original task\ntheorem IMO1986P1\n  (d : ℕ)\n  (h₀ : d > 1)\n  (h₁ : is_square (2 * d - 1))\n  (h₂ : is_square (5 * d - 1))\n  (h₃ : is_square (13 * d - 1)):\n  false :=\nbegin\n  -- step 1, proving that a is odd\n  unfold is_square at h₁,\n  cases h₁ with a ha,\n  have a_odd : odd a, by {\n    rw [num_odd_square_odd, ha, nat.odd_sub'],\n    {\n      have one_odd : odd 1, by {rw odd, use 0, ring},\n      have even_2d : even (2 * d), by {rw even, use d},\n      exact iff_of_true one_odd even_2d\n    },\n    {\n      linarith\n    },\n  },\n  -- step 2, proving that d is odd\n  unfold odd at a_odd,\n  cases a_odd with x hx,\n  have d_odd : odd d, by {\n    have h₄ : (2*x + 1)^2 = 2*d - 1, by {rw ←hx, exact ha},\n    have h₅ : 4*x*x + 4*x + 1 = 2*d - 1, by linarith,\n    have h₆ : 2*d - 1 = 4*x*x + 4*x + 1, by exact eq.symm h₅,\n    have h₇ : 2*d - 1 + 1 = 4*x*x + 4*x + 1 + 1, by linarith,\n    have h₈ : 2*d = 4*x*x + 4*x + 1 + 1, by {\n      rw ←h₇, induction d, linarith, ring_nf,\n    },\n    have h₉ : 2*d = 4*x*x + 4*x + 2, by linarith,\n    have hh₁ : 2*d = 2*(2*x*x + 2*x + 1), by linarith,\n    have hh₂ : d = 2*x*x + 2*x + 1, by linarith,\n    rw odd,\n    use (x*x + x),\n    rw [mul_add, ←mul_assoc],\n    exact hh₂,\n  },\n  -- step 3, proving that b is even\n  unfold odd at d_odd,\n  cases d_odd with d' hd',\n  unfold is_square at h₂,\n  cases h₂ with b hb,\n  have b_even : even b, by {\n    rw [num_even_square_even, hb, hd', even],\n    use (5*d' + 2),\n    repeat {rw mul_add, rw ←mul_assoc},\n    simp,\n    refl,\n  },\n  -- step 4, proving that c is even\n  unfold is_square at h₃,\n  cases h₃ with c hc,\n  have c_even : even c, by {\n    rw [num_even_square_even, hc, hd', even],\n    use (13*d' + 6),\n    repeat {rw mul_add, rw ←mul_assoc},\n    simp,\n    refl,\n  },\n  -- step 5, introducing new parity facts about d\n  unfold even at b_even,\n  cases b_even with y hy,\n  unfold even at c_even,\n  cases c_even with z hz,\n  have hdp : (z + y) * (z - y) = 2*d, by {\n    have h₁ : c^2 - b^2 = (13*d-1) - (5*d-1), by rw [hc, hb],\n    have h₂ : c^2 - b^2 = 8*d, by {\n      rw h₁,\n      have h₃ : 13 = 8 + 5, by refl,\n      rw h₃,\n      rw add_mul,\n      have h₄ : (∃ t₁ : ℕ, t₁ = 8*d), by use (8*d),\n      cases h₄ with t₁ ht₁,\n      have h₅ : (∃ t₂ : ℕ, t₂ = 5*d), by use (5*d),\n      cases h₅ with t₂ ht₂,\n      repeat {rw [←ht₁, ←ht₂]},\n      have h₆ : 1 ≤ t₂, by {rw ht₂, linarith},\n      have h₇ : t₁ + t₂ - 1 = t₁ + (t₂ - 1), by {\n        rw nat.add_sub_assoc,\n        exact h₆,\n      },\n      rw h₇,\n      have h₈ : (∃ t₃ : ℕ, t₃ = t₂ - 1), by use (t₂-1),\n      cases h₈ with t₃ ht₃,\n      repeat {rw ←ht₃},\n      simp,\n    },\n    have h₃ : (2*z)^2 - (2*y)^2 = 8*d, by {rw [←hz, ←hy], exact h₂},\n    have h₄ : 4*z*z - 4*y*y = 8*d, by {\n      rw ←h₃,\n      repeat {rw [pow_two, ←mul_assoc]},\n      ring_nf,\n    },\n    have h₅ : 4*(z*z - y*y) = 4*(2*d), by {\n      have eight_eq : 4 * 2 = 8, by refl,\n      rw [←mul_assoc, eight_eq, ←h₄, mul_assoc, mul_assoc],\n      have h₆ : (∃ t₁ : ℕ, t₁ = z * z), by use (z*z),\n      cases h₆ with t₁ ht₁,\n      have h₇ : (∃ t₂ : ℕ, t₂ = y * y), by use (y*y),\n      cases h₇ with t₂ ht₂,\n      rw [←ht₁, ←ht₂],\n      rw nat.mul_sub_left_distrib,\n    },\n    have h₆ : z*z - y*y = 2*d, by linarith,\n    rw [←h₆, nat.mul_self_sub_mul_self_eq],\n  },\n  -- step 6, proving the possible cases of new parity facts\n  have h : odd (z + y) ∧ odd (z - y) ∨ even (z + y) ∧ even (z - y), by {\n    rw ←even_diff_same_parity,\n    {\n      rw even,\n      use y,\n      have z_ge_y : z ≥ y, by {\n        have y_2_le_z_2 : 2 * y ≤ 2 * z, by {\n          rw [←hy, ←hz],\n          have b2_le_c2 : b ^ 2 ≤ c ^ 2, by {\n            rw [hb, hc],\n            have d5_le_d13 : 5 * d ≤ 13 * d, by linarith,\n            exact tsub_le_tsub_right d5_le_d13 1,\n          },\n          repeat {rw pow_two at b2_le_c2},\n          exact nat.mul_self_le_mul_self_iff.mpr b2_le_c2,\n        },\n        linarith,\n      },\n      have h₁ : (∃ t₁ : ℕ, t₁ = z + y), by use (z + y),\n      cases h₁ with t₁ ht₁,\n      have h₂ : (∃ t₂ : ℕ, t₂ = z - y), by use (z - y),\n      cases h₂ with t₂ ht₂,\n      have h₃ : (∃ t₃ : ℕ, t₃ = 2 * y), by use (2 * y),\n      cases h₃ with t₃ ht₃,\n      rw [←ht₁, ←ht₂, ←ht₃],\n      have h₁ : t₁ ≥ t₂, by {\n        rw [ht₁, ht₂],\n        norm_num,\n        induction y,\n        {ring_nf},\n        {\n          ring_nf,\n          exact le_self_add,\n        },\n      },\n      rw nat.sub_eq_iff_eq_add,\n      {\n        rw [ht₂, ←nat.add_sub_assoc],\n        {\n          rw nat.sub_add_comm,\n          {\n            rw [ht₃, ←nat.one_mul y, ←mul_assoc, ←nat.mul_sub_right_distrib],\n            norm_num,\n            rw ht₁,\n            exact add_comm z y,\n          },\n          {rw ht₃, linarith},\n        },\n        {exact z_ge_y},\n      },\n      {exact h₁},\n    },\n    {\n      have ht : z - y + y ≤ z + y + y, by {simp, linarith},\n      exact (add_le_add_iff_right y).mp ht,\n    },\n  },\n  cases h with mul_odd mul_even,\n  {\n    cases mul_odd with h₁ h₂,\n    have even_2d : even (2 * d), by {rw even, use d},\n    have odd_2d : odd (2 * d), by {rw ←hdp, exact odd.mul h₁ h₂},\n    have not_odd_2d : ¬odd (2 * d), by {rw ←even_iff_not_odd, exact even_2d},\n    exact not_odd_2d odd_2d,\n  },\n  {\n    cases mul_even with h₁ h₂,\n    unfold even at h₁ h₂,\n    cases h₁ with t₁ ht₁,\n    cases h₂ with t₂ ht₂,\n    have d_odd : odd d, by {rw odd, use d', exact hd'},\n    have d_even : even d, by {\n      have h₁ : (2 * t₁) * (2 * t₂) = 2 * d, by {rw [←ht₁, ←ht₂], exact hdp},\n      have h₂ : 2 * t₁ * t₂ = d, by linarith,\n      rw even,\n      use (t₁ * t₂),\n      rw ←h₂,\n      exact mul_assoc 2 t₁ t₂,\n    },\n    have d_not_odd : ¬odd d, by {rw ←even_iff_not_odd, exact d_even},\n    exact d_not_odd d_odd,\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/imo_1986_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8289388019824947, "lm_q1q2_score": 0.7805736666933043}}
{"text": "import Mathlib.Tactic.Basic\nimport Basics.FunctionDefinitions\n/-!\n## Structured Constructs\n\nThe previous section presented the main commands for writing structured proofs: `fun`, `have`,\nand `show`. We now review the components of structured proofs more systematically.\n\n**Lemma or Hypothesis**\n\nThe simplest structured proof, apart from `sorry`, is the name of a lemma or hypothesis. If we have\n-/\nlemma two_add_two_eq_four :\n  2 + 2 = 4 :=\n-- . . .\n/-!\nthen the lemma name `two_add_two_eq_four` can be used as a proof of `2 + 2 = 4` later.\nFor example:\n-/\nlemma this_time_with_feelings :\n  2 + 2 = 4 :=\ntwo_add_two_eq_four\n\n/-!\nWe can pass arguments to lemmas to instantiate ∀-quantifiers and discharge assumptions. Suppose the\nlemma `add_comm (m n : ℕ) : add m n = add n m` is available, and suppose we want to prove its instance\n`add 0 n = add n 0`. This can be achieved neatly using the name of the lemma and two arguments:\n-/\naxiom add_comm (m n : ℕ) : add m n = add n m\n\nlemma add_comm_zero_left (n : ℕ) :\n  add 0 n = add n 0 :=\n  add_comm 0 n\n/-!\nThis has the same effect as the tactical proof `by exact add_comm 0 n`, but is more concise. The `exact`\ntactic can be seen as the inverse of `by`. Why enter tactic mode if only to leave it immediately?\n\nLike with `exact` and `apply`, the lemma or hypothesis’s statement is matched with the current goal up\nto computation. This gives some flexibility.\n\n**fun**\n\n```lean\nfun (names₁ [: type₁]) . . . (namesₙ [: typeₙ]) =>\n```\n\nA lambda `fun` moves ∀-quantified variables from the goal’s target to the local\ncontext. It can be seen as a structured version of the `intros` tactic.\n\n**have**\n\n```lean\nhave name : proposition := proof\n```\nThe `have` command lets us state and prove an intermediate lemma, which may refer to names\nintroduced previously. The proof can be tactical or structured. Generally, we tend to use structured\nproofs to sketch the main argument and resort to tactical proofs for proving subgoals or\nuninteresting intermediate steps. Another kind of mixture arises when we pass arguments to lemma\nnames. For example, given `hab : a → b` and `ha : a`, the tactic `exact hab ha` will prove the goal\n`⊢ b`. Here, `hab ha` is a proof term nested inside a tactic. So the earlier line\n`have hb : b := hab ha` can also be written using a tactic as `have hb : b := by exact hab ha`.\n\n**let**\n```\nlet name [: type] := term\n```\nJust as with a normal `def` the `let` command introduces a new local definition. It can be used to\nname a complex object that occurs several times in the proof afterwards. It is similar to `have` but\nis designed for computable data, not proofs. Expanding or introducing a let corresponds to\nζ-conversion (Section 2.2).\n\n**show**\n```lean\nshow proposition from proof\nshow proposition by tactic proof\n```\nThe `show` command lets us repeat the goal to prove, which can be useful as documentation. It also\nallows us to rephrase the goal in a syntactically equal form up to computation. Instead of the\nsyntax `show proposition from proof`, we can simply write `proof` if we do not want to repeat the goal\nand do not need to rephrase it. The proof can also be tactical if you write `show proposition by ...`\n\n\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/ForwardProofs/StructuredConstructs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594991, "lm_q2_score": 0.8947894632969137, "lm_q1q2_score": 0.7805672362272397}}
{"text": "/-\nTranslate a few missing lemmas to the subgroup API.\nAuthor: Adrián Doña Mateo\n\nThese were contributed to mathlib in\n[#6974](https://github.com/leanprover-community/mathlib/pull/6974/).\n\nThere are no name clashes in this file because the local version of the library is has not\nbeen upgraded to this PR.\n-/\n\nimport group_theory.subgroup\n\n-- These lemmas were added to src/group_theory/subgroup.lean\n\nvariables {G N : Type*} [group G] [group N]\n\nnamespace subgroup\nopen set\n\n@[to_additive]\nlemma comap_mono {f : G →* N} {K K' : subgroup N} : K ≤ K' → comap f K ≤ comap f K' :=\npreimage_mono\n\n@[to_additive]\nlemma map_mono {f : G →* N} {K K' : subgroup G} : K ≤ K' → map f K ≤ map f K' :=\nimage_subset _\n\nopen monoid_hom\n\nvariables {H : Type*} [group H]\n\n@[to_additive]\nlemma map_le_range (f : G →* H) (K : subgroup G) : map f K ≤ f.range :=\n(range_eq_map f).symm ▸ map_mono le_top\n\n@[to_additive]\nlemma ker_le_comap (f : G →* H) (K : subgroup H) : f.ker ≤ comap f K :=\ncomap_mono bot_le\n\n@[to_additive]\nlemma map_comap_le (f : G →* H) (K : subgroup H) : map f (comap f K) ≤ K :=\n(gc_map_comap f).l_u_le _\n\n@[to_additive]\nlemma le_comap_map (f : G →* H) (K : subgroup G) : K ≤ comap f (map f K) :=\n(gc_map_comap f).le_u_l _\n\n@[to_additive]\nlemma map_comap_eq (f : G →* H) (K : subgroup H) :\n  map f (comap f K) = f.range ⊓ K :=\nset_like.ext' begin\n  convert set.image_preimage_eq_inter_range,\n  simp [set.inter_comm],\nend\n\n@[to_additive]\nlemma comap_map_eq (f : G →* H) (K : subgroup G) :\n  comap f (map f K) = K ⊔ f.ker :=\nbegin\n  refine le_antisymm _ (sup_le (le_comap_map _ _) (ker_le_comap _ _)),\n  intros x hx, simp only [exists_prop, mem_map, mem_comap] at hx,\n  rcases hx with ⟨y, hy, hy'⟩,\n  have : y⁻¹ * x ∈ f.ker, { rw mem_ker, simp [hy'] },\n  convert mul_mem _ (mem_sup_left hy) (mem_sup_right this),\n  simp,\nend\n\n@[to_additive]\nlemma map_comap_eq_self {f : G →* H} {K : subgroup H} (h : K ≤ f.range) :\n  map f (comap f K) = K :=\nby rwa [map_comap_eq, inf_eq_right]\n\n@[to_additive]\nlemma map_comap_eq_self_of_surjective {f : G →* H} (h : function.surjective f) (K : subgroup H) :\n  map f (comap f K) = K :=\nmap_comap_eq_self ((range_top_of_surjective _ h).symm ▸ le_top)\n\n@[to_additive]\nlemma comap_injective {f : G →* H} (h : function.surjective f) : function.injective (comap f) :=\nλ K L hKL, by { apply_fun map f at hKL, simpa [map_comap_eq_self_of_surjective h] using hKL }\n\n@[to_additive]\nlemma comap_map_eq_self {f : G →* H} {K : subgroup G} (h : f.ker ≤ K) :\n  comap f (map f K) = K :=\nby rwa [comap_map_eq, sup_eq_left]\n\n@[to_additive]\nlemma comap_map_eq_self_of_injective {f : G →* H} (h : function.injective f) (K : subgroup G) :\n  comap f (map f K) = K :=\ncomap_map_eq_self (((ker_eq_bot_iff _).mpr h).symm ▸ bot_le)\n\n@[to_additive]\nlemma map_injective {f : G →* H} (h : function.injective f) : function.injective (map f) :=\nλ K L hKL, by { apply_fun comap f at hKL, simpa [comap_map_eq_self_of_injective h] using hKL }\n\n@[to_additive]\nlemma map_eq_comap_of_inverse {f : G →* H} {g : H →* G} (hl : function.left_inverse g f)\n  (hr : function.right_inverse g f) (K : subgroup G) : map f K = comap g K :=\nset_like.ext' $ by rw [coe_map, coe_comap, set.image_eq_preimage_of_inverse hl hr]\n\nend subgroup\n\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/mapcomap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8723473763375643, "lm_q1q2_score": 0.780567235786594}}
{"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.choose.multinomial\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.BigOperators.Fin\nimport Mathbin.Data.Nat.Choose.Sum\nimport Mathbin.Data.Nat.Factorial.BigOperators\nimport Mathbin.Data.Fin.VecNotation\nimport Mathbin.Data.Finset.Sym\nimport Mathbin.Data.Finsupp.Multiset\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\n\nopen BigOperators Nat\n\nopen BigOperators\n\nnamespace Nat\n\nvariable {α : Type _} (s : Finset α) (f : α → ℕ) {a b : α} (n : ℕ)\n\n/-- The multinomial coefficient. Gives the number of strings consisting of symbols\nfrom `s`, where `c ∈ s` appears with multiplicity `f c`.\n\nDefined as `(∑ i in s, f i)! / ∏ i in s, (f i)!`.\n-/\ndef multinomial : ℕ :=\n  (∑ i in s, f i)! / ∏ i in s, (f i)!\n#align nat.multinomial Nat.multinomial\n\ntheorem multinomial_pos : 0 < multinomial s f :=\n  Nat.div_pos (le_of_dvd (factorial_pos _) (prod_factorial_dvd_factorial_sum s f))\n    (prod_factorial_pos s f)\n#align nat.multinomial_pos Nat.multinomial_pos\n\ntheorem multinomial_spec : (∏ i in s, (f i)!) * multinomial s f = (∑ i in s, f i)! :=\n  Nat.mul_div_cancel' (prod_factorial_dvd_factorial_sum s f)\n#align nat.multinomial_spec Nat.multinomial_spec\n\n@[simp]\ntheorem multinomial_nil : multinomial ∅ f = 1 :=\n  rfl\n#align nat.multinomial_nil Nat.multinomial_nil\n\n@[simp]\ntheorem multinomial_singleton : multinomial {a} f = 1 := by\n  simp [multinomial, Nat.div_self (factorial_pos (f a))]\n#align nat.multinomial_singleton Nat.multinomial_singleton\n\n@[simp]\ntheorem multinomial_insert_one [DecidableEq α] (h : a ∉ s) (h₁ : f a = 1) :\n    multinomial (insert a s) f = (s.Sum f).succ * multinomial s f :=\n  by\n  simp only [multinomial, one_mul, factorial]\n  rw [Finset.sum_insert h, Finset.prod_insert h, h₁, add_comm, ← succ_eq_add_one, factorial_succ]\n  simp only [factorial_one, one_mul, Function.comp_apply, factorial]\n  rw [Nat.mul_div_assoc _ (prod_factorial_dvd_factorial_sum _ _)]\n#align nat.multinomial_insert_one Nat.multinomial_insert_one\n\ntheorem multinomial_insert [DecidableEq α] (h : a ∉ s) :\n    multinomial (insert a s) f = (f a + s.Sum f).choose (f a) * multinomial s f :=\n  by\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_apply]\n  rw [div_mul_div_comm ((f a).factorial_mul_factorial_dvd_factorial_add (s.sum f))\n      (prod_factorial_dvd_factorial_sum _ _),\n    mul_comm (f a)! (s.sum f)!, mul_assoc, mul_comm _ (s.sum f)!,\n    Nat.mul_div_mul _ _ (factorial_pos _)]\n#align nat.multinomial_insert Nat.multinomial_insert\n\ntheorem multinomial_congr {f g : α → ℕ} (h : ∀ a ∈ s, f a = g a) :\n    multinomial s f = multinomial s g :=\n  by\n  simp only [multinomial]; congr 1\n  · rw [Finset.sum_congr rfl h]\n  · exact Finset.prod_congr rfl fun a ha => by rw [h a ha]\n#align nat.multinomial_congr Nat.multinomial_congr\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\n\ntheorem binomial_eq [DecidableEq α] (h : a ≠ b) :\n    multinomial {a, b} f = (f a + f b)! / ((f a)! * (f b)!) := by\n  simp [multinomial, Finset.sum_pair h, Finset.prod_pair h]\n#align nat.binomial_eq Nat.binomial_eq\n\ntheorem binomial_eq_choose [DecidableEq α] (h : a ≠ b) :\n    multinomial {a, b} f = (f a + f b).choose (f a) := by\n  simp [binomial_eq _ h, choose_eq_factorial_div_factorial (Nat.le_add_right _ _)]\n#align nat.binomial_eq_choose Nat.binomial_eq_choose\n\ntheorem binomial_spec [DecidableEq α] (hab : a ≠ b) :\n    (f a)! * (f b)! * multinomial {a, b} f = (f a + f b)! := by\n  simpa [Finset.sum_pair hab, Finset.prod_pair hab] using multinomial_spec {a, b} f\n#align nat.binomial_spec Nat.binomial_spec\n\n@[simp]\ntheorem binomial_one [DecidableEq α] (h : a ≠ b) (h₁ : f a = 1) :\n    multinomial {a, b} f = (f b).succ := by\n  simp [multinomial_insert_one {b} f (finset.not_mem_singleton.mpr h) h₁]\n#align nat.binomial_one Nat.binomial_one\n\ntheorem binomial_succ_succ [DecidableEq α] (h : a ≠ 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) + multinomial {a, b} (f.update b (f b).succ) :=\n  by\n  simp only [binomial_eq_choose, Function.update_apply, Function.update_noteq, succ_add, add_succ,\n    choose_succ_succ, h, Ne.def, not_false_iff, Function.update_same]\n  rw [if_neg h.symm]\n  ring\n#align nat.binomial_succ_succ Nat.binomial_succ_succ\n\ntheorem succ_mul_binomial [DecidableEq α] (h : a ≠ b) :\n    (f a + f b).succ * multinomial {a, b} f =\n      (f a).succ * multinomial {a, b} (f.update a (f a).succ) :=\n  by\n  rw [binomial_eq_choose _ h, binomial_eq_choose _ h, mul_comm (f a).succ, Function.update_same,\n    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)\n#align nat.succ_mul_binomial Nat.succ_mul_binomial\n\n/-! ### Simple cases -/\n\n\ntheorem multinomial_univ_two (a b : ℕ) : multinomial Finset.univ ![a, b] = (a + b)! / (a ! * b !) :=\n  by simp [multinomial, Fin.sum_univ_two, Fin.prod_univ_two]\n#align nat.multinomial_univ_two Nat.multinomial_univ_two\n\ntheorem multinomial_univ_three (a b c : ℕ) :\n    multinomial Finset.univ ![a, b, c] = (a + b + c)! / (a ! * b ! * c !) := by\n  simp [multinomial, Fin.sum_univ_three, Fin.prod_univ_three]\n#align nat.multinomial_univ_three Nat.multinomial_univ_three\n\nend Nat\n\n/-! ### Alternative definitions -/\n\n\nnamespace Finsupp\n\nvariable {α : Type _}\n\n/-- Alternative multinomial definition based on a finsupp, using the support\n  for the big operations\n-/\ndef multinomial (f : α →₀ ℕ) : ℕ :=\n  (f.Sum fun _ => id)! / f.Prod fun _ n => n !\n#align finsupp.multinomial Finsupp.multinomial\n\ntheorem multinomial_eq (f : α →₀ ℕ) : f.multinomial = Nat.multinomial f.support f :=\n  rfl\n#align finsupp.multinomial_eq Finsupp.multinomial_eq\n\ntheorem multinomial_update (a : α) (f : α →₀ ℕ) :\n    f.multinomial = (f.Sum fun _ => id).choose (f a) * (f.update a 0).multinomial :=\n  by\n  simp only [multinomial_eq]\n  classical\n    by_cases a ∈ f.support\n    · rw [← Finset.insert_erase h, Nat.multinomial_insert _ f (Finset.not_mem_erase a _),\n        Finset.add_sum_erase _ f h, support_update_zero]\n      congr 1\n      exact\n        Nat.multinomial_congr _ fun _ h => (Function.update_noteq (Finset.mem_erase.1 h).1 0 f).symm\n    rw [not_mem_support_iff] at h\n    rw [h, Nat.choose_zero_right, one_mul, ← h, update_self]\n#align finsupp.multinomial_update Finsupp.multinomial_update\n\nend Finsupp\n\nnamespace Multiset\n\nvariable {α : Type _}\n\n/-- Alternative definition of multinomial based on `multiset` delegating to the\n  finsupp definition\n-/\nnoncomputable def multinomial (m : Multiset α) : ℕ :=\n  m.toFinsupp.multinomial\n#align multiset.multinomial Multiset.multinomial\n\ntheorem multinomial_filter_ne [DecidableEq α] (a : α) (m : Multiset α) :\n    m.multinomial = m.card.choose (m.count a) * (m.filterₓ ((· ≠ ·) a)).multinomial :=\n  by\n  dsimp only [multinomial]\n  convert Finsupp.multinomial_update a _\n  · rw [← Finsupp.card_toMultiset, m.to_finsupp_to_multiset]\n  · ext1 a'\n    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]\n#align multiset.multinomial_filter_ne Multiset.multinomial_filter_ne\n\nend Multiset\n\nnamespace Finset\n\n/-! ### Multinomial theorem -/\n\n\nvariable {α : Type _} [DecidableEq α] (s : Finset α) {R : Type _}\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 : α → R)\n    (hc : (s : Set α).Pairwise fun i j => Commute (x i) (x j)) :\n    ∀ n,\n      s.Sum x ^ n =\n        ∑ k : s.Sym n,\n          k.1.1.multinomial *\n            (k.1.1.map <| x).noncommProd\n              (Multiset.map_set_pairwise <| hc.mono <| mem_sym_iff.1 k.2) :=\n  by\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\n      · exact ⟨0, Or.inl rfl⟩\n      convert(one_mul _).symm\n      apply Nat.cast_one\n    · rw [pow_succ, MulZeroClass.zero_mul]\n      apply (Fintype.sum_empty _).symm\n      rw [sym_empty]\n      infer_instance\n  intro n; specialize ih (hc.mono <| s.subset_insert a)\n  rw [sum_insert ha, (Commute.sum_right s _ _ fun 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) _ _ fun m => _).symm\n  rw [m.1.1.multinomial_filter_ne a]\n  conv in m.1.1.map _ => rw [← m.1.1.filter_add_not ((· = ·) a), Multiset.map_add]\n  simp_rw [Multiset.noncommProd_add, m.1.1.filter_eq, Multiset.map_replicate, m.1.2]\n  rw [Multiset.noncommProd_eq_pow_card _ _ _ fun _ => Multiset.eq_of_mem_replicate]\n  rw [Multiset.card_replicate, Nat.cast_mul, mul_assoc, Nat.cast_comm]\n  congr 1; simp_rw [← mul_assoc, Nat.cast_comm]; rfl\n#align finset.sum_pow_of_commute Finset.sum_pow_of_commute\n\ntheorem sum_pow [CommSemiring R] (x : α → R) (n : ℕ) :\n    s.Sum x ^ n = ∑ k in s.Sym n, k.val.multinomial * (k.val.map x).Prod :=\n  by\n  conv_rhs => rw [← sum_coe_sort]\n  convert sum_pow_of_commute s x (fun _ _ _ _ _ => mul_comm _ _) n\n  ext1; rw [Multiset.noncommProd_eq_prod]; rfl\n#align finset.sum_pow Finset.sum_pow\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/Data/Nat/Choose/Multinomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7804826885239519}}
{"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.nat.parity\nimport data.zmod.basic\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\nlemma eq_zero_iff_even {n : ℕ} : (n : zmod 2) = 0 ↔ even n :=\n(char_p.cast_eq_zero_iff (zmod 2) 2 n).trans even_iff_two_dvd.symm\n\nlemma eq_one_iff_odd {n : ℕ} : (n : zmod 2) = 1 ↔ odd n :=\nby { rw [← @nat.cast_one (zmod 2), zmod.eq_iff_modeq_nat, nat.odd_iff, nat.modeq], norm_num }\n\n\n\nend zmod\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/zmod/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7804826833775821}}
{"text": "import data.real.basic\n\nvariables a b c : ℝ\n\n#check mul_comm b a\n#check mul_assoc c b a\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  /- mul_comm a b refers to the communicative law for multiplication \n  on a and b: a * b = b * a. 'rw mul_comm a b' tells Lean to replace\n  a * b with b * a in the goal. -/\n  \n  rw mul_assoc b a c,\n  /- mul_assoc b a c refers to the associative law for multiplication \n  on b, a, and c: b * a * c = b * (a * c). Note that Lean leaves out \n  parentheses when possible. Since multiplication associates to the left,\n  the left-hand side of mul_assoc b * a * c refers to (b * a) * c. \n  'rw mul_assoc b a c' solves the goal b * a * c = b * (a * c), and hence, \n  completes the proof. -/\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/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966702001758, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7804329162562792}}
{"text": "/-\n    Stalk (of types).\n\n    https://stacks.math.columbia.edu/tag/0078\n-/\n\nimport to_mathlib.opens\nimport topology.basic\nimport sheaves.presheaf\n\nuniverse u \n\nsection stalk\n\nvariables {α : Type u} [topological_space α] \nvariables (F : presheaf α) (x : α)\n\nopen topological_space\n\n-- An element in the stalk is a pair (U, s) under an equivalence relation \n\nstructure stalk.elem :=\n(U   : opens α) \n(HxU : x ∈ U) \n(s   : F U)\n\n-- Equivalence relation on the set of pairs. (U,s) ~ (V,t) iff there exists W \n-- open s.t. x ∈ W ⊆ U ∩ V, and s|W = t|W.\n\ndef stalk.relation : stalk.elem F x → stalk.elem F x → Prop :=\nλ Us Vt,\n    ∃ (W : opens α) (HxW : x ∈ W) (HWU : W ⊆ Us.U) (HWV : W ⊆ Vt.U),\n    F.res Us.U W HWU Us.s = F.res Vt.U W HWV Vt.s\n    \nlemma stalk.relation.reflexive : reflexive (stalk.relation F x) :=\nλ ⟨U, HxU, s⟩, ⟨U, HxU, set.subset.refl _, set.subset.refl _, rfl⟩\n\nlemma stalk.relation.symmetric : symmetric (stalk.relation F x) :=\nλ Us Vt ⟨W, HxW, HWU, HWV, Hres⟩, ⟨W, HxW, HWV, HWU, Hres.symm⟩\n\nlemma stalk.relation.transitive : transitive (stalk.relation F x) :=\nλ ⟨U, HxU, sU⟩ ⟨V, HxV, sV⟩ ⟨W, HxW, sW⟩,\nλ ⟨R, HxR, HRU, HRV, HresR⟩ ⟨S, HxS, HSV, HSW, HresS⟩,\n⟨R ∩ S, ⟨HxR, HxS⟩,\nλ y ⟨HyR, _⟩, HRU HyR, λ y ⟨_, HyS⟩, HSW HyS,\nhave HURRS : _ := F.Hcomp U R (R ∩ S) (set.inter_subset_left _ _) HRU,\nhave HVRRS : _ := F.Hcomp V R (R ∩ S) (set.inter_subset_left _ _) HRV,\nhave HVSRS : _ := F.Hcomp V S (R ∩ S) (set.inter_subset_right _ _) HSV,\nhave HWSRS : _ := F.Hcomp W S (R ∩ S) (set.inter_subset_right _ _) HSW,\ncalc  F.res U (R ∩ S) _ sU \n    = F.res R (R ∩ S) _ (F.res U R _ sU) : congr_fun HURRS sU \n... = F.res R (R ∩ S) _ (F.res V R _ sV) : congr_arg _ HresR\n... = F.res V (R ∩ S) _ sV               : congr_fun HVRRS.symm sV\n... = F.res S (R ∩ S) _ (F.res V S _ sV) : congr_fun HVSRS sV\n... = F.res S (R ∩ S) _ (F.res W S _ sW) : congr_arg _ HresS\n... = F.res W (R ∩ S) _ sW               : congr_fun HWSRS.symm sW⟩\n\nlemma stalk.relation.equivalence : equivalence (stalk.relation F x) :=\n⟨stalk.relation.reflexive F x, \nstalk.relation.symmetric F x,\nstalk.relation.transitive F x⟩\n\ninstance stalk.setoid : setoid (stalk.elem F x) :=\n{ r := stalk.relation F x,\n  iseqv := stalk.relation.equivalence F x }\n\n-- We define a stalk as the set of stalk elements under the defined relation.\n\ndefinition stalk := quotient (stalk.setoid F x)\n\nend stalk\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/stalk.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.780432910574885}}
{"text": "/-  MATH40001 : Introduction to university mathematics.\n\nPeano Axioms - Extra Practice, October 2020.\n\nThese questions are based on Dr Lawn's Practice Questions\non Blackboard.\n\nThis is a Lean file. It can be read with the Lean theorem prover.\n\nYou can work on this file online at the following URL:\n\n\nor you can install Lean and its maths library following the instructions at\nhttps://leanprover-community.github.io/get_started.html\n\nThere are advantages to installing Lean on your own computer\n(for example it's faster), but it's more hassle than just using it online.\n\n\nReplace the sorries for the theorems you think are provable\nwith tactics which prove them.\n\nHere, we use the function `succ` instead of `ν`.\n-/\n\nimport data.nat.basic\n\nopen nat function\n\n#check (succ : ℕ → ℕ)\n#reduce succ 0\n#reduce succ 36\n\n\ntheorem exists_succ_true : ∃ (ν : ℕ → ℕ), ν = succ :=\nbegin\n  sorry\nend\n\ntheorem exists_succ_false : ¬ ∃ (ν : ℕ → ℕ), ν = succ :=\nbegin\n  sorry\nend\n\n\ntheorem succ_injective_true : injective succ :=\nbegin\n  unfold injective,\n  sorry\nend\n\ntheorem succ_injective_false : ¬ injective succ :=\nbegin\n  unfold injective,\n  sorry\nend\n\n\ntheorem succ_surjective_true : surjective succ :=\nbegin\n  unfold surjective,\n  sorry\nend\n\ntheorem succ_surjective_false : ¬ surjective succ :=\nbegin\n  unfold surjective,\n  sorry\nend\n\n\ntheorem all_functions_are_succ_true : ∀ (ν : ℕ → ℕ), ν = succ :=\nbegin\n  sorry\nend\n\ntheorem all_functions_are_succ_false : ¬ ∀ (ν : ℕ → ℕ), ν = succ :=\nbegin\n  sorry\nend\n\n\ntheorem exists_unique_zero_true : ∃! n : ℕ, n = 0 :=\nbegin\n  sorry\nend\n\ntheorem exists_unique_zero_false : ¬ ∃! n : ℕ, n = 0:=\nbegin\n  sorry\nend\n\n/-\nThe lemma\n`funext_iff` : (f₁ = f₂) ↔ (∀ x, f₁ x = f₂ x)\nmight come in handy somewhere above.\n\nNext, try writing down the Peano Axioms as given in the lectures/notes:\n\ntype `\\forall`, `\\exists`, `\\nu`, `\\in`, `\\sub` and `\\to`\nand then SPACE or TAB for their respective symbols ∀ ∃ ν ∈ ⊆ →\n-/\n\ndef N : set ℕ := {n | true} -- Let `N` be the set of all natural numbers\n\ndef Peano_Axiom_1 : Prop := 0 ∈ N -- as an example\ndef Peano_Axiom_2 : Prop := sorry\ndef Peano_Axiom_3 : Prop := sorry\ndef Peano_Axiom_4 : Prop := sorry\ndef Peano_Axiom_5 : Prop := sorry\n\n\n\n-- Lean Fun Facts!\n\nset_option pp.numerals false  -- changes lean's pretty printer options\n\n#reduce succ 5\n#reduce 37\n\n#check 6\n#check 37\n\n-- Compare Lean's recursor with (P5)\n#check (@nat.rec : ∀ {C : ℕ → Sort*}, C 0 → (∀ n, C n → C (succ n)) → ∀ n, C 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/peano/peano_practice_questions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7803634867731019}}
{"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 algebraic_geometry.prime_spectrum.basic\nimport ring_theory.polynomial.basic\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\nopen ideal polynomial prime_spectrum set\nopen_locale polynomial\n\nnamespace algebraic_geometry\n\nnamespace polynomial\n\nvariables {R : Type*} [comm_ring R] {f : R[X]}\n\n/-- Given a polynomial `f ∈ 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})ᶜ` under the morphism\n`comap C : Spec R[x] → Spec R`. -/\ndef image_of_Df (f) : set (prime_spectrum R) :=\n  {p : prime_spectrum R | ∃ i : ℕ , (coeff f i) ∉ p.as_ideal}\n\nlemma is_open_image_of_Df : is_open (image_of_Df f) :=\nbegin\n  rw [image_of_Df, set_of_exists (λ i (x : prime_spectrum R), coeff f i ∉ x.val)],\n  exact is_open_Union (λ i, is_open_basic_open),\nend\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`. -/\nlemma comap_C_mem_image_of_Df {I : prime_spectrum R[X]}\n  (H : I ∈ (zero_locus {f} : set (prime_spectrum R[X]))ᶜ ) :\n  prime_spectrum.comap (polynomial.C : R →+* R[X]) I ∈ image_of_Df f :=\nexists_coeff_not_mem_C_inverse (mem_compl_zero_locus_iff_not_mem.mp H)\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C⁺ : Spec R[x] → Spec R`. -/\nlemma image_of_Df_eq_comap_C_compl_zero_locus :\n  image_of_Df f = prime_spectrum.comap (C : R →+* R[X]) '' (zero_locus {f})ᶜ :=\nbegin\n  refine ext (λ x, ⟨λ hx, ⟨⟨map C x.val, (is_prime_map_C_of_is_prime x.property)⟩, ⟨_, _⟩⟩, _⟩),\n  { rw [mem_compl_eq, mem_zero_locus, singleton_subset_iff],\n    cases hx with i hi,\n    exact λ a, hi (mem_map_C_iff.mp a i) },\n  { refine subtype.ext (ext (λ x, ⟨λ h, _, λ h, subset_span (mem_image_of_mem C.1 h)⟩)),\n    rw ← @coeff_C_zero R x _,\n    exact mem_map_C_iff.mp h 0 },\n  { rintro ⟨xli, complement, rfl⟩,\n    exact comap_C_mem_image_of_Df complement }\nend\n\n/--  The morphism `C⁺ : Spec R[x] → Spec R` is open.\nStacks Project \"Lemma 00FB\", first part.\n\nhttps://stacks.math.columbia.edu/tag/00FB\n-/\ntheorem is_open_map_comap_C :\n  is_open_map (prime_spectrum.comap (C : R →+* R[X])) :=\nbegin\n  rintros U ⟨s, z⟩,\n  rw [← compl_compl U, ← z, ← Union_of_singleton_coe s, zero_locus_Union, compl_Inter, image_Union],\n  simp_rw [← image_of_Df_eq_comap_C_compl_zero_locus],\n  exact is_open_Union (λ f, is_open_image_of_Df),\nend\n\nend polynomial\n\nend algebraic_geometry\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/algebraic_geometry/prime_spectrum/is_open_comap_C.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.780229333769789}}
{"text": "import data.real.basic\nimport topology.metric_space.basic\nimport analysis.specific_limits\nimport topology.sequences\nimport order.filter.at_top_bot\nimport tactic\n\nvariable {f : ℝ → ℝ}\nvariable {x₀ : ℝ}\nvariable {u : ℕ → ℝ}\nvariable {φ : ℕ → ℕ}\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la notación |x| para el valor\n-- absoluto de x.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la función\n--    limite : (ℕ → ℝ) → ℝ → Prop\n-- tal que (limite u c) expresa que c es el límite de\n-- la sucesión u.\n-- ----------------------------------------------------\n\ndef limite : (ℕ → ℝ) → ℝ → Prop :=\nλ u c, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - c| ≤ ε\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (∀ ε > 0, y ≤ x + ε) →  y ≤ x\n-- ----------------------------------------------------------------------\n\nlemma le_of_le_add_all\n  {x y : ℝ}\n  : (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si x es el límite de u y\n--    ∃ N, ∀ n ≥ N, y ≤ u n\n-- entonce y ≤ x.\n-- ----------------------------------------------------------------------\n\nlemma le_lim\n  {x y : ℝ}\n  {u : ℕ → ℝ}\n  (hu : limite u x)\n  (h : ∃ N, ∀ n ≥ N, y ≤ u n)\n  : y ≤ x :=\nbegin\n  apply le_of_le_add_all,\n  intros ε hε,\n  cases hu ε hε with N hN,\n  cases h with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left N N'),\n  specialize hN' N₀ (le_max_right N N'),\n  rw abs_le at hN,\n  linarith,\nend\n\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la función\n--    cota_superior : set ℝ → ℝ → Prop\n-- tal que (cota_superior A x) expresa que x es una\n-- cota superior de A.\n-- ----------------------------------------------------\n\ndef cota_superior : set ℝ → ℝ → Prop :=\nλ A x, ∀ a ∈ A, a ≤ x\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la función\n--    es_supremo : set ℝ → ℝ → Prop\n-- tal que (es_supremos A x) expresa que x es el\n-- supremo de A.\n-- ----------------------------------------------------\n\ndef es_supremo : set ℝ → ℝ → Prop :=\nλ A x, cota_superior A x ∧ ∀ y, cota_superior A y → x ≤ y\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si x es el supremo de A,\n-- entonces\n--    ∀ y, y < x → ∃ a ∈ A, y < a\n-- ----------------------------------------------------------------------\n\nlemma lt_sup\n  {A : set ℝ}\n  {x : ℝ} (\n  hx : es_supremo A x)\n  : ∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    limite (λ n, x) x\n-- ----------------------------------------------------------------------\n\nlemma limit_const\n  (x : ℝ)\n  : limite (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si x es el límite de u e y es una cota\n-- superior de u, entonces x ≤ y.\n-- ----------------------------------------------------------------------\n\nlemma lim_le\n  {x y : ℝ}\n  {u : ℕ → ℝ}\n  (hu : limite u x)\n  (ineg : ∀ n, u n ≤ y)\n  : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que si dos sucesiones tienen\n-- el mismo límite, entonces las sucesiones que están\n-- comprendidas entre éstas también tienen el mismo\n-- límite.\n-- ----------------------------------------------------\n\n-- Nota. En la demostración se usará el siguiente lema:\nlemma max_ge_iff\n  {p q r : ℕ}\n  : r ≥ max p q ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\nlemma emparedado\n  {u v w : ℕ → ℝ}\n  {a : ℝ}\n  (hu : limite u a)\n  (hw : limite w a)\n  (h : ∀ n, u n ≤ v n)\n  (h' : ∀ n, v n ≤ w n)\n  : limite v a :=\nbegin\n  intros ε hε,\n  cases hu ε hε with N hN, clear hu,\n  cases hw ε hε with N' hN', clear hw hε,\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-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε\n-- ----------------------------------------------------------------------\n\nlemma inv_succ_le_all :\n  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    { intros h ε ε_pos,\n      cases h (ε/2) (by linarith) with N hN,\n      use N,\n      intros n hn,\n      rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n      specialize hN n hn,\n      linarith, },\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    ∀ n, |u n - x| ≤ 1/(n+1) ⊢ limite u x\n-- ----------------------------------------------------------------------\n\nlemma limit_of_sub_le_inv_succ\n  {u : ℕ → ℝ}\n  {x : ℝ}\n  (h : ∀ n, |u n - x| ≤ 1/(n+1))\n  : limite u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que x es el límite de\n--   x - 1/(n+1)\n-- ----------------------------------------------------------------------\n\nlemma limit_const_sub_inv_succ\n  (x : ℝ)\n  : limite (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que son equivalentes\n-- + es_supremo A x\n-- + cota_superior A x ∧ ∃ u : ℕ → ℝ, limite u x ∧ ∀ n, u n ∈ A\n-- ----------------------------------------------------------------------\n\nlemma es_supremo_iff\n  (A : set ℝ)\n  (x : ℝ)\n  : (es_supremo A x) ↔\n    (cota_superior A x ∧ ∃ u : ℕ → ℝ, limite u x ∧ ∀ n, u n ∈ A ) :=\nbegin\n  split,\n  { intro h,\n    split,\n    { exact h.left, },\n    { have : ∀ n : ℕ, ∃ a ∈ A, x - 1/(n+1) < a,\n      { intros n,\n        have : 1/(n+1 : ℝ) > 0,\n          exact nat.one_div_pos_of_nat,\n        exact lt_sup h _ (by linarith), },\n      choose u hu using this,\n      use u,\n      split,\n      { apply emparedado (limit_const_sub_inv_succ x) (limit_const x),\n        { intros n,\n          exact le_of_lt (hu n).2, },\n        { intro n,\n          exact h.1 _ (hu n).left, } },\n      { intro n,\n        exact (hu n).left }}},\n  { rintro ⟨maj, u, limu, u_in⟩,\n    split,\n    { exact maj },\n    { intros y ymaj,\n      apply lim_le limu,\n      intro n,\n      apply ymaj,\n      apply u_in }},\nend\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la función\n--    continua_en_punto : (ℝ → ℝ) → ℝ → Prop\n-- tal que (continua_en_punto f x₀) expresa que f es\n-- continua en x₀.\n-- ----------------------------------------------------\n\ndef continua_en_punto : (ℝ → ℝ) → ℝ → Prop :=\nλ f x₀, ∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - f x₀| ≤ ε\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si el límite de f es x₀ y f es continua en\n-- x₀, entonces el límite de (f ∘ u) es f(x₀).\n-- ----------------------------------------------------------------------\n\nlemma seq_continuous_of_continuous\n  (hf : continua_en_punto f x₀)\n  (hu : limite u x₀)\n  : limite (f ∘ u) (f x₀) :=\nbegin\n  intros ε ε_pos,\n  rcases hf ε ε_pos with ⟨δ, δ_pos, hδ⟩,\n  cases hu δ δ_pos with N hN,\n  use N,\n  intros n hn,\n  apply hδ,\n  exact hN n hn,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    ∀ u : ℕ → ℝ, limite u x₀ → limite (f ∘ u) (f x₀)\n-- entonces f es continua en x₀.\n-- ----------------------------------------------------------------------\n\nexample :\n  (∀ u : ℕ → ℝ, limite u x₀ → limite (f ∘ u) (f x₀)) →\n  continua_en_punto f x₀ :=\nbegin\n  contrapose!,\n  intro hf,\n  unfold continua_en_punto at hf,\n  push_neg at hf,\n  cases hf with ε h,\n  cases h with ε_pos hf,\n  have H : ∀ n : ℕ, ∃ x, |x - x₀| ≤ 1/(n+1) ∧ ε < |f x - f x₀|,\n    intro n,\n    apply hf,\n    exact nat.one_div_pos_of_nat,\n  clear hf,\n  choose u hu using H,\n  use u,\n  split,\n    intros η η_pos,\n    have fait : ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → 1 / (↑n + 1) ≤ η,\n      exact inv_succ_le_all η η_pos,\n    cases fait with N hN,\n    use N,\n    intros n hn,\n    calc |u n - x₀| ≤ 1/(n+1) : (hu n).left\n                ... ≤ η       : hN n hn,\n  unfold limite,\n  push_neg,\n  use [ε, ε_pos],\n  intro N,\n  use N,\n  split,\n  linarith,\n  exact (hu N).right,\nend\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la función\n-- ----------------------------------------------------\n\ndef tiende_a_infinito : (ℕ → ℝ) → Prop :=\nλ u, ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\n-- ----------------------------------------------------\n-- Ejercicio. Para extraer una sucesión se aplica una\n-- función de extracción que conserva el orden; por\n-- ejemplo, la subsucesión\n--    uₒ, u₂, u₄, u₆, ...\n-- se ha obtenido con la función de extracción φ tal\n-- que φ(n) = 2*n.\n--\n-- Definir la función\n--    extraccion : (ℕ → ℕ) → Prop\n-- tal que (extraccion φ) expresa que φ es una función\n-- de extracción\n-- ----------------------------------------------------\n\ndef extraccion : (ℕ → ℕ) → Prop\n| φ := ∀ n m, n < m → φ n < φ m\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que si φ es una función de\n-- extracción, entonces\n--    ∀ n, n ≤ φ n\n-- ----------------------------------------------------\n\nlemma id_mne_extraccion :\n  extraccion φ → ∀ n, n ≤ φ n :=\nbegin\n  intros h n,\n  induction n with m HI,\n  { linarith },\n  { apply nat.succ_le_of_lt,\n    linarith [h m (m+1) (by linarith)] },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si u tiende a infinito y φ es una función de\n-- extracción, entonces (u ∘ φ) tiende a infinito.\n-- ----------------------------------------------------------------------\n\nlemma subseq_tenstoinfinity\n  (h : tiende_a_infinito u)\n  (hφ : extraccion φ)\n  : tiende_a_infinito (u ∘ φ) :=\nbegin\n  intros A,\n  cases h A with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn\n     ... ≤ φ n : id_mne_extraccion hφ n,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si u tiende al infinito y\n--    ∀ n, u n ≤ v n\n-- entonces v tiende al infinito.\n-- ----------------------------------------------------------------------\n\nlemma squeeze_infinity\n  {u v : ℕ → ℝ}\n  (hu : tiende_a_infinito u)\n  (huv : ∀ n, u n ≤ v n)\n  : tiende_a_infinito v :=\nbegin\n  intros A,\n  cases hu A with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  specialize huv n,\n  linarith,\nend\n\nopen set\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la sucesión identidad tiende a infinito.\n-- ----------------------------------------------------------------------\n\nlemma limite_id : tiende_a_infinito (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N,\n    exact_mod_cast hn,\n  linarith,\nend\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir la función\n--    punto_acumulacion : (ℕ → ℝ) → ℝ → Prop\n-- tal que (punto_acumulacion u a) expresa que a es un\n-- punto de acumulación de u; es decir, que es el\n-- límite de alguna subsucesión de u.\n-- ----------------------------------------------------\n\ndef punto_acumulacion : (ℕ → ℝ) → ℝ → Prop\n| u a := ∃ φ, extraccion φ ∧ limite (u ∘ φ) a\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si es una sucesión en [a,b], entonces\n-- existe algún c en [a,b] que es el punto de acumulación de u.\n-- ----------------------------------------------------------------------\n\nlemma bolzano_weierstrass\n  {a b : ℝ}\n  {u : ℕ → ℝ}\n  (h : ∀ n, u n ∈ Icc a b)\n  : ∃ c ∈ Icc a b, punto_acumulacion u c :=\nbegin\n  rcases (compact_Icc : is_compact (Icc a b)).tendsto_subseq h with ⟨c, c_in, φ, hφ, lim⟩,\n  use [c, c_in, φ, hφ],\n  simp_rw [metric.tendsto_nhds, filter.eventually_at_top, real.dist_eq] at lim,\n  intros ε ε_pos,\n  rcases lim ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  exact le_of_lt (hN n hn)\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    tiende_a_infinito u → ∀ x, ¬ limite u x\n-- ----------------------------------------------------------------------\n\nlemma not_seq_limit_of_tendstoinfinity\n  {u : ℕ → ℝ} :\n  tiende_a_infinito u → ∀ x, ¬ limite u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es continua en [a,b], entonces existe\n-- un M tal que, para todo x ∈ [a,b], f(x) ≤ M.\n-- ----------------------------------------------------------------------\n\nlemma bdd_above_segment\n  {f : ℝ → ℝ}\n  {a b : ℝ}\n  (hf : ∀ x ∈ Icc a b, continua_en_punto f x)\n  : ∃ M, ∀ x ∈ Icc a b, f x ≤ M :=\nbegin\n  by_contradiction H,\n  push_neg at H,\n  have clef : ∀ n : ℕ, ∃ x, x ∈ Icc a b ∧ f x > n,\n    intro n,\n    apply H,\n    clear H,\n  choose u hu using clef,\n  have lim_infinie : tiende_a_infinito (f ∘ u),\n    apply squeeze_infinity (limite_id),\n    intros n,\n    specialize hu n,\n    linarith,\n  have bornes : ∀ n, u n ∈ Icc a b,\n    intro n,\n    exact (hu n).left,\n  rcases bolzano_weierstrass bornes with ⟨c, c_dans, φ, φ_extr, lim⟩,\n  have lim_infinie_extr : tiende_a_infinito (f ∘ (u ∘ φ)),\n    exact subseq_tenstoinfinity lim_infinie φ_extr,\n  have lim_extr : limite (f ∘ (u ∘ φ)) (f c),\n    exact seq_continuous_of_continuous (hf c c_dans) lim,\n  exact not_seq_limit_of_tendstoinfinity lim_infinie_extr (f c) lim_extr,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es continua en x₀, también lo es -f.\n-- ----------------------------------------------------------------------\n\nlemma continuous_opposite\n  {f : ℝ → ℝ}\n  {x₀ : ℝ}\n  (h : continua_en_punto f x₀)\n  : continua_en_punto (λ x, -f x) x₀ :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with δ h,\n  cases h with δ_pos h,\n  use [δ, δ_pos],\n  intros y hy,\n  have :  -f y - -f x₀ = -(f y - f x₀), ring,\n  rw [this, abs_neg],\n  exact h y hy,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es continua en [a,b], entonces existe\n-- un m en [a,b] tal que, para todo x de [a,b], m ≤ f(x).\n-- ----------------------------------------------------------------------\n\nlemma bdd_below_segment\n  {f : ℝ → ℝ}\n  {a b : ℝ}\n  (hf : ∀ x ∈ Icc a b, continua_en_punto f x)\n  : ∃ m, ∀ x ∈ Icc a b, m ≤ f x :=\nbegin\n  have : ∃ M, ∀ x ∈ Icc a b, -f x ≤ M,\n  { apply bdd_above_segment,\n    intros x x_dans,\n    exact continuous_opposite (hf x x_dans), },\n  cases this with M hM,\n  use -M,\n  intros x x_dans,\n  specialize hM x x_dans,\n  linarith,\nend\n\nopen real\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si A es un subconjunto no vacío de [a,b],\n-- entonces existe un x en [a,b] que es el supremo de A.\n-- ----------------------------------------------------------------------\n\nlemma sup_segment\n  {a b : ℝ}\n  {A : set ℝ}\n  (hnonvide : ∃ x, x ∈ A)\n  (h : A ⊆ Icc a b)\n  : ∃ x ∈ Icc a b, es_supremo A x :=\nbegin\n  have b_maj : ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : cota_superior A (Sup A),\n  { intro x,\n    apply real.le_Sup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply Sup_le_ub A hnonvide b_maj } },\n  { use Sup_maj,\n    intros y y_in,\n    rwa real.Sup_le _ hnonvide ⟨b, b_maj⟩ },\nend\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que cada sucesión tiene como\n-- máximo un límite.\n-- ----------------------------------------------------\n\nlemma unicidad_limite\n  {a b : ℝ}\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  by_contradiction H,\n  change a ≠ b at H,\n  have h1 : |a - b| > 0,\n    exact abs_pos.mpr (sub_ne_zero_of_ne H),\n  cases ha (|a - b|/4) (by linarith) with N hN,\n  cases hb (|a - b|/4) (by linarith) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  have h2 : |a - b| < |a - b |,\n    calc  |a - b| = |(a - u N₀) + (u N₀ - b)| : by ring\n    ... ≤ |a - u N₀| + |u N₀ - b|             : by apply abs_add\n    ... = |u N₀ - a| + |u N₀ - b|             : by rw abs_sub\n    ... < |a - b|                             : by linarith,\n  linarith,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si l es el límite de u y φ es una extracción,\n-- entonces l es el límite de (u ∘ φ).\n-- ----------------------------------------------------------------------\n\nlemma subseq_tendsto_of_tendsto\n  {l : ℝ}\n  (h : limite u l)\n  (hφ : extraccion φ)\n  : limite (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn\n     ... ≤ φ n : id_mne_extraccion hφ n,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es continua en [a,b], existe un x₀ ∈ [a,b],\n-- tal que, para todo x ∈ [a,b], f(x) ≤ f(x₀).\n-- ----------------------------------------------------------------------\n\nexample\n  {a b : ℝ}\n  (hab : a ≤ b)\n  (hf : ∀ x ∈ Icc a b, continua_en_punto f x)\n  : ∃ x₀ ∈ Icc a b, ∀ x ∈ Icc a b, f x ≤ f x₀ :=\nbegin\n  cases bdd_below_segment hf with m hm,\n  cases bdd_above_segment hf with M hM,\n  let A := {y | ∃ x ∈ Icc a b, y = f x},\n  obtain ⟨y₀, y_dans, y_sup⟩ : ∃ y₀ ∈ Icc m M, es_supremo A y₀,\n  { apply sup_segment,\n    { use [f a, a, by linarith, hab, by ring], },\n    { rintros y ⟨x, x_in, rfl⟩,\n      exact ⟨hm x x_in, hM x x_in⟩ } },\n  rw es_supremo_iff at y_sup,\n  rcases y_sup with ⟨y_maj, u, lim_u, u_dans⟩,\n  choose v hv using u_dans,\n  cases forall_and_distrib.mp hv with v_dans hufv,\n  replace hufv : u = f ∘ v := funext hufv,\n  rcases bolzano_weierstrass v_dans with ⟨x₀, x₀_in, φ, φ_extr, lim_vφ⟩,\n  use [x₀, x₀_in],\n  intros x x_dans,\n  have lim : limite (f ∘ v ∘ φ) (f x₀),\n  { apply seq_continuous_of_continuous,\n    exact hf x₀ x₀_in,\n    exact lim_vφ },\n  have unique : f x₀ = y₀,\n  { apply unicidad_limite lim,\n    rw hufv at lim_u,\n    exact subseq_tendsto_of_tendsto lim_u φ_extr },\n  rw unique,\n  apply y_maj,\n  use [x, x_dans],\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si x ∈ [a,b] y x ≠ b, entonces x < b.\n-- ----------------------------------------------------------------------\n\nlemma stupid\n  {a b x : ℝ}\n  (h : x ∈ Icc a b)\n  (h' : x ≠ b)\n  : x < b :=\nlt_of_le_of_ne h.right h'\n\n-- ----------------------------------------------------\n-- Ejercicio. Definir I como el intervalo [0,1].\n-- ----------------------------------------------------\n\ndef I := (Icc 0 1 : set ℝ)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que x es el límite de\n--    x + 1/(n+1)\n-- ----------------------------------------------------------------------\n\nlemma limit_const_add_inv_succ\n  (x : ℝ)\n  : limite (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ;\nlinarith [@nat.one_div_pos_of_nat ℝ _ n])\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es continua, f(0) < 0 y f(1) > 0,\n-- entonces existe un x₀ ∈ I tal que f(x₀) = 0.\n-- ----------------------------------------------------------------------\n\nexample\n  (f : ℝ → ℝ)\n  (hf : ∀ x, continua_en_punto f x)\n  (h₀ : f 0 < 0)\n  (h₁ : f 1 > 0)\n  : ∃ x₀ ∈ I, f x₀ = 0 :=\nbegin\n  let A := { x | x ∈ I ∧ f x < 0},\n  have ex_x₀ : ∃ x₀ ∈ I, es_supremo A x₀,\n  { apply sup_segment,\n      use 0,\n      split,\n        split, linarith, linarith,\n      exact h₀,\n    intros x hx,\n    exact hx.left },\n  rcases ex_x₀ with ⟨x₀, x₀_in, x₀_sup⟩,\n  use [x₀, x₀_in],\n  have : f x₀ ≤ 0,\n  { rw es_supremo_iff at x₀_sup,\n    rcases x₀_sup with ⟨maj_x₀, u, lim_u, u_dans⟩,\n    have : limite (f ∘ u) (f x₀),\n      exact seq_continuous_of_continuous (hf x₀) lim_u,\n    apply lim_le this,\n    intros n,\n    have : f (u n) < 0,\n      exact (u_dans n).right,\n    linarith  },\n  have x₀_1: x₀ < 1,\n  { apply stupid x₀_in,\n    intro h,\n    rw ← h at h₁,\n    linarith  },\n  have : f x₀ ≥ 0,\n  { have in_I : ∃ N : ℕ, ∀ n ≥ N, x₀ + 1/(n+1) ∈ I,\n    { have : ∃ N : ℕ, ∀ n≥ N, 1/(n+1 : ℝ) ≤ 1-x₀,\n      { apply inv_succ_le_all,\n        linarith, },\n      cases this with N hN,\n      use N,\n      intros n hn,\n      specialize hN n hn,\n      have : 1/(n+1 : ℝ) > 0,\n        exact nat.one_div_pos_of_nat,\n      change 0 ≤ x₀ ∧ x₀ ≤ 1 at x₀_in,\n      split ; linarith, },\n    have not_in : ∀ n : ℕ, x₀ + 1/(n+1) ∉ A,\n    -- By definition, x ∉ A means ¬ (x ∈ A).\n    { intros n hn,\n      cases x₀_sup with x₀_maj _,\n      specialize x₀_maj _ hn,\n      have : 1/(n+1 : ℝ) > 0,\n        from nat.one_div_pos_of_nat,\n      linarith, },\n    dsimp [A] at not_in, -- This is useful to unfold a let\n    push_neg at not_in,\n    have lim : limite (λ n, f(x₀ + 1/(n+1))) (f x₀),\n    { apply seq_continuous_of_continuous (hf x₀),\n      apply limit_const_add_inv_succ },\n    apply le_lim lim,\n    cases in_I with N hN,\n    use N,\n    intros n hn,\n    exact not_in n (hN n hn), },\n  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/7_Ampliacion_de_limites/Ampliacion_de_limites.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701655, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7802293181545101}}
{"text": "import group_theory.subgroup.basic\n\n-- for any type `G` we can define its diagonal type `ΔG={(g,g)|g∈G}`\ndef Δ (G : Type*) : set (G × G) := { g : G × G | g.fst = g.snd }\n\n-- 14.1\ndef subgroup_Δ (G : Type*) [group G] : subgroup (G × G) := \n{ carrier := Δ G,\n  one_mem' := by { refine rfl, },\n  mul_mem' := by { intros a b ga gb,rw Δ at *,finish, },\n  inv_mem' := by { intros x hx,rw Δ at *,finish, } }\n\n-- 14.2\ntheorem normal_Δ_iff_comm (G : Type*) [group G] : (subgroup_Δ G).normal ↔ ∀ g h : G, g * h = h * g :=\nbegin\n  split,\n  { intros H g h,\n    cases H,\n    simp [subgroup_Δ,Δ,*] at *,\n    specialize H g g (by refl) g h,\n    norm_num at H,\n    rw H,\n    norm_num,\n    exact H,\n  },\n  {\n    intros h,\n    fconstructor,\n    intros n nsg g,\n    simp [subgroup_Δ,Δ,*] at *,\n    specialize h g.snd n.snd,\n    rw ← h,\n    norm_num,\n  }\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/diag-subgroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625145783431, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7802115916439254}}
{"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.big_operators.basic\nimport ring_theory.polynomial.basic\n\n/-!\n# Lagrange interpolation\n\n## Main definitions\n\n* `lagrange.basis s x` where `s : finset F` and `x : F`: the Lagrange basis polynomial\n  that evaluates to `1` at `x` and `0` at other elements of `s`.\n* `lagrange.interpolate s f` where `s : finset F` and `f : F → F`: the Lagrange interpolant\n  that evaluates to `f x` at `x` for `x ∈ s`.\n-/\n\nnoncomputable theory\nopen_locale big_operators classical\n\nuniverse u\n\nnamespace lagrange\n\nvariables {F : Type u} [decidable_eq F] [field F] (s : finset F)\nvariables {F' : Type u} [field F'] (s' : finset F')\n\nopen polynomial\n\n/-- Lagrange basis polynomials that evaluate to 1 at `x` and 0 at other elements of `s`. -/\ndef basis (x : F) : polynomial F :=\n∏ y in s.erase x, C (x - y)⁻¹ * (X - C y)\n\n@[simp] theorem basis_empty (x : F) : basis ∅ x = 1 :=\nrfl\n\n@[simp] theorem basis_singleton_self (x : F) : basis {x} x = 1 :=\nby rw [basis, finset.erase_singleton, finset.prod_empty]\n\n@[simp] theorem eval_basis_self (x : F) : (basis s x).eval x = 1 :=\nbegin\n  rw [basis, ← coe_eval_ring_hom, (eval_ring_hom x).map_prod, coe_eval_ring_hom,\n    finset.prod_eq_one],\n  intros y hy, simp_rw [eval_mul, eval_sub, eval_C, eval_X],\n  exact inv_mul_cancel (sub_ne_zero_of_ne (finset.ne_of_mem_erase hy).symm)\nend\n\n@[simp] theorem eval_basis_ne (x y : F) (h1 : y ∈ s) (h2 : y ≠ x) : (basis s x).eval y = 0 :=\nbegin\n  rw [basis,\n  ← coe_eval_ring_hom, (eval_ring_hom y).map_prod, coe_eval_ring_hom,\n    finset.prod_eq_zero (finset.mem_erase.2 ⟨h2, h1⟩)],\n  simp_rw [eval_mul, eval_sub, eval_C, eval_X, sub_self, mul_zero]\nend\n\ntheorem eval_basis (x y : F) (h : y ∈ s) : (basis s x).eval y = if y = x then 1 else 0 :=\nby { split_ifs with H, { subst H, apply eval_basis_self }, { exact eval_basis_ne s x y h H } }\n\n@[simp] theorem nat_degree_basis (x : F) (hx : x ∈ s) : (basis s x).nat_degree = s.card - 1 :=\nbegin\n  unfold basis, generalize hsx : s.erase x = sx,\n  have : x ∉ sx := hsx ▸ finset.not_mem_erase x s,\n  rw [← finset.insert_erase hx, hsx, finset.card_insert_of_not_mem this, add_tsub_cancel_right],\n  clear hx hsx s, revert this, apply sx.induction_on,\n  { intros hx, rw [finset.prod_empty, nat_degree_one], refl },\n  { intros y s hys ih hx, rw [finset.mem_insert, not_or_distrib] at hx,\n    have h1 : C (x - y)⁻¹ ≠ C 0 := λ h, hx.1 (eq_of_sub_eq_zero $ inv_eq_zero.1 $ C_inj.1 h),\n    have h2 : X ^ 1 - C y ≠ 0 := by convert X_pow_sub_C_ne_zero zero_lt_one y,\n    rw C_0 at h1, rw pow_one at h2,\n    rw [finset.prod_insert hys, nat_degree_mul (mul_ne_zero h1 h2), ih hx.2,\n        finset.card_insert_of_not_mem hys, nat_degree_mul h1 h2,\n        nat_degree_C, zero_add, nat_degree, degree_X_sub_C, add_comm], refl,\n    rw [ne, finset.prod_eq_zero_iff], rintro ⟨z, hzs, hz⟩,\n    rw mul_eq_zero at hz, cases hz with hz hz,\n    { rw [← C_0, C_inj, inv_eq_zero, sub_eq_zero] at hz, exact hx.2 (hz.symm ▸ hzs) },\n    { rw ← pow_one (X : polynomial F) at hz, exact X_pow_sub_C_ne_zero zero_lt_one _ hz } }\nend\n\nvariables (f : F → F)\n\n/-- Lagrange interpolation: given a finset `s` and a function `f : F → F`,\n`interpolate s f` is the unique polynomial of degree `< s.card`\nthat takes value `f x` on all `x` in `s`. -/\ndef interpolate : polynomial F :=\n∑ x in s, C (f x) * basis s x\n\n@[simp] theorem interpolate_empty (f) : interpolate (∅ : finset F) f = 0 :=\nrfl\n\n@[simp] theorem interpolate_singleton (f) (x : F) : interpolate {x} f = C (f x) :=\nby rw [interpolate, finset.sum_singleton, basis_singleton_self, mul_one]\n\n@[simp] theorem eval_interpolate (x) (H : x ∈ s) : eval x (interpolate s f) = f x :=\nbegin\n  rw [interpolate, ←coe_eval_ring_hom, ring_hom.map_sum, coe_eval_ring_hom, finset.sum_eq_single x],\n  { simp },\n  { intros y hy hxy, simp [eval_basis_ne s y x H hxy.symm] },\n  { intro h, exact (h H).elim }\nend\n\ntheorem degree_interpolate_lt : (interpolate s f).degree < s.card :=\nif H : s = ∅ then by { subst H, rw [interpolate_empty, degree_zero], exact with_bot.bot_lt_coe _ }\nelse (degree_sum_le _ _).trans_lt $ (finset.sup_lt_iff $ with_bot.bot_lt_coe s.card).2 $ λ b _,\ncalc  (C (f b) * basis s b).degree\n    ≤ (C (f b)).degree + (basis s b).degree : degree_mul_le _ _\n... ≤ 0 + (basis s b).degree : add_le_add_right degree_C_le _\n... = (basis s b).degree : zero_add _\n... ≤ (basis s b).nat_degree : degree_le_nat_degree\n... = (s.card - 1 : ℕ) : by { rwa nat_degree_basis }\n... < s.card : with_bot.coe_lt_coe.2 (nat.pred_lt $ mt finset.card_eq_zero.1 H)\n\ntheorem degree_interpolate_erase {x} (hx : x ∈ s) :\n  (interpolate (s.erase x) f).degree < (s.card - 1 : ℕ) :=\nbegin\n  convert degree_interpolate_lt (s.erase x) f,\n  rw [finset.card_erase_of_mem hx, nat.pred_eq_sub_one]\nend\n\ntheorem interpolate_eq_of_eval_eq (f g : F → F) {s : finset F} (hs : ∀ x ∈ s, f x = g x) :\n  interpolate s f = interpolate s g :=\nbegin\n  rw [interpolate, interpolate],\n  refine finset.sum_congr rfl (λ x hx, _),\n  rw hs x hx,\nend\n\n/-- Linear version of `interpolate`. -/\ndef linterpolate : (F → F) →ₗ[F] polynomial F :=\n{ to_fun := interpolate s,\n  map_add' := λ f g, by { simp_rw [interpolate, ← finset.sum_add_distrib, ← add_mul, ← C_add],\n    refl },\n  map_smul' := λ c f, by { simp_rw [interpolate, finset.smul_sum, C_mul', smul_smul], refl } }\n\n@[simp] lemma interpolate_add (f g) : interpolate s (f + g) = interpolate s f + interpolate s g :=\n(linterpolate s).map_add f g\n\n@[simp] lemma interpolate_zero : interpolate s 0 = 0 :=\n(linterpolate s).map_zero\n\n@[simp] lemma interpolate_neg (f) : interpolate s (-f) = -interpolate s f :=\n(linterpolate s).map_neg f\n\n@[simp] lemma interpolate_sub (f g) : interpolate s (f - g) = interpolate s f - interpolate s g :=\n(linterpolate s).map_sub f g\n\n@[simp] lemma interpolate_smul (c : F) (f) : interpolate s (c • f) = c • interpolate s f :=\n(linterpolate s).map_smul c f\n\ntheorem eq_zero_of_eval_eq_zero {f : polynomial F'} (hf1 : f.degree < s'.card)\n  (hf2 : ∀ x ∈ s', f.eval x = 0) : f = 0 :=\nby_contradiction $ λ hf3, not_le_of_lt hf1 $\ncalc  (s'.card : with_bot ℕ)\n    ≤ f.roots.to_finset.card : with_bot.coe_le_coe.2 $ finset.card_le_of_subset $ λ x hx,\n        (multiset.mem_to_finset).mpr $ (mem_roots hf3).2 $ hf2 x hx\n... ≤ f.roots.card : with_bot.coe_le_coe.2 $ f.roots.to_finset_card_le\n... ≤ f.degree : card_roots hf3\n\ntheorem eq_of_eval_eq {f g : polynomial F'} (hf : f.degree < s'.card) (hg : g.degree < s'.card)\n  (hfg : ∀ x ∈ s', f.eval x = g.eval x) : f = g :=\neq_of_sub_eq_zero $ eq_zero_of_eval_eq_zero s'\n  (lt_of_le_of_lt (degree_sub_le f g) $ max_lt hf hg)\n  (λ x hx, by rw [eval_sub, hfg x hx, sub_self])\n\ntheorem eq_interpolate_of_eval_eq {g : polynomial F} (hg : g.degree < s.card)\n  (hgf : ∀ x ∈ s, g.eval x = f x) : interpolate s f = g :=\neq_of_eval_eq s (degree_interpolate_lt _ _) hg $ λ x hx, begin\n  rw hgf x hx,\n  exact eval_interpolate _ _ _ hx,\nend\n\ntheorem eq_interpolate (f : polynomial F) (hf : f.degree < s.card) :\n  interpolate s (λ x, f.eval x) = f :=\neq_of_eval_eq s (degree_interpolate_lt s _) hf $ λ x hx, eval_interpolate s _ x hx\n\n/-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials\nof degree less than `s.card`. -/\ndef fun_equiv_degree_lt : degree_lt F s.card ≃ₗ[F] (s → F) :=\n{ to_fun := λ f x, f.1.eval x,\n  map_add' := λ f g, funext $ λ x, eval_add,\n  map_smul' := λ c f, funext $ by simp,\n  inv_fun := λ f, ⟨interpolate s (λ x, if hx : x ∈ s then f ⟨x, hx⟩ else 0),\n    mem_degree_lt.2 $ degree_interpolate_lt _ _⟩,\n  left_inv := λ f, begin apply subtype.eq,\n    simp only [subtype.coe_mk, subtype.val_eq_coe, dite_eq_ite],\n    convert eq_interpolate s f (mem_degree_lt.1 f.2) using 1,\n    rw interpolate_eq_of_eval_eq,\n    intros x hx,\n    rw if_pos hx end,\n  right_inv := λ f, funext $ λ ⟨x, hx⟩, begin\n    convert eval_interpolate s _ x hx,\n    simp_rw dif_pos hx end }\n\ntheorem interpolate_eq_interpolate_erase_add {x y : F} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) :\n  interpolate s f =\n  C (y - x)⁻¹ * ((X - C x) * interpolate (s.erase x) f + (C y - X) * interpolate (s.erase y) f) :=\nbegin\n  refine eq_interpolate_of_eval_eq _ _ _ (λ z hz, _),\n  { rw [degree_mul, degree_C (inv_ne_zero (sub_ne_zero.2 hxy.symm)), zero_add],\n    refine lt_of_le_of_lt (degree_add_le _ _) (max_lt _ _),\n    { rw [degree_mul, degree_X_sub_C],\n      convert (with_bot.add_lt_add_iff_left (with_bot.coe_ne_bot _)).2\n        (degree_interpolate_erase s f hx),\n      simp [nat.one_add, nat.sub_one, nat.succ_pred_eq_of_pos (finset.card_pos.2 ⟨x, hx⟩)] },\n    { rw [degree_mul, ←neg_sub, degree_neg, degree_X_sub_C],\n      convert (with_bot.add_lt_add_iff_left (with_bot.coe_ne_bot _)).2\n        (degree_interpolate_erase s f hy),\n      simp [nat.one_add, nat.sub_one, nat.succ_pred_eq_of_pos (finset.card_pos.2 ⟨y, hy⟩)] } },\n  { by_cases hzx : z = x,\n    { simp [hzx, eval_interpolate (s.erase y) f x (finset.mem_erase_of_ne_of_mem hxy hx),\n            inv_mul_eq_iff_eq_mul₀ (sub_ne_zero_of_ne hxy.symm)] },\n    { by_cases hzy : z = y,\n      { simp [hzy, eval_interpolate (s.erase x) f y (finset.mem_erase_of_ne_of_mem hxy.symm hy),\n              inv_mul_eq_iff_eq_mul₀ (sub_ne_zero_of_ne hxy.symm)] },\n      { simp only [eval_interpolate (s.erase x) f z (finset.mem_erase_of_ne_of_mem hzx hz),\n                   eval_interpolate (s.erase y) f z (finset.mem_erase_of_ne_of_mem hzy hz),\n                   inv_mul_eq_iff_eq_mul₀ (sub_ne_zero_of_ne hxy.symm), eval_mul, eval_C, eval_add,\n                   eval_sub, eval_X],\n        ring } } }\nend\n\nend lagrange\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/lagrange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7802115868630001}}
{"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 tactic.noncomm_ring\nimport field_theory.is_alg_closed.basic\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 → A`: the resolvent function is `λ r, ring.inverse (↑ₐr - a)`, and hence\n  when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - 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 `σ (a*b)` coincide with those in `σ (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* `σ a` : `spectrum R a` of `a : A`\n-/\n\nuniverses u v\n\n\nsection defs\n\nvariables (R : Type u) {A : Type v}\nvariables [comm_semiring R] [ring A] [algebra R A]\n\n-- definition and basic properties\n\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•1 - a` is a unit of the\nalgebra `A`.  -/\ndef resolvent_set (a : A) : set R :=\n{ r : R | is_unit (algebra_map R A r - a) }\n\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•1 - 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(resolvent_set R a)ᶜ\n\nvariable {R}\n/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is\n    a map `R → A` which sends `r : R` to `(algebra_map R A r - a)⁻¹` when\n    `r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/\nnoncomputable def resolvent (a : A) (r : R) : A :=\nring.inverse (algebra_map R A r - a)\n\n\nend defs\n\n\n-- products of scalar units and algebra units\n\n\nlemma is_unit.smul_sub_iff_sub_inv_smul {R : Type u} {A : Type v}\n  [comm_ring R] [ring A] [algebra R A] {r : Rˣ} {a : A} :\n  is_unit (r • 1 - a) ↔ is_unit (1 - r⁻¹ • a) :=\nbegin\n  have a_eq : a = r•r⁻¹•a, by simp,\n  nth_rewrite 0 a_eq,\n  rw [←smul_sub,is_unit_smul_iff],\nend\n\nnamespace spectrum\n\nsection scalar_ring\n\nvariables {R : Type u} {A : Type v}\nvariables [comm_ring R] [ring A] [algebra R A]\n\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma mem_iff {r : R} {a : A} :\n  r ∈ σ a ↔ ¬ is_unit (↑ₐr - a) :=\niff.rfl\n\nlemma not_mem_iff {r : R} {a : A} :\n  r ∉ σ a ↔ is_unit (↑ₐr - a) :=\nby { apply not_iff_not.mp, simp [set.not_not_mem, mem_iff] }\n\nlemma mem_resolvent_set_of_left_right_inverse {r : R} {a b c : A}\n  (h₁ : (↑ₐr - a) * b = 1) (h₂ : c * (↑ₐr - a) = 1) :\n  r ∈ resolvent_set R a :=\nunits.is_unit ⟨↑ₐr - a, b, h₁, by rwa ←left_inv_eq_right_inv h₂ h₁⟩\n\nlemma mem_resolvent_set_iff {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (↑ₐr - a) :=\niff.rfl\n\nlemma resolvent_eq {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  resolvent a r = ↑h.unit⁻¹ :=\nring.inverse_unit h.unit\n\nlemma add_mem_iff {a : A} {r s : R} :\n  r ∈ σ a ↔ r + s ∈ σ (↑ₐs + a) :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff],\n  have h_eq : ↑ₐ(r + s) - (↑ₐs + a) = ↑ₐr - a,\n    { simp, noncomm_ring },\n  rw h_eq,\nend\n\nlemma smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} :\n  r • s ∈ σ (r • a) ↔ s ∈ σ a :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one],\n  have h_eq : (r • s) • (1 : A) = r • s • 1, by simp,\n  rw [h_eq, ←smul_sub, is_unit_smul_iff],\nend\n\nopen_locale pointwise\n\ntheorem unit_smul_eq_smul (a : A) (r : Rˣ) :\n  σ (r • a) = r • σ a :=\nbegin\n  ext,\n  have x_eq : x = r • r⁻¹ • x, by simp,\n  nth_rewrite 0 x_eq,\n  rw smul_mem_smul_iff,\n  split,\n    { exact λ h, ⟨r⁻¹ • x, ⟨h, by simp⟩⟩},\n    { rintros ⟨_, _, x'_eq⟩, simpa [←x'_eq],}\nend\n\ntheorem left_add_coset_eq (a : A) (r : R) :\n  left_add_coset r (σ a) = σ (↑ₐr + a) :=\nby { ext, rw [mem_left_add_coset_iff, neg_add_eq_sub, add_mem_iff],\n     nth_rewrite 1 ←sub_add_cancel x r, }\n\n-- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ`\ntheorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : Rˣ} :\n  ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one],\n  have coe_smul_eq : ↑r • 1 = r • (1 : A), from rfl,\n  rw coe_smul_eq,\n  simp only [is_unit.smul_sub_iff_sub_inv_smul],\n  have right_inv_of_swap : ∀ {x y z : A} (h : (1 - x * y) * z = 1),\n    (1 - y * x) * (1 + y * z * x) = 1, from λ x y z h,\n      calc (1 - y * x) * (1 + y * z * x) = 1 - y * x + y * ((1 - x * y) * z) * x : by noncomm_ring\n      ...                                = 1                                     : by simp [h],\n  have left_inv_of_swap : ∀ {x y z : A} (h : z * (1 - x * y) = 1),\n    (1 + y * z * x) * (1 - y * x) = 1, from λ x y z h,\n      calc (1 + y * z * x) * (1 - y * x) = 1 - y * x + y * (z * (1 - x * y)) * x : by noncomm_ring\n      ...                                = 1                                     : by simp [h],\n  have is_unit_one_sub_mul_of_swap : ∀ {x y : A} (h : is_unit (1 - x * y)),\n    is_unit (1 - y * x), from λ x y h, by\n      { let h₁ := right_inv_of_swap h.unit.val_inv,\n        let h₂ := left_inv_of_swap h.unit.inv_val,\n        exact ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, h₁, h₂⟩, rfl⟩, },\n  have is_unit_one_sub_mul_iff_swap : ∀ {x y : A},\n    is_unit (1 - x * y) ↔ is_unit (1 - y * x), by\n      { intros, split, repeat {apply is_unit_one_sub_mul_of_swap}, },\n  rw [←smul_mul_assoc, ←mul_smul_comm r⁻¹ b a, is_unit_one_sub_mul_iff_swap],\nend\n\ntheorem preimage_units_mul_eq_swap_mul {a b : A} :\n  (coe : Rˣ → R) ⁻¹' σ (a * b) = coe ⁻¹'  σ (b * a) :=\nby { ext, exact unit_mem_mul_iff_mem_swap_mul, }\n\nend scalar_ring\n\nsection scalar_field\n\nvariables {𝕜 : Type u} {A : Type v}\nvariables [field 𝕜] [ring A] [algebra 𝕜 A]\n\nlocal notation `σ` := spectrum 𝕜\nlocal notation `↑ₐ` := algebra_map 𝕜 A\n\n/-- Without the assumption `nontrivial A`, then `0 : A` would be invertible. -/\n@[simp] lemma zero_eq [nontrivial A] : σ (0 : A) = {0} :=\nbegin\n  refine set.subset.antisymm _ (by simp [algebra.algebra_map_eq_smul_one, mem_iff]),\n  rw [spectrum, set.compl_subset_comm],\n  intros k hk,\n  rw set.mem_compl_singleton_iff at hk,\n  have : is_unit (units.mk0 k hk • (1 : A)) := is_unit.smul (units.mk0 k hk) is_unit_one,\n  simpa [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one]\nend\n\n@[simp] theorem scalar_eq [nontrivial A] (k : 𝕜) : σ (↑ₐk) = {k} :=\nbegin\n  have coset_eq : left_add_coset k {0} = {k}, by\n    { ext, split,\n      { intro hx, simp [left_add_coset] at hx, exact hx, },\n      { intro hx, simp at hx, exact ⟨0, ⟨set.mem_singleton 0, by simp [hx]⟩⟩, }, },\n  calc σ (↑ₐk) = σ (↑ₐk + 0)                  : by simp\n    ...        = left_add_coset k (σ (0 : A)) : by rw ←left_add_coset_eq\n    ...        = left_add_coset k {0}         : by rw zero_eq\n    ...        = {k}                          : coset_eq,\nend\n\n@[simp] lemma one_eq [nontrivial A] : σ (1 : A) = {1} :=\ncalc σ (1 : A) = σ (↑ₐ1) : by simp [algebra.algebra_map_eq_smul_one]\n  ...          = {1}     : scalar_eq 1\n\nopen_locale pointwise\n\n/-- the assumption `(σ a).nonempty` is necessary and cannot be removed without\n    further conditions on the algebra `A` and scalar field `𝕜`. -/\ntheorem smul_eq_smul [nontrivial A] (k : 𝕜) (a : A) (ha : (σ a).nonempty) :\n  σ (k • a) = k • (σ a) :=\nbegin\n  rcases eq_or_ne k 0 with rfl | h,\n  { simpa [ha, zero_smul_set] },\n  { exact unit_smul_eq_smul a (units.mk0 k h) },\nend\n\ntheorem nonzero_mul_eq_swap_mul (a b : A) : σ (a * b) \\ {0} = σ (b * a) \\ {0} :=\nbegin\n  suffices h : ∀ (x y : A), σ (x * y) \\ {0} ⊆ σ (y * x) \\ {0},\n  { exact set.eq_of_subset_of_subset (h a b) (h b a) },\n  { rintros _ _ k ⟨k_mem, k_neq⟩,\n    change k with ↑(units.mk0 k k_neq) at k_mem,\n    exact ⟨unit_mem_mul_iff_mem_swap_mul.mp k_mem, k_neq⟩ },\nend\n\nopen polynomial\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. -/\n\n\nlemma exists_mem_of_not_is_unit_aeval_prod {p : polynomial 𝕜} {a : A} (hp : p ≠ 0)\n  (h : ¬is_unit (aeval a (multiset.map (λ (x : 𝕜), X - C x) p.roots).prod)) :\n  ∃ k : 𝕜, k ∈ σ a ∧ eval k p = 0 :=\nbegin\n  rw [←multiset.prod_to_list, alg_hom.map_list_prod] at h,\n  replace h := mt list.prod_is_unit h,\n  simp only [not_forall, exists_prop, aeval_C, multiset.mem_to_list,\n    list.mem_map, aeval_X, exists_exists_and_eq_and, multiset.mem_map, alg_hom.map_sub] at h,\n  rcases h with ⟨r, r_mem, r_nu⟩,\n  exact ⟨r, by rwa [mem_iff, ←is_unit.sub_iff], by rwa [←is_root.def, ←mem_roots hp]⟩\nend\n\n/-- The *spectral mapping theorem* for polynomials.  Note: the assumption `degree p > 0`\nis necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side,\nassuming `[nontrivial A]`, is `{k}` where `p = polynomial.C k`. -/\ntheorem map_polynomial_aeval_of_degree_pos [is_alg_closed 𝕜] (a : A) (p : polynomial 𝕜)\n  (hdeg : 0 < degree p) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  /- handle the easy direction via `spectrum.subset_polynomial_aeval` -/\n  refine set.eq_of_subset_of_subset (λ k hk, _) (subset_polynomial_aeval a p),\n  /- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`. -/\n  have hprod := eq_prod_roots_of_splits_id (is_alg_closed.splits (C k - p)),\n  have h_ne : C k - p ≠ 0, from 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 (↑ₐ).to_monoid_hom (units.mk0 _ lead_ne)).is_unit,\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) = ↑ₐk - aeval a p,\n    by simp only [aeval_C, alg_hom.map_sub, sub_left_inj],\n  rw [mem_iff, ←p_a_eq, hprod, aeval_mul,\n    ((commute.all _ _).map (aeval a)).is_unit_mul_iff, 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 ⟨r, r_mem, r_ev⟩,\n  exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩,\nend\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. Note: the\nassumption `[nontrivial A]` is necessary for the same reason as in `spectrum.zero_eq`. -/\ntheorem map_polynomial_aeval_of_nonempty [is_alg_closed 𝕜] [nontrivial A] (a : A) (p : polynomial 𝕜)\n  (hnon : (σ a).nonempty) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  refine or.elim (le_or_gt (degree p) 0) (λ h, _) (map_polynomial_aeval_of_degree_pos a p),\n  { 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] },\nend\n\nvariable (𝕜)\n/--\nEvery element `a` in a nontrivial finite-dimensional algebra `A`\nover an algebraically closed field `𝕜` has non-empty spectrum. -/\n-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.\nlemma nonempty_of_is_alg_closed_of_finite_dimensional [is_alg_closed 𝕜]\n  [nontrivial A] [I : finite_dimensional 𝕜 A] (a : A) :\n  ∃ k : 𝕜, k ∈ σ a :=\nbegin\n  obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := is_integral_of_noetherian (is_noetherian.iff_fg.2 I) a,\n  have nu : ¬ is_unit (aeval a p), { rw [←aeval_def] at h_eval_p, rw h_eval_p, simp, },\n  rw [eq_prod_roots_of_monic_of_splits_id h_mon (is_alg_closed.splits p)] at nu,\n  obtain ⟨k, hk, _⟩ := exists_mem_of_not_is_unit_aeval_prod (monic.ne_zero h_mon) nu,\n  exact ⟨k, hk⟩\nend\n\nend scalar_field\n\nend spectrum\n\nnamespace alg_hom\n\nvariables {R : Type*} {A : Type*} [comm_ring R] [ring A] [algebra R A]\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma apply_mem_spectrum [nontrivial R] (φ : A →ₐ[R] R) (a : A) : φ a ∈ σ a :=\nbegin\n  have h : ↑ₐ(φ a) - a ∈ φ.to_ring_hom.ker,\n  { simp only [ring_hom.mem_ker, coe_to_ring_hom, commutes, algebra.id.map_eq_id,\n               to_ring_hom_eq_coe, ring_hom.id_apply, sub_self, map_sub] },\n  simp only [spectrum.mem_iff, ←mem_nonunits_iff,\n             coe_subset_nonunits (φ.to_ring_hom.ker_ne_top) h],\nend\n\nend alg_hom\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/algebra/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159727, "lm_q2_score": 0.8539127548105612, "lm_q1q2_score": 0.7802000451426494}}
{"text": "import data.real.basic\nimport tactic\n \n \nnamespace logic_example\n \nvariable U : Type\nvariables A B : U → Prop\n \n/-\nIf you have a proof, h1, which says:\n   for all x, if the property A(x) is true, then the property B(x) is true.\nand you have another proof, h2, which says:\n   for all x, the property A(X) is true,\n \nThen the following is a proof which says:\n   for all x, B(X) is true.\n-/\nexample\n (h1 : ∀ x, A x → B x)\n (h2 : ∀ x, A x) :\n∀ x, B x :=\nassume y,\nhave h3 : A y, from h2 y,\nhave h4 : A y → B y, from h1 y,\nshow B y, from h4 h3\n \nend logic_example\n \n \n \n\n\n\n \n \nset_option pp.implicit true\n-- Make simp display the steps used.\nset_option trace.simplify.rewrite true\n-- # 1\nnamespace problem1\n-- let X, Y, Z be sets.\nvariables {X Y Z : Type}\n-- a function f : X → Y is *injective* if f(a) = f(b) → a = b for all a,b in X.\ndef injective (f : X → Y)  : Prop :=\n∀ a b : X, f(a) = f(b) → a = b\n-- challenge: the composite of two injective functions is injective\ntheorem challenge1\n(f : X → Y) (hf : injective f)\n(g : Y → Z) (hg : injective g) :\ninjective (g ∘ f) :=\nbegin\n  intros a b,\n  intro h₁, --: g ∘ f a  = g ∘ f b, How to specify the type of h₁?\n  have h₂ : f a = f b, from hg (f a) (f b) h₁,\n  have h₃ : a = b, from hf a b h₂,\n  exact h₃\nend\ntheorem challenge1_solution\n(f : X → Y) (hf : injective f)\n(g : Y → Z) (hg : injective g) :\ninjective (g ∘ f) :=\nbegin\n-- the *definition* of \"injective\" is \"for all a and b...\", so let\n-- a and b be arbitrary elements of X.\nintros a b,\n-- Assume (g ∘ f) a = (g ∘ f) b\nintro hab,\n-- The goal is now ⊢ a = b .\n-- By injectivity of f, it suffices to prove f(a)=f(b)\napply hf,\n-- By injectivity of g, it suffices to prove g(f(a))=g(f(b))\napply hg,\n-- but this is precisely our assumption.\nexact hab,\n-- \"no goals\" means we're done.\nend\nend problem1\n \n \n \n\n\n \n \n \nnamespace problem2\n-- basic definitions\ndef upper_bounds (S : set ℝ) : set ℝ := { b | ∀s ∈ S, s ≤ b }\ndef lower_bounds (S : set ℝ) : set ℝ := { b | ∀s ∈ S, b ≤ s }\ndef is_least (S : set ℝ) (l : ℝ) : Prop := l ∈ S ∧ l ∈ lower_bounds S\ndef is_lub (S : set ℝ) (l : ℝ) : Prop := is_least (upper_bounds S) l\n\n/-- A set has at most one least upper bound -/\ntheorem challenge2\n(S : set ℝ)\n(a b : ℝ)\n(ha : is_lub S a)\n(hb : is_lub S b) :\na = b :=\nbegin\nhave h₁ : a ∈ upper_bounds S, from ha.left,\nhave h₂ : b ∈ upper_bounds S, from hb.left,\nhave h₃ : a ≤ b, from ha.right b h₂,\nhave h₄ : b ≤ a, from hb.right a h₁,\nlinarith,\n-- or\n--exact @le_antisymm ℝ real.partial_order a b h₃ h₄\nend\n \n \n \n \n \n \n \n \n/-- A set has at most one least upper bound -/\ntheorem challenge2_tactic_version\n(S : set ℝ)\n(a b : ℝ)\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 ∈ upper_bounds S ∧ a ∈ lower_bounds (upper_bounds S)\n-- so it's a proof of P ∧ Q, so you can use `cases` to recover the proofs of P and Q.\ncases ha with ha₁ ha₂,\n-- you don't have to do the unfolding though.\ncases hb with hb₁ hb₂,\n-- we prove a = b by showing a ≤ b and b ≤ a\napply le_antisymm, \n{ -- to prove a ≤ 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 ha₂,\n  -- and now we just need that b is an upper bound\n  exact hb₁},\n{ -- The other way is similar.\n  apply hb₂,\n  exact ha₁}\nend\nend problem2\n\n\n\n\n\n\n\n\n\n\n\nnamespace ploblem3\ntheorem challenge3 :\n(2 : ℝ) + 2 ≠ 5 :=\nbegin\nlinarith,\nend\ntheorem challenge3_solution :\n(2 : ℝ) + 2 ≠ 5 :=\nbegin\nnorm_num\nend\n/-\nNotes:\nAfter checking the docs, norm_num is more lightweight, covering arithmetic\nevaluations of *,+,-,^,≤, 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-/\nend ploblem3\nnamespace problem4\nopen function\ntheorem challenge4\n(X Y Z : Type)\n(f : X → Y)\n(g : Y → Z) :\nsurjective (g ∘ f) → surjective g :=\nassume h₁,\nassume z,\nhave h₂ : ∃y : Y, g y = z, from exists.elim (h₁ z)\n(assume (x : X) (hh₁ : (g ∘ f) x = z),\n  have hh₂ : g (f x) = z, from hh₁,\n  let y := f x in exists.intro y hh₂),\nh₂\ntheorem challenge4_solution\n(X Y Z : Type)\n(f : X → Y)\n(g : Y → Z) :\nsurjective (g ∘ f) → surjective g :=\nbegin\nintro h,\nintro z,\ncases h z with a ha,\nuse f a,\nassumption,\nend\nend problem4\n \n \n \n\n", "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/demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676530465412, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7802000414370817}}
{"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.star.pointwise\nimport algebra.star.subalgebra\nimport field_theory.is_alg_closed.basic\nimport tactic.noncomm_ring\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 → A`: the resolvent function is `λ r, ring.inverse (↑ₐr - a)`, and hence\n  when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - 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 `σ (a*b)` coincide with those in `σ (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* `σ a` : `spectrum R a` of `a : A`\n-/\n\nopen set\nopen_locale pointwise\n\nuniverses u v\n\nsection defs\n\nvariables (R : Type u) {A : Type v}\nvariables [comm_semiring R] [ring A] [algebra R A]\n\nlocal notation `↑ₐ` := algebra_map R A\n\n-- definition and basic properties\n\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•1 - a` is a unit of the\nalgebra `A`.  -/\ndef resolvent_set (a : A) : set R :=\n{ r : R | is_unit (↑ₐr - a) }\n\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•1 - 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(resolvent_set R a)ᶜ\n\nvariable {R}\n/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is\n    a map `R → A` which sends `r : R` to `(algebra_map R A r - a)⁻¹` when\n    `r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/\nnoncomputable def resolvent (a : A) (r : R) : A :=\nring.inverse (↑ₐr - a)\n\n/-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/\n@[simps]\nnoncomputable def is_unit.sub_inv_smul {r : Rˣ} {s : R} {a : A}\n  (h : is_unit $ r • ↑ₐs  - a) : Aˣ :=\n{ val := ↑ₐs - r⁻¹ • a,\n  inv := r • ↑h.unit⁻¹,\n  val_inv := by rw [mul_smul_comm, ←smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_coe_inv],\n  inv_val := by rw [smul_mul_assoc, ←mul_smul_comm, smul_sub, smul_inv_smul, h.coe_inv_mul], }\n\nend defs\n\nnamespace spectrum\nopen_locale polynomial\n\nsection scalar_semiring\n\nvariables {R : Type u} {A : Type v}\nvariables [comm_semiring R] [ring A] [algebra R A]\n\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma mem_iff {r : R} {a : A} :\n  r ∈ σ a ↔ ¬ is_unit (↑ₐr - a) :=\niff.rfl\n\nlemma not_mem_iff {r : R} {a : A} :\n  r ∉ σ a ↔ is_unit (↑ₐr - a) :=\nby { apply not_iff_not.mp, simp [set.not_not_mem, mem_iff] }\n\nvariables (R)\n\nlemma zero_mem_iff {a : A} : (0 : R) ∈ σ a ↔ ¬is_unit a :=\nby rw [mem_iff, map_zero, zero_sub, is_unit.neg_iff]\n\nlemma zero_not_mem_iff {a : A} : (0 : R) ∉ σ a ↔ is_unit a :=\nby rw [zero_mem_iff, not_not]\n\nvariables {R}\n\nlemma mem_resolvent_set_of_left_right_inverse {r : R} {a b c : A}\n  (h₁ : (↑ₐr - a) * b = 1) (h₂ : c * (↑ₐr - a) = 1) :\n  r ∈ resolvent_set R a :=\nunits.is_unit ⟨↑ₐr - a, b, h₁, by rwa ←left_inv_eq_right_inv h₂ h₁⟩\n\nlemma mem_resolvent_set_iff {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (↑ₐr - a) :=\niff.rfl\n\n@[simp] lemma resolvent_set_of_subsingleton [subsingleton A] (a : A) :\n  resolvent_set R a = set.univ :=\nby simp_rw [resolvent_set, subsingleton.elim (algebra_map R A _ - a) 1, is_unit_one,\n  set.set_of_true]\n\n@[simp] lemma of_subsingleton [subsingleton A] (a : A) :\n  spectrum R a = ∅ :=\nby rw [spectrum, resolvent_set_of_subsingleton, set.compl_univ]\n\nlemma resolvent_eq {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  resolvent a r = ↑h.unit⁻¹ :=\nring.inverse_unit h.unit\n\nlemma units_smul_resolvent {r : Rˣ} {s : R} {a : A} :\n  r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) :=\nbegin\n  by_cases h : s ∈ spectrum R a,\n  { rw [mem_iff] at h,\n    simp only [resolvent, algebra.algebra_map_eq_smul_one] at *,\n    rw [smul_assoc, ←smul_sub],\n    have h' : ¬ is_unit (r⁻¹ • (s • 1 - a)),\n      from λ hu, h (by simpa only [smul_inv_smul] using is_unit.smul r hu),\n    simp only [ring.inverse_non_unit _ h, ring.inverse_non_unit _ h', smul_zero] },\n  { simp only [resolvent],\n    have h' : is_unit (r • (algebra_map R A (r⁻¹ • s)) - a),\n      { simpa [algebra.algebra_map_eq_smul_one, smul_assoc] using not_mem_iff.mp h },\n    rw [←h'.coe_sub_inv_smul, ←(not_mem_iff.mp h).unit_spec, ring.inverse_unit, ring.inverse_unit,\n      h'.coe_inv_sub_inv_smul],\n    simp only [algebra.algebra_map_eq_smul_one, smul_assoc, smul_inv_smul], },\nend\n\nlemma units_smul_resolvent_self {r : Rˣ} {a : A} :\n  r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) :=\nby simpa only [units.smul_def, algebra.id.smul_eq_mul, units.inv_mul]\n  using @units_smul_resolvent _ _ _ _ _ r r a\n\n/-- The resolvent is a unit when the argument is in the resolvent set. -/\nlemma is_unit_resolvent {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (resolvent a r) :=\nis_unit_ring_inverse.symm\n\nlemma inv_mem_resolvent_set {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolvent_set R (a : A)) :\n  (↑r⁻¹ : R) ∈ resolvent_set R (↑a⁻¹ : A) :=\nbegin\n  rw [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one, ←units.smul_def] at h ⊢,\n  rw [is_unit.smul_sub_iff_sub_inv_smul, inv_inv, is_unit.sub_iff],\n  have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • 1 - a,\n  { rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one], },\n  have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • 1 - a,\n  { rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul], },\n  have hcomm : commute (a : A) (r • (↑a⁻¹ : A) - 1), { rwa ←h₂ at h₁ },\n  exact (hcomm.is_unit_mul_iff.mp (h₁.symm ▸ h)).2,\nend\n\nlemma inv_mem_iff {r : Rˣ} {a : Aˣ} :\n  (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) :=\nnot_iff_not.2 $ ⟨inv_mem_resolvent_set, inv_mem_resolvent_set⟩\n\nlemma zero_mem_resolvent_set_of_unit (a : Aˣ) : 0 ∈ resolvent_set R (a : A) :=\nby simpa only [mem_resolvent_set_iff, ←not_mem_iff, zero_not_mem_iff] using a.is_unit\n\nlemma ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 :=\nλ hn, (hn ▸ hr) (zero_mem_resolvent_set_of_unit a)\n\nlemma add_mem_iff {a : A} {r s : R} :\n  r + s ∈ σ a ↔ r ∈ σ (-↑ₐs + a) :=\nby simp only [mem_iff, sub_neg_eq_add, ←sub_sub, map_add]\n\nlemma add_mem_add_iff {a : A} {r s : R} :\n  r + s ∈ σ (↑ₐs + a) ↔ r ∈ σ a  :=\nby rw [add_mem_iff, neg_add_cancel_left]\n\nlemma smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} :\n  r • s ∈ σ (r • a) ↔ s ∈ σ a :=\nby simp only [mem_iff, not_iff_not, algebra.algebra_map_eq_smul_one, smul_assoc, ←smul_sub,\n  is_unit_smul_iff]\n\nopen_locale polynomial\n\ntheorem unit_smul_eq_smul (a : A) (r : Rˣ) :\n  σ (r • a) = r • σ a :=\nbegin\n  ext,\n  have x_eq : x = r • r⁻¹ • x, by simp,\n  nth_rewrite 0 x_eq,\n  rw smul_mem_smul_iff,\n  split,\n    { exact λ h, ⟨r⁻¹ • x, ⟨h, by simp⟩⟩},\n    { rintros ⟨_, _, x'_eq⟩, simpa [←x'_eq],}\nend\n\n-- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ`\ntheorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : Rˣ} :\n  ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) :=\nbegin\n  have h₁ : ∀ x y : A, is_unit (1 - x * y) → is_unit (1 - y * x),\n  { refine λ x y h, ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, _, _⟩, rfl⟩,\n    calc (1 - y * x) * (1 + y * (is_unit.unit h).inv * x)\n        = (1 - y * x) + y * ((1 - x * y) * h.unit.inv) * x : by noncomm_ring\n    ... = 1 : by simp only [units.inv_eq_coe_inv, is_unit.mul_coe_inv, mul_one, sub_add_cancel],\n    calc (1 + y * (is_unit.unit h).inv * x) * (1 - y * x)\n        = (1 - y * x) + y * (h.unit.inv * (1 - x * y)) * x : by noncomm_ring\n    ... = 1 : by simp only [units.inv_eq_coe_inv, is_unit.coe_inv_mul, mul_one, sub_add_cancel]},\n  simpa only [mem_iff, not_iff_not, algebra.algebra_map_eq_smul_one, ←units.smul_def,\n    is_unit.smul_sub_iff_sub_inv_smul, ←smul_mul_assoc, ←mul_smul_comm r⁻¹ b a]\n    using iff.intro (h₁ (r⁻¹ • a) b) (h₁ b (r⁻¹ • a)),\nend\n\ntheorem preimage_units_mul_eq_swap_mul {a b : A} :\n  (coe : Rˣ → R) ⁻¹' σ (a * b) = coe ⁻¹'  σ (b * a) :=\nset.ext $ λ _, unit_mem_mul_iff_mem_swap_mul\n\nsection star\n\nvariables [has_involutive_star R] [star_ring A] [star_module R A]\n\nlemma star_mem_resolvent_set_iff {r : R} {a : A} :\n  star r ∈ resolvent_set R a ↔ r ∈ resolvent_set R (star a) :=\nby refine ⟨λ h, _, λ h, _⟩;\n  simpa only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one, star_sub, star_smul,\n    star_star, star_one] using is_unit.star h\n\nprotected lemma map_star (a : A) : σ (star a) = star (σ a) :=\nby { ext, simpa only [set.mem_star, mem_iff, not_iff_not] using star_mem_resolvent_set_iff.symm }\n\nend star\n\nend scalar_semiring\n\nsection scalar_ring\n\nvariables {R : Type u} {A : Type v}\nvariables [comm_ring R] [ring A] [algebra R A]\n\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\n-- it would be nice to state this for `subalgebra_class`, but we don't have such a thing yet\nlemma subset_subalgebra {S : subalgebra R A} (a : S) : spectrum R (a : A) ⊆ spectrum R a :=\ncompl_subset_compl.2 (λ _, is_unit.map S.val)\n\n-- this is why it would be nice if `subset_subalgebra` was registered for `subalgebra_class`.\nlemma subset_star_subalgebra [star_ring R] [star_ring A] [star_module R A] {S : star_subalgebra R A}\n  (a : S) : spectrum R (a : A) ⊆ spectrum R a :=\ncompl_subset_compl.2 (λ _, is_unit.map S.subtype)\n\nlemma singleton_add_eq (a : A) (r : R) : {r} + (σ a) = σ (↑ₐr + a) :=\next $ λ x,\n  by rw [singleton_add, image_add_left, mem_preimage, add_comm, add_mem_iff, map_neg, neg_neg]\n\nlemma add_singleton_eq (a : A) (r : R) : (σ a) + {r} = σ (a + ↑ₐr) :=\nadd_comm {r} (σ a) ▸ add_comm (algebra_map R A r) a ▸ singleton_add_eq a r\n\nlemma vadd_eq (a : A) (r : R) : r +ᵥ (σ a) = σ (↑ₐr + a) :=\n(singleton_add).symm.trans $ singleton_add_eq a r\n\nlemma neg_eq (a : A) : -(σ a) = σ (-a) :=\nset.ext $ λ x, by simp only [mem_neg, mem_iff, map_neg, ←neg_add', is_unit.neg_iff, sub_neg_eq_add]\n\nlemma singleton_sub_eq (a : A) (r : R) :\n  {r} - (σ a) = σ (↑ₐr - a) :=\nby rw [sub_eq_add_neg, neg_eq, singleton_add_eq, sub_eq_add_neg]\n\nlemma sub_singleton_eq (a : A) (r : R) :\n  (σ a) - {r} = σ (a - ↑ₐr) :=\nby simpa only [neg_sub, neg_eq] using congr_arg has_neg.neg (singleton_sub_eq a r)\n\nopen polynomial\n\nlemma exists_mem_of_not_is_unit_aeval_prod [is_domain R] {p : R[X]} {a : A} (hp : p ≠ 0)\n  (h : ¬is_unit (aeval a (multiset.map (λ (x : R), X - C x) p.roots).prod)) :\n  ∃ k : R, k ∈ σ a ∧ eval k p = 0 :=\nbegin\n  rw [←multiset.prod_to_list, alg_hom.map_list_prod] at h,\n  replace h := mt list.prod_is_unit h,\n  simp only [not_forall, exists_prop, aeval_C, multiset.mem_to_list,\n    list.mem_map, aeval_X, exists_exists_and_eq_and, multiset.mem_map, alg_hom.map_sub] at h,\n  rcases h with ⟨r, r_mem, r_nu⟩,\n  exact ⟨r, by rwa [mem_iff, ←is_unit.sub_iff], by rwa [←is_root.def, ←mem_roots hp]⟩\nend\n\nend scalar_ring\n\nsection scalar_field\n\nvariables {𝕜 : Type u} {A : Type v}\nvariables [field 𝕜] [ring A] [algebra 𝕜 A]\n\nlocal notation `σ` := spectrum 𝕜\nlocal notation `↑ₐ` := algebra_map 𝕜 A\n\n/-- Without the assumption `nontrivial A`, then `0 : A` would be invertible. -/\n@[simp] lemma zero_eq [nontrivial A] : σ (0 : A) = {0} :=\nbegin\n  refine set.subset.antisymm _ (by simp [algebra.algebra_map_eq_smul_one, mem_iff]),\n  rw [spectrum, set.compl_subset_comm],\n  intros k hk,\n  rw set.mem_compl_singleton_iff at hk,\n  have : is_unit (units.mk0 k hk • (1 : A)) := is_unit.smul (units.mk0 k hk) is_unit_one,\n  simpa [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one]\nend\n\n@[simp] theorem scalar_eq [nontrivial A] (k : 𝕜) : σ (↑ₐk) = {k} :=\nby rw [←add_zero (↑ₐk), ←singleton_add_eq, zero_eq, set.singleton_add_singleton, add_zero]\n\n@[simp] lemma one_eq [nontrivial A] : σ (1 : A) = {1} :=\ncalc σ (1 : A) = σ (↑ₐ1) : by rw [algebra.algebra_map_eq_smul_one, one_smul]\n  ...          = {1}     : scalar_eq 1\n\n/-- the assumption `(σ a).nonempty` is necessary and cannot be removed without\n    further conditions on the algebra `A` and scalar field `𝕜`. -/\ntheorem smul_eq_smul [nontrivial A] (k : 𝕜) (a : A) (ha : (σ a).nonempty) :\n  σ (k • a) = k • (σ a) :=\nbegin\n  rcases eq_or_ne k 0 with rfl | h,\n  { simpa [ha, zero_smul_set] },\n  { exact unit_smul_eq_smul a (units.mk0 k h) },\nend\n\ntheorem nonzero_mul_eq_swap_mul (a b : A) : σ (a * b) \\ {0} = σ (b * a) \\ {0} :=\nbegin\n  suffices h : ∀ (x y : A), σ (x * y) \\ {0} ⊆ σ (y * x) \\ {0},\n  { exact set.eq_of_subset_of_subset (h a b) (h b a) },\n  { rintros _ _ k ⟨k_mem, k_neq⟩,\n    change k with ↑(units.mk0 k k_neq) at k_mem,\n    exact ⟨unit_mem_mul_iff_mem_swap_mul.mp k_mem, k_neq⟩ },\nend\n\nprotected lemma map_inv (a : Aˣ) : (σ (a : A))⁻¹ = σ (↑a⁻¹ : A) :=\nbegin\n  refine set.eq_of_subset_of_subset (λ k hk, _) (λ k hk, _),\n  { rw set.mem_inv at hk,\n    have : k ≠ 0,\n    { simpa only [inv_inv] using inv_ne_zero (ne_zero_of_mem_of_unit hk), },\n    lift k to 𝕜ˣ using is_unit_iff_ne_zero.mpr this,\n    rw ←units.coe_inv k at hk,\n    exact inv_mem_iff.mp hk },\n  { lift k to 𝕜ˣ using is_unit_iff_ne_zero.mpr (ne_zero_of_mem_of_unit hk),\n    simpa only [units.coe_inv] using inv_mem_iff.mp hk, }\nend\n\nopen polynomial\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. -/\n\n\n/-- The *spectral mapping theorem* for polynomials.  Note: the assumption `degree p > 0`\nis necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side,\nassuming `[nontrivial A]`, is `{k}` where `p = polynomial.C k`. -/\ntheorem map_polynomial_aeval_of_degree_pos [is_alg_closed 𝕜] (a : A) (p : 𝕜[X])\n  (hdeg : 0 < degree p) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  /- handle the easy direction via `spectrum.subset_polynomial_aeval` -/\n  refine set.eq_of_subset_of_subset (λ k hk, _) (subset_polynomial_aeval a p),\n  /- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`. -/\n  have hprod := eq_prod_roots_of_splits_id (is_alg_closed.splits (C k - p)),\n  have h_ne : C k - p ≠ 0, from 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 (↑ₐ).to_monoid_hom (units.mk0 _ lead_ne)).is_unit,\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) = ↑ₐk - aeval a p,\n    by simp only [aeval_C, alg_hom.map_sub, sub_left_inj],\n  rw [mem_iff, ←p_a_eq, hprod, aeval_mul,\n    ((commute.all _ _).map (aeval a)).is_unit_mul_iff, 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 ⟨r, r_mem, r_ev⟩,\n  exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩,\nend\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 [is_alg_closed 𝕜] (a : A) (p : 𝕜[X])\n  (hnon : (σ a).nonempty) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  nontriviality A,\n  refine or.elim (le_or_gt (degree p) 0) (λ h, _) (map_polynomial_aeval_of_degree_pos a p),\n  { 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] },\nend\n\n/-- A specialization of `spectrum.subset_polynomial_aeval` to monic monomials for convenience. -/\nlemma pow_image_subset (a : A) (n : ℕ) : (λ x, x ^ n) '' (σ a) ⊆ σ (a ^ n) :=\nby simpa only [eval_pow, eval_X, aeval_X_pow] using subset_polynomial_aeval a (X ^ n : 𝕜[X])\n\n/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for\nconvenience. -/\nlemma map_pow_of_pos [is_alg_closed 𝕜] (a : A) {n : ℕ} (hn : 0 < n) :\n  σ (a ^ n) = (λ x, x ^ n) '' (σ a) :=\nby simpa only [aeval_X_pow, eval_pow, eval_X] using\n  map_polynomial_aeval_of_degree_pos a (X ^ n : 𝕜[X]) (by { rw_mod_cast degree_X_pow, exact hn })\n\n/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for\nconvenience. -/\nlemma map_pow_of_nonempty [is_alg_closed 𝕜] {a : A} (ha : (σ a).nonempty) (n : ℕ) :\n  σ (a ^ n) = (λ x, x ^ n) '' (σ a) :=\nby simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval_of_nonempty a (X ^ n) ha\n\nvariable (𝕜)\n/--\nEvery element `a` in a nontrivial finite-dimensional algebra `A`\nover an algebraically closed field `𝕜` has non-empty spectrum. -/\n-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.\nlemma nonempty_of_is_alg_closed_of_finite_dimensional [is_alg_closed 𝕜]\n  [nontrivial A] [I : finite_dimensional 𝕜 A] (a : A) :\n  ∃ k : 𝕜, k ∈ σ a :=\nbegin\n  obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := is_integral_of_noetherian (is_noetherian.iff_fg.2 I) a,\n  have nu : ¬ is_unit (aeval a p), { rw [←aeval_def] at h_eval_p, rw h_eval_p, simp, },\n  rw [eq_prod_roots_of_monic_of_splits_id h_mon (is_alg_closed.splits p)] at nu,\n  obtain ⟨k, hk, _⟩ := exists_mem_of_not_is_unit_aeval_prod (monic.ne_zero h_mon) nu,\n  exact ⟨k, hk⟩\nend\n\nend scalar_field\n\nend spectrum\n\nnamespace alg_hom\n\nsection comm_semiring\n\nvariables {F R A B : Type*} [comm_ring R] [ring A] [algebra R A] [ring B] [algebra R B]\nvariables [alg_hom_class F R A B]\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma mem_resolvent_set_apply (φ : F) {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  r ∈ resolvent_set R ((φ : A → B) a) :=\nby simpa only [map_sub, alg_hom_class.commutes] using h.map φ\n\nlemma spectrum_apply_subset (φ : F) (a : A) : σ ((φ : A → B) a) ⊆ σ a :=\nλ _, mt (mem_resolvent_set_apply φ)\n\nend comm_semiring\n\nsection comm_ring\n\nvariables {F R A B : Type*} [comm_ring R] [ring A] [algebra R A] [ring B] [algebra R B]\nvariables [alg_hom_class F R A R]\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma apply_mem_spectrum [nontrivial R] (φ : F) (a : A) : φ a ∈ σ a :=\nbegin\n  have h : ↑ₐ(φ a) - a ∈ (φ : A →+* R).ker,\n  { simp only [ring_hom.mem_ker, map_sub, ring_hom.coe_coe, alg_hom_class.commutes,\n      algebra.id.map_eq_id, ring_hom.id_apply, sub_self], },\n  simp only [spectrum.mem_iff, ←mem_nonunits_iff, coe_subset_nonunits ((φ : A →+* R).ker_ne_top) h],\nend\n\nend comm_ring\n\nend 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/algebra/algebra/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7802000394299079}}
{"text": "import data.real.basic\nimport data.nat.basic\nvariables (x y : ℝ) \n\n\nexample (A B : Prop) : (¬ A) ∨ (B) ↔ (A ∧ B) ∨ (¬ A) :=\nbegin\nsplit,\nintro h,\ncases h with ha hab,\nright,\nexact ha,\nby_cases h:A,\nleft,\nsplit,\nexact h,\nexact hab,\nright,\nexact h,\nintro h,\nby_cases ha:A,\nright,\ncases h with h₁ h₂,\ncases h₁ with h₃ h₄,\nexact h₄,\nexfalso,\napply h₂,\nexact ha,\nleft,\nexact ha,\nend\n\ntheorem de_morgan1 (A B : Prop) : ¬ (A∨B) ↔ (¬A) ∧ (¬B) :=\nbegin\nsplit, --We consider each implication separately\nintro h₁, --We introduce ¬(A ∨ B) as the hypothesis h₁\nsplit, --Instead of showing ¬A ∧ ¬B, we will show ¬A and ¬B separately\nintro h₂, --The goal ¬A changes to false, and we the hypothesis h₂:A\napply h₁,\nleft,\nexact h₂,\nintro h₂,\napply h₁,\nright,\nexact h₂,\nintros h₁ h₂,\ncases h₁ with h₃ h₄,\ncases h₂ with h₅ h₆,\napply h₃,\nexact h₅,\napply h₄,\nexact h₆,\nend\n\ntheorem de_morgan2 (A B : Prop) : ¬(A∧B) ↔ (¬A)∨(¬B):=\nbegin\nsplit,\nintro h₁,\nby_cases h:A,\nright,\nintro h₂,\napply h₁,\nsplit,\nexact h,\nexact h₂,\nleft,\nexact h,\nintros h₁ h₂,\ncases h₂ with h₃ h₄,\ncases h₁ with h₅ h₆,\napply h₅,\nexact h₃,\napply h₆,\napply h₄,\nend\n\ntheorem lawofcomm (A B : Prop) : A∧B ↔ B∧A:=\nbegin\nsplit, --We consider the separate implications ⊢ A ∧ B → B ∧ A and ⊢B ∧ A → A ∧ B\nintro h₁, --This lets us consider the hypothesis A ∧ B\ncases h₁ with h₂ h₃, -- h₁:A ∧ B changes to h₂:A and h₃:B\nsplit,--Instead of showing B ∧ A we show B and A separately\nexact h₃,\nexact h₂,\nintro h₁,\ncases h₁ with h₂ h₃, \nsplit,\nexact h₃,\nexact h₂,\nend\n\ntheorem lawofcomm (A B : Prop) : A∧B ↔ B∧A:=\nbegin\nsplit, --We consider the separate implications ⊢ A ∧ B → B ∧ A and ⊢B ∧ A → A ∧ B\niterate 2\n{intro h₁, --This lets us consider the hypothesis A ∧ B\ncases h₁ with h₂ h₃, -- h₁:A ∧ B changes to h₂:A and h₃:B\nsplit,--Instead of showing B ∧ A we show B and A separately\nexact h₃,\nexact h₂,},\nend\n\ntheorem lawofassoc (A B C : Prop) : A∧(B∧C) ↔ (A∧B)∧C:=\nbegin\nsplit,\nintro h₁,\nsplit, \ncases h₁ with h₂ h₃,\ncases h₃ with h₄ h₅,\nsplit,\nexact h₂,\nexact h₄,\ncases h₁ with h₂ h₃,\ncases h₃ with h₄ h₅,\nexact h₅,\nintro h₁,\nsplit, \ncases h₁ with h₂ h₃,\ncases h₂ with h₄ h₅,\nexact h₄,\ncases h₁ with h₂ h₃,\ncases h₂ with h₄ h₅,\nsplit,\nexact h₅,\nexact h₃,\nend\n\ntheorem lawofdist (A B C : Prop) : A∧(B∨C) ↔ (A∧B)∨(A∧C):=\nbegin\nsplit,\nintro h₁,\ncases h₁ with h₂ h₃,\ncases h₃ with h₄ h₅,\nleft,\nsplit,\nexact h₂,\nexact h₄,\nright,\nsplit,\nexact h₂,\nexact h₅,\nintro h₁,\ncases h₁ with h₂ h₃,\ncases h₂ with h₄ h₅,\nsplit,\nexact h₄,\nleft,\nexact h₅,\nsplit,\ncases h₃ with h₄ h₅,\nexact h₄,\ncases h₃ with h₄ h₅,\nright,\nexact h₅,\nend\n\n\nexample (n: nat)  (h:x>0) : (1+x)^n ≥ 1 + x*n :=\nbegin\n  induction n with d hd,\n  norm_num,\n  have h₁:d.succ = ↑d+1,\n  norm_num,\n  rw h₁,\n  norm_num,\n  rw mul_add,\n  rw pow_succ,\n  rw add_mul,\n  rw ← add_assoc,\n  rw one_mul,\n  rw mul_one,\n  norm_num at hd,\n  apply add_le_add hd,\n  nth_rewrite 0 ← mul_one x,\n  apply mul_le_mul,\n  clear hd,\n  refl,\n  clear hd,\n  induction d with d hd,\n  simp[pow_zero,pow_succ],\n  nth_rewrite 0 ← mul_one (1:ℝ),\n  apply mul_le_mul,\n  linarith,\n  finish,\n  repeat{linarith},\n\nend\n\nexample {x : ℝ} {n : ℕ} (h : 0 < x) : 1 + x * n ≤ (1 + x) ^ n :=\nbegin\n  induction n with n hn,\n  { norm_num },\n  { change n.succ with n + 1, norm_num,\n    simp [pow_succ, mul_add, ←add_assoc, add_mul],\n    apply add_le_add hn, clear hn, nth_rewrite 0 ←mul_one x,\n    apply mul_le_mul; try {linarith},\n    induction n with n hn; simp [pow_zero, pow_succ],\n    nth_rewrite 0 ←mul_one (1 : ℝ), apply mul_le_mul; linarith },\nend\n\n\n", "meta": {"author": "HarryPacitti", "repo": "LeanAnalysisTutorial1", "sha": "a1d39999c13f33aecd808d72961c94edc10c54a8", "save_path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1", "path": "github-repos/lean/HarryPacitti-LeanAnalysisTutorial1/LeanAnalysisTutorial1-a1d39999c13f33aecd808d72961c94edc10c54a8/Examples/Logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7802000323275528}}
{"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 → α` 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 → α`.\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 {α β 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 → α`,\n    we define `circulant v` to be the circulant matrix generated by `v` of type `matrix n n α`.\n    The `(i,j)`th entry is defined to be `v (i - j)`. -/\n@[simp]\ndef circulant [has_sub n] (v : n → α) : matrix n n α\n| i j := v (i - j)\n\nlemma circulant_col_zero_eq [add_group n] (v : n → α) (i : n) : circulant v i 0 = v i :=\ncongr_arg v (sub_zero _)\n\nlemma circulant_injective [add_group n] : injective (circulant : (n → α) → matrix n n α) :=\nbegin\n  intros v w h,\n  ext k,\n  rw [← circulant_col_zero_eq v, ← circulant_col_zero_eq w, h]\nend\n\nlemma fin.circulant_injective : ∀ n, injective (λ v : fin n → α, circulant v)\n| 0     := dec_trivial\n| (n+1) := circulant_injective\n\n@[simp] lemma circulant_inj [add_group n] {v w : n → α} :\n  circulant v = circulant w ↔ v = w :=\ncirculant_injective.eq_iff\n\n@[simp] lemma fin.circulant_inj {n} {v w : fin n → α} :\n  circulant v = circulant w ↔ v = w :=\n(fin.circulant_injective n).eq_iff\n\nlemma transpose_circulant [add_group n] (v : n → α) :\n  (circulant v)ᵀ = circulant (λ i, v (-i)) :=\nby ext; simp\n\nlemma conj_transpose_circulant [has_star α] [add_group n] (v : n → α) :\n  (circulant v)ᴴ = circulant (star (λ i, v (-i))) :=\nby ext; simp\n\nlemma fin.transpose_circulant : ∀ {n} (v : fin n → α), (circulant v)ᵀ =  circulant (λ i, v (-i))\n| 0     := dec_trivial\n| (n+1) := transpose_circulant\n\nlemma fin.conj_transpose_circulant [has_star α] :\n  ∀ {n} (v : fin n → α), (circulant v)ᴴ = circulant (star (λ i, v (-i)))\n| 0     := dec_trivial\n| (n+1) := conj_transpose_circulant\n\nlemma map_circulant [has_sub n] (v : n → α) (f : α → β) :\n  (circulant v).map f = circulant (λ i, f (v i)) :=\next $ λ _ _, rfl\n\nlemma circulant_neg [has_neg α] [has_sub n] (v : n → α) :\n  circulant (- v) = - circulant v :=\next $ λ _ _, rfl\n\n@[simp] lemma circulant_zero (α n) [has_zero α] [has_sub n] :\n  circulant 0 = (0 : matrix n n α) :=\next $ λ _ _, rfl\n\nlemma circulant_add [has_add α] [has_sub n] (v w : n → α) :\n  circulant (v + w) = circulant v + circulant w :=\next $ λ _ _, rfl\n\nlemma circulant_sub [has_sub α] [has_sub n] (v w : n → α) :\n  circulant (v - w) = circulant v - circulant w :=\next $ λ _ _, 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 α] [fintype n] [add_group n] (v w : n → α) :\n  circulant v ⬝ circulant w = circulant (mul_vec (circulant v) w) :=\nbegin\n  ext i j,\n  simp only [mul_apply, mul_vec, circulant, 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 α] :\n  ∀ {n} (v w : fin n → α), circulant v ⬝ 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 α] [add_comm_monoid α] [fintype n] [add_comm_group n] (v w : n → α) :\n  circulant v ⬝ circulant w = circulant w ⬝ circulant v :=\nbegin\n  ext i j,\n  simp only [mul_apply, circulant, 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 α] [add_comm_monoid α] :\n  ∀ {n} (v w : fin n → α), circulant v ⬝ circulant w = circulant w ⬝ circulant v\n| 0     := dec_trivial\n| (n+1) := circulant_mul_comm\n\n/-- `k • circulant v` is another circulant matrix `circulant (k • v)`. -/\nlemma circulant_smul [has_sub n] [has_scalar R α] (k : R) (v : n → α) :\n  circulant (k • v) = k • circulant v :=\nby ext; simp\n\n@[simp] lemma circulant_single_one\n  (α n) [has_zero α] [has_one α] [decidable_eq n] [add_group n] :\n  circulant (pi.single 0 1 : n → α) = (1 : matrix n n α) :=\nby { ext i j, simp [one_apply, pi.single_apply, sub_eq_zero] }\n\n@[simp] lemma circulant_single\n  (n) [semiring α] [decidable_eq n] [add_group n] [fintype n] (a : α) :\n  circulant (pi.single 0 a : n → α) = scalar n a :=\nbegin\n  ext i j,\n  simp [pi.single_apply, one_apply, sub_eq_zero],\nend\n\n/-- Note we use `↑i = 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 (α) [has_zero α] [has_one α] :\n  ∀ n, circulant (λ i, ite (↑i = 0) 1 0 : fin n → α) = 1\n| 0     := dec_trivial\n| (n+1) :=\nbegin\n  rw [←circulant_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 → α} :\n  (circulant v).is_symm ↔ ∀ i, v (- i) = v i :=\nby rw [is_symm, transpose_circulant, circulant_inj, funext_iff]\n\nlemma fin.circulant_is_symm_iff :\n  ∀ {n} {v : fin n → α}, (circulant v).is_symm ↔ ∀ i, v (- i) = v i\n| 0     := λ v, by simp [is_symm.ext_iff, is_empty.forall_iff]\n| (n+1) := λ v, circulant_is_symm_iff\n\n/-- If `circulant v` is symmetric, `∀ i j : I, v (- i) = v i`. -/\nlemma circulant_is_symm_apply [add_group n] {v : n → α} (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 → α} (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": "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/circulant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7802000300115989}}
{"text": "import data.nat.choose.vandermonde\n--import multinomial \n\nsection combinatorics\n\n/-- Number of possibilities of choosing m groups of n-element subsets out of mn elements -/\ndef mchoose (m n : ℕ) : ℕ := \nfinset.prod (finset.range m) (λ p, nat.choose (p * n + n - 1) (n - 1))\n\nlemma mchoose_zero (n : ℕ) : mchoose 0 n = 1 := \nby rw [mchoose, finset.range_zero, finset.prod_empty]\n\nlemma mchoose_zero' (m : ℕ) : mchoose m 0 = 1 :=\nby simp only [mchoose, mul_zero, nat.choose_self, finset.prod_const_one] \n\nlemma mchoose_succ (m n : ℕ) : \n  mchoose (m + 1) n = (nat.choose (m * n + n - 1) (n - 1)) * (mchoose m n) := \nby simp only [mchoose, finset.prod_range_succ, mul_comm]\n\nlemma mchoose_lemma (m : ℕ) {n : ℕ} (hn : n ≠ 0) :\n  (m.factorial) * (n.factorial)^m * (mchoose m n) = (m * n).factorial :=\nbegin\n  rw ← zero_lt_iff at hn,\n  induction m with m ih,\n  { rw [mchoose_zero, mul_one, zero_mul, nat.factorial_zero, pow_zero, mul_one] }, \n  { have hmn : (m + 1) * (m * n + n - 1).choose (n - 1) = (m * n + n).choose n,\n    { rw [← mul_left_inj' (nat.mul_ne_zero (nat.factorial_ne_zero (m * n)) (nat.factorial_ne_zero n)),\n        ← mul_assoc, ← mul_assoc, nat.add_choose_mul_factorial_mul_factorial,\n        ← nat.mul_factorial_pred hn, mul_comm n _, ← mul_assoc, nat.add_sub_assoc hn (m * n),\n        mul_comm,mul_assoc ((m + 1) * (m * n + (n - 1)).choose (n - 1)), mul_assoc (m + 1),\n        ← mul_assoc ((m * n + (n - 1)).choose (n - 1)), nat.add_choose_mul_factorial_mul_factorial,\n        ← nat.mul_factorial_pred  (nat.add_pos_right _ hn), ← nat.add_sub_assoc hn (m * n)], \n      ring, },\n    rw [mchoose_succ, nat.factorial_succ, pow_succ, ← mul_assoc],\n    conv_rhs { rw nat.succ_mul},\n    rw [← nat.add_choose_mul_factorial_mul_factorial, ← ih, ← hmn],\n    ring_nf, } \nend\n\nend combinatorics", "meta": {"author": "AntoineChambert-Loir", "repo": "divided_powers", "sha": "86b6f8716590d38e63ed11d34c0140de8ae2af7d", "save_path": "github-repos/lean/AntoineChambert-Loir-divided_powers", "path": "github-repos/lean/AntoineChambert-Loir-divided_powers/divided_powers-86b6f8716590d38e63ed11d34c0140de8ae2af7d/src/combinatorics_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875641, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.780189460626298}}
{"text": "/-\nCopyright (c) 2021 Hanting Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hanting Zhang\n-/\nimport analysis.special_functions.integrals\n\n/-! # The Wallis formula for Pi\n\nThis file establishes the Wallis product for `π` (`real.tendsto_prod_pi_div_two`). Our proof is\nlargely about analyzing the behaviour of the sequence `∫ x in 0..π, sin x ^ n` as `n → ∞`.\nSee: https://en.wikipedia.org/wiki/Wallis_product\n\nThe proof can be broken down into two pieces. The first step (carried out in\n`analysis.special_functions.integrals`) is to use repeated integration by parts to obtain an\nexplicit formula for this integral, which is rational if `n` is odd and a rational multiple of `π`\nif `n` is even.\n\nThe second step, carried out here, is to estimate the ratio\n`∫ (x : ℝ) in 0..π, sin x ^ (2 * k + 1) / ∫ (x : ℝ) in 0..π, sin x ^ (2 * k)` and prove that\nit converges to one using the squeeze theorem. The final product for `π` is obtained after some\nalgebraic manipulation.\n\n## Main statements\n\n* `real.wallis.W`: the product of the first `k` terms in Wallis' formula for `π`.\n* `real.wallis.W_eq_integral_sin_pow_div_integral_sin_pow`: express `W n` as a ratio of integrals.\n* `real.wallis.W_le` and `real.wallis.le_W`: upper and lower bounds for `W n`.\n* `real.tendsto_prod_pi_div_two`: the Wallis product formula.\n -/\n\nopen_locale real topology big_operators nat\nopen filter finset interval_integral\n\nnamespace real\n\nnamespace wallis\n\n/-- The product of the first `k` terms in Wallis' formula for `π`. -/\nnoncomputable def W (k : ℕ) : ℝ :=\n∏ i in range k, (2 * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3))\n\nlemma W_succ (k : ℕ) :\n  W (k + 1) = W k * ((2 * k + 2) / (2 * k + 1) * ((2 * k + 2) / (2 * k + 3))) :=\nprod_range_succ _ _\n\nlemma W_pos (k : ℕ) : 0 < W k :=\nbegin\n  induction k with k hk,\n  { unfold W, simp },\n  { rw W_succ,\n    refine mul_pos hk (mul_pos (div_pos _ _) (div_pos _ _));\n    positivity }\nend\n\nlemma W_eq_factorial_ratio (n : ℕ) :\n  W n = (2 ^ (4 * n) * n! ^ 4) / ((2 * n)!^ 2 * (2 * n + 1)) :=\nbegin\n  induction n with n IH,\n  { simp only [W, prod_range_zero, nat.factorial_zero, mul_zero, pow_zero, algebra_map.coe_one,\n      one_pow, mul_one, algebra_map.coe_zero, zero_add, div_self, ne.def, one_ne_zero,\n      not_false_iff] },\n  { unfold W at ⊢ IH,\n    rw [prod_range_succ, IH, _root_.div_mul_div_comm, _root_.div_mul_div_comm],\n    refine (div_eq_div_iff _ _).mpr _,\n    any_goals { exact ne_of_gt (by positivity) },\n    simp_rw [nat.mul_succ, nat.factorial_succ, pow_succ],\n    push_cast,\n    ring_nf }\nend\n\nlemma W_eq_integral_sin_pow_div_integral_sin_pow (k : ℕ) :\n  (π/2)⁻¹ * W k = (∫ (x : ℝ) in 0..π, sin x ^ (2 * k + 1)) / ∫ (x : ℝ) in 0..π, sin x ^ (2 * k) :=\nbegin\n  rw [integral_sin_pow_even, integral_sin_pow_odd, mul_div_mul_comm, ←prod_div_distrib, inv_div],\n  simp_rw [div_div_div_comm, div_div_eq_mul_div, mul_div_assoc],\n  refl,\nend\n\nlemma W_le (k : ℕ) : W k ≤ π / 2 :=\nbegin\n  rw [←div_le_one pi_div_two_pos, div_eq_inv_mul],\n  rw [W_eq_integral_sin_pow_div_integral_sin_pow, div_le_one (integral_sin_pow_pos _)],\n  apply integral_sin_pow_succ_le,\nend\n\nlemma le_W (k : ℕ) : ((2:ℝ) * k + 1) / (2 * k + 2) * (π / 2) ≤ W k :=\nbegin\n  rw [←le_div_iff pi_div_two_pos, div_eq_inv_mul (W k) _],\n  rw [W_eq_integral_sin_pow_div_integral_sin_pow, le_div_iff (integral_sin_pow_pos _)],\n  convert integral_sin_pow_succ_le (2 * k + 1),\n  rw integral_sin_pow (2 * k),\n  simp only [sin_zero, zero_pow', ne.def, nat.succ_ne_zero, not_false_iff, zero_mul, sin_pi,\n    tsub_zero, nat.cast_mul, nat.cast_bit0, algebra_map.coe_one, zero_div, zero_add],\nend\n\nlemma tendsto_W_nhds_pi_div_two : tendsto W at_top (𝓝 $ π / 2) :=\nbegin\n  refine tendsto_of_tendsto_of_tendsto_of_le_of_le _ tendsto_const_nhds le_W W_le,\n  have : 𝓝 (π / 2) = 𝓝 ((1 - 0) * (π / 2)), by rw [sub_zero, one_mul], rw this,\n  refine tendsto.mul _ tendsto_const_nhds,\n  have h : ∀ (n:ℕ), ((2:ℝ) * n + 1) / (2 * n + 2) = 1 - 1 / (2 * n + 2),\n  { intro n,\n    rw [sub_div' _ _ _ (ne_of_gt (add_pos_of_nonneg_of_pos\n      (mul_nonneg ((two_pos : 0 < (2:ℝ)).le) (nat.cast_nonneg _)) two_pos)), one_mul],\n    congr' 1, ring },\n  simp_rw h,\n  refine (tendsto_const_nhds.div_at_top _).const_sub _,\n  refine tendsto.at_top_add _ tendsto_const_nhds,\n  exact tendsto_coe_nat_at_top_at_top.const_mul_at_top two_pos\nend\n\nend wallis\n\nend real\n\n/-- Wallis' product formula for `π / 2`. -/\ntheorem real.tendsto_prod_pi_div_two :\n  tendsto\n  (λ k, ∏ i in range k, (((2:ℝ) * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3)))\n  at_top (𝓝 (π/2)) :=\nreal.wallis.tendsto_W_nhds_pi_div_two\n", "meta": {"author": "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/pi/wallis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.7801008986760145}}
{"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 8ef6f08ff8c781c5c07a8b12843710e1a0d8a688\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.NumberTheory.Divisors\nimport Mathbin.RingTheory.Int.Basic\nimport Mathbin.Tactic.RingExp\n\n/-!\n# p-adic Valuation\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 `p`-adic valuation on `ℕ`, `ℤ`, and `ℚ`.\n\nThe `p`-adic valuation on `ℚ` 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 `ℕ` and `ℤ` agree with that on `ℚ`.\n\nThe valuation induces a norm on `ℚ`. 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 p.prime]` as a type class argument.\n\n## References\n\n* [F. Q. Gouvêa, *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#print padicValNat /-\n/-- For `p ≠ 1`, the `p`-adic valuation of a natural `n ≠ 0` is the largest natural number `k` such\nthat `p^k` divides `z`. If `n = 0` or `p = 1`, then `padic_val_nat p q` defaults to `0`. -/\ndef padicValNat (p : ℕ) (n : ℕ) : ℕ :=\n  if h : p ≠ 1 ∧ 0 < n then (multiplicity p n).get (multiplicity.finite_nat_iff.2 h) else 0\n#align padic_val_nat padicValNat\n-/\n\nnamespace padicValNat\n\nopen multiplicity\n\nvariable {p : ℕ}\n\n#print padicValNat.zero /-\n/-- `padic_val_nat p 0` is `0` for any `p`. -/\n@[simp]\nprotected theorem zero : padicValNat p 0 = 0 := by simp [padicValNat]\n#align padic_val_nat.zero padicValNat.zero\n-/\n\n#print padicValNat.one /-\n/-- `padic_val_nat p 1` is `0` for any `p`. -/\n@[simp]\nprotected theorem one : padicValNat p 1 = 0 :=\n  by\n  unfold padicValNat\n  split_ifs\n  simp\n#align padic_val_nat.one padicValNat.one\n-/\n\n#print padicValNat.self /-\n/-- If `p ≠ 0` and `p ≠ 1`, then `padic_val_rat p p` is `1`. -/\n@[simp]\ntheorem self (hp : 1 < p) : padicValNat p p = 1 :=\n  by\n  have neq_one : ¬p = 1 ↔ True := iff_of_true (ne_of_lt hp).symm trivial\n  have eq_zero_false : p = 0 ↔ False := iff_false_intro (ne_of_lt (trans zero_lt_one hp)).symm\n  simp [padicValNat, neq_one, eq_zero_false]\n#align padic_val_nat.self padicValNat.self\n-/\n\n#print padicValNat.eq_zero_iff /-\n@[simp]\ntheorem eq_zero_iff {n : ℕ} : padicValNat p n = 0 ↔ p = 1 ∨ n = 0 ∨ ¬p ∣ 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, ← or_iff_not_imp_left]\n#align padic_val_nat.eq_zero_iff padicValNat.eq_zero_iff\n-/\n\n#print padicValNat.eq_zero_of_not_dvd /-\ntheorem eq_zero_of_not_dvd {n : ℕ} (h : ¬p ∣ 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-/\n\nend padicValNat\n\n#print padicValInt /-\n/-- For `p ≠ 1`, the `p`-adic valuation of an integer `z ≠ 0` is the largest natural number `k` such\nthat `p^k` divides `z`. If `x = 0` or `p = 1`, then `padic_val_int p q` defaults to `0`. -/\ndef padicValInt (p : ℕ) (z : ℤ) : ℕ :=\n  padicValNat p z.natAbs\n#align padic_val_int padicValInt\n-/\n\nnamespace padicValInt\n\nopen multiplicity\n\nvariable {p : ℕ}\n\n/- warning: padic_val_int.of_ne_one_ne_zero -> padicValInt.of_ne_one_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {z : Int} (hp : Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (hz : Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))), Eq.{1} Nat (padicValInt p z) (Part.get.{0} Nat (multiplicity.{0} Int Int.monoid (fun (a : Int) (b : Int) => Int.decidableDvd a b) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z) (Iff.mpr (multiplicity.Finite.{0} Int Int.monoid ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z) (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (multiplicity.finite_int_iff ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z) (Eq.mpr.{0} (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) True (id_tag Tactic.IdTag.simp (Eq.{1} Prop (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) True) (Eq.trans.{1} Prop (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (And True True) True ((fun (a : Prop) (a_1 : Prop) (e_1 : Eq.{1} Prop a a_1) (b : Prop) (b_1 : Prop) (e_2 : Eq.{1} Prop b b_1) => congr.{1, 1} Prop Prop (And a) (And a_1) b b_1 (congr_arg.{1, 1} Prop (Prop -> Prop) a a_1 And e_1) e_2) (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) True (Eq.trans.{1} Prop (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Not False) True (Eq.trans.{1} Prop (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Not False) (Eq.trans.{1} Prop (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) ((fun (a : Nat) (a_1 : Nat) (e_1 : Eq.{1} Nat a a_1) (b : Nat) (b_1 : Nat) (e_2 : Eq.{1} Nat b b_1) => congr.{1, 1} Nat Prop (Ne.{1} Nat a) (Ne.{1} Nat a_1) b b_1 (congr_arg.{1, 1} Nat (Nat -> Prop) a a_1 (Ne.{1} Nat) e_1) e_2) (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) p (Int.natAbs_ofNat p) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (rfl.{1} Nat (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Ne.def.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) ((fun (a : Prop) (a_1 : Prop) (e_1 : Eq.{1} Prop a a_1) => congr_arg.{1, 1} Prop Prop a a_1 Not e_1) (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) False (propext (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) False (iff_false_intro (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) hp)))) (propext (Not False) True not_false_iff)) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) True (Eq.trans.{1} Prop (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (Not False) True (Eq.trans.{1} Prop (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (Not (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (Not False) (Ne.def.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) ((fun (a : Prop) (a_1 : Prop) (e_1 : Eq.{1} Prop a a_1) => congr_arg.{1, 1} Prop Prop a a_1 Not e_1) (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) False (propext (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) False (iff_false_intro (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) hz)))) (propext (Not False) True not_false_iff))) (propext (And True True) True (and_self_iff True)))) trivial)))\nbut is expected to have type\n  forall {p : Nat} {z : Int} (hp : Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (hz : Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))), Eq.{1} Nat (padicValInt p z) (Part.get.{0} Nat (multiplicity.{0} Int Int.instMonoidInt (fun (a : Int) (b : Int) => Int.decidableDvd a b) (Nat.cast.{0} Int instNatCastInt p) z) (Iff.mpr (multiplicity.Finite.{0} Int Int.instMonoidInt (Nat.cast.{0} Int instNatCastInt p) z) (And (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) (multiplicity.finite_int_iff (Nat.cast.{0} Int instNatCastInt p) z) (of_eq_true (And (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Not (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))))) (Eq.trans.{1} Prop (And (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Not (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))))) (And True True) True (congr.{1, 1} Prop Prop (And (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (And True) (Not (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) True (congrArg.{1, 1} Prop (Prop -> Prop) (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) True And (Eq.trans.{1} Prop (Not (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Not False) True (congrArg.{1, 1} Prop Prop (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) False Not (eq_false (Eq.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) hp)) Std.Logic._auxLemma.4)) (Eq.trans.{1} Prop (Not (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) (Not False) True (congrArg.{1, 1} Prop Prop (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) False Not (eq_false (Eq.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) hz)) Std.Logic._auxLemma.4)) (and_self True)))))\nCase conversion may be inaccurate. Consider using '#align padic_val_int.of_ne_one_ne_zero padicValInt.of_ne_one_ne_zeroₓ'. -/\ntheorem of_ne_one_ne_zero {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) :\n    padicValInt p z =\n      (multiplicity (p : ℤ) z).get\n        (by\n          apply multiplicity.finite_int_iff.2\n          simp [hp, hz]) :=\n  by\n  rw [padicValInt, padicValNat, dif_pos (And.intro hp (Int.natAbs_pos_of_ne_zero hz))]\n  simp only [multiplicity.Int.natAbs p z]\n  rfl\n#align padic_val_int.of_ne_one_ne_zero padicValInt.of_ne_one_ne_zero\n\n#print padicValInt.zero /-\n/-- `padic_val_int 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\n#print padicValInt.one /-\n/-- `padic_val_int 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\n#print padicValInt.of_nat /-\n/-- The `p`-adic value of a natural is its `p`-adic value as an integer. -/\n@[simp]\ntheorem of_nat {n : ℕ} : padicValInt p n = padicValNat p n := by simp [padicValInt]\n#align padic_val_int.of_nat padicValInt.of_nat\n-/\n\n#print padicValInt.self /-\n/-- If `p ≠ 0` and `p ≠ 1`, then `padic_val_int 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-/\n\n/- warning: padic_val_int.eq_zero_of_not_dvd -> padicValInt.eq_zero_of_not_dvd is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {z : Int}, (Not (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z)) -> (Eq.{1} Nat (padicValInt p z) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))\nbut is expected to have type\n  forall {p : Nat} {z : Int}, (Not (Dvd.dvd.{0} Int Int.instDvdInt (Nat.cast.{0} Int instNatCastInt p) z)) -> (Eq.{1} Nat (padicValInt p z) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align padic_val_int.eq_zero_of_not_dvd padicValInt.eq_zero_of_not_dvdₓ'. -/\ntheorem eq_zero_of_not_dvd {z : ℤ} (h : ¬(p : ℤ) ∣ z) : padicValInt p z = 0 :=\n  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#print padicValRat /-\n/-- `padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the\nvaluation of `q.denom`. If `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to `0`. -/\ndef padicValRat (p : ℕ) (q : ℚ) : ℤ :=\n  padicValInt p q.num - padicValNat p q.den\n#align padic_val_rat padicValRat\n-/\n\nnamespace padicValRat\n\nopen multiplicity\n\nvariable {p : ℕ}\n\n#print padicValRat.neg /-\n/-- `padic_val_rat p q` is symmetric in `q`. -/\n@[simp]\nprotected theorem neg (q : ℚ) : padicValRat p (-q) = padicValRat p q := by\n  simp [padicValRat, padicValInt]\n#align padic_val_rat.neg padicValRat.neg\n-/\n\n#print padicValRat.zero /-\n/-- `padic_val_rat 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\n#print padicValRat.one /-\n/-- `padic_val_rat 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\n#print padicValRat.of_int /-\n/-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic_value as a rational. -/\n@[simp]\ntheorem of_int {z : ℤ} : padicValRat p z = padicValInt p z := by simp [padicValRat]\n#align padic_val_rat.of_int padicValRat.of_int\n-/\n\n/- warning: padic_val_rat.of_int_multiplicity -> padicValRat.of_int_multiplicity is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {z : Int} (hp : Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (hz : Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))), Eq.{1} Int (padicValRat p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) z)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Part.get.{0} Nat (multiplicity.{0} Int Int.monoid (fun (a : Int) (b : Int) => Int.decidableDvd a b) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z) (Iff.mpr (multiplicity.Finite.{0} Int Int.monoid ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z) (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (multiplicity.finite_int_iff ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) z) (And.intro (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) hp hz))))\nbut is expected to have type\n  forall {p : Nat} {z : Int} (hp : Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (hz : Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))), Eq.{1} Int (padicValRat p (Int.cast.{0} Rat Rat.instIntCastRat z)) (Nat.cast.{0} Int instNatCastInt (Part.get.{0} Nat (multiplicity.{0} Int Int.instMonoidInt (fun (a : Int) (b : Int) => Int.decidableDvd a b) (Nat.cast.{0} Int instNatCastInt p) z) (Iff.mpr (multiplicity.Finite.{0} Int Int.instMonoidInt (Nat.cast.{0} Int instNatCastInt p) z) (And (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) (multiplicity.finite_int_iff (Nat.cast.{0} Int instNatCastInt p) z) (And.intro (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int z (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) hp hz))))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.of_int_multiplicity padicValRat.of_int_multiplicityₓ'. -/\n/-- The `p`-adic value of an integer `z ≠ 0` is the multiplicity of `p` in `z`. -/\ntheorem of_int_multiplicity {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) :\n    padicValRat p (z : ℚ) = (multiplicity (p : ℤ) z).get (finite_int_iff.2 ⟨hp, hz⟩) := 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\n/- warning: padic_val_rat.multiplicity_sub_multiplicity -> padicValRat.multiplicity_sub_multiplicity is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {q : Rat} (hp : Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (hq : Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))), Eq.{1} Int (padicValRat p q) (HSub.hSub.{0, 0, 0} Int Int Int (instHSub.{0} Int Int.hasSub) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Part.get.{0} Nat (multiplicity.{0} Int Int.monoid (fun (a : Int) (b : Int) => Int.decidableDvd a b) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) (Rat.num q)) (Iff.mpr (multiplicity.Finite.{0} Int Int.monoid ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) (Rat.num q)) (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int (Rat.num q) (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (multiplicity.finite_int_iff ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) (Rat.num q)) (And.intro (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int (Rat.num q) (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) hp (Rat.num_ne_zero_of_ne_zero q hq))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Part.get.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q)) (Eq.mpr.{0} (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q))) (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q))) (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q))) (Eq.ndrec.{0, 1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q))) (fun (_a : Prop) => Eq.{1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q))) _a) (rfl.{1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q)))) (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (Eq.symm.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q))) (propext (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q))) (multiplicity.finite_iff_dom.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Rat.den q)))))) (Eq.mpr.{0} (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Rat.den q))) (id_tag Tactic.IdTag.rw (Eq.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Rat.den q)))) (Eq.ndrec.{0, 1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (fun (_a : Prop) => Eq.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) _a) (rfl.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q))) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Rat.den q))) (propext (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Rat.den q))) (multiplicity.finite_nat_iff p (Rat.den q))))) (And.intro (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) (Rat.den q)) hp (Rat.pos q)))))))\nbut is expected to have type\n  forall {p : Nat} {q : Rat} (hp : Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (hq : Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))), Eq.{1} Int (padicValRat p q) (HSub.hSub.{0, 0, 0} Int Int Int (instHSub.{0} Int Int.instSubInt) (Nat.cast.{0} Int instNatCastInt (Part.get.{0} Nat (multiplicity.{0} Int Int.instMonoidInt (fun (a : Int) (b : Int) => Int.decidableDvd a b) (Nat.cast.{0} Int instNatCastInt p) (Rat.num q)) (Iff.mpr (multiplicity.Finite.{0} Int Int.instMonoidInt (Nat.cast.{0} Int instNatCastInt p) (Rat.num q)) (And (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int (Rat.num q) (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) (multiplicity.finite_int_iff (Nat.cast.{0} Int instNatCastInt p) (Rat.num q)) (And.intro (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int (Rat.num q) (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) hp (Rat.num_ne_zero_of_ne_zero q hq))))) (Nat.cast.{0} Int instNatCastInt (Part.get.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q)) (Eq.mpr.{0} (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q))) (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (id.{0} (Eq.{1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q))) (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q))) (Eq.ndrec.{0, 1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q))) (fun (_a : Prop) => Eq.{1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q))) _a) (Eq.refl.{1} Prop (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q)))) (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (Eq.symm.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q))) (propext (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (Part.Dom.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q))) (multiplicity.finite_iff_dom.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Rat.den q)))))) (Eq.mpr.{0} (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Rat.den q))) (id.{0} (Eq.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Rat.den q)))) (Eq.ndrec.{0, 1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (fun (_a : Prop) => Eq.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) _a) (Eq.refl.{1} Prop (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q))) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Rat.den q))) (propext (multiplicity.Finite.{0} Nat Nat.monoid p (Rat.den q)) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Rat.den q))) (multiplicity.finite_nat_iff p (Rat.den q))))) (And.intro (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) (Rat.den q)) hp (Rat.pos q)))))))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.multiplicity_sub_multiplicity padicValRat.multiplicity_sub_multiplicityₓ'. -/\ntheorem multiplicity_sub_multiplicity {q : ℚ} (hp : p ≠ 1) (hq : q ≠ 0) :\n    padicValRat p q =\n      (multiplicity (p : ℤ) q.num).get (finite_int_iff.2 ⟨hp, Rat.num_ne_zero_of_ne_zero hq⟩) -\n        (multiplicity p q.den).get\n          (by\n            rw [← finite_iff_dom, finite_nat_iff]\n            exact ⟨hp, q.pos⟩) :=\n  by\n  rw [padicValRat, padicValInt.of_ne_one_ne_zero hp, padicValNat, dif_pos]\n  · rfl\n  · exact ⟨hp, q.pos⟩\n  · exact Rat.num_ne_zero_of_ne_zero hq\n#align padic_val_rat.multiplicity_sub_multiplicity padicValRat.multiplicity_sub_multiplicity\n\n/- warning: padic_val_rat.of_nat -> padicValRat.of_nat is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat}, Eq.{1} Int (padicValRat p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (padicValNat p n))\nbut is expected to have type\n  forall {p : Nat} {n : Nat}, Eq.{1} Int (padicValRat p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.instLinearOrderedRingRat)))) n)) (Nat.cast.{0} Int instNatCastInt (padicValNat p n))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.of_nat padicValRat.of_natₓ'. -/\n/-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic value as a rational. -/\n@[simp]\ntheorem of_nat {n : ℕ} : padicValRat p n = padicValNat p n := by simp [padicValRat]\n#align padic_val_rat.of_nat padicValRat.of_nat\n\n/- warning: padic_val_rat.self -> padicValRat.self is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) p) -> (Eq.{1} Int (padicValRat p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p)) (OfNat.ofNat.{0} Int 1 (OfNat.mk.{0} Int 1 (One.one.{0} Int Int.hasOne))))\nbut is expected to have type\n  forall {p : Nat}, (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) p) -> (Eq.{1} Int (padicValRat p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.instLinearOrderedRingRat)))) p)) (OfNat.ofNat.{0} Int 1 (instOfNatInt 1)))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.self padicValRat.selfₓ'. -/\n/-- If `p ≠ 0` and `p ≠ 1`, then `padic_val_rat 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 : ℕ}\n\n/- warning: zero_le_padic_val_rat_of_nat -> zero_le_padicValRat_of_nat is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} (n : Nat), LE.le.{0} Int Int.hasLe (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) (padicValRat p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) n))\nbut is expected to have type\n  forall {p : Nat} (n : Nat), LE.le.{0} Int Int.instLEInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) (padicValRat p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.instLinearOrderedRingRat)))) n))\nCase conversion may be inaccurate. Consider using '#align zero_le_padic_val_rat_of_nat zero_le_padicValRat_of_natₓ'. -/\ntheorem zero_le_padicValRat_of_nat (n : ℕ) : 0 ≤ padicValRat p n := by simp\n#align zero_le_padic_val_rat_of_nat zero_le_padicValRat_of_nat\n\n/- warning: padic_val_rat_of_nat -> padicValRat_of_nat is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} (n : Nat), Eq.{1} Int ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (padicValNat p n)) (padicValRat p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) n))\nbut is expected to have type\n  forall {p : Nat} (n : Nat), Eq.{1} Int (Nat.cast.{0} Int instNatCastInt (padicValNat p n)) (padicValRat p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.instLinearOrderedRingRat)))) n))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat_of_nat padicValRat_of_natₓ'. -/\n/-- `padic_val_rat` coincides with `padic_val_nat`. -/\n@[norm_cast]\ntheorem padicValRat_of_nat (n : ℕ) : ↑(padicValNat p n) = padicValRat p n := by simp\n#align padic_val_rat_of_nat padicValRat_of_nat\n\n/- warning: padic_val_nat_def -> padicValNat_def is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {n : Nat} (hn : 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} Nat (padicValNat p n) (Part.get.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p n) (Iff.mpr (multiplicity.Finite.{0} Nat Nat.monoid p n) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n)) (multiplicity.finite_nat_iff p n) (And.intro (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) (Nat.Prime.ne_one p (Fact.out (Nat.Prime p) hp)) hn)))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {n : Nat} (hn : LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n), Eq.{1} Nat (padicValNat p n) (Part.get.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p n) (Iff.mpr (multiplicity.Finite.{0} Nat Nat.monoid p n) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n)) (multiplicity.finite_nat_iff p n) (And.intro (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) (Nat.Prime.ne_one p (Fact.out (Nat.Prime p) hp)) hn)))\nCase conversion may be inaccurate. Consider using '#align padic_val_nat_def padicValNat_defₓ'. -/\n/-- A simplification of `padic_val_nat` when one input is prime, by analogy with\n`padic_val_rat_def`. -/\ntheorem padicValNat_def [hp : Fact p.Prime] {n : ℕ} (hn : 0 < n) :\n    padicValNat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨hp.out.ne_one, hn⟩) :=\n  dif_pos ⟨hp.out.ne_one, hn⟩\n#align padic_val_nat_def padicValNat_def\n\n/- warning: padic_val_nat_def' -> padicValNat_def' is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat}, (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) -> (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} PartENat ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) (padicValNat p n)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p n))\nbut is expected to have type\n  forall {p : Nat} {n : Nat}, (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) -> (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) -> (Eq.{1} PartENat (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) (padicValNat p n)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p n))\nCase conversion may be inaccurate. Consider using '#align padic_val_nat_def' padicValNat_def'ₓ'. -/\ntheorem padicValNat_def' {n : ℕ} (hp : p ≠ 1) (hn : 0 < n) :\n    ↑(padicValNat p n) = multiplicity p n := by simp [padicValNat, hp, hn]\n#align padic_val_nat_def' padicValNat_def'\n\n#print padicValNat_self /-\n@[simp]\ntheorem padicValNat_self [Fact p.Prime] : padicValNat p p = 1 := by\n  simp [padicValNat_def (Fact.out p.prime).Pos]\n#align padic_val_nat_self padicValNat_self\n-/\n\n#print one_le_padicValNat_of_dvd /-\ntheorem one_le_padicValNat_of_dvd {n : ℕ} [hp : Fact p.Prime] (hn : 0 < n) (div : p ∣ n) :\n    1 ≤ padicValNat p n := by\n  rwa [← PartENat.coe_le_coe, padicValNat_def' hp.out.ne_one hn, ← pow_dvd_iff_le_multiplicity,\n    pow_one]\n#align one_le_padic_val_nat_of_dvd one_le_padicValNat_of_dvd\n-/\n\n#print dvd_iff_padicValNat_ne_zero /-\ntheorem dvd_iff_padicValNat_ne_zero {p n : ℕ} [Fact p.Prime] (hn0 : n ≠ 0) :\n    p ∣ n ↔ padicValNat p n ≠ 0 :=\n  ⟨fun 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)⟩\n#align dvd_iff_padic_val_nat_ne_zero dvd_iff_padicValNat_ne_zero\n-/\n\nend padicValNat\n\nnamespace padicValRat\n\nopen multiplicity\n\nvariable {p : ℕ} [hp : Fact p.Prime]\n\ninclude hp\n\n/- warning: padic_val_rat.finite_int_prime_iff -> padicValRat.finite_int_prime_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {a : Int}, Iff (multiplicity.Finite.{0} Int Int.monoid ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) a) (Ne.{1} Int a (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {a : Int}, Iff (multiplicity.Finite.{0} Int Int.instMonoidInt (Nat.cast.{0} Int instNatCastInt p) a) (Ne.{1} Int a (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.finite_int_prime_iff padicValRat.finite_int_prime_iffₓ'. -/\n/-- The multiplicity of `p : ℕ` in `a : ℤ` is finite exactly when `a ≠ 0`. -/\ntheorem finite_int_prime_iff {a : ℤ} : Finite (p : ℤ) a ↔ a ≠ 0 := by\n  simp [finite_int_iff, Ne.symm (ne_of_lt hp.1.one_lt)]\n#align padic_val_rat.finite_int_prime_iff padicValRat.finite_int_prime_iff\n\n/- warning: padic_val_rat.defn -> padicValRat.defn is a dubious translation:\nlean 3 declaration is\n  forall (p : Nat) [hp : Fact (Nat.Prime p)] {q : Rat} {n : Int} {d : Int} (hqz : Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) (qdf : Eq.{1} Rat q (Rat.mk n d)), Eq.{1} Int (padicValRat p q) (HSub.hSub.{0, 0, 0} Int Int Int (instHSub.{0} Int Int.hasSub) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Part.get.{0} Nat (multiplicity.{0} Int Int.monoid (fun (a : Int) (b : Int) => Int.decidableDvd a b) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) n) (Iff.mpr (multiplicity.Finite.{0} Int Int.monoid ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) n) (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (multiplicity.finite_int_iff ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) n) (And.intro (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (Ne.symm.{1} Nat (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (ne_of_lt.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (Nat.Prime.one_lt p (Fact.out (Nat.Prime p) hp)))) (fun (hn : Eq.{1} Int n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) => False.ndrec.{0} False (Eq.mp.{0} (Eq.{1} Rat q (Rat.mk n d)) False (Eq.trans.{1} Prop (Eq.{1} Rat q (Rat.mk n d)) (Eq.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) False ((fun (a : Rat) (a_1 : Rat) (e_1 : Eq.{1} Rat a a_1) (ᾰ : Rat) (ᾰ_1 : Rat) (e_2 : Eq.{1} Rat ᾰ ᾰ_1) => congr.{1, 1} Rat Prop (Eq.{1} Rat a) (Eq.{1} Rat a_1) ᾰ ᾰ_1 (congr_arg.{1, 1} Rat (Rat -> Prop) a a_1 (Eq.{1} Rat) e_1) e_2) q q (rfl.{1} Rat q) (Rat.mk n d) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) (Eq.trans.{1} Rat (Rat.mk n d) (Rat.mk (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) d) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) ((fun (ᾰ : Int) (ᾰ_1 : Int) (e_1 : Eq.{1} Int ᾰ ᾰ_1) (ᾰ_2 : Int) (ᾰ_3 : Int) (e_2 : Eq.{1} Int ᾰ_2 ᾰ_3) => congr.{1, 1} Int Rat (Rat.mk ᾰ) (Rat.mk ᾰ_1) ᾰ_2 ᾰ_3 (congr_arg.{1, 1} Int (Int -> Rat) ᾰ ᾰ_1 Rat.mk e_1) e_2) n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) hn d d (rfl.{1} Int d)) (Rat.zero_divInt d))) (propext (Eq.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) False (iff_false_intro (Eq.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) hqz))) qdf)))))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (Part.get.{0} Nat (multiplicity.{0} Int Int.monoid (fun (a : Int) (b : Int) => Int.decidableDvd a b) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) d) (Iff.mpr (multiplicity.Finite.{0} Int Int.monoid ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) d) (And (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))))) (multiplicity.finite_int_iff ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) d) (And.intro (Ne.{1} Nat (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (Ne.symm.{1} Nat (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (ne_of_lt.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Int.natAbs ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p)) (Nat.Prime.one_lt p (Fact.out (Nat.Prime p) hp)))) (fun (hd : Eq.{1} Int d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) => False.ndrec.{0} False (Eq.mp.{0} (Eq.{1} Rat q (Rat.mk n d)) False (Eq.trans.{1} Prop (Eq.{1} Rat q (Rat.mk n d)) (Eq.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) False ((fun (a : Rat) (a_1 : Rat) (e_1 : Eq.{1} Rat a a_1) (ᾰ : Rat) (ᾰ_1 : Rat) (e_2 : Eq.{1} Rat ᾰ ᾰ_1) => congr.{1, 1} Rat Prop (Eq.{1} Rat a) (Eq.{1} Rat a_1) ᾰ ᾰ_1 (congr_arg.{1, 1} Rat (Rat -> Prop) a a_1 (Eq.{1} Rat) e_1) e_2) q q (rfl.{1} Rat q) (Rat.mk n d) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) (Eq.trans.{1} Rat (Rat.mk n d) (Rat.mk n (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) ((fun (ᾰ : Int) (ᾰ_1 : Int) (e_1 : Eq.{1} Int ᾰ ᾰ_1) (ᾰ_2 : Int) (ᾰ_3 : Int) (e_2 : Eq.{1} Int ᾰ_2 ᾰ_3) => congr.{1, 1} Int Rat (Rat.mk ᾰ) (Rat.mk ᾰ_1) ᾰ_2 ᾰ_3 (congr_arg.{1, 1} Int (Int -> Rat) ᾰ ᾰ_1 Rat.mk e_1) e_2) n n (rfl.{1} Int n) d (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero))) hd) (Rat.divInt_zero n))) (propext (Eq.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) False (iff_false_intro (Eq.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) hqz))) qdf)))))))\nbut is expected to have type\n  forall (p : Nat) [hp : Fact (Nat.Prime p)] {q : Rat} {n : Int} {d : Int} (hqz : Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (qdf : Eq.{1} Rat q (Rat.divInt n d)), Eq.{1} Int (padicValRat p q) (HSub.hSub.{0, 0, 0} Int Int Int (instHSub.{0} Int Int.instSubInt) (Nat.cast.{0} Int instNatCastInt (Part.get.{0} Nat (multiplicity.{0} Int Int.instMonoidInt (fun (a : Int) (b : Int) => Int.decidableDvd a b) (Nat.cast.{0} Int instNatCastInt p) n) (Iff.mpr (multiplicity.Finite.{0} Int Int.instMonoidInt (Nat.cast.{0} Int instNatCastInt p) n) (And (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) (multiplicity.finite_int_iff (Nat.cast.{0} Int instNatCastInt p) n) (And.intro (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (Nat.Prime.ne_one p (Fact.out (Nat.Prime p) hp)) (fun (hn : Eq.{1} Int n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) => False.elim.{0} False (Eq.mp.{0} (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) False (Eq.trans.{1} Prop (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (Ne.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) False (congrFun.{1, 1} Rat (fun (b : Rat) => Prop) (Ne.{1} Rat q) (Ne.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (congrArg.{1, 1} Rat (Rat -> Prop) q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (Ne.{1} Rat) (Eq.trans.{1} Rat q (Rat.divInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) d) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (Eq.trans.{1} Rat q (Rat.divInt n d) (Rat.divInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) d) qdf (congrFun.{1, 1} Int (fun (a._@.Std.Data.Rat.Basic._hyg.923 : Int) => Rat) (Rat.divInt n) (Rat.divInt (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (congrArg.{1, 1} Int (Int -> Rat) n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) Rat.divInt hn) d)) (Rat.zero_divInt d))) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (eq_false_of_decide (Not (Eq.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)))) (instDecidableNot (Eq.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (instDecidableEqRat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)))) (Eq.refl.{1} Bool Bool.false))) hqz)))))) (Nat.cast.{0} Int instNatCastInt (Part.get.{0} Nat (multiplicity.{0} Int Int.instMonoidInt (fun (a : Int) (b : Int) => Int.decidableDvd a b) (Nat.cast.{0} Int instNatCastInt p) d) (Iff.mpr (multiplicity.Finite.{0} Int Int.instMonoidInt (Nat.cast.{0} Int instNatCastInt p) d) (And (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)))) (multiplicity.finite_int_iff (Nat.cast.{0} Int instNatCastInt p) d) (And.intro (Ne.{1} Nat (Int.natAbs (Nat.cast.{0} Int instNatCastInt p)) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Ne.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (Nat.Prime.ne_one p (Fact.out (Nat.Prime p) hp)) (fun (hd : Eq.{1} Int d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) => False.elim.{0} False (Eq.mp.{0} (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) False (Eq.trans.{1} Prop (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (Ne.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) False (congrFun.{1, 1} Rat (fun (b : Rat) => Prop) (Ne.{1} Rat q) (Ne.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (congrArg.{1, 1} Rat (Rat -> Prop) q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (Ne.{1} Rat) (Eq.trans.{1} Rat q (Rat.divInt n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (Eq.trans.{1} Rat q (Rat.divInt n d) (Rat.divInt n (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) qdf (congrArg.{1, 1} Int Rat d (OfNat.ofNat.{0} Int 0 (instOfNatInt 0)) (Rat.divInt n) hd)) (Rat.divInt_zero n))) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (eq_false_of_decide (Not (Eq.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)))) (instDecidableNot (Eq.{1} Rat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) (instDecidableEqRat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)))) (Eq.refl.{1} Bool Bool.false))) hqz)))))))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.defn padicValRat.defnₓ'. -/\n/-- A rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`. -/\nprotected theorem defn (p : ℕ) [hp : Fact p.Prime] {q : ℚ} {n d : ℤ} (hqz : q ≠ 0)\n    (qdf : q = n /. d) :\n    padicValRat p q =\n      (multiplicity (p : ℤ) n).get\n          (finite_int_iff.2 ⟨Ne.symm <| ne_of_lt hp.1.one_lt, fun hn => by simp_all⟩) -\n        (multiplicity (p : ℤ) d).get\n          (finite_int_iff.2 ⟨Ne.symm <| ne_of_lt hp.1.one_lt, fun hd => by simp_all⟩) :=\n  by\n  have hd : d ≠ 0 := Rat.mk_denom_ne_zero_of_ne_zero hqz qdf\n  let ⟨c, hc1, hc2⟩ := Rat.num_den_mk hd qdf\n  rw [padicValRat.multiplicity_sub_multiplicity] <;>\n    simp [hc1, hc2, multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),\n      Ne.symm (ne_of_lt hp.1.one_lt), hqz, pos_iff_ne_zero, int.coe_nat_multiplicity p q.denom]\n#align padic_val_rat.defn padicValRat.defn\n\n#print padicValRat.mul /-\n/-- A rewrite lemma for `padic_val_rat p (q * r)` with conditions `q ≠ 0`, `r ≠ 0`. -/\nprotected theorem mul {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :\n    padicValRat p (q * r) = padicValRat p q + padicValRat p r :=\n  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 ≠ 0 := by rw [Rat.num_den] <;> exact hq\n  have hr' : r.num /. r.den ≠ 0 := by rw [Rat.num_den] <;> exact hr\n  have hp' : Prime (p : ℤ) := Nat.prime_iff_prime_int.1 hp.1\n  rw [padicValRat.defn p (mul_ne_zero hq hr) this]\n  conv_rhs =>\n    rw [← @Rat.num_den q, padicValRat.defn p hq', ← @Rat.num_den r, padicValRat.defn p hr']\n  rw [multiplicity.mul' hp', multiplicity.mul' hp'] <;>\n    simp [add_comm, add_left_comm, sub_eq_add_neg]\n#align padic_val_rat.mul padicValRat.mul\n-/\n\n#print padicValRat.pow /-\n/-- A rewrite lemma for `padic_val_rat p (q^k)` with condition `q ≠ 0`. -/\nprotected theorem pow {q : ℚ} (hq : q ≠ 0) {k : ℕ} : padicValRat p (q ^ k) = k * padicValRat p q :=\n  by induction k <;> simp [*, padicValRat.mul hq (pow_ne_zero _ hq), pow_succ, add_mul, add_comm]\n#align padic_val_rat.pow padicValRat.pow\n-/\n\n#print padicValRat.inv /-\n/-- A rewrite lemma for `padic_val_rat p (q⁻¹)` with condition `q ≠ 0`. -/\nprotected theorem inv (q : ℚ) : padicValRat p q⁻¹ = -padicValRat p q :=\n  by\n  by_cases hq : q = 0\n  · simp [hq]\n  · rw [eq_neg_iff_add_eq_zero, ← padicValRat.mul (inv_ne_zero hq) hq, inv_mul_cancel hq,\n      padicValRat.one]\n    exact hp\n#align padic_val_rat.inv padicValRat.inv\n-/\n\n#print padicValRat.div /-\n/-- A rewrite lemma for `padic_val_rat p (q / r)` with conditions `q ≠ 0`, `r ≠ 0`. -/\nprotected theorem div {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :\n    padicValRat p (q / r) = padicValRat p q - padicValRat p r :=\n  by\n  rw [div_eq_mul_inv, padicValRat.mul hq (inv_ne_zero hr), padicValRat.inv r, sub_eq_add_neg]\n  all_goals exact hp\n#align padic_val_rat.div padicValRat.div\n-/\n\n/- warning: padic_val_rat.padic_val_rat_le_padic_val_rat_iff -> padicValRat.padicValRat_le_padicValRat_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {n₁ : Int} {n₂ : Int} {d₁ : Int} {d₂ : Int}, (Ne.{1} Int n₁ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int n₂ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) -> (Iff (LE.le.{0} Int Int.hasLe (padicValRat p (Rat.mk n₁ d₁)) (padicValRat p (Rat.mk n₂ d₂))) (forall (n : Nat), (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) (HPow.hPow.{0, 0, 0} Int Nat Int (instHPow.{0, 0} Int Nat (Monoid.Pow.{0} Int Int.monoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) n) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n₁ d₂)) -> (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) (HPow.hPow.{0, 0, 0} Int Nat Int (instHPow.{0, 0} Int Nat (Monoid.Pow.{0} Int Int.monoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) n) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.hasMul) n₂ d₁))))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {n₁ : Int} {n₂ : Int} {d₁ : Int} {d₂ : Int}, (Ne.{1} Int n₁ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int n₂ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d₁ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Ne.{1} Int d₂ (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) -> (Iff (LE.le.{0} Int Int.instLEInt (padicValRat p (Rat.divInt n₁ d₁)) (padicValRat p (Rat.divInt n₂ d₂))) (forall (n : Nat), (Dvd.dvd.{0} Int Int.instDvdInt (HPow.hPow.{0, 0, 0} Int Nat Int Int.instHPowIntNat (Nat.cast.{0} Int instNatCastInt p) n) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₁ d₂)) -> (Dvd.dvd.{0} Int Int.instDvdInt (HPow.hPow.{0, 0, 0} Int Nat Int Int.instHPowIntNat (Nat.cast.{0} Int instNatCastInt p) n) (HMul.hMul.{0, 0, 0} Int Int Int (instHMul.{0} Int Int.instMulInt) n₂ d₁))))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.padic_val_rat_le_padic_val_rat_iff padicValRat.padicValRat_le_padicValRat_iffₓ'. -/\n/-- A condition for `padic_val_rat p (n₁ / d₁) ≤ padic_val_rat p (n₂ / d₂)`, in terms of\ndivisibility by `p^n`. -/\ntheorem padicValRat_le_padicValRat_iff {n₁ n₂ d₁ d₂ : ℤ} (hn₁ : n₁ ≠ 0) (hn₂ : n₂ ≠ 0)\n    (hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) :\n    padicValRat p (n₁ /. d₁) ≤ padicValRat p (n₂ /. d₂) ↔\n      ∀ n : ℕ, ↑p ^ n ∣ n₁ * d₂ → ↑p ^ n ∣ n₂ * d₁ :=\n  by\n  have hf1 : Finite (p : ℤ) (n₁ * d₂) := finite_int_prime_iff.2 (mul_ne_zero hn₁ hd₂)\n  have hf2 : Finite (p : ℤ) (n₂ * d₁) := finite_int_prime_iff.2 (mul_ne_zero hn₂ hd₁)\n  conv =>\n    lhs\n    rw [padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn₁ hd₁) rfl,\n      padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn₂ hd₂) rfl, sub_le_iff_le_add', ←\n      add_sub_assoc, le_sub_iff_add_le]\n    norm_cast\n    rw [← multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf1, add_comm, ←\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#print padicValRat.le_padicValRat_add_of_le /-\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 : ℚ} (hqr : q + r ≠ 0)\n    (h : padicValRat p q ≤ padicValRat p r) : padicValRat p q ≤ 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 ≠ 0 := Rat.num_ne_zero_of_ne_zero hq\n      have hqd : (q.den : ℤ) ≠ 0 := by exact_mod_cast Rat.den_nz _\n      have hrn : r.num ≠ 0 := Rat.num_ne_zero_of_ne_zero hr\n      have hrd : (r.den : ℤ) ≠ 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 ≠ 0 := Rat.mk_num_ne_zero_of_ne_zero hqr hqreq\n      conv_lhs => rw [← @Rat.num_den q]\n      rw [hqreq, padic_val_rat_le_padic_val_rat_iff hqn hqrd hqd (mul_ne_zero hqd hrd), ←\n        multiplicity_le_multiplicity_iff, mul_left_comm,\n        multiplicity.mul (Nat.prime_iff_prime_int.1 hp.1), add_mul]\n      rw [← @Rat.num_den q, ← @Rat.num_den r, padic_val_rat_le_padic_val_rat_iff hqn hrn hqd hrd, ←\n        multiplicity_le_multiplicity_iff] at h\n      calc\n        _ ≤\n            min (multiplicity (↑p) (q.num * ↑r.denom * ↑q.denom))\n              (multiplicity (↑p) (↑q.denom * r.num * ↑q.denom)) :=\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.denom : ℤ) (_ * _)\n                    (Nat.prime_iff_prime_int.1 hp.1)] <;>\n                exact add_le_add_left h _)\n        _ ≤ _ := min_le_multiplicity_add\n        \n      all_goals exact hp\n#align padic_val_rat.le_padic_val_rat_add_of_le padicValRat.le_padicValRat_add_of_le\n-/\n\n/- warning: padic_val_rat.min_le_padic_val_rat_add -> padicValRat.min_le_padicValRat_add is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, (Ne.{1} Rat (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) q r) (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) -> (LE.le.{0} Int Int.hasLe (LinearOrder.min.{0} Int Int.linearOrder (padicValRat p q) (padicValRat p r)) (padicValRat p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) q r)))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, (Ne.{1} Rat (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) q r) (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) -> (LE.le.{0} Int Int.instLEInt (Min.min.{0} Int Int.instMinInt (padicValRat p q) (padicValRat p r)) (padicValRat p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) q r)))\nCase conversion may be inaccurate. Consider using '#align padic_val_rat.min_le_padic_val_rat_add padicValRat.min_le_padicValRat_addₓ'. -/\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 : ℚ} (hqr : q + r ≠ 0) :\n    min (padicValRat p q) (padicValRat p r) ≤ 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_padic_val_rat_add_of_le hqr h) fun h => by\n    rw [min_eq_right h, add_comm] <;> exact le_padic_val_rat_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#print padicValRat.sum_pos_of_pos /-\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 : ℕ} {F : ℕ → ℚ} (hF : ∀ i, i < n → 0 < padicValRat p (F i))\n    (hn0 : (∑ i in Finset.range n, F i) ≠ 0) : 0 < padicValRat p (∑ i in Finset.range n, F i) :=\n  by\n  induction' n with d hd\n  · exact False.elim (hn0 rfl)\n  · rw [Finset.sum_range_succ] at hn0⊢\n    by_cases h : (∑ x : ℕ 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 hn0)\n      · 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-/\n\nend padicValRat\n\nnamespace padicValNat\n\nvariable {p a b : ℕ} [hp : Fact p.Prime]\n\ninclude hp\n\n#print padicValNat.mul /-\n/-- A rewrite lemma for `padic_val_nat p (a * b)` with conditions `a ≠ 0`, `b ≠ 0`. -/\nprotected theorem mul : a ≠ 0 → b ≠ 0 → 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-/\n\n#print padicValNat.div_of_dvd /-\nprotected theorem div_of_dvd (h : b ∣ a) :\n    padicValNat p (a / b) = padicValNat p a - padicValNat p b :=\n  by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  · simp\n  obtain ⟨k, rfl⟩ := h\n  obtain ⟨hb, hk⟩ := 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  exact hp\n#align padic_val_nat.div_of_dvd padicValNat.div_of_dvd\n-/\n\n#print padicValNat.div /-\n/-- Dividing out by a prime factor reduces the `padic_val_nat` by `1`. -/\nprotected theorem div (dvd : p ∣ b) : padicValNat p (b / p) = padicValNat p b - 1 :=\n  by\n  convert padicValNat.div_of_dvd dvd\n  rw [padicValNat_self]\n  exact hp\n#align padic_val_nat.div padicValNat.div\n-/\n\n#print padicValNat.pow /-\n/-- A version of `padic_val_rat.pow` for `padic_val_nat`. -/\nprotected theorem pow (n : ℕ) (ha : a ≠ 0) : padicValNat p (a ^ n) = n * padicValNat p a := by\n  simpa only [← @Nat.cast_inj ℤ, push_cast] using padicValRat.pow (cast_ne_zero.mpr ha)\n#align padic_val_nat.pow padicValNat.pow\n-/\n\n#print padicValNat.prime_pow /-\n@[simp]\nprotected theorem prime_pow (n : ℕ) : padicValNat p (p ^ n) = n := by\n  rwa [padicValNat.pow _ (Fact.out p.prime).NeZero, padicValNat_self, mul_one]\n#align padic_val_nat.prime_pow padicValNat.prime_pow\n-/\n\n#print padicValNat.div_pow /-\nprotected theorem div_pow (dvd : p ^ a ∣ b) : padicValNat p (b / p ^ a) = padicValNat p b - a :=\n  by\n  rw [padicValNat.div_of_dvd dvd, padicValNat.prime_pow]\n  exact hp\n#align padic_val_nat.div_pow padicValNat.div_pow\n-/\n\n#print padicValNat.div' /-\nprotected theorem div' {m : ℕ} (cpm : coprime p m) {b : ℕ} (dvd : m ∣ 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    assumption\n#align padic_val_nat.div' padicValNat.div'\n-/\n\nend padicValNat\n\nsection padicValNat\n\nvariable {p : ℕ}\n\n#print dvd_of_one_le_padicValNat /-\ntheorem dvd_of_one_le_padicValNat {n : ℕ} (hp : 1 ≤ padicValNat p n) : p ∣ n :=\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-/\n\n#print pow_padicValNat_dvd /-\ntheorem pow_padicValNat_dvd {n : ℕ} : p ^ padicValNat p n ∣ n :=\n  by\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, padicValNat_def'] <;> assumption\n#align pow_padic_val_nat_dvd pow_padicValNat_dvd\n-/\n\n#print padicValNat_dvd_iff_le /-\ntheorem padicValNat_dvd_iff_le [hp : Fact p.Prime] {a n : ℕ} (ha : a ≠ 0) :\n    p ^ n ∣ a ↔ n ≤ padicValNat p a := by\n  rw [pow_dvd_iff_le_multiplicity, ← 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-/\n\n#print padicValNat_dvd_iff /-\ntheorem padicValNat_dvd_iff (n : ℕ) [hp : Fact p.Prime] (a : ℕ) :\n    p ^ n ∣ a ↔ a = 0 ∨ n ≤ padicValNat p a :=\n  by\n  rcases eq_or_ne a 0 with (rfl | ha)\n  · exact iff_of_true (dvd_zero _) (Or.inl rfl)\n  · simp only [ha, false_or_iff, padicValNat_dvd_iff_le ha]\n#align padic_val_nat_dvd_iff padicValNat_dvd_iff\n-/\n\n#print pow_succ_padicValNat_not_dvd /-\ntheorem pow_succ_padicValNat_not_dvd {n : ℕ} [hp : Fact p.Prime] (hn : n ≠ 0) :\n    ¬p ^ (padicValNat p n + 1) ∣ n :=\n  by\n  rw [padicValNat_dvd_iff_le hn, not_le]\n  exacts[Nat.lt_succ_self _, hp]\n#align pow_succ_padic_val_nat_not_dvd pow_succ_padicValNat_not_dvd\n-/\n\n#print padicValNat_primes /-\ntheorem padicValNat_primes {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime] (neq : p ≠ 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-/\n\nopen BigOperators\n\n/- warning: range_pow_padic_val_nat_subset_divisors -> range_pow_padicValNat_subset_divisors is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (HasSubset.Subset.{0} (Finset.{0} Nat) (Finset.hasSubset.{0} Nat) (Finset.image.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p) (Finset.range (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (padicValNat p n) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))) (Nat.divisors n))\nbut is expected to have type\n  forall {p : Nat} {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (HasSubset.Subset.{0} (Finset.{0} Nat) (Finset.instHasSubsetFinset.{0} Nat) (Finset.image.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (fun (x._@.Mathlib.NumberTheory.Padics.PadicVal._hyg.4443 : Nat) => HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p x._@.Mathlib.NumberTheory.Padics.PadicVal._hyg.4443) (Finset.range (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (padicValNat p n) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (Nat.divisors n))\nCase conversion may be inaccurate. Consider using '#align range_pow_padic_val_nat_subset_divisors range_pow_padicValNat_subset_divisorsₓ'. -/\ntheorem range_pow_padicValNat_subset_divisors {n : ℕ} (hn : n ≠ 0) :\n    (Finset.range (padicValNat p n + 1)).image (pow p) ⊆ n.divisors :=\n  by\n  intro t ht\n  simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht\n  obtain ⟨k, hk, rfl⟩ := ht\n  rw [Nat.mem_divisors]\n  exact ⟨(pow_dvd_pow p <| by linarith).trans pow_padicValNat_dvd, hn⟩\n#align range_pow_padic_val_nat_subset_divisors range_pow_padicValNat_subset_divisors\n\n/- warning: range_pow_padic_val_nat_subset_divisors' -> range_pow_padicValNat_subset_divisors' is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat} [hp : Fact (Nat.Prime p)], HasSubset.Subset.{0} (Finset.{0} Nat) (Finset.hasSubset.{0} Nat) (Finset.image.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (fun (t : Nat) => HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) t (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))))) (Finset.range (padicValNat p n))) (Finset.erase.{0} Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (Nat.divisors 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 {p : Nat} {n : Nat} [hp : Fact (Nat.Prime p)], HasSubset.Subset.{0} (Finset.{0} Nat) (Finset.instHasSubsetFinset.{0} Nat) (Finset.image.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (fun (t : Nat) => HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) t (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))) (Finset.range (padicValNat p n))) (Finset.erase.{0} Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (Nat.divisors n) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))\nCase conversion may be inaccurate. Consider using '#align range_pow_padic_val_nat_subset_divisors' range_pow_padicValNat_subset_divisors'ₓ'. -/\ntheorem range_pow_padicValNat_subset_divisors' {n : ℕ} [hp : Fact p.Prime] :\n    ((Finset.range (padicValNat p n)).image fun t => p ^ (t + 1)) ⊆ n.divisors.eraseₓ 1 :=\n  by\n  rcases eq_or_ne n 0 with (rfl | hn)\n  · simp\n  intro t ht\n  simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht\n  obtain ⟨k, hk, rfl⟩ := ht\n  rw [Finset.mem_erase, Nat.mem_divisors]\n  refine' ⟨_, (pow_dvd_pow p <| succ_le_iff.2 hk).trans pow_padicValNat_dvd, hn⟩\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 : ℕ} [hp : Fact p.Prime]\n\ninclude hp\n\n/- warning: padic_val_int_dvd_iff -> padicValInt_dvd_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (n : Nat) (a : Int), Iff (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) (HPow.hPow.{0, 0, 0} Int Nat Int (instHPow.{0, 0} Int Nat (Monoid.Pow.{0} Int Int.monoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) n) a) (Or (Eq.{1} Int a (OfNat.ofNat.{0} Int 0 (OfNat.mk.{0} Int 0 (Zero.zero.{0} Int Int.hasZero)))) (LE.le.{0} Nat Nat.hasLe n (padicValInt p a)))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (n : Nat) (a : Int), Iff (Dvd.dvd.{0} Int Int.instDvdInt (HPow.hPow.{0, 0, 0} Int Nat Int Int.instHPowIntNat (Nat.cast.{0} Int instNatCastInt p) n) a) (Or (Eq.{1} Int a (OfNat.ofNat.{0} Int 0 (instOfNatInt 0))) (LE.le.{0} Nat instLENat n (padicValInt p a)))\nCase conversion may be inaccurate. Consider using '#align padic_val_int_dvd_iff padicValInt_dvd_iffₓ'. -/\ntheorem padicValInt_dvd_iff (n : ℕ) (a : ℤ) : (p : ℤ) ^ n ∣ a ↔ a = 0 ∨ n ≤ padicValInt p a := by\n  rw [padicValInt, ← Int.natAbs_eq_zero, ← padicValNat_dvd_iff, ← Int.coe_nat_dvd_left,\n    Int.coe_nat_pow]\n#align padic_val_int_dvd_iff padicValInt_dvd_iff\n\n/- warning: padic_val_int_dvd -> padicValInt_dvd is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (a : Int), Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) (HPow.hPow.{0, 0, 0} Int Nat Int (instHPow.{0, 0} Int Nat (Monoid.Pow.{0} Int Int.monoid)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) (padicValInt p a)) a\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (a : Int), Dvd.dvd.{0} Int Int.instDvdInt (HPow.hPow.{0, 0, 0} Int Nat Int Int.instHPowIntNat (Nat.cast.{0} Int instNatCastInt p) (padicValInt p a)) a\nCase conversion may be inaccurate. Consider using '#align padic_val_int_dvd padicValInt_dvdₓ'. -/\ntheorem padicValInt_dvd (a : ℤ) : (p : ℤ) ^ padicValInt p a ∣ a :=\n  by\n  rw [padicValInt_dvd_iff]\n  exact Or.inr le_rfl\n#align padic_val_int_dvd padicValInt_dvd\n\n#print padicValInt_self /-\ntheorem padicValInt_self : padicValInt p p = 1 :=\n  padicValInt.self hp.out.one_lt\n#align padic_val_int_self padicValInt_self\n-/\n\n#print padicValInt.mul /-\ntheorem padicValInt.mul {a b : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) :\n    padicValInt p (a * b) = padicValInt p a + padicValInt p b :=\n  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-/\n\n#print padicValInt_mul_eq_succ /-\ntheorem padicValInt_mul_eq_succ (a : ℤ) (ha : a ≠ 0) :\n    padicValInt p (a * p) = padicValInt p a + 1 :=\n  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  exact hp\n#align padic_val_int_mul_eq_succ padicValInt_mul_eq_succ\n-/\n\nend padicValInt\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/Padics/PadicVal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.779983425527928}}
{"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.gcd_monoid.finset\nimport data.polynomial.field_division\nimport data.polynomial.erase_lead\nimport data.polynomial.cancel_leads\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\nnamespace polynomial\nopen_locale polynomial\n\nsection primitive\n\nvariables {R : Type*} [comm_semiring R]\n\n/-- A polynomial is primitive when the only constant polynomials dividing it are units -/\ndef is_primitive (p : R[X]) : Prop :=\n∀ (r : R), C r ∣ p → is_unit r\n\nlemma is_primitive_iff_is_unit_of_C_dvd {p : R[X]} :\n  p.is_primitive ↔ ∀ (r : R), C r ∣ p → is_unit r :=\niff.rfl\n\n@[simp]\nlemma is_primitive_one : is_primitive (1 : R[X]) :=\nλ r h, is_unit_C.mp (is_unit_of_dvd_one (C r) h)\n\nlemma monic.is_primitive {p : R[X]} (hp : p.monic) : p.is_primitive :=\nbegin\n  rintros r ⟨q, h⟩,\n  exact is_unit_of_mul_eq_one r (q.coeff p.nat_degree) (by rwa [←coeff_C_mul, ←h]),\nend\n\nlemma is_primitive.ne_zero [nontrivial R] {p : R[X]} (hp : p.is_primitive) : p ≠ 0 :=\nbegin\n  rintro rfl,\n  exact (hp 0 (dvd_zero (C 0))).ne_zero rfl,\nend\n\nlemma is_primitive_of_dvd {p q : R[X]} (hp : is_primitive p) (hq : q ∣ p) : is_primitive q :=\nλ a ha, is_primitive_iff_is_unit_of_C_dvd.mp hp a (dvd_trans ha hq)\n\nend primitive\n\nvariables {R : Type*} [comm_ring R] [is_domain R]\n\nsection normalized_gcd_monoid\nvariable [normalized_gcd_monoid R]\n\n/-- `p.content` is the `gcd` of the coefficients of `p`. -/\ndef content (p : R[X]) : R := (p.support).gcd p.coeff\n\nlemma content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n :=\nbegin\n  by_cases h : n ∈ p.support,\n  { apply finset.gcd_dvd h },\n  rw [mem_support_iff, not_not] at h,\n  rw h,\n  apply dvd_zero,\nend\n\n@[simp] lemma content_C {r : R} : (C r).content = normalize r :=\nbegin\n  rw content,\n  by_cases h0 : r = 0,\n  { simp [h0] },\n  have h : (C r).support = {0} := support_monomial _ h0,\n  simp [h],\nend\n\n@[simp] lemma content_zero : content (0 : R[X]) = 0 :=\nby rw [← C_0, content_C, normalize_zero]\n\n@[simp] lemma content_one : content (1 : R[X]) = 1 :=\nby rw [← C_1, content_C, normalize_one]\n\nlemma content_X_mul {p : R[X]} : content (X * p) = content p :=\nbegin\n  rw [content, content, finset.gcd_def, finset.gcd_def],\n  refine congr rfl _,\n  have h : (X * p).support = p.support.map ⟨nat.succ, nat.succ_injective⟩,\n  { ext a,\n    simp only [exists_prop, finset.mem_map, function.embedding.coe_fn_mk, ne.def,\n      mem_support_iff],\n    cases a,\n    { simp [coeff_X_mul_zero, nat.succ_ne_zero] },\n    rw [mul_comm, coeff_mul_X],\n    split,\n    { intro h,\n      use a,\n      simp [h] },\n    { rintros ⟨b, ⟨h1, h2⟩⟩,\n      rw ← nat.succ_injective h2,\n      apply h1 } },\n  rw h,\n  simp only [finset.map_val, function.comp_app, function.embedding.coe_fn_mk, multiset.map_map],\n  refine congr (congr rfl _) rfl,\n  ext a,\n  rw mul_comm,\n  simp [coeff_mul_X],\nend\n\n@[simp] lemma content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 :=\nbegin\n  induction k with k hi,\n  { simp },\n  rw [pow_succ, content_X_mul, hi]\nend\n\n@[simp] lemma content_X : content (X : R[X]) = 1 :=\nby { rw [← mul_one X, content_X_mul, content_one] }\n\nlemma content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content :=\nbegin\n  by_cases h0 : r = 0, { simp [h0] },\n  rw content, rw content, rw ← finset.gcd_mul_left,\n  refine congr (congr rfl _) _; ext; simp [h0, mem_support_iff]\nend\n\n@[simp] lemma content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r :=\nby rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one]\n\nlemma content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 :=\nbegin\n  rw [content, finset.gcd_eq_zero_iff],\n  split; intro h,\n  { ext n,\n    by_cases h0 : n ∈ p.support,\n    { rw [h n h0, coeff_zero], },\n    { rw mem_support_iff at h0,\n      push_neg at h0,\n      simp [h0] } },\n  { intros x h0,\n    simp [h] }\nend\n\n@[simp] lemma normalize_content {p : R[X]} : normalize p.content = p.content :=\nfinset.normalize_gcd\n\nlemma content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.nat_degree < n) :\n  p.content = (finset.range n).gcd p.coeff :=\nbegin\n  apply dvd_antisymm_of_normalize_eq normalize_content finset.normalize_gcd,\n  { rw finset.dvd_gcd_iff,\n    intros i hi,\n    apply content_dvd_coeff _ },\n  { 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), }\nend\n\n\n\nlemma content_eq_gcd_leading_coeff_content_erase_lead (p : R[X]) :\n  p.content = gcd_monoid.gcd p.leading_coeff (erase_lead p).content :=\nbegin\n  by_cases h : p = 0,\n  { simp [h] },\n  rw [← leading_coeff_eq_zero, leading_coeff, ← ne.def, ← mem_support_iff] at h,\n  rw [content, ← finset.insert_erase h, finset.gcd_insert, leading_coeff, content,\n    erase_lead_support],\n  refine congr rfl (finset.gcd_congr rfl (λ i hi, _)),\n  rw finset.mem_erase at hi,\n  rw [erase_lead_coeff, if_neg hi.1],\nend\n\nlemma dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p :=\nbegin\n  rw C_dvd_iff_dvd_coeff,\n  split,\n  { intros h i,\n    apply h.trans (content_dvd_coeff _) },\n  { intro h,\n    rw [content, finset.dvd_gcd_iff],\n    intros i hi,\n    apply h i }\nend\n\nlemma C_content_dvd (p : R[X]) : C p.content ∣ p :=\ndvd_content_iff_C_dvd.1 dvd_rfl\n\nlemma is_primitive_iff_content_eq_one {p : R[X]} : p.is_primitive ↔ p.content = 1 :=\nbegin\n  rw [←normalize_content, normalize_eq_one, is_primitive],\n  simp_rw [←dvd_content_iff_C_dvd],\n  exact ⟨λ h, h p.content (dvd_refl p.content), λ h r hdvd, is_unit_of_dvd_unit hdvd h⟩,\nend\n\nlemma is_primitive.content_eq_one {p : R[X]} (hp : p.is_primitive) : p.content = 1 :=\nis_primitive_iff_content_eq_one.mp hp\n\nopen_locale classical\nnoncomputable theory\n\nsection prim_part\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 (p : R[X]) : R[X] :=\nif p = 0 then 1 else classical.some (C_content_dvd p)\n\nlemma eq_C_content_mul_prim_part (p : R[X]) : p = C p.content * p.prim_part :=\nbegin\n  by_cases h : p = 0, { simp [h] },\n  rw [prim_part, if_neg h, ← classical.some_spec (C_content_dvd p)],\nend\n\n@[simp]\nlemma prim_part_zero : prim_part (0 : R[X]) = 1 := if_pos rfl\n\nlemma is_primitive_prim_part (p : R[X]) : p.prim_part.is_primitive :=\nbegin\n  by_cases h : p = 0, { simp [h] },\n  rw ← content_eq_zero_iff at h,\n  rw is_primitive_iff_content_eq_one,\n  apply mul_left_cancel₀ h,\n  conv_rhs { rw [p.eq_C_content_mul_prim_part, mul_one, content_C_mul, normalize_content] }\nend\n\nlemma content_prim_part (p : R[X]) : p.prim_part.content = 1 :=\np.is_primitive_prim_part.content_eq_one\n\nlemma prim_part_ne_zero (p : R[X]) : p.prim_part ≠ 0 := p.is_primitive_prim_part.ne_zero\n\nlemma nat_degree_prim_part (p : R[X]) : p.prim_part.nat_degree = p.nat_degree :=\nbegin\n  by_cases h : C p.content = 0,\n  { rw [C_eq_zero, content_eq_zero_iff] at h, simp [h] },\n  conv_rhs { rw [p.eq_C_content_mul_prim_part,\n    nat_degree_mul h p.prim_part_ne_zero, nat_degree_C, zero_add] },\nend\n\n@[simp]\nlemma is_primitive.prim_part_eq {p : R[X]} (hp : p.is_primitive) : p.prim_part = p :=\nby rw [← one_mul p.prim_part, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_prim_part]\n\nlemma is_unit_prim_part_C (r : R) : is_unit (C r).prim_part :=\nbegin\n  by_cases h0 : r = 0,\n  { simp [h0] },\n  unfold is_unit,\n  refine ⟨⟨C ↑(norm_unit r)⁻¹, C ↑(norm_unit r),\n    by rw [← ring_hom.map_mul, units.inv_mul, C_1],\n    by rw [← ring_hom.map_mul, units.mul_inv, C_1]⟩, _⟩,\n  rw [← normalize_eq_zero, ← C_eq_zero] at h0,\n  apply mul_left_cancel₀ h0,\n  conv_rhs { rw [← content_C, ← (C r).eq_C_content_mul_prim_part], },\n  simp only [units.coe_mk, normalize_apply, ring_hom.map_mul],\n  rw [mul_assoc, ← ring_hom.map_mul, units.mul_inv, C_1, mul_one],\nend\n\nlemma prim_part_dvd (p : R[X]) : p.prim_part ∣ p :=\ndvd.intro_left (C p.content) p.eq_C_content_mul_prim_part.symm\n\nlemma aeval_prim_part_eq_zero {S : Type*} [ring S] [is_domain S] [algebra R S]\n  [no_zero_smul_divisors R S] {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : aeval s p = 0) :\n  aeval s p.prim_part = 0 :=\nbegin\n  rw [eq_C_content_mul_prim_part p, map_mul, aeval_C] at hp,\n  have hcont : p.content ≠ 0 := λ h, hpzero (content_eq_zero_iff.1 h),\n  replace hcont := function.injective.ne (no_zero_smul_divisors.algebra_map_injective R S) hcont,\n  rw [map_zero] at hcont,\n  exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp\nend\n\nlemma eval₂_prim_part_eq_zero {S : Type*} [comm_ring S] [is_domain S] {f : R →+* S}\n  (hinj : function.injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0)\n  (hp : eval₂ f s p = 0) : eval₂ f s p.prim_part = 0 :=\nbegin\n  rw [eq_C_content_mul_prim_part p, eval₂_mul, eval₂_C] at hp,\n  have hcont : p.content ≠ 0 := λ 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\nend\n\nend prim_part\n\nlemma gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) :\n  gcd_monoid.gcd a p.content = gcd_monoid.gcd a q.content :=\nbegin\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  intros x hx,\n  cases h with w hw,\n  use w.coeff x,\n  rw [← coeff_sub, hw, coeff_C_mul]\nend\n\nlemma content_mul_aux {p q : R[X]} :\n  gcd_monoid.gcd (p * q).erase_lead.content p.leading_coeff =\n  gcd_monoid.gcd (p.erase_lead * q).content p.leading_coeff :=\nbegin\n  rw [gcd_comm (content _) _, gcd_comm (content _) _],\n  apply gcd_content_eq_of_dvd_sub,\n  rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,\n    sub_sub_cancel, leading_coeff_mul, ring_hom.map_mul, mul_assoc, mul_assoc],\n  apply dvd_sub (dvd.intro _ rfl) (dvd.intro _ rfl),\nend\n\n@[simp]\ntheorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content :=\nbegin\n  classical,\n  suffices h : ∀ (n : ℕ) (p q : R[X]), ((p * q).degree < n) →\n    (p * q).content = p.content * q.content,\n  { apply h,\n    apply (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (nat.lt_succ_self _))) },\n  intro n,\n  induction n with n ih,\n  { intros p q hpq,\n    rw [with_bot.coe_zero, nat.with_bot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq,\n    rcases hpq with rfl | rfl; simp },\n  intros p q hpq,\n  by_cases p0 : p = 0, { simp [p0] },\n  by_cases q0 : q = 0, { simp [q0] },\n  rw [degree_eq_nat_degree (mul_ne_zero p0 q0), with_bot.coe_lt_coe, nat.lt_succ_iff_lt_or_eq,\n    ← with_bot.coe_lt_coe, ← degree_eq_nat_degree (mul_ne_zero p0 q0), nat_degree_mul p0 q0] at hpq,\n  rcases hpq with hlt | heq, { apply ih _ _ hlt },\n  rw [← p.nat_degree_prim_part, ← q.nat_degree_prim_part, ← with_bot.coe_eq_coe, with_bot.coe_add,\n    ← degree_eq_nat_degree p.prim_part_ne_zero, ← 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  { 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 [← normalize_content, normalize_eq_one, is_unit_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,\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,\n      ← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part],\n  { rw [← heq, degree_mul, with_bot.add_lt_add_iff_right],\n    { apply degree_erase_lt p.prim_part_ne_zero },\n    { rw [ne.def, degree_eq_bot],\n      apply q.prim_part_ne_zero } },\n  { rw [mul_comm, ← heq, degree_mul, with_bot.add_lt_add_iff_left],\n    { apply degree_erase_lt q.prim_part_ne_zero },\n    { rw [ne.def, degree_eq_bot],\n      apply p.prim_part_ne_zero } }\nend\n\ntheorem is_primitive.mul {p q : R[X]} (hp : p.is_primitive) (hq : q.is_primitive) :\n  (p * q).is_primitive :=\nby rw [is_primitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]\n\n@[simp]\ntheorem prim_part_mul {p q : R[X]} (h0 : p * q ≠ 0) :\n  (p * q).prim_part = p.prim_part * q.prim_part :=\nbegin\n  rw [ne.def, ← content_eq_zero_iff, ← C_eq_zero] at h0,\n  apply mul_left_cancel₀ h0,\n  conv_lhs { rw [← (p * q).eq_C_content_mul_prim_part,\n    p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part] },\n  rw [content_mul, ring_hom.map_mul],\n  ring,\nend\n\nlemma is_primitive.dvd_prim_part_iff_dvd {p q : R[X]}\n  (hp : p.is_primitive) (hq : q ≠ 0) :\n  p ∣ q.prim_part ↔ p ∣ q :=\nbegin\n  refine ⟨λ h, h.trans (dvd.intro_left _ q.eq_C_content_mul_prim_part.symm), λ h, _⟩,\n  rcases h with ⟨r, rfl⟩,\n  apply dvd.intro _,\n  rw [prim_part_mul hq, hp.prim_part_eq],\nend\n\ntheorem exists_primitive_lcm_of_is_primitive {p q : R[X]}\n  (hp : p.is_primitive) (hq : q.is_primitive) :\n  ∃ r : R[X], r.is_primitive ∧ (∀ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s) :=\nbegin\n  classical,\n  have h : ∃ (n : ℕ) (r : R[X]), r.nat_degree = n ∧ r.is_primitive ∧ p ∣ r ∧ q ∣ r :=\n    ⟨(p * q).nat_degree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩,\n  rcases nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩,\n  refine ⟨r, rprim, λ s, ⟨_, λ rs, ⟨pr.trans rs, qr.trans rs⟩⟩⟩,\n  suffices hs : ∀ (n : ℕ) (s : R[X]), s.nat_degree = n → (p ∣ s ∧ q ∣ s → r ∣ s),\n  { apply hs s.nat_degree s rfl },\n  clear s,\n  by_contra' con,\n  rcases nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩,\n  have s0 : s ≠ 0,\n  { contrapose! rs, simp [rs] },\n  have hs := nat.find_min' h ⟨_, s.nat_degree_prim_part, s.is_primitive_prim_part,\n              (hp.dvd_prim_part_iff_dvd s0).2 ps, (hq.dvd_prim_part_iff_dvd s0).2 qs⟩,\n  rw ← rdeg at hs,\n  by_cases sC : s.nat_degree ≤ 0,\n  { rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), is_primitive_iff_content_eq_one,\n      content_C, normalize_eq_one] at rprim,\n    rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), ← 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 ⟨_, rfl, ⟨dvd_cancel_leads_of_dvd_of_dvd pr ps, dvd_cancel_leads_of_dvd_of_dvd qr qs⟩,\n      λ rcs, rs _⟩,\n  rw ← 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, ← leading_coeff_eq_zero, ← C_eq_zero] at hC0,\n  rw [sub_add_cancel, ← rprim.dvd_prim_part_iff_dvd (mul_ne_zero hC0 s0)] at h,\n  rcases is_unit_prim_part_C r.leading_coeff with ⟨u, hu⟩,\n  apply h.trans (associated.symm ⟨u, _⟩).dvd,\n  rw [prim_part_mul (mul_ne_zero hC0 s0), hu, mul_comm],\nend\n\nlemma dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part\n  {p q : R[X]} (hq : q ≠ 0) :\n  p ∣ q ↔ p.content ∣ q.content ∧ p.prim_part ∣ q.prim_part :=\nbegin\n  split; intro h,\n  { rcases h with ⟨r, rfl⟩,\n    rw [content_mul, p.is_primitive_prim_part.dvd_prim_part_iff_dvd hq],\n    exact ⟨dvd.intro _ rfl, p.prim_part_dvd.trans (dvd.intro _ rfl)⟩ },\n  { rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part],\n    exact mul_dvd_mul (ring_hom.map_dvd C h.1) h.2 }\nend\n\n@[priority 100]\ninstance normalized_gcd_monoid : normalized_gcd_monoid R[X] :=\nnormalized_gcd_monoid_of_exists_lcm $ λ p q, begin\n  rcases exists_primitive_lcm_of_is_primitive p.is_primitive_prim_part q.is_primitive_prim_part\n    with ⟨r, rprim, hr⟩,\n  refine ⟨C (lcm p.content q.content) * r, λ s, _⟩,\n  by_cases hs : s = 0,\n  { simp [hs] },\n  by_cases hpq : C (lcm p.content q.content) = 0,\n  { 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    is_unit.mul_left_dvd _ _ _ (is_unit_prim_part_C (lcm p.content q.content)), ← hr s.prim_part],\n  tauto,\nend\n\nlemma degree_gcd_le_left {p : R[X]} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree :=\nbegin\n  have := nat_degree_le_iff_degree_le.mp\n    (nat_degree_le_of_dvd (gcd_dvd_left p q) hp),\n  rwa degree_eq_nat_degree hp\nend\n\nlemma degree_gcd_le_right (p) {q : R[X]} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree :=\nby { rw [gcd_comm], exact degree_gcd_le_left hq p }\n\nend normalized_gcd_monoid\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/content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.77998341848013}}
{"text": "import tactic\n\n/-!\n\n# Groups\n\nDefinition and basic properties of a group.\n\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\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 → G → G`\n`has_one G` means that `G` has a `1 : G`\n`has_inv G` means that `G` has an `⁻¹ : G → G`\n\nAll of `*`, `1` and `⁻¹` are just 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-/\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 : ∀ (a b c : G), a * b * c = a * (b * c))\n(one_mul : ∀ (a : G), 1 * a = a)\n(mul_left_inv : ∀ (a : G), a⁻¹ * 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 : ∀ (a : G), a * 1 = a`\nand `mul_right_inv : ∀ (a : G), a * a⁻¹ = 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 : ∀ (a b c : G), a * b = a * c → b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a⁻¹ * y → a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a⁻¹ = 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 : ∀ a b c, a * b = a * c → 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\n`mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c)`\n`one_mul : ∀ (a : G), 1 * a = a`\n`mul_left_inv : ∀ (a : G), a⁻¹ * a = 1`\n\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⁻¹ * a) * b : by rw mul_left_inv\n    ... = a⁻¹ * (a * b) : by rw mul_assoc\n    ... = a⁻¹ * (a * c) : by rw Habac\n    ... = (a⁻¹ * a) * c : by rw mul_assoc\n    ... = 1 * c         : by rw mul_left_inv\n    ... = c             : by rw one_mul\nend\n\n/-\nNext we prove that if `x = a⁻¹ * 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⁻¹ * (a * x) = a⁻¹ * y.`\nNow use associativity and left cancellation on on the left, to reduce\nto `h`. \n\nNote that `mul_left_cancel` is a function, and its first input is \ncalled `a`, but you had better give it `a⁻¹` instead.  \n-/\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  rw ←mul_assoc,\n  rw mul_left_inv,\n  rwa one_mul, -- `rwa` is \"rewrite, then assumption\"\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  apply mul_eq_of_eq_inv_mul,\n  rw mul_left_inv,\nend\n\n@[simp] theorem mul_right_inv : a * a⁻¹ = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  rw mul_one,\nend\n\n-- Now let's talk about what that `@[simp]` means.\n\n/-\n\n## Lean's simplifier\n\nA human sees `a * a⁻¹` 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 ↔ Q` (by tagging them with the `@[simp]` attribute) and then give\nit a complicated goal, like\n\n`example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * 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⁻¹ = 1`\n\nthe right hand side is simpler than the left hand side. It would be a\ndisaster to tag `a = a * 1` with the `@[simp]` tag -- can you see why?\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-/\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⁻¹ * (a * b) = b`\n`mul_inv_cancel_left : a * (a⁻¹ * b) = b`\n`inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹`\n`one_inv : (1 : G)⁻¹ = 1`\n`inv_inv : (a⁻¹)⁻¹ = 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⁻¹ * (a * b) = b :=\nbegin\n  rw ← mul_assoc, -- the simplifier will not rewrite that way...\n  simp -- ...but from here on it can manage.\nend\n\n@[simp] lemma mul_inv_cancel_left : a * (a⁻¹ * b) = b :=\nbegin\n  rw ←mul_assoc,\n  simp\nend\n\n@[simp] lemma inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv,\n  simp,\nend\n\n@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=\nbegin\n  apply mul_left_cancel (1 : G),\n  rw mul_right_inv,\n  simp,\nend\n\n@[simp] lemma inv_inv : (a ⁻¹) ⁻¹ = a :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  simp,\nend\n\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\n\nhttps://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group\n\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öbner bases.\n\n-/\n\n-- Now let's try our example...\nexample : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * 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⁻¹ :=\nbegin\n  rw ← h,\n  simp,\nend\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b⁻¹ * c :=\nbegin\n  rw ← h,\n  simp,\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b ↔ a = 1 :=\nbegin\n  split,\n  { intro h,\n    replace h := eq_mul_inv_of_mul_eq h,\n    simp [h] }, -- use h as well as the simp lemmas\n  { intro h,\n    rw [h, one_mul] }\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a ↔ b = 1 :=\nbegin\n  split,\n  { intro h,\n    replace h := eq_inv_mul_of_mul_eq h,\n    simp [h] },\n  { rintro rfl, -- let's define `b` to be 1\n    simp },\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b⁻¹ :=\nbegin\n  convert eq_mul_inv_of_mul_eq h, -- `convert x` means \"I claim the goal is x;\n                                  -- now show me the parts where it isn't\". \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⁻¹ = b :=\nbegin\n  -- we can change hypotheses with the `replace` tactic.\n  -- h implies a = 1 * b⁻¹\n  replace h := eq_mul_inv_of_mul_eq h,\n  simp [h],\nend\n\n-- you don't even need `begin / end` to do a `calc`.\nlemma unique_left_id {e : G} (h : ∀ x : G, e * x = x) : e = 1 :=\ncalc e = e * 1 : by rw mul_one\n  ...  = 1 : by rw h 1\n\nlemma unique_right_inv {a b : G} (h : a * b = 1) : b = a⁻¹ :=\nbegin\n  apply mul_left_cancel a,\n  simp [h],\nend\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y ↔ x = y :=\nbegin\n  split,\n  { apply mul_left_cancel },\n  { intro hxy,\n    rwa hxy }\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⁻¹) : by rw mul_right_inv\n  ...  = x * a * a⁻¹ : by rw mul_assoc\n  ...  = y * a * a⁻¹ : by rw Habac\n  ...  = y * (a * a⁻¹) : by rw mul_assoc\n  ...  = y * 1 : by rw mul_right_inv\n  ...  = y : by rw mul_one\n\n-- `↔` lemmas are good simp lemmas too.\n@[simp] theorem inv_inj_iff {a b : G}: a⁻¹ = b⁻¹ ↔ a = b :=\nbegin\n  split,\n  { intro h,\n    rw [← inv_inv a, h, inv_inv b] },\n  { rintro rfl, -- define b to be a\n    refl }  \nend   \n\ntheorem inv_eq {a b : G}: a⁻¹ = b ↔ b⁻¹ = a :=\nbegin\n  split;\n  { rintro rfl,\n    rw inv_inv }\nend  \n\nend group\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_2/kb_solutions/Part_A_groups_solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8976952948443462, "lm_q1q2_score": 0.7799416968677986}}
{"text": "import tactic\nimport data.real.basic\n\n/- Tacics you may consider\n-intro\n-rw\n-apply\n-exact\n-cases\n-rcases\n-split\n-contrapose!\n-push_neg\n-/\n\n#check le_trans\n#check lt_trans\n#check @lt_iff_le_not_le\n\n-- BEGIN\nvariables {α : Type*} [preorder α]\nvariables a b c : α\n\nexample : ¬ a < a :=\nbegin\n  rw lt_iff_le_not_le,\n  push_neg,\n  intro h, \n  exact h,\nend\n\nexample : a < b → b < c → a < c :=\nbegin\n  simp only [lt_iff_le_not_le],\n  intros h h',\n  cases h with h1 h2,\n  cases h' with h'1 h'2,\n  split,\n  apply le_trans h1 h'1,\n  contrapose! h'2,\n  apply le_trans h'2,\n  exact h1,\nend\n\nexample (x y : ℝ) : (∃ z : ℝ, x < z ∧ z < y) → x < y :=\nbegin\n  intro z,\n  cases z with z hz,\n  cases hz with xltz zlty,\n  exact lt_trans xltz zlty,\nend\n\n/- Alternatively, using the rcases tactic leads to a shorter proof -/\nexample (x y : ℝ) : (∃ z : ℝ, x < z ∧ z < y) → x < y :=\nbegin\n  rintros ⟨z, xltz, zlty⟩,\n  exact lt_trans xltz zlty,\nend\n\nexample (x y : ℝ) : (∃ z : ℝ, x < z ∧ z < y) → x < y :=\nλ ⟨z, xltz, zlty⟩, lt_trans xltz zlty\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/ex3_exact_lt_trans.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7798928022192578}}
{"text": "/-\nIf P and Q are arbitrary propositions, then to prove \nP ∧ Q, you need to prove P and to prove Q and then to\nform the pair of these proofs to construct a proof of\nP ∧ Q. \n-/\n\n-- Suppose P and Q are arbitrary propositions\naxioms (P Q : Prop)\n\n-- Suppose you have proofs of P and of Q\naxioms (p : P) (q : Q)\n\n-- You can now construct a proof of P ∧ Q\n\n#check and.intro p q\n\n\n/- \nNote: Lean provides a nice notation for\nand.intro. Use backslash left and right\nangle brackets. This notation emphasizes\nthat a proof of a conjunctions is formed\nas a pair of proofs.\n-/\nlemma pq : P ∧ Q := ⟨ p, q ⟩ \n\n/-\nThe elimination rules for and allow you\nto deduce from a proof of P ∧ Q that there\nis a proof of P and a proof of Q.\n-/\n\n#check pq.left\n#check pq.right", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/predicate_logic/intro_and_elim_rules/and.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.779892800355736}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n\n/-!\n# Function World\n\n## Level 4: the `apply` tactic.\n\nLet's do the same level again a different way:\n\n![diagram](../assets/function_diag.svg)\n\nWe are given  `p  ∈ P ` and our goal is to find an element of  `U `, or\nin other words to find a path through the maze that links  `P ` to  `U `.\nIn level 3 we solved this by using `have`s to move forward, from  `P `\nto  `Q ` to  `T ` to  `U `.\nUsing the [apply tactic](../Tactics/apply.lean.md) we can instead construct\nthe path backwards, moving from  `U ` to  `T ` to  `Q ` to  `P `.\n\nOur goal is to construct an element of the set  `U `. But  `l:T → U ` is\na function, so it would suffice to construct an element of  `T `. Tell\nLean this by starting the proof below with\n\n`apply l`\n\nand notice that our assumptions don't change but *the goal changes*\nfrom `⊢ U` to `⊢ T`.\n\nKeep `apply`ing functions until your goal is `P`, and try not\nto get lost! Now solve this goal\nwith `exact p`. Note: you will need to learn the difference between\n`exact p` (which works) and `exact P` (which doesn't, because  `P ` is\nnot an element of  `P `).\n\n## Definition\nGiven an element of  `P ` we can define an element of  `U `.\n-/\nexample (P Q R S T U: Type)\n(p : P)\n(h : P → Q)\n(i : Q → R)\n(j : Q → T)\n(k : S → T)\n(l : T → U)\n: U := by\n  apply l\n  apply j\n  apply h\n  exact p\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/FunctionWorld/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7798787541318039}}
{"text": "-- Proves infinitude of prime numbers using Fermat numbers.\n-- There are infinite Fermat numbers and they have no common factors.\n\nimport data.nat.basic\nimport data.nat.pow\nimport data.nat.prime\n\n\ndef fermat_num (n : ℕ) := 2^(2^n) + 1\n\ndef fermat_prod : ℕ → ℕ\n| 0 := 1\n| (n+1) := fermat_num n * fermat_prod n\n\n\nlemma two_lt_fermat_num (n : ℕ) : 2 < fermat_num n :=\nbegin\n  rw fermat_num,\n  apply lt_of_le_of_lt' _ (nat.lt_succ_self 2),\n  rw nat.succ_le_succ_iff,\n  apply le_self_pow,\n    simp,\n  apply pow_ne_zero,\n  simp,\nend\n\nlemma odd_iff {n : ℕ} : ¬ 2 ∣ n ↔ n % 2 = 1 :=\nbegin\n  rw nat.dvd_iff_mod_eq_zero,\n  apply iff.intro,\n    intro h',\n    cases (nat.mod_two_eq_zero_or_one n),\n      contradiction,\n    assumption,\n  cases (nat.mod_two_eq_zero_or_one n),\n    rw h,\n    contradiction,\n  rw h,\n  simp,\nend\n\nlemma fermat_num_odd (n : ℕ) : ¬ 2 ∣ fermat_num n :=\nbegin\n  rw odd_iff,\n  have h := nat.mod_two_eq_zero_or_one,\n  rw fermat_num,\n  cases n, simp,\n  simp [nat.add_mod, nat.pow_mod],\nend\n\n-- The main result on which the proof depends.\ntheorem prod_add_two_eq_num {n : ℕ} :\n  fermat_prod n + 2 = fermat_num n :=\nbegin\n  rw fermat_num,\n  induction n with k hk,\n    rw fermat_prod, simp,\n  rw fermat_prod,\n  rw fermat_num,\n  simp [add_mul],\n  rw add_assoc,\n  rw hk,\n  rw ← add_assoc,\n  rw nat.succ.inj_eq,\n  rw pow_succ,\n  rw mul_comm 2 _,  -- Ensure we get (2^2^k)^2 rather than (2^2)^(2^k).\n  rw pow_mul,\n  rw ← nat.mul_succ,\n  rw pow_two,\n  simp,\n  apply nat.succ.inj,\n  exact hk,\nend\n\n\nlemma fermat_num_dvd_prod {k n : ℕ} : k < n → fermat_num k ∣ fermat_prod n :=\nbegin\n  cases n,\n    simp,\n  intro hkn,\n  cases nat.le.dest (nat.le_of_lt_succ hkn) with d hd,\n  rw ← hd, clear hkn hd,\n  induction d with i hi,\n    simp,\n    rw fermat_prod, simp,\n  rw nat.add_succ,\n  rw fermat_prod,\n  apply dvd_trans hi,\n  simp,\nend\n\nlemma fermat_dvd_fermat_sub_two {k n : ℕ} :\n  k < n → fermat_num k ∣ fermat_num n - 2 :=\nbegin\n  cases n,\n    simp,\n  intro hkn,\n  rw ← @prod_add_two_eq_num n.succ, simp,\n  apply fermat_num_dvd_prod hkn,\nend\n\n-- Lazy proof of a simple result.\nlemma dvd_two_iff {m : ℕ} : m ∣ 2 ↔ m = 1 ∨ m = 2 :=\nbegin\n  apply iff.intro,\n    cases m, simp,\n    cases m, simp,\n    cases m, simp,\n    intro h,\n    exfalso,\n    have h_le := nat.le_of_dvd (dec_trivial) h,\n    revert h_le,\n    dec_trivial,\n  intro h,\n  cases h,\n    rw h, dec_trivial,\n  rw h,\nend\n\n-- Cannot apply dvd_add_right to ℕ (needs non_unital_ring).\n-- From (m ∣ x) and (m ∣ x-2), we have that (m ∣ 2), hence m = 1 or 2.\nlemma nat_dvd_add_right {a b c : ℕ} : (a ∣ b) → (a ∣ b + c) → a ∣ c :=\nbegin\n  rw nat.dvd_iff_mod_eq_zero,\n  rw nat.dvd_iff_mod_eq_zero,\n  rw nat.dvd_iff_mod_eq_zero,\n  rw ← nat.mod_add_mod,\n  intro ha, rw ha, simp,\nend\n\n-- Didn't need this in the end. May be useful in the future.\ntheorem nat_sub_sub {x y z : ℕ} : x ≤ y → y ≤ z → z - (y - x) = x + (z - y) :=\nbegin\n  intro hxy,\n  intro hyz,\n  have hxz := le_trans hxy hyz,\n  have hy_z : y ≤ z + x := nat.add_le_add hyz (nat.zero_le _),\n  have hy_z : y - x ≤ z := _,\n    rw nat.sub_eq_iff_eq_add hy_z,\n    rw add_assoc, rw add_comm (z-y) (y-x), rw ← add_assoc,\n    rw ← nat.add_sub_assoc hxy, simp,\n    rw ← nat.add_sub_assoc hyz, simp,\n  have hx_z : x ≤ z + x := nat.add_le_add hxz (nat.zero_le _),\n  rw ← nat.add_sub_cancel z x,\n  rw nat.sub_le_sub_iff_right hx_z, assumption,\nend\n\n-- Like nat_dvd_add_right but for (valid) sub.\nlemma nat_dvd_sub_right {a b c : ℕ} : c ≤ b → (a ∣ b) → (a ∣ b - c) → a ∣ c :=\nbegin\n  intro h_le,\n  rw le_iff_exists_add at h_le,\n  cases h_le with d hd,\n  rw hd, simp,\n  rw add_comm,\n  intro ha,\n  intro hb,\n  apply nat_dvd_add_right hb ha,\nend\n\n-- All fermat numbers are co-prime.\ntheorem fermat_coprime {k n : ℕ} :\n  k < n → ∀ (m : ℕ), (m ∣ fermat_num k) → (m ∣ fermat_num n) → m = 1 :=\nbegin\n  intro hkn,\n  intro m,\n  intro hfk,\n  intro hfn,\n  have h_dvd_sub_two := dvd_trans hfk (fermat_dvd_fermat_sub_two hkn),\n  -- Combine the two dvd results to obtain constraint on m.\n  have h := nat_dvd_sub_right _ hfn h_dvd_sub_two,\n    rw dvd_two_iff at h,\n    cases h, assumption,\n    -- m cannot be 2 since all Fermat numbers are odd.\n    exfalso,\n    apply fermat_num_odd k,\n    rw h at hfk, exact hfk,\n  apply le_of_lt,\n  apply two_lt_fermat_num,\nend\n\n\n-- Function that maps any number to a novel prime number.\ndef make_prime (n : ℕ) := (fermat_num n).min_fac\n\nlemma make_prime_is_prime (n : ℕ) : nat.prime (make_prime n) :=\nbegin\n  rw make_prime,\n  apply nat.min_fac_prime,\n  rw fermat_num,\n  simp,\nend\n\nlemma not_make_prime_eq_one {n : ℕ} : ¬ make_prime n = 1 :=\nbegin\n  intro h',\n  apply nat.not_prime_one,\n  have h := make_prime_is_prime n,\n  rw h' at h,\n  exact h,\nend\n\n-- Prove that make_prime n generates a new prime number for any n.\ntheorem infinite_primes (n : ℕ) :\n  nat.prime (make_prime n) ∧ ∀ (k : ℕ), k < n → make_prime k ≠ make_prime n :=\nbegin\n  cases n, simp,\n    apply nat.min_fac_prime,\n    rw fermat_num, simp,\n  apply and.intro (make_prime_is_prime _),\n  intro k,\n  intro hk,\n  have h_prime := make_prime_is_prime k,\n  simp, intro h_eq,\n  have h := fermat_coprime hk (make_prime k),  -- but we know that make_prime k ≠ 1\n  apply not_make_prime_eq_one,\n  apply h,\n    rw make_prime,\n    apply nat.min_fac_dvd,\n  rw h_eq,\n  rw make_prime,\n  apply nat.min_fac_dvd,\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_fermat_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475762847495, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7798765652087929}}
{"text": "/-\nCopyright (c) 2022 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey, Patrick Stevens, Thomas Browning\n-/\n\nimport data.nat.choose.central\nimport number_theory.padics.padic_norm\nimport data.nat.multiplicity\n\n/-!\n# Factorization of Binomial Coefficients\n\nThis file contains a few results on the multiplicity of prime factors within certain size\nbounds in binomial coefficients. These include:\n\n* `nat.factorization_choose_le_log`: a logarithmic upper bound on the multiplicity of a prime in\n  a binomial coefficient.\n* `nat.factorization_choose_le_one`: Primes above `sqrt n` appear at most once\n  in the factorization of `n` choose `k`.\n* `nat.factorization_central_binom_of_two_mul_self_lt_three_mul`: Primes from `2 * n / 3` to `n`\ndo not appear in the factorization of the `n`th central binomial coefficient.\n* `nat.factorization_choose_eq_zero_of_lt`: Primes greater than `n` do not\n  appear in the factorization of `n` choose `k`.\n\nThese results appear in the [Erdős proof of Bertrand's postulate](aigner1999proofs).\n-/\n\nnamespace nat\n\nvariables {p n k : ℕ}\n\n/--\nA logarithmic upper bound on the multiplicity of a prime in a binomial coefficient.\n-/\nlemma factorization_choose_le_log : (choose n k).factorization p ≤ log p n :=\nbegin\n  by_cases h : (choose n k).factorization p = 0, { simp [h] },\n  have hp : p.prime := not.imp_symm (choose n k).factorization_eq_zero_of_non_prime h,\n  have hkn : k ≤ n, { refine le_of_not_lt (λ hnk, h _), simp [choose_eq_zero_of_lt hnk] },\n  rw [←@padic_val_nat_eq_factorization p _ ⟨hp⟩, @padic_val_nat_def _ ⟨hp⟩ _ (choose_pos hkn)],\n  simp only [hp.multiplicity_choose hkn (lt_add_one _), enat.get_coe],\n  refine (finset.card_filter_le _ _).trans (le_of_eq (nat.card_Ico _ _)),\nend\n\n/--\nA `pow` form of `nat.factorization_choose_le`\n-/\nlemma pow_factorization_choose_le (hn : 0 < n) : p ^ (choose n k).factorization p ≤ n :=\nbegin\n  cases le_or_lt p 1,\n  { exact (pow_le_pow_of_le h).trans ((le_of_eq (one_pow _)).trans hn) },\n  { exact (pow_le_iff_le_log h hn).mpr factorization_choose_le_log },\nend\n\n/--\nPrimes greater than about `sqrt n` appear only to multiplicity 0 or 1 in the binomial coefficient.\n-/\nlemma factorization_choose_le_one (p_large : n < p ^ 2) : (choose n k).factorization p ≤ 1 :=\nbegin\n  apply factorization_choose_le_log.trans,\n  rcases n.eq_zero_or_pos with rfl | hn0, { simp },\n  refine lt_succ_iff.1 ((lt_pow_iff_log_lt _ hn0).1 p_large),\n  contrapose! hn0,\n  exact lt_succ_iff.1 (lt_of_lt_of_le p_large (pow_le_one' hn0 2)),\nend\n\nlemma factorization_choose_of_lt_three_mul\n  (hp' : p ≠ 2) (hk : p ≤ k) (hk' : p ≤ n - k) (hn : n < 3 * p) :\n  (choose n k).factorization p = 0 :=\nbegin\n  cases em' p.prime with hp hp,\n  { exact factorization_eq_zero_of_non_prime (choose n k) hp },\n  cases lt_or_le n k with hnk hkn,\n  { simp [choose_eq_zero_of_lt hnk] },\n  rw [←@padic_val_nat_eq_factorization p _ ⟨hp⟩, @padic_val_nat_def _ ⟨hp⟩ _ (choose_pos hkn)],\n  simp only [hp.multiplicity_choose hkn (lt_add_one _), enat.get_coe,\n    finset.card_eq_zero, finset.filter_eq_empty_iff, not_le],\n  intros i hi,\n  rcases eq_or_lt_of_le (finset.mem_Ico.mp hi).1 with rfl | hi,\n  { rw [pow_one, ←add_lt_add_iff_left (2 * p), ←succ_mul, two_mul, add_add_add_comm],\n    exact lt_of_le_of_lt (add_le_add\n      (add_le_add_right (le_mul_of_one_le_right' ((one_le_div_iff hp.pos).mpr hk)) (k % p))\n      (add_le_add_right (le_mul_of_one_le_right' ((one_le_div_iff hp.pos).mpr hk')) ((n - k) % p)))\n      (by rwa [div_add_mod, div_add_mod, add_tsub_cancel_of_le hkn]) },\n  { replace hn : n < p ^ i,\n    { calc n < 3 * p : hn\n      ... ≤ p * p : mul_le_mul_right' (lt_of_le_of_ne hp.two_le hp'.symm) p\n      ... = p ^ 2 : (sq p).symm\n      ... ≤ p ^ i : pow_le_pow hp.one_lt.le hi },\n    rwa [mod_eq_of_lt (lt_of_le_of_lt hkn hn), mod_eq_of_lt (lt_of_le_of_lt tsub_le_self hn),\n      add_tsub_cancel_of_le hkn] },\nend\n\n/--\nPrimes greater than about `2 * n / 3` and less than `n` do not appear in the factorization of\n`central_binom n`.\n-/\nlemma factorization_central_binom_of_two_mul_self_lt_three_mul\n  (n_big : 2 < n) (p_le_n : p ≤ n) (big : 2 * n < 3 * p) :\n  (central_binom n).factorization p = 0 :=\nbegin\n  refine factorization_choose_of_lt_three_mul _ p_le_n (p_le_n.trans _) big,\n  { rintro rfl, linarith },\n  { rw [two_mul, add_tsub_cancel_left] },\nend\n\nlemma factorization_factorial_eq_zero_of_lt (h : n < p) :\n  (factorial n).factorization p = 0 :=\nbegin\n  induction n with n hn, { simp },\n  rw [factorial_succ, factorization_mul n.succ_ne_zero n.factorial_ne_zero, finsupp.coe_add,\n      pi.add_apply, hn (lt_of_succ_lt h), add_zero, factorization_eq_zero_of_lt h],\nend\n\nlemma factorization_choose_eq_zero_of_lt (h : n < p) :\n  (choose n k).factorization p = 0 :=\nbegin\n  by_cases hnk : n < k, { simp [choose_eq_zero_of_lt hnk] },\n  rw [choose_eq_factorial_div_factorial (le_of_not_lt hnk),\n      factorization_div (factorial_mul_factorial_dvd_factorial (le_of_not_lt hnk)),\n      finsupp.coe_tsub, pi.sub_apply, factorization_factorial_eq_zero_of_lt h, zero_tsub],\nend\n\n/--\nIf a prime `p` has positive multiplicity in the `n`th central binomial coefficient,\n`p` is no more than `2 * n`\n-/\nlemma factorization_central_binom_eq_zero_of_two_mul_lt (h : 2 * n < p) :\n  (central_binom n).factorization p = 0 :=\nfactorization_choose_eq_zero_of_lt h\n\n/--\nContrapositive form of `nat.factorization_central_binom_eq_zero_of_two_mul_lt`\n-/\nlemma le_two_mul_of_factorization_central_binom_pos\n  (h_pos : 0 < (central_binom n).factorization p) : p ≤ 2 * n :=\nle_of_not_lt (pos_iff_ne_zero.mp h_pos ∘ factorization_central_binom_eq_zero_of_two_mul_lt)\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/factorization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7798660744577077}}
{"text": "/-\nCopyright (c) 2022 OpenAI. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Daniel Selsam\n-/\nimport data.nat.basic\nimport data.nat.digits\nimport data.finset.basic\n\n-- `f` is the collatz function\ndef f (n : ℕ) : ℕ := \n  if 2 ∣ n then n / 2 else 3 * n + 1\n\ndef simulate : Π (k : ℕ) (n : ℕ), list ℕ \n  | _ 1     := [1]\n  | 0 n     := [n]\n  | (k+1) n := n :: simulate k (f n)\n\nexample : simulate 6 7 = [7, 22, 11, 34, 17, 52, 26] := rfl\n\n@[reducible] \ndef gcond (n : ℕ) : Prop :=\n  3 ∣ (n-1) ∧ ¬ (2 ∣ ((n - 1)/3))\n\n-- `g` is the inverse of `f`\n-- f (2 * n) = n\n-- f ((n-1)/3) = n ↔ (n-1)/3 is an odd integer\ndef g (n : ℕ) : finset ℕ :=\n  if gcond n then { 2 * n, (n - 1) / 3 } else { 2 * n } \n\nlemma not_gcond (n : ℕ) : ¬ gcond n → (¬ (3 ∣ (n-1)) ∨ 2 ∣ ((n - 1)/3)) :=\nbegin\n  unfold gcond,\n  intro h_ngcond,\n  simp at h_ngcond,\n  by_cases h : 3 ∣ (n-1),\n  simp [h_ngcond h],\n  simp [h]\nend\n\nlemma cancel_shift {d n k : ℕ} : d ∣ (n - k) → k ≤ n → d * ((n - k) / d) + k = n :=\nbegin\n  intros h_div h_le,\n  suffices h_goal : d * ((n - k) / d) = n - k, \n  { simp [h_goal], apply nat.sub_add_cancel h_le,  },\n  { rw [mul_comm], apply nat.div_mul_cancel h_div },\nend\n\nlemma g_inv_f : ∀ (n : ℕ), 1 ≤ n → ∀ (k : ℕ), k ∈ g n ↔ f k = n :=\nbegin\n  intros n h_ge1 k,\n  split,\n  -- k ∈ g n → f k = n\n  {\n    intro hk_gn,\n    dunfold g at hk_gn,\n    by_cases h_cond : gcond n,\n    -- case 1: can reach n from two different positions\n    { \n      simp [h_cond] at hk_gn, \n      cases hk_gn ; subst hk_gn,\n      -- f (2 * n) = n\n      { simp [f], },\n      -- f ((n-1)/3) = n\n      { \n        unfold gcond at h_cond,\n        simp [f, h_cond.2, cancel_shift h_cond.1 h_ge1],  \n      },\n    },\n    -- case 2: can only reach n from above\n    {\n      simp [h_cond] at hk_gn,\n      simp [f, hk_gn],\n    },\n  },\n  -- f k = n → k ∈ g n\n  {\n    intro h_fk,\n    subst h_fk,\n    simp [g],\n    by_cases h_gcond : gcond (f k),\n    -- case 1: gcond (f k)\n    { \n      simp [h_gcond],\n      unfold gcond at h_gcond,\n      unfold f at *,\n      by_cases h_2k : 2 ∣ k,\n      { simp [h_2k], left, rw [mul_comm, nat.div_mul_cancel h_2k] },\n      { simp [h_2k] }\n    },\n    -- case 2: ¬ gcond (f k)\n    { \n      simp [h_gcond],\n      unfold f at *,\n      by_cases h_2k : 2 ∣ k,\n      { simp [h_2k], rw [mul_comm, nat.div_mul_cancel h_2k] },\n      { simp [h_2k] at h_gcond, contradiction }\n    }\n  }\nend\n\ndef iterate {α : Type} (f : α → α) : ℕ → α → α\n| 0 x := x\n| (steps+1) x := iterate steps (f x)\n\ndef finset.iterate {α : Type} [decidable_eq α] (g : α → finset α) : ℕ → α → finset α\n| 0 x := {x}\n| (steps+1) x := (finset.iterate steps x).bUnion g\n\ntheorem iterate_g_ge1 : ∀ {steps x : ℕ}, x ∈ finset.iterate g steps 1 → 1 ≤ x\n| 0 x h := \nbegin \n  clear iterate_g_ge1, \n  simp [finset.iterate, g, gcond] at h, \n  subst h\nend\n| (steps+1) x₀ h :=\nbegin\n  simp [finset.iterate, g] at h, \n  obtain ⟨x, hx, hy⟩ := h,\n  have hx_ge1 : 1 ≤ x := iterate_g_ge1 hx,\n  have one_le2x : 1 ≤ 2 * x,\n  { \n    transitivity x, \n    exact hx_ge1, \n    exact nat.le_mul_of_pos_left (nat.zero_lt_succ 1) \n  },\n  by_cases h_cond : (gcond x),\n  -- case 1: 2 possibilities\n  { \n    simp [h_cond] at hy,\n    cases hy,\n    -- easy case\n    { \n      subst hy,\n      exact one_le2x\n    },\n    -- hard (3) case\n    {\n      subst hy,\n      simp [gcond] at h_cond,\n      --obtain ⟨⟨z3, h_z3⟩, h_x2⟩ := h_cond,\n      obtain ⟨h_x3, h_x2⟩ := h_cond,\n      -- We first rule out 0-3\n      cases x, { norm_num at h_x2 },\n      cases x, { norm_num at h_x2 },\n      cases x, { norm_num at h_x2 },\n      cases x, { norm_num at h_x2 },\n      show 1 ≤ (x+3) / 3,\n      norm_num,\n      show 1 ≤ (x/3) + 1,\n      exact nat.le_add_left _ _\n    }\n  },\n  -- gcond=false\n  {\n    simp [h_cond] at hy,\n    subst hy,\n    exact one_le2x\n  }\nend\n\ntheorem iterate_f_ge1 : ∀ {steps x : ℕ}, iterate f steps x = 1 → x ≥ 1\n| 0 x h_f := by { simp [iterate] at h_f, subst h_f, apply le_refl }\n| (steps+1) x h_f :=\nbegin\nsimp [iterate] at h_f,\nhave hx_ge1 : 1 ≤ f x := iterate_f_ge1 h_f,\nsimp [f] at hx_ge1,\nby_cases h_x : 2 ∣ x,\n{\n  simp [h_x] at hx_ge1,\n  rw [← nat.div_mul_cancel h_x],\n  rw [mul_comm],\n  transitivity x/2,\n  apply nat.le_mul_of_pos_left (nat.zero_lt_succ 1),\n  exact hx_ge1\n},\n{\n  simp [h_x] at hx_ge1,\n  cases x, { simp at h_x, contradiction },\n  show 1 ≤ x+1,\n  apply nat.le_add_left\n}\nend\n\nlemma iter_g_inv_f : ∀ (steps k : ℕ), k ∈ finset.iterate g steps 1 ↔ iterate f steps k = 1 \n| 0 _ := by split ; simp [f, g, iterate, finset.iterate, gcond]\n| (steps+1) k :=\nbegin\n  split,\n  {\n    intro h_kg,\n    simp [iterate],\n    simp [finset.iterate] at h_kg,\n    obtain ⟨x, h_x, h_y⟩ := h_kg,\n    rw [g_inv_f _ (iterate_g_ge1 h_x) k] at h_y,\n    subst h_y,\n    exact (iter_g_inv_f _ _).mp h_x\n  },\n  {\n    intro h_kg,\n    simp [finset.iterate],\n    simp [iterate] at h_kg,\n    existsi f k,\n    split,\n    { exact (iter_g_inv_f _ _).mpr h_kg },\n    { rw [g_inv_f _ (iterate_f_ge1 h_kg) _]}\n  }\nend\n\ntheorem amc8_2020_p22 :\n  let s : set ℕ := {n | iterate f 6 n = 1 } in\n  ∃ (fs : finset ℕ), ↑fs = s ∧ fs.sum id = 83 :=\nbegin\n  intro s,\n  simp [s], clear s,\n  existsi (finset.iterate g 6 1),\n  split,\n  -- Restatement of our main lemma\n  { \n    ext, \n    simp [iter_g_inv_f] \n  },\n  -- Now for the computation\n  { \n    dec_trivial\n  }\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/amc/8/2020/p22.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258007, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7798660744577077}}
{"text": "/-\nIf P and Q are propositions, then\nso is P ↔ Q. We call this form of\nproposition a bi-implication. It\nmeans P → Q ∧  Q → P. \n\nHere's a somewhat silly example:\nif it has been raining the ground\nin the desert is wet (R → W) and\nif the ground in the desert is wet\nthen it has been raining (W → R).\nIn this case, we can say that the\nground in the desert is wet \"if and\nonly if\" (iff) it has been raining.\n\nIn such a situation we say that \n\"it has been raining\" and \"the\nground in the desert is wet\" are\nequivalent, as the two states of\naffairs invariable occur or do not\noccur together.\n\nThe rules for ↔ introducing and \nelimination are conceptually the same \nas for ∧ applied to two implications,\none going in each direction (R to W\nand W to R, respectively).\n\nWe recommend that you pronounce \nP ↔ Q as \"P and Q are equivalent\".\nMost mathematicians pronounce it\nas \"P if and only if Q\", which \nthey generally abbreviate P iff\nQ (note the extra f). Figuring \nout why the phrase \"if and only \nif\" actually makes sense is arguably \nmore trouble than it's worth. Just\nknow that people use this phrase\nin mathematics and logic all the \ntime. \n\n /- \n  *************************\n  *** Introduction Rule ***\n  *************************\n-/\n   \nTo construct a proof of P ↔ Q you \nmust have (or have assumed) proofs\nof two propositions: a proof of   \nP → Q, and a proof of Q → P. The\ninference rule is thus as follows:\n\nP Q : Prop, p2q : P → Q, q2p: Q → P\n-----------------------------------\n        PiffQ : P ↔ Q\n\nIn informal mathematical writing, a \nproof of P ↔ Q will start with the\nfollowing kind of language. \"We are\nto prove P ↔ Q. To prove it we must\nfirst prove P → Q, then we must prove\nP → Q. We consider the case P → Q \nfirst. \" \"first we consider the implication\nfrom P to Q, ...\" Once that part\nis proved, it will say \"and now \nwe consider the implication in\nthe other direction.\" When that\npart is also done, it will then \nsay, combing these results thus \nproves P ↔ Q. QED.\"\n\nLean provides the iff.intro rule\nto construct a proof of P ↔ Q \nfrom the requisite sub-proofs.\nHere's an example of its use\nin a program whose type makes\nclear what's required to use it.\n-/\n\nlemma bi_implication : \n ∀ { P Q : Prop }, \n    (P → Q) → (Q → P) → (P ↔ Q) :=\n        λ P Q pfPQ pfQP, \n            iff.intro pfPQ pfQP\n\n/-\nThe logical way to read this is as\nsaying that if we assume that P and \nQ are propositions, and if we assume\nwe're given a proof of P → Q and we\nfurthermore assume we're given a\nproof of Q → P then we can derive a\nproof of P ↔ Q by appealing to (by\napplying) the iff introduction rule\nof the natural deduction system of\nlogical reasoning.\n-/\n\n/-\nLet's assume we have two propositions,\nP and Q.\n-/\n\nvariables P Q : Prop\n\n/- \nand that we have proofs of both P → Q \nand of Q → P\n-/\nvariable forward: P → Q\nvariable backward: Q → P\n\n\n/-\nthen we can apply iff-intro to derive \na proof of P ↔ Q.  \n-/\n\ndef pqEquiv := iff.intro forward backward\n\n/-\nGoing the other way, if we're given a \nproof of P ↔ Q, then we can derive proofs\nof P → Q and of Q → P using the iff.elim\nleft and right rules.\n-/\n\n#check  pqEquiv\n\n\n/-\nA proof of P ↔ Q is essentially a \nproof of the conjunction (P → Q) ∧  \n(Q → P). iff.intro is like ∧-intro,\nand the left and right iff.elim \nrules are like the ∧-elim left and\nright rules.\n-/\n\n/-\nEXERCISE: Construct a proof, pqequiv, of \nthe proposition, P ∧ Q ↔ Q ∧ P. Note:\nwe don't need to know whether P and Q\nare true, false, or unknown to provide\nsuch a proof.\n-/\n\ntheorem andcomm : P ∧ Q ↔ Q ∧ P :=\nbegin\napply iff.intro,\n-- left to right\nassume pq : P ∧ Q,\nshow Q ∧ P,\nfrom and.intro (pq.right) (pq.left),\n-- in other direction\nassume qp: Q ∧ P,\nshow P ∧ Q,\nfrom and.intro (qp.right) (qp.left),\nend\n\n/-\nNote that the proposition that andcomm\nproves is: ∀ P Q: Prop, P ∧ Q ↔ Q ∧ P.\nThe use of \"variables P Q : Prop\" above\nbasically adds a \"∀ P Q : Prop\" to each\nof the propositions that follow.\n\nAs a result, andcomm in effect takes\nany two propositions as arguments and\nreturns a proof that the conjunctions\nare equivalent no matter the order of\nthe conjuncts.\n-/\n\n#check andcomm (0=0) (1=1)\n#reduce andcomm (0=0) (1=1)\n\n/-\nIn the following trivial example,\nwe can see how the bi_implication\nintroduction rule (run backwards)\ngives us a way to split a goal of\nproving P ↔ Q into two sub-goals,\none implication in each direction.\nKnowing to do that split and then\nto provide two proofs, one for each\ndirection, is the key to proving\nbi-implications, whether using a\nprover such as Lean or just using\npaper and pencil.\n-/\ntheorem easy_iff: 0 = 0 ↔ 1 = 1 :=\nbegin\napply bi_implication,\nexact λ e, eq.refl 1, -- ignores argument\nexact λ e, eq.refl 0, -- ignores argument\nend\n\n/-\nEXERCISE:\n1. Prove that A → B → C ↔ A ∧ B → C.\n2. Given that you can prove this, does this\nmean that A → B = A ∧ B?\n-/\n\nlemma a_imp_b_imp_c_iff_a_and_b_imp_c:\n  ∀ A B C: Prop, (A → B → C) ↔ ((A ∧ B) → C) :=\n  λ A B C: Prop,\nbegin\napply iff.intro,\n-- forward\nassume abc : (A → B → C),\nassume ab : A ∧ B,\nshow C,\nfrom \n  begin\n  have a : A := ab.left,\n  have b : B := ab.right,\n  show C,\n  from abc a b,\n  end, \n-- backward\n  assume abc : (A ∧ B → C),\n  show A → B → C,\n  from \n    begin\n    assume (a : A) (b : B),\n    have ab := and.intro a b,\n    show C,\n    from abc ab\n    end,\nend \n\n/- \n  *************************\n  *** Elimination Rules ***\n  *************************\n-/\n\n\n/-\nAs with ∧, the elimination rules,\niff.elim_left and iff.elim_right,\ntake a proof of P ↔ Q and return \nthe constituent sub-proofs, P → Q,\nand Q → P, respectively.\n-/\n\n#check iff.elim_left (andcomm P Q)\n#check iff.elim_right (andcomm P Q)\n\n\ntheorem PIffQImpP2Q : (P ↔ Q) → P →  Q :=\nbegin\nassume piffq p,\nshow Q,\nfrom \n  begin\n  have p2q := iff.elim_left piffq,\n  exact (p2q p)\n  end\nend\n\n-- even easier is this\ntheorem PIffQImpP2Q' : (P ↔ Q) → P -> Q :=\nbegin\nassume piffq,\nshow P → Q,\nfrom iff.elim_left piffq\nend\n\n/-\nEXERCISE: Prove P ↔ Q) → Q -> P\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/00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.8887587957022977, "lm_q1q2_score": 0.7798652043561036}}
{"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.adj_matrix\nimport combinatorics.simple_graph.basic\nimport linear_algebra.matrix\nimport project.incidence\n\n/-!\n# Laplacian matrices\n\nThis module defines the Laplacian matrix `laplace_matrix` of an undirected graph `simple_graph` and\nprovides theorems and lemmas connecting graph properties to computational properties of the matrix.\n\n## Main definitions\n\n* `laplace_matrix` is the Laplace matrix of a `simple_graph` with coefficients in a ring R\n* `degree_matrix` is the degree matrix of a `simple_graph` with coefficients in a ring R\n* `signless_laplace_matrix` is the signless Laplace matrix of a `simple_graph` with coefficients in a ring R\n* `edge_from_vertices` is the edge that is created by two adjacent vertices\n\n## Main statements\n\n1. The degree of a vertex v is equal to the sum of elements from row v of the adjacency matrix.\n2. The Laplacian matrix is symmetric.\n3. The sum of elements on any row of the Laplacian is zero.\n4. The Laplacian matrix is equal to the difference between the degree and adjancency matrices.\n5. The signless Laplacian matrix decomposition.\n6. The Laplacian matrix decomposition.\n7. The Laplacian is a quadratic form : xᵀ ⬝ L ⬝ x = ∑ e : G.edge_set, (x head(e) - x tail(e)) ^ 2.\n-/\n\nopen_locale big_operators matrix\nopen finset matrix simple_graph\n\nuniverses u v\nvariables {V : Type u} [fintype V] [decidable_eq V]\nvariables {R : Type v} [comm_ring R] [nontrivial R] [decidable_eq R]\n\nlemma dot_product_helper {x y z : V → R} (H_eq : x = y) : dot_product x z = dot_product y z :=\nby rw H_eq\n\nnamespace simple_graph\n\nvariables (G : simple_graph V) (R) [decidable_rel G.adj]\n\nlemma adj_matrix_eq {i j : V} (H_eq : i = j) : G.adj_matrix R i j = 0 :=\nby simp only [H_eq, irrefl, if_false, adj_matrix_apply]\n\nlemma adj_matrix_adj {i j : V} (H_adj : G.adj i j) : G.adj_matrix R i j = 1 :=\nby simp only [H_adj, adj_matrix_apply, if_true]\n\nlemma adj_matrix_not_adj {i j : V} (H_not_adj : ¬ G.adj i j) : G.adj_matrix R i j = 0 :=\nby simp only [H_not_adj, adj_matrix_apply, if_false]\n\n-- 1. The degree of a vertex v is equal to the sum of elements from row v of the adjacency matrix.\nlemma degree_eq_sum_of_adj_matrix_row {α : Type*} [semiring α] {i : V} :\n  (G.degree i : α) = ∑ (j : V), G.adj_matrix α i j :=\nby { rw [← mul_one (G.degree i : α)],\n     simp only [← adj_matrix_mul_vec_const_apply, mul_vec, dot_product, boole_mul, adj_matrix_apply] }\n\n-- ## Laplacian matrix L\n\n/-- `laplace_matrix G` is the matrix `L` of an `simple graph G` with `∀ i j ∈ V` :\n` | L i j = G.degree i`, if `i = j`\n` | L i j = - A i j`, otherwise. -/\ndef laplace_matrix : matrix V V R\n| i j := if i = j then G.degree i else - G.adj_matrix R i j\n\n@[simp]\nlemma laplace_matrix_apply {i j : V} :\n  G.laplace_matrix R i j = if i = j then G.degree i else - G.adj_matrix R i j := rfl\n\nlemma laplace_matrix_eq {i j : V} (H_eq : i = j) : G.laplace_matrix R i j = G.degree i :=\nby { rw [laplace_matrix_apply, adj_matrix_apply], simp only [H_eq, if_true, eq_self_iff_true] }\n\nlemma laplace_matrix_neq {i j : V} (H_neq : i ≠ j) : G.laplace_matrix R i j = - G.adj_matrix R i j :=\nby simp only [laplace_matrix_apply, adj_matrix_apply, H_neq, if_false]\n\n-- 2. The Laplacian matrix is symmetric.\n@[simp]\nlemma transpose_laplace_matrix : (G.laplace_matrix R)ᵀ = G.laplace_matrix R :=\nbegin\n  ext i j,\n  by_cases H : (i = j),\n  { simp only [H, transpose_apply] },\n  { rw [transpose_apply, G.laplace_matrix_neq R H, G.laplace_matrix_neq R (ne.symm H)],\n    simp [edge_symm] }\nend\n\nlemma filter_eq_neq_empty {i : V} [decidable_eq V] : filter (eq i) (univ \\ {i}) = ∅ :=\nby { ext, tidy }\n\nlemma filter_id {i : V}: filter (λ (x : V), ¬i = x) (univ \\ {i}) = (univ \\ {i}) :=\nby { ext, tidy }\n\n-- 3. The sum of elements on any row of the Laplacian is zero.\nlemma sum_of_laplace_row_equals_zero {i : V} : ∑ (j : V), G.laplace_matrix R i j = 0 :=\nbegin\n  rw [sum_eq_add_sum_diff_singleton (mem_univ i), laplace_matrix_eq],\n  simp only [laplace_matrix_apply, sum_ite, filter_eq_neq_empty, filter_id, adj_matrix_apply],\n  rw [sum_neg_distrib, sum_boole, sum_const, card_empty, zero_smul, zero_add],\n  rw degree_eq_sum_of_adj_matrix_row,\n  have H : filter (λ (x : V), G.adj i x) (univ \\ {i}) = filter (G.adj i) univ,\n  { ext,\n    simp only [true_and, mem_filter, mem_sdiff, and_iff_right_iff_imp, mem_univ, mem_singleton],\n    intro hyp,\n    exact ne.symm (G.ne_of_adj hyp) },\n  simp only [H, adj_matrix_apply, sum_boole, add_right_neg, eq_self_iff_true],\nend\n\n-- ## Degree matrix D\n\n/-- `degree_matrix G` is the matrix `D` with `∀ i j ∈ V` :\n` | D i j = 0` if `i` ≠ `j`\n` | D i j = G.degree i` otherwise. -/\ndef degree_matrix : matrix V V R\n| i j := if i = j then G.degree i else 0\n\n@[simp]\nlemma degree_matrix_apply {i j : V} :\n  G.degree_matrix R i j = if i = j then G.degree i else 0 := rfl\n\nlemma degree_matrix_eq {i j : V} (H_eq : i = j) : G.degree_matrix R i j = G.degree i :=\nby { rw H_eq, simp only [degree_matrix_apply, if_true, eq_self_iff_true] }\n\nlemma degree_matrix_neq {i j : V} (H_neq : i ≠ j) : G.degree_matrix R i j = 0 :=\nby simp only [degree_matrix_apply, H_neq, if_false]\n\n-- 4. L = D - A.\nlemma laplace_eq_degree_minus_adj :\n  G.laplace_matrix R = G.degree_matrix R - G.adj_matrix R :=\nbegin\n  ext,\n  by_cases H : (i = j),\n  { rw [G.laplace_matrix_eq R H, dmatrix.sub_apply, G.degree_matrix_eq R H,\n        G.adj_matrix_eq R H, sub_zero] },\n  { rw [G.laplace_matrix_neq R H, dmatrix.sub_apply, G.degree_matrix_neq R H, zero_sub] }\nend\n\n-- ## Signless Laplace matrix Q\n\ndef signless_laplace_matrix : matrix V V R := G.degree_matrix R + G.adj_matrix R\n\n@[simp]\nlemma signless_laplace_matrix_apply {i j : V} :\n  G.signless_laplace_matrix R i j = (G.degree_matrix R + G.adj_matrix R) i j := rfl\n\n-- 5. Q = M ⬝ Mᵀ.\nlemma signless_laplace_decomposition : G.signless_laplace_matrix R = G.inc_matrix R ⬝ (G.inc_matrix R)ᵀ :=\nbegin\n  ext,\n  by_cases H_ij : i = j,\n  { rw [signless_laplace_matrix_apply, dmatrix.add_apply, G.adj_matrix_eq R H_ij, add_zero],\n    rw [mul_apply, G.degree_matrix_eq R H_ij, H_ij, degree_equals_sum_of_incidence_row],\n    simp only [transpose_apply, inc_matrix_element_power_id] },\n  { rw [signless_laplace_matrix_apply, dmatrix.add_apply, G.degree_matrix_neq R H_ij, zero_add],\n    rw [mul_apply],\n    by_cases H_adj : G.adj i j,\n    { simp only [G.adj_matrix_adj R H_adj, transpose_apply, G.adj_sum_of_prod_inc_one R H_adj] },\n    { simp only [G.adj_matrix_not_adj R H_adj, transpose_apply,\n                 G.inc_matrix_prod_non_adj R H_ij H_adj, sum_const_zero] } }\nend\n\ndef edge_from_vertices (i j : V) (H_adj : G.adj i j) : G.edge_set := ⟨⟦(i, j)⟧, G.mem_edge_set.mpr H_adj⟩\n\n@[simp]\nlemma edge_from_vertices_iff {i j : V} {e : G.edge_set} (H_adj : G.adj i j) :\n   e = G.edge_from_vertices i j H_adj ↔ e.val = ⟦(i, j)⟧ :=\nbegin\n  split,\n  { intro hyp, simp only [edge_from_vertices, hyp] },\n  { intro hyp, tidy }\nend\n\n-- 6. L = N(o) ⬝ N(o)ᵀ, for any orientation o.\nlemma laplace_decomposition (o : orientation G) :\n  G.laplace_matrix R = G.dir_inc_matrix R o ⬝ (G.dir_inc_matrix R o)ᵀ :=\nbegin\n  ext i j,\n  by_cases H_ij : i = j,\n  { rw [G.laplace_matrix_eq R H_ij, mul_apply, H_ij, G.degree_equals_sum_of_incidence_row R],\n    simp only [transpose_apply, G.dir_inc_matrix_elem_squared R] },\n  { rw [G.laplace_matrix_neq R H_ij, mul_apply],\n    by_cases H_adj : G.adj i j,\n    { simp only [G.adj_matrix_adj R H_adj, transpose_apply, G.dir_inc_matrix_prod_of_adj R H_adj],\n      have key : ∀ (e : G.edge_set), ite (e.val = ⟦(i, j)⟧) (-1 : R) 0 = - ite (e.val = ⟦(i, j)⟧) 1 0,\n      { intro e,\n        convert (apply_ite (λ x : R, -x) (e.val = ⟦(i, j)⟧) (1 : R) (0 : R)).symm,\n        rw neg_zero },\n      have sum : ∑ (e : G.edge_set), ite (e.val = ⟦(i, j)⟧) (-1 : R) 0 =\n                 ∑ (e : G.edge_set), - ite (e.val = ⟦(i, j)⟧) (1 : R) 0,\n      { simp only [key] },\n      rw [sum, sum_hom, neg_inj, sum_boole],\n      have key : filter (λ (e : G.edge_set), e.val = ⟦(i, j)⟧) univ = {G.edge_from_vertices i j H_adj},\n      { ext,\n        simp only [true_and, mem_filter, mem_univ, mem_singleton],\n        rw G.edge_from_vertices_iff H_adj },\n      rw key,\n      simp only [nat.cast_one, card_singleton] },\n    { simp only [G.adj_matrix_not_adj R H_adj, transpose_apply,\n                 G.dir_inc_matrix_prod_non_adj R H_ij H_adj, sum_const_zero, neg_zero] } }\nend\n\n-- 7. The Laplacian is a quadratic form : xᵀ ⬝ L ⬝ x = ∑ e : G.edge_set, (x head(e) - x tail(e)) ^ 2.\nlemma laplace_quadratic_form {o : orientation G} (x : V → R) :\n  dot_product (vec_mul x (G.laplace_matrix R)) x = ∑ e : G.edge_set, (x (o.head e) - x (o.tail e)) ^ 2 :=\nby calc dot_product (vec_mul x (G.laplace_matrix R)) x\n       = dot_product (vec_mul x (G.dir_inc_matrix R o ⬝ (G.dir_inc_matrix R o)ᵀ)) x :\n   by { rw laplace_decomposition }                          -- xᵀ ⬝ L ⬝ x = xᵀ ⬝ (N ⬝ Nᵀ) ⬝ x\n   ... = dot_product (vec_mul (vec_mul x (G.dir_inc_matrix R o)) (G.dir_inc_matrix R o)ᵀ) x :\n   by { rw ← vec_mul_vec_mul }                                     -- ... = (xᵀ ⬝ N) ⬝ Nᵀ ⬝ x\n   ... = dot_product (λ j, dot_product (vec_mul x (G.dir_inc_matrix R o)) (λ i, (G.dir_inc_matrix R o)ᵀ i j)) x :\n   by { apply dot_product_helper, ext, unfold vec_mul }\n   ... = dot_product (vec_mul x (G.dir_inc_matrix R o)) (λ (e : G.edge_set), dot_product ((G.dir_inc_matrix R o)ᵀ e) x) :\n   by { rw dot_product_assoc }\n   ... = dot_product (vec_mul x (G.dir_inc_matrix R o)) ((G.dir_inc_matrix R o)ᵀ.mul_vec x) :\n   by { exact dot_product_helper rfl, }                            -- ... = (xᵀ ⬝ N) ⬝ (Nᵀ ⬝ x)\n   ... = dot_product (vec_mul x (G.dir_inc_matrix R o)) (vec_mul x (G.dir_inc_matrix R o)) :\n   by { rw mul_vec_transpose }                                     -- ... = (xᵀ ⬝ N) ⬝ (xᵀ ⬝ N)ᵀ\n   ... = ∑ e : G.edge_set, (x (o.head e) - x (o.tail e)) ^ 2 :\n   by { simp only [dot_product, vec_mul_dir_inc_matrix], ring_nf } -- = ∑ e, (x head(e) - x tail(e)) ^ 2\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/laplacian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.779857140359526}}
{"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 data.equiv.fin\nimport data.equiv.embedding\n\n/-!\n# Number of embeddings\n\nThis file establishes the cardinality of `α ↪ β` in full generality.\n-/\n\nlocal notation `|` x `|` := finset.card x\nlocal notation `‖` x `‖` := fintype.card x\n\nopen_locale nat\n\nlocal attribute [semireducible] function.embedding.fintype\n\nnamespace fintype\n\n-- We need the separate `fintype α` instance as it contains data,\n-- and may not match definitionally with the instance coming from `unique.fintype`.\nlemma card_embedding_eq_of_unique\n  {α β : Type*} [unique α] [fintype α] [fintype β] [decidable_eq α] [decidable_eq β]:\n‖α ↪ β‖ = ‖β‖ := card_congr equiv.unique_embedding_equiv_result\n\nprivate lemma card_embedding_aux {n : ℕ} {β} [fintype β] [decidable_eq β] (h : n ≤ ‖β‖) :\n  ‖fin n ↪ β‖ = ‖β‖.desc_factorial n :=\nbegin\n  induction n with n hn,\n  { nontriviality (fin 0 ↪ β),\n    rw [nat.desc_factorial_zero, fintype.card_eq_one_iff],\n    refine ⟨nonempty.some nontrivial.to_nonempty, λ x, function.embedding.ext fin.elim0⟩ },\n\n  rw [nat.succ_eq_add_one, ←card_congr (equiv.embedding_congr fin_sum_fin_equiv (equiv.refl β)),\n    card_congr equiv.sum_embedding_equiv_sigma_embedding_restricted],\n  -- these `rw`s create goals for instances, which it doesn't infer for some reason\n  all_goals { try { apply_instance } },\n  -- however, this needs to be done here instead of at the end\n  -- else, a later `simp`, which depends on the `fintype` instance, won't work.\n\n  have : ∀ (f : fin n ↪ β), ‖fin 1 ↪ ((set.range f)ᶜ : set β)‖ = ‖β‖ - n,\n  { intro f,\n    rw card_embedding_eq_of_unique,\n    rw card_of_finset' (finset.map f finset.univ)ᶜ,\n    { rw [finset.card_compl, finset.card_map, finset.card_fin] },\n    { simp } },\n\n  -- putting `card_sigma` in `simp` causes it to not fully simplify\n  rw card_sigma,\n  simp only [this, finset.sum_const, finset.card_univ, nsmul_eq_mul, nat.cast_id],\n\n  replace h := (nat.lt_of_succ_le h).le,\n  rw [nat.desc_factorial_succ, hn h, mul_comm]\nend\n\n/- Establishes the cardinality of the type of all injections between two finite types. -/\n@[simp] theorem card_embedding_eq {α β} [fintype α] [fintype β] [decidable_eq α] [decidable_eq β] :\n‖α ↪ β‖ = (‖β‖.desc_factorial ‖α‖) :=\nbegin\n  obtain h | h := lt_or_ge (‖β‖) (‖α‖),\n  { rw [card_eq_zero_iff.mpr (function.embedding.is_empty_of_card_lt h),\n        nat.desc_factorial_eq_zero_iff_lt.mpr h] },\n  { trunc_cases fintype.trunc_equiv_fin α with eq,\n    rw fintype.card_congr (equiv.embedding_congr eq (equiv.refl β)),\n    exact card_embedding_aux h }\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 {α β} [infinite α] [fintype β] : ‖α ↪ β‖ = 0 :=\ncard_eq_zero_iff.mpr function.embedding.is_empty\n\nend fintype\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/card_embedding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7797862426947915}}
{"text": "import algebra.big_operators.basic\nimport algebra.big_operators.nat_antidiagonal\nimport algebra.big_operators.ring\nimport data.finset.nat_antidiagonal\nimport data.real.basic\nimport tactic\n\nnamespace OSK2002_5\n\nopen_locale big_operators\n\n-- Lemma by Eric Wieser from the Xena Project Discord\nlemma pow_sub_pow {R} [ring R] {a b : R} (h : commute a b) {n : ℕ} :\n  a^n.succ - b^n.succ = (a - b) * ∑ x in finset.nat.antidiagonal n, a^x.1 * b^x.2 :=\nbegin\n  rw [sub_mul, sub_eq_sub_iff_add_eq_add, finset.mul_sum, finset.mul_sum],\n  simp_rw [(h.symm.pow_right _).left_comm, ←mul_assoc a, ←pow_succ],\n  transitivity ∑ x in finset.nat.antidiagonal n.succ, a^x.1 * b^x.2,\n  { rw [finset.nat.sum_antidiagonal_succ', pow_zero, mul_one], },\n  { rw [finset.nat.sum_antidiagonal_succ, pow_zero, one_mul, add_comm] },\nend\n\nlemma cube_sub_cube {a b : ℝ} : a^3 - b^3 = (a - b) * (a^2 + a * b + b^2) := by ring\n\n-- Added hypothesis that a ≠ 0 that's missing from the original statement \ntheorem osk2002_5 {a : ℝ} (h : a ≠ 0) : a^3 - a^(-3 : ℤ) = (a - (1 / a)) * (a^2 + 1 + (1 / a^2)) :=\nbegin\n  rw zpow_neg,\n  rw ← inv_zpow,\n  rw inv_eq_one_div,\n  norm_cast,\n  rw ← one_div_pow,\n  have h1 : 1 = a * (1 / a),\n  { rw mul_one_div,\n    rw div_self,\n    exact h,},\n  nth_rewrite_rhs 1 h1,\n  rw cube_sub_cube,\nend\n\nend OSK2002_5", "meta": {"author": "Faris999", "repo": "indonesian-mo-formalization", "sha": "7191b73028675adf5b1fe73151d88d0bb1967797", "save_path": "github-repos/lean/Faris999-indonesian-mo-formalization", "path": "github-repos/lean/Faris999-indonesian-mo-formalization/indonesian-mo-formalization-7191b73028675adf5b1fe73151d88d0bb1967797/src/2002/osk/05-2002-osk.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.779786241107413}}
{"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 number_theory.padics.padic_val\n\n/-!\n# p-adic norm\n\nThis file defines the p-adic norm on ℚ.\n\nThe p-adic valuation on ℚ 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 ℚ. This norm is a nonarchimedean absolute value.\nIt takes values in {0} ∪ {1/p^k | k ∈ ℤ}.\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êa, *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/--\nIf `q ≠ 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 : ℕ) (q : ℚ) : ℚ :=\nif q = 0 then 0 else (↑p : ℚ) ^ (-(padic_val_rat p q))\n\nnamespace padic_norm\n\nsection padic_norm\nopen padic_val_rat\nvariables (p : ℕ)\n\n/-- Unfolds the definition of the p-adic norm of `q` when `q ≠ 0`. -/\n@[simp] protected lemma eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :\n  padic_norm p q = p ^ (-(padic_val_rat p q)) :=\nby simp [hq, padic_norm]\n\n/-- The p-adic norm is nonnegative. -/\nprotected lemma nonneg (q : ℚ) : 0 ≤ 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/-- The p-adic norm of 0 is 0. -/\n@[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm]\n\n/-- The p-adic norm of 1 is 1. -/\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 : ℕ} (hp : 1 < p) : padic_norm p p = 1 / p :=\nby simp [padic_norm, (pos_of_gt hp).ne', padic_val_nat.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 : ℕ) [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 : ℕ} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p ≠ 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 : ℕ} (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 : ℕ) [fact p.prime] : padic_norm p p < 1 :=\npadic_norm_p_lt_one $ nat.prime.one_lt (fact.out _)\n\n/-- `padic_norm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/\nprotected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padic_norm p q = p ^ (-z) :=\n⟨ (padic_val_rat p q), by simp [padic_norm, hq] ⟩\n\n/-- `padic_norm p` is symmetric. -/\n@[simp] protected lemma neg (q : ℚ) : 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/-- If `q ≠ 0`, then `padic_norm p q ≠ 0`. -/\nprotected lemma nonzero {q : ℚ} (hq : q ≠ 0) : padic_norm p q ≠ 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/-- If the p-adic norm of `q` is 0, then `q` is 0. -/\nlemma zero_of_padic_norm_eq_zero {q : ℚ} (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/-- The p-adic norm is multiplicative. -/\n@[simp] protected theorem mul (q r : ℚ) : 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 ≠ 0, from mul_ne_zero hq hr,\n  have (↑p : ℚ) ≠ 0, by simp [hp.1.ne_zero],\n  by simp [padic_norm, *, padic_val_rat.mul, zpow_add₀ this, mul_comm]\n\n/-- The p-adic norm respects division. -/\n@[simp] protected theorem div (q r : ℚ) : 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 [←padic_norm.mul, div_mul_cancel _ hr])\n\n/-- The p-adic norm of an integer is at most 1. -/\nprotected theorem of_int (z : ℤ) : padic_norm p ↑z ≤ 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, neg_nonpos],\n      norm_cast, simp }},\n  exact_mod_cast hz,\nend\n\nprivate lemma nonarchimedean_aux {q r : ℚ} (h : padic_val_rat p q ≤ padic_val_rat p r) :\n  padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) :=\nhave hnqp : padic_norm p q ≥ 0, from padic_norm.nonneg _ _,\nhave hnrp : padic_norm p r ≥ 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 : ℚ} :\n  padic_norm p (q + r) ≤ 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 : ℚ) : padic_norm p (q + r) ≤ padic_norm p q + padic_norm p r :=\ncalc padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p\n                       ... ≤ 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 : ℚ} : padic_norm p (q - r) ≤ max (padic_norm p q) (padic_norm p r) :=\nby rw [sub_eq_add_neg, ←padic_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 : ℚ} (hne : padic_norm p q ≠ 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 ≤ 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               ... ≤ 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 ≤ 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 ≤ 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 : ℕ} {z : ℤ} : ↑(p^n) ∣ z ↔ padic_norm p z ≤ ↑p ^ (-n : ℤ) :=\nbegin\n  unfold padic_norm, split_ifs with hz,\n  { norm_cast at hz,\n    have : 0 ≤ (p^n : ℚ), {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,\n      padic_val_int.of_ne_one_ne_zero hp.1.ne_one _],\n    { norm_cast,\n      rw [← enat.coe_le_coe, enat.coe_get, ← 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": "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_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7797862408568497}}
{"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 7a030ab8eb5d99f05a891dccc49c5b5b90c947d3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.GCDMonoid.Finset\nimport Mathlib.Data.Polynomial.FieldDivision\nimport Mathlib.Data.Polynomial.EraseLead\nimport Mathlib.Data.Polynomial.CancelLeads\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 : R[X]`.\n - `p.content` is the `gcd` of the coefficients of `p`.\n - `p.IsPrimitive` 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.NormalizedGcdMonoid`:\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/-- A polynomial is primitive when the only constant polynomials dividing it are units -/\ndef IsPrimitive (p : R[X]) : Prop :=\n  ∀ r : R, C r ∣ p → IsUnit r\n#align polynomial.is_primitive Polynomial.IsPrimitive\n\ntheorem isPrimitive_iff_isUnit_of_c_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r :=\n  Iff.rfl\nset_option linter.uppercaseLean3 false in\n#align polynomial.is_primitive_iff_is_unit_of_C_dvd Polynomial.isPrimitive_iff_isUnit_of_c_dvd\n\n@[simp]\ntheorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h =>\n  isUnit_C.mp (isUnit_of_dvd_one h)\n#align polynomial.is_primitive_one Polynomial.isPrimitive_one\n\ntheorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by\n  rintro r ⟨q, h⟩\n  exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h])\n#align polynomial.monic.is_primitive Polynomial.Monic.isPrimitive\n\ntheorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by\n  rintro rfl\n  exact (hp 0 (dvd_zero (C 0))).ne_zero rfl\n#align polynomial.is_primitive.ne_zero Polynomial.IsPrimitive.ne_zero\n\ntheorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ 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\nend Primitive\n\nvariable {R : Type _} [CommRing R] [IsDomain R]\n\nsection NormalizedGCDMonoid\n\nvariable [NormalizedGCDMonoid R]\n\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\ntheorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by\n  by_cases h : n ∈ p.support\n  · 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@[simp]\ntheorem content_C {r : R} : (C r).content = normalize r := by\n  rw [content]\n  by_cases h0 : r = 0\n  · simp [h0]\n  have h : (C r).support = {0} := support_monomial _ h0\n  simp [h]\nset_option linter.uppercaseLean3 false in\n#align polynomial.content_C Polynomial.content_C\n\n@[simp]\ntheorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero]\n#align polynomial.content_zero Polynomial.content_zero\n\n@[simp]\ntheorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one]\n#align polynomial.content_one Polynomial.content_one\n\ntheorem content_X_mul {p : R[X]} : content (X * p) = content p := by\n  rw [content, content, Finset.gcd_def, Finset.gcd_def]\n  refine' congr rfl _\n  have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ :=\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 with a\n    · simp [coeff_X_mul_zero, Nat.succ_ne_zero]\n    rw [mul_comm, coeff_mul_X]\n    constructor\n    · intro h\n      use a\n      simp [h]\n    · rintro ⟨b, ⟨h1, h2⟩⟩\n      rw [← 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]\nset_option linter.uppercaseLean3 false in\n#align polynomial.content_X_mul Polynomial.content_X_mul\n\n@[simp]\ntheorem content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 := by\n  induction' k with k hi\n  · simp\n  rw [pow_succ, content_X_mul, hi]\nset_option linter.uppercaseLean3 false in\n#align polynomial.content_X_pow Polynomial.content_X_pow\n\n@[simp]\ntheorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.content_X Polynomial.content_X\n\ntheorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by\n  by_cases h0 : r = 0; · simp [h0]\n  rw [content]; rw [content]; rw [← Finset.gcd_mul_left]\n  refine' congr (congr rfl _) _ <;> ext <;> simp [h0, mem_support_iff]\nset_option linter.uppercaseLean3 false in\n#align polynomial.content_C_mul Polynomial.content_C_mul\n\n@[simp]\ntheorem content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by\n  rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one]\n#align polynomial.content_monomial Polynomial.content_monomial\n\ntheorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by\n  rw [content, Finset.gcd_eq_zero_iff]\n  constructor <;> intro h\n  · ext n\n    by_cases h0 : n ∈ p.support\n    · rw [h n h0, coeff_zero]\n    · rw [mem_support_iff] at h0\n      push_neg  at h0\n      simp [h0]\n  · intro x\n    simp [h]\n#align polynomial.content_eq_zero_iff Polynomial.content_eq_zero_iff\n\n-- Porting note: this reduced with simp so created `normUnit_content` and put simp on it\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@[simp]\ntheorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by\n  by_cases hp0 : p.content = 0\n  . simp [hp0]\n  . ext\n    apply mul_left_cancel₀ hp0\n    erw [← normalize_apply, normalize_content, mul_one]\n\ntheorem content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.natDegree < n) :\n    p.content = (Finset.range n).gcd p.coeff := by\n  apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd\n  · rw [Finset.dvd_gcd_iff]\n    intro i _\n    apply content_dvd_coeff _\n  · 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_natDegree_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\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\ntheorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) :\n    p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by\n  by_cases h : p = 0\n  · simp [h]\n  rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne.def, ← mem_support_iff] at h\n  rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content,\n    eraseLead_support]\n  refine' congr rfl (Finset.gcd_congr rfl fun i hi => _)\n  rw [Finset.mem_erase] at hi\n  rw [eraseLead_coeff, if_neg hi.1]\n#align polynomial.content_eq_gcd_leading_coeff_content_erase_lead Polynomial.content_eq_gcd_leadingCoeff_content_eraseLead\n\ntheorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by\n  rw [C_dvd_iff_dvd_coeff]\n  constructor\n  · intro h i\n    apply h.trans (content_dvd_coeff _)\n  · intro h\n    rw [content, Finset.dvd_gcd_iff]\n    intro i _\n    apply h i\nset_option linter.uppercaseLean3 false in\n#align polynomial.dvd_content_iff_C_dvd Polynomial.dvd_content_iff_C_dvd\n\ntheorem C_content_dvd (p : R[X]) : C p.content ∣ p :=\n  dvd_content_iff_C_dvd.1 dvd_rfl\nset_option linter.uppercaseLean3 false in\n#align polynomial.C_content_dvd Polynomial.C_content_dvd\n\ntheorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by\n  rw [← normalize_content, normalize_eq_one, IsPrimitive]\n  simp_rw [← dvd_content_iff_C_dvd]\n  exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩\n#align polynomial.is_primitive_iff_content_eq_one Polynomial.isPrimitive_iff_content_eq_one\n\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\nsection PrimPart\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.primPart = 1`.  -/\nnoncomputable def 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\ntheorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by\n  by_cases h : p = 0; · simp [h]\n  rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)]\nset_option linter.uppercaseLean3 false in\n#align polynomial.eq_C_content_mul_prim_part Polynomial.eq_C_content_mul_primPart\n\n@[simp]\ntheorem primPart_zero : primPart (0 : R[X]) = 1 :=\n  if_pos rfl\n#align polynomial.prim_part_zero Polynomial.primPart_zero\n\ntheorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by\n  by_cases h : p = 0; · simp [h]\n  rw [← content_eq_zero_iff] at h\n  rw [isPrimitive_iff_content_eq_one]\n  apply mul_left_cancel₀ h\n  conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content]\n#align polynomial.is_primitive_prim_part Polynomial.isPrimitive_primPart\n\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\n\ntheorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by\n  by_cases h : C p.content = 0\n  · rw [C_eq_zero, content_eq_zero_iff] at h\n    simp [h]\n  conv_rhs =>\n    rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add]\n#align polynomial.nat_degree_prim_part Polynomial.natDegree_primPart\n\n@[simp]\ntheorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by\n  rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart]\n#align polynomial.is_primitive.prim_part_eq Polynomial.IsPrimitive.primPart_eq\n\ntheorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by\n  by_cases h0 : r = 0\n  · simp [h0]\n  unfold IsUnit\n  refine'\n    ⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by\n        rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩,\n      _⟩\n  rw [← normalize_eq_zero, ← C_eq_zero] at h0\n  apply mul_left_cancel₀ h0\n  conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart]\n  simp only [Units.val_mk, normalize_apply, RingHom.map_mul]\n  rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one]\nset_option linter.uppercaseLean3 false in\n#align polynomial.is_unit_prim_part_C Polynomial.isUnit_primPart_C\n\ntheorem primPart_dvd (p : R[X]) : p.primPart ∣ 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\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 ≠ 0) (hp : aeval s p = 0) :\n    aeval s p.primPart = 0 := by\n  rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp\n  have hcont : p.content ≠ 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\ntheorem eval₂_primPart_eq_zero {S : Type _} [CommRing S] [IsDomain S] {f : R →+* S}\n    (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : eval₂ f s p = 0) :\n    eval₂ f s p.primPart = 0 := by\n  rw [eq_C_content_mul_primPart p, eval₂_mul, eval₂_C] at hp\n  have hcont : p.content ≠ 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₂_prim_part_eq_zero Polynomial.eval₂_primPart_eq_zero\n\nend PrimPart\n\ntheorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) :\n    GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by\n  rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).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.natDegree q.natDegree).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 _\n  cases' h with w hw\n  use w.coeff x\n  rw [← coeff_sub, hw, coeff_C_mul]\n#align polynomial.gcd_content_eq_of_dvd_sub Polynomial.gcd_content_eq_of_dvd_sub\n\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 := by\n  rw [gcd_comm (content _) _, gcd_comm (content _) _]\n  apply gcd_content_eq_of_dvd_sub\n  rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,\n    sub_sub_cancel, leadingCoeff_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@[simp]\ntheorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by\n  classical\n    suffices h :\n      ∀ (n : ℕ) (p q : R[X]), (p * q).degree < n → (p * q).content = p.content * q.content\n    · apply h\n      apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _))\n    intro n\n    induction' n with n ih\n    · intro p q hpq\n      dsimp at hpq\n      rw [Nat.cast_withBot, WithBot.coe_zero,\n        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    · simp [p0]\n    by_cases q0 : q = 0\n    · simp [q0]\n    rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_withBot,\n      Nat.cast_withBot, WithBot.coe_lt_coe, Nat.lt_succ_iff_lt_or_eq, ←\n      WithBot.coe_lt_coe, ←Nat.cast_withBot, ← degree_eq_natDegree (mul_ne_zero p0 q0),\n      natDegree_mul p0 q0] at hpq\n    rcases hpq with (hlt | heq)\n    · apply ih _ _ hlt\n    rw [← p.natDegree_primPart, ← q.natDegree_primPart, ← WithBot.coe_eq_coe,\n      WithBot.coe_add, ← Nat.cast_withBot, ←degree_eq_natDegree p.primPart_ne_zero,\n      ← Nat.cast_withBot, ← degree_eq_natDegree q.primPart_ne_zero] at heq\n    rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart]\n    suffices h : (q.primPart * p.primPart).content = 1\n    ·\n      rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul,\n        content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one]\n    rw [← normalize_content, normalize_eq_one, isUnit_iff_dvd_one,\n      content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm]\n    apply (gcd_mul_dvd_mul_gcd _ _ _).trans\n    rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ←\n      content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul,\n      mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ←\n      content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart]\n    · rw [Nat.cast_withBot, ← heq, degree_mul, WithBot.add_lt_add_iff_right]\n      · apply degree_erase_lt p.primPart_ne_zero\n      · rw [Ne.def, degree_eq_bot]\n        apply q.primPart_ne_zero\n    · rw [mul_comm, Nat.cast_withBot, ← heq, degree_mul, WithBot.add_lt_add_iff_left]\n      · apply degree_erase_lt q.primPart_ne_zero\n      · rw [Ne.def, degree_eq_bot]\n        apply p.primPart_ne_zero\n#align polynomial.content_mul Polynomial.content_mul\n\ntheorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :\n    (p * q).IsPrimitive := by\n  rw [isPrimitive_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@[simp]\ntheorem primPart_mul {p q : R[X]} (h0 : p * q ≠ 0) : (p * q).primPart = p.primPart * q.primPart :=\n  by\n  rw [Ne.def, ← content_eq_zero_iff, ← C_eq_zero] at h0\n  apply mul_left_cancel₀ h0\n  conv_lhs =>\n    rw [← (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_primPart,\n      q.eq_C_content_mul_primPart]\n  rw [content_mul, RingHom.map_mul]\n  ring\n#align polynomial.prim_part_mul Polynomial.primPart_mul\n\ntheorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q ≠ 0) :\n    p ∣ q.primPart ↔ p ∣ q := by\n  refine' ⟨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => _⟩\n  rcases h with ⟨r, rfl⟩\n  apply Dvd.intro _\n  rw [primPart_mul hq, hp.primPart_eq]\n#align polynomial.is_primitive.dvd_prim_part_iff_dvd Polynomial.IsPrimitive.dvd_primPart_iff_dvd\n\ntheorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :\n    ∃ r : R[X], r.IsPrimitive ∧ ∀ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s := by\n  classical\n    have h : ∃ (n : ℕ)(r : R[X]), r.natDegree = n ∧ r.IsPrimitive ∧ p ∣ r ∧ q ∣ r :=\n      ⟨(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩\n    rcases Nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩\n    refine' ⟨r, rprim, fun s => ⟨_, fun rs => ⟨pr.trans rs, qr.trans rs⟩⟩⟩\n    suffices hs : ∀ (n : ℕ) (s : R[X]), s.natDegree = n → p ∣ s ∧ q ∣ s → r ∣ s\n    · apply hs s.natDegree s rfl\n    clear s\n    by_contra' con\n    rcases Nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩\n    have s0 : s ≠ 0 := by\n      contrapose! rs\n      simp [rs]\n    have hs :=\n      Nat.find_min' h\n        ⟨_, s.natDegree_primPart, s.isPrimitive_primPart, (hp.dvd_primPart_iff_dvd s0).2 ps,\n          (hq.dvd_primPart_iff_dvd s0).2 qs⟩\n    rw [← rdeg] at hs\n    by_cases sC : s.natDegree ≤ 0\n    · rw [eq_C_of_natDegree_le_zero (le_trans hs sC), isPrimitive_iff_content_eq_one, content_C,\n        normalize_eq_one] at rprim\n      rw [eq_C_of_natDegree_le_zero (le_trans hs sC), ← dvd_content_iff_C_dvd] at rs\n      apply rs rprim.dvd\n    have hcancel := natDegree_cancelLeads_lt_of_natDegree_le_natDegree hs (lt_of_not_ge sC)\n    rw [sdeg] at hcancel\n    apply Nat.find_min con hcancel\n    refine'\n      ⟨_, rfl, ⟨dvd_cancelLeads_of_dvd_of_dvd pr ps, dvd_cancelLeads_of_dvd_of_dvd qr qs⟩,\n        fun rcs => rs _⟩\n    rw [← rprim.dvd_primPart_iff_dvd s0]\n    rw [cancelLeads, tsub_eq_zero_iff_le.mpr hs, pow_zero, mul_one] at rcs\n    have h :=\n      dvd_add rcs (Dvd.intro_left (C (leadingCoeff s) * X ^ (natDegree s - natDegree r)) rfl)\n    have hC0 := rprim.ne_zero\n    rw [Ne.def, ← leadingCoeff_eq_zero, ← C_eq_zero] at hC0\n    rw [sub_add_cancel, ← rprim.dvd_primPart_iff_dvd (mul_ne_zero hC0 s0)] at h\n    rcases isUnit_primPart_C r.leadingCoeff with ⟨u, hu⟩\n    apply h.trans (Associated.symm ⟨u, _⟩).dvd\n    rw [primPart_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\ntheorem dvd_iff_content_dvd_content_and_primPart_dvd_primPart {p q : R[X]} (hq : q ≠ 0) :\n    p ∣ q ↔ p.content ∣ q.content ∧ p.primPart ∣ q.primPart := by\n  constructor <;> intro h\n  · rcases h with ⟨r, rfl⟩\n    rw [content_mul, p.isPrimitive_primPart.dvd_primPart_iff_dvd hq]\n    exact ⟨Dvd.intro _ rfl, p.primPart_dvd.trans (Dvd.intro _ rfl)⟩\n  · rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart]\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\nnoncomputable instance (priority := 100) normalizedGcdMonoid : NormalizedGCDMonoid R[X] :=\n  normalizedGCDMonoidOfExistsLCM fun p q =>\n    by\n    rcases exists_primitive_lcm_of_isPrimitive p.isPrimitive_primPart\n        q.isPrimitive_primPart with\n      ⟨r, rprim, hr⟩\n    refine' ⟨C (lcm p.content q.content) * r, fun s => _⟩\n    by_cases hs : s = 0\n    · simp [hs]\n    by_cases hpq : C (lcm p.content q.content) = 0\n    · 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_primPart_dvd_primPart hs]\n    rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff,\n      primPart_mul (mul_ne_zero hpq rprim.ne_zero), rprim.primPart_eq,\n      IsUnit.mul_left_dvd _ _ _ (isUnit_primPart_C (lcm p.content q.content)), ← hr s.primPart]\n    tauto\n#align polynomial.normalized_gcd_monoid Polynomial.normalizedGcdMonoid\n\ntheorem degree_gcd_le_left {p : R[X]} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree := by\n  have := natDegree_le_iff_degree_le.mp (natDegree_le_of_dvd (gcd_dvd_left p q) hp)\n  rwa [degree_eq_natDegree hp]\n#align polynomial.degree_gcd_le_left Polynomial.degree_gcd_le_left\n\ntheorem degree_gcd_le_right (p) {q : R[X]} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree := 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\nend NormalizedGCDMonoid\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/Content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7797152475228274}}
{"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 algebraic_geometry.prime_spectrum\nimport ring_theory.polynomial.basic\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\nopen ideal polynomial prime_spectrum set\n\nnamespace algebraic_geometry\n\nnamespace polynomial\n\nvariables {R : Type*} [comm_ring R] {f : polynomial R}\n\n/-- Given a polynomial `f ∈ 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})ᶜ` under the morphism\n`comap C : Spec R[x] → Spec R`. -/\ndef image_of_Df (f) : set (prime_spectrum R) :=\n  {p : prime_spectrum R | ∃ i : ℕ , (coeff f i) ∉ p.as_ideal}\n\nlemma is_open_image_of_Df : is_open (image_of_Df f) :=\nbegin\n  rw [image_of_Df, set_of_exists (λ i (x : prime_spectrum R), coeff f i ∉ x.val)],\n  exact is_open_Union (λ i, is_open_basic_open),\nend\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`. -/\nlemma comap_C_mem_image_of_Df {I : prime_spectrum (polynomial R)}\n  (H : I ∈ (zero_locus {f} : set (prime_spectrum (polynomial R)))ᶜ ) :\n  comap (polynomial.C : R →+* polynomial R) I ∈ image_of_Df f :=\nexists_coeff_not_mem_C_inverse (mem_compl_zero_locus_iff_not_mem.mp H)\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C⁺ : Spec R[x] → Spec R`. -/\nlemma image_of_Df_eq_comap_C_compl_zero_locus :\n  image_of_Df f = comap C '' (zero_locus {f})ᶜ :=\nbegin\n  refine ext (λ x, ⟨λ hx, ⟨⟨map C x.val, (is_prime_map_C_of_is_prime x.property)⟩, ⟨_, _⟩⟩, _⟩),\n  { rw [mem_compl_eq, mem_zero_locus, singleton_subset_iff],\n    cases hx with i hi,\n    exact λ a, hi (mem_map_C_iff.mp a i) },\n  { refine subtype.ext (ext (λ x, ⟨λ h, _, λ h, subset_span (mem_image_of_mem C.1 h)⟩)),\n    rw ← @coeff_C_zero R x _,\n    exact mem_map_C_iff.mp h 0 },\n  { rintro ⟨xli, complement, rfl⟩,\n    exact comap_C_mem_image_of_Df complement }\nend\n\n/--  The morphism `C⁺ : Spec R[x] → Spec R` is open.\nStacks Project \"Lemma 00FB\", first part.\n\nhttps://stacks.math.columbia.edu/tag/00FB\n-/\ntheorem is_open_map_comap_C :\n  is_open_map (comap (C : R →+* polynomial R)) :=\nbegin\n  rintros U ⟨s, z⟩,\n  rw [← compl_compl U, ← z, ← Union_of_singleton_coe s, zero_locus_Union, compl_Inter, image_Union],\n  simp_rw [← image_of_Df_eq_comap_C_compl_zero_locus],\n  exact is_open_Union (λ f, is_open_image_of_Df),\nend\n\nend polynomial\n\nend algebraic_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/algebraic_geometry/is_open_comap_C.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7797152462193414}}
{"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\nlemma factorial_eq_prod (n : ℕ) : n.factorial = ∏ i in finset.Icc 1 n, i :=\nbegin\n  induction n with d hd,\n  { refl, },\n  { rw [nat.factorial_succ, hd],\n    rw finset.Icc_eq_cons_Ico (show 1 ≤ d + 1, by linarith),\n    rw finset.prod_cons,\n    congr', },\nend\n\nlemma wilson_theorem {p n : ℕ}\n  (hp : nat.prime p)\n  (hn : p = 4 * n + 1) :\n     ∏ (j : ℕ) in finset.Icc 1 (4 * n), (j : zmod p) = -1 :=\nbegin\n  have := (nat.prime_iff_fac_equiv_neg_one (_ : p ≠ 1)).1 hp,\n  { rw [← this, hn],\n    norm_cast,\n    congr',\n    simp,\n    rw factorial_eq_prod,\n  },\n  { exact nat.prime.ne_one hp, },\nend\n\nlemma exists_sqrt_neg_one_of_one_mod_four (p : ℕ) (hp : p.prime) \n  (hp2 : ∃ n, p = 4 * n + 1) : ∃ i : zmod p, i^2 = -1 :=\nbegin\n  cases hp2 with n hn,\n  set i := ∏ j in (finset.Icc 1 (2 * n)), (j : zmod p) with hi,\n  have h1 : ∏ j in (finset.Icc 1 (2 * n)), (-1 : zmod p) = 1,\n  { rw [finset.prod_const],\n    simp only [nat.add_succ_sub_one, add_zero, nat.card_Icc],\n    rw [pow_mul, neg_one_pow_two, one_pow], },\n  have h2 : ∏ j in (finset.Icc 1 (2 * n)), (-j : zmod p) = i,\n  { conv_lhs {\n      congr, skip, funext,\n      rw neg_eq_neg_one_mul,\n    },\n    rw [finset.prod_mul_distrib, h1, one_mul], },\n  have h3 : ∏ j in (finset.Icc (2 * n + 1) (4 * n)), (j : zmod p) = i,\n  { rw ←h2,\n    apply finset.prod_bij' (λ j hj, p - j) _ _ (λ j hj, p - j),\n    { intros,\n      dsimp,\n      rw finset.mem_Icc at ha,\n      cases ha,\n      omega, },\n    { intros,\n      dsimp,\n      rw finset.mem_Icc at ha,\n      omega, },\n    { intros,\n      dsimp,\n      rw finset.mem_Icc at ha ⊢,\n      omega, },\n    { intros,\n      dsimp,\n      rw finset.mem_Icc at ha ⊢,\n      omega, },\n    { intros,\n      dsimp,\n      rw finset.mem_Icc at ha,\n      rw eq_neg_iff_add_eq_zero,\n      suffices : a + (p - a) = p,\n      { norm_cast, \n        simp [this], },\n      omega, },\n  },\n  use i,\n  rw pow_two,\n  nth_rewrite 0 hi,\n  rw ←h3,\n  rw ← finset.prod_union, \n  { convert_to ∏ j in finset.Icc 1 (4 * n), (j : zmod p) = -1,\n    { congr',\n      ext,\n      rw finset.mem_union,\n      simp only [finset.mem_Icc],\n      omega, },\n    { apply wilson_theorem hp hn, }, },\n  { rw disjoint_iff_inf_le,\n    rintro x (hx : x ∈ _ ∩ _),\n    rw [finset.mem_inter, finset.mem_Icc, finset.mem_Icc] at hx,\n    rcases hx with ⟨⟨_, _⟩, _, _⟩,\n    linarith,\n  },\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/section15number_theory/sheet8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865197, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7797152422955573}}
{"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-/\n\nimport data.nat.interval\nimport data.polynomial.derivative\nimport tactic.linarith\n\n/-!\n# Theory of iterated derivative\nWe define and prove some lemmas about iterated (formal) derivative for polynomials over a semiring.\n-/\n\nnoncomputable theory\n\nopen finset nat polynomial\nopen_locale big_operators polynomial\n\nnamespace polynomial\nuniverses u\nvariable {R : Type u}\n\nsection semiring\n\nvariables [semiring R] (r : R) (f p q : R[X]) (n k : ℕ)\n\n/-- `iterated_deriv f n` is the `n`-th formal derivative of the polynomial `f` -/\ndef iterated_deriv : R[X] := derivative ^[n] f\n\n@[simp] lemma iterated_deriv_zero_right : iterated_deriv f 0 = f := rfl\n\nlemma iterated_deriv_succ : iterated_deriv f (n + 1) = (iterated_deriv f n).derivative :=\nby rw [iterated_deriv, iterated_deriv, function.iterate_succ']\n\n@[simp] lemma iterated_deriv_zero_left : iterated_deriv (0 : R[X]) n = 0 :=\nbegin\n  induction n with n hn,\n  { exact iterated_deriv_zero_right _ },\n  { rw [iterated_deriv_succ, hn, derivative_zero] },\nend\n\n@[simp] lemma iterated_deriv_add :\n  iterated_deriv (p + q) n = iterated_deriv p n + iterated_deriv q n :=\nbegin\n  induction n with n ih,\n  { simp only [iterated_deriv_zero_right], },\n  { simp only [iterated_deriv_succ, ih, derivative_add] }\nend\n\n@[simp] lemma iterated_deriv_smul : iterated_deriv (r • p) n = r • iterated_deriv p n :=\nbegin\n  induction n with n ih,\n  { simp only [iterated_deriv_zero_right] },\n  { simp only [iterated_deriv_succ, ih, derivative_smul] }\nend\n\n@[simp] lemma iterated_deriv_X_zero : iterated_deriv (X : R[X]) 0 = X :=\nby simp only [iterated_deriv_zero_right]\n\n@[simp] lemma iterated_deriv_X_one : iterated_deriv (X : R[X]) 1 = 1 :=\nby simp only [iterated_deriv, derivative_X, function.iterate_one]\n\n@[simp] lemma iterated_deriv_X (h : 1 < n) : iterated_deriv (X : R[X]) n = 0 :=\nbegin\n  induction n with n ih,\n  { exfalso, exact nat.not_lt_zero 1 h },\n  { simp only [iterated_deriv_succ],\n    by_cases H : n = 1,\n    { rw H, simp only [iterated_deriv_X_one, derivative_one] },\n    { replace h : 1 < n := array.push_back_idx h (ne.symm H),\n      rw ih h, simp only [derivative_zero] } }\nend\n\n\n@[simp] lemma iterated_deriv_C_zero : iterated_deriv (C r) 0 = C r :=\nby simp only [iterated_deriv_zero_right]\n\n@[simp] lemma iterated_deriv_C (h : 0 < n) : iterated_deriv (C r) n = 0 :=\nbegin\n  induction n with n ih,\n  { exfalso, exact nat.lt_asymm h h },\n  { by_cases H : n = 0,\n    { rw [iterated_deriv_succ, H], simp only [iterated_deriv_C_zero, derivative_C] },\n    { replace h : 0 < n := nat.pos_of_ne_zero H,\n      rw [iterated_deriv_succ, ih h], simp only [derivative_zero] } }\nend\n\n@[simp] lemma iterated_deriv_one_zero : iterated_deriv (1 : R[X]) 0 = 1 :=\nby simp only [iterated_deriv_zero_right]\n\n@[simp] lemma iterated_deriv_one : 0 < n → iterated_deriv (1 : R[X]) n = 0 := λ h,\nbegin\n  have eq1 : (1 : R[X]) = C 1 := by simp only [ring_hom.map_one],\n  rw eq1, exact iterated_deriv_C _ _ h,\nend\n\nend semiring\n\nsection ring\nvariables [ring R] (p q : R[X]) (n : ℕ)\n\n@[simp] lemma iterated_deriv_neg : iterated_deriv (-p) n = - iterated_deriv p n :=\nbegin\n  induction n with n ih,\n  { simp only [iterated_deriv_zero_right] },\n  { simp only [iterated_deriv_succ, ih, derivative_neg] }\nend\n\n@[simp] lemma iterated_deriv_sub :\n  iterated_deriv (p - q) n = iterated_deriv p n - iterated_deriv q n :=\nby rw [sub_eq_add_neg, iterated_deriv_add, iterated_deriv_neg, ←sub_eq_add_neg]\n\n\nend ring\n\nsection comm_semiring\nvariable [comm_semiring R]\nvariables (f p q : R[X]) (n k : ℕ)\n\nlemma coeff_iterated_deriv_as_prod_Ico :\n  ∀ m : ℕ, (iterated_deriv f k).coeff m = (∏ i in Ico m.succ (m + k.succ), i) * (f.coeff (m+k)) :=\nbegin\n  induction k with k ih,\n  { simp only [add_zero, forall_const, one_mul, Ico_self, eq_self_iff_true,\n      iterated_deriv_zero_right, prod_empty] },\n  { intro m, rw [iterated_deriv_succ, coeff_derivative, ih (m+1), mul_right_comm],\n    apply congr_arg2,\n    { have set_eq : (Ico m.succ (m + k.succ.succ)) = (Ico (m + 1).succ (m + 1 + k.succ)) ∪ {m+1},\n      { rw [union_comm, ←insert_eq, Ico_insert_succ_left, add_succ, add_succ, add_succ _ k,\n            ←succ_eq_add_one, succ_add],\n        rw succ_eq_add_one,\n        linarith },\n      rw [set_eq, prod_union],\n      apply congr_arg2,\n      { refl },\n      { simp only [prod_singleton], norm_cast },\n      { rw [disjoint_singleton_right, mem_Ico],\n        exact λ h, (nat.lt_succ_self _).not_le h.1 } },\n    { exact congr_arg _ (succ_add m k) } },\nend\n\nlemma coeff_iterated_deriv_as_prod_range :\n  ∀ m : ℕ, (iterated_deriv f k).coeff m = f.coeff (m + k) * (∏ i in range k, ↑(m + k - i)) :=\nbegin\n  induction k with k ih,\n  { simp },\n  intro m,\n  calc (f.iterated_deriv k.succ).coeff m\n      = f.coeff (m + k.succ) * (∏ i in range k, ↑(m + k.succ - i)) * (m + 1) :\n    by rw [iterated_deriv_succ, coeff_derivative, ih m.succ, succ_add, add_succ]\n  ... = f.coeff (m + k.succ) * (∏ i in range k, ↑(m + k.succ - i)) * ↑(m + 1) :\n    by push_cast\n  ... = f.coeff (m + k.succ) * (∏ i in range k.succ, ↑(m + k.succ - i)) :\n    by rw [prod_range_succ, add_tsub_assoc_of_le k.le_succ, succ_sub le_rfl, tsub_self, mul_assoc]\nend\n\nlemma iterated_deriv_eq_zero_of_nat_degree_lt (h : f.nat_degree < n) : iterated_deriv f n = 0 :=\nbegin\n  ext m,\n  rw [coeff_iterated_deriv_as_prod_range, coeff_zero, coeff_eq_zero_of_nat_degree_lt, zero_mul],\n  linarith\nend\n\nlemma iterated_deriv_mul :\n  iterated_deriv (p * q) n =\n  ∑ k in range n.succ,\n    (C (n.choose k : R)) * iterated_deriv p (n - k) * iterated_deriv q k :=\nbegin\n  induction n with n IH,\n  { simp },\n\n  calc (p * q).iterated_deriv n.succ\n      = (∑ (k : ℕ) in range n.succ,\n           C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv k).derivative :\n    by rw [iterated_deriv_succ, IH]\n  ... = ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k + 1) * q.iterated_deriv k +\n        ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) :\n    by simp_rw [derivative_sum, derivative_mul, derivative_C, zero_mul, zero_add,\n                iterated_deriv_succ, sum_add_distrib]\n  ... = (∑ (k : ℕ) in range n.succ,\n            C ↑(n.choose k.succ) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) +\n          C ↑1 * p.iterated_deriv n.succ * q.iterated_deriv 0) +\n        ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) : _\n  ... = ∑ (k : ℕ) in range n.succ,\n          C ↑(n.choose k) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) +\n        ∑ (k : ℕ) in range n.succ,\n            C ↑(n.choose k.succ) * p.iterated_deriv (n - k) * q.iterated_deriv (k + 1) +\n        C ↑1 * p.iterated_deriv n.succ * q.iterated_deriv 0 :\n    by ring\n  ... = ∑ (i : ℕ) in range n.succ,\n          C ↑((n+1).choose (i+1)) * p.iterated_deriv (n + 1 - (i+1)) * q.iterated_deriv (i+1) +\n        C ↑1 * p.iterated_deriv n.succ * q.iterated_deriv 0 :\n    by simp_rw [choose_succ_succ, succ_sub_succ, cast_add, C.map_add, add_mul, sum_add_distrib]\n  ... = ∑ (k : ℕ) in range n.succ.succ,\n          C ↑(n.succ.choose k) * p.iterated_deriv (n.succ - k) * q.iterated_deriv k :\n    by rw [sum_range_succ' _ n.succ, choose_zero_right, tsub_zero],\n\n  congr,\n  refine (sum_range_succ' _ _).trans (congr_arg2 (+) _ _),\n  { rw [sum_range_succ, nat.choose_succ_self, cast_zero, C.map_zero, zero_mul, zero_mul, add_zero],\n    refine sum_congr rfl (λ 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  { rw [choose_zero_right, tsub_zero] },\nend\n\nend comm_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/iterated_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7796808177232688}}
{"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 : ℕ → ℕ → ℕ\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 → ℤ\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 → aexp\n| (aexp.add (aexp.num 0) e₂) := simplify e₂\n| (aexp.add e₁ (aexp.num 0)) := simplify e₁\n| (aexp.sub e₁ (aexp.num 0)) := simplify e₁\n| (aexp.mul (aexp.num 0) e₂) := aexp.num 0\n| (aexp.mul e₁ (aexp.num 0)) := aexp.num 0\n| (aexp.mul (aexp.num 1) e₂) := simplify e₂\n| (aexp.mul e₁ (aexp.num 1)) := simplify e₁\n| (aexp.div (aexp.num 0) e₂) := aexp.num 0\n| (aexp.div e₁ (aexp.num 0)) := aexp.num 0\n| (aexp.div e₁ (aexp.num 1)) := simplify e₁\n-- catch-all cases below\n| (aexp.num i)               := aexp.num i\n| (aexp.var x)               := aexp.var x\n| (aexp.add e₁ e₂)           := aexp.add (simplify e₁) (simplify e₂)\n| (aexp.sub e₁ e₂)           := aexp.sub (simplify e₁) (simplify e₂)\n| (aexp.mul e₁ e₂)           := aexp.mul (simplify e₁) (simplify e₂)\n| (aexp.div e₁ e₂)           := aexp.div (simplify e₁) (simplify e₂)\n\n/- 2.3. State (without proving it) the correctness lemma for `simplify`, namely\nthat the simplified expression should have the same semantics, with respect to\n`eval`, as the original expression. -/\n\nlemma simplify_correct (env : string → ℤ) (e : aexp) :\n  eval env (simplify e) = eval env e :=\nsorry\n\n\n/- ## Question 3: λ-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 : α → α :=\nλa, a\n\ndef K : α → β → α :=\nλa b, a\n\ndef C : (α → β → γ) → β → α → γ :=\nλg b a, g a b\n\ndef proj_1st : α → α → α :=\nλx y, x\n\n/- Please give a different answer than for `proj_1st`. -/\n\ndef proj_2nd : α → α → α :=\nλx y, y\n\ndef some_nonsense : (α → β → γ) → α → (α → γ) → β → γ :=\nλg 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 `–` (to draw\nhorizontal bars) and `⊢` useful. -/\n\n/- Let `D` := `g : α → β → γ, b : β, a : α`. We have\n\n    –––––––––––––––––– Var    –––––––––– Var\n    D ⊢ g : α → β → γ         D ⊢ a : α\n    –––––––––––––––––––––––––––––––––––– App    –––––––––– Var\n    D ⊢ g a : β → γ                             D ⊢ b : β\n    –––––––––––––––––––––––––––––––––––––––––––––––––––––– App\n    D ⊢ g a b : γ\n    ––––––––––––––––––––––––––––––––––––––––––– Lam\n    g : α → β → γ, b : β ⊢ (λa : α, g a b) : γ\n    –––––––––––––––––––––––––––––––––––––––––––––– Lam\n    g : α → β → γ ⊢ (λ(b : β) (a : α), g a b) : γ\n    ––––––––––––––––––––––––––––––––––––––––––––––– Lam\n    ⊢ (λ(g : α → β → γ) (b : β) (a : α), g a b) : γ -/\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/love01_definitions_and_statements_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7796164019885689}}
{"text": "/- \nHomeowork 9  \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\n\n\n\nopen PROOFS \nopen PROOFS.STR \n\n\nvariables {X : Type} {P : X → Prop}\n\n\n\n/- The first question is about __unique existence__. For instance, we know not only that there exists a natural `n` such that `n` is even and prime, but such a number is unique.  -/\n\n-- ∃! is the symbol for unique existence. \n\n#check exists_unique\n\n\nlemma uniquely_exists₁  : \n  (∃! x, P x) ↔ (∃ x, P x ∧ (∀ y : X, P y → y = x)) := \nbegin\n  rw exists_unique, \nend \n\n\n/-! ## Question 1 (20 pts): \nGive a proof of the following lemma. \n-/\n\nlemma uniquely_exists₂  : \n  (∃! x, P x) ↔ (∃ x, P x) ∧ (∀ y z : X, P y ∧ P z → y = z) := \nbegin\n  sorry, \nend \n\n\n\n\n\n\n/- Questions 2 and 3 concern the notion of quasigroup.  In below we define __quasigroup__ structures. A quasigroup structure consists of one binary operation `op` operations and left and right divisions (with respect `op` ). \n-/\n\nclass quasi_group_str (Q : Type) := \n(op : Q → Q → Q) -- a binary operation `op` on `Q` \n(left_div : Q → Q → Q)  \n(right_div : Q → Q → Q) \n(l := left_div) -- temporary notation, just inside this structure declaration\n(r := right_div) -- temporary notation, just inside this structure declaration \n(op_of_left_div : ∀ x y : Q, op x  (l x y) = y) -- finding column \n(left_div_of_op : ∀ x y : Q, l x (op x y) = y) -- unique column \n(op_of_right_div : ∀ x y : Q, op (r y x)  x = y)\n(right_div_of_op : ∀ x y : Q, r (op y  x) x  = y)\n\n\n\nlocal infix `#` :15 := quasi_group_str.op\nlocal infix ` \\\\ ` :15 := quasi_group_str.left_div -- `l x y` is `x \\\\ y`\nlocal infixl ` // ` :15 := quasi_group_str.right_div -- `r x y` is `y // x` \n\n\n/-! ## Question 2 (20 pts):\nShow that The integers ℤ with subtraction form a quasigroup. \n-/\ninstance : quasi_group_str ℤ := \n{ \n  op := λ x, λ y, x - y,\n  left_div := sorry,\n  right_div := sorry,\n  op_of_left_div := sorry,\n  left_div_of_op := sorry, \n  op_of_right_div := sorry, \n  right_div_of_op := sorry, \n}\n\n\n\n\n\n\n/-! ## Question 3 (20 pts)\n**(Part I)** :\n Prove the following simplification lemmas directly from the definitions above. \n-/\n\n@[simp]\nlemma mul_of_left_div_def {Q : Type} [quasi_group_str Q] (a b : Q) : \n  (a # (a \\\\ b)) = b := \nbegin\n  sorry, \nend \n\n\n@[simp]\nlemma left_div_of_mul_def {Q : Type} [quasi_group_str Q] (a b : Q) : \n  (a \\\\ (a # b)) = b := \nbegin\n  sorry, \nend \n\n\nlemma mul_of_right_div_def {Q : Type} [quasi_group_str Q] (a b : Q) : \n  ((b // a) # a) = b := \nbegin\n  sorry, \nend \n\n\nlemma right_div_of_mul_def {Q : Type} [quasi_group_str Q] (a b : Q) : \n  ((b # a) // a) = b := \nbegin\n  sorry,\nend \n\n\n\n/- \n## Question 3 (Part II): \n Prove the Latin square property of quasigroups. A __Latin square__ is an array filled with different symbols, each occurring exactly once in each row and exactly once in each column. \nAn example of a `3×3` Latin square with symbols `A B C` is\n\n                      A\tB\tC\n                      C\tA\tB\n                      B\tC\tA\n\nHint : Q1 should help you here.                       \n-/\n\ntheorem Latin_square_property {Q : Type} [quasi_group_str Q] : \n  ∀ a b : Q, (∃! x : Q, (a # x) = b) ∧ (∃! y : Q, (y # a) = b) := \nbegin\n  sorry,\nend    \n\n\n\n\n\n\n\n/- The notion of __monoid__ strucutre (`mult_monoid_str` and `additive_monoid_str`) was defined in lecture 12. -/\n\n@[ext]\nstructure positive_nat := \n(num : ℕ)\n(pos : 0 < num)\n\n\n\n\nlocal notation ` ℕ₊ `: 15 := positive_nat\n\n/- Fill in `sorry` placeholder in below.-/\ninstance : has_one ℕ₊ := sorry \n\n\n@[simp] \nlemma pos_nat_one_val : (1 : ℕ₊).num = 1 := \nbegin\n  sorry,  \nend \n\n/- Fill in `sorry` placeholder in below.-/\ninstance : has_mul ℕ₊ := sorry\n\n\n\n\n/-! ## Question 4 (20 pts):\nShow that the positive natural numbers admit a multiplicative monoid structure fy filling in the `sorry` placeholders in below. You should use the instances of type classes `has_one ℕ₊` and `has_mul ℕ₊` in above. Feel free to prove your own simplification lemmas if needed.  \n-/\n\ninstance : mult_monoid_str ℕ₊ := \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/-!  In below we define the __group__ structure. A group structure on a type `X` consists of a binary operation (e.g. multiplication, addition) and a unary operation of taking __inverse__.  \n-/\n\nclass additive_group_str (X : Type) extends additive_monoid_str X := \n(inv : X → X) \n(left_inv : ∀ x : X,  (inv x) + x =  0)\n(right_inv : ∀ x : X,  x + (inv x) = 0)\n\n\n\nclass mult_group_str (X : Type) extends mult_monoid_str X := \n(inv : X → X) \n(left_inv : ∀ x : X,  (inv x) * x =  1)\n(right_inv : ∀ x : X,  x * (inv x) = 1)\n\n-- our notation for inverse of an element. \npostfix `ⁱ` :std.prec.max_plus := mult_group_str.inv  \n\n\nsection\nvariables (G : Type) [mult_group_str G] (x : G)\n#check x\n#check xⁱ\nend \n\n\n\n\n/-! ## Question 5 (20 pts) : \nShow that the Gaussian integers with the opeation of addition form an additive group. -/\n\n\n-- instance : additive_group_str ℤ[i] := \n-- { inv := has_neg.neg,\n--   left_inv := by {intro x, ext; simp [gaussian_int.add_def]; simp [gaussian_int.neg_def],  },\n--   right_inv := by {intro x, ext; simp [gaussian_int.add_def]; simp [gaussian_int.neg_def],  }, }\n\n\n\n\n@[simp]\ntheorem add_im_def (x y : ℤ[i]) :\n  (x + y).im = x.im + y.im :=\nbegin\n  refl,\nend\n\n\nlemma gaussian_add_opposite {x : ℤ[i]} : -x + x = 0 :=\nbegin\next,\nrw gaussian_int.add_re_def,\nrw gaussian_int.neg_def,\nring_nf,\nrw gaussian_int.add_im_def,\nrw gaussian_int.neg_def,\nring_nf,\nend\n\n\ninstance : additive_group_str ℤ[i] := \n{ inv := has_neg.neg,\n  left_inv := by { intro z,  rw gaussian_add_opposite,  },\n  right_inv := by {intro x, ext; simp [gaussian_int.add_def]; simp [gaussian_int.neg_def],  }, }\n\n\n\n\n\n/-\nIn below we define the notion of __monoid morphism__. A monoid morphism between monoids `M` and `N` is given by a function `f : M → N` which preserves the multiplication operation. \n-/\n\nclass mult_monoid.morphism (M : Type) (N : Type) [mult_monoid_str M] [mult_monoid_str N] :=\n(to_fun : M → N)\n(resp_one : to_fun 1 = 1)\n(resp_mul : ∀ x y : M, to_fun (x * y) = to_fun x * to_fun y)\n\n\ninfixr ` →ₘ* `:25 := mult_monoid.morphism\n\n\n\n/-! ## Question 6 (20 pts):\nShow that the function from ℕ₊ → ℤ[i] which maps `n` to `n + 0i` is a multiplicative monoid morphism. \n-/\n\ninstance : ℕ₊ →ₘ* ℤ[i] := sorry \n\n\n\n\n\n\n\n\n/-! ## Question 7 (20 pts): \nShow that for a type `X` the automorphisms of `X` admits a group strucuture where the multiplication operation is given by the composition of functions. You might like to use some stuff we proved about `auto` in Lecture on unbundled strucutres. -/\n\ndef group_of_auto : mult_group_str (auto X) := \nsorry\n\n\n\n\n\n\n\n\n\n\n\n/-! ## Question 8 (20 pts): \nShow that the endomorphisms of any type form a monoid with composition of functions as monoid multiplication. \n-/ \n\ninstance monoid_of_endo : mult_monoid_str (endo X) := \nsorry \n\n\n\n\n\n\n\n\n/-! ## Question 9 (20 pts):\n**Part I :** Prove the following lemma. \n-/\nlemma inv_cancel_left {G : Type} [mult_group_str G] :\n  ∀ a b : G, (aⁱ) * (a * b) = b := \nbegin\n  sorry \nend   \n\n\n/-\n**Part II :** Use the previous lemma to prove the following cancellation property of multiplication for groups. \n-/\n\nlemma mul_left_cancel_group {G : Type} [mult_group_str G] :\n  ∀ a b c : G, (a * b = a * c) → b = c := \nbegin \n  sorry, \nend   \n\n\n\n\n\n/- \nIn below we define the __action__ of a monoid on a type. \n-/\n\nclass mult_monoid_action (M A : Type) [mult_monoid_str M] :=\n(smul : M → A → A) -- the scalar multiplication of `M` on `A`. \n(one_smul : ∀ (x : A), smul (1 : M) x = x)\n(mul_smul : ∀ (r s : M) (x : A), \nsmul (r * s)  x = smul r (smul s x))\n\n\n/- ## Question 10 (20 pts): \nGiven a monoid `M` and an action of `M` on a type `A` construct a monoid morphism from `M` to `endo A`. \n-/ \n\n\ndef monoid_morphism_of_monoid_action  (M A : Type) [mult_monoid_str M] [mult_monoid_action M A] : \nM →ₘ* (endo A) := \n{ to_fun := mult_monoid_action.smul ,\n  resp_one := by {funext, rw mult_monoid_action.one_smul,  },\n  resp_mul := sorry, }\n\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/homework/hw9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8670357615200475, "lm_q1q2_score": 0.7795703810090575}}
{"text": "open classical \n#check Prop\n\nvariables P Q R : Prop \n#check P \n\n-- Capítulo 3, Ejemplo 3.8.1, página 20\ntheorem T1 (h1 : P) (h2 : Q) : P ∧ Q :=\nbegin\n  exact and.intro h1 h2,\nend\n\n-- Capítulo 3, Ejemplo 3.8.2, página 20\ntheorem T2 (h1:P) (h2:P → Q) : Q  :=\nbegin\nexact h2 h1,\nend\n\n-- Capítulo 3, Ejemplo 3.8.3, página 21\ntheorem T3: ¬¬P ↔ P:=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1, \nby_contradiction h2,\nexact h1 h2,\n-- de derecha a izquierda\nassume h1, \nby_contradiction h2, \nexact h2 h1, \nend \n\n-- Capítulo 3, Lema 3.11.1 reflexividad, página 22\ntheorem T4: P ↔ P :=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1, \nexact h1, \n-- de derecha a izquierda\nassume h1, \nexact h1,\nend\n\n-- Capítulo 3, Lema 3.11.2 simetría, página 22\ntheorem T5 (h1: P ↔ Q) : Q ↔ P :=\nbegin\nsplit,\nexact iff.elim_right h1,\nexact iff.elim_left h1,\nend\n\n-- Capítulo 3, Lema 3.11.3 transitividad, página 22\ntheorem T6 (h1: P ↔ Q) (h2: Q ↔  R) : P ↔ R:=\nbegin\nsplit, \n-- de izquierda a derecha\nhave h3: P → Q, exact iff.elim_left h1,\nhave h4: Q → R, exact iff.elim_left h2,\nassume h5,\nhave h6: Q, exact h3 h5,\nexact h4 h6,\n-- de derecha a izquierda\nhave h3: Q → P, exact iff.elim_right h1,\nhave h4: R → Q, exact iff.elim_right h2,\nassume h5,\nhave h6: Q, exact h4 h5,\nexact h3 h6,\nend \n\n-- Capítulo 3, Lema 3.12.1\ntheorem T7 (h1: P → Q) : P ∧ Q ↔ P:=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h2,\nexact and.elim_left h2,\n-- de derecha a izquierda\nassume h2, \nhave h3: Q, exact h1 h2, \nexact and.intro h2 h3,\nend\n\n-- Capítulo 3, Lema 3.12.2\ntheorem T8 (h1: P → Q) : P ∨ Q ↔ Q:=\nbegin\nsplit,\n--de izquierda a derecha\nassume h2,\ncases h2 with hP hQ,\n--Caso hP\nhave h3: Q, exact h1 hP,\nexact h3,\n--Caso hQ\nexact hQ,\n-- de derecha a izquierda\nassume h2, \nexact or.inr h2,\nend\n\n-- Capítulo 3, Lema 3.12.3\ntheorem T9 (h1: P) : P ∧ Q ↔ Q:=\nbegin\nsplit, \n-- de izquierda a derecha \nassume h2, \nexact and.elim_right h2, \n-- de derecha a izquierda\nassume h2,\nexact and.intro h1 h2,\nend\n\n-- Capítulo 3, Lema 3.12.4\ntheorem T10 (h1: P) : ¬ P ∨ Q ↔ Q:=\nbegin\nsplit,\n--de izquierda a derecha\nassume h2,\ncases h2 with hNP hQ,\n--caso hNP\nhave h3: false, exact hNP h1,\nexact false.elim h3,\n--caso hQ\nexact hQ,\n-- de derecha a izquierda\nassume h2, \nexact or.inr h2,\nend\n\n-- Capítulo 5, Ejemplo 5.3, página 29\ntheorem T11: (P → Q) ↔ (¬P ∨ Q):= \nbegin\nsplit,\n--de izquierda a derecha\nassume h1,\nhave h2: P ∨ ¬ P , exact em P,\ncases h2 with hP hnP,\n-- caso 1\nhave h3: Q, exact h1 hP,\nexact or.inr h3,\n-- caso 2\nexact or.inl hnP,\n-- de derecha a izquierda\nassume h1,\ncases h1 with hnP hQ,\n--caso 1\nassume h2, \nhave h3: false, exact hnP h2,\nexact false.elim h3, \n--caso 2\nassume h2,\nexact hQ,\nend\n\n-- Capítulo 5 Teorema 5.5.1, página 30\ntheorem T12 : (P ↔ Q) ↔ ((P → Q) ∧ (Q → P)) :=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1,\nhave h2: P → Q, exact iff.elim_left h1,\nhave h3: Q → P, exact iff.elim_right h1,\nexact and.intro h2 h3,\n--de derecha a izquierda\nassume h1, \nhave h2: P → Q, exact and.elim_left h1,\nhave h3: Q → P, exact and.elim_right h1,\nsplit, \n-- de izquierda a derecha\nexact h2,\n-- de derecha a izquierda \nexact h3,\nend\n\n-- Capítulo 5 Teorema 5.5.2, página 31\ntheorem T13: (P → Q) ↔ (¬P ∨ Q):= \nbegin\nsplit,\n--de izquierda a derecha\nassume h1,\nhave h2: P ∨ ¬ P , exact em P,\ncases h2 with hP hnP,\n-- caso 1\nhave h3: Q, exact h1 hP,\nexact or.inr h3,\n-- caso 2\nexact or.inl hnP,\n-- de derecha a izquierda\nassume h1,\ncases h1 with hnP hQ,\n--caso 1\nassume h2, \nhave h3: false, exact hnP h2,\nexact false.elim h3, \n--caso 2\nassume h2,\nexact hQ,\nend\n\n-- Capítulo 5 Teorema 5.5.3, página 31\ntheorem T14: (P ∨ Q) ↔ (¬ P → Q) :=\nbegin\nsplit,\n--de izquierda a derecha \nassume h1,\ncases h1 with hP hQ,\n--caso hP\nhave h2: P ∨ ¬ P, exact em P,\nassume h3,\nhave h4: false, exact h3 hP,\nexact false.elim h4,\n--caso hQ\nassume h1,\nexact hQ,\n-- de derecha a izquierda\nassume h1,\nhave h2: P ∨ ¬ P, exact em P, \ncases h2 with hP hnP,\n--caso hP\nexact or.inl hP,\n--caso hnP\nhave h1: Q, exact h1 hnP,\nexact or.inr h1, \nend\n\n-- Capítulo 5 Teorema 5.5.4, página 31\ntheorem T15: (P ∨ Q) ↔ ¬ (¬ P ∧ ¬ Q) :=\nbegin\nsplit,\n-- de izquierda a derecha \nassume h1,\nby_contradiction h2, \nhave h3: ¬ P, exact and.elim_left h2,\nhave h4: ¬ Q, exact and.elim_right h2,\ncases h1 with hP hQ, \n-- caso 1\nexact h3 hP,\n--caso 2\nexact h4 hQ,\n-- de derecha a izquierda\nassume h1, \nhave h2: P ∨ ¬ P, exact em P,\ncases h2 with hP hnP,\nexact or.inl hP, \nhave h3: Q ∨ ¬ Q, exact em Q,\ncases h3 with hQ hnQ,\nexact or.inr hQ,\nhave h4: ¬ P ∧ ¬ Q , exact and.intro hnP hnQ,\nhave h5: false, exact h1 h4,\nexact false.elim h5,\nend\n\n-- Capítulo 5 Teorema 5.5.5, página 31\ntheorem T16: (P ∧ Q) ↔ ¬ (¬ Q ∨ ¬ P):=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1,\nby_contradiction h2,\ncases h2 with hnQ hnP,\nhave h3: Q, exact and.elim_right h1,\nexact hnQ h3,\nhave h4: P, exact and.elim_left h1,\nexact hnP h4,\n-- de derecha a izquierda\nassume h1,\nhave h2: P ∨ ¬ P, exact em P,\ncases h2 with hP hnP,\nhave h3: Q ∨ ¬ Q, exact em Q,\ncases h3 with hQ hnQ,\nexact and.intro hP hQ,\nhave h4: ¬ Q ∨ ¬ P, exact or.inl hnQ,\nhave h5: false, exact h1 h4,\nexact false.elim h5,\nhave h2: Q ∨ ¬ Q, exact em Q, \ncases h2 with hQ hnQ, \nhave h3: ¬ Q ∨ ¬ P , exact or.inr hnP,\nhave h5: false, exact h1 h3, \nexact false.elim h5, \nhave h2: ¬ Q ∨ ¬ P, exact or.inr hnP, \nhave h3: false, exact h1 h2, \nexact false.elim h3, \nend\n\n-- Capítulo 5 Teorema 5.5.6, página 31\ntheorem T17: (¬ P) ↔ P → false  :=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1,\nassume h2,\nexact h1 h2,\n-- de derecha a izquierda\nassume h1,\nexact h1,\nend\n\n-- Capítulo 5 Teorema 5.5.7, página 31\ntheorem T18: false ↔ (P ∧ ¬ P):=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1,\nexact false.elim h1, \n-- de derecha a izquierda\nassume h1,\ncases h1 with hP hnP,\nexact hnP hP, \nend\n\n-- Capítulo 6, Teorema 6.1, 1.1 Asociatividad de ∧ \ntheorem T19: ((P ∧ Q) ∧ R) ↔ (P ∧ (Q ∧ R)):=\nbegin\nsplit,\nassume h1,\nhave h2: R, exact and.elim_right h1, \nhave h3: P ∧ Q, exact and.elim_left h1,\nhave h4: P, exact and.elim_left h3,\nhave h5: Q, exact and.elim_right h3,\nhave h6: Q ∧ R, exact and.intro h5 h2,\nexact and.intro h4 h6,\nassume h1, \nhave h2: P, exact and.elim_left h1,\nhave h3: Q ∧ R, exact and.elim_right h1,\nhave h4: Q, exact and.elim_left h3,\nhave h5: R, exact and.elim_right h3,\nhave h6: P ∧ Q, exact and.intro h2 h4,\nexact and.intro h6 h5,\nend \n\n-- Capítulo 6, Teorema 6.1, 1.2 Asociatividad de ∨ \ntheorem T20: ((P ∨ Q) ∨ R) ↔ (P ∨ (Q ∨ R)):=\nbegin\nsplit,\nassume h1, \ncases h1 with hPQ hR,\ncases hPQ with hP hQ,\nexact or.inl hP, \nhave h1: Q ∨ R, exact or.inl hQ,\nexact or.inr h1,\nhave h1: Q ∨ R, exact or.inr hR,\nexact or.inr h1,\nassume h1, \ncases h1 with hP hQR,\nhave h1: P ∨ Q, exact or.inl  hP,\nexact or.inl h1,\ncases hQR with hQ hR,\nhave h1: P ∨ Q, exact or.inr hQ,\nexact or.inl h1,\nexact or.inr hR,\nend\n\n-- Capítulo 6, Teorema 6.1, 2.1 Neutro para ∧ \ntheorem T21: (P ∧ ¬ false) ↔ P:=\nbegin\nsplit,\nassume h1,\nexact and.elim_left h1,\nassume h1,\nhave h2: ¬ false, by_contradiction h3,\nexact h3,\nexact and.intro h1 h2,\nend\n\n-- Capítulo 6, Teorema 6.1, 2.2 Neutro para ∨ \ntheorem T22: (P ∨ false) ↔ P:=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1,\ncases h1 with hP hF,\n--caso 1\nexact hP,\n--caso 2\nexact false.elim hF,\n-- de derecha a izquierda\nassume h1,\nexact or.inl h1,\nend\n\n-- Capítulo 6, Teorema 6.1, 3.1 Commutatividad de ∧ \ntheorem T23: (P ∧ Q) ↔ (Q ∧ P):=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1,\nhave h2: P, exact and.elim_left h1, \nhave h3: Q, exact and.elim_right h1,\nexact and.intro h3 h2, \n-- de derecha a izquierda\nassume h1, \nhave h2: Q, exact and.elim_left h1,\nhave h3: P, exact and.elim_right h1,\nexact and.intro h3 h2, \nend\n\n-- Capítulo 6, Teorema 6.1, 3.2 Commutatividad de ∨\ntheorem T24: (P ∨ Q) ↔ (Q ∨ P):=\nbegin\nsplit, \n-- de izquierda a derecha\nassume h1, \ncases h1 with hP hQ,\n--caso 1\nexact or.inr hP,\n--caso 2\nexact or.inl hQ, \n-- de derecha a izquierda\nassume h1,\ncases h1 with hQ hP, \n--caso 1\nexact or.inr hQ,\n--caso 2\nexact or.inl hP, \nend\n\n-- Capítulo 6, Teorema 6.1, 4.1 Distributividad de ∧ \ntheorem T25: P ∨ (Q ∧ R) ↔ (P ∨ Q) ∧ (P ∨ R):=\nbegin\nsplit, \nassume h1, \ncases h1 with h1 h2,\nhave h2: P ∨ Q, exact or.inl h1,\nhave h3: P ∨ R, exact or.inl h1,\nexact and.intro h2 h3,\nhave h3: Q, exact and.elim_left h2,\nhave h4: R, exact and.elim_right h2,\nhave h5: P ∨ Q, exact or.inr h3,\nhave h6: P ∨ R, exact or.inr h4,\nexact and.intro h5 h6,\nassume h1,\nhave h2: P ∨ Q, exact and.elim_left h1,\nhave h3: P ∨ R, exact and.elim_right h1,\ncases h2 with hP hQ,\nexact or.inl hP,\ncases h3 with hP hR,\nexact or.inl hP,\nexact or.inr (and.intro hQ hR),\nend \n\n-- Capítulo 6, Teorema 6.1, 4.2 Distributividad de ∨ \ntheorem T26: P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R):=\nbegin\nsplit, \nassume h1, \nhave hP: P, exact and.elim_left h1,\nhave hQR: Q ∨ R, exact and.elim_right h1,\ncases hQR with hQ hR,\nexact or.inl (and.intro hP hQ),\nexact or.inr (and.intro hP hR),\nassume h1,\ncases h1 with hPQ hPR,\nhave hP: P, exact and.elim_left hPQ,\nhave hQ: Q, exact and.elim_right hPQ,\nhave hQR: Q ∨ R, exact or.inl hQ,\nexact and.intro hP hQR,\nhave hP: P, exact and.elim_left hPR,\nhave hR: R, exact and.elim_right hPR,\nhave hQR: Q ∨ R, exact or.inr hR,\nexact and.intro hP hQR,\nend\n\n-- Capítulo 6, Teorema 6.1, 5.1 Leyes de De Morgan\ntheorem T27: ¬ (P ∧ Q) ↔ (¬ P ∨ ¬ Q):=\nbegin\nsplit, \nassume h1,\nhave h2: P ∨ ¬ P, exact em P,\ncases h2 with h2,\nhave h3: Q ∨ ¬ Q, exact em Q,\ncases h3 with h3,\nhave h4: P ∧ Q, exact and.intro h2 h3,\nhave h5 : false, exact h1 h4,\nexact false.elim h5, \nexact or.inr h3,\nexact or.inl h2,\nassume h1,\nby_contradiction h2,\nhave h3: P, exact and.elim_left h2,\nhave h4: Q, exact and.elim_right h2,\ncases h1 with h1,\nexact h1 h3,\nexact h1 h4,\nend\n\n-- Capítulo 6, Teorema 6.1, 5.2 Leyes de De Morgan\ntheorem T28: ¬ (P ∨ Q) ↔ (¬ P ∧ ¬ Q):=\nbegin\nsplit, \nassume h1, \nhave hP: ¬ P, by_contradiction hP,\nhave hPQ: P ∨ Q, exact or.inl hP,\nexact h1 hPQ,\nhave hQ: ¬ Q, by_contradiction hQ,\nhave hPQ: P ∨ Q, exact or.inr hQ,\nexact h1 hPQ,\nexact and.intro hP hQ,\nassume h1,\nhave h2: ¬ P, exact and.elim_left h1,\nhave h3: ¬ Q, exact and.elim_right h1,\nby_contradiction h4,\ncases h4 with hP hQ,\nexact h2 hP,\nexact h3 hQ,\nend \n\n-- Capítulo 6, Teorema 6.1, 6.1 Idempotencia de ∧ \ntheorem T29: P ∧ P ↔ P:=\nbegin\nsplit, \n--de izquierda a derecha\nassume h1,\nexact and.elim_left h1, \n-- de derecha a izquierda\nassume h1, \nexact and.intro h1 h1,\nend \n\n-- Capítulo 6, Teorema 6.1, 6.2 Idempotencia de ∨\ntheorem T30: P ∨ P ↔ P:=\nbegin\nsplit, \n-- de izquierda a derecha \nassume h1, \ncases h1 with hP hiP,\nexact hP,\nexact hiP,\n-- de derecha a izquierda\nassume h1, \nexact or.inl h1, \nend\n\n-- Capítulo 6, Teorema 6.1, 7 Doble negación\ntheorem T31: ¬ ¬ P ↔ P:=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1, \nby_contradiction h2,\nexact h1 h2,\n-- de derecha a izquierda\nassume h1, \nby_contradiction h2, \nexact h2 h1, \nend \n\n-- Capítulo 6, Teorema 6.2, 1 Exportación e importación\ntheorem T32: P → (Q → R) ↔ P ∧ Q → R:=\nbegin\nsplit, \nassume h1, \nassume h2, \nhave h3: P, exact and.elim_left h2,\nhave h4: Q, exact and.elim_right h2, \nhave h5: Q→ R, exact h1 h3,\nexact h5 h4,\nassume h1, \nassume h2, \nassume h3, \nhave h4: P ∧ Q , exact and.intro h2 h3,\nexact h1 h4, \nend\n\n-- Capítulo 6, Teorema 6.2, 2 Contraposición\ntheorem T33: P → Q ↔ ¬ Q → ¬ P:=\nbegin\nsplit, \n-- de izquierda a derecha\nassume h1,\nassume h2,\nhave h3: ¬ P, by_contradiction hP, \nhave h4: Q, exact h1 hP,\nexact h2 h4, \nexact h3,  \n-- de derecha a izquierda\nassume h1,\nassume h2, \nhave h2: Q, by_contradiction hQ,\nhave h3: ¬P, exact h1 hQ,\nexact h3 h2,\nexact h2, \nend\n\n-- Capítulo 6, Teorema 6.2, 3 Implicación de una disjuntiva\ntheorem T34: ((P ∨ Q) → R) ↔ (P → R) ∧ (Q → R):=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1, \nhave h2: P → R,\nassume h3,\nhave h4: P ∨ Q, exact or.inl h3,\nexact h1 h4,\nhave h3: Q → R,\nassume h4,\nhave h5: P ∨ Q, exact or.inr h4,\nexact h1 h5,\nexact and.intro h2 h3,\n-- de derecha a izquierda\nassume h1,\nhave h2: P → R, exact and.elim_left h1,\nhave h3: Q → R, exact and.elim_right h1,\nassume h4,\ncases h4 with hP hQ,\n--caso hP\nexact h2 hP,\n--caso hQ\nexact h3 hQ,\nend\n\n-- Capítulo 6, Teorema 6.2, 4 Implicación a una disjuntiva\ntheorem T35: R → (P ∧ Q) ↔ (R → P) ∧ (R → Q):=\nbegin\nsplit,\n-- de izquierda a derecha\nassume h1, \nhave h2: R → P,\nassume h3,\nhave h4: P ∧ Q, exact h1 h3,\nexact and.elim_left h4,\nhave h7: R → Q,\nassume h3,\nhave h4: P ∧ Q, exact h1 h3,\nexact and.elim_right h4,\nexact and.intro h2 h7,\n-- de derecha a izquierda\nassume h1, \nassume h2,\nhave h3: R → P, exact and.elim_left h1,\nhave h4: R → Q, exact and.elim_right h1,\nhave h5: P, exact h3 h2, \nhave h6: Q, exact h4 h2, \nexact and.intro h5 h6, \nend\n", "meta": {"author": "blancagimeno", "repo": "TFG", "sha": "9e960214dbcbc9924bde50b80558ccc3d4033163", "save_path": "github-repos/lean/blancagimeno-TFG", "path": "github-repos/lean/blancagimeno-TFG/TFG-9e960214dbcbc9924bde50b80558ccc3d4033163/lean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115783, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.7795117355844836}}
{"text": "/-\nCopyright (c) 2022 Hans Parshall. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hans Parshall\n-/\nimport analysis.matrix\nimport analysis.normed_space.basic\nimport data.complex.is_R_or_C\nimport linear_algebra.unitary_group\n\n/-!\n# Unitary matrices\n\nThis file collects facts about the unitary matrices over `𝕜` (either `ℝ` or `ℂ`).\n-/\n\nopen_locale big_operators matrix\n\nvariables {𝕜 m n E : Type*}\n\nsection entrywise_sup_norm\nvariables [is_R_or_C 𝕜] [fintype n] [decidable_eq n]\n\nlemma entry_norm_bound_of_unitary {U : matrix n n 𝕜} (hU : U ∈ matrix.unitary_group n 𝕜) (i j : n):\n  ∥U i j∥ ≤ 1 :=\nbegin\n  -- The norm squared of an entry is at most the L2 norm of its row.\n  have norm_sum : ∥ U i j ∥^2 ≤ (∑ x, ∥ U i x ∥^2),\n  { apply multiset.single_le_sum,\n    { intros x h_x,\n      rw multiset.mem_map at h_x,\n      cases h_x with a h_a,\n      rw ← h_a.2,\n      apply sq_nonneg },\n    { rw multiset.mem_map,\n      use j,\n      simp only [eq_self_iff_true, finset.mem_univ_val, and_self, sq_eq_sq] } },\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ\n  have diag_eq_norm_sum : (U ⬝ Uᴴ) i i = ∑ (x : n), ∥ U i x ∥^2,\n  { simp only [matrix.mul_apply, matrix.conj_transpose_apply, ←star_ring_end_apply,\n               is_R_or_C.mul_conj, is_R_or_C.norm_sq_eq_def', is_R_or_C.of_real_pow] },\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ, real part\n  have re_diag_eq_norm_sum : is_R_or_C.re ((U ⬝ Uᴴ) i i) = ∑ (x : n), ∥ U i x ∥^2,\n  { rw is_R_or_C.ext_iff at diag_eq_norm_sum,\n    rw diag_eq_norm_sum.1,\n    norm_cast },\n  -- Since U is unitary, the diagonal entries of U ⬝ Uᴴ are all 1\n  have mul_eq_one : (U ⬝ Uᴴ) = 1, from unitary.mul_star_self_of_mem hU,\n  have diag_eq_one : is_R_or_C.re ((U ⬝ Uᴴ) i i) = 1,\n  { simp only [mul_eq_one, eq_self_iff_true, matrix.one_apply_eq, is_R_or_C.one_re] },\n  -- Putting it all together\n  rw [← sq_le_one_iff (norm_nonneg (U i j)), ← diag_eq_one, re_diag_eq_norm_sum],\n  exact norm_sum,\nend\n\nlocal attribute [instance] matrix.normed_group\n\n/-- The entrywise sup norm of a unitary matrix is at most 1. -/\nlemma entrywise_sup_norm_bound_of_unitary {U : matrix n n 𝕜} (hU : U ∈ matrix.unitary_group n 𝕜) :\n  ∥ U ∥ ≤ 1 :=\nbegin\n  simp_rw pi_norm_le_iff zero_le_one,\n  intros i j,\n  exact entry_norm_bound_of_unitary hU _ _\nend\n\nend entrywise_sup_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/normed_space/star/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.7795117301872665}}
{"text": "import tactic --hide\n\n-- Level name : Boss level\n\n/- Hint : Hint 1\n Notice we have three implications, so we need to introduce all of them using `intros`.\n\n-/\n\n/-Hint : Hint 2\nWhen using `apply` we need to make sure that we use an assumption that contains our goal.\n\n-/\n\n/-Hint : Hint 3\nIf we have more than one goal to prove, then we need to do them in order. By default the lean \napplies the tactics to the first goal until complete and then moves on to the next.  \n\n-/\n\n\n/-Lemma \nIf $P,Q,R$ are logical statements and\n $(P \\implies Q \\implies R)$  then $((P \\implies Q) \\implies (P \\implies R)$.\n-/\nlemma lemma_5 (P Q R : Prop) : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  intros hPQR hPQ hP,\n  apply hPQR,\n  { exact hP },\n  { apply hPQ,\n    exact hP }\n\n\n\nend\n\n/- Hint : Tip\nTo skip proving a goal you can  write `sorry,`. But don't forget to go back and prove it to solve the\nlevel.  \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/logic7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505204, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7794472519899963}}
{"text": "/-\nThe plan for this week is to tackle the typeclass system in Lean, which is the last \n\nWe will do this by working through a few extended examples of some \"real mathematics\". In \nparticular, we'll be talking about _monoids_ and _groups_. \n-/\nimport tactic\n\n/-\nIf you asked a mathematican what a monoid is they'd say something like \"It's a set, together with\na binary map which is associative and has two-sided identities.\" Before we try to implement this\ndefinition we'll begin by making 1 modification:\n\nLean can talk about sets, but it is a lot more natural to define monoid structures on types instead.\nNot much is lost in making this modification, and in fact there is a lot to be gained (if we go the\nfurther step in making our types universe polymorphic)\n\nWithout further ado, we then would arrive at the following definition:\n-/\n\n#check mul_assoc\n\nuniverse u\n\n#check mul_assoc\n\nstructure mymonoid := \n(carrier : Type u)\n(id' : carrier)\n(mul' : carrier → carrier → carrier)\n(mul_assoc' : ∀(a b c : carrier), mul' (mul' a b) c = mul' a (mul' b c))\n(id_mul' : ∀a, mul' id' a = a)\n(mul_id' : ∀a, mul' a id' = a)\n\n\nnamespace mymonoid\n\n/- \nWriting `mul` all over the place is annoying, so we can do this. Note we're secretly doing some\ntypeclass stuff here\n-/\ninstance (M : mymonoid) : has_mul M.carrier := { mul := M.mul' }\ninstance (M : mymonoid) : has_one M.carrier := { one := M.id' }\n\n\n\n@[simp] lemma mul_assoc {M : mymonoid} : ∀(a b c : M.carrier), a * b * c = a * (b * c) := sorry\n\n@[simp] lemma id_mul {M : mymonoid} : ∀(a : M.carrier), 1 * a = a := sorry\n\n@[simp] lemma mul_id {M : mymonoid} : ∀(a : M.carrier), a * 1 = a := sorry\n\ntheorem unique_id {M : mymonoid} {e : M.carrier} (hid : ∀a, e * a = a) : e = 1 :=\nbegin\n  specialize hid 1,\n  simp at hid,\n  exact hid,\nend\n\nend mymonoid\n\n/-\nThe way we construct some new examples of these objects is by defining things of the appropriate\ntypes. For example\n-/\n\ndef mynat : mymonoid :=\n{ carrier := ℕ,\n  id' := 0,\n  mul' := (+),\n  mul_assoc' := add_assoc,\n  id_mul' := zero_add,\n  mul_id' := add_zero }\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/-\nAs you can see from dealing with mymonoid, we're running into some annoying issues. The first of \nwhich is that we have to constantly talk about the underlying type of a `M : mymonoid` by calling it\nwith `M.carrier`, when in principle it doesn't have any more information than a type `M` anyway.\n\nThe solution to this is to **un-bundle** the type from the structure. In some sense, we're taking\nour algebraic objects and turning them into function types...\n-/\n\nstructure mymonoid' (M : Type u) := \n(id' : M)\n(mul' : M → M → M)\n(mul_assoc' : ∀(a b c : M), mul' (mul' a b) c = mul' a (mul' b c))\n(id_mul' : ∀a, mul' id' a = a)\n(mul_id' : ∀a, mul' a id' = a)\n\n/-\nOf course these two constructures are equivalent to each other. \n-/\n\nexample (M : Type u) : mymonoid' M → mymonoid := λh, { carrier := M,\n  id' := h.id',\n  mul' := h.mul',\n  mul_assoc' := h.mul_assoc',\n  id_mul' := h.id_mul',\n  mul_id' := h.mul_id' }\n\nexample : Π(M : mymonoid), mymonoid' M.carrier := λM, { id' := M.id', -- note the dependent type!\n  mul' := M.mul',\n  mul_assoc' := M.mul_assoc',\n  id_mul' := M.id_mul',\n  mul_id' := M.mul_id' }\n\n/-\nYou may have noticed a little bit of an annoying feature in the above arguments: Because everything\nwas named exactly the same between the two different \n\nWe can actually simplify the above kinds of arguments into really simple 1 or 2 line arguments:\n-/\n\nexample (M : Type u) : mymonoid' M → mymonoid := λh, { carrier := M,\n ..h }\n\nexample : Π(M : mymonoid), mymonoid' M.carrier := λM, { ..M }\n\n/-\nThe `..h` and `..M` say \"Look at all the records defining this structure, and unfold them all and\nprovide.\" It's important that the names actually matched between the two structures, as otherwise \nthis wouldn't work.\n\nThere is still something annoying about this construction, and it will become most obvious if we\nwant to define an extension of our object:\n-/\n\nstructure mygroup' (G : Type u) extends mymonoid' G :=\n(inv': G → G)\n(mul_inv' : ∀g, mul' g (inv' g) = id')\n\ndef int_group' : mygroup' ℤ := { id' := 0,\n  mul' := (+),\n  mul_assoc' :=add_assoc,\n  id_mul' := zero_add,\n  mul_id' := add_zero,\n  inv' := λz, -z,\n  mul_inv' :=  add_neg_self }\n\n/-\nGreat! We've got a `mygroup'`. But a `mygroup'` extends a `mymonoid'`... But we have no way to\naccess all the results we may have proven about `mymonoid'` to `int_group'`! \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/-\nThis problem, and many others are solved entirely by the **type class** system in Lean... You may\nhave seen the `[   ]` variable declarations, and these are exactly type classes! Lets see how \ngroups in Lean are actually implemented:\n-/\n\n#check group\n\n\n\n\n\n\n/-\nThat was a trip! But it was classes all the way down! has_mul, semigroup, monoid, and finally group. \nThe great thing is that if we prove something about monoids, then we get the results for free for\nany group because of the typeclass inheritance. \n\nIt also solves the issue of having all those annoying structure declarations having to be explicit,\nLean has a **type class inference** system which can deduce instances of a typeclass based off \nrules available to it. Lets do some examples:\n-/\n\nclass mymonoid'' (M : Type u) extends has_mul M, has_one M:= -- `extends` is not unique to classes\n(mul_assoc : ∀(a b c : M), a * b * c = a * (b * c))\n(id_mul : ∀a, 1 * a = a)\n(mul_id : ∀a, a * 1 = a)\n\nnamespace mymonoid''\n\nuniverse v\n\nvariables {M : Type u} {N : Type v} [mymonoid'' M] [mymonoid'' N]\n\n/-\nWe can now provide _instances_ for the typeclass system to start inhabiting. These can be as simple\nas showing previously defined structures are monoids:\n-/\n\ninstance nat_is_monoid: mymonoid'' ℕ := { mul := (+),\n  one := 0,\n  mul_assoc := add_assoc,\n  id_mul := sorry, \n  mul_id := sorry }\n\n/-\nWe can even define instances in terms of other instances\n-/\n\ninstance monoid_prod : mymonoid'' (M × N) := { mul := λp q, ⟨p.1 * q.1, p.2 * q.2⟩,\n  one := ⟨1, 1⟩,\n  mul_assoc := \n  begin\n    intros a b c,\n    ext,\n    exact mul_assoc a.1 b.1 c.1,\n    exact mul_assoc a.2 b.2 c.2,\n  end,\n  id_mul := sorry,\n  mul_id := sorry }\n\nvariables (g h : M × N)\n\n#check g * h\n\nend mymonoid''\n\n/-\nThis is a synonym for `class`!\n-/\n@[class] structure mygroup'' (G : Type u) extends mymonoid'' G, has_inv G:=\n(mul_inv : ∀(g : G), g * g⁻¹ = 1)\n\ninstance int_mygroup : mygroup'' ℤ :=\n{ mul := (+),\n  one := 0,\n  mul_assoc := add_assoc,\n  id_mul := sorry,\n  mul_id := sorry,\n  inv := has_neg.neg,\n  mul_inv := add_neg_self}\n\nvariables (G H : Type) [mygroup'' G] [mygroup'' H]\nvariables (g h : G × H)\n\n#check g * h\n\n#print instances mygroup''\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/-\nFinally, let me just say a few words about where type classes are helpful in your day to day life as\na programmer. \n\nTypeclasses give you a way of defining polymorphic functions! \n-/\n\nclass printable (T : Type) :=\n(print: T → string)\n\nclass foldable (T : Type → Type) :=\n(fold (α β : Type) : (α → β → β) → β → T α → β)\n\n#check list\n\ninstance : foldable list :=\n{ fold := λα β m b L, begin\n  cases L,\n  exact b,\n  exact m L_hd b,\nend }", "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/week7/demo7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7793910072078127}}
{"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-/\nimport analysis.normed_space.conformal_linear_map\nimport analysis.inner_product_space.basic\n\n/-!\n# Conformal maps between inner product spaces\n\nIn an inner product space, a map is conformal iff it preserves inner products up to a scalar factor.\n-/\n\nvariables {E F : Type*} [inner_product_space ℝ E] [inner_product_space ℝ F]\n\nopen linear_isometry continuous_linear_map\nopen_locale real_inner_product_space\n\nlemma is_conformal_map_iff (f' : E →L[ℝ] F) :\n  is_conformal_map f' ↔ ∃ (c : ℝ), 0 < c ∧\n  ∀ (u v : E), ⟪f' u, f' v⟫ = (c : ℝ) * ⟪u, v⟫ :=\nbegin\n  split,\n  { rintros ⟨c₁, hc₁, li, h⟩,\n    refine ⟨c₁ * c₁, mul_self_pos.2 hc₁, λ u v, _⟩,\n    simp only [h, pi.smul_apply, inner_map_map,\n               real_inner_smul_left, real_inner_smul_right, mul_assoc], },\n  { rintros ⟨c₁, hc₁, huv⟩,\n    let c := real.sqrt c₁⁻¹,\n    have hc : c ≠ 0 := λ w, by {simp only [c] at w;\n      exact (real.sqrt_ne_zero'.mpr $ inv_pos.mpr hc₁) w},\n    let f₁ := c • f',\n    have minor : (f₁ : E → F) = c • f' := rfl,\n    have minor' : (f' : E → F) = c⁻¹ • f₁ := by ext;\n      simp_rw [minor, pi.smul_apply]; rw [smul_smul, inv_mul_cancel hc, one_smul],\n    refine ⟨c⁻¹, inv_ne_zero hc, f₁.to_linear_map.isometry_of_inner (λ u v, _), minor'⟩,\n    simp_rw [to_linear_map_eq_coe, continuous_linear_map.coe_coe, minor, pi.smul_apply],\n    rw [real_inner_smul_left, real_inner_smul_right,\n        huv u v, ← mul_assoc, ← mul_assoc,\n        real.mul_self_sqrt $ le_of_lt $ inv_pos.mpr hc₁,\n        inv_mul_cancel $ ne_of_gt hc₁, one_mul], },\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/conformal_linear_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7793910059944664}}
{"text": "import algebra.group_power\n/-\nM1F 2017-18 Sheet 1 Question 1\nAuthor : Kevin Buzzard\n\nThis file should work with any version of lean -- whether you installed it yourself\nor are running the version on https://leanprover.github.io/live/latest/\n\n-/\n\n-- Ignore the next 4 lines -- they are just defining the power notation :-)\n--@[reducible] definition pow : int -> nat -> int\n--| _ 0 := (1:int)\n--| x (nat.succ n) := x * (pow x n)\n--notation x `^` n := pow x n\n-- Power notation is in the maths library but then you have to figure out\n-- how to import the maths library. Now we have this definition, this\n-- file *just works*, with any recent version of lean.\n\n-- The rest of this file is the six parts of M1F Sheet 1 Q1.\n\n-- part (a): which one of these is provable? Prove one, delete\n-- the other.\n\ntheorem m1f_sheet01_q01a_is_T : ∀ x : ℤ, x^2 - 3*x + 2 = 0 → x=1 := sorry\ntheorem m1f_sheet01_q01a_is_F : ¬ (∀ x : ℤ, x^2 - 3*x + 2 = 0 → x=1) := sorry\n\n-- part (b) etc etc.\n\ntheorem m1f_sheet01_q01b_is_T : ∀ x : ℤ, x=1 → x^2-3*x+2=0 := sorry\ntheorem m1f_sheet01_q01b_is_F : ¬ (∀ x : ℤ, x=1 → x^2-3*x+2=0) := sorry\n\n-- part (c)\n\ntheorem m1f_sheet01_q01c_is_T : ∀ x : ℤ, x^2 - 3*x + 2 = 0 ↔ x=1 := sorry\ntheorem m1f_sheet01_q01c_is_F : ¬ (∀ x : ℤ, x^2 - 3*x + 2 = 0 ↔ x=1) := sorry\n\n-- part (d)\n\ntheorem m1f_sheet01_q01d_is_T : ∀ x : ℤ, x^2 - 3*x + 2 = 0 ↔ (x=1 ∨ x=2) := sorry\ntheorem m1f_sheet01_q01d_is_F : ¬ (∀ x : ℤ, x^2 - 3*x + 2 = 0 ↔ (x=1 ∨ x=2)) := sorry\n\n-- part (e)\n\ntheorem m1f_sheet01_q01e_is_T : ∀ x : ℤ, x^2 - 3*x + 2 = 0 → (x=1 ∨ x=2 ∨ x=3) := sorry\ntheorem m1f_sheet01_q01e_is_F : ¬ (∀ x : ℤ, x^2 - 3*x + 2 = 0 → (x=1 ∨ x=2 ∨ x=3)) := sorry\n\n-- part (f)\n\ntheorem m1f_sheet01_q01f_is_T : ∀ x : ℤ, (x=1 ∨ x=2 ∨ x=3) → x^2 - 3*x + 2 = 0  := sorry\ntheorem m1f_sheet01_q01f_is_F : ¬ (∀ x : ℤ, (x=1 ∨ x=2 ∨ x=3) → x^2 - 3*x + 2 = 0)  := 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/0101/Q0101.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.7793910043863945}}
{"text": "import tactic.ring\nimport tactic.linarith\n\n-- Testing ground for theorems\n\ntheorem contrapositive\n  (P Q : Prop) (HPQ : P → Q) : ¬ Q → ¬ P :=\nby {intros hnq hp, from hnq (HPQ hp)}\n\ntheorem and_transitive (P Q R : Prop) :\n  (P ∧ Q) ∧ (Q ∧ R) → (P ∧ R) :=\nby {intro h, from ⟨h.left.left, h.right.right⟩}\n\ntheorem iff_symmetric\n    (P Q : Prop) : (P ↔ Q) ↔ (Q ↔ P) :=\nby {split,\n  {intro h, rw h},\n  {intro h, rw h}\n}\n\nexample\n  (P Q R : Prop) : (P ↔ Q) ∧ (Q ↔ R) → (P ↔ R) :=\nby {\n  intro h, split,\n  {intro hp, rwa [←h.right, ←h.left]},\n  {intro hr, rwa [h.left, h.right]}\n}\n\nexample\n  (P : Prop) : ¬ (¬ P) ↔ P :=\nby {\n  split,\n  {intro h, \n  cases classical.em P,\n    {assumption},\n    {contradiction} },\n  {intros hp hnp, contradiction}\n}\n\nexample\n  (P Q : Prop) : (¬ Q → ¬ P) → (P → Q) :=\nby {\n  intros h hp,\n  apply classical.by_contradiction,\n  intro hnq,\n  from (h hnq) hp\n}\n\n\nexample (P Q R : Prop) : (P → Q) ∧ (Q → R) → (P → R) := \nby {intros h hp, from h.right (h.left hp)}\n\nexample \n  (X : Type) (P Q : X → Prop) (a : X) (HP : ∀ x : X, P x) (HQ : ∀ x : X, Q x): P a ∧ Q a :=\nby {from ⟨HP a, HQ a⟩}\n\nexample (P Q : Prop) : ¬ P → ¬ (P ∧ Q) :=\nby {intro h, push_neg, left, assumption}\n\nexample\n  (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) :=\nby {\n  split,\n  {intro h, cases h.right with Q R,\n  all_goals { {left, from ⟨h.left, Q⟩}  <|> {right, from ⟨h.left, R⟩} } },\n  {intro h, cases h,\n  all_goals {split, from h.left},\n  {left, from h.right},\n  {right, from h.right}  }\n}\n\nexample\n    (P Q : Prop) : ¬ (P ∧ Q) → ¬ P ∨ ¬ Q :=\nby {push_neg, intro, assumption}\n\nexample\n  (P Q : Prop) : ¬ (P ∧ ¬ Q) → (P → Q) :=\nby {\n  push_neg, intros h hp, cases h, \n  {contradiction}, \n  {assumption}\n}\n\nexample\n  (P Q : Prop) : ¬ (P → Q) → (P ∧ ¬ Q) :=\nby {push_neg, intro, assumption}\n\nexample\n  (P Q : Prop) : (P ∧ ¬ Q) → ¬ (P → Q) :=\nby {push_neg, intro, assumption}\n\nvariables p q r : Prop\n\nexample : p ∨ q → q ∨ p :=\nby {intro h, cases h, all_goals{{left, assumption} <|> {right, assumption}}}\n\nexample : ¬ (p ↔ ¬ p) :=\nby {\n  intro h,\n  cases classical.em p with hp hnp,\n  {from (h.mp hp) hp},\n  {from hnp (h.mpr hnp)}\n}\n\nexample : p ∨ ¬ p :=\nby {\n  cases classical.em p,\n  all_goals { {left, assumption} <|> {right, assumption} }\n}\n\nexample : (p → q) ↔ (¬ q → ¬ p) :=\nby {\n  split,\n  all_goals {intros a b},\n  {intro h, from b (a h)},\n  {apply classical.by_contradiction, intro h, from (a h) b}\n}\n\nvariables (X : Type) (P Q : X → Prop)\n\nexample : (∀ x, P x ∧ Q x) → (∀ x, Q x ∧ P x) :=\nby {\n  intros h x,\n  split, all_goals {  {from (h x).right} <|>  {from (h x).left} }\n}\n\nexample : (∃ x, P x ∨ Q x) → (∃ x, Q x ∨ P x) :=\nby {\n  rintro ⟨x, hx⟩, existsi x,\n  cases hx,\n  all_goals { {left, assumption} <|> {right, assumption}}\n}\n\nexample : (∀ x, P x) ∧ (∀ x, Q x) ↔ (∀ x, P x ∧ Q x) :=\nby {\n  split,\n  {rintros ⟨hp, hq⟩ x, from ⟨hp x, hq x⟩},\n  {intro h, split,\n  all_goals {intro x, from (h x).left <|> from (h x).right} }\n}\n\nexample : (∃ x, P x) ∨ (∃ x, Q x) ↔ (∃ x, P x ∨ Q x) :=\nby {\n  split,\n  {intro h, repeat {rcases h with ⟨x, hx⟩},\n  all_goals {existsi x, {left, assumption} <|> {right, assumption}  }\n  },\n  {rintro ⟨x, hx⟩, cases hx, \n  {left, existsi x, assumption},\n  {right, existsi x, assumption} }\n}\n\nexample (α : Type) (p q : α → Prop) : (∀ x : α, p x ∧ q x) → ∀ x : α, p x  :=\nby {intros h x, from (h x).left}\n\nexample : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x :=\nby {push_neg, refl}\n\ndef even (a : ℤ) := ∃ b : ℤ, a = 2 * b\ndef odd (a : ℤ) := ∃ b : ℤ, a = 2 * b + 1\n\ntheorem timeseven\n  (a : ℤ) : even a → even (a * a) :=\nbegin\n  intro h,\n  have h1 : ∃ b : ℤ, a = 2 * b, exact h,\n  have h2 : ∃ b : ℤ, a * a = 2 * b,\n  cases h1 with hz ha,\n  existsi 2 * hz * hz,\n  rw ha,\n  have hc : 2 * hz = hz * 2, \n    rw mul_comm,\n  rw [hc, mul_assoc, mul_assoc, hc, mul_left_comm],\n  exact h2,\nend\n\ntheorem timesodd\n  (a : ℤ) : odd a → odd (a * a) :=\nbegin\n  intro h,\n  have h1 : ∃ b : ℤ, a = 2 * b + 1, exact h,\n  have h2 : ∃ b : ℤ, a * a = 2 * b + 1,\n  cases h1 with x ha,\n  existsi 2 * x * x + 2 * x,\n  rw ha,\n  ring,\n  exact h2,\nend \n\ntheorem eventimesodd\n  (a b : ℤ) : odd a ∧ even b → even (a * b) :=\nbegin\n  intro h,\n  cases h with ha hb,\n  have h1 : ∃ c : ℤ, a = 2 * c + 1, exact ha,\n  have h2 : ∃ c : ℤ, b = 2 * c, exact hb,\n  have h3 : ∃ c : ℤ, a * b = 2 * c,\n  cases h1 with x0 hk,\n  cases h2 with x1 hm,\n  existsi x1 * (2 * x0 + 1),\n  rw hk, rw hm,\n  ring,\n  exact h3,\nend\n\ntheorem orderx (x y z : ℕ) (h : z > 0) : x > y → x * z > y * z :=\nby {from (mul_lt_mul_right h).mpr}\n\ntheorem orderone (a b : ℕ) (ha : a > 1) : b > 1 → a * b > a :=\nbegin\n  intro h,\n  have hb : b > 0,\n    have h0 : 1 > 0,\n      simp,\n    exact trans h h0,\n  have hc : a = a * 1, simp,\n  rw hc,\n  have hd : 1 * b = b, simp,\n  rw mul_assoc,\n  rw hd,\n  rw mul_comm,\n  have he : a * 1 = 1 * a, simp,\n  rw he,\n  apply orderx,\n  have hf : 1 > 0, simp,\n  exact trans ha hf,\n  exact h,\nend\n\ntheorem ordermul\n  (a b n : ℕ) (h1 : a > 1) (h2 : b > 1): n > a * b → n > a ∧ n > b :=\nbegin\n  intro h,\n  split, \n  have hab : a * b > a,\n    apply orderone, exact h1, exact h2,\n  exact trans h hab,\n  have hba : a * b > b,\n    rw mul_comm, apply orderone, exact h2, exact h1,\n  exact trans h hba,\nend\n\nexample (P Q : Prop) : ((P → Q) → P) → P :=\nbegin\n  intro h,\n  cases classical.em P with hp hnp,\n  assumption,\n\n  have ha : ¬ P → ¬ (P → Q),\n    apply contrapositive,\n    assumption,\n  have hb : ¬ (P → Q) := ha hnp,\n  revert hb,\n  push_neg,\n  intro hc,\n  exact hc.left,\nend\n\nexample (a b : ℕ) : a + a = b + b → a = b :=\nby{ring, rw nat.mul_left_inj, intro; assumption, simp}", "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/Stuff_for_reference/prop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7793910025663745}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, 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 `∪`, `∩`, `insert`, and provide\nformulas for `∅`, `univ`, and intervals.\n-/\nopen set order_dual (to_dual of_dual)\n\nuniverses u v w x\nvariables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}\n\nsection\nvariables [preorder α] [preorder β] {s t : set α} {a b : α}\n\n/-!\n### Definitions\n-/\n\n/-- The set of upper bounds of a set. -/\ndef upper_bounds (s : set α) : set α := { x | ∀ ⦃a⦄, a ∈ s → a ≤ x }\n/-- The set of lower bounds of a set. -/\ndef lower_bounds (s : set α) : set α := { x | ∀ ⦃a⦄, a ∈ s → x ≤ a }\n\n/-- A set is bounded above if there exists an upper bound. -/\ndef bdd_above (s : set α) := (upper_bounds s).nonempty\n/-- A set is bounded below if there exists a lower bound. -/\ndef bdd_below (s : set α) := (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 α) (a : α) : Prop := a ∈ s ∧ a ∈ 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 α) (a : α) : Prop := a ∈ s ∧ a ∈ 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 α) : α → 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 α) : α → Prop := is_greatest (lower_bounds s)\n\nlemma mem_upper_bounds : a ∈ upper_bounds s ↔ ∀ x ∈ s, x ≤ a := iff.rfl\n\nlemma mem_lower_bounds : a ∈ lower_bounds s ↔ ∀ x ∈ s, a ≤ x := iff.rfl\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`¬(y ≤ x)`. A version for linear orders is called `not_bdd_above_iff`. -/\nlemma not_bdd_above_iff' : ¬bdd_above s ↔ ∀ x, ∃ y ∈ s, ¬(y ≤ 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 ∈ s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`¬(x ≤ y)`. A version for linear orders is called `not_bdd_below_iff`. -/\nlemma not_bdd_below_iff' : ¬bdd_below s ↔ ∀ x, ∃ y ∈ s, ¬(x ≤ y) :=\n@not_bdd_above_iff' (order_dual α) _ _\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\nlemma not_bdd_above_iff {α : Type*} [linear_order α] {s : set α} :\n  ¬bdd_above s ↔ ∀ x, ∃ y ∈ 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 ∈ s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\nlemma not_bdd_below_iff {α : Type*} [linear_order α] {s : set α} :\n  ¬bdd_below s ↔ ∀ x, ∃ y ∈ s, y < x :=\n@not_bdd_above_iff (order_dual α) _ _\n\nlemma bdd_above.dual (h : bdd_above s) : bdd_below (of_dual ⁻¹' s) := h\n\nlemma bdd_below.dual (h : bdd_below s) : bdd_above (of_dual ⁻¹' s) := h\n\nlemma is_least.dual (h : is_least s a) : is_greatest (of_dual ⁻¹' s) (to_dual a) := h\n\nlemma is_greatest.dual (h : is_greatest s a) : is_least (of_dual ⁻¹' s) (to_dual a) := h\n\nlemma is_lub.dual (h : is_lub s a) : is_glb (of_dual ⁻¹' s) (to_dual a) := h\n\nlemma is_glb.dual (h : is_glb s a) : is_lub (of_dual ⁻¹' s) (to_dual a) := h\n\n/-!\n### Monotonicity\n-/\n\nlemma upper_bounds_mono_set ⦃s t : set α⦄ (hst : s ⊆ t) :\n  upper_bounds t ⊆ upper_bounds s :=\nλ b hb x h, hb $ hst h\n\nlemma lower_bounds_mono_set ⦃s t : set α⦄ (hst : s ⊆ t) :\n  lower_bounds t ⊆ lower_bounds s :=\nλ b hb x h, hb $ hst h\n\nlemma upper_bounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upper_bounds s → b ∈ upper_bounds s :=\nλ ha x h, le_trans (ha h) hab\n\nlemma lower_bounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lower_bounds s → a ∈ lower_bounds s :=\nλ hb x h, le_trans hab (hb h)\n\nlemma upper_bounds_mono ⦃s t : set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :\n  a ∈ upper_bounds t → b ∈ upper_bounds s :=\nλ ha, upper_bounds_mono_set hst $ upper_bounds_mono_mem hab ha\n\nlemma lower_bounds_mono ⦃s t : set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :\n  b ∈ lower_bounds t → a ∈ lower_bounds s :=\nλ hb, lower_bounds_mono_set hst $ lower_bounds_mono_mem hab hb\n\n/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/\nlemma bdd_above.mono ⦃s t : set α⦄ (h : s ⊆ t) : bdd_above t → bdd_above s :=\nnonempty.mono $ upper_bounds_mono_set h\n\n/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/\nlemma bdd_below.mono ⦃s t : set α⦄ (h : s ⊆ t) : bdd_below t → 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 ⊆ t ⊆ p`. -/\nlemma is_lub.of_subset_of_superset {s t p : set α} (hs : is_lub s a) (hp : is_lub p a)\n  (hst : s ⊆ t) (htp : t ⊆ p) : is_lub t a :=\n⟨upper_bounds_mono_set htp hp.1, lower_bounds_mono_set (upper_bounds_mono_set hst) hs.2⟩\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 ⊆ t ⊆ p`. -/\nlemma is_glb.of_subset_of_superset {s t p : set α} (hs : is_glb s a) (hp : is_glb p a)\n  (hst : s ⊆ t) (htp : t ⊆ 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 ⊆ t) : b ≤ a :=\nhb.2 (hst ha.1)\n\nlemma is_greatest.mono (ha : is_greatest s a) (hb : is_greatest t b) (hst : s ⊆ t) : a ≤ b :=\nhb.2 (hst ha.1)\n\nlemma is_lub.mono (ha : is_lub s a) (hb : is_lub t b) (hst : s ⊆ t) : a ≤ 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 ⊆ t) : b ≤ a :=\nhb.mono ha $ lower_bounds_mono_set hst\n\nlemma subset_lower_bounds_upper_bounds (s : set α) : s ⊆ lower_bounds (upper_bounds s) :=\nλ x hx y hy, hy hx\n\nlemma subset_upper_bounds_lower_bounds (s : set α) : s ⊆ upper_bounds (lower_bounds s) :=\nλ 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 := ⟨h.2, λ b hb, hb h.1⟩\n\nlemma is_greatest.is_lub (h : is_greatest s a) : is_lub s a := ⟨h.2, λ b hb, hb h.1⟩\n\nlemma is_lub.upper_bounds_eq (h : is_lub s a) : upper_bounds s = Ici a :=\nset.ext $ λ b, ⟨λ hb, h.2 hb, λ hb, upper_bounds_mono_mem hb h.1⟩\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 ≤ b ↔ b ∈ upper_bounds s :=\nby { rw h.upper_bounds_eq, refl }\n\nlemma le_is_glb_iff (h : is_glb s a) : b ≤ a ↔ b ∈ lower_bounds s :=\nby { rw h.lower_bounds_eq, refl }\n\nlemma is_lub_iff_le_iff : is_lub s a ↔ ∀ b, a ≤ b ↔ b ∈ upper_bounds s :=\n⟨λ h b, is_lub_le_iff h, λ H, ⟨(H _).1 le_rfl, λ b hb, (H b).2 hb⟩⟩\n\nlemma is_glb_iff_le_iff : is_glb s a ↔ ∀ b, b ≤ a ↔ b ∈ lower_bounds s :=\n@is_lub_iff_le_iff (order_dual α) _ _ _\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 := ⟨a, h.1⟩\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 := ⟨a, h.1⟩\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 := ⟨a, h.2⟩\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 := ⟨a, h.2⟩\n\nlemma is_least.nonempty (h : is_least s a) : s.nonempty := ⟨a, h.1⟩\n\nlemma is_greatest.nonempty (h : is_greatest s a) : s.nonempty := ⟨a, h.1⟩\n\n/-!\n### Union and intersection\n-/\n\n@[simp] lemma upper_bounds_union : upper_bounds (s ∪ t) = upper_bounds s ∩ upper_bounds t :=\nsubset.antisymm\n  (λ b hb, ⟨λ x hx, hb (or.inl hx), λ x hx, hb (or.inr hx)⟩)\n  (λ b hb x hx, hx.elim (λ hs, hb.1 hs) (λ ht, hb.2 ht))\n\n@[simp] lemma lower_bounds_union : lower_bounds (s ∪ t) = lower_bounds s ∩ lower_bounds t :=\n@upper_bounds_union (order_dual α) _ s t\n\nlemma union_upper_bounds_subset_upper_bounds_inter :\n  upper_bounds s ∪ upper_bounds t ⊆ upper_bounds (s ∩ 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 ∪ lower_bounds t ⊆ lower_bounds (s ∩ t) :=\n@union_upper_bounds_subset_upper_bounds_inter (order_dual α) _ s t\n\nlemma is_least_union_iff {a : α} {s t : set α} :\n  is_least (s ∪ t) a ↔ (is_least s a ∧ a ∈ lower_bounds t ∨ a ∈ lower_bounds s ∧ is_least t a) :=\nby simp [is_least, lower_bounds_union, or_and_distrib_right, and_comm (a ∈ t), and_assoc]\n\nlemma is_greatest_union_iff :\n  is_greatest (s ∪ t) a ↔ (is_greatest s a ∧ a ∈ upper_bounds t ∨\n    a ∈ upper_bounds s ∧ is_greatest t a) :=\n@is_least_union_iff (order_dual α) _ a s t\n\n/-- If `s` is bounded, then so is `s ∩ t` -/\nlemma bdd_above.inter_of_left (h : bdd_above s) : bdd_above (s ∩ t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s ∩ t` -/\nlemma bdd_above.inter_of_right (h : bdd_above t) : bdd_above (s ∩ t) :=\nh.mono $ inter_subset_right s t\n\n/-- If `s` is bounded, then so is `s ∩ t` -/\nlemma bdd_below.inter_of_left (h : bdd_below s) : bdd_below (s ∩ t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s ∩ t` -/\nlemma bdd_below.inter_of_right (h : bdd_below t) : bdd_below (s ∩ 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 ∪ t`. -/\nlemma bdd_above.union [semilattice_sup γ] {s t : set γ} :\n  bdd_above s → bdd_above t → bdd_above (s ∪ t) :=\nbegin\n  rintros ⟨bs, hs⟩ ⟨bt, ht⟩,\n  use bs ⊔ bt,\n  rw upper_bounds_union,\n  exact ⟨upper_bounds_mono_mem le_sup_left hs,\n    upper_bounds_mono_mem le_sup_right ht⟩\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 γ] {s t : set γ} :\n  bdd_above (s ∪ t) ↔ bdd_above s ∧ bdd_above t :=\n⟨λ h, ⟨h.mono $ subset_union_left s t, h.mono $ subset_union_right s t⟩,\n  λ h, h.1.union h.2⟩\n\nlemma bdd_below.union [semilattice_inf γ] {s t : set γ} :\n  bdd_below s → bdd_below t → bdd_below (s ∪ t) :=\n@bdd_above.union (order_dual γ) _ 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 γ] {s t : set γ} :\n  bdd_below (s ∪ t) ↔ bdd_below s ∧ bdd_below t :=\n@bdd_above_union (order_dual γ) _ s t\n\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a ⊔ b` is the least upper bound of `s ∪ t`. -/\nlemma is_lub.union [semilattice_sup γ] {a b : γ} {s t : set γ}\n  (hs : is_lub s a) (ht : is_lub t b) :\n  is_lub (s ∪ t) (a ⊔ b) :=\n⟨λ c h, h.cases_on (λ h, le_sup_of_le_left $ hs.left h) (λ h, le_sup_of_le_right $ ht.left h),\n  assume c hc, sup_le\n    (hs.right $ assume d hd, hc $ or.inl hd) (ht.right $ assume d hd, hc $ or.inr hd)⟩\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/\nlemma is_glb.union [semilattice_inf γ] {a₁ a₂ : γ} {s t : set γ}\n  (hs : is_glb s a₁) (ht : is_glb t a₂) :\n  is_glb (s ∪ t) (a₁ ⊓ a₂) :=\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 ∪ t`. -/\nlemma is_least.union [linear_order γ] {a b : γ} {s t : set γ}\n  (ha : is_least s a) (hb : is_least t b) : is_least (s ∪ t) (min a b) :=\n⟨by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_glb.union hb.is_glb).1⟩\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 ∪ t`. -/\nlemma is_greatest.union [linear_order γ] {a b : γ} {s t : set γ}\n  (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s ∪ t) (max a b) :=\n⟨by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_lub.union hb.is_lub).1⟩\n\nlemma is_lub.inter_Ici_of_mem [linear_order γ] {s : set γ} {a b : γ} (ha : is_lub s a)\n  (hb : b ∈ s) : is_lub (s ∩ Ici b) a :=\n⟨λ x hx, ha.1 hx.1, λ c hc, have hbc : b ≤ c, from hc ⟨hb, le_rfl⟩,\n  ha.2 $ λ x hx, (le_total x b).elim (λ hxb, hxb.trans hbc) $ λ hbx, hc ⟨hx, hbx⟩⟩\n\nlemma is_glb.inter_Iic_of_mem [linear_order γ] {s : set γ} {a b : γ} (ha : is_glb s a)\n  (hb : b ∈ s) : is_glb (s ∩ Iic b) a :=\nha.dual.inter_Ici_of_mem hb\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\nlemma is_least_Ici : is_least (Ici a) a := ⟨left_mem_Ici, λ x, id⟩\n\nlemma is_greatest_Iic : is_greatest (Iic a) a := ⟨right_mem_Iic, λ x, id⟩\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) := ⟨a, λ x hx, le_of_lt hx⟩\n\nlemma bdd_below_Ioi : bdd_below (Ioi a) := ⟨a, λ x hx, le_of_lt hx⟩\n\nsection\n\nvariables [linear_order γ] [densely_ordered γ]\n\nlemma is_lub_Iio {a : γ} : is_lub (Iio a) a :=\n⟨λ x hx, le_of_lt hx, λ y hy, le_of_forall_ge_of_dense hy⟩\n\nlemma is_glb_Ioi {a : γ} : is_glb (Ioi a) a := @is_lub_Iio (order_dual γ) _ _ a\n\nlemma upper_bounds_Iio {a : γ} : upper_bounds (Iio a) = Ici a := is_lub_Iio.upper_bounds_eq\n\nlemma lower_bounds_Ioi {a : γ} : 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⟨mem_singleton a, λ x hx, le_of_eq $ eq_of_mem_singleton hx⟩\n\nlemma is_least_singleton : is_least {a} a :=\n@is_greatest_singleton (order_dual α) _ 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 α) := is_lub_singleton.bdd_above\n\nlemma bdd_below_singleton : bdd_below ({a} : set α) := 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) := ⟨b, λ _, and.right⟩\n\nlemma bdd_below_Icc : bdd_below (Icc a b) := ⟨a, λ _, and.left⟩\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 ≤ b) : is_greatest (Icc a b) b :=\n⟨right_mem_Icc.2 h, λ x, and.right⟩\n\nlemma is_lub_Icc (h : a ≤ b) : is_lub (Icc a b) b := (is_greatest_Icc h).is_lub\n\nlemma upper_bounds_Icc (h : a ≤ b) : upper_bounds (Icc a b) = Ici b :=\n(is_lub_Icc h).upper_bounds_eq\n\nlemma is_least_Icc (h : a ≤ b) : is_least (Icc a b) a :=\n⟨left_mem_Icc.2 h, λ x, and.left⟩\n\nlemma is_glb_Icc (h : a ≤ b) : is_glb (Icc a b) a := (is_least_Icc h).is_glb\n\nlemma lower_bounds_Icc (h : a ≤ 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⟨right_mem_Ioc.2 h, λ x, and.right⟩\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⟨left_mem_Ico.2 h, λ x, and.left⟩\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 γ] [densely_ordered γ]\n\nlemma is_glb_Ioo {a b : γ} (h : a < b) :\n  is_glb (Ioo a b) a :=\n⟨λ x hx, hx.1.le, λ x hx,\nbegin\n  cases eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ h₂,\n  { exact h₁.symm ▸ le_sup_left },\n  obtain ⟨y, lty, ylt⟩ := exists_between h₂,\n  apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim,\n  obtain ⟨u, au, ub⟩ := exists_between h,\n  apply (hx ⟨au, ub⟩).trans ub.le,\nend⟩\n\nlemma lower_bounds_Ioo {a b : γ} (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 : γ} (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 : γ} (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 γ] [densely_ordered γ]\n\nlemma is_lub_Ioo {a b : γ} (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 : γ} (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 : γ} (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 : γ} (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 ↔ ∃ a, s ⊆ Ici a := iff.rfl\n\nlemma bdd_above_iff_subset_Iic : bdd_above s ↔ ∃ a, s ⊆ Iic a := iff.rfl\n\nlemma bdd_below_bdd_above_iff_subset_Icc : bdd_below s ∧ bdd_above s ↔ ∃ a b, s ⊆ 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 γ] [order_top γ] : is_greatest (univ : set γ) ⊤ :=\n⟨mem_univ _, λ x hx, le_top⟩\n\n@[simp] lemma order_top.upper_bounds_univ [partial_order γ] [order_top γ] :\n  upper_bounds (univ : set γ) = {⊤} :=\nby rw [is_greatest_univ.upper_bounds_eq, Ici_top]\n\nlemma is_lub_univ [preorder γ] [order_top γ] : is_lub (univ : set γ) ⊤ :=\nis_greatest_univ.is_lub\n\n@[simp] lemma order_bot.lower_bounds_univ [partial_order γ] [order_bot γ] :\n  lower_bounds (univ : set γ) = {⊥} :=\n@order_top.upper_bounds_univ (order_dual γ) _ _\n\nlemma is_least_univ [preorder γ] [order_bot γ] : is_least (univ : set γ) ⊥ :=\n@is_greatest_univ (order_dual γ) _ _\n\nlemma is_glb_univ [preorder γ] [order_bot γ] : is_glb (univ : set γ) ⊥ :=\nis_least_univ.is_glb\n\n@[simp] lemma no_top_order.upper_bounds_univ [no_top_order α] : upper_bounds (univ : set α) = ∅ :=\neq_empty_of_subset_empty $ λ b hb, let ⟨x, hx⟩ := no_top b in\nnot_le_of_lt hx (hb trivial)\n\n@[simp] lemma no_bot_order.lower_bounds_univ [no_bot_order α] : lower_bounds (univ : set α) = ∅ :=\n@no_top_order.upper_bounds_univ (order_dual α) _ _\n\n@[simp] lemma not_bdd_above_univ [no_top_order α] : ¬bdd_above (univ : set α) :=\nby simp [bdd_above]\n\n@[simp] lemma not_bdd_below_univ [no_bot_order α] : ¬bdd_below (univ : set α) :=\n@not_bdd_above_univ (order_dual α) _ _\n\n/-!\n#### Empty set\n-/\n\n@[simp] lemma upper_bounds_empty : upper_bounds (∅ : set α) = 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 (∅ : set α) = univ :=\n@upper_bounds_empty (order_dual α) _\n\n@[simp] lemma bdd_above_empty [nonempty α] : bdd_above (∅ : set α) :=\nby simp only [bdd_above, upper_bounds_empty, univ_nonempty]\n\n@[simp] lemma bdd_below_empty [nonempty α] : bdd_below (∅ : set α) :=\nby simp only [bdd_below, lower_bounds_empty, univ_nonempty]\n\nlemma is_glb_empty [preorder γ] [order_top γ] : is_glb ∅ (⊤:γ) :=\nby simp only [is_glb, lower_bounds_empty, is_greatest_univ]\n\nlemma is_lub_empty [preorder γ] [order_bot γ] : is_lub ∅ (⊥:γ) :=\n@is_glb_empty (order_dual γ) _ _\n\nlemma is_lub.nonempty [no_bot_order α] (hs : is_lub s a) : s.nonempty :=\nlet ⟨a', ha'⟩ := no_bot a in\nne_empty_iff_nonempty.1 $ assume h,\nhave a ≤ a', from hs.right $ by simp only [h, upper_bounds_empty],\nnot_le_of_lt ha' this\n\nlemma is_glb.nonempty [no_top_order α] (hs : is_glb s a) : s.nonempty := hs.dual.nonempty\n\nlemma nonempty_of_not_bdd_above [ha : nonempty α] (h : ¬bdd_above s) : s.nonempty :=\nnonempty.elim ha $ λ x, (not_bdd_above_iff'.1 h x).imp $ λ a ha, ha.fst\n\nlemma nonempty_of_not_bdd_below [ha : nonempty α] (h : ¬bdd_below s) : s.nonempty :=\n@nonempty_of_not_bdd_above (order_dual α) _ _ _ 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 γ] (a : γ) {s : set γ} :\n  bdd_above (insert a s) ↔ bdd_above s :=\nby simp only [insert_eq, bdd_above_union, bdd_above_singleton, true_and]\n\nlemma bdd_above.insert [semilattice_sup γ] (a : γ) {s : set γ} (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 γ] (a : γ) {s : set γ} :\n  bdd_below (insert a s) ↔ bdd_below s :=\nby simp only [insert_eq, bdd_below_union, bdd_below_singleton, true_and]\n\nlemma bdd_below.insert [semilattice_inf γ] (a : γ) {s : set γ} (hs : bdd_below s) :\n  bdd_below (insert a s) :=\n(bdd_below_insert a).2 hs\n\nlemma is_lub.insert [semilattice_sup γ] (a) {b} {s : set γ} (hs : is_lub s b) :\n  is_lub (insert a s) (a ⊔ b) :=\nby { rw insert_eq, exact is_lub_singleton.union hs }\n\nlemma is_glb.insert [semilattice_inf γ] (a) {b} {s : set γ} (hs : is_glb s b) :\n  is_glb (insert a s) (a ⊓ b) :=\nby { rw insert_eq, exact is_glb_singleton.union hs }\n\nlemma is_greatest.insert [linear_order γ] (a) {b} {s : set γ} (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 γ] (a) {b} {s : set γ} (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 : α) (s : set α) :\n  upper_bounds (insert a s) = Ici a ∩ upper_bounds s :=\nby rw [insert_eq, upper_bounds_union, upper_bounds_singleton]\n\n@[simp] lemma lower_bounds_insert (a : α) (s : set α) :\n  lower_bounds (insert a s) = Iic a ∩ 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 γ] [order_top γ] (s : set γ) : bdd_above s :=\n⟨⊤, assume a ha, order_top.le_top a⟩\n\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp] protected lemma order_bot.bdd_below [preorder γ] [order_bot γ] (s : set γ) : bdd_below s :=\n⟨⊥, assume a ha, order_bot.bot_le a⟩\n\n/-!\n#### Pair\n-/\n\nlemma is_lub_pair [semilattice_sup γ] {a b : γ} : is_lub {a, b} (a ⊔ b) :=\nis_lub_singleton.insert _\n\nlemma is_glb_pair [semilattice_inf γ] {a b : γ} : is_glb {a, b} (a ⊓ b) :=\nis_glb_singleton.insert _\n\nlemma is_least_pair [linear_order γ] {a b : γ} : is_least {a, b} (min a b) :=\nis_least_singleton.insert _\n\nlemma is_greatest_pair [linear_order γ] {a b : γ} : 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 ↔ is_glb s a :=\n⟨λ H, ⟨λ x hx, H.2 $ subset_upper_bounds_lower_bounds s hx, H.1⟩, is_greatest.is_lub⟩\n\n@[simp] lemma is_glb_upper_bounds : is_glb (upper_bounds s) a ↔ is_lub s a :=\n@is_lub_lower_bounds (order_dual α) _ _ _\n\nend\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\nsection preorder\nvariables [preorder α] {s : set α} {a b : α}\n\nlemma lower_bounds_le_upper_bounds (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds s) :\n  s.nonempty → a ≤ b\n| ⟨c, hc⟩ := 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 ≤ b :=\nlower_bounds_le_upper_bounds ha.1 hb.1 hs\n\nlemma is_lub_lt_iff (ha : is_lub s a) : a < b ↔ ∃ c ∈ upper_bounds s, c < b :=\n⟨λ hb, ⟨a, ha.1, hb⟩, λ ⟨c, hcs, hcb⟩, lt_of_le_of_lt (ha.2 hcs) hcb⟩\n\nlemma lt_is_glb_iff (ha : is_glb s a) : b < a ↔ ∃ c ∈ 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 ≤ a)\n  (hx : x ∈ s) (hy : y ∈ s) : x ≤ y :=\ncalc x ≤ b : hb.1 hx\n   ... ≤ a : hab\n   ... ≤ y : ha.1 hy\n\nend preorder\n\nsection partial_order\nvariables [partial_order α] {s : set α} {a b : α}\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 ↔ a = b :=\niff.intro Ha.unique (assume h, h ▸ 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 ↔ a = b :=\niff.intro Ha.unique (assume h, h ▸ 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 ≤ a) :\n  s.subsingleton :=\nλ 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 ∈ s) (Hy : y ∈ s) (Hxy : x ≠ y) :\n  a < b :=\nlt_iff_le_not_le.2\n  ⟨lower_bounds_le_upper_bounds Ha.1 Hb.1 ⟨x, Hx⟩,\n    λ hab, Hxy $ set.subsingleton_of_is_lub_le_is_glb Ha Hb hab Hx Hy⟩\n\nend partial_order\n\nsection linear_order\nvariables [linear_order α] {s : set α} {a b : α}\n\nlemma lt_is_lub_iff (h : is_lub s a) : b < a ↔ ∃ c ∈ s, b < c :=\nby simp only [← 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 ↔ ∃ c ∈ s, c < b := lt_is_lub_iff h.dual\n\nlemma is_lub.exists_between (h : is_lub s a) (hb : b < a) :\n  ∃ c ∈ s, b < c ∧ c ≤ a :=\nlet ⟨c, hcs, hbc⟩ := (lt_is_lub_iff h).1 hb in ⟨c, hcs, hbc, h.1 hcs⟩\n\nlemma is_lub.exists_between' (h : is_lub s a) (h' : a ∉ s) (hb : b < a) :\n  ∃ c ∈ s, b < c ∧ c < a :=\nlet ⟨c, hcs, hbc, hca⟩ := h.exists_between hb\nin ⟨c, hcs, hbc, hca.lt_of_ne $ λ hac, h' $ hac ▸ hcs⟩\n\nlemma is_glb.exists_between (h : is_glb s a) (hb : a < b) :\n  ∃ c ∈ s, a ≤ c ∧ c < b :=\nlet ⟨c, hcs, hbc⟩ := (is_glb_lt_iff h).1 hb in ⟨c, hcs, h.1 hcs, hbc⟩\n\nlemma is_glb.exists_between' (h : is_glb s a) (h' : a ∉ s) (hb : a < b) :\n  ∃ c ∈ s, a < c ∧ c < b :=\nlet ⟨c, hcs, hac, hcb⟩ := h.exists_between hb\nin ⟨c, hcs, hac.lt_of_ne $ λ hac, h' $ hac.symm ▸ hcs, hcb⟩\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 α] {s : set α} {a ε : α}\n\nlemma is_glb.exists_between_self_add (h : is_glb s a) (hε : 0 < ε) :\n  ∃ b ∈ s, a ≤ b ∧ b < a + ε :=\nh.exists_between $ lt_add_of_pos_right _ hε\n\nlemma is_glb.exists_between_self_add' (h : is_glb s a) (h₂ : a ∉ s) (hε : 0 < ε) :\n  ∃ b ∈ s, a < b ∧ b < a + ε :=\nh.exists_between' h₂ $ lt_add_of_pos_right _ hε\n\nlemma is_lub.exists_between_sub_self  (h : is_lub s a) (hε : 0 < ε) : ∃ b ∈ s, a - ε < b ∧ b ≤ a :=\nh.exists_between $ sub_lt_self _ hε\n\nlemma is_lub.exists_between_sub_self' (h : is_lub s a) (h₂ : a ∉ s) (hε : 0 < ε) :\n  ∃ b ∈ s, a - ε < b ∧ b < a :=\nh.exists_between' h₂ $ sub_lt_self _ hε\n\nend linear_ordered_add_comm_group\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\nnamespace monotone\n\nvariables [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α}\n\nlemma mem_upper_bounds_image (Ha : a ∈ upper_bounds s) :\n  f a ∈ upper_bounds (f '' s) :=\nball_image_of_ball (assume x H, Hf (Ha ‹x ∈ s›))\n\nlemma mem_lower_bounds_image (Ha : a ∈ lower_bounds s) :\n  f a ∈ lower_bounds (f '' s) :=\nball_image_of_ball (assume x H, Hf (Ha ‹x ∈ s›))\n\nlemma image_upper_bounds_subset_upper_bounds_image (hf : monotone f) :\n  f '' upper_bounds s ⊆ upper_bounds (f '' s) :=\nbegin\n  rintro _ ⟨a, ha, rfl⟩,\n  exact hf.mem_upper_bounds_image ha,\nend\n\nlemma image_lower_bounds_subset_lower_bounds_image (hf : monotone f) :\n  f '' lower_bounds s ⊆ 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. -/\nlemma map_bdd_above (hf : monotone f) : bdd_above s → bdd_above (f '' s)\n| ⟨C, hC⟩ := ⟨f C, hf.mem_upper_bounds_image hC⟩\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. -/\nlemma map_bdd_below (hf : monotone f) : bdd_below s → bdd_below (f '' s)\n| ⟨C, hC⟩ := ⟨f C, hf.mem_lower_bounds_image hC⟩\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⟨mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image Ha.2⟩\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⟨mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image Ha.2⟩\n\nlemma is_lub_image_le (Ha : is_lub s a) {b : β} (Hb : is_lub (f '' s) b) :\n  b ≤ f a :=\nHb.2 (Hf.mem_upper_bounds_image Ha.1)\n\nlemma le_is_glb_image (Ha : is_glb s a) {b : β} (Hb : is_glb (f '' s) b) :\n  f a ≤ b :=\nHb.2 (Hf.mem_lower_bounds_image Ha.1)\n\nend monotone\n\nnamespace antitone\nvariables [preorder α] [preorder β] {f : α → β} (hf : antitone f) {a : α} {s : set α}\n\nlemma mem_upper_bounds_image (ha : a ∈ lower_bounds s) :\n  f a ∈ upper_bounds (f '' s) :=\nhf.dual_right.mem_lower_bounds_image ha\n\nlemma mem_lower_bounds_image (ha : a ∈ upper_bounds s) :\n  f a ∈ lower_bounds (f '' s) :=\nhf.dual_right.mem_upper_bounds_image ha\n\nlemma image_lower_bounds_subset_upper_bounds_image (hf : antitone f) :\n  f '' lower_bounds s ⊆ upper_bounds (f '' s) :=\nhf.dual_right.image_lower_bounds_subset_lower_bounds_image\n\nlemma image_upper_bounds_subset_lower_bounds_image (hf : antitone f) :\n  f '' upper_bounds s ⊆ 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 (hf : antitone f) : bdd_above s → 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 (hf : antitone f) : bdd_below s → 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 (ha : is_greatest s a) : is_least (f '' s) (f a) :=\nhf.dual_right.map_is_greatest ha\n\n/-- An antitone map sends a least element of a set to a greatest element of its image. -/\nlemma map_is_least (ha : is_least s a) : is_greatest (f '' s) (f a) :=\nhf.dual_right.map_is_least ha\n\nlemma is_lub_image_le (ha : is_glb s a) {b : β} (hb : is_lub (f '' s) b) : b ≤ f a :=\nhf.dual_left.is_lub_image_le ha hb\n\nlemma le_is_glb_image (ha : is_lub s a) {b : β} (hb : is_glb (f '' s) b) : f a ≤ b :=\nhf.dual_left.le_is_glb_image ha hb\n\nend antitone\n\nlemma is_glb.of_image [preorder α] [preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y)\n  {s : set α} {x : α} (hx : is_glb (f '' s) (f x)) :\n  is_glb s x :=\n⟨λ y hy, hf.1 $ hx.1 $ mem_image_of_mem _ hy,\n  λ y hy, hf.1 $ hx.2 $ monotone.mem_lower_bounds_image (λ x y, hf.2) hy⟩\n\nlemma is_lub.of_image [preorder α] [preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y)\n  {s : set α} {x : α} (hx : is_lub (f '' s) (f x)) :\n  is_lub s x :=\n@is_glb.of_image (order_dual α) (order_dual β) _ _ f (λ x y, hf) _ _ hx\n\nlemma is_lub_pi {π : α → Type*} [Π a, preorder (π a)] {s : set (Π a, π a)} {f : Π a, π a} :\n  is_lub s f ↔ ∀ a, is_lub (function.eval a '' s) (f a) :=\nbegin\n  classical,\n  refine ⟨λ H a, ⟨(function.monotone_eval a).mem_upper_bounds_image H.1, λ b hb, _⟩, λ H, ⟨_, _⟩⟩,\n  { suffices : function.update f a b ∈ upper_bounds s,\n      from function.update_same a b f ▸ H.2 this a,\n    refine λ g hg, le_update_iff.2 ⟨hb $ mem_image_of_mem _ hg, λ i hi, H.1 hg i⟩ },\n  { exact λ g hg a, (H a).1 (mem_image_of_mem _ hg) },\n  { exact λ g hg a, (H a).2 ((function.monotone_eval a).mem_upper_bounds_image hg) }\nend\n\nlemma is_glb_pi {π : α → Type*} [Π a, preorder (π a)] {s : set (Π a, π a)} {f : Π a, π a} :\n  is_glb s f ↔ ∀ a, is_glb (function.eval a '' s) (f a) :=\n@is_lub_pi α (λ a, order_dual (π a)) _ s f\n\nlemma is_lub_prod [preorder α] [preorder β] {s : set (α × β)} (p : α × β) :\n  is_lub s p ↔ is_lub (prod.fst '' s) p.1 ∧ is_lub (prod.snd '' s) p.2 :=\nbegin\n  refine ⟨λ H, ⟨⟨monotone_fst.mem_upper_bounds_image H.1, λ a ha, _⟩,\n    ⟨monotone_snd.mem_upper_bounds_image H.1, λ a ha, _⟩⟩, λ H, ⟨_, _⟩⟩,\n  { suffices : (a, p.2) ∈ upper_bounds s, from (H.2 this).1,\n    exact λ q hq, ⟨ha $ mem_image_of_mem _ hq, (H.1 hq).2⟩ },\n  { suffices : (p.1, a) ∈ upper_bounds s, from (H.2 this).2,\n    exact λ q hq, ⟨(H.1 hq).1, ha $ mem_image_of_mem _ hq⟩ },\n  { exact λ q hq, ⟨H.1.1 $ mem_image_of_mem _ hq, H.2.1 $ mem_image_of_mem _ hq⟩ },\n  { exact λ q hq, ⟨H.1.2 $ monotone_fst.mem_upper_bounds_image hq,\n      H.2.2 $ monotone_snd.mem_upper_bounds_image hq⟩ }\nend\n\nlemma is_glb_prod [preorder α] [preorder β] {s : set (α × β)} (p : α × β) :\n  is_glb s p ↔ is_glb (prod.fst '' s) p.1 ∧ is_glb (prod.snd '' s) p.2 :=\n@is_lub_prod (order_dual α) (order_dual β) _ _ _ _\n\nnamespace order_iso\n\nvariables [preorder α] [preorder β] (f : α ≃o β)\n\nlemma upper_bounds_image {s : set α} :\n  upper_bounds (f '' s) = f '' upper_bounds s :=\nsubset.antisymm\n  (λ x hx, ⟨f.symm x, λ y hy, f.le_symm_apply.2 (hx $ mem_image_of_mem _ hy), f.apply_symm_apply x⟩)\n  f.monotone.image_upper_bounds_subset_upper_bounds_image\n\nlemma lower_bounds_image {s : set α} :\n  lower_bounds (f '' s) = f '' lower_bounds s :=\n@upper_bounds_image (order_dual α) (order_dual β) _ _ f.dual _\n\n@[simp] lemma is_lub_image {s : set α} {x : β} :\n  is_lub (f '' s) x ↔ is_lub s (f.symm x) :=\n⟨λ h, is_lub.of_image (λ _ _, f.le_iff_le) ((f.apply_symm_apply x).symm ▸ h),\n  λ h, is_lub.of_image (λ _ _, f.symm.le_iff_le) $ (f.symm_image_image s).symm ▸ h⟩\n\nlemma is_lub_image' {s : set α} {x : α} :\n  is_lub (f '' s) (f x) ↔ is_lub s x :=\nby rw [is_lub_image, f.symm_apply_apply]\n\n@[simp] lemma is_glb_image {s : set α} {x : β} :\n  is_glb (f '' s) x ↔ is_glb s (f.symm x) :=\nf.dual.is_lub_image\n\nlemma is_glb_image' {s : set α} {x : α} :\n  is_glb (f '' s) (f x) ↔ is_glb s x :=\nf.dual.is_lub_image'\n\n@[simp] lemma is_lub_preimage {s : set β} {x : α} :\n  is_lub (f ⁻¹' s) x ↔ is_lub s (f x) :=\nby rw [← f.symm_symm, ← image_eq_preimage, is_lub_image]\n\nlemma is_lub_preimage' {s : set β} {x : β} :\n  is_lub (f ⁻¹' s) (f.symm x) ↔ is_lub s x :=\nby rw [is_lub_preimage, f.apply_symm_apply]\n\n@[simp] lemma is_glb_preimage {s : set β} {x : α} :\n  is_glb (f ⁻¹' s) x ↔ is_glb s (f x) :=\nf.dual.is_lub_preimage\n\nlemma is_glb_preimage' {s : set β} {x : β} :\n  is_glb (f ⁻¹' s) (f.symm x) ↔ is_glb s x :=\nf.dual.is_lub_preimage'\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/order/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181418, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.779390998136884}}
{"text": "import MyNat.Addition -- imports addition.\nnamespace MyNat\nopen MyNat\n\n/-!\n# Addition World.\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? Didn't you already prove\nthat adding zero to `n` gave us `n`? No you didn't! You proved `n + 0 = n`, and that proof was called\n`add_zero`. We're now trying to establish `zero_add`, the proof that `0 + n = n`. But aren't these\ntwo theorems the same? No they're not! It is *true* that `x + y = y + x`, but you haven't *proved* it\nyet, and in fact you will need both `add_zero` and `zero_add` in order to prove this. In fact\n`x + y = y + x` is the boss level for addition world, and `induction` is the only other tactic you'll\nneed to beat it.\n\nNow `add_zero` is one of Peano's axioms, so you don't need to prove it, you already have it (indeed,\nif you've used Goto Definition (F12) on this theorem you can even see it). To prove `0 + n = n` we\nneed to use induction on `n`. While we're here, note that `zero_add` is about zero add something,\nand `add_zero` is about something add zero. The names of the proofs tell you what the theorems are.\n\n**Lemma**\n\nFor all natural numbers `n`, we have `0 + n = n.`\n-/\nlemma zero_add (n : MyNat) : 0 + n = n := by\n  induction n with\n  | zero => rfl\n  | succ n ih =>\n      rw [add_succ]\n      rw [ih]\n\n/-!\n\nNotice that the [induction tactic](../Tactics/induction.lean.md) has created *two sub-goals*\nwhich you can match using vertical bar pattern patching.\n\nThe induction tactic has generated for us a base case with `n = zero` (the goal at the top)\nand an inductive step (the goal underneath). The golden rule: **Tactics operate on the first goal**\n- the goal at the top. So let's just worry about that top goal now, the base case.\nIf you place the cursor right after the `=>` symbol you will see the goal listed in\nthe InfoView as `⊢ 0 + zero = zero`.\n\nRemember that `add_zero` (the proof we have already) is the proof of `x + 0 = x`\n(for any `x`) so you can try `rw [add_zero]` here but what do you think the goal will change to?\nRemember to just keep focussing on the top goal, ignore\nthe other one for now, it's not changing and in fact, the InfoView tells you why:\n```\ntactic 'rewrite' failed, did not find instance of the pattern in the target expression\n```\n\nBut as you can see `rfl` can solve the first case. You should now see `Goals accomplished 🎉` when\nyour cursor is placed on the right of the `rfl` which means you have solved this base case sub-goal,\nand you are ready to tackle the next sub-goal -- the inductive step. Take a look at the text below\nthe lemma to see an explanation of this goal.\n\nIn the successor case the InfoView tactic state should look something like this:\n\n```\ncase succ\nn: MyNat\nih: 0 + n = n\n⊢ 0 + succ n = succ n\n```\n\n*Important:* make sure that you only have one goal at this point. You should have proved `0 + 0 = 0`\nby now. Tactics only operate on the top goal.\n\nThe first line just reminds you you're doing the inductive step. You have a fixed natural number `n`,\nand the inductive hypothesis `ih : 0 + n = n` which means this hypothesis proves `0 + n = n`. Your\ngoal is to prove `0 + succ n = succ n`. In other words, we're showing that if the lemma is true for\n`n`, then it's also true for `n + 1`. That's the inductive step that you might be familiar with in\nproof by induction. Once we've proved this inductive step, you will have proved `zero_add` by the\nprinciple of mathematical induction.\n\nTo prove your goal, you need to use `add_succ` which you proved in\n[Tutorial World Level 4](../TutorialWorld/Level4.lean.md). Note that `add_succ 0 d`\nis the result that `0 + succ d = succ (0 + d)`, so the first thing\nyou need to do is to replace the left hand side `0 + succ d` of your\ngoal with the right hand side. You do this with the `rw` command: `rw [add_succ]`\n(or even `rw [add_succ 0 n]` if you want to give Lean all the inputs instead of making it\nfigure them out itself). Notice goal changes to `⊢ succ (0 + n) = succ n`.\n\nNow remember the inductive hypothesis `ih : 0 + d = d`. This `0 + d` matches\nthe `(0 + n)` in the goal, so you can write that using `rw [ih]`.\nThe goal will now change to\n\n`⊢ succ d = succ d`\n\nand the `rw` tactic will automatically finish our proof using the `rfl` tactic.\nAfter you apply it, Lean will inform you that there are no goals left. You are done!\n\nRemember that you can write `rw [add_succ, ih]` also, but notice that rewriting is\norder dependent and that `rw [ih, add_succ]` does not work.\n\n## Now venture off on your own\n\nThose three tactics --\n\n* `induction n with ...`\n* `rw [h]`\n* `rfl`\n\nwill get you quite a long way through this tutorial. Using only these tactics\ndo all of Addition World,\nall of [Multiplication World](../MultiplicationWorld.lean.md) including the boss level `a * b = b * a`,\nand even all of [Power World](../PowerWorld.lean.md) 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 read 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 [the Lean chat](https://leanprover.zulipchat.com).\n(login required, real name preferred, github account id is handy).\nKevin or Mohammad or one of the other people there might be able to help.\n\nOn to [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/AdditionWorld/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505273888291, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7793909907031984}}
{"text": "import MyNat.Definition\nimport MultiplicationWorld.Level1 -- zero_mul\nimport AdvancedMultiplicationWorld.Level2 -- eq_zero_or_eq_zero_of_mul_eq_zero\nimport Mathlib.Tactic.LeftRight\nnamespace MyNat\nopen MyNat\n\n/-!\n# Advanced Multiplication World\n\n## Level 3: `mul_eq_zero_iff`\n\nNow you have `eq_zero_or_eq_zero_of_mul_eq_zero` this is pretty straightforward.\n\n## Theorem\n`ab = 0`, if and only if at least one of `a` or `b` is equal to zero.\n-/\ntheorem mul_eq_zero_iff (a b : MyNat): a * b = 0 ↔ a = 0 ∨ b = 0 := by\n  constructor\n  {\n     intro h\n     exact eq_zero_or_eq_zero_of_mul_eq_zero a b h\n  }\n  {\n    intro hab\n    cases hab with\n    | inl ha =>\n      rw [ha]\n      rw [zero_mul]\n    | inr hb =>\n      rw [hb]\n      rw [mul_zero]\n  }\n\n/-!\n\nNext up [Level 4](./Level4.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/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7791639914271998}}
{"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 {α β γ A B C: Type*}\nvariable (R : A → A → Prop)\n\ndef union (r : α → β → Prop) (s : α → β → Prop) (a : α) (b : β) : Prop := r a b ∨ s a b\ndef intersect (r : α → β → Prop) (s : α → β → Prop) (a : α) (b : β) : Prop := r a b ∧ s a b\ndef transpose (r : α → β → Prop) (b : β) (a : α) : Prop := r a b\ndef complement (r : α → β → Prop) (a : α) (b : β) : Prop := ¬(r a b)\ndef comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ (b : β), r a b ∧ p b c\n\ndef reflexive (R : A → A → Prop) : Prop := ∀ x, R x x\ndef irreflexive (R : A → A → Prop) : Prop := ∀ x, ¬ R x x\ndef symmetric (R : A → A → Prop) : Prop := ∀ x y, R x y → R y x\ndef asymmetric (R : A → A → Prop) : Prop := ∀ (a b : A), R a b → ¬(R b a)\ndef transitive (R : A → A → Prop) : Prop := ∀ x y z, R x y → R y z → R x z\ndef anti_symmetric (R : A → A → Prop) : Prop := ∀ x y, R x y → R y x → x = y\n\ndef preorder (R : A → A → Prop) : Prop := reflexive R ∧ transitive R\ndef total (R : A → A → Prop) : Prop := ∀ x y, R x y ∨ R y x\ndef partial_order (R : A → A → Prop) : Prop := preorder R ∧ anti_symmetric R\ndef total_order (R : A → A → Prop) : Prop := partial_order R ∧ total R\ndef strict_order (R : A → A → Prop) : Prop := transitive R ∧ asymmetric R\n\n-- Section 4: Equivalence relations\ndef equivalence (R : A → A → Prop) := reflexive R ∧ symmetric R ∧ transitive R\n\n-- Using preorder, we describe a partial order as an antisymmetric preorder,\n-- and an equivalence relation as a symmetric preorder\n\nexample (R : A → A → Prop):\n  equivalence R ↔ preorder R ∧ symmetric R :=\nbegin\n  split,\n  { intro equivR,\n    cases equivR with reflR h1,\n    split,\n    split,\n    exact reflR,\n    exact h1.2, -- transitive R\n    exact h1.1}, -- symmetric R\n  { intro h,\n    cases h with h1 symmR,\n    split,\n    exact h1.1, -- reflexive R\n    split,\n    exact symmR,\n    exact h1.2}, -- transitive R\nend\n\n-- another way of defining equivalence relations\nexample (R : A → A → Prop) (reflR : reflexive R) (h : ∀ (a b c : A), R a b ∧ R c b → R a c) : equivalence R :=\nbegin\n  split,\n  -- prove reflexivity\n  exact reflR,\n\n  split,\n  -- prove symmetry\n  intros a b hRab,\n  have h1 : R b b := reflR b,\n  specialize h b b a,\n  apply h,\n  split,\n  exact h1, exact hRab,\n\n  -- prove transitivity\n  intros a b c hRab hRbc,\n  have h2 : R a b ∧ R c b → R a c := h a b c,\n  have h3 : R c c ∧ R b c → R c b := h c c b,\n  apply h2,\n  split,\n  exact hRab,\n  apply h3,\n  split,\n  exact reflR c,\n  exact hRbc,\nend\n\n-- If E is a equivalence relation, then E ∘ ((E ∘ R) ∩ S) = (E ∘ R) ∩ (E ∘ S)\nexample (E : A → A → Prop) (R : A → A → Prop) (S : A → A → Prop) (equivE : equivalence E) : comp E (intersect (comp E R) S) = intersect (comp E R) (comp E S) :=\nbegin\n  cases equivE with reflE equivE,\n  cases equivE with symmE transE,\n\n  ext a b,\n  split,\n  { intro h,\n    cases h with c hc,\n    cases hc with hEac hc,\n    cases hc with hER hScb,\n    cases hER with d hcd,\n    split,\n    { use d,\n      split,\n      apply transE a c d hEac hcd.1,\n      exact hcd.2},\n    { use c,\n      split,\n      exact hEac,\n      exact hScb},\n    },\n  { intro h,\n    cases h with hER hES,\n    cases hER with c hc,\n    cases hES with d hd,\n    use d,\n    split,\n    exact hd.1,\n    split,\n    { use c,\n      split,\n      have hEda : E d a, apply symmE a d hd.1,\n      apply transE d a c hEda hc.1,\n      exact hc.2},\n    exact hd.2,\n    },\nend\n-- Since R, S are arbitrary, we can use similar arguments to show `E ∘ ((E ∘ S) ∩ R) = (E ∘ R) ∩ (E ∘ S)`.\n\n-- Section 5: Compositions\nnamespace composition_relations\n/-\nDefine composition of relations (analogous to friend of a friend):\nFor relations R,S on set A, the composition `R ∘ S` is the relation that, for a,b ∈ A, \n(R ∘ S)(a,b) is the proposition that `∃ (y : A), R a y ∧ S y b`.\n\nIf R = S, we write the composition as R₂.\n-/\ndef R₂ (a b : A) : Prop := ∃ (y : A), R a y ∧ R y b\n-- ∃ (y : A), R a y ∧ R y b\n-- (∀ (a b : A), (∃ (y : A), R a y ∧ R y b) → R a b)\n\n-- The composition operation on binary relations is associative.\nlemma relation_comp_assoc (R : A → A → Prop) (S : A → A → Prop) (T : A → A → Prop) : comp (comp R S) T = comp R (comp S T) :=\nbegin\n  ext a b,\n  split,\n  { intro h,\n    cases h with y h, -- unfold relation.comp & let such element be y\n    cases h with h1 h2, -- split conjunction ∧\n    cases h1 with z h1, -- unfold relation.comp & let such element be z\n    use z,\n    split,\n    exact h1.1,\n    { use y,\n      split,\n      exact h1.2,\n      exact h2},\n    },\n  { intro h,\n    rw comp at *,\n    cases h with y h, -- unfold relation.comp & let such element be y\n    cases h with h1 h2,\n    cases h2 with z h2, -- unfold relation.comp & let such element be y\n    use z,\n    split,\n    { use y,\n      split,\n      exact h1,\n      exact h2.1},\n    exact h2.2,\n  },\nend\n\n-- A relation R is transitive iff R_2 is transitive.\nlemma trans_iff_closure (R : A → A → Prop) : transitive R ↔ (∀ (a b : A), (∃ (y : A), R a y ∧ R y b) → R a b) :=\nbegin\n  split,\n  { intros transR a b h1,\n    cases h1 with y h1,\n    apply transR a y b h1.1 h1.2,\n    },\n  { intro h,\n    intros a b c hRab hRbc,\n    specialize h a c,\n    apply h,\n    use b,\n    split,\n    exact hRab,\n    exact hRbc,\n    },\nend\n\ndef idempotent (R : A → A → Prop) : Prop := \n∀ (a b : A), (∃ (y : A), R a y ∧ R y b) ↔ R a b\n\nlemma refl_trans_implies_idempotence (reflR : reflexive R) (transR : transitive R) : idempotent R :=\nbegin\n  intros a b,\n  split,\n  { intro h,\n    cases h with y h,\n    apply transR a y b h.1 h.2},\n  { intro Rab,\n    use a,\n    split,\n    apply reflR a,\n    exact Rab},\nend \n\ndef R_transpose (a b : A) : Prop := R b a\n\nend composition_relations\n\nnamespace relations_2\n--variables {a b : A}\n\n/- Schröder's rule\nFor binary relations (a : A → B → Prop) (b : B → C → Prop) (c : A → C → Prop), the following are equivalent:\n1)  a ∘ b ⊆ c\n2)  a.transpose ∘ c.complement ⊆ b.complement\n3)  c.complement ∘ b.transpose ⊆ a.complement\n-/\n\ntheorem schroder_rule_1 (a : A → B → Prop) (b : B → C → Prop) (c : A → C → Prop) : \n(∀ (x : A) (z : C), relation.comp a b x z → c x z) ↔ (∀ (y : B) (z : C), relation.comp (transpose a) (complement c) y z → complement b y z) :=\nbegin\n  split,\n  { intro h,\n    intros y z h1, -- fix y ∈ B and z ∈ C\n    --rw relation.comp at h1, -- unfold relation composition\n    cases h1 with x h1, -- let such element be x ∈ A\n    cases h1 with haxy hncxz, -- simplify `and` conjunction\n    specialize h x z,\n    intro hbyz, -- change complement def into `b y z → false`\n    apply hncxz,\n    apply h,\n    use y, -- y is the required intermediate element\n    split,\n    exact haxy,\n    exact hbyz,\n    },\n  { intro h,\n    intros x z h1, -- fix x ∈ A and z ∈ C\n    cases h1 with y h1, -- let such intermediate element be y\n    cases h1 with haxy hbyz, -- simplify `and` conjunction\n    specialize h y z,\n    by_contra hncxz,\n    apply h,\n    { use x, -- x is the required intermediate element\n      split,\n      exact haxy,\n      exact hncxz},\n    exact hbyz,\n    },\nend\n\ntheorem schroder_rule_2 (a : A → B → Prop) (b : B → C → Prop) (c : A → C → Prop) : (∀ (x : A) (z : C), comp a b x z → c x z) ↔ (∀ (x : A) (y : B), comp (complement c) (transpose b) x y → complement a x y) :=\nbegin\n  split,\n  { intro h,\n    intros x y h1, -- fix x ∈ A and y ∈ B\n    cases h1 with z h1, -- let such element be z ∈ C\n    cases h1 with hncxz hbzy, -- simplify `and` conjunction\n    specialize h x z,\n    intro haxy,\n    apply hncxz,\n    apply h,\n    use y, -- y is the required intermediate element\n    split,\n    exact haxy,\n    exact hbzy},\n  { intro h,\n    intros x z h1, -- fix x ∈ A and z ∈ C\n    cases h1 with y h1, -- let such element be y ∈ B\n    cases h1 with haxy hbyz,\n    specialize h x y,\n    by_contra hncxz,\n    apply h,\n    { use z,  -- z is the required intermediate element\n      split,\n      exact hncxz,\n      exact hbyz},\n    exact haxy},\nend\n\nlemma transpose_comp (a : A → B → Prop) (b : B → C → Prop) : transpose (comp a b) = comp (transpose b) (transpose a) :=\nbegin\n  ext z x,\n  split,\n  { intro h,\n    -- rw relation_transpose at h,\n    cases h with y hy, -- let such element in the composition be y ∈ B\n    use y,\n    split,\n    exact hy.2,\n    exact hy.1},\n  { intro h,\n    cases h with y hy,\n    use y,\n    split,\n    exact hy.2,\n    exact hy.1},\nend\n\n/- Dedekind rule\nFor binary relations (a : A → B → Prop) (b : B → C → Prop) (c : A → C → Prop), x ∈ A, y ∈ B,\n((a ∘ b) ∩ c) x y → ((a ∩ (c ∘ b.transpose)) ∘ (b ∩ (a.transpose ∘ c))) x y\n-/\n\ntheorem dedekind_rule (a : A → B → Prop) (b : B → C → Prop) (c : A → C → Prop) : ∀ (x : A) (z : C), intersect (comp a b) c x z → comp (intersect a (comp c (transpose b))) (intersect b (comp (transpose a) c)) x z :=\nbegin\n  intros x z h,\n  cases h with h1 hcxz,\n  cases h1 with y h1_y,\n  use y,\n  split,\n  { split,\n    { exact h1_y.1},\n    { use z,\n      split,\n      exact hcxz,\n      exact h1_y.2},\n    },\n  { split,\n    { exact h1_y.2},\n    { use x,\n      split,\n      exact h1_y.1,\n      exact hcxz},\n    },\nend\n\n-- Exercise 4.3.1 (Relational Mathematics) (R ⊆ R ∘ R.transpose ∘ R)\nexample (r : A → B → Prop) (x : A) (y : B): r x y → comp (comp r (transpose r)) r x y :=\nbegin\n  intro rxy,\n  use x,\n  split,\n  { use y,\n    split,\n    exact rxy,\n    exact rxy},\n  { exact rxy},\nend\n\n-- Exercise 4.3.2 (Relational Mathematics) (A.transpose ∘ C ⊆ D → (A ∘ B) ∩ C ⊆ A ∘ (B ∩ D))\nexample (a : A → B → Prop) (b : B → C → Prop) (c : A → C → Prop) (d : B → C → Prop) : \n(∀ (y : B) (z : C), comp (transpose a) c y z → d y z) → (∀ (x : A) (z : C), intersect (comp a b) c x z  → comp a (intersect b d) x z) :=\nbegin\n  intro h,\n  intros x z h1,\n  cases h1 with h2 hcxz,\n  cases h2 with y h2,\n  cases h2 with haxy hbyz,\n  specialize h y z,\n  use y,\n  split,\n  exact haxy,\n  split,\n  { exact hbyz},\n  { apply h,\n    use x,\n    split,\n    exact haxy,\n    exact hcxz},\nend\n\nend relations_2\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_(3_equiv_and_composition).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.779160052512926}}
{"text": "import tactic\n\n/-\n\ndata.equiv.basic  is the import which gives you the type `equiv X Y`, the type o\nf\nbijections from X to Y.\n\nHere's the definition of equiv from that file.\n\nstructure equiv (α : Sort*) (β : Sort*) :=\n(to_fun    : α → β)\n(inv_fun   : β → α)\n(left_inv  : left_inverse inv_fun to_fun)\n(right_inv : right_inverse inv_fun to_fun)\n\nTo make a term of type `equiv α β` you have to supply a function α → β,\na function β → α, and proofs that both composites are the identity function.\n\nLet's see how to create the bijection ℤ → ℤ sending x to -x.\n-/\n-- let's prove that x ↦ -x can be extended to\nexample : equiv ℤ ℤ :=\n{ to_fun := λ x, -x, -- this is data\n  inv_fun := λ x, -x,  -- this is data\n  left_inv := begin -- this is a proof\n    change ∀ (x : ℤ), - -x = x, -- that's the question\n    exact neg_neg, -- note: I guessed what this function was called.\n                   -- If it had been called \"lemma 12\" I would not have been able to guess\n  end,\n  right_inv := neg_neg -- another proof, this time in term mode\n}\n\n/-\nQ1 Define the type of partitions of a type.\nA partition of X is a set of subsets of X with the property that each subset\nis non-empty and each element of X is in precisely one of the subsets.\nNB : this is one of the harder questions here.\n-/\n\nstructure partition (X : Type*) :=\n(ℱ : set (set X))\n(disjoint : ∀ A B ∈ ℱ, A ≠ B → A ∩ B = ∅)\n(cover : ∀ x : X, ∃ A ∈ ℱ, x ∈ A)\n(nonempty : ∀ A ∈ ℱ, A ≠ ∅)\n\n\n/-\nEquivalence relations are in core Lean -- we don't need any imports.\nHere's an example: I'll prove that the \"always true\" relation on a set is\nan equivalence relation.\n\n-/\n\ndef always_true (X : Type*) : X → X → Prop := λ a b, true\n\n-- and now here's the proof that it's an equivalence relation.\n\ntheorem always_true_refl (X) : reflexive (always_true X) :=\nbegin\n  intro x,\n  trivial\nend\n\ntheorem always_true_symm (X) : symmetric (always_true X) :=\nbegin\n  intros a b H,\n  trivial\nend\n\ntheorem always_true_trans (X) : transitive (always_true X) :=\nbegin\n  intros a b c Hab Hbc,\n  trivial\nend\n\n-- note pointy brackets to make a term of type \"A ∧ B ∧ C\"\ntheorem always_true_equiv (X): equivalence (always_true X) :=\n⟨always_true_refl X, always_true_symm X, always_true_trans X⟩\n-- autocomplete made that proof really easy to type. It's really\n-- lucky that I didn't call these lemmas lemma 12, lemma 13 and lemma 14.\n\n-- if X is a type, then `setoid X` is is the type of equivalence relations on X.\n-- I'll now make a term of type `setoid X` corresponding to that equivalence\n-- relation above.\n\n-- note squiggly brackets and commas at the end of each definition \n-- to make a structure\ndef always_true_setoid (X : Type*) : setoid X :=\n{ r := always_true X,\n  iseqv := always_true_equiv X }\n\n/-\nQ2 : If X is a type then `setoid X` is the type of equivalence relations on X,\nand `partitions X` is the type of partitions of X. These two concepts are in\nsome sort of \"canonical\" bijection with each other (interesting exercise: make\nthis statement mathematically meaningful -- I know we all say it, but what\ndoes it *mean*?).\n\nLet's prove that these sets biject with each other by defining\na term of type equiv (setoid X) (partitions X)\n-/\n\nvariable {X : Type*}\n\ndef F (S : setoid X) : partition X := sorry\n\n/-\nQ3 : now define a map the other way\n-/\n\ndef G (P : partition X) : setoid X := sorry\n\n/-\nQ4 : now finally prove that the composite of maps in both directions\nis the identity\n-/\n\ntheorem FG_eq_id (P : partition X) : F (G P) = P := sorry\ntheorem GF_eq_id (S : setoid X) : G (F S) = S := sorry\n\n/-\nQ5 : now finally construct the term we seek.\n-/\n\ndef partitions_biject_with_equivalence_relations :\n  equiv (setoid X) (partition X) := 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/2020/relations/equiv_partition2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.779140886906814}}
{"text": "import data.nat.basic\nimport data.set.basic\nimport logic.basic\nimport tactic.basic\nimport tactic.suggest\nopen classical\n\n-- So that we can ignore the difference between computable and uncomputable sets.\n-- open_locale classical\n-- noncomputable theory\n\ndef is_even (a : ℕ) := ∃ b, 2 * b = a\n\ndef is_odd (a : ℕ) := ∃ b, 2 * b + 1 = a\n\ntheorem zero_is_even: is_even 0 :=\nexists.intro 0 (zero_mul 2)\n\ntheorem even_plus_one_is_odd (a : ℕ) (h: is_even a) : is_odd (a + 1) :=\nexists.elim h\n(assume b, assume hb: 2 * b = a, show is_odd (a + 1), from\nexists.intro b\n  (calc\n  2 * b + 1 = a + 1 : by rw hb\n  )       \n)\n\nlemma two_times_one: 2 * 1 = 1 + 1 := rfl\n\ntheorem odd_plus_one_is_even (a : ℕ) (h: is_odd a) : is_even (a + 1) :=\nexists.elim h\n(assume b, assume hb: 2 * b + 1 = a, show is_even (a + 1), from\nexists.intro (b + 1)\n(calc\n  2 * (b + 1) = 2 * b + 2 * 1 : by rw mul_add\n  ... = 2 * b + 1 + 1 : by rw two_times_one\n  ... = a + 1 : by rw hb\n)\n)\n\ndef eoro (a : ℕ) := (is_even a) ∨ (is_odd a)\n\nlemma even_plus_one_eoro (a : ℕ) (h: is_even a) : eoro (a + 1) :=\n(or.intro_right (is_even (a + 1)) (even_plus_one_is_odd a h))\n\nlemma odd_plus_one_eoro (a : ℕ) (h: is_odd a) : eoro (a + 1) :=\n(or.intro_left (is_odd (a + 1)) (odd_plus_one_is_even a h))\n\nlemma eoro_inducts (a : ℕ) (h: eoro a) : eoro (a + 1) :=\nor.elim h\n(assume he: is_even a, show eoro (a + 1), from even_plus_one_eoro a he)\n(assume ho: is_odd a, show eoro (a + 1), from odd_plus_one_eoro a ho)\n\nlemma zero_eoro : (eoro 0) := or.intro_left (is_odd 0) zero_is_even\n\ntheorem all_eoro (n : ℕ) : eoro n :=\nnat.rec_on n\n(show eoro 0, from zero_eoro)\n(assume n,\n assume hn : eoro n,\n show eoro (n + 1),\n from eoro_inducts n hn)\n\ndef times_successor (n : ℕ) := n * (n + 1)\n\ntheorem even_times_any (a b : ℕ) (h: is_even a) : is_even (a * b) :=\nexists.elim h\n(assume c, assume hc: 2 * c = a, show is_even (a * b), from\n exists.intro (c * b)\n (calc\n  2 * (c * b) = (2 * c) * b : by rw mul_assoc 2 c b\n  ... = a * b : by rw hc))\n\ntheorem any_times_even (a b : ℕ) (h: is_even b): is_even (a * b) :=\nhave h1: b * a = a * b, from (mul_comm b a),\nhave h2: is_even (b * a), from (even_times_any b a h),\nh1 ▸ h2\n\nlemma even_tse (a : ℕ) (h: is_even a) : is_even (times_successor a) :=\neven_times_any a (a + 1) h\n\nlemma odd_tse (a : ℕ) (h1: is_odd a) : is_even (times_successor a) :=\nhave h2: is_even (a + 1), from (odd_plus_one_is_even a h1),\nany_times_even a (a + 1) h2\n\ntheorem times_successor_even (a : ℕ) : is_even (times_successor a) :=\nhave h: eoro a, from all_eoro a,\nor.elim h\n(assume he: is_even a, show is_even (times_successor a), from even_tse a he)\n(assume ho: is_odd a, show is_even (times_successor a), from odd_tse a ho)\n\ndef is_composite (a : ℕ) := ∃ b, ∃ c, b > 1 ∧ c > 1 ∧ b * c = a\n\ntheorem composite_divisor_lt (a b c : ℕ) (h1: a * b = c) (h2: a > 1) (h3: b > 1) : a < c :=\nhave h4: 0 < b, from nat.lt_of_succ_lt h3,\nhave h5: a ≤ a * b, from nat.le_mul_of_pos_right h4,\nhave h6: a ≤ c, from eq.subst h1 h5,\nhave h7: a = c ∨ a ≠ c, from em(a=c),\nor.elim h7\n (assume h8: a = c,\n  have h9: a * b = a, from (rfl.congr (eq.symm h8)).mp h1,\n  have h10: 0 < a, from nat.lt_of_succ_lt h2,\n  have h11: b = 1, from (nat.mul_right_eq_self_iff h10).mp h9,\n  have h12: b ≠ 1, from ne_of_gt h3,\n  absurd h11 h12)\n (assume : a ≠ c,\n  show a < c, from lt_of_le_of_ne h6 this)\n\ndef is_prime (p : ℕ) := p > 1 ∧ ¬ (is_composite p)\n\ntheorem prime_pos (p : ℕ) (h1: is_prime p) : p > 0 :=\nhave p > 1, from h1.left,\nshow p > 0, from nat.lt_of_succ_lt this\n\ndef divides (a b : ℕ) := ∃ c, a * c = b\n\ndef is_empty (s : set ℕ) := ∀ a : ℕ, a ∉ s\ndef lower_bound (a : ℕ) (s : set ℕ) := ∀ b : ℕ, b ∈ s → a ≤ b\ndef upper_bound (a : ℕ) (s : set ℕ) := ∀ b : ℕ, b ∈ s → a ≥ b\ndef is_smallest (a : ℕ) (s : set ℕ) := a ∈ s ∧ lower_bound a s\ndef is_largest (a : ℕ) (s : set ℕ) := a ∈ s ∧ upper_bound a s\n\ntheorem not_ltz (a : ℕ) : ¬ (a < 0) := not_lt_bot\n\nlemma lower_bound_union (s1 s2 : set ℕ) (a1 a2 : ℕ)\n(h1: lower_bound a1 s1) (h2: lower_bound a2 s2) (h3 : a1 ≤ a2) :\nlower_bound a1 (s1 ∪ s2) :=\nassume b : ℕ,\nassume h4: b ∈ (s1 ∪ s2),\nor.elim h4\n(assume h5: b ∈ s1, show a1 ≤ b, from h1 b h5)\n(assume h6: b ∈ s2,\n have h7: a2 ≤ b, from h2 b h6,\n show a1 ≤ b, from le_trans h3 h7)\n\nlemma upper_bound_union (s1 s2 : set ℕ) (a1 a2 : ℕ)\n(h1: upper_bound a1 s1) (h2: upper_bound a2 s2) (h3 : a1 ≤ a2) :\nupper_bound a2 (s1 ∪ s2) :=\nassume b : ℕ,\nassume h4: b ∈ s1 ∪ s2,\nor.elim h4\n(assume h5: b ∈ s1,\n have h6: a1 ≥ b, from h1 b h5,\n show a2 ≥ b, from le_trans h6 h3)\n(assume h7: b ∈ s2,\n show a2 ≥ b, from h2 b h7)\n\nlemma is_smallest_union (s1 s2 : set ℕ) (a1 a2 : ℕ)\n(h1 : is_smallest a1 s1) (h2 : is_smallest a2 s2) (h3 : a1 ≤ a2) :\nis_smallest a1 (s1 ∪ s2) :=\nhave h4: a1 ∈ (s1 ∪ s2), from set.mem_union_left s2 h1.left,\nhave h5: lower_bound a1 (s1 ∪ s2), from lower_bound_union s1 s2 a1 a2 h1.right h2.right h3,\nand.intro h4 h5\n\nlemma inne (s : set ℕ) (a b : ℕ) (ha : a ∈ s) (hb : b ∉ s) : a ≠ b :=\nhave h1: a = b ∨ a ≠ b, from em(a=b),\nor.elim h1\n  (assume h2: a = b,\n   have h3: b ∈ s, from eq.subst h2 ha,\n   show a ≠ b, from absurd h3 hb)\n  (assume h4: a ≠ b, show a ≠ b, from h4)\n\nlemma lbih (s : set ℕ) (n : ℕ) (h1 : lower_bound n s) (h2 : n ∉ s) : lower_bound (n+1) s :=\nassume b : ℕ,\nassume h3 : b ∈ s,\nhave h4: b ≠ n, from inne s b n h3 h2,\nhave h5: b ≥ n, from h1 b h3,\nhave h6: b > n, from lt_of_le_of_ne h5 (ne.symm h4),\nshow b ≥ n + 1, from h6\n\nlemma lbi1 (s : set ℕ) (n : ℕ) (h : lower_bound n s) : is_smallest n s ∨ lower_bound (n+1) s :=\nhave h1: n ∈ s ∨ n ∉ s, from em(n ∈ s),\nor.elim h1\n  (assume h2: n ∈ s,\n   have h3: is_smallest n s, from and.intro h2 h,\n   or.inl h3)\n  (assume h3: n ∉ s,\n   have h4: lower_bound (n+1) s, from lbih s n h h3,\n   or.inr h4)\n\nlemma lbiz (s : set ℕ) : lower_bound 0 s :=\nassume b : ℕ,\nassume h: b ∈ s,\nshow b ≥ 0, from bot_le\n\nlemma lbi2 (s : set ℕ) (n : ℕ) : lower_bound n s ∨ ∃ a, is_smallest a s :=\nnat.rec_on n\n(or.inl (lbiz s))\n(assume n,\n assume h1: lower_bound n s ∨ ∃ a, is_smallest a s,\n or.elim h1\n (assume h2: lower_bound n s,\n  have h3: is_smallest n s ∨ lower_bound (n+1) s, from lbi1 s n h2,\n  or.elim h3\n    (assume h4: is_smallest n s,\n     have h5: ∃ a, is_smallest a s, from exists.intro n h4,\n     or.inr h5)\n    (assume h6: lower_bound (n+1) s,\n     or.inl h6)\n  )\n (assume ha: ∃ a, is_smallest a s,\n  or.inr ha)\n)\n\nlemma nlb (s : set ℕ) (n : ℕ) (h1: n ∈ s) (h2: lower_bound (n+1) s) : false := \nhave h3: n + 1 ≤ n, from h2 n h1,\nhave h4: n + 1 > n, from lt_add_one n,\nshow false, from nat.lt_le_antisymm h4 h3\n\ntheorem well_ordered (s : set ℕ) (h1: s.nonempty) : ∃ a, is_smallest a s :=\nexists.elim h1\n (assume n,\n  assume h2: n ∈ s,\n  have h3: lower_bound (n+1) s ∨ ∃ a, is_smallest a s, from lbi2 s (n+1),\n  or.elim h3\n    (assume h4: lower_bound (n+1) s,\n     have h5: false, from nlb s n h2 h4,\n     false.rec (∃ a, is_smallest a s) h5)\n    (assume h6: ∃ a, is_smallest a s, show ∃ a, is_smallest a s, from h6))\n\ntheorem one_divides (n : ℕ) : divides 1 n :=\nhave h: 1 * n = n, from one_mul n,\nexists.intro n h\n\ntheorem divides_zero (n : ℕ) : divides n 0 :=\nhave h: n * 0 = 0, from rfl,\nexists.intro 0 h\n\ntheorem divides_nonzero (a b : ℕ) (h1: ¬ divides a b) : b ≠ 0 :=\nhave h2: b = 0 ∨ b ≠ 0, from (em(b = 0)),\nor.elim h2\n  (assume h3: b = 0,\n   have h4: divides a 0, from divides_zero a,\n   have h5: divides a b, from eq.subst (eq.symm h3) h4,\n   show b ≠ 0, from absurd h5 h1)\n  (assume h6: b ≠ 0, show b ≠ 0, from h6)\n\ndef divisors (n : ℕ) := { d : ℕ | divides d n }\n\ntheorem divisors_nonempty (n : ℕ) : (divisors n).nonempty :=\nhave 1 ∈ (divisors n), from one_divides n,\nshow (divisors n).nonempty, from set.nonempty_of_mem this\n\nlemma rdivisor_nonzero (a b c : ℕ) (h1 : c > 0) (h2 : a * b = c) : b > 0 :=\nhave h3: b = 0 ∨ b > 0, from nat.eq_zero_or_pos b,\nor.elim h3\n  (assume h4: b = 0,\n   have h5: a * 0 = 0, from rfl,\n   have h6: a * b = 0, from eq.subst (eq.symm h4) h5,\n   have h7: c = 0, from eq.subst h2 h6,\n   have h8: ¬ (0 > 0), from irrefl 0,\n   have h9: ¬ (c > 0), from eq.subst (eq.symm h7) h8,\n   absurd h1 h9)\n  (assume h10: b > 0,\n   h10)\n\ntheorem divisors_nonzero (a b c : ℕ) (h1 : c > 0) (h2 : a * b = c) : a > 0 ∧ b > 0 :=\nhave h3: b > 0, from rdivisor_nonzero a b c h1 h2,\nhave h4: b * a = c, from eq.subst (mul_comm a b) h2,\nhave h5: a > 0, from rdivisor_nonzero b a c h1 h4,\nand.intro h5 h3\n\ntheorem prime_divisors (d p : ℕ) (h1: is_prime p) (h2: divides d p) : d = 1 ∨ d = p :=\nhave h3: (d = 1 ∨ d = p) ∨ ¬ (d = 1 ∨ d = p), from em(d = 1 ∨ d = p),\nor.elim h3\n (assume h4: d = 1 ∨ d = p,\n  h4)\n (assume h5: ¬ (d = 1 ∨ d = p),\n  have h6: ¬ (d = 1) ∧ ¬ (d = p), from or_imp_distrib.mp h5,\n  have h7: d ≠ 1, from h6.left,\n  have h8: d ≠ p, from h6.right,\n  have h9: p > 1, from h1.left,\n  exists.elim h2\n   (assume c,\n    assume h10: d * c = p,\n    have h11: p > 0, from nat.lt_of_succ_lt h9,\n    have h12: d > 0 ∧ c > 0, from divisors_nonzero d c p h11 h10,\n    have h13: d > 0, from h12.left,\n    have h14: d > 1, from lt_of_le_of_ne h13 (ne.symm h7),\n    have h15: c > 0, from h12.right,\n    have h16: c = 1 ∨ c ≠ 1, from em(c = 1),\n    or.elim h16\n     (assume h17: c = 1,\n      have h18: d * 1 = p, from eq.subst h17 h10,\n      have h19: d = p, from eq.subst (mul_one d) h18,\n      absurd h19 h8)\n     (assume h20: c ≠ 1,\n      have h21: c > 1, from lt_of_le_of_ne h15 (ne.symm h20),\n      have h22: d > 1 ∧ c > 1 ∧ d * c = p, from and.intro h14 (and.intro h21 h10),\n      have h23: is_composite p, from exists.intro d (exists.intro c h22),\n      absurd h23 h1.right)))\n\ntheorem divisors_bounded (n : ℕ) (h : n > 0) : upper_bound n (divisors n) :=\nassume a,\nassume h1: a ∈ divisors n,\nhave h2: divides a n, from h1,\nhave h3: 0 < n, from h,\nhave h4: ∃ c, a * c = n, from h1,\nexists.elim h4\n  (assume b,\n   assume h5: a * b = n,\n   have h6: b > 0, from rdivisor_nonzero a b n h h5,\n   have h7: a ≤ a * b, from nat.le_mul_of_pos_right h6,\n   show a ≤ n, from eq.subst h5 h7)\n\ndef flip_set (s : set ℕ) (n : ℕ) := { a : ℕ | a ≤ n ∧ n - a ∈ s }\n\nlemma df1 (s : set ℕ) (n : ℕ) : flip_set (flip_set s n) n ⊆ s :=\nassume a,\nassume h1: a ∈ flip_set (flip_set s n) n,\nhave h2: a ≤ n, from h1.left,\nhave h3: n - a ∈ flip_set s n, from h1.right,\nhave h4: n - (n - a) ∈ s, from h3.right,\nhave h5: n - (n - a) = a, from nat.sub_sub_self h2,\nshow a ∈ s, from eq.subst h5 h4\n\nlemma df2 (s : set ℕ) (n : ℕ) (h1 : upper_bound n s) : s ⊆ flip_set (flip_set s n) n :=\nassume a,\nassume h2: a ∈ s,\nhave h3: n - a ≤ n, from nat.sub_le n a,\nhave h4: a ≤ n, from h1 a h2,\nhave h5: n - (n - a) = a, from nat.sub_sub_self h4,\nhave h6: n - (n - a) ∈ s, from eq.subst (eq.symm h5) h2,\nhave h7: n - a ∈ flip_set s n, from and.intro h3 h6,\nshow a ∈ flip_set (flip_set s n) n, from and.intro h4 h7\n\ndef double_flip (s : set ℕ) (n : ℕ) (h1: upper_bound n s) : flip_set (flip_set s n) n = s :=\nset.subset.antisymm (df1 s n) (df2 s n h1)\n\nlemma lb_flips (s : set ℕ) (a n : ℕ) (h1: lower_bound a s) :\nupper_bound (n - a) (flip_set s n) :=\n(assume b,\n assume h2: b ∈ (flip_set s n),\n have h3: n - b ∈ s, from h2.right,\n have h4: a ≤ n - b, from h1 (n-b) h3,\n have h5: b ≤ n, from h2.left,\n have h6: a + b ≤ n, from (nat.add_le_to_le_sub a h5).mpr h4,\n show n - a ≥ b, from nat.le_sub_left_of_add_le h6)\n\nlemma smallest_flips (s : set ℕ) (a n : ℕ) (h1: upper_bound n s) (h2: is_smallest a s) :\nis_largest (n-a) (flip_set s n) :=\nhave h3: a ∈ s, from h2.left,\nhave h4: n ≥ a, from h1 a h3,\nhave h5: n - (n - a) = a, from nat.sub_sub_self h4,\nhave h6: n - (n - a) ∈ s, from set.mem_of_eq_of_mem h5 h3,\nhave h7: n - a ≤ n, from nat.sub_le n a,\nhave h8: n - a ∈ (flip_set s n), from and.intro h7 h6,\nhave h9: upper_bound (n - a) (flip_set s n), from lb_flips s a n h2.right,\nand.intro h8 h9\n\nlemma nonempty_flips (s : set ℕ) (n : ℕ) (h1: upper_bound n s) (h2: s.nonempty) :\n(flip_set s n).nonempty :=\nexists.elim h2\n(assume a,\n assume h3: a ∈ s,\n have h4: a ≤ n, from h1 a h3,\n have h5: n - (n - a) = a, from nat.sub_sub_self h4,\n have h6: n - a ≤ n, from nat.sub_le n a,\n have h7: n - (n - a) ∈ s, from eq.subst (eq.symm h5) h3,\n have h6: n - a ∈ flip_set s n, from set.mem_sep h6 h7,\n show (flip_set s n).nonempty, from set.nonempty_of_mem h6)\n\ntheorem bounded_has_largest (s : set ℕ) (n : ℕ) (h1: upper_bound n s) (h2: s.nonempty) :\n∃ a, is_largest a s :=\nhave h3: (flip_set s n).nonempty, from nonempty_flips s n h1 h2,\nhave h4: ∃ x, is_smallest x (flip_set s n), from well_ordered (flip_set s n) h3,\nexists.elim h4\n(assume b,\n assume h5: is_smallest b (flip_set s n),\n have h6: upper_bound n (flip_set s n), from lb_flips s 0 n (lbiz s),\n have h7: is_largest (n-b) (flip_set (flip_set s n) n),\n   from (smallest_flips (flip_set s n) b n h6 h5),\n have h8: flip_set (flip_set s n) n = s, from double_flip s n h1,\n have h9: is_largest (n-b) s, from eq.subst h8 h7,\n show ∃ a, is_largest a s, from exists.intro (n-b) h9)\n\ndef common_divisors (a b : ℕ) := (divisors a) ∩ (divisors b)\n\ndef is_gcd (d a b : ℕ) := is_largest d (common_divisors a b)\n\ndef relatively_prime (a b : ℕ) := is_gcd 1 a b\n\ntheorem division (a m : ℕ) (h1: m > 0) : ∃ c : ℕ, ∃ d : ℕ, m * c + d = a ∧ d < m :=\nnat.rec_on a\n(have h2: m * 0 + 0 = 0, from rfl,\n have h3: m * 0 + 0 = 0 ∧ 0 < m, from and.intro h2 h1,\n have h4: ∃ d : ℕ, m * 0 + d = 0 ∧ d < m, from exists.intro 0 h3,\n show ∃ c : ℕ, ∃ d : ℕ, m * c + d = 0 ∧ d < m, from exists.intro 0 h4)\n(assume n,\n assume h5: ∃ c : ℕ, ∃ d : ℕ, m * c + d = n ∧ d < m,\n exists.elim h5\n (assume c,\n  assume h6: ∃ d : ℕ, m * c + d = n ∧ d < m,\n  exists.elim h6\n  (assume d,\n   assume h7: m * c + d = n ∧ d < m,\n   have h8: d + 1 = m ∨ d + 1 ≠ m, from em(d + 1 = m),\n   have h9: m * c + d = n, from h7.left,\n   have h10: m * c + d + 1 = n + 1, from congr_fun (congr_arg has_add.add h9) 1,\n   or.elim h8\n   (assume h11: d + 1 = m,\n    have h12: m * (c + 1) + 0 = n + 1, from (congr_arg (has_add.add (m * c)) (eq.symm h11)).trans h10,\n    have h13: ∃ f : ℕ, m * (c + 1) + f = n + 1 ∧ f < m, from exists.intro 0 (and.intro h12 h1),\n    show ∃ e : ℕ, ∃ f : ℕ, m * e + f = n + 1 ∧ f < m, from exists.intro (c+1) h13)\n   (assume h14: d + 1 ≠ m,\n    have h15: d < m, from h7.right,\n    have h16: d + 1 < m, from lt_of_le_of_ne h15 h14,\n    have h17: ∃ f : ℕ, m * c + f = n + 1 ∧ f < m, from exists.intro (d+1) (and.intro h10 h16),\n    show ∃ e : ℕ, ∃ f : ℕ, m * e + f = n + 1 ∧ f < m, from exists.intro c h17)\n)))\n\ntheorem divides_self (n : ℕ) : divides n n :=\nhave h1: n * 1 = n, from mul_one n,\nexists.intro 1 h1\n\ntheorem divides_add (d a b : ℕ) (h1: divides d a) (h2: divides d b) : divides d (a + b) :=\nexists.elim h1\n (assume e,\n  assume h3: d * e = a,\n  exists.elim h2\n   (assume f,\n    assume h4: d * f = b, \n    have h5: d * (e + f) = d * e + d * f, from mul_add d e f,\n    have h6: d * (e + f) = a + d * f, from eq.subst h3 h5,\n    have h7: d * (e + f) = a + b, from eq.subst h4 h6,\n    show divides d (a + b), from exists.intro (e + f) h7))\n\ntheorem divides_sub (d a b : ℕ) (h1: divides d a) (h2: divides d b) : divides d (a - b) :=\nexists.elim h1\n (assume e,\n  assume h3: d * e = a,\n  exists.elim h2\n   (assume f,\n    assume h4: d * f = b, \n    have h5: d * (e - f) = d * e - d * f, from nat.mul_sub_left_distrib d e f,\n    have h6: d * (e - f) = a - d * f, from eq.subst h3 h5,\n    have h7: d * (e - f) = a - b, from eq.subst h4 h6,\n    show divides d (a - b), from exists.intro (e - f) h7))\n\ntheorem divides_mul (d a b : ℕ) (h1: divides d a) : divides d (a * b) :=\nexists.elim h1\n (assume c,\n  assume h2: d * c = a,\n  have h3: d * c * b = a * b, from congr_fun (congr_arg has_mul.mul h2) b,\n  have h4: d * (c * b) = a * b, from eq.subst (mul_assoc d c b) h3,\n  exists.intro (c*b) h4)\n\ntheorem divides_trans (a b c : ℕ) (h1: divides a b) (h2: divides b c) : divides a c :=\nexists.elim h2\n (assume e,\n  assume h3: b * e = c,\n  have h4: divides a (b * e), from divides_mul a b e h1,\n  show divides a c, from eq.subst h3 h4)\n\ntheorem divides_le (a b : ℕ) (h1: divides a b) (h2: b > 0) : a ≤ b :=\nexists.elim h1\n (assume c,\n  assume h3: a * c = b,\n  have h4: c = 0 ∨ c ≠ 0, from em(c = 0),\n  or.elim h4\n   (assume h5: c = 0,\n    have h6: a * 0 = 0, from rfl,\n    have h7: a * c = 0, from eq.subst h5.symm h6,\n    have h8: b = 0, from eq.subst h3 h7,\n    have h9: b ≠ 0, from ne_of_gt h2,\n    absurd h8 h9)\n   (assume h10: c ≠ 0,\n    have h11: 0 < c, from bot_lt_iff_ne_bot.mpr h10,\n    have h12: a ≤ a * c, from nat.le_mul_of_pos_right h11,\n    eq.subst h3 h12))\n\ndef eset (p b : ℕ) (h: is_prime p) := { x : ℕ | x > 0 ∧ divides p (x*b) }\n\ntheorem eset_nonempty (p b : ℕ) (h1: is_prime p) : (eset p b h1).nonempty :=\nhave h2: p > 0, from prime_pos p h1,\nhave h3: divides p (p*b), from exists.intro b rfl,\nhave h4: p ∈ (eset p b h1), from and.intro h2 h3,\nshow (eset p b h1).nonempty, from set.nonempty_of_mem h4\n\nlemma ehelp (a b p x0 x : ℕ) (h1: is_prime p) (h2: is_smallest x0 (eset p b h1)) (h3: x ∈ eset p b h1) :\ndivides x0 x :=\nhave h4: x0 > 0, from h2.left.left,\nhave h5: ∃ q : ℕ, ∃ r : ℕ, x0 * q + r = x ∧ r < x0, from division x x0 h4,\nexists.elim h5\n (assume q,\n  assume h6: ∃ r : ℕ, x0 * q + r = x ∧ r < x0,\n  exists.elim h6\n   (assume r,\n    assume h7: x0 * q + r = x ∧ r < x0,\n    have h8: x - x0 * q = r, from nat.sub_eq_of_eq_add (eq.symm h7.left),\n    have h9: (x - x0 * q) * b = r * b, from congr_fun (congr_arg has_mul.mul h8) b,\n    have h10: x * b - x0 * q * b = r * b, from eq.subst (nat.mul_sub_right_distrib x (x0*q) b) h9,\n    have h11: divides p (x * b), from h3.right,\n    have h12: divides p (x0 * b), from h2.left.right,\n    have h13: divides p (x0 * b * q), from divides_mul p (x0 * b) q h12,\n    have h14: divides p (x0 * (b * q)), from eq.subst (mul_assoc x0 b q) h13,\n    have h15: divides p (x0 * (q * b)), from eq.subst (mul_comm b q) h14,\n    have h16: divides p (x0 * q * b), from eq.subst (eq.symm (mul_assoc x0 q b)) h15,\n    have h17: divides p (x * b - x0 * q * b), from divides_sub p (x * b) (x0 * q * b) h11 h16,\n    have h18: divides p (r * b), from eq.subst h10 h17,\n    have h19: r = 0 ∨ r ≠ 0, from em(r=0),\n    or.elim h19\n     (assume h20: r = 0,\n      have h21: x0 * q + 0 = x, from eq.subst h20 h7.left,\n      have h22: x0 * q = x, from h21,\n      show divides x0 x, from exists.intro q h22)\n     (assume h23: r ≠ 0,\n      have h24: r > 0, from bot_lt_iff_ne_bot.mpr h23,\n      have h25: r ∈ eset p b h1, from and.intro h24 h18,\n      have h26: r < x0, from h7.right,\n      have h27: lower_bound x0 (eset p b h1), from h2.right,\n      have h28: x0 ≤ r, from h27 r h25,\n      have h29: ¬ (r < x0), from not_lt.mpr h28,\n      show divides x0 x, from absurd h26 h29)))\n\ntheorem euclids_lemma (p a b : ℕ) (h1 : is_prime p) (h2 : divides p (a * b))\n: divides p a ∨ divides p b :=\nhave h3: divides p a ∨ ¬ divides p a, from em(divides p a),\nor.elim h3\n (assume h4: divides p a, or.inl h4)\n (assume h5: ¬ divides p a,\n  have h6: (eset p b h1).nonempty, from eset_nonempty p b h1,\n  have h7: ∃ x0, is_smallest x0 (eset p b h1), from well_ordered (eset p b h1) h6,\n  exists.elim h7\n   (assume x0,\n    assume h8: is_smallest x0 (eset p b h1),\n    have h9: divides p (p * b), from exists.intro b rfl,\n    have h10: p ∈ eset p b h1, from and.intro (prime_pos p h1) h9,\n    have h11: a ≠ 0, from divides_nonzero p a h5,\n    have h12: a > 0, from bot_lt_iff_ne_bot.mpr h11,\n    have h13: a ∈ eset p b h1, from and.intro h12 h2,\n    have h14: divides x0 p, from ehelp a b p x0 p h1 h8 h10,\n    have h15: divides x0 a, from ehelp a b p x0 a h1 h8 h13,\n    have h16: x0 = 1 ∨ x0 = p, from prime_divisors x0 p h1 h14,\n    or.elim h16\n     (assume h17: x0 = 1,\n      have h18: divides p (x0 * b), from h8.left.right,\n      have h19: 1 * b = b, from one_mul b,\n      have h20: x0 * b = b, from eq.subst (eq.symm h17) h19,\n      have h21: divides p b, from eq.subst h20 h18,\n      or.inr h21)\n     (assume h22: x0 = p,\n      have h23: divides p a, from eq.subst h22 h15,\n      absurd h23 h5)))\n\ndef g1_divisors (n : ℕ) := { d : ℕ | d > 1 ∧ divides d n }\n\ntheorem smallest_g1_divisor_prime (p n : ℕ) (h1: is_smallest p (g1_divisors n)) : is_prime p :=\nhave h2: is_composite p ∨ ¬ is_composite p, from em(is_composite p),\nhave h3: p > 1, from h1.left.left,\nor.elim h2\n (assume h3: is_composite p,\n  exists.elim h3\n   (assume b,\n    assume h4: ∃ c, b > 1 ∧ c > 1 ∧ b * c = p,\n    exists.elim h4\n     (assume c,\n      assume h5: b > 1 ∧ c > 1 ∧ b * c = p,\n      have h6: divides b p, from exists.intro c h5.right.right,\n      have h7: divides b n, from divides_trans b p n h6 h1.left.right,\n      have h8: b ∈ g1_divisors n, from and.intro h5.left h7,\n      have h9: b < p, from composite_divisor_lt b c p h5.right.right h5.left h5.right.left,\n      have h10: p ≤ b, from h1.right b h8,\n      have h11: ¬ (b < p), from not_lt.mpr h10,\n      absurd h9 h11)))\n (assume hz: ¬ is_composite p, and.intro h3 hz)\n\ntheorem g1_divisors_nonempty (n : ℕ) (h1: n > 1) : (g1_divisors n).nonempty :=\nhave h2: divides n n, from divides_self n,\nhave h3: n ∈ g1_divisors n, from and.intro h1 h2,\nset.nonempty_of_mem h3\n\ntheorem has_prime_divisor (n : ℕ) (h1: n > 1) : ∃ p, is_prime p ∧ divides p n :=\nhave h2: ∃ p, is_smallest p (g1_divisors n),\n    from well_ordered (g1_divisors n) (g1_divisors_nonempty n h1),\nexists.elim h2\n (assume p,\n  assume h2: is_smallest p (g1_divisors n),\n  have h3: is_prime p, from smallest_g1_divisor_prime p n h2,\n  have h4: divides p n, from h2.left.right,\n  exists.intro p (and.intro h3 h4))\n\ndef codivisors (a b : ℕ) := {d : ℕ | divides d a ∧ divides d b}\n\ntheorem codivisors_comm (a b: ℕ) : codivisors a b = codivisors b a :=\nhave h1: codivisors a b = divisors a ∩ divisors b, from rfl,\nhave h2: divisors a ∩ divisors b = divisors b ∩ divisors a,\n    from set.inter_comm (divisors a) (divisors b),\nhave h3: codivisors b a = divisors b ∩ divisors a, from rfl,\nby rw [h1, h2, h3.symm]\n\ndef coprime (a b : ℕ) := upper_bound 1 (codivisors a b)\n\ntheorem coprime_comm (a b: ℕ) (h1: coprime a b) : coprime b a :=\nhave h2: upper_bound 1 (codivisors a b), from h1,\nhave h3: upper_bound 1 (codivisors b a), from eq.subst (codivisors_comm a b) h2,\nh3\n\nlemma not_coprime (x y : ℕ) (h1: ¬ coprime x y) : ∃ z, z > 1 ∧ divides z x ∧ divides z y :=\nhave h2: ∃ b : ℕ, ¬ (b ∈ codivisors x y → 1 ≥ b), from classical.not_forall.mp h1,\nexists.elim h2\n (assume b,\n  assume h4: ¬ (b ∈ codivisors x y → 1 ≥ b),\n  have h5: b ∈ codivisors x y ∧ ¬ (1 ≥ b), from classical.not_imp.mp h4,\n  have h6: divides b x ∧ divides b y, from h5.left,\n  have h7: ¬ (1 ≥ b), from h5.right,\n  have h8: b > 1, from not_le.mp h7,\n  have h9: b > 1 ∧ divides b x ∧ divides b y, from and.intro h8 h6,\n  exists.intro b h9)\n\nlemma div_not_coprime (p a b: ℕ) (h1: is_prime p) (h2: divides p a) (h3: divides p b) :\n¬ coprime a b :=\nhave h4: p > 1, from h1.left,\nhave h5: p ∈ codivisors a b, from set.mem_sep h2 h3,\nhave h6: coprime a b ∨ ¬ coprime a b, from em(coprime a b),\nor.elim h6\n (assume h7: coprime a b,\n  have h8: 1 ≥ p, from h7 p h5,\n  have h9: ¬ (p > 1), from not_lt.mpr h8,\n  absurd h4 h9)\n (assume: ¬ coprime a b, this)\n\ntheorem single_cofactor (a b : ℕ) (h1: a > 0) (h2: b > 0) :\ncoprime a b ∨ ∃ p, is_prime p ∧ divides p a ∧ divides p b :=\nhave h3: coprime a b ∨ ¬ coprime a b, from em(coprime a b),\nor.elim h3\n (assume h4: coprime a b,\n  or.inl h4)\n (assume h5: ¬ coprime a b,\n  have h6: ∃ d : ℕ, d > 1 ∧ divides d a ∧ divides d b, from not_coprime a b h5,\n  exists.elim h6\n   (assume d,\n    assume h7: d > 1 ∧ divides d a ∧ divides d b,\n    have h8: ∃ p, is_prime p ∧ divides p d, from has_prime_divisor d h7.left,\n    exists.elim h8\n     (assume p,\n      assume h9: is_prime p ∧ divides p d,\n      have h10: divides p a, from divides_trans p d a h9.right h7.right.left,\n      have h11: divides p b, from divides_trans p d b h9.right h7.right.right,\n      or.inr (exists.intro p (and.intro h9.left (and.intro h10 h11))))))\n\ntheorem coprime_mult (a b c: ℕ) (h1: a > 0) (h2: b > 0) (h3: c > 0)\n(h4: coprime a b) (h5: coprime a c) :\ncoprime a (b*c) :=\nhave h6: b*c > 0, from mul_pos h2 h3,\nhave h7: coprime a (b*c) ∨ ∃ p, is_prime p ∧ divides p a ∧ divides p (b*c),\n    from single_cofactor a (b*c) h1 h6,\nor.elim h7\n (assume: coprime a (b*c), this)\n (assume h8: ∃ p, is_prime p ∧ divides p a ∧ divides p (b*c),\n  exists.elim h8\n   (assume p,\n    assume h9: is_prime p ∧ divides p a ∧ divides p (b*c),\n    have h10: divides p b ∨ divides p c, from euclids_lemma p b c h9.left h9.right.right,\n    or.elim h10\n     (assume h11: divides p b,\n      have h12: ¬ coprime a b, from div_not_coprime p a b h9.left h9.right.left h11,\n      absurd h4 h12)\n     (assume h13: divides p c,\n      have h14: ¬ coprime a c, from div_not_coprime p a c h9.left h9.right.left h13,\n      absurd h5 h14)))\n\ntheorem coprime_nonzero (a b: ℕ) (h1: a > 1) (h2: coprime a b) : b > 0 :=\nhave h3: b = 0 ∨ b ≠ 0, from em(b = 0),\nor.elim h3\n (assume h4: b = 0, \n  have h5: divides a 0, from divides_zero a,\n  have h6: divides a b, from eq.subst h4.symm h5,\n  have h7: divides a a, from divides_self a,\n  have h8: a ∈ codivisors a b, from set.mem_sep h7 h6,\n  have h9: 1 ≥ a, from h2 a h8,\n  have h10: ¬ (a > 1), from not_lt.mpr h9,\n  absurd h1 h10)\n (assume h11: b ≠ 0,\n  bot_lt_iff_ne_bot.mpr h11)\n\ndef linear_combo (a b : ℕ) := { e : ℕ | ∃ c : ℕ, ∃ d : ℕ, a * c = b * d + e }\n\ntheorem lc_left (a b : ℕ) : a ∈ linear_combo a b :=\nhave h1: a * 1 = b * 0 + a, from rfl,\nexists.intro 1 (exists.intro 0 h1)\n\ntheorem lc_right (a b : ℕ) (h1: a > 0) : b ∈ linear_combo a b :=\nhave h2: b*(a-1) + b = b * (a-1) + b, from rfl,\nhave h3: b*(a-1) = b*a - b, from nat.mul_pred_right b (nat.sub a 0),\nhave h4: b*a - b + b = b * (a-1) + b, from eq.subst h3 h2,\nhave h5: b ≤ b*a, from nat.le_mul_of_pos_right h1,\nhave h6: b*a - b + b = b*a + b - b, from nat.sub_add_eq_add_sub h5,\nhave h7: b*a + b - b = b*a, from (b*a).add_sub_cancel b,\nhave h8: a * b = b * a, from mul_comm a b,\nhave h9: a * b = b * (a-1) + b, by rw [h8, h7.symm, h6.symm, h4],\nexists.intro b (exists.intro (a-1) h9)\n\ntheorem lc_zero (a b : ℕ) : 0 ∈ linear_combo a b :=\nhave h1: a * 0 = b * 0 + 0, from rfl,\nexists.intro 0 (exists.intro 0 h1)\n\ntheorem lc_mul (a b x y : ℕ) (h1: x ∈ linear_combo a b) : x * y ∈ linear_combo a b :=\nexists.elim h1\n (assume c, assume : ∃ d, a * c = b * d + x,\n  exists.elim this\n   (assume d,\n    assume h2: a * c = b * d + x,\n    have h3: (b*d+x)*y = b*d*y + x*y, from add_mul (b*d) x y,\n    have h4: a*c*y = b*d*y + x*y, from eq.subst h2.symm h3,\n    have h5: a*(c*y) = b*d*y + x*y, from eq.subst (mul_assoc a c y) h4,\n    have h6: a*(c*y) = b*(d*y) + x*y, from eq.subst (mul_assoc b d y) h5,\n    exists.intro (c*y) (exists.intro (d*y) h6)))\n\nlemma sub_to_zero (a b : ℕ) (h1: a > b) : b - a = 0 :=\nhave h2: b ≤ a, from le_of_lt h1,\nhave h3: b - a ≤ a - a, from nat.sub_le_sub_right h2 a,\nhave h4: a - a = 0, from nat.sub_self a,\nhave h5: b - a ≤ 0, from eq.subst h4 h3,\neq_bot_iff.mpr h5\n\nlemma lc_minus_bx (a b e x : ℕ) (h1: e ∈ linear_combo a b) :\n(e - b*x) ∈ linear_combo a b :=\nexists.elim h1\n (assume c, assume : ∃ d, a * c = b * d + e,\n  exists.elim this\n   (assume d,\n    assume h2: a * c = b * d + e,\n    have h3: b*x + e - b*x = e, from nat.sub_eq_of_eq_add rfl,\n    have h4: a * c = b * d + (b*x + e - b*x), from eq.subst h3.symm h2,\n    have h5: b*x > e ∨ ¬ (b*x > e), from em(b*x > e),\n    or.elim h5\n     (assume h6: b*x > e,\n      have h7: e - b*x = 0, from sub_to_zero (b*x) e h6,\n      eq.subst h7.symm (lc_zero a b))\n     (assume h8: ¬ (b*x > e),\n      have h9: b*x ≤ e, from not_lt.mp h8,\n      have h10: b*x + e - b*x = b*x + (e - b*x), from nat.add_sub_assoc h9 (b*x),\n      have h11: a * c = b * d + (b*x + (e-b*x)), from eq.subst h10 h4,\n      have h12: a * c = (b * d + b * x) + (e-b*x), by rw [h11, add_assoc],\n      have h13: b * d + b * x = b * (d + x), from (mul_add b d x).symm,\n      have h14: a * c = b * (d + x) + (e-b*x), from eq.subst h13 h12,\n      exists.intro c (exists.intro (d + x) h14))))\n\nlemma lc_minus_ax (a b e x : ℕ) (h1: e ∈ linear_combo a b) : e - a*x ∈ linear_combo a b :=\nexists.elim h1\n (assume c, assume : ∃ d : ℕ, a * c = b * d + e,\n  exists.elim this\n   (assume d,\n    assume h4: a * c = b * d + e,\n    have h5: a * (c - x) = a * c - a * x, from nat.mul_sub_left_distrib a c x,\n    have h6: a * (c - x) = (b * d + e) - a*x, from eq.subst h4 h5,\n    have h7: a*x > e ∨ ¬ (a*x > e), from em(a*x > e),\n    or.elim h7\n     (assume h8: a*x > e,\n      have h9: e - a*x = 0, from sub_to_zero (a*x) e h8,\n      eq.subst h9.symm (lc_zero a b))\n     (assume h10: ¬ (a * x > e),\n      have h11: a*x ≤ e, from not_lt.mp h10,\n      have h12: (b * d + e) - a*x = b*d + (e - a*x), from nat.add_sub_assoc h11 (b*d),\n      have h13: a * (c - x) = b*d + (e - a*x), from eq.subst h12 h6,\n      exists.intro (c-x) (exists.intro d h13))))\n\ntheorem lc_add (a b c d : ℕ) (h1: c ∈ linear_combo a b) (h2: d ∈ linear_combo a b) :\n(c + d) ∈ linear_combo a b :=\nexists.elim h1\n (assume e, assume : ∃ f : ℕ, a * e = b * f + c, \n  exists.elim this\n   (assume f,\n    assume h3: a * e = b * f + c,\n    exists.elim h2\n     (assume g, assume : ∃ h : ℕ, a * g = b * h + d,\n      exists.elim this\n       (assume h,\n        assume h4: a * g = b * h + d,\n        have h5: a * e + a * g = a * e + a * g, from rfl,\n        have h6: a * e + a * g = b * f + c + a * g, from eq.subst h3 h5,\n        have h7: a*e + a*g = b*f + c + (b*h + d), from eq.subst h4 h6,\n        have h8: a*(e+g) = b*f + c + (b*h + d), from eq.subst (mul_add a e g).symm h7,\n        have h9: b*f + c + (b*h + d) = (b*f + b*h) + (c+d),\n            from add_add_add_comm (b*f) c (b*h) d,\n        have h10: a*(e+g) = (b*f + b*h) + (c+d), from eq.subst h9 h8,\n        have h11: a*(e+g) = b*(f+h) + (c+d), from eq.subst (mul_add b f h).symm h10,\n        exists.intro (e+g) (exists.intro (f+h) h11)))))\n\nlemma lc_comm_subset (a b : ℕ) (h1: b > 0) : linear_combo a b ⊆ linear_combo b a :=\nassume e,\nassume h2: e ∈ linear_combo a b,\nexists.elim h2\n (assume c, assume : ∃ d, a*c = b*d + e,\n  exists.elim this\n   (assume d,\n    assume h3: a*c = b*d + e,\n    have h4: e = a*c - b*d, from (nat.sub_eq_of_eq_add h3).symm,\n    have h5: a ∈ linear_combo b a, from lc_right b a h1,\n    have h6: a*c ∈ linear_combo b a, from lc_mul b a a c h5,\n    have h7: a*c - b*d ∈ linear_combo b a, from lc_minus_ax b a (a*c) d h6,\n    eq.subst h4.symm h7))\n\ntheorem lc_comm (a b : ℕ) (h1: a > 0) (h2: b > 0) : linear_combo a b = linear_combo b a :=\nset.eq_of_subset_of_subset\n (lc_comm_subset a b h2)\n (lc_comm_subset b a h1)\n\ntheorem lc_a_minus (a b e : ℕ) (ha: a > 0) (hb: b > 0) (h1: e ∈ linear_combo a b) :\na - e ∈ linear_combo a b :=\nexists.elim h1\n (assume c, assume : ∃ d, a*c = b*d + e,\n  exists.elim this\n   (assume d,\n    assume h2: a*c = b*d + e,\n    have h3: a*c - e = a*c - e, from rfl,\n    have h4: b*d + e - e = a*c - e, from eq.subst h2 h3,\n    have h5: b*d + e - e = b*d, from (b*d).add_sub_cancel e,\n    have h6: b*d = a*c - e, from eq.subst h5 h4,\n    have h7: a*(c-1) = a*c - a*1, from nat.mul_sub_left_distrib a c 1,\n    have h8: a*(c-1) = a*c - a, by rw [h7, mul_one],\n    have h9: a*(c-1) + a = a*c - a + a, from congr (congr_arg has_add.add h8) rfl,\n    have h10: c = 0 ∨ c ≠ 0, from em(c=0),\n    or.elim h10\n     (assume h11: c = 0,\n      have h12: a*0 = 0, from rfl,\n      have h13: a*c = 0, from eq.subst h11.symm h12,\n      have h14: 0 = b*d + e, from eq.subst h13 h2,\n      have h15: e ≤ b*d + e, from nat.le_add_left e (b*d),\n      have h16: e ≤ 0, from eq.subst h14.symm h15,\n      have h17: e = 0, from eq_bot_iff.mpr h16,\n      have h18: a - 0 = a, from rfl,\n      have h19: a - e = a, from eq.subst h17.symm h18,\n      eq.subst h19.symm (lc_left a b))\n     (assume h20: c ≠ 0,\n      have h21: c ≥ 1, from bot_lt_iff_ne_bot.mpr h20,\n      have h22: a*c ≥ a, from nat.le_mul_of_pos_right h21,\n      have h23: a*c - a + a = a*c, from nat.sub_add_cancel h22,\n      have h24: a*(c-1) + a = a*c, by rw [h9, h23],\n      have h25: b*d = a*(c-1) + a - e, from eq.subst h24.symm h6,\n      have h26: e > a ∨ ¬ (e > a), from em(e > a),\n      or.elim h26\n       (assume h27: e > a,\n        have h28: a - e = 0, from sub_to_zero e a h27,\n        eq.subst h28.symm (lc_zero a b))\n       (assume h29: ¬ e > a,\n        have h30: e ≤ a, from not_lt.mp h29,\n        have h31: a*(c-1) + a - e = a*(c-1) + (a-e), from nat.add_sub_assoc h30 (a*(c-1)),\n        have h32: b*d = a*(c-1) + (a-e), from eq.subst h31 h25,\n        have h33: (a-e) ∈ linear_combo b a, from exists.intro d (exists.intro (c-1) h32),\n        eq.subst (lc_comm b a hb ha) h33))))\n\ndef pos_linear_combo (a b : ℕ) := { e : ℕ | e > 0 ∧ e ∈ linear_combo a b }\n\nlemma plc_nonempty (a b : ℕ) (h1: a > 0) : (pos_linear_combo a b).nonempty :=\nhave h2: a ∈ linear_combo a b, from lc_left a b,\nhave h3: a ∈ pos_linear_combo a b, from and.intro h1 h2,\nset.nonempty_of_mem h3\n\nlemma plc_comm_subset (a b : ℕ) (h1: a > 0) (h2: b > 0) : pos_linear_combo a b ⊆ pos_linear_combo b a :=\nassume e,\nassume h3: e ∈ pos_linear_combo a b,\nhave h4: e ∈ linear_combo b a, from eq.subst (lc_comm a b h1 h2) h3.right,\nand.intro h3.left h4\n\ntheorem plc_comm (a b : ℕ) (h1: a > 0) (h2: b > 0) : pos_linear_combo a b = pos_linear_combo b a :=\nset.eq_of_subset_of_subset\n (plc_comm_subset a b h1 h2)\n (plc_comm_subset b a h2 h1)\n\nlemma bezdiv (a b s : ℕ) (h1: a > 0) (h2: b > 0) (h3: is_smallest s (pos_linear_combo a b)) : divides s a :=\nexists.elim (division a s h3.left.left)\n (assume q, assume : ∃ r : ℕ, s * q + r = a ∧ r < s,\n  exists.elim this\n   (assume r,\n    assume h6: s * q + r = a ∧ r < s,\n    have h7: r = 0 ∨ ¬ r = 0, from em(r=0),\n    or.elim h7\n     (assume h8: r = 0,\n      have h9: s * q + 0 = a, from eq.subst h8 h6.left,\n      have h10: s * q = a, from h9,\n      exists.intro q h10)\n     (assume h11: ¬ r = 0,\n      have h12: r > 0, from bot_lt_iff_ne_bot.mpr h11,\n      have h13: a - s*q = r, from nat.sub_eq_of_eq_add (h6.left.symm),\n      have h14: (s*q) ∈ linear_combo a b, from lc_mul a b s q h3.left.right,\n      have h15: (a - s*q) ∈ linear_combo a b, from lc_a_minus a b (s*q) h1 h2 h14,\n      have h16: r ∈ linear_combo a b, from eq.subst h13 h15,\n      have h17: r ∈ pos_linear_combo a b, from and.intro h12 h16,\n      have h18: s ≤ r, from h3.right r h17,\n      have h19: ¬ (r < s), from not_lt.mpr h18,\n      absurd h6.right h19)))\n\ntheorem bezout (a b : ℕ) (h1: a > 0) (h2: b > 0) (h3: coprime a b) : 1 ∈ linear_combo a b :=\nhave h4: (pos_linear_combo a b).nonempty, from plc_nonempty a b h1,\nhave h5: ∃ s, is_smallest s (pos_linear_combo a b), from well_ordered (pos_linear_combo a b) h4,\nexists.elim h5\n (assume s,\n  assume h6: is_smallest s (pos_linear_combo a b),\n  have h7: divides s a, from bezdiv a b s h1 h2 h6,\n  have h8: is_smallest s (pos_linear_combo b a), from eq.subst (plc_comm a b h1 h2) h6,\n  have h9: divides s b, from bezdiv b a s h2 h1 h8,\n  have h10: s ∈ codivisors a b, from and.intro h7 h9,\n  have h11: 1 ≥ s, from h3 s h10,\n  have h12: s > 0, from h6.left.left,\n  have h13: s = 1, from le_antisymm h11 h12,\n  eq.subst h13 h6.left.right)\n\ndef mod : ℕ → ℕ → ℕ\n| a m :=\n  if h1 : m ≥ 1 ∧ m ≤ a then\n    have a - m < a, from nat.sub_lt (le_trans h1.left h1.right) h1.left,\n    mod (a-m) m\n  else\n    a\n   \nlemma mdl (a m : ℕ) (h: m ≥ 1 ∧ m ≤ a) : mod a m = mod (a-m) m := by rw [mod, if_pos h]\n\nlemma mdr (a m : ℕ) (h: ¬ (m ≥ 1 ∧ m ≤ a)) : mod a m = a := by rw [mod, if_neg h]\n\ndef counterexamples_mod_less (m : ℕ) := { a : ℕ | mod a m ≥ m }\n\ntheorem mod_zero (a: ℕ) : mod a 0 = a :=\nhave h1: ¬ (0 ≥ 1 ∧ 0 ≤ a), from of_to_bool_ff rfl,\nmdr a 0 h1\n\ntheorem mod_less (a m : ℕ) (h1: m > 0) : mod a m < m :=\nhave h2: (mod a m < m) ∨ ¬ (mod a m < m), from em(mod a m < m),\nor.elim h2\n (assume : mod a m < m, this)\n (assume h3: ¬ (mod a m < m),\n  have h4: mod a m ≥ m, from not_lt.mp h3,\n  have h5: (counterexamples_mod_less m).nonempty, from set.nonempty_of_mem h4,\n  have h6: ∃ s, is_smallest s (counterexamples_mod_less m),\n      from well_ordered (counterexamples_mod_less m) h5,\n  exists.elim h6\n   (assume s,\n    assume h7: is_smallest s (counterexamples_mod_less m),\n    have h8: m ≤ s ∨ ¬ (m ≤ s), from em(m ≤ s),\n    or.elim h8\n     (assume h9: m ≤ s,\n      have h10: m ≥ 1 ∧ m ≤ s, from and.intro h1 h9,\n      have h11: mod s m = mod (s-m) m, from mdl s m h10,\n      have h12: mod (s-m) m ≥ m, from eq.subst h11 h7.left,\n      have h13: s - m ≥ s, from h7.right (s-m) h12,\n      have h14: s - m < s, from nat.sub_lt_of_pos_le m s h1 h9,\n      have h15: ¬ (s - m < s), from not_lt.mpr h13,\n      absurd h14 h15)\n     (assume h16: ¬ (m ≤ s),\n      have h17: ¬ (m ≥ 1 ∧ m ≤ s), from not_and_of_not_right (m ≥ 1) h16,\n      have h18: mod s m = s, from mdr s m h17,\n      have h19: ¬ (mod s m ≥ m), from eq.subst h18.symm h16,\n      absurd h7.left h19)))\n\ntheorem mod_cyclic (a m : ℕ) : mod (a + m) m = mod a m :=\nhave h1: m = 0 ∨ m ≠ 0, from em(m=0),\nor.elim h1\n (assume h2: m = 0,\n  have h3: a + 0 = a, from rfl,\n  have h4: a + m = a, from eq.subst h2.symm h3,\n  show mod (a+m) m = mod a m, by rw [h4])\n (assume h5: m ≠ 0,\n  have h6: m ≥ 1, from bot_lt_iff_ne_bot.mpr h5,\n  have h7: m ≤ a + m, from nat.le_add_left m a,\n  have h8: mod (a+m) m = mod (a+m-m) m, from mdl (a+m) m (and.intro h6 h7),\n  have h9: a+m-m = a, from nat.add_sub_cancel a m,\n  show mod (a+m) m = mod a m, by rw [h8, h9])\n\ntheorem mod_rem (a m r : ℕ) : mod (a*m + r) m = mod r m :=\nnat.rec_on a\n (show mod (0*m + r) m = mod r m, by rw [zero_mul, zero_add])\n (assume a,\n  assume h1: mod (a*m + r) m = mod r m,\n  have h2: mod ((a+1)*m + r) m = mod (a*m + r + m) m,\n      by rw [add_mul, one_mul, add_assoc, (add_comm m r), add_assoc],\n  have h3: mod (a*m + r + m) m = mod (a*m + r) m, from mod_cyclic (a*m+r) m,\n  have h4: mod (a*m + r + m) m = mod r m, from eq.subst h1 h3,\n  eq.subst h4 h2)\n\ntheorem mod_base (a m : ℕ) (h1: a < m) : mod a m = a :=\nhave h2: ¬ (m ≤ a), from not_le.mpr h1,\nhave h3: ¬ (m ≥ 1 ∧ m ≤ a), from not_and_of_not_right (m ≥ 1) h2,\nmdr a m h3\n\ntheorem zero_mod (m: ℕ) : mod 0 m = 0 :=\nhave h1: m = 0 ∨ m ≠ 0, from em(m = 0),\nor.elim h1\n (assume h2: m = 0,\n  have h3: mod 0 0 = 0, from mod_zero 0,\n  show mod 0 m = 0, from eq.subst h2.symm h3)\n (assume h4: m ≠ 0,\n  have h5: 0 < m, from bot_lt_iff_ne_bot.mpr h4,\n  mod_base 0 m h5)\n\nlemma mod_div_pos (a m: ℕ) (h1: m > 0) : ∃ q, m*q + mod a m = a :=\nhave h2: ∃ c, ∃ d, m*c + d = a ∧ d < m, from division a m h1,\nexists.elim h2\n (assume c,\n  assume: ∃ d, m*c + d = a ∧ d < m, \n  exists.elim this\n   (assume d,\n    assume h3: m*c + d = a ∧ d < m,\n    have h4: c*m + d = a, from eq.subst (mul_comm m c) h3.left,\n    have h5: mod (c*m + d) m = mod d m, from mod_rem c m d,\n    have h6: mod a m = mod d m, from eq.subst h4 h5,\n    have h7: mod d m = d, from mod_base d m h3.right,\n    have h8: mod a m = d, by rw [h6, h7],\n    have h9: m*c + mod a m = a, from eq.subst h8.symm h3.left,\n    exists.intro c h9))\n\ntheorem mod_div (a m: ℕ) : ∃ q, m*q + mod a m = a :=\nhave h1: m = 0 ∨ m ≠ 0, from em(m = 0),\nor.elim h1\n (assume h2: m = 0,\n  have h3: mod a m = a, from eq.subst h2.symm (mod_zero a),\n  have h4: m*1 + a = a, from eq.subst h2.symm (mul_one a),\n  have h5: m*1 + mod a m = a, from eq.subst h3.symm h4,\n  exists.intro 1 h5)\n (assume h6: m ≠ 0,\n  have h7: m > 0, from bot_lt_iff_ne_bot.mpr h6,\n  mod_div_pos a m h7)\n\ntheorem zero_mod_divides (a m: ℕ) (h1: mod a m = 0) : divides m a :=\nhave h2: ∃ q, m*q + mod a m = a, from mod_div a m,\nexists.elim h2\n (assume q,\n  assume h3: m*q + mod a m = a,\n  have h4: m*q + 0 = a, from eq.subst h1 h3,\n  have h5: m*q = a, from h4,\n  exists.intro q h5)\n\ntheorem mod_nondivisor (a m: ℕ) (h1: ¬ divides m a) : mod a m > 0 :=\nhave h2: mod a m = 0 ∨ mod a m ≠ 0, from em(mod a m = 0),\nor.elim h2\n (assume h3: mod a m = 0,\n  have h4: divides m a, from zero_mod_divides a m h3,\n  absurd h4 h1)\n (assume: mod a m ≠ 0,\n  bot_lt_iff_ne_bot.mpr this)\n\ndef range (n : ℕ) := { x : ℕ | x < n }\n\ndef surj (s1 s2 : set ℕ) (f : ℕ → ℕ) := ∀ x2: ℕ, x2 ∈ s2 → ∃ x1: ℕ, x1 ∈ s1 ∧ f x1 = x2\n\ndef covers (s1 s2 : set ℕ) := ∃ f: ℕ → ℕ, surj s1 s2 f\n\ndef bijects (s1 s2 : set ℕ) := covers s1 s2 ∧ covers s2 s1\n\ndef has_size (s : set ℕ) (n : ℕ) := bijects (range n) s\n\ntheorem bijects_comm (s1 s2 : set ℕ) (h: bijects s1 s2) : bijects s2 s1 :=\nand.intro h.right h.left\n\ndef nat_id (n : ℕ) := n\n\ntheorem superset_covers (s1 s2 : set ℕ) (h1: s1 ⊇ s2) : covers s1 s2 :=\nhave h2: surj s1 s2 nat_id ∨ ¬ (surj s1 s2 nat_id), from em(surj s1 s2 nat_id),\nor.elim h2\n (assume: surj s1 s2 nat_id, exists.intro nat_id this)\n (assume h3: ¬ (surj s1 s2 nat_id),\n  have h4: ∃ x2 : ℕ, ¬ (x2 ∈ s2 → ∃ x1: ℕ, x1 ∈ s1 ∧ nat_id x1 = x2),\n      from classical.not_forall.mp h3,\n  exists.elim h4\n   (assume x2,\n    assume h5: ¬ (x2 ∈ s2 → ∃ x1: ℕ, x1 ∈ s1 ∧ nat_id x1 = x2),\n    have h6: x2 ∈ s2 ∧ ¬ (∃ x1: ℕ, x1 ∈ s1 ∧ nat_id x1 = x2), from classical.not_imp.mp h5,\n    have h7: nat_id x2 = x2, from rfl,\n    have h8: x2 ∈ s1, from set.mem_of_mem_of_subset h6.left h1,\n    have h9: ∃ x1: ℕ, x1 ∈ s1 ∧ nat_id x1 = x2, from exists.intro x2 (and.intro h8 h7),\n    absurd h9 h6.right))\n\ntheorem covers_rfl (s : set ℕ) : covers s s :=\nhave h1: s ⊆ s, from set.subset.refl s,\nsuperset_covers s s h1\n\ntheorem bijects_refl (s : set ℕ) : bijects s s :=\nhave h1: s ⊆ s, from set.subset.refl s,\nhave h2: covers s s, from superset_covers s s h1,\nand.intro h2 h2\n\nlemma rzse : range 0 ⊆ ∅ :=\nassume x,\nassume h1: x ∈ range 0,\nhave h2: x < 0, from h1,\nhave h3: ¬ (x < 0), from not_ltz x,\nshow x ∈ ∅, from absurd h2 h3\n\ntheorem range_zero : range 0 = ∅ := set.eq_empty_of_subset_empty rzse\n\ntheorem range_size (n: ℕ) : has_size (range n) n := bijects_refl (range n)\n\ntheorem range_subset (a b : ℕ) (h1: a ≤ b) : range a ⊆ range b :=\nassume x,\nassume h2: x ∈ range a,\nhave h3: x < b, from lt_of_lt_of_le h2 h1,\nshow x ∈ range b, from h3\n\ntheorem empty_size : has_size ∅ 0 := eq.subst range_zero (range_size 0)\n\ntheorem surj_trans (s1 s2 s3 : set ℕ) (f1 f2 : ℕ → ℕ)\n(h1: surj s1 s2 f1) (h2: surj s2 s3 f2) :\nsurj s1 s3 (f2 ∘ f1) :=\nassume x3,\nassume h3: x3 ∈ s3,\nhave h4: ∃ x2: ℕ, x2 ∈ s2 ∧ f2 x2 = x3, from h2 x3 h3,\nexists.elim h4\n (assume x2,\n  assume h5: x2 ∈ s2 ∧ f2 x2 = x3,\n  have h6: ∃ x1: ℕ, x1 ∈ s1 ∧ f1 x1 = x2, from h1 x2 h5.left,\n  exists.elim h6\n   (assume x1,\n    assume h7: x1 ∈ s1 ∧ f1 x1 = x2,\n    have h8: (f2 ∘ f1) x1 = x3, from eq.subst h5.right (congr_arg f2 h7.right),\n    exists.intro x1 (and.intro h7.left h8)))\n\ntheorem covers_trans (s1 s2 s3 : set ℕ) (h1: covers s1 s2) (h2: covers s2 s3) :\ncovers s1 s3 :=\nexists.elim h1\n (assume f1,\n  assume h3: surj s1 s2 f1,\n  exists.elim h2\n   (assume f2,\n    assume h4: surj s2 s3 f2,\n    have h5: surj s1 s3 (f2 ∘ f1), from surj_trans s1 s2 s3 f1 f2 h3 h4,\n    exists.intro (f2 ∘ f1) h5))\n\ntheorem bijects_trans (s1 s2 s3 : set ℕ) (h1: bijects s1 s2) (h2: bijects s2 s3) :\nbijects s1 s3 :=\nhave h3: covers s1 s3, from covers_trans s1 s2 s3 h1.left h2.left,\nhave h4: covers s3 s1, from covers_trans s3 s2 s1 h2.right h1.right,\nand.intro h3 h4\n\ndef single (n: ℕ) := {x | x = n}\n\ntheorem range_one : range 1 = single 0 :=\nset.eq_of_subset_of_subset\n (assume x,\n  assume h1: x ∈ range 1,\n  have h2: x ≤ 0, from nat.lt_succ_iff.mp h1,\n  have h3: x = 0, from eq_bot_iff.mpr h2,\n  show x ∈ single 0, from h3)\n (assume x,\n  assume h4: x ∈ single 0,\n  have h5: x < 1, from eq.subst (h4.symm) (lt_add_one 0),\n  show x ∈ range 1, from h5)\n\ntheorem single_covers (a b : ℕ) : covers (single a) (single b) :=\nhave h1: ∃ x1: ℕ, x1 ∈ single a ∧ (λ x: ℕ, b) a = b, from exists_eq_left.mpr rfl,\nhave h2: ∀ x2: ℕ, x2 ∈ single b → ∃ x1: ℕ, x1 ∈ single a ∧ (λ x: ℕ, b) a = x2, from\n (assume x2,\n  assume h3: x2 ∈ single b,\n  have h4: x2 = b, from h3,\n  eq.subst h4.symm h1),\nhave h5: surj (single a) (single b) (λ x: ℕ, b), from h2,\nexists.intro (λ x : ℕ, b) h5\n\ntheorem single_bijects (a b : ℕ) : bijects (single a) (single b) :=\nand.intro (single_covers a b) (single_covers b a)\n\ntheorem single_size (a: ℕ) : has_size (single a) 1 := \nhave h1: bijects (single 0) (single a), from single_bijects 0 a,\nhave h2: bijects (range 1) (single a), from eq.subst range_one.symm h1,\nh2\n\ntheorem bijects_size (s1 s2 : set ℕ) (h1: bijects s1 s2) (n: ℕ) (h2: has_size s1 n) :\nhas_size s2 n :=\nhave h3: bijects (range n) s1, from h2,\nhave h4: bijects (range n) s2, from bijects_trans (range n) s1 s2 h3 h1,\nh4\n\ntheorem surj_empty (s : set ℕ) (f : ℕ → ℕ) : surj s (∅: set ℕ) f :=\nassume x2: ℕ,\nassume h1: x2 ∈ (∅: set ℕ),\nhave h2: x2 ∉ (∅: set ℕ), from not_false,\nabsurd h1 h2\n\ntheorem covers_empty (s : set ℕ) : covers s (∅: set ℕ) :=\nhave h1: surj s (∅: set ℕ) nat_id, from surj_empty s nat_id,\nexists.intro nat_id h1\n\ntheorem surj_nonempty (s1 s2: set ℕ) (f: ℕ → ℕ) (h1: surj s1 s2 f) (h2: s2.nonempty) :\ns1.nonempty :=\nhave h3: ∃ x2: ℕ, x2 ∈ s2, from h2,\nexists.elim h3\n (assume x2,\n  assume h4: x2 ∈ s2,\n  have h5: ∃ x1: ℕ, x1 ∈ s1 ∧ f x1 = x2, from h1 x2 h4,\n  exists.elim h5\n   (assume x1,\n    assume h6: x1 ∈ s1 ∧ f x1 = x2,\n    set.nonempty_of_mem h6.left))\n\ntheorem empty_surj (s : set ℕ) (f : ℕ → ℕ) (h1: surj (∅: set ℕ) s f) : s = ∅ :=\nhave h2: s = ∅ ∨ s.nonempty, from set.eq_empty_or_nonempty s,\nor.elim h2\n (assume: s = ∅, this)\n (assume h3: s.nonempty,\n  have h4: (∅: set ℕ).nonempty, from surj_nonempty ∅ s f h1 h3,\n  absurd h4 exists_false)\n\ntheorem empty_covers (s : set ℕ) (h1: covers (∅: set ℕ) s) : s = ∅ :=\nexists.elim h1\n (assume f: ℕ → ℕ,\n  assume h2: surj (∅: set ℕ) s f,\n  empty_surj s f h2)\n\ntheorem size_zero_empty (s: set ℕ) (h1: has_size s 0) : s = ∅ :=\nhave h2: covers (range 0) s, from h1.left,\nhave h3: covers ∅ s, from eq.subst range_zero h2,\nempty_covers s h3\n\ntheorem covers_nonempty (s1 s2: set ℕ) (h1: covers s1 s2) (h2: s2.nonempty) :\ns1.nonempty :=\nexists.elim h1\n (assume f: ℕ → ℕ,\n  assume h3: surj s1 s2 f,\n  surj_nonempty s1 s2 f h3 h2)\n\ntheorem bijects_empty (s: set ℕ) (h1: bijects s ∅) : s = ∅ :=\nempty_covers s h1.right\n\ntheorem bijects_nonempty (s1 s2: set ℕ) (h1: bijects s1 s2) (h2: s2.nonempty) :\ns1.nonempty :=\ncovers_nonempty s1 s2 h1.left h2\n\ntheorem range_nonempty (n: ℕ) (h1: n > 0) : (range n).nonempty :=\nhave h2: 0 ∈ range n, from h1,\nset.nonempty_of_mem h2\n\ntheorem pos_size (n : ℕ) (s: set ℕ) (h1: n > 0) (h2: has_size s n) : s.nonempty :=\nhave h3: bijects s (range n), from bijects_comm (range n) s h2,\nhave h4: (range n).nonempty, from range_nonempty n h1,\nbijects_nonempty s (range n) h3 h4\n\ndef remove (s: set ℕ) (a: ℕ) := {x | x ∈ s ∧ x ≠ a}\n\nlemma remove_nmem (s: set ℕ) (a: ℕ) (h1: a ∉ s) : remove s a = s :=\nset.diff_singleton_eq_self h1\n\ntheorem remove_subset (s: set ℕ) (a: ℕ) : (remove s a) ⊆ s :=\nset.sep_subset s (λ x: ℕ, x ≠ a)\n\ntheorem remove_union (s1 s2: set ℕ) (x: ℕ) :\nremove (s1 ∪ s2) x = (remove s1 x) ∪ (remove s2 x) := set.union_diff_distrib\n\nlemma surj_dec (a: ℕ) (s1 s2: set ℕ) (f: ℕ → ℕ) (h2: surj s1 s2 f):\nsurj (remove s1 a) (remove s2 (f a)) f :=\nassume x2,\nassume h4: x2 ∈ (remove s2 (f a)),\nhave h5: x2 ∈ s2, from h4.left,\nhave h6: ∃ x1: ℕ, x1 ∈ s1 ∧ f x1 = x2, from h2 x2 h5,\nexists.elim h6\n (assume x1,\n  assume h7: x1 ∈ s1 ∧ f x1 = x2,\n  have h8: x2 ≠ f a, from h4.right,\n  have h9: f x1 ≠ f a, from eq.subst h7.right.symm h8, \n  have x1 = a ∨ x1 ≠ a, from em(x1 = a),\n  or.elim this\n   (assume h10: x1 = a,\n    have h11: f x1 = f a, from congr_arg f h10,\n    absurd h11 h9)\n   (assume h12: x1 ≠ a,\n    have h13: x1 ∈ (remove s1 a), from and.intro h7.left h12,\n    exists.intro x1 (and.intro h13 h7.right)))\n\ndef swap : ℕ → ℕ → ℕ → ℕ\n| a b c :=\nif a = c then b else (if b = c then a else c)\n\nlemma swapl (a b : ℕ) : swap a b a = b := if_pos rfl\n\nlemma swapr (a b : ℕ) : swap a b b = a :=\nhave h1: a = b ∨ a ≠ b, from em(a=b),\nor.elim h1\n (assume h2: a = b,\n  have h3: swap a a a = a, from swapl a a,\n  have h4: swap a b b = a, from eq.subst h2 h3,\n  h4)\n (assume h5: a ≠ b,\n  have h6: swap a b b = (if b = b then a else b), from if_neg h5,\n  have h7: (if b = b then a else b) = a, from if_pos rfl,\n  have h8: swap a b b = a, by rw [h6, h7],\n  h8)\n\nlemma swapne (a b c : ℕ) (h1: a ≠ c) (h2: b ≠ c) : swap a b c = c :=\nhave h3: swap a b c = (if b = c then a else c), from if_neg h1,\nhave h4: (if b = c then a else c) = c, from if_neg h2,\nby rw [h3, h4]\n\nlemma surj_swap (a b : ℕ) (s : set ℕ) (h2: b ∈ s) (h3: a ≠ b) :\nsurj (remove s a) (remove s b) (swap a b) :=\nassume x2,\nassume h4: x2 ∈ (remove s b),\nhave h5: x2 = a ∨ x2 ≠ a, from em(x2 = a),\nor.elim h5\n (assume h6: x2 = a,\n  have h7: b ∈ (remove s a), from set.mem_sep h2 h3.symm,\n  have h8: (swap a b) b = x2, from eq.subst h6.symm (swapr a b),\n  exists.intro b (and.intro h7 h8))\n (assume h9: x2 ≠ a,\n  have h10: x2 ∈ (remove s a), from and.intro h4.left h9,\n  have h11: x2 ≠ b, from h4.right,\n  have h12: (swap a b) x2 = x2, from swapne a b x2 h9.symm h11.symm,\n  exists.intro x2 (and.intro h10 h12))\n\nlemma covers_swap (a b : ℕ) (s : set ℕ) (h2: b ∈ s) :\ncovers (remove s a) (remove s b) :=\nhave h3: a = b ∨ a ≠ b, from em(a = b),\nor.elim h3\n (assume h4: a = b,\n  have h5: covers (remove s a) (remove s a), from covers_rfl (remove s a),\n  have h6: remove s b = remove s a, from congr_arg (remove s) h4.symm,\n  have h7: remove s b ⊆ remove s a, from (set.subset.antisymm_iff.mp h6).left,\n  superset_covers (remove s a) (remove s b) h7)\n (assume h8: a ≠ b,\n  exists.intro (swap a b) (surj_swap a b s h2 h8))\n\nlemma bijects_swap (a b : ℕ) (s : set ℕ) (h1: a ∈ s) (h2: b ∈ s):\nbijects (remove s a) (remove s b) :=\nand.intro (covers_swap a b s h2) (covers_swap b a s h1)\n\nlemma rrn (n: ℕ) : range n = remove (range (n+1)) n :=\nset.eq_of_subset_of_subset\n (assume x,\n  assume h1: x ∈ range n,\n  have h2: x < n + 1, from nat.lt.step h1,\n  have h3: x ≠ n, from ne_of_lt h1,\n  and.intro h2 h3)\n (assume x,\n  assume h4: x ∈ remove (range (n+1)) n,\n  have h5: x < n + 1, from h4.left,\n  have h6: x ≠ n, from h4.right,\n  array.push_back_idx h5 h6)\n\nlemma range_remove (a n : ℕ) (h1: a ∈ range (n+1)) :\nbijects (range n) (remove (range (n+1)) a) :=\nhave h2: n ∈ range (n+1), from lt_add_one n,\nhave h3: bijects (remove (range (n+1)) n) (remove (range (n+1)) a),\n    from bijects_swap n a (range (n+1)) h2 h1,\neq.subst (rrn n).symm h3\n\ndef overcovers (n: ℕ) := covers (range n) (range (n+1))\n\nlemma noc_zero : ¬ overcovers 0 :=\nhave h1: overcovers 0 ∨ ¬ overcovers 0, from em(overcovers 0),\nor.elim h1\n (assume h2: overcovers 0,\n  have h3: covers ∅ (range 1), from eq.subst range_zero h2,\n  have h4: (range 1) = ∅, from empty_covers (range 1) h3,\n  have h5: 1 > 0, from lt_add_one 0,\n  have h6: (range 1).nonempty, from range_nonempty 1 h5,\n  have h7: ¬ (range 1 = ∅), from set.nmem_singleton_empty.mpr h6,\n  absurd h4 h7)\n (assume: ¬ overcovers 0, this)\n\nlemma ocai (n: ℕ) (h1: overcovers (n+1)) : overcovers n :=\nexists.elim h1\n (assume f,\n  assume h2: ∀ x2: ℕ, x2 ∈ range ((n+1)+1) → ∃ x1: ℕ, x1 ∈ range (n+1) ∧ f x1 = x2,\n  have h3: n+1 ∈ range((n+1)+1), from lt_add_one (n+1),\n  have h4: ∃ x1: ℕ, x1 ∈ range (n+1) ∧ f x1 = (n+1), from h2 (n+1) h3,\n  exists.elim h4\n   (assume x1,\n    assume h5: x1 ∈ range (n+1) ∧ f x1 = (n+1),\n    have h6: surj (remove (range (n+1)) x1) (remove (range ((n+1)+1)) (f x1)) f,\n        from surj_dec x1 (range (n+1)) (range ((n+1)+1)) f h2,\n    have h7: range (n+1) = remove (range ((n+1)+1)) (f x1),\n        from eq.subst h5.right.symm (rrn (n+1)),\n    have h8: bijects (range n) (remove (range (n+1)) x1) , from range_remove x1 n h5.left,\n    have h9: covers (remove (range (n+1)) x1) (remove (range ((n+1)+1)) (f x1)),\n        from exists.intro f h6,\n    have h10: covers (range n) (remove (range ((n+1)+1)) (f x1)),\n        from covers_trans (range n) (remove (range (n+1)) x1)\n             (remove (range ((n+1)+1)) (f x1)) h8.left h9,\n    have h11: covers (range n) (range (n+1)), from eq.subst h7.symm h10,\n    h11))\n\nlemma noc_any (n: ℕ) : ¬ overcovers n :=\nnat.rec_on n\n (noc_zero)\n (assume n,\n  assume h1: ¬ overcovers n,\n  have h2: overcovers (n+1) ∨ ¬ overcovers (n+1), from em(overcovers (n+1)),\n  or.elim h2\n   (assume h3: overcovers (n+1),\n    have h4: overcovers n, from ocai n h3,\n    absurd h4 h1)\n   (assume: ¬ overcovers (n+1), this))\n\nlemma suhelp (s: set ℕ) (a b: ℕ) (h1: has_size s a) (h2: has_size s b) (h3: a > b) :\na = b :=\nhave h4: bijects (range a) s, from h1,\nhave h5: bijects (range b) s, from h2,\nhave h6: bijects s (range b), from bijects_comm (range b) s h5,\nhave h7: bijects (range a) (range b), from bijects_trans (range a) s (range b) h4 h6,\nhave h8: b+1 ≤ a, from h3,\nhave h9: range (b+1) ⊆ range a, from range_subset (b+1) a h8,\nhave h10: covers (range a) (range (b+1)), from superset_covers (range a) (range (b+1)) h9,\nhave h11: covers (range b) (range (b+1)),\n    from covers_trans (range b) (range a) (range (b+1)) h7.right h10,\nabsurd h11 (noc_any b)\n\ntheorem size_unique (s : set ℕ) (a b : ℕ) (h1: has_size s a) (h2: has_size s b) : a = b :=\nhave h3: a < b ∨ ¬ (a < b), from em(a < b),\nor.elim h3\n (assume h4: a < b,\n  have h6: b = a, from suhelp s b a h2 h1 h4,\n  h6.symm)\n (assume h7: ¬ (a < b),\n  have h8: a = b ∨ a > b, from eq_or_lt_of_not_lt h7,\n  or.elim h8\n   (assume: a = b, this)\n   (assume h9: a > b,\n    suhelp s a b h1 h2 h9))\n\ntheorem covers_remove (s1 s2: set ℕ) (x1 x2: ℕ) (h2: x2 ∈ s2) (h3: covers s1 s2) :\ncovers (remove s1 x1) (remove s2 x2) :=\nexists.elim h3\n (assume f,\n  assume h4: surj s1 s2 f,\n  have h5: surj (remove s1 x1) (remove s2 (f x1)) f, from surj_dec x1 s1 s2 f h4,\n  have h6: covers (remove s1 x1) (remove s2 (f x1)), from exists.intro f h5,\n  have h7: covers (remove s2 (f x1)) (remove s2 x2), from covers_swap (f x1) x2 s2 h2,\n  covers_trans (remove s1 x1) (remove s2 (f x1)) (remove s2 x2) h6 h7)\n\ntheorem bijects_remove (s1 s2: set ℕ) (x1 x2: ℕ) (h1: x1 ∈ s1) (h2: x2 ∈ s2)\n(h3: bijects s1 s2) :\nbijects (remove s1 x1) (remove s2 x2) :=\nand.intro (covers_remove s1 s2 x1 x2 h2 h3.left) (covers_remove s2 s1 x2 x1 h1 h3.right)\n\ntheorem remove_size (s: set ℕ) (a n: ℕ) (h1: has_size s (n+1)) (h2: a ∈ s) :\nhas_size (remove s a) n :=\nhave h3: bijects (range (n+1)) s, from h1,\nhave h4: n ∈ range (n+1), from lt_add_one n,\nhave h5: bijects (remove (range (n+1)) n) (remove s a),\n    from bijects_remove (range (n+1)) s n a h4 h2 h3,\nhave h6: bijects (range n) (remove s a), from eq.subst (rrn n).symm h5,\nh6\n\ndef patch : (ℕ → ℕ) → ℕ → ℕ → ℕ → ℕ\n| f a b x :=\nif x = a then b else (f x)\n\nlemma patchl (f: ℕ → ℕ) (a b : ℕ) : patch f a b a = b := if_pos rfl\nlemma patchr (f: ℕ → ℕ) (a b x : ℕ) (h1: x ≠ a) : patch f a b x = f x := if_neg h1\n\nlemma surj_insert (a: ℕ) (s1 s2: set ℕ) (f: ℕ → ℕ) (h1: a ∈ s1)\n(h2: surj (remove s1 a) (remove s2 (f a)) f) :\nsurj s1 s2 f :=\nassume x2,\nassume h3: x2 ∈ s2,\nhave h4: x2 = (f a) ∨ x2 ≠ (f a), from em(x2 = (f a)),\nor.elim h4\n (assume h5: x2 = (f a),\n  have h6: a ∈ s1 ∧ f a = x2, from and.intro h1 h5.symm,\n  exists.intro a h6)\n (assume h7: x2 ≠ (f a),\n  have h8: x2 ∈ remove s2 (f a), from set.mem_sep h3 h7,\n  have h9: ∃ x1: ℕ, x1 ∈ (remove s1 a) ∧ f x1 = x2, from h2 x2 h8,\n  exists.elim h9\n   (assume x1,\n    assume h10: x1 ∈ (remove s1 a) ∧ f x1 = x2,\n    have h11: x1 ∈ s1, from h10.left.left,\n    exists.intro x1 (and.intro h11 h10.right)))\n\nlemma surj_patch (a b: ℕ) (s1 s2: set ℕ) (f: ℕ → ℕ) (h1: a ∉ s1) (h2: surj s1 s2 f) :\nsurj s1 s2 (patch f a b) :=\nassume x2,\nassume h3: x2 ∈ s2,\nhave h4: ∃ x1: ℕ, x1 ∈ s1 ∧ f x1 = x2, from h2 x2 h3,\nexists.elim h4\n (assume x1,\n  assume h5: x1 ∈ s1 ∧ f x1 = x2,\n  have h6: x1 = a ∨ x1 ≠ a, from em(x1 = a),\n  or.elim h6\n   (assume h7: x1 = a,\n    have h8: x1 ∉ s1, from eq.subst h7.symm h1,\n    absurd h5.left h8)\n   (assume h9: x1 ≠ a,\n    have h10: (patch f a b) x1 = x2, from eq.subst h5.right (patchr f a b x1 h9),\n    exists.intro x1 (and.intro h5.left h10)))\n\ntheorem covers_insert (s1 s2: set ℕ) (x1 x2: ℕ) (h1: x1 ∈ s1)\n(h2: covers (remove s1 x1) (remove s2 x2)) :\ncovers s1 s2 :=\nexists.elim h2\n (assume f,\n  assume h3: surj (remove s1 x1) (remove s2 x2) f,\n  have h4: x1 ∉ (remove s1 x1), from not_and_not_right.mpr (congr_fun rfl),\n  have h5: surj (remove s1 x1) (remove s2 x2) (patch f x1 x2),\n      from surj_patch x1 x2 (remove s1 x1) (remove s2 x2) f h4 h3,\n  have h6: surj (remove s1 x1) (remove s2 ((patch f x1 x2) x1)) (patch f x1 x2),\n      from eq.subst (patchl f x1 x2).symm h5,\n  have h7: surj s1 s2 (patch f x1 x2), from surj_insert x1 s1 s2 (patch f x1 x2) h1 h6,\n  exists.intro (patch f x1 x2) h7)\n\ntheorem bijects_insert (s1 s2: set ℕ) (x1 x2: ℕ) (h1: x1 ∈ s1) (h2: x2 ∈ s2)\n(h3: bijects (remove s1 x1) (remove s2 x2)) :\nbijects s1 s2 :=\nand.intro (covers_insert s1 s2 x1 x2 h1 h3.left) (covers_insert s2 s1 x2 x1 h2 h3.right)\n\ntheorem insert_size (s: set ℕ) (a n: ℕ) (h1: a ∈ s) (h2: has_size (remove s a) n) :\nhas_size s (n+1) :=\nhave h3: bijects (range n) (remove s a), from h2,\nhave h4: n ∈ range (n+1), from lt_add_one n,\nhave h5: bijects (remove (range (n+1)) n) (remove s a), from eq.subst (rrn n) h3,\nbijects_insert (range (n+1)) s n a h4 h1 h5\n\ndef rcfn (n: ℕ) := ∀ s: set ℕ, covers (range n) s → ∃ a: ℕ, has_size s a\n\nlemma rcfz : rcfn 0 :=\nassume s,\nassume h1: covers (range 0) s,\nhave h2: covers ∅ s, from eq.subst range_zero h1,\nhave h3: s = ∅, from empty_covers s h2,\nhave h4: has_size s 0, from eq.subst h3.symm empty_size,\nexists.intro 0 h4\n\nlemma range_covers_finite (n: ℕ) : rcfn n :=\nnat.rec_on n\n (rcfz)\n (assume n,\n  assume h1: rcfn n,\n  assume s,\n  assume h2: covers (range (n+1)) s,\n  exists.elim h2\n   (assume f,\n    assume h3: surj (range (n+1)) s f,\n    have h5: surj (remove (range (n+1)) n) (remove s (f n)) f,\n        from surj_dec n (range (n+1)) s f h3,\n    have h6: surj (range n) (remove s (f n)) f, from eq.subst (rrn n).symm h5,\n    have h7: covers (range n) (remove s (f n)), from exists.intro f h6,\n    have h8: ∃ a: ℕ, has_size (remove s (f n)) a, from h1 (remove s (f n)) h7,\n    exists.elim h8\n     (assume a,\n      assume h9: has_size (remove s (f n)) a,\n      have h10: (f n) ∈ s ∨ (f n) ∉ s, from em((f n) ∈ s),\n      or.elim h10\n       (assume h11: (f n) ∈ s,\n        have h12: has_size s (a+1), from insert_size s (f n) a h11 h9,\n        exists.intro (a+1) h12)\n       (assume h13: (f n) ∉ s,\n        have h14: (remove s (f n)) = s, from remove_nmem s (f n) h13,\n        have h15: has_size s a, from eq.subst h14 h9,\n        exists.intro a h15))))\n\n\ntheorem subset_finite (s1 s2: set ℕ) (n2: ℕ) (h1: s1 ⊆ s2) (h2: has_size s2 n2) :\n∃ n1: ℕ, has_size s1 n1 :=\nhave h3: covers (range n2) s2, from h2.left,\nhave h4: covers s2 s1, from superset_covers s2 s1 h1,\nhave h5: covers (range n2) s1, from covers_trans (range n2) s2 s1 h3 h4,\nrange_covers_finite n2 s1 h5\n\ndef ssn (n1: ℕ) := ∀ s1: set ℕ, ∀ s2: set ℕ, ∀ n2: ℕ,\nhas_size s1 n1 ∧ has_size s2 n2 ∧ s1 ∩ s2 = ∅ → has_size (s1 ∪ s2) (n1 + n2)\n\nlemma ssnz : ssn 0 :=\nassume s1,\nassume s2,\nassume n2,\nassume h1: has_size s1 0 ∧ has_size s2 n2 ∧ s1 ∩ s2 = ∅,\nhave h2: s1 = ∅, from size_zero_empty s1 h1.left,\nhave h3: ∅ ∪ s2 = s2, from set.empty_union s2,\nhave h4: s1 ∪ s2 = s2, from eq.subst h2.symm h3,\nhave h5: 0 + n2 = n2, from mul_one n2,\nhave h6: has_size (s1 ∪ s2) n2, from eq.subst h4.symm h1.right.left,\neq.subst h5.symm h6\n\nlemma nmem_nonint (s1 s2: set ℕ) (x1: ℕ) (h1: x1 ∈ s1) (h2: s1 ∩ s2 = ∅) : x1 ∉ s2 :=\nhave h3: x1 ∈ s2 ∨ x1 ∉ s2, from em(x1 ∈ s2),\nor.elim h3\n (assume h4: x1 ∈ s2,\n  have h5: x1 ∈ s1 ∩ s2, from set.mem_sep h1 h4,\n  have h6: x1 ∉ ∅, from list.not_mem_nil x1,\n  have h7: x1 ∉ s1 ∩ s2, from eq.subst h2.symm h6,\n  absurd h5 h7)\n (assume: x1 ∉ s2, this)\n\nlemma ssni (n1: ℕ) (h1: ssn n1) : ssn (n1+1) :=\nassume s1,\nassume s2,\nassume n2,\nassume h2: has_size s1 (n1+1) ∧ has_size s2 n2 ∧ s1 ∩ s2 = ∅,\nhave h3: covers s1 (range (n1+1)), from h2.left.right,\nhave h4: n1+1 > 0, from nat.succ_pos n1,\nhave h5: (range (n1+1)).nonempty, from range_nonempty (n1+1) h4,\nhave h6: s1.nonempty, from covers_nonempty s1 (range (n1+1)) h3 h5,\nhave h7: ∃ x, x ∈ s1, from h6,\nexists.elim h7\n (assume x,\n  assume h8: x ∈ s1,\n  have h9: has_size (remove s1 x) n1, from remove_size s1 x n1 h2.left h8,\n  have h10: (remove s1 x) ⊆ s1, from remove_subset s1 x,\n  have h11: (remove s1 x) ∩ s2 ⊆ s1 ∩ s2, from set.inter_subset_inter_left s2 h10,\n  have h12: (remove s1 x) ∩ s2 ⊆ ∅, from eq.subst h2.right.right h11,\n  have h13: (remove s1 x) ∩ s2 = ∅, from set.subset_eq_empty h12 rfl,\n  have h14: has_size ((remove s1 x) ∪ s2) (n1 + n2),\n      from h1 (remove s1 x) s2 n2 (and.intro h9 (and.intro h2.right.left h13)),\n  have h15: remove (s1 ∪ s2) x = (remove s1 x) ∪ (remove s2 x), from remove_union s1 s2 x,\n  have h16: x ∉ s2, from nmem_nonint s1 s2 x h8 h2.right.right,\n  have h17: (remove s2 x) = s2, from remove_nmem s2 x h16,\n  have h18: remove (s1 ∪ s2) x = (remove s1 x) ∪ s2,\n      from eq.trans h15 (congr_arg (has_union.union (remove s1 x)) h17),\n  have h19: has_size (remove (s1 ∪ s2) x) (n1 + n2), from eq.subst h18.symm h14,\n  have h20: x ∈ s1 ∪ s2, from set.mem_union_left s2 h8,\n  have h21: has_size (s1 ∪ s2) (n1 + n2 + 1),\n      from insert_size (s1 ∪ s2) x (n1 + n2) h20 h19,\n  have h22: (n1+1) + n2 = (n1 + n2 + 1), from nat.succ_add n1 n2,\n  eq.subst h22.symm h21)\n\nlemma ssn_any (n: ℕ) : ssn n :=\nnat.rec_on n\n (ssnz)\n (assume n,\n  assume h1: ssn n,\n  ssni n h1)\n\ntheorem size_sum (s1 s2: set ℕ) (n1 n2: ℕ) (h1: has_size s1 n1) (h2: has_size s2 n2)\n(h3: s1 ∩ s2 = ∅) : has_size (s1 ∪ s2) (n1 + n2) :=\nssn_any n1 s1 s2 n2 (and.intro h1 (and.intro h2 h3))\n\ndef set_mod_mult (s: set ℕ) (a m: ℕ) := { c | ∃ b: ℕ, b ∈ s ∧ mod (a*b) m = c }\n\ndef prange (n: ℕ) := remove (range n) 0\n\ntheorem prange_pos (a b: ℕ) (h1: a ∈ prange b) : a > 0 :=\nhave h2: a ≠ 0, from h1.right,\nbot_lt_iff_ne_bot.mpr h2\n\ntheorem prange_coprime (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) : coprime x p :=\nhave h3: coprime x p ∨ ¬ coprime x p, from em(coprime x p),\nor.elim h3\n (assume: coprime x p, this)\n (assume: ¬ coprime x p, \n  have h4: ∃ y, y > 1 ∧ divides y x ∧ divides y p, from not_coprime x p this,\n  exists.elim h4\n   (assume y,\n    assume h5: y > 1 ∧ divides y x ∧ divides y p,\n    have h6: y = 1 ∨ y = p, from prime_divisors y p h1 h5.right.right,\n    have h7: y ≠ 1, from ne_of_gt h5.left,\n    have h8: y = p, from or.resolve_left h6 h7,\n    have h9: divides p x, from eq.subst h8 h5.right.left,\n    have h11: x > 0, from prange_pos x p h2,\n    have h12: p ≤ x, from divides_le p x h9 h11,\n    have h13: x < p, from h2.left,\n    have h14: ¬ (x < p), from not_lt.mpr h12,\n    absurd h13 h14))\n\ntheorem prange_nondivisor (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) : ¬ divides p x :=\nhave h3: coprime x p, from prange_coprime x p h1 h2,\nhave h4: divides p x ∨ ¬ divides p x, from em(divides p x),\nor.elim h4\n (assume h5: divides p x,\n  have h6: divides p p, from divides_self p,\n  have h7: ¬ coprime x p, from div_not_coprime p x p h1 h5 h6,\n  absurd h3 h7)\n (assume: ¬ divides p x, this)\n\ntheorem prange_closed (x y p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) (h3: y ∈ prange p) :\nmod (x*y) p ∈ prange p :=\nhave h4: coprime x p, from prange_coprime x p h1 h2,\nhave h5: coprime y p, from prange_coprime y p h1 h3,\nhave h6: x > 0, from prange_pos x p h2,\nhave h7: y > 0, from prange_pos y p h3,\nhave h8: p > 0, from prime_pos p h1,\nhave h9: coprime p (x*y), from coprime_mult p x y h8 h6 h7 (coprime_comm x p h4) (coprime_comm y p h5),\nhave h10: coprime (x*y) p, from coprime_comm p (x*y) h9,\nhave h11: divides p (x*y) ∨ ¬ divides p (x*y), from em(divides p (x*y)),\nor.elim h11\n (assume h12: divides p (x*y),\n  have h13: divides p x ∨ divides p y, from euclids_lemma p x y h1 h12,\n  or.elim h13\n   (assume: divides p x,\n    absurd this (prange_nondivisor x p h1 h2))\n   (assume: divides p y,\n    absurd this (prange_nondivisor y p h1 h3)))\n (assume h14: ¬ divides p (x*y),\n  have h15: mod (x*y) p > 0, from mod_nondivisor (x*y) p h14,\n  have h16: mod (x*y) p < p, from mod_less (x*y) p h8,\n  have h17: mod (x*y) p ≠ 0, from ne_of_gt h15,\n  and.intro h16 h17)\n\ntheorem mod_rmult (a b m: ℕ): mod (a * (mod b m)) m = mod (a*b) m :=\nhave h1: ∃ q, m*q + mod b m = b, from mod_div b m,\nexists.elim h1\n (assume q,\n  assume h2: m*q + mod b m = b,\n  have h3: mod (a*b) m = mod (a*(m*q + mod b m)) m, from eq.subst h2.symm rfl,\n  have h4: a*(m*q + mod b m) = (a*q)*m + a*(mod b m), by rw [mul_add, (mul_comm m q), mul_assoc],\n  have h5: mod ((a*q)*m + a*(mod b m)) m = mod (a*(mod b m)) m, from mod_rem (a*q) m (a*(mod b m)),\n  have h6: mod (a*b) m = mod (a*(mod b m)) m, by rw [h3, h4, h5],\n  h6.symm)\n\ntheorem mod_lmult (a b m: ℕ): mod ((mod a m) * b) m = mod (a*b) m :=\nby rw [(mul_comm (mod a m) b), mod_rmult, (mul_comm b a)]\n\ntheorem right_inv (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) :\n∃ y: ℕ, y ∈ prange p ∧ mod (x*y) p = 1 :=\nhave h3: coprime x p, from prange_coprime x p h1 h2,\nhave h4: x > 0, from prange_pos x p h2,\nhave h5: p > 0, from prime_pos p h1,\nhave h6: 1 ∈ linear_combo x p, from bezout x p h4 h5 h3,\nexists.elim h6\n (assume y,\n  assume: ∃ m:ℕ, x*y = p*m + 1,\n  exists.elim this\n   (assume m,\n    assume h7: x*y = p*m + 1,\n    have h8: mod (m*p + 1) p = mod 1 p, from mod_rem m p 1,\n    have h9: mod 1 p = 1, from mod_base 1 p h1.left,\n    have h10: mod (m*p + 1) p = 1, by rw [h8, h9],\n    have h11: m*p = p*m, from mul_comm m p,\n    have h12: x*y = m*p + 1, from eq.subst h11.symm h7,\n    have h13: mod (x*y) p = 1, from eq.subst h12.symm h10,\n    have h14: mod (x * (mod y p)) p = mod (x*y) p, from mod_rmult x y p,\n    have h15: mod (x * (mod y p)) p = 1, from eq.subst h14.symm h13,\n    have h16: mod y p = 0 ∨ mod y p ≠ 0, from em(mod y p = 0),\n    or.elim h16\n     (assume h17: mod y p = 0,\n      have h18: x * 0 = 0, from rfl,\n      have h19: x * mod y p = 0, from eq.subst h17.symm h18,\n      have h20: mod 0 p = 1, from eq.subst h19 h15,\n      have h21: mod 0 p = 0, from zero_mod p,\n      have h22: 0 = 1, by rw [h21.symm, h20],\n      absurd h22 zero_ne_one)\n     (assume h23: mod y p ≠ 0,\n      have h24: mod y p ∈ range p, from mod_less y p h5,\n      have h25: mod y p ∈ prange p, from and.intro h24 h23,\n      exists.intro (mod y p) (and.intro h25 h15))))\n\ntheorem left_inv (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) :\n∃ y: ℕ, y ∈ prange p ∧ mod (y*x) p = 1 :=\nexists.elim (right_inv x p h1 h2)\n (assume y,\n  assume h3: y ∈ prange p ∧ mod (x*y) p = 1,\n  have h4: x*y = y*x, from mul_comm x y,\n  exists.intro y (eq.subst h4 h3))\n\nlemma smm_eq_1 (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) :\nset_mod_mult (prange p) x p ⊆ prange p :=\nassume z,\nassume h3: z ∈ set_mod_mult (prange p) x p,\nexists.elim h3\n (assume y,\n  assume h4: y ∈ (prange p) ∧ mod (x*y) p = z,\n  have h5: mod (x*y) p ∈ prange p, from prange_closed x y p h1 h2 h4.left,\n  eq.subst h4.right h5)\n\nlemma smm_eq_2 (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) :\nprange p ⊆ set_mod_mult (prange p) x p :=\nassume y,\nassume h3: y ∈ prange p,\nhave h4: ∃ z: ℕ, z ∈ prange p ∧ mod (z*x) p = 1, from left_inv x p h1 h2,\nexists.elim h4\n (assume z,\n  assume h5: z ∈ prange p ∧ mod (z*x) p = 1,\n  have h6: mod ((mod (z*x) p) * y) p = mod ((z*x)*y) p, from mod_lmult (z*x) y p,\n  have h7: mod (1*y) p = mod ((z*x)*y) p, from eq.subst h5.right h6,\n  have h8: mod (1*y) p = mod y p, by rw [(one_mul y)],\n  have h9: mod y p = y, from mod_base y p h3.left,\n  have h10: mod ((z*x)*y) p = mod (x*(z*y)) p, by rw [(mul_comm z x), (mul_assoc x z y)],\n  have h11: mod (z*y) p ∈ prange p, from prange_closed z y p h1 h5.left h3,\n  have h12: mod (x * (mod (z*y) p)) p = mod (x*(z*y)) p, from mod_rmult x (z*y) p,\n  have h13: mod (x * (mod (z*y) p)) p = y, by rw [h12, h10.symm, h7.symm, h8, h9],\n  have h14: mod (z*y) p ∈ prange p ∧ mod (x * (mod (z*y) p)) p = y, from and.intro h11 h13,\n  exists.intro (mod (z*y) p) h14)\n\ntheorem smm_eq (x p: ℕ) (h1: is_prime p) (h2: x ∈ prange p) :\nset_mod_mult (prange p) x p = prange p :=\nset.subset.antisymm (smm_eq_1 x p h1 h2) (smm_eq_2 x p h1 h2)\n\n/- (fprod n f) is the product of f(x) from 1 to n -/\ndef fprod: ℕ → (ℕ → ℕ) → ℕ\n| 0 f := 1\n| (x+1) f := (f (x+1)) * (fprod x f)\n\nlemma pp_base (f: ℕ → ℕ) : fprod 0 f = 1 := rfl\n\ndef mulf: (ℕ → ℕ) → (ℕ → ℕ) → ℕ → ℕ\n| f g x := (f x) * (g x)\n\nlemma pp_comm_mult_zero (f g: ℕ → ℕ) :\n(fprod 0 f) * (fprod 0 g) = fprod 0 (mulf f g) :=\nhave h1: 1 * 1 = 1, from rfl,\nby rw [(pp_base f), (pp_base g), h1, (pp_base (mulf f g)).symm]\n\ntheorem pp_comm_mult (n: ℕ) (f g: ℕ → ℕ) :\n(fprod n f) * (fprod n g) = fprod n (mulf f g) :=\nnat.rec_on n\n (pp_comm_mult_zero f g)\n (assume y,\n  assume h1: (fprod y f) * (fprod y g) = fprod y (mulf f g),\n  have h2: fprod (y+1) (mulf f g) = (mulf f g (y+1)) * (fprod y (mulf f g)), from rfl,\n  have h3: mulf f g (y+1) = (f (y+1)) * (g (y+1)), from rfl,\n  have h4: fprod (y+1) (mulf f g) = ((f (y+1)) * (fprod y f)) * ((g (y+1)) * (fprod y g)),\n      by rw [h2, h1.symm, h3, mul_mul_mul_comm],\n  show (fprod (y+1) f) * (fprod (y+1) g) = fprod (y+1) (mulf f g), from h4.symm)\n\ndef modf: (ℕ → ℕ) → ℕ → ℕ → ℕ\n| f m x := mod (f x) m\n\nlemma pp_comm_mod_zero (m: ℕ) (f: ℕ → ℕ) : mod (fprod 0 (modf f m)) m = mod (fprod 0 f) m :=\nhave h1: fprod 0 (modf f m) = 1, from rfl,\nhave h2: fprod 0 f = 1, from rfl,\nby rw [h1, h2.symm]\n\ntheorem pp_comm_mod (m n: ℕ) (f: ℕ → ℕ) :\nmod (fprod n (modf f m)) m = mod (fprod n f) m :=\nnat.rec_on n\n (pp_comm_mod_zero m f)\n (assume x,\n  assume h1: mod (fprod x (modf f m)) m = mod (fprod x f) m,\n  have h2: fprod (x+1) (modf f m) = (modf f m (x+1)) * (fprod x (modf f m)), from rfl,\n  have h3: mod (fprod (x+1) (modf f m)) m = mod ((modf f m (x+1)) * mod (fprod x (modf f m)) m) m,\n      by rw [h2, mod_rmult],\n  have h4: modf f m (x+1) = mod (f (x+1)) m, from rfl,\n  have h5: mod (fprod (x+1) (modf f m)) m = mod ((f (x+1)) * (fprod x f)) m,\n      by rw [h3, h1, mod_rmult, h4, mod_lmult],\n  have h6: (f (x+1)) * (fprod x f) = fprod (x+1) f, from rfl,\n  show mod (fprod (x+1) (modf f m)) m = mod (fprod (x+1) f) m, from eq.subst h6 h5)\n\ndef constf: ℕ → ℕ → ℕ\n| a b := a\n\ndef exp: ℕ → ℕ → ℕ\n| a b := fprod b (constf a)\n\ndef prangemap: ℕ → (ℕ → ℕ) → (set ℕ)\n| n f := {b: ℕ | ∃ a: ℕ, a ∈ prange n ∧ f a = b}\n\ntheorem flt (a p: ℕ) (h1: is_prime p) (h2: a ∈ prange p) : mod (exp a (p-1)) p = 1 := sorry\n\n/-\n\nTODO: Fermat's Little Theorem.\n\nWe need to prove that (p-1)! is equal, no matter what order we multiply it in.\nMaybe we can do this with prangemaps - can we prove that if two functions have equal prangemaps,\ntheir fprods are the same?\n\nWe need to calculate (p-1)! two ways, before and after multiplying by a.\nThey're equal mod p, because it's the same set of numbers.\n\nI should also check out the community. If there's a future, it's in there somewhere.\n-/\n\n", "meta": {"author": "lacker", "repo": "kata", "sha": "43dd06d46a2b4284378eb376b09d9cadbba60096", "save_path": "github-repos/lean/lacker-kata", "path": "github-repos/lean/lacker-kata/kata-43dd06d46a2b4284378eb376b09d9cadbba60096/lean/src/tutorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7791408828403131}}
{"text": "/-\nExercises from https://leanprover.github.io/logic_and_proof\n\nChapter 12. Sets in Lean\n-/\n\nimport data.set\n\n-- 1\nsection\n  variable U : Type\n  variables A B C : set U\n\n  example : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=\n  assume x,\n  assume : x ∈ A ∩ C,\n  have x ∈ A, from this.left,\n  show x ∈ A ∪ B, from or.inl this\n\n  example : ∀ x, x ∈ -(A ∪ B) → x ∈ -A :=\n  assume x,\n  assume : x ∈ -(A ∪ B),\n  have np : x ∉ A ∪ B, from this,\n  assume : x ∈ A,\n  have p : x ∈ A ∪ B, from or.inl this,\n  absurd p np\nend\n\n-- 2\nsection\n\nopen set\n\nvariable {U : Type}\n\n/- defining \"disjoint\" -/\n\ndef disj (A B : set U) : Prop := ∀ ⦃x⦄, x ∈ A → x ∈ B → false\n\nexample (A B : set U) (h : ∀ x, ¬ (x ∈ A ∧ x ∈ B)) :\n  disj A B :=\nassume x,\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\nhave h3 : x ∈ A ∧ x ∈ B, from and.intro h1 h2,\nshow false, from h x h3\n\n-- notice that we do not have to mention x when applying\n--   h : disj A B\nexample (A B : set U) (h1 : disj A B) (x : U)\n    (h2 : x ∈ A) (h3 : x ∈ B) :\n  false :=\nh1 h2 h3\n\n-- the same is true of ⊆\nexample (A B : set U) (x : U) (h : A ⊆ B) (h1 : x ∈ A) :\n  x ∈ B :=\nh h1\n\nexample (A B C D : set U) (h1 : disj A B) (h2 : C ⊆ A)\n    (h3 : D ⊆ B) :\n  disj C D :=\nassume x,\nassume c : x ∈ C,\nhave a : x ∈ A, from h2 c,\nassume d : x ∈ D,\nhave b : x ∈ B, from h3 d,\nh1 a b\n\nend\n\n-- 3\nsection\n\nopen set\n\nvariables {I U : Type}\nvariables (A : I → set U) (B : I → set U) (C : set U)\n\nexample : (⋂ i, A i) ∩ (⋂ i, B i) ⊆ (⋂ i, A i ∩ B i) :=\nassume x,\nassume h : x ∈ (⋂ i, A i) ∩ (⋂ i, B i),\nshow x ∈ ⋂ i, A i ∩ B i, by simp * at *\n\nexample : C ∩ (⋃ i, A i) ⊆ ⋃i, C ∩ A i :=\nassume x,\nassume h : x ∈ C ∩ (⋃ i, A i),\nshow x ∈ ⋃ i, C ∩ A i, by simp * at *\n\nend\n\n-- 4\nsection\n\nopen set\n\nvariable  {U : Type}\nvariables A B C : set U\n\nexample (h1 : A ⊆ B) (h2 : B ⊆ C) : A ⊆ C := subset.trans h1 h2\nexample : A ⊆ A := subset.refl A\n\nexample (h : A ⊆ B) : powerset A ⊆ powerset B :=\nassume p,\nassume : p ∈ 𝒫 A,\nhave p ⊆ A, from this,\nhave p ⊆ B, from subset.trans this h,\nshow p ∈ 𝒫 B, from this\n\nexample (h : powerset A ⊆ powerset B) : A ⊆ B :=\nhave A ∈ 𝒫 A, from subset.refl A,\nhave A ∈ 𝒫 B, from (h this),\nshow A ⊆ B, from this\n\nend", "meta": {"author": "jamesdabbs", "repo": "proofs", "sha": "00baf355b08e7aec00de34208e1b2cb4a8d7b701", "save_path": "github-repos/lean/jamesdabbs-proofs", "path": "github-repos/lean/jamesdabbs-proofs/proofs-00baf355b08e7aec00de34208e1b2cb4a8d7b701/src/exercises/logic_and_proof/12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391386, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7791408743598728}}
{"text": "import algebra.group\n\n-- BEGIN\n\nvariables {G : Type*} [group G] \n\n#check one_mul \n#check mul_assoc\n#check mul_left_inv\n#check mul_right_cancel \n\nnamespace my_group\n\ntheorem mul_right_inv (a : G) : a * a⁻¹ = 1 :=\nbegin\n  have h : a * a⁻¹ * a = 1 * a,\n    { sorry, },\n  apply mul_right_cancel h,\nend\n\ntheorem mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\nbegin\n  have h : (a * b)⁻¹ * a * b = b⁻¹ * a⁻¹ * a * b,\n    { sorry, },\n  rw mul_assoc at h,\n  rw mul_assoc at h,\n  apply mul_right_cancel h,\nend \n\nend my_group\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/7_have/ex2_have_inv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7791121604292508}}
{"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\n! This file was ported from Lean 3 source module data.W.cardinal\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 Mathlib.Data.W.Basic\nimport Mathlib.SetTheory.Cardinal.Ordinal\n\n/-!\n# Cardinality of W-types\n\nThis file proves some theorems about the cardinality of W-types. The main result is\n`cardinal_mk_le_max_aleph0_of_finite` which says that if for any `a : α`,\n`β a` is finite, then the cardinality of `WType β` is at most the maximum of the\ncardinality of `α` and `ℵ₀`.\nThis can be used to prove theorems about the cardinality of algebraic constructions such as\npolynomials. There is a surjection from a `WType` to `MvPolynomial` for example, and\nthis surjection can be used to put an upper bound on the cardinality of `MvPolynomial`.\n\n## Tags\n\nW, W type, cardinal, first order\n-/\n\n\nuniverse u\n\nvariable {α : Type u} {β : α → Type u}\n\nnoncomputable section\n\nnamespace WType\n\nopen Cardinal\n\nopen Cardinal\n-- porting note: `W` is a special name, exceptionally in upper case in Lean3\nset_option linter.uppercaseLean3 false\n\ntheorem cardinal_mk_eq_sum : (#WType β) = sum (fun a : α => (#WType β) ^ (#β a)) := by\n  simp only [Cardinal.power_def, ← Cardinal.mk_sigma]\n  exact mk_congr (equivSigma β)\n#align W_type.cardinal_mk_eq_sum WType.cardinal_mk_eq_sum\n\n/-- `#(WType β)` is the least cardinal `κ` such that `Sum (λ a : α, κ ^ #(β a)) ≤ κ` -/\ntheorem cardinal_mk_le_of_le {κ : Cardinal.{u}} (hκ : (sum fun a : α => κ ^ (#β a)) ≤ κ) :\n    (#WType β) ≤ κ := by\n  induction' κ using Cardinal.inductionOn with γ\n  simp only [Cardinal.power_def, ← Cardinal.mk_sigma, Cardinal.le_def] at hκ\n  cases' hκ with hκ\n  exact Cardinal.mk_le_of_injective (elim_injective _ hκ.1 hκ.2)\n#align W_type.cardinal_mk_le_of_le WType.cardinal_mk_le_of_le\n\n/-- If, for any `a : α`, `β a` is finite, then the cardinality of `WType β`\n  is at most the maximum of the cardinality of `α` and `ℵ₀`  -/\ntheorem cardinal_mk_le_max_aleph0_of_finite [∀ a, Finite (β a)] : (#WType β) ≤ max (#α) ℵ₀ :=\n  (isEmpty_or_nonempty α).elim\n    (by\n      intro h\n      rw [Cardinal.mk_eq_zero (WType β)]\n      exact zero_le _)\n    fun hn =>\n    let m := max (#α) ℵ₀\n    cardinal_mk_le_of_le <|\n      calc\n        (Cardinal.sum fun a => m ^ (#β a)) ≤ (#α) * ⨆ a, m ^ (#β a) := Cardinal.sum_le_supᵢ _\n        _ ≤ m * ⨆ a, m ^ (#β a) := mul_le_mul' (le_max_left _ _) le_rfl\n        _ = m :=\n          mul_eq_left.{u} (le_max_right _ _)\n              (csupᵢ_le' fun i => pow_le (le_max_right _ _) (lt_aleph0_of_finite _)) <|\n            pos_iff_ne_zero.1 <|\n              Order.succ_le_iff.1\n                (by\n                  rw [succ_zero]\n                  obtain ⟨a⟩ : Nonempty α; exact hn\n                  refine' le_trans _ (le_csupᵢ (bddAbove_range.{u, u} _) a)\n                  rw [← power_zero]\n                  exact\n                    power_le_power_left\n                      (pos_iff_ne_zero.1 (aleph0_pos.trans_le (le_max_right _ _))) (zero_le _))\n\n#align W_type.cardinal_mk_le_max_aleph_0_of_finite WType.cardinal_mk_le_max_aleph0_of_finite\n\nend WType\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/W/Cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.8354835371034369, "lm_q1q2_score": 0.7790493839656739}}
{"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 : ℕ} : ↑n = 0 ↔ 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 : ℕ} : ↑n = 1 ↔ odd n := sorry\n\ntheorem ne_zero_iff_odd {n : ℕ} : ↑n ≠ 0 ↔ odd 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/data/zmod/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.778956240487582}}
{"text": "import Mathlib.Data.Nat.Basic\nimport Mathlib.Algebra.GroupPower.Basic\nimport Mathlib.Tactic.Linarith\n\n/-!\n# International Mathematical Olympiad 1964, Problem 1b\n\nProve that there is no positive integer n for which 2ⁿ + 1 is divisible by 7.\n-/\n\n/-\nInformal proof (credit to twitch.tv viewer int_fast64_t):\n  let 2^n = 2^{3k + j},j < 3\n  (i.e. write n as 3k + j)\n  =>\n    2^n mod 7 = (2^3 mod 7)^k * 2^j mod 7 = 1 mod 7 * 2^j mod 7,\n  but 2^j < 5\n-/\ntheorem imo_1964_q1b (n : ℕ) : ¬ 7 ∣ (2^n + 1) := by\n  intro h\n  replace h := Nat.mod_eq_zero_of_dvd h\n  rw[←Nat.div_add_mod n 3] at h\n\n  have h := calc\n     0 = (2 ^ (3 * (n / 3) + n % 3) + 1) % 7       := h.symm\n     _ = ((2 ^ 3) ^ (n / 3) * 2 ^ (n % 3) + 1) % 7 := by rw[pow_add, pow_mul]\n     _ = ((2 ^ 3 % 7) ^ (n / 3) % 7 * (2 ^ (n % 3) % 7) % 7 + 1 % 7) % 7 :=\n                   by rw[Nat.add_mod, Nat.mul_mod, Nat.pow_mod]\n     _ = (1 ^ (n / 3) % 7 * (2 ^ (n % 3) % 7) % 7 + 1 % 7) % 7 :=\n                   by rw[show (2 ^ 3) % 7 = 1 by rfl]\n     _ = (1 % 7 * (2 ^ (n % 3) % 7) % 7 + 1 % 7) % 7 := by rw[one_pow]\n     _ = (2 ^ (n % 3) % 7 + 1) % 7 :=\n                   by rw[show 1 % 7 = 1 by rfl, one_mul, Nat.mod_mod]\n\n  cases hn' : n % 3 with\n  | zero => rw[hn'] at h; norm_num at h\n  | succ n' =>\n    cases n' with\n    | zero => rw[hn'] at h; norm_num at h\n    | succ n' =>\n      cases n' with\n      | zero => rw[hn'] at h; norm_num at h\n      | succ n' => have h5 : 3 > 0 := by norm_num\n                   have h6 := Nat.mod_lt n h5\n                   rw[hn'] at h6\n                   linarith\n\n/- An alternative proof, heavily golfed. The statement here is slightly modified from the original one. -/\ntheorem imo_1964_q1b' : ∀ (n : ℕ), (2 ^ n + 1) % 7 ≠ 0\n    | 0 | 1 | 2 => by decide\n    | n + 3 => by\n      rw [pow_add, Nat.add_mod, Nat.mul_mod, show 2 ^ 3 % 7 = 1 from by rfl]\n      simp [imo_1964_q1b' n]\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/Imo1964Q1B.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723468, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7789482391805257}}
{"text": "open Nat\n\nnamespace Nat\n\ntheorem zeroSub (a : Nat) : 0 - a = 0 := by\n  match a with\n  | 0     => rfl\n  | a + 1 => simp[Nat.sub_succ, pred, zeroSub a]\n\ntheorem subAdd_assoc {a b c : Nat} : a - b - c = a - (b + c) := by\n  induction c with\n  | zero      => simp\n  | succ c ih => rw [add_succ, sub_succ a, ←ih, sub_succ]\n\n@[simp] theorem addSub {a b : Nat} : a + b - b = a := by\n  revert a\n  induction b with\n  | zero => intros; simp\n  | succ b h =>\n    intros a\n    rw [←@Nat.subAdd_assoc (a + succ b) b 1, Nat.add_succ, ←Nat.succ_add]\n    rw [h, Nat.sub_succ, Nat.sub_zero]\n    rfl\n\n@[simp] theorem succSubOne {a : Nat} : succ a - 1 = a := @addSub a 1\n\ntheorem leSuccSubOne {a : Nat} : a ≤ succ (a - 1) :=\n match a with\n | zero => rfl\n | succ a => by simp [Nat.leRefl]\n\ntheorem le_subAdd {a b : Nat} (h : b ≤ a) : a = a - b + b := by\n  rw [←(le.dest h).2, Nat.add_comm]; simp;\n\ntheorem lt_add_right_cancel {m n k : Nat} : m + k > n + k → m > n :=\n  match k with\n  | zero => fun h => h\n  | succ k => fun h => by\n    simp only [Nat.add_succ] at h\n    exact lt_add_right_cancel (Nat.lt_of_succ_lt_succ h)\n\ntheorem lt_add_left_cancel {m n k : Nat} : k + m > k + n → m > n := by\n  rw [Nat.add_comm, Nat.add_comm (m := n) (n := k)]; exact lt_add_right_cancel\n\ntheorem ltImpLt_of_leImpLe {a b c d : Nat} (h : a ≤ b → c ≤ d) (h' : d < c) : b < a :=\n  gtOfNotLe $ fun h'' => Nat.notLeOfGt h' (h h'')\n\n\ntheorem lt_sub_right_cancel {m n k : Nat} : m - k > n - k → m > n := by\n  refine ltImpLt_of_leImpLe ?_\n  induction k with\n  | zero => intro h; rw [Nat.sub_zero, Nat.sub_zero]; exact h\n  | succ k ih => intro h; rw [Nat.sub_succ, Nat.sub_succ]; apply predLePred; exact ih h\n\ntheorem zeroLtIffSub {a b : Nat} : b < a ↔ a - b > 0 := by\n  apply Iff.intro\n  case mp =>\n    intro h\n    apply lt_add_right_cancel (k := b)\n    rw [←le_subAdd (Nat.leOfLt h)]\n    simp [h]\n  case mpr =>\n    intro h\n    apply lt_sub_right_cancel (k := b)\n    rw [Nat.sub_self]\n    exact h\n\ntheorem neSuccSelf (a : Nat) : a ≠ succ a := by\n  induction a with\n  | zero => simp\n  | succ a ih =>\n    intro heq\n    apply ih\n    apply Nat.add_right_cancel (m := 1)\n    exact heq\n\nend Nat\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/Eulerian/Nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.778948231932742}}
{"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.definitions\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\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\nnamespace polynomial\n\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 ≠ 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = ⊤`. -/\ndef trailing_degree {R : Type u} [semiring R] (p : polynomial R) : with_top ℕ :=\n  finset.inf (finsupp.support p) some\n\ntheorem trailing_degree_lt_wf {R : Type u} [semiring R] :\n    well_founded fun (p q : polynomial R) => trailing_degree p < trailing_degree q :=\n  inv_image.wf trailing_degree (with_top.well_founded_lt nat.lt_wf)\n\n/-- `nat_trailing_degree p` forces `trailing_degree p` to `ℕ`, by defining\n`nat_trailing_degree ⊤ = 0`. -/\ndef nat_trailing_degree {R : Type u} [semiring R] (p : polynomial R) : ℕ :=\n  option.get_or_else (trailing_degree p) 0\n\n/-- `trailing_coeff p` gives the coefficient of the smallest power of `X` in `p`-/\ndef trailing_coeff {R : Type u} [semiring R] (p : polynomial R) : R :=\n  coeff p (nat_trailing_degree p)\n\n/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/\ndef trailing_monic {R : Type u} [semiring R] (p : polynomial R) := trailing_coeff p = 1\n\ntheorem trailing_monic.def {R : Type u} [semiring R] {p : polynomial R} :\n    trailing_monic p ↔ trailing_coeff p = 1 :=\n  iff.rfl\n\nprotected instance trailing_monic.decidable {R : Type u} [semiring R] {p : polynomial R}\n    [DecidableEq R] : Decidable (trailing_monic p) :=\n  eq.mpr sorry (_inst_2 (trailing_coeff p) 1)\n\n@[simp] theorem trailing_monic.trailing_coeff {R : Type u} [semiring R] {p : polynomial R}\n    (hp : trailing_monic p) : trailing_coeff p = 1 :=\n  hp\n\n@[simp] theorem trailing_degree_zero {R : Type u} [semiring R] : trailing_degree 0 = ⊤ := rfl\n\n@[simp] theorem nat_trailing_degree_zero {R : Type u} [semiring R] : nat_trailing_degree 0 = 0 :=\n  rfl\n\ntheorem trailing_degree_eq_top {R : Type u} [semiring R] {p : polynomial R} :\n    trailing_degree p = ⊤ ↔ p = 0 :=\n  sorry\n\ntheorem trailing_degree_eq_nat_trailing_degree {R : Type u} [semiring R] {p : polynomial R}\n    (hp : p ≠ 0) : trailing_degree p = ↑(nat_trailing_degree p) :=\n  sorry\n\ntheorem trailing_degree_eq_iff_nat_trailing_degree_eq {R : Type u} [semiring R] {p : polynomial R}\n    {n : ℕ} (hp : p ≠ 0) : trailing_degree p = ↑n ↔ nat_trailing_degree p = n :=\n  sorry\n\ntheorem trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos {R : Type u} [semiring R]\n    {p : polynomial R} {n : ℕ} (hn : 0 < n) : trailing_degree p = ↑n ↔ nat_trailing_degree p = n :=\n  sorry\n\ntheorem nat_trailing_degree_eq_of_trailing_degree_eq_some {R : Type u} [semiring R]\n    {p : polynomial R} {n : ℕ} (h : trailing_degree p = ↑n) : nat_trailing_degree p = n :=\n  sorry\n\n@[simp] theorem nat_trailing_degree_le_trailing_degree {R : Type u} [semiring R]\n    {p : polynomial R} : ↑(nat_trailing_degree p) ≤ trailing_degree p :=\n  sorry\n\ntheorem nat_trailing_degree_eq_of_trailing_degree_eq {R : Type u} {S : Type v} [semiring R]\n    {p : polynomial R} [semiring S] {q : polynomial S} (h : trailing_degree p = trailing_degree q) :\n    nat_trailing_degree p = nat_trailing_degree q :=\n  sorry\n\ntheorem le_trailing_degree_of_ne_zero {R : Type u} {n : ℕ} [semiring R] {p : polynomial R}\n    (h : coeff p n ≠ 0) : trailing_degree p ≤ ↑n :=\n  (fun (this : finset.inf (finsupp.support p) some ≤ some n) => this)\n    (finset.inf_le (iff.mpr finsupp.mem_support_iff h))\n\ntheorem nat_trailing_degree_le_of_ne_zero {R : Type u} {n : ℕ} [semiring R] {p : polynomial R}\n    (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n :=\n  sorry\n\ntheorem trailing_degree_le_trailing_degree {R : Type u} [semiring R] {p : polynomial R}\n    {q : polynomial R} (h : coeff q (nat_trailing_degree p) ≠ 0) :\n    trailing_degree q ≤ trailing_degree p :=\n  sorry\n\ntheorem trailing_degree_ne_of_nat_trailing_degree_ne {R : Type u} [semiring R] {p : polynomial R}\n    {n : ℕ} : nat_trailing_degree p ≠ n → trailing_degree p ≠ ↑n :=\n  sorry\n\ntheorem nat_trailing_degree_le_of_trailing_degree_le {R : Type u} [semiring R] {p : polynomial R}\n    {n : ℕ} {hp : p ≠ 0} (H : ↑n ≤ trailing_degree p) : n ≤ nat_trailing_degree p :=\n  iff.mp with_top.coe_le_coe\n    (eq.mp\n      (Eq._oldrec (Eq.refl (↑n ≤ trailing_degree p)) (trailing_degree_eq_nat_trailing_degree hp)) H)\n\ntheorem nat_trailing_degree_le_nat_trailing_degree {R : Type u} [semiring R] {p : polynomial R}\n    {q : polynomial R} {hq : q ≠ 0} (hpq : trailing_degree p ≤ trailing_degree q) :\n    nat_trailing_degree p ≤ nat_trailing_degree q :=\n  sorry\n\n@[simp] theorem trailing_degree_monomial {R : Type u} {a : R} {n : ℕ} [semiring R] (ha : a ≠ 0) :\n    trailing_degree (coe_fn (monomial n) a) = ↑n :=\n  sorry\n\ntheorem nat_trailing_degree_monomial {R : Type u} {a : R} {n : ℕ} [semiring R] (ha : a ≠ 0) :\n    nat_trailing_degree (coe_fn (monomial n) a) = n :=\n  sorry\n\ntheorem nat_trailing_degree_monomial_le {R : Type u} {a : R} {n : ℕ} [semiring R] :\n    nat_trailing_degree (coe_fn (monomial n) a) ≤ n :=\n  sorry\n\ntheorem le_trailing_degree_monomial {R : Type u} {a : R} {n : ℕ} [semiring R] :\n    ↑n ≤ trailing_degree (coe_fn (monomial n) a) :=\n  sorry\n\n@[simp] theorem trailing_degree_C {R : Type u} {a : R} [semiring R] (ha : a ≠ 0) :\n    trailing_degree (coe_fn C a) = 0 :=\n  trailing_degree_monomial ha\n\ntheorem le_trailing_degree_C {R : Type u} {a : R} [semiring R] : 0 ≤ trailing_degree (coe_fn C a) :=\n  le_trailing_degree_monomial\n\ntheorem trailing_degree_one_le {R : Type u} [semiring R] : 0 ≤ trailing_degree 1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (0 ≤ trailing_degree 1)) (Eq.symm C_1))) le_trailing_degree_C\n\n@[simp] theorem nat_trailing_degree_C {R : Type u} [semiring R] (a : R) :\n    nat_trailing_degree (coe_fn C a) = 0 :=\n  iff.mp nonpos_iff_eq_zero nat_trailing_degree_monomial_le\n\n@[simp] theorem nat_trailing_degree_one {R : Type u} [semiring R] : nat_trailing_degree 1 = 0 :=\n  nat_trailing_degree_C 1\n\n@[simp] theorem nat_trailing_degree_nat_cast {R : Type u} [semiring R] (n : ℕ) :\n    nat_trailing_degree ↑n = 0 :=\n  sorry\n\n@[simp] theorem trailing_degree_C_mul_X_pow {R : Type u} {a : R} [semiring R] (n : ℕ) (ha : a ≠ 0) :\n    trailing_degree (coe_fn C a * X ^ n) = ↑n :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (trailing_degree (coe_fn C a * X ^ n) = ↑n))\n        (C_mul_X_pow_eq_monomial a n)))\n    (eq.mpr\n      (id\n        (Eq._oldrec (Eq.refl (trailing_degree (coe_fn (monomial n) a) = ↑n))\n          (trailing_degree_monomial ha)))\n      (Eq.refl ↑n))\n\ntheorem le_trailing_degree_C_mul_X_pow {R : Type u} [semiring R] (n : ℕ) (a : R) :\n    ↑n ≤ trailing_degree (coe_fn C a * X ^ n) :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (↑n ≤ trailing_degree (coe_fn C a * X ^ n)))\n        (C_mul_X_pow_eq_monomial a n)))\n    le_trailing_degree_monomial\n\ntheorem coeff_eq_zero_of_trailing_degree_lt {R : Type u} {n : ℕ} [semiring R] {p : polynomial R}\n    (h : ↑n < trailing_degree p) : coeff p n = 0 :=\n  iff.mp not_not (mt le_trailing_degree_of_ne_zero (not_le_of_gt h))\n\ntheorem coeff_eq_zero_of_lt_nat_trailing_degree {R : Type u} [semiring R] {p : polynomial R} {n : ℕ}\n    (h : n < nat_trailing_degree p) : coeff p n = 0 :=\n  sorry\n\n@[simp] theorem coeff_nat_trailing_degree_pred_eq_zero {R : Type u} [semiring R] {p : polynomial R}\n    {hp : 0 < ↑(nat_trailing_degree p)} : coeff p (nat_trailing_degree p - 1) = 0 :=\n  coeff_eq_zero_of_lt_nat_trailing_degree\n    (nat.sub_lt (iff.mp (with_top.zero_lt_coe (nat_trailing_degree p)) hp) nat.one_pos)\n\ntheorem le_trailing_degree_X_pow {R : Type u} [semiring R] (n : ℕ) : ↑n ≤ trailing_degree (X ^ n) :=\n  sorry\n\ntheorem le_trailing_degree_X {R : Type u} [semiring R] : 1 ≤ trailing_degree X :=\n  le_trailing_degree_monomial\n\ntheorem nat_trailing_degree_X_le {R : Type u} [semiring R] : nat_trailing_degree X ≤ 1 :=\n  nat_trailing_degree_monomial_le\n\n@[simp] theorem trailing_coeff_eq_zero {R : Type u} [semiring R] {p : polynomial R} :\n    trailing_coeff p = 0 ↔ p = 0 :=\n  sorry\n\ntheorem trailing_coeff_nonzero_iff_nonzero {R : Type u} [semiring R] {p : polynomial R} :\n    trailing_coeff p ≠ 0 ↔ p ≠ 0 :=\n  not_congr trailing_coeff_eq_zero\n\ntheorem nat_trailing_degree_mem_support_of_nonzero {R : Type u} [semiring R] {p : polynomial R} :\n    p ≠ 0 → nat_trailing_degree p ∈ finsupp.support p :=\n  iff.mpr mem_support_iff_coeff_ne_zero ∘ iff.mpr trailing_coeff_nonzero_iff_nonzero\n\ntheorem nat_trailing_degree_le_of_mem_supp {R : Type u} [semiring R] {p : polynomial R} (a : ℕ) :\n    a ∈ finsupp.support p → nat_trailing_degree p ≤ a :=\n  nat_trailing_degree_le_of_ne_zero ∘ iff.mp mem_support_iff_coeff_ne_zero\n\ntheorem nat_trailing_degree_eq_support_min' {R : Type u} [semiring R] {p : polynomial R}\n    (h : p ≠ 0) :\n    nat_trailing_degree p = finset.min' (finsupp.support p) (iff.mpr nonempty_support_iff h) :=\n  sorry\n\n@[simp] theorem trailing_degree_one {R : Type u} [semiring R] [nontrivial R] :\n    trailing_degree 1 = 0 :=\n  trailing_degree_C one_ne_zero\n\n@[simp] theorem trailing_degree_X {R : Type u} [semiring R] [nontrivial R] :\n    trailing_degree X = 1 :=\n  trailing_degree_monomial one_ne_zero\n\n@[simp] theorem nat_trailing_degree_X {R : Type u} [semiring R] [nontrivial R] :\n    nat_trailing_degree X = 1 :=\n  nat_trailing_degree_monomial one_ne_zero\n\n@[simp] theorem trailing_degree_neg {R : Type u} [ring R] (p : polynomial R) :\n    trailing_degree (-p) = trailing_degree p :=\n  sorry\n\n@[simp] theorem nat_trailing_degree_neg {R : Type u} [ring R] (p : polynomial R) :\n    nat_trailing_degree (-p) = nat_trailing_degree p :=\n  sorry\n\n@[simp] theorem nat_trailing_degree_int_cast {R : Type u} [ring R] (n : ℤ) :\n    nat_trailing_degree ↑n = 0 :=\n  sorry\n\n/-- The second-lowest coefficient, or 0 for constants -/\ndef next_coeff_up {R : Type u} [semiring R] (p : polynomial R) : R :=\n  ite (nat_trailing_degree p = 0) 0 (coeff p (nat_trailing_degree p + 1))\n\n@[simp] theorem next_coeff_up_C_eq_zero {R : Type u} [semiring R] (c : R) :\n    next_coeff_up (coe_fn C c) = 0 :=\n  sorry\n\ntheorem next_coeff_up_of_pos_nat_trailing_degree {R : Type u} [semiring R] (p : polynomial R)\n    (hp : 0 < nat_trailing_degree p) : next_coeff_up p = coeff p (nat_trailing_degree p + 1) :=\n  sorry\n\ntheorem coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt {R : Type u} [semiring R]\n    {p : polynomial R} {q : polynomial R} (h : trailing_degree p < trailing_degree q) :\n    coeff q (nat_trailing_degree p) = 0 :=\n  coeff_eq_zero_of_trailing_degree_lt (has_le.le.trans_lt nat_trailing_degree_le_trailing_degree h)\n\ntheorem ne_zero_of_trailing_degree_lt {R : Type u} [semiring R] {p : polynomial R} {n : with_top ℕ}\n    (h : trailing_degree p < n) : p ≠ 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/data/polynomial/degree/trailing_degree_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7789482302221613}}
{"text": "/-\nIn Lean, false is a proposition that\nis false in the sense that there is\nno proof of it. It's an uninhabited\ntype.\n-/\n\n#check false\n\n/-\ninductive false : Prop\n-/\n\n/-\nThere's no introduction rule for false\nas there are no proofs of it at all.\n-/\n\n/-\nThe elimination rule for false is very\nimportant.\n-/\n\ntheorem false_elim' : ∀ (P : Prop), false → P :=    -- false elimination\nλ P f, \n  match f with\n  end\n\ntheorem false_imp_anything : ∀ (P : Prop), false → P :=\nλ P f, false.elim f\n\n-- Universal specialization\nlemma false_imp_false : false → false := false_imp_anything false\n\nlemma false_imp_true : false → true := false_imp_anything true\n\n-- trick question\nlemma true_imp_false : true → false := λ t, _   -- stuck \n\n/-\nAs expected from propositional logic\n\ntrue → true   is true\ntrue → false  is false\nfalse → true  is true\nfalse → false is true\n-/\n\n\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/false.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7789350626717291}}
{"text": "import tactic \nimport data.real.basic\nimport topology.metric_space.basic\n\nopen_locale big_operators\n\n#print finset.sum_mono_set_of_nonneg\n\nopen finset (range)\n\n\n\nexample (n m : ℕ) (h : n ≤ m) : finset.range n ≤ finset.range m := finset.range_mono h\n\nlemma nonneg_sub_of_nonneg_sum {x : ℕ → ℝ} {n j : ℕ} (x_nonneg : ∀ i, 0 ≤ x i)\n  : 0 ≤ (∑ i in finset.range (n + j), (x i)) - (∑ i in finset.range n, (x i)) := by {\n    have h₁ : range n ≤ range (n + j) := sorry,\n    have : (∑ i in finset.range n, (x i)) ≤ (∑ i in finset.range (n + j), (x i)) := by {\n      have := @finset.sum_mono_set_of_nonneg ℕ ℝ _ x x_nonneg,\n      specialize this h₁,\n      dsimp only at this,\n      exact this,\n    },\n    exact sub_nonneg.mpr this,\n  }\n\n\nexample (a b : ℝ) (h₁ : 0 ≤ a) (h₂ : a ≤ 1) (h₃ : 0 ≤ b): a * b ≤ b := by {\n  exact mul_le_of_le_one_left h₃ h₂,\n}\nexample (a : ℝ) (h₁ : 0 ≤ a) (h₂ : a ≤ 1) : 0 ≤ 1 - a := sub_nonneg.mpr h₂\n\nexample (a : ℝ) (h₁ : 0 ≤ a) (h₂ : a ≤ 1) : 1 - a ≤ 1 := sub_le_self 1 h₁\n\nexample (a b c : ℝ) (h₁ : a ≤ b) : a + c ≤ b + c := add_le_add_right h₁ c\n\nexample (a b : ℝ) (h₁ : 0 ≤ a) (h₂ : a ≤ 1) (h₃ : 0 ≤ b) : a * b ≤ b := mul_le_of_le_one_left h₃ h₂\n\nexample (a : ℝ) (h : 0 ≤ a) : 0 ≤ 1 / a := one_div_nonneg.mpr h\n\nexample (a : ℕ) : 0 ≤ (a : ℝ) := nat.cast_nonneg a\n\nexample (a : ℝ) (h : 0 ≤ a) : 0 ≤ a + 1 := by linarith\n\n#check finset.prod_le_one\n\n-- ????????\nexample (a b c : ℝ) (h : a = b * c) (h₁) : a / b = c := congr_fun (congr_fun h₁ a) b\n\nexample (a b c : ℝ) (h : a = b * c) (h₁ : 0 ≠ b) : a / b = c := (cancel_factors.cancel_factors_eq_div (eq.symm h) (ne.symm h₁)).symm\n\nexample (a b : ℝ) (h : a ≠ b) : b ≠ a := by library_search\n\nexample (a b : ℝ) : dist a b = abs (a - b) := real.dist_eq a b\n\n#check abs_eq_self\n\nexample (n m : ℕ) (x : ℕ → ℝ) : ∏ i in range m, x (n + i) = ∏ i in finset.Ico n (n + m), x i := by {\n  -- library_search,\n}\n\n#check finset.prod_Ico_eq_prod_range\n\n#check @finset.sum_sdiff\n\n#check @finset.Ico.subset_iff\n\n#check finset.range_eq_Ico\n\nexample (n m : ℕ) (h : n ≤ m) : n + (m - n) = n + m - n :=\nbegin \n  exact (nat.add_sub_assoc h n).symm,\nend\n\n#check finset.Ico.diff\n\nexample (a b c : ℕ) : a = b + (a - b) := \nbegin \n  simp,\nend\n\nexample (n : ℕ) : n ≤ n + 1 := nat.le_succ n\n\nlemma some_ineq (a n m : ℕ) (h : a ≤ n) : a.succ ≤ n + m + 1 := by {\n  have h₁ : a + 1 ≤ n + 1 := add_le_add_right h 1,\n  have h₂ : n + 1 ≤ n + m + 1 := by {\n    rw [add_comm n m, add_assoc],\n    exact le_add_self,\n  },\n  exact le_trans h₁ h₂,\n}\n\n-- example (a b : ℕ) : (a : ℝ) = (b : ℝ) → a = b := by {\n--   intros h,\n--   library_search,\n-- }\n\nlemma le_Ico_of_le (a b c : ℕ) (h : a ≤ b) : finset.Ico b c ≤ finset.Ico a c := by {\n  dsimp,\n  simp [has_subset.subset],\n  intros x h₁ h₂,\n  exact and.intro (le_trans h h₁) h₂,\n}", "meta": {"author": "hcheval", "repo": "tikhonov-mann", "sha": "6ab7fcefe9e1156c20bd5d1998a7deabd1eeb018", "save_path": "github-repos/lean/hcheval-tikhonov-mann", "path": "github-repos/lean/hcheval-tikhonov-mann/tikhonov-mann-6ab7fcefe9e1156c20bd5d1998a7deabd1eeb018/src/playground.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7789350609848621}}
{"text": "/-\nCopyright (c) 2022 María Inés de Frutos-Fernández, Filippo A. E. Nuccio. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: María Inés de Frutos-Fernández, Filippo A. E. Nuccio\n-/\nimport number_theory.padics.padic_integers\n\nnoncomputable theory\n\nopen function\nopen_locale big_operators\n\nnamespace padic_int\n\nvariables {p : ℕ} [fact(nat.prime p)]\n\n-- *[FAE]*: `Already declared`, probably already pushed?\n-- lemma coe_eq_zero (x : ℤ_[p]) : (x : ℚ_[p]) = 0  ↔ x = 0 :=\n-- ⟨λ h, by {rw ← padic_int.coe_zero at h, exact subtype.coe_inj.mp h},\n--     λ h, by {rw h, exact padic_int.coe_zero}⟩\n\n/-- `ℤ_[p]` with its usual ring structure is not a field. -/\nlemma not_is_field (p : ℕ) [hp : fact(nat.prime p)] : ¬ is_field ℤ_[p] :=\nbegin\n  rw ring.not_is_field_iff_exists_ideal_bot_lt_and_lt_top,\n  use ideal.span {(p : ℤ_[p])},\n  split,\n  { rw [bot_lt_iff_ne_bot, ne.def, ideal.span_singleton_eq_bot, nat.cast_eq_zero],\n    exact hp.1.ne_zero },\n  { rw [lt_top_iff_ne_top, ne.def, ideal.eq_top_iff_one, ideal.mem_span_singleton,\n      ← padic_int.norm_lt_one_iff_dvd, norm_one, not_lt], }\nend\n\nend padic_int\n\n-- For instances/lemmas about ℚₚ and ℤₚ\nnamespace padic\n\nvariables {p : ℕ} [fact(nat.prime p)]\n\ninstance algebra : algebra ℤ_[p] ℚ_[p] := ring_hom.to_algebra (padic_int.coe.ring_hom)\n\nlemma algebra_map_def : algebra_map ℤ_[p] ℚ_[p] =  padic_int.coe.ring_hom := rfl\nlemma algebra_map_apply (x : ℤ_[p]) : algebra_map ℤ_[p] ℚ_[p] x = x := rfl\n\n-- *[FAE]* `Already declared`: already pushed?\n-- lemma norm_le_one_iff_val_nonneg (x : ℚ_[p]) : ‖x‖ ≤ 1 ↔ 0 ≤ x.valuation := \n-- begin\n--   by_cases hx : x = 0,\n--   { simp only [hx, norm_zero, padic.valuation_zero, zero_le_one, le_refl], },\n--   { rw [padic.norm_eq_pow_val hx, ← zpow_zero (p : ℝ), zpow_le_iff_le \n--       (nat.one_lt_cast.mpr (nat.prime.one_lt' p).1), right.neg_nonpos_iff], \n--     apply_instance, }\n-- end\n\ninstance is_fraction_ring : is_fraction_ring ℤ_[p] ℚ_[p] :=\n{ map_units := \n  begin\n    rintros ⟨x, hx⟩,\n    rw [set_like.coe_mk, algebra_map_apply, is_unit_iff_ne_zero, ne.def,\n      padic_int.coe_eq_zero],\n    exact mem_non_zero_divisors_iff_ne_zero.mp hx,\n  end,\n  surj      := λ x,\n  begin\n    by_cases hx : ‖x‖ ≤ 1,\n    { use (⟨x, hx⟩, 1),\n      rw [submonoid.coe_one, map_one, mul_one],\n      refl, },\n    { set n := int.to_nat(- x.valuation) with hn,\n      have hn_coe : (n : ℤ) = -x.valuation,\n      { rw [hn, int.to_nat_of_nonneg],\n        rw right.nonneg_neg_iff,\n        rw norm_le_one_iff_val_nonneg at hx,\n        exact le_of_lt (not_le.mp hx), },\n      set a := x * p^n with ha,\n      have ha_norm : ‖a‖ = 1,\n      { have hx : x ≠ 0,\n        { intro h0,\n          rw [h0, norm_zero] at hx,\n          exact hx (zero_le_one) },\n        rw [padic_norm_e.mul, padic_norm_e.norm_p_pow, zpow_neg,\n          norm_eq_pow_val hx, mul_inv_eq_one₀, hn_coe],\n        apply zpow_ne_zero_of_ne_zero,\n        exact nat.cast_ne_zero.mpr (ne_zero.ne p) },\n      set b := (p^n : ℤ_[p]) with hb,\n      have hb_mem : b ∈ non_zero_divisors ℤ_[p],\n      { exact mem_non_zero_divisors_iff_ne_zero.mpr (ne_zero.ne _) },\n      use (⟨a, le_of_eq ha_norm⟩, ⟨b, hb_mem⟩),\n      simp only [set_like.coe_mk, map_pow, map_nat_cast, algebra_map_apply,\n        padic_int.coe_pow, padic_int.coe_nat_cast, subtype.coe_mk] }\n  end,\n  eq_iff_exists := λ x y,\n  begin\n    rw [algebra_map_apply, algebra_map_apply, subtype.coe_inj],\n    refine ⟨λ h, _, _⟩,\n    { use 1,\n      simp only [submonoid.coe_one, one_mul],\n      exact h },\n    { rintro ⟨⟨c, hc⟩, h⟩,\n      exact (mul_eq_mul_left_iff.mp h).resolve_right (mem_non_zero_divisors_iff_ne_zero.mp hc) }\n  end }\n\nend padic", "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/padic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436482, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7789350607822921}}
{"text": "\nvariable (α : Type) (p q : α → Prop)\n\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\n  Iff.intro\n    (\n      λ h : ∀ x, p x ∧ q x =>\n          ⟨\n            λ y : α =>\n              (h y).left\n          , λ y : α =>\n              (h y).right\n          ⟩\n    )\n    (\n      λ h : (∀ x, p x) ∧ (∀ x, q x) =>\n        λ y : α =>\n          ⟨\n            h.left y\n          , h.right y\n          ⟩\n    )\n\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\n  λ h : ∀ x, p x → q x =>\n    λ h' : ∀ y, p y =>\n      λ z : α =>\n        have h'' : p z → q z := h z\n        have z' : p z := h' z\n        h'' z'\n\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\n  λ h : (∀ x, p x) ∨ (∀ x, q x) =>\n    λ y : α =>\n      Or.elim h\n        (\n          λ hl : ∀ x, p x =>\n            Or.inl (hl y)\n        )\n        (\n          λ hr : ∀ x, q x =>\n            Or.inr (hr y)\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-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948928, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7789264100974682}}
{"text": "import data.real.basic\nimport algebra.big_operators\n\n---- DISCRETE RANDOM VARIABLE\n\nopen finset\n\nopen_locale big_operators\n\nuniverse x\n\nvariables \n{ι : Type x} \n[fintype ι]\n[decidable_eq ι]\n\nclass rnd_var (X : ι → ℝ) :=\n(probs_nonneg :  ∀ i, 0 ≤ X i)\n(sum_probs_one : ∑ i, X i = 1)\n\nvariables {X : ι → ℝ} [rnd_var X]\n\nlemma probs_le_one : ∀ i, X i ≤ 1 := \nbegin\n  have h1 : ∑ i, X i ≤ 1, by exact le_of_eq rnd_var.sum_probs_one,\n  have h2 : ∀ i, X i ≤ ∑ i, X i, {\n    intro i,\n    apply single_le_sum,\n    intros i hi,\n    apply rnd_var.probs_nonneg,\n    norm_num,\n  },\n  intro i,\n  apply le_trans, exact h2 i, exact h1,\nend\n\nvariable (X) -- Tell Lean to explicitly ask for X in what follows.\n\nnoncomputable theory\n\nsection\nopen_locale classical\n\n/--\nKronecker delta: \n-/\ndef delta (i : ι) (j : ι) : ℝ := if (i = j) then 1 else 0\n\n/--\nDefinition (deterministic random variable): \n-/\ndef is_deterministic :=  ∃ j, ∀ i, if (i = j) then (X i = 1) else (X i = 0)  \n\nend\n\nlemma delta_if_det {X : ι → ℝ} [rnd_var X]\n  (h : ∀ i, X i = 0 ∨ X i = 1) :\n  (∃ j, ∀ i, if (i = j) then (X i = 1) else (X i = 0)) :=\nbegin\n  have h_ite : X = λ i, if (X i = 1) then 1 else 0,\n  { ext i,\n    cases h i with hxi0 hxi1,\n    { rw [hxi0, if_neg (@zero_ne_one ℝ _ _)] },\n    { rw [if_pos hxi1, hxi1] } },\n  have h_norm : ∑ i, X i = 1 := rnd_var.sum_probs_one,\n  rw h_ite at h_norm,\n  dsimp only at h_norm,\n  -- split sum into two by value of X i\n  rw sum_ite at h_norm,\n  have h_aux : (∑ x in univ.filter (λ x, ¬X x = 1), 0 : ℝ) = 0 := sum_const_zero,\n  rw h_aux at h_norm,\n  rw [add_zero, sum_const, nsmul_one, ← nat.cast_one, nat.cast_inj,\n      card_eq_one] at h_norm,\n  -- now h_norm is essentially the goal but needs some massaging\n  cases h_norm with j hj,\n  simp_rw [ext_iff, mem_filter, mem_univ, true_and, mem_singleton, nat.cast_one] at hj,\n  use j,\n  intro i,\n  rw if_congr_prop (hj i).symm iff.rfl iff.rfl,\n  cases h i with hxi0 hxi1,\n  { rw [hxi0, if_neg (@zero_ne_one ℝ _ _)] },\n  { rw [if_pos hxi1, hxi1] }\nend\n\n/--\nDefinition (uniform random variable): a random variable\nwhose  probabilities are equal to 1/n, where n \nis the number of symbols that the random variable \ncan assume.\n-/\ndef is_uniform := ∀ i, X i = 1 / fintype.card ι", "meta": {"author": "BassemSafieldeen", "repo": "Shannon-theory", "sha": "7258c8e33739c30f1078b7f7f53513d36559f89c", "save_path": "github-repos/lean/BassemSafieldeen-Shannon-theory", "path": "github-repos/lean/BassemSafieldeen-Shannon-theory/Shannon-theory-7258c8e33739c30f1078b7f7f53513d36559f89c/src/rnd_var.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229959153748, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7788823128927683}}
{"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 ↔ F.ne_bot ∧ ∀ U ∈ B, ∃ M ∈ F, ∀ x y ∈ M, y - x ∈ U :=\nbegin\n  letI := B.uniform_space,\n  haveI := B.uniform_add_group,\n  suffices : F ×ᶠ F ≤ 𝓤 G ↔ ∀ U ∈ B, ∃ M ∈ F, ∀ x y ∈ M, y - x ∈ U,\n    by split ; rintros ⟨h', h⟩ ; refine ⟨h', _⟩ ; [rwa ← this, rwa this],\n  rw [uniformity_eq_comap_nhds_zero G, ← map_le_iff_le_comap],\n  change tendsto _ _ _ ↔ _,\n  simp [(basis_sets F).prod_self.tendsto_iff B.nhds_zero_has_basis]\nend\n\nend add_group_filter_basis\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/uniform_filter_basis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.778882307685969}}
{"text": "/-\nCopyright (c) 2021 François Sunatori. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: François Sunatori\n-/\nimport analysis.complex.circle\nimport linear_algebra.determinant\nimport linear_algebra.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 `|` x `|` := complex.abs x\n\n/-- An element of the unit circle defines a `linear_isometry_equiv` from `ℂ` to itself, by\nrotation. -/\ndef rotation : circle →* (ℂ ≃ₗᵢ[ℝ] ℂ) :=\n{ to_fun := λ a,\n  { norm_map' := λ x, show |a * x| = |x|, by rw [complex.abs_mul, abs_coe_circle, one_mul],\n    ..distrib_mul_action.to_linear_equiv ℝ ℂ a },\n  map_one' := linear_isometry_equiv.ext $ one_smul _,\n  map_mul' := λ _ _, linear_isometry_equiv.ext $ mul_smul _ _ }\n\n@[simp] lemma rotation_apply (a : circle) (z : ℂ) : rotation a z = a * z := rfl\n\nlemma rotation_ne_conj_lie (a : circle) : rotation a ≠ 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, ← 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 `ℂ ≃ₗᵢ[ℝ] ℂ` and checks if it is a rotation, returns an element of the\nunit circle. -/\n@[simps]\ndef rotation_of (e : ℂ ≃ₗᵢ[ℝ] ℂ) : circle :=\n⟨(e 1) / complex.abs (e 1), by simp⟩\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 : ℂ →ₗᵢ[ℝ] ℂ)\n  (h₃ : ∀ z, z + conj z = f z + conj (f z)) (z : ℂ) : (f z).re = z.re :=\nby simpa [ext_iff, add_re, add_im, conj_re, conj_im, ←two_mul,\n         (show (2 : ℝ) ≠ 0, by simp [two_ne_zero'])] using (h₃ z).symm\n\nlemma linear_isometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ}\n  (h₂ : ∀ z, (f z).re = z.re) (z : ℂ) :\n  (f z).im = z.im ∨ (f z).im = -z.im :=\nbegin\n  have h₁ := f.norm_map z,\n  simp only [complex.abs, norm_eq_abs] at h₁,\n  rwa [real.sqrt_inj (norm_sq_nonneg _) (norm_sq_nonneg _), norm_sq_apply (f z), norm_sq_apply z,\n    h₂, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h₁,\nend\n\nlemma linear_isometry.im_apply_eq_im {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) :\n  z + conj z = f z + conj (f z) :=\nbegin\n  have : ∥f z - 1∥ = ∥z - 1∥ := by rw [← f.norm_map (z - 1), f.map_sub, h],\n  apply_fun λ x, x ^ 2 at this,\n  simp only [norm_eq_abs, ←norm_sq_eq_abs] at this,\n  rw [←of_real_inj, ←mul_conj, ←mul_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, ←norm_eq_abs, linear_isometry.norm_map] at this,\n  rw [mul_conj, norm_sq_eq_abs, ←norm_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, ←this, add_comm],\nend\n\nlemma linear_isometry.re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : (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 : ℂ ≃ₗᵢ[ℝ] ℂ} (h : f 1 = 1) :\n  f = linear_isometry_equiv.refl ℝ ℂ ∨ f = conj_lie :=\nbegin\n  have h0 : f I = I ∨ f I = -I,\n  { have : |f I| = 1 := by simpa using f.norm_map complex.I,\n    simp only [ext_iff, ←and_or_distrib_left, neg_re, I_re, neg_im, neg_zero],\n    split,\n    { rw ←I_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 (λ h' : f I = I, _) (λ 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 : ℂ ≃ₗᵢ[ℝ] ℂ) :\n  ∃ a : circle, f = rotation a ∨ f = conj_lie.trans (rotation a) :=\nbegin\n  let a : circle := ⟨f 1, by simpa using f.norm_map 1⟩,\n  use a,\n  have : (f.trans (rotation a).symm) 1 = 1,\n  { simpa using rotation_apply a⁻¹ (f 1) },\n  refine (linear_isometry_complex_aux this).imp (λ h₁, _) (λ h₂, _),\n  { simpa using eq_mul_of_inv_mul_eq h₁ },\n  { exact eq_mul_of_inv_mul_eq h₂ }\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, ←norm_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 : ℂ →ₗ[ℝ] ℂ).det = 1 :=\nbegin\n  rw [←linear_map.det_to_matrix basis_one_I, to_matrix_rotation, matrix.det_fin_two],\n  simp [←norm_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 [←units.eq_iff, linear_equiv.coe_det, det_rotation, units.coe_one]\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/isometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7788823073853346}}
{"text": "import tactic\n/-\nThe theory of even and odd numbers\n-/\ndef even (n : ℕ) : Prop := ∃ d, n = 2 * d\ndef odd (n : ℕ) : Prop := ∃ d, n = 2 * d + 1\n\n/-\nsee https://www.codewars.com/kata/5e998b42dcf07b0001581def/lean\nfor a completely different approach (inductive definitions)\n-/\n\n/- ## interaction with 0 -/\n\nlemma even_zero : even 0 :=\nbegin\n  unfold even,\n\nend\n\n/- ## interaction with succ -/\n\nlemma even_add_one {n : ℕ} : even n → odd (n + 1) := sorry\n\nlemma odd_add_one {n : ℕ} : odd n → even (n + 1) := sorry\n\n/- ## interaction with add -/\n\ntheorem odd_add_odd {n m : ℕ} (hn : odd n) (hm : odd m) :\n  even (n + m) := sorry\n\ntheorem odd_add_even {n m : ℕ} (hn : odd n) (hm : even m) :\n  odd (n + m) := sorry\n\ntheorem even_add_odd {n m : ℕ} (hn : even n) (hm : odd m) :\n  odd (n + m) := sorry\n\ntheorem even_add_even {n m : ℕ} (hn : even n) (hm : even m) :\n  even (n + m) := sorry\n\n/- ## interaction with one -/\n\ntheorem odd_one : odd 1 := sorry\n\n/- ## interaction with mul -/\n\ntheorem even_mul_even {n m : ℕ} (hn : even n) (hm : even m) :\n  even (n * m) := sorry\n\ntheorem even_mul_odd {n m : ℕ} (hn : even n) (hm : odd m) :\n  even (n * m) := sorry\n\ntheorem odd_mul_even {n m : ℕ} (hn : odd n) (hm : even m) :\n  even (n * m) := sorry\n\ntheorem odd_mul_odd {n m : ℕ} (hn : odd n) (hm : odd m) :\n  odd (n * m) := sorry\n\n/- ## interaction with each other -/\n\nlemma odd_or_even (n : ℕ) : odd n ∨ even n := sorry \n\n-- hard?\nlemma not_odd_and_even {n : ℕ} : ¬ (odd n ∧ even n) := sorry\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/nat/even_and_odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7788823054493118}}
{"text": "def main :\n\nnamespace hides\n\ninductive nat : Type\n| zero : nat\n| succ : nat → nat\n\ndef nat_to_string : nat → string\n| nat.zero := \"0\"\n| (nat.succ n) := \"succ(\" ++ nat_to_string n ++ \")\"\n\ninstance : has_repr nat := ⟨nat_to_string⟩\n\ndef add : nat → nat → nat\n| m nat.zero := m\n| m (nat.succ n) := nat.succ (add m n)\n\ndef zero : nat := nat.zero\ndef one : nat := nat.succ nat.zero\ndef two : nat := nat.succ one\ndef three : nat := nat.succ two\n\n#eval three\n\nend hides\n\ndef even (n : nat) : Prop := ∃ m, n = 2 * m\ndef odd (n : nat) : Prop := ∃ m, n = 2 * m + 1\n\n#check ∀ n, even n ∨ even (n+1)\n\nlemma even_10: even 10 :=\nbegin\n  use 5,\n  refl,\nend\n\ntheorem even_plus_even {n m : nat} (h1 : even n) (h2 : even m) : even (n + m) :=\nbegin\n  cases h1 with k hk,\n  cases h2 with l hl,\n  use k + l,\n  rw [hk, hl],\n  ring,\nend\n\ninductive mynat : Type\n| zero : mynat\n| succ : mynat → mynat\n\n\nvariables (p q : Prop)\n\ntheorem and_comm : p ∧ q → q ∧ p :=\nbegin\n  assume h,\n  cases h with hp hq,\n  split,\n  exact hq,\n  exact hp,\nend\n\ntheorem and_left : p ∧ q → p :=\nbegin\n  assume h,\n  cases h with hp hq,\n  exact hp,\nend\n\ntheorem or_left : p ∨ q → p :=\nbegin\n  assume h,\n  cases h with hp hq,\n exact hp,\nend ", "meta": {"author": "nielsthl", "repo": "LEAN", "sha": "d84a434cad150b12ff2514d7c59aec900d598832", "save_path": "github-repos/lean/nielsthl-LEAN", "path": "github-repos/lean/nielsthl-LEAN/LEAN-d84a434cad150b12ff2514d7c59aec900d598832/nomathlib/test2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7788416482668788}}
{"text": "-- Conmutatividad_del_maximo.lean\n-- Si a, b ∈ ℝ, entonces max(a,b) = max(b,a)\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 30-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si a, b ∈ ℝ, entonces max(a,b) = max(b,a)\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : ℝ\n\n-- 1ª demostración\n-- ===============\n\nexample : max a b = max b a :=\nbegin\n  apply le_antisymm,\n  { show max a b ≤ max b a,\n    apply max_le,\n    { apply le_max_right },\n    { apply le_max_left }},\n  { show max b a ≤ max a b,\n    apply max_le,\n    { apply le_max_right },\n    { apply le_max_left }},\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : max a b = max b a :=\nbegin\n  have h : ∀ x y : ℝ, max x y ≤ max y x,\n  { intros x y,\n    apply max_le,\n    { apply le_max_right },\n    { apply le_max_left }},\n  apply le_antisymm,\n  apply h,\n  apply h,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : max a b = max b a :=\nbegin\n  have h : ∀ {x y : ℝ}, max x y ≤ max y x,\n  { intros x y,\n    exact max_le (le_max_right y x) (le_max_left y x),},\n  exact le_antisymm h h,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample : max a b = max b a :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply max_le,\n    apply le_max_right,\n    apply le_max_left },\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/Conmutatividad_del_maximo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7788416372970467}}
{"text": "/-\nStyles of function writing\n    1) \"C\" style\n    2) tactic script\n    3) lambda abstraction\n-/\ndef square : ℕ → ℕ \n    | n := n*n\n\n\ndef square' : ℕ → ℕ :=\n    λ n, n^2\n\n#eval (λ (n : ℕ ), n^2) 3\n\ndef x := λ (n:ℕ ), n^2\n\n#check x\n\n/-\nMust really know how to write lambda expressions\n-/\ndef x' := λ (n : bool), tt\n\n/-\nBe able to produce recursive function definitions (in Lean) for simple\narithmetic functions. Know how to reason about and write appropriate base \nand recursive cases for functions involving natural numbers. A base case \ngenerally involves an argument value of nat.zero. A recursive case generally \noccurs when an argument value is of the form (nat.succ n') for some n'. These\ntwo cases correspond to the two constructors for the nat data type. You might \nbe tempted to name the argument in a recursive case n, and to recurse on the \nexpression \"n minus 1\" but this will not work in Lean, because Lean cannot then \nprove to itself that the recursion terminates. The definition of the factorial \nfunction (in Lean) is a good example to study. \n-/\n\n--recursive find fibonaci\nopen nat\ndef fib : ℕ → ℕ \n    |nat.zero := nat.zero\n    | (succ(nat.zero)):= (succ(nat.zero))\n    | (succ(succ n')) := fib(n') + fib(n' + 1)\n\ndef fact : ℕ → ℕ \n    | nat.zero := succ nat.zero\n    | (succ(nat.zero)):= (succ(nat.zero))\n    | (succ n') := fact (n') * (succ n')\n\n#eval fact 4\n\n/-\nUnderstand key tradeoffs when defining functions using mathematical logic, and\nusing imperative programming languages, respectively\nAnswer: mathematical logic can be easier to understand and explain but imperative\nprogramming allows for more efficient use of computational resources as\nwell as fewer lines of code\n-/\n\n/-\nUnderstand key shortcomings of natural languages for expressing mathematical \n(including specification and implementation) concepts.\nAnswer: Natural Language: The language that we all speak.\nNot the language that machines operate using. There is too much \nambiguity in natural language. It is not checkable by machines.\n\nFormal Language: ex Python, boolean algebra. Well defined\nlanguage with no ambiguity. Some formal languages are based\noff of the structure of natural language(ex. cobol)\n-/\n\n/-\nUnderstand precisely what it means for a program to be correct with respect to \n(or \"equivalent\" to) a specification written in math logic.\n-/\n\n/-\nKnow Boolean function truth tables\n-/\n\n/-\nKnow how lists (\"sequences\") are inductively defined and be able to define\nrecursive functions that operate on lists\n\ninductive nat : Type\n| zero : nat\n| succ : nat → nat\n-/\nopen nat\ninductive list_nat : Type\n| nil\n| cons : nat → list_nat → list_nat\nopen list_nat\n--Recursive list function\ndef length_nat : list_nat → ℕ \n| nil := 0\n| (cons h t) := 1 + (length_nat t)\n\ndef append_mnat : list_nat → list_nat → list_nat\n| nil h := h\n| (cons h t) o := cons h (append_mnat t o)\n\n/-\nKnow how to define polymorphic functions that work with values of type \n(list alpha), where alpha is a type parameter. Understand implicit \narguments and how to use them in Lean function definitions.\n\ndef unbox' (α : Type) : boxed α → α\n| (box v) := v\n\ndef unbox {α : Type} : boxed α → α \n-- Use curly braces to indicate implicit arg\n| (box v) := v\n-/\n\n/-\nKnow how to define simple enumerated types in Lean and functions\nthat operate on values of such types. The \"day\" type that we covered\nis an example of such a type.\n-/\ninductive day : Type  \n | sun : day\n | mon : day\n | tue : day \n | wed : day \n | thu : day \n | fri : day \n | sat : day\n\n\ninductive mybool : Type\n    | ttt\n    | fff\n\nopen day\ndef nextDay : day → day \n | sun := mon\n | mon := tue\n | tue := wed \n | wed := thu \n | thu := fri \n | fri := sat \n | sat := sun\n\n/-\nUnderstand the higher-order \"map\" and \"reduce\" functions \nthat we've studied. The key characteristic of higher-order \nfunctions is that they take function arguments, or return \nfunctions as results, or both. Be able to implement and use \nmap and reduce functions. \n-/\nopen list\ndef map_pred : (ℕ → bool) → list nat → (list bool)\n| _ [] := []\n| f (cons h t) := \n    if (f h)\n    then (cons tt (map_pred f t))\n    else (cons ff (map_pred f t))\n\n-- Answer here\ndef b_list := [0,1,2,5,1,0]\n\ndef reduce_and : list bool → bool \n| [] := tt \n| (cons ff t) := ff\n| (cons tt t) := reduce_and t\n\n/-\nUnderstand how to specify and work with \"product\" types. \nThe \"prod\" type we defined is an example of a type whose \nvalues are ordered *pairs* of values of other specified types.\n\nAns: A polymorphic \"product type\", prod. A product\ntype is a type whose values are ordered pairs.\nHere the types of the first and second elements\nof such a pair are given by the values of two\ntype arguments, α and β respectively. The pair\nconstructor takes a value of type α and one of\ntype β and yeilds the term (pair a b), whic we \nwill interpret as representing the ordered pair,\n(a, b), a concept that should be familiar from\nbasic high school algebra.\n-/\n\ninductive prod2 (α β : Type) : Type\n| pair (a : α) (b : β) : prod2\n\ndef fst {α β : Type} : prod2 α β → α \n| (prod2.pair a b) := a\n\ndef snd {α β : Type} : prod2 α β → β \n| (prod2.pair a b) := b\n\n\n/-\nUnderstand the combinatorics of binary values. E.g., \nthere are 2^n possible values of a sequence of n \nbinary variables.\n\n(2^(n))^(2^m) = number of posible functions with n \ninput bits and m output bits\n-/", "meta": {"author": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/ExamPractice/exam_1_studyshi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.7788416284748857}}
{"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.fintype.card\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 ≠ 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`\nrepresents the rotations of the `n`-gon by `2πi/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 ≠ 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πi/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 : ℕ) : Type\n| r : zmod n → dihedral_group\n| sr : zmod n → dihedral_group\n\nnamespace dihedral_group\n\nvariables {n : ℕ}\n\n/--\nMultiplication of the dihedral group.\n-/\nprivate def mul : dihedral_group n → dihedral_group n → 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) := ⟨one⟩\n\n/--\nThe inverse of a an element of the dihedral group.\n-/\nprivate def inv : dihedral_group n → 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 ⊕ zmod n) ≃ dihedral_group n :=\n{ inv_fun := λ i, match i with\n                 | (r j) := sum.inl j\n                 | (sr j) := sum.inr j\n                 end,\n  to_fun := λ 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) := ⟨⟨r 0, sr 0, dec_trivial⟩⟩\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 [← fintype.card_eq.mpr ⟨fintype_helper⟩, fintype.card_sum, zmod.card, two_mul]\n\n@[simp] lemma r_one_pow (k : ℕ) : (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 ⟨nat.prime_two⟩ },\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) := ⟨hnpos⟩,\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 [← 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 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 ←zmod.nat_cast_zmod_val i },\n  rw [←r_one_pow, order_of_pow, order_of_r_one]\nend\n\nend dihedral_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/group_theory/specific_groups/dihedral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7787449622785036}}
{"text": "/-\n# References\n\n1. Avigad, Jeremy. ‘Theorem Proving in Lean’, n.d.\n-/\n\n-- Exercise 1\n--\n-- Prove these equivalences. You should also try to understand why the reverse\n-- implication is not derivable in the last example.\nnamespace ex1\n\nvariable (α : Type _)\nvariable (p q : α → Prop)\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\n  Iff.intro\n    (fun h => ⟨fun x => And.left (h x), fun x => And.right (h x)⟩)\n    (fun ⟨h₁, h₂⟩ x => ⟨h₁ x, h₂ x⟩)\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\n  fun h₁ h₂ x =>\n    have px : p x := h₂ x\n    h₁ x px\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\n  fun h₁ x => h₁.elim\n    (fun h₂ => Or.inl (h₂ x))\n    (fun h₂ => Or.inr (h₂ x))\n\n-- The implication in the above example cannot be proven in the other direction\n-- because it may be the case predicate `p x` holds for certain values of `x`\n-- but not others that `q x` may hold for (and vice versa).\n\nend ex1\n\n-- Exercise 2\n--\n-- It is often possible to bring a component of a formula outside a universal\n-- quantifier, when it does not depend on the quantified variable. Try proving\n-- these (one direction of the second of these requires classical logic).\nnamespace ex2\n\nvariable (α : Type _)\nvariable (p q : α → Prop)\nvariable (r : Prop)\n\nexample : α → ((∀ _ : α, r) ↔ r) :=\n  fun a => Iff.intro (fun h => h a) (fun hr _ => hr)\n\nsection\n\nopen Classical\n\nexample : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=\n  Iff.intro\n    (fun h₁ => (em r).elim\n      Or.inr\n      (fun nr => Or.inl (fun x => (h₁ x).elim id (absurd · nr))))\n    (fun h₁ => h₁.elim\n      (fun h₂ x => Or.inl (h₂ x))\n      (fun hr _ => Or.inr hr))\n\nend\n\nexample : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=\n  Iff.intro\n    (fun h hr hx => h hx hr)\n    (fun h hx hr => h hr hx)\n\nend ex2\n\n-- Exercise 3\n--\n-- Consider the \"barber paradox,\" that is, the claim that in a certain town\n-- there is a (male) barber that shaves all and only the men who do not shave\n-- themselves. Prove that this is a contradiction.\nnamespace ex3\n\nopen Classical\n\nvariable (men : Type _)\nvariable (barber : men)\nvariable (shaves : men → men → Prop)\n\nexample (h : ∀ x : men, shaves barber x ↔ ¬shaves x x) : False :=\n  have b : shaves barber barber ↔ ¬shaves barber barber := h barber\n  (em (shaves barber barber)).elim\n    (fun b' => absurd b' (Iff.mp b b'))\n    (fun b' => absurd (Iff.mpr b b') b')\n\nend ex3\n\n-- Exercise 4\n--\n-- Remember that, without any parameters, an expression of type `Prop` is just\n-- an assertion. Fill in the definitions of `prime` and `Fermat_prime` below,\n-- and construct each of the given assertions. For example, you can say that\n-- there are infinitely many primes by asserting that for every natural number\n-- `n`, there is a prime number greater than `n.` Goldbach’s weak conjecture\n-- states that every odd number greater than `5` is the sum of three primes.\n-- Look up the definition of a Fermat prime or any of the other statements, if\n-- necessary.\nnamespace ex4\n\ndef even (a : Nat) := ∃ b, a = 2 * b\n\ndef odd (a : Nat) := ¬even a\n\ndef prime (n : Nat) : Prop :=\n  n > 1 ∧ ∀ (m : Nat), (1 < m ∧ m < n) → n % m ≠ 0\n\ndef infinitelyManyPrimes : Prop :=\n  ∀ (n : Nat), (∃ (m : Nat), m > n ∧ prime m)\n\ndef FermatPrime (n : Nat) : Prop :=\n  ∃ (m : Nat), n = 2^(2^m) + 1\n\ndef infinitelyManyFermatPrimes : Prop :=\n  ∀ (n : Nat), (∃ (m : Nat), m > n ∧ FermatPrime m)\n\ndef GoldbachConjecture : Prop :=\n  ∀ (n : Nat), even n ∧ n > 2 →\n    ∃ (x y : Nat), prime x ∧ prime y ∧ x + y = n\n\ndef Goldbach'sWeakConjecture : Prop :=\n  ∀ (n : Nat), odd n ∧ n > 5 →\n    ∃ (x y z : Nat), prime x ∧ prime y ∧ prime z ∧ x + y + z = n\n\ndef Fermat'sLastTheorem : Prop :=\n  ∀ (n : Nat), n > 2 → (∀ (a b c : Nat), a^n + b^n ≠ c^n)\n\nend ex4\n\n-- Exercise 5\n--\n-- Prove as many of the identities listed in Section 4.4 as you can.\nnamespace ex5\n\nopen Classical\n\nvariable (α : Type _)\nvariable (p q : α → Prop)\nvariable (r s : Prop)\n\nexample : (∃ _ : α, r) → r :=\n  fun ⟨_, hr⟩ => hr\n\nexample (a : α) : r → (∃ _ : α, r) :=\n  fun hr => ⟨a, hr⟩\n\nexample : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r :=\n  Iff.intro\n    (fun ⟨hx, ⟨hp, hr⟩⟩ => ⟨⟨hx, hp⟩, hr⟩)\n    (fun ⟨⟨hx, hp⟩, hr⟩ => ⟨hx, ⟨hp, hr⟩⟩)\n\nexample : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=\n  Iff.intro\n    (fun ⟨hx, hpq⟩ => hpq.elim\n      (fun hp => Or.inl ⟨hx, hp⟩)\n      (fun hq => Or.inr ⟨hx, hq⟩))\n    (fun h => h.elim\n      (fun ⟨hx, hp⟩ => ⟨hx, Or.inl hp⟩)\n      (fun ⟨hx, hq⟩ => ⟨hx, Or.inr hq⟩))\n\nexample : (∀ x, p x) ↔ ¬(∃ x, ¬p x) :=\n  Iff.intro\n    (fun h ⟨hx, np⟩ => np (h hx))\n    (fun h hx => byContradiction\n      fun np => h ⟨hx, np⟩)\n\nexample : (∃ x, p x) ↔ ¬(∀ x, ¬p x) :=\n  Iff.intro\n    (fun ⟨hx, hp⟩ h => absurd hp (h hx))\n    (fun h => byContradiction\n      fun h' => h (fun (x : α) hp => h' ⟨x, hp⟩))\n\nexample : (¬∃ x, p x) ↔ (∀ x, ¬p x) :=\n  Iff.intro\n    (fun h hx hp => h ⟨hx, hp⟩)\n    (fun h ⟨hx, hp⟩ => absurd hp (h hx))\n\ntheorem forall_negation : (¬∀ x, p x) ↔ (∃ x, ¬p x) :=\n  Iff.intro\n    (fun h => byContradiction\n      fun h' => h (fun (x : α) => byContradiction\n        fun np => h' ⟨x, np⟩))\n    (fun ⟨hx, np⟩ h => absurd (h hx) np)\n\nexample : (¬∀ x, p x) ↔ (∃ x, ¬p x) :=\n  forall_negation α p\n\nexample : (∀ x, p x → r) ↔ (∃ x, p x) → r :=\n  Iff.intro\n    (fun h ⟨hx, hp⟩ => h hx hp)\n    (fun h hx hp => h ⟨hx, hp⟩)\n\nexample (a : α) : (∃ x, p x → r) ↔ (∀ x, p x) → r :=\n  Iff.intro\n    (fun ⟨hx, hp⟩ h => hp (h hx))\n    (fun h₁ => (em (∀ x, p x)).elim\n      (fun h₂ => ⟨a, fun _ => h₁ h₂⟩)\n      (fun h₂ =>\n        have h₃ : (∃ x, ¬p x) := Iff.mp (forall_negation α p) h₂\n        match h₃ with\n        | ⟨hx, hp⟩ => ⟨hx, fun hp' => absurd hp' hp⟩))\n\nexample (a : α) : (∃ x, r → p x) ↔ (r → ∃ x, p x) :=\n  Iff.intro\n    (fun ⟨hx, hrp⟩ hr => ⟨hx, hrp hr⟩)\n    (fun h => (em r).elim\n      (fun hr => match h hr with\n                 | ⟨hx, hp⟩ => ⟨hx, fun _ => hp⟩)\n      (fun nr => ⟨a, fun hr => absurd hr nr⟩))\n\nend ex5\n\n-- Exercise 6\n--\n-- Give a calculational proof of the theorem `log_mul` below.\nnamespace ex6\n\nvariable (log exp : Float → Float)\nvariable (log_exp_eq : ∀ x, log (exp x) = x)\nvariable (exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x)\nvariable (exp_pos : ∀ x, exp x > 0)\nvariable (exp_add : ∀ x y, exp (x + y) = exp x * exp y)\n\nexample (x y z : Float) : exp (x + y + z) = exp x * exp y * exp z :=\n  by rw [exp_add, exp_add]\n\nexample (y : Float) (h : y > 0) : exp (log y) = y := exp_log_eq h\n\ntheorem log_mul {x y : Float} (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 hy]\n               _ = log (exp (log x) * exp (log y)) := by rw [exp_log_eq hx]\n               _ = log (exp (log x + log y)) := by rw [exp_add]\n               _ = log x + log y := by rw [log_exp_eq]\n\nend ex6\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/Exercises4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7787449572603091}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    [a,b] - (a,b) = {a,b}\n-- ----------------------------------------------------------------------\n\nimport data.set.intervals.basic\nimport tactic\n\nopen set\n\nvariables {α : Type*}  [linear_order α]\nvariables {a b : α}\n\nopen_locale classical\n\n-- 1ª demostración\n-- ===============\n\nlemma aux\n  (h : a < b)\n  (x : α)\n  : (x ∈ Icc a b \\ Ioo a b) ↔ x ∈ ({a, b} : set α) :=\nbegin\n  by_cases h' : a < x,\n  { simp [h', ne_of_gt h'],\n    split;\n    simp [le_antisymm_iff, le_of_lt h']\n      {contextual := tt} },\n  { push_neg at h',\n    simp [h', ne_of_lt (lt_of_le_of_lt h' h), le_trans h' (le_of_lt h)],\n    simp [le_antisymm_iff, h'],\n    intros h1 h2,\n    have h3 : a = x := le_antisymm h1 h',\n    rw h3 at h2,\n    have h4 : ¬(x < x) := lt_irrefl x,\n    exfalso,\n    apply h4,\n    exact h2, },\nend\n\nexample\n  (h : a < b)\n  : Icc a b \\ Ioo a b = {a, b} :=\next (aux h)\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (h : a < b)\n  : Icc a b \\ Ioo a b = {a, b} :=\nIcc_diff_Ioo_same $ le_of_lt h\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/Diferencia_de_intervalos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7787449564239411}}
{"text": "-- Si |x| < ε, para todo ε > 0, entonces x = 0\n-- ===========================================\n\nimport data.real.basic\n\nvariable (x : ℝ)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la notación |x| para el valor\n-- absoluto de x.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que si |x| < ε, para todo\n-- ε > 0, entonces x = 0\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nbegin\n  rw ← abs_eq_zero,\n  apply eq_of_le_of_forall_le_of_dense,\n  { exact abs_nonneg x, },\n  { intros ε hε,\n    apply le_of_lt,\n    exact h ε hε, },\nend\n\n-- 2ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nbegin\n  rw ← abs_eq_zero,\n  apply eq_of_le_of_forall_le_of_dense,\n  { exact abs_nonneg x, },\n  { intros ε hε,\n    exact le_of_lt (h ε hε), },\nend\n\n-- 3ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nbegin\n  rw ← abs_eq_zero,\n  apply eq_of_le_of_forall_le_of_dense,\n  { exact abs_nonneg x, },\n  { exact λ ε hε, le_of_lt (h ε hε), },\nend\n\n-- 4ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nbegin\n  rw ← abs_eq_zero,\n  apply eq_of_le_of_forall_le_of_dense\n        (abs_nonneg x)\n        (λ ε hε, le_of_lt (h ε hε)),\nend\n\n-- 5ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nabs_eq_zero.mp\n  (eq_of_le_of_forall_le_of_dense\n    (abs_nonneg x)\n    (λ ε hε, le_of_lt (h ε hε)))\n\n-- 6ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nhave h1 : 0 ≤ |x|,\n  from abs_nonneg x,\nhave h2 : ∀ ε, ε > 0 → |x| ≤ ε,\n  { assume ε,\n    assume hε : ε > 0,\n    have h2a : |x| < ε,\n      from h ε hε,\n    show |x| ≤ ε,\n      from le_of_lt h2a },\nhave h3 : |x| = 0,\n  from eq_of_le_of_forall_le_of_dense h1 h2,\nshow x = 0,\n  from abs_eq_zero.mp h3\n\n-- 7ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nhave h1 : 0 ≤ |x|,\n  from abs_nonneg x,\nhave h2 : ∀ ε, ε > 0 → |x| ≤ ε,\n  { assume ε,\n    assume hε : ε > 0,\n    have h2a : |x| < ε,\n      from h ε hε,\n    show |x| ≤ ε,\n      from le_of_lt h2a },\nhave h3 : |x| = 0,\n  from eq_of_le_of_forall_le_of_dense h1 h2,\nabs_eq_zero.mp h3\n\n-- 8ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nhave h1 : 0 ≤ |x|,\n  from abs_nonneg x,\nhave h2 : ∀ ε, ε > 0 → |x| ≤ ε,\n  { assume ε,\n    assume hε : ε > 0,\n    have h2a : |x| < ε,\n      from h ε hε,\n    show |x| ≤ ε,\n      from le_of_lt h2a },\nabs_eq_zero.mp (eq_of_le_of_forall_le_of_dense h1 h2)\n\n-- 9ª demostración\nexample\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nhave h1 : 0 ≤ |x|,\n  from abs_nonneg x,\nhave h2 : ∀ ε, ε > 0 → |x| ≤ ε,\n  { assume ε,\n    assume hε : ε > 0,\n    show |x| ≤ ε,\n      from le_of_lt (h ε hε) },\nabs_eq_zero.mp (eq_of_le_of_forall_le_of_dense h1 h2)\n\n-- 10ª demostración\nlemma cero_de_abs_mn_todos\n  (h : ∀ ε > 0, |x| < ε)\n  : x = 0 :=\nabs_eq_zero.mp\n  (eq_of_le_of_forall_le_of_dense\n    (abs_nonneg x)\n    (λ ε hε, le_of_lt (h ε hε)))\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/cero_de_abs_mn_todos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103777, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7787449564239369}}
{"text": "/-\nIf P and Q are propositions, then so in P ∨ Q.\nWe want to judge P ∨ Q to be true if at least\none of them is true. In other words, to judge\nP ∨ Q to be true, we need either to be able to\njudge P to be true or Q to be true (and if both\nare true, that's fine, too).\n-/\n\n#check or\n\n/-\ninductive or (a b : Prop) : Prop\n| inl (h : a) : or\n| inr (h : b) : or\n-/\n\n/-\nIt's a polymorphic \"either\" type (in Prop)!\n-/\n\n\naxioms (P Q : Prop) (p : P)\n\nlemma porq' : P ∨ Q := or.inl p\n\nlemma porq'' : P ∨ Q := \nbegin\napply or.inl _,\nexact p,\nend\n\naxiom q : Q\n\nlemma porq''' : P ∨ Q := or.inr q\n\n/-\ndef or.intro_left {a : Prop} (b : Prop) (ha : a) : or a b :=\nor.inl ha\n\ndef or.intro_right (a : Prop) {b : Prop} (hb : b) : or a b :=\nor.inr hb\n-/\n\n\n/-\nSuppose it's raining or the sprinkler is running.\nFuthermore, suppose that if it's raining the grass\nis wet, and if the sprinkler is running then the\ngrass is wet? What can you conclude? \n-/\n\n/-\nYou *used* the fact that at least one of the cases\nheld, combined with the fact that in *either* case,\nthe grass is wet, to deduce that the grass is wet.\n-/\n\naxioms (R : Prop) (porq : P ∨ Q) (pr : P → R) (qr : Q → R)\n\ntheorem RisTrue : R := or.elim porq pr qr\n\ntheorem RisTrue' : R := \nbegin\napply or.elim porq, \nexact pr,\nexact qr,\nend\n\n\n/- Or -/\n\n/-\ninductive or (a b : Prop) : Prop\n| inl (h : a) : or\n| inr (h : b) : or\n-/\n\n-- commutes forward, proof term\nexample : P ∨ Q → Q ∨ P :=\nλ h, \n  (match h with \n  | or.inl p := or.inr p\n  | or.inr q := or.inl q\n  end)\n\n-- commutes forward, tactic script\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  assume porq,\n  cases porq with p q,\n  exact or.inr p,\n  exact or.inl q,\nend\n\n/-\nor is associative, full proof\n-/\nexample : P ∨ (Q ∨ R) ↔ (P ∨ Q) ∨ R := \nbegin\n  apply iff.intro _ _,\n  \n  -- Forwards ->\n  assume pqr,\n  cases pqr with p qr,\n  apply or.inl _,\n  exact or.inl p,\n  cases qr with q r,\n  apply or.inl,\n  exact or.inr q,\n  exact or.inr r,\n\n  -- Backwards <-\n  assume pqr, \n  cases pqr,\n  _\nend", "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/or.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7787107504239699}}
{"text": "import data.set\nimport .src_17_even_odd_further\n\nopen set function\n\nnamespace mth1001\n\nsection images_of_functions\n\n/-\nSuppose `U` and `V` are types, that `f : U → V` is a function with domain `U` and codomain `V`.\n\nGiven a set `A : set U`, the *image* of `A` under `f` is the set\n`{v : V | ∃ u : U, u ∈ A ∧ f u = v}`.\n\nIn less formal language, we write this as `{f u | u ∈ A}`.\n\nLean denotes this image as `image f A` or `f '' A`. Mathematicians typically write the image of `A`\nunder `f` as `f (A)`. Note `A` is a set and so is `f (A)`.\n-/\n\nsection image_example\n\n/-\nFor example, we'll define a function `f : ℤ → ℤ` by `f n = 2 * n + 6`. We'll take `A` to be the\nset of integers and we'll show that `image f A` is the set of even integers.\n-/\n\ndef f (n : ℤ) : ℤ := 2 * n + 6\ndef A : set ℤ := {x | true} -- This is the set of all integers\n\nexample : f '' A = {y | even y} :=\nbegin\n  ext,  -- Assume `x : ℤ`. It suffices to show `x ∈ f '' A ↔ x ∈ {y : ℤ | even y}`.\n  split, -- Decompose the `↔` into two implication proofs.\n  { rintro ⟨n, ⟨_, h₂⟩⟩, -- `rintro` is intro followed by recursive application of `cases`.\n    -- Used here, we have `h₂ : f n = x` with a goal `x ∈ {y : ℤ | even y}`.\n    use (n + 3), -- It suffices to show `x = 2 * (n + 3)`.\n    rw ←h₂, -- Equally, to show `f n = 2 * (n + 3)`.\n    unfold f, -- In other words, to show `2 * n + 6 = 2 * (n + 3)`.\n    linarith, }, -- Which follows by linear arithmetic.\n  { rintro ⟨m, h₂⟩, -- Assume `m : ℤ` and `h₂ : x = 2 *m`. It suffices to show `x ∈ f '' A`.\n    use (m - 3), -- It suffices to show `m - 3 ∈ A ∧ f (m - 3) = x`.\n    split,\n    { unfold A, }, -- It's trivially true that `m - 3 ∈ A` as `A` is the set of all integers.\n    { unfold f, -- It suffices to show `2 * (m - 3) + 6 = x`.\n      rw h₂, -- That is, we must show `2 * (m - 3) + 6 = 2 * m`.\n      linarith, }, }, -- Which holds by linear arithmetic.\nend\n\nend image_example\n\nsection image_theorems\n\nvariable {α : Type*}\nvariable {β : Type*}\nvariables S T : set α\n\n-- The image of a union of the union of images.\ntheorem image_union (f : α → β) : f '' (S ∪ T) = f '' S ∪ f '' T :=\nbegin\n  ext,\n  split,\n  { rintro ⟨a, hs | ht, rfl⟩,\n    { rw mem_union_eq,\n      left,\n      use a,\n      cc, },\n    { right,\n      use a,\n      cc, }, },\n  { rintro (⟨a, hs, rfl⟩ | ⟨a, ht, rfl⟩),\n    { use a,\n      split,\n      { left, exact hs, },\n      { refl, }, },\n    { use a,\n      split,\n      { right, exact ht, },\n      { refl, }, }, },\nend\n\n-- Exercise 143:\n-- The image of an intersection is a subset of the intersection of the images.\ntheorem image_inter_subset (f : α → β) : f '' (S ∩ T) ⊆ f '' S ∩ f '' T :=\nbegin\n  rw subset_def,\n  sorry    \nend\n\n\n/-\nThe reverse inclusion of the above theorem is false. That is, there exist types `α`, `β`,\nthere exists a function `f : α → β`, there exist sets `S : set α` and `T : set β` such that\n`¬(f '' S ∩ f '' T ⊆ f '' (S ∩ T))`.\n\nCan you find a counterexample?\n-/\n\nend image_theorems\n\nend images_of_functions\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_29_images_of_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8633916152464016, "lm_q1q2_score": 0.7787107474568018}}
{"text": "import tactic.linarith\n\nnamespace mth1001\n\nsection inequalities_and_upper_bounds\n\n/-\nAt the start of this module, we looked at simple inequalities. We'll extend our study to\nconsider bounds and greatest bounds.\n\nThese considerations will later form the basis of our study of suprema of sets of real numbers.\n-/\n\n-- Given, `x ≤ 2`, we can prove `3 * x + 8 ≥ 5 * x`.\n-- Below, `∀ x ≤ 2, 3 * x + 8 ≥ 5 * x` is an abbreviation of `∀ x, x ≤ 2 → 3 * x + 8 ≥ 5 * x`.\nexample : ∀ x ≤ 2, 3 * x + 8 ≥ 5 * x :=\nbegin \n  intros x hx,\n  linarith,\nend \n\n-- Exercise 100:\nexample : ∀ x ≤ 0, 3 * x  + 8 ≥ 5 * x :=\nbegin \n  sorry  \nend \n\n\n/-\nWe can generalise the above, writing `x ≤ y` instead of `x ≤ 2` or `x ≤ 0`. However, it simply\nisn't true *for every `y`* that if `x ≤ y`, then `3 * x + 8 ≥ 5 * x`. We ask you to prove this\nbelow.\n-/\n\n-- Exercise 101:\nexample : ¬(∀ y, ∀ x, x ≤ y → 3 * x + 8 ≥ 5 * x) :=\nbegin \n  sorry  \nend\n\n/-\nHowever, if we impose constraints on `y`, for instance, given `y ≤ 3`, given `x ≤ y`, you can \nprove `3 * x + 8 ≥ 5 * x`.\n-/\n\n-- Exercise 102:\nexample : ∀ y ≤ 1, ∀ x ≤ y, 3 * x + 8 ≥ 5 * x :=\nbegin \n  sorry    \nend \n\n/-\nNow `1` isn't the only bound for `y`.\n-/\n\n-- Exercise 103:\nexample : ∀ y ≤ 0, ∀ x ≤ y, 3 * x + 8 ≥ 5 * x :=\nbegin \n  sorry  \nend \n\n-- Exercise 104:\n/-\nWe can generalise further, writing `y ≤ z` instead of `1` or `0` above. Once more, however, it\nisn't true that *for every* `z`, given `y ≤ z`, given `x ≤ y`, one has `3 * x + 8 ≥ 5 * x`.\n-/\nexample : ¬(∀ z, ∀ y ≤ z, ∀ x ≤ y, 3 * x + 8 ≥ 5 * x) :=\nbegin \n  sorry  \nend\n\n/-\nWe'll write a new definition `is_bnd_ineq` so that `is_bnd_ineq z` holds if, given `y ≤ z`,\ngiven `x ≤ y`, one has `3 * x + 8 ≥ 5 * x`.\n-/\n\ndef is_bnd_ineq (z : ℤ) := ∀ y ≤ z, ∀ x ≤ y, 3 * x + 8 ≥ 5 * x\n\n/-\nWith this definition, we can rephrase some of the results above. The proofs are no different.\n-/\n\n-- Exercise 105:\nexample : is_bnd_ineq 1 :=\nbegin\n  unfold is_bnd_ineq, -- This line isn't necessary for Lean, but helps the human proof writer!\n  sorry  \nend\n\n-- Exercise 106:\nexample : is_bnd_ineq 0 :=\nbegin\n  sorry  \nend\n\n/-\nWe come now to the main definition of this section. What does it mean to be a *greatest* bound?\n`z` is a greatest bound if:\n* `z` is a bound (i.e. we have `is_bnd_ineq z`) and\n* For every `w`, if `w` is a bound, then `w ≤ z`.\n-/\n\ndef greatest_bnd_ineq (z : ℤ) :=\nis_bnd_ineq z ∧ (∀ w, is_bnd_ineq w → w ≤ z)\n\n/-\nThe main task of this section is to prove `greatest_bnd_ineq 4`, i.e that `4` is a greatest bound.\n-/\n\n-- Exercise 107:\nexample : greatest_bnd_ineq 4 :=\nbegin \n  sorry  \nend\n\n/-\nWe'd like to conclude that `4` is *the* greatest bound, but we haven't proved that there is only\none greatest bound. This, we proceed to do.\n-/\n\n-- Exercise 108:\nexample (z₁ z₂ : ℤ) : greatest_bnd_ineq z₁ ∧ greatest_bnd_ineq z₂ → z₁ = z₂ :=\nbegin \n  intro h,\n  rcases h with ⟨⟨bnd₁, gt₁⟩, bnd₂, gt₂⟩,\n  have : z₁ ≤ z₂,\n  { sorry, }, \n  have : z₂ ≤ z₁,\n  { sorry, }, \n  linarith,\nend \n\nend inequalities_and_upper_bounds\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_18_inequalities_and_upper_bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7786667633470392}}
{"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, Patrick Massot\n\n! This file was ported from Lean 3 source module topology.nhds_set\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.Basic\n\n/-!\n# Neighborhoods of a set\n\nIn this file we define the filter `𝓝ˢ s` or `nhdsSet s` consisting of all neighborhoods of a set\n`s`.\n\n## Main Properties\n\nThere are a couple different notions equivalent to `s ∈ 𝓝ˢ t`:\n* `s ⊆ interior t` using `subset_interior_iff_mem_nhdsSet`\n* `∀ x : α, x ∈ t → s ∈ 𝓝 x` using `mem_nhdsSet_iff_forall`\n* `∃ U : Set α, IsOpen U ∧ t ⊆ U ∧ U ⊆ s` using `mem_nhdsSet_iff_exists`\n\nFurthermore, we have the following results:\n* `monotone_nhdsSet`: `𝓝ˢ` is monotone\n* In T₁-spaces, `𝓝ˢ`is strictly monotone and hence injective:\n  `strict_mono_nhdsSet`/`injective_nhdsSet`. These results are in `Mathlib.Topology.Separation`.\n\n-/\n\nopen Set Filter Topology\n\nvariable {α β : Type _} [TopologicalSpace α] [TopologicalSpace β] {s t s₁ s₂ t₁ t₂ : Set α} {x : α}\n\n/-- The filter of neighborhoods of a set in a topological space. -/\ndef nhdsSet (s : Set α) : Filter α :=\n  supₛ (nhds '' s)\n#align nhds_set nhdsSet\n\n@[inherit_doc] scoped[Topology] notation \"𝓝ˢ\" => nhdsSet\n\ntheorem nhdsSet_diagonal (α) [TopologicalSpace (α × α)] :\n    𝓝ˢ (diagonal α) = ⨆ (x : α), 𝓝 (x, x) := by\n  rw [nhdsSet, ← range_diag, ← range_comp]\n  rfl\n#align nhds_set_diagonal nhdsSet_diagonal\n\ntheorem mem_nhdsSet_iff_forall : s ∈ 𝓝ˢ t ↔ ∀ x : α, x ∈ t → s ∈ 𝓝 x := by\n  simp_rw [nhdsSet, Filter.mem_supₛ, ball_image_iff]\n#align mem_nhds_set_iff_forall mem_nhdsSet_iff_forall\n\ntheorem bUnion_mem_nhdsSet {t : α → Set α} (h : ∀ x ∈ s, t x ∈ 𝓝 x) : (⋃ x ∈ s, t x) ∈ 𝓝ˢ s :=\n  mem_nhdsSet_iff_forall.2 fun x hx => mem_of_superset (h x hx) <|\n    subset_unionᵢ₂ (s := fun x _ => t x) x hx -- porting note: fails to find `s`\n#align bUnion_mem_nhds_set bUnion_mem_nhdsSet\n\ntheorem subset_interior_iff_mem_nhdsSet : s ⊆ interior t ↔ t ∈ 𝓝ˢ s := by\n  simp_rw [mem_nhdsSet_iff_forall, subset_interior_iff_nhds]\n#align subset_interior_iff_mem_nhds_set subset_interior_iff_mem_nhdsSet\n\ntheorem disjoint_principal_nhdsSet : Disjoint (𝓟 s) (𝓝ˢ t) ↔ Disjoint (closure s) t := by\n  rw [disjoint_principal_left, ← subset_interior_iff_mem_nhdsSet, interior_compl,\n    subset_compl_iff_disjoint_left]\n\ntheorem disjoint_nhdsSet_principal : Disjoint (𝓝ˢ s) (𝓟 t) ↔ Disjoint s (closure t) := by\n  rw [disjoint_comm, disjoint_principal_nhdsSet, disjoint_comm]\n\ntheorem mem_nhdsSet_iff_exists : s ∈ 𝓝ˢ t ↔ ∃ U : Set α, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := by\n  rw [← subset_interior_iff_mem_nhdsSet, subset_interior_iff]\n#align mem_nhds_set_iff_exists mem_nhdsSet_iff_exists\n\ntheorem hasBasis_nhdsSet (s : Set α) : (𝓝ˢ s).HasBasis (fun U => IsOpen U ∧ s ⊆ U) fun U => U :=\n  ⟨fun t => by simp [mem_nhdsSet_iff_exists, and_assoc]⟩\n#align has_basis_nhds_set hasBasis_nhdsSet\n\ntheorem IsOpen.mem_nhdsSet (hU : IsOpen s) : s ∈ 𝓝ˢ t ↔ t ⊆ s := by\n  rw [← subset_interior_iff_mem_nhdsSet, hU.interior_eq]\n#align is_open.mem_nhds_set IsOpen.mem_nhdsSet\n\ntheorem principal_le_nhdsSet : 𝓟 s ≤ 𝓝ˢ s := fun _s hs =>\n  (subset_interior_iff_mem_nhdsSet.mpr hs).trans interior_subset\n#align principal_le_nhds_set principal_le_nhdsSet\n\n@[simp]\ntheorem nhdsSet_eq_principal_iff : 𝓝ˢ s = 𝓟 s ↔ IsOpen s := by\n  rw [← principal_le_nhdsSet.le_iff_eq, le_principal_iff, mem_nhdsSet_iff_forall,\n    isOpen_iff_mem_nhds]\n#align nhds_set_eq_principal_iff nhdsSet_eq_principal_iff\n\nalias nhdsSet_eq_principal_iff ↔ _ IsOpen.nhdsSet_eq\n#align is_open.nhds_set_eq IsOpen.nhdsSet_eq\n\n@[simp]\ntheorem nhdsSet_interior : 𝓝ˢ (interior s) = 𝓟 (interior s) :=\n  isOpen_interior.nhdsSet_eq\n#align nhds_set_interior nhdsSet_interior\n\n@[simp]\ntheorem nhdsSet_singleton : 𝓝ˢ {x} = 𝓝 x := by\n  ext\n  rw [← subset_interior_iff_mem_nhdsSet, ← mem_interior_iff_mem_nhds, singleton_subset_iff]\n#align nhds_set_singleton nhdsSet_singleton\n\ntheorem mem_nhdsSet_interior : s ∈ 𝓝ˢ (interior s) :=\n  subset_interior_iff_mem_nhdsSet.mp Subset.rfl\n#align mem_nhds_set_interior mem_nhdsSet_interior\n\n@[simp]\ntheorem nhdsSet_empty : 𝓝ˢ (∅ : Set α) = ⊥ := by rw [isOpen_empty.nhdsSet_eq, principal_empty]\n#align nhds_set_empty nhdsSet_empty\n\ntheorem mem_nhdsSet_empty : s ∈ 𝓝ˢ (∅ : Set α) := by simp\n#align mem_nhds_set_empty mem_nhdsSet_empty\n\n@[simp]\ntheorem nhdsSet_univ : 𝓝ˢ (univ : Set α) = ⊤ := by rw [isOpen_univ.nhdsSet_eq, principal_univ]\n#align nhds_set_univ nhdsSet_univ\n\n@[mono]\ntheorem nhdsSet_mono (h : s ⊆ t) : 𝓝ˢ s ≤ 𝓝ˢ t :=\n  supₛ_le_supₛ <| image_subset _ h\n#align nhds_set_mono nhdsSet_mono\n\ntheorem monotone_nhdsSet : Monotone (𝓝ˢ : Set α → Filter α) := fun _ _ => nhdsSet_mono\n#align monotone_nhds_set monotone_nhdsSet\n\ntheorem nhds_le_nhdsSet (h : x ∈ s) : 𝓝 x ≤ 𝓝ˢ s :=\n  le_supₛ <| mem_image_of_mem _ h\n#align nhds_le_nhds_set nhds_le_nhdsSet\n\n@[simp]\ntheorem nhdsSet_union (s t : Set α) : 𝓝ˢ (s ∪ t) = 𝓝ˢ s ⊔ 𝓝ˢ t := by\n  simp only [nhdsSet, image_union, supₛ_union]\n#align nhds_set_union nhdsSet_union\n\ntheorem union_mem_nhdsSet (h₁ : s₁ ∈ 𝓝ˢ t₁) (h₂ : s₂ ∈ 𝓝ˢ t₂) : s₁ ∪ s₂ ∈ 𝓝ˢ (t₁ ∪ t₂) := by\n  rw [nhdsSet_union]\n  exact union_mem_sup h₁ h₂\n#align union_mem_nhds_set union_mem_nhdsSet\n\n/-- Preimage of a set neighborhood of `t` under a continuous map `f` is a set neighborhood of `s`\nprovided that `f` maps `s` to `t`.  -/\ntheorem Continuous.tendsto_nhdsSet {f : α → β} {t : Set β} (hf : Continuous f)\n    (hst : MapsTo f s t) : Tendsto f (𝓝ˢ s) (𝓝ˢ t) :=\n  ((hasBasis_nhdsSet s).tendsto_iff (hasBasis_nhdsSet t)).mpr fun U hU =>\n    ⟨f ⁻¹' U, ⟨hU.1.preimage hf, hst.mono Subset.rfl hU.2⟩, fun _ => id⟩\n#align continuous.tendsto_nhds_set Continuous.tendsto_nhdsSet\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/NhdsSet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7786667542311343}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es una función de ℝ en ℝ tal que \n-- para cada a, existe un x tal que f x > a, entonces f no tiene cota\n-- superior.  \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\ndef fn_ub (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, f x ≤ a\n\ndef fn_has_ub (f : ℝ → ℝ) := ∃ a, fn_ub f a\n\nvariable f : ℝ → ℝ\n\nlemma no_has_ub \n  (h : ∀ a, ∃ x, f x > a) \n  : ¬ fn_has_ub f :=\nbegin\n  intros fnub,\n  cases fnub with a fnuba,\n  cases h a with x hx,\n  have : f x ≤ a,\n    from fnuba x,\n  linarith,\nend\n\n-- Prueba\n-- ------\n\n-- f : ℝ → ℝ,\n-- h : ∀ (a : ℝ), ∃ (x : ℝ), f x > a\n-- ⊢ ¬fn_has_ub f\n--    >> intros fnub,\n-- fnub : fn_has_ub f\n-- ⊢ false\n--    >> cases fnub with a fnuba,\n-- a : ℝ,\n-- fnuba : fn_ub f a\n-- ⊢ false\n--    >> cases h a with x hx,\n-- x : ℝ,\n-- hx : f x > a\n-- ⊢ false\n--    >> have : f x ≤ a,\n--    >>   from fnuba x,\n-- this : f x ≤ a\n-- ⊢ false\n--    >> linarith,\n-- no 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/Funcion_no_acotada_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7786667540251576}}
{"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.nat.prime\nimport data.list.prime\nimport data.list.sort\nimport tactic.nth_rewrite\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\nopen bool subtype\nopen_locale nat\n\nnamespace nat\n\n/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/\ndef factors : ℕ → list ℕ\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 : ∀ {n p}, p ∈ factors n → prime p\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := λ p h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  have h₁ : p = m ∨ p ∈ (factors (n / m)) :=\n    (list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),\n  or.cases_on h₁ (λ h₂, h₂.symm ▸ min_fac_prime dec_trivial)\n    prime_of_mem_factors\n\nlemma pos_of_mem_factors {n p : ℕ} (h : p ∈ factors n) : 0 < p :=\nprime.pos (prime_of_mem_factors h)\n\nlemma prod_factors : ∀ {n}, n ≠ 0 → list.prod (factors n) = n\n| 0       := by simp\n| 1       := by simp\n| n@(k+2) := λ h,\n  let m := min_fac n in have n / m < n := factors_lemma,\n  show (factors n).prod = n, from\n  have h₁ : n / m ≠ 0 := λ 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 ≠ 0, from dec_trivial) this,\n  by rw [factors, list.prod_cons, prod_factors h₁, nat.mul_div_cancel' (min_fac_dvd _)]\n\nlemma factors_prime {p : ℕ} (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 : ∀ {n a}, (∀ p, prime p → p ∣ n → a ≤ p) → list.chain (≤) a (factors n)\n| 0       := λ a h, by simp\n| 1       := λ a h, by simp\n| n@(k+2) := λ 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 λ 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 (≤) 2 (factors n) := factors_chain $ λ p pp _, pp.two_le\n\nlemma factors_chain' (n) : list.chain' (≤) (factors n) :=\n@list.chain'.tail _ _ (_::_) (factors_chain_2 _)\n\nlemma factors_sorted (n : ℕ) : list.sorted (≤) (factors n) :=\nlist.chain'_iff_pairwise.1 (factors_chain' _)\n\n/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/\nlemma factors_add_two (n : ℕ) :\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 : ℕ) : n.factors = [] ↔ n = 0 ∨ 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 : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) (h : a.factors ~ b.factors) : a = b :=\nby simpa [prod_factors ha, prod_factors hb] using list.perm.prod_eq h\n\nsection\nopen list\n\nlemma mem_factors_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : prime p) : p ∈ factors n ↔ p ∣ n :=\n⟨λ h, prod_factors hn ▸ list.dvd_prod h,\n  λ h, mem_list_primes_of_dvd_prod\n    (prime_iff.mp hp)\n    (λ p h, prime_iff.mp (prime_of_mem_factors h))\n    ((prod_factors hn).symm ▸ h)⟩\n\nlemma dvd_of_mem_factors {n p : ℕ} (h : p ∈ n.factors) : p ∣ n :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact dvd_zero p },\n  { rwa ←mem_factors_iff_dvd hn.ne' (prime_of_mem_factors h) }\nend\n\nlemma mem_factors {n p} (hn : n ≠ 0) : p ∈ factors n ↔ prime p ∧ p ∣ n :=\n⟨λ h, ⟨prime_of_mem_factors h, dvd_of_mem_factors h⟩,\n λ ⟨hprime, hdvd⟩, (mem_factors_iff_dvd hn hprime).mpr hdvd⟩\n\nlemma le_of_mem_factors {n p : ℕ} (h : p ∈ n.factors) : p ≤ 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 : ℕ} {l : list ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, prime p) :\n  l ~ factors n :=\nbegin\n  refine perm_of_prod_eq_prod _ _ _,\n  { rw h₁,\n    refine (prod_factors _).symm,\n    rintro rfl,\n    rw prod_eq_zero_iff at h₁,\n    exact prime.ne_zero (h₂ 0 h₁) rfl },\n  { simp_rw ←prime_iff, exact h₂ },\n  { simp_rw ←prime_iff, exact (λ p, prime_of_mem_factors) },\nend\n\nlemma prime.factors_pow {p : ℕ} (hp : p.prime) (n : ℕ) :\n  (p ^ n).factors = list.replicate n p :=\nbegin\n  symmetry,\n  rw ← list.replicate_perm,\n  apply nat.factors_unique (list.prod_replicate n p),\n  intros q hq,\n  rwa eq_of_mem_replicate hq,\nend\n\nlemma eq_prime_pow_of_unique_prime_dvd {n p : ℕ} (hpos : n ≠ 0)\n  (h : ∀ {d}, nat.prime d → d ∣ n → d = p) :\n  n = p ^ n.factors.length :=\nbegin\n  set k := n.factors.length,\n  rw [← prod_factors hpos, ← prod_replicate k p,\n    eq_replicate_of_mem (λ 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 : ℕ} (ha : a ≠ 0) (hb : b ≠ 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 : ℕ} (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 : ℕ} (h : k ≠ 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 : ℕ} (h : n ∣ k) (h' : k ≠ 0) : n.factors <+ k.factors :=\nbegin\n  obtain ⟨a, rfl⟩ := h,\n  exact factors_sublist_right (right_ne_zero_of_mul h'),\nend\n\nlemma factors_subset_right {n k : ℕ} (h : k ≠ 0) : n.factors ⊆ (n * k).factors :=\n(factors_sublist_right h).subset\n\nlemma factors_subset_of_dvd {n k : ℕ} (h : n ∣ k) (h' : k ≠ 0) : n.factors ⊆ k.factors :=\n(factors_sublist_of_dvd h h').subset\n\nlemma dvd_of_factors_subperm {a b : ℕ} (ha : a ≠ 0) (h : a.factors <+~ b.factors) : a ∣ 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 ←nat.prod_factors ha,\n  rw [←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']\nend\n\nend\n\nlemma mem_factors_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) {p : ℕ} :\n  p ∈ (a * b).factors ↔ p ∈ a.factors ∨ p ∈ b.factors :=\nbegin\n  rw [mem_factors (mul_ne_zero ha hb), mem_factors ha, mem_factors hb, ←and_or_distrib_left],\n  simpa only [and.congr_right_iff] using prime.dvd_mul\nend\n\n/-- The sets of factors of coprime `a` and `b` are disjoint -/\nlemma coprime_factors_disjoint {a b : ℕ} (hab : a.coprime b) : list.disjoint a.factors b.factors :=\nbegin\n  intros q hqa hqb,\n  apply not_prime_one,\n  rw ←(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 : ℕ} (hab : coprime a b) (p : ℕ):\n  p ∈ (a * b).factors ↔ p ∈ 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  rw [mem_factors_mul ha.ne' hb.ne', list.mem_union]\nend\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 : ℕ} (hpa : p ∈ a.factors) (hb : b ≠ 0) : p ∈ (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 : ℕ} (hpb : p ∈ b.factors) (ha : a ≠ 0) : p ∈ (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 : ℕ) :\n  (∃ k : ℕ, n = 2 ^ k) ∨ ∃ p, nat.prime p ∧ p ∣ n ∧ odd p :=\n(eq_or_ne n 0).elim\n  (λ hn, (or.inr ⟨3, prime_three, hn.symm ▸ dvd_zero 3, ⟨1, rfl⟩⟩))\n  (λ hn, or_iff_not_imp_right.mpr\n    (λ H, ⟨n.factors.length, eq_prime_pow_of_unique_prime_dvd hn\n      (λ p hprime hdvd, hprime.eq_two_or_odd'.resolve_right\n        (λ hodd, H ⟨p, hprime, hdvd, hodd⟩))⟩))\n\nend nat\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/factors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.77865921733696}}
{"text": "import combinatorics.simple_graph.basic\nimport combinatorics.simple_graph.degree_sum\nimport data.finset.basic\nimport data.nat.basic\nimport tactic.core\nimport algebra.big_operators\n\n\n--local\nimport misc_finset\n\nopen finset nat \nopen_locale big_operators \nnamespace simple_graph\n\n-- When counting edges in graphs we often want to consider subgraphs induced by a set of vertices\n-- or subgraphs between two (possibly disjoint) sets of vertices \n-- For this purpose we introduce the restricted neighbourhood a vertex to a finset.\n-- this is G.nbhd_res v A = A ∩ G.neighbor_finset v\n\n-- the restricted nbhd of a set of vertices\nsection nbhd_res\nvariables {t n : ℕ} \nvariables {α : Type*} (G : simple_graph α) [fintype α][nonempty α]{s : finset α}[decidable_eq α][decidable_rel G.adj]\n\n\n-- restricted nbhd is the part of nbhd in A\ninclude G\n@[ext]\ndef nbhd_res (v : α) (A : finset α) : finset α := A ∩ G.neighbor_finset v \n\n-- restriction of degree to A\ndef deg_res (v : α) (A : finset α) : ℕ:= (G.nbhd_res v A).card\n\n-- restricting to univ is no restriction at all\nlemma deg_res_univ (v : α) : G.deg_res v univ = G.degree v:=\nbegin\n  rw [deg_res,degree], congr, rw [nbhd_res,univ_inter],\nend\n\n-- we only define this over A restricted to A (could be broader)\n-- max deg res is zero if A is empty\n-- could replace this with (G.ind A).max_degree\ndef max_deg_res (A :finset α) : ℕ :=option.get_or_else (A.image (λ v, G.deg_res v A)).max 0\n\n\n-- if A.nonempty then there is a vertex of max_deg_res A\nlemma exists_max_res_deg_vertex  {A :finset α} (hA: A.nonempty) :\n  ∃ v∈A, G.max_deg_res A  = G.deg_res v A :=\nbegin\n  have neim: (A.image (λ v, G.deg_res v A)).nonempty:=nonempty.image hA _,\n  obtain ⟨t, ht⟩ := max_of_nonempty neim,\n  have ht₂ := mem_of_max ht,\n  simp only [pi.coe_nat, nat.cast_id, exists_prop, nonempty.image_iff, mem_image] at *,\n  rcases ht₂ with ⟨a,ha1, ha2⟩,\n  refine ⟨a, _⟩,\n  rw [max_deg_res, ht,option.get_or_else_coe],\n  exact ⟨ha1,ha2.symm⟩,\nend\n\n\n\n-- The max_deg_res over A is at least the deg_res of any particular vertex in A. \nlemma deg_res_le_max_deg_res  {v : α} {A : finset α} (hvA: v ∈ A) : G.deg_res v A ≤ G.max_deg_res A :=\nbegin\n  have hA: A.nonempty:=⟨v,hvA⟩,\n  obtain ⟨t, ht : _ = _⟩ := finset.max_of_mem (mem_image_of_mem (λ v, G.deg_res v A) hvA),\n  have := finset.le_max_of_mem (mem_image_of_mem _ hvA) ht,\n  rwa [max_deg_res,ht],  \nend\n\n\n-- bound on sum of deg_res given max deg_res (also a bound on e(C) for C ⊆ A)\n-- or equiv if C ⊆ A then 2*e(G[C])+e(G[C,A\\C])≤ (G.ind A).max_degree * |C|\nlemma max_deg_res_sum_le {A C : finset α} (hC: C ⊆ A) : ∑ v in C, G.deg_res v A ≤ (G.max_deg_res A)*(C.card):=\nbegin\n  rw [card_eq_sum_ones, mul_sum, mul_one],\n  apply sum_le_sum _, intros i hi, exact G.deg_res_le_max_deg_res (hC hi),\nend\n\n-- restricted degree to A is sum of ones over each neighbour of v in A\nlemma deg_res_ones (v : α) (A : finset α) : G.deg_res v A = ∑ x in G.nbhd_res v A, 1:=card_eq_sum_ones _\n\n--- if the restricted nbhd is non-empty then v has a neighbor in A\nlemma exists_mem_nempty {v :α} {A : finset α} (hA:  ¬(G.nbhd_res v A) = ∅ ): ∃ w∈A, G.adj v w :=\nbegin\n  rw nbhd_res at hA, contrapose! hA,\n  rw eq_empty_iff_forall_not_mem,\n  intros x hx, rw [mem_inter, mem_neighbor_finset] at hx, \n  exact hA x hx.1 hx.2, \nend\n\n-- member of the restricted nhd iff in nbhd and in A\nlemma mem_res_nbhd (v w : α) (A : finset α) : w ∈ G.nbhd_res v A ↔ w ∈ A ∧ w ∈ G.neighbor_finset v\n:=by rwa [nbhd_res,mem_inter]\n\n-- v is not a neighbor of itself\nlemma not_mem_nbhd (v : α)  : v ∉ G.neighbor_finset v :=\nbegin\n rw mem_neighbor_finset, exact G.loopless v,\nend\n\n-- nor is v a restricted neighbor of itself\nlemma not_mem_res_nbhd (v : α) (A :finset α) : v ∉ G.nbhd_res v A :=\nbegin\n  rw mem_res_nbhd,push_neg,intro h, exact G.not_mem_nbhd v,\nend\n\n-- restricted nbhd is contained in A\nlemma sub_res_nbhd_A (v : α) (A : finset α) : G.nbhd_res v A ⊆ A:=\nbegin\n  intro x, rw mem_res_nbhd,intro h, exact h.1,\nend\n\n-- restricted nbhd of member is stictly contained in A\nlemma ssub_res_nbhd_of_mem {v : α} {A : finset α} (h: v ∈ A) : G.nbhd_res v A ⊂ A\n:=(ssubset_iff_of_subset (G.sub_res_nbhd_A v A)).mpr ⟨v,h,G.not_mem_res_nbhd v A⟩\n\n-- restricted nbhd contained in nbhd\nlemma sub_res_nbhd_N (v : α)(A : finset α) : G.nbhd_res v A ⊆ G.neighbor_finset v:=\nbegin\n  intro _, rw mem_res_nbhd, intro h, exact h.2,\nend\n\n\n\n-- restricted degree additive over partition of A into B ∪ A\\B\n-- this is daft, it would work for any function defined on A \nlemma sum_sdf {A B: finset α} (hB: B ⊆ A) (C: finset α):\n ∑ v in A, G.deg_res v C = ∑v in B, G.deg_res v C + ∑ v in A\\B, G.deg_res v C:=\nbegin\n  nth_rewrite 0 ← union_sdiff_of_subset hB, exact sum_union (disjoint_sdiff),\nend\n\n-- restricted deg over A = restricted deg over B + restricted deg over A\\B\nlemma deg_res_add  {v : α} {A B : finset α} (hB: B ⊆ A): G.deg_res v A=  G.deg_res v B +  G.deg_res v (A\\B):=\nbegin\n  simp [deg_res,nbhd_res], nth_rewrite 0 ← union_sdiff_of_subset hB, \n  rw inter_distrib_right B (A\\B) _,\n  exact card_disjoint_union (sdiff_inter_disj A B _),\nend\n\n-- sum version of previous lemma\nlemma deg_res_add_sum {A B C : finset α} (hB: B ⊆ A) : ∑ v in C, G.deg_res v A=  ∑ v in C, G.deg_res v B+  ∑ v in C,G.deg_res v (A\\B):=\nbegin\n  rw ← sum_add_distrib, exact sum_congr rfl (λ _ _ , G.deg_res_add hB),\nend\n\n-- if A and B are disjoint then for any vertex v the deg_res add\nlemma deg_res_add'  {v : α} {A B : finset α} (h: disjoint A B): G.deg_res v (A∪B)=  G.deg_res v A +  G.deg_res v B:=\nbegin\n  simp [deg_res,nbhd_res],  rw inter_distrib_right,\n  exact card_disjoint_union (disj_of_inter_disj _ _ h),\nend\n \n-- sum version of previous lemma\nlemma deg_res_add_sum' {A B C: finset α} (h: disjoint A B) : ∑ v in C, G.deg_res v (A ∪ B) = ∑ v in C, G.deg_res v A +∑ v in C, G.deg_res v B:=\nbegin\n  rw ← sum_add_distrib, exact sum_congr rfl (λ _ _ , G.deg_res_add' h),\nend\n\n-- counting edges exiting B via ite helper, really just counting edges in e(B,A\\B)\nlemma bip_count_help {A B : finset α} (hB: B ⊆ A) : ∑ v in B, G.deg_res v (A\\B) = ∑ v in B, ∑ w in A\\B, ite (G.adj v w) 1 0:=\nbegin\n  simp only [deg_res_ones], congr,ext x, simp only [sum_const, algebra.id.smul_eq_mul, mul_one, sum_boole, cast_id], \n  congr, ext, rwa [mem_res_nbhd,mem_filter,mem_neighbor_finset],\nend\n\n-- edges from B to A\\B equals edges from A\\B to B\nlemma bip_count {A B : finset α} (hB: B ⊆ A) : ∑ v in B, G.deg_res v (A\\B) = ∑ v in A\\B, G.deg_res v B:=\nbegin\n  rw G.bip_count_help hB,\n  have:=sdiff_sdiff_eq_self hB,\n  conv { to_rhs,congr, skip,rw ← this,},\n  rw [G.bip_count_help (sdiff_subset A B),this,sum_comm],\n  congr, ext y, congr,ext x, \n  split_ifs,{refl},{exfalso, rw adj_comm at h, exact h_1 h}, \n  {exfalso, rw adj_comm at h, exact h h_1},{refl},\nend\n\n-- same but between any pair of disjoint sets rather tha B⊆A and A\\B\nlemma bip_count_help' {A B : finset α}  (hB: disjoint A B ) : ∑ v in B, G.deg_res v A = ∑ v in B, ∑ w in A, ite (G.adj v w) 1 0:=\nbegin\n  simp only [deg_res_ones], congr,ext x, simp only [sum_const, algebra.id.smul_eq_mul, mul_one, sum_boole, cast_id], \n  congr, ext, rwa [mem_res_nbhd,mem_filter,mem_neighbor_finset],\nend\n\n-- edges from A to B (disjoint) equals edges from B to A\nlemma bip_count' {A B : finset α} (hB: disjoint A B ) : ∑ v in B, G.deg_res v A = ∑ v in A, G.deg_res v B:=\nbegin\n  rw G.bip_count_help' hB, rw G.bip_count_help' hB.symm,rw sum_comm, congr,\n  ext y, congr,ext x, \n  split_ifs,{refl},{exfalso, rw adj_comm at h, exact h_1 h}, \n  {exfalso, rw adj_comm at h, exact h h_1},{refl},\nend\n\n-- sum of res_res_deg ≤ sum of res_deg \nlemma sum_res_le {A B C: finset α} (hB: B ⊆ A) (hC: C ⊆ A): ∑ v in C, G.deg_res v B ≤ ∑ v in C, G.deg_res v A :=\nbegin\n  apply sum_le_sum _,\n  intros i hi, \n  rw [deg_res,deg_res], apply card_le_of_subset _,\n  intros x hx, rw [mem_res_nbhd] at *,\n  exact ⟨hB hx.1, hx.2⟩,\nend\n\n\nend nbhd_res\n#lint\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/nbhd_res.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7786544672296157}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández 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 {α : Type*} {r : α → α → Prop} {s t : set α}\n\n/-! ### Subsets of bounded and unbounded sets -/\n\ntheorem bounded.mono (hst : s ⊆ t) (hs : bounded r t) : bounded r s :=\nhs.imp $ λ a ha b hb, ha b (hst hb)\n\ntheorem unbounded.mono (hst : s ⊆ t) (hs : unbounded r s) : unbounded r t :=\nλ a, let ⟨b, hb, hb'⟩ := hs a in ⟨b, hst hb, hb'⟩\n\n/-! ### Alternate characterizations of unboundedness on orders -/\n\nlemma unbounded_le_of_forall_exists_lt [preorder α] (h : ∀ a, ∃ b ∈ s, a < b) : unbounded (≤) s :=\nλ a, let ⟨b, hb, hb'⟩ := h a in ⟨b, hb, λ hba, hba.not_lt hb'⟩\n\nlemma unbounded_le_iff [linear_order α] : unbounded (≤) s ↔ ∀ a, ∃ b ∈ s, a < b :=\nby simp only [unbounded, not_le]\n\nlemma unbounded_lt_of_forall_exists_le [preorder α] (h : ∀ a, ∃ b ∈ s, a ≤ b) : unbounded (<) s :=\nλ a, let ⟨b, hb, hb'⟩ := h a in ⟨b, hb, λ hba, hba.not_le hb'⟩\n\nlemma unbounded_lt_iff [linear_order α] : unbounded (<) s ↔ ∀ a, ∃ b ∈ s, a ≤ b :=\nby simp only [unbounded, not_lt]\n\nlemma unbounded_ge_of_forall_exists_gt [preorder α] (h : ∀ a, ∃ b ∈ s, b < a) : unbounded (≥) s :=\n@unbounded_le_of_forall_exists_lt (order_dual α) _ _ h\n\nlemma unbounded_ge_iff [linear_order α] : unbounded (≥) s ↔ ∀ a, ∃ b ∈ s, b < a :=\n⟨λ h a, let ⟨b, hb, hba⟩ := h a in ⟨b, hb, lt_of_not_ge hba⟩, unbounded_ge_of_forall_exists_gt⟩\n\nlemma unbounded_gt_of_forall_exists_ge [preorder α] (h : ∀ a, ∃ b ∈ s, b ≤ a) : unbounded (>) s :=\nλ a, let ⟨b, hb, hb'⟩ := h a in ⟨b, hb, λ hba, not_le_of_gt hba hb'⟩\n\nlemma unbounded_gt_iff [linear_order α] : unbounded (>) s ↔ ∀ a, ∃ b ∈ s, b ≤ a :=\n⟨λ h a, let ⟨b, hb, hba⟩ := h a in ⟨b, hb, le_of_not_gt hba⟩, unbounded_gt_of_forall_exists_ge⟩\n\n/-! ### Relation between boundedness by strict and nonstrict orders. -/\n\n/-! #### Less and less or equal -/\n\nlemma bounded.rel_mono {r' : α → α → Prop} (h : bounded r s) (hrr' : r ≤ r') : bounded r' s :=\nlet ⟨a, ha⟩ := h in ⟨a, λ b hb, hrr' b a (ha b hb)⟩\n\nlemma bounded_le_of_bounded_lt [preorder α] (h : bounded (<) s) : bounded (≤) s :=\nh.rel_mono $ λ _ _, le_of_lt\n\nlemma unbounded.rel_mono {r' : α → α → Prop} (hr : r' ≤ r) (h : unbounded r s) : unbounded r' s :=\nλ a, let ⟨b, hb, hba⟩ := h a in ⟨b, hb, λ hba', hba (hr b a hba')⟩\n\nlemma unbounded_lt_of_unbounded_le [preorder α] (h : unbounded (≤) s) :\n  unbounded (<) s :=\nh.rel_mono $ λ _ _, le_of_lt\n\nlemma bounded_le_iff_bounded_lt [preorder α] [no_max_order α] : bounded (≤) s ↔ bounded (<) s :=\nbegin\n  refine ⟨λ h, _, bounded_le_of_bounded_lt⟩,\n  cases h with a ha,\n  cases exists_gt a with b hb,\n  exact ⟨b, λ c hc, lt_of_le_of_lt (ha c hc) hb⟩\nend\n\nlemma unbounded_lt_iff_unbounded_le [preorder α] [no_max_order α] :\n  unbounded (<) s ↔ unbounded (≤) s :=\nby simp_rw [← not_bounded_iff, bounded_le_iff_bounded_lt]\n\n/-! #### Greater and greater or equal -/\n\nlemma bounded_ge_of_bounded_gt [preorder α] (h : bounded (>) s) : bounded (≥) s :=\nlet ⟨a, ha⟩ := h in ⟨a, λ b hb, le_of_lt (ha b hb)⟩\n\nlemma unbounded_gt_of_unbounded_ge [preorder α] (h : unbounded (≥) s) : unbounded (>) s :=\nλ a, let ⟨b, hb, hba⟩ := h a in ⟨b, hb, λ hba', hba (le_of_lt hba')⟩\n\nlemma bounded_ge_iff_bounded_gt [preorder α] [no_min_order α] : bounded (≥) s ↔ bounded (>) s :=\n@bounded_le_iff_bounded_lt (order_dual α) _ _ _\n\nlemma unbounded_gt_iff_unbounded_ge [preorder α] [no_min_order α] :\n  unbounded (>) s ↔ unbounded (≥) s :=\n@unbounded_lt_iff_unbounded_le (order_dual α) _ _ _\n\n/-! ### Bounded and unbounded intervals -/\n\ntheorem bounded_self (a : α) : bounded r {b | r b a} :=\n⟨a, λ x, id⟩\n\n/-! #### Half-open bounded intervals -/\n\n\n\ntheorem bounded_le_Iio [preorder α] (a : α) : bounded (≤) (set.Iio a) :=\nbounded_le_of_bounded_lt (bounded_lt_Iio a)\n\ntheorem bounded_le_Iic [preorder α] (a : α) : bounded (≤) (set.Iic a) :=\nbounded_self a\n\ntheorem bounded_lt_Iic [preorder α] [no_max_order α] (a : α) : bounded (<) (set.Iic a) :=\nby simp only [← bounded_le_iff_bounded_lt, bounded_le_Iic]\n\ntheorem bounded_gt_Ioi [preorder α] (a : α) : bounded (>) (set.Ioi a) :=\nbounded_self a\n\ntheorem bounded_ge_Ioi [preorder α] (a : α) : bounded (≥) (set.Ioi a) :=\nbounded_ge_of_bounded_gt (bounded_gt_Ioi a)\n\ntheorem bounded_ge_Ici [preorder α] (a : α) : bounded (≥) (set.Ici a) :=\nbounded_self a\n\ntheorem bounded_gt_Ici [preorder α] [no_min_order α] (a : α) : bounded (>) (set.Ici a) :=\nby simp only [← bounded_ge_iff_bounded_gt, bounded_ge_Ici]\n\n/-! #### Other bounded intervals -/\n\ntheorem bounded_lt_Ioo [preorder α] (a b : α) : bounded (<) (set.Ioo a b) :=\n(bounded_lt_Iio b).mono set.Ioo_subset_Iio_self\n\ntheorem bounded_lt_Ico [preorder α] (a b : α) : bounded (<) (set.Ico a b) :=\n(bounded_lt_Iio b).mono set.Ico_subset_Iio_self\n\ntheorem bounded_lt_Ioc [preorder α] [no_max_order α] (a b : α) : bounded (<) (set.Ioc a b) :=\n(bounded_lt_Iic b).mono set.Ioc_subset_Iic_self\n\ntheorem bounded_lt_Icc [preorder α] [no_max_order α] (a b : α) : bounded (<) (set.Icc a b) :=\n(bounded_lt_Iic b).mono set.Icc_subset_Iic_self\n\ntheorem bounded_le_Ioo [preorder α] (a b : α) : bounded (≤) (set.Ioo a b) :=\n(bounded_le_Iio b).mono set.Ioo_subset_Iio_self\n\ntheorem bounded_le_Ico [preorder α] (a b : α) : bounded (≤) (set.Ico a b) :=\n(bounded_le_Iio b).mono set.Ico_subset_Iio_self\n\ntheorem bounded_le_Ioc [preorder α] (a b : α) : bounded (≤) (set.Ioc a b) :=\n(bounded_le_Iic b).mono set.Ioc_subset_Iic_self\n\ntheorem bounded_le_Icc [preorder α] (a b : α) : bounded (≤) (set.Icc a b) :=\n(bounded_le_Iic b).mono set.Icc_subset_Iic_self\n\ntheorem bounded_gt_Ioo [preorder α] (a b : α) : bounded (>) (set.Ioo a b) :=\n(bounded_gt_Ioi a).mono set.Ioo_subset_Ioi_self\n\ntheorem bounded_gt_Ioc [preorder α] (a b : α) : bounded (>) (set.Ioc a b) :=\n(bounded_gt_Ioi a).mono set.Ioc_subset_Ioi_self\n\ntheorem bounded_gt_Ico [preorder α] [no_min_order α] (a b : α) : bounded (>) (set.Ico a b) :=\n(bounded_gt_Ici a).mono set.Ico_subset_Ici_self\n\ntheorem bounded_gt_Icc [preorder α] [no_min_order α] (a b : α) : bounded (>) (set.Icc a b) :=\n(bounded_gt_Ici a).mono set.Icc_subset_Ici_self\n\ntheorem bounded_ge_Ioo [preorder α] (a b : α) : bounded (≥) (set.Ioo a b) :=\n(bounded_ge_Ioi a).mono set.Ioo_subset_Ioi_self\n\ntheorem bounded_ge_Ioc [preorder α] (a b : α) : bounded (≥) (set.Ioc a b) :=\n(bounded_ge_Ioi a).mono set.Ioc_subset_Ioi_self\n\ntheorem bounded_ge_Ico [preorder α] (a b : α) : bounded (≥) (set.Ico a b) :=\n(bounded_ge_Ici a).mono set.Ico_subset_Ici_self\n\ntheorem bounded_ge_Icc [preorder α] (a b : α) : bounded (≥) (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 α] [no_max_order α] (a : α) : unbounded (≤) (set.Ioi a) :=\nλ b, let ⟨c, hc⟩ := exists_gt (a ⊔ b) in\n  ⟨c, le_sup_left.trans_lt hc, (le_sup_right.trans_lt hc).not_le⟩\n\ntheorem unbounded_le_Ici [semilattice_sup α] [no_max_order α] (a : α) : unbounded (≤) (set.Ici a) :=\n(unbounded_le_Ioi a).mono set.Ioi_subset_Ici_self\n\ntheorem unbounded_lt_Ioi [semilattice_sup α] [no_max_order α] (a : α) : unbounded (<) (set.Ioi a) :=\nunbounded_lt_of_unbounded_le (unbounded_le_Ioi a)\n\ntheorem unbounded_lt_Ici [semilattice_sup α] (a : α) : unbounded (<) (set.Ici a) :=\nλ b, ⟨a ⊔ b, le_sup_left, le_sup_right.not_lt⟩\n\n/-! ### Bounded initial segments -/\n\ntheorem bounded_inter_not (H : ∀ a b, ∃ m, ∀ c, r c a ∨ r c b → r c m) (a : α) :\n  bounded r (s ∩ {b | ¬ r b a}) ↔ bounded r s :=\nbegin\n  refine ⟨_, bounded.mono (set.inter_subset_left s _)⟩,\n  rintro ⟨b, hb⟩,\n  cases H a b with m hm,\n  exact ⟨m, λ c hc, hm c (or_iff_not_imp_left.2 (λ hca, (hb c ⟨hc, hca⟩)))⟩\nend\n\ntheorem unbounded_inter_not (H : ∀ a b, ∃ m, ∀ c, r c a ∨ r c b → r c m) (a : α) :\n  unbounded r (s ∩ {b | ¬ r b a}) ↔ unbounded r s :=\nby simp_rw [← not_bounded_iff, bounded_inter_not H]\n\n/-! #### Less or equal -/\n\ntheorem bounded_le_inter_not_le [semilattice_sup α] (a : α) :\n  bounded (≤) (s ∩ {b | ¬ b ≤ a}) ↔ bounded (≤) s :=\nbounded_inter_not (λ x y, ⟨x ⊔ y, λ z h, h.elim le_sup_of_le_left le_sup_of_le_right⟩) a\n\ntheorem unbounded_le_inter_not_le [semilattice_sup α] (a : α) :\n  unbounded (≤) (s ∩ {b | ¬ b ≤ a}) ↔ unbounded (≤) s :=\nbegin\n  rw [←not_bounded_iff, ←not_bounded_iff, not_iff_not],\n  exact bounded_le_inter_not_le a\nend\n\ntheorem bounded_le_inter_lt [linear_order α] (a : α) :\n  bounded (≤) (s ∩ {b | a < b}) ↔ bounded (≤) s :=\nby simp_rw [← not_le, bounded_le_inter_not_le]\n\ntheorem unbounded_le_inter_lt [linear_order α] (a : α) :\n  unbounded (≤) (s ∩ {b | a < b}) ↔ unbounded (≤) s :=\nby { convert unbounded_le_inter_not_le a, ext, exact lt_iff_not_ge' }\n\ntheorem bounded_le_inter_le [linear_order α] (a : α) :\n  bounded (≤) (s ∩ {b | a ≤ b}) ↔ bounded (≤) s :=\nbegin\n  refine ⟨_, bounded.mono (set.inter_subset_left s _)⟩,\n  rw ←@bounded_le_inter_lt _ s _ a,\n  exact bounded.mono (λ x ⟨hx, hx'⟩, ⟨hx, le_of_lt hx'⟩)\nend\n\ntheorem unbounded_le_inter_le [linear_order α] (a : α) :\n  unbounded (≤) (s ∩ {b | a ≤ b}) ↔ unbounded (≤) s :=\nbegin\n  rw [←not_bounded_iff, ←not_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 α] (a : α) :\n  bounded (<) (s ∩ {b | ¬ b < a}) ↔ bounded (<) s :=\nbounded_inter_not (λ x y, ⟨x ⊔ y, λ z h, h.elim lt_sup_of_lt_left lt_sup_of_lt_right⟩) a\n\ntheorem unbounded_lt_inter_not_lt [semilattice_sup α] (a : α) :\n  unbounded (<) (s ∩ {b | ¬ b < a}) ↔ unbounded (<) s :=\nbegin\n  rw [←not_bounded_iff, ←not_bounded_iff, not_iff_not],\n  exact bounded_lt_inter_not_lt a\nend\n\ntheorem bounded_lt_inter_le [linear_order α] (a : α) :\n  bounded (<) (s ∩ {b | a ≤ b}) ↔ bounded (<) s :=\nby { convert bounded_lt_inter_not_lt a, ext, exact not_lt.symm }\n\ntheorem unbounded_lt_inter_le [linear_order α] (a : α) :\n  unbounded (<) (s ∩ {b | a ≤ b}) ↔ unbounded (<) s :=\nby { convert unbounded_lt_inter_not_lt a, ext, exact not_lt.symm }\n\ntheorem bounded_lt_inter_lt [linear_order α] [no_max_order α] (a : α) :\n  bounded (<) (s ∩ {b | a < b}) ↔ bounded (<) s :=\nbegin\n  rw [←bounded_le_iff_bounded_lt, ←bounded_le_iff_bounded_lt],\n  exact bounded_le_inter_lt a\nend\n\ntheorem unbounded_lt_inter_lt [linear_order α] [no_max_order α] (a : α) :\n  unbounded (<) (s ∩ {b | a < b}) ↔ unbounded (<) s :=\nbegin\n  rw [←not_bounded_iff, ←not_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 α] (a : α) :\n  bounded (≥) (s ∩ {b | ¬ a ≤ b}) ↔ bounded (≥) s :=\n@bounded_le_inter_not_le (order_dual α) s _ a\n\ntheorem unbounded_ge_inter_not_ge [semilattice_inf α] (a : α) :\n  unbounded (≥) (s ∩ {b | ¬ a ≤ b}) ↔ unbounded (≥) s :=\n@unbounded_le_inter_not_le (order_dual α) s _ a\n\ntheorem bounded_ge_inter_gt [linear_order α] (a : α) :\n  bounded (≥) (s ∩ {b | b < a}) ↔ bounded (≥) s :=\n@bounded_le_inter_lt (order_dual α) s _ a\n\ntheorem unbounded_ge_inter_gt [linear_order α] (a : α) :\n  unbounded (≥) (s ∩ {b | b < a}) ↔ unbounded (≥) s :=\n@unbounded_le_inter_lt (order_dual α) s _ a\n\ntheorem bounded_ge_inter_ge [linear_order α] (a : α) :\n  bounded (≥) (s ∩ {b | b ≤ a}) ↔ bounded (≥) s :=\n@bounded_le_inter_le (order_dual α) s _ a\n\ntheorem unbounded_ge_iff_unbounded_inter_ge [linear_order α] (a : α) :\n  unbounded (≥) (s ∩ {b | b ≤ a}) ↔ unbounded (≥) s :=\n@unbounded_le_inter_le (order_dual α) s _ a\n\n/-! #### Greater than -/\n\ntheorem bounded_gt_inter_not_gt [semilattice_inf α] (a : α) :\n  bounded (>) (s ∩ {b | ¬ a < b}) ↔ bounded (>) s :=\n@bounded_lt_inter_not_lt (order_dual α) s _ a\n\ntheorem unbounded_gt_inter_not_gt [semilattice_inf α] (a : α) :\n  unbounded (>) (s ∩ {b | ¬ a < b}) ↔ unbounded (>) s :=\n@unbounded_lt_inter_not_lt (order_dual α) s _ a\n\ntheorem bounded_gt_inter_ge [linear_order α] (a : α) :\n  bounded (>) (s ∩ {b | b ≤ a}) ↔ bounded (>) s :=\n@bounded_lt_inter_le (order_dual α) s _ a\n\ntheorem unbounded_inter_ge [linear_order α] (a : α) :\n  unbounded (>) (s ∩ {b | b ≤ a}) ↔ unbounded (>) s :=\n@unbounded_lt_inter_le (order_dual α) s _ a\n\ntheorem bounded_gt_inter_gt [linear_order α] [no_min_order α] (a : α) :\n  bounded (>) (s ∩ {b | b < a}) ↔ bounded (>) s :=\n@bounded_lt_inter_lt (order_dual α) s _ _ a\n\ntheorem unbounded_gt_inter_gt [linear_order α] [no_min_order α] (a : α) :\n  unbounded (>) (s ∩ {b | b < a}) ↔ unbounded (>) s :=\n@unbounded_lt_inter_lt (order_dual α) s _ _ a\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/bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.8872045847699186, "lm_q1q2_score": 0.7785014374111069}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hp,\n  intro np,\n  exact np hp,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro hnnp,\n  by_cases p : P, --LEM cria dois dados novos P e ¬P\n                  -- e dois jogos para cada um\n  exact p, -- fecha o primeiro jogo com dado P\n  exfalso, -- transforma alvo em boom  \n  contradiction, -- tenho em meus dados ¬P e ¬¬P \nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  exact doubleneg_elim P, \n  exact doubleneg_intro P,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hor,\n  cases hor with hp hq,\n  -- case left\n    right,\n    exact hp,\n  -- case rigth\n    left,\n    exact hq,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro hand,\n  cases hand with hp hq,\n  split,\n  -- left\n    exact hq,\n  -- rigth,\n    exact hp,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro hor,\n  intro hp,\n  cases hor with hnp hq,\n  -- left (¬P)\n    contradiction,\n  -- right (Q)\n    exact hq,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro hor,\n  intro hnp,\n  cases hor with hp hq,\n  -- left (P)\n     contradiction,\n  -- right (Q)\n     exact hq,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro hpq,\n  intro hnq,\n  by_cases hp: P, -- LEM\n     -- case LEM P\n     have hq: Q := hpq hp,\n     contradiction,\n     -- case LEM ¬P\n     exact hp,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n\n  intro hnqnp,\n  intro hp,\n  by_cases hq: Q, -- LEM Q\n  --- case LEM Q\n     exact hq,\n  --- case LEM ¬Q\n     have hnp: ¬P := hnqnp hq,\n     contradiction, \nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  -- visto do tópico do Ian, como reaproveitar teoremas \n  exact impl_as_contrapositive P Q,\n  exact impl_as_contrapositive_converse P Q,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro hnorp,\n  have hpornp : P∨¬P,-- demonstrar algo nos dados\n      right,\n      intro hp,\n      have hpornp : P∨¬P, -- demonstrar algo nos dados\n         left,\n         exact hp,\n         contradiction,\n      contradiction,\nend\n\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro hpqp,\n  intro hnp,\n  have hpq: (P → Q),\n     intro hp,\n     contradiction,\n  have hp : P := hpqp hpq,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro hor,\n  intro hnand,\n  cases hnand with hnp hnq,\n  cases hor with horp horq,\n  -- case P\n     contradiction,\n  -- case Q\n     contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro hand,\n  intro hnor,\n  cases hand with hp hq,\n  cases hnor with hnp hnq,\n  -- case ¬P\n     contradiction,\n  -- case ¬Q\n     contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n   intro hnpq,\n   split,\n   --- Part L\n      intro hp,\n      have hor : P∨Q,\n         left,\n         exact hp,\n      contradiction,\n    --- Part R\n      intro hq,\n      have hor: P∨Q,\n         right,\n         exact hq,\n      contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro hnpnq,\n  intro hporq,\n  cases hnpnq with hnp hnq,\n  cases hporq with hp hq,\n      -- case P\n      contradiction,\n      -- Case Q\n      contradiction,\n  ---\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro hnpq,\n  by_cases hq: Q,\n    --- case Q\n    right,\n    intro hp,\n    exact hnpq ⟨hp,hq⟩ ,\n    --- case ¬Q\n    left,\n    exact hq,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro hnqornp,\n  intro hpandq,\n  cases hpandq with hp hq,\n  cases hnqornp with hnq hnp,\n     --- case ¬Q\n     contradiction,\n     -- case ¬P\n     contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  exact demorgan_conj P Q,\n  exact demorgan_conj_converse P Q,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  exact demorgan_disj P Q,\n  exact demorgan_disj_converse P Q,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro hpqr,\n  cases hpqr with hp hqr,\n  cases hqr with hq hr,\n    left,\n      exact ⟨hp, hq⟩,\n    right,\n      exact ⟨hp, hr⟩,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro hor,\n  cases hor with hpq hpr,\n  --- case P∧Q\n     cases hpq with hp hq,\n     split,\n      --- Part P\n      exact hp,\n      --- Part QVR\n      left,\n        exact hq,\n  --- case P∧R\n      cases hpr with hp hr,\n      split,\n      --- Part P\n      exact hp,\n      --- QVR\n      right,\n        exact hr,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro hpqr,\n  cases hpqr,\n  -- case P\n    split,\n    --- Part PVQ\n      left,\n      exact hpqr,\n    --- Part PVR\n      left,\n      exact hpqr,\n  -- case Q^R\n    cases hpqr,\n    split,\n    --- part PVQ\n       right,\n       exact hpqr_left,\n    --- part PVR\n       right,\n       exact hpqr_right,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro hpqpr,\n  cases hpqpr with hpq hpr,\n  cases hpq,\n  --- case P\n     left,\n     exact hpq,\n  --- case Q,\n     cases hpr,\n     -- case P\n        left,\n        exact hpr,\n     -- case R\n        right,\n        exact ⟨hpq, hpr⟩,\n   end\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro pandqr,\n  intro hp,\n  intro hq,\n  have hpand: (P∧Q),\n     split,\n     exact hp,\n     exact hq,\n  exact pandqr hpand, \nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro hpqr,\n  intro pandq,\n  cases pandq with hp hq,\n  exact hpqr hp hq,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro hp,\n  exact hp,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro hp,\n  left,\n  exact hp,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro hq,\n  right,\n  exact hq,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro pandq,\n  exact pandq.left,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro hpq,\n  exact hpq.right,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pandp,\n  exact pandp.right,\n  intro hp,\n  split,\n     repeat{exact hp,},\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro porp,\n  cases porp,\n   repeat{exact porp,},\n  intro hp,\n    left,\n    exact hp,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n   intro hexistp,\n   intro x,\n   intro hp,\n   have existpx: ∃x, P x,\n      existsi x, exact hp,\n   contradiction,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro hnp,\n  by_contradiction hp,\n  cases hp with u hu,\n  have hnp: ¬P u := hnp u,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  rw [contrapositive_law, doubleneg_law],\n  intro hexistnp,\n  intro x,\n  by_cases hp: P x,\n  --- case P x\n     exact hp,\n  --- case ¬P x\n     have notexistpx: ∃x, ¬P x,\n         existsi x, exact hp,\n     contradiction,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro hnpx,\n  cases hnpx with u hnpu,\n  intro hpx,\n  have hpu: P u := hpx u,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_forall U P,\n  exact demorgan_forall_converse U P,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  exact demorgan_exists U P,\n  exact demorgan_exists_converse U P,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro hp,\n  cases hp with u hu,\n  intro hnp,\n  have hnu: ¬P u := hnp u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro hp,\n  intro hnp,\n  cases hnp with u hnu,\n  have hu : P u := hp u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro hnp,\n  intro x,\n  by_contradiction boom,\n  have henp: ∃x, ¬P x,\n     existsi x,\n     exact boom,\n  have f: false := hnp henp,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  rw [ contrapositive_law , doubleneg_law],\n  intro hp,\n  intro x,\n  by_cases hpl: P x,\n     -- case P x,\n     have existpx: ∃x, P x,\n         existsi x, exact hpl,\n     contradiction,\n     -- case ¬P x,\n     exact hpl,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  exact forall_as_neg_exists U P,\n  exact forall_as_neg_exists_converse U P,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  exact exists_as_neg_forall U P,\n  exact exists_as_neg_forall_converse U P,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro hpq,\n  cases hpq with u hu, --- seja u tq P u & Q u\n  cases hu with hpu hqu,\n  split,\n  --- Part P x\n     existsi u,\n     exact hpu,\n  --- Part Q x\n     existsi u,\n     exact hqu,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro hpq,\n  cases hpq with u hu,\n  cases hu with pu qu,\n  -- case pu\n     left,\n     existsi u,\n     exact pu,\n  --- case qu\n     right,\n     existsi u,\n     exact qu,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  --- case hp\n     cases hp with u pu,\n     existsi u,\n     left,\n     exact pu,\n  --- case hq\n     cases hq with u qu,\n     existsi u,\n     right,\n     exact qu,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro hpq,\n  split,\n  --- Part Px\n     intro x,\n     have hpqx : P x ∧ Q x := hpq x,\n     exact hpqx.left,\n  --- Part Qx\n     intro x,\n     have hpqx : P x ∧ Q x := hpq x,\n     exact hpqx.right,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro hand,\n  intro x,\n  cases hand with hp hq,\n  have hpx: P x := hp x,\n  have hqx: Q x := hq x,\n  exact ⟨hpx, hqx⟩, \nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro hporq,\n  intro x,\n  cases hporq with hpx hqx,\n  --- case hpx\n      have hpx: P x := hpx x,\n      left,\n      exact hpx,\n  --- case hqx,\n      have hqx: Q x := hqx x,\n      right,\n      exact hqx,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "samuamorin", "repo": "fmclean", "sha": "02fa4c0ba79f2842fd7800ec2965403742e854b0", "save_path": "github-repos/lean/samuamorin-fmclean", "path": "github-repos/lean/samuamorin-fmclean/fmclean-02fa4c0ba79f2842fd7800ec2965403742e854b0/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7784378711592141}}
{"text": "import MyNat.Definition\nimport MyNat.Addition\nimport AdvancedAdditionWorld.Level9 -- succ_ne_zero\nnamespace MyNat\nopen MyNat\n/-!\n# Advanced Addition World\n\n## Level 10: `add_left_eq_zero`\n\n## Important: the definition of `≠`\n\nIn Lean, `a ≠ b` is *defined to mean* `(a = b) → false`.\nThis means that if you see `a ≠ b` you can *literally treat\nit as saying* `(a = b) → false`. Computer scientists would\nsay that these two terms are *definitionally equal*.\n\nThe following lemma, `a+b=0 ⟹ b=0`, will be useful in [Inequality World](../InequalityWorld.lean.md).\nLet me go through the proof, because it introduces several new\nconcepts:\n\n* `cases b`, where `b : MyNat`\n* `exfalso`\n* `apply succ_ne_zero`\n\nWe're going to prove `a+b=0 ⟹ b=0`. Here is the\nstrategy. Each natural number is either `0` or `succ d` for\nsome other natural number `d`. So we can start the proof\nwith\n\n`cases b with d`\n\nand then we have two goals, the case `b = 0` (which you can solve easily)\nand the case `b = succ d`, which looks like this:\n\n```\na d : MyNat,\nh : a + succ d = 0\n⊢ succ d = 0\n```\n\nOur goal is impossible to prove. However our hypothesis `h`\nis also impossible, meaning that we still have a chance!\nFirst let's see why `h` is impossible. We can\n\n`rw [add_succ] at h`\n\nto turn `h` into `h : succ (a + d) = 0`. Because\n`succ_ne_zero (a + d)` is a proof that `succ (a + d) ≠ 0`,\nit is also a proof of the implication `succ (a + d) = 0 → false`.\nHence `succ_ne_zero (a + d) h` is a proof of `false`!\nUnfortunately our goal is not `false`, it's a generic\nfalse statement.\n\nRecall however that the `exfalso` command turns any goal into `false`\n(it's logically OK because `false` implies every proposition, true or false).\n\n\n## Lemma\nIf `a` and `b` are natural numbers such that `a + b = 0` then `b = 0`.\n-/\nlemma add_left_eq_zero {{a b : MyNat}} (h : a + b = 0) : b = 0 := by\n  cases b with\n  | zero =>\n    rfl\n  | succ d =>\n    rw [add_succ] at h\n    exfalso\n    apply succ_ne_zero (a + d)\n    exact h\n\n/-!\nNext up [Level 11](./Level11.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/Level10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.778409266775399}}
{"text": "/-\nUVa CS 2102 Discrete Math, Semester Exam 2.\n\nThis is an individual evaluation. You may not\ncommunicate with anyone about it by any means\nfor any reason whether directly or indirectly,\nwhile you, or anyone else in this class with \nwhom you might be communicating, directly or \nindirectly, has not yet taken and completed \nthe submission of their exam. You may not get\ninformation from anyone else that could help\nyou with this exam, nor may you allow any of\nyour information to be so obtained by others.\nViolations of these rules will result in the\nfailure of the exam, of the course, and can \nbe referred to the Honor Committee. Please\nsignal that you understand by signing the\nHonor Pledge electronically when you submit\nyour exam. Some students will be on travel\nor otherwise unable to take the exam today.\nDo not make answers or any other knowledge\nof the exam available until your instructors \nindicate that all exams have been submitted. \nThat will take up to one full week. \n\nThe exam has six questions for a total of\n100 points with an extra credit question\nworth two points. Several of the questions\nhave several parts. In these cases, the total\npoints for a question are evenly distributed\nover the parts.\n\nIf you don't know how to solve a particular\nproblem, just move on the the next problem.\nCome back to any problems you skipped when\nyou are finished with all the problems you\nknow how to solve without difficuty. \n\nThis is an open book, open your-own-notes\nexam.\n\nTurn off all communications software on all\nof your electronic devices before starting \nthis test. Turn off your cell phone. Turn off \nyour smart watch. Exit from Skype, messenger, \nmessages, Facetime, Signal, WhatsApp, and \nall other such services.\n-/\n\n\n/-\nThe first three questions of the exam\nuse definitions that we enclose within\na namespace. The end  of the namespace \nis after question 3. You can basically \nignore this except for a brief note in \nthe instructions for question 3, below.\n-/\nnamespace quantifiers\n\n/-\nThe following sequence of three problems\nuses two defintions that we now provide.\nWe assume there are people, and that one \nperson can like another. We formalize \nthese assumptions in the following axioms. \nWe assume that there are people, formally\nrepresented as terms of a type, Person;\nand we assume that and given person, p1, \nmight Like another person, p2, represented \nas a predicate, Likes, taking two arguments\nof type Person. We intepret \"Likes p1 p2\" \nas asserting that the person, p1, likes the \nperson, p2.\n-/\n\naxiom Person : Type\naxiom Likes : Person → Person → Prop\n\n/-\n1. [30 points in 5 parts with 6 points each] \n\nFor each part of this problem, write a formal \nproposition in Lean that expresses the given \npropositions given in English. Give you answers \nby filling them in in place of the holes.\n-/\n\n/-\n1a. Everyone likes someone.\n-/\n\ndef everyoneLikesSomeone : Prop := \n  (∀ (P: Person), ∃ (S : Person), Likes P S)\n\n/-\n1b. There is someone nobody likes.\n-/\n\ndef thereIsSomeoneNobodyLikes : Prop :=\n  (∃ (S : Person), ∀ P : Person, ¬Likes P S)\n\n/-\n1c. Someone likes everyone.\n-/\ndef someoneLikesEveryone : Prop :=\n  (∃ (S : Person), ∀ P : Person, Likes S P)\n\n/-\n1d. There is someone who doesn't like anyone.\n-/\n\ndef thereIsSomeoneWhoLikesNoOne : Prop :=\n  (∃ ( S : Person), ∀ P : Person, ¬Likes S P)\n\n/-\n1e. A predicate can be understood as defining \na relation. The pairs in the relation defined\nby the Likes predicate are all of those pairs\nof persons, (p1, p2) such that \"Likes p1 p2\" is\ntrue. What you are to express formally here is \nthe proposition that \"Likes is symmetric.\"\n-/\ndef likesIsSymmetric : Prop :=\n  ∀ p1 p2 : Person, Likes p1 p2 ↔ Likes p2 p1\n\n\n/-\n2. [5 points] Define a new predicate, LikedBy, \ntrue for Persons p1 and p2 if \"Likes p1 p2\". \nRemember that we formalize a predicate as a \nfunction. You should use the Likes predicate \nin formulating your answer.\n-/\n\ndef LikedBy (p2 p1 : Person) : Prop :=\n  Likes p1 p2\n\n/-\n\n3. [10 points] \nYou are to prove that \"if there is someone who\nnobody likes, then if Likes is also a symmetric \nrelation, then there is someone who doesn't like \nanybody.\" Give your formal proof in place of the \nhole.\n\nNote: When you introduce the premises, they\nwill appear in your context with the name of\nthe enclosing \"quantifiers\" namespace attached. \nE.g., you'll see \"quantifiers.likesIsSymmetric\". \nIf/when you want to use such a value, leave off \nthe name of the namespace. For example, you \nwould simply refer to the preceding value as \nlikesIsSymmetric.\n-/\nopen classical \n\nexample : \n    thereIsSomeoneNobodyLikes → \n    likesIsSymmetric →\n    thereIsSomeoneWhoLikesNoOne\n:=\nbegin\n  assume SNL,\n  assume LIS,\n  apply exists.elim SNL,\n  assume S,\n  assume Pfunc,\n  -- have Sfunc := Pfunc S,\n  apply exists.intro,\n    assume P,\n    assume like,\n    have likeo := LIS S P,\n    have likesp := likeo.1,\n    have likeps := likesp like,\n    have pf := Pfunc P,\n    exact pf likeps,\n    -- cases em (Likes P S) with l nl,\n    --   contradiction,\n    --   assume l,\n    --   have Ls := LIS S P,\n    --   have PS := Ls l,\n    --   contradiction,\nend\n\n-- end of quantifiers namespace\nend quantifiers\n\n\n\n/- \n4. [10 points] Implication and bi-implication\n\nProve each of the following propositions. Hint: Don't get distracted\nby seemingly confusing complexities. Just focus on the overall form \nand content of the propositions to be proved.\n-/\n\n-- 4a. Note: the conjecture to be proved is an implication.\nexample : \n(¬ ∃ (a b c n : ℕ), a > 0 ∧ b > 0 ∧ c > 0 ∧ n > 2 ∧ a^n + b^n = c^n) →\n1 + 1 = 2 :=\nbegin\n  assume func,\n  exact rfl,\nend \n\n-- 4b.\nexample : \n1 + 1 = 0 → \n(¬ ∃ (a b c n : ℕ), a > 0 ∧ b > 0 ∧ c > 0 ∧ n > 2 ∧ a^n + b^n = c^n) :=\nbegin\n  assume ooz,\n  assume func,\n  have contra : 1 + 1 ≠ 0 :=\n    begin\n      apply nat.no_confusion,\n    end,\n  contradiction,\nend\n\n\n/-\nExtra Credit [2 points[]]. What is the common name for the conjecture,\n¬ ∃ (a b c n : ℕ), a > 0 ∧ b > 0 ∧ c > 0 ∧ n > 2 → a^n + b^n = c^n.\n\nYour Answer: Fermat's Last Theorem\n\n-/\n\n\n\n-- 4c. [15 points] Prove that conjunction is associative.\n\nexample : ∀ (P Q R : Prop), P ∧ Q ∧ R ↔ (P ∧ Q) ∧ R :=\nbegin\n  intros P Q R,\n  apply iff.intro,\n    assume pqr,\n      have p := pqr.1,\n      have q := pqr.2.1,\n      have r := pqr.2.2,\n      exact and.intro (and.intro p q) r,\n    assume paqr,\n      have paq := paqr.1,\n      have r := paqr.2,\n      have p := paq.1,\n      have q := paq.2,\n      exact and.intro p (and.intro q r),\nend\n\n\n/-\n5. [20 points] Boolean Satisfiability.\n-/\n\n-- 5a. Find a solution; the only witnesses you may use are true and false.\n\nexample : ∃ (P Q : Prop), ((P ∧ ¬ Q) ∨ (Q ∧ ¬ P)) ∧ ¬ Q :=\nbegin\n  apply exists.intro true,\n  apply exists.intro false,\n  split,\n    apply or.inl,\n      split,\n        exact true.intro,\n        exact false.elim,\n      exact false.elim,\nend\n\n-- 5b. Show there is no satisfying solution for the following formula.\nopen classical\n\nexample : ¬ ∃ (P Q : Prop), ((P ∧ ¬ Q) ∨ (Q ∧ ¬ P)) ∧ ¬ (Q ∨ P) :=\nbegin\n  assume func,\n  apply exists.elim func,\n  assume P,\n  assume Pf,\n  apply exists.elim Pf,\n  assume Q,\n  assume Qf,\n  cases Qf with q1 q2,\n    cases q1 with qq q3,\n      have p := qq.1,\n      have f : false := q2 (or.inr p),\n      exact f,\n      have q := q3.1,\n      have f : false := q2 (or.inl q),\n      exact f,\n  -- cases em P with p np,\n  --   cases em Q with q nq,\n  --     have nqop := Qf.2,\n  --     have f : false := nqop (or.inl q),\n  --     exact f,\n  --     have nqop := Qf.2,\n  --     have f : false := nqop (or.inr p),\n  --     exact f,\n  --     cases em Q with q nq,\n  --     have nqop := Qf.2,\n  --     have f : false := nqop(or.inl q),\n  --     exact f,\n  --     have pnqqnp := Qf.1,\n  --     cases pnqqnp with pnq qnp,\n  --     have p := pnq.1,\n  --     exact np p,\n  --     have q := qnp.1,\n  --     exact nq q,\nend\n\n\n/-\n6. [10 points] Classical reasoning. Prove the following conjecture.\nYou may use the axiom of the excluded middle.\n-/\n\nopen classical\n\nexample: ∀(A B: Prop),\n  ¬(A ∧ B) → (¬A ∨ ¬B) :=\nbegin\n  intros A B,\n  assume nab,\n  cases em A with a na,\n    cases em B with b nb,\n      have f : false := nab (and.intro a b),\n      exact false.elim f,\n      exact or.inr nb,\n      exact or.inl na,\nend", "meta": {"author": "justinqcai", "repo": "CS2102", "sha": "d309f0db3f1df52eb77206ee1e8665a3b49d7a0c", "save_path": "github-repos/lean/justinqcai-CS2102", "path": "github-repos/lean/justinqcai-CS2102/CS2102-d309f0db3f1df52eb77206ee1e8665a3b49d7a0c/exam2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8887588052782736, "lm_q1q2_score": 0.7783633974939087}}
{"text": "-- La_suma_de_los_n_primeros_impares_es_n^2.lean\n-- La suma de los n primeros impares es n^2.\n-- José A. Alonso Jiménez\n-- Sevilla, 3 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, se puede definir el n-ésimo número primo por\n--    def impar (n : ℕ) := 2 * n + 1\n-- Además, en la librería finset están definidas las funciones\n--    range :: ℕ → finset ℕ\n--    sum :: finset α → (α → β) → β\n-- tales que\n-- + (range n) es el conjunto de los n primeros números naturales. Por\n--   ejemplo, el valor de (range 3) es {0, 1, 2}.\n-- + (sum A f) es la suma del conjunto obtenido aplicando la función f a\n--   los elementos del conjunto finito A. Por ejemplo, el valor de\n--   (sum (range 3) impar) es 9.\n--\n-- Demostrar que la suma de los n primeros números impares es n².\n-- ---------------------------------------------------------------------\n\nimport data.finset\nimport tactic.ring\nopen nat\n\nset_option pp.structure_projections false\n\nvariable (n : ℕ)\n\ndef impar (n : ℕ) := 2 * n + 1\n\n-- 1ª demostración\nexample :\n  finset.sum (finset.range n) impar = n ^ 2 :=\nbegin\n  induction n with m HI,\n  { calc finset.sum (finset.range 0) impar\n          = 0\n            : by simp\n     ...  = 0 ^ 2\n            : rfl, },\n  { calc finset.sum (finset.range (succ m)) impar\n         = finset.sum (finset.range m) impar + impar m\n           : finset.sum_range_succ impar m\n     ... = m ^ 2 + impar m\n           : congr_arg2 (+) HI rfl\n     ... = m ^ 2 + 2 * m + 1\n           : rfl\n     ... = (m + 1) ^ 2\n           : by ring_nf\n     ... = succ m ^ 2\n           : rfl },\nend\n\n-- 2ª demostración\nexample :\n  finset.sum (finset.range n) impar = n ^ 2 :=\nbegin\n  induction n with d hd,\n  { refl, },\n  { rw finset.sum_range_succ,\n    rw hd,\n    change d ^ 2 + (2 * d + 1) = (d + 1) ^ 2,\n    ring_nf, },\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/La_suma_de_los_n_primeros_impares_es_n^2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8670357598021708, "lm_q1q2_score": 0.7783339196631253}}
{"text": "import data.nat.basic\nimport tactic.interval_cases\n\nopen nat\n\nvariable {n : ℕ}\n\n-- 1ª demostración\nexample :\n  (n % 3 = 0) ∨ (n % 3 = 1) ∨ (n % 3 = 2) :=\nbegin\n  induction n with n hn,\n  { exact or.inl (zero_mod 3), },\n  { rw [succ_eq_add_one, add_mod],\n    cases hn with hn hn,\n    { rw hn,\n      exact or.inr (or.inl rfl) },\n    { cases hn with hn hn,\n      { rw hn,\n        exact or.inr (or.inr rfl) },\n      { rw hn,\n        exact or.inl rfl }}},\nend\n\n-- 1ª demostración\nexample :\n  (n % 3 = 0) ∨ (n % 3 = 1) ∨ (n % 3 = 2) :=\nbegin\n  induction n with n hn,\n  { exact or.inl (zero_mod 3), },\n  { rw [succ_eq_add_one, add_mod],\n    rcases hn with hn | hn | hn;\n      { rw hn, tauto }},\nend\n\n-- 3ª solución\nexample :\n  (n % 3 = 0) ∨ (n % 3 = 1) ∨ (n % 3 = 2) :=\nbegin\n  have : n % 3 < 3 := mod_lt n zero_lt_three,\n  interval_cases n % 3; tauto,\nend\n\n-- 4ª demostración\nexample :\n  (n % 3 = 0) ∨ (n % 3 = 1) ∨ (n % 3 = 2) :=\nmatch n % 3, @nat.mod_lt n 3 dec_trivial with\n| 0,   _ := or.inl rfl\n| 1,   _ := or.inr $ or.inl rfl\n| 2,   _ := or.inr $ or.inr rfl\n| k+3, h := absurd h dec_trivial\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/Divisibilidad_por_tres.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7782215779191598}}
{"text": "import game.order.level09\nimport data.real.basic -- imports the real numbers ℝ\n\nnamespace xena -- hide\n\n-- World name : Sup and Inf\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 1 : Upper bounds\n-/\n\n/-\nLet $X$ be a set of real numbers.\n\nWe say a real number $b$ is an *upper bound* for $X$ if every $x \\in X$ is at most $b$.\n-/\n\ndefinition is_upper_bound (S : set ℝ) (x : ℝ) := ∀ s ∈ S, s ≤ x \n\n/-\nHere is an easy fact about upper bounds, which we shall prove below: \nIf $X \\subseteq Y$ are two sets of reals, and $b$ is an upper bound for $Y$, \nthen it's also an upper bound for $X$.\n\nYou can prove this easily in Lean using the `change` tactic. \n-/\n\n/- Lemma\nIf $X \\subseteq Y$ are two sets of reals, and $b$ is an upper bound for $Y$, \nthen it's also an upper bound for $X$.\n-/\nlemma upper_bounds_mono (X Y : set ℝ) (h1 : X ⊆ Y) (b : ℝ) : is_upper_bound Y b → is_upper_bound X b :=\nbegin\n  intro h,\n  intro j,\n  intro k,\n  apply h,\n  change ∀j, j ∈ X → j ∈ Y at h1,\n  apply h1,\n  exact k,\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/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7781867743387445}}
{"text": "import data.real.basic\n\n-- now we have the field of real numbers\n\n-- So now we can build the complex numbers as an ordered pair of reals.\nstructure complex : Type :=\n(re' : ℝ) (im' : ℝ)\n\nnotation `ℂ` := complex\n\nnamespace complex\n\n-- now some computer science boilerplate.\n\n-- First define the two projections from the complexes back to the reals.\n-- These are great examples of \"eliminators\" -- functions on the complex numbers.\ndefinition re : ℂ → ℝ\n| ⟨x, y⟩ := x\n\ndefinition im : ℂ → ℝ\n| ⟨x, y⟩ := y\n\n-- You can also use this ⟨x, y⟩ notation to make the constructor.\n-- Here the 0's are (0 : ℝ)\ndefinition zero : ℂ := ⟨0, 0⟩\n\n-- zero notation\ninstance : has_zero ℂ := ⟨complex.zero⟩\n\n#check (0 : ℂ) -- now works\n\n-- how to make 3 + 4i\nexample : ℂ := ⟨3, 4⟩\n\n-- Now we should prove that the constructor applied to the eliminators\n-- gets us back to where we started.\ntheorem eta (z : ℂ) : (⟨re z, im z⟩ : ℂ) = 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.\ntheorem ext (z w : ℂ) (Hre : re z = re w) (Him : im z = im w) :\nz = w := \nbegin\n  cases w with x y,\n  rw ←eta z,\n  -- this is the goal now:\n  show (⟨re z, im z⟩ : ℂ) = ⟨x, y⟩,\n  rw Hre,\n  rw Him,\n  -- the goal is now true by definition\n  show (⟨x, y⟩ : ℂ) = ⟨x, y⟩,\n  refl\nend\n\n-- complex conjugation is a great example of seeing the constructor\n-- and eliminator both in action.\ndefinition conj : ℂ → ℂ\n| ⟨x, y⟩ := ⟨x, -y⟩\n\ndefinition add : ℂ → ℂ → ℂ := sorry -- try filling this in\n\n-- add the notation\ninstance : has_add ℂ := ⟨complex.add⟩\n\ndefinition mul : ℂ → ℂ → ℂ := sorry -- try filling this in\n\n-- add the notation\ninstance : has_mul ℂ := ⟨complex.mul⟩\n\n-- Can you prove this?\ntheorem add_mul (a b c : ℂ) :\n(a + b) * c = a * c + b * c := sorry\n\n-- Can you construct terms of these types?\n\ninstance : add_comm_group ℂ := sorry\n\ninstance : comm_ring ℂ := sorry\n\nend complex\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/complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7781867704226523}}
{"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 `ℍ := ℍ[ℝ]` of quaternions:\n\n* inner product space;\n* normed ring;\n* normed space over `ℝ`.\n\n## Notation\n\nThe following notation is available with `open_locale quaternion`:\n\n* `ℍ` : quaternions\n\n## Tags\n\nquaternion, normed ring, normed space, normed algebra\n-/\n\nlocalized \"notation `ℍ` := quaternion ℝ\" in quaternion\nopen_locale real_inner_product_space\n\nnoncomputable theory\n\nnamespace quaternion\n\ninstance : has_inner ℝ ℍ := ⟨λ a b, (a * b.conj).re⟩\n\nlemma inner_self (a : ℍ) : ⟪a, a⟫ = norm_sq a := rfl\n\nlemma inner_def (a b : ℍ) : ⟪a, b⟫ = (a * b.conj).re := rfl\n\ninstance : inner_product_space ℝ ℍ :=\ninner_product_space.of_core\n{ inner := has_inner.inner,\n  conj_sym := λ x y, by simp [inner_def, mul_comm],\n  nonneg_re := λ x, norm_sq_nonneg,\n  definite := λ x, norm_sq_eq_zero.1,\n  add_left := λ x y z, by simp only [inner_def, add_mul, add_re],\n  smul_left := λ x y r, by simp [inner_def] }\n\nlemma norm_sq_eq_norm_sq (a : ℍ) : norm_sq a = ∥a∥ * ∥a∥ :=\nby rw [← inner_self, real_inner_self_eq_norm_mul_norm]\n\ninstance : norm_one_class ℍ :=\n⟨by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]⟩\n\n@[simp, norm_cast] lemma norm_coe (a : ℝ) : ∥(a : ℍ)∥ = ∥a∥ :=\nby rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_coe, real.sqrt_sq_eq_abs, real.norm_eq_abs]\n\nnoncomputable instance : normed_division_ring ℍ :=\n{ dist_eq := λ _ _, rfl,\n  norm_mul' := λ 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 ℝ ℍ :=\n{ norm_algebra_map_eq := norm_coe,\n  to_algebra := quaternion.algebra }\n\ninstance : has_coe ℂ ℍ := ⟨λ z, ⟨z.re, z.im, 0, 0⟩⟩\n\n@[simp, norm_cast] \n\n@[simp, norm_cast] lemma coe_complex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_zero : ((0 : ℂ) : ℍ) = 0 := rfl\n@[simp, norm_cast] lemma coe_complex_one : ((1 : ℂ) : ℍ) = 1 := rfl\n@[simp, norm_cast] lemma coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z :=\nby ext; simp\n@[simp, norm_cast] lemma coe_complex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl\n\n/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/\ndef of_complex : ℂ →ₐ[ℝ] ℍ :=\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' := λ x, rfl }\n\n@[simp] lemma coe_of_complex : ⇑of_complex = coe := rfl\n\nend quaternion\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/quaternion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7780679715882578}}
{"text": "/-\nProof strategies.\n\n- direct proof: use established facts\n\n- by negation: to prove ¬ P, assume P;\n  show that this yields a contradiction,\n  from which a proof of false can then \n  be derived. This shows P → false, and\n  that is the definition of ¬ P.\n\n  - by contradiction : to prove P, assume\n    ¬ P and show that this leads to a\n    contradiction, from which a proof of\n    false can be derived. This proves\n    ¬ P → false, which is equivalent to\n    ¬ ¬ P. The apply the *classical* rule\n    of negation elimination to deduce P.with\n\n- Classical rule of negation elimination:\n  ∀ (P : Prop), ¬ ¬ P ¬ P\n\n  Prove 0 = 0 by contradiction\n\n  We want to prove P (0 = 0). Assume ¬ 0 = 0,\n  and show that this leads to a contradiction. But by the\n  reflexive property of equality, which says everything is equal to itself,\n  we know timmedate that 0 = 0. That gives us a direct contradiction\n  between ¬ (0 = 0) and (0 = 0). From such a contradiction we\n  can derive a proof of false, showing that ¬ (0 = 0) → false.\n  And this just means ¬ (0 = 0). Then by the classical negation\n  elimination, this imlies 0 = 0.\n\n    - Today: proof by induction.\n-/\n\n-- Answer to question about why contradictions imply false\naxiom P : Prop\naxiom p : P\naxiom np : ¬ P -- P → false\n#check np p\n\n\n/-\nProof by negation english language example\n\nProve that the square root of two is NOT rational\n\nProve ¬ sqrt(2) is rational.#check\n\nProof:\nAssume sqrt(2) is rational. In this case, we can write sqrt(2)\nas some fraction a/b. We now want to show that this leads to\na contradiction...\n\nProof by negation ≠ proof by contradiction\n\n-/\n\n/-\n\nProve this: ∀ (m : ℕ), 0 + m = m\n\nProof: By the definition of addition,\nand specifically by the first of the\ntwo cases, which tells us that for any\nm, 0 + m = m. \n\n-/\n\ndef my_add : ℕ → ℕ → ℕ \n| nat.zero m := m\n| (nat.succ n') m := nat.succ (my_add n' m)\n\n-- 0 + m = m\n-- (1 + n') + m = 1 + (n' + m)\n\n/-\nNot needed for final\n\nexample : ∀ (m : ℕ), my_add 0 m = m\n| _ := by simp [my_add]\n-/\n\n/-\nMany proofs are accomplished by mere\nsimplification of both sides of some\nequation *using function definitions*\nthat are already known. \n-/\n\n/-\nIf one is being precise, however, there\nare some unexpected consequences. One is\nthat sometimes something that looks easy\nturns out to be a bit more complicated.\n\nFor example, try to prove this (using)\nonly what we know so far.\n-/\n\nexample : ∀ (n : ℕ), my_add n 0 = n\n| _ := by simp [my_add]\n\n/-\nWe have no rule (yet) for adding zero \non the right, so simplifying using the\ndefinition of my_add doesn't work.with\nInstead, we need to try a whole different\nproof strategy.\n-/\n\n/-\nHere's the idea: \n\n- every inductively defined type has a\n  corresponding induction rule\n\n- It's a rule for showing that some\n  proposition is true for *every* value\n  of the given type\n\n- The induction principle for ℕ is this:\n  ∀ P : ℕ → Prop,\n  P 0 → \n  ((∀ n' : ℕ), P n' → P (nat.succ n')) → \n  ∀ n, P n\n\nIn other words, for any predicate/property\nP, to show ∀ (n : ℕ), P n, it *suffices* \nto show the following: \n    (1) P 0, \n    (2) (∀ n' : ℕ), P n' → P (nat.succ n')\n-/\n\n/-\nExample: We want to prove ∀ n, n + 0 = n.\n(1) Case: n = 0. By first rule of my_add.\n(2) Case: n = nat.succ n': \n    Show P n' → P (nat.succ n').\n    What does P n' say? my_add n' 0 = n'\n    So *assume* P n', now show P (nat.succ n')\n    That is, show (my_add (nat.succ n') 0 = (nat.succ n')) \n\n    Using my_add\n    Simp: nat.succ (my_add n' 0) = nat.succ n'\n    Apply induction hypothesis: nat.succ n' = nat.succ n'\n    Finish by reflexive property of equality\n-/\n\n/-\nSum numbers from 0 to n is n * (succ n) / 2.\n\nProof by induction. We will apply the principle of induction\nfor the natural numbers to two smaller proofs: one for n = 0,\nand one that shows that if the formula is true for some n > 0,\nthen it must also be true succ n'.\n\nBase case: prove (P 0): show sum from 0 to 0 = (0 * 1)/ 2 = 0\nInductive case: Show P n' → P (n' + 1)\nAssume P n'. The sum from 0 to n' = n' * (n' + 1) / 2.\nShow (P (n' + 1)): \nThe sum from 0 to n'++1 = (n' + 1)((n' +1)+1)/2.\n\n1+2+3+4+5 if we assume this is 5*6/2\n(1+2+3+4+5)+6 show this is 6*7/2\nsum 0 to 5 + 6! = 5*6/2 +6\n\nThe sum from 0 to (n' + 1) = sum from 0 to n' + (n' + 1)\n                           = (n'*(n+1)/2) + (n' + 1)\n                           ...\n                           = (n' + 1)((n'+1)+1)/2\n\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/hw9/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7780679674690867}}
{"text": "import tactic.linarith\n\nnamespace mth1001\n\nsection negating_quantifiers \n\n/-\nWe *can* deal with negated quantified statements using `intro`, as we did before for other\nnegated statements.\n-/\n\n-- Exercise 081:\n-- Finish the proof below using `specialize` and `linarith`.\n-- *Note*, `linarith` can prove `false` if there is a contradiction amongst the premises.\nexample : ¬(∀ x : ℤ, 2 * x + 6 = 0) :=\nbegin \n  intro h,\n  sorry  \nend\n\n/-\nA more natural approach is to recognise that `¬(∀ x, P x)` can always be rewritten as\n`∃ x, ¬(P x)`, where `P` is any function (more accurately a *predicate*) depending on `x`.\nThe Lean tactic `push_neg`, which we've seen before, accomplishes this transformation.\n-/\n\n-- Exercise 082:\n-- Below, `push_neg` transforms the goal into `∃ x : ℤ, 2 * x + 6 ≠ 0`.\nexample : ¬(∀ x : ℤ, 2 * x + 6 = 0) :=\nbegin \n  push_neg,\n  sorry  \nend\n\n-- Exercise 083:\n-- Solve the following using `push_neg`\nexample : ¬(∀ x : ℤ, x > 5) := \nbegin \n  sorry  \nend \n\n\n/-\nNegating existential quantifiers follows a similar principle. We begin by using `intro`.\n-/\n\n\n-- Exercise 084:\n-- Use `cases` and `linarith` to prove the following result.\nexample : ¬(∃ x : ℤ, (x + 2 ≥ 3) ∧ (2 * x + 10 ≤ 8)) :=\nbegin \n  intro h,\n  sorry  \nend \n\n-- Exercise 085:\n/-\nAn alternative approach is to recognise that `¬(∃ x, P x)` is equivalent to `∀ x, ¬(P x)`.\n\nLean offers this method via `push_neg`. Finish the proof below.\n-/\nexample : ¬(∃ x : ℤ, (x + 2 ≥ 3) ∧ (2 * x + 10 ≤ 8)) :=\nbegin \n  push_neg,\n  intro x,\n  by_cases h : x + 2 < 3,\n  { sorry, }, \n  { sorry, }, \nend\n\nend negating_quantifiers\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_15_negating_quantifiers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.778067965043668}}
{"text": "import betweenness_world.level03 --hide\nopen IncidencePlane --hide\n\n\n/-\n# Betweenness World\n\n## Level 4: another version of the previous level...\n\nTo solve this level, the mathematical proof in paper will be given to you **inside the Hint Box** (right below). \nRemember that you can use theorem statements from previous worlds. Make an effort to write the proof by your own. \nYou may find the proof of the previous level very helpful for this one.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\n**Claim:** Given two different collinear points A and B, there is a third C that shares the same line with them and satisfies A * B * C.\n\n**Proof:** Let `r` be the line that is incident with the points A and B.\n\n**(i)** Let us assume that A ≠ B ∧ A ≠ C ∧ B ≠ C. By the first axiom of order `different_of_between`, since A * B * C, then we prove that \nA ≠ B ∧ A ≠ C ∧ B ≠ C.\n \n**(ii)** Let us assume that ∃ ℓ, such that A ∈ ℓ ∧ B ∈ ℓ ∧ C ∈ ℓ. By the first axiom of order `collinear_of_between`, since A * B * C, then \nwe prove that ∃ ℓ, such that A ∈ ℓ ∧ B ∈ ℓ ∧ C ∈ ℓ. Let this line be called `s`. Then, A ∈ s ∧ B ∈ s ∧ C ∈ s.\n\n**(iii)** Let us assume that r = s. By the lemma `equal_lines_of_contain_two_points`, since A ≠ B, A ∈ r, A ∈ s, B ∈ r and B ∈ s, then we prove that\nr = s. Because C ∈ s, which we proved in **(ii)**, and r = s, then we prove that C ∈ r. \n\nHence, we have shown that given two different collinear points A and B, there is a third C that shares the same line with them and satisfies A * B * C.\n\nStill bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution.\n-/\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\nvariables {A B C P Q R : Ω} --hide\nvariables {ℓ r s t : Line Ω} --hide\n\n/- Lemma :\nGiven two different collinear points A and B, there is a third C that shares the same line with them and satisfies A * B * C.\n-/\nlemma between_points_share_line_v2 (hAr : A ∈ r) (hBr : B ∈ r) : \n\t(A * B * C) → C ∈ r :=\nbegin\n    intro H,\n    have h1 : A ≠ B ∧ A ≠ C ∧ B ≠ C,\n    {\n        exact different_of_between H,\n    },\n    have h2 : ∃ ℓ, A ∈ ℓ ∧ B ∈ ℓ ∧ C ∈ ℓ,\n    { \n        apply collinear_of_between,\n        exact H,\n    },\n    cases h2 with s hs,\n    have h3 : r = s,\n    {\n        exact equal_lines_of_contain_two_points h1.1 hAr hs.1 hBr hs.2.1,\n    },\n    rw h3,\n    exact hs.2.2,\n\t\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/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7780053249917789}}
{"text": "/- TACTICS -/\n\nnamespace TBA\n\n-- definitions from last week\n-- NOTE: We renamed it from `Nat'` for consistency. The new namespace makes sure we don't use the\n-- standard library `Nat`.\ninductive Nat : Type where\n  | zero : Nat\n  | succ (n : Nat) : Nat\n\nopen Nat\n\ndef add (m n : Nat) : Nat :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\n-- With this command we add a notation for `add`. From now on we will be able to write `m + n` for\n-- `add m n`. The 65 denotes how strongly the operator should bind to what's adjacent to it.\n-- The `priority` means that Lean will prefer it over the built-in `+`.\ninfix:65 (priority := high) \" + \" => add\n\ndef mul (m n : Nat) : Nat :=\n  match n with\n  | zero   => zero\n  | succ n => (mul m n) + m\n\n-- We also want a notation for `mul`, with a higher binding strength than addition so that\n-- `a + b * c` means `a + (b * c`)`.\ninfix:70 (priority := high) \" * \" => mul\n\ninductive LE : Nat → Nat → Prop where\n  | refl (n : Nat) : LE n n\n  | succ : LE m n → LE m (succ n)\n\n-- lower binding strength than either addition or multiplication\ninfix:50 (priority := high) \" ≤ \" => LE\n\n-- Let's start by reproving some theorems from last week, but this time with tactics!\n-- useful tactics:\n-- * `induction ... with ...`\n-- * `rw [f]` to unfold applications of a function `f`\n-- * `rw [h]` to rewrite every `a` to `b` if `h : a = b`\n-- * `apply/exact`\n-- * `simp/simp_all`... are powerful and basically always useful, though make sure that you could also\n--   do the proof without them\ntheorem zero_add : zero + n = n := by\n  induction n with\n  | zero      =>\n  | succ n ih =>\n\ntheorem le_add : m ≤ m + n := by\n\n-- Alright, let's start automating more!\nattribute [simp] add mul\n-- These definitions will now automatically be unfolded when you use `simp/simp_all`\n\n\n-- This one is a bit more tricky, you might need to prove a helper lemma!\ntheorem add_comm : n + m = m + n := by\n\n-- Associativity can be proven in a similar way.\ntheorem add_assoc : (m + n) + k = m + (n + k) := by\n\ndef one := succ zero\n\ntheorem mul_one : m * one = m := by\n\n-- To prove associativity of multiplication, you might have to come up with\n-- some more lemmas about multiplication first. Some are similar to the above laws of\n-- addition, some use both addition and multiplication (\"distributivity\" is the keyword).\n\ntheorem mul_assoc : (m * n) * k = m * (n * k) := by \n\n-- Remember the structures for semigroups and monoids which we defined last week?\nstructure Semigroup (α : Type) where\n  mul   : α → α → α\n  assoc : mul (mul a b) c = mul a (mul b c)\n\nstructure Monoid (α : Type) extends Semigroup α where\n  e     : α\n  e_mul : mul e a = a\n  mul_e : mul a e = a\n\n\n-- You should now be able to instantiate two of them, including proofs!\ndef Nat_add_Monoid : Monoid Nat := _\n\ndef Nat_mul_Monoid : Monoid Nat := _\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/Exercise4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8723473862936942, "lm_q1q2_score": 0.7779690370640165}}
{"text": "-- Producto_por_funcion_acotada_superiormente.lean\n-- Si c ≥ 0 y f está acotada superiormente, entonces c * f también lo está.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 30-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si c ≥ 0 y f está acotada superiormente, entonces c * f\n-- también lo está.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {f : ℝ → ℝ}\nvariables {a c : ℝ}\n\n-- (cota_superior f a) se verifica si a es una cota superior de f.\ndef cota_superior (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, f x ≤ a\n\n-- (acotada_sup f) se verifica si f tiene cota superior.\ndef acotada_sup (f : ℝ → ℝ) := ∃ a, cota_superior f a\n\n-- Lema auxiliar\n-- ============\n\nlemma cota_superior_mul\n  (hfa : cota_superior f a)\n  (h : c ≥ 0)\n  : cota_superior (λ x, c * f x) (c * a) :=\nλ x, mul_le_mul_of_nonneg_left (hfa x) h\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (hf : acotada_sup f)\n  (h : c ≥ 0)\n  : acotada_sup (λ x, c * f x) :=\nbegin\n  cases hf with a ha,\n  have h1 : cota_superior (λ x, c * f x) (c * a) := cota_superior_mul ha h,\n  have h2 : ∃ z, ∀ x, (λ x, c * f x) x ≤ z,\n    by exact Exists.intro (c * a) h1,\n  show acotada_sup (λ x, c * f x),\n    by exact h2,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (hf : acotada_sup f)\n  (h : c ≥ 0)\n  : acotada_sup (λ x, c * f x) :=\nbegin\n  cases hf with a ha,\n  use c * a,\n  apply cota_superior_mul ha h,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (hf : acotada_sup f)\n  (h : c ≥ 0)\n  : acotada_sup (λ x, c * f x) :=\nbegin\n  rcases hf with ⟨a, ha⟩,\n  exact ⟨c * a, cota_superior_mul ha h⟩,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample\n  (h : c ≥ 0)\n  : acotada_sup f → acotada_sup (λ x, c * f x) :=\nbegin\n  rintro ⟨a, ha⟩,\n  exact ⟨c * a, cota_superior_mul ha h⟩,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample\n  (h : c ≥ 0)\n  : acotada_sup f → acotada_sup (λ x, c * f x) :=\nλ ⟨a, ha⟩, ⟨c * a, cota_superior_mul ha h⟩\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_por_funcion_acotada_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8918110504699677, "lm_q1q2_score": 0.7779690167478425}}
{"text": "import tactic\nimport data.zmod.basic\nimport field_theory.finite.basic\n/-\n\n# Prove the theorem, due to Kraichik, asserting that 13|2^70+3^70\n\nThis is the sixth question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\n-/\n\nexample : 13 ∣ 2^70 + 3^70 :=\nbegin\n  use 192550423461109399456637645953021,\n  norm_num,\nend\n\n\n/-\n\nthoughts\n\n2,4,8,3,6,12=-1,-2,-4,-8,-3,-6,1 2^12=1 mod 13\n\n3,9,1\n-/\n\nexample : 13 ∣ 2^70 + 3^70 :=\nbegin\n  rw ← zmod.nat_coe_zmod_eq_zero_iff_dvd,\n  push_cast,\n  change (2 : zmod 13) ^ 70 + (3 : zmod 13) ^ 70 = 0,\n  have h0 : nat.prime 13 := by norm_num,\n  haveI : fact (nat.prime 13) := ⟨h0⟩,\n  have h1 : (2 : zmod 13)^12 = 1,\n  { apply zmod.pow_card_sub_one_eq_one,\n    intro h2,\n    have h3 : ((2 : ℕ) : zmod 13) = 0,\n      assumption_mod_cast,\n    rw zmod.nat_coe_zmod_eq_zero_iff_dvd at h3,\n    revert h3,\n    norm_num,\n  },\n  have h2 : (3 : zmod 13)^3 = 1,\n    refl,\n  conv_lhs begin\n    congr,\n    rw (show 70 = 12 * 5 + 10, by norm_num),\n    skip,\n    rw (show 70 = 3 * 23 + 1, by norm_num),\n  end,\n  rw [pow_add, pow_add, pow_mul, pow_mul, h1, h2],\n  simp,\n  refl,\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/example06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7779662983668291}}
{"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* `→` (\"implies\" -- type with `\\l`)\n* `¬` (\"not\" -- type with `\\not` or `\\n`)\n* `∧` (\"and\" -- type with `\\and` or `\\an`)\n* `↔` (\"iff\" -- type with `\\iff` or `\\lr`)\n* `∨` (\"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 (→)\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 → P :=\nbegin\n  -- Prove this using `intro` and `exact`\n  sorry\nend\n\n/-\nNote that → isn't associative!\nTry working out `false → (false → false) and (false → false) → false\n-/\n\nexample : (false → (false → false)) ↔ true := by simp\nexample : ((false → false) → false) ↔ false := by simp\n\n-- in Lean, `P → Q → R` is _defined_ to mean `P → (Q → R)`\n-- Here's a proof of what I just said.\nexample : (P → Q → R) ↔ (P → (Q → R)) :=\nbegin\n  -- look at the goal!\n  refl -- true because ↔ is reflexive\nend\n\ntheorem imp_intro : P → Q → P :=\nbegin\n  -- remember that by definition the goal is P → (Q → P).\n  -- Prove this proposition using `intro` and `exact`.\n  -- Experiment. Can you prove it using `intros` and `assumption`?\n  sorry\nend\n\n/-- If we know `P`, and we also know `P → Q`, we can deduce `Q`. -/\nlemma modus_ponens : P → (P → Q) → Q :=\nbegin\n  -- You might find the `apply` tactic useful here.\n  sorry\nend\n\n/-- implication is transitive -/\nlemma imp_trans : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  -- The tactics you know should be enough\n  sorry\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 → Q → R) → (P → Q) → (P → R) :=\nbegin\n  -- `intros hPQR hPQ hP,` would be a fast way to start.\n  -- Make sure you understand what is going on there, if you use it.\n  sorry\nend\n\n/-\n\n### not\n\n`not P`, with notation `¬ P`, is *defined* to mean `P → false` in Lean,\ni.e., the proposition that P implies false. You can easily check with\na truth table that P → false and ¬ P are equivalent.\n\nWe develop a basic interface for `¬`.\n-/\n\n\n-- I'll prove this one for you\ntheorem not_iff_imp_false : ¬ P ↔ (P → false) :=\nbegin\n  -- true by definition\n  refl\nend\n\ntheorem not_not_intro : P → ¬ (¬ P) :=\nbegin\n  intro hP,\n  rw not_iff_imp_false,\n  -- You can use `rw not_iff_imp_false` to change `¬ X` into `X → false`. \n  -- But you don't actually have to, because they are the same *by definition*\n  sorry,\nend\n\n-- Here is a funny alternative proof! Can you work out how it works?\nexample : P → ¬ (¬ 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 → ¬ (¬ P) :=\nλ hP hnP, hnP hP\n\n-- This is \"modus tollens\". Some mathematicians think of it as\n-- \"proof by contradiction\".\ntheorem modus_tollens : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  sorry,\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 : ¬ (¬ P) → P :=\nbegin\n  sorry,\nend\n\n/-!\n\n### and\n\nThe hypothesis `hPaQ : P ∧ 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 `⊢ P ∧ Q` as a goal, and want to turn the goal\ninto two goals `⊢ P` and `⊢ 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 ∧ 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 ∧ Q :=\nbegin\n  split,\n    exact hP,\n  exact hQ\nend\n```\n\n-/\n\ntheorem and.elim_left : P ∧ Q → P :=\nbegin\n  -- I would recommend starting with\n  -- `intro hPaQ,` and then `cases hPaQ with hP hQ`.\n  sorry\nend\n\ntheorem and.elim_right : P ∧ Q → Q :=\nbegin\n  sorry\nend\n\n-- fancy term mode proof\nexample : P ∧ Q → Q := λ hPaQ, hPaQ.2\n\ntheorem and.intro : P → Q → P ∧ Q :=\nbegin\n  -- remember the `split` tactic.\n  sorry\nend\n\n/-- the eliminator for `∧` -/ \ntheorem and.elim : P ∧ Q → (P → Q → R) → R :=\nbegin\n  sorry,\nend\n\n/-- The recursor for `∧` -/\ntheorem and.rec : (P → Q → R) → P ∧ Q → R :=\nbegin\n  sorry\nend\n\n/-- `∧` is symmetric -/\ntheorem and.symm : P ∧ Q → Q ∧ P :=\nbegin\n  sorry\nend\n\n-- term mode proof\nexample : P ∧ Q → Q ∧ P :=\nλ ⟨hP, hQ⟩, ⟨hQ, hP⟩\n\n/-- `∧` is transitive -/\ntheorem and.trans : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  -- The `rintro` tactic will do `intro` and `cases` all in one go.\n  -- If you like, try starting this proof with `rintro ⟨hP, hQ⟩` if you want\n  -- to experiment with it. Get the pointy brackets with `\\<` and `\\>`,\n  -- or both at once with `\\<>`.\n  sorry,\nend\n\n/-\nRecall that the convention for the implies sign →\nis that it is _right associative_, by which\nI mean that `P → Q → R` means `P → (Q → R)` by definition.\nNow note that if `P` implies `Q → R`\nthen this means that `P` and `Q` together, imply `R`,\nso `P → Q → R` is logically equivalent to `(P ∧ Q) → R`.\n\nWe proved that `P → Q → R` implied `(P ∧ Q) → R`; this was `and.rec`.\nLet's go the other way.\n-/\n\nlemma imp_imp_of_and_imp : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  sorry,\nend\n\n\n/-!\n\n### iff\n\nThe basic theory of `iff`.\n\nIn Lean, to prove `P ∧ Q` you have to prove `P` and `Q`.\nSimilarly, to prove `P ↔ Q` in Lean, you have to prove `P → Q`\nand `Q → P`. Just like `∧`, you can uses `cases h` if you have\na hypothesis `h : P ↔ Q`, and `split` if you have a goal `⊢ P ↔ Q`.\n-/\n\n/-- `P ↔ P` is true for all propositions `P`, i.e. `↔` is reflexive. -/\ntheorem iff.refl : P ↔ P :=\nbegin\n  -- start with `split`\n  sorry,\nend\n\n-- If you get stuck, there is always the \"truth table\" tactic `tauto!`\nexample : P ↔ P :=\nbegin\n  tauto!, -- the \"truth table\" tactic.\nend\n\n-- refl tactic also works\nexample : P ↔ P :=\nbegin\n  refl -- `refl` knows that `=` and `↔` are reflexive.\nend\n\n/-- `↔` is symmetric -/\ntheorem iff.symm : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  sorry\nend\n\n-- NB there is quite a devious proof of this using `rw`.\n\n-- show-off term mode proof\nexample : (P ↔ Q) → (Q ↔ P) :=\nλ ⟨hPQ, hQP⟩, ⟨hQP, hPQ⟩\n\n/-- `↔` is commutative -/\ntheorem iff.comm : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  sorry\nend\n\n-- without rw or cc this is painful!\n/-- `↔` is transitive -/\ntheorem iff.trans :  (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  sorry,\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 : ¬ (P ↔ ¬ P) :=\nbegin\n  sorry\nend\n\n-- Now we have iff we can go back to and.\n\n/-!\n### ↔ and ∧\n-/\n\n/-- `∧` is commutative -/\ntheorem and.comm : P ∧ Q ↔ Q ∧ P :=\nbegin\n  sorry,\nend\n\n-- fancy term-mode proof\nexample : P ∧ Q ↔ Q ∧ P :=\n⟨and.symm _ _, and.symm _ _⟩\n\n-- Note that ∧ is \"right associative\" in Lean, which means\n-- that `P ∧ Q ∧ R` is _defined to mean_ `P ∧ (Q ∧ R)`.\n-- Associativity can hence be written like this:\n/-- `∧` is associative -/\ntheorem and_assoc : ((P ∧ Q) ∧ R) ↔ (P ∧ Q ∧ R) :=\nbegin\n  sorry,\nend\n\n\n\n/-!\n\n## Or\n\n`P ∨ Q` is true when at least one of `P` and `Q` are true.\nHere is how to work with `∨` in Lean.\n\nIf you have a hypothesis `hPoQ : P ∨ 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 `⊢ P ∨ 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 → P ∨ Q :=\nbegin\n  sorry\nend\n\ntheorem or.intro_right : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\n/-- the eliminator for `∨`. -/\ntheorem or.elim : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  sorry\nend\n\n/-- `∨` is symmetric -/\ntheorem or.symm : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n/-- `∨` is commutative -/\ntheorem or.comm : P ∨ Q ↔ Q ∨ P :=\nbegin\n  sorry,\nend\n\n/-- `∨` is associative -/\ntheorem or.assoc : (P ∨ Q) ∨ R ↔ P ∨ Q ∨ R :=\nbegin\n  sorry,\nend\n\n/-!\n### More about → and ∨\n-/\n\ntheorem or.imp : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\ntheorem or.imp_left : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\ntheorem or.imp_right : (P → Q) → R ∨ P → R ∨ Q :=\nbegin\n  sorry,\nend\n\ntheorem or.left_comm : P ∨ Q ∨ R ↔ Q ∨ P ∨ R :=\nbegin\n  -- Try rewriting `or.comm` and `or.assoc` to do this one quickly.\n  sorry,\nend\n\n/-- the recursor for `∨` -/\ntheorem or.rec : (P → R) → (Q → R) → P ∨ Q → R :=\nbegin\n  sorry,\nend\n\ntheorem or_congr : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\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 ∧ 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 → P :=\nbegin\n  sorry,\nend\n\ntheorem and_true_iff : P ∧ true ↔ P :=\nbegin\n  sorry,\nend\n\ntheorem or_false_iff : P ∨ false ↔ P :=\nbegin\n  sorry,\nend\n\n-- false.elim is handy for this one\ntheorem or.resolve_left : P ∨ Q → ¬P → Q :=\nbegin\n  sorry,\nend\n\n-- this one you can't do constructively\ntheorem or_iff_not_imp_left : P ∨ Q ↔ ¬P → Q :=\nbegin\n  sorry,\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/Part_A_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7779662877392407}}
{"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 1 : ∪ ∩ ⊆ and all that\n\nLean doesn't have \"abstract\" sets, it only has *subsets* of a type. If `X : Type` is a type\nthen the type of subsets of `X` is called `set X`. A term `A : set X`\ncan be thought of in three ways:\n\n1) A set of elements of `X` (i.e. a set of elements all of which have type `X`);\n2) A subset of `X`;\n3) An element of the power set of `X`;\n4) A function from `X` to `Prop` (sending the elements of `A` to `true` and the other ones to `false`)\n\nSo `set X` could have been called `subset X` or `powerset X`; I guess they chose `set X`\nbecause it was the shortest.\n\nNote that `X` is a type, but `A` is a term; the type of `A` is `set X`. This means\nthat `a : A` doesn't make sense. What we say instead is `a : X` and `a ∈ A`. \nOf course `a ∈ A` is a true-false statement, so `a ∈ A : Prop`. \n\nAll the sets `A`, `B`, `C` etc we consider will be subsets of `X`. \nIf `x : X` then `x` may or may not be an element of `A`, `B`, `C`,\nbut it will always be a term of type `X`.\n\n-/\n\n-- set up variables\nvariables\n  (X : Type) -- Everything will be a subset of `X`\n  (A B C D : set X) -- A,B,C 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\n# subset (`⊆`), union (`∪`) and intersection (`∩`)\n\nHere are some mathematical facts:\n\n`A ⊆ B` is equivalent to `∀ x, x ∈ A → x ∈ B`;\n`x ∈ A ∪ B` is equivalent to `x ∈ A ∨ x ∈ B`;\n`x ∈ A ∩ B` is equivalent to `x ∈ A ∧ x ∈ B`. \n\nAll of these things are true *by definition* in Lean. Let's\ncheck this.\n\n-/\n\nlemma subset_def : A ⊆ B ↔ ∀ x, x ∈ A → x ∈ B :=\nbegin\n  -- ↔ is reflexive so `refl` works because LHS is defined to be equal to RHS\n  refl\nend\n\nlemma mem_union_iff : x ∈ A ∪ B ↔ x ∈ A ∨ x ∈ B :=\nbegin\n  refl\nend\n\nlemma mem_inter_iff : x ∈ A ∩ B ↔ x ∈ A ∧ x ∈ B :=\niff.rfl -- you don't even have to go into tactic mode to prove this\n\n/-\n\nSo now to change one side of these `↔`s to the other, you can\n`rw` the appropriate lemma, or you can just use `change`. Or\nyou can ask yourself whether you need to do this at all.\n\nLet's prove some theorems.\n\n-/\n\nexample : A ⊆ A :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → B ⊆ C → A ⊆ C :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ A ∪ B :=\nbegin\n  sorry,\nend\n\nexample : A ∩ B ⊆ A :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → A ⊆ C → A ⊆ (B ∩ C) :=\nbegin\n  sorry,\nend\n\nexample : B ⊆ A → C ⊆ A → B ∪ C ⊆ A :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → C ⊆ D → A ∪ C ⊆ B ∪ D :=\nbegin\n  sorry,\nend\n\nexample : A ⊆ B → C ⊆ D → A ∩ C ⊆ B ∩ D :=\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/section05sets/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7779662839222068}}
{"text": "import Analysis.Set.Basic\n\nnamespace Set\n\ndef image (f : α → β) (s : Set α) : Set β := { y : β | ∃ x ∈ s, y = f x }\n\ntheorem memImage {s : Set α} {f : α → β} (y : β) : \n  y ∈ s.image f ↔ ∃ x ∈ s, y = f x :=  Iff.rfl\n\ntheorem memImageOfMem {s : Set α} {f : α → β} {x : α} (hx : x ∈ s) : \n  f x ∈ s.image f := Exists.intro x ⟨hx, rfl⟩\n\ndef preimage (f : α → β) (s : Set β) : Set α := { x : α | f x ∈ s }\n\ntheorem memPreimage {s : Set β} {f : α → β} {x : α} : \n  x ∈ s.preimage f ↔ f x ∈ s := Iff.rfl\n\ntheorem preimageUniv (f : α → β) : univ.preimage f = univ := rfl\n\ntheorem preimageMono (f : α → β) {s t : Set β} (hst : s ⊆ t) : \n  s.preimage f ⊆ t.preimage f := \n  λ x hx => hst _ hx\n\ntheorem preimageInter (f : α → β) (s t : Set β) : \n  (s ∩ t).preimage f = s.preimage f ∩ t.preimage f := rfl\n\ntheorem preimageId (s : Set α) : preimage id s = s := rfl\n\nend Set", "meta": {"author": "JasonKYi", "repo": "analysis_in_lean4", "sha": "280d45bf2fc9c2f599b365a60a4b980bb2721c24", "save_path": "github-repos/lean/JasonKYi-analysis_in_lean4", "path": "github-repos/lean/JasonKYi-analysis_in_lean4/analysis_in_lean4-280d45bf2fc9c2f599b365a60a4b980bb2721c24/Analysis/Set/Function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7779662804046322}}
{"text": "section propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intros hp hpf, --\"Suponha P, ¬P\"\n  have hf : false := hpf hp, --\"Como P → ⊥ e P, logo ⊥\"\n  exact hf, --\"Imediato (tenho meu alvo nos meus dados)\"\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro hpf,\n  by_cases p : P,\n  exact p,\n  exfalso,\n  have hboom : false := hpf p,\n  exact hboom,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  apply doubleneg_elim,\n  apply doubleneg_intro,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro poq,\n  cases poq with hp hq,\n  right,\n  exact hp,\n  left,\n  exact hq,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro peq,\n  cases peq with hp hq,\n  split,\n  exact hq,\n  exact hp,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h_fp_or_q,\n  intro p,\n  cases h_fp_or_q with hp hq,\n  exfalso,\n  contradiction,\n  exact hq,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro h,\n  intro np,\n  cases h with hp hq,\n  exfalso,\n  contradiction,\n  exact hq,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros hpq hnq hp,\n  have hq := hpq hp,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros hnq_np p,\n  by_cases hq : Q,\n  exact hq,\n  exfalso,\n  have hnp := hnq_np hq,\n  have hboom := hnp p,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  apply impl_as_contrapositive,\n  apply impl_as_contrapositive_converse,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro n_p_np,\n  apply n_p_np,\n  right,\n  intro p,\n  have p_or_q : P ∨ ¬P,\n  left,\n  exact p,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros pq_p np,\n  have p : P,\n  apply pq_p,\n  intro p,\n  exfalso,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro poq,\n  intro np_nq,\n  cases np_nq with np nq,\n  cases poq,\n  contradiction,\n  contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro p_and_q,\n  intro np_or_nq,\n  cases p_and_q with p q,\n  cases np_or_nq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro n_p_or_q,\n  split,\n  intro p,\n  have p_or_q : P ∨ Q,\n  left,\n  exact p,\n  contradiction,\n  intro q,\n  have p_or_q : P ∨ Q,\n  right,\n  exact q,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros np_and_nq p_or_q,\n  cases np_and_nq with np nq,\n  cases p_or_q,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro n_p_and_q,\n  by_contra n_nq_or_np,\n  apply n_p_and_q,\n  split,\n  by_contra np,\n  apply n_nq_or_np,\n  right,\n  assumption,\n  by_contra nq,\n  apply n_nq_or_np,\n  left,\n  assumption,  \nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros nq_or_np p_and_q,\n  cases p_and_q with p q,\n  cases nq_or_np,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  apply demorgan_conj,\n  apply demorgan_conj_converse,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  apply demorgan_disj,\n  apply demorgan_disj_converse,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro p_and_pr,\n  cases p_and_pr with p q_and_r,\n  cases q_and_r with q r,\n  left,\n  split,\n  repeat {assumption},\n  right,\n  split,\n  repeat {assumption},\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro pq_or_pr,\n  cases pq_or_pr with pq pr,\n  cases pq with p q,\n  split,\n  exact p,\n  left,\n  exact q,\n  split,\n  cases pr with p r,\n  exact p,\n  right,\n  cases pr with p r,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro p_or_qandr,\n  cases p_or_qandr with p qandr,\n  split,\n  left,\n  exact p,\n  left,\n  exact p,\n  cases qandr with q r,\n  split,\n  right,\n  exact q,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro porq_and_porr,\n  cases porq_and_porr with p_or_q p_or_r,\n  cases p_or_r with p r,\n  left,\n  exact p,\n  cases p_or_q with p q,\n  left,\n  exact p,\n  right,\n  split,\n  exact q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros pandq_imp_r p q,\n  apply pandq_imp_r,\n  split,\n  repeat {assumption},\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros p_q_r p_and_q,\n  apply p_q_r,\n  cases p_and_q with p q,\n  exact p,\n  cases p_and_q with p q,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro p_and_q,\n  cases p_and_q with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro p_and_q,\n  cases p_and_q with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro p_and_p,\n  cases p_and_p with p p,\n  exact p,\n  intro p,\n  split,\n  repeat {exact p},\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro p_or_p,\n  cases p_or_p with p p,\n  repeat {exact p},\n  intro p,\n  left,\n  exact p,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists : \n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros ex_px u pu,\n  apply ex_px,\n  existsi u,\n  exact pu,\nend\n\ntheorem demorgan_exists_converse : \n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros all_npx ex_px,\n  cases ex_px with u p_u,\n  have np_u := all_npx u,\n  contradiction,\nend\n\ntheorem demorgan_forall : \n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  intro n_all_p,\n  by_contra nex_np,\n  apply n_all_p,\n  intro u,\n  by_contra npu,\n  apply nex_np,\n  existsi u,\n  intro pu,\n  contradiction,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro h,\n  cases h with x npx,\n  intro all_p,\n  have px := all_p x,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_forall,\n  apply demorgan_forall_converse,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  apply demorgan_exists,\n  apply demorgan_exists_converse,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros ex_p all_np,\n  cases ex_p with u pu,\n  have npu := all_np u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros all_p ex_np,\n  cases ex_np with u npu,\n  have pu := all_p u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro nex_np,\n  by_contra nall_px,\n  apply nall_px,\n  intro u,\n  by_contra npu,\n  apply nex_np,\n  existsi u,\n  intro pu,\n  contradiction,\n\n  \nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro n_all_np,\n  by_contra nex_p,\n  apply n_all_np,\n  intro u,\n  by_contra pu,\n  apply nex_p,\n  existsi u,\n  exact pu,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  apply forall_as_neg_exists,\n  apply forall_as_neg_exists_converse,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  apply exists_as_neg_forall,\n  apply exists_as_neg_forall_converse,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro ex_p_and_q,\n  cases ex_p_and_q with u pu_and_qu,\n  cases pu_and_qu with pu qu,\n  split,\n  existsi u,\n  assumption,\n  existsi u,\n  assumption,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro ex_p_or_q,\n  cases ex_p_or_q with u pu_or_qu,\n  cases pu_or_qu with pu pq,\n  left,\n  existsi u,\n  assumption,\n  right,\n  existsi u,\n  assumption,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro exp_or_exq,\n  cases exp_or_exq with exp exq,\n  cases exp with u pu,\n  existsi u,\n  left,\n  assumption,\n  cases exq with u qu,\n  existsi u,\n  right,\n  assumption,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro all_p_and_q,\n  split,\n  intro u,\n  have pu_and_qu := all_p_and_q u,\n  cases pu_and_qu with pu qu,\n  assumption,\n  intro x,\n  have px_and_qx := all_p_and_q x,\n  cases px_and_qx with px qx,\n  assumption,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro allp_and_allq,\n  intro a,\n  cases allp_and_allq with all_p all_q,\n  split,\n  have pa := all_p a,\n  assumption,\n  have qa := all_q a,\n  assumption,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro allp_or_allq,\n  intro u,\n  cases allp_or_allq with allp allq,\n  have pu := allp u,\n  left,\n  assumption,\n  have qu := allq u,\n  right,\n  assumption,\nend\n\n/-SECTION \"NOT THEOREMS\"\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\n  intro all_p_or_q,\n  left,\n  intro u,\n  have pu_or_qu := all_p_or_q u,\n  cases pu_or_qu with pu qu,\n  exact pu,\n  --NÃO VALIDO\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\n  intro exp_or_exq,\n  cases exp_or_exq with exp exq,\n  cases exp with u pu,\n  existsi u,\n  split,\n  assumption,\n  cases exq with u' qu,\n  --NÃO VALIDO\nend\n\n-----------------------------------------/\n\nend predicate\n", "meta": {"author": "DanieLuan", "repo": "fmclean", "sha": "53e4e5bd8ff2ddbe0380cf44b9c25829590037e5", "save_path": "github-repos/lean/DanieLuan-fmclean", "path": "github-repos/lean/DanieLuan-fmclean/fmclean-53e4e5bd8ff2ddbe0380cf44b9c25829590037e5/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7779662784961151}}
{"text": "import .lecture_26\nimport data.set\n\nnamespace relations\n\nsection functions\n\nvariables {α β γ : Type} (r : α → β → Prop)\nlocal infix `≺`:50 := r\n\n/-\nSINGLE-VALUED BINARY RELATION\n-/\n\ndef single_valued := \n  ∀ {x : α} {y z : β}, r x y → r x z → y = z \n\n#check @single_valued   -- property of a relation\n\n\n/-\nExercises: Which of the following are single-valued?\n- r = {(0,1), (0,2)}\n- r = {(1,0), (2,0)}\n- the unit circle on ℝ \n- r = {(-1,0), (0,-1), (1,0), (0,1)}\n- y = x^2\n- x = y^2\n- y = + / - square root x\n- f(x) = 3x+1\n- y = sin x\n- x = sin y\n-/\n\n/- FUNCTION\n\nA single-valued binary relation is also called a \nfunction (sometimes a functional binary relation).\n-/\ndef function := single_valued r\n\n/-\nOne possible property of a relation, r, is the \nproperty of being a function, i.e., of r being\nsingle-valued. Single-valuedness is a predicate\non relations. (This idea is isn't definable in\nfirst order predicate logic.)\n-/\n#check @function  \n\n/-\nThe same vocabulary applies to functions as to\nrelations, as functions are just special cases\n(single-valued) of otherwise arbitrary binary \nrelations.\n\nAs with any relation, for example, a function \nhas a domain, α, a domain of definition, and a\nco-domain, β. As with any relation, the set of \npairs of a function (that we're specifying) is\nis some subset of α × β; or equivalently it is\nin the powerset of α × β. \n\nWhen you want to express the idea that you have \nan arbitrary relation (possible a function) from\nα to β, you may write either of the following:\n\n  - let r ⊆ α × β be any relation from α → β  \n  - let r ∈ 𝒫 (α × β) be any relation, α → β \n  - let r : α → β be any binary relation\n\nBe sure you see that these are equivalent \nstatements! A key point is that in addition \nto a set of pairs a function (or relation) \nhas a domain of definition and a co-domain.\nKeeping track of exactly how a set of pairs\nrelates to its domain and codomain sets is\nessential.\n-/\n\n/- FOR A RELATION TO BE \"DEFINED\" FOR A VALUE\n\nProperty: We say that a function is \"defined\" for some\nvalue, (a : α), if there is some (b : β), such that the\npair, (a,b) is \"in\" r, i.e., (r a b) is true.\n-/\n\ndef defined (a : α) := ∃ (b : β), r a b\n\n/-\nExamples: Which is partial, which is total?\n\n- the positive square root function for x ∈ ℝ (dom def)\n- the positive square root function for x ∈ ℝ, x ≥ 0 \n-/\n\n\n/- THE TOTAL vs PARTIAL FUNCTION DICHOTOMY\n\nProperty: We say that a function is \"total\" if it is\ndefined for every value in its domain. Note that this\nusage of the word \"total\" is completely distinct from\nwhat we learned earlier for relations in general. It's\nthus better to use \"strongly connected\" for relations\nto mean every object is related to another in at least\none direction, and to use total to refer to a function \nthat is defined on every element of its domain. \n-/\n\ndef total_function := function r ∧ ∀ (a : α), defined r a\n\n/-\nAt this point we expect that for  a total function, r, \ndom_of_def r = domain r. At one key juncture you use\nthe axiom of set extensionality to convert the goal \nas an equality into that goal as a bi-implication.\nAfter that it's basic predicate logical reasoning,\nrather than more reasoning in set theory terms. \n-/\n\nexample : total_function r → dom_of_def r = dom r :=\nbegin\n  assume total_r,\n  cases total_r with func_r defall,\n  unfold dom_of_def,\n  unfold dom,\n  apply set.ext,\n  assume x,\n  split,\n\n  -- forwards\n  assume h,\n  unfold defined at defall,\n  unfold defined at defall,\n  -- goal completed\n  \n  -- backwards\n  assume h,\n  exact defall x,\n\nend\n\n/-\nWith that proof down as an example, we return to complete\nour list of properties of functions: \n  - total\n  - partial\n  - strictly partial\nHere are the definitions for the remaning two.\n-/\n\ndef strictly_partial_fun := function r ∧ ¬total_function r\ndef partial_function := function r -- includes total funs\n\n/-\nMathematicians generally consider the set of partial\nfunctions to include the total functions. We will use\nthe term \"strictly partial\" function to mean a function,\nf, that is not total, where dom_of_def f ⊊ dom f. (Be\nsure you see that the subset symbol here means subset\nbut not equal. That's what the slash through the bottom\nline in the symbol means: strict subset.)\n-/\n\n/- SURJECTIVE FUNCTIONS\n\nA function that \"covers\" its codomain (where every value in \nthe codomain is an \"output\" for some value in its domain) \nis said to map its domain *onto* its entire codomain. \nMathematicians will say that such a function is \"onto,\" \nor \"surjective.\" \n-/\n\ndef surjective := \n  total_function r ∧  \n  ∀ (b : β), ∃ a : α, r a b\n\n/-\nShould this be true?\n-/\n\nexample : \n  surjective r → \n  image_set r (dom r) = { b : β | true } :=\nbegin\n-- homework (on your own ungraded but please do it!)\nend\n\n/-\nWhich of the following functions are surjective?\n\n- y = log x, viewed as a function from ℝ → ℝ⁺\n\nAs written, the question is, um, tricky. Let's \nanalyze it. Then we'll give simpler questions.\n\nFirst a little background on logarithmic and\nexponential functions. Simply put, exponentiation\nraises a base to an exponent to produce an output,\nwhile the logarithm takes and converts it into \nthe exponent to which the base is raised to give\nthe input. \n\nFrom basic algebra, the log (base 10) function,\ny = log(x), is defined for any positive real, x,\nand is equal to the exponent to which the base\n(here 10) must be raised to produce x. Therefore\nas usually defined its domain of definition is\nthe *positive reals* and its co-domain is (*all\nof*) the reals.\n\nNow consider the question again. The domain of\ndefinition of log is the positive reals, so if\nwe expand the domain to all the reals, then the\nresulting function becomes partial. On the other\nside, if we restrict the range to the positive\nreals, then we are excluding from the function\nall those values in the interval (0,1) from the\ninput side in order to restrict the output to\nvalues greater than 0. \n\nSelf homework: Graph this function. \n\n- λ x, log x : ℝ+ → ℝ, bijective? \n- y = x^2, viewed as a function from ℝ → ℝ \n- y = x, viewed as a function from ℝ → ℝ\n- y = sin x, viewed as a function from ℝ → ℝ\n- y = sin x, as a function from ℝ to [-1,1] ∈ ℝ\n\n-/\n\n/- INJECTIVE FUNCTION\n\nWe have seen that for a relation to be a function, it \ncannot be \"one-to-many\" (some x value is associated\nwith more than one y value). On the other hand, it is\npossible for a function to associate many x values \nwith a single y value. There can be no fan-out from \nx/domain values to y/codomain values, but there can\nbe fan-in from x to y values.\n\nWhich is the following functions exhibits \"fan-in\",\nwith different x values associated with the same y\nvalues?\n\ny = x\ny = sin x\nx = 1 (trick question)\ny = 1\ny = x^2 on ℝ \ny = x^2 on ℝ⁺ (the positive reals)\n-/\n\ndef injective := \n  total_function r ∧ \n  ∀ {x y : α} {z : β}, \n    r x z → r y z → x = y\n/-\nWe will often want to know that a function does not\nmap multiple x values to the same y value. Example:\nin a company, we will very like want a function that \nmaps each employee to an employee ID number *unique*\nto that employee. Rather than being \"many to one\" we\ncall such a function \"one-to-one.\" We also say that\nsuch a function has the property of being *injective*.\n-/\n\n/-\nWe will often want to know that a function does not\nmap multiple x values to the same y value. Example:\nin a company, we will very like want a function that \nmaps each employee to an employee ID number *unique*\nto that employee. Rather than being \"many to one\" we\ncall such a function \"one-to-one.\" We also say that\nsuch a function has the property of being *injective*.\nThere is yet another way to understand the concept.\n-/\n\n\n/- BIJECTIVE FUNCTIONS\n-/\n\n/-\nFinally, a function is called one-to-one and onto, or\n*bijective* if it is both surjective and injective. In\nthis case, it has to map every element of its domain\n-/\n\ndef bijective := surjective r ∧ injective r\n\n/-\nAn essential property of any bijective relation is that \nit puts the elements of the domain and codomain into a\none-to-one correspondence. \n\nThat we've assumed that a function is total is important\nhere. Here's a counterexample: consider the relation from\ndom = {1,2,3} to codom = {A, B} with r = {(1,A), (2,B)}.\nThis function is injective and surjective but it clearly\ndoes not establish a 1-1 correspondence. \n\nWe can define what it means for a strictly partial function\nto be surjective or injective (we don't do it formally here).\nWe say that a partial function is surjective or injective if\nits domain restriction to its domain of definition (making it\ntotal) meets the definitions given above. \n\nNote that our use of the term, one-to-one, here is\ncompletely distinct from its use in the definition of \nan injective function. An injective function is said\nto be \"one-to-one\" in the sense that it's not many to\none: you can't have f(x) = k and f(y)=k where x ≠ y. \nA one-to-one correspondence *between two sets*, on the \nother hand, is a pairing of elements that associates\neach element of one set with a unique single element\nof the other set, and vice versa.\n-/\n\n/-\nQuestion: Is the inverse of a function always a function.\nThink about the function, y = x^2. What is its inverse?\nIs it's inverse a function? There's your answer.\n\nA critical property of a bijective function, on the other\nhand, is that its inverse is also a bijective function. It\nis easy to see: just reverse the \"arrows\" in a one-to-one\ncorrespondence between two sets. A function who inverse \nis a function is said to be invertible (as a function, as \nevery relation has and inverse that is again a relation). \n-/\n\n/-\nEXERCISE #1: Prove that the inverse of a \nbijective function is a function. Ok, yes, \nwe will work this one out for you! But you\nshould really read and understand it. Then\nthe rest shouldn't be too bad.\n-/\n\nexample : bijective r → function (inverse r) :=\nbegin\n  /-\n    Assume hypothesis\n  -/\n  assume r_bij,\n\n  /-\n  Unfold definitions and, from definitions,\n  deduce all the basic facts we'll have to\n  work with.\n  -/\n  cases r_bij with r_sur r_inj,\n  cases r_inj with r_tot r_one_to_one,\n  cases r_sur with r_tot r_onto,\n  unfold total_function at r_tot, \n  cases r_tot with r_fun alldef,\n  unfold function at r_fun,\n  unfold single_valued at r_fun,\n  unfold defined at alldef,\n\n  /-\n  What remains to be shown is that the\n  inverse of r is function. Expanding \n  the definition of function, that means\n  r inverse is single-valued. Let's see. \n  -/\n  unfold function,\n  unfold single_valued,\n  /-\n  To show that r inverse (mapping β values\n  back to α values) r is single-valued, \n  assume that b is some value of type β \n  (in the codomain of r) and show that if \n  r inverse maps b is mapped to both a1 and \n  a2 then a1 = a2.\n  -/\n  assume b a1 a2 irba1 irba2,\n  /-\n  Key insight: (inverse r) b a means r a b. \n  In other words, r b a is in r inverse (it\n  contains the pair (b, a)) if and only if \n  (a, b) is in r, i.e., r a b.\n  -/\n  unfold inverse at irba1 irba2,\n  /-\n  With those pairs now turned around, by the \n  injectivity of r, we're there!\n  -/\n  apply r_one_to_one irba1 irba2,\nend \n\n/-\nJust to set expectations: The reality is that\nI explored numerous ways of writing this proof.\nOften a first proof will be confusing, messy,\netc. Most proofs of theorems you see in most\nmathematics books are gems, polished in their\npresentations by generations of mathematicians.\nIt took me a little while to get to this proof\nscript and the sequence of reasoning steps and\nintermediate proof states it traverses. \n-/\n\n\n/- INJECTIVE AND SURJECTIVE *PARTIAL* FUNCTIONS\n\nOkay, we actually are now able to to define just\nwhat is means for a *partial* function to be\ninjective, surjective, bijective, which is that \nit is so when its domain is restricted to its \ndomain of definition, rendering it total (at \nwhich point the preceding definition applies). \n-/\n\ndef injectivep := function r ∧ injective (dom_res r (dom_of_def r))\ndef surjectivep := function r ∧ surjective (dom_res r (dom_of_def r))\ndef bijectivep := function r ∧ bijective (dom_res r (dom_of_def r))\n\n\n\n\n-- EXERCISE #2: Prove that the inverse of a bijective function is bijective.\nexample : bijective r → bijective (inverse r) :=\nbegin\n  assume bij_r,\n  unfold bijective,\n  unfold bijective at bij_r,\n  cases bij_r with surj_r inj_r,\n  unfold surjective at surj_r,\n  unfold injective at inj_r,\n  cases surj_r with r_tot r_onto,\n  cases inj_r with r_tot r_one_to_one,\n  cases r_tot with r_fun alldef,\n  unfold function at r_fun,\n  unfold single_valued at r_fun,\n\n  apply and.intro _ _,\n\n  unfold surjective,\n  unfold total_function,\n  split,\n  split,\n  unfold function,\n  unfold single_valued,\n  unfold inverse,\n  assume b a x rab rxb,\n  apply r_one_to_one rab,\n  exact rxb,\n\n  assume b,\n  apply r_onto b,\n  unfold inverse,\n  unfold defined at alldef,\n  exact alldef,\n\n  unfold injective inverse,\n  split, \n  unfold total_function,\n  split,\n  unfold function,\n  unfold single_valued,\n  assume b a z rab rzb,\n  apply r_one_to_one rab rzb,\n\n  assume b,\n  unfold defined at alldef,\n  apply r_onto b,\n\n  assume c b a rac rab,\n  apply r_fun rac rab,\nend\n\n\n/-\nEXERCISE #3: Prove that the inverse of the inverse of a bijective\nfunction is that function.\n-/\nexample : bijective r → (r = inverse (inverse r)) :=\nbegin\n  assume bijr,\n  unfold inverse,\nend\n\n/-\nEXERCISE  #4: Formally state and prove that every injective function \nhas a *function* as an inverse.\n-/\nexample : injective r → function (inverse r) :=\n  begin\n  assume injr,-- hint: remember recent work\n  unfold function,\n  unfold single_valued,\n  cases injr with r_tot r_one_to_one,\n  unfold total_function at r_tot,\n  unfold function at r_tot,\n  unfold single_valued at r_tot,\n  unfold defined at r_tot,\n  cases r_tot with r_fun alldef,\n  assume x y z rxy rxz,\n  unfold inverse at rxy,\n  unfold inverse at rxz,\n  apply r_one_to_one rxy rxz,\n  end\n\n/-\nEXERCISE #5. Is bijectivity transitive? In other words, if the\nrelations, s and r, are both bijective, then is the\ncomposition, s after r, also always bijective? Now\nwe'll see.\n-/\n\nopen relations    -- for definition of composition\n\n/-\nCheck the following proposition. True? prove it for all.\nFalse? Present a counterexample.\n-/\ndef bij_trans (s : β → γ → Prop)  (r : α → β → Prop) :\n  bijective r → bijective s → bijective (composition s r) := \n  begin\n    assume bijr bijs,\n    unfold bijective,\n\n    apply and.intro _ _,\n    unfold bijective at bijr bijs,\n    cases bijr with r_sur r_inj,\n    cases bijs with s_sur s_inj,\n\n    unfold surjective,\n    unfold total_function,\n    unfold function,\n    unfold single_valued,\n    \n    unfold surjective at r_sur s_sur,\n    unfold total_function at r_sur s_sur,\n    cases r_sur with r_tot r_onto,\n    cases s_sur with s_tot s_onto,\n    unfold function at r_tot s_tot,\n    unfold single_valued at r_tot s_tot,\n    cases r_tot with r_fun r_alldef,\n    cases s_tot with s_fun s_alldef,\n\n    unfold injective at r_inj s_inj,\n    cases r_inj with r_tot r_one_to_one,\n    cases s_inj with s_tot s_one_to_one,\n\n    unfold total_function at r_tot s_tot,\n    unfold function at r_tot s_tot,\n    unfold single_valued at r_tot s_tot,\n    unfold defined at r_tot s_tot r_alldef s_alldef,\n  \n    cases r_tot with r_fun alldef_r,\n    cases s_tot with s_fun alldef_s,\n\n    split,\n    split,\n    \n    unfold composition,\n    assume x y z,\n    assume h i,\n    apply exists.elim h,\n    apply exists.elim i,\n\n    assume b sbz_rxb,\n    assume t sty_rxt,\n\n    have rxb := sbz_rxb.right,\n    have rxt := sty_rxt.right,\n\n    have bt := r_fun rxb rxt,\n\n    have sbz := sbz_rxb.left,\n    have sty := sty_rxt.left,\n    have stz : s t z := eq.subst bt sbz,\n    apply s_fun sty stz,\n\n    assume i,\n    unfold defined,\n    have sr := composition s r,\n    have idd := sr i,\n    have idd2 := alldef_r i,\n    \n    unfold composition,\n    cases idd2 with beta ribeta,\n    have idd3 := alldef_s beta,\n    cases idd3 with g sbetag,\n    apply exists.intro,\n    apply exists.intro,\n    apply and.intro sbetag ribeta,\n\n    assume g,\n    unfold composition,\n    have sr := composition s r,\n    have idd := s_onto g,\n    cases idd with b sbg,\n    have idd2:= r_onto b,\n    cases idd2 with a rab,\n    apply exists.intro,\n    apply exists.intro,\n    apply and.intro sbg rab,\n\n    unfold bijective at bijr bijs,\n    cases bijr with r_sur r_inj,\n    cases bijs with s_sur s_inj,\n\n    unfold injective,\n    unfold total_function,\n    unfold function,\n    unfold single_valued,\n    \n    unfold surjective at r_sur s_sur,\n    unfold total_function at r_sur s_sur,\n    cases r_sur with r_tot r_onto,\n    cases s_sur with s_tot s_onto,\n    unfold function at r_tot s_tot,\n    unfold single_valued at r_tot s_tot,\n    cases r_tot with r_fun r_alldef,\n    cases s_tot with s_fun s_alldef,\n\n    unfold injective at r_inj s_inj,\n    cases r_inj with r_tot r_one_to_one,\n    cases s_inj with s_tot s_one_to_one,\n\n    unfold total_function at r_tot s_tot,\n    unfold function at r_tot s_tot,\n    unfold single_valued at r_tot s_tot,\n    unfold defined at r_tot s_tot r_alldef s_alldef,\n\n    cases r_tot with r_fun alldef_r,\n    cases s_tot with s_fun alldef_s,\n\n    split,\n    split,\n\n    unfold composition,\n    assume x y z,\n    assume h i,\n    apply exists.elim h,\n    apply exists.elim i,\n    assume b sbz_rxb,\n    assume t sty_rxt,\n\n    have sbz := sbz_rxb.left,\n    have sty := sty_rxt.left,\n    \n    have rxb := sbz_rxb.right,\n    have rxt := sty_rxt.right,\n\n    have bt := r_fun rxb rxt,\n\n    have stz : s t z := eq.subst bt sbz,\n    apply s_fun sty stz,\n\n    assume i,\n    unfold defined,\n    have sr := composition s r,\n    have idd := sr i,\n    have idd2 := alldef_r i,\n    \n    unfold composition,\n    cases idd2 with beta ribeta,\n    have idd3 := alldef_s beta,\n    cases idd3 with g sbetag,\n    apply exists.intro,\n    apply exists.intro,\n    apply and.intro sbetag ribeta,\n\n    assume i,\n    unfold composition,\n    have sr := composition s r,\n    assume a g,\n    assume e_sbg_rib e_sbg_rab,\n    cases e_sbg_rib with b sbg_rib,\n    cases e_sbg_rab with t stg_rat,\n\n    have sbg := sbg_rib.left,\n    have stg := stg_rat.left,\n    \n    have rib := sbg_rib.right,\n    have rat := stg_rat.right,\n\n    have bt := s_one_to_one sbg stg,\n\n    have rit : r i t := eq.subst bt rib,\n    apply r_one_to_one rit rat,\n  end\n\n/-\nIn general, an operation (such as inverse, here) that, \nwhen applied twice, is the identity, is said to be an\ninvolution. Relational inverse on bijective functions\nis involutive in this sense.\n\nA visualization: each green ball here goes to a red\nball there and the inverse takes each red ball right\nback to the green ball from which it came, leaving\nthe original green ball as the end result, as well.\nAn identity function.\n-/\n\nend functions\nend relations\n", "meta": {"author": "jakekauff", "repo": "DiscreteMath", "sha": "1ce98ac3fdb7b7fa880e595ac29f66a5098cfdba", "save_path": "github-repos/lean/jakekauff-DiscreteMath", "path": "github-repos/lean/jakekauff-DiscreteMath/DiscreteMath-1ce98ac3fdb7b7fa880e595ac29f66a5098cfdba/hw8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7779662768121928}}
{"text": "-- Divisivilidad_productos.lean\n-- Si x, y, z ∈ ℕ, entonces x ∣ y * x * z\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 6-octubre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si x, y, z ∈ N, entonces\n--    x ∣ y * x * z\n-- ----------------------------------------------------------------------\n\nimport data.nat.basic\nvariables x y z : ℕ\n\n-- 1ª demostración\n-- ===============\n\nexample : x ∣ y * x * z :=\nbegin\n  have h1 : x ∣ y * x,\n    { exact dvd_mul_left x y },\n  have h2 : (y * x) ∣ (y * x * z),\n    { exact dvd.intro z rfl},\n  show x ∣ y * x * z,\n    { exact dvd_trans h1 h2},\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : x ∣ y * x * z :=\ndvd_trans (dvd_mul_left x y) (dvd.intro z rfl)\n\n-- 3ª demostración\n-- ===============\n\nexample : x ∣ y * x * z :=\nbegin\n  apply dvd_mul_of_dvd_left,\n  apply dvd_mul_left\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/Divisivilidad_productos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9241418137109955, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7779662749785404}}
{"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 : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from ℝ to ℝ\n-- x₀ and l are real numbers\nvariables (u : ℕ → ℝ) (f : ℝ → ℝ) (x₀ l : ℝ)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : ¬ (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε) ↔\n∃ ε > 0, ∀ N, ∃ n ≥ N, |u n - l| > ε\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is continuous at x₀\" -/\n-- 0063\nexample : ¬ (∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ →  |f x - f x₀| ≤ ε) ↔\n∃ ε > 0, ∀ δ > 0, ∃ x, |x-x₀| ≤ δ ∧ |f x - f x₀| > ε\n:=\nbegin\n  check_me,\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`∀ x x', ...` is the abbreviation of\n`∀ x, ∀ x', ... `. \n\nAlso, `∃ x x', ...` is the abbreviation of `∃ x, ∃ x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on ℝ\" -/\n-- 0064\nexample : ¬ (∀ ε > 0, ∃ δ > 0, ∀ x x', |x' - x| ≤ δ →  |f x' - f x| ≤ ε) ↔\n(∃ ε > 0, ∀ δ > 0, ∃ x x', |x'-x| ≤ δ ∧ |f x' - f x| > ε)\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is sequentially continuous at x₀\" -/\n-- 0065\nexample : ¬ (∀ u : ℕ → ℝ, (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - x₀| ≤ ε) → (∀ ε > 0, ∃ N, ∀ n ≥ N, |(f ∘ u) n - f x₀| ≤ ε))  ↔\n∃ u : ℕ → ℝ, (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - x₀| ≤ ε) ∧ (∃ ε > 0, ∀ N, ∃ n ≥ N, |(f ∘ u) n - f x₀| > ε)\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 : ℝ} : |x| ≤ y ↔ -y ≤ x ∧ x ≤ y\n\nge_max_iff (p q r) : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q\n\nle_max_left p q : p ≤ max p q\n\nle_max_right p q : q ≤ max p q\n\n/-- The sequence `u` tends to `+∞`. -/\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n-/\n\n-- 0066\nexample {u : ℕ → ℝ} : tendsto_infinity u → ∀ l, ¬ seq_limit u l :=\nbegin\n  intros h1 l h2,\n  cases h1 (l+2) with M h3,\n  cases h2 1 (by linarith) with N h4,\n  let n := max N M,\n  specialize h3 n (le_max_right _ _),\n  specialize h4 n (le_max_left _ _),\n  rw abs_le at h4,\n  linarith,\nend\n\ndef nondecreasing_seq (u : ℕ → ℝ) := ∀ n m, n ≤ m → u n ≤ u m\n\n-- 0067\nexample (u : ℕ → ℝ) (l : ℝ) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  ∀ n, u n ≤ l :=\nbegin\n  intros n,\n  by_contradiction h2,\n  push_neg at h2,\n  cases h ((u n - l)/2) (by linarith) with N h3,\n  let m := max n N,\n  specialize h3 m (le_max_right _ _),\n  rw abs_le at h3,\n  specialize h' n m (le_max_left _ _),\n  linarith,\nend\n\n/-\nIn the following exercises, `A : set ℝ` means that A is a set of real numbers.\nWe can use the usual notation x ∈ A.\n\nThe notation `∀ x ∈ A, ...` is the abbreviation of `∀ x, x ∈ A → ... `\n\nThe notation `∃ x ∈ A, ...` is the abbreviation of `∃ x, x ∈ A ∧ ... `.\nMore precisely it is the abbreviation of `∃ x (H : x ∈ A), ...`\nwhich is Lean's strange way of saying `∃ x, x ∈ A ∧ ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (∃ (h : p), q) ↔ p ∧ 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 ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ 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 ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intros y,\n  contrapose!,\n  exact hx.right y,\n  -- by_contradiction h2,\n  -- push_neg at h2,\n  -- linarith [hx.right y h2],\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 : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intros hxy,\n  use (y-x)/2,\n  split; linarith, -- NOTE split\nend\n\n-- 0070\nexample {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  by_contradiction hxy,\n  push_neg at hxy,\n  let ε := (x-y)/2,\n  have fact : ε > 0,\n  { dsimp [ε], linarith, },\n  cases hu ε fact with N hN,\n  specialize hN N (by linarith),\n  rw abs_le at hN,\n  cases hN,\n  specialize ineg N,\n  have h0 : y > y,\n  calc y ≥ u N : ineg\n  ... ≥ x - ε : by linarith\n  ... > y : by { dsimp [ε], linarith, },\n  linarith,\nend\n\n", "meta": {"author": "fzyzcjy", "repo": "learn_lean", "sha": "3d47e1641bb7d7afb590d18a73fa0c562e51e733", "save_path": "github-repos/lean/fzyzcjy-learn_lean", "path": "github-repos/lean/fzyzcjy-learn_lean/learn_lean-3d47e1641bb7d7afb590d18a73fa0c562e51e733/src/tutorial/exercises/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7779646533610862}}
{"text": "import .love12_basic_mathematical_structures_demo\n\n\n/- # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Type Classes\n\nRecall the inductive type `btree` we introduced earlier: -/\n\n#check btree\n\n/- The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/- 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nsorry\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nsorry\n\n/- 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\nsorry\n\n/- 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/- 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀ y : btree ℕ, btree.graft y x ≠ btree.empty :=\nsorry\n\n\n/- ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/- 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nsorry\n\n/- 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nsorry\n\n/- 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nsorry\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\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/love12_basic_mathematical_structures_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7779646499435902}}
{"text": "import ..fglib\nimport ..basic\nimport .data\n\nnamespace FG\n\n/- ## Invertible 3x3 Matrix -/\n\n/- `is_invertible` is a `Prop` of `mat3`. -/\nnamespace mat3\n\ndef is_invertible (A : mat3) : Prop :=\n  ∃(B : mat3), A * B = 1\n\n/- A `mat3` is unitary if it's the inverse of its transpose. -/\n@[simp] def is_unitary (A : mat3) : Prop :=\n  A * A.transpose = 1\n\nlemma unitary_is_inverible (A : mat3) :\n  is_unitary A → is_invertible A :=\nbegin\n  intro h,\n  use A.transpose,\n  assumption\nend\n\n/- Get the inverse of a `mat3`, by calculating the adjugate matrix.\n  It's noncomputable because of the dependency of `real.div`. -/\nnoncomputable def inverse (A : mat3): mat3 :=\nbegin\n  let detA := A.det,\n  let AT := A.transpose,\n  let subdet := λ(a b c d : ℝ), a * d - b * c,\n  let M : mat3 :=\n  ⟨ ⟨ subdet AT.y.y AT.y.z AT.z.y AT.z.z, subdet AT.y.x AT.y.z AT.z.x AT.z.z, subdet AT.y.x AT.y.y AT.z.x AT.z.y ⟩,\n    ⟨ subdet AT.x.y AT.x.z AT.z.y AT.z.z, subdet AT.x.x AT.x.z AT.z.x AT.z.z, subdet AT.x.x AT.x.y AT.z.x AT.z.y ⟩,\n    ⟨ subdet AT.x.y AT.x.z AT.y.y AT.y.z, subdet AT.x.x AT.x.z AT.y.x AT.y.z, subdet AT.x.x AT.x.y AT.y.x AT.y.y ⟩ ⟩,\n  use\n  ⟨ ⟨ M.x.x / detA, -M.x.y / detA, M.x.z / detA ⟩,\n    ⟨ -M.y.x / detA, M.y.y / detA, -M.y.z / detA ⟩,\n    ⟨ M.z.x / detA, -M.z.y / detA, M.z.z / detA ⟩ ⟩\nend\n\n/- There is an inverse if the matrix has nonzero determinant.\n  It is -/\n@[simp] theorem mul_inv_eq_one (A : mat3) (h : A.det ≠ 0) :\n  A * A.inverse = 1 :=\nbegin\n  simp [inverse, *],\n  repeat { apply and.intro },\n  /- `field_simp` is used since divisions are involved. -/\n  repeat { field_simp, ring }\nend\n@[simp] theorem inv_mul_eq_one (A : mat3) (h : A.det ≠ 0) :\n  A.inverse * A = 1 :=\nbegin\n  simp [inverse, *],\n  repeat { apply and.intro },\n  /- `field_simp` is used since divisions are involved. -/\n  repeat { field_simp, ring }\nend\n\n/- `is_invertible` is equivalent to `det ≠ 0` -/\n@[simp] lemma invertible_det_ne_zero (A : mat3) :\n  is_invertible A → A.det ≠ 0 :=\nbegin\n  intros ha,\n  cases' ha with B hab,\n  intro hn,\n  have hadet0 : A.det = 0 := by simp [hn],\n  have hdet0 : A.det * B.det = 0 := by rw hadet0; apply zero_mul B.det,\n  have hdet := by calc A.det * B.det = (A * B).det\n      : by rw mat3.det_mul_det\n    ... = (1 : mat3).det\n      : by rw hab\n    ... = 1\n      : by rw mat3.det_one,\n  linarith\nend\n\n@[simp] lemma det_ne_zero_invertible (A : mat3) :\n  A.det ≠ 0 → is_invertible A :=\nbegin\n  intro h,\n  use A.inverse,\n  exact mul_inv_eq_one A h\nend\n\ntheorem det_iff (A : mat3) :\n  is_invertible A ↔ A.det ≠ 0 :=\nbegin\n  split,\n  { exact invertible_det_ne_zero A },\n  { exact det_ne_zero_invertible A }\nend\n\nlemma inverse_invertible (A : mat3) (h : A.det ≠ 0) :\n  is_invertible A.inverse :=\nbegin\n  apply exists.intro A,\n  exact inv_mul_eq_one A h\nend\n\nend mat3\n\n/- `invertible_mat3` is a subtype of `mat3` that has the `is_invertible` property. -/\n\n@[simp] def invertible_mat3 : Type := { A : mat3 // A.is_invertible }\n\nnamespace invertible_mat3\n\n@[ext] theorem ext {A B : invertible_mat3} :\n  A.val = B.val → A = B :=\nsubtype.eq\n\n@[simps] def mul (A B : invertible_mat3) : invertible_mat3 :=\n⟨ A.val * B.val,\n  begin\n    apply mat3.det_ne_zero_invertible,\n    have ha := mat3.invertible_det_ne_zero A.val A.property,\n    have hb := mat3.invertible_det_ne_zero B.val B.property,\n    calc (A.val * B.val).det = A.val.det * B.val.det\n        : by rw mat3.det_mul_det\n      ... ≠ 0\n        : by apply mul_ne_zero ha hb\n  end ⟩\n\n@[simps] def one : invertible_mat3 :=\n⟨1, by simp⟩\n\n@[simps] noncomputable def inv (A : invertible_mat3) :\n  invertible_mat3 :=\n⟨A.val.inverse, begin\n  apply mat3.inverse_invertible,\n  apply mat3.invertible_det_ne_zero,\n  exact A.property\nend⟩\n\n\n@[simp] lemma one_mul (A : invertible_mat3) :\n  mul one A = A :=\nbegin\n  cases' A,\n  apply ext,\n  simp only [one, mul],\n  cases' val,\n  simp,\n  repeat { apply and.intro },\n  { cases' x, refl },\n  { cases' y, refl },\n  { cases' z, refl }\nend\n\n@[simp] lemma mul_one (A : invertible_mat3) :\n  mul A one = A :=\nbegin\n  cases' A,\n  cases' val,\n  ext,\n  simp,\n  repeat { apply and.intro },\n  { cases' x, refl },\n  { cases' y, refl },\n  { cases' z, refl }\nend\n\n@[simp] lemma mul_assoc (A B C : invertible_mat3) :\n  mul (mul A B) C = mul A (mul B C) :=\nbegin\n  cases' A with A _,\n  cases' B with B _,\n  cases' C with C _,\n  ext,\n  simp,\n  repeat { apply and.intro },\n  repeat { ring }\nend\n\n@[simp] lemma mul_left_inv (A : invertible_mat3) :\n  mul (inv A) A = one :=\nbegin\n  cases' A,\n  apply ext,\n  simp only [one, inv, mul],\n  apply mat3.inv_mul_eq_one,\n  apply mat3.invertible_det_ne_zero,\n  assumption\nend\n\n/- Then it's a `group`. Since any invertible matrix has an inverse. -/\n@[simps] noncomputable instance group : group invertible_mat3 :=\n{ mul := mul,\n  one := one,\n  inv := inv,\n  one_mul := one_mul,\n  mul_one := mul_one,\n  mul_assoc := mul_assoc,\n  mul_left_inv := mul_left_inv }\n\n@[simps] def transpose (A : invertible_mat3) : invertible_mat3 :=\n⟨A.val.transpose, begin\n  apply mat3.det_ne_zero_invertible,\n  rw mat3.transpose_det,\n  apply mat3.invertible_det_ne_zero,\n  exact A.property\nend⟩\n\n@[simp] def is_unitary (A : invertible_mat3) : Prop :=\n  A.val.is_unitary\n\nend invertible_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/invertible_mat3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7779646495577097}}
{"text": "/-\nCopyright (c) Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel\n\n! This file was ported from Lean 3 source module analysis.complex.operator_norm\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.Analysis.NormedSpace.OperatorNorm\nimport Mathbin.Data.Complex.Determinant\n\n/-! # The basic continuous linear maps associated to `ℂ`\n\nThe continuous linear maps `complex.re_clm` (real part), `complex.im_clm` (imaginary part),\n`complex.conj_cle` (conjugation), and `complex.of_real_clm` (inclusion of `ℝ`) were introduced in\n`analysis.complex.operator_norm`.  This file contains a few calculations requiring more imports:\nthe operator norm and (for `complex.conj_cle`) the determinant.\n-/\n\n\nopen ContinuousLinearMap\n\nnamespace Complex\n\n/-- The determinant of `conj_lie`, as a linear map. -/\n@[simp]\ntheorem det_conjLie : (conjLie.toLinearEquiv : ℂ →ₗ[ℝ] ℂ).det = -1 :=\n  det_conjAe\n#align complex.det_conj_lie Complex.det_conjLie\n\n/-- The determinant of `conj_lie`, as a linear equiv. -/\n@[simp]\ntheorem linearEquiv_det_conjLie : conjLie.toLinearEquiv.det = -1 :=\n  linearEquiv_det_conjAe\n#align complex.linear_equiv_det_conj_lie Complex.linearEquiv_det_conjLie\n\n@[simp]\ntheorem reClm_norm : ‖reClm‖ = 1 :=\n  le_antisymm (LinearMap.mkContinuous_norm_le _ zero_le_one _) <|\n    calc\n      1 = ‖reClm 1‖ := by simp\n      _ ≤ ‖reClm‖ := unit_le_op_norm _ _ (by simp)\n      \n#align complex.re_clm_norm Complex.reClm_norm\n\n@[simp]\ntheorem reClm_nnnorm : ‖reClm‖₊ = 1 :=\n  Subtype.ext reClm_norm\n#align complex.re_clm_nnnorm Complex.reClm_nnnorm\n\n@[simp]\ntheorem imClm_norm : ‖imClm‖ = 1 :=\n  le_antisymm (LinearMap.mkContinuous_norm_le _ zero_le_one _) <|\n    calc\n      1 = ‖imClm I‖ := by simp\n      _ ≤ ‖imClm‖ := unit_le_op_norm _ _ (by simp)\n      \n#align complex.im_clm_norm Complex.imClm_norm\n\n@[simp]\ntheorem imClm_nnnorm : ‖imClm‖₊ = 1 :=\n  Subtype.ext imClm_norm\n#align complex.im_clm_nnnorm Complex.imClm_nnnorm\n\n@[simp]\ntheorem conjCle_norm : ‖(conjCle : ℂ →L[ℝ] ℂ)‖ = 1 :=\n  conjLie.toLinearIsometry.norm_toContinuousLinearMap\n#align complex.conj_cle_norm Complex.conjCle_norm\n\n@[simp]\ntheorem conjCle_nnorm : ‖(conjCle : ℂ →L[ℝ] ℂ)‖₊ = 1 :=\n  Subtype.ext conjCle_norm\n#align complex.conj_cle_nnorm Complex.conjCle_nnorm\n\n@[simp]\ntheorem ofRealClm_norm : ‖ofRealClm‖ = 1 :=\n  ofRealLi.norm_toContinuousLinearMap\n#align complex.of_real_clm_norm Complex.ofRealClm_norm\n\n@[simp]\ntheorem ofRealClm_nnnorm : ‖ofRealClm‖₊ = 1 :=\n  Subtype.ext <| ofRealClm_norm\n#align complex.of_real_clm_nnnorm Complex.ofRealClm_nnnorm\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/OperatorNorm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.7779414648820513}}
{"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 ∩ 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 ⊓ B ≠ ⊥ :=\nbegin\n  intro h,\n  have h1 := submodule.dim_sup_add_dim_inf_eq A B,\n  rw [hA, hB, h, finrank_bot k V] at h1,\n  norm_num at h1,\n  have h2 := submodule.finrank_le (A ⊔ B),\n  rw [h1, hV] at h2,\n  linarith,\nend\n\n/-\n\nHere's some API which you will need for this question. Noet 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 `↥A`, 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 ↥(A ⊔ B) + finrank k ↥(A ⊓ B) = finrank k ↥A + finrank k ↥B`\n`submodule.finrank_le A : finrank k ↥A ≤ finrank k V`\n`finrank_bot k V : finrank K ↥⊥ = 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/solutions/section11vector_spaces/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8652240756264638, "lm_q1q2_score": 0.7779414648631964}}
{"text": "import utilities\n\nopen list\nopen nat\n\nset_option trace.simplify.rewrite true\n\nvariable {α : Type*}\nvariable r: α → α → Prop\nvariable x: α \nvariable xs: list α  \n\n/- \n# Quicksort\n\nThe qsort from the library is *not* really quicksort since it doesn't partition the elements in-place.\nQuicksort is defined here following the definition from __Functional Algorithms, Verified!__.\n -/\n\n/-\nThis lemma is used in the definition of quicksort.\n-/\nlemma well_founded_qs [decidable_rel r]: (list.filter (λ y, r y x) xs).sizeof < 1 + xs.sizeof :=\n  begin\n    induction xs,\n    repeat { simp [list.filter]},\n    split_ifs,\n    repeat { simp [list.sizeof],\n      linarith },\n  end\n\n/-\nThis lemma is used in the definition of quicksort.\n-/\nlemma well_founded_qs' [decidable_rel r]: (list.filter (λ y,¬ r y x) xs).sizeof < 1 + xs.sizeof :=\nbegin\n    induction xs,\n    repeat { simp [list.filter] },\n    split_ifs,\n    repeat { simp [list.sizeof],\n      linarith },\nend\n\ndef quicksort [decidable_rel r]: list α → list α     \n| [] := []\n| (x::xs) :=  \n  have (xs.filter (λ y, r y x)).sizeof < 1 + xs.sizeof, by apply well_founded_qs,\n  have (xs.filter (λ y, ¬r y x)).sizeof < 1 + xs.sizeof, by apply well_founded_qs',\n  quicksort (xs.filter (λ y, r y x)) ++ [x] ++ quicksort (xs.filter (λ y, ¬ r y x))   \n\n/-\n## Functional Correctness\n-/\n\nlemma mset_quicksort [decidable_rel r]: \n  ∀ xs: list α, (↑(quicksort r xs): multiset α)  = ↑xs\n| [] := by simp only [quicksort]\n| (x::xs) :=  \nbegin\n  rw quicksort,\n  repeat {rw ← multiset.coe_add},\n  have h1: (list.filter (λ y, r y x) xs).sizeof < 1 + xs.sizeof ∧ (list.filter (λ y, ¬ r y x) xs).sizeof < 1 + xs.sizeof , from begin\n    apply and.intro,\n    { apply well_founded_qs},\n    apply well_founded_qs',\n  end,\n  cases h1,\n  simp only [mset_quicksort (filter (λ (y : α), r y x) xs), mset_quicksort (filter (λ (y : α), ¬ r y x) xs), ← multiset.coe_filter, add_comm, add_assoc, multiset.filter_add_not],\n  simp,\nend\n\nlemma set_quicksort [decidable_rel r]: (quicksort r xs).to_set = xs.to_set :=\nbegin\n  simp [← set_mset_mset, mset_quicksort],\nend\n\nlemma sorted_quicksort [decidable_rel r] [is_linear_order α r] : \n  ∀ xs, sorted' r (quicksort r xs)\n| [] := by simp [quicksort]\n| (x::xs) := \nbegin\n  rw quicksort,\n  simp [sorted'_append],\n  have h1: (list.filter (λ (y), r y x) xs).sizeof < 1 + xs.sizeof ∧ (list.filter (λ (y),¬ r y x) xs).sizeof < 1 + xs.sizeof , from begin\n    apply and.intro,\n    { apply well_founded_qs},\n    apply well_founded_qs',\n  end,\n  cases h1,\n  apply and.intro,\n  { simp only [sorted_quicksort (filter (λ (y : α), r y x) xs)],},\n  apply and.intro,\n  { simp [sorted'],\n    apply and.intro,\n    { simp [set_quicksort],\n      intros,\n      simp [← set_mset_mset, multiset.to_set] at H,\n      exact or.resolve_right (total_of r x y) H.right},\n    simp only [sorted_quicksort (filter (λ (y : α), ¬ r y x) xs)]},\n  intros,\n  have h1: x_1 ∈ (↑(quicksort r (filter (λ (y : α), r y x) xs)): multiset α ), by simp [H],\n  have h3: x_1 ∈ (↑ (filter (λ (y : α), r y x) xs): multiset α), from eq.subst (mset_quicksort r (filter (λ y, r y x) xs)) h1,\n  simp at h3,\n  apply and.intro,\n  { exact h3.right},\n  intros a h1,\n  have h2: a ∈ (↑(quicksort r (filter (λ y, ¬ r y x) xs)): multiset α ), by simp [h1],\n  have h5: a ∈ (↑ (filter (λ y, ¬ r y x) xs): multiset α), from eq.subst (mset_quicksort r (filter (λ y, ¬ r y x) xs)) h2,\n  simp at h5,\n  have h4: r x a , from or.resolve_left (total_of r a x) h5.right,\n  exact trans h3.right h4,\nend\n\n/- \n## Time Complexity\nLike in __Functional Algorithms, Verified!__ the running time is not analyzed, \nbecause it is well known that it is quadratic in the worst case but sort of O(n lg n) on average. \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/quicksort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.7779414547220392}}
{"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ébastien Gouëzel\n\n! This file was ported from Lean 3 source module measure_theory.measure.haar_lebesgue\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.Lebesgue\nimport Mathbin.MeasureTheory.Measure.Haar\nimport Mathbin.LinearAlgebra.FiniteDimensional\nimport Mathbin.Analysis.NormedSpace.Pointwise\nimport Mathbin.MeasureTheory.Group.Pointwise\nimport Mathbin.MeasureTheory.Measure.Doubling\n\n/-!\n# Relationship between the Haar and Lebesgue measures\n\nWe prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, 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_preimage_linear_map` : when `f` is a linear map with nonzero determinant, the measure\n  of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the\n  determinant of `f`.\n* `add_haar_image_linear_map` : when `f` is a linear map, the measure of `f '' s` is the\n  measure of `s` multiplied by the absolute value of the determinant of `f`.\n* `add_haar_submodule` : a strict submodule has measure `0`.\n* `add_haar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`.\n* `add_haar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`.\n* `add_haar_closed_ball`: the measure of `closed_ball x r` is `r ^ dim * μ (ball 0 1)`.\n* `add_haar_sphere`: spheres have zero measure.\n\nThis makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`.\nThis measure is called `alternating_map.measure`. Its main property is\n`ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned\nby vectors `v₁, ..., vₙ` is given by `|ω v|`.\n\nWe also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has\ndensity one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in\n`tendsto_add_haar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for\nsmall `r`, see `eventually_nonempty_inter_smul_of_density_one`.\n-/\n\n\nopen TopologicalSpace Set Filter Metric\n\nopen ENNReal Pointwise Topology NNReal\n\n/-- The interval `[0,1]` as a compact set with non-empty interior. -/\ndef TopologicalSpace.PositiveCompacts.icc01 : PositiveCompacts ℝ\n    where\n  carrier := Icc 0 1\n  is_compact' := isCompact_Icc\n  interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]\n#align topological_space.positive_compacts.Icc01 TopologicalSpace.PositiveCompacts.icc01\n\nuniverse u\n\n/-- The set `[0,1]^ι` as a compact set with non-empty interior. -/\ndef TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type _) [Fintype ι] : PositiveCompacts (ι → ℝ)\n    where\n  carrier := pi univ fun i => Icc 0 1\n  is_compact' := isCompact_univ_pi fun i => isCompact_Icc\n  interior_nonempty' := by\n    simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,\n      imp_true_iff, zero_lt_one]\n#align topological_space.positive_compacts.pi_Icc01 TopologicalSpace.PositiveCompacts.piIcc01\n\nnamespace MeasureTheory\n\nopen Measure TopologicalSpace.PositiveCompacts FiniteDimensional\n\n/-!\n### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`.\n-/\n\n\n/-- The Haar measure equals the Lebesgue measure on `ℝ`. -/\ntheorem add_haar_measure_eq_volume : add_haar_measure icc01 = volume :=\n  by\n  convert(add_haar_measure_unique volume Icc01).symm\n  simp [Icc01]\n#align measure_theory.add_haar_measure_eq_volume MeasureTheory.add_haar_measure_eq_volume\n\n/-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/\ntheorem add_haar_measure_eq_volume_pi (ι : Type _) [Fintype ι] :\n    add_haar_measure (piIcc01 ι) = volume :=\n  by\n  convert(add_haar_measure_unique volume (pi_Icc01 ι)).symm\n  simp only [pi_Icc01, volume_pi_pi fun i => Icc (0 : ℝ) 1, positive_compacts.coe_mk,\n    compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero]\n#align measure_theory.add_haar_measure_eq_volume_pi MeasureTheory.add_haar_measure_eq_volume_pi\n\ninstance isAddHaarMeasureVolumePi (ι : Type _) [Fintype ι] :\n    IsAddHaarMeasure (volume : Measure (ι → ℝ)) :=\n  by\n  rw [← add_haar_measure_eq_volume_pi]\n  infer_instance\n#align measure_theory.is_add_haar_measure_volume_pi MeasureTheory.isAddHaarMeasureVolumePi\n\nnamespace Measure\n\n/-!\n### Strict subspaces have zero measure\n-/\n\n\n/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure\nzero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/\ntheorem add_haar_eq_zero_of_disjoint_translates_aux {E : Type _} [NormedAddCommGroup E]\n    [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)\n    [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : Bounded s) (hu : Bounded (range u))\n    (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 :=\n  by\n  by_contra h\n  apply lt_irrefl ∞\n  calc\n    ∞ = ∑' n : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm\n    _ = ∑' n : ℕ, μ ({u n} + s) := by\n      congr 1\n      ext1 n\n      simp only [image_add_left, measure_preimage_add, singleton_add]\n    _ = μ (⋃ n, {u n} + s) := by\n      rw [measure_Union hs fun n => by\n          simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's]\n    _ = μ (range u + s) := by rw [← Union_add, Union_singleton_eq_range]\n    _ < ∞ := bounded.measure_lt_top (hu.add sb)\n    \n#align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates_aux MeasureTheory.Measure.add_haar_eq_zero_of_disjoint_translates_aux\n\n/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure\nzero. -/\ntheorem add_haar_eq_zero_of_disjoint_translates {E : Type _} [NormedAddCommGroup E]\n    [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)\n    [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : Bounded (range u))\n    (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 :=\n  by\n  suffices H : ∀ R, μ (s ∩ closed_ball 0 R) = 0\n  · apply le_antisymm _ (zero_le _)\n    calc\n      μ s ≤ ∑' n : ℕ, μ (s ∩ closed_ball 0 n) :=\n        by\n        conv_lhs => rw [← Union_inter_closed_ball_nat s 0]\n        exact measure_Union_le _\n      _ = 0 := by simp only [H, tsum_zero]\n      \n  intro R\n  apply\n    add_haar_eq_zero_of_disjoint_translates_aux μ u\n      (bounded.mono (inter_subset_right _ _) bounded_closed_ball) hu _\n      (h's.inter measurableSet_closedBall)\n  apply pairwise_disjoint_mono hs fun n => _\n  exact add_subset_add (subset.refl _) (inter_subset_left _ _)\n#align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates MeasureTheory.Measure.add_haar_eq_zero_of_disjoint_translates\n\n/-- A strict vector subspace has measure zero. -/\ntheorem add_haar_submodule {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E]\n    [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E)\n    (hs : s ≠ ⊤) : μ s = 0 :=\n  by\n  obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by\n    simpa only [Submodule.eq_top_iff', not_exists, Ne.def, not_forall] using hs\n  obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩\n  have A : bounded (range fun n : ℕ => c ^ n • x) :=\n    haveI : tendsto (fun n : ℕ => c ^ n • x) at_top (𝓝 ((0 : ℝ) • x)) :=\n      (tendsto_pow_atTop_nhds_0_of_lt_1 cpos.le cone).smul_const x\n    bounded_range_of_tendsto _ this\n  apply\n    add_haar_eq_zero_of_disjoint_translates μ _ A _\n      (Submodule.closed_of_finiteDimensional s).MeasurableSet\n  intro m n hmn\n  simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage,\n    SetLike.mem_coe]\n  intro y hym hyn\n  have A : (c ^ n - c ^ m) • x ∈ s := by\n    convert s.sub_mem hym hyn\n    simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub]\n  have H : c ^ n - c ^ m ≠ 0 := by\n    simpa only [sub_eq_zero, Ne.def] using (strictAnti_pow cpos cone).Injective.Ne hmn.symm\n  have : x ∈ s := by\n    convert s.smul_mem (c ^ n - c ^ m)⁻¹ A\n    rw [smul_smul, inv_mul_cancel H, one_smul]\n  exact hx this\n#align measure_theory.measure.add_haar_submodule MeasureTheory.Measure.add_haar_submodule\n\n/-- A strict affine subspace has measure zero. -/\ntheorem add_haar_affineSubspace {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E]\n    [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]\n    (s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 :=\n  by\n  rcases s.eq_bot_or_nonempty with (rfl | hne)\n  · rw [AffineSubspace.bot_coe, measure_empty]\n  rw [Ne.def, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs\n  rcases hne with ⟨x, hx : x ∈ s⟩\n  simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg,\n    image_add_right, neg_neg, measure_preimage_add_right] using add_haar_submodule μ s.direction hs\n#align measure_theory.measure.add_haar_affine_subspace MeasureTheory.Measure.add_haar_affineSubspace\n\n/-!\n### Applying a linear map rescales Haar measure by the determinant\n\nWe first prove this on `ι → ℝ`, 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 `ι → ℝ`, and arguing that such a\nlinear equiv maps Haar measure to Haar measure.\n-/\n\n\ntheorem map_linearMap_add_haar_pi_eq_smul_add_haar {ι : Type _} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ}\n    (hf : f.det ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] :\n    Measure.map f μ = ENNReal.ofReal (abs f.det⁻¹) • μ :=\n  by\n  cases nonempty_fintype ι\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 μ (pi_Icc01 ι)\n  rw [this, add_haar_measure_eq_volume_pi, measure.map_smul,\n    Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm]\n#align measure_theory.measure.map_linear_map_add_haar_pi_eq_smul_add_haar MeasureTheory.Measure.map_linearMap_add_haar_pi_eq_smul_add_haar\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]\n  [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {F : Type _} [NormedAddCommGroup F]\n  [NormedSpace ℝ F] [CompleteSpace F]\n\ntheorem map_linearMap_add_haar_eq_smul_add_haar {f : E →ₗ[ℝ] E} (hf : f.det ≠ 0) :\n    Measure.map f μ = ENNReal.ofReal (abs f.det⁻¹) • μ :=\n  by\n  -- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using\n  -- matrices in `map_linear_map_add_haar_pi_eq_smul_add_haar`.\n  let ι := Fin (finrank ℝ E)\n  haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance\n  have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp\n  have e : E ≃ₗ[ℝ] ι → ℝ := linear_equiv.of_finrank_eq E (ι → ℝ) this\n  -- next line is to avoid `g` getting reduced by `simp`.\n  obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩\n  have gdet : g.det = f.det := by\n    rw [hg]\n    exact LinearMap.det_conj f e\n  rw [← gdet] at hf⊢\n  have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) :=\n    by\n    ext x\n    simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp,\n      LinearEquiv.symm_apply_apply, hg]\n  simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp]\n  have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional\n  have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g\n  have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional\n  rw [← map_map Cesymm.measurable (Cg.comp Ce).Measurable, ← map_map Cg.measurable Ce.measurable]\n  haveI : is_add_haar_measure (map e μ) := (e : E ≃+ (ι → ℝ)).is_add_haar_measure_map μ Ce Cesymm\n  have ecomp : e.symm ∘ e = id := by\n    ext x\n    simp only [id.def, Function.comp_apply, LinearEquiv.symm_apply_apply]\n  rw [map_linear_map_add_haar_pi_eq_smul_add_haar hf (map e μ), measure.map_smul,\n    map_map Cesymm.measurable Ce.measurable, ecomp, measure.map_id]\n#align measure_theory.measure.map_linear_map_add_haar_eq_smul_add_haar MeasureTheory.Measure.map_linearMap_add_haar_eq_smul_add_haar\n\n/-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure\nequal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : f.det ≠ 0) (s : Set E) :\n    μ (f ⁻¹' s) = ENNReal.ofReal (abs f.det⁻¹) * μ s :=\n  calc\n    μ (f ⁻¹' s) = Measure.map f μ s :=\n      ((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply\n          s).symm\n    _ = ENNReal.ofReal (abs f.det⁻¹) * μ s :=\n      by\n      rw [map_linear_map_add_haar_eq_smul_add_haar μ hf]\n      rfl\n    \n#align measure_theory.measure.add_haar_preimage_linear_map MeasureTheory.Measure.add_haar_preimage_linearMap\n\n/-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure\nequal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_preimage_continuousLinearMap {f : E →L[ℝ] E}\n    (hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) :\n    μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s :=\n  add_haar_preimage_linearMap μ hf s\n#align measure_theory.measure.add_haar_preimage_continuous_linear_map MeasureTheory.Measure.add_haar_preimage_continuousLinearMap\n\n/-- The preimage of a set `s` under a linear equiv `f` has measure\nequal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) :\n    μ (f ⁻¹' s) = ENNReal.ofReal (abs (f.symm : E →ₗ[ℝ] E).det) * μ s :=\n  by\n  have A : (f : E →ₗ[ℝ] E).det ≠ 0 := (LinearEquiv.isUnit_det' f).NeZero\n  convert add_haar_preimage_linear_map μ A s\n  simp only [LinearEquiv.det_coe_symm]\n#align measure_theory.measure.add_haar_preimage_linear_equiv MeasureTheory.Measure.add_haar_preimage_linearEquiv\n\n/-- The preimage of a set `s` under a continuous linear equiv `f` has measure\nequal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :\n    μ (f ⁻¹' s) = ENNReal.ofReal (abs (f.symm : E →ₗ[ℝ] E).det) * μ s :=\n  add_haar_preimage_linearEquiv μ _ s\n#align measure_theory.measure.add_haar_preimage_continuous_linear_equiv MeasureTheory.Measure.add_haar_preimage_continuousLinearEquiv\n\n/-- The image of a set `s` under a linear map `f` has measure\nequal to `μ s` times the absolute value of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) :\n    μ (f '' s) = ENNReal.ofReal (abs f.det) * μ s :=\n  by\n  rcases ne_or_eq f.det 0 with (hf | hf)\n  · let g := (f.equiv_of_det_ne_zero hf).toContinuousLinearEquiv\n    change μ (g '' s) = _\n    rw [ContinuousLinearEquiv.image_eq_preimage g s, add_haar_preimage_continuous_linear_equiv]\n    congr\n    ext x\n    simp only [LinearEquiv.coe_toContinuousLinearEquiv, LinearEquiv.ofIsUnitDet_apply,\n      LinearEquiv.coe_coe, ContinuousLinearEquiv.symm_symm]\n  · simp only [hf, MulZeroClass.zero_mul, ENNReal.ofReal_zero, abs_zero]\n    have : μ f.range = 0 := add_haar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).Ne\n    exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _)\n#align measure_theory.measure.add_haar_image_linear_map MeasureTheory.Measure.add_haar_image_linearMap\n\n/-- The image of a set `s` under a continuous linear map `f` has measure\nequal to `μ s` times the absolute value of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) :\n    μ (f '' s) = ENNReal.ofReal (abs (f : E →ₗ[ℝ] E).det) * μ s :=\n  add_haar_image_linearMap μ _ s\n#align measure_theory.measure.add_haar_image_continuous_linear_map MeasureTheory.Measure.add_haar_image_continuousLinearMap\n\n/-- The image of a set `s` under a continuous linear equiv `f` has measure\nequal to `μ s` times the absolute value of the determinant of `f`. -/\n@[simp]\ntheorem add_haar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :\n    μ (f '' s) = ENNReal.ofReal (abs (f : E →ₗ[ℝ] E).det) * μ s :=\n  μ.add_haar_image_linearMap (f : E →ₗ[ℝ] E) s\n#align measure_theory.measure.add_haar_image_continuous_linear_equiv MeasureTheory.Measure.add_haar_image_continuousLinearEquiv\n\n/-!\n### Basic properties of Haar measures on real vector spaces\n-/\n\n\ntheorem map_add_haar_smul {r : ℝ} (hr : r ≠ 0) :\n    Measure.map ((· • ·) r) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ :=\n  by\n  let f : E →ₗ[ℝ] E := r • 1\n  change measure.map f μ = _\n  have hf : f.det ≠ 0 :=\n    by\n    simp only [mul_one, LinearMap.det_smul, Ne.def, MonoidHom.map_one]\n    intro h\n    exact hr (pow_eq_zero h)\n  simp only [map_linear_map_add_haar_eq_smul_add_haar μ hf, mul_one, LinearMap.det_smul,\n    MonoidHom.map_one]\n#align measure_theory.measure.map_add_haar_smul MeasureTheory.Measure.map_add_haar_smul\n\n@[simp]\ntheorem add_haar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) :\n    μ ((· • ·) r ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s :=\n  calc\n    μ ((· • ·) r ⁻¹' s) = Measure.map ((· • ·) r) μ s :=\n      ((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).Unit).toMeasurableEquiv.map_apply s).symm\n    _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s :=\n      by\n      rw [map_add_haar_smul μ hr]\n      rfl\n    \n#align measure_theory.measure.add_haar_preimage_smul MeasureTheory.Measure.add_haar_preimage_smul\n\n/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/\n@[simp]\ntheorem add_haar_smul (r : ℝ) (s : Set E) :\n    μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s :=\n  by\n  rcases ne_or_eq r 0 with (h | rfl)\n  · rw [← preimage_smul_inv₀ h, add_haar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv]\n  rcases eq_empty_or_nonempty s with (rfl | hs)\n  · simp only [measure_empty, MulZeroClass.mul_zero, smul_set_empty]\n  rw [zero_smul_set hs, ← singleton_zero]\n  by_cases h : finrank ℝ E = 0\n  · haveI : Subsingleton E := finrank_zero_iff.1 h\n    simp only [h, one_mul, ENNReal.ofReal_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, MulZeroClass.zero_mul, ENNReal.ofReal_zero, abs_zero, Ne.def, not_false_iff,\n      zero_pow', measure_singleton]\n#align measure_theory.measure.add_haar_smul MeasureTheory.Measure.add_haar_smul\n\n@[simp]\ntheorem add_haar_image_homothety (x : E) (r : ℝ) (s : Set E) :\n    μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s :=\n  calc\n    μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) :=\n      by\n      simp only [← image_smul, image_image, ← sub_eq_add_neg]\n      rfl\n    _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by\n      simp only [image_add_right, measure_preimage_add_right, add_haar_smul]\n    \n#align measure_theory.measure.add_haar_image_homothety MeasureTheory.Measure.add_haar_image_homothety\n\n/-- The integral of `f (R • x)` with respect to an additive Haar measure is a multiple of the\nintegral of `f`. The formula we give works even when `f` is not integrable or `R = 0`\nthanks to the convention that a non-integrable function has integral zero. -/\ntheorem integral_comp_smul (f : E → F) (R : ℝ) :\n    (∫ x, f (R • x) ∂μ) = |(R ^ finrank ℝ E)⁻¹| • ∫ x, f x ∂μ :=\n  by\n  rcases eq_or_ne R 0 with (rfl | hR)\n  · simp only [zero_smul, integral_const]\n    rcases Nat.eq_zero_or_pos (finrank ℝ E) with (hE | hE)\n    · have : Subsingleton E := finrank_zero_iff.1 hE\n      have : f = fun x => f 0 := by\n        ext x\n        rw [Subsingleton.elim x 0]\n      conv_rhs => rw [this]\n      simp only [hE, pow_zero, inv_one, abs_one, one_smul, integral_const]\n    · have : Nontrivial E := finrank_pos_iff.1 hE\n      simp only [zero_pow hE, measure_univ_of_is_add_left_invariant, ENNReal.top_toReal, zero_smul,\n        inv_zero, abs_zero]\n  ·\n    calc\n      (∫ x, f (R • x) ∂μ) = ∫ y, f y ∂measure.map (fun x => R • x) μ :=\n        (integral_map_equiv (Homeomorph.smul (isUnit_iff_ne_zero.2 hR).Unit).toMeasurableEquiv\n            f).symm\n      _ = |(R ^ finrank ℝ E)⁻¹| • ∫ x, f x ∂μ := by\n        simp only [map_add_haar_smul μ hR, integral_smul_measure, ENNReal.toReal_ofReal, abs_nonneg]\n      \n#align measure_theory.measure.integral_comp_smul MeasureTheory.Measure.integral_comp_smul\n\n/-- The integral of `f (R • x)` with respect to an additive Haar measure is a multiple of the\nintegral of `f`. The formula we give works even when `f` is not integrable or `R = 0`\nthanks to the convention that a non-integrable function has integral zero. -/\ntheorem integral_comp_smul_of_nonneg (f : E → F) (R : ℝ) {hR : 0 ≤ R} :\n    (∫ x, f (R • x) ∂μ) = (R ^ finrank ℝ E)⁻¹ • ∫ x, f x ∂μ := by\n  rw [integral_comp_smul μ f R, abs_of_nonneg (inv_nonneg.2 (pow_nonneg hR _))]\n#align measure_theory.measure.integral_comp_smul_of_nonneg MeasureTheory.Measure.integral_comp_smul_of_nonneg\n\n/-- The integral of `f (R⁻¹ • x)` with respect to an additive Haar measure is a multiple of the\nintegral of `f`. The formula we give works even when `f` is not integrable or `R = 0`\nthanks to the convention that a non-integrable function has integral zero. -/\ntheorem integral_comp_inv_smul (f : E → F) (R : ℝ) :\n    (∫ x, f (R⁻¹ • x) ∂μ) = |R ^ finrank ℝ E| • ∫ x, f x ∂μ := by\n  rw [integral_comp_smul μ f R⁻¹, inv_pow, inv_inv]\n#align measure_theory.measure.integral_comp_inv_smul MeasureTheory.Measure.integral_comp_inv_smul\n\n/-- The integral of `f (R⁻¹ • x)` with respect to an additive Haar measure is a multiple of the\nintegral of `f`. The formula we give works even when `f` is not integrable or `R = 0`\nthanks to the convention that a non-integrable function has integral zero. -/\ntheorem integral_comp_inv_smul_of_nonneg (f : E → F) {R : ℝ} (hR : 0 ≤ R) :\n    (∫ x, f (R⁻¹ • x) ∂μ) = R ^ finrank ℝ E • ∫ x, f x ∂μ := by\n  rw [integral_comp_inv_smul μ f R, abs_of_nonneg (pow_nonneg hR _)]\n#align measure_theory.measure.integral_comp_inv_smul_of_nonneg MeasureTheory.Measure.integral_comp_inv_smul_of_nonneg\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\n/-! ### Measure of balls -/\n\n\ntheorem add_haar_ball_center {E : Type _} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E]\n    (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) :=\n  by\n  have : ball (0 : E) r = (· + ·) x ⁻¹' ball x r := by simp [preimage_add_ball]\n  rw [this, measure_preimage_add]\n#align measure_theory.measure.add_haar_ball_center MeasureTheory.Measure.add_haar_ball_center\n\ntheorem add_haar_closedBall_center {E : Type _} [NormedAddCommGroup E] [MeasurableSpace E]\n    [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :\n    μ (closedBall x r) = μ (closedBall (0 : E) r) :=\n  by\n  have : closed_ball (0 : E) r = (· + ·) x ⁻¹' closed_ball x r := by simp [preimage_add_closedBall]\n  rw [this, measure_preimage_add]\n#align measure_theory.measure.add_haar_closed_ball_center MeasureTheory.Measure.add_haar_closedBall_center\n\ntheorem add_haar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :\n    μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) :=\n  by\n  have : ball (0 : E) (r * s) = r • ball 0 s := by\n    simp only [smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero]\n  simp only [this, add_haar_smul, abs_of_nonneg hr.le, add_haar_ball_center, abs_pow]\n#align measure_theory.measure.add_haar_ball_mul_of_pos MeasureTheory.Measure.add_haar_ball_mul_of_pos\n\ntheorem add_haar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) :\n    μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by\n  rw [← add_haar_ball_mul_of_pos μ x hr, mul_one]\n#align measure_theory.measure.add_haar_ball_of_pos MeasureTheory.Measure.add_haar_ball_of_pos\n\ntheorem add_haar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) :\n    μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) :=\n  by\n  rcases LE.le.eq_or_lt hr with (h | h)\n  ·\n    simp only [← h, zero_pow finrank_pos, measure_empty, MulZeroClass.zero_mul, ENNReal.ofReal_zero,\n      ball_zero]\n  · exact add_haar_ball_mul_of_pos μ x h s\n#align measure_theory.measure.add_haar_ball_mul MeasureTheory.Measure.add_haar_ball_mul\n\ntheorem add_haar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) :\n    μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by\n  rw [← add_haar_ball_mul μ x hr, mul_one]\n#align measure_theory.measure.add_haar_ball MeasureTheory.Measure.add_haar_ball\n\ntheorem add_haar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :\n    μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) :=\n  by\n  have : closed_ball (0 : E) (r * s) = r • closed_ball 0 s := by\n    simp [smul_closed_ball' hr.ne' (0 : E), abs_of_nonneg hr.le]\n  simp only [this, add_haar_smul, abs_of_nonneg hr.le, add_haar_closed_ball_center, abs_pow]\n#align measure_theory.measure.add_haar_closed_ball_mul_of_pos MeasureTheory.Measure.add_haar_closedBall_mul_of_pos\n\ntheorem add_haar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) :\n    μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) :=\n  by\n  have : closed_ball (0 : E) (r * s) = r • closed_ball 0 s := by\n    simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr]\n  simp only [this, add_haar_smul, abs_of_nonneg hr, add_haar_closed_ball_center, abs_pow]\n#align measure_theory.measure.add_haar_closed_ball_mul MeasureTheory.Measure.add_haar_closedBall_mul\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. -/\ntheorem add_haar_closed_ball' (x : E) {r : ℝ} (hr : 0 ≤ r) :\n    μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by\n  rw [← add_haar_closed_ball_mul μ x hr zero_le_one, mul_one]\n#align measure_theory.measure.add_haar_closed_ball' MeasureTheory.Measure.add_haar_closed_ball'\n\ntheorem add_haar_closed_unit_ball_eq_add_haar_unit_ball : μ (closedBall (0 : E) 1) = μ (ball 0 1) :=\n  by\n  apply le_antisymm _ (measure_mono ball_subset_closed_ball)\n  have A :\n    tendsto (fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closed_ball (0 : E) 1)) (𝓝[<] 1)\n      (𝓝 (ENNReal.ofReal (1 ^ finrank ℝ E) * μ (closed_ball (0 : E) 1))) :=\n    by\n    refine' ENNReal.Tendsto.mul _ (by simp) tendsto_const_nhds (by simp)\n    exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _)\n  simp only [one_pow, one_mul, ENNReal.ofReal_one] at A\n  refine' le_of_tendsto A _\n  refine' mem_nhdsWithin_Iio_iff_exists_Ioo_subset.2 ⟨(0 : ℝ), by simp, fun r hr => _⟩\n  dsimp\n  rw [← add_haar_closed_ball' μ (0 : E) hr.1.le]\n  exact measure_mono (closed_ball_subset_ball hr.2)\n#align measure_theory.measure.add_haar_closed_unit_ball_eq_add_haar_unit_ball MeasureTheory.Measure.add_haar_closed_unit_ball_eq_add_haar_unit_ball\n\ntheorem add_haar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) :\n    μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by\n  rw [add_haar_closed_ball' μ x hr, add_haar_closed_unit_ball_eq_add_haar_unit_ball]\n#align measure_theory.measure.add_haar_closed_ball MeasureTheory.Measure.add_haar_closedBall\n\ntheorem add_haar_closedBall_eq_add_haar_ball [Nontrivial E] (x : E) (r : ℝ) :\n    μ (closedBall x r) = μ (ball x r) :=\n  by\n  by_cases h : r < 0\n  · rw [metric.closed_ball_eq_empty.mpr h, metric.ball_eq_empty.mpr h.le]\n  push_neg  at h\n  rw [add_haar_closed_ball μ x h, add_haar_ball μ x h]\n#align measure_theory.measure.add_haar_closed_ball_eq_add_haar_ball MeasureTheory.Measure.add_haar_closedBall_eq_add_haar_ball\n\ntheorem add_haar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 :=\n  by\n  rcases hr.lt_or_lt with (h | h)\n  · simp only [empty_diff, measure_empty, ← closed_ball_diff_ball, closed_ball_eq_empty.2 h]\n  ·\n    rw [← closed_ball_diff_ball,\n        measure_diff ball_subset_closed_ball measurableSet_ball measure_ball_lt_top.ne,\n        add_haar_ball_of_pos μ _ h, add_haar_closed_ball μ _ h.le, tsub_self] <;>\n      infer_instance\n#align measure_theory.measure.add_haar_sphere_of_ne_zero MeasureTheory.Measure.add_haar_sphere_of_ne_zero\n\ntheorem add_haar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 :=\n  by\n  rcases eq_or_ne r 0 with (rfl | h)\n  · rw [sphere_zero, measure_singleton]\n  · exact add_haar_sphere_of_ne_zero μ x h\n#align measure_theory.measure.add_haar_sphere MeasureTheory.Measure.add_haar_sphere\n\ntheorem add_haar_singleton_add_smul_div_singleton_add_smul {r : ℝ} (hr : r ≠ 0) (x y : E)\n    (s t : Set E) : μ ({x} + r • s) / μ ({y} + r • t) = μ s / μ t :=\n  calc\n    μ ({x} + r • s) / μ ({y} + r • t) =\n        ENNReal.ofReal (|r| ^ finrank ℝ E) * μ s * (ENNReal.ofReal (|r| ^ finrank ℝ E) * μ t)⁻¹ :=\n      by\n      simp only [div_eq_mul_inv, add_haar_smul, image_add_left, measure_preimage_add, abs_pow,\n        singleton_add]\n    _ =\n        ENNReal.ofReal (|r| ^ finrank ℝ E) * (ENNReal.ofReal (|r| ^ finrank ℝ E))⁻¹ *\n          (μ s * (μ t)⁻¹) :=\n      by\n      rw [ENNReal.mul_inv]\n      · ring\n      · simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne.def, true_or_iff]\n      · simp only [ENNReal.ofReal_ne_top, true_or_iff, Ne.def, not_false_iff]\n    _ = μ s / μ t := by\n      rw [ENNReal.mul_inv_cancel, one_mul, div_eq_mul_inv]\n      · simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne.def]\n      · simp only [ENNReal.ofReal_ne_top, Ne.def, not_false_iff]\n    \n#align measure_theory.measure.add_haar_singleton_add_smul_div_singleton_add_smul MeasureTheory.Measure.add_haar_singleton_add_smul_div_singleton_add_smul\n\ninstance (priority := 100) isDoublingMeasureOfIsAddHaarMeasure : IsDoublingMeasure μ :=\n  by\n  refine' ⟨⟨(2 : ℝ≥0) ^ finrank ℝ E, _⟩⟩\n  filter_upwards [self_mem_nhdsWithin]with r hr x\n  rw [add_haar_closed_ball_mul μ x zero_le_two (le_of_lt hr), add_haar_closed_ball_center μ x,\n    ENNReal.ofReal, Real.toNNReal_pow zero_le_two]\n  simp only [[anonymous], Real.toNNReal_one, le_refl]\n#align measure_theory.measure.is_doubling_measure_of_is_add_haar_measure MeasureTheory.Measure.isDoublingMeasureOfIsAddHaarMeasure\n\nsection\n\n/-!\n### The Lebesgue measure associated to an alternating map\n-/\n\n\nvariable {ι G : Type _} [Fintype ι] [DecidableEq ι] [NormedAddCommGroup G] [NormedSpace ℝ G]\n  [MeasurableSpace G] [BorelSpace G]\n\ntheorem addHaar_parallelepiped (b : Basis ι ℝ G) (v : ι → G) :\n    b.add_haar (parallelepiped v) = ENNReal.ofReal (|b.det v|) :=\n  by\n  have : FiniteDimensional ℝ G := FiniteDimensional.of_fintype_basis b\n  have A : parallelepiped v = b.constr ℕ v '' parallelepiped b :=\n    by\n    rw [image_parallelepiped]\n    congr 1 with i\n    exact (b.constr_basis ℕ v i).symm\n  rw [A, add_haar_image_linear_map, Basis.addHaar_self, mul_one, ← LinearMap.det_toMatrix b, ←\n    Basis.toMatrix_eq_toMatrix_constr]\n  rfl\n#align measure_theory.measure.add_haar_parallelepiped MeasureTheory.Measure.addHaar_parallelepiped\n\nvariable [FiniteDimensional ℝ G] {n : ℕ} [_i : Fact (finrank ℝ G = n)]\n\ninclude _i\n\n/-- The Lebesgue measure associated to an alternating map. It gives measure `|ω v|` to the\nparallelepiped spanned by the vectors `v₁, ..., vₙ`. Note that it is not always a Haar measure,\nas it can be zero, but it is always locally finite and translation invariant. -/\nnoncomputable irreducible_def AlternatingMap.measure (ω : AlternatingMap ℝ G ℝ (Fin n)) :\n  Measure G :=\n  ‖ω (finBasisOfFinrankEq ℝ G _i.out)‖₊ • (finBasisOfFinrankEq ℝ G _i.out).add_haar\n#align alternating_map.measure AlternatingMap.measure\n\ntheorem AlternatingMap.measure_parallelepiped (ω : AlternatingMap ℝ G ℝ (Fin n)) (v : Fin n → G) :\n    ω.Measure (parallelepiped v) = ENNReal.ofReal (|ω v|) :=\n  by\n  conv_rhs => rw [ω.eq_smul_basis_det (fin_basis_of_finrank_eq ℝ G _i.out)]\n  simp only [add_haar_parallelepiped, AlternatingMap.measure, coe_nnreal_smul_apply,\n    AlternatingMap.smul_apply, Algebra.id.smul_eq_mul, abs_mul, ENNReal.ofReal_mul (abs_nonneg _),\n    Real.ennnorm_eq_ofReal_abs]\n#align alternating_map.measure_parallelepiped AlternatingMap.measure_parallelepiped\n\ninstance (ω : AlternatingMap ℝ G ℝ (Fin n)) : IsAddLeftInvariant ω.Measure :=\n  by\n  rw [AlternatingMap.measure]\n  infer_instance\n\ninstance (ω : AlternatingMap ℝ G ℝ (Fin n)) : IsLocallyFiniteMeasure ω.Measure :=\n  by\n  rw [AlternatingMap.measure]\n  infer_instance\n\nend\n\n/-!\n### Density points\n\nBesicovitch covering theorem ensures that, for any locally finite measure on a finite-dimensional\nreal vector space, almost every point of a set `s` is a density point, i.e.,\n`μ (s ∩ closed_ball x r) / μ (closed_ball x r)` tends to `1` as `r` tends to `0`\n(see `besicovitch.ae_tendsto_measure_inter_div`).\nWhen `μ` is a Haar measure, one can deduce the same property for any rescaling sequence of sets,\nof the form `{x} + r • t` where `t` is a set with positive finite measure, instead of the sequence\nof closed balls.\n\nWe argue first for the dual property, i.e., if `s` has density `0` at `x`, then\n`μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)` tends to `0`. First when `t` is contained in the ball\nof radius `1`, in `tendsto_add_haar_inter_smul_zero_of_density_zero_aux1`,\n(by arguing by inclusion). Then when `t` is bounded, reducing to the previous one by rescaling, in\n`tendsto_add_haar_inter_smul_zero_of_density_zero_aux2`.\nThen for a general set `t`, by cutting it into a bounded part and a part with small measure, in\n`tendsto_add_haar_inter_smul_zero_of_density_zero`.\nGoing to the complement, one obtains the desired property at points of density `1`, first when\n`s` is measurable in `tendsto_add_haar_inter_smul_one_of_density_one_aux`, and then without this\nassumption in `tendsto_add_haar_inter_smul_one_of_density_one` by applying the previous lemma to\nthe measurable hull `to_measurable μ s`\n-/\n\n\ntheorem tendsto_add_haar_inter_smul_zero_of_density_zero_aux1 (s : Set E) (x : E)\n    (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)\n    (u : Set E) (h'u : μ u ≠ 0) (t_bound : t ⊆ closedBall 0 1) :\n    Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) (𝓝[>] 0) (𝓝 0) :=\n  by\n  have A : tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ (closed_ball x r)) (𝓝[>] 0) (𝓝 0) :=\n    by\n    apply\n      tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds h\n        (eventually_of_forall fun b => zero_le _)\n    filter_upwards [self_mem_nhdsWithin]\n    rintro r (rpos : 0 < r)\n    apply mul_le_mul_right' (measure_mono (inter_subset_inter_right _ _)) _\n    intro y hy\n    have : y - x ∈ r • closed_ball (0 : E) 1 :=\n      by\n      apply smul_set_mono t_bound\n      simpa [neg_add_eq_sub] using hy\n    simpa only [smul_closedBall _ _ zero_le_one, Real.norm_of_nonneg rpos.le,\n      mem_closedBall_iff_norm, mul_one, sub_zero, smul_zero]\n  have B :\n    tendsto (fun r : ℝ => μ (closed_ball x r) / μ ({x} + r • u)) (𝓝[>] 0)\n      (𝓝 (μ (closed_ball x 1) / μ ({x} + u))) :=\n    by\n    apply tendsto_const_nhds.congr' _\n    filter_upwards [self_mem_nhdsWithin]\n    rintro r (rpos : 0 < r)\n    have : closed_ball x r = {x} + r • closed_ball 0 1 := by\n      simp only [_root_.smul_closed_ball, Real.norm_of_nonneg rpos.le, zero_le_one, add_zero,\n        mul_one, singleton_add_closedBall, smul_zero]\n    simp only [this, add_haar_singleton_add_smul_div_singleton_add_smul μ rpos.ne']\n    simp only [add_haar_closed_ball_center, image_add_left, measure_preimage_add, singleton_add]\n  have C :\n    tendsto\n      (fun r : ℝ =>\n        μ (s ∩ ({x} + r • t)) / μ (closed_ball x r) * (μ (closed_ball x r) / μ ({x} + r • u)))\n      (𝓝[>] 0) (𝓝 (0 * (μ (closed_ball x 1) / μ ({x} + u)))) :=\n    by\n    apply ENNReal.Tendsto.mul A _ B (Or.inr ENNReal.zero_ne_top)\n    simp only [ENNReal.div_eq_top, h'u, measure_closed_ball_lt_top.ne, false_or_iff, image_add_left,\n      eq_self_iff_true, not_true, Ne.def, not_false_iff, measure_preimage_add, singleton_add,\n      and_false_iff, false_and_iff]\n  simp only [MulZeroClass.zero_mul] at C\n  apply C.congr' _\n  filter_upwards [self_mem_nhdsWithin]\n  rintro r (rpos : 0 < r)\n  calc\n    μ (s ∩ ({x} + r • t)) / μ (closed_ball x r) * (μ (closed_ball x r) / μ ({x} + r • u)) =\n        μ (closed_ball x r) * (μ (closed_ball x r))⁻¹ * (μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) :=\n      by\n      simp only [div_eq_mul_inv]\n      ring\n    _ = μ (s ∩ ({x} + r • t)) / μ ({x} + r • u) := by\n      rw [ENNReal.mul_inv_cancel (measure_closed_ball_pos μ x rpos).ne'\n          measure_closed_ball_lt_top.ne,\n        one_mul]\n    \n#align measure_theory.measure.tendsto_add_haar_inter_smul_zero_of_density_zero_aux1 MeasureTheory.Measure.tendsto_add_haar_inter_smul_zero_of_density_zero_aux1\n\ntheorem tendsto_add_haar_inter_smul_zero_of_density_zero_aux2 (s : Set E) (x : E)\n    (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)\n    (u : Set E) (h'u : μ u ≠ 0) (R : ℝ) (Rpos : 0 < R) (t_bound : t ⊆ closedBall 0 R) :\n    Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) (𝓝[>] 0) (𝓝 0) :=\n  by\n  set t' := R⁻¹ • t with ht'\n  set u' := R⁻¹ • u with hu'\n  have A : tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t')) / μ ({x} + r • u')) (𝓝[>] 0) (𝓝 0) :=\n    by\n    apply tendsto_add_haar_inter_smul_zero_of_density_zero_aux1 μ s x h t' u'\n    ·\n      simp only [h'u, (pow_pos Rpos _).ne', abs_nonpos_iff, add_haar_smul, not_false_iff,\n        ENNReal.ofReal_eq_zero, inv_eq_zero, inv_pow, Ne.def, or_self_iff, mul_eq_zero]\n    · convert smul_set_mono t_bound\n      rw [smul_closedBall _ _ Rpos.le, smul_zero, Real.norm_of_nonneg (inv_nonneg.2 Rpos.le),\n        inv_mul_cancel Rpos.ne']\n  have B : tendsto (fun r : ℝ => R * r) (𝓝[>] 0) (𝓝[>] (R * 0)) :=\n    by\n    apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within\n    · exact (tendsto_const_nhds.mul tendsto_id).mono_left nhdsWithin_le_nhds\n    · filter_upwards [self_mem_nhdsWithin]\n      intro r rpos\n      rw [MulZeroClass.mul_zero]\n      exact mul_pos Rpos rpos\n  rw [MulZeroClass.mul_zero] at B\n  apply (A.comp B).congr' _\n  filter_upwards [self_mem_nhdsWithin]\n  rintro r (rpos : 0 < r)\n  have T : (R * r) • t' = r • t := by\n    rw [mul_comm, ht', smul_smul, mul_assoc, mul_inv_cancel Rpos.ne', mul_one]\n  have U : (R * r) • u' = r • u := by\n    rw [mul_comm, hu', smul_smul, mul_assoc, mul_inv_cancel Rpos.ne', mul_one]\n  dsimp\n  rw [T, U]\n#align measure_theory.measure.tendsto_add_haar_inter_smul_zero_of_density_zero_aux2 MeasureTheory.Measure.tendsto_add_haar_inter_smul_zero_of_density_zero_aux2\n\n/-- Consider a point `x` at which a set `s` has density zero, with respect to closed balls. Then it\nalso has density zero with respect to any measurable set `t`: the proportion of points in `s`\nbelonging to a rescaled copy `{x} + r • t` of `t` tends to zero as `r` tends to zero. -/\ntheorem tendsto_add_haar_inter_smul_zero_of_density_zero (s : Set E) (x : E)\n    (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)\n    (ht : MeasurableSet t) (h''t : μ t ≠ ∞) :\n    Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 0) :=\n  by\n  refine' tendsto_order.2 ⟨fun a' ha' => (ENNReal.not_lt_zero ha').elim, fun ε (εpos : 0 < ε) => _⟩\n  rcases eq_or_ne (μ t) 0 with (h't | h't)\n  · apply eventually_of_forall fun r => _\n    suffices H : μ (s ∩ ({x} + r • t)) = 0\n    · rw [H]\n      simpa only [ENNReal.zero_div] using εpos\n    apply le_antisymm _ (zero_le _)\n    calc\n      μ (s ∩ ({x} + r • t)) ≤ μ ({x} + r • t) := measure_mono (inter_subset_right _ _)\n      _ = 0 := by\n        simp only [h't, add_haar_smul, image_add_left, measure_preimage_add, singleton_add,\n          MulZeroClass.mul_zero]\n      \n  obtain ⟨n, npos, hn⟩ : ∃ n : ℕ, 0 < n ∧ μ (t \\ closed_ball 0 n) < ε / 2 * μ t :=\n    by\n    have A :\n      tendsto (fun n : ℕ => μ (t \\ closed_ball 0 n)) at_top\n        (𝓝 (μ (⋂ n : ℕ, t \\ closed_ball 0 n))) :=\n      by\n      have N : ∃ n : ℕ, μ (t \\ closed_ball 0 n) ≠ ∞ :=\n        ⟨0, ((measure_mono (diff_subset t _)).trans_lt h''t.lt_top).Ne⟩\n      refine' tendsto_measure_Inter (fun n => ht.diff measurableSet_closedBall) (fun m n hmn => _) N\n      exact diff_subset_diff subset.rfl (closed_ball_subset_closed_ball (Nat.cast_le.2 hmn))\n    have : (⋂ n : ℕ, t \\ closed_ball 0 n) = ∅ := by\n      simp_rw [diff_eq, ← inter_Inter, Inter_eq_compl_Union_compl, compl_compl,\n        Union_closed_ball_nat, compl_univ, inter_empty]\n    simp only [this, measure_empty] at A\n    have I : 0 < ε / 2 * μ t := ENNReal.mul_pos (ENNReal.half_pos εpos.ne').ne' h't\n    exact (eventually.and (Ioi_mem_at_top 0) ((tendsto_order.1 A).2 _ I)).exists\n  have L :\n    tendsto (fun r : ℝ => μ (s ∩ ({x} + r • (t ∩ closed_ball 0 n))) / μ ({x} + r • t)) (𝓝[>] 0)\n      (𝓝 0) :=\n    tendsto_add_haar_inter_smul_zero_of_density_zero_aux2 μ s x h _ t h't n (Nat.cast_pos.2 npos)\n      (inter_subset_right _ _)\n  filter_upwards [(tendsto_order.1 L).2 _ (ENNReal.half_pos εpos.ne'), self_mem_nhdsWithin]\n  rintro r hr (rpos : 0 < r)\n  have I :\n    μ (s ∩ ({x} + r • t)) ≤\n      μ (s ∩ ({x} + r • (t ∩ closed_ball 0 n))) + μ ({x} + r • (t \\ closed_ball 0 n)) :=\n    calc\n      μ (s ∩ ({x} + r • t)) =\n          μ (s ∩ ({x} + r • (t ∩ closed_ball 0 n)) ∪ s ∩ ({x} + r • (t \\ closed_ball 0 n))) :=\n        by rw [← inter_union_distrib_left, ← add_union, ← smul_set_union, inter_union_diff]\n      _ ≤ μ (s ∩ ({x} + r • (t ∩ closed_ball 0 n))) + μ (s ∩ ({x} + r • (t \\ closed_ball 0 n))) :=\n        (measure_union_le _ _)\n      _ ≤ μ (s ∩ ({x} + r • (t ∩ closed_ball 0 n))) + μ ({x} + r • (t \\ closed_ball 0 n)) :=\n        add_le_add le_rfl (measure_mono (inter_subset_right _ _))\n      \n  calc\n    μ (s ∩ ({x} + r • t)) / μ ({x} + r • t) ≤\n        (μ (s ∩ ({x} + r • (t ∩ closed_ball 0 n))) + μ ({x} + r • (t \\ closed_ball 0 n))) /\n          μ ({x} + r • t) :=\n      mul_le_mul_right' I _\n    _ < ε / 2 + ε / 2 := by\n      rw [ENNReal.add_div]\n      apply ENNReal.add_lt_add hr _\n      rwa [add_haar_singleton_add_smul_div_singleton_add_smul μ rpos.ne',\n        ENNReal.div_lt_iff (Or.inl h't) (Or.inl h''t)]\n    _ = ε := ENNReal.add_halves _\n    \n#align measure_theory.measure.tendsto_add_haar_inter_smul_zero_of_density_zero MeasureTheory.Measure.tendsto_add_haar_inter_smul_zero_of_density_zero\n\ntheorem tendsto_add_haar_inter_smul_one_of_density_one_aux (s : Set E) (hs : MeasurableSet s)\n    (x : E) (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1))\n    (t : Set E) (ht : MeasurableSet t) (h't : μ t ≠ 0) (h''t : μ t ≠ ∞) :\n    Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) :=\n  by\n  have I :\n    ∀ u v, μ u ≠ 0 → μ u ≠ ∞ → MeasurableSet v → μ u / μ u - μ (vᶜ ∩ u) / μ u = μ (v ∩ u) / μ u :=\n    by\n    intro u v uzero utop vmeas\n    simp_rw [div_eq_mul_inv]\n    rw [← ENNReal.sub_mul]\n    swap\n    · simp only [uzero, ENNReal.inv_eq_top, imp_true_iff, Ne.def, not_false_iff]\n    congr 1\n    apply\n      ENNReal.sub_eq_of_add_eq (ne_top_of_le_ne_top utop (measure_mono (inter_subset_right _ _)))\n    rw [inter_comm _ u, inter_comm _ u]\n    exact measure_inter_add_diff u vmeas\n  have L : tendsto (fun r => μ (sᶜ ∩ closed_ball x r) / μ (closed_ball x r)) (𝓝[>] 0) (𝓝 0) :=\n    by\n    have A : tendsto (fun r => μ (closed_ball x r) / μ (closed_ball x r)) (𝓝[>] 0) (𝓝 1) :=\n      by\n      apply tendsto_const_nhds.congr' _\n      filter_upwards [self_mem_nhdsWithin]\n      intro r hr\n      rw [div_eq_mul_inv, ENNReal.mul_inv_cancel]\n      · exact (measure_closed_ball_pos μ _ hr).ne'\n      · exact measure_closed_ball_lt_top.ne\n    have B := ENNReal.Tendsto.sub A h (Or.inl ENNReal.one_ne_top)\n    simp only [tsub_self] at B\n    apply B.congr' _\n    filter_upwards [self_mem_nhdsWithin]\n    rintro r (rpos : 0 < r)\n    convert I (closed_ball x r) (sᶜ) (measure_closed_ball_pos μ _ rpos).ne'\n        measure_closed_ball_lt_top.Ne hs.compl\n    rw [compl_compl]\n  have L' : tendsto (fun r : ℝ => μ (sᶜ ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 0) :=\n    tendsto_add_haar_inter_smul_zero_of_density_zero μ (sᶜ) x L t ht h''t\n  have L'' : tendsto (fun r : ℝ => μ ({x} + r • t) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) :=\n    by\n    apply tendsto_const_nhds.congr' _\n    filter_upwards [self_mem_nhdsWithin]\n    rintro r (rpos : 0 < r)\n    rw [add_haar_singleton_add_smul_div_singleton_add_smul μ rpos.ne', ENNReal.div_self h't h''t]\n  have := ENNReal.Tendsto.sub L'' L' (Or.inl ENNReal.one_ne_top)\n  simp only [tsub_zero] at this\n  apply this.congr' _\n  filter_upwards [self_mem_nhdsWithin]\n  rintro r (rpos : 0 < r)\n  refine' I ({x} + r • t) s _ _ hs\n  ·\n    simp only [h't, abs_of_nonneg rpos.le, pow_pos rpos, add_haar_smul, image_add_left,\n      ENNReal.ofReal_eq_zero, not_le, or_false_iff, Ne.def, measure_preimage_add, abs_pow,\n      singleton_add, mul_eq_zero]\n  ·\n    simp only [h''t, ENNReal.ofReal_ne_top, add_haar_smul, image_add_left, WithTop.mul_eq_top_iff,\n      Ne.def, not_false_iff, measure_preimage_add, singleton_add, and_false_iff, false_and_iff,\n      or_self_iff]\n#align measure_theory.measure.tendsto_add_haar_inter_smul_one_of_density_one_aux MeasureTheory.Measure.tendsto_add_haar_inter_smul_one_of_density_one_aux\n\n/-- Consider a point `x` at which a set `s` has density one, with respect to closed balls (i.e.,\na Lebesgue density point of `s`). Then `s` has also density one at `x` with respect to any\nmeasurable set `t`: the proportion of points in `s` belonging to a rescaled copy `{x} + r • t`\nof `t` tends to one as `r` tends to zero. -/\ntheorem tendsto_add_haar_inter_smul_one_of_density_one (s : Set E) (x : E)\n    (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1)) (t : Set E)\n    (ht : MeasurableSet t) (h't : μ t ≠ 0) (h''t : μ t ≠ ∞) :\n    Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) :=\n  by\n  have :\n    tendsto (fun r : ℝ => μ (to_measurable μ s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) :=\n    by\n    apply\n      tendsto_add_haar_inter_smul_one_of_density_one_aux μ _ (measurable_set_to_measurable _ _) _ _\n        t ht h't h''t\n    apply tendsto_of_tendsto_of_tendsto_of_le_of_le' h tendsto_const_nhds\n    · refine' eventually_of_forall fun r => mul_le_mul_right' _ _\n      exact measure_mono (inter_subset_inter_left _ (subset_to_measurable _ _))\n    · filter_upwards [self_mem_nhdsWithin]\n      rintro r (rpos : 0 < r)\n      apply ENNReal.div_le_of_le_mul\n      rw [one_mul]\n      exact measure_mono (inter_subset_right _ _)\n  apply this.congr fun r => _\n  congr 1\n  apply measure_to_measurable_inter_of_sigma_finite\n  simp only [image_add_left, singleton_add]\n  apply (continuous_add_left (-x)).Measurable (ht.const_smul₀ r)\n#align measure_theory.measure.tendsto_add_haar_inter_smul_one_of_density_one MeasureTheory.Measure.tendsto_add_haar_inter_smul_one_of_density_one\n\n/-- Consider a point `x` at which a set `s` has density one, with respect to closed balls (i.e.,\na Lebesgue density point of `s`). Then `s` intersects the rescaled copies `{x} + r • t` of a given\nset `t` with positive measure, for any small enough `r`. -/\ntheorem eventually_nonempty_inter_smul_of_density_one (s : Set E) (x : E)\n    (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1)) (t : Set E)\n    (ht : MeasurableSet t) (h't : μ t ≠ 0) : ∀ᶠ r in 𝓝[>] (0 : ℝ), (s ∩ ({x} + r • t)).Nonempty :=\n  by\n  obtain ⟨t', t'_meas, t't, t'pos, t'top⟩ : ∃ t', MeasurableSet t' ∧ t' ⊆ t ∧ 0 < μ t' ∧ μ t' < ⊤ :=\n    exists_subset_measure_lt_top ht h't.bot_lt\n  filter_upwards [(tendsto_order.1\n          (tendsto_add_haar_inter_smul_one_of_density_one μ s x h t' t'_meas t'pos.ne' t'top.ne)).1\n      0 zero_lt_one]\n  intro r hr\n  have : μ (s ∩ ({x} + r • t')) ≠ 0 := fun h' => by\n    simpa only [ENNReal.not_lt_zero, ENNReal.zero_div, h'] using hr\n  have : (s ∩ ({x} + r • t')).Nonempty := nonempty_of_measure_ne_zero this\n  apply this.mono (inter_subset_inter subset.rfl _)\n  exact add_subset_add subset.rfl (smul_set_mono t't)\n#align measure_theory.measure.eventually_nonempty_inter_smul_of_density_one MeasureTheory.Measure.eventually_nonempty_inter_smul_of_density_one\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/HaarLebesgue.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8652240704135291, "lm_q1q2_score": 0.7779414531596855}}
{"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 algebraic_geometry.prime_spectrum.basic\nimport ring_theory.polynomial.basic\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\nopen ideal polynomial prime_spectrum set\n\nnamespace algebraic_geometry\n\nnamespace polynomial\n\nvariables {R : Type*} [comm_ring R] {f : polynomial R}\n\n/-- Given a polynomial `f ∈ 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})ᶜ` under the morphism\n`comap C : Spec R[x] → Spec R`. -/\ndef image_of_Df (f) : set (prime_spectrum R) :=\n  {p : prime_spectrum R | ∃ i : ℕ , (coeff f i) ∉ p.as_ideal}\n\nlemma is_open_image_of_Df : is_open (image_of_Df f) :=\nbegin\n  rw [image_of_Df, set_of_exists (λ i (x : prime_spectrum R), coeff f i ∉ x.val)],\n  exact is_open_Union (λ i, is_open_basic_open),\nend\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`. -/\nlemma comap_C_mem_image_of_Df {I : prime_spectrum (polynomial R)}\n  (H : I ∈ (zero_locus {f} : set (prime_spectrum (polynomial R)))ᶜ ) :\n  prime_spectrum.comap (polynomial.C : R →+* polynomial R) I ∈ image_of_Df f :=\nexists_coeff_not_mem_C_inverse (mem_compl_zero_locus_iff_not_mem.mp H)\n\n/-- The open set `image_of_Df f` coincides with the image of `basic_open f` under the\nmorphism `C⁺ : Spec R[x] → Spec R`. -/\nlemma image_of_Df_eq_comap_C_compl_zero_locus :\n  image_of_Df f = prime_spectrum.comap (C : R →+* polynomial R) '' (zero_locus {f})ᶜ :=\nbegin\n  refine ext (λ x, ⟨λ hx, ⟨⟨map C x.val, (is_prime_map_C_of_is_prime x.property)⟩, ⟨_, _⟩⟩, _⟩),\n  { rw [mem_compl_eq, mem_zero_locus, singleton_subset_iff],\n    cases hx with i hi,\n    exact λ a, hi (mem_map_C_iff.mp a i) },\n  { refine subtype.ext (ext (λ x, ⟨λ h, _, λ h, subset_span (mem_image_of_mem C.1 h)⟩)),\n    rw ← @coeff_C_zero R x _,\n    exact mem_map_C_iff.mp h 0 },\n  { rintro ⟨xli, complement, rfl⟩,\n    exact comap_C_mem_image_of_Df complement }\nend\n\n/--  The morphism `C⁺ : Spec R[x] → Spec R` is open.\nStacks Project \"Lemma 00FB\", first part.\n\nhttps://stacks.math.columbia.edu/tag/00FB\n-/\ntheorem is_open_map_comap_C :\n  is_open_map (prime_spectrum.comap (C : R →+* polynomial R)) :=\nbegin\n  rintros U ⟨s, z⟩,\n  rw [← compl_compl U, ← z, ← Union_of_singleton_coe s, zero_locus_Union, compl_Inter, image_Union],\n  simp_rw [← image_of_Df_eq_comap_C_compl_zero_locus],\n  exact is_open_Union (λ f, is_open_image_of_Df),\nend\n\nend polynomial\n\nend algebraic_geometry\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/is_open_comap_C.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8333245973817159, "lm_q1q2_score": 0.7778508578712273}}
{"text": "import MyNat.Addition\nnamespace MyNat\nopen MyNat\n/-!\n# Addition World\n\n## Level 5: `succ_eq_add_one`\n\n-/\naxiom one_eq_succ_zero : (1 : MyNat) = MyNat.succ 0\n/-!\nWe've just added `one_eq_succ_zero` (a statement that `1 = succ 0`).\nThis is not a proof it is an axiom.  In Lean an `axiom` tells Lean\ndon't both looking for a proof for this fact, just trust me, it's true.\nSo you must be very careful in how you use `axiom` because it can\nlead to inconsistencies in subsequent proofs if your axiom contains\nan error.\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## Theorem\n\nFor any natural number `n`, we have `succ n = n + 1.`\n-/\ntheorem succ_eq_add_one (n : MyNat) : succ n = n + 1 := by\n  rw [one_eq_succ_zero]\n  rw [add_succ]\n  rfl\n\n/-!\nNote that `lemma` and `theorem` are the same thing and can be used\ninterchangeably.\n\nHint: if you use proof by induction, but then find you don't need the hypothesis\nin the inductive step, then you probably didn't need proof by induction.\n\nPress on to [level 6](./Level6.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/AdditionWorld/Level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308165850442, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7778508555505886}}
{"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 topology.urysohns_lemma\nimport topology.continuous_function.bounded\n\n/-!\n# Urysohn's lemma for bounded continuous functions\n\nIn this file we reformulate Urysohn's lemma `exists_continuous_zero_one_of_closed` in terms of\nbounded continuous functions `X →ᵇ ℝ`. These lemmas live in a separate file because\n`topology.continuous_function.bounded` imports too many other files.\n-/\n\nopen_locale bounded_continuous_function\nopen set function\n\n/-- Urysohns lemma: if `s` and `t` are two disjoint closed sets in a normal topological space `X`,\nthen there exists a continuous function `f : X → ℝ` such that\n\n* `f` equals zero on `s`;\n* `f` equals one on `t`;\n* `0 ≤ f x ≤ 1` for all `x`.\n-/\nlemma exists_bounded_zero_one_of_closed {X : Type*} [topological_space X] [normal_space X]\n  {s t : set X} (hs : is_closed s) (ht : is_closed t)\n  (hd : disjoint s t) :\n  ∃ f : X →ᵇ ℝ, eq_on f 0 s ∧ eq_on f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 :=\nlet ⟨f, hfs, hft, hf⟩ := exists_continuous_zero_one_of_closed hs ht hd\nin ⟨⟨f, 1, λ x y, real.dist_le_of_mem_Icc_01 (hf _) (hf _)⟩, hfs, hft, hf⟩\n\n/-- Urysohns lemma: if `s` and `t` are two disjoint closed sets in a normal topological space `X`,\nand `a ≤ b` are two real numbers, then there exists a continuous function `f : X → ℝ` such that\n\n* `f` equals `a` on `s`;\n* `f` equals `b` on `t`;\n* `a ≤ f x ≤ b` for all `x`.\n-/\nlemma exists_bounded_mem_Icc_of_closed_of_le {X : Type*} [topological_space X] [normal_space X]\n  {s t : set X} (hs : is_closed s) (ht : is_closed t) (hd : disjoint s t)\n  {a b : ℝ} (hle : a ≤ b) :\n  ∃ f : X →ᵇ ℝ, eq_on f (const X a) s ∧ eq_on f (const X b) t ∧ ∀ x, f x ∈ Icc a b :=\nlet ⟨f, hfs, hft, hf01⟩ := exists_bounded_zero_one_of_closed hs ht hd\nin ⟨bounded_continuous_function.const X a + (b - a) • f,\n  λ x hx, by simp [hfs hx], λ x hx, by simp [hft hx],\n  λ x, ⟨by dsimp; nlinarith [(hf01 x).1], by dsimp; nlinarith [(hf01 x).2]⟩⟩\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/urysohns_bounded.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368929, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7778508532299501}}
{"text": "import data.real.basic\nimport linear_algebra.finite_dimensional \nimport algebra.module.linear_map\n\n\n-- The structure of an ℝ-vector space on a type. Don't worry about this.\n@[ext, class]\nstructure R_vector_space (V : Type) extends add_comm_group V, module ℝ V\n\n-- The type of ℝ-linear maps between two vector spaces. Don't worry about this.\nabbreviation R_linear_map (V W : Type) [R_vector_space V] [R_vector_space W] :=\n  linear_map (ring_hom.id ℝ) V W\n\n/-  Some variables you can use: `V` and `W` are vector spaces over ℝ, and `f` is a linear map \n    `V → W`. -/\nvariables {V W : Type} [R_vector_space V] [R_vector_space W]\nvariables (f : R_linear_map V W)\n\n/-  Try writing `cases f,` in tactic mode below. The hypothesis `f` will disappear and three new \n    ones will appear in its place: `f_to_fun`, `f_map_add'`, and `f_map_smul'` (smul stands for \n    scalar multiplication). The first is just the underlying function `V → W` while the latter two \n    are the defining properties of a linear map. You can access these any time using dot notation \n    without using the `cases` tactic (e.g. `f.to_fun : V → W`). First try finishing the proof by \n    yourself. Then try `library_search` to see if Lean already knows that a linear map takes \n    0 to 0. -/\nexample : f 0 = 0 :=\nbegin\n  sorry, -- start with `cases f, simp,` and finish the proof yourself\nend  \nexample : f 0 = 0 :=\nbegin\n  sorry, -- try library_search\nend\n\n/-  Recall that the type of subsets of a type `α` is denoted `set α` and is definitionally equal to \n    the type `α → Prop`. Think about why this makes sense. Below, we define the kernel of a linear \n    map from `V` to `W`. This is the subset of `V` that gets mapped to zero, in other words the map \n    `V → Prop` that takes `x` to the proposition `f x = 0`. Our goal is to prove that a linear map\n    is injective iff the kernel is trivial -/\ndef ker : set V := λ x, f x = 0\n\n/-  By proving the following series of lemmas, you should have everything you need to prove the\n    theorem.  -/\n\n-- If `f` is injective, then the only element that gets mapped to zero is zero itself\nlemma zero_injective (hf : function.injective f) (x : V) : (f x) = 0 → x = 0 :=\nbegin\n  sorry,\nend\n\n-- An obvious, but useful lemma\nlemma minus_lemma (x y : V) : x = y ↔ x - y = 0 :=\nbegin\n  sorry,\nend\n\n-- Another useful lemma\nlemma minus_lemma_map (x y : V) : f x = f y ↔ f (x - y) = 0 :=\nbegin\n  sorry,\nend\n\n-- The main theorem\ntheorem injective_iff_ker_eq_zero : function.injective f ↔ ker f = {0} :=\nbegin\n  sorry,\nend\n\n/-  Possibly useful tricks: \n    - `map_sub f : f (x - y) = f x - f y`\n    - `map_zero f : f 0 = 0`\n    - `rw ← add_left_inj a` adds `a` to both sides of an equation -/\n\n/-  Ideas on how to continue this project:\n    - Define eigenvalues and prove some theorems about them.\n    - Prove that if V and W have the same finite dimension, then f is injective if and only if it is \n      surjective, or other properties of finite dimensional vector spaces. Write \n      `[finite_dimensional ℝ V]` before the colon if you want to assume that `V` is finite \n      dimensional.\n    - Prove that every linear map `ℝ → ℝ` is of the form `λ x, a • x` where `a` is a real number\n    - Anything else you can think of!  -/\n\n/-  You don't need to worry about the following instance, it's just telling Lean how to regard ℝ as \n    a vector space over itself. -/\ninstance : R_vector_space ℝ := \n{ to_add_comm_group := by apply_instance,\n  to_module := by apply_instance, }\n\n", "meta": {"author": "dagurtomas", "repo": "lin_alg_project", "sha": "19b594288a3ea99304fbe51c9b6d693b0bfc754f", "save_path": "github-repos/lean/dagurtomas-lin_alg_project", "path": "github-repos/lean/dagurtomas-lin_alg_project/lin_alg_project-19b594288a3ea99304fbe51c9b6d693b0bfc754f/src/project.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.7778430748712918}}
{"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 `ℵ₀`.\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] ≤ max (#R) ℵ₀ :=\ncalc #R[X] = #(mv_polynomial punit.{u + 1} R) :\n  cardinal.eq.2 ⟨(mv_polynomial.punit_alg_equiv.{u u} R).to_equiv.symm⟩\n... ≤ _ : mv_polynomial.cardinal_mk_le_max\n... ≤ _ : by rw [max_assoc, max_eq_right (lt_aleph_0_of_fintype punit).le]\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/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.777761976800411}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p := \n  Iff.intro\n    (fun h : p ∧ q =>\n      have hp : p := h.left\n      have hq : q := h.right\n      show q ∧ p from ⟨hq, hp⟩)\n    (fun h : q ∧ p =>\n      have hq : q := h.left\n      have hp : p := h.right\n      show p ∧ q from And.intro hp hq)\n\n\nexample : p ∨ q ↔ q ∨ p := \n  Iff.intro\n    (fun h : p ∨ q =>\n      Or.elim h\n        (fun hp : p => show q ∨ p from Or.inr hp)\n        (fun hq : q => show q ∨ p from Or.inl hq))\n    (fun h : q ∨ p =>\n      Or.elim h\n        (fun hq : q => show p ∨ q from Or.inr hq)\n        (fun hp : p => show p ∨ q from Or.inl hp))\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  Iff.intro \n    (fun h : (p ∧ q) ∧ r =>\n      have hpq : p ∧ q := h.left\n      have hp : p := hpq.left\n      have hq : q := hpq.right\n      have hr : r := h.right\n      show p ∧ (q ∧ r) from And.intro hp (And.intro hq hr))\n    (fun h : p ∧ (q ∧ r) =>\n      have hp : p := h.left\n      have hqr : q ∧ r := h.right\n      have hq : q := hqr.left\n      have hr : r := hqr.right\n      show (p ∧ q) ∧ r from And.intro (And.intro hp hq) hr)\n\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := \n  Iff.intro\n    (fun h : (p ∨ q) ∨ r =>\n      Or.elim h\n        (fun hpq : p ∨ q =>\n          Or.elim hpq\n            (fun hp : p => show p ∨ (q ∨ r) from Or.inl hp)\n            (fun hq : q => show p ∨ (q ∨ r) from Or.inr (Or.inl hq)))  \n        (fun hr : r => show p ∨ (q ∨ r) from Or.inr (Or.inr hr)))\n    (fun h : p ∨ (q ∨ r) =>\n      Or.elim h\n        (fun hp : p => show (p ∨ q) ∨ r from Or.inl (Or.inl hp))\n        (fun hqr : q ∨ r =>\n          Or.elim hqr\n            (fun hq : q => show (p ∨ q) ∨ r from Or.inl (Or.inr hq))\n            (fun hr : r => show (p ∨ q) ∨ r from Or.inr hr)))\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := \n  Iff.intro\n    (fun h : p ∧ (q ∨ r) =>\n      have hp : p := h.left\n      have hqr : q ∨ r := h.right\n      Or.elim hqr\n        (fun hq : q => show (p ∧ q) ∨ (p ∧ r) from Or.inl (And.intro hp hq))\n        (fun hr : r => show (p ∧ q) ∨ (p ∧ r) from Or.inr (And.intro hp hr)))\n    (fun h : (p ∧ q) ∨ (p ∧ r) =>\n      Or.elim h\n        (fun hpq : p ∧ q =>\n          have hp : p := hpq.left\n          have hq : q := hpq.right\n          show p ∧ (q ∨ r) from And.intro hp (Or.inl hq))\n        (fun hpr : p ∧ r =>\n          have hp : p := hpr.left\n          have hr : r := hpr.right\n          show p ∧ (q ∨ r) from And.intro hp (Or.inr hr)))\n\n\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := \n  Iff.intro \n    (fun h : p ∨ (q ∧ r) =>\n      Or.elim h\n        (fun hp : p =>\n          show (p ∨ q) ∧ (p ∨ r) from And.intro (Or.inl hp) (Or.inl hp))\n        (fun hqr : q ∧ r =>\n          have hq : q := hqr.left\n          have hr : r := hqr.right\n          show (p ∨ q) ∧ (p ∨ r) from And.intro (Or.inr hq) (Or.inr hr)))\n    (fun h : (p ∨ q) ∧ (p ∨ r) =>\n      have hpq : p ∨ q := h.left\n      have hpr : p ∨ r := h.right\n      Or.elim hpq \n        (fun hp : p => show p ∨ (q ∧ r) from Or.inl hp)\n        (fun hq : q =>\n          Or.elim hpr\n            (fun hp : p => show p ∨ (q ∧ r) from Or.inl hp)\n            (fun hr : r => show p ∨ (q ∧ r) from Or.inr (And.intro hq hr))))\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := \n  Iff.intro \n    (fun h : p → (q → r) =>\n      fun hpq : p ∧ q =>\n        have hp : p := hpq.left\n        have hq : q := hpq.right\n        show r from h hp hq)\n    (fun h : p ∧ q → r =>\n      fun hp : p =>\n        fun hq : q =>\n          show r from h (And.intro hp hq))\n\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \n  Iff.intro\n    (fun h : (p ∨ q) → r =>\n      show (p → r) ∧ (q → r) from And.intro\n        (fun hp : p =>\n          show r from h (Or.inl hp))\n        (fun hq : q =>\n          show r from h (Or.inr hq)))\n    (fun h : (p → r) ∧ (q → r) =>\n      have hpr : p → r := h.left\n      have hqr : q → r := h.right\n      fun hpq : p ∨ q =>\n        Or.elim hpq\n          (fun hp : p => show r from hpr hp)\n          (fun hq : q => show r from hqr hq))\n\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \n  Iff.intro \n    (fun h : ¬(p ∨ q) =>\n      Or.elim (Classical.em p)\n        (fun hp : p => absurd (Or.inl hp) h)\n        (fun hnp : ¬p =>\n          Or.elim (Classical.em q)\n            (fun hq : q => absurd (Or.inr hq) h)\n            (fun hnq : ¬q => show ¬p ∧ ¬q from And.intro hnp hnq)))\n    (fun h : ¬p ∧ ¬q =>\n      Or.elim (Classical.em (p ∨ q))\n        (fun hpq : p ∨ q =>\n          Or.elim hpq\n            (fun hp : p => absurd hp h.left)\n            (fun hq : q => absurd hq h.right))\n        (fun hnpq : ¬(p ∨ q) => hnpq))\n\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) := \n  fun h : ¬p ∨ ¬q =>\n    Or.elim h\n      (fun hnp : ¬p =>\n        Or.elim (Classical.em (p ∧ q))\n          (fun hpq : p ∧ q =>\n            absurd hpq.left hnp)\n          (fun hnpq : ¬(p ∧ q) => hnpq))\n      (fun hnq : ¬q =>\n        Or.elim (Classical.em (p ∧ q))\n          (fun hpq : p ∧ q =>\n            absurd hpq.right hnq)\n          (fun hnpq : ¬(p ∧ q) => hnpq))\n\n\nexample : ¬(p ∧ ¬p) := \n  Or.elim (Classical.em (p ∧ ¬p))\n    (fun h : p ∧ ¬p => absurd h.left h.right)\n    (fun hn : ¬(p ∧ ¬p) => hn)\n\n\nexample : p ∧ ¬q → ¬(p → q) := \n  fun h : p ∧ ¬q =>\n    Or.elim (Classical.em (p → q))\n      (fun hpq : p → q => \n        have h₁ : q := hpq h.left\n        have h₂ : ¬q := h.right\n        absurd h₁ h₂)\n      (fun hn : ¬(p → q) => hn)\n\n\nexample : ¬p → (p → q) := \n  fun h : ¬p =>\n    fun hp : p => show q from absurd hp h\n\n\nexample : (¬p ∨ q) → (p → q) := \n  fun h : ¬p ∨ q =>\n    Or.elim h\n      (fun hnp : ¬p =>\n        fun hp : p => absurd hp hnp)\n      (fun hq : q =>\n        fun hp : p => hq)\n\n\nexample : p ∨ False ↔ p := \n  Iff.intro \n    (fun h : p ∨ False =>\n      Or.elim h\n        (fun hp : p => hp)\n        (fun hf : False => False.elim hf))\n    (fun h : p => show p ∨ False from Or.inl h)\n\n\nexample : p ∧ False ↔ False := \n  Iff.intro\n    (fun h : p ∧ False =>\n      False.elim h.right)\n    (fun h : False => show p ∧ False from False.elim h)\n\n\nexample : (p → q) → (¬q → ¬p) := \n  fun h : p → q =>\n    fun hnq : ¬q =>\n      Or.elim (Classical.em p)\n        (fun hp : p => absurd (h hp) hnq)\n        (fun hnp : ¬p => hnp)\n\n\n\nvariable (p q r s : Prop)\n\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) := \n  fun h : p → r ∨ s =>\n    Classical.byCases\n      (fun hp : p => \n        Or.elim (h hp)\n          (fun hr : r => show (p → r) ∨ (p → s) from Or.inl (fun hp => hr))\n          (fun hs : s => show (p → r) ∨ (p → s) from Or.inr (fun hp => hs)))\n      (fun hnp : ¬p => \n        have hpr : p → r := (fun hp => absurd hp hnp)\n        show (p → r) ∨ (p → s) from Or.inl hpr)\n\n\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q := \n  fun h : ¬(p ∧ q) =>\n    Or.elim (Classical.em p)\n      (fun hp : p => \n        Or.elim (Classical.em q)\n          (fun hq : q => absurd (And.intro hp hq) h)\n          (fun hnq : ¬q => show ¬p ∨ ¬q from Or.inr hnq))\n      (fun hnp : ¬p => show ¬p ∨ ¬q from Or.inl hnp)\n\n\nexample : ¬(p → q) → p ∧ ¬q := \n  fun h : ¬(p → q) =>\n    Classical.byCases\n      (fun hp : p => \n        Classical.byCases\n          (fun hq : q => absurd (fun hp => hq) h)\n          (fun hnq : ¬q => And.intro hp hnq))\n      (fun hnp : ¬p => \n        Classical.byCases\n          (fun hq : q =>\n            have hpq : p → q := (fun hp => hq)\n            absurd hpq h)\n          (fun hnq : ¬q =>\n            have hpq : p → q := \n              (fun hp : p => absurd hp hnp)\n            absurd hpq h))\n\nexample : (p → q) → (¬p ∨ q) := \n  fun h : p → q =>\n    Or.elim (Classical.em p)\n      (fun hp : p => show ¬p ∨ q from Or.inr (h hp))\n      (fun hnp : ¬p => show ¬p ∨ q from Or.inl hnp)\n\n\nexample : (¬q → ¬p) → (p → q) := \n  fun h : ¬q → ¬p =>\n    fun hp : p =>\n      Or.elim (Classical.em q)\n        (fun hq : q => hq)\n        (fun hnq : ¬q => absurd hp (h hnq))\n\n\nexample : p ∨ ¬p := \n  Classical.byCases\n    (fun hp : p => show p ∨ ¬p from Or.inl hp)\n    (fun hnp : ¬p => show p ∨ ¬p from Or.inr hnp)\n\n\nexample : (((p → q) → p) → p) := \n  fun h : (p → q) → p =>\n    Classical.byCases\n      (fun hpq : p → q => h hpq)\n      (fun hnpq : ¬ (p → q) =>\n        Classical.byContradiction\n          (fun hnp : ¬ p => \n           have hpq : p → q := (fun hp : p => absurd hp hnp)\n           show False from hnpq hpq))\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/TheoremProvingLean/propositions_proofs_exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7777541654976657}}
{"text": "import data.real.basic\n\nnamespace challenges\n\n-- basic definitions\ndef upper_bounds (S : set ℝ) : set ℝ := { b | ∀s ∈ S, s ≤ b }\ndef lower_bounds (S : set ℝ) : set ℝ := { b | ∀s ∈ S, b ≤ s }\ndef is_least (S : set ℝ) (l : ℝ) : Prop := l ∈ S ∧ l ∈ lower_bounds S\ndef is_lub (S : set ℝ) (l : ℝ) : Prop := is_least (upper_bounds S) l\n\n/-- A set has at most one least upper bound -/\ntheorem challenge2 (S : set ℝ) (a b : ℝ) (ha : is_lub S a) (hb : is_lub S b) : a = b :=\nbegin\n  sorry\nend \n\nend 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/challenges/challenge2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.8244619177503206, "lm_q1q2_score": 0.7777541531619812}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport tactic\n\n/-!\n\n# Funciones en Lean.\n\nLa notación para funciones es la habitual en matemáticas: dados dos tipos `X` e `Y`, `f : X → Y` \ndenota una función de `X` a `Y`. \n\nInternamente, `X → Y` denota el tipo de funciones de `X` a `Y`, y `f : X → Y` indica que  `f` es un\ntérmino de tipo `X → Y`, es decir, una  función de `X` a `Y`. \n\n\nNOTACIÓN: dado `x : X` y `f : X → Y`, para denotar la evaluación  `f(x)` es posible omitir los \nparéntesis, escribiendo simplemente `f x`. Sin embargo, para expresiones más complicadas los \nparéntesis son necesarios. Por ejemplo, dados `x : X`, `f : X → Y` y `g : Y → Z`, para evaluar\nla composición `g(f(x))` necesitamos al menos los paréntesis exteriores: `g(f x)`.\n\nOJO: Dados `a b : X` y `f : X → Y`, si escribimos `f a + b`, Lean lo interpretará como `f(a) + b` \n(y en general esto causará un error). Si lo que queremos es `f(a + b)`, necesitamos los paréntesis.\n\n\n## Inyectividad y sobreyectividad\n\nLean conoce las definiciones de función injectiva (`function.injective`) y sobreyectiva \n(`function.surjective`). Dada cualquier función `f : X → Y`, `function.injective f`\ny `function.surjective f` son proposiciones (verdaderas o falsas dependiendo de `f`).\n\n-/\n\n/- Si abrimos el `namespace` \"function\", no es necesario escribir `function.`; podemos escribir\n`injective f` y `surjective f`. -/\n\nopen function\n\n\n/- Fijamos tres tipos `X`, `Y`, `Z` (podemos pensar en ellos como conjuntos) y dos funciones \n`f : X → Y`, `g : Y → Z`. -/\nvariables {X Y Z : Type} {f : X → Y} {g : Y → Z}\n\n/- Sean `a,b,x` elementos de `X`, `y ∈ Y`, `z ∈ Z`. -/\nvariables (a b x : X) (y : Y) (z : Z)\n\n-- Abrimos un `namespace` para evitar colisiones de nomenclatura con lemas existentes en Lean.\nnamespace funciones\n\n/-!\n# Funciones inyectivas\n-/\n\n/- Comprobamos que en Lean la definición de función sobreyectiva es la esperada. -/\nlemma injective_def : injective f ↔ ∀ a b : X, f a = f b → a = b :=\nbegin\n  refl -- cierto por definición\nend\n\n-- La táctica `rw injective_def` cambia `injective f` por su definición.\n\n/- Comprobamos que la función identidad ` id : X → X` está definida como `id(x) = x`. -/\nlemma id_eval : id x = x :=\nbegin\n  refl -- cierto por definición\nend\n\n-- La composición de funciones se denota mediante `∘`. Por definición, `(g ∘ f) (x) = g(f(x))`.\nlemma comp_eval : (g ∘ f) x = g (f x) :=\nbegin\n  refl\nend\n\n/- La razón por la que demostramos estos teoremas demostrables \"por definición\" (`refl`) es que\nesto nos permite utilizar la táctica  `rw` para reemplazar términos por su definición. -/\n\n/- Por ejemplo, podemos empezar la siguiente demostración con `rw injective_def`, y más adelante \nutilizar `rw id_eval`. -/\nlemma injective_id : injective (id : X → X) :=\nbegin\n  rw injective_def, -- es posible eliminar esta instrucción\n  intros x y hxy,\n  rw id_eval x at hxy, -- ésta también\n  rw id_eval y at hxy, -- ésta también\n  exact hxy,\nend\n\n/- Si eliminamos la instrucción  `rw injective_def`, nada cambia. El motivo es que esta instrucción\nno es realmente necesaria para Lean (ya que sólo está reescribiendo una definición), pero puede\nser útil para la persona escribiendo la demostración. Prueba a hacer lo mismo con `rw id_eval`. -/\n\n/-- La composición de dos funciones inyectivas es inyectiva. -/\nlemma injective_comp (hf : injective f) (hg : injective g) : injective (g ∘ f) :=\nbegin\n  rw injective at *, -- por legibilidad\n  intros x y hxy,\n  apply hf,\n  apply hg,\n  exact hxy,\nend\n\n/- Ejercicio -/\nexample (f : X → Y) (g : Y → Z) : \n  injective (g ∘ f) → injective f :=\nbegin\n  intros h x y hxy,\n  apply h,\n  rw comp_eval,\n  rw hxy,\nend\n\n\n/-!\n\n### Funciones sobreyectivas\n\n-/\n\n/- Comprobamos que en Lean la definición de función sobreyectiva es la esperada. -/\nlemma surjective_def : surjective f ↔ ∀ y : Y, ∃ x : X, f x = y :=\nbegin\n  refl\nend\n\n/-- La función identidad es sobreyectiva. -/\nlemma surjective_id : surjective (id : X → X) :=\nbegin\n  intros x,\n  use x,\n  rw id_eval, -- o `refl`\nend\n\n\n/-- Una composición de funciones sobreyectivas es sobreyectiva. -/\nlemma surjective_comp (hf : surjective f) (hg : surjective g) : surjective (g ∘ f) :=\nbegin\n  intros z,\n  cases hg z with y hy,\n  cases hf y with x hx,\n  use x,\n  rw comp_eval, -- Nótese que, en este caso, eliminar esta línea provoca un error en la siguiente.\n  rw hx,\n  rw hy,\nend\n\n/- Ejercicio -/\nexample (f : X → Y) (g : Y → Z) : \n  surjective (g ∘ f) → surjective g :=\nbegin\n  intros h z,\n  cases (h z) with x hx,\n  use (f x),\n  exact hx,\nend\n\n/-!\n### Funciones biyectivas\n-/\n\n/- En Lean, una función biyectiva es, por definición, una función inyectiva y sobreyectiva. -/\nlemma bijective_def : bijective f ↔ injective f ∧ surjective f :=\nbegin\n  refl\nend\n\n/-- La función identidad es biyectiva. -/\nlemma bijective_id : bijective (id : X → X) :=\nbegin\n  rw bijective_def, --no necesaria\n  split,\n  { exact injective_id },\n  { exact surjective_id },\nend\n\n/-- Una composición de funciones biyectivas es biyectiva. -/\nlemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g ∘ f) :=\nbegin\n  cases hf with hf_inj hf_surj,\n  cases hg with hg_inj hg_surj,\n  exact ⟨injective_comp hf_inj hg_inj, surjective_comp hf_surj hg_surj⟩ \nend\n\nend funciones", "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/funciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.777695274699192}}
{"text": "namespace Hidden\n-- 1\ninductive Nat where \n  | zero : Nat \n  | succ : Nat → Nat \nderiving Repr \n\ndef add : Nat → Nat → Nat \n  | Nat.zero, k => k\n  | Nat.succ n, k => Nat.succ (add n k)\n\n#eval add (Nat.succ (Nat.succ Nat.zero)) (Nat.succ Nat.zero)\n\ndef mul : Nat → Nat → Nat \n  | Nat.zero, _ => Nat.zero\n  | Nat.succ n, k => add k (mul n k)\n\n#eval mul (Nat.succ (Nat.succ Nat.zero)) (Nat.succ (Nat.succ Nat.zero))\n\ndef pow (n m : Nat) : Nat := \n  match m with \n  | Nat.zero => Nat.succ Nat.zero \n  | Nat.succ m => mul n (pow n m)\n\n#eval pow (Nat.succ (Nat.succ Nat.zero)) (Nat.succ (Nat.succ (Nat.succ Nat.zero)))\n\n--2\ninductive List (α : Type u) where\n  | nil  : List α\n  | cons : α → List α → List α\nderiving Repr \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 α) : List α := \n  match as with \n  | [] => bs \n  | x :: xs => x :: (append xs bs)\n\ninfixl:65 (priority := high) \" ++ \" => append\n\ndef reverse (xs : List α) : List α := \n  match xs with \n  | List.nil => List.nil\n  | List.cons x xs => (reverse xs) ++ (List.cons x List.nil)\n\n@[simp]theorem append_nil (xs: List α) : reverse (xs ++ []) = [] ++ reverse xs := by \n  induction xs \n  . case nil => rfl \n  . case cons x xs h => simp [h, append, reverse]\n\n@[simp]theorem nil_append (xs: List α) : reverse ([] ++ xs) = reverse xs ++ [] := by \n  induction xs \n  . case nil => rfl \n  . case cons x xs h => \n    rw [reverse]\n    sorry\n    -- simp [h, append, reverse]\n\n\ntheorem reverse_append (xs : List α) (ys : List α) : reverse (xs ++ ys) = reverse ys ++ reverse xs := by\n  induction xs\n  . case nil => sorry\n  . case cons x xs => \n    sorry\n\n\n#eval reverse (List.cons 1 (List.cons 2 (List.cons 3 List.nil)))\n\ntheorem double_reverse (xs : List α) : reverse (reverse xs) = xs := by\n  induction xs\n  . case nil => rfl\n  . case cons x xs h => \n    rw [reverse]\n    sorry\n    -- simp [h] \n    -- simp [reverse, append]\n\n    -- simp_all [reverse, h, append]\n\n-- 3   \n\n\nend Hidden \n\n-- 4 \n\ninductive Vector (α : Type u) : Nat → Type u\n  | nil  : Vector α 0\n  | cons : α → {n : Nat} → Vector α n → Vector α (n+1)\nderiving Repr\n\nnamespace Vector\n\ndef v1 := Vector.cons 5 (Vector.cons 0 Vector.nil)\ndef v2 := Vector.cons 8 (Vector.cons 5 (Vector.cons 0 Vector.nil))\n\n-- def add [Add α] : Vector α n → Vector α n → Vector α n\n--   | nil,       nil       => nil\n--   | cons a as, cons b bs => cons (a + b) (add as bs)\n\n\n-- def tailAux (v : Vector α m) : m = n + 1 → Vector α n :=\n--   Vector.casesOn (motive := fun x _ => x = n + 1 → Vector α n) v\n--     (fun h : 0 = n + 1 => Nat.noConfusion h)\n--     (fun (a : α) (m : Nat) (as : Vector α m) =>\n--      fun (h : m + 1 = n + 1) =>\n--        Nat.noConfusion h (fun h1 : m = n => h1 ▸ as))\n\n-- def tail (v : Vector α (n+1)) : Vector α n :=\n--   tailAux v rfl\n\n-- def append: {n m : Nat} → Vector α n → Vector α m → Vector α (n + m)\n--   -- | 0,   nil,       nil       => nil\n--   |  0, _, nil,       k       => k\n--   | cons a as, k => cons a (append as (tail k))\n\n-- #eval add v1 v2\n\nend Vector\n\n-- 5\ninductive Expr where\n  | const : Nat → Expr\n  | var : Nat → Expr\n  | plus : Expr → Expr → Expr\n  | times : Expr → Expr → Expr\n  deriving Repr\n\nopen Expr\n\ndef sampleExpr : Expr :=\n  plus (times (var 0) (const 7)) (times (const 2) (var 1))\n\ndef eval (v : Nat → Nat) : Expr → Nat\n  | const n     => n\n  | var n       => v n\n  | plus e₁ e₂  => (eval v e₁) + (eval v e₂)\n  | times e₁ e₂ => (eval v e₁) * (eval v e₂)\n\ndef sampleVal : Nat → Nat\n  | 0 => 5\n  | 1 => 6\n  | _ => 0\n\n-- Try it out. You should get 47 here.\n#eval eval sampleVal sampleExpr\n\ndef simpConst : Expr → Expr\n  | plus (const n₁) (const n₂)  => const (n₁ + n₂)\n  | times (const n₁) (const n₂) => const (n₁ * n₂)\n  | e                           => e\n\n#eval simpConst sampleExpr\n\ndef fuse : Expr → Expr := sorry\n\ntheorem simpConst_eq (v : Nat → Nat)\n        : ∀ e : Expr, eval v (simpConst e) = eval v e :=\n  sorry\n\ntheorem fuse_eq (v : Nat → Nat)\n        : ∀ e : Expr, eval v (fuse e) = eval v e :=\n  sorry\n\n\nexample : 10 < 5 ∨ 1 > 0 := by\n  decide\n\nexample : ¬ (True ∧ False) := by\n  decide\n\nexample : 10 * 20 = 200 := by\n  decide\n\ntheorem ex : True ∧ 2 = 1+1 := by\n  decide\n\n#print ex\n-- theorem ex : True ∧ 2 = 1 + 1 :=\n-- of_decide_eq_true (Eq.refl true)\n\n#check @of_decide_eq_true\n-- ∀ {p : Prop} [Decidable p], decide p = true → p\n\n#check @decide\n-- (p : Prop) → [Decidable p] → Bool\n\n\nexample (a b c : Nat) : a * (b * c) = a * (c * b) := by\n  conv =>\n    -- |- a * (b * c) = a * (c * b)\n    lhs\n    -- |- a * (b * c)\n    congr\n    -- 2 goals : |- a and |- b * c\n    rfl\n    -- |- b * c\n    rw [Nat.mul_comm]\n\n\n#eval 4 = 4\n\ndef Set (α : Type u) := α → Prop\n\nnamespace Set\n\ndef mem (x : α) (a : Set α) := a x\n\ninfix:50 (priority := high) \"∈\" => mem\n\nend Set\n\ntheorem tteq : (True ∧ True) = True :=\n  propext (Iff.intro (fun ⟨h, _⟩ => h) (fun h => ⟨h, h⟩))\n\ndef val : Nat :=\n  Eq.recOn (motive := fun _ _ => Nat) tteq 0\n\n-- does not reduce to 0\n#reduce val\n\n-- evaluates to 0\n#eval val\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/theorem_proving/exercises_chapter_8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7776952708629702}}
{"text": "import incidence_world.level05 --hide\nopen IncidencePlane --hide\n\n/-\n# Incidence World\n\n## Level 6: almost there...\n\nCongratulations! You're almost there! To solve this level, we provide you with the mathematical proof in paper. Read it carefully and make\nan effort to understand every bit of it. Then, try to type the mathematical proof in Lean by your own. If needed, you can go back to the previous \nlevels to remember how to use some tactics. By the way, don't forget your list of theorem statements! Just as a final hint, you may want to start \nyour proof by typing `rcases (point_existence_postulate P) with ⟨Q, R, ⟨hPQ, hPR, hQR,H⟩⟩,`... Good luck!\n\n## The mathematical proof in paper...\n\n**Claim:** There are at least two different lines passing through a given point.\n\n**Proof:** Let P be the given point.\n\nBy the lemma `point_existence_postulate`, there exist two points Q and R such that the points P, Q and R are non-collinear.\n\nBy the first axiom of incidence, let `r` be the line that passes through (= is incident with) the points P and Q.\n\nBy the first axiom of incidence, let `s` be the line that passes through the points P and R.\n\nBy the lemma `ne_of_not_share_point`, since the point R is incident with the line through P and R and it is not incident with the \nline through P and Q, then the lines `r` and `s` are not equal.\n\nHence, we have shown that there at least two different lines passing through a given point.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nThis is not a proof by cases. The `use` tactic may get you going with the second and third lines of the proof. To close the last goal,\ngo back to Level 3 of this world and try to see how we used the `point_in_line_not_point` lemma. Still bewildered? Click on \"View source\" \n(located on the top right corner of the game screen) to see the solution. \n-/\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\n\n/- Lemma :\nThere are at least two different lines passing through a given point.\n-/\nlemma point_exists_two_lines (P : Ω) : ∃ (r s: Line Ω), P ∈ s ∧ P ∈ r ∧ s ≠ r :=\nbegin\n  rcases (point_existence_postulate P) with ⟨Q, R, ⟨hPQ, hPR, hQR,H⟩⟩,\n  use line_through P Q,\n  use line_through P R,\n  split,\n  {\n    exact line_through_left P R,\n  },\n  split,\n  {\n    exact line_through_left P Q,\n  },\n  {\n    exact ne_of_not_share_point (line_through_right P R) 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/incidence_world/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088045171238, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7776537469162853}}
{"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 (∪)\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 ⊆ A ∪ B$. To work with unions you will\nneed to know the property which classifies them:\n\n```\nmem_union_iff : x ∈ A ∪ B ↔ x ∈ A ∨ x ∈ 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 ∈ A ∪ B ↔ x ∈ A ∨ x ∈ 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 `⊢ ∀ (x : X), x ∈ A → x ∈ A ∪ 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 ⊆ A ∪ B :=\nbegin\n  rw subset_iff,\n  intros x hxA,\n  rw mem_union_iff,\n  left,\n  assumption,\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_level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240142763574, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7776474024519464}}
{"text": "-- Introducción de la intersección\n-- ===============================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    x ∈ A → x ∈ B → x ∈ A ∩ B\n-- ----------------------------------------------------\n\nimport data.set\n\nvariable  U : Type\nvariables A B : set U\nvariable  x : U\n\nopen set\n\n-- #reduce x ∈ A ∩ B\n\n-- 1ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nbegin\n  intros h1 h2,\n  simp,\n  split,\n  { exact h1, },\n  { exact h2, },\nend\n\n-- 2ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nbegin\n  intros h1 h2,\n  split,\n  { exact h1, },\n  { exact h2, },\nend\n\n-- 3ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\nshow x ∈ A ∩ B, from and.intro h1 h2\n\n-- 4ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\nshow x ∈ A ∩ B, from ⟨h1, h2⟩\n\n-- 5ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\n⟨h1, h2⟩\n\n-- 6ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nλ h1 h2, ⟨h1, h2⟩\n\n-- 7ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\n-- by library_search\nmem_inter\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/Introduccion_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7776416734805973}}
{"text": "import data.set\nimport logic.function.iterate\nimport algebra.group_power\nimport tactic.nth_rewrite\nimport data.list.basic\nimport languages.basic\n\nopen set\n\nnamespace languages\n\nvariable {S : Type}\n\n@[simp] def kleene_star (L : set (list S)) := {w : list S | ∃ (n : ℕ), w ∈ L^n}\n\nlemma star_Union (L : set (list S)): kleene_star L = ⋃ (n : ℕ), L^n :=\nbegin\n    apply subset.antisymm, {\n        rintro w hw,\n        rw mem_Union,\n        exact hw,\n    }, {\n        rintro w hw,\n        rw mem_Union at hw,\n        exact hw,\n    }\nend\n\n@[simp] lemma one_subset_star {L : set (list S)} : 1 ⊆ kleene_star L :=\nbegin    \n    intros x hx,\n    use 0,\n    simpa only [pow_zero],\nend\n\n@[simp] lemma nil_mem_star {L : set (list S)} : [] ∈ kleene_star L :=\nbegin\n    use 0,\n    simp only [one_def, pow_zero, mem_singleton],\nend\n\n@[simp] lemma power_subset_star {L : set (list S)} (n : ℕ) : L^n ⊆ kleene_star L :=\nbegin\n    rw star_Union,\n    refine subset_Union _ _,\nend\n\n@[simp] lemma lang_subset_star {L : set (list S)} : L ⊆ kleene_star L :=\nbegin\n    convert power_subset_star 1,\n    simp only [pow_one],\nend\n\nlemma star_subset_of_subset {A B : set (list S)} : A ⊆ B → kleene_star A ⊆ kleene_star B :=\nbegin\n    rintro hAB w ⟨n, ha⟩,\n    use n,\n    exact power_subset_of_subset hAB ha,\nend\n\nlemma power_star_eq_star {A : set (list S)} (n : ℕ) : (kleene_star A)^n.succ = kleene_star A :=\nbegin\n    induction n with n hyp, {\n        simp only [pow_one],\n    }, {\n        apply subset.antisymm, {\n            rw [pow_succ, hyp],\n            rintro w ⟨ left, right, ⟨ nleft, hleft ⟩, ⟨ nright, hright ⟩, rfl ⟩,\n            use nleft + nright,\n            rw pow_add,\n            use [left, right, hleft, hright],\n        }, {\n            apply contain_eps_subset_power,\n            simp only [one_subset_star],             \n        },\n    },\nend\n                \ntheorem star_star_eq_star {A : set (list S)} : kleene_star (kleene_star A) = kleene_star A :=\nbegin\n    apply subset.antisymm, {\n        rintro x ⟨⟨_⟩, hx⟩, {\n            use 0,\n            simpa only [pow_zero],\n        }, {\n            rw power_star_eq_star at hx,\n            exact hx,\n        },\n    }, {\n        exact star_subset_of_subset lang_subset_star,\n    },\nend\n\nlemma append_subset_star {A B L : set (list S)} : \n    A ⊆ kleene_star L → B ⊆ kleene_star L → (A * B) ⊆ kleene_star L :=\nbegin\n    rintro al bl _ ⟨ left, right, hleft, hright, rfl ⟩,\n    rcases al hleft with ⟨an, ah⟩,\n    rcases bl hright with ⟨bn, bh⟩,\n    use an + bn,\n    rw pow_add,\n    use [left, right, ah, bh],\nend\n\nlemma star_eq_list_join {L : set (list S)} {w : list S} : \n    w ∈ kleene_star L ↔ ∃ l (h : ∀ x, x ∈ l → x ∈ L), w = list.join l :=\nbegin\n    split, {\n        rintro ⟨n, hw⟩,\n        rcases power_eq_list_join.1 hw with ⟨l, h, ⟨rfl, rfl⟩⟩,\n        use [l, h],\n    }, {\n        rintro ⟨l, h, rfl⟩,\n        apply power_subset_star (l.length),\n        apply power_eq_list_join.2,\n        use [l, h],\n        simp only [eq_self_iff_true, and_self], \n    }\nend\n\nend languages", "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/languages/star.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7776416612210919}}
{"text": "import data.tree\nimport utilities\nimport data.nat.pow\n\nset_option trace.simplify.rewrite true\n\nopen tree\n\nvariable { α : Type}\nvariable { β : Type}\nvariable a: α \nvariables t l r s: tree α \nvariable f: α → β \n\n/-\n## Basic Functions\n\nA binary tree is already defined in Lean as tree. \nThe difference with __Functional Algorithms, Verified!__ is that a leaf is called nil, \nand the order of the node is (α, tree, tree) instead of (tree, α, tree). \nSince this does not change the structure of the proofs, the Lean definition is reused.\n-/\n\ndef set_tree: tree α → set α \n| nil := {}\n| (node a l r) := set_tree l ∪ {a} ∪ set_tree r\n\n/-\nmap_tree is already defined in Lean as map and is reused.\n-/\n\ndef inorder: tree α → list α \n| nil := []\n| (node a l r) := inorder l ++ [a] ++ inorder r\n\n/-\nThe name preorder is already used in lean, therefore the name preorder' is used.\n-/\ndef preorder': tree α → list α \n| nil := []\n| (node a l r) := [a] ++ preorder' l ++ preorder' r\n\ndef postorder: tree α → list α \n| nil := []\n| (node a l r) := postorder l ++ postorder r ++ [a]\n\ndef size: tree α → ℕ\n| nil := 0\n| (node a l r) := size l + size r + 1\n\ndef size1: tree α → ℕ\n| nil := 1\n| (node a l r) := size1 l + size1 r\n\ndef height : tree α → ℕ\n| nil := 0\n| (node a l r) := max (height l) (height r) + 1\n\ndef min_height: tree α → ℕ \n| nil := 0\n| (node a l r) := min (min_height l) (min_height r) + 1\n\ndef subtrees: tree α → set (tree α)\n| nil := {tree.nil}\n| (node a l r) := { (node a l r)} ∪ subtrees l ∪ subtrees r\n\n/-\n## Lemmas Size\nExcept for the first lemma, these lemmas are only in the Isabelle file\n-/\n\nlemma size1_size: size1 t = size t + 1 :=\nbegin\n  induction' t,\n  repeat { simp [size, size1, *]},\n  cc\nend\n\n@[simp]\nlemma size1_ge0: 0 < size1 t :=\nbegin\n  simp [size1_size],\nend\n\n@[simp]\nlemma eq_size_0 : size t = 0 ↔ t = nil :=\nbegin\n  cases t,\n  repeat { simp [size] },\nend\n\n@[simp]\nlemma eq_0_size: 0 = size t ↔ t = nil :=\nbegin\n  cases t with a l r,\n  repeat { simp [size, nat.add_one, ← ne.def]},\n  apply ne.symm,\n  simp,\nend\n\n/-\nThis lemma is called __neq_Leaf_iff__ in the Isabelle file.\n-/\nlemma neq_nil_iff: t ≠ nil ↔ ∃ a l r, t = (node a l r) :=\nbegin\n  cases t with a l r,\n  repeat { simp },\nend  \n\n/-\n## Lemmas Height\nSome of these lemmas are only in the Isabelle file.\n-/\n\n@[simp]\nlemma eq_height_0 : height t = 0 ↔ t = nil :=\nbegin\n  cases t,\n  repeat { simp [height],},\nend\n\n@[simp]\nlemma eq_0_height : 0 = height t ↔ t = nil :=\nbegin\n  cases t with a l r,\n  repeat { simp [height, nat.add_one, ← ne.def]},\n  apply ne.symm,\n  simp,\nend\n\n@[simp]\nlemma height_le_size_tree: height t <= size t :=\nbegin\n  induction' t,\n  repeat { simp [height, size] },\n  apply and.intro,\n  { calc\n      height t <= size t : by simp * \n      ... ≤ size t + size t_1 :by simp},\n  calc\n    height t_1 <= size t_1: by simp * \n    ... ≤ size t + size t_1 : by simp\nend\n\nlemma min_height_le_height : min_height t <= height t:=\nbegin\n  induction' t,\n  repeat { simp [height, min_height, *]}\nend\n\nlemma size1_height: size1 t <= 2 ^ height t :=\nbegin\n  have h2: 2 <= 2, by trivial,\n  induction' t with a l r,\n  repeat { simp [size1, height, max_def] },\n  split_ifs,\n  { have h3: 2 ^ height r <= 2 ^height l, from iff.elim_right (nat.pow_le_iff_le_right h2) h,\n    calc\n      size1 l + size1 r <= 2 ^ height l + size1 r : by simp *\n      ... <= 2 ^ height l + 2 ^ height r  : by simp *\n      ... <= 2 ^ height l + 2 ^ height l  : by simp *\n      ... = 2 ^ (height l + 1) : by ring },\n  have h1: height l <= height r, by linarith, \n  have h3: 2 ^ height l <= 2 ^height r, by apply iff.elim_right (nat.pow_le_iff_le_right h2) h1,\n  calc\n    size1 l + size1 r <= 2 ^ height l + size1 r: by simp *\n    ... <= 2 ^ height l + 2 ^ height r : by simp *\n    ... <= 2 ^ height r + 2 ^ height r : by simp *\n    ... = 2 ^ (height r + 1) : by ring\nend\n\nlemma size_height: size t <= 2 ^ height t - 1 :=\nbegin\n  have h: size1 t <= 2 ^ height t, from size1_height t,\n  have h1: size1 t = size t + 1, from size1_size t,\n  rw h1 at h,\n  have h2: 1 <= 2 ^ height t, from nat.one_le_two_pow (height t),\n  have h3:size t + 1 ≤ 2 ^ height t ↔ size t ≤ 2 ^ height t - 1, from nat.add_le_to_le_sub (size t) h2,\n  exact iff.elim_left h3 h,\nend\n\nlemma min_height_size1: 2 ^ min_height t <= size1 t :=\nbegin\n  have h2: 2 <= 2, by trivial,\n  induction' t with a l r,\n  repeat { simp [min_height, size1, min_def] },\n  split_ifs,\n  { have h3: 2 ^ min_height l <= 2 ^ min_height r, from iff.elim_right (nat.pow_le_iff_le_right h2) h,\n    calc\n      2 ^ (min_height l + 1) = 2 ^ min_height l + 2 ^ min_height l : by ring\n      ... <= 2 ^ min_height l + 2 ^ min_height r : by simp *\n      ... <= size1 l + 2 ^ min_height r: by simp *\n      ... <= size1 l + size1 r : by simp * },\n  have h1: min_height r <= min_height l, by linarith, \n  have h3: 2 ^ min_height r <= 2 ^ min_height l, from iff.elim_right (nat.pow_le_iff_le_right h2) h1,\n    calc\n      2 ^ (min_height r + 1) = 2 ^ min_height r + 2 ^ min_height r : by ring\n      ... <= 2 ^ min_height l + 2 ^ min_height r : by simp *\n      ... <= 2 ^ min_height l + size1 r: by simp *\n      ... <= size1 l + size1 r : by simp *\nend\n\n/-\n## Lemmas set_tree\nThese lemmas are only in the Isabelle file.\n-/\n\n@[simp]\nlemma eq_set_tree_empty : set_tree t = {} ↔ t = nil :=\nbegin\n  cases t with a l r,\n  repeat { simp [set_tree, set.nonempty.ne_empty]},\nend\n\n@[simp]\nlemma eq_empty_set_tree: {} = set_tree t ↔ t = nil :=\nbegin\n  cases t with a l r,\n  repeat { simp [ set_tree]},\n  apply ne.symm,\n  simp [set.nonempty.ne_empty],\nend\n\n@[simp]\nlemma finite_set_tree : (set_tree t).finite :=\nbegin\n  induction' t with a l r,\n  repeat { simp [set_tree] },\n  apply set.finite.union,\n  { simp *,},\n  assumption\nend\n\n/-\n## Lemmas Subtrees\nThese lemmas are only in the Isabelle file.\n-/\n\n@[simp]\nlemma neq_subtrees_empty : subtrees t ≠ {} :=\nbegin\n  cases t with a l r,\n  repeat { simp [subtrees, set.nonempty.ne_empty] },\nend\n\n@[simp]\nlemma neg_empty_subtrees : {} ≠ subtrees t :=\nbegin\n  apply ne.symm,\n  cases t,\n  repeat { simp [subtrees, set.nonempty.ne_empty] },\nend\n\nlemma size_subtrees: s ∈ subtrees t → size s <= size t :=\nbegin\n  induction' t with a l r,\n  repeat { simp [subtrees, size] },\n  intro h,\n  cases h,\n  { cases h,\n    { calc\n        size s = size l + size r + 1 : by simp [*, size]\n        ... ≤ size l + size r + 1: by ring},\n    calc \n      size s <= size l: by simp *\n      ... ≤ size l + size r + 1: by linarith,},\n  calc \n  size s <= size r: by simp *\n  ... ≤ size l + size r + 1: by linarith,\nend\n\nlemma set_treeE: a ∈ set_tree t → ∃ l r, (node a l r) ∈ subtrees t :=\nbegin\n  induction' t fixing * with x l r,\n  repeat {simp [set_tree],},\n  intro h,\n  cases h,\n  { cases h,\n    { apply exists.intro l,\n      apply exists.intro r,\n      rw h,\n      simp [subtrees],},\n    have ih_l' : ∃ (l_1 r : tree α), node a l_1 r ∈ subtrees l, from ih_l h,\n    apply exists.elim ih_l',\n    intros a_1 h1,\n    apply exists.elim h1,\n    intros a_2 h2,\n    apply exists.intro a_1,\n    apply exists.intro a_2,\n    simp [subtrees],\n    cc, },\n  have ih_r': ∃ (l r_1 : tree α), node a l r_1 ∈ subtrees r, from ih_r h,\n  apply exists.elim ih_r',\n  intros a_1 h1,\n  apply exists.elim h1,\n  intros a_2 h2,\n  apply exists.intro a_1,\n  apply exists.intro a_2,\n  simp [subtrees],\n  cc,\nend\n\n@[simp]\nlemma node_notin_subtrees_if : a ∉ set_tree t → node a l r ∉ subtrees t :=\nbegin\n  induction' t fixing *,\n  { simp [set_tree, subtrees] },\n  simp [set_tree],\n  intro h,\n  rw not_or_distrib at h,\n  cases h,\n  rw not_or_distrib at h_left,\n  have: node a l r ∉ subtrees t_1, from ih_t_1 h_right,\n  have: node a l r ∉ subtrees t, from ih_t h_left.right,\n  simp [subtrees],\n  cc,\nend\n\nlemma in_set_tree_if: node a l r ∈ subtrees t → a ∈ set_tree t :=\nbegin\n  contrapose,\n  exact node_notin_subtrees_if a t l r\nend\n\n/-\n## Lemmas List of Entries\nThese lemmas are only in the Isabelle file.\n-/\n\n@[simp]\nlemma eq_inorder_nil: inorder t = [] ↔ t = nil :=\nbegin\n  cases t,\n  repeat { simp [inorder] },\nend\n\n@[simp]\nlemma eq_nil_inorder: [] = inorder t ↔ t = nil :=\nbegin\n  cases t,\n  repeat { simp [inorder] },\nend\n\n@[simp]\nlemma set_inorder : (inorder t).to_set = set_tree t :=\nbegin\n  induction' t,\n  repeat { simp only [inorder, list.to_set, set_tree] },\n  simp only [set_append, list.to_set, *, set.union_empty],\nend\n\n@[simp]\nlemma set_preorder : (preorder' t).to_set = set_tree t :=\nbegin\n  induction' t,\n  repeat { simp only [preorder', list.to_set, set_tree] },\n  simp only [set_append, list.to_set, *, set.union_comm, set.union_empty],\nend\n\n@[simp]\nlemma set_postorder : (postorder t).to_set = set_tree t :=\nbegin\n  induction' t,\n  repeat { simp  [postorder, list.to_set, set_tree] },\n  simp [set_append, list.to_set, *, set.union_empty, set.insert_union],\nend\n\n@[simp]\nlemma length_preorder: (preorder' t).length = size t :=\nbegin\n  induction' t,\n  repeat { simp [size, preorder', *] },\nend\n\n@[simp]\nlemma length_inorder: (inorder t).length = size t :=\nbegin\n  induction' t,\n  repeat { simp [size, inorder, *, add_assoc] },\nend\n\n@[simp]\nlemma length_postorder: (postorder t).length = size t :=\nbegin\n  induction' t,\n  repeat { simp [size, postorder, *, add_assoc] },\nend\n\nlemma preorder_map: preorder' (map f t) = list.map f (preorder' t) :=\nbegin\n  induction' t,\n  repeat { simp [map, preorder', *] },\nend\n\nlemma inorder_map: inorder (map f t) = list.map f (inorder t) :=\nbegin\n  induction' t,\n  repeat { simp [map, inorder, *] },\nend\n\nlemma postorder_map: postorder (map f t) = list.map f (postorder t) :=\nbegin\n  induction' t,\n  repeat { simp [map, postorder, *] },\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/binary_tree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7776394309320047}}
{"text": "/- # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n1.1. Carry out the following proofs using basic tactics.\nHint: Some strategies for carrying out such proofs are described at the end of\nSection 2.3 in the Hitchhiker's Guide. -/\n\nlemma I (a : Prop) :\n  a → a :=\nbegin\n  intro h1,\n  exact h1,\nend\n\nlemma K (a b : Prop) :\n  a → b → b :=\nbegin\n  assume ha,\n  exact I(b),\nend\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nbegin\n  assume h1,\n  assume hb,\n  assume ha,\n  exact h1 ha hb,\nend\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nbegin\n  assume h1,\n  assume h2,\n  exact h1,\nend\n\n/- Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nbegin\n  exact K a a,\nend\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nbegin\n  assume h1,\n  assume ha,\n  assume hac,\n  assume hb,\n  exact hac ha,\nend\n\n/- 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nbegin\n  assume hab,\n  assume nob,\n  assume ha,\n  exact nob (hab ha),\nend\n\n/- 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nbegin\n  apply iff.intro,\n  {\n    assume h1,\n    apply and.intro,\n    {\n      assume t,\n      have h2 := h1 t,\n      exact and.elim_left h2,\n    },\n    {\n      assume t,\n      have h2 := h1 t,\n      exact and.elim_right h2,\n    }\n  },\n  {\n    assume h1,\n    assume t,\n    exact and.intro (and.elim_left h1 t) (and.elim_right h1 t)\n    }\nend\n\n\n/- ## Question 2: Natural Numbers\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nsorry\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nsorry\n\n/- 2.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nsorry\n\n/- 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nsorry\n\n\n/- ## Question 3 (**optional**): Intuitionistic Logic\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation :=\n∀a : Prop, (¬¬ a) → a\n\n/- For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, because this would defeat the purpose of the exercise.\n3.1 (**optional**). Prove the following implication using tactics.\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nbegin\n  rw excluded_middle,\n  rw peirce,\n  assume exc,\n  assume ha hb,\n  assume h1,\n  apply or.elim (exc ha),\n  {\n    assume a,\n    exact a,\n  },\n  {\n    assume noa,\n    apply h1,\n    assume a,\n    apply false.elim,\n    exact noa a,\n  }\nend\n\n/- 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nbegin\n  rw peirce,\n  rw double_negation,\n  assume hpeir,\n  assume a,\n  assume hnonoa,\n  apply hpeir a false,\n  assume hnoa,\n  apply false.elim,\n  apply hnonoa,\n  exact hnoa,\nend\n\n/- We leave the missing implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\n\nend backward_proofs\n\nend LoVe", "meta": {"author": "raulmom", "repo": "Colab", "sha": "6c0b668e7ac308047faa34b21bb06759ef0b9f6c", "save_path": "github-repos/lean/raulmom-Colab", "path": "github-repos/lean/raulmom-Colab/Colab-6c0b668e7ac308047faa34b21bb06759ef0b9f6c/UACourse/Tema_2/Exercise_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.7774170493668485}}
{"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 data.polynomial.ring_division\nimport data.mv_polynomial.rename\nimport ring_theory.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 `φ ψ : mv_polynomial σ R`\n  over an infinite integral domain `R` are equal if `eval x φ = eval x ψ` for all `x : σ → R`.\n\n-/\n\nnamespace mv_polynomial\n\nvariables {R : Type*} [comm_ring R] [is_domain R] [infinite R]\n\nprivate lemma funext_fin {n : ℕ} {p : mv_polynomial (fin n) R}\n  (h : ∀ x : fin n → R, eval x p = 0) : p = 0 :=\nbegin\n  unfreezingI { induction n with n ih generalizing R },\n  { let e := (mv_polynomial.is_empty_ring_equiv R (fin 0)),\n    apply e.injective,\n    rw ring_equiv.map_zero,\n    convert h fin_zero_elim,\n    suffices : (eval₂_hom (ring_hom.id _) (is_empty.elim' fin.is_empty)) p =\n      (eval fin_zero_elim : mv_polynomial (fin 0) R →+* R) p,\n    { rw [← this],\n      simp only [coe_eval₂_hom, is_empty_ring_equiv_apply,\n        ring_equiv.trans_apply, aeval_eq_eval₂_hom],\n      congr },\n    exact eval₂_hom_congr rfl (subsingleton.elim _ _) rfl },\n  { let e := (fin_succ_equiv R n).to_ring_equiv,\n    apply e.injective,\n    simp only [ring_equiv.map_zero],\n    apply polynomial.funext,\n    intro q,\n    rw [polynomial.eval_zero],\n    apply ih, swap, { apply_instance },\n    intro x,\n    dsimp [e],\n    rw [fin_succ_equiv_apply],\n    calc _ = eval _ p : _\n       ... = 0 : h _,\n    { intro i, exact fin.cases (eval x q) x i },\n    apply induction_on p,\n    { intro r,\n      simp only [eval_C, polynomial.eval_C, ring_hom.coe_comp, eval₂_hom_C], },\n    { intros, simp only [*, ring_hom.map_add, polynomial.eval_add] },\n    { intros φ i hφ, simp only [*, eval_X, polynomial.eval_mul, ring_hom.map_mul, eval₂_hom_X'],\n      congr' 1,\n      by_cases hi : i = 0,\n      { subst hi, simp only [polynomial.eval_X, fin.cases_zero] },\n      { rw [← fin.succ_pred i hi], simp only [eval_X, polynomial.eval_C, fin.cases_succ] } },\n    { apply_instance, }, },\nend\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. -/\nlemma funext {σ : Type*} {p q : mv_polynomial σ R}\n  (h : ∀ x : σ → R, eval x p = eval x q) : p = q :=\nbegin\n  suffices : ∀ p, (∀ (x : σ → R), eval x p = 0) → p = 0,\n  { rw [← sub_eq_zero, this (p - q)], simp only [h, ring_hom.map_sub, forall_const, sub_self] },\n  clear h p q,\n  intros p h,\n  obtain ⟨n, f, hf, p, rfl⟩ := exists_fin_rename p,\n  suffices : p = 0, { rw [this, alg_hom.map_zero] },\n  apply funext_fin,\n  intro x,\n  classical,\n  convert h (function.extend f x 0),\n  simp only [eval, eval₂_hom_rename, function.extend_comp hf]\nend\n\nlemma funext_iff {σ : Type*} {p q : mv_polynomial σ R} :\n  p = q ↔ (∀ x : σ → R, eval x p = eval x q) :=\n⟨by rintro rfl; simp only [forall_const, eq_self_iff_true], funext⟩\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/funext.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7774170368938111}}
{"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 6 : \"or\" (∨`)\n\nWe learn about how to manipulate `P ∨ 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-/\n\n-- Throughout this sheet, `P`, `Q`, `R` and `S` will denote propositions.\n\nvariables (P Q R S : Prop)\n\nexample : P → P ∨ Q :=\nbegin\n  intro hP,\n  left,\n  exact hP,\nend\n\nexample : Q → P ∨ Q :=\nbegin\n  intro hQ,\n  right,\n  exact hQ,\nend\n\nexample : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  intros hPoQ hPR hQR,\n  cases hPoQ with hP hQ,\n  { apply hPR,\n    exact hP },\n  { exact hQR hQ }\nend\n\n-- symmetry of `or`\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  intro hPoQ,\n  cases hPoQ with hP hQ,\n  { right, assumption },\n  { left, assumption }\nend\n\n-- associativity of `or`\nexample : (P ∨ Q) ∨ R ↔ P ∨ (Q ∨ R) :=\nbegin\n  split,\n  { rintros ((hP | hQ) | hR),\n    { left, exact hP },\n    { right, left, exact hQ },\n    { right, right, exact hR } },\n  { rintros (hP | hQ | hR),\n    { left, left, exact hP },\n    { left, right, exact hQ },\n    { right, exact hR } }\nend\n\nexample : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  rintro hPR hQS (hP | hQ),\n  { left, apply hPR, exact hP },\n  { right, exact hQS hQ }\nend\n\nexample : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  intros hPQ h,\n  cases h with hP hR,\n  { left, apply hPQ, exact hP },\n  { right, exact hR }\nend\n\nexample : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  intros h1 h2,\n  rw [h1, h2],\nend\n\n-- de Morgan's laws\nexample : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ 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  { rintro ⟨hnP, hnQ⟩ (hP | hQ),\n    { apply hnP, exact hP },\n    { exact hnQ hQ } }\nend\n\nexample : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\nbegin\n  split,\n  { intro h,\n    by_cases hP : P,\n    { right,\n      intro hQ,\n      apply h,\n      exact ⟨hP, hQ⟩ },\n    { left,\n      exact hP } },\n  { rintro (hnP | hnQ) ⟨hP, hQ⟩,\n    { contradiction },\n    { apply hnQ, exact hQ } }\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/section01logic/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7774067411689929}}
{"text": "import set_theory_world.image_union -- hide\nopen function -- hide\nopen_locale big_operators -- hide\n/-\n## Indexed unions\n\nIn this level we learn how to work with arbitrary indexed unions. These are made\nof an index set, and a function `A : I → set X`, that picks a subset of `A i` of `X` for\neach index `i : I`.\n\nThe defining property of the union is given by the following lemma:\n-/\n\n/- Symbol :\n∪ : \\cup\n∩ : \\cap\n⋃ : \\Union\n⋂ : \\Inter\n-/\nvariables {X Y I : Type} -- hide\nvariables {A : I → set X}\nvariable {x : X}\n\nlemma mem_Union : (x ∈ ⋃ i, A i) ↔ ∃ i, x ∈ A i :=\nset.mem_Union -- hide\n\n/- Lemma : \nThe image of an arbitrary union of sets is the union of the images.\n-/\nlemma image_Union  (f : X → Y) (A : I → set X) :\nf '' ( ⋃ i, A i ) = ⋃ i, f '' (A i) :=\nbegin\n  ext y,\n  split,\n  {\n    intro h,\n    obtain ⟨x, ⟨hx1, hx2⟩⟩ := h,\n    rw set.mem_Union at hx1,\n    obtain ⟨j, hj⟩ := hx1,\n    rw mem_Union,\n    use j,\n    use x,\n    split; assumption,\n  },\n  {\n    intro h,\n    rw mem_Union at h,\n    obtain ⟨i, hi⟩ := h,\n    obtain ⟨x, ⟨hx1, hx2⟩⟩ := hi,\n    use x,\n    rw mem_Union,\n    split,\n    {\n      use i,\n      assumption,\n    },\n    {\n      assumption,\n    }\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.9304582554941719, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7773825601445922}}
{"text": "/-\nSimulating classical reasoning without assuming excluded middle.\nThe idea is to use the double-negation translation.\nWe define several \"helper\" theorems for double negated formulas.\n-/\nvariables {p q r : Prop}\n\ntheorem not_and_of_or_not : ¬p ∨ ¬q → ¬(p ∧ q) :=\nλ h hpq, or.elim h\n  (λ hnp : ¬p, absurd (and.elim_left hpq) hnp)\n  (λ hnq : ¬q, absurd (and.elim_right hpq) hnq)\n\ntheorem not_or_elim_left : ¬(p ∨ q) → ¬p :=\nλ hpq hp, absurd (or.inl hp) hpq\n\ntheorem not_or_elim_right : ¬(p ∨ q) → ¬q :=\nλ hpq hq, absurd (or.inr hq) hpq\n\ntheorem not_imp_elim_right : ¬(p → q) → ¬q :=\nλ h₁ hq, absurd (λ h, hq) h₁\n\ntheorem not_imp_elim_left : ¬(p → q) → ¬¬p :=\nλ h₁ hnp, absurd (λ hp, by contradiction) h₁\n\ntheorem not_imp_intro : ¬¬p → ¬q → ¬(p → q) :=\nλ hnnp hnq hpq,\n  have hnp : ¬ p, from λ hp, absurd (hpq hp) hnq,\n  absurd hnp hnnp\n\n/- Double negation introduction -/\ntheorem nn_intro : p → ¬¬p :=\nλ hp hnp, absurd hp hnp\n\n/- Double negated implication -/\n-- Introduction\ntheorem nn_imp_intro : (¬¬p → ¬¬q) → ¬¬(p → q) :=\nλ h hnpq,\n  have hnnp : ¬¬p, from not_imp_elim_left hnpq,\n  have hnq  : ¬q,  from not_imp_elim_right hnpq,\n  have hnnq : ¬¬q, from h hnnp,\n  absurd hnq hnnq\n\n-- Elimination (modus ponens)\ntheorem nn_mp : ¬¬(p → q) → p → ¬¬q :=\nλ hpq hp hnq,\n  have aux : ¬(p → q), from not_imp_intro (nn_intro hp) hnq,\n  absurd aux hpq\n\n-- Double negated modus tollens\ntheorem nn_mt : ¬¬(p → q) → ¬q → ¬p :=\nλ hpq hnq hp, absurd hnq (nn_mp hpq hp)\n\n/- Double negated disjuction -/\nlemma not_or_of_not_of_not : ¬p → ¬q → ¬(p ∨ q) :=\nλ hnp hnq hpq, or.elim hpq (λ hp, absurd hp hnp) (λ hq, absurd hq hnq)\n\n-- Elimination\ntheorem nn_or_elim : ¬¬(p ∨ q) → (p → ¬¬r) → (q → ¬¬r) → ¬¬r :=\nλ hpq hpr hqr hnr,\n  have hnp : ¬p, from λhp, absurd hnr (hpr hp),\n  have hnq : ¬q, from λhq, absurd hnr (hqr hq),\n  have aux : ¬(p ∨ q), from not_or_of_not_of_not hnp hnq,\n  absurd aux hpq\n\n-- Introduction\ntheorem nn_or_inl : ¬¬p → ¬¬(p ∨ q) :=\nλ h hnpq, absurd (not_or_elim_left hnpq) h\n\ntheorem nn_or_inr : ¬¬q → ¬¬(p ∨ q) :=\nλ h hnpq, absurd (not_or_elim_right hnpq) h\n\n/- Double negated conjunction -/\n\n-- Elimination\ntheorem nn_and_elim_left : ¬¬(p ∧ q) → ¬¬p :=\nλ h hnp, absurd (not_and_of_or_not (or.inl hnp)) h\n\ntheorem nn_and_elim_right : ¬¬(p ∧ q) → ¬¬q :=\nλ h hnq, absurd (not_and_of_or_not (or.inr hnq)) h\n\n-- Introduction\ntheorem nn_and_intro : ¬¬p → ¬¬q → ¬¬(p ∧ q) :=\nλ hnnp hnnq hnpq,\n  have h₁ : ¬(p → ¬q), from not_imp_intro hnnp hnnq,\n  have h₂ :  p → ¬q,   from λ hp hq, absurd (and.intro hp hq) hnpq,\n  absurd h₂ h₁\n\n/- Double negated excluded middle -/\ntheorem nn_em : ¬¬(p ∨ ¬p) :=\nλ hn,\n  have hnp : ¬p,   from not_or_elim_left hn,\n  have hnnp : ¬¬p, from not_or_elim_right hn,\n  absurd hnp hnnp\n\n/- Examples: the following two examples are classically valid.\n   We can \"simulate\" the classical proofs using double negation.\n-/\nexample : ¬¬((p → q) → (¬p ∨ q)) :=\nnn_imp_intro (λ h, nn_or_elim (@nn_em p)\n  (λ hp  : p,\n     have hnnq : ¬¬q, from nn_mp h hp,\n     nn_or_inr hnnq)\n  (λ hnp : ¬p, nn_intro (or.inl hnp)))\n\n/- \"Prove\" Peirce's law -/\nexample : ¬¬(((p → q) → p) → p) :=\nnn_imp_intro (λ h, nn_or_elim (@nn_em p)\n  (λ hp  :  p, nn_intro hp)\n  (λ hnp : ¬p,\n    have h₁ : ¬(p → q), from nn_mt h hnp,\n    have hnnp : ¬¬p,    from not_imp_elim_left h₁,\n    absurd hnp hnnp))\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/double_negation_translation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7773825573550099}}
{"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 analysis.complex.arg\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.InnerProductSpace.Basic\nimport Mathbin.Analysis.SpecialFunctions.Complex.Arg\n\n/-!\n# Rays in the complex numbers\n\nThis file links the definition `same_ray ℝ x y` with the equality of arguments of complex numbers,\nthe usual way this is considered.\n\n## Main statements\n\n* `complex.same_ray_iff` : Two complex numbers are on the same ray iff one of them is zero, or they\n  have the same argument.\n* `complex.abs_add_eq/complex.abs_sub_eq`: If two non zero complex numbers have different argument,\n  then the triangle inequality becomes strict.\n\n-/\n\n\nvariable {x y : ℂ}\n\nnamespace Complex\n\ntheorem sameRay_iff : SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\n  by\n  rcases eq_or_ne x 0 with (rfl | hx)\n  · simp\n  rcases eq_or_ne y 0 with (rfl | hy)\n  · simp\n  simp only [hx, hy, false_or_iff, sameRay_iff_norm_smul_eq, arg_eq_arg_iff hx hy]\n  field_simp [hx, hy]\n  rw [mul_comm, eq_comm]\n#align complex.same_ray_iff Complex.sameRay_iff\n\ntheorem sameRay_iff_arg_div_eq_zero : SameRay ℝ x y ↔ arg (x / y) = 0 :=\n  by\n  rw [← Real.Angle.toReal_zero, ← arg_coe_angle_eq_iff_eq_to_real, same_ray_iff]\n  by_cases hx : x = 0; · simp [hx]\n  by_cases hy : y = 0; · simp [hy]\n  simp [hx, hy, arg_div_coe_angle, sub_eq_zero]\n#align complex.same_ray_iff_arg_div_eq_zero Complex.sameRay_iff_arg_div_eq_zero\n\ntheorem abs_add_eq_iff : (x + y).abs = x.abs + y.abs ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\n  sameRay_iff_norm_add.symm.trans sameRay_iff\n#align complex.abs_add_eq_iff Complex.abs_add_eq_iff\n\ntheorem abs_sub_eq_iff : (x - y).abs = |x.abs - y.abs| ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\n  sameRay_iff_norm_sub.symm.trans sameRay_iff\n#align complex.abs_sub_eq_iff Complex.abs_sub_eq_iff\n\ntheorem sameRay_of_arg_eq (h : x.arg = y.arg) : SameRay ℝ x y :=\n  sameRay_iff.mpr <| Or.inr <| Or.inr h\n#align complex.same_ray_of_arg_eq Complex.sameRay_of_arg_eq\n\ntheorem abs_add_eq (h : x.arg = y.arg) : (x + y).abs = x.abs + y.abs :=\n  (sameRay_of_arg_eq h).norm_add\n#align complex.abs_add_eq Complex.abs_add_eq\n\ntheorem abs_sub_eq (h : x.arg = y.arg) : (x - y).abs = ‖x.abs - y.abs‖ :=\n  (sameRay_of_arg_eq h).norm_sub\n#align complex.abs_sub_eq Complex.abs_sub_eq\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/Arg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7773525461914917}}
{"text": "/-\nCopyright (c) 2020 Kevin Buzzard. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kevin Buzzard\n-/\nimport algebra.group.pi\nimport algebra.group.commute\nimport data.int.basic\nimport tactic.linarith\n\n/-!\n# IMO 2019 Q1\n\nDetermine all functions `f : ℤ → ℤ` such that, for all integers `a` and `b`,\n`f(2a) + 2f(b) = f(f(a+b))`.\n\nThe desired theorem is that either:\n  -  `f = λ _, 0`\n  -  `∃ c, f = λ x, 2 * x + c`\n\nNote that there is a much more compact proof of this fact in Isabelle/HOL\n  - http://downthetypehole.de/paste/4YbGgqb4\n-/\n\ntheorem imo2019Q1 (f : ℤ → ℤ) :\n  (∀ a b : ℤ, f (2 * a) + 2 * (f b) = f (f (a + b))) ↔\n    (f = 0) ∨ ∃ c, f = λ x, 2 * x + c :=\nbegin\n  split, swap,\n  -- easy way: f(x)=0 and f(x)=2x+c work.\n  { rintros (rfl|⟨c, rfl⟩); intros; simp only [pi.zero_apply]; ring },\n  -- hard way.\n  intro hf, -- functional equation\n  -- Using `h` for `(0, b)` and `(-1, b + 1)`, we get `f (b + 1) = f b + m`\n  obtain ⟨m, H⟩ : ∃ m, ∀ b, f (b + 1) = f b + m,\n  { refine ⟨(f 0 - f (-2)) / 2, λ b, _⟩,\n    refine sub_eq_iff_eq_add'.1 (int.eq_div_of_mul_eq_right two_ne_zero _),\n    have h1 : f 0 + 2 * f b = f (f b) := by simpa using hf 0 b,\n    have h2 : f (-2) + 2 * f (b + 1) = f (f b) := by simpa using hf (-1) (b + 1),\n    linarith },\n  -- Hence, `f` is an affine map, `f b = f 0 + m * b`\n  obtain ⟨c, H⟩ : ∃ c, ∀ b, f b = c + m * b,\n  { refine ⟨f 0, λ b, _⟩,\n    induction b using int.induction_on with b ihb b ihb,\n    { simp },\n    { simp [H, ihb, mul_add, add_assoc] },\n    { rw ← sub_eq_of_eq_add (H _),\n      simp [ihb]; ring } },\n  -- Now use `hf 0 0` and `hf 0 1` to show that `m ∈ {0, 2}`\n  have H3 : 2 * c = m * c := by simpa [H, mul_add] using hf 0 0,\n  obtain (rfl|rfl) : 2 = m ∨ m = 0 := by simpa [H, mul_add, H3] using hf 0 1,\n  { right, use c, ext b, simp [H, add_comm] },\n  { left, ext b, simpa [H, two_ne_zero] using H3 }\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/imo2019_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7773525418206391}}
{"text": "/- TACTICS -/\n\nnamespace TBA\n\n-- definitions from last week\n-- NOTE: We renamed it from `Nat'` for consistency. The new namespace makes sure we don't use the\n-- standard library `Nat`.\ninductive Nat : Type\n  | zero : Nat\n  | succ (n : Nat) : Nat\n\nopen Nat\n\ndef add (m n : Nat) : Nat :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\n-- With this command we add a notation for `add`. From now on we will be able to write `m + n` for\n-- `add m n`. The 65 denotes how strongly the operator should bind to what's adjacent to it.\n-- The `priority` means that Lean will prefer it over the built-in `+`.\ninfix:65 (priority := high) \" + \" => add\n\ndef mul (m n : Nat) : Nat :=\n  match n with\n  | zero   => zero\n  | succ n => (mul m n) + m\n\n-- We also want a notation for `mul`, with a higher binding strength than addition so that\n-- `a + b * c` means `a + (b * c`)`.\ninfix:70 (priority := high) \" * \" => mul\n\ninductive LE : Nat → Nat → Prop where\n  | refl (n : Nat) : LE n n\n  | succ : LE m n → LE m (succ n)\n\n-- lower binding strength than either addition or multiplication\ninfix:50 (priority := high) \" ≤ \" => LE\n\n-- Let's start by reproving some theorems from last week, but this time with tactics!\n-- useful tactics:\n-- * `induction ... with ...`\n-- * `simp only [f]` to unfold applications of a function `f`\n-- * `rw [h]` to rewrite every `a` to `b` if `h : a = b`\n-- * `apply/exact`\n-- * `simp/simp_all`... are powerful and basically always useful, though make sure that you could also\n--   do the proof without them\ntheorem zero_add : zero + n = n := by\n  induction n with\n  | zero      =>\n    rfl\n    -- same as\n    --exact rfl\n  | succ n ih =>\n    simp only [add]\n    rw [ih]\n    -- or\n    --simp [add, ih]\n  -- or simply\n  --induction n <;> simp_all [add]\n  \n\ntheorem le_add : m ≤ m + n := by\n  induction n with\n  | zero =>\n    apply LE.refl\n    -- same as\n    --exact LE.refl _\n  | succ n ih =>\n    simp only [add]  -- optional, but helpful\n    apply LE.succ\n    apply ih\n    -- same as\n    --exact LE.succ ih\n    -- alternatively, simply use\n    --simp [add, LE.succ, ih]\n    -- ...but using a conditional simp theorem like `LE.succ` is usually not obvious\n    -- when first writing a proof\n  -- or simply\n  --induction n <;> simp_all [LE.refl, LE.succ, add]\n  \n\n-- Alright, let's start automating more!\nattribute [simp] add mul\n-- These definitions will now automatically be unfolded when you use `simp/simp_all`\n\n\ntheorem add_succ : (succ n) + m = succ (n + m) := by\n  induction m <;> simp_all [zero_add]\n\n-- This one is a bit more tricky, you might need to prove a helper lemma!\ntheorem add_comm : n + m = m + n := by\n  induction n with\n  | zero      => simp [zero_add]\n  | succ n ih => simp [add_succ, ih]\n  \n\n-- Associativity can be proven in a similar way.\ntheorem add_assoc : (m + n) + k = m + (n + k) := by\n  induction k with\n  | zero      => rfl\n  | succ k ih => simp [add_succ, ih]\n  \n\ndef one := succ zero\n\ntheorem mul_one : m * one = m := by\n  simp [zero_add]\n\n-- To prove associativity of multiplication, you might have to come up with\n-- some more lemmas about multiplication first. Some are similar to the above laws of\n-- addition, some use both addition and multiplication (\"distributivity\" is the keyword).\n\ntheorem left_distrib : m * (n + k) = (m * n) + (m * k) := by\n  induction k with\n  | zero      => simp\n  | succ k ih =>\n    simp only [mul]\n    rw [ih, ←add_assoc]\n    -- NOTE: We *could* also use `add_assoc` as a simp theorem here.\n    -- ```\n    --  | succ n ih => simp [add_succ, ih, add_assoc]\n    -- ```\n    -- This even works with `add_comm` since `simp` is clever enough to avoid\n    -- permutating applicable terms endlessly! However, such general simp theorems\n    -- are best avoided for performance reasons and unintended interactions with\n    -- other simp theorems.\n\n\ntheorem mul_assoc : (m * n) * k = m * (n * k) := by \n  induction k with\n  | zero      => rfl\n  | succ k ih => simp [ih, left_distrib]\n  \n\n-- Remember the structures for semigroups and monoids which we defined last week?\nstructure Semigroup (α : Type) where\n  mul   : α → α → α\n  assoc : mul (mul a b) c = mul a (mul b c)\n\nstructure Monoid (α : Type) extends Semigroup α where\n  e     : α\n  e_mul : mul e a = a\n  mul_e : mul a e = a\n\n\ntheorem one_mul : one * m = m := by\n  induction m with\n  | zero      => rfl\n  | succ m ih => simp [ih]\n\n-- You should now be able to instantiate two of them,  including proofs!\ndef Nat_add_Monoid : Monoid Nat := \n  { mul := add,\n    assoc := add_assoc,\n    e := zero,\n    e_mul := by intros; simp [zero_add]\n    mul_e := by intros; rfl }\n  \n\ndef Nat_mul_Monoid : Monoid Nat := \n  { mul := mul,\n    assoc := mul_assoc,\n    e := one,\n    e_mul := one_mul,\n    mul_e := mul_one }\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/Exercise4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7772002835566234}}
{"text": "\n/- Problem 1: Append and Reverse -/\n\n/- Prove the following theorems. If you can't complete a proof, \nyou can use the tactic `sorry` for any part that you are \nunable to complete. -/\n\n/- Note that we again define our own append reverse, \nthis time using the built in types -/\n\n-- part p1\ndef app : List Nat -> List Nat -> List Nat\n  | List.nil,       bs => bs\n  | List.cons a as, bs => List.cons a (app as bs)\n\ndef rev : List Nat -> List Nat \n  | List.nil => List.nil\n  | List.cons a L => app (rev L) (List.cons a List.nil) \n\n-- 6 lines\ntheorem app_nil : forall (l : List Nat), app l [] = l := \n  by sorry\n\n-- 6 lines\ntheorem app_assoc : forall (l1 l2 l3 : List Nat),\n  app (app l1 l2) l3 = app l1 (app l2 l3) := \n by sorry\n\n-- 8 lines\ntheorem rev_app_distr: forall l1 l2 : List Nat,\n  rev (app l1 l2) = app (rev l2) (rev l1) := \n by sorry\n\n-- 8 lines\ntheorem rev_involutive : forall l : List Nat,\n  rev (rev l) = l := \n by sorry\n-- part p1\n\n\n/- Problem 2: Evenness (and Relations) -/\n\n/- Prove the following theorems. If you can't complete a proof, \nyou can use the tactic `sorry` for any part that you are \nunable to complete. -/\n\n-- part p2\ninductive ev : Nat -> Prop \n| O : ev 0\n| SS (n : Nat) (H : ev n) : ev (Nat.succ (Nat.succ n))\n\ndef double : Nat -> Nat\n| 0 => 0\n| Nat.succ n => Nat.succ (Nat.succ (double n))\n\n-- 5 lines\ntheorem ev_double : forall n, ev (double n) := \n by sorry\n\n-- 15 lines\ntheorem ev_sum : forall n m, ev n -> ev m -> ev (Nat.add n m) := \n by sorry\n\n-- 3 lines\ntheorem three_not_ev : Not (ev 3) := \n by sorry\n\ninductive ev' : Nat -> Prop :=\n  | O : ev' 0\n  | SSO : ev' 2\n  | sum n m (Hn : ev' n) (Hm : ev' m) : ev' (Nat.add n m)\n\n-- 21 lines\ntheorem ev'_ev : forall n, ev' n <-> ev n := \n by sorry\n\n-- part p2\n\n/- Problem 3: Subsequences -/\n\n/- Prove the following theorems. If you can't complete a proof, \nyou can use the tactic `sorry` for any part that you are \nunable to complete. -/\n\n-- part p3\ninductive subseq : List Nat -> List Nat -> Prop\n| empty : subseq [] []\n| include x l1 l2 (H : subseq l1 l2) : subseq (x::l1) (x::l2)\n| skip x l1 l2 (H : subseq l1 l2) : subseq l1 (x::l2)\n\n-- 6 lines\ntheorem subseq_refl : forall (l : List Nat), \n  subseq l l :=\n by sorry\n\n-- 5 lines\ntheorem subseq_empty : forall l, subseq [] l := \n by sorry\n\n-- 13 lines\ntheorem subseq_app : forall (l1 l2 l3 : List Nat),\n  subseq l1 l2 ->\n  subseq l1 (List.append l2 l3) :=\n by sorry\n-- part p3\n\n/- Problem 4: Insertion Sort -/\n\n\n/- Prove the following theorems. If you can't complete a proof, \nyou can use the tactic `sorry` for any part that you are \nunable to complete. -/\n\n-- part p4\ndef insert : Nat -> List Nat -> List Nat\n| y, [] => [y]\n| y, x::xs => if Nat.ble y x \n              then y :: x :: xs \n              else x :: insert y xs\n\ndef isort : List Nat -> List Nat\n| []      => []\n| x :: xs => insert x (isort xs) \n\ninductive All : {T : Type} -> (T -> Prop) -> List T -> Prop\n| nil : All P []\n| cons : forall x L, P x -> All P L -> All P (x :: L)\n\ninductive Sorted : List Nat -> Prop\n| nil : Sorted []\n| cons : forall n l, Sorted l -> \n                     All (Nat.le n) l ->\n                     Sorted (n :: l)\n\n\ntheorem all_trans : forall (P : T -> Prop) (Q : T -> Prop) L,\n  All P L ->\n  (forall x, P x -> Q x) ->\n  All Q L := \n by intros P Q L Hall PtoQ\n    induction Hall\n    case nil => constructor\n    case cons P x L Px HL =>\n      constructor\n      apply PtoQ\n      assumption\n      assumption\n\n-- 23 lines\ntheorem insert_le : forall n x l,\n  All (Nat.le n) l ->\n  Nat.le n x ->\n  All (Nat.le n) (insert x l) := \n by sorry\n\n\ntheorem ble_inv : forall a b, \n                  Nat.ble a b = false\n               -> Nat.ble b a = true := \n by intros a b H\n    rw [Nat.ble_eq]\n    cases (Nat.le_total b a)\n    assumption\n    rw [<- Nat.not_lt_eq]\n    rw [<- Bool.not_eq_true] at H\n    rw [Nat.ble_eq] at H\n    contradiction\n\n-- 37 lines\ntheorem insert_sorted : forall x l, \n  Sorted l ->\n  Sorted (insert x l) := \n by sorry\n\n-- 8 lines\ntheorem isort_sorted : forall l, Sorted (isort l) :=\n by sorry\n\ninductive Permutation : {T : Type} -> List T -> List T -> Prop\n| nil   : Permutation [] []\n| skip  : forall (x : A) (l l' : List A),\n          Permutation l l' ->\n          Permutation (x :: l) (x :: l')\n| swap  : forall (x y : A) (l : List A),\n          Permutation (y :: x :: l) (x :: y :: l)\n| trans : forall l l' l'' : List A,\n          Permutation l l' ->\n          Permutation l' l'' ->\n          Permutation l l''\n\nexample : Permutation [true,true,false] [false,true,true] :=\n by apply Permutation.trans (l' := [true,false,true])\n    . apply Permutation.skip\n      apply Permutation.swap\n    . apply Permutation.swap\n\n-- 6 lines\ntheorem perm_refl : forall {T : Type} (l : List T), \n  Permutation l l := \n by sorry\n\n-- 10 lines\ntheorem perm_length : forall {T : Type} (l1 l2 : List T), \n  Permutation l1 l2 -> l1.length = l2.length :=\n by sorry\n\n-- 12 lines\ntheorem perm_sym : forall {T : Type} (l1 l2 : List T), \n  Permutation l1 l2 -> Permutation l2 l1 :=\n by sorry\n\n-- 18 lines\ntheorem insert_perm : forall x l, \n  Permutation (x :: l) (insert x l) :=\n by sorry\n\n-- 10 lines\ntheorem isort_perm : forall l, Permutation l (isort l) :=\n by sorry\n\n-- part p4", "meta": {"author": "logiccomp", "repo": "s23-hw9", "sha": "9bd57a90d51c9b7bb18f3a2dbe4d146c5d9c097a", "save_path": "github-repos/lean/logiccomp-s23-hw9", "path": "github-repos/lean/logiccomp-s23-hw9/s23-hw9-9bd57a90d51c9b7bb18f3a2dbe4d146c5d9c097a/hw9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7771291691933175}}
{"text": "-- Pruebas de la distributiva de la intersección general sobre la intersección \n-- ===========================================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) \n-- ----------------------------------------------------\n\nimport data.set\nimport tactic\n\nopen set\n\nvariables {I U : Type}\nvariables {A B : I → set U}\n\n-- 1ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\nbegin\n  ext,\n  split,\n  { intro h,\n    rw mem_Inter at h,\n    split,\n    { rw mem_Inter,\n      intro i,\n      exact (h i).left, },\n    { rw mem_Inter,\n      intro i,\n      exact (h i).right, }},\n  { rintro ⟨h1, h2⟩,\n    rw mem_Inter at *,\n    intro i,\n    exact ⟨h1 i, h2 i⟩, },\nend\n\n-- 2ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\next $\nassume x : U,\niff.intro\n( assume h : x ∈ ⋂ i, A i ∩ B i,\n  have h1 : ∀ i, x ∈ A i ∩ B i,     \n    from mem_Inter.mp h,\n  have h2 : ∀ i, x ∈ A i,           \n    from assume i, and.left (h1 i),\n  have h3 : ∀ i, x ∈ B i,           \n    from assume i, and.right (h1 i),\n  have h4 : x ∈ ⋂ i, A i,           \n    from mem_Inter.mpr h2,\n  have h5 : x ∈ ⋂ i, B i,           \n    from mem_Inter.mpr h3,\n  show x ∈ (⋂ i, A i) ∩ (⋂ i, B i), \n    from and.intro h4 h5)\n( assume h : x ∈ (⋂ i, A i) ∩ (⋂ i, B i),\n  have h1 : ∀ i, x ∈ A i,\n    from mem_Inter.mp (and.left h), \n  have h2 : ∀ i, x ∈ B i,\n    from mem_Inter.mp (and.right h),\n  have h3 : ∀ i, x ∈ A i ∩ B i,\n    from assume i, and.intro (h1 i) (h2 i),\n  show x ∈ ⋂ i, A i ∩ B i, \n    from mem_Inter.mpr h3)\n\n-- 3ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\n-- by library_search\nInter_inter_distrib A B\n\n-- 4ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\next (by finish)\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_la_propiedad_distributiva_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7771291681328448}}
{"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-/\nimport topology.metric_space.basic\n\n/-!\n# Infimum separation\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 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\nvariables {α β : Type*}\n\nnamespace set\n\nsection einfsep\nopen_locale ennreal\nopen function\n\n/-- The \"extended infimum separation\" of a set with an edist function. -/\nnoncomputable def einfsep [has_edist α] (s : set α) : ℝ≥0∞ :=\n⨅ (x ∈ s) (y ∈ s) (hxy : x ≠ y), edist x y\n\nsection has_edist\nvariables [has_edist α] {x y : α} {s t : set α}\n\nlemma le_einfsep_iff {d} : d ≤ s.einfsep ↔ ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ edist x y :=\nby simp_rw [einfsep, le_infi_iff]\n\ntheorem einfsep_zero :\n  s.einfsep = 0 ↔ ∀ C (hC : 0 < C), ∃ (x y ∈ s) (hxy : x ≠ y), edist x y < C :=\nby simp_rw [einfsep, ← bot_eq_zero, infi_eq_bot, infi_lt_iff]\n\ntheorem einfsep_pos :\n  0 < s.einfsep ↔ ∃ C (hC : 0 < C), ∀ (x y ∈ s) (hxy : x ≠ y), C ≤ edist x y :=\nby { rw [pos_iff_ne_zero, ne.def, einfsep_zero], simp only [not_forall, not_exists, not_lt] }\n\nlemma einfsep_top : s.einfsep = ∞ ↔ ∀ (x y ∈ s) (hxy : x ≠ y), edist x y = ∞ :=\nby simp_rw [einfsep, infi_eq_top]\n\nlemma einfsep_lt_top : s.einfsep < ∞ ↔ ∃ (x y ∈ s) (hxy : x ≠ y), edist x y < ∞ :=\nby simp_rw [einfsep, infi_lt_iff]\n\nlemma einfsep_ne_top : s.einfsep ≠ ∞ ↔ ∃ (x y ∈ s) (hxy : x ≠ y), edist x y ≠ ∞ :=\nby simp_rw [←lt_top_iff_ne_top, einfsep_lt_top]\n\nlemma einfsep_lt_iff {d} : s.einfsep < d ↔ ∃ (x y ∈ s) (h : x ≠ y), edist x y < d :=\nby simp_rw [einfsep, infi_lt_iff]\n\nlemma nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.nontrivial :=\nby { rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩, exact ⟨_, hx, _, hy, hxy⟩ }\n\nlemma nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.nontrivial :=\nnontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)\n\nlemma subsingleton.einfsep (hs : s.subsingleton) : s.einfsep = ∞ :=\nby { rw einfsep_top, exact λ _ hx _ hy hxy, (hxy $ hs hx hy).elim }\n\nlemma le_einfsep_image_iff {d} {f : β → α} {s : set β} :\n  d ≤ einfsep (f '' s) ↔ ∀ x y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) :=\nby simp_rw [le_einfsep_iff, ball_image_iff]\n\nlemma le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)\n  (hd : d ≤ s.einfsep) : d ≤ edist x y := le_einfsep_iff.1 hd x hx y hy hxy\n\nlemma einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) :\n  s.einfsep ≤ edist x y := le_edist_of_le_einfsep hx hy hxy le_rfl\n\nlemma einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)\n  (hxy' : edist x y ≤ d) : s.einfsep ≤ d := le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy'\n\nlemma le_einfsep {d} (h : ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ edist x y) :\n  d ≤ s.einfsep := le_einfsep_iff.2 h\n\n@[simp] lemma einfsep_empty : (∅ : set α).einfsep = ∞ := subsingleton_empty.einfsep\n\n@[simp] lemma einfsep_singleton : ({x} : set α).einfsep = ∞ := subsingleton_singleton.einfsep\n\nlemma einfsep_Union_mem_option {ι : Type*} (o : option ι) (s : ι → set α) :\n  (⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o; simp\n\nlemma einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep :=\nle_einfsep $ λ x hx y hy, einfsep_le_edist_of_mem (hst hx) (hst hy)\n\nlemma einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (hxy : x ≠ y), edist x y :=\nbegin\n  simp_rw le_infi_iff,\n  refine λ _ hy hxy, einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy\nend\n\nlemma le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : set α).einfsep :=\nbegin\n  simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff],\n  rintros a (rfl | rfl) b (rfl | rfl) hab; finish\nend\n\nlemma einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : set α).einfsep ≤ edist x y :=\neinfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy\n\nlemma einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : set α).einfsep ≤ edist y x :=\nby rw pair_comm; exact einfsep_pair_le_left hxy.symm\n\nlemma einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : set α).einfsep = (edist x y) ⊓ (edist y x) :=\nle_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair\n\nlemma einfsep_eq_infi : s.einfsep = ⨅ d : s.off_diag, (uncurry edist) (d : α × α) :=\nbegin\n  refine eq_of_forall_le_iff (λ _, _),\n  simp_rw [le_einfsep_iff, le_infi_iff, imp_forall_iff, set_coe.forall, subtype.coe_mk,\n          mem_off_diag, prod.forall, uncurry_apply_pair, and_imp]\nend\n\nlemma einfsep_of_fintype [decidable_eq α] [fintype s] :\n  s.einfsep = s.off_diag.to_finset.inf (uncurry edist) :=\nbegin\n  refine eq_of_forall_le_iff (λ _, _),\n  simp_rw [le_einfsep_iff, imp_forall_iff, finset.le_inf_iff, mem_to_finset, mem_off_diag,\n          prod.forall, uncurry_apply_pair, and_imp]\nend\n\nlemma finite.einfsep (hs : s.finite) :\n  s.einfsep = hs.off_diag.to_finset.inf (uncurry edist) :=\nbegin\n  refine eq_of_forall_le_iff (λ _, _),\n  simp_rw [le_einfsep_iff, imp_forall_iff, finset.le_inf_iff, finite.mem_to_finset, mem_off_diag,\n          prod.forall, uncurry_apply_pair, and_imp]\nend\n\nlemma finset.coe_einfsep [decidable_eq α] {s : finset α} :\n  (s : set α).einfsep = s.off_diag.inf (uncurry edist) :=\nby simp_rw [einfsep_of_fintype, ← finset.coe_off_diag, finset.to_finset_coe]\n\nlemma nontrivial.einfsep_exists_of_finite [finite s] (hs : s.nontrivial) :\n  ∃ (x y ∈ s) (hxy : x ≠ y), s.einfsep = edist x y :=\nbegin\n  classical,\n  casesI nonempty_fintype s,\n  simp_rw einfsep_of_fintype,\n  rcases @finset.exists_mem_eq_inf _ _ _ _ (s.off_diag.to_finset) (by simpa) (uncurry edist)\n    with ⟨_, hxy, hed⟩,\n  simp_rw mem_to_finset at hxy,\n  refine ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩\nend\n\nlemma finite.einfsep_exists_of_nontrivial (hsf : s.finite) (hs : s.nontrivial) :\n  ∃ (x y ∈ s) (hxy : x ≠ y), s.einfsep = edist x y :=\nby { letI := hsf.fintype, exact hs.einfsep_exists_of_finite }\n\nend has_edist\n\nsection pseudo_emetric_space\nvariables [pseudo_emetric_space α] {x y z : α} {s t : set α}\n\nlemma einfsep_pair (hxy : x ≠ y) : ({x, y} : set α).einfsep = edist x y :=\nbegin\n  nth_rewrite 0 [← min_self (edist x y)],\n  convert einfsep_pair_eq_inf hxy using 2,\n  rw edist_comm\nend\n\nlemma einfsep_insert :\n  einfsep (insert x s) = (⨅ (y ∈ s) (hxy : x ≠ y), edist x y) ⊓ (s.einfsep) :=\nbegin\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  rintros y (rfl | hy) z (rfl | hz) hyz,\n  { exact false.elim (hyz rfl) },\n  { exact or.inl (infi_le_of_le _ (infi₂_le hz hyz)) },\n  { rw edist_comm, exact or.inl (infi_le_of_le _ (infi₂_le hy hyz.symm)) },\n  { exact or.inr (einfsep_le_edist_of_mem hy hz hyz) }\nend\n\nlemma einfsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) :\n  einfsep ({x, y, z} : set α) = edist x y ⊓ edist x z ⊓ edist y z :=\nby simp_rw [einfsep_insert, infi_insert, infi_singleton, einfsep_singleton,\n            inf_top_eq, cinfi_pos hxy, cinfi_pos hyz, cinfi_pos hxz]\n\nlemma le_einfsep_pi_of_le {π : β → Type*} [fintype β] [∀ b, pseudo_emetric_space (π b)]\n  {s : Π (b : β), set (π b)} {c : ℝ≥0∞} (h : ∀ b, c ≤ einfsep (s b) ) :\n  c ≤ einfsep (set.pi univ s) :=\nbegin\n  refine le_einfsep (λ x hx y hy hxy, _),\n  rw mem_univ_pi at hx hy,\n  rcases function.ne_iff.mp hxy with ⟨i, hi⟩,\n  exact le_trans (le_einfsep_iff.1 (h i) _ (hx _) _ (hy _) hi) (edist_le_pi_edist _ _ i)\nend\n\nend pseudo_emetric_space\n\nsection pseudo_metric_space\nvariables [pseudo_metric_space α] {s : set α}\n\ntheorem subsingleton_of_einfsep_eq_top (hs : s.einfsep = ∞) : s.subsingleton :=\nbegin\n  rw einfsep_top at hs,\n  exact λ _ hx _ hy, of_not_not (λ hxy, edist_ne_top _ _ (hs _ hx _ hy hxy))\nend\n\ntheorem einfsep_eq_top_iff : s.einfsep = ∞ ↔ s.subsingleton :=\n⟨subsingleton_of_einfsep_eq_top, subsingleton.einfsep⟩\n\ntheorem nontrivial.einfsep_ne_top (hs : s.nontrivial) : s.einfsep ≠ ∞ :=\nby { contrapose! hs, rw not_nontrivial_iff, exact subsingleton_of_einfsep_eq_top hs }\n\ntheorem nontrivial.einfsep_lt_top (hs : s.nontrivial) : s.einfsep < ∞ :=\nby { rw lt_top_iff_ne_top, exact hs.einfsep_ne_top }\n\ntheorem einfsep_lt_top_iff : s.einfsep < ∞ ↔ s.nontrivial :=\n⟨nontrivial_of_einfsep_lt_top, nontrivial.einfsep_lt_top⟩\n\ntheorem einfsep_ne_top_iff : s.einfsep ≠ ∞ ↔ s.nontrivial :=\n⟨nontrivial_of_einfsep_ne_top, nontrivial.einfsep_ne_top⟩\n\nlemma le_einfsep_of_forall_dist_le {d} (h : ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ dist x y) :\n  ennreal.of_real d ≤ s.einfsep :=\nle_einfsep $\nλ x hx y hy hxy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy hxy)\n\nend pseudo_metric_space\n\nsection emetric_space\nvariables [emetric_space α] {x y z : α} {s t : set α} {C : ℝ≥0∞} {sC : set ℝ≥0∞}\n\nlemma einfsep_pos_of_finite [finite s] : 0 < s.einfsep :=\nbegin\n  casesI nonempty_fintype s,\n  by_cases hs : s.nontrivial,\n  { rcases hs.einfsep_exists_of_finite with ⟨x, hx, y, hy, hxy, hxy'⟩,\n    exact hxy'.symm ▸ edist_pos.2 hxy },\n  { rw not_nontrivial_iff at hs,\n    exact hs.einfsep.symm ▸ with_top.zero_lt_top }\nend\n\nlemma relatively_discrete_of_finite [finite s] :\n  ∃ C (hC : 0 < C), ∀ (x y ∈ s) (hxy : x ≠ y), C ≤ edist x y :=\nby { rw ← einfsep_pos, exact einfsep_pos_of_finite }\n\nlemma finite.einfsep_pos (hs : s.finite) : 0 < s.einfsep :=\nby { letI := hs.fintype, exact einfsep_pos_of_finite }\n\nlemma finite.relatively_discrete (hs : s.finite) :\n  ∃ C (hC : 0 < C), ∀ (x y ∈ s) (hxy : x ≠ y), C ≤ edist x y :=\nby { letI := hs.fintype, exact relatively_discrete_of_finite }\n\nend emetric_space\n\nend einfsep\n\nsection infsep\nopen_locale ennreal\nopen set function\n\n/-- The \"infimum separation\" of a set with an edist function. -/\nnoncomputable def infsep [has_edist α] (s : set α) : ℝ := ennreal.to_real (s.einfsep)\n\nsection has_edist\nvariables [has_edist α] {x y : α} {s : set α}\n\nlemma infsep_zero : s.infsep = 0 ↔ s.einfsep = 0 ∨ s.einfsep = ∞ :=\nby rw [infsep, ennreal.to_real_eq_zero_iff]\n\nlemma infsep_nonneg : 0 ≤ s.infsep := ennreal.to_real_nonneg\n\nlemma infsep_pos : 0 < s.infsep ↔ 0 < s.einfsep ∧ s.einfsep < ∞ :=\nby simp_rw [infsep, ennreal.to_real_pos_iff]\n\nlemma subsingleton.infsep_zero (hs : s.subsingleton) : s.infsep = 0 :=\nby { rw [infsep_zero, hs.einfsep], right, refl }\n\nlemma nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.nontrivial :=\nby { contrapose hs, rw not_nontrivial_iff at hs, exact hs.infsep_zero ▸ lt_irrefl _ }\n\nlemma infsep_empty : (∅ : set α).infsep = 0 :=\nsubsingleton_empty.infsep_zero\n\nlemma infsep_singleton : ({x} : set α).infsep = 0 :=\nsubsingleton_singleton.infsep_zero\n\nlemma infsep_pair_le_to_real_inf (hxy : x ≠ y) :\n  ({x, y} : set α).infsep ≤ (edist x y ⊓ edist y x).to_real :=\nby simp_rw [infsep, einfsep_pair_eq_inf hxy]\n\nend has_edist\n\nsection pseudo_emetric_space\nvariables [pseudo_emetric_space α] {x y : α} {s : set α}\n\nlemma infsep_pair_eq_to_real : ({x, y} : set α).infsep = (edist x y).to_real :=\nbegin\n  by_cases hxy : x = y,\n  { rw hxy, simp only [infsep_singleton, pair_eq_singleton, edist_self, ennreal.zero_to_real] },\n  { rw [infsep, einfsep_pair hxy] }\nend\n\nend pseudo_emetric_space\n\nsection pseudo_metric_space\n\nvariables [pseudo_metric_space α] {x y z: α} {s t : set α}\n\nlemma nontrivial.le_infsep_iff {d} (hs : s.nontrivial) :\n  d ≤ s.infsep ↔ ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ dist x y :=\nby simp_rw [infsep, ← ennreal.of_real_le_iff_le_to_real (hs.einfsep_ne_top), le_einfsep_iff,\n            edist_dist, ennreal.of_real_le_of_real_iff (dist_nonneg)]\n\nlemma nontrivial.infsep_lt_iff {d} (hs : s.nontrivial) :\n  s.infsep < d ↔ ∃ (x y ∈ s) (hxy : x ≠ y), dist x y < d :=\nby { rw ← not_iff_not, push_neg, exact hs.le_infsep_iff }\n\nlemma nontrivial.le_infsep {d} (hs : s.nontrivial) (h : ∀ (x y ∈ s) (hxy : x ≠ y), d ≤ dist x y) :\n  d ≤ s.infsep := hs.le_infsep_iff.2 h\n\nlemma le_edist_of_le_infsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s)\n  (hxy : x ≠ y) (hd : d ≤ s.infsep) : d ≤ dist x y :=\nbegin\n  by_cases hs : s.nontrivial,\n  { exact hs.le_infsep_iff.1 hd x hx y hy hxy },\n  { rw not_nontrivial_iff at hs,\n    rw hs.infsep_zero at hd,\n    exact le_trans hd dist_nonneg }\nend\n\nlemma infsep_le_dist_of_mem (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : s.infsep ≤ dist x y :=\nle_edist_of_le_infsep hx hy hxy le_rfl\n\nlemma infsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)\n  (hxy' : dist x y ≤ d) : s.infsep ≤ d := le_trans (infsep_le_dist_of_mem hx hy hxy) hxy'\n\nlemma infsep_pair : ({x, y} : set α).infsep = dist x y :=\nby { rw [infsep_pair_eq_to_real, edist_dist], exact ennreal.to_real_of_real (dist_nonneg) }\n\nlemma infsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) :\n  ({x, y, z} : set α).infsep = dist x y ⊓ dist x z ⊓ dist y z :=\nby simp only [infsep, einfsep_triple hxy hyz hxz, ennreal.to_real_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,\n             and_self, not_false_iff]\n\n\nlemma nontrivial.infsep_anti (hs : s.nontrivial) (hst : s ⊆ t) : t.infsep ≤ s.infsep :=\nennreal.to_real_mono hs.einfsep_ne_top (einfsep_anti hst)\n\nlemma infsep_eq_infi [decidable s.nontrivial] :\n  s.infsep = if s.nontrivial then ⨅ d : s.off_diag, (uncurry dist) (d : α × α) else 0 :=\nbegin\n  split_ifs with hs,\n  { have hb : bdd_below (uncurry dist '' s.off_diag),\n    { refine ⟨0, λ d h, _⟩,\n      simp_rw [mem_image, prod.exists, uncurry_apply_pair] at h,\n      rcases h with ⟨_, _, _, rfl⟩,\n      exact dist_nonneg },\n    refine eq_of_forall_le_iff (λ _, _),\n    simp_rw [hs.le_infsep_iff, le_cinfi_set_iff (off_diag_nonempty.mpr hs) hb, imp_forall_iff,\n            mem_off_diag, prod.forall, uncurry_apply_pair, and_imp] },\n  { exact ((not_nontrivial_iff).mp hs).infsep_zero }\nend\n\nlemma nontrivial.infsep_eq_infi (hs : s.nontrivial)\n  : s.infsep = ⨅ d : s.off_diag, (uncurry dist) (d : α × α) :=\nby { classical, rw [infsep_eq_infi, if_pos hs] }\n\nlemma infsep_of_fintype [decidable s.nontrivial] [decidable_eq α] [fintype s] :\n  s.infsep = if hs : s.nontrivial then s.off_diag.to_finset.inf' (by simpa) (uncurry dist) else 0 :=\nbegin\n  split_ifs with hs,\n  { refine eq_of_forall_le_iff (λ _, _),\n    simp_rw [hs.le_infsep_iff, imp_forall_iff, finset.le_inf'_iff, mem_to_finset, mem_off_diag,\n             prod.forall, uncurry_apply_pair, and_imp] },\n  { rw not_nontrivial_iff at hs, exact hs.infsep_zero }\nend\n\nlemma nontrivial.infsep_of_fintype [decidable_eq α] [fintype s] (hs : s.nontrivial) :\n  s.infsep = s.off_diag.to_finset.inf' (by simpa) (uncurry dist) :=\nby { classical, rw [infsep_of_fintype, dif_pos hs] }\n\nlemma finite.infsep [decidable s.nontrivial] (hsf : s.finite) :\n  s.infsep = if hs : s.nontrivial then hsf.off_diag.to_finset.inf' (by simpa) (uncurry dist)\n  else 0 :=\nbegin\n  split_ifs with hs,\n  { refine eq_of_forall_le_iff (λ _, _),\n    simp_rw [hs.le_infsep_iff, imp_forall_iff, finset.le_inf'_iff, finite.mem_to_finset,\n            mem_off_diag, prod.forall, uncurry_apply_pair, and_imp] },\n  { rw not_nontrivial_iff at hs, exact hs.infsep_zero }\nend\n\nlemma finite.infsep_of_nontrivial (hsf : s.finite) (hs : s.nontrivial) :\n  s.infsep = hsf.off_diag.to_finset.inf' (by simpa) (uncurry dist) :=\n  by { classical, simp_rw [hsf.infsep, dif_pos hs] }\n\nlemma _root_.finset.coe_infsep [decidable_eq α] (s : finset α) :\n  (s : set α).infsep = if hs : s.off_diag.nonempty then s.off_diag.inf' hs (uncurry dist)\n                         else 0 :=\nbegin\n  have H : (s : set α).nontrivial ↔ s.off_diag.nonempty,\n  by rwa [← set.off_diag_nonempty, ← finset.coe_off_diag, finset.coe_nonempty],\n  split_ifs with hs,\n  { simp_rw [(H.mpr hs).infsep_of_fintype, ← finset.coe_off_diag, finset.to_finset_coe] },\n  { exact ((not_nontrivial_iff).mp (H.mp.mt hs)).infsep_zero }\nend\n\nlemma _root_.finset.coe_infsep_of_off_diag_nonempty [decidable_eq α] {s : finset α}\n  (hs : s.off_diag.nonempty) : (s : set α).infsep = s.off_diag.inf' hs (uncurry dist) :=\nby rw [finset.coe_infsep, dif_pos hs]\n\nlemma _root_.finset.coe_infsep_of_off_diag_empty [decidable_eq α] {s : finset α}\n  (hs : s.off_diag = ∅) : (s : set α).infsep = 0 :=\nby { rw ← finset.not_nonempty_iff_eq_empty at hs, rw [finset.coe_infsep, dif_neg hs] }\n\nlemma nontrivial.infsep_exists_of_finite [finite s] (hs : s.nontrivial) :\n  ∃ (x y ∈ s) (hxy : x ≠ y), s.infsep = dist x y :=\nbegin\n  classical,\n  casesI nonempty_fintype s,\n  simp_rw hs.infsep_of_fintype,\n  rcases @finset.exists_mem_eq_inf' _ _ _ (s.off_diag.to_finset) (by simpa) (uncurry dist)\n    with ⟨_, hxy, hed⟩,\n  simp_rw mem_to_finset at hxy,\n  exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩\nend\n\nlemma finite.infsep_exists_of_nontrivial (hsf : s.finite) (hs : s.nontrivial) :\n  ∃ (x y ∈ s) (hxy : x ≠ y), s.infsep = dist x y :=\nby { letI := hsf.fintype, exact hs.infsep_exists_of_finite }\n\nend pseudo_metric_space\n\nsection metric_space\nvariables [metric_space α] {s : set α}\n\nlemma infsep_zero_iff_subsingleton_of_finite [finite s] :\n  s.infsep = 0 ↔ s.subsingleton :=\nbegin\n  rw [infsep_zero, einfsep_eq_top_iff, or_iff_right_iff_imp],\n  exact λ H, (einfsep_pos_of_finite.ne' H).elim\nend\n\nlemma infsep_pos_iff_nontrivial_of_finite [finite s] :\n  0 < s.infsep ↔ s.nontrivial :=\nbegin\n  rw [infsep_pos, einfsep_lt_top_iff, and_iff_right_iff_imp],\n  exact λ _, einfsep_pos_of_finite\nend\n\nlemma finite.infsep_zero_iff_subsingleton (hs : s.finite) :\n  s.infsep = 0 ↔ s.subsingleton :=\nby { letI := hs.fintype, exact infsep_zero_iff_subsingleton_of_finite }\n\nlemma finite.infsep_pos_iff_nontrivial (hs : s.finite) :\n  0 < s.infsep ↔ s.nontrivial :=\nby { letI := hs.fintype, exact infsep_pos_iff_nontrivial_of_finite }\n\nlemma _root_.finset.infsep_zero_iff_subsingleton (s : finset α) :\n  (s : set α).infsep = 0 ↔ (s : set α).subsingleton := infsep_zero_iff_subsingleton_of_finite\n\nlemma _root_.finset.infsep_pos_iff_nontrivial (s : finset α) :\n  0 < (s : set α).infsep ↔ (s : set α).nontrivial := infsep_pos_iff_nontrivial_of_finite\n\nend metric_space\n\nend infsep\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/topology/metric_space/infsep.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.85776809953619, "lm_q1q2_score": 0.777129166429427}}
{"text": "/- A natural number is either zero or the successor of a natural number.-/\ninductive mynat : Type\n  | zero   : mynat\n  | mysucc : mynat → mynat\n\nopen mynat\n\nlemma succ_eq (a b : mynat) : (a = b) -> (mysucc a = mysucc b) :=\nbegin\n  intros h, rw h,\nend\n\ndef nat_one : mynat := (mysucc zero)\n\ndef myadd : mynat → mynat → mynat\n| x zero       := x\n| x (mysucc y) := mysucc (myadd x y)\n\nlemma add_zero (n : mynat) : myadd n zero = n :=\nbegin\n  unfold myadd,\nend\nlemma add_succ (n m : mynat) : myadd n (mysucc m) = mysucc (myadd n m) :=\nbegin\n  unfold myadd,\nend\n\nlemma zero_add (n : mynat) : myadd zero n = n :=\nbegin\n  induction n,\n    rw add_zero,\n    rw add_succ, rw n_ih,\nend\n\nlemma succ_add (n m : mynat) : myadd (mysucc n) m = mysucc (myadd n m) :=\nbegin\n  induction m,\n    repeat {rw add_zero},\n    rw add_succ, rw m_ih, refl,\nend\n\nlemma add_assoc (a b c : mynat) : myadd (myadd a b) c = myadd a (myadd b c) :=\nbegin\n  induction c,\n    repeat {rw add_zero},\n    repeat {rw add_succ}, rw c_ih,\nend\n\nlemma add_comm (a b : mynat) : myadd a b = myadd b a :=\nbegin\n  induction a,\n    rw add_zero, rw zero_add,\n    rw add_succ, rw succ_add, rw a_ih,\nend\n\nlemma add_cancel_a (a b c : mynat) : myadd b a = myadd c a -> b = c :=\nbegin\n    intros h,\n    induction a,\n      repeat {rw add_zero at h}, exact h,\n      repeat {rw add_succ at h}, simp at h, exact a_ih h,\nend\n\nlemma add_cancel_a_rev (a b c : mynat) : myadd a b = myadd a c -> b = c :=\nbegin\n  rw add_comm a b, rw add_comm a c, exact add_cancel_a a b c,\nend\n\nlemma add_cancel_b (a b c : mynat) : b = c -> myadd b a = myadd c a :=\nbegin\n    intros h,\n    induction a,\n      repeat {rw add_zero}, exact h,\n      repeat {rw add_succ}, simp, exact a_ih,\nend\n\nlemma add_comm_in_tree (a b c d : mynat) : (myadd (myadd a b) (myadd c d)) = (myadd (myadd a c) (myadd b d)) :=\nbegin\n  rw add_assoc, rw <- add_assoc b c d, rw add_comm b c, rw add_assoc c b d, rw <- add_assoc,\nend\n\nlemma add_combine_eq (a b c d : mynat) : (a = b) -> ((c = d) ->\n                                          (myadd a c = myadd b d)) :=\nbegin\n  intros h1 h2,\n  rw h1, rw h2,\nend\n\ndef mymul : mynat → mynat → mynat\n| x zero       := zero\n| x (mysucc y) := myadd x (mymul x y)\n\nlemma zero_mul (n : mynat) : mymul zero n = zero :=\nbegin\n  induction n,\n    unfold mymul,\n    unfold mymul, rw n_ih, unfold myadd,\nend\n\nlemma mul_zero (n : mynat) : mymul n zero = zero :=\nbegin\n  unfold mymul,\nend\n\nlemma one_mul_eq (n : mynat) : mymul (mysucc zero) n = n :=\nbegin\n  induction n,\n    unfold mymul,\n    unfold mymul, rw succ_add, rw n_ih, rw zero_add,\nend\n\nlemma mul_one_eq (n : mynat) : mymul n (mysucc zero) = n :=\nbegin\n  cases n,\n    rw zero_mul,\n    unfold mymul, rw add_zero,\nend\n\nlemma mul_succ (n m : mynat) : mymul (mysucc n) m = myadd (mymul n m) m :=\nbegin\n  induction m,\n    unfold mymul, unfold myadd,\n    unfold mymul, rw m_ih, repeat {unfold myadd}, rw add_assoc, rw succ_add,\nend\n\nlemma succ_mul (n m : mynat) : mymul n (mysucc m) = myadd (mymul n m) n :=\nbegin\n  unfold mymul, rw add_comm,\nend\n\nlemma mul_comm (n m : mynat) : mymul n m = mymul m n :=\nbegin\n  induction n,\n    rw zero_mul, unfold mymul,\n    rw mul_succ, rw n_ih, unfold mymul, rw add_comm,\nend\n\nlemma mul_add (t a b : mynat) : (mymul t (myadd a b)) =\n                      (myadd (mymul t a) (mymul t b)) :=\nbegin\n  induction b,\n    unfold mymul, unfold myadd,\n    repeat {rw add_succ}, repeat {unfold mymul}, rw b_ih,\n      rw add_comm (mymul t a), rw <- add_assoc, rw add_comm,\nend\n\nlemma mul_assoc (a b c : mynat) : mymul (mymul a b) c = mymul a (mymul b c) :=\nbegin\n  induction c,\n    unfold mymul,\n    repeat {rw succ_mul}, rw mul_add, rw c_ih,\nend\n\nlemma mul_add_distrib (a b c : mynat) : mymul (myadd a b) c =\n                                  myadd (mymul a c) (mymul b c) :=\nbegin\n  induction c with c1,\n    unfold mymul, unfold myadd,\n    unfold mymul, rw c_ih,\n    rw add_comm a b, rw add_assoc, rw add_comm, rw add_comm b (mymul b c1),\n    repeat {rw add_assoc},\nend\n\nlemma mul_add_distrib_alt (a b c : mynat) : mymul a (myadd b c) = myadd (mymul a b) (mymul a c) :=\nbegin\n  rw mul_comm, rw mul_add_distrib, rw mul_comm b a, rw mul_comm c a,\nend\n\nlemma mul_add_distrib_rev (a b c : mynat) : myadd (mymul a b) (mymul a c) = mymul (myadd b c) a :=\nbegin\n  rw mul_comm, rw mul_comm a c, rw <- mul_add_distrib,\nend\n\nlemma mul_two (a : mynat) : mymul zero.mysucc.mysucc a = myadd a a :=\nbegin\n  rw mul_comm, unfold mymul, rw add_zero,\nend\n\nlemma mul_result_zero (a b c : mynat) : (a = mysucc(c)) -> ((mymul a b = zero) -> (b = zero)) :=\nbegin\n  intros h1 h2, rw h1 at h2, cases b,\n    refl,\n    unfold mymul at h2, rw add_comm at h2, unfold myadd at h2, contradiction,\nend\n\nlemma mul_cancel (a b c : mynat) : (mymul a (mysucc c) = mymul b (mysucc c)) -> (a = b) :=\nbegin\n  rw mul_comm, rw mul_comm b c.mysucc, revert b,\n  induction a with a1, intro b, cases b,\n      intros, refl,\n      intros h, repeat {unfold mymul at h}, rw add_comm at h, unfold myadd at h, contradiction,\n    intro b, cases b,\n      intros h, repeat {unfold mymul at h}, rw add_comm at h, unfold myadd at h, contradiction,\n      intros h1, unfold mymul at h1,\n      have h2 : (mymul c.mysucc a1) = (mymul c.mysucc b),\n        exact add_cancel_a_rev c.mysucc (mymul c.mysucc a1) (mymul c.mysucc b) h1,\n      apply succ_eq a1 b,\n      exact a_ih b h2,\nend\n\nlemma mul_zero_collapse (a b c : mynat) : ¬(a = b) -> ((mymul a c = mymul b c) -> c = zero) :=\nbegin\n  intros h1 h2, cases c,\n    refl,\n    have absurd : a = b,\n      exact mul_cancel a b c h2,\n    exfalso, exact h1 absurd,\nend\n\nlemma add_self_eq_mul_two (a : mynat) : (myadd a a) = (mymul (zero.mysucc.mysucc) a) :=\nbegin\n  induction a with a1,\n    unfold myadd, unfold mymul,\n    unfold mymul, unfold myadd,  rw add_comm, unfold myadd,\n      rw add_comm zero.mysucc.mysucc (mymul zero.mysucc.mysucc a1), repeat {unfold myadd}, rw a_ih,\nend\n\nlemma add_self (a b : mynat) : (myadd a a = myadd b b) -> (a = b) :=\nbegin\n  repeat {rw add_self_eq_mul_two}, intros h,\n  rw mul_comm zero.mysucc.mysucc a at h, rw mul_comm zero.mysucc.mysucc b at h,\n  exact mul_cancel a b zero.mysucc h,\nend\n\nlemma add_self_inv (a b : mynat) : ¬(a = b) -> ¬(myadd a a = myadd b b) :=\nbegin\n  intros h, intros h2, exact h (add_self a b h2),\nend\n\nlemma mul_weird_sub_a (a b c d : mynat) : (∃e : mynat, d = (myadd c (mysucc e))) ->\n        (myadd (mymul a c) (mymul b d)) = (myadd (mymul b c) (mymul a d)) ->\n        (a = b) :=\nbegin\n  intros h1 h2, cases h1 with e h1, rw h1 at h2,\n  rw mul_add_distrib_alt b c e.mysucc at h2, rw mul_add_distrib_alt a c e.mysucc at h2,\n  rw <- add_assoc (mymul a c) (mymul b c) (mymul b e.mysucc) at h2, rw <- add_assoc (mymul b c) (mymul a c) (mymul a e.mysucc) at h2,\n  rw add_comm (mymul a c) (mymul b c) at h2,\n  have tmp : (mymul b e.mysucc) = (mymul a e.mysucc),\n    exact add_cancel_a_rev (myadd (mymul b c) (mymul a c)) (mymul b e.mysucc) (mymul a e.mysucc) h2,\n  symmetry, exact mul_cancel b a e tmp,\nend\n\nlemma difference_exists (a b : mynat) : (∃c : mynat, (myadd a c) = b) \\/ (∃c : mynat, a = (myadd b c)) :=\nbegin\n  induction a,\n    left, existsi b, rw zero_add,\n    cases a_ih with h h,\n      cases h with c hc, cases c,\n        rw add_zero at hc, rw hc, right, existsi (zero.mysucc), unfold myadd,\n        left, existsi c, unfold myadd at hc, rw succ_add, exact hc,\n      cases h with c hc, cases c,\n        rw add_zero at hc, rw hc, right, existsi (zero.mysucc), unfold myadd,\n        right, existsi c.mysucc.mysucc, rw hc, unfold myadd,\nend\n\nlemma ne_implies_nonzero_diff (a b : mynat) : (a ≠ b) ->\n              ((∃c : mynat, b = (myadd a c.mysucc)) \\/ (∃c : mynat, a = (myadd b c.mysucc))) :=\nbegin\n  intro h,\n  have diff_h : (∃d : mynat, (myadd a d) = b) \\/ (∃d : mynat, a = (myadd b d)),\n    exact difference_exists a b,\n  cases diff_h,\n    left, cases diff_h with d hd, cases d,\n      rw add_zero at hd, exfalso, exact h hd,\n      existsi d, symmetry, exact hd,\n    right, cases diff_h with d hd, cases d,\n      rw add_zero at hd, exfalso, exact h hd,\n      existsi d, exact hd,\nend\n\n/- This is a weird formula but we need it later, OK...-/\nlemma mul_weird_sub (a b c d : mynat) : (c ≠ d) ->\n        (myadd (mymul a c) (mymul b d)) = (myadd (mymul b c) (mymul a d)) ->\n        (a = b) :=\nbegin\n  intros h1 h2, cases (ne_implies_nonzero_diff c d h1) with h3 h3,\n    exact mul_weird_sub_a a b c d h3 h2,\n    symmetry, rw add_comm (mymul a c) (mymul b d) at h2, rw add_comm (mymul b c) (mymul a d) at h2,\n      exact mul_weird_sub_a b a d c h3 h2,\nend\n\n/- We represent integers as a pair of natural numbers, where (a, b) represents (a - b).-/\ninductive myint : Type\n| int  : mynat -> mynat -> myint\n\nopen myint\n\ndef int_zero : myint := (int zero zero)\ndef int_one : myint := (int nat_one zero)\n\ndef iszero : myint -> Prop\n| (int a b) := (a = b)\n\n/- Because of the implementation, we need a new version of equals.-/\n/- e.g. (0, 0) = (1, 1) as both represent zero, even though they are representationally different.-/\ndef int_equal : myint -> myint -> Prop\n| (int a b) (int c d) := ((myadd a d) = (myadd b c))\n\nlemma int_zeros_eq (a b : myint) : (iszero a) -> (iszero b) -> (int_equal a b) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus,\n  unfold iszero, unfold int_equal, intros h1 h2, rw h1, rw h2,\nend\n\nlemma int_zeros_only_eq (a b : myint) : (iszero a) -> ((int_equal a b) -> (iszero b)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus,\n  unfold iszero, unfold int_equal, intros h1 h2,\n  rw h1 at h2,\n  rw add_comm aminus bminus at h2, rw add_comm aminus bplus at h2,\n  apply add_cancel_a aminus bplus bminus, symmetry, exact h2,\nend\n\nlemma int_zeros_only_eq_rev (a b : myint) : (iszero a) -> ((int_equal b a) -> (iszero b)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus,\n  unfold iszero, unfold int_equal, intros h1 h2,\n  rw h1 at h2,\n  apply add_cancel_a aminus bplus bminus, exact h2,\nend\n\nlemma int_equal_refl (a : myint) : (int_equal a a) :=\nbegin\n  cases a with aplus aminus, unfold int_equal,\n  rw add_comm,\nend\n\nlemma int_eq_comm (a b : myint) : (int_equal a b) -> (int_equal b a) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus,\n  unfold int_equal,\n    intros h, rw add_comm bplus aminus, rw add_comm bminus aplus, symmetry, exact h,\nend\n\nlemma int_eq_comm_double (a b : myint) : (int_equal a b) <-> (int_equal b a) :=\nbegin\n  split,\n    exact int_eq_comm a b,\n    exact int_eq_comm b a,\nend\n\nlemma int_eq_trans (a b c : myint) : (int_equal a b) -> (int_equal b c) ->\n                                          (int_equal a c) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_equal,\n  intros h1 h2,\n  have h3 : (myadd (myadd aplus bminus) (myadd bplus cminus) = myadd (myadd aminus bplus) (myadd bminus cplus)),\n    exact add_combine_eq (myadd aplus bminus) (myadd aminus bplus) (myadd bplus cminus) (myadd bminus cplus) h1 h2,\n    apply add_cancel_a (myadd bplus bminus) (myadd aplus cminus) (myadd aminus cplus),\n    rw add_comm bplus bminus, rw add_comm_in_tree, rw add_comm cminus bplus,\n    symmetry,\n    rw add_comm bminus bplus, rw add_comm_in_tree, symmetry, rw add_comm cplus bminus,\n    exact h3,\nend\n\ndef int_add : myint -> myint -> myint\n| (int a b) (int c d) := (int (myadd a c) (myadd b d))\n\nlemma add_zero_int (a b : myint) : (iszero a) ->\n        (int_equal b (int_add a b)) :=\nbegin\n  intros h, cases a with aplus aminus, unfold iszero at h,\n  cases b with bplus bminus, unfold int_add, unfold int_equal,\n  rw h, rw <- add_assoc, rw add_comm,\n  have h : myadd bplus aminus = myadd aminus bplus,\n    rw add_comm,\n  rw h,\nend\n\nlemma add_zero_int_alt (a b : myint) : (iszero a) -> (int_equal (int_add a b) b) :=\nbegin\n  intros h, have int : int_equal b (int_add a b), exact add_zero_int a b h, exact int_eq_comm b (int_add a b) int,\nend\n\nlemma add_comm_int (a b : myint) : int_equal (int_add a b) (int_add b a) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus,\n  unfold int_add, unfold int_equal,\n  rw add_comm (myadd aplus bplus) (myadd bminus aminus),\n  rw add_comm aminus bminus,\n  rw add_comm aplus bplus,\nend\n\nlemma add_comm_int_rw (a b : myint) : (int_add a b) = (int_add b a) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold int_add,\n  rw add_comm bplus aplus, rw add_comm bminus aminus,\nend\n\nlemma add_eq (a b c : myint) : int_equal b c <->\n                                int_equal (int_add a b) (int_add a c) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  split,\n    intros h,\n    unfold int_equal at h,\n    unfold int_add, unfold int_equal,\n    rw add_assoc, rw add_comm aminus cminus, rw <- add_assoc bplus cminus aminus,\n    rw h,\n    rw add_assoc, rw add_comm cplus aminus, rw <- add_assoc, rw <- add_assoc,\n    rw add_comm aplus bminus,  rw add_comm (myadd bminus aplus) aminus,\n    repeat {rw add_assoc},\n\n    intros h,\n    unfold int_equal, unfold int_add at h, unfold int_equal at h,\n    rw add_assoc at h, rw add_comm at h, rw add_comm aminus cminus at h,\n    rw add_comm aplus cplus at h, rw add_comm aminus bminus at h,\n    rw add_assoc bminus aminus (myadd cplus aplus) at h,\n    rw <- add_assoc aminus cplus aplus at h,\n    rw add_comm aminus cplus at h, rw add_assoc cplus aminus aplus at h,\n    rw <- add_assoc bminus cplus (myadd aminus aplus) at h,\n    rw add_assoc at h, rw add_assoc cminus aminus aplus at h,\n    rw <- add_assoc bplus cminus (myadd aminus aplus) at h,\n    exact add_cancel_a (myadd aminus aplus) (myadd bplus cminus) (myadd bminus cplus) h,\nend\n\nlemma add_assoc_int (a b c : myint) : int_equal (int_add (int_add a b) c)\n                                                (int_add a (int_add b c)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_add, unfold int_equal,\n  rw add_comm,\n  repeat {rw add_assoc},\nend\n\nlemma add_assoc_int_rw (a b c : myint) : (int_add (int_add a b) c) = (int_add a (int_add b c)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_add, repeat {rw add_assoc},\nend\n\nlemma add_sub_int (a b c d : myint) : (int_equal a b) -> (int_equal (int_add a c) d) ->\n                                                         (int_equal (int_add b c) d) :=\nbegin\n  intros h1 h2,\n  have h3 : int_equal a b <-> int_equal (int_add c a) (int_add c b),\n    exact add_eq c a b,\n  cases h3 with h3 _,\n  have h4 : int_equal (int_add c a) (int_add c b), exact h3 h1,\n  rw add_comm_int_rw c a at h4, rw add_comm_int_rw c b at h4,\n  have h5 : int_equal d (int_add a c), exact int_eq_comm (int_add a c) d h2,\n  apply int_eq_comm d (int_add b c),\n  exact int_eq_trans d (int_add a c) (int_add b c) h5 h4,\nend\n\nlemma int_add_self_nonzero (a : myint) : ¬(iszero a) -> ¬(iszero (int_add a a)) :=\nbegin\n  cases a with aplus aminus, unfold int_add, unfold iszero, intros h,\n  exact add_self_inv aplus aminus h,\nend\n\n/- (a - b)(c - d) = (ac + bd) - (ad + bc)-/\ndef int_mul : myint -> myint -> myint\n| (int a b) (int c d) := (int (myadd (mymul a c) (mymul b d))\n                              (myadd (mymul a d) (mymul b c)))\n\nlemma mul_comm_int (a b : myint) : int_equal (int_mul a b) (int_mul b a) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus,\n  unfold int_mul, unfold int_equal,\n  rw add_comm,\n  rw add_comm (mymul bplus aminus) (mymul bminus aplus),\n  rw mul_comm bminus aplus, rw mul_comm bplus aminus,\n  rw mul_comm aplus bplus, rw mul_comm aminus bminus,\nend\n\nlemma mul_comm_int_rw (a b : myint) : (int_mul a b) = (int_mul b a) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold int_mul,\n  rw mul_comm bplus aplus, rw mul_comm bminus aminus,\n  rw add_comm (mymul bplus aminus) (mymul bminus aplus),\n  rw mul_comm bminus aplus, rw mul_comm bplus aminus,\nend\n\n/- Trivial consequence of previous results but makes some of the rewriting easier.-/\nlemma add_helper_1 (a b c : mynat) : myadd (myadd a b) c = myadd (myadd a c) b :=\nbegin\n  rw add_assoc, rw add_comm b c, rw <- add_assoc,\nend\n\n/- ditto -/\nlemma add_helper_2 (a b c d : mynat) : myadd a (myadd (myadd b c) d) = myadd b (myadd (myadd a c) d) :=\nbegin\n  repeat {rw <- add_assoc}, rw add_comm a b,\nend\n\n/- unlike for addition this implication only goes one way.\n    (a * b) = (a * c) -> b = c\n    is WRONG if a = 0.  -/\nlemma mul_eq (a b c : myint) : int_equal b c ->\n                            int_equal (int_mul a b) (int_mul a c) :=\nbegin\n  intros h,\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_equal at h, unfold int_mul, unfold int_equal,\n  rw add_comm (mymul aplus bplus) (mymul aminus bminus),\n  repeat {rw add_assoc},\n  rw <- add_assoc (mymul aplus bplus) (mymul aplus cminus) (mymul aminus cplus),\n  rw mul_comm aplus bplus, rw mul_comm aplus cminus,\n  rw <- mul_add_distrib,\n  rw h, rw mul_add_distrib,\n  rw add_comm (mymul aplus cplus) (mymul aminus cminus),\n  rw <- add_assoc (mymul aminus bplus) (mymul aminus cminus) (mymul aplus cplus),\n  rw mul_comm aminus bplus, rw mul_comm aminus cminus,\n  rw <- mul_add_distrib bplus cminus aminus,\n  rw h, rw mul_add_distrib,\n  rw add_helper_1 (mymul bminus aminus) (mymul cplus aminus) (mymul aplus cplus),\n  rw add_helper_2,\n  rw mul_comm bminus aplus, rw mul_comm aminus bminus, rw mul_comm cplus aplus, rw mul_comm aminus cplus,\nend\n\nlemma mul_eq_alt (a b c : myint) : int_equal b c ->\n                                  int_equal (int_mul b a) (int_mul c a) :=\nbegin\n  intros h,\n  have int1 : int_equal (int_mul a b) (int_mul a c),\n    exact mul_eq a b c h,\n  have int2 : int_equal (int_mul a b) (int_mul b a),\n    exact mul_comm_int a b,\n  have int3 : int_equal (int_mul b a) (int_mul a c),\n    exact int_eq_trans (int_mul b a) (int_mul a b) (int_mul a c) (int_eq_comm (int_mul a b) (int_mul b a) int2) int1,\n  exact int_eq_trans (int_mul b a) (int_mul a c) (int_mul c a) int3 (mul_comm_int a c),\nend\n\nattribute [simp]\nlemma mul_assoc_int (a b c : myint) : int_equal (int_mul (int_mul a b) c)\n                                                (int_mul a (int_mul b c)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_mul, unfold int_equal,\n  repeat {rw mul_add_distrib}, repeat {rw mul_add_distrib_alt},\n  /- The below code was generated with an external python script.-/\n  /- It is almost certainly not the most efficient way to do this, but it works...-/\n  rw add_comm (mymul aminus (mymul bplus cplus)) (mymul aminus (mymul bminus cminus)), rw <- add_assoc (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus))) (mymul aminus (mymul bminus cminus)) (mymul aminus (mymul bplus cplus)), rw add_comm (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus))) (mymul aminus (mymul bminus cminus)), rw <- add_assoc (myadd (myadd (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bminus) cplus)) (myadd (mymul (mymul aplus bminus) cminus) (mymul (mymul aminus bplus) cminus))) (myadd (mymul aminus (mymul bminus cminus)) (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus)))) (mymul aminus (mymul bplus cplus)), rw <- add_assoc (myadd (myadd (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bminus) cplus)) (myadd (mymul (mymul aplus bminus) cminus) (mymul (mymul aminus bplus) cminus))) (mymul aminus (mymul bminus cminus)) (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus))), rw add_comm (myadd (myadd (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bminus) cplus)) (myadd (mymul (mymul aplus bminus) cminus) (mymul (mymul aminus bplus) cminus))) (mymul aminus (mymul bminus cminus)), rw add_comm (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bminus) cplus), rw <- add_assoc (mymul aminus (mymul bminus cminus)) (myadd (mymul (mymul aminus bminus) cplus) (mymul (mymul aplus bplus) cplus)) (myadd (mymul (mymul aplus bminus) cminus) (mymul (mymul aminus bplus) cminus)), rw <- add_assoc (mymul aminus (mymul bminus cminus)) (mymul (mymul aminus bminus) cplus) (mymul (mymul aplus bplus) cplus), rw add_comm (mymul aminus (mymul bminus cminus)) (mymul (mymul aminus bminus) cplus), rw add_comm (mymul (mymul aplus bminus) cminus) (mymul (mymul aminus bplus) cminus), rw <- add_assoc (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus)) (mymul (mymul aminus bplus) cminus) (mymul (mymul aplus bminus) cminus), rw add_comm (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus)) (mymul (mymul aminus bplus) cminus), rw add_comm (myadd (myadd (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus))) (mymul (mymul aplus bminus) cminus)) (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus)))) (mymul aminus (mymul bplus cplus)), rw add_comm (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus))) (mymul (mymul aplus bminus) cminus), rw <- add_assoc (mymul aminus (mymul bplus cplus)) (myadd (mymul (mymul aplus bminus) cminus) (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus)))) (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus))), rw <- add_assoc (mymul aminus (mymul bplus cplus)) (mymul (mymul aplus bminus) cminus) (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus))), rw add_comm (mymul aminus (mymul bplus cplus)) (mymul (mymul aplus bminus) cminus), rw add_comm (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus)), rw <- add_assoc (myadd (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))) (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus)))) (mymul aplus (mymul bminus cplus)) (mymul aplus (mymul bplus cminus)), rw add_comm (myadd (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))) (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus)))) (mymul aplus (mymul bminus cplus)), rw add_comm (myadd (mymul aplus (mymul bminus cplus)) (myadd (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))) (myadd (mymul (mymul aminus bplus) cminus) (myadd (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus))))) (mymul aplus (mymul bplus cminus)), rw add_comm (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))) (mymul (mymul aplus bplus) cplus), rw <- add_assoc (mymul (mymul aminus bplus) cminus) (mymul (mymul aplus bplus) cplus) (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))), rw add_comm (mymul (mymul aminus bplus) cminus) (mymul (mymul aplus bplus) cplus), rw <- add_assoc (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))) (myadd (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bplus) cminus)) (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))), rw <- add_assoc (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))) (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bplus) cminus), rw add_comm (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))) (mymul (mymul aplus bplus) cplus), rw <- add_assoc (mymul aplus (mymul bminus cplus)) (myadd (myadd (mymul (mymul aplus bplus) cplus) (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus)))) (mymul (mymul aminus bplus) cminus)) (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))), rw <- add_assoc (mymul aplus (mymul bminus cplus)) (myadd (mymul (mymul aplus bplus) cplus) (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus)))) (mymul (mymul aminus bplus) cminus), rw <- add_assoc (mymul aplus (mymul bminus cplus)) (mymul (mymul aplus bplus) cplus) (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))), rw add_comm (mymul aplus (mymul bminus cplus)) (mymul (mymul aplus bplus) cplus), rw <- add_assoc (mymul aplus (mymul bplus cminus)) (myadd (myadd (myadd (mymul (mymul aplus bplus) cplus) (mymul aplus (mymul bminus cplus))) (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus)))) (mymul (mymul aminus bplus) cminus)) (myadd (mymul (mymul aminus bminus) cplus) (mymul aminus (mymul bminus cminus))), rw <- add_assoc (mymul aplus (mymul bplus cminus)) (myadd (myadd (mymul (mymul aplus bplus) cplus) (mymul aplus (mymul bminus cplus))) (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus)))) (mymul (mymul aminus bplus) cminus), rw <- add_assoc (mymul aplus (mymul bplus cminus)) (myadd (mymul (mymul aplus bplus) cplus) (mymul aplus (mymul bminus cplus))) (myadd (mymul (mymul aplus bminus) cminus) (mymul aminus (mymul bplus cplus))), rw <- add_assoc (mymul aplus (mymul bplus cminus)) (mymul (mymul aplus bplus) cplus) (mymul aplus (mymul bminus cplus)), rw add_comm (mymul aplus (mymul bplus cminus)) (mymul (mymul aplus bplus) cplus),\n  symmetry,\n  rw add_comm (mymul (mymul aplus bplus) cminus) (mymul (mymul aminus bminus) cminus), rw add_comm (mymul aminus (mymul bplus cminus)) (mymul aminus (mymul bminus cplus)), rw <- add_assoc (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus))) (mymul aminus (mymul bminus cplus)) (mymul aminus (mymul bplus cminus)), rw add_comm (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus))) (mymul aminus (mymul bminus cplus)), rw <- add_assoc (myadd (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (myadd (mymul (mymul aplus bminus) cplus) (mymul (mymul aminus bplus) cplus))) (myadd (mymul aminus (mymul bminus cplus)) (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus)))) (mymul aminus (mymul bplus cminus)), rw <- add_assoc (myadd (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (myadd (mymul (mymul aplus bminus) cplus) (mymul (mymul aminus bplus) cplus))) (mymul aminus (mymul bminus cplus)) (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus))), rw add_comm (myadd (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (myadd (mymul (mymul aplus bminus) cplus) (mymul (mymul aminus bplus) cplus))) (mymul aminus (mymul bminus cplus)), rw add_comm (myadd (myadd (mymul aminus (mymul bminus cplus)) (myadd (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (myadd (mymul (mymul aplus bminus) cplus) (mymul (mymul aminus bplus) cplus)))) (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus)))) (mymul aminus (mymul bplus cminus)), rw add_comm (mymul (mymul aplus bminus) cplus) (mymul (mymul aminus bplus) cplus), rw <- add_assoc (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (mymul (mymul aminus bplus) cplus) (mymul (mymul aplus bminus) cplus), rw add_comm (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (mymul (mymul aminus bplus) cplus), rw <- add_assoc (mymul aminus (mymul bminus cplus)) (myadd (mymul (mymul aminus bplus) cplus) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus), rw <- add_assoc (mymul aminus (mymul bminus cplus)) (mymul (mymul aminus bplus) cplus) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)), rw add_comm (mymul aminus (mymul bminus cplus)) (mymul (mymul aminus bplus) cplus), rw <- add_assoc (mymul aminus (mymul bplus cminus)) (myadd (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus)) (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus))), rw <- add_assoc (mymul aminus (mymul bplus cminus)) (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus), rw <- add_assoc (mymul aminus (mymul bplus cminus)) (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)), rw <- add_assoc (mymul aminus (mymul bplus cminus)) (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bminus cplus)), rw add_comm (mymul aminus (mymul bplus cminus)) (mymul (mymul aminus bplus) cplus), rw add_comm (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus)), rw <- add_assoc (myadd (myadd (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus)) (mymul aplus (mymul bminus cminus)) (mymul aplus (mymul bplus cplus)), rw add_comm (myadd (myadd (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus)) (mymul aplus (mymul bminus cminus)), rw add_comm (myadd (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus), rw <- add_assoc (mymul aplus (mymul bminus cminus)) (mymul (mymul aplus bminus) cplus) (myadd (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))), rw add_comm (mymul aplus (mymul bminus cminus)) (mymul (mymul aplus bminus) cplus), rw add_comm (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus), rw <- add_assoc (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (mymul (mymul aplus bplus) cminus) (mymul (mymul aminus bminus) cminus), rw add_comm (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (mymul (mymul aplus bplus) cminus), rw <- add_assoc (myadd (mymul (mymul aplus bminus) cplus) (mymul aplus (mymul bminus cminus))) (myadd (mymul (mymul aplus bplus) cminus) (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus)))) (mymul (mymul aminus bminus) cminus), rw <- add_assoc (myadd (mymul (mymul aplus bminus) cplus) (mymul aplus (mymul bminus cminus))) (mymul (mymul aplus bplus) cminus) (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))), rw add_comm (myadd (mymul (mymul aplus bminus) cplus) (mymul aplus (mymul bminus cminus))) (mymul (mymul aplus bplus) cminus), rw add_comm (myadd (myadd (myadd (mymul (mymul aplus bplus) cminus) (myadd (mymul (mymul aplus bminus) cplus) (mymul aplus (mymul bminus cminus)))) (myadd (myadd (mymul (mymul aminus bplus) cplus) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus)))) (mymul (mymul aminus bminus) cminus)) (mymul aplus (mymul bplus cplus)),\n  repeat {rw add_assoc},\n  repeat {rw mul_assoc},\nend\n\nlemma mul_assoc_int_rw (a b c : myint) : (int_mul (int_mul a b) c) = (int_mul a (int_mul b c)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_mul, repeat {rw mul_add_distrib},\n  /- Also python. -/\n  rw add_comm (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bminus) cplus), rw add_comm (mymul (mymul aplus bminus) cminus) (mymul (mymul aminus bplus) cminus), rw <- add_assoc (myadd (mymul (mymul aminus bminus) cplus) (mymul (mymul aplus bplus) cplus)) (mymul (mymul aminus bplus) cminus) (mymul (mymul aplus bminus) cminus), rw add_comm (myadd (mymul (mymul aminus bminus) cplus) (mymul (mymul aplus bplus) cplus)) (mymul (mymul aminus bplus) cminus), rw add_comm (myadd (mymul (mymul aminus bplus) cminus) (myadd (mymul (mymul aminus bminus) cplus) (mymul (mymul aplus bplus) cplus))) (mymul (mymul aplus bminus) cminus), rw add_comm (mymul (mymul aminus bminus) cplus) (mymul (mymul aplus bplus) cplus), rw <- add_assoc (mymul (mymul aminus bplus) cminus) (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bminus) cplus), rw add_comm (mymul (mymul aminus bplus) cminus) (mymul (mymul aplus bplus) cplus), rw <- add_assoc (mymul (mymul aplus bminus) cminus) (myadd (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bplus) cminus)) (mymul (mymul aminus bminus) cplus), rw <- add_assoc (mymul (mymul aplus bminus) cminus) (mymul (mymul aplus bplus) cplus) (mymul (mymul aminus bplus) cminus), rw add_comm (mymul (mymul aplus bminus) cminus) (mymul (mymul aplus bplus) cplus),\n  rw add_comm (mymul (mymul aplus bplus) cminus) (mymul (mymul aminus bminus) cminus), rw add_comm (mymul (mymul aplus bminus) cplus) (mymul (mymul aminus bplus) cplus), rw <- add_assoc (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (mymul (mymul aminus bplus) cplus) (mymul (mymul aplus bminus) cplus), rw add_comm (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus)) (mymul (mymul aminus bplus) cplus), rw add_comm (myadd (mymul (mymul aminus bplus) cplus) (myadd (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus))) (mymul (mymul aplus bminus) cplus), rw add_comm (mymul (mymul aminus bminus) cminus) (mymul (mymul aplus bplus) cminus), rw <- add_assoc (mymul (mymul aminus bplus) cplus) (mymul (mymul aplus bplus) cminus) (mymul (mymul aminus bminus) cminus), rw add_comm (mymul (mymul aminus bplus) cplus) (mymul (mymul aplus bplus) cminus), rw <- add_assoc (mymul (mymul aplus bminus) cplus) (myadd (mymul (mymul aplus bplus) cminus) (mymul (mymul aminus bplus) cplus)) (mymul (mymul aminus bminus) cminus), rw <- add_assoc (mymul (mymul aplus bminus) cplus) (mymul (mymul aplus bplus) cminus) (mymul (mymul aminus bplus) cplus), rw add_comm (mymul (mymul aplus bminus) cplus) (mymul (mymul aplus bplus) cminus),\n  symmetry, repeat {rw mul_add_distrib_alt},\n  rw add_comm (mymul aminus (mymul bplus cminus)) (mymul aminus (mymul bminus cplus)), rw <- add_assoc (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus))) (mymul aminus (mymul bminus cplus)) (mymul aminus (mymul bplus cminus)), rw add_comm (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus))) (mymul aminus (mymul bminus cplus)), rw add_comm (myadd (mymul aminus (mymul bminus cplus)) (myadd (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus)))) (mymul aminus (mymul bplus cminus)), rw add_comm (mymul aplus (mymul bplus cplus)) (mymul aplus (mymul bminus cminus)), rw <- add_assoc (mymul aminus (mymul bminus cplus)) (mymul aplus (mymul bminus cminus)) (mymul aplus (mymul bplus cplus)), rw add_comm (mymul aminus (mymul bminus cplus)) (mymul aplus (mymul bminus cminus)), rw <- add_assoc (mymul aminus (mymul bplus cminus)) (myadd (mymul aplus (mymul bminus cminus)) (mymul aminus (mymul bminus cplus))) (mymul aplus (mymul bplus cplus)), rw <- add_assoc (mymul aminus (mymul bplus cminus)) (mymul aplus (mymul bminus cminus)) (mymul aminus (mymul bminus cplus)), rw add_comm (mymul aminus (mymul bplus cminus)) (mymul aplus (mymul bminus cminus)), rw add_comm (myadd (myadd (mymul aplus (mymul bminus cminus)) (mymul aminus (mymul bplus cminus))) (mymul aminus (mymul bminus cplus))) (mymul aplus (mymul bplus cplus)),\n  rw add_comm (mymul aminus (mymul bplus cplus)) (mymul aminus (mymul bminus cminus)), rw <- add_assoc (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus))) (mymul aminus (mymul bminus cminus)) (mymul aminus (mymul bplus cplus)), rw add_comm (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus))) (mymul aminus (mymul bminus cminus)), rw add_comm (myadd (mymul aminus (mymul bminus cminus)) (myadd (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus)))) (mymul aminus (mymul bplus cplus)), rw add_comm (mymul aplus (mymul bplus cminus)) (mymul aplus (mymul bminus cplus)), rw <- add_assoc (mymul aminus (mymul bminus cminus)) (mymul aplus (mymul bminus cplus)) (mymul aplus (mymul bplus cminus)), rw add_comm (mymul aminus (mymul bminus cminus)) (mymul aplus (mymul bminus cplus)), rw <- add_assoc (mymul aminus (mymul bplus cplus)) (myadd (mymul aplus (mymul bminus cplus)) (mymul aminus (mymul bminus cminus))) (mymul aplus (mymul bplus cminus)), rw <- add_assoc (mymul aminus (mymul bplus cplus)) (mymul aplus (mymul bminus cplus)) (mymul aminus (mymul bminus cminus)), rw add_comm (mymul aminus (mymul bplus cplus)) (mymul aplus (mymul bminus cplus)), rw add_comm (myadd (myadd (mymul aplus (mymul bminus cplus)) (mymul aminus (mymul bplus cplus))) (mymul aminus (mymul bminus cminus))) (mymul aplus (mymul bplus cminus)),\n  repeat {rw mul_assoc}, repeat {rw add_assoc},\nend\n\n/- This will be useful later.-/\nlemma mul_tree_swap_int_rw (a b c d : myint) : (int_mul (int_mul a b) (int_mul c d)) =\n                                               (int_mul (int_mul a c) (int_mul b d)) :=\nbegin\n  rw mul_assoc_int_rw a b (int_mul c d),\n  rw <- mul_assoc_int_rw b c d,\n  rw mul_comm_int_rw b c,\n  rw mul_assoc_int_rw c b d,\n  rw <- mul_assoc_int_rw a c (int_mul b d),\nend\n\nlemma mul_distrib_int (a b c : myint) : int_equal (int_mul (int_add a b) c)\n                                        (int_add (int_mul a c) (int_mul b c)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_mul, unfold int_add, unfold int_mul, unfold int_equal,\n  repeat {rw mul_add_distrib},\n  /- Ditto.  Rewriting these massive chunks of addition manually seems like a bad\n     use of time, even though it might produce marginally better code in the end.-/\n  rw <- add_assoc (myadd (mymul aplus cplus) (mymul bplus cplus)) (mymul aminus cminus) (mymul bminus cminus), rw add_comm (myadd (mymul aplus cplus) (mymul bplus cplus)) (mymul aminus cminus), rw add_comm (mymul aplus cminus) (mymul aminus cplus), rw <- add_assoc (myadd (myadd (mymul aminus cminus) (myadd (mymul aplus cplus) (mymul bplus cplus))) (mymul bminus cminus)) (myadd (mymul aminus cplus) (mymul aplus cminus)) (myadd (mymul bplus cminus) (mymul bminus cplus)), rw <- add_assoc (myadd (myadd (mymul aminus cminus) (myadd (mymul aplus cplus) (mymul bplus cplus))) (mymul bminus cminus)) (mymul aminus cplus) (mymul aplus cminus), rw add_comm (myadd (myadd (mymul aminus cminus) (myadd (mymul aplus cplus) (mymul bplus cplus))) (mymul bminus cminus)) (mymul aminus cplus), rw add_comm (myadd (mymul aminus cplus) (myadd (myadd (mymul aminus cminus) (myadd (mymul aplus cplus) (mymul bplus cplus))) (mymul bminus cminus))) (mymul aplus cminus), rw <- add_assoc (mymul aminus cminus) (mymul aplus cplus) (mymul bplus cplus), rw add_comm (mymul aminus cminus) (mymul aplus cplus), rw <- add_assoc (mymul aminus cplus) (myadd (myadd (mymul aplus cplus) (mymul aminus cminus)) (mymul bplus cplus)) (mymul bminus cminus), rw <- add_assoc (mymul aminus cplus) (myadd (mymul aplus cplus) (mymul aminus cminus)) (mymul bplus cplus), rw <- add_assoc (mymul aminus cplus) (mymul aplus cplus) (mymul aminus cminus), rw add_comm (mymul aminus cplus) (mymul aplus cplus), rw <- add_assoc (mymul aplus cminus) (myadd (myadd (myadd (mymul aplus cplus) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus)) (mymul bminus cminus), rw <- add_assoc (mymul aplus cminus) (myadd (myadd (mymul aplus cplus) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus), rw <- add_assoc (mymul aplus cminus) (myadd (mymul aplus cplus) (mymul aminus cplus)) (mymul aminus cminus), rw <- add_assoc (mymul aplus cminus) (mymul aplus cplus) (mymul aminus cplus), rw add_comm (mymul aplus cminus) (mymul aplus cplus), rw add_comm (myadd (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus)) (mymul bminus cminus), rw add_comm (mymul bplus cminus) (mymul bminus cplus), rw <- add_assoc (myadd (mymul bminus cminus) (myadd (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus))) (mymul bminus cplus) (mymul bplus cminus), rw add_comm (myadd (mymul bminus cminus) (myadd (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus))) (mymul bminus cplus), rw add_comm (myadd (mymul bminus cplus) (myadd (mymul bminus cminus) (myadd (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus)))) (mymul bplus cminus), rw add_comm (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)) (mymul bplus cplus), rw <- add_assoc (mymul bminus cminus) (mymul bplus cplus) (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)), rw add_comm (mymul bminus cminus) (mymul bplus cplus), rw <- add_assoc (mymul bminus cplus) (myadd (mymul bplus cplus) (mymul bminus cminus)) (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)), rw <- add_assoc (mymul bminus cplus) (mymul bplus cplus) (mymul bminus cminus), rw add_comm (mymul bminus cplus) (mymul bplus cplus), rw <- add_assoc (mymul bplus cminus) (myadd (myadd (mymul bplus cplus) (mymul bminus cplus)) (mymul bminus cminus)) (myadd (myadd (myadd (mymul aplus cplus) (mymul aplus cminus)) (mymul aminus cplus)) (mymul aminus cminus)), rw <- add_assoc (mymul bplus cminus) (myadd (mymul bplus cplus) (mymul bminus cplus)) (mymul bminus cminus), rw <- add_assoc (mymul bplus cminus) (mymul bplus cplus) (mymul bminus cplus), rw add_comm (mymul bplus cminus) (mymul bplus cplus),\n  symmetry,\n  rw add_comm (mymul aplus cplus) (mymul aminus cminus), rw <- add_assoc (myadd (myadd (mymul aplus cminus) (mymul bplus cminus)) (myadd (mymul aminus cplus) (mymul bminus cplus))) (myadd (mymul aminus cminus) (mymul aplus cplus)) (myadd (mymul bplus cplus) (mymul bminus cminus)), rw <- add_assoc (myadd (myadd (mymul aplus cminus) (mymul bplus cminus)) (myadd (mymul aminus cplus) (mymul bminus cplus))) (mymul aminus cminus) (mymul aplus cplus), rw add_comm (myadd (myadd (mymul aplus cminus) (mymul bplus cminus)) (myadd (mymul aminus cplus) (mymul bminus cplus))) (mymul aminus cminus), rw <- add_assoc (myadd (mymul aplus cminus) (mymul bplus cminus)) (mymul aminus cplus) (mymul bminus cplus), rw add_comm (myadd (mymul aplus cminus) (mymul bplus cminus)) (mymul aminus cplus), rw <- add_assoc (mymul aminus cminus) (myadd (mymul aminus cplus) (myadd (mymul aplus cminus) (mymul bplus cminus))) (mymul bminus cplus), rw <- add_assoc (mymul aminus cminus) (mymul aminus cplus) (myadd (mymul aplus cminus) (mymul bplus cminus)), rw add_comm (mymul aminus cminus) (mymul aminus cplus), rw <- add_assoc (myadd (mymul aminus cplus) (mymul aminus cminus)) (mymul aplus cminus) (mymul bplus cminus), rw add_comm (myadd (mymul aminus cplus) (mymul aminus cminus)) (mymul aplus cminus), rw add_comm (myadd (myadd (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus)) (mymul bminus cplus)) (mymul aplus cplus), rw add_comm (mymul bplus cplus) (mymul bminus cminus), rw <- add_assoc (myadd (mymul aplus cplus) (myadd (myadd (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus)) (mymul bminus cplus))) (mymul bminus cminus) (mymul bplus cplus), rw add_comm (myadd (mymul aplus cplus) (myadd (myadd (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus)) (mymul bminus cplus))) (mymul bminus cminus), rw add_comm (myadd (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus)) (mymul bminus cplus), rw <- add_assoc (mymul aplus cplus) (mymul bminus cplus) (myadd (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus)), rw add_comm (mymul aplus cplus) (mymul bminus cplus), rw <- add_assoc (mymul bminus cminus) (myadd (mymul bminus cplus) (mymul aplus cplus)) (myadd (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus)), rw <- add_assoc (mymul bminus cminus) (mymul bminus cplus) (mymul aplus cplus), rw add_comm (mymul bminus cminus) (mymul bminus cplus), rw add_comm (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))) (mymul bplus cminus), rw <- add_assoc (myadd (myadd (mymul bminus cplus) (mymul bminus cminus)) (mymul aplus cplus)) (mymul bplus cminus) (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus))), rw add_comm (myadd (myadd (mymul bminus cplus) (mymul bminus cminus)) (mymul aplus cplus)) (mymul bplus cminus), rw add_comm (myadd (myadd (mymul bplus cminus) (myadd (myadd (mymul bminus cplus) (mymul bminus cminus)) (mymul aplus cplus))) (myadd (mymul aplus cminus) (myadd (mymul aminus cplus) (mymul aminus cminus)))) (mymul bplus cplus),\n  repeat {rw add_assoc},\nend\n\nlemma mul_distrib_int_rw (a b c : myint) : (int_mul (int_add a b) c) =\n                                        (int_add (int_mul a c) (int_mul b c)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold int_mul, unfold int_add, unfold int_mul,\n  repeat {rw mul_add_distrib},\n  rw add_comm_in_tree (mymul aplus cplus) (mymul bplus cplus) (mymul aminus cminus) (mymul bminus cminus),\n  rw add_comm_in_tree (mymul aplus cminus) (mymul bplus cminus) (mymul aminus cplus) (mymul bminus cplus),\nend\n\nlemma mul_distrib_int_rw_alt (a b c : myint) : (int_mul a (int_add b c)) = (int_add (int_mul a b) (int_mul a c)) :=\nbegin\n  rw mul_comm_int_rw, rw mul_distrib_int_rw, rw mul_comm_int_rw b a, rw mul_comm_int_rw c a,\nend\n\nlemma mul_zero_int (a b : myint) : (iszero a) -> (iszero (int_mul a b)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold int_mul, unfold iszero,\n  intros h, rw h, rw add_comm,\nend\n\nlemma mul_zero_int_alt (a b : myint) : (iszero a) -> (iszero (int_mul b a)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold int_mul, unfold iszero,\n  intros h, rw h,\nend\n\nlemma mul_zero_int_zero (a : myint) : int_equal (int_mul a int_zero) int_zero :=\nbegin\n  cases a with aplus aminus, unfold int_zero, unfold int_mul, rw mul_zero, rw zero_add, rw mul_zero,\n  exact int_equal_refl (int zero zero),\nend\n\nlemma mul_result_zero_int (a b : myint) : (¬iszero a) -> (iszero (int_mul a b)) -> (iszero b) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold int_mul, unfold iszero,\n  intros h1 h2,\n  rw mul_comm aplus bplus at h2,\n  rw mul_comm aminus bminus at h2,\n  rw mul_comm aplus bminus at h2,\n  rw mul_comm aminus bplus at h2,\n  exact mul_weird_sub bplus bminus aplus aminus h1 h2,\nend\n\nlemma mul_result_zero_int_rev (a b : myint) : (¬iszero b) -> (iszero (int_mul a b)) -> iszero a :=\nbegin\n  intros h1 h2, rw mul_comm_int_rw at h2,\n  exact mul_result_zero_int b a h1 h2,\nend\n\nlemma mul_one_int (a : myint) : int_equal a (int_mul a int_one) :=\nbegin\n  cases a with aplus aminus, unfold int_one, unfold nat_one, unfold int_mul, unfold int_equal,\n  repeat {rw mul_one_eq}, repeat {rw mul_zero},\n  rw add_zero, rw zero_add, rw add_comm,\nend\n\nlemma mul_one_int_rw (a : myint) : (int_mul a int_one) = a :=\nbegin\n  cases a with aplus aminus,\n  unfold int_one, unfold nat_one, unfold int_mul, repeat {rw mul_zero}, rw add_zero, rw zero_add,\n  repeat {rw mul_one_eq},\nend\n\nlemma mul_one_int_rw_alt (a : myint) : (int_mul (int zero.mysucc zero) a) = a :=\nbegin\n  cases a with plus minus, unfold int_mul, repeat {rw zero_mul}, repeat {rw add_zero},\n  repeat {rw one_mul_eq},\nend\n\nlemma mul_comm_zero_int (a b : myint) : (iszero (int_mul a b)) = (iszero (int_mul b a)) :=\nbegin\n  have h1 : int_equal (int_mul a b) (int_mul b a),\n    exact mul_comm_int a b,\n  by_cases (iszero (int_mul a b)),\n    have h2 : (iszero (int_mul b a)),\n      exact int_zeros_only_eq (int_mul a b) (int_mul b a) h h1,\n    cc,\n\n    by_cases (iszero (int_mul b a)),\n      have absurd : (iszero (int_mul a b)),\n        exact int_zeros_only_eq (int_mul b a) (int_mul a b) h (mul_comm_int b a),\n      contradiction,\n      cc,\nend\n\nlemma mul_sub_int (a b c d : myint) : (int_equal a b) -> (int_equal (int_mul a c) d) ->\n                                                         (int_equal (int_mul b c) d) :=\nbegin\n  intros h1 h2,\n  exact int_eq_trans (int_mul b c) (int_mul a c) d\n      (int_eq_comm (int_mul a c) (int_mul b c) (mul_eq_alt c a b h1)) h2,\nend\n\nlemma multiply_two_equalities_int (a b c d : myint) : int_equal a b -> int_equal c d ->\n                                        (int_equal (int_mul a c) (int_mul b d)) :=\nbegin\n  intros h1 h2,\n  have tmp1 : int_equal (int_mul b d) (int_mul b d),\n    exact int_equal_refl (int_mul b d),\n  have tmp2 : int_equal (int_mul a d) (int_mul b d),\n    exact mul_sub_int b a d (int_mul b d) (int_eq_comm a b h1) tmp1,\n  have tmp3 : int_equal (int_mul a d) (int_mul d a),\n    exact mul_comm_int a d,\n  have tmp4 : int_equal (int_mul d a) (int_mul a c),\n    exact mul_sub_int c d a (int_mul a c) h2 (mul_comm_int c a),\n  exact int_eq_trans (int_mul a c) (int_mul a d) (int_mul b d)\n    (int_eq_comm (int_mul a d) (int_mul a c)\n      (int_eq_trans (int_mul a d) (int_mul d a) (int_mul a c) (mul_comm_int a d) tmp4)) tmp2,\nend\n\nlemma stupid (a b : mynat) : (a = b) = (b = a) :=\nbegin\n  by_cases (a = b),\n    cc,\n    cc,\nend\n\nlemma mul_cancel_int (a b c : myint) : (¬ iszero b) -> (int_equal (int_mul a b) (int_mul c b)) ->\n                                                       (int_equal a c) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, cases c with cplus cminus,\n  unfold iszero, unfold int_mul, unfold int_equal, intros b_not_zero, intros h,\n\n  /- Two python-generated lines.-/\n  rw add_comm (mymul aplus bplus) (mymul aminus bminus) at h, rw <- add_assoc (myadd (mymul aminus bminus) (mymul aplus bplus)) (mymul cplus bminus) (mymul cminus bplus) at h, rw add_comm (myadd (mymul aminus bminus) (mymul aplus bplus)) (mymul cplus bminus) at h, rw add_comm (mymul aminus bminus) (mymul aplus bplus) at h, rw <- add_assoc (mymul cplus bminus) (mymul aplus bplus) (mymul aminus bminus) at h, rw add_comm (mymul cplus bminus) (mymul aplus bplus) at h, rw add_comm (myadd (myadd (mymul aplus bplus) (mymul cplus bminus)) (mymul aminus bminus)) (mymul cminus bplus) at h,\n  rw stupid at h,\n  rw add_comm (mymul cplus bplus) (mymul cminus bminus) at h, rw <- add_assoc (myadd (mymul aplus bminus) (mymul aminus bplus)) (mymul cminus bminus) (mymul cplus bplus) at h, rw add_comm (myadd (mymul aplus bminus) (mymul aminus bplus)) (mymul cminus bminus) at h, rw add_comm (mymul aplus bminus) (mymul aminus bplus) at h, rw <- add_assoc (mymul cminus bminus) (mymul aminus bplus) (mymul aplus bminus) at h, rw add_comm (mymul cminus bminus) (mymul aminus bplus) at h, rw add_comm (myadd (myadd (mymul aminus bplus) (mymul cminus bminus)) (mymul aplus bminus)) (mymul cplus bplus) at h,\n  repeat {rw add_assoc at h},\n\n  rw <- add_assoc (mymul cplus bplus) (mymul aminus bplus) (myadd (mymul cminus bminus) (mymul aplus bminus)) at h,\n  rw <- mul_add_distrib cplus aminus bplus at h, rw <- mul_add_distrib cminus aplus bminus at h,\n  rw <- add_assoc (mymul cminus bplus) (mymul aplus bplus) (myadd (mymul cplus bminus) (mymul aminus bminus)) at h,\n  rw <- mul_add_distrib cminus aplus bplus at h, rw <- mul_add_distrib cplus aminus bminus at h,\n\n  have tmp : (myadd cplus aminus) = (myadd cminus aplus),\n    exact mul_weird_sub (myadd cplus aminus) (myadd cminus aplus) bplus bminus b_not_zero h,\n  symmetry, rw add_comm aminus cplus, rw add_comm aplus cminus, exact tmp,\nend\n\nlemma mul_cancel_int_alt (a b c : myint) : (¬ iszero a) -> (int_equal (int_mul a b) (int_mul a c)) ->\n                                                           (int_equal b c) :=\nbegin\n  rw mul_comm_int_rw a b, rw mul_comm_int_rw a c, exact mul_cancel_int b a c,\nend\n\nlemma mul_nonzero_int (a b : myint) : (¬ iszero a) -> (¬ iszero b) -> (¬ iszero (int_mul a b)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold int_mul, unfold iszero, intros h1 h2,\n  by_contradiction h,\n  rw add_comm (mymul aplus bminus) (mymul aminus bplus) at h,\n  exact h1 ((mul_weird_sub aplus aminus bplus bminus h2) h),\nend\n\nlemma mul_sub_in_add_int (a b c d e : myint) : (int_equal a b) -> (int_equal (int_add (int_mul a c) d) e) ->\n                                                                  (int_equal (int_add (int_mul b c) d) e) :=\nbegin\n  intros h1 h2,\n  have h3 : int_equal (int_mul a c) (int_mul b c),\n    exact mul_eq_alt c a b h1,\n  exact add_sub_int (int_mul a c) (int_mul b c) d e h3 h2,\nend\n\nlemma mul_two_int (a : myint) : int_mul (int zero.mysucc.mysucc zero) a = (int_add a a) :=\nbegin\n  cases a with plus minus, unfold int_add, unfold int_mul, repeat {rw zero_mul}, repeat {rw add_zero},\n  repeat {rw mul_two},\nend\n\ndef negative : myint -> myint\n| (int pos neg) := (int neg pos)\n\ndef negative_eq (a b : myint) : (int_equal a b) -> (int_equal (negative a) (negative b)) :=\nbegin\n  cases a with aplus aminus, cases b with bplus bminus, unfold negative, unfold int_equal, intros, cc,\nend\n\ndef add_to_negative (a : myint) : (int_equal int_zero (int_add a (negative a))) :=\nbegin\n  cases a with plus minus,\n  unfold negative, unfold int_add, unfold int_zero, unfold int_equal, rw add_comm minus plus,\nend\n\ndef add_to_negative_alt (a : myint) : iszero (int_add a (negative a)) :=\nbegin\n  cases a with aplus aminus, unfold negative, unfold int_add, unfold iszero, rw add_comm aplus aminus,\nend\n\ndef mul_negative (a b : myint) : int_mul a (negative b) = negative (int_mul a b) :=\nbegin\n  cases a with apos aneg, cases b with bpos bneg, unfold negative, unfold int_mul, unfold negative,\nend\n\ndef mul_negative_alt (a b : myint) : int_mul a (negative b) = int_mul (negative a) b :=\nbegin\n  cases a with apos aneg, cases b with bpos bneg, unfold negative, unfold int_mul,\n  rw add_comm (mymul apos bneg) (mymul aneg bpos),\n  rw add_comm (mymul aneg bneg) (mymul apos bpos),\nend\n\n/- A rational number is a pair representing a/b -/\ninductive myrat : Type\n| rat : myint -> myint -> myrat\n\nopen myrat\n/- Definition:\n    A myrat where iszero (second component) is True is an undefined value\n    All operations on myrat types should return an undefined value if given one.\n    In this way, failure can propagate.\n    Also, all predicates are True about undefined values, so that proofs\n    do not have to start with \"defined (a) ->\".-/\n\ndef rat_zero : myrat := (rat int_zero int_one)\n\ndef rat_one : myrat := (rat int_one int_one)\ndef rat_two : myrat := (rat (int zero.mysucc.mysucc zero) int_one)\n\ndef defined : myrat -> Prop\n| (rat _ den) := (¬(iszero den))\n\ndef iszero_rat : myrat -> Prop\n| (rat num den) := (iszero num) \\/ (iszero den)\n\nlemma undef_iszero (a : myrat) : ¬(defined a) -> (iszero_rat a) :=\nbegin\n  cases a with anum aden, unfold defined, unfold iszero_rat, intros, right, cc,\nend\n\ndef rat_eq : myrat -> myrat -> Prop\n| (rat anum aden) (rat bnum bden) := int_equal (int_mul anum bden) (int_mul aden bnum) \\/\n                                              (iszero aden) \\/ (iszero bden)\n\nlemma undef_eq (a b : myrat) : ¬(defined a) -> (rat_eq a b) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold defined, unfold rat_eq, intros,\n  right, left, by_cases (¬(iszero aden)),\n    cc, cc,\nend\n\nlemma rat_eq_refl (a : myrat) : (rat_eq a a) :=\nbegin\n  cases a with anum aden, unfold rat_eq, left, exact mul_comm_int anum aden,\nend\n\nlemma rat_eq_comm (a b : myrat) : (rat_eq a b) -> (rat_eq b a) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_eq, intros h, cases h,\n    left,\n    have tmp1 : int_equal (int_mul bden anum) (int_mul anum bden),\n      exact mul_comm_int bden anum,\n    have tmp2 : int_equal (int_mul bden anum) (int_mul aden bnum),\n      exact int_eq_trans (int_mul bden anum) (int_mul anum bden) (int_mul aden bnum) tmp1 h,\n    have tmp3 : int_equal (int_mul aden bnum) (int_mul bnum aden),\n      exact mul_comm_int aden bnum,\n    exact int_eq_comm (int_mul bden anum) (int_mul bnum aden) (int_eq_trans (int_mul bden anum) (int_mul aden bnum) (int_mul bnum aden) tmp2 tmp3),\n\n    cases h,\n      right, right, exact h,\n      right, left, exact h,\nend\n\nlemma eq_undef (a b : myrat) : ¬(defined b) -> (rat_eq a b) :=\nbegin\n  intros h, exact rat_eq_comm b a (undef_eq b a h),\nend\n\nlemma zeroes_only_eq_rat (a b : myrat) : (defined a) -> (rat_eq a b) -> (iszero_rat a) -> (iszero_rat b) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_eq, unfold iszero_rat, unfold defined, intros h2 h3 h1,\n  cases h1, cases h3,\n    have tmp : iszero (int_mul aden bnum),\n      exact int_zeros_only_eq (int_mul anum bden) (int_mul aden bnum) (mul_zero_int anum bden h1) h3,\n    left, by_cases (iszero bnum), cc, exfalso, exact mul_nonzero_int aden bnum h2 h tmp,\n\n    cases h3, cc, cc, cc,\nend\n\nlemma rat_eq_trans (a b c : myrat) : (defined b) -> (rat_eq a b) -> (rat_eq b c) -> (rat_eq a c) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden, unfold rat_eq,\n  intros h1, intros h2, intros h3,\n  by_cases h4 : (iszero aden),\n    right, left, exact h4,\n  by_cases h5 : (iszero cden),\n    right, right, exact h5,\n  unfold defined at h1,\n  cases h2, cases h3,\n  by_cases (iszero bnum),\n\n    have h6 : iszero (int_mul aden bnum),\n      rw mul_comm_int_rw aden bnum,\n      exact mul_zero_int bnum aden h,\n    have h7 : iszero (int_mul bnum cden),\n      exact mul_zero_int bnum cden h,\n    have h8 : iszero anum,\n      exact mul_result_zero_int_rev anum bden h1 (int_zeros_only_eq_rev (int_mul aden bnum) (int_mul anum bden) h6 h2),\n    have h9 : iszero cnum,\n      exact mul_result_zero_int bden cnum h1 (int_zeros_only_eq (int_mul bnum cden) (int_mul bden cnum) h7 h3),\n    left,\n    exact int_zeros_eq (int_mul anum cden) (int_mul aden cnum) (mul_zero_int anum cden h8) (mul_zero_int_alt cnum aden h9),\n\n    have tmp : int_equal (int_mul (int_mul anum bden) (int_mul bnum cden)) (int_mul (int_mul aden bnum) (int_mul bden cnum)),\n      exact multiply_two_equalities_int (int_mul anum bden) (int_mul aden bnum) (int_mul bnum cden) (int_mul bden cnum) h2 h3,\n    rw mul_assoc_int_rw aden bnum (int_mul bden cnum) at tmp,\n    rw <- mul_assoc_int_rw bnum bden cnum at tmp,\n    rw mul_comm_int_rw (int_mul bnum bden) cnum at tmp,\n    rw mul_assoc_int_rw anum bden (int_mul bnum cden) at tmp,\n    rw <- mul_assoc_int_rw bden bnum cden at tmp,\n    rw mul_comm_int_rw (int_mul bden bnum) cden at tmp,\n    rw mul_comm_int_rw bden bnum at tmp,\n    repeat {rw <- mul_assoc_int_rw at tmp},\n    rw mul_assoc_int_rw (int_mul aden cnum) bnum bden at tmp,\n    rw mul_assoc_int_rw (int_mul anum cden) bnum bden at tmp,\n    have tmp2 : ¬ iszero (int_mul bnum bden),\n      exact mul_nonzero_int bnum bden h h1,\n    left, exact mul_cancel_int (int_mul anum cden) (int_mul bnum bden) (int_mul aden cnum) tmp2 tmp,\n\n    cases h3, cc, cc, cases h2, cc, cc,\nend\n\ndef rat_mul : myrat -> myrat -> myrat\n| (rat anum aden) (rat bnum bden) := (rat (int_mul anum bnum) (int_mul aden bden))\n\nlemma rat_mul_comm (a b : myrat) : (rat_mul a b) = (rat_mul b a) :=\nbegin\n  cases a with anum aden, cases b with bnum bden,\n  unfold rat_mul,\n  rw mul_comm_int_rw anum bnum, rw mul_comm_int_rw aden bden,\nend\n\nlemma rat_mul_def (a b : myrat) : (defined a) -> (defined b) -> (defined (rat_mul a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden,\n  unfold rat_mul, unfold defined, intros h1 h2,\n  exact mul_nonzero_int aden bden h1 h2,\nend\n\nlemma rat_mul_undef (a b : myrat) : ¬(defined a) -> ¬(defined (rat_mul a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden,\n  unfold rat_mul, unfold defined, intros,\n  by_cases (iszero aden),\n    have tmp : iszero (int_mul aden bden),\n      exact mul_zero_int aden bden h,\n    cc,\n    cc,\nend\n\nlemma rat_undef_mul (a b : myrat) : ¬(defined b) -> ¬(defined (rat_mul a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden,\n  unfold rat_mul, unfold defined, intros,\n  by_cases (iszero bden),\n    have tmp : iszero (int_mul aden bden),\n      exact mul_zero_int_alt bden aden h,\n    cc, cc,\nend\n\nlemma rat_mul_zero (a b : myrat) : (iszero_rat a) -> (iszero_rat (rat_mul a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_mul, unfold iszero_rat, intros h,\n  cases h,\n    left, exact mul_zero_int anum bnum h,\n    right, exact mul_zero_int aden bden h,\nend\n\nlemma rat_mul_assoc (a b c : myrat) : (rat_mul (rat_mul a b) c) = (rat_mul a (rat_mul b c)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden,\n  unfold rat_mul,\n  repeat {rw mul_assoc_int_rw},\nend\n\nlemma rat_mul_eq (a b c : myrat) : (rat_eq b c) -> (rat_eq (rat_mul a b) (rat_mul a c)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden,\n  unfold rat_mul, unfold rat_eq, intros h, cases h with h1 h1,\n    left,\n    have h2 : int_equal (int_mul (int_mul bnum cden) (int_mul anum aden)) (int_mul (int_mul bden cnum) (int_mul anum aden)),\n      exact mul_eq_alt (int_mul anum aden) (int_mul bnum cden) (int_mul bden cnum) h1,\n    rw mul_comm_int_rw anum bnum,\n    rw mul_comm_int_rw aden cden,\n    rw mul_tree_swap_int_rw bnum anum cden aden,\n    rw mul_comm_int_rw aden bden,\n    rw mul_comm_int_rw anum cnum,\n    rw mul_tree_swap_int_rw bden aden cnum anum,\n    rw mul_comm_int_rw aden anum, exact h2,\n\n    right, cases h1,\n      left, exact mul_zero_int_alt bden aden h1,\n      right, exact mul_zero_int_alt cden aden h1,\nend\n\nlemma mul_sub_rat (a b c d : myrat) : (defined a) -> (rat_eq a b) ->\n                                      (rat_eq (rat_mul a c) d) -> (rat_eq (rat_mul b c) d) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden, cases d with dnum dden,\n  unfold rat_mul, unfold rat_eq, intros h1 h2 h3,\n  by_cases h6 : (iszero bden), right, left, exact mul_zero_int bden cden h6,\n  by_cases h8 : (iszero cden), right, left, exact mul_zero_int_alt cden bden h8,\n  cases h2 with h2,\n    cases h3 with h3,\n      unfold defined at h1,\n    have h4 : int_equal (int_mul (int_mul bnum bden) (int_mul (int_mul anum cnum) dden))\n                            (int_mul (int_mul bnum bden) (int_mul (int_mul aden cden) dnum)),\n          exact mul_eq (int_mul bnum bden) (int_mul (int_mul anum cnum) dden) (int_mul (int_mul aden cden) dnum) h3,\n        repeat {rw <- mul_assoc_int_rw at h4},\n        rw mul_assoc_int_rw bnum bden anum at h4,\n        rw mul_comm_int_rw bden anum at h4,\n        rw mul_comm_int_rw bnum bden at h4,\n        rw mul_assoc_int_rw bden bnum aden at h4,\n        rw mul_comm_int_rw bnum aden at h4,\n        by_cases h5 : (iszero bnum),\n          have h7 : iszero anum,\n            exact mul_result_zero_int_rev anum bden h6 (int_zeros_only_eq_rev (int_mul aden bnum) (int_mul anum bden) (mul_zero_int_alt bnum aden h5) h2),\n          have h9 : iszero dnum,\n            exact mul_result_zero_int (int_mul aden cden) dnum (mul_nonzero_int aden cden h1 h8) (int_zeros_only_eq (int_mul (int_mul anum cnum) dden) (int_mul (int_mul aden cden) dnum) (mul_zero_int (int_mul anum cnum) dden (mul_zero_int anum cnum h7)) h3),\n          left,\n          exact int_zeros_eq (int_mul (int_mul bnum cnum) dden) (int_mul (int_mul bden cden) dnum) (mul_zero_int (int_mul bnum cnum) dden (mul_zero_int bnum cnum h5)) (mul_zero_int_alt dnum (int_mul bden cden) h9),\n\n          rw mul_comm_int_rw bden (int_mul aden bnum) at h4, rw mul_comm_int_rw bnum (int_mul anum bden) at h4,\n          repeat {rw mul_assoc_int_rw at h4},\n          rw <- mul_assoc_int_rw at h4,\n          rw <- mul_assoc_int_rw aden bnum (int_mul bden (int_mul cden dnum)) at h4,\n          have h7 : int_equal (int_mul (int_mul aden bnum) (int_mul bnum (int_mul cnum dden))) (int_mul (int_mul aden bnum) (int_mul bden (int_mul cden dnum))),\n            exact mul_sub_int (int_mul anum bden) (int_mul aden bnum) (int_mul bnum (int_mul cnum dden)) (int_mul (int_mul aden bnum) (int_mul bden (int_mul cden dnum))) h2 h4,\n          left, repeat {rw mul_assoc_int_rw},\n          exact mul_cancel_int_alt (int_mul aden bnum) (int_mul bnum (int_mul cnum dden)) (int_mul bden (int_mul cden dnum)) (mul_nonzero_int aden bnum h1 h5) h7,\n\n      cases h3 with h3,\n        unfold defined at h1, right, left,\n        have h7 : iszero cden,\n          exact mul_result_zero_int aden cden h1 h3,\n        contradiction,\n\n        right, right, exact h3,\n\n    cases h2,\n      unfold defined at h1, contradiction,\n      right, left, exact mul_zero_int bden cden h2,\nend\n\nlemma mul_eq_rat (a b c : myrat) : (rat_eq a b) -> (rat_eq (rat_mul a c) (rat_mul b c)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden, unfold rat_mul, unfold rat_eq,\n  intros h1, cases h1 with h1,\n    left, rw mul_tree_swap_int_rw anum cnum bden cden,\n    have h2 : int_equal (int_mul aden bnum) (int_mul anum bden),\n      exact int_eq_comm (int_mul anum bden) (int_mul aden bnum) h1,\n    apply mul_sub_int (int_mul aden bnum) (int_mul anum bden) (int_mul cnum cden) (int_mul (int_mul aden cden) (int_mul bnum cnum)) h2,\n    rw mul_comm_int_rw cnum cden, rw mul_tree_swap_int_rw aden bnum cden cnum,\n    exact int_equal_refl (int_mul (int_mul aden cden) (int_mul bnum cnum)),\n\n    cases h1 with h1,\n      right, left, exact mul_zero_int aden cden h1,\n      right, right, exact mul_zero_int bden cden h1,\nend\n\nlemma mul_eq_rat_alt (a b c : myrat) : (rat_eq a b) -> (rat_eq (rat_mul c a) (rat_mul c b)) :=\nbegin\n  rw rat_mul_comm c a, rw rat_mul_comm c b, exact mul_eq_rat a b c,\nend\n\ndef rat_add : myrat -> myrat -> myrat\n| (rat anum aden) (rat bnum bden) := (rat (int_add (int_mul anum bden) (int_mul bnum aden))\n                                                      (int_mul aden bden))\n\nlemma rat_add_undef (a b : myrat) : ¬(defined a) -> ¬(defined (rat_add a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_add, unfold defined, intros h1,\n  by_cases h2 : (iszero aden),\n    have h3 : iszero (int_mul aden bden),\n      exact mul_zero_int aden bden h2,\n    cc, cc,\nend\n\nlemma rat_add_def (a b : myrat) : (defined a) -> (defined b) -> (defined (rat_add a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_add, unfold defined, intros h1 h2,\n  exact mul_nonzero_int aden bden h1 h2,\nend\n\nlemma rat_add_zero (a b : myrat) : (iszero_rat a) -> (rat_eq (rat_add a b) b) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_add, unfold rat_eq, unfold iszero_rat, intros h,\n  cases h, left,\n  have h1 : (int_equal (int_mul bnum aden) (int_add (int_mul anum bden) (int_mul bnum aden))),\n    exact add_zero_int (int_mul anum bden) (int_mul bnum aden) (mul_zero_int anum bden h),\n  have h2 : int_equal (int_mul bden (int_mul bnum aden)) (int_mul bden (int_add (int_mul anum bden) (int_mul bnum aden))),\n    exact mul_eq bden (int_mul bnum aden) (int_add (int_mul anum bden) (int_mul bnum aden)) h1,\n  rw mul_comm_int_rw (int_add (int_mul anum bden) (int_mul bnum aden)) bden,\n  rw mul_comm_int_rw aden bden, rw mul_assoc_int_rw bden aden bnum, rw mul_comm_int_rw aden bnum,\n  exact int_eq_comm (int_mul bden (int_mul bnum aden)) (int_mul bden (int_add (int_mul anum bden) (int_mul bnum aden))) h2,\n\n  right, left, exact mul_zero_int aden bden h,\nend\n\nlemma rat_add_zero_alt (a : myrat) : (rat_add a rat_zero) = a :=\nbegin\n  unfold rat_zero, cases a with anum aden, unfold rat_add, repeat {rw mul_one_int_rw _},\n  cases aden with adenplus adenminus, unfold int_zero, unfold int_mul,\n  rw mul_comm, rw mul_comm zero adenminus, repeat {rw mul_zero}, unfold myadd,\n  cases anum with anumplus anumminus, unfold int_add, repeat {rw add_zero},\nend\n\nlemma add_eq_rat (a b c : myrat) : (rat_eq a b) -> (rat_eq (rat_add a c) (rat_add b c)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden, unfold rat_add, unfold rat_eq, intros h,\n  cases h, left,\n    repeat {rw mul_distrib_int_rw}, repeat {rw mul_distrib_int_rw_alt},\n    rw mul_assoc_int_rw anum cden (int_mul bden cden), rw <- mul_assoc_int_rw cden bden cden,\n    rw mul_comm_int_rw cden bden, rw mul_assoc_int_rw bden cden cden,\n    rw <- mul_assoc_int_rw anum bden (int_mul cden cden),\n    apply mul_sub_in_add_int (int_mul aden bnum) (int_mul anum bden) (int_mul cden cden) (int_mul (int_mul cnum aden) (int_mul bden cden)) (int_add (int_mul (int_mul aden cden) (int_mul bnum cden)) (int_mul (int_mul aden cden) (int_mul cnum bden))) (int_eq_comm _ _ h),\n    rw mul_assoc_int_rw aden bnum (int_mul cden cden), rw <- mul_assoc_int_rw bnum cden cden,\n    rw mul_comm_int_rw bnum cden, rw mul_assoc_int_rw cden bnum cden,\n    rw <- mul_assoc_int_rw aden cden (int_mul bnum cden), rw mul_comm_int_rw bnum cden,\n    rw mul_comm_int_rw cnum aden, rw mul_comm_int_rw bden cden,\n    rw mul_assoc_int_rw aden cnum (int_mul cden bden), rw <- mul_assoc_int_rw cnum cden bden,\n    rw mul_comm_int_rw cnum cden, rw mul_assoc_int_rw cden cnum bden,\n    rw <- mul_assoc_int_rw aden cden (int_mul cnum bden),\n    exact int_equal_refl _,\n\n    cases h,\n      right, left,  exact mul_zero_int aden cden h,\n      right, right, exact mul_zero_int bden cden h,\nend\n\nlemma rat_add_comm (a b : myrat) : (rat_add a b) = (rat_add b a) :=\nbegin\n  cases a with anum aden, cases b with bnum bden,\n  unfold rat_add,\n  rw add_comm_int_rw (int_mul anum bden) (int_mul bnum aden),\n  rw mul_comm_int_rw bden aden,\nend\n\nlemma rat_add_assoc (a b c : myrat) : (rat_add a (rat_add b c)) = (rat_add (rat_add a b) c) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden, unfold rat_add,\n  repeat {rw mul_assoc_int_rw}, repeat {rw mul_distrib_int_rw},\n  repeat {rw mul_assoc_int_rw}, repeat {rw add_assoc_int_rw},\n  rw mul_comm_int_rw aden bden, rw mul_comm_int_rw aden cden,\nend\n\nlemma add_sub_rat (a b c d : myrat) : (defined a) -> (rat_eq a b) ->\n                                      (rat_eq (rat_add a c) d) -> (rat_eq (rat_add b c) d) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden, cases d with dnum dden,\n  unfold rat_add, unfold rat_eq, intros h1 h2 h3, unfold defined at h1,\n  by_cases h4 : iszero bden, right, left, exact mul_zero_int bden cden h4,\n  by_cases h5 : iszero cden, right, left, exact mul_zero_int_alt cden bden h5,\n  by_cases h6 : iszero dden, right, right, exact h6,\n  left,\n  cases h2 with h2, cases h3 with h3,\n    by_cases h7 : (iszero anum),\n      have h8 : (iszero bnum),\n        exact mul_result_zero_int aden bnum h1 (int_zeros_only_eq (int_mul anum bden) (int_mul aden bnum) (mul_zero_int anum bden h7) h2),\n      have h9 : int_equal (int_mul (int_mul cnum aden) dden) (int_mul (int_mul aden cden) dnum),\n        exact mul_sub_int (int_add (int_mul anum cden) (int_mul cnum aden)) (int_mul cnum aden) dden (int_mul (int_mul aden cden) dnum) (add_zero_int_alt (int_mul anum cden) (int_mul cnum aden) (mul_zero_int anum cden h7)) h3,\n      rw mul_comm_int_rw cnum aden at h9, repeat {rw mul_assoc_int_rw at h9},\n      have h10 : int_equal (int_mul cnum dden) (int_mul cden dnum),\n        exact mul_cancel_int_alt aden (int_mul cnum dden) (int_mul cden dnum) h1 h9,\n      rw mul_distrib_int_rw,\n      have h11 : int_equal (int_mul (int_mul cnum bden) dden) (int_add (int_mul (int_mul bnum cden) dden) (int_mul (int_mul cnum bden) dden)),\n        exact add_zero_int (int_mul (int_mul bnum cden) dden) (int_mul (int_mul cnum bden) dden) (mul_zero_int (int_mul bnum cden) dden (mul_zero_int bnum cden h8)),\n      rw mul_comm_int_rw cnum bden at h11, rw mul_assoc_int_rw bden cnum dden at h11, rw mul_comm_int_rw bden (int_mul cnum dden) at h11,\n      have h12 : int_equal (int_mul (int_mul cden dnum) bden) (int_add (int_mul (int_mul bnum cden) dden) (int_mul (int_mul cnum dden) bden)),\n        exact mul_sub_int (int_mul cnum dden) (int_mul cden dnum) bden (int_add (int_mul (int_mul bnum cden) dden) (int_mul (int_mul cnum dden) bden)) h10 h11,\n      rw mul_assoc_int_rw cnum bden dden, rw mul_comm_int_rw bden dden, rw <- mul_assoc_int_rw cnum dden bden,\n      rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden dnum, rw mul_comm_int_rw bden dnum, rw <- mul_assoc_int_rw cden dnum bden,\n      exact int_eq_comm (int_mul (int_mul cden dnum) bden) (int_add (int_mul (int_mul bnum cden) dden) (int_mul (int_mul cnum dden) bden)) h12,\n\n      rw mul_distrib_int_rw at h3, rw mul_distrib_int_rw,\n      have h8 : int_equal (int_mul bden (int_add (int_mul (int_mul anum cden) dden) (int_mul (int_mul cnum aden) dden))) (int_mul bden (int_mul (int_mul aden cden) dnum)),\n        exact mul_eq bden (int_add (int_mul (int_mul anum cden) dden) (int_mul (int_mul cnum aden) dden)) (int_mul (int_mul aden cden) dnum) h3,\n      rw mul_distrib_int_rw_alt at h8,\n      rw mul_assoc_int_rw anum cden dden at h8, rw <- mul_assoc_int_rw bden anum (int_mul cden dden) at h8, rw mul_comm_int_rw bden anum at h8,\n      have h9 : int_equal (int_add (int_mul (int_mul aden bnum) (int_mul cden dden)) (int_mul bden (int_mul (int_mul cnum aden) dden))) (int_mul bden (int_mul (int_mul aden cden) dnum)),\n        exact mul_sub_in_add_int (int_mul anum bden) (int_mul aden bnum) (int_mul cden dden) (int_mul bden (int_mul (int_mul cnum aden) dden)) (int_mul bden (int_mul (int_mul aden cden) dnum)) h2 h8,\n      rw mul_assoc_int_rw aden bnum (int_mul cden dden) at h9,\n      rw mul_comm_int_rw cnum aden at h9, rw mul_assoc_int_rw aden cnum dden at h9, rw <- mul_assoc_int_rw bden aden (int_mul cnum dden) at h9,\n      rw mul_comm_int_rw bden aden at h9, rw mul_assoc_int_rw aden bden (int_mul cnum dden) at h9,\n      rw <- mul_distrib_int_rw_alt aden (int_mul bnum (int_mul cden dden)) (int_mul bden (int_mul cnum dden)) at h9,\n      rw mul_assoc_int_rw aden cden dnum at h9, rw <- mul_assoc_int_rw bden aden (int_mul cden dnum) at h9, rw mul_comm_int_rw bden aden at h9, rw mul_assoc_int_rw aden bden (int_mul cden dnum) at h9,\n      rw mul_assoc_int_rw bnum cden dden, rw mul_assoc_int_rw bden cden dnum,\n      rw mul_comm_int_rw cnum bden, rw mul_assoc_int_rw bden cnum dden,\n      exact mul_cancel_int_alt aden (int_add (int_mul bnum (int_mul cden dden)) (int_mul bden (int_mul cnum dden))) (int_mul bden (int_mul cden dnum)) h1 h9,\n\n    cases h3 with h3,\n      exfalso, exact h5 (mul_result_zero_int aden cden h1 h3),\n      contradiction,\n\n    exfalso, cases h2 with h2, exact h1 h2, exact h4 h2,\nend\n\nlemma add_sub_rat_alt (a b c d : myrat) : (defined a) -> (rat_eq a b) -> (rat_eq (rat_add c a) d) -> (rat_eq (rat_add c b) d) :=\nbegin\n  intros h1 h2 h3, rw rat_add_comm, rw rat_add_comm at h3, exact add_sub_rat a b c d h1 h2 h3,\nend\n\nlemma add_self_nonzero_rat (a : myrat) : ¬(iszero_rat a) -> ¬(iszero_rat (rat_add a a)) :=\nbegin\n  cases a with anum aden, unfold rat_add, unfold iszero_rat, intros,\n  by_cases (iszero (int_add (int_mul anum aden) (int_mul anum aden)) ∨ iszero (int_mul aden aden)),\n  exfalso, cases h,\n    by_cases h_anum : (iszero anum), cc,\n    by_cases h_aden : (iszero aden), cc,\n    exact int_add_self_nonzero (int_mul anum aden) (mul_nonzero_int anum aden h_anum h_aden) h,\n\n    by_cases h_aden : (iszero aden), cc,\n    exact (mul_nonzero_int aden aden h_aden h_aden) h,\n    cc,\nend\n\nlemma rat_mul_zero_alt (a : myrat) : rat_eq rat_zero (rat_mul a rat_zero) :=\nbegin\n  cases a with anum aden,\n  unfold rat_zero, unfold int_zero, unfold int_one, unfold rat_mul, unfold rat_eq, by_cases (iszero aden),\n    right, right, exact mul_zero_int aden (int nat_one zero) h,\n    left, have int : iszero (int zero zero),\n      unfold iszero,\n    exact int_zeros_eq (int_mul (myint.int zero zero) (int_mul aden (myint.int nat_one zero))) ((int_mul (myint.int nat_one zero) (int_mul anum (myint.int zero zero)))) (mul_zero_int (myint.int zero zero) (int_mul aden (myint.int nat_one zero)) int) (mul_zero_int_alt (int_mul anum (myint.int zero zero)) ((myint.int nat_one zero)) (mul_zero_int_alt (myint.int zero zero) anum int)),\nend\n\nlemma rat_mul_one (a b : myrat) : rat_eq a rat_one -> rat_eq b (rat_mul a b) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_mul, unfold rat_one, unfold rat_eq, intros h, cases h,\n    left, repeat {rw mul_one_int_rw at h},\n    have h1 : int_equal aden anum,\n      exact int_eq_comm anum aden h,\n    rw <- mul_assoc_int_rw bnum aden bden, rw mul_comm_int_rw bnum aden, rw mul_assoc_int_rw aden bnum bden,\n    rw <- mul_assoc_int_rw bden anum bnum, rw mul_comm_int_rw bden anum, rw mul_assoc_int_rw anum bden bnum,\n    rw mul_comm_int_rw bnum bden,\n    exact mul_eq_alt (int_mul bden bnum) aden anum h1,\n\n    cases h,\n      right, right, exact mul_zero_int aden bden h,\n      unfold int_one at h, unfold iszero at h, unfold nat_one at h, cc,\nend\n\nlemma rat_mul_one_rw (a : myrat) : rat_mul a rat_one = a :=\nbegin\n  cases a with num den, unfold rat_one, unfold rat_mul,\n  cases num with numplus numminus, cases den with denplus denminus,\n  unfold int_one, unfold int_mul, rw mul_zero, rw add_zero, unfold nat_one,\n  rw mul_one_eq, rw mul_zero, rw zero_add, rw mul_one_eq, rw mul_one_eq, rw mul_zero, rw add_zero,\n  rw mul_zero, rw zero_add, rw mul_one_eq,\nend\n\nlemma rat_mul_distrib (a b c : myrat) : rat_eq (rat_mul (rat_add a b) c) (rat_add (rat_mul a c) (rat_mul b c)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, cases c with cnum cden,\n  unfold rat_mul, unfold rat_add, unfold rat_mul,\n  rw mul_distrib_int_rw, repeat {rw mul_assoc_int_rw},\n  unfold rat_eq, left,\n  rw mul_distrib_int_rw_alt, rw mul_distrib_int_rw, repeat {rw mul_assoc_int_rw},\n  /- Don't lie and try to tell me you haven't missed the inefficient Python-generated code.-/\n  rw <- mul_assoc_int_rw anum bden (int_mul cnum (int_mul aden (int_mul cden (int_mul bden cden)))), rw mul_comm_int_rw anum bden, rw mul_assoc_int_rw bden anum (int_mul cnum (int_mul aden (int_mul cden (int_mul bden cden)))), rw <- mul_assoc_int_rw anum cnum (int_mul aden (int_mul cden (int_mul bden cden))), rw mul_comm_int_rw anum cnum, rw mul_assoc_int_rw cnum anum (int_mul aden (int_mul cden (int_mul bden cden))), rw <- mul_assoc_int_rw aden cden (int_mul bden cden), rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden (int_mul bden cden), rw <- mul_assoc_int_rw aden bden cden, rw mul_comm_int_rw aden bden, rw mul_assoc_int_rw bden aden cden, rw mul_comm_int_rw aden cden, rw <- mul_assoc_int_rw bden cnum (int_mul anum (int_mul cden (int_mul bden (int_mul cden aden)))), rw mul_comm_int_rw bden cnum, rw mul_assoc_int_rw cnum bden (int_mul anum (int_mul cden (int_mul bden (int_mul cden aden)))), rw <- mul_assoc_int_rw anum cden (int_mul bden (int_mul cden aden)), rw mul_comm_int_rw anum cden, rw mul_assoc_int_rw cden anum (int_mul bden (int_mul cden aden)), rw <- mul_assoc_int_rw anum bden (int_mul cden aden), rw mul_comm_int_rw anum bden, rw mul_assoc_int_rw bden anum (int_mul cden aden), rw <- mul_assoc_int_rw anum cden aden, rw mul_comm_int_rw anum cden, rw mul_assoc_int_rw cden anum aden, rw <- mul_assoc_int_rw bden cden (int_mul bden (int_mul cden (int_mul anum aden))), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul bden (int_mul cden (int_mul anum aden))), rw <- mul_assoc_int_rw bden cden (int_mul anum aden), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul anum aden), rw <- mul_assoc_int_rw bden cden (int_mul bden (int_mul anum aden)), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul bden (int_mul anum aden)),\n  rw <- mul_assoc_int_rw aden cnum (int_mul cden (int_mul bden (int_mul cden aden))), rw mul_comm_int_rw aden cnum, rw mul_assoc_int_rw cnum aden (int_mul cden (int_mul bden (int_mul cden aden))), rw <- mul_assoc_int_rw aden cden (int_mul bden (int_mul cden aden)), rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden (int_mul bden (int_mul cden aden)), rw <- mul_assoc_int_rw aden bden (int_mul cden aden), rw mul_comm_int_rw aden bden, rw mul_assoc_int_rw bden aden (int_mul cden aden), rw <- mul_assoc_int_rw aden cden aden, rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden aden, rw <- mul_assoc_int_rw bnum cnum (int_mul cden (int_mul bden (int_mul cden (int_mul aden aden)))), rw mul_comm_int_rw bnum cnum, rw mul_assoc_int_rw cnum bnum (int_mul cden (int_mul bden (int_mul cden (int_mul aden aden)))), rw <- mul_assoc_int_rw bnum cden (int_mul bden (int_mul cden (int_mul aden aden))), rw mul_comm_int_rw bnum cden, rw mul_assoc_int_rw cden bnum (int_mul bden (int_mul cden (int_mul aden aden))), rw <- mul_assoc_int_rw bden cden (int_mul aden aden), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul aden aden), rw <- mul_assoc_int_rw bnum cden (int_mul bden (int_mul aden aden)), rw mul_comm_int_rw bnum cden, rw mul_assoc_int_rw cden bnum (int_mul bden (int_mul aden aden)),\n  apply int_eq_comm,\n  rw <- mul_assoc_int_rw aden bden (int_mul cden (int_mul anum (int_mul cnum (int_mul cden bden)))), rw mul_comm_int_rw aden bden, rw mul_assoc_int_rw bden aden (int_mul cden (int_mul anum (int_mul cnum (int_mul cden bden)))), rw <- mul_assoc_int_rw aden cden (int_mul anum (int_mul cnum (int_mul cden bden))), rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden (int_mul anum (int_mul cnum (int_mul cden bden))), rw <- mul_assoc_int_rw aden anum (int_mul cnum (int_mul cden bden)), rw mul_comm_int_rw aden anum, rw mul_assoc_int_rw anum aden (int_mul cnum (int_mul cden bden)), rw <- mul_assoc_int_rw aden cnum (int_mul cden bden), rw mul_comm_int_rw aden cnum, rw mul_assoc_int_rw cnum aden (int_mul cden bden), rw <- mul_assoc_int_rw aden cden bden, rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden bden, rw mul_comm_int_rw aden bden, rw <- mul_assoc_int_rw bden cden (int_mul anum (int_mul cnum (int_mul cden (int_mul bden aden)))), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul anum (int_mul cnum (int_mul cden (int_mul bden aden)))), rw <- mul_assoc_int_rw anum cnum (int_mul cden (int_mul bden aden)), rw mul_comm_int_rw anum cnum, rw mul_assoc_int_rw cnum anum (int_mul cden (int_mul bden aden)), rw <- mul_assoc_int_rw anum cden (int_mul bden aden), rw mul_comm_int_rw anum cden, rw mul_assoc_int_rw cden anum (int_mul bden aden), rw <- mul_assoc_int_rw anum bden aden, rw mul_comm_int_rw anum bden, rw mul_assoc_int_rw bden anum aden, rw <- mul_assoc_int_rw bden cnum (int_mul cden (int_mul bden (int_mul anum aden))), rw mul_comm_int_rw bden cnum, rw mul_assoc_int_rw cnum bden (int_mul cden (int_mul bden (int_mul anum aden))), rw <- mul_assoc_int_rw bden cden (int_mul bden (int_mul anum aden)), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul bden (int_mul anum aden)), rw <- mul_assoc_int_rw cden cnum (int_mul cden (int_mul bden (int_mul bden (int_mul anum aden)))), rw mul_comm_int_rw cden cnum, rw mul_assoc_int_rw cnum cden (int_mul cden (int_mul bden (int_mul bden (int_mul anum aden)))),\n  rw <- mul_assoc_int_rw aden bden (int_mul cden (int_mul bnum (int_mul cnum (int_mul cden aden)))), rw mul_comm_int_rw aden bden, rw mul_assoc_int_rw bden aden (int_mul cden (int_mul bnum (int_mul cnum (int_mul cden aden)))), rw <- mul_assoc_int_rw aden cden (int_mul bnum (int_mul cnum (int_mul cden aden))), rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden (int_mul bnum (int_mul cnum (int_mul cden aden))), rw <- mul_assoc_int_rw aden bnum (int_mul cnum (int_mul cden aden)), rw mul_comm_int_rw aden bnum, rw mul_assoc_int_rw bnum aden (int_mul cnum (int_mul cden aden)), rw <- mul_assoc_int_rw aden cnum (int_mul cden aden), rw mul_comm_int_rw aden cnum, rw mul_assoc_int_rw cnum aden (int_mul cden aden), rw <- mul_assoc_int_rw aden cden aden, rw mul_comm_int_rw aden cden, rw mul_assoc_int_rw cden aden aden, rw <- mul_assoc_int_rw bden cden (int_mul bnum (int_mul cnum (int_mul cden (int_mul aden aden)))), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul bnum (int_mul cnum (int_mul cden (int_mul aden aden)))), rw <- mul_assoc_int_rw bden bnum (int_mul cnum (int_mul cden (int_mul aden aden))), rw mul_comm_int_rw bden bnum, rw mul_assoc_int_rw bnum bden (int_mul cnum (int_mul cden (int_mul aden aden))), rw <- mul_assoc_int_rw bden cnum (int_mul cden (int_mul aden aden)), rw mul_comm_int_rw bden cnum, rw mul_assoc_int_rw cnum bden (int_mul cden (int_mul aden aden)), rw <- mul_assoc_int_rw bden cden (int_mul aden aden), rw mul_comm_int_rw bden cden, rw mul_assoc_int_rw cden bden (int_mul aden aden), rw <- mul_assoc_int_rw bnum cnum (int_mul cden (int_mul bden (int_mul aden aden))), rw mul_comm_int_rw bnum cnum, rw mul_assoc_int_rw cnum bnum (int_mul cden (int_mul bden (int_mul aden aden))), rw <- mul_assoc_int_rw bnum cden (int_mul bden (int_mul aden aden)), rw mul_comm_int_rw bnum cden, rw mul_assoc_int_rw cden bnum (int_mul bden (int_mul aden aden)), rw <- mul_assoc_int_rw cden cnum (int_mul cden (int_mul bnum (int_mul bden (int_mul aden aden)))), rw mul_comm_int_rw cden cnum, rw mul_assoc_int_rw cnum cden (int_mul cden (int_mul bnum (int_mul bden (int_mul aden aden)))),\n  exact int_equal_refl (int_add (int_mul cnum (int_mul cden (int_mul cden (int_mul bden (int_mul bden (int_mul anum aden)))))) (int_mul cnum (int_mul cden (int_mul cden (int_mul bnum (int_mul bden (int_mul aden aden))))))),\nend\n\nlemma rat_mul_distrib_inv (a b c : myrat) : rat_eq (rat_add (rat_mul a c) (rat_mul b c)) (rat_mul (rat_add a b) c) :=\nbegin\n  apply rat_eq_comm _ _, exact rat_mul_distrib a b c,\nend\n\nlemma rat_mul_distrib_alt (a b c : myrat) : rat_eq (rat_mul a (rat_add b c)) (rat_add (rat_mul a b) (rat_mul a c)) :=\nbegin\n  rw rat_mul_comm, rw rat_mul_comm a b, rw rat_mul_comm a c, exact rat_mul_distrib b c a,\nend\n\nlemma rat_one_mul (a b : myrat) : rat_eq a rat_one -> rat_eq (rat_mul a b) b :=\nbegin\n  intros h, exact rat_eq_comm b (rat_mul a b) (rat_mul_one a b h),\nend\n\ndef rat_reciprocal : myrat -> myrat\n| (rat num den) := (rat (int_mul den den) (int_mul num den))\n/- We can't just do (rat den num) because then reciprocal (1/0) is 0/1, so we\n   get a defined value from an undefined value.-/\n\nlemma reciprocal_mul_inv (a : myrat) : rat_eq rat_one (rat_mul a (rat_reciprocal a)) :=\nbegin\n  cases a with anum aden, unfold rat_reciprocal, unfold rat_mul, unfold rat_one, unfold rat_eq,\n  by_cases (iszero aden),\n    right, right, exact mul_zero_int aden (int_mul anum aden) h,\n\n    left, rw mul_comm_int_rw int_one (int_mul aden (int_mul anum aden)),\n    rw mul_comm_int_rw int_one (int_mul anum (int_mul aden aden)),\n    apply (mul_eq_alt int_one (int_mul aden (int_mul anum aden)) (int_mul anum (int_mul aden aden))),\n    rw <- mul_assoc_int_rw anum aden aden,\n    rw mul_comm_int_rw aden (int_mul anum aden),\n    exact int_equal_refl (int_mul (int_mul anum aden) aden),\nend\n\nlemma reciprocal_inv_mul (a : myrat) : rat_eq (rat_mul a (rat_reciprocal a)) rat_one :=\nbegin\n  exact rat_eq_comm rat_one (rat_mul a (rat_reciprocal a)) (reciprocal_mul_inv a),\nend\n\nlemma reciprocal_mul_cancel (a b : myrat) : rat_eq a (rat_mul a (rat_mul b (rat_reciprocal b))) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_reciprocal, unfold rat_mul, unfold rat_eq,\n  left, rw <- mul_assoc_int_rw bden bnum bden, rw mul_comm_int_rw bden bnum, rw mul_assoc_int_rw bnum bden bden,\n  rw <- mul_assoc_int_rw anum aden (int_mul bnum (int_mul bden bden)), rw mul_comm_int_rw anum aden,\n  repeat {rw mul_assoc_int_rw}, exact int_equal_refl _,\nend\n\nlemma reciprocal_def (a : myrat) : (defined a) -> ¬(iszero_rat a) -> (defined (rat_reciprocal a)) :=\nbegin\n  cases a with anum aden, unfold rat_reciprocal, unfold defined, unfold iszero_rat, intros,\n  by_cases h1 : iszero anum,\n    have tmp : iszero anum \\/ iszero aden, left, exact h1,\n    cc,\n  by_cases h2 : iszero aden,\n    have tmp : iszero anum \\/ iszero aden, right, exact h2,\n    cc,\n  exact mul_nonzero_int anum aden h1 h2,\nend\n\nlemma reciprocal_undef_undef (a : myrat) : ¬(defined a) -> ¬(defined (rat_reciprocal a)) :=\nbegin\n  cases a with anum aden, unfold rat_reciprocal, unfold defined, intros,\n  by_cases h1 : (iszero aden),\n    by_cases h2 : ¬(iszero (int_mul anum aden)),\n      have h3 : iszero (int_mul anum aden),\n        exact mul_zero_int_alt aden anum h1,\n      cc,\n      exact h2,\n    cc,\nend\n\nlemma reciprocal_zero_undef (a : myrat) : (iszero_rat a) -> ¬(defined (rat_reciprocal a)) :=\nbegin\n  cases a with anum aden, unfold rat_reciprocal, unfold defined, unfold iszero_rat, intros h,\n  cases h with h,\n  by_cases h1 : ¬(iszero (int_mul anum aden)),\n    have h2 : iszero (int_mul anum aden),\n      exact mul_zero_int anum aden h,\n    cc,\n    cc,\n  have h1 : iszero (int_mul anum aden), exact mul_zero_int_alt aden anum h,\n  cc,\nend\n\nlemma reciprocal_mul_inv_alt (a b : myrat) : rat_eq a (rat_mul (rat_mul a b) (rat_reciprocal b)) :=\nbegin\n  rw rat_mul_assoc, apply rat_eq_comm _ _, rw rat_mul_comm _ _, by_cases h1 : (defined b), by_cases h2 : (iszero_rat b),\n    exact undef_eq (rat_mul (rat_mul b (rat_reciprocal b)) a) a (rat_mul_undef (rat_mul b (rat_reciprocal b)) a (rat_undef_mul b (rat_reciprocal b) (reciprocal_zero_undef b h2))),\n    have tmp : defined (rat_mul b (rat_reciprocal b)),\n       exact rat_mul_def b (rat_reciprocal b) h1 (reciprocal_def b h1 h2),\n    have tmp2 : defined rat_one,\n      unfold rat_one, unfold defined, unfold int_one, unfold iszero, unfold nat_one, cc,\n    apply mul_sub_rat rat_one (rat_mul b (rat_reciprocal b)) a a tmp2 (reciprocal_mul_inv b),\n    rw rat_mul_comm,  rw rat_mul_one_rw, exact rat_eq_refl a,\n\n    exact undef_eq (rat_mul (rat_mul b (rat_reciprocal b)) a) a (rat_mul_undef (rat_mul b (rat_reciprocal b)) a (rat_mul_undef b (rat_reciprocal b) h1)),\nend\n\nlemma reciprocal_eq (a b : myrat) : (rat_eq a b) -> (rat_eq (rat_reciprocal a) (rat_reciprocal b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_reciprocal, unfold rat_eq, intros h, cases h,\n    left, rw mul_comm_int_rw anum aden, repeat {rw mul_assoc_int_rw},\n    apply mul_eq aden (int_mul aden (int_mul bnum bden)) (int_mul anum (int_mul bden bden)),\n    repeat {rw <- mul_assoc_int_rw},\n    apply mul_eq_alt bden (int_mul aden bnum) (int_mul anum bden),\n    exact int_eq_comm _ _ h,\n\n    cases h, right, left, exact mul_zero_int_alt aden anum h,\n             right, right, exact mul_zero_int_alt bden bnum h,\nend\n\n/- We'll need this to cancel the /2a in the quadratic formula.-/\nlemma half_reciprocal_mul (a : myrat) : rat_eq (rat_reciprocal rat_two) (rat_mul a (rat_reciprocal (rat_add a a))) :=\nbegin\n  unfold rat_two, cases a with num den, unfold rat_add, unfold rat_reciprocal, unfold rat_mul, unfold rat_eq, left,\n  unfold int_one, unfold int_mul, unfold mymul, unfold myadd, unfold nat_one, unfold mymul, unfold myadd,\n  rw <- mul_two_int, rw mul_one_int_rw_alt,\n  repeat {rw mul_assoc_int_rw},\n  rw <- mul_assoc_int_rw den (int zero.mysucc.mysucc zero) (int_mul num (int_mul den (int_mul den den))),\n  rw mul_comm_int_rw den (int zero.mysucc.mysucc zero),\n  repeat {rw mul_assoc_int_rw},\n  rw <- mul_assoc_int_rw den num (int_mul den (int_mul den den)),\n  rw mul_comm_int_rw den num, repeat {rw mul_assoc_int_rw},\n  exact int_equal_refl _,\nend\n\ndef negate_rat : myrat -> myrat\n| (rat num den) := (rat (negative num) den)\n\nlemma negate_def (a : myrat) : (defined a) -> (defined (negate_rat a)) :=\nbegin\n  cases a with anum aden, unfold negate_rat, unfold defined, cc,\nend\n\nlemma negate_undef (a : myrat) : ¬(defined a) -> ¬(defined (negate_rat a)) :=\nbegin\n  cases a with anum aden, unfold negate_rat, unfold defined, cc,\nend\n\nlemma negate_eq_rat (a b : myrat) : (rat_eq a b) -> (rat_eq (negate_rat a) (negate_rat b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold negate_rat, unfold rat_eq, intros h, cases h, left,\n    rw mul_comm_int_rw (negative anum) bden, repeat {rw mul_negative},\n    rw mul_comm_int_rw bden anum, exact negative_eq (int_mul anum bden) (int_mul aden bnum) h,\n\n    cc,\nend\n\nlemma double_negate (a : myrat) : (negate_rat (negate_rat a)) = a :=\nbegin\n  cases a with anum aden, unfold negate_rat, cases anum with aplus aminus, unfold negative,\nend\n\nlemma mul_negate (a b : myrat) : rat_eq (rat_mul a (negate_rat b)) (negate_rat (rat_mul a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_mul, unfold negate_rat,\n  rw <- mul_negative anum bnum,\n  unfold rat_mul,\n  exact rat_eq_refl (rat (int_mul anum (negative bnum)) (int_mul aden bden)),\nend\n\nlemma mul_negate_rw (a b : myrat) : (rat_mul a (negate_rat b)) = (negate_rat (rat_mul a b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_mul, unfold negate_rat,\n  rw <- mul_negative anum bnum,\n  unfold rat_mul,\nend\n\nlemma mul_negate_alt_rw (a b : myrat) : (rat_mul (negate_rat a) b) = (rat_mul a (negate_rat b)) :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold negate_rat, unfold rat_mul,\n  rw mul_negative_alt anum bnum,\nend\n\nlemma add_negate_rat (a : myrat) : rat_eq (rat_add a (negate_rat a)) rat_zero :=\nbegin\n  cases a with anum aden, unfold negate_rat, unfold rat_zero, unfold rat_add, unfold rat_eq,\n  left, rw mul_one_int_rw, rw mul_comm_int_rw (negative anum) aden, rw mul_negative aden anum,\n  have h1 : int_equal int_zero (int_add (int_mul anum aden) (negative (int_mul anum aden))),\n    exact add_to_negative (int_mul anum aden),\n  have h2 : int_equal (int_mul (int_mul aden aden) int_zero) int_zero,\n    exact mul_zero_int_zero (int_mul aden aden),\n  have h3 : int_equal (int_mul (int_mul aden aden) int_zero) (int_add (int_mul anum aden) (negative (int_mul anum aden))),\n    exact int_eq_trans (int_mul (int_mul aden aden) int_zero) int_zero (int_add (int_mul anum aden) (negative (int_mul anum aden))) h2 h1,\n  rw mul_comm_int_rw aden anum,\n  exact int_eq_comm (int_mul (int_mul aden aden) int_zero) (int_add (int_mul anum aden) (negative (int_mul anum aden))) h3,\nend\n\nlemma add_negate_rat_alt (a : myrat) : iszero_rat (rat_add a (negate_rat a)) :=\nbegin\n  cases a with anum aden, unfold negate_rat, unfold rat_add, unfold iszero_rat,\n  rw mul_comm_int_rw (negative anum) aden, rw mul_negative aden anum, rw mul_comm_int_rw anum aden, left,\n  exact add_to_negative_alt (int_mul aden anum),\nend\n\nlemma iszero_mul_rat (a b : myrat) : ¬(iszero_rat b) -> (defined b) -> (iszero_rat (rat_mul a b)) -> iszero_rat a :=\nbegin\n  cases a with anum aden, cases b with bnum bden, unfold rat_mul, unfold iszero_rat, unfold defined, intros h1 h2 h3,\n  by_cases h4 : iszero bnum,\n    cc, cases h3,\n      left, rw mul_comm_int_rw at h3, exact mul_result_zero_int bnum anum h4 h3,\n      right, exact mul_result_zero_int_rev aden bden h2 h3,\nend\n\n/- I don't know if you'd really call it a \"formula\", but the solution to ax + b = 0 is\n    x = -b/a.  We may as well prove that, right?-/\ndef linear_formula : myrat -> myrat -> myrat\n| a b := negate_rat (rat_mul b (rat_reciprocal a))\n\nlemma linear_formula_works (a b : myrat) : rat_eq (rat_add (rat_mul a (linear_formula a b)) b) rat_zero :=\nbegin\n  unfold linear_formula, repeat {rw <- mul_negate_rw},\n  rw <- rat_mul_assoc a b (negate_rat (rat_reciprocal a)),\n  rw rat_mul_comm a b,\n  rw rat_mul_assoc b a (negate_rat (rat_reciprocal a)),\n  rw mul_negate_rw a (rat_reciprocal a),\n  rw <- mul_negate_alt_rw b (rat_mul a (rat_reciprocal a)),\n  have h1 : rat_eq (rat_mul a (rat_reciprocal a)) rat_one,\n    exact rat_eq_comm rat_one (rat_mul a (rat_reciprocal a)) (reciprocal_mul_inv a),\n  by_cases h2 : (defined a),\n    by_cases h3 : (iszero_rat a),\n      have h4 : ¬defined (rat_reciprocal a),\n        exact reciprocal_zero_undef a h3,\n      have h5 : ¬defined (rat_mul a (rat_reciprocal a)),\n        exact rat_undef_mul a (rat_reciprocal a) h4,\n      have h6 : ¬defined (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))),\n        exact rat_undef_mul (negate_rat b) (rat_mul a (rat_reciprocal a)) h5,\n      have h7 : ¬defined (rat_add (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) b),\n        exact rat_add_undef (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) b h6,\n      exact undef_eq (rat_add (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) b) rat_zero h7,\n\n      have h4 : rat_eq (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) (negate_rat b),\n        rw rat_mul_comm (negate_rat b) (rat_mul a (rat_reciprocal a)),\n        exact rat_one_mul (rat_mul a (rat_reciprocal a)) (negate_rat b) h1,\n      have h5 : defined (rat_mul a (rat_reciprocal a)),\n        exact rat_mul_def a (rat_reciprocal a) h2 (reciprocal_def a h2 h3),\n      have h6 : rat_eq (rat_add (negate_rat b) b) rat_zero,\n        rw rat_add_comm, exact add_negate_rat b,\n      have h7 : rat_eq (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) (negate_rat b),\n         rw rat_mul_comm, exact rat_one_mul (rat_mul a (rat_reciprocal a)) (negate_rat b) (reciprocal_inv_mul a),\n      by_cases h8 : (defined b),\n        exact add_sub_rat (negate_rat b) (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) b rat_zero (negate_def b h8) (rat_eq_comm (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) (negate_rat b) h7) h6,\n\n        rw rat_add_comm,\n        exact undef_eq (rat_add b (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a)))) rat_zero (rat_add_undef b (rat_mul (negate_rat b) (rat_mul a (rat_reciprocal a))) h8),\n\n    rw rat_mul_comm (negate_rat b) (rat_mul a (rat_reciprocal a)),\n    exact undef_eq (rat_add (rat_mul (rat_mul a (rat_reciprocal a)) (negate_rat b)) b) rat_zero (rat_add_undef (rat_mul (rat_mul a (rat_reciprocal a)) (negate_rat b)) b (rat_mul_undef (rat_mul a (rat_reciprocal a)) (negate_rat b) (rat_mul_undef a (rat_reciprocal a) h2))),\nend\n\n/- OK.  a + (b * sqrt(c)) is not a field.\n   However, a + (b * sqrt(c)) where c is constant IS a field.\n   Ergo, we need to define a type constructor where c is part of the type.-/\ninductive rat_plus_sqrt (a : myrat) : Type\n| rps : myrat -> myrat -> rat_plus_sqrt\n/- A value (a, b) of type (rat_plus_sqrt c) represents the number a + (b * sqrt(c))\n   This means that operations are only defined when the values inside the square roots are the same.-/\nopen rat_plus_sqrt\n\ndef zero_rps (k : myrat) : rat_plus_sqrt k := (rps rat_zero rat_zero)\n\ndef defined_rps (k : myrat) : rat_plus_sqrt k -> Prop\n| (rps a b) := (defined a) /\\ (defined b) /\\ (defined k)\n\ndef rps_equal (k : myrat) : rat_plus_sqrt k -> rat_plus_sqrt k -> Prop\n| (rps a b) (rps c d) := (rat_eq a c) /\\ (rat_eq b d)\n/- There are some niche scenarios where this could be wrong.\n  E.g. 3 + 0√4 compared to 1 + 1√4 - they are equal as real numbers but not by the above.\n  However, as we are treating roots as black boxes, it simplifies things dramatically to not\n  do those sorts of comparisons, and for the sake of provign the quadratic formula it doesn't matter.-/\n\ndef iszero_rps (k : myrat) : rat_plus_sqrt k -> Prop\n| (rps a b) := (iszero_rat a) /\\ (iszero_rat b)\n/- Technically this is slightly too strict, as for example 6 + (-3)√4 = 0 but is not detected\n    as zero by the above.  However this will do for the purposes of checking the quadratic formula.-/\n\n/- The below definitions cannot be proven to be correct from within Lean, as we are simply defining\n   √k to be the number that gives k when it is multiplied by itself, so Lean knows of no other properties of it.\n   View the comments for an explanation of how each one follows from the field axioms.\n   Therefore the only real assumptions that we are making here is that the square root of a given\n   number exists (which it does if we allow complex numbers) and that the complex numbers are a field.-/\ndef add_rps (k : myrat) : rat_plus_sqrt k -> rat_plus_sqrt k -> rat_plus_sqrt k\n| (rps a b) (rps c d) := (rps (rat_add a c) (rat_add b d))\n/- This is straightforwardly true because addition is associative and commutative.\n    (a + bq) + (c + dq) = (a + c) + bq + dq no matter what properties q might have.\n    And then because multiplication distributes over addition we can write that as (a + c) + (b + d)q-/\n\ndef negate_rps (k : myrat) : rat_plus_sqrt k -> rat_plus_sqrt k\n| (rps a b) := (rps (negate_rat a) (negate_rat b))\n/- Simple.  Multiplication distributes over addition, so multiplying both pats of a sum by -1\n   is equivalent to multiplying the whole thing by -1.-/\n\ndef mul_rps (k : myrat) : rat_plus_sqrt k -> rat_plus_sqrt k -> rat_plus_sqrt k\n| (rps a b) (rps c d) := (rps (rat_add (rat_mul a c) (rat_mul b (rat_mul d k)))\n                              (rat_add (rat_mul a d) (rat_mul b c)))\n/- Multiplication distributes over addition.  Ergo\n      (a + b√k)(c + d√k) = a(c + d√k) + b√k(c + d√k) = ac + ad√k + bc√k + bd√k√k\n   Addition is commutative and associative, so we can rearrange terms...\n      = ac + bd√k√k + ad√k + bc√k\n   And then √k√k = k by definition.\n      = ac + bdk + (ad + bd)√k\n   Ergo the above equation makes no assumptions apart from the field axioms and the definition of a square root.-/\n\ndef add_rps_to_rat (k : myrat) : rat_plus_sqrt k -> myrat -> rat_plus_sqrt k\n| (rps a b) c := (rps (rat_add a c) b)\n/- Trivial by commutativity and associativity of addition.-/\n\ndef mul_rps_by_rat (k : myrat) : rat_plus_sqrt k -> myrat -> rat_plus_sqrt k\n| (rps a b) c := (rps (rat_mul a c) (rat_mul b c))\n/- Again, distribution and commutativity of multiplication.  (a + b√k)c = ac + b(√k)c = ac + bc√k-/\n\ndef sqrt (k : myrat) : rat_plus_sqrt k := (rps rat_zero rat_one)\n/- Follows easily from how we defined the rat_plus_sqrt type.-/\n\nlemma add_zero_rps_alt (k : myrat) (a : rat_plus_sqrt k) : (add_rps k a (zero_rps k)) = a :=\nbegin\n  unfold zero_rps, cases a with rata roota, unfold add_rps, repeat {rw rat_add_zero_alt},\nend\n\nlemma add_comm_rps (k : myrat) (a b : rat_plus_sqrt k) : (add_rps k a b) = (add_rps k b a) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, unfold add_rps,\n  rw rat_add_comm rata ratb, rw rat_add_comm roota rootb,\nend\n\nlemma add_assoc_rps (k : myrat) (a b c : rat_plus_sqrt k) :\n        (add_rps k (add_rps k a b) c) = (add_rps k a (add_rps k b c)) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, cases c with ratc rootc,\n  unfold add_rps, rw rat_add_assoc rata ratb ratc, rw rat_add_assoc roota rootb rootc,\nend\n\nlemma add_zero_rps (k : myrat) (a b : rat_plus_sqrt k) :\n    (iszero_rps k a) -> (rps_equal k (add_rps k a b) b) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb,\n  unfold add_rps, unfold iszero_rps, unfold rps_equal, intros h, cases h with h1 h2, split,\n    exact rat_add_zero rata ratb h1,\n    exact rat_add_zero roota rootb h2,\nend\n\nlemma add_def_rps (k : myrat) (a b : rat_plus_sqrt k) :\n  (defined_rps k a) -> (defined_rps k b) -> (defined_rps k (add_rps k a b)) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, unfold add_rps, unfold defined_rps, intros h1 h2,\n  cases h1 with h11 h12, cases h12 with h12 h13, cases h2 with h21 h22, cases h22 with h22 h23, split,\n  exact rat_add_def rata ratb h11 h21, split,\n  exact rat_add_def roota rootb h12 h22, exact h13,\nend\n\n/- Woo classical logic! -/\nlemma negate_and (a b c : Prop) : ¬(a /\\ b /\\ c) -> (¬a \\/ ¬b \\/ ¬c) :=\nbegin\n  intros h, by_cases ha : a, by_cases hb : b, by_cases hc : c,\n    have h1 : (a /\\ b /\\ c), split, exact ha, split, exact hb, exact hc, cc,\n    right, right, cc,\n    right, left, cc,\n    left, cc,\nend\n\nlemma add_undef_rps (k : myrat) (a b : rat_plus_sqrt k) :\n  ¬(defined_rps k a) -> ¬(defined_rps k (add_rps k a b)) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, unfold add_rps, unfold defined_rps, intros h,\n  have h1 : (¬(defined rata) \\/ ¬(defined roota) \\/ ¬(defined k)),\n    exact negate_and (defined rata) (defined roota) (defined k) h,\n  cases h1,\n    intro h2, cases h2 with h2 _, exact rat_add_undef rata ratb h1 h2,\n    cases h1,\n      intro h2, cases h2 with _ h2, cases h2 with h2 _, exact rat_add_undef roota rootb h1 h2,\n      intro h2, cases h2 with _ h2, cases h2 with _ h2, exact h1 h2,\nend\n\nlemma negate_add_inv_rps (k : myrat) (a : rat_plus_sqrt k) :\n  iszero_rps k (add_rps k a (negate_rps k a)) :=\nbegin\n  cases a with rata roota, unfold negate_rps, unfold add_rps, unfold iszero_rps, split,\n    exact add_negate_rat_alt rata,\n    exact add_negate_rat_alt roota,\nend\n\nlemma mul_comm_rps (k : myrat) (a b : rat_plus_sqrt k) : (mul_rps k a b) = (mul_rps k b a) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, unfold mul_rps,\n  rw <- rat_mul_assoc roota rootb k, rw rat_mul_comm roota rootb, rw rat_mul_assoc rootb roota k,\n  rw rat_add_comm (rat_mul ratb roota) (rat_mul rootb rata),\n  rw rat_mul_comm ratb roota, rw rat_mul_comm rata rootb,\n  rw rat_mul_comm rata ratb,\nend\n\nlemma mul_assoc_rps (k : myrat) (a b c : rat_plus_sqrt k) :\n  rps_equal k (mul_rps k (mul_rps k a b) c) (mul_rps k a (mul_rps k b c)) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, cases c with ratc rootc,\n  unfold mul_rps, unfold rps_equal, split,\n  repeat {rw rat_add_assoc},\n  /- Using python for something a bit different this time.\n     The proof is trivial for all the cases where one of the numbers isn't defined, but we don't\n     want to have to through them all manually.  Much better to leave that bit to the machine.-/\n  by_cases ratc_def_tmp : (¬defined ratc), rw rat_mul_comm (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc, exact undef_eq (rat_add (rat_mul ratc (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)))) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul ratc (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)))) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_undef ratc (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc_def_tmp)), have ratc_defined : (defined ratc), cc, clear ratc_def_tmp, by_cases ratb_def_tmp : (¬defined ratb), rw rat_mul_comm rata ratb, exact undef_eq (rat_add (rat_mul (rat_add (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul (rat_add (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_undef (rat_add (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k))) ratc (rat_add_undef (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k)) (rat_mul_undef ratb rata ratb_def_tmp)))), have ratb_defined : (defined ratb), cc, clear ratb_def_tmp, by_cases rootb_def_tmp : (¬defined rootb), rw rat_add_comm (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)), rw rat_mul_comm roota (rat_mul rootb k), exact undef_eq (rat_add (rat_mul (rat_add (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb)) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul (rat_add (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb)) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_undef (rat_add (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb)) ratc (rat_add_undef (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb) (rat_mul_undef (rat_mul rootb k) roota (rat_mul_undef rootb k rootb_def_tmp))))), have rootb_defined : (defined rootb), cc, clear rootb_def_tmp, by_cases roota_def_tmp : (¬defined roota), rw rat_add_comm (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)), exact undef_eq (rat_add (rat_mul (rat_add (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb)) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul (rat_add (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb)) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_undef (rat_add (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb)) ratc (rat_add_undef (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb) (rat_mul_undef roota (rat_mul rootb k) roota_def_tmp)))), have roota_defined : (defined roota), cc, clear roota_def_tmp, by_cases rata_def_tmp : (¬defined rata), exact undef_eq (rat_add (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_undef (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc (rat_add_undef (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)) (rat_mul_undef rata ratb rata_def_tmp)))), have rata_defined : (defined rata), cc, clear rata_def_tmp, by_cases rootc_def_tmp : (¬defined rootc), rw rat_add_comm (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)), rw rat_mul_comm (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k), exact undef_eq (rat_add (rat_mul (rat_mul rootc k) (rat_add (rat_mul rata rootb) (rat_mul roota ratb))) (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul (rat_mul rootc k) (rat_add (rat_mul rata rootb) (rat_mul roota ratb))) (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul_undef (rat_mul rootc k) (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul_undef rootc k rootc_def_tmp))), have rootc_defined : (defined rootc), cc, clear rootc_def_tmp, by_cases k_def_tmp : (¬defined k), rw rat_add_comm (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)), rw rat_mul_comm roota (rat_mul rootb k), rw rat_mul_comm rootb k, exact undef_eq (rat_add (rat_mul (rat_add (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb)) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_undef (rat_mul (rat_add (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb)) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_undef (rat_add (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb)) ratc (rat_add_undef (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb) (rat_mul_undef (rat_mul k rootb) roota (rat_mul_undef k rootb k_def_tmp))))), have k_defined : (defined k), cc, clear k_def_tmp,\n  /- Basically, we now have hypotheses \"x_defined : defined X\" for every rational number in the proof.-/\n  apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_def (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) ((rat_add_def (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc) ((rat_mul_def (rat_mul rata ratb) ratc ((rat_mul_def rata ratb (rata_defined) (ratb_defined))) (ratc_defined))) ((rat_mul_def (rat_mul roota (rat_mul rootb k)) ratc ((rat_mul_def roota (rat_mul rootb k) (roota_defined) ((rat_mul_def rootb k (rootb_defined) (k_defined))))) (ratc_defined))))) ((rat_mul_def (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k) ((rat_add_def (rat_mul rata rootb) (rat_mul roota ratb) ((rat_mul_def rata rootb (rata_defined) (rootb_defined))) ((rat_mul_def roota ratb (roota_defined) (ratb_defined))))) ((rat_mul_def rootc k (rootc_defined) (k_defined))))))(add_eq_rat (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) ratc) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_mul_distrib (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)) ratc)), rw rat_add_comm (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)), apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k))) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc))) (rat_add (rat_mul rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add_def (rat_add (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k))) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc)) ((rat_add_def (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k)) ((rat_mul_def (rat_mul rata rootb) (rat_mul rootc k) ((rat_mul_def rata rootb (rata_defined) (rootb_defined))) ((rat_mul_def rootc k (rootc_defined) (k_defined))))) ((rat_mul_def (rat_mul roota ratb) (rat_mul rootc k) ((rat_mul_def roota ratb (roota_defined) (ratb_defined))) ((rat_mul_def rootc k (rootc_defined) (k_defined))))))) ((rat_add_def (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc) ((rat_mul_def (rat_mul rata ratb) ratc ((rat_mul_def rata ratb (rata_defined) (ratb_defined))) (ratc_defined))) ((rat_mul_def (rat_mul roota (rat_mul rootb k)) ratc ((rat_mul_def roota (rat_mul rootb k) (roota_defined) ((rat_mul_def rootb k (rootb_defined) (k_defined))))) (ratc_defined))))))(add_eq_rat (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) (rat_mul rootc k)) (rat_add (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k))) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc)) (rat_mul_distrib (rat_mul rata rootb) (rat_mul roota ratb) (rat_mul rootc k))),\n  apply rat_eq_comm _ _, rw rat_mul_comm rata (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))), apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))) rata) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k))) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc))) (rat_add_def (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k)) ((rat_add_def (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata) ((rat_mul_def (rat_mul ratb ratc) rata ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))) (rata_defined))) ((rat_mul_def (rat_mul rootb (rat_mul rootc k)) rata ((rat_mul_def rootb (rat_mul rootc k) (rootb_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))) (rata_defined))))) ((rat_mul_def roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k) (roota_defined) ((rat_mul_def (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k ((rat_add_def (rat_mul ratb rootc) (rat_mul rootb ratc) ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))) ((rat_mul_def rootb ratc (rootb_defined) (ratc_defined))))) (k_defined))))))(add_eq_rat (rat_mul (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))) rata) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) (rat_mul roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k)) (rat_mul_distrib (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)) rata)), rw rat_mul_comm roota (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k), rw rat_add_comm (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) (rat_mul (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k) roota), apply rat_eq_trans (rat_add (rat_mul (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k) roota) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata))) (rat_add (rat_mul (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k))) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc))) (rat_add_def (rat_mul (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) ((rat_mul_def (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota ((rat_add_def (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k) ((rat_mul_def (rat_mul ratb rootc) k ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))) (k_defined))) ((rat_mul_def (rat_mul rootb ratc) k ((rat_mul_def rootb ratc (rootb_defined) (ratc_defined))) (k_defined))))) (roota_defined))) ((rat_add_def (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata) ((rat_mul_def (rat_mul ratb ratc) rata ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))) (rata_defined))) ((rat_mul_def (rat_mul rootb (rat_mul rootc k)) rata ((rat_mul_def rootb (rat_mul rootc k) (rootb_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))) (rata_defined))))))(add_eq_rat (rat_mul (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k) roota) (rat_mul (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) (mul_eq_rat (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) k) (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota (rat_mul_distrib (rat_mul ratb rootc) (rat_mul rootb ratc) k))), apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata))) (rat_add (rat_add (rat_mul (rat_mul (rat_mul ratb rootc) k) roota) (rat_mul (rat_mul (rat_mul rootb ratc) k) roota)) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) (rat_mul rootc k)) (rat_mul (rat_mul roota ratb) (rat_mul rootc k))) (rat_add (rat_mul (rat_mul rata ratb) ratc) (rat_mul (rat_mul roota (rat_mul rootb k)) ratc))) (rat_add_def (rat_add (rat_mul (rat_mul (rat_mul ratb rootc) k) roota) (rat_mul (rat_mul (rat_mul rootb ratc) k) roota)) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) ((rat_add_def (rat_mul (rat_mul (rat_mul ratb rootc) k) roota) (rat_mul (rat_mul (rat_mul rootb ratc) k) roota) ((rat_mul_def (rat_mul (rat_mul ratb rootc) k) roota ((rat_mul_def (rat_mul ratb rootc) k ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))) (k_defined))) (roota_defined))) ((rat_mul_def (rat_mul (rat_mul rootb ratc) k) roota ((rat_mul_def (rat_mul rootb ratc) k ((rat_mul_def rootb ratc (rootb_defined) (ratc_defined))) (k_defined))) (roota_defined))))) ((rat_add_def (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata) ((rat_mul_def (rat_mul ratb ratc) rata ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))) (rata_defined))) ((rat_mul_def (rat_mul rootb (rat_mul rootc k)) rata ((rat_mul_def rootb (rat_mul rootc k) (rootb_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))) (rata_defined))))))(add_eq_rat (rat_mul (rat_add (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k)) roota) (rat_add (rat_mul (rat_mul (rat_mul ratb rootc) k) roota) (rat_mul (rat_mul (rat_mul rootb ratc) k) roota)) (rat_add (rat_mul (rat_mul ratb ratc) rata) (rat_mul (rat_mul rootb (rat_mul rootc k)) rata)) (rat_mul_distrib (rat_mul (rat_mul ratb rootc) k) (rat_mul (rat_mul rootb ratc) k) roota)),\n  /- The above lines do all the distributive rewrites.  This was trivial for ints, but is less trivial for rats.-/\n\n  repeat {rw rat_mul_assoc}, repeat {rw rat_add_assoc},\n  rw <- rat_mul_assoc rootc k roota, rw rat_mul_comm rootc k, rw rat_mul_assoc k rootc roota, rw rat_mul_comm rootc roota, rw <- rat_mul_assoc ratb k (rat_mul roota rootc), rw rat_mul_comm ratb k, rw rat_mul_assoc k ratb (rat_mul roota rootc), rw <- rat_mul_assoc rootb ratc (rat_mul k roota), rw rat_mul_comm rootb ratc, rw rat_mul_assoc ratc rootb (rat_mul k roota), rw <- rat_mul_assoc rootb k roota, rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb roota, rw rat_mul_comm rootb roota, rw <- rat_mul_assoc ratc k (rat_mul roota rootb), rw rat_mul_comm ratc k, rw rat_mul_assoc k ratc (rat_mul roota rootb), rw rat_mul_comm ratc rata, rw <- rat_mul_assoc ratb rata ratc, rw rat_mul_comm ratb rata, rw rat_mul_assoc rata ratb ratc, rw <- rat_mul_assoc rootc k rata, rw rat_mul_comm rootc k, rw rat_mul_assoc k rootc rata, rw rat_mul_comm rootc rata, rw <- rat_mul_assoc rootb k (rat_mul rata rootc), rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb (rat_mul rata rootc), rw <- rat_mul_assoc rootb rata rootc, rw rat_mul_comm rootb rata, rw rat_mul_assoc rata rootb rootc, rw rat_add_comm (rat_add (rat_add (rat_mul k (rat_mul ratb (rat_mul roota rootc))) (rat_mul k (rat_mul ratc (rat_mul roota rootb)))) (rat_mul rata (rat_mul ratb ratc))) (rat_mul k (rat_mul rata (rat_mul rootb rootc))),\n  rw <- rat_mul_assoc rootb k rootc, rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb rootc, rw <- rat_mul_assoc rata k (rat_mul rootb rootc), rw rat_mul_comm rata k, rw rat_mul_assoc k rata (rat_mul rootb rootc), rw <- rat_mul_assoc roota ratb (rat_mul k rootc), rw rat_mul_comm roota ratb, rw rat_mul_assoc ratb roota (rat_mul k rootc), rw <- rat_mul_assoc roota k rootc, rw rat_mul_comm roota k, rw rat_mul_assoc k roota rootc, rw <- rat_mul_assoc ratb k (rat_mul roota rootc), rw rat_mul_comm ratb k, rw rat_mul_assoc k ratb (rat_mul roota rootc), rw <- rat_mul_assoc rootb k ratc, rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb ratc, rw rat_mul_comm rootb ratc, rw <- rat_mul_assoc roota k (rat_mul ratc rootb), rw rat_mul_comm roota k, rw rat_mul_assoc k roota (rat_mul ratc rootb), rw <- rat_mul_assoc roota ratc rootb, rw rat_mul_comm roota ratc, rw rat_mul_assoc ratc roota rootb,\n  repeat {rw <- rat_add_assoc}, rw rat_add_comm (rat_mul rata (rat_mul ratb ratc)) (rat_mul k (rat_mul ratc (rat_mul roota rootb))),\n  exact rat_eq_refl _,\n\n\n  by_cases k_def_tmp : (¬defined k), rw rat_add_comm (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)), rw rat_mul_comm roota (rat_mul rootb k), rw rat_mul_comm rootb k, exact undef_eq (rat_add (rat_mul (rat_add (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb)) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul (rat_add (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb)) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_undef (rat_add (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb)) rootc (rat_add_undef (rat_mul (rat_mul k rootb) roota) (rat_mul rata ratb) (rat_mul_undef (rat_mul k rootb) roota (rat_mul_undef k rootb k_def_tmp))))), have k_defined : (defined k), cc, clear k_def_tmp, by_cases rootb_def_tmp : (¬defined rootb), rw rat_add_comm (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)), rw rat_mul_comm roota (rat_mul rootb k), exact undef_eq (rat_add (rat_mul (rat_add (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb)) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul (rat_add (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb)) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_undef (rat_add (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb)) rootc (rat_add_undef (rat_mul (rat_mul rootb k) roota) (rat_mul rata ratb) (rat_mul_undef (rat_mul rootb k) roota (rat_mul_undef rootb k rootb_def_tmp))))), have rootb_defined : (defined rootb), cc, clear rootb_def_tmp, by_cases rootc_def_tmp : (¬defined rootc), rw rat_mul_comm (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc, exact undef_eq (rat_add (rat_mul rootc (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)))) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul rootc (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)))) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_undef rootc (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc_def_tmp)), have rootc_defined : (defined rootc), cc, clear rootc_def_tmp, by_cases roota_def_tmp : (¬defined roota), rw rat_add_comm (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)), exact undef_eq (rat_add (rat_mul (rat_add (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb)) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul (rat_add (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb)) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_undef (rat_add (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb)) rootc (rat_add_undef (rat_mul roota (rat_mul rootb k)) (rat_mul rata ratb) (rat_mul_undef roota (rat_mul rootb k) roota_def_tmp)))), have roota_defined : (defined roota), cc, clear roota_def_tmp, by_cases ratc_def_tmp : (¬defined ratc), rw rat_add_comm (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc), rw rat_mul_comm (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc, exact undef_eq (rat_add (rat_mul ratc (rat_add (rat_mul rata rootb) (rat_mul roota ratb))) (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul ratc (rat_add (rat_mul rata rootb) (rat_mul roota ratb))) (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul_undef ratc (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc_def_tmp)), have ratc_defined : (defined ratc), cc, clear ratc_def_tmp, by_cases rata_def_tmp : (¬defined rata), exact undef_eq (rat_add (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_undef (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc (rat_add_undef (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)) (rat_mul_undef rata ratb rata_def_tmp)))), have rata_defined : (defined rata), cc, clear rata_def_tmp, by_cases ratb_def_tmp : (¬defined ratb), rw rat_mul_comm rata ratb, exact undef_eq (rat_add (rat_mul (rat_add (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_undef (rat_mul (rat_add (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_undef (rat_add (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k))) rootc (rat_add_undef (rat_mul ratb rata) (rat_mul roota (rat_mul rootb k)) (rat_mul_undef ratb rata ratb_def_tmp)))), have ratb_defined : (defined ratb), cc, clear ratb_def_tmp,\n  apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc)) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_def (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) ((rat_add_def (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc) ((rat_mul_def (rat_mul rata ratb) rootc ((rat_mul_def rata ratb (rata_defined) (ratb_defined))) (rootc_defined))) ((rat_mul_def (rat_mul roota (rat_mul rootb k)) rootc ((rat_mul_def roota (rat_mul rootb k) (roota_defined) ((rat_mul_def rootb k (rootb_defined) (k_defined))))) (rootc_defined))))) ((rat_mul_def (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc ((rat_add_def (rat_mul rata rootb) (rat_mul roota ratb) ((rat_mul_def rata rootb (rata_defined) (rootb_defined))) ((rat_mul_def roota ratb (roota_defined) (ratb_defined))))) (ratc_defined))))(add_eq_rat (rat_mul (rat_add (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k))) rootc) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_mul_distrib (rat_mul rata ratb) (rat_mul roota (rat_mul rootb k)) rootc)), rw rat_add_comm (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc)) (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc), apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) ratc) (rat_mul (rat_mul roota ratb) ratc)) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc))) (rat_add (rat_mul rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc))) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add_def (rat_add (rat_mul (rat_mul rata rootb) ratc) (rat_mul (rat_mul roota ratb) ratc)) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc)) ((rat_add_def (rat_mul (rat_mul rata rootb) ratc) (rat_mul (rat_mul roota ratb) ratc) ((rat_mul_def (rat_mul rata rootb) ratc ((rat_mul_def rata rootb (rata_defined) (rootb_defined))) (ratc_defined))) ((rat_mul_def (rat_mul roota ratb) ratc ((rat_mul_def roota ratb (roota_defined) (ratb_defined))) (ratc_defined))))) ((rat_add_def (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc) ((rat_mul_def (rat_mul rata ratb) rootc ((rat_mul_def rata ratb (rata_defined) (ratb_defined))) (rootc_defined))) ((rat_mul_def (rat_mul roota (rat_mul rootb k)) rootc ((rat_mul_def roota (rat_mul rootb k) (roota_defined) ((rat_mul_def rootb k (rootb_defined) (k_defined))))) (rootc_defined))))))(add_eq_rat (rat_mul (rat_add (rat_mul rata rootb) (rat_mul roota ratb)) ratc) (rat_add (rat_mul (rat_mul rata rootb) ratc) (rat_mul (rat_mul roota ratb) ratc)) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc)) (rat_mul_distrib (rat_mul rata rootb) (rat_mul roota ratb) ratc)),\n  apply rat_eq_comm _ _, rw rat_mul_comm rata (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)), apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) rata) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata)) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) ratc) (rat_mul (rat_mul roota ratb) ratc)) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc))) (rat_add_def (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata)) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) ((rat_add_def (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata) ((rat_mul_def (rat_mul ratb rootc) rata ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))) (rata_defined))) ((rat_mul_def (rat_mul rootb ratc) rata ((rat_mul_def rootb ratc (rootb_defined) (ratc_defined))) (rata_defined))))) ((rat_mul_def roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))) (roota_defined) ((rat_add_def (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)) ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))) ((rat_mul_def rootb (rat_mul rootc k) (rootb_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))))))))(add_eq_rat (rat_mul (rat_add (rat_mul ratb rootc) (rat_mul rootb ratc)) rata) (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata)) (rat_mul roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_mul_distrib (rat_mul ratb rootc) (rat_mul rootb ratc) rata)), rw rat_mul_comm roota (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))), rw rat_add_comm (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata)) (rat_mul (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))) roota), apply rat_eq_trans (rat_add (rat_mul (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))) roota) (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata))) (rat_add (rat_add (rat_mul (rat_mul ratb ratc) roota) (rat_mul (rat_mul rootb (rat_mul rootc k)) roota)) (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata))) (rat_add (rat_add (rat_mul (rat_mul rata rootb) ratc) (rat_mul (rat_mul roota ratb) ratc)) (rat_add (rat_mul (rat_mul rata ratb) rootc) (rat_mul (rat_mul roota (rat_mul rootb k)) rootc))) (rat_add_def (rat_add (rat_mul (rat_mul ratb ratc) roota) (rat_mul (rat_mul rootb (rat_mul rootc k)) roota)) (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata)) ((rat_add_def (rat_mul (rat_mul ratb ratc) roota) (rat_mul (rat_mul rootb (rat_mul rootc k)) roota) ((rat_mul_def (rat_mul ratb ratc) roota ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))) (roota_defined))) ((rat_mul_def (rat_mul rootb (rat_mul rootc k)) roota ((rat_mul_def rootb (rat_mul rootc k) (rootb_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))) (roota_defined))))) ((rat_add_def (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata) ((rat_mul_def (rat_mul ratb rootc) rata ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))) (rata_defined))) ((rat_mul_def (rat_mul rootb ratc) rata ((rat_mul_def rootb ratc (rootb_defined) (ratc_defined))) (rata_defined))))))(add_eq_rat (rat_mul (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k))) roota) (rat_add (rat_mul (rat_mul ratb ratc) roota) (rat_mul (rat_mul rootb (rat_mul rootc k)) roota)) (rat_add (rat_mul (rat_mul ratb rootc) rata) (rat_mul (rat_mul rootb ratc) rata)) (rat_mul_distrib (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)) roota)),\n\n  repeat {rw rat_mul_assoc}, repeat {rw rat_add_assoc},\n  rw <- rat_mul_assoc rootc k roota, rw rat_mul_comm rootc k, rw rat_mul_assoc k rootc roota, rw rat_mul_comm rootc roota, rw <- rat_mul_assoc rootb k (rat_mul roota rootc), rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb (rat_mul roota rootc), rw <- rat_mul_assoc rootb roota rootc, rw rat_mul_comm rootb roota, rw rat_mul_assoc roota rootb rootc, rw rat_add_comm (rat_mul ratb (rat_mul ratc roota)) (rat_mul k (rat_mul roota (rat_mul rootb rootc))), rw rat_mul_comm rootc rata, rw <- rat_mul_assoc ratb rata rootc, rw rat_mul_comm ratb rata, rw rat_mul_assoc rata ratb rootc, rw <- rat_mul_assoc rootb ratc rata, rw rat_mul_comm rootb ratc, rw rat_mul_assoc ratc rootb rata, rw rat_mul_comm rootb rata, rw <- rat_mul_assoc ratc rata rootb, rw rat_mul_comm ratc rata, rw rat_mul_assoc rata ratc rootb,\n  apply rat_eq_comm _ _, rw <- rat_mul_assoc roota ratb ratc, rw rat_mul_comm roota ratb, rw rat_mul_assoc ratb roota ratc, rw rat_mul_comm roota ratc, rw rat_add_comm (rat_add (rat_mul rata (rat_mul ratc rootb)) (rat_mul ratb (rat_mul ratc roota))) (rat_mul rata (rat_mul ratb rootc)), rw <- rat_mul_assoc rootb k rootc, rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb rootc, rw <- rat_mul_assoc roota k (rat_mul rootb rootc), rw rat_mul_comm roota k, rw rat_mul_assoc k roota (rat_mul rootb rootc), rw rat_add_comm (rat_add (rat_mul rata (rat_mul ratb rootc)) (rat_add (rat_mul rata (rat_mul ratc rootb)) (rat_mul ratb (rat_mul ratc roota)))) (rat_mul k (rat_mul roota (rat_mul rootb rootc))),\n  rw rat_add_comm (rat_mul rata (rat_mul ratc rootb)) (rat_mul ratb (rat_mul ratc roota)),\n  repeat {rw <- rat_add_assoc}, rw rat_add_assoc (rat_mul ratb (rat_mul ratc roota)) (rat_mul rata (rat_mul ratb rootc)) (rat_mul rata (rat_mul ratc rootb)),\n  rw rat_add_comm (rat_mul ratb (rat_mul ratc roota)) (rat_mul rata (rat_mul ratb rootc)),\n  repeat {rw rat_add_assoc}, exact rat_eq_refl _,\nend\n\nlemma mul_distrib_rps (k : myrat) (a b c : rat_plus_sqrt k) :\n            rps_equal k (mul_rps k (add_rps k a b) c) (add_rps k (mul_rps k a c) (mul_rps k b c)) :=\nbegin\n  cases a with rata roota, cases b with ratb rootb, cases c with ratc rootc,\n  unfold add_rps, unfold mul_rps, unfold add_rps, unfold rps_equal, split,\n    by_cases roota_def_tmp : (¬defined roota), rw rat_add_comm (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k)), exact undef_eq (rat_add (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_mul (rat_add rata ratb) ratc)) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_undef (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_mul (rat_add rata ratb) ratc) (rat_mul_undef (rat_add roota rootb) (rat_mul rootc k) (rat_add_undef roota rootb roota_def_tmp))), have roota_defined : (defined roota), cc, clear roota_def_tmp, by_cases ratb_def_tmp : (¬defined ratb), rw rat_add_comm rata ratb, exact undef_eq (rat_add (rat_mul (rat_add ratb rata) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k))) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_undef (rat_mul (rat_add ratb rata) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_mul_undef (rat_add ratb rata) ratc (rat_add_undef ratb rata ratb_def_tmp))), have ratb_defined : (defined ratb), cc, clear ratb_def_tmp, by_cases rata_def_tmp : (¬defined rata), exact undef_eq (rat_add (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k))) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_undef (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_mul_undef (rat_add rata ratb) ratc (rat_add_undef rata ratb rata_def_tmp))), have rata_defined : (defined rata), cc, clear rata_def_tmp, by_cases ratc_def_tmp : (¬defined ratc), rw rat_mul_comm (rat_add rata ratb) ratc, exact undef_eq (rat_add (rat_mul ratc (rat_add rata ratb)) (rat_mul (rat_add roota rootb) (rat_mul rootc k))) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_undef (rat_mul ratc (rat_add rata ratb)) (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_mul_undef ratc (rat_add rata ratb) ratc_def_tmp)), have ratc_defined : (defined ratc), cc, clear ratc_def_tmp, by_cases rootc_def_tmp : (¬defined rootc), rw rat_add_comm (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k)), rw rat_mul_comm (rat_add roota rootb) (rat_mul rootc k), exact undef_eq (rat_add (rat_mul (rat_mul rootc k) (rat_add roota rootb)) (rat_mul (rat_add rata ratb) ratc)) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_undef (rat_mul (rat_mul rootc k) (rat_add roota rootb)) (rat_mul (rat_add rata ratb) ratc) (rat_mul_undef (rat_mul rootc k) (rat_add roota rootb) (rat_mul_undef rootc k rootc_def_tmp))), have rootc_defined : (defined rootc), cc, clear rootc_def_tmp, by_cases rootb_def_tmp : (¬defined rootb), rw rat_add_comm (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k)), rw rat_add_comm roota rootb, exact undef_eq (rat_add (rat_mul (rat_add rootb roota) (rat_mul rootc k)) (rat_mul (rat_add rata ratb) ratc)) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_undef (rat_mul (rat_add rootb roota) (rat_mul rootc k)) (rat_mul (rat_add rata ratb) ratc) (rat_mul_undef (rat_add rootb roota) (rat_mul rootc k) (rat_add_undef rootb roota rootb_def_tmp))), have rootb_defined : (defined rootb), cc, clear rootb_def_tmp, by_cases k_def_tmp : (¬defined k), rw rat_add_comm (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k)), rw rat_mul_comm (rat_add roota rootb) (rat_mul rootc k), rw rat_mul_comm rootc k, exact undef_eq (rat_add (rat_mul (rat_mul k rootc) (rat_add roota rootb)) (rat_mul (rat_add rata ratb) ratc)) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul k rootc))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul k rootc)))) (rat_add_undef (rat_mul (rat_mul k rootc) (rat_add roota rootb)) (rat_mul (rat_add rata ratb) ratc) (rat_mul_undef (rat_mul k rootc) (rat_add roota rootb) (rat_mul_undef k rootc k_def_tmp))), have k_defined : (defined k), cc, clear k_def_tmp,\n    apply rat_eq_trans (rat_add (rat_mul (rat_add rata ratb) ratc) (rat_mul (rat_add roota rootb) (rat_mul rootc k))) (rat_add (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)) (rat_mul (rat_add roota rootb) (rat_mul rootc k))) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_def (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)) (rat_mul (rat_add roota rootb) (rat_mul rootc k)) ((rat_add_def (rat_mul rata ratc) (rat_mul ratb ratc) ((rat_mul_def rata ratc (rata_defined) (ratc_defined))) ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))))) ((rat_mul_def (rat_add roota rootb) (rat_mul rootc k) ((rat_add_def roota rootb (roota_defined) (rootb_defined))) ((rat_mul_def rootc k (rootc_defined) (k_defined))))))(add_eq_rat (rat_mul (rat_add rata ratb) ratc) (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)) (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_mul_distrib rata ratb ratc)), rw rat_add_comm (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)) (rat_mul (rat_add roota rootb) (rat_mul rootc k)), apply rat_eq_trans (rat_add (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_add (rat_mul rata ratc) (rat_mul ratb ratc))) (rat_add (rat_add (rat_mul roota (rat_mul rootc k)) (rat_mul rootb (rat_mul rootc k))) (rat_add (rat_mul rata ratc) (rat_mul ratb ratc))) (rat_add (rat_add (rat_mul rata ratc) (rat_mul roota (rat_mul rootc k))) (rat_add (rat_mul ratb ratc) (rat_mul rootb (rat_mul rootc k)))) (rat_add_def (rat_add (rat_mul roota (rat_mul rootc k)) (rat_mul rootb (rat_mul rootc k))) (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)) ((rat_add_def (rat_mul roota (rat_mul rootc k)) (rat_mul rootb (rat_mul rootc k)) ((rat_mul_def roota (rat_mul rootc k) (roota_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))) ((rat_mul_def rootb (rat_mul rootc k) (rootb_defined) ((rat_mul_def rootc k (rootc_defined) (k_defined))))))) ((rat_add_def (rat_mul rata ratc) (rat_mul ratb ratc) ((rat_mul_def rata ratc (rata_defined) (ratc_defined))) ((rat_mul_def ratb ratc (ratb_defined) (ratc_defined))))))(add_eq_rat (rat_mul (rat_add roota rootb) (rat_mul rootc k)) (rat_add (rat_mul roota (rat_mul rootc k)) (rat_mul rootb (rat_mul rootc k))) (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)) (rat_mul_distrib roota rootb (rat_mul rootc k))),\n    repeat {rw rat_mul_assoc}, repeat {rw rat_add_assoc},\n    rw rat_mul_comm rootc k, rw <- rat_mul_assoc roota k rootc, rw rat_mul_comm roota k, rw rat_mul_assoc k roota rootc,  rw <- rat_mul_assoc rootb k rootc, rw rat_mul_comm rootb k, rw rat_mul_assoc k rootb rootc,\n    repeat {rw rat_mul_assoc}, repeat {rw <- rat_add_assoc},\n    rw rat_add_comm (rat_mul k (rat_mul rootb rootc)) (rat_add (rat_mul rata ratc) (rat_mul ratb ratc)),\n    repeat {rw rat_add_assoc}, rw rat_add_comm (rat_mul k (rat_mul roota rootc)) (rat_mul rata ratc),\n    exact rat_eq_refl _,\n\n    by_cases rootb_def_tmp : (¬defined rootb), rw rat_add_comm (rat_mul (rat_add rata ratb) rootc) (rat_mul (rat_add roota rootb) ratc), rw rat_add_comm roota rootb, exact undef_eq (rat_add (rat_mul (rat_add rootb roota) ratc) (rat_mul (rat_add rata ratb) rootc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_undef (rat_mul (rat_add rootb roota) ratc) (rat_mul (rat_add rata ratb) rootc) (rat_mul_undef (rat_add rootb roota) ratc (rat_add_undef rootb roota rootb_def_tmp))), have rootb_defined : (defined rootb), cc, clear rootb_def_tmp, by_cases rootc_def_tmp : (¬defined rootc), rw rat_mul_comm (rat_add rata ratb) rootc, exact undef_eq (rat_add (rat_mul rootc (rat_add rata ratb)) (rat_mul (rat_add roota rootb) ratc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_undef (rat_mul rootc (rat_add rata ratb)) (rat_mul (rat_add roota rootb) ratc) (rat_mul_undef rootc (rat_add rata ratb) rootc_def_tmp)), have rootc_defined : (defined rootc), cc, clear rootc_def_tmp, by_cases ratc_def_tmp : (¬defined ratc), rw rat_add_comm (rat_mul (rat_add rata ratb) rootc) (rat_mul (rat_add roota rootb) ratc), rw rat_mul_comm (rat_add roota rootb) ratc, exact undef_eq (rat_add (rat_mul ratc (rat_add roota rootb)) (rat_mul (rat_add rata ratb) rootc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_undef (rat_mul ratc (rat_add roota rootb)) (rat_mul (rat_add rata ratb) rootc) (rat_mul_undef ratc (rat_add roota rootb) ratc_def_tmp)), have ratc_defined : (defined ratc), cc, clear ratc_def_tmp, by_cases rata_def_tmp : (¬defined rata), exact undef_eq (rat_add (rat_mul (rat_add rata ratb) rootc) (rat_mul (rat_add roota rootb) ratc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_undef (rat_mul (rat_add rata ratb) rootc) (rat_mul (rat_add roota rootb) ratc) (rat_mul_undef (rat_add rata ratb) rootc (rat_add_undef rata ratb rata_def_tmp))), have rata_defined : (defined rata), cc, clear rata_def_tmp, by_cases ratb_def_tmp : (¬defined ratb), rw rat_add_comm rata ratb, exact undef_eq (rat_add (rat_mul (rat_add ratb rata) rootc) (rat_mul (rat_add roota rootb) ratc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_undef (rat_mul (rat_add ratb rata) rootc) (rat_mul (rat_add roota rootb) ratc) (rat_mul_undef (rat_add ratb rata) rootc (rat_add_undef ratb rata ratb_def_tmp))), have ratb_defined : (defined ratb), cc, clear ratb_def_tmp, by_cases roota_def_tmp : (¬defined roota), rw rat_add_comm (rat_mul (rat_add rata ratb) rootc) (rat_mul (rat_add roota rootb) ratc), exact undef_eq (rat_add (rat_mul (rat_add roota rootb) ratc) (rat_mul (rat_add rata ratb) rootc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_undef (rat_mul (rat_add roota rootb) ratc) (rat_mul (rat_add rata ratb) rootc) (rat_mul_undef (rat_add roota rootb) ratc (rat_add_undef roota rootb roota_def_tmp))), have roota_defined : (defined roota), cc, clear roota_def_tmp,\n    apply rat_eq_trans (rat_add (rat_mul (rat_add rata ratb) rootc) (rat_mul (rat_add roota rootb) ratc)) (rat_add (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)) (rat_mul (rat_add roota rootb) ratc)) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_def (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)) (rat_mul (rat_add roota rootb) ratc) ((rat_add_def (rat_mul rata rootc) (rat_mul ratb rootc) ((rat_mul_def rata rootc (rata_defined) (rootc_defined))) ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))))) ((rat_mul_def (rat_add roota rootb) ratc ((rat_add_def roota rootb (roota_defined) (rootb_defined))) (ratc_defined))))(add_eq_rat (rat_mul (rat_add rata ratb) rootc) (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)) (rat_mul (rat_add roota rootb) ratc) (rat_mul_distrib rata ratb rootc)), rw rat_add_comm (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)) (rat_mul (rat_add roota rootb) ratc), apply rat_eq_trans (rat_add (rat_mul (rat_add roota rootb) ratc) (rat_add (rat_mul rata rootc) (rat_mul ratb rootc))) (rat_add (rat_add (rat_mul roota ratc) (rat_mul rootb ratc)) (rat_add (rat_mul rata rootc) (rat_mul ratb rootc))) (rat_add (rat_add (rat_add (rat_mul rata rootc) (rat_mul roota ratc)) (rat_mul ratb rootc)) (rat_mul rootb ratc)) (rat_add_def (rat_add (rat_mul roota ratc) (rat_mul rootb ratc)) (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)) ((rat_add_def (rat_mul roota ratc) (rat_mul rootb ratc) ((rat_mul_def roota ratc (roota_defined) (ratc_defined))) ((rat_mul_def rootb ratc (rootb_defined) (ratc_defined))))) ((rat_add_def (rat_mul rata rootc) (rat_mul ratb rootc) ((rat_mul_def rata rootc (rata_defined) (rootc_defined))) ((rat_mul_def ratb rootc (ratb_defined) (rootc_defined))))))(add_eq_rat (rat_mul (rat_add roota rootb) ratc) (rat_add (rat_mul roota ratc) (rat_mul rootb ratc)) (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)) (rat_mul_distrib roota rootb ratc)),\n    repeat {rw <- rat_add_assoc}, rw rat_add_comm (rat_mul rootb ratc) (rat_add (rat_mul rata rootc) (rat_mul ratb rootc)),\n    repeat {rw rat_add_assoc}, rw rat_add_comm (rat_mul roota ratc) (rat_mul rata rootc),\n    exact rat_eq_refl _,\nend\n\n/- TODO: Prove that multipliplying an rps by a rat still works as a multiplication by the field axioms.-/\n\ndef rat_four : myrat := (rat (int zero.mysucc.mysucc.mysucc.mysucc zero) (int zero.mysucc zero))\n\n/- b^2 - 4ac -/\ndef discriminant : myrat -> myrat -> myrat -> myrat\n| a b c := (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))\n\n/- As this is of type (rat_plus_sqrt (discriminant a b c)) then it represents a number of the form\n      x + y * sqrt (discriminant)\n      The various occurrences of (discriminant a b c) make the formula more difficult to read, so a\n      clearer presentaion would be\n      mul_rps_by_rat (add_rps_to_rat (sqrt (discriminant) - b)) (reciprocal (a + a)\n      Which is hopefully fairly obviously the well-known quadratic formula.-/\ndef quadratic_formula (a b c : myrat) : (rat_plus_sqrt (discriminant a b c)) :=\n    mul_rps_by_rat (discriminant a b c)\n      (add_rps_to_rat (discriminant a b c) (sqrt (discriminant a b c)) (negate_rat b))\n      (rat_reciprocal (rat_add a a))\n\n/- rat_plus_sqrt is a dependent type that takes a rat as argument.  -/\n/- a + (b * sqrt(c)) is represented by the value (a,b) of type (rat_plus_sqrt c)-/\n\ndef quadratic_subst (k : myrat) : myrat -> myrat -> myrat -> (rat_plus_sqrt k) -> (rat_plus_sqrt k)\n| a b c x := add_rps_to_rat k (add_rps k (mul_rps_by_rat k (mul_rps k x x) a) (mul_rps_by_rat k x b)) c\n\nlemma half_defined : defined (rat_reciprocal rat_two) :=\nbegin\n  unfold rat_two, unfold rat_reciprocal, unfold defined,\n  apply mul_nonzero_int (int zero.mysucc.mysucc zero) int_one, unfold iszero, cc, unfold int_one,\n  unfold nat_one, unfold iszero, cc,\nend\n\nlemma rat_two_defined : defined (rat_two) :=\nbegin\n  unfold rat_two, unfold defined, unfold int_one, unfold iszero, unfold nat_one, cc,\nend\n\nlemma four_divided_by_two : rat_eq (rat_mul rat_four (rat_reciprocal rat_two)) rat_two :=\nbegin\n  unfold rat_two, unfold rat_four, unfold rat_reciprocal, unfold rat_mul, unfold rat_eq, left,\n  unfold int_one, unfold int_mul, unfold nat_one, repeat {unfold mymul}, repeat {rw zero_add}, repeat {rw add_zero},\n  unfold mymul, unfold myadd, exact int_equal_refl _,\nend\n\nlemma add_two_halves (a : myrat) : rat_eq a (rat_add\n                                                (rat_mul a (rat_reciprocal rat_two))\n                                                (rat_mul a (rat_reciprocal rat_two))) :=\nbegin\n  cases a with num den, unfold rat_two, unfold rat_reciprocal, unfold rat_mul,\n  repeat {rw mul_one_int_rw},\n  unfold rat_add, unfold rat_eq, left,\n  rw mul_comm_int_rw den (int zero.mysucc.mysucc zero), rw mul_two_int den,\n  repeat {rw mul_distrib_int_rw_alt}, repeat {rw mul_distrib_int_rw}, repeat {rw mul_distrib_int_rw_alt}, repeat {rw mul_distrib_int_rw},\n  repeat {rw <- mul_assoc_int_rw den num den}, repeat {rw mul_comm_int_rw den num},\n  repeat {rw mul_assoc_int_rw num den den}, repeat {rw add_assoc_int_rw},\n  exact int_equal_refl _,\nend\n\nlemma mul_two_rat (a : myrat) : rat_eq (rat_mul a rat_two) (rat_add a a) :=\nbegin\n  cases a with num den, unfold rat_two, unfold rat_mul,\n  rw mul_comm_int_rw num (int zero.mysucc.mysucc zero), rw mul_two_int,\n  unfold rat_add, unfold rat_eq, left, rw mul_one_int_rw, rw mul_distrib_int_rw,\n  rw mul_comm_int_rw den (int_add (int_mul num den) (int_mul num den)), rw mul_distrib_int_rw,\n  repeat {rw <- mul_assoc_int_rw}, exact int_equal_refl _,\nend\n\nlemma rat_zero_defined : defined (rat_zero) :=\nbegin\n  unfold rat_zero, unfold defined, unfold int_one, unfold iszero, unfold nat_one, cc,\nend\n\nlemma quadratic_formula_works (a b c : myrat) :\n  iszero_rps (discriminant a b c) (quadratic_subst (discriminant a b c) a b c (quadratic_formula a b c)) :=\nbegin\n  /- As I have the intention of using a different approach for the cubic and quartic proofs, this\n    is probably the swan-song of the python-generated code.  But Python is going to go out with\n    a bang, I promise. ;-)\n    -/\n  unfold quadratic_subst, unfold quadratic_formula,\n  unfold sqrt, unfold add_rps_to_rat,\n  rw rat_add_comm rat_zero (negate_rat b), rw rat_add_zero_alt (negate_rat b),\n  unfold mul_rps_by_rat, rw rat_mul_comm rat_one (rat_reciprocal (rat_add a a)),\n  rw rat_mul_one_rw, unfold mul_rps, unfold mul_rps_by_rat,\n  unfold add_rps, unfold add_rps_to_rat, unfold iszero_rps,\n  split,\n    unfold discriminant,\n    by_cases a_def_tmp : (¬defined a), rw rat_mul_comm (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a, exact undef_iszero (rat_add (rat_add (rat_mul a (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add_undef (rat_add (rat_mul a (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (rat_add_undef (rat_mul a (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_mul_undef a (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a_def_tmp))), have a_defined : (defined a), cc, clear a_def_tmp, by_cases c_def_tmp : (¬defined c), rw rat_add_comm (rat_add (rat_mul (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c, exact undef_iszero (rat_add c (rat_add (rat_mul (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b))) (rat_add_undef c (rat_add (rat_mul (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c_def_tmp), have c_defined : (defined c), cc, clear c_def_tmp, by_cases b_def_tmp : (¬defined b), rw rat_add_comm (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))), rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))), rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))), exact undef_iszero (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add_undef (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (rat_add_undef (rat_mul (rat_add (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_mul_undef (rat_add (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))))) a (rat_add_undef (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul_undef (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) (rat_mul_undef (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a)) (rat_add_undef (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul_undef b b b_def_tmp)))))))), have b_defined : (defined b), cc, clear b_def_tmp,\n    have rat_four_defined : (defined rat_four), unfold rat_four, unfold defined, unfold iszero, cc,\n    by_cases (iszero_rat a),\n      have int1 : ¬defined (rat_reciprocal (rat_add a a)),\n        apply reciprocal_zero_undef (rat_add a a),\n        exact zeroes_only_eq_rat a (rat_add a a) a_defined (rat_eq_comm (rat_add a a) a (rat_add_zero a a h)) h,\n      rw rat_mul_comm (negate_rat b) (rat_reciprocal (rat_add a a)),\n      exact undef_iszero (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) b)) c) ((rat_add_undef (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) b)) c (rat_add_undef (rat_mul (rat_add (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) b) (rat_mul_undef (rat_add (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a (rat_add_undef (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) (rat_mul_undef (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat b)) (rat_mul_undef (rat_reciprocal (rat_add a a)) (negate_rat b) int1))))))),\n      have int1 : defined (rat_reciprocal (rat_add a a)),\n        exact reciprocal_def (rat_add a a) (rat_add_def a a a_defined a_defined) (add_self_nonzero_rat a h),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add_def (rat_add (rat_add (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c ((rat_add_def (rat_add (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) ((rat_add_def (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))) ((rat_mul_def (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))) (int1) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (int1) ((rat_add_def (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))) ((rat_mul_def b b (b_defined) (b_defined))) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))))))))) (a_defined))))) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))))) (c_defined))(add_eq_rat (rat_add (rat_add (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add (rat_mul (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (add_eq_rat (rat_add (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a)) (rat_mul (rat_add (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))))))) a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))))) a))))),\n      rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))),\n      rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))),\n      rw rat_add_comm (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add_def (rat_add (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c ((rat_add_def (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) ((rat_add_def (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) ((rat_mul_def (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a)) ((rat_add_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))))) (int1))) (a_defined))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))))) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))))) (c_defined))(add_eq_rat (rat_add (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (add_eq_rat (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add (rat_mul (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (add_eq_rat (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (mul_eq_rat (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a (mul_eq_rat (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_add (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_mul b b) (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))))))))),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add_def (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c ((rat_add_def (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) ((rat_add_def (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) ((rat_mul_def (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a ((rat_add_def (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) ((rat_mul_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) (int1))) ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))))) (a_defined))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))))) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))))) (c_defined))(add_eq_rat (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (add_eq_rat (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (add_eq_rat (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (mul_eq_rat (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) (rat_mul (rat_add (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a))) a ( (rat_eq_comm _ _ (rat_mul_distrib (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))))))))),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add_def (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c ((rat_add_def (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) ((rat_add_def (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) ((rat_add_def (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) ((rat_mul_def (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) (int1))) (a_defined))) ((rat_mul_def (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))) (a_defined))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))))) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))))) (c_defined))(add_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (add_eq_rat (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (add_eq_rat (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_add (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)))) a) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)))))),\n\n      /- Multiply through by 2a.  As a ≠ 0 this doesn't affect the results of the iszero, but can make things easier.-/\n      apply iszero_mul_rat (rat_add (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add a a) (add_self_nonzero_rat a h) (rat_add_def a a a_defined a_defined),\n\n      /- Now we do a lot of work to cancel the 2a and the 1/2a in every term where they both appear.-/\n      apply zeroes_only_eq_rat (rat_add (rat_mul (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add a a)) (rat_mul c (rat_add a a))) (rat_mul (rat_add (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c) (rat_add a a)) (rat_add_def (rat_mul (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add a a)) (rat_mul c (rat_add a a)) ((rat_mul_def (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add a a) ((rat_add_def (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) ((rat_add_def (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) ((rat_add_def (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) ((rat_mul_def (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) (int1))) (a_defined))) ((rat_mul_def (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))) (a_defined))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))))) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))))) ((rat_add_def a a (a_defined) (a_defined))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))( (rat_eq_comm _ _ (rat_mul_distrib (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) c (rat_add a a)))),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add (rat_mul (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add a a)) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ((rat_mul_def (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a) ((rat_add_def (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) ((rat_add_def (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) ((rat_mul_def (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) (int1))) (a_defined))) ((rat_mul_def (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))) (a_defined))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))))) ((rat_add_def a a (a_defined) (a_defined))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b)) (rat_add a a)) (rat_mul c (rat_add a a)) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))))),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ((rat_add_def (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) ((rat_mul_def (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a) ((rat_add_def (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) ((rat_mul_def (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) (int1))) (a_defined))) ((rat_mul_def (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))) (a_defined))))) ((rat_add_def a a (a_defined) (a_defined))))) ((rat_mul_def (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_add (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)))))),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ((rat_add_def (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) ((rat_add_def (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) ((rat_mul_def (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (rat_mul b b) (rat_reciprocal (rat_add a a)) ((rat_mul_def b b (b_defined) (b_defined))) (int1))) (int1))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))) ((rat_mul_def (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_add (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_add (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) (add_eq_rat (rat_add (rat_mul (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_add (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))))))),\n      rw rat_mul_comm (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a, rw rat_mul_comm (rat_add a a) (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_mul (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_add a a)) a, rw rat_mul_comm (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_add a a) (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_mul (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_add a a)) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (rat_mul b b) (rat_reciprocal (rat_add a a))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul b b) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_add a a) (rat_mul b b), rw rat_mul_assoc (rat_mul b b) (rat_add a a) (rat_reciprocal (rat_add a a)),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ((rat_add_def (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) ((rat_add_def (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b b) (int1) ((rat_mul_def b b (b_defined) (b_defined))))))) ((rat_mul_def (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a ((rat_mul_def (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)) ((rat_mul_def (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))) (int1))) (int1))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) (add_eq_rat (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) (add_eq_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)) (mul_eq_rat_alt (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))) a (mul_eq_rat_alt (rat_mul b b) (rat_mul (rat_mul b b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a)) (reciprocal_mul_cancel (rat_mul b b) (rat_add a a)))))))),\n      rw rat_add_comm (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a)),\n      rw rat_mul_comm (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) a, rw rat_mul_comm (rat_add a a) (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_mul (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_add a a)) a, rw rat_mul_comm (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_add a a) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_mul (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_add a a)) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_add a a) (negate_rat (rat_mul rat_four (rat_mul a c))), rw rat_mul_assoc (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_add a a) (rat_reciprocal (rat_add a a)),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ((rat_add_def (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) ((rat_add_def (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c)))) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))) (int1) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))))))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b b) (int1) ((rat_mul_def b b (b_defined) (b_defined))))))))) ((rat_mul_def (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_add (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) (add_eq_rat (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) (add_eq_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (mul_eq_rat_alt (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c)))) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))) a (mul_eq_rat_alt (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) (rat_reciprocal (rat_add a a)) (reciprocal_mul_cancel (negate_rat (rat_mul rat_four (rat_mul a c))) (rat_add a a)))))))),\n      rw rat_add_comm (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a)),\n      rw rat_mul_comm (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) a, rw rat_mul_comm (rat_add a a) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))), rw rat_mul_comm (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_add a a)) a, rw rat_mul_comm (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a)))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_add a a) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_add a a)) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (negate_rat b) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_add a a) (negate_rat b), rw rat_mul_assoc (negate_rat b) (rat_add a a) (rat_reciprocal (rat_add a a)),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) ((rat_add_def (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) ((rat_mul_def a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b)) (a_defined) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b) ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) ((negate_def b b_defined)))))) ((rat_add_def (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c)))) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))) (int1) ((negate_def (rat_mul rat_four (rat_mul a c)) (rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))))))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b b) (int1) ((rat_mul_def b b (b_defined) (b_defined))))))))))) ((rat_mul_def (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a) ((rat_mul_def (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b ((rat_mul_def (negate_rat b) (rat_reciprocal (rat_add a a)) ((negate_def b b_defined)) (int1))) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_add (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_add (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) b) (rat_add a a)) (add_eq_rat (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b))) (rat_mul a (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (mul_eq_rat_alt (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (negate_rat b)) (rat_mul (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (rat_mul (negate_rat b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))) a (mul_eq_rat_alt (negate_rat b) (rat_mul (negate_rat b) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) (rat_mul (negate_rat b) (rat_reciprocal (rat_add a a))) (reciprocal_mul_cancel (negate_rat b) (rat_add a a))))))),\n      repeat {rw mul_negate_alt_rw},\n      rw rat_add_comm (rat_add (rat_mul a (rat_mul (rat_mul b (negate_rat (rat_reciprocal (rat_add a a)))) (negate_rat b))) (rat_add (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (negate_rat (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_mul (rat_mul (rat_mul b (negate_rat (rat_reciprocal (rat_add a a)))) b) (rat_add a a)),\n      repeat {rw rat_mul_assoc}, repeat {rw mul_negate_rw}, repeat {rw mul_negate_alt_rw}, repeat {rw mul_negate_rw},\n      rw double_negate,\n      rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_mul b (rat_add a a)), rw rat_mul_assoc b (rat_add a a) (rat_reciprocal (rat_add a a)),\n      apply zeroes_only_eq_rat (rat_add (rat_add (negate_rat (rat_mul b b)) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))))) (rat_mul c (rat_add a a))) (rat_add (rat_add (negate_rat (rat_mul b (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (negate_rat (rat_mul b b)) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))))) (rat_mul c (rat_add a a)) ((rat_add_def (negate_rat (rat_mul b b)) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) ((negate_def (rat_mul b b) (rat_mul_def b b (b_defined) (b_defined)))) ((rat_add_def (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) ((rat_mul_def a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b)) (a_defined) ((rat_mul_def b (rat_mul (rat_reciprocal (rat_add a a)) b) (b_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) b (int1) (b_defined))))))) ((rat_add_def (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) ((negate_def (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c)))) (rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c)) (int1) ((rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))))))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b b) (int1) ((rat_mul_def b b (b_defined) (b_defined))))))))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (negate_rat (rat_mul b b)) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))))) (rat_add (negate_rat (rat_mul b (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))))) (rat_mul c (rat_add a a)) (add_eq_rat (negate_rat (rat_mul b b)) (negate_rat (rat_mul b (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_eq_rat (rat_mul b b) (rat_mul b (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))) (mul_eq_rat_alt b (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) b (reciprocal_mul_cancel b (rat_add a a)))))),\n\n      /- Now we have two locations with a * 1/(a + a), so we can cancel them down to 1/2  -/\n      rw rat_add_comm (negate_rat (rat_mul b b)) (rat_add (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) b))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))), repeat {rw rat_mul_assoc},\n      rw <- rat_mul_assoc a b (rat_mul (rat_reciprocal (rat_add a a)) b), rw rat_mul_comm a b, rw rat_mul_assoc b a (rat_mul (rat_reciprocal (rat_add a a)) b), rw <- rat_mul_assoc a (rat_reciprocal (rat_add a a)) b, rw rat_mul_comm a (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) a) b, rw rat_mul_comm (rat_reciprocal (rat_add a a)) a,\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_mul b (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b)) ((rat_add_def (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) ((rat_mul_def b (rat_mul b (rat_reciprocal rat_two)) (b_defined) ((rat_mul_def b (rat_reciprocal rat_two) (b_defined) (half_defined))))) ((rat_add_def (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) ((negate_def (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c)))) (rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c)) (int1) ((rat_mul_def rat_four (rat_mul a c) (rat_four_defined) ((rat_mul_def a c (a_defined) (c_defined)))))))))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b b) (int1) ((rat_mul_def b b (b_defined) (b_defined))))))))))) ((negate_def (rat_mul b b) (rat_mul_def b b (b_defined) (b_defined)))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b))) (rat_add (rat_add (rat_mul b (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (rat_add (rat_mul b (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))))) (negate_rat (rat_mul b b)) (add_eq_rat (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_mul b (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (mul_eq_rat_alt (rat_mul b (rat_reciprocal rat_two)) (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a)))) b (mul_eq_rat_alt (rat_reciprocal rat_two) (rat_mul a (rat_reciprocal (rat_add a a))) b (half_reciprocal_mul a)))))),\n      rw rat_add_comm (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))),\n      rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_mul rat_four (rat_mul a c)), rw rat_mul_assoc rat_four (rat_mul a c) (rat_reciprocal (rat_add a a)), rw rat_mul_assoc a c (rat_reciprocal (rat_add a a)), rw <- rat_mul_assoc a c (rat_reciprocal (rat_add a a)), rw rat_mul_comm a c, rw rat_mul_assoc c a (rat_reciprocal (rat_add a a)),\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a))))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b)) ((rat_add_def (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two))) ((rat_add_def (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) ((negate_def (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))) (rat_mul_def a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))) (a_defined) ((rat_mul_def rat_four (rat_mul c (rat_reciprocal rat_two)) (rat_four_defined) ((rat_mul_def c (rat_reciprocal rat_two) (c_defined) (half_defined)))))))) ((rat_mul_def a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)) (a_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b b) (int1) ((rat_mul_def b b (b_defined) (b_defined))))))))) ((rat_mul_def b (rat_mul b (rat_reciprocal rat_two)) (b_defined) ((rat_mul_def b (rat_reciprocal rat_two) (b_defined) (half_defined))))))) ((negate_def (rat_mul b b) (rat_mul_def b b (b_defined) (b_defined)))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_add (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a))))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a))))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b)) (add_eq_rat (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a))))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b)))) (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (add_eq_rat (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a))))))) (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))) (negate_eq_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))) (rat_mul a (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a)))))) (mul_eq_rat_alt (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))) (rat_mul rat_four (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a))))) a (mul_eq_rat_alt (rat_mul c (rat_reciprocal rat_two)) (rat_mul c (rat_mul a (rat_reciprocal (rat_add a a)))) rat_four (mul_eq_rat_alt (rat_reciprocal rat_two) (rat_mul a (rat_reciprocal (rat_add a a))) c (half_reciprocal_mul a))))))))),\n      rw rat_add_comm (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))  (rat_mul a (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b b))),\n      rw <- rat_mul_assoc a (rat_reciprocal (rat_add a a)) (rat_mul b b), rw rat_mul_comm a (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) a) (rat_mul b b), rw rat_mul_comm (rat_reciprocal (rat_add a a)) a,\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_add (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (rat_add (rat_add (rat_add (rat_add (rat_mul (rat_mul b b) (rat_mul a (rat_reciprocal (rat_add a a)))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (rat_add_def (rat_add (rat_add (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) ((rat_add_def (rat_add (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b)) ((rat_add_def (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two))) ((rat_add_def (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) ((rat_mul_def (rat_mul b b) (rat_reciprocal rat_two) ((rat_mul_def b b (b_defined) (b_defined))) (half_defined))) ((negate_def (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))) (rat_mul_def a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))) (a_defined) ((rat_mul_def rat_four (rat_mul c (rat_reciprocal rat_two)) (rat_four_defined) ((rat_mul_def c (rat_reciprocal rat_two) (c_defined) (half_defined)))))))))) ((rat_mul_def b (rat_mul b (rat_reciprocal rat_two)) (b_defined) ((rat_mul_def b (rat_reciprocal rat_two) (b_defined) (half_defined))))))) ((negate_def (rat_mul b b) (rat_mul_def b b (b_defined) (b_defined)))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_add (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_add (rat_add (rat_add (rat_mul (rat_mul b b) (rat_mul a (rat_reciprocal (rat_add a a)))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) (add_eq_rat (rat_add (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (rat_add (rat_add (rat_mul (rat_mul b b) (rat_mul a (rat_reciprocal (rat_add a a)))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two)))) (negate_rat (rat_mul b b)) (add_eq_rat (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_add (rat_mul (rat_mul b b) (rat_mul a (rat_reciprocal (rat_add a a)))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two))) (add_eq_rat (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (rat_mul (rat_mul b b) (rat_mul a (rat_reciprocal (rat_add a a)))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (mul_eq_rat_alt (rat_reciprocal rat_two) (rat_mul a (rat_reciprocal (rat_add a a))) (rat_mul b b) (half_reciprocal_mul a)))))),\n\n      /- Now we have two terms of the form ((b^2) * 1/2) -/\n      /- We can add them together to make a single b^2 term-/\n      rw rat_add_comm (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))))) (rat_mul b (rat_mul b (rat_reciprocal rat_two))), repeat {rw rat_add_assoc},\n      repeat {rw <- rat_mul_assoc b b (rat_reciprocal rat_two)},\n      repeat {rw <- rat_add_assoc (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (rat_mul (rat_mul b b) (rat_reciprocal rat_two))) _ _},\n      apply zeroes_only_eq_rat (rat_add (rat_mul b b) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)))) (rat_add (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (rat_mul (rat_mul b b) (rat_reciprocal rat_two))) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)))) (rat_add_def (rat_mul b b) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) ((rat_mul_def b b (b_defined) (b_defined))) ((rat_add_def (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a)) ((rat_add_def (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b)) ((negate_def (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))) (rat_mul_def a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))) (a_defined) ((rat_mul_def rat_four (rat_mul c (rat_reciprocal rat_two)) (rat_four_defined) ((rat_mul_def c (rat_reciprocal rat_two) (c_defined) (half_defined)))))))) ((negate_def (rat_mul b b) (rat_mul_def b b (b_defined) (b_defined)))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined)))))))) (add_eq_rat (rat_mul b b) (rat_add (rat_mul (rat_mul b b) (rat_reciprocal rat_two)) (rat_mul (rat_mul b b) (rat_reciprocal rat_two))) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b))) (rat_mul c (rat_add a a))) (add_two_halves (rat_mul b b))),\n\n      /- And now we have both b^2 and -(b^2), so we can cancel them.-/\n      rw rat_add_comm (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (negate_rat (rat_mul b b)),\n      repeat {rw rat_add_assoc (rat_mul b b) _ _},  rw <- rat_add_assoc (rat_add (rat_mul b b) (negate_rat (rat_mul b b))) (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a)),\n      apply zeroes_only_eq_rat (rat_add rat_zero (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a))))  (rat_add (rat_add (rat_mul b b) (negate_rat (rat_mul b b))) (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a)))) (rat_add_def rat_zero (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a))) (rat_zero_defined) ((rat_add_def (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a)) ((negate_def (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two)))) (rat_mul_def a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))) (a_defined) ((rat_mul_def rat_four (rat_mul c (rat_reciprocal rat_two)) (rat_four_defined) ((rat_mul_def c (rat_reciprocal rat_two) (c_defined) (half_defined)))))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined)))))))) (add_eq_rat rat_zero (rat_add (rat_mul b b) (negate_rat (rat_mul b b))) (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a))) (rat_eq_comm (rat_add (rat_mul b b) (negate_rat (rat_mul b b))) rat_zero (add_negate_rat (rat_mul b b)))),\n      rw rat_add_comm rat_zero (rat_add (negate_rat (rat_mul a (rat_mul rat_four (rat_mul c (rat_reciprocal rat_two))))) (rat_mul c (rat_add a a))),\n      rw rat_add_zero_alt,\n\n      /- We have eliminated all the terms with b in them, all that's left is\n        -4ac/2 + c(a + a) = 0.  Not much left to do, first cancel the 4/2-/\n      rw <- rat_mul_assoc rat_four c (rat_reciprocal rat_two), rw rat_mul_comm rat_four c,\n      rw rat_mul_comm a (rat_mul (rat_mul c rat_four) (rat_reciprocal rat_two)),\n      rw rat_mul_assoc c rat_four (rat_reciprocal rat_two), rw rat_mul_comm c (rat_mul rat_four (rat_reciprocal rat_two)),\n      rw rat_mul_assoc (rat_mul rat_four (rat_reciprocal rat_two)) c a,\n      apply zeroes_only_eq_rat (rat_add (negate_rat (rat_mul rat_two (rat_mul c a))) (rat_mul c (rat_add a a))) (rat_add (negate_rat (rat_mul (rat_mul rat_four (rat_reciprocal rat_two)) (rat_mul c a))) (rat_mul c (rat_add a a))) (rat_add_def (negate_rat (rat_mul rat_two (rat_mul c a))) (rat_mul c (rat_add a a)) ((negate_def (rat_mul rat_two (rat_mul c a)) (rat_mul_def rat_two (rat_mul c a) (rat_two_defined) ((rat_mul_def c a (c_defined) (a_defined)))))) ((rat_mul_def c (rat_add a a) (c_defined) ((rat_add_def a a (a_defined) (a_defined)))))) (add_eq_rat (negate_rat (rat_mul rat_two (rat_mul c a))) (negate_rat (rat_mul (rat_mul rat_four (rat_reciprocal rat_two)) (rat_mul c a))) (rat_mul c (rat_add a a)) (negate_eq_rat (rat_mul rat_two (rat_mul c a)) (rat_mul (rat_mul rat_four (rat_reciprocal rat_two)) (rat_mul c a)) (mul_eq_rat rat_two (rat_mul rat_four (rat_reciprocal rat_two)) (rat_mul c a) (rat_eq_comm (rat_mul rat_four (rat_reciprocal rat_two)) rat_two four_divided_by_two)))),\n\n     /- And finally, just prove that 2ca = c(a + a)-/\n      rw rat_add_comm (negate_rat (rat_mul rat_two (rat_mul c a))) (rat_mul c (rat_add a a)),\n      rw rat_mul_comm c (rat_add a a),\n      apply zeroes_only_eq_rat (rat_add (rat_mul (rat_mul a rat_two) c) (negate_rat (rat_mul rat_two (rat_mul c a)))) (rat_add (rat_mul (rat_add a a) c) (negate_rat (rat_mul rat_two (rat_mul c a)))) (rat_add_def (rat_mul (rat_mul a rat_two) c) (negate_rat (rat_mul rat_two (rat_mul c a))) ((rat_mul_def (rat_mul a rat_two) c ((rat_mul_def a rat_two (a_defined) (rat_two_defined))) (c_defined))) ((negate_def (rat_mul rat_two (rat_mul c a)) (rat_mul_def rat_two (rat_mul c a) (rat_two_defined) ((rat_mul_def c a (c_defined) (a_defined))))))) (add_eq_rat (rat_mul (rat_mul a rat_two) c) (rat_mul (rat_add a a) c) (negate_rat (rat_mul rat_two (rat_mul c a))) (mul_eq_rat (rat_mul a rat_two) (rat_add a a) c (mul_two_rat a))),\n      rw rat_mul_comm c a, rw rat_mul_comm a rat_two, rw rat_mul_assoc,\n      exact add_negate_rat_alt (rat_mul rat_two (rat_mul a c)),\n\n      /- And we are DONE for the first goal (the part that isn't multiplied by the root of the discriminant)! -/\n      /- For the second goal, start by again doing all the trivial cases with undefined values, yay Python.-/\n      by_cases a_def_tmp : (¬defined a), rw rat_mul_comm (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a, exact undef_iszero (rat_add (rat_mul a (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))))) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add_undef (rat_mul a (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))))) (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_mul_undef a (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a_def_tmp)), have a_defined : (defined a), cc, clear a_def_tmp, by_cases b_def_tmp : (¬defined b), exact undef_iszero (rat_add (rat_mul (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add_undef (rat_mul (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a) (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_mul_undef (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a (rat_add_undef (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_undef (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) (rat_mul_undef b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b_def_tmp))))), have b_defined : (defined b), cc, clear b_def_tmp,\n      by_cases recip_def_tmp : (¬defined (rat_reciprocal (rat_add a a))), rw rat_mul_comm b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))),\n      exact undef_iszero (rat_add (rat_mul (rat_add (negate_rat (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b)) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add_undef (rat_mul (rat_add (negate_rat (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b)) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a) (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_mul_undef (rat_add (negate_rat (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b)) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a (rat_add_undef (negate_rat (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b)) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_undef (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b) (rat_mul_undef (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) b (rat_mul_undef (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)) recip_def_tmp)))))), have int1 : defined (rat_reciprocal (rat_add a a)), cc, clear recip_def_tmp,\n      have h : (¬iszero_rat a), intro h, exact reciprocal_zero_undef (rat_add a a) (zeroes_only_eq_rat a (rat_add a a) a_defined (rat_eq_comm (rat_add a a) a (rat_add_zero a a h)) h) int1,\n\n      /- Now do the distributive rewrite.-/\n      apply zeroes_only_eq_rat (rat_add (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add (rat_mul (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add_def (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_mul (rat_reciprocal (rat_add a a)) b) ((rat_add_def (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) ((rat_mul_def (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a ((negate_def (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) (rat_mul_def b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) (b_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)) (int1) (int1)))))) (a_defined))) ((rat_mul_def (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a ((negate_def (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))) (int1) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))) (a_defined))))) ((rat_mul_def (rat_reciprocal (rat_add a a)) b (int1) (b_defined))))(add_eq_rat (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_mul (rat_add (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))))) a) (rat_mul (rat_reciprocal (rat_add a a)) b) ( (rat_eq_comm _ _ (rat_mul_distrib (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)))),\n\n      /- Again. multiply through by 2a.-/\n      apply iszero_mul_rat (rat_add (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add a a) (add_self_nonzero_rat a h) (rat_add_def a a a_defined a_defined),\n      apply zeroes_only_eq_rat (rat_add (rat_mul (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_mul (rat_add (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_mul (rat_reciprocal (rat_add a a)) b)) (rat_add a a)) (rat_add_def (rat_mul (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) ((rat_mul_def (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_add a a) ((rat_add_def (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) ((rat_mul_def (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a ((negate_def (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) (rat_mul_def b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) (b_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)) (int1) (int1)))))) (a_defined))) ((rat_mul_def (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a ((negate_def (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))) (int1) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))) (a_defined))))) ((rat_add_def a a (a_defined) (a_defined))))) ((rat_mul_def (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a) ((rat_mul_def (rat_reciprocal (rat_add a a)) b (int1) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))( (rat_eq_comm _ _ (rat_mul_distrib (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)))), apply zeroes_only_eq_rat (rat_add (rat_add (rat_mul (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_add a a)) (rat_mul (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) (rat_add a a))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_add (rat_mul (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_add_def (rat_add (rat_mul (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_add a a)) (rat_mul (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) (rat_add a a))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) ((rat_add_def (rat_mul (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_add a a)) (rat_mul (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) (rat_add a a)) ((rat_mul_def (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_add a a) ((rat_mul_def (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a ((negate_def (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) (rat_mul_def b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))) (b_defined) ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)) (int1) (int1)))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))) ((rat_mul_def (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) (rat_add a a) ((rat_mul_def (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a ((negate_def (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))) (int1) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined))))))) ((rat_mul_def (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a) ((rat_mul_def (rat_reciprocal (rat_add a a)) b (int1) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (rat_mul (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_add a a)) (rat_mul (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) (rat_add a a))) (rat_mul (rat_add (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a)) (rat_add a a)) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) ( (rat_eq_comm _ _ (rat_mul_distrib (rat_mul (negate_rat (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))))) a) (rat_mul (negate_rat (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))))) a) (rat_add a a))))),\n      repeat {rw mul_negate_alt_rw}, repeat {rw mul_negate_rw}, repeat {rw mul_negate_alt_rw}, repeat {rw mul_negate_rw},\n\n\n      /- Cancel where possible (which is everywhere for this bit).-/\n      rw rat_mul_comm (rat_mul (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) a) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) a, rw rat_mul_comm (rat_add a a) (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))), rw rat_mul_comm (rat_mul (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) (rat_add a a)) a, rw rat_mul_comm (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) b (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_add a a) b, rw rat_mul_assoc b (rat_add a a) (rat_mul (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a))), rw <- rat_mul_assoc (rat_add a a) (rat_reciprocal (rat_add a a)) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_add a a) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) (rat_add a a)) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_add a a),\n      apply zeroes_only_eq_rat (rat_add (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a)))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a)))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_add_def (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a)))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) ((rat_add_def (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) ((negate_def (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def a (rat_mul b (rat_reciprocal (rat_add a a))) (a_defined) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))) ((negate_def (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a)) (rat_mul_def (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a) ((rat_mul_def (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a ((rat_mul_def (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))) (int1) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1))))) (a_defined))) ((rat_add_def a a (a_defined) (a_defined)))))))) ((rat_mul_def (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a) ((rat_mul_def (rat_reciprocal (rat_add a a)) b (int1) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a)))) (rat_add (negate_rat (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a)))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) (add_eq_rat (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a))) (negate_eq_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul a (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (mul_eq_rat_alt (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul b (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))) a (mul_eq_rat_alt (rat_reciprocal (rat_add a a)) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) b (reciprocal_mul_cancel (rat_reciprocal (rat_add a a)) (rat_add a a))))))),\n      rw rat_add_comm (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a))),\n      rw rat_mul_comm (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) a, rw rat_mul_comm (rat_add a a) (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))), rw rat_mul_comm (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_add a a)) a, rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_reciprocal (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_add a a) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) (rat_add a a)) (rat_mul b (rat_reciprocal (rat_add a a))), rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_add a a),\n      apply zeroes_only_eq_rat (rat_add (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_add (rat_add (negate_rat (rat_mul a (rat_mul (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a))) (rat_add_def (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) ((rat_add_def (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) ((negate_def (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def a (rat_mul b (rat_reciprocal (rat_add a a))) (a_defined) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))) ((negate_def (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def a (rat_mul b (rat_reciprocal (rat_add a a))) (a_defined) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))))) ((rat_mul_def (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a) ((rat_mul_def (rat_reciprocal (rat_add a a)) b (int1) (b_defined))) ((rat_add_def a a (a_defined) (a_defined))))))(add_eq_rat (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (rat_add (negate_rat (rat_mul a (rat_mul (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)) (add_eq_rat (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_eq_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul a (rat_mul (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a))))) (mul_eq_rat_alt (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul (rat_mul b (rat_reciprocal (rat_add a a))) (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) a (reciprocal_mul_cancel (rat_mul b (rat_reciprocal (rat_add a a))) (rat_add a a)))))),\n      rw rat_add_comm (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (rat_mul (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a)),\n      rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) b) (rat_add a a), rw <- rat_mul_assoc (rat_add a a) (rat_reciprocal (rat_add a a)) b, rw rat_mul_comm (rat_add a a) (rat_reciprocal (rat_add a a)), rw rat_mul_comm (rat_mul (rat_reciprocal (rat_add a a)) (rat_add a a)) b, rw rat_mul_comm (rat_reciprocal (rat_add a a)) (rat_add a a),\n      apply zeroes_only_eq_rat (rat_add b (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))))) (rat_add (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))))) (rat_add_def b (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) b_defined ((rat_add_def (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) ((negate_def (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def a (rat_mul b (rat_reciprocal (rat_add a a))) (a_defined) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1)))))) ((negate_def (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))) (rat_mul_def a (rat_mul b (rat_reciprocal (rat_add a a))) (a_defined) ((rat_mul_def b (rat_reciprocal (rat_add a a)) (b_defined) (int1))))))))) (add_eq_rat b (rat_mul b (rat_mul (rat_add a a) (rat_reciprocal (rat_add a a)))) (rat_add (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a))))) (negate_rat (rat_mul a (rat_mul b (rat_reciprocal (rat_add a a)))))) (reciprocal_mul_cancel b (rat_add a a))),\n\n      /- Cancel in the two nodes that have a * 1/(a + a)-/\n      rw rat_add_comm b _, rw rat_mul_comm b (rat_reciprocal (rat_add a a)),\n      rw <- rat_mul_assoc a (rat_reciprocal (rat_add a a)) b, rw <- rat_add_assoc,\n      rw rat_mul_comm (rat_mul a (rat_reciprocal (rat_add a a))) b,\n      apply zeroes_only_eq_rat (rat_add (negate_rat (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b)) (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b)) (rat_add_def (negate_rat (rat_mul b (rat_reciprocal rat_two))) (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b) ((negate_def (rat_mul b (rat_reciprocal rat_two)) (rat_mul_def b (rat_reciprocal rat_two) (b_defined) (half_defined)))) ((rat_add_def (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b ((negate_def (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a)))) (rat_mul_def b (rat_mul a (rat_reciprocal (rat_add a a))) (b_defined) ((rat_mul_def a (rat_reciprocal (rat_add a a)) (a_defined) (int1)))))) (b_defined))))(add_eq_rat (negate_rat (rat_mul b (rat_reciprocal rat_two))) (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b) (negate_eq_rat (rat_mul b (rat_reciprocal rat_two)) (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a)))) (mul_eq_rat_alt (rat_reciprocal rat_two) (rat_mul a (rat_reciprocal (rat_add a a))) b (half_reciprocal_mul a)))),\n      rw rat_add_comm,\n      apply zeroes_only_eq_rat (rat_add (rat_add (negate_rat (rat_mul b (rat_reciprocal rat_two))) b) (negate_rat (rat_mul b (rat_reciprocal rat_two)))) (rat_add (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b) (negate_rat (rat_mul b (rat_reciprocal rat_two)))) (rat_add_def (rat_add (negate_rat (rat_mul b (rat_reciprocal rat_two))) b) (negate_rat (rat_mul b (rat_reciprocal rat_two))) ((rat_add_def (negate_rat (rat_mul b (rat_reciprocal rat_two))) b ((negate_def (rat_mul b (rat_reciprocal rat_two)) (rat_mul_def b (rat_reciprocal rat_two) (b_defined) (half_defined)))) (b_defined))) ((negate_def (rat_mul b (rat_reciprocal rat_two)) (rat_mul_def b (rat_reciprocal rat_two) (b_defined) (half_defined)))))(add_eq_rat (rat_add (negate_rat (rat_mul b (rat_reciprocal rat_two))) b) (rat_add (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b) (negate_rat (rat_mul b (rat_reciprocal rat_two))) (add_eq_rat (negate_rat (rat_mul b (rat_reciprocal rat_two))) (negate_rat (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a))))) b (negate_eq_rat (rat_mul b (rat_reciprocal rat_two)) (rat_mul b (rat_mul a (rat_reciprocal (rat_add a a)))) (mul_eq_rat_alt (rat_reciprocal rat_two) (rat_mul a (rat_reciprocal (rat_add a a))) b (half_reciprocal_mul a))))),\n\n      /- Add the two -b/2 terms together...-/\n      rw rat_mul_comm b (rat_reciprocal rat_two), rw <- mul_negate_rw (rat_reciprocal rat_two) b, rw rat_mul_comm (rat_reciprocal rat_two) (negate_rat b),\n      rw rat_add_comm (rat_mul (negate_rat b) (rat_reciprocal rat_two)) b, rw <- rat_add_assoc, rw rat_add_comm,\n      apply zeroes_only_eq_rat (rat_add (negate_rat b) b) (rat_add (rat_add (rat_mul (negate_rat b) (rat_reciprocal rat_two)) (rat_mul (negate_rat b) (rat_reciprocal rat_two))) b) (rat_add_def (negate_rat b) b ((negate_def b b_defined)) (b_defined)) (add_eq_rat (negate_rat b) (rat_add (rat_mul (negate_rat b) (rat_reciprocal rat_two)) (rat_mul (negate_rat b) (rat_reciprocal rat_two))) b (add_two_halves (negate_rat b))),\n\n      /- And all we have left is (-b) + b, which is obviously zero.-/\n      rw rat_add_comm,\n      exact add_negate_rat_alt b,\n      /- QUOD.-/\n      /- ERAT.-/\n      /- DEMONSTRANDUM.-/\n\nend\n\n", "meta": {"author": "anonymousLeanDocsHosting", "repo": "lean-polynomials", "sha": "361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613", "save_path": "github-repos/lean/anonymousLeanDocsHosting-lean-polynomials", "path": "github-repos/lean/anonymousLeanDocsHosting-lean-polynomials/lean-polynomials-361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613/non-mathlib/early_version.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7770498942716766}}
{"text": "-- Unicidad del límite de las sucesiones convergentes\n-- ==================================================\n\nimport data.real.basic\n\nvariables (u : ℕ → ℝ)\nvariables (a b x y : ℝ)\n\n-- ----------------------------------------------------\n-- Nota. Se usarán las siguientes notaciones,\n-- definiciones y lemas estudiados anteriormente:\n-- + |x| = abs x\n-- + limite u c :\n--      ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - c| ≤ ε\n-- + cero_de_abs_mn_todos:\n--      (∀ ε > 0, |x| ≤ ε) → x = 0\n-- + ig_de_abs_sub_mne_todos:\n--      (∀ ε > 0, |x - y| ≤ ε) → x = y\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\ndef limite : (ℕ → ℝ) → ℝ → Prop :=\nλ u c, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - c| ≤ ε\n\nlemma cero_de_abs_mn_todos\n  (h : ∀ ε > 0, |x| ≤ ε)\n  : x = 0 :=\nabs_eq_zero.mp\n  (eq_of_le_of_forall_le_of_dense (abs_nonneg x) h)\n\nlemma ig_de_abs_sub_mne_todos\n  (h : ∀ ε > 0, |x - y| ≤ ε)\n  : x = y :=\nsub_eq_zero.mp (cero_de_abs_mn_todos (x - y) h)\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que cada sucesión tiene como\n-- máximo un límite.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  apply ig_de_abs_sub_mne_todos,\n  intros ε hε,\n  cases ha (ε/2) (half_pos hε) with Na hNa,\n  cases hb (ε/2) (half_pos hε) with Nb hNb,\n  let N := max Na Nb,\n  clear ha hb,\n  specialize hNa N (le_max_left  _ _),\n  specialize hNb N (le_max_right  _ _),\n  calc |a - b|\n       = |(a - u N) + (u N - b)| : by ring\n   ... ≤ |a - u N| + |u N - b|   : by apply abs_add\n   ... = |u N - a| + |u N - b|   : by rw abs_sub\n   ... ≤ ε/2 + ε/2               : add_le_add hNa hNb\n   ... = ε                       : add_halves ε\nend\n\n-- 2ª demostración\nlemma unicidad_limite\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  apply ig_de_abs_sub_mne_todos,\n  intros ε hε,\n  cases ha (ε/2) (by linarith) with Na hNa,\n  cases hb (ε/2) (by linarith) with Nb hNb,\n  let N := max Na Nb,\n  specialize hNa N (by finish),\n  specialize hNb N (by finish),\n  calc |a - b|\n       = |(a - u N) + (u N - b)| : by ring\n   ... ≤ |a - u N| + |u N - b|   : by apply abs_add\n   ... = |u N - a| + |u N - b|   : by rw abs_sub\n   ... ≤ ε                       : by linarith [hNa, hNb]\nend\n\n-- 3ª demostración\nexample\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  by_contradiction H,\n  change a ≠ b at H,\n  have h1 : |a - b| > 0,\n    exact abs_pos.mpr (sub_ne_zero_of_ne H),\n  cases ha (|a - b|/4) (by linarith) with N hN,\n  cases hb (|a - b|/4) (by linarith) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  have h2 : |a - b| < |a - b |,\n    calc  |a - b| = |(a - u N₀) + (u N₀ - b)| : by ring\n    ... ≤ |a - u N₀| + |u N₀ - b|             : by apply abs_add\n    ... = |u N₀ - a| + |u N₀ - b|             : by rw abs_sub\n    ... < |a - b|                             : by linarith,\n  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/5_Limites/Unicidad_del_limite_de_las_sucesiones_convergentes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963207, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7770498942448625}}
{"text": "def Nat.bit (b : Bool) (n : Nat) : Nat :=\n  cond b (2*n+1) (2*n)\n\ntheorem Nat.bit_div_even (h : n % 2 = 0) : bit false (n / 2) = n := by\n  simp [bit]\n  have := Nat.div_add_mod n 2\n  simp [h] at this\n  assumption\n\ntheorem Nat.bit_div_odd (h : n % 2 ≠ 0) : bit true (n / 2) = n := by\n  have h : n % 2 = 1 := by\n    have := mod_lt n (by decide : 2 > 0)\n    revert h this\n    generalize n%2 = k\n    match k with\n    | 0   => decide\n    | 1   => decide\n    | n+2 => intros; contradiction\n  simp [bit]\n  have := Nat.div_add_mod n 2\n  simp [h] at this\n  assumption\n\ntheorem Nat.div2_lt (h : n ≠ 0) : n / 2 < n := by\n  match n with\n  | 1   => decide\n  | 2   => decide\n  | 3   => decide\n  | n+4 =>\n    rw [div_eq, if_pos]\n    refine succ_lt_succ (Nat.lt_trans ?_ (lt_succ_self _))\n    exact @div2_lt (n+2) (by simp_arith)\n    simp_arith\n\n@[specialize]\ndef Nat.binrec\n    (motive : Nat → Sort u)\n    (base : Unit → motive 0)\n    (ind  : (b : Bool) → (n : Nat) → (Unit → motive n) → motive (bit b n))\n    (n : Nat) : motive n :=\n  if h₁ : n = 0 then\n    h₁ ▸ base ()\n  else if h₂ : n % 2 = 0 then\n    bit_div_even h₂ ▸ ind false (n / 2) (fun _ => binrec motive base ind (n / 2))\n  else\n    bit_div_odd h₂ ▸ ind true  (n / 2) (fun _ => binrec motive base ind (n / 2))\ntermination_by _ n => n\ndecreasing_by exact Nat.div2_lt h₁\n\ntheorem Nat.binind\n    (motive : Nat → Prop)\n    (base : motive 0)\n    (ind  : (b : Bool) → (n : Nat) → motive n → motive (bit b n))\n    (n : Nat) : motive n :=\n binrec motive (fun _ => base) (fun b n ih => ind b n (ih ())) n\n\nset_option trace.compiler.ir.result true in\ndef Nat.toBit (n : Nat) : List Bool :=\n  binrec (fun _ => List Bool)\n    (fun _ => [])\n    (fun b n ih => b :: ih ())\n    n\n\n#eval Nat.toBit 18\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/binrec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7770380400480343}}
{"text": "-- Pruebas de desarrollo de producto de sumas\n-- ==========================================\n\n-- ------------------------------------------------------\n-- Ej. 1. Sean a, b, c y d números enteros. Demostrar que \n--    (a + b) * (c + d) = a * c + b * c + a * d + b * d \n-- ------------------------------------------------------\n\nimport tactic\nimport data.int.basic\n\nvariables a b c d : ℤ\n\n-- 1ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\ncalc\n  (a + b) * (c + d) \n      = (a + b) * c + (a + b) * d         : by rw left_distrib\n  ... = (a * c + b * c) + (a + b) * d     : by rw right_distrib\n  ... = (a * c + b * c) + (a * d + b * d) : by rw right_distrib\n  ... = a * c + b * c + a * d + b * d     : by rw ←add_assoc\n\n-- 2ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\nby rw [left_distrib, right_distrib, right_distrib, ←add_assoc]\n\n-- 3ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\nbegin\n  rw left_distrib,\n  rw right_distrib,\n  rw right_distrib,\n  rw ←add_assoc,\nend\n \n-- 4ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\ncalc\n  (a + b) * (c + d) \n      = (a + b) * c + (a + b) * d         : by rw mul_add\n  ... = (a * c + b * c) + (a + b) * d     : by rw add_mul\n  ... = (a * c + b * c) + (a * d + b * d) : by rw add_mul\n  ... = a * c + b * c + a * d + b * d     : by rw ←add_assoc\n\n-- 5ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\n-- by hint\nby linarith\n\n-- 6ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\nby nlinarith\n \n-- 7ª demostración\nexample : (a + b) * (c + d) = a * c + b * c + a * d + b * d :=\nby ring\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/Pruebas_de_desarrollo_de_producto_de_sumas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7770380347506045}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Importar la teoría de las propiedades de los subconjuntos\n-- de espacios topológicos.\n-- ---------------------------------------------------------------------\n\nimport topology.subset_properties\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar\n-- + X e Y como variables sobre espacios topológicos\n-- + f como variable de funciones de X en Y.\n-- ---------------------------------------------------------------------\n\nvariables (X Y : Type) [topological_space X] [topological_space Y]\nvariable  (f : X → Y)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir las teorías filter y set.\n-- ---------------------------------------------------------------------\n\nopen filter set\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir localmente las teorías filter (para 𝓟) y\n-- topological_space (para 𝓝).\n-- ---------------------------------------------------------------------\n\nopen_locale filter\nopen_locale topological_space\n\n-- =====================================================================\n-- § Filtros de entornos                                              --\n-- =====================================================================\n\n-- Si `α` es un espacio topológico y `a : α` entonces `𝓝 a` es el\n-- siguiente filtro sobre `α`: `X ∈ 𝓝 a` si y sólo si `X` contiene un\n-- entorno abierto de `a` o, equivalentemente, si `a` está en el\n-- interior de `X`. Hay que pensar en `𝓝 a` como el \"subconjunto\n-- generalizado\" de `X` correspondiente a un entorno abierto\n-- infinitesimal `a`.\n--\n-- Utilizaremos la API de interior y clausura, y comprobaremos que `𝓝 a`\n-- es un filtro.\n--\n-- Los siguientes lemas de los espacios topológicos serán utiles:\n-- + interior_univ {α : Type u} [topological_space α] :\n--      interior univ = univ\n-- + mem_univ {α : Type u} (x : α) :\n--      x ∈ univ\n-- + interior_mono {α : Type u} [topological_space α] {s t : set α} (h : s ⊆ t) :\n--     interior s ⊆ interior t\n-- + interior_inter {α : Type u} [topological_space α] {s t : set α} :\n--     interior (s ∩ t) = interior s ∩ interior t\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar α como una variable sobre espacios topológicos.\n-- ---------------------------------------------------------------------\n\nvariables {α : Type*} [topological_space α]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir el espacio de nombre de conjuntos.\n-- ---------------------------------------------------------------------\n\nopen set\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el conjunto de los entornos abiertos de un\n-- punto a (en mathlib se denota por `𝓝 a`) es un filtro.\n-- ---------------------------------------------------------------------\n\n-- Demostración. Sea a un punto. El conjunto de los entornos abiertos de\n-- a es\n--    F = {X : set α | a ∈ interior X}.\n-- Veamos que F cumple los axiomas de filtro.\n--\n-- (1º axioma) univ ∈ F, ya que a ∈ univ = interior(univ).\n--\n-- (2º axioma): Sean X ∈ F y X ⊆ Y. Entonces,\n--    a ∈ interior(X) ⊆ interior(Y)\n-- Luego, a ∈ interior(Y) y Y ∈ F.\n--\n-- (3º axioma): Sean X, Y ∈ F. Entonces,\n--    a ∈ interior(X) y a ∈ interior(Y)\n--    ⟹ a ∈ interior(X) ∩ interior(Y) = interior(X ∩ Y)\n-- Por tanto, X ∩ Y ∈ F.\n\nexample (a : α): filter α :=\n{ sets := {X : set α | a ∈ interior X},\n  univ_sets :=\n  begin\n    rw mem_set_of_eq,\n    rw interior_univ,\n    exact mem_univ a,\n  end,\n  sets_of_superset :=\n  begin\n    intros X Y haX hXY,\n    rw mem_set_of_eq at *,\n    exact interior_mono hXY haX,\n  end,\n  inter_sets :=\n  begin\n    intros X Y hX hY,\n    rw mem_set_of_eq at *,\n    rw interior_inter,\n    exact ⟨hX, hY⟩\n  end }\n\n-- =====================================================================\n-- § Puntos de acumulación                                            --\n-- =====================================================================\n\n-- Un punto de acumulación `a : α` de un filtro `F : filter α` en un\n-- espacio topológico debe pensarse como un punto en la clausura del\n-- \"conjunto generalizado\" correspondiente a `F`. Esta es la definición\n-- formal.\n--\n-- Un punto de acumulación de un filtro `F : filter α` (también conocido\n-- como punto límite) es `x : α` tal que `𝓝 x ⊓ F ≠ ⊥`. La imagen es que\n-- la intersección del conjunto generalizado `F` y el entorno abierto\n-- `𝓝 x` de `x` tienen intersección no vacía. Sin embargo, repasemos la\n-- notación con más cuidado. Recordemos que el orden de los filtros es\n-- al revés, por lo que `𝓝 x ⊓ F` significa el filtro generado por `F` y\n-- los entornos de `x`, y `⊥` es el filtro que contiene cada\n-- subconjunto. Así que esto se reduce a decir que no existen conjuntos\n-- `A ∈ 𝓝 x` y `B ∈ F` tales que `A ∩ B = ∅`, o, en otras palabras, cada\n-- elemento del filtro intersecta todos los entornos de `x`. Por\n-- ejemplo, si `S` es un subconjunto cualquiera de `α`, entonces los\n-- puntos de acumulación de `𝓟 S` son los puntos `x` tales que cualquier\n-- conjunto abierto que contiene a `x` se encuentra con `S`, o lo que es\n-- lo mismo, que `x` está en la cierre de `S`.\n--\n-- El siguiente lema (que se llama `cluster_pt.mono` en mathlib) afirma\n-- que si `F` y `G` son subconjuntos generalizados de un espacio\n-- topológico y `F ⊆ G`, entonces `clausura(F) ⊆ clausura(G)`.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si x es un punto de acumulación del filtro F\n-- y F ≤ G, entonces x es un punto de acumulación del filtro G.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración. Sea `U ∈ 𝓝 x` y `V ∈ G`. Entonces, `V ∈ F` (porque\n-- `F ≤ G`) y `U ∩ V ≠ ∅` (porque `x` es un punto de acumulación de\n-- `F`). Por tanto, `x` es un punto de acumulación de `G`.\n\nexample\n  {x : α}\n  {F G : filter α}\n  (hxF : cluster_pt x F)\n  (hFG : F ≤ G)\n  : cluster_pt x G :=\nbegin\n  rw cluster_pt_iff at *,\n  intros,\n  apply hxF hU,\n  rw filter.le_def at hFG,\n  apply hFG _ hV,\nend\n\n-- 2ª demostración. Se tiene\n--    𝓝 x ⊓ F ≠ ⊥          [porque x es un punto de acumulación de F]\n--    𝓝 x ⊓ F ≤ 𝓝 x ⊓ G    [porque F ≤ G]\n--    𝓝 x ⊓ G ≠ ⊥          [por los dos anteriores]\n-- Por tanto, x es un punto de acumulación de G.\n\nexample\n  {x : α}\n  {F G : filter α}\n  (hxF : cluster_pt x F)\n  (hFG : F ≤ G)\n  : cluster_pt x G :=\nbegin\n  unfold cluster_pt,\n  apply ne_bot_of_le_ne_bot hxF,\n  exact inf_le_inf_left _ hFG,\nend\n\n-- 3ª demostración\nexample\n  {x : α}\n  {F G : filter α}\n  (hxF : cluster_pt x F)\n  (hFG : F ≤ G)\n  : cluster_pt x G :=\n-- by library_search\ncluster_pt.mono hxF hFG\n\n-- =====================================================================\n-- § Compacidad                                                       --\n-- =====================================================================\n\n-- La definición actual de `is_compact` en mathlib dice que un\n-- subconjunto `S` de un espacio topológico espacio `α` es *compacto` si\n-- para cada filtro `F ≠ ⊥` tal que `S ∈ F` existe `a : α` tal que cada\n-- conjunto de `F` comparte elementos con cada entorno de `a`. En otras\n-- palabras, `S` es compacto si el cierre de cada subconjunto\n-- generalizado no vacío `F ⊆ S` contiene algún elemento de `S`. De\n-- alguna manera, la no compacidad da lugar a subconjuntos generalizados\n-- que están \"en el límite de `S`\" pero que no intersectan un entorno de\n-- elementos de \"S\". Tal vez sea mejor no preocuparse por esta exótica\n-- definición. Por supuesto es equivalente a la definición habitual de\n-- compacidad, pero no vamos a demostrarlo.\n--\n-- Vamos a volver a probar que un subconjunto cerrado de un espacio\n-- compacto es compacto. Como antes, demostramos la afirmación más\n-- general de que si `α` es cualquier espacio topológico, la\n-- intersección de un subconjunto compacto de `α` y un subconjunto\n-- cerrado de `α` es un subconjunto compacto de `α`.\n--\n-- Esta es la definición en mathlib:\n--    def is_compact (s : set α) := ∀ ⦃f⦄ [ne_bot f], f ≤ 𝓟 s → ∃a∈s, cluster_pt a f\n--\n-- Nótese que `ne_bot f` está entre corchetes, lo que significa que el\n-- sistema de inferencia de tipos lo deduce.\n--\n-- Una sugerencia para una prueba es primero mostrar que por la\n-- compacidad de `S`, podemos encontrar un punto de acumulación `a` para\n-- `f` en `s` y después demostrar que este punto de acumulación está en\n-- `t` también, porque \"t\" es cerrado.\n\n-- Algunos lemas útiles son:\n-- + is_closed.closure_eq\n--     {α : Type u} [topological_space α]\n--     {s : set α}\n--     (h : is_closed s)\n--     : closure s = s\n-- + mem_closure_iff_cluster_pt\n--     {α : Type u} [topological_space α]\n--     {s : set α}\n--     {a : α}\n--     : a ∈ closure s ↔ cluster_pt a (𝓟 s)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la intersección de un compacto s con un\n-- cerrado (t) es un compacto (s ∩ t).\n-- ---------------------------------------------------------------------\n\n-- Demostración. Sea `f` un filtro tal que `f ≠ ⊥` y `f ≤ 𝓟 (s ∩ t)`.\n-- Tenemos que demostrar que existe `a ∈ s ∩ t` que es un punto de\n-- acumulación de `f`.\n--\n-- De `f ≤ 𝓟 (s ∩ t)` se sigue que `f ≤ 𝓟 s` y, por ser `s`  compacto,\n-- existe `a ∈ s` que es un punto de acumulación de `f`. Pra concluir la\n-- demostración, basta demostrar que `a ∈ t` (ya que entonces\n-- `a ∈ s ∩ t`). Su demostración es\n--    s ∩ t ⊆ s\n--    ⟹ 𝓟 (s ∩ t) ≤ 𝓟 t\n--           [por principal_mono]\n--    ⟹ f ≤ 𝓟 t\n--           [porque f ≤ 𝓟 (s ∩ t)]\n--    ⟹ a es un punto de acumulación de 𝓟 t\n--           [por cluster_pt.mono y serlo de f]\n--    ⟹ a ∈ clausura(t)\n--           [por mem_closure_iff_cluster_pt]\n--    ⟹ a ∈ t\n--           [por closure_eq_iff_is_closed.mpr y ser t cerrado]\n--\n\nlemma closed_of_compact\n  (s : set X)\n  (hs : is_compact s)\n  (t : set X)\n  (ht : is_closed t)\n  : is_compact (s ∩ t) :=\nbegin\n  unfold is_compact,\n  intros f hnf hstf,\n  haveI := hnf,\n  obtain ⟨a, has, ha⟩ : ∃ a ∈ s, cluster_pt a f,\n  { unfold is_compact at hs,\n    apply hs,\n    apply le_trans hstf,\n    rw principal_mono,\n    apply inter_subset_left },\n  have hat : a ∈ t,\n  { rw ← closure_eq_iff_is_closed.mpr ht,\n    rw mem_closure_iff_cluster_pt,\n    apply cluster_pt.mono ha,\n    refine le_trans hstf _,\n    rw principal_mono,\n    apply inter_subset_right },\n  exact ⟨a, ⟨has, hat⟩, ha⟩\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/5_Filtros/Filtros_y_topologia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526934, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7770380347506044}}
{"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.complex.circle\nimport analysis.inner_product_space.l2_space\nimport measure_theory.function.continuous_map_dense\nimport measure_theory.function.l2_space\nimport measure_theory.measure.haar\nimport measure_theory.group.integration\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 results on 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 : ℤ`, `fourier n` is the monomial `λ z, z ^ n`, bundled as a continuous map from `circle`\n  to `ℂ`\n* for `n : ℤ` and `p : ℝ≥0∞`, `fourier_Lp p n` is an abbreviation for the monomial `fourier n`\n  considered as an element of the Lᵖ-space `Lp ℂ p haar_circle`, via the embedding\n  `continuous_map.to_Lp`\n* `fourier_series` is the canonical isometric isomorphism from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`\n  induced by taking Fourier series\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, ℂ)`, i.e. that its `submodule.topological_closure` is `⊤`.  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 ≤ p < ∞` the span of the monomials\n`fourier_Lp` is dense in `Lp ℂ p haar_circle`, i.e. that its `submodule.topological_closure` is\n`⊤`.  This follows from the previous theorem using general theory on approximation of Lᵖ functions\nby continuous functions.\n\nThe theorem `orthonormal_fourier` states that the monomials `fourier_Lp 2 n` form an orthonormal\nset (in the L² space of the circle).\n\nThe last two results together provide that the functions `fourier_Lp 2 n` form a Hilbert basis for\nL²; this is named as `fourier_series`.\n\nParseval's identity, `tsum_sq_fourier_series_repr`, is a direct consequence of the construction of\nthis Hilbert basis.\n-/\n\nnoncomputable theory\nopen_locale ennreal complex_conjugate classical\nopen topological_space continuous_map measure_theory measure_theory.measure algebra submodule set\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 := ⟨rfl⟩\n\n/-- Haar measure on the circle, normalized to have total measure 1. -/\n@[derive is_haar_measure]\ndef haar_circle : measure circle := haar_measure ⊤\n\ninstance : is_probability_measure haar_circle := ⟨haar_measure_self⟩\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 monomials\n\n/-- The family of monomials `λ z, z ^ n`, parametrized by `n : ℤ` and considered as bundled\ncontinuous maps from `circle` to `ℂ`. -/\n@[simps] def fourier (n : ℤ) : C(circle, ℂ) :=\n{ to_fun := λ z, z ^ n,\n  continuous_to_fun := continuous_subtype_coe.zpow₀ n $ λ z, or.inl (ne_zero_of_mem_circle z) }\n\n@[simp] lemma fourier_zero {z : circle} : fourier 0 z = 1 := rfl\n\n@[simp] lemma fourier_neg {n : ℤ} {z : circle} : fourier (-n) z = conj (fourier n z) :=\nby simp [← coe_inv_circle_eq_conj z]\n\n@[simp] lemma fourier_add {m n : ℤ} {z : circle} :\n  fourier (m + n) z = (fourier m z) * (fourier n z) :=\nby simp [zpow_add₀ (ne_zero_of_mem_circle z)]\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ`; equivalently, polynomials in\n`z` and `conj z`. -/\ndef fourier_subalgebra : subalgebra ℂ C(circle, ℂ) := algebra.adjoin ℂ (range fourier)\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ` is in fact the linear span of\nthese functions. -/\nlemma fourier_subalgebra_coe : fourier_subalgebra.to_submodule = span ℂ (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 (λ _, id) ⟨0, rfl⟩,\n  rintros _ _ ⟨m, rfl⟩ ⟨n, rfl⟩,\n  refine ⟨m + n, _⟩,\n  ext1 z,\n  exact fourier_add,\nend\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ` separates points. -/\nlemma fourier_subalgebra_separates_points : fourier_subalgebra.separates_points :=\nbegin\n  intros x y hxy,\n  refine ⟨_, ⟨fourier 1, _, rfl⟩, _⟩,\n  { exact subset_adjoin ⟨1, rfl⟩ },\n  { simp [hxy] }\nend\n\n/-- The subalgebra of `C(circle, ℂ)` generated by `z ^ n` for `n ∈ ℤ` is invariant under complex\nconjugation. -/\nlemma fourier_subalgebra_conj_invariant :\n  conj_invariant_subalgebra (fourier_subalgebra.restrict_scalars ℝ) :=\nbegin\n  rintros _ ⟨f, hf, rfl⟩,\n  change _ ∈ fourier_subalgebra,\n  change _ ∈ fourier_subalgebra at hf,\n  apply adjoin_induction hf,\n  { rintros _ ⟨n, rfl⟩,\n    suffices : fourier (-n) ∈ fourier_subalgebra,\n    { convert this,\n      ext1,\n      simp },\n    exact subset_adjoin ⟨-n, rfl⟩ },\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, ℂ)` generated by `z ^ n` for `n ∈ ℤ` is dense. -/\nlemma fourier_subalgebra_closure_eq_top : fourier_subalgebra.topological_closure = ⊤ :=\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, ℂ)`. -/\nlemma span_fourier_closure_eq_top : (span ℂ (range fourier)).topological_closure = ⊤ :=\nbegin\n  rw ← fourier_subalgebra_coe,\n  exact congr_arg subalgebra.to_submodule fourier_subalgebra_closure_eq_top,\nend\n\n/-- The family of monomials `λ z, z ^ n`, parametrized by `n : ℤ` and considered as elements of\nthe `Lp` space of functions on `circle` taking values in `ℂ`. -/\nabbreviation fourier_Lp (p : ℝ≥0∞) [fact (1 ≤ p)] (n : ℤ) : Lp ℂ p haar_circle :=\nto_Lp p haar_circle ℂ (fourier n)\n\nlemma coe_fn_fourier_Lp (p : ℝ≥0∞) [fact (1 ≤ p)] (n : ℤ) :\n  ⇑(fourier_Lp p n) =ᵐ[haar_circle] fourier n :=\ncoe_fn_to_Lp haar_circle (fourier n)\n\n/-- For each `1 ≤ p < ∞`, the linear span of the monomials `z ^ n` is dense in\n`Lp ℂ p haar_circle`. -/\nlemma span_fourier_Lp_closure_eq_top {p : ℝ≥0∞} [fact (1 ≤ p)] (hp : p ≠ ∞) :\n  (span ℂ (range (fourier_Lp p))).topological_closure = ⊤ :=\nbegin\n  convert (continuous_map.to_Lp_dense_range ℂ hp haar_circle ℂ).topological_closure_map_submodule\n    span_fourier_closure_eq_top,\n  rw [map_span, range_comp],\n  simp\nend\n\n/-- For `n ≠ 0`, a rotation by `n⁻¹ * real.pi` negates the monomial `z ^ n`. -/\nlemma fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (z : circle) :\n  fourier n ((exp_map_circle (n⁻¹ * real.pi) * z)) = - fourier n z :=\nbegin\n  have : ↑n * ((↑n)⁻¹ * ↑real.pi * complex.I) = ↑real.pi * complex.I,\n  { have : (n:ℂ) ≠ 0 := by exact_mod_cast hn,\n    field_simp,\n    ring },\n  simp [mul_zpow₀, ← 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 ℂ (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, ← fourier_neg, ← fourier_add, -fourier_to_fun] },\n  simp only [← fourier_add, ← fourier_neg],\n  have hij : -i + j ≠ 0,\n  { rw add_comm,\n    exact sub_ne_zero.mpr (ne.symm h) },\n  exact integral_eq_zero_of_mul_left_eq_neg (fourier_add_half_inv_index hij)\nend\n\nend monomials\n\nsection fourier\n\n/-- We define `fourier_series` to be a `ℤ`-indexed Hilbert basis for `Lp ℂ 2 haar_circle`, which by\ndefinition is an isometric isomorphism from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`. -/\ndef fourier_series : hilbert_basis ℤ ℂ (Lp ℂ 2 haar_circle) :=\nhilbert_basis.mk orthonormal_fourier (span_fourier_Lp_closure_eq_top (by norm_num))\n\n/-- The elements of the Hilbert basis `fourier_series` for `Lp ℂ 2 haar_circle` are the functions\n`fourier_Lp 2`, the monomials `λ z, z ^ n` on the circle considered as elements of `L2`. -/\n@[simp] lemma coe_fourier_series : ⇑fourier_series = fourier_Lp 2 := hilbert_basis.coe_mk _ _\n\n/-- Under the isometric isomorphism `fourier_series` from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`, the\n`i`-th coefficient is the integral over the circle of `λ t, t ^ (-i) * f t`. -/\nlemma fourier_series_repr (f : Lp ℂ 2 haar_circle) (i : ℤ) :\n  fourier_series.repr f i = ∫ t : circle, t ^ (-i) * f t ∂ haar_circle :=\nbegin\n  transitivity ∫ t : circle, conj ((fourier_Lp 2 i : circle → ℂ) t) * f t ∂ haar_circle,\n  { simp [fourier_series.repr_apply_apply f i, measure_theory.L2.inner_def] },\n  apply integral_congr_ae,\n  filter_upwards [coe_fn_fourier_Lp 2 i] with _ ht,\n  rw [ht, ← fourier_neg],\n  simp [-fourier_neg]\nend\n\n/-- The Fourier series of an `L2` function `f` sums to `f`, in the `L2` topology on the circle. -/\nlemma has_sum_fourier_series (f : Lp ℂ 2 haar_circle) :\n  has_sum (λ i, fourier_series.repr f i • fourier_Lp 2 i) f :=\nby simpa using hilbert_basis.has_sum_repr fourier_series f\n\n/-- **Parseval's identity**: the sum of the squared norms of the Fourier coefficients equals the\n`L2` norm of the function. -/\nlemma tsum_sq_fourier_series_repr (f : Lp ℂ 2 haar_circle) :\n  ∑' i : ℤ, ∥fourier_series.repr f i∥ ^ 2 = ∫ t : circle, ∥f t∥ ^ 2 ∂ haar_circle :=\nbegin\n  have H₁ : ∥fourier_series.repr f∥ ^ 2 = ∑' i, ∥fourier_series.repr f i∥ ^ 2,\n  { exact_mod_cast lp.norm_rpow_eq_tsum _ (fourier_series.repr f),\n    norm_num },\n  have H₂ : ∥fourier_series.repr f∥ ^ 2 = ∥f∥ ^2 := by simp,\n  have H₃ := congr_arg is_R_or_C.re (@L2.inner_def circle ℂ ℂ _ _ _ _ f f),\n  rw ← integral_re at H₃,\n  { simp only [← norm_sq_eq_inner] at H₃,\n    rw [← H₁, H₂],\n    exact H₃ },\n  { exact L2.integrable_inner f f },\nend\n\nend fourier\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/fourier.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8267117983401362, "lm_q1q2_score": 0.7770374529356319}}
{"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.spectrum\nimport linear_algebra.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\nnamespace matrix\n\nvariables {𝕜 : Type*} [is_R_or_C 𝕜] [decidable_eq 𝕜] {n : Type*} [fintype n] [decidable_eq n]\nvariables {A : matrix n n 𝕜}\n\nopen_locale matrix\nopen_locale big_operators\n\nnamespace is_hermitian\n\nvariables (hA : A.is_hermitian)\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₀ : fin (fintype.card n) → ℝ :=\n(is_hermitian_iff_is_symmetric.1 hA).eigenvalues finrank_euclidean_space\n\n/-- The eigenvalues of a hermitian matrix, reusing the index `n` of the matrix entries. -/\nnoncomputable def eigenvalues : n → ℝ :=\nλ i, hA.eigenvalues₀ $ (fintype.equiv_of_card_eq (fintype.card_fin _)).symm i\n\n/-- A choice of an orthonormal basis of eigenvectors of a hermitian matrix. -/\nnoncomputable def eigenvector_basis : orthonormal_basis n 𝕜 (euclidean_space 𝕜 n) :=\n((is_hermitian_iff_is_symmetric.1 hA).eigenvector_basis finrank_euclidean_space).reindex\n  (fintype.equiv_of_card_eq (fintype.card_fin _))\n\n/-- A matrix whose columns are an orthonormal basis of eigenvectors of a hermitian matrix. -/\nnoncomputable def eigenvector_matrix : matrix n n 𝕜 :=\n(pi_Lp.basis_fun _ 𝕜 n).to_matrix (eigenvector_basis hA).to_basis\n\n/-- The inverse of `eigenvector_matrix` -/\nnoncomputable def eigenvector_matrix_inv : matrix n n 𝕜 :=\n(eigenvector_basis hA).to_basis.to_matrix (pi_Lp.basis_fun _ 𝕜 n)\n\nlemma eigenvector_matrix_mul_inv :\n  hA.eigenvector_matrix ⬝ hA.eigenvector_matrix_inv = 1 :=\nby apply basis.to_matrix_mul_to_matrix_flip\n\nnoncomputable instance : invertible hA.eigenvector_matrix_inv :=\ninvertible_of_left_inverse _ _ hA.eigenvector_matrix_mul_inv\n\nnoncomputable instance : invertible hA.eigenvector_matrix :=\ninvertible_of_right_inverse _ _ hA.eigenvector_matrix_mul_inv\n\nlemma eigenvector_matrix_apply (i j : n) : hA.eigenvector_matrix i j = hA.eigenvector_basis j i :=\nby simp_rw [eigenvector_matrix, basis.to_matrix_apply, orthonormal_basis.coe_to_basis,\n    pi_Lp.basis_fun_repr]\n\nlemma eigenvector_matrix_inv_apply (i j : n) :\n  hA.eigenvector_matrix_inv i j = star (hA.eigenvector_basis i j) :=\nbegin\n  rw [eigenvector_matrix_inv, basis.to_matrix_apply, orthonormal_basis.coe_to_basis_repr_apply,\n    orthonormal_basis.repr_apply_apply, pi_Lp.basis_fun_apply, pi_Lp.equiv_symm_single,\n    euclidean_space.inner_single_right, one_mul, is_R_or_C.star_def],\nend\n\nlemma conj_transpose_eigenvector_matrix_inv : hA.eigenvector_matrix_invᴴ = hA.eigenvector_matrix :=\nby { ext i j,\n  rw [conj_transpose_apply, eigenvector_matrix_inv_apply, eigenvector_matrix_apply, star_star] }\n\nlemma conj_transpose_eigenvector_matrix : hA.eigenvector_matrixᴴ = hA.eigenvector_matrix_inv :=\nby rw [← conj_transpose_eigenvector_matrix_inv, conj_transpose_conj_transpose]\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.eigenvector_matrix_inv ⬝ A =\n    diagonal (coe ∘ hA.eigenvalues) ⬝ hA.eigenvector_matrix_inv :=\nbegin\n  rw [eigenvector_matrix_inv, pi_Lp.basis_to_matrix_basis_fun_mul],\n  ext i j,\n  have := is_hermitian_iff_is_symmetric.1 hA,\n  convert this.diagonalization_basis_apply_self_apply finrank_euclidean_space\n    (euclidean_space.single j 1)\n    ((fintype.equiv_of_card_eq (fintype.card_fin _)).symm i) using 1,\n  { dsimp only [euclidean_space.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, orthonormal_basis.coe_to_basis_repr_apply,\n      orthonormal_basis.repr_reindex],\n    refl },\n  { simp only [diagonal_mul, (∘), eigenvalues],\n    rw [eigenvector_basis, basis.to_matrix_apply,\n      orthonormal_basis.coe_to_basis_repr_apply, orthonormal_basis.repr_reindex,\n      eigenvalues₀, pi_Lp.basis_fun_apply, pi_Lp.equiv_symm_single] }\nend\n\nlemma eigenvalues_eq (i : n) :\n  hA.eigenvalues i =\n    is_R_or_C.re ((star (hA.eigenvector_matrixᵀ i) ⬝ᵥ (A.mul_vec (hA.eigenvector_matrixᵀ i)))) :=\nbegin\n  have := hA.spectral_theorem,\n  rw [←matrix.mul_inv_eq_iff_eq_mul_of_invertible] at this,\n  have := congr_arg is_R_or_C.re (congr_fun (congr_fun this i) i),\n  rw [diagonal_apply_eq, is_R_or_C.of_real_re, inv_eq_left_inv hA.eigenvector_matrix_mul_inv,\n    ← conj_transpose_eigenvector_matrix, mul_mul_apply] at this,\n  exact this.symm,\nend\n\n/-- The determinant of a hermitian matrix is the product of its eigenvalues. -/\nlemma det_eq_prod_eigenvalues : det A = ∏ i, hA.eigenvalues i :=\nbegin\n  apply mul_left_cancel₀ (det_ne_zero_of_left_inverse (eigenvector_matrix_mul_inv hA)),\n  rw [←det_mul, spectral_theorem, det_mul, mul_comm, det_diagonal]\nend\n\nend is_hermitian\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/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133464597458, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7770374489227069}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el rango de la función exponencial es el\n-- conjunto de los números positivos,\n-- ----------------------------------------------------------------------\n\nimport analysis.special_functions.exp_log\n\nopen set real\n\nexample : range exp = { y | y > 0 } :=\nbegin\n  ext y,\n  split,\n  { rintros ⟨x, rfl⟩,\n    apply exp_pos },\n  { intro ypos,\n    use log y,\n    rw exp_log ypos },\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ range exp = {y : ℝ | y > 0}\n  >> ext y,\ny : ℝ\n⊢ y ∈ range exp ↔ y ∈ {y : ℝ | y > 0}\n  >> split,\n| y : ℝ\n| ⊢ y ∈ range exp ↔ y ∈ {y : ℝ | y > 0}\n|   >> { rintros ⟨x, rfl⟩\n| x : ℝ\n| ⊢ x.exp ∈ {y : ℝ | y > 0},\n|   >>   apply exp_pos },\ny : ℝ\n⊢ y ∈ {y : ℝ | y > 0} → y ∈ range exp\n  >> { intro ypos,\nypos : y ∈ {y : ℝ | y > 0}\n⊢ y ∈ range exp\n  >>   use log y,\n⊢ y.log.exp = y\n  >>   rw exp_log ypos },\n⊢ y.log.exp = y\n-/\n\n-- Comentario: Se ha usado el lema\n-- + exp_log : 0 < x → log (exp x) = x\n\nvariable (x : ℝ)\n-- #check @exp_log 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/Rango_de_la_exponencial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7770362781833172}}
{"text": "import MyNat.Definition\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level2 -- add_assoc\nimport InequalityWorld.Level2 -- le_refl_mynat\nimport Mathlib.Init.Algebra.Order\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 5: `le_trans`\n\nAnother straightforward one.\n\n## Lemma : le_trans\n≤ is transitive. In other words, if `a ≤ b` and `b ≤ c` then `a ≤ c`.\n-/\ntheorem le_trans (a b c : MyNat) (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := by\n  cases hab with\n  | _ d hd =>\n    cases hbc with\n    | _ e he =>\n      use (d + e)\n      rw [←add_assoc]\n      rw [←hd]\n      assumption\n\n/-!\nThis proved that the natural numbers are a preorder.\n-/\n\ninstance : Preorder MyNat :=\n  ⟨le_refl_mynat, le_trans, lt⟩\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/InequalityWorld/Level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205503, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7770317662998534}}
{"text": "--import mynat.lt -- definition of <\nimport game.world10.level14 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\n## Level 15: introducing `<`\n\nTo get the remaining collectibles in this world, we need to\ngive a definition of `<`. By default, the definition of `a < b`\nin Lean, once `≤` is defined, is this:\n\n`a < b := a ≤ b ∧ ¬ (b ≤ a)`\n\n. But a much more usable definition would be this:\n\n`a < b := succ(a) ≤ b`\n\n. Let's prove that these two definitions are the same\n-/\n\n/- Lemma : \nFor all naturals $a$ and $b$,\n$$a\\le b\\land\\lnot(b\\le a)\\implies\\operatorname{succ}(a)\\le b.$$\n-/\nlemma lt_aux_one (a b : mynat) : a ≤ b ∧ ¬ (b ≤ a) → succ a ≤ b :=\nbegin [nat_num_game]\n  intro h,\n  cases h with h1 h2,\n  cases h1 with c hc,\n  cases c with d,\n    exfalso,\n    rw add_zero at hc,\n    apply h2,\n    rw hc,\n    refl,\n  use d,\n  rw hc,\n  rw add_succ,\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/level15.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7770317641876074}}
{"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 →ₗ[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 →ₗ[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 →ₗ[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 →ₗ[R] M`. -/\ndef charpoly : R[X] :=\n(to_matrix (choose_basis R M) (choose_basis R M) f).charpoly\n\nlemma charpoly_def :\n  f.charpoly = (to_matrix (choose_basis R M) (choose_basis R M) f).charpoly := rfl\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, ← alg_equiv.coe_alg_hom,\n    ← polynomial.aeval_alg_hom_apply _ _ _, charpoly_def],\n  exact aeval_self_charpoly _,\nend\n\nlemma is_integral : is_integral R f := ⟨f.charpoly, ⟨charpoly_monic f, aeval_self_charpoly f⟩⟩\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 →ₗ[K] M) : minpoly K f ∣ f.charpoly :=\nminpoly.dvd _ _ (aeval_self_charpoly f)\n\n/-- Any endomorphism polynomial `p` is equivalent under evaluation to `p %ₘ 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 %ₘ 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 : ℕ) : f^k = aeval f (X^k %ₘ f.charpoly) :=\nby rw [←aeval_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 ≠ 0 :=\nbegin\n  intro h,\n  obtain ⟨P, hP⟩ := 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 (λ 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, ← 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": "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/charpoly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109812297142, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7770317580353245}}
{"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\nimport computability.DFA\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\nuniverses u v\n\n/-- An NFA is a set of states (`σ`), 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 (α : Type u) (σ : Type v) :=\n(step : σ → α → set σ)\n(start : set σ)\n(accept : set σ)\n\nvariables {α : Type u} {σ σ' : Type v} (M : NFA α σ)\n\nnamespace NFA\n\ninstance : inhabited (NFA α σ) := ⟨ NFA.mk (λ _ _, ∅) ∅ ∅ ⟩\n\n/-- `M.step_set S a` is the union of `M.step s a` for all `s ∈ S`. -/\ndef step_set : set σ → α → set σ :=\nλ Ss a, Ss >>= (λ S, (M.step S a))\n\n\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 σ) : list α → set σ :=\nlist.foldl M.step_set start\n\n/-- `M.eval x` computes all possible paths though `M` with input `x` starting at an element of\n  `M.start`. -/\ndef eval := M.eval_from M.start\n\n/-- `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. -/\ndef accepts : language α :=\nλ x, ∃ S ∈ M.accept, S ∈ 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 α (set σ) :=\n{ step := M.step_set,\n  start := M.start,\n  accept := {S | ∃ s ∈ S, s ∈ 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 _ _ _ ∈ {S | _} ↔ _,\n  finish\nend\n\nlemma pumping_lemma [fintype σ] {x : list α} (hx : x ∈ M.accepts)\n  (hlen : fintype.card (set σ) + 1 ≤ list.length x) :\n  ∃ a b c, x = a ++ b ++ c ∧ a.length + b.length ≤ fintype.card (set σ) + 1 ∧ b ≠ [] ∧\n  {a} * language.star {b} * {c} ≤ M.accepts :=\nbegin\n  rw ←to_DFA_correct at hx ⊢,\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 α σ') : NFA α σ' :=\n{ step := λ 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 α σ) (start : σ) (s : list α) :\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    have h : M.to_NFA.step_set {start} a = {M.step start a},\n    { rw NFA.step_set,\n      finish },\n    rw h,\n    tauto }\nend\n\n@[simp] lemma to_NFA_correct (M : DFA α σ) :\n  M.to_NFA.accepts = M.accepts :=\nbegin\n  ext x,\n  change (∃ S H, S ∈ M.to_NFA.eval_from {M.start} x) ↔ _,\n  rw to_NFA_eval_from_match,\n  split,\n  { rintro ⟨ S, hS₁, hS₂ ⟩,\n    rw set.mem_singleton_iff at hS₂,\n    rw hS₂ at hS₁,\n    assumption },\n  { intro h,\n    use M.eval x,\n    finish }\nend\n\nend DFA\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/NFA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7769470248577579}}
{"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\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 →+* 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 →+* 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 : ℕ) [char_p R p] : char_p A p :=\n{ cast_eq_zero_iff := λx,\n  begin\n    rw ←char_p.cast_eq_zero_iff R p x,\n    change algebra_map ℕ A x = 0 ↔ algebra_map ℕ R x = 0,\n    rw is_scalar_tower.algebra_map_apply ℕ 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 : ℕ) [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 →+* 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 := λ x y hxy,\n  begin\n    change algebra_map ℕ A x = algebra_map ℕ A y at hxy,\n    rw is_scalar_tower.algebra_map_apply ℕ R A x at hxy,\n    rw is_scalar_tower.algebra_map_apply ℕ 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\nsection\n\nvariables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]\n\nlemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=\n(algebra_map K L).char_p_iff_char_p p\n\nend\n\nnamespace free_algebra\n\nvariables {R X : Type*} [comm_semiring R] (p : ℕ)\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 : ℕ)\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": "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/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7769470231264706}}
{"text": "/- LoVe Exercise 3: Structured Proofs and Proof Terms -/\n\nimport .lovelib\n\nnamespace LoVe\n\n\n/- Question 1: Chain of Equalities -/\n\n/- 1.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 `rw`, `simp`, `ac_refl`, and the lemmas `mul_add`,\n`add_mul`, and `two_mul`. -/\n\nlemma binomial_square (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/- 1.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₂ (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\n\n/- 1.3 (**optional**). Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square₃ (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  sorry\nend\n\n\n/- Question 2: Connectives and Quantifiers -/\n\n/- 2.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a → a :=\nsorry\n\nlemma K (a b : Prop) :\n  a → b → b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nsorry\n\n-- please give a different answer than for `proj_1st`\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nsorry\n\n/- 2.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\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/love03_structured_proofs_and_proof_terms_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8887587846530938, "lm_q1q2_score": 0.7768438153873994}}
{"text": "/-\nGiven propositions P and Q, to prove P ↔ Q \nrequires a proof of P → Q and a proof of \nQ → P. The introduction rule is iff.intro :\n(P → Q) → (Q → P) → P ↔ Q.\n-/\n\n#check iff\n#check @iff.intro\n\n/-\nstructure iff (a b : Prop) : Prop :=\nintro :: (mp : a → b) (mpr : b → a)\n-/\n\n/-\nIt's a special case of and. The elimination\nrules are analogous, too. Remember reading\nthe next types that → is right associative.\n-/\n\n#check @iff.elim_left\n#check @iff.elim_right\n\n\n/-\nExample. 1 = 1 ↔ 0 = 0.\n-/\n\nexample : 1 = 1 ↔ 0 = 0 :=\niff.intro \n  (λ _, rfl)   -- ⊢ 1 = 1 → 0 = 0\n  (λ _, rfl)   -- ⊢ 0 = 0 → 1 = 1\n\n/-\nAnd so for the eliminators.\n-/\n\n#check @iff.elim_left\n#check @iff.elim_right\n\n/- \nShow: ∀ (P Q : Prop), (P ↔ Q) → Q → P.\n-/\n\nexample : ∀ (P Q : Prop), (P ↔ Q) → Q → P := \nλ P Q h q,    \n  -- use what you have to make what you need\n  _\n\n\n/-\nGeneral requirement to prove P ↔ Q is to \ngive proofs of P → Q and Q → P to ↔-intro. \nThat is, apply ↔-intro to a proof of P → Q\nand a proof of Q → P. Thus:\n\niff.intro : (P → Q) → (Q → P) → (P ↔ Q)\niff.elim_left : (P ↔ Q) → (P → Q)\niff.elim_right : (P ↔ Q) → (Q → P)\n-/\n\n-- Exercise: Try it to test yourself.\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/iff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8479677660619634, "lm_q1q2_score": 0.7768314283298436}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que lo función logarítmica es inyectiva sobre\n-- los números positivos.\n-- ----------------------------------------------------------------------\n\nimport analysis.special_functions.exp_log\n\nopen set real\n\nexample : inj_on log { x | x > 0 } :=\nbegin\n  intros x xpos y ypos,\n  intro h,\n  calc\n    x   = exp (log x) : by rw exp_log xpos\n    ... = exp (log y) : by rw h\n    ... = y           : by rw exp_log ypos,\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ inj_on log {x : ℝ | x > 0}\n  >> intros x y xpos ypos,\nx y : ℝ,\nxpos : x ∈ {x : ℝ | x > 0},\nypos : y ∈ {x : ℝ | x > 0}\n⊢ x.log = y.log → x = y\n  >> intro h,\nh : x.log = y.log\n⊢ x = y\n  >> calc\n  >>   x   = exp (log x) : by rw exp_log xpos\n  >>   ... = exp (log y) : by rw h\n  >>   ... = y           : by rw exp_log ypos,\n-/\n\n-- Comentario: Se ha usado el lema\n-- + exp_log : 0 < x → exp (log x) = x\n\n-- Comprobación:\nvariable (x : ℝ)\n-- #check @exp_log 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_logaritmo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7768314166767739}}
{"text": "-- this is a proof that ∀ vectors a, b ∈ ℤ³, \n-- (a × b) ⬝ a = 0 ∧ (a × b) ⬝ b = 0\n\ndef dot: ℤ × ℤ × ℤ → ℤ × ℤ × ℤ → ℤ := λ ⟨a, b, c⟩ ⟨d, e, f⟩, a*d + b*e + c*f\ndef cross: ℤ × ℤ × ℤ → ℤ × ℤ × ℤ → ℤ × ℤ × ℤ := λ ⟨a, b, c⟩ ⟨d, e, f⟩, ⟨b*f - c*e, c*d - a*f, a*e - b*d⟩\n\nvariables m n p j k l : ℤ\n#eval cross (124, 1294, 123) (156, 949, 29238499)\n#reduce dot (cross (8, 1, 5) (2, 8, 9)) (2, 8, 9)\n#reduce dot (cross (m, n, p) (j, k, l)) (j, k, l)\n\ntheorem cross' (a b c d e f: ℤ) : cross (a, b, c) (d, e, f) = (b*f - c*e, c*d - a*f, a*e - b*d) := rfl\ntheorem dot' (a b c d e f: ℤ) : dot (a, b, c) (d, e, f) = a*d + b*e + c*f := rfl\n\nlocal attribute [simp] mul_comm mul_assoc mul_right_comm\n\ntheorem proof1 : ∀ {a b c d e f: ℤ}, dot (cross (a, b, c) (d, e, f)) (a, b, c) = 0 :=\nassume a b c d e f,\ncalc\n    dot (cross (a, b, c) (d, e, f)) (a, b, c) = dot (b*f - c*e, c*d - a*f, a*e - b*d) (a, b, c) : by rw cross'\n    ... = (b*f - c*e)*a + (c*d - a*f)*b + (a*e - b*d)*c : by rw dot'\n    ... = b*f*a - c*e*a + (c*d*b - a*f*b) + (a*e*c - b*d*c) : by repeat {rw sub_mul}\n    ... = 0 : by simp\n#check proof1\n\ntheorem proof2 : ∀ {a b c d e f: ℤ}, dot (cross (a, b, c) (d, e, f)) (d, e, f) = 0 :=\nassume a b c d e f,\ncalc\n    dot (cross (a, b, c) (d, e, f)) (d, e, f) = dot (b*f - c*e, c*d - a*f, a*e - b*d) (d, e, f) : by rw cross'\n    ... = (b*f - c*e)*d + (c*d - a*f)*e + (a*e - b*d)*f : by rw dot'\n    ... = b*f*d - c*e*d + (c*d*e - a*f*e) + (a*e*f - b*d*f) : by repeat {rw sub_mul}\n    ... = a * (e * f) + (c * (d * e) + (-(a * (e * f)) + -(c * (d * e)))) : by simp\n    ... = a * (e * f) + (c * (d * e) + -(a * (e * f)) + -(c * (d * e))) : by rw add_assoc\n    ... = 0 : by simp\n\n#check proof2\n\nexample (a b c d e f: ℤ) : \n     dot (cross (a, b, c) (d, e, f)) (a, b, c) = 0 ∧ dot (cross (a, b, c) (d, e, f)) (d, e, f) = 0 :=\n    and.intro proof1 proof2", "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/int_vector3d_cross.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7767514096722127}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sea x un número real tal que para todo número positivo ε,\n-- x ≤ ε Demostrar que x ≤ 0.\n-- ----------------------------------------------------------------------\n\n\nimport data.real.basic\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (x : ℝ) \n  (h : ∀ ε > 0, x ≤ ε) \n  : x ≤ 0 :=\nbegin\n  apply le_of_not_gt,\n  intro hx0,\n  specialize h (x/2),\n  have h1 : x ≤ x / 2,\n    { apply h,\n      apply half_pos hx0},\n  have : x / 2 < x,\n    { apply half_lt_self hx0 },\n  linarith,\nend\n\n-- Prueba\n-- ======\n\n-- x : ℝ,\n-- h : ∀ (ε : ℝ), ε > 0 → x ≤ ε\n-- ⊢ x ≤ 0\n--    >> apply le_of_not_gt,\n-- ⊢ ¬x > 0\n--    >> intro hx0,\n-- hx0 : x > 0\n-- ⊢ false\n--    >> specialize h (x/2),\n-- h : x / 2 > 0 → x ≤ x / 2\n-- ⊢ false\n--    >> have h1 : x ≤ x / 2,\n--    >>   { apply h,\n-- ⊢ x / 2 > 0\n--    >>     apply half_pos hx0},\n-- h1 : x ≤ x / 2\n-- ⊢ false\n--    >> have : x / 2 < x,\n--    >>   { apply half_lt_self hx0 },\n-- this : x / 2 < x\n-- ⊢ false\n--    >> linarith,\n-- no goals\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (x : ℝ) \n  (h : ∀ ε > 0, x ≤ ε) \n  : x ≤ 0 :=\nbegin\n  contrapose! h,\n  use x / 2,\n  split; linarith,\nend\n\n-- Prueba\n-- ======\n\n-- x : ℝ,\n-- h : ∀ (ε : ℝ), ε > 0 → x ≤ ε\n-- ⊢ x ≤ 0\n--    >> contrapose! h,\n-- h : 0 < x\n-- ⊢ ∃ (ε : ℝ), ε > 0 ∧ ε < x\n--    >> use x / 2,\n-- ⊢ x / 2 > 0 ∧ x / 2 < x\n--    >> split; linarith\n-- no 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/Condicion_para_no_positivo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.865224070413529, "lm_q1q2_score": 0.7767075793644158}}
{"text": "-- Monotonia_de_la_multiplicacion_por_no_negativo.lean\n-- Monotonía de la multiplicación por no negativo.\n-- José A. Alonso Jiménez\n-- Sevilla, 22 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a, b y c son números reales tales que \n-- 0 ≤ c y a ≤ b, entonces a*c ≤ b*c.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {a b c : ℝ}\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (hc : 0 ≤ c) \n  (hab : a ≤ b) \n  : a * c ≤ b * c :=\nbegin\n  rw ← sub_nonneg,\n  have h : b * c - a * c = (b - a) * c,\n  { ring },\n  { rw h,\n    apply mul_nonneg,\n    { rw sub_nonneg,\n      exact hab },\n    { exact hc }},\nend\n\n-- Comentario: Se ha usado el lema\n-- + mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (hc : 0 ≤ c) \n  (hab : a ≤ b) \n  : a * c ≤ b * c :=\nbegin\n  have hab' : 0 ≤ b - a,\n  { rw ← sub_nonneg at hab,\n    exact hab, },\n  have h1 : 0 ≤ (b - a) * c,\n  { exact mul_nonneg hab' hc, },\n  have h2 : (b - a) * c = b * c - a * c,\n  { ring, },\n  have h3 : 0 ≤ b * c - a * c,\n  { rw h2 at h1,\n    exact h1, },\n  rw sub_nonneg at h3,\n  exact h3,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample \n  (hc : 0 ≤ c) \n  (hab : a ≤ b) \n  : a * c ≤ b * c :=\nbegin\n  have hab' : 0 ≤ b - a,\n  { rwa ← sub_nonneg at hab, },\n  have h1 : 0 ≤ (b - a) * c,\n  { exact mul_nonneg hab' hc },\n  have h2 : (b - a) * c = b * c - a * c,\n  { ring, },\n  have h3 : 0 ≤ b * c - a * c,\n  { rwa h2 at h1, },\n  rwa sub_nonneg at h3,\nend\n\n-- Comentario: \n-- + La táctica (rwa h at h'), cuando h es una igualdad. sustituye en la\n--   hipótesis h' el término izquierdo de h por el derecho y, a\n--   continuación, aplica assumption.\n-- + La táctica (rwa ← h at h'), cuando h es una igualdad, sustituye en\n--   la hipótesis h' el término derecho de h por el izquierdo y, a\n--   continuación, aplica assumption.\n\n-- 4ª demostración\n-- ===============\n\nexample \n  (hc : 0 ≤ c) \n  (hab : a ≤ b) \n  : a * c ≤ b * c :=\nbegin\n  rw ← sub_nonneg,\n  calc 0 ≤ (b - a)*c  : mul_nonneg (by rwa sub_nonneg) hc\n     ... =  b*c - a*c : by ring,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample \n  (hc : 0 ≤ c) \n  (hab : a ≤ b) \n  : a * c ≤ b * c :=\nmul_mono_nonneg hc hab\n\n-- Comentario: Se usa el lema\n-- + mul_mono_nonneg : 0 ≤ c → a ≤ b → a * c ≤ b * c \n\n-- 6ª demostración\n-- ===============\n\nexample \n  (hc : 0 ≤ c) \n  (hab : a ≤ b) \n  : a * c ≤ b * c :=\nby nlinarith\n\n-- Comentario: \n-- + La táctica nlinarith es una extensión de linarith con un\n--   preprocesamiento que permite resolver problemas aritméticos no\n--   lineales.  \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/Monotonia_de_la_multiplicacion_por_no_negativo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343393, "lm_q2_score": 0.8902942304882371, "lm_q1q2_score": 0.7766458435214553}}
{"text": "/- LoVe Homework 6: Monads -/\n\nimport .lovelib\n\nnamespace LoVe\n\n\n/- Question 1: `map` for Monads\n\nDefine `map` for monads. This is the generalization of `map` on lists. Use the\nmonad operations to define `map`. The functorial properties (`map_id` and\n`map_map`) are derived from the monad laws.\n\nThis time, we use Lean's monad definition. In combination, `monad` and\n`is_lawful_monad` include the same constants, laws, and syntactic sugar as the\n`lawful_monad` type class from the lecture. -/\n\nsection map\n\n/- We fix a lawful monad `m`: -/\n\nvariables {m : Type → 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 β`. Follow the types.\nOne way to proceed is to list all the arguments and operations\navailable (e.g., `pure`, `>>=`) with their types and see if you can plug\nthem together like Lego blocks. -/\n\ndef map {α β} (f : α → β) (ma : m α) : m β :=\n:= sorry\n\n/- 1.2. Prove the identity law for `map`.\n\n**Hint**: You will need the `bind_pure` property of monads. -/\n\nlemma map_id {α} (ma : m α) : map id ma = ma :=\nsorry\n\n/- 1.3. Prove the composition law for `map`. -/\n\nlemma map_map {α β γ} (f : α → β) (g : β → γ) (ma : m α) :\n  map g (map f ma) = map (g ∘ f) ma :=\nsorry\n\nend map\n\n\n/- Question 2 **optional**: Monadic Structure on Lists -/\n\n/- `list` can be seen as a monad, similar to `option` but with several possible\noutcomes. It is also similar to `set`, but the results are ordered and finite.\nThe code below sets `list` up as a monad. -/\n\nnamespace list\n\nprotected def bind {α β : Type} : list α → (α → list β) → list β\n| []        f := []\n| (a :: as) f := f a ++ bind as f\n\nprotected def pure {α : Type} (a : α) : list α :=\n[a]\n\nlemma pure_eq_singleton {α : Type} (a : α) :\n  pure a = [a] :=\nby refl\n\ninstance : monad list :=\n{ pure := @list.pure,\n  bind := @list.bind }\n\n/- 2.1 **optional**. Prove the following properties of `bind` under the empty\nlist (`[]`), the list constructor (`::`), and `++`. -/\n\n@[simp] lemma bind_nil {α β : Type} (f : α → list β) :\n  [] >>= f = [] :=\nsorry\n\n@[simp] lemma bind_cons {α β : Type} (f : α → list β) (a : α) (as : list α) :\n  list.cons a as >>= f = f a ++ (as >>= f) :=\nsorry\n\n@[simp] lemma bind_append {α β : Type} (f : α → list β) :\n  ∀as as' : list α, (as ++ as') >>= f = (as >>= f) ++ (as' >>= f)\n:= sorry\n\n/- 2.2. Prove the monadic laws for `list`.\n\n**Hint:** The simplifier cannot see through the type class definition of `pure`.\nYou can use `pure_eq_singleton` to unfold the definition or `show` to state the\nlemma statement using `bind` and `[…]`. -/\n\nlemma pure_bind {α β : Type} (a : α) (f : α → list β) :\n  (pure a >>= f) = f a :=\nsorry\n\nlemma bind_pure {α : Type} :\n  ∀as : list α, as >>= pure = as\n:= sorry\n\nlemma bind_assoc {α β γ : Type} (f : α → list β) (g : β → list γ) :\n  ∀as : list α, (as >>= f) >>= g = as >>= (λa, f a >>= g)\n:= sorry\n\nlemma bind_pure_comp_eq_map {α β : Type} {f : α → β} :\n  ∀as : list α, as >>= (pure ∘ f) = list.map f as\n:= sorry\n\nend list\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/love06_monads_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8723473846343394, "lm_q1q2_score": 0.7766458346341385}}
{"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: Scott Morrison\n\n! This file was ported from Lean 3 source module data.int.dvd.basic\n! leanprover-community/mathlib commit e1bccd6e40ae78370f01659715d3c948716e3b7e\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.Nat.Cast.Basic\n\n/-!\n# Basic lemmas about the divisibility relation in `ℤ`.\n-/\n\n\nopen Nat\n\nnamespace Int\n\n@[norm_cast]\ntheorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n :=\n  ⟨fun ⟨a, ae⟩ =>\n    m.eq_zero_or_pos.elim (fun m0 => by simp [m0] at ae; simp [ae, m0]) fun m0l => by\n      cases'\n        eq_ofNat_of_zero_le\n          (@nonneg_of_mul_nonneg_right ℤ _ m a (by simp [ae.symm]) (by simpa using m0l)) with\n        k e\n      subst a\n      exact ⟨k, Int.ofNat.inj ae⟩,\n    fun ⟨k, e⟩ => Dvd.intro k <| by rw [e, Int.ofNat_mul]⟩\n#align int.coe_nat_dvd Int.coe_nat_dvd\n\ntheorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.natAbs := by\n  rcases natAbs_eq z with (eq | eq) <;> rw [eq] <;> simp [←coe_nat_dvd]\n#align int.coe_nat_dvd_left Int.coe_nat_dvd_left\n\ntheorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.natAbs ∣ n := by\n  rcases natAbs_eq z with (eq | eq) <;> rw [eq] <;> simp [←coe_nat_dvd]\n#align int.coe_nat_dvd_right Int.coe_nat_dvd_right\n\n#align int.le_of_dvd Int.le_of_dvd\n\n#align int.eq_one_of_dvd_one Int.eq_one_of_dvd_one\n\n#align int.eq_one_of_mul_eq_one_right Int.eq_one_of_mul_eq_one_right\n\n#align int.eq_one_of_mul_eq_one_left Int.eq_one_of_mul_eq_one_left\n\ntheorem ofNat_dvd_of_dvd_natAbs {a : ℕ} : ∀ {z : ℤ} (_ : a ∣ z.natAbs), ↑a ∣ z\n  | Int.ofNat _, haz => Int.coe_nat_dvd.2 haz\n  | -[k+1], haz => by\n    change ↑a ∣ -(k + 1 : ℤ)\n    apply dvd_neg_of_dvd\n    apply Int.coe_nat_dvd.2\n    exact haz\n#align int.of_nat_dvd_of_dvd_nat_abs Int.ofNat_dvd_of_dvd_natAbs\n\ntheorem dvd_natAbs_of_ofNat_dvd {a : ℕ} : ∀ {z : ℤ} (_ : ↑a ∣ z), a ∣ z.natAbs\n  | Int.ofNat _, haz => Int.coe_nat_dvd.1 (Int.dvd_natAbs.2 haz)\n  | -[k+1], haz =>\n    have haz' : (↑a : ℤ) ∣ (↑(k + 1) : ℤ) := dvd_of_dvd_neg haz\n    Int.coe_nat_dvd.1 haz'\n#align int.dvd_nat_abs_of_of_nat_dvd Int.dvd_natAbs_of_ofNat_dvd\n\n#align int.dvd_antisymm Int.dvd_antisymm\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/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788077, "lm_q2_score": 0.8723473862936943, "lm_q1q2_score": 0.7766458310329857}}
{"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 {α β γ A B C: Type*}\n\ndef union (r : α → β → Prop) (s : α → β → Prop) (a : α) (b : β) : Prop := r a b ∨ s a b\ndef intersect (r : α → β → Prop) (s : α → β → Prop) (a : α) (b : β) : Prop := r a b ∧ s a b\ndef transpose (r : α → β → Prop) (b : β) (a : α) : Prop := r a b\ndef complement (r : α → β → Prop) (a : α) (b : β) : Prop := ¬(r a b)\ndef comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ (b : β), r a b ∧ p b c\n\ndef reflexive (R : A → A → Prop) : Prop := ∀ x, R x x\ndef irreflexive (R : A → A → Prop) : Prop := ∀ x, ¬ R x x\ndef symmetric (R : A → A → Prop) : Prop := ∀ x y, R x y → R y x\ndef asymmetric (R : A → A → Prop) : Prop := ∀ (a b : A), R a b → ¬(R b a)\ndef transitive (R : A → A → Prop) : Prop := ∀ x y z, R x y → R y z → R x z\ndef anti_symmetric (R : A → A → Prop) : Prop := ∀ x y, R x y → R y x → x = y\n\ndef preorder (R : A → A → Prop) : Prop := reflexive R ∧ transitive R\ndef total (R : A → A → Prop) : Prop := ∀ x y, R x y ∨ R y x\ndef partial_order (R : A → A → Prop) : Prop := preorder R ∧ anti_symmetric R\ndef total_order (R : A → A → Prop) : Prop := partial_order R ∧ total R\ndef strict_order (R : A → A → Prop) : Prop := transitive R ∧ asymmetric R\n\n-- Miscellaneous problems related to composition\n\n-- For relations (R S : A → A → Prop), \n-- (1)  if R and S are reflexive, is R ∘ S reflexive?\n-- (2)  if R and S are symmetric, is R ∘ S symmetric?\n-- (3)  if R and S are transitive, is R ∘ S transitive?\n-- (4)  if R and S are anti-symmetric, is R ∘ S anti-symmetric?\n-- (5)  if R and S are asymmetric, is R ∘ S asymmetric?\n-- (6)  if R and S are irreflexive, is R ∘ S irreflexive?\n-- (7)  if R and S are total, is R ∘ S total?\n\n-- (1) Reflexivity: Preserved under composition\nexample (R S : A → A → Prop) (reflR : reflexive R) (reflS : reflexive S) : reflexive (comp R S) :=\nbegin\n  intro x,\n  use x, -- x is the required intermediate element\n  split,\n  { apply reflR x}, -- show R x x true, followed from reflexivity of R\n  { apply reflS x}, -- show S x x true, followed from reflexivity of S\nend\n\n-- (2) Symmetry: Not preserved under composition\n-- Counterexample: R, S are relations that\n                -- R(a,b), R(b,a) true, else false\n                -- S(a,a) true, else false\n\nnamespace symmetry\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), R(b,a) true, else false\ndef R : X → X → Prop\n| a a := false\n| a b := true\n| b a := true\n| b b := false\n\n-- Define binary relation S such that \n-- S(a,a) true, else false\ndef S : X → X → Prop\n| a a := true\n| a b := false\n| b a := false\n| b b := false\n\ndef U : X → X → Prop := comp R S\n\n-- R is symmetric\nlemma R_symm : symmetric R :=\nbegin\n  intros x y hxy,\n  rcases x,\n    -- x = a\n    rcases y,\n      exact hxy, -- the case y = a\n      triv, -- the case y = b; `R b a` is true\n    -- x = b\n    rcases y,\n      triv, -- the case y = a; `R a b` is true\n      exact hxy, -- the case y = b\nend\n\n-- S is symmetric\nlemma S_symm : symmetric S :=\nbegin\n  intros x y hxy,\n  rcases x,\n    -- x = a\n    rcases y,\n      exact hxy, -- the case y = a\n      exfalso, exact hxy, -- the case y = b\n    -- x = b\n    rcases y,\n      exfalso, exact hxy, -- the case y = a\n      exact hxy, -- the case y = b\nend\n\n-- U is NOT symmetric\nexample : ¬(∀ A : Type, ∀ (R: A → A → Prop) (S: A → A → Prop), symmetric R → symmetric S → symmetric U) := \nbegin\n  intro h, -- change to `hypothesis → false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { exact R_symm}, -- Prove R is symmetric\n  { have h1 : symmetric U, {apply h, exact S_symm},\n    have h2 : U b a, -- show hypothesis that U b a is true\n      {use a, split, triv, triv},\n    have h3 : ¬(U a b), -- show hypothesis that U a b is false\n      {intro hUab, cases hUab with x hx, rcases x, apply hx.2, apply hx.2},\n    specialize h1 b a h2, -- focus on the specific case with h1, h2\n    apply h3, exact h1,\n  },\nend\n\nend X\nend symmetry\n\n-- (3) Transitivity: Not preserved under composition\n-- Counterexample: R, S are relations that\n                -- R(a,b), R(b,c), R(c,a) true, else false\n                -- S(a,a) 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,b), R(b,c), R(c,a) true, else false\ndef R : X → X → Prop\n| a b := true\n| b c := true\n| a c := true\n| a a := false\n| b a := false\n| b b := false\n| c a := false\n| c b := false\n| c c := false\n\n-- Define binary relation S such that \n-- S(b,c), S(c,a), S(b,a) true, else false\ndef S : X → X → Prop\n| b c := true\n| c a := true\n| b a := true\n| a a := false\n| a b := false\n| a c := false\n| b b := false\n| c b := false\n| c c := false\n\ndef U : X → X → Prop := comp R S\n\n-- R is transitive\nlemma R_trans : transitive R :=\nbegin\n  intros x y z hxy hyz,\n  rcases x,\n    -- x = a\n    rcases y,\n      -- y = a\n      rcases z,\n        exact hxy, -- the case z = a\n        exact hyz, -- the case z = b\n        exact hyz, -- the case z = c\n      -- y = b\n      rcases z,\n        exact hyz, -- the case z = a; `R b a` is false\n        exact hxy, -- the case z = b\n        triv,      -- the case z = c; `R a c` is true\n      -- y = c\n      rcases z,\n        exact hyz, -- the case z = a; `R c a` is false\n        triv,      -- the case z = b; `R a b` is true\n        exact hxy, -- the case z = c\n    -- x = b\n    rcases y,\n      -- y = a\n      rcases z,\n        exact hxy, -- the case z = a \n        exact hxy, -- the case z = b; `R b a` is false\n        triv,      -- the case z = c; `R b c` is true\n      -- y = b\n      rcases z,\n        exact hyz, -- the case z = a\n        exact hxy, -- the case z = b\n        exact hyz, -- the case z = c\n      -- y = c\n      rcases z,\n        exact hyz, -- the case z = a; `R c a` is false\n        exact hyz, -- the case z = b; `R c b` is false\n        exact hxy, -- the case z = c\n    -- x = c\n    rcases y,\n      -- y = a\n      rcases z,\n        exact hxy, -- the case z = a \n        exact hxy, -- the case z = b; `R c a` is false\n        exact hxy, -- the case z = c; `R c a` is false\n      -- y = b\n      rcases z,\n        exact hyz, -- the case z = a; `R b a` is false\n        exact hxy, -- the case z = b\n        exact hxy, -- the case z = c; `R c b` is false\n      -- y = c\n      rcases z,\n        exact hyz, -- the case z = a\n        exact hyz, -- the case z = b\n        exact hxy, -- the case z = c\nend\n\n-- S is transitive\nlemma S_trans : transitive S :=\nbegin\n  intros x y z hxy hyz,\n  rcases x,\n    -- x = a\n    rcases y,\n      -- y = a\n      rcases z,\n        exact hxy, -- the case z = a\n        exact hyz, -- the case z = b\n        exact hyz, -- the case z = c\n      -- y = b\n      rcases z,\n        exact hxy, -- the case z = a; `S a b` is false\n        exact hxy, -- the case z = b\n        exact hxy, -- the case z = c; `S a b` is false\n      -- y = c\n      rcases z,\n        exact hxy, -- the case z = a; `S a c` is false\n        exact hxy, -- the case z = b; `S a c` is false\n        exact hxy, -- the case z = c\n    -- x = b\n    rcases y,\n      -- y = a\n      rcases z,\n        exact hxy, -- the case z = a \n        exact hyz, -- the case z = b; `S a b` is false\n        triv,      -- the case z = c; `S b c` is true\n      -- y = b\n      rcases z,\n        exact hyz, -- the case z = a\n        exact hxy, -- the case z = b\n        exact hyz, -- the case z = c\n      -- y = c\n      rcases z,\n        triv,      -- the case z = a; `S b a` is true\n        exact hyz, -- the case z = b; `S c b` is false\n        exact hxy, -- the case z = c\n    -- x = c\n    rcases y,\n      -- y = a\n      rcases z,\n        exact hxy, -- the case z = a \n        exact hyz, -- the case z = b; `S a b` is false\n        exact hyz, -- the case z = c; `S a c` is false\n      -- y = b\n      rcases z,\n        triv,      -- the case z = a; `S c a` is true\n        exact hxy, -- the case z = b\n        exact hxy, -- the case z = c; `S c b` is false\n      -- y = c\n      rcases z,\n        exact hyz, -- the case z = a\n        exact hyz, -- the case z = b\n        exact hyz, -- the case z = c\nend\n\n-- U is NOT transitive\nexample : ¬(∀ A : Type, ∀ (R: A → A → Prop) (S: A → A → Prop), transitive R → transitive S → transitive U) := \nbegin\n  intro h, -- change to `hypothesis → false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { exact R_trans}, -- Prove R is transitive\n  { have h1 : transitive U, {apply h, exact S_trans},\n    have h2 : U b a, -- show hypothesis that U b a is true\n      {use c, split, triv, triv},\n    have h3 : U a c, -- show hypothesis that U a c is true\n      {use b, split, triv, triv},\n    specialize h1 b a c h2 h3, -- focus on the specific case with h1, h2\n    { cases h1 with x hx,\n      rcases x,\n      exact hx.1, exact hx.1, exact hx.2}, -- check `U b c` is false\n  },\nend\n\nend X\nend transitivity\n\n-- (4) Antisymmetry: Not preserved under composition\n-- Counterexample: R, S are relations on X = {a,b} that\n                -- R(a,b), R(b,b) true, else false\n                -- S(b,a), S(b,b) true, else false\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), R(b,b) true, else false\ndef R : X → X → Prop\n| a a := false\n| a b := true\n| b a := false\n| b b := true\n\n-- Define binary relation S such that \n-- S(b,a), S(b,b) true, else false\ndef S : X → X → Prop\n| a a := false\n| a b := false\n| b a := true\n| b b := true\n\ndef U : X → X → Prop := comp R S\n\n-- R is anti-symmetric\nlemma R_antisymm : anti_symmetric R :=\nbegin\n  intros x y hxy hyx,\n  rcases x,\n    -- x = a\n    rcases y,\n      refl,               -- y = a\n      exfalso, apply hyx, -- y = b\n    -- x = b\n    rcases y,\n      exfalso, apply hxy, -- y = a\n      refl,               -- y = b\nend\n\n-- S is anti-symmetric\nlemma S_antisymm : anti_symmetric S :=\nbegin\n  intros x y hxy hyx,\n  rcases x,\n    -- x = a\n    rcases y,\n      refl,               -- y = a\n      exfalso, apply hxy, -- y = b\n    -- x = b\n    rcases y,\n      exfalso, apply hyx, -- y = a\n      refl,               -- y = b\nend\n\n-- U is NOT anti-symmetric\nexample : ¬(∀ A : Type, ∀ (R: A → A → Prop) (S: A → A → Prop), anti_symmetric R → anti_symmetric S → anti_symmetric U) := \nbegin\n  intro h, -- change to `hypothesis → false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { exact R_antisymm}, -- Prove R is antisymmetric\n  { have h1 : anti_symmetric U, {apply h, exact S_antisymm},\n    have h2 : U a b, -- show hypothesis that U b a is true\n      {use b, split, triv, triv},\n    have h3 : U b a, -- show hypothesis that U a b is true\n      {use b, split, triv, triv},\n    specialize h1 a b h2 h3, -- focus on the specific case with h1, h2\n    rcases h1, -- check that h1 is false\n  },\nend\n\nend X\nend antisymmetry\n\n-- (5) Asymmetry: Not preserved under composition\n-- Counterexample: R, S are relations on X = {a,b} that\n                -- R(a,b) true, else false\n                -- S(b,a) true, else false\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 → X → Prop\n| a a := false\n| a b := true\n| b a := false\n| b b := false\n\n-- Define binary relation S such that \n-- S(b,a) true, else false\ndef S : X → X → Prop\n| a a := false\n| a b := false\n| b a := true\n| b b := false\n\ndef U : X → X → Prop := comp R S\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, -- y = a; `R a a` is false\n      exact hyx, -- y = b; `R b a` is false\n    -- x = b\n    rcases y,\n      exact hxy, -- y = a; `R b a` is false\n      exact hyx, -- y = b; `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, -- y = a; `S a a` is false\n      exact hxy, -- y = b; `S a b` is false\n    -- x = b\n    rcases y,\n      exact hyx, -- y = a; `S a b` is false\n      exact hyx, -- y = b; `R b b` is false\nend\n\n-- U is NOT asymmetric\nexample : ¬(∀ A : Type, ∀ (R: A → A → Prop) (S: A → A → Prop), asymmetric R → asymmetric S → asymmetric U) := \nbegin\n  intro h, -- change to `hypothesis → false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { exact R_asymm}, -- Prove R is antisymmetric\n  { have h1 : asymmetric U, {apply h, exact S_asymm},\n    have h2 : U a a, {use b, split, triv, triv}, -- show hypothesis that U a a is true\n    specialize h1 a a, -- focus on the specific case with h1, h2\n    apply h1, exact h2, exact h2, -- check that h1 is false\n  },\nend\n\nend X\nend asymmetry\n\n-- (6) Irreflexivity: Not preserved under composition\n-- Counterexample: R, S are relations on X = {a,b} that\n                -- R(a,b) true, else false\n                -- S(b,a) true, else false\nnamespace irreflexivity\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 → X → Prop\n| a a := false\n| a b := true\n| b a := false\n| b b := false\n\n-- Define binary relation S such that \n-- S(b,a) true, else false\ndef S : X → X → Prop\n| a a := false\n| a b := false\n| b a := true\n| b b := false\n\ndef U : X → X → Prop := comp R S\n\n-- R is irreflexive\nlemma R_irrfl : irreflexive R :=\nbegin\n  intro x,\n  rcases x,\n    repeat { intro h, exact h},\nend\n\n-- S is irreflexive\nlemma S_irrfl : irreflexive S :=\nbegin\n  intro x,\n  rcases x,\n    repeat { intro h, exact h},\nend\n\n-- U is NOT irreflexive\nexample : ¬(∀ A : Type, ∀ (R: A → A → Prop) (S: A → A → Prop), irreflexive R → irreflexive S → irreflexive U) := \nbegin\n  intro h, -- change to `hypothesis → false`\n  specialize h X R S _, -- focus on the specific example we construct\n  { exact R_irrfl}, -- Prove R is antisymmetric\n  { have h1 : irreflexive U, {apply h, exact S_irrfl},\n    have h2 : U a a, {use b, split, triv, triv}, -- show hypothesis that U a a is true\n    specialize h1 a, -- focus on the specific case with h1, h2\n    apply h1, exact h2, -- check that h1 is false\n  },\nend\n\nend X\nend irreflexivity\n\n-- (7) Totality: Preserved under composition\nexample (R S : A → A → Prop) (totalR : total R) (totalS : total S) : total (comp R S) :=\nbegin\n  intros x y,\n  have h1 : R x x ∨ R x x, apply totalR x x,\n  have h2 : R y y ∨ R y y, apply totalR y y,\n  specialize totalS x y,\n  cases totalS with hSxy hSyx,\n    {left, use x, split, rcases h1, exact h1, exact h1, exact hSxy},\n    {right, use y, split, rcases h2, exact h2, exact h2, exact hSyx},\nend\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_(3_1_exercises_composition).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7765987055661016}}
{"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.integral.interval_average\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.MeasureTheory.Integral.Average\n\n/-!\n# Integral average over an interval\n\nIn this file we introduce notation `⨍ x in a..b, f x` for the average `⨍ x in Ι a b, f x` of `f`\nover the interval `Ι a b = set.Ioc (min a b) (max a b)` w.r.t. the Lebesgue measure, then prove\nformulas for this average:\n\n* `interval_average_eq`: `⨍ x in a..b, f x = (b - a)⁻¹ • ∫ x in a..b, f x`;\n* `interval_average_eq_div`: `⨍ x in a..b, f x = (∫ x in a..b, f x) / (b - a)`.\n\nWe also prove that `⨍ x in a..b, f x = ⨍ x in b..a, f x`, see `interval_average_symm`.\n\n## Notation\n\n`⨍ x in a..b, f x`: average of `f` over the interval `Ι a b` w.r.t. the Lebesgue measure.\n\n-/\n\n\nopen MeasureTheory Set TopologicalSpace\n\nopen Interval\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]\n\n-- mathport name: «expr⨍ in .. , »\nnotation3\"⨍ \"(...)\" in \"a\"..\"b\", \"r:(scoped f => average Measure.restrict volume Ι a b f) => r\n\ntheorem interval_average_symm (f : ℝ → E) (a b : ℝ) : (⨍ x in a..b, f x) = ⨍ x in b..a, f x := by\n  rw [set_average_eq, set_average_eq, uIoc_swap]\n#align interval_average_symm interval_average_symm\n\ntheorem interval_average_eq (f : ℝ → E) (a b : ℝ) :\n    (⨍ x in a..b, f x) = (b - a)⁻¹ • ∫ x in a..b, f x :=\n  by\n  cases' le_or_lt a b with h h\n  ·\n    rw [set_average_eq, uIoc_of_le h, Real.volume_Ioc, intervalIntegral.integral_of_le h,\n      ENNReal.toReal_ofReal (sub_nonneg.2 h)]\n  ·\n    rw [set_average_eq, uIoc_of_lt h, Real.volume_Ioc, intervalIntegral.integral_of_ge h.le,\n      ENNReal.toReal_ofReal (sub_nonneg.2 h.le), smul_neg, ← neg_smul, ← inv_neg, neg_sub]\n#align interval_average_eq interval_average_eq\n\ntheorem interval_average_eq_div (f : ℝ → ℝ) (a b : ℝ) :\n    (⨍ x in a..b, f x) = (∫ x in a..b, f x) / (b - a) := by\n  rw [interval_average_eq, smul_eq_mul, div_eq_inv_mul]\n#align interval_average_eq_div interval_average_eq_div\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/IntervalAverage.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7765321550128346}}
{"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.order\nimport algebra.big_operators.basic\n\n/-!\n# Definitions and properties of `gcd`, `lcm`, and `coprime`\n\n-/\n\nnamespace nat\n\n/-! ### `gcd` -/\n\ntheorem gcd_dvd (m n : ℕ) : (gcd m n ∣ m) ∧ (gcd m n ∣ n) :=\ngcd.induction m n\n  (λn, by rw gcd_zero_left; exact ⟨dvd_zero n, dvd_refl n⟩)\n  (λm n npos, by rw ←gcd_rec; exact λ ⟨IH₁, IH₂⟩, ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩)\n\ntheorem gcd_dvd_left (m n : ℕ) : gcd m n ∣ m := (gcd_dvd m n).left\n\ntheorem gcd_dvd_right (m n : ℕ) : gcd m n ∣ n := (gcd_dvd m n).right\n\ntheorem gcd_le_left {m} (n) (h : 0 < m) : gcd m n ≤ m := le_of_dvd h $ gcd_dvd_left m n\n\ntheorem gcd_le_right (m) {n} (h : 0 < n) : gcd m n ≤ n := le_of_dvd h $ gcd_dvd_right m n\n\ntheorem dvd_gcd {m n k : ℕ} : k ∣ m → k ∣ n → k ∣ gcd m n :=\ngcd.induction m n (λn _ kn, by rw gcd_zero_left; exact kn)\n  (λn 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 : ℕ} : k ∣ gcd m n ↔ k ∣ m ∧ k ∣ n :=\niff.intro (λ h, ⟨h.trans (gcd_dvd m n).left, h.trans (gcd_dvd m n).right⟩)\n          (λ h, dvd_gcd h.left h.right)\n\ntheorem gcd_comm (m n : ℕ) : 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 : ℕ} : m ∣ n ↔ gcd m n = m :=\n⟨λ h, by rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left],\n λ h, h ▸ gcd_dvd_right m n⟩\n\ntheorem gcd_eq_right_iff_dvd {m n : ℕ} : m ∣ n ↔ gcd n m = m :=\nby rw gcd_comm; apply gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m n k : ℕ) : 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 : ℕ) : gcd n 1 = 1 :=\neq.trans (gcd_comm n 1) $ gcd_one_left n\n\ntheorem gcd_mul_left (m n k : ℕ) : gcd (m * n) (m * k) = m * gcd n k :=\ngcd.induction n k\n  (λk, by repeat {rw mul_zero <|> rw gcd_zero_left})\n  (λk n H IH, by rwa [←mul_mod_mul_left, ←gcd_rec, ←gcd_rec] at IH)\n\ntheorem gcd_mul_right (m n k : ℕ) : 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 : ℕ} (n : ℕ) (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 : ℕ) {n : ℕ} (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 : ℕ} (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 : ℕ} (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 : ℕ} : gcd i j = 0 ↔ i = 0 ∧ j = 0 :=\nbegin\n  split,\n  { intro h,\n    exact ⟨eq_zero_of_gcd_eq_zero_left h, eq_zero_of_gcd_eq_zero_right h⟩, },\n  { rintro ⟨rfl, rfl⟩,\n    exact nat.gcd_zero_right 0 }\nend\n\ntheorem gcd_div {m n k : ℕ} (H1 : k ∣ m) (H2 : k ∣ n) :\n  gcd (m / k) (n / k) = gcd m n / k :=\nor.elim (nat.eq_zero_or_pos k)\n  (λk0, by rw [k0, nat.div_zero, nat.div_zero, nat.div_zero, gcd_zero_right])\n  (λH3, nat.eq_of_mul_eq_mul_right H3 $ by rw [\n    nat.div_mul_cancel (dvd_gcd H1 H2), ←gcd_mul_right,\n    nat.div_mul_cancel H1, nat.div_mul_cancel H2])\n\ntheorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b)\n  (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ 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 : ℕ} (n : ℕ) (H : m ∣ k) : gcd m n ∣ 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 : ℕ} (n : ℕ) (H : m ∣ k) : gcd n m ∣ 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 : ℕ) : gcd m n ∣ gcd (k * m) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (m n k : ℕ) : gcd m n ∣ gcd (m * k) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (m n k : ℕ) : gcd m n ∣ gcd m (k * n) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (m n k : ℕ) : gcd m n ∣ gcd m (n * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {m n : ℕ} (H : m ∣ n) : gcd m n = m :=\ndvd_antisymm (gcd_dvd_left _ _) (dvd_gcd dvd_rfl H)\n\ntheorem gcd_eq_right {m n : ℕ} (H : n ∣ 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 : ℕ) : 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 : ℕ) : gcd n (m * n) = n :=\nby rw [gcd_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_left (m n : ℕ) : gcd (n * m) n = n :=\nby rw [mul_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_right (m n : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : gcd m (m + n) = gcd m n :=\nby rw [add_comm, gcd_add_self_right]\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m n : ℕ) : lcm m n = lcm n m :=\nby delta lcm; rw [mul_comm, gcd_comm]\n\n@[simp]\ntheorem lcm_zero_left (m : ℕ) : lcm 0 m = 0 :=\nby delta lcm; rw [zero_mul, nat.zero_div]\n\n@[simp]\ntheorem lcm_zero_right (m : ℕ) : lcm m 0 = 0 := lcm_comm 0 m ▸ lcm_zero_left m\n\n@[simp]\ntheorem lcm_one_left (m : ℕ) : lcm 1 m = m :=\nby delta lcm; rw [one_mul, gcd_one_left, nat.div_one]\n\n@[simp]\ntheorem lcm_one_right (m : ℕ) : lcm m 1 = m := lcm_comm 1 m ▸ lcm_one_left m\n\n@[simp]\ntheorem lcm_self (m : ℕ) : lcm m m = m :=\nor.elim (nat.eq_zero_or_pos m)\n  (λh, by rw [h, lcm_zero_left])\n  (λh, by delta lcm; rw [gcd_self, nat.mul_div_cancel _ h])\n\ntheorem dvd_lcm_left (m n : ℕ) : m ∣ 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 : ℕ) : n ∣ lcm m n :=\nlcm_comm n m ▸ dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m n : ℕ) : 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 : ℕ} (H1 : m ∣ k) (H2 : n ∣ k) : lcm m n ∣ k :=\nor.elim (nat.eq_zero_or_pos k)\n  (λh, by rw h; exact dvd_zero _)\n  (λkpos, 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, ←gcd_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 : ℕ) : lcm m n ∣ m * n :=\nlcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _)\n\nlemma lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k :=\n⟨λ h, ⟨(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩,\n  and_imp.2 lcm_dvd⟩\n\ntheorem lcm_assoc (m n k : ℕ) : 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 : ℕ} (hm : m ≠ 0) (hn : n ≠ 0) : lcm m n ≠ 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 : ℕ) : decidable (coprime m n) := by unfold coprime; apply_instance\n\ntheorem coprime_iff_gcd_eq_one {m n : ℕ} : coprime m n ↔ gcd m n = 1 := iff.rfl\n\ntheorem coprime.gcd_eq_one {m n : ℕ} (h : coprime m n) : gcd m n = 1 := h\n\ntheorem coprime.lcm_eq_mul {m n : ℕ} (h : coprime m n) : lcm m n = m * n :=\nby rw [←one_mul (lcm m n), ←h.gcd_eq_one, gcd_mul_lcm]\n\ntheorem coprime.symm {m n : ℕ} : coprime n m → coprime m n := (gcd_comm m n).trans\n\ntheorem coprime_comm {m n : ℕ} : coprime n m ↔ coprime m n := ⟨coprime.symm, coprime.symm⟩\n\ntheorem coprime.dvd_of_dvd_mul_right {m n k : ℕ} (H1 : coprime k n) (H2 : k ∣ m * n) : k ∣ 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\ntheorem coprime.dvd_of_dvd_mul_left {m n k : ℕ} (H1 : coprime k m) (H2 : k ∣ m * n) : k ∣ n :=\nby rw mul_comm at H2; exact H1.dvd_of_dvd_mul_right H2\n\ntheorem coprime.dvd_mul_right {m n k : ℕ} (H : coprime k n) : k ∣ m * n ↔ k ∣ m :=\n⟨H.dvd_of_dvd_mul_right, λ h, dvd_mul_of_dvd_left h n⟩\n\ntheorem coprime.dvd_mul_left {m n k : ℕ} (H : coprime k m) : k ∣ m * n ↔ k ∣ n :=\n⟨H.dvd_of_dvd_mul_left, λ h, dvd_mul_of_dvd_right h m⟩\n\ntheorem coprime.gcd_mul_left_cancel {k : ℕ} (m : ℕ) {n : ℕ} (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 : ℕ) {k n : ℕ} (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 : ℕ} (n : ℕ) (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 : ℕ} (n : ℕ) (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 : ℕ} (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 : ℕ} (dgt1 : 1 < d) (Hm : d ∣ m) (Hn : d ∣ n) :\n  ¬ coprime m n :=\nλ co, not_lt_of_ge (le_of_dvd zero_lt_one $ by rw [←co.gcd_eq_one]; exact dvd_gcd Hm Hn) dgt1\n\ntheorem exists_coprime {m n : ℕ} (H : 0 < gcd m n) :\n  ∃ m' n', coprime m' n' ∧ m = m' * gcd m n ∧ n = n' * gcd m n :=\n⟨_, _, 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⟩\n\ntheorem exists_coprime' {m n : ℕ} (H : 0 < gcd m n) :\n  ∃ g m' n', 0 < g ∧ coprime m' n' ∧ m = m' * g ∧ n = n' * g :=\nlet ⟨m', n', h⟩ := exists_coprime H in ⟨_, m', n', H, h⟩\n\n@[simp] theorem coprime_add_self_right {m n : ℕ} : coprime m (n + m) ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_self_right]\n\n@[simp] theorem coprime_self_add_right {m n : ℕ} : coprime m (m + n) ↔ coprime m n :=\nby rw [add_comm, coprime_add_self_right]\n\n@[simp] theorem coprime_add_self_left {m n : ℕ} : coprime (m + n) n ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_self_left]\n\n@[simp] theorem coprime_self_add_left {m n : ℕ} : coprime (m + n) m ↔ coprime n m :=\nby rw [coprime, coprime, gcd_self_add_left]\n\n@[simp] lemma coprime_add_mul_right_right (m n k : ℕ) : coprime m (n + k * m) ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_right_right]\n\n@[simp] lemma coprime_add_mul_left_right (m n k : ℕ) : coprime m (n + m * k) ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_left_right]\n\n@[simp] lemma coprime_mul_right_add_right (m n k : ℕ) : coprime m (k * m + n) ↔ coprime m n :=\nby rw [coprime, coprime, gcd_mul_right_add_right]\n\n@[simp] lemma coprime_mul_left_add_right (m n k : ℕ) : coprime m (m * k + n) ↔ coprime m n :=\nby rw [coprime, coprime, gcd_mul_left_add_right]\n\n@[simp] lemma coprime_add_mul_right_left (m n k : ℕ) : coprime (m + k * n) n ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_right_left]\n\n@[simp] lemma coprime_add_mul_left_left (m n k : ℕ) : coprime (m + n * k) n ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_mul_left_left]\n\n@[simp] lemma coprime_mul_right_add_left (m n k : ℕ) : coprime (k * n + m) n ↔ coprime m n :=\nby rw [coprime, coprime, gcd_mul_right_add_left]\n\n@[simp] lemma coprime_mul_left_add_left (m n k : ℕ) : coprime (n * k + m) n ↔ coprime m n :=\nby rw [coprime, coprime, gcd_mul_left_add_left]\n\ntheorem coprime.mul {m n k : ℕ} (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 : ℕ} (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 : ℕ} (H1 : m ∣ k) (H2 : coprime k n) : coprime m n :=\neq_one_of_dvd_one (by delta coprime at H2; rw ← H2; exact gcd_dvd_gcd_of_dvd_left _ H1)\n\ntheorem coprime.coprime_dvd_right {m k n : ℕ} (H1 : n ∣ 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 : ℕ} (H : coprime (k * m) n) : coprime m n :=\nH.coprime_dvd_left (dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right {k m n : ℕ} (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 : ℕ} (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 : ℕ} (H : coprime m (n * k)) : coprime m n :=\nH.coprime_dvd_right (dvd_mul_right _ _)\n\ntheorem coprime.coprime_div_left {m n a : ℕ} (cmn : coprime m n) (dvd : a ∣ 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 ⟨k, rfl⟩,\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 : ℕ} (cmn : coprime m n) (dvd : a ∣ n) :\n  coprime m (n / a) :=\n(coprime.coprime_div_left cmn.symm dvd).symm\n\nlemma coprime_mul_iff_left {k m n : ℕ} : coprime (m * n) k ↔ coprime m k ∧ coprime n k :=\n⟨λ h, ⟨coprime.coprime_mul_right h, coprime.coprime_mul_left h⟩,\n  λ ⟨h, _⟩, by rwa [coprime_iff_gcd_eq_one, coprime.gcd_mul_left_cancel n h]⟩\n\nlemma coprime_mul_iff_right {k m n : ℕ} : coprime k (m * n) ↔ coprime k m ∧ coprime k n :=\nby simpa only [coprime_comm] using coprime_mul_iff_left\n\nlemma coprime.gcd_left (k : ℕ) {m n : ℕ} (hmn : coprime m n) : coprime (gcd k m) n :=\nhmn.coprime_dvd_left $ gcd_dvd_right k m\n\nlemma coprime.gcd_right (k : ℕ) {m n : ℕ} (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 : ℕ) {m n : ℕ} (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 : ℕ} (hmn : coprime m n)\n  (hm : m ∣ a) (hn : n ∣ a) : m * n ∣ a :=\nlet ⟨k, hk⟩ := hm in hk.symm ▸ mul_dvd_mul_left _ (hmn.symm.dvd_of_dvd_mul_left (hk ▸ hn))\n\ntheorem coprime_one_left : ∀ n, coprime 1 n := gcd_one_left\n\ntheorem coprime_one_right : ∀ n, coprime n 1 := gcd_one_right\n\ntheorem coprime.pow_left {m k : ℕ} (n : ℕ) (H1 : coprime m k) : coprime (m ^ n) k :=\nnat.rec_on n (coprime_one_left _) (λn IH, H1.mul IH)\n\ntheorem coprime.pow_right {m k : ℕ} (n : ℕ) (H1 : coprime k m) : coprime k (m ^ n) :=\n(H1.symm.pow_left n).symm\n\ntheorem coprime.pow {k l : ℕ} (m n : ℕ) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n(H1.pow_left _).pow_right _\n\n@[simp] lemma coprime_pow_left_iff {n : ℕ} (hn : 0 < n) (a b : ℕ)  :\n  nat.coprime (a ^ n) b ↔ nat.coprime a b :=\nbegin\n  obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero hn.ne',\n  rw [pow_succ, nat.coprime_mul_iff_left],\n  exact ⟨and.left, λ hab, ⟨hab, hab.pow_left _⟩⟩\nend\n\n@[simp] lemma coprime_pow_right_iff {n : ℕ} (hn : 0 < n) (a b : ℕ)  :\n  nat.coprime a (b ^ n) ↔ 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 : ℕ} (H : coprime k m) (d : k ∣ m) : k = 1 :=\nby rw [← H.gcd_eq_one, gcd_eq_left d]\n\n@[simp] theorem coprime_zero_left (n : ℕ) : coprime 0 n ↔ n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_zero_right (n : ℕ) : coprime n 0 ↔ n = 1 :=\nby simp [coprime]\n\ntheorem not_coprime_zero_zero : ¬ coprime 0 0 := by simp\n\n@[simp] theorem coprime_one_left_iff (n : ℕ) : coprime 1 n ↔ true :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_right_iff (n : ℕ) : coprime n 1 ↔ true :=\nby simp [coprime]\n\n@[simp] theorem coprime_self (n : ℕ) : coprime n n ↔ n = 1 :=\nby simp [coprime]\n\nlemma gcd_mul_of_coprime_of_dvd {a b c : ℕ} (hac : coprime a c) (b_dvd_c : b ∣ c) :\n  gcd (a * b) c = b :=\nbegin\n  rcases exists_eq_mul_left_of_dvd b_dvd_c with ⟨d, rfl⟩,\n  rw [gcd_mul_right],\n  convert one_mul b,\n  exact coprime.coprime_mul_right_right hac,\nend\n\nsection big_operators\n\nopen_locale big_operators\n\n/-- See `is_coprime.prod_left` for the corresponding lemma about `is_coprime` -/\nlemma coprime_prod_left\n  {ι : Type*} {x : ℕ} {s : ι → ℕ} {t : finset ι} :\n  (∀ (i : ι), i ∈ t → coprime (s i) x) → coprime (∏ (i : ι) in t, s i) x :=\nfinset.prod_induction s (λ y, y.coprime x) (λ 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  {ι : Type*} {x : ℕ} {s : ι → ℕ} {t : finset ι} :\n  (∀ (i : ι), i ∈ t → coprime x (s i)) → coprime x (∏ (i : ι) in t, s i) :=\nfinset.prod_induction s (λ y, x.coprime y) (λ a b, coprime.mul_right) (by simp)\n\nend big_operators\n\nlemma coprime.eq_of_mul_eq_zero {m n : ℕ} (h : m.coprime n) (hmn : m * n = 0) :\n  m = 0 ∧ n = 1 ∨ m = 1 ∧ n = 0 :=\n(nat.eq_zero_of_mul_eq_zero hmn).imp\n  (λ hm, ⟨hm, n.coprime_zero_left.mp $ hm ▸ h⟩)\n  (λ hn, ⟨m.coprime_zero_left.mp $ hn ▸ h.symm, hn⟩)\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 : ℕ} (H : k ∣ m * n) :\n  { d : {m' // m' ∣ m} × {n' // n' ∣ n} // k = d.1 * d.2 } :=\nbegin\ncases h0 : (gcd k m),\ncase nat.zero\n{ have : k = 0 := eq_zero_of_gcd_eq_zero_left h0, subst this,\n  have : m = 0 := eq_zero_of_gcd_eq_zero_right h0, subst this,\n  exact ⟨⟨⟨0, dvd_refl 0⟩, ⟨n, dvd_refl n⟩⟩, (zero_mul n).symm⟩ },\ncase nat.succ : tmp\n{ have hpos : 0 < gcd k m := h0.symm ▸ 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 ⟨⟨⟨gcd k m,  gcd_dvd_right k m⟩, ⟨k / gcd k m, _⟩⟩, hd.symm⟩,\n  apply dvd_of_mul_dvd_mul_left hpos,\n  rw [hd, ← gcd_mul_right],\n  exact dvd_gcd (dvd_mul_right _ _) H }\nend\n\ntheorem gcd_mul_dvd_mul_gcd (k m n : ℕ) : gcd k (m * n) ∣ gcd k m * gcd k n :=\nbegin\nrcases (prod_dvd_and_dvd_of_dvd_prod $ gcd_dvd_right k (m * n)) with ⟨⟨⟨m', hm'⟩, ⟨n', hn'⟩⟩, h⟩,\nreplace h : gcd k (m * n) = m' * n' := h,\nrw h,\nhave hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _,\napply mul_dvd_mul,\n  { have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n',\n    exact dvd_gcd hm'k hm' },\n  { have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n',\n    exact dvd_gcd hn'k hn' }\nend\n\ntheorem coprime.gcd_mul (k : ℕ) {m n : ℕ} (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 : ℕ} (n0 : 0 < n) : a ^ n ∣ b ^ n ↔ a ∣ b :=\nbegin\n  refine ⟨λ h, _, λ h, pow_dvd_pow_of_dvd h _⟩,\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 ⟨g, a', b', g0', co, rfl, rfl⟩,\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 : ℕ} (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 ← 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:ℕ` divides coprime `a` and `b` then `k = 1` -/\nlemma eq_one_of_dvd_coprimes {a b k : ℕ} (h_ab_coprime : coprime a b)\n  (hka : k ∣ a) (hkb : k ∣ 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 : ℕ} (cop : coprime m n) (ha : a ≠ 0) (hb : b ≠ 0) :\n  a * m + b * n ≠ m * n :=\nbegin\n  intro h,\n  obtain ⟨x, rfl⟩ : n ∣ 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 ⟨y, rfl⟩ : m ∣ 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, ←one_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 [← mul_assoc, ← h, add_mul, add_mul, mul_comm _ n, ←mul_assoc, mul_comm y]\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/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.7765292926585092}}
{"text": "import BrownCs22.Library.Tactics\nimport BrownCs22.Library.TruthTables\n\n/-\n\nIn this file, we'll keep a running lecture-by-lecture list\nof the Lean syntax and tactics that we've learned.\n\n-/\n\n\n\n/-\n\n## Lecture 2\n\n`#check <expression>` tells us what kind of thing `<expression>` is.\n\n-/\n\n#check 0 \n#check 1 + 1 = 3\n\n\n/-\n\n## Lecture 3\n\n`variable (p q r : Prop)` introduces the atomic propositions `p`, `q`, `r`.\n(If we enclose them in `section` ... `end`, their scope is limited.)\n\n-/\n\nsection \n\nvariable (p q r : Prop)\n\n#check p ∧ q → r\n\nend \n\n/- \n\n`#truth_table p ∧ q ∨ r` prints a truth table for the given proposition.\n\n-/\n\n#truth_table p ∧ q\n\n\n/-\n\n## Lecture 4\n\nWe begin proofs by writing \n\n`example : p → p := by` or \n`theorem my_theorem_name : p → p := by`.\n\nFollowing lines should be indented two spaces.\n\n-/\n\nexample : p → p := by\n  intro hp \n  assumption \n\n/-\n\nThe new tactics (proof rules) we saw:\n\n* `sorry`: proves anything! (Cheating!)\n\n* `split_goal`: turn a goal of `p ∧ q` into two goals `p` and `q`,\n  and a goal of `p ↔ q` into two goals `p → q` and `q → p`. \n\n* `left` and `right`: turn a goal of `p ∨ q` into a goal of `p` \n  or a goal of `q`, respectively.\n\n* `intro h`: turn a goal of `p → q` into a goal of `q`,\n  with an extra hypothesis `h : p`.\n\n* `assumption`: if a hypothesis `h` matches the goal, will solve the goal.\n\n* `eliminate h with h1 h2`: when a hypothesis `h : p ∧ q`, \n  replaces `h` with two hypotheses `h1 : p` and `h2 : q`. \n  When a hypothesis `h : p ∨ q`, creates two goals, one with \n  a hypothesis `h1 : p` and one with a hypothesis `h2 : q`. \n\n* `apply h`: if `h : p → q` and the goal is `q`, changes the goal to `p`.\n  Read this as \"to show `q`, it suffices to show `p`\".\n  We'll use this later in a slightly different context. \n\n* `have h : q := hpq hp`: if `hpq : p → q` and `hp : p` (the lhs of the → matches),\n  creates a new hypothesis `h : q`. \n  Read this as \"I know `p → q` and I know `p`, so I know `q`.\"\n\n* `contradiction`: If you have both a proposition and its negation in your context,\n  will prove any goal.\n\n-/\n\n\n/-\n\n## Lecture 6\n\nSome more new tactics, or new behavior for old tactics:\n\n* `intro t`: turn a goal of `∀ x : T, P x` into a goal of `P t`,\n  with a new term `t : T` in the context. \n\n* `have h : P t := hP t`: if `hP : ∀ x : T, P x` and `t : T`,\n  creates a new hypothesis `h : P t`. \n  Read this as \"I know every `T` has property `P`, and `t` is a `T`, \n  so `t` must have property `P`.\n\n* `existsi t`: turns a goal of `∃ x : T, G x` into a goal of `G t`.\n  This is the tactic we use to provide a witness.\n\n* `eliminate h with t ht`: when a hypothesis `h :  ∃ x : T, H x`, \n  replaces `h` with a new witness `t` and the hypothesis `ht : H t`.\n  You should always use a fresh name for `t`.\n\n* `reflexivity`: proves equality goals where the LHS and RHS are the same,\n  like `x = x` and `f y = f y`. \n\n-/\n\n\n/-\n\n## Homework 2\n\n* `positivity`: if your goal is to show something is positive or nonnegative \n  (like `0 < x`, `x ≥ 0`, `0 ≤ a^2`, ...) and this \"obviously\" follows from\n  your hypotheses, write `positivity` to finish that goal. This tactic knows\n  basic facts like \"natural numbers are nonnegative\" and \"the square of a \n  positive number is positive.\" It does not know complicated arithmetic.\n\n* `numbers`: If your goal is to show an arithmetic statement about numerals,\n  like `5 + 5 = 10` or `1000 < 50000000`, `numbers` will close the goal.\n  It's basically a calculator!\n\n* `linarith`: stands for \"linear arithmetic.\" (If you don't know this term,\n  don't worry.) `linarith` does similar things to `positivity` and `numbers`,\n  but it can do some simple arithmetic, and use hypotheses.\n  For instance, if you know `h1 : x < 10` and `h2 : x + y < 20`, `linarith`\n  can prove the goal `3*x + 2*y < 50`.\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/Demos/QuickReference.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138366, "lm_q2_score": 0.907312221360624, "lm_q1q2_score": 0.7765241986370516}}
{"text": "/-\nFrom LF Require Export Basics.\n-/\n\nimport data.nat.basic\nimport tactic.basic\nimport .ch01_basics\n\nopen basics (evenb)\nopen nat (succ)\n\nnamespace induction\n\n/-\nTheorem plus_n_O_firsttry : ∀n:nat,\n  n = n + 0.\nProof.\n  intros n.\n  simpl. (* Does nothing! *)\nAbort.\n-/\n\n/- swapping order as this is refl in lean -/\n\n/- zero_add is a theorem used by simp in lean -/\ntheorem zero_add_firsttry (n : ℕ) : 0 + n = n := by squeeze_simp\n\n/-\nTheorem plus_n_O_secondtry : ∀n:nat,\n  n = n + 0.\nProof.\n  intros n. destruct n as [| n'] eqn:E.\n  - (* n = 0 *)\n    reflexivity. (* so far so good... *)\n  - (* n = S n' *)\n    simpl. (* ...but here we are stuck again *)\nAbort.\n-/\n\n/- zero_add is still a theorem in lean -/\ntheorem zero_add_secondtry (n : ℕ) : 0 + n = n :=\nbegin\n  cases n,\n    refl,\n  squeeze_simp,\nend\n\n/-\nTheorem plus_n_O : ∀n:nat, n = n + 0.\nProof.\n  intros n. induction n as [| n' IHn'].\n  - (* n = 0 *) reflexivity.\n  - (* n = S n' *) simpl. rewrite <- IHn'. reflexivity. Qed.\n-/\n\ntheorem zero_add (n : ℕ) : 0 + n = n :=\nbegin\n  induction n with n ih,\n    refl,\n  rw nat.add_succ,\n  rw ih,\nend\n\n/-\nTheorem minus_diag : ∀n,\n  minus n n = 0.\nProof.\n  (* WORKED IN CLASS *)\n  intros n. induction n as [| n' IHn'].\n  - (* n = 0 *)\n    simpl. reflexivity.\n  - (* n = S n' *)\n    simpl. rewrite → IHn'. reflexivity. Qed.\n-/\n\ntheorem sub_self (n : ℕ) : n - n = 0 :=\nbegin\n  induction n with n ih,\n    refl,\n  /- don't use version from library -/\n  simp only [nat.succ_sub_succ_eq_sub],\n  rw ih,\nend\n\n/-\nTheorem mult_0_r : ∀n:nat,\n  n * 0 = 0.\nProof.\n\n  (* FILL IN HERE *) Admitted.\nTheorem plus_n_Sm : ∀n m : nat,\n  S (n + m) = n + (S m).\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem plus_comm : ∀n m : nat,\n  n + m = m + n.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem plus_assoc : ∀n m p : nat,\n  n + (m + p) = (n + m) + p.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n/-\n  n.b. lean defines mul with recursion on the right,\n  which makes this too trivial\n-/\ntheorem mul_zero (n : ℕ) : n * 0 = 0 := rfl\n\n/-\n  defining other way to get similar challenge as expected\n-/\ntheorem mul_succ (n m : ℕ) : n * succ m = (n * m) + n := rfl\n\ntheorem zero_mul (n : ℕ) : 0 * n = 0 :=\nbegin\n  induction n with n ih,\n    refl,\n  rw mul_succ,\n  rw ih,\nend\n\ntheorem add_succ (n m : ℕ) : n + succ m = succ (n + m) := rfl\n\ntheorem succ_add (n m : ℕ) : succ n + m = succ (n + m) :=\nbegin\n  induction m with m ih,\n    refl,\n  rw add_succ,\n  rw ih,\nend\n\ntheorem add_comm (n m : ℕ) : n + m = m + n :=\nbegin\n  induction n with n ih,\n    rw add_zero,\n    rw zero_add,\n  rw add_succ,\n  rw succ_add,\n  rw ih,\nend\n\ntheorem add_assoc (n m p : ℕ) : n + (m + p) = (n + m) + p :=\nbegin\n  induction n with n ih,\n    rw [zero_add, zero_add],\n  rw [succ_add, succ_add, succ_add],\n  rw ih,\nend\n\n/-\nFixpoint double (n:nat) :=\n  match n with\n  | O ⇒ O\n  | S n' ⇒ S (S (double n'))\n  end.\n-/\n\ndef double : ℕ → ℕ\n| 0 := 0\n| (n + 1) := double n + 2\n\n/-\nLemma double_plus : ∀n, double n = n + n .\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma double_add (n : ℕ) : double n = n + n :=\nbegin\n  induction n with n ih,\n    refl,\n  rw double,\n  rw ih,\n  rw succ_add,\n  rw [add_succ, add_succ, add_succ],\n  rw add_zero,\nend\n\n/-\nTheorem evenb_S : ∀n : nat,\n  evenb (S n) = negb (evenb n).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem evenb_succ (n : ℕ) : evenb (succ n) = bnot (evenb n) :=\nbegin\n  induction n with n ih,\n    refl,\n  rw evenb,\n  rw ih,\n  rw bnot_bnot,\nend\n\n/-\nTheorem mult_0_plus' : ∀n m : nat,\n  (0 + n) * m = n * m.\nProof.\n  intros n m.\n  assert (H: 0 + n = n). { reflexivity. }\n  rewrite → H.\n  reflexivity. Qed.\n-/\n\ntheorem zero_add_mul' (n m : ℕ) : (0 + n) * m = n * m :=\nbegin\n  have h : 0 + n = n, rw zero_add,\n  rewrite h,\nend\n\n/-\nTheorem plus_rearrange_firsttry : ∀n m p q : nat,\n  (n + m) + (p + q) = (m + n) + (p + q).\nProof.\n  intros n m p q.\n  (* We just need to swap (n + m) for (m + n)... seems\n     like plus_comm should do the trick! *)\n  rewrite → plus_comm.\n  (* Doesn't work...Coq rewrites the wrong plus! *)\nAbort.\n-/\n\ntheorem add_rearrange_firsttry (n m p q : ℕ)\n  : (n + m) + (p + q) = (m + n) + (p + q) :=\nbegin\n  rw add_comm,\n  /- simp is a bit smarter though -/\n  /- ac_refl also works -/\n  simp [add_comm],\nend\n\n/-\nTheorem plus_rearrange : ∀n m p q : nat,\n  (n + m) + (p + q) = (m + n) + (p + q).\nProof.\n  intros n m p q.\n  assert (H: n + m = m + n).\n  { rewrite → plus_comm. reflexivity. }\n  rewrite → H. reflexivity. Qed.\n-/\n\ntheorem add_rearrange (n m p q : ℕ)\n  : (n + m) + (p + q) = (m + n) + (p + q) :=\nbegin\n  have h : n + m = m + n,\n    rw add_comm,\n  rw h,\nend\n\n/- or tell it where to apply -/\ntheorem add_rearrange' (n m p q : ℕ)\n  : (n + m) + (p + q) = (m + n) + (p + q) := by rw add_comm n m\n\n/-\nTheorem plus_assoc' : ∀n m p : nat,\n  n + (m + p) = (n + m) + p.\nProof. intros n m p. induction n as [| n' IHn']. reflexivity.\n  simpl. rewrite → IHn'. reflexivity. Qed.\n-/\n\ntheorem add_assoc' (n m p : ℕ) : n + (m + p) = (n + m) + p :=\nbegin\n  induction n with n ih,\n    rw [zero_add, zero_add],\n  rw [succ_add, succ_add, succ_add],\n  rw ih,\nend\n\n/-\nTheorem plus_assoc'' : ∀n m p : nat,\n  n + (m + p) = (n + m) + p.\nProof.\n  intros n m p. induction n as [| n' IHn'].\n  - (* n = 0 *)\n    reflexivity.\n  - (* n = S n' *)\n    simpl. rewrite → IHn'. reflexivity. Qed.\n-/\n\ntheorem add_assoc'' (n m p : ℕ) : n + (m + p) = (n + m) + p :=\nbegin\n  induction n,\n  case zero {\n    show 0 + (m + p) = (0 + m) + p,\n    rw [zero_add, zero_add],\n  },\n  case succ : n ih {\n    show (succ n) + (m + p) = ((succ n) + m) + p,\n    rw [succ_add, succ_add, succ_add],\n    show succ (n + (m + p)) = succ ((n + m) + p),\n    rw ih,\n  }\nend\n\nend induction", "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/ch02_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7765241933929709}}
{"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 {α : Type} : list α → list α → list α\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 {α : Type} :\n  ∀as xs : list α, accurev as xs = reverse xs ++ as\n| as []        := by refl\n| as (x :: xs) := by simp [reverse, accurev, accurev_eq_reverse_append _ xs]\n\n/-! 1.2. Derive the desired equation. -/\n\nlemma accurev_eq_reverse {α : Type} (xs : list α) :\n  accurev [] xs = reverse xs :=\nby simp [accurev_eq_reverse_append]\n\n/-! 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {α : Type} (xs : list α) :\n  accurev [] (accurev [] xs) = xs :=\nby simp [accurev_eq_reverse, reverse_reverse]\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 {α : Type} :\n      ∀as xs : list α, 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/-! We perform the proof by structural induction on `xs` (generalizing `as`).\n\nCase `[]`: The goal is `accurev as [] = reverse [] ++ as`. The left-hand side\nis `as` by definition of `accurev`. The right-hand side is `as` by definition\nof `reverse` and `++`.\n\nCase `x :: xs`: The goal is `accurev as (x :: xs) = reverse (x :: xs) ++ as`.\nThe induction hypothesis is `∀as, accurev as xs = reverse xs ++ as`.\n\nLet us simplify the goal's left-hand side:\n\n      accurev as (x :: xs)\n    = accurev (x :: as) xs        -- by definition of `accurev`\n    = reverse xs ++ (x :: as)     -- by the induction hypothesis\n\nNow let us massage the right-hand side so that it matches the simplified\nleft-hand side:\n\n      reverse (x :: xs) ++ as\n    = (reverse xs ++ [x]) ++ as   -- by definition of `reverse`\n    = reverse xs ++ ([x] ++ as)   -- by associativity of `++`\n    = reverse xs ++ (x :: as)     -- by definition of `++`\n\nThe two sides are equal. QED -/\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 {α : Type} : ℕ → list α → list α\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 {α : Type} : ℕ → list α → list α\n| 0       _         := []\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := x :: take m xs\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 {α : Type} :\n  ∀n : ℕ, drop n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\n\n@[simp] lemma take_nil {α : Type} :\n  ∀n : ℕ, take n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\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, `←add_assoc` might be useful. -/\n\nlemma drop_drop {α : Type} :\n  ∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) _ []        := by simp [drop]\n| (m + 1) n (x :: xs) :=\n  by simp [drop, drop_drop m n xs, ←add_assoc]\n\nlemma take_take {α : Type} :\n  ∀(m : ℕ) (xs : list α), 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 {α : Type} :\n  ∀(n : ℕ) (xs : list α), 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/-! ## Question 3: A Type of λ-Terms\n\n3.1. Define an inductive type corresponding to the untyped λ-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- λ-expression (e.g., `λx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\ninductive term : Type\n| var : string → term\n| lam : string → term → term\n| app : term → term → term\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 → string\n| (term.var s)   := s\n| (term.lam s t) := \"(λ\" ++ s ++ \", \" ++ term.repr t ++ \")\"\n| (term.app t u) := \"(\" ++ term.repr t ++ \" \" ++ term.repr u ++ \")\"\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 `(λx, ((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 → nat → Type` that represents a sequence\nof values of a particular length. -/\n\ninductive vec (α : Type) : ℕ → Type\n| nil {}                           : vec 0\n| cons (a : α) {n : ℕ} (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 ℕ 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 {α : Type} : ∀ {m n : ℕ}, vec α m → vec α n → vec α (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₁, v₂, ..., vₙ]` and `V[w₁, w₂, ..., wₙ]` is the number\n`v₁ * w₁ + v₂ * w₂ + ... + vₙ * wₙ`, or, more formally, `∑_{i=1}^n (vᵢ * wᵢ)`. -/\n\ndef dot_product : ∀ {n : ℕ}, vec ℤ n → vec ℤ n → ℤ\n| _ vec.nil vec.nil := 0\n| _ (vec.cons m ms) (vec.cons n ns) := m * n + dot_product ms ns\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 {α β γ : Type} : ∀ {n : ℕ}, (α → β → γ) → vec α n → vec β n → vec γ n\n| _ f vec.nil vec.nil := vec.nil\n| _ f (vec.cons x xs) (vec.cons y ys) := vec.cons (f x y) (meld f xs ys)\n\n/-! The *product* of two types `α` and `β`, denoted `α × β`, is the type of\npairs `(a, b)` such that `a : α` and `b : β`. (`(a, b)` is syntactic sugar for\n`prod.mk a b`, where `prod.mk : ∀ {α β : Type}, α → β → α × β`.) -/\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 ℕ 3` and\n`[\"a\", \"b\", \"c\"] : vec string 3` yields the vector\n`[(1, \"a\"), (2, \"b\"), (3, \"c\")] : vec (ℕ × 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 {α β : Type} {n : ℕ} : vec α n → vec β n → vec (α × β) n :=\nmeld prod.mk\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 {α β γ : Type} : ∀ {m n : ℕ}\n  (f : α → β → γ) (vs : vec α n) (ws : vec β n) (xs : vec α m) (ys : vec β 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   by simp [append, meld]\n| _ _ f (vec.cons v vs) (vec.cons w ws) xs ys :=\n   have ih : _, from meld_append f vs ws xs ys,\ncalc\n  meld f (append (vec.cons v vs) xs) (append (vec.cons w ws) ys)\n      = meld f (vec.cons v (append vs xs)) (vec.cons w (append ws ys)) : rfl\n  ... = vec.cons (f v w) (meld f (append vs xs) (append ws ys)) : rfl\n  ... = vec.cons (f v w) (append (meld f vs ws) (meld f xs ys)) : by rw [ih]\n  ... = append (vec.cons (f v w) (meld f vs ws)) (meld f xs ys) : eq.symm rfl\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 : ℕ) (c : ℕ) : Type :=\nvec (vec ℕ c) r\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 {α β : Type} : ∀ {n : ℕ}, (α → β) → vec α n → vec β n\n| _ _ vec.nil         := vec.nil\n| _ f (vec.cons x xs) := vec.cons (f x) (vec.map f xs)\n\ndef vec.nth {α : Type} : ∀ {n : ℕ} (i : ℕ), i < n → vec α n → α\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 : ℕ} (i : ℕ) (h : i < r) (m : mat r c) : vec ℕ c :=\nvec.nth i h m \n\ndef get_col {r c : ℕ} (i : ℕ) (h : i < c) (m : mat r c) : vec ℕ r :=\nvec.map (vec.nth i h) m \n\n\n/-! 4.7. Our second matrix operation is addition. Matrix addition proceeds\ncomponent-wise: e.g.,\n┌     ┐    ┌     ┐     ┌         ┐\n| a b |  + | e f |  =  | a+e b+f |\n| c d |    | g h |     | c+g d+h |\n└     ┘    └     ┘     └         ┘\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 : ∀ {r c}, mat r c → mat r c → mat r c \n:= λ _ _, vec.meld (vec.meld (+))\n\nend mat\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_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870288, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7764082640706071}}
{"text": "/-\nComplete these proofs.\n\nvariable  U : Type\nvariables A B C : U → Prop\n\nexample : (¬ ∃ x, A x) → ∀ x, ¬ A x :=\nsorry\n\nexample : (∀ x, ¬ A x) → ¬ ∃ x, A x :=\nsorry\n-/\n\nvariable  U : Type\nvariables A B C : U → Prop\n\nexample : (¬ ∃ x, A x) → ∀ x, ¬ A x :=\nassume hNotExistsAx: (¬ ∃ x, A x),\nassume x: U,\nassume hAx: A(x),\nshow false, from (\n  have hExistsAx: ∃ x, A x,\n  from exists.intro(x)(hAx),\n  hNotExistsAx(hExistsAx)\n)\n\nexample : (∀ x, ¬ A x) → ¬ ∃ x, A x :=\nassume hNeverA: (∀ x, ¬ A x),\nassume hExistAx: ∃ x, A x,\nshow false, from (\n  exists.elim(hExistAx)(\n    assume (x: U) (hAx: A(x)),\n    have hnAx: ¬ A(x), from hNeverA(x),\n    hnAx(hAx)\n  )\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/chapter9/ex8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9579122708828602, "lm_q2_score": 0.8104789132480439, "lm_q1q2_score": 0.7763676962921064}}
{"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\" (`∧`)\n\nWe learn about how to manipulate `P ∧ 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### The `cases` tactic\n\nIf `h : P ∧ Q` is a hypothesis, then `cases h with hP hQ,`\ndecomposes it into two hypotheses `hP : P` and `hQ : Q`.\n\n### The `split` tactic\n\nIf `⊢ P ∧ Q` is in the goal, The `split` tactic will turn it into\ntwo goals, `⊢ P` and `⊢ Q`. NB tactics operate on the first goal only.\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nvariables (P Q R : Prop)\n\nexample : P ∧ Q → P :=\nbegin\n  intro h,\n  cases h with hP hQ,\n  apply hP,\n  /-intro h, apply h.1-/\nend\n\nexample : P ∧ Q → Q :=\nbegin\n  intro h,\n  apply h.2,\nend\n\nexample : (P → Q → R) → (P ∧ Q → R) :=\nbegin\n  intro h,\n  intro hPQ,\n  apply h hPQ.1 hPQ.2,\nend\n\nexample : P → Q → P ∧ Q :=\nbegin\n  intros hP hQ,\n  split,\n  apply hP,\n  apply hQ,\nend\n\n/-- `∧` is symmetric -/\nexample : P ∧ Q → Q ∧ P :=\nbegin\n  intro h,\n  split,\n  apply h.2,\n  apply h.1,\nend\n\nexample : P → P ∧ true :=\nbegin\n  intro h,\n  split,\n  exact h,\n  trivial,\nend\n\nexample : false → P ∧ false :=\nbegin\n  trivial,\nend\n\n/-- `∧` is transitive -/\nexample : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  intros hPQ hQR,\n  split,\n  apply hPQ.1,\n  apply hQR.2,\nend\n\nexample : ((P ∧ Q) → R) → (P → Q → R) :=\nbegin\n  intro hPQR,\n  intros hP hQ,\n  apply hPQR,\n  split,\n  apply hP,\n  apply hQ\nend\n\n/-!\n\n# Logic in Lean, example sheet 5 : \"iff\" (`↔`)\n\nWe learn about how to manipulate `P ↔ Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following two new tactics:\n\n* `refl`\n* `rw`\n\n### The `refl` tactic\n\nIf your goal is `P ↔ P` then `refl,` will solve it.\n\n### The `rw` tactic\n\nIf `h : P ↔ Q` is a hypothesis, you can decompose it\nusing `cases h with hPQ hQP,`. However, if you keep\nit around then you can do `rw h,` which changes all `P`s in the goal to `Q`s.\nVariant: `rw h at h2,` will change all `P`s to `Q`s in hypothesis `h2`.\n\n-/\n\nvariables (S : Prop)\n\nexample : P ↔ P :=\nby refl\n\nexample : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  intro hPQ,\n  split,\n  apply hPQ.2,\n  apply hPQ.1,\nend\n\nexample : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  split,\n  {intro hPQ,\n  rw hPQ,},\n  {intro hQP,\n  rw hQP,},\nend\n\nexample : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  intros hPQ hQR,\n  split,\n  {rw[hPQ, hQR], intro h, exact h,},\n  {rw[hPQ, hQR], intro h, exact h,},\nend\n\nexample : P ∧ Q ↔ Q ∧ P :=\nbegin\n  split,                                    /-very much the same-/\n  {intro h, split, apply h.2, apply h.1,},\n  {intro h, split, apply h.2, apply h.1,}\nend\n\nexample : ((P ∧ Q) ∧ R) ↔ (P ∧ (Q ∧ R)) :=\nbegin\n  split,\n  {intro hPQR,\n  split,\n  {apply hPQR.1.1,},\n  {split,\n  apply hPQR.1.2,\n  apply hPQR.2}},\n  {intro hPQR,\n  split,\n  {split,\n  apply hPQR.1,\n  apply hPQR.2.1},\n  apply hPQR.2.2,},\nend\n\nexample : P ↔ (P ∧ true) :=\nbegin\n  split,\n  {intro hP,\n  split,\n  apply hP,\n  trivial,},\n  {intro hP',\n  apply hP'.1},\nend\n\nexample : false ↔ (P ∧ false) :=\nbegin\n  split,\n  {trivial,},\n  {intro h,\n  apply h.2}\nend\n\nexample : (P ↔ Q) → (R ↔ S) → (P ∧ R ↔ Q ∧ S) :=\nbegin\n  intros hPQ hRS,\n  split,\n  {intro hPR,\n  split,\n  rw ←hPQ, apply hPR.1,\n  rw ←hRS, apply hPR.2,},\n  {intro hQS,\n  split,\n  rw hPQ, apply hQS.1,\n  rw hRS, apply hQS.2,},\nend\n\nexample : ¬ (P ↔ ¬ P) :=\nbegin\n  by_contra h1,\n  by_cases P,\n  {have h2: ¬ P, rw h1 at h,\n  change P → false at h,\n  trivial,\n  trivial,},\n  {have h2: P, rw ←h1 at h,\n  apply h,\n  trivial,},\nend\n\n/-at: rw h₁ at h₂-/\n", "meta": {"author": "Siesta233", "repo": "LeanPractice", "sha": "3795eeb8763edacf2c74b9c8925f642d6cc56daf", "save_path": "github-repos/lean/Siesta233-LeanPractice", "path": "github-repos/lean/Siesta233-LeanPractice/LeanPractice-3795eeb8763edacf2c74b9c8925f642d6cc56daf/src/PS4&5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213880824791, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7762938659788763}}
{"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 tactic.monotonicity.basic\nimport algebra.ordered_ring\nimport data.set.lattice\nimport order.bounds\n\nvariables {α : Type*}\n\n@[mono]\nlemma mul_mono_nonneg {x y z : α} [ordered_semiring α]\n  (h' : 0 ≤ z)\n  (h : x ≤ y)\n: x * z ≤ y * z :=\nby apply mul_le_mul_of_nonneg_right; assumption\n\nlemma lt_of_mul_lt_mul_neg_right {a b c : α}  [linear_ordered_ring α]\n  (h : a * c < b * c) (hc : c ≤ 0) : b < a :=\nhave nhc : -c ≥ 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 : α} [linear_ordered_ring α]\n  (h' : z ≤ 0) (h : y ≤ x) : x * z ≤ 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 : ℕ}\n  (h' : z ≤ x)\n  (h : x < y)\n: x - z < y - z :=\nbegin\n  have : z ≤ y,\n  { transitivity, assumption, apply le_of_lt h, },\n  apply @nat.lt_of_add_lt_add_left z,\n  rw [nat.add_sub_of_le,nat.add_sub_of_le];\n    solve_by_elim\nend\n\n@[mono]\nlemma nat.sub_mono_right_strict {x y z : ℕ}\n  (h' : x ≤ z)\n  (h : y < x)\n: z - x < z - y :=\nbegin\n  have h'' : y ≤ z,\n  { transitivity, apply le_of_lt h, assumption },\n  apply @nat.lt_of_add_lt_add_right _ x,\n  rw [nat.sub_add_cancel h'],\n  apply @lt_of_le_of_lt _ _ _ (z - y + y),\n  rw [nat.sub_add_cancel 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 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": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/tactic/monotonicity/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636752, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7762938456547286}}
{"text": "import data.set\nimport .src_13_applications_to_even_and_odd\nimport .src_22_set_equality\n\nopen set\n\nnamespace mth1001\n\nsection subsets\n\n/-\nType `⊆` as `\\sub`\n-/\n\n/-\nWorking with particular finite sets, Lean can prove results using `dec_trivial`.\n-/\nexample : ({4, 6, 8} : finset ℤ) ⊆ ({8, 4, 8, 10, 6} : finset ℤ) := dec_trivial\n\n/-\nRecall our theorem that for every `a : ℤ`, if `a` is even, then `a * a` is even.\n-/\ntheorem even_square_of_even : ∀ a : ℤ , even a → even (a*a) :=\nbegin\n  intros a h,\n  cases h with k hk,\n  use (2*k*k),\n  rw hk,\n  ring, \nend\n\n/-\nWe'll show that the set of even numbers is a subset of the set of numbers whose square is even.\nLean automatically uses the definition of subset to turn the goal into one of proving\na univerally quantified statement.\n-/\nexample : {x : ℤ | even x} ⊆ {x : ℤ | even (x*x)} := by apply even_square_of_even\n\n-- Here's a proof of the same result that doesn't use `even_square_of_even`.\n\nexample : {x : ℤ | even x} ⊆ {x : ℤ | even (x*x)} :=\nbegin\n  intros a h, -- Assume `a : ℤ`, assume `h : a ∈ {x : ℤ | even x}`. \n  rw mem_set_of_eq at *, -- By def. of set membership, `h : even a`. Goal `⊢ even (a*a)`.\n  unfold even at h, -- By definition of even, `h : ∃ (m : ℤ), a = 2 * m`.\n  cases h with b hb, -- Assume `b : ℤ`, assume `hb : a = 2*b` (exists elim. on `h`)\n  -- It suffices to prove `even (a*a)`, i.e. `∃ (m : ℤ), (a*a) = 2*m`\n  use (2*b*b), -- By exists introduction on `2*b*b`, it suffices to prove `(a*a)=2*(2*b*b)`.\n  rw hb, -- Rewriting with `hb`, the goal is to prove `(2*b)*(2*b)=2*(2*b*b)`.\n  ring,  -- This follows by basic arithmetic.\nend\n\nopen_locale classical\n\n-- Exercise 128:\n-- In the following example, we show the converse of the above result. You may wish to refer to\n-- the file `src_13_applications_to_even_and_odd.lean` for inspiration.\n-- Helpful results and tactics: `even_iff_not_odd`, `not_not`, `contrapose`. \nexample : {x : ℤ | even (x*x)} ⊆ {x : ℤ | even x} :=\nbegin\n  rw subset_def, -- We must show `∀ (x : ℤ), x ∈ {x : ℤ | even (x*x)} → {x : ℤ | even x}`\n  intro x, -- Assume `x : ℤ`. We must show `x ∈ {x : ℤ | even (x*x)} → {x : ℤ | even x}`\n  sorry  \nend\n\n-- Exercise 129:\n/-\nWe'll show 'anti-symmetry' of the subset relation. That is, for sets `S` and `T`, we show\n`S = T ↔ (S ⊆ T) ∧ (T ⊆ S)`.\n-/\ntheorem subset_antisymm (A : Type*) (S T : set A) : S = T ↔ (S ⊆ T) ∧ (T ⊆ S) :=\nbegin\n  rw ext_iff, -- Rewrite using the definition of set.\n  repeat { rw subset_def, }, -- Rewrite (repeatedly) using the definition of subset.\n  split,\n  { intro h ,\n    sorry, }, \n  { intros h x,\n    sorry, }, \nend\n\n-- Exercise 130:\n-- Transitivity of the subset relation. We prove this from the definition.\ntheorem subset_trans (A : Type*) (S T U : set A) : (S ⊆ T) ∧ (T ⊆ U) → (S ⊆ U) :=\nbegin\n  repeat { rw subset_def, }, -- Rewrite (repeatedly) using the definition of subset.\n  intros h x h₂, -- Assume `h : (S ⊆ T) ∧ (T ⊆ U)`, `x : A`, and `h₂ : x ∈ S`.\n  cases h with h₃ h₄, -- Left & right ∧ elim. `h₃ : ∀ x, x ∈ S → x ∈ T`, `h₄ : ∀ x, x ∈ T → x ∈ U`.\n  sorry  \nend\n\n\n/-\nWe'll prove that for all sets `S` and `T` on a type `A`, `¬(S ⊆ T) ↔ ∃ x, x ∈ S ∧ x ∉ T`.\n-/\ntheorem not_subset {A : Type*} (S T : set A): ¬(S ⊆ T) ↔ ∃ x, x ∈ S ∧ x ∉ T :=\nbegin\n  rw subset_def, -- Rewrite using the definition of subset.\n  push_neg, -- Negate the universal quantifier and the implication,\n  refl, -- The result follows by reflexivity.\nend\n\n\n/-\nIn the following, we show `{4, 2, 6}` is a subset of the set of even integers.\nIn Lean, we write the above set as `({4, 2, 6} : set ℤ)`.\nNote that the `rcases` tactic decomposes set membership recursively.\n-/\nexample : ({4, 2, -6} : set ℤ) ⊆ {x : ℤ | even x} :=\nbegin\n  intros x h, -- Assume `x : ℤ` and `h : x ∈ {4, 2, 6}`.\n  rcases h with hm₆ | h₂ | h₄ | k,\n  { use (-3), rw hm₆, norm_num, }, -- The case `x = -6`.\n  { use 1, rw h₂, norm_num, }, -- The case `x = 2`.\n  { use 2, rw h₄, norm_num, }, -- The case `x = 4`.\n  { exfalso, apply k }, -- The case `x ∈ ∅`.\nend \n\nopen classical\nlocal attribute [instance] prop_decidable\n\n/-\nLet `U = {x : ℤ | x ≤ 8 ∧ x > 4}` and let `S` be the set of even integers. We'll show `¬(U ⊆ S)`.\n\n-/\nexample : ¬( {x : ℤ | x ≤ 8 ∧ x > 4} ⊆ {x : ℤ | even x} ) :=\nbegin\n  rw not_subset, -- By the `not_subset` result, it suffices to show\n  -- `∃ x : ℤ, x ∈ U ∧ x ∉ S`.\n  use 5, -- By `∃` intro on `5 : ℤ`, it suffices to prove `5 ∈ U ∧ 5 ∉ S`.\n  split, -- By and introduction, it suffices to prove 1. `5 ∈ U` and 2. `5 ∉ S`.\n  { split; -- By and introduction, it suffices to prove `5 ≤ 8` and `5 > 4` }\n    -- The semi-colon (rather than comma) here means, 'apply the following tactic to *both* goals'.\n      norm_num, -- We close both goals `5 ≤ 8` and `5 > 4` with norm_num.\n  },\n  { rw nmem_set_of_eq, -- Rewriting by definition of `∉`, the goal is to show `¬even 5`.\n    rw even_iff_not_odd, -- Equally, to show `¬¬odd 5`.\n    rw not_not, -- By double negation, we must show `odd 5`, i.e. `∃ m : Z, 5 = 2 * m + 1`.\n    use 2, -- By `∃` intro with `2`, it suffices to show `5 = 2 * 2 + 1`.\n    norm_num, -- We close the goal with `norm_num`.     \n  }\nend\n\n/-\nWe show the subset relation is not symmetric via a counterexample.\nWe aim to show `¬ (∀ S T, S ⊆ T → T ⊆ S)`.\n-/\nexample : ¬(∀ A : Type*, ∀ S T : set A, S ⊆ T → T ⊆ S) :=\nbegin\n  push_neg, -- Push the negation inside the goal to tranform it to\n  -- `∃ (A : Type*), ∃ S T : set A, S ⊆ T ∧ ¬(T ⊆ S)`.\n  use [ℤ, {1, 2}, {1, 2, 3}], -- Take `A = ℤ`, `S = {1, 2}`, and `T = {1, 2, 3}`.\n  split,\n  { exact subset_insert 3 {1, 2} }, -- `{1, 2, 3}` is the set construct by inserting `3`\n  -- into the set `{1, 2}`, so `{1, 2}` is a subset of `{1, 2, 3}`.\n  { rw subset_def, -- Rewrite the goal using the definition of subset.\n    intro h, -- Assume `h : ∀ x, x ∈ {1, 2, 3} → x ∈ {1, 2}`.\n    specialize h 3, -- By `∀` elim. on `h` with `3`, we have `h : 3 ∈ {1, 2, 3} → 3 ∈ {1, 2}`.\n    contrapose! h, -- Negating, the goal is equivalent to `3 ∈ {1, 2, 3} ∧ 3 ∉ {1, 2}`.\n    split; -- By and introduction, it suffices to prove 1. `3 ∈ {1, 2, 3}` and 2. `3 ∉ {1, 2}`.\n      norm_num, }, -- Close both goals by `norm_num`.\nend\n\nend subsets\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_23_subsets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7762821121788539}}
{"text": "import Proofs.Naturals\n\ninductive le : ℕ → ℕ → Type where \n  | zLEN : {n : ℕ} → le 0 n \n  | sLEN : le m n  → le (ℕ.s m) (ℕ.s n) \n\nmacro_rules | `($x ≤ $y)  => `(le $x $y)\n\nexample : (2 ≤ 4) := le.sLEN (le.sLEN (le.zLEN))\n\ntheorem invLE : ℕ.s m ≤ ℕ.s n → m ≤ n | le.sLEN n => n\ntheorem invZE : ∀{m : ℕ}, m ≤ 0 → m = 0 | _, le.zLEN => rfl\n\n-- Relation types\n-- Reflexive: a ≤ n holds\n-- Transitive: if m ≤ n and n ≤ j then m ≤ j\n-- Antisimetric: if m ≤ n and n ≤ m then m = n\n-- Total: forall a b either a ≤ b or b ≤ a holds\n\n-- Pre order: reflexive + transative\n-- Partial order: also antisimetric\n-- Total oroder: also total\n\ninductive Total : ℕ → ℕ → Type where \n  | forward : m ≤ n → Total m n \n  | flipped : n ≤ m → Total m n \n\ndef totalSuc : Total m n → Total (ℕ.s m) (ℕ.s n)\n  | Total.forward m => Total.forward (le.sLEN m)\n  | Total.flipped m => Total.flipped (le.sLEN m)\n\ntheorem Le.refl : ∀ {m : ℕ}, m ≤ m   \n  | 0 => le.zLEN\n  | ℕ.s m => le.sLEN (@refl m)\n\ntheorem Le.trans : m ≤ n → n ≤ p → m ≤ p\n  | le.zLEN, n => le.zLEN\n  | le.sLEN m, le.sLEN n => le.sLEN (trans m n)\n\ntheorem Le.antiSym : m ≤ n → n ≤ m → m = n \n  | le.zLEN, le.zLEN => rfl\n  | le.sLEN m, le.sLEN n => congrArg ℕ.s (antiSym m n)\n\ntheorem Le.total : ∀ {m n : ℕ}, Total m n\n  | 0, n => Total.forward le.zLEN\n  | n, 0 => Total.flipped le.zLEN\n  | ℕ.s m, ℕ.s n => totalSuc (@total m n)\n\ntheorem Le.Add.monoLeft: ∀ {m n p : ℕ}, m ≤ n → p + m ≤ p + n\n  | m, n, 0, hip   => hip\n  | m, n, ℕ.s p, hip => le.sLEN (@monoLeft m n p hip)\n\ntheorem Le.Add.monoRight {m n p : ℕ} : m ≤ n → m + p ≤ n + p := by \n  simp [Nt.Add.comm m p, Nt.Add.comm n p]\n  apply Le.Add.monoLeft\n\ntheorem Le.Add.mono : ∀ {m n p q : ℕ}, (m ≤ n) → (p ≤ q) → (p + m ≤ q + n)\n  | m, n, p, q, h1, h2 => Le.trans (@Le.Add.monoLeft m n p h1) (@Le.Add.monoRight p q n h2)\n\ntheorem Le.Mul.monoLeft : ∀ {m n p : ℕ}, (m ≤ n) → (p * m ≤ p * n)\n  | m, n, 0, h1     => by simp [Nt.Mul.leftNeutral]; exact le.zLEN\n  | m, n, ℕ.s p, h1 => by \n    simp [Nt.Mul.sucLeft]; \n    apply (Le.Add.mono (@monoLeft m n p h1) h1)\n\ntheorem Le.Mul.mono : ∀ {m n p q : ℕ}, (m ≤ n) -> (p ≤ q) → (p * m ≤ q * n)\n  | m, n, 0    , q, h1, h2 => by simp [Nt.Mul.leftNeutral]; exact le.zLEN\n  | m, n, ℕ.s p, ℕ.s q, h1, h2 => by \n    simp [Nt.Mul.sucLeft]; \n    exact (@Le.Add.mono (p*m) (q*n) m n (@mono m n p q h1 (invLE h2)) h1)\n    \n-- Inequality \n\ninductive ls : ℕ → ℕ → Type where \n  | zLEN : {n : ℕ} → ls 0 (ℕ.s n) \n  | sLEN : ls m n  → ls (ℕ.s m) (ℕ.s n) \n\nmacro_rules | `($x < $y)  => `(ls $x $y)\n\ninductive Tricotomy : ℕ → ℕ → Type where \n  | lessT  : {n m : ℕ} → ls n m → Tricotomy n m\n  | greatT : {n m : ℕ} → ls m n → Tricotomy n m\n  | eqT    : {n : ℕ}           → Tricotomy n n\n\ndef succTricotomy : Tricotomy m n → Tricotomy (ℕ.s m) (ℕ.s n)\n  | Tricotomy.eqT      => Tricotomy.eqT \n  | Tricotomy.lessT p  => Tricotomy.lessT (ls.sLEN p)\n  | Tricotomy.greatT p => Tricotomy.greatT (ls.sLEN p)\n\ntheorem tricotomy : ∀ {m n}, Tricotomy m n\n  | 0    , 0     => Tricotomy.eqT\n  | ℕ.s m, 0     => Tricotomy.greatT ls.zLEN\n  | 0    , ℕ.s n => Tricotomy.lessT ls.zLEN\n  | ℕ.s m, ℕ.s n => succTricotomy (@tricotomy m n)\n\ntheorem Ls.trans : m < n → n < p → m < p \n  | ls.zLEN  , ls.sLEN m => ls.zLEN \n  | ls.sLEN m, ls.sLEN n => ls.sLEN (trans m n)\n\ntheorem Ls.Add.monoLeft : ∀ {m n p: ℕ}, m < n → (p + m < p + n)\n  | m, n, 0, h1 => h1\n  | m, n, ℕ.s p, h1 => ls.sLEN (@monoLeft m n p h1)\n\ntheorem Ls.Add.monoRight : ∀ {m n p: ℕ}, m < n → (m + p < n + p)\n  | m, n, 0, h1 => by simp [Nt.Add.rightId]; exact h1\n  | m, n, ℕ.s p, h1 => by rw [Nt.Add.comm m (ℕ.s p), Nt.Add.comm n (ℕ.s p)]; exact (@Ls.Add.monoLeft m n (ℕ.s p) h1)\n\ntheorem Ls.Add.mono {m n p q : ℕ} (h1: m < n) (h2: p < q) : (p + m < q + n) := \n  Ls.trans (@Ls.Add.monoLeft m n p h1) (@Ls.Add.monoRight p q n h2)\n\ntheorem Ls.Eq.iff : ∀ {m n : ℕ}, ℕ.s m ≤ n → m < n \n  | ℕ.z, ℕ.s n, le.sLEN _ => ls.zLEN\n  | ℕ.s m, ℕ.s n, le.sLEN o => ls.sLEN (iff o)\n\ntheorem Ls.Eq.iffInv : ∀ {m n : ℕ}, m < n → ℕ.s m ≤ n \n  | 0,     ℕ.s n, ls.zLEN   => le.sLEN le.zLEN\n  | ℕ.s m, ℕ.s n, ls.sLEN o => le.sLEN (iffInv o)\n\ntheorem Ls.toLs : ∀ {m n : ℕ}, m < n → m ≤ n \n  | 0,     ℕ.s n, ls.zLEN   => le.zLEN\n  | ℕ.s m, ℕ.s n, ls.sLEN o => le.sLEN (toLs o)\n\ntheorem leTransRevisited (h1: m < n) (h2: n < p): m < p := Ls.Eq.iff (Le.trans (Ls.Eq.iffInv h1) (Ls.toLs h2))", "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/Relations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7762106105415448}}
{"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\n! This file was ported from Lean 3 source module analysis.normed_space.indicator_function\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 Mathlib.Analysis.Normed.Group.Basic\nimport Mathlib.Algebra.IndicatorFunction\n\n/-!\n# Indicator function and norm\n\nThis file contains a few simple lemmas about `Set.indicator` and `norm`.\n\n## Tags\nindicator, norm\n-/\n\n\nvariable {α E : Type _} [SeminormedAddCommGroup E] {s t : Set α} (f : α → E) (a : α)\n\nopen Set\n\ntheorem norm_indicator_eq_indicator_norm : ‖indicator s f a‖ = indicator s (fun a => ‖f a‖) a :=\n  flip congr_fun a (indicator_comp_of_zero norm_zero).symm\n#align norm_indicator_eq_indicator_norm norm_indicator_eq_indicator_norm\n\ntheorem nnnorm_indicator_eq_indicator_nnnorm :\n    ‖indicator s f a‖₊ = indicator s (fun a => ‖f a‖₊) a :=\n  flip congr_fun a (indicator_comp_of_zero nnnorm_zero).symm\n#align nnnorm_indicator_eq_indicator_nnnorm nnnorm_indicator_eq_indicator_nnnorm\n\ntheorem norm_indicator_le_of_subset (h : s ⊆ t) (f : α → E) (a : α) :\n    ‖indicator s f a‖ ≤ ‖indicator t f a‖ := by\n  simp only [norm_indicator_eq_indicator_norm]\n  exact indicator_le_indicator_of_subset ‹_› (fun _ => norm_nonneg _) _\n#align norm_indicator_le_of_subset norm_indicator_le_of_subset\n\ntheorem indicator_norm_le_norm_self : indicator s (fun a => ‖f a‖) a ≤ ‖f a‖ :=\n  indicator_le_self' (fun _ _ => norm_nonneg _) a\n#align indicator_norm_le_norm_self indicator_norm_le_norm_self\n\ntheorem norm_indicator_le_norm_self : ‖indicator s f a‖ ≤ ‖f a‖ := by\n  rw [norm_indicator_eq_indicator_norm]\n  apply indicator_norm_le_norm_self\n#align norm_indicator_le_norm_self norm_indicator_le_norm_self\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/NormedSpace/IndicatorFunction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7761311274605873}}
{"text": "import algebra.pi_instances\nimport data.real.basic\n\nlocal attribute [instance] classical.prop_decidable\n\nclass metric_space (α : Type*) :=\n(dist : α → α → ℝ)\n(dist_self : ∀ x, dist x x = 0)\n(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)\n(dist_comm : ∀ x y : α, dist x y = dist y x)\n(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)\n\nopen metric_space\n\nsection\n\nvariables {α : Type*} [metric_space α]\nvariables {u v : ℕ → α} {l l₁ l₂ : α}\n\ndef limit (u : ℕ → α) (l : α) : Prop :=\n  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, dist (u n) l ≤ ε\n\ntheorem dist_nonneg {x y : α}: 0 ≤ dist x y :=\nbegin\n  have : dist x x ≤ dist x y + dist y x, from dist_triangle _ _ _,\n  rw dist_comm y x at this,\n  rw dist_self at this,\n  linarith\nend\n\ntheorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=\nbegin\n  split; contrapose!,\n  { rintro rfl,\n    have : dist x x = 0, from dist_self _,\n    linarith },\n  { intro h,\n    apply eq_of_dist_eq_zero,\n    have : 0 ≤ dist x y, from dist_nonneg,\n    linarith }\nend\n\nlemma limit_unique (h₁ : limit u l₁) (h₂ : limit u l₂) : l₁ = l₂ :=\nbegin\n  by_contra h,\n  let ε := dist l₁ l₂,\n  have : ε > 0, from dist_pos.mpr h,\n  cases h₁ (ε/3) (by linarith) with N₁ hN₁,\n  cases h₂ (ε/3) (by linarith) with N₂ hN₂,\n  let n := max N₁ N₂,\n  specialize hN₁ n (le_max_left _ _),\n  specialize hN₂ n (le_max_right _ _),\n  have : dist (u n) l₁ + dist (u n) l₂ < ε, by linarith,\n  have : ε ≤ dist l₁ (u n) + dist (u n) l₂, from dist_triangle _ _ _,\n  linarith [dist_comm l₁ (u n)]\nend\n\nend\n\nnotation `|`x`|` := abs x\n\nnoncomputable instance : metric_space ℝ :=\n{ dist := λ x y, |x - y|,\n  -- This proof term is hideous and beautiful simultaneously.\n  dist_self := λ x, eq.symm (sub_self x) ▸ abs_zero,\n  eq_of_dist_eq_zero := λ x y, eq_of_abs_sub_eq_zero,\n  dist_comm := abs_sub,\n  dist_triangle := abs_sub_le }\n\nvariables {u v : ℕ → ℝ} {c l l₁ l₂ : ℝ}\n\n@[simp] def const (l : ℝ) : ℕ → ℝ := function.const _ l\n\nlemma neg_const : -const l = const (-l) := by funext; simp\n\ntheorem const_limit : limit (const c) c :=\nbegin\n  intros ε ε_pos,\n  use 0,\n  intros n hn,\n  unfold dist,\n  simp,\n  linarith\nend\n\ntheorem limit_add_limit (h₁ : limit u l₁) (h₂ : limit v l₂) :\n  limit (u + v) (l₁ + l₂) :=\nbegin\n  intros ε ε_pos,\n  cases h₁ (ε/2) (by linarith) with N₁ hN₁,\n  cases h₂ (ε/2) (by linarith) with N₂ hN₂,\n  use max N₁ N₂,\n  intros n hn,\n  specialize hN₁ n (le_of_max_le_left hn),\n  specialize hN₂ n (le_of_max_le_right hn),\n  unfold dist at *,\n  calc\n  |(u + v) n - (l₁ + l₂)| = |(u n + v n) - (l₁ + l₂)| : rfl\n  ...                     = |(u n - l₁) + (v n - l₂)| : by congr; ring\n  ...                     ≤ |u n - l₁| + |v n - l₂|   : by apply abs_add\n  ...                     ≤ ε                         : by linarith\nend\n\nlemma limit_add_const (h : limit u l) : limit (u + const c) (l + c) := \nlimit_add_limit h const_limit\n\nlemma limit_sub_self (h : limit u l) : limit (u - const l) 0 :=\nbegin\n  rw [←sub_self l, sub_eq_add_neg, sub_eq_add_neg, neg_const],\n  exact limit_add_const h\nend\n\nexample (α : Type*) [linear_ordered_field α] (a b c : α) (h : a ≤ b / c) (H : c > 0) : a*c ≤ b := by refine (le_div_iff H).mp h\n\nlemma limit_mul_const (h : limit u l) : limit (u * const c) (l * c) :=\nbegin\n  intros ε ε_pos,\n  by_cases hc : c = 0,\n  { use 0,\n    intros n hn,\n    rw hc,\n    simp,\n    rw dist_self,\n    exact le_of_lt ε_pos },\n  { change c ≠ 0 at hc,\n    have : ε / |c| > 0, from div_pos_of_pos_of_pos ε_pos (by rwa abs_pos_iff),\n    cases h _ this with N hN,\n    use N,\n    intros n hn,\n    specialize hN n hn,\n    unfold dist at *,\n    suffices : |(u n - l) * c| ≤ ε,\n    { calc\n      |(u * const c) n - l * c| = |(u n * c) - l * c| : rfl\n      ...                       = |(u n - l) * c|     : by congr; ring\n      ...                       ≤ ε                   : this },\n    rwa [abs_mul, ←le_div_iff],\n    rwa abs_pos_iff }\nend\n\ntheorem limit_zero_mul_limit_zero (h₁ : limit u 0) (h₂ : limit v 0) :\n  limit (u * v) 0 :=\nbegin\n  intros ε ε_pos,\n  have : ε.sqrt > 0, from real.sqrt_pos.mpr ε_pos,\n  cases h₁ (ε.sqrt) this with N₁ hN₁,\n  cases h₂ (ε.sqrt) this with N₂ hN₂,\n  use max N₁ N₂,\n  intros n hn,\n  specialize hN₁ n (le_of_max_le_left hn),\n  specialize hN₂ n (le_of_max_le_right hn),\n  unfold dist at *,\n  calc\n  |(u * v) n - 0| = |(u n * v n) - 0|       : rfl\n  ...             = |(u n - 0) * (v n - 0)| : by ring\n  ...             = |u n - 0| * |v n - 0|   : by apply abs_mul\n  ...             ≤ ε.sqrt * ε.sqrt         : mul_le_mul hN₁ hN₂ (abs_nonneg _) (le_of_lt this)\n  ...             = ε.sqrt ^ 2              : by ring\n  ...             = ε                       : real.sqr_sqrt (le_of_lt ε_pos)\nend\n\nlemma limit_neg_iff : limit (-u) (-l) ↔ limit u l :=\nbegin\n  split;\n  { intros h ε ε_pos,\n    cases h ε ε_pos with N hN,\n    use N,\n    intros n hn,\n    specialize hN n hn,\n    unfold dist at *,\n    simp at *,\n    rwa abs_sub at hN }\nend\n\nnotation u `+` v := limit_add_limit u v\n\ntheorem limit_mul_limit (h₁ : limit u l₁) (h₂ : limit v l₂) :\n  limit (u * v) (l₁ * l₂) :=\nbegin\n  let c₁ := const l₁,\n  let c₂ := const l₂,\n  have w₁ : limit ((u - c₁) * (v - c₂)) 0,\n  from limit_zero_mul_limit_zero (limit_sub_self h₁) (limit_sub_self h₂),\n  rw (show (u - c₁) * (v - c₂) = u * v - u * c₂ - v * c₁ + c₁ * c₂, by ring) at w₁,\n  have w₂ : limit (-c₁ * c₂) (-l₁ * l₂),\n  { simp,\n    rw limit_neg_iff,\n    exact limit_mul_const const_limit },\n  have w₃ : limit (u * c₂) (l₁ * l₂), from limit_mul_const h₁,\n  have w₄ : limit (v * c₁) (l₁ * l₂), by { rw mul_comm l₁, exact limit_mul_const h₂ },\n  have w := w₁ + w₂ + w₃ + w₄,\n  -- The most satisfying two lines.\n  simp at w,\n  ring at w,\n  rwa [mul_comm u, mul_comm l₁]\nend", "meta": {"author": "pedrominicz", "repo": "learn", "sha": "b79b802a9846c86c21d4b6f3e17af36e7382f0ef", "save_path": "github-repos/lean/pedrominicz-learn", "path": "github-repos/lean/pedrominicz-learn/learn-b79b802a9846c86c21d4b6f3e17af36e7382f0ef/src/real_analysis/01_convergent_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7761229793568745}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport topology.basic\n\n/-!\n\n# API para el `interior` de un conjunto.\n\nFijamos un espacio topológico `X` y un subconjunto `S : set X`. \n\nEn Lean, `interior S` denota el interior de `S`, es decir, el mayor \nsubconjunto abierto de `S`. Sin embargo, para practicar parte\nde lo introducido en el fichero `conjuntos_2.lean`, en este \nfichero definiremos de nuevo esta noción (que denotaremos\n`interior' S`) y crearemos su API básica.\n\n-/\n\n--Fijamos un espacio topológico `X` y un subconjunto `S : set X`. \nvariables {X : Type} [topological_space X] (S : set X)\n\n/-\n\n## API para espacios topológicos\n\n`is_open S : Prop` es el predicado que dice que `S : set X` es abierto.\n\nLos siguientes lemas de `mathlib` serán útiles en estos ejercicios:\n* is_open_univ\n* is_open_Union, is_open_bUnion\n* is_open.inter\n\nLos nombres son descriptivos, pero si queréis aseguraros de que un\nlema dice lo que creéis, podéis utilizar #check o buscarlo en la\ndocumentación de mathlib (https://leanprover-community.github.io/mathlib_docs/).\n-/\n\n\nopen set\n\n/-- El interior de `S` es la unión de todos los subconjuntos abiertos de `X`\n  contenidos en `S`. -/\ndef interior' (S : set X) : set X := ⋃ (U ∈ {V : set X | is_open V ∧ V ⊆ S}), U\n\n-- Lema de reescritura\nlemma mem_interior' (x : X) :\n  x ∈ interior' S ↔ ∃ (U : set X) (hU : is_open U) (hUS : U ⊆ S), x ∈ U :=\nbegin\n  unfold interior',\n  simp only [set.mem_set_of_eq, set.mem_Union, exists_prop],\n  tauto,\nend\n\n/-- Como hemos definido `interior'` como una `bUnion`, podemos empezar\n  la demostración con `apply is_open_bUnion`. -/\nlemma interior'_open : is_open (interior' S) := \nbegin\n  apply is_open_bUnion,\n  intros U hU,\n  exact hU.left,\nend\n\nlemma interior'_subset : interior' S ⊆ S :=\nbegin\n  intros x hx,\n  rw mem_interior' at hx,\n  obtain ⟨U, hU, hUS, hUX⟩ := hx,\n  exact hUS hUX,\nend\n\nvariable {S}\n\nlemma subset_interior' {U : set X} (hU : is_open U) (hUS : U ⊆ S) : U ⊆ interior' S :=\nbegin\n  intros x hx,\n  rw mem_interior',\n  exact ⟨U, hU, hUS, hx⟩,\nend\n\nlemma interior'_mono {S T : set X} (hST : S ⊆ T) : interior' S ⊆ interior' T :=\nbegin\n  rintros x hx,\n  rw mem_interior' at hx ⊢,\n  obtain ⟨U, hU, hUS, hUx⟩ := hx,\n  exact ⟨U, hU, subset_trans hUS hST, hUx⟩,\nend\n\n\n/- En lugar de empezar con `ext x`, podéis usar `apply set.subset.antisymm`,\n  que dice que si `S ⊆ T` y `T ⊆ S` entonces `S = T`. -/\nlemma interior'_interior' : interior' (interior' S) = interior' S :=\nbegin\n  apply set.subset.antisymm,\n  { exact interior'_subset _ },\n  { exact subset_interior' (interior'_open _) rfl.subset },\nend\n\n--Ejemplos de interiores:\n\nlemma interior'_empty : interior' (∅ : set X) = ∅ :=\nbegin\n  exact set.eq_empty_of_subset_empty (interior'_subset _)\nend\n\nlemma interior'_univ : interior' (set.univ : set X) = set.univ :=\nbegin\n  exact set.eq_univ_of_univ_subset (subset_interior' is_open_univ rfl.subset)\nend\n\nlemma interior'_inter (S T : set X) : interior' (S ∩ T) = interior' S ∩ interior' T :=\nbegin\n  apply set.subset.antisymm,\n  { rw [set.subset_inter_iff],\n    exact ⟨interior'_mono (inter_subset_left _ _), interior'_mono (inter_subset_right _ _)⟩, },\n  { rintros x ⟨hxS, hxT⟩,\n    rw mem_interior' at hxS hxT ⊢,\n    obtain ⟨U, hU, hUS, hUx⟩ := hxS,\n    obtain ⟨V, hV, hVT, hVx⟩ := hxT,\n    refine ⟨U ∩ V, hU.inter hV, inter_subset_inter hUS hVT, mem_inter hUx hVx⟩ },\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_5/soluciones/interior.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7761082987644408}}
{"text": "import topology.metric_space.basic\n\nnoncomputable theory \n\nopen topological_space filter\n\nuniverse u            -- the universe we work in\nvariable {X : Type u} -- the underlying set for our space\n\n/-- input a pseudo_metric_space and a set. Returns a collection of open sets centered on that set. -/\ndef base_of_metric_and_set [M : pseudo_metric_space X] (D : set X) : \nset (set X) := { Y | ∃(n:ℕ) (d:X), d ∈ D ∧ metric.ball d (1/(↑n+1)) = Y }\n\n/-This is a lemma to make it easier to access the inner sets.-/\nlemma sets_in_base [M : pseudo_metric_space X] (D : set X) : ∀(n:ℕ) (d ∈ D), metric.ball d (1/(↑n+1)) ∈ base_of_metric_and_set D :=\nbegin\n  intros n d hd,\n  refine set.mem_def.mpr _,\n  split,\n  use d,\n  split, \n  exact hd,\n  simp,\nend\n\n/- This is a lemma to more easily say dense set intsersect all balls.-/\nlemma dense_set_int_balls [M : pseudo_metric_space X] (D : set X) (hD : dense D) (x:X) (r:ℝ) ( hr_pos : r>0): set.nonempty ((metric.ball x r) ∩ D) :=\nbegin\n  have ball_open := @metric.is_open_ball X M x r, \n  have ball_nonempty := @metric.nonempty_ball X M x r,\n  rcases ball_nonempty with ⟨-,ball_nonempty⟩,\n  specialize ball_nonempty hr_pos,\n  have D_int_ball := dense.inter_open_nonempty hD (metric.ball x r) ball_open ball_nonempty, \n  exact D_int_ball,\nend\n\nlemma sets_in_nbhd [M : pseudo_metric_space X] (D : set X) (hD : dense D) (U : set X) ( hU : is_open U) (x : X) (hx : x ∈ U): \n∃(n:ℕ) (d ∈ D), metric.ball d (1/(↑n+1)) ⊆ U ∧ x ∈ metric.ball d (1/(n+1 : ℝ)) :=\nbegin\n  have hdist := (@metric.is_open_iff X M U),\n  rcases hdist with ⟨hdist , -⟩,\n  replace hdist := hdist hU x hx,\n  rcases hdist with ⟨δ, ⟨δ_pos, hball⟩ ⟩,\n  have δ2_pos : δ/2 > 0 := by linarith,\n  have hyp := exists_nat_one_div_lt (δ2_pos),\n  cases hyp with n n_less_δ2,\n  have int_nonempty := dense_set_int_balls D hD x (1 / (↑n + 1)) (nat.one_div_pos_of_nat),\n  have d_in_int := @set.nonempty.some_mem X (metric.ball x (1 / (↑n + 1)) ∩ D) int_nonempty,\n  cases d_in_int with d_in_ball_xn d_in_D,\n  use [n, int_nonempty.some, d_in_D],\n  set d := int_nonempty.some,\n  split,\n  have ball_dn_subset_ball_xδ : metric.ball d (1/(↑n + 1)) ⊆ metric.ball x δ,\n  { have h_dist := @metric.mem_ball X M x d (1/(↑n + 1)),\n    rcases h_dist with ⟨h_dist, -⟩,\n    specialize h_dist d_in_ball_xn,\n    refine metric.ball_subset _,    \n    linarith  },\n  exact set.subset.trans ball_dn_subset_ball_xδ hball,\n  have final := @metric.mem_ball_comm X M x d (1 / (↑n+1)),\n  rw final,\n  exact d_in_ball_xn,\nend\n\n/--The construction results in a topological basis when the set is dense. -/\nlemma metric_and_dense_is_basis [M : pseudo_metric_space X] (D : set X) (hD : dense D): topological_space.is_topological_basis (base_of_metric_and_set D) :=\nbegin\n  set BASIS := base_of_metric_and_set D,\n  have hopen : ∀B ∈ BASIS, is_open B, \n  { rintro B ⟨n, ⟨d, ⟨hd, b2⟩⟩⟩,\n    rw ← b2,\n    apply metric.is_open_ball },\n  have hbase : ∀ x:X, ∀ U:set X, (x ∈ U)  → is_open U → (∃ (B : set X) (H : B ∈ BASIS), x ∈ B ∧ B ⊆ U),\n  { intros x U U_is_nbhd U_is_open,\n    have openiff := @metric.is_open_iff X M U,\n    rcases openiff with ⟨case1,-⟩,\n    replace case1 := case1 U_is_open,\n    specialize case1 x U_is_nbhd,\n    rcases case1 with ⟨ε,  ⟨ε_geq, Hball_subset⟩⟩, \n    have HBnbhd := sets_in_nbhd D hD U U_is_open x U_is_nbhd,\n    rcases HBnbhd with ⟨Jn, ⟨Jd, ⟨JD, ⟨Jhu, Jhx⟩⟩⟩⟩,\n    use metric.ball Jd (1 / (↑Jn+1)),\n    split,\n    apply sets_in_base D Jn Jd JD,\n    split,\n    apply Jhx,\n    apply Jhu },\n  exact is_topological_basis_of_open_of_nhds (hopen) (hbase),\nend", "meta": {"author": "carlosa95silva", "repo": "project", "sha": "90fe846b85d46f56160a9ec14c8db5d1f5fc36ee", "save_path": "github-repos/lean/carlosa95silva-project", "path": "github-repos/lean/carlosa95silva-project/project-90fe846b85d46f56160a9ec14c8db5d1f5fc36ee/src/metric_stuff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7761082979167324}}
{"text": "\n-- import data.real.basic  -- Real numbers and their basic properties\nimport tactic\nimport tactic.suggest  -- Lean's built-in \"help\" functionality\n\n/-\nLean exercise:\n\nDefine the relation \"x is a subsequence of y\", and prove ...\n\n\"subsequence\" is a preorder, since it is:\n* reflexive\n* transitive\n\n\"subsequence\" is not a partial order, since it is:\n* not antisymmetric\n\n-/\n\n\n/- DEFINITIONS -/\n\n-- An infinite sequence is equivalent to a map from ℕ to sequence elements.\ndef seq (t : Type) :=\n  ℕ → t\n\n-- To define \"subsequence\", we need to keep track of a sequence of increasing indices.\n-- An increasing indices sequence is an increasing sequence of natural numbers.\ndef is_inc_indices (s : seq ℕ) :=\n  ∀ i j : ℕ , (i < j) → (s i < s j)\ndef inc_indices :=\n  {s : seq ℕ // is_inc_indices s}\n\n-- A subsequence is created by taking some elements from a sequence, keeping them in order.\n-- Given a sequence and some increasing indices, we can construct a subsequence.\ndef subseq_of {t : Type} (p : seq t) (s : inc_indices) : seq t :=\n  λ i, p (s.1 i)\n\n-- We define subsequence in terms of inc_indices and subseq_of.\ndef subseq {t : Type} (x y : seq t) :=\n  ∃ s : inc_indices, x = subseq_of y s\n\n\n/- REFLEXIVITY -/\n\n-- subseq is a reflexive relation.\nlemma subseq_refl {t : Type} (a : seq t) : subseq a a :=\nbegin\n  unfold subseq,\n  use id,  -- use the identity function as the indexing sequence\n  {\n    -- prove ⊢ is_inc_indices id\n    -- unfold is_inc_indices,\n    intros i j h,\n    -- unfold id,\n    exact h,\n  },\n  {\n    -- prove ⊢ a = subseq_of a ⟨id ℕ, _⟩\n    unfold subseq_of,\n    simp,\n  },\nend\n\n\n/- TRANSITIVITY -/\n-- First, define/prove that increasing indices can be composed, and will still be increasing.\ndef inc_comp (s1 s2 : inc_indices) : inc_indices :=\n⟨\n  s1.1 ∘ s2.1,\n  begin\n    unfold is_inc_indices,\n    intros i j h,\n    unfold function.comp,\n    apply s1.2,\n    apply s2.2,\n    exact h,\n  end\n⟩\n\n-- subseq is a transitive relation.\nlemma Subseq_trans {t : Type} (a b c : seq t) :\n  subseq a b → subseq b c → subseq a c :=\nbegin\n  unfold subseq,\n  -- intros h1 h2,\n  -- cases h1 with s1 h1,\n  -- cases h2 with s2 h2,\n  rintros ⟨s1, h1⟩ ⟨s2, h2⟩,\n  cases h1 with h1l h1r,\n  cases h2 with h2l h2r,\n  use inc_comp s2 s1,\n  exact h1,\nend\n\n\n/- NON-ANTISYMMETRIC -/\n-- 'subseq', as defined above, is not a partial order, since it is not antisymmetric.\n-- For antisymmetry, we would have to have:\n--   ∀ a b,  (a ≤ b) ∧ (b ≤ a)  →  a = b\n-- We will prove that subseq is not antisymmetric, by providing a counterexample.\n\n-- The sequence (0, 1, 0, 1, ...).\ndef seq0101 := λ n : ℕ, n % 2\n-- The sequence (1, 0, 1, 0, ...).\ndef seq1010 := λ n : ℕ, (n + 1) % 2\n\n-- The indexing sequence (1, 2, 3, 4, ...).\ndef seq1234 : inc_indices :=\n⟨\n  λ n : ℕ, n + 1,\n  begin\n    unfold is_inc_indices,\n    intros i j h,\n    simp,\n    exact h,\n  end\n⟩\n\n-- subseq is not an antisymmetric relation.\nlemma subseq_not_antisymm :\n  ¬ ∀ t : Type, ∀ a b : seq t, subseq a b → subseq b a → a = b :=\nbegin\n  push_neg,\n  use ℕ,\n  use seq0101,\n  use seq1010,\n  split,\n  {\n    -- prove ⊢ subseq seq0101 seq1010\n    use seq1234,\n    unfold subseq_of,\n    rw seq1234,\n    rw seq0101,\n    rw seq1010,\n    simp,\n    apply funext,\n    intro n,\n    rw add_assoc,\n    simp,\n  },\n  split,\n  {\n    -- prove ⊢ subseq seq1010 seq0101\n    use seq1234,\n    unfold subseq_of,\n    rw seq1234,\n    rw seq0101,\n    rw seq1010,\n  },\n  {\n    -- prove ⊢ seq0101 ≠ seq1010\n    intro h,\n    have hh : (seq0101 0 = seq0101 0),\n    {refl},\n    nth_rewrite 0 h at hh,\n    rw seq0101 at hh,\n    rw seq1010 at hh,\n    simp at hh,\n    contradiction,\n  },\nend\n\n\n", "meta": {"author": "amackay", "repo": "lean_practice", "sha": "58db9e629dda11b464be7cdfe85a0252dc04e944", "save_path": "github-repos/lean/amackay-lean_practice", "path": "github-repos/lean/amackay-lean_practice/lean_practice-58db9e629dda11b464be7cdfe85a0252dc04e944/misc/subsequence_ordering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7760974507599331}}
{"text": "/-\nYou need to understand the following\nelements of automated predicate logic \nfor Exam 2\n\nSuppose P and Q are arbitrary propositions \n(i.e., P Q : Prop) and T and V are arbitrary\ntypes (i.e., T V : Type). \n\nKnow the following forms, how to prove them, \nhow to use proofs of them, and how to do these \nthings in Lean. \n\nTo know how to prove them and how to use proofs\nof them, you need an intuitive understanding of\nthe introduction and elimination rules for each\nform, and how to use them in Lean.\n\n* true : Prop\n* false : Prop\n* =                    -- equality\n* P ∧ Q : Prop\n* (∀ p : P, Q) : Prop  -- Q can involve p\n* T → V : Type         -- function type)\n* P → Q : Prop         -- implication)\n* ¬ P : Prop\n* P ↔ Q : Prop\n* P ∨ Q : Prop\n* (∃ p : P, Q) : Prop  -- Q can involve p\n* T → Prop             -- a property of Ts\n* T → V → Prop         -- a T-V binary relation\n\nKnowing this material, you are also expected to be\nable to combine these reasoning rules to prove more \ninteresting propositions. In general, such a proof\nfirst applies elimination rules to obtain additional \nuseful elements from given assumptions, and then uses \nintroduction  rules to combine the elements obtained \ninto proofs of desired conclusions. \n\nYou should have an intuitive understanding of the\nmeaning of each form and how to use each form in \nlogical reasoning. In particular, understand (1)\nthe introduction rules for each -- how to construct\nproofs in these forms -- and (2) the elimination\nrules for each form -- how to use proofs in these \nforms to obtain additional facts to be used in \nconstructing proofs of other propositions.\n\nFor extra credit, be able to work in Lean with\n(1) propositions and proofs involving combinations \nof quantifiers, such as (∀ x : X, ∃ y : Y, Z) and\n(∃ x : X, ∀ y : Y, Z), and with (2) negations of \nquantified propositions, such as ¬ (∃ p : P, Q) \nand ¬ (∀ p : P, Q).\n\nThe test will be structured to help you to know and\nto show how far you've gotten and where you still \nhave some work to do. \n\nHere are exercises for each form.\n-/\n\n/- ***************************************** -/\n/- ***************** true ****************** -/\n/- ***************************************** -/\n\n/- \n(1)\n\nUse \"example\" in Lean to prove that there\nis a proof of true.  Be sure that after the :=\nyou can provide a proof using both an expression\nand a tactic script.\n-/\n\n/- ***************************************** -/\n/- ***************** false ***************** -/\n/- ***************************************** -/\n\n/-\n(2)\nUse \"def\" in Lean to define a function, fq, \nthat proves that if P and Q are propositions \nand if Q is true then false → ¬ Q.\n-/\n\n\n/-\n(3)\nUse \"example\" in Lean to prove that if 0 = 1\nthen 0 ≠ 1.\n-/\n\n\n/-\n(4) Use \"example\" to prove that for any two\nnatural numbers, a and b if a = b then if \nb ≠ a then a ≠ b.\n-/\n\n\n\n/- ***************************************** -/\n/- ***************** and ******************* -/\n/- ***************************************** -/\n\n/-\n(5) \n\nUse \"example\" to prove that if P, Q, and R \nare propositions, P → Q → R → (P ∧ Q) ∧ R\n-/\n\n\n\n/-\n(6) \n\nUse \"example\" to prove that if P, Q, and R \nare propositions, (P ∧ Q) ∧ R → P ∧ R.\n-/\n\n\n/- ***************************************** -/\n/- *************** functions *************** -/\n/- ***************************************** -/\n\n/-\n(7) Use example to prove that if S and T \nare arbitrary types and if there is a value, \nt : T, then S → T. Remember that a proof of \nS → T has to be a function that if given any \nvalue of type S returns some value of type T.\n\nPresent this proof as a Python-style function\ndefinition, isFun, then using a tactic script. \nThe Π you can read and treast as ∀, for now.\n-/\n\n\n/-\n(8) use def to define comp to be a function \nthat takes as its argments, the types S, T, \nand R, along with a function of type S → T \nand a function of type T → R and that returns \na function of type S → R. It should take S,\nT, and R implicitly and st and tr explicitly.\n-/\n\n\n/-\n(9) Define square to be a function that\ntakes a natural number and returns its\nsquare, and inc to be a function that\ntakes a nat, n, and returns n + 1. Now\nuse def and comp to define incSquare to\nbe a function that takes a nat, n, as an\nargument and that returns one more than\nn^2. Use #reduce to check that the value\nof (incSquare 5) is 26. \n-/\n\n\n/-\n(10)\n\nConsider the function, sum4, below. What\nis the type of (sum4 3 7)? What function is\n(sum4 3 7)? Answer the second question \nwith a lambda abstraction.\n-/\n\n\n/- ***************************************** -/\n/- ************** implication ************** -/\n/- ***************************************** -/\n\n/-\n(11)\n\nUse several \"examples\" to prove (1) false → false, \n(2) false → true, (3) ¬ (true → false).\n-/\n\n/-\n(12)\n\nUse example to prove that for any two \npropositions, P, Q, if P ∧ Q is true\nthen if ¬ (P ∨ Q) is true, then you \ncan derive a proof of false.\n-/\n\n\n\n\n/- ***************************************** -/\n/- *************** forall (∀) ************** -/\n/- ***************************************** -/\n\n/-\n(13) \n\nUse example to prove that for all proposition,\nP, Q, and R, if P → Q → R then P → R.\n-/\n\n\n\n/-\n(14)\n\nProve that for any type, T, for any a : T, \nand for any property, (P : T → Prop), if \n(∀ t : T, P t), then P a.\n-/\n\n\n\n\n/- ***************************************** -/\n/- *************** negation **************** -/\n/- ***************************************** -/\n\n/-\n(15) \n\nShow that for any propositions, P and Q, \n¬ ((P ∧ Q) ∧ ((P ∧ Q) → (¬ Q ∧ P)).\n-/\n\n\n\n/-\n(16)\n\nProve that for any propositions, P and R, \nif P → R  and ¬ P → R, then R. You might \nneed to use the law of the excluded middle.\n-/\n\n\n\n\n/- ***************************************** -/\n/- ************* bi-implication ************ -/\n/- ***************************************** -/\n\n/-\n(17)\n\nProve that for any propositions P and Q, \n(P -> Q) ∧ (Q → P) → (P ↔ Q).\n-/\n\n\n\n/-\n(18)\n\nProve that for propositions P and Q,\n((P ↔ Q) ∧ P) → Q.\n-/\n\n\n\n\n/- ***************************************** -/\n/- ************** disjunction ************** -/\n/- ***************************************** -/\n\n/-\n(19)\n\nProve that if you eat donuts or if you eat\ncandy you will get cavities. The proposition\nyou prove should build in the assumptions \nthat if you eat donuts you will get cavities\nand if you eat candy you will get cavities. \nWe start the proof for you. You complete it.\nStart your proof like this:\n\nexample : ∀ donut candy cavity : Prop, ...\n-/\n\n\n\n/-\n(20)\n\nProve that if P and Q are any propositions, and\nif you have a proof of ¬(P ∨ Q) then you can\nconstruct a proof of ¬ P.\n-/\n\n\n\n/-\n(21)\n\nShow, without using em explicitly, that if\nfor any proposition, P, P ∨ ¬ P, then for any\nproposition, Q, ¬ ¬ Q → Q. The proposition to \nprove is (∀ P : Prop, P ∨ ¬ P) → (∀ Q, ¬¬ Q → Q).\nRemember that a proof of (∀ P, S) can be applied\nto a value of type P to get a value of type S.\n-/\n\n\n\n/- ***************************************** -/\n/- **************** predicates ************* -/\n/- ***************************************** -/\n\n\n/-\n(22)\n\nDefine notZero(n) to be a predicate on\nnatural numbers that is true when 0 ≠ n\n(and false otherwise). Then prove two facts \nusing \"example.\" First, ¬ (notZero 0). When\ndoing this proof, remember what (notZero 0)\nmeans, and remember what negation means.\nSecond, prove (notZero 1).\n-/\n\n\n\n/-\n(23)\n\nDefine eqString(s, t) to be a predicate on\nvalues of type string, that is true when\ns = t (and not true otherwise). Then prove: \neqString \"Hello Lean\" (\"Hello \" ++ \"Lean\")\n-/\n\n\n/- ***************************************** -/\n/- **************** exists ***************** -/\n/- ***************************************** -/\n\n/-\n(24) \n\nProve that ∃ n : ℕ, n = 13. \n-/\n\n\n\n/-\n(25)\n\nProve ∀ s : string, ∃ n, n = string.length s.\n-/\n\n\n/-\n(26)\n\nProve exists m : ℕ, exists n: ℕ, m * n = 100.\nRemember that you can apply exists.intro to a\nwitness, leaving the proof to be constructed\ninteractively.\n-/\n\n\n\n/-\n(27)\n\nProve that if P and S are properties of \nnatural numbers, and if (∃ n : ℕ, P n ∧ S n), \nthen (∃ n : ℕ, P n ∨ S 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/Exam2-Review.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7760974435129578}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Mario Carneiro\n\nTheory of topological spaces.\n\nParts of the formalization is based on the books:\n  N. Bourbaki: General Topology\n  I. M. James: Topologies and Uniformities\nA major difference is that this formalization is heavily based on the filter library.\n-/\nimport order.filter data.set.countable tactic\n\nopen set filter lattice classical\nlocal attribute [instance] prop_decidable\n\nuniverses u v w\n\nstructure topological_space (α : Type u) :=\n(is_open       : set α → Prop)\n(is_open_univ   : is_open univ)\n(is_open_inter  : ∀s t, is_open s → is_open t → is_open (s ∩ t))\n(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))\n\nattribute [class] topological_space\n\nsection topological_space\n\nvariables {α : Type u} {β : Type v} {ι : Sort w} {a a₁ a₂ : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop}\n\nlemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g\n| ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl\n\nsection\nvariables [t : topological_space α]\ninclude t\n\n/-- `is_open s` means that `s` is open in the ambient topological space on `α` -/\ndef is_open (s : set α) : Prop := topological_space.is_open t s\n\n@[simp]\nlemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t\n\nlemma is_open_inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) :=\ntopological_space.is_open_inter t s₁ s₂ h₁ h₂\n\nlemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) :=\ntopological_space.is_open_sUnion t s h\n\nend\n\nlemma is_open_fold {s : set α} {t : topological_space α} : t.is_open s = @is_open α t s :=\nrfl\n\nvariables [topological_space α]\n\nlemma is_open_union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) :=\nhave (⋃₀ {s₁, s₂}) = (s₁ ∪ s₂), by simp [union_comm],\nthis ▸ is_open_sUnion $ show ∀(t : set α), t ∈ ({s₁, s₂} : set (set α)) → is_open t,\n  by finish\n\nlemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=\nis_open_sUnion $ assume t ⟨i, (heq : t = f i)⟩, heq.symm ▸ h i\n\nlemma is_open_bUnion {s : set β} {f : β → set α} (h : ∀i∈s, is_open (f i)) :\n  is_open (⋃i∈s, f i) :=\nis_open_Union $ assume i, is_open_Union $ assume hi, h i hi\n\n@[simp] lemma is_open_empty : is_open (∅ : set α) :=\nhave is_open (⋃₀ ∅ : set α), from is_open_sUnion (assume a, false.elim),\nby simp at this; assumption\n\nlemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) :=\nfinite.induction_on hs (by simp) $ λ a s has hs ih h, begin\n  suffices : is_open (a ∩ ⋂₀ s), { simpa },\n  exact is_open_inter (h _ $ mem_insert _ _) (ih $ assume t ht, h _ $ mem_insert_of_mem _ ht)\nend\n\nlemma is_open_bInter {s : set β} {f : β → set α} (hs : finite s) :\n  (∀i∈s, is_open (f i)) → is_open (⋂i∈s, f i) :=\nfinite.induction_on hs\n  (by simp)\n  (by simp [or_imp_distrib, _root_.is_open_inter, forall_and_distrib] {contextual := tt})\n\nlemma is_open_const {p : Prop} : is_open {a : α | p} :=\nby_cases\n  (assume : p, begin simp [*]; exact is_open_univ end)\n  (assume : ¬ p, begin simp [*]; exact is_open_empty end)\n\nlemma is_open_and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} :=\nis_open_inter\n\n/-- A set is closed if its complement is open -/\ndef is_closed (s : set α) : Prop := is_open (-s)\n\n@[simp] lemma is_closed_empty : is_closed (∅ : set α) := by simp [is_closed]\n\n@[simp] lemma is_closed_univ : is_closed (univ : set α) := by simp [is_closed]\n\nlemma is_closed_union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) :=\nby simp [is_closed]; exact is_open_inter\n\nlemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) :=\nby simp [is_closed, compl_sInter]; exact assume h, is_open_Union $ assume t, is_open_Union $ assume ht, h t ht\n\nlemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) :=\nis_closed_sInter $ assume t ⟨i, (heq : t = f i)⟩, heq.symm ▸ h i\n\n@[simp] lemma is_open_compl_iff {s : set α} : is_open (-s) ↔ is_closed s := iff.rfl\n\n@[simp] lemma is_closed_compl_iff {s : set α} : is_closed (-s) ↔ is_open s :=\nby rw [←is_open_compl_iff, compl_compl]\n\nlemma is_open_diff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s \\ t) :=\nis_open_inter h₁ $ is_open_compl_iff.mpr h₂\n\nlemma is_closed_inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) :=\nby rw [is_closed, compl_inter]; exact is_open_union h₁ h₂\n\nlemma is_closed_Union {s : set β} {f : β → set α} (hs : finite s) :\n  (∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) :=\nfinite.induction_on hs\n  (by simp)\n  (by simp [or_imp_distrib, is_closed_union, forall_and_distrib] {contextual := tt})\n\nlemma is_closed_imp [topological_space α] {p q : α → Prop}\n  (hp : is_open {x | p x}) (hq : is_closed {x | q x}) : is_closed {x | p x → q x} :=\nhave {x | p x → q x} = (- {x | p x}) ∪ {x | q x}, from set.ext $ by finish,\nby rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq\n\nlemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} :=\nis_open_compl_iff.mpr\n\n/-- The interior of a set `s` is the largest open subset of `s`. -/\ndef interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s}\n\nlemma mem_interior {s : set α} {x : α} :\n  x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t :=\nby simp [interior, and_comm, and.left_comm]\n\n@[simp] lemma is_open_interior {s : set α} : is_open (interior s) :=\nis_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁\n\nlemma interior_subset {s : set α} : interior s ⊆ s :=\nsUnion_subset $ assume t ⟨h₁, h₂⟩, h₂\n\nlemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s :=\nsubset_sUnion_of_mem ⟨h₂, h₁⟩\n\nlemma interior_eq_of_open {s : set α} (h : is_open s) : interior s = s :=\nsubset.antisymm interior_subset (interior_maximal (subset.refl s) h)\n\nlemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s :=\n⟨assume h, h ▸ is_open_interior, interior_eq_of_open⟩\n\nlemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s :=\nby simp [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset]\n\nlemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) :\n  s ⊆ interior t ↔ s ⊆ t :=\n⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩\n\nlemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t :=\ninterior_maximal (subset.trans interior_subset h) is_open_interior\n\n@[simp] lemma interior_empty : interior (∅ : set α) = ∅ :=\ninterior_eq_of_open is_open_empty\n\n@[simp] lemma interior_univ : interior (univ : set α) = univ :=\ninterior_eq_of_open is_open_univ\n\n@[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s :=\ninterior_eq_of_open is_open_interior\n\n@[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t :=\nsubset.antisymm\n  (subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t))\n  (interior_maximal (inter_subset_inter interior_subset interior_subset) $ by simp [is_open_inter])\n\nlemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s) (h₂ : interior t = ∅) :\n  interior (s ∪ t) = interior s :=\nhave interior (s ∪ t) ⊆ s, from\n  assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩,\n  classical.by_contradiction $ assume hx₂ : x ∉ s,\n    have u \\ s ⊆ t,\n      from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂,\n    have u \\ s ⊆ interior t,\n      by simp [subset_interior_iff_subset_of_open, this, is_open_diff hu₁ h₁],\n    have u \\ s ⊆ ∅,\n      by rw [h₂] at this; assumption,\n    this ⟨hx₁, hx₂⟩,\nsubset.antisymm\n  (interior_maximal this is_open_interior)\n  (interior_mono $ subset_union_left _ _)\n\nlemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t :=\nby rw ← subset_interior_iff_open; simp [subset_def, mem_interior]\n\n/-- The closure of `s` is the smallest closed set containing `s`. -/\ndef closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t}\n\n@[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) :=\nis_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁\n\nlemma subset_closure {s : set α} : s ⊆ closure s :=\nsubset_sInter $ assume t ⟨h₁, h₂⟩, h₂\n\nlemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t :=\nsInter_subset_of_mem ⟨h₂, h₁⟩\n\nlemma closure_eq_of_is_closed {s : set α} (h : is_closed s) : closure s = s :=\nsubset.antisymm (closure_minimal (subset.refl s) h) subset_closure\n\nlemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s :=\n⟨assume h, h ▸ is_closed_closure, closure_eq_of_is_closed⟩\n\nlemma closure_subset_iff_subset_of_is_closed {s t : set α} (h₁ : is_closed t) :\n  closure s ⊆ t ↔ s ⊆ t :=\n⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩\n\nlemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t :=\nclosure_minimal (subset.trans h subset_closure) is_closed_closure\n\n@[simp] lemma closure_empty : closure (∅ : set α) = ∅ :=\nclosure_eq_of_is_closed is_closed_empty\n\nlemma closure_empty_iff (s : set α) : closure s = ∅ ↔ s = ∅ :=\nbegin\n  split ; intro h,\n  { rw set.eq_empty_iff_forall_not_mem,\n    intros x H,\n    simpa [h] using subset_closure H },\n  { exact (eq.symm h) ▸ closure_empty },\nend\n\n@[simp] lemma closure_univ : closure (univ : set α) = univ :=\nclosure_eq_of_is_closed is_closed_univ\n\n@[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s :=\nclosure_eq_of_is_closed is_closed_closure\n\n@[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t :=\nsubset.antisymm\n  (closure_minimal (union_subset_union subset_closure subset_closure) $ by simp [is_closed_union])\n  (union_subset (closure_mono $ subset_union_left _ _) (closure_mono $ subset_union_right _ _))\n\nlemma interior_subset_closure {s : set α} : interior s ⊆ closure s :=\nsubset.trans interior_subset subset_closure\n\nlemma closure_eq_compl_interior_compl {s : set α} : closure s = - interior (- s) :=\nbegin\n  simp [interior, closure],\n  rw [compl_sUnion, compl_image_set_of],\n  simp [compl_subset_compl]\nend\n\n@[simp] lemma interior_compl_eq {s : set α} : interior (- s) = - closure s :=\nby simp [closure_eq_compl_interior_compl]\n\n@[simp] lemma closure_compl_eq {s : set α} : closure (- s) = - interior s :=\nby simp [closure_eq_compl_interior_compl]\n\nlemma closure_compl {s : set α} : closure (-s) = - interior s :=\nsubset.antisymm\n  (by simp [closure_subset_iff_subset_of_is_closed, compl_subset_compl, subset.refl])\n  begin\n    rw [compl_subset_comm, subset_interior_iff_subset_of_open, compl_subset_comm],\n    exact subset_closure,\n    exact is_open_compl_iff.mpr is_closed_closure\n  end\n\nlemma interior_compl {s : set α} : interior (-s) = - closure s :=\ncalc interior (- s) = - - interior (- s) : by simp\n  ... = - closure (- (- s)) : by rw [closure_compl]\n  ... = - closure s : by simp\n\ntheorem mem_closure_iff {s : set α} {a : α} : a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → o ∩ s ≠ ∅ :=\n⟨λ h o oo ao os,\n  have s ⊆ -o, from λ x xs xo, @ne_empty_of_mem α (o∩s) x ⟨xo, xs⟩ os,\n  closure_minimal this (is_closed_compl_iff.2 oo) h ao,\nλ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc,\n  let ⟨x, hc, hs⟩ := exists_mem_of_ne_empty (H _ h₁ nc) in hc (h₂ hs)⟩\n\nlemma dense_iff_inter_open {s : set α} : closure s = univ ↔ ∀ U, is_open U → U ≠ ∅ → U ∩ s ≠ ∅ :=\nbegin\n  split ; intro h,\n  { intros U U_op U_ne,\n    cases exists_mem_of_ne_empty U_ne with x x_in,\n    exact  mem_closure_iff.1 (by simp[h]) U U_op x_in },\n  { ext x,\n    suffices : x ∈ closure s, by simp [this],\n    rw mem_closure_iff,\n    intros U U_op x_in,\n    exact h U U_op (ne_empty_of_mem x_in) },\nend\n\n/-- The frontier of a set is the set of points between the closure and interior. -/\ndef frontier (s : set α) : set α := closure s \\ interior s\n\nlemma frontier_eq_closure_inter_closure {s : set α} :\n  frontier s = closure s ∩ closure (- s) :=\nby rw [closure_compl, frontier, diff_eq]\n\n@[simp] lemma frontier_compl (s : set α) : frontier (-s) = frontier s :=\nby simp [frontier_eq_closure_inter_closure, inter_comm]\n\n/-- neighbourhood filter -/\ndef nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s)\n\nlemma tendsto_nhds {m : β → α} {f : filter β} (h : ∀s, a ∈ s → is_open s → m ⁻¹' s ∈ f.sets) :\n  tendsto m f (nhds a) :=\nshow map m f ≤ (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s),\n  from le_infi $ assume s, le_infi $ assume ⟨ha, hs⟩, le_principal_iff.mpr $ h s ha hs\n\nlemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (nhds a) :=\ntendsto_nhds $ assume s ha hs, univ_mem_sets' $ assume _, ha\n\nlemma nhds_sets {a : α} : (nhds a).sets = {s | ∃t⊆s, is_open t ∧ a ∈ t} :=\ncalc (nhds a).sets = (⋃s∈{s : set α| a ∈ s ∧ is_open s}, (principal s).sets) : infi_sets_eq'\n  (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,\n    ⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, by simp [ge]⟩)\n  ⟨univ, by simp⟩\n  ... = {s | ∃t⊆s, is_open t ∧ a ∈ t} :\n    le_antisymm\n      (supr_le $ assume i, supr_le $ assume ⟨hi₁, hi₂⟩ t ht, ⟨i, ht, hi₂, hi₁⟩)\n      (assume t ⟨i, hi₁, hi₂, hi₃⟩, by simp; exact ⟨i, ⟨hi₃, hi₂⟩, hi₁⟩)\n\nlemma map_nhds {a : α} {f : α → β} :\n  map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal (image f s)) :=\ncalc map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, map f (principal s)) :\n    map_binfi_eq\n    (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,\n      ⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, by simp [ge]⟩)\n    ⟨univ, by simp⟩\n  ... = _ : by simp\n\nlemma mem_nhds_sets_iff {a : α} {s : set α} :\n s ∈ (nhds a).sets ↔ ∃t⊆s, is_open t ∧ a ∈ t :=\nby simp [nhds_sets]\n\nlemma mem_of_nhds {a : α} {s : set α} : s ∈ (nhds a).sets → a ∈ s :=\nby simp [mem_nhds_sets_iff]; exact assume t ht _ hs, ht hs\n\nlemma mem_nhds_sets {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :\n s ∈ (nhds a).sets :=\nby simp [nhds_sets]; exact ⟨s, subset.refl _, hs, ha⟩\n\nlemma pure_le_nhds : pure ≤ (nhds : α → filter α) :=\nassume a, le_infi $ assume s, le_infi $ assume ⟨h₁, _⟩, principal_mono.mpr $ by simp [h₁]\n\n@[simp] lemma nhds_neq_bot {a : α} : nhds a ≠ ⊥ :=\nassume : nhds a = ⊥,\nhave pure a = (⊥ : filter α),\n  from lattice.bot_unique $ this ▸ pure_le_nhds a,\npure_neq_bot this\n\nlemma interior_eq_nhds {s : set α} : interior s = {a | nhds a ≤ principal s} :=\nset.ext $ by simp [mem_interior, nhds_sets]\n\nlemma mem_interior_iff_mem_nhds {s : set α} {a : α} :\n  a ∈ interior s ↔ s ∈ (nhds a).sets :=\nby simp [interior_eq_nhds]\n\nlemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, nhds a ≤ principal s :=\ncalc is_open s ↔ interior s = s : by rw [interior_eq_iff_open]\n  ... ↔ s ⊆ interior s : ⟨assume h, by simp [*, subset.refl], subset.antisymm interior_subset⟩\n  ... ↔ (∀a∈s, nhds a ≤ principal s) : by rw [interior_eq_nhds]; refl\n\nlemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ (nhds a).sets :=\nby simpa using @is_open_iff_nhds α _ _\n\nlemma closure_eq_nhds {s : set α} : closure s = {a | nhds a ⊓ principal s ≠ ⊥} :=\ncalc closure s = - interior (- s) : closure_eq_compl_interior_compl\n  ... = {a | ¬ nhds a ≤ principal (-s)} : by rw [interior_eq_nhds]; refl\n  ... = {a | nhds a ⊓ principal s ≠ ⊥} : set.ext $ assume a, not_congr\n    (inf_eq_bot_iff_le_compl\n      (show principal s ⊔ principal (-s) = ⊤, by simp [principal_univ])\n      (by simp)).symm\n\ntheorem mem_closure_iff_nhds {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ (nhds a).sets, t ∩ s ≠ ∅ :=\nmem_closure_iff.trans\n⟨λ H t ht, subset_ne_empty\n  (inter_subset_inter_left _ interior_subset)\n  (H _ is_open_interior (mem_interior_iff_mem_nhds.2 ht)),\n λ H o oo ao, H _ (mem_nhds_sets oo ao)⟩\n\nlemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s :=\ncalc is_closed s ↔ closure s = s : by rw [closure_eq_iff_is_closed]\n  ... ↔ closure s ⊆ s : ⟨assume h, by simp [*, subset.refl], assume h, subset.antisymm h subset_closure⟩\n  ... ↔ (∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s) : by rw [closure_eq_nhds]; refl\n\nlemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) :=\nassume a ⟨hs, ht⟩,\nhave s ∈ (nhds a).sets, from mem_nhds_sets h hs,\nhave nhds a ⊓ principal s = nhds a, from inf_of_le_left $ by simp [this],\nhave nhds a ⊓ principal (s ∩ t) ≠ ⊥,\n  from calc nhds a ⊓ principal (s ∩ t) = nhds a ⊓ (principal s ⊓ principal t) : by simp\n    ... = nhds a ⊓ principal t : by rw [←inf_assoc, this]\n    ... ≠ ⊥ : by rw [closure_eq_nhds] at ht; assumption,\nby rw [closure_eq_nhds]; assumption\n\nlemma closure_diff {s t : set α} : closure s - closure t ⊆ closure (s - t) :=\ncalc closure s \\ closure t = (- closure t) ∩ closure s : by simp [diff_eq, inter_comm]\n  ... ⊆ closure (- closure t ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure\n  ... = closure (s \\ closure t) : by simp [diff_eq, inter_comm]\n  ... ⊆ closure (s \\ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure\n\nlemma mem_of_closed_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}\n  (hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (hs : is_closed s) (h : f ⁻¹' s ∈ b.sets) : a ∈ s :=\nhave b.map f ≤ nhds a ⊓ principal s,\n  from le_trans (le_inf (le_refl _) (le_principal_iff.mpr h)) (inf_le_inf hf (le_refl _)),\nis_closed_iff_nhds.mp hs a $ neq_bot_of_le_neq_bot (map_ne_bot hb) this\n\nlemma mem_closure_of_tendsto {f : β → α} {x : filter β} {a : α} {s : set α}\n  (hf : tendsto f x (nhds a)) (hs : is_closed s) (h : x ⊓ principal (f ⁻¹' s) ≠ ⊥) : a ∈ s :=\nis_closed_iff_nhds.mp hs _ $ neq_bot_of_le_neq_bot (@map_ne_bot _ _ _ f h) $\n  le_inf (le_trans (map_mono $ inf_le_left) hf) $\n    le_trans (map_mono $ inf_le_right_of_le $ by simp; exact subset.refl _) (@map_comap_le _ _ _ f)\n\n/- locally finite family [General Topology (Bourbaki, 1995)] -/\nsection locally_finite\n\n/-- A family of sets in `set α` is locally finite if at every point `x:α`,\n  there is a neighborhood of `x` which meets only finitely many sets in the family -/\ndef locally_finite (f : β → set α) :=\n∀x:α, ∃t∈(nhds x).sets, finite {i | f i ∩ t ≠ ∅ }\n\nlemma locally_finite_of_finite {f : β → set α} (h : finite (univ : set β)) : locally_finite f :=\nassume x, ⟨univ, univ_mem_sets, finite_subset h $ by simp⟩\n\nlemma locally_finite_subset\n  {f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ :=\nassume a,\nlet ⟨t, ht₁, ht₂⟩ := hf₂ a in\n⟨t, ht₁, finite_subset ht₂ $ assume i hi,\n  neq_bot_of_le_neq_bot hi $ inter_subset_inter (hf i) $ subset.refl _⟩\n\nlemma is_closed_Union_of_locally_finite {f : β → set α}\n  (h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) :=\nis_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i),\n  have ∀i, a ∈ -f i,\n    from assume i hi, by simp at h; exact h i hi,\n  have ∀i, - f i ∈ (nhds a).sets,\n    by rw [nhds_sets]; exact assume i, ⟨- f i, subset.refl _, h₂ i, this i⟩,\n  let ⟨t, h_sets, (h_fin : finite {i | f i ∩ t ≠ ∅ })⟩ := h₁ a in\n\n  calc nhds a ≤ principal (t ∩ (⋂ i∈{i | f i ∩ t ≠ ∅ }, - f i)) :\n  begin\n    rw [le_principal_iff],\n    apply @filter.inter_mem_sets _ (nhds a) _ _ h_sets,\n    apply @filter.Inter_mem_sets _ (nhds a) _ _ _ h_fin,\n    exact assume i h, this i\n  end\n  ... ≤ principal (- ⋃i, f i) :\n  begin\n    simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq,\n      mem_Inter, mem_set_of_eq, mem_Union, and_imp, not_exists,\n      not_eq_empty_iff_exists, exists_imp_distrib, (≠)],\n    exact assume x xt ht i xfi, ht i x xfi xt xfi\n  end\n\nend locally_finite\n\n/- compact sets -/\nsection compact\n\n/-- A set `s` is compact if for every filter `f` that contains `s`,\n    every set of `f` also meets every neighborhood of some `a ∈ s`. -/\ndef compact (s : set α) := ∀f, f ≠ ⊥ → f ≤ principal s → ∃a∈s, f ⊓ nhds a ≠ ⊥\n\nlemma compact_inter {s t : set α} (hs : compact s) (ht : is_closed t) : compact (s ∩ t) :=\nassume f hnf hstf,\nlet ⟨a, hsa, (ha : f ⊓ nhds a ≠ ⊥)⟩ := hs f hnf (le_trans hstf (by simp)) in\nhave ∀a, principal t ⊓ nhds a ≠ ⊥ → a ∈ t,\n  by intro a; rw [inf_comm]; rw [is_closed_iff_nhds] at ht; exact ht a,\nhave a ∈ t,\n  from this a $ neq_bot_of_le_neq_bot ha $ inf_le_inf (le_trans hstf (by simp)) (le_refl _),\n⟨a, ⟨hsa, this⟩, ha⟩\n\nlemma compact_diff {s t : set α} (hs : compact s) (ht : is_open t) : compact (s \\ t) :=\ncompact_inter hs (is_closed_compl_iff.mpr ht)\n\nlemma compact_of_is_closed_subset {s t : set α}\n  (hs : compact s) (ht : is_closed t) (h : t ⊆ s) : compact t :=\nby convert ← compact_inter hs ht; exact inter_eq_self_of_subset_right h\n\nlemma compact_adherence_nhdset {s t : set α} {f : filter α}\n  (hs : compact s) (hf₂ : f ≤ principal s) (ht₁ : is_open t) (ht₂ : ∀a∈s, nhds a ⊓ f ≠ ⊥ → a ∈ t) :\n  t ∈ f.sets :=\nclassical.by_cases mem_sets_of_neq_bot $\n  assume : f ⊓ principal (- t) ≠ ⊥,\n  let ⟨a, ha, (hfa : f ⊓ principal (-t) ⊓ nhds a ≠ ⊥)⟩ := hs _ this $ inf_le_left_of_le hf₂ in\n  have a ∈ t,\n    from ht₂ a ha $ neq_bot_of_le_neq_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_left,\n  have nhds a ⊓ principal (-t) ≠ ⊥,\n    from neq_bot_of_le_neq_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_right,\n  have ∀s∈(nhds a ⊓ principal (-t)).sets, s ≠ ∅,\n    from forall_sets_neq_empty_iff_neq_bot.mpr this,\n  have false,\n    from this _ ⟨t, mem_nhds_sets ht₁ ‹a ∈ t›, -t, subset.refl _, subset.refl _⟩ (by simp),\n  by contradiction\n\nlemma compact_iff_ultrafilter_le_nhds {s : set α} :\n  compact s ↔ (∀f, ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ nhds a) :=\n⟨assume hs : compact s, assume f hf hfs,\n  let ⟨a, ha, h⟩ := hs _ hf.left hfs in\n  ⟨a, ha, le_of_ultrafilter hf h⟩,\n\n  assume hs : (∀f, ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ nhds a),\n  assume f hf hfs,\n  let ⟨a, ha, (h : ultrafilter_of f ≤ nhds a)⟩ :=\n    hs (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs) in\n  have ultrafilter_of f ⊓ nhds a ≠ ⊥,\n    by simp [inf_of_le_left, h]; exact (ultrafilter_ultrafilter_of hf).left,\n  ⟨a, ha, neq_bot_of_le_neq_bot this (inf_le_inf ultrafilter_of_le (le_refl _))⟩⟩\n\nlemma compact_elim_finite_subcover {s : set α} {c : set (set α)}\n  (hs : compact s) (hc₁ : ∀t∈c, is_open t) (hc₂ : s ⊆ ⋃₀ c) : ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c' :=\nclassical.by_contradiction $ assume h,\n  have h : ∀{c'}, c' ⊆ c → finite c' → ¬ s ⊆ ⋃₀ c',\n    from assume c' h₁ h₂ h₃, h ⟨c', h₁, h₂, h₃⟩,\n  let\n    f : filter α := (⨅c':{c' : set (set α) // c' ⊆ c ∧ finite c'}, principal (s - ⋃₀ c')),\n    ⟨a, ha⟩ := @exists_mem_of_ne_empty α s\n      (assume h', h (empty_subset _) finite_empty $ h'.symm ▸ empty_subset _)\n  in\n  have f ≠ ⊥, from infi_neq_bot_of_directed ⟨a⟩\n    (assume ⟨c₁, hc₁, hc'₁⟩ ⟨c₂, hc₂, hc'₂⟩, ⟨⟨c₁ ∪ c₂, union_subset hc₁ hc₂, finite_union hc'₁ hc'₂⟩,\n      principal_mono.mpr $ diff_subset_diff_right $ sUnion_mono $ subset_union_left _ _,\n      principal_mono.mpr $ diff_subset_diff_right $ sUnion_mono $ subset_union_right _ _⟩)\n    (assume ⟨c', hc'₁, hc'₂⟩, show principal (s \\ _) ≠ ⊥, by simp [diff_eq_empty]; exact h hc'₁ hc'₂),\n  have f ≤ principal s, from infi_le_of_le ⟨∅, empty_subset _, finite_empty⟩ $\n    show principal (s \\ ⋃₀∅) ≤ principal s, by simp; exact subset.refl s,\n  let\n    ⟨a, ha, (h : f ⊓ nhds a ≠ ⊥)⟩ := hs f ‹f ≠ ⊥› this,\n    ⟨t, ht₁, (ht₂ : a ∈ t)⟩ := hc₂ ha\n  in\n  have f ≤ principal (-t),\n    from infi_le_of_le ⟨{t}, by simp [ht₁], finite_insert _ finite_empty⟩ $\n      principal_mono.mpr $\n        show s - ⋃₀{t} ⊆ - t, begin simp; exact assume x ⟨_, hnt⟩, hnt end,\n  have is_closed (- t), from is_open_compl_iff.mp $ by simp; exact hc₁ t ht₁,\n  have a ∈ - t, from is_closed_iff_nhds.mp this _ $ neq_bot_of_le_neq_bot h $\n    le_inf inf_le_right (inf_le_left_of_le ‹f ≤ principal (- t)›),\n  this ‹a ∈ t›\n\nlemma compact_elim_finite_subcover_image {s : set α} {b : set β} {c : β → set α}\n  (hs : compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) :\n  ∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i :=\nif h : b = ∅ then ⟨∅, by simp, by simp, h ▸ hc₂⟩ else\nlet ⟨i, hi⟩ := exists_mem_of_ne_empty h in\nhave hc'₁ : ∀i∈c '' b, is_open i, from assume i ⟨j, hj, h⟩, h ▸ hc₁ _ hj,\nhave hc'₂ : s ⊆ ⋃₀ (c '' b), by simpa,\nlet ⟨d, hd₁, hd₂, hd₃⟩ := compact_elim_finite_subcover hs hc'₁ hc'₂ in\nhave ∀x : d, ∃i, i ∈ b ∧ c i = x, from assume ⟨x, hx⟩, hd₁ hx,\nlet ⟨f', hf⟩ := axiom_of_choice this,\n    f := λx:set α, (if h : x ∈ d then f' ⟨x, h⟩ else i : β) in\nhave ∀(x : α) (i : set α), i ∈ d → x ∈ i → (∃ (i : β), i ∈ f '' d ∧ x ∈ c i),\n  from assume x i hid hxi, ⟨f i, mem_image_of_mem f hid,\n    by simpa [f, hid, (hf ⟨_, hid⟩).2] using hxi⟩,\n⟨f '' d,\n  assume i ⟨j, hj, h⟩,\n  h ▸ by simpa [f, hj] using (hf ⟨_, hj⟩).1,\n  finite_image f hd₂,\n  subset.trans hd₃ $ by simpa [subset_def]⟩\n\nlemma compact_of_finite_subcover {s : set α}\n  (h : ∀c, (∀t∈c, is_open t) → s ⊆ ⋃₀ c → ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c') : compact s :=\nassume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, f ⊓ nhds x ≠ ⊥),\n  have hf : ∀x∈s, nhds x ⊓ f = ⊥,\n    by simpa [not_and, inf_comm],\n  have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,\n    from assume ⟨x, hxs, hx⟩,\n    have ∅ ∈ (nhds x ⊓ f).sets, by rw [empty_in_sets_eq_bot, hf x hxs],\n    let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_sets] at this; exact this in\n    have ∅ ∈ (nhds x ⊓ principal t₂).sets,\n      from (nhds x ⊓ principal t₂).sets_of_superset (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,\n    have nhds x ⊓ principal t₂ = ⊥,\n      by rwa [empty_in_sets_eq_bot] at this,\n    by simp [closure_eq_nhds] at hx; exact hx t₂ ht₂ this,\n  have ∀x∈s, ∃t∈f.sets, x ∉ closure t, by simpa [_root_.not_forall],\n  let c := (λt, - closure t) '' f.sets, ⟨c', hcc', hcf, hsc'⟩ := h c\n    (assume t ⟨s, hs, h⟩, h ▸ is_closed_closure) (by simpa [subset_def]) in\n  let ⟨b, hb⟩ := axiom_of_choice $\n    show ∀s:c', ∃t, t ∈ f.sets ∧ - closure t = s,\n      from assume ⟨x, hx⟩, hcc' hx in\n  have (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f.sets,\n    from Inter_mem_sets hcf $ assume t ht, by rw [dif_pos ht]; exact (hb ⟨t, ht⟩).left,\n  have s ∩ (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f.sets,\n    from inter_mem_sets (by simp at hfs; assumption) this,\n  have ∅ ∈ f.sets,\n    from mem_sets_of_superset this $ assume x ⟨hxs, hxi⟩,\n    let ⟨t, htc', hxt⟩ := (show ∃t ∈ c', x ∈ t, by simpa using hsc' hxs) in\n    have -closure (b ⟨t, htc'⟩) = t, from (hb _).right,\n    have x ∈ - t,\n      from this ▸ (calc x ∈ b ⟨t, htc'⟩ : by simp at hxi; have h := hxi t htc'; rwa [dif_pos htc'] at h\n        ... ⊆ closure (b ⟨t, htc'⟩) : subset_closure\n        ... ⊆ - - closure (b ⟨t, htc'⟩) : by simp; exact subset.refl _),\n    show false, from this hxt,\n  hfn $ by rwa [empty_in_sets_eq_bot] at this\n\nlemma compact_iff_finite_subcover {s : set α} :\n  compact s ↔ (∀c, (∀t∈c, is_open t) → s ⊆ ⋃₀ c → ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c') :=\n⟨assume hc c, compact_elim_finite_subcover hc, compact_of_finite_subcover⟩\n\nlemma compact_empty : compact (∅ : set α) :=\nassume f hnf hsf, not.elim hnf $\nby simpa [empty_in_sets_eq_bot] using hsf\n\nlemma compact_singleton {a : α} : compact ({a} : set α) :=\ncompact_of_finite_subcover $ assume c hc₁ hc₂,\n  let ⟨i, hic, hai⟩ := (show ∃i ∈ c, a ∈ i, by simpa using hc₂) in\n  ⟨{i}, by simp [hic], finite_singleton _, by simp [hai]⟩\n\nlemma compact_bUnion_of_compact {s : set β} {f : β → set α} (hs : finite s) :\n  (∀i ∈ s, compact (f i)) → compact (⋃i ∈ s, f i) :=\nassume hf, compact_of_finite_subcover $ assume c c_open c_cover,\n  have ∀i : subtype s, ∃c' ⊆ c, finite c' ∧ f i ⊆ ⋃₀ c', from\n    assume ⟨i, hi⟩, compact_elim_finite_subcover (hf i hi) c_open\n      (calc f i ⊆ ⋃i ∈ s, f i : subset_bUnion_of_mem hi\n            ... ⊆ ⋃₀ c        : c_cover),\n  let ⟨finite_subcovers, h⟩ := axiom_of_choice this in\n  let c' := ⋃i, finite_subcovers i in\n  have c' ⊆ c, from Union_subset (λi, (h i).fst),\n  have finite c', from @finite_Union _ _ hs.fintype _ (λi, (h i).snd.1),\n  have (⋃i ∈ s, f i) ⊆ ⋃₀ c', from bUnion_subset $ λi hi, calc\n    f i ⊆ ⋃₀ finite_subcovers ⟨i,hi⟩ : (h ⟨i,hi⟩).snd.2\n    ... ⊆ ⋃₀ c'                      : sUnion_mono (subset_Union _ _),\n  ⟨c', ‹c' ⊆ c›, ‹finite c'›, this⟩\n\nlemma compact_of_finite {s : set α} (hs : finite s) : compact s :=\nlet s' : set α := ⋃i ∈ s, {i} in\nhave e : s' = s, from ext $ λi, by simp,\nhave compact s', from compact_bUnion_of_compact hs (λ_ _, compact_singleton),\ne ▸ this\n\nend compact\n\n/- separation axioms -/\n\nsection separation\n\n/-- A T₁ space, also known as a Fréchet space, is a topological space\n  where for every pair `x ≠ y`, there is an open set containing `x` and not `y`.\n  Equivalently, every singleton set is closed. -/\nclass t1_space (α : Type u) [topological_space α] :=\n(t1 : ∀x, is_closed ({x} : set α))\n\nlemma is_closed_singleton [t1_space α] {x : α} : is_closed ({x} : set α) :=\nt1_space.t1 x\n\nlemma compl_singleton_mem_nhds [t1_space α] {x y : α} (h : y ≠ x) : - {x} ∈ (nhds y).sets :=\nmem_nhds_sets is_closed_singleton $ by simp; exact h\n\n@[simp] lemma closure_singleton [topological_space α] [t1_space α] {a : α} :\n  closure ({a} : set α) = {a} :=\nclosure_eq_of_is_closed is_closed_singleton\n\n/-- A T₂ space, also known as a Hausdorff space, is one in which for every\n  `x ≠ y` there exists disjoint open sets around `x` and `y`. This is\n  the most widely used of the separation axioms. -/\nclass t2_space (α : Type u) [topological_space α] :=\n(t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅)\n\nlemma t2_separation [t2_space α] {x y : α} (h : x ≠ y) :\n  ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=\nt2_space.t2 x y h\n\ninstance t2_space.t1_space [topological_space α] [t2_space α] : t1_space α :=\n⟨assume x,\n  have ∀y, y ≠ x ↔ ∃ (i : set α), (x ∉ i ∧ is_open i) ∧ y ∈ i,\n    from assume y, ⟨assume h',\n      let ⟨u, v, hu, hv, hy, hx, h⟩ := t2_separation h' in\n      have x ∉ u,\n        from assume : x ∈ u,\n        have x ∈ u ∩ v, from ⟨this, hx⟩,\n        by rwa [h] at this,\n      ⟨u, ⟨this, hu⟩, hy⟩,\n      assume ⟨s, ⟨hx, hs⟩, hy⟩ h, hx $ h ▸ hy⟩,\n  have (-{x} : set α) = (⋃s∈{s : set α | x ∉ s ∧ is_open s}, s),\n    by apply set.ext; simpa,\n  show is_open (- {x}),\n    by rw [this]; exact (is_open_Union $ assume s, is_open_Union $ assume ⟨_, hs⟩, hs)⟩\n\nlemma eq_of_nhds_neq_bot [ht : t2_space α] {x y : α} (h : nhds x ⊓ nhds y ≠ ⊥) : x = y :=\nclassical.by_contradiction $ assume : x ≠ y,\nlet ⟨u, v, hu, hv, hx, hy, huv⟩ := t2_space.t2 x y this in\nhave u ∩ v ∈ (nhds x ⊓ nhds y).sets,\n  from inter_mem_inf_sets (mem_nhds_sets hu hx) (mem_nhds_sets hv hy),\nh $ empty_in_sets_eq_bot.mp $ huv ▸ this\n\n@[simp] lemma nhds_eq_nhds_iff {a b : α} [t2_space α] : nhds a = nhds b ↔ a = b :=\n⟨assume h, eq_of_nhds_neq_bot $ by simp [h], assume h, h ▸ rfl⟩\n\n@[simp] lemma nhds_le_nhds_iff {a b : α} [t2_space α] : nhds a ≤ nhds b ↔ a = b :=\n⟨assume h, eq_of_nhds_neq_bot $ by simp [inf_of_le_left h], assume h, h ▸ le_refl _⟩\n\nlemma tendsto_nhds_unique [t2_space α] {f : β → α} {l : filter β} {a b : α}\n  (hl : l ≠ ⊥) (ha : tendsto f l (nhds a)) (hb : tendsto f l (nhds b)) : a = b :=\neq_of_nhds_neq_bot $ neq_bot_of_le_neq_bot (map_ne_bot hl) $ le_inf ha hb\n\nend separation\n\nsection regularity\n\n/-- A T₃ space, also known as a regular space (although this condition sometimes\n  omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist\n  disjoint open sets containing `x` and `C` respectively. -/\nclass regular_space (α : Type u) [topological_space α] extends t2_space α :=\n(regular : ∀{s:set α} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ nhds a ⊓ principal t = ⊥)\n\nlemma nhds_is_closed [regular_space α] {a : α} {s : set α} (h : s ∈ (nhds a).sets) :\n  ∃t∈(nhds a).sets, t ⊆ s ∧ is_closed t :=\nlet ⟨s', h₁, h₂, h₃⟩ := mem_nhds_sets_iff.mp h in\nhave ∃t, is_open t ∧ -s' ⊆ t ∧ nhds a ⊓ principal t = ⊥,\n  from regular_space.regular (is_closed_compl_iff.mpr h₂) (not_not_intro h₃),\nlet ⟨t, ht₁, ht₂, ht₃⟩ := this in\n⟨-t,\n  mem_sets_of_neq_bot $ by simp; exact ht₃,\n  subset.trans (compl_subset_comm.1 ht₂) h₁,\n  is_closed_compl_iff.mpr ht₁⟩\n\nend regularity\n\n/- generating sets -/\n\nend topological_space\n\nnamespace topological_space\nvariables {α : Type u}\n\n/-- The least topology containing a collection of basic sets. -/\ninductive generate_open (g : set (set α)) : set α → Prop\n| basic  : ∀s∈g, generate_open s\n| univ   : generate_open univ\n| inter  : ∀s t, generate_open s → generate_open t → generate_open (s ∩ t)\n| sUnion : ∀k, (∀s∈k, generate_open s) → generate_open (⋃₀ k)\n\n/-- The smallest topological space containing the collection `g` of basic sets -/\ndef generate_from (g : set (set α)) : topological_space α :=\n{ is_open        := generate_open g,\n  is_open_univ   := generate_open.univ g,\n  is_open_inter  := generate_open.inter,\n  is_open_sUnion := generate_open.sUnion  }\n\nlemma nhds_generate_from {g : set (set α)} {a : α} :\n  @nhds α (generate_from g) a = (⨅s∈{s | a ∈ s ∧ s ∈ g}, principal s) :=\nle_antisymm\n  (infi_le_infi $ assume s, infi_le_infi_const $ assume ⟨as, sg⟩, ⟨as, generate_open.basic _ sg⟩)\n  (le_infi $ assume s, le_infi $ assume ⟨as, hs⟩,\n    have ∀s, generate_open g s → a ∈ s → (⨅s∈{s | a ∈ s ∧ s ∈ g}, principal s) ≤ principal s,\n    begin\n      intros s hs,\n      induction hs,\n      case generate_open.basic : s hs\n      { exact assume as, infi_le_of_le s $ infi_le _ ⟨as, hs⟩ },\n      case generate_open.univ\n      { rw [principal_univ],\n        exact assume _, le_top },\n      case generate_open.inter : s t hs' ht' hs ht\n      { exact assume ⟨has, hat⟩, calc _ ≤ principal s ⊓ principal t : le_inf (hs has) (ht hat)\n          ... = _ : by simp },\n      case generate_open.sUnion : k hk' hk\n      { exact λ ⟨t, htk, hat⟩, calc _ ≤ principal t : hk t htk hat\n          ... ≤ _ : begin simp; exact subset_sUnion_of_mem htk end }\n    end,\n    this s hs as)\n\nlemma tendsto_nhds_generate_from {β : Type*} {m : α → β} {f : filter α} {g : set (set β)} {b : β}\n  (h : ∀s∈g, b ∈ s → m ⁻¹' s ∈ f.sets) : tendsto m f (@nhds β (generate_from g) b) :=\nby rw [nhds_generate_from]; exact\n  (tendsto_infi.2 $ assume s, tendsto_infi.2 $ assume ⟨hbs, hsg⟩, tendsto_principal.2 $ h s hsg hbs)\n\nprotected def mk_of_nhds (n : α → filter α) : topological_space α :=\n{ is_open        := λs, ∀a∈s, s ∈ (n a).sets,\n  is_open_univ   := assume x h, univ_mem_sets,\n  is_open_inter  := assume s t hs ht x ⟨hxs, hxt⟩, inter_mem_sets (hs x hxs) (ht x hxt),\n  is_open_sUnion := assume s hs a ⟨x, hx, hxa⟩, mem_sets_of_superset (hs x hx _ hxa) (set.subset_sUnion_of_mem hx) }\n\nlemma nhds_mk_of_nhds (n : α → filter α) (a : α)\n  (h₀ : pure ≤ n) (h₁ : ∀{a s}, s ∈ (n a).sets → ∃t∈(n a).sets, t ⊆ s ∧ ∀a'∈t, t ∈ (n a').sets) :\n  @nhds α (topological_space.mk_of_nhds n) a = n a :=\nby letI := topological_space.mk_of_nhds n; from\n(le_antisymm\n  (assume s hs, let ⟨t, ht, hst, h⟩ := h₁ hs in\n    have t ∈ (nhds a).sets, from mem_nhds_sets h (mem_pure_sets.1 $ h₀ a ht),\n    (nhds a).sets_of_superset this hst)\n  (assume s hs,\n    let ⟨t, hts, ht, hat⟩ := (@mem_nhds_sets_iff α (topological_space.mk_of_nhds n) _ _).1 hs in\n    (n a).sets_of_superset (ht _ hat) hts))\n\nend topological_space\n\nsection lattice\n\nvariables {α : Type u} {β : Type v}\n\ninstance : partial_order (topological_space α) :=\n{ le          := λt s, t.is_open ≤ s.is_open,\n  le_antisymm := assume t s h₁ h₂, topological_space_eq $ le_antisymm h₁ h₂,\n  le_refl     := assume t, le_refl t.is_open,\n  le_trans    := assume a b c h₁ h₂, @le_trans _ _ a.is_open b.is_open c.is_open h₁ h₂ }\n\nlemma generate_from_le_iff_subset_is_open {g : set (set α)} {t : topological_space α} :\n  topological_space.generate_from g ≤ t ↔ g ⊆ {s | t.is_open s} :=\niff.intro\n  (assume ht s hs, ht _ $ topological_space.generate_open.basic s hs)\n  (assume hg s hs, hs.rec_on (assume v hv, hg hv)\n    t.is_open_univ (assume u v _ _, t.is_open_inter u v) (assume k _, t.is_open_sUnion k))\n\nprotected def mk_of_closure (s : set (set α))\n  (hs : {u | (topological_space.generate_from s).is_open u} = s) : topological_space α :=\n{ is_open        := λu, u ∈ s,\n  is_open_univ   := hs ▸ topological_space.generate_open.univ _,\n  is_open_inter  := hs ▸ topological_space.generate_open.inter,\n  is_open_sUnion := hs ▸ topological_space.generate_open.sUnion }\n\nlemma mk_of_closure_sets {s : set (set α)}\n  {hs : {u | (topological_space.generate_from s).is_open u} = s} :\n  mk_of_closure s hs = topological_space.generate_from s :=\ntopological_space_eq hs.symm\n\ndef gi_generate_from (α : Type*) :\n  galois_insertion topological_space.generate_from (λt:topological_space α, {s | t.is_open s}) :=\n{ gc        := assume g t, generate_from_le_iff_subset_is_open,\n  le_l_u    := assume ts s hs, topological_space.generate_open.basic s hs,\n  choice    := λg hg, mk_of_closure g\n    (subset.antisymm hg $ generate_from_le_iff_subset_is_open.1 $ le_refl _),\n  choice_eq := assume s hs, mk_of_closure_sets }\n\nlemma generate_from_mono {α} {g₁ g₂ : set (set α)} (h : g₁ ⊆ g₂) :\n  topological_space.generate_from g₁ ≤ topological_space.generate_from g₂ :=\n(gi_generate_from _).gc.monotone_l h\n\ninstance {α : Type u} : complete_lattice (topological_space α) :=\n(gi_generate_from α).lift_complete_lattice\n\n@[simp] lemma is_open_top {s : set α} : @is_open α ⊤ s := trivial\n\nlemma le_of_nhds_le_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₂ x ≤ @nhds α t₁ x) :\n  t₁ ≤ t₂ :=\nassume s, show @is_open α t₁ s → @is_open α t₂ s,\n  begin simp [is_open_iff_nhds]; exact assume hs a ha, h _ $ hs _ ha end\n\nlemma eq_of_nhds_eq_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₂ x = @nhds α t₁ x) :\n  t₁ = t₂ :=\nle_antisymm\n  (le_of_nhds_le_nhds $ assume x, le_of_eq $ h x)\n  (le_of_nhds_le_nhds $ assume x, le_of_eq $ (h x).symm)\n\nend lattice\n\nsection galois_connection\nvariables {α : Type*} {β : Type*} {γ : Type*}\n\n/-- Given `f : α → β` and a topology on `β`, the induced topology on `α` is the collection of\n  sets that are preimages of some open set in `β`. This is the coarsest topology that\n  makes `f` continuous. -/\ndef topological_space.induced {α : Type u} {β : Type v} (f : α → β) (t : topological_space β) :\n  topological_space α :=\n{ is_open        := λs, ∃s', t.is_open s' ∧ s = f ⁻¹' s',\n  is_open_univ   := ⟨univ, by simp; exact t.is_open_univ⟩,\n  is_open_inter  := assume s₁ s₂ ⟨s'₁, hs₁, eq₁⟩ ⟨s'₂, hs₂, eq₂⟩,\n    ⟨s'₁ ∩ s'₂, by simp [eq₁, eq₂]; exact t.is_open_inter _ _ hs₁ hs₂⟩,\n  is_open_sUnion := assume s h,\n  begin\n    simp [classical.skolem] at h,\n    cases h with f hf,\n    apply exists.intro (⋃(x : set α) (h : x ∈ s), f x h),\n    simp [sUnion_eq_bUnion, (λx h, (hf x h).right.symm)],\n    exact (@is_open_Union β _ t _ $ assume i,\n      show is_open (⋃h, f i h), from @is_open_Union β _ t _ $ assume h, (hf i h).left)\n  end }\n\nlemma is_closed_induced_iff [t : topological_space β] {s : set α} {f : α → β} :\n  @is_closed α (t.induced f) s ↔ (∃t, is_closed t ∧ s = f ⁻¹' t) :=\n⟨assume ⟨t, ht, heq⟩, ⟨-t, by simp; assumption, by simp [preimage_compl, heq.symm]⟩,\n  assume ⟨t, ht, heq⟩, ⟨-t, ht, by simp [preimage_compl, heq.symm]⟩⟩\n\n/-- Given `f : α → β` and a topology on `α`, the coinduced topology on `β` is defined\n  such that `s:set β` is open if the preimage of `s` is open. This is the finest topology that\n  makes `f` continuous. -/\ndef topological_space.coinduced {α : Type u} {β : Type v} (f : α → β) (t : topological_space α) :\n  topological_space β :=\n{ is_open        := λs, t.is_open (f ⁻¹' s),\n  is_open_univ   := by simp; exact t.is_open_univ,\n  is_open_inter  := assume s₁ s₂ h₁ h₂, by simp; exact t.is_open_inter _ _ h₁ h₂,\n  is_open_sUnion := assume s h, by rw [preimage_sUnion]; exact (@is_open_Union _ _ t _ $ assume i,\n    show is_open (⋃ (H : i ∈ s), f ⁻¹' i), from\n      @is_open_Union _ _ t _ $ assume hi, h i hi) }\n\nvariables {t t₁ t₂ : topological_space α} {t' : topological_space β} {f : α → β} {g : β → α}\n\nlemma induced_le_iff_le_coinduced {f : α → β } {tα : topological_space α} {tβ : topological_space β} :\n  tβ.induced f ≤ tα ↔ tβ ≤ tα.coinduced f :=\niff.intro\n  (assume h s hs, show tα.is_open (f ⁻¹' s), from h _ ⟨s, hs, rfl⟩)\n  (assume h s ⟨t, ht, hst⟩, hst.symm ▸ h _ ht)\n\nlemma gc_induced_coinduced (f : α → β) :\n  galois_connection (topological_space.induced f) (topological_space.coinduced f) :=\nassume f g, induced_le_iff_le_coinduced\n\nlemma induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g :=\n(gc_induced_coinduced g).monotone_l h\n\nlemma coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f :=\n(gc_induced_coinduced f).monotone_u h\n\n@[simp] lemma induced_bot : (⊥ : topological_space α).induced g = ⊥ :=\n(gc_induced_coinduced g).l_bot\n\n@[simp] lemma induced_sup : (t₁ ⊔ t₂).induced g = t₁.induced g ⊔ t₂.induced g :=\n(gc_induced_coinduced g).l_sup\n\n@[simp] lemma induced_supr {ι : Sort w} {t : ι → topological_space α} :\n  (⨆i, t i).induced g = (⨆i, (t i).induced g) :=\n(gc_induced_coinduced g).l_supr\n\n@[simp] lemma coinduced_top : (⊤ : topological_space α).coinduced f = ⊤ :=\n(gc_induced_coinduced f).u_top\n\n@[simp] lemma coinduced_inf : (t₁ ⊓ t₂).coinduced f = t₁.coinduced f ⊓ t₂.coinduced f :=\n(gc_induced_coinduced f).u_inf\n\n@[simp] lemma coinduced_infi {ι : Sort w} {t : ι → topological_space α} :\n  (⨅i, t i).coinduced f = (⨅i, (t i).coinduced f) :=\n(gc_induced_coinduced f).u_infi\n\nlemma induced_id [t : topological_space α] : t.induced id = t :=\ntopological_space_eq $ funext $ assume s, propext $\n  ⟨assume ⟨s', hs, h⟩, h.symm ▸ hs, assume hs, ⟨s, hs, rfl⟩⟩\n\nlemma induced_compose [tβ : topological_space β] [tγ : topological_space γ]\n  {f : α → β} {g : β → γ} : (tγ.induced g).induced f = tγ.induced (g ∘ f) :=\ntopological_space_eq $ funext $ assume s, propext $\n  ⟨assume ⟨s', ⟨s, hs, h₂⟩, h₁⟩, h₁.symm ▸ h₂.symm ▸ ⟨s, hs, rfl⟩,\n    assume ⟨s, hs, h⟩, ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩\n\nlemma coinduced_id [t : topological_space α] : t.coinduced id = t :=\ntopological_space_eq rfl\n\nlemma coinduced_compose [tα : topological_space α]\n  {f : α → β} {g : β → γ} : (tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) :=\ntopological_space_eq rfl\n\nend galois_connection\n\n/- constructions using the complete lattice structure -/\nsection constructions\nopen topological_space\n\nvariables {α : Type u} {β : Type v}\n\ninstance inhabited_topological_space {α : Type u} : inhabited (topological_space α) :=\n⟨⊤⟩\n\nlemma t2_space_top : @t2_space α ⊤ :=\n{ t2 := assume x y hxy, ⟨{x}, {y}, trivial, trivial, mem_insert _ _, mem_insert _ _,\n  eq_empty_iff_forall_not_mem.2 $ by intros z hz; simp at hz; cc⟩ }\n\ninstance : topological_space empty := ⊤\ninstance : topological_space unit := ⊤\ninstance : topological_space bool := ⊤\ninstance : topological_space ℕ := ⊤\ninstance : topological_space ℤ := ⊤\n\ninstance sierpinski_space : topological_space Prop :=\ngenerate_from {{true}}\n\ninstance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=\ninduced subtype.val t\n\ninstance {r : α → α → Prop} [t : topological_space α] : topological_space (quot r) :=\ncoinduced (quot.mk r) t\n\ninstance {s : setoid α} [t : topological_space α] : topological_space (quotient s) :=\ncoinduced quotient.mk t\n\ninstance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α × β) :=\ninduced prod.fst t₁ ⊔ induced prod.snd t₂\n\ninstance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α ⊕ β) :=\ncoinduced sum.inl t₁ ⊓ coinduced sum.inr t₂\n\ninstance {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (sigma β) :=\n⨅a, coinduced (sigma.mk a) (t₂ a)\n\ninstance Pi.topological_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (Πa, β a) :=\n⨆a, induced (λf, f a) (t₂ a)\n\ninstance [topological_space α] : topological_space (list α) :=\ntopological_space.mk_of_nhds (traverse nhds)\n\nlemma nhds_list [topological_space α] (as : list α) : nhds as = traverse nhds as :=\nbegin\n  refine nhds_mk_of_nhds _ _ _ _,\n  { assume l, induction l,\n    case list.nil { exact le_refl _ },\n    case list.cons : a l ih {\n      suffices : list.cons <$> pure a <*> pure l ≤ list.cons <$> nhds a <*> traverse nhds l,\n      { simpa [-filter.pure_def] with functor_norm using this },\n      exact filter.seq_mono (filter.map_mono $ pure_le_nhds a) ih } },\n  { assume l s hs,\n    rcases (mem_traverse_sets_iff _ _).1 hs with ⟨u, hu, hus⟩, clear as hs,\n    have : ∃v:list (set α), l.forall₂ (λa s, is_open s ∧ a ∈ s) v ∧ sequence v ⊆ s,\n    { induction hu generalizing s,\n      case list.forall₂.nil : hs this { existsi [], simpa },\n      case list.forall₂.cons : a s as ss ht h ih t hts {\n        rcases mem_nhds_sets_iff.1 ht with ⟨u, hut, hu⟩,\n        rcases ih (subset.refl _) with ⟨v, hv, hvss⟩,\n        exact ⟨u::v, list.forall₂.cons hu hv,\n          subset.trans (set.seq_mono (set.image_subset _ hut) hvss) hts⟩ } },\n    rcases this with ⟨v, hv, hvs⟩,\n    refine ⟨sequence v, mem_traverse_sets _ _ _, hvs, _⟩,\n    { exact hv.imp (assume a s ⟨hs, ha⟩, mem_nhds_sets hs ha) },\n    { assume u hu,\n      have hu := (list.mem_traverse _ _).1 hu,\n      have : list.forall₂ (λa s, is_open s ∧ a ∈ s) u v,\n      { refine list.forall₂.flip _,\n        replace hv := hv.flip,\n        simp [list.forall₂_and_left, flip] at ⊢ hv,\n        exact ⟨hv.1, hu.flip⟩ },\n      exact mem_traverse_sets _ _ (this.imp $ assume a s ⟨hs, ha⟩, mem_nhds_sets hs ha) } }\nend\n\nlemma quotient_dense_of_dense [setoid α] [topological_space α] {s : set α} (H : ∀ x, x ∈ closure s) :\n  closure (quotient.mk '' s) = univ :=\nbegin\n  ext x,\n  suffices : x ∈ closure (quotient.mk '' s), by simp [this],\n  rw mem_closure_iff,\n  intros U U_op x_in_U,\n  let V := quotient.mk ⁻¹' U,\n  cases quotient.exists_rep x with y y_x,\n  have y_in_V : y ∈ V, by simp [mem_preimage_eq, y_x, x_in_U],\n  have V_op : is_open V := U_op,\n  have : V ∩ s ≠ ∅ := mem_closure_iff.1 (H y) V V_op y_in_V,\n  rcases exists_mem_of_ne_empty this with ⟨w, w_in_V, w_in_range⟩,\n  exact ne_empty_of_mem ⟨by tauto, mem_image_of_mem quotient.mk w_in_range⟩\nend\n\nlemma generate_from_le {t : topological_space α} { g : set (set α) } (h : ∀s∈g, is_open s) :\n  generate_from g ≤ t :=\ngenerate_from_le_iff_subset_is_open.2 h\n\nprotected def topological_space.nhds_adjoint (a : α) (f : filter α) : topological_space α :=\n{ is_open        := λs, a ∈ s → s ∈ f.sets,\n  is_open_univ   := assume s, univ_mem_sets,\n  is_open_inter  := assume s t hs ht ⟨has, hat⟩, inter_mem_sets (hs has) (ht hat),\n  is_open_sUnion := assume k hk ⟨u, hu, hau⟩, mem_sets_of_superset (hk u hu hau) (subset_sUnion_of_mem hu) }\n\nlemma gc_nhds (a : α) :\n  @galois_connection _ (order_dual (filter α)) _ _ (λt, @nhds α t a) (topological_space.nhds_adjoint a) :=\nassume t (f : filter α), show f ≤ @nhds α t a ↔ _, from iff.intro\n  (assume h s hs has, h $ @mem_nhds_sets α t a s hs has)\n  (assume h, le_infi $ assume u, le_infi $ assume ⟨hau, hu⟩, le_principal_iff.2 $ h _ hu hau)\n\nlemma nhds_mono {t₁ t₂ : topological_space α} {a : α} (h : t₁ ≤ t₂) :\n  @nhds α t₂ a ≤ @nhds α t₁ a := (gc_nhds a).monotone_l h\n\nlemma nhds_supr {ι : Sort*} {t : ι → topological_space α} {a : α} :\n  @nhds α (supr t) a = (⨅i, @nhds α (t i) a) := (gc_nhds a).l_supr\n\nlemma nhds_Sup {s : set (topological_space α)} {a : α} :\n  @nhds α (Sup s) a = (⨅t∈s, @nhds α t a) := (gc_nhds a).l_Sup\n\nlemma nhds_sup {t₁ t₂ : topological_space α} {a : α} :\n  @nhds α (t₁ ⊔ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a := (gc_nhds a).l_sup\n\nlemma nhds_bot {a : α} : @nhds α ⊥ a = ⊤ := (gc_nhds a).l_bot\n\nprivate lemma separated_by_f\n  [tα : topological_space α] [tβ : topological_space β] [t2_space β]\n  (f : α → β) (hf : induced f tβ ≤ tα) {x y : α} (h : f x ≠ f y) :\n  ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=\nlet ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in\n⟨f ⁻¹' u, f ⁻¹' v, hf _ ⟨u, uo, rfl⟩, hf _ ⟨v, vo, rfl⟩, xu, yv,\n  by rw [←preimage_inter, uv, preimage_empty]⟩\n\ninstance {p : α → Prop} [t : topological_space α] [t2_space α] : t2_space (subtype p) :=\n⟨assume x y h,\n  separated_by_f subtype.val (le_refl _) (mt subtype.eq h)⟩\n\ninstance [t₁ : topological_space α] [t2_space α] [t₂ : topological_space β] [t2_space β] :\n  t2_space (α × β) :=\n⟨assume ⟨x₁,x₂⟩ ⟨y₁,y₂⟩ h,\n  or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h))\n    (λ h₁, separated_by_f prod.fst le_sup_left h₁)\n    (λ h₂, separated_by_f prod.snd le_sup_right h₂)⟩\n\ninstance Pi.t2_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] [Πa, t2_space (β a)] :\n  t2_space (Πa, β a) :=\n⟨assume x y h,\n  let ⟨i, hi⟩ := not_forall.mp (mt funext h) in\n  separated_by_f (λz, z i) (le_supr _ i) hi⟩\n\nend constructions\n\nnamespace topological_space\n/- countability axioms\n\nFor our applications we are interested that there exists a countable basis, but we do not need the\nconcrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins.\n-/\nvariables {α : Type u} [t : topological_space α]\ninclude t\n\n/-- A topological basis is one that satisfies the necessary conditions so that\n  it suffices to take unions of the basis sets to get a topology (without taking\n  finite intersections as well). -/\ndef is_topological_basis (s : set (set α)) : Prop :=\n(∀t₁∈s, ∀t₂∈s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃∈s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂) ∧\n(⋃₀ s) = univ ∧\nt = generate_from s\n\nlemma is_topological_basis_of_subbasis {s : set (set α)} (hs : t = generate_from s) :\n  is_topological_basis ((λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ ⋂₀ f ≠ ∅}) :=\nlet b' := (λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ ⋂₀ f ≠ ∅} in\n⟨assume s₁ ⟨t₁, ⟨hft₁, ht₁b, ht₁⟩, eq₁⟩ s₂ ⟨t₂, ⟨hft₂, ht₂b, ht₂⟩, eq₂⟩,\n    have ie : ⋂₀(t₁ ∪ t₂) = ⋂₀ t₁ ∩ ⋂₀ t₂, from Inf_union,\n    eq₁ ▸ eq₂ ▸ assume x h,\n      ⟨_, ⟨t₁ ∪ t₂, ⟨finite_union hft₁ hft₂, union_subset ht₁b ht₂b,\n        by simpa [ie] using ne_empty_of_mem h⟩, ie⟩, h, subset.refl _⟩,\n  eq_univ_iff_forall.2 $ assume a, ⟨univ, ⟨∅, by simp; exact (@empty_ne_univ _ ⟨a⟩).symm⟩, mem_univ _⟩,\n have generate_from s = generate_from b',\n    from le_antisymm\n      (generate_from_le $ assume s hs,\n        by_cases\n          (assume : s = ∅, by rw [this]; apply @is_open_empty _ _)\n          (assume : s ≠ ∅, generate_open.basic _ ⟨{s}, by simp [this, hs]⟩))\n      (generate_from_le $ assume u ⟨t, ⟨hft, htb, ne⟩, eq⟩,\n        eq ▸ @is_open_sInter _ (generate_from s) _ hft (assume s hs, generate_open.basic _ $ htb hs)),\n  this ▸ hs⟩\n\nlemma is_topological_basis_of_open_of_nhds {s : set (set α)}\n  (h_open : ∀ u ∈ s, _root_.is_open u)\n  (h_nhds : ∀(a:α) (u : set α), a ∈ u → _root_.is_open u → ∃v ∈ s, a ∈ v ∧ v ⊆ u) :\n  is_topological_basis s :=\n⟨assume t₁ ht₁ t₂ ht₂ x ⟨xt₁, xt₂⟩,\n    h_nhds x (t₁ ∩ t₂) ⟨xt₁, xt₂⟩\n      (is_open_inter _ _ _ (h_open _ ht₁) (h_open _ ht₂)),\n  eq_univ_iff_forall.2 $ assume a,\n    let ⟨u, h₁, h₂, _⟩ := h_nhds a univ trivial (is_open_univ _) in\n    ⟨u, h₁, h₂⟩,\n  le_antisymm\n    (assume u hu,\n      (@is_open_iff_nhds α (generate_from _) _).mpr $ assume a hau,\n        let ⟨v, hvs, hav, hvu⟩ := h_nhds a u hau hu in\n        by rw nhds_generate_from; exact infi_le_of_le v (infi_le_of_le ⟨hav, hvs⟩ $ by simp [hvu]))\n    (generate_from_le h_open)⟩\n\nlemma mem_nhds_of_is_topological_basis {a : α} {s : set α} {b : set (set α)}\n  (hb : is_topological_basis b) : s ∈ (nhds a).sets ↔ ∃t∈b, a ∈ t ∧ t ⊆ s :=\nbegin\n  rw [hb.2.2, nhds_generate_from, infi_sets_eq'],\n  { simp [and_comm, and.left_comm] },\n  { exact assume s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩,\n      have a ∈ s ∩ t, from ⟨hs₁, ht₁⟩,\n      let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ this in\n      ⟨u, ⟨hu₂, hu₁⟩, by simpa [(≥)] using hu₃⟩ },\n  { suffices : a ∈ (⋃₀ b), { simpa [and_comm] },\n    { rw [hb.2.1], trivial } }\nend\n\nlemma is_open_of_is_topological_basis {s : set α} {b : set (set α)}\n  (hb : is_topological_basis b) (hs : s ∈ b) : _root_.is_open s :=\nis_open_iff_mem_nhds.2 $ λ a as,\n(mem_nhds_of_is_topological_basis hb).2 ⟨s, hs, as, subset.refl _⟩\n\nlemma mem_basis_subset_of_mem_open {b : set (set α)}\n  (hb : is_topological_basis b) {a:α} {u : set α} (au : a ∈ u)\n  (ou : _root_.is_open u) : ∃v ∈ b, a ∈ v ∧ v ⊆ u :=\n(mem_nhds_of_is_topological_basis hb).1 $ mem_nhds_sets ou au\n\nlemma sUnion_basis_of_is_open {B : set (set α)}\n  (hB : is_topological_basis B) {u : set α} (ou : _root_.is_open u) :\n  ∃ S ⊆ B, u = ⋃₀ S :=\n⟨{s ∈ B | s ⊆ u}, λ s h, h.1, set.ext $ λ a,\n  ⟨λ ha, let ⟨b, hb, ab, bu⟩ := mem_basis_subset_of_mem_open hB ha ou in\n         ⟨b, ⟨hb, bu⟩, ab⟩,\n   λ ⟨b, ⟨hb, bu⟩, ab⟩, bu ab⟩⟩\n\nlemma Union_basis_of_is_open {B : set (set α)}\n  (hB : is_topological_basis B) {u : set α} (ou : _root_.is_open u) :\n  ∃ (β : Type u) (f : β → set α), u = (⋃ i, f i) ∧ ∀ i, f i ∈ B :=\nlet ⟨S, sb, su⟩ := sUnion_basis_of_is_open hB ou in\n⟨S, subtype.val, su.trans set.sUnion_eq_Union, λ ⟨b, h⟩, sb h⟩\n\nvariables (α)\n\n/-- A separable space is one with a countable dense subset. -/\nclass separable_space : Prop :=\n(exists_countable_closure_eq_univ : ∃s:set α, countable s ∧ closure s = univ)\n\n/-- A first-countable space is one in which every point has a\n  countable neighborhood basis. -/\nclass first_countable_topology : Prop :=\n(nhds_generated_countable : ∀a:α, ∃s:set (set α), countable s ∧ nhds a = (⨅t∈s, principal t))\n\n/-- A second-countable space is one with a countable basis. -/\nclass second_countable_topology : Prop :=\n(is_open_generated_countable : ∃b:set (set α), countable b ∧ t = topological_space.generate_from b)\n\ninstance second_countable_topology.to_first_countable_topology\n  [second_countable_topology α] : first_countable_topology α :=\nlet ⟨b, hb, eq⟩ := second_countable_topology.is_open_generated_countable α in\n⟨assume a, ⟨{s | a ∈ s ∧ s ∈ b},\n  countable_subset (assume x ⟨_, hx⟩, hx) hb, by rw [eq, nhds_generate_from]⟩⟩\n\nlemma is_open_generated_countable_inter [second_countable_topology α] :\n  ∃b:set (set α), countable b ∧ ∅ ∉ b ∧ is_topological_basis b :=\nlet ⟨b, hb₁, hb₂⟩ := second_countable_topology.is_open_generated_countable α in\nlet b' := (λs, ⋂₀ s) '' {s:set (set α) | finite s ∧ s ⊆ b ∧ ⋂₀ s ≠ ∅} in\n⟨b',\n  countable_image _ $ countable_subset (by simp {contextual:=tt}) (countable_set_of_finite_subset hb₁),\n  assume ⟨s, ⟨_, _, hn⟩, hp⟩, hn hp,\n  is_topological_basis_of_subbasis hb₂⟩\n\ninstance second_countable_topology.to_separable_space\n  [second_countable_topology α] : separable_space α :=\nlet ⟨b, hb₁, hb₂, hb₃, hb₄, eq⟩ := is_open_generated_countable_inter α in\nhave nhds_eq : ∀a, nhds a = (⨅ s : {s : set α // a ∈ s ∧ s ∈ b}, principal s.val),\n  by intro a; rw [eq, nhds_generate_from]; simp [infi_subtype],\nhave ∀s∈b, ∃a, a ∈ s, from assume s hs, exists_mem_of_ne_empty $ assume eq, hb₂ $ eq ▸ hs,\nhave ∃f:∀s∈b, α, ∀s h, f s h ∈ s, by simp only [skolem] at this; exact this,\nlet ⟨f, hf⟩ := this in\n⟨⟨(⋃s∈b, ⋃h:s∈b, {f s h}),\n  countable_bUnion hb₁ (by simp [countable_Union_Prop]),\n  set.ext $ assume a,\n  have a ∈ (⋃₀ b), by rw [hb₄]; exact trivial,\n  let ⟨t, ht₁, ht₂⟩ := this in\n  have w : {s : set α // a ∈ s ∧ s ∈ b}, from ⟨t, ht₂, ht₁⟩,\n  suffices (⨅ (x : {s // a ∈ s ∧ s ∈ b}), principal (x.val ∩ ⋃s (h₁ h₂ : s ∈ b), {f s h₂})) ≠ ⊥,\n    by simpa [closure_eq_nhds, nhds_eq, infi_inf w],\n  infi_neq_bot_of_directed ⟨a⟩\n    (assume ⟨s₁, has₁, hs₁⟩ ⟨s₂, has₂, hs₂⟩,\n      have a ∈ s₁ ∩ s₂, from ⟨has₁, has₂⟩,\n      let ⟨s₃, hs₃, has₃, hs⟩ := hb₃ _ hs₁ _ hs₂ _ this in\n      ⟨⟨s₃, has₃, hs₃⟩, begin\n        simp only [le_principal_iff, mem_principal_sets, (≥)],\n        simp at hs, split; apply inter_subset_inter_left; simp [hs]\n      end⟩)\n    (assume ⟨s, has, hs⟩,\n      have s ∩ (⋃ (s : set α) (H h : s ∈ b), {f s h}) ≠ ∅,\n        from ne_empty_of_mem ⟨hf _ hs, mem_bUnion hs $ mem_Union.mpr ⟨hs, by simp⟩⟩,\n      by simp [this]) ⟩⟩\n\nlemma is_open_sUnion_countable [second_countable_topology α]\n  (S : set (set α)) (H : ∀ s ∈ S, _root_.is_open s) :\n  ∃ T : set (set α), countable T ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S :=\nlet ⟨B, cB, _, bB⟩ := is_open_generated_countable_inter α in\nbegin\n  let B' := {b ∈ B | ∃ s ∈ S, b ⊆ s},\n  rcases axiom_of_choice (λ b:B', b.2.2) with ⟨f, hf⟩,\n  change B' → set α at f,\n  haveI : encodable B' := (countable_subset (sep_subset _ _) cB).to_encodable,\n  have : range f ⊆ S := range_subset_iff.2 (λ x, (hf x).fst),\n  exact ⟨_, countable_range f, this,\n    subset.antisymm (sUnion_subset_sUnion this) $\n    sUnion_subset $ λ s hs x xs,\n      let ⟨b, hb, xb, bs⟩ := mem_basis_subset_of_mem_open bB xs (H _ hs) in\n      ⟨_, ⟨⟨_, hb, _, hs, bs⟩, rfl⟩, (hf _).snd xb⟩⟩\nend\n\nend topological_space\n\nsection limit\nvariables {α : Type u} [inhabited α] [topological_space α]\nopen classical\n\n/-- If `f` is a filter, then `lim f` is a limit of the filter, if it exists. -/\nnoncomputable def lim (f : filter α) : α := epsilon $ λa, f ≤ nhds a\n\nlemma lim_spec {f : filter α} (h : ∃a, f ≤ nhds a) : f ≤ nhds (lim f) := epsilon_spec h\n\nvariables [t2_space α] {f : filter α}\n\nlemma lim_eq {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : lim f = a :=\neq_of_nhds_neq_bot $ neq_bot_of_le_neq_bot hf $ le_inf (lim_spec ⟨_, h⟩) h\n\n@[simp] lemma lim_nhds_eq {a : α} : lim (nhds a) = a :=\nlim_eq nhds_neq_bot (le_refl _)\n\n@[simp] lemma lim_nhds_eq_of_closure {a : α} {s : set α} (h : a ∈ closure s) :\n  lim (nhds a ⊓ principal s) = a :=\nlim_eq begin rw [closure_eq_nhds] at h, exact h end inf_le_left\n\nend limit\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/topology/topological_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7760974435129577}}
{"text": "/-\nEste documento ha sido escrito completamente como un archivo de Lean.\nPara seguir los ejercicios, debe abrir este archivo en su editor,\npor ejemplo VS Code. Se le deberían haber entregado instrucciones\nde como instalar Lean en su computadora. En esta página puede\nencontrar detalladas instrucciones, en inglés, de como instalar\nLean 3 en diferentes sistemas operativos:\n\nhttps://leanprover-community.github.io/get_started.html\n-/\n\n/-\nSe recomienda enfáticamente participar activamente en este curso:\nno sólo escuche, pruebe también! \n\nSi de verdad intentó instalar Lean y no pudo por alguna razón,\nuna opción alternativa es ver esta hoja en línea:\n\nhttps://leanprover-community.github.io/lean-web-editor/#url=https%3A%2F%2Fraw.githubusercontent.com%2Fgoens%2Fsmf-ues-2022%2Fmaster%2Fsrc%2Flogica.lean\n\nSin embargo, se recomienda *no* acceder en línea, sino instalar\nLean en su computadora directamente. Así puede guardar su progreso\ny en un futuro tal vez trabajar con teoremas más complejos también.\n-/\n\n/-\nEsta primera hoja discute las bases de lógica en Lean.\nLa lógica es la base de la matemática moderna (axiomática). \n\nSi bien el estudio de la lógica puede ser complejo e interesante \npor su cuenta, en este minicurso no vamos a profundizar en temas\nde lógica matemática. La idea de este primer módulo es aprender\nsólo las bases de la lógica mínimas necesarias para usar Lean y\ndemostrar teoremas de otras ramas de la matemática.\n\nEste minicurso está basado, en parte, en el curso \"Formalizing\nMathematics\" de Kevin Buzzard: \nhttps://github.com/ImperialCollegeLondon/formalising-mathematics\n-/\n\n/-\nAntes de empezar con definiciones, creamos un espacio de nombres\npara este curso, smf22. Este espacio lo usamos sólo para no tener\nproblemas de que usamos el mismo nombre que algo que ya exista.\n-/\nnamespace smf22\n\n/-\nEn la lógica los objetos principales de interés son \"proposiciones\"\nUna proposición es un enunciado o una aseveración,\ngeneralmente de una verdad demostrada o asumida, pero también de\nuna falsedad. A Lean le decimos que `P` es una proposición con la\nnotación usando dos puntos: `P : Prop`.\n\nPor ejemplo:\n-/\nvariables  (P Q R : Prop).\n\n/- Esta declaración está diciendole a Lean que tenemos tres variables,\n`P`, `Q` y `R`. Estas tres variables representan propoiciones.\nPodrían ser proposiciones como \"todos los hombres son mortales\" o\n\"Socrates es un hombre\", ejemplos clásicos de la lógica, pero también\nproposiciones matemáticas como \"2 es el único número primo par\" \no incluso \"La parte real de todo cero no trivial de la función \nzeta de Riemann es `1/2`\". \n\nEn la lógica no importa lo que estas proposiciones representan.\nLo que importa son sus relaciones, como implicación.\nEn las matemáticas, generalmente escribimos `P ⇒ Q` para\ndecir que `P` implica `Q`. En Lean se usa la flecha sencilla,\n`P → Q`, por razones que van más allá de este minicurso (tiene \nque ver con un concepto llamado la correspondencia de Curry-Howard,\npero no profundizaremos en esto).  -/\n\n/-\nEmpezamos demostrando un teorema bien sencillo, para entender\ncomo funciona Lean y como nos ayuda a demostrar. Toda proposición\n`P` se implica a si misma. En Lean lo decimos de la siguiente manera:\n-/\ntheorem id : P → P :=\nbegin\n  intro hP,\n  exact hP,\nend\n\n/-\nPara demostrar esto usamos dos \"tácticas\", `intro` que introduce\nhipótesis, y `exact` que le dice a Lean que nuestra solución es\nexactamente la hipótesis nombrada.\n\nUn ejemplo un poco menos trivial, conocido como \"modus ponens\"\n  en lógica, que viene del latín: \"el modo que, al afirmar, afirma\"\n-/\nlemma modus_ponens : P → (P → Q) → Q := \nbegin\n  intro hP,\n  intro hPQ,\n  apply hPQ,\n  exact hP,\nend\n\n/- \nLa táctica `intro` se puede usar para introducir varias\nhipótesis a la vez, diciendo en vez `intros`.\n\nAquí también hemos usado una nueva táctica, `apply`. \nEsta reduce nuestro *objetivo* usando una suposición.\nNote como esto nos sirve para razonar \"para atrás\": \n\nPara demostrar `Q`, sabiendo que `P → Q`, basta demostrar\n`P`. En las matemáticas es más común razonar \"para adelante\":\n-/\nlemma modus_ponens_adelante : P → (P → Q) → Q := \nbegin\n  intros hP hPQ,\n  have hQ := hPQ hP,\n  exact hQ,\nend\n\n/- Al usar `have` le podemos dar nombre a una conclusión que\ntenemos, en el estilo de razonamiento \"hacia adelante\". Sin \nembargo, trabjando en Lean preferimos la otra variante, reduciendo\nel objectivo. -/\n\n/- Empezamos con el primer ejercicio para resolver, demostremos\nque la implicación lógica es transitiva -/\nlemma imp_trans : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  intros PQ hQR hP,\n  apply hQR,\n  apply PQ,\n  exact hP,\nend\n\n/- Le decimos a Lean que no tenemos una demostración usando\n`sorry`, como disculpa, para que acepte el teorema sin demostación.\nNo se preocupe, sin embargo, Lean advierte cuando un teorema ha sido\naceptado sin demostración, también cuando hemos usado un teorema que\nya teníamos. -/\n\n-- El siguiente us una variante \"relativa\" del \"modus ponens\".\n -- Asumiendo `P`, si `Q -> R` y `Q`, entonces `R`.\nlemma forall_imp : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  -- `intros hPQR hPQ hP,` sería una forma rápida de comenzar.\n  -- Asegúrese de entender que está pasando aquí si la usa.\n  sorry\nend\n\n/-\nHemos visto implicación lógica. El siguiente concepto central\nque veremos es la negación.\n \nLa negación de `P` se escribe `¬ P`. En Lean, esto es *por definición*\nequivalente a decir `P → false`. El origen de esto es el concepto\nen lógica de \"Ex falso quodlibet\", de la falsedad se puede deducir\ncalquier cosa. Entonces una proposicicón `P` es falsa si (y sólo si)\npodemos deducir also falso de ella. Esto nunca pasa con una \nproposición verdadera, o si no nuestros axiomas fueran inconsistentes!\n\nEn Lean podemos escribir esta caracterización de la siguiente manera:\n-/\ntheorem not_iff_imp_false : ¬ P ↔ (P → false) :=\nbegin\n  -- por definición\n  refl\nend\n\n/-\nHemos escrito `↔` en vez de `→`, para decir \"si y sólo si\". \n`P ↔ Q` no quiere decir más que `P → Q` y `Q → P`.\n\nPara demostrarlo usamos una nueva táctia, `refl`, que quiere\ndecir que por \"reflexividad\" (de la equivalencia). Básicamente\nle estamos diciendo esto es verdad porque ambos lados dicen lo\nmismo.\n\nVamos a demostrar la doble negación, de la siguiente manera:\n-/\ntheorem not_not_intro : P → ¬ (¬ P) :=\nbegin\n  intro hP,\n  rw not_iff_imp_false,\n  rw not_iff_imp_false,\n  intro hP1,\n  apply hP1,\n  exact hP,\n  -- Podemos usar `rw not_iff_imp_false` para cambiar `¬ X` a `X → false`. \n  -- Pero no tenemos que hacerlo porque son lo mismo *por definición*\nend\n\n/-\nLa táctica `rw` viene de \"rewrite\" (reescribir, en inglés). \nLa usamos para cambiar dos porposiciónes que son equivalentes,\no dos valores que son iguales, en alguna hipótesis u objetivo.\n-/\n\n/-\nLa otra implicación, `¬ (¬ P) → P` no la podemos demostrar aquí.\nDe hecho, esto es equivalente a un axioma que se llama el\n \"principio del tercero excluido\":\n-/\naxiom te (A : Prop) : A ∨ ¬ A\n\n/-\nDiscutiremos esto más tarde, después de hablar de disyunciones.\n-/\n\n/- Relacionado con el anterior, vamos a demostrar otro principio \nde razonamiento lógico que normalmente se le concoce como \n\"modus tollens\". A veces se le considera una forma de \n\"demostración por contradicción\": -/\n\ntheorem modus_tollens : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  sorry,\nend\n\n/-\nPara demostrar la porposición de \"ex falso quod libet\"\n  mencionada arriba\n-/\ntheorem ex_falso_quod_libet : false → Q :=\nbegin\n  intros hFalso,\n  exfalso,\n  exact hFalso,\nend\n\n/- Esta demostración ocupa una tactica 'exfalso'\npara cambiar el objectivo a \"false\" (falso).\nPodemos hacer esto porque (asumimos que) a partir de nuestros \naxiomas no se puede demostrar falso. \n\nEntonces en este caso podemos deducir cualquier cosa, \npero obviamente la premisa (falso) nunca se cumplirá.\nRecuerde que aquí estamos demostrando la *implicación*\n`false → Q`, y no la proposición `Q` sola. \n -/\n\n/-\nA continuación vamos a cubrir conjunciones (el \"y\" lógico).\nEn Lean, igual que en lógica, escribimos una conjunción con el\nsímbolo `∧`. \n\nEn Lean, la hipótesis `P ∧ Q` es equivalente a tener dos\nhipótesis, `P` y `Q`. Podemos separarlas usando la táctica\n`cases`:\n-/\n\ntheorem and.elim_left : P ∧ Q → P :=\nbegin\n  intros hPyQ,\n  cases hPyQ with hP hQ,\n  exact hP,\nend\n\n/- Ahora un exercicio muy sencillo! -/\ntheorem and.elim_right : P ∧ Q → Q :=\nbegin\n  intros hPyQ,\n  cases hPyQ with hP hQ,\n  exact hQ,\nend\n\n/- Hemos visto como usar una hipótesis con una conjunción.\n Ahora, para *demostrar* una proposición con una conjución,\n tenemos que demostrar que amabs proposiciones son verdaderas.\n Esto lo hacemos con la táctica `split`: -/\n\ntheorem and.intro : P → Q → P ∧ Q :=\nbegin\n  intros hP hQ,\n  split,\n  { --usamos estos parentesis curvos para 'enfocar' un objetivo.\n     exact hP,\n  },\n  {\n     exact hQ,\n   }\nend\n\n/- Un par de ejercicios: -/\ntheorem and.elim : P ∧ Q → (P → Q → R) → R :=\nbegin\n  intros hPyQ hPQR,\n  cases hPyQ with hP hQ,\n  apply hPQR, -- P → (Q → R)\n  {\n    exact hP,\n  },\n  {\n    exact hQ,\n  }\nend\n\n/-- `∧` es simétrico -/\ntheorem and.symm : P ∧ Q → Q ∧ P :=\nbegin\n  sorry\nend\n\n/-- `∧` es transitivo -/\ntheorem and.trans : (P ∧ Q) → (Q ∧ R) → (P ∧ R) :=\nbegin\n  sorry,\nend\n\n/- Luego de ver la conjunción, vamos a ver la disyunción. \nPara esto necesitaremos una variable más, `S`, que también\nsea una proposición:\n-/\nvariable (S : Prop)\n\n/- Igual que con la conjunción, es diferente como demostrar\nuna disyunción a como usarla en una demostración: -/\n\ntheorem or.intro_left : P → P ∨ Q :=\nbegin\n  intros hP,\n  left,\n  exact hP,\nend\n\n/- La táctica `left` (izquierda en inglés) se usa para escoger\nla parte izquierda de una disjyunción. Equivalentamente podemos\ndemostrar escogiendo la derecha con la táctica `right`. Intente\ndemostrar lo siguiente: -/\ntheorem or.intro_right : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\n/- Como usamos una disyunción en una hipótesis? \n  Igual que vimos anteriormente, distinguiendo \n  diferentes casos con la táctica `cases` -/\ntheorem or.elim : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  intros hPoQ, \n  cases hPoQ with hP hQ,\n  {\n   intros hPR hQR,\n   apply hPR,\n   exact hP,\n  },\n  {\n   intros hPR hQR,\n   apply hQR,\n   exact hQ,\n  }\nend\n\n/- Cual es la diferencia entre el uso de `cases` aquí en \ndisyunción y anteriormente en una conjunción? -/\n\n/- Un par de ejercicios de propiedades de la disyunción: -/\n/- `∨` es simétrico -/\ntheorem or.symm : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n/- `∨` is commutativo -/\ntheorem or.comm : P ∨ Q ↔ Q ∨ P :=\nbegin\n  sorry,\nend\n\n/- `∨` is associativo -/\ntheorem or.assoc : (P ∨ Q) ∨ R ↔ P ∨ Q ∨ R :=\nbegin\n  sorry,\nend\n\n/-\nFinalmente, regresamos al principio del tercero\nexcluido. Puede demostrar la otra dirección de\nla doble negación que vimos anteriormente?\n\nRecuerde que *necesita* usar el axioma `te`\nque definimos arriba. \n\nPodemos pedirle a Lean que nos lo recuerde\nusando `#check`:\n-/\n#check te\n\n/-\nAquí usamos `have` para incluir la hipótesis que\nobtenemos del axioma explicitamente en nuestra\ndemostración:\n-/\ntheorem eliminacion_de_doble_negacion : ¬ (¬ P) → P :=\nbegin\n  have hPonoP := (te P),\n  sorry,\nend\n\n\nend smf22\n", "meta": {"author": "goens", "repo": "smf-ues-2022", "sha": "d0122da8b17aef50361c59e3ebcb6fd8f4b45ad1", "save_path": "github-repos/lean/goens-smf-ues-2022", "path": "github-repos/lean/goens-smf-ues-2022/smf-ues-2022-d0122da8b17aef50361c59e3ebcb6fd8f4b45ad1/src/logica.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.8438951025545427, "lm_q1q2_score": 0.7760818263032117}}
{"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-/\n\nimport data.int.basic\nimport algebra.field.basic\n\n/-!\n# Euclidean domains\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 `ℕ` 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\n* `gcd_eq_gcd_ab`: states Bézout's lemma for Euclidean domains.\n* `int.euclidean_domain`: shows that `ℤ` is a Euclidean domain.\n* `field.to_euclidean_domain`: shows that any field is a Euclidean domain.\n\n## Notation\n\n`≺` denotes the well founded relation on the Euclidean domain, e.g. in the example of the polynomial\nring over a field, `p ≺ 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 `ℤ` would correspond to\nsetting `i ≺ 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 à valeurs finies*]\n  [MR399081]\n* [M. Nagata, *On Euclid algorithm*][MR541021]\n\n\n## Tags\n\nEuclidean domain, transfinite Euclidean domain, Bézout'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 → ℕ`.\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 → R → R)\n(quotient_zero : ∀ a, quotient a 0 = 0)\n(remainder : R → R → R)\n(quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a)\n(r : R → R → Prop)\n(r_well_founded : well_founded r)\n(remainder_lt : ∀ a {b}, b ≠ 0 → r (remainder a b) b)\n(mul_left_not_lt : ∀ a {b}, b ≠ 0 → ¬r (a * b) a)\n\nnamespace euclidean_domain\nvariable {R : Type u}\nvariables [euclidean_domain R]\n\nlocal infix ` ≺ `:50 := euclidean_domain.r\n\n@[priority 70] -- see Note [lower instance priority]\ninstance : has_div R := ⟨euclidean_domain.quotient⟩\n\n@[priority 70] -- see Note [lower instance priority]\ninstance : has_mod R := ⟨euclidean_domain.remainder⟩\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 : ∀ a {b : R}, b ≠ 0 → (a % b) ≺ b :=\neuclidean_domain.remainder_lt\n\ntheorem mul_right_not_lt {a : R} (b) (h : a ≠ 0) : ¬(a * b) ≺ b :=\nby { rw mul_comm, exact mul_left_not_lt b h }\n\nlemma mul_div_cancel_left {a : R} (b) (a0 : a ≠ 0) : a * b / a = b :=\neq.symm $ eq_of_sub_eq_zero $ classical.by_contradiction $ λ 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 : R} (b0 : b ≠ 0) : a * b / b = a :=\nby { rw mul_comm, exact mul_div_cancel_left a b0 }\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\n@[simp] lemma mod_eq_zero {a b : R} : a % b = 0 ↔ b ∣ a :=\n⟨λ h, by { rw [← div_add_mod a b, h, add_zero], exact dvd_mul_right _ _ },\n λ ⟨c, e⟩, begin\n  rw [e, ← 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⟩\n\n@[simp] lemma mod_self (a : R) : a % a = 0 :=\nmod_eq_zero.2 dvd_rfl\n\nlemma dvd_mod_iff {a b c : R} (h : c ∣ b) : c ∣ a % b ↔ c ∣ a :=\nby rw [dvd_add_iff_right (h.mul_right _), div_add_mod]\n\nlemma lt_one (a : R) : a ≺ (1:R) → a = 0 :=\nby { haveI := classical.dec, exact\n  not_imp_not.1 (λ h, by simpa only [one_mul] using mul_left_not_lt 1 h) }\n\nlemma val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b\n| _ b ⟨d, rfl⟩ ha := mul_left_not_lt b (mt (by { rintro rfl, exact mul_zero _ }) ha)\n\n@[simp] lemma mod_one (a : R) : a % 1 = 0 :=\nmod_eq_zero.2 (one_dvd _)\n\n@[simp] lemma zero_mod (b : R) : 0 % b = 0 :=\nmod_eq_zero.2 (dvd_zero _)\n\n@[simp, priority 900] lemma div_zero (a : R) : a / 0 = 0 :=\neuclidean_domain.quotient_zero a\n\n@[simp, priority 900] lemma zero_div {a : R} : 0 / a = 0 :=\nclassical.by_cases\n  (λ a0 : a = 0, a0.symm ▸ div_zero 0)\n  (λ a0, by simpa only [zero_mul] using mul_div_cancel 0 a0)\n\n@[simp, priority 900] lemma div_self {a : R} (a0 : a ≠ 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 : R} (hb : b ≠ 0) (h : a * b = c) : a = c / b :=\nby rw [← h, mul_div_cancel _ hb]\n\nlemma eq_div_of_mul_eq_right {a b c : R} (ha : a ≠ 0) (h : a * b = c) : b = c / a :=\nby rw [← h, mul_div_cancel_left _ ha]\n\ntheorem mul_div_assoc (x : R) {y z : R} (h : z ∣ 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 ⟨p, rfl⟩,\n  rw [mul_div_cancel_left _ hz, mul_left_comm, mul_div_cancel_left _ hz]\nend\n\n@[simp, priority 900] -- This generalizes `int.div_one`, see note [simp-normal form]\nlemma div_one (p : R) : p / 1 = p :=\n(euclidean_domain.eq_div_of_mul_eq_left (@one_ne_zero R _ _) (mul_one p)).symm\n\nlemma div_dvd_of_dvd {p q : R} (hpq : q ∣ p) :\n  p / q ∣ p :=\nbegin\n  by_cases hq : q = 0,\n  { rw [hq, zero_dvd_iff] at hpq,\n    rw hpq,\n    exact dvd_zero _ },\n  use q,\n  rw [mul_comm, ← euclidean_domain.mul_div_assoc _ hpq, mul_comm,\n      euclidean_domain.mul_div_cancel _ hq]\nend\n\nsection\nopen_locale classical\n\n@[elab_as_eliminator]\ntheorem gcd.induction {P : R → R → Prop} : ∀ a b : R,\n  (∀ x, P 0 x) →\n  (∀ a b, a ≠ 0 → P (b % a) a → P a b) →\n  P a b\n| a := λ b H0 H1, if a0 : a = 0 then a0.symm ▸ 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 := λ _ _, `[exact ⟨_, r_well_founded⟩]}\n\nend\n\nsection gcd\nvariable [decidable_eq R]\n\n/-- `gcd a b` is a (non-unique) element such that `gcd a b ∣ a` `gcd a b ∣ b`, and for\n  any element `c` such that `c ∣ a` and `c ∣ b`, then `c ∣ gcd a b` -/\ndef gcd : R → R → R\n| a := λ 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 := λ _ _, `[exact ⟨_, r_well_founded⟩]}\n\n@[simp] theorem gcd_zero_left (a : R) : gcd 0 a = a :=\nby { rw gcd, exact if_pos rfl }\n\n@[simp] theorem gcd_zero_right (a : R) : gcd a 0 = a :=\nby { rw gcd, split_ifs; simp only [h, zero_mod, gcd_zero_left] }\n\ntheorem gcd_val (a b : R) : gcd a b = gcd (b % a) a :=\nby { rw gcd, split_ifs; [simp only [h, mod_zero, gcd_zero_right], refl]}\n\ntheorem gcd_dvd (a b : R) : gcd a b ∣ a ∧ gcd a b ∣ b :=\ngcd.induction a b\n  (λ b, by { rw gcd_zero_left, exact ⟨dvd_zero _, dvd_rfl⟩ })\n  (λ a b aneq ⟨IH₁, IH₂⟩, by { rw gcd_val,\n    exact ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩ })\n\ntheorem gcd_dvd_left (a b : R) : gcd a b ∣ a := (gcd_dvd a b).left\n\ntheorem gcd_dvd_right (a b : R) : gcd a b ∣ b := (gcd_dvd a b).right\n\nprotected theorem gcd_eq_zero_iff {a b : R} :\n  gcd a b = 0 ↔ a = 0 ∧ b = 0 :=\n⟨λ h, by simpa [h] using gcd_dvd a b,\n by { rintro ⟨rfl, rfl⟩, exact gcd_zero_right _ }⟩\n\ntheorem dvd_gcd {a b c : R} : c ∣ a → c ∣ b → c ∣ gcd a b :=\ngcd.induction a b\n  (λ _ _ H, by simpa only [gcd_zero_left] using H)\n  (λ 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 : R} : gcd a b = a ↔ a ∣ b :=\n⟨λ h, by {rw ← h, apply gcd_dvd_right },\n λ h, by rw [gcd_val, mod_eq_zero.2 h, gcd_zero_left]⟩\n\n@[simp] theorem gcd_one_left (a : R) : gcd 1 a = 1 :=\ngcd_eq_left.2 (one_dvd _)\n\n@[simp] theorem gcd_self (a : R) : gcd a a = a :=\ngcd_eq_left.2 dvd_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 → R → R → R → R → R → R × R × R\n| r := λ s t r' s' t',\nif hr : r = 0 then (r', s', t')\n  else\n  have r' % r ≺ 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 := λ _ _, `[exact ⟨_, r_well_founded⟩]}\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 ≠ 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 × 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\n@[simp] theorem xgcd_aux_fst (x y : R) : ∀ 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(λ x y h IH s t s' t', by { simp only [xgcd_aux_rec h, if_neg h, IH], rw ← gcd_val })\n\ntheorem xgcd_aux_val (x y : R) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=\nby rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1, prod.mk.eta]\n\ntheorem xgcd_val (x y : R) : xgcd x y = (gcd_a x y, gcd_b x y) :=\nprod.mk.eta.symm\n\nprivate def P (a b : R) : R × R × R → Prop | (r, s, t) := (r : R) = a * s + b * t\n\ntheorem xgcd_aux_P (a b : R) {r r' : R} : ∀ {s t s' t'}, P a b (r, s, t) →\n  P a b (r', s', t') → P a b (xgcd_aux r s t r' s' t') :=\ngcd.induction r r' (by { intros, simpa only [xgcd_zero_left] }) $ λ 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' ⊢,\n  rw [mul_sub, mul_sub, add_sub, sub_add_eq_add_sub, ← p', sub_sub,\n    mul_comm _ s, ← mul_assoc, mul_comm _ t, ← mul_assoc, ← add_mul, ← p,\n    mod_eq_sub_mul_div]\nend\n\n/-- An explicit version of **Bézout's lemma** for Euclidean domains. -/\ntheorem gcd_eq_gcd_ab (a b : R) : (gcd a b : R) = 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\n@[priority 70] -- see Note [lower instance priority]\ninstance (R : Type*) [e : euclidean_domain R] : is_domain R :=\nby { haveI := classical.dec_eq R, exact\n{ eq_zero_or_eq_zero_of_mul_eq_zero :=\n    λ a b h, (or_iff_not_and_not.2 $ λ h0,\n      h0.1 $ by rw [← mul_div_cancel a h0.2, h, zero_div]),\n  ..e }}\n\nend gcd\n\nsection lcm\nvariables [decidable_eq R]\n\n/-- `lcm a b` is a (non-unique) element such that `a ∣ lcm a b` `b ∣ lcm a b`, and for\n  any element `c` such that `a ∣ c` and `b ∣ c`, then `lcm a b ∣ c` -/\ndef lcm (x y : R) : R :=\nx * y / gcd x y\n\ntheorem dvd_lcm_left (x y : R) : x ∣ lcm x y :=\nclassical.by_cases\n  (assume hxy : gcd x y = 0, by { rw [lcm, hxy, div_zero], exact dvd_zero _ })\n  (λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).2 in ⟨z, eq.symm $ eq_div_of_mul_eq_left hxy $\n    by rw [mul_right_comm, mul_assoc, ← hz]⟩)\n\ntheorem dvd_lcm_right (x y : R) : y ∣ lcm x y :=\nclassical.by_cases\n  (assume hxy : gcd x y = 0, by { rw [lcm, hxy, div_zero], exact dvd_zero _ })\n  (λ hxy, let ⟨z, hz⟩ := (gcd_dvd x y).1 in ⟨z, eq.symm $ eq_div_of_mul_eq_right hxy $\n    by rw [← mul_assoc, mul_right_comm, ← hz]⟩)\n\ntheorem lcm_dvd {x y z : R} (hxz : x ∣ z) (hyz : y ∣ z) : lcm x y ∣ 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 ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,\n  suffices : x * y ∣ z * gcd x y,\n  { cases this with p hp, use p,\n    generalize_hyp : gcd x y = g at hxy hs hp ⊢, subst hs,\n    rw [mul_left_comm, mul_div_cancel_left _ hxy, ← mul_left_inj' hxy, hp],\n    rw [← 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 _ (hyz.mul_right _) },\n  { rw [mul_left_comm, mul_comm], exact mul_dvd_mul_left _ (hxz.mul_right _) }\nend\n\n@[simp] lemma lcm_dvd_iff {x y z : R} : lcm x y ∣ z ↔ x ∣ z ∧ y ∣ z :=\n⟨λ hz, ⟨(dvd_lcm_left _ _).trans hz, (dvd_lcm_right _ _).trans hz⟩,\nλ ⟨hxz, hyz⟩, lcm_dvd hxz hyz⟩\n\n@[simp] lemma lcm_zero_left (x : R) : lcm 0 x = 0 :=\nby rw [lcm, zero_mul, zero_div]\n\n@[simp] lemma lcm_zero_right (x : R) : lcm x 0 = 0 :=\nby rw [lcm, mul_zero, zero_div]\n\n@[simp] lemma lcm_eq_zero_iff {x y : R} : lcm x y = 0 ↔ x = 0 ∨ 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 ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,\n      generalize_hyp : gcd x y = g at hr hs hy hgxy ⊢, 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 : R) : 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 ⟨⟨r, hr⟩, ⟨s, hs⟩⟩,\n  generalize_hyp : gcd x y = g at h hr ⊢, subst hr,\n  rw [mul_assoc, mul_div_cancel_left _ h]\nend\n\nend lcm\n\nsection div\n\nlemma mul_div_mul_cancel {a b c : R} (ha : a ≠ 0) (hcb : c ∣ b) :\n  a * b / (a * c) = b / c :=\nbegin\n  by_cases hc : c = 0, { simp [hc] },\n  refine eq_div_of_mul_eq_right hc (mul_left_cancel₀ ha _),\n  rw [← mul_assoc, ← mul_div_assoc _ (mul_dvd_mul_left a hcb),\n         mul_div_cancel_left _ (mul_ne_zero ha hc)]\nend\n\nend div\n\nend euclidean_domain\n\ninstance int.euclidean_domain : euclidean_domain ℤ :=\n{ add := (+),\n  mul := (*),\n  one := 1,\n  zero := 0,\n  neg := has_neg.neg,\n  quotient := (/),\n  quotient_zero := int.div_zero,\n  remainder := (%),\n  quotient_mul_add_remainder_eq := λ a b, int.div_add_mod _ _,\n  r := λ a b, a.nat_abs < b.nat_abs,\n  r_well_founded := measure_wf (λ a, int.nat_abs a),\n  remainder_lt := λ a b b0, int.coe_nat_lt.1 $\n    by { rw [int.nat_abs_of_nonneg (int.mod_nonneg _ b0), ← int.abs_eq_nat_abs],\n      exact int.mod_lt _ b0 },\n  mul_left_not_lt := λ a b b0, not_lt_of_ge $\n    by {rw [← 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  .. int.comm_ring,\n  .. int.nontrivial }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance field.to_euclidean_domain {K : Type u} [field K] : euclidean_domain K :=\n{ add := (+),\n  mul := (*),\n  one := 1,\n  zero := 0,\n  neg := has_neg.neg,\n  quotient := (/),\n  remainder := λ a b, a - a * b / b,\n  quotient_zero := div_zero,\n  quotient_mul_add_remainder_eq := λ a b,\n    by { classical, by_cases b = 0; simp [h, mul_div_cancel'] },\n  r := λ a b, a = 0 ∧ b ≠ 0,\n  r_well_founded := well_founded.intro $ λ a, acc.intro _ $ λ b ⟨hb, hna⟩,\n    acc.intro _ $ λ c ⟨hc, hnb⟩, false.elim $ hnb hb,\n  remainder_lt := λ a b hnb, by simp [hnb],\n  mul_left_not_lt := λ a b hnb ⟨hab, hna⟩, or.cases_on (mul_eq_zero.1 hab) hna hnb,\n  .. ‹field K› }\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/euclidean_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7760332807903064}}
{"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# The real numbers in Lean\n\nLean has a copy of of the real numbers. It's called `real`, \nbut we use the usual notation `ℝ`. Put your cursor on the `ℝ` to find\nout how to type it in VS Code.\n\nIn this sheet you will prove some basic equalities and inequalities\nbetween \"numerical expressions\" in Lean. A numeral is something like `37`,\nand a numerical expression is something like `(37 + 6) / 4`. To make\nthings a bit harder, I will throw in some `∃` statements. To make\nprogress on an `∃` goal, use the `use` tactic.\n\n## Tactics\n\nNew tactics you'll need to know about:\n\n* `norm_num` (proves equalities and inequalities involving numerical expressions)\n* `use` (if the goal is `∃ x, x + 37 = 42` then `use 8` will change the goal\n*        to `8 + 37 = 42`, and `use 10` will change it to `10 + 37 = 42`.\n\n-/\n\nexample : (2 : ℝ) + 2 = 4 :=\nbegin\n  norm_num,\nend\n\nexample : (2 : ℝ) + 2 ≠ 5 :=\nbegin\n  norm_num,\nend\n\nexample : (2 : ℝ) + 2 < 5 :=\nbegin\n  norm_num,\nend\n\nexample : ∃ (x : ℝ), 3 * x + 7 = 12 :=\nbegin\n  use 5/3,\n  norm_num,\nend\n\nexample : ∃ (x : ℝ), 3 * x + 7 ≠ 12 :=\nbegin\n  use 0,\n  norm_num,\nend\n\nexample : ∃ (x y : ℝ), 2 * x + 3 * y = 7 ∧ x + 2 * y = 4 :=\nbegin\n  use [2, 1],\n  norm_num,\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/section02reals/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454896, "lm_q2_score": 0.8152324983301568, "lm_q1q2_score": 0.775989842604097}}
{"text": "-- Suma_de_desigualdades.lean\n-- Suma de desigualdades\n-- José A. Alonso Jiménez\n-- Sevilla, 22 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar si a, b, c y d son números reales tales que\n-- a ≤ b y c ≤ d, entonces a + c ≤ b + d.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables (a b c d : ℝ)\n\n-- 1ª demostración\n-- ===============\n\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nbegin\n  calc\n    a + c ≤ b + c : add_le_add_right hab c\n    ...   ≤ b + d : add_le_add_left hcd b,\nend\n\n-- 2ª demostración\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nbegin\n  have h1 : a + c ≤ b + c := \n    add_le_add_right hab c,\n  have h2 : b + c ≤ b + d :=\n    add_le_add_left hcd b,\n  show a + c ≤ b + d, \n    from le_trans h1 h2,\nend\n\n-- Comentario: Se ha usado el lema\n-- + le_trans: a ≤ b → b ≤ c → a ≤ c\n\n-- 3ª demostración\n-- ===============\n\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nadd_le_add hab hcd\n\n-- Comentario: Se ha usado el lema\n-- + add_le_add : a ≤ b → c ≤ d → a + c ≤ b + d \n\n-- 4ª demostración\n-- ===============\n\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nby linarith\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/Suma_de_desigualdades.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7759852442989504}}
{"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 ℕ\n\nThis file identifies a few functions on `ℕ` 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 : ℕ) : periodic (gcd a) a :=\nby simp only [forall_const, gcd_add_self_right, eq_self_iff_true, periodic]\n\nlemma periodic_coprime (a : ℕ) : periodic (coprime a) a :=\nby simp only [coprime_add_self_right, forall_const, iff_self, eq_iff_iff, periodic]\n\nlemma periodic_mod (a : ℕ) : periodic (λ 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 {α : Type*} {f : ℕ → α} {a : ℕ} (hf : periodic f a) :\n  ∀ n, f (n % a) = f n :=\nλ n, by conv_rhs { rw [← nat.mod_add_div n a, mul_comm, ← 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 : ℕ) (p : ℕ → 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_coe,\n    ←multiset_Ico_map_mod n, ←map_count_true_eq_filter_card, ←map_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 : ℕ) (p : ℕ → 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": "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/periodic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7759803691170386}}
{"text": "import 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' {α : Type*} [discrete_field α] (a : α) (n : ℕ) : (a ^ n)⁻¹ = a⁻¹ ^ n :=\nby induction n; simp [_root_.pow_succ, *, mul_inv', mul_comm]\n\nlemma pow_incrs_of_gt_one {α : Type*}  [linear_ordered_semiring α] {x : α} {n m : ℕ} \n  (h1x : 1 < x) (hnm : n < m) : x ^ n < x ^ m := \nbegin\n  rw [← nat.sub_add_cancel hnm, _root_.pow_add, _root_.pow_succ, ← mul_assoc],\n  refine (lt_mul_iff_one_lt_left (pow_pos (lt_trans (by norm_num) h1x) _)).2 _,\n  rw ← one_mul (1 : α),\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 {α : Type*} [discrete_linear_ordered_field α] {x : α} {n m : ℕ}\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 {α : Type*} [add_comm_monoid α] (f : ℕ → α) : \n  (range 0).sum f = 0 := rfl\n\nlemma sum_range_succ {α : Type*} [add_comm_monoid α] (f : ℕ → α) (n : ℕ) :\n  (range (succ n)).sum f = f n + (range n).sum f := by simp\n\nlemma sum_range_succ' {α : Type*} [add_comm_monoid α] (f : ℕ → α) : \n  ∀ n : ℕ, (range (nat.succ n)).sum f = (range n).sum (f ∘ nat.succ) + f 0\n| 0       := by simp\n| (n + 1) := by rw [sum_range_succ (λ m, f (nat.succ m)), add_assoc, ← sum_range_succ'];\n  exact sum_range_succ _ _\n\n/-- The binomial theorem -/\ntheorem add_pow {α : Type*} [comm_semiring α] (x y : α) : ∀ n : ℕ,\n    (x + y) ^ n = (range (succ n)).sum (λ m, x ^ m * y ^ (n - m) * choose n m)\n| 0        := by simp\n| (succ n) :=\nhave h₁ : 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₂ : 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₃ : (range n).sum (λ 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 (λ m, x ^ succ m * y ^ (succ n - succ m) * ↑(choose (succ n) (succ m))),\n  from finset.sum_congr rfl $ λ 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 [← _root_.pow_succ', add_one, ← 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, ← add_assoc ((range n).sum _), \n    ← finset.sum_add_distrib, h₁, h₂, h₃]\n\nlemma geo_series_eq {α : Type*} [field α] {x : α} (n : ℕ) (hx1 : x ≠ 1) : \n  (range n).sum (λ m, x ^ m) = (1 - x ^ n) / (1 - x) :=\nhave 1 - x ≠ 0 := mt sub_eq_zero_iff_eq.1 hx1.symm, \nbegin\n  induction n with n ih,\n  { simp },\n  { rw [sum_range_succ, ← mul_div_cancel (x ^ n) this, ih, ← add_div, _root_.pow_succ],\n    refine congr_fun (congr_arg _ _) _,\n    ring }\nend\n\nvariables {α : Type*} {β : Type*} \n  [discrete_linear_ordered_field α] [archimedean α] {abv : β → α}\n\nlemma forall_ge_le_of_forall_le_succ {α : Type*} [preorder α] (f : ℕ → α) {m : ℕ}\n  (h : ∀ n ≥ m, f (succ n) ≤ f n) : ∀ l, ∀ k ≥ m, k ≤ l → f l ≤ f k :=\nbegin\n  assume l k hkm hkl,\n  generalize hp : l - k = p,\n  have : l = k + p := add_comm p k ▸ (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 {α : Type*} [discrete_linear_ordered_field α] \n  [archimedean α] (f : ℕ → α) \n  {a : α} {m : ℕ} (ham : ∀ n ≥ m, abs (f n) ≤ a) \n  (hnm : ∀ n ≥ m, f (succ n) ≤ f n) : is_cau_seq abs f := \nλ ε ε0, \nlet ⟨k, hk⟩ := archimedean.arch a ε0 in\nhave h : ∃ l, ∀ n ≥ m, a - add_monoid.smul l ε < f n :=\n  ⟨k + k + 1, λ n hnm, lt_of_lt_of_le \n    (show a - add_monoid.smul (k + (k + 1)) ε < -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 _ ε0)),\n      end))\n    (neg_le.2 $ (abs_neg (f n)) ▸ le_abs_self _)⟩,\nlet l := nat.find h in\nhave hl : ∀ (n : ℕ), n ≥ m → f n > a - add_monoid.smul l ε := nat.find_spec h,\nhave hl0 : l ≠ 0 := λ 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 ≤ 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 ≤ a - add_monoid.smul (pred l) ε : hi.2\n    ... = a - add_monoid.smul l ε + ε : \n      by conv {to_rhs, rw [← succ_pred_eq_of_pos (nat.pos_of_ne_zero hl0), succ_smul',\n        sub_add, add_sub_cancel] }\n    ... < f j + ε : add_lt_add_right (hl j (le_trans hi.1 hj)) _\nend\n\nlemma is_cau_of_incrs_bounded {α : Type*} [discrete_linear_ordered_field α] \n  [archimedean α] (f : ℕ → α) \n  {a : α} {m : ℕ} (ham : ∀ n ≥ m, abs (f n) ≤ a) \n  (hnm : ∀ n ≥ m, f n ≤ f (succ n)) : is_cau_seq abs f :=\nbegin\n  refine @eq.rec_on (ℕ → α) _ (is_cau_seq abs) _ _\n    (-⟨_, @is_cau_of_dcrs_bounded _ _ _ (λ n, -f n) a m (by simpa) (by simpa)⟩ : cau_seq α abs).2,\n  ext,\n  exact neg_neg _\nend\n\nlemma series_cau_of_abv_le_cau {α : Type*} {β : Type*} [discrete_linear_ordered_field α] [ring β] {f : ℕ → β}\n    {g : ℕ → α} {abv : β → α} [is_absolute_value abv] (n : ℕ) : (∀ m, n ≤ m → abv (f m) ≤ g m) → \n    is_cau_seq abs (λ n, (range n).sum g) → is_cau_seq abv (λ n, (range n).sum f) := begin\n  assume hm hg ε ε0,cases hg (ε / 2) (div_pos ε0 (by norm_num)) with i hi,\n  existsi max n i,\n  assume j ji,\n  have hi₁ := hi j (le_trans (le_max_right n i) ji),\n  have hi₂ := 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₁ hi₂,\n  rw abs_sub ((range (max n i)).sum g) at this,\n  rw add_halves ε 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₂ hi₁ hi ε0 ε 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 {α β : Type*} [discrete_linear_ordered_field α] [domain β] (abv : β → α) [is_absolute_value abv]\n  (a : β) (n : ℕ) : 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 {α : Type*} {β : Type*} [discrete_linear_ordered_field α] [ring β] {abv : β → α} {f : ℕ → β} \n    [is_absolute_value abv] : is_cau_seq abs (λ m, (range m).sum (λ n, abv (f n))) → is_cau_seq abv (λ m, (range m).sum f) := \n   λ h, series_cau_of_abv_le_cau 0 (λ n h, le_refl _) h\n\nlemma geo_series_cau {α β : Type*} [discrete_linear_ordered_field α] [archimedean α] [field β]\n  {abv : β → α} [is_absolute_value abv]\n   (x : β) (hx1 : abv x < 1) : is_cau_seq abv (λ n, (range n).sum (λ m, x ^ m)) :=\nhave hx1' : abv x ≠ 1 := λ 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 : α) / (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 ▸ 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, ← one_mul (1 : α)],\n      refine mul_le_mul (le_of_lt hx1) ih (pow_abv abv x n ▸ 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 [← 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 {α : Type*} [discrete_linear_ordered_field α] [archimedean α] (a x : α) :\n  abs x < 1 → is_cau_seq abs (λ m, (range m).sum (λ n, a * x ^ n)) :=\nλ hx1, begin\n  have : is_cau_seq abs (λ m, a * (range m).sum (λ n, x ^ n)) := (cau_seq.const abs a * ⟨_, geo_series_cau x hx1⟩).2,\n  simpa only [mul_sum] using this\nend\n\n-- The form of ratio test with  0 ≤ r < 1, and abv (f (succ m)) ≤ r * abv (f m) handled zero terms of series the best\nlemma series_ratio_test {α : Type*} {β : Type*} [discrete_linear_ordered_field α] [ring β] \n    [archimedean α] {abv : β → α} [is_absolute_value abv] {f : ℕ → β} (n : ℕ) (r : α) :\n    0 ≤ r → r < 1 → (∀ m, n ≤ m → abv (f (succ m)) ≤ r * abv (f m)) → is_cau_seq abv (λ 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⁻¹ ^ (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,←pow_inv',←div_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) ≥ (succ n), rw ←zero_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),←mul_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 {α : Type*} [add_comm_monoid α] (n : ℕ) (f : ℕ → ℕ → α) : \n    (range n).sum (λ m, (range (m + 1)).sum (λ k, f k (m - k))) = \n    (range n).sum (λ m, (range (n - m)).sum (f m)) :=\nhave h₁ : ((range n).sigma (range ∘ succ)).sum\n    (λ (a : Σ m, ℕ), f (a.2) (a.1 - a.2)) = \n    (range n).sum (λ m, (range (m + 1)).sum\n    (λ k, f k (m - k))) := sum_sigma,\nhave h₂ : ((range n).sigma (λ m, range (n - m))).sum (λ a : Σ (m : ℕ), ℕ, f (a.1) (a.2)) =\n    (range n).sum (λ m, sum (range (n - m)) (f m)) := sum_sigma,\nh₁ ▸ h₂ ▸ sum_bij \n(λ a _, ⟨a.2, a.1 - a.2⟩)\n(λ a ha, have h₁ : a.1 < n := mem_range.1 (mem_sigma.1 ha).1,\n  have h₂ : a.2 < succ a.1 := mem_range.1 (mem_sigma.1 ha).2,\n    mem_sigma.2 ⟨mem_range.2 (lt_of_lt_of_le h₂ h₁), \n    mem_range.2 ((nat.sub_lt_sub_right_iff (le_of_lt_succ h₂)).2 h₁)⟩) \n(λ _ _, rfl) \n(λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ ha hb h,\n  have ha : a₁ < n ∧ a₂ ≤ a₁ := \n      ⟨mem_range.1 (mem_sigma.1 ha).1, le_of_lt_succ (mem_range.1 (mem_sigma.1 ha).2)⟩,\n  have hb : b₁ < n ∧ b₂ ≤ b₁ :=\n      ⟨mem_range.1 (mem_sigma.1 hb).1, le_of_lt_succ (mem_range.1 (mem_sigma.1 hb).2)⟩,\n  have h : a₂ = b₂ ∧ _ := sigma.mk.inj h,\n  have h' : a₁ = b₁ - b₂ + a₂ := (nat.sub_eq_iff_eq_add ha.2).1 (eq_of_heq h.2),\n  sigma.mk.inj_iff.2  \n    ⟨nat.sub_add_cancel hb.2 ▸ h'.symm ▸ h.1 ▸ rfl, \n    (heq_of_eq h.1)⟩)\n(λ ⟨a₁, a₂⟩ ha,\n  have ha : a₁ < n ∧ a₂ < n - a₁ := \n      ⟨mem_range.1 (mem_sigma.1 ha).1, (mem_range.1 (mem_sigma.1 ha).2)⟩,\n  ⟨⟨a₂ + a₁, a₁⟩, ⟨mem_sigma.2 ⟨mem_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 _ _))⟩, \n  sigma.mk.inj_iff.2 ⟨rfl, heq_of_eq (nat.add_sub_cancel _ _).symm⟩⟩⟩)\n\nlemma abv_sum_le_sum_abv {α β γ : Type*} [discrete_linear_ordered_field α] [ring β]\n  (abv : β → α) [is_absolute_value abv] (f : γ → β) (s : finset γ) : abv (s.sum f) ≤ s.sum (abv ∘ f) :=\nfinset.induction_on s (by simp [abv_zero abv]) $ λ 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 {α β : Type*} [ordered_comm_monoid α] {f : β → α} {s : finset β} :\n  (∀ x ∈ s, 0 ≤ f x) → 0 ≤ s.sum f :=\nfinset.induction_on s (by simp) $ λ a s has ih h, begin\n  rw [sum_insert has],\n  exact add_nonneg' (h a (by simp)) (ih (λx hx, by simp *)),\nend\n\nlemma neg_sum {α β : Type*} [add_comm_group α] {f : β → α} {s : finset β} :\n  -s.sum f = s.sum (λ x, -f x) :=\nfinset.induction_on s (by simp) (by simp {contextual := tt})\n\n@[simp] lemma filter_true {α : Type*} (s : finset α) : s.filter (λ _, true) = s :=\nfinset.ext.2 $ by simp\n\nlemma sum_range_sub_sum_range {α : Type*} [add_comm_group α] {f : ℕ → α} \n  {n m : ℕ} (hnm : n ≤ m) : (range m).sum f - (range n).sum f = \n  ((range m).filter (λ k, n ≤ k)).sum f :=\nbegin\n  rw [← sum_sdiff (@filter_subset _ (λ k, n ≤ k) _ (range m)),\n    sub_eq_iff_eq_add, ← eq_sub_iff_add_eq, add_sub_cancel'],\n  refine finset.sum_congr \n    (finset.ext.2 $ λ a, ⟨λ h, by simp at *; finish,\n    λ h, have ham : a < m := lt_of_lt_of_le (mem_range.1 h) hnm, \n      by simp * at *⟩)\n    (λ _ _, rfl),\nend\n\nlemma series_cauchy_prod {α β : Type*} [discrete_linear_ordered_field α] [ring β] {a b : ℕ → β}\n  {abv : β → α} [is_absolute_value abv] : is_cau_seq abs (λ m, (range m).sum (λ n, abv (a n))) → is_cau_seq abv (λ m, (range m).sum b) → \n  ∀ ε : α, 0 < ε → ∃ i : ℕ, ∀ j ≥ i, abv ((range j).sum a * (range j).sum b - (range j).sum (λ n, \n  (range (n + 1)).sum (λ m, a m * b (n - m))) ) < ε :=\nbegin\n-- slightly adapted version of theorem 9.4.7 from \"The Real Numbers and Real Analysis\", Ethan D. Bloch\n  assume ha hb ε ε0,\n  cases cau_seq.bounded ⟨_, hb⟩ with Q hQ,simp at hQ,\n  cases cau_seq.bounded ⟨_, ha⟩ with P hP,simp at hP,\n  have P0 : 0 < P,exact lt_of_le_of_lt (abs_nonneg _) (hP 0),\n  have Pε0 := div_pos ε0 (mul_pos (show (2 : α) > 0, from by norm_num) P0),\n  cases cau_seq.cauchy₂ ⟨_, hb⟩ Pε0 with N hN,simp at hN,\n  have Qε0 := div_pos ε0 (mul_pos (show (4 : α) > 0, from by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))),\n  cases cau_seq.cauchy₂ ⟨_, ha⟩ Qε0 with M hM,simp at hM,\n  existsi 2 * (max N M + 1),\n  assume K hK,\n  have := sum_range_diag_flip K (λ m n, a m * b n),\n  dsimp at this,\n  rw this,\n  have : (λ (i : ℕ), (range (K - i)).sum (λ (k : ℕ), a i * b k)) = (λ (i : ℕ), a i * (range (K - i)).sum b),\n    by simp [finset.mul_sum],\n  rw this,clear this,\n  have : (range K).sum (λ (i : ℕ), a i * (range (K - i)).sum b) = \n    (range K).sum (λ (i : ℕ), a i * ((range (K - i)).sum b - (range K).sum b))\n    + (range K).sum (λ i, a i * (range K).sum b),\n    {rw ←sum_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 (λ (i : ℕ), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) +\n    ((range K).sum (λ (i : ℕ), abv (a i) * abv ((range (K - i)).sum b - (range K).sum b)) -(range (max N M + 1)).sum\n     (λ (i : ℕ), \n    abv (a i) * abv ((range (K - i)).sum b - (range K).sum b))) < ε / (2 * P) * P + ε / (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 : α) = 2 * 2),←div_div_eq_div_mul,mul_comm (2 : α),←_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 (λ (i : ℕ), abv (a i) * \n    abv ((range (K - i)).sum b - (range K).sum b)) ≤ (range (max N M + 1)).sum\n  (λ (i : ℕ), abv (a i) * (ε / (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 ←_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 [← sum_mul, mul_comm],\n  specialize hP (max N M + 1),rwa abs_of_nonneg at hP,\n  exact (mul_lt_mul_left Pε0).mpr hP,\n  exact sum_nonneg (λ 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,←add_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 (λ (k : ℕ), max N M + 1 ≤ k) (range K))\n      (λ (i : ℕ), abv (a i) * abv (sum (range (K - i)) b - sum (range K) b))\n      ≤ sum (filter (λ (k : ℕ), max N M + 1 ≤ k) (range K)) (λ 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 [← sum_mul, ← 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 : ℂ) : is_cau_seq abs (λ n, (range n).sum (λ m, complex.abs (z ^ m / fact m))) := begin\n  cases exists_nat_gt (complex.abs z) with n hn,\n  have n_pos : (0 : ℝ) < 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 ↑(fact m))⁻¹ * (complex.abs ↑(succ m))⁻¹) = complex.abs z * \n    complex.abs (z ^ m) * (complex.abs ↑(fact m))⁻¹ * (complex.abs ↑(succ m))⁻¹,ring,rw this,\n  have : complex.abs z * (↑n)⁻¹ * (complex.abs (z ^ m) * (complex.abs ↑(fact m))⁻¹) = complex.abs z * complex.abs (z ^ m) * (complex.abs ↑(fact m))⁻¹ * (↑n)⁻¹,ring,\n  rw this,\n  rw[(by simp : (succ m : ℂ) = ((succ m : ℝ) : ℂ)),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 [←nat.cast_zero,nat.cast_lt],exact succ_pos _,exact n_pos,rw[←complex.abs_inv,←complex.abs_mul,←complex.abs_mul],\n  exact complex.abs_nonneg _,rw[←nat.cast_zero,nat.cast_le],exact zero_le _,\nend\n\nlemma complex.exp_series_cau (z : ℂ) : is_cau_seq complex.abs (λ n, (range n).sum (λ m, z ^ m / fact m)) := \n  series_cau_of_abv_cau (complex.exp_series_abs_cau z)\n\ndef exp' (z : ℂ) : cau_seq ℂ complex.abs := ⟨_, complex.exp_series_cau z⟩\n\nopen complex\ndef exp (z : ℂ) : ℂ := complex.lim (exp' z)\n\ndef sin (z : ℂ) : ℂ := (exp (I * z) - exp (-I * z)) / (2 * I)\n\ndef cos (z : ℂ) : ℂ := (exp (I * z) + exp (-I * z)) / 2\n\ndef tan (z : ℂ) : ℂ := sin z / cos z\n\ndef sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2\n\ndef cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2\n\ndef tanh (z : ℂ) : ℂ := 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 ε ε0,\n  existsi 1,\n  assume j hj,\n  dsimp [exp'],\n  suffices : complex.abs (sum (range j) (λ (m : ℕ), 0 ^ m / ↑(fact m)) + -1) = 0,\n    rwa this,\n  cases j,\n  { exact absurd hj (by norm_num) },\n  { induction j,\n    { simpa },\n    { rw ← j_ih dec_trivial,\n      simp only [sum_range_succ, _root_.pow_succ],\n      simp } }\nend\n\nlemma exp_add (x y : ℂ) : exp (x + y) = exp x * exp y := \nshow complex.lim (⟨_, complex.exp_series_cau (x + y)⟩ : cau_seq ℂ abs) = \n  complex.lim ⇑(show cau_seq ℂ abs, from ⟨_, complex.exp_series_cau x⟩)\n  * complex.lim (show cau_seq ℂ abs, from ⟨_, complex.exp_series_cau y⟩),\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 : ∀ j : ℕ, (range j).sum (λ (m : ℕ),\n    (x + y) ^ m / ↑(fact m)) = (range j).sum \n    (λ i, (range (i + 1)).sum (λ k, x ^ k / fact k *\n    (y ^ (i - k) / fact (i - k)))),\n    { assume j,\n      refine finset.sum_congr rfl (λ m hm, _),\n      rw [add_pow, div_eq_mul_inv, sum_mul],\n      refine finset.sum_congr rfl (λ i hi, _),\n      have := choose_mul_fact_mul_fact (le_of_lt_succ $ finset.mem_range.1 hi),\n      rw [← this, nat.cast_mul, nat.cast_mul, mul_inv', mul_inv'],\n      simp only [mul_left_comm (choose m i : ℂ), mul_assoc, mul_left_comm (choose m i : ℂ)⁻¹,\n        mul_comm (choose m i : ℂ)],\n      have : (choose m i : ℂ) ≠ 0 := nat.cast_ne_zero.2 (λ 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 ε ε0,\n  dsimp,\n  simp only [hj],\n  exact this ε ε0,\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/chris_hughes_various/exponential/exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505273888291, "lm_q2_score": 0.8577681049901036, "lm_q1q2_score": 0.7759803685566138}}
{"text": "import data.real.basic\n\nvariables {x y : ℝ}\n\n#check le_refl\n#check le_refl y\n#check @le_abs \n#check @abs_le\n#check neg_add\n#check add_le_add\n\nnamespace my_abs\n\n-- BEGIN\ntheorem le_abs_self : x ≤ abs x :=\nbegin\n  rw le_abs,\n  left,\n  apply le_refl,\nend\n\ntheorem neg_le_abs_self : -x ≤ abs x :=\nbegin\n  rw le_abs,\n  right,\n  apply le_refl,\nend\n\n/- Alternatively -/\n\nlemma neg_abs_le_self : - abs x ≤ x :=\nbegin\n  nth_rewrite_rhs 0 ← neg_neg x,\n  apply neg_le_neg,\n  exact neg_le_abs_self,\nend\n\ntheorem abs_add : abs (x + y) ≤ abs x + abs y :=\nbegin\n  cases lt_or_le x 0 with hx hx;\n  cases lt_or_le y 0 with hy hy;\n  cases lt_or_le (x + y) 0 with hxy hxy;\n  simp [abs_of_neg, abs_of_nonneg, hx, hy, hxy];\n  linarith,\nend\n\n/- Essentially the same as the previous one, but we no longer need \nthe lemma `neg_abs_le_self`. -/\nexample : abs (x + y) ≤ abs x + abs y :=\nbegin\n  rw abs_eq_max_neg,\n  rw max_le_iff,\n  split,\n  { apply add_le_add,\n    exact le_abs_self,\n    exact le_abs_self, },\n  { rw neg_add,\n    apply add_le_add,\n    exact neg_le_abs_self,\n    exact neg_le_abs_self, },\nend\n\n-- END\n\n#check @le_abs_self\n#check @neg_le_abs_self\n#check @abs_add\n\nend my_abs", "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/ex18_rw_inequal_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.8376199714402813, "lm_q1q2_score": 0.7758904990015341}}
{"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 302eab4f46abb63de520828de78c04cb0f9b5836\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.ENat.Basic\nimport Mathlib.Data.Polynomial.Degree.Definitions\n\n/-!\n# Trailing degree of univariate polynomials\n\n## Main definitions\n\n* `trailingDegree p`: the multiplicity of `X` in the polynomial `p`\n* `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers\n* `trailingCoeff`: the coefficient at index `natTrailingDegree p`\n\nConverts most results about `degree`, `natDegree` and `leadingCoeff` 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 : ℕ}\n\nsection Semiring\n\nvariable [Semiring R] {p q r : R[X]}\n\n/-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest\n`X`-exponent in `p`.\n`trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailingDegree 0 = ⊤`. -/\ndef trailingDegree (p : R[X]) : ℕ∞ :=\n  p.support.min\n#align polynomial.trailing_degree Polynomial.trailingDegree\n\ntheorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q :=\n  InvImage.wf trailingDegree (WithTop.wellFounded_lt Nat.lt_wfRel.2)\n#align polynomial.trailing_degree_lt_wf Polynomial.trailingDegree_lt_wf\n\n/-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining\n`natTrailingDegree ⊤ = 0`. -/\ndef natTrailingDegree (p : R[X]) : ℕ :=\n  (trailingDegree p).getD 0\n#align polynomial.nat_trailing_degree Polynomial.natTrailingDegree\n\n/-- `trailingCoeff 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/-- 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\ntheorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 :=\n  Iff.rfl\n#align polynomial.trailing_monic.def Polynomial.TrailingMonic.def\n\n-- Porting note: Removed unused argument `[DecidableEq R]`?\ninstance TrailingMonic.decidable: Decidable (TrailingMonic p) := inferInstance\n#align polynomial.trailing_monic.decidable Polynomial.TrailingMonic.decidable\n\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@[simp]\ntheorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ :=\n  rfl\n#align polynomial.trailing_degree_zero Polynomial.trailingDegree_zero\n\n@[simp]\ntheorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.trailing_coeff_zero Polynomial.trailingCoeff_zero\n\n@[simp]\ntheorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 :=\n  rfl\n#align polynomial.nat_trailing_degree_zero Polynomial.natTrailingDegree_zero\n\ntheorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 :=\n  ⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩\n#align polynomial.trailing_degree_eq_top Polynomial.trailingDegree_eq_top\n\ntheorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) :\n    trailingDegree p = (natTrailingDegree p : ℕ∞) := by\n  let ⟨n, hn⟩ :=\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 [natTrailingDegree, hn]\n  rfl\n#align polynomial.trailing_degree_eq_nat_trailing_degree Polynomial.trailingDegree_eq_natTrailingDegree\n\ntheorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :\n    p.trailingDegree = n ↔ p.natTrailingDegree = n := by\n  rw [trailingDegree_eq_natTrailingDegree hp]\n  exact WithTop.coe_eq_coe\n#align polynomial.trailing_degree_eq_iff_nat_trailing_degree_eq Polynomial.trailingDegree_eq_iff_natTrailingDegree_eq\n\ntheorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :\n    p.trailingDegree = n ↔ p.natTrailingDegree = n := by\n  constructor\n  · intro H\n    rwa [← trailingDegree_eq_iff_natTrailingDegree_eq]\n    rintro rfl\n    rw [trailingDegree_zero] at H\n    exact Option.noConfusion H\n  · intro H\n    rwa [trailingDegree_eq_iff_natTrailingDegree_eq]\n    rintro rfl\n    rw [natTrailingDegree_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\ntheorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ}\n    (h : trailingDegree p = n) : natTrailingDegree p = n :=\n  have hp0 : p ≠ 0 := fun hp0 => by rw [hp0] at h; exact Option.noConfusion h\n  Option.some_inj.1 <|\n    show (natTrailingDegree p : ℕ∞) = n by rwa [← trailingDegree_eq_natTrailingDegree hp0]\n#align polynomial.nat_trailing_degree_eq_of_trailing_degree_eq_some Polynomial.natTrailingDegree_eq_of_trailingDegree_eq_some\n\n@[simp]\ntheorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p := by\n  by_cases hp : p = 0;\n  · rw [hp, trailingDegree_zero]\n    exact le_top\n  rw [trailingDegree_eq_natTrailingDegree hp]\n#align polynomial.nat_trailing_degree_le_trailing_degree Polynomial.natTrailingDegree_le_trailingDegree\n\ntheorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]}\n    (h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by\n  unfold natTrailingDegree\n  rw [h]\n#align polynomial.nat_trailing_degree_eq_of_trailing_degree_eq Polynomial.natTrailingDegree_eq_of_trailingDegree_eq\n\ntheorem le_trailingDegree_of_ne_zero (h : coeff p n ≠ 0) : trailingDegree p ≤ n :=\n  show @LE.le ℕ∞ _ 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\ntheorem natTrailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : natTrailingDegree p ≤ n := by\n  have : WithTop.some (natTrailingDegree p) = Nat.cast (natTrailingDegree p) := rfl\n  rw [← WithTop.coe_le_coe, this, ← trailingDegree_eq_natTrailingDegree]\n  · exact le_trailingDegree_of_ne_zero h\n  · 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\ntheorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) ≠ 0) :\n    trailingDegree q ≤ trailingDegree p := by\n  by_cases hp : p = 0\n  · rw [hp]\n    exact le_top\n  · rw [trailingDegree_eq_natTrailingDegree hp]\n    exact le_trailingDegree_of_ne_zero h\n#align polynomial.trailing_degree_le_trailing_degree Polynomial.trailingDegree_le_trailingDegree\n\ntheorem trailingDegree_ne_of_natTrailingDegree_ne {n : ℕ} :\n    p.natTrailingDegree ≠ n → trailingDegree p ≠ n := by\n  -- Porting note: Needed to account for different coercion behaviour & add the lemma below\n  have : Nat.cast n = WithTop.some n := rfl\n  exact mt fun h => by rw [natTrailingDegree, h, this, ←WithTop.some_eq_coe, Option.getD_coe]\n#align polynomial.trailing_degree_ne_of_nat_trailing_degree_ne Polynomial.trailingDegree_ne_of_natTrailingDegree_ne\n\ntheorem natTrailingDegree_le_of_trailingDegree_le {n : ℕ} {hp : p ≠ 0}\n    (H : (n : ℕ∞) ≤ trailingDegree p) : n ≤ natTrailingDegree p := by\n  rw [trailingDegree_eq_natTrailingDegree hp] at H\n  exact WithTop.coe_le_coe.mp H\n#align polynomial.nat_trailing_degree_le_of_trailing_degree_le Polynomial.natTrailingDegree_le_of_trailingDegree_le\n\ntheorem natTrailingDegree_le_natTrailingDegree {hq : q ≠ 0}\n    (hpq : p.trailingDegree ≤ q.trailingDegree) : p.natTrailingDegree ≤ q.natTrailingDegree := by\n  by_cases hp : p = 0;\n  · rw [hp, natTrailingDegree_zero]\n    exact zero_le _\n  rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq] at hpq\n  exact WithTop.coe_le_coe.1 hpq\n#align polynomial.nat_trailing_degree_le_nat_trailing_degree Polynomial.natTrailingDegree_le_natTrailingDegree\n\n@[simp]\ntheorem trailingDegree_monomial (ha : a ≠ 0) : trailingDegree (monomial n a) = n := by\n  rw [trailingDegree, support_monomial n ha, min_singleton]\n  rfl\n#align polynomial.trailing_degree_monomial Polynomial.trailingDegree_monomial\n\ntheorem natTrailingDegree_monomial (ha : a ≠ 0) : natTrailingDegree (monomial n a) = n := by\n  rw [natTrailingDegree, trailingDegree_monomial ha]\n  rfl\n#align polynomial.nat_trailing_degree_monomial Polynomial.natTrailingDegree_monomial\n\ntheorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) ≤ 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\ntheorem le_trailingDegree_monomial : ↑n ≤ 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@[simp]\ntheorem trailingDegree_C (ha : a ≠ 0) : trailingDegree (C a) = (0 : ℕ∞) :=\n  trailingDegree_monomial ha\nset_option linter.uppercaseLean3 false in\n#align polynomial.trailing_degree_C Polynomial.trailingDegree_C\n\ntheorem le_trailingDegree_C : (0 : ℕ∞) ≤ trailingDegree (C a) :=\n  le_trailingDegree_monomial\nset_option linter.uppercaseLean3 false in\n#align polynomial.le_trailing_degree_C Polynomial.le_trailingDegree_C\n\n\n\n@[simp]\ntheorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 :=\n  nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le\nset_option linter.uppercaseLean3 false in\n#align polynomial.nat_trailing_degree_C Polynomial.natTrailingDegree_C\n\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@[simp]\ntheorem natTrailingDegree_nat_cast (n : ℕ) : natTrailingDegree (n : R[X]) = 0 := by\n  simp only [← C_eq_nat_cast, natTrailingDegree_C]\n#align polynomial.nat_trailing_degree_nat_cast Polynomial.natTrailingDegree_nat_cast\n\n@[simp]\ntheorem trailingDegree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : trailingDegree (C a * X ^ n) = n := by\n  rw [C_mul_X_pow_eq_monomial, trailingDegree_monomial ha]\nset_option linter.uppercaseLean3 false in\n#align polynomial.trailing_degree_C_mul_X_pow Polynomial.trailingDegree_C_mul_X_pow\n\ntheorem le_trailingDegree_C_mul_X_pow (n : ℕ) (a : R) : (n : ℕ∞) ≤ trailingDegree (C a * X ^ n) :=\n  by\n  rw [C_mul_X_pow_eq_monomial]\n  exact le_trailingDegree_monomial\nset_option linter.uppercaseLean3 false in\n#align polynomial.le_trailing_degree_C_mul_X_pow Polynomial.le_trailingDegree_C_mul_X_pow\n\ntheorem coeff_eq_zero_of_trailingDegree_lt (h : (n : ℕ∞) < 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\ntheorem coeff_eq_zero_of_lt_natTrailingDegree {p : R[X]} {n : ℕ} (h : n < p.natTrailingDegree) :\n    p.coeff n = 0 := by\n  apply coeff_eq_zero_of_trailingDegree_lt\n  by_cases hp : p = 0\n  · rw [hp, trailingDegree_zero]\n    exact WithTop.coe_lt_top n\n  · rw [trailingDegree_eq_natTrailingDegree hp]\n    exact WithTop.coe_lt_coe.2 h\n#align polynomial.coeff_eq_zero_of_lt_nat_trailing_degree Polynomial.coeff_eq_zero_of_lt_natTrailingDegree\n\n@[simp]\ntheorem coeff_natTrailingDegree_pred_eq_zero {p : R[X]} {hp : (0 : ℕ∞) < 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\ntheorem le_trailingDegree_X_pow (n : ℕ) : (n : ℕ∞) ≤ trailingDegree (X ^ n : R[X]) := by\n  simpa only [C_1, one_mul] using le_trailingDegree_C_mul_X_pow n (1 : R)\nset_option linter.uppercaseLean3 false in\n#align polynomial.le_trailing_degree_X_pow Polynomial.le_trailingDegree_X_pow\n\ntheorem le_trailingDegree_X : (1 : ℕ∞) ≤ trailingDegree (X : R[X]) :=\n  le_trailingDegree_monomial\nset_option linter.uppercaseLean3 false in\n#align polynomial.le_trailing_degree_X Polynomial.le_trailingDegree_X\n\ntheorem natTrailingDegree_X_le : (X : R[X]).natTrailingDegree ≤ 1 :=\n  natTrailingDegree_monomial_le\nset_option linter.uppercaseLean3 false in\n#align polynomial.nat_trailing_degree_X_le Polynomial.natTrailingDegree_X_le\n\n@[simp]\ntheorem trailingCoeff_eq_zero : trailingCoeff p = 0 ↔ p = 0 :=\n  ⟨fun h =>\n    _root_.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 ▸ leadingCoeff_zero⟩\n#align polynomial.trailing_coeff_eq_zero Polynomial.trailingCoeff_eq_zero\n\ntheorem trailingCoeff_nonzero_iff_nonzero : trailingCoeff p ≠ 0 ↔ p ≠ 0 :=\n  not_congr trailingCoeff_eq_zero\n#align polynomial.trailing_coeff_nonzero_iff_nonzero Polynomial.trailingCoeff_nonzero_iff_nonzero\n\ntheorem natTrailingDegree_mem_support_of_nonzero : p ≠ 0 → natTrailingDegree p ∈ p.support :=\n  mem_support_iff.mpr ∘ trailingCoeff_nonzero_iff_nonzero.mpr\n#align polynomial.nat_trailing_degree_mem_support_of_nonzero Polynomial.natTrailingDegree_mem_support_of_nonzero\n\ntheorem natTrailingDegree_le_of_mem_supp (a : ℕ) : a ∈ p.support → natTrailingDegree p ≤ a :=\n  natTrailingDegree_le_of_ne_zero ∘ mem_support_iff.mp\n#align polynomial.nat_trailing_degree_le_of_mem_supp Polynomial.natTrailingDegree_le_of_mem_supp\n\ntheorem natTrailingDegree_eq_support_min' (h : p ≠ 0) :\n    natTrailingDegree p = p.support.min' (nonempty_support_iff.mpr h) := by\n  apply le_antisymm\n  · apply le_min'\n    intro y hy\n    exact natTrailingDegree_le_of_mem_supp y hy\n  · apply Finset.min'_le\n    exact mem_support_iff.mpr (trailingCoeff_nonzero_iff_nonzero.mpr h)\n#align polynomial.nat_trailing_degree_eq_support_min' Polynomial.natTrailingDegree_eq_support_min'\n\ntheorem le_natTrailingDegree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) : n ≤ p.natTrailingDegree :=\n  by\n  rw [natTrailingDegree_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\ntheorem natTrailingDegree_le_natDegree (p : R[X]) : p.natTrailingDegree ≤ p.natDegree := by\n  by_cases hp : p = 0\n  · rw [hp, natDegree_zero, natTrailingDegree_zero]\n  · exact le_natDegree_of_ne_zero (mt trailingCoeff_eq_zero.mp hp)\n#align polynomial.nat_trailing_degree_le_nat_degree Polynomial.natTrailingDegree_le_natDegree\n\ntheorem natTrailingDegree_mul_X_pow {p : R[X]} (hp : p ≠ 0) (n : ℕ) :\n    (p * X ^ n).natTrailingDegree = p.natTrailingDegree + n := by\n  apply le_antisymm\n  · refine' natTrailingDegree_le_of_ne_zero fun h => mt trailingCoeff_eq_zero.mp hp _\n    rwa [trailingCoeff, ← coeff_mul_X_pow]\n  · rw [natTrailingDegree_eq_support_min' fun h => hp (mul_X_pow_eq_zero h), Finset.le_min'_iff]\n    intro y hy\n    have key : n ≤ 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 (natTrailingDegree_le_of_ne_zero hy)\nset_option linter.uppercaseLean3 false in\n#align polynomial.nat_trailing_degree_mul_X_pow Polynomial.natTrailingDegree_mul_X_pow\n\ntheorem le_trailingDegree_mul : p.trailingDegree + q.trailingDegree ≤ (p * q).trailingDegree := by\n  refine' Finset.le_min fun n hn => _\n  rw [mem_support_iff, coeff_mul] at hn\n  obtain ⟨⟨i, j⟩, hij, hpq⟩ := 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 [← WithTop.coe_add, WithTop.coe_eq_coe, ← Nat.mem_antidiagonal]\n#align polynomial.le_trailing_degree_mul Polynomial.le_trailingDegree_mul\n\ntheorem le_natTrailingDegree_mul (h : p * q ≠ 0) :\n    p.natTrailingDegree + q.natTrailingDegree ≤ (p * q).natTrailingDegree := by\n  have hp : p ≠ 0 := fun hp => h (by rw [hp, zero_mul])\n  have hq : q ≠ 0 := fun hq => h (by rw [hq, mul_zero])\n  -- Porting note: Needed to account for different coercion behaviour & add the lemma below\n  have : ∀ (p : R[X]), WithTop.some (natTrailingDegree p) = Nat.cast (natTrailingDegree p) :=\n    fun p ↦ rfl\n  rw [← WithTop.coe_le_coe, WithTop.coe_add, this p, this q, this (p * q),\n    ← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq,\n    ← trailingDegree_eq_natTrailingDegree h]\n  exact le_trailingDegree_mul\n#align polynomial.le_nat_trailing_degree_mul Polynomial.le_natTrailingDegree_mul\n\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.natTrailingDegree, q.natTrailingDegree) _ fun h =>\n      (h (Nat.mem_antidiagonal.mpr rfl)).elim\n  rintro ⟨i, j⟩ h₁ h₂\n  rw [Nat.mem_antidiagonal] at h₁\n  by_cases hi : i < p.natTrailingDegree\n  · rw [coeff_eq_zero_of_lt_natTrailingDegree hi, zero_mul]\n  by_cases hj : j < q.natTrailingDegree\n  · rw [coeff_eq_zero_of_lt_natTrailingDegree hj, mul_zero]\n  rw [not_lt] at hi hj\n  refine' (h₂ (Prod.ext_iff.mpr _).symm).elim\n  exact (add_eq_add_iff_eq_and_eq hi hj).mp h₁.symm\n#align polynomial.coeff_mul_nat_trailing_degree_add_nat_trailing_degree Polynomial.coeff_mul_natTrailingDegree_add_natTrailingDegree\n\ntheorem trailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) :\n    (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by\n  have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul])\n  have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero])\n  refine' le_antisymm _ le_trailingDegree_mul\n  rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, ←\n    ENat.coe_add]\n  apply le_trailingDegree_of_ne_zero\n  rwa [coeff_mul_natTrailingDegree_add_natTrailingDegree]\n#align polynomial.trailing_degree_mul' Polynomial.trailingDegree_mul'\n\ntheorem natTrailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) :\n    (p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree := by\n  have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul])\n  have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero])\n  -- Porting note: Needed to account for different coercion behaviour & add the lemmas below\n  have aux1 : ∀ n, Nat.cast n = WithTop.some (n) := fun n ↦ rfl\n  have aux2 : ∀ (p : R[X]), WithTop.some (natTrailingDegree p) = Nat.cast (natTrailingDegree p) :=\n    fun p ↦ rfl\n  apply natTrailingDegree_eq_of_trailingDegree_eq_some\n  rw [trailingDegree_mul' h, aux1 (natTrailingDegree p + natTrailingDegree q),\n    WithTop.coe_add, aux2 p, aux2 q, ← trailingDegree_eq_natTrailingDegree hp, ←\n    trailingDegree_eq_natTrailingDegree hq]\n#align polynomial.nat_trailing_degree_mul' Polynomial.natTrailingDegree_mul'\n\ntheorem natTrailingDegree_mul [NoZeroDivisors R] (hp : p ≠ 0) (hq : q ≠ 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@[simp]\ntheorem trailingDegree_one : trailingDegree (1 : R[X]) = (0 : ℕ∞) :=\n  trailingDegree_C one_ne_zero\n#align polynomial.trailing_degree_one Polynomial.trailingDegree_one\n\n@[simp]\ntheorem trailingDegree_X : trailingDegree (X : R[X]) = 1 :=\n  trailingDegree_monomial one_ne_zero\nset_option linter.uppercaseLean3 false in\n#align polynomial.trailing_degree_X Polynomial.trailingDegree_X\n\n@[simp]\ntheorem natTrailingDegree_X : (X : R[X]).natTrailingDegree = 1 :=\n  natTrailingDegree_monomial one_ne_zero\nset_option linter.uppercaseLean3 false in\n#align polynomial.nat_trailing_degree_X Polynomial.natTrailingDegree_X\n\nend NonzeroSemiring\n\nsection Ring\n\nvariable [Ring R]\n\n@[simp]\ntheorem trailingDegree_neg (p : R[X]) : trailingDegree (-p) = trailingDegree p := by\n  unfold trailingDegree\n  rw [support_neg]\n#align polynomial.trailing_degree_neg Polynomial.trailingDegree_neg\n\n@[simp]\ntheorem natTrailingDegree_neg (p : R[X]) : natTrailingDegree (-p) = natTrailingDegree p := by\n  simp [natTrailingDegree]\n#align polynomial.nat_trailing_degree_neg Polynomial.natTrailingDegree_neg\n\n@[simp]\ntheorem natTrailingDegree_int_cast (n : ℤ) : natTrailingDegree (n : R[X]) = 0 := by\n  simp only [← C_eq_int_cast, natTrailingDegree_C]\n#align polynomial.nat_trailing_degree_int_cast Polynomial.natTrailingDegree_int_cast\n\nend Ring\n\nsection Semiring\n\nvariable [Semiring R]\n\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@[simp]\ntheorem nextCoeffUp_C_eq_zero (c : R) : nextCoeffUp (C c) = 0 := by\n  rw [nextCoeffUp]\n  simp\nset_option linter.uppercaseLean3 false in\n#align polynomial.next_coeff_up_C_eq_zero Polynomial.nextCoeffUp_C_eq_zero\n\ntheorem nextCoeffUp_of_pos_natTrailingDegree (p : R[X]) (hp : 0 < p.natTrailingDegree) :\n    nextCoeffUp p = p.coeff (p.natTrailingDegree + 1) := by\n  rw [nextCoeffUp, if_neg]\n  contrapose! hp\n  simpa\n#align polynomial.next_coeff_up_of_pos_nat_trailing_degree Polynomial.nextCoeffUp_of_pos_natTrailingDegree\n\nend Semiring\n\nsection Semiring\n\nvariable [Semiring R] {p q : R[X]} {ι : Type _}\n\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\ntheorem ne_zero_of_trailingDegree_lt {n : ℕ∞} (h : trailingDegree p < n) : p ≠ 0 := fun h₀ =>\n  h.not_le (by simp [h₀])\n#align polynomial.ne_zero_of_trailing_degree_lt Polynomial.ne_zero_of_trailingDegree_lt\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/Degree/TrailingDegree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7758904892680518}}
{"text": "import data.int.basic data.nat.gcd\n\nnamespace int\n\nlemma dvd_mod_iff {k m n : ℤ} (h : k ∣ n) : k ∣ m % n ↔ k ∣ 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 : ℤ) : gcd 0 a = a.nat_abs := nat.gcd_zero_left _\n\n@[simp] lemma gcd_one_left (a : ℤ) : gcd 1 a = 1 := nat.gcd_one_left _\n\n@[simp] lemma gcd_one_right (a : ℤ) : gcd a 1 = 1 := nat.gcd_one_right _\n\nlemma gcd_comm (a b : ℤ) : gcd a b = gcd b a := nat.gcd_comm _ _\n\nlemma gcd_mul_left (a b c : ℤ) : 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 : ℤ) : 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 : ℤ} (b : ℤ) (hb : b ≠ 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 : ℤ) : gcd (-a) b = gcd a b :=\nby unfold gcd; rw nat_abs_neg\n\n@[simp] lemma gcd_neg' (a b : ℤ) : gcd a (-b) = gcd a b :=\nby unfold gcd; rw nat_abs_neg\n\nlemma gcd_dvd_left (a b : ℤ) : (gcd a b : ℤ) ∣ a :=\ndvd_nat_abs.1 $ int.coe_nat_dvd.2 $ nat.gcd_dvd_left _ _\n\nlemma gcd_dvd_right (a b : ℤ) : (gcd a b : ℤ) ∣ b :=\ndvd_nat_abs.1 $ int.coe_nat_dvd.2 $ nat.gcd_dvd_right _ _ \n\nlemma dvd_gcd {a b c : ℤ} (hb : a ∣ b) (hc : a ∣ c) : a ∣ gcd b c :=\nnat_abs_dvd.1 $ int.coe_nat_dvd.2 (begin\n  rw [← nat_abs_dvd, ← dvd_nat_abs, int.coe_nat_dvd] at hb hc,\n  exact nat.dvd_gcd hb hc\nend)\n\nlemma gcd_mod (a b : ℤ) : 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 : ℤ) : gcd (gcd a b) c = gcd a (gcd b c) := nat.gcd_assoc _ _ _\n\nend int\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff1", "sha": "cbcd788b8b1d07b20b2fff4482c870077a13d1c0", "save_path": "github-repos/lean/ChrisHughes24-leanstuff1", "path": "github-repos/lean/ChrisHughes24-leanstuff1/leanstuff1-cbcd788b8b1d07b20b2fff4482c870077a13d1c0/int_gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7758804105920073}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\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 ↔ Q` you can just access the proofs of `P → Q` and `Q → P`\ndirectly with `h.mp` and `h.mpr`.\n\n## Lemma\nIf `P`, `Q` and `R` are true/false statements, then `P ↔ Q` and `Q ↔ R` together imply `P ↔ R`.\n-/\nlemma iff_trans₂ (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := by\n  intros hpq hqr\n  constructor\n  intro p\n  apply hqr.mp\n  apply hpq.mp\n  assumption\n  intro r\n  apply hpq.mpr\n  apply hqr.mpr\n  assumption\n\n/-!\n\n\n### Another trick\n\nInstead of using `cases` on `h : P ↔ 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-/\nlemma iff_trans₃ (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := by\n  intros hpq hqr\n  rw [hpq]\n  rw [hqr]\n\n/-!\n\n\nNext up [Level 6](./Level6.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/Level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7758804034120039}}
{"text": "open classical\n\nvariables p q r s : Prop\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p := \niff.intro \n    (assume hpq : p ∧ q, and.intro hpq.right hpq.left)\n    (assume hqp : q ∧ p, and.intro hqp.right hqp.left)\n\nexample : p ∨ q ↔ q ∨ p := \niff.intro \n    (assume hpq : p ∨ q, \n    or.elim hpq \n        (assume hp : p, show q ∨ p, from or.intro_right q hp)\n        (assume hq : q, show q ∨ p, from or.intro_left p hq)\n    )\n    (assume hqp : q ∨ p, \n    or.elim hqp \n        (assume hq : q, show p ∨ q, from or.intro_right p hq)\n        (assume hp : p, show p ∨ q, from or.intro_left q hp)\n    )\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\niff.intro \n    (assume h : (p ∧ q) ∧ r, \n    show p ∧ (q ∧ r), \n    from and.intro (h.left.left) (and.intro h.left.right h.right))\n    (assume h : p ∧ (q ∧ r), \n    show (p ∧ q) ∧ r, \n    from and.intro (and.intro h.left h.right.left) (h.right.right))\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\niff.intro \n    (assume h : (p ∨ q) ∨ r, \n    show p ∨ (q ∨ r), \n    from or.elim h\n        (λ hpq : p ∨ q, or.elim hpq\n            (λ hp : p, or.intro_left (q ∨ r) hp)\n            (λ hq : q, or.intro_right p (or.intro_left r hq)))\n        (λ hr : r, or.intro_right p (or.intro_right q hr)))\n    (assume h : p ∨ (q ∨ r), \n    show (p ∨ q) ∨ r, \n    from or.elim h\n        (λ hp : p, or.intro_left r (or.intro_left q hp))\n        (λ hqr : q ∨ r, or.elim hqr\n            (λ hq : q, or.intro_left r (or.intro_right p hq))\n            (λ hr : r, or.intro_right (p ∨ q) hr)))\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\niff.intro \n    (λ h : p ∧ (q ∨ r), or.elim h.right\n        (λ hq: q, or.intro_left (p ∧ r) (and.intro h.left hq))\n        (λ hr: r, or.intro_right (p ∧ q) (and.intro h.left hr)))\n    (λ h : (p ∧ q) ∨ (p ∧ r), or.elim h\n        (λ hpq: p ∧ q, and.intro hpq.left (or.intro_left r hpq.right))\n        (λ hpr: p ∧ r, and.intro hpr.left (or.intro_right q hpr.right)))\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\niff.intro \n    (λ h : p ∨ (q ∧ r), or.elim h\n        (λ hp: p, and.intro (or.intro_left q hp) (or.intro_left r hp))\n        (λ hqr: q ∧ r, and.intro (or.intro_right p hqr.left) (or.intro_right p hqr.right)))\n    (λ h : (p ∨ q) ∧ (p ∨ r), or.elim h.left\n        (λ hp: p, or.intro_left (q ∧ r) hp)\n        (λ hq: q, or.elim h.right\n            (λ hp: p, or.intro_left (q ∧ r) hp)\n            (λ hr: r, or.intro_right p (and.intro hq hr))))\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) :=\niff.intro\n    (assume h: p → (q → r),\n    assume hpq: p ∧ q,\n    have hqr: q → r, from h hpq.left,\n    show r, from hqr hpq.right)\n    (assume h: p ∧ q → r,\n    assume hp: p,\n    assume hq: q,\n    show r, from h (and.intro hp hq))\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \niff.intro\n    (assume h : (p ∨ q) → r, and.intro\n        (assume hp: p, show r, from h (or.intro_left q hp))\n        (assume hq: q, show r, from h (or.intro_right p hq)))\n    (assume h : (p → r) ∧ (q → r),\n    assume hpq: p ∨ q, or.elim hpq\n        (assume hp: p, show r, from h.left hp)\n        (assume hq: q, show r, from h.right hq))\n\nexample : ¬(p ∨ q) → ¬p :=\n    assume h : ¬(p ∨ q),\n    show ¬p, from (\n        assume hp: p,\n        have hpq: p ∨ q, from or.intro_left q hp,\n        show false, from absurd hpq h)\n\n-- changed to lemma for later use\nlemma not_or_and_not : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\niff.intro\n    (assume h : ¬(p ∨ q), and.intro \n        (assume hp: p,\n        have hpq: p ∨ q, from or.intro_left q hp,\n        show false, from absurd hpq h)\n        (assume hq: q,\n        have hpq: p ∨ q, from or.intro_right p hq,\n        show false, from absurd hpq h))\n    (assume npq: ¬p ∧ ¬q,\n    assume hpq: p ∨ q,\n    have np: ¬p, from npq.left,\n    have nq: ¬q, from npq.right,\n    show false, from or.elim hpq\n        (assume hp: p, absurd hp np)\n        (assume hq: q, absurd hq nq))\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\n    assume npq: ¬p ∨ ¬q,\n    assume hpq: p ∧ q,\n    have hp: p, from hpq.left,\n    have hq: q, from hpq.right,\n    show false, from or.elim npq\n        (assume np: ¬p, absurd hp np)\n        (assume nq: ¬q, absurd hq nq)\n\nexample : ¬(p ∧ ¬p) :=\n    assume h : p ∧ ¬p,\n    have hp: p, from h.left,\n    have np: ¬p, from h.right,\n    show false, from absurd hp np\n\nexample : p ∧ ¬q → ¬(p → q) :=\n    assume hpnq: p ∧ ¬q,\n    assume hpq: p → q,\n    have hp: p, from hpnq.left,\n    have nq: ¬q, from hpnq.right,\n    have hq: q, from hpq hp,\n    show false, from absurd hq nq\n\nexample : ¬p → (p → q) :=\n    assume np: ¬p,\n    assume hp: p,\n    show q, from absurd hp np\n\nexample : (¬p ∨ q) → (p → q) :=\n    assume h: ¬p ∨ q,\n    assume hp: p,\n    show q, from or.elim h\n        (assume np: ¬p, absurd hp np)\n        (assume hq: q, hq)\n\nexample : p ∨ false ↔ p :=\niff.intro\n    (assume h : p ∨ false, or.elim h\n        (assume hp: p, hp)\n        (assume f: false, false.elim f))\n    (assume hp: p, or.intro_left false hp)\n\nexample : p ∧ false ↔ false := \niff.intro\n    (assume h : p ∧ false, false.elim h.right)\n    (assume f: false, false.elim f)\n\n/-\nExercise 2. Prove ¬(p ↔ ¬p) without using classical logic.\n-/\nlemma implies_to_double_not_and : (p → q) → ¬¬(¬p ∨ q):=\n    assume h: p → q,\n    assume h₂ : ¬(¬p ∨ q),\n    have h₃ : ¬¬p ∧ ¬q, from iff.elim_left (not_or_and_not (¬p) q) h₂,\n    have nnp: ¬¬p, from h₃.left,\n    have nq: ¬q, from h₃.right,\n    have np: ¬p, from (\n        assume hp: p,\n        have hq: q, from h hp,\n        show false, from absurd hq nq),\n    show false, from absurd np nnp\nlemma iff_to_not_iff : (p ↔ q) → (¬p ↔ ¬q) :=\n    assume h : p ↔ q, iff.intro\n        (assume np : ¬p,\n        assume hq : q,\n        have hp: p, from iff.elim_right h hq,\n        show false, from absurd hp np)\n        (assume nq : ¬q,\n        assume hp : p,\n        have hq: q, from iff.elim_left h hp,\n        show false, from absurd hq nq)\nlemma not_and_same : ¬(p ∧ p) → ¬p :=\n    assume h: ¬(p ∧ p),\n    assume hp: p,\n    have hpp: p ∧ p, from and.intro hp hp,\n    show false, from absurd hpp h\nexample : ¬(p ↔ ¬p) :=\n    -- enumerate negations\n    assume h₀: p ↔ ¬p,\n    have h₁ : ¬p ↔ ¬¬p, from iff_to_not_iff p (¬p) h₀,\n    have h₂ : ¬¬p ↔ ¬¬¬p, from iff_to_not_iff (¬p) (¬¬p) h₁,\n    -- get negated p\n    have hnnnp : ¬(¬¬p ∧ ¬¬p), from (\n        -- (p → ¬p) → ¬(¬¬p ∧ ¬¬p)\n        have h₁ : ¬¬(¬p ∨ ¬p), from implies_to_double_not_and p (¬p) (iff.elim_left h₀),\n        have h₂ : ¬¬(¬p ∨ ¬p) ↔ ¬(¬¬p ∧ ¬¬p), from iff_to_not_iff (¬(¬p ∨ ¬p)) (¬¬p ∧ ¬¬p) (not_or_and_not (¬p) (¬p)),\n        show ¬(¬¬p ∧ ¬¬p), from (iff.elim_left h₂) h₁),\n    --implies_to_andish p (¬p) (iff.elim_left h₀),\n    have nnnp : ¬¬¬p, from not_and_same (¬¬p) hnnnp,\n    -- eliminate negations\n    have nnp : ¬¬p, from iff.elim_right h₂ nnnp,\n    show false, from absurd nnp nnnp\n\n-- changed to lemma for later use\nlemma reverse_imp : (p → q) → (¬q → ¬p) :=\n    assume hpq: p → q,\n    assume nq: ¬q,\n    assume hp: p,\n    have hq: q, from hpq hp,\n    show false, from absurd hq nq\n\n-- these require classical reasoning\n\nlemma notnot : ¬¬p ↔ p :=\n    iff.intro\n        (assume h: ¬¬p,\n        by_contradiction (assume h1 : ¬p, show false, from h h1))\n        (assume h: p,\n        by_cases \n            (assume h1 : ¬p, absurd h h1)\n            (assume h1 : ¬¬p, h1))\n\nlemma imp_substitue_frst : ((p → q) ∧ (p ↔ r)) → (r → q) :=\n    assume h: (p → q) ∧ (p ↔ r),\n    assume hr: r,\n    have hp: p, from iff.elim_right (and.elim_right h) hr,\n    show q, from and.elim_left h hp\n\nlemma imp_substitue_scnd : ((p → q) ∧ (q ↔ r)) → (p → r) :=\n    assume h: (p → q) ∧ (q ↔ r),\n    assume hp: p,\n    have hq: q, from and.elim_left h hp,\n    show r, from iff.elim_left (and.elim_right h) hq\n\nlemma not_and_to_imp : ¬(p ∧ ¬q) → (p → q) :=\n    assume h : ¬(p ∧ ¬q),\n    assume hp : p,\n    show q, from\n    or.elim (em q)\n        (assume hq : q, hq)\n        (assume hnq : ¬q, absurd (and.intro hp hnq) h)\n\nlemma not_iff : ¬(p → q) → p ∧ ¬q :=\n    assume h : ¬(p → q),\n    by_contradiction\n        (assume n₀ : ¬(p ∧ ¬q),\n        have n₁ : p → q, from not_and_to_imp  p q n₀,\n        show false, from absurd n₁ h)\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n    assume h : p → r ∨ s,\n    by_contradiction\n        (assume n₀ : ¬((p → r) ∨ (p → s)),\n        have n₁ : ¬(p → r) ∧ ¬(p → s), from iff.elim_left (not_or_and_not (p → r) (p → s)) n₀,\n        have n₂ : p ∧ ¬r, from not_iff p r (and.elim_left n₁),\n        have n₃ : p ∧ ¬s, from not_iff p s (and.elim_right n₁),\n        have hrs: r ∨ s, from h (and.elim_left n₂),\n        have nrs: ¬(r ∨ s), from iff.elim_right (not_or_and_not r s) (and.intro n₂.right n₃.right),\n        show false, from absurd hrs nrs)\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n    assume h : ¬(p ∧ q),\n    by_cases\n        (assume hp: p, \n        have nq: ¬q, from by_contradiction(\n            assume nnq: ¬¬q,\n            have hq: q, from iff.elim_left (notnot q) nnq,\n            have n : p ∧ q, from and.intro hp hq,\n            show false, from absurd n h),\n        show ¬p ∨ ¬q, from or.intro_right (¬p) nq)\n        (assume np: ¬p, show ¬p ∨ ¬q, from or.intro_left (¬q) np)\n    \n-- changed to lemma for later use\nlemma implies_as_or : (p → q) → (¬p ∨ q) :=\nassume h : p → q,\nby_cases\n    (assume hp : p,\n    have hq: q, from h hp,\n    show ¬p ∨ q, from or.intro_right (¬p) hq)\n    (assume np : ¬p, show ¬p ∨ q, from or.intro_left (q) np)\n\nexample : (¬q → ¬p) → (p → q) :=\n    assume h : ¬q → ¬p,\n    assume hp : p,\n    by_contradiction (\n        assume nq: ¬q,\n        have np : ¬p, from h nq,\n        show false, from absurd hp np)\n\nexample : p ∨ ¬p := em p\n\nexample : (((p → q) → p) → p) :=\n    by_contradiction\n        (assume n : ¬ (((p → q) → p) → p),\n        have h₀ : ((p → q) → p) ∧ ¬p, from not_iff ((p → q) → p) p n,\n        have h₁ : ¬(p → q), from (reverse_imp (p → q) p h₀.left) h₀.right,\n        have h₂ : p ∧ ¬q, from not_iff p q h₁,\n        show false, from absurd h₂.left h₀.right)", "meta": {"author": "mbrg", "repo": "lean-tutorial-reference", "sha": "46cb983e8547fc39e43480c37e6cf4dd3e085485", "save_path": "github-repos/lean/mbrg-lean-tutorial-reference", "path": "github-repos/lean/mbrg-lean-tutorial-reference/lean-tutorial-reference-46cb983e8547fc39e43480c37e6cf4dd3e085485/Theorem Proving in Lean/3.propositions_and_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7758145288309918}}
{"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.determinant\nimport topology.algebra.ring\n\n/-!\n# Topological properties of matrices\n\nThis file is a place to collect topological results about matrices.\n\n## Main definitions:\n\n * `continuous_det`: the determinant is continuous over a topological ring.\n-/\n\nopen matrix\n\nvariables {ι k : Type*} [topological_space k]\n\ninstance : topological_space (matrix ι ι k) := Pi.topological_space\n\nvariables [fintype ι] [decidable_eq ι] [comm_ring k] [topological_ring k]\n\nlemma continuous_det : continuous (det : matrix ι ι k → k) :=\nbegin\n  suffices : ∀ (n : ℕ), continuous (λ A : matrix (fin n) (fin n) k, matrix.det A),\n  { have h : (det : matrix ι ι k → k) = det ∘ reindex (fintype.equiv_fin ι) (fintype.equiv_fin ι),\n    { ext, simp, },\n    rw h,\n    apply (this (fintype.card ι)).comp,\n    exact continuous_pi (λ i, continuous_pi (λ j, continuous_apply_apply _ _)), },\n  intros n,\n  induction n with n ih,\n  { simp_rw coe_det_is_empty,\n    exact continuous_const, },\n  simp_rw det_succ_column_zero,\n  refine continuous_finset_sum _ (λ l _, _),\n  refine (continuous_const.mul (continuous_apply_apply _ _)).mul (ih.comp _),\n  exact continuous_pi (λ i, continuous_pi (λ j, continuous_apply_apply _ _)),\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/topology/algebra/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7758065113131144}}
{"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 topology.continuous_on\n\n/-!\n# Left and right continuity\n\nIn this file we prove a few lemmas about left and right continuous functions:\n\n* `continuous_within_at_Ioi_iff_Ici`: two definitions of right continuity\n  (with `(a, ∞)` and with `[a, ∞)`) are equivalent;\n* `continuous_within_at_Iio_iff_Iic`: two definitions of left continuity\n  (with `(-∞, a)` and with `(-∞, a]`) are equivalent;\n* `continuous_at_iff_continuous_left_right`, `continuous_at_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\nopen set filter\nopen_locale topological_space\n\nsection partial_order\n\nvariables {α β : Type*} [topological_space α] [partial_order α] [topological_space β]\n\nlemma continuous_within_at_Ioi_iff_Ici {a : α} {f : α → β} :\n  continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a :=\nby simp only [← Ici_diff_left, continuous_within_at_diff_self]\n\nlemma continuous_within_at_Iio_iff_Iic {a : α} {f : α → β} :\n  continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a :=\n@continuous_within_at_Ioi_iff_Ici (order_dual α) _ ‹topological_space α› _ _ _ f\n\nend partial_order\n\nvariables {α β : Type*} [topological_space α] [linear_order α] [topological_space β]\n\nlemma nhds_left_sup_nhds_right (a : α) :\n  𝓝[Iic a] a ⊔ 𝓝[Ici a] a = 𝓝 a :=\nby rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ]\n\nlemma nhds_left'_sup_nhds_right (a : α) :\n  𝓝[Iio a] a ⊔ 𝓝[Ici a] a = 𝓝 a :=\nby rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ]\n\nlemma nhds_left_sup_nhds_right' (a : α) :\n  𝓝[Iic a] a ⊔ 𝓝[Ioi a] a = 𝓝 a :=\nby rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ]\n\nlemma continuous_at_iff_continuous_left_right {a : α} {f : α → β} :\n  continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a :=\nby simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right]\n\nlemma continuous_at_iff_continuous_left'_right' {a : α} {f : α → β} :\n  continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a :=\nby rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic,\n  continuous_at_iff_continuous_left_right]\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/left_right.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.7757239471587083}}
{"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\nimport 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\nnamespace nat\n\n/-- Recursion principle on even and odd numbers: if we have `P 0`, and for all `i : ℕ` we can\nextend from `P i` to both `P (2 * i)` and `P (2 * i + 1)`, then we have `P n` for all `n : ℕ`.\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_eliminator]\ndef even_odd_rec {P : ℕ → Sort*} (h0 : P 0)\n  (h_even : ∀ n (ih : P n), P (2 * n))\n  (h_odd : ∀ n (ih : P n), P (2 * n + 1)) (n : ℕ) : P n :=\nbegin\n  refine @binary_rec P h0 (λ b i hi, _) n,\n  cases b,\n  { simpa [bit, bit0_val i] using h_even i hi },\n  { simpa [bit, bit1_val i] using h_odd i hi },\nend\n\n@[simp] lemma even_odd_rec_zero (P : ℕ → Sort*) (h0 : P 0)\n  (h_even : ∀ i, P i → P (2 * i)) (h_odd : ∀ i, P i → P (2 * i + 1)) :\n  @even_odd_rec _ h0 h_even h_odd 0 = h0 := binary_rec_zero _ _\n\n@[simp] lemma even_odd_rec_even (n : ℕ) (P : ℕ → Sort*) (h0 : P 0)\n  (h_even : ∀ i, P i → P (2 * i)) (h_odd : ∀ i, P i → P (2 * i + 1))\n  (H : h_even 0 h0 = h0) :\n  @even_odd_rec _ h0 h_even h_odd (2 * n) = h_even n (even_odd_rec h0 h_even h_odd n) :=\nbegin\n  convert binary_rec_eq _ ff n,\n  { exact (bit0_eq_two_mul _).symm },\n  { exact (bit0_eq_two_mul _).symm },\n  { apply heq_of_cast_eq, refl },\n  { exact H }\nend\n\n@[simp] lemma even_odd_rec_odd (n : ℕ) (P : ℕ → Sort*) (h0 : P 0)\n  (h_even : ∀ i, P i → P (2 * i)) (h_odd : ∀ i, P i → P (2 * i + 1))\n  (H : h_even 0 h0 = h0) :\n  @even_odd_rec _ h0 h_even h_odd (2 * n + 1) = h_odd n (even_odd_rec h0 h_even h_odd n) :=\nbegin\n  convert binary_rec_eq _ tt n,\n  { exact (bit0_eq_two_mul _).symm },\n  { exact (bit0_eq_two_mul _).symm },\n  { apply heq_of_cast_eq, refl },\n  { exact 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/data/nat/even_odd_rec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.8840392878563336, "lm_q1q2_score": 0.7757239458182968}}
{"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.convex.star\nimport 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\nvariables {E : Type*} [add_comm_group E] [module ℝ E] [topological_space E]\n  [has_continuous_add E] [has_continuous_smul ℝ E] {s : set E} {x : E}\n\n/-- A non-empty star convex set is a contractible space. -/\nprotected lemma star_convex.contractible_space (h : star_convex ℝ x s) (hne : s.nonempty) :\n  contractible_space s :=\nbegin\n  refine (contractible_iff_id_nullhomotopic _).2 ⟨⟨x, h.mem hne⟩,\n    ⟨⟨⟨λ p, ⟨p.1.1 • x + (1 - p.1.1) • p.2, _⟩, _⟩, λ x, _, λ x, _⟩⟩⟩,\n  { exact h p.2.2 p.1.2.1 (sub_nonneg.2 p.1.2.2) (add_sub_cancel'_right _ _) },\n  { exact ((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  { ext1, simp },\n  { ext1, simp }\nend\n\n/-- A non-empty convex set is a contractible space. -/\nprotected lemma convex.contractible_space (hs : convex ℝ s) (hne : s.nonempty) :\n  contractible_space s :=\nlet ⟨x, hx⟩ := hne in (hs.star_convex hx).contractible_space hne\n\n@[priority 100] instance real_topological_vector_space.contractible_space : contractible_space E :=\n(homeomorph.set.univ E).contractible_space_iff.mp $ convex_univ.contractible_space set.univ_nonempty\n", "meta": {"author": "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/contractible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.7757239376241123}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intros h1 h2,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  by_cases hipo : P,\n    intro h1,\n    apply hipo,\n\n    intro h1,\n    have newhipo := h1 hipo,\n    contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  have primeiraHipo := doubleneg_elim P,\n    apply primeiraHipo,\n  have segundaHipo := doubleneg_intro P,\n    apply segundaHipo,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro h1,\n  cases h1,\n  right,\n    apply h1,\n  left,\n    apply h1,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro h1,\n  cases h1 with part1 part2,\n  split,\n  apply part2,\n  apply part1,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intros h1 h2,\n  cases h1,\n  contradiction,\n  apply h1,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intros h1 h2,\n  cases h1,\n  contradiction,\n  apply h1,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intros h1 h2 h3,\n  have newhipo : Q := h1 h3,\n    contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros h1 h2,\n  by_cases q: Q,\n    assumption,\n    have newhipo := h1 q,\n      contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  have primeiraHipo := impl_as_contrapositive P Q,\n    apply primeiraHipo,\n  have segundaHipo := impl_as_contrapositive_converse P Q,\n    apply segundaHipo,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intros h1,\n  have leiTercEscolh : P ∨ ¬P,\n    right,\n    intro h2,\n    have leiTercEscolhOutraParte : P ∨ ¬P,\n      left,\n      apply h2,\n      contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros h1 h2,\n  have newhipo : P → Q,\n    intro h2,\n    contradiction,\n  have obterP := h1 newhipo,\n    contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intros h1 h2,\n  cases h2 with hp hq,\n  cases  h1,\n    contradiction,\n    contradiction,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intros h1 h2,\n  cases h1 with hp hq,\n  cases h2,\n    contradiction,\n    contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro h1,\n  split,\n    intro hp,\n    have newhipo : (P∨Q),\n    left,\n      apply hp,\n      contradiction,\n    intro hq,\n    have newhipo : (P∨Q),\n      right,\n      apply hq,\n      contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intros h1 h2,\n  cases h1 with naop naoq,\n    cases h2,\n    contradiction,\n    contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro h1,\n  by_cases P,\n  left,\n  by_contradiction q,\n  have newhipo : P∧Q,\n    split,\n    repeat {assumption},\n  contradiction,\n  right,\n  assumption,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intros h1 h2,\n  cases h2 with hp hq,\n    cases h1 with naoq naop,\n    contradiction,\n    contradiction,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  have primeiraHipo := demorgan_conj P Q,\n    apply primeiraHipo,\n  have segundaHipo := demorgan_conj_converse P Q,\n    apply segundaHipo,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  have primeiraHipo := demorgan_disj P Q,\n    apply primeiraHipo,\n  have segundaHipo := demorgan_disj_converse P Q,\n    apply segundaHipo,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro h1,\n  cases h1 with hp hqr,\n  cases hqr,\n  left,\n    split,\n      assumption,\n      assumption,\n  right,\n    split,\n      assumption,\n      assumption,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro h1,\n  split,\n  cases h1,\n    cases h1 with hq hpr,\n    assumption,\n      cases h1 with p q,\n      assumption,\n      cases h1,\n        cases h1 with hp hq,\n        left,\n          assumption,\n        cases h1 with hp hpr,\n        right,\n        assumption,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro h1,\n  cases h1,\n    split,\n    left,\n      assumption,\n      left,\n        assumption,\n    cases h1 with hq hr,\n    split,\n    right,\n      assumption,\n    right,\n      assumption,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro h1,\n  cases h1 with pq pr,\n  cases pq with p q,\n    left,\n      assumption,\n    cases pr with p r,\n      left,\n        assumption,\n      right,\n        split,\n          repeat {assumption},\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intros h1 h2 h3,\n  have newhipo : (P∧Q),\n  split,\n    assumption,\n    assumption,\n  apply h1 newhipo,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intros h1 h2,\n  cases h2 with hp hq,\n  apply h1 hp hq,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro h1,\n  assumption,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro h1,\n  left, --escolhe lado esquerdo do alvo\n  assumption,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro h1,\n  right, --escolhe lado direito do alvo\n  assumption,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro h1,\n  cases h1 with hp hq,\n    assumption,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro h1,\n  cases h1 with hp hq,\n    assumption,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro h1,\n  cases h1,\n    assumption,\n  intro h2,\n    split,\n      assumption,\n      assumption,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro h1,\n  cases h1,\n    assumption,\n    assumption,\n  intro h2,\n    right, --ou esquerda, tanto faz\n      assumption,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros nEa a pA,\n  apply nEa,\n  existsi a,\n  assumption,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros pTdA eA,\n  cases eA with a,\n  have newhipo := pTdA a,\n  contradiction,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  apply impl_as_contrapositive_converse (¬(∀x, P x)) (∃x, ¬P x),\n  intros nEa,\n  apply doubleneg_intro (∀x, P x),\n  intro a,\n  by_contra nPa,\n  have newhipo : (∃x, ¬P x),\n    existsi a,\n    assumption,\n  contradiction,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intros eA pTdA,\n  cases eA with a,\n  have newhipo := pTdA a,\n  contradiction,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  have primeiraHipo := demorgan_forall U P,\n    apply primeiraHipo,\n  have segundaHipo := demorgan_forall_converse U P,\n    apply segundaHipo,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  have primeiraHipo := demorgan_exists U P,\n    apply primeiraHipo,\n  have segundaHipo := demorgan_exists_converse U P,\n    apply segundaHipo,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros eA nPtdA,\n  cases eA with u pU,\n  have newhipo := nPtdA u,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros pTdA eA,\n  cases eA with a nPa,\n  have newhipo := pTdA a,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intros nEnPa a,\n  by_contra nPa,\n  have newhipo : ∃x, ¬P x,\n    existsi a,\n    apply nPa,\n  contradiction,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro npTdA,\n  by_contra nEa,\n  have newhipo : (∀x, ¬P x),\n    intros a Pa,\n    have otherhipo : ∃x, P x,\n      existsi a,\n      assumption,\n    contradiction,\n  contradiction,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  have primeiraHipo := forall_as_neg_exists U P,\n    apply primeiraHipo,\n  have segundaHipo := forall_as_neg_exists_converse U P,\n    apply segundaHipo,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  have primeiraHipo := exists_as_neg_forall U P,\n    apply primeiraHipo,\n  have segundaHipo := exists_as_neg_forall_converse U P,\n    apply segundaHipo,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro ePa,\n  cases ePa with a pq,\n    cases pq with pa qa,\n      split,\n        existsi a,\n        assumption,\n        existsi a,\n        assumption,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro ePa,\n  cases ePa with a pq,\n    cases pq with pa qa,\n      left,\n        existsi a,\n        assumption,\n      right,\n        existsi a,\n        assumption,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro ePaOUeQa,\n  cases ePaOUeQa with ePa eQa,\n    cases ePa with a Pa,\n      existsi a,\n      left,\n        assumption,\n    cases eQa with a Qa,\n      existsi a,\n      right,\n        assumption,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro pTdaPaEQa,\n  split,\n    intro a,\n    have newhipo := pTdaPaEQa a,\n    cases newhipo with pq qa,\n    assumption,\n\n    intro a,\n    have otherhipo := pTdaPaEQa a,\n    cases otherhipo with pq qa,\n    assumption,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intros pTdaPaEpTdaQa a,\n  cases pTdaPaEpTdaQa with pTdaPa pTdaQa,\n    split,\n      have newhipo := pTdaPa a,\n        assumption,\n      have newhipo := pTdaQa a,\n        assumption,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intros pTdaPaOUpTdaQa a,\n  cases pTdaPaOUpTdaQa with pTdaPa pTdaQa,\n    left,\n      have newhipo := pTdaPa a,\n        assumption,\n    right,\n      have newhipo := pTdaQa a,\n        assumption,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "carloseps", "repo": "fmclean", "sha": "0db71e19f43b5c223cb25ffab63b6af130a98049", "save_path": "github-repos/lean/carloseps-fmclean", "path": "github-repos/lean/carloseps-fmclean/fmclean-0db71e19f43b5c223cb25ffab63b6af130a98049/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897475985936, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7756453316782078}}
{"text": "-- Monotonía de la suma por la derecha en Lean\n-- ===========================================\n\n-- Demostrar que si a, b y c son números reales \n-- tales que a ≤ b, entonces a + c ≤ b + c.\n\nimport data.real.basic\n\nvariables {a b c : ℝ}\n\n-- 1ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin \n  rw ← 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ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin\n  rw ← sub_nonneg,\n  calc \n    0   ≤ b - a           \n            : by exact sub_nonneg.mpr hab\n    ... = b + c - (a + c) \n            : by exact (add_sub_add_right_eq_sub b a c).symm, \nend\n\n-- 3ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin\n  rw ← sub_nonneg,\n  calc \n    0   ≤ b - a           \n            : sub_nonneg.mpr hab\n    ... = b + c - (a + c) \n            : (add_sub_add_right_eq_sub b a c).symm, \nend\n\n-- 4ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin\n  rw ← sub_nonneg,\n  calc 0   ≤ b - a           : sub_nonneg.mpr hab\n       ... = b + c - (a + c) : by ring,\nend\n\n-- 5ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin\n  rw ← sub_nonneg,\n  simp,\n  exact hab,\nend\n\n-- 6ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin\n  rw ← sub_nonneg,\n  simp [hab],\nend\n\n-- 7ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin\n  simp [hab],\nend\n\n-- 8ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nby simp [hab]\n\n-- 9ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nadd_le_add_right hab c\n\n-- 10ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nby linarith\n\n-- 11ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nby finish\n\n-- 12ª demostración\nexample \n  (hab : a ≤ b) \n  : a + c ≤ b + c :=\nbegin \n  rw add_comm a c,\n  rw add_comm b c,\n  exact add_le_add_left hab c,\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/2_Conectivas/Monotonia_de_la_suma_por_la_derecha_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7756245289259379}}
{"text": "import tactic\nimport data.nat.gcd.basic\n\n\n-- Rather than reinventing the wheel now we want to explore how to use mathlib\n\n-- this gives us access to most results of the form `nat.blah` in their short form `blah`\n\nopen nat\nvariables {a b c d k m n : ℕ} -- these will now be available when needed in our examples below\n\n/- TODO Ask Richard what he thinks we need to do on this topic -/\n/- Integer dvd -/\nexample : d ∣ n ↔ ∃ k, n = d*k :=\nbegin\n  refl,\nend\n\nexample : a ∣ b →  b ∣ c →  a ∣ c:=\nbegin\n  sorry,\nend\n\nexample : a ∣ b → b ∣ a →  a = b:=\nbegin\n  sorry,\nend\n\nexample : 0 ∣ a → a = 0:=\nbegin\n  sorry,\nend\n\nexample : 1 ∣ a :=\nbegin\n  sorry,\nend\n\nexample : 2 ∣ a ↔ even a :=\nbegin\n  sorry,\nend\n\nexample : 2 ∣ a →  3 ∣ a →  6 ∣ a:=\nbegin\n  sorry,\nend\n\n/-  k % m the remainder of k after division by m`\n  while k/m is the quotient so: -/\nexample : m*(k/m) + (k%m) = k:=\nbegin\n  sorry,\nend\n\nexample : a % m = b % m → b % m = c % m → a % m = c % m:=\nbegin\n  sorry,\nend\n\n#check nat.gcd\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/4_numbers/nats_division_etc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9597620585273153, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7755522523078318}}
{"text": "-- https://leanprover.github.io/theorem_proving_in_lean/propositions_and_proofs.html#exercises\n\nvariables p q r : Prop\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p := \n  ⟨ assume h: p ∧ q, ⟨h.right, h.left⟩, assume h: q ∧ p, ⟨h.right, h.left⟩ ⟩\n\nexample : p ∨ q ↔ q ∨ p := \n  ⟨\n    assume h: p ∨ q,\n    show q ∨ p, from h.elim (λ hp: p, or.inr hp) (λ hq: q, or.inl hq),\n\n    assume h: q ∨ p,\n    show p ∨ q, from h.elim (λ hq: q, or.inr hq) (λ hp: p, or.inl hp),\n  ⟩\n    \n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := \n  ⟨\n    assume h: (p ∧ q) ∧ r,\n    show p ∧ (q ∧ r), from ⟨h.left.left, ⟨h.left.right, h.right⟩⟩,\n\n    assume h: p ∧ (q ∧ r),\n    show (p ∧ q) ∧ r, from ⟨⟨h.left, h.right.left⟩, h.right.right⟩,\n  ⟩\n  \nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := ⟨\n  let goal := p ∨ (q ∨ r) in\n  assume h: (p ∨ q) ∨ r,\n  show goal, from h.elim (\n    assume hpq: p ∨ q, show goal, from hpq.elim \n      (assume hp: p, show goal, from or.inl hp)\n      (assume hq: q, show goal, from or.inr (or.inl hq))\n  ) (\n    assume hr: r, show goal, from or.inr (or.inr hr)\n  ),\n\n  let goal := (p ∨ q) ∨ r in\n  assume h: p ∨ (q ∨ r),\n  show goal, from h.elim (\n    assume hp: p, show goal, from or.inl (or.inl hp)\n  ) (\n    assume hqr: q ∨ r, show goal, from hqr.elim \n      (assume hq: q, show goal, from or.inl (or.inr hq))\n      (assume hr: r, show goal, from or.inr hr)\n  )\n⟩\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := ⟨\n  assume h: p ∧ (q ∨ r),\n  show (p ∧ q) ∨ (p ∧ r), from (\n    have hp: p, from h.left,\n    have hqr: q ∨ r, from h.right,\n    or.elim hqr (\n      assume hq: q, or.inl ⟨hp, hq⟩\n    ) (\n      assume hr: r, or.inr ⟨hp, hr⟩\n    )\n  ),\n\n  assume h: (p ∧ q) ∨ (p ∧ r),\n  show p ∧ (q ∨ r), from (\n    or.elim h (\n      assume hpq: p ∧ q,\n      ⟨hpq.left, or.inl hpq.right⟩\n    ) (\n      assume hpr: p ∧ r,\n      ⟨hpr.left, or.inr hpr.right⟩\n    )\n  ),\n⟩\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := \nlet left := p ∨ (q ∧ r) in\nlet right := (p ∨ q) ∧ (p ∨ r) in ⟨\n  assume h: left,\n  show right, from or.elim h\n    (λ hp: p, show right, from ⟨or.inl hp, or.inl hp⟩)\n    (λ hqr: q ∧ r, show right, from ⟨or.inr hqr.left, or.inr hqr.right⟩),\n  \n  assume h: right,\n  have hpq: p ∨ q, from h.left,\n  show left, from or.elim hpq (\n    λ hp: p, or.inl hp\n  ) (\n    λ hq: q,\n      have hqr: p ∨ r, from h.right,\n      show left, from or.elim hqr (\n        λ hp: p, or.inl hp\n      ) (\n        λ hr: r, or.inr ⟨hq, hr⟩\n      )\n  )\n⟩\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := \nlet left := p → (q → r) in\nlet right := (p ∧ q → r) in\n⟨\n  assume h: left,\n  show right, from \n    (λ hpq: p ∧ q, h hpq.left hpq.right),\n\n  assume h: right,\n  show left, from (λ (hp: p) (hq: q), h ⟨hp, hq⟩)\n⟩\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \nlet left := (p ∨ q) → r, right := (p → r) ∧ (q → r) in\n⟨\n  assume h: left,\n  show right, from ⟨λ hp: p, h $ or.inl hp,  λ hq: q, h $ or.inr hq⟩,\n\n  assume h: right,\n  show left, from λ hpq: p ∨ q, hpq.elim\n    (λ hp: p, h.left hp) \n    (λ hq: q, h.right hq)\n⟩\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \nlet left := ¬(p ∨ q), right := ¬ p ∧ ¬ q in ⟨\n  assume h: left, show right, from\n  let hnp := \n    show ¬ p, from \n    assume hp: p,\n    have hpq: (p ∨ q), from or.inl hp,\n    show false, from h hpq in\n  let hnq :=\n    show ¬ q, from\n    assume hq: q,\n    have hpq: (p ∨ q), from or.inr hq,\n    show false, from h hpq in\n  ⟨hnp, hnq⟩,\n\n  assume h: right, show left, from\n  let hnp := h.left, hnq := h.right in\n  assume hpq: p ∨ q,\n  show false, from hpq.elim (λ hp: p, hnp hp) (λ hq: q, hnq hq)\n⟩\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) := \nassume h: ¬ p ∨ ¬ q, assume hpq: p ∧ q, show false, from\n  h.elim (λ hnp: ¬ p, hnp hpq.left) (λ hnq: ¬ q, hnq hpq.right)\n\nexample : ¬(p ∧ ¬p) := \nassume h: p ∧ ¬ p, show false, from h.right h.left\n\nexample : p ∧ ¬q → ¬(p → q) := \nassume h: p ∧ ¬q,\nhave hp: p, from h.left, have hnq: q -> false, from h.right,\nassume hpq: p -> q, show false, from hnq $ hpq hp\n\nexample : ¬p → (p → q) := \nassume hnp: ¬ p, assume hp: p, show q, from absurd hp hnp\n\nexample : (¬p ∨ q) → (p → q) := \nassume h: ¬ p ∨ q, h.elim \n  (λ hnp: ¬ p, λ hp: p, absurd hp hnp) \n  (λ hq: q, λ hp: p, hq)\n\nexample : p ∨ false ↔ p := ⟨\n  assume h: p ∨ false,\n  show p, from h.elim (λ x, x) false.elim,\n\n  λ h: p, or.inl h\n⟩\n\nexample : p ∧ false ↔ false := ⟨\n  λ h: p ∧ false, h.right,\n  λ h: false, ⟨h.elim, h⟩\n⟩\n\nexample : ¬(p ↔ ¬p) := \n  assume h: (p ↔ ¬p),\n  have hl: p -> p -> false, from h.mp,\n  have hnp: p -> false, from λ hp, hl hp hp,\n  have hr: (p -> false) -> p, from h.mpr,\n  have hp: p, from hr hnp,\n  absurd hp hnp\n\nexample : (p → q) → (¬q → ¬p) := \nassume (h: p -> q) (hnq: ¬ q),\nshow ¬ p, from\n  assume hp: p,\n  absurd (h hp) hnq\n\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/3-7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7755444452822299}}
{"text": "import tools.auto.finish\nimport _target.deps.mini_crush.src.mini_crush\n\nnamespace arith\n-- *Artihmetic Expressions Over Natural Numbers\n-- **Source Language\n\n-- binary operation syntax\ninductive binop : Type\n| Plus\n| Times\n\n-- arithmetic expression syntax\ninductive exp : Type\n| Const : ℕ → exp\n| Binop : binop → exp → exp → exp\n\n-- binop denotational semantics\ndef binopDenote : binop → ℕ → ℕ → ℕ\n| binop.Plus  := nat.add\n| binop.Times := nat.mul\n\n-- exp denotational semantics\ndef expDenote : exp → ℕ\n| (exp.Const n)       := n\n| (exp.Binop b e1 e2) := (binopDenote b) (expDenote e1) (expDenote e2)\n\n-- tests using both #reduce and #eval\n#reduce (decidable.to_bool(expDenote (exp.Const 42) = 42))\n#eval   (decidable.to_bool(expDenote (exp.Const 42) = 42))\n\n#reduce (decidable.to_bool(expDenote (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2)) = 4))\n#eval   (decidable.to_bool(expDenote (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2)) = 4))\n\n#reduce (decidable.to_bool(expDenote (exp.Binop binop.Times (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2)) (exp.Const 7)) = 28))\n#eval   (decidable.to_bool(expDenote (exp.Binop binop.Times (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2)) (exp.Const 7)) = 28))\n\n-- **Target Language\n\n-- instruction syntax\ninductive instr : Type\n| iConst : ℕ → instr\n| iBinop : binop → instr\n\n-- program and stack syntax\n-- mark as reducible so lean can unfold the definitions during typechecking\n@[reducible] def prog : Type := list instr\n@[reducible] def stack : Type := list ℕ\n\n-- instr denotational semantics\ndef instrDenote (i : instr) (s : stack) : option stack :=\n    match i with\n    | (instr.iConst n) := some (n :: s)\n    | (instr.iBinop b) :=\n        match s with\n        | arg1 :: arg2 :: s' := some ((binopDenote b) arg1 arg2 :: s')\n        | _ := none\n        end\n    end\n\n-- prog denotational semantics\ndef progDenote : prog → stack → option stack\n| [] s := some s\n| (i :: p') s :=\n    match instrDenote i s with\n    | none    := none\n    | some s' := progDenote p' s'\n    end\n\n-- **Translation\n\ndef compile : exp → prog\n| (exp.Const n)       := instr.iConst n :: []\n| (exp.Binop b e1 e2) := compile e2 ++ compile e1 ++ instr.iBinop b :: []\n\n-- compilation examples\n#reduce compile (exp.Const 42)\n#reduce compile (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2))\n#reduce compile (exp.Binop binop.Times (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2))(exp.Const 7))\n\n-- compilation-evaluation examples\n#reduce progDenote (compile (exp.Const 42)) []\n#reduce progDenote (compile (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2))) []\n#reduce progDenote (compile (exp.Binop binop.Times (exp.Binop binop.Plus (exp.Const 2) (exp.Const 2))(exp.Const 7))) []\n\n-- **Translation Correctness\n\nlemma compile_correct' (e : exp) : ∀ p s, progDenote (compile e ++ p) s = progDenote p (expDenote e :: s) :=\nbegin\ninduction e; intros,\ncase exp.Const {\n    unfold compile,\n    unfold expDenote,\n    simp,\n    unfold progDenote,\n    unfold instrDenote,\n    simp,\n    unfold instrDenote._match_1,\n    unfold progDenote._match_1,\n    refl\n},\ncase exp.Binop {\n    unfold compile,\n    unfold expDenote,\n    simp,    /- can replace these lines with simph -/\n    rw ih_2, /- -/\n    rw ih_1, /- -/\n    unfold progDenote,\n    unfold instrDenote,\n    simp,\n    unfold instrDenote._match_1,\n    unfold instrDenote._match_2,\n    unfold progDenote._match_1,\n    refl\n}\nend\n\nlemma compile_correct'_lean (e : exp) : ∀ p s, progDenote (compile e ++ p) s = progDenote p (expDenote e :: s) :=\nbegin\ninduction e; intros,\ncase exp.Const {refl},\ncase exp.Binop {\n    unfold compile expDenote,\n    simph,\n    refl\n}\nend\n\n@[simp] lemma compile_correct'_crush (e : exp) : ∀ p s, progDenote (compile e ++ p) s = progDenote p (expDenote e :: s) :=\nby mini_crush\n\nlemma app_nil_end {A : Type} (l : list A) : l = l ++ list.nil := by induction l; simph\n\ntheorem compile_correct (e : exp) : progDenote (compile e) [] = some (expDenote e :: []) :=\nbegin\nrw app_nil_end (compile e),\nrw compile_correct',\nrefl\nend\n\n-- TODO: excessive memory consumption\ntheorem compile_correct_crush (e : exp) : progDenote (compile e) [] = some (expDenote e :: []) :=\nby mini_crush\n\nend arith\n\nnamespace typed\n-- *Typed Expressions\n-- **Source Language\n\n-- atomic types\ninductive type : Type\n| Nat\n| Bool\nopen type\n\n-- binop types\ninductive tbinop : type → type → type → Type\n| TPlus  : tbinop Nat Nat Nat\n| TTimes : tbinop Nat Nat Nat\n| TEq    : ∀ t, tbinop t t Bool\n| TLt    : tbinop Nat Nat Bool\nopen tbinop\n\n-- expression types\ninductive texp : type → Type\n| TNConst : ℕ → texp Nat\n| TBConst : bool → texp Bool\n| TBinop : ∀ {t1 t2 t}, tbinop t1 t2 t → texp t1 → texp t2 → texp t\nopen texp\n\n-- type denotational semantics\ndef typeDenote : type → Type\n| Nat := ℕ\n| Bool := bool\n\n-- tbinop denotational semantics\ndef tbinopDenote : ∀ {arg1 arg2 res} (b : tbinop arg1 arg2 res),\n    typeDenote arg1 → typeDenote arg2 → typeDenote res\n| ._ ._ ._ TPlus      := nat.add\n| ._ ._ ._ TTimes     := nat.mul\n| ._ ._ ._ (TEq Nat)  := (λ x y, decidable.to_bool $ x = y)\n| ._ ._ ._ (TEq Bool) := (λ x y, decidable.to_bool $ x = y)\n| ._ ._ ._ TLt        := (λ x y, decidable.to_bool $ nat.le x y)\n\n-- texp denotational semantics\ndef texpDenote : ∀ {t}, texp t → typeDenote t\n| ._ (TNConst n) := n\n| ._ (TBConst b) := b\n| ._ (@TBinop _ _ _ b e1 e2) := (tbinopDenote b) (texpDenote e1) (texpDenote e2)\n\n#reduce texpDenote (TNConst 42)\n#reduce texpDenote (TBConst true)\n-- TODO: is there a way to remove need for _'s?\n#reduce texpDenote (TBinop TTimes (TBinop TPlus (TNConst 2) (TNConst 2)) (TNConst 7))\n#reduce texpDenote (TBinop (TEq Nat) (TBinop TPlus (TNConst 2) (TNConst 2)) (TNConst 7))\n#reduce texpDenote (TBinop TLt (TBinop TPlus (TNConst 2) (TNConst 2)) (TNConst 7))\n\n-- **Target Language\n\n-- stack type to describe how expressions affect the stack\n@[reducible] def tstack := list type\n\ninductive tinstr : tstack → tstack → Type\n| TiNConst : ∀ s, ℕ → tinstr s (Nat :: s)\n| TiBConst : ∀ s, bool → tinstr s (Bool :: s)\n| TiBinop  : ∀ arg1 arg2 res s,\n    tbinop arg1 arg2 res\n    → tinstr (arg1 :: arg2 :: s) (res :: s)\nopen tinstr\n\ninductive tprog : tstack → tstack → Type\n| TNil  : ∀ s, tprog s s\n| TCons : ∀ s1 s2 s3,\n    tinstr s1 s2\n    → tprog s2 s3\n    → tprog s1 s3\nopen tprog\n\ndef vstack : tstack → Type\n| []      := unit\n| (t :: ts) := typeDenote t × vstack ts\n\ndef tinstrDenote : ∀ {ts} {ts'}, tinstr ts ts' → vstack ts → vstack ts'\n| ._ ._ (TiNConst _ n)      := (λ s, (n, s))\n| ._ ._ (TiBConst _ b)      := (λ s, (b, s))\n| ._ ._ (TiBinop _ _ _ _ b) := (λ s,\n    let (arg1, (arg2, s')) := s in\n        ((tbinopDenote b) arg1 arg2, s'))\n\ndef tprogDenote : ∀ {ts} {ts'}, tprog ts ts' → vstack ts → vstack ts'\n| ._ ._ (TNil _) := (λ s, s)\n| ._ ._ (TCons _ _ _ i p) := (λ s, tprogDenote p (tinstrDenote i s))\n\n-- **Translation\n\ndef tconcat : ∀ {ts} {ts'} {ts''}, tprog ts ts' → tprog ts' ts'' → tprog ts ts''\n| ._ ._ ts'' (TNil _) := (λ p, p)\n| ._ ._ ts'' (TCons _ _ _ i p1) := (λ p, TCons _ _ _ i (tconcat p1 p))\n\ndef tcompile : ∀ {t} (e : texp t) (ts : tstack), tprog ts (t :: ts)\n| ._ (TNConst n) _ := TCons _ _ _ (TiNConst _ n) (TNil _)\n| ._ (TBConst b) _ := TCons _ _ _ (TiBConst _ b) (TNil _)\n| ._ (@TBinop _ _ _ b e1 e2) _ := tconcat (tcompile e2 _)\n    (tconcat (tcompile e1 _) (TCons _ _ _ (TiBinop _ _ _ _ b) (TNil _)))\n\n#reduce tprogDenote (tcompile (TNConst 42) []) ()\n#reduce tprogDenote (tcompile (TBConst true) []) ()\n#reduce tprogDenote (tcompile (TBinop TTimes (TBinop TPlus (TNConst 2)\n    (TNConst 2)) (TNConst 7)) []) ()\n#reduce tprogDenote (tcompile (TBinop (TEq Nat) (TBinop TPlus (TNConst 2)\n    (TNConst 2)) (TNConst 7)) []) ()\n#reduce  tprogDenote (tcompile (TBinop TLt (TBinop TPlus (TNConst 2) (TNConst 2))\n    (TNConst 7)) []) ()\n\n-- **Translation Correctness\n\n@[simp] lemma tconcat_correct : ∀ ts ts' ts'' (p : tprog ts ts') (p' : tprog ts' ts'') (s : vstack ts),\n    tprogDenote (tconcat p p') s = tprogDenote p' (tprogDenote p s) :=\nby mini_crush\n\n@[simp] lemma tcompile_correct' : ∀ t (e : texp t) ts (s : vstack ts),\n    tprogDenote (tcompile e ts) s = (texpDenote e, s) :=\nby mini_crush\n\ntheorem tcompile_correct : ∀ t (e : texp t),\n    tprogDenote (tcompile e []) () = (texpDenote e, ()) := by mini_crush\n\nend typed", "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/2_StackMachine.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7755444360330696}}
{"text": "/- Justin Cai, jc5pz -/\n\n/-\nRead, and if you have already read, then re-read, the \nchapters in the notes on proofs of disjunctions and negations. \nWe have added some new material, especially under negation\nelimination.\n\nIn proofs of bi-implications, use comments to mark the start of\nthe proofs of the implications in each direction. Label one as\n\"forward\" the other other as \"backward.\"\n\nThe collaboration policy for this homework is \"no collaboration\nallowed.\" You may study and discuss the underlying concepts with\nanyone.\n\nYou may provide proofs in the style of your choice: term-style,\ntactic style, or mixed. Yes, you can using tactic scripts within\nterms and terms within tactic scripts. You may use any tactics \nyou know of. As a courtesy, we provide begin/end pairs, in case\nyou should want to use them. Otherwise you may delete them.\n-/\n\n/- \n1. 15 points\n-/\nexample : ∀ (P Q : Prop), P ∧ Q → P ∨ Q :=\nbegin\n    intros P Q,\n    assume paq,\n    have p := paq.left,\n    exact or.inl p,\nend\n\n\n/-\n2. 15 points\n-/\nexample : \n    ∀ (P Q R : Prop), (P ∨ Q) → (Q ∨ R) → ¬ Q → (P ∧ R) :=\nbegin\n    intros P Q R,\n    assume poq,\n    assume qor,\n    assume nq,\n    cases poq with p q,\n    cases qor with q r,\n    \n        contradiction,\n        exact and.intro p r,\n        contradiction,\nend \n\n/-\n3. 15 points\n-/\nexample : \n    ∀ (P Q R : Prop), P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) :=\nbegin\n    intros P Q R,\n    apply iff.intro,\n    /- forward -/\n        assume paqor,\n        have p := paqor.1,\n        have qor := paqor.2,\n        cases qor with q r,\n            apply or.inl,\n            exact and.intro p q,\n            apply or.inr,\n            exact and.intro p r,\n    /- backward -/\n        assume paqopar,\n        cases paqopar with paq par,\n           have p := paq.1,\n           have q := paq.2,\n           exact and.intro p (or.inl q),\n           have p := par.1,\n           have r := par.2,\n           exact and.intro p (or.inr r),\nend\n\n\n/-\n4. 10 points\n-/\n\nexample : ∀ (P Q R : Prop), P → Q → R → ¬ Q → (Q ∨ ¬ Q) :=\nbegin\n    intros P Q R,\n    assume p,\n    assume q,\n    assume r,\n    assume nq,\n    contradiction,\nend\n\nopen classical      -- hint: you can now use em easily\n\n/-\n4a. 5 points. Write *your own* proof of this conjecture.\n-/\n\nexample : ∀ (P Q : Prop), ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nbegin\n    intros P Q,\n    apply iff.intro,\n    /- forward-/\n        assume npoq,\n        cases em P with p np,\n        have f : false := npoq (or.inl p),\n        exact false.elim f,\n        cases em Q with q nq,\n        have f : false := npoq (or.inr q),\n        exact false.elim f,\n        exact and.intro np nq,\n    /-backward-/\n        assume npanq,\n        assume npoq,\n        cases npoq with p q,\n        have np := npanq.left,\n        contradiction,\n        have nq := npanq.right,\n        contradiction,\nend\n\n/-\n4b. 5 points. Is this theorem classically true in neither, one, or\nboth directions. Explain your answer in relation to your proof. \n\nAnswer: \nThis theorem is classically true in both directions. It's definitely\nclassically true in forward direction because it requires the use of em \n(aka classical logic) for the proof to even work, and it's classically true\nin backward direction because the backward proof is true in constructive\nlogic, making it also true in classical logic.\n-/\n\n/-\n5. 5 points. Write *your own proof* of this conjecture.\n-/\nexample : ∀ (P Q : Prop), ¬ (P ∧ Q) ↔ (¬ P ∨ ¬ Q) :=\nbegin\n    intros P Q,\n    apply iff.intro,\n    /- forward -/\n        assume npaq,\n        cases em P with p np,\n        cases em Q with q nq,\n        have f : false := npaq (and.intro p q),\n        exact false.elim f,\n        exact or.inr nq,\n        exact or.inl np,\n    /-backward-/\n        assume nponq,\n        assume paq,\n        cases nponq with np nq,\n        have p := paq.left,\n        have f : false := np p,\n        exact false.elim f,\n        have q := paq.right,\n        have f : false := nq q,\n        exact false.elim f,\nend\n\n\n/-\n6. 10 points\n-/\n\nexample : ∀ (P : Prop), (¬ ¬ P → P) ↔ (P ∨ ¬ P) :=\nbegin\n    intro P,\n    apply iff.intro,\n    /-forward-/\n        assume nnpp,\n        cases em P with p np,\n        exact or.inl p,\n        exact or.inr np,\n    /-backward-/\n        assume ponp,\n        assume nnp,\n        cases ponp with p np,\n        exact p,\n        contradiction,\nend\n\n\n/-\n7. 5 points\n\nTranlate the preceding proposition into English,\nreferring explicitly to the principles of negation \nelimination and excluded middle. Write your sentence\nhere:\n\nThe proposition states that for all P of type Prop, (P implies false \nimplies false implies P) implies ((P or P implies false) is true), and vice\nversa.\n\n1. Assumed P\n2. Applied bi-implication introduction\n3. Forward proof\n    a. Assumed not not P implies P\n    b. Used the law of excluded middle (which states that either P or not P\n    must be true) to create two cases for P to prove.\n    I must prove: \n        1. that if P is true then P or not P is true\n        2. and that if not P is true then P or not P is true\n    c. Since I am given a proof of P, I am able to apply the or introduction\n    rule for the left side (which is asking for a proof of P)\n    d. Since I am given a proof of not P, I am able to apply the or \n    introduction rule for the right side (which is asking for a proof of \n    not P)\n4. Backward proof\n    a. Assumed P or not P is true\n    b. Assumed not not P is true\n    c. Created two cases for P or not P to prove.\n    I must prove:\n        1. If P is true, then P is true\n        2. If not P is true, then P is true\n    d. Since I am given a proof of P, all I had to do was apply that proof of P to\n    prove that P is true\n    e. Since I am given a proof of not P and a proof of not not P, there is a \n    contradiction in the proposition due to negation elimination; all I had to do \n    was apply the contradiction rule\n-/\n\n\n/-\n8. [10 points]\n-/\nexample : \n    (∀ ( P Q : Prop ), (P → Q) ↔ (¬ Q → ¬ P)) → \n        ∀ (Raining Wet : Prop), (¬ Wet → ¬ Raining) → \n            (Raining → Wet) :=\nbegin\n    intros PQ,\n    assume Raining Wet,\n    assume nWetnRaining,\n    assume Rain,\n    have RainingWet := PQ Raining Wet,\n    have RWback := RainingWet.2,\n    exact RWback nWetnRaining Rain,\nend\n\nexample : \n    (∀ ( P Q : Prop ), (P → Q) ↔ (¬ Q → ¬ P)) → \n        ∀ (Raining Wet : Prop), (¬ Wet → ¬ Raining) → \n            (Raining → Wet) :=\nbegin\n    intros PQnQnP Raining Wet,\n    assume nwnr,\n    assume r,\n    have pfRW := PQnQnP Raining Wet,\n    apply iff.elim_right pfRW nwnr,\n    exact r,\nend\n\n\n/-\n9. [5 points]\n\nWhat is the name of the principle expressed by the\npremise, (P → Q) ↔ (¬ Q → ¬ P)), in the preceding\nproblem? Answer here:\n\nProof by Contrapositive \n-/", "meta": {"author": "justinqcai", "repo": "CS2102", "sha": "d309f0db3f1df52eb77206ee1e8665a3b49d7a0c", "save_path": "github-repos/lean/justinqcai-CS2102", "path": "github-repos/lean/justinqcai-CS2102/CS2102-d309f0db3f1df52eb77206ee1e8665a3b49d7a0c/hw7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.7754853519428199}}
{"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 ℕ\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 : ℕ) := (n - m) + (m - n)\n\ntheorem dist.def (n m : ℕ) : dist n m = (n - m) + (m - n) := rfl\n\ntheorem dist_comm (n m : ℕ) : dist n m = dist m n :=\nby simp [dist.def, add_comm]\n\n@[simp] theorem dist_self (n : ℕ) : dist n n = 0 :=\nby simp [dist.def, tsub_self]\n\ntheorem eq_of_dist_eq_zero {n m : ℕ} (h : dist n m = 0) : n = m :=\nhave n - m = 0, from nat.eq_zero_of_add_eq_zero_right h,\nhave n ≤ 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 ≤ n, from tsub_eq_zero_iff_le.mp this,\nle_antisymm ‹n ≤ m› ‹m ≤ n›\n\ntheorem dist_eq_zero {n m : ℕ} (h : n = m) : dist n m = 0 :=\nbegin rw [h, dist_self] end\n\ntheorem dist_eq_sub_of_le {n m : ℕ} (h : n ≤ m) : dist n m = m - n :=\nbegin rw [dist.def, tsub_eq_zero_iff_le.mpr h, zero_add] end\n\ntheorem dist_eq_sub_of_le_right {n m : ℕ} (h : m ≤ 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 : ℕ) : m ≤ dist n m + n :=\nle_trans le_tsub_add (add_le_add_right (nat.le_add_left _ _) _)\n\ntheorem dist_tri_right (n m : ℕ) : m ≤ n + dist n m :=\nby rw add_comm; apply dist_tri_left\n\ntheorem dist_tri_left' (n m : ℕ) : n ≤ dist n m + m :=\nby rw dist_comm; apply dist_tri_left\n\ntheorem dist_tri_right' (n m : ℕ) : n ≤ m + dist n m :=\nby rw dist_comm; apply dist_tri_right\n\ntheorem dist_zero_right (n : ℕ) : dist n 0 = n :=\neq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n)\n\ntheorem dist_zero_left (n : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ} (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 : ℕ) : dist n k ≤ 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 : ℕ) : 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 : ℕ) : 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 ≥ 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 ≠ j → 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": "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/nat/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7754853368467013}}
{"text": "/-\nExercise 3.\nLet us define the binary relation ~> as follow:\nLet X and Y be two sets, and f : X → V be some function between the sets, then ∀ x, y ∈ X, x ~> y if and only if f(x) = f(y).\n\nCan you prove that ~> is an equivalence relation?\nReplace the sorry for your proof.\n\nHere are some basic tactics that might help : http://wwwf.imperial.ac.uk/~buzzard/xena/html/source/tactics/guide.html\n-/\n\nuniverse u\nvariables {X V : Type u}\n\n-- Defining crel as the aforementioned binary relation with notation ~>\ndef crel (f : X → V) (x y : X) := f x = f y\ninfix ` ~> `: 50 := crel\n\n\n@[simp] lemma crel_refl : ∀ f : X → V, reflexive ((~>) f) := \nbegin \n    sorry\nend\n\n@[simp] lemma crel_symm : ∀ f : X → V, symmetric ((~>) f) :=\nbegin\n    sorry\nend\n\n@[simp] lemma crel_trans : ∀ f : X → V, transitive ((~>) f) :=\nbegin\n    sorry\nend\n\ntheorem crel_eq : ∀ f : X → V, equivalence ((~>) f) :=\nbegin\n    sorry\nend", "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/Exercises/Exercies3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012762876286, "lm_q2_score": 0.819893340314393, "lm_q1q2_score": 0.7754561676890799}}
{"text": "import data.real.basic\n\nvariables {x y : ℝ}\n\n#check lt_or_le\n#check @abs_of_neg\n#check @abs_of_nonneg\n\nnamespace my_abs\n\n-- BEGIN\n\ntheorem abs_add : abs (x + y) ≤ abs x + abs y :=\nbegin\n  cases lt_or_le x 0 with hx hx;\n  cases lt_or_le y 0 with hy hy;\n  cases lt_or_le (x + y) 0 with hxy hxy;\n  simp [abs_of_neg, abs_of_nonneg, hx, hy, hxy];\n  linarith,\nend\n\n-- END\n\nend my_abs", "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/ex3_cases_abs_add.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012717045181, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.7754561576879141}}
{"text": "import MyNat.Power\nimport MyNat.Multiplication\nimport PowerWorld.Level5 -- pow_add\nnamespace MyNat\nopen MyNat\n\n/-!\n# Power World\n\n## Level 7: `pow_pow`\n\nBoss level! What will the collectible be?\n\n## Lemma\nFor all naturals `a`, `m`, `n`, we have `(a ^ m) ^ n = a ^ {mn}`.\n-/\nlemma pow_pow (a m n : MyNat) : (a ^ m) ^ n = a ^ (m * n) := by\n  induction n with\n  | zero =>\n    rw [zero_is_0]\n    rw [mul_zero]\n    repeat rw [pow_zero]\n  | succ n ih =>\n    rw [pow_succ]\n    rw [ih]\n    rw [mul_succ]\n    rw [pow_add]\n\n\n/-!\nApparently Lean can't find a collectible, even though you feel like you\njust finished power world so you must have proved *something*. What should the\ncollectible for this level be called?\n\nBut what is this? It's one of those twists where there's another\nboss after the boss you thought was the final boss! Go to the next\nlevel!\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/PowerWorld/Level7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9539660962919971, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7754478533515282}}
{"text": "variables (real : Type) [ordered_ring real]\nvariables (log exp : real → real)\nvariable  log_exp_eq : ∀ x, log (exp x) = x\nvariable  exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x\nvariable  exp_pos    : ∀ x, exp x > 0\nvariable  exp_add    : ∀ 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): exp (x + y + z) = exp x * exp y * exp z := begin\nrw [exp_add, exp_add]\nend\n\nexample (y : real) (h : y > 0)  : exp (log y) = y := begin\nexact exp_log_eq h\nend\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y := begin\nrw [\n  <- exp_log_eq hx,\n  <- exp_log_eq hy,\n  <- exp_add (log x) (log y),\n  log_exp_eq,\n  log_exp_eq,\n  log_exp_eq\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.6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7754020419906791}}
{"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ölzl, Scott Morrison, Jens Wagemaker\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.eval\nimport Mathlib.tactic.interval_cases\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\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\nnamespace polynomial\n\n\ntheorem nat_degree_comp_le {R : Type u} [semiring R] {p : polynomial R} {q : polynomial R} : nat_degree (comp p q) ≤ nat_degree p * nat_degree q := sorry\n\ntheorem degree_map_le {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) : degree (map f p) ≤ degree p := sorry\n\ntheorem nat_degree_map_le {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) : nat_degree (map f p) ≤ nat_degree p := sorry\n\ntheorem degree_map_eq_of_leading_coeff_ne_zero {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (hf : coe_fn f (leading_coeff p) ≠ 0) : degree (map f p) = degree p := sorry\n\ntheorem nat_degree_map_of_leading_coeff_ne_zero {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (hf : coe_fn f (leading_coeff p) ≠ 0) : nat_degree (map f p) = nat_degree p :=\n  nat_degree_eq_of_degree_eq (degree_map_eq_of_leading_coeff_ne_zero f hf)\n\ntheorem leading_coeff_map_of_leading_coeff_ne_zero {R : Type u} {S : Type v} [semiring R] {p : polynomial R} [semiring S] (f : R →+* S) (hf : coe_fn f (leading_coeff p) ≠ 0) : leading_coeff (map f p) = coe_fn f (leading_coeff p) := sorry\n\ntheorem degree_pos_of_root {R : Type u} {a : R} [semiring R] {p : polynomial R} (hp : p ≠ 0) (h : is_root p a) : 0 < degree p := sorry\n\ntheorem nat_degree_pos_of_eval₂_root {R : Type u} {S : Type v} [semiring R] [semiring S] {p : polynomial R} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ (x : R), coe_fn f x = 0 → x = 0) : 0 < nat_degree p := sorry\n\ntheorem degree_pos_of_eval₂_root {R : Type u} {S : Type v} [semiring R] [semiring S] {p : polynomial R} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ (x : R), coe_fn f x = 0 → x = 0) : 0 < degree p :=\n  iff.mp nat_degree_pos_iff_degree_pos (nat_degree_pos_of_eval₂_root hp f hz inj)\n\ntheorem degree_map_eq_of_injective {R : Type u} {S : Type v} [semiring R] [semiring S] {f : R →+* S} (hf : function.injective ⇑f) (p : polynomial R) : degree (map f p) = degree p := sorry\n\ntheorem degree_map' {R : Type u} {S : Type v} [semiring R] [semiring S] {f : R →+* S} (hf : function.injective ⇑f) (p : polynomial R) : degree (map f p) = degree p :=\n  degree_map_eq_of_injective hf p\n\ntheorem nat_degree_map' {R : Type u} {S : Type v} [semiring R] [semiring S] {f : R →+* S} (hf : function.injective ⇑f) (p : polynomial R) : nat_degree (map f p) = nat_degree p :=\n  nat_degree_eq_of_degree_eq (degree_map' hf p)\n\ntheorem leading_coeff_map' {R : Type u} {S : Type v} [semiring R] [semiring S] {f : R →+* S} (hf : function.injective ⇑f) (p : polynomial R) : leading_coeff (map f p) = coe_fn f (leading_coeff p) := sorry\n\ntheorem monomial_nat_degree_leading_coeff_eq_self {R : Type u} [semiring R] {f : polynomial R} (h : finset.card (finsupp.support f) ≤ 1) : coe_fn (monomial (nat_degree f)) (leading_coeff f) = f := sorry\n\ntheorem C_mul_X_pow_eq_self {R : Type u} [semiring R] {f : polynomial R} (h : finset.card (finsupp.support f) ≤ 1) : coe_fn C (leading_coeff f) * X ^ nat_degree f = 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/degree/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7753737543541072}}
{"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\nimport probability.cond_count\nimport probability.notation\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 (α ↪ β)` which this proof\nuses is `fintype.card_embedding_eq`.\n-/\n\nlocal notation (name := finset.card)  `|` x `|` := finset.card x\nlocal notation (name := fintype.card) `‖` x `‖` := fintype.card x\n\n/-- **Birthday Problem**: set cardinality interpretation. -/\ntheorem birthday :\n  2 * ‖fin 23 ↪ fin 365‖ < ‖fin 23 → fin 365‖ ∧ 2 * ‖fin 22 ↪ fin 365‖ > ‖fin 22 → fin 365‖ :=\nbegin\n  simp only [nat.desc_factorial, fintype.card_fin, fintype.card_embedding_eq, fintype.card_fun],\n  norm_num\nend\n\nsection measure_theory\n\nopen measure_theory probability_theory\nopen_locale probability_theory ennreal\n\nvariables {n m : ℕ}\n\n/- In order for Lean to understand that we can take probabilities in `fin 23 → fin 365`, we must\ntell Lean that there is a `measurable_space` structure on the space. Note that this instance\nis only for `fin m` - Lean automatically figures out that the function space `fin n → fin m`\nis _also_ measurable, by using `measurable_space.pi`, and furthermore that all sets are measurable,\nfrom `measurable_singleton_class.pi`. -/\ninstance : measurable_space (fin m) := ⊤\ninstance : measurable_singleton_class (fin m) := ⟨λ _, trivial⟩\n\n/- We then endow the space with a canonical measure, which is called ℙ.\nWe define this to be the conditional counting measure. -/\nnoncomputable instance : measure_space (fin n → fin m) := ⟨cond_count set.univ⟩\n\n/- The canonical measure on `fin n → fin m` is a probability measure (except on an empty space). -/\ninstance : is_probability_measure (ℙ : measure (fin n → fin (m + 1))) :=\ncond_count_is_probability_measure set.finite_univ set.univ_nonempty\n\nlemma fin_fin.measure_apply {s : set $ fin n → fin m} :\n  ℙ s = (|s.to_finite.to_finset|) / ‖fin n → fin m‖ :=\nby erw [cond_count_univ, measure.count_apply_finite]\n\n/-- **Birthday Problem**: first probabilistic interpretation. -/\ntheorem birthday_measure : ℙ {f : fin 23 → fin 365 | function.injective f} < 1 / 2 :=\nbegin\n  -- most of this proof is essentially converting it to the same form as `birthday`.\n  rw [fin_fin.measure_apply],\n  generalize_proofs hfin,\n  have : |hfin.to_finset| = 42200819302092359872395663074908957253749760700776448000000,\n  { transitivity ‖fin 23 ↪ fin 365‖,\n    { simp_rw [←fintype.card_coe, set.finite.coe_sort_to_finset, set.coe_set_of],\n      exact fintype.card_congr (equiv.subtype_injective_equiv_embedding _ _) },\n    { simp only [fintype.card_embedding_eq, fintype.card_fin, nat.desc_factorial],\n      norm_num } },\n  rw [this, ennreal.lt_div_iff_mul_lt, mul_comm, mul_div, ennreal.div_lt_iff],\n  rotate, iterate 2 { right, norm_num }, iterate 2 { left, norm_num },\n  norm_cast,\n  simp only [fintype.card_pi, fintype.card_fin],\n  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/archive/100-theorems-list/93_birthday_problem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582574225517, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7753737488956159}}
{"text": "-- El punto de acumulación de las convergentes es su límite\n-- ========================================================\n\nimport data.real.basic\n\nvariable  {u : ℕ → ℝ}\nvariables {a b: ℝ}\nvariables (x y : ℝ)\nvariable  {φ : ℕ → ℕ}\n\n-- ----------------------------------------------------\n-- Nota. Usaremos los siguientes conceptos estudiados\n-- anteriormente.\n-- ----------------------------------------------------\n\nnotation `|`x`|` := abs x\n\ndef limite : (ℕ → ℝ) → ℝ → Prop :=\nλ u c, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - c| ≤ ε\n\nlemma cero_de_abs_mn_todos\n  (h : ∀ ε > 0, |x| ≤ ε)\n  : x = 0 :=\nabs_eq_zero.mp\n  (eq_of_le_of_forall_le_of_dense (abs_nonneg x) h)\n\nlemma ig_de_abs_sub_mne_todos\n  (h : ∀ ε > 0, |x - y| ≤ ε)\n  : x = y :=\nsub_eq_zero.mp (cero_de_abs_mn_todos (x - y) h)\n\nlemma unicidad_limite\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  apply ig_de_abs_sub_mne_todos,\n  intros ε hε,\n  cases ha (ε/2) (by linarith) with Na hNa,\n  cases hb (ε/2) (by linarith) with Nb hNb,\n  let N := max Na Nb,\n  specialize hNa N (by finish),\n  specialize hNb N (by finish),\n  calc |a - b|\n       = |(a - u N) + (u N - b)| : by ring\n   ... ≤ |a - u N| + |u N - b|   : by apply abs_add\n   ... = |u N - a| + |u N - b|   : by rw abs_sub\n   ... ≤ ε                       : by linarith [hNa, hNb]\nend\n\ndef extraccion : (ℕ → ℕ) → Prop\n| φ := ∀ n m, n < m → φ n < φ m\n\nlemma id_mne_extraccion\n  (h : extraccion φ)\n  : ∀ n, n ≤ φ 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\ndef punto_acumulacion : (ℕ → ℝ) → ℝ → Prop\n| u a := ∃ φ, extraccion φ ∧ limite (u ∘ φ) a\n\nlemma limite_subsucesion\n  (h : limite u a)\n  (hφ : extraccion φ)\n  : limite (u ∘ φ) a :=\nassume ε,\nassume hε : ε > 0,\nexists.elim (h ε hε)\n ( assume N,\n   assume hN : ∀ n, n ≥ N → |u n - a| ≤ ε,\n   have h1 : ∀n, n ≥ N → |(u ∘ φ) n - a| ≤ ε,\n     { assume n,\n       assume hn : n ≥ N,\n       have h2 : N ≤ φ n, from\n         calc N ≤ n   : hn\n           ... ≤ φ n : id_mne_extraccion hφ n,\n       show |(u ∘ φ) n - a| ≤ ε,\n         from hN (φ n) h2,\n     },\n   show ∃ N, ∀n, n ≥ N → |(u ∘ φ) n - a| ≤ ε,\n     from exists.intro N h1)\n\n-- ----------------------------------------------------\n-- Ejercicio. Demostrar que si a es un punto de\n-- acumulación de una sucesión de límite b, entonces a\n-- y b son iguales.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample\n  (ha : punto_acumulacion u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  -- unfold punto_acumulacion at ha,\n  rcases ha with ⟨φ, hφ₁, hφ₂⟩,\n  have hφ₃ : limite (u ∘ φ) b,\n    from limite_subsucesion hb hφ₁,\n  exact unicidad_limite hφ₂ hφ₃,\nend\n\n-- 2ª demostración\nexample\n  (ha : punto_acumulacion u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  rcases ha with ⟨φ, hφ₁, hφ₂⟩,\n  exact unicidad_limite hφ₂ (limite_subsucesion hb hφ₁),\nend\n\n-- 3ª demostración\nexample\n  (ha : punto_acumulacion u a)\n  (hb : limite u b)\n  : a = b :=\nexists.elim ha\n  (λ φ hφ, unicidad_limite hφ.2 (limite_subsucesion hb hφ.1))\n\n-- 4ª demostración\nexample\n  (ha : punto_acumulacion u a)\n  (hb : limite u b)\n  : a = b :=\nexists.elim ha\n  ( assume φ,\n    assume hφ : extraccion φ ∧ limite (u ∘ φ) a,\n    have hφ' : limite (u ∘ φ) b,\n      from limite_subsucesion hb hφ.1,\n    show a = b,\n      from unicidad_limite hφ.2 hφ')\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/acumulacion_limite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7751978239211168}}
{"text": "-- Las partes estrictas de los órdenes parciales son transitivas\n-- =============================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. La parte estricta de una relación R es la \n-- relación R' definida por\n--    R' a b := R a b ∧ a ≠ b\n-- \n-- Demostrar que si R es un orden parcial, entonces su \n-- parte estricta es transitiva.\n-- ----------------------------------------------------\n\nimport tactic\n\nsection\n\nparameter {A : Type} \nparameter (R : A → A → Prop)\nparameter (reflR    : reflexive R)\nparameter (transR   : transitive R)\nparameter (antisimR : anti_symmetric R)\nvariables {a b c : A}\n\ndefinition R' (a b : A) : Prop := \n  R a b ∧ a ≠ b\n\ninclude transR\ninclude antisimR\n\n-- 1ª demostración\nexample : transitive R' :=\nbegin\n  rintros a b c ⟨h1,h2⟩ ⟨h3,h4⟩,\n  split,\n  { apply (transR h1 h3), },\n  { intro h5,\n    apply h4,\n    apply (antisimR h3),\n    rw ←h5,\n    exact h1, },\nend\n\n-- 2ª demostración\n-- ===============\n\nlocal infix ≤ := R\nlocal infix < := R'\n\nexample : transitive (<) :=\nassume a b c,\nassume h₁ : a < b,\nassume h₂ : b < c,\nhave a ≤ b, from and.left h₁,\nhave a ≠ b, from and.right h₁,\nhave b ≤ c, from and.left h₂,\nhave b ≠ c, from and.right h₂,\nhave a ≤ c, from transR ‹a ≤ b› ‹b ≤ c›,\nhave a ≠ c, from\n    assume : a = c,\n    have c ≤ b, from eq.subst ‹a = c› ‹a ≤ b›,\n    have b = c, from antisimR ‹b ≤ c› ‹c ≤ b›,\n    show false, from ‹b ≠ c› ‹b = c›,\nshow a < c, from and.intro ‹a ≤ c› ‹a ≠ c›\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/4_Relaciones/Las_partes_estrictas_de_los_ordenes_parciales_son_transitivas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7751978149991471}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_zero\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level2 -- add_assoc\nimport AdditionWorld.Level3 -- succ_add\nimport InequalityWorld.Level5 -- le_trans\nimport InequalityWorld.Level6 -- le_antisymm\nimport InequalityWorld.Level10 -- le_succ_self\nimport AdvancedAdditionWorld.Level13 -- ne_succ_self\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 16: equivalence of two definitions of `<`\n\nNow let's go the other way.\n\n## Lemma : lt_aux₂\nFor all naturals `a` and `b`, `succ a ≤ b  ⟹ a ≤ b ∧ ¬ (b ≤ a)`.\n-/\nlemma lt_aux₂ (a b : MyNat) : succ a ≤ b → a ≤ b ∧ ¬ (b ≤ a) := by\n  intro h\n  constructor\n  {\n    apply le_trans a (succ a) b\n    exact le_succ_self a\n    exact h\n  }\n  {\n    intro nh\n    apply ne_succ_self a\n    apply le_antisymm a (succ a)\n    exact le_succ_self a\n    exact le_trans (succ a) b a h nh\n  }\n\n/-!\nNow for the payoff.\n\nNext up [Level 17](./Level17.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/Level16.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9481545348152283, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7751869534738813}}
{"text": "-- Conmutatividad_del_minimo.lean\n-- Si a, b ∈ ℝ, entonces min(a,b) = min(b,a)\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 29-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si a, b ∈ ℝ, entonces min(a,b) = min(b,a)\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : ℝ\n\n-- 1ª demostración\n-- ===============\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  { show min a b ≤ min b a,\n    apply le_min,\n    { apply min_le_right },\n    { apply min_le_left }},\n  { show min b a ≤ min a b,\n    apply le_min,\n    { apply min_le_right },\n    { apply min_le_left }},\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : min a b = min b a :=\nbegin\n  have h : ∀ x y : ℝ, min x y ≤ min y x,\n  { intros x y,\n    apply le_min,\n    { apply min_le_right },\n    { apply min_le_left }},\n  apply le_antisymm,\n  apply h,\n  apply h,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : min a b = min b a :=\nbegin\n  have h : ∀ {x y : ℝ}, min x y ≤ min y x,\n  { intros x y,\n    exact le_min (min_le_right x y) (min_le_left x y) },\n  exact le_antisymm h h,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left },\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/Conmutatividad_del_minimo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7751443648951719}}
{"text": "import .love12_basic_mathematical_structures_demo\n\n\n/- # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Question 1: Type Classes\n\nRecall the inductive type `btree` we introduced earlier: -/\n\n#check btree\n\n/- The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/- 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [btree.graft, ih_l, ih_r] }\nend\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [btree.graft, ih_l, ih_r] }\nend\n\n/- 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\n{ add       := btree.graft,\n  add_assoc := btree.graft_assoc,\n  zero      := btree.empty,\n  add_zero  := btree.graft_empty,\n  zero_add  := by intro x; refl }\n\n/- 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/- No matter how we define `neg` (`-`), we will not be able to prove\n`add_left_neg`, which amounts to the following property:\n\n    `∀t, btree.graft (btree.neg t) t = btree.empty`\n\nHowever, if `t` is a nonempty tree, `btree.graft _ t` cannot possibly be equal\nto `btree.empty`, no matter what the first argument is. -/\n\n/- 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀ y : btree ℕ, btree.graft y x ≠ btree.empty :=\nbegin\n  apply exists.intro (btree.node 0 btree.empty btree.empty),\n  intros y hy,\n  cases' y,\n  { cases' hy },\n  { cases' hy }\nend\n\n\n/- ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/- 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    rw multiset.elems,\n    rw mirror,\n    rw ←ih_l,\n    rw ←ih_r,\n    rw multiset.elems,\n    cc }\nend\n\n/- 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    rw finset.elems,\n    rw mirror,\n    rw ←ih_l,\n    rw ←ih_r,\n    rw finset.elems,\n    cc }\nend\n\n/- 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nbtree.node 0 (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\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/love12_basic_mathematical_structures_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.920789673717312, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7751443594056346}}
{"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 algebra.gcd_monoid.finset\nimport number_theory.padics.padic_val\n\n/-!\n# Basic results about setwise gcds on ℕ\n\nThis file proves some basic results about `finset.gcd` on `ℕ`.\n\n## Main results\n* `finset.coprime_of_div_gcd`: The elements of a set divided through by their gcd are coprime.\n\n-/\n\ninstance : is_idempotent ℕ gcd_monoid.gcd := ⟨nat.gcd_self⟩\n\nnamespace finset\n\ntheorem coprime_of_div_gcd (s : finset ℕ) {x : ℕ} (hx : x ∈ s) (hnz : x ≠ 0) :\n  s.gcd (/ (s.gcd id)) = 1 :=\nbegin\n  rw nat.eq_one_iff_not_exists_prime_dvd,\n  intros p hp hdvd,\n  haveI : fact p.prime := ⟨hp⟩,\n  rw dvd_gcd_iff at hdvd,\n  replace hdvd : ∀ b ∈ s, s.gcd id * p ∣ b,\n  { intros b hb,\n    specialize hdvd b hb,\n    rwa nat.dvd_div_iff at hdvd,\n    apply gcd_dvd hb },\n  have : s.gcd id ≠ 0 := (not_iff_not.mpr gcd_eq_zero_iff).mpr (λ h, hnz $ h x hx),\n  apply @pow_succ_padic_val_nat_not_dvd p _ _ this.bot_lt,\n  apply dvd_gcd,\n  intros b hb,\n  obtain ⟨k, rfl⟩ := hdvd b hb,\n  rw [id, mul_right_comm, pow_succ', mul_dvd_mul_iff_right hp.ne_zero],\n  apply dvd_mul_of_dvd_left,\n  exact pow_padic_val_nat_dvd\nend\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/gcd_monoid/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7751443575700987}}
{"text": "import data.set\n\nopen set\n\nnamespace mth1001\n\nvariable A : Type*\nvariables (S T : set A)\n\n#check powerset\n#check mem_set_of_eq\n#check mem_union_eq\n#check subset_def\n#check subset_union_left\n\n/-\nType `𝒫` as `\\power`\n-/\n\nexample : (𝒫 S) ∪ (𝒫 T) ⊆ 𝒫 (S ∪ T) :=\nbegin\n  -- Using the definition of subset, we must show, `∀ x, x ∈ 𝒫 S ∪ 𝒫 T → x ∈ 𝒫 (S ∪ T)`.\n--  rw subset_def, \n  intro x, -- Assume `x : U`.\n  intro h, -- Assume `h : x ∈ 𝒫 S ∪ 𝒫 T`.\n  rw mem_union_eq at h, -- By definition, `h : x ∈ 𝒫 S ∨ 𝒫 T`.\n  /-\n  By or elim., it suffices to prove the goal under the assumptions\n  1. `h₂ : x ∈ 𝒫 S`,\n  2. `h₃ : x ∈ 𝒫 T`.\n  -/\n  -- By repeated definion of 𝒫 and ∈, `h : x ⊆ S ∨ x ⊆ T`. The goal is `x ⊆ S ∪ T`.\n  repeat { rw [powerset, mem_set_of_eq] at *, }, \n  cases h with h₂ h₃,\n  { have h₄ : S ⊆ S ∪ T, from set.subset_union_left S T,\n    transitivity,\n    { exact h₂,}, \n    { exact h₄, }, },\n  { transitivity,\n    { exact h₃, },\n    { exact set.subset_union_right S T, }, },\nend\n\n/-\nThe converse of the above result is *not* true. Here's a proof by counterexample.\n-/\nexample : ¬(∀ A : Type*, ∀ S T : set A, 𝒫 (S ∪ T) ⊆  (𝒫 S) ∪ (𝒫 T)) :=\nbegin\n  push_neg, -- Negating, the goal is `∃ A, ∃ S T : set A, ¬(𝒫 (S ∪ T) ⊆ 𝒫 S ∪ 𝒫 T)`.\n  use [ℤ, {1}, {2}], -- We'll take `A` as `ℤ`, `S` as `{1}` and `T` as `{2}`.\n  repeat { rw powerset },    -- Apply repeatedly the definitions of powerset\n  repeat { rw subset_def },  -- and subset,\n  norm_num, -- negating and noting `{1} ∪ {2} = {2, 1}`, the goal is to prove\n  -- `∃ (x : set ℤ), x ⊆ {2, 1} ∧ ¬(x ⊆ {1} ∨ x ⊆ {2})`\n  use {1, 2}, -- We take `{1, 2}` for `x`.\n  split, /- It suffices to prove the two goals:\n  1. `{1, 2} ⊆ {2, 1}` and\n  2. `({1, 2} ⊆ {1} ∨ {1, 2} ⊆ {2})`\n  -/\n  { rw subset_def, -- We solve the first subgoal by definition of subset\n    finish, },     -- and rules of logic.\n  { repeat { rw subset_def }, -- By repeated application of the definition of subset\n    push_neg, -- and negating, we must show\n    -- `(∃ (x : ℤ), x ∈ {1, 2} ∧ x ∉ {1}) ∧ ∃ (x : ℤ), x ∈ {1, 2} ∧ x ∉ {2}`.    \n    split, /- By and introduction, this splits into two subgoals:\n    2.1. `∃ (x : ℤ), x ∈ {1, 2} ∧ x ∉ {1}`.\n    2.2. `∃ (x : ℤ), x ∈ {1, 2} ∧ x ∉ {2}`.\n    -/\n    { use 2, finish, }, -- We close the goal by showing `2 ∈ {1, 2} ∧ 2 ∉ {1}`.\n    { use 1, finish, }, }, -- We close the goal by showing `1 ∈ {1, 2} ∧ 1 ∉ {2}`.\nend\n\n-- Exercise 141:\nexample : (𝒫 S) ∩ (𝒫 T) ⊆ 𝒫 (S ∩ T) :=\nbegin\n  sorry  \nend\n\n-- Exercise 142:\nexample : 𝒫 (S ∩ T) ⊆ (𝒫 S) ∩ (𝒫 T) :=\nbegin\n  sorry  \nend\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_28_powerset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.775107343459989}}
{"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ébastien Gouëzel\n-/\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 : ℕ`, `λ x, x ^ n` is convex\n  and strictly convex when `2 ≤ n`.\n* `convex_on_pow`, `strict_convex_on_pow` : For `n : ℕ`, `λ x, x ^ n` is convex on $[0, +∞)$ and\n  strictly convex when `2 ≤ n`.\n* `convex_on_zpow`, `strict_convex_on_zpow` : For `m : ℤ`, `λ x, x ^ m` is convex on $[0, +∞)$ and\n  strictly convex when `m ≠ 0, 1`.\n* `convex_on_rpow`, `strict_convex_on_rpow` : For `p : ℝ`, `λ x, x ^ p` is convex on $[0, +∞)$ when\n  `1 ≤ 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, +∞)$ and $(-∞, 0)$ respectively.\n\n## TODO\n\nFor `p : ℝ`, prove that `λ x, x ^ p` is concave when `0 ≤ p ≤ 1` and strictly concave when\n`0 < p < 1`.\n-/\n\nopen real set\nopen_locale big_operators nnreal\n\n/-- `exp` is strictly convex on the whole real line. -/\nlemma strict_convex_on_exp : strict_convex_on ℝ univ exp :=\nstrict_convex_on_univ_of_deriv2_pos continuous_exp (λ x, (iter_deriv_exp 2).symm ▸ exp_pos x)\n\n/-- `exp` is convex on the whole real line. -/\nlemma convex_on_exp : convex_on ℝ univ exp := strict_convex_on_exp.convex_on\n\n/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even -/\nlemma even.convex_on_pow {n : ℕ} (hn : even n) : convex_on ℝ set.univ (λ x : ℝ, 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 ⟨k, hk⟩ := (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 : ℕ` is strictly convex on the whole real line whenever `n ≠ 0` is even. -/\nlemma even.strict_convex_on_pow {n : ℕ} (hn : even n) (h : n ≠ 0) :\n  strict_convex_on ℝ set.univ (λ x : ℝ, x^n) :=\nbegin\n  apply strict_mono.strict_convex_on_univ_of_deriv (continuous_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 : ℕ` is convex on `[0, +∞)` for all `n` -/\nlemma convex_on_pow (n : ℕ) : convex_on ℝ (Ici 0) (λ x : ℝ, 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 ℝ _ _ _).const_mul (n : ℝ) },\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 : ℕ` is strictly convex on `[0, +∞)` for all `n` greater than `2`. -/\nlemma strict_convex_on_pow {n : ℕ} (hn : 2 ≤ n) : strict_convex_on ℝ (Ici 0) (λ x : ℝ, x^n) :=\nbegin\n  apply strict_mono_on.strict_convex_on_of_deriv (convex_Ici _) (continuous_on_pow _),\n  rw [deriv_pow', interior_Ici],\n  exact λ 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\n/-- Specific case of Jensen's inequality for sums of powers -/\nlemma real.pow_sum_div_card_le_sum_pow {α : Type*} {s : finset α} {f : α → ℝ} (n : ℕ)\n  (hf : ∀ a ∈ s, 0 ≤ f a) : (∑ x in s, f x) ^ (n + 1) / s.card ^ n ≤ ∑ x in s, (f x) ^ (n + 1) :=\nbegin\n  rcases s.eq_empty_or_nonempty with rfl | hs,\n  { simp_rw [finset.sum_empty, zero_pow' _ (nat.succ_ne_zero n), zero_div] },\n  { have hs0 : 0 < (s.card : ℝ) := nat.cast_pos.2 hs.card_pos,\n    suffices : (∑ x in s, f x / s.card) ^ (n + 1) ≤ ∑ x in s, (f x ^ (n + 1) / s.card),\n    { rwa [← finset.sum_div, ← finset.sum_div, div_pow, pow_succ' (s.card : ℝ),\n        ← div_div, div_le_iff hs0, div_mul, div_self hs0.ne', div_one] at this },\n    have := @convex_on.map_sum_le ℝ ℝ ℝ α _ _ _ _ _ _ (set.Ici 0) (λ x, x ^ (n + 1)) s\n      (λ _, 1 / s.card) (coe ∘ f) (convex_on_pow (n + 1)) _ _ (λ i hi, set.mem_Ici.2 (hf i hi)),\n    { simpa only [inv_mul_eq_div, one_div, algebra.id.smul_eq_mul] using this },\n    { simp only [one_div, inv_nonneg, nat.cast_nonneg, implies_true_iff] },\n    { simpa only [one_div, finset.sum_const, nsmul_eq_mul] using mul_inv_cancel hs0.ne' } }\nend\n\nlemma nnreal.pow_sum_div_card_le_sum_pow {α : Type*} (s : finset α) (f : α → ℝ≥0) (n : ℕ) :\n  (∑ x in s, f x) ^ (n + 1) / s.card ^ n ≤ ∑ x in s, (f x) ^ (n + 1) :=\nby simpa only [← nnreal.coe_le_coe, nnreal.coe_sum, nonneg.coe_div, nnreal.coe_pow] using\n  @real.pow_sum_div_card_le_sum_pow α s (coe ∘ f) n (λ _ _, nnreal.coe_nonneg _)\n\nlemma finset.prod_nonneg_of_card_nonpos_even\n  {α β : Type*} [linear_ordered_comm_ring β]\n  {f : α → β} [decidable_pred (λ x, f x ≤ 0)]\n  {s : finset α} (h0 : even (s.filter (λ x, f x ≤ 0)).card) :\n  0 ≤ ∏ x in s, f x :=\ncalc 0 ≤ (∏ x in s, ((if f x ≤ 0 then (-1:β) else 1) * f x)) :\n  finset.prod_nonneg (λ x _, by\n    { split_ifs with hx hx, by simp [hx], simp at hx ⊢, 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 : ℤ) (n : ℕ) (hn : even n) :\n  0 ≤ ∏ k in finset.range n, (m - k) :=\nbegin\n  rcases hn with ⟨n, rfl⟩,\n  induction n with n ihn, { simp },\n  rw ← two_mul at ihn,\n  rw [← two_mul, nat.succ_eq_add_one, mul_add, mul_one, bit0, ← 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 ≤ k + 1, from hmk.trans (lt_add_one ↑k).le,\n    convert mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) _,\n    convert 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 : ℤ} {n : ℕ} (hn : even n) (hm : m ∉ Ico (0 : ℤ) n) :\n  0 < ∏ k in finset.range n, (m - k) :=\nbegin\n  refine (int_prod_range_nonneg m n hn).lt_of_ne (λ h, hm _),\n  rw [eq_comm, finset.prod_eq_zero_iff] at h,\n  obtain ⟨a, ha, h⟩ := h,\n  rw sub_eq_zero.1 h,\n  exact ⟨int.coe_zero_le _, int.coe_nat_lt.2 $ finset.mem_range.1 ha⟩,\nend\n\n/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` -/\nlemma convex_on_zpow (m : ℤ) : convex_on ℝ (Ioi 0) (λ x : ℝ, x^m) :=\nbegin\n  have : ∀ n : ℤ, differentiable_on ℝ (λ x, x ^ n) (Ioi (0 : ℝ)),\n    from λ 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 : ℤ` is convex on `(0, +∞)` for all `m` except `0` and `1`. -/\nlemma strict_convex_on_zpow {m : ℤ} (hm₀ : m ≠ 0) (hm₁ : m ≠ 1) :\n  strict_convex_on ℝ (Ioi 0) (λ x : ℝ, x^m) :=\nbegin\n  apply strict_convex_on_of_deriv2_pos' (convex_Ioi 0),\n  { exact (continuous_on_zpow₀ m).mono (λ x hx, ne_of_gt hx) },\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) (λ hm, _),\n  norm_cast at hm,\n  rw ← finset.coe_Ico at hm,\n  fin_cases hm; cc,\nend\n\nlemma convex_on_rpow {p : ℝ} (hp : 1 ≤ p) : convex_on ℝ (Ici 0) (λ x : ℝ, x^p) :=\nbegin\n  have A : deriv (λ (x : ℝ), x ^ p) = λ 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 (λ 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 ≠ 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 ≤ 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 : ℝ} (hp : 1 < p) : strict_convex_on ℝ (Ici 0) (λ x : ℝ, x^p) :=\nbegin\n  have A : deriv (λ (x : ℝ), x ^ p) = λ 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 (λ x _, or.inr (zero_le_one.trans hp.le)) },\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 ℝ (Ioi 0) log :=\nbegin\n  have h₁ : Ioi 0 ⊆ ({0} : set ℝ)ᶜ,\n  { exact λ x (hx : 0 < x) (hx' : x = 0), hx.ne' hx' },\n  refine strict_concave_on_of_deriv2_neg' (convex_Ioi 0)\n    (continuous_on_log.mono h₁) (λ 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 ℝ (Iio 0) log :=\nbegin\n  have h₁ : Iio 0 ⊆ ({0} : set ℝ)ᶜ,\n  { exact λ x (hx : x < 0) (hx' : x = 0), hx.ne hx' },\n  refine strict_concave_on_of_deriv2_neg' (convex_Iio 0)\n    (continuous_on_log.mono h₁) (λ 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 : ℝ} (hx : x ≠ 0) :\n  has_deriv_at (λ 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, ←div_eq_mul_inv, sqrt_div_self',\n      add_comm, div_eq_mul_one_div, mul_comm],\nend\n\nlemma deriv_sqrt_mul_log (x : ℝ) : deriv (λ 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 (λ x hx, _) hx,\n    rw [sqrt_eq_zero_of_nonpos hx, zero_mul] },\nend\n\nlemma deriv_sqrt_mul_log' : deriv (λ x, sqrt x * log x) = λ x, (2 + log x) / (2 * sqrt x) :=\nfunext deriv_sqrt_mul_log\n\nlemma deriv2_sqrt_mul_log (x : ℝ) :\n  deriv^[2] (λ 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 (λ x hx, _) hx,\n    rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] },\n  { have h₀ : sqrt x ≠ 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₀).deriv using 1,\n    nth_rewrite 2 [← mul_self_sqrt hx.le],\n    field_simp, ring },\nend\n\nlemma strict_concave_on_sqrt_mul_log_Ioi : strict_concave_on ℝ (set.Ioi 1) (λ x, sqrt x * log x) :=\nbegin\n  apply strict_concave_on_of_deriv2_neg' (convex_Ioi 1) _ (λ x hx, _),\n  { exact continuous_sqrt.continuous_on.mul\n      (continuous_on_log.mono (λ x hx, ne_of_gt (zero_lt_one.trans hx))) },\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 ℝ (Icc 0 π) sin :=\nbegin\n  apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_sin (λ 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 ℝ (Icc (-(π/2)) (π/2)) cos :=\nbegin\n  apply strict_concave_on_of_deriv2_neg (convex_Icc _ _) continuous_on_cos (λ x hx, _),\n  rw interior_Icc at hx,\n  simp [cos_pos_of_mem_Ioo 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/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788077, "lm_q2_score": 0.870597273444551, "lm_q1q2_score": 0.7750877156887083}}
{"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 analysis.quaternion\nimport analysis.normed_space.exponential\nimport analysis.inner_product_space.pi_L2\nimport analysis.special_functions.trigonometric.series\n\n/-!\n# Lemmas about `exp` on `quaternion`s\n\nThis file contains results about `exp` on `quaternion ℝ`.\n\n## Main results\n\n* `quaternion.exp_eq`: the general expansion of the quaternion exponential in terms of `real.cos`\n  and `real.sin`.\n* `quaternion.exp_of_re_eq_zero`: the special case when the quaternion has a zero real part.\n* `quaternion.norm_exp`: the norm of the quaternion exponential is the norm of the exponential of\n  the real part.\n\n-/\n\nopen_locale quaternion nat\n\nnamespace quaternion\n\nlemma conj_exp (q : ℍ[ℝ]) : conj (exp ℝ q) = exp ℝ (conj q) := star_exp q\n\n@[simp, norm_cast] lemma exp_coe (r : ℝ) : exp ℝ (r : ℍ[ℝ]) = ↑(exp ℝ r) :=\n(map_exp ℝ (algebra_map ℝ ℍ[ℝ]) (continuous_algebra_map _ _) _).symm\n\n/-- Auxiliary result; if the power series corresponding to `real.cos` and `real.sin` evaluated\nat `‖q‖` tend to `c` and `s`, then the exponential series tends to `c + (s / ‖q‖)`. -/\nlemma has_sum_exp_series_of_imaginary\n  {q : quaternion ℝ} (hq : q.re = 0) {c s : ℝ}\n  (hc : has_sum (λ n, (-1)^n * ‖q‖^(2 * n) / (2 * n)!) c)\n  (hs : has_sum (λ n, (-1)^n * ‖q‖^(2 * n + 1) / (2 * n + 1)!) s) :\n  has_sum (λ n, exp_series ℝ _ n (λ _, q)) (↑c + (s / ‖q‖) • q) :=\nbegin\n  replace hc := has_sum_coe.mpr hc,\n  replace hs := (hs.div_const ‖q‖).smul_const q,\n  obtain rfl | hq0 := eq_or_ne q 0,\n  { simp_rw [exp_series_apply_zero, norm_zero, div_zero, zero_smul, add_zero],\n    simp_rw [norm_zero] at hc,\n    convert hc,\n    ext (_ | n) : 1,\n    { rw [pow_zero, mul_zero, pow_zero, nat.factorial_zero, nat.cast_one, div_one, one_mul,\n        pi.single_eq_same, coe_one], },\n    { rw [zero_pow (mul_pos two_pos (nat.succ_pos _)), mul_zero, zero_div,\n        pi.single_eq_of_ne (n.succ_ne_zero), coe_zero], } },\n  simp_rw exp_series_apply_eq,\n  have hq2 : q^2 = -norm_sq q := sq_eq_neg_norm_sq.mpr hq,\n  have hqn := norm_ne_zero_iff.mpr hq0,\n  refine has_sum.even_add_odd _ _,\n  { convert hc using 1,\n    ext n : 1,\n    let k : ℝ := ↑(2 * n)!,\n    calc k⁻¹ • q ^ (2 * n)\n        = k⁻¹ • ((-norm_sq q) ^ n) : by rw [pow_mul, hq2]\n    ... = k⁻¹ • ↑((-1) ^ n * ‖q‖ ^ (2 * n)) : _\n    ... = ↑((-1) ^ n * ‖q‖ ^ (2 * n) / k) : _,\n    { congr' 1,\n      rw [neg_pow, norm_sq_eq_norm_sq, pow_mul, sq],\n      push_cast },\n    { rw [←coe_mul_eq_smul, div_eq_mul_inv],\n      norm_cast,\n      ring_nf } },\n  { convert hs using 1,\n    ext n : 1,\n    let k : ℝ := ↑(2 * n + 1)!,\n    calc k⁻¹ • q ^ (2 * n + 1)\n        = k⁻¹ • ((-norm_sq q) ^ n * q) : by rw [pow_succ', pow_mul, hq2]\n    ... = k⁻¹ • ((-1) ^ n * ‖q‖ ^ (2 * n)) • q : _\n    ... = ((-1) ^ n * ‖q‖ ^ (2 * n + 1) / k / ‖q‖) • q : _,\n    { congr' 1,\n      rw [neg_pow, norm_sq_eq_norm_sq, pow_mul, sq, ←coe_mul_eq_smul],\n      push_cast },\n    { rw smul_smul,\n      congr' 1,\n      simp_rw [pow_succ', mul_div_assoc, div_div_cancel_left' hqn],\n      ring } },\nend\n\n/-- The closed form for the quaternion exponential on imaginary quaternions. -/\nlemma exp_of_re_eq_zero (q : quaternion ℝ) (hq : q.re = 0) :\n  exp ℝ q = ↑(real.cos ‖q‖) + (real.sin ‖q‖ / ‖q‖) • q :=\nbegin\n  rw [exp_eq_tsum],\n  refine has_sum.tsum_eq _,\n  simp_rw ← exp_series_apply_eq,\n  exact has_sum_exp_series_of_imaginary hq (real.has_sum_cos _) (real.has_sum_sin _),\nend\n\n/-- The closed form for the quaternion exponential on arbitrary quaternions. -/\nlemma exp_eq (q : quaternion ℝ) :\n  exp ℝ q = exp ℝ q.re • (↑(real.cos ‖q.im‖) + (real.sin ‖q.im‖ / ‖q.im‖) • q.im) :=\nbegin\n  rw [←exp_of_re_eq_zero q.im q.im_re, ←coe_mul_eq_smul, ←exp_coe, ←exp_add_of_commute, re_add_im],\n  exact algebra.commutes q.re (_ : ℍ[ℝ]),\nend\n\nlemma re_exp (q : ℍ[ℝ]) : (exp ℝ q).re = exp ℝ q.re * (real.cos ‖q - q.re‖) :=\nby simp [exp_eq]\n\nlemma im_exp (q : ℍ[ℝ]) : (exp ℝ q).im = (exp ℝ q.re * (real.sin ‖q.im‖ / ‖q.im‖)) • q.im :=\nby simp [exp_eq, smul_smul]\n\nlemma norm_sq_exp (q : ℍ[ℝ]) : norm_sq (exp ℝ q) = (exp ℝ q.re)^2 :=\ncalc norm_sq (exp ℝ q)\n    = norm_sq (exp ℝ q.re • (↑(real.cos ‖q.im‖) + (real.sin ‖q.im‖ / ‖q.im‖) • q.im))\n    : by rw exp_eq\n... = (exp ℝ q.re)^2 * norm_sq ((↑(real.cos ‖q.im‖) + (real.sin ‖q.im‖ / ‖q.im‖) • q.im))\n    : by rw [norm_sq_smul]\n... = (exp ℝ q.re)^2 * ((real.cos ‖q.im‖) ^ 2 + (real.sin ‖q.im‖)^2)\n    : begin\n      congr' 1,\n      obtain hv | hv := eq_or_ne (‖q.im‖) 0,\n      { simp [hv] },\n      rw [norm_sq_add, norm_sq_smul, conj_smul, coe_mul_eq_smul, smul_re, smul_re, conj_re, im_re,\n        smul_zero, smul_zero, mul_zero, add_zero, div_pow, norm_sq_coe, norm_sq_eq_norm_sq, ←sq,\n        div_mul_cancel _ (pow_ne_zero _ hv)],\n    end\n... = (exp ℝ q.re)^2 : by rw [real.cos_sq_add_sin_sq, mul_one]\n\n/-- Note that this implies that exponentials of pure imaginary quaternions are unit quaternions\nsince in that case the RHS is `1` via `exp_zero` and `norm_one`. -/\n@[simp] lemma norm_exp (q : ℍ[ℝ]) : ‖exp ℝ q‖ = ‖exp ℝ q.re‖ :=\nby rw [norm_eq_sqrt_real_inner (exp ℝ q), inner_self, norm_sq_exp, real.sqrt_sq_eq_abs,\n  real.norm_eq_abs]\n\nend quaternion\n", "meta": {"author": "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/quaternion_exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7750625866739169}}
{"text": "import linear_algebra.projection\nimport linear_algebra.dual\n\nuniverses u v w\n\nvariables {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]\n\n/-- The first isomorphism theorem for surjective linear maps. -/\nnoncomputable def linear_map.quot_ker_equiv_of_surjective \n  {R : Type u} {M : Type v} {M₂ : Type w} [comm_ring R] \n  [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]\n  (f : M →ₗ[R] M₂) (hf : function.surjective f) : f.ker.quotient ≃ₗ[R] M₂ := \nf.quot_ker_equiv_range.trans\n  (linear_equiv.of_top f.range (linear_map.range_eq_top.2 hf))\n\nnamespace submodule\n\nvariable {W : submodule R M}\n\n/-- The `dual_annihilator` of a submodule `W` is the set of linear maps `φ` such \n  that `φ w = 0` for all `w ∈ W`. -/\ndef dual_annihilator {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M]\n  [module R M] (W : submodule R M) : submodule R $ module.dual R M := \n{ carrier := { φ | ∀ w ∈ W, φ w = 0 },\n  zero_mem' := by simp,\n  add_mem' :=  by { intros φ ψ hφ hψ w hw,\n    rw [linear_map.add_apply, hφ w hw, hψ w hw, add_zero] },\n  smul_mem' := by { intros c φ hφ w hw,\n    rw [linear_map.smul_apply, hφ w hw, smul_zero] } }\n\n@[simp] lemma mem_dual_annihilator (φ : module.dual R M) : \n  φ ∈ W.dual_annihilator ↔ ∀ w ∈ W, φ w = 0 := iff.rfl\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 →ₗ[R] module.dual R W := \n{ to_fun := λ φ, φ.dom_restrict W,\n  map_add' := by simp [linear_map.ext_iff],\n  map_smul' := by simp [linear_map.ext_iff] }.\n\n@[simp] lemma dual_restrict_apply \n  (W : submodule R M) (φ : module.dual R M) (x : W) : \n  W.dual_restrict φ x = φ x.1 := rfl\n\nlemma dual_restrict_ker_eq_dual_anihilator \n  (W : submodule R M) : W.dual_restrict.ker = W.dual_annihilator :=\nbegin\n  ext φ, split; intro hφ,\n  { intros w hw,\n    rw linear_map.mem_ker at hφ,\n    rw [← W.dual_restrict_apply φ ⟨w, hw⟩, hφ], refl },\n  { ext, exact hφ x.1 x.2 }\nend\n\nend submodule\n\nnamespace subspace\n\nopen submodule linear_map\n\nvariables {K : Type u} {V : Type v} [field K] [add_comm_group V] [vector_space K V] \n\n-- We work in vector spaces because `exists_is_compl` only hold for vector spaces\n/-- Given a subspace `W` of `V` and an element of its dual `φ`, `dual_lift W φ` is \n  the natural extenstion of `φ` to an element of the dual of `V`. -/\nnoncomputable def dual_lift \n  (W : subspace K V) (φ : module.dual K W) : module.dual K V := \nlet h := classical.indefinite_description _ W.exists_is_compl in of_is_compl h.2 φ 0\n\nvariable {W : subspace K V}\n\n@[simp] lemma dual_lift_of_subtype {φ : module.dual K W} (w : W) : \n  W.dual_lift φ (w : V) = φ w := \nby erw of_is_compl_left_apply _ w\n\nlemma dual_lift_of_mem {φ : module.dual K W} {w : V} (hw : w ∈ W) : \n  W.dual_lift φ w = φ ⟨w, hw⟩ := \ndual_lift_of_subtype ⟨w, hw⟩\n\n@[simp] lemma dual_lift_zero : W.dual_lift 0 = 0 := by simp [dual_lift]\n\n@[simp] lemma dual_lift_add (φ ψ : module.dual K W) : \n  W.dual_lift (φ + ψ) = W.dual_lift φ + W.dual_lift ψ := \nbegin\n  -- `change` is significantly slower than `show`\n  show of_is_compl _ _ 0 = of_is_compl _ φ 0 + of_is_compl _ ψ 0,\n  rw [← zero_add (0 : _ →ₗ[K] _), of_is_compl_add], simp\nend\n\n@[simp] lemma dual_lift_smul (c : K) (φ : module.dual K W) : \n  W.dual_lift (c • φ) = c • W.dual_lift φ := \nbegin\n  show of_is_compl _ _ 0 = c • of_is_compl _ _ 0,\n  rw [← smul_zero c, of_is_compl_smul], simp\nend \n\nlemma dual_restrict_surjective : \n  function.surjective W.dual_restrict :=\nbegin\n  intros φ, refine ⟨W.dual_lift φ, _⟩, ext, \n  erw [dual_restrict_apply, dual_lift, of_is_compl_left_apply],\nend\n\nlemma dual_lift_injective : function.injective W.dual_lift :=\nbegin\n  rintro _ _ h, \n  ext, rw [← dual_lift_of_subtype, h, dual_lift_of_subtype], \nend\n\n-- V* / U∘ ≅ U*\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  W.dual_annihilator.quotient ≃ₗ[K] module.dual K W := \n(quot_equiv_of_eq _ _ W.dual_restrict_ker_eq_dual_anihilator).symm.trans $\n  W.dual_restrict.quot_ker_equiv_of_surjective dual_restrict_surjective\n\n/-- The representation of the dual of a subspace `W` of `V` as a subspace of \n  the dual of `V`. -/\ndef dual (W : subspace K V) : subspace K (module.dual K V) := \n{ carrier := { φ | ∃ ψ : module.dual K W, φ = W.dual_lift ψ },\n  zero_mem' := ⟨0, dual_lift_zero.symm⟩,\n  add_mem' := \n    by { rintro _ _ ⟨ψ₁, rfl⟩ ⟨ψ₂, rfl⟩, \n         exact ⟨ψ₁ + ψ₂, (dual_lift_add ψ₁ ψ₂).symm⟩ },\n  smul_mem' := \n    by { rintro c _ ⟨ψ, rfl⟩,\n         exact ⟨c • ψ, (dual_lift_smul c ψ).symm⟩ } }\n\n@[simp] lemma mem_dual_iff (φ : module.dual K V) : φ ∈ W.dual ↔ \n  ∃ ψ : module.dual K W, φ = W.dual_lift ψ := iff.rfl\n\n/-- The natural linear map from the dual of a subspace `W` to `W.dual`. -/\nnoncomputable def dual_to_subspace_dual (W : subspace K V) : \n  module.dual K W →ₗ[K] W.dual := \n{ to_fun := λ φ, ⟨W.dual_lift φ, ⟨φ, rfl⟩⟩,\n  map_add' := by { intros _ _, simp_rw [dual_lift_add], refl },\n  map_smul' := by { intros _ _, simp_rw [dual_lift_smul], refl } }\n\n@[simp] lemma dual_to_subspace_dual_apply (φ : module.dual K W) : \n  W.dual_to_subspace_dual φ = ⟨W.dual_lift φ, ⟨φ, rfl⟩⟩ := rfl\n\nlemma dual_to_subspace_ker_eq_bot : \n  W.dual_to_subspace_dual.ker = ⊥ :=\nlinear_map.ker_eq_bot.2 $ λ φ ψ h, dual_lift_injective (subtype.mk_eq_mk.1 h)\n\nlemma dual_to_subspace_range_eq_top : \n  W.dual_to_subspace_dual.range = ⊤ := \nlinear_map.range_eq_top.2 $ λ ⟨φ, hφ⟩, let ⟨ψ, hψ⟩ := hφ in\n  ⟨ψ, by rw [dual_to_subspace_dual_apply, subtype.mk_eq_mk, hψ]⟩\n\n/-- The natural isomorphism forom the dual of a subspace `W` to `W.dual`. -/\nnoncomputable def dual_equiv_dual (W : subspace K V) : \n  module.dual K W ≃ₗ[K] W.dual := \nlinear_equiv.of_bijective W.dual_to_subspace_dual \n  dual_to_subspace_ker_eq_bot dual_to_subspace_range_eq_top\n\n/- Next step\n  V* / U∘ ≅ U*\n  → V* / U* ≅ U∘ \n  → V / U ≅ U∘ ≅ U⊥\n-/\n\nsection\n\nopen_locale classical\n\nopen finite_dimensional\n\nvariables {V₁ : Type*} [add_comm_group V₁] [vector_space K V₁]\nvariables [finite_dimensional K V] [finite_dimensional K V₁]\n\n/-- Given isomorphic subspaces `p q` of vector spaces `V` and `V₁` respectively, \n  `p.quotient` is isomorphic to `q.quotient`. -/\nnoncomputable def linear_equiv.quot_equiv_of_equiv\n  {p : subspace K V} {q : subspace K V₁}\n  (f₁ : p ≃ₗ[K] q) (f₂ : V ≃ₗ[K] V₁) : p.quotient ≃ₗ[K] q.quotient := \nlinear_equiv.of_findim_eq _ _ \nbegin\n  rw [← @add_right_cancel_iff _ _ (findim K p), findim_quotient_add_findim, \n    linear_equiv.findim_eq f₁, findim_quotient_add_findim, linear_equiv.findim_eq f₂],\nend\n\n/-- Given the subspaces `p q`, if `p.quotient ≃ₗ[K] q`, then `q.quotient ≃ₗ[K] p` -/\nnoncomputable def linear_equiv.quot_equiv_of_quot_equiv\n  {p q : subspace K V} (f : p.quotient ≃ₗ[K] q) : q.quotient ≃ₗ[K] p := \nlinear_equiv.of_findim_eq _ _ \nbegin\n  rw [← @add_right_cancel_iff _ _ (findim K q), findim_quotient_add_findim, \n    ← linear_equiv.findim_eq f, add_comm, findim_quotient_add_findim]  \nend\n\n-- dependency\ninstance [H : finite_dimensional K V] : finite_dimensional K (module.dual K V) := \nbegin\n  refine @linear_equiv.finite_dimensional _ _ _ _ _ _ _ _ _ H,\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/-- The quotient by the dual is isomorphic to its dual annihilator.  -/\nnoncomputable def quot_dual_equiv_annihilator (W : subspace K V) : \n  W.dual.quotient ≃ₗ[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  W.quotient ≃ₗ[K] W.dual_annihilator := \nbegin\n  refine linear_equiv.trans _ W.quot_dual_equiv_annihilator,\n  refine linear_equiv.quot_equiv_of_equiv _ _,\n  { refine linear_equiv.trans _ W.dual_equiv_dual,\n    have hB := classical.some_spec (exists_is_basis_finite K W),\n    haveI := classical.choice hB.2,\n    exact is_basis.to_dual_equiv _ hB.1 },\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\nend\n\nend subspace", "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/annihilator.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.863391599428538, "lm_q1q2_score": 0.7750625811413372}}
{"text": "import data.real.basic\n\nnamespace xena -- hide\n\nopen function\nopen real\n\nopen_locale classical\n\n/-\nClassic eps-delta definition of continuity is equivalent to \nthe definition using sequences.\n-/\n\nnotation `|` x `|` := abs x\ndef is_limit (a : ℕ → ℝ) (l : ℝ) := \n    ∀ ε : ℝ, 0 < ε → ∃ N : ℕ, ∀ n : ℕ, N ≤ n → |a n - l| < ε\n\ndef continuous_at_x (f : ℝ → ℝ) (x : ℝ) := \n    ∀ ε : ℝ, 0 < ε → ∃ δ : ℝ, 0 < δ ∧ ∀ y : ℝ, |y - x| < δ → |f y - f x| < ε\ndef seq_continuous_at_x (f : ℝ → ℝ) (x : ℝ) :=\n    ∀ (a : ℕ → ℝ), is_limit a x → is_limit ( λ n : ℕ, f (a n) ) (f x)\n\n/- Lemma\nThe two definitions of continuity are equivalent.\n-/\nlemma cont_iff_seq_cont (f : ℝ → ℝ) : \n    ∀ x : ℝ, continuous_at_x f x ↔ seq_continuous_at_x f x :=\nbegin\n    intro x,\n    split,\n    { -- classical continuity def -> sequence def\n        intros H a hax e he,\n        have h1 := H e he,\n        cases h1 with d hdd,\n        cases hdd with hd hy,\n        have h2 := hax d hd,\n        cases h2 with N hN,\n        use N,\n        intros n hn,\n        have hnd := hN n hn,\n        have G := hy (a n) hnd, exact G,\n    },\n    { -- sequence def -> classical def is a little trickier\n      -- contrapositive\n      contrapose!,\n      intro H, unfold continuous_at_x at H,\n      push_neg at H,\n      cases H with e hee,\n      cases hee with he hdd,\n      unfold seq_continuous_at_x, push_neg,\n      -- using these hypotheses, choose a sequence \n      have k : ∀ n : ℕ, ∃ y : ℝ, |y - x| < (1:ℝ)/(n+1) ∧ e ≤ | f y - f x|, \n        intro n,\n        have g1 := hdd ( (1:ℝ)/(n+1) ),\n        cases g1 with g11 g12,\n        exfalso,\n        {  -- this seems complicated, but other ways got into coercion problems\n            have f1 : ∀ m : ℕ, 0 < m+1,\n                intro m, exact nat.succ_pos m,\n            have f2 : ∀ m : ℕ, 0 < ( (m+1): ℝ),\n                intro m, \n                have f21 := f1 m,\n                norm_cast, linarith,\n            have f3 : ∀ m : ℕ, 0 < 1 / ( (m+1): ℝ),\n                intro m,\n                have f31 := one_div_pos_of_pos (f2 m),\n                exact f31,\n            have f4 := f3 n,\n            linarith, \n        },\n        exact g12,\n      choose a ha using k,\n      use a,\n      -- prove this sequence does converge to x\n      split,\n      {\n        intros ε hε,\n        set N := nat_ceil ( (1:ℝ)/ ε ) with hN,\n        use N,\n        intros n hn,\n        have H := ha n, \n        cases H with h1 h2,\n        have hN1 := le_nat_ceil ( (1:ℝ)/ε), rw ← hN at hN1,\n        have hN2 : ((1:ℝ) / ↑N) ≤ ε, \n            exact one_div_le_of_one_div_le_of_pos hε hN1,\n        have hN3 : ((1:ℝ)/(↑n+1)) < ((1:ℝ) / ↑N), \n            have hN31 : (n + 1) > N, linarith,\n            have hN32 : 0 < (n+1), linarith,\n            have hN33 : 0 < N, \n                have hN34 : 0 < ( (1:ℝ)/ε ), exact one_div_pos_of_pos hε,\n                have hN35 := lt_of_lt_of_le hN34 hN1,\n                norm_cast at hN35, exact hN35,\n            apply one_div_lt_one_div_of_lt,\n            norm_cast, linarith, norm_cast, linarith,\n        have hN4 : ((1:ℝ)/(↑n+1)) < ε, linarith, \n        linarith,\n      },\n      \n      { -- but f(a n) does not converge to f(x)\n        unfold is_limit, push_neg,\n        use e, split, exact he, \n        intro N, use N, split, linarith,\n        have G := ha N, cases G with G1 G2, exact G2, \n      }, \n      done\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/functions/seqContinDef.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520764, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7750020808213473}}
{"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 → p := fun hp => hp\n\nexample : p → (q → p) := fun hp => fun _ => hp\n\n-- Note: `→` associates to the right, so the above proposition is equivalent to\n-- `p → q → p`\n\nexample : (p → False) → (p → q) := fun hnp => fun hp => nomatch hnp hp\n\nexample : (p ∨ p) → p := fun h =>\n  match h with \n  | Or.inr hp => hp\n  | Or.inl hp => hp\n\nexample : (p → q → r) → (p ∧ q → r) := fun h => fun hpq => h hpq.1 hpq.2\n\nexample : (p ∧ q → r) → (p → q → r) := fun h => fun hp => fun hq => h ⟨hp,hq⟩ \n\nexample : p → (p → q) → p ∧ q := fun hp => fun hpq => ⟨hp, hpq hp⟩ \n\ntheorem imp_and : (p → q ∧ r) → (p → q) ∧ (p → r) := fun h => \n  And.intro (fun hp => (h hp).1) (fun hp => (h hp).2)\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 → B) → (B → A) → (A ↔ B)\n-- Can you recover the proof for A → B by a match expression?\n\nexample (hpq : p ↔ q) : (p → q) := fun hp => \n  match hpq with \n  | ⟨hpq',_⟩ => hpq' hp\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: `↔` is defined to bind less tightly than other connectives such as `∧` or `∨`.\n\ntheorem iff_and : (p → q ∧ r) ↔ (p → q) ∧ (p → r) := \n  Iff.intro \n  (fun h => ⟨fun hp => (h hp).1, fun hp => (h hp).2⟩)\n  (fun h hp => ⟨h.left hp, h.right hp⟩)\n\ntheorem or_and : (p ∨ q → r) ↔ (p → r) ∧ (q → r) := \n  Iff.intro \n  (fun h => ⟨fun hp => h (Or.inl hp), fun hq => h (Or.inr hq)⟩)\n  (fun h hpq => \n    match hpq with \n    | Or.inl hp => h.left hp\n    | Or.inr hq => h.right hq\n  )\n\ntheorem iff_and_false : False ↔ p ∧ False := \n  Iff.intro \n  (fun h => ⟨nomatch h, h⟩)\n  (fun h => h.2)\n\n/- NEGATION -/\n\n-- Negation is defined by ¬ A := (A → False).\n-- How is that a good choice? Let us check some basic properties of negation:\n\nexample : ¬False := fun h => h\n\ntheorem imp_not_not : p → ¬¬p := fun hp hnp => hnp hp\n\nexample : ¬(p ∧ ¬p) := fun hpnp => hpnp.2 hpnp.1\n\ntheorem not_or_not : (¬p ∨ ¬q) → ¬(p ∧ q) := fun h h1 => \n  match h with \n  | Or.inl hnp => hnp h1.1\n  | Or.inr hnq => hnq h1.2\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 : ¬(p ↔ ¬p) := fun h => \n    -- (fun hp => h.1 hp) this is an implication\n    have hp : p := h.2 (fun hp => h.1 hp hp)\n    h.1 hp hp\n\n-- example : ¬¬(¬¬p → p) := fun h => nomatch h (fun h1 => _)\nexample : ¬¬(¬¬p → p) := \n  fun hnnnpp => hnnnpp fun hnnp => False.elim (hnnp (fun hp => hnnnpp fun _ => hp))\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 : ¬(p ∧ q) → (¬ p ∨ ¬ q) := fun h => \n  match (em p) with \n  | Or.inr hnp => Or.inl hnp\n  | Or.inl hp => \n    match (em q) with \n    | Or.inr hnq => Or.inr hnq\n    | Or.inl hq => Or.inr (nomatch h ⟨hp,hq⟩)\n\n-- Also, we can now deal better with double negations:\n\nexample : ¬¬p ↔ p := \n  match (em p) with \n  | Or.inr hnp => ⟨fun hnnp => nomatch hnnp hnp, fun hp hnp => hnp hp⟩\n  | Or.inl hp => ⟨fun _ => hp, fun _ hnp => hnp hp⟩\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/Exercise1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7749910860398723}}
{"text": "import tactic\n\nnamespace binomial\n\ndef binomial : ℕ → ℕ → ℕ \n  | _ 0 := 1\n  | 0 _ := 0\n  | (n+1) (k+1) := binomial n (k+1) + binomial n k\n\n@[simp] lemma choose_zero_is_one (n : ℕ) : binomial n 0 = 1 := by {\n  induction n with d hd,\n  {\n    refl,\n  },\n  {\n    refl,\n  }\n}\n\n@[simp] lemma zero_choose_succ_is_zero (n : ℕ) : binomial 0 (n+1) = 0 := by {cases n, refl, refl,}\n\n@[simp] lemma pascal_identity (n : ℕ) (k : ℕ) : binomial (n+1) (k+1) = binomial n (k+1) + binomial n k := by refl\n\n@[simp] lemma choose_one_is_self (n : ℕ) : binomial n 1 = n := \nbegin\n  induction n with d hd,\n  refl,\n  rw binomial,\n  rw hd,\n  simp,\nend\n\n@[simp] lemma n_choose_gt_n_is_zero (n : ℕ) : ∀ (k : ℕ), n < k → binomial n k = 0 := by {\n  induction n with d hd,\n  {\n    intro k,\n    intro hkpos,\n    cases k,\n    {\n      have f : false := nat.lt_asymm hkpos hkpos,\n      exact false.rec (binomial 0 0 = 0) f,\n    },\n    refl,\n  },\n  {\n    intro k,\n    cases k,\n    {\n      intro h,\n      have f : false := nat.not_lt_zero d.succ h,\n      exact false.rec (binomial (nat.succ d) 0 = 0) f,\n    },\n    {\n      rw binomial,\n      intro hdsks,\n      have hdk : d < k := nat.succ_lt_succ_iff.mp hdsks,\n      have hdks : d < k.succ := nat.lt.step hdk,\n      rw hd k hdk,\n      rw hd _ hdks,\n    }\n  }\n}\n\n@[simp] lemma choose_self_is_one (n : ℕ) : binomial n n = 1 :=\nbegin\n  induction n with d hd,\n  refl,\n  rw binomial,\n  rw hd,\n  simp,\nend\n\n@[simp] lemma choose_succ_equals_succ (n : ℕ) : binomial n.succ n = n.succ := by {\n  induction n with d hd,\n  simp,\n  rw binomial,\n  rw hd,\n  simp,\n  exact (nat.succ d).one_add,\n}\n\n@[simp] lemma choose_lt_zero_is_zero (n : ℕ) : ∀ (k : ℕ), k < 0 → binomial n k = 0 := by {\n  induction n with d hd,\n  {\n    intro k,\n    intro hkltzero,\n    cases k,\n    {\n      have f : false := nat.lt_asymm hkltzero hkltzero,\n      exact false.rec (binomial 0 0 = 0) f,\n    },\n    refl,\n  },\n  {\n    intro k,\n    intro hkltzero,\n    cases k,\n    {\n      have f : false := nat.lt_asymm hkltzero hkltzero,\n      exact false.rec (binomial (nat.succ d) 0 = 0) f,\n    },\n    {\n      rw binomial,\n      have hk_ltzero : k < 0 := nat.lt_of_succ_lt hkltzero,\n      rw hd _ hk_ltzero,\n      rw hd _ hkltzero,\n    }\n  }\n}\n\nlemma choose_pos (n : ℕ) : ∀ {k : ℕ}, k ≤ n → 0 < binomial n k := by {\n  induction n with d hd,\n  {\n    intro k,\n    intro kzero,\n    cases k,\n    {\n      simp,\n    },\n    {\n      simp,\n      exact nat.not_succ_le_zero k kzero,\n    },\n  },\n  {\n    intro k,\n    intro hkltds,\n    cases k,\n    {\n      simp,\n    },\n    {\n      rw binomial,\n      have hkld : k ≤ d := nat.succ_le_succ_iff.mp hkltds,\n      have hbindkpos : 0 < binomial d k := hd hkld,\n      linarith,\n    }\n  }\n}\n\nlemma pascal_identity_with_conditions (n : ℕ) (k : ℕ) : (0 < k) → binomial n k + binomial n (k-1) = binomial n.succ k :=\nbegin\n  intro hkpos,\n  have h_pred : ∃ (m : ℕ), k = m.succ :=\n  begin\n    refine nat.exists_eq_succ_of_ne_zero _,\n    linarith,\n  end,\n  cases h_pred with m hm,\n  rw hm at *,\n  rw pascal_identity,\n  simp,\nend\n\ntheorem binomial_symm (n : ℕ) : ∀ (k : ℕ), k ≤ n → binomial n k = binomial n (n - k) := \nbegin\n  induction n with d hd,\n  {\n    intro k,\n    intro hkleqzero,\n    cases k,\n    {\n      refl,\n    },\n    {\n      have f : false := nat.not_succ_le_zero k hkleqzero,\n      exact congr_arg (binomial 0) (congr_fun (false.rec (nat.succ = λ (k : ℕ), 0 - k.succ) f) k),\n    }\n  },\n  {\n    intro k,\n    intro hkleqds,\n    cases k,\n    {\n      simp,\n    },\n    {\n      rw binomial,\n      have hkld : k ≤ d := nat.succ_le_succ_iff.mp hkleqds,\n      rw hd _ hkld,\n      cases hkleqds,\n      {\n        simp,\n      },\n      {\n        rw hd _ hkleqds_ᾰ,\n        rw add_comm,\n        have hdks : (d - k.succ) = ((d - k) - 1) := by {\n          rw nat.succ_eq_add_one,\n          exact (nat.sub_sub d k 1).symm,\n        },\n        rw hdks,\n        have dk_succ_diff : d.succ - k.succ = d - k := nat.succ_sub_succ d k,\n        rw dk_succ_diff,\n        have hksleqd : k + 1 ≤ d := hkleqds_ᾰ,\n        have dk_diff_pos : 0 < d-k := by {\n          refine nat.succ_le_iff.mp _,\n          exact nat.le_sub_left_of_add_le hksleqd,\n        },\n        exact pascal_identity_with_conditions d (d-k) dk_diff_pos,\n      }\n    }\n  }\nend\n\nend binomial", "meta": {"author": "0art0", "repo": "WZ", "sha": "134e872d8071107d8348f38cafd21c66ab4d04de", "save_path": "github-repos/lean/0art0-WZ", "path": "github-repos/lean/0art0-WZ/WZ-134e872d8071107d8348f38cafd21c66ab4d04de/binomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299570920386, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7749910846095021}}
{"text": "section propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro p,\n  intro np,\n  contradiction,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro nnp,\n  by_cases p: P,\n  exact p,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n\n  intro nnp,\n  by_contradiction,\n  contradiction,\n\n  intro p,\n  intro np,\n  contradiction,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro pouq,\n  cases pouq,\n  right,\n  assumption,\n  left,\n  assumption,\n\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro peq,\n  cases peq,\n  split,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro npouq,\n  intro p,\n  cases npouq,\n\n  contradiction,\n\n  assumption,\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro pouq,\n  intro np,\n  cases pouq with hp hq,\n\n  contradiction,\n\n  assumption,\n\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro pimplq,\n  intro nq,\n  intro p,\n  have q : Q := pimplq p,\n  contradiction,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro nqimplnp,\n  intro p,\n  by_contradiction,\n  have np := nqimplnp h,\n  contradiction,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n\n  intro pimplq,\n  intro nq,\n  intro p,\n  have q := pimplq p,\n  contradiction,\n\n  intro nqimplnp,\n  intro p,\n  by_contradiction,\n  have np := nqimplnp h,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro npounp,\n  have pounp : P ∨ ¬P,\n  right,\n  intro p,\n  have lem: P ∨ ¬P,\n  left,\n  assumption,\n  contradiction,\n  contradiction,\n\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro pimplqimplp,\n  intro np,\n  have pimplq: P → Q,\n  intro p,\n  contradiction,\n\n  have p := pimplqimplp pimplq,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro pouq,\n  intro npenq,\n  cases npenq with np nq,\n  cases pouq with p q,\n  contradiction,\n  contradiction,\n\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro peq,\n  intro npounq,\n  cases peq with p q,\n  cases npounq with np nq,\n  contradiction,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro npouq,\n  split,\n\n  intro p,\n  have pouq: P∨Q,\n  left,\n  assumption,\n  contradiction,\n\n  intro q,\n  have pouq: P∨Q,\n  right,\n  assumption,\n  contradiction,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro npenq,\n  intro pouq,\n  cases  npenq with np nq,\n  cases pouq with p q,\n  contradiction,\n  contradiction,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  sorry,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  sorry,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  sorry,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  sorry,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  sorry,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  sorry,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  sorry,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  sorry,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  sorry,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  sorry,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  sorry,\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  sorry,\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  sorry,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "iasmikelle", "repo": "fmclean", "sha": "9f7bc324600520efacb73a221f21ea3d6f35fb7d", "save_path": "github-repos/lean/iasmikelle-fmclean", "path": "github-repos/lean/iasmikelle-fmclean/fmclean-9f7bc324600520efacb73a221f21ea3d6f35fb7d/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7749759916114372}}
{"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\nimport algebra.free_algebra\n\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 `fraction_ring R`.\n\n\n## Main results\n\n- `char_p_of_injective_algebra_map` If `R →+* 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 →+* 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 : ℕ) [char_p R p] : char_p A p :=\n{ cast_eq_zero_iff := λx,\n  begin\n    rw ←char_p.cast_eq_zero_iff R p x,\n    change algebra_map ℕ A x = 0 ↔ algebra_map ℕ R x = 0,\n    rw is_scalar_tower.algebra_map_apply ℕ R A x,\n    refine iff.trans _ h.eq_iff,\n    rw ring_hom.map_zero,\n  end }\n\n/-- If the algebra map `R →+* 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 := λ x y hxy,\n  begin\n    change algebra_map ℕ A x = algebra_map ℕ A y at hxy,\n    rw is_scalar_tower.algebra_map_apply ℕ R A x at hxy,\n    rw is_scalar_tower.algebra_map_apply ℕ 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\nsection\n\nvariables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]\n\nlemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=\n(algebra_map K L).char_p_iff_char_p p\n\nend\n\nnamespace free_algebra\n\nvariables {R X : Type*} [comm_semiring R] (p : ℕ)\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 : ℕ)\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": "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/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7749759882117871}}
{"text": "/-\nCopyright (c) 2023 Huub Vromen. All rights reserved.\nAuthor: Huub Vromen\n-/\n\nimport data.set.basic\n\n/--  First-order semantics for Aristotle's assertoric syllogisms\nA first-order logic semantics is a variant of a set-theoretic semantics.\nSee, for instance Malink (2013, ch. 3).\nTerms are interpreted as non-empty subsets of some set of individuals. -/\n\nvariable {α : Type}\nvariable {x : α}\nvariables {A B C : α → Prop}\n\n/-- semantics of the `a` relation -/\ndef universal_affirmative (A: α → Prop) (B: α → Prop) : Prop := \n  ∀x, B x → A x\ninfixr ` a ` : 80 := universal_affirmative\n\n/-- semantics of the `e` relation -/\ndef universal_negative (A: α → Prop) (B: α → Prop) : Prop :=  \n  ∀x, B x → ¬ A x\ninfixr ` e ` : 80 := universal_negative\n\n/-- semantics of the `i` relation -/\ndef particular_affirmative (A: α → Prop) (B: α → Prop) : Prop := \n  ∃x, A x ∧ B x\n-- existential import needs to be stipulated\ninfixr ` i ` : 80 := particular_affirmative\n\n/-- semantics of the `o` relation -/\ndef particular_negative (A: α → Prop) (B: α → Prop) : Prop := \n  ∃x, B x ∧ ¬ A x\ninfixr ` o ` : 80 := particular_negative\n\n/-- semantics of contradictory: contradictory is defined as negation -/\ndef c (p : Prop) : Prop := ¬ p\n\n\n/--  We prove the soundness of the axiom system DR -/\n\nlemma Barbara₁ : A a B → B a C → A a C :=\nbegin\nintros h1 h2,\nrw universal_affirmative,\n{ intros p h3,\n  have h4 : B p := by exact h2 p h3,\n  exact h1 p h4 },\nend\n\nlemma Celarent₁ : A e B → B a C → A e C :=\nbegin\n  intros h1 h2 p h3,\n  have h4 : B p := by exact h2 p h3,\n  exact h1 p h4\nend\n\nlemma e_conv : A e B → B e A :=\nbegin\nintros h1 b h2,\nby_contra,\nshow false, from (h1 b h) h2,\nend\n\nlemma a_conv (hex: ∃x, B x) : A a B → B i A :=\n  begin\n  intro h1,\n  rw universal_affirmative at h1,\n  rw particular_affirmative,\n  cases hex with p hp,\n  apply exists.intro p (and.intro hp (h1 p hp))\n  end \n\nlemma contr {p r : Prop} : (c r → c p) → p → 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 := \nbegin\nsimp [c, particular_affirmative, universal_negative],\nfinish\nend\n\nlemma contr_i : c (A i B) = A e B :=\nbegin\nsimp [c, particular_affirmative, universal_negative],\nfinish\nend\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₁ : A a B → B i C → A i C :=\nbegin\nintros h1 h2,\ncases h2 with p h,\napply exists.intro p,\nexact and.intro (h1 p h.1) h.2\nend\n\nlemma Ferio₁ : A e B → B i C → A o C :=\nbegin\n  intros h1 h2,\n  cases h2 with p h,\n  --rw universal_denial at h1,\n  have h3 : ¬ A p := by exact h1 p h.1,\n  --rw particular_denial,\n  apply exists.intro p (and.intro h.2 h3)\nend\n\nlemma i_conv : A i B → B i A :=\nbegin\nintros h1,\ncases h1 with p h2,\ncases h2 with q r,\napply exists.intro p (and.intro r q)\nend\n\n#lint", "meta": {"author": "hjvromen", "repo": "aristotle", "sha": "fdc6c68ce2edcf6faaa638457cb593e922bfa521", "save_path": "github-repos/lean/hjvromen-aristotle", "path": "github-repos/lean/hjvromen-aristotle/aristotle-fdc6c68ce2edcf6faaa638457cb593e922bfa521/src/aristotle_FOL_semantics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7749227819078626}}
{"text": "import algebra.ring\n\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\nvariables a b c : R\n\n#check zero_add \n#check zero_add c\n#check add_zero\n#check add_zero b\n#check add_comm \n#check add_comm c\n#check add_assoc\n#check add_right_neg\n#check add_right_neg b\n\n-- BEGIN\ntheorem add_left_cancel {a b c : R} (h : a + b = a + c) : b = c :=\nbegin\n  rw [← zero_add b, ← zero_add c, ← add_right_neg a],\n  rw [add_comm a, add_assoc, h, ← add_assoc],\nend\n\ntheorem add_right_cancel {a b c : R} (h : a + b = c + b) : a = c :=\nbegin\n  rw [← add_zero a, ← add_zero c, ← add_right_neg b],\n  sorry,   \nend\n-- END\n\n#check @add_left_cancel\n#check @add_right_cancel\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/ex7_rw_add_cancel.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7749227777448494}}
{"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 linear_algebra.matrix.nondegenerate\n! leanprover-community/mathlib commit 2a32c70c78096758af93e997b978a5d461007b4f\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.Matrix.Determinant\nimport Mathbin.LinearAlgebra.Matrix.Adjugate\n\n/-!\n# Matrices associated with non-degenerate bilinear forms\n\n## Main definitions\n\n* `matrix.nondegenerate A`: the proposition that when interpreted as a bilinear form, the matrix `A`\n  is nondegenerate.\n\n-/\n\n\nnamespace Matrix\n\nvariable {m R A : Type _} [Fintype m] [CommRing R]\n\n/-- A matrix `M` is nondegenerate if for all `v ≠ 0`, there is a `w ≠ 0` with `w ⬝ M ⬝ v ≠ 0`. -/\ndef Nondegenerate (M : Matrix m m R) :=\n  ∀ v, (∀ w, Matrix.dotProduct v (mulVec M w) = 0) → v = 0\n#align matrix.nondegenerate Matrix.Nondegenerate\n\n/-- If `M` is nondegenerate and `w ⬝ M ⬝ v = 0` for all `w`, then `v = 0`. -/\ntheorem Nondegenerate.eq_zero_of_ortho {M : Matrix m m R} (hM : Nondegenerate M) {v : m → R}\n    (hv : ∀ w, Matrix.dotProduct v (mulVec M w) = 0) : v = 0 :=\n  hM v hv\n#align matrix.nondegenerate.eq_zero_of_ortho Matrix.Nondegenerate.eq_zero_of_ortho\n\n/-- If `M` is nondegenerate and `v ≠ 0`, then there is some `w` such that `w ⬝ M ⬝ v ≠ 0`. -/\ntheorem Nondegenerate.exists_not_ortho_of_ne_zero {M : Matrix m m R} (hM : Nondegenerate M)\n    {v : m → R} (hv : v ≠ 0) : ∃ w, Matrix.dotProduct v (mulVec M w) ≠ 0 :=\n  not_forall.mp (mt hM.eq_zero_of_ortho hv)\n#align matrix.nondegenerate.exists_not_ortho_of_ne_zero Matrix.Nondegenerate.exists_not_ortho_of_ne_zero\n\nvariable [CommRing A] [IsDomain A]\n\n/-- If `M` has a nonzero determinant, then `M` as a bilinear form on `n → A` is nondegenerate.\n\nSee also `bilin_form.nondegenerate_of_det_ne_zero'` and `bilin_form.nondegenerate_of_det_ne_zero`.\n-/\ntheorem nondegenerate_of_det_ne_zero [DecidableEq m] {M : Matrix m m A} (hM : M.det ≠ 0) :\n    Nondegenerate M := by\n  intro v hv\n  ext i\n  specialize hv (M.cramer (Pi.single i 1))\n  refine' (mul_eq_zero.mp _).resolve_right hM\n  convert hv\n  simp only [mul_vec_cramer M (Pi.single i 1), dot_product, Pi.smul_apply, smul_eq_mul]\n  rw [Finset.sum_eq_single i, Pi.single_eq_same, mul_one]\n  · intro j _ hj\n    simp [hj]\n  · intros\n    have := Finset.mem_univ i\n    contradiction\n#align matrix.nondegenerate_of_det_ne_zero Matrix.nondegenerate_of_det_ne_zero\n\ntheorem eq_zero_of_vecMul_eq_zero [DecidableEq m] {M : Matrix m m A} (hM : M.det ≠ 0) {v : m → A}\n    (hv : M.vecMul v = 0) : v = 0 :=\n  (nondegenerate_of_det_ne_zero hM).eq_zero_of_ortho fun w => by\n    rw [dot_product_mul_vec, hv, zero_dot_product]\n#align matrix.eq_zero_of_vec_mul_eq_zero Matrix.eq_zero_of_vecMul_eq_zero\n\ntheorem eq_zero_of_mulVec_eq_zero [DecidableEq m] {M : Matrix m m A} (hM : M.det ≠ 0) {v : m → A}\n    (hv : M.mulVec v = 0) : v = 0 :=\n  eq_zero_of_vecMul_eq_zero (by rwa [det_transpose]) ((vecMul_transpose M v).trans hv)\n#align matrix.eq_zero_of_mul_vec_eq_zero Matrix.eq_zero_of_mulVec_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/Matrix/Nondegenerate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939913343093499, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7749227715548543}}
{"text": "inductive bin : nat -> Prop\n| bin_epsilon : bin 0\n| bin_0 : ∀ n, bin n -> bin (2 * n)\n| bin_1 : ∀ n, bin n -> bin (2 * n + 1)\n\ndefinition is_expressible_in_binary_notation := bin.\n\nlemma zero_or_one {n} (h: n < 2): n = 0 ∨ n = 1\n:=\nbegin\n  cases h,\n  right, trivial,\n  left,\n  apply nat.eq_zero_of_le_zero,\n  exact nat.le_of_succ_le_succ h_a,\nend\n\nlemma two_gt_zero: 2 > 0 := nat.zero_lt_succ 1\n\nlemma half_lt {x} (h: 0 < x): x / 2 < x\n:=\nbegin\n  apply (nat.div_lt_iff_lt_mul x x two_gt_zero).2,\n  have h: x * 1 < x * 2, from nat.mul_lt_mul_of_pos_left dec_trivial h,\n  rw mul_one at h,\n  exact h\nend\n\nexample: ∀ n, is_expressible_in_binary_notation n\n:=\nbegin\n  intro n,\n  unfold is_expressible_in_binary_notation,\n  apply well_founded.induction nat.lt_wf n _; clear n,\n  intros x ih,\n  let q := x / 2,\n  let r := x % 2,\n  have hx: x = 2 * q + r, {\n    apply symm,\n    rw nat.add_comm,\n    exact nat.mod_add_div x 2,\n  },\n  have hq: x = 0 ∨ q < x, {\n    cases nat.eq_zero_or_pos x with h0 hp,\n      left,\n      exact h0,\n    right,\n    exact half_lt hp\n  },\n  cases hq with hx0 hqltx, {\n    rw hx0,\n    exact bin.bin_epsilon,\n  },\n  have r_lt_two: r < 2, {\n    apply nat.mod_lt,\n    exact nat.zero_lt_succ 1,\n  },\n  rw hx,\n  cases zero_or_one r_lt_two with hr0 hr1,\n  {\n    rw hr0,\n    simp,\n    apply bin.bin_0 q _,\n    exact ih q hqltx,\n  },\n  {\n    rw hr1,\n    apply bin.bin_1 q _,\n    exact ih q hqltx,\n  }\nend\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/ukikagi/top23.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7749227669706295}}
{"text": "\nimport linear_algebra.basic\nimport data.real.basic\nimport data.set.basic\nimport tactic.interactive\nimport .inner_product_space\n\nnoncomputable theory\nlocal attribute [instance] classical.prop_decidable\n\nsection basic\n\nvariables \n  {α : Type*} \n  [has_scalar ℝ α]\n  {ι : Sort _} \n  (A : set α) (B : set α) (x : α)  \n\nopen set\n\n-- Cones\n\ndef cone (A : set α) : Prop :=\n  ∀x ∈ A, ∀(c : ℝ), 0 ≤ c → c • x ∈ A\n\nlemma cone_empty : \n  cone ({} : set α) := \nby finish\n\nlemma cone_univ : \n  cone (univ : set α) := \nby finish\n\nlemma cone_inter (hA: cone A) (hB: cone B) : \n  cone (A ∩ B) :=\nλ x hx c hc,\n  mem_inter (hA _ (mem_of_mem_inter_left  hx) _ hc)\n            (hB _ (mem_of_mem_inter_right hx) _ hc)\n\nlemma cone_Inter {s: ι → set α} (h: ∀ i : ι, cone (s i)) : \n  cone (Inter s) :=\nbegin\n intros x hx c hc,\n rw mem_Inter at hx |-,\n exact (λ i, h i x (hx i) c hc)\nend\n\nlemma cone_union (hA: cone A) (hB: cone B) : \n  cone (A ∪ B) :=\nbegin\n  intros x hx c hc,\n  apply or.elim (mem_or_mem_of_mem_union hx),\n  { intro h, \n    apply mem_union_left, \n    apply hA _ h _ hc },\n  { intro h, \n    apply mem_union_right,\n    apply hB _ h _ hc }\nend\n\nlemma cone_Union {s: ι → set α} (h: ∀ i : ι, cone (s i)) : \n  cone (Union s) :=\nbegin\n  intros x hx c hc,\n  apply exists.elim (mem_Union.1 hx),\n  intros i hi,\n  apply mem_Union.2,\n  use i,\n  apply h i _ hi _ hc\nend\n\nend basic\n\nsection vector_space\n\nvariables \n  {α : Type*} \n  [add_comm_group α] [vector_space ℝ α]\n  (A : set α) (B : set α) (x : α)  \n\nopen set\n\nlemma cone_subspace {s : subspace ℝ α} : \n  cone (s.carrier) :=\nλ x hx c hc, s.smul c hx\n\nlemma cone_contains_0 (hA : cone A) : \n  A ≠ ∅ ↔ (0 : α) ∈ A :=\nbegin\n apply iff.intro,\n { intros h, \n   apply exists.elim (exists_mem_of_ne_empty h), \n   intros x hx, rw ←zero_smul ℝ, \n   apply hA x hx 0 (le_refl 0) },\n { intros h, \n   exact ne_empty_of_mem h }\nend\n\nlemma cone_0 {α : Type*} [add_comm_group α] [semimodule ℝ α] : cone ({0} : set α) :=\nbegin\n  intros x hx c hc,\n  apply mem_singleton_of_eq,\n  convert smul_zero c,\n  exact eq_of_mem_singleton hx\nend\n\nend vector_space\n\nsection dual_cone\n\ndef dual_cone {α : Type*} [has_inner ℝ α] (A : set α) : set α := \n{ y | ∀ x ∈ A, 0 ≤ ⟪ x, y ⟫ }\n\nopen real_inner_product_space\n\nvariables {α : Type*}\n  [real_inner_product_space α] \n  (A : set α) (B : set α)\n\nlemma cone_dual_cone : cone (dual_cone A) :=\nbegin\n  intros x ha c hc z hz,\n  rw inner_smul_right,\n  apply mul_nonneg' hc,\n  exact ha _ hz\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/cone.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7749187781101005}}
{"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-/\nimport number_theory.legendre_symbol.gauss_eisenstein_lemmas\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\nopen_locale nat\n\nnamespace nat\nvariable {n : ℕ}\n\n/-- For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` only if n is prime. -/\nlemma prime_of_fac_equiv_neg_one\n  (h : ((n - 1)! : zmod n) = -1) (h1 : n ≠ 1) : prime n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | h0,\n  { norm_num at h },\n  replace h1 : 1 < n := n.two_le_iff.mpr ⟨h0, h1⟩,\n  by_contradiction h2,\n  obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2,\n  have hm : m ∣ (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 [←zmod.nat_coe_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg],\nend\n\n/-- **Wilson's Theorem**: For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. -/\ntheorem prime_iff_fac_equiv_neg_one (h : n ≠ 1) :\n  prime n ↔ ((n - 1)! : zmod n) = -1 :=\nbegin\n  refine ⟨λ h1, _, λ h2, prime_of_fac_equiv_neg_one h2 h⟩,\n  haveI := fact.mk h1,\n  exact zmod.wilsons_lemma 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/number_theory/wilson.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8688267660487572, "lm_q1q2_score": 0.7748293090326659}}
{"text": "import algebra.group group_theory.subgroup\n\n-- `G` and `H` are groups\nvariables {G H : Type} [group G] [group H]\n\nopen subgroup\n\n-- `A` and `B` are normal subgroups of `G` and `H` respectively.\nvariables {A : subgroup G} [normal A] {B : subgroup H} [normal B]\n\n-- The following is, essentially, the definition of normal subgroup.\n--lemma normal_def : ∀ n ∈ A, ∀ g : G, g * n * g⁻¹ ∈ A:= normal.conj_mem infer_instance\n\nlemma normal_def {K : subgroup G} : normal K ↔ ∀ n ∈ K, ∀ g : G, g * n * g⁻¹ ∈ K :=\n⟨λ h, h.conj_mem, λ h, ⟨h⟩⟩ \n\nlemma conj_mem_of_normal {K : subgroup G} [normal K] : ∀ n ∈ K, ∀ g : G, g * n * g⁻¹ ∈ K\n  := normal_def.mp infer_instance\n\n\n-- We now prove that `A × B` is a normal subgroup of `G × H`\n-- Note that the (subgroup) product is written `prod A B` rather than `A × B`.\n\nlemma normal_prod : normal (prod A B) :=\n{ conj_mem := begin\n  rintros ⟨a, b⟩ hin ⟨g, h⟩,\n  rw prod.inv_mk, -- The result that `(s, t)⁻¹ = (t⁻¹, s⁻¹)`\n  rw prod.mk_mul_mk, -- The result that `(p, q) * (s, t) = (p * s, q * t)`\n  rw prod.mk_mul_mk,\n  rw mem_prod at hin ⊢, -- The result that `(u, v) ∈ prod U V ↔ u ∈ U ∧ v ∈ V`.\n  dsimp at hin ⊢, -- Make things look nicer.\n  rcases hin with ⟨ha, hb⟩,\n  split,\n  { apply conj_mem_of_normal, apply ha, },\n  { apply conj_mem_of_normal, apply hb },\nend\n}", "meta": {"author": "gihanmarasingha", "repo": "exleanblog", "sha": "aa6dc06cb64376dc87ba680815b9d14a904ad2ff", "save_path": "github-repos/lean/gihanmarasingha-exleanblog", "path": "github-repos/lean/gihanmarasingha-exleanblog/exleanblog-aa6dc06cb64376dc87ba680815b9d14a904ad2ff/src/2021/06/well_founded2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7748032207852074}}
{"text": "import data.set\nopen set\n\nsection\n  variable U: Type\n  variables A B C: set U\n\n  example : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=\n    assume x,\n    assume :x ∈ A ∩ C,\n    have x ∈ A, from and.left this,\n    show x ∈ A ∪ B, from or.inl this\n\n  example : ∀ x, x ∈ (A ∪ B)ᶜ  → x ∈ Aᶜ :=\n    assume x,\n    assume :x ∈ (A ∪ B)ᶜ,\n    have x ∈ Aᶜ ∩ Bᶜ, from eq.subst (compl_union A B) this,\n    show x ∈ Aᶜ, from and.left this\n\nend\n\nsection\n  variable {U : Type}\n\n  def disj (A B : set U) : Prop := ∀ ⦃x⦄, x ∈ A → x ∈ B → false\n\n  example (A B C D : set U) (h1 : disj A B) (h2 : C ⊆ A)\n      (h3 : D ⊆ B) :\n    disj C D :=\n  assume x,\n  assume :x ∈ C,\n  have x ∈ A, from h2 this,\n  assume :x ∈ D,\n  have x ∈ B, from h3 this,\n  show false, from h1 ‹x ∈ A› ‹x ∈ B› \n  \nend\n\nsection\n  variables {I U : Type}\n  variables (A : I → set U) (B : I → set U) (C : set U)\n\n  example : (⋂ i, A i) ∩ (⋂ i, B i) ⊆ (⋂ i, A i ∩ B i) :=\n    assume x,\n    assume h: x ∈ (⋂ i, A i) ∩ (⋂ i, B i),\n    have x ∈ (⋂ i, A i), from and.left h,\n    have x ∈ (⋂ i, B i), from and.right h,\n    have ∀i, x ∈ A i, by simp * at *,\n    have ∀i, x ∈ B i, by simp * at *,\n    have ∀i, x ∈ A i ∩ B i, from\n      assume i: I,\n      have x ∈ A i, from ‹∀i, x ∈ A i› i,\n      have x ∈ B i, from ‹∀i, x ∈ B i› i,\n      show x ∈ A i ∩ B i, from and.intro ‹x ∈ A i› ‹x ∈ B i›,\n    show x ∈ (⋂ i, A i ∩ B i), by simp * at *\n\n  example : C ∩ (⋃i, A i) ⊆ ⋃i, C ∩ A i :=\n    assume x,\n    assume h: x ∈ C ∩ (⋃i, A i),\n    have x ∈ C, from and.left h,\n    have x ∈ (⋃i, A i), from and.right h,\n    have ∃i, x ∈ A i, from by simp * at *,\n    have ∃i, x ∈ C ∩ A i, from exists.elim this $\n      assume i,\n      assume :x ∈ A i,\n      have x ∈ C ∩ A i, from and.intro ‹x ∈ C› this,\n      exists.intro i this,\n    show x ∈ ⋃i, C ∩ A i, by simp * at *\n    \nend\n\nsection\n  variable  {U : Type}\n  variables A B C : set U\n\n  example (h : A ⊆ B) : powerset A ⊆ powerset B :=\n    assume x,\n    assume :x ∈ powerset A,\n    show x ∈ powerset B, from subset.trans this h\n\n  example (h : powerset A ⊆ powerset B) : A ⊆ B :=\n    show A ⊆ B, from h (subset.refl A)\nend", "meta": {"author": "TateKennington", "repo": "logic-and-proof-exercises", "sha": "acca8882026e7b643453eb096d3021cd043005bd", "save_path": "github-repos/lean/TateKennington-logic-and-proof-exercises", "path": "github-repos/lean/TateKennington-logic-and-proof-exercises/logic-and-proof-exercises-acca8882026e7b643453eb096d3021cd043005bd/chapter12.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7748032116807702}}
{"text": "/-\nTHIS ASSIGNMENT IS DUE BEFORE 9AM \nON TUESDAY NEXT WEEK, BEFORE THE \nDAY'S 2101 CLASSES BEGIN. WE WILL \nREVIEW THE ANSWERS IN CLASS. THEN \nWE WILL GIVE An IN-CLASS, GRADED \nEXERCISE TO TEST YOUR UNDERSTANDING.\n\nThis file comes in two parts. The first\npart presents an example that you are to\nread and understand. It's an example of \na proof of a bi-implication between two\nequivalent disjunctions. The key lesson \nit teaches is proof by *case analysis*.\n\nWhen you are asked to prove that P ∨ Q \nimplies some conclusion, you do it by \ncase analysis. The idea is that if P ∨ Q \nis true, there are two ways in which it\ncan be true: either P is true, or Q is \ntrue. You have prove the goal follows \nin either case. If the goal follows in \neither case,  then it follows from the \ndisjunction, P ∨ Q, as a whole. \n\nWe use the \"cases\" tactic in lean to \nreason about the two possible cases of\na proof of P ∨ Q. Using this tactic \nproduces two subgoals. In one case, P \nis assumed to have a proof, p. In the\nother case, Q is assumed to have a proof,\nq. The aim then is to show that the main\ngoal follows in each case, as that will\nthen prove that the goal follows from \nthe disjunction as a whole.\n\nThe second part of this file presents a\nproblem for you to solve. One again it's\na bi-implication involving a disjunction\nas a premise (in one direction but not in\nthe other direction). \n\nIn both of these parts, we, or you will, \nstart by applying iff.intro to split the \nbi-implication into two implications to be proved. \n\nThen in the subproblems with disjunctions \nas premises, you will use case analysis. \nA hint: Remember that ¬ X means X → false,\nand the way to prove this is to assume X\nand show this leads to a contradiction. It\nis this maneuver that gets you a disjunction \nas a premise in the problem you're to solve.\n-/\n\n\n-- PART I: A WORKED EXAMPLE\n\n/-\nWe first show you how to prove P ∨ Q ↔ Q ∨ P.\nAt the highest level, the proof is by showing\nthe implication in each direction. Within each\ndirection, the proof is by case analysis for \nthe disjunction that forms the premise of the\nimplication. These ideas are explained in more\ndetail in the proof that follows.\n-/\n\ntheorem \nor_commutes :  \n    ∀ P Q: Prop, P ∨ Q ↔ Q ∨ P \n:=\nbegin\n\n/-\nIntroduce the assumptions that P and Q\nare arbitrary propositions.\n-/\nassume P Q: Prop,\n\n/-\nTo prove a bi-implication, we prove the\nimplications in each direction. That is, \nwe break the overall goal into subgoals, \none for the forward implication and one\nfor its converse (in the other direction).\n-/\napply iff.intro,\n\n    -- now we prove the forward implication\n    assume pq : P ∨ Q,\n    show Q ∨ P,\n    from\n        begin\n        /-\n        The key proof technique for reasoning \n        from a proof of a disjunction, P ∨ Q,\n        is to consider two possible cases for \n        this proof, that either P is true or \n        Q is, and to show that the goal is\n        true in either case. This shows that\n        no matter why P ∨ Q is true, the goal\n        follows.\n    \n        So, the proof strategy is first to \n        assumes that P ∨ Q is true because P \n        is true, which is to say you assume \n        you have a proof of P, and then show \n        that the goal follows. Then you assume \n        P ∨ Q is true because Q is true, and \n        you show that given an assumed proof\n        of Q, the goal follows. The goal thus\n        follows in either case. \n\n        The tactic that we use in Lean to \n        reason by cases from a disjunction is \n        called \"cases.\" As arguments you give \n        it (1) the name of the disjunction to \n        reason from, and (2) names to use for \n        the assumed proofs of P and Q in the \n        respective cases (after keyword \"with\").  \n\n        So here we go. Make sure you have the \n        Lean Messages window open so that you \n        can see how \"cases\" changes your tactic \n        state. Note that it introduces two new \n        subgoals. In the first, there is an \n        assumed proof, p : P. In the second, \n        there is an an assumed proof q : Q.\n        -/\n        cases pq with p q,\n        -- now prove each case separately\n\n            -- proof for case where P is true\n            show Q ∨ P,\n            from or.intro_right Q p,\n\n            -- proof for case where Q is true\n            show Q ∨ P,\n            from or.intro_left P q,\n        end,\n    \n    -- and now we prove the converse\n    assume qp : Q ∨ P,\n    show P ∨ Q,\n    from \n        begin\n        cases qp with q p,\n            show P ∨ Q,\n            from or.intro_right P q,\n            show P ∨ Q,\n            from or.intro_left Q p,\n        end,\nend\n\n\n\n-- PART II: YOUR HOMEWORK ASSIGNMENT\n\n/-\nHomework: \n\nProve, ∀ P Q: Prop, ¬ P ∧ ¬ Q ↔ ¬ (P ∨ Q) \n\n-/\n\ntheorem aDemorganLaw : \n    ∀ P Q: Prop, ¬ P ∧ ¬ Q ↔ ¬ (P ∨ Q) :=\nbegin\n_\nend", "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/HOMEWORK/HW4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167045, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7747967578184725}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández Palacios\n-/\n\nimport set_theory.game.ordinal\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 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} → ordinal.{u}\n| ⟨xl, xr, xL, xR⟩ :=\n    max (lsub.{u u} $ λ i, birthday (xL i)) (lsub.{u u} $ λ i, birthday (xR i))\n\ntheorem birthday_def (x : pgame) : birthday x = max\n  (lsub.{u u} (λ i, birthday (x.move_left i)))\n  (lsub.{u u} (λ 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 ↔\n  (∃ i : x.left_moves, o ≤ (x.move_left i).birthday) ∨\n  (∃ i : x.right_moves, o ≤ (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 (⟨i, hi⟩ | ⟨i, hi⟩),\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 : ∀ {x y : pgame.{u}}, x ≡r y → birthday x = birthday y\n| ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ ⟨L, R, hL, hR⟩ := begin\n  rw [birthday, birthday],\n  congr' 1,\n  all_goals\n  { apply lsub_eq_of_range_eq.{u u u},\n    ext i,\n    split },\n  { rintro ⟨j, rfl⟩,\n    exact ⟨L j, (hL j).birthday_congr.symm⟩ },\n  { rintro ⟨j, rfl⟩,\n    refine ⟨L.symm j, relabelling.birthday_congr _⟩,\n    convert hL (L.symm j),\n    rw L.apply_symm_apply },\n  { rintro ⟨j, rfl⟩,\n    refine ⟨R j, (relabelling.birthday_congr _).symm⟩,\n    convert hR (R j),\n    rw R.symm_apply_apply },\n  { rintro ⟨j, rfl⟩,\n    exact ⟨R.symm j, (hR j).birthday_congr⟩ }\nend\nusing_well_founded { dec_tac := pgame_wf_tac }\n\n@[simp] theorem birthday_add_zero (x : pgame) : birthday (x + 0) = birthday x :=\n(add_zero_relabelling x).birthday_congr\n\n@[simp] theorem birthday_zero_add (x : pgame) : birthday (0 + x) = birthday x :=\n(zero_add_relabelling x).birthday_congr\n\n@[simp] theorem birthday_eq_zero (x : pgame) :\n  birthday x = 0 ↔ is_empty x.left_moves ∧ 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 : ∀ x : pgame, (-x).birthday = x.birthday\n| ⟨xl, xr, xL, xR⟩ := begin\n  rw [birthday_def, birthday_def, max_comm],\n  congr; funext; apply neg_birthday\nend\n\n@[simp] \n\ntheorem le_birthday : ∀ x : pgame, x ≤ x.birthday.to_pgame\n| ⟨xl, _, xL, _⟩ :=\nle_def.2 ⟨λ i, or.inl ⟨to_left_moves_to_pgame ⟨_, birthday_move_left_lt i⟩,\n  by simp [le_birthday (xL i)]⟩, is_empty_elim⟩\n\ntheorem neg_birthday_le (x : pgame) : -x.birthday.to_pgame ≤ x :=\nlet h := le_birthday (-x) in by rwa [neg_birthday, neg_le_iff] at h\n\nend pgame\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/birthday.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7747654796483234}}
{"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 algebra.group.pi\nimport algebra.group_power.lemmas\nimport logic.function.iterate\n\n/-!\n# The group of permutations (self-equivalences) of a type `α`\n\nThis file defines the `group` structure on `equiv.perm α`.\n-/\nuniverses u v\n\nnamespace equiv\n\nvariables {α : Type u} {β : Type v}\n\nnamespace perm\n\ninstance perm_group : group (perm α) :=\n{ mul := λ f g, equiv.trans g f,\n  one := equiv.refl α,\n  inv := equiv.symm,\n  mul_assoc := λ f g h, (trans_assoc _ _ _).symm,\n  one_mul := trans_refl,\n  mul_one := refl_trans,\n  mul_left_inv := self_trans_symm }\n\ntheorem mul_apply (f g : perm α) (x) : (f * g) x = f (g x) :=\nequiv.trans_apply _ _ _\n\ntheorem one_apply (x) : (1 : perm α) x = x := rfl\n\n@[simp] lemma inv_apply_self (f : perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x\n\n@[simp] lemma apply_inv_self (f : perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x\n\nlemma one_def : (1 : perm α) = equiv.refl α := rfl\n\nlemma mul_def (f g : perm α) : f * g = g.trans f := rfl\n\nlemma inv_def (f : perm α) : f⁻¹ = f.symm := rfl\n\n@[simp] lemma coe_mul (f g : perm α) : ⇑(f * g) = f ∘ g := rfl\n\n@[simp] lemma coe_one : ⇑(1 : perm α) = id := rfl\n\nlemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply\n\nlemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq\n\nlemma zpow_apply_comm {α : Type*} (σ : perm α) (m n : ℤ) {x : α} :\n  (σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) :=\nby rw [←equiv.perm.mul_apply, ←equiv.perm.mul_apply, zpow_mul_comm]\n\n@[simp] lemma iterate_eq_pow (f : perm α) : ∀ n, f^[n] = ⇑(f ^ n)\n| 0       := rfl\n| (n + 1) := by { rw [function.iterate_succ, pow_add, iterate_eq_pow], refl }\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] lemma trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : perm β) = e :=\nequiv.trans_refl e\n\n@[simp] lemma mul_refl (e : perm α) : e * equiv.refl α = e := equiv.trans_refl e\n\n@[simp] lemma one_symm : (1 : perm α).symm = 1 := equiv.refl_symm\n\n@[simp] lemma refl_inv : (equiv.refl α : perm α)⁻¹ = 1 := equiv.refl_symm\n\n@[simp] lemma one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : perm α).trans e = e :=\nequiv.refl_trans e\n\n@[simp] lemma refl_mul (e : perm α) : equiv.refl α * e = e := equiv.refl_trans e\n\n@[simp] lemma inv_trans_self (e : perm α) : e⁻¹.trans e = 1 := equiv.symm_trans_self e\n\n@[simp] lemma mul_symm (e : perm α) : e * e.symm = 1 := equiv.symm_trans_self e\n\n@[simp] lemma self_trans_inv (e : perm α) : e.trans e⁻¹ = 1 := equiv.self_trans_symm e\n\n@[simp] lemma symm_mul (e : perm α) : e.symm * e = 1 := equiv.self_trans_symm e\n\n/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/\n\n@[simp] lemma sum_congr_mul {α β : Type*} (e : perm α) (f : perm β) (g : perm α) (h : perm β) :\n  sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=\nsum_congr_trans g h e f\n\n@[simp] lemma sum_congr_inv {α β : Type*} (e : perm α) (f : perm β) :\n  (sum_congr e f)⁻¹ = sum_congr e⁻¹ f⁻¹ :=\nsum_congr_symm e f\n\n@[simp] lemma sum_congr_one {α β : Type*} :\n  sum_congr (1 : perm α) (1 : perm β) = 1 :=\nsum_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 `α` and `β`. -/\n@[simps]\ndef sum_congr_hom (α β : Type*) :\n  perm α × perm β →* perm (α ⊕ β) :=\n{ to_fun := λ a, sum_congr a.1 a.2,\n  map_one' := sum_congr_one,\n  map_mul' := λ a b, (sum_congr_mul _ _ _ _).symm}\n\nlemma sum_congr_hom_injective {α β : Type*} :\n  function.injective (sum_congr_hom α β) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ h,\n  rw prod.mk.inj_iff,\n  split; ext i,\n  { simpa using equiv.congr_fun h (sum.inl i), },\n  { simpa using equiv.congr_fun h (sum.inr i), },\nend\n\n@[simp] lemma sum_congr_swap_one {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : α) :\n  sum_congr (equiv.swap i j) (1 : perm β) = equiv.swap (sum.inl i) (sum.inl j) :=\nsum_congr_swap_refl i j\n\n@[simp] lemma sum_congr_one_swap {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : β) :\n  sum_congr (1 : perm α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=\nsum_congr_refl_swap i j\n\n/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/\n\n@[simp] lemma sigma_congr_right_mul {α : Type*} {β : α → Type*}\n  (F : Π a, perm (β a)) (G : Π a, perm (β a)) :\n  sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=\nsigma_congr_right_trans G F\n\n@[simp] lemma sigma_congr_right_inv {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) :\n  (sigma_congr_right F)⁻¹ = sigma_congr_right (λ a, (F a)⁻¹) :=\nsigma_congr_right_symm F\n\n@[simp] lemma sigma_congr_right_one {α : Type*} {β : α → Type*} :\n  (sigma_congr_right (1 : Π a, equiv.perm $ β a)) = 1 :=\nsigma_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. -/\n@[simps]\ndef sigma_congr_right_hom {α : Type*} (β : α → Type*) :\n  (Π a, perm (β a)) →* perm (Σ a, β a) :=\n{ to_fun := sigma_congr_right,\n  map_one' := sigma_congr_right_one,\n  map_mul' := λ a b, (sigma_congr_right_mul _ _).symm }\n\nlemma sigma_congr_right_hom_injective {α : Type*} {β : α → Type*} :\n  function.injective (sigma_congr_right_hom β) :=\nbegin\n  intros x y h,\n  ext a b,\n  simpa using equiv.congr_fun h ⟨a, b⟩,\nend\n\n/-- `equiv.perm.subtype_congr` as a `monoid_hom`. -/\n@[simps] def subtype_congr_hom (p : α → Prop) [decidable_pred p] :\n  (perm {a // p a}) × (perm {a // ¬ p a}) →* perm α :=\n{ to_fun := λ pair, perm.subtype_congr pair.fst pair.snd,\n  map_one' := perm.subtype_congr.refl,\n  map_mul' := λ _ _, (perm.subtype_congr.trans _ _ _ _).symm }\n\nlemma subtype_congr_hom_injective (p : α → Prop) [decidable_pred p] :\n  function.injective (subtype_congr_hom p) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ h,\n  rw prod.mk.inj_iff,\n  split;\n  ext i;\n  simpa using equiv.congr_fun h i\nend\n\n/-- If `e` is also a permutation, we can write `perm_congr`\ncompletely in terms of the group structure. -/\n@[simp] lemma perm_congr_eq_mul (e p : perm α) :\n  e.perm_congr p = e * p * e⁻¹ := rfl\n\nsection extend_domain\n\n/-! Lemmas about `equiv.perm.extend_domain` re-expressed via the group structure. -/\n\nvariables (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p)\n\n@[simp] lemma extend_domain_one : extend_domain 1 f = 1 :=\nextend_domain_refl f\n\n@[simp] lemma extend_domain_inv : (e.extend_domain f)⁻¹ = e⁻¹.extend_domain f := rfl\n\n@[simp] lemma extend_domain_mul (e e' : perm α) :\n  (e.extend_domain f) * (e'.extend_domain f) = (e * e').extend_domain f :=\nextend_domain_trans _ _ _\n\n/-- `extend_domain` as a group homomorphism -/\n@[simps] def extend_domain_hom : perm α →* perm β :=\n{ to_fun := λ e, extend_domain e f,\n  map_one' := extend_domain_one f,\n  map_mul' := λ e e', (extend_domain_mul f e e').symm }\n\nlemma extend_domain_hom_injective : function.injective (extend_domain_hom f) :=\n(injective_iff_map_eq_one (extend_domain_hom f)).mpr (λ e he, ext (λ x, f.injective (subtype.ext\n  ((extend_domain_apply_image e f x).symm.trans (ext_iff.mp he (f x))))))\n\n@[simp] \n\nend extend_domain\n\n/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation\n  on `{x // p x}` induced by `f`. -/\ndef subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} :=\n⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩,\n  λ _, by simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk],\n  λ _, by simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk]⟩\n\n@[simp] lemma subtype_perm_apply (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x))\n  (x : {x // p x}) : subtype_perm f h x = ⟨f x, (h _).1 x.2⟩ := rfl\n\n@[simp] lemma subtype_perm_one (p : α → Prop) (h : ∀ x, p x ↔ p ((1 : perm α) x)) :\n  @subtype_perm α 1 p h = 1 :=\nequiv.ext $ λ ⟨_, _⟩, rfl\n\n/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,\n  fixing the other points. -/\ndef of_subtype {p : α → Prop} [decidable_pred p] : perm (subtype p) →* perm α :=\n{ to_fun := λ f,\n  ⟨λ x, if h : p x then f ⟨x, h⟩ else x, λ x, if h : p x then f⁻¹ ⟨x, h⟩ else x,\n  λ x, have h : ∀ h : p x, p (f ⟨x, h⟩), from λ h, (f ⟨x, h⟩).2,\n    by { simp only [], split_ifs at *;\n         simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk, not_true, *] at * },\n  λ x, have h : ∀ h : p x, p (f⁻¹ ⟨x, h⟩), from λ h, (f⁻¹ ⟨x, h⟩).2,\n    by { simp only [], split_ifs at *;\n         simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk, not_true, *] at * }⟩,\n  map_one' := begin ext, dsimp, split_ifs; refl, end,\n  map_mul' := λ f g, equiv.ext $ λ x, begin\n  by_cases h : p x,\n  { have h₁ : p (f (g ⟨x, h⟩)), from (f (g ⟨x, h⟩)).2,\n    have h₂ : p (g ⟨x, h⟩), from (g ⟨x, h⟩).2,\n    simp only [h, h₂, coe_fn_mk, perm.mul_apply, dif_pos, subtype.coe_eta] },\n  { simp only [h, coe_fn_mk, perm.mul_apply, dif_neg, not_false_iff] }\nend }\n\nlemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p]\n  (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) :\n  of_subtype (subtype_perm f h₁) = f :=\nequiv.ext $ λ x, begin\n  rw [of_subtype, subtype_perm],\n  by_cases hx : p x,\n  { simp only [hx, coe_fn_mk, dif_pos, monoid_hom.coe_mk, subtype.coe_mk]},\n  { haveI := classical.prop_decidable,\n    simp only [hx, not_not.mp (mt (h₂ x) hx), coe_fn_mk, dif_neg, not_false_iff,\n      monoid_hom.coe_mk] }\nend\n\nlemma of_subtype_apply_of_mem {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) {x : α} (hx : p x) :\n  of_subtype f x = f ⟨x, hx⟩ :=\ndif_pos hx\n\n@[simp] lemma of_subtype_apply_coe {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) (x : subtype p)  :\n  of_subtype f x = f x :=\nsubtype.cases_on x $ λ _, of_subtype_apply_of_mem f\n\nlemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) {x : α} (hx : ¬ p x) :\n  of_subtype f x = x :=\ndif_neg hx\n\nlemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) (x : α) :\n  p x ↔ p ((of_subtype f : α → α) x) :=\nif h : p x then by simpa only [of_subtype, h, coe_fn_mk, dif_pos, true_iff, monoid_hom.coe_mk]\n  using (f ⟨x, h⟩).2\nelse by simp [h, of_subtype_apply_of_not_mem f h]\n\n@[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) :\n  subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f :=\nequiv.ext $ λ ⟨x, hx⟩, by { dsimp [subtype_perm, of_subtype],\n  simp only [show p x, from hx, dif_pos, subtype.coe_eta] }\n\n@[simp] lemma default_perm {n : Type*} : (default : perm n) = 1 := rfl\n\n/-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise\nthe rest. -/\n@[simps] protected def subtype_equiv_subtype_perm (p : α → Prop) [decidable_pred p] :\n  perm (subtype p) ≃ {f : perm α // ∀ a, ¬p a → f a = a} :=\n{ to_fun := λ f, ⟨f.of_subtype, λ a, f.of_subtype_apply_of_not_mem⟩,\n  inv_fun := λ f, (f : perm α).subtype_perm\n    (λ a, ⟨decidable.not_imp_not.1 $ λ hfa, (f.val.injective (f.prop _ hfa) ▸ hfa),\n    decidable.not_imp_not.1 $ λ ha hfa, ha $ f.prop a ha ▸ hfa⟩),\n  left_inv := equiv.perm.subtype_perm_of_subtype,\n  right_inv := λ f,\n    subtype.ext (equiv.perm.of_subtype_subtype_perm _ $ λ a, not.decidable_imp_symm $ f.prop a) }\n\nlemma subtype_equiv_subtype_perm_apply_of_mem {α : Type*} {p : α → Prop}\n  [decidable_pred p] (f : perm (subtype p)) {a : α} (h : p a) :\n  perm.subtype_equiv_subtype_perm p f a = f ⟨a, h⟩ :=\nf.of_subtype_apply_of_mem h\n\nlemma subtype_equiv_subtype_perm_apply_of_not_mem {α : Type*} {p : α → Prop}\n  [decidable_pred p] (f : perm (subtype p)) {a : α} (h : ¬ p a) :\n  perm.subtype_equiv_subtype_perm p f a = a :=\nf.of_subtype_apply_of_not_mem h\n\nvariables (e : perm α) (ι : α ↪ β)\n\nopen_locale classical\n\n/-- Noncomputable version of `equiv.perm.via_fintype_embedding` that does not assume `fintype` -/\nnoncomputable def via_embedding : perm β :=\nextend_domain e (of_injective ι.1 ι.2)\n\nlemma via_embedding_apply (x : α) : e.via_embedding ι (ι x) = ι (e x) :=\nextend_domain_apply_image e (of_injective ι.1 ι.2) x\n\nlemma via_embedding_apply_of_not_mem (x : β) (hx : x ∉ _root_.set.range ι) :\n  e.via_embedding ι x = x :=\nextend_domain_apply_not_subtype e (of_injective ι.1 ι.2) hx\n\n/-- `via_embedding` as a group homomorphism -/\nnoncomputable def via_embedding_hom : perm α →* perm β:=\nextend_domain_hom (of_injective ι.1 ι.2)\n\nlemma via_embedding_hom_apply : via_embedding_hom ι e = via_embedding e ι := rfl\n\nlemma via_embedding_hom_injective : function.injective (via_embedding_hom ι) :=\nextend_domain_hom_injective (of_injective ι.1 ι.2)\n\nend perm\n\nsection swap\nvariables [decidable_eq α]\n\n@[simp] lemma swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl\n\n@[simp] lemma swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j\n\nlemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=\nequiv.ext $ λ z, begin\n  simp only [perm.mul_apply, swap_apply_def],\n  split_ifs;\n  simp only [perm.apply_inv_self, *, perm.eq_inv_iff_eq, eq_self_iff_true, not_true] at *\nend\n\nlemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f :=\nby rw [swap_mul_eq_mul_swap, perm.inv_apply_self, perm.inv_apply_self]\n\nlemma swap_apply_apply (f : perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ :=\nby rw [mul_swap_eq_swap_mul, mul_inv_cancel_right]\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]\nlemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ :=\nby rw [←mul_assoc, swap_mul_self, one_mul]\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]\nlemma mul_swap_mul_self (i j : α) (σ : perm α) : (σ * equiv.swap i j) * equiv.swap i j = σ :=\nby rw [mul_assoc, swap_mul_self, mul_one]\n\n/-- A stronger version of `mul_right_injective` -/\n@[simp]\nlemma swap_mul_involutive (i j : α) : function.involutive ((*) (equiv.swap i j)) :=\nswap_mul_self_mul i j\n\n/-- A stronger version of `mul_left_injective` -/\n@[simp]\nlemma mul_swap_involutive (i j : α) : function.involutive (* (equiv.swap i j)) :=\nmul_swap_mul_self i j\n\n@[simp] lemma swap_eq_one_iff {i j : α} : swap i j = (1 : perm α) ↔ i = j :=\nswap_eq_refl_iff\n\nlemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j :=\n⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm),\n  by {rw [←swap_apply_right i j, swap_id], refl}),\n(assume h, by erw [h, swap_self, one_mul])⟩\n\nlemma mul_swap_eq_iff {i j : α} {σ : perm α} : σ * swap i j = σ ↔ i = j :=\n⟨(assume h, have swap_id : swap i j = 1 := mul_left_cancel (trans h (one_mul σ).symm),\n  by {rw [←swap_apply_right i j, swap_id], refl}),\n(assume h, by erw [h, swap_self, mul_one])⟩\n\nlemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) :\n  swap y z * swap x y * swap y z = swap z x :=\nequiv.ext $ λ n, by { simp only [swap_apply_def, perm.mul_apply], split_ifs; cc }\n\nend swap\n\nend equiv\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7747654775081801}}
{"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.fin.tuple.sort\nimport data.fintype.perm\nimport order.well_founded\n\n/-!\n# \"Bubble sort\" induction\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe implement the following induction principle `tuple.bubble_sort_induction`\non tuples with values in a linear order `α`.\n\nLet `f : fin n → α` and let `P` be a predicate on `fin n → α`. Then we can show that\n`f ∘ sort f` satisfies `P` if `f` satisfies `P`, and whenever some `g : fin n → α`\nsatisfies `P` and `g i > g j` for some `i < j`, then `g ∘ swap i j` also satisfies `P`.\n\nWe deduce it from a stronger variant `tuple.bubble_sort_induction'`, which\nrequires the assumption only for `g` that are permutations of `f`.\n\nThe latter is proved by well-founded induction via `well_founded.induction_bot'`\nwith respect to the lexicographic ordering on the finite set of all permutations of `f`.\n-/\n\nnamespace tuple\n\n/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`\nif `f` satsifies `P` and `P` is preserved on permutations of `f` when swapping two\nantitone values. -/\nlemma bubble_sort_induction' {n : ℕ} {α : Type*} [linear_order α] {f : fin n → α}\n  {P : (fin n → α) → Prop} (hf : P f)\n  (h : ∀ (σ : equiv.perm (fin n)) (i j : fin n),\n              i < j → (f ∘ σ) j < (f ∘ σ) i → P (f ∘ σ) → P (f ∘ σ ∘ equiv.swap i j)) :\n  P (f ∘ sort f) :=\nbegin\n  letI := @preorder.lift _ (lex (fin n → α)) _ (λ σ : equiv.perm (fin n), to_lex (f ∘ σ)),\n  refine @well_founded.induction_bot' _ _ _\n    (@finite.preorder.well_founded_lt (equiv.perm (fin n)) _ _)\n    (equiv.refl _) (sort f) P (λ σ, f ∘ σ) (λ σ hσ hfσ, _) hf,\n  obtain ⟨i, j, hij₁, hij₂⟩ := antitone_pair_of_not_sorted' hσ,\n  exact ⟨σ * equiv.swap i j, pi.lex_desc hij₁ hij₂, h σ i j hij₁ hij₂ hfσ⟩,\nend\n\n/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`\nif `f` satsifies `P` and `P` is preserved when swapping two antitone values. -/\nlemma bubble_sort_induction {n : ℕ} {α : Type*} [linear_order α] {f : fin n → α}\n  {P : (fin n → α) → Prop} (hf : P f)\n  (h : ∀ (g : fin n → α) (i j : fin n), i < j → g j < g i → P g → P (g ∘ equiv.swap i j)) :\n  P (f ∘ sort f) :=\nbubble_sort_induction' hf (λ σ, h _)\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/bubble_sort_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213880824789, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7746274355444563}}
{"text": "import .love09_hoare_logic_demo\n\n\n/-! # LoVe Exercise 9: Hoare Logic -/\n\n\nset_option pp.beta true\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\" (λs, 0) ;;\nstmt.while (λs, s \"n\" ≠ 0)\n  (stmt.assign \"r\" (λs, s \"r\" + s \"n\") ;;\n   stmt.assign \"n\" (λs, s \"n\" - 1))\n\n/-! The summation function: -/\n\ndef sum_upto : ℕ → ℕ\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₀ : ℕ) :\n    {* λs, s \"n\" = n₀ *} GAUSS {* λs, s \"r\" = sum_upto n₀ *} :=\nshow {* λs, s \"n\" = n₀ *}\n  stmt.assign \"r\" (λs, 0) ;;\n  stmt.while_inv (λ s, (sum_upto (s \"n\")) + s \"r\" ==  sum_upto n₀ )\n    (λs, s \"n\" ≠ 0)\n    (stmt.assign \"r\" (λs, s \"r\" + s \"n\") ;;\n    stmt.assign \"n\" (λs, s \"n\" - 1))\n    {* λs, s \"r\" = sum_upto n₀ *}, from\nbegin\n  vcg; simp {contextual := tt},\n  {\n    intros s hinv hloop,\n    rw <- hinv,\n    have h: (sum_upto (s \"n\" - 1)) + s \"n\" = sum_upto (s \"n\"), by {\n      cases (s \"n\"),\n      { triv,},\n      {\n        have h2: sum_upto(n.succ - 1) == sum_upto n, by {\n            simp,\n        },\n        simp [h2, sum_upto],\n        have h3: (sum_upto n) + n.succ = (sum_upto n) + (n + 1), by {\n          have h4: n.succ = n + 1, by { simp },\n          simp [h4],\n        },\n        simp [h3],\n        cc,\n      }\n    },\n    rw <- h,\n    cc,\n  },\n  {\n    intros s hinv hloop,\n    rw <- hloop,\n    unfold sum_upto,\n    finish,\n  }\nend\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₀`. -/\n\ndef MUL : stmt :=\nstmt.assign \"r\" (λs, 0) ;;\nstmt.while (λs, s \"n\" ≠ 0)\n  (stmt.assign \"r\" (λs, s \"r\" + s \"m\") ;;\n   stmt.assign \"n\" (λs, s \"n\" - 1))\n\nlemma MUL_correct (n₀ m₀ : ℕ) :\n  {* λs, s \"n\" = n₀ ∧ s \"m\" = m₀ *} MUL {* λs, s \"r\" = n₀ * m₀ *} :=\nsorry\n\n\n/-! ## Question 2: Hoare Triples for Total Correctness -/\n\ndef total_hoare (P : state → Prop) (S : stmt) (Q : state → Prop) : Prop :=\n∀s, P s → ∃t, (S, s) ⟹ t ∧ Q t\n#print total_hoare\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 → Prop} {S}\n    (hS : [* P *] S [* Q *]) (hP : ∀s, P' s → P s) (hQ : ∀s, Q s → Q' s) :\n  [* P' *] S [* Q' *] :=\nbegin\n    intro s,\n    intro hps,\n    cases hS s (hP s hps),\n    use w,\n    cases h,\n    tautology,\nend\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 → Prop} {x} {a : state → ℕ} :\n  [* λs, P (s{x ↦ 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 → Prop} {S T}\n    (hS : [* λs, P s ∧ b s *] S [* Q *])\n    (hT : [* λs, P s ∧ ¬ 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_intro.aux` as induction\nhypothesis we recommend to do it directly after proving that the argument is\nless than `v₀`:\n\n    have ih : ∃u, (stmt.while b S, t) ⟹ u ∧ I u ∧ ¬ b u :=\n      have V t < v₀ :=\n        …,\n      while_intro.aux (V t) …,\n\nSimilarly to `ite`, the proof requires a case distinction on `b s ∨ ¬ b s`. -/\n\nlemma while_intro.aux {b : state → Prop} (I : state → Prop) (V : state → ℕ) {S}\n  (h_inv : ∀v₀, [* λs, I s ∧ b s ∧ V s = v₀ *] S [* λs, I s ∧ V s < v₀ *]) :\n  ∀v₀ s, V s = v₀ → I s → ∃t, (stmt.while b S, s) ⟹ t ∧ I t ∧ ¬ b t\n| v₀ s V_eq hs :=\nsorry\n\nlemma while_intro {b : state → Prop} (I : state → Prop) (V : state → ℕ) {S}\n  (hinv : ∀v₀, [* λs, I s ∧ b s ∧ V s = v₀ *] S [* λs, I s ∧ V s < v₀ *]) :\n  [* I *] stmt.while b S [* λs, I s ∧ ¬ b s *] :=\nsorry\n\nend total_hoare\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/love09_hoare_logic_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8991213806488609, "lm_q1q2_score": 0.7746274275418671}}
{"text": "import data.real.basic\nimport data.set.basic\nimport tactic\n\nnamespace mth1001\n\n/-\nWe'll only deal with real-valued sequences. Such a sequence is merely a function from `ℕ` to `ℝ`\nWe'll use the Lean built-in real number type rather than the type we've constructed.\n-/\n\nsection convergence\n\n-- `convergesto f a` means\ndef convergesto (f : ℕ → ℝ) (a : ℝ) := ∀ ε > 0, ∃ N, ∀ n ≥ N, abs (f n - a) < ε\n\n/-\nWe'll prove that the sequence `f₁ : ℕ → R` given by `f₁(n) = 5` converges to `5`.\n-/\n\ndef f₁ : ℕ → ℝ := λ n, (5 : ℝ)\n\nexample : convergesto f₁ 5 :=\nbegin\n  assume ε : ℝ,\n  assume εpos : ε > 0, -- It suffices to prove `∃ N, ∀ n ≥ N, abs (f₁ n - 5) < ε`.\n  use 1, -- Take `N := 1`.\n  assume n : ℕ,\n  assume hn : n ≥ 1,\n  unfold f₁, -- By unfolding, it suffices to show `abs (5 - 5) < ε`.\n  norm_num, -- That is, to prove `abs 0 < ε`.\n  linarith, -- This is proven by the `linarith` tactic.\nend\n\n/-\nMore generally, we'll show a constant sequence converges.\n-/\n\n-- Exercise 075:\nlemma convergesto_const (c : ℝ) : convergesto (λ n, c) c :=\nbegin\n  assume ε : ℝ,\n  assume εpos : ε > 0,\n  sorry  \nend\n\nend convergence\n\nsection uniqueness_of_limits\n\nvariables {f : ℕ → ℝ} {a b : ℝ}\n\nlemma convergesto_unique (h₁ : convergesto f a) (h₂ : convergesto f b) : a = b :=\nbegin\n  sorry\nend\n\n\nend uniqueness_of_limits\n\nsection algebra_of_limits\n\nvariables (f g : ℕ → ℝ) -- `f` and `g` are sequences\nvariables (a b c : ℝ)\n\n-- The following result will often come in handy!\nlemma div_abs_pos_of_pos_of_non_zero {ε c : ℝ} (εpos : ε > 0) (h : c ≠ 0) : ε / abs c > 0 :=\nbegin\n  have h₂ : 0 < abs c, from  abs_pos_iff.mpr h,\n  have h₃ : 0 < (abs c)⁻¹, from inv_pos.mpr h₂,\n  exact mul_pos εpos h₃,\nend\n\nexample (a b c : ℝ) (h₁ : a < b / c) (h₂ : 0 < c): a * c < b := (lt_div_iff h₂).mp h₁\n\nexample (a b : ℝ) : abs (a*b) = abs a * abs b := abs_mul a b\n\nexample (x y : ℝ) : x ≤ max x y := le_max_left x y\n\nexample (x y : ℝ) : y ≤ max x y := le_max_right x y\n\n-- Exercise 076:\ntheorem convergesto_scalar_mul (h : convergesto f a) : convergesto (λ n, c * (f n)) (c * a) :=\nbegin\n  by_cases h₂ : c = 0,\n  { sorry, }, \n  { sorry, }, \nend\n\n-- Here is the triangle inequality in Lean.\nexample (x y : ℝ) : abs (x + y) ≤ abs x + abs y := abs_add x y\n\n-- Exercise 077:\ntheorem convergesto_add (h₁ : convergesto f a) (h₂ : convergesto g b )\n: convergesto (λ n, f n + g n) (a + b) :=\nbegin\n  sorry  \nend\n\n-- Exercise 078:\n-- The same proof can be written more briefly using `congr'` and by giving arguments to `linarith`.\nexample (h₁ : convergesto f a) (h₂ : convergesto g b ) : convergesto (λ n, f n + g n) (a + b) :=\nbegin\n  sorry    \nend\n\n\nend algebra_of_limits\n\nsection specific_example\n\n/-\nIn Lean, it's often harder to work with particular examples than with general theorems.\nHere, we show convergence of a particular sequence.\n\nWe'll need the corollorary to the Archimedean property. In Lean,this is `exists_nat_one_div_lt`.\nNote the use of `↑n` to indicate the embedding (or coercion) of the natural number `n`\nas a real number.\n-/\n\nexample (ε : ℝ) (h : 0 < ε) : ∃ n : ℕ, 1/(↑n + 1) < ε := exists_nat_one_div_lt h\n\nexample (x : ℝ) (h : x > 0) : abs x = x := abs_of_pos h\n\nexample (x : ℝ) (h : 0 < x) : 0 < x⁻¹ := by {rwa inv_pos}\n\nexample (x : ℝ) (h : 0 < x) : x⁻¹ = (1 : ℝ) / x := inv_eq_one_div x\n\n-- Now we'll show the sequence given by `λ n, 3 + 1/n` converges to `3`.\nexample : convergesto (λ n, 3 + 1/n) 3 :=\nbegin\n  unfold convergesto,\n  assume ε εpos,\n  have h : ∃ N : ℕ, 1/(↑N + 1) < ε, from exists_nat_one_div_lt εpos,\n  cases h with N hN, -- By `∃` elim. on `h`, STP the goal assuming `N : ℕ` and `hN : 1/(↑N+1) < ε`.\n  use N + 1, -- By `∃` intro on `N + 1`, it suffices to prove\n  -- `∀ n ≥ N + 1, n ≥ N + 1 → abs (3 + 1/↑n - 3) < ε`.\n  assume n hn, -- assume `n : ℕ` and `hn : n ≥ N`.\n  have h₂ : abs ((3 : ℝ) + 1 / ↑n - 3)  = abs (↑n)⁻¹, ring,\n  rw h₂,\n  have : N + 1 > 0, linarith,\n  have : n > 0, linarith,\n  have :  (0 : ℝ) < ↑n, { rwa nat.cast_pos },\n  have : (0 : ℝ) < N + 1, {change (0 : ℝ) < ↑(N + 1), rw nat.cast_pos, linarith, },\n  have : (0 : ℝ) < (↑n)⁻¹, { rwa inv_pos },\n  rw abs_of_pos this,\n  have : (↑n)⁻¹ ≤ (↑N + (1 : ℝ))⁻¹,\n  { rw inv_le_inv, \n    change ↑(N + 1) ≤ ↑n,\n    rwa nat.cast_le,\n    repeat { assumption }, },\n  apply lt_of_le_of_lt,\n  { assumption, },\n  { rwa inv_eq_one_div, },\nend\n\nend specific_example\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_40_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8289388167733099, "lm_q1q2_score": 0.7745564219497783}}
{"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ölzl\nPorted by: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.order.group.order_iso\n! leanprover-community/mathlib commit a95b16cbade0f938fc24abd05412bde1e84bab9b\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.Defs\nimport Mathlib.Algebra.Hom.Equiv.Units.Basic\n\n/-!\n# Inverse and multiplication as order isomorphisms in ordered groups\n\n-/\n\nopen Function\n\nuniverse u\n\nvariable {α : Type u}\n\nsection Group\n\nvariable [Group α]\n\nsection TypeclassesLeftRightLE\n\nvariable [LE α] [CovariantClass α α (· * ·) (· ≤ ·)] [CovariantClass α α (swap (· * ·)) (· ≤ ·)]\n  {a b c d : α}\n\nsection\n\nvariable (α)\n\n/-- `x ↦ x⁻¹` as an order-reversing equivalence. -/\n@[to_additive (attr := simps!) \"`x ↦ -x` as an order-reversing equivalence.\"]\ndef OrderIso.inv : α ≃o αᵒᵈ where\n  toEquiv := (Equiv.inv α).trans OrderDual.toDual\n  map_rel_iff' {_ _} := @inv_le_inv_iff α _ _ _ _ _ _\n#align order_iso.inv OrderIso.inv\n#align order_iso.neg OrderIso.neg\n#align order_iso.inv_apply OrderIso.inv_apply\n#align order_iso.inv_symm_apply OrderIso.inv_symm_apply\n\nend\n\n@[to_additive neg_le]\ntheorem inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=\n  (OrderIso.inv α).symm_apply_le\n#align inv_le' inv_le'\n#align neg_le neg_le\n\nalias inv_le' ↔ inv_le_of_inv_le' _\n#align inv_le_of_inv_le' inv_le_of_inv_le'\n\nattribute [to_additive neg_le_of_neg_le] inv_le_of_inv_le'\n#align neg_le_of_neg_le neg_le_of_neg_le\n\n@[to_additive le_neg]\ntheorem le_inv' : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=\n  (OrderIso.inv α).le_symm_apply\n#align le_inv' le_inv'\n#align le_neg le_neg\n\nend TypeclassesLeftRightLE\n\nend Group\n\nalias le_inv' ↔ le_inv_of_le_inv _\n#align le_inv_of_le_inv le_inv_of_le_inv\n\nattribute [to_additive] le_inv_of_le_inv\n#align le_neg_of_le_neg le_neg_of_le_neg\n\nsection Group\n\nvariable [Group α] [LE α]\n\nsection Right\n\nvariable [CovariantClass α α (swap (· * ·)) (· ≤ ·)] {a b c d : α}\n\n/-- `Equiv.mulRight` as an `OrderIso`. See also `OrderEmbedding.mulRight`. -/\n@[to_additive (attr := simps! (config := { simpRhs := true }) toEquiv apply)\n  \"`Equiv.addRight` as an `OrderIso`. See also `OrderEmbedding.addRight`.\"]\ndef OrderIso.mulRight (a : α) : α ≃o α where\n  map_rel_iff' {_ _} := mul_le_mul_iff_right a\n  toEquiv := Equiv.mulRight a\n#align order_iso.mul_right OrderIso.mulRight\n#align order_iso.add_right OrderIso.addRight\n#align order_iso.mul_right_apply OrderIso.mulRight_apply\n#align order_iso.mul_right_to_equiv OrderIso.mulRight_toEquiv\n\n@[to_additive (attr := simp)]\ntheorem OrderIso.mulRight_symm (a : α) : (OrderIso.mulRight a).symm = OrderIso.mulRight a⁻¹ := by\n  ext x\n  rfl\n#align order_iso.mul_right_symm OrderIso.mulRight_symm\n#align order_iso.add_right_symm OrderIso.addRight_symm\n\nend Right\n\nsection Left\n\nvariable [CovariantClass α α (· * ·) (· ≤ ·)]\n\n/-- `Equiv.mulLeft` as an `OrderIso`. See also `OrderEmbedding.mulLeft`. -/\n@[to_additive (attr := simps! (config := { simpRhs := true }) toEquiv apply)\n  \"`Equiv.addLeft` as an `OrderIso`. See also `OrderEmbedding.addLeft`.\"]\ndef OrderIso.mulLeft (a : α) : α ≃o α where\n  map_rel_iff' {_ _} := mul_le_mul_iff_left a\n  toEquiv := Equiv.mulLeft a\n#align order_iso.mul_left OrderIso.mulLeft\n#align order_iso.add_left OrderIso.addLeft\n#align order_iso.mul_left_apply OrderIso.mulLeft_apply\n#align order_iso.add_left_apply OrderIso.addLeft_apply\n#align order_iso.add_left_to_equiv OrderIso.addLeft_toEquiv\n\n@[to_additive (attr := simp)]\ntheorem OrderIso.mulLeft_symm (a : α) : (OrderIso.mulLeft a).symm = OrderIso.mulLeft a⁻¹ := by\n  ext x\n  rfl\n#align order_iso.mul_left_symm OrderIso.mulLeft_symm\n#align order_iso.add_left_symm OrderIso.addLeft_symm\n\nend Left\n\nend Group\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/OrderIso.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7745564155667635}}
{"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_space.ordered\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 `β`. While the\ndefinition only requires `β` to be a `normed_group`, most interesting properties require it to be a\n`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 `β` is a `normed_group` :\n\n- `_ ~[l] _` is an equivalence relation\n- Equivalent statements for `u ~[l] const _ c` :\n  - If `c ≠ 0`, this is true iff `tendsto u l (𝓝 c)` (see `is_equivalent_const_iff_tendsto`)\n  - For `c = 0`, this is true iff `u =ᶠ[l] 0` (see `is_equivalent_zero_iff_eventually_zero`)\n\nIf `β` is a `normed_field` :\n\n- Alternative characterization of the relation (see `is_equivalent_iff_exists_eq_mul`) :\n\n  `u ~[l] v ↔ ∃ (φ : α → β) (hφ : tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v`\n\n- Provided some non-vanishing hypothesis, this can be seen as `u ~[l] v ↔ tendsto (u/v) l (𝓝 1)`\n  (see `is_equivalent_iff_tendsto_one`)\n- For any constant `c`, `u ~[l] v` implies `tendsto u l (𝓝 c) ↔ tendsto v l (𝓝 c)`\n  (see `is_equivalent.tendsto_nhds_iff`)\n- `*` and `/` are compatible with `_ ~[l] _` (see `is_equivalent.mul` and `is_equivalent.div`)\n\nIf `β` is a `normed_linear_ordered_field` :\n\n- If `u ~[l] v`, we have `tendsto u l at_top ↔ 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 α) (u v : α → β)` 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 topological_space\n\nsection normed_group\n\nvariables {α β : Type*} [normed_group β]\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 α) (u v : α → β) := (u - v) =o[l] v\n\nlocalized \"notation u ` ~[`:50 l:50 `] `:0 v:50 := asymptotics.is_equivalent l u v\" in asymptotics\n\nvariables {u v w : α → β} {l : filter α}\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 α} {u v w : α → β}\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 : α → β} {l : filter α} (huv : u ~[l] v)\n  (huw : u =ᶠ[l] w) : w ~[l] v :=\nhuv.congr' (huw.sub (eventually_eq.refl _ _)) (eventually_eq.refl _ _)\n\nlemma is_equivalent.congr_right {u v w : α → β} {l : filter α} (huv : u ~[l] v)\n  (hvw : v =ᶠ[l] w) : u ~[l] w :=\n(huv.symm.congr_left hvw).symm\n\nlemma is_equivalent_zero_iff_eventually_zero : u ~[l] 0 ↔ u =ᶠ[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 ↔ u =O[l] (0 : α → β) :=\nbegin\n  refine ⟨is_equivalent.is_O, λ h, _⟩,\n  rw [is_equivalent_zero_iff_eventually_zero, eventually_eq_iff_exists_mem],\n  exact ⟨{x : α | u x = 0}, is_O_zero_right_iff.mp h, λ x hx, hx⟩,\nend\n\nlemma is_equivalent_const_iff_tendsto {c : β} (h : c ≠ 0) : u ~[l] const _ c ↔ tendsto u l (𝓝 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 ← sub_self c} ];\n  convert this; try { ext }; simp\nend\n\nlemma is_equivalent.tendsto_const {c : β} (hu : u ~[l] const _ c) : tendsto u l (𝓝 c) :=\nbegin\n  rcases (em $ c = 0) with ⟨rfl, h⟩,\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 : β} (huv : u ~[l] v) :\n  tendsto u l (𝓝 c) ↔ tendsto v l (𝓝 c) := ⟨huv.tendsto_nhds, huv.symm.tendsto_nhds⟩\n\nlemma is_equivalent.add_is_o (huv : u ~[l] v) (hwv : w =o[l] v) : (w + u) ~[l] v :=\nby simpa only [is_equivalent, pi.sub_apply, add_sub] using hwv.add huv\n\nlemma is_o.add_is_equivalent (hu : u =o[l] w) (hv : v ~[l] w) : (u + v) ~[l] w :=\nadd_comm u v ▸ 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) : (λ x, - u x) ~[l] (λ 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_group\n\nopen_locale asymptotics\n\nsection normed_field\n\nvariables {α β : Type*} [normed_field β] {t u v w : α → β} {l : filter α}\n\nlemma is_equivalent_iff_exists_eq_mul : u ~[l] v ↔\n  ∃ (φ : α → β) (hφ : tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v :=\nbegin\n  rw [is_equivalent, is_o_iff_exists_eq_mul],\n  split; rintros ⟨φ, hφ, h⟩; [use (φ + 1), use (φ - 1)]; split,\n  { conv in (𝓝 _) { rw ← zero_add (1 : β) },\n    exact hφ.add (tendsto_const_nhds) },\n  { convert h.add (eventually_eq.refl l v); ext; simp [add_mul] },\n  { conv in (𝓝 _) { rw ← sub_self (1 : β) },\n    exact hφ.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  ∃ (φ : α → β) (hφ : tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v :=\nis_equivalent_iff_exists_eq_mul.mp huv\n\nlemma is_equivalent_of_tendsto_one (hz : ∀ᶠ x in l, v x = 0 → u x = 0)\n  (huv : tendsto (u/v) l (𝓝 1)) : u ~[l] v :=\nbegin\n  rw is_equivalent_iff_exists_eq_mul,\n  refine ⟨u/v, huv, hz.mono $ λ x hz', (div_mul_cancel_of_imp hz').symm⟩,\nend\n\nlemma is_equivalent_of_tendsto_one' (hz : ∀ x, v x = 0 → u x = 0) (huv : tendsto (u/v) l (𝓝 1)) :\n  u ~[l] v :=\nis_equivalent_of_tendsto_one (eventually_of_forall hz) huv\n\nlemma is_equivalent_iff_tendsto_one (hz : ∀ᶠ x in l, v x ≠ 0) :\n  u ~[l] v ↔ tendsto (u/v) l (𝓝 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 (λ x, v x / v x) l (𝓝 1),\n    { exact (tendsto_congr' $ hz.mono $ λ 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 $ λ x hnvz hz, (hnvz hz).elim) }\nend\n\nend normed_field\n\nsection smul\n\nlemma is_equivalent.smul {α E 𝕜 : Type*} [normed_field 𝕜] [normed_group E]\n  [normed_space 𝕜 E] {a b : α → 𝕜} {u v : α → E} {l : filter α} (hab : a ~[l] b) (huv : u ~[l] v) :\n  (λ x, a x • u x) ~[l] (λ x, b x • v x) :=\nbegin\n  rcases hab.exists_eq_mul with ⟨φ, hφ, habφ⟩,\n  have : (λ (x : α), a x • u x) - (λ (x : α), b x • v x) =ᶠ[l] λ x, b x • ((φ x • u x) - v x),\n  { convert (habφ.comp₂ (•) $ eventually_eq.refl _ u).sub (eventually_eq.refl _ (λ x, b x • v x)),\n    ext,\n    rw [pi.mul_apply, mul_comm, mul_smul, ← 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 ⟨C, hC, hCuv⟩,\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φ,\n  intros c hc,\n  specialize hφ ((c/2)/C) (div_pos (by linarith) hC),\n  specialize huv (show 0 < c/2, by linarith),\n  refine hφ.mp (huv.mp $ hCuv.mono $ λ x hCuvx huvx hφx, _),\n\n  have key :=\n    calc ∥φ x - 1∥ * ∥u x∥\n            ≤ (c/2) / C * ∥u x∥ : mul_le_mul_of_nonneg_right hφx.le (norm_nonneg $ u x)\n        ... ≤ (c/2) / C * (C*∥v x∥) : mul_le_mul_of_nonneg_left hCuvx (div_pos (by linarith) hC).le\n        ... = c/2 * ∥v x∥ : by {field_simp [hC.ne.symm], ring},\n\n  calc ∥((λ (x : α), φ x • u x) - v) x∥\n          = ∥(φ x - 1) • u x + (u x - v x)∥ : by simp [sub_smul, sub_add]\n      ... ≤ ∥(φ x - 1) • u x∥ + ∥u x - v x∥ : norm_add_le _ _\n      ... = ∥φ x - 1∥ * ∥u x∥ + ∥u x - v x∥ : by rw norm_smul\n      ... ≤ c / 2 * ∥v x∥ + ∥u x - v x∥ : add_le_add_right key _\n      ... ≤ c / 2 * ∥v x∥ + c / 2 * ∥v x∥ : add_le_add_left huvx _\n      ... = c * ∥v x∥ : by ring,\nend\n\nend smul\n\nsection mul_inv\n\nvariables {α β : Type*} [normed_field β] {t u v w : α → β} {l : filter α}\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) : (λ x, (u x)⁻¹) ~[l] (λ x, (v x)⁻¹) :=\nbegin\n  rw is_equivalent_iff_exists_eq_mul at *,\n  rcases huv with ⟨φ, hφ, h⟩,\n  rw ← inv_one,\n  refine ⟨λ x, (φ x)⁻¹, tendsto.inv₀ hφ (by norm_num) , _⟩,\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  (λ x, t x / v x) ~[l] (λ 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 {α β : Type*} [normed_linear_ordered_field β] {u v : α → β} {l : filter α}\n\nlemma is_equivalent.tendsto_at_top [order_topology β] (huv : u ~[l] v) (hu : tendsto u l at_top) :\n  tendsto v l at_top :=\nlet ⟨φ, hφ, h⟩ := huv.symm.exists_eq_mul in\ntendsto.congr' h.symm ((mul_comm u φ) ▸ (hu.at_top_mul zero_lt_one hφ))\n\nlemma is_equivalent.tendsto_at_top_iff [order_topology β] (huv : u ~[l] v) :\n  tendsto u l at_top ↔ tendsto v l at_top := ⟨huv.tendsto_at_top, huv.symm.tendsto_at_top⟩\n\nlemma is_equivalent.tendsto_at_bot [order_topology β] (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 β] (huv : u ~[l] v) :\n  tendsto u l at_bot ↔ tendsto v l at_bot := ⟨huv.tendsto_at_bot, huv.symm.tendsto_at_bot⟩\n\nend normed_linear_ordered_field\n\nend asymptotics\n\nopen filter asymptotics\nopen_locale asymptotics\n\nvariables {α β : Type*} [normed_group β]\n\nlemma filter.eventually_eq.is_equivalent {u v : α → β} {l : filter α} (h : u =ᶠ[l] v) : u ~[l] v :=\nis_equivalent.congr_right (is_o_refl_left _ _) h\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/asymptotics/asymptotic_equivalent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951616274769, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7745564058577201}}
{"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ébastien Gouëzel\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 $(-∞, +∞)$;\n* `convex_on_pow_of_even` : given an even natural number $n$, the function $f(x)=x^n$\n  is convex on $(-∞, +∞)$;\n* `convex_on_pow` : for a natural $n$, the function $f(x)=x^n$ is convex on $[0, +∞)$;\n* `convex_on_fpow` : for an integer $m$, the function $f(x)=x^m$ is convex on $(0, +∞)$.\n* `convex_on_rpow : ∀ p : ℝ, 1 ≤ p → convex_on (Ici 0) (λ 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 : ℕ` is convex on the whole real line whenever `n` is even -/\ntheorem convex_on_pow_of_even {n : ℕ} (hn : even n) : convex_on set.univ fun (x : ℝ) => x ^ n := sorry\n\n/-- `x^n`, `n : ℕ` is convex on `[0, +∞)` for all `n` -/\ntheorem convex_on_pow (n : ℕ) : convex_on (set.Ici 0) fun (x : ℝ) => x ^ n := sorry\n\ntheorem finset.prod_nonneg_of_card_nonpos_even {α : Type u_1} {β : Type u_2} [linear_ordered_comm_ring β] {f : α → β} [decidable_pred fun (x : α) => f x ≤ 0] {s : finset α} (h0 : even (finset.card (finset.filter (fun (x : α) => f x ≤ 0) s))) : 0 ≤ finset.prod s fun (x : α) => f x := sorry\n\ntheorem int_prod_range_nonneg (m : ℤ) (n : ℕ) (hn : even n) : 0 ≤ finset.prod (finset.range n) fun (k : ℕ) => m - ↑k := sorry\n\n/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` -/\ntheorem convex_on_fpow (m : ℤ) : convex_on (set.Ioi 0) fun (x : ℝ) => x ^ m := sorry\n\ntheorem convex_on_rpow {p : ℝ} (hp : 1 ≤ p) : convex_on (set.Ici 0) fun (x : ℝ) => 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\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/specific_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810481379379, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7745545662926717}}
{"text": "import Sets.Basic\nimport Functions.Basic\nimport Relations.Basic\n\nopen Set\nopen Func\nopen Relations \n\nvariable { α : Type }\n\n-- Problem 1 \n\ntheorem subset_refl : Reflexive (@Subset α) := sorry \n\ntheorem subset_antisymm : AntiSymmetric (@Subset α) := sorry  \n\ntheorem subset_trans : Transitive (@Subset α) := sorry \n\n-- Problem 2 \n\ndef Rel (f : α → α) (a₁ a₂ : α) : Prop := sorry \n\ntheorem refl_id (f : α → α) (h : Reflexive (Rel f) ) : f = id := sorry  \n\ntheorem symm_involution (f : α → α) (h : Symmetric (Rel f)) : f ∘ f = id := sorry  \n\ntheorem trans_idempotent (f : α → α) (h : Transitive (Rel f)) : f ∘ f = f := sorry  \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/Hw11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810451666345, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7745545596523857}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Importar la teoría de anillos.\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Crear el espacio de nombre my_ring\n-- ----------------------------------------------------------------------\n\nnamespace my_ring\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Declarar R como una variable sobre anillos.\n-- ----------------------------------------------------------------------\n\nvariables {R : Type*} [ring R]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que para todo a, b ∈ R,\n--    -a + (a + b) = b\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (a b : R)\n  : -a + (a + b) = b :=\ncalc -a + (a + b)\n     = (-a + a) + b : by rw ← add_assoc\n ... = 0 + b        : by rw add_left_neg\n ... = b            : by rw zero_add\n\n-- 2ª demostración\n-- ===============\n\ntheorem neg_add_cancel_left\n  (a b : R)\n  : -a + (a + b) = b :=\nby rw [←add_assoc, add_left_neg, zero_add]\n\n-- El desarrollo de la prueba es\n--\n--    R : Type u_1,\n--    _inst_1 : ring R,\n--    a b : R\n--    ⊢ -a + (a + b) = b\n-- rw ← add_assoc,\n--    ⊢ -a + a + b = b\n-- rw add_left_neg,\n--    ⊢ 0 + b = b\n-- rw zero_add,\n--    no goals\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Cerrar el espacio de nombre my_ring.\n-- ----------------------------------------------------------------------\n\nend my_ring\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/neg_add_cancel_left.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.7745312186752125}}
{"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 5 : \"iff\" (`↔`)\n\nWe learn about how to manipulate `P ↔ Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following two new tactics:\n\n* `refl`\n* `rw`\n\n### The `refl` tactic\n\nIf your goal is `P ↔ P` then `refl,` will solve it.\n\n### The `rw` tactic\n\nIf `h : P ↔ Q` is a hypothesis, you can decompose it\nusing `cases h with hPQ hQP,`. However, if you keep\nit around then you can do `rw h,` which changes all `P`s in the goal to `Q`s.\nVariant: `rw h at h2,` will change all `P`s to `Q`s in hypothesis `h2`.\n\n-/\n\nvariables (P Q R S : Prop)\n\nexample : P ↔ P :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  sorry\nend\n\nexample : P ∧ Q ↔ Q ∧ P :=\nbegin\n  sorry\nend\n\nexample : ((P ∧ Q) ∧ R) ↔ (P ∧ (Q ∧ R)) :=\nbegin\n  sorry\nend\n\nexample : P ↔ (P ∧ true) :=\nbegin\n  sorry\nend\n\nexample : false ↔ (P ∧ false) :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) → (R ↔ S) → (P ∧ R ↔ Q ∧ S) :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ↔ ¬ P) :=\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/logic/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8670357683915538, "lm_q1q2_score": 0.7745311974388517}}
{"text": "/-\nCopyright (c) 2014 Mario Carneiro. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro\n-/\nimport data.int.cast.defs\n\n/-!\n# Characteristic zero\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nA ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered\nas an element of `R`. Since this definition doesn't mention the multiplicative structure of `R`\nexcept for the existence of `1` in this file characteristic zero is defined for additive monoids\nwith `1`.\n\n## Main definition\n\n`char_zero` is the typeclass of an additive monoid with one such that the natural homomorphism\nfrom the natural numbers into it is injective.\n\n## TODO\n\n* Unify with `char_p` (possibly using an out-parameter)\n-/\n\n/-- Typeclass for monoids with characteristic zero.\n  (This is usually stated on fields but it makes sense for any additive monoid with 1.)\n\n*Warning*: for a semiring `R`, `char_zero R` and `char_p R 0` need not coincide.\n* `char_zero R` requires an injection `ℕ ↪ R`;\n* `char_p R 0` asks that only `0 : ℕ` maps to `0 : R` under the map `ℕ → R`.\n\nFor instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that\n`char_zero {0, 1}` does not hold and yet `char_p {0, 1} 0` does.\nThis example is formalized in `counterexamples/char_p_zero_ne_char_zero`.\n -/\nclass char_zero (R : Type*) [add_monoid_with_one R] : Prop :=\n(cast_injective : function.injective (coe : ℕ → R))\n\ntheorem char_zero_of_inj_zero {R : Type*} [add_group_with_one R]\n  (H : ∀ n:ℕ, (n:R) = 0 → n = 0) : char_zero R :=\n⟨λ m n h, begin\n  induction m with m ih generalizing n, { rw H n, rw [← h, nat.cast_zero] },\n  cases n with n, { apply H, rw [h, nat.cast_zero], },\n  simp_rw [nat.cast_succ, add_right_cancel_iff] at h, rwa ih,\nend⟩\n\nnamespace nat\nvariables {R : Type*} [add_monoid_with_one R] [char_zero R]\n\ntheorem cast_injective : function.injective (coe : ℕ → R) :=\nchar_zero.cast_injective\n\n@[simp, norm_cast] theorem cast_inj {m n : ℕ} : (m : R) = n ↔ m = n :=\ncast_injective.eq_iff\n\n@[simp, norm_cast] theorem cast_eq_zero {n : ℕ} : (n : R) = 0 ↔ n = 0 :=\nby rw [← cast_zero, cast_inj]\n\n@[norm_cast] theorem cast_ne_zero {n : ℕ} : (n : R) ≠ 0 ↔ n ≠ 0 :=\nnot_congr cast_eq_zero\n\nlemma cast_add_one_ne_zero (n : ℕ) : (n + 1 : R) ≠ 0 :=\nby exact_mod_cast n.succ_ne_zero\n\n@[simp, norm_cast] \n\n@[norm_cast] theorem cast_ne_one {n : ℕ} : (n : R) ≠ 1 ↔ n ≠ 1 :=\ncast_eq_one.not\n\nend nat\n\nnamespace ne_zero\n\ninstance char_zero {M} {n : ℕ}\n  [ne_zero n] [add_monoid_with_one M] [char_zero M] : ne_zero (n : M) :=\n⟨nat.cast_ne_zero.mpr out⟩\n\nend ne_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/char_zero/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.867035758084294, "lm_q1q2_score": 0.7745311882312795}}
{"text": "import 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 : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=\n  assume x,\n  assume h : x ∈ A ∩ C,\n  have h1 : x ∈ A, from and.left h,\n  show x ∈ A ∪ B, from or.inl h1\n\n  example : ∀ x, x ∈ (A ∪ B)ᶜ → x ∈ Aᶜ :=\n  assume x,\n  assume h : x ∈ (A ∪ B)ᶜ,\n  have h1 : ¬ x ∈ (A ∪ B), from h,\n    assume h2 : x ∈ A, \n    show false, from h1 (or.inl h2)\n \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 := ∀ ⦃x⦄, x ∈ A → x ∈ B → false\n\n  example (A B : set U) (h : ∀ x, ¬ (x ∈ A ∧ x ∈ B)) : disj A B :=\n  assume x,\n  assume h1 : x ∈ A,\n  assume h2 : x ∈ B,\n  have h3 : x ∈ A ∧ x ∈ 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 ∈ A) (h3 : x ∈ B) : false :=\n  h1 h2 h3\n\n  -- the same is true of ⊆\n  example (A B : set U) (x : U) (h : A ⊆ B) (h1 : x ∈ A) : x ∈ B :=\n  h h1\n\n  example (A B C D : set U) (h1 : disj A B) (h2 : C ⊆ A) (h3 : D ⊆ B) : disj C D :=\n  assume x,   \n  assume h4: x ∈ C,\n  assume h5: x ∈ D,\n  have h6: x ∈ A, from h2 h4,\n  have h7: x ∈ B, from h3 h5, \n  show false, from h1 h6 h7\n\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 → set U} {B : I → set U} {C : set U}\n\n  theorem Inter.intro {x : U} (h : ∀ i, x ∈ A i) : x ∈ ⋂ i, A i :=\n  by simp; assumption\n\n  @[elab_simple]\n  theorem Inter.elim {x : U} (h : x ∈ ⋂ i, A i) (i : I) : x ∈ A i :=\n  by simp at h; apply h\n\n  theorem Union.intro {x : U} (i : I) (h : x ∈ A i) : x ∈ ⋃ i, A i :=\n  by {simp, existsi i, exact h}\n\n  theorem Union.elim {P : Prop} {x : U} (h₁ : x ∈ ⋃ i, A i) (h₂ : ∀ (i : I), x ∈ A i → P) : P :=\n  by {simp at h₁, cases h₁ with i h, exact h₂ i h}\n\n  example : (⋂ i, A i) ∩ (⋂ i, B i) ⊆ (⋂ i, A i ∩ B i) :=\n  assume x,\n  assume h3 : x ∈ ((⋂ i, A i) ∩ (⋂ i, B i)), \n  have h4 : x ∈ (⋂ i, A i), from h3.left,\n  have h5 : x ∈ (⋂ i, B i), from h3.right,\n  show x ∈ (⋂ i, A i ∩ B i), from \n  Inter.intro \n    (assume i : I,\n     have h1: x ∈ A i, from Inter.elim h4 i,\n     have h2: x ∈ B i, from Inter.elim h5 i,\n     show x ∈ A i ∩ B i, from and.intro h1 h2)\n\n  example : C ∩ (⋃i, A i) ⊆ ⋃i, C ∩ A i :=\n  assume x : U,\n  assume h : x ∈ C ∩ (⋃i, A i),\n  show x ∈ ⋃ i, C ∩ A i, from\n  Union.elim h.right \n    (assume i : I,\n     assume h1: x ∈ A i,\n     show  x ∈ ⋃ i, C ∩ A i, from \n     Union.intro i (and.intro h.left h1))\n     \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  -- For this exercise these two facts are useful\n  example (h1 : A ⊆ B) (h2 : B ⊆ C) : A ⊆ C :=\n  subset.trans h1 h2\n\n  example : A ⊆ A :=\n  subset.refl A\n\n  example (h : A ⊆ B) : powerset A ⊆ powerset B :=\n  assume X : set U,\n  assume h1 : X ∈ powerset A,\n  show X ∈ powerset B, from subset.trans h1 h\n  \n\n  example (h : powerset A ⊆ powerset B) : A ⊆ B :=\n  assume x: U,\n  assume h1 : x ∈ A,\n  have h2: {y|x = y} ∈ powerset A, from \n    assume z,\n    assume : z ∈ {y| x = y},\n    have x = z, from this,\n      show z ∈ A, from eq.subst this h1, \n      have h3: {y| x = y} ∈ powerset B, from h h2, \n      have h4: x ∈ {y| x = y}, from eq.refl x,\n      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'​ out of a strict partial order R.\nsection\n  parameters {A : Type} {R : A → A → 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 ∨ a = b\n  local infix ≤ := R'\n\n  theorem reflR' (a : A) : a ≤ a :=\n  have h1: a = a, from eq.refl a,\n  show a ≤ a, from or.inr h1\n  \n  theorem transR' {a b c : A} (h1 : a ≤ b) (h2 : b ≤ c): a ≤ 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 h5: b = c, eq.subst h5 h1))\n      (assume h6: a = b, eq.subst (eq.symm h6) h2)\n\n  theorem antisymmR' {a b : A} (h1 : a ≤ b) (h2 : b ≤ 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 h4: b = a, eq.symm h4))\n        (assume h5: a = b, h5)\n\nend\n\n-- 6\nsection\n  parameters {A : Type} {R : A → A → Prop}\n  parameter (reflR : reflexive R)\n  parameter (transR : transitive R)\n\n  def S (a b : A) : Prop := R a b ∧ R b a\n\n  example : transitive S :=\n  assume x y z,\n  assume h1 : S x y,\n  assume h2 : S y z,\n  and.intro (transR h1.left h2.left) (transR h2.right h1.right)\n\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 → A → Prop}\n  parameter (Rab : R a b)\n  parameter (Rbc : R b c)\n  parameter (nRac : ¬ R a c)\n\n  --theorem R_is_strict_partial_order : irreflexive R ∧ transitive R :=\n  -- this theorem is not provable\n  --sorry\n\n  theorem R_is_not_strict_partial_order : ¬(irreflexive R ∧ transitive R) :=\n  assume h: irreflexive R ∧ transitive R, \n  show false, from nRac (h.right Rab Rbc)\n\nend\n\n-- 8\nsection\n  open nat\n\n  example : 1 ≤ 4 :=\n  have l1: 1 + 1 = 2, by simp,\n  have h1: 1 <  2, from lt_succ_self 1, \n  have l2 : 2 + 1 = 3, by simp,\n  have h2: (1 + 1) < 3, from lt_succ_self (1 + 1),\n  have l3 : 3 + 1 = 4, by simp,\n  have h3: (1 + 1 + 1) < 4, from lt_succ_self (1 + 1 + 1),\n  have h4: 1 ≤ 4, from le_of_lt (lt_trans h1 (lt_trans h2 h3)),\n  show 1 ≤ 4, from eq.subst l3 h4\n\nend\n\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-3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7745311854837441}}
{"text": "import data.real.basic\n\nvariables {x y : ℝ}\n\n#check le_refl\n#check le_refl y\n#check @le_abs \n#check @abs_le\n#check neg_add\n#check add_le_add\n\nnamespace my_abs\n\n-- BEGIN\ntheorem le_abs_self : x ≤ abs x :=\nbegin\n  rw le_abs,\n  left,\n  apply le_refl,\nend\n\ntheorem neg_le_abs_self : -x ≤ abs x :=\nbegin\n  rw le_abs,\n  right,\n  apply le_refl,\nend\n-- END\n\n#check @le_abs_self\n#check @neg_le_abs_self\n\nend my_abs", "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/ex1_disj_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7745255554785856}}
{"text": "open function int algebra\n\ndef f (x : ℤ) : ℤ := x + 3\ndef g (x : ℤ) : ℤ := -x\ndef h (x : ℤ) : ℤ := 2 * x + 3\n\nexample : injective f :=\nassume x1 x2,\nassume h1 : x1 + 3 = x2 + 3,   -- Lean knows this is the same as f x1 = f x2\nshow x1 = x2, from eq_of_add_eq_add_right h1\n\nexample : surjective f :=\nassume y,\nhave h1 : f (y - 3) = y, from calc\n  f (y - 3) = (y - 3) + 3 : rfl\n        ... = y           : by rw sub_add_cancel,\nshow ∃ x, f x = y, from exists.intro (y - 3) h1\n\nexample (x y : ℤ) (h : 2 * x = 2 * y) : x = y :=\nhave h1 : 2 ≠ (0 : ℤ), from dec_trivial,  -- this tells Lean to figure it out itself\nshow x = y, from eq_of_mul_eq_mul_left h1 h\n\nexample (x : ℤ) : -(-x) = x := neg_neg x\n\nexample (A B : Type) (u : A → B) (v : B → A) (h : left_inverse u v) :\n  ∀ x, u (v x) = x :=\nh\n\nexample (A B : Type) (u : A → B) (v : B → A) (h : left_inverse u v) :\n  right_inverse v u :=\nh\n\n-- fill in the sorry's in the following proofs\n\nexample : injective h :=\nassume x₁ x₂,\nassume : 2 * x₁ + 3 = 2 * x₂ + 3,\nhave 2 * x₁ = 2 * x₂ , from eq_of_add_eq_add_right this,\nhave 2 ≠ (0 : ℤ), from dec_trivial,\nshow x₁ = x₂ , from eq_of_mul_eq_mul_left this ‹ 2 * x₁ = 2 * x₂ ›\n\nexample : surjective g :=\nassume y,\nhave h₁ : g (-y) = y, from calc\n  g (-y) = -(-y): rfl\n     ... =     y: by rw neg_neg,\nshow ∃ x, g x = y, from exists.intro (-y) h₁\n\nexample (A B : Type) (u : A → B) (v1 : B → A) (v2 : B → A)\n  (h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=\nfunext\n  (assume x,\n    calc\n      v1 x = v1 (u (v2 x)) : by rw (h2 x)\n       ... = v2 x          : by rw (h1 (v2 x)))\n\n---\n\nimport data.set\nopen function set\n\nvariables {X Y : Type}\nvariable  f : X → Y\nvariables A B : set X\n\nexample : f '' (A ∪ B) = f '' A ∪ f '' B :=\neq_of_subset_of_subset\n  (assume y,\n    assume h1 : y ∈ f '' (A ∪ B),\n    exists.elim h1 $\n    assume x h,\n    have h2 : x ∈ A ∪ B, from h.left,\n    have h3 : f x = y, from h.right,\n    or.elim h2\n      (assume h4 : x ∈ A,\n        have h5 : y ∈ f '' A, from ⟨x, h4, h3⟩,\n        show y ∈ f '' A ∪ f '' B, from or.inl h5)\n      (assume h4 : x ∈ B,\n        have h5 : y ∈ f ''  B, from ⟨x, h4, h3⟩,\n        show y ∈ f '' A ∪ f '' B, from or.inr h5))\n  (assume y,\n    assume h2 : y ∈ f '' A ∪ f '' B,\n    or.elim h2\n      (assume h3 : y ∈ f '' A,\n        exists.elim h3 $\n        assume x h,\n        have h4 : x ∈ A, from h.left,\n        have h5 : f x = y, from h.right,\n        have h6 : x ∈ A ∪ B, from or.inl h4,\n        show y ∈ f '' (A ∪ B), from ⟨x, h6, h5⟩)\n      (assume h3 : y ∈ f '' B,\n        exists.elim h3 $\n        assume x h,\n        have h4 : x ∈ B, from h.left,\n        have h5 : f x = y, from h.right,\n        have h6 : x ∈ A ∪ B, from or.inr h4,\n        show y ∈ f '' (A ∪ B), from ⟨x, h6, h5⟩))\n\n-- remember, x ∈ A ∩ B is the same as x ∈ A ∧ x ∈ B\nexample (x : X) (h1 : x ∈ A) (h2 : x ∈ B) : x ∈ A ∩ B :=\nand.intro h1 h2\n\nexample (x : X) (h1 : x ∈ A ∩ B) : x ∈ A :=\nand.left h1\n\n-- Fill in the proof below.\n-- (It should take about 8 lines.)\n\nexample : f '' (A ∩ B) ⊆ f '' A ∩ f '' B :=\nassume y,\nassume h1 : y ∈ f '' (A ∩ B),\nshow y ∈ f '' A ∩ f '' B, from\n  exists.elim h1 $\n    assume x h,\n    have y ∈ f '' A, from ⟨ x, h.left.left, h.right ⟩,\n    have y ∈ f '' B, from ⟨ x, h.left.right, h.right ⟩,\n    ⟨ ‹ y ∈ f '' A › , ‹ y ∈ f '' B › ⟩\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/ch16.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7744764887167634}}
{"text": "-- Notes/exercises from:\n-- https://leanprover.github.io/theorem_proving_in_lean/index.html\n-- Section 3 (Propositions and Proofs)\n\nopen classical\n\nvariables p q r s : Prop\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=\n  iff.intro\n  -- Written out a little more verbosely so I can test some things:\n  (assume h : p ∧ q,\n    have hp : p, from and.left h,\n    have hq : q, from and.right h,\n    show q ∧ p, from and.intro hq hp)\n  (assume h : q ∧ p,\n    have hq : q, from and.left h,\n    have hp : p, from and.right h,\n    show p ∧ q, from and.intro hp hq)\n\nexample : p ∨ q ↔ q ∨ p :=\n  iff.intro\n  (assume h : p ∨ q, \n    or.elim h (assume hp : p, show q ∨ p, from or.inr hp)\n              (assume hq : q, show q ∨ p, from or.inl hq))\n  (assume h : q ∨ p,\n    or.elim h (assume hq : q, show p ∨ q, from or.inr hq)\n              (assume hp : p, show p ∨ q, from or.inl hp))\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  iff.intro\n    (assume hpqr : (p ∧ q) ∧ r,\n      have hr : r, from and.right hpqr,\n      have hpq : p ∧ q, from and.left hpqr,\n      have hp : p, from and.left hpq,\n      have hq : q, from and.right hpq,\n      show p ∧ (q ∧ r), from and.intro hp (and.intro hq hr))\n    (assume hpqr : p ∧ (q ∧ r), \n      have hp : p, from and.left hpqr,\n      have hqr : q ∧ r, from and.right hpqr,\n      have hq : q, from and.left hqr,\n      have hr : r, from and.right hqr,\n      show (p ∧ q) ∧ r, from and.intro (and.intro hp hq) hr)\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n  iff.intro\n    (assume hpqr : (p ∨ q) ∨ r, \n      or.elim hpqr\n        (assume hpq : p ∨ q,\n          or.elim hpq\n            (assume hp : p, or.inl hp)\n            -- Now I see how 'show' is just an annotation:\n            (assume hq : q, show p ∨ (q ∨ r), from or.inr (or.inl hq)))\n        (assume hr : r, or.inr (or.inr hr)))\n    (assume hpqr : p ∨ (q ∨ r),\n      or.elim hpqr\n        (assume hp : p, or.inl (or.inl hp))\n        (assume hqr : q ∨ r,\n          or.elim hqr\n            (assume hq : q, or.inl (or.inr hq))\n            (assume hr : r, or.inr hr)))\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n  iff.intro\n    (assume h : p ∧ (q ∨ r),\n      (show (p ∧ q) ∨ (p ∧ r), from\n        and.elim h\n          (assume hp : p, assume hqr : q ∨ r,\n            or.elim hqr\n              (assume hq : q, or.inl (and.intro hp hq))\n              (assume hr : r, or.inr (and.intro hp hr)))))\n    (assume h : (p ∧ q) ∨ (p ∧ r),\n      (show p ∧ (q ∨ r), from\n        or.elim h\n          (assume hpq : (p ∧ q),\n            have hp : p, from and.left hpq,\n            have hqr : q ∨ r, from or.inl (and.right hpq),\n            and.intro hp hqr)\n          (assume hpr : (p ∧ r),\n            have hp : p, from and.left hpr,\n            have hqr : q ∨ r, from or.inr (and.right hpr),\n            and.intro hp hqr)))\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\n  iff.intro\n    (assume h : p ∨ (q ∧ r),\n      (show (p ∨ q) ∧ (p ∨ r), from\n        or.elim h\n          (assume hp : p,\n            and.intro (or.inl hp) (or.inl hp))\n          (assume hqr : q ∧ r,\n            and.elim hqr\n              (assume hq : q, assume hr : r,\n                and.intro (or.inr hq) (or.inr hr)))))\n    (assume h : (p ∨ q) ∧ (p ∨ r), \n      (show (p ∨ (q ∧ r)), from\n        and.elim h\n          (assume pq : p ∨ q, assume pr : p ∨ r,\n            or.elim pq\n              (assume hp : p, or.inl hp)\n              (assume hq : q, \n                or.elim pr\n                  -- I feel like this part could possibly be simpler,\n                  -- but then, this branch of or.elim doesn't\n                  -- guarantee ¬p (it's not exclusive or)\n                  (assume hp2 : p, or.inl hp2)\n                  (assume hr : r, or.inr (and.intro hq hr))))))\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) :=\n  iff.intro\n    (assume h : p → (q → r),\n      assume hpq : p ∧ q,\n        have hp : p, from and.left hpq,\n        have hq : q, from and.right hpq,\n        (h hp) hq)\n    (assume h : p ∧ q → r,\n      assume hp : p,\n      assume hq : q,\n      have pq : p ∧ q, from and.intro hp hq,\n      h pq)\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\n  iff.intro\n    (assume h : (p ∨ q) → r,\n      and.intro\n        (assume hp : p, h (or.inl hp))\n        (assume hq : q, h (or.inr hq)))\n    (assume h : (p → r) ∧ (q → r),\n      and.elim h\n        (assume pr : p → r, assume qr : q → r,\n          assume pq : p ∨ q, or.elim pq pr qr))\n\n-- Below is just a special case of the above theorem but I'm not sure\n-- how to express it:\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  iff.intro\n    (assume h : ¬(p ∨ q),\n      and.intro\n        (assume hp : p, h (or.inl hp))\n        (assume hq : q, h (or.inr hq)))\n    (assume h : ¬p ∧ ¬q,\n      and.elim h\n        (assume np : ¬p, assume nq : ¬q,\n          not.intro\n            (assume pq : p ∨ q, or.elim pq np nq)))\n\ntheorem dm1 : ¬p ∨ ¬q → ¬(p ∧ q) :=\n  assume npq : ¬p ∨ ¬q,\n    or.elim npq\n      (assume np : ¬p,\n        not.intro\n          (assume pq : p ∧ q, np (and.elim_left pq)))\n      (assume nq : ¬q,\n        not.intro\n          (assume pq : p ∧ q, nq (and.elim_right pq)))\n\nexample : ¬(p ∧ ¬ p) :=\n  assume pnp : p ∧ ¬p,\n    and.elim pnp (assume hp : p, assume hnp : ¬p, hnp hp)\n\nexample : p ∧ ¬q → ¬(p → q) :=\n  assume pnq : p ∧ ¬q,\n    not.intro (assume pq : p → q,\n      and.elim pnq (assume hp : p, assume hnq : ¬q,\n        hnq (pq hp)))\n\nexample : ¬p → (p → q) :=\n  assume hnp : ¬p, assume hp : p, absurd hp hnp\n\nexample : (¬p ∨ q) → (p → q) :=\n  assume npq : ¬p ∨ q, assume hp : p,\n    or.elim npq\n      (assume hnp : ¬p, absurd hp hnp)\n      (assume hq : q, hq)\n\nexample : p ∨ false ↔ p :=\n  iff.intro\n    (assume pf : p ∨ false,\n      or.elim pf (assume hp : p, hp) false.elim)\n    (assume hp : p, or.inl hp)\n\nexample : p ∧ false ↔ false :=\n  iff.intro (assume pf : p ∧ false, and.right pf) false.elim\n\ntheorem thm1 : (p → ¬p) → ¬p :=\n  assume h : p → ¬p,\n  assume h2 : p,\n  (h h2) h2\n\n-- \"If (p → ¬p), then (p → (p → false)), so in particular (p →\n-- false). Put another way, (p → ¬p) → ¬p is an intuitionistically\n-- valid theorem. From this, you have ¬p and ¬p → p from the\n-- assumptions, so p, so false.\"\n\nexample : ¬(p ↔ ¬p) :=\n  not.intro\n    (assume impl : p ↔ ¬p,\n     have hnp : ¬p, from thm1 p (iff.mp impl),\n     have hp : p, from (iff.mpr impl) hnp,\n     hnp hp)\n\ntheorem cp : (p → q) → (¬q → ¬p) :=\n  assume pq : p → q,\n  assume nq : ¬q,\n  show p → false, from\n    assume hp : p, nq (pq hp)\n\n-- these require classical reasoning\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n  assume rps : p → r ∨ s,\n  by_cases\n    (assume hp : p,\n      or.elim (rps hp)\n        (assume hr : r, or.inl (assume hp2 : p, hr))\n        (assume hs : s, or.inr (assume hp2 : p, hs)))\n    (assume hnp : ¬p,\n      or.inl (assume hp : p, absurd hp hnp))\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n  assume npq : ¬(p ∧ q),\n  by_cases\n    (assume hp : p,\n      by_cases\n        (assume hq : q,\n          have pq : p ∧ q, from and.intro hp hq,\n          absurd pq npq)\n        (assume hnq : ¬q, or.inr hnq))\n    (assume hnp : ¬p, or.inl hnp)\n  \nexample : ¬(p → q) → p ∧ ¬q :=\n  assume npq : ¬(p → q),\n  by_cases\n    (assume hq : q, absurd (assume p, hq) npq)\n    (assume hnq : ¬q,\n      by_cases\n        (assume hp : p, and.intro hp hnq)\n        (assume hnp : ¬p,\n          have pq : p → q, from (assume hp : p, absurd hp hnp),\n          absurd pq npq))\n\nexample : (p → q) → (¬p ∨ q) :=\n  assume pq : p → q, by_cases\n    (assume hp : p, or.inr (pq hp))\n    (assume hnp : ¬p, or.inl hnp)\n\ntheorem dne {p : Prop} (h : ¬¬p) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : ¬p, absurd hnp h)\n\n-- How is this so simple?\ntheorem dne2 {p : Prop} (hp : p) : ¬¬p :=\n  (assume hnp : ¬p, hnp hp)\n\ntheorem cp2 : (¬q → ¬p) → (p → q) :=\n  assume npnq : ¬q → ¬p,\n  have pq2 : ¬¬p → ¬¬q, from cp (¬q) (¬p) npnq,\n  assume hp : p, dne (pq2 (dne2 hp))\n\n-- Is this cheating?\nexample : p ∨ ¬p := em p\n\nexample : (((p → q) → p) → p) :=\n  assume pqp : ((p → q) → p),\n  by_cases\n    (assume hq : q,\n      have pq : p → q, from (assume p, hq), pqp pq)\n    (assume hnq : ¬q,\n      by_cases\n        (assume hp : p, hp)\n        (assume hnp : ¬p,\n          have pq : p → q, from cp2 p q (assume hnq : ¬q, hnp),\n          have hp : p, from pqp pq,\n          absurd hp hnp))\n  -- Is there a simpler way to show the above?  Maybe proof by\n  -- contradiction or something?\n", "meta": {"author": "Hodapp87", "repo": "leanprover_scratch", "sha": "de347c54ee56c2a05804f80d5f28e98070507236", "save_path": "github-repos/lean/Hodapp87-leanprover_scratch", "path": "github-repos/lean/Hodapp87-leanprover_scratch/leanprover_scratch-de347c54ee56c2a05804f80d5f28e98070507236/tpl-sec3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7744764852539185}}
{"text": "------------------------------------------------------------------------\n-- Las relaciones de equivalencia son isomorfas a las particiones\n------------------------------------------------------------------------\n\nimport tactic\n\n-- =====================================================================\n-- § Visión general                                                   --\n-- =====================================================================\n\n-- En esta teoría, definiremos las particiones de `A` y construiremos\n-- algunas interfaz (es decir, probaremos algunas\n-- proposiciones). Definiremos las clases de equivalencia y haremos lo\n-- mismo. Finalmente, demostraremos que existe una biyección entre\n-- relaciones de equivalencia en `A` y particiones de` A`.\n--\n-- En Lean se tiene las siguiente definiciones:\n--    reflexive R := ∀ (x : A), R x x\n--    symmetric R := ∀ ⦃x y : A⦄, R x y → R y x\n--    transitive R := ∀ ⦃x y z : A⦄, R x y → R y z → R x z\n--    equivalence R := reflexive R ∧ symmetric R ∧ transitive R\n-- donde `A` un tipo y `R: A → A → Prop` es una relación binaria en `A`.\n\n-- =====================================================================\n-- § Particiones                                                      --\n-- =====================================================================\n\n-- =====================================================================\n-- §§ Definición de una partición                                     --\n-- =====================================================================\n\n-- Sea `A` un tipo. Una partición en `A` es una estructura con los\n-- siguientes  componentes:\n-- 1) Un conjunto de subconjuntos de A. Dichos subconjuntos se llaman\n--   los bloques de la partición.\n-- 2) Una hipótesis (es decir, una prueba) de que los bloques no están vacíos.\n-- 3) Una hipótesis de que cada término de tipo A está en uno de los bloques.\n-- 4) Una hipótesis de que dos bloques con intersección no vacía son iguales.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Definir la estructura `particion` tal que `particion A`\n-- es el tipo de las particiones sobre `A`.\n-- ---------------------------------------------------------------------\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : ∀ X ∈ Bloques, (X : set A).nonempty)\n(Hrecubren  : ∀ a, ∃ X ∈ Bloques, a ∈ X)\n(Hdisjuntos : ∀ X Y ∈ Bloques, (X ∩ Y : set A).nonempty → X = Y)\n\n-- Notaciones\n-- + `P : particion A` expresa que `P` es una partición de `A`.\n-- + `Bloques P` es el conjunto de los bloque de P.\n-- + `Hno_vacios P` prueba que los bloques de `P` son no vacíos.\n-- + `Hrecubren P` prueba que los bloque de `P` recubren a `A`.\n-- + `Hdisjuntos p` prueba que los bloques de `P` son disjuntos entre sí\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Abrir el espacio de nombre `particion`.\n-- ---------------------------------------------------------------------\n\nnamespace particion\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Definir las siguientes variables\n-- + A para un tipo\n-- + P para las particiones sobre A\n-- + X e Y para subconjuntos de A.\n-- ---------------------------------------------------------------------\n\nvariable  {A : Type}\nvariable  {P : particion A}\nvariables {X Y : set A}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que si dos bloques de una partición tienen un\n-- elemento en común, entonces son iguales.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nbegin\n  apply Hdisjuntos P,\n  { exact hX, },\n  { exact hY, },\n  { rw set.nonempty_def,\n    use a,\n    split,\n    { exact haX, },\n    { exact haY, }},\nend\n\n-- 2ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nbegin\n  apply Hdisjuntos P,\n  { exact hX, },\n  { exact hY, },\n  { use a,\n    exact ⟨haX, haY⟩, },\nend\n\n-- 3ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nbegin\n  apply Hdisjuntos P,\n  { exact hX, },\n  { exact hY, },\n  { exact ⟨a, haX, haY⟩, },\nend\n\n-- 4ª demostración\nlemma iguales_si_comun\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nHdisjuntos P X Y hX hY ⟨a, haX, haY⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que si dos bloques de una partición tienen\n-- elementos comunes, entonces los elementos de uno también pertenecen\n-- al otro.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a b : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  (hbX : b ∈ X)\n  : b ∈ Y :=\nbegin\n  convert hbX,\n  apply iguales_si_comun hY hX haY,\n  exact haX,\nend\n\n-- 2ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a b : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  (hbX : b ∈ X)\n  : b ∈ Y :=\nbegin\n  have hXY : X = Y := iguales_si_comun hX hY haX haY,\n  rw ← hXY,\n  exact hbX,\nend\n\n-- 3ª demostración\nlemma pertenece_si_pertenece\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a b : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  (hbX : b ∈ X)\n  : b ∈ Y :=\nbegin\n  convert hbX,\n  exact iguales_si_comun hY hX haY haX,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que si P es una partición sobre A, entonces\n-- para cada elemento a de A hay algún bloque X de P tal que a ∈ X.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (a : A)\n  : ∃ X, X ∈ Bloques P ∧ a ∈ X :=\nbegin\n  rcases Hrecubren P a with ⟨X, hX, haX⟩,\n  use X,\n  exact ⟨hX, haX⟩,\nend\n\n-- 2ª demostración\nexample\n  (a : A)\n  : ∃ X, X ∈ Bloques P ∧ a ∈ X :=\nbegin\n  rcases Hrecubren P a with ⟨X, hX, haX⟩,\n  exact ⟨X, hX, haX⟩,\nend\n\n-- 3ª demostración\nlemma pertenece_bloque\n  (a : A)\n  : ∃ X : set A, X ∈ Bloques P ∧ a ∈ X :=\nbegin\n  obtain ⟨X, hX, haX⟩ := Hrecubren P a,\n  use X,\n  exact ⟨hX, haX⟩,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Cerrar el espacio de nombres `particion`.\n-- ---------------------------------------------------------------------\n\nend particion\n\n-- =====================================================================\n-- § Relaciones de equivalencia                                      --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 8. Abrir la sección `clases_de_equivalencia`.\n-- ---------------------------------------------------------------------\n\nsection clases_de_equivalencia\n\n-- =====================================================================\n-- §§ Definición de relaciones de equivalencia                        --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 9. Definir las siguientes variables\n-- + A para un tipo\n-- + R para las relaciones binarias en A.\n-- ---------------------------------------------------------------------\n\nvariable {A : Type}\nvariable (R : A → A → Prop)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 10. Definir la función\n--    clase : A → set A\n-- tal que (clase a) es el conjunto de los elementos relacionados con a\n-- (mediante R). Se dice que `clase a` es la clase de a.\n-- ---------------------------------------------------------------------\n\ndef clase (a : A) :=\n  {b : A | R b a}\n\n-- =====================================================================\n-- § Lemas elementales de las clases                   --\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 11. Demostrar que\n--    b ∈ clase R a ↔ R b a\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  {a b : A}\n  : b ∈ clase R a ↔ R b a :=\nbegin\n  unfold clase,\n  dsimp,\n  refl,\nend\n\n-- 2ª demostración\nlemma pertenece_clase_syss\n  {a b : A}\n  : b ∈ clase R a ↔ R b a :=\nby refl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 12. Definir como hipótesis hR el que R es una relación de\n-- equivalencia y usarla en el resto de la sección.\n-- ---------------------------------------------------------------------\n\nvariables {R} (hR : equivalence R)\ninclude hR\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 13. Demostrar que\n--    a ∈ clase R a\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (a : A)\n  : a ∈ clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  suffices h : reflexive R,\n  { exact h a, },\n  { rcases hR with ⟨h2, -, -⟩,\n    exact h2, },\nend\n\n-- 2ª demostración\nexample\n  (a : A)\n  : a ∈ 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ª demostración\nexample\n  (a : A)\n  : a ∈ clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  rcases hR with ⟨hrefl, -, -⟩,\n  exact hrefl a,\nend\n\n-- 4ª demostración\nexample\n  (a : A)\n  : a ∈ clase R a :=\nbegin\n  obtain ⟨hrefl, -, -⟩ := hR,\n  rw pertenece_clase_syss,\n  apply hrefl,\nend\n\n-- 5ª demostración\nexample\n  (a : A)\n  : a ∈ clase R a :=\nbegin\n  rw pertenece_clase_syss,\n  apply hR.1,\nend\n\n-- 6ª demostración\nlemma pertenece_clase_propia\n  (a : A)\n  : a ∈ clase R a :=\n(pertenece_clase_syss R).mpr (hR.1 a)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 14. Demostrar que\n--    a ∈ clase R b → clase R a ⊆ clase R b\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  {a b : A}\n  : a ∈ clase R b → clase R a ⊆ clase R b :=\nbegin\n  intro hab,\n  intros z hza,\n  rw pertenece_clase_syss at hab hza ⊢,\n  obtain ⟨-, -, htrans⟩ := hR,\n  exact htrans hza hab,\nend\n\n-- 2ª demostración\nexample\n  {a b : A}\n  : a ∈ clase R b → clase R a ⊆ clase R b :=\nbegin\n  intros hab z hza,\n  exact hR.2.2 hza hab,\nend\n\n-- 3ª demostración\nlemma subclase_si_pertenece\n  {a b : A}\n  : a ∈ clase R b → clase R a ⊆ clase R b :=\nλ hab z hza, hR.2.2 hza hab\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 15. Demostrar que\n--    a ∈ clase R b → clase R a = clase R b\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  {a b : A}\n  : a ∈ clase R b → 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 ⟨-, hsymm, -⟩,\n    exact hsymm hab }\nend\n\n-- 2ª demostración\nexample\n  {a b : A}\n  : a ∈ clase R b → 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ª demostración\nexample\n  {a b : A}\n  : a ∈ clase R b → 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ª demostración\nlemma clases_iguales_si_pertenece\n  {a b : A}\n  : a ∈ clase R b → clase R a = clase R b :=\nλ hab, set.subset.antisymm\n        (subclase_si_pertenece hR hab)\n        (subclase_si_pertenece hR (hR.2.1 hab))\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 16. Cerrar la sección `clases_de_equivalencia`.\n-- ---------------------------------------------------------------------\n\nend clases_de_equivalencia\n\n-- =====================================================================\n-- § El teorema                                                       --\n-- =====================================================================\n\n-- Sea `A` un tipo. Existe una biyección entre las relaciones de\n-- equivalencia en `A` y particiones de `A`. Lo demostraremos\n-- escribiendo una dfunción en cada dirección y probando que las\n-- funciones son inversas.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 17. Abrir el espacio de nombre `particion`.\n-- ---------------------------------------------------------------------\n\nopen particion\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 18. Definir las variables\n-- + A para tipos y\n-- + R para relaciones binarias en A.\n-- ---------------------------------------------------------------------\n\nvariable {A : Type}\nvariable (R : A → A → Prop)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 19. Definir la función\n--    clases : (A → A → Prop) → set (set A)\n-- tal que (clases R) es el conjunto de las clases de R.\n-- ---------------------------------------------------------------------\n\ndef clases : (A → A → Prop) → set (set A) :=\n  λ R, {B : set A | ∃ x : A, B = clase R x}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 20. Demostrar que si R es una relación de equivalencia,\n-- entonces las clases de R son no vacías.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hR: equivalence R)\n  : ∀ (X : set A), X ∈ clases R → 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 ⟨hrefl, -, -⟩,\n  exact hrefl a,\nend\n\n-- 2ª demostración\nlemma clases_no_vacias\n  (hR: equivalence R)\n  : ∀ (X : set A), X ∈ clases R → X.nonempty :=\nbegin\n  rintros _ ⟨a, rfl⟩,\n  use a,\n  rw pertenece_clase_syss,\n  apply hR.1,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 21. Demostrar que si R es una relación de equivalencia en A,\n-- entonces las clases de R recubren a A; es decir, para cada elemento a\n-- de A existe una clase X de R tal que a ∈ X.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración,\nexample\n  (hR: equivalence R)\n  : ∀ a, ∃ X ∈ clases R, a ∈ X :=\nbegin\n  intro a,\n  use clase R a,\n  split,\n  { unfold clases,\n    dsimp,\n    use a, },\n  { exact pertenece_clase_propia hR a, },\nend\n\n-- 2ª demostración,\nlemma clases_recubren\n  (hR: equivalence R)\n  : ∀ a, ∃ X ∈ clases R, a ∈ X :=\nbegin\n  intro a,\n  use clase R a,\n  split,\n  { use a, },\n  { exact hR.1 a, },\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 22. Demostrar que si R es una relación de equivalencia,\n-- entonces las clases de R son disjuntas; es decir, si dos clases de R\n-- son no disjuntas, entonces son iguales.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hR: equivalence R)\n  : ∀ X Y ∈ clases R, (X ∩ Y : set A).nonempty → X = Y :=\nbegin\n  intros X Y hX hY hXY,\n  unfold clases at hX hY,\n  dsimp at hX hY,\n  cases hX with a ha,\n  cases hY with b hb,\n  rw [ha, hb] at *,\n  rw set.nonempty_def at hXY,\n  cases hXY with c hc,\n  cases hc with hca hcb,\n  apply clases_iguales_si_pertenece hR,\n  apply hR.2.2 _ hcb,\n  apply hR.2.1,\n  exact hca,\nend\n\n-- 2ª demostración\nexample\n  (hR: equivalence R)\n  : ∀ X Y ∈ clases R, (X ∩ Y : set A).nonempty → X = Y :=\nbegin\n  intros X Y hX hY hXY,\n  cases hX with a ha,\n  cases hY with b hb,\n  rw [ha, hb] at *,\n  rw set.nonempty_def at hXY,\n  cases hXY with c hc,\n  cases hc with hca hcb,\n  apply clases_iguales_si_pertenece hR,\n  apply hR.2.2 _ hcb,\n  apply hR.2.1,\n  exact hca,\nend\n\n-- 3ª demostración\nexample\n  (hR: equivalence R)\n  : ∀ X Y ∈ clases R, (X ∩ Y : set A).nonempty → X = Y :=\nbegin\n  rintros X Y ⟨a, rfl⟩ ⟨b, rfl⟩ ⟨c, hca, hcb⟩,\n  apply clases_iguales_si_pertenece hR,\n  apply hR.2.2 _ hcb,\n  apply hR.2.1,\n  exact hca,\nend\n\n-- 4ª demostración\nlemma clases_disjuntas\n  (hR: equivalence R)\n  : ∀ X Y ∈ clases R, (X ∩ Y : set A).nonempty → X = Y :=\nbegin\n  rintros X Y ⟨a, rfl⟩ ⟨b, rfl⟩ ⟨c, hca, hcb⟩,\n  exact clases_iguales_si_pertenece hR (hR.2.2 (hR.2.1 hca) hcb),\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 23. Definir la función\n--    cociente : {R : A → A → Prop // equivalence R} → particion A\n-- tal que (cociente R) es el conjunto cociente  de la relación de\n-- equivalencia R.\n-- ---------------------------------------------------------------------\n\ndef cociente : {R : A → A → Prop // equivalence R} → particion A :=\n  λ R, { Bloques    := {B : set A | ∃ 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\n-- ---------------------------------------------------------------------\n-- Ejercicio 24. Definir P como una variable sobre los conjuntos de\n-- conjuntos de A.\n-- ---------------------------------------------------------------------\n\nvariable (P : set (set A))\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 25. Definir la función\n--    relacion : (particion A) → (A → A → Prop)\n-- tal que (relacion P) es la relación correspondiente a la partición P.\n-- ---------------------------------------------------------------------\n\ndef relacion : (particion A) → (A → A → Prop) :=\n  λ P a b, ∀ X ∈ Bloques P, a ∈ X → b ∈ X\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 26. Demostrar que la relación correspondiente a la\n-- partición P es reflexiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\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ª demostración\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ª demostración\nexample\n  (P : particion A)\n  : reflexive (relacion P) :=\nbegin\n  intros a X hXC haX,\n  exact haX,\nend\n\n-- 4ª demostración\nlemma reflexiva\n  (P : particion A)\n  : reflexive (relacion P) :=\nλ a X hXC haX, haX\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 37. Demostrar que la relación correspondiente a la parición\n-- P es simétrica\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\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 ⟨Y, hY, haY⟩ := Hrecubren P a,\n  specialize hab Y hY haY,\n  exact pertenece_si_pertenece hY hX hab hbX haY,\nend\n\n-- 2ª demostración\nexample\n  (P : particion A)\n  : symmetric (relacion P) :=\nbegin\n  intros a b hab,\n  intros X hX hbX,\n  obtain ⟨Y, hY, haY⟩ := Hrecubren P a,\n  specialize hab Y hY haY,\n  exact pertenece_si_pertenece hY hX hab hbX haY,\nend\n\n-- 3ª demostración\nlemma simetrica\n  (P : particion A)\n  : symmetric (relacion P) :=\nbegin\n  intros a b h X hX hbX,\n  obtain ⟨Y, hY, haY⟩ := Hrecubren P a,\n  specialize h Y hY haY,\n  exact pertenece_si_pertenece hY hX h hbX haY,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 28. Demostrar que la relación correspondiente a la relación P\n-- es transitiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (P : particion A)\n  : transitive (relacion P) :=\nbegin\n  unfold transitive,\n  intros a b c hab hbc,\n  unfold relacion at *,\n  intros X hX haX,\n  apply hbc,\n  { exact hX, },\n  { apply hab,\n    { exact hX, },\n    { exact haX, }},\nend\n\n-- 2ª demostración\nexample\n  (P : particion A)\n  : transitive (relacion P) :=\nbegin\n  intros a b c hab hbc,\n  intros X hX haX,\n  apply hbc X hX,\n  apply hab X hX,\n  exact haX,\nend\n\n-- 3ª demostración\nexample\n  (P : particion A)\n  : transitive (relacion P) :=\nbegin\n  intros a b c hab hbc X hX haX,\n  exact hbc X hX (hab X hX haX),\nend\n\n-- 4ª demostración\nlemma transitiva\n  (P : particion A)\n  : transitive (relacion P) :=\nλ a b c hab hbc X hX haX, hbc X hX (hab X hX haX)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 29. Definir la función\n--    relacionP : particion A → {R : A → A → Prop // equivalence R}\n-- ---------------------------------------------------------------------\n\ndef relacionP : particion A → {R : A → A → Prop // equivalence R} :=\n  λ P, ⟨λ a b, ∀ X ∈ Bloques P, a ∈ X → b ∈ X,\n        ⟨reflexiva P, simetrica P, transitiva P⟩⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 30. Demostrar que relacionP es inversa por la izquierda de\n-- cociente.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  function.left_inverse relacionP (@cociente A) :=\nbegin\n  unfold function.left_inverse,\n  intro S,\n  cases S with R hR,\n  unfold relacionP cociente relacion,\n  simp,\n  ext a b,\n  split,\n  { intros hab,\n    apply hR.2.1,\n    unfold clase at hab,\n    dsimp at hab,\n    apply hab,\n    apply hR.1, },\n  { intros hab c hac,\n    unfold clase at *,\n    dsimp at *,\n    apply hR.2.2 (hR.2.1 hab) hac, },\nend\n\n-- 2ª demostración\nexample :\n  function.left_inverse relacionP (@cociente A) :=\nbegin\n  rintro ⟨R, hR⟩,\n  simp [relacionP, cociente],\n  ext a b,\n  split,\n  { intros hab,\n    apply hR.2.1,\n    apply hab,\n    apply hR.1, },\n  { intros hab c hac,\n    apply hR.2.2 (hR.2.1 hab) hac, },\nend\n\n-- 3ª demostración\nexample :\n  function.left_inverse relacionP (@cociente A) :=\nbegin\n  rintro ⟨R, hR⟩,\n  simp [relacionP, cociente],\n  ext a b,\n  split,\n  { intros hab,\n    exact hR.2.1 (hab a (hR.1 a)), },\n  { intros hab c hac,\n    exact hR.2.2 (hR.2.1 hab) hac, },\nend\n\n-- 4ª demostración\nexample :\n  function.left_inverse relacionP (@cociente A) :=\nbegin\n  rintro ⟨R, hR⟩,\n  simp [relacionP, cociente],\n  ext a b,\n  split,\n  { exact λ hab, hR.2.1 (hab a (hR.1 a)), },\n  { exact λ hab c hac, hR.2.2 (hR.2.1 hab) hac, },\nend\n\n-- 5ª demostración\nexample :\n  function.left_inverse relacionP (@cociente A) :=\nbegin\n  rintro ⟨R, hR⟩,\n  simp [relacionP, cociente],\n  ext a b,\n  exact ⟨λ hab, hR.2.1 (hab a (hR.1 a)),\n         λ hab c hac, hR.2.2 (hR.2.1 hab) hac⟩,\nend\n\n-- 6ª demostración\nlemma inversa_izq :\n  function.left_inverse relacionP (@cociente A) :=\nbegin\n  rintro ⟨R, hR⟩,\n  suffices : (λ (a b : A), ∀ (c : A), a ∈ clase R c → b ∈ clase R c) = R,\n  { simpa [relacionP, cociente], },\n  { ext a b,\n    show (∀ (c : A), a ∈ clase R c → b ∈ clase R c) ↔ R a b,\n    split,\n    { intros hab,\n      apply hR.2.1,\n      unfold clase at hab,\n      dsimp at hab,\n      apply hab,\n      apply hR.1, },\n    { intros hab c hac,\n      unfold clase at *,\n      dsimp at *,\n      apply hR.2.2 (hR.2.1 hab) hac, }},\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 31. Demostrar que la función cociente que aplica relaciones\n-- de equivalencia en la partición del conjunto cociente es inyectiva.\n-- ---------------------------------------------------------------------\n\nlemma cociente_es_inyectiva :\n  function.injective (@cociente A) :=\nfunction.left_inverse.injective inversa_izq\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 32. Demostrar que relacionP es inversa por la derecha de\n-- cociente.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  function.right_inverse relacionP (@cociente A) :=\nbegin\n  unfold function.right_inverse,\n  unfold function.left_inverse,\n  intro P,\n  ext X,\n  simp [cociente],\n  split,\n  { intro h,\n    cases h with a ha,\n    rw ha,\n    rcases Hrecubren P a with ⟨X, hX, haX⟩,\n    convert hX,\n    ext b,\n    rw pertenece_clase_syss,\n    split,\n    { intro hba,\n      rcases Hrecubren P b with ⟨Y, hY, hbY⟩,\n      specialize hba Y hY hbY,\n      convert hbY,\n      exact iguales_si_comun hX hY haX hba, },\n    { intros hbX Y hY hbY,\n      apply pertenece_si_pertenece hX hY hbX hbY haX, }},\n  { intro hX,\n    rcases Hno_vacios P X hX with ⟨a, ha⟩,\n    use a,\n    ext b,\n    split,\n    { intro hbX,\n      rw pertenece_clase_syss,\n      intros Y hY hbY,\n      exact pertenece_si_pertenece hX hY hbX hbY ha, },\n    { rw pertenece_clase_syss,\n      intro hba,\n      rcases Hrecubren P b with ⟨Y, hY, hbY⟩,\n      specialize hba Y hY hbY,\n      exact pertenece_si_pertenece hY hX hba ha hbY, }}\nend\n\n-- 2ª demostración\nlemma inversa_dcha :\n  function.right_inverse relacionP (@cociente A) :=\nbegin\n  intro P,\n  ext X,\n  show (∃ (a : A), X = clase _ a) ↔ X ∈ Bloques P,\n  split,\n  { rintro ⟨a, rfl⟩,\n    obtain ⟨X, hX, haX⟩ := Hrecubren P a,\n    convert hX,\n    ext b,\n    rw pertenece_clase_syss,\n    split,\n    { intro hba,\n      obtain ⟨Y, hY, hbY⟩ := Hrecubren P b,\n      specialize hba Y hY hbY,\n      convert hbY,\n      exact iguales_si_comun hX hY haX hba, },\n    { intros hbX Y hY hbY,\n      apply pertenece_si_pertenece hX hY hbX hbY haX, }},\n  { intro hX,\n    rcases Hno_vacios P X hX with ⟨a, ha⟩,\n    use a,\n    ext b,\n    split,\n    { intro hbX,\n      rw pertenece_clase_syss,\n      intros Y hY hbY,\n      exact pertenece_si_pertenece hX hY hbX hbY ha, },\n    { rw pertenece_clase_syss,\n      intro hba,\n      obtain ⟨Y, hY, hbY⟩ := Hrecubren P b,\n      specialize hba Y hY hbY,\n      exact pertenece_si_pertenece hY hX hba ha hbY, }}\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 33. Demostrar que la función cociente que aplica relaciones\n-- de equivalencia en la partición del conjunto cociente es suprayectiva.\n-- ---------------------------------------------------------------------\n\nlemma cociente_es_suprayectiva :\n  function.surjective (@cociente A) :=\nfunction.right_inverse.surjective inversa_dcha\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 34. Demostrar que la función cociente que aplica relaciones\n-- de equivalencia en la partición del conjunto cociente es biyectiva.\n-- ---------------------------------------------------------------------\n\nlemma cociente_es_biyectiva :\n  function.bijective (@cociente A) :=\n⟨cociente_es_inyectiva, cociente_es_suprayectiva⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 35. Demostrar que los tipos de las relaciones de equivalencia\n-- sobre A y el de las particiones de A son isomorfos.\n-- ---------------------------------------------------------------------\n\ntheorem equivalencia_particiones\n  (A : Type)\n  : {R : A → A → Prop // equivalence R} ≃ particion A :=\n{ to_fun    := cociente,\n  inv_fun   := relacionP,\n  left_inv  := inversa_izq,\n  right_inv := inversa_dcha, }\n\n-- =====================================================================\n-- § Referencias                                                      --\n-- =====================================================================\n\n-- + Kevin Buzzard. \"Formalising mathematics : workshop 1 — logic, sets,\n--   functions, relations\" https://bit.ly/3kJo231\n-- + Kevin Buzzard. formalising-mathematics: Part_D_relations.lean\n--   https://bit.ly/3AQWY7o\n-- + Kevin Buzzard. formalising-mathematics: Part_D_relations_solutions.lean\n--   https://bit.ly/2WpcfgY\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/4_Relaciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7744764846166058}}
{"text": "/-\nCopyright (c) 2019 Jesse Michael Han. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor(s): Jesse Michael Han \n\nA simplified version of the coffee can problem, from David Gries' The Science of Programming\n\nGiven a coffee can filled with finitely many black and white beans, and an infinite supply of white beans, carry out the following procedure: as long as there is more than one bean in the can,\n\n - Draw two beans.\n - If their colors are different, discard the white one and return the black one to the can.\n - If their colors are the same, discard both of them and add a white bean to the can.\n\nProve that if the number of black beans in the can is odd, then the process always ends with a black bean, and that if the number of black beans in the can is even, then the process always ends with a white bean.\n-/\n\nimport tactic\nimport data.nat.parity\n\n@[derive decidable_eq, derive has_reflect]\ninductive beans : Type\n| white : beans\n| black : beans\n\ninstance : has_repr beans :=\n{ repr := λ b, beans.cases_on b \"white\" \"black\" }\n\nopen beans\n\n@[simp]def count_black : list beans → ℕ\n| [] := 0\n| (white::xs) := count_black xs\n| (black::xs) := count_black xs + 1\n\n@[simp]def count_white : list beans → ℕ\n| [] := 0\n| (white::xs) := count_white xs + 1\n| (black::xs) := count_white xs\n\n@[simp]lemma count_eq_length (xs : list beans) : count_black xs + count_white xs = xs.length :=\nbegin\n  induction xs with x_hd x_tl ih,\n    { refl },\n    { cases x_hd; simp [ih.symm] }\nend\n\ndef coffee : list beans → list beans\n| [] := []\n| [x] := [x]\n| (black::white::xs) := coffee (black::xs)\n| (white::black::xs) := coffee (black::xs)\n| (black::black::xs) := coffee (white::xs)\n| (white::white::xs) := coffee (white::xs)\n\n@[simp]lemma coffee_singleton {x : beans} : coffee [x] = [x] :=\nbeans.cases_on x rfl rfl\n\ndef some_beans : list beans := [black, white, black, black, white, black, white, black, black, white, black]\n\n#eval coffee some_beans\n-- [black]\n\nsection metaprogramming\n\nmeta instance : has_to_format beans :=\n{ to_format := λ b, beans.cases_on b (format.of_string \"white\") (format.of_string \"black\") }\n\nmeta def coffee_eval : list beans → tactic unit\n| [] := tactic.trace \"[]\"\n| [x] := tactic.trace format!\"final state: [{x}]\"\n| arg@(black::white::xs) := \n  do  tactic.trace format!\"current state: {arg}\",\n      tactic.trace \"got black + white, discarding white\",\n      coffee_eval (black::xs)\n| arg@(white::black::xs) :=\n  do  tactic.trace format!\"current state: {arg}\",\n      tactic.trace \"got white + black, discarding white\",\n      coffee_eval (black::xs)\n| arg@(black::black::xs) :=\n  do  tactic.trace format!\"current state: {arg}\",\n      tactic.trace \"got black + black, discarding both and adding white\",\n      coffee_eval (white::xs)\n| arg@(white::white::xs) :=\n  do tactic.trace format!\"current state: {arg}\",\n     tactic.trace \"got white + white, discarding white\",\n     coffee_eval (white::xs)\n\n@[reducible]meta def my_parser := state_t string tactic\n\nmeta def beans.of_string : my_parser beans :=\n⟨ λ ⟨cs⟩, match cs with\n         | [] := tactic.failed\n         | (x::xs) := if x = '0' then return (white, ⟨xs⟩) else\n                      if x = '1' then return (black, ⟨xs⟩) else\n                      tactic.failed\n         end ⟩\n\nmeta def repeat {α} : my_parser α → my_parser (list α) :=\nλ p, (list.cons) <$> p <*> (repeat p <|> return [])\n\nmeta def my_parser.run {α} [has_to_tactic_format α] (p : my_parser α) (arg : string) : tactic α :=\ndo bs <- prod.fst <$> state_t.run p arg,\n   tactic.trace bs,\n   return bs\n\nmeta def parse_beans (arg : string) : tactic unit :=\ndo bs <- my_parser.run (repeat beans.of_string) arg,\n   tactic.exact `(bs).to_expr\n\nend metaprogramming\n\nsection test\n\ndef some_more_beans : list beans := by {parse_beans \"10110001011\"}\n\nrun_cmd coffee_eval some_more_beans\n\nend test\n\n@[simp]lemma coffee_white {x} {xs} : coffee (white::x::xs) = coffee (x::xs) :=\nbegin\n  cases x,\n    { rw coffee },\n    { simp [coffee] },\nend\n\nlemma coffee_black_white {x} {xs} : coffee (x::xs) = [black] ∨ coffee (x::xs) = [white] :=\nbegin\n  induction xs with y xs ih generalizing x,\n    { cases x; simp },\n    { cases x; cases y; simp [*,coffee] }\nend\n\nopen nat\n\nlemma coffee_parity_aux (xs : list beans) (k : ℕ) (H_k : k = xs.length) : even (count_black xs) ↔ even (count_black (coffee xs)) :=\nbegin\n  revert xs H_k, apply nat.strong_induction_on k, clear k,\n  intros n IH xs Hn,\n  cases xs with x xs,\n    { simp [coffee] },\n    { cases xs with y xs,\n      { simp [coffee] },\n      { cases x; cases y,\n          { simp [coffee] with parity_simps,\n            rw ← IH (xs.length + 1) (by norm_num*),\n            { simp },\n            { refl }},\n          { simp [coffee], rw ← IH (xs.length + 1) (by norm_num*),\n            { simp },\n            { refl }},\n          { simp [coffee], rw ← IH (xs.length + 1) (by norm_num*),\n            { simp },\n            { refl }},\n          { simp [coffee] with parity_simps,\n            rw ← IH (xs.length + 1) (by norm_num*),\n            { simp },\n            { refl }}}}\nend\n\nlemma coffee_parity {xs : list beans} : even (count_black xs) ↔ even (count_black (coffee xs)) :=\ncoffee_parity_aux xs xs.length rfl\n\ntheorem ends_black_of_count_black_odd {x} {xs : list beans} (H_odd : ¬ (even $ count_black $ x::xs)) : coffee (x::xs) = [black] :=\nby {have := @coffee_parity (x::xs), have := @coffee_black_white x xs, finish}\n\ntheorem ends_white_of_count_black_even {x} {xs : list beans} (H_even : even $ count_black $ x::xs) : coffee (x::xs) = [white] :=\nby {have := @coffee_parity (x::xs), have := @coffee_black_white x xs, finish}\n", "meta": {"author": "jesse-michael-han", "repo": "lean-coffee-can", "sha": "86929b4909aa602c867bc5f7fc130c5b7cd84076", "save_path": "github-repos/lean/jesse-michael-han-lean-coffee-can", "path": "github-repos/lean/jesse-michael-han-lean-coffee-can/lean-coffee-can-86929b4909aa602c867bc5f7fc130c5b7cd84076/src/coffee.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488296, "lm_q2_score": 0.8791467754256018, "lm_q1q2_score": 0.774349908157651}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que los primos mayores que 2 son impares.\n-- ----------------------------------------------------------------------\n\nimport data.nat.prime data.nat.parity tactic\n\nopen set nat\n\nexample : { n | prime n } ∩ { n | n > 2} ⊆ { n | ¬ even n } :=\nbegin\n  intro n,\n  simp,\n  intro nprime,\n  cases prime.eq_two_or_odd nprime with h h,\n  { rw h,\n    intro,\n    linarith },\n  { rw even_iff,\n    rw h,\n    norm_num },\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ {n : ℕ | n.prime} ∩ {n : ℕ | n > 2} ⊆ {n : ℕ | ¬n.even}\n  >> intro n,\nn : ℕ\n⊢ n ∈ {n : ℕ | n.prime} ∩ {n : ℕ | n > 2} → n ∈ {n : ℕ | ¬n.even}\n  >> simp,\n⊢ n.prime → 2 < n → ¬n.even\n  >> intro nprime,\nnprime : n.prime\n⊢ 2 < n → ¬n.even\n  >> cases prime.eq_two_or_odd nprime with h h,\n| h : n = 2\n| ⊢ 2 < n → ¬n.even\n|   >> { rw h,\n| ⊢ 2 < 2 → ¬2.even\n|   >>   intro,\n| a : 2 < 2\n| ⊢ ¬2.even\n|   >>   linarith },\nh : n % 2 = 1\n⊢ 2 < n → ¬n.even\n  >> { rw even_iff,\n⊢ 2 < n → ¬n % 2 = 0\n  >>   rw h,\n⊢ 2 < n → ¬1 = 0\n  >>   norm_num },\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + prime.eq_two_or_odd : p.prime → p = 2 ∨ p % 2 = 1\n-- + even_iff : even n ↔ n % 2 = 0\n\nvariables (n p : ℕ)\n-- #check @prime.eq_two_or_odd p\n-- #check @even_iff 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/Primos_mayores_que_dos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7742461986595993}}
{"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 ↔ ∀ x : X, x ∈ A ↔ x ∈ 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 ↔ ∀ x : X, x ∈ A ↔ x ∈ 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`⊢\t∀ (x : X), x ∈ B ↔ x ∈ A ∪ B` then `rw mem_union_iff` won't work!\nIt's the `∀` 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 ⊆ B ↔ B = A ∪ B := \nbegin\n  rw subset_iff,\n  split,\n  intro h,\n  rw ext_iff,\n  simp_rw mem_union_iff,\n  intro j,\n  specialize h j,\n  tauto!,\n\n  intro h,\n  intro k,\n  intro b,\n  rw h,\n  left,\n  exact b,\n\nend\n\n--begin hide\n-- theorem subset_iff_union_eq' (A : set X) (B : set X) : A ⊆ B ↔ B = A ∪ 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\n\n\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  --}", "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_level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7742461930814337}}
{"text": "import data.real.basic\n\n/-\nOne of the earliest kind of proofs one encounters while learning mathematics is proving by\na calculation. It may not sound like a proof, but this is actually using lemmas expressing\nproperties of operations on numbers. It also uses the fundamental property of equality: if two\nmathematical objects A and B are equal then, in any statement involving A, one can replace A\nby B. This operation is called rewriting, and the Lean \"tactic\" for this is `rw`.\n\nIn the following exercises, we will use the following two lemmas:\n  mul_assoc a b c : a * b * c = a * (b * c)\n  mul_comm a b : a*b = b*a\n\nHence the command\n  rw mul_assoc a b c,\nwill replace a*b*c by a*(b*c) in the current goal.\n\nIn order to replace backward, we use\n  rw ← mul_assoc a b c,\nreplacing a*(b*c) by a*b*c in the current goal.\n\nOf course we don't want to constantly invoke those lemmas, and we will eventually introduce\nmore powerful solutions.\n-/\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 0001\nexample (a b c : ℝ) : (c * b) * a = b * (a * c) :=\nbegin\n  rw mul_comm c,\n  rw mul_assoc,\n  rw mul_comm c,\nend\n\n-- 0002\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ←mul_assoc,\n  rw mul_comm a,\n  rw mul_assoc,\nend\n\n/-\nNow let's return to the preceding example to experiment with what happens\nif we don't give arguments to mul_assoc or mul_comm.\nFor instance, you can start the next proof with\n  rw ← mul_assoc,\nTry to figure out what happens.\n-/\n\n-- 0003\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ←mul_assoc,\n  rw mul_comm a,\n  rw mul_assoc,\nend\n\n/-\nWe can also perform rewriting in an assumption of the local context, using for instance\n  rw mul_comm a b at hyp,\nin order to replace a*b by b*a in assumption hyp.\n\nThe next example will use a third lemma:\n  two_mul a : 2*a = a + a\n\nAlso we use the `exact` tactic, which allows to provide a direct proof term.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a*d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp, -- Our assumption hyp is now exactly what we have to prove\nend\n\n/-\nAnd the next one can use:\n  sub_self x : x - x = 0\n-/\n\n-- 0004\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  rw mul_comm at hyp,\n  subst hyp',\n  rwa sub_self at hyp,\nend\n\n/-\nWhat is written in the two preceding example is very far away from what we would write on\npaper. Let's now see how to get a more natural layout.\nInside each pair of curly braces below, the goal is to prove equality with the preceding line.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b : by { rw hyp }\n  ... = d*a + a*d  : by { rw hyp' }\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\n/-\nLet's note there is no comma at the end of each line of calculation. `calc` is really one\ncommand, and the comma comes only after it's fully done.\n\nFrom a practical point of view, when writing such a proof, it is convenient to:\n* pause the tactic state view update in VScode by clicking the Pause icon button\n  in the top right corner of the Lean Goal buffer\n* write the full calculation, ending each line with \": by {}\"\n* resume tactic state update by clicking the Play icon button and fill in proofs between\n  curly braces.\n\nLet's return to the other example using this method.\n-/\n\n-- 0005\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  calc c = b*a -d : hyp\n  ... = a*b - d   : by rw mul_comm\n  ... = d - d     : by rw ←hyp'\n  ... = 0         : sub_self _,\nend\n\n/-\nThe preceding proofs have exhausted our supply of \"mul_comm\" patience. Now it's time\nto get the computer to work harder. The `ring` tactic will prove any goal that follows by\napplying only the axioms of commutative (semi-)rings, in particular commutativity and\nassociativity of addition and multiplication, as well as distributivity.\n\nWe also note that curly braces are not necessary when we write a single tactic proof, so\nlet's get rid of them.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b   : by rw hyp\n     ... = d*a + a*d : by rw hyp'\n     ... = 2*a*d     : by ring,\nend\n\n/-\nOf course we can use `ring` outside of `calc`. Let's do the next one in one line.\n-/\n\n-- 0006\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) := by ring\n\n/-\nThis is too much fun. Let's do it again.\n-/\n\n-- 0007\nexample (a b : ℝ) : (a + b) + a = 2*a + b := by ring\n\n/-\nMaybe this is cheating. Let's try to do the next computation without ring.\nWe could use:\npow_two x : x^2 = x*x\nmul_sub a b c : a*(b-c) = a*b - a*c\nadd_mul a b c : (a+b)*c = a*c + b*c\nadd_sub a b c : a + (b - c) = (a + b) - c\nsub_sub a b c : a - b - c = a - (b + c)\nadd_zero a : a + 0 = a\n-/\n\n-- 0008\nexample (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 :=\nbegin\n  calc\n    (a + b) * (a - b) = a * (a - b) + b * (a - b)       : by rw add_mul\n    ...               = a * a - a * b + (b * a - b * b) : by repeat {rw mul_sub}\n    ...               = a^2 - a * b + (b * a - b^2)     : by repeat {rw ←pow_two}\n    ...               = a^2 - a * b + b * a - b^2       : by rw add_sub\n    ...               = a^2 - a * b + a * b - b^2       : by rw mul_comm b\n    ...               = a^2 - b^2                       : by rw sub_add_cancel\nend\n\n/- Let's stick to ring in the end. -/\n\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/tutorials/src/exercises/01_equality_rewriting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.904650527388829, "lm_q1q2_score": 0.7742461848179876}}
{"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 `α`, 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 ≤ 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\nopen_locale pointwise\n\nnamespace set\n\nsection linear_order\n\nvariables {α : Type u} [linear_order α] {a a₁ a₂ b b₁ b₂ c x : α}\n\n/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/\ndef interval (a b : α) := Icc (min a b) (max a b)\n\nlocalized \"notation `[`a `, ` b `]` := set.interval a b\" in interval\n\n@[simp] lemma interval_of_le (h : a ≤ 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 ≤ a) : [a, b] = Icc b a :=\nby { rw [interval, min_eq_right h, max_eq_left h] }\n\nlemma interval_swap (a b : α) : [a, b] = [b, a] :=\nby rw [interval, interval, min_comm, max_comm]\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 : ¬ a ≤ b) : [a, b] = Icc b a :=\ninterval_of_gt (lt_of_not_ge h)\n\nlemma interval_of_not_ge (h : ¬ b ≤ 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 ∈ [a, b] :=\nby { rw [interval, mem_Icc], exact ⟨min_le_left _ _, le_max_left _ _⟩ }\n\n@[simp] lemma right_mem_interval : b ∈ [a, b] :=\nby { rw interval_swap, exact left_mem_interval }\n\nlemma Icc_subset_interval : Icc a b ⊆ [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 ⊆ [a, b] :=\nby { rw interval_swap, apply Icc_subset_interval }\n\nlemma mem_interval_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [a, b] :=\nIcc_subset_interval ⟨ha, hb⟩\n\nlemma mem_interval_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [a, b] :=\nIcc_subset_interval' ⟨hb, ha⟩\n\nlemma not_mem_interval_of_lt (ha : c < a) (hb : c < b) : c ∉ interval a b :=\nnot_mem_Icc_of_lt $ lt_min_iff.mpr ⟨ha, hb⟩\n\nlemma not_mem_interval_of_gt (ha : a < c) (hb : b < c) : c ∉ interval a b :=\nnot_mem_Icc_of_gt $ max_lt_iff.mpr ⟨ha, hb⟩\n\nlemma interval_subset_interval (h₁ : a₁ ∈ [a₂, b₂]) (h₂ : b₁ ∈ [a₂, b₂]) : [a₁, b₁] ⊆ [a₂, b₂] :=\nIcc_subset_Icc (le_min h₁.1 h₂.1) (max_le h₁.2 h₂.2)\n\nlemma interval_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [a₁, b₁] ⊆ Icc a₂ b₂ :=\nIcc_subset_Icc (le_min ha.1 hb.1) (max_le ha.2 hb.2)\n\nlemma interval_subset_interval_iff_mem : [a₁, b₁] ⊆ [a₂, b₂] ↔ a₁ ∈ [a₂, b₂] ∧ b₁ ∈ [a₂, b₂] :=\niff.intro (λh, ⟨h left_mem_interval, h right_mem_interval⟩) (λ h, interval_subset_interval h.1 h.2)\n\nlemma interval_subset_interval_iff_le :\n  [a₁, b₁] ⊆ [a₂, b₂] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ :=\nby { rw [interval, interval, Icc_subset_Icc_iff], exact min_le_max }\n\nlemma interval_subset_interval_right (h : x ∈ [a, b]) : [x, b] ⊆ [a, b] :=\ninterval_subset_interval h right_mem_interval\n\nlemma interval_subset_interval_left (h : x ∈ [a, b]) : [a, x] ⊆ [a, b] :=\ninterval_subset_interval left_mem_interval h\n\n/-- A sort of triangle inequality. -/\nlemma interval_subset_interval_union_interval : [a, c] ⊆ [a, b] ∪ [b, c] :=\nbegin\n  rintro x hx,\n  obtain hac | hac := le_total a c,\n  { rw interval_of_le hac at hx,\n    obtain hb | hb := le_total x b,\n    { exact or.inl (mem_interval_of_le hx.1 hb) },\n    { exact or.inr (mem_interval_of_le hb hx.2) } },\n  { rw interval_of_ge hac at hx,\n    obtain hb | hb := le_total x b,\n    { exact or.inr (mem_interval_of_ge hx.1 hb) },\n    { exact or.inl (mem_interval_of_ge hb hx.2) } }\nend\n\nlemma bdd_below_bdd_above_iff_subset_interval (s : set α) :\n  bdd_below s ∧ bdd_above s ↔ ∃ a b, s ⊆ [a, b] :=\nbegin\n  rw [bdd_below_bdd_above_iff_subset_Icc],\n  split,\n  { rintro ⟨a, b, h⟩, exact ⟨a, b, λ x hx, Icc_subset_interval (h hx)⟩ },\n  { rintro ⟨a, b, h⟩, exact ⟨min a b, max a b, h⟩ }\nend\n\n/-- The open-closed interval with unordered bounds. -/\ndef interval_oc : α → α → set α := λ a b, Ioc (min a b) (max a b)\n\n-- Below is a capital iota\nlocalized \"notation `Ι` := set.interval_oc\" in interval\n\nlemma interval_oc_of_le (h : a ≤ b) : Ι a b = Ioc a b :=\nby simp [interval_oc, h]\n\nlemma interval_oc_of_lt (h : b < a) : Ι a b = Ioc b a :=\nby simp [interval_oc, le_of_lt h]\n\nlemma forall_interval_oc_iff  {P : α → Prop} :\n  (∀ x ∈ Ι a b, P x) ↔ (∀ x ∈ Ioc a b, P x) ∧ (∀ x ∈ Ioc b a, P x) :=\nby { dsimp [interval_oc], cases le_total a b with hab hab ; simp [hab] }\n\nlemma interval_oc_subset_interval_oc_of_interval_subset_interval {a b c d : α}\n  (h : [a, b] ⊆ [c, d]) : Ι a b ⊆ Ι c d :=\nIoc_subset_Ioc (interval_subset_interval_iff_le.1 h).1 (interval_subset_interval_iff_le.1 h).2\n\nlemma interval_oc_swap (a b : α) : Ι a b = Ι b a :=\nby simp only [interval_oc, min_comm a b, max_comm a b]\n\nend linear_order\n\nopen_locale interval\n\nsection ordered_add_comm_group\n\nvariables {α : Type u} [linear_ordered_add_comm_group α] (a b c x y : α)\n\n@[simp] lemma preimage_const_add_interval : (λ x, a + x) ⁻¹' [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 : (λ x, x + a) ⁻¹' [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 : (λ x, x - a) ⁻¹' [b, c] = [b + a, c + a] :=\nby simp [sub_eq_add_neg]\n\n@[simp] lemma preimage_const_sub_interval : (λ x, a - x) ⁻¹' [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 : (λ x, a + x) '' [b, c] = [a + b, a + c] :=\nby simp [add_comm]\n\n@[simp] lemma image_add_const_interval : (λ x, x + a) '' [b, c] = [b + a, c + a] :=\nby simp\n\n@[simp] lemma image_const_sub_interval : (λ x, a - x) '' [b, c] = [a - b, a - c] :=\nby simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]\n\n@[simp] lemma image_sub_const_interval : (λ 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] ⊆ [a, b]) : |y - x| ≤ |b - a| :=\nbegin\n  rw [← max_sub_min_eq_abs, ← 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 ∈ [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 ∈ [a, b]) : |x - a| ≤ |b - a| :=\nabs_sub_le_of_subinterval (interval_subset_interval_left h)\n\n/-- If `x ∈ [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 ∈ [a, b]) : |b - x| ≤ |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 ≠ 0) (b c : k) :\n  (λ x, x * a) ⁻¹' [b, c] = [b / a, c / a] :=\n(lt_or_gt_of_ne ha).elim\n  (λ ha, by simp [interval, ha, ha.le, min_div_div_right_of_nonpos, max_div_div_right_of_nonpos])\n  (λ (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 ≠ 0) (b c : k) :\n  (λ x, a * x) ⁻¹' [b, c] = [b / a, c / a] :=\nby simp only [← preimage_mul_const_interval ha, mul_comm]\n\n@[simp] lemma preimage_div_const_interval (ha : a ≠ 0) (b c : k) :\n  (λ x, x / a) ⁻¹' [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) : (λ x, x * a) '' [b, c] = [b * a, c * a] :=\nif ha : a = 0 then by simp [ha] else\ncalc (λ x, x * a) '' [b, c] = (λ x, x * a⁻¹) ⁻¹' [b, c] :\n  (units.mk0 a ha).mul_right.image_eq_preimage _\n... = (λ x, x / a) ⁻¹' [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) : (λ 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) : (λ 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": "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/intervals/unordered_interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7742301157658857}}
{"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_fin\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.Nat.Factors\nimport Mathlib.Data.Set.Finite\n\n/-!\n# Prime numbers\n\nThis file contains some results about prime numbers which depend on finiteness of sets.\n-/\n\n\nnamespace Nat\n\n/-- A version of `Nat.exists_infinite_primes` using the `Set.Infinite` predicate. -/\ntheorem infinite_setOf_prime : { p | Prime p }.Infinite :=\n  Set.infinite_of_not_bddAbove not_bddAbove_setOf_prime\n#align nat.infinite_set_of_prime Nat.infinite_setOf_prime\n\n/-- If `a`, `b` are positive, the prime divisors of `a * b` are the union of those of `a` and `b` -/\ntheorem factors_mul_toFinset {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :\n    (a * b).factors.toFinset = a.factors.toFinset ∪ b.factors.toFinset :=\n  (List.toFinset.ext fun _ => (mem_factors_mul ha hb).trans List.mem_union.symm).trans <|\n    List.toFinset_union _ _\n#align nat.factors_mul_to_finset Nat.factors_mul_toFinset\n\ntheorem pow_succ_factors_toFinset (n k : ℕ) : (n ^ (k + 1)).factors.toFinset = n.factors.toFinset :=\n  by\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_toFinset hn (pow_ne_zero _ hn), ih, Finset.union_idempotent]\n#align nat.pow_succ_factors_to_finset Nat.pow_succ_factors_toFinset\n\ntheorem pow_factors_toFinset (n : ℕ) {k : ℕ} (hk : k ≠ 0) :\n    (n ^ k).factors.toFinset = n.factors.toFinset := by\n  cases k\n  · simp at hk\n  rw [pow_succ_factors_toFinset]\n#align nat.pow_factors_to_finset Nat.pow_factors_toFinset\n\n/-- The only prime divisor of positive prime power `p^k` is `p` itself -/\ntheorem prime_pow_prime_divisor {p k : ℕ} (hk : k ≠ 0) (hp : Prime p) :\n    (p ^ k).factors.toFinset = {p} := by simp [pow_factors_toFinset p hk, factors_prime hp]\n#align nat.prime_pow_prime_divisor Nat.prime_pow_prime_divisor\n\ntheorem factors_mul_toFinset_of_coprime {a b : ℕ} (hab : coprime a b) :\n    (a * b).factors.toFinset = a.factors.toFinset ∪ b.factors.toFinset :=\n  (List.toFinset.ext <| mem_factors_mul_of_coprime hab).trans <| List.toFinset_union _ _\n#align nat.factors_mul_to_finset_of_coprime Nat.factors_mul_toFinset_of_coprime\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/PrimeFin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479467, "lm_q2_score": 0.8840392832736084, "lm_q1q2_score": 0.7742301043968004}}
{"text": "import data.real.basic\n\nimport tactic.suggest\n\nimport game.Completeness.level01\n\nnoncomputable theory\nopen_locale classical\n\n/-\n# Chapter 6 : Completeness\n\n## Level 3 \n\nThe infimum, call it y, of a set A is the greatest lower bound\nof A. In lean, we define the infimum as the maximum of the lwoer bound. \n\n\nProve that for any number in a lower bounded set, \nthere exists an element in A such that \nthe element will be less than the number. \n\nHint: it may help to prove by contrapositive. \n-/\n\nlemma inf_lt {A : set ℝ} {x : ℝ} (hx : x is_an_inf_of A) :\n  ∀ y, x < y → ∃ a ∈ 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 `¬` 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\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/Completeness/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7742013247714551}}
{"text": "/-! \n\n# Probability overivew\n\nIn this short file, I will give a brief overview of what probability theory \ncurrently exists in mathlib. \n\nThe quickest indicator of what exists in mathlib is simply going into the \nprobability folder and look at the file names. Of course, this method doesn't \nreally give you a indicator of what is actually there. Also, some results \nrelevant to probability theory might not actually be in the probability folder, \ne.g. conditional expectation. I will now list the relevant files. \n\n`probability._`: \n- `cond_count`: classical probability formulated in measure theory. Useful for \n  probabilistic arguments in combinatorics.\n- `conditional_expectation`: this is *not* where conditional expectaion is \n  defined but the idea is that it should contain \"probabilistic\" results about \n  the conditional expectation. There is only one result there at the moment.\n- `conditional_probability`: conditioning by an event and Bayes' theorem. \n  This is *not* the conditional probability defined via. the conditional \n  expectation.\n- `density`: defines the probability density function and the uniform \n  distribution. It also contains results such as the LOTUS theorem.\n- `ident_distrib`: definition of identically distributed random variables.\n- `indepencence`: definition of independence (in a lot of sense); has a lot of \n  useful lemmas especially should you want to prove independence via. \n  π-λ systems.\n- `integration`: lemmas about independence of random variables\n- `moments`: moment generating functions and cumulant generating functions and \n  basic lemmas about them.\n- `notation`: defines probability notations (requires you to write\n  `open_locale probability_theory` in the file to before you can use)\n- `strong_law`: the strong law of large numbers (both the a.e. and Lᵖ versions)\n- `variance`: defines variance. Also contain the Chebyshev inequality.\n\n`probability.process._` (most of this is rather self explainitory):\n- `adapted`: defines adaptedness for stochastic processes\n- `filtration`: defines filtration for stochastic processes\n- `hitting_time`: hitting times are a random time (a stopping time in the \n  discrete time setting) and this file contains some basic results about them.\n- `stopping`: defines stopping time for stochastic processes\n\n`probability.martingale._`:\n- `basic`: defines (sub/super)martingales and prove basic properties about them.\n- `borel_cantelli`: proves the one-sided (sub)martingale bound and Lévy's \n  generalized Borel-Cantelli lemma.\n- `centering`: proves the Doob's decomposition.\n- `convergence`: proves the a.e. and L¹-martingale convergence theorems.\n- `optional_stopping`: optional stopping theorem and the maximal inequality.\n- `upcrossing`: two variants of the Doob's upcrossing estimate used to prove \n  the martingale covnergence theorems.\n\n`probability.probability_mass_function._`:\nI don't know much about this folder. I think these are finite stuff, not very \nrelevant to what we want to work with but a lot of \"Giry monads\" whatever those \nare.\n\n`measure_theory.function.conditional_expectation._`:\n- `basic`: the construction of the conditional expecation. A lot of useful \n  lemmas are there too though the idea is we will eventually move them out of \n  there.\n- `indicator`: the full-out property of conditional expectation for indicator \n  functions.\n- `real`: contains results about the conditional expectation of real-valued \n  random variables (in contrast to Banach-space valued random variables). \n  In particular, this shows that our construction is equivalent to the \n  construction of the conditional expectation via. the Radon-Nikodym derivative. \n  Also, it show the pull-out proerty for real-valued random variables.\n  It also contains some cool bounds for real-valued random variables also, \n  though we hope to generalize a lot of them once we have the conditional \n  Jensen's inequality.\n\n`measure_theory.function.uniform_integrable`: uniform integrability in both the \nanalyst's and the probabilist's sense (the two definitions are *not* equivalent) \nand proves the Vitali's convergence theorem.\n\n`measure_theory.function.convergence_in_measure`: convergence in measure. See \nthe `prob_thy` file for more details.\n\nI am also very familiar with the `measure_theory.decomposition` folder so you \ncan ask me about it if you are interested in the formalization of the \nRadon-Nikodym theorem.\n\n-/", "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_overview.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7741933853887005}}
{"text": "import tactic --hide\nlemma not_iff_imp_false (P : Prop) : ¬ P ↔ P → false := iff.rfl -- hide\nlemma contra (P Q : Prop) : (P ∧ ¬ P) → Q := by {cc} --hide\n\n\n/-Lemma\nIf $P, Q$ are logical statements then $(P \\implies Q)$ is equivalent to $(¬P) ∨ Q$.\n-/\nlemma P_imp_Q_equiv_not_P_and_Q (P Q : Prop) : (P → Q) ↔ ¬ P ∨ Q :=\nbegin\n  split,\n  intro h,\n  by_cases p : P,\n  right,\n  apply h,\n  exact p,\n  left,\n  exact p,\n  intros h1 h2,\n  cases h1,\n  exfalso,\n  apply h1,\n  exact h2,\n  exact h1,\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/logic3/notlogicb4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248123094437, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7741902056720417}}
{"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-/\nimport data.matrix.pequiv\nimport data.fintype.card\nimport group_theory.perm.fin\nimport group_theory.perm.sign\nimport algebra.algebra.basic\nimport tactic.ring\nimport linear_algebra.alternating\nimport linear_algebra.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_multilinear`: the determinant, as an `alternating_map` in the rows of the matrix\n\n## Main results\n\n - `det_mul`: the determinant of `A ⬝ 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\nuniverses u v w z\nopen equiv equiv.perm finset function\n\nnamespace matrix\nopen_locale matrix big_operators\n\nvariables {m n : Type*} [decidable_eq n] [fintype n] [decidable_eq m] [fintype m]\nvariables {R : Type v} [comm_ring R]\n\nlocal notation `ε` σ:max := ((sign σ : ℤ ) : R)\n\n\n/-- `det` is an `alternating_map` in the rows of the matrix. -/\ndef det_row_multilinear : alternating_map R (n → R) R n :=\n((multilinear_map.mk_pi_algebra R n R).comp_linear_map (linear_map.proj)).alternatization\n\n/-- The determinant of a matrix given by the Leibniz formula. -/\nabbreviation det (M : matrix n n R) : R :=\ndet_row_multilinear M\n\nlemma det_apply (M : matrix n n R) :\n  M.det = ∑ σ : perm n, (σ.sign : ℤ) • ∏ i, M (σ i) i :=\nmultilinear_map.alternatization_apply _ M\n\n-- This is what the old definition was. We use it to avoid having to change the old proofs below\nlemma det_apply' (M : matrix n n R) :\n  M.det = ∑ σ : perm n, ε σ * ∏ i, M (σ i) i :=\nby simp [det_apply]\n\n@[simp] lemma det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i :=\nbegin\n  rw det_apply',\n  refine (finset.sum_eq_single 1 _ _).trans _,\n  { intros σ h1 h2,\n    cases not_forall.1 (mt equiv.ext h2) with x h3,\n    convert mul_zero _,\n    apply finset.prod_eq_zero,\n    { change x ∈ _, simp },\n    exact if_neg h3 },\n  { simp },\n  { simp }\nend\n\n@[simp] lemma det_zero (h : nonempty n) : det (0 : matrix n n R) = 0 :=\n(det_row_multilinear : alternating_map R (n → R) R n).map_zero\n\n@[simp] lemma det_one : det (1 : matrix n n R) = 1 :=\nby rw [← diagonal_one]; simp [-diagonal_one]\n\nlemma det_eq_one_of_card_eq_zero {A : matrix n n R} (h : fintype.card n = 0) : det A = 1 :=\nbegin\n  have perm_eq : (univ : finset (perm n)) = {1} :=\n  univ_eq_singleton_of_card_one (1 : perm n) (by simp [card_univ, fintype.card_perm, h]),\n  simp [det_apply, card_eq_zero.mp h, perm_eq],\nend\n\n/-- Specialize `det_eq_one_of_card_eq_zero` to `fin 0`.\n\nThis is especially useful in combination with the `det_succ_` lemmas,\nfor computing the determinant of a matrix given in the `![...]` notation.\n-/\n@[simp] lemma det_fin_zero {A : matrix (fin 0) (fin 0) R}: det A = 1 :=\ndet_eq_one_of_card_eq_zero (fintype.card_fin _)\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]\nlemma det_unique {n : Type*} [unique n] [decidable_eq n] [fintype n] (A : matrix n n R) :\n  det A = A (default n) (default n) :=\nby simp [det_apply, univ_unique]\n\nlemma 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 :=\nbegin\n  have h1 : (univ : finset (perm n)) = {1},\n  { apply univ_eq_singleton_of_card_one (1 : perm n),\n    simp [card_univ, fintype.card_perm, h] },\n  have h2 := univ_eq_singleton_of_card_one k h,\n  simp [det_apply, h1, h2],\nend\n\nlemma det_mul_aux {M N : matrix n n R} {p : n → n} (H : ¬bijective p) :\n  ∑ σ : perm n, (ε σ) * ∏ x, (M (σ x) (p x) * N (p x) x) = 0 :=\nbegin\n  obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j,\n  { rw [← fintype.injective_iff_bijective, injective] at H,\n    push_neg at H,\n    exact H },\n  exact sum_involution\n    (λ σ _, σ * swap i j)\n    (λ σ _,\n      have ∏ x, M (σ x) (p x) = ∏ x, M ((σ * swap i j) x) (p x),\n        from fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]),\n      by simp [this, sign_swap hij, prod_mul_distrib])\n    (λ σ _ _, (not_congr mul_swap_eq_iff).mpr hij)\n    (λ _ _, mem_univ _)\n    (λ σ _, mul_swap_involutive i j σ)\nend\n\n@[simp] lemma det_mul (M N : matrix n n R) : det (M ⬝ N) = det M * det N :=\ncalc det (M ⬝ N) = ∑ p : n → n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :\n  by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum,\n    fintype.pi_finset_univ]; rw [finset.sum_comm]\n... = ∑ p in (@univ (n → n) _).filter bijective, ∑ σ : perm n,\n    ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :\n  eq.symm $ sum_subset (filter_subset _ _)\n    (λ f _ hbij, det_mul_aux $ by simpa using hbij)\n... = ∑ τ : perm n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (τ i) * N (τ i) i) :\n  sum_bij (λ p h, equiv.of_bijective p (mem_filter.1 h).2) (λ _ _, mem_univ _)\n    (λ _ _, rfl) (λ _ _ _ _ h, by injection h)\n    (λ b _, ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩)\n... = ∑ σ : perm n, ∑ τ : perm n, (∏ i, N (σ i) i) * ε τ * (∏ j, M (τ j) (σ j)) :\n  by simp [mul_sum, det_apply', mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]\n... = ∑ σ : perm n, ∑ τ : perm n, (((∏ i, N (σ i) i) * (ε σ * ε τ)) * ∏ i, M (τ i) i) :\n  sum_congr rfl (λ σ _, fintype.sum_equiv (equiv.mul_right σ⁻¹) _ _\n    (λ τ,\n      have ∏ j, M (τ j) (σ j) = ∏ j, M ((τ * σ⁻¹) j) j,\n        by rw ← σ⁻¹.prod_comp; simp [mul_apply],\n      have h : ε σ * ε (τ * σ⁻¹) = ε τ :=\n        calc ε σ * ε (τ * σ⁻¹) = ε ((τ * σ⁻¹) * σ) :\n          by rw [mul_comm, sign_mul (τ * σ⁻¹)]; simp\n        ... = ε τ : by simp,\n      by simp_rw [equiv.coe_mul_right, h]; simp [this, mul_comm, mul_assoc, mul_left_comm]))\n... = det M * det N : by simp [det_apply', mul_assoc, mul_sum, mul_comm, mul_left_comm]\n\ninstance : is_monoid_hom (det : matrix n n R → R) :=\n{ map_one := det_one,\n  map_mul := det_mul }\n\n/-- Transposing a matrix preserves the determinant. -/\n@[simp] lemma det_transpose (M : matrix n n R) : Mᵀ.det = M.det :=\nbegin\n  rw [det_apply', det_apply'],\n  refine fintype.sum_bijective _ inv_involutive.bijective _ _ _,\n  intros σ,\n  rw sign_inv,\n  congr' 1,\n  apply fintype.prod_equiv σ,\n  intros,\n  simp\nend\n\n\n/-- Permuting the columns changes the sign of the determinant. -/\nlemma det_permute (σ : perm n) (M : matrix n n R) : matrix.det (λ i, M (σ i)) = σ.sign * M.det :=\n((det_row_multilinear : alternating_map R (n → R) R n).map_perm M σ).trans (by simp)\n\n/-- Permuting rows and columns with the same equivalence has no effect. -/\n@[simp]\nlemma det_minor_equiv_self (e : n ≃ m) (A : matrix m m R) :\n  det (A.minor e e) = det A :=\nbegin\n  rw [det_apply', det_apply'],\n  apply finset.sum_bij' (λ σ _, equiv.perm_congr e σ) _ _ (λ σ _, equiv.perm_congr e.symm σ),\n  { intros σ _, ext, simp only [equiv.symm_symm, equiv.perm_congr_apply, equiv.symm_apply_apply] },\n  { intros σ _, ext, simp only [equiv.symm_symm, equiv.perm_congr_apply, equiv.apply_symm_apply] },\n  { intros σ _, apply finset.mem_univ },\n  { intros σ _, apply finset.mem_univ },\n  intros σ _,\n  simp_rw [equiv.perm_congr_apply],\n  rw equiv.perm.sign_perm_congr e σ,\n  congr' 1,\n  apply finset.prod_bij' (λ i _, e i) _ _ (λ i _, e.symm i),\n  { intros, simp_rw equiv.symm_apply_apply },\n  { intros, simp_rw equiv.apply_symm_apply },\n  { intros, apply finset.mem_univ },\n  { intros, apply finset.mem_univ },\n  { intros, simp_rw equiv.symm_apply_apply, rw minor_apply, },\nend\n\n/-- Reindexing both indices along the same equivalence preserves the determinant.\n\nFor the `simp` version of this lemma, see `det_minor_equiv_self`; this one is unsuitable because\n`matrix.reindex_apply` unfolds `reindex` first.\n-/\nlemma det_reindex_self (e : m ≃ n) (A : matrix m m R) : det (reindex e e A) = det A :=\ndet_minor_equiv_self e.symm A\n\n/-- The determinant of a permutation matrix equals its sign. -/\n@[simp] lemma det_permutation (σ : perm n) :\n  matrix.det (σ.to_pequiv.to_matrix : matrix n n R) = σ.sign :=\nby rw [←matrix.mul_one (σ.to_pequiv.to_matrix : matrix n n R), pequiv.to_pequiv_mul_matrix,\n  det_permute, det_one, mul_one]\n\n@[simp] lemma det_smul {A : matrix n n R} {c : R} : det (c • A) = c ^ fintype.card n * det A :=\ncalc det (c • A) = det (matrix.mul (diagonal (λ _, c)) A) : by rw [smul_eq_diagonal_mul]\n             ... = det (diagonal (λ _, c)) * det A        : det_mul _ _\n             ... = c ^ fintype.card n * det A             : by simp [card_univ]\n\n/-- Multiplying each row by a fixed `v i` multiplies the determinant by\nthe product of the `v`s. -/\nlemma det_mul_row (v : n → R) (A : matrix n n R) :\n  det (λ i j, v j * A i j) = (∏ i, v i) * det A :=\ncalc det (λ i j, v j * A i j) = det (A ⬝ diagonal v) : congr_arg det $ by { ext, simp [mul_comm] }\n                          ... = (∏ i, v i) * det A : by rw [det_mul, det_diagonal, mul_comm]\n\n/-- Multiplying each column by a fixed `v j` multiplies the determinant by\nthe product of the `v`s. -/\nlemma det_mul_column (v : n → R) (A : matrix n n R) :\n  det (λ i j, v i * A i j) = (∏ i, v i) * det A :=\nmultilinear_map.map_smul_univ _ v A\n\nsection hom_map\n\nvariables {S : Type w} [comm_ring S]\n\nlemma ring_hom.map_det {M : matrix n n R} {f : R →+* S} :\n  f M.det = matrix.det (f.map_matrix M) :=\nby simp [matrix.det_apply', f.map_sum, f.map_prod]\n\nlemma alg_hom.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T]\n  {M : matrix n n S} {f : S →ₐ[R] T} :\n  f M.det = matrix.det ((f : S →+* T).map_matrix M) :=\nby rw [← alg_hom.coe_to_ring_hom, ring_hom.map_det]\n\nend hom_map\n\nsection det_zero\n/-!\n### `det_zero` section\n\nProve that a matrix with a repeated column has determinant equal to zero.\n-/\n\nlemma det_eq_zero_of_row_eq_zero {A : matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 :=\n(det_row_multilinear : alternating_map R (n → R) R n).map_coord_zero i (funext h)\n\nlemma det_eq_zero_of_column_eq_zero {A : matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 :=\nby { rw ← det_transpose, exact det_eq_zero_of_row_eq_zero j h, }\n\nvariables {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 ≠ j) (hij : M i = M j) : M.det = 0 :=\n(det_row_multilinear : alternating_map R (n → R) R n).map_eq_zero_of_eq M hij i_ne_j\n\n/-- If a matrix has a repeated column, the determinant will be zero. -/\ntheorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 :=\nby { rw [← det_transpose, det_zero_of_row_eq i_ne_j], exact funext hij }\n\nend det_zero\n\nlemma det_update_row_add (M : matrix n n R) (j : n) (u v : n → R) :\n  det (update_row M j $ u + v) = det (update_row M j u) + det (update_row M j v) :=\n(det_row_multilinear : alternating_map R (n → R) R n).map_add M j u v\n\nlemma det_update_column_add (M : matrix n n R) (j : n) (u v : n → R) :\n  det (update_column M j $ u + v) = det (update_column M j u) + det (update_column M j v) :=\nbegin\n  rw [← det_transpose, ← update_row_transpose, det_update_row_add],\n  simp [update_row_transpose, det_transpose]\nend\n\nlemma det_update_row_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :\n  det (update_row M j $ s • u) = s * det (update_row M j u) :=\n(det_row_multilinear : alternating_map R (n → R) R n).map_smul M j s u\n\nlemma det_update_column_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :\n  det (update_column M j $ s • u) = s * det (update_column M j u) :=\nbegin\n  rw [← det_transpose, ← update_row_transpose, det_update_row_smul],\n  simp [update_row_transpose, det_transpose]\nend\n\nsection det_eq\n\n/-! ### `det_eq` section\n\nLemmas showing the determinant is invariant under a variety of operations.\n-/\nlemma det_eq_of_eq_mul_det_one {A B : matrix n n R}\n  (C : matrix n n R) (hC : det C = 1) (hA : A = B ⬝ C) : det A = det B :=\ncalc det A = det (B ⬝ C) : congr_arg _ hA\n       ... = det B * det C : det_mul _ _\n       ... = det B : by rw [hC, mul_one]\n\nlemma det_eq_of_eq_det_one_mul {A B : matrix n n R}\n  (C : matrix n n R) (hC : det C = 1) (hA : A = C ⬝ B) : det A = det B :=\ncalc det A = det (C ⬝ B) : congr_arg _ hA\n       ... = det C * det B : det_mul _ _\n       ... = det B : by rw [hC, one_mul]\n\nlemma det_update_row_add_self (A : matrix n n R) {i j : n} (hij : i ≠ j) :\n  det (update_row A i (A i + A j)) = det A :=\nby simp [det_update_row_add,\n    det_zero_of_row_eq hij ((update_row_self).trans (update_row_ne hij.symm).symm)]\n\nlemma det_update_column_add_self (A : matrix n n R) {i j : n} (hij : i ≠ j) :\n  det (update_column A i (λ k, A k i + A k j)) = det A :=\nby { rw [← det_transpose, ← update_row_transpose, ← det_transpose A],\n     exact det_update_row_add_self Aᵀ hij }\n\nlemma det_update_row_add_smul_self (A : matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :\n  det (update_row A i (A i + c • A j)) = det A :=\nby 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\nlemma det_update_column_add_smul_self (A : matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :\n  det (update_column A i (λ k, A k i + c • A k j)) = det A :=\nby { rw [← det_transpose, ← update_row_transpose, ← det_transpose A],\n      exact det_update_row_add_smul_self Aᵀ hij c }\n\nlemma det_eq_of_forall_row_eq_smul_add_const_aux\n  {A B : matrix n n R} {s : finset n} : ∀ (c : n → R) (hs : ∀ i, i ∉ s → c i = 0)\n  (k : n) (hk : k ∉ s) (A_eq : ∀ i j, A i j = B i j + c i * B k j),\n  det A = det B :=\nbegin\n  revert B,\n  refine s.induction_on _ _,\n  { intros A c hs k hk A_eq,\n    have : ∀ i, c i = 0,\n    { intros i,\n      specialize hs i,\n      contrapose! hs,\n      simp [hs] },\n    congr,\n    ext i j,\n    rw [A_eq, this, zero_mul, add_zero], },\n  { intros i s hi ih B c hs k hk A_eq,\n    have hAi : A i = B i + c i • B k := funext (A_eq i),\n    rw [@ih (update_row B i (A i)) (function.update c i 0), hAi,\n        det_update_row_add_smul_self],\n    { exact mt (λ h, show k ∈ insert i s, from h ▸ finset.mem_insert_self _ _) hk },\n    { intros i' hi',\n      rw function.update_apply,\n      split_ifs with hi'i, { refl },\n      { exact hs i' (λ h, hi' ((finset.mem_insert.mp h).resolve_left hi'i)) } },\n    { exact λ h, hk (finset.mem_insert_of_mem h) },\n    { intros i' j',\n      rw [update_row_apply, function.update_apply],\n      split_ifs with hi'i,\n      { simp [hi'i] },\n      rw [A_eq, update_row_ne (λ (h : k = i), hk $ h ▸ finset.mem_insert_self k s)] } }\nend\n\n/-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/\nlemma det_eq_of_forall_row_eq_smul_add_const\n  {A B : matrix n n R} (c : n → R) (k : n) (hk : c k = 0)\n  (A_eq : ∀ i j, A i j = B i j + c i * B k j) :\n  det A = det B :=\ndet_eq_of_forall_row_eq_smul_add_const_aux c\n  (λ i, not_imp_comm.mp $ λ hi, finset.mem_erase.mpr\n    ⟨mt (λ (h : i = k), show c i = 0, from h.symm ▸ hk) hi, finset.mem_univ i⟩)\n  k (finset.not_mem_erase k finset.univ) A_eq\n\nlemma det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : fin (n + 1)) :\n  ∀ (c : fin n → R) (hc : ∀ (i : fin n), k < i.succ → c i = 0)\n    {M N : matrix (fin n.succ) (fin n.succ) R}\n    (h0 : ∀ j, M 0 j = N 0 j)\n    (hsucc : ∀ (i : fin n) j, M i.succ j = N i.succ j + c i * M i.cast_succ j),\n    det M = det N :=\nbegin\n  refine fin.induction _ (λ k ih, _) k;\n    intros c hc M N h0 hsucc,\n  { congr,\n    ext i j,\n    refine fin.cases (h0 j) (λ i, _) i,\n    rw [hsucc, hc i (fin.succ_pos _), zero_mul, add_zero] },\n\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 • M k.cast_succ),\n  { ext i j,\n    by_cases hi : i = k.succ,\n    { simp [hi, hM', hsucc, update_row_self] },\n    rw [update_row_ne hi, hM', update_row_ne hi] },\n\n  have k_ne_succ : k.cast_succ ≠ k.succ := (fin.cast_succ_lt_succ k).ne,\n  have M_k : M k.cast_succ = M' k.cast_succ := (update_row_ne k_ne_succ).symm,\n\n  rw [hM, M_k, det_update_row_add_smul_self M' k_ne_succ.symm, ih (function.update c k 0)],\n  { intros i hi,\n    rw [fin.lt_iff_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff] at hi,\n    rw function.update_apply,\n    split_ifs with hik, { refl },\n    exact hc _ (fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (ne.symm hik))) },\n  { rwa [hM', update_row_ne (fin.succ_ne_zero _).symm] },\n  intros i j,\n  rw function.update_apply,\n  split_ifs with hik,\n  { rw [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  { 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_coe_lt_coe, fin.coe_cast_succ, fin.coe_succ, nat.lt_succ_iff, ← not_lt]\nend\n\n/-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/\nlemma det_eq_of_forall_row_eq_smul_add_pred {n : ℕ}\n  {A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n → R)\n  (A_zero : ∀ j, A 0 j = B 0 j)\n  (A_succ : ∀ (i : fin n) j, A i.succ j = B i.succ j + c i * A i.cast_succ j) :\n  det A = det B :=\ndet_eq_of_forall_row_eq_smul_add_pred_aux (fin.last _) c\n  (λ i hi, absurd hi (not_lt_of_ge (fin.le_last _)))\n  A_zero A_succ\n\n/-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/\nlemma det_eq_of_forall_col_eq_smul_add_pred {n : ℕ}\n  {A B : matrix (fin (n + 1)) (fin (n + 1)) R} (c : fin n → R)\n  (A_zero : ∀ i, A i 0 = B i 0)\n  (A_succ : ∀ i (j : fin n), A i j.succ = B i j.succ + c j * A i j.cast_succ) :\n  det A = det B :=\nby { rw [← det_transpose A, ← det_transpose B],\n     exact det_eq_of_forall_row_eq_smul_add_pred c A_zero (λ i j, A_succ j i) }\n\nend det_eq\n\n@[simp] lemma det_block_diagonal {o : Type*} [fintype o] [decidable_eq o] (M : o → matrix n n R) :\n  (block_diagonal M).det = ∏ k, (M k).det :=\nbegin\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 × o)) :=\n    finset.univ.filter (λ σ, ∀ x, (σ x).snd = x.snd),\n  have mem_preserving_snd : ∀ {σ : equiv.perm (n × o)},\n    σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd :=\n    λ σ, finset.mem_filter.trans ⟨λ h, h.2, λ h, ⟨finset.mem_univ _, h⟩⟩,\n  rw ← finset.sum_subset (finset.subset_univ preserving_snd) _,\n  -- And that these are in bijection with `o → equiv.perm m`.\n  rw (finset.sum_bij (λ (σ : ∀ (k : o), k ∈ finset.univ → equiv.perm n) _,\n                        prod_congr_left (λ k, σ k (finset.mem_univ k))) _ _ _ _).symm,\n  { intros σ _,\n    rw mem_preserving_snd,\n    rintros ⟨k, x⟩,\n    simp },\n  { intros σ _,\n    rw [finset.prod_mul_distrib, ←finset.univ_product_univ, finset.prod_product, finset.prod_comm],\n    simp [sign_prod_congr_left] },\n  { intros σ σ' _ _ eq,\n    ext x hx k,\n    simp only at eq,\n    have : ∀ k x, prod_congr_left (λ k, σ k (finset.mem_univ _)) (k, x) =\n                  prod_congr_left (λ k, σ' k (finset.mem_univ _)) (k, x) :=\n      λ 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  { intros σ hσ,\n    rw mem_preserving_snd at hσ,\n    have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd,\n    { intro x, conv_rhs { rw [← perm.apply_inv_self σ x, hσ] } },\n    have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k),\n    { intros k x,\n      ext; simp [hσ] },\n    have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k),\n    { intros k x,\n      conv_lhs { rw ← perm.apply_inv_self σ (x, k) },\n      ext; simp [hσ'] },\n    refine ⟨λ k _, ⟨λ x, (σ (x, k)).fst, λ x, (σ⁻¹ (x, k)).fst, _, _⟩, _, _⟩,\n    { intro x,\n      simp [mk_apply_eq, mk_inv_apply_eq] },\n    { intro x,\n      simp [mk_apply_eq, mk_inv_apply_eq] },\n    { apply finset.mem_univ },\n    { ext ⟨k, x⟩; simp [hσ] } },\n  { intros σ _ hσ,\n    rw mem_preserving_snd at hσ,\n    obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ,\n    rw [finset.prod_eq_zero (finset.mem_univ (k, x)), mul_zero],\n    rw [← @prod.mk.eta _ _ (σ (k, x)), block_diagonal_apply_ne],\n    exact hkx }\nend\n\n/-- The determinant of a 2x2 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.upper_block_triangular_det`. -/\nlemma upper_two_block_triangular_det\n  (A : matrix m m R) (B : matrix m n R) (D : matrix n n R) :\n  (matrix.from_blocks A B 0 D).det = A.det * D.det :=\nbegin\n  classical,\n  simp_rw det_apply',\n  convert\n    (sum_subset (subset_univ ((sum_congr_hom m n).range : set (perm (m ⊕ n))).to_finset) _).symm,\n  rw sum_mul_sum,\n  simp_rw univ_product_univ,\n  rw (sum_bij (λ (σ : perm m × perm n) _, equiv.sum_congr σ.fst σ.snd) _ _ _ _).symm,\n  { intros σ₁₂ h,\n    simp only [],\n    erw [set.mem_to_finset, monoid_hom.mem_range],\n    use σ₁₂,\n    simp },\n  { simp only [forall_prop_of_true, prod.forall, mem_univ],\n    intros σ₁ σ₂,\n    rw fintype.prod_sum_type,\n    simp_rw [equiv.sum_congr_apply, sum.map_inr, sum.map_inl, from_blocks_apply₁₁,\n      from_blocks_apply₂₂],\n    have hr : ∀ (a b c d : R), (a * b) * (c * d) = a * c * (b * d), { intros, ac_refl },\n    rw hr,\n    congr,\n    norm_cast,\n    rw sign_sum_congr },\n  { intros σ₁ σ₂ h₁ h₂,\n    dsimp only [],\n    intro h,\n    have h2 : ∀ x, perm.sum_congr σ₁.fst σ₁.snd x = perm.sum_congr σ₂.fst σ₂.snd x,\n    { intro x, 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    { exact h2.left x },\n    { exact h2.right x }},\n  { intros σ hσ,\n    erw [set.mem_to_finset, monoid_hom.mem_range] at hσ,\n    obtain ⟨σ₁₂, hσ₁₂⟩ := hσ,\n    use σ₁₂,\n    rw ←hσ₁₂,\n    simp },\n  { intros σ hσ hσn,\n    have h1 : ¬ (∀ x, ∃ y, sum.inl y = σ (sum.inl x)),\n    { by_contradiction,\n      rw set.mem_to_finset at hσn,\n      apply absurd (mem_sum_congr_hom_range_of_perm_maps_to_inl _) hσn,\n      rintros x ⟨a, ha⟩,\n      rw [←ha], exact h a },\n    obtain ⟨a, ha⟩ := not_forall.mp h1,\n    cases hx : σ (sum.inl a) with a2 b,\n    { have hn := (not_exists.mp ha) a2,\n      exact absurd hx.symm hn },\n    { rw [finset.prod_eq_zero (finset.mem_univ (sum.inl a)), mul_zero],\n      rw [hx, from_blocks_apply₂₁], refl }}\nend\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column 0. -/\nlemma det_succ_column_zero {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) :\n  det A = ∑ i : fin n.succ, (-1) ^ (i : ℕ) * A i 0 *\n    det (A.minor i.succ_above fin.succ) :=\nbegin\n  rw [matrix.det_apply, finset.univ_perm_fin_succ, ← finset.univ_product_univ],\n  simp only [finset.sum_map, equiv.to_embedding_apply, finset.sum_product, matrix.minor],\n  refine finset.sum_congr rfl (λ i _, fin.cases _ (λ i, _) i),\n  { simp only [fin.prod_univ_succ, matrix.det_apply, finset.mul_sum,\n        equiv.perm.decompose_fin_symm_apply_zero, fin.coe_zero, one_mul,\n        equiv.perm.decompose_fin.symm_sign, equiv.swap_self, if_true, id.def, eq_self_iff_true,\n        equiv.perm.decompose_fin_symm_apply_succ, fin.succ_above_zero, equiv.coe_refl, pow_zero,\n        algebra.mul_smul_comm] },\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 : ℕ) = i.cycle_range.sign,\n  { simp [fin.sign_cycle_range] },\n  rw [fin.coe_succ, pow_succ, this, mul_assoc, mul_assoc, mul_left_comm ↑(equiv.perm.sign _),\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 (λ σ _, _),\n  rw [equiv.perm.decompose_fin.symm_sign, if_neg (fin.succ_ne_zero i)],\n  calc ((-1) * σ.sign : ℤ) • ∏ i', A (equiv.perm.decompose_fin.symm (fin.succ i, σ) i') i'\n      = ((-1) * σ.sign : ℤ) • (A (fin.succ i) 0 *\n        ∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (σ i'))) i'.succ) :\n    by simp only [fin.prod_univ_succ, fin.succ_above_cycle_range,\n      equiv.perm.decompose_fin_symm_apply_zero, equiv.perm.decompose_fin_symm_apply_succ]\n  ... = (-1) * (A (fin.succ i) 0 * (σ.sign : ℤ) •\n        ∏ i', A (((fin.succ i).succ_above) (fin.cycle_range i (σ i'))) i'.succ) :\n    by simp only [mul_assoc, mul_comm, neg_mul_eq_neg_mul_symm, one_mul, gsmul_eq_mul, neg_inj,\n      neg_smul, fin.succ_above_cycle_range],\nend\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row 0. -/\nlemma det_succ_row_zero {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) :\n  det A = ∑ j : fin n.succ, (-1) ^ (j : ℕ) * A 0 j *\n    det (A.minor fin.succ j.succ_above) :=\nby { rw [← det_transpose A, det_succ_column_zero],\n     refine finset.sum_congr rfl (λ i _, _),\n     rw [← det_transpose],\n     simp only [transpose_apply, transpose_minor, transpose_transpose] }\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row `i`. -/\nlemma det_succ_row {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) (i : fin n.succ) :\n  det A = ∑ j : fin n.succ, (-1) ^ (i + j : ℕ) * A i j *\n    det (A.minor i.succ_above j.succ_above) :=\nbegin\n  simp_rw [pow_add, mul_assoc, ← mul_sum],\n  have : det A = (-1 : R) ^ (i : ℕ) * (i.cycle_range⁻¹).sign * det A,\n  { calc det A = ↑((-1 : units ℤ) ^ (i : ℕ) * (-1 : units ℤ) ^ (i : ℕ) : units ℤ) * det A :\n             by simp\n           ... = (-1 : R) ^ (i : ℕ) * (i.cycle_range⁻¹).sign * det A :\n             by simp [-int.units_mul_self] },\n  rw [this, mul_assoc],\n  congr,\n  rw [← det_permute, det_succ_row_zero],\n  refine finset.sum_congr rfl (λ j _, _),\n  rw [mul_assoc, matrix.minor, matrix.minor],\n  congr,\n  { rw [equiv.perm.inv_def, fin.cycle_range_symm_zero] },\n  { ext i' j',\n    rw [equiv.perm.inv_def, fin.cycle_range_symm_succ] },\nend\n\n/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column `j`. -/\nlemma det_succ_column {n : ℕ} (A : matrix (fin n.succ) (fin n.succ) R) (j : fin n.succ) :\n  det A = ∑ i : fin n.succ, (-1) ^ (i + j : ℕ) * A i j *\n    det (A.minor i.succ_above j.succ_above) :=\nby { rw [← det_transpose, det_succ_row _ j],\n     refine finset.sum_congr rfl (λ i _, _),\n     rw [add_comm, ← det_transpose, transpose_apply, transpose_minor, transpose_transpose] }\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/linear_algebra/determinant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7741786727861913}}
{"text": "import data.multiset data.finset .to_multiset algebra.big_operators\n\nopen classical multiset finset\nlocal attribute [instance] prop_decidable\n\nuniverse u\nvariable α : Type u\n\n\nlemma eq_zero_iff_to_finset_eq_empty {g : multiset α} : g = 0 ↔ g.to_finset = ∅ :=\nbegin\n  apply iff.intro,\n  {\n    intro h1,\n    rw finset.ext,\n    intro a,\n    simp [*]\n  },\n  {\n    intro h1,\n    by_contradiction h2,\n    rcases (exists_mem_of_ne_zero h2) with ⟨m, h3⟩,\n    rw [←mem_to_finset, h1] at h3,\n    have : ¬ m ∈ ∅,\n      from finset.not_mem_empty m,\n    contradiction\n  }\nend\n\nlemma prod_ne_zero_of_forall_mem_ne_zero' {β : Type u} [has_zero α] [integral_domain β] {f : finset α } {g : α → β}\n  (ha : ∀ x : α, x ≠ 0 → g x ≠ 0) (hb : (0 : β) ≠ 1) : (∀ x ∈ f, x ≠ (0 :α)) → (finset.prod f g ≠ 0) :=\nbegin\n apply finset.induction_on f,\n  {\n    simp *,\n  },\n  {\n    intros a s h1 h2 h3,\n    have h4 : (∀ (x : α), x ∈ s → x ≠ 0),\n    {\n      intros x h4,\n      simp *,\n    },\n    have h5 : finset.prod s g ≠ 0,\n      from h2 h4,\n    have h6 : a ≠ 0,\n    {\n      apply h3,\n      simp,\n    },\n    have h7 : g a ≠ 0,\n      from ha _ h6,\n    rw finset.prod_insert h1,\n    exact mul_ne_zero h7 h5,\n  }\nend\n", "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_finset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7741786691074332}}
{"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.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 `Λ`.\n\nWe then prove the classical summation property of the von Mangoldt function in\n`nat.arithmetic_function.von_mangoldt_sum`, that `∑ i in n.divisors, Λ i = real.log n`, and use this\nto deduce alternative expressions for the von Mangoldt function via Möbius inversion, see\n`nat.arithmetic_function.sum_moebius_mul_log_eq`.\n\n## Notation\n\nWe use the standard notation `Λ` 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 `ℕ → ℝ`. 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 ℝ :=\n⟨λ n, real.log n, by simp⟩\n\n@[simp] lemma log_apply {n : ℕ} : 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 `Λ` for this function.\n-/\nnoncomputable def von_mangoldt : arithmetic_function ℝ :=\n⟨λ n, if is_prime_pow n then real.log (min_fac n) else 0, if_neg not_is_prime_pow_zero⟩\n\nlocalized \"notation `Λ` := nat.arithmetic_function.von_mangoldt\" in arithmetic_function\n\nlemma von_mangoldt_apply {n : ℕ} :\n  Λ n = if is_prime_pow n then real.log (min_fac n) else 0 := rfl\n\n@[simp] lemma von_mangoldt_apply_one : Λ 1 = 0 := by simp [von_mangoldt_apply]\n\n@[simp] lemma von_mangoldt_nonneg {n : ℕ} : 0 ≤ Λ 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 : ℕ} (hk : k ≠ 0) : Λ (n ^ k) = Λ n :=\nby simp only [von_mangoldt_apply, is_prime_pow_pow_iff hk, pow_min_fac hk]\n\nlemma von_mangoldt_apply_prime {p : ℕ} (hp : p.prime) : Λ 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\nlemma von_mangoldt_ne_zero_iff {n : ℕ} : Λ n ≠ 0 ↔ is_prime_pow n :=\nbegin\n  rcases eq_or_ne n 1 with rfl | hn, { simp [not_is_prime_pow_one] },\n  exact (real.log_pos (one_lt_cast.2 (min_fac_prime hn).one_lt)).ne'.ite_ne_right_iff\nend\n\nlemma von_mangoldt_pos_iff {n : ℕ} : 0 < Λ n ↔ is_prime_pow n :=\nvon_mangoldt_nonneg.lt_iff_ne.trans (ne_comm.trans von_mangoldt_ne_zero_iff)\n\nlemma von_mangoldt_eq_zero_iff {n : ℕ} : Λ n = 0 ↔ ¬is_prime_pow n :=\nvon_mangoldt_ne_zero_iff.not_right\n\nopen_locale big_operators\n\nlemma von_mangoldt_sum {n : ℕ} :\n  ∑ i in n.divisors, Λ 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, ←sum_filter] at ha hb ⊢,\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')],\nend\n\n@[simp] lemma von_mangoldt_mul_zeta : Λ * ζ = log :=\nby { ext n, rw [coe_mul_zeta_apply, von_mangoldt_sum], refl }\n\n@[simp] lemma zeta_mul_von_mangoldt : (ζ : arithmetic_function ℝ) * Λ = log :=\nby { rw [mul_comm], simp }\n\n@[simp] \n\n@[simp] lemma moebius_mul_log_eq_von_mangoldt : (μ : arithmetic_function ℝ) * log = Λ :=\nby { rw [mul_comm], simp }\n\nlemma sum_moebius_mul_log_eq {n : ℕ} :\n  ∑ d in n.divisors, (μ d : ℝ) * log d = - Λ n :=\nbegin\n  simp only [←log_mul_moebius_eq_von_mangoldt, mul_comm log, mul_apply, log_apply, int_coe_apply,\n    ←finset.sum_neg_distrib, neg_mul_eq_mul_neg],\n  rw sum_divisors_antidiagonal (λ i j, (μ i : ℝ) * -real.log j),\n  have : ∑ (i : ℕ) in n.divisors, (μ i : ℝ) * -real.log (n / i : ℕ) =\n         ∑ (i : ℕ) in n.divisors, ((μ i : ℝ) * real.log i - μ 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 : ℝ) ≠ 0,\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, ←sum_mul, ←int.cast_sum, ←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;\n  simp [hn],\nend\n\nlemma von_mangoldt_le_log : ∀ {n : ℕ}, Λ n ≤ real.log (n : ℝ)\n| 0 := by simp\n| (n+1) :=\n  begin\n    rw ←von_mangoldt_sum,\n    exact single_le_sum (λ _ _, von_mangoldt_nonneg) (mem_divisors_self _ n.succ_ne_zero),\n  end\n\nend arithmetic_function\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/von_mangoldt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8418256432832332, "lm_q1q2_score": 0.774178669107433}}
{"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 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.Fintype.Units\n\n/-!\n# Some facts about finite rings\n-/\n\n\nopen Classical\n\ntheorem card_units_lt (M₀ : Type _) [MonoidWithZero M₀] [Nontrivial M₀] [Fintype M₀] :\n    Fintype.card M₀ˣ < Fintype.card M₀ :=\n  Fintype.card_lt_of_injective_of_not_mem Units.val Units.ext not_isUnit_zero\n#align card_units_lt card_units_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/RingTheory/Fintype.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7741785811632578}}
{"text": "import analysis.special_functions.exp\nimport analysis.special_functions.log.basic\n\n/- Tactics you may consider\n-apply\n-exact\n-have\n-norm_num: deals with numerical expressions \n-/\n\nopen real\nvariables a b c d e : ℝ\n\n#check le_refl\n#check le_refl b\n#check add_pos\n#check add_le_add\n#check add_le_add_left\n#check exp_pos\n#check exp_pos d\n#check exp_le_exp.mpr\n#check log_le_log\n\n-- BEGIN\nexample (h₀ : d ≤ e) : c + exp (a + d) ≤ c + exp (a + e) :=\nbegin\n  apply add_le_add,\n    apply le_refl c,\n    apply exp_le_exp.mpr,\n  apply add_le_add,\n   apply le_refl a,\n   apply h₀,\nend\n\nexample : (0 : ℝ) < 1 :=\nby norm_num\n\nexample (h : a ≤ b) : log (1 + exp a) ≤ log (1 + exp b) :=\nbegin\n  have h₀ : 0 < 1 + exp a,\n  { apply add_pos, \n    norm_num, \n    exact exp_pos a},\n  have h₁ : 0 < 1 + exp b,\n  { apply add_pos, \n    norm_num, \n    exact exp_pos b},\n  apply (log_le_log h₀ h₁).mpr,\n   { apply add_le_add_left, \n    apply exp_le_exp.mpr 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/ex5_apply_le_exp_log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314624993576758, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7741785787339033}}
{"text": "import game.max.level05 -- hide\n\nopen_locale classical -- hide\n\nnoncomputable theory -- hide\n\nnamespace xena -- hide\n\n/-\n# Chapter ? : 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 ≤ z` and you have a hypothesis `h : y ≤ z`\nthen of course it will suffice to prove `x ≤ y` and then you\ncan use transitivity. Instead of `have hxy : x ≤ 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 ≤ 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 : ℝ} : a ≤ c ∧ b ≤ c ↔ max a b ≤ c :=\nbegin\n  split,\n  { intro h,\n    cases h with hac hbc,\n    exact max_le hac hbc\n  },\n  { intro habc,\n    split,\n    { apply le_trans _ habc,\n      apply le_max_left},\n    { apply le_trans _ habc,\n      apply le_max_right\n    }\n  }\nend\n\nend xena --hide\n\n/- Hint : Solution\n  split,\n  { intro h,\n    cases h with hac hbc,\n    exact max_le hac hbc\n  },\n  { intro habc,\n    split,\n    { apply le_trans _ habc,\n      apply le_max_left},\n    { apply le_trans _ habc,\n      apply le_max_right\n    }\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/max/level06.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7741690858604063}}
{"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\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 + √(2n)`.\n\n# Solution\nWe first prove the following lemma: for every prime `p > 20`, satisfying `p ≡ 1 [MOD 4]`,\nthere exists `n ∈ ℕ` such that `p ∣ n^2 + 1` and `p > 2n + √(2n)`. Then the statement of the\nproblem follows from the fact that there exist infinitely many primes `p ≡ 1 [MOD 4]`.\n\nTo prove the lemma, notice that `p ≡ 1 [MOD 4]` implies `∃ n ∈ ℕ` such that `n^2 ≡ -1 [MOD p]`\nand we can take this `n` such that `n ≤ p/2`. Let `k = p - 2n ≥ 0`. Then we have:\n`k^2 + 4 = (p - 2n)^2 + 4 ≣ 4n^2 + 4 ≡ 0 [MOD p]`. Then `k^2 + 4 ≥ p` and so `k ≥ √(p - 4) > 4`.\nThen `p = 2n + k ≥ 2n + √(p - 4) = 2n + √(2n + k - 4) > √(2n)` and we are done.\n-/\n\nopen real\n\nlemma p_lemma (p : ℕ) (hpp : nat.prime p) (hp_mod_4_eq_1 : p ≡ 1 [MOD 4]) (hp_gt_20 : p > 20) :\n  ∃ n : ℕ, p ∣ n ^ 2 + 1 ∧ (p : ℝ) > 2 * n + sqrt(2 * n) :=\nbegin\n  haveI := fact.mk hpp,\n  have hp_mod_4_ne_3 : p % 4 ≠ 3, { linarith [(show p % 4 = 1, by exact hp_mod_4_eq_1)] },\n  obtain ⟨y, hy⟩ := (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₁ : p ∣ 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₂ : n ≤ p / 2 := zmod.nat_abs_val_min_abs_le y,\n  have hnat₃ : p ≥ 2 * n, { linarith [nat.div_mul_le_self p 2] },\n\n  set k : ℕ := p - 2 * n with hnat₄,\n\n  have hnat₅ : p ∣ k ^ 2 + 4,\n  { cases hnat₁ with x hx,\n    let p₁ := (p : ℤ), let n₁ := (n : ℤ), let k₁ := (k : ℤ), let x₁ := (x : ℤ),\n    have : p₁ ∣ k₁ ^ 2 + 4,\n    { use p₁ - 4 * n₁ + 4 * x₁,\n      have hcast₁ : k₁ = p₁ - 2 * n₁, { assumption_mod_cast },\n      have hcast₂ : n₁ ^ 2 + 1 = p₁ * x₁, { assumption_mod_cast },\n      calc  k₁ ^ 2 + 4\n          = (p₁ - 2 * n₁) ^ 2 + 4                   : by rw hcast₁\n      ... = p₁ ^ 2 - 4 * p₁ * n₁ + 4 * (n₁ ^ 2 + 1) : by ring\n      ... = p₁ ^ 2 - 4 * p₁ * n₁ + 4 * (p₁ * x₁)    : by rw hcast₂\n      ... = p₁ * (p₁ - 4 * n₁ + 4 * x₁)             : by ring },\n    assumption_mod_cast },\n\n  have hnat₆ : k ^ 2 + 4 ≥ p := nat.le_of_dvd (k ^ 2 + 3).succ_pos hnat₅,\n\n  let p₀ := (p : ℝ), let n₀ := (n : ℝ), let k₀ := (k : ℝ),\n\n  have hreal₁ : p₀ = 2 * n₀ + k₀, { linarith [(show k₀ = p₀ - 2 * n₀, by assumption_mod_cast)] },\n  have hreal₂ : p₀ > 20,          { assumption_mod_cast },\n  have hreal₃ : k₀ ^ 2 + 4 ≥ p₀,  { assumption_mod_cast },\n\n  have hreal₄ : k₀ ≥ sqrt(p₀ - 4),\n  { calc k₀ = sqrt(k₀ ^ 2) : eq.symm (sqrt_sq (nat.cast_nonneg k))\n    ...     ≥ sqrt(p₀ - 4) : sqrt_le_sqrt (by linarith [hreal₃]) },\n\n  have hreal₅ : k₀ > 4,\n  { calc k₀ ≥ sqrt(p₀ - 4) : hreal₄\n    ...     > sqrt(4 ^ 2)  : (sqrt_lt (by linarith)).mpr (by linarith [hreal₂])\n    ...     = 4            : sqrt_sq (by linarith) },\n\n  have hreal₆ : p₀ > 2 * n₀ + sqrt(2 * n),\n  { calc p₀ = 2 * n₀ + k₀                    : hreal₁\n    ...     ≥ 2 * n₀ + sqrt(p₀ - 4)          : by linarith [hreal₄]\n    ...     = 2 * n₀ + sqrt(2 * n₀ + k₀ - 4) : by rw hreal₁\n    ...     > 2 * n₀ + sqrt(2 * n₀)     : by { refine add_lt_add_left _ (2 * n₀),\n                                               refine (sqrt_lt _).mpr _,\n                                               refine mul_nonneg zero_le_two (nat.cast_nonneg n),\n                                               linarith [hreal₅] } },\n\n  exact ⟨n, hnat₁, hreal₆⟩,\nend\n\ntheorem imo2008_q3 : ∀ N : ℕ, ∃ n : ℕ, n ≥ N ∧\n  ∃ p : ℕ, nat.prime p ∧ p ∣ n ^ 2 + 1 ∧ (p : ℝ) > 2 * n + sqrt(2 * n) :=\nbegin\n  intro N,\n  obtain ⟨p, hpp, hineq₁, hpmod4⟩ := nat.exists_prime_ge_modeq_one 4 (N ^ 2 + 21) zero_lt_four,\n  obtain ⟨n, hnat, hreal⟩ := p_lemma p hpp hpmod4 (by linarith [hineq₁, nat.zero_le (N ^ 2)]),\n\n  have hineq₂  : n ^ 2 + 1 ≥ p := nat.le_of_dvd (n ^ 2).succ_pos hnat,\n  have hineq₃  : n * n ≥ N * N, { linarith [hineq₁, hineq₂, (sq n), (sq N)] },\n  have hn_ge_N : n ≥ N := nat.mul_self_le_mul_self_iff.mpr hineq₃,\n\n  exact ⟨n, hn_ge_N, p, hpp, hnat, hreal⟩,\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_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7741690822101522}}
{"text": "import ..lectures.love12_basic_mathematical_structures_demo\n\n\n/-! # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Type Classes\n\nRecall the inductive type `btree` we introduced earlier: -/\n\n#check btree\n\n/-! The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/-! 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [btree.graft, ih_l, ih_r] }\nend\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    simp [btree.graft, ih_l, ih_r] }\nend\n\n/-! 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\n{ add       := btree.graft,\n  add_assoc := btree.graft_assoc,\n  zero      := btree.empty,\n  add_zero  := btree.graft_empty,\n  zero_add  := by intro x; refl }\n\n/-! 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/-! No matter how we define `neg` (`-`), we will not be able to prove\n`add_left_neg`, which amounts to the following property:\n\n    `∀t, btree.graft (btree.neg t) t = btree.empty`\n\nHowever, if `t` is a nonempty tree, `btree.graft _ t` cannot possibly be equal\nto `btree.empty`, no matter what the first argument is. -/\n\n/-! 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀y : btree ℕ, btree.graft y x ≠ btree.empty :=\nbegin\n  apply exists.intro (btree.node 0 btree.empty btree.empty),\n  intros y hy,\n  cases' y,\n  { cases' hy },\n  { cases' hy }\nend\n\n\n/-! ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/-! 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    rw multiset.elems,\n    rw mirror,\n    rw ←ih_l,\n    rw ←ih_r,\n    rw multiset.elems,\n    cc }\nend\n\n/-! 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nbegin\n  induction' t,\n  case empty {\n    refl },\n  case node : a l r ih_l ih_r {\n    rw finset.elems,\n    rw mirror,\n    rw ←ih_l,\n    rw ←ih_r,\n    rw finset.elems,\n    cc }\nend\n\n/-! 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nbtree.node 0 (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\nend\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/love12_basic_mathematical_structures_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529791457032, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7741528163509779}}
{"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 combinatorics.simple_graph.connectivity -- paths, cycles etc in graph theory\n\n/-\n\nCut and pasted directly from the module docstring from the file imported above:\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(and then there's a warning that in topology some of these words are\nused to mean different things)\n\nSo of course the question is how to actually do this in Lean. Here's how.\nLet `G` be a simple graph with vertex set `V`, and say `v,w,x` in `V`\n\n-/\n\nvariables (V : Type) (G : simple_graph V) (v w x : V)\n\n-- The type of all walks from `v` to `w`\n\nexample : Type := G.walk v w\n\n-- The empty walk from `v` to `v`\n\nexample : G.walk v v := simple_graph.walk.nil' v\n\n-- oh that's a bit annoying, let's open `simple_graph`\n\nopen simple_graph\n\nexample : G.walk v v := walk.nil' v\n\n-- Add an edge to the beginning of a walk\n\nexample (h : G.adj v w) (a : G.walk w x) : G.walk v x := walk.cons' v w x h a \n\n-- There's also walk.cons where you don't have to specify the vertices\n\nexample (h : G.adj v w) (a : G.walk w x) : G.walk v x := walk.cons h a \n\n-- concatenation of walks\n\nexample (a : G.walk v w) (b : G.walk w x) : G.walk v x := a.append b\n\n-- Let `a` be a walk from `v` to `w`\n\nvariable (a : G.walk v w)\n\n-- length of `a` is a natural\n\nexample : ℕ := a.length\n\n-- reverse of `a`\n\nexample : G.walk w v := a.reverse\n\n-- n'th vertex visited in `a`\n\nexample (n : ℕ) : V := a.get_vert n\n\n-- 0'th vertex is where we start\n\nexample : a.get_vert 0 = v := walk.get_vert_zero a\n\n-- (Walk length)'th vertex is where we end.\n\nexample : a.get_vert a.length = w := walk.get_vert_length a\n\n-- Support of `a` is the list of vertices it goes through\n\nexample : list V := a.support\n\n-- Edges of `a` is the list of edges it goes through\n\nexample : list (sym2 V) := a.edges\n\n-- A walk is a *trail* if it has no repeating edges.\n\nexample : Prop := a.is_trail\n\n-- A walk is a *path* if it has no repeating vertices.\n\nexample : Prop :=  a.is_path\n\n-- Paths are sufficiently common that `G.path v w` is defined to be the\n-- subtype `{p : G.walk v w // p.is_path}`. So to give a term of type `G.path v w`\n-- is to give a pair consisting of a walk `p : G.walk v w` and a proof of `p.is_path`.\n\n-- A walk is a *circuit* at `v : V` if it's a nonempty trail beginning and ending at `v`.\n\nexample (b : G.walk v v) : Prop := b.is_circuit\n\n-- A walk is a *cycle* at `v : V` if it's a circuit at `v` whose only repeating vertex\n-- is `v` (which appears exactly twice).\n\nexample (b : G.walk v v) : Prop := b.is_cycle\n\n-- Exercise : give an example of a circuit which isn't a cycle. Can you do it in Lean?\n-- Remark: a Lean solution is in the solutions.\n\n-- Example theorem in the API: given a walk `p` from `v` to `u` and an edge from `u` to `v`,\n-- putting them together gives a cycle iff `p` is a path and the edge from `u` to `v`\n-- is not in the edges of `p`.\n\nexample {u v : V} (p : G.walk v u) (h : G.adj u v) :\n  (walk.cons h p).is_cycle ↔ p.is_path ∧ ¬ ⟦(u, v)⟧ ∈ p.edges :=\nwalk.cons_is_cycle_iff p h\n\n-- Given a walk from `v` to `w` and a vertex `u` in the support of the walk,\n-- truncate the walk so it starts at `v` and finishes at `u`.\n\nopen_locale classical\nnoncomputable theory -- don't ask me\n\nexample (a : G.walk v w) (u : V) (hu : u ∈ a.support) : G.walk v u :=\na.take_until u hu\n\n-- With the same hypotheses, return the rest of the walk from `u` to `w`\nexample (a : G.walk v w) (u : V) (hu : u ∈ a.support) : G.walk u w :=\na.drop_until u hu\n\n-- Example in the API : those two walks added together give the original\n-- walk again\n\nexample (a : G.walk v w) (u : V) (hu : u ∈ a.support) :\n(a.take_until u hu).append (a.drop_until u hu) = a := walk.take_spec a hu\n\n-- Two vertices `u` and `v` satisfy `G.reachable u v : Prop` if there's a walk from `u` to `v`.\nexample : G.reachable v w ↔ nonempty (G.walk v w) := iff.rfl -- true by definition\n\n-- Can you show that `G.reachable` is an equivalence relation?\nexample : equivalence (G.reachable) :=\nbegin\n  sorry,\nend\n\n-- A graph is \"preconnected\" if `G.reachable v w` is true for any `v w : V`.\n-- Note that this includes the empty graph with `V` empty, for silly logic reasons.\n\nexample : G.preconnected ↔ ∀ v w : V, G.reachable v w := iff.rfl -- true by definition\n\n-- A graph is connected iff it's preconnected and nonempty.\n\nexample : G.connected ↔ G.preconnected ∧ nonempty V :=\nbegin\n  exact connected_iff G,\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/section18graph_theory/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7740995580873115}}
{"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.section06quotients.sheet2zmod37\n\n/-!\n\n# Z/37 is a ring\n\n(or an additive abelian group if you only get half way through the sheet)\n\n-/\n\nnamespace Zmod\n\n-- We already defined negation but right now it's called `neg`. \n-- Let's set up notation for it so we can call it `-`.\n\ninstance : has_neg Zmod37 :=\n{ neg := neg }\n\n-- Now we can talk about `-⟦a⟧` and Lean will interpret it as `neg ⟦a⟧`.\n\n-- Let's train the simplifier to push everything into\n-- the brackets\n@[simp] lemma neg_def (a : ℤ) : -⟦a⟧ = ⟦-a⟧ :=\nbegin\n  refl\nend\n\n-- Let's also define notation for zero\ninstance : has_zero Zmod37 :=\n{ zero := ⟦0⟧ }\n\n\n@[simp] lemma zero_def : (0 : Zmod37) = ⟦0⟧ :=\nbegin\n  refl\nend\n\n/-\n\n## Maps X → X → X\n\nWe're trying to make `Zmod37` into an additive group; we've defined\nthe additive unit `0` and additive inverse `-`; we still need to \ndefine the group law `+` though. The type of `+` will be\n`Zmod37 → Zmod37 → Zmod37` and this might look a bit weird, so let\nme just spell it out. We usually think of addition as a function\nwhich eats two elements of an additive group `G` and returns another\nelement. But here what we're going to do is to think of addition\nas a function `g + _` which eats *one* element `g` and returns a\nfunction `G → G`, namely the function which adds `g` to its input.\nWith this way of thinking about it, addition is a function\nfrom `Zmod37` to the type of functions from `Zmod37` to `Zmod37`,\nand this latter type is called `Zmod37 → Zmod37`. So, putting\nit all together, addition has type `Zmod37 → (Zmod37 → Zmod37)`,\nand because `→` is right associative in Lean we can write this\nas `Zmod37 → Zmod37 → Zmod37` (indeed, that's what \"right associative\" means).\n\n-/\n\n-- We define addition using a function in the library called `quotient.map₂`\n-- which will descend a term of type `ℤ → ℤ → ℤ` to a term of type\n-- `Zmod37 → Zmod37 → Zmod37`. We descend addition on the integers.\n-- To make this work (to check it's a \"well-defined definition\") we need to prove\n-- a theorem, hence this starts as a definition and ends up as a proof of a theorem.\n\ndef add : Zmod37 → Zmod37 → Zmod37 :=\nquotient.map₂ (λ a b, a + b) begin\n  rintros a1 a2 ⟨x, hx⟩ b1 b2 ⟨y, hy⟩,\n  refine ⟨x + y, _⟩,\n  simp [mul_add, ← hx, ← hy],\n  ring,\nend\n\ninstance : has_add Zmod37 :=\n{ add := add }\n\n@[simp] lemma add_def (a b : ℤ) : ⟦a⟧ + ⟦b⟧ = ⟦a + b⟧ :=\nbegin\n  refl\nend\n\n/-\n\n## `quotient.induction_on`\n\nThe one thing I've not told you about is a really nice way of \nreducing questions about `Zmod37` to equations about integers.\nSure you can use `surjective_quotient_mk` but there's a much\nnicer way; you can do \"induction on the terms of the quotient\".\nLet me do this first one for you, to give you the idea of\nhow to do these simply.\n\n-/\nlemma add_zero (z : Zmod37) : z + 0 = z :=\nbegin\n  -- A question about Zmod37, a type we're in the middle of building\n  -- an API for.\n  apply quotient.induction_on z, clear z,\n  -- Still a question about Zmod37, but now all our variables\n  -- are integers,\n  intro a,\n  change ⟦a + 0⟧ = ⟦a⟧,\n  -- There are now two approaches. You can either `apply quotient.sound`\n  -- to turn it into a question about integers, where we can use\n  -- all the usual tactics like `ring`, or you can see how far\n  -- the simplifier gets, because we've been training it to\n  -- do questions like these.\n  -- We told it `0 = ⟦0⟧` and `⟦a⟧ + ⟦b⟧ = ⟦a + b⟧`.\n  -- In this case, the simplifier can do it.\n  simp,\n  -- If it can't do it, try applying `quotient.sound` and\n  -- then perhaps `dsimp` to get rid of the lambdas.\nend\n\n-- I'll give you the first line for this one.\nlemma add_comm (y z : Zmod37) : y + z = z + y :=\nbegin\n  apply quotient.induction_on₂ y z, clear y z,\n  intros,\n  simp [add_comm],\nend\n\n-- See if you can prove the remaining axioms for an additive abelian group yourself.\n-- We name this instance `Zmod.add_comm_group` and we'll use it later on.\ninstance add_comm_group : add_comm_group Zmod37 :=\n{ add := (+),\n  zero := 0,\n  neg := has_neg.neg,\n  add_assoc := begin\n    intros,\n    apply quotient.induction_on₃ a b c, clear a b c,\n    intros,\n    simp [add_assoc],\n  end,\n  zero_add := begin\n    intro z, apply quotient.induction_on z, clear z,\n    intros, simp,\n  end,\n  add_zero := add_zero,\n  add_left_neg := begin\n    intro z, apply quotient.induction_on z, clear z,\n     intros, simp,\n  end,\n  add_comm := add_comm }\n\n-- Bonus points: see if you can make it a ring!\n-- The rest of this file introduces no new techniques; all it offers\n-- you is the satisfaction of proving that ℤ/37ℤ is a ring by yourself.\n\ninstance : has_one Zmod37 :=\n{ one := ⟦1⟧ }\n\n@[simp] lemma one_def : (1 : Zmod37) = ⟦1⟧ :=\nbegin\n  refl\nend\n\ndef mul : Zmod37 → Zmod37 → Zmod37 :=\nquotient.map₂ (λ x y, x * y) begin\n  -- tricky!\n  rintros a1 a2 ⟨a, ha⟩ b1 b2 ⟨b, hb⟩,\n  dsimp,\n  use a * b1 + b * a2,\n  rw [mul_add, ← mul_assoc, ← mul_assoc, ← ha, ← hb],\n  ring,\nend\n\n-- notation for multiplcation\ninstance : has_mul Zmod37 :=\n{ mul := mul }\n\n@[simp] lemma mul_def (a b : ℤ) : ⟦a⟧ * ⟦b⟧ = ⟦a * b⟧ :=\nbegin\n  refl\nend\n\ninstance : comm_ring Zmod37 :=\n{ \n  mul := (*),\n  add := (+),\n  mul_assoc := begin\n    intros,\n    apply quotient.induction_on₃ a b c, clear a b c,\n    intros,\n    simp [mul_assoc],\n  end,\n  one := 1,\n  one_mul := begin\n    intro z, apply quotient.induction_on z, clear z,\n    intros, simp,\n  end,\n  mul_one := begin\n    intro z, apply quotient.induction_on z, clear z,\n    intros, simp,\n  end,\n  left_distrib := begin\n    intros,\n    apply quotient.induction_on₃ a b c, clear a b c,\n    intros,\n    simp [left_distrib],\n  end,\n  right_distrib := begin\n    intros,\n    apply quotient.induction_on₃ a b c, clear a b c,\n    intros,\n    simp [right_distrib],\n  end,\n  mul_comm := begin\n  intros,\n  apply quotient.induction_on₂ a b, clear a b,\n  intros,\n  simp [mul_comm],\nend,\n  -- the rest of the ring axioms are the axioms for an additive abelian group,\n  -- and we did those already.\n  ..Zmod.add_comm_group }\nend Zmod\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/section06quotients/sheet3ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.774079643107375}}
{"text": "import data.nat.choose\nimport data.set\nimport data.set.finite\nimport data.multiset\nimport data.finset\nimport data.list\nimport data.finset algebra.big_operators\nimport algebra.big_operators\nimport init.algebra.functions\nimport algebra.group_power\n#eval choose 5 4\n#check nat.rec_on\n\n/- Collaboration between\n   Travis Hance (thance)\n   Katherine Cordwell (kcordwell)\n-/\n\n/- Following the proof at https://artofproblemsolving.com/wiki/index.php/Combinatorial_identity -/\n\n/- sum_for_hockey_stick takes r and k and computes the sum from i = r \nto i = r + k of (i choose r) -/\ndef sum_for_hockey_stick (r k : ℕ) : ℕ := \nnat.rec_on k 1 (λ k ih, ih + (choose (r + k + 1) r))\n\n#eval sum_for_hockey_stick  5 0 /- this is really saying 5 choose 5 is 1 -/\n\n#eval sum_for_hockey_stick 5 1 /- this is saying 5 choose 5 + 6 choose 5 is 7 -/\n#eval choose 7 6\n\n#eval sum_for_hockey_stick 5 2 /- calculates 5 choose 5 + 6 choose 5 + 7 choose 5-/\n#eval choose 8 6\n\n#eval sum_for_hockey_stick 5 3 /- calculates 5 choose 5 + 6 choose 5 + 7 choose 5 + 8 choose 5-/\n#eval choose 9 6\n\n/- Says that for natural numbers r and n, if n >= r, then the sum from i = r to n \nof i choose r equals n + 1 choose r + 1 -/\ntheorem hockey_stick_identity (k r : ℕ) :\nsum_for_hockey_stick r k = (choose (r + k + 1) (r + 1)) :=\nbegin\ninduction k with k ih,\n{have h: sum_for_hockey_stick r 0 = 1, by refl,\nsimp[*, refl]},\n{\n    calc sum_for_hockey_stick r (nat.succ k) \n        = (sum_for_hockey_stick r k) + (choose (r + k + 1) r): by simp[sum_for_hockey_stick]\n    ... = (choose (r + k + 1) (r + 1)) + (choose (r + k + 1) r) : by rw[ih]\n    ... = (choose (r + k + 1) r) + (choose (r + k + 1) (r + 1)): by simp\n    ... = choose (r + k + 1) r + choose (r + k + 1) (nat.succ r) : by refl\n    ... = choose (r + k + 1 + 1) (r + 1) : by rw[←choose]\n}\nend\n\n/- Here is my first attempt at stating Vandermonde's identity.\n Vandermonde's identity says that m + n choose r equals the \nsum from k = 0 to r of (m choose k)*(n choose r - k).  I tried to do\nan inductive proof as at https://math.stackexchange.com/questions/219928/inductive-proof-for-vandermondes-identity/219938,\nbut this was not so good because the induction was on both n and r, and it got fairly messy.\nSo I decided to try a different approach (see below).\n-/\ndef sum_for_vandermonde (m n r i: ℕ) : ℕ :=\nnat.rec_on i ((choose m 0)*(choose n r)) \n(λ i ih, ih + (choose m (i + 1))*(choose n (r - (i + 1))))\n\n#eval sum_for_vandermonde  3 4 6 6\n#eval choose (3 + 4) 6\n\n#eval sum_for_vandermonde 12 5 8 8\n#eval choose (12 + 5) 8\n\n/- double-checked with Mathematica -/\n#eval sum_for_vandermonde 12 5 8 3\n#eval sum_for_vandermonde  3 4 6 5\n\nlemma sum_for_vandermonde_with_n_is_zero (m r: ℕ) : sum_for_vandermonde m 0 r r = choose m r := \nbegin\ninduction r with r ih,\n{\n   calc \n    sum_for_vandermonde m 0 0 0 = (choose m 0)*(choose 0 0) : by refl\n    ... = choose m 0 : by simp\n    },\ncalc \n    sum_for_vandermonde m 0 (nat.succ r) (nat.succ r) = sorry : sorry\n    ... = choose m (nat.succ r): sorry\nend\n\ntheorem vandermonde_identity (m n : ℕ) :\n∀ r : ℕ, sum_for_vandermonde m n r r = choose (m + n) r := \nbegin\ninduction n with n ih1,\n{simp[choose, sum_for_vandermonde_with_n_is_zero]},\nintro r, simp[sum_for_vandermonde, choose], sorry\nend\n\n\n/- Next I decided to restate Vandermonde's theorem using big_ops and started on\nthe algebraic proof of Vandermonde's as found on Wikipedia: \nhttps://en.wikipedia.org/wiki/Vandermonde%27s_identity.  I proved the first few\nsteps but ended up spending time on some other parts of the project and didn't finish. -/\n\n/- Lemma for a case of using the binomial theorem -/\nvariables x y : ℕ \nlemma binomial_theorem_with_1 (x n : ℕ) : \n    ∀ n : ℕ, (x + 1)^n = (finset.range (nat.succ n)).sum (λ m, x ^ m * choose n m) :=\n    begin\n    intro n,\n    have h3 := add_pow x 1 n,\n    simp at h3, apply h3\n    end \n\n /-show sum from r = 0 to m + n (m + n choose r) x^r = (1 + x)^(m + n) = (\n     1 + x)^m = (1 + x)^n = (scary) * (scary) -/\n#check pow_add\nlemma binomial_theorem_for_vandermonde (x m n : ℕ) :\n    ∀ n m: ℕ, (finset.range (m + nat.succ n)).sum(λ r, x^r * (choose (m + n) r)) \n        = (finset.range (nat.succ m)).sum(λ r, x^r * \n        choose m r)*(finset.range (nat.succ n)).sum(λ r, x^r * choose n r) :=\n    begin\n        intros n m,\n        have h := pow_add (x + 1) m n,\n        have h1 : n + m = m + n, by simp[add_comm],\n        simp at h,\n        rw h1 at h,\n        calc \n        (finset.range (m + nat.succ n)).sum(λ r, x^r * (choose (m + n) r)) = \n                (x + 1)^(m + n): by rw ← binomial_theorem_with_1 x (m + nat.succ n)\n        ... = (x + 1)^m * (x + 1)^n: h\n        ... = (finset.range (nat.succ m)).sum(λ r, x^r * choose m r) * (x + 1)^n: by rw binomial_theorem_with_1 x (nat.succ m)\n        ... = (finset.range (nat.succ m)).sum(λ r, x^r * \n        choose m r)*(finset.range (nat.succ n)).sum(λ r, x^r * choose n r) : by rw binomial_theorem_with_1 x (nat.succ n)\n    end\n\n/- Vandermonde's identity (restated) -/\ntheorem vandermonde_thm (m n r : ℕ) :\n∀ r : ℕ, (finset.range (nat.succ r)).sum(λ k, (choose m k)*(choose n (r-k)))= choose (m + n) r := \nbegin\nsorry\nend", "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/hockeystick.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336302, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.773953547688372}}
{"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.order\n\n/-!\n# Definitions and properties of `gcd`, `lcm`, and `coprime`\n\n-/\n\nnamespace nat\n\n/-! ### `gcd` -/\n\ntheorem gcd_dvd (m n : ℕ) : (gcd m n ∣ m) ∧ (gcd m n ∣ n) :=\ngcd.induction m n\n  (λn, by rw gcd_zero_left; exact ⟨dvd_zero n, dvd_refl n⟩)\n  (λm n npos, by rw ←gcd_rec; exact λ ⟨IH₁, IH₂⟩, ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩)\n\ntheorem gcd_dvd_left (m n : ℕ) : gcd m n ∣ m := (gcd_dvd m n).left\n\ntheorem gcd_dvd_right (m n : ℕ) : gcd m n ∣ n := (gcd_dvd m n).right\n\ntheorem gcd_le_left {m} (n) (h : 0 < m) : gcd m n ≤ m := le_of_dvd h $ gcd_dvd_left m n\n\ntheorem gcd_le_right (m) {n} (h : 0 < n) : gcd m n ≤ n := le_of_dvd h $ gcd_dvd_right m n\n\ntheorem dvd_gcd {m n k : ℕ} : k ∣ m → k ∣ n → k ∣ gcd m n :=\ngcd.induction m n (λn _ kn, by rw gcd_zero_left; exact kn)\n  (λn 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 : ℕ} : k ∣ gcd m n ↔ k ∣ m ∧ k ∣ n :=\niff.intro (λ h, ⟨h.trans (gcd_dvd m n).left, h.trans (gcd_dvd m n).right⟩)\n          (λ h, dvd_gcd h.left h.right)\n\ntheorem gcd_comm (m n : ℕ) : 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 : ℕ} : m ∣ n ↔ gcd m n = m :=\n⟨λ h, by rw [gcd_rec, mod_eq_zero_of_dvd h, gcd_zero_left],\n λ h, h ▸ gcd_dvd_right m n⟩\n\ntheorem gcd_eq_right_iff_dvd {m n : ℕ} : m ∣ n ↔ gcd n m = m :=\nby rw gcd_comm; apply gcd_eq_left_iff_dvd\n\ntheorem gcd_assoc (m n k : ℕ) : 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 : ℕ) : gcd n 1 = 1 :=\neq.trans (gcd_comm n 1) $ gcd_one_left n\n\ntheorem gcd_mul_left (m n k : ℕ) : gcd (m * n) (m * k) = m * gcd n k :=\ngcd.induction n k\n  (λk, by repeat {rw mul_zero <|> rw gcd_zero_left})\n  (λk n H IH, by rwa [←mul_mod_mul_left, ←gcd_rec, ←gcd_rec] at IH)\n\ntheorem gcd_mul_right (m n k : ℕ) : 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 : ℕ} (n : ℕ) (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 : ℕ) {n : ℕ} (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 : ℕ} (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 : ℕ} (H : gcd m n = 0) : n = 0 :=\nby rw gcd_comm at H; exact eq_zero_of_gcd_eq_zero_left H\n\ntheorem gcd_div {m n k : ℕ} (H1 : k ∣ m) (H2 : k ∣ n) :\n  gcd (m / k) (n / k) = gcd m n / k :=\nor.elim (nat.eq_zero_or_pos k)\n  (λk0, by rw [k0, nat.div_zero, nat.div_zero, nat.div_zero, gcd_zero_right])\n  (λH3, nat.eq_of_mul_eq_mul_right H3 $ by rw [\n    nat.div_mul_cancel (dvd_gcd H1 H2), ←gcd_mul_right,\n    nat.div_mul_cancel H1, nat.div_mul_cancel H2])\n\ntheorem gcd_dvd_gcd_of_dvd_left {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd m n ∣ 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 : ℕ} (n : ℕ) (H : m ∣ k) : gcd n m ∣ 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 : ℕ) : gcd m n ∣ gcd (k * m) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right (m n k : ℕ) : gcd m n ∣ gcd (m * k) n :=\ngcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)\n\ntheorem gcd_dvd_gcd_mul_left_right (m n k : ℕ) : gcd m n ∣ gcd m (k * n) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)\n\ntheorem gcd_dvd_gcd_mul_right_right (m n k : ℕ) : gcd m n ∣ gcd m (n * k) :=\ngcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)\n\ntheorem gcd_eq_left {m n : ℕ} (H : m ∣ n) : gcd m n = m :=\ndvd_antisymm (gcd_dvd_left _ _) (dvd_gcd dvd_rfl H)\n\ntheorem gcd_eq_right {m n : ℕ} (H : n ∣ m) : gcd m n = n :=\nby rw [gcd_comm, gcd_eq_left H]\n\n@[simp] lemma gcd_mul_left_left (m n : ℕ) : 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 : ℕ) : gcd n (m * n) = n :=\nby rw [gcd_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_left (m n : ℕ) : gcd (n * m) n = n :=\nby rw [mul_comm, gcd_mul_left_left]\n\n@[simp] lemma gcd_mul_right_right (m n : ℕ) : gcd n (n * m) = n :=\nby rw [gcd_comm, gcd_mul_right_left]\n\n@[simp] lemma gcd_gcd_self_right_left (m n : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ) : gcd (gcd m n) m = gcd m n :=\nby rw [gcd_comm m n, gcd_gcd_self_left_right]\n\n@[simp] lemma gcd_add_mul_self (m n k : ℕ) : 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_self_right (m n : ℕ) : gcd m (n + m) = gcd m n :=\neq.trans (by rw one_mul) (gcd_add_mul_self m n 1)\n\n@[simp] lemma gcd_add_self_left (m n : ℕ) : 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 : ℕ) : 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 : ℕ) : gcd m (m + n) = gcd m n :=\nby rw [add_comm, gcd_add_self_right]\n\n@[simp] theorem gcd_eq_zero_iff {i j : ℕ} : gcd i j = 0 ↔ i = 0 ∧ j = 0 :=\nbegin\n  split,\n  { intro h,\n    exact ⟨eq_zero_of_gcd_eq_zero_left h, eq_zero_of_gcd_eq_zero_right h⟩, },\n  { rintro ⟨rfl, rfl⟩,\n    exact nat.gcd_zero_right 0 }\nend\n\n/-! ### `lcm` -/\n\ntheorem lcm_comm (m n : ℕ) : lcm m n = lcm n m :=\nby delta lcm; rw [mul_comm, gcd_comm]\n\n@[simp]\ntheorem lcm_zero_left (m : ℕ) : lcm 0 m = 0 :=\nby delta lcm; rw [zero_mul, nat.zero_div]\n\n@[simp]\ntheorem lcm_zero_right (m : ℕ) : lcm m 0 = 0 := lcm_comm 0 m ▸ lcm_zero_left m\n\n@[simp]\ntheorem lcm_one_left (m : ℕ) : lcm 1 m = m :=\nby delta lcm; rw [one_mul, gcd_one_left, nat.div_one]\n\n@[simp]\ntheorem lcm_one_right (m : ℕ) : lcm m 1 = m := lcm_comm 1 m ▸ lcm_one_left m\n\n@[simp]\ntheorem lcm_self (m : ℕ) : lcm m m = m :=\nor.elim (nat.eq_zero_or_pos m)\n  (λh, by rw [h, lcm_zero_left])\n  (λh, by delta lcm; rw [gcd_self, nat.mul_div_cancel _ h])\n\ntheorem dvd_lcm_left (m n : ℕ) : m ∣ 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 : ℕ) : n ∣ lcm m n :=\nlcm_comm n m ▸ dvd_lcm_left n m\n\ntheorem gcd_mul_lcm (m n : ℕ) : 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 : ℕ} (H1 : m ∣ k) (H2 : n ∣ k) : lcm m n ∣ k :=\nor.elim (nat.eq_zero_or_pos k)\n  (λh, by rw h; exact dvd_zero _)\n  (λkpos, 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, ←gcd_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 : ℕ) : lcm m n ∣ m * n :=\nlcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _)\n\nlemma lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k :=\n⟨λ h, ⟨(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩,\n  and_imp.2 lcm_dvd⟩\n\ntheorem lcm_assoc (m n k : ℕ) : 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 : ℕ} (hm : m ≠ 0) (hn : n ≠ 0) : lcm m n ≠ 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 : ℕ) : decidable (coprime m n) := by unfold coprime; apply_instance\n\ntheorem coprime_iff_gcd_eq_one {m n : ℕ} : coprime m n ↔ gcd m n = 1 := iff.rfl\n\ntheorem coprime.gcd_eq_one {m n : ℕ} (h : coprime m n) : gcd m n = 1 := h\n\ntheorem coprime.lcm_eq_mul {m n : ℕ} (h : coprime m n) : lcm m n = m * n :=\nby rw [←one_mul (lcm m n), ←h.gcd_eq_one, gcd_mul_lcm]\n\ntheorem coprime.symm {m n : ℕ} : coprime n m → coprime m n := (gcd_comm m n).trans\n\ntheorem coprime_comm {m n : ℕ} : coprime n m ↔ coprime m n := ⟨coprime.symm, coprime.symm⟩\n\ntheorem coprime.dvd_of_dvd_mul_right {m n k : ℕ} (H1 : coprime k n) (H2 : k ∣ m * n) : k ∣ 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\ntheorem coprime.dvd_of_dvd_mul_left {m n k : ℕ} (H1 : coprime k m) (H2 : k ∣ m * n) : k ∣ n :=\nby rw mul_comm at H2; exact H1.dvd_of_dvd_mul_right H2\n\ntheorem coprime.dvd_mul_right {m n k : ℕ} (H : coprime k n) : k ∣ m * n ↔ k ∣ m :=\n⟨H.dvd_of_dvd_mul_right, λ h, dvd_mul_of_dvd_left h n⟩\n\ntheorem coprime.dvd_mul_left {m n k : ℕ} (H : coprime k m) : k ∣ m * n ↔ k ∣ n :=\n⟨H.dvd_of_dvd_mul_left, λ h, dvd_mul_of_dvd_right h m⟩\n\ntheorem coprime.gcd_mul_left_cancel {k : ℕ} (m : ℕ) {n : ℕ} (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 : ℕ) {k n : ℕ} (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 : ℕ} (n : ℕ) (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 : ℕ} (n : ℕ) (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 : ℕ} (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 : ℕ} (dgt1 : 1 < d) (Hm : d ∣ m) (Hn : d ∣ n) :\n  ¬ coprime m n :=\nλ co, not_lt_of_ge (le_of_dvd zero_lt_one $ by rw [←co.gcd_eq_one]; exact dvd_gcd Hm Hn) dgt1\n\ntheorem exists_coprime {m n : ℕ} (H : 0 < gcd m n) :\n  ∃ m' n', coprime m' n' ∧ m = m' * gcd m n ∧ n = n' * gcd m n :=\n⟨_, _, 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⟩\n\ntheorem exists_coprime' {m n : ℕ} (H : 0 < gcd m n) :\n  ∃ g m' n', 0 < g ∧ coprime m' n' ∧ m = m' * g ∧ n = n' * g :=\nlet ⟨m', n', h⟩ := exists_coprime H in ⟨_, m', n', H, h⟩\n\n@[simp] theorem coprime_add_self_right {m n : ℕ} : coprime m (n + m) ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_self_right]\n\n@[simp] theorem coprime_self_add_right {m n : ℕ} : coprime m (m + n) ↔ coprime m n :=\nby rw [add_comm, coprime_add_self_right]\n\n@[simp] theorem coprime_add_self_left {m n : ℕ} : coprime (m + n) n ↔ coprime m n :=\nby rw [coprime, coprime, gcd_add_self_left]\n\n@[simp] theorem coprime_self_add_left {m n : ℕ} : coprime (m + n) m ↔ coprime n m :=\nby rw [coprime, coprime, gcd_self_add_left]\n\ntheorem coprime.mul {m n k : ℕ} (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 : ℕ} (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 : ℕ} (H1 : m ∣ k) (H2 : coprime k n) : coprime m n :=\neq_one_of_dvd_one (by delta coprime at H2; rw ← H2; exact gcd_dvd_gcd_of_dvd_left _ H1)\n\ntheorem coprime.coprime_dvd_right {m k n : ℕ} (H1 : n ∣ 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 : ℕ} (H : coprime (k * m) n) : coprime m n :=\nH.coprime_dvd_left (dvd_mul_left _ _)\n\ntheorem coprime.coprime_mul_right {k m n : ℕ} (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 : ℕ} (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 : ℕ} (H : coprime m (n * k)) : coprime m n :=\nH.coprime_dvd_right (dvd_mul_right _ _)\n\ntheorem coprime.coprime_div_left {m n a : ℕ} (cmn : coprime m n) (dvd : a ∣ 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 ⟨k, rfl⟩,\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 : ℕ} (cmn : coprime m n) (dvd : a ∣ n) :\n  coprime m (n / a) :=\n(coprime.coprime_div_left cmn.symm dvd).symm\n\nlemma coprime_mul_iff_left {k m n : ℕ} : coprime (m * n) k ↔ coprime m k ∧ coprime n k :=\n⟨λ h, ⟨coprime.coprime_mul_right h, coprime.coprime_mul_left h⟩,\n  λ ⟨h, _⟩, by rwa [coprime_iff_gcd_eq_one, coprime.gcd_mul_left_cancel n h]⟩\n\nlemma coprime_mul_iff_right {k m n : ℕ} : coprime k (m * n) ↔ coprime k m ∧ coprime k n :=\nby simpa only [coprime_comm] using coprime_mul_iff_left\n\nlemma coprime.gcd_left (k : ℕ) {m n : ℕ} (hmn : coprime m n) : coprime (gcd k m) n :=\nhmn.coprime_dvd_left $ gcd_dvd_right k m\n\nlemma coprime.gcd_right (k : ℕ) {m n : ℕ} (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 : ℕ) {m n : ℕ} (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 : ℕ} (hmn : coprime m n)\n  (hm : m ∣ a) (hn : n ∣ a) : m * n ∣ a :=\nlet ⟨k, hk⟩ := hm in hk.symm ▸ mul_dvd_mul_left _ (hmn.symm.dvd_of_dvd_mul_left (hk ▸ hn))\n\ntheorem coprime_one_left : ∀ n, coprime 1 n := gcd_one_left\n\ntheorem coprime_one_right : ∀ n, coprime n 1 := gcd_one_right\n\ntheorem coprime.pow_left {m k : ℕ} (n : ℕ) (H1 : coprime m k) : coprime (m ^ n) k :=\nnat.rec_on n (coprime_one_left _) (λn IH, H1.mul IH)\n\ntheorem coprime.pow_right {m k : ℕ} (n : ℕ) (H1 : coprime k m) : coprime k (m ^ n) :=\n(H1.symm.pow_left n).symm\n\ntheorem coprime.pow {k l : ℕ} (m n : ℕ) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) :=\n(H1.pow_left _).pow_right _\n\nlemma coprime_pow_left_iff {n : ℕ} (hn : 0 < n) (a b : ℕ)  :\n  nat.coprime (a ^ n) b ↔ nat.coprime a b :=\nbegin\n  obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero hn.ne',\n  rw [pow_succ, nat.coprime_mul_iff_left],\n  exact ⟨and.left, λ hab, ⟨hab, hab.pow_left _⟩⟩\nend\n\nlemma coprime_pow_right_iff {n : ℕ} (hn : 0 < n) (a b : ℕ)  :\n  nat.coprime a (b ^ n) ↔ 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 : ℕ} (H : coprime k m) (d : k ∣ m) : k = 1 :=\nby rw [← H.gcd_eq_one, gcd_eq_left d]\n\n@[simp] theorem coprime_zero_left (n : ℕ) : coprime 0 n ↔ n = 1 :=\nby simp [coprime]\n\n@[simp] theorem coprime_zero_right (n : ℕ) : coprime n 0 ↔ n = 1 :=\nby simp [coprime]\n\ntheorem not_coprime_zero_zero : ¬ coprime 0 0 := by simp\n\n@[simp] theorem coprime_one_left_iff (n : ℕ) : coprime 1 n ↔ true :=\nby simp [coprime]\n\n@[simp] theorem coprime_one_right_iff (n : ℕ) : coprime n 1 ↔ true :=\nby simp [coprime]\n\n@[simp] theorem coprime_self (n : ℕ) : coprime n n ↔ n = 1 :=\nby simp [coprime]\n\nlemma coprime.eq_of_mul_eq_zero {m n : ℕ} (h : m.coprime n) (hmn : m * n = 0) :\n  m = 0 ∧ n = 1 ∨ m = 1 ∧ n = 0 :=\n(nat.eq_zero_of_mul_eq_zero hmn).imp\n  (λ hm, ⟨hm, n.coprime_zero_left.mp $ hm ▸ h⟩)\n  (λ hn, ⟨m.coprime_zero_left.mp $ hn ▸ h.symm, hn⟩)\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 : ℕ} (H : k ∣ m * n) :\n  { d : {m' // m' ∣ m} × {n' // n' ∣ n} // k = d.1 * d.2 } :=\nbegin\ncases h0 : (gcd k m),\ncase nat.zero\n{ have : k = 0 := eq_zero_of_gcd_eq_zero_left h0, subst this,\n  have : m = 0 := eq_zero_of_gcd_eq_zero_right h0, subst this,\n  exact ⟨⟨⟨0, dvd_refl 0⟩, ⟨n, dvd_refl n⟩⟩, (zero_mul n).symm⟩ },\ncase nat.succ : tmp\n{ have hpos : 0 < gcd k m := h0.symm ▸ 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 ⟨⟨⟨gcd k m,  gcd_dvd_right k m⟩, ⟨k / gcd k m, _⟩⟩, hd.symm⟩,\n  apply dvd_of_mul_dvd_mul_left hpos,\n  rw [hd, ← gcd_mul_right],\n  exact dvd_gcd (dvd_mul_right _ _) H }\nend\n\ntheorem gcd_mul_dvd_mul_gcd (k m n : ℕ) : gcd k (m * n) ∣ gcd k m * gcd k n :=\nbegin\nrcases (prod_dvd_and_dvd_of_dvd_prod $ gcd_dvd_right k (m * n)) with ⟨⟨⟨m', hm'⟩, ⟨n', hn'⟩⟩, h⟩,\nreplace h : gcd k (m * n) = m' * n' := h,\nrw h,\nhave hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _,\napply mul_dvd_mul,\n  { have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n',\n    exact dvd_gcd hm'k hm' },\n  { have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n',\n    exact dvd_gcd hn'k hn' }\nend\n\ntheorem coprime.gcd_mul (k : ℕ) {m n : ℕ} (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 : ℕ} (n0 : 0 < n) : a ^ n ∣ b ^ n ↔ a ∣ b :=\nbegin\n  refine ⟨λ h, _, λ h, pow_dvd_pow_of_dvd h _⟩,\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 ⟨g, a', b', g0', co, rfl, rfl⟩,\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 : ℕ} (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 ← 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:ℕ` divides coprime `a` and `b` then `k = 1` -/\nlemma eq_one_of_dvd_coprimes {a b k : ℕ} (h_ab_coprime : coprime a b)\n  (hka : k ∣ a) (hkb : k ∣ 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\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/gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.7739535439487945}}
{"text": "/-***************-/\n/- ** BASICS ** --/\n/-***************-/\n\n/-\n# \n\nWrite a defintion of x as a value of \ntype nat having the specific value 0.\nBe sure it type-checks. \n-/\n\ndef x : ℕ := 0\n\n/-\n# \n\nWrite a definition of f as a function\nof type ℕ → ℕ that returns the square of\nthe value to which it is applied (i.e.,\nthat it is given as an argument)\n-/\n\ndef square (n: ℕ) : nat := n^2\n\n#reduce square 3\n\n/-\n#\n\nWrite a definition of a function, nt, that\ntakes any proposition, P, and that returns\nthe proposition, P → false. \n-/\n\ndef nt (P : Prop) : Prop := P → false\n\n/-\n#\n\nWhat is the type of this function? Hint:\nUse #check to check it.\n-/\n\n\n/-****************************************-/\n/- ** PROOFS OF EQUALITY PROPOSITIONS ** --/\n/-****************************************-/\n\n\n/-\n#1 \n\nWrite a function that takes any type, \nT : Type, and any value, t : T, and that \nreturns a proof of t = t.\n-/\n\ndef equality {T : Type} (t : T) : t = t := eq.refl t\n\n/-\n#2a\n\nWrite a function that takes any type, T; three values, \na, b, and c, of type T; a proof of a = b; and a proof \nof b = c; and that returns a proof of c = a. We give\nyou most of the answer. Replace the sorry with your\nanswer.  \n-/\n\ndef aBbCCa \n    { T : Type } \n    (a b c : T)\n    (ab : a = b)\n    (bc: c = b) :\n    (c = a) \n    := eq.trans bc (eq.symm ab)\n\ndef testMyself : ∀(a b c : Type), a = b → c = b → c = a := \n    λ a b c ab cb,\n        eq.trans cb (eq.symm ab)\n\n/-  \n#2b.\n\n\nDefine aBbCCa' to be the same function, but specify \nits type using ∀ and → connectives, and then provide\nthe function value using a lambda expression (λ). So\nyou will start with \"def\", then the name, then a :,\nthen the proposition, starting with ∀ and ending with\n→ (c = a), followed by :=, and finally follwed by a\nlambda expression.\n-/\n\ndef aBbCCa' : ∀(a b c : Type), ((a = b) → (c = b) → (c = a)) :=\n    λ (a : Type) (b : Type) (c : Type),\n      λ (ab : a = b) (cb : c = b),\n        (eq.trans cb (eq.symm ab))\n\n-- λT, λa, λb,  λc,  λ (ab : a=b),  λ (bc : b = c),\n-- eq.trans cb (eq.symm ab)\n-- this also works\n\n\n/-*******************************-/\n/- ** PROOFS OF CONJUNCTIONS ** --/\n/-*******************************-/\n\n/-\nWe assume P Q and R are propositions using the\nfollowing \"variables\" declaration. That means that\nwe can use P, Q, R, and S in the following theorems\nwithout having to use ∀ P Q R S : Prop to introduce\nthem again for each individual proposition.\n-/\n\nvariables P Q R S : Prop\n\n/-\nProve the following propositions by completing\nthe definitions (replace sorrys with your answers).\n-/\n\ntheorem t1 : P → Q → R → P := \n    λ (pfP : P) (pfQ : Q) (pfR : R),\n        pfP\n\ntheorem t2 : Q → (Q ∧ Q) := \n    λ (pfQ : Q),\n        (and.intro pfQ pfQ)\n\ntheorem t3 : (P ∧ Q) ∧ (Q ∧ R) → (P ∧ R) :=\n    λ (pfAll : (P ∧ Q) ∧ (Q ∧ R)),\n        and.intro (and.elim_left(and.elim_left pfAll)) (and.elim_right (and.elim_right pfAll))\n\n\n/-*******************************-/\n/- ** PROOFS OF IMPLICATIONS ** --/\n/-*******************************-/\n\n/-\nProve the following theorem. It claims that\nimplication is transitive (which it is).\n-/\n\ntheorem t4 : ((P → Q) ∧ P) → Q :=\n    λ (pfLeft : ((P → Q) ∧ P)),\n        (and.elim_left pfLeft) (and.elim_right pfLeft)\n\n\ntheorem t5 : \n    (P → Q) → (Q → R) → (R → S) → (P → S) :=\n        λ (pfPtoQ : P → Q) (pfQtoR : Q → R) (pfRtoS : R → S) (pfP : P),\n            pfRtoS (pfQtoR (pfPtoQ (pfP)))\n\n-- or\n-- begin\n-- assume pq qr rs,\n-- assume p,\n-- show S,\n-- from rs (qr (pq p))\n        \n\n/-******************-/\n/- ** Functions ** --/\n/-******************-/\n\n\n/-\nComplete the following definition\nwith a value that makes the definition\ntype-check. You can answer with a\nlambda expression. You can also\nuse a tactic script if you prefer.\n-/\ndef n2n : ℕ → ℕ := \n    λ (n : ℕ),\n        n\n\n/-\nDefine a function called double \nthat takes any natural number, n, \nand returns two times n. \n-/\n\ndef double (g : ℕ) := g*2\n\n\n/-\nWrite a test case for double\nin the form of a theorem called\nd15is30, that asserts that the\ndouble of 15 is 30, and prove it.\n-/\n\ndef d15is30 : double 15 = 30 := eq.refl 30\n\n--- Your answer here\n\n/-\nWrite a function, sum3, that takes three \nnatural numbers, a, b, c, and that returns\nthe sum of a, b, and c. Use a λ expression\nto express the function.\n-/\n\ndef sum3 : ∀(a b c : ℕ), ℕ :=\n    λ (a b c : ℕ), a + b + c\n\n#reduce sum3 1 32 4\n\n\n/-*****************-/\n/- ** NEGATION ** --/\n/-*****************-/\n\n/-\nYou already know that double\nnegation elimination requires\nclassical reasoning (using the \nlaw of the excluded middle).\nGive a proof of the following\nproposition, which asserts that\nit's valid to introduce double\nnegatations. Note: You do not \nneed the law of the excluded\nmiddle to prove it.\n-/\n\ndef t6 : P → ¬ ¬ P :=\nbegin\n    assume pfP : P,\n    assume np : ¬P,\n    show false, from np pfP\nend\n\n-- applies not p to p implies false\n\n/-\nYou've learned a few important \nproof strategies. Explain in a \nfew words when might a proof\nby negation be attempted, and \nhow one proceeds to use it.\n\nKnow the answer to the same\nquestion about a proof by\ncontradiction. \n-/\n\n-- A proof by negation is attempted by first assuming that a proposition\n-- is true, then proving that it cannot be true, therefore showing that the\n-- propoisiton is false. For example, if you are trying to prove P → false, \n-- you start by assuming P is true, then go through steps to show that it can't\n-- be true, thereby showing P → False.\n\n/-\nExplain precisely why using a\nproof by contradiction relies\non classical reasoning using\nthe law of the excluded middle.\n-/\n\n-- The law of excluded middle is needed because we need the axiom that there\n-- are no \"in between stages,\" either its P or its ¬P. Without that we cannot\n-- know for certain that ¬¬P is P because ¬¬P could be one of the 'in between'\n-- cases, but the law of excluded middle prevents this case. \n\n/-\nEXTRA CREDIT: Write a function \nthat takes a function, f, of type\nℕ → ℕ, and that returns a function\nthat, for any value, n, returns \none more that what f returns. \n-/\n\ndef f : ℕ → ℕ :=\n    λ (n : ℕ),\n        n*2\n\ndef xtra (f : ℕ → ℕ) : ℕ → ℕ :=\n    λ (n : ℕ),\n    (f n) + 1\n\n#reduce xtra f 2\n\n\n/-\nThat's the end of the practice test.\nHere's a partial inventory of inference\nrules we've covered. and related concepts.\nThis is not enough material for a complete\nreview. Reread all the notes and work any\nproblems that you're not yet sure you know\nhow to solve.\n-/\n\n\n/-\nPartial inventory of inference rules.\n\n* Equality\n-- eq.refl : given a type T and a value t : T, derives a proof of t = t\n-- eq.symm : given a type T, values a b : T, and a proof of a = b, derives a proof of b = a\n-- eq.trans : given a type T, values a b c : T, and proofs of a = b and b = c, derives a proof of a = c\n\n* Conjunction\n-- and.intro : given propositions, P Q : Prop, a proof P : P, and a proof q : Q, derives a proof of P ∧ Q\n-- and.elim_right : given propositions, P Q : Prop and a proof pq : P ∧ Q, derives a proof of P\n-- and.elim_right : given propositions, P Q : Prop and a proof pq : P ∧ Q, derives a proof of Q\n\n* Implication\n-- → introduction: given P Q : Prop and a derivation of a proof Q from a proof of P, conclude P → Q\n-- note : a derivation of a proof of Q from a proof of P is given as a function of type P → Q\n-- → elimination: given propositions, P and Q, a proof of P → Q, and a proof of P, derive a proof of Q\n-- note that → elimination is both a formal version of Aristotle's modus ponens rule and function application\n\n* Negation\n-- introduction : given a proposition P and a proof of P → false, conclude ¬ P\n-- elimination\n---- in constructive logic, showing that a proposition, ¬ P, is false proves only ¬ ¬ P, not that P is true\n---- try to derive a proof of P from the assumption of a proof for ¬ ¬ P and you will see the problem\n---- you can read ¬ ¬ P as \"there's no proof of ¬ P,\" or as \"¬ P is false,\" \n---- classical logic adds the axiom of the excluded middle (AEM), stating that ∀ P : Prop, P ∨ ¬ P\n---- if you accept this axiom and you know that ¬ P is false, then P must be true\n---- the AEM enables ¬ elimination\n---- given a proposition P and a proof of ¬ P → false (of ¬ ¬ P), derive a proof of P\n\n* Forall\n-- introduction : to prove ∀ p : P, Q, where P is a type and Q is a proposition that can involve be written in terms of p, show that Q holds for an any arbitrarily assumed value, p, of type P\n-- elimination : given a proof of ∀ p : P, Q, and a specific value x : P, conclude Q \n-/", "meta": {"author": "Mnormansell", "repo": "Discrete-Notes", "sha": "61f13b98be590269fc4822be7b47924a6ddc1261", "save_path": "github-repos/lean/Mnormansell-Discrete-Notes", "path": "github-repos/lean/Mnormansell-Discrete-Notes/Discrete-Notes-61f13b98be590269fc4822be7b47924a6ddc1261/HOMEWORK/exam1-practice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8723473846343394, "lm_q1q2_score": 0.7739506017613189}}
{"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 data.polynomial.ring_division\nimport linear_algebra.dimension\nimport algebra.polynomial.big_operators\n\n/-!\n# Linear recurrence\n\nInformally, a \"linear recurrence\" is an assertion of the form\n`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,\nwhere `u` is a sequence, `d` is the *order* of the recurrence and the `a i`\nare its *coefficients*.\n\nIn this file, we define the structure `linear_recurrence` so that\n`linear_recurrence.mk d a` represents the above relation, and we call\na sequence `u` which verifies it a *solution* of the linear recurrence.\n\nWe prove a few basic lemmas about this concept, such as :\n\n* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`\n  is a field)\n* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`\n  between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two\n  solutions are equal if and only if their first `d` terms are equals.\n* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,\n  which we call the *characteristic polynomial* of the recurrence\n\nOf course, although we can inductively generate solutions (cf `mk_sol`), the\ninteresting part would be to determinate closed-forms for the solutions.\nThis is currently *not implemented*, as we are waiting for definition and\nproperties of eigenvalues and eigenvectors.\n\n-/\n\nnoncomputable theory\nopen finset\nopen_locale big_operators\n\n/-- A \"linear recurrence relation\" over a commutative semiring is given by its\n  order `n` and `n` coefficients. -/\nstructure linear_recurrence (α : Type*) [comm_semiring α] := (order : ℕ) (coeffs : fin order → α)\n\ninstance (α : Type*) [comm_semiring α] : inhabited (linear_recurrence α) :=\n⟨⟨0, default _⟩⟩\n\nnamespace linear_recurrence\n\nsection comm_semiring\n\nvariables {α : Type*} [comm_semiring α] (E : linear_recurrence α)\n\n/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have\n  `u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/\ndef is_solution (u : ℕ → α) :=\n  ∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)\n\n/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.\n  We will prove this is the only such solution. -/\ndef mk_sol (init : fin E.order → α) : ℕ → α\n| n := if h : n < E.order then init ⟨n, h⟩ else\n  ∑ k : fin E.order,\n    have n - E.order + k < n :=\n    begin\n      rw [add_comm, ← nat.add_sub_assoc (not_lt.mp h), nat.sub_lt_left_iff_lt_add],\n      { exact add_lt_add_right k.is_lt n },\n      { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h),\n        simp only [zero_add] }\n    end,\n    E.coeffs k * mk_sol (n - E.order + k)\n\n/-- `E.mk_sol` indeed gives solutions to `E`. -/\nlemma is_sol_mk_sol (init : fin E.order → α) : E.is_solution (E.mk_sol init) :=\n  λ n, by rw mk_sol; simp\n\n/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/\nlemma mk_sol_eq_init (init : fin E.order → α) : ∀ n : fin E.order, E.mk_sol init n = init n :=\n  λ n, by { rw mk_sol, simp only [n.is_lt, dif_pos, fin.mk_coe, fin.eta] }\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `∀ n, u n = E.mk_sol init n`. -/\nlemma eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) :\n  ∀ n, u n = E.mk_sol init n\n| n := if h' : n < E.order\n  then by rw mk_sol; simp only [h', dif_pos]; exact_mod_cast heq ⟨n, h'⟩\n  else begin\n    rw [mk_sol, ← nat.sub_add_cancel (le_of_not_lt h'), h (n-E.order)],\n    simp [h'],\n    congr' with k,\n    exact have wf : n - E.order + k < n :=\n      begin\n        rw [add_comm, ← nat.add_sub_assoc (not_lt.mp h'), nat.sub_lt_left_iff_lt_add],\n        { exact add_lt_add_right k.is_lt n },\n        { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h'),\n          simp only [zero_add] }\n      end,\n      by rw eq_mk_of_is_sol_of_eq_init\n  end\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution\n  of `E` whose first `E.order` values are given by `init`. -/\nlemma eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) : u = E.mk_sol init :=\n  funext (E.eq_mk_of_is_sol_of_eq_init h heq)\n\n/-- The space of solutions of `E`, as a `submodule` over `α` of the module `ℕ → α`. -/\ndef sol_space : submodule α (ℕ → α) :=\n{ carrier := {u | E.is_solution u},\n  zero_mem' := λ n, by simp,\n  add_mem' := λ u v hu hv n, by simp [mul_add, sum_add_distrib, hu n, hv n],\n  smul_mem' := λ a u hu n, by simp [hu n, mul_sum]; congr'; ext; ac_refl }\n\n/-- Defining property of the solution space : `u` is a solution\n  iff it belongs to the solution space. -/\nlemma is_sol_iff_mem_sol_space (u : ℕ → α) : E.is_solution u ↔ u ∈ E.sol_space :=\n  iff.rfl\n\n/-- The function that maps a solution `u` of `E` to its first\n  `E.order` terms as a `linear_equiv`. -/\ndef to_init :\n  E.sol_space ≃ₗ[α] (fin E.order → α) :=\n{ to_fun := λ u x, (u : ℕ → α) x,\n  map_add' := λ u v, by { ext, simp },\n  map_smul' := λ a u, by { ext, simp },\n  inv_fun := λ u, ⟨E.mk_sol u, E.is_sol_mk_sol u⟩,\n  left_inv := λ u, by ext n; symmetry; apply E.eq_mk_of_is_sol_of_eq_init u.2; intros k; refl,\n  right_inv := λ u, function.funext_iff.mpr (λ n, E.mk_sol_eq_init u n) }\n\n/-- Two solutions are equal iff they are equal on `range E.order`. -/\nlemma sol_eq_of_eq_init (u v : ℕ → α) (hu : E.is_solution u) (hv : E.is_solution v) :\n  u = v ↔ set.eq_on u v ↑(range E.order) :=\nbegin\n  refine iff.intro (λ h x hx, h ▸ rfl) _,\n  intro h,\n  set u' : ↥(E.sol_space) := ⟨u, hu⟩,\n  set v' : ↥(E.sol_space) := ⟨v, hv⟩,\n  change u'.val = v'.val,\n  suffices h' : u' = v', from h' ▸ rfl,\n  rw [← E.to_init.to_equiv.apply_eq_iff_eq, linear_equiv.coe_to_equiv],\n  ext x,\n  exact_mod_cast h (mem_range.mpr x.2)\nend\n\n/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. This operation is quite useful for determining closed-form\n  solutions of `E`. -/\n\n/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. -/\ndef tuple_succ : (fin E.order → α) →ₗ[α] (fin E.order → α) :=\n{ to_fun := λ X i, if h : (i : ℕ) + 1 < E.order then X ⟨i+1, h⟩ else (∑ i, E.coeffs i * X i),\n  map_add' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_add, sum_add_distrib],\n    end,\n  map_smul' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_sum],\n      exact sum_congr rfl (λ x _, by ac_refl),\n    end }\n\nend comm_semiring\n\nsection field\n\nvariables {α : Type*} [field α] (E : linear_recurrence α)\n\n/-- The dimension of `E.sol_space` is `E.order`. -/\nlemma sol_space_dim : module.rank α E.sol_space = E.order :=\n@dim_fin_fun α _ E.order ▸ E.to_init.dim_eq\n\nend field\n\nsection comm_ring\n\nvariables {α : Type*} [comm_ring α] (E : linear_recurrence α)\n\n/-- The characteristic polynomial of `E` is\n`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/\ndef char_poly : polynomial α :=\n  polynomial.monomial E.order 1 - (∑ i : fin E.order, polynomial.monomial i (E.coeffs i))\n\n/-- The geometric sequence `q^n` is a solution of `E` iff\n  `q` is a root of `E`'s characteristic polynomial. -/\nlemma geom_sol_iff_root_char_poly (q : α) : E.is_solution (λ n, q^n) ↔ E.char_poly.is_root q :=\nbegin\n  rw [char_poly, polynomial.is_root.def, polynomial.eval],\n  simp only [polynomial.eval₂_finset_sum, one_mul,\n              ring_hom.id_apply, polynomial.eval₂_monomial, polynomial.eval₂_sub],\n  split,\n  { intro h,\n    simpa [sub_eq_zero] using h 0 },\n  { intros h n,\n    simp only [pow_add, sub_eq_zero.mp h, mul_sum],\n    exact sum_congr rfl (λ _ _, by ring) }\nend\n\nend comm_ring\n\nend linear_recurrence\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/linear_recurrence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7738159246844398}}
{"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\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 ↔ is_O (λ x, ∥f x∥) (λ x, ∥g x∥) 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 ↔ tendsto (λ x, f x / (g x)) l (𝓝 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échet derivative.)\n-/\n\nopen filter set\nopen_locale topological_space big_operators classical filter nnreal\n\nnamespace asymptotics\n\nvariables {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*}\n  {E' : Type*} {F' : Type*} {G' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : 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 𝕜] [normed_field 𝕜']\n  {c c' : ℝ} {f : α → E} {g : α → F} {k : α → G} {f' : α → E'} {g' : α → F'} {k' : α → G'}\n  {l l' : filter α}\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 `α` and `l` is a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by `C * ∥g∥`.\nIn other words, `∥f∥ / ∥g∥` 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 : ℝ) (f : α → E) (g : α → F) (l : filter α) : Prop :=\n∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥\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 : ℝ} {f : α → E} {g : α → F} {l : filter α} :\n  is_O_with c f g l ↔ ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := by rw is_O_with\n\nalias is_O_with_iff ↔ 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 `α` and `l` is\na filter on `α`, means that eventually for `l`, `∥f∥` is bounded by a constant multiple of `∥g∥`.\nIn other words, `∥f∥ / ∥g∥` is eventually bounded, modulo division by zero issues that are avoided\nby this definition. -/\n@[irreducible]\ndef is_O (f : α → E) (g : α → F) (l : filter α) : Prop := ∃ c : ℝ, 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 : α → E} {g : α → F} {l : filter α} :\n  is_O f g l ↔ ∃ c : ℝ, 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 : α → E} {g : α → F} {l : filter α} :\n  is_O f g l ↔ ∃ c : ℝ, ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := by simp [is_O, is_O_with]\n\nlemma is_O.of_bound (c : ℝ) {f : α → E} {g : α → F} {l : filter α}\n  (h : ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥) : is_O f g l := is_O_iff.2 ⟨c, h⟩\n\nlemma is_O.bound {f : α → E} {g : α → F} {l : filter α} :\n  is_O f g l → ∃ c : ℝ, ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := is_O_iff.1\n\n/-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `α` and `l` is\na filter on `α`, means that eventually for `l`, `∥f∥` is bounded by an arbitrarily small constant\nmultiple of `∥g∥`. In other words, `∥f∥ / ∥g∥` tends to `0` along `l`, modulo division by zero\nissues that are avoided by this definition. -/\n@[irreducible]\ndef is_o (f : α → E) (g : α → F) (l : filter α) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → 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 : α → E} {g : α → F} {l : filter α} :\n  is_o f g l ↔ ∀ ⦃c : ℝ⦄, 0 < c → is_O_with c f g l := by rw is_o\n\nalias is_o_iff_forall_is_O_with ↔ 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 : α → E} {g : α → F} {l : filter α} :\n  is_o f g l ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ :=\nby simp only [is_o, is_O_with]\n\nalias is_o_iff ↔ asymptotics.is_o.bound asymptotics.is_o.of_bound\n\nlemma is_o.def {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) :\n  ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ :=\nis_o_iff.1 h hc\n\nlemma is_o.def' {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (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 ⟨c, h⟩\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 : α → E} {g : α → F} {l : filter α} :\n  is_O f g l → ∃ c : ℝ, 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 ≤ c') : is_O_with c' f g' l :=\nis_O_with.of_bound $ mem_sets_of_superset h.bound $ λ x hx,\ncalc ∥f x∥ ≤ c * ∥g' x∥ : hx\n... ≤ _ : 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  ∃ c' (H : 0 < c'), is_O_with c' f g' l :=\n⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken $ le_max_left c 1⟩\n\ntheorem is_O.exists_pos (h : is_O f g' l) : ∃ c (H : 0 < c), is_O_with c f g' l :=\nlet ⟨c, hc⟩ := h.is_O_with in hc.exists_pos\n\ntheorem is_O_with.exists_nonneg (h : is_O_with c f g' l) :\n  ∃ c' (H : 0 ≤ c'), is_O_with c' f g' l :=\nlet ⟨c, cpos, hc⟩ := h.exists_pos in ⟨c, le_of_lt cpos, hc⟩\n\ntheorem is_O.exists_nonneg (h : is_O f g' l) :\n  ∃ c (H : 0 ≤ c), is_O_with c f g' l :=\nlet ⟨c, hc⟩ := 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 ↔ ∀ᶠ c in at_top, is_O_with c f g' l :=\nis_O_iff_is_O_with.trans\n  ⟨λ ⟨c, hc⟩, mem_at_top_sets.2 ⟨c, λ c' hc', hc.weaken hc'⟩, λ h, h.exists⟩\n\n/-- `f = O(g)` if and only if `∀ᶠ x in l, ∥f x∥ ≤ c * ∥g x∥` for all sufficiently large `c`. -/\nlemma is_O_iff_eventually : is_O f g' l ↔ ∀ᶠ c in at_top, ∀ᶠ x in l, ∥f x∥ ≤ c * ∥g' x∥ :=\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 $ λ 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₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n  (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :\n  is_O_with c₁ f₁ g₁ l ↔ is_O_with c₂ f₂ g₂ l :=\nbegin\n  unfold is_O_with,\n  subst c₂,\n  apply filter.eventually_congr,\n  filter_upwards [hf, hg],\n  assume x e₁ e₂,\n  rw [e₁, e₂]\nend\n\ntheorem is_O_with.congr' {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n  (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :\n  is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=\n(is_O_with_congr hc hf hg).mp\n\ntheorem is_O_with.congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n  (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :\n  is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=\nλ h, h.congr' hc (univ_mem_sets' hf) (univ_mem_sets' hg)\n\ntheorem is_O_with.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :\n  is_O_with c f₁ g l → is_O_with c f₂ g l :=\nis_O_with.congr rfl hf (λ _, rfl)\n\ntheorem is_O_with.congr_right {g₁ g₂ : α → F} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :\n  is_O_with c f g₁ l → is_O_with c f g₂ l :=\nis_O_with.congr rfl (λ _, rfl) hg\n\ntheorem is_O_with.congr_const {c₁ c₂} {l : filter α} (hc : c₁ = c₂) :\n  is_O_with c₁ f g l → is_O_with c₂ f g l :=\nis_O_with.congr hc (λ _, rfl) (λ _, rfl)\n\ntheorem is_O_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n    (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :\n  is_O f₁ g₁ l ↔ is_O f₂ g₂ l :=\nby { unfold is_O, exact exists_congr (λ c, is_O_with_congr rfl hf hg) }\n\ntheorem is_O.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n    (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :\n  is_O f₁ g₁ l → is_O f₂ g₂ l :=\n(is_O_congr hf hg).mp\n\ntheorem is_O.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n    (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :\n  is_O f₁ g₁ l → is_O f₂ g₂ l :=\nλ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)\n\ntheorem is_O.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :\n  is_O f₁ g l → is_O f₂ g l :=\nis_O.congr hf (λ _, rfl)\n\ntheorem is_O.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :\n  is_O f g₁ l → is_O f g₂ l :=\nis_O.congr (λ _, rfl) hg\n\ntheorem is_o_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n    (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :\n  is_o f₁ g₁ l ↔ is_o f₂ g₂ l :=\nby { unfold is_o, exact ball_congr (λ c hc, is_O_with_congr (eq.refl c) hf hg) }\n\ntheorem is_o.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n    (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :\n  is_o f₁ g₁ l → is_o f₂ g₂ l :=\n(is_o_congr hf hg).mp\n\ntheorem is_o.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}\n    (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :\n  is_o f₁ g₁ l → is_o f₂ g₂ l :=\nλ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)\n\ntheorem is_o.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :\n  is_o f₁ g l → is_o f₂ g l :=\nis_o.congr hf (λ _, rfl)\n\ntheorem is_o.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :\n  is_o f g₁ l → is_o f g₂ l :=\nis_o.congr (λ _, 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 : β → α} {l' : filter β} (hk : tendsto k l' l):\n  is_O_with c (f ∘ k) (g ∘ k) l' :=\nis_O_with.of_bound $ hk hcfg.bound\n\ntheorem is_O.comp_tendsto (hfg : is_O f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :\n  is_O (f ∘ k) (g ∘ k) l' :=\nis_O_iff_is_O_with.2 $ hfg.is_O_with.imp (λ c h, h.comp_tendsto hk)\n\ntheorem is_o.comp_tendsto (hfg : is_o f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :\n  is_o (f ∘ k) (g ∘ k) l' :=\nis_o.of_is_O_with $ λ c cpos, (hfg.forall_is_O_with cpos).comp_tendsto hk\n\n@[simp] theorem is_O_with_map {k : β → α} {l : filter β} :\n  is_O_with c f g (map k l) ↔ is_O_with c (f ∘ k) (g ∘ k) l :=\nby { unfold is_O_with, exact mem_map }\n\n@[simp] theorem is_O_map {k : β → α} {l : filter β} :\n  is_O f g (map k l) ↔ is_O (f ∘ k) (g ∘ k) l :=\nby simp only [is_O, is_O_with_map]\n\n@[simp] theorem is_o_map {k : β → α} {l : filter β} :\n  is_o f g (map k l) ↔ is_o (f ∘ k) (g ∘ 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 ≤ 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 ≤ l') : is_O f g l :=\nis_O_iff_is_O_with.2 $ h.is_O_with.imp (λ c h, h.mono hl)\n\ntheorem is_o.mono (h : is_o f g l') (hl : l ≤ l') : is_o f g l :=\nis_o.of_is_O_with $ λ 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 ≤ c) :\n  is_O_with (c * c') f k l :=\nbegin\n  unfold is_O_with at *,\n  filter_upwards [hfg, hgk],\n  assume x hx hx',\n  calc ∥f x∥ ≤ c * ∥g x∥ : hx\n  ... ≤ c * (c' * ∥k x∥) : mul_le_mul_of_nonneg_left hx' hc\n  ... = c * c' * ∥k x∥ : (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 ⟨c, cnonneg, hc⟩ := hfg.exists_nonneg, ⟨c', hc'⟩ := 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 ⟨c, cpos, hc⟩ := 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 ⟨c, cpos, hc⟩ := 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 : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O_with c f g l :=\nis_O_with.of_bound $ univ_mem_sets' hfg\n\ntheorem is_O_with_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O_with 1 f g l :=\nis_O_with_of_le' l $ λ x, by { rw one_mul, exact hfg x }\n\ntheorem is_O_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O f g l :=\n(is_O_with_of_le' l hfg).is_O\n\ntheorem is_O_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O f g l :=\n(is_O_with_of_le l hfg).is_O\n\nend\n\ntheorem is_O_with_refl (f : α → E) (l : filter α) : is_O_with 1 f f l :=\nis_O_with_of_le l $ λ _, le_refl _\n\ntheorem is_O_refl (f : α → E) (l : filter α) : 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 : ∀ x, ∥g x∥ ≤ ∥k x∥) (hc : 0 ≤ 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 : ∀ x, ∥g' x∥ ≤ ∥k x∥) :\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 : ∀ x, ∥g x∥ ≤ ∥k x∥) :\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 ⊥ := is_O_with.of_bound $ trivial\n\n@[simp] theorem is_O_bot : is_O f g ⊥ := (is_O_with_bot 1 f g).is_O\n\n@[simp] theorem is_o_bot : is_o f g ⊥ := is_o.of_is_O_with $ λ 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 ⊔ l') :=\nis_O_with.of_bound $ mem_sup_sets.2 ⟨h.bound, h'.bound⟩\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 ⊔ l') :=\nis_O_with.of_bound $\nmem_sup_sets.2 ⟨(h.weaken $ le_max_left c c').bound, (h'.weaken $ le_max_right c c').bound⟩\n\ntheorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l ⊔ l') :=\nlet ⟨c, hc⟩ := h.is_O_with, ⟨c', hc'⟩ := 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 ⊔ l') :=\nis_o.of_is_O_with $\nλ 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 (λ x, ∥g' x∥) l ↔ is_O_with c f g' l :=\nby simp only [is_O_with, norm_norm]\n\nalias is_O_with_norm_right ↔ asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right\n\n@[simp] theorem is_O_norm_right : is_O f (λ x, ∥g' x∥) l ↔ is_O f g' l :=\nby { unfold is_O, exact exists_congr (λ _, is_O_with_norm_right) }\n\nalias is_O_norm_right ↔ asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right\n\n@[simp] theorem is_o_norm_right : is_o f (λ x, ∥g' x∥) l ↔ is_o f g' l :=\nby { unfold is_o, exact forall_congr (λ _, forall_congr $ λ _, is_O_with_norm_right) }\n\nalias is_o_norm_right ↔ asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right\n\n@[simp] theorem is_O_with_norm_left : is_O_with c (λ x, ∥f' x∥) g l ↔ is_O_with c f' g l :=\nby simp only [is_O_with, norm_norm]\n\nalias is_O_with_norm_left ↔ asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left\n\n@[simp] theorem is_O_norm_left : is_O (λ x, ∥f' x∥) g l ↔ is_O f' g l :=\nby { unfold is_O, exact exists_congr (λ _, is_O_with_norm_left) }\n\nalias is_O_norm_left ↔ asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left\n\n@[simp] theorem is_o_norm_left : is_o (λ x, ∥f' x∥) g l ↔ is_o f' g l :=\nby { unfold is_o,  exact forall_congr (λ _, forall_congr $ λ _, is_O_with_norm_left) }\n\nalias is_o_norm_left ↔ asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left\n\ntheorem is_O_with_norm_norm :\n  is_O_with c (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ 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 ↔ asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm\n\ntheorem is_O_norm_norm :\n  is_O (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O f' g' l :=\nis_O_norm_left.trans is_O_norm_right\n\nalias is_O_norm_norm ↔ asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm\n\ntheorem is_o_norm_norm :\n  is_o (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_o f' g' l :=\nis_o_norm_left.trans is_o_norm_right\n\nalias is_o_norm_norm ↔ 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 (λ x, -(g' x)) l ↔ is_O_with c f g' l :=\nby simp only [is_O_with, norm_neg]\n\nalias is_O_with_neg_right ↔ asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right\n\n@[simp] theorem is_O_neg_right : is_O f (λ x, -(g' x)) l ↔ is_O f g' l :=\nby { unfold is_O, exact exists_congr (λ _, is_O_with_neg_right) }\n\nalias is_O_neg_right ↔ asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right\n\n@[simp] theorem is_o_neg_right : is_o f (λ x, -(g' x)) l ↔ is_o f g' l :=\nby { unfold is_o, exact forall_congr (λ _, (forall_congr (λ _, is_O_with_neg_right))) }\n\nalias is_o_neg_right ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right\n\n@[simp] theorem is_O_with_neg_left : is_O_with c (λ x, -(f' x)) g l ↔ is_O_with c f' g l :=\nby simp only [is_O_with, norm_neg]\n\nalias is_O_with_neg_left ↔ asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left\n\n@[simp] theorem is_O_neg_left : is_O (λ x, -(f' x)) g l ↔ is_O f' g l :=\nby { unfold is_O, exact exists_congr (λ _, is_O_with_neg_left) }\n\nalias is_O_neg_left ↔ asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left\n\n@[simp] theorem is_o_neg_left : is_o (λ x, -(f' x)) g l ↔ is_o f' g l :=\nby { unfold is_o, exact forall_congr (λ _, (forall_congr (λ _, is_O_with_neg_left))) }\n\nalias is_o_neg_left ↔ 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' (λ x, (f' x, g' x)) l :=\nis_O_with_of_le l $ λ x, le_max_left _ _\n\nlemma is_O_with_snd_prod : is_O_with 1 g' (λ x, (f' x, g' x)) l :=\nis_O_with_of_le l $ λ x, le_max_right _ _\n\nlemma is_O_fst_prod : is_O f' (λ x, (f' x, g' x)) l := is_O_with_fst_prod.is_O\n\nlemma is_O_snd_prod : is_O g' (λ x, (f' x, g' x)) l := is_O_with_snd_prod.is_O\n\nlemma is_O_fst_prod' {f' : α → E' × F'} : is_O (λ 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' : α → E' × F'} : is_O (λ 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 (λx, (g' x, k' x)) l :=\nlet ⟨c, cnonneg, hc⟩ := 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 (λ x, (g' x, k' x)) l :=\nis_o.of_is_O_with $\nλ 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 ≤ c) :\n  is_O_with c f (λ 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 (λx, (f' x, g' x)) l :=\nlet ⟨c, cnonneg, hc⟩ := 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 (λx, (f' x, g' x)) l :=\nis_o.of_is_O_with $\nλ 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 (λ x, (f' x, g' x)) k' l :=\nby rw is_O_with_iff at *; filter_upwards [hf, hg] λ x, 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') (λ 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 (λ 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 (λ 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 (λ x, (f' x, g' x)) k' l ↔ is_O_with c f' k' l ∧ is_O_with c g' k' l :=\n⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left_same h.2⟩\n\nlemma is_O.prod_left (hf : is_O f' k' l) (hg : is_O g' k' l) : is_O (λ x, (f' x, g' x)) k' l :=\nlet ⟨c, hf⟩ := hf.is_O_with, ⟨c', hg⟩ := hg.is_O_with in (hf.prod_left hg).is_O\n\nlemma is_O.prod_left_fst (h : is_O (λ 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 (λ 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 (λ x, (f' x, g' x)) k' l ↔ is_O f' k' l ∧ is_O g' k' l :=\n⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩\n\nlemma is_o.prod_left (hf : is_o f' k' l) (hg : is_o g' k' l) : is_o (λ x, (f' x, g' x)) k' l :=\nis_o.of_is_O_with $\nλ 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 (λ 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 (λ 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 (λ x, (f' x, g' x)) k' l ↔ is_o f' k' l ∧ is_o g' k' l :=\n⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩\n\nlemma is_O_with.eq_zero_imp (h : is_O_with c f' g' l) : ∀ᶠ x in l, g' x = 0 → f' x = 0 :=\neventually.mono h.bound $ λ 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) : ∀ᶠ x in l, g' x = 0 → f' x = 0 :=\nlet ⟨C, hC⟩ := h.is_O_with in hC.eq_zero_imp\n\n/-! ### Addition and subtraction -/\n\nsection add_sub\n\nvariables {c₁ c₂ : ℝ} {f₁ f₂ : α → E'}\n\ntheorem is_O_with.add (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) :\n  is_O_with (c₁ + c₂) (λ x, f₁ x + f₂ x) g l :=\nby rw is_O_with at *; filter_upwards [h₁, h₂] λ x hx₁ hx₂,\ncalc ∥f₁ x + f₂ x∥ ≤ c₁ * ∥g x∥ + c₂ * ∥g x∥ : norm_add_le_of_le hx₁ hx₂\n               ... = (c₁ + c₂) * ∥g x∥       : (add_mul _ _ _).symm\n\ntheorem is_O.add (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=\nlet ⟨c₁, hc₁⟩ := h₁.is_O_with, ⟨c₂, hc₂⟩ := h₂.is_O_with in (hc₁.add hc₂).is_O\n\ntheorem is_o.add (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x + f₂ x) g l :=\nis_o.of_is_O_with $ λ c cpos, ((h₁.forall_is_O_with $ half_pos cpos).add\n  (h₂.forall_is_O_with $ half_pos cpos)).congr_const (add_halves c)\n\ntheorem is_o.add_add {g₁ g₂ : α → F'} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :\n  is_o (λ x, f₁ x + f₂ x) (λ x, ∥g₁ x∥ + ∥g₂ x∥) l :=\nby refine (h₁.trans_le $ λ x, _).add (h₂.trans_le _);\n  simp [real.norm_eq_abs, abs_of_nonneg, add_nonneg]\n\ntheorem is_O.add_is_o (h₁ : is_O f₁ g l) (h₂ : is_o f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=\nh₁.add h₂.is_O\n\ntheorem is_o.add_is_O (h₁ : is_o f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=\nh₁.is_O.add h₂\n\ntheorem is_O_with.add_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) :\n  is_O_with c₂ (λx, f₁ x + f₂ x) g l :=\n(h₁.add (h₂.forall_is_O_with (sub_pos.2 hc))).congr_const (add_sub_cancel'_right _ _)\n\ntheorem is_o.add_is_O_with (h₁ : is_o f₁ g l) (h₂ : is_O_with c₁ f₂ g l) (hc : c₁ < c₂) :\n  is_O_with c₂ (λx, f₁ x + f₂ x) g l :=\n(h₂.add_is_o h₁ hc).congr_left $ λ _, add_comm _ _\n\ntheorem is_O_with.sub (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) :\n  is_O_with (c₁ + c₂) (λ x, f₁ x - f₂ x) g l :=\nby simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left\n\ntheorem is_O_with.sub_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) :\n  is_O_with c₂ (λ x, f₁ x - f₂ x) g l :=\nby simpa only [sub_eq_add_neg] using h₁.add_is_o h₂.neg_left hc\n\ntheorem is_O.sub (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x - f₂ x) g l :=\nby simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left\n\ntheorem is_o.sub (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x - f₂ x) g l :=\nby simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left\n\nend add_sub\n\n/-! ### Lemmas about `is_O (f₁ - f₂) g l` / `is_o (f₁ - f₂) g l` treated as a binary relation -/\n\nsection is_oO_as_rel\n\nvariables {f₁ f₂ f₃ : α → E'}\n\ntheorem is_O_with.symm (h : is_O_with c (λ x, f₁ x - f₂ x) g l) :\n  is_O_with c (λ x, f₂ x - f₁ x) g l :=\nh.neg_left.congr_left $ λ x, neg_sub _ _\n\ntheorem is_O_with_comm :\n  is_O_with c (λ x, f₁ x - f₂ x) g l ↔ is_O_with c (λ x, f₂ x - f₁ x) g l :=\n⟨is_O_with.symm, is_O_with.symm⟩\n\ntheorem is_O.symm (h : is_O (λ x, f₁ x - f₂ x) g l) : is_O (λ x, f₂ x - f₁ x) g l :=\nh.neg_left.congr_left $ λ x, neg_sub _ _\n\ntheorem is_O_comm : is_O (λ x, f₁ x - f₂ x) g l ↔ is_O (λ x, f₂ x - f₁ x) g l :=\n⟨is_O.symm, is_O.symm⟩\n\ntheorem is_o.symm (h : is_o (λ x, f₁ x - f₂ x) g l) : is_o (λ x, f₂ x - f₁ x) g l :=\nby simpa only [neg_sub] using h.neg_left\n\ntheorem is_o_comm : is_o (λ x, f₁ x - f₂ x) g l ↔ is_o (λ x, f₂ x - f₁ x) g l :=\n⟨is_o.symm, is_o.symm⟩\n\ntheorem is_O_with.triangle (h₁ : is_O_with c (λ x, f₁ x - f₂ x) g l)\n  (h₂ : is_O_with c' (λ x, f₂ x - f₃ x) g l) :\n  is_O_with (c + c') (λ x, f₁ x - f₃ x) g l :=\n(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _\n\ntheorem is_O.triangle (h₁ : is_O (λ x, f₁ x - f₂ x) g l) (h₂ : is_O (λ x, f₂ x - f₃ x) g l) :\n  is_O (λ x, f₁ x - f₃ x) g l :=\n(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _\n\ntheorem is_o.triangle (h₁ : is_o (λ x, f₁ x - f₂ x) g l) (h₂ : is_o (λ x, f₂ x - f₃ x) g l) :\n  is_o (λ x, f₁ x - f₃ x) g l :=\n(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _\n\ntheorem is_O.congr_of_sub (h : is_O (λ x, f₁ x - f₂ x) g l) :\n  is_O f₁ g l ↔ is_O f₂ g l :=\n⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _),\n λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩\n\ntheorem is_o.congr_of_sub (h : is_o (λ x, f₁ x - f₂ x) g l) :\n  is_o f₁ g l ↔ is_o f₂ g l :=\n⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _),\n λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩\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 (λ x, (0 : E')) g' l :=\nis_o.of_bound $ λ c hc, univ_mem_sets' $ λ x,\nby simpa using mul_nonneg (le_of_lt hc) (norm_nonneg $ g' x)\n\ntheorem is_O_with_zero (hc : 0 ≤ c) : is_O_with c (λ x, (0 : E')) g' l :=\nis_O_with.of_bound $ univ_mem_sets' $ λ x, by simpa using mul_nonneg hc (norm_nonneg $ g' x)\n\ntheorem is_O_with_zero' : is_O_with 0 (λ x, (0 : E')) g l :=\nis_O_with.of_bound $ univ_mem_sets' $ λ x, by simp\n\ntheorem is_O_zero : is_O (λ x, (0 : E')) g l :=\nis_O_iff_is_O_with.2 ⟨0, is_O_with_zero' _ _⟩\n\ntheorem is_O_refl_left : is_O (λ x, f' x - f' x) g' l :=\n(is_O_zero g' l).congr_left $ λ x, (sub_self _).symm\n\ntheorem is_o_refl_left : is_o (λ x, f' x - f' x) g' l :=\n(is_o_zero g' l).congr_left $ λ 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' (λ x, (0 : F')) l ↔ ∀ᶠ 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' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=\n⟨λ h, let ⟨c, hc⟩ := h.is_O_with in is_O_with_zero_right_iff.1 hc,\n  λ h, (is_O_with_zero_right_iff.2 h : is_O_with 1 _ _ _).is_O⟩\n\n@[simp] theorem is_o_zero_right_iff :\n  is_o f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=\n⟨λ h, is_O_zero_right_iff.1 h.is_O,\n  λ h, is_o.of_is_O_with $ λ c hc, is_O_with_zero_right_iff.2 h⟩\n\ntheorem is_O_with_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) :\n  is_O_with (∥c∥ / ∥c'∥) (λ x : α, c) (λ x, c') l :=\nbegin\n  unfold is_O_with,\n  apply univ_mem_sets',\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' ≠ 0) (l : filter α) :\n  is_O (λ x : α, c) (λ 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 ⊤ ↔ ∀ x, ∥f x∥ ≤ c * ∥g x∥ := by rw is_O_with; refl\n\n@[simp] lemma is_O_top : is_O f g ⊤ ↔ ∃ C, ∀ x, ∥f x∥ ≤ C * ∥g x∥ := by rw is_O_iff; refl\n\n@[simp] lemma is_o_top : is_o f' g' ⊤ ↔ ∀ x, f' x = 0 :=\nbegin\n  refine ⟨_, λ h, (is_o_zero g' ⊤).congr (λ x, (h x).symm) (λ x, rfl)⟩,\n  simp only [is_o_iff, eventually_top],\n  refine λ h x, norm_le_zero_iff.1 _,\n  have : tendsto (λ c : ℝ, c * ∥g' x∥) (𝓝[Ioi 0] 0) (𝓝 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 $ λ c hc, h hc x)\nend\n\n@[simp] lemma is_O_with_principal {s : set α} :\n  is_O_with c f g (𝓟 s) ↔ ∀ x ∈ s, ∥f x∥ ≤ c * ∥g x∥ :=\nby rw is_O_with; refl\n\nlemma is_O_principal {s : set α} :\n  is_O f g (𝓟 s) ↔ ∃ c, ∀ x ∈ s, ∥f x∥ ≤ c * ∥g x∥ :=\nby rw is_O_iff; refl\n\ntheorem is_O_with_const_one (c : E) (l : filter α) : is_O_with ∥c∥ (λ x : α, c) (λ x, (1 : 𝕜)) 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 α) : is_O (λ x : α, c) (λ x, (1 : 𝕜)) l :=\n(is_O_with_const_one c l).is_O\n\nsection\n\nvariable (𝕜)\n\ntheorem is_o_const_iff_is_o_one {c : F'} (hc : c ≠ 0) :\n  is_o f (λ x, c) l ↔ is_o f (λ x, (1:𝕜)) l :=\n⟨λ h, h.trans_is_O $ is_O_const_one c l, λ h, h.trans_is_O $ is_O_const_const _ hc _⟩\n\nend\n\ntheorem is_o_const_iff {c : F'} (hc : c ≠ 0) :\n  is_o f' (λ x, c) l ↔ tendsto f' l (𝓝 0) :=\n(is_o_const_iff_is_o_one ℝ 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 ≠ 0) :\n  is_o (λ (x : E'), x) (λ x, c) (𝓝 0) :=\n(is_o_const_iff hc).mpr (continuous_id.tendsto 0)\n\ntheorem is_O_const_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) {c : F'} (hc : c ≠ 0) :\n  is_O f' (λ x, c) l :=\nbegin\n  refine is_O.trans _ (is_O_const_const (∥y∥ + 1) hc l),\n  refine is_O.of_bound 1 _,\n  simp only [is_O_with, one_mul],\n  have : tendsto (λx, ∥f' x∥) l (𝓝 ∥y∥), from (continuous_norm.tendsto _).comp h,\n  have Iy : ∥y∥ < ∥∥y∥ + 1∥, from lt_of_lt_of_le (lt_add_one _) (le_abs_self _),\n  exact this (ge_mem_nhds Iy)\nend\n\nsection\n\nvariable (𝕜)\n\ntheorem is_o_one_iff : is_o f' (λ x, (1 : 𝕜)) l ↔ tendsto f' l (𝓝 0) :=\nis_o_const_iff one_ne_zero\n\ntheorem is_O_one_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) :\n  is_O f' (λ x, (1:𝕜)) 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 (𝓝 y)) :\n  is_O f (λ x, (1:𝕜)) l :=\nhfg.trans $ is_O_one_of_tendsto 𝕜 hg\n\nend\n\ntheorem is_O.trans_tendsto (hfg : is_O f' g' l) (hg : tendsto g' l (𝓝 0)) :\n  tendsto f' l (𝓝 0) :=\n(is_o_one_iff ℝ).1 $ hfg.trans_is_o $ (is_o_one_iff ℝ).2 hg\n\ntheorem is_o.trans_tendsto (hfg : is_o f' g' l) (hg : tendsto g' l (𝓝 0)) :\n  tendsto f' l (𝓝 0) :=\nhfg.is_O.trans_tendsto hg\n\n/-! ### Multiplication by a constant -/\n\ntheorem is_O_with_const_mul_self (c : R) (f : α → R) (l : filter α) :\n  is_O_with ∥c∥ (λ x, c * f x) f l :=\nis_O_with_of_le' _ $ λ x, norm_mul_le _ _\n\ntheorem is_O_const_mul_self (c : R) (f : α → R) (l : filter α) :\n  is_O (λ 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 : α → R} (h : is_O_with c f g l) (c' : R) :\n  is_O_with (∥c'∥ * c) (λ 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 : α → R} (h : is_O f g l) (c' : R) :\n  is_O (λ x, c' * f x) g l :=\nlet ⟨c, hc⟩ := h.is_O_with in (hc.const_mul_left c').is_O\n\ntheorem is_O_with_self_const_mul' (u : units R) (f : α → R) (l : filter α) :\n  is_O_with ∥(↑u⁻¹:R)∥ f (λ x, ↑u * f x) l :=\n(is_O_with_const_mul_self ↑u⁻¹ _ l).congr_left $ λ x, u.inv_mul_cancel_left (f x)\n\ntheorem is_O_with_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) :\n  is_O_with ∥c∥⁻¹ f (λ 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 : α → R) (l : filter α) :\n  is_O f (λ x, c * f x) l :=\nlet ⟨u, hu⟩ := hc in hu ▸ (is_O_with_self_const_mul' u f l).is_O\n\ntheorem is_O_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) :\n  is_O f (λ 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 : α → R} {c : R} (hc : is_unit c) :\n  is_O (λ x, c * f x) g l ↔ is_O f g l :=\n⟨(is_O_self_const_mul' hc f l).trans, λ h, h.const_mul_left c⟩\n\ntheorem is_O_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :\n  is_O (λ x, c * f x) g l ↔ is_O f g l :=\nis_O_const_mul_left_iff' $ is_unit.mk0 c hc\n\ntheorem is_o.const_mul_left {f : α → R} (h : is_o f g l) (c : R) :\n  is_o (λ 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 : α → R} {c : R} (hc : is_unit c) :\n  is_o (λ x, c * f x) g l ↔ is_o f g l :=\n⟨(is_O_self_const_mul' hc f l).trans_is_o, λ h, h.const_mul_left c⟩\n\ntheorem is_o_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :\n  is_o (λ x, c * f x) g l ↔ 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 : α → R} {c : R} (hc' : 0 ≤ c')\n  (h : is_O_with c' f (λ x, c * g x) l) :\n  is_O_with (c' * ∥c∥) f g l :=\nh.trans (is_O_with_const_mul_self c g l) hc'\n\ntheorem is_O.of_const_mul_right {g : α → R} {c : R}\n  (h : is_O f (λ x, c * g x) l) :\n  is_O f g l :=\nlet ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.of_const_mul_right cnonneg).is_O\n\ntheorem is_O_with.const_mul_right' {g : α → R} {u : units R} {c' : ℝ} (hc' : 0 ≤ c')\n  (h : is_O_with c' f g l) :\n  is_O_with (c' * ∥(↑u⁻¹:R)∥) f (λ x, ↑u * g x) l :=\nh.trans (is_O_with_self_const_mul' _ _ _) hc'\n\ntheorem is_O_with.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0)\n  {c' : ℝ} (hc' : 0 ≤ c') (h : is_O_with c' f g l) :\n  is_O_with (c' * ∥c∥⁻¹) f (λ 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 : α → R} {c : R} (hc : is_unit c) (h : is_O f g l) :\n  is_O f (λ x, c * g x) l :=\nh.trans (is_O_self_const_mul' hc g l)\n\ntheorem is_O.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_O f g l) :\n  is_O f (λ x, c * g x) l :=\nh.const_mul_right' $ is_unit.mk0 c hc\n\ntheorem is_O_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) :\n  is_O f (λ x, c * g x) l ↔ is_O f g l :=\n⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩\n\ntheorem is_O_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :\n  is_O f (λ x, c * g x) l ↔ 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 : α → R} {c : R} (h : is_o f (λ 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 : α → R} {c : R} (hc : is_unit c) (h : is_o f g l) :\n  is_o f (λ 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 : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_o f g l) :\n  is_o f (λ x, c * g x) l :=\nh.const_mul_right' $ is_unit.mk0 c hc\n\ntheorem is_o_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) :\n  is_o f (λ x, c * g x) l ↔ is_o f g l :=\n⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩\n\ntheorem is_o_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :\n  is_o f (λ x, c * g x) l ↔ 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₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ}\n  (h₁ : is_O_with c₁ f₁ g₁ l) (h₂ : is_O_with c₂ f₂ g₂ l) :\n  is_O_with (c₁ * c₂) (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=\nbegin\n  unfold is_O_with at *,\n  filter_upwards [h₁, h₂],\n  intros x hx₁ hx₂,\n  apply le_trans (norm_mul_le _ _),\n  convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1,\n  rw normed_field.norm_mul,\n  ac_refl\nend\n\ntheorem is_O.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}\n  (h₁ : is_O f₁ g₁ l) (h₂ : is_O f₂ g₂ l) :\n  is_O (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=\nlet ⟨c, hc⟩ := h₁.is_O_with, ⟨c', hc'⟩ := h₂.is_O_with in (hc.mul hc').is_O\n\ntheorem is_O.mul_is_o {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}\n  (h₁ : is_O f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :\n  is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=\nbegin\n  unfold is_o at *,\n  intros c cpos,\n  rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩,\n  exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel' _ (ne_of_gt c'pos))\nend\n\ntheorem is_o.mul_is_O {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}\n  (h₁ : is_o f₁ g₁ l) (h₂ : is_O f₂ g₂ l) :\n  is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=\nbegin\n  unfold is_o at *,\n  intros c cpos,\n  rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩,\n  exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel _ (ne_of_gt c'pos))\nend\n\ntheorem is_o.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :\n  is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=\nh₁.mul_is_O h₂.is_O\n\ntheorem is_O_with.pow' {f : α → R} {g : α → 𝕜} (h : is_O_with c f g l) :\n  ∀ n : ℕ, is_O_with (nat.cases_on n ∥(1 : R)∥ (λ n, c ^ (n + 1))) (λ x, f x ^ n) (λ x, g x ^ n) l\n| 0 := by simpa using is_O_with_const_const (1 : R) (@one_ne_zero 𝕜 _ _) 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 : α → R} {g : α → 𝕜} (h : is_O_with c f g l) :\n  ∀ n : ℕ, is_O_with (c ^ n) (λ x, f x ^ n) (λ 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 : α → R} {g : α → 𝕜} (h : is_O f g l) (n : ℕ) :\n  is_O (λ x, f x ^ n) (λ x, g x ^ n) l :=\nlet ⟨C, hC⟩ := h.is_O_with in is_O_iff_is_O_with.2 ⟨_, hC.pow' n⟩\n\ntheorem is_o.pow {f : α → R} {g : α → 𝕜} (h : is_o f g l) {n : ℕ} (hn : 0 < n) :\n  is_o (λ x, f x ^ n) (λ 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/-! ### Scalar multiplication -/\n\nsection smul_const\nvariables [normed_space 𝕜 E']\n\ntheorem is_O_with.const_smul_left (h : is_O_with c f' g l) (c' : 𝕜) :\n  is_O_with (∥c'∥ * c) (λ x, c' • f' x) g l :=\nby refine ((h.norm_left.const_mul_left (∥c'∥)).congr _ _ (λ _, rfl)).of_norm_left;\n    intros; simp only [norm_norm, norm_smul]\n\ntheorem is_O_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) :\n  is_O (λ x, c • f' x) g l ↔ is_O f' g l :=\nbegin\n  have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,\n  rw [←is_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 : 𝕜) :\n  is_o (λ x, c • f' x) g l :=\nbegin\n  refine ((h.norm_left.const_mul_left (∥c∥)).congr_left _).of_norm_left,\n  exact λ x, (norm_smul _ _).symm\nend\n\ntheorem is_o_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) :\n  is_o (λ x, c • f' x) g l ↔ is_o f' g l :=\nbegin\n  have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,\n  rw [←is_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 : 𝕜} (hc : c ≠ 0) :\n  is_O f (λ x, c • f' x) l ↔ is_O f f' l :=\nbegin\n  have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,\n  rw [←is_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 : 𝕜} (hc : c ≠ 0) :\n  is_o f (λ x, c • f' x) l ↔ is_o f f' l :=\nbegin\n  have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,\n  rw [←is_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 𝕜 E'] [normed_space 𝕜 F']\n\ntheorem is_O_with.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O_with c k₁ k₂ l) (h₂ : is_O_with c' f' g' l) :\n  is_O_with (c * c') (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=\nby refine ((h₁.norm_norm.mul h₂.norm_norm).congr rfl _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_O.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_O f' g' l) :\n  is_O (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=\nby refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_O.smul_is_o {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_o f' g' l) :\n  is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=\nby refine ((h₁.norm_norm.mul_is_o h₂.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_o.smul_is_O {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_O f' g' l) :\n  is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=\nby refine ((h₁.norm_norm.mul_is_O h₂.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\ntheorem is_o.smul {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_o f' g' l) :\n  is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=\nby refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm;\n  by intros; simp only [norm_smul]\n\nend smul\n\n/-! ### Sum -/\n\nsection sum\n\nvariables {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : finset ι}\n\ntheorem is_O_with.sum (h : ∀ i ∈ s, is_O_with (C i) (A i) g l) :\n  is_O_with (∑ i in s, C i) (λ x, ∑ 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 (λ j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\ntheorem is_O.sum (h : ∀ i ∈ s, is_O (A i) g l) :\n  is_O (λ x, ∑ 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 (λ j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\ntheorem is_o.sum (h : ∀ i ∈ s, is_o (A i) g' l) :\n  is_o (λ x, ∑ 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 (λ j hj, h _ (finset.mem_insert_of_mem hj))) }\nend\n\nend sum\n\n/-! ### Relation between `f = o(g)` and `f / g → 0` -/\n\ntheorem is_o.tendsto_0 {f g : α → 𝕜} {l : filter α} (h : is_o f g l) :\n  tendsto (λ x, f x / (g x)) l (𝓝 0) :=\nhave eq₁ : is_o (λ x, f x / g x) (λ x, g x / g x) l,\n  by simpa only [div_eq_mul_inv] using h.mul_is_O (is_O_refl _ _),\nhave eq₂ : is_O (λ x, g x / g x) (λ x, (1 : 𝕜)) l,\n  from is_O_of_le _ (λ x, by by_cases h : ∥g x∥ = 0; simp [h, zero_le_one]),\n(is_o_one_iff 𝕜).mp (eq₁.trans_is_O eq₂)\n\ntheorem is_o_iff_tendsto' {f g : α → 𝕜} {l : filter α}\n    (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) :\n  is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0) :=\niff.intro is_o.tendsto_0 $ λ h,\n  (((is_o_one_iff _).mpr h).mul_is_O (is_O_refl g l)).congr'\n    (hgf.mono $ λ x, div_mul_cancel_of_imp) (eventually_of_forall $ λ x, one_mul _)\n\ntheorem is_o_iff_tendsto {f g : α → 𝕜} {l : filter α}\n    (hgf : ∀ x, g x = 0 → f x = 0) :\n  is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0) :=\n⟨λ h, h.tendsto_0, (is_o_iff_tendsto' (eventually_of_forall hgf)).2⟩\n\nalias is_o_iff_tendsto' ↔ _ asymptotics.is_o_of_tendsto'\nalias is_o_iff_tendsto ↔ _ asymptotics.is_o_of_tendsto\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 : α → 𝕜}\n\nlemma is_O_with.eventually_mul_div_cancel (h : is_O_with c u v l) :\n  (u / v) * v =ᶠ[l] u :=\neventually.mono h.bound (λ y hy, div_mul_cancel_of_imp $ λ 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 =ᶠ[l] u :=\nlet ⟨c, hc⟩ := 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 =ᶠ[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 `∃ φ, u =ᶠ[l] φ * v` in a `normed_field`. -/\n\nsection exists_mul_eq\n\nvariables {u v : α → 𝕜}\n\n/-- If `∥φ∥` is eventually bounded by `c`, and `u =ᶠ[l] φ * 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 (φ : α → 𝕜) (hφ : ∀ᶠ x in l, ∥φ x∥ ≤ c) (h : u =ᶠ[l] φ * v) :\n  is_O_with c u v l :=\nbegin\n  unfold is_O_with,\n  refine h.symm.rw (λ x a, ∥a∥ ≤ c * ∥v x∥) (hφ.mono $ λ 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 ≤ c) :\n  is_O_with c u v l ↔ ∃ (φ : α → 𝕜) (hφ : ∀ᶠ x in l, ∥φ x∥ ≤ c), u =ᶠ[l] φ * v :=\nbegin\n  split,\n  { intro h,\n    use (λ x, u x / v x),\n    refine ⟨eventually.mono h.bound (λ y hy, _), h.eventually_mul_div_cancel.symm⟩,\n    simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy },\n  { rintros ⟨φ, hφ, h⟩,\n    exact is_O_with_of_eq_mul φ hφ h }\nend\n\nlemma is_O_with.exists_eq_mul (h : is_O_with c u v l) (hc : 0 ≤ c) :\n  ∃ (φ : α → 𝕜) (hφ : ∀ᶠ x in l, ∥φ x∥ ≤ c), u =ᶠ[l] φ * 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 ↔ ∃ (φ : α → 𝕜) (hφ : l.is_bounded_under (≤) (norm ∘ φ)), u =ᶠ[l] φ * v :=\nbegin\n  split,\n  { rintros h,\n    rcases h.exists_nonneg with ⟨c, hnnc, hc⟩,\n    rcases hc.exists_eq_mul hnnc with ⟨φ, hφ, huvφ⟩,\n    exact ⟨φ, ⟨c, hφ⟩, huvφ⟩ },\n  { rintros ⟨φ, ⟨c, hφ⟩, huvφ⟩,\n    exact is_O_iff_is_O_with.2 ⟨c, is_O_with_of_eq_mul φ hφ huvφ⟩ }\nend\n\nalias is_O_iff_exists_eq_mul ↔ asymptotics.is_O.exists_eq_mul _\n\nlemma is_o_iff_exists_eq_mul :\n  is_o u v l ↔ ∃ (φ : α → 𝕜) (hφ : tendsto φ l (𝓝 0)), u =ᶠ[l] φ * v :=\nbegin\n  split,\n  { exact λ h, ⟨λ x, u x / v x, h.tendsto_0, h.eventually_mul_div_cancel.symm⟩ },\n  { unfold is_o, rintros ⟨φ, hφ, huvφ⟩ c hpos,\n    rw normed_group.tendsto_nhds_zero at hφ,\n    exact is_O_with_of_eq_mul _ ((hφ c hpos).mono $ λ x, le_of_lt)  huvφ }\nend\n\nalias is_o_iff_exists_eq_mul ↔ asymptotics.is_o.exists_eq_mul _\n\nend exists_mul_eq\n\n/-! ### Miscellanous lemmas -/\n\ntheorem div_is_bounded_under_of_is_O {α : Type*} {l : filter α}\n  {f g : α → 𝕜} (h : is_O f g l) :\n  is_bounded_under (≤) l (λ x, ∥f x / g x∥) :=\nbegin\n  obtain ⟨c, hc⟩ := is_O_iff.mp h,\n  refine ⟨max c 0, eventually_map.2 (filter.mem_sets_of_superset hc (λ x hx, _))⟩,\n  simp only [mem_set_of_eq, normed_field.norm_div] at ⊢ 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 {α : Type*} {l : filter α}\n  {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) :\n  is_O f g l ↔ is_bounded_under (≤) l (λ x, ∥f x / g x∥) :=\nbegin\n  refine ⟨div_is_bounded_under_of_is_O, λ h, _⟩,\n  obtain ⟨c, hc⟩ := 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 ⟨c, filter.eventually_of_mem (inter_mem_sets hgf hc) (λ x hx, _)⟩,\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 {α : Type*} {l : filter α}\n  {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0)\n  (c : 𝕜) (H : filter.tendsto (f / g) l (𝓝 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 {α E 𝕜 : Type*} [normed_group E] [normed_field 𝕜] {u : α → E}\n  {v : α → 𝕜} {l : filter α} {y : 𝕜} (huv : is_o u v l) (hv : tendsto v l (𝓝 y)) :\n  tendsto u l (𝓝 0) :=\nbegin\n  suffices h : is_o u (λ x, (1 : 𝕜)) l,\n  { rwa is_o_one_iff at h },\n  exact huv.trans_is_O (is_O_one_of_tendsto 𝕜 hv),\nend\n\ntheorem is_o_pow_pow {m n : ℕ} (h : m < n) :\n  is_o (λ(x : 𝕜), x^n) (λx, x^m) (𝓝 0) :=\nbegin\n  let p := n - m,\n  have nmp : n = m + p := (nat.add_sub_cancel' (le_of_lt h)).symm,\n  have : (λ(x : 𝕜), x^m) = (λx, 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 : 𝕜),\n  exact (zero_pow (nat.sub_pos_of_lt h)).symm\nend\n\ntheorem is_o_norm_pow_norm_pow {m n : ℕ} (h : m < n) :\n  is_o (λ(x : E'), ∥x∥^n) (λx, ∥x∥^m) (𝓝 (0 : E')) :=\n(is_o_pow_pow h).comp_tendsto tendsto_norm_zero\n\ntheorem is_o_pow_id {n : ℕ} (h : 1 < n) :\n  is_o (λ(x : 𝕜), x^n) (λx, x) (𝓝 0) :=\nby { convert is_o_pow_pow h, simp only [pow_one] }\n\ntheorem is_o_norm_pow_id {n : ℕ} (h : 1 < n) :\n  is_o (λ(x : E'), ∥x∥^n) (λx, x) (𝓝 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₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :\n  is_O_with (1 / (1 - c)) f₂ (λx, f₂ x - f₁ x) l :=\nis_O_with.of_bound $ mem_sets_of_superset h.bound $ λ x hx,\nbegin\n  simp only [mem_set_of_eq] at hx ⊢,\n  rw [mul_comm, one_div, ← 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₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :\n  is_O_with (1 / (1 - c)) f₂ (λx, f₁ x + f₂ x) l :=\n(h.neg_right.right_le_sub_of_lt_1 hc).neg_right.of_neg_left.congr rfl (λ x, rfl)\n  (λ x, by rw [neg_sub, sub_neg_eq_add])\n\ntheorem is_o.right_is_O_sub {f₁ f₂ : α → E'} (h : is_o f₁ f₂ l) :\n  is_O f₂ (λx, f₂ x - f₁ 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₁ f₂ : α → E'} (h : is_o f₁ f₂ l) :\n  is_O f₂ (λx, f₁ x + f₂ 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`∥f x∥ ≤ C * ∥g x∥` whenever `g x ≠ 0`. -/\ntheorem bound_of_is_O_cofinite (h : is_O f g' cofinite) :\n  ∃ C > 0, ∀ ⦃x⦄, g' x ≠ 0 → ∥f x∥ ≤ C * ∥g' x∥ :=\nbegin\n  rcases h.exists_pos with ⟨C, C₀, hC⟩,\n  rw [is_O_with, eventually_cofinite] at hC,\n  rcases (hC.to_finset.image (λ x, ∥f x∥ / ∥g' x∥)).exists_le with ⟨C', hC'⟩,\n  have : ∀ x, C * ∥g' x∥ < ∥f x∥ → ∥f x∥ / ∥g' x∥ ≤ C', by simpa using hC',\n  refine ⟨max C C', lt_max_iff.2 (or.inl C₀), λ x h₀, _⟩,\n  rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le],\n  exact λ hx, (div_le_iff (norm_pos_iff.2 h₀)).1 (this _ hx)\nend\n\ntheorem is_O_cofinite_iff (h : ∀ x, g' x = 0 → f' x = 0) :\n  is_O f' g' cofinite ↔ ∃ C, ∀ x, ∥f' x∥ ≤ C * ∥g' x∥ :=\n⟨λ h', let ⟨C, C₀, hC⟩ := bound_of_is_O_cofinite h' in\n  ⟨C, λ x, if hx : g' x = 0 then by simp [h _ hx, hx] else hC hx⟩,\n  λ h, (is_O_top.2 h).mono le_top⟩\n\ntheorem bound_of_is_O_nat_at_top {f : ℕ → E} {g' : ℕ → E'} (h : is_O f g' at_top) :\n  ∃ C > 0, ∀ ⦃x⦄, g' x ≠ 0 → ∥f x∥ ≤ C * ∥g' x∥ :=\nbound_of_is_O_cofinite $ by rwa nat.cofinite_eq_at_top\n\ntheorem is_O_nat_at_top_iff {f : ℕ → E'} {g : ℕ → F'} (h : ∀ x, g x = 0 → f x = 0) :\n  is_O f g at_top ↔ ∃ C, ∀ x, ∥f x∥ ≤ C * ∥g x∥ :=\nby rw [← nat.cofinite_eq_at_top, is_O_cofinite_iff h]\n\ntheorem is_O_one_nat_at_top_iff {f : ℕ → E'} :\n  is_O f (λ n, 1 : ℕ → ℝ) at_top ↔ ∃ C, ∀ n, ∥f n∥ ≤ C :=\niff.trans (is_O_nat_at_top_iff (λ n h, (one_ne_zero h).elim)) $\n  by simp only [norm_one, mul_one]\n\ntheorem is_O_with_pi {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)]\n  {f : α → Π i, E' i} {C : ℝ} (hC : 0 ≤ C) :\n  is_O_with C f g' l ↔ ∀ i, is_O_with C (λ x, f x i) g' l :=\nhave ∀ x, 0 ≤ C * ∥g' x∥, from λ 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 {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)]\n  {f : α → Π i, E' i} :\n  is_O f g' l ↔ ∀ i, is_O (λ x, f x i) g' l :=\nbegin\n  simp only [is_O_iff_eventually_is_O_with, ← eventually_all],\n  exact eventually_congr (eventually_at_top.2 ⟨0, λ c, is_O_with_pi⟩)\nend\n\n@[simp] theorem is_o_pi {ι : Type*} [fintype ι] {E' : ι → Type*} [Π i, normed_group (E' i)]\n  {f : α → Π i, E' i} :\n  is_o f g' l ↔ ∀ i, is_o (λ x, f x i) g' l :=\nbegin\n  simp only [is_o, is_O_with_pi, le_of_lt] { contextual := tt },\n  exact ⟨λ h i c hc, h hc i, λ h c hc i, h i hc⟩\nend\n\nend asymptotics\n\nopen asymptotics\n\nlemma summable_of_is_O {ι E} [normed_group E] [complete_space E] {f : ι → E} (g : ι → ℝ)\n  (hg : summable g) (h : is_O f g cofinite) : summable f :=\nlet ⟨C, hC⟩ := h.is_O_with in\nsummable_of_norm_bounded_eventually (λ x, C * ∥g x∥) (hg.abs.mul_left _) hC.bound\n\nlemma summable_of_is_O_nat {E} [normed_group E] [complete_space E] {f : ℕ → E} (g : ℕ → ℝ)\n  (hg : summable g) (h : is_O f g at_top) : summable f :=\nsummable_of_is_O g hg $ nat.cofinite_eq_at_top.symm ▸ h\n\nnamespace local_homeomorph\n\nvariables {α : Type*} {β : Type*} [topological_space α] [topological_space β]\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 α β) {b : β} (hb : b ∈ e.target)\n  {f : β → E} {g : β → F} {C : ℝ} :\n  is_O_with C f g (𝓝 b) ↔ is_O_with C (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=\n⟨λ h, h.comp_tendsto $\n  by { convert e.continuous_at (e.map_target hb), exact (e.right_inv hb).symm },\n  λ h, (h.comp_tendsto (e.continuous_at_symm hb)).congr' rfl\n    ((e.eventually_right_inverse hb).mono $ λ x hx, congr_arg f hx)\n    ((e.eventually_right_inverse hb).mono $ λ x hx, congr_arg g hx)⟩\n\n/-- Transfer `is_O` over a `local_homeomorph`. -/\nlemma is_O_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} :\n  is_O f g (𝓝 b) ↔ is_O (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=\nby { unfold is_O, exact exists_congr (λ C, e.is_O_with_congr hb) }\n\n/-- Transfer `is_o` over a `local_homeomorph`. -/\nlemma is_o_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} :\n  is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=\nby { unfold is_o, exact (forall_congr $ λ c, forall_congr $ λ hc, e.is_O_with_congr hb) }\n\nend local_homeomorph\n\nnamespace homeomorph\n\nvariables {α : Type*} {β : Type*} [topological_space α] [topological_space β]\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 : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} {C : ℝ} :\n  is_O_with C f g (𝓝 b) ↔ is_O_with C (f ∘ e) (g ∘ e) (𝓝 (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 : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} :\n  is_O f g (𝓝 b) ↔ is_O (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=\nby { unfold is_O, exact exists_congr (λ C, e.is_O_with_congr) }\n\n/-- Transfer `is_o` over a `homeomorph`. -/\nlemma is_o_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} :\n  is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=\nby { unfold is_o, exact forall_congr (λ c, forall_congr (λ hc, e.is_O_with_congr)) }\n\nend homeomorph\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/asymptotics/asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.773815915991048}}
{"text": "import tactic --hide\n\n/-\n\n#Logical statements \n\nIn Logic, a *statement* is a sentence that is either true of false, for example: \n\n```md\n1. The sum of two odd numbers is an even number\n2. 36 is divisible by 3\n3. x > 2\n```\n\nOne of the goals of this game is to show you how to work with logical statements on a computer, \nspecifically using a computer language called Lean. In Lean, logical staments live in a \nplace called `Prop` (which is short for \"Propositions\"). For example, if we write  <mark style =\"background-color :   #ebdef0 \">`P : Prop`</mark> \nwe mean \"`P` is a logical statement.\"  Think of the \"`:`\" symbol as saying `P` lives in `Prop` \n(in Maths this would be denoted by `P ∈ Prop`, to mean `P` is an element of `Prop`).\n\n#Truth Values\n\nThe *truth value* of a logical statement (i.e. some `P : Prop` is whether the statement is true or \nfalse. For example, the truth value of the statement: \"For all integers $x ∈ ℤ$, $0 ≤ x^2$\" \nis *true*, while \"For all integers $x ∈ ℤ$, $0 ≤ x^3$\" is *false*. \n\nIn Lean we assign truth values as follows: We first think of a proposition $P$ as a set with \n*at most* one element. If this set is empty, then we say `P` is *false*. Otherwise, if this set has \nan element, lets call it `p`, then this statement is *true* and `p` is the proof. We will usually \nuse upper case letters for logical statements, and lower case for their proofs.\n\nTo recap, we write `P : Prop` to mean `P` is a \nproposition and we write  <mark style =\"background-color : #ebdef0 \">`p : P`</mark>  to mean \"`p` is a \nproof of `P`\".\n\nThe aim of this game is to learn how to prove logical statements, which we call *lemmas* through a\nseries of manipulations which we call *tactics*. \n \nLets start with a simple example of how a lemma looks like in Lean.\n\nThis is where the window on the right will come into play. If you delete the *sorry* below, \non the right you will see the following state: \n\n```\nP : Prop,\np : P,\n⊢ P\n```\n\nHere, the first two lines are our assumptions, where the first line `P : Prop` says \"$P$ is a \nlogical statement\" and the second line `p : P` says `p` is the proof of `P`.\n\nThe thing after the `⊢` symbol is what we need to prove to win the level (i.e. prove the lemma).\n\nIn this game our \"moves\" or, as we call them in Lean, *tactics*, are what will allow us to \nmanipulate our statements and produce proofs.\n\nThe first tactic we will use is called *exact*. It is used when you need to prove a \nstatement $P$ and you have the proof of it. In the example above we have `p : P` and we need to\nprove `P`, then typing <mark style =\"background-color :   #ebdef0 \">`exact p,`</mark>  will prove it. \n\n**Note:  We end each line with a comma `,` to tell Lean that this is the end of our move.** \n\nTry it for yourself now and see what happens!\n\n-/\n\n\n/- Lemma\nIf $P$ is a logical stament and $p$ is a proof of $P$ then $P$ is true.\n-/\nlemma example_one (P : Prop) (p : P) : P :=\nbegin\n  exact p,\n\n\nend\n\n/- Tactic : exact\n## Summary \nIf the goal is `⊢ P` then `exact p,` will close the goal if\nand only if `p` is a proof of `P` (i.e. `p : P`) \n## Details\nSay $P$, $Q$ and $R$ are logical staments\nand your lemma looks like this: \n```\np : P,\nh : P → Q,\nj : Q → R\n⊢ R\n```\nThen you can solve the level by using `exact j(h(p)),`\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/tutorial/tutorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7737570320345435}}
{"text": "/-\nIn this unit, we implement our own version of the Boolean algebra\nalready built into Lean. We will define our own version of Lean's\nbool type, and our own versions of its and, or, and not operators.\n-/\n\n/-\nIn doing this, we will encounter several important concepts in\nLean, which are also shared by many other languages. They include\nthe following:\n\n- namespaces\n- inductive type definitions \n- sets, product sets, tuples, binary relations, and functions\n- type judgments, type declarations, and type inference\n- function types and function values\n- functional programing: case analysis via pattern matching\n-/\n\n\n-- NAMESPACES\n\n/-\nPicking good names for concepts is important in every field.\nIt's  especially important in computer science and software\ndevelopment because we want complex \"code,\" often involving \nhundreds, thousands, or even millions of identifiers (the\nCS term for a name to which a meaning is given in a program), \nto be humanly understandable.\n\nFor example, rather than using a cryptic identifier, such as\n\"n\", to refer to the \"next node\" to be processed in a loop,\none might instead use the identifier \"next_node\". It makes\nno difference to the machine, but it makes a big difference\nto the programmer coming to the code for the first time or\nreturning to it after some time has passed. The names that \nwe pick in this way can serve to document the intended \ninterpretation of the otherwise cryptic logic of the code.\n\nA problem arises, of course, when two programmers, working\non two different parts of a larger program, decide to use\nthe same name for different concepts. One can imagine two\nprogrammers both deciding to use \"next_node\" to refer to\nthe next object to be processed in two unrelated pieces of\ncode. When those pieces of code are brought together, the\nresult could be that the name becomes ambiguous: with two\ndifferent meanings.\n\nA general solution to this problem employed by many\ndifferent programming languages is to define meanings\nfor identifiers within different namespaces. A namespace\nis just a prefix that it implicitly prepended to each\nname defined within the namespace. \n\nIf you've programmed in Python, Java, or most any other\nindustrial programming language, then you've seen the \nuse of namespaces.\n\nIn this class, we will enclose all of our definitions \nwithin a namespace called edu.virginia.cs.dm. The idea\nis that (1) the namespace explains the context in which\nnames are defined, i.e., the discrete math (dm) class\nat UVa; and (2) no one else seems likely to pick the \nsame namespace. The next line of code tells Lean that\nall names between here at the \"end edu.virginia.cs.dm\"\ncommand at the end of the file are defined within the\nedu.virginia.cs.dm namespace.\n-/\n\nnamespace edu.virginia.cs.dm\n\n/-\nWhat this means is that every name, such as dm_bool, \nbelow is implicitly prefixed with edu.virginia.cs.dm. \nThe \"fully qualified\" name for dm_bool as defined below \nis thus edu.virginia.cs.dm.dm_bool. \n-/\n\n/-\nWith that ancillary detail out of the way we can \nnow turn to the main content of this chapter, giving \nour own implementation of Boolean algebra. \n-/\n\n\n/-\n**** INDUCTIVE DEFINITIONS OF TYPES: CASE STUDY OF bool ****\n-/\n\n/-\nOur implementation comprises (1) a definition of the \"carrier \nset\" of values of the Boolean type, and (2) a definition of a \nset of operations (functions) closed on this set. \n\nWe first specify the \"carrier set\" of values of Boolean \nalgebra. The values are typically called true and false\n(with different names in different natural languages).\nThe set of values of Boolean algebra can thus be written \nas { true, false }. We call this \"display notation\".\n\nA data type defines nothing other than a set of values, \nnamely the values that are specified as having that type \nand no other values whatsoever. \n\nHere's how we will represent the carrier set of Boolean\nalgebra as a data type in the Lean language. We explain\nthis code below.\n-/\n\ninductive dm_bool : Type\n| dm_ff : dm_bool\n| dm_tt : dm_bool\n\n/-\nTo avoid any possibility of confusion between the\nbuilt-in bool type, and its tt and ff values (even\nthough we're in our own namespace here), we will \ndefine our own Boolean algebra implementation to\nbe like the built-in version but with all names\nprefixed with an \"dm\".\n-/\n\n/-\nIn Lean, as in many other functional languages, we \ndefine types inductively. We specify the name of the \ntype and then we give a list of constructors that \nspecify the values of the type being defined.\n\nThe Lean keyword \"inductive\" introduces an inductive \ndefinition. The name of the type being defined is \ndm_bool, which is declared to be a type. (Technically\nit is declared to be a value of type, Type, which, \nas you might guess, is a type! Yep, types are values\ntoo, in Lean: values of type Type.) \n\nFinally a list of constructors is given, each starting\nwith a vertical bar, followed by the name of the \nconstructor and, at least in the simple case here, \na statement saying that the given constructor *is* a \nvalue of the type being defined. \n\nWe have thus just defined a type called dm_bool with \ntwo values, and no other values, namely dm_tt and dm_ff. \nOur *intended* interpretation is that dm_bool represents \nthe carrier set of Boolean algebra, dm_tt represents the \ntrue value of Boolean algebram and dm_ff represents \nthe false value.\n\nThis definition precisely mirrors the definition of \nthe built-in Boolean type in Lean, which is specified \nlike this:\n\ninductive bool : Type\n| ff : bool\n| tt : bool\n\n-/\n\n/-\nOur inductive type definition has actually defined meanings \nfor three different names: dm_bool, dm_tt, and dm_ff. The name, or\nidentifier, dm_bool, now refers to a type with two values, dm_tt\nand dm_ff. Each dm_tt and dm_ff refer to two different constructors\nthat in effect define the two different values of the dm_bool\ntype.\n\nWe can use Lean's #check command to see that these names are\ndefined, and Lean will tell us the type of thing that each\nname means. We start by using the fully qualified name of\nour dm_bool type. Hover your mouse pointer over the two\nparts of this command to see what it tells you.\n-/\n\n#check edu.virginia.cs.dm.dm_bool\n\n/-\nBecause we are within the edu.virginia.cs.dm namespace here,\nand because there is no ambiguity, we can leave off the whole\nedu.virginia.cs.dm prefix. Note that when you hover over dm_bool\nin the following #check command, it does tell you the fully\nqualified name of dm_bool.\n-/\n\n#check dm_bool\n\n/-\nImportantly, Lean tells you that the type of dm_bool is Type.\nThat's it's way of saying \"dm_bool is a type!\"\n-/\n\n/-\nYou might think that you can also use the #check command\nto check to see what's the type of dm_tt, and indeed we can.\nHowever, we can't just do \"#check dm_tt\" because the name,\ndm_tt, is defined in a namespace created by the dm_bool type.\nUncomment the following code and see what error you get.\n-/\n\n-- #check dm_tt\n\n/-\nHere's what you need to do instead.\n-/\n\n#check dm_bool.dm_tt\n\n/-\nThis is equivalent to the following.\n-/\n\n#check edu.virginia.cs.dm.dm_bool.dm_tt\n\n/-\nWhat we see is that the name, dm_bool, as defined in the\ncurrent namespace, is \"visible\" in this namespace, but\nthe names defined in its namespace are still hidden away.\n\nIf you want to be able to use the names dm_tt and dm_ff \nwithout qualifiers, you have to \"open\" the namespace \nin which they are defined, i.e., the dm_bool namespace.\n-/\n\nopen dm_bool\n\n/-\nAh, now it all just works. That's it on namespaces.\n-/\n\n#check dm_tt\n#check dm_ff\n\n/-\nWe've thus got the first component of our algebra defined: the \ncarrier set of Boolean values! To complete our implementation, \nwe need to define a set of operations on this set: operations \nsuch as \"and\", \"or\", and \"not\", which should already be familiar \nfrom CS1 (abh: CS 1xxx?). Take a few minutes to recall exactly how they work in\na language you already know (e..g, Python).\n-/\n\n/-\nEXERCISES:\n\n* In the language you used for CS1, assign the Boolean \nvalue, true, however it is written in your language, to \na variable called X. Assign the Boolean variable, false, \nto Y. Assign to a variable, Z, the value of the negation \nof (\"not\") X. Assign to W the disjunction (\"or\") of X and \nY. Finally print the value of the conjunction of W and \ntrue. What value is produced? Every useful programming\nlanguages provides a built-in implementation of Boolean\nalgebra. Now you're building your own.\n-/\n\n\n-- MATHEMATICAL FUNCTIONS AND PURE FUNCTIONAL PROGRAMS\n\n/-\nAs you now recall from CS1, \"and\", \"or\", and \"not\" are really\njust functions that take and return Boolean values. The \"not\"\nfunction takes a single bool value as an argument (\"not\" is a \nunary function) and returns its opposite bool value. The \"and\" \nand \"or\" operations each take two bool values (they are binary\noperations) and return bool values. \n-/\n\n/-\nWe now complete a definition of a limited version Boolean algebra\nby defining several unary functions and binary operations over the\nBooleans. A unary operation (aka function) takes one argument. A \nbinary operation takes two. Let's start with unary operations.\n-/\n\n/- THE UNARY OPERATIONS OF BOOLEAN ALGEBRA -/\n\n/-\nA unary operation takes one argument and on the basis of its value\nalone returns a result. Boolean operations take and return Boolean\nvalues, here implemented (represented, if you will) as the value of\nour type, bool.\n\nThe functions of an algebra are \"closed\" on the carrier set of that\nalgebra. What this means is that each such functions yields a result\nin that set when given any argument values from that set. We can also\ncall such a function \"total.\" A \"partial function\" is not necessarily\ntotal, and a \"strictly partial\" function is definitely not total. An\nexample of a partial function on the real numbers is division. It is\nnot defined when the second argument (the denominator) is zero. \n\nWe are interested in this section only in total unary functions on\nthe Booleans. What this means is, first, that for each Boolean value\nthere must be a corresponding Boolean result, and, second, to be a\n*function*, there can be no more than one result. That is, there is\nexactly one result for each argument value.\n-/\n\n/-\nAs a mathematical object, such a function is a set of pairs with\nexactly one pair having each Boolean value in the first position.\nFor example, the set, { (tt, ff), (ff, tt) } is such a function. \nThe set { (tt, tt), (tt, ff) } is not, for two different reasons. \nFirst, it is not a function at all, because it has two pairs with \nthe same first element, and so is not single-valued. Second, it\ndoesn't have a pair with ff as a first element and so is not total. \n-/\n\n/-\nWe can graphically depict a total unary function on the Booleans\nas a table with two rows and two columns. The first entry in each\nrow indicates the argument to the function, and the second entry,\nthe corresponding result. Every such table will have the same first\ncolumn, listing each and every possible argument value. Different\nfunctions will then be defined by the corresponding entries in the\nsecond column. Such a table looks like this, where underscores are\nplaceholders for return values. \n\n Arg   Ret\n+----+----+\n| tt | __ |\n+----+----|\n| ff | __ |\n+----+----+\n-/\n\n/-\nOne of the important concepts in discrete mathematics is that of\n\"counting\" the number of objects of some particular kind. Here the\nquestion is, how many unary functions are there on the Booleans?\nThe answer is equal to the number of different ways in which that\nsecond column can be completed. For example, the co-called identity\nfunction on the Booleans is the function where the return result\nis always the same as the argument value. Here's the table.\n\n Arg   Ret\n+----+----+\n| tt | tt |\n+----+----|\n| ff | ff |\n+----+----+\n\nOf course such a table is just another way of representing the set\nof pairs, { (tt, tt), (ff, ff) }, which is the right way to think of\nthe identity function as a mathematical object. If we wanted to give\nthis function a name, we might call it id_bool, with a prefix, id,\nsuggesting the identity function, and the suffix, _bool, suggesting\nthat this is the identity function for the bool type. \n\nIf you were writing out the algebra in ordinary paper-and-pencil \nmathematics,  you'd write this function as id_bool(b) = b, where \nb is any Boolean value. You can imagine the corresponding identity \nfunctions for any other type. E.g., for the natural numbers, you \ncould define id_nat as id_nat(n) = n, where n is any natural number.\n-/\n\n/-\nWe can now put all of these ideas together to write a pure\nfunctional program that implements this function. We will call\nthis program id_bool. If we apply this resulting program to a\nBoolean-valued argument value, b, which would be done by writing\nthe expression, \"id_bool b\", the result that is returned will be\njust b itself. \n\nAs we've now seen, a Boolean function can be represented in at\nleast three ways:\n\n- as a set of pairs, such as { (tt, tt), (ff, ff) }\n- in the form of a table, namely a truth table\n- using an equation, such as \"id_bool(b) = b\" \n  \nSimple pure functional programs are generally written in the\nequational form. Here's the code for the id_bool function. \n-/\n\ndef id_bool (b: dm_bool) : dm_bool := b\n\n/-\nThe \"def\" keyword introduces a new definition -- a binding of a name,\nor \"identifier\", here id_bool, to a value, here a definition of the\nidentity function that takes a bool argument and returns that same\nvalue as the result. (Yes, function bodies are values, too.)\n\nYou can thus pronounce this code as follows: \"we define id_bool to \nbe a function that takes one argument of type bool, bound to the \nidentifier b,  and that also returns a value of type bool, namely \nthat obtained by evaluating the expression, \"b\", in the context of\nthe prevailing binding of the identifier, b, to the value of the\nbool argument to which the function is applied in any given case. \n-/\n\n\n/-\nEXERCISE: Write pure functional programs called false_bool and\ntrue_bool, respectively, each of which takes a bool argument and\nthat always returns false or true, respectively.\n-/\n\n-- TYPE INFERENCE\n\n/-\nThere's a shorter way to write the same function: we can leave out \nthe explicit return type (the bool after the colon) because Lean \ncan infer what it must be by analyzing the type of the expression\nthat defines the return result. The argument, b, is declared to\nbe of type bool, so it is clear that type obtained by evaluating\nthe expression, b, defining the return result, is also of type bool. \nHere's another version of the same definition,  with a \"prime\" mark \nto make the name unique, exhibiting the use of type inference.\n\n-/\n\ndef id_bool' (b: dm_bool) := b\n\n/-\nEXERCISE: Use type inference to write shorter versions of \nyou true_bool and false_bool programs.\n-/\n\n-- FUNCTION APPLICATION EXPRESSIONS\n\n/-\nA function application expression is an expression written \nas a function name (or more generally as an expression that\nreduces to a function value)) followed by an expression that \nreduces to a value that is taken to be the argument to the \nfunction. \n\nThe simplest form of a function application expression is\njust a function name applied to a so-called \"literal value\"\nof the required type. In the function application expression,\n\"id_bool tt\", you see first a function name, the \"variable\",\nid_bool, followed by the literal expression, tt.\n\nHere's an example in which id_bool is\napplied to the literal value, tt. By hovering over the\n#reduce command, you can see the value to which this\nfunction application expression is reduced.\n-/\n\n#reduce id_bool dm_tt\n\n/-\nEXERCISES: Write and reduce expressions in which you apply\nyour true_bool and false_bool programs to each of the two\nbool values, thereby exhaustively testing each program for\ncorrectness.\n-/\n\n-- EVALUATION OF FUNCTION APPLICATION EXPRESSIONS\n\n/-\nReducing a function application expression is a very simple\nprocess. First you evaluate the function expression, then you\nevaluate the argument expression, then you apply the resulting\nfunction to the resulting value. Let's do this in steps. \n\nFirst, the function expression is given by the identifier,\nid_bool. To obtain the actual function, Lean looks up its\ndefinition and finds a function that takes a bool as a value\nand that returns that same bool value as a result.\n\nabh: there are a lot of references to \"tt\" where we clearly\nmean \"dm_tt\"\n\nSecond, the identifier, tt, is a literal expression for the\ntt value/constructor of the bool type.\n\nFinally, the function is applied to this argument value.\nThis is done by substituting the argument value for the\nargument variable wherever it appears in the body of the\nfunction and by then evaluating the resulting expression.\n\nThe body of the function in this case is just \"b\". So the\nvalue, tt, is substituted for \"b\". Finally this expression\nis evaluated, once again producing the value, tt, and that\nis the result of the function application!\n-/\n\n/-\nEXERCISE: We previously confirmed that the definition of \ntt is ambiguous in the current environment. So why was it \nokay here to write tt without qualifiers in the expression, \nid_bool tt?\n-/\n\n/-\nEXERCISE: Explain in precise, concise English exactly \nhow your true_bool program is evaluated when applied to\nthe argument given by the literal expression, tt.\n-/\n\n\n-- FUNCTION TYPES\n\n-- abh: There's some redundancy between dm_bool.lean and functions.lean\n\n/-\nFunctions also have types. We can check the type of id_boolean \nusing the #check  command. Hover your mouse over the #check. \nLean reports that the type of this function is boolean → boolean. \nThat is how, in type theory, we write the type of a function\nthat takes an argument of type bool and that returns a result\nof that same type. \n-/\n#check id_bool\n\n/-\nEXERCISE: First mentally determine the types of your false_bool\nand true_bool functions, and then use #check commands to test\nyour predictions.\n-/\n\n-- TESTING FUNCTION IMPLEMENTATIONS FOR CORRECTNESS\n\n/-\nWhenever we write programs that are meant to compute values\nof functions for given arguments, the question arises, did\nwe represent/implement the intended function correctly?  \n\nAn important observation is that the question presumes\nthat we have a definition of a function to be implemented\nagainst which the correctness of the implementation can\nbe evaluated. \n\nConsider our implementation of id_bool? Against what \nspecification should its correctness be determined? \nHere the best answers are that we can evaluate the \ncorrectness of id_bool against either the truth table \nor the equivalent set-theoretic definition. The tuples \nin the definition of the function, (tt, tt) and (ff, ff), \ntell us what result to *expect* for each argument value: \nexpect tt when given tt as an argument and expect ff \nwhen given ff as an argument.\n-/\n\n/-\nThe process of software *testing* is one in which a\nprogram is evaluated for one or more argument values\nand the actual results are compared with the expected\nresults to identify any discrepancies. A single pair,\n(argument value, expected result) is called a *test\ncase*. The tuples in our set-theoretic definition\nof id_bool can thus serve as test cases. Consider\nthe tuple, (tt, tt). Viewing it as a test case tells\nus that we should expect that \"id_bool tt = tt.\" \n-/\n\n-- PROPOSITIONS AND PROOFS\n\n/-\nA claim like this---an assertion that a certain state\nof affairs holds in a given situation, here the assertion\nthat if we evaluate id_bool with argument tt the result \nwill be tt---is what in logic we call a proposition. \n\nA proposition is a truth claim. A proposition can thus\nbe true, or false, or, in some logics the truth of a \ngiven proposition can be indeterminate. In any case, \nestablishing the truth of a proposition requires what\nwe call a proof.\n-/\n\n/-\nThe real power of Lean is that in addition to letting\nus write programs, it also let us write propositions\nand proofs, and it checks that proofs are correct.\nHere, the proposition for which we want a proof is\nthe proposition, id_bool tt = tt. We can write and\nprove this proposition in Lean as follows.\n-/\n\ntheorem id_bool_correct_for_tt: id_bool dm_tt = dm_tt :=\n    rfl\n/-\nWe introduce a proposition and its proof with the\nkeyword, theorem. Technically theorem is just the\nsame as definition: it's a way to say we're about \nto define a value but we intend for that value to\nbe a proof of some proposition \n\nFollowing this keyword we give a name to the proof \nthat we intend to define: id_bool_correct_for_tt.\n\nNext, after the colon comes the proposition itself:\nhere, id_bool tt = tt. \n\nNext comes a :=. Finally we write the proof: here \nthe cryptic term, rfl. \n-/\n\n/-\nPROOF BY SIMPLIFICATION AND THE REFLEXIVE PROPERTY\nOF EQUALITY\n-/\n\n/-\nProofs come in many forms. As a mathematician,\nyou learn what forms of proofs work for what\nkinds of propositions. Here we have propositions\nthat two expressions reduce to the same value.\nTo construct such a proof, you first reduce each\nexpression to a value. The expression id_bool dm_tt\nreduces to tt. The expression dm_tt reduces to dm_tt \n(it's already reduced to a value). Then what \nyou have is the proposition, dm_tt = dm_tt. But \nthat is true by the reflexive property of\nequality: for any value x, no matter what it \nis, x = x. So dm_tt = dm_tt. The proposition is\nthus proved.\n-/\n\n/-\nYou thus read \"rfl\" as saying what a mathematician\nwould pronounce as, \"by simplification of expressions \nand the reflexive property of equality.\" \n\nThe fact that Lean accepts rfl as a proof (value)\nprovides a very strong mechanized check on the \ncorrectness of the proof.\n-/\n\n/-\nEXERCISE: Use Lean to state and prove the proposition\nthat id_bool dm_ff = dm_ff.\n-/\n\n/-\nEXERCISE: Write a similar definition, bad_proof_1,\nasserting that there is a proof of the proposition,\nid_bool dm_tt = dm_ff. Does Lean accept the proof? What \nerror messages does Lean report?\n-/\n\n-- YOUR WORK HERE\n\n/-\nThe red under rfl indicates a \"type mismatch\", stating\nthat rfl was expected to be a proof that something\n(here given the arbitrary name m_2) is equal to itself,\nbut that (in so many words) the things asserted to be\nequal are not equal. \n\nThe red under bad_proof states, in effect, that the\nname, bad_proof, was expected to be bound to a proof\nof some proposition, but it is not so bound (due to\nthe preceding error).\n\nA proposition that is false has no proof. To see that\nrfl cannot be a proof of id_bool dm_tt = dm_ff, observe that\nid_bool dm_tt reduces to dm_tt, so the proposition reduces \nto dm_tt = dm_ff, but dm_tt and dm_ff are not equal, and so rfl \nis not a valid proof: it can only be used to prove that\ntwo values are equal to themselves. In the logic of \nLean, different constructors *always* build different \nvalues -- values that are never equal to each other --\nso dm_ff cannot be equal to dm_tt. The proposed proof, rfl,\nis thus rejected. \n-/\n\n\n/-\nEXERCISE: Give a proof, call it one_equals_one, for \nthe proposition, 1 = 1.\n-/\n\n-- YOUR WORK HERE\n\n/-\nEXERCISE: Attempt to give a proof, using rfl, of the\nproposition that 1 = 2. What happens. Investigate and\nbriefly explain in plain English the meanings of the\nerror messages that are reported.\n-/\n\n\n/- UNIVERSAL QUANTIFICATION AND PROOF BY CASE ANALYSIS -/\n\n/-\nTesting that a program is correct for one input, which is\nwhat a test case asserts, does not prove that it is correct\nfor all possible inputs, unless there is only one possible\ninput, in which case the function is pretty much useless.\nThe kind of propositions that we really want to prove are\nones that claim= a program is correct *for all* possible\ninputs. \n-/\n\ntheorem id_bool_correct: \n  ∀ b: dm_bool, id_bool b = b \n    | dm_tt := rfl\n    | dm_ff := rfl\n\n\n\n\n/-\nWe once again give our proof a name that reflects the \nproposition that it proves: here, id_bool_correct. We\nare claiming that the function is correct for every\npossible input. On the second lines is the proposition\nitself. The \"universal quantifier\", ∀, pronounced as\n\"for all\", or \"for every\", or \"for any\". It is followed \nby a variable, b, and its type, bool. So far we can thus\npronounce the proposition as saying \"for any value, b, \nof type bool.\" Then comes a comma followed by the rest\nof the proposition: namely, the claim that, for any\nsuch b, id_bool b = b. The \"b\" in this part of the \nproposition is the b \"bound\" in the quantifier part \nof the expression. The whole proposition thus covers \nall possible cases, and reads, \"for any boolean value,\nb, id_bool b is equal to b.\" \n\nWe can't use rfl directly as a proof, because the \nform of the proposition is not a simple assertion\nof equality of the values of two expressions. It is\ninstead a \"universally quantified\" proposition\n\nThe remainder is the code instead gives a \"proof by \ncase analysis.\" We show that for each possible value\nof b considered in turn, the claim that id_bool b = b\nis true. \n\nBecause there are only two values of type bool, there \nare two cases: one where b is tt, and one where b is \nff. \n\nEach case starts with a vertical bar, followed by the \ncase (the value of b) being considered. Then comes a\n:=, and followed by a proof for that case. \n\nConsider the first case, in which b is bound to tt. \nIn this case, making this substitution in the \"body\"\nof the proposition gives us id_bool tt = tt. For \nthis proposition, we already have a proof! It's rfl.\nThe same holds true for the second case. \n\nAs we've now given a proof for each individual case, \nwe've given a proof \"for all\" cases, showing that\nthe overall quantified proposition is true. Proving\nuniversally quantified propositions about software\ncorrectness is called formal verification, and is a\nstate of the art approach to producing ultra-high\nquality code. Such a high standard of correctness\nis not always necessary or practical, but when \nlives or nations depend on correctness of code, it\nis a \"gold standard\" approach to software quality. \n-/\n\n/-\nEXERCISE: In a similar style, state and prove the\nproposition that every natural number, n, is equal \nto itself. Call your proof nat_refl. You can get\nthe ∀ character (the universal quantifier, for all)\nin Lean by typing \\forall followed by a space.\n\nNOTE: You don't know how to write such a proof \nyet, so just write \"sorry\" instead. This tells\nLean to accept the proposition as being true\neven though you haven't yet given a proof (and\neven if it's actually not even true). You are\nsaying, \"accept the proposition without proof\",\nor \"accept it as an \"axiom.\" An axiom is any\nproposition that is accepted without a proof.\n\nThis is really just an exercise that asks you\nto write a proposition in Lean using a ∀.\n-/\n\n-- theorem nat_refl: ∀ n: nat, n = n := sorry\n\n/-\nEXERCISE: State a proposition and give a proof\nin Lean for the proposition stating that for\n*every* possible argument, b, to false_bool,\nfalse_bool b = false. Similarly prove that\nyour implementation of true_bool is correct\nwith respect to our understanding of how it\nshould behave.\n-/\n\n\n\n/-\nExercise: How many test cases do we need to \"prove\" that \nthe function works correctly for all possible inputs of \ntype boolean. (Hint: how many such inputs are there?) \nWrite any additional test cases need to prove that our \ndefinition of the identity function works as we expect \nit to. \n-/\n\n/-\nProof by case analysis often works well when you want to \nprove that something is true for every element in a finite \nset of elements. It isn't an appropriate proof strategy when \nthe set of values to be considered is infinite, as it would \nbe impossible to test every individual case. For example, \nyou can't prove that a functional program that takes a \nnatural number as an argument is correct by giving a proof\nfor each natural number in turn because there is an infinity\nof such values. Another proof strategy would be need. It \ngoes by the name of \"proof by induction.\" More on that later!\n-/\n\n-- THE MAJOR FUNCTIONS OF BOOLEAN ALGEBRA\n\n/-\nSo far we have implemented three of the four unary functions\nof Boolean algebra. The remaining one is usually called \"not\"\nor \"negation.\" We will give it the name, negb. Given one of \nthe two Boolean values as an argument, negb returns the other.\n\nThe set-theoretic definition is negb = { (tt, ff), (ff, tt) }.\nThe truth table depicts this definition graphically. \n\nabh: the table below has switched from tt/ff to T/F\n\n Arg Ret\n+---+---+\n| T | F |\n+---+---|\n| F | T |\n+---+---+\n-/\n\n/-\nWe don't yet have the tools needed to implement this function.\nThe tool we need is called pattern matching. It's just a form\nof case analysis! Here's the code.\n-/\n\ndef negb (b: dm_bool): dm_bool :=\n  match b with \n    | dm_tt := dm_ff\n    | dm_ff := dm_tt\n  end\n\n/-\nWe define negb to be a function that takes a Boolean value and\nreturns a Boolean value. That is, the type of this function is,\nlike the others we've defined so far, bool → bool. The thing that\nis different about this function is that we have to inspect the\nargument value to determining what result to return. We do that by\ncase analysis! What the body of this function says is \"match the\nvalue of b with each of its possible cases. THe first case is tt,\nand in this case (after the :=), the return value is given by\nthe expression ff. Similarly, for the case, ff, the result is tt.\nThere are no more cases, and so this function has given a result\nvalue \"for every\" possible value of b. This is thus a definition\nof a total function by case analysis!\n\n(You get the → symbol in Lean by typing \\to. EXERCISE: Try it.)\n-/\n\n/-\nEXERCISE: Write a second implementation of id_bool, call it\nid_bool', using case analysis. Prove by case analysis that it \nis correct with respect to its expected behavior.\n-/\n\n-- FUNCTION TYPES\n\n/-\nIn Lean, every function is required to be total. That is, a\nfunction must define how to construct a return value of the\nspecified type \"for every\" value of its argument type. The\nfour unary functions we've seen so far all do this. For every\nvalue of type dm_bool, each of them returns a value of type dm_bool.\nWe've seen that you can write this type as dm_bool → dm_bool, but\nanother way to write it is, ∀ b: dm_bool, dm_bool. This just says,\nfor every value of type bool you can give me, I promise to\ngive you back a value of type dm_bool. Hover over the #check\nthat follows. You will see that we have just found two ways\nto write the same function type!\n-/\n\n\n#check ∀ b: dm_bool, dm_bool\n\n/-\nEXERCISE: Use a universal quantifier to write and check the\ntype of functions from natural numbers to dm_bools. An example\nof such a function would be one that took any natural number\nand returned dm_tt if and only it it was even, and dm_ff otherwise.\n-/\n\n#check ∀ n: nat, dm_bool\n\n/-\nTHE BINARY OPERATORS OF BOOLEAN ALGEBRA\n-/\n\n/-\nBinary operations of an algebra are functions that take two \narguments of a given type (such as dm_bool) and that return a\nvalue of that same type. The conjunction, aka and, operation\nin Boolean algebra is an example. It takes two Boolean values\nas arguments and returns a Boolean result. If both arguments\nare true, its result is true, otherwise it is false. This\nbehavior is reflected in  the following set-theoretic and \ntruth table specifications. We will call the function xandb. \n\n\nxandb = { ((T, T), T), ((T, F), F), ((F, T), F), ((F, F), F) }\n\nNote that we again give the function as a set of argument/result\npairs, but now each argument is itself a pair of values.\n\n\n\nA truth table view:\n\n    xandb\n+---+---+---+\n| T | T | T |\n+---+---|---+\n| T | F | F |\n+---+---+---+\n| F | T | F |\n+---+---+---+\n| F | F | F |\n+---+---+---+\n\nabh: An alternative truth table view\n(lower-case inputs, upper-case result):\n\n        arg 1\n      +---+---+\n      | t | f |\na +---+---|---+\nr | t | T | F |\ng +---+---+---+\n  | f | F | F |\n2 +---+---+---+\n\n-/\n\n/-\nWe already have all the tools but for one to implement this\nfunction. The one tool we need is pattern matching (i.e., case\nanalysis) for *pairs* of argument values. This following code\nshows how to do this. Instead of matching on one value, b, we\nnow match on the comma-separated pair of values, b1, b2; and\neach case now corresponds to a possible pair of argument values.\nThere are four possible pairs of Boolean values, and so there \nare four cases to consider. Note how the visual organization\nof the code reflects the truth table contents (and thus the\nequivalent set-theoretic definition nearly directly.)\n-/\n\ndef and_boolean' (b1 b2: dm_bool): dm_bool :=\n    match b1, b2 with\n        | dm_tt, dm_tt := dm_tt\n        | dm_tt, dm_ff := dm_ff\n        | dm_ff, dm_tt := dm_ff\n        | dm_ff, dm_ff := dm_ff\n    end\n\n/-\nIt's often the case (ha ha) that in a case analysis, one\ncase stands out and several others or all the rest can be\nconsidered at once. To define \"xandb\" all we really have to\nsay is \"if b1 and b2 are both true, the result is true, and\nin any other case the result is false.\" In Lean and in many\nother functional programming language, we can write cases\nanalysis using \"wildcards\" (here underscores) that match\nany values not considered in previous cases.\n-/\n\ndef and_boolean (b1 b2: dm_bool): dm_bool :=\n    match b1, b2 with\n        | dm_tt, dm_tt := dm_tt\n        | _, _ := dm_ff\n    end\n\n\n/- \nEXERCISES:\n\n1. Using case analysis, write definitions of the following binary \nfunctions on booleans in the form of (a) sets, using display notation, \n(b) truth tables, (3) functional programs. When writing functional\nprograms, use wildcards where possible to shorten your definitions.\n\n* or (call it dm_orb)-- false if both arguments are false, otherwise true\n* xor (dm_orb) -- true if either not both both arguments are true\n* xnand (dm_nandb) -- the negation of the conjunction of the arguments\n* ximplies (dm_implb) -- false if b1 is true and b2 is false otherwise true\n* xnor (dm_norb)-- the negation of the \"disjunction\" of its arguments\n\n2. By the method of case analysis, prove that your \"or\" and \"xor\" programs are\ncorrect with respect to your truth table definitions, i.e., that they produce the\noutputs specified by the truth tables for the given inputs.\n\n3. How many binary functions on booleans are there? Justify your answer. Hint:\nthink about the truth tables. The set of possible arguments is always the set of\npairs of booleans. How many different ways can these arguments be associated with\nboolean results?\n\n4. Write a second definition of nandb, call it nandb', that instead of\nusing pattern matching applies a combination of andb and negb functions.\nSurround function application expressions with parentheses to specify\ngroupings when they might otherwise be misinterpreted, e.g., vvv (www x y)\nin the case where the argument to vvv is meant to be the result of \nevaluating www x y.\n-/\n\n\n/-\nFORMAL AND INFORMAL PROOFS.\n-/\n\n/-\nOur formal proofs are very precise and their correctness is assured by Lean's\nautomated proof checking mechanism. By contrast, most working mathematicians\nwrite informal proofs. These are still highly precise, but they are written in\nstructured English (or another natural language) rather than in what amounts \nto code. The major benefit of informal proofs is that they are easier for most\npeople to understand. The downside is that mistakes in proofs can, and often \ndo, go undetected. One benefit of formal proofs is that they are checked for\ncorrectness by a computer, and, when verified can be accepted as correct with\nvery high levels of confidence. Another benefit of learning how to write such\nproofs is that the relationships between forms of propositions (e.g., equality\nclaims or universally quantified claims) and the forms of the corresponding\nproofs becomes very clear. Learning how to write both informal and formal\npropositions and proofs is an important goal of this class.\n-/\n\n/-\nAs an example, let's recast our formal proof of the correctness of our\nprogram for id_bool as an informal proof. Here's how it might be written.\n\n\"The goal is to show that for every value, b, id_bool = b. We do this by\ncase analysis. There are two cases: b = dm_tt, and b = dm_ff, respectively. We\nfirst consider the case where b = dm_tt. In this case, the proposition to be\nproved is that id_bool dm_tt = dm_tt. We prove this by simplification of the left\nhand side to tt by applying the definition of id_bool. What's left to prove\nis that dm_tt = dm_tt, and this is done trivially by appealing to the reflexive\nproperty of equality. The proof of the second case is by the same strategy\nof simplification and reflexivity of equality.\"\n-/\n\n\n/-\nEXERCISE: Write both a formal and a corresponding informal proof of the \ncorrectness of your andb function.\n-/\n\n/-\nBOOLEAN ALGEBRA AS AN ALGEBRA\n-/\n\n/-\nWe have now gotten to the point where we can make sense of the term, boolean algebra.\nBoolean algebra is an algebra, which is to say it is a particular set of values and\na particular collection of operations closed on that set. We have represented the set\nof values as a type, namely our dm_bool type. We have represented the operations as\npure functional programs taking and returning values of this type. \n\nMoreover, by defining this set and its operations in a namespace, we've grouped\nthe values and operations on them in a meaningful way.\n\n+ --------------+\n|  csdm.dm_bool |  DATA\n+---------------+\n|  csdm.dm_negb |\n|  csdm.dm_andb | OPERATIONS\n|  csdm.dm_orb  |\n|     ...       |\n+---------------+\n\nSuch a structure, comprising a data type and a collection of operations on it is\nalso known, in the computer science field, as an \"abstract data type (ADT)\". When\ncomputer scientists talk about \"types\", sometimes they mean inductively defined\ntypes, such as the bool type (separate from operations), and sometimes (actually\nmore often) then mean abstract data types. Abstract data types, i.e., algebras!,\nare fundamental building blocks of software. It took a while for us to build up\nour bool ADT, but now that we're done, you can step back and now view our data \ntype definition and our definitions of a collection of associated operations as \na coherent whole, an abstract data type that implements the algebra of Boolean\ntruth values. \n-/\n\n-- USING AN ABSTRCT DATA TYPE\n\n/-\nThe last question we address in this chapter is how to use such an abstract \ndata type implementation. To this end, please open and shift your attention\nto the file csdm_bool_test.lean. It will show you how to import and use type\nand function definitions in another file: this file in this case. \n-/\n\n/-\nSUMMARY\n\n- boolean algebra\n  * inductive definition of the type of booleans\n  * functions on booleans\n  ** set theoretic, truth table, and pure functional representations\n  ** unary functions on booleans\n  ** binary functions on booleans\n- types and values\n- inductive definitions\n- tuple values and tuple types\n- relations and functions (set theoretic)\n- functional programs: their types and values\n- propositions\n  * about equality of terms\n  * universally quantified propositions\n- an application: propositions and proofs of program correctness\n- proof strategies:\n  * by simplification and reflexivity of equality\n  * by exhaustive case analysis\n- formal and informal proofs\n- algebras\n-/\n\nend edu.virginia.cs.dm", "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/AA_Algebras/01_dm_bool/2a_dm_bool.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.9124361700013356, "lm_q1q2_score": 0.7737164642558088}}
{"text": "-- Logical Equivalance\n\nvariables p q : Prop\n\ntheorem and_swap : p ∧ q ↔ q ∧ p :=\niff.intro\n  (assume h : p ∧ q,\n    show q ∧ p, from and.intro h.right h.left)\n  (assume h : q ∧ p,\n    show p ∧ q, from ⟨ h.right, h.left ⟩)\n\n#check and_swap p q\n\nvariable h : p ∧ q\nexample : q ∧ p := iff.mp (and_swap p q) h\n\ntheorem and_swap' : p ∧ q ↔ q ∧ p :=\n⟨λ h : p ∧ q, ⟨ h.right, h.left ⟩ , λ h : q ∧ p, ⟨ h.right, h.left ⟩ ⟩ \n\nexample (h : p ∧ q) : q ∧ p := (and_swap' p q).mp h\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.3.4-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7737164421568594}}
{"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\nParity.\n-/\nimport data.nat.power logic.identities\n\nnamespace nat\nopen decidable\n\ndefinition even (n : nat) := n % 2 = 0\n\ndefinition decidable_even [instance] : ∀ n, decidable (even n) :=\ntake n, !nat.has_decidable_eq\n\ndefinition odd (n : nat) := ¬even n\n\ndefinition decidable_odd [instance] : ∀ n, decidable (odd n) :=\ntake n, decidable_not\n\nlemma even_of_dvd {n} : 2 ∣ n → even n :=\nmod_eq_zero_of_dvd\n\nlemma dvd_of_even {n} : even n → 2 ∣ n :=\ndvd_of_mod_eq_zero\n\nlemma not_odd_zero : ¬ odd 0 :=\ndec_trivial\n\nlemma even_zero : even 0 :=\ndec_trivial\n\nlemma odd_one : odd 1 :=\ndec_trivial\n\nlemma not_even_one : ¬ even 1 :=\ndec_trivial\n\nlemma odd_eq_not_even (n : nat) : odd n = ¬ even n :=\nrfl\n\nlemma odd_iff_not_even (n : nat) : odd n ↔ ¬ even n :=\n!iff.refl\n\nlemma odd_of_not_even {n} : ¬ even n → odd n :=\nsuppose ¬ even n,\niff.mpr !odd_iff_not_even this\n\nlemma even_of_not_odd {n} : ¬ odd n → even n :=\nsuppose ¬ odd n,\nnot_not_elim (iff.mp (not_iff_not_of_iff !odd_iff_not_even) this)\n\nlemma not_odd_of_even {n} : even n → ¬ odd n :=\nsuppose even n,\niff.mpr (not_iff_not_of_iff !odd_iff_not_even) (not_not_intro this)\n\nlemma not_even_of_odd {n} : odd n → ¬ even n :=\nsuppose odd n,\niff.mp !odd_iff_not_even this\n\nlemma odd_succ_of_even {n} : even n → odd (succ n) :=\nsuppose even n,\nhave n ≡ 0 [mod 2],       from this,\nhave n+1 ≡ 0+1 [mod 2],   from add_mod_eq_add_mod_right 1 this,\nhave h : n+1 ≡ 1 [mod 2], from this,\nby_contradiction (suppose ¬ odd (succ n),\n  have n+1 ≡ 0 [mod 2], from even_of_not_odd this,\n  have 1 ≡ 0 [mod 2],   from eq.trans (eq.symm h) this,\n  have 1 = 0,         from this,\n  by contradiction)\n\nlemma eq_1_of_ne_0_lt_2 : ∀ {n : nat}, n ≠ 0 → n < 2 → n = 1\n| 0     h₁ h₂ := absurd rfl h₁\n| 1     h₁ h₂ := rfl\n| (n+2) h₁ h₂ := absurd (lt_of_succ_lt_succ (lt_of_succ_lt_succ h₂)) !not_lt_zero\n\nlemma mod_eq_of_odd {n} : odd n → n % 2 = 1 :=\nsuppose odd n,\n  have ¬ n % 2 = 0, from this,\n  have n % 2 < 2,   from mod_lt n dec_trivial,\n  eq_1_of_ne_0_lt_2 `¬ n % 2 = 0` `n % 2 < 2`\n\nlemma odd_of_mod_eq {n} : n % 2 = 1 → odd n :=\nsuppose n % 2 = 1,\nby_contradiction (suppose ¬ odd n,\n  have n % 2 = 0, from even_of_not_odd this,\n  by rewrite this at *; contradiction)\n\nlemma even_succ_of_odd {n} : odd n → even (succ n) :=\nsuppose odd n,\n  have n % 2 = 1 % 2,     from mod_eq_of_odd this,\n  have (n+1) % 2 = 2 % 2, from add_mod_eq_add_mod_right 1 this,\n  by rewrite mod_self at this; exact this\n\nlemma odd_succ_succ_of_odd {n} : odd n → odd (succ (succ n)) :=\nsuppose odd n,\nodd_succ_of_even (even_succ_of_odd this)\n\nlemma even_succ_succ_of_even {n} : even n → even (succ (succ n)) :=\nsuppose even n,\neven_succ_of_odd (odd_succ_of_even this)\n\nlemma even_of_odd_succ {n} : odd (succ n) → even n :=\nsuppose odd (succ n),\nby_contradiction (suppose ¬ even n,\n  have odd n,         from odd_of_not_even this,\n  have even (succ n), from even_succ_of_odd this,\n  absurd this (not_even_of_odd `odd (succ n)`))\n\nlemma odd_of_even_succ {n} : even (succ n) → odd n :=\nsuppose even (succ n),\nby_contradiction (suppose ¬ odd n,\n  have even n,       from even_of_not_odd this,\n  have odd (succ n), from odd_succ_of_even this,\n  absurd `even (succ n)` (not_even_of_odd this))\n\nlemma even_of_even_succ_succ {n} : even (succ (succ n)) → even n :=\nsuppose even (n+2),\neven_of_odd_succ (odd_of_even_succ this)\n\nlemma odd_of_odd_succ_succ {n} : odd (succ (succ n)) → odd n :=\nsuppose odd (n+2),\nodd_of_even_succ (even_of_odd_succ this)\n\nlemma dvd_of_odd {n} : odd n → 2 ∣ n+1 :=\nsuppose odd n,\ndvd_of_even (even_succ_of_odd this)\n\nlemma odd_of_dvd {n} : 2 ∣ n+1 → odd n :=\nsuppose 2 ∣ n+1,\nodd_of_even_succ (even_of_dvd this)\n\nlemma even_two_mul : ∀ n, even (2 * n) :=\ntake n, even_of_dvd (dvd_mul_right 2 n)\n\nlemma odd_two_mul_plus_one : ∀ n, odd (2 * n + 1) :=\ntake n, odd_succ_of_even (even_two_mul n)\n\nlemma not_even_two_mul_plus_one : ∀ n, ¬ even (2 * n + 1) :=\ntake n, not_even_of_odd (odd_two_mul_plus_one n)\n\nlemma not_odd_two_mul : ∀ n, ¬ odd (2 * n) :=\ntake n, not_odd_of_even (even_two_mul n)\n\nlemma even_pred_of_odd : ∀ {n}, odd n → even (pred n)\n| 0     h := absurd h not_odd_zero\n| (n+1) h := even_of_odd_succ h\n\nlemma even_or_odd : ∀ n, even n ∨ odd n :=\nλ n, by_cases\n  (λ h : even n,   or.inl h)\n  (λ h : ¬ even n, or.inr (odd_of_not_even h))\n\nlemma exists_of_even {n} : even n → ∃ k, n = 2*k :=\nλ h, exists_eq_mul_right_of_dvd (dvd_of_even h)\n\nlemma exists_of_odd : ∀ {n}, odd n → ∃ k, n = 2*k + 1\n| 0 h     := absurd h not_odd_zero\n| (n+1) h :=\n  obtain k (hk : n = 2*k), from exists_of_even (even_of_odd_succ h),\n  exists.intro k (by subst n)\n\nlemma even_of_exists {n} : (∃ k, n = 2 * k) → even n :=\nsuppose ∃ k, n = 2 * k,\nobtain k (hk : n = 2 * k), from this,\nhave 2 ∣ n, by subst n; apply dvd_mul_right,\neven_of_dvd this\n\nlemma odd_of_exists {n} : (∃ k, n = 2 * k + 1) → odd n :=\nassume h, by_contradiction (λ hn,\n  have even n, from even_of_not_odd hn,\n  have ∃ k, n = 2 * k, from exists_of_even this,\n  obtain k₁ (hk₁ : n = 2 * k₁ + 1), from h,\n  obtain k₂ (hk₂ : n = 2 * k₂), from this,\n  have (2 * k₁ + 1) % 2 = (2 * k₂) % 2, by rewrite [-hk₁, -hk₂],\n  begin\n    rewrite [mul_mod_right at this, add.comm at this, add_mul_mod_self_left at this],\n    contradiction\n  end)\n\nlemma even_add_of_even_of_even {n m} : even n → even m → even (n+m) :=\nsuppose even n, suppose even m,\nobtain k₁ (hk₁ : n = 2 * k₁), from exists_of_even `even n`,\nobtain k₂ (hk₂ : m = 2 * k₂), from exists_of_even `even m`,\neven_of_exists (exists.intro (k₁+k₂) (by rewrite [hk₁, hk₂, left_distrib]))\n\nlemma even_add_of_odd_of_odd {n m} : odd n → odd m → even (n+m) :=\nsuppose odd n, suppose odd m,\nhave even (succ n + succ m),\n  from even_add_of_even_of_even (even_succ_of_odd `odd n`) (even_succ_of_odd `odd m`),\nhave   even(succ (succ (n + m))), by rewrite [add_succ at this, succ_add at this]; exact this,\neven_of_even_succ_succ this\n\nlemma odd_add_of_even_of_odd {n m} : even n → odd m → odd (n+m) :=\nsuppose even n, suppose odd m,\nhave even (n + succ m), from even_add_of_even_of_even `even n` (even_succ_of_odd `odd m`),\nodd_of_even_succ this\n\nlemma odd_add_of_odd_of_even {n m} : odd n → even m → odd (n+m) :=\nsuppose odd n, suppose even m,\nhave odd (m+n), from odd_add_of_even_of_odd `even m` `odd n`,\nby rewrite add.comm at this; exact this\n\nlemma even_mul_of_even_left {n} (m) : even n → even (n*m) :=\nsuppose even n,\nobtain k (hk : n = 2*k), from exists_of_even this,\neven_of_exists (exists.intro (k*m) (by rewrite [hk, mul.assoc]))\n\nlemma even_mul_of_even_right {n} (m) : even n → even (m*n) :=\nsuppose even n,\nhave even (n*m), from even_mul_of_even_left _ this,\nby rewrite mul.comm at this; exact this\n\nlemma odd_mul_of_odd_of_odd {n m} : odd n → odd m → odd (n*m) :=\nsuppose odd n, suppose odd m,\nhave even (n * succ m), from even_mul_of_even_right _ (even_succ_of_odd `odd m`),\nhave even (n * m + n),  by rewrite mul_succ at this; exact this,\nby_contradiction (suppose ¬ odd (n*m),\n  have even (n*m), from even_of_not_odd this,\n  absurd `even (n * m + n)` (not_even_of_odd (odd_add_of_even_of_odd this `odd n`)))\n\nlemma even_of_even_mul_self {n} : even (n * n) → even n :=\nsuppose even (n * n),\nby_contradiction (suppose odd n,\n  have odd (n * n), from odd_mul_of_odd_of_odd this this,\n  show false, from this `even (n * n)`)\n\nlemma odd_of_odd_mul_self {n} : odd (n * n) → odd n :=\nsuppose odd (n * n),\n  suppose even n,\n  have even (n * n), from !even_mul_of_even_left this,\n  show false, from `odd (n * n)` this\n\nlemma odd_pow {n m} (h : odd n) : odd (n^m) :=\nnat.induction_on m\n  (show odd (n^0), from dec_trivial)\n  (take m, suppose odd (n^m),\n    show odd (n^(m+1)), from odd_mul_of_odd_of_odd h this)\n\nlemma even_pow {n m} (mpos : m > 0) (h : even n) : even (n^m) :=\nhave h₁ : ∀ m, even (n^succ m),\n  from take m, nat.induction_on m\n    (show even (n^1), by rewrite pow_one; apply h)\n    (take m, suppose even (n^succ m),\n      show even (n^(succ (succ m))), from !even_mul_of_even_left h),\nobtain m' (h₂ : m = succ m'), from exists_eq_succ_of_pos mpos,\nshow even (n^m), by rewrite h₂; apply h₁\n\nlemma odd_of_odd_pow {n m} (mpos : m > 0) (h : odd (n^m)) : odd n :=\nsuppose even n,\nhave even (n^m), from even_pow mpos this,\nshow false, from `odd (n^m)` this\n\nlemma even_of_even_pow {n m} (h : even (n^m)) : even n :=\nby_contradiction\n  (suppose odd n,\n    have odd (n^m), from odd_pow this,\n    show false, from this `even (n^m)`)\n\nlemma eq_of_div2_of_even {n m : nat} : n / 2 = m / 2 → (even n ↔ even m) → n = m :=\nassume h₁ h₂,\n or.elim (em (even n))\n   (suppose even n, or.elim (em (even m))\n     (suppose even m,\n      obtain w₁ (hw₁ : n = 2*w₁), from exists_of_even `even n`,\n      obtain w₂ (hw₂ : m = 2*w₂), from exists_of_even `even m`,\n      begin\n        substvars, rewrite [mul.comm 2 w₁ at h₁, mul.comm 2 w₂ at h₁,\n                            *nat.mul_div_cancel _ (dec_trivial : 2 > 0) at h₁, h₁]\n      end)\n     (suppose odd m,  absurd `odd m` (not_odd_of_even (iff.mp h₂ `even n`))))\n   (suppose odd n,  or.elim (em (even m))\n     (suppose even m, absurd `odd n` (not_odd_of_even (iff.mpr h₂ `even m`)))\n     (suppose odd m,\n      have d : 1 / 2 = (0:nat),   from dec_trivial,\n      obtain w₁ (hw₁ : n = 2*w₁ + 1), from exists_of_odd `odd n`,\n      obtain w₂ (hw₂ : m = 2*w₂ + 1), from exists_of_odd `odd m`,\n      begin\n        substvars,\n        rewrite [add.comm at h₁, add_mul_div_self_left _ _ (dec_trivial : 2 > 0) at h₁, d at h₁,\n                 zero_add at h₁],\n        rewrite [add.comm at h₁, add_mul_div_self_left _ _ (dec_trivial : 2 > 0) at h₁, d at h₁,\n                 zero_add at h₁],\n        rewrite h₁\n      end))\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.773638791423157}}
{"text": "-- Classical Logic\n\nopen classical\n\nvariables p q : Prop\n#check em p\n\ntheorem dne {p : Prop} (h : ¬¬ p) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : ¬ p, absurd hnp h)\n\n-- theorem converse {p : Prop} : p ∨ ¬ p :=\n-- stopped here - no idea how to prove this!\n\n-- There is a classical proof in Lemmon, result 44, p52!\n-- As a warm-up for converting natural deduction proofs\n-- into Lean proofs, try result 23 on p27.\n\ntheorem lemmon_23 {p : Prop} (h : p → ¬ p) : ¬ p :=\nassume hp : p,\nhave hnp : ¬ p, from h hp,\nshow false, from hnp hp\n\n#check @lemmon_23 p\n#print lemmon_23\n\n-- Write lemmon_23 as a term\n\ntheorem lemmon_23' {p : Prop} (h : p → ¬ p) : ¬ p :=\nλ hp : p, (h hp) hp\n\n#check @lemmon_23' p\n#check lemmon_23'\n\ntheorem lemmon_44 {p : Prop} : p ∨ ¬ p :=\nhave hdn : ¬ ¬ (p ∨ ¬ p), from (\n  assume h : ¬ (p ∨ ¬ p),\n  have hnp : ¬ p, from (\n    assume hp : p,\n    have h1 : p ∨ ¬ p, from or.intro_left (¬ p) hp,\n    show false, from h h1),\n  have h2 : p ∨ ¬ p, from or.intro_right p hnp,\n  show false, from h h2),\nshow p ∨ ¬ p, from dne hdn\n\n-- Not sure about the \"assume\", \"show\" syntax, \n-- but it looks like lambda abstraction.\n-- Does \"show\" pair up with the nearest \"assume\" and close its scope?\n-- I think \"show\" simply annotates the result given by the \"from\".\n\n-- \"show\" and \"from\" are used to annotate a term, \n-- which could be expected in the context of either the definition or the lambda\n\n#check @lemmon_44 p\n#check lemmon_44\n#print lemmon_44\n\n-- Try using \"suffices\" to improve lemmon_44\n\ntheorem lemmon_44' {p : Prop} : p ∨ ¬ p :=\nsuffices hdn : ¬ ¬ (p ∨ ¬ p), from dne hdn,\nassume h : ¬ (p ∨ ¬ p),\nhave hnp : ¬ p, from (\n  assume hp : p,\n  have h1 : p ∨ ¬ p, from or.intro_left (¬ p) hp,\n  show false, from h h1),\nhave h2 : p ∨ ¬ p, from or.intro_right p hnp,\nshow false, from h h2\n\n#check lemmon_44'\n\nexample (h : ¬ ¬ p) : p :=\nby_cases\n  (assume h1 : p, h1)\n  (assume h1 : ¬ p, absurd h1 h)\n\nexample (h : ¬ ¬ p) : p :=\nby_contradiction\n  (assume h1 : ¬ p,\n    show false, from h h1)\n\nexample (h : ¬ (p ∧ q)) : ¬ p ∨ ¬ q :=\nor.elim (em p)\n  (assume hp : p,\n    or.inr \n      (show ¬ q, from\n        assume hq : q, \n        h ⟨ hp, hq ⟩ ))\n  (assume hp : ¬ p, \n    or.inl 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/03-Propositions-and-Proofs/example-3.5-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7736387883147878}}
{"text": "/-\n  Package the definition of an open cover of an open set.\n-/\n\nimport topology.basic\nimport topology.opens\nimport to_mathlib.opens\n\nuniverses u \n\nopen topological_space lattice\n\nsection covering\n\nvariables {α : Type u} [topological_space α]\n\n-- Open cover.\n\nstructure covering (U : opens α) := \n{γ    : Type u}\n(Uis  : γ → opens α)\n(Hcov : ⋃ Uis = U)\n\nvariable (α)\n\ndef covering.univ := covering (@opens.univ α _)\n\nvariable {α}\n\n-- If ⋃ Ui = U then for all i, Ui ⊆ U.\n\nlemma subset_covering {U : opens α} {OC : covering U} : \n∀ i, OC.Uis i ⊆ U := \nλ i x Hx, OC.Hcov ▸ 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) → set (opens A) := λ C, { x | x.1 ∈ C }\n\nlemma opens.from_sets.eq {A : Type*} [topological_space A] \n(S : set (set A)) (HS : ∀ (t : set A), t ∈ S → is_open t)\n: subtype.val '' (opens.from_sets S) = S :=\nset.ext $ λ x, ⟨\n  λ ⟨x', Hx', Hval⟩, Hval ▸ Hx',\n  λ Hx, by simp [HS x Hx]; by exact Hx⟩ \n\n@[reducible] def covering.from_cover {A : Type*} [topological_space A]\n(U     : opens A)\n(C     : set (set A))\n(HC    : ∀ (t : set A), t ∈ C → is_open t)\n(Hcov : U.1 = ⋃₀ C)\n: covering U :=\n{ γ := opens.from_sets C,\n  Uis := λ 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 ⟨U, HU, HxU⟩,\n        existsi U,\n        simp at HU,\n        rcases HU with ⟨OU, HU⟩,\n        rw ←opens.from_sets.eq C HC,\n        split,\n        { simp [HU],\n          use OU, },\n        { exact HxU, } },\n      { intros Hx,\n        rcases Hx with ⟨U, HU, HxU⟩,\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    : ∀ (t : set A), t ∈ C → is_open t)\n(Hcov : U.1 = ⋃₀ C)\n: ∀ i, ((covering.from_cover U C HC Hcov).Uis i).1 ∈ 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": "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/sheaves/covering/covering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7736387860534479}}
{"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\nimport combinatorics.composition\nimport data.nat.parity\nimport tactic.apply_fun\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\nvariables {α : Type*}\n\nopen multiset\nopen_locale big_operators\n\nnamespace nat\n\n/-- A partition of `n` is a multiset of positive integers summing to `n`. -/\n@[ext, derive decidable_eq] structure partition (n : ℕ) :=\n(parts : multiset ℕ)\n(parts_pos : ∀ {i}, i ∈ parts → 0 < i)\n(parts_sum : parts.sum = n)\n\nnamespace partition\n\n/-- A composition induces a partition (just convert the list to a multiset). -/\ndef of_composition (n : ℕ) (c : composition n) : partition n :=\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\nlemma of_composition_surj {n : ℕ} : function.surjective (of_composition n) :=\nbegin\n  rintro ⟨b, hb₁, hb₂⟩,\n  rcases quotient.exists_rep b with ⟨b, rfl⟩,\n  refine ⟨⟨b, λ i hi, hb₁ hi, _⟩, partition.ext _ _ rfl⟩,\n  simpa using hb₂\nend\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-- proof obligation `l.sum = n`.\ndef of_sums (n : ℕ) (l : multiset ℕ) (hl : l.sum = n) : partition n :=\n{ parts := l.filter (≠ 0),\n  parts_pos := λ i hi, nat.pos_of_ne_zero $ by apply of_mem_filter hi,\n  parts_sum :=\n  begin\n    have lt : l.filter (= 0) + l.filter (≠ 0) = l := filter_add_not _ l,\n    apply_fun multiset.sum at lt,\n    have lz : (l.filter (= 0)).sum = 0,\n    { rw multiset.sum_eq_zero_iff,\n      simp },\n    simpa [lz, hl] using lt,\n  end }\n\n/-- A `multiset ℕ` induces a partition on its sum. -/\ndef of_multiset (l : multiset ℕ) : partition l.sum :=\nof_sums _ l rfl\n\n/-- The partition of exactly one part. -/\ndef indiscrete_partition (n : ℕ) : partition n :=\nof_sums n {n} rfl\n\ninstance {n : ℕ} : inhabited (partition n) := ⟨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-/\nlemma count_of_sums_of_ne_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) {i : ℕ} (hi : i ≠ 0) :\n  (of_sums n l hl).parts.count i = l.count i :=\ncount_filter_of_pos hi\n\nlemma count_of_sums_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) :\n  (of_sums n l hl).parts.count 0 = 0 :=\ncount_filter_of_neg (λ h, h rfl)\n\n/--\nShow there are finitely many partitions by considering the surjection from compositions to\npartitions.\n-/\ninstance (n : ℕ) : fintype (partition n) :=\nfintype.of_surjective (of_composition n) of_composition_surj\n\n/-- The finset of those partitions in which every part is odd. -/\ndef odds (n : ℕ) : finset (partition n) :=\nfinset.univ.filter (λ c, ∀ i ∈ c.parts, ¬ even i)\n\n/-- The finset of those partitions in which each part is used at most once. -/\ndef distincts (n : ℕ) : finset (partition n) :=\nfinset.univ.filter (λ c, c.parts.nodup)\n\n/-- The finset of those partitions in which every part is odd and used at most once. -/\ndef odd_distincts (n : ℕ) : finset (partition n) := odds n ∩ distincts n\n\nend partition\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/partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8577680977182187, "lm_q1q2_score": 0.773638785260812}}
{"text": "/-\n-/\n\nsection homework\n\nvariables P Q R S : Prop\n\nexample : (P → (Q → R)) → (P ∧ Q → R) := \n    sorry\n\nexample : P ∧ (P → Q) → Q :=\nassume h : P ∧ (P → Q),\nhave p : P := h.left,\nshow Q,\nfrom h.right p\n\nexample : P → ¬ (¬ P ∧ Q) :=\nassume p: P,\nassume c: (¬ P ∧ Q),\nhave np: ¬ P := c.left,\nshow false,\nfrom np p\n\nexample : ¬ (P ∧ Q) → (P → ¬ Q) :=\nassume h : ¬ (P ∧ Q),\nassume p : P,\nsorry\n\nexample (h₁ : P ∨ Q) (h₂ : P → R) (h₃ : Q → S) : R ∨ S :=\nsorry\n\nexample (h : ¬ P ∧ ¬ Q) : ¬ (P ∨ Q) :=\nsorry\n\nexample : ¬ (P ↔ ¬ P) :=\nsorry \n\n/-\nProve P → ¬ ¬ P without using\nthe axiom of the excluded middle.\n\nCan you prove ¬ ¬ P → P without using\nthe axiom of the excluded middle. Explain.\n\nCan you prove (P → Q) → (¬ Q → ¬ P) \n\"intuitionistically\" (without relying\ndirectly or indirectly on the axiom \nof the excluded middle)? If so, prove \nit intuitionistically. If not, explain \nexactly where you get stuck and then\nprove it \"classically\" (where you can\nuse, directly or indirectly, the axiom\nof the excluded middle).\n\nCan you prove (¬ Q → ¬ P) → (P → Q)\n\"intuitionistically\" (without relying\ndirectly or indirectly on the axiom \nof the excluded middle)? If so, prove \nit intuitionistically. If not, explain \nexactly where you get stuck and then\nprove it \"classically\" (where you can\nuse, directly or indirectly, the axiom\nof the excluded middle).\n-/\n\n\nCommutativity of ∧: A∧B↔B∧A\nCommutativity of ∨: A∨B↔B∨A\nAssociativity of ∧: (A∧B)∧C↔A∧(B∧C)\nAssociativity of ∨ (A∨B)∨C↔A∨(B∨C)\nDistributivity of ∧ over ∨: A∧(B∨C)↔(A∧B)∨(A∧C)\nDistributivity of ∨ over ∧: A∨(B∧C)↔(A∨B)∧(A∨C)\n(A→(B→C))↔(A∧B→C).\n(A→B)→((B→C)→(A→C))\n((A∨B)→C)↔(A→C)∧(B→C)\n¬(A∨B)↔¬A∧¬B\n¬(A∧B)↔¬A∨¬B\n¬(A∧¬A)\n¬(A→B)↔A∧¬B\n¬A→(A→B)\n(¬A∨B)↔(A→B)\nA∨⊥↔A\nA∧⊥↔⊥\nA∨¬A\n¬(A↔¬A)\n(A→B)↔(¬B→¬A)\n(A→C∨D)→((A→C)∨(A→D))\n(((A→B)→A)→A)\n\nGive a natural deduction proof of ¬(A∧B)→(A→¬B).\nGive a natural deduction proof of (A→C)∧(B→¬C)→¬(A∧B).\nGive a natural deduction proof of (A∧B)→((A→C)→¬(B→¬C)).\nTake another look at Exercise 3 in the last chapter. Using propositional variables A, B, and C for “Alan likes kangaroos,” “Betty likes frogs” and “Carl likes hamsters,” respectively, express the three hypotheses in the previous problem as symbolic formulas, and then derive a contradiction from them in natural deduction.\nGive a natural deduction proof of A∨B→B∨A.\nGive a natural deduction proof of ¬A∧¬B→¬(A∨B)\nGive a natural deduction proof of ¬(A∧B) from ¬A∨¬B. (You do not need to use proof by contradiction.)\nGive a natural deduction proof of ¬(A↔¬A).\nGive a natural deduction proof of (¬A↔¬B) from hypothesis A↔B.\n\n\n\nend homework", "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/07_Negation/01_homework_key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7736362578182141}}
{"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\nStructures with multiplicative and additive components, including semirings, rings, and fields.\nThe development is modeled after Isabelle's library.\n-/\n\nimport .group\nuniverses u v w\nhott_theory\nset_option old_structure_cmd true\n\nnamespace hott\nopen algebra\n\nvariable {A : Type _}\nnamespace algebra\n/- auxiliary classes -/\n\n@[hott, class] structure distrib (A : Type _) extends has_mul A, has_add A :=\n(left_distrib : Πa b c, mul a (add b c) = add (mul a b) (mul a c))\n(right_distrib : Πa b c, mul (add a b) c = add (mul a c) (mul b c))\n\n@[hott] def left_distrib [s : distrib A] (a b c : A) : a * (b + c) = a * b + a * c :=\ndistrib.left_distrib _ _ _\n\n@[hott] def right_distrib [s: distrib A] (a b c : A) : (a + b) * c = a * c + b * c :=\ndistrib.right_distrib _ _ _\n\n@[hott, class] structure mul_zero_class (A : Type _) extends has_mul A, has_zero A :=\n(zero_mul : Πa, mul zero a = zero)\n(mul_zero : Πa, mul a zero = zero)\n\n@[hott] def zero_mul [s : mul_zero_class A] (a : A) : 0 * a = 0 := mul_zero_class.zero_mul _\n@[hott] def mul_zero [s : mul_zero_class A] (a : A) : a * 0 = 0 := mul_zero_class.mul_zero _\n\n@[hott, class] structure zero_ne_one_class (A : Type _) extends has_zero A, has_one A :=\n(zero_ne_one : zero ≠ one)\n\n@[hott] theorem zero_ne_one [s: zero_ne_one_class A] : 0 ≠ (1:A) := @zero_ne_one_class.zero_ne_one A s\n\n/- semiring -/\n@[hott] structure semiring (A : Type _) extends comm_monoid A renaming\n  mul→add mul_assoc→add_assoc one→zero one_mul→zero_add mul_one→add_zero mul_comm→add_comm,\n  monoid A, distrib A, mul_zero_class A\n\n/- we make it a class now (and not as part of the structure) to avoid\n  semiring.to_comm_monoid to be an instance -/\nattribute [class] semiring\n\n@[hott, reducible, instance] def add_comm_monoid_of_semiring (A : Type _)\n  [H : semiring A] : add_comm_monoid A :=\n@semiring.to_comm_monoid A H\n\n@[hott, reducible, instance] def monoid_of_semiring (A : Type _)\n  [H : semiring A] : monoid A :=\n@semiring.to_monoid A H\n\n@[hott, reducible, instance] def distrib_of_semiring (A : Type _)\n  [H : semiring A] : distrib A :=\n@semiring.to_distrib A H\n\n@[hott, reducible, instance] def mul_zero_class_of_semiring (A : Type _)\n  [H : semiring A] : mul_zero_class A :=\n@semiring.to_mul_zero_class A H\n\nsection semiring\n  variables [s : semiring A] (a b c : A)\n  include s\n\n  @[hott] theorem As {a b c : A} : a + b + c = a + (b + c) :=\n  add.assoc _ _ _\n\n  @[hott] theorem one_add_one_eq_two : 1 + 1 = 2 :> A :=\n  by refl\n\n  @[hott] theorem ne_zero_of_mul_ne_zero_right {a b : A} (H : a * b ≠ 0) : a ≠ 0 :=\n  λthis,\n  have a * b = 0, by rwr [this, zero_mul],\n  H this\n\n  @[hott] theorem ne_zero_of_mul_ne_zero_left {a b : A} (H : a * b ≠ 0) : b ≠ 0 :=\n  λthis,\n  have a * b = 0, by rwr [this, mul_zero],\n  H this\n\n  @[hott] theorem distrib_three_right (a b c d : A) : (a + b + c) * d = a * d + b * d + c * d :=\n  by rwr [right_distrib, right_distrib]\n\n  @[hott] theorem mul_two : a * 2 = a + a :=\n  by rwr [←one_add_one_eq_two, left_distrib, mul_one]\n\n  @[hott] theorem two_mul : 2 * a = a + a :=\n  by rwr [←one_add_one_eq_two, right_distrib, one_mul]\n\nend semiring\n\n/- comm semiring -/\n\n@[hott, class] structure comm_semiring (A : Type _) extends semiring A, comm_monoid A\n-- TODO: we could also define a cancelative comm_semiring, i.e. satisfying\n-- c ≠ 0 → c * a = c * b → a = b.\n\n-- section comm_semiring\n--   variables [s : comm_semiring A] (a b c : A)\n--   include s\n\n--   @[hott] protected def algebra.dvd (a b : A) : Type _ := Σc, b = a * c\n\n--   @[hott, instance, priority 500] def comm_semiring_has_dvd : has_dvd A :=\n--   has_dvd.mk hott.algebra.dvd\n\n--   @[hott] theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b :=\n--   sigma.mk _ H⁻¹\n\n--   @[hott] theorem dvd_of_mul_right_eq {a b c : A} (H : a * c = b) : a ∣ b := dvd.intro H\n\n--   @[hott] theorem dvd.intro_left {a b c : A} (H : c * a = b) : a ∣ b :=\n--   by rwr mul.comm at H; exact dvd.intro H\n\n--   @[hott] theorem dvd_of_mul_left_eq {a b c : A} (H : c * a = b) : a ∣ b := dvd.intro_left H\n\n--   @[hott] theorem exists_eq_mul_right_of_dvd {a b : A} (H : a ∣ b) : Σc, b = a * c := H\n\n--   @[hott] theorem dvd.elim {P : Type _} {a b : A} (H₁ : a ∣ b) (H₂ : Πc, b = a * c → P) : P :=\n--   sigma.rec_on H₁ H₂\n\n--   @[hott] theorem exists_eq_mul_left_of_dvd {a b : A} (H : a ∣ b) : Σc, b = c * a :=\n--   dvd.elim H (take c, assume H1 : b = a * c, sigma.mk c (H1 ⬝ mul.comm _ _))\n\n--   @[hott] theorem dvd.elim_left {P : Type _} {a b : A} (H₁ : a ∣ b) (H₂ : Πc, b = c * a → P) : P :=\n--   sigma.rec_on (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃)\n\n--   @[hott] theorem dvd.refl : a ∣ a := dvd.intro (mul_one _)\n\n--   @[hott] theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c :=\n--   dvd.elim H₁\n--     (take d, assume H₃ : b = a * d,\n--       dvd.elim H₂\n--         (take e, assume H₄ : c = b * e,\n--           dvd.intro\n--             (show a * (d * e) = c, by rwr [←mul.assoc, -H₃, H₄])))\n\n--   @[hott] theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 :=\n--     dvd.elim H (take c, assume H' : a = 0 * c, H' ⬝ (zero_mul _))\n\n--   @[hott] theorem dvd_zero : a ∣ 0 := dvd.intro (mul_zero _)\n\n--   @[hott] theorem one_dvd : 1 ∣ a := dvd.intro (one_mul _)\n\n--   @[hott] theorem dvd_mul_right : a ∣ a * b := dvd.intro rfl\n\n--   @[hott] theorem dvd_mul_left : a ∣ b * a :=\n--   by rwr mul.comm; apply dvd_mul_right\n\n--   @[hott] theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c :=\n--   dvd.elim H\n--     (take d,\n--       suppose b = a * d,\n--       dvd.intro\n--         (show a * (d * c) = b * c, from by rwr [←mul.assoc]; substvars))\n\n--   @[hott] theorem dvd_mul_of_dvd_right {a b : A} (H : a ∣ b) (c : A) : a ∣ c * b :=\n--   by rwr mul.comm; exact dvd_mul_of_dvd_left H _\n\n--   @[hott] theorem mul_dvd_mul {a b c d : A} (dvd_ab : a ∣ b) (dvd_cd : c ∣ d) : a * c ∣ b * d :=\n--   dvd.elim dvd_ab\n--     (take e, suppose b = a * e,\n--       dvd.elim dvd_cd\n--         (take f, suppose d = c * f,\n--           dvd.intro\n--             (show a * c * (e * f) = b * d,\n--              by rwr [mul.assoc, {c*_}mul.left_comm, -mul.assoc]; substvars)))\n\n--   @[hott] theorem dvd_of_mul_right_dvd {a b c : A} (H : a * b ∣ c) : a ∣ c :=\n--   dvd.elim H (take d, assume Habdc : c = a * b * d, dvd.intro ((mul.assoc _ _ _)⁻¹ ⬝ (Habdc _ _ _ _)⁻¹))\n\n--   @[hott] theorem dvd_of_mul_left_dvd {a b c : A} (H : a * b ∣ c) : b ∣ c :=\n--   by apply dvd_of_mul_right_dvd; rwr mul.comm; exact H\n\n--   @[hott] theorem dvd_add {a b c : A} (Hab : a ∣ b) (Hac : a ∣ c) : a ∣ b + c :=\n--   dvd.elim Hab\n--     (take d, suppose b = a * d,\n--       dvd.elim Hac\n--         (take e, suppose c = a * e,\n--           dvd.intro (show a * (d + e) = b + c,\n--                      by rwr [left_distrib]; substvars)))\n-- end comm_semiring\n\n/- ring -/\n\n@[hott] structure ring (A : Type _) extends ab_group A renaming mul→add mul_assoc→add_assoc\n  one→zero one_mul→zero_add mul_one→add_zero inv→neg mul_left_inv→add_left_inv mul_comm→add_comm,\n  monoid A, distrib A\n\n/- we make it a class now (and not as part of the structure) to avoid\n  ring.to_ab_group to be an instance -/\nattribute [class] ring\n\n@[hott, reducible, instance] def add_ab_group_of_ring (A : Type _)\n  [H : ring A] : add_ab_group A :=\n@ring.to_ab_group A H\n\n@[hott, reducible, instance] def monoid_of_ring (A : Type _)\n  [H : ring A] : monoid A :=\n@ring.to_monoid A H\n\n@[hott, reducible, instance] def distrib_of_ring (A : Type _)\n  [H : ring A] : distrib A :=\n@ring.to_distrib A H\n\n@[hott] def ring.mul_zero [s : ring A] (a : A) : a * 0 = 0 :=\nhave a * 0 + 0 = a * 0 + a * 0, from calc\n  a * 0 + 0 = a * 0         : by rwr add_zero\n        ... = a * (0 + 0)   : by rwr add_zero\n        ... = a * 0 + a * 0 : left_distrib a 0 0,\nshow a * 0 = 0, from (add.left_cancel this)⁻¹\n\n@[hott] def ring.zero_mul [s : ring A] (a : A) : 0 * a = 0 :=\nhave 0 * a + 0 = 0 * a + 0 * a, from calc\n  0 * a + 0 = 0 * a         : by rwr add_zero\n        ... = (0 + 0) * a   : by rwr add_zero\n        ... = 0 * a + 0 * a : right_distrib 0 0 a,\nshow 0 * a = 0, from  (add.left_cancel this)⁻¹\n\n@[hott, reducible, instance] def ring.to_semiring [s : ring A] : semiring A :=\n{ mul_zero := ring.mul_zero,\n  zero_mul := ring.zero_mul, ..s}\n\nsection\nvariables [s : ring A] (a b c d e : A)\ninclude s\n\n@[hott] def neg_mul_eq_neg_mul : -(a * b) = -a * b :=\nneg_eq_of_add_eq_zero\n  begin\n    rwr [←right_distrib, add.right_inv, zero_mul]\n  end\n\n@[hott] def neg_mul_eq_mul_neg : -(a * b) = a * -b :=\n neg_eq_of_add_eq_zero\n   begin\n     rwr [←left_distrib, add.right_inv, mul_zero]\n   end\n\n@[hott] def neg_mul_eq_neg_mul_symm : - a * b = - (a * b) := (neg_mul_eq_neg_mul _ _)⁻¹ᵖ\n@[hott] def mul_neg_eq_neg_mul_symm : a * - b = - (a * b) := (neg_mul_eq_mul_neg _ _)⁻¹ᵖ\n\n@[hott] theorem neg_mul_neg : -a * -b = a * b :=\ncalc\n   -a * -b = -(a * -b) : by rwr ←neg_mul_eq_neg_mul\n     ... = - -(a * b)  : by rwr ←neg_mul_eq_mul_neg\n     ... = a * b       : by rwr neg_neg\n\n@[hott] theorem neg_mul_comm : -a * b = a * -b :=\n(neg_mul_eq_neg_mul _ _)⁻¹ ⬝ (neg_mul_eq_mul_neg _ _)\n\n@[hott] def neg_eq_neg_one_mul : -a = - 1 * a :=\ncalc\n  -a = -(1 * a)  : by rwr one_mul\n    ... = - 1 * a : by rwr neg_mul_eq_neg_mul\n\n@[hott] def mul_sub_left_distrib : a * (b - c) = a * b - a * c :=\ncalc\n  a * (b - c) = a * b + a * -c : left_distrib _ _ _\n    ... = a * b + - (a * c)    : by rwr ←neg_mul_eq_mul_neg\n    ... = a * b - a * c        : rfl\n\n@[hott] def mul_sub_right_distrib : (a - b) * c = a * c - b * c :=\ncalc\n  (a - b) * c = a * c  + -b * c : right_distrib _ _ _\n    ... = a * c + - (b * c)     : by rwr neg_mul_eq_neg_mul\n    ... = a * c - b * c         : rfl\n\n@[hott] theorem mul_add_eq_mul_add_iff_sub_mul_add_eq :\n  a * e + c = b * e + d ↔ (a - b) * e + c = d :=\ncalc\n  a * e + c = b * e + d ↔ a * e + c = d + b * e : by rwr add.comm (b*e)\n    ... ↔ a * e + c - b * e = d : iff.symm (sub_eq_iff_eq_add _ _ _)\n    ... ↔ a * e - b * e + c = d : by rwr sub_add_eq_add_sub\n    ... ↔ (a - b) * e + c = d   : by rwr mul_sub_right_distrib\n\n@[hott] theorem mul_add_eq_mul_add_of_sub_mul_add_eq :\n  (a - b) * e + c = d → a * e + c = b * e + d :=\niff.mpr (mul_add_eq_mul_add_iff_sub_mul_add_eq _ _ _ _ _)\n\n@[hott] theorem sub_mul_add_eq_of_mul_add_eq_mul_add :\n  a * e + c = b * e + d → (a - b) * e + c = d :=\niff.mp (mul_add_eq_mul_add_iff_sub_mul_add_eq _ _ _ _ _)\n\n@[hott] theorem mul_neg_one_eq_neg : a * (- 1) = -a :=\n  have a + a * - 1 = 0, from calc\n    a + a * - 1 = a * 1 + a * - 1 : by rwr mul_one\n           ... = a * (1 + - 1)   : by rwr left_distrib\n           ... = a * 0          : by rwr add.right_inv\n           ... = 0              : by rwr mul_zero,\n  (neg_eq_of_add_eq_zero this)⁻¹\n\n@[hott] theorem ne_zero_prod_ne_zero_of_mul_ne_zero {a b : A} (H : a * b ≠ 0) : a ≠ 0 × b ≠ 0 :=\n  have H1 : a ≠ 0, from\n    (λthis,\n      have a * b = 0, by rwr [this, zero_mul],\n      absurd this H),\n  have b ≠ 0, from\n    (λthis,\n      have a * b = 0, by rwr [this, mul_zero],\n      absurd this H),\n  prod.mk H1 this\nend\n\n@[hott, class] structure comm_ring (A : Type _) extends ring A, comm_semigroup A\n\n@[hott, reducible, instance] def comm_ring.to_comm_semiring [s : comm_ring A] :\n  comm_semiring A :=\n{ mul_zero := mul_zero,\n  zero_mul := zero_mul, ..s }\n\nsection\n  variables [s : comm_ring A] (a b c d e : A)\n  include s\n\n  @[hott] theorem mul_self_sub_mul_self_eq : a * a - b * b = (a + b) * (a - b) :=\n  begin\n    change a * a + - (b * b) = (a + b) * (a + - b),\n    rwr [left_distrib, right_distrib, right_distrib, add.assoc],\n    rwr [←add.assoc (b*a),\n             ←neg_mul_eq_mul_neg, ←neg_mul_eq_mul_neg, mul.comm a b, add.right_inv, zero_add]\n  end\n\n  @[hott] theorem mul_self_sub_one_eq : a * a - 1 = (a + 1) * (a - 1) :=\n  by rwr [←mul_self_sub_mul_self_eq, mul_one]\n\n  -- @[hott] theorem dvd_neg_iff_dvd : (a ∣ -b) ↔ (a ∣ b) :=\n  -- iff.intro\n  --   (suppose a ∣ -b,\n  --     dvd.elim this\n  --       (take c, suppose -b = a * c,\n  --         dvd.intro\n  --           (show a * -c = b,\n  --            by rwr [←neg_mul_eq_mul_neg, -this, neg_neg])))\n  --   (suppose a ∣ b,\n  --     dvd.elim this\n  --       (take c, suppose b = a * c,\n  --         dvd.intro\n  --           (show a * -c = -b,\n  --            by rwr [←neg_mul_eq_mul_neg, -this])))\n\n  -- @[hott] theorem dvd_neg_of_dvd : (a ∣ b) → (a ∣ -b) :=\n  --   iff.mpr (dvd_neg_iff_dvd _ _)\n\n  -- @[hott] theorem dvd_of_dvd_neg : (a ∣ -b) → (a ∣ b) :=\n  --   iff.mp (dvd_neg_iff_dvd _ _)\n\n  -- @[hott] theorem neg_dvd_iff_dvd : (-a ∣ b) ↔ (a ∣ b) :=\n  -- iff.intro\n  --   (suppose -a ∣ b,\n  --     dvd.elim this\n  --       (take c, suppose b = -a * c,\n  --         dvd.intro\n  --           (show a * -c = b, by rwr [←neg_mul_comm, this])))\n  --   (suppose a ∣ b,\n  --     dvd.elim this\n  --       (take c, suppose b = a * c,\n  --         dvd.intro\n  --           (show -a * -c = b, by rwr [neg_mul_neg, this])))\n\n  -- @[hott] theorem neg_dvd_of_dvd : (a ∣ b) → (-a ∣ b) :=\n  --   iff.mpr (neg_dvd_iff_dvd _ _)\n\n  -- @[hott] theorem dvd_of_neg_dvd : (-a ∣ b) → (a ∣ b) :=\n  --   iff.mp (neg_dvd_iff_dvd _ _)\n\n  -- @[hott] theorem dvd_sub (H₁ : (a ∣ b)) (H₂ : (a ∣ c)) : (a ∣ b - c) :=\n  -- dvd_add H₁ (dvd_neg_of_dvd H₂)\nend\n\n/- integral domains -/\n\n@[hott, class] structure no_zero_divisors (A : Type _) extends has_mul A, has_zero A :=\n(eq_zero_sum_eq_zero_of_mul_eq_zero : Πa b, mul a b = zero → a = zero ⊎ b = zero)\n\n@[hott] def eq_zero_sum_eq_zero_of_mul_eq_zero {A : Type _} [s : no_zero_divisors A] {a b : A}\n    (H : a * b = 0) : a = 0 ⊎ b = 0 :=\nno_zero_divisors.eq_zero_sum_eq_zero_of_mul_eq_zero _ _ H\n\n@[hott, class] structure integral_domain (A : Type _) extends comm_ring A, no_zero_divisors A,\n    zero_ne_one_class A\n\nsection\n  variables [s : integral_domain A] (a b c d e : A)\n  include s\n\n  @[hott] theorem mul_ne_zero {a b : A} (H1 : a ≠ 0) (H2 : b ≠ 0) : a * b ≠ 0 :=\n  λthis,\n    sum.elim (eq_zero_sum_eq_zero_of_mul_eq_zero this) (assume H3, H1 H3) (assume H4, H2 H4)\n\n  -- @[hott] theorem eq_of_mul_eq_mul_right {a b c : A} (Ha : a ≠ 0) (H : b * a = c * a) : b = c :=\n  -- have b * a - c * a = 0, from iff.mp (eq_iff_sub_eq_zero _ _) H,\n  -- have (b - c) * a = 0, by rwr [mul_sub_right_distrib, this],\n  -- have b - c = 0, from sum_resolve_left (eq_zero_sum_eq_zero_of_mul_eq_zero this) Ha,\n  -- iff.elim_right (eq_iff_sub_eq_zero _ _) this\n\n  -- @[hott] theorem eq_of_mul_eq_mul_left {a b c : A} (Ha : a ≠ 0) (H : a * b = a * c) : b = c :=\n  -- have a * b - a * c = 0, from iff.mp (eq_iff_sub_eq_zero _ _) H,\n  -- have a * (b - c) = 0, by rwr [mul_sub_left_distrib, this],\n  -- have b - c = 0, from sum_resolve_right (eq_zero_sum_eq_zero_of_mul_eq_zero this) Ha,\n  -- iff.elim_right (eq_iff_sub_eq_zero _ _) this\n\n  -- -- TODO: do we want the iff versions?\n\n  -- @[hott] theorem eq_zero_of_mul_eq_self_right {a b : A} (H₁ : b ≠ 1) (H₂ : a * b = a) : a = 0 :=\n  -- have b - 1 ≠ 0, by intro this; apply H₁; rwr zero_add; apply eq_add_of_sub_eq; exact this,\n  -- have a * b - a = 0, by rwr H₂; apply sub_self,\n  -- have a * (b - 1) = 0, by rwr [mul_sub_left_distrib, mul_one]; apply this,\n  --   show a = 0, from sum_resolve_left (eq_zero_sum_eq_zero_of_mul_eq_zero this) `b - 1 ≠ 0`\n\n  -- @[hott] theorem eq_zero_of_mul_eq_self_left {a b : A} (H₁ : b ≠ 1) (H₂ : b * a = a) : a = 0 :=\n  -- by apply eq_zero_of_mul_eq_self_right H₁; by rwr mul.comm; exact H₂\n\n  -- @[hott] theorem mul_self_eq_mul_self_iff (a b : A) : a * a = b * b ↔ a = b ⊎ a = -b :=\n  -- iff.intro\n  --   (suppose a * a = b * b,\n  --     have (a - b) * (a + b) = 0,\n  --       by rwr [mul.comm, -mul_self_sub_mul_self_eq, this, sub_self],\n  --     have a - b = 0 ⊎ a + b = 0, from eq_zero_sum_eq_zero_of_mul_eq_zero this,\n  --     sum.elim this\n  --       (suppose a - b = 0, sum.inl (eq_of_sub_eq_zero this))\n  --       (suppose a + b = 0, sum.inr (eq_neg_of_add_eq_zero this)))\n  --   (suppose a = b ⊎ a = -b, sum.elim this\n  --     (suppose a = b,  by rwr this)\n  --     (suppose a = -b, by rwr [this, neg_mul_neg]))\n\n  -- @[hott] theorem mul_self_eq_one_iff (a : A) : a * a = 1 ↔ a = 1 ⊎ a = - 1 :=\n  -- have a * a = 1 * 1 ↔ a = 1 ⊎ a = - 1, from mul_self_eq_mul_self_iff a 1,\n  -- by rwr mul_one at this; exact this\n\n  -- -- TODO: c - b * c → c = 0 ⊎ b = 1 and variants\n\n  -- @[hott] theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=\n  -- dvd.elim Hdvd\n  --   (take d,\n  --     suppose a * c = a * b * d,\n  --     have b * d = c, by apply eq_of_mul_eq_mul_left Ha; rwr [mul.assoc, this],\n  --     dvd.intro this)\n\n  -- @[hott] theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=\n  -- dvd.elim Hdvd\n  --   (take d,\n  --     suppose c * a = b * a * d,\n  --     have b * d * a = c * a, from by rwr [mul.right_comm, -this],\n  --     have b * d = c, from eq_of_mul_eq_mul_right Ha this,\n  --     dvd.intro this)\nend\n\nnamespace norm_num\n\n-- @[hott] theorem mul_zero [s : mul_zero_class A] (a : A) : a * zero = zero :=\n--   by rwr [↑zero, mul_zero]\n\n-- @[hott] theorem zero_mul [s : mul_zero_class A] (a : A) : zero * a = zero :=\n--   by rwr [↑zero, zero_mul]\n\n-- @[hott] theorem mul_one [s : monoid A] (a : A) : a * one = a :=\n--   by rwr [↑one, mul_one]\n\n-- @[hott] theorem mul_bit0 [s : distrib A] (a b : A) : a * (bit0 b) = bit0 (a * b) :=\n--   by rwr [↑bit0, left_distrib]\n\n-- @[hott] theorem mul_bit0_helper [s : distrib A] (a b t : A) (H : a * b = t) : a * (bit0 b) = bit0 t :=\n--   by rwr ←H; apply mul_bit0\n\n-- @[hott] theorem mul_bit1 [s : semiring A] (a b : A) : a * (bit1 b) = bit0 (a * b) + a :=\n--   by rwr [↑bit1, ↑bit0, +left_distrib, ↑one, mul_one]\n\n-- @[hott] theorem mul_bit1_helper [s : semiring A] (a b s t : A) (Hs : a * b = s) (Ht : bit0 s + a  = t) :\n--         a * (bit1 b) = t :=\n--   begin rwr [←Ht, -Hs, mul_bit1] end\n\n-- @[hott] theorem subst_into_prod [s : has_mul A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)\n--         (prt : tl * tr = t) :\n--         l * r = t :=\n--    by rwr [prl, prr, prt]\n\n-- @[hott] theorem mk_cong (op : A → A) (a b : A) (H : a = b) : op a = op b :=\n--   by congruence; exact H\n\n-- @[hott] theorem mk_eq (a : A) : a = a := rfl\n\n-- @[hott] theorem neg_add_neg_eq_of_add_add_eq_zero [s : add_ab_group A] (a b c : A) (H : c + a + b = 0) :\n--         -a + -b = c :=\n--   begin\n--     apply add_neg_eq_of_eq_add,\n--     apply neg_eq_of_add_eq_zero,\n--     rwr [add.comm, add.assoc, add.comm b, -add.assoc, H]\n--   end\n\n-- @[hott] theorem neg_add_neg_helper [s : add_ab_group A] (a b c : A) (H : a + b = c) : -a + -b = -c :=\n--   begin apply iff.mp (neg_eq_neg_iff_eq _ _), rwr [neg_add, *neg_neg, H] end\n\n-- @[hott] theorem neg_add_pos_eq_of_eq_add [s : add_ab_group A] (a b c : A) (H : b = c + a) : -a + b = c :=\n--   begin apply neg_add_eq_of_eq_add, rwr add.comm, exact H end\n\n-- @[hott] theorem neg_add_pos_helper1 [s : add_ab_group A] (a b c : A) (H : b + c = a) : -a + b = -c :=\n--   begin apply neg_add_eq_of_eq_add, apply eq_add_neg_of_add_eq H end\n\n-- @[hott] theorem neg_add_pos_helper2 [s : add_ab_group A] (a b c : A) (H : a + c = b) : -a + b = c :=\n--   begin apply neg_add_eq_of_eq_add, rwr H end\n\n-- @[hott] theorem pos_add_neg_helper [s : add_ab_group A] (a b c : A) (H : b + a = c) : a + b = c :=\n--   by rwr [add.comm, H]\n\n-- @[hott] theorem sub_eq_add_neg_helper [s : add_ab_group A] (t₁ t₂ e w₁ w₂: A) (H₁ : t₁ = w₁)\n--         (H₂ : t₂ = w₂) (H : w₁ + -w₂ = e) : t₁ - t₂ = e :=\n--   by rwr [sub_eq_add_neg, H₁, H₂, H]\n\n-- @[hott] theorem pos_add_pos_helper [s : add_ab_group A] (a b c h₁ h₂ : A) (H₁ : a = h₁) (H₂ : b = h₂)\n--         (H : h₁ + h₂ = c) : a + b = c :=\n--   by rwr [H₁, H₂, H]\n\n-- @[hott] theorem subst_into_subtr [s : add_group A] (l r t : A) (prt : l + -r = t) : l - r = t :=\n--    by rwr [sub_eq_add_neg, prt]\n\n-- @[hott] theorem neg_neg_helper [s : add_group A] (a b : A) (H : a = -b) : -a = b :=\n--   by rwr [H, neg_neg]\n\n-- @[hott] theorem neg_mul_neg_helper [s : ring A] (a b c : A) (H : a * b = c) : (-a) * (-b) = c :=\n--   begin rwr [neg_mul_neg, H] end\n\n-- @[hott] theorem neg_mul_pos_helper [s : ring A] (a b c : A) (H : a * b = c) : (-a) * b = -c :=\n--   begin rwr [←neg_mul_eq_neg_mul, H] end\n\n-- @[hott] theorem pos_mul_neg_helper [s : ring A] (a b c : A) (H : a * b = c) : a * (-b) = -c :=\n--   begin rwr [←neg_mul_comm, -neg_mul_eq_neg_mul, H] end\n\nend norm_num\nend algebra\nend hott\n", "meta": {"author": "gebner", "repo": "hott3", "sha": "7ead7a8a2503049eacd45cbff6587802bae2add2", "save_path": "github-repos/lean/gebner-hott3", "path": "github-repos/lean/gebner-hott3/hott3-7ead7a8a2503049eacd45cbff6587802bae2add2/src/hott/algebra/ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684336, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7736362501149764}}
{"text": "import data.real.basic\n\nvariables {x y : ℝ}\n\nnamespace my_abs\n\n-- BEGIN\ntheorem lt_abs : x < abs y ↔ x < y ∨ x < -y :=\nbegin\n  split; intro h,\n  { cases lt_or_ge y 0 with y_neg y_nonneg,\n    { rw abs_of_neg y_neg at h, right, exact h, },\n    { rw abs_of_nonneg y_nonneg at h, left, exact h, }, },\n  { cases h with x_lt_y x_lt_neg_y,\n    linarith [le_abs_self y],\n    linarith [neg_le_abs_self y], }\nend\n\ntheorem abs_lt : abs x < y ↔ - y < x ∧ x < y :=\nbegin\n  split; intro h,\n  { split,\n    linarith [neg_abs_le_self x],\n    linarith [le_abs_self x], },\n  { cases lt_or_ge x 0 with x_neg x_nonneg,\n    { rw abs_of_neg x_neg, linarith only [h.1], },\n    { rw abs_of_nonneg x_nonneg, exact h.2 }, },\nend\n-- END\n\nend my_abs", "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/ex4_split_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572777987970316, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7735447990451306}}
{"text": "-- Estructuras y clases\n-- =====================================================================\n\n\n------------------------------------------------------------------------\n-- § Introducción                                                     --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Importar las teorías data.rat.basic, data.nat.parity y\n-- tactic.basic.\n-- ---------------------------------------------------------------------\n\n\nimport data.rat.basic\nimport data.nat.parity\nimport tactic.basic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir la teoría de los naturales.\n-- ----------------------------------------------------------------------\n\nopen nat\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Permitir en esta teoría definiciones no computables.\n-- ----------------------------------------------------------------------\n\nnoncomputable theory\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Permitir el uso de la lógica clásica.\n-- ----------------------------------------------------------------------\n\nopen_locale classical\n\n------------------------------------------------------------------------\n-- § Estructuras y clases                                             --\n------------------------------------------------------------------------\n\n------------------------------------------------------------------------\n-- §§ Declaración de estructuras                                      --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructura even_natural_number con dos campos\n-- + n que es un número natural\n-- + even_n que es una demostración de que n es par.\n-- ----------------------------------------------------------------------\n\nstructure even_natural_number : Type :=\n  (n : ℕ)\n  (even_n : even n)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Ver la información de even_natural_number\n-- ----------------------------------------------------------------------\n\n#print even_natural_number\n\n-- Comentario: Al colocar el curso sobre print se obtiene\n--    structure even_natural_number : Type\n--    fields:\n--    even_natural_number.n : even_natural_number → ℕ\n--    even_natural_number.even_n : ∀ (c : even_natural_number), c.n.even\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructuras (is_even_cube_above_100 n) cuyos\n-- campos son\n-- + even con una demostración de que n es par\n-- + is_cube con una demostración de que n es un cubo y\n-- + gt_100 con una demostración de que n es mayor que 100.\n-- ----------------------------------------------------------------------\n\nstructure is_even_cube_above_100 (n : ℕ) : Prop :=\n  (even : even n)\n  (is_cube : ∃ k, n = k^3)\n  (gt_100 : n > 100)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Ver la información de (is_even_cube_above_100).\n-- ----------------------------------------------------------------------\n\n#print is_even_cube_above_100\n\n-- Comentario: Al colocar el cursor sobre print se obtiene\n--    structure is_even_cube_above_100 : ℕ → Prop\n--    fields:\n--    is_even_cube_above_100.even :\n---     ∀ {n : ℕ}, is_even_cube_above_100 n → n.even\n--    is_even_cube_above_100.is_cube :\n--      ∀ {n : ℕ}, is_even_cube_above_100 n → (∃ (k : ℕ), n = k ^ 3)\n--    is_even_cube_above_100.gt_100 :\n--      ∀ {n : ℕ}, is_even_cube_above_100 n → n > 100\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir las estructuras (bound f) cuyo argumento es una\n-- función de ℕ en ℕ y sus campos son\n-- + bound que es un número natural\n-- + le_bound que es una prueba de que bound es una cota superior de f.\n-- ----------------------------------------------------------------------\n\nstructure bounds (f : ℕ → ℕ) :=\n  (bound : ℕ)\n  (le_bound : ∀ (n : ℕ), f n ≤ bound)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Ver la información de bounds\n-- ----------------------------------------------------------------------\n\n#print bounds\n\n-- Comentario: Al colocar el cursor sobre print se obtiene\n--    structure bounds : (ℕ → ℕ) → Type\n--    fields:\n--    bounds.bound : Π {f : ℕ → ℕ}, bounds f → ℕ\n--    bounds.le_bound : ∀ {f : ℕ → ℕ} (c : bounds f) (n : ℕ), f n ≤ c.bound\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructura eventually_constant_sequence cuyos\n-- campos son\n-- + seq que es una sucesión entera\n-- + eventually_constant que afirma que seq es eventualmente constante.\n-- ----------------------------------------------------------------------\n\nstructure eventually_constant_sequence : Type :=\n(seq : ℕ → ℕ)\n(eventually_constant : ∃ k v, ∀ n ≥ k, seq n = v)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructura bipointed_type de los tipos don dos\n-- elementos distintos.\n-- ----------------------------------------------------------------------\n\nstructure bipointed_type :=\n(A : Type)\n(x y : A)\n(x_ne_y : x ≠ y)\n\n------------------------------------------------------------------------\n-- § Proyecciones de una estructura                                   --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    is_even_cube_above_100 n\n-- entonces n es mayor que 100.\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (n : ℕ)\n  (hn : is_even_cube_above_100 n)\n  : n > 100 :=\nis_even_cube_above_100.gt_100 hn\n\n-- 2ª demostración\n-- ===============\n\nsection\n\nopen is_even_cube_above_100\n\nexample\n  (n : ℕ)\n  (hn : is_even_cube_above_100 n)\n  : n > 100 :=\ngt_100 hn\n\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    is_even_cube_above_100 n\n-- entonces n es par.\n-- ----------------------------------------------------------------------\n\nexample\n  (n : ℕ)\n  (hn : is_even_cube_above_100 n)\n  : even n :=\nhn.even\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    is_even_cube_above_100 n\n-- entonces n es par y cubo.\n-- ----------------------------------------------------------------------\n\nexample\n  (n : ℕ)\n  (hn : is_even_cube_above_100 n)\n  : even n ∧ ∃ k, n = k^3 :=\n⟨ hn.even, hn.is_cube ⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    is_even_cube_above_100 n\n-- entonces n es par, mayor que 100 y cubo.\n-- ----------------------------------------------------------------------\n\nexample\n  (n : ℕ)\n  (hn : is_even_cube_above_100 n)\n  : even n ∧ n > 100 ∧ (∃ k, n = k^3) :=\n⟨ hn.1, hn.3, hn.2 ⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la función\n--    is_even_cube_above_100' : ℕ → Prop\n-- tal que 8is_even_cube_above_100') afirma que n es par, cubo y mayor\n-- que 100.\n-- ----------------------------------------------------------------------\n\ndef is_even_cube_above_100' (n : ℕ) : Prop :=\neven n ∧ (∃ k, n = k^3) ∧ n > 100\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el subtipo even_natural_number' de los números\n-- naturales pares.\n-- ----------------------------------------------------------------------\n\ndef even_natural_number' : Type :=\n{ n : ℕ // even n }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el conjunto set_of_even_natural_numbers de los\n-- números naturales pares.\n-- ----------------------------------------------------------------------\n\ndef set_of_even_natural_numbers : set ℕ :=\n{ n : ℕ | even n }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    even_natural_number → even_natural_number'\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : even_natural_number → even_natural_number' :=\nbegin\n  intro h,\n  cases h with n hn,\n  use n,\n  exact hn,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : even_natural_number → even_natural_number' :=\nλ n, ⟨n.1, n.2⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que, para todo natural n,\n--    is_even_cube_above_100 n → is_even_cube_above_100' n\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (n : ℕ)\n  : is_even_cube_above_100 n → is_even_cube_above_100' n :=\nbegin\n  intro hn,\n  cases hn with neven ncube ngt,\n  split,\n  { exact neven, },\n  { split,\n    { exact ncube, },\n    { exact ngt, }},\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (n : ℕ)\n  : is_even_cube_above_100 n → is_even_cube_above_100' n :=\nbegin\n  rintros ⟨neven, ncube, ngt⟩,\n  exact ⟨neven, ncube, ngt⟩,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (n : ℕ)\n  : is_even_cube_above_100 n → is_even_cube_above_100' n :=\nλ hn, ⟨hn.even, hn.is_cube, hn.gt_100⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    even_natural_number' → even_natural_number\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample : even_natural_number' → even_natural_number :=\nλ n,\n{ even_natural_number .\n  n      := n.1,\n  even_n := n.2 }\n\n-- 2ª demostración\nexample : even_natural_number' → even_natural_number :=\nλ n,\n{ n      := n.1,\n  even_n := n.2 }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que, para todo número natural n,\n--    is_even_cube_above_100' n → is_even_cube_above_100 n\n-- ----------------------------------------------------------------------\n\nexample\n  (n : ℕ)\n  : is_even_cube_above_100' n → is_even_cube_above_100 n :=\nλ ⟨h1n, h2n, h3n⟩,\n{ even    := h1n,\n  is_cube := h2n,\n  gt_100  := h3n }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la función\n--    bounds' : (ℕ → ℕ) → Type\n-- tal que (bound' f) es el subtipo de las cotas superiores de f.\n-- ----------------------------------------------------------------------\n\ndef bounds' (f : ℕ → ℕ) : Type :=\n{ n : ℕ // ∀ (m : ℕ), f m ≤ n }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que para toda f,\n--    bounds f → bounds' f\n-- ----------------------------------------------------------------------\n\nexample\n  (f : ℕ → ℕ)\n  : bounds f → bounds' f :=\nλ ⟨n, hn⟩, ⟨n, hn⟩\n\n-- ----------------------------------------------------------------------\n-- Ejercicio. Demostrar que para toda f,\n--    bounds' f → bounds f\n-- ----------------------------------------------------------------------\n\nexample\n  (f : ℕ → ℕ)\n  : bounds' f → bounds f :=\nλ n, { bound := n.1, le_bound := n.2 }\n\n------------------------------------------------------------------------\n-- § Clases                                                           --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la clase\n--    is_square : ℕ → Prop\n-- tal que (is_square n) si n es un cuadrado.\n-- ----------------------------------------------------------------------\n\n@[class]\ndef is_square (n : ℕ) : Prop :=\n  ∃k : ℕ, k^2 = n\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Iniciar el espacio de nombres is_square.\n-- ----------------------------------------------------------------------\n\nnamespace is_square\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la función\n--    sqrt : ℕ → ℕ\n-- tal que, si n es un número cuadrado, entonces (sqrt n) es su raíz\n-- cuadrada.\n-- ----------------------------------------------------------------------\n\ndef sqrt (n : ℕ) [hn : is_square n] : ℕ := classical.some hn\n\n-- Comentario: Se ha usado el lema\n-- + classical.some : (∃ (x : ℕ), p x) → ℕ [2 times]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir √ como notación para la raíz cuadrada.\n-- ----------------------------------------------------------------------\n\nprefix `√`:(max+1) := sqrt\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si n es un cuadrado, entonces\n--    (√n) ^ 2 = n\n-- y declararlo como regla de simplificación\n-- ----------------------------------------------------------------------\n\n@[simp] lemma square_sqrt\n  (n : ℕ)\n  [hn : is_square n]\n  : (√n) ^ 2 = n :=\nclassical.some_spec hn\n\n-- Comentario: Se ha usado el lema\n-- + classical.some_spec : ∀ (h : ∃ (x : ℕ), p x), p (classical.some h)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si n es un número cuadrado, entonces\n--    √n = k ↔ n = k^2\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (n k : ℕ)\n  [is_square n]\n  : √n = k ↔ n = k^2 :=\nbegin\n  split,\n  { intro h,\n    rw ← h,\n    exact (square_sqrt n).symm },\n  { intro h,\n    apply pow_left_inj (nat.zero_le _) (nat.zero_le k) two_pos,\n    simp [h] },\nend\n\n-- Comentario: Se usan los lemas\n-- + pow_left_inj : 0 ≤ x → 0 ≤ y → 0 < n → x ^ n = y ^ n → x = y\n-- + zero_le : ∀ (n : ℕ), 0 ≤ n\n-- + two_pos : 0 < 2\n\n-- 2ª demostración\n-- ===============\n\n@[simp] lemma sqrt_eq_iff\n  (n k : ℕ)\n  [is_square n]\n  : √n = k ↔ n = k^2 :=\nbegin\n  split;\n  intro h,\n  { simp [← h] },\n  { exact pow_left_inj (nat.zero_le _) (nat.zero_le k) two_pos (by simp [h]) }\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que n^2 es un cuadrado y declararlo como\n-- instancia (para aplicarlo directamente en las inferencias de clases).\n-- ----------------------------------------------------------------------\n\ninstance square_square\n  (n : ℕ)\n  : is_square (n^2) :=\n⟨n, rfl⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    √(n ^ 2) 0 n\n-- ----------------------------------------------------------------------\n\nlemma sqrt_square\n  (n : ℕ)\n  : √(n ^ 2) = n :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que el producto de dos cuadrados es un cuadrado\n-- (y declarlo como instancia)\n-- ----------------------------------------------------------------------\n\nexample\n  (n m : ℕ)\n  [is_square n]\n  [is_square m]\n  : is_square (n*m) :=\nbegin\n  use (√n * √m),\n  rw nat.mul_pow,\n  rw square_sqrt,\n  rw square_sqrt,\nend\n\n-- Prueba\n-- ======\n\n/-\nn m : ℕ,\n_inst_1 : is_square n,\n_inst_2 : is_square m\n⊢ is_square (n * m)\n  >> use (√n * √m),\n⊢ (√n * √m) ^ 2 = n * m\n  >> rw nat.mul_pow,\n⊢ √n ^ 2 * √m ^ 2 = n * m\n  >> rw square_sqrt,\n⊢ n * √m ^ 2 = n * m\n  >> rw square_sqrt,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\ninstance square_mul\n  (n m : ℕ)\n  [is_square n]\n  [is_square m]\n  : is_square (n*m) :=\n⟨√n * √m, by simp [nat.mul_pow]⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si n y m son cuadrados, entonces\n--    √(n * m) = √n * √m\n-- ----------------------------------------------------------------------\n\nlemma sqrt_mul\n  (n m : ℕ)\n  [is_square n]\n  [is_square m]\n  : √(n * m) = √n * √m :=\nby simp [nat.mul_pow]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si n es un cuadrado, entonces\n--    √(n * m ^ 2) = √n * m\n-- ----------------------------------------------------------------------\n\nexample\n  (n m : ℕ)\n  [is_square n]\n  : √(n * m ^ 2) = √n * m :=\nby simp [sqrt_mul, sqrt_square]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si n es un cuadrado, entonces\n--    √n ≤ n\n-- ----------------------------------------------------------------------\n\nlemma sqrt_le\n  (n : ℕ)\n  [is_square n]\n  : √n ≤ n :=\nbegin\n  conv_rhs { rw [← square_sqrt n, nat.pow_two] },\n             apply nat.le_mul_self\nend\n\n-- Comentario: Se han usado los lemas\n-- + nat.le_mul_self : n ≤ n * n\n-- + nat.pow_two : n ^ 2 = n * n\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Cerrar el espacio de nombres is_square.\n-- ----------------------------------------------------------------------\n\nend is_square\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Iniciar la sección bijections.\n-- ----------------------------------------------------------------------\n\nsection bijections\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Abrir la teoría function.\n-- ----------------------------------------------------------------------\n\nopen function\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar α y β como variables de tipo.\n-- ----------------------------------------------------------------------\n\nvariables {α β : Type*}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Obtener la información de la estructura equiv.\n-- ----------------------------------------------------------------------\n\n#print equiv\n\n-- Comentario: Al colocar el cursor sobre print se obtiene\n--    structure equiv :\n--      Sort u_1 → Sort u_2 → Sort (max 1 (imax u_1 u_2) (imax u_2 u_1))\n--    fields:\n--    equiv.to_fun : Π {α : Sort u_1} {β : Sort u_2}, α ≃ β → α → β\n--    equiv.inv_fun : Π {α : Sort u_1} {β : Sort u_2}, α ≃ β → β → α\n--    equiv.left_inv : ∀ {α : Sort u_1} {β : Sort u_2} (c : α ≃ β),\n--                     left_inverse c.inv_fun c.to_fun\n--    equiv.right_inv : ∀ {α : Sort u_1} {β : Sort u_2} (c : α ≃ β),\n--                      right_inverse c.inv_fun c.to_fun\n--\n-- Su definición es\n--    structure equiv (α β : Type*) :=\n--    (to_fun    : α → β)\n--    (inv_fun   : β → α)\n--    (left_inv  : left_inverse inv_fun to_fun)\n--    (right_inv : right_inverse inv_fun to_fun)\n-- Es decir, da una equivalencia (biyección) entre dos tipos.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructura biyection que afirma la existencia\n-- de una aplicación inyectiva y suprayectiva entre los tipos.\n-- ----------------------------------------------------------------------\n\nstructure bijection (α β : Type*) :=\n  (to_fun : α → β)\n  (injective : injective to_fun)\n  (surjective : surjective to_fun)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar bijection como una instancia de has_coe_to_fun\n-- para tratar las biyecciones como funciones.\n-- ----------------------------------------------------------------------\n\ninstance : has_coe_to_fun (bijection α β) :=\n⟨_, λ f, f.to_fun⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Ampliar la táctica de extensionalidad a las biyecciones.\n-- ----------------------------------------------------------------------\n\n@[ext]\ndef bijection.ext\n  {f g : bijection α β}\n  (hfg : ∀ x, f x = g x)\n  : f = g :=\nby { cases f, cases g, congr, ext, exact hfg x }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar el lema coe_mk para reducir la aplicación de una\n-- biyección a un argumento.\n-- ----------------------------------------------------------------------\n\n@[simp]\nlemma coe_mk\n  {f : α → β}\n  {h1f : injective f}\n  {h2f : surjective f}\n  {x : α}\n  : { bijection . to_fun := f,\n      injective := h1f,\n      surjective := h2f } x = f x :=\n rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir equiv_of_bijection tal que, si f es una biyección\n-- de α en β entonces (equiv_of_bijection f) es una equivalencia entre α\n-- y β.\n-- ----------------------------------------------------------------------\n\ndef equiv_of_bijection (f : bijection α β) : α ≃ β :=\nbegin\n  exact equiv.of_bijective f ⟨f.injective, f.surjective⟩\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir bijection_of_equiv tal que si f es una\n-- equivalencia entre α y β, entonces (bijection_of_equiv f) es una\n-- biyección de α en β.\n-- ----------------------------------------------------------------------\n\ndef bijection_of_equiv (f : α ≃ β) : bijection α β :=\n{ to_fun := f,\n  injective := f.injective,\n  surjective := f.surjective }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que las biyecciones son equivalentes a las\n-- equivalencias.\n-- ----------------------------------------------------------------------\n\ndef bijection_equiv_equiv : bijection α β ≃ (α ≃ β) :=\n{ to_fun := equiv_of_bijection,\n  inv_fun := bijection_of_equiv,\n  left_inv :=\n    by { intro f, ext, simp [bijection_of_equiv, equiv_of_bijection] },\n  right_inv :=\n    by { intro f, ext, simp [bijection_of_equiv, equiv_of_bijection] } }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Cerrar la sección bijections\n-- ----------------------------------------------------------------------\n\nend bijections\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructura Group que tiene\n--    + universo: G,\n--    + operación interna: op (representada por *)\n--    + elemento neutro por la izquierda: id (representado por 1)\n--    + inverso por la izquierda inv (representado por ⁻¹)\n-- y verifica los axiomas\n--    + asociativa: ∀ (x y z : G), (x * y) * z = x * (y * z)\n--    + neutro: ∀ (x : G), 1 * x = x)\n--    + inverso: ∀ (x : G), x⁻¹ * x = 1\n-- ----------------------------------------------------------------------\n\nstructure Group :=\n  (G : Type*)\n  (op : G → G → G) (infix *    := op)\n  (id : G)         (notation 1 := id)\n  (inv : G → G)    (postfix ⁻¹ := inv)\n  (op_assoc' : ∀ (x y z : G), (x * y) * z = x * (y * z))\n  (id_op' : ∀ (x : G), 1 * x = x)\n  (op_left_inv' : ∀ (x : G), x⁻¹ * x = 1)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Extender la estructura Group a CommGroup de los grupos\n-- conmutativos.\n-- ----------------------------------------------------------------------\n\nstructure CommGroup extends Group :=\n  (infix * := op)\n  (op_comm : ∀ (x y : G), x * y = y * x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el grupo aditivo de los racionales.\n-- ----------------------------------------------------------------------\n\ndef rat_Group : Group :=\n{ G := ℚ,\n  op := (+),\n  id := 0,\n  inv := λ x, -x,\n  op_assoc' := add_assoc,\n  id_op' := zero_add,\n  op_left_inv' := neg_add_self }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Extender el grupo aditivo de los racionales a grupo\n-- conmutativo.\n-- ----------------------------------------------------------------------\n\ndef rat_CommGroup : CommGroup :=\n{ G := ℚ,\n  op_comm := add_comm,\n  ..rat_Group }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Iniciar el espacio de nombres Group\n-- ----------------------------------------------------------------------\n\nnamespace Group\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar G como una variable sobre grupos.\n-- ----------------------------------------------------------------------\n\nvariables {G : Group}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar los grupos como instancias de tipos.\n-- ----------------------------------------------------------------------\n\ninstance : has_coe_to_sort Group := ⟨_, Group.G⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar que G tiene\n--    + multiplicación: op (o *)\n--    + neutro: id (o 1)\n--    + inverso: inv (o ⁻¹)\n-- ----------------------------------------------------------------------\n\ninstance : has_mul G := ⟨G.op⟩\ninstance : has_one G := ⟨G.id⟩\ninstance : has_inv G := ⟨G.inv⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que G cumple los axiomas de grupo.\n-- ----------------------------------------------------------------------\n\nlemma op_assoc\n  (x y z : G)\n  : (x * y) * z = x * (y * z) :=\nG.op_assoc' x y z\n\nlemma id_op\n  (x : G)\n  : 1 * x = x :=\nG.id_op' x\n\nlemma op_left_inv\n  (x : G)\n  : x⁻¹ * x = 1 :=\n  G.op_left_inv' x\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si G es un grupo y x es un elemento de G,\n-- entonces\n--    x * x = x → x = 1\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {G : Group}\n  {x : G}\n  : x * x = x → x = 1 :=\nbegin\n  intro hx,\n  rw ← id_op x,\n  rw ← op_left_inv x,\n  rw op_assoc,\n  rw hx,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Group,\nx : ↥G\n⊢ x * x = x → x = 1\n  >> intro hx,\nhx : x * x = x\n⊢ x = 1\n  >> rw ← id_op x,\n⊢ 1 * x = 1\n  >> rw ← op_left_inv x,\n⊢ (x⁻¹ * x) * x = x⁻¹ * x\n  >> rw op_assoc,\n⊢ x⁻¹ * (x * x) = x⁻¹ * x\n  >> rw hx,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nlemma eq_id_of_op_eq_self\n  {G : Group}\n  {x : G}\n  : x * x = x → x = 1 :=\nbegin\n  intro hx,\n  rw [← id_op x, ← op_left_inv x, op_assoc, hx]\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que x⁻¹ es el inverso de x por la derecha.\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {G : Group}\n  (x : G)\n  : x * x⁻¹ = 1 :=\nbegin\n  apply eq_id_of_op_eq_self,\n  rw op_assoc x x⁻¹ (x * x⁻¹),\n  rw ← op_assoc x⁻¹ x x⁻¹,\n  rw op_left_inv,\n  rw id_op,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Group,\nx : ↥G\n⊢ x * x⁻¹ = 1\n  >> apply eq_id_of_op_eq_self,\n⊢ (x * x⁻¹) * (x * x⁻¹) = x * x⁻¹\n  >> rw op_assoc x x⁻¹ (x * x⁻¹),\n⊢ x * (x⁻¹ * (x * x⁻¹)) = x * x⁻¹\n  >> rw ← op_assoc x⁻¹ x x⁻¹,\n⊢ x * ((x⁻¹ * x) * x⁻¹) = x * x⁻¹\n  >> rw op_left_inv,\n⊢ x * (1 * x⁻¹) = x * x⁻¹\n  >> rw id_op,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nlemma op_right_inv\n  {G : Group}\n  (x : G)\n  : x * x⁻¹ = 1 :=\nbegin\n  apply eq_id_of_op_eq_self,\n  rw [op_assoc x x⁻¹ (x * x⁻¹), ← op_assoc x⁻¹ x x⁻¹, op_left_inv, id_op]\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que 1 es neutro por la derecha.\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {G : Group}\n  (x : G)\n  : x * 1 = x :=\nbegin\n  rw ← op_left_inv x,\n  rw ← op_assoc,\n  rw op_right_inv,\n  rw id_op,\nend\n\n-- Prueba\n-- ======\n\n/-\nG : Group,\nx : ↥G\n⊢ x * 1 = x\n  >> rw ← op_left_inv x,\n⊢ x * (x⁻¹ * x) = x\n  >> rw ← op_assoc,\n⊢ (x * x⁻¹) * x = x\n  >> rw op_right_inv,\n⊢ 1 * x = x\n  >> rw id_op,\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nlemma op_id\n  {G : Group}\n  (x : G)\n  : x * 1 = x :=\nby rw [← op_left_inv x, ← op_assoc, op_right_inv, id_op]\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el producto cartesiano de dos grupos.\n-- ----------------------------------------------------------------------\n\ndef prod_Group (G₁ G₂ : Group) : Group :=\n{ G := G₁ × G₂,\n  op := λ x y, (x.1 * y.1, x.2 * y.2),\n  op_assoc' := by { intros, ext; simp; rw [op_assoc] },\n  id := (1, 1),\n  id_op' := by { intros, ext; simp; rw [id_op] },\n  inv := λ x, (x.1⁻¹, x.2⁻¹),\n  op_left_inv' := by { intros, ext; simp; rw [op_left_inv] } }\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Cerrar el espacio de nombres Group\n-- ----------------------------------------------------------------------\n\nend Group\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la estructura pointed_type cuyos campos son\n-- + type que es un tipo y\n-- + point que es un elemento de type.\n-- ----------------------------------------------------------------------\n\nstructure pointed_type :=\n(type : Type*)\n(point : type)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Empezar el espacio de nombre pointed_type.\n-- ----------------------------------------------------------------------\n\nnamespace pointed_type\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Declarar A y B como variables sobre pointed_type\n-- ----------------------------------------------------------------------\n\nvariables {A B : pointed_type}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si A es un pointed_type entonces es un tipo.\n-- ----------------------------------------------------------------------\n\ninstance : has_coe_to_sort pointed_type := ⟨_, pointed_type.type⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir el producto de pointed_type.\n-- ----------------------------------------------------------------------\n\n@[simps point]\ndef prod (A B : pointed_type) : pointed_type :=\n{ type := A × B,\n  point := (A.point, B.point) }\n\n-- Comentario: El atributo @[simps point] indica que se puede desplegar\n-- la definición.\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Terminar el espacio de nombres de pointed_type.\n-- ----------------------------------------------------------------------\n\nend pointed_type\n\nstructure pointed_map (A B : pointed_type) :=\n(to_fun : A → B)\n(to_fun_point : to_fun A.point = B.point)\n\nnamespace pointed_map\n\ninfix ` →. `:25 := pointed_map\n\nvariables {A B C D : pointed_type}\nvariables {h : C →. D} {g : B →. C} {f f₁ f₂ : A →. B}\n\ninstance : has_coe_to_fun (A →. B) := ⟨λ _, A → B, pointed_map.to_fun⟩\n\n@[simp] lemma coe_mk {f : A → B} {hf : f A.point = B.point} {x : A} :\n  { pointed_map . to_fun := f, to_fun_point := hf } x = f x := rfl\n@[simp] lemma coe_point : f A.point = B.point := f.to_fun_point\n\n@[ext] protected lemma ext (hf₁₂ : ∀ x, f₁ x = f₂ x) : f₁ = f₂ :=\nbegin\n  cases f₁ with f₁ hf₁, cases f₂ with f₂ hf₂, congr, ext x, exact hf₁₂ x\nend\n\n/-! Below we show that pointed types form a category. -/\n\ndef comp (g : B →. C) (f : A →. B) : A →. C :=\n{ to_fun := g ∘ f,\n  to_fun_point := by simp }\n\ndef id : A →. A :=\n{ to_fun := id,\n  to_fun_point := by simp }\n\n/-! You can use projection notation for any declaration declared in the same namespace as the\n  structure. For example, `g.comp f` means `pointed_map.comp g f` -/\nlemma comp_assoc : h.comp (g.comp f) = (h.comp g).comp f :=\nby { ext x, refl }\n\nlemma id_comp : f.comp id = f :=\nby { ext x, refl }\n\nlemma comp_id : id.comp f = f :=\nby { ext x, refl }\n\n/-! Below we show that `A.prod B` (that is, `pointed_type.prod A B`) is a product in the category of\n  pointed types. -/\n\ndef fst : A.prod B →. A :=\n{ to_fun := prod.fst,\n  to_fun_point := rfl }\n\ndef snd : A.prod B →. B :=\n{ to_fun := prod.snd,\n  to_fun_point := rfl }\n\ndef pair (f : C →. A) (g : C →. B) : C →. A.prod B :=\n{ to_fun := λ c, (f c, g c),\n  to_fun_point := by simp }\n\nlemma fst_pair (f : C →. A) (g : C →. B) : fst.comp (f.pair g) = f :=\nby { ext, simp [pair, fst, comp] }\n\nlemma snd_pair (f : C →. A) (g : C →. B) : snd.comp (f.pair g) = g :=\nby { ext, simp [pair, snd, comp] }\n\nlemma pair_unique (f : C →. A) (g : C →. B) (u : C →. A.prod B) (h1u : fst.comp u = f)\n  (h2u : snd.comp u = g) : u = f.pair g :=\nbegin\n  ext,\n  { have : fst (u x) = f x, { rw [←h1u], simp [comp] }, simpa using this },\n  { have : snd (u x) = g x, { rw [←h2u], simp [comp] }, simpa using this }\nend\n\n\nend pointed_map\n\n/-! As an advanced exercise, you can show that the category of pointed type has coproducts.\n  For this we need quotients, the basic interface is given with the declarations\n  `quot r`: the quotient of the equivalence relation generated by relation `r` on `A`\n  `quot.mk r : A → quot r`,\n  `quot.sound`\n  `quot.lift` (see below)\n  -/\n\n#print quot\n#print quot.mk\n#print quot.sound\n#print quot.lift\n\nopen sum\n\n/-! We want to define the coproduct of pointed types `A` and `B` as the coproduct `A ⊕ B` of the\n  underlying type, identifying the two basepoints.\n\n  First define a relation that *only* relates `inl A.point ~ inr B.point`.\n-/\ndef coprod_rel (A B : pointed_type) : (A ⊕ B) → (A ⊕ B) → Prop :=\nλ x y, x = inl A.point ∧ y = inr B.point\n\nnamespace pointed_type\n\n-- @[simps point]\n-- omit\n@[simps point]\n-- omit\ndef coprod (A B : pointed_type) : pointed_type :=\n{ type := quot (coprod_rel A B),\n  point := quot.mk _ (inl A.point) }\nend pointed_type\n\nnamespace pointed_map\n\nvariables {A B C D : pointed_type}\n\ndef inl : A →. A.coprod B :=\n{ to_fun := quot.mk _ ∘ sum.inl,\n  to_fun_point := rfl }\n\ndef inr : B →. A.coprod B :=\n{ to_fun := quot.mk _ ∘ sum.inr,\n  to_fun_point := by { refine (quot.sound _).symm, exact ⟨rfl, rfl⟩ } }\n\ndef elim (f : A →. C) (g : B →. C) : A.coprod B →. C :=\n{ to_fun := quot.lift (sum.elim f g) (by { rintro _ _ ⟨rfl, rfl⟩, simp }),\n  to_fun_point := by simp }\n\nlemma elim_comp_inl (f : A →. C) (g : B →. C) : (f.elim g).comp inl = f :=\nby { ext, simp [elim, inl, comp] }\n\nlemma elim_comp_inr (f : A →. C) (g : B →. C) : (f.elim g).comp inr = g :=\nby { ext, simp [elim, inr, comp] }\n\nlemma elim_unique (f : A →. C) (g : B →. C) (u : A.coprod B →. C) (h1u : u.comp inl = f)\n  (h2u : u.comp inr = g) : u = f.elim g :=\nbegin\n  ext (x|y),\n  { have : u (inl x) = f x, { rw [←h1u], simp [comp] }, simpa [elim, inl] using this },\n  { have : u (inr y) = g y, { rw [←h2u], simp [comp] }, simpa [elim, inl] using this }\nend\n\nend pointed_map\n\n-- Comprobación de la corrección sintáctica\n#lint\n\n------------------------------------------------------------------------\n-- § Referencia                                                       --\n------------------------------------------------------------------------\n\n-- Basado en la teoría structures.lean de Floris van Doorn que se\n-- encuentra en https://bit.ly/39s7AwF y se comenta en los vídeos\n-- \"Structures and Classes\" que se encuentra en\n-- https://youtu.be/xYenPIeX6MY\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/Estructuras/Estructuras.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8902942217558213, "lm_q1q2_score": 0.7735114464961426}}
{"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-/\nimport group_theory.free_group\nimport group_theory.quotient_group\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 `α`, this file constructs the group\ngiven by generators `x : α` and relations `r ∈ rels`.\n\n## Main definitions\n\n* `presented_group rels`: the quotient group of the free group on a type `α` by a subset `rels` of\n  relations of the free group on `α`.\n* `of`: The canonical map from `α` to a presented group with generators `α`.\n* `to_group f`: the canonical group homomorphism `presented_group rels → G`, given a function\n  `f : α → G` from a type `α` to a group `G` which satisfies the relations `rels`.\n\n## Tags\n\ngenerators, relations, group presentations\n-/\n\nvariables {α : Type}\n\n/-- Given a set of relations, rels, over a type `α`, presented_group constructs the group with\ngenerators `x : α` and relations `rels` as a quotient of free_group `α`.-/\ndef presented_group (rels : set (free_group α)) : Type :=\nquotient_group.quotient $ subgroup.normal_closure rels\n\nnamespace presented_group\n\ninstance (rels : set (free_group α)) : group (presented_group (rels)) :=\nquotient_group.quotient.group _\n\n/-- `of` is the canonical map from `α` to a presented group with generators `x : α`. The term `x` is\nmapped to the equivalence class of the image of `x` in `free_group α`. -/\ndef of {rels : set (free_group α)} (x : α) : presented_group rels :=\nquotient_group.mk (free_group.of x)\n\nsection to_group\n\n/-\nPresented groups satisfy a universal property. If `G` is a group and `f : α → G` is a map such that\nthe images of `f` satisfy all the given relations, then `f` extends uniquely to a group homomorphism\nfrom `presented_group rels` to `G`.\n-/\n\nvariables {G : Type} [group G] {f : α → G} {rels : set (free_group α)}\n\nlocal notation `F` := free_group.lift f\n\nvariable (h : ∀ r ∈ rels, F r = 1)\n\nlemma closure_rels_subset_ker : subgroup.normal_closure rels ≤ monoid_hom.ker F :=\nsubgroup.normal_closure_le_normal (λ x w, (monoid_hom.mem_ker _).2 (h x w))\n\nlemma to_group_eq_one_of_mem_closure : ∀ x ∈ subgroup.normal_closure rels, F x = 1 :=\nλ x w, (monoid_hom.mem_ker _).1 $ closure_rels_subset_ker h w\n\n/-- The extension of a map `f : α → G` that satisfies the given relations to a group homomorphism\nfrom `presented_group rels → G`. -/\ndef to_group : presented_group rels →* G :=\nquotient_group.lift (subgroup.normal_closure rels) F (to_group_eq_one_of_mem_closure h)\n\n@[simp] lemma to_group.of {x : α} : to_group h (of x) = f x := free_group.lift.of\n\ntheorem to_group.unique (g : presented_group rels →* G)\n  (hg : ∀ x : α, g (of x) = f x) : ∀ {x}, g x = to_group h x :=\nλ x, quotient_group.induction_on x\n    (λ _, free_group.lift.unique (g.comp (quotient_group.mk' _)) hg)\n\nend to_group\n\ninstance (rels : set (free_group α)) : inhabited (presented_group rels) := ⟨1⟩\n\nend presented_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/presented_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.7733987945768341}}
{"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.modeq\n\n/-!\n# Parity of natural numbers\n\nThis file contains theorems about the `even` and `odd` predicates on the natural numbers.\n\n## Tags\n\neven, odd\n-/\n\nnamespace nat\n\nvariables {m n : ℕ}\n\n@[simp] theorem mod_two_ne_one : ¬ n % 2 = 1 ↔ n % 2 = 0 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\n@[simp] theorem mod_two_ne_zero : ¬ n % 2 = 0 ↔ n % 2 = 1 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\ntheorem even_iff : even n ↔ n % 2 = 0 :=\n⟨λ ⟨m, hm⟩, by simp [hm], λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by simp [h])⟩⟩\n\ntheorem odd_iff : odd n ↔ n % 2 = 1 :=\n⟨λ ⟨m, hm⟩, by norm_num [hm, add_mod],\n λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by rw [h, add_comm])⟩⟩\n\nlemma not_even_iff : ¬ even n ↔ n % 2 = 1 :=\nby rw [even_iff, mod_two_ne_zero]\n\nlemma not_odd_iff : ¬ odd n ↔ n % 2 = 0 :=\nby rw [odd_iff, mod_two_ne_one]\n\nlemma even_iff_not_odd : even n ↔ ¬ odd n :=\nby rw [not_odd_iff, even_iff]\n\n@[simp] lemma odd_iff_not_even : odd n ↔ ¬ even n :=\nby rw [not_even_iff, odd_iff]\n\nlemma is_compl_even_odd : is_compl {n : ℕ | even n} {n | odd n} :=\nby simp [← set.compl_set_of, is_compl_compl]\n\nlemma even_or_odd (n : ℕ) : even n ∨ odd n :=\nor.imp_right odd_iff_not_even.2 $ em $ even n\n\nlemma even_or_odd' (n : ℕ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 :=\nby simpa only [exists_or_distrib, ← odd, ← even] using even_or_odd n\n\nlemma even_xor_odd (n : ℕ) : xor (even n) (odd n) :=\nbegin\n  cases even_or_odd n with h,\n  { exact or.inl ⟨h, even_iff_not_odd.mp h⟩ },\n  { exact or.inr ⟨h, odd_iff_not_even.mp h⟩ },\nend\n\nlemma even_xor_odd' (n : ℕ) : ∃ k, xor (n = 2 * k) (n = 2 * k + 1) :=\nbegin\n  rcases even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩;\n  use k,\n  { simpa only [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\nlemma odd_gt_zero (h : odd n) : 0 < n :=\nby { obtain ⟨k, rfl⟩ := h, exact succ_pos' }\n\n@[simp] theorem two_dvd_ne_zero : ¬ 2 ∣ n ↔ n % 2 = 1 :=\nnot_even_iff\n\ninstance : decidable_pred (even : ℕ → Prop) :=\nλ n, decidable_of_decidable_of_iff (by apply_instance) even_iff.symm\n\ninstance decidable_pred_odd : decidable_pred (odd : ℕ → Prop) :=\nλ n, decidable_of_decidable_of_iff (by apply_instance) odd_iff_not_even.symm\n\nmk_simp_attribute parity_simps \"Simp attribute for lemmas about `even`\"\n\n@[simp] theorem even_zero : even 0 := ⟨0, dec_trivial⟩\n\n@[simp] theorem not_even_one : ¬ even 1 :=\nby rw even_iff; norm_num\n\n@[simp] theorem even_bit0 (n : ℕ) : even (bit0 n) :=\n⟨n, by rw [bit0, two_mul]⟩\n\n@[parity_simps] theorem even_add : even (m + n) ↔ (even m ↔ even n) :=\nby cases mod_two_eq_zero_or_one m with h₁ h₁;\n   cases mod_two_eq_zero_or_one n with h₂ h₂;\n   simp [even_iff, h₁, h₂, nat.add_mod];\n   norm_num\n\ntheorem even.add_even (hm : even m) (hn : even n) : even (m + n) :=\neven_add.2 $ iff_of_true hm hn\n\ntheorem even_add' : even (m + n) ↔ (odd m ↔ odd n) :=\nby rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\ntheorem odd.add_odd (hm : odd m) (hn : odd n) : even (m + n) :=\neven_add'.2 $ iff_of_true hm hn\n\n@[simp] theorem not_even_bit1 (n : ℕ) : ¬ even (bit1 n) :=\nby simp [bit1] with parity_simps\n\nlemma two_not_dvd_two_mul_add_one (n : ℕ) : ¬(2 ∣ 2 * n + 1) :=\nby convert not_even_bit1 n; exact two_mul n\n\nlemma two_not_dvd_two_mul_sub_one : Π {n} (w : 0 < n), ¬(2 ∣ 2 * n - 1)\n| (n + 1) _ := two_not_dvd_two_mul_add_one n\n\n@[parity_simps] theorem even_sub (h : n ≤ m) : even (m - n) ↔ (even m ↔ even n) :=\nbegin\n  conv { to_rhs, rw [←nat.sub_add_cancel h, even_add] },\n  by_cases h : even n; simp [h]\nend\n\ntheorem even.sub_even (hm : even m) (hn : even n) : even (m - n) :=\n(le_total n m).elim\n  (λ h, by simp only [even_sub h, *])\n  (λ h, by simp only [sub_eq_zero_of_le h, even_zero])\n\ntheorem even_sub' (h : n ≤ m) : even (m - n) ↔ (odd m ↔ odd n) :=\nby rw [even_sub h, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\ntheorem odd.sub_odd (hm : odd m) (hn : odd n) : even (m - n) :=\n(le_total n m).elim\n  (λ h, by simp only [even_sub' h, *])\n  (λ h, by simp only [sub_eq_zero_of_le h, even_zero])\n\n@[parity_simps] theorem even_succ : even (succ n) ↔ ¬ even n :=\nby rw [succ_eq_add_one, even_add]; simp [not_even_one]\n\n@[parity_simps] theorem even_mul : even (m * n) ↔ even m ∨ even n :=\nby cases mod_two_eq_zero_or_one m with h₁ h₁;\n   cases mod_two_eq_zero_or_one n with h₂ h₂;\n   simp [even_iff, h₁, h₂, nat.mul_mod];\n   norm_num\n\ntheorem odd_mul : odd (m * n) ↔ odd m ∧ odd n :=\nby simp [not_or_distrib] with parity_simps\n\ntheorem even.mul_left (hm : even m) (n) : even (m * n) :=\neven_mul.mpr $ or.inl hm\n\ntheorem even.mul_right (m) (hn : even n) : even (m * n) :=\neven_mul.mpr $ or.inr hn\n\ntheorem odd.mul (hm : odd m) (hn : odd n) : odd (m * n) :=\nodd_mul.mpr ⟨hm, hn⟩\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/-- If `m` and `n` are natural numbers, then the natural number `m^n` is even\nif and only if `m` is even and `n` is positive. -/\n@[parity_simps] theorem even_pow : even (m^n) ↔ even m ∧ n ≠ 0 :=\nby { induction n with n ih; simp [*, pow_succ', even_mul], tauto }\n\ntheorem even_div : even (m / n) ↔ m % (2 * n) / n = 0 :=\nby rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, nat.div_mod_eq_mod_mul_div, mul_comm]\n\n@[parity_simps] theorem odd_add : odd (m + n) ↔ (odd m ↔ even n) :=\nby rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even]\n\ntheorem odd.add_even (hm : odd m) (hn : even n) : odd (m + n) :=\nodd_add.2 $ iff_of_true hm hn\n\ntheorem odd_add' : odd (m + n) ↔ (odd n ↔ even m) :=\nby rw [add_comm, odd_add]\n\ntheorem even.add_odd (hm : even m) (hn : odd n) : odd (m + n) :=\nodd_add'.2 $ iff_of_true hn hm\n\nlemma ne_of_odd_add (h : odd (m + n)) : m ≠ n :=\nλ hnot, by simpa [hnot] with parity_simps using h\n\n@[parity_simps] theorem odd_sub (h : n ≤ m) : odd (m - n) ↔ (odd m ↔ even n) :=\nby rw [odd_iff_not_even, even_sub h, not_iff, odd_iff_not_even]\n\ntheorem odd.sub_even (h : n ≤ m) (hm : odd m) (hn : even n) : odd (m - n) :=\n(odd_sub h).mpr $ iff_of_true hm hn\n\ntheorem odd_sub' (h : n ≤ m) : odd (m - n) ↔ (odd n ↔ even m) :=\nby rw [odd_iff_not_even, even_sub h, not_iff, not_iff_comm, odd_iff_not_even]\n\ntheorem even.sub_odd (h : n ≤ m) (hm : even m) (hn : odd n) : odd (m - n) :=\n(odd_sub' h).mpr $ iff_of_true hn hm\n\nlemma even_mul_succ_self (n : ℕ) : even (n * (n + 1)) :=\nbegin\n  rw even_mul,\n  convert n.even_or_odd,\n  simp with parity_simps\nend\n\nvariables {R : Type*} [ring R]\n\ntheorem neg_one_pow_eq_one_iff_even (h1 : (-1 : R) ≠ 1) : (-1 : R) ^ n = 1 ↔ even n :=\n⟨λ h, n.mod_two_eq_zero_or_one.elim (dvd_iff_mod_eq_zero _ _).2\n  (λ hn, by rw [neg_one_pow_eq_pow_mod_two, hn, pow_one] at h; exact (h1 h).elim),\n  λ ⟨m, hm⟩, by rw [neg_one_pow_eq_pow_mod_two, hm]; simp⟩\n\n@[simp] theorem neg_one_sq : (-1 : R) ^ 2 = 1 := by simp\n\nalias nat.neg_one_sq ← nat.neg_one_pow_two\n\ntheorem neg_one_pow_of_even : even n → (-1 : R) ^ n = 1 :=\nby { rintro ⟨c, rfl⟩, simp [pow_mul] }\n\ntheorem neg_one_pow_of_odd : odd n → (-1 : R) ^ n = -1 :=\nby { rintro ⟨c, rfl⟩, simp [pow_add, pow_mul] }\n\n-- Here are examples of how `parity_simps` can be used with `nat`.\n\nexample (m n : ℕ) (h : even m) : ¬ even (n + 3) ↔ even (m^2 + m + n) :=\nby simp [*, (dec_trivial : ¬ 2 = 0)] with parity_simps\n\nexample : ¬ even 25394535 :=\nby simp\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703478, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7733987874316794}}
{"text": "import .src_07_existential_quantification\n\nvariables p q r : Prop \n\nnamespace mth1001\n\nsection or_introduction\n\n/-\nGiven `p`, we know `p ∨ q`. Given `q`, we know `p ∨ q`. This is called or introduction.\nThe symbol `∨` is written `\\or`.\n-/\n\n-- Left or introduction\nexample (h : p) : p ∨ q :=\nor.inl h\n\n-- Right or introduction\nexample (h : q) : p ∨ q :=\nor.inr h\n\n-- Tactic style\nexample (h : p) : p ∨ q :=\nbegin \n  left,\n  exact h,\nend\n\n-- Exercise 046:\nexample (h : q) : p ∨ q :=\nbegin\n  sorry  \nend\n\n/-\nRecall that any result with premises can be translated into a result without premises via\nimplication introduction.\n-/\nexample : p → p ∨ q :=\nassume h : p,\n  or.inl h\n\n-- Exercise 047:\n-- Give a tactic-style proof of the above.\nexample : p → p ∨ q :=\nbegin\n  sorry  \nend\n\n-- Exercise 048:\n-- The following example is a little more challenging.\nexample : p ∧ q → p ∨ q :=\nbegin \n  sorry  \nend\n\n\n-- Exercise 049:\n-- We return to looking at odd numbers. Refer back to the section on existential quantification.\nexample (n : ℤ) : (∃ m, n = 4 *m + 3) → (odd 10) ∨ (odd n) :=\nbegin \n  sorry  \nend\n\nend or_introduction\n\n/-\nSUMMARY:\n\n* Or introduction.\n* Term-style introduction using `or.inl` or `or.inr`.\n* Tactic-style introduction using `left` or `right`.\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_08_or_introduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7733947345772402}}
{"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-/\nimport group_theory.subsemigroup.operations\nimport data.fintype.basic\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.add_center`: the center of an additive magma\n* `add_subsemigroup.center`: the center of an additive semigroup\n\nWe provide `submonoid.center`, `add_submonoid.center`, `subgroup.center`, `add_subgroup.center`,\n`subsemiring.center`, and `subring.center` in other files.\n-/\n\nvariables {M : Type*}\n\nnamespace set\n\nvariables (M)\n\n/-- The center of a magma. -/\n@[to_additive add_center /-\" The center of an additive magma. \"-/]\ndef center [has_mul M] : set M := {z | ∀ m, m * z = z * m}\n\n@[to_additive mem_add_center]\nlemma mem_center_iff [has_mul M] {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl\n\ninstance decidable_mem_center [has_mul M] [decidable_eq M] [fintype M] :\n  decidable_pred (∈ center M) :=\nλ _, decidable_of_iff' _ (mem_center_iff M)\n\n@[simp, to_additive zero_mem_add_center]\nlemma one_mem_center [mul_one_class M] : (1 : M) ∈ set.center M := by simp [mem_center_iff]\n\n@[simp]\nlemma zero_mem_center [mul_zero_class M] : (0 : M) ∈ set.center M := by simp [mem_center_iff]\n\nvariables {M}\n\n@[simp, to_additive add_mem_add_center]\nlemma mul_mem_center [semigroup M] {a b : M}\n  (ha : a ∈ set.center M) (hb : b ∈ set.center M) : a * b ∈ set.center M :=\nλ g, by rw [mul_assoc, ←hb g, ← mul_assoc, ha g, mul_assoc]\n\n@[simp, to_additive neg_mem_add_center]\nlemma inv_mem_center [group M] {a : M} (ha : a ∈ set.center M) : a⁻¹ ∈ set.center M :=\nλ g, by rw [← inv_inj, mul_inv_rev, inv_inv, ← ha, mul_inv_rev, inv_inv]\n\n@[simp]\nlemma add_mem_center [distrib M] {a b : M}\n  (ha : a ∈ set.center M) (hb : b ∈ set.center M) : a + b ∈ set.center M :=\nλ c, by rw [add_mul, mul_add, ha c, hb c]\n\n@[simp]\nlemma neg_mem_center [ring M] {a : M} (ha : a ∈ set.center M) : -a ∈ set.center M :=\nλ c, by rw [←neg_mul_comm, ha (-c), neg_mul_comm]\n\n@[to_additive subset_add_center_add_units]\nlemma subset_center_units [monoid M] :\n  (coe : Mˣ → M) ⁻¹' center M ⊆ set.center Mˣ :=\nλ a ha b, units.ext $ ha _\n\nlemma center_units_subset [group_with_zero M] :\n  set.center Mˣ ⊆ (coe : Mˣ → M) ⁻¹' center M :=\nλ a ha b, begin\n  obtain rfl | hb := eq_or_ne b 0,\n  { rw [zero_mul, mul_zero], },\n  { exact units.ext_iff.mp (ha (units.mk0 _ hb)) }\nend\n\n/-- In a group with zero, the center of the units is the preimage of the center. -/\nlemma center_units_eq [group_with_zero M] :\n  set.center Mˣ = (coe : Mˣ → M) ⁻¹' center M :=\nsubset.antisymm center_units_subset subset_center_units\n\n@[simp]\nlemma inv_mem_center₀ [group_with_zero M] {a : M} (ha : a ∈ set.center M) : a⁻¹ ∈ set.center M :=\nbegin\n  obtain rfl | ha0 := eq_or_ne a 0,\n  { rw inv_zero, exact zero_mem_center M },\n  rcases is_unit.mk0 _ ha0 with ⟨a, rfl⟩,\n  rw ←units.coe_inv,\n  exact center_units_subset (inv_mem_center (subset_center_units ha)),\nend\n\n@[simp, to_additive sub_mem_add_center]\nlemma div_mem_center [group M] {a b : M} (ha : a ∈ set.center M) (hb : b ∈ set.center M) :\n  a / b ∈ set.center M :=\nbegin\n  rw [div_eq_mul_inv],\n  exact mul_mem_center ha (inv_mem_center hb),\nend\n\n@[simp]\nlemma div_mem_center₀ [group_with_zero M] {a b : M} (ha : a ∈ set.center M)\n  (hb : b ∈ set.center M) : a / b ∈ set.center M :=\nbegin\n  rw div_eq_mul_inv,\n  exact mul_mem_center ha (inv_mem_center₀ hb),\nend\n\nvariables (M)\n\n@[simp, to_additive add_center_eq_univ]\nlemma center_eq_univ [comm_semigroup M] : center M = set.univ :=\nsubset.antisymm (subset_univ _) $ λ x _ y, mul_comm y x\n\nend set\n\nnamespace subsemigroup\nsection\nvariables (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 \"The center of a semigroup `M` is the set of elements that commute with everything in\n`M`\"]\ndef center : subsemigroup M :=\n{ carrier := set.center M,\n  mul_mem' := λ a b, set.mul_mem_center }\n\n@[to_additive] lemma coe_center : ↑(center M) = set.center M := rfl\n\nvariables {M}\n\n@[to_additive] lemma mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl\n\n@[to_additive]\ninstance decidable_mem_center [decidable_eq M] [fintype M] : decidable_pred (∈ center M) :=\nλ _, decidable_of_iff' _ mem_center_iff\n\n/-- The center of a semigroup is commutative. -/\n@[to_additive \"The center of an additive semigroup is commutative.\"]\ninstance : comm_semigroup (center M) :=\n{ mul_comm := λ a b, subtype.ext $ b.prop _,\n  .. mul_mem_class.to_semigroup (center M) }\n\nend\n\nsection\nvariables (M) [comm_semigroup M]\n\n@[to_additive, simp] lemma center_eq_top : center M = ⊤ :=\nset_like.coe_injective (set.center_eq_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/center.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793113, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7733439132387764}}
{"text": "import M40001.M40001_C2\n\n/-\nExercise 4.\nLet us define the binary relation ~> as follow:\nLet X and Y be two sets, and f : X → V be some function between the sets, then ∀ x, y ∈ X, x ~> y if and only if f(x) = f(y).\n\nCan you prove that ~> is an equivalence relation?\nReplace the sorry for your proof.\n\nHere are some basic tactics that might help : http://wwwf.imperial.ac.uk/~buzzard/xena/html/source/tactics/guide.html\n-/\n\nuniverse u\nvariables {X V : Type u}\n\ndef bin_rel (X) := X → X → Prop\ndef equivalence_rel (r : bin_rel X) := reflexive r ∧ symmetric r ∧ transitive r\ndef cls (r : bin_rel X) (s : X) := {x : X | r s x}\ndef partition (A : set (set X)) : Prop := (∀ x : X, (∃ B ∈ A, x ∈ B ∧ ∀ C ∈ A, x ∈ C → B = C)) ∧ ∅ ∉ A\ndef rs (A : set (set(X))) (s t : X) := ∃ B ∈ A, s ∈ B ∧ t ∈ B\n-- The code above is simply used to esablish the definitions!\n\ntheorem partition_equiv_relation -- I have defined rs to be: def rs (A : set (set(X))) (s t : X) := ∃ B ∈ A, s ∈ B ∧ t ∈ B\n    (C : set (set X)) (h : partition C) : equivalence_rel (rs C) :=\nbegin\n    split,\n-- Proving reflexivity\n    {intro x,\n    cases h with ha hb,\n    replace ha: \n        ∃ (B : set X) (H : B ∈ C), x ∈ B ∧ ∀ (D : set X), D ∈ C → x ∈ D → B = D := ha x,\n    rcases ha with ⟨ha, ⟨hb, ⟨hc, hd⟩⟩⟩,\n    use ha, use hb,\n    split,\n    repeat {assumption}\n    },\n-- Proving symmtric\n    {split,\n        {rintros x y ⟨ha, ⟨hb, ⟨hc, hd⟩⟩⟩,\n        use ha, use hb,\n        split,\n        repeat {assumption}\n        },\n-- Proving transitivity\n        {rintros x y z ⟨ha, ⟨hb, ⟨hd, he⟩⟩⟩ ⟨hf, ⟨hg, ⟨hk, hl⟩⟩⟩,\n        use ha, use hb,\n        cases h with hm hn,\n        replace hm : \n            ∃ (B : set X) (H : B ∈ C), y ∈ B ∧ ∀ (D : set X), D ∈ C → y ∈ D → B = D := hm y,\n        rcases hm with ⟨ho, ⟨hp, ⟨hq, hr⟩⟩⟩,\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 ←this},\n        }\n    }\nend", "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/Exercises/Exercies4_sol.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646392, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7732183734459861}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=\n  ⟨fun h : p ∧ q => ⟨h.right, h.left⟩, \n   fun h : q ∧ p => ⟨h.right, h.left⟩⟩\n\nexample : p ∨ q ↔ q ∨ p :=\n  ⟨fun h : p ∨ q => h.elim (fun hp : p => Or.inr hp) (fun hq : q => Or.inl hq), \n   fun h : q ∨ p => h.elim (fun hq : q => Or.inr hq) (fun hp : p => Or.inl hp)⟩\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  ⟨fun h : (p ∧ q) ∧ r => ⟨h.left.left, h.left.right, h.right⟩, \n   fun h : p ∧ q ∧ r => ⟨⟨h.left, h.right.left⟩, h.right.right⟩⟩\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n  ⟨fun h : (p ∨ q) ∨ r => h.elim \n    (fun h₁ : p ∨ q => h₁.elim (fun hp : p => Or.inl hp) (fun hq : q => Or.inr (Or.inl hq))) \n     fun hr : r => Or.inr (Or.inr hr), \n   fun h : p ∨ q ∨ r => h.elim \n    (fun hp : p => Or.inl (Or.inl hp)) \n     fun h₁ : q ∨ r => h₁.elim (fun hq : q => Or.inl (Or.inr hq)) (fun hr : r => Or.inr hr)⟩\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n  ⟨fun h : p ∧ (q ∨ r) => h.right.elim \n    (fun hq : q => Or.inl ⟨h.left, hq⟩)\n     fun hr : r => Or.inr ⟨h.left, hr⟩, \n   fun h : p ∧ q ∨ p ∧ r => h.elim \n    (fun hpq : p ∧ q => ⟨hpq.left, Or.inl hpq.right⟩) \n     fun hpr : p ∧ r => ⟨hpr.left, Or.inr hpr.right⟩⟩\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\n  ⟨fun h : p ∨ q ∧ r => h.elim \n    (fun hp : p => ⟨Or.inl hp, Or.inl hp⟩) \n     fun hqr : q ∧ r => ⟨Or.inr hqr.left, Or.inr hqr.right⟩, \n   fun h : (p ∨ q) ∧ (p ∨ r) => h.left.elim \n    (fun hp : p => Or.inl hp) \n     fun hq : q => h.right.elim (fun hp : p => Or.inl hp) (fun hr : r => Or.inr ⟨hq, hr⟩)⟩ \n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := \n  ⟨fun h : p → q → r => (fun hpq : p ∧ q => h hpq.left hpq.right), \n   fun h : p ∧ q → r => (fun hp : p => (fun hq : q => h ⟨hp, hq⟩))⟩ \n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\n  ⟨fun h : p ∨ q → r => ⟨fun hp : p => h (Or.inl hp), (fun hq : q => h (Or.inr hq))⟩, \n   fun h : (p → r) ∧ (q → r) => \n    (fun hpq : p ∨ q => hpq.elim (fun hp : p => h.left hp) (fun hq : q => h.right hq))⟩\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \n  ⟨fun h : ¬(p ∨ q) => ⟨fun hp : p => h (Or.inl hp), (fun hq : q => h (Or.inr hq))⟩, \n   fun h : ¬p ∧ ¬q => (fun hpq : p ∨ q => hpq.elim h.left h.right)⟩\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) := \n  fun h : ¬p ∨ ¬q => fun hpq : p ∧ q => h.elim \n    (fun hnp : ¬p => hnp hpq.left) (fun hnq : ¬q => hnq hpq.right)\n\nexample : ¬(p ∧ ¬p) := \n  fun h : p ∧ ¬p => h.right h.left \n\nexample : p ∧ ¬q → ¬(p → q) := \n  fun h : p ∧ ¬q => fun h₁ : p → q => h.right (h₁ h.left)\n\nexample : ¬p → (p → q) := \n  fun hnp : ¬p => fun hp : p => absurd hp hnp\n\nexample : (¬p ∨ q) → (p → q) := \n  fun h : ¬p ∨ q => fun hp : p => h.elim (fun hnp : ¬p => absurd hp hnp) id\n\nexample : p ∨ False ↔ p := \n  ⟨fun h : p ∨ False => h.elim id False.elim, fun hp : p => Or.inl hp⟩ \n\nexample : p ∧ False ↔ False := \n  ⟨fun h : p ∧ False => h.right, False.elim⟩\n\nexample : (p → q) → (¬q → ¬p) := \n  fun h : p → q => fun hnq : ¬q => fun hp : p => hnq (h hp)\n\n\n-- classical\nopen Classical\n\nvariable (p q r s : Prop)\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) := \n  fun h : p → r ∨ s => (em p).elim \n    (fun hp : p => (h hp).elim \n      (fun hr : r => Or.inl fun hpp : p => hr) (fun hs : s => Or.inr fun hpp : p => hs)) \n    (fun hnp : ¬p => Or.inl fun hp : p => absurd hp hnp)\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q := \n  fun h : ¬(p ∧ q) => (em p).elim \n    ((em q).elim (fun hq : q => fun hp : p => absurd ⟨hp, hq⟩ h) \n      (fun hnq : ¬q => fun hp : p => Or.inr hnq)) \n    (fun hnp : ¬p => Or.inl hnp)\n\nexample : ¬(p → q) → p ∧ ¬q :=\n  fun h : ¬(p → q) => \n    ⟨(em p).elim id (fun hnp : ¬p => absurd (fun hp : p => absurd hp hnp) h), \n     (em q).elim (fun hq : q => absurd (fun hp : p => hq) h) id⟩\n\nexample : (p → q) → (¬p ∨ q) :=\n  fun h : p → q => (em p).elim (fun hp : p => Or.inr (h hp)) (fun hnp : ¬p => Or.inl hnp)\n\nexample : (¬q → ¬p) → (p → q) :=\n  fun h : ¬q → ¬p => fun hp : p => (em q).elim id (fun hnq : ¬q => absurd hp (h hnq))\n\nexample : p ∨ ¬p :=\n  (em p).elim (fun hp : p => Or.inl hp) (fun hnp : ¬p => Or.inr hnp)\n\nexample : (((p → q) → p) → p) :=\n  fun h : (p → q) → p => (em p).elim id (fun hnp : ¬p => \n    (em q).elim (fun hq : q => h fun hp : p => hq) \n    (fun hnq : ¬q => absurd (h fun hp : p => absurd hp hnp) hnp))\n\n\n-- iff not self (not classical)\nexample : ¬(p ↔ ¬p) :=\n  fun h : p ↔ ¬p => \n  have hnp : ¬p := fun hp : p => h.mp hp hp\n  hnp (h.mpr hnp) \n", "meta": {"author": "hikarimusic", "repo": "MyLean", "sha": "e42dc138addf5ad80dc3e5dbdbc329b90d9531b0", "save_path": "github-repos/lean/hikarimusic-MyLean", "path": "github-repos/lean/hikarimusic-MyLean/MyLean-e42dc138addf5ad80dc3e5dbdbc329b90d9531b0/Ch3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480237330998, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7732002148116855}}
{"text": "import Mathlib\n-- Credit to Alexander Bentkamp and Evgeniy Kuznetsov on the Lean zulip chat\n-- for help cleaning up (really rewriting) these lemmas.\n\ndef merge : List Nat → List Nat → List Nat\n| xs, [] => xs\n| [], ys => ys\n| (x :: xs), (y :: ys) => if x < y then x :: (merge xs (y :: ys))\n                                   else y :: (merge (x :: xs) ys)\ntermination_by merge xs ys => xs.length + ys.length\n\n-- When we (natural) divide the length of a list by 2, and the list has at\n-- least 2 elements, then we get a number strictly smaller than the length of\n-- the list.\nlemma length_div_2 : List.length (x :: y :: ys) / 2 < List.length (x :: y :: ys) := by\n\n  -- Let n be the length of the list, and k = 2.\n  -- Then n / k < n when 1 < k and 0 < n.\n  apply Nat.div_lt_self\n\n  -- So now we must prove 1 < k and 0 < n.\n  -- We do the latter first.\n  · simp [Nat.zero_lt_succ]\n\n  -- And then we prove 1 < k.\n  · simp\n\nlemma length_sub_div_2 : List.length (x :: y :: ys) - List.length (x :: y :: ys) / 2 < List.length (x :: y :: ys) := by\n\n  -- Let `b` be the length of the list, and `a` be half the length of the list.\n  -- If 0 < a and a ≤ b, then b - a < b.\n  apply Nat.sub_lt_self\n\n  -- Now we prove 0 < a.\n  -- If n + 1 ≤ m, then n < m.\n  apply Nat.lt_of_succ_le\n\n  -- Multiply both sides of an `≤` by k (in this case, 2).\n  rw [Nat.le_div_iff_mul_le]\n\n  -- Simplify Nat.succ 0 * 2 → 2.\n  simp only [Nat.succ_eq_one_add, Nat.add_zero, Nat.one_mul]\n\n  -- Prove that 2 ≤ length of a list with length at least 2.\n  simp only [Nat.succ_eq_one_add, ← add_assoc, Nat.le_add_right, List.length_cons]\n\n  -- Show 0 < 2. \n  apply Nat.zero_lt_succ\n\n  -- Now our goal is basically exactly the statement of `length_div_2`.\n  -- Since `length_div_2` is for `<`, convert it to `≤`.\n  exact le_of_lt length_div_2\n\ndef first_half {α : Type} (xs : List α) : List α := \n  List.take (xs.length / 2) xs\n\ndef second_half {α : Type} (xs : List α) : List α :=\n  List.drop (xs.length / 2) xs\n\nlemma length_first_half : List.length (first_half (x :: y :: ys)) < List.length (x :: y :: ys) := by\n  -- Use the definition of `first_half`, and the theorem that says that if we\n  -- take `i` values from the beginning of a list, we'll get either `i` values\n  -- or the entire list, whichever is smaller.\n  -- \n  -- Then use the theorem that says that min(a, b) is `a` if a < b.\n  -- Note that in our case, `b` is the length, and `a`is the length divided by\n  -- two.\n  rw [first_half, List.length_take, min_eq_left_of_lt]\n  repeat exact length_div_2\n  \nlemma length_second_half : List.length (second_half (x :: y :: ys)) < List.length (x :: y :: ys) := by\n  -- Use the definition of `second_half`, and then the theorem that says that\n  -- after we drop the first `i` values from a list, the result has length\n  -- `length - i` (natural subtraction).\n  rw [second_half, List.length_drop]\n  repeat exact length_sub_div_2\n\ndef mergesort : List Nat → List Nat\n| [] => []\n| [a] => [a]\n| (x :: (y :: ys)) => \n  have : List.length (first_half (x :: (y :: ys))) < List.length (x :: (y :: ys)) := length_first_half\n  have : List.length (second_half (x :: (y :: ys))) < List.length (x :: (y :: ys)) := length_second_half\n  merge (mergesort <| first_half (x :: (y :: ys))) (mergesort <| second_half (x :: (y :: ys)))\ntermination_by mergesort xs => xs.length\n\ndef l := [1, 2, 3]\n#eval (l).length\n#eval l.length\n#eval l.take 1\n\n#eval mergesort [1, 3, 2]\n#eval mergesort [3, 2, 1]\n#eval mergesort [5, 4, 3, 1, 2]\n", "meta": {"author": "langfield", "repo": "mergesort", "sha": "3db14fc5a60175c1663756581cfed4e2ba0916b7", "save_path": "github-repos/lean/langfield-mergesort", "path": "github-repos/lean/langfield-mergesort/mergesort-3db14fc5a60175c1663756581cfed4e2ba0916b7/Mergesort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.923039160069787, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7731560292836128}}
{"text": "import Experiments.FreeAbelianMeta\n\n/-\nThis file contains examples of the abelian group simplification tactic in action.\n\nThis is still work in progress, so the verbose proofs below will eventually be bundled up together into a tactic and completely automated.\n\nThe purpose of this tactic is to simplify expressions in Abelian groups and prove basic equations.\nThe key idea here is that to prove an equation such as `{A : Type} → [AddCommGroup A] → ∀ x y : A, x + y - x - y + x = x` involving $n$ variables for all Abelian groups,\nit suffices to verify it by direct computation in `ℤⁿ` for the $n$ basis elements `{(0, 0, …, i, 0, 0)}`. The reason is that `ℤⁿ` is a free group,\nso given any elements `x₁, x₂, …, xₙ` in a specific group `A`, there is a unique homomorphism taking the generators of `ℤⁿ` to the chosen elements.\n\nIn the example above, it is easy to verify that `(1, 0) + (0, 1) - (1, 0) - (0, 1) + (1, 0) = (1, 0)` by a computation. Given any elements `a` and `b` in an Abelian group `A`,\napplying the unique homomorphism `ϕ : ℤ² → A` taking `(1, 0)` to `a` and `(0, 1)` to `b` to this equation yields a proof that `a + b - a - b + a = a`. This allows one to prove equations in\nAbelian groups without any explicit commutativity and associativity rewrites, and consequently the resulting proofs are quite short.\n-/\n\n\n/- This example shows that the expression on the left reduces to the one on the right -/\nexample {x y z : ℤ} : x + x + y - x - y + z - x = z := by\n    have p := freeGroupEq# (x + x + y - x - y + z - x) -- a proof that the term is the image of the free group element `(0, 0, 1)`\n    rw [p, map_free_elem] -- remove the induced homomorphism from the picture\n    -- expand out and simplify (routine steps that can be automated)\n    simp [List.sum]\n    rw [SubNegMonoid.gsmul_zero', zero_add, SubNegMonoid.gsmul_zero', zero_add, SubNegMonoid.gsmul_one]\n\n\n/- An example in a general Abelian group -/\nexample {A : Type _} [AddCommGroup A] {a b : A} : (a + b) - (b - a) - a = a := by\n  have p := freeGroupEq# ((a + b) - (b - a) - a) -- a proof that the term is the image of the free group element `(1, 0)`\n  rw [p, map_free_elem] -- remove the induced homomorphism from the picture\n  -- routine simplification\n  simp [List.sum, SubNegMonoid.gsmul_one]\n\n\n/- An example where both sides of the equality are unreduced (not completely implemented) -/\nexample {a b : ℤ} : a + b - a - b = b - b + a - a := by\n  have pₗ := freeGroupEq# (a + b - a - b) -- a simpler expression for the left side\n  have pᵣ := freeGroupEq# (b - b + a - a) -- a simpler expression for the right side\n  rw [pₗ, pᵣ, map_free_elem, map_free_elem] -- remove the induced homomorphisms from the picture\n  -- routine simplification\n  simp [List.sum]\n  rw [SubNegMonoid.gsmul_zero', SubNegMonoid.gsmul_zero']\n\n\n/- A more complicated example involving five variables -/\nexample {A : Type _} [AddCommGroup A] {a b c d e : A} : a + b - c - d + e - a + b + c - a - e + a - b + d - b = 0 := by\n  have p := freeGroupEq# (a + b - c - d + e - a + b + c - a - e + a - b + d - b) -- a proof that the given expression is the image of `0 : ℤ⁵`\n  rw [p, map_free_elem] -- removing the induced homomorphism from the picture\n  -- routine simplification\n  simp [List.sum]\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/Examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868805, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7731560273153969}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport sesion_4.soluciones.limites\n\nimport topology.instances.real\n\n/-\n# Límites de secuencias en Lean\n\nAhora que sabemos cómo utilizar filtros en Lean, podemos reescribir\nlas soluciones de los ejercicios de límites de la sesión 4.\n\n-/\n\nopen filter\n\nopen_locale topology -- para acceder a la notación 𝓝 \n\nnamespace limites\n\n-- Nuestra definición `tends_to` es equivalente a `filter.tendsto`\nlemma tends_to_iff_tendsto (a : ℕ → ℝ) (l : ℝ) :\n  tends_to a l ↔ tendsto a at_top (𝓝 l) :=\nbegin\n  rw metric.tendsto_at_top,\n  rw tends_to,\n  congr',\nend\n\n/-- El límite de la secuencia constante con valor `c` es `c`. -/\ntheorem tends_to_const (c : ℝ) : tends_to (λ n, c) c :=\nbegin\n  rw tends_to_iff_tendsto,\n  exact tendsto_const_nhds,\nend\n\n/-- Si `a(n)` tiende a `L` entonces `a(n) + c` tiende a `t + c` -/\ntheorem tends_to_add_const {a : ℕ → ℝ} {L : ℝ} (c : ℝ)\n  (h : tends_to a L) :\n  tends_to (λ n, a n + c) (L + c) :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto.add_const c h,\nend\n\n/-- Si `a(n)` tiende a `L`, entonces `-a(n)` tiende a `-L`.\nSi simplificar la expresión dentro del valor absoluto te está\ndando problemas, ve a la hoja `reales.lean`.\n-/\ntheorem tends_to_neg {a : ℕ → ℝ} {L : ℝ} (ha : tends_to a L) :\n  tends_to (λ n, - a n) (-L) :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto.neg ha,\nend\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) + b(n)` \n  tiende a `La + Lb`. -/\ntheorem tends_to_add {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n + b n) (La + Lb) :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto.add ha hb,\nend\n\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) - b(n)`\ntiende a `La - Lb`. -/\ntheorem tends_to_sub {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n - b n) (La - Lb) :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto.sub ha hb,\nend\n\n/-- Si `a(n)` tiende a `L`, entonces `c*a(n)` tiende a `c*L`.\nPista: tratad el caso `c = 0` por separado, utilizando `by_cases hc : c = 0`.\n-/\nlemma tends_to_mul_const_left {a : ℕ → ℝ} {L c : ℝ} (h : tends_to a L) :\n  tends_to (λ n, c * (a n)) (c * L) := \nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto.const_mul c h,\nend\n\n/- Lema del sandwich. -/\ntheorem sandwich (a b c : ℕ → ℝ) (L : ℝ) (ha : tends_to a L) (hc : tends_to c L) \n  (hab : ∀ n, a n ≤ b n) (hbc : ∀ n, b n ≤ c n) : \n  tends_to b L :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto_of_tendsto_of_tendsto_of_le_of_le ha hc hab hbc, \n  -- Buscando `sandwich` o `squeeze` en la documentación de mathlib, aparece este lema.\nend\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) * b(n)` \n  tiende a `La * Lb`. -/\ntheorem tends_to_mul {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n * b n) (La * Lb) :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  exact tendsto.mul ha hb,\nend\n\nend limites", "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/limites.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7731560200272216}}
{"text": "import game.limits.L01defs\nimport game.sup_inf.GLBprop_if_LUBprop\n\n\nnamespace xena -- hide\n\nnotation `|` x `|` := abs x -- hide\n\n/-\nAnother basic result for working with sequences.\n-/\n\n/- Lemma\nIf $\\lim_{n \\to \\infty} a_n = \\alpha$ and $\\lim_{n \\to \\infty} b_n = \\beta$, then\n $\\lim_{n \\to \\infty} (a_n + b_n) = \\alpha + \\beta$\n-/\nlemma lim_add (a : ℕ → ℝ) (b : ℕ → ℝ) (α β : ℝ) \n    (ha : is_limit a α) (hb : is_limit b β) : \n    is_limit ( λ n, (a n) + (b n) ) (α + β) :=\nbegin\n   intros ε hε,\n   set e := ε / 2 with hedef,\n   have he : 0 < e, linarith,\n   have Ha := ha e he,\n   have Hb := hb e he,\n   cases Ha with na hna,\n   cases Hb with nb hnb,\n   set m := max na nb with hm,\n   have hm1 : m ≥ na, norm_num, left, linarith,\n   have hm2 : m ≥ nb, norm_num, right, linarith,\n   use m,\n   intros n hn,\n   have hn1 : n ≥ na, linarith,\n   have hn2 : n ≥ nb, linarith,\n   have H1 := hna n hn1,\n   have H2 := hnb n hn2,\n   have H := abs_add (a n - α) (b n - β),\n   simp, \n   have G : a n - α + (b n - β) = a n + b n - (α + β), linarith,\n   rw G at H,\n   have F : |a n - α| + |b n - β| < 2 * e, linarith,\n   have E : |a n + b n - (α + β)| < 2 * e, linarith,\n   have D : 2 * e = ε, linarith,\n   rw D at E, exact E, 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_lim_add.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7731004109162168}}
{"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.polynomial.degree.definitions\n\n/-!\n# Cancel the leading terms of two polynomials\n\n## Definition\n\n* `cancel_leads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting.\n\n## Main Results\nThe degree of `cancel_leads` is less than that of the larger of the two polynomials being cancelled.\nThus it is useful for induction or minimal-degree arguments.\n-/\nnamespace polynomial\nnoncomputable theory\nopen_locale polynomial\n\nvariables {R : Type*}\n\nsection comm_ring\nvariables [comm_ring R] (p q : R[X])\n\n/-- `cancel_leads p q` is formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting. -/\ndef cancel_leads : R[X] :=\nC p.leading_coeff * X ^ (p.nat_degree - q.nat_degree) * q -\nC q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p\n\nvariables {p q}\n\n@[simp] lemma neg_cancel_leads : - p.cancel_leads q = q.cancel_leads p := neg_sub _ _\n\nlemma dvd_cancel_leads_of_dvd_of_dvd {r : R[X]} (pq : p ∣ q) (pr : p ∣ r) :\n  p ∣ q.cancel_leads r :=\ndvd_sub (pr.trans (dvd.intro_left _ rfl)) (pq.trans (dvd.intro_left _ rfl))\n\nend comm_ring\n\nlemma nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree [comm_ring R] [is_domain R]\n  {p q : R[X]} (h : p.nat_degree ≤ q.nat_degree) (hq : 0 < q.nat_degree) :\n  (p.cancel_leads q).nat_degree < q.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { convert hq,\n    simp [hp, cancel_leads], },\n  rw [cancel_leads, sub_eq_add_neg, tsub_eq_zero_iff_le.mpr h, pow_zero, mul_one],\n  by_cases h0 :\n      C p.leading_coeff * q + -(C q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p) = 0,\n  { convert hq,\n    simp only [h0, nat_degree_zero], },\n  have hq0 : ¬ q = 0,\n  { contrapose! hq,\n    simp [hq] },\n  apply lt_of_le_of_ne,\n  { rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree h0, ← degree_eq_nat_degree hq0],\n    apply le_trans (degree_add_le _ _),\n    rw ← leading_coeff_eq_zero at hp hq0,\n    simp only [max_le_iff, degree_C hp, degree_C hq0, le_refl q.degree, true_and, nat.cast_with_bot,\n      nsmul_one, degree_neg, degree_mul, zero_add, degree_X, degree_pow],\n    rw leading_coeff_eq_zero at hp hq0,\n    rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq0, ← with_bot.coe_add, with_bot.coe_le_coe,\n      tsub_add_cancel_of_le h], },\n  { contrapose! h0,\n    rw [← leading_coeff_eq_zero, leading_coeff, h0, mul_assoc, mul_comm _ p,\n      ← tsub_add_cancel_of_le h, add_comm _ p.nat_degree],\n    simp only [coeff_mul_X_pow, coeff_neg, coeff_C_mul, add_tsub_cancel_left, coeff_add],\n    rw [add_comm p.nat_degree, tsub_add_cancel_of_le h, ← leading_coeff, ← leading_coeff,\n      mul_comm _ q.leading_coeff, ← sub_eq_add_neg, ← mul_sub, sub_self, mul_zero] }\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/cancel_leads.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7730853828144697}}
{"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.gcd_monoid.finset\nimport data.polynomial.field_division\nimport data.polynomial.erase_lead\nimport data.polynomial.cancel_leads\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 : 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\nnamespace polynomial\nopen_locale polynomial\n\nsection primitive\n\nvariables {R : Type*} [comm_semiring R]\n\n/-- A polynomial is primitive when the only constant polynomials dividing it are units -/\ndef is_primitive (p : R[X]) : Prop :=\n∀ (r : R), C r ∣ p → is_unit r\n\nlemma is_primitive_iff_is_unit_of_C_dvd {p : R[X]} :\n  p.is_primitive ↔ ∀ (r : R), C r ∣ p → is_unit r :=\niff.rfl\n\n@[simp]\nlemma is_primitive_one : is_primitive (1 : R[X]) :=\nλ r h, is_unit_C.mp (is_unit_of_dvd_one (C r) h)\n\nlemma monic.is_primitive {p : R[X]} (hp : p.monic) : p.is_primitive :=\nbegin\n  rintros r ⟨q, h⟩,\n  exact is_unit_of_mul_eq_one r (q.coeff p.nat_degree) (by rwa [←coeff_C_mul, ←h]),\nend\n\nlemma is_primitive.ne_zero [nontrivial R] {p : R[X]} (hp : p.is_primitive) : p ≠ 0 :=\nbegin\n  rintro rfl,\n  exact (hp 0 (dvd_zero (C 0))).ne_zero rfl,\nend\n\nend primitive\n\nvariables {R : Type*} [comm_ring R] [is_domain R]\n\nsection normalized_gcd_monoid\nvariable [normalized_gcd_monoid R]\n\n/-- `p.content` is the `gcd` of the coefficients of `p`. -/\ndef content (p : R[X]) : R := (p.support).gcd p.coeff\n\nlemma content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n :=\nbegin\n  by_cases h : n ∈ p.support,\n  { apply finset.gcd_dvd h },\n  rw [mem_support_iff, not_not] at h,\n  rw h,\n  apply dvd_zero,\nend\n\n@[simp] lemma content_C {r : R} : (C r).content = normalize r :=\nbegin\n  rw content,\n  by_cases h0 : r = 0,\n  { simp [h0] },\n  have h : (C r).support = {0} := support_monomial _ _ h0,\n  simp [h],\nend\n\n@[simp] lemma content_zero : content (0 : R[X]) = 0 :=\nby rw [← C_0, content_C, normalize_zero]\n\n@[simp] lemma content_one : content (1 : R[X]) = 1 :=\nby rw [← C_1, content_C, normalize_one]\n\nlemma content_X_mul {p : R[X]} : content (X * p) = content p :=\nbegin\n  rw [content, content, finset.gcd_def, finset.gcd_def],\n  refine congr rfl _,\n  have h : (X * p).support = p.support.map ⟨nat.succ, nat.succ_injective⟩,\n  { ext a,\n    simp only [exists_prop, finset.mem_map, function.embedding.coe_fn_mk, ne.def,\n      mem_support_iff],\n    cases a,\n    { simp [coeff_X_mul_zero, nat.succ_ne_zero] },\n    rw [mul_comm, coeff_mul_X],\n    split,\n    { intro h,\n      use a,\n      simp [h] },\n    { rintros ⟨b, ⟨h1, h2⟩⟩,\n      rw ← nat.succ_injective h2,\n      apply h1 } },\n  rw h,\n  simp only [finset.map_val, function.comp_app, function.embedding.coe_fn_mk, multiset.map_map],\n  refine congr (congr rfl _) rfl,\n  ext a,\n  rw mul_comm,\n  simp [coeff_mul_X],\nend\n\n@[simp] lemma content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 :=\nbegin\n  induction k with k hi,\n  { simp },\n  rw [pow_succ, content_X_mul, hi]\nend\n\n@[simp] lemma content_X : content (X : R[X]) = 1 :=\nby { rw [← mul_one X, content_X_mul, content_one] }\n\nlemma content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content :=\nbegin\n  by_cases h0 : r = 0, { simp [h0] },\n  rw content, rw content, rw ← finset.gcd_mul_left,\n  refine congr (congr rfl _) _; ext; simp [h0, mem_support_iff]\nend\n\n@[simp] lemma content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r :=\nby { rw [monomial_eq_C_mul_X, content_C_mul, content_X_pow, mul_one] }\n\nlemma content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 :=\nbegin\n  rw [content, finset.gcd_eq_zero_iff],\n  split; intro h,\n  { ext n,\n    by_cases h0 : n ∈ p.support,\n    { rw [h n h0, coeff_zero], },\n    { rw mem_support_iff at h0,\n      push_neg at h0,\n      simp [h0] } },\n  { intros x h0,\n    simp [h] }\nend\n\n@[simp] lemma normalize_content {p : R[X]} : normalize p.content = p.content :=\nfinset.normalize_gcd\n\nlemma content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.nat_degree < n) :\n  p.content = (finset.range n).gcd p.coeff :=\nbegin\n  apply dvd_antisymm_of_normalize_eq normalize_content finset.normalize_gcd,\n  { rw finset.dvd_gcd_iff,\n    intros i hi,\n    apply content_dvd_coeff _ },\n  { 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), }\nend\n\n\n\nlemma content_eq_gcd_leading_coeff_content_erase_lead (p : R[X]) :\n  p.content = gcd_monoid.gcd p.leading_coeff (erase_lead p).content :=\nbegin\n  by_cases h : p = 0,\n  { simp [h] },\n  rw [← leading_coeff_eq_zero, leading_coeff, ← ne.def, ← mem_support_iff] at h,\n  rw [content, ← finset.insert_erase h, finset.gcd_insert, leading_coeff, content,\n    erase_lead_support],\n  refine congr rfl (finset.gcd_congr rfl (λ i hi, _)),\n  rw finset.mem_erase at hi,\n  rw [erase_lead_coeff, if_neg hi.1],\nend\n\nlemma dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p :=\nbegin\n  rw C_dvd_iff_dvd_coeff,\n  split,\n  { intros h i,\n    apply h.trans (content_dvd_coeff _) },\n  { intro h,\n    rw [content, finset.dvd_gcd_iff],\n    intros i hi,\n    apply h i }\nend\n\nlemma C_content_dvd (p : R[X]) : C p.content ∣ p :=\ndvd_content_iff_C_dvd.1 dvd_rfl\n\nlemma is_primitive_iff_content_eq_one {p : R[X]} : p.is_primitive ↔ p.content = 1 :=\nbegin\n  rw [←normalize_content, normalize_eq_one, is_primitive],\n  simp_rw [←dvd_content_iff_C_dvd],\n  exact ⟨λ h, h p.content (dvd_refl p.content), λ h r hdvd, is_unit_of_dvd_unit hdvd h⟩,\nend\n\nlemma is_primitive.content_eq_one {p : R[X]} (hp : p.is_primitive) : p.content = 1 :=\nis_primitive_iff_content_eq_one.mp hp\n\nopen_locale classical\nnoncomputable theory\n\nsection prim_part\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 (p : R[X]) : R[X] :=\nif p = 0 then 1 else classical.some (C_content_dvd p)\n\nlemma eq_C_content_mul_prim_part (p : R[X]) : p = C p.content * p.prim_part :=\nbegin\n  by_cases h : p = 0, { simp [h] },\n  rw [prim_part, if_neg h, ← classical.some_spec (C_content_dvd p)],\nend\n\n@[simp]\nlemma prim_part_zero : prim_part (0 : R[X]) = 1 := if_pos rfl\n\nlemma is_primitive_prim_part (p : R[X]) : p.prim_part.is_primitive :=\nbegin\n  by_cases h : p = 0, { simp [h] },\n  rw ← content_eq_zero_iff at h,\n  rw is_primitive_iff_content_eq_one,\n  apply mul_left_cancel₀ h,\n  conv_rhs { rw [p.eq_C_content_mul_prim_part, mul_one, content_C_mul, normalize_content] }\nend\n\nlemma content_prim_part (p : R[X]) : p.prim_part.content = 1 :=\np.is_primitive_prim_part.content_eq_one\n\nlemma prim_part_ne_zero (p : R[X]) : p.prim_part ≠ 0 := p.is_primitive_prim_part.ne_zero\n\nlemma nat_degree_prim_part (p : R[X]) : p.prim_part.nat_degree = p.nat_degree :=\nbegin\n  by_cases h : C p.content = 0,\n  { rw [C_eq_zero, content_eq_zero_iff] at h, simp [h] },\n  conv_rhs { rw [p.eq_C_content_mul_prim_part,\n    nat_degree_mul h p.prim_part_ne_zero, nat_degree_C, zero_add] },\nend\n\n@[simp]\nlemma is_primitive.prim_part_eq {p : R[X]} (hp : p.is_primitive) : p.prim_part = p :=\nby rw [← one_mul p.prim_part, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_prim_part]\n\nlemma is_unit_prim_part_C (r : R) : is_unit (C r).prim_part :=\nbegin\n  by_cases h0 : r = 0,\n  { simp [h0] },\n  unfold is_unit,\n  refine ⟨⟨C ↑(norm_unit r)⁻¹, C ↑(norm_unit r),\n    by rw [← ring_hom.map_mul, units.inv_mul, C_1],\n    by rw [← ring_hom.map_mul, units.mul_inv, C_1]⟩, _⟩,\n  rw [← normalize_eq_zero, ← C_eq_zero] at h0,\n  apply mul_left_cancel₀ h0,\n  conv_rhs { rw [← content_C, ← (C r).eq_C_content_mul_prim_part], },\n  simp only [units.coe_mk, normalize_apply, ring_hom.map_mul],\n  rw [mul_assoc, ← ring_hom.map_mul, units.mul_inv, C_1, mul_one],\nend\n\nlemma prim_part_dvd (p : R[X]) : p.prim_part ∣ p :=\ndvd.intro_left (C p.content) p.eq_C_content_mul_prim_part.symm\n\nend prim_part\n\nlemma gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) :\n  gcd_monoid.gcd a p.content = gcd_monoid.gcd a q.content :=\nbegin\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  intros x hx,\n  cases h with w hw,\n  use w.coeff x,\n  rw [← coeff_sub, hw, coeff_C_mul]\nend\n\nlemma content_mul_aux {p q : R[X]} :\n  gcd_monoid.gcd (p * q).erase_lead.content p.leading_coeff =\n  gcd_monoid.gcd (p.erase_lead * q).content p.leading_coeff :=\nbegin\n  rw [gcd_comm (content _) _, gcd_comm (content _) _],\n  apply gcd_content_eq_of_dvd_sub,\n  rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,\n    sub_sub_cancel, leading_coeff_mul, ring_hom.map_mul, mul_assoc, mul_assoc],\n  apply dvd_sub (dvd.intro _ rfl) (dvd.intro _ rfl),\nend\n\n@[simp]\ntheorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content :=\nbegin\n  classical,\n  suffices h : ∀ (n : ℕ) (p q : R[X]), ((p * q).degree < n) →\n    (p * q).content = p.content * q.content,\n  { apply h,\n    apply (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (nat.lt_succ_self _))) },\n  intro n,\n  induction n with n ih,\n  { intros p q hpq,\n    rw [with_bot.coe_zero, nat.with_bot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq,\n    rcases hpq with rfl | rfl; simp },\n  intros p q hpq,\n  by_cases p0 : p = 0, { simp [p0] },\n  by_cases q0 : q = 0, { simp [q0] },\n  rw [degree_eq_nat_degree (mul_ne_zero p0 q0), with_bot.coe_lt_coe, nat.lt_succ_iff_lt_or_eq,\n    ← with_bot.coe_lt_coe, ← degree_eq_nat_degree (mul_ne_zero p0 q0), nat_degree_mul p0 q0] at hpq,\n  rcases hpq with hlt | heq, { apply ih _ _ hlt },\n  rw [← p.nat_degree_prim_part, ← q.nat_degree_prim_part, ← with_bot.coe_eq_coe, with_bot.coe_add,\n    ← degree_eq_nat_degree p.prim_part_ne_zero, ← 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  { 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 [← normalize_content, normalize_eq_one, is_unit_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,\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,\n      ← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part],\n  { rw [← heq, degree_mul, with_bot.add_lt_add_iff_right],\n    { apply degree_erase_lt p.prim_part_ne_zero },\n    { rw [ne.def, degree_eq_bot],\n      apply q.prim_part_ne_zero } },\n  { rw [mul_comm, ← heq, degree_mul, with_bot.add_lt_add_iff_left],\n    { apply degree_erase_lt q.prim_part_ne_zero },\n    { rw [ne.def, degree_eq_bot],\n      apply p.prim_part_ne_zero } }\nend\n\ntheorem is_primitive.mul {p q : R[X]} (hp : p.is_primitive) (hq : q.is_primitive) :\n  (p * q).is_primitive :=\nby rw [is_primitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]\n\n@[simp]\ntheorem prim_part_mul {p q : R[X]} (h0 : p * q ≠ 0) :\n  (p * q).prim_part = p.prim_part * q.prim_part :=\nbegin\n  rw [ne.def, ← content_eq_zero_iff, ← C_eq_zero] at h0,\n  apply mul_left_cancel₀ h0,\n  conv_lhs { rw [← (p * q).eq_C_content_mul_prim_part,\n    p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part] },\n  rw [content_mul, ring_hom.map_mul],\n  ring,\nend\n\nlemma is_primitive.is_primitive_of_dvd {p q : R[X]} (hp : p.is_primitive) (hdvd : q ∣ p) :\n  q.is_primitive :=\nbegin\n  rcases hdvd with ⟨r, rfl⟩,\n  rw [is_primitive_iff_content_eq_one, ← normalize_content, normalize_eq_one, is_unit_iff_dvd_one],\n  apply dvd.intro r.content,\n  rwa [is_primitive_iff_content_eq_one, content_mul] at hp,\nend\n\nlemma is_primitive.dvd_prim_part_iff_dvd {p q : R[X]}\n  (hp : p.is_primitive) (hq : q ≠ 0) :\n  p ∣ q.prim_part ↔ p ∣ q :=\nbegin\n  refine ⟨λ h, h.trans (dvd.intro_left _ q.eq_C_content_mul_prim_part.symm), λ h, _⟩,\n  rcases h with ⟨r, rfl⟩,\n  apply dvd.intro _,\n  rw [prim_part_mul hq, hp.prim_part_eq],\nend\n\ntheorem exists_primitive_lcm_of_is_primitive {p q : R[X]}\n  (hp : p.is_primitive) (hq : q.is_primitive) :\n  ∃ r : R[X], r.is_primitive ∧ (∀ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s) :=\nbegin\n  classical,\n  have h : ∃ (n : ℕ) (r : R[X]), r.nat_degree = n ∧ r.is_primitive ∧ p ∣ r ∧ q ∣ r :=\n    ⟨(p * q).nat_degree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩,\n  rcases nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩,\n  refine ⟨r, rprim, λ s, ⟨_, λ rs, ⟨pr.trans rs, qr.trans rs⟩⟩⟩,\n  suffices hs : ∀ (n : ℕ) (s : R[X]), s.nat_degree = n → (p ∣ s ∧ q ∣ s → r ∣ s),\n  { apply hs s.nat_degree s rfl },\n  clear s,\n  by_contra' con,\n  rcases nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩,\n  have s0 : s ≠ 0,\n  { contrapose! rs, simp [rs] },\n  have hs := nat.find_min' h ⟨_, s.nat_degree_prim_part, s.is_primitive_prim_part,\n              (hp.dvd_prim_part_iff_dvd s0).2 ps, (hq.dvd_prim_part_iff_dvd s0).2 qs⟩,\n  rw ← rdeg at hs,\n  by_cases sC : s.nat_degree ≤ 0,\n  { rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), is_primitive_iff_content_eq_one,\n      content_C, normalize_eq_one] at rprim,\n    rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), ← 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 ⟨_, rfl, ⟨dvd_cancel_leads_of_dvd_of_dvd pr ps, dvd_cancel_leads_of_dvd_of_dvd qr qs⟩,\n      λ rcs, rs _⟩,\n  rw ← 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, ← leading_coeff_eq_zero, ← C_eq_zero] at hC0,\n  rw [sub_add_cancel, ← rprim.dvd_prim_part_iff_dvd (mul_ne_zero hC0 s0)] at h,\n  rcases is_unit_prim_part_C r.leading_coeff with ⟨u, hu⟩,\n  apply h.trans (associated.symm ⟨u, _⟩).dvd,\n  rw [prim_part_mul (mul_ne_zero hC0 s0), hu, mul_comm],\nend\n\nlemma dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part\n  {p q : R[X]} (hq : q ≠ 0) :\n  p ∣ q ↔ p.content ∣ q.content ∧ p.prim_part ∣ q.prim_part :=\nbegin\n  split; intro h,\n  { rcases h with ⟨r, rfl⟩,\n    rw [content_mul, p.is_primitive_prim_part.dvd_prim_part_iff_dvd hq],\n    exact ⟨dvd.intro _ rfl, p.prim_part_dvd.trans (dvd.intro _ rfl)⟩ },\n  { rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part],\n    exact mul_dvd_mul (ring_hom.map_dvd C h.1) h.2 }\nend\n\n@[priority 100]\ninstance normalized_gcd_monoid : normalized_gcd_monoid R[X] :=\nnormalized_gcd_monoid_of_exists_lcm $ λ p q, begin\n  rcases exists_primitive_lcm_of_is_primitive p.is_primitive_prim_part q.is_primitive_prim_part\n    with ⟨r, rprim, hr⟩,\n  refine ⟨C (lcm p.content q.content) * r, λ s, _⟩,\n  by_cases hs : s = 0,\n  { simp [hs] },\n  by_cases hpq : C (lcm p.content q.content) = 0,\n  { 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    is_unit.mul_left_dvd _ _ _ (is_unit_prim_part_C (lcm p.content q.content)), ← hr s.prim_part],\n  tauto,\nend\n\nlemma degree_gcd_le_left {p : R[X]} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree :=\nbegin\n  have := nat_degree_le_iff_degree_le.mp\n    (nat_degree_le_of_dvd (gcd_dvd_left p q) hp),\n  rwa degree_eq_nat_degree hp\nend\n\nlemma degree_gcd_le_right (p) {q : R[X]} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree :=\nby { rw [gcd_comm], exact degree_gcd_le_left hq p }\n\nend normalized_gcd_monoid\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/ring_theory/polynomial/content.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7730144026979101}}
{"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 order.filter.basic\n\n/-!\n\n# Filters\n\n## What is a filter?\n\nMorally, a filter on a type `α` is a \"generalised subset of `α`\". By this I mean that each subset \nof `α` gives rise to a filter, but there are other \"ideas\", such as \"an infinitesimal neighbourhood of\na point in a topological space\" or \"a neighbourhood of infinity in a totally ordered set\", which can be \nexpressed as filters but not as sets (Isaac Newton might have wanted to have `dx` as \"a real number\ninfinitesimally close to 0\", but the modern treatments of real numbers don't allow `dx` as elements;\nfilters enable you to recover these thoughts)\n\nThe property which we want a \"generalised subset\" to have, is that it is uniquely determined\nby the *actual* subsets which it's containined in. Let's use this point of view to figure\nout the definition of a filter.\n\nIf `F` is a \"generalised subset\" of a type `α`, then then what properties should\nthe collection of *actual* subsets of `α` which contain `F` have?\n\n1) If `S` contains `F` and `S ⊆ T` then `T` contains `F`.\n2) If `S` and `T` contain `F`, then so does `S ∩ T`\n3) The set `α` itself (or, in Lean speak, `set.univ : set α`) contains `F`.\n\nThe way that these \"generalised subsets\" of `α` are modelled is precisely as collections\nof subsets of `α` satisfying these three axioms.\n\n## The formal definition\n\nstructure filter (α : Type*) :=\n(sets                   : set (set α))\n(univ_sets              : set.univ ∈ sets)\n(sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets)\n(inter_sets {x y}       : x ∈ sets → y ∈ sets → x ∩ y ∈ sets)\n\nIn other words, to give a filter on a type `α` is to give a set of subsets of `α` satisfying\nthe three axioms above.\n\nSome people add in an extra fourth axiom, saying that the empty set is not allowed to\nbe in `sets`. This is a way of saying that the empty set is not allowed to be a\ngeneralised subset of `α`. But it's certainly a subset of `α`, so in mathlib we do not\ninclude this fourth axiom. To me this missing axiom feels analogous to an axiom saying\nthat e.g. a ring is not allowed to be an ideal of itself; it might seem initially like\na good idea (because then \"maximal ideals\" really are maximal elements in the set of\nideals) but it causes a lot of confusion later on because you have to constantly deal\nwith the special case which you've disallowed.\n\n## Notation, helpful tactics and helpful theorems\n\nWe are not going to build filters from first principles, we will be\nusing Lean's API for filters. \n\nSay `α : Type` and `F : filter α` and `S : set α`. The notation `S ∈ F` is\ndefined to mean `S ∈ F.sets`. You should think of it as morally meaning `F ⊆ S`,\nbut this doesn't make sense because `F` is a filter, not a subset.\n\nThe `ext` tactic can be used to reduce a goal `F = G` to a goal of\nthe form `∀ S, S ∈ F ↔ S ∈ G`.\n\nThe fields of the structure mention things like `S ∈ F.sets`, so the\naxioms are restated with different names, but using the `S ∈ F` notation.\nThe lemmas corresponding to the definitions are:\n\n`univ_mem : univ ∈ F`\n`mem_of_superset : S ∈ F → S ⊆ T → T ∈ F`\n`inter_mem : S ∈ F → T ∈ F → S ∩ T ∈ F`\n\nThese lemmas in the `filter` namespace, i.e. their full names are\n`filter.univ_mem_sets` etc. But we are about to say `open filter`\nwhich means that you don't have to type this `filter.` thing in front of every\nlemma you need about filters. In fact we'll also be using a bunch of\nstuff about sets, like `set.inter_subset_left`, so why don't we `open set`\nas well.\n-/\n\nopen filter set\n\n-- Variables!\n-- let `α` be a type, let `F` be a filter on `α`, and let `S` and `T`\n-- denote subsets of `α`.\n\nvariables (α : Type) (F : filter α) (S T : set α)\n\n/-\nHere's a lemma about filters: Two sets `S` and `T` are both in\na filter `F` if and only if their intersection is. See if you can deduce\nit from the axioms of a filter.\n\nFor this one it's useful to know the following results (from the set namespace)\n`inter_subset_left S T : S ∩ T ⊆ S`\nand\n`inter_subset_right S T : S ∩ T ⊆ S`\n-/\nexample : S ∩ T ∈ F ↔ S ∈ F ∧ T ∈ F :=\nbegin\n  split,\n  { intro hST,\n    split,\n    { apply mem_of_superset hST,\n      exact inter_subset_left S T },\n    { apply mem_of_superset hST,\n      exact inter_subset_right S T } },\n  { rintros ⟨hS, hT⟩,\n    exact inter_mem hS hT }\nend\n\n/-\n\n## Principal filters\n\nSurely a subset of `α` should be a generalised subset of `α`! So there\nshould be a map `set α → filter α`. It's called `principal` and it\nhas notation `𝓟`. The principal filter `𝓟 X` generated by `X : set α` is the \nsubsets of `α` which contain `X`. Prove that it's a filter.\n\nHelpful for this exercise:\n`mem_univ s : s ∈ univ`\n`subset.trans : A ⊆ B → B ⊆ C → A ⊆ C`\n`subset_inter : X ⊆ S → X ⊆ T → X ⊆ S ∩ T`\n(note that you could probably prove those last two things directly yourself,\nbut we may as well use the interface for sets given that it's there)\n`mem_set_of_eq : x ∈ {a : α | p a} = p x`\n(this one is definitional, so you could use `change` instead, or just\nnot rewrite it at all)\n\n-/\n\n-- this is called `𝓟 X` in mathlib but let's just make it ourselves.\nexample (X : set α) : filter α :=\n{ sets := {S : set α | X ⊆ S},\n  univ_sets := begin\n    intros a ha,\n    exact mem_univ _,\n  end,\n  sets_of_superset := begin\n    intros S T hS hT,\n--    change X ⊆ T,\n--    change X ⊆ S at hS,\n    exact subset.trans hS hT,\n  end,\n  inter_sets := begin\n    intros S T hS hT,\n--    rw mem_set_of_eq at ⊢ hS hT,\n    exact subset_inter hS hT,\n  end }\n\n-- The notation for the principal filter generated by `X : set α` is `𝓟 X`.\n-- This notation is in the \"filter locale\", which is just a posh way\n-- of saying that you have to type\n\nopen_locale filter\n\n-- in order to get the notation.\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/section11_and_a_half_filters/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299498760558, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7730143854713799}}
{"text": "#check @nat.rec_on\n\n/-\nnat.rec_on :\n  Π {motive : ℕ → Sort u_1} \n  (n : ℕ), \n  motive 0 → \n  (Π (n : ℕ), motive n → motive n.succ) → \n  motive n\n-/\n\ndef fac : ℕ → ℕ :=\nbegin\n  assume n,\n  apply nat.rec_on n,\n  \n  -- first machine, base case\n  exact 1,\n\n  -- inductive case\n  assume n' facn',\n  exact facn' * (n'+1)\nend\n\nexample : fac 0 = 1 := rfl\nexample : fac 5 = 120 := rfl\n\ndef fac' : ℕ → ℕ \n| 0 := 1\n| (nat.succ n') := (nat.succ n') * (fac' n')\n\nexample : fac' 0 = 1 := rfl\nexample : fac' 5 = 120 := rfl\n\ndef sum_to : ℕ → ℕ \n| 0 := 0\n| (nat.succ n') := (nat.succ n') + (sum_to n')\n\nexample : sum_to 0 = 0 := rfl\nexample : sum_to 10 = 55 := rfl\n\ntheorem sum_thm : \n∀ (n : ℕ), 2 * sum_to n = n * (nat.succ n) :=\nbegin\n  assume n,\n  apply nat.rec_on n,\n  -- base case\n  exact rfl,\n  -- inductive\n  assume n' h,\n  --unfold sum_to,\n  simp [sum_to],\nend\n\n/-\nLet's looks at some induction principles\n-/\n\n\n#check @bool.rec_on\n\n/-\ninductive bool : Type\n| tt \n| ff\n\n Π {motive : bool → Sort u_1} (n : bool), motive ff → motive tt → motive n\n -/\n\n#print punit\n#check @punit.rec_on\n\n/-\nΠ {motive : punit → Sort u_1} (n : punit), motive punit.star → motive n\n-/\n\n#check empty\n\n/-\ninductive empty : Type\n\nΠ {motive : empty → Sort u_1} (n : empty), motive n\n-/\n\n#check @punit.rec_on\n\n/-\n Π {motive : punit → Sort u_1} (n : punit), motive \n-/\n\naxioms (e : empty) (purple : empty → Prop)\n\nexample : ∀ (e : empty), purple e :=\nbegin\n  assume e,\n  apply empty.rec_on,\nend\n\n/-\nCase analysis vs induction\n-/\n\nexample : ∀ (e : empty), purple e :=\nbegin\n  assume e,\n  cases e,\nend\n\nexample : ∀ (b : bool), band b tt = b :=\nbegin\n  assume b,\n  cases b,\n  repeat {exact rfl},\nend \n\ntheorem sum_thm' : \n∀ (n : ℕ), 2 * sum_to n = n * (nat.succ n) :=\nbegin\n  assume n,\n  cases n,\n  exact rfl,\n  apply linarith,\nend ", "meta": {"author": "kevinsullivan", "repo": "cs6501s22", "sha": "c55d342145b127e7b7bf396c660966034e80a944", "save_path": "github-repos/lean/kevinsullivan-cs6501s22", "path": "github-repos/lean/kevinsullivan-cs6501s22/cs6501s22-c55d342145b127e7b7bf396c660966034e80a944/src/content/S_02_PredicateLogic/L_05_Induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543454, "lm_q2_score": 0.8519528094861981, "lm_q1q2_score": 0.7729871939341159}}
{"text": "/-\nCopyright (c) 2022 Rishikesh Vaishnav. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rishikesh Vaishnav\n-/\nimport measure_theory.measure.measure_space\n\n/-!\n# Conditional Probability\n\nThis file defines conditional probability and includes basic results relating to it.\n\nGiven some measure `μ` defined on a measure space on some type `Ω` and some `s : set Ω`,\nwe define the measure of `μ` conditioned on `s` as the restricted measure scaled by\nthe inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling\nensures that this is a probability measure (when `μ` is a finite measure).\n\nFrom this definition, we derive the \"axiomatic\" definition of conditional probability\nbased on application: for any `s t : set Ω`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`.\n\n## Main Statements\n\n* `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent\n  to conditioning on their intersection.\n* `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`.\n\n## Notations\n\nThis file uses the notation `μ[|s]` the measure of `μ` conditioned on `s`,\nand `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the\napplication `μ[|s] t`).\n\nThese notations are contained in the locale `probability_theory`.\n\n## Implementation notes\n\nBecause we have the alternative measure restriction application principles\n`measure.restrict_apply` and `measure.restrict_apply'`, which require\nmeasurability of the restricted and restricting sets, respectively,\nmany of the theorems here will have corresponding alternatives as well.\nFor the sake of brevity, we've chosen to only go with `measure.restrict_apply'`\nfor now, but the alternative theorems can be added if needed.\n\nUse of `@[simp]` generally follows the rule of removing conditions on a measure\nwhen possible.\n\nHypotheses that are used to \"define\" a conditional distribution by requiring that\nthe conditioning set has non-zero measure should be named using the abbreviation\n\"c\" (which stands for \"conditionable\") rather than \"nz\". For example `(hci : μ (s ∩ t) ≠ 0)`\n(rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined.\n\n## Tags\nconditional, conditioned, bayes\n-/\n\nnoncomputable theory\n\nopen_locale ennreal\n\nopen measure_theory measurable_space\n\nvariables {Ω : Type*} {m : measurable_space Ω} (μ : measure Ω) {s t : set Ω}\n\nnamespace probability_theory\n\nsection definitions\n\n/-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s`\nand scaled by the inverse of `μ s` (to make it a probability measure):\n`(μ s)⁻¹ • μ.restrict s`. -/\ndef cond (s : set Ω) : measure Ω :=\n  (μ s)⁻¹ • μ.restrict s\n\nend definitions\n\nlocalized \"notation (name := probability_theory.cond)\n  μ `[` s `|` t `]` := probability_theory.cond μ t s\" in probability_theory\nlocalized \"notation (name := probability_theory.cond_fn)\n  μ `[|`:60 t`]` := probability_theory.cond μ t\" in probability_theory\n\n/-- The conditional probability measure of any finite measure on any set of positive measure\nis a probability measure. -/\n\n\nsection bayes\n\n@[simp] lemma cond_empty : μ[|∅] = 0 :=\nby simp [cond]\n\n@[simp] lemma cond_univ [is_probability_measure μ] :\n  μ[|set.univ] = μ :=\nby simp [cond, measure_univ, measure.restrict_univ]\n\n/-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/\nlemma cond_apply (hms : measurable_set s) (t : set Ω) :\n  μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) :=\nby { rw [cond, measure.smul_apply, measure.restrict_apply' hms, set.inter_comm], refl }\n\nlemma cond_inter_self (hms : measurable_set s) (t : set Ω) :\n  μ[s ∩ t|s] = μ[t|s] :=\nby rw [cond_apply _ hms, ← set.inter_assoc, set.inter_self, ← cond_apply _ hms]\n\nlemma inter_pos_of_cond_ne_zero (hms : measurable_set s) (hcst : μ[t|s] ≠ 0) :\n  0 < μ (s ∩ t) :=\nbegin\n  refine pos_iff_ne_zero.mpr (right_ne_zero_of_mul _),\n  { exact (μ s)⁻¹ },\n  convert hcst,\n  simp [hms, set.inter_comm]\nend\n\nlemma cond_pos_of_inter_ne_zero [is_finite_measure μ]\n  (hms : measurable_set s) (hci : μ (s ∩ t) ≠ 0) :\n  0 < μ[|s] t :=\nbegin\n  rw cond_apply _ hms,\n  refine ennreal.mul_pos _ hci,\n  exact ennreal.inv_ne_zero.mpr (measure_ne_top _ _),\nend\n\nlemma cond_cond_eq_cond_inter'\n  (hms : measurable_set s) (hmt : measurable_set t) (hcs : μ s ≠ ∞) (hci : μ (s ∩ t) ≠ 0) :\n  μ[|s][|t] = μ[|s ∩ t] :=\nbegin\n  have hcs : μ s ≠ 0 := (μ.to_outer_measure.pos_of_subset_ne_zero\n    (set.inter_subset_left _ _) hci).ne',\n  ext u,\n  simp [*, hms.inter hmt, cond_apply, ← mul_assoc, ← set.inter_assoc,\n    ennreal.mul_inv, mul_comm, ← mul_assoc, ennreal.inv_mul_cancel],\nend\n\n/-- Conditioning first on `s` and then on `t` results in the same measure as conditioning\non `s ∩ t`. -/\nlemma cond_cond_eq_cond_inter [is_finite_measure μ]\n  (hms : measurable_set s) (hmt : measurable_set t) (hci : μ (s ∩ t) ≠ 0) :\n  μ[|s][|t] = μ[|s ∩ t] :=\ncond_cond_eq_cond_inter' μ hms hmt (measure_ne_top μ s) hci\n\nlemma cond_mul_eq_inter'\n  (hms : measurable_set s) (hcs : μ s ≠ 0) (hcs' : μ s ≠ ∞) (t : set Ω) :\n  μ[t|s] * μ s = μ (s ∩ t) :=\nby rw [cond_apply μ hms t, mul_comm, ←mul_assoc,\n  ennreal.mul_inv_cancel hcs hcs', one_mul]\n\nlemma cond_mul_eq_inter [is_finite_measure μ]\n  (hms : measurable_set s) (hcs : μ s ≠ 0) (t : set Ω) :\n  μ[t|s] * μ s = μ (s ∩ t) :=\ncond_mul_eq_inter' μ hms hcs (measure_ne_top _ s) t\n\n/-- A version of the law of total probability. -/\nlemma cond_add_cond_compl_eq [is_finite_measure μ]\n  (hms : measurable_set s) (hcs : μ s ≠ 0) (hcs' : μ sᶜ ≠ 0) :\n  μ[t|s] * μ s + μ[t|sᶜ] * μ sᶜ = μ t :=\nbegin\n  rw [cond_mul_eq_inter μ hms hcs, cond_mul_eq_inter μ hms.compl hcs', set.inter_comm _ t,\n    set.inter_comm _ t],\n  exact measure_inter_add_diff t hms,\nend\n\n/-- **Bayes' Theorem** -/\ntheorem cond_eq_inv_mul_cond_mul [is_finite_measure μ]\n  (hms : measurable_set s) (hmt : measurable_set t) :\n  μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t) :=\nbegin\n  by_cases ht : μ t = 0,\n  { simp [cond, ht, measure.restrict_apply hmt, or.inr (measure_inter_null_of_null_left s ht)] },\n  { rw [mul_assoc, cond_mul_eq_inter μ hmt ht s, set.inter_comm, cond_apply _ hms] }\nend\n\nend bayes\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/conditional_probability.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7729871926733959}}
{"text": "import definitions \nimport data.list.basic\n\ndefinition fib_mod (m : ℕ) : ℕ → ℕ \n| 0 := 0 % m\n| 1 := 1 % m\n| (n + 2) := ( (fib_mod n) + (fib_mod (n + 1)) ) % m\n\ndef luc_mod (m : ℕ) : ℕ → ℕ\n| 0 := 2 % m\n| 1 := 1 % m\n| (n + 2) := ( (luc_mod n) + (luc_mod (n + 1)) ) % m\n\ntheorem luc_mod_is_luc (m : ℕ) : ∀ r : ℕ,\nluc_mod m r = (luc r) % m  \n| 0 := rfl\n| 1 := rfl \n| (n + 2) := begin\nhave Hn := luc_mod_is_luc n,\nhave Hnp1 := luc_mod_is_luc (n + 1),\nunfold luc_mod,\nunfold luc,\nrw Hn,\nrw Hnp1,\nshow (luc n % m + luc (n + 1) % m) % m = (luc n + luc (n + 1)) % m,\napply nat.mod_add,\nend \n\n\n\ntheorem fib_mod_eq (m n : ℕ) : (fib_mod m) n = (fib n) % m :=\nnat.rec_on_two n (rfl) (rfl) (begin\n  intros d Hd Hdplus1,\n  unfold fib,\n  unfold fib_mod,\n  rw Hd,\n  rw Hdplus1,\n  exact nat.mod_add _ _ _\nend)\n\ntheorem luc_mod_eq (m n : ℕ) : (luc_mod m) n = (luc n) % m :=\nnat.rec_on_two n (rfl) (rfl) (begin\n  intros d Hd Hdplus1,\n  unfold luc,\n  unfold luc_mod,\n  rw Hd,\n  rw Hdplus1,\n  exact nat.mod_add _ _ _\nend)\n\n\ntheorem fib_mod_16_aux (n : ℕ) : (fib_mod 16) (n + 24) = (fib_mod 16) n :=\nnat.rec_on_two n (rfl) (rfl) (begin\n  intros d Hd Hdplus1,\n  show (fib_mod 16 (d + 24) + fib_mod 16 (nat.succ d + 24)) % 16 = \n  (fib_mod 16 d + fib_mod 16 (nat.succ d)) % 16,\n  rw Hd,rw Hdplus1,\nend)\n\ntheorem fib_mod_16 (n : ℕ) : (fib_mod 16) n = (fib_mod 16) (n % 24) := \nbegin\n  have H : ∀ n k, fib_mod 16 (n + 24 * k) = (fib_mod 16) n,\n  { intros n k, \n    induction k with d Hd,\n    -- base case\n    { refl},\n    -- inductive step\n    { show fib_mod 16 (n + 24 * (d + 1)) = fib_mod 16 n,\n      rwa [mul_add,←add_assoc,mul_one,fib_mod_16_aux],\n    },\n  },\n  conv begin\n    to_lhs,\n    rw ←nat.mod_add_div n 24,\n  end,\n  rw H (n % 24) (n / 24)\nend\n\ntheorem luc_mod_8_aux (n : ℕ) : (luc_mod 8) (n + 12) = (luc_mod 8) n :=\nnat.rec_on_two n (rfl) (rfl) (begin\n  intros d Hd Hdplus1,\n  show (luc_mod 8 (d + 12) + luc_mod 8 (nat.succ d + 12)) % 8 = \n  (luc_mod 8 d + luc_mod 8 (nat.succ d)) % 8,\n  rw Hd,rw Hdplus1,\nend)\n\ntheorem luc_mod_8 (n : ℕ) : (luc_mod 8) n = (luc_mod 8) (n % 12) := \nbegin\n  have H : ∀ n k, luc_mod 8 (n + 12 * k) = (luc_mod 8) n,\n  { intros n k, \n    induction k with d Hd,\n    -- base case\n    { refl},\n    -- inductive step\n    { show luc_mod 8 (n + 12 * (d + 1)) = luc_mod 8 n,\n      rwa [mul_add,←add_assoc,mul_one,luc_mod_8_aux],\n    },\n  },\n  conv begin\n    to_lhs,\n    rw ←nat.mod_add_div n 12,\n  end,\n  rw H (n % 12) (n / 12)\nend\n\ntheorem luc_mod_3_aux (n : ℕ) : (luc_mod 3) (n + 8) = (luc_mod 3) n :=\nnat.rec_on_two n (rfl) (rfl) (begin\n  intros d Hd Hdplus1,\n  show (luc_mod 3 (d + 8) + luc_mod 3 (nat.succ d + 8)) % 3 = \n  (luc_mod 3 d + luc_mod 3 (nat.succ d)) % 3,\n  rw Hd,rw Hdplus1,\nend)\n\ntheorem luc_mod_3 (n : ℕ) : (luc_mod 3) n = (luc_mod 3) (n % 8) := \nbegin\n  have H : ∀ n k, luc_mod 3 (n + 8 * k) = (luc_mod 3) n,\n  { intros n k, \n    induction k with d Hd,\n    -- base case\n    { refl},\n    -- inductive step\n    { show luc_mod 3 (n + 8 * (d + 1)) = luc_mod 3 n,\n      rwa [mul_add,←add_assoc,mul_one,luc_mod_3_aux],\n    },\n  },\n  conv begin\n    to_lhs,\n    rw ←nat.mod_add_div n 8,\n  end,\n  rw H (n % 8) (n / 8)\nend\n\ntheorem luc_mod_2_aux (n : ℕ) : (luc_mod 2) (n + 3) = (luc_mod 2) n :=\nnat.rec_on_two n (rfl) (rfl) (begin\n  intros d Hd Hdplus1,\n  show (luc_mod 2 (d + 3) + luc_mod 2 (nat.succ d + 3)) % 2 = \n  (luc_mod 2 d + luc_mod 2 (nat.succ d)) % 2,\n  rw Hd,rw Hdplus1,\nend)\n\ntheorem luc_mod_2 (n : ℕ) : (luc_mod 2) n = (luc_mod 2) (n % 3) := \nbegin\n  have H : ∀ n k, luc_mod 2 (n + 3 * k) = (luc_mod 2) n,\n  { intros n k, \n    induction k with d Hd,\n    -- base case\n    { refl},\n    -- inductive step\n    { show luc_mod 2 (n + 3 * (d + 1)) = luc_mod 2 n,\n      rwa [mul_add,←add_assoc,mul_one,luc_mod_2_aux],\n    },\n  },\n  conv begin\n    to_lhs,\n    rw ←nat.mod_add_div n 3,\n  end,\n  rw H (n % 3) (n / 3)\nend\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/fib_mod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551957, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.772966372674177}}
{"text": "import Mathlib.Data.Nat.Log\nimport Mathlib.Tactic.Linarith\nimport Mathlib.Tactic.NormNum\n\ntheorem log_pred : ∀ (a : Nat) , Nat.log 2 a - 1 = Nat.log 2 (a / 2)\n| 0 => by simp only [Nat.log_zero_right, Nat.zero_div]\n| 1 => by norm_num\n| (a + 2) => by\n  rw [Nat.log]\n  split_ifs with h\n  { simp }\n  simp at h\n\ntheorem log_2_val : Nat.log 2 2 = 1 := by rfl\n \ntheorem sum_2b (a b : Nat) : a ≤ 2 * b → a + 2 * b ≤ 4 * b := fun h =>\n  calc a + 2 * b ≤ 2 * b + 2 * b := add_le_add h rfl.ge\n       _         = 4 * b := by linarith\n\n\ntheorem log_2_times : ∀ (a : Nat), 2 * Nat.log 2 (a + 2) ≤ a + 2\n| 0       => by { rw [log_2_val] }\n| (a + 1) => by\n  have tmp : (a + 1) / 2 < a + 1 := Nat.div_lt_self' a 0\n  rw [Nat.log]\n  split_ifs\n  { have ih := log_2_times ((a + 1) / 2)\n    rw [mul_add]\n    cases a with\n    | zero    => rw [Nat.log]; simp\n    | succ a' =>\n        cases a' with\n        | zero     => norm_num; rw [log_2_val]\n        | succ a'' =>\n          norm_num\n          have add_one :\n            2 * Nat.log 2 ((a''.succ.succ + 1) / 2).succ ≤\n            2 * Nat.log 2 (((a''.succ.succ + 1) / 2) + 2) :=\n              by apply Nat.mul_le_mul_left 2\n                 apply Nat.log_monotone\n                 exact Nat.le_succ ((a''.succ.succ + 1) / 2 + 1)\n          apply le_trans add_one\n          apply le_trans ih\n          have succ_succ_two : a''.succ.succ + 1 = a'' + 3 := rfl\n          have two_div_two : ∀ {y}, (y + 2) / 2 = y / 2 + 1 := by\n            intro y; rw [(y + 2).div_eq 2]; simp\n          have three_eq_one_plus_two : ∀ {y}, y + 3 = y + 1 + 2 := by\n            intro y; rfl\n          rw [ succ_succ_two\n             , two_div_two\n             , three_eq_one_plus_two\n             , ← three_eq_one_plus_two\n             ]\n          apply flip add_le_add (le_refl 3)\n          exact Nat.lt_succ_iff.mp (Nat.div_lt_self' a'' 0)\n  }\n  simp\n\ntheorem div_two (b a : ℕ) : 2 * a ≤ b → a ≤ b / 2 :=\n  by simp_rw [Nat.le_div_iff_mul_le zero_lt_two, mul_comm, imp_self]\n", "meta": {"author": "tomaz1502", "repo": "runtime-formalization4", "sha": "22b5078c2a9830b8b0bfcb594609589f7d88661c", "save_path": "github-repos/lean/tomaz1502-runtime-formalization4", "path": "github-repos/lean/tomaz1502-runtime-formalization4/runtime-formalization4-22b5078c2a9830b8b0bfcb594609589f7d88661c/Runtime/MergeSort/LogLemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7729467322775572}}
{"text": "import analysis.specific_limits.basic\nimport data.int.parity\nimport topology.sequences\n\nattribute [instance] classical.prop_decidable\n\n/- \nLemmas from that file were hidden in my course, or restating things which\nwere proved without name in previous files.\n-/\n\nnotation `|`x`|` := abs x\n\n-- The mathlib version is unusable because it is stated in terms of ≤\nlemma ge_max_iff {α : Type*} [linear_order α] {p q r : α} : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\n/- No idea why this is not in mathlib-/\nlemma eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h, \n  apply eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\nlemma unique_limit {u l l'} : seq_limit u l → seq_limit u l' → l = l' :=\nbegin\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros ε ε_pos,\n  specialize hl (ε/2) (by linarith),\n  cases hl with N hN,\n  specialize hl' (ε/2) (by linarith),\n  cases hl' with N' hN',\n  specialize hN (max N N') (le_max_left _ _),\n  specialize hN' (max N N') (le_max_right _ _),\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring_nf\n  ... ≤ |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  ... ≤ ε/2 + ε/2 : by linarith\n  ... = ε : by ring,\nend\n\nlemma le_of_le_add_all {x y : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\ndef upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y\n\nlemma lt_sup {A : set ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\nlemma squeeze {u v w : ℕ → ℝ} {l} (hu : seq_limit u l) (hw : seq_limit w l)\n(h : ∀ n, u n ≤ v n)\n(h' : ∀ n, v n ≤ w n) : seq_limit v l :=\nbegin\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases hw ε ε_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 ; linarith\nend\n\ndef extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m\n\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\nlemma lim_le {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\nlemma inv_succ_le_all :  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    intros h ε ε_pos,\n    cases h (ε/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n    specialize hN n hn,\n    linarith,\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\nlemma limit_const (x : ℝ) : seq_limit (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\nlemma limit_of_sub_le_inv_succ {u : ℕ → ℝ} {x : ℝ} (h : ∀ n, |u n - x| ≤ 1/(n+1)) :\nseq_limit u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\nlemma limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ; linarith [@nat.one_div_pos_of_nat ℝ _ n])\n\nlemma limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\nlemma id_le_extraction {φ}: extraction φ → ∀ n, n ≤ φ 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\nlemma seq_limit_id : tendsto_infinity (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N, exact_mod_cast hn, \n  linarith,\nend\n\nvariables {u : ℕ → ℝ} {l : ℝ} {φ : ℕ → ℕ}\n\nopen set filter\n\ndef cluster_point (u : ℕ → ℝ) (a : ℝ) :=\n∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a\n\nlemma bolzano_weierstrass {a b : ℝ} {u : ℕ → ℝ} (h : ∀ n, u n ∈ Icc a b) :\n∃ c ∈ Icc a b, cluster_point u c :=\nbegin\n  rcases (is_compact_Icc : is_compact (Icc a b)).tendsto_subseq h with ⟨c, c_in, φ, hφ, lim⟩,\n  use [c, c_in, φ, hφ],\n  simp_rw [metric.tendsto_nhds, eventually_at_top, real.dist_eq] at lim,\n  intros ε ε_pos,\n  rcases lim ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  exact le_of_lt (hN n hn)\nend\n\nlemma not_seq_limit_of_tendstoinfinity {u : ℕ → ℝ} :\n  tendsto_infinity u → ∀ x, ¬ seq_limit u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\nopen real \n\nlemma sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :\n  ∃ x ∈ Icc a b, is_sup A x :=\nbegin\n  have b_maj :  ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : upper_bound A (Sup A),\n  { intro x,\n    apply le_cSup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply cSup_le hnonvide b_maj } },\n  { exact ⟨Sup_maj, λ y, cSup_le hnonvide⟩ },\nend\n\nlemma subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn \n     ... ≤ φ n : id_le_extraction hφ n, \nend\nnamespace tactic.interactive\nopen tactic\n\nmeta def check_me : tactic unit :=\n`[ { repeat { unfold seq_limit},\n   repeat { unfold continue_en },\n   push_neg,\n   try { simp only [exists_prop] },\n   try { exact iff.rfl },\n   done } <|> fail \"That's not quite right. Please try again.\" ]\n\nend tactic.interactive\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/tuto_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7729420641367302}}
{"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ël Dillies\n-/\nimport data.nat.pow\nimport tactic.by_contra\n\n/-!\n# Natural number logarithms\n\nThis file defines two `ℕ`-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 ≤ n`.\n* `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n ≤ 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 : ℕ`\nsuch that `b^k ≤ n`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def log (b : ℕ) : ℕ → ℕ\n| n :=\n  if h : b ≤ n ∧ 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\nlemma log_eq_zero {b n : ℕ} (hnb : n < b ∨ b ≤ 1) : log b n = 0 :=\nbegin\n  rw [or_iff_not_and_not, not_lt, not_le] at hnb,\n  rw [log, ←ite_not, if_pos hnb],\nend\n\nlemma log_of_one_lt_of_le {b n : ℕ} (h : 1 < b) (hn : b ≤ n) : log b n = log b (n / b) + 1 :=\nbegin\n  rw log,\n  exact if_pos ⟨hn, h⟩,\nend\n\nlemma log_of_lt {b n : ℕ} (hnb : n < b) : log b n = 0 :=\nby rw [log, if_neg (λ h : b ≤ n ∧ 1 < b, h.1.not_lt hnb)]\n\nlemma log_of_left_le_one {b n : ℕ} (hb : b ≤ 1) : log b n = 0 :=\nby rw [log, if_neg (λ h : b ≤ n ∧ 1 < b, h.2.not_le hb)]\n\nlemma log_eq_zero_iff {b n : ℕ} : log b n = 0 ↔ n < b ∨ b ≤ 1 :=\nbegin\n  refine ⟨λ h_log, _, log_eq_zero⟩,\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\n\nlemma log_eq_one_iff {b n : ℕ} : log b n = 1 ↔ n < b * b ∧ 1 < b ∧ b ≤ n :=\n-- This is best possible: if b = 2, n = 5, then 1 < b and b ≤ n but n > b * b.\nbegin\n  refine ⟨λ h_log, _, _⟩,\n  { have bound : 1 < b ∧ b ≤ n,\n    { contrapose h_log,\n      rw [not_and_distrib, not_lt, not_le, or_comm, ←log_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 ⟨_, one_lt_b, b_le_n⟩,\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 (λ b_small, lt_irrefl _ (lt_of_lt_of_le one_lt_b b_small)), },\n  { rintros ⟨h, one_lt_b, b_le_n⟩,\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 (n : ℕ) : log 0 n = 0 :=\nlog_of_left_le_one zero_le_one\n\n@[simp] lemma log_zero_right (b : ℕ) : log b 0 = 0 :=\nby { rw log, cases b; refl }\n\n@[simp] lemma log_one_left (n : ℕ) : log 1 n = 0 :=\nlog_of_left_le_one le_rfl\n\n@[simp] lemma log_one_right (b : ℕ) : log b 1 = 0 :=\nif h : b ≤ 1 then\n  log_of_left_le_one h\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 : ℕ} (hb : 1 < b) {x y : ℕ} (hy : 0 < y) :\n  b^x ≤ y ↔ x ≤ 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, ←ih (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 (λ hby, h ⟨le_trans _ hby, hb⟩) (not_succ_le_zero _),\n    convert pow_mono hb.le (zero_lt_succ x),\n    exact (pow_one b).symm }\nend\n\nlemma log_pow {b : ℕ} (hb : 1 < b) (x : ℕ) : log b (b ^ x) = x :=\neq_of_forall_le_iff $ λ z,\nby { rw ←pow_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 : ℕ} (hb : 1 < b) (hn : b ≤ n) : 0 < log b n :=\nby { rwa [←succ_le_iff, ←pow_le_iff_le_log hb (hb.le.trans hn), pow_one] }\n\nlemma log_mul_base (b n : ℕ) (hb : 1 < b) (hn : 0 < n) : log b (n * b) = log b n + 1 :=\neq_of_forall_le_iff $ λ z,\nbegin\n  cases z,\n  { simp },\n  have : 0 < b := zero_lt_one.trans hb,\n  rw [←pow_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 : ℕ} (hb : 1 < b) {x : ℕ} (hx : 0 < x) :\n  x < b ^ (log b x).succ :=\nbegin\n  rw [←not_le, pow_le_iff_le_log hb hx, not_le],\n  exact lt_succ_self _,\nend\n\nlemma pow_log_le_self {b : ℕ} (hb : 1 < b) {x : ℕ} (hx : 0 < x) : b ^ log b x ≤ x :=\n(pow_le_iff_le_log hb hx).2 le_rfl\n\nlemma log_le_log_of_le {b n m : ℕ} (h : n ≤ m) : log b n ≤ 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 ←pow_le_iff_le_log hb (hn.trans_le h),\n      exact (pow_log_le_self hb hn).trans h } }\nend\n\nlemma log_le_log_of_left_ge {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : log b n ≤ log c n :=\nbegin\n  cases n, { simp },\n  rw ← pow_le_iff_le_log hc (zero_lt_succ n),\n  calc\n    c ^ log b n.succ ≤ b ^ log b n.succ : pow_le_pow_of_le_left\n                                            (le_of_lt $ zero_lt_one.trans hc) hb _\n                 ... ≤ n.succ           : pow_log_le_self (lt_of_lt_of_le hc hb)\n                                            (zero_lt_succ n)\nend\n\nlemma log_monotone {b : ℕ} : monotone (λ n : ℕ, log b n) :=\nλ x y, log_le_log_of_le\n\nlemma log_antitone_left {n : ℕ} : antitone_on (λ b, log b n) (set.Ioi 1) :=\nλ _ hc _ _ hb, log_le_log_of_left_ge (set.mem_Iio.1 hc) hb\n\n@[simp] lemma log_div_mul_self (b n : ℕ) : log b (n / b * b) = log b n :=\nbegin\n  refine eq_of_forall_le_iff (λ z, _),\n  split,\n  { intro h,\n    exact h.trans (log_monotone (div_mul_le_self _ _)) },\n  { intro h,\n    rcases b with _|_|b,\n    { simpa using h },\n    { simpa using h },\n    rcases n.zero_le.eq_or_lt with rfl|hn,\n    { simpa using h },\n    cases le_or_lt b.succ.succ n with hb hb,\n    { cases z,\n      { simp },\n      have : 0 < b.succ.succ := nat.succ_pos',\n      rw [←pow_le_iff_le_log, pow_succ'] at h ⊢,\n      { rwa [(strict_mono_mul_right_of_pos this).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_eq_zero] using h } }\nend\n\n@[simp] lemma log_div_base (b n : ℕ) : log b (n / b) = log b n - 1 :=\nbegin\n  cases lt_or_le n b with h h,\n  { simp [div_eq_of_lt, h, log_eq_zero] },\n  rcases n.zero_le.eq_or_lt with rfl|hn,\n  { simp },\n  rcases b with _|_|b,\n  { simp },\n  { simp },\n  rw [←succ_inj', ←succ_inj'],\n  simp_rw succ_eq_add_one,\n  rw [nat.sub_add_cancel, ←log_mul_base];\n  { simp [succ_le_iff, log_pos, h, nat.div_pos] },\nend\n\n\nprivate lemma add_pred_div_lt {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : (n + b - 1)/b < n :=\nbegin\n  rw [div_lt_iff_lt_mul _ _ (zero_lt_one.trans hb), ←succ_le_iff, ←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,\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 : ℕ` such that `n ≤ b^k`, so if `b^k = n`, it returns exactly `k`. -/\n@[pp_nodot] def clog (b : ℕ) : ℕ → ℕ\n| n :=\n  if h : 1 < b ∧ 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 : ℕ} (hb : b ≤ 1) (n : ℕ) : clog b n = 0 :=\nby rw [clog, if_neg (λ h : 1 < b ∧ 1 < n, h.1.not_le hb)]\n\nlemma clog_of_right_le_one {n : ℕ} (hn : n ≤ 1) (b : ℕ) : clog b n = 0 :=\nby rw [clog, if_neg (λ h : 1 < b ∧ 1 < n, h.2.not_le hn)]\n\n@[simp] lemma clog_zero_left (n : ℕ) : clog 0 n = 0 :=\nclog_of_left_le_one zero_le_one _\n\n@[simp] lemma clog_zero_right (b : ℕ) : clog b 0 = 0 :=\nclog_of_right_le_one zero_le_one _\n\n@[simp] lemma clog_one_left (n : ℕ) : clog 1 n = 0 :=\nclog_of_left_le_one le_rfl _\n\n@[simp] lemma clog_one_right (b : ℕ) : clog b 1 = 0 :=\nclog_of_right_le_one le_rfl _\n\nlemma clog_of_two_le {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) :\n  clog b n = clog b ((n + b - 1)/b) + 1 :=\nby rw [clog, if_pos (⟨hb, hn⟩ : 1 < b ∧ 1 < n)]\n\nlemma clog_pos {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : 0 < clog b n :=\nby { rw clog_of_two_le hb hn, exact zero_lt_succ _ }\n\nlemma clog_eq_one {b n : ℕ} (hn : 2 ≤ n) (h : n ≤ 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 [←lt_succ_iff, nat.div_lt_iff_lt_mul _ _ (n_pos.trans_le h), ←succ_le_iff,\n    ←pred_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 : ℕ} (hb : 1 < b) {x y : ℕ} :\n  x ≤ b^y ↔ clog b x ≤ y :=\nbegin\n  induction x using nat.strong_induction_on with x ih generalizing y,\n  cases y,\n  { rw [pow_zero],\n    refine ⟨λ h, (clog_of_right_le_one h b).le, _⟩,\n    simp_rw ←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  { rw [succ_eq_add_one, add_le_add_iff_right, ←ih ((x + b - 1)/b) (add_pred_div_lt hb h.2),\n      nat.div_le_iff_le_mul_add_pred b_pos,\n      ← 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 clog_pow (b x : ℕ) (hb : 1 < b) : clog b (b ^ x) = x :=\neq_of_forall_ge_iff $ λ z,\nby { rw ←le_pow_iff_clog_le hb, exact (pow_right_strict_mono hb).le_iff_le }\n\nlemma pow_pred_clog_lt_self {b : ℕ} (hb : 1 < b) {x : ℕ} (hx : 1 < x) :\n  b ^ (clog b x).pred < x :=\nbegin\n  rw [←not_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 : ℕ} (hb : 1 < b) (x : ℕ) : x ≤ b ^ clog b x :=\n(le_pow_iff_clog_le hb).2 le_rfl\n\nlemma clog_le_clog_of_le (b : ℕ) {n m : ℕ} (h : n ≤ m) : clog b n ≤ 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 ←le_pow_iff_clog_le hb,\n    exact h.trans (le_pow_clog hb _) }\nend\n\nlemma clog_le_clog_of_left_ge {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : clog b n ≤ clog c n :=\nbegin\n  cases n, { simp },\n  rw ← le_pow_iff_clog_le (lt_of_lt_of_le hc hb),\n  calc\n    n.succ ≤ c ^ clog c n.succ : le_pow_clog hc _\n       ... ≤ b ^ clog c n.succ : pow_le_pow_of_le_left (le_of_lt $ zero_lt_one.trans hc) hb _\nend\n\nlemma clog_monotone (b : ℕ) : monotone (clog b) :=\nλ x y, clog_le_clog_of_le _\n\nlemma clog_antitone_left {n : ℕ} : antitone_on (λ b : ℕ, clog b n) (set.Ioi 1) :=\nλ _ hc _ _ hb, clog_le_clog_of_left_ge (set.mem_Iio.1 hc) hb\n\nlemma log_le_clog (b n : ℕ) : log b n ≤ 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": "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/log.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.772942045143451}}
{"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 `ℍ := ℍ[ℝ]` of quaternions:\n\n* inner product space;\n* normed ring;\n* normed space over `ℝ`.\n\n## Notation\n\nThe following notation is available with `open_locale quaternion`:\n\n* `ℍ` : quaternions\n\n## Tags\n\nquaternion, normed ring, normed space, normed algebra\n-/\n\nlocalized \"notation `ℍ` := quaternion ℝ\" in quaternion\nopen_locale real_inner_product_space\n\nnoncomputable theory\n\nnamespace quaternion\n\ninstance : has_inner ℝ ℍ := ⟨λ a b, (a * b.conj).re⟩\n\nlemma inner_self (a : ℍ) : ⟪a, a⟫ = norm_sq a := rfl\n\nlemma inner_def (a b : ℍ) : ⟪a, b⟫ = (a * b.conj).re := rfl\n\ninstance : inner_product_space ℝ ℍ :=\ninner_product_space.of_core\n{ inner := has_inner.inner,\n  conj_sym := λ x y, by simp [inner_def, mul_comm],\n  nonneg_re := λ x, norm_sq_nonneg,\n  definite := λ x, norm_sq_eq_zero.1,\n  add_left := λ x y z, by simp only [inner_def, add_mul, add_re],\n  smul_left := λ x y r, by simp [inner_def] }\n\nlemma norm_sq_eq_norm_sq (a : ℍ) : norm_sq a = ∥a∥ * ∥a∥ :=\nby rw [← inner_self, real_inner_self_eq_norm_mul_norm]\n\ninstance : norm_one_class ℍ :=\n⟨by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]⟩\n\n@[simp] lemma norm_mul (a b : ℍ) : ∥a * b∥ = ∥a∥ * ∥b∥ :=\nbegin\n  simp only [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_mul],\n  exact real.sqrt_mul norm_sq_nonneg _\nend\n\n@[simp, norm_cast] lemma norm_coe (a : ℝ) : ∥(a : ℍ)∥ = ∥a∥ :=\nby rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_coe, real.sqrt_sq_eq_abs, real.norm_eq_abs]\n\nnoncomputable instance : normed_ring ℍ :=\n{ dist_eq := λ _ _, rfl,\n  norm_mul := λ a b, (norm_mul a b).le }\n\nnoncomputable instance : normed_algebra ℝ ℍ :=\n{ norm_algebra_map_eq := norm_coe,\n  to_algebra := quaternion.algebra }\n\ninstance : has_coe ℂ ℍ := ⟨λ z, ⟨z.re, z.im, 0, 0⟩⟩\n\n@[simp, norm_cast] \n\n@[simp, norm_cast] lemma coe_complex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_zero : ((0 : ℂ) : ℍ) = 0 := rfl\n@[simp, norm_cast] lemma coe_complex_one : ((1 : ℂ) : ℍ) = 1 := rfl\n@[simp, norm_cast] lemma coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z :=\nby ext; simp\n@[simp, norm_cast] lemma coe_complex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl\n\n/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/\ndef of_complex : ℂ →ₐ[ℝ] ℍ :=\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' := λ x, rfl }\n\n@[simp] lemma coe_of_complex : ⇑of_complex = coe := rfl\n\nend quaternion\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/quaternion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.772917748248655}}
{"text": "/-\nCopyright 2019 Kevin Sullivan and Ben Hocking.  \n-/\n\n/-\nInference rules. Introduction rules construct proofs that you don't yet have. Elimination rules extract information from proofs that you already have.\n-/\nnamespace Introduction.ex1\n-- introduction: construct a proof\ndef construct_a_proof\n(P Q : Prop)\n(p : P)\n(q : Q)\n: P ∧ Q\n:= and.intro p q\n\n-- elimination: use a proof\ndef use_a_proof\n(P Q : Prop)\n(p_and_q : P ∧ Q)\n: P\n:= and.elim_left p_and_q\nend Introduction.ex1\n\n\n/-\nBinding of names to values and the evaluation of names that are already bound to values. Names can be bound to values only once. There are no \"variables\" (no \"mutable state\") in Lean.\n-/\nnamespace Introduction.ex2\ndef x : nat := 5  -- bind the name x to the value, 5\n#check x          -- the type of the term x is now nat\n#reduce x         -- evaluating x yields the value 5\ndef x := 6        -- we cannot bind a new value to x\nend Introduction.ex2\n\n\n-- Function application expressions and evaluation\n#reduce 3 * 4\n\n\n\n/-\nTerms have types, too.\n-/\n#check 3\n#check 3 * 4\n\n\n\n/-\nLean is stronly and statically typed. It will issue an error for the following code.\n-/\n#check 3 * \"Hello, Lean!\"\n\n\n\n  /-\n Lean does type inference. Type inference means that you can leave out explicit type declarations in cases where Lean can figure out what the types must be from context.\n  -/\nnamespace Introduction.ex3\ndef x : nat := (1 : nat)\ndef x' : nat := 1\ndef x'' := 1\n#check x\n#check x'\n#check x''\nend Introduction.ex3\n\n\n\n/-\nAll terms in Lean have types.\n-/\n#check tt\n#check ff\n#check \"Hello, Lean!\"\n\n\n\n/-\nTypes are values (terms) too\n-/\n#check nat\n#check bool\n#check string\n\n\n/-\nYou can check out the entire type hierarchy yourself.\n-/\n#check 3\n#check nat\n#check Type\n#check Type 0\n#check Type 1\n\n\n\n/-\nPropositions are types and proofs are values of these types. This principle is the basis for automated proof checking in Lean and in other constructive logic proof assistants such as Coq and Agda.\n-/\nnamespace Introduction.ex4\ndef p : true := true.intro\nend Introduction.ex4\n\n\n\n/-\nLean rejects proof terms that do not type check, just as it rejects ordinary computational values that do not typecheck, as illustrated in the example above. You will thus see an error in the following code.\n-/\nnamespace Introduction.ex5\ndef p : false := true.intro\nend Introduction.ex5\n\n\n\n/-\nA formalized rendition of the famous example in which it is deduced that Socrates is mortal. You are not expected to fully understand this code at this point.\n-/\nnamespace Introduction.ex6\ndef modus_ponens\n    (α : Type)\n    (M : α → Prop)\n    (h : ∀ a : α, M a)\n    (w : α)\n    : (M w)\n    := (h w)\n\naxiom Person : Type\naxiom Mortal : Person → Prop\naxiom EveryoneIsMortal : ∀ p : Person, Mortal p\naxiom Socrates : Person\n\ntheorem aProof : Mortal Socrates :=\n    modus_ponens Person Mortal EveryoneIsMortal Socrates\nend Introduction.ex6", "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/src/2.1_logic_introduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7728188410926997}}
{"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-/\n\n/-\nimport linear_algebra.matrix.nonsingular_inverse\n\n/-!\nThis file supplements things about matrix inverse, that were missing in mathlib.\n-/\n\nnamespace matrix\nuniverses u v\nvariables {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α]\nopen_locale matrix big_operators\nopen equiv equiv.perm finset\n\nvariables (A : matrix n n α) (B : matrix n n α)\n\n/- `is_unit_of_invertible A`\n   converts the \"stronger\" condition `invertible A` to proposition `is_unit A`. -/\n\n/-- `matrix.is_unit_det_of_invertible` converts `invertible A` to `is_unit A.det`. -/\nlemma is_unit_det_of_invertible [invertible A] : is_unit A.det :=\n@is_unit_of_invertible _ _ _(det_invertible_of_invertible A)\n\n@[simp]\nlemma inv_eq_nonsing_inv_of_invertible [invertible A] : ⅟ A = A⁻¹ :=\nbegin\n  suffices : is_unit A,\n  { rw [←this.mul_left_inj, inv_of_mul_self, matrix.mul_eq_mul, nonsing_inv_mul],\n    rwa ←is_unit_iff_is_unit_det },\n  exact is_unit_of_invertible _\nend\n\nvariables {A} {B}\n\n/- `is_unit.invertible` lifts the proposition `is_unit A` to a constructive inverse of `A`. -/\n\n/-- \"Lift\" the proposition `is_unit A.det` to a constructive inverse of `A`. -/\nnoncomputable def invertible_of_is_unit_det  (h : is_unit A.det) : invertible A :=\n⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩\n\n/-- If matrix A is left invertible, then its inverse equals its left inverse. -/\nlemma inv_eq_left_inv (h : B ⬝ A = 1) : A⁻¹ = B :=\nbegin\n  have h1 :=  (is_unit_det_of_left_inverse h),\n  have h2 := matrix.invertible_of_is_unit_det h1,\n  have := @inv_of_eq_left_inv (matrix n n α) (infer_instance) A B h2 h,\n  simp* at *,\nend\n\n/-- If matrix A is right invertible, then its inverse equals its right inverse. -/\nlemma inv_eq_right_inv (h : A ⬝ B = 1) : A⁻¹ = B :=\nbegin\n  have h1 :=  (is_unit_det_of_right_inverse h),\n  have h2 := matrix.invertible_of_is_unit_det h1,\n  have := @inv_of_eq_right_inv (matrix n n α) (infer_instance) A B h2 h,\n  simp* at *,\nend\n\n/-- We can construct an instance of invertible A if A has a left inverse. -/\ndef invertible_of_left_inverse (h: B ⬝ A = 1) : invertible A :=\n⟨B, h, nonsing_inv_right_left h⟩\n\n/-- We can construct an instance of invertible A if A has a right inverse. -/\ndef invertible_of_right_inverse (h: A ⬝ B = 1) : invertible A :=\n⟨B, nonsing_inv_left_right h, h⟩\n\nvariables {C: matrix n n α}\n\n/-- The left inverse of matrix A is unique when existing. -/\nlemma left_inv_eq_left_inv (h: B ⬝ A = 1) (g: C ⬝ A = 1) : B = C :=\nby rw [←(inv_eq_left_inv h), ←(inv_eq_left_inv g)]\n\n/-- The right inverse of matrix A is unique when existing. -/\nlemma right_inv_eq_right_inv (h: A ⬝ B = 1) (g: A ⬝ C = 1) : B = C :=\nby rw [←(inv_eq_right_inv h), ←(inv_eq_right_inv g)]\n\n/-- The right inverse of matrix A equals the left inverse of A when they exist. -/\nlemma right_inv_eq_left_inv (h: A ⬝ B = 1) (g: C ⬝ A = 1) : B = C :=\nby rw [←(inv_eq_right_inv h), ←(inv_eq_left_inv g)]\n\nvariable (A)\n\n@[simp] lemma mul_inv_of_invertible [invertible A] : A ⬝ A⁻¹ = 1 :=\nmul_nonsing_inv A (is_unit_det_of_invertible A)\n\n@[simp] lemma inv_mul_of_invertible [invertible A] : A⁻¹ ⬝ A = 1 :=\nnonsing_inv_mul A (is_unit_det_of_invertible A)\n\nend matrix\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/inv_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632896242074, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7727946303558917}}
{"text": "import tactic                 \nimport data.nat.lattice       -- for well-ordering for naturals \nimport data.set.basic         -- for creating sets\n\n-- Define a set for the remainder of a/b :\n-- remainder_set takes a and b and returns set of all possible nonnegative remainders of a/b\n\ndef remainder_set : ℤ → ℤ → set ℕ := λ a, λ b, { y | (∃ x : ℤ, ((y : ℤ) = a - b * x))}\n\n-- LEMMAS\n\nlemma mem_remainder_set_iff {a b : ℤ} {k : ℕ}  : (k ∈ remainder_set a b) ↔\n  ∃ x : ℤ, (k : ℤ) = a - b * x :=\n  begin\n    split, {\n      intro h,\n      rw set.mem_def at h,\n      exact h,\n    }, {\n      intro h,\n      rw set.mem_def,\n      exact h,\n    }\n  end\n\nlemma pos_z_pos_nat { b : ℤ } (hb : b > 0 ) : (b.to_nat > 0) :=\nbegin\n  have hb2 := (le_of_lt hb),\n  rw ← (int.to_nat_of_nonneg hb2) at hb,\n  exact int.coe_nat_pos.mp hb,\nend\n\nlemma nonneg_remainder_exists { a b : ℤ } (hb : b > 0) : a + b * |a| ≥ 0 :=\nbegin\n  have ha := le_or_lt 0 a,\n  cases ha,\n  {\n    rw abs_of_nonneg ha,\n    nth_rewrite 0 ← one_mul a,\n    rw ← add_mul,\n    have hb2 : 1 + b ≥ 0 := by linarith,\n    exact mul_nonneg hb2 ha,\n  }, {\n    rw [abs_of_neg ha, (neg_mul_comm b a).symm],\n    nth_rewrite 0 ← one_mul a,\n    rw ← add_mul,\n    have hb2 : 1 + -b ≤ 0 := by linarith,\n    have ha2 : a ≤ 0 := le_of_lt ha,\n    exact mul_nonneg_of_nonpos_of_nonpos hb2 ha2,\n  },\nend\n\n\n\n\n\n\n\n\n\n\n\n\n/-       PROOF SKETCH\n\n  (1) Define remainder set, S\n      -- let S = {a - bx : x ∈ ℤ ∧ a - bx ≥ 0}\n\n  (2) Show S is nonempty\n      -- use x = -|a|, and a + b |a| ≥ 0 to show S nonempty\n\n  (3) Apply Well-ordering of naturals to show that S contains a minimum, r\n\n  (4) Show r satisfies conditions of division algorithm\n      -- show r < b, by contradiction if r - b ≥ 0 \n\n-/\n\nlemma division_algorithm (a b : ℤ) (hb : b > 0) : (∃ q r : ℤ, ((a = b * q + r) ∧ (0 ≤ r) ∧ (r < b))) :=\nbegin\n  -- (1) Define remainder set, S\n  --     let S = {a - bx : x ∈ ℤ ∧ a - bx ≥ 0} \n  -- ( remainder_set : ℤ → ℤ → set ℕ := λ a, λ b, { y | (∃ x : ℤ, ((y : ℤ) = a - b * x)) } )\n  set S := remainder_set a b,                                                                     \n  set r := has_Inf.Inf S,                                                                        \n\n  -- (2) Show S is nonempty\n  --     use x = -|a|, and a + b |a| ≥ 0 to show S nonempty\n  have hns : S.nonempty,  -- we are asserting this is true, and proving it in the brackets                                                                       \n  {\n    -- show that a + b * |a| ≥ 0 (using lemma proved above)\n    have h1 : a + b * |a| ≥ 0 := nonneg_remainder_exists hb,                                      \n    -- set k = a + b * |a| ≥ 0 (and we want k ∈ ℕ)\n    obtain ⟨k, hk⟩ := int.eq_coe_of_zero_le (h1), -- obtain = have + cases\n    -- show k ∈ S\n    have hk_mem : k ∈ S,\n      {\n        rw mem_remainder_set_iff,\n        use (-|a|),\n        linarith,\n      },\n    -- since k ∈ S, S ≠ ∅\n    exact set.nonempty_of_mem hk_mem,\n  },\n\n  -- (3) Apply Well-ordering of naturals to show that S contains a minimum, r\n  have hr : r ∈ S := Inf_mem hns,\n\n  -- (4) Show r satisfies conditions of division algorithm\n  --     show r < b, by contradiction: if r - b ≥ 0, then r - b ∈ S, so r - b ≤ r since r = Inf S.\n\n  -- use definition of r ∈ S\n  rw mem_remainder_set_iff at hr,\n  -- get x and hx from existence in hypothesis \n  cases hr with x hx,\n  -- show x and r satisfy existence in target\n  use [x, r],\n  \n  -- we need to prove both sides of conjunction (∧ is right associative)\n  split, {\n    -- r = a - b x, so a = b x + r\n    linarith,\n  }, {\n    split, {\n      -- r ∈ ℕ, so r ≥ 0\n      exact int.of_nat_nonneg r,\n    }, {\n      -- suppose r ≥ b, prove false\n      by_contra h, \n      push_neg at h,\n      rw ← int.to_nat_of_nonneg (le_of_lt hb) at h,\n      \n      -- prove that r - b ∈ S\n      have h_r_sub_b_mem : (r - b.to_nat) ∈ S,\n      { \n        rw mem_remainder_set_iff,\n        -- r = a - b x → r - b = a - b (x + 1)\n        use (x + 1),\n        -- remove coercions\n        rw [int.coe_nat_sub (int.coe_nat_le.mp h), hx, int.to_nat_of_nonneg (le_of_lt hb)],\n        linarith,\n      },\n      -- b > 0, so r - b < r\n      have h_r_sub_b_le_r : r - b.to_nat < r := (b.to_nat).sub_lt_of_pos_le r (pos_z_pos_nat hb) (int.coe_nat_le.mp h),\n      -- infimum of S is less than or equal to every member of S\n      have h_mem_ge_inf : r ≤ r - b.to_nat := nat.Inf_le h_r_sub_b_mem,\n      -- r - b < r and r ≤ r - b → false\n      exact nat.lt_le_antisymm h_r_sub_b_le_r h_mem_ge_inf,\n    },\n  },\nend\n \n--#print division_algorithm -- theorem above is one big λ function!\n\n-- EASY WAY\n-- use ℤ is an instance of Euclidean Domain\n\ntheorem division_algorithm' (a b : ℤ) (hb : b > 0) : \n(∃ q r : ℤ, ((a = b * q + r) ∧ (0 ≤ r) ∧ (r < b))) :=\nbegin\n  have h := euclidean_domain.mod_add_div a b,  -- q, r not unique for general ED \n  use [(a/b), a % b ], -- integer division and remainder : q = a/b ; r = a % b\n  exact ⟨(euclidean_domain.quotient_mul_add_remainder_eq a b).symm, int.mod_nonneg a (ne_of_gt hb), int.mod_lt_of_pos a hb,⟩,\nend\n\n\n\n\n\n\n\n\n\n\n\n\n\n-- (5) Show uniqueness \n\nlemma division_algorithm_uniqueness (a b q1 q2 r1 r2 : ℤ) (hr1 : (0 ≤ r1) ∧ (r1 < b)) (hr2 : (0 ≤ r2) ∧ (r2 < b))  (hb : b > 0) (hd1 : a = b * q1 + r1) (hd2 : a = b * q2 + r2) : (q1 = q2 ∧ r1 = r2) :=\nbegin\n    have hq : q1 = q2,\n    { \n      rw hd2 at hd1,\n      have j : b * (q2 - q1) = r1 - r2 := by linarith,\n\n      have k : -b < -r2 ∧ -r2 ≤ 0,\n      { split, { linarith, }, { linarith, },},\n\n      have l : -b < r1 - r2 ∧ r1 - r2 < b,\n      { split, { linarith,}, { linarith,},},\n\n      have m : -b < b*(q2 - q1) ∧ b*(q2 - q1) < b,\n      { split, {linarith,}, {linarith,},},\n\n      have i : -1 < q2 - q1 ∧ q2 - q1 < 1,\n      {split, {\n        cases m,\n        rw (show -b = b*(-1), by linarith) at m_left,\n        exact (mul_lt_mul_left hb).mp m_left,\n      }, {\n        cases m,\n        nth_rewrite 1 ← (mul_one b) at m_right,\n        exact (mul_lt_mul_left hb).mp m_right,\n      },},\n      linarith,\n  \n    },\n    split, {\n      assumption,\n    }, {\n      rw hq at hd1,\n      linarith,\n    },\nend\n\n", "meta": {"author": "raymondpg", "repo": "XLL", "sha": "f97237922687d0edfa3fdab4c9cb831b39284e49", "save_path": "github-repos/lean/raymondpg-XLL", "path": "github-repos/lean/raymondpg-XLL/XLL-f97237922687d0edfa3fdab4c9cb831b39284e49/src/Zachary/div_alg2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7727549858113913}}
{"text": "\ndefinition is_prime (x: ℕ): Prop\n:= 1 < x ∧ ∀ y: ℕ, y ∣ x → y = 1 ∨ y = x\n \ndefinition factorial: ℕ → ℕ\n| 0 := 1\n| (nat.succ n) := nat.succ n * factorial n\n\nlemma pos_factorial (n: ℕ):\n  factorial n > 0\n:=\nbegin\n  induction n with k ih,\n  {\n    simp [factorial],\n    exact nat.succ_pos 0,\n  },\n  {\n    simp [factorial],\n    have hskpos: nat.succ k > 0, from nat.succ_pos k,\n    have h: nat.succ k * 0 < nat.succ k * factorial k, from mul_lt_mul_of_pos_left ih hskpos,\n    rw (mul_zero (nat.succ k)) at h,\n    exact h\n  }\nend\n\nlemma factorial_division (n: ℕ):\n  ∀ m: ℕ, 1 ≤ m → m ≤ n → m ∣ factorial n\n:=\nbegin\n  intros m h1 h2,\n  induction n with k h3,\n    have le10: 1 ≤ 0 := le_trans h1 h2,\n    exact absurd le10 (nat.not_succ_le_zero 0),\n  simp [factorial],\n  cases h2 with _ hlek,\n  {\n    simp\n  },\n  {\n    apply dvd_mul_of_dvd_right,\n    exact h3 hlek\n  }\nend\n\nlemma construct_prime (n: ℕ) (h: 1 < n):\n  ∃ p: ℕ, is_prime p ∧ p ∣ n\n:=\nbegin\n  let nontriv_factor := λx, 1 < x ∧ x ∣ n,\n  have h: ∃ x: ℕ, nontriv_factor x, by {\n    existsi n,\n    split,\n    exact h,\n    simp\n  },\n  let p := nat.find h,\n  let hp := nat.find_spec h,\n  have defprev: nat.find h = p, by simp,\n  rw [defprev] at hp,\n  cases hp with hpos hdvd,\n  existsi p,\n  split,\n  {\n    simp [is_prime],\n    split,\n    {\n      exact hpos,\n    },\n    {\n      intros y hyp,\n      cases lt_trichotomy 1 y with h1lty hrest,\n      {\n        right,\n        have hpley: p ≤ y, from (nat.find_min' h) (and.intro h1lty (dvd_trans hyp hdvd)),\n        have h0ltp: 0 < p, from lt_trans zero_lt_one hpos,\n        have hylep: y ≤ p, from (nat.le_of_dvd h0ltp hyp),\n        exact le_antisymm hylep hpley\n      },\n      cases hrest with h1eqy hylt1,\n      {\n        left,\n        exact h1eqy.symm\n      },\n      {\n        exfalso,\n        have hyeq0: y = 0, by {\n          apply nat.eq_zero_of_le_zero,\n          apply nat.le_of_lt_succ,\n          exact hylt1\n        },\n        rw hyeq0 at hyp,\n        have hpeq0: p = 0, from eq_zero_of_zero_dvd hyp,\n        have h1lt0: 1 < 0, by { rw hpeq0 at hpos, exact hpos },\n        exact nat.not_lt_zero 1 h1lt0,\n      }\n    }\n  },\n  {\n    exact hdvd\n  }\nend\n\ntheorem unbouded_primes:\n  ∀ m: ℕ, ∃ p: ℕ, is_prime p ∧ m < p :=\nbegin\n  intro m,\n  let a := factorial m + 1,\n  have h1lea: 1 < a, by {\n    simp [a],\n    refine nat.lt_add_of_pos_left _,\n    exact pos_factorial m\n  },\n  have h: ∃ p: ℕ, is_prime p ∧ p ∣ a, from construct_prime a h1lea,\n  cases h with p hp,\n  cases hp with hprime hpdvda,\n  existsi p,\n  split,\n  {\n    exact hprime\n  },\n  {\n    simp [is_prime] at hprime,\n    cases lt_or_ge m p with hmltp hmgep,\n    {\n      exact hmltp,\n    }, {\n      exfalso,\n      have h1ltp: 1 < p, from hprime.left,\n      have hdvdfm: p ∣ factorial m, from factorial_division m p (le_of_lt h1ltp) hmgep,\n      have hpdvd1: p ∣ 1, by {\n        refine (nat.dvd_add_iff_right hdvdfm).mpr hpdvda,\n      },\n      have hpeq1: p = 1, from nat.eq_one_of_dvd_one hpdvd1,\n      rw hpeq1 at h1ltp,\n      exact lt_irrefl 1 h1ltp\n    }\n  }\nend\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/ukikagi/primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542875927781, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.772725570522176}}
{"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 algebra.group.pi\nimport algebra.group_power.lemmas\n\n/-!\n# The group of permutations (self-equivalences) of a type `α`\n\nThis file defines the `group` structure on `equiv.perm α`.\n-/\nuniverses u v\n\nnamespace equiv\n\nvariables {α : Type u} {β : Type v}\n\nnamespace perm\n\ninstance perm_group : group (perm α) :=\n{ mul := λ f g, equiv.trans g f,\n  one := equiv.refl α,\n  inv := equiv.symm,\n  mul_assoc := λ f g h, (trans_assoc _ _ _).symm,\n  one_mul := trans_refl,\n  mul_one := refl_trans,\n  mul_left_inv := self_trans_symm }\n\ntheorem mul_apply (f g : perm α) (x) : (f * g) x = f (g x) :=\nequiv.trans_apply _ _ _\n\ntheorem one_apply (x) : (1 : perm α) x = x := rfl\n\n@[simp] lemma inv_apply_self (f : perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x\n\n@[simp] lemma apply_inv_self (f : perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x\n\nlemma one_def : (1 : perm α) = equiv.refl α := rfl\n\nlemma mul_def (f g : perm α) : f * g = g.trans f := rfl\n\nlemma inv_def (f : perm α) : f⁻¹ = f.symm := rfl\n\n@[simp] lemma coe_mul (f g : perm α) : ⇑(f * g) = f ∘ g := rfl\n\n@[simp] lemma coe_one : ⇑(1 : perm α) = id := rfl\n\nlemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply\n\nlemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq\n\nlemma zpow_apply_comm {α : Type*} (σ : equiv.perm α) (m n : ℤ) {x : α} :\n  (σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) :=\nby rw [←equiv.perm.mul_apply, ←equiv.perm.mul_apply, zpow_mul_comm]\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] lemma trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : perm β) = e :=\nequiv.trans_refl e\n\n@[simp] lemma mul_refl (e : perm α) : e * equiv.refl α = e := equiv.trans_refl e\n\n@[simp] lemma one_symm : (1 : perm α).symm = 1 := equiv.refl_symm\n\n@[simp] lemma refl_inv : (equiv.refl α : perm α)⁻¹ = 1 := equiv.refl_symm\n\n@[simp] lemma one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : perm α).trans e = e :=\nequiv.refl_trans e\n\n@[simp] lemma refl_mul (e : perm α) : equiv.refl α * e = e := equiv.refl_trans e\n\n@[simp] lemma inv_trans_self (e : perm α) : e⁻¹.trans e = 1 := equiv.symm_trans_self e\n\n@[simp] lemma mul_symm (e : perm α) : e * e.symm = 1 := equiv.symm_trans_self e\n\n@[simp] lemma self_trans_inv (e : perm α) : e.trans e⁻¹ = 1 := equiv.self_trans_symm e\n\n@[simp] lemma symm_mul (e : perm α) : e.symm * e = 1 := equiv.self_trans_symm e\n\n/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/\n\n@[simp] lemma sum_congr_mul {α β : Type*} (e : perm α) (f : perm β) (g : perm α) (h : perm β) :\n  sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=\nsum_congr_trans g h e f\n\n@[simp] lemma sum_congr_inv {α β : Type*} (e : perm α) (f : perm β) :\n  (sum_congr e f)⁻¹ = sum_congr e⁻¹ f⁻¹ :=\nsum_congr_symm e f\n\n@[simp] lemma sum_congr_one {α β : Type*} :\n  sum_congr (1 : perm α) (1 : perm β) = 1 :=\nsum_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 `α` and `β`. -/\n@[simps]\ndef sum_congr_hom (α β : Type*) :\n  perm α × perm β →* perm (α ⊕ β) :=\n{ to_fun := λ a, sum_congr a.1 a.2,\n  map_one' := sum_congr_one,\n  map_mul' := λ a b, (sum_congr_mul _ _ _ _).symm}\n\nlemma sum_congr_hom_injective {α β : Type*} :\n  function.injective (sum_congr_hom α β) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ h,\n  rw prod.mk.inj_iff,\n  split; ext i,\n  { simpa using equiv.congr_fun h (sum.inl i), },\n  { simpa using equiv.congr_fun h (sum.inr i), },\nend\n\n@[simp] lemma sum_congr_swap_one {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : α) :\n  sum_congr (equiv.swap i j) (1 : perm β) = equiv.swap (sum.inl i) (sum.inl j) :=\nsum_congr_swap_refl i j\n\n@[simp] lemma sum_congr_one_swap {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : β) :\n  sum_congr (1 : perm α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=\nsum_congr_refl_swap i j\n\n/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/\n\n@[simp] lemma sigma_congr_right_mul {α : Type*} {β : α → Type*}\n  (F : Π a, perm (β a)) (G : Π a, perm (β a)) :\n  sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=\nsigma_congr_right_trans G F\n\n@[simp] lemma sigma_congr_right_inv {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) :\n  (sigma_congr_right F)⁻¹ = sigma_congr_right (λ a, (F a)⁻¹) :=\nsigma_congr_right_symm F\n\n@[simp] lemma sigma_congr_right_one {α : Type*} {β : α → Type*} :\n  (sigma_congr_right (1 : Π a, equiv.perm $ β a)) = 1 :=\nsigma_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. -/\n@[simps]\ndef sigma_congr_right_hom {α : Type*} (β : α → Type*) :\n  (Π a, perm (β a)) →* perm (Σ a, β a) :=\n{ to_fun := sigma_congr_right,\n  map_one' := sigma_congr_right_one,\n  map_mul' := λ a b, (sigma_congr_right_mul _ _).symm }\n\nlemma sigma_congr_right_hom_injective {α : Type*} {β : α → Type*} :\n  function.injective (sigma_congr_right_hom β) :=\nbegin\n  intros x y h,\n  ext a b,\n  simpa using equiv.congr_fun h ⟨a, b⟩,\nend\n\n/-- `equiv.perm.subtype_congr` as a `monoid_hom`. -/\n@[simps] def subtype_congr_hom (p : α → Prop) [decidable_pred p] :\n  (perm {a // p a}) × (perm {a // ¬ p a}) →* perm α :=\n{ to_fun := λ pair, perm.subtype_congr pair.fst pair.snd,\n  map_one' := perm.subtype_congr.refl,\n  map_mul' := λ _ _, (perm.subtype_congr.trans _ _ _ _).symm }\n\nlemma subtype_congr_hom_injective (p : α → Prop) [decidable_pred p] :\n  function.injective (subtype_congr_hom p) :=\nbegin\n  rintros ⟨⟩ ⟨⟩ h,\n  rw prod.mk.inj_iff,\n  split;\n  ext i;\n  simpa using equiv.congr_fun h i\nend\n\n/-- If `e` is also a permutation, we can write `perm_congr`\ncompletely in terms of the group structure. -/\n@[simp] lemma perm_congr_eq_mul (e p : perm α) :\n  e.perm_congr p = e * p * e⁻¹ := rfl\n\nsection extend_domain\n\n/-! Lemmas about `equiv.perm.extend_domain` re-expressed via the group structure. -/\n\nvariables (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p)\n\n@[simp] lemma extend_domain_one : extend_domain 1 f = 1 :=\nextend_domain_refl f\n\n@[simp] lemma extend_domain_inv : (e.extend_domain f)⁻¹ = e⁻¹.extend_domain f := rfl\n\n@[simp] lemma extend_domain_mul (e e' : perm α) :\n  (e.extend_domain f) * (e'.extend_domain f) = (e * e').extend_domain f :=\nextend_domain_trans _ _ _\n\n/-- `extend_domain` as a group homomorphism -/\n@[simps] def extend_domain_hom : perm α →* perm β :=\n{ to_fun := λ e, extend_domain e f,\n  map_one' := extend_domain_one f,\n  map_mul' := λ e e', (extend_domain_mul f e e').symm }\n\nlemma extend_domain_hom_injective : function.injective (extend_domain_hom f) :=\n((extend_domain_hom f).injective_iff).mpr (λ e he, ext (λ x, f.injective (subtype.ext\n  ((extend_domain_apply_image e f x).symm.trans (ext_iff.mp he (f x))))))\n\n@[simp] \n\nend extend_domain\n\n/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation\n  on `{x // p x}` induced by `f`. -/\ndef subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} :=\n⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩,\n  λ _, by simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk],\n  λ _, by simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk]⟩\n\n@[simp] lemma subtype_perm_apply (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x))\n  (x : {x // p x}) : subtype_perm f h x = ⟨f x, (h _).1 x.2⟩ := rfl\n\n@[simp] lemma subtype_perm_one (p : α → Prop) (h : ∀ x, p x ↔ p ((1 : perm α) x)) :\n  @subtype_perm α 1 p h = 1 :=\nequiv.ext $ λ ⟨_, _⟩, rfl\n\n/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,\n  fixing the other points. -/\ndef of_subtype {p : α → Prop} [decidable_pred p] : perm (subtype p) →* perm α :=\n{ to_fun := λ f,\n  ⟨λ x, if h : p x then f ⟨x, h⟩ else x, λ x, if h : p x then f⁻¹ ⟨x, h⟩ else x,\n  λ x, have h : ∀ h : p x, p (f ⟨x, h⟩), from λ h, (f ⟨x, h⟩).2,\n    by { simp only [], split_ifs at *;\n         simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk, not_true, *] at * },\n  λ x, have h : ∀ h : p x, p (f⁻¹ ⟨x, h⟩), from λ h, (f⁻¹ ⟨x, h⟩).2,\n    by { simp only [], split_ifs at *;\n         simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk, not_true, *] at * }⟩,\n  map_one' := begin ext, dsimp, split_ifs; refl, end,\n  map_mul' := λ f g, equiv.ext $ λ x, begin\n  by_cases h : p x,\n  { have h₁ : p (f (g ⟨x, h⟩)), from (f (g ⟨x, h⟩)).2,\n    have h₂ : p (g ⟨x, h⟩), from (g ⟨x, h⟩).2,\n    simp only [h, h₂, coe_fn_mk, perm.mul_apply, dif_pos, subtype.coe_eta] },\n  { simp only [h, coe_fn_mk, perm.mul_apply, dif_neg, not_false_iff] }\nend }\n\nlemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p]\n  (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) :\n  of_subtype (subtype_perm f h₁) = f :=\nequiv.ext $ λ x, begin\n  rw [of_subtype, subtype_perm],\n  by_cases hx : p x,\n  { simp only [hx, coe_fn_mk, dif_pos, monoid_hom.coe_mk, subtype.coe_mk]},\n  { haveI := classical.prop_decidable,\n    simp only [hx, not_not.mp (mt (h₂ x) hx), coe_fn_mk, dif_neg, not_false_iff,\n      monoid_hom.coe_mk] }\nend\n\nlemma of_subtype_apply_of_mem {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) {x : α} (hx : p x) :\n  of_subtype f x = f ⟨x, hx⟩ :=\ndif_pos hx\n\n@[simp] lemma of_subtype_apply_coe {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) (x : subtype p)  :\n  of_subtype f x = f x :=\nsubtype.cases_on x $ λ _, of_subtype_apply_of_mem f\n\nlemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) {x : α} (hx : ¬ p x) :\n  of_subtype f x = x :=\ndif_neg hx\n\nlemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p]\n  (f : perm (subtype p)) (x : α) :\n  p x ↔ p ((of_subtype f : α → α) x) :=\nif h : p x then by simpa only [of_subtype, h, coe_fn_mk, dif_pos, true_iff, monoid_hom.coe_mk]\n  using (f ⟨x, h⟩).2\nelse by simp [h, of_subtype_apply_of_not_mem f h]\n\n@[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) :\n  subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f :=\nequiv.ext $ λ ⟨x, hx⟩, by { dsimp [subtype_perm, of_subtype],\n  simp only [show p x, from hx, dif_pos, subtype.coe_eta] }\n\n@[simp] lemma default_perm {n : Type*} : default (equiv.perm n) = 1 := rfl\n\n/-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise\nthe rest. -/\n@[simps] protected def subtype_equiv_subtype_perm (p : α → Prop) [decidable_pred p] :\n  perm (subtype p) ≃ {f : perm α // ∀ a, ¬p a → f a = a} :=\n{ to_fun := λ f, ⟨f.of_subtype, λ a, f.of_subtype_apply_of_not_mem⟩,\n  inv_fun := λ f, (f : perm α).subtype_perm\n    (λ a, ⟨decidable.not_imp_not.1 $ λ hfa, (f.val.injective (f.prop _ hfa) ▸ hfa),\n    decidable.not_imp_not.1 $ λ ha hfa, ha $ f.prop a ha ▸ hfa⟩),\n  left_inv := equiv.perm.subtype_perm_of_subtype,\n  right_inv := λ f,\n    subtype.ext (equiv.perm.of_subtype_subtype_perm _ $ λ a, not.decidable_imp_symm $ f.prop a) }\n\nlemma subtype_equiv_subtype_perm_apply_of_mem {α : Type*} {p : α → Prop}\n  [decidable_pred p] (f : perm (subtype p)) {a : α} (h : p a) :\n  perm.subtype_equiv_subtype_perm p f a = f ⟨a, h⟩ :=\nf.of_subtype_apply_of_mem h\n\nlemma subtype_equiv_subtype_perm_apply_of_not_mem {α : Type*} {p : α → Prop}\n  [decidable_pred p] (f : perm (subtype p)) {a : α} (h : ¬ p a) :\n  perm.subtype_equiv_subtype_perm p f a = a :=\nf.of_subtype_apply_of_not_mem h\n\nvariables (e : perm α) (ι : α ↪ β)\n\nopen_locale classical\n\n/-- Noncomputable version of `equiv.perm.via_fintype_embedding` that does not assume `fintype` -/\nnoncomputable def via_embedding : perm β :=\nextend_domain e (of_injective ι.1 ι.2)\n\nlemma via_embedding_apply (x : α) : e.via_embedding ι (ι x) = ι (e x) :=\nextend_domain_apply_image e (of_injective ι.1 ι.2) x\n\nlemma via_embedding_apply_of_not_mem (x : β) (hx : x ∉ _root_.set.range ι) :\n  e.via_embedding ι x = x :=\nextend_domain_apply_not_subtype e (of_injective ι.1 ι.2) hx\n\n/-- `via_embedding` as a group homomorphism -/\nnoncomputable def via_embedding_hom : perm α →* perm β:=\nextend_domain_hom (of_injective ι.1 ι.2)\n\nlemma via_embedding_hom_apply : via_embedding_hom ι e = via_embedding e ι := rfl\n\nlemma via_embedding_hom_injective : function.injective (via_embedding_hom ι) :=\nextend_domain_hom_injective (of_injective ι.1 ι.2)\n\nend perm\n\nsection swap\nvariables [decidable_eq α]\n\n@[simp] lemma swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl\n\n@[simp] lemma swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j\n\nlemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=\nequiv.ext $ λ z, begin\n  simp only [perm.mul_apply, swap_apply_def],\n  split_ifs;\n  simp only [perm.apply_inv_self, *, perm.eq_inv_iff_eq, eq_self_iff_true, not_true] at *\nend\n\nlemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f :=\nby rw [swap_mul_eq_mul_swap, perm.inv_apply_self, perm.inv_apply_self]\n\nlemma swap_apply_apply (f : perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ :=\nby rw [mul_swap_eq_swap_mul, mul_inv_cancel_right]\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]\nlemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ :=\nby rw [←mul_assoc, swap_mul_self, one_mul]\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]\nlemma mul_swap_mul_self (i j : α) (σ : perm α) : (σ * equiv.swap i j) * equiv.swap i j = σ :=\nby rw [mul_assoc, swap_mul_self, mul_one]\n\n/-- A stronger version of `mul_right_injective` -/\n@[simp]\nlemma swap_mul_involutive (i j : α) : function.involutive ((*) (equiv.swap i j)) :=\nswap_mul_self_mul i j\n\n/-- A stronger version of `mul_left_injective` -/\n@[simp]\nlemma mul_swap_involutive (i j : α) : function.involutive (* (equiv.swap i j)) :=\nmul_swap_mul_self i j\n\n@[simp] lemma swap_eq_one_iff {i j : α} : swap i j = (1 : perm α) ↔ i = j :=\nswap_eq_refl_iff\n\nlemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j :=\n⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm),\n  by {rw [←swap_apply_right i j, swap_id], refl}),\n(assume h, by erw [h, swap_self, one_mul])⟩\n\nlemma mul_swap_eq_iff {i j : α} {σ : perm α} : σ * swap i j = σ ↔ i = j :=\n⟨(assume h, have swap_id : swap i j = 1 := mul_left_cancel (trans h (one_mul σ).symm),\n  by {rw [←swap_apply_right i j, swap_id], refl}),\n(assume h, by erw [h, swap_self, mul_one])⟩\n\nlemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) :\n  swap y z * swap x y * swap y z = swap z x :=\nequiv.ext $ λ n, by { simp only [swap_apply_def, perm.mul_apply], split_ifs; cc }\n\nend swap\n\nend equiv\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8740772482857833, "lm_q1q2_score": 0.7727186254355503}}
{"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 data.list.intervals\n! leanprover-community/mathlib commit b71077179fac7179e3a342ff319392ad8dcb773c\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.Lattice\nimport Mathbin.Data.List.Range\n\n/-!\n# Intervals in ℕ\n\nThis file defines intervals of naturals. `list.Ico m n` is the list of integers greater than `m`\nand strictly less than `n`.\n\n## TODO\n- Define `Ioo` and `Icc`, state basic lemmas about them.\n- Also do the versions for integers?\n- One could generalise even further, defining 'locally finite partial orders', for which\n  `set.Ico a b` is `[finite]`, and 'locally finite total orders', for which there is a list model.\n- Once the above is done, get rid of `data.int.range` (and maybe `list.range'`?).\n-/\n\n\nopen Nat\n\nnamespace List\n\n/-- `Ico n m` is the list of natural numbers `n ≤ 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 ≤ x < m` as a multiset or as a finset.\n -/\ndef ico (n m : ℕ) : List ℕ :=\n  range' n (m - n)\n#align list.Ico List.ico\n\nnamespace Ico\n\ntheorem zero_bot (n : ℕ) : ico 0 n = range n := by rw [Ico, tsub_zero, range_eq_range']\n#align list.Ico.zero_bot List.ico.zero_bot\n\n@[simp]\ntheorem length (n m : ℕ) : length (ico n m) = m - n :=\n  by\n  dsimp [Ico]\n  simp only [length_range']\n#align list.Ico.length List.ico.length\n\ntheorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (ico n m) :=\n  by\n  dsimp [Ico]\n  simp only [pairwise_lt_range']\n#align list.Ico.pairwise_lt List.ico.pairwise_lt\n\ntheorem nodup (n m : ℕ) : Nodup (ico n m) :=\n  by\n  dsimp [Ico]\n  simp only [nodup_range']\n#align list.Ico.nodup List.ico.nodup\n\n@[simp]\ntheorem mem {n m l : ℕ} : l ∈ ico n m ↔ n ≤ l ∧ l < m :=\n  by\n  suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this]\n  cases' le_total n m with hnm hmn\n  · rw [add_tsub_cancel_of_le hnm]\n  · rw [tsub_eq_zero_iff_le.mpr hmn, add_zero]\n    exact\n      and_congr_right fun hnl =>\n        Iff.intro (fun hln => (not_le_of_gt hln hnl).elim) fun hlm => lt_of_lt_of_le hlm hmn\n#align list.Ico.mem List.ico.mem\n\ntheorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : ico n m = [] := by\n  simp [Ico, tsub_eq_zero_iff_le.mpr h]\n#align list.Ico.eq_nil_of_le List.ico.eq_nil_of_le\n\ntheorem map_add (n m k : ℕ) : (ico n m).map ((· + ·) k) = ico (n + k) (m + k) := by\n  rw [Ico, Ico, map_add_range', add_tsub_add_eq_tsub_right, add_comm n k]\n#align list.Ico.map_add List.ico.map_add\n\ntheorem map_sub (n m k : ℕ) (h₁ : k ≤ n) : ((ico n m).map fun x => x - k) = ico (n - k) (m - k) :=\n  by rw [Ico, Ico, tsub_tsub_tsub_cancel_right h₁, map_sub_range' _ _ _ h₁]\n#align list.Ico.map_sub List.ico.map_sub\n\n@[simp]\ntheorem self_empty {n : ℕ} : ico n n = [] :=\n  eq_nil_of_le (le_refl n)\n#align list.Ico.self_empty List.ico.self_empty\n\n@[simp]\ntheorem eq_empty_iff {n m : ℕ} : ico n m = [] ↔ m ≤ n :=\n  Iff.intro (fun h => tsub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le\n#align list.Ico.eq_empty_iff List.ico.eq_empty_iff\n\ntheorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) : ico n m ++ ico m l = ico n l :=\n  by\n  dsimp only [Ico]\n  convert range'_append _ _ _\n  · exact (add_tsub_cancel_of_le hnm).symm\n  · rwa [← add_tsub_assoc_of_le hnm, tsub_add_cancel_of_le]\n#align list.Ico.append_consecutive List.ico.append_consecutive\n\n@[simp]\ntheorem inter_consecutive (n m l : ℕ) : ico n m ∩ ico m l = [] :=\n  by\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  intro h₁ h₂ h₃\n  exfalso\n  exact not_lt_of_ge h₃ h₂\n#align list.Ico.inter_consecutive List.ico.inter_consecutive\n\n@[simp]\ntheorem bagInter_consecutive (n m l : ℕ) : List.bagInter (ico n m) (ico m l) = [] :=\n  (bagInter_nil_iff_inter_nil _ _).2 (inter_consecutive n m l)\n#align list.Ico.bag_inter_consecutive List.ico.bagInterₓ_consecutive\n\n@[simp]\ntheorem succ_singleton {n : ℕ} : ico n (n + 1) = [n] :=\n  by\n  dsimp [Ico]\n  simp [add_tsub_cancel_left]\n#align list.Ico.succ_singleton List.ico.succ_singleton\n\ntheorem succ_top {n m : ℕ} (h : n ≤ m) : ico n (m + 1) = ico n m ++ [m] :=\n  by\n  rwa [← succ_singleton, append_consecutive]\n  exact Nat.le_succ _\n#align list.Ico.succ_top List.ico.succ_top\n\ntheorem eq_cons {n m : ℕ} (h : n < m) : ico n m = n :: ico (n + 1) m :=\n  by\n  rw [← append_consecutive (Nat.le_succ n) h, succ_singleton]\n  rfl\n#align list.Ico.eq_cons List.ico.eq_cons\n\n@[simp]\ntheorem pred_singleton {m : ℕ} (h : 0 < m) : ico (m - 1) m = [m - 1] :=\n  by\n  dsimp [Ico]\n  rw [tsub_tsub_cancel_of_le (succ_le_of_lt h)]\n  simp\n#align list.Ico.pred_singleton List.ico.pred_singleton\n\ntheorem chain'_succ (n m : ℕ) : Chain' (fun a b => b = succ a) (ico n m) :=\n  by\n  by_cases n < m\n  · rw [eq_cons h]\n    exact chain_succ_range' _ _\n  · rw [eq_nil_of_le (le_of_not_gt h)]\n    trivial\n#align list.Ico.chain'_succ List.ico.chain'_succ\n\n@[simp]\ntheorem not_mem_top {n m : ℕ} : m ∉ ico n m := by simp\n#align list.Ico.not_mem_top List.ico.not_mem_top\n\ntheorem filter_lt_of_top_le {n m l : ℕ} (hml : m ≤ l) :\n    ((ico n m).filterₓ fun x => x < l) = ico n m :=\n  filter_eq_self.2 fun k hk => lt_of_lt_of_le (mem.1 hk).2 hml\n#align list.Ico.filter_lt_of_top_le List.ico.filterₓ_lt_of_top_le\n\ntheorem filter_lt_of_le_bot {n m l : ℕ} (hln : l ≤ n) : ((ico n m).filterₓ fun x => x < l) = [] :=\n  filter_eq_nil.2 fun k hk => not_lt_of_le <| le_trans hln <| (mem.1 hk).1\n#align list.Ico.filter_lt_of_le_bot List.ico.filterₓ_lt_of_le_bot\n\ntheorem filter_lt_of_ge {n m l : ℕ} (hlm : l ≤ m) : ((ico n m).filterₓ fun x => x < l) = ico n l :=\n  by\n  cases' le_total n l with hnl hln\n  ·\n    rw [← append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l),\n      filter_lt_of_le_bot (le_refl l), append_nil]\n  · rw [eq_nil_of_le hln, filter_lt_of_le_bot hln]\n#align list.Ico.filter_lt_of_ge List.ico.filterₓ_lt_of_ge\n\n@[simp]\ntheorem filter_lt (n m l : ℕ) : ((ico n m).filterₓ fun x => x < l) = ico n (min m l) :=\n  by\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]\n#align list.Ico.filter_lt List.ico.filterₓ_lt\n\ntheorem filter_le_of_le_bot {n m l : ℕ} (hln : l ≤ n) :\n    ((ico n m).filterₓ fun x => l ≤ x) = ico n m :=\n  filter_eq_self.2 fun k hk => le_trans hln (mem.1 hk).1\n#align list.Ico.filter_le_of_le_bot List.ico.filterₓ_le_of_le_bot\n\ntheorem filter_le_of_top_le {n m l : ℕ} (hml : m ≤ l) : ((ico n m).filterₓ fun x => l ≤ x) = [] :=\n  filter_eq_nil.2 fun k hk => not_le_of_gt (lt_of_lt_of_le (mem.1 hk).2 hml)\n#align list.Ico.filter_le_of_top_le List.ico.filterₓ_le_of_top_le\n\ntheorem filter_le_of_le {n m l : ℕ} (hnl : n ≤ l) : ((ico n m).filterₓ fun x => l ≤ x) = ico l m :=\n  by\n  cases' le_total l m with hlm hml\n  ·\n    rw [← append_consecutive hnl hlm, filter_append, filter_le_of_top_le (le_refl l),\n      filter_le_of_le_bot (le_refl l), nil_append]\n  · rw [eq_nil_of_le hml, filter_le_of_top_le hml]\n#align list.Ico.filter_le_of_le List.ico.filterₓ_le_of_le\n\n@[simp]\ntheorem filter_le (n m l : ℕ) : ((ico n m).filterₓ fun x => l ≤ x) = ico (max n l) m :=\n  by\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]\n#align list.Ico.filter_le List.ico.filterₓ_le\n\ntheorem filter_lt_of_succ_bot {n m : ℕ} (hnm : n < m) :\n    ((ico n m).filterₓ fun x => x < n + 1) = [n] :=\n  by\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]\n#align list.Ico.filter_lt_of_succ_bot List.ico.filterₓ_lt_of_succ_bot\n\n@[simp]\ntheorem filter_le_of_bot {n m : ℕ} (hnm : n < m) : ((ico n m).filterₓ fun x => x ≤ n) = [n] :=\n  by\n  rw [← filter_lt_of_succ_bot hnm]\n  exact filter_congr' fun _ _ => lt_succ_iff.symm\n#align list.Ico.filter_le_of_bot List.ico.filterₓ_le_of_bot\n\n/-- For any natural numbers n, a, and b, one of the following holds:\n1. n < a\n2. n ≥ b\n3. n ∈ Ico a b\n-/\ntheorem trichotomy (n a b : ℕ) : n < a ∨ b ≤ n ∨ n ∈ ico a b :=\n  by\n  by_cases h₁ : n < a\n  · left\n    exact h₁\n  · right\n    by_cases h₂ : n ∈ Ico a b\n    · right\n      exact h₂\n    · left\n      simp only [Ico.mem, not_and, not_lt] at *\n      exact h₂ h₁\n#align list.Ico.trichotomy List.ico.trichotomy\n\nend Ico\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/Intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8840392893839085, "lm_q1q2_score": 0.7727186120420984}}
{"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 data.fintype.card\nimport dynamics.fixed_points.basic\n\n/-!\n# Formalization of IMO 1987, Q1\n\nLet $p_{n, k}$ be the number of permutations of a set of cardinality `n ≥ 1` that fix exactly `k`\nelements. Prove that $∑_{k=0}^n k p_{n,k}=n!$.\n\nTo prove this identity, we show that both sides are equal to the cardinality of the set\n`{(x : α, σ : perm α) | σ x = x}`, regrouping by `card (fixed_points σ)` for the left hand side and\nby `x` for the right hand side.\n\nThe original problem assumes `n ≥ 1`. It turns out that a version with `n * (n - 1)!` in the RHS\nholds true for `n = 0` as well, so we first prove it, then deduce the original version in the case\n`n ≥ 1`. -/\n\nvariables (α : Type*) [fintype α] [decidable_eq α]\n\nopen_locale big_operators nat\nopen equiv fintype function finset (range sum_const) set (Iic)\n\nnamespace imo_1987_q1\n\n/-- The set of pairs `(x : α, σ : perm α)` such that `σ x = x` is equivalent to the set of pairs\n`(x : α, σ : perm {x}ᶜ)`. -/\ndef fixed_points_equiv :\n  {σx : α × perm α | σx.2 σx.1 = σx.1} ≃ Σ x : α, perm ({x}ᶜ : set α) :=\ncalc {σx : α × perm α | σx.2 σx.1 = σx.1} ≃ Σ x : α, {σ : perm α | σ x = x} : set_prod_equiv_sigma _\n... ≃ Σ x : α, {σ : perm α | ∀ y : ({x} : set α), σ y = equiv.refl ↥({x} : set α) y} :\n  sigma_congr_right (λ x, equiv.set.of_eq $ by { simp only [set_coe.forall], dsimp, simp })\n... ≃ Σ x : α, perm ({x}ᶜ : set α) :\n  sigma_congr_right (λ x, by apply equiv.set.compl)\n\ntheorem card_fixed_points :\n  card {σx : α × perm α | σx.2 σx.1 = σx.1} = card α * (card α - 1)! :=\nby simp [card_congr (fixed_points_equiv α), card_perm, finset.filter_not, finset.card_sdiff,\n  finset.filter_eq', finset.card_univ]\n\n/-- Given `α : Type*` and `k : ℕ`, `fiber α k` is the set of permutations of `α` with exactly `k`\nfixed points. -/\n@[derive fintype]\ndef fiber (k : ℕ) : set (perm α) := {σ : perm α | card (fixed_points σ) = k}\n\n@[simp] lemma mem_fiber {σ : perm α} {k : ℕ} : σ ∈ fiber α k ↔ card (fixed_points σ) = k := iff.rfl\n\n/-- `p α k` is the number of permutations of `α` with exactly `k` fixed points. -/\ndef p (k : ℕ) := card (fiber α k)\n\n/-- The set of triples `(k ≤ card α, σ ∈ fiber α k, x ∈ fixed_points σ)` is equivalent\nto the set of pairs `(x : α, σ : perm α)` such that `σ x = x`. The equivalence sends\n`(k, σ, x)` to `(x, σ)` and `(x, σ)` to `(card (fixed_points σ), σ, x)`.\n\nIt is easy to see that the cardinality of the LHS is given by\n`∑ k : fin (card α + 1), k * p α k`. -/\ndef fixed_points_equiv' :\n  (Σ (k : fin (card α + 1)) (σ : fiber α k), fixed_points σ.1) ≃\n    {σx : α × perm α | σx.2 σx.1 = σx.1} :=\n{ to_fun := λ p, ⟨⟨p.2.2, p.2.1⟩, p.2.2.2⟩,\n  inv_fun := λ p,\n    ⟨⟨card (fixed_points p.1.2), (card_subtype_le _).trans_lt (nat.lt_succ_self _)⟩,\n     ⟨p.1.2, rfl⟩, ⟨p.1.1, p.2⟩⟩,\n  left_inv := λ ⟨⟨k, hk⟩, ⟨σ, hσ⟩, ⟨x, hx⟩⟩, by { simp only [mem_fiber, subtype.coe_mk] at hσ,\n    subst k, refl },\n  right_inv := λ ⟨⟨x, σ⟩, h⟩, rfl }\n\n/-- Main statement for any `(α : Type*) [fintype α]`. -/\ntheorem main_fintype :\n  ∑ k in range (card α + 1), k * p α k = card α * (card α - 1)! :=\nhave A : ∀ k (σ : fiber α k), card (fixed_points ⇑(↑σ : perm α)) = k := λ k σ, σ.2,\nby simpa [A, ← fin.sum_univ_eq_sum_range, -card_of_finset, finset.card_univ,\n  card_fixed_points, mul_comm] using card_congr (fixed_points_equiv' α)\n\n/-- Main statement for permutations of `fin n`, a version that works for `n = 0`. -/\ntheorem main₀ (n : ℕ) :\n  ∑ k in range (n + 1), k * p (fin n) k = n * (n - 1)! :=\nby simpa using main_fintype (fin n)\n\n/-- Main statement for permutations of `fin n`. -/\ntheorem main {n : ℕ} (hn : 1 ≤ n) :\n  ∑ k in range (n + 1), k * p (fin n) k = n! :=\nby rw [main₀, nat.mul_factorial_pred (zero_lt_one.trans_le hn)]\n\nend imo_1987_q1\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/imo1987_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.874077230244524, "lm_q1q2_score": 0.7727186041454938}}
{"text": "import .lemmas\n\nnamespace nat\n\n-- Bit Width of Naturals\n\ndef width : nat -> nat\n| n := \n  if h : n > 1 then \n    have n.div2 < n,\n      from div2_lt_self (lt.trans zero_lt_one h),\n    succ (width n.div2)\n  else\n    1\n\n-- Basic Width Theorems\n\ntheorem width_zero : width 0 = 1 := rfl\ntheorem width_one : width 1 = 1 := rfl\ntheorem width_le1 {n : nat} (n_le1 : n <= 1) : width n = 1 \n:= begin\n  cases n, refl,\n  cases n, refl,\n  exact absurd n_le1 (not_succ_succ_le_one n)\nend\n\ntheorem width_gt1 {n : nat} (n_gt1 : n > 1) : n.width = n.div2.width.succ \n:= by rw [width, if_pos n_gt1]\n\nlemma width_succ_succ (n : nat) : \nn.succ.succ.width = n.succ.succ.div2.width.succ \n:= width_gt1 (one_lt_succ_succ n)\n\nlemma width_two : width 2 = 2 := \nby rw [width_gt1 one_lt_two, div2_two, width_one]\n\nlemma width_three : width 3 = 2 :=\nby rw [width_gt1 (one_lt_succ_succ 1), div2_succ_succ, div2_one, width_one]\n\n\ntheorem width_pos {n : nat} : n.width > 0\n:= begin\n  cases n,\n  rw [width_zero], \n  exact nat.zero_lt_one,\n  cases n,\n  rw [width_one], \n  exact nat.zero_lt_one,\n  rw [width_succ_succ n],\n  exact (nat.zero_lt_succ _)\nend\n\nlemma zero_lt_width (n : nat) : n.width > 0 := width_pos\n\n--- Complex Width Theorems\n\ntheorem width_div2 {n : nat} (n_gt1 : n > 1): \nn.div2.width = n.width.pred  \n:= by rw [width_gt1 n_gt1, pred_succ]\n\nlemma width_div2_succ_succ (n : nat) : \nn.succ.succ.div2.width = n.succ.succ.width.pred  \n:= width_div2 (one_lt_succ_succ n)\n\ntheorem width_mul2 {n : nat} (n_pos : n > 0): \nwidth (2 * n) = n.width.succ\n:= begin\n  cases n,\n  exact absurd n_pos (not_lt_zero 0),\n  rw [mul_succ 2 n, add_two],\n  rw [width_succ_succ (2 * n)],\n  rw [div2_succ_succ, div2_mul2],\nend\n\nlemma width_mul2_succ (n : nat): \nwidth (2 * n.succ) = n.succ.width.succ\n:= width_mul2 (zero_lt_succ n)\n\ntheorem width_mul2_add_one (n : nat) (n_pos : n > 0): \nwidth (2 * n + 1) = n.width.succ\n:= begin\n  cases n, exact absurd n_pos (not_lt_zero 0),\n  rw [width_gt1 (one_lt_succ_of_pos (mul_pos two_pos n_pos))],\n  rw [div2_succ_mul2],\nend\n\ntheorem width_pow2 (n : nat): \nwidth (2 ^ n) = n.succ\n:= begin\n  induction n, refl,\n  rw [pow_succ, nat.mul_comm],\n  rw [width_mul2 pow2_pos, n_ih],\nend\n\ntheorem width_pow2_add {n : nat}: \nforall {m : nat}, m < 2 ^ n -> width (2 ^ n + m) = n.succ\n:= begin\n  induction n,\n  rw [pow_zero],\n  intro m, assume h,\n  cases m, refl,\n  exact absurd h (not_succ_lt_one _),\n  intro m, assume h,\n  rw [width_gt1 (one_lt_pow2_succ_add_right _ m)],\n  rw [div2_val, pow_succ_add_div _ _ two_pos],\n  have h' := div_lt_of_lt_pow_succ two_pos h,\n  rw [n_ih h'],\nend\n\ntheorem width_pow2_sub_one (n : nat) (n_pos : n > 0): \nwidth (2 ^ n - 1) = n\n:= begin\n  cases n, exact absurd n_pos (not_lt_zero 0),\n  induction n, transitivity width 1, refl, exact width_one,\n  rw [width_gt1 (one_lt_pow2_sub_one (one_lt_succ_succ n_n))],\n  rw [div2_pow2_succ_sub_one (succ n_n)],\n  rw [n_ih (zero_lt_succ n_n)],\nend\n\ntheorem lt_pow2_of_width (n : nat): n < 2 ^ (width n)\n:= begin\n  apply nat.strong_induction_on n,\n  intro n_n, assume n_ih,\n  cases n_n, \n  rw [width_zero, pow_one],\n  exact zero_lt_two,\n  cases n_n,\n  rw [width_one, pow_one],\n  exact one_lt_two,\n  rw [width_succ_succ],\n  rw [pow_succ, div2_val],\n  apply (div_lt_iff_lt_mul n_n.succ.succ _ two_pos).mp,\n  apply n_ih (n_n.succ.succ / 2),\n  exact (div_lt_self (zero_lt_succ n_n.succ) one_lt_two),\nend\n\ntheorem lt_pow2_max_width_right (n x : nat): n < 2 ^ max x (width n) \n:= begin\n  apply nat.lt_of_lt_of_le,\n  exact lt_pow2_of_width n,\n  apply pow_le_pow_of_le_right two_pos,\n  exact le_max_right _ _,\nend\n\nend nat", "meta": {"author": "tydeu", "repo": "cantor", "sha": "e804bc2a436f296233431c6320e3dd7a40ce6a27", "save_path": "github-repos/lean/tydeu-cantor", "path": "github-repos/lean/tydeu-cantor/cantor-e804bc2a436f296233431c6320e3dd7a40ce6a27/src/nat/width.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7726946191185303}}
{"text": "/-\n  Exercise 1.\n    Prove the following identities, replacing the “sorry” placeholders with actual proofs.\n-/\n\nvariables p q r : Prop\n\n-- commutativity of ∧ and ∨\n\ntheorem and_com {p q : Prop} : p ∧ q ↔ q ∧ p := \niff.intro\n  (assume h : p ∧ q,\n    show q ∧ p, from ⟨ h.right, h.left ⟩)\n  (assume h : q ∧ p,\n    show p ∧ q, from ⟨ h.right, h.left ⟩)\n  \ntheorem or_com {p q : Prop} : p ∨ q ↔ q ∨ p :=\niff.intro\n  (assume h : p ∨ q,\n    h.elim\n      (assume hp : p, or.inr hp)\n      (assume hq : q, or.inl hq))\n  (assume h : q ∨ p,\n    h.elim\n      (assume hq : q, or.inr hq)\n      (assume hp : p, or.inl hp))\n\n-- associativity of ∧ and ∨\n\ntheorem and_ass {p q r : Prop} : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\niff.intro\n  (assume h : (p ∧ q) ∧ r,\n    show p ∧ (q ∧ r), from ⟨ h.left.left, ⟨ h.left.right, h.right ⟩ ⟩)\n  (assume h : p ∧ (q ∧ r),\n    show (p ∧ q) ∧ r, from ⟨ ⟨ h.left, h.right.left ⟩, h.right.right ⟩)\n\ntheorem or_ass {p q r : Prop} : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\niff.intro\n  (assume h : (p ∨ q) ∨ r,\n    h.elim\n    (assume hpq : p ∨ q,\n      hpq.elim\n      (assume hp : p,\n        show p ∨ (q ∨ r), from or.inl hp)\n      (assume hq : q,\n        show p ∨ (q ∨ r), from or.inr (or.inl hq)))\n    (assume hr : r,\n      show p ∨ (q ∨ r), from or.inr (or.inr hr)))\n  (assume h : p ∨ (q ∨ r),\n    h.elim\n    (assume hp : p,\n      show (p ∨ q) ∨ r, from or.inl (or.inl hp))\n    (assume hqr : q ∨ r,\n      hqr.elim\n      (assume hq : q,\n        show (p ∨ q) ∨ r, from or.inl (or.inr hq))\n      (assume hr : r,\n        show (p ∨ q) ∨ r, from or.inr hr)))\n\n-- distributivity\n\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\niff.intro\n  (assume h : p ∧ (q ∨ r),\n    h.right.elim\n      (assume hq : q,\n        show (p ∧ q) ∨ (p ∧ r), from or.inl ⟨ h.left, hq ⟩)\n      (assume hr : r,\n        show (p ∧ q) ∨ (p ∧ r), from or.inr ⟨ h.left, hr ⟩))\n  (assume h : (p ∧ q) ∨ (p ∧ r),\n    h.elim\n      (assume hpq : p ∧ q,\n        show p ∧ (q ∨ r), from ⟨ hpq.left, or.inl hpq.right ⟩)\n      (assume hpr : p ∧ r,\n        show p ∧ (q ∨ r), from ⟨ hpr.left, or.inr hpr.right ⟩))\n      \n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\niff.intro\n  (assume h : p ∨ (q ∧ r),\n    h.elim\n      (assume hp : p,\n        show (p ∨ q) ∧ (p ∨ r), from ⟨ or.inl hp, or.inl hp ⟩)\n      (assume hqr : q ∧ r,\n        show (p ∨ q) ∧ (p ∨ r), from ⟨ or.inr hqr.left, or.inr hqr.right ⟩))\n  (assume h : (p ∨ q) ∧ (p ∨ r),\n    have hpq : p ∨ q, from h.left,\n    have hpr : p ∨ r, from h.right,\n    hpq.elim\n      (assume hp : p,\n        show p ∨ (q ∧ r), from or.inl hp)\n      (assume hq : q,\n        hpr.elim\n          (assume hp : p,\n            show p ∨ (q ∧ r), from or.inl hp)\n          (assume hr : r,\n            show p ∨ (q ∧ r), from or.inr ⟨ hq, hr ⟩)))\n\n-- other properties\n\ntheorem exportation {p q r : Prop} : (p → (q → r)) ↔ (p ∧ q → r) :=\niff.intro\n  (assume (h₁ : (p → q → r)) (h₂ : p ∧ q),\n    show r, from h₁ h₂.left h₂.right)\n  (assume (h : p ∧ q → r) (hp : p) (hq : q),\n    show r, from h (and.intro hp hq))\n\ntheorem antidist_or : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\niff.intro\n  (assume (h₁ : p ∨ q → r),\n    show (p → r) ∧ (q → r), from and.intro -- ⟨ λ hp, h₁ (or.inl hp), λ hq, h₁ (or.inr hq) ⟩\n      (assume hp : p,\n        have h₂ : p ∨ q, from or.inl hp,\n        show r, from h₁ h₂)\n      (assume hq : q,\n        have h₂ : p ∨ q, from or.inr hq,\n        show r, from h₁ h₂))\n  (assume (h₁ : (p → r) ∧ (q → r)) (h₂ : p ∨ q),\n    show r, from h₂.elim\n      (assume hp : p, h₁.left hp)\n      (assume hq : q, h₁.right hq))\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := antidist_or p q false\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\nassume (h₁ : ¬p ∨ ¬q) (h₂ : p ∧ q),\nh₁.elim\n  (assume hnp : ¬p, absurd h₂.left hnp)\n  (assume hnq : ¬q, absurd h₂.right hnq)\n\ntheorem nonabsurdity : ¬(p ∧ ¬p) := \nassume h : p ∧ ¬p,\nabsurd h.left h.right\n\nexample : p ∧ ¬q → ¬(p → q) :=\nassume (h₁ : p ∧ ¬q) (h₂ : p → q),\nabsurd (h₂ h₁.left) h₁.right\n\n-- principle of explosion\ntheorem explosion : ¬p → (p → q) := \nassume (hnp : ¬p) (hp : p),\nabsurd hp hnp\n\n-- material implication\ntheorem mat_impl_right {p q : Prop} : (¬p ∨ q) → (p → q) := \nassume (h : ¬p ∨ q) (hp : p),\nh.elim\n  (assume hnp : ¬p, absurd hp hnp)\n  (assume hq : q, hq)\n\nexample : p ∨ false ↔ p := \niff.intro\n  (assume h : p ∨ false, h.elim\n    (assume hp : p, hp)\n    (assume hf : false, hf.elim))\n  (assume hp : p, or.inl hp)\n\nexample : p ∧ false ↔ false := \niff.intro\n  (assume h : p ∧ false, h.right.elim)\n  (assume h : false, h.elim)\n\nopen classical\n\nexample : ¬(p ↔ ¬p) := \nassume h,\n(em p).elim\n  (assume hp : p,\n    show false, from absurd hp (h.mp hp))\n  (assume hnp : ¬p,\n    show false, from absurd (h.mpr hnp) hnp)\n\nexample : (p → q) → (¬q → ¬p) := \nassume (hpq : p → q) (hnq : ¬q) (hp : p),\nshow false, from hnq (hpq hp)\n\n\n\n/-\n  Exercise 2.\n    Prove the following identities, replacing the “sorry” placeholders with actual proofs.\n    These require classical reasoning.\n-/\n\nopen classical\n\ntheorem mat_impl_left {p q : Prop} : (p → q) → (¬p ∨ q) :=\nassume h : p → q,\nby_cases\n  (assume hp : p,\n    or.inr (h hp))\n  (assume hnp : ¬p,\n    or.inl hnp)\n\nexample : (p → q ∨ r) → ((p → q) ∨ (p → r)) :=\nassume h : p → q ∨ r,\nhave h₁ : ¬p ∨ (q ∨ r), from mat_impl_left h,\nhave h₂ : (¬p ∨ q) ∨ r, from or_ass.elim_right h₁,\nhave h₃ : r ∨ (¬p ∨ q), from or_com.elim_left h₂,\nhave h₄ : ¬p ∨ (r ∨ (¬p ∨ q)), from or.inr h₃,\nhave h₅ : (¬p ∨ r) ∨ (¬p ∨ q), from or_ass.elim_right h₄,\nh₅.elim\n  (assume hh : (¬p ∨ r),\n    have ha : p → r, from mat_impl_right hh,\n    or.inr ha)\n  (assume hh : (¬p ∨ q),\n    have ha : p → q, from mat_impl_right hh,\n    or.inl ha)\n\ntheorem demorgans_4 {p q : Prop} : ¬(p ∧ q) → ¬p ∨ ¬q :=\nassume h : ¬(p ∧ q),\nby_cases\n  (assume hp : p, by_cases\n    (assume hq : q, absurd (and.intro hp hq) h)\n    (assume hnq : ¬q, or.inr hnq))\n  (assume hnp : ¬p, or.inl hnp)\n\ntheorem dne {p : Prop} (h : ¬¬p) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : ¬p, absurd hnp h)\n\n-- probably could use mat_impl_left and demorgans\ntheorem mat_impl_neg_left {p q : Prop} : ¬(p → q) → p ∧ ¬q :=\nassume h : ¬(p → q),\nby_contradiction\n  (assume hc : ¬(p ∧ ¬q),\n    have h₁ : ¬p ∨ ¬¬q, from demorgans_4 hc,\n    have h₂ : ¬p ∨ q, from h₁.elim\n      (assume g : ¬p, or.inl g)\n      (assume g : ¬¬q, or.inr (dne g)),\n    have h₃ : p → q, from mat_impl_right h₂,\n    show false, from h h₃)\n\n-- example : (p → q) → (¬p ∨ q) := sorry -- proved above as theorem mat_impl_left\n\nexample : (¬q → ¬p) → (p → q) :=\nassume (h : ¬q → ¬p) (hp : p),\nby_cases\n  (assume hq : q, hq)\n  (assume hnq : ¬q, absurd hp (h hnq))\n\nexample : p ∨ ¬p := em p\n\n-- Peirce's law\nexample : (((p → q) → p) → p) :=\nassume h : (p → q) → p,\nby_cases\n  (assume hc : p → q, h hc)\n  (assume hc : ¬(p → q),\n    have h₁ : p ∧ ¬q, from mat_impl_neg_left hc,\n    h₁.left)\n\n/-\n  Exercise 3.\n    Prove ¬(p ↔ ¬p) without using classical logic.\n-/\n\nexample : ¬(p ↔ ¬p) :=\nassume h,\nhave h₁ : p → ¬p, from h.elim_left,\nhave h₂ : ¬p → p, from h.elim_right,\nhave h₃ : ¬(p ∧ p), from exportation.elim_left h₁,\nhave hnp : ¬p, from sorry, -- so close...\nabsurd (h₂ hnp) hnp\n", "meta": {"author": "quasimik", "repo": "tp-lean", "sha": "bdf59f3d2fe22b95ed0944252a5019ca0081f96c", "save_path": "github-repos/lean/quasimik-tp-lean", "path": "github-repos/lean/quasimik-tp-lean/tp-lean-bdf59f3d2fe22b95ed0944252a5019ca0081f96c/3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7726510211344652}}
{"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/- \nWe would like prove that there is no rational number whose square is 2 using the techniques introduced earlier.\n-/\n\ndef even (a : ℤ) := ∃ b : ℤ, a = 2 * b\ndef odd (a : ℤ) := ∃ b : ℤ, a = 2 * b + 1\n\nlemma not_even_is_odd (n : ℤ) : ¬ even n ↔ odd n := \nbegin\n    split,\n    intro ha,\n    have hb : n % 2 = 1,\n        have hc : n % 2 = 0 ∨ 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, simp, refl,\n    have hd : n % 2 = 0,\n        rw hy, simp,\n    have he : (1 : ℤ) = (0 : ℤ),\n        rwa [←hc, ←hd],\n    have hf : ¬ ( (1 : ℤ) = (0 : ℤ)), simp,\n    exact hf he,\nend\n\nlemma gcdeven (n m : ℕ) : 2 ∣ nat.gcd (2 * n) (2 * m) :=\nbegin\n    have ha : 2 ∣ 2 * n, existsi n, refl,\n    have hb : 2 ∣ 2 * m, existsi m, refl,\n    have hc : (2 ∣ 2 * n) → (2 ∣ 2 * m) → 2 ∣ nat.gcd (2 * n) (2 * m),\n    exact nat.dvd_gcd,\n    apply hc,\n    repeat {assumption},\nend\n\n/- Lemma\nIf $a$ is an integer, then $a$ is even is and only if $a^2$ is even.\n-/\nlemma times_even\n  (a : ℤ) : even a ↔ even (a ^ 2) :=\nbegin\n    split,\n    intro h,\n    have ha : ∃ b : ℤ, a = 2 * b, exact h,\n    have hb : ∃ b : ℤ, 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 ←not_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 : ¬ 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 : ¬ ∃ r : ℚ, 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 ←h,\n    intro hcon,\n    -- The denominator must not be zero\n    have hdnot0 : r.denom ≠ 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 ≠ 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 : ℤ) ^ 2,\n        have ha : r.num ^ 2 = r.num ^ 2 * 1,\n            simp,\n        rwa [ha, ←rat.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 → 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 * ↑(r.denom) ^ 2 = 4 * (b ^ 2)) → (↑(r.denom) ^ 2 = 2 * b ^ 2),\n            have hβ : 4 * b ^ 2 = 2 * 2 * b ^ 2, refl,\n            rw [hβ, ←sub_eq_zero],\n            have hγ : 2 * ↑(r.denom) ^ 2 - 2 * 2 * b ^ 2 = 2 * (↑(r.denom) ^ 2 - 2 * b ^ 2), ring,\n            rw [hγ, mul_eq_zero],\n            intro hδ,\n            cases hδ with hδ1 hδ2,\n            exfalso,\n            convert hδ1, simp, linarith,\n            rw ←sub_eq_zero,\n            assumption,\n        rw hb,\n        have hc : 4 * b ^ 2 = (2 * b) ^ 2,\n            ring,\n        rw [hc, ←ha],\n    have hd : ↑r.denom * ↑r.denom = r.denom * r.denom, simp,\n        have he : rat.mk (r.num ^ 2) (r.denom ^ 2) = 2, \n            rw ←hcon, \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) ↑(r.denom),\n        have hg : 2 * (↑(r.denom) ^ 2) =  r.num ^ 2 * 1 → 2 * (↑(r.denom) * ↑(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 ←rat.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 ←hd,\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 : ¬ nat.coprime (int.nat_abs (r.num)) (r.denom),\n        have ha : ¬ nat.coprime (int.nat_abs (r.num)) (r.denom) ↔ nat.gcd (int.nat_abs (r.num)) (r.denom) ≠ 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 : ℕ) = 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 : ¬ (2 ∣ nat.gcd (2 * int.nat_abs k) (2 * int.nat_abs m)),\n            rw he,\n            simp,\n            linarith,\n        have hg : 2 ∣ 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": "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/Sqrt2_not_rational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8479677506936879, "lm_q1q2_score": 0.772651003040711}}
{"text": "-- You can ignore this line for now, but don't remove it.\nnamespace hw3\n\n/-\nIn this assignment, you will put into practice your new\nknowledge of terms and definitions in predicate logic by\nusing it to implement a library of Boolean functions. You\nwill also gain practice using different forms of syntax\nfor defining functions.\n-/\n\n/-\nTo begin, we present one \"unary\" Boolean function (taking\none Boolean argument and returning a Boolean result) and one\n\"binary\" function (taking two arguments), using each of three\nstyles of syntax.\n-/\n\n/-\nFirst, here are three implementations of exactly the\nsame unary function, namely negation, in three styles. \n-/\n\n-- explicitly lambda expression\ndef neg_bool : bool → bool :=\n    λ (b : bool), \n        match b with \n        | ff := tt\n        | tt := ff\n        end\n\n-- by cases; note absence of := after function type\ndef neg_bool' : bool → bool\n    | ff := tt\n    | tt := ff   \n\n-- C-style; note return type is now between : and :=\ndef neg_bool'' (b : bool) : bool :=\n   match b with \n    | ff := tt\n    | tt := ff\n    end\n\n/-\nSecond, here are three implementations of exactly the\nsame binary function (Boolean \"and\"), in the same three\nstyles. \n-/\n\n-- Note commas in match expression and in each case\ndef and_bool : bool → bool → bool :=\n    λ (b1 b2 : bool),       --shorthand for two lambdas\n        match b1, b2 with   -- matching on two arguments\n            | ff, ff := ff\n            | ff, tt := ff\n            | tt, ff := ff\n            | tt, tt := tt\n        end\n\n-- Note absence of := and of commas in each of the cases\ndef and_bool' : bool → bool → bool \n    | ff ff := ff\n    | ff tt := ff\n    | tt ff := ff\n    | tt tt := tt\n\n-- should seem straightforward now\ndef and_bool'' (b1 b2 : bool) : bool :=\n       match b1, b2 with\n            | ff, ff := ff\n            | ff, tt := ff\n            | tt, ff := ff\n            | tt, tt := tt\n        end\n\n/-\nYour homework is to implement the remaining unary Boolean\nfunctions, and several key binary Boolean functions, each\none in each of these styles: lambda, by-cases, and C-style.\n-/\n\n/-\n1. Implement the always false unary Boolean function in each\nof the three styles, lambda, by-cases, and C-style. Call the\nfunctions false_bool, false_bool', and false_bool'', in that\norder.\n-/\n\n-- Here's the first one, just to get you going.\ndef false_bool : bool → bool :=\n    λ (b : bool),\n        ff\n\n-- Now false_bool'\n\n\n-- And now false_bool''\n\n/-\n2. Do the same for the always true unary Boolean function,\nusing true_bool as the function name (with zero, one, and \ntwo ' marks to avoid name conflicts. You will use ' in this\nway for each of the remaining parts of this assignment).\n-/\n\n\n\n/-\n3. Do the same for the unary Boolean identity function,\nusing ident_bool (and ' variants) as the function name.\n-/\n\n\n\n/-\nCongrats, you now have a small library of all unary Boolean\nfunctions. Now turn to the binary functions. Each will take\ntwo Boolean arguments, we can call them b1 and b2, and will\nreturn a Boolean result.\n-/\n\n\n/-\n4. The Boolean \"or\" function is true if and only if at least \none of b1 and b2 is true. Equivalently it is false if and only \nif both b1 and b2 are false. Implement this function in each\nof the three styles, using or_bool as the function name. You \nmay use the example of \"and_bool\" above as a model. While you\ncould just cut and paste, we strongly recommend that you type\nyour answers in full. Learning new syntax is an exercise is \n\"muscle memory\", so don't take shortcuts here. Learn the \nsyntax now and it will save you frustration later.\n-/\n\n\n\n\n/-\n5. The Boolean \"exclusive or\" function is true if and only if \nexactly one of its arguments is true. Implement this function\nin each style using xor_bool as the function name.\n-/\n\n\n\n\n/-\n6. The Boolean \"implies\" function is true if and only if \neither its first argument is false, or its first argument is \ntrue and its second argument is also true. Equivalently it is \nfalse if and only if its first argument is true and its second is false. Implement it in each style, calling it implies_bool.\n-/\n\n\n\n\n/-\n7. The Boolean \"equivalent-to\" function is true if its two arguments are the same, either both true or both false; \notherwise it is false. Implement it in the three styles,\nusing equiv_bool as a function name.\n-/\n\n\n\n\n-- leave the following in place as the last line in this file\nend hw3\n\n", "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/hw3_function_terms_lambda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8947894625955064, "lm_q1q2_score": 0.7725537021168789}}
{"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.big_operators.nat_antidiagonal\nimport data.polynomial.ring_division\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\nnamespace polynomial\nopen_locale polynomial\n\nsection semiring\n\nvariables {R : Type*} [semiring R] (p q : R[X])\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\n@[simp] lemma mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror]\n\nlemma mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = (monomial n a) :=\nbegin\n  classical,\n  by_cases ha : a = 0,\n  { rw [ha, monomial_zero_right, mirror_zero] },\n  { rw [mirror, reverse, nat_degree_monomial n a, if_neg ha, nat_trailing_degree_monomial ha,\n        ←C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, rev_at_le (le_refl n),\n        tsub_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 : R[X]) :=\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  nontriviality R,\n  rw [mirror, nat_degree_mul', reverse_nat_degree, nat_degree_X_pow,\n      tsub_add_cancel_of_le p.nat_trailing_degree_le_nat_degree],\n  rwa [leading_coeff_X_pow, mul_one, reverse_leading_coeff, ne, trailing_coeff_eq_zero]\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 : ℕ) :\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 ≤ p.nat_degree + p.nat_trailing_degree,\n    { rw [rev_at_le h1, coeff_eq_zero_of_lt_nat_trailing_degree],\n      exact (tsub_lt_iff_left h1).mpr (nat.add_lt_add_right h2 _) },\n    { rw [←rev_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 ≤ n,\n  { rw [←tsub_add_eq_add_tsub h2, ←tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow',\n        if_pos h3, coeff_reverse, rev_at_le (tsub_le_self.trans h2)] },\n  rw not_le at h3,\n  rw coeff_eq_zero_of_nat_degree_lt (lt_tsub_iff_right.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 (λ n, by rw [coeff_mirror, coeff_mirror,\n  mirror_nat_degree, mirror_nat_trailing_degree, rev_at_invol])\n\nvariables {p q}\n\nlemma mirror_involutive : function.involutive (mirror : R[X] → R[X]) :=\nmirror_mirror\n\nlemma mirror_eq_iff : p.mirror = q ↔ p = q.mirror :=\nmirror_involutive.eq_iff\n\n@[simp] lemma mirror_inj : p.mirror = q.mirror ↔ p = q :=\nmirror_involutive.injective.eq_iff\n\n@[simp] lemma mirror_eq_zero : p.mirror = 0 ↔ p = 0 :=\n⟨λ h, by rw [←p.mirror_mirror, h, mirror_zero], λ h, by rw [h, mirror_zero]⟩\n\nvariables (p q)\n\n@[simp] lemma 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 _ _), add_tsub_cancel_right]\n\n@[simp] lemma mirror_leading_coeff : p.mirror.leading_coeff = p.trailing_coeff :=\nby rw [←p.mirror_mirror, mirror_trailing_coeff, p.mirror_mirror]\n\nlemma coeff_mul_mirror :\n  (p * p.mirror).coeff (p.nat_degree + p.nat_trailing_degree) = p.sum (λ n, (^ 2)) :=\nbegin\n  rw [coeff_mul, finset.nat.sum_antidiagonal_eq_sum_range_succ_mk],\n  refine (finset.sum_congr rfl (λ n hn, _)).trans (p.sum_eq_of_subset (λ n, (^ 2))\n    (λ n, zero_pow zero_lt_two) _ (λ n hn, finset.mem_range_succ_iff.mpr\n    ((le_nat_degree_of_mem_supp n hn).trans (nat.le_add_right _ _)))).symm,\n  rw [coeff_mirror, ←rev_at_le (finset.mem_range_succ_iff.mp hn), rev_at_invol, ←sq],\nend\n\nvariables [no_zero_divisors R]\n\nlemma nat_degree_mul_mirror : (p * p.mirror).nat_degree = 2 * p.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, zero_mul, nat_degree_zero, mul_zero] },\n  rw [nat_degree_mul hp (mt mirror_eq_zero.mp hp), mirror_nat_degree, two_mul],\nend\n\nlemma nat_trailing_degree_mul_mirror :\n  (p * p.mirror).nat_trailing_degree = 2 * p.nat_trailing_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, zero_mul, nat_trailing_degree_zero, mul_zero] },\n  rw [nat_trailing_degree_mul hp (mt mirror_eq_zero.mp hp), mirror_nat_trailing_degree, two_mul],\nend\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [ring R] (p q : R[X])\n\nlemma mirror_neg : (-p).mirror = -(p.mirror) :=\nby rw [mirror, mirror, reverse_neg, nat_trailing_degree_neg, neg_mul_eq_neg_mul]\n\nvariables [no_zero_divisors R]\n\nlemma mirror_mul_of_domain : (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  rw [mul_assoc, ←mul_assoc q.reverse],\n  conv_lhs { congr, skip, congr, rw [←X_pow_mul] },\n  repeat { rw [mul_assoc], },\nend\n\nlemma mirror_smul (a : R) : (a • p).mirror = a • p.mirror :=\nby rw [←C_mul', ←C_mul', mirror_mul_of_domain, mirror_C]\n\nend ring\n\nsection comm_ring\n\nvariables {R : Type*} [comm_ring R] [no_zero_divisors R] {f : R[X]}\n\nlemma irreducible_of_mirror (h1 : ¬ is_unit f)\n  (h2 : ∀ k, f * f.mirror = k * k.mirror → k = f ∨ k = -f ∨ k = f.mirror ∨ k = -f.mirror)\n  (h3 : ∀ g, g ∣ f → g ∣ f.mirror → 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, ←mul_assoc] },\n    have g_dvd_f : g ∣ f,\n    { rw fgh,\n      exact dvd_mul_right g h },\n    have h_dvd_f : h ∣ f,\n    { rw fgh,\n      exact dvd_mul_left h g },\n    have g_dvd_k : g ∣ k,\n    { exact dvd_mul_right g h.mirror },\n    have h_dvd_k_rev : h ∣ 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 ← 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 ← hk)) },\n    { exact or.inl (h3 g g_dvd_f (by rwa [eq_neg_iff_eq_neg.mp hk, dvd_neg])) } },\nend\n\nend comm_ring\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/mirror.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8633915994285382, "lm_q1q2_score": 0.7725536986006564}}
{"text": "/-\nA total function\n-- set theoretic representation of the squaring function\nsqr : ℕ → ℕ := { (0,0), (1,1), (2,4), (3,9), ... }\n-/\n\n\n/-\nComputational representation of the function\n-/\ndef sqr : ℕ → ℕ := λ n, n*n\n#eval sqr 3\n\n\n/-\nLogical, declarative, predicate that defines the same function\n-/\ninductive sqr_pred : ℕ → ℕ → Prop \n| in_sqr_pred : ∀ (n1 n2 : ℕ), (n2 = n1 * n1) → sqr_pred n1 n2\n\n-- h === in_sqr_pred n1 n2 k\n\ntheorem verification : ∀ (n1 n2 : ℕ), sqr_pred n1 n2 → sqr n1 = n2 := \nbegin\n  assume n1 n2,\n  assume h,\n  cases h,\n  unfold sqr,\n  apply eq.symm _,\n  assumption,\nend\n\n-- \n\n#check sqr_pred\n#check sqr_pred 3 8 \n\nopen sqr_pred\n\n-- explicit proof term\nexample : sqr_pred 3 9 := in_sqr_pred 3 9 (eq.refl 9)\n\nexample : sqr_pred 4 16 := in_sqr_pred _ _ (eq.refl _)\n\nexample : sqr_pred 3 9 := \nbegin\n  apply in_sqr_pred _ _ _,\n  exact eq.refl _,\nend\n\nexample : sqr_pred 4 16 := \nbegin\n  apply in_sqr_pred _ _ _,\n  exact eq.refl _,\nend\n\nexample : sqr_pred 3 15 := in_sqr_pred _ _ (eq.refl _)\n\n\n/-\nsqr_ev : ℕ → ℕ := { (0,0), (2,4), (4,16), ... }\n-/\n\ndef evn : ℕ → bool := λ n, n%2 = 0\n\ninductive sqr_ev_pred : ℕ → ℕ → Prop \n| in_sqr_ev_pred : ∀ (n1 n2 : ℕ),  (n1%2 = 0) → (n2 = n1 * n1) → sqr_ev_pred n1 n2\n\nopen sqr_ev_pred\n\nexample : sqr_ev_pred 4 16 := \nbegin\n  apply in_sqr_ev_pred,\n  apply eq.refl _,\n  apply eq.refl 16,\nend\n\nexample : sqr_ev_pred 3 9 := \nbegin\n  apply in_sqr_ev_pred,\n  apply eq.refl _, -- stuck\nend\n\n\n\n\n\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/play.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7724979293889728}}
{"text": "-- source: https://github.com/bryangingechen/lean-fibonacci/blob/master/src/fib.lean\nimport data.list.range\n\n\n@[reducible]\ndef fibonacci : ℕ → ℕ\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 : ℕ) : ℕ :=\n  ((range n).map fibonacci).sum\n\n@[reducible]\ndef fib_odd_sum (n : ℕ) : ℕ :=\n  ((range n).map (λ m, fibonacci (2*m + 1))).sum\n\n@[reducible]\ndef fib_even_sum (n : ℕ) : ℕ :=\n  ((range n).map (λ m, fibonacci (2*m))).sum\n\ntheorem fib_odd_sum_eq : ∀ (n : ℕ),\n  fib_odd_sum n = fibonacci (2*n)\n| 0 := rfl\n| (n+1) := by rw [\n    fib_odd_sum,\n    sum_range_succ, -- (f : ℕ → α) (n : ℕ), (map f (range n.succ)).sum = (map f (range n)).sum + f n\n    ←fib_odd_sum,\n    fib_odd_sum_eq,\n    mul_add, -- (a b c : α), a * (b + c) = a * b + a * c\n    mul_one, -- (a : α), a * 1 = a\n    fibonacci\n  ]\n\ntheorem fib_even_sum_eq : ∀ {n : ℕ} (h : n > 0),\n  fib_even_sum n + 1 = fibonacci (2*n - 1)\n| 0 h := (gt_irrefl 0 h).elim -- used false.elim : false → C\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    ←fib_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 [←fibonacci],\nend\n-- *** Added example ***\nnamespace false_elim_test\n\nconstant h1 : false\n#check false.elim h1\n#check @false.elim\n\nend false_elim_test\n\nset_option trace.simplify.rewrite true\n\ntheorem fib_sum_eq : ∀ (n : ℕ),\n  fib_sum n + 1 = fibonacci (n+1)\n| 0 := rfl\n| (n+1) :=\nbegin\n  rw [fibonacci,\n    ←fib_sum_eq n\n  ],\n  simp [range_concat, fib_sum, add_left_comm, add_comm],\n-- [fib_sum.equations._eqn_1]: fib_sum (n + 1) ==> (map fibonacci (range (n + 1))).sum\n-- [list.range_concat]: range (n + 1) ==> range n ++ [n]\n-- [list.map_append]: map fibonacci (range n ++ [n]) ==> map fibonacci (range n) ++ map fibonacci [n]\n-- [list.map.equations._eqn_2]: map fibonacci [n] ==> fibonacci n :: map fibonacci nil\n-- [list.map_nil]: map fibonacci nil ==> nil\n-- [list.sum_append]: (map fibonacci (range n) ++ [fibonacci n]).sum ==> (map fibonacci (range n)).sum + [fibonacci n].sum\n-- [list.sum_cons]: [fibonacci n].sum ==> fibonacci n + nil.sum\n-- [list.sum_nil]: nil.sum ==> 0\n-- [add_zero]: fibonacci n + 0 ==> fibonacci n\n-- [add_comm]: (map fibonacci (range n)).sum + fibonacci n ==> fibonacci n + (map fibonacci (range n)).sum\n-- [add_comm]: fibonacci n + (map fibonacci (range n)).sum + 1 ==> 1 + (fibonacci n + (map fibonacci (range n)).sum)\n-- [add_left_comm]: 1 + (fibonacci n + (map fibonacci (range n)).sum) ==> fibonacci n + (1 + (map fibonacci (range n)).sum)\n-- [fib_sum.equations._eqn_1]: fib_sum n ==> (map fibonacci (range n)).sum\n-- [add_comm]: (map fibonacci (range n)).sum + 1 ==> 1 + (map fibonacci (range n)).sum\n-- [add_left_inj]: fibonacci n + (1 + (map fibonacci (range n)).sum) = fibonacci n + (1 + (map fibonacci (range n)).sum) ==> fibonacci n = fibonacci n\n-- [eq_self_iff_true]: fibonacci n = fibonacci n ==> true\nend\n\ninductive bee : Type\n| queen : bee\n| worker : bee\n| drone : bee\n\nopen bee list\n\ninstance : has_repr bee :=\n⟨λ s, match s with\n| queen := \"Q\"\n| worker := \"W\"\n| drone := \"D\"\nend⟩\n\nnamespace bee\n\ndef parents : bee → list bee\n| queen := [queen, drone]\n| worker := [queen, drone]\n| drone := [queen]\n\ndef ancestors (b : bee) : ℕ → list bee\n| 0 := [b]\n| (n+1) := ((ancestors n).map parents).join\n\ndef tree_json : bee → ℕ → string\n| b 0 := \"{\\\"name\\\":\\\"\" ++ repr b ++ \"\\\"}\"\n| b (n+1) := \"{\\\"name\\\":\\\"\" ++ repr b ++ \"\\\",\\\"children\\\":[\" ++\n  string.intercalate \",\" (b.parents.map (λ p, p.tree_json n)) ++ \"]}\"\n\nlemma drone_ancestors_concat : ∀ (n : ℕ),\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 {\n    to_lhs,\n    rw [\n      drone_ancestors_concat n,\n      map_append, -- (f : α → β) (l₁ l₂ : list α), map f (l₁ ++ l₂) = map f l₁ ++ map f l₂\n      join_append], -- (L₁ L₂ : list (list α)), (L₁ ++ L₂).join = L₁.join ++ L₂.join\n  },\n  refl,\nend\n\ntheorem drone_ancestors_length_eq_fib_succ : ∀ (n : ℕ),\n  (drone.ancestors n).length = fibonacci (n + 1)\n| 0 := rfl\n| 1 := rfl\n| (n+2) := begin\n  rw [\n    drone_ancestors_concat,\n    length_append, -- (s t : list α), (s ++ t).length = s.length + t.length\n    drone_ancestors_length_eq_fib_succ n,\n    drone_ancestors_length_eq_fib_succ (n+1),\n    add_comm -- (a b : α), a + b = b + a\n  ],\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⟨λ s, match s with\n| rabbit := \"R\"\n| cadillac := \"C\"\nend⟩\n\nnamespace car\n\n@[reducible]\ndef size : car → ℕ\n| rabbit := 1\n| cadillac := 2\n\n@[reducible]\ndef sum_size (cs : list car) : ℕ :=\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 :=\nbegin\n  simp only [sum_size, sum_cons, map, add_comm],\n  -- [car.sum_size.equations._eqn_1]: sum_size (c :: cs) ==> (map size (c :: cs)).sum\n  -- [list.map.equations._eqn_2]: map size (c :: cs) ==> c.size :: map size cs\n  -- [list.sum_cons]: (c.size :: map size cs).sum ==> c.size + (map size cs).sum\n  -- [car.sum_size.equations._eqn_1]: sum_size cs ==> (map size cs).sum\n  -- [add_comm]: (map size cs).sum + c.size ==> c.size + (map size cs).sum \nend\n\n@[reducible]\ndef packings : ℕ → 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 : ∀ (n : ℕ),\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  -- [car.packings.equations._eqn_3]: packings (n + 2) ==> map (cons rabbit) (packings n.succ) ++ map (cons cadillac) (packings n)\n  -- [list.length_append]: (map (cons rabbit) (packings n.succ) ++ map (cons cadillac) (packings n)).length ==> (map (cons rabbit) (packings n.succ)).length + (map (cons cadillac) (packings n)).length\n  -- [list.length_map]: (map (cons rabbit) (packings n.succ)).length ==> (packings n.succ).length\n  -- [list.length_map]: (map (cons cadillac) (packings n)).length ==> (packings n).length\n  -- [add_comm]: (packings n.succ).length + (packings n).length ==> (packings n).length + (packings n.succ).length\n  -- [add_comm]: n + 2 + 1 ==> 1 + (n + 2)\n  -- [add_left_comm]: 1 + (n + 2) ==> n + (1 + 2)\n  -- [add_zero]: n + (1 + 2) ==> n + 3\n  -- [fibonacci.equations._eqn_3]: fibonacci (n + 3) ==> fibonacci (n + 1) + fibonacci (n + 1).succ\n  -- [fibonacci.equations._eqn_3]: fibonacci (n + 1).succ ==> fibonacci n + fibonacci n.succ\n  -- [add_left_comm]: fibonacci (n + 1) + (fibonacci n + fibonacci n.succ) ==> fibonacci n + (fibonacci (n + 1) + fibonacci n.succ)\n  -- [add_comm]: fibonacci (n + 1) + fibonacci n.succ ==> fibonacci n.succ + fibonacci (n + 1)\n  rw [num_packings_eq_fib n,\n    num_packings_eq_fib (n+1),\n    add_left_comm, -- (a b c : α), a + (b + c) = b + (a + c)\n    add_right_inj, -- (a : M) {b c : M}, a + b = a + c ↔ b = c\n    fibonacci\n  ],\nend\n\ntheorem packing_size : ∀ {n : ℕ} {cs : list car} (h : cs ∈ 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-- [car.packings.equations._eqn_3]: packings (n + 2) ==> \n--                                    map (cons rabbit) (packings n.succ) ++ map (cons cadillac) (packings n)\n-- [list.mem_append]: cs ∈ map (cons rabbit) (packings n.succ) ++ map (cons cadillac) (packings n) ==>\n--                      cs ∈ map (cons rabbit) (packings n.succ) ∨ cs ∈ map (cons cadillac) (packings n)\n-- [list.mem_map]: cs ∈ map (cons rabbit) (packings n.succ) ==> \n--                   ∃ (a : list car), a ∈ packings n.succ ∧ rabbit :: a = cs\n-- [list.mem_map]: cs ∈ map (cons cadillac) (packings n) ==> \n--                   ∃ (a : list car), a ∈ packings n ∧ cadillac :: a = cs\n  rcases h with ⟨cs', h₁, h₂⟩ | ⟨cs', h₁, h₂⟩,\n  all_goals {\n    rw [\n      ←h₂,\n      sum_size_cons,\n      size,\n      packing_size h₁\n    ],\n  },\nend\n\nlemma car_size_ne_zero (c : car) : size c ≠ 0 :=\nby cases c; contradiction -- why contradiction tactic works with ⊢ rabbit.size ≠ 0 ?\n\nlemma sum_size_zero : ∀ {cs : list car} (h : sum_size cs = 0),\n  cs = []\n| [] _ := rfl\n| (c :: cs) h :=\nbegin -- ⊢ c :: cs = nil\n  exfalso, -- try to find contradiction\n  rw [\n    sum_size_cons, -- sum_size (c :: cs) = sum_size cs + c.size\n    add_eq_zero_iff -- a + b = 0 ↔ a = 0 ∧ b = 0\n  ] at h,\n  apply car_size_ne_zero c,\n  exact h.right,\nend\n\nlemma sum_size_one : ∀ {cs : list car} (h : sum_size cs = 1),\n  cs = [rabbit]\n| [] h := by contradiction -- ⊢ nil = [rabbit]\n| (rabbit :: cs) h :=\nbegin\n  rw sum_size_cons at h, -- sum_size (c :: cs) = sum_size cs + c.size\n  simp,\n  -- [eq_self_iff_true]: rabbit = rabbit ==> true\n  -- [true_and]: true ∧ cs = nil ==> cs = nil\n\n  -- ⊢ cs = nil\n  apply sum_size_zero, -- sum_size cs = 0 → cs = nil\n  -- ⊢ sum_size cs = 0\n  have u := succ_inj h, -- succ_inj : n.succ = m.succ → n = m\n  change sum_size cs + 1 = 1 at h, -- rabbit.size = 1\n  exact u, \nend\n| (cadillac :: cs) h :=\nbegin\n  rw sum_size_cons at h, -- sum_size (c :: cs) = sum_size cs + c.size\n  have : sum_size cs + 1 = 0 := succ_inj h,\n  -- cadillac.size = 2\n  rw size at h,\n  contradiction, -- why contradiction works ?\nend\n\ntheorem all_packings : ∀ {n : ℕ} {cs : list car} (h : sum_size cs = n),\n  cs ∈ 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 -- this case have 0 solutions?\n| (n+2) (rabbit :: cs) h :=\nbegin\n  rw [sum_size_cons, -- sum_size (c :: cs) = sum_size cs + c.size\n    add_left_inj 1 -- (a : M) {b c : M}, b + a = c + a ↔ b = c\n  ] at h,\n  simp [packings, all_packings, h],\n  -- [car.packings.equations._eqn_3]: packings (n + 2) ==> map (cons rabbit) (packings n.succ) ++ map (cons cadillac) (packings n)\n  -- [list.mem_append]: rabbit :: cs ∈ map (cons rabbit) (packings n.succ) ++ map (cons cadillac) (packings n) ==>\n  --                      rabbit :: cs ∈ map (cons rabbit) (packings n.succ) ∨ rabbit :: cs ∈ map (cons cadillac) (packings n)\n  -- [list.mem_map]: rabbit :: cs ∈ map (cons rabbit) (packings n.succ) ==> \n  --                             ∃ (a : list car), a ∈ packings n.succ ∧ rabbit :: a = rabbit :: cs\n  -- [eq_self_iff_true]: rabbit = rabbit ==> true\n  -- [true_and]: true ∧ a = cs ==> a = cs\n  -- [exists_eq_right]: ∃ (a : list car), a ∈ packings n.succ ∧ a = cs ==> cs ∈ packings n.succ\n  -- [h]: sum_size cs ==> n + 1\n  -- [eq_self_iff_true]: n + 1 = n.succ ==> true\n  -- [[anonymous]]: cs ∈ packings n.succ ==> true\n  -- [list.mem_map]: rabbit :: cs ∈ map (cons cadillac) (packings n) ==> ∃ (a : list car), a ∈ packings n ∧ cadillac :: a = rabbit :: cs\n  -- [false_and]: false ∧ a = cs ==> false\n  -- [and_false]: a ∈ packings n ∧ false ==> false\n  -- [exists_false]: ∃ (a : list car), false ==> false\n  -- [or_false]: true ∨ false ==> true\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", "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/lean-fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8539127529517044, "lm_q1q2_score": 0.7724926332775188}}
{"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 analysis.special_functions.trigonometric.deriv\nimport analysis.special_functions.log.basic\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 definitions\n\n- `real.arsinh`: The inverse function of `real.sinh`.\n\n- `real.sinh_equiv`, `real.sinh_order_iso`, `real.sinh_homeomorph`: `real.sinh` as an `equiv`,\n  `order_iso`, and `homeomorph`, respectively.\n\n## Main Results\n\n- `real.sinh_surjective`, `real.sinh_bijective`: `real.sinh` is surjective and bijective;\n\n- `real.arsinh_injective`, `real.arsinh_surjective`, `real.arsinh_bijective`: `real.arsinh` is\n  injective, surjective, and bijective;\n\n- `real.continuous_arsinh`, `real.differentiable_arsinh`, `real.cont_diff_arsinh`: `real.arsinh` is\n  continuous, differentiable, and continuously differentiable; we also provide dot notation\n  convenience lemmas like `filter.tendsto.arsinh` and `cont_diff_at.arsinh`.\n\n## Tags\n\narsinh, arcsinh, argsinh, asinh, sinh injective, sinh bijective, sinh surjective\n-/\nnoncomputable theory\n\nopen function filter set\nopen_locale topology\n\nnamespace real\n\nvariables {x y : ℝ}\n\n/-- `arsinh` is defined using a logarithm, `arsinh x = log (x + sqrt(1 + x^2))`. -/\n@[pp_nodot] def arsinh (x : ℝ) := log (x + sqrt (1 + x^2))\n\nlemma exp_arsinh (x : ℝ) : exp (arsinh x) = x + sqrt (1 + x^2) :=\nbegin\n  apply exp_log,\n  rw [← neg_lt_iff_pos_add'],\n  calc -x ≤ sqrt (x ^ 2) : le_sqrt_of_sq_le (neg_pow_bit0 _ _).le\n  ... < sqrt (1 + x ^ 2) : sqrt_lt_sqrt (sq_nonneg _) (lt_one_add _)\nend\n\n@[simp] lemma arsinh_zero : arsinh 0 = 0 := by simp [arsinh]\n\n@[simp] lemma arsinh_neg (x : ℝ) : arsinh (-x) = -arsinh x :=\nbegin\n  rw [← exp_eq_exp, exp_arsinh, exp_neg, exp_arsinh],\n  apply eq_inv_of_mul_eq_one_left,\n  rw [neg_sq, neg_add_eq_sub, add_comm x, mul_comm, ← sq_sub_sq, sq_sqrt, add_sub_cancel],\n  exact add_nonneg zero_le_one (sq_nonneg _)\nend\n\n/-- `arsinh` is the right inverse of `sinh`. -/\n@[simp] lemma sinh_arsinh (x : ℝ) : sinh (arsinh x) = x :=\nby { rw [sinh_eq, ← arsinh_neg, exp_arsinh, exp_arsinh, neg_sq], field_simp }\n\n@[simp] lemma cosh_arsinh (x : ℝ) : cosh (arsinh x) = sqrt (1 + x^2) :=\nby rw [← sqrt_sq (cosh_pos _).le, cosh_sq', sinh_arsinh]\n\n/-- `sinh` is surjective, `∀ b, ∃ a, sinh a = b`. In this case, we use `a = arsinh b`. -/\nlemma sinh_surjective : surjective sinh := left_inverse.surjective sinh_arsinh\n\n/-- `sinh` is bijective, both injective and surjective. -/\nlemma sinh_bijective : bijective sinh := ⟨sinh_injective, sinh_surjective⟩\n\n/-- `arsinh` is the left inverse of `sinh`. -/\n@[simp] lemma arsinh_sinh (x : ℝ) : arsinh (sinh x) = x :=\nright_inverse_of_injective_of_left_inverse sinh_injective sinh_arsinh x\n\n/-- `real.sinh` as an `equiv`. -/\n@[simps] def sinh_equiv : ℝ ≃ ℝ :=\n{ to_fun := sinh,\n  inv_fun := arsinh,\n  left_inv := arsinh_sinh,\n  right_inv := sinh_arsinh }\n\n/-- `real.sinh` as an `order_iso`. -/\n@[simps { fully_applied := ff }] def sinh_order_iso : ℝ ≃o ℝ :=\n{ to_equiv := sinh_equiv,\n  map_rel_iff' := @sinh_le_sinh }\n\n/-- `real.sinh` as a `homeomorph`. -/\n@[simps { fully_applied := ff }] def sinh_homeomorph : ℝ ≃ₜ ℝ := sinh_order_iso.to_homeomorph\n\nlemma arsinh_bijective : bijective arsinh := sinh_equiv.symm.bijective\nlemma arsinh_injective : injective arsinh := sinh_equiv.symm.injective\nlemma arsinh_surjective : surjective arsinh := sinh_equiv.symm.surjective\n\nlemma arsinh_strict_mono : strict_mono arsinh := sinh_order_iso.symm.strict_mono\n\n@[simp] lemma arsinh_inj : arsinh x = arsinh y ↔ x = y := arsinh_injective.eq_iff\n@[simp] lemma arsinh_le_arsinh : arsinh x ≤ arsinh y ↔ x ≤ y := sinh_order_iso.symm.le_iff_le\n@[simp] lemma arsinh_lt_arsinh : arsinh x < arsinh y ↔ x < y := sinh_order_iso.symm.lt_iff_lt\n\n@[simp] lemma arsinh_eq_zero_iff : arsinh x = 0 ↔ x = 0 :=\narsinh_injective.eq_iff' arsinh_zero\n\n@[simp] lemma arsinh_nonneg_iff : 0 ≤ arsinh x ↔ 0 ≤ x :=\nby rw [← sinh_le_sinh, sinh_zero, sinh_arsinh]\n\n@[simp] lemma arsinh_nonpos_iff : arsinh x ≤ 0 ↔ x ≤ 0 :=\nby rw [← sinh_le_sinh, sinh_zero, sinh_arsinh]\n\n@[simp] lemma arsinh_pos_iff : 0 < arsinh x ↔ 0 < x :=\nlt_iff_lt_of_le_iff_le arsinh_nonpos_iff\n\n@[simp] lemma arsinh_neg_iff : arsinh x < 0 ↔ x < 0 :=\nlt_iff_lt_of_le_iff_le arsinh_nonneg_iff\n\nlemma has_strict_deriv_at_arsinh (x : ℝ) : has_strict_deriv_at arsinh (sqrt (1 + x ^ 2))⁻¹ x :=\nbegin\n  convert sinh_homeomorph.to_local_homeomorph.has_strict_deriv_at_symm (mem_univ x)\n    (cosh_pos _).ne' (has_strict_deriv_at_sinh _),\n  exact (cosh_arsinh _).symm\nend\n\nlemma has_deriv_at_arsinh (x : ℝ) : has_deriv_at arsinh (sqrt (1 + x ^ 2))⁻¹ x :=\n(has_strict_deriv_at_arsinh x).has_deriv_at\n\nlemma differentiable_arsinh : differentiable ℝ arsinh :=\nλ x, (has_deriv_at_arsinh x).differentiable_at\n\nlemma cont_diff_arsinh {n : ℕ∞} : cont_diff ℝ n arsinh :=\nsinh_homeomorph.cont_diff_symm_deriv (λ x, (cosh_pos x).ne') has_deriv_at_sinh cont_diff_sinh\n\n@[continuity] lemma continuous_arsinh : continuous arsinh := sinh_homeomorph.symm.continuous\n\nend real\n\nopen real\n\nlemma filter.tendsto.arsinh {α : Type*} {l : filter α} {f : α → ℝ} {a : ℝ}\n  (h : tendsto f l (𝓝 a)) : tendsto (λ x, arsinh (f x)) l (𝓝 (arsinh a)) :=\n(continuous_arsinh.tendsto _).comp h\n\nsection continuous\n\nvariables {X : Type*} [topological_space X] {f : X → ℝ} {s : set X} {a : X}\n\nlemma continuous_at.arsinh (h : continuous_at f a) : continuous_at (λ x, arsinh (f x)) a := h.arsinh\n\nlemma continuous_within_at.arsinh (h : continuous_within_at f s a) :\n  continuous_within_at (λ x, arsinh (f x)) s a :=\nh.arsinh\n\nlemma continuous_on.arsinh (h : continuous_on f s) : continuous_on (λ x, arsinh (f x)) s :=\nλ x hx, (h x hx).arsinh\n\nlemma continuous.arsinh (h : continuous f) : continuous (λ x, arsinh (f x)) :=\ncontinuous_arsinh.comp h\n\nend continuous\n\nsection fderiv\n\nvariables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] {f : E → ℝ} {s : set E} {a : E}\n  {f' : E →L[ℝ] ℝ} {n : ℕ∞}\n\nlemma has_strict_fderiv_at.arsinh (hf : has_strict_fderiv_at f f' a) :\n  has_strict_fderiv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_strict_deriv_at_arsinh _).comp_has_strict_fderiv_at a hf\n\nlemma has_fderiv_at.arsinh (hf : has_fderiv_at f f' a) :\n  has_fderiv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_deriv_at_arsinh _).comp_has_fderiv_at a hf\n\nlemma has_fderiv_within_at.arsinh (hf : has_fderiv_within_at f f' s a) :\n  has_fderiv_within_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') s a :=\n(has_deriv_at_arsinh _).comp_has_fderiv_within_at a hf\n\nlemma differentiable_at.arsinh (h : differentiable_at ℝ f a) :\n  differentiable_at ℝ (λ x, arsinh (f x)) a :=\n(differentiable_arsinh _).comp a h\n\nlemma differentiable_within_at.arsinh (h : differentiable_within_at ℝ f s a) :\n  differentiable_within_at ℝ (λ x, arsinh (f x)) s a :=\n(differentiable_arsinh _).comp_differentiable_within_at a h\n\nlemma differentiable_on.arsinh (h : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λ x, arsinh (f x)) s :=\nλ x hx, (h x hx).arsinh\n\nlemma differentiable.arsinh (h : differentiable ℝ f) :\n  differentiable ℝ (λ x, arsinh (f x)) :=\ndifferentiable_arsinh.comp h\n\nlemma cont_diff_at.arsinh (h : cont_diff_at ℝ n f a) :\n  cont_diff_at ℝ n (λ x, arsinh (f x)) a :=\ncont_diff_arsinh.cont_diff_at.comp a h\n\nlemma cont_diff_within_at.arsinh (h : cont_diff_within_at ℝ n f s a) :\n  cont_diff_within_at ℝ n (λ x, arsinh (f x)) s a :=\ncont_diff_arsinh.cont_diff_at.comp_cont_diff_within_at a h\n\nlemma cont_diff.arsinh (h : cont_diff ℝ n f) : cont_diff ℝ n (λ x, arsinh (f x)) :=\ncont_diff_arsinh.comp h\n\nlemma cont_diff_on.arsinh (h : cont_diff_on ℝ n f s) : cont_diff_on ℝ n (λ x, arsinh (f x)) s :=\nλ x hx, (h x hx).arsinh\n\nend fderiv\n\nsection deriv\n\nvariables {f : ℝ → ℝ} {s : set ℝ} {a f' : ℝ}\n\nlemma has_strict_deriv_at.arsinh (hf : has_strict_deriv_at f f' a) :\n  has_strict_deriv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_strict_deriv_at_arsinh _).comp a hf\n\nlemma has_deriv_at.arsinh (hf : has_deriv_at f f' a) :\n  has_deriv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_deriv_at_arsinh _).comp a hf\n\nlemma has_deriv_within_at.arsinh (hf : has_deriv_within_at f f' s a) :\n  has_deriv_within_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') s a :=\n(has_deriv_at_arsinh _).comp_has_deriv_within_at a hf\n\nend 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/arsinh.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181418, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7724926133802006}}
{"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-/\nimport topology.basic\nimport topology.constructions\nimport topology.algebra.ordered.basic\n\n/-!\n# Topological lattices\n\nIn this file we define mixin classes `has_continuous_inf` and `has_continuous_sup`. We define the\nclass `topological_lattice` as a topological space and lattice `L` extending `has_continuous_inf`\nand `has_continuous_sup`.\n\n## References\n\n* [Gierz et al, A Compendium of Continuous Lattices][GierzEtAl1980]\n\n## Tags\n\ntopological, lattice\n-/\n\n/--\nLet `L` be a topological space and let `L×L` be equipped with the product topology and let\n`⊓:L×L → L` be an infimum. Then `L` is said to have *(jointly) continuous infimum* if the map\n`⊓:L×L → L` is continuous.\n-/\nclass has_continuous_inf (L : Type*) [topological_space L] [has_inf L] : Prop :=\n(continuous_inf : continuous (λ p : L × L, p.1 ⊓ p.2))\n\n/--\nLet `L` be a topological space and let `L×L` be equipped with the product topology and let\n`⊓:L×L → L` be a supremum. Then `L` is said to have *(jointly) continuous supremum* if the map\n`⊓:L×L → L` is continuous.\n-/\nclass has_continuous_sup (L : Type*) [topological_space L] [has_sup L] : Prop :=\n(continuous_sup : continuous (λ p : L × L, p.1 ⊔ p.2))\n\n@[priority 100] -- see Note [lower instance priority]\ninstance order_dual.has_continuous_sup\n  (L : Type*) [topological_space L] [has_inf L] [has_continuous_inf L] :\n  has_continuous_sup (order_dual L) :=\n{ continuous_sup := @has_continuous_inf.continuous_inf L _ _ _ }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance order_dual.has_continuous_inf\n  (L : Type*) [topological_space L] [has_sup L] [has_continuous_sup L] :\n  has_continuous_inf (order_dual L) :=\n{ continuous_inf := @has_continuous_sup.continuous_sup L _ _ _ }\n\n/--\nLet `L` be a lattice equipped with a topology such that `L` has continuous infimum and supremum.\nThen `L` is said to be a *topological lattice*.\n-/\nclass topological_lattice (L : Type*) [topological_space L] [lattice L]\n  extends has_continuous_inf L, has_continuous_sup L\n\n@[priority 100] -- see Note [lower instance priority]\ninstance order_dual.topological_lattice\n  (L : Type*) [topological_space L] [lattice L] [topological_lattice L] :\n  topological_lattice (order_dual L) := {}\n\nvariables {L : Type*} [topological_space L]\nvariables {X : Type*} [topological_space X]\n\n@[continuity] lemma continuous_inf [has_inf L] [has_continuous_inf L] :\n  continuous (λp:L×L, p.1 ⊓ p.2) :=\nhas_continuous_inf.continuous_inf\n\n@[continuity] lemma continuous.inf [has_inf L] [has_continuous_inf L]\n  {f g : X → L} (hf : continuous f) (hg : continuous g) :\n  continuous (λx, f x ⊓ g x) :=\ncontinuous_inf.comp (hf.prod_mk hg : _)\n\n@[continuity] lemma continuous_sup [has_sup L] [has_continuous_sup L] :\n  continuous (λp:L×L, p.1 ⊔ p.2) :=\nhas_continuous_sup.continuous_sup\n\n@[continuity] lemma continuous.sup [has_sup L] [has_continuous_sup L]\n  {f g : X → L} (hf : continuous f) (hg : continuous g) :\n  continuous (λx, f x ⊔ g x) :=\ncontinuous_sup.comp (hf.prod_mk hg : _)\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/order/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7724755086895455}}
{"text": "-- 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 : ∀ 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\nnoncomputable definition natural_power : real → nat → real\n| x 0 := 1\n| x (succ n) := (natural_power x n) * x\n\n-- Proof by Eduard Oravkin\ntheorem T1 : ∀ x:real, ∀ m n:nat, natural_power x (m+n) = natural_power x m *natural_power x n :=\nbegin\nintro x, intro m, intro n,\ninduction n with s H1,\nhave H : natural_power x 0 = 1,\n  refl,\nrw [add_zero, H , mul_one],\nunfold natural_power,\nrw [← mul_assoc, H1],\nend\n\n-- Proof by Chris Hughes \ntheorem T2 : ∀ x: real, ∀ 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 [T1,H]\nend\n\n-- Proof by Ali Barkhordarian\ntheorem T3 : ∀ x y: real, ∀ 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,\nexact one_mul 1,\nunfold natural_power,\nrw [mul_assoc],\nrw [← mul_assoc x],\nrw [mul_comm x],\nrw [mul_assoc, ←mul_assoc],\nrw [H]\nend\n\n\nconstant nth_root (x : real) (n : nat) : (x>0) → (n>0) → 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", "meta": {"author": "ImperialCollegeLondon", "repo": "M1F_room_342_questions", "sha": "63de9a6ab9c27a433039dd5530bc9b10b1d227f7", "save_path": "github-repos/lean/ImperialCollegeLondon-M1F_room_342_questions", "path": "github-repos/lean/ImperialCollegeLondon-M1F_room_342_questions/M1F_room_342_questions-63de9a6ab9c27a433039dd5530bc9b10b1d227f7/src/Rational_Powers/rational_powers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7724755061532501}}
{"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.polynomial.degree.definitions\n\n/-!\n# Cancel the leading terms of two polynomials\n\n## Definition\n\n* `cancel_leads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting.\n\n## Main Results\nThe degree of `cancel_leads` is less than that of the larger of the two polynomials being cancelled.\nThus it is useful for induction or minimal-degree arguments.\n-/\nnamespace polynomial\nnoncomputable theory\n\nvariables {R : Type*}\n\nsection comm_ring\nvariables [comm_ring R] (p q : polynomial R)\n\n/-- `cancel_leads p q` is formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting. -/\ndef cancel_leads : polynomial R :=\nC p.leading_coeff * X ^ (p.nat_degree - q.nat_degree) * q -\nC q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p\n\nvariables {p q}\n\n@[simp] lemma neg_cancel_leads : - p.cancel_leads q = q.cancel_leads p := neg_sub _ _\n\nlemma dvd_cancel_leads_of_dvd_of_dvd {r : polynomial R} (pq : p ∣ q) (pr : p ∣ r) :\n  p ∣ q.cancel_leads r :=\ndvd_sub (pr.trans (dvd.intro_left _ rfl)) (pq.trans (dvd.intro_left _ rfl))\n\nend comm_ring\n\nlemma nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree [comm_ring R] [is_domain R]\n  {p q : polynomial R} (h : p.nat_degree ≤ q.nat_degree) (hq : 0 < q.nat_degree) :\n  (p.cancel_leads q).nat_degree < q.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { convert hq,\n    simp [hp, cancel_leads], },\n  rw [cancel_leads, sub_eq_add_neg, tsub_eq_zero_iff_le.mpr h, pow_zero, mul_one],\n  by_cases h0 :\n      C p.leading_coeff * q + -(C q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p) = 0,\n  { convert hq,\n    simp only [h0, nat_degree_zero], },\n  have hq0 : ¬ q = 0,\n  { contrapose! hq,\n    simp [hq] },\n  apply lt_of_le_of_ne,\n  { rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree h0, ← degree_eq_nat_degree hq0],\n    apply le_trans (degree_add_le _ _),\n    rw ← leading_coeff_eq_zero at hp hq0,\n    simp only [max_le_iff, degree_C hp, degree_C hq0, le_refl q.degree, true_and, nat.cast_with_bot,\n      nsmul_one, degree_neg, degree_mul, zero_add, degree_X, degree_pow],\n    rw leading_coeff_eq_zero at hp hq0,\n    rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq0, ← with_bot.coe_add, with_bot.coe_le_coe,\n      tsub_add_cancel_of_le h], },\n  { contrapose! h0,\n    rw [← leading_coeff_eq_zero, leading_coeff, h0, mul_assoc, mul_comm _ p,\n      ← tsub_add_cancel_of_le h, add_comm _ p.nat_degree],\n    simp only [coeff_mul_X_pow, coeff_neg, coeff_C_mul, add_tsub_cancel_left, coeff_add],\n    rw [add_comm p.nat_degree, tsub_add_cancel_of_le h, ← leading_coeff, ← leading_coeff,\n      mul_comm _ q.leading_coeff, ← sub_eq_add_neg, ← mul_sub, sub_self, mul_zero] }\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/cancel_leads.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7722990203529551}}
{"text": "import data.real.basic\nimport data.list.range\n\n\ndef converges_to (s : ℕ → ℝ) (a : ℝ) :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, abs (s n - a) < ε\n\nvariables {s : ℕ → ℝ} {a : ℝ}\n\ntheorem exists_le_of_converges_to_ev (cs : converges_to s a) :\n  ∃ N b, ∀ n, N ≤ n → s n < b :=\nbegin\ncases cs 1 zero_lt_one with N h,\nuse [N , a + 1],\nintros n h₁,\nspecialize @h n h₁,\nhave h₂: s n - a ≤ abs(s n - a),\napply le_abs_self,\nsuffices h₃: s n - a < 1,\nexact sub_lt_iff_lt_add'.mp h₃,\napply lt_of_le_of_lt h₂ h,\nend\n\ntheorem exists_le_of_converges (cs : converges_to s a) :\n  ∃ b, ∀ n, s n < b :=\nbegin\ncases cs 1 zero_lt_one with N h,\nlet l := list.map (λ n, s ↑n) (list.range N.succ),\nhave : l.maximum ≠ ⊥,\n{ intro hl, rw [← with_bot.none_eq_bot, list.maximum_eq_none] at hl,\n  refine (list.ne_nil_of_length_eq_succ _) hl,\n    exact N,\n    { rw list.length_map, exact list.length_range (nat.succ N) },\n },\nlet lm : ℝ := with_bot.unbot l.maximum this,\nhave : l.maximum = ↑lm,\n  exact ((list.maximum l).coe_unbot this).symm,\n\nuse max lm a + 1,\nintro n,\ncases nat.lt_or_ge n N with hn hn,\n{ apply lt_of_le_of_lt _ (lt_add_one (max lm a)),\n  apply le_trans _ (le_max_left _ _),\n  apply list.le_maximum_of_mem _ this,\n  rw list.mem_map,\n  use n, split,\n    rw list.mem_range,\n    exact lt_of_lt_of_le hn (nat.le_succ N),\n    simp only [nat.cast_id], },\n{ have : a + 1 ≤ max lm a + 1,\n    simp only [add_le_add_iff_right, le_max_iff, le_refl, or_true],\n  refine lt_of_lt_of_le _ this,\n  let hn := (abs_lt.mp (h n hn)).right,\n  apply lt_add_of_neg_add_lt_left ,\n  rw [add_comm, ← sub_eq_add_neg],\n  exact hn }\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/convbound.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7722990188460594}}
{"text": "\nnamespace ex1\n    variables p q r : Prop\n\n    -- >>> Proofs <<< --\n\n    theorem and_commutes : p ∧ q ↔ q ∧ p :=\n        iff.intro\n            (λ pq, ⟨pq.right, pq.left⟩)\n            (λ qp, ⟨qp.right, qp.left⟩)\n\n    theorem or_commutes : p ∨ q ↔ q ∨ p :=\n        iff.intro\n            (λ pq, pq.elim (λ hp, or.inr hp) (λ hq, or.inl hq) )\n            (λ qp, qp.elim (λ hq, or.inr hq) (λ hp, or.inl hp))\n\n\n    theorem and_associates : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n        have ltr : (p ∧ q) ∧ r → p ∧ (q ∧ r), from λ hpqr, ⟨hpqr.left.left, ⟨hpqr.left.right, hpqr.right⟩⟩,\n        have rtl : p ∧ (q ∧ r) → (p ∧ q) ∧ r, from λ hpqr, ⟨⟨hpqr.left, hpqr.right.left⟩, hpqr.right.right⟩ ,\n        ⟨ltr, rtl⟩\n\n    theorem or_associates : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n        let ltr := λ (h : (p ∨ q) ∨ r),\n            h.elim\n                (λ hpq, hpq.elim (λ hp, or.inl hp) (λ hq, or.inr (or.inl hq)))\n                (λ hr, or.inr (or.inr hr)) in\n        let rtl := λ (h : p ∨ (q ∨ r)),\n            h.elim\n                (λ hp, or.inl (or.inl hp))\n                (λ hqr, hqr.elim (λ hq, or.inl (or.inr hq)) (λ hr, or.inr hr)) in\n        ⟨ltr, rtl⟩\n\n    theorem and_distributes : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n    have left_to_right : p ∧ (q ∨ r) → (p ∧ q) ∨ (p ∧ r), from\n        λ h, and.elim h (λ hp hqr, hqr.elim (λ hq, or.inl ⟨hp, hq⟩) (λ hr, or.inr ⟨hp, hr⟩)),\n\n    have right_to_left : (p ∧ q) ∨ (p ∧ r) → p ∧ (q ∨ r), from\n        λ h, or.elim h\n            (λ hpq, ⟨hpq.left, or.inl hpq.right⟩)\n            (λ hpr, ⟨hpr.left, or.inr hpr.right⟩),\n\n    ⟨left_to_right, right_to_left⟩\n\n\n    theorem or_distributes : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\n    have left_to_right : p ∨ (q ∧ r) → (p ∨ q) ∧ (p ∨ r), from\n        λ h, or.elim h\n            (λ hp, ⟨or.inl hp, or.inl hp⟩)\n            (λ hqr, ⟨or.inr hqr.left, or.inr hqr.right⟩),\n    have right_to_left : (p ∨ q) ∧ (p ∨ r) → p ∨ (q ∧ r), from\n        λ h, and.elim h\n            (λ h₁ h₂, h₁.elim (λ hp, or.inl hp) (λ hq, h₂.elim (λ hp, or.inl hp) (λ hr, or.inr ⟨hq, hr⟩))),\n    ⟨left_to_right, right_to_left⟩\n\n    theorem implication_flips (h : p → q) (hnq : ¬q): ¬p :=\n    assume hp : p,\n    absurd (h hp) hnq\n\n    theorem p_and_not_p_is_absurd : ¬(p ∧ ¬p) :=\n    assume h₁ : p ∧ ¬p,\n    absurd h₁.left h₁.right\n\n\n    -- negation is a powerful drug\n    theorem p_is_equivalent_to_not_p_is_absurd : ¬(p ↔ ¬p) :=\n    assume h,\n    have p_implies_not_p : p → ¬p, from iff.elim_left h,\n    have not_p_implies_p : ¬p → p, from iff.elim_right h,\n    have hnp : ¬p, from λ hp : p, absurd hp (p_implies_not_p hp),\n    absurd (not_p_implies_p hnp) hnp\n\n    theorem implication_composition : (p → (q → r)) ↔ (p ∧ q → r) :=\n    have left_to_right : (p → (q → r)) → (p ∧ q → r), from λ f₁, λ hpq, (f₁ hpq.left) hpq.right,\n    have right_to_left : (p ∧ q → r) → (p → (q → r)), from λ f₁ hp hq, f₁ (and.intro hp hq),\n    ⟨left_to_right, right_to_left⟩\n\n    theorem disjunct_implications_decomposition : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\n    have left_to_right : ((p ∨ q) → r) → (p → r) ∧ (q → r), from λ f, and.intro (λ hp, f $ or.inl hp) (λ hq, f $ or.inr hq),\n    have right_to_left : (p → r) ∧ (q → r) → ((p ∨ q) → r), from λ fs, λ hor, or.elim hor (λ hp, fs.left hp) (λ hq, fs.right hq),\n    ⟨left_to_right, right_to_left⟩\n\n    theorem de_morgan_disjunction : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n    have left_to_right : ¬(p ∨ q) → ¬p ∧ ¬q, from λ hnpq, and.intro (λ hp, hnpq (or.inl hp)) (λ hq, hnpq (or.inr hq)),\n    have right_to_left : ¬p ∧ ¬q → ¬(p ∨ q), from λ hnpq, assume p_or_q, or.elim p_or_q (λ hp, hnpq.left hp) (λ hq, hnpq.right hq),\n    ⟨left_to_right, right_to_left⟩\n\n    theorem disjunction_of_negations_implies_negation_of_conjunction : ¬p ∨ ¬q → ¬(p ∧ q) :=\n        λ h, assume p_and_q, or.elim h (λ hnp, hnp p_and_q.left) (λ hnq, hnq p_and_q.right)\n\n    theorem p_and_not_q_means_p_does_not_imply_q : p ∧ ¬q → ¬(p → q) := λ h, assume ptoq, absurd (ptoq h.left) h.right\n\n    theorem p_or_false_equivalent_to_p : p ∨ false ↔ p :=\n    have left_to_right : p ∨ false → p, from λ h, or.elim h (λ hp, hp) (λ ff, false.elim ff),\n    have right_to_left : p → p ∨ false, from λ hp, or.inl hp,\n    ⟨left_to_right, right_to_left⟩\n\n    theorem p_and_false_equivalent_to_false : p ∧ false ↔ false :=\n    have left_to_right : p ∧ false → false, from λ pair, pair.right,\n    have right_to_left : false → p ∧ false, from λ f, false.elim f,\n    ⟨left_to_right, right_to_left⟩\n\n    theorem not_p_or_q_implies_p_implies_q : (¬p ∨ q) → (p → q) := λ h, λ hp, or.elim h (λ hnp, absurd hp hnp) (λ hq, hq)\n\n    -- >>> Goals <<< --\n\n    -- commutativity of ∧ and ∨\n    example : p ∧ q ↔ q ∧ p := @and_commutes p q\n    example : p ∨ q ↔ q ∨ p := @or_commutes p q\n\n    -- associativity of ∧ and ∨\n    example : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := @and_associates p q r\n    example : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := @or_associates p q r\n\n    -- distributivity\n    example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := @and_distributes p q r\n    example : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := @or_distributes p q r\n\n    -- other properties\n    example : (p → (q → r)) ↔ (p ∧ q → r) := @implication_composition p q r\n    example : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := @disjunct_implications_decomposition p q r\n    example : ¬(p ∨ q) ↔ ¬p ∧ ¬q := @de_morgan_disjunction p q\n    example : ¬p ∨ ¬q → ¬(p ∧ q) := @disjunction_of_negations_implies_negation_of_conjunction p q\n    example : ¬(p ∧ ¬p) := @p_and_not_p_is_absurd p\n    example : p ∧ ¬q → ¬(p → q) := @p_and_not_q_means_p_does_not_imply_q p q\n    example : ¬p → (p → q) := assume hnp hp, absurd hp hnp\n    example : (¬p ∨ q) → (p → q) := @not_p_or_q_implies_p_implies_q p q\n    example : p ∨ false ↔ p := @p_or_false_equivalent_to_p p\n    example : p ∧ false ↔ false := @p_and_false_equivalent_to_false p\n    example : ¬(p ↔ ¬p) := @p_is_equivalent_to_not_p_is_absurd p\n    example : (p → q) → (¬q → ¬p) := @implication_flips p q\n\nend ex1\n\nsection ex2\n    open classical\n\n    variables p q r s : Prop\n\n    theorem long (h : p → r ∨ s) : (p → r) ∨ (p → s) :=\n    by_cases\n        (λ hp : p,\n            have r_or_s : r ∨ s, from h hp,\n            or.elim r_or_s (λ hr : r, or.inl (λ hp, hr)) (λ hs : s, or.inr (λ hp, hs))\n        )\n        (λ hnp : ¬p, or.inl (λ hp : p, absurd hp hnp))\n\n    theorem not_conjunction_implies_disjunction_of_nots (h : ¬(p ∧ q)) : ¬p ∨ ¬q :=\n    by_cases\n        (λ hp : p, by_cases (λ hq : q, false.elim $ h (and.intro hp hq)) (λ hnq : ¬q, or.inr hnq))\n        (λ hnp : ¬p, or.inl hnp)\n\n    theorem nptoq_to_p_and_nq (h : ¬(p → q)) : p ∧ ¬q :=\n    by_cases\n        (λ hq : q,\n            have p_to_q : p → q, from λ hp : p, hq,\n            false.elim $ absurd p_to_q h\n        )\n        (λ hnq : ¬q,\n            by_cases\n                (λ hp : p, and.intro hp hnq)\n                (λ hnp : ¬p,\n                    have p_to_q : p → q, from λ hp, absurd hp hnp,\n                    false.elim $ absurd p_to_q h\n                )\n        )\n\n    theorem p_implies_q_implies_not_p_or_q (h : p → q) : (¬p ∨ q) :=\n    or.elim (em p)\n        (λ hp, or.inr (h hp))\n        (λ hnp, or.inl hnp)\n\n    theorem give_this_one_a_name (h : ¬q → ¬p) (hp : p) : q :=\n    by_contradiction (\n        λ hnq,\n            have hnp : ¬p, from h hnq,\n            absurd hp hnp\n    )\n\n    theorem last_one (h : (p → q) → p) : p :=\n    or.elim (em p)\n        (@id p)\n        (λ hnp,\n            have p_to_q : p → q, from λ hp, absurd hp hnp,\n            show p, from h p_to_q\n        )\n\n    example : (p → r ∨ s) → ((p → r) ∨ (p → s)) := @long p r s\n    example : ¬(p ∧ q) → ¬p ∨ ¬q := @not_conjunction_implies_disjunction_of_nots p q\n    example : ¬(p → q) → p ∧ ¬q := @nptoq_to_p_and_nq p q\n    example : (p → q) → (¬p ∨ q) := @p_implies_q_implies_not_p_or_q p q\n    example : (¬q → ¬p) → (p → q) := @give_this_one_a_name p q\n    example : p ∨ ¬p := @em p\n    example : (((p → q) → p) → p) := @last_one p q\n\nend ex2\n\nsection ex3\n    variable p : Prop\n\n    example : ¬(p ↔ ¬p) := @ex1.p_is_equivalent_to_not_p_is_absurd p\nend ex3\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_take_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.77229901404312}}
{"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 data.nat.lattice\n\n/-!\n# Eventually constant sequences\n\nThis file defines eventually constant sequences and their properties.\n\n## Main definitions\n * `eventually_constant_seq`\n * `sequence_limit`\n-/\n\n/-- A sequence has the `is_eventually_constant` predicate if all the elements of the sequence\n  are eventually the same. -/\ndef is_eventually_constant {α : Type*} (a : ℕ → α) : Prop :=\n { n | ∀ m, n ≤ m → a (nat.succ m) = a m }.nonempty\n\n/-- An eventually constant sequence is a sequence which has the `is_eventually_constant`\n  predicate. -/\nstructure eventually_constant_seq {α : Type*} :=\n(to_seq : ℕ → α)\n(is_eventually_const : is_eventually_constant to_seq)\n\nnamespace eventually_constant_seq\n\n/-- The smallest number `m` for the sequence `a` such that `a n = a (n + 1)` for all `n ≥ m`. -/\nnoncomputable def sequence_limit_index' {α : Type*} (a : @eventually_constant_seq α) : ℕ :=\nInf { n | ∀ m, n ≤ m → a.to_seq m.succ = a.to_seq m }\n\n/-- The smallest number `m` for the sequence `a` such that `a n = a m` for all `n ≥ m`. -/\nnoncomputable def sequence_limit_index {α : Type*} (a : ℕ → α) : ℕ :=\nInf { n | ∀ m, n ≤ m → a n = a m }\n\n/-- The limit of an `eventually_constant_seq`. -/\nnoncomputable def sequence_limit {α : Type*} (a : @eventually_constant_seq α) :=\na.to_seq (sequence_limit_index' a)\n\nlemma sequence_limit_eq {α : Type*} (a : @eventually_constant_seq α) (m : ℕ)\n  (hm : sequence_limit_index' a ≤ m) : sequence_limit a = a.to_seq m :=\nbegin\n  rw sequence_limit,\n  induction m with d hd,\n  { rw nat.le_zero_iff at hm, rw hm, },\n  { have := nat.of_le_succ hm,\n    cases this,\n    { rw hd this,\n      refine (nat.Inf_mem a.is_eventually_const d _).symm,\n      exact this, },\n    { rw this, }, },\nend\n\nend eventually_constant_seq\n", "meta": {"author": "laughinggas", "repo": "p-adic-L-functions", "sha": "bfc0c84fabe9b89e3da79f95d7a8eacabe8a5bb7", "save_path": "github-repos/lean/laughinggas-p-adic-L-functions", "path": "github-repos/lean/laughinggas-p-adic-L-functions/p-adic-L-functions-bfc0c84fabe9b89e3da79f95d7a8eacabe8a5bb7/src/bernoulli_measure/eventually_constant_sequence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092415, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7722990123165654}}
{"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 number_theory.liouville.basic\nimport topology.metric_space.baire\nimport topology.instances.irrational\n\n/-!\n# Density of Liouville numbers\n\nIn this file we prove that the set of Liouville numbers form a dense `Gδ` set. We also prove a\nsimilar statement about irrational numbers.\n-/\n\nopen_locale filter\nopen filter set metric\n\nlemma set_of_liouville_eq_Inter_Union :\n  {x | liouville x} =\n    ⋂ n : ℕ, ⋃ (a b : ℤ) (hb : 1 < b), ball (a / b) (1 / b ^ n) \\ {a / b} :=\nbegin\n  ext x,\n  simp only [mem_Inter, mem_Union, liouville, mem_set_of_eq, exists_prop, mem_diff,\n    mem_singleton_iff, mem_ball, real.dist_eq, and_comm]\nend\n\nlemma is_Gδ_set_of_liouville : is_Gδ {x | liouville x} :=\nbegin\n  rw set_of_liouville_eq_Inter_Union,\n  refine is_Gδ_Inter (λ n, is_open.is_Gδ _),\n  refine is_open_Union (λ a, is_open_Union $ λ b, is_open_Union $ λ hb, _),\n  exact is_open_ball.inter is_closed_singleton.is_open_compl\nend\n\nlemma set_of_liouville_eq_irrational_inter_Inter_Union :\n  {x | liouville x} =\n    {x | irrational x} ∩ ⋂ n : ℕ, ⋃ (a b : ℤ) (hb : 1 < b), ball (a / b) (1 / b ^ n) :=\nbegin\n  refine subset.antisymm _ _,\n  { refine subset_inter (λ x hx, hx.irrational) _,\n    rw set_of_liouville_eq_Inter_Union,\n    exact Inter_subset_Inter (λ n, Union_subset_Union $ λ a, Union_subset_Union $\n      λ b, Union_subset_Union $ λ hb, diff_subset _ _) },\n  { simp only [inter_Inter, inter_Union, set_of_liouville_eq_Inter_Union],\n    refine Inter_subset_Inter (λ n, Union_subset_Union $ λ a, Union_subset_Union $\n      λ b, Union_subset_Union $ λ hb, _),\n    rw [inter_comm],\n    refine diff_subset_diff subset.rfl (singleton_subset_iff.2 ⟨a / b, _⟩),\n    norm_cast }\nend\n\n/-- The set of Liouville numbers is a residual set. -/\nlemma eventually_residual_liouville : ∀ᶠ x in residual ℝ, liouville x :=\nbegin\n  rw [filter.eventually, set_of_liouville_eq_irrational_inter_Inter_Union],\n  refine eventually_residual_irrational.and _,\n  refine eventually_residual.2 ⟨_, _, rat.dense_embedding_coe_real.dense.mono _, subset.rfl⟩,\n  { exact is_Gδ_Inter (λ n, is_open.is_Gδ $ is_open_Union $ λ a, is_open_Union $\n      λ b, is_open_Union $ λ hb, is_open_ball) },\n  { rintro _ ⟨r, rfl⟩,\n    simp only [mem_Inter, mem_Union],\n    refine λ n, ⟨r.num * 2, r.denom * 2, _, _⟩,\n    { have := int.coe_nat_le.2 r.pos, rw int.coe_nat_one at this, linarith },\n    { convert mem_ball_self _ using 2,\n      { norm_cast, field_simp },\n      { refine one_div_pos.2 (pow_pos (int.cast_pos.2 _) _),\n        exact mul_pos (int.coe_nat_pos.2 r.pos) zero_lt_two } } }\nend\n\n/-- The set of Liouville numbers in dense. -/\nlemma dense_liouville : dense {x | liouville x} :=\ndense_of_mem_residual eventually_residual_liouville\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/liouville/residual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7722550734109926}}
{"text": "-- Setup for doing the topology problem sheet 2 exercise 4\nimport analysis.topology.continuity\nimport analysis.topology.topological_space\nimport analysis.topology.infinite_sum\nimport analysis.topology.topological_structures\nimport analysis.topology.uniform_space\n\nuniverse u\n\nopen set filter lattice classical\n\n-- A function that checks if a collection is sets satisfies the axioms of a topology\ndefinition is_open_sets {α : Type u} (is_open : set α → Prop) :=\n  is_open univ ∧ (∀s t, is_open s → is_open t → is_open (s ∩ t)) ∧ (∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))\n\n-- A function that converts a proof that a collection of sets satisfies the axioms of a topology into an actual topology (see the definition of a topology in mathlib)\ndefinition is_to_top {α : Type u} (is_open : set α → Prop) (H : is_open_sets (is_open)) : topological_space α :=\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\n-- A function that converts a topology into a proof that the given collection of sets satisfies the axioms of a topology.\ndefinition top_to_is {α : Type u} (T : topological_space α) : is_open_sets (T.is_open) :=\n⟨T.is_open_univ,T.is_open_inter,T.is_open_sUnion⟩\n\n-- A proof that given two collections of sets that satisfy the axioms of a topology, their intersection satisfies the axioms of a topology.\ntheorem exercisefoura {α : Type u} {T1_sets T2_sets : set α → Prop} : is_open_sets T1_sets → is_open_sets T2_sets → is_open_sets (λ (a : set α), and (T1_sets a) (T2_sets a) :=\nbegin\nintros H1 H2,\nunfold is_open_sets,\nsplit,\nexact ⟨H1.left, H2.left⟩,\nsplit,\nintros s t H3 H4,\nexact ⟨H1.right.left s t H3.left H4.left, H2.right.left s t H3.right H4.right⟩,\nintros I H3,\nsplit,\nhave H4 : ∀ (t : set α), t ∈ I → T1_sets t,\nintros A H5,\nexact (H3 A H5).left,\nexact H1.right.right I H4,\nhave H4 :  ∀ (t : set α), t ∈ I → T2_sets t,\nintros A H5,\nexact (H3 A H5).right,\nexact H2.right.right I H4,\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/Problem_Sheets/ps_2_ex4a.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7722550659977887}}
{"text": "import Mathlib.Data.Real.Basic\nvariable (P Q R S : Prop)\nvariable (A B C D : Type)\nvariable (a b c d k m n x: ℕ)\nopen Function Set\n/-\n# Logic\n\nIn Lean a `Prop` is any true/false statement. \n\nFor example: `3 = 2`  or `x = 7 → x is prime` or \n`∀ (n:ℕ), 2 ∣ n` or `∃ (k:ℕ), even k ∧ ¬ prime k` -/\n\n--#check 3 = 2\n--#check x = 7 → prime x\n--#check ∀ (n:ℕ), 2 ∣ n\n--#check ∃ (k:ℕ), even k ∧ ¬ prime k\n\n/-\nIf we have `(P : Prop)` then `P` is a proposition, so it is\na statement that is either true or false. \n\nSo what is `(hp : P)`? It is simply a proof that P is true.\nOr equivalently `hp` is the hypothesis that P is true.\n\n# Tactics\n\nWe will use the three basic tactics from last time: `exact`, `intro`, `apply`\n\n# exact\nIf our goal is `⊢ P` and we have a term `hp : P` then \nwe can close it with `exact hp`\n\n# intro(s)\nIf our goal is `⊢ P → Q` then `intro hp` introduces a term `(hp : P)`\ninto our local context and our goal changes to `⊢ Q`.\n\n# apply\nIf our goal is `⊢ Q` and we have a term `(hpq : P → Q)` then\n`apply hpq` changes our goal to `⊢ P`\n\n(We think of this as : we know `P implies Q`, so if our goal is `Q` it\nsuffices to prove `P` and then `Q` follows.) \n\n# New tactic: refl\n\n# refl \nIf our goal can be proved by `reflexivity` then `refl` will close it.\nFor example  `P = P` or `P ↔ P` -/\n\n-- 01 `if and only if` `↔` is reflexive so refl works here\nexample : P ↔ P :=\nby\n  rfl\n\n\n-- 02 Equality is also reflexive so again `refl` will work\nexample : P = P := \nby\n  rfl\n\n\n/- Unless told otherwise, Lean assumes numerals refer to natural\nnumbers i.e. ℕ = {0, 1, 2,...} also known as `nats`.\n\nIf we do operations such as ` + - / * ^ % ` with nats then the result is\nalso a nat. -/\n\n-- 03\nexample : 1 + 1 = 2 :=\nby\n  rfl\n\n-- 04 \nexample : 12 * 25 = 300 :=\nby\n  rfl\n\n\n-- 05\nexample : 7 - 3 = 2 ^ 2 :=\nby\n  rfl\n\n\n-- 06\nexample : 2 - 3 = 0 := -- yes 2 - 3 = 0 in Lean\nby\n  rfl\n\n\n-- 07  `a % b` is the remainder of `a` after division by `b`.\nexample : 18 % 7 = 4:=\nby\n  rfl\n\n-- 08  Remember everything here is a natural number\nexample (n : ℕ): (12 / 5)^4  = 4^(5 / 2) * n^ (3 - 4) :=\nby\n  rfl\n\n\n-- 09 `refl` can also see through definitions \nexample  (f : A → B) : Injective f ↔ ∀ (x y : A), f x = f y → x = y :=\nby\n  rfl\n\n\n-- 10 \nexample (f : A → B) : Surjective f ↔ ∀ (b:B), ∃ (a:A), f a = b:=\nby\n  rfl\n\n\n/- We give the next example a name because it captures one of the fundmental \n   properties of `Prop` in Lean: \n           `Any two proofs of the same Prop are equal` -/\n-- 11 \nlemma proof_irrelevance (P : Prop) (h1 : P) (h2 : P) : h1 = h2:=\nby\n  rfl\n\n\n/- The same isn't true for most Types. \n   [Qu: what can you say about types for which this is true?] -/\n-- 12\nexample (A : Type) (a1 : A) (a2 : A) : a1 = a2:=\nby \n  sorry -- don't try to prove this it isn't true without further assumptions about A!\n\n\n-- 13 Any proposition implies itself\nexample  : P → P :=\nby\n  intro hp -- introduce the hypothesis `hp : P` in the local context\n            -- our goal is now `⊢ P` so we can accomplish this with\n  exact hp\n\n\n-- 14 If P is true and P → Q is true then Q is true\nexample (hp : P) (hpq : P → Q) : Q :=\nby\n  exact hpq hp\n\n\n\n/-  # There is no special `implies` symbol in Lean\n\nAs we have just seen we don't have a different symbol for `implies` we just reuse `→` \nthat was introduced earlier for functions. \n\nSo if `(A B : Type)` and `(P Q : Prop)` what is the difference between\n `f : A → B` and `hpq : P → Q` ?\n\n`f` is a function mapping terms of type `A` to terms of type `B`, while `hpq` is a \nfunction mapping terms of type `P` to terms of type `Q`. \n\nThe crucial difference is that `A` and `B` have type `Type` while `P` and `Q` have \ntype `Prop`\n\nInterpreting a term of type `P` as a proof of `P` then we can think of `hpq : P → Q` as \na function mapping proofs of P to proofs of Q. -/\n\n\n-- 15\nexample : P → Q → P :=\nby\n  intro hp _\n  exact hp\n\n\n-- 16\nexample : P → (P → Q) → (Q → R) → R :=\nby\n  intro p pq qr\n  apply qr\n  apply pq \n  exact p\n\n\n-- 17\nexample  : (P → Q → R) → (Q → R → P) → (R → Q → P) :=\nby\n  intro _ qrp r q\n  apply qrp \n  exact q\n  exact r\n\n\n/-\n# New tactic: rw\n\n# rw\nrw is short for rewrite, it allows us to rewrite using equations and equivalences.\n\nFor example if we have `h : a = b` and our goal is `⊢ a + c = b + c` then `rw h` will replace\n`a` by `b` in the goal so it becomes `⊢ b + c = b + c`  (which we can then close with `refl`) \n\nWe can tell `rw` to do the rewrite on a term in our local context.\nFor example if we have `h1 : a = b` and `h2 : a = c` we can use `rw h1 at h2` to convert h2\ninto `h2 : b = c`\n\nrw works from left to right, so given `h : a = b`, `rw h` will replace each `a` in the goal by `b`.\nIf we want to instead replace each `b` by `a` we can use `rw ← h` to rewrite from right to left.  -/\n\n-- 18 We can do this be rewriting \nexample (h1 : a = b) (h2 : b = c) (h3: c = d) : a = d:=\nby\n  rwa [h1,h2]\n\n\n-- 19 We start with a rewrite in the local context\nexample (h1 : a = b) (h2 : b = c) (h3: c = d) : a = d :=\nby\n  rw [h1] \n  rwa [h3] at h2\n\n\n-- 20 We can start by rewriting from right to left using `hqr : Q ↔ R`\nexample  (hpq : P ↔ Q) (hqr : Q ↔ R) : P ↔ R:=\nby\n  rwa [hpq]\n \n\n\n-- 21\nexample  (f g : A → B) (hfg : Injective f ↔ Injective g) \n(hg : ∀ (x y: A), g x = g y → x = y)  : Injective f:=\nby\n   rw [hfg]\n   intro a b h\n   apply hg\n   assumption\n\n\n-- 22 -- symmetry may be useful here..\nexample (f: A → ℕ) (x y : A) (hf : f x = f y → x = y) \n(hfx: f x = n) (hfy: f y = m) (heq: m = n) : x = y:=\nby  \n  apply hf\n  rw [hfx,hfy]\n  exact heq.symm\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/2_logic/basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7722201337222926}}
{"text": "import data.set.basic -- hide\nimport data.set.finite -- hide\nopen set -- hide\n/-\nWe will use the following lemma when we start proving facts about topological spaces.\n\nIt seems clear that we want to use induction, so we can try to apply the `finite.induction_on`\nlemma. But be careful on how you apply it, or you will be left with an impossible goal.\n\nFor the inductive step, the lemmas `sInter_insert`, `mem_insert_iff` and `forall_eq_or_imp`\nmay be useful, as well as the `simp` tactic.\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nThe `finite.induction_on` lemma allows to prove something of the form `P S` for all finite sets `S`.\nSo apply `finite.induction_on hfin` looks like it's making progress. However, the induction\nhypothesis you will be left with is too weak. Try instead starting with `revert hS`, and\nsee why this helps.\n-/\n\nvariables {X Y : Type} -- hide\n\n/- Lemma : no-side-bar\nIf P is a property of sets which is closed under pairwise intersection then it is also closed under\narbitrary finite interesctions.\n-/\nlemma sInter_of_inter (P : set X → Prop) (huniv : P univ) (hinter : ∀ A B : set X, P A → P B → P (A ∩ B))\n(S : set (set X)) (hfin : finite S) (hS : ∀ s ∈ S, P s) : P ( sInter S ) :=\nbegin\n  revert hS,\n  apply finite.induction_on hfin,\n  { \n    simp,\n    exact huniv,\n  },\n  {\n    intros U S hUS hSfin hind h,\n    have h : ⋂₀ insert U S = (⋂₀ S) ∩ U, by finish,\n    rw h,\n    apply hinter;\n    finish,\n  }\nend\n\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/set_theory_world/level10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7722089052974997}}
{"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.mv_polynomial.rename\nimport data.mv_polynomial.comm_ring\nimport algebra.algebra.subalgebra.basic\n\n/-!\n# Symmetric Polynomials and Elementary Symmetric Polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\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 σ R n`, is the `n`th elementary symmetric polynomial in `mv_polynomial σ R`.\n\nAs in other polynomial files, we typically use the notation:\n\n+ `σ τ : 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 : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians\n\n+ `φ ψ : mv_polynomial σ R`\n\n-/\n\nopen equiv (perm)\nopen_locale big_operators\nnoncomputable theory\n\nnamespace multiset\n\nvariables {R : Type*} [comm_semiring R]\n\n/-- The `n`th elementary symmetric function evaluated at the elements of `s` -/\ndef esymm (s : multiset R) (n : ℕ) : R := ((s.powerset_len n).map multiset.prod).sum\n\nlemma _root_.finset.esymm_map_val {σ} (f : σ → R) (s : finset σ) (n : ℕ) :\n  (s.val.map f).esymm n = (s.powerset_len n).sum (λ t, t.prod f) :=\nby simpa only [esymm, powerset_len_map, ← finset.map_val_val_powerset_len, map_map]\n\nend multiset\n\nnamespace mv_polynomial\n\nvariables {σ : Type*} {R : Type*}\nvariables {τ : Type*} {S : Type*}\n\n/-- A `mv_polynomial φ` is symmetric if it is invariant under\npermutations of its variables by the  `rename` operation -/\ndef is_symmetric [comm_semiring R] (φ : mv_polynomial σ R) : Prop :=\n∀ e : perm σ, rename e φ = φ\n\nvariables (σ R)\n\n/-- The subalgebra of symmetric `mv_polynomial`s. -/\ndef symmetric_subalgebra [comm_semiring R] : subalgebra R (mv_polynomial σ R) :=\n{ carrier := set_of is_symmetric,\n  algebra_map_mem' := λ r e, rename_C e r,\n  mul_mem' := λ a b ha hb e, by rw [alg_hom.map_mul, ha, hb],\n  add_mem' := λ a b ha hb e, by rw [alg_hom.map_add, ha, hb] }\n\nvariables {σ R}\n\n@[simp] lemma mem_symmetric_subalgebra [comm_semiring R] (p : mv_polynomial σ R) :\n  p ∈ symmetric_subalgebra σ R ↔ p.is_symmetric := iff.rfl\n\nnamespace is_symmetric\n\nsection comm_semiring\nvariables [comm_semiring R] [comm_semiring S] {φ ψ : mv_polynomial σ R}\n\n@[simp]\nlemma C (r : R) : is_symmetric (C r : mv_polynomial σ R) :=\n(symmetric_subalgebra σ R).algebra_map_mem r\n\n@[simp]\nlemma zero : is_symmetric (0 : mv_polynomial σ R) :=\n(symmetric_subalgebra σ R).zero_mem\n\n@[simp]\nlemma one : is_symmetric (1 : mv_polynomial σ R) :=\n(symmetric_subalgebra σ R).one_mem\n\nlemma add (hφ : is_symmetric φ) (hψ : is_symmetric ψ) : is_symmetric (φ + ψ) :=\n(symmetric_subalgebra σ R).add_mem hφ hψ\n\nlemma mul (hφ : is_symmetric φ) (hψ : is_symmetric ψ) : is_symmetric (φ * ψ) :=\n(symmetric_subalgebra σ R).mul_mem hφ hψ\n\n\n\n@[simp]\nlemma map (hφ : is_symmetric φ) (f : R →+* S) : is_symmetric (map f φ) :=\nλ e, by rw [← map_rename, hφ]\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring R] {φ ψ : mv_polynomial σ R}\n\nlemma neg (hφ : is_symmetric φ) : is_symmetric (-φ) :=\n(symmetric_subalgebra σ R).neg_mem hφ\n\nlemma sub (hφ : is_symmetric φ) (hψ : is_symmetric ψ) : is_symmetric (φ - ψ) :=\n(symmetric_subalgebra σ R).sub_mem hφ hψ\n\nend comm_ring\n\nend is_symmetric\n\nsection elementary_symmetric\nopen finset\nvariables (σ R) [comm_semiring R] [comm_semiring S] [fintype σ] [fintype τ]\n\n/-- The `n`th elementary symmetric `mv_polynomial σ R`. -/\ndef esymm (n : ℕ) : mv_polynomial σ R :=\n∑ t in powerset_len n univ, ∏ i in t, X i\n\n/-- The `n`th elementary symmetric `mv_polynomial σ R` is obtained by evaluating the\n`n`th elementary symmetric at the `multiset` of the monomials -/\nlemma esymm_eq_multiset_esymm : esymm σ R = (finset.univ.val.map X).esymm :=\nfunext $ λ n, (finset.univ.esymm_map_val X n).symm\n\nlemma aeval_esymm_eq_multiset_esymm [algebra R S] (f : σ → S) (n : ℕ) :\n  aeval f (esymm σ R n) = (finset.univ.val.map f).esymm n :=\nby simp_rw [esymm, aeval_sum, aeval_prod, aeval_X, esymm_map_val]\n\n/-- We can define `esymm σ R n` by summing over a subtype instead of over `powerset_len`. -/\nlemma esymm_eq_sum_subtype (n : ℕ) : esymm σ R n =\n  ∑ t : {s : finset σ // s.card = n}, ∏ i in (t : finset σ), X i :=\nsum_subtype _ (λ _, mem_powerset_len_univ_iff) _\n\n/-- We can define `esymm σ R n` as a sum over explicit monomials -/\nlemma esymm_eq_sum_monomial (n : ℕ) : esymm σ R n =\n  ∑ t in powerset_len n univ, monomial (∑ i in t, finsupp.single i 1) 1 :=\nbegin\n  simp_rw monomial_sum_one,\n  refl,\nend\n\n@[simp] lemma esymm_zero : esymm σ R 0 = 1 :=\nby simp only [esymm, powerset_len_zero, sum_singleton, prod_empty]\n\nlemma map_esymm (n : ℕ) (f : R →+* S) : map f (esymm σ R n) = esymm σ S n :=\nby simp_rw [esymm, map_sum, map_prod, map_X]\n\nlemma rename_esymm (n : ℕ) (e : σ ≃ τ) : rename e (esymm σ R n) = esymm τ R n :=\ncalc rename e (esymm σ R n)\n     = ∑ x in powerset_len n univ, ∏ i in x, X (e i)\n       : by simp_rw [esymm, map_sum, map_prod, rename_X]\n ... = ∑ t in powerset_len n (univ.map e.to_embedding), ∏ i in t, X i\n       : by simp [finset.powerset_len_map, -finset.map_univ_equiv]\n ... = ∑ t in powerset_len n univ, ∏ i in t, X i : by rw finset.map_univ_equiv\n\nlemma esymm_is_symmetric (n : ℕ) : is_symmetric (esymm σ R n) :=\nby { intro, rw rename_esymm }\n\nlemma support_esymm'' (n : ℕ) [decidable_eq σ] [nontrivial R] :\n  (esymm σ R n).support = (powerset_len n (univ : finset σ)).bUnion\n    (λ t, (finsupp.single (∑ (i : σ) in t, finsupp.single i 1) (1:R)).support) :=\nbegin\n  rw esymm_eq_sum_monomial,\n  simp only [← single_eq_monomial],\n  convert finsupp.support_sum_eq_bUnion (powerset_len n (univ : finset σ)) _,\n  intros s t hst,\n  rw finset.disjoint_left,\n  simp only [finsupp.support_single_ne_zero _ one_ne_zero, mem_singleton],\n  rintro a 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 : ℕ) [decidable_eq σ] [nontrivial R] :\n  (esymm σ R n).support =\n  (powerset_len n (univ : finset σ)).bUnion (λ t, {∑ (i : σ) 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 : ℕ) [decidable_eq σ] [nontrivial R] :\n  (esymm σ R n).support =\n  (powerset_len n (univ : finset σ)).image (λ t, ∑ (i : σ) in t, finsupp.single i 1) :=\nby { rw support_esymm', exact bUnion_singleton }\n\nlemma degrees_esymm [nontrivial R]\n  (n : ℕ) (hpos : 0 < n) (hn : n ≤ fintype.card σ) :\n  (esymm σ R n).degrees = (univ : finset σ).val :=\nbegin\n  classical,\n  have : (finsupp.to_multiset ∘ λ (t : finset σ), ∑ (i : σ) 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, ←comp_sup_eq_sup_comp],\n  { obtain ⟨k, rfl⟩ := 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": "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/symmetric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7722089052974997}}
{"text": "inductive bool_var : Type\n| mk (n : nat)\n\nopen bool_var\n\n/-\nAbstract syntax\n-/\ninductive bool_expr : Type\n| lit_expr : bool → bool_expr \n| var_expr : bool_var → bool_expr\n| and_expr : bool_expr → bool_expr → bool_expr \n| or_expr : bool_expr → bool_expr → bool_expr \n| impl_expr : bool_expr → bool_expr → bool_expr   -- New\n| not_expr : bool_expr → bool_expr \n\nopen bool_expr \n\n/-\nConcrete syntax\n-/\nnotation e1 ∧ e2 := and_expr e1 e2\nnotation e1 ∨ e2 := or_expr e1 e2\nnotation ¬e := not_expr e\nnotation `[` b `]` := lit_expr b\nnotation `[` v `]` := var_expr v\nreserve infixr `=>`:67                          -- New\nnotation e1 => e2 := impl_expr e1 e2            -- New    \n\n/-\nSemantics\n-/\n\n-- Boolean implies function, not provided by Lean\ndef bimp : bool → bool → bool \n| tt ff := ff\n| _ _ := tt\n\ndef bool_eval : bool_expr → (bool_var → bool) → bool\n| (lit_expr b) _ := b\n| (var_expr v) st := st v \n| (and_expr e1 e2) st := band (bool_eval e1 st) (bool_eval e2 st)\n| (or_expr e1 e2) st := bor (bool_eval e1 st) (bool_eval e2 st)\n| (impl_expr e1 e2) st := bimp (bool_eval e1 st) (bool_eval e2 st) -- New\n| (not_expr e) st := bnot (bool_eval e st)\n\n/-\nTesting -- traditional, run program, compare to expected output\n-/\n\ndef true_expr : bool_expr := [tt]\ndef false_expr : bool_expr := [ff]\ndef e1 := [tt] ∧ [ff]\ndef e2 := e1 ∨  [tt]\n\n-- Let's name some variables\n\ndef Pvar := (bool_var.mk 0)\ndef Qvar := (bool_var.mk 1)\ndef Rvar := (bool_var.mk 2)\n\n-- One possible state: giving values to variables\ndef bool_state_4 : bool_var → bool :=\nλ v, \nmatch v with\n  | (bool_var.mk 0) := tt\n  | (bool_var.mk 1) := ff\n  | (bool_var.mk 2) := ff\n  | _ := ff\n  end\n\n/-\nInformal testing: run code, compare actual to expected output\n-/\n#eval bool_eval e2 bool_state_4  -- expect tt\n\n/-\nTesting as proving theorems about specific inputs (not ∀ propositions)\n-/\nexample : bool_eval e2 bool_state_4 = tt := rfl\nexample : bool_eval (¬e2 ∨ e1) bool_state_4 = ff := rfl\n\n-- An expression with variable expressions as subexpressions\ndef e5' := [Pvar] ∧ [Qvar]\n\n/-\nProperties\n-/\n\n-- Oops, this proof broke when we added state as an argument\n\ntheorem and_connective_commutes : ∀ (e1 e2 : bool_expr), \n  bool_eval (e1 ∧ e2) = bool_eval (e2 ∧ e1) \n  :=\nbegin\n  assume e1 e2,\n  simp [bool_eval],\n  cases (bool_eval e1),\n  cases (bool_eval e2),\n  apply rfl,\n  apply rfl,\n  cases (bool_eval e2),\n  repeat {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/langs/bool_expr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7721548055971104}}
{"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\nimport algebra.ring.basic\nimport algebra.algebra.basic\nimport algebra.group_power.basic\nimport algebra.field_power\nimport algebra.opposites\n\n/-!  # Squares, even and odd elements\n\nThis file proves some general facts about squares, even and odd elements of semirings.\n\nIn the implementation, we define `is_square` and we let `even` be the notion transported by\n`to_additive`.  The definition are therefore as follows:\n```lean\nis_square a ↔ ∃ r, a = r * r\neven a ↔ ∃ r, a = r + r\n```\n\nOdd elements are not unified with a multiplicative notion.\n\n## Future work\n\n* TODO: Try to generalize further the typeclass assumptions on `is_square/even`.\n  For instance, in some cases, there are `semiring` assumptions that I (DT) am not convinced are\n  necessary.\n* TODO: Consider moving the definition and lemmas about `odd` to a separate file.\n* TODO: The \"old\" definition of `even a` asked for the existence of an element `c` such that\n  `a = 2 * c`.  For this reason, several fixes introduce an extra `two_mul` or `← two_mul`.\n  It might be the case that by making a careful choice of `simp` lemma, this can be avoided.\n -/\n\nopen mul_opposite\nvariables {α β : Type*}\n\n/--  An element `a` of a type `α` with multiplication satisfies `square a` if `a = r * r`,\nfor some `r : α`. -/\n@[to_additive\n\"An element `a` of a type `α` with addition satisfies `even a` if `a = r + r`,\nfor some `r : α`.\"]\ndef is_square [has_mul α] (a : α) : Prop := ∃ r, a = r * r\n\n@[simp, to_additive]\nlemma is_square_mul_self [has_mul α] (m : α) : is_square (m * m) := ⟨m, rfl⟩\n\n@[to_additive even_iff_exists_two_nsmul]\nlemma is_square_iff_exists_sq [monoid α] (m : α) : is_square m ↔ ∃ c, m = c ^ 2 :=\nby simp [is_square, pow_two]\n\nalias is_square_iff_exists_sq ↔ is_square.exists_sq is_square_of_exists_sq\n\nattribute [to_additive even.exists_two_nsmul] is_square.exists_sq\n/-- Alias of the forwards direction of `even_iff_exists_two_nsmul`. -/\nadd_decl_doc even.exists_two_nsmul\n\nattribute [to_additive even_of_exists_two_nsmul] is_square_of_exists_sq\n/-- Alias of the backwards direction of `even_iff_exists_two_nsmul`. -/\nadd_decl_doc even_of_exists_two_nsmul\n\n@[simp, to_additive even_two_nsmul]\nlemma is_square_sq [monoid α] (a : α) : is_square (a ^ 2) := ⟨a, pow_two _⟩\n\n@[simp, to_additive]\nlemma is_square_one [mul_one_class α] : is_square (1 : α) := ⟨1, (mul_one _).symm⟩\n\n@[to_additive]\nlemma is_square.map {F : Type*} [mul_one_class α] [mul_one_class β] [monoid_hom_class F α β]\n  {m : α} (f : F) (hm : is_square m) :\n  is_square (f m) :=\nbegin\n  rcases hm with ⟨m, rfl⟩,\n  exact ⟨f m, by simp⟩\nend\n\n@[to_additive]\nlemma is_square.mul_is_square [comm_monoid α] {m n : α} (hm : is_square m) (hn : is_square n) :\n  is_square (m * n) :=\nbegin\n  rcases hm with ⟨m, rfl⟩,\n  rcases hn with ⟨n, rfl⟩,\n  refine ⟨m * n, mul_mul_mul_comm m m n n⟩,\nend\n\nsection group\nvariable [group α]\n\n@[to_additive]\nlemma is_square_op_iff (a : α) : is_square (op a) ↔ is_square a :=\n⟨λ ⟨c, hc⟩, ⟨unop c, by rw [← unop_mul, ← hc, unop_op]⟩, λ ⟨c, hc⟩, by simp [hc]⟩\n\n@[simp, to_additive] lemma is_square_inv (a : α) : is_square a⁻¹ ↔ is_square a :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { rw [← is_square_op_iff, ← inv_inv a],\n    exact h.map (mul_equiv.inv' α) },\n  { exact ((is_square_op_iff a).mpr h).map (mul_equiv.inv' α).symm }\nend\n\nend group\n\nsection comm_group\nvariable [comm_group α]\n\n@[to_additive]\nlemma is_square.div_is_square {m n : α} (hm : is_square m) (hn : is_square n) : is_square (m / n) :=\nby { rw div_eq_mul_inv,  exact hm.mul_is_square ((is_square_inv n).mpr hn) }\n\nend comm_group\n\nsection semiring\nvariables [semiring α] [semiring β] {m n : α}\n\nlemma even_iff_exists_two_mul (m : α) : even m ↔ ∃ c, m = 2 * c :=\nby simp [even_iff_exists_two_nsmul]\n\nlemma even_iff_two_dvd {a : α} : even a ↔ 2 ∣ a := by simp [even, has_dvd.dvd, two_mul]\n\n@[simp] lemma range_two_mul (α : Type*) [semiring α] :\n  set.range (λ x : α, 2 * x) = {a | even a} :=\nby { ext x, simp [eq_comm, two_mul, even] }\n\n@[simp] lemma even_bit0 (a : α) : even (bit0 a) :=\n⟨a, rfl⟩\n\n@[simp] lemma even_two : even (2 : α) := ⟨1, rfl⟩\n\n@[simp] lemma even.mul_left (hm : even m) (n) : even (n * m) :=\nhm.map (add_monoid_hom.mul_left n)\n\n@[simp] lemma even.mul_right (hm : even m) (n) : even (m * n) :=\nhm.map (add_monoid_hom.mul_right n)\n\nlemma even_two_mul (m : α) : even (2 * m) := ⟨m, two_mul _⟩\n\nlemma even.pow_of_ne_zero (hm : even m) : ∀ {a : ℕ}, a ≠ 0 → even (m ^ a)\n| 0       a0 := (a0 rfl).elim\n| (a + 1) _  := by { rw pow_succ, exact hm.mul_right _ }\n\nsection with_odd\n\n/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/\ndef odd (a : α) : Prop := ∃ k, a = 2*k + 1\n\n@[simp] lemma odd_bit1 (a : α) : odd (bit1 a) :=\n⟨a, by rw [bit1, bit0, two_mul]⟩\n\n@[simp] lemma range_two_mul_add_one (α : Type*) [semiring α] :\n  set.range (λ x : α, 2 * x + 1) = {a | odd a} :=\nby { ext x, simp [odd, eq_comm] }\n\nlemma even.add_odd (hm : even m) (hn : odd n) : odd (m + n) :=\nbegin\n  rcases hm with ⟨m, rfl⟩,\n  rcases hn with ⟨n, rfl⟩,\n  exact ⟨m + n, by rw [mul_add, ← two_mul, add_assoc]⟩\nend\n\nlemma odd.add_even (hm : odd m) (hn : even n) : odd (m + n) :=\nby { rw add_comm, exact hn.add_odd hm }\n\nlemma odd.add_odd (hm : odd m) (hn : odd n) : even (m + n) :=\nbegin\n  rcases hm with ⟨m, rfl⟩,\n  rcases hn with ⟨n, rfl⟩,\n  refine ⟨n + m + 1, _⟩,\n  rw [← two_mul, ←add_assoc, add_comm _ (2 * n), ←add_assoc, ←mul_add, add_assoc, mul_add _ (n + m),\n    mul_one],\n  refl\nend\n\n@[simp] lemma odd_one : odd (1 : α) :=\n⟨0, (zero_add _).symm.trans (congr_arg (+ (1 : α)) (mul_zero _).symm)⟩\n\n@[simp] lemma odd_two_mul_add_one (m : α) : odd (2 * m + 1) := ⟨m, rfl⟩\n\nlemma ring_hom.odd (f : α →+* β) (hm : odd m) : odd (f m) :=\nbegin\n  rcases hm with ⟨m, rfl⟩,\n  exact ⟨f m, by simp [two_mul]⟩\nend\n\n@[simp] lemma odd.mul_odd (hm : odd m) (hn : odd n) : odd (m * n) :=\nbegin\n  rcases hm with ⟨m, rfl⟩,\n  rcases hn with ⟨n, rfl⟩,\n  refine ⟨2 * m * n + n + m, _⟩,\n  rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc,\n    ← nat.cast_two, ← nat.cast_comm],\nend\n\nlemma odd.pow (hm : odd m) : ∀ {a : ℕ}, odd (m ^ a)\n| 0       := by { rw pow_zero, exact odd_one }\n| (a + 1) := by { rw pow_succ, exact hm.mul_odd odd.pow }\n\nend with_odd\n\nend semiring\n\nsection ring\nvariables [ring α] {m n : α}\n\n@[simp] lemma even_neg_two : even (- 2 : α) := by simp only [even_neg, even_two]\n\nlemma even_abs [linear_order α] {a : α} : even (|a|) ↔ even a :=\nbegin\n  rcases abs_choice a with h | h; rw h,\n  exact even_neg a,\nend\n\nlemma odd.neg {a : α} (hp : odd a) : odd (-a) :=\nbegin\n  obtain ⟨k, hk⟩ := hp,\n  use -(k + 1),\n  rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add,\n    neg_add_cancel_right, ←neg_add, hk],\nend\n\n@[simp] lemma odd_neg (a : α) : odd (-a) ↔ odd a :=\n⟨λ h, neg_neg a ▸ h.neg, odd.neg⟩\n\n@[simp] lemma odd_neg_one : odd (- 1 : α) := by simp\n\ntheorem odd.sub_even (hm : odd m) (hn : even n) : odd (m - n) :=\nby { rw sub_eq_add_neg, exact hm.add_even ((even_neg n).mpr hn) }\n\ntheorem even.sub_odd (hm : even m) (hn : odd n) : odd (m - n) :=\nby { rw sub_eq_add_neg, exact hm.add_odd ((odd_neg n).mpr hn) }\n\nlemma odd.sub_odd (hm : odd m) (hn : odd n) : even (m - n) :=\nby { rw sub_eq_add_neg, exact hm.add_odd ((odd_neg n).mpr hn) }\n\nlemma odd_abs [linear_order α] {a : α} : odd (abs a) ↔ odd a :=\nby { cases abs_choice a with h h; simp only [h, odd_neg] }\n\nend ring\n\nsection powers\nvariables {R : Type*}\n  {a : R} {n : ℕ} [linear_ordered_ring R]\n\nlemma even.pow_nonneg (hn : even n) (a : R) : 0 ≤ a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_nonneg a k\n\nlemma even.pow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_pos ha k\n\nlemma odd.pow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_nonpos_iff.mpr ha\n\nlemma odd.pow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_neg_iff.mpr ha\n\nlemma odd.pow_nonneg_iff (hn : odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=\n⟨λ h, le_of_not_lt (λ ha, h.not_lt $ hn.pow_neg ha), λ ha, pow_nonneg ha n⟩\n\nlemma odd.pow_nonpos_iff (hn : odd n) : a ^ n ≤ 0 ↔ a ≤ 0 :=\n⟨λ h, le_of_not_lt (λ ha, h.not_lt $ pow_pos ha _), hn.pow_nonpos⟩\n\nlemma odd.pow_pos_iff (hn : odd n) : 0 < a ^ n ↔ 0 < a :=\n⟨λ h, lt_of_not_ge' (λ ha, h.not_le $ hn.pow_nonpos ha), λ ha, pow_pos ha n⟩\n\nlemma odd.pow_neg_iff (hn : odd n) : a ^ n < 0 ↔ a < 0 :=\n⟨λ h, lt_of_not_ge' (λ ha, h.not_le $ pow_nonneg ha _), hn.pow_neg⟩\n\nlemma even.pow_pos_iff (hn : even n) (h₀ : 0 < n) : 0 < a ^ n ↔ a ≠ 0 :=\n⟨λ h ha, by { rw [ha, zero_pow h₀] at h, exact lt_irrefl 0 h }, hn.pow_pos⟩\n\nlemma even.pow_abs {p : ℕ} (hp : even p) (a : R) : |a| ^ p = a ^ p :=\nbegin\n  rw [←abs_pow, abs_eq_self],\n  exact hp.pow_nonneg _\nend\n\n@[simp] lemma pow_bit0_abs (a : R) (p : ℕ) : |a| ^ bit0 p = a ^ bit0 p := (even_bit0 _).pow_abs _\n\nlemma odd.strict_mono_pow (hn : odd n) : strict_mono (λ a : R, a ^ n) :=\nby cases hn with k hk; simpa only [hk, two_mul] using strict_mono_pow_bit1 _\n\nend powers\n\n/-- The cardinality of `fin (bit0 k)` is even, `fact` version.\nThis `fact` is needed as an instance by `matrix.special_linear_group.has_neg`. -/\nlemma fintype.card_fin_even {k : ℕ} : fact (even (fintype.card (fin (bit0 k)))) :=\n⟨by { rw [fintype.card_fin], exact even_bit0 k }⟩\n\nsection field_power\nvariable {K : Type*}\n\nlemma even.zpow_neg [division_ring K] {n : ℤ} (h : even n) (a : K) :\n  (-a) ^ n = a ^ n :=\nbegin\n  obtain ⟨k, rfl⟩ := h,\n  rw [← two_mul, ←bit0_eq_two_mul, zpow_bit0_neg],\nend\n\nvariables [linear_ordered_field K] {n : ℤ} {a : K}\n\nlemma even.zpow_nonneg (hn : even n) (a : K) :\n  0 ≤ a ^ n :=\nbegin\n  cases le_or_lt 0 a with h h,\n  { exact zpow_nonneg h _ },\n  { exact (hn.zpow_neg a).subst (zpow_nonneg (neg_nonneg_of_nonpos h.le) _) }\nend\n\ntheorem even.zpow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit0_pos ha k\n\ntheorem odd.zpow_nonneg (hn : odd n) (ha : 0 ≤ a) : 0 ≤ a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_nonneg_iff.mpr ha\n\ntheorem odd.zpow_pos (hn : odd n) (ha : 0 < a) : 0 < a ^ n :=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_pos_iff.mpr ha\n\ntheorem odd.zpow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_nonpos_iff.mpr ha\n\ntheorem odd.zpow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:=\nby cases hn with k hk; simpa only [hk, two_mul] using zpow_bit1_neg_iff.mpr ha\n\nlemma even.zpow_abs {p : ℤ} (hp : even p) (a : K) : |a| ^ p = a ^ p :=\nbegin\n  cases abs_choice a with h h;\n  simp only [h, hp.zpow_neg _],\nend\n\n@[simp] lemma zpow_bit0_abs (a : K) (p : ℤ) : |a| ^ bit0 p = a ^ bit0 p :=\n(even_bit0 _).zpow_abs _\n\nlemma even.abs_zpow {p : ℤ} (hp : even p) (a : K) : |a ^ p| = a ^ p :=\nbegin\n  rw [abs_eq_self],\n  exact hp.zpow_nonneg _\nend\n\n@[simp] lemma abs_zpow_bit0 (a : K) (p : ℤ) :\n  |a ^ bit0 p| = a ^ bit0 p :=\n(even_bit0 _).abs_zpow _\n\nend field_power\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047848, "lm_q2_score": 0.8615382076534743, "lm_q1q2_score": 0.7721548040039685}}
{"text": "-- Pruebas de intersección sobre unión general\n-- ===========================================\n\nimport data.set\n\nopen set\n\nvariables {I U : Type}\nvariables {A : I → set U}\nvariable  {C : set U}\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i)  :=\nbegin\n  rintros x ⟨hC, hU⟩,\n  rw mem_Union at hU,\n  cases hU with i hA,\n  apply mem_Union.mpr,\n  use i,\n  split,\n  assumption',\nend\n\n-- 2ª demostración\nexample : \n  C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i)  :=\nbegin\n  intros x h,\n  simp * at *,\nend\n\n-- 3ª demostración\nlemma inter_Uni_l1 : \n  C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i)  :=\nby {intros x h, simp * at *}\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar\n--    (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nbegin\n  intros x h,\n  rw mem_Union at h,\n  cases h with i hi,\n  cases hi with hC hA,\n  split,\n  { exact hC, },\n  { apply mem_Union.mpr,\n    use i,\n    exact hA, },\nend\n\n-- 2ª demostración\nexample : (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nbegin\n  intros x h,\n  rw mem_Union at h,\n  rcases h with ⟨i, hC, hA⟩,\n  split,\n  { exact hC, },\n  { apply mem_Union.mpr,\n    use i,\n    exact hA, },\nend\n\n-- 3ª demostración\nexample : \n  (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nbegin\n  intros x h,\n  simp * at *,\nend\n\n-- 4ª demostración\nlemma inter_Uni_l2 : \n  (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nby {intros x h, simp * at *}\n\n-- ----------------------------------------------------\n-- Ej. 3. Demostrar\n--    C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\neq_of_subset_of_subset inter_Uni_l1 inter_Uni_l2\n\n-- 2ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\n-- by library_search\ninter_Union C A\n\n-- 3ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\next $ by simp\n\n-- 4ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\nby {ext, 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/Pruebas_de_interseccion_sobre_union_general.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8615382058759128, "lm_q1q2_score": 0.7721547952484342}}
{"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 ⊆ B` and `B ⊆ 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ᶜ)ᶜ = 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ᶜ` instead \n  of using a bar over the letter. (Diacritics are hard in a text editor!)\n\n* You can type `⊆` using `\\sub`.\n\n* You can type `ᶜ` 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 ∈ A ↔ x ∈ 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 ∈ A ∩ B` simplifies to `x ∈ A ∧ x ∈ B`. \n  `x ∈ A \\ C` simplifies to `x ∈ A ∧ ¬(x ∈ 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 `↔` goal?\n\n-/\n\n/- 4 points -/\ntheorem problem_1 : (A ∩ B) ∪ A = A := by \n  ext x \n  split_goal \n  { intro hx \n    set_simplify\n    eliminate hx with hxab hxa\n    { eliminate hxab with hxa hxb \n      assumption }\n    { assumption } }\n  { intro hx \n    set_simplify \n    right\n    assumption }\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 ∩ 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 ∪ (X ∩ 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 ∩ ((Aᶜ ∩ B) ∪ Aᶜ) = ∅ := 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 ∩ Aᶜ = ∅`. 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 ↔ 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 ∩ sᶜ = ∅`, so it replaces `s ∩ sᶜ` with `∅`.\nSometimes you can use a rule in reverse direction, right to left,\nusing the symbol `←` (typed `\\l` or `\\<-`). For example:\n\n-/ \n\nexample : Aᶜ ∩ Aᶜ = Aᶜ := by \n  rewrite [← compl_union] -- we have used de morgan's law \"backward\",\n                          -- changing `Aᶜ ∩ Aᶜ` to `(A ∪ A)ᶜ`.\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 `∅`, you can replace \nit with `s ∩ sᶜ`. 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ᶜ \\ B)ᶜ = A ∪ B := by \n  rewrite [diff_eq]\n  rewrite [compl_inter]\n  rewrite [compl_compl]\n  rewrite [compl_compl]\n  reflexivity\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/Hw3Sols.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7721547920666477}}
{"text": "import analysis.special_functions.trigonometric data.real.basic analysis.special_functions.pow\nimport tactic\n\nvariables (x : ℝ)\nopen real\nnoncomputable theory\n\nattribute [pp_nodot] real.log\n\nlemma cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 :=\neq_div_of_mul_eq two_ne_zero $ by rw [cosh, exp, exp, complex.of_real_neg, complex.cosh, mul_two,\n    ← complex.add_re, ← mul_two, div_mul_cancel _ (two_ne_zero' : (2 : ℂ) ≠ 0), complex.add_re]\n\n\nlemma sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 :=\neq_div_of_mul_eq two_ne_zero $ by rw [sinh, exp, exp, complex.of_real_neg, complex.sinh, mul_two,\n    ← complex.add_re, ← mul_two, div_mul_cancel _ (two_ne_zero' : (2 : ℂ) ≠ 0), complex.sub_re]\n\n\n/-- A real version of `complex.cosh_sq_sub_sinh_sq`-/\nlemma real.cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 :=\nbegin\n  rw [sinh, cosh],\n  have := complex.cosh_sq_sub_sinh_sq x,\n  apply_fun complex.re at this,\n  rw [pow_two, pow_two] at this,\n  change (⟨_, _⟩ : ℂ).re - (⟨_, _⟩ : ℂ).re = 1 at this,\n  rw [complex.cosh_of_real_im x, complex.sinh_of_real_im x] at this,\n  norm_num at this,\n  rwa [pow_two, pow_two],\nend\n\n/-- `real.cosh` is positive-/\nlemma cosh_pos (x : ℝ) : 0 < real.cosh x :=\n(cosh_eq x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x)))\n\nlemma cosh_nonneg (x : ℝ) : 0 ≤ real.cosh x := le_of_lt (cosh_pos x)\n\nlemma sinh_strict_mono : strict_mono sinh :=\nstrict_mono_of_deriv_pos differentiable_sinh (by rw [real.deriv_sinh]; exact cosh_pos)\n\n@[simp] lemma cosh_zero : cosh 0 = 1 := by simp [cosh]\n\n@[simp] lemma cosh_neg : cosh (-x) = cosh x :=\nby simp [add_comm, cosh, exp_neg]\n\nlemma sinh_nonneg (h : 0 ≤ x) : 0 ≤ sinh x :=\nbegin\n  rw sinh_eq,\n  apply div_nonneg,\n  { rw [le_sub_iff_add_le, zero_add, exp_le_exp],\n    linarith},\n  { norm_num},\nend\n", "meta": {"author": "jamesa9283", "repo": "invHypTrig", "sha": "acf74fb1873b43d27f15b47b0ced4010cecffa72", "save_path": "github-repos/lean/jamesa9283-invHypTrig", "path": "github-repos/lean/jamesa9283-invHypTrig/invHypTrig-acf74fb1873b43d27f15b47b0ced4010cecffa72/src/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.7721547896746864}}
{"text": "def binom: ℕ → ℕ → ℕ\n| _ 0 := 1\n| 0 _ := 0\n| (m + 1) (n + 1) := binom m (n + 1) + binom m n\n\ndef binom_sum: ℕ → ℕ → ℕ\n| n 0 := binom n 0\n| n (k + 1) := binom_sum n k + binom n (k + 1)\n\nlemma is_zero: ∀ k, binom 0 (k + 1) = 0 :=\nbegin\n    intros,\n    induction k,\n        simp [binom],\n    assumption\nend\n\nlemma binom_sum_zero: ∀ (n : ℕ), binom_sum 0 n = 1 :=\nbegin\n    intros,\n    induction n,\n        simp [binom_sum, binom],\n    simp [binom_sum, binom],\n    rw [n_ih, is_zero]\nend\n\nlemma binom_exceeds: ∀ (n : ℕ), ∀ (k : ℕ), binom n (n + 1 + k) = 0 :=\nbegin\n    intro n,\n    induction n,\n        simp [is_zero],\n    intros,\n    rw [←nat.add_one],\n    calc  binom (n_n + 1) (n_n + 1 + 1 + k)\n        = binom (n_n + 1) ((n_n + 1 + k) + 1)\n            : by simp [nat.add_assoc, nat.add_comm]\n    ... = binom n_n (n_n + 1 + k + 1) + binom n_n (n_n + 1 + k)\n            : by rw [binom]\n    ... = binom n_n (n_n + 1 + k + 1) + 0 : by rw [n_ih]\n    ... = binom n_n (n_n + 1 + (k + 1))\n            : by simp [nat.add_zero, nat.add_assoc]\n    ... = 0 : by rw [n_ih]\nend\n\nlemma binom_sum_continue: ∀ n, binom_sum n (n + 1) = binom_sum n n :=\nbegin\n    intros,\n    simp [binom_sum, binom_exceeds n 0]\nend\n\nlemma binom_sum_split: ∀ (n: ℕ), ∀ (k: ℕ), binom_sum (n + 1) (k + 1)\n    = binom_sum n (k + 1) + binom_sum n k :=\nbegin\n    intro n, induction n,\n        intro k, induction k,\n            simp [binom, binom_sum],\n        rw [binom_sum_zero] at *,\n        simp * at *,\n        assumption,\n    intro k, induction k,\n        simp [binom_sum, binom],\n    calc  binom_sum (nat.succ n_n + 1) (nat.succ k_n + 1)\n        = binom_sum (nat.succ n_n + 1) (nat.succ k_n)\n          + binom (nat.succ n_n + 1) (nat.succ k_n + 1)\n            : by rw binom_sum\n    ... = binom_sum (nat.succ n_n) (k_n + 1) + binom_sum (nat.succ n_n) k_n\n          + binom (nat.succ n_n + 1) (nat.succ k_n + 1)\n            : by rw k_ih\n    ... = (binom_sum (nat.succ n_n) (k_n + 1) + binom_sum (nat.succ n_n) k_n)\n          + binom (nat.succ n_n) (nat.succ k_n + 1) + binom (nat.succ n_n) (nat.succ k_n)\n            : by simp [binom]\n    ... = (binom_sum (nat.succ n_n) (k_n + 1) + binom (nat.succ n_n) (nat.succ k_n + 1))\n          + (binom_sum (nat.succ n_n) k_n) + binom (nat.succ n_n) (nat.succ k_n)\n            : by simp [nat.add_assoc, nat.add_comm]\n    ... = binom_sum (nat.succ n_n) (nat.succ k_n + 1)\n           + binom_sum (nat.succ n_n) (nat.succ k_n)\n            : by simp [binom_sum]\nend\n\nexample: ∀ (n: ℕ), binom_sum n n = 2^n :=\nbegin\n    intros,\n    induction n,\n        simp [binom_sum, binom],\n    simp [binom_sum_split],\n    simp [binom_sum_continue],\n    simp *,\n    calc 2 ^ n_n + 2 ^ n_n\n        = 1 * 2 ^ n_n + 2 ^ n_n : by rw nat.one_mul\n    ... = 2 * 2 ^ n_n : by rw ←nat.succ_mul\n    ... = 2 ^ n_n * 2 : by rw ←mul_comm\n    ... = 2 ^ nat.succ n_n : by rw nat.pow_succ\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/31.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7721254213042011}}
{"text": "import float.basic \n\n-- Following https://isabelle.in.tum.de/website-Isabelle2013/dist/library/HOL/HOL-Library/Float.html\n\nvariable (prec : ℕ)\n\ndef round_up (x : ℚ) : 𝔽 := \nfloat.mk (⌈x * 2 ^ prec⌉) (-prec)\n\ndef round_down (x : ℚ) : 𝔽 := \nfloat.mk (⌊x * 2 ^ prec⌋) (-prec)\n\nlemma round_up_zero : round_up prec 0 = 0 :=\nby { apply quotient.sound, show to_rat _ = _, simp [to_rat], }\n\nlemma round_down_zero : round_down prec 0 = 0 :=\nby { apply quotient.sound, show to_rat _ = _, simp [to_rat], }\n\nlemma round_up_diff_round_down (x : ℚ)\n: round_up prec x - round_down prec x ≤ float.mk 1 (-prec) :=\nbegin \n  show float.eval _ ≤ _, \n  simp [float.eval_sub, round_up, round_down, float.eval_mk],\n  suffices hsuff : ↑(⌈x * 2 ^ prec⌉ - ⌊x * 2 ^ prec⌋) * ((2 : ℚ) ^ prec)⁻¹ ≤ 1 * ((2 : ℚ) ^ prec)⁻¹,\n  { push_cast at hsuff, rw [sub_mul, one_mul] at hsuff, exact hsuff, },\n  have h : 0 < ((2 : ℚ) ^ prec)⁻¹,\n  { norm_num, },\n  rw [mul_le_mul_right h], show _ ≤ ↑(1 : ℤ), simp [coe],\n  rw [sub_le_iff_le_add, add_comm],\n  exact ceil_le_floor_add_one _,\nend \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/round.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7721052781393273}}
{"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 : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from ℝ to ℝ\n-- x₀ and l are real numbers\nvariables (u : ℕ → ℝ) (f : ℝ → ℝ) (x₀ l : ℝ)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : ¬ (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε) ↔\n∃ ε > 0, ∀ N, ∃ n ≥ N, |u n - l| > ε \n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is continuous at x₀\" -/\n-- 0063\nexample : ¬ (∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ →  |f x - f x₀| ≤ ε) ↔\n∃ ε > 0, ∀ δ > 0, ∃ x, |x - x₀| ≤ δ ∧ |f x - f x₀| > ε\n:=\nbegin\n  check_me,\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`∀ x x', ...` is the abbreviation of\n`∀ x, ∀ x', ... `. \n\nAlso, `∃ x x', ...` is the abbreviation of `∃ x, ∃ x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on ℝ\" -/\n-- 0064\nexample : ¬ (∀ ε > 0, ∃ δ > 0, ∀ x x', |x' - x| ≤ δ →  |f x' - f x| ≤ ε) ↔\n∃ ε > 0, ∀ δ > 0, ∃ x x', |x' - x| ≤ δ ∧ |f x' - f x| > ε\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is sequentially continuous at x₀\" -/\n-- 0065\nexample : ¬ (∀ u : ℕ → ℝ, (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - x₀| ≤ ε) → (∀ ε > 0, ∃ N, ∀ n ≥ N, |(f ∘ u) n - f x₀| ≤ ε))  ↔\n∃ u : ℕ → ℝ, (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - x₀| ≤ ε) ∧ (∃ ε > 0, ∀ N, ∃ n ≥ N, |(f ∘ u) n - f x₀| > ε)\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 : ℝ} : |x| ≤ y ↔ -y ≤ x ∧ x ≤ y\n\nge_max_iff (p q r) : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q\n\nle_max_left p q : p ≤ max p q\n\nle_max_right p q : q ≤ max p q\n\n/-- The sequence `u` tends to `+∞`. -/\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n-/\n\n-- 0066\nexample {u : ℕ → ℝ} : tendsto_infinity u → ∀ l, ¬ seq_limit u l :=\nbegin\n  intros h l, unfold seq_limit, push_neg, use 1, split, linarith, intro N,\n  rcases h (l+2) with ⟨N', hN⟩, specialize hN (max N N'), specialize hN (le_max_right _ _),\n  use max N N', split, apply le_max_left, by_contradiction hyp, push_neg at hyp,\n  rw abs_le at hyp, cases hyp with h1 h2, linarith,\nend\n\ndef nondecreasing_seq (u : ℕ → ℝ) := ∀ n m, n ≤ m → u n ≤ u m\n\n-- 0067\nexample (u : ℕ → ℝ) (l : ℝ) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  ∀ n, u n ≤ l :=\nbegin\n  intro k, by_contradiction hyp, push_neg at hyp, specialize h ((u k - l)/2) (by linarith),\n  cases h with N h, specialize h (max N k) (le_max_left _ _),\n  specialize h' k (max N k) (le_max_right _ _), rw abs_le at h, cases h with h1 h2, linarith,\nend\n\n/-\nIn the following exercises, `A : set ℝ` means that A is a set of real numbers.\nWe can use the usual notation x ∈ A.\n\nThe notation `∀ x ∈ A, ...` is the abbreviation of `∀ x, x ∈ A → ... `\n\nThe notation `∃ x ∈ A, ...` is the abbreviation of `∃ x, x ∈ A ∧ ... `.\nMore precisely it is the abbreviation of `∃ x (H : x ∈ A), ...`\nwhich is Lean's strange way of saying `∃ x, x ∈ A ∧ ... `. \nYou can convert between these forms using the lemma \n  exists_prop {p q : Prop} : (∃ (h : p), q) ↔ p ∧ 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 ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ 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 ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intros y hy, by_contradiction hyp, push_neg at hyp, change upper_bound A y at hyp,\n  cases hx with h1 h2, specialize h2 y hyp, 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 : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  intro h, by_contradiction hyp, push_neg at hyp, specialize h ((y-x)/2) (by linarith),\n  linarith,\nend\n\n-- 0070\nexample {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all', intros ε ε_pos, rcases hu ε ε_pos with ⟨N, hN⟩,\n  specialize hN N (by linarith), specialize ineg N, rw abs_le at hN, linarith,\nend\n\n", "meta": {"author": "yqaddur1", "repo": "Lean", "sha": "16ddbf6da45e28bf1de59171113537cebe2858fa", "save_path": "github-repos/lean/yqaddur1-Lean", "path": "github-repos/lean/yqaddur1-Lean/Lean-16ddbf6da45e28bf1de59171113537cebe2858fa/tutorials/src/myexercises/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336302, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7720804391572718}}
{"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 linear_algebra.finite_dimensional\n! leanprover-community/mathlib commit dc17b6ac53b111affde68d96e5e7a0726816e2cf\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.Subalgebra.Basic\nimport Mathbin.FieldTheory.Finiteness\nimport Mathbin.LinearAlgebra.FreeModule.Finite.Rank\nimport Mathbin.Tactic.IntervalCases\n\n/-!\n# Finite dimensional vector spaces\n\nDefinition and basic properties of finite dimensional vector spaces, of their dimensions, and\nof linear maps on such spaces.\n\n## Main definitions\n\nAssume `V` is a vector space over a division ring `K`. There are (at least) three equivalent\ndefinitions of finite-dimensionality of `V`:\n\n- it admits a finite basis.\n- it is finitely generated.\n- it is noetherian, i.e., every subspace is finitely generated.\n\nWe introduce a typeclass `finite_dimensional K V` capturing this property. For ease of transfer of\nproof, it is defined using the second point of view, i.e., as `finite`. However, we prove\nthat all these points of view are equivalent, with the following lemmas\n(in the namespace `finite_dimensional`):\n\n- `fintype_basis_index` states that a finite-dimensional\n  vector space has a finite basis\n- `finite_dimensional.fin_basis` and `finite_dimensional.fin_basis_of_finrank_eq`\n  are bases for finite dimensional vector spaces, where the index type\n  is `fin`\n- `of_fintype_basis` states that the existence of a basis indexed by a\n  finite type implies finite-dimensionality\n- `of_finite_basis` states that the existence of a basis indexed by a\n  finite set implies finite-dimensionality\n- `is_noetherian.iff_fg` states that the space is finite-dimensional if and only if\n  it is noetherian\n\nWe make use of `finrank`, the dimension of a finite dimensional space, returning a `nat`, as\nopposed to `module.rank`, which returns a `cardinal`. When the space has infinite dimension, its\n`finrank` is by convention set to `0`. `finrank` is not defined using `finite_dimensional`.\nFor basic results that do not need the `finite_dimensional` class, import `linear_algebra.finrank`.\n\nPreservation of finite-dimensionality and formulas for the dimension are given for\n- submodules\n- quotients (for the dimension of a quotient, see `finrank_quotient_add_finrank`)\n- linear equivs, in `linear_equiv.finite_dimensional`\n- image under a linear map (the rank-nullity formula is in `finrank_range_add_finrank_ker`)\n\nBasic properties of linear maps of a finite-dimensional vector space are given. Notably, the\nequivalence of injectivity and surjectivity is proved in `linear_map.injective_iff_surjective`,\nand the equivalence between left-inverse and right-inverse in `linear_map.mul_eq_one_comm`\nand `linear_map.comp_eq_id_comm`.\n\n## Implementation notes\n\nMost results are deduced from the corresponding results for the general dimension (as a cardinal),\nin `dimension.lean`. Not all results have been ported yet.\n\nYou should not assume that there has been any effort to state lemmas as generally as possible.\n\nOne of the characterizations of finite-dimensionality is in terms of finite generation. This\nproperty is currently defined only for submodules, so we express it through the fact that the\nmaximal submodule (which, as a set, coincides with the whole space) is finitely generated. This is\nnot very convenient to use, although there are some helper functions. However, this becomes very\nconvenient when speaking of submodules which are finite-dimensional, as this notion coincides with\nthe fact that the submodule is finitely generated (as a submodule of the whole space). This\nequivalence is proved in `submodule.fg_iff_finite_dimensional`.\n-/\n\n\nuniverse u v v' w\n\nopen Classical Cardinal\n\nopen Cardinal Submodule Module Function\n\n/-- `finite_dimensional` vector spaces are defined to be finite modules.\nUse `finite_dimensional.of_fintype_basis` to prove finite dimension from another definition. -/\n@[reducible]\ndef FiniteDimensional (K V : Type _) [DivisionRing K] [AddCommGroup V] [Module K V] :=\n  Module.Finite K V\n#align finite_dimensional FiniteDimensional\n\nvariable {K : Type u} {V : Type v}\n\nnamespace FiniteDimensional\n\nopen IsNoetherian\n\nsection DivisionRing\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]\n  [Module K V₂]\n\n/-- If the codomain of an injective linear map is finite dimensional, the domain must be as well. -/\ntheorem of_injective (f : V →ₗ[K] V₂) (w : Function.Injective f) [FiniteDimensional K V₂] :\n    FiniteDimensional K V :=\n  have : IsNoetherian K V₂ := IsNoetherian.iff_fg.mpr ‹_›\n  Module.Finite.of_injective f w\n#align finite_dimensional.of_injective FiniteDimensional.of_injective\n\n/-- If the domain of a surjective linear map is finite dimensional, the codomain must be as well. -/\ntheorem of_surjective (f : V →ₗ[K] V₂) (w : Function.Surjective f) [FiniteDimensional K V] :\n    FiniteDimensional K V₂ :=\n  Module.Finite.of_surjective f w\n#align finite_dimensional.of_surjective FiniteDimensional.of_surjective\n\nvariable (K V)\n\ninstance finiteDimensional_pi {ι : Type _} [Finite ι] : FiniteDimensional K (ι → K) :=\n  iff_fg.1 isNoetherian_pi\n#align finite_dimensional.finite_dimensional_pi FiniteDimensional.finiteDimensional_pi\n\ninstance finiteDimensional_pi' {ι : Type _} [Finite ι] (M : ι → Type _) [∀ i, AddCommGroup (M i)]\n    [∀ i, Module K (M i)] [I : ∀ i, FiniteDimensional K (M i)] : FiniteDimensional K (∀ i, M i) :=\n  haveI : ∀ i : ι, IsNoetherian K (M i) := fun i => iff_fg.2 (I i)\n  iff_fg.1 isNoetherian_pi\n#align finite_dimensional.finite_dimensional_pi' FiniteDimensional.finiteDimensional_pi'\n\n/-- A finite dimensional vector space over a finite field is finite -/\nnoncomputable def fintypeOfFintype [Fintype K] [FiniteDimensional K V] : Fintype V :=\n  Module.fintypeOfFintype (@finsetBasis K V _ _ _ (iff_fg.2 inferInstance))\n#align finite_dimensional.fintype_of_fintype FiniteDimensional.fintypeOfFintype\n\ntheorem finite_of_finite [Finite K] [FiniteDimensional K V] : Finite V :=\n  by\n  cases nonempty_fintype K\n  haveI := fintype_of_fintype K V\n  infer_instance\n#align finite_dimensional.finite_of_finite FiniteDimensional.finite_of_finite\n\nvariable {K V}\n\n/-- If a vector space has a finite basis, then it is finite-dimensional. -/\ntheorem of_fintype_basis {ι : Type w} [Finite ι] (h : Basis ι K V) : FiniteDimensional K V :=\n  by\n  cases nonempty_fintype ι\n  exact\n    ⟨⟨finset.univ.image h, by\n        convert h.span_eq\n        simp⟩⟩\n#align finite_dimensional.of_fintype_basis FiniteDimensional.of_fintype_basis\n\n/-- If a vector space is `finite_dimensional`, all bases are indexed by a finite type -/\nnoncomputable def fintypeBasisIndex {ι : Type _} [FiniteDimensional K V] (b : Basis ι K V) :\n    Fintype ι :=\n  letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance\n  IsNoetherian.fintypeBasisIndex b\n#align finite_dimensional.fintype_basis_index FiniteDimensional.fintypeBasisIndex\n\n/-- If a vector space is `finite_dimensional`, `basis.of_vector_space` is indexed by\n  a finite type.-/\nnoncomputable instance [FiniteDimensional K V] : Fintype (Basis.ofVectorSpaceIndex K V) :=\n  by\n  letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance\n  infer_instance\n\n/-- If a vector space has a basis indexed by elements of a finite set, then it is\nfinite-dimensional. -/\ntheorem of_finite_basis {ι : Type w} {s : Set ι} (h : Basis s K V) (hs : Set.Finite s) :\n    FiniteDimensional K V :=\n  haveI := hs.fintype\n  of_fintype_basis h\n#align finite_dimensional.of_finite_basis FiniteDimensional.of_finite_basis\n\n/-- A subspace of a finite-dimensional space is also finite-dimensional. -/\ninstance finiteDimensional_submodule [FiniteDimensional K V] (S : Submodule K V) :\n    FiniteDimensional K S := by\n  letI : IsNoetherian K V := iff_fg.2 _\n  exact\n    iff_fg.1\n      (IsNoetherian.iff_dim_lt_aleph0.2 (lt_of_le_of_lt (dim_submodule_le _) (dim_lt_aleph_0 K V)))\n  infer_instance\n#align finite_dimensional.finite_dimensional_submodule FiniteDimensional.finiteDimensional_submodule\n\n/-- A quotient of a finite-dimensional space is also finite-dimensional. -/\ninstance finiteDimensional_quotient [FiniteDimensional K V] (S : Submodule K V) :\n    FiniteDimensional K (V ⧸ S) :=\n  Module.Finite.of_surjective (Submodule.mkQ S) <| surjective_quot_mk _\n#align finite_dimensional.finite_dimensional_quotient FiniteDimensional.finiteDimensional_quotient\n\nvariable (K V)\n\n/-- In a finite-dimensional space, its dimension (seen as a cardinal) coincides with its\n`finrank`. -/\ntheorem finrank_eq_dim [FiniteDimensional K V] : (finrank K V : Cardinal.{v}) = Module.rank K V :=\n  by\n  letI : IsNoetherian K V := iff_fg.2 inferInstance\n  rw [finrank, cast_to_nat_of_lt_aleph_0 (dim_lt_aleph_0 K V)]\n#align finite_dimensional.finrank_eq_dim FiniteDimensional.finrank_eq_dim\n\nvariable {K V}\n\ntheorem finrank_of_infinite_dimensional (h : ¬FiniteDimensional K V) : finrank K V = 0 :=\n  dif_neg <| mt IsNoetherian.iff_dim_lt_aleph0.2 <| (not_iff_not.2 iff_fg).2 h\n#align finite_dimensional.finrank_of_infinite_dimensional FiniteDimensional.finrank_of_infinite_dimensional\n\ntheorem finiteDimensional_of_finrank (h : 0 < finrank K V) : FiniteDimensional K V :=\n  by\n  contrapose h\n  simp [finrank_of_infinite_dimensional h]\n#align finite_dimensional.finite_dimensional_of_finrank FiniteDimensional.finiteDimensional_of_finrank\n\ntheorem finiteDimensional_of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) :\n    FiniteDimensional K V :=\n  finiteDimensional_of_finrank <| by rw [hn] <;> exact n.succ_pos\n#align finite_dimensional.finite_dimensional_of_finrank_eq_succ FiniteDimensional.finiteDimensional_of_finrank_eq_succ\n\n/-- We can infer `finite_dimensional K V` in the presence of `[fact (finrank K V = n + 1)]`. Declare\nthis as a local instance where needed. -/\ntheorem fact_finiteDimensional_of_finrank_eq_succ (n : ℕ) [Fact (finrank K V = n + 1)] :\n    FiniteDimensional K V :=\n  finiteDimensional_of_finrank <| by convert Nat.succ_pos n <;> apply Fact.out\n#align finite_dimensional.fact_finite_dimensional_of_finrank_eq_succ FiniteDimensional.fact_finiteDimensional_of_finrank_eq_succ\n\ntheorem finiteDimensional_iff_of_rank_eq_nsmul {W} [AddCommGroup W] [Module K W] {n : ℕ}\n    (hn : n ≠ 0) (hVW : Module.rank K V = n • Module.rank K W) :\n    FiniteDimensional K V ↔ FiniteDimensional K W := by\n  simp only [FiniteDimensional, ← IsNoetherian.iff_fg, IsNoetherian.iff_dim_lt_aleph0, hVW,\n    Cardinal.nsmul_lt_aleph0_iff_of_ne_zero hn]\n#align finite_dimensional.finite_dimensional_iff_of_rank_eq_nsmul FiniteDimensional.finiteDimensional_iff_of_rank_eq_nsmul\n\n/-- If a vector space is finite-dimensional, then the cardinality of any basis is equal to its\n`finrank`. -/\ntheorem finrank_eq_card_basis' [FiniteDimensional K V] {ι : Type w} (h : Basis ι K V) :\n    (finrank K V : Cardinal.{w}) = (#ι) :=\n  by\n  haveI : IsNoetherian K V := iff_fg.2 inferInstance\n  haveI : Fintype ι := fintype_basis_index h\n  rw [Cardinal.mk_fintype, finrank_eq_card_basis h]\n#align finite_dimensional.finrank_eq_card_basis' FiniteDimensional.finrank_eq_card_basis'\n\n/-- Given a basis of a division ring over itself indexed by a type `ι`, then `ι` is `unique`. -/\nnoncomputable def Basis.unique {ι : Type _} (b : Basis ι K K) : Unique ι :=\n  by\n  have A : Cardinal.mk ι = ↑(FiniteDimensional.finrank K K) :=\n    (FiniteDimensional.finrank_eq_card_basis' b).symm\n  simp only [Cardinal.eq_one_iff_unique, FiniteDimensional.finrank_self, algebraMap.coe_one] at A\n  exact Nonempty.some ((unique_iff_subsingleton_and_nonempty _).2 A)\n#align basis.unique Basis.unique\n\nvariable (K V)\n\n/-- A finite dimensional vector space has a basis indexed by `fin (finrank K V)`. -/\nnoncomputable def finBasis [FiniteDimensional K V] : Basis (Fin (finrank K V)) K V :=\n  have h : Fintype.card (@finsetBasisIndex K V _ _ _ (iff_fg.2 inferInstance)) = finrank K V :=\n    (finrank_eq_card_basis (@finsetBasis K V _ _ _ (iff_fg.2 inferInstance))).symm\n  (@finsetBasis K V _ _ _ (iff_fg.2 inferInstance)).reindex (Fintype.equivFinOfCardEq h)\n#align finite_dimensional.fin_basis FiniteDimensional.finBasis\n\n/-- An `n`-dimensional vector space has a basis indexed by `fin n`. -/\nnoncomputable def finBasisOfFinrankEq [FiniteDimensional K V] {n : ℕ} (hn : finrank K V = n) :\n    Basis (Fin n) K V :=\n  (finBasis K V).reindex (Fin.cast hn).toEquiv\n#align finite_dimensional.fin_basis_of_finrank_eq FiniteDimensional.finBasisOfFinrankEq\n\nvariable {K V}\n\n/-- A module with dimension 1 has a basis with one element. -/\nnoncomputable def basisUnique (ι : Type _) [Unique ι] (h : finrank K V = 1) : Basis ι K V :=\n  haveI := finite_dimensional_of_finrank (_root_.zero_lt_one.trans_le h.symm.le)\n  (fin_basis_of_finrank_eq K V h).reindex (Equiv.equivOfUnique _ _)\n#align finite_dimensional.basis_unique FiniteDimensional.basisUnique\n\n@[simp]\ntheorem basisUnique.repr_eq_zero_iff {ι : Type _} [Unique ι] {h : finrank K V = 1} {v : V} {i : ι} :\n    (basisUnique ι h).repr v i = 0 ↔ v = 0 :=\n  ⟨fun hv =>\n    (basisUnique ι h).repr.map_eq_zero_iff.mp (Finsupp.ext fun j => Subsingleton.elim i j ▸ hv),\n    fun hv => by rw [hv, LinearEquiv.map_zero, Finsupp.zero_apply]⟩\n#align finite_dimensional.basis_unique.repr_eq_zero_iff FiniteDimensional.basisUnique.repr_eq_zero_iff\n\ntheorem cardinal_mk_le_finrank_of_linearIndependent [FiniteDimensional K V] {ι : Type w} {b : ι → V}\n    (h : LinearIndependent K b) : (#ι) ≤ finrank K V :=\n  by\n  rw [← lift_le.{_, max v w}]\n  simpa [← finrank_eq_dim, -Module.Free.finrank_eq_rank] using\n    cardinal_lift_le_dim_of_linearIndependent.{_, _, _, max v w} h\n#align finite_dimensional.cardinal_mk_le_finrank_of_linear_independent FiniteDimensional.cardinal_mk_le_finrank_of_linearIndependent\n\ntheorem fintype_card_le_finrank_of_linearIndependent [FiniteDimensional K V] {ι : Type _}\n    [Fintype ι] {b : ι → V} (h : LinearIndependent K b) : Fintype.card ι ≤ finrank K V := by\n  simpa using cardinal_mk_le_finrank_of_linear_independent h\n#align finite_dimensional.fintype_card_le_finrank_of_linear_independent FiniteDimensional.fintype_card_le_finrank_of_linearIndependent\n\ntheorem finset_card_le_finrank_of_linearIndependent [FiniteDimensional K V] {b : Finset V}\n    (h : LinearIndependent K (fun x => x : b → V)) : b.card ≤ finrank K V :=\n  by\n  rw [← Fintype.card_coe]\n  exact fintype_card_le_finrank_of_linear_independent h\n#align finite_dimensional.finset_card_le_finrank_of_linear_independent FiniteDimensional.finset_card_le_finrank_of_linearIndependent\n\ntheorem lt_aleph0_of_linearIndependent {ι : Type w} [FiniteDimensional K V] {v : ι → V}\n    (h : LinearIndependent K v) : (#ι) < ℵ₀ :=\n  by\n  apply Cardinal.lift_lt.1\n  apply lt_of_le_of_lt\n  apply cardinal_lift_le_dim_of_linearIndependent h\n  rw [← finrank_eq_dim, Cardinal.lift_aleph0, Cardinal.lift_natCast]\n  apply Cardinal.nat_lt_aleph0\n#align finite_dimensional.lt_aleph_0_of_linear_independent FiniteDimensional.lt_aleph0_of_linearIndependent\n\ntheorem LinearIndependent.finite [FiniteDimensional K V] {b : Set V}\n    (h : LinearIndependent K fun x : b => (x : V)) : b.Finite :=\n  Cardinal.lt_aleph0_iff_set_finite.mp (FiniteDimensional.lt_aleph0_of_linearIndependent h)\n#align linear_independent.finite LinearIndependent.finite\n\ntheorem not_linearIndependent_of_infinite {ι : Type w} [inf : Infinite ι] [FiniteDimensional K V]\n    (v : ι → V) : ¬LinearIndependent K v :=\n  by\n  intro h_lin_indep\n  have : ¬ℵ₀ ≤ (#ι) := not_le.mpr (lt_aleph_0_of_linear_independent h_lin_indep)\n  have : ℵ₀ ≤ (#ι) := infinite_iff.mp inf\n  contradiction\n#align finite_dimensional.not_linear_independent_of_infinite FiniteDimensional.not_linearIndependent_of_infinite\n\n/-- A finite dimensional space has positive `finrank` iff it has a nonzero element. -/\ntheorem finrank_pos_iff_exists_ne_zero [FiniteDimensional K V] : 0 < finrank K V ↔ ∃ x : V, x ≠ 0 :=\n  Iff.trans\n    (by\n      rw [← finrank_eq_dim]\n      norm_cast)\n    (@dim_pos_iff_exists_ne_zero K V _ _ _ _ _)\n#align finite_dimensional.finrank_pos_iff_exists_ne_zero FiniteDimensional.finrank_pos_iff_exists_ne_zero\n\n/-- A finite dimensional space has positive `finrank` iff it is nontrivial. -/\ntheorem finrank_pos_iff [FiniteDimensional K V] : 0 < finrank K V ↔ Nontrivial V :=\n  Iff.trans\n    (by\n      rw [← finrank_eq_dim]\n      norm_cast)\n    (@dim_pos_iff_nontrivial K V _ _ _ _ _)\n#align finite_dimensional.finrank_pos_iff FiniteDimensional.finrank_pos_iff\n\n/-- A nontrivial finite dimensional space has positive `finrank`. -/\ntheorem finrank_pos [FiniteDimensional K V] [h : Nontrivial V] : 0 < finrank K V :=\n  finrank_pos_iff.mpr h\n#align finite_dimensional.finrank_pos FiniteDimensional.finrank_pos\n\n/-- A finite dimensional space has zero `finrank` iff it is a subsingleton.\nThis is the `finrank` version of `dim_zero_iff`. -/\ntheorem finrank_zero_iff [FiniteDimensional K V] : finrank K V = 0 ↔ Subsingleton V :=\n  Iff.trans\n    (by\n      rw [← finrank_eq_dim]\n      norm_cast)\n    (@dim_zero_iff K V _ _ _ _ _)\n#align finite_dimensional.finrank_zero_iff FiniteDimensional.finrank_zero_iff\n\n/-- If a submodule has maximal dimension in a finite dimensional space, then it is equal to the\nwhole space. -/\ntheorem eq_top_of_finrank_eq [FiniteDimensional K V] {S : Submodule K V}\n    (h : finrank K S = finrank K V) : S = ⊤ :=\n  by\n  haveI : IsNoetherian K V := iff_fg.2 inferInstance\n  set bS := Basis.ofVectorSpace K S with bS_eq\n  have : LinearIndependent K (coe : (coe '' Basis.ofVectorSpaceIndex K S : Set V) → V) :=\n    @LinearIndependent.image_subtype _ _ _ _ _ _ _ _ _ (Submodule.subtype S)\n      (by simpa using bS.linear_independent) (by simp)\n  set b := Basis.extend this with b_eq\n  letI : Fintype (this.extend _) :=\n    (finite_of_linearIndependent (by simpa using b.linear_independent)).Fintype\n  letI : Fintype (coe '' Basis.ofVectorSpaceIndex K S) := (finite_of_linearIndependent this).Fintype\n  letI : Fintype (Basis.ofVectorSpaceIndex K S) :=\n    (finite_of_linearIndependent (by simpa using bS.linear_independent)).Fintype\n  have : coe '' Basis.ofVectorSpaceIndex K S = this.extend (Set.subset_univ _) :=\n    Set.eq_of_subset_of_card_le (this.subset_extend _)\n      (by\n        rw [Set.card_image_of_injective _ Subtype.coe_injective, ← finrank_eq_card_basis bS, ←\n            finrank_eq_card_basis b, h] <;>\n          infer_instance)\n  rw [← b.span_eq, b_eq, Basis.coe_extend, Subtype.range_coe, ← this, ← Submodule.coeSubtype,\n    span_image]\n  have := bS.span_eq\n  rw [bS_eq, Basis.coe_ofVectorSpace, Subtype.range_coe] at this\n  rw [this, map_top (Submodule.subtype S), range_subtype]\n#align finite_dimensional.eq_top_of_finrank_eq FiniteDimensional.eq_top_of_finrank_eq\n\nvariable (K)\n\ninstance finiteDimensional_self : FiniteDimensional K K := by infer_instance\n#align finite_dimensional.finite_dimensional_self FiniteDimensional.finiteDimensional_self\n\n/-- The submodule generated by a finite set is finite-dimensional. -/\ntheorem span_of_finite {A : Set V} (hA : Set.Finite A) : FiniteDimensional K (Submodule.span K A) :=\n  iff_fg.1 <| isNoetherian_span_of_finite K hA\n#align finite_dimensional.span_of_finite FiniteDimensional.span_of_finite\n\n/-- The submodule generated by a single element is finite-dimensional. -/\ninstance span_singleton (x : V) : FiniteDimensional K (K ∙ x) :=\n  span_of_finite K <| Set.finite_singleton _\n#align finite_dimensional.span_singleton FiniteDimensional.span_singleton\n\n/-- The submodule generated by a finset is finite-dimensional. -/\ninstance span_finset (s : Finset V) : FiniteDimensional K (span K (s : Set V)) :=\n  span_of_finite K <| s.finite_toSet\n#align finite_dimensional.span_finset FiniteDimensional.span_finset\n\n/-- Pushforwards of finite-dimensional submodules are finite-dimensional. -/\ninstance (f : V →ₗ[K] V₂) (p : Submodule K V) [h : FiniteDimensional K p] :\n    FiniteDimensional K (p.map f) :=\n  by\n  rw [FiniteDimensional, ← iff_fg, IsNoetherian.iff_dim_lt_aleph0] at h⊢\n  rw [← Cardinal.lift_lt.{v', v}]\n  rw [← Cardinal.lift_lt.{v, v'}] at h\n  rw [Cardinal.lift_aleph0] at h⊢\n  exact (lift_dim_map_le f p).trans_lt h\n\n/-- Pushforwards of finite-dimensional submodules have a smaller finrank. -/\ntheorem finrank_map_le (f : V →ₗ[K] V₂) (p : Submodule K V) [FiniteDimensional K p] :\n    finrank K (p.map f) ≤ finrank K p := by\n  simpa [← finrank_eq_dim, -Module.Free.finrank_eq_rank] using lift_dim_map_le f p\n#align finite_dimensional.finrank_map_le FiniteDimensional.finrank_map_le\n\nvariable {K}\n\ntheorem CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux [FiniteDimensional K V]\n    {ι : Type w} {p : ι → Submodule K V} (hp : CompleteLattice.Independent p) :\n    (#{ i // p i ≠ ⊥ }) ≤ (finrank K V : Cardinal.{w}) :=\n  by\n  suffices Cardinal.lift.{v} (#{ i // p i ≠ ⊥ }) ≤ Cardinal.lift.{v} (finrank K V : Cardinal.{w}) by\n    rwa [Cardinal.lift_le] at this\n  calc\n    Cardinal.lift.{v} (#{ i // p i ≠ ⊥ }) ≤ Cardinal.lift.{w} (Module.rank K V) :=\n      hp.subtype_ne_bot_le_rank\n    _ = Cardinal.lift.{w} (finrank K V : Cardinal.{v}) := by rw [finrank_eq_dim]\n    _ = Cardinal.lift.{v} (finrank K V : Cardinal.{w}) := by simp\n    \n#align complete_lattice.independent.subtype_ne_bot_le_finrank_aux CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux\n\n/-- If `p` is an independent family of subspaces of a finite-dimensional space `V`, then the\nnumber of nontrivial subspaces in the family `p` is finite. -/\nnoncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional\n    [FiniteDimensional K V] {ι : Type w} {p : ι → Submodule K V}\n    (hp : CompleteLattice.Independent p) : Fintype { i : ι // p i ≠ ⊥ } :=\n  by\n  suffices (#{ i // p i ≠ ⊥ }) < (ℵ₀ : Cardinal.{w})\n    by\n    rw [Cardinal.lt_aleph0_iff_fintype] at this\n    exact this.some\n  refine' lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux _\n  simp [Cardinal.nat_lt_aleph0]\n#align complete_lattice.independent.fintype_ne_bot_of_finite_dimensional CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional\n\n/-- If `p` is an independent family of subspaces of a finite-dimensional space `V`, then the\nnumber of nontrivial subspaces in the family `p` is bounded above by the dimension of `V`.\n\nNote that the `fintype` hypothesis required here can be provided by\n`complete_lattice.independent.fintype_ne_bot_of_finite_dimensional`. -/\ntheorem CompleteLattice.Independent.subtype_ne_bot_le_finrank [FiniteDimensional K V] {ι : Type w}\n    {p : ι → Submodule K V} (hp : CompleteLattice.Independent p) [Fintype { i // p i ≠ ⊥ }] :\n    Fintype.card { i // p i ≠ ⊥ } ≤ finrank K V := by simpa using hp.subtype_ne_bot_le_finrank_aux\n#align complete_lattice.independent.subtype_ne_bot_le_finrank CompleteLattice.Independent.subtype_ne_bot_le_finrank\n\nsection\n\nopen BigOperators\n\nopen Finset\n\n/-- If a finset has cardinality larger than the dimension of the space,\nthen there is a nontrivial linear relation amongst its elements.\n-/\ntheorem exists_nontrivial_relation_of_dim_lt_card [FiniteDimensional K V] {t : Finset V}\n    (h : finrank K V < t.card) : ∃ f : V → K, (∑ e in t, f e • e) = 0 ∧ ∃ x ∈ t, f x ≠ 0 :=\n  by\n  have := mt finset_card_le_finrank_of_linear_independent (by simpa using h)\n  rw [not_linearIndependent_iff] at this\n  obtain ⟨s, g, sum, z, zm, nonzero⟩ := this\n  -- Now we have to extend `g` to all of `t`, then to all of `V`.\n  let f : V → K := fun x => if h : x ∈ t then if (⟨x, h⟩ : t) ∈ s then g ⟨x, h⟩ else 0 else 0\n  -- and finally clean up the mess caused by the extension.\n  refine' ⟨f, _, _⟩\n  · dsimp [f]\n    rw [← Sum]\n    fapply sum_bij_ne_zero fun v hvt _ => (⟨v, hvt⟩ : { v // v ∈ t })\n    · intro v hvt H\n      dsimp\n      rw [dif_pos hvt] at H\n      contrapose! H\n      rw [if_neg H, zero_smul]\n    · intro _ _ _ _ _ _\n      exact Subtype.mk.inj\n    · intro b hbs hb\n      use b\n      simpa only [hbs, exists_prop, dif_pos, Finset.mk_coe, and_true_iff, if_true, Finset.coe_mem,\n        eq_self_iff_true, exists_prop_of_true, Ne.def] using hb\n    · intro a h₁\n      dsimp\n      rw [dif_pos h₁]\n      intro h₂\n      rw [if_pos]\n      contrapose! h₂\n      rw [if_neg h₂, zero_smul]\n  · refine' ⟨z, z.2, _⟩\n    dsimp only [f]\n    erw [dif_pos z.2, if_pos] <;> rwa [Subtype.coe_eta]\n#align finite_dimensional.exists_nontrivial_relation_of_dim_lt_card FiniteDimensional.exists_nontrivial_relation_of_dim_lt_card\n\n/-- If a finset has cardinality larger than `finrank + 1`,\nthen there is a nontrivial linear relation amongst its elements,\nsuch that the coefficients of the relation sum to zero.\n-/\ntheorem exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card [FiniteDimensional K V]\n    {t : Finset V} (h : finrank K V + 1 < t.card) :\n    ∃ f : V → K, (∑ e in t, f e • e) = 0 ∧ (∑ e in t, f e) = 0 ∧ ∃ x ∈ t, f x ≠ 0 :=\n  by\n  -- Pick an element x₀ ∈ t,\n  have card_pos : 0 < t.card := lt_trans (Nat.succ_pos _) h\n  obtain ⟨x₀, m⟩ := (Finset.card_pos.1 card_pos).bex\n  -- and apply the previous lemma to the {xᵢ - x₀}\n  let shift : V ↪ V := ⟨fun x => x - x₀, sub_left_injective⟩\n  let t' := (t.erase x₀).map shift\n  have h' : finrank K V < t'.card :=\n    by\n    simp only [t', card_map, Finset.card_erase_of_mem m]\n    exact nat.lt_pred_iff.mpr h\n  -- to obtain a function `g`.\n  obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_dim_lt_card h'\n  -- Then obtain `f` by translating back by `x₀`,\n  -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`.\n  let f : V → K := fun z => if z = x₀ then -∑ z in t.erase x₀, g (z - x₀) else g (z - x₀)\n  refine' ⟨f, _, _, _⟩\n  -- After this, it's a matter of verifiying the properties,\n  -- based on the corresponding properties for `g`.\n  · show (∑ e : V in t, f e • e) = 0\n    -- We prove this by splitting off the `x₀` term of the sum,\n    -- which is itself a sum over `t.erase x₀`,\n    -- combining the two sums, and\n    -- observing that after reindexing we have exactly\n    -- ∑ (x : V) in t', g x • x = 0.\n    simp only [f]\n    conv_lhs =>\n      apply_congr\n      skip\n      rw [ite_smul]\n    rw [Finset.sum_ite]\n    conv =>\n      congr\n      congr\n      apply_congr\n      simp [filter_eq', m]\n    conv =>\n      congr\n      congr\n      skip\n      apply_congr\n      simp [filter_ne']\n    rw [sum_singleton, neg_smul, add_comm, ← sub_eq_add_neg, sum_smul, ← sum_sub_distrib]\n    simp only [← smul_sub]\n    -- At the end we have to reindex the sum, so we use `change` to\n    -- express the summand using `shift`.\n    change (∑ x : V in t.erase x₀, (fun e => g e • e) (shift x)) = 0\n    rw [← sum_map _ shift]\n    exact gsum\n  · show (∑ e : V in t, f e) = 0\n    -- Again we split off the `x₀` term,\n    -- observing that it exactly cancels the other terms.\n    rw [← insert_erase m, sum_insert (not_mem_erase x₀ t)]\n    dsimp [f]\n    rw [if_pos rfl]\n    conv_lhs =>\n      congr\n      skip\n      apply_congr\n      skip\n      rw [if_neg (show x ≠ x₀ from (mem_erase.mp H).1)]\n    exact neg_add_self _\n  · show ∃ (x : V)(H : x ∈ t), f x ≠ 0\n    -- We can use x₁ + x₀.\n    refine' ⟨x₁ + x₀, _, _⟩\n    · rw [Finset.mem_map] at x₁_mem\n      rcases x₁_mem with ⟨x₁, x₁_mem, rfl⟩\n      rw [mem_erase] at x₁_mem\n      simp only [x₁_mem, sub_add_cancel, Function.Embedding.coeFn_mk]\n    · dsimp only [f]\n      rwa [if_neg, add_sub_cancel]\n      rw [add_left_eq_self]\n      rintro rfl\n      simpa only [sub_eq_zero, exists_prop, Finset.mem_map, embedding.coe_fn_mk, eq_self_iff_true,\n        mem_erase, not_true, exists_eq_right, Ne.def, false_and_iff] using x₁_mem\n#align finite_dimensional.exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card FiniteDimensional.exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card\n\nsection\n\nvariable {L : Type _} [LinearOrderedField L]\n\nvariable {W : Type v} [AddCommGroup W] [Module L W]\n\n/-- A slight strengthening of `exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card`\navailable when working over an ordered field:\nwe can ensure a positive coefficient, not just a nonzero coefficient.\n-/\ntheorem exists_relation_sum_zero_pos_coefficient_of_dim_succ_lt_card [FiniteDimensional L W]\n    {t : Finset W} (h : finrank L W + 1 < t.card) :\n    ∃ f : W → L, (∑ e in t, f e • e) = 0 ∧ (∑ e in t, f e) = 0 ∧ ∃ x ∈ t, 0 < f x :=\n  by\n  obtain ⟨f, sum, total, nonzero⟩ := exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card h\n  exact ⟨f, Sum, Total, exists_pos_of_sum_zero_of_exists_nonzero f Total nonzero⟩\n#align finite_dimensional.exists_relation_sum_zero_pos_coefficient_of_dim_succ_lt_card FiniteDimensional.exists_relation_sum_zero_pos_coefficient_of_dim_succ_lt_card\n\nend\n\nend\n\n/-- In a vector space with dimension 1, each set {v} is a basis for `v ≠ 0`. -/\n@[simps]\nnoncomputable def basisSingleton (ι : Type _) [Unique ι] (h : finrank K V = 1) (v : V)\n    (hv : v ≠ 0) : Basis ι K V :=\n  let b := basisUnique ι h\n  let h : b.repr v default ≠ 0 := mt basisUnique.repr_eq_zero_iff.mp hv\n  Basis.ofRepr\n    { toFun := fun w => Finsupp.single default (b.repr w default / b.repr v default)\n      invFun := fun f => f default • v\n      map_add' := by simp [add_div]\n      map_smul' := by simp [mul_div]\n      left_inv := fun w => by\n        apply_fun b.repr using b.repr.to_equiv.injective\n        apply_fun Equiv.finsuppUnique\n        simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,\n          RingHom.id_apply, smul_eq_mul, Pi.smul_apply, Equiv.finsuppUnique_apply]\n        exact div_mul_cancel _ h\n      right_inv := fun f => by\n        ext\n        simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,\n          RingHom.id_apply, smul_eq_mul, Pi.smul_apply]\n        exact mul_div_cancel _ h }\n#align finite_dimensional.basis_singleton FiniteDimensional.basisSingleton\n\n@[simp]\ntheorem basisSingleton_apply (ι : Type _) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0)\n    (i : ι) : basisSingleton ι h v hv i = v :=\n  by\n  cases Unique.uniq ‹Unique ι› i\n  simp [basis_singleton]\n#align finite_dimensional.basis_singleton_apply FiniteDimensional.basisSingleton_apply\n\n@[simp]\ntheorem range_basisSingleton (ι : Type _) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) :\n    Set.range (basisSingleton ι h v hv) = {v} := by rw [Set.range_unique, basis_singleton_apply]\n#align finite_dimensional.range_basis_singleton FiniteDimensional.range_basisSingleton\n\nend DivisionRing\n\nend FiniteDimensional\n\nvariable {K V}\n\nsection ZeroDim\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\nopen FiniteDimensional\n\ntheorem finiteDimensional_of_dim_eq_nat {n : ℕ} (h : Module.rank K V = n) : FiniteDimensional K V :=\n  by\n  rw [FiniteDimensional, ← IsNoetherian.iff_fg, IsNoetherian.iff_dim_lt_aleph0, h]\n  exact nat_lt_aleph_0 n\n#align finite_dimensional_of_dim_eq_nat finiteDimensional_of_dim_eq_nat\n\n-- TODO: generalize to free modules over general rings.\ntheorem finiteDimensional_of_dim_eq_zero (h : Module.rank K V = 0) : FiniteDimensional K V :=\n  finiteDimensional_of_dim_eq_nat <| h.trans Nat.cast_zero.symm\n#align finite_dimensional_of_dim_eq_zero finiteDimensional_of_dim_eq_zero\n\ntheorem finiteDimensional_of_dim_eq_one (h : Module.rank K V = 1) : FiniteDimensional K V :=\n  finiteDimensional_of_dim_eq_nat <| h.trans Nat.cast_one.symm\n#align finite_dimensional_of_dim_eq_one finiteDimensional_of_dim_eq_one\n\ntheorem finrank_eq_zero_of_dim_eq_zero [FiniteDimensional K V] (h : Module.rank K V = 0) :\n    finrank K V = 0 := by\n  convert finrank_eq_dim K V\n  rw [h]; norm_cast\n#align finrank_eq_zero_of_dim_eq_zero finrank_eq_zero_of_dim_eq_zero\n\nvariable (K V)\n\ninstance finiteDimensional_bot : FiniteDimensional K (⊥ : Submodule K V) :=\n  finiteDimensional_of_dim_eq_zero <| by simp\n#align finite_dimensional_bot finiteDimensional_bot\n\nvariable {K V}\n\ntheorem bot_eq_top_of_dim_eq_zero (h : Module.rank K V = 0) : (⊥ : Submodule K V) = ⊤ :=\n  by\n  haveI := finiteDimensional_of_dim_eq_zero h\n  apply eq_top_of_finrank_eq\n  rw [finrank_bot, finrank_eq_zero_of_dim_eq_zero h]\n#align bot_eq_top_of_dim_eq_zero bot_eq_top_of_dim_eq_zero\n\n@[simp]\ntheorem dim_eq_zero {S : Submodule K V} : Module.rank K S = 0 ↔ S = ⊥ :=\n  ⟨fun h =>\n    (Submodule.eq_bot_iff _).2 fun x hx =>\n      congr_arg Subtype.val <|\n        ((Submodule.eq_bot_iff _).1 <| Eq.symm <| bot_eq_top_of_dim_eq_zero h) ⟨x, hx⟩\n          Submodule.mem_top,\n    fun h => by rw [h, dim_bot]⟩\n#align dim_eq_zero dim_eq_zero\n\n@[simp]\ntheorem finrank_eq_zero {S : Submodule K V} [FiniteDimensional K S] : finrank K S = 0 ↔ S = ⊥ := by\n  rw [← dim_eq_zero, ← finrank_eq_dim, ← @Nat.cast_zero Cardinal, Cardinal.natCast_inj]\n#align finrank_eq_zero finrank_eq_zero\n\nend ZeroDim\n\nnamespace Submodule\n\nopen IsNoetherian FiniteDimensional\n\nsection DivisionRing\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\n/-- A submodule is finitely generated if and only if it is finite-dimensional -/\ntheorem fg_iff_finiteDimensional (s : Submodule K V) : s.Fg ↔ FiniteDimensional K s :=\n  ⟨fun h => Module.finite_def.2 <| (fg_top s).2 h, fun h => (fg_top s).1 <| Module.finite_def.1 h⟩\n#align submodule.fg_iff_finite_dimensional Submodule.fg_iff_finiteDimensional\n\n/-- A submodule contained in a finite-dimensional submodule is\nfinite-dimensional. -/\ntheorem finiteDimensional_of_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (h : S₁ ≤ S₂) :\n    FiniteDimensional K S₁ :=\n  haveI : IsNoetherian K S₂ := iff_fg.2 inferInstance\n  iff_fg.1\n    (IsNoetherian.iff_dim_lt_aleph0.2\n      (lt_of_le_of_lt (dim_le_of_submodule _ _ h) (dim_lt_aleph_0 K S₂)))\n#align submodule.finite_dimensional_of_le Submodule.finiteDimensional_of_le\n\n/-- The inf of two submodules, the first finite-dimensional, is\nfinite-dimensional. -/\ninstance finiteDimensional_inf_left (S₁ S₂ : Submodule K V) [FiniteDimensional K S₁] :\n    FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=\n  finiteDimensional_of_le inf_le_left\n#align submodule.finite_dimensional_inf_left Submodule.finiteDimensional_inf_left\n\n/-- The inf of two submodules, the second finite-dimensional, is\nfinite-dimensional. -/\ninstance finiteDimensional_inf_right (S₁ S₂ : Submodule K V) [FiniteDimensional K S₂] :\n    FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=\n  finiteDimensional_of_le inf_le_right\n#align submodule.finite_dimensional_inf_right Submodule.finiteDimensional_inf_right\n\n/-- The sup of two finite-dimensional submodules is\nfinite-dimensional. -/\ninstance finiteDimensional_sup (S₁ S₂ : Submodule K V) [h₁ : FiniteDimensional K S₁]\n    [h₂ : FiniteDimensional K S₂] : FiniteDimensional K (S₁ ⊔ S₂ : Submodule K V) :=\n  by\n  unfold FiniteDimensional at *\n  rw [finite_def] at *\n  exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂))\n#align submodule.finite_dimensional_sup Submodule.finiteDimensional_sup\n\n/-- The submodule generated by a finite supremum of finite dimensional submodules is\nfinite-dimensional.\n\nNote that strictly this only needs `∀ i ∈ s, finite_dimensional K (S i)`, but that doesn't\nwork well with typeclass search. -/\ninstance finiteDimensional_finset_sup {ι : Type _} (s : Finset ι) (S : ι → Submodule K V)\n    [∀ i, FiniteDimensional K (S i)] : FiniteDimensional K (s.sup S : Submodule K V) :=\n  by\n  refine'\n    @Finset.sup_induction _ _ _ _ s S (fun i => FiniteDimensional K ↥i) (finiteDimensional_bot K V)\n      _ fun i hi => by infer_instance\n  · intro S₁ hS₁ S₂ hS₂\n    exact Submodule.finiteDimensional_sup S₁ S₂\n#align submodule.finite_dimensional_finset_sup Submodule.finiteDimensional_finset_sup\n\n/-- The submodule generated by a supremum of finite dimensional submodules, indexed by a finite\ntype is finite-dimensional. -/\ninstance finiteDimensional_supᵢ {ι : Type _} [Finite ι] (S : ι → Submodule K V)\n    [∀ i, FiniteDimensional K (S i)] : FiniteDimensional K ↥(⨆ i, S i) :=\n  by\n  cases nonempty_fintype ι\n  rw [← Finset.sup_univ_eq_supᵢ]\n  exact Submodule.finiteDimensional_finset_sup _ _\n#align submodule.finite_dimensional_supr Submodule.finiteDimensional_supᵢ\n\n/-- The submodule generated by a supremum indexed by a proposition is finite-dimensional if\nthe submodule is. -/\ninstance finiteDimensional_supᵢ_prop {P : Prop} (S : P → Submodule K V)\n    [∀ h, FiniteDimensional K (S h)] : FiniteDimensional K ↥(⨆ h, S h) :=\n  by\n  by_cases hp : P\n  · rw [supᵢ_pos hp]\n    infer_instance\n  · rw [supᵢ_neg hp]\n    infer_instance\n#align submodule.finite_dimensional_supr_prop Submodule.finiteDimensional_supᵢ_prop\n\n/-- The dimension of a submodule is bounded by the dimension of the ambient space. -/\ntheorem finrank_le [FiniteDimensional K V] (s : Submodule K V) : finrank K s ≤ finrank K V := by\n  simpa only [Cardinal.natCast_le, ← finrank_eq_dim] using\n    s.subtype.dim_le_of_injective (injective_subtype s)\n#align submodule.finrank_le Submodule.finrank_le\n\n/-- The dimension of a quotient is bounded by the dimension of the ambient space. -/\ntheorem finrank_quotient_le [FiniteDimensional K V] (s : Submodule K V) :\n    finrank K (V ⧸ s) ≤ finrank K V := by\n  simpa only [Cardinal.natCast_le, ← finrank_eq_dim] using\n    (mkq s).dim_le_of_surjective (surjective_quot_mk _)\n#align submodule.finrank_quotient_le Submodule.finrank_quotient_le\n\n/-- In a finite-dimensional vector space, the dimensions of a submodule and of the corresponding\nquotient add up to the dimension of the space. -/\ntheorem finrank_quotient_add_finrank [FiniteDimensional K V] (s : Submodule K V) :\n    finrank K (V ⧸ s) + finrank K s = finrank K V :=\n  by\n  have := dim_quotient_add_dim s\n  rw [← finrank_eq_dim, ← finrank_eq_dim, ← finrank_eq_dim] at this\n  exact_mod_cast this\n#align submodule.finrank_quotient_add_finrank Submodule.finrank_quotient_add_finrank\n\n/-- The dimension of a strict submodule is strictly bounded by the dimension of the ambient\nspace. -/\ntheorem finrank_lt [FiniteDimensional K V] {s : Submodule K V} (h : s < ⊤) :\n    finrank K s < finrank K V :=\n  by\n  rw [← s.finrank_quotient_add_finrank, add_comm]\n  exact Nat.lt_add_of_zero_lt_left _ _ (finrank_pos_iff.mpr (quotient.nontrivial_of_lt_top _ h))\n#align submodule.finrank_lt Submodule.finrank_lt\n\n/-- The sum of the dimensions of s + t and s ∩ t is the sum of the dimensions of s and t -/\ntheorem dim_sup_add_dim_inf_eq (s t : Submodule K V) [FiniteDimensional K s]\n    [FiniteDimensional K t] :\n    finrank K ↥(s ⊔ t) + finrank K ↥(s ⊓ t) = finrank K ↥s + finrank K ↥t :=\n  by\n  have key : Module.rank K ↥(s ⊔ t) + Module.rank K ↥(s ⊓ t) = Module.rank K s + Module.rank K t :=\n    dim_sup_add_dim_inf_eq s t\n  repeat' rw [← finrank_eq_dim] at key\n  norm_cast  at key\n  exact key\n#align submodule.dim_sup_add_dim_inf_eq Submodule.dim_sup_add_dim_inf_eq\n\ntheorem dim_add_le_dim_add_dim (s t : Submodule K V) [FiniteDimensional K s]\n    [FiniteDimensional K t] : finrank K (s ⊔ t : Submodule K V) ≤ finrank K s + finrank K t :=\n  by\n  rw [← dim_sup_add_dim_inf_eq]\n  exact self_le_add_right _ _\n#align submodule.dim_add_le_dim_add_dim Submodule.dim_add_le_dim_add_dim\n\ntheorem eq_top_of_disjoint [FiniteDimensional K V] (s t : Submodule K V)\n    (hdim : finrank K s + finrank K t = finrank K V) (hdisjoint : Disjoint s t) : s ⊔ t = ⊤ :=\n  by\n  have h_finrank_inf : finrank K ↥(s ⊓ t) = 0 :=\n    by\n    rw [disjoint_iff_inf_le, le_bot_iff] at hdisjoint\n    rw [hdisjoint, finrank_bot]\n  apply eq_top_of_finrank_eq\n  rw [← hdim]\n  convert s.dim_sup_add_dim_inf_eq t\n  rw [h_finrank_inf]\n  rfl\n#align submodule.eq_top_of_disjoint Submodule.eq_top_of_disjoint\n\nend DivisionRing\n\nend Submodule\n\nnamespace LinearEquiv\n\nopen FiniteDimensional\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]\n  [Module K V₂]\n\n/-- Finite dimensionality is preserved under linear equivalence. -/\nprotected theorem finiteDimensional (f : V ≃ₗ[K] V₂) [FiniteDimensional K V] :\n    FiniteDimensional K V₂ :=\n  Module.Finite.equiv f\n#align linear_equiv.finite_dimensional LinearEquiv.finiteDimensional\n\nvariable {R M M₂ : Type _} [Ring R] [AddCommGroup M] [AddCommGroup M₂]\n\nvariable [Module R M] [Module R M₂]\n\nend LinearEquiv\n\nsection\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\ninstance finiteDimensional_finsupp {ι : Type _} [Finite ι] [h : FiniteDimensional K V] :\n    FiniteDimensional K (ι →₀ V) :=\n  (Finsupp.linearEquivFunOnFinite K V ι).symm.FiniteDimensional\n#align finite_dimensional_finsupp finiteDimensional_finsupp\n\nend\n\nnamespace FiniteDimensional\n\nsection DivisionRing\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]\n  [Module K V₂]\n\n/-- Two finite-dimensional vector spaces are isomorphic if they have the same (finite) dimension.\n-/\ntheorem nonempty_linearEquiv_of_finrank_eq [FiniteDimensional K V] [FiniteDimensional K V₂]\n    (cond : finrank K V = finrank K V₂) : Nonempty (V ≃ₗ[K] V₂) :=\n  nonempty_linearEquiv_of_lift_dim_eq <| by simp only [← finrank_eq_dim, cond, lift_nat_cast]\n#align finite_dimensional.nonempty_linear_equiv_of_finrank_eq FiniteDimensional.nonempty_linearEquiv_of_finrank_eq\n\n/-- Two finite-dimensional vector spaces are isomorphic if and only if they have the same (finite)\ndimension.\n-/\ntheorem nonempty_linearEquiv_iff_finrank_eq [FiniteDimensional K V] [FiniteDimensional K V₂] :\n    Nonempty (V ≃ₗ[K] V₂) ↔ finrank K V = finrank K V₂ :=\n  ⟨fun ⟨h⟩ => h.finrank_eq, fun h => nonempty_linearEquiv_of_finrank_eq h⟩\n#align finite_dimensional.nonempty_linear_equiv_iff_finrank_eq FiniteDimensional.nonempty_linearEquiv_iff_finrank_eq\n\nvariable (V V₂)\n\n/-- Two finite-dimensional vector spaces are isomorphic if they have the same (finite) dimension.\n-/\nnoncomputable def LinearEquiv.ofFinrankEq [FiniteDimensional K V] [FiniteDimensional K V₂]\n    (cond : finrank K V = finrank K V₂) : V ≃ₗ[K] V₂ :=\n  Classical.choice <| nonempty_linearEquiv_of_finrank_eq cond\n#align finite_dimensional.linear_equiv.of_finrank_eq FiniteDimensional.LinearEquiv.ofFinrankEq\n\nvariable {V}\n\ntheorem eq_of_le_of_finrank_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)\n    (hd : finrank K S₂ ≤ finrank K S₁) : S₁ = S₂ :=\n  by\n  rw [← LinearEquiv.finrank_eq (Submodule.comapSubtypeEquivOfLe hle)] at hd\n  exact\n    le_antisymm hle\n      (Submodule.comap_subtype_eq_top.1\n        (eq_top_of_finrank_eq (le_antisymm (comap (Submodule.subtype S₂) S₁).finrank_le hd)))\n#align finite_dimensional.eq_of_le_of_finrank_le FiniteDimensional.eq_of_le_of_finrank_le\n\n/-- If a submodule is less than or equal to a finite-dimensional\nsubmodule with the same dimension, they are equal. -/\ntheorem eq_of_le_of_finrank_eq {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)\n    (hd : finrank K S₁ = finrank K S₂) : S₁ = S₂ :=\n  eq_of_le_of_finrank_le hle hd.ge\n#align finite_dimensional.eq_of_le_of_finrank_eq FiniteDimensional.eq_of_le_of_finrank_eq\n\n@[simp]\ntheorem finrank_map_subtype_eq (p : Submodule K V) (q : Submodule K p) :\n    FiniteDimensional.finrank K (q.map p.Subtype) = FiniteDimensional.finrank K q :=\n  (Submodule.equivSubtypeMap p q).symm.finrank_eq\n#align finite_dimensional.finrank_map_subtype_eq FiniteDimensional.finrank_map_subtype_eq\n\nvariable {V₂} [FiniteDimensional K V] [FiniteDimensional K V₂]\n\n/-- Given isomorphic subspaces `p q` of vector spaces `V` and `V₁` respectively,\n  `p.quotient` is isomorphic to `q.quotient`. -/\nnoncomputable def LinearEquiv.quotEquivOfEquiv {p : Subspace K V} {q : Subspace K V₂}\n    (f₁ : p ≃ₗ[K] q) (f₂ : V ≃ₗ[K] V₂) : (V ⧸ p) ≃ₗ[K] V₂ ⧸ q :=\n  LinearEquiv.ofFinrankEq _ _\n    (by\n      rw [← @add_right_cancel_iff _ _ _ (finrank K p), Submodule.finrank_quotient_add_finrank,\n        LinearEquiv.finrank_eq f₁, Submodule.finrank_quotient_add_finrank,\n        LinearEquiv.finrank_eq f₂])\n#align finite_dimensional.linear_equiv.quot_equiv_of_equiv FiniteDimensional.LinearEquiv.quotEquivOfEquiv\n\n-- TODO: generalize to the case where one of `p` and `q` is finite-dimensional.\n/-- Given the subspaces `p q`, if `p.quotient ≃ₗ[K] q`, then `q.quotient ≃ₗ[K] p` -/\nnoncomputable def LinearEquiv.quotEquivOfQuotEquiv {p q : Subspace K V} (f : (V ⧸ p) ≃ₗ[K] q) :\n    (V ⧸ q) ≃ₗ[K] p :=\n  LinearEquiv.ofFinrankEq _ _ <|\n    add_right_cancel <| by\n      rw [Submodule.finrank_quotient_add_finrank, ← LinearEquiv.finrank_eq f, add_comm,\n        Submodule.finrank_quotient_add_finrank]\n#align finite_dimensional.linear_equiv.quot_equiv_of_quot_equiv FiniteDimensional.LinearEquiv.quotEquivOfQuotEquiv\n\nend DivisionRing\n\nend FiniteDimensional\n\nnamespace LinearMap\n\nopen FiniteDimensional\n\nsection DivisionRing\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]\n  [Module K V₂]\n\n/-- On a finite-dimensional space, an injective linear map is surjective. -/\ntheorem surjective_of_injective [FiniteDimensional K V] {f : V →ₗ[K] V} (hinj : Injective f) :\n    Surjective f := by\n  have h := dim_eq_of_injective _ hinj\n  rw [← finrank_eq_dim, ← finrank_eq_dim, nat_cast_inj] at h\n  exact range_eq_top.1 (eq_top_of_finrank_eq h.symm)\n#align linear_map.surjective_of_injective LinearMap.surjective_of_injective\n\n/-- The image under an onto linear map of a finite-dimensional space is also finite-dimensional. -/\ntheorem finiteDimensional_of_surjective [FiniteDimensional K V] (f : V →ₗ[K] V₂)\n    (hf : f.range = ⊤) : FiniteDimensional K V₂ :=\n  Module.Finite.of_surjective f <| range_eq_top.1 hf\n#align linear_map.finite_dimensional_of_surjective LinearMap.finiteDimensional_of_surjective\n\n/-- The range of a linear map defined on a finite-dimensional space is also finite-dimensional. -/\ninstance finiteDimensional_range [FiniteDimensional K V] (f : V →ₗ[K] V₂) :\n    FiniteDimensional K f.range :=\n  f.quotKerEquivRange.FiniteDimensional\n#align linear_map.finite_dimensional_range LinearMap.finiteDimensional_range\n\n/-- On a finite-dimensional space, a linear map is injective if and only if it is surjective. -/\ntheorem injective_iff_surjective [FiniteDimensional K V] {f : V →ₗ[K] V} :\n    Injective f ↔ Surjective f :=\n  ⟨surjective_of_injective, fun hsurj =>\n    let ⟨g, hg⟩ := f.exists_rightInverse_of_surjective (range_eq_top.2 hsurj)\n    have : Function.RightInverse g f := LinearMap.ext_iff.1 hg\n    (leftInverse_of_surjective_of_rightInverse (surjective_of_injective this.Injective)\n        this).Injective⟩\n#align linear_map.injective_iff_surjective LinearMap.injective_iff_surjective\n\ntheorem ker_eq_bot_iff_range_eq_top [FiniteDimensional K V] {f : V →ₗ[K] V} :\n    f.ker = ⊥ ↔ f.range = ⊤ := by rw [range_eq_top, ker_eq_bot, injective_iff_surjective]\n#align linear_map.ker_eq_bot_iff_range_eq_top LinearMap.ker_eq_bot_iff_range_eq_top\n\n/-- In a finite-dimensional space, if linear maps are inverse to each other on one side then they\nare also inverse to each other on the other side. -/\ntheorem mul_eq_one_of_mul_eq_one [FiniteDimensional K V] {f g : V →ₗ[K] V} (hfg : f * g = 1) :\n    g * f = 1 :=\n  by\n  have ginj : Injective g :=\n    HasLeftInverse.injective ⟨f, fun x => show (f * g) x = (1 : V →ₗ[K] V) x by rw [hfg] <;> rfl⟩\n  let ⟨i, hi⟩ :=\n    g.exists_rightInverse_of_surjective (range_eq_top.2 (injective_iff_surjective.1 ginj))\n  have : f * (g * i) = f * 1 := congr_arg _ hi\n  rw [← mul_assoc, hfg, one_mul, mul_one] at this <;> rwa [← this]\n#align linear_map.mul_eq_one_of_mul_eq_one LinearMap.mul_eq_one_of_mul_eq_one\n\n/-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if\nthey are inverse to each other on the other side. -/\ntheorem mul_eq_one_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f * g = 1 ↔ g * f = 1 :=\n  ⟨mul_eq_one_of_mul_eq_one, mul_eq_one_of_mul_eq_one⟩\n#align linear_map.mul_eq_one_comm LinearMap.mul_eq_one_comm\n\n/-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if\nthey are inverse to each other on the other side. -/\ntheorem comp_eq_id_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f.comp g = id ↔ g.comp f = id :=\n  mul_eq_one_comm\n#align linear_map.comp_eq_id_comm LinearMap.comp_eq_id_comm\n\n/-- rank-nullity theorem : the dimensions of the kernel and the range of a linear map add up to\nthe dimension of the source space. -/\ntheorem finrank_range_add_finrank_ker [FiniteDimensional K V] (f : V →ₗ[K] V₂) :\n    finrank K f.range + finrank K f.ker = finrank K V :=\n  by\n  rw [← f.quot_ker_equiv_range.finrank_eq]\n  exact Submodule.finrank_quotient_add_finrank _\n#align linear_map.finrank_range_add_finrank_ker LinearMap.finrank_range_add_finrank_ker\n\nend DivisionRing\n\nend LinearMap\n\nnamespace LinearEquiv\n\nopen FiniteDimensional\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\nvariable [FiniteDimensional K V]\n\n/-- The linear equivalence corresponging to an injective endomorphism. -/\nnoncomputable def ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) : V ≃ₗ[K] V :=\n  LinearEquiv.ofBijective f ⟨h_inj, LinearMap.injective_iff_surjective.mp h_inj⟩\n#align linear_equiv.of_injective_endo LinearEquiv.ofInjectiveEndo\n\n@[simp]\ntheorem coe_ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) :\n    ⇑(ofInjectiveEndo f h_inj) = f :=\n  rfl\n#align linear_equiv.coe_of_injective_endo LinearEquiv.coe_ofInjectiveEndo\n\n@[simp]\ntheorem ofInjectiveEndo_right_inv (f : V →ₗ[K] V) (h_inj : Injective f) :\n    f * (ofInjectiveEndo f h_inj).symm = 1 :=\n  LinearMap.ext <| (ofInjectiveEndo f h_inj).apply_symm_apply\n#align linear_equiv.of_injective_endo_right_inv LinearEquiv.ofInjectiveEndo_right_inv\n\n@[simp]\ntheorem ofInjectiveEndo_left_inv (f : V →ₗ[K] V) (h_inj : Injective f) :\n    ((ofInjectiveEndo f h_inj).symm : V →ₗ[K] V) * f = 1 :=\n  LinearMap.ext <| (ofInjectiveEndo f h_inj).symm_apply_apply\n#align linear_equiv.of_injective_endo_left_inv LinearEquiv.ofInjectiveEndo_left_inv\n\nend LinearEquiv\n\nnamespace LinearMap\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\ntheorem isUnit_iff_ker_eq_bot [FiniteDimensional K V] (f : V →ₗ[K] V) : IsUnit f ↔ f.ker = ⊥ :=\n  by\n  constructor\n  · rintro ⟨u, rfl⟩\n    exact LinearMap.ker_eq_bot_of_inverse u.inv_mul\n  · intro h_inj\n    rw [ker_eq_bot] at h_inj\n    exact\n      ⟨⟨f, (LinearEquiv.ofInjectiveEndo f h_inj).symm.toLinearMap,\n          LinearEquiv.ofInjectiveEndo_right_inv f h_inj,\n          LinearEquiv.ofInjectiveEndo_left_inv f h_inj⟩,\n        rfl⟩\n#align linear_map.is_unit_iff_ker_eq_bot LinearMap.isUnit_iff_ker_eq_bot\n\ntheorem isUnit_iff_range_eq_top [FiniteDimensional K V] (f : V →ₗ[K] V) : IsUnit f ↔ f.range = ⊤ :=\n  by rw [is_unit_iff_ker_eq_bot, ker_eq_bot_iff_range_eq_top]\n#align linear_map.is_unit_iff_range_eq_top LinearMap.isUnit_iff_range_eq_top\n\nend LinearMap\n\nopen Module FiniteDimensional\n\nsection\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\ntheorem finrank_zero_iff_forall_zero [FiniteDimensional K V] : finrank K V = 0 ↔ ∀ x : V, x = 0 :=\n  finrank_zero_iff.trans (subsingleton_iff_forall_eq 0)\n#align finrank_zero_iff_forall_zero finrank_zero_iff_forall_zero\n\n/-- If `ι` is an empty type and `V` is zero-dimensional, there is a unique `ι`-indexed basis. -/\nnoncomputable def basisOfFinrankZero [FiniteDimensional K V] {ι : Type _} [IsEmpty ι]\n    (hV : finrank K V = 0) : Basis ι K V :=\n  haveI : Subsingleton V := finrank_zero_iff.1 hV\n  Basis.empty _\n#align basis_of_finrank_zero basisOfFinrankZero\n\nend\n\nnamespace LinearMap\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]\n  [Module K V₂]\n\ntheorem injective_iff_surjective_of_finrank_eq_finrank [FiniteDimensional K V]\n    [FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} :\n    Function.Injective f ↔ Function.Surjective f :=\n  by\n  have := finrank_range_add_finrank_ker f\n  rw [← ker_eq_bot, ← range_eq_top]; refine' ⟨fun h => _, fun h => _⟩\n  · rw [h, finrank_bot, add_zero, H] at this\n    exact eq_top_of_finrank_eq this\n  · rw [h, finrank_top, H] at this\n    exact finrank_eq_zero.1 (add_right_injective _ this)\n#align linear_map.injective_iff_surjective_of_finrank_eq_finrank LinearMap.injective_iff_surjective_of_finrank_eq_finrank\n\ntheorem ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank [FiniteDimensional K V]\n    [FiniteDimensional K V₂] (H : finrank K V = finrank K V₂) {f : V →ₗ[K] V₂} :\n    f.ker = ⊥ ↔ f.range = ⊤ := by\n  rw [range_eq_top, ker_eq_bot, injective_iff_surjective_of_finrank_eq_finrank H]\n#align linear_map.ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank LinearMap.ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank\n\ntheorem finrank_le_finrank_of_injective [FiniteDimensional K V] [FiniteDimensional K V₂]\n    {f : V →ₗ[K] V₂} (hf : Function.Injective f) : finrank K V ≤ finrank K V₂ :=\n  calc\n    finrank K V = finrank K f.range + finrank K f.ker := (finrank_range_add_finrank_ker f).symm\n    _ = finrank K f.range := by rw [ker_eq_bot.2 hf, finrank_bot, add_zero]\n    _ ≤ finrank K V₂ := Submodule.finrank_le _\n    \n#align linear_map.finrank_le_finrank_of_injective LinearMap.finrank_le_finrank_of_injective\n\n/-- Given a linear map `f` between two vector spaces with the same dimension, if\n`ker f = ⊥` then `linear_equiv_of_injective` is the induced isomorphism\nbetween the two vector spaces. -/\nnoncomputable def linearEquivOfInjective [FiniteDimensional K V] [FiniteDimensional K V₂]\n    (f : V →ₗ[K] V₂) (hf : Injective f) (hdim : finrank K V = finrank K V₂) : V ≃ₗ[K] V₂ :=\n  LinearEquiv.ofBijective f\n    ⟨hf, (LinearMap.injective_iff_surjective_of_finrank_eq_finrank hdim).mp hf⟩\n#align linear_map.linear_equiv_of_injective LinearMap.linearEquivOfInjective\n\n@[simp]\ntheorem linearEquivOfInjective_apply [FiniteDimensional K V] [FiniteDimensional K V₂]\n    {f : V →ₗ[K] V₂} (hf : Injective f) (hdim : finrank K V = finrank K V₂) (x : V) :\n    f.linearEquivOfInjective hf hdim x = f x :=\n  rfl\n#align linear_map.linear_equiv_of_injective_apply LinearMap.linearEquivOfInjective_apply\n\nend LinearMap\n\nsection\n\n/-- A domain that is module-finite as an algebra over a field is a division ring. -/\nnoncomputable def divisionRingOfFiniteDimensional (F K : Type _) [Field F] [Ring K] [IsDomain K]\n    [Algebra F K] [FiniteDimensional F K] : DivisionRing K :=\n  { ‹IsDomain K›,\n    ‹Ring\n        K› with\n    inv := fun x =>\n      if H : x = 0 then 0\n      else\n        Classical.choose <|\n          (show Function.Surjective (LinearMap.mulLeft F x) from\n              LinearMap.injective_iff_surjective.1 fun _ _ => (mul_right_inj' H).1)\n            1\n    mul_inv_cancel := fun x hx =>\n      show x * dite _ _ _ = _ by\n        rw [dif_neg hx]\n        exact\n          Classical.choose_spec\n            ((show Function.Surjective (LinearMap.mulLeft F x) from\n                LinearMap.injective_iff_surjective.1 fun _ _ => (mul_right_inj' hx).1)\n              1)\n    inv_zero := dif_pos rfl }\n#align division_ring_of_finite_dimensional divisionRingOfFiniteDimensional\n\n/-- An integral domain that is module-finite as an algebra over a field is a field. -/\nnoncomputable def fieldOfFiniteDimensional (F K : Type _) [Field F] [CommRing K] [IsDomain K]\n    [Algebra F K] [FiniteDimensional F K] : Field K :=\n  { divisionRingOfFiniteDimensional F K, ‹CommRing K› with }\n#align field_of_finite_dimensional fieldOfFiniteDimensional\n\nend\n\nnamespace Submodule\n\nsection DivisionRing\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]\n  [Module K V₂]\n\ntheorem eq_top_of_finrank_eq [FiniteDimensional K V] {S : Submodule K V}\n    (h : finrank K S = finrank K V) : S = ⊤ :=\n  FiniteDimensional.eq_of_le_of_finrank_eq le_top (by simp [h, finrank_top])\n#align submodule.eq_top_of_finrank_eq Submodule.eq_top_of_finrank_eq\n\ntheorem finrank_le_finrank_of_le {s t : Submodule K V} [FiniteDimensional K t] (hst : s ≤ t) :\n    finrank K s ≤ finrank K t :=\n  calc\n    finrank K s = finrank K (comap t.Subtype s) := (comapSubtypeEquivOfLe hst).finrank_eq.symm\n    _ ≤ finrank K t := finrank_le _\n    \n#align submodule.finrank_le_finrank_of_le Submodule.finrank_le_finrank_of_le\n\ntheorem finrank_mono [FiniteDimensional K V] : Monotone fun s : Submodule K V => finrank K s :=\n  fun s t => finrank_le_finrank_of_le\n#align submodule.finrank_mono Submodule.finrank_mono\n\ntheorem finrank_lt_finrank_of_lt {s t : Submodule K V} [FiniteDimensional K t] (hst : s < t) :\n    finrank K s < finrank K t :=\n  (comapSubtypeEquivOfLe hst.le).finrank_eq.symm.trans_lt <|\n    finrank_lt (le_top.lt_of_ne <| hst.not_le ∘ comap_subtype_eq_top.1)\n#align submodule.finrank_lt_finrank_of_lt Submodule.finrank_lt_finrank_of_lt\n\ntheorem finrank_strictMono [FiniteDimensional K V] :\n    StrictMono fun s : Submodule K V => finrank K s := fun s t => finrank_lt_finrank_of_lt\n#align submodule.finrank_strict_mono Submodule.finrank_strictMono\n\ntheorem finrank_add_eq_of_isCompl [FiniteDimensional K V] {U W : Submodule K V} (h : IsCompl U W) :\n    finrank K U + finrank K W = finrank K V :=\n  by\n  rw [← dim_sup_add_dim_inf_eq, h.codisjoint.eq_top, h.disjoint.eq_bot, finrank_bot, add_zero]\n  exact finrank_top\n#align submodule.finrank_add_eq_of_is_compl Submodule.finrank_add_eq_of_isCompl\n\nend DivisionRing\n\nend Submodule\n\nsection DivisionRing\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\nsection Span\n\nopen Submodule\n\ntheorem finrank_span_singleton {v : V} (hv : v ≠ 0) : finrank K (K ∙ v) = 1 :=\n  by\n  apply le_antisymm\n  · exact finrank_span_le_card ({v} : Set V)\n  · rw [Nat.succ_le_iff, finrank_pos_iff]\n    use ⟨v, mem_span_singleton_self v⟩, 0\n    simp [hv]\n#align finrank_span_singleton finrank_span_singleton\n\ntheorem Set.finrank_mono [FiniteDimensional K V] {s t : Set V} (h : s ⊆ t) :\n    s.finrank K ≤ t.finrank K :=\n  finrank_mono (span_mono h)\n#align set.finrank_mono Set.finrank_mono\n\nend Span\n\nsection Basis\n\ntheorem span_eq_top_of_linearIndependent_of_card_eq_finrank {ι : Type _} [hι : Nonempty ι]\n    [Fintype ι] {b : ι → V} (lin_ind : LinearIndependent K b)\n    (card_eq : Fintype.card ι = finrank K V) : span K (Set.range b) = ⊤ :=\n  by\n  by_cases fin : FiniteDimensional K V\n  · haveI := Fin\n    by_contra ne_top\n    have lt_top : span K (Set.range b) < ⊤ := lt_of_le_of_ne le_top ne_top\n    exact ne_of_lt (Submodule.finrank_lt lt_top) (trans (finrank_span_eq_card lin_ind) card_eq)\n  · exfalso\n    apply ne_of_lt (fintype.card_pos_iff.mpr hι)\n    symm\n    replace fin := (not_iff_not.2 IsNoetherian.iff_fg).2 Fin\n    calc\n      Fintype.card ι = finrank K V := card_eq\n      _ = 0 := dif_neg (mt is_noetherian.iff_dim_lt_aleph_0.mpr Fin)\n      \n#align span_eq_top_of_linear_independent_of_card_eq_finrank span_eq_top_of_linearIndependent_of_card_eq_finrank\n\n/-- A linear independent family of `finrank K V` vectors forms a basis. -/\n@[simps]\nnoncomputable def basisOfLinearIndependentOfCardEqFinrank {ι : Type _} [Nonempty ι] [Fintype ι]\n    {b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) :\n    Basis ι K V :=\n  Basis.mk lin_ind <| (span_eq_top_of_linearIndependent_of_card_eq_finrank lin_ind card_eq).ge\n#align basis_of_linear_independent_of_card_eq_finrank basisOfLinearIndependentOfCardEqFinrank\n\n@[simp]\ntheorem coe_basisOfLinearIndependentOfCardEqFinrank {ι : Type _} [Nonempty ι] [Fintype ι]\n    {b : ι → V} (lin_ind : LinearIndependent K b) (card_eq : Fintype.card ι = finrank K V) :\n    ⇑(basisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = b :=\n  Basis.coe_mk _ _\n#align coe_basis_of_linear_independent_of_card_eq_finrank coe_basisOfLinearIndependentOfCardEqFinrank\n\n/-- A linear independent finset of `finrank K V` vectors forms a basis. -/\n@[simps]\nnoncomputable def finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty)\n    (lin_ind : LinearIndependent K (coe : s → V)) (card_eq : s.card = finrank K V) : Basis s K V :=\n  @basisOfLinearIndependentOfCardEqFinrank _ _ _ _ _ _ ⟨(⟨hs.some, hs.choose_spec⟩ : s)⟩ _ _ lin_ind\n    (trans (Fintype.card_coe _) card_eq)\n#align finset_basis_of_linear_independent_of_card_eq_finrank finsetBasisOfLinearIndependentOfCardEqFinrank\n\n@[simp]\ntheorem coe_finsetBasisOfLinearIndependentOfCardEqFinrank {s : Finset V} (hs : s.Nonempty)\n    (lin_ind : LinearIndependent K (coe : s → V)) (card_eq : s.card = finrank K V) :\n    ⇑(finsetBasisOfLinearIndependentOfCardEqFinrank hs lin_ind card_eq) = coe :=\n  Basis.coe_mk _ _\n#align coe_finset_basis_of_linear_independent_of_card_eq_finrank coe_finsetBasisOfLinearIndependentOfCardEqFinrank\n\n/-- A linear independent set of `finrank K V` vectors forms a basis. -/\n@[simps]\nnoncomputable def setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s]\n    (lin_ind : LinearIndependent K (coe : s → V)) (card_eq : s.toFinset.card = finrank K V) :\n    Basis s K V :=\n  basisOfLinearIndependentOfCardEqFinrank lin_ind (trans s.toFinset_card.symm card_eq)\n#align set_basis_of_linear_independent_of_card_eq_finrank setBasisOfLinearIndependentOfCardEqFinrank\n\n@[simp]\ntheorem coe_setBasisOfLinearIndependentOfCardEqFinrank {s : Set V} [Nonempty s] [Fintype s]\n    (lin_ind : LinearIndependent K (coe : s → V)) (card_eq : s.toFinset.card = finrank K V) :\n    ⇑(setBasisOfLinearIndependentOfCardEqFinrank lin_ind card_eq) = coe :=\n  Basis.coe_mk _ _\n#align coe_set_basis_of_linear_independent_of_card_eq_finrank coe_setBasisOfLinearIndependentOfCardEqFinrank\n\nend Basis\n\n/-!\nWe now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`.\n-/\n\n\nsection finrank_eq_one\n\n/-- A vector space with a nonzero vector `v` has dimension 1 iff `v` spans.\n-/\ntheorem finrank_eq_one_iff_of_nonzero (v : V) (nz : v ≠ 0) :\n    finrank K V = 1 ↔ span K ({v} : Set V) = ⊤ :=\n  ⟨fun h => by simpa using (basis_singleton PUnit h v nz).span_eq, fun s =>\n    finrank_eq_card_basis\n      (Basis.mk (linearIndependent_singleton nz)\n        (by\n          convert s\n          simp))⟩\n#align finrank_eq_one_iff_of_nonzero finrank_eq_one_iff_of_nonzero\n\n/-- A module with a nonzero vector `v` has dimension 1 iff every vector is a multiple of `v`.\n-/\ntheorem finrank_eq_one_iff_of_nonzero' (v : V) (nz : v ≠ 0) :\n    finrank K V = 1 ↔ ∀ w : V, ∃ c : K, c • v = w :=\n  by\n  rw [finrank_eq_one_iff_of_nonzero v nz]\n  apply span_singleton_eq_top_iff\n#align finrank_eq_one_iff_of_nonzero' finrank_eq_one_iff_of_nonzero'\n\n/-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis.\n-/\ntheorem finrank_eq_one_iff (ι : Type _) [Unique ι] : finrank K V = 1 ↔ Nonempty (Basis ι K V) :=\n  by\n  fconstructor\n  · intro h\n    haveI := finite_dimensional_of_finrank (_root_.zero_lt_one.trans_le h.symm.le)\n    exact ⟨basis_unique ι h⟩\n  · rintro ⟨b⟩\n    simpa using finrank_eq_card_basis b\n#align finrank_eq_one_iff finrank_eq_one_iff\n\n/-- A module has dimension 1 iff there is some nonzero `v : V` so every vector is a multiple of `v`.\n-/\ntheorem finrank_eq_one_iff' : finrank K V = 1 ↔ ∃ (v : V)(n : v ≠ 0), ∀ w : V, ∃ c : K, c • v = w :=\n  by\n  convert finrank_eq_one_iff PUnit\n  simp only [exists_prop, eq_iff_iff, Ne.def]\n  convert(Basis.basis_singleton_iff PUnit).symm\n  funext v\n  simp\n  infer_instance; infer_instance\n#align finrank_eq_one_iff' finrank_eq_one_iff'\n\n-- Not sure why this aren't found automatically.\n/-- A finite dimensional module has dimension at most 1 iff\nthere is some `v : V` so every vector is a multiple of `v`.\n-/\ntheorem finrank_le_one_iff [FiniteDimensional K V] :\n    finrank K V ≤ 1 ↔ ∃ v : V, ∀ w : V, ∃ c : K, c • v = w :=\n  by\n  fconstructor\n  · intro h\n    by_cases h' : finrank K V = 0\n    · use 0\n      intro w\n      use 0\n      haveI := finrank_zero_iff.mp h'\n      apply Subsingleton.elim\n    · replace h' := zero_lt_iff.mpr h'\n      have : finrank K V = 1 := by linarith\n      obtain ⟨v, -, p⟩ := finrank_eq_one_iff'.mp this\n      use ⟨v, p⟩\n  · rintro ⟨v, p⟩\n    exact finrank_le_one v p\n#align finrank_le_one_iff finrank_le_one_iff\n\ntheorem Submodule.finrank_le_one_iff_isPrincipal (W : Submodule K V) [FiniteDimensional K W] :\n    finrank K W ≤ 1 ↔ W.IsPrincipal := by\n  rw [← W.rank_le_one_iff_is_principal, ← finrank_eq_dim, ← Cardinal.natCast_le, Nat.cast_one]\n#align submodule.finrank_le_one_iff_is_principal Submodule.finrank_le_one_iff_isPrincipal\n\ntheorem Module.finrank_le_one_iff_top_isPrincipal [FiniteDimensional K V] :\n    finrank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by\n  rw [← Module.rank_le_one_iff_top_isPrincipal, ← finrank_eq_dim, ← Cardinal.natCast_le,\n    Nat.cast_one]\n#align module.finrank_le_one_iff_top_is_principal Module.finrank_le_one_iff_top_isPrincipal\n\n-- We use the `linear_map.compatible_smul` typeclass here, to encompass two situations:\n-- * `A = K`\n-- * `[field K] [algebra K A] [is_scalar_tower K A V] [is_scalar_tower K A W]`\ntheorem surjective_of_nonzero_of_finrank_eq_one {W A : Type _} [Semiring A] [Module A V]\n    [AddCommGroup W] [Module K W] [Module A W] [LinearMap.CompatibleSMul V W K A]\n    (h : finrank K W = 1) {f : V →ₗ[A] W} (w : f ≠ 0) : Surjective f :=\n  by\n  change surjective (f.restrict_scalars K)\n  obtain ⟨v, n⟩ := fun_like.ne_iff.mp w\n  intro z\n  obtain ⟨c, rfl⟩ := (finrank_eq_one_iff_of_nonzero' (f v) n).mp h z\n  exact ⟨c • v, by simp⟩\n#align surjective_of_nonzero_of_finrank_eq_one surjective_of_nonzero_of_finrank_eq_one\n\n/-- Any `K`-algebra module that is 1-dimensional over `K` is simple. -/\ntheorem is_simple_module_of_finrank_eq_one {A} [Semiring A] [Module A V] [SMul K A]\n    [IsScalarTower K A V] (h : finrank K V = 1) : IsSimpleOrder (Submodule A V) :=\n  by\n  haveI := nontrivial_of_finrank_eq_succ h\n  refine' ⟨fun S => or_iff_not_imp_left.2 fun hn => _⟩\n  rw [← restrict_scalars_inj K] at hn⊢\n  haveI := finite_dimensional_of_finrank_eq_succ h\n  refine' eq_top_of_finrank_eq ((Submodule.finrank_le _).antisymm _)\n  simpa only [h, finrank_bot] using Submodule.finrank_strictMono (Ne.bot_lt hn)\n#align is_simple_module_of_finrank_eq_one is_simple_module_of_finrank_eq_one\n\nend finrank_eq_one\n\nend DivisionRing\n\nsection SubalgebraDim\n\nopen Module\n\nvariable {F E : Type _} [Field F] [Ring E] [Algebra F E]\n\n/-- A `subalgebra` is `finite_dimensional` iff it is finite_dimensional as a submodule. -/\ntheorem Subalgebra.finiteDimensional_toSubmodule {S : Subalgebra F E} :\n    FiniteDimensional F S.toSubmodule ↔ FiniteDimensional F S :=\n  Iff.rfl\n#align subalgebra.finite_dimensional_to_submodule Subalgebra.finiteDimensional_toSubmodule\n\nalias Subalgebra.finiteDimensional_toSubmodule ↔\n  FiniteDimensional.of_subalgebra_toSubmodule FiniteDimensional.subalgebra_toSubmodule\n#align finite_dimensional.of_subalgebra_to_submodule FiniteDimensional.of_subalgebra_toSubmodule\n#align finite_dimensional.subalgebra_to_submodule FiniteDimensional.subalgebra_toSubmodule\n\ninstance FiniteDimensional.finiteDimensional_subalgebra [FiniteDimensional F E]\n    (S : Subalgebra F E) : FiniteDimensional F S :=\n  FiniteDimensional.of_subalgebra_toSubmodule inferInstance\n#align finite_dimensional.finite_dimensional_subalgebra FiniteDimensional.finiteDimensional_subalgebra\n\ninstance Subalgebra.finiteDimensional_bot : FiniteDimensional F (⊥ : Subalgebra F E) :=\n  by\n  nontriviality E\n  exact finiteDimensional_of_dim_eq_one Subalgebra.dim_bot\n#align subalgebra.finite_dimensional_bot Subalgebra.finiteDimensional_bot\n\ntheorem Subalgebra.eq_bot_of_dim_le_one {S : Subalgebra F E} (h : Module.rank F S ≤ 1) : S = ⊥ :=\n  by\n  nontriviality E\n  obtain ⟨m, hm, he⟩ := Cardinal.exists_nat_eq_of_le_nat (h.trans_eq nat.cast_one.symm)\n  haveI := finiteDimensional_of_dim_eq_nat he\n  rw [← not_bot_lt_iff, ← subalgebra.to_submodule.lt_iff_lt]\n  haveI := S.to_submodule_equiv.symm.FiniteDimensional\n  refine' fun hl => (Submodule.finrank_lt_finrank_of_lt hl).not_le (nat_cast_le.1 _)\n  iterate 2 rw [Subalgebra.finrank_toSubmodule, finrank_eq_dim]\n  exact h.trans_eq subalgebra.dim_bot.symm\n#align subalgebra.eq_bot_of_dim_le_one Subalgebra.eq_bot_of_dim_le_one\n\ntheorem Subalgebra.eq_bot_of_finrank_one {S : Subalgebra F E} (h : finrank F S = 1) : S = ⊥ :=\n  Subalgebra.eq_bot_of_dim_le_one <|\n    by\n    haveI := finite_dimensional_of_finrank_eq_succ h\n    rw [← finrank_eq_dim, h, Nat.cast_one]\n#align subalgebra.eq_bot_of_finrank_one Subalgebra.eq_bot_of_finrank_one\n\n@[simp]\ntheorem Subalgebra.dim_eq_one_iff [Nontrivial E] {S : Subalgebra F E} :\n    Module.rank F S = 1 ↔ S = ⊥ :=\n  ⟨fun h => Subalgebra.eq_bot_of_dim_le_one h.le, fun h => h.symm ▸ Subalgebra.dim_bot⟩\n#align subalgebra.dim_eq_one_iff Subalgebra.dim_eq_one_iff\n\n@[simp]\ntheorem Subalgebra.finrank_eq_one_iff [Nontrivial E] {S : Subalgebra F E} :\n    finrank F S = 1 ↔ S = ⊥ :=\n  ⟨Subalgebra.eq_bot_of_finrank_one, fun h => h.symm ▸ Subalgebra.finrank_bot⟩\n#align subalgebra.finrank_eq_one_iff Subalgebra.finrank_eq_one_iff\n\ntheorem Subalgebra.bot_eq_top_iff_dim_eq_one [Nontrivial E] :\n    (⊥ : Subalgebra F E) = ⊤ ↔ Module.rank F E = 1 := by\n  rw [← dim_top, ← subalgebra_top_dim_eq_submodule_top_dim, Subalgebra.dim_eq_one_iff, eq_comm]\n#align subalgebra.bot_eq_top_iff_dim_eq_one Subalgebra.bot_eq_top_iff_dim_eq_one\n\ntheorem Subalgebra.bot_eq_top_iff_finrank_eq_one [Nontrivial E] :\n    (⊥ : Subalgebra F E) = ⊤ ↔ finrank F E = 1 := by\n  rw [← finrank_top, ← subalgebra_top_finrank_eq_submodule_top_finrank,\n    Subalgebra.finrank_eq_one_iff, eq_comm]\n#align subalgebra.bot_eq_top_iff_finrank_eq_one Subalgebra.bot_eq_top_iff_finrank_eq_one\n\nalias Subalgebra.bot_eq_top_iff_dim_eq_one ↔ _ Subalgebra.bot_eq_top_of_dim_eq_one\n#align subalgebra.bot_eq_top_of_dim_eq_one Subalgebra.bot_eq_top_of_dim_eq_one\n\nalias Subalgebra.bot_eq_top_iff_finrank_eq_one ↔ _ Subalgebra.bot_eq_top_of_finrank_eq_one\n#align subalgebra.bot_eq_top_of_finrank_eq_one Subalgebra.bot_eq_top_of_finrank_eq_one\n\nattribute [simp] Subalgebra.bot_eq_top_of_finrank_eq_one Subalgebra.bot_eq_top_of_dim_eq_one\n\ntheorem Subalgebra.isSimpleOrder_of_finrank (hr : finrank F E = 2) :\n    IsSimpleOrder (Subalgebra F E) :=\n  let i := nontrivial_of_finrank_pos (zero_lt_two.trans_eq hr.symm)\n  { to_nontrivial :=\n      ⟨⟨⊥, ⊤, fun h => by cases hr.symm.trans (Subalgebra.bot_eq_top_iff_finrank_eq_one.1 h)⟩⟩\n    eq_bot_or_eq_top := by\n      intro S\n      haveI : FiniteDimensional F E := finite_dimensional_of_finrank_eq_succ hr\n      haveI : FiniteDimensional F S := FiniteDimensional.finiteDimensional_submodule S.to_submodule\n      have : finrank F S ≤ 2 := hr ▸ S.to_submodule.finrank_le\n      have : 0 < finrank F S := finrank_pos_iff.mpr inferInstance\n      interval_cases\n      · left\n        exact Subalgebra.eq_bot_of_finrank_one h\n      · right\n        rw [← hr] at h\n        rw [← Algebra.toSubmodule_eq_top]\n        exact Submodule.eq_top_of_finrank_eq h }\n#align subalgebra.is_simple_order_of_finrank Subalgebra.isSimpleOrder_of_finrank\n\nend SubalgebraDim\n\nnamespace Module\n\nnamespace End\n\nvariable [DivisionRing K] [AddCommGroup V] [Module K V]\n\ntheorem exists_ker_pow_eq_ker_pow_succ [FiniteDimensional K V] (f : End K V) :\n    ∃ k : ℕ, k ≤ finrank K V ∧ (f ^ k).ker = (f ^ k.succ).ker := by\n  classical\n    by_contra h_contra\n    simp_rw [not_exists, not_and] at h_contra\n    have h_le_ker_pow : ∀ n : ℕ, n ≤ (finrank K V).succ → n ≤ finrank K (f ^ n).ker :=\n      by\n      intro n hn\n      induction' n with n ih\n      · exact zero_le (finrank _ _)\n      · have h_ker_lt_ker : (f ^ n).ker < (f ^ n.succ).ker :=\n          by\n          refine' lt_of_le_of_ne _ (h_contra n (Nat.le_of_succ_le_succ hn))\n          rw [pow_succ]\n          apply LinearMap.ker_le_ker_comp\n        have h_finrank_lt_finrank : finrank K (f ^ n).ker < finrank K (f ^ n.succ).ker := by\n          apply Submodule.finrank_lt_finrank_of_lt h_ker_lt_ker\n        calc\n          n.succ ≤ (finrank K ↥(LinearMap.ker (f ^ n))).succ :=\n            Nat.succ_le_succ (ih (Nat.le_of_succ_le hn))\n          _ ≤ finrank K ↥(LinearMap.ker (f ^ n.succ)) := Nat.succ_le_of_lt h_finrank_lt_finrank\n          \n    have h_le_finrank_V : ∀ n, finrank K (f ^ n).ker ≤ finrank K V := fun n =>\n      Submodule.finrank_le _\n    have h_any_n_lt : ∀ n, n ≤ (finrank K V).succ → n ≤ finrank K V := fun n hn =>\n      (h_le_ker_pow n hn).trans (h_le_finrank_V n)\n    show False\n    exact Nat.not_succ_le_self _ (h_any_n_lt (finrank K V).succ (finrank K V).succ.le_refl)\n#align module.End.exists_ker_pow_eq_ker_pow_succ Module.End.exists_ker_pow_eq_ker_pow_succ\n\ntheorem ker_pow_constant {f : End K V} {k : ℕ} (h : (f ^ k).ker = (f ^ k.succ).ker) :\n    ∀ m, (f ^ k).ker = (f ^ (k + m)).ker\n  | 0 => by simp\n  | m + 1 => by\n    apply le_antisymm\n    · rw [add_comm, pow_add]\n      apply LinearMap.ker_le_ker_comp\n    · rw [ker_pow_constant m, add_comm m 1, ← add_assoc, pow_add, pow_add f k m]\n      change LinearMap.ker ((f ^ (k + 1)).comp (f ^ m)) ≤ LinearMap.ker ((f ^ k).comp (f ^ m))\n      rw [LinearMap.ker_comp, LinearMap.ker_comp, h, Nat.add_one]\n      exact le_rfl\n#align module.End.ker_pow_constant Module.End.ker_pow_constant\n\ntheorem ker_pow_eq_ker_pow_finrank_of_le [FiniteDimensional K V] {f : End K V} {m : ℕ}\n    (hm : finrank K V ≤ m) : (f ^ m).ker = (f ^ finrank K V).ker :=\n  by\n  obtain ⟨k, h_k_le, hk⟩ :\n    ∃ k, k ≤ finrank K V ∧ LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ) :=\n    exists_ker_pow_eq_ker_pow_succ f\n  calc\n    (f ^ m).ker = (f ^ (k + (m - k))).ker := by rw [add_tsub_cancel_of_le (h_k_le.trans hm)]\n    _ = (f ^ k).ker := by rw [ker_pow_constant hk _]\n    _ = (f ^ (k + (finrank K V - k))).ker := (ker_pow_constant hk (finrank K V - k))\n    _ = (f ^ finrank K V).ker := by rw [add_tsub_cancel_of_le h_k_le]\n    \n#align module.End.ker_pow_eq_ker_pow_finrank_of_le Module.End.ker_pow_eq_ker_pow_finrank_of_le\n\ntheorem ker_pow_le_ker_pow_finrank [FiniteDimensional K V] (f : End K V) (m : ℕ) :\n    (f ^ m).ker ≤ (f ^ finrank K V).ker :=\n  by\n  by_cases h_cases : m < finrank K V\n  · rw [← add_tsub_cancel_of_le (Nat.le_of_lt h_cases), add_comm, pow_add]\n    apply LinearMap.ker_le_ker_comp\n  · rw [ker_pow_eq_ker_pow_finrank_of_le (le_of_not_lt h_cases)]\n    exact le_rfl\n#align module.End.ker_pow_le_ker_pow_finrank Module.End.ker_pow_le_ker_pow_finrank\n\nend End\n\nend Module\n\nsection Module\n\nopen Module\n\nopen Cardinal\n\ntheorem cardinal_mk_eq_cardinal_mk_field_pow_dim (K V : Type u) [DivisionRing K] [AddCommGroup V]\n    [Module K V] [FiniteDimensional K V] : (#V) = (#K) ^ Module.rank K V :=\n  by\n  let s := Basis.ofVectorSpaceIndex K V\n  let hs := Basis.ofVectorSpace K V\n  calc\n    (#V) = (#s →₀ K) := Quotient.sound ⟨hs.repr.to_equiv⟩\n    _ = (#s → K) := (Quotient.sound ⟨Finsupp.equivFunOnFinite⟩)\n    _ = _ := by rw [← Cardinal.lift_inj.1 hs.mk_eq_dim, Cardinal.power_def]\n    \n#align cardinal_mk_eq_cardinal_mk_field_pow_dim cardinal_mk_eq_cardinal_mk_field_pow_dim\n\ntheorem cardinal_lt_aleph0_of_finiteDimensional (K V : Type u) [DivisionRing K] [AddCommGroup V]\n    [Module K V] [Finite K] [FiniteDimensional K V] : (#V) < ℵ₀ :=\n  by\n  letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance\n  rw [cardinal_mk_eq_cardinal_mk_field_pow_dim K V]\n  exact Cardinal.power_lt_aleph0 (Cardinal.lt_aleph0_of_finite K) (IsNoetherian.dim_lt_aleph0 K V)\n#align cardinal_lt_aleph_0_of_finite_dimensional cardinal_lt_aleph0_of_finiteDimensional\n\nend Module\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/FiniteDimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7720804277328863}}
{"text": "/-\nPropositions as types: the very idea.\n-/\n\n/-\nIdea #1. Use types to represent\nlogical propositions and values of\nthese types to represent \"evidence\" \nor \"proofs\" of truth. A type that\nis inhabited we then judge to be\nlogically true, and one that is \nuninhabited we judge to be false. \n-/\n\n/-\nIdea #2. When we use values of a\ntype only to represent evidence\nof logical truth, then it doesn't\nreally matter *which* value of a\ntype we pick as evidence. To the \nfirst order, we don't care which\nproof of a theorem a mathematician\nproduces, only that there is at\nleast one. And indeed, any proof\nwill do to justify a judgment that\na proposition is true. So when we\nrepresent propositions as types and\nproofs as values, in some sense we\nwant every proof of a given type to\nbe equivalent to any other. We want\nevery value of a \"logical\" type to\nbe equivalent to any other. Making\nthis equivalence of proof terms is\none of the main purposes of the last\nof Lean's type universes, which we \nnow introduce: Prop. \n-/\n\ninductive its_raining : Prop  -- not quite right\n| i_see_rain_falling : its_raining\n| i_hear_rain_on_roof : its_raining\n\ninductive streets_wet : Prop\n| i_see_wet_streets : streets_wet\n| i_feel_wet_streets : streets_wet\n\nopen its_raining streets_wet\n\ndef proof_1'' : its_raining := i_see_rain_falling\ndef proof_2'' : its_raining := i_hear_rain_on_roof\n\nlemma proof_1' : its_raining := i_see_rain_falling\nlemma proof_2' : its_raining := i_hear_rain_on_roof\n\ntheorem proof_1 : its_raining := i_see_rain_falling\ntheorem proof_2 : its_raining := i_hear_rain_on_roof\n\n/-\nWe just don't care which value of a\npropositional type is used. Values\nbuild by different constructors in \nType n, are always NOT equal. This \nis the idea that \"constructors are\ninjective and disjoint.\"\n-/\n\n/-\nProp        Sort 0\nType 0      Sort 1\nType 1      Sort 2\nType 2      Sort 3       \n...         ...\n-/\n\n-- Change Type to Prop above!\n\n/-\nJust as we can represent propositions\nas types, we can represent *predicates*\nas type families indexed by arguments, \ni.e., as \"propositions with parameters.\"\n-/\n\ninductive day : Type \n| su | mo | tu | we | th | fr | sa \n\nopen day\n\n/-\nA type family indexed by day representing\nthe predicate ⟨ is_always_rainy d ⟩, where\nd is a parameter of type day. Providing a\nvalue for d yields a specific proposition\nin the family of propositions we've defined, \nnamely one claims that a specific day, d, is\nalways rainy. \n-/\n\ninductive is_always_rainy : day → Sort 0\n| mo_rainy : ∀ (d :day), (d = mo) → is_always_rainy d\n\nopen is_always_rainy\n\n#check is_always_rainy\n#check is_always_rainy su\n#check is_always_rainy mo\n#check is_always_rainy tu\n\n\n\nlemma bad_tuesdays : is_always_rainy tu := mo_rainy _ _ -- stuck\nlemma bad_fridays : is_always_rainy fr := mo_rainy _ _    -- stuck\nlemma bad_mondays : is_always_rainy mo := mo_rainy mo (eq.refl mo)\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/propositions/propositions_as_types_the_idea.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7720559988228335}}
{"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₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`.\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ₙ₊₂ = Fₙ + Fₙ₊₁.`.\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 `⟨Fₙ, Fₙ₊₁⟩`. -/\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 : ℕ) : ℕ :=\n  prod.fst (fib_aux_stream n)\n\n@[simp] theorem fib_zero : fib 0 = 0 :=\n  rfl\n\n@[simp] theorem fib_one : fib 1 = 1 :=\n  rfl\n\n@[simp] theorem fib_two : fib (bit0 1) = 1 :=\n  rfl\n\n/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.` -/\ntheorem fib_succ_succ {n : ℕ} : fib (n + bit0 1) = fib n + fib (n + 1) := sorry\n\ntheorem fib_pos {n : ℕ} (n_pos : 0 < n) : 0 < fib n := sorry\n\ntheorem fib_le_fib_succ {n : ℕ} : fib n ≤ fib (n + 1) := sorry\n\ntheorem fib_mono : monotone fib :=\n  monotone_of_monotone_nat fun (_x : ℕ) => fib_le_fib_succ\n\ntheorem le_fib_self {n : ℕ} (five_le_n : bit1 (bit0 1) ≤ n) : n ≤ 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 : ℕ) : 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 : ℕ) (n : ℕ) : fib m * fib n + fib (m + 1) * fib (n + 1) = fib (m + n + 1) := sorry\n\ntheorem gcd_fib_add_self (m : ℕ) (n : ℕ) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) := sorry\n\ntheorem gcd_fib_add_mul_self (m : ℕ) (n : ℕ) (k : ℕ) : gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib 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 : ℕ) (n : ℕ) : fib (gcd m n) = gcd (fib m) (fib n) := sorry\n\ntheorem fib_dvd (m : ℕ) (n : ℕ) (h : m ∣ n) : fib m ∣ fib n :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (fib m ∣ 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))) (Eq.refl (fib m))))\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/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7720559631886941}}
{"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.normed_space.inner_product\nimport algebra.quadratic_discriminant\nimport analysis.normed_space.add_torsor\nimport data.matrix.notation\nimport linear_algebra.affine_space.finite_dimensional\nimport tactic.fin_cases\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* `inner_product_geometry.angle` is the undirected angle between two\n  vectors.\n\n* `euclidean_geometry.angle`, with notation `∠`, is the undirected\n  angle determined by three points.\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 `[inner_product_space ℝ V] [metric_space P]\n[normed_add_torsor V P]`.  This 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\nopen_locale real_inner_product_space\n\nnamespace inner_product_geometry\n/-!\n### Geometrical results on real inner product spaces\n\nThis section develops some geometrical definitions and results on real\ninner product spaces, where those definitions and results can most\nconveniently be developed in terms of vectors and then used to deduce\ncorresponding results for Euclidean affine spaces.\n-/\n\nvariables {V : Type*} [inner_product_space ℝ V]\n\n/-- The undirected angle between two vectors. If either vector is 0,\nthis is π/2. -/\ndef angle (x y : V) : ℝ := real.arccos (inner x y / (∥x∥ * ∥y∥))\n\n/-- The cosine of the angle between two vectors. -/\nlemma cos_angle (x y : V) : real.cos (angle x y) = inner x y / (∥x∥ * ∥y∥) :=\nreal.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\n/-- The angle between two vectors does not depend on their order. -/\nlemma angle_comm (x y : V) : angle x y = angle y x :=\nbegin\n  unfold angle,\n  rw [real_inner_comm, mul_comm]\nend\n\n/-- The angle between the negation of two vectors. -/\n@[simp] lemma angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y :=\nbegin\n  unfold angle,\n  rw [inner_neg_neg, norm_neg, norm_neg]\nend\n\n/-- The angle between two vectors is nonnegative. -/\nlemma angle_nonneg (x y : V) : 0 ≤ angle x y :=\nreal.arccos_nonneg _\n\n/-- The angle between two vectors is at most π. -/\nlemma angle_le_pi (x y : V) : angle x y ≤ π :=\nreal.arccos_le_pi _\n\n/-- The angle between a vector and the negation of another vector. -/\nlemma angle_neg_right (x y : V) : angle x (-y) = π - angle x y :=\nbegin\n  unfold angle,\n  rw [←real.arccos_neg, norm_neg, inner_neg_right, neg_div]\nend\n\n/-- The angle between the negation of a vector and another vector. -/\nlemma angle_neg_left (x y : V) : angle (-x) y = π - angle x y :=\nby rw [←angle_neg_neg, neg_neg, angle_neg_right]\n\n/-- The angle between the zero vector and a vector. -/\n@[simp] lemma angle_zero_left (x : V) : angle 0 x = π / 2 :=\nbegin\n  unfold angle,\n  rw [inner_zero_left, zero_div, real.arccos_zero]\nend\n\n/-- The angle between a vector and the zero vector. -/\n@[simp] lemma angle_zero_right (x : V) : angle x 0 = π / 2 :=\nbegin\n  unfold angle,\n  rw [inner_zero_right, zero_div, real.arccos_zero]\nend\n\n/-- The angle between a nonzero vector and itself. -/\n@[simp] lemma angle_self {x : V} (hx : x ≠ 0) : angle x x = 0 :=\nbegin\n  unfold angle,\n  rw [←real_inner_self_eq_norm_sq, div_self (λ h, hx (inner_self_eq_zero.1 h)),\n      real.arccos_one]\nend\n\n/-- The angle between a nonzero vector and its negation. -/\n@[simp] lemma angle_self_neg_of_nonzero {x : V} (hx : x ≠ 0) : angle x (-x) = π :=\nby rw [angle_neg_right, angle_self hx, sub_zero]\n\n/-- The angle between the negation of a nonzero vector and that\nvector. -/\n@[simp] lemma angle_neg_self_of_nonzero {x : V} (hx : x ≠ 0) : angle (-x) x = π :=\nby rw [angle_comm, angle_self_neg_of_nonzero hx]\n\n/-- The angle between a vector and a positive multiple of a vector. -/\n@[simp] lemma angle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :\n  angle x (r • y) = angle x y :=\nbegin\n  unfold angle,\n  rw [inner_smul_right, norm_smul, real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), ←mul_assoc,\n      mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)]\nend\n\n/-- The angle between a positive multiple of a vector and a vector. -/\n@[simp] lemma angle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :\n  angle (r • x) y = angle x y :=\nby rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm]\n\n/-- The angle between a vector and a negative multiple of a vector. -/\n@[simp] lemma angle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) :\n  angle x (r • y) = angle x (-y) :=\nby rw [←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\n/-- The angle between a negative multiple of a vector and a vector. -/\n@[simp] lemma angle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) :\n  angle (r • x) y = angle (-x) y :=\nby rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm]\n\n/-- The cosine of the angle between two vectors, multiplied by the\nproduct of their norms. -/\nlemma cos_angle_mul_norm_mul_norm (x y : V) : real.cos (angle x y) * (∥x∥ * ∥y∥) = inner x y :=\nbegin\n  rw [cos_angle, div_mul_cancel_of_imp],\n  simp [or_imp_distrib] { contextual := tt },\nend\n\n/-- The sine of the angle between two vectors, multiplied by the\nproduct of their norms. -/\nlemma sin_angle_mul_norm_mul_norm (x y : V) : real.sin (angle x y) * (∥x∥ * ∥y∥) =\n    real.sqrt (inner x x * inner y y - inner x y * inner x y) :=\nbegin\n  unfold angle,\n  rw [real.sin_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      ←real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),\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_sq,\n      real_inner_self_eq_norm_sq],\n  by_cases h : (∥x∥ * ∥y∥) = 0,\n  { rw [(show ∥x∥ * ∥x∥ * (∥y∥ * ∥y∥) = (∥x∥ * ∥y∥) * (∥x∥ * ∥y∥), by ring), h, mul_zero, mul_zero,\n        zero_sub],\n    cases eq_zero_or_eq_zero_of_mul_eq_zero h with hx hy,\n    { rw norm_eq_zero at hx,\n      rw [hx, inner_zero_left, zero_mul, neg_zero] },\n    { rw norm_eq_zero at hy,\n      rw [hy, inner_zero_right, zero_mul, neg_zero] } },\n  { field_simp [h],\n    ring_nf,\n    ring_nf, }\nend\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. -/\nlemma angle_eq_zero_iff {x y : V} : angle x y = 0 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), 0 < r ∧ y = r • x) :=\nbegin\n  rw [angle, ← real_inner_div_norm_mul_norm_eq_one_iff, real.arccos_eq_zero, has_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\nend\n\n/-- The angle between two vectors is π if and only if they are nonzero\nand one is a negative multiple of the other. -/\nlemma angle_eq_pi_iff {x y : V} : angle x y = π ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r < 0 ∧ y = r • x) :=\nbegin\n  rw [angle, ← real_inner_div_norm_mul_norm_eq_neg_one_iff, real.arccos_eq_pi, has_le.le.le_iff_eq],\n  exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1\nend\n\n/-- If the angle between two vectors is π, the angles between those\nvectors and a third vector add to π. -/\nlemma angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = π) :\n  angle x z + angle y z = π :=\nbegin\n  rcases angle_eq_pi_iff.1 h with ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩,\n  rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel'_right]\nend\n\n/-- Two vectors have inner product 0 if and only if the angle between\nthem is π/2. -/\nlemma inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : ⟪x, y⟫ = 0 ↔ angle x y = π / 2 :=\niff.symm $ by simp [angle, or_imp_distrib] { contextual := tt }\n\n/-- If the angle between two vectors is π, the inner product equals the negative product\nof the norms. -/\nlemma inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ⟪x, y⟫ = - (∥x∥ * ∥y∥) :=\nby simp [← cos_angle_mul_norm_mul_norm, h]\n\n/-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/\nlemma inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ⟪x, y⟫ = ∥x∥ * ∥y∥ :=\nby simp [← cos_angle_mul_norm_mul_norm, h]\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 π. -/\nlemma inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ⟪x, y⟫ = - (∥x∥ * ∥y∥) ↔ angle x y = π :=\nbegin\n  refine ⟨λ h, _, inner_eq_neg_mul_norm_of_angle_eq_pi⟩,\n  have h₁ : (∥x∥ * ∥y∥) ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne',\n  rw [angle, h, neg_div, div_self h₁, real.arccos_neg_one],\nend\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. -/\nlemma inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ⟪x, y⟫ = ∥x∥ * ∥y∥ ↔ angle x y = 0 :=\nbegin\n  refine ⟨λ h, _, inner_eq_mul_norm_of_angle_eq_zero⟩,\n  have h₁ : (∥x∥ * ∥y∥) ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne',\n  rw [angle, h, div_self h₁, real.arccos_one],\nend\n\n/-- If the angle between two vectors is π, the norm of their difference equals\nthe sum of their norms. -/\nlemma norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ∥x - y∥ = ∥x∥ + ∥y∥ :=\nbegin\n  rw ← eq_of_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,\nend\n\n/-- If the angle between two vectors is 0, the norm of their sum equals\nthe sum of their norms. -/\nlemma norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ∥x + y∥ = ∥x∥ + ∥y∥ :=\nbegin\n  rw ← eq_of_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,\nend\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. -/\nlemma norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :\n  ∥x - y∥ = abs (∥x∥ - ∥y∥) :=\nbegin\n  rw [← eq_of_sq_eq_sq (norm_nonneg (x - y)) (abs_nonneg (∥x∥ - ∥y∥)),\n      norm_sub_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (∥x∥ - ∥y∥)],\n  ring,\nend\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 π. -/\nlemma norm_sub_eq_add_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ∥x - y∥ = ∥x∥ + ∥y∥ ↔ angle x y = π :=\nbegin\n  refine ⟨λ h, _, norm_sub_eq_add_norm_of_angle_eq_pi⟩,\n  rw ← inner_eq_neg_mul_norm_iff_angle_eq_pi hx hy,\n  obtain ⟨hxy₁, hxy₂⟩ := ⟨norm_nonneg (x - y), add_nonneg (norm_nonneg x) (norm_nonneg y)⟩,\n  rw [← eq_of_sq_eq_sq hxy₁ hxy₂, norm_sub_pow_two_real] at h,\n  calc inner x y = (∥x∥ ^ 2 + ∥y∥ ^ 2 - (∥x∥ + ∥y∥) ^ 2) / 2 : by linarith\n  ...            = -(∥x∥ * ∥y∥) : by ring,\nend\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. -/\nlemma norm_add_eq_add_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ∥x + y∥ = ∥x∥ + ∥y∥ ↔ angle x y = 0 :=\nbegin\n  refine ⟨λ h, _, norm_add_eq_add_norm_of_angle_eq_zero⟩,\n  rw ← inner_eq_mul_norm_iff_angle_eq_zero hx hy,\n  obtain ⟨hxy₁, hxy₂⟩ := ⟨norm_nonneg (x + y), add_nonneg (norm_nonneg x) (norm_nonneg y)⟩,\n  rw [← eq_of_sq_eq_sq hxy₁ hxy₂, norm_add_pow_two_real] at h,\n  calc inner x y = ((∥x∥ + ∥y∥) ^ 2 - ∥x∥ ^ 2 - ∥y∥ ^ 2)/ 2 : by linarith\n  ...            = ∥x∥ * ∥y∥ : by ring,\nend\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. -/\nlemma norm_sub_eq_abs_sub_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ∥x - y∥ = abs (∥x∥ - ∥y∥) ↔ angle x y = 0 :=\nbegin\n  refine ⟨λ h, _, norm_sub_eq_abs_sub_norm_of_angle_eq_zero⟩,\n  rw ← inner_eq_mul_norm_iff_angle_eq_zero hx hy,\n  have h1 : ∥x - y∥ ^ 2 = (∥x∥ - ∥y∥) ^ 2, { rw h, exact sq_abs (∥x∥ - ∥y∥) },\n  rw norm_sub_pow_two_real at h1,\n  calc inner x y = ((∥x∥ + ∥y∥) ^ 2 - ∥x∥ ^ 2 - ∥y∥ ^ 2)/ 2 : by linarith\n  ...            = ∥x∥ * ∥y∥ : by ring,\nend\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 π/2. -/\nlemma norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (x y : V) :\n  ∥x + y∥ = ∥x - y∥ ↔ angle x y = π / 2 :=\nbegin\n  rw [← eq_of_sq_eq_sq (norm_nonneg (x + y)) (norm_nonneg (x - y)),\n      ← inner_eq_zero_iff_angle_eq_pi_div_two x y, norm_add_pow_two_real, norm_sub_pow_two_real],\n  split; intro h; linarith,\nend\n\nend inner_product_geometry\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-/\nopen inner_product_geometry\n\nvariables {V : Type*} {P : Type*} [inner_product_space ℝ V] [metric_space P]\n    [normed_add_torsor V P]\nlocal notation `⟪`x`, `y`⟫` := @inner ℝ V _ x y\ninclude V\n\n/-- The undirected angle at `p2` between the line segments to `p1` and\n`p3`. If either of those points equals `p2`, this is π/2. Use\n`open_locale euclidean_geometry` to access the `∠ p1 p2 p3`\nnotation. -/\ndef angle (p1 p2 p3 : P) : ℝ := angle (p1 -ᵥ p2 : V) (p3 -ᵥ p2)\n\nlocalized \"notation `∠` := euclidean_geometry.angle\" in euclidean_geometry\n\n/-- The angle at a point does not depend on the order of the other two\npoints. -/\nlemma angle_comm (p1 p2 p3 : P) : ∠ p1 p2 p3 = ∠ p3 p2 p1 :=\nangle_comm _ _\n\n/-- The angle at a point is nonnegative. -/\nlemma angle_nonneg (p1 p2 p3 : P) : 0 ≤ ∠ p1 p2 p3 :=\nangle_nonneg _ _\n\n/-- The angle at a point is at most π. -/\nlemma angle_le_pi (p1 p2 p3 : P) : ∠ p1 p2 p3 ≤ π :=\nangle_le_pi _ _\n\n/-- The angle ∠AAB at a point. -/\nlemma angle_eq_left (p1 p2 : P) : ∠ p1 p1 p2 = π / 2 :=\nbegin\n  unfold angle,\n  rw vsub_self,\n  exact angle_zero_left _\nend\n\n/-- The angle ∠ABB at a point. -/\nlemma angle_eq_right (p1 p2 : P) : ∠ p1 p2 p2 = π / 2 :=\nby rw [angle_comm, angle_eq_left]\n\n/-- The angle ∠ABA at a point. -/\nlemma angle_eq_of_ne {p1 p2 : P} (h : p1 ≠ p2) : ∠ p1 p2 p1 = 0 :=\nangle_self (λ he, h (vsub_eq_zero_iff_eq.1 he))\n\n/-- If the angle ∠ABC at a point is π, the angle ∠BAC is 0. -/\nlemma angle_eq_zero_of_angle_eq_pi_left {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) :\n  ∠ p2 p1 p3 = 0 :=\nbegin\n  unfold angle at h,\n  rw angle_eq_pi_iff at h,\n  rcases h with ⟨hp1p2, ⟨r, ⟨hr, hpr⟩⟩⟩,\n  unfold angle,\n  rw angle_eq_zero_iff,\n  rw [←neg_vsub_eq_vsub_rev, neg_ne_zero] at hp1p2,\n  use [hp1p2, -r + 1, add_pos (neg_pos_of_neg hr) zero_lt_one],\n  rw [add_smul, ←neg_vsub_eq_vsub_rev p1 p2, smul_neg],\n  simp [←hpr]\nend\n\n/-- If the angle ∠ABC at a point is π, the angle ∠BCA is 0. -/\nlemma angle_eq_zero_of_angle_eq_pi_right {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) :\n  ∠ p2 p3 p1 = 0 :=\nbegin\n  rw angle_comm at h,\n  exact angle_eq_zero_of_angle_eq_pi_left h\nend\n\n/-- If ∠BCD = π, then ∠ABC = ∠ABD. -/\nlemma angle_eq_angle_of_angle_eq_pi (p1 : P) {p2 p3 p4 : P} (h : ∠ p2 p3 p4 = π) :\n  ∠ p1 p2 p3 = ∠ p1 p2 p4 :=\nbegin\n  unfold angle at *,\n  rcases angle_eq_pi_iff.1 h with ⟨hp2p3, ⟨r, ⟨hr, hpr⟩⟩⟩,\n  rw [eq_comm],\n  convert angle_smul_right_of_pos (p1 -ᵥ p2) (p3 -ᵥ p2) (add_pos (neg_pos_of_neg hr) zero_lt_one),\n  rw [add_smul, ← neg_vsub_eq_vsub_rev p2 p3, smul_neg, neg_smul, ← hpr],\n  simp\nend\n\n/-- If ∠BCD = π, then ∠ACB + ∠ACD = π. -/\nlemma angle_add_angle_eq_pi_of_angle_eq_pi (p1 : P) {p2 p3 p4 : P} (h : ∠ p2 p3 p4 = π) :\n  ∠ p1 p3 p2 + ∠ p1 p3 p4 = π :=\nbegin\n  unfold angle at h,\n  rw [angle_comm p1 p3 p2, angle_comm p1 p3 p4],\n  unfold angle,\n  exact angle_add_angle_eq_pi_of_angle_eq_pi _ h\nend\n\n/-- Vertical Angles Theorem: angles opposite each other, formed by two intersecting straight\nlines, are equal. -/\nlemma angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi {p1 p2 p3 p4 p5 : P}\n  (hapc : ∠ p1 p5 p3 = π) (hbpd : ∠ p2 p5 p4 = π) : ∠ p1 p5 p2 = ∠ p3 p5 p4 :=\nby linarith [angle_add_angle_eq_pi_of_angle_eq_pi p1 hbpd, angle_comm p4 p5 p1,\n             angle_add_angle_eq_pi_of_angle_eq_pi p4 hapc, angle_comm p4 p5 p3]\n\n/-- If ∠ABC = π then dist A B ≠ 0. -/\nlemma left_dist_ne_zero_of_angle_eq_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) : dist p1 p2 ≠ 0 :=\nbegin\n  by_contra heq,\n  rw [not_not, dist_eq_zero] at heq,\n  rw [heq, angle_eq_left] at h,\n  exact real.pi_ne_zero (by linarith),\nend\n\n/-- If ∠ABC = π then dist C B ≠ 0. -/\nlemma right_dist_ne_zero_of_angle_eq_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) : dist p3 p2 ≠ 0 :=\nleft_dist_ne_zero_of_angle_eq_pi $ (angle_comm _ _ _).trans h\n\n/-- If ∠ABC = π, then (dist A C) = (dist A B) + (dist B C). -/\nlemma dist_eq_add_dist_of_angle_eq_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) :\n  dist p1 p3 = dist p1 p2 + dist p3 p2 :=\nbegin\n  rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],\n  exact norm_sub_eq_add_norm_of_angle_eq_pi h,\nend\n\n/-- If A ≠ B and C ≠ B then ∠ABC = π if and only if (dist A C) = (dist A B) + (dist B C). -/\nlemma dist_eq_add_dist_iff_angle_eq_pi {p1 p2 p3 : P} (hp1p2 : p1 ≠ p2) (hp3p2 : p3 ≠ p2) :\n  dist p1 p3 = dist p1 p2 + dist p3 p2 ↔ ∠ p1 p2 p3 = π :=\nbegin\n  rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],\n  exact norm_sub_eq_add_norm_iff_angle_eq_pi\n    ((λ he, hp1p2 (vsub_eq_zero_iff_eq.1 he))) (λ he, hp3p2 (vsub_eq_zero_iff_eq.1 he)),\nend\n\n/-- If ∠ABC = 0, then (dist A C) = abs ((dist A B) - (dist B C)). -/\nlemma dist_eq_abs_sub_dist_of_angle_eq_zero {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = 0) :\n  (dist p1 p3) = abs ((dist p1 p2) - (dist p3 p2)) :=\nbegin\n  rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],\n  exact norm_sub_eq_abs_sub_norm_of_angle_eq_zero h,\nend\n\n/-- If A ≠ B and C ≠ B then ∠ABC = 0 if and only if (dist A C) = abs ((dist A B) - (dist B C)). -/\nlemma dist_eq_abs_sub_dist_iff_angle_eq_zero {p1 p2 p3 : P} (hp1p2 : p1 ≠ p2) (hp3p2 : p3 ≠ p2) :\n  (dist p1 p3) = abs ((dist p1 p2) - (dist p3 p2)) ↔ ∠ p1 p2 p3 = 0 :=\nbegin\n  rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],\n  exact norm_sub_eq_abs_sub_norm_iff_angle_eq_zero\n    ((λ he, hp1p2 (vsub_eq_zero_iff_eq.1 he))) (λ he, hp3p2 (vsub_eq_zero_iff_eq.1 he)),\nend\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 ℝ p1 p2) = dist p2 (midpoint ℝ p1 p2) :=\nby rw [dist_left_midpoint p1 p2, dist_right_midpoint p1 p2]\n\n/-- If M is the midpoint of the segment AB, then ∠AMB = π. -/\nlemma angle_midpoint_eq_pi (p1 p2 : P) (hp1p2 : p1 ≠ p2) : ∠ p1 (midpoint ℝ p1 p2) p2 = π :=\nhave p2 -ᵥ midpoint ℝ p1 p2 = -(p1 -ᵥ midpoint ℝ p1 p2), by { rw neg_vsub_eq_vsub_rev, simp },\nby simp [angle, this, hp1p2]\n\n/-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B\nthen ∠CMA = π / 2. -/\nlemma angle_left_midpoint_eq_pi_div_two_of_dist_eq {p1 p2 p3 : P} (h : dist p3 p1 = dist p3 p2) :\n  ∠ p3 (midpoint ℝ p1 p2) p1 = π / 2 :=\nbegin\n  let m : P := midpoint ℝ p1 p2,\n  have h1 : p3 -ᵥ p1 = (p3 -ᵥ m) - (p1 -ᵥ m) := (vsub_sub_vsub_cancel_right p3 p1 m).symm,\n  have h2 : p3 -ᵥ p2 = (p3 -ᵥ m) + (p1 -ᵥ m),\n  { rw [left_vsub_midpoint, ← midpoint_vsub_right, vsub_add_vsub_cancel] },\n  rw [dist_eq_norm_vsub V p3 p1, dist_eq_norm_vsub V p3 p2, h1, h2] at h,\n  exact (norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (p3 -ᵥ m) (p1 -ᵥ m)).mp h.symm,\nend\n\n/-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B\nthen ∠CMB = π / 2. -/\nlemma angle_right_midpoint_eq_pi_div_two_of_dist_eq {p1 p2 p3 : P} (h : dist p3 p1 = dist p3 p2) :\n  ∠ p3 (midpoint ℝ p1 p2) p2 = π / 2 :=\nby rw [midpoint_comm p1 p2, angle_left_midpoint_eq_pi_div_two_of_dist_eq h.symm]\n\n/-- The inner product of two vectors given with `weighted_vsub`, in\nterms of the pairwise distances. -/\nlemma inner_weighted_vsub {ι₁ : Type*} {s₁ : finset ι₁} {w₁ : ι₁ → ℝ} (p₁ : ι₁ → P)\n    (h₁ : ∑ i in s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : finset ι₂} {w₂ : ι₂ → ℝ} (p₂ : ι₂ → P)\n    (h₂ : ∑ i in s₂, w₂ i = 0) :\n  inner (s₁.weighted_vsub p₁ w₁) (s₂.weighted_vsub p₂ w₂) =\n    (-∑ i₁ in s₁, ∑ i₂ in s₂,\n      w₁ i₁ * w₂ i₂ * (dist (p₁ i₁) (p₂ i₂) * dist (p₁ i₁) (p₂ i₂))) / 2 :=\nbegin\n  rw [finset.weighted_vsub_apply, finset.weighted_vsub_apply,\n      inner_sum_smul_sum_smul_of_sum_eq_zero _ h₁ _ h₂],\n  simp_rw [vsub_sub_vsub_cancel_right],\n  rcongr i₁ i₂; rw dist_eq_norm_vsub V (p₁ i₁) (p₂ i₂)\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₁` is equidistant from `p₁` and `p₂`, and the same\napplies to `c₂`.  Then the vector between `c₁` and `c₂` is orthogonal\nto that between `p₁` and `p₂`.  (In two dimensions, this says that the\ndiagonals of a kite are orthogonal.) -/\nlemma inner_vsub_vsub_of_dist_eq_of_dist_eq {c₁ c₂ p₁ p₂ : P} (hc₁ : dist p₁ c₁ = dist p₂ c₁)\n  (hc₂ : dist p₁ c₂ = dist p₂ c₂) : ⟪c₂ -ᵥ c₁, p₂ -ᵥ p₁⟫ = 0 :=\nbegin\n  have h : ⟪(c₂ -ᵥ c₁) + (c₂ -ᵥ c₁), p₂ -ᵥ p₁⟫ = 0,\n  { conv_lhs { congr, congr, rw ←vsub_sub_vsub_cancel_right c₂ c₁ p₁,\n               skip, rw ←vsub_sub_vsub_cancel_right c₂ c₁ p₂ },\n    rw [←add_sub_comm, inner_sub_left],\n    conv_lhs { congr, rw ←vsub_sub_vsub_cancel_right p₂ p₁ c₂,\n               skip, rw ←vsub_sub_vsub_cancel_right p₂ p₁ c₁ },\n    rw [dist_comm p₁, dist_comm p₂, dist_eq_norm_vsub V _ p₁,\n        dist_eq_norm_vsub V _ p₂, ←real_inner_add_sub_eq_zero_iff] at hc₁ hc₂,\n    simp_rw [←neg_vsub_eq_vsub_rev c₁, ←neg_vsub_eq_vsub_rev c₂, sub_neg_eq_add,\n             neg_add_eq_sub, hc₁, hc₂, sub_zero] },\n  simpa [inner_add_left, ←mul_two, (by norm_num : (2 : ℝ) ≠ 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 : ℝ) (v : V) (p₁ p₂ : P) :\n  dist (r • v +ᵥ p₁) p₂ * dist (r • v +ᵥ p₁) p₂ =\n    ⟪v, v⟫ * r * r + 2 * ⟪v, p₁ -ᵥ p₂⟫ * r + ⟪p₁ -ᵥ p₂, p₁ -ᵥ p₂⟫ :=\nbegin\n  rw [dist_eq_norm_vsub V _ p₂, ←real_inner_self_eq_norm_sq, 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₁ p₂ : P) (hv : v ≠ 0) (r : ℝ) :\n  dist (r • v +ᵥ p₁) p₂ = dist p₁ p₂ ↔ (r = 0 ∨ r = -2 * ⟪v, p₁ -ᵥ p₂⟫ / ⟪v, v⟫) :=\nbegin\n  conv_lhs { rw [←mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_smul_vadd_sq,\n                 ←sub_eq_zero, add_sub_assoc, dist_eq_norm_vsub V p₁ p₂,\n                 ←real_inner_self_eq_norm_sq, sub_self] },\n  have hvi : ⟪v, v⟫ ≠ 0, by simpa using hv,\n  have hd : discrim ⟪v, v⟫ (2 * ⟪v, p₁ -ᵥ p₂⟫) 0 =\n    (2 * inner v (p₁ -ᵥ p₂)) * (2 * inner v (p₁ -ᵥ p₂)),\n  { rw discrim, ring },\n  rw [quadratic_eq_zero_iff hvi hd, add_left_neg, zero_div, neg_mul_eq_neg_mul,\n      ←mul_sub_right_distrib, sub_eq_add_neg, ←mul_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₁` `r₂` of `p` from two different points `c₁` `c₂` determine at\nmost two points `p₁` `p₂` 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 ℝ P}\n  [finite_dimensional ℝ s.direction] (hd : finrank ℝ s.direction = 2) {c₁ c₂ p₁ p₂ p : P}\n  (hc₁s : c₁ ∈ s) (hc₂s : c₂ ∈ s) (hp₁s : p₁ ∈ s) (hp₂s : p₂ ∈ s) (hps : p ∈ s) {r₁ r₂ : ℝ}\n  (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁) (hp₂c₁ : dist p₂ c₁ = r₁)\n  (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂) (hp₂c₂ : dist p₂ c₂ = r₂)\n  (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ :=\nbegin\n  have ho : ⟪c₂ -ᵥ c₁, p₂ -ᵥ p₁⟫ = 0 :=\n    inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hp₂c₁.symm) (hp₁c₂.trans hp₂c₂.symm),\n  have hop : ⟪c₂ -ᵥ c₁, p -ᵥ p₁⟫ = 0 :=\n    inner_vsub_vsub_of_dist_eq_of_dist_eq (hp₁c₁.trans hpc₁.symm) (hp₁c₂.trans hpc₂.symm),\n  let b : fin 2 → V := ![c₂ -ᵥ c₁, p₂ -ᵥ p₁],\n  have hb : linear_independent ℝ 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 ℝ (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₂s hc₁s },\n      { exact vsub_mem_direction hp₂s hp₁s } },\n    { rw [finrank_span_eq_card hb, fintype.card_fin, hd] } },\n  have hv : ∀ v ∈ s.direction, ∃ t₁ t₂ : ℝ, v = t₁ • (c₂ -ᵥ c₁) + t₂ • (p₂ -ᵥ p₁),\n  { intros v hv,\n    have hr : set.range b = {c₂ -ᵥ c₁, p₂ -ᵥ p₁},\n    { have hu : (finset.univ : finset (fin 2)) = {0, 1}, by dec_trivial,\n      rw [←fintype.coe_image_univ, hu],\n      simp,\n      refl },\n    rw [←hbs, hr, submodule.mem_span_insert] at hv,\n    rcases hv with ⟨t₁, v', hv', hv⟩,\n    rw submodule.mem_span_singleton at hv',\n    rcases hv' with ⟨t₂, rfl⟩,\n    exact ⟨t₁, t₂, hv⟩ },\n  rcases hv (p -ᵥ p₁) (vsub_mem_direction hps hp₁s) with ⟨t₁, t₂, hpt⟩,\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, ←eq_vadd_iff_vsub_eq] at hpt,\n  subst hpt,\n  have hp' : (p₂ -ᵥ p₁ : V) ≠ 0, { simp [hp.symm] },\n  have hp₂ : dist ((1 : ℝ) • (p₂ -ᵥ p₁) +ᵥ p₁) c₁ = r₁, { simp [hp₂c₁] },\n  rw [←hp₁c₁, dist_smul_vadd_eq_dist _ _ hp'] at hpc₁ hp₂,\n  simp only [one_ne_zero, false_or] at hp₂,\n  rw hp₂.symm at hpc₁,\n  cases hpc₁; simp [hpc₁]\nend\n\n/-- Distances `r₁` `r₂` of `p` from two different points `c₁` `c₂` determine at\nmost two points `p₁` `p₂` 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 ℝ V] (hd : finrank ℝ V = 2)\n  {c₁ c₂ p₁ p₂ p : P} {r₁ r₂ : ℝ} (hc : c₁ ≠ c₂) (hp : p₁ ≠ p₂) (hp₁c₁ : dist p₁ c₁ = r₁)\n  (hp₂c₁ : dist p₂ c₁ = r₁) (hpc₁ : dist p c₁ = r₁) (hp₁c₂ : dist p₁ c₂ = r₂)\n  (hp₂c₂ : dist p₂ c₂ = r₂) (hpc₂ : dist p c₂ = r₂) : p = p₁ ∨ p = p₂ :=\nbegin\n  have hd' : finrank ℝ (⊤ : affine_subspace ℝ 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 ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _) (mem_top ℝ V _)\n    hc hp hp₁c₁ hp₂c₁ hpc₁ hp₁c₂ hp₂c₂ hpc₂\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 ℝ 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 ‹_›)\n  (mk'_nonempty p s.directionᗮ)\n  begin\n    convert submodule.is_compl_orthogonal_of_is_complete\n      (complete_space_coe_iff_is_complete.mp ‹_›),\n    exact direction_mk' p s.directionᗮ\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 ℝ P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  (s : set P) ∩ (mk' p s.directionᗮ) = {orthogonal_projection_fn s p} :=\nclassical.some_spec $ inter_eq_singleton_of_nonempty_of_is_compl\n  (nonempty_subtype.mp ‹_›)\n  (mk'_nonempty p s.directionᗮ)\n  begin\n    convert submodule.is_compl_orthogonal_of_is_complete\n      (complete_space_coe_iff_is_complete.mp ‹_›),\n    exact direction_mk' p s.directionᗮ\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 ℝ P} [nonempty s]\n  [complete_space s.direction] (p : P) : orthogonal_projection_fn s p ∈ s :=\nbegin\n  rw [←mem_coe, ←set.singleton_subset_iff, ←inter_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 ℝ P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  orthogonal_projection_fn s p ∈ mk' p s.directionᗮ :=\nbegin\n  rw [←mem_coe, ←set.singleton_subset_iff, ←inter_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 ℝ P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  orthogonal_projection_fn s p -ᵥ p ∈ s.directionᗮ :=\ndirection_mk' p s.directionᗮ ▸\n  vsub_mem_direction (orthogonal_projection_fn_mem_orthogonal p) (self_mem_mk' _ _)\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 ℝ P) [nonempty s] [complete_space s.direction] :\n  P →ᵃ[ℝ] s :=\n{ to_fun := λ p, ⟨orthogonal_projection_fn s p, orthogonal_projection_fn_mem p⟩,\n  linear := orthogonal_projection s.direction,\n  map_vadd' := λ p v, begin\n    have hs : ((orthogonal_projection s.direction) v : V) +ᵥ orthogonal_projection_fn s p ∈ 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) +ᵥ orthogonal_projection_fn s p ∈\n      mk' (v +ᵥ p) s.directionᗮ,\n    { rw [←vsub_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 [←neg_sub, inner_neg_left, orthogonal_projection_inner_eq_zero _ w hw, neg_zero], },\n    have hm : ((orthogonal_projection s.direction) v : V) +ᵥ orthogonal_projection_fn s p ∈\n      ({orthogonal_projection_fn s (v +ᵥ p)} : set P),\n    { rw ←inter_eq_singleton_orthogonal_projection_fn (v +ᵥ 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 ℝ 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 ℝ 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 ℝ P} [nonempty s]\n  [complete_space s.direction] (p : P) :\n  (s : set P) ∩ (mk' p s.directionᗮ) = {orthogonal_projection s p} :=\nbegin\n  rw ←orthogonal_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 ℝ P} [nonempty s] [complete_space s.direction]\n  (p : P) : ↑(orthogonal_projection s p) ∈ 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 ℝ P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  ↑(orthogonal_projection s p) ∈ mk' p s.directionᗮ :=\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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p1 : P} (p2 : P) (hp1 : p1 ∈ s) :\n  ↑(orthogonal_projection s p2 -ᵥ ⟨p1, hp1⟩ : s.direction) ∈ s.direction :=\n(orthogonal_projection s p2 -ᵥ ⟨p1, hp1⟩ : 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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p1 : P} (p2 : P) (hp1 : p1 ∈ s) :\n  ↑((⟨p1, hp1⟩ : s) -ᵥ orthogonal_projection s p2 : s.direction) ∈ s.direction :=\n((⟨p1, hp1⟩ : s) -ᵥ 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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p : P} :\n  ↑(orthogonal_projection s p) = p ↔ p ∈ s :=\nbegin\n  split,\n  { exact λ h, h ▸ orthogonal_projection_mem p },\n  { intro h,\n    have hp : p ∈ ((s : set P) ∩ mk' p s.directionᗮ) := ⟨h, self_mem_mk' p _⟩,\n    rw [inter_eq_singleton_orthogonal_projection p] at hp,\n    symmetry,\n    exact hp }\nend\n\n/-- Orthogonal projection is idempotent. -/\n@[simp] lemma orthogonal_projection_orthogonal_projection (s : affine_subspace ℝ 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 ℝ 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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p : P} :\n  dist p (orthogonal_projection s p) = 0 ↔ p ∈ 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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p : P} (hp : p ∉ s) :\n  dist p (orthogonal_projection s p) ≠ 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 ℝ P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  (orthogonal_projection s p : P) -ᵥ p ∈ s.directionᗮ :=\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 ℝ P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  p -ᵥ orthogonal_projection s p ∈ s.directionᗮ :=\ndirection_mk' p s.directionᗮ ▸\n  vsub_mem_direction (self_mem_mk' _ _) (orthogonal_projection_mem_orthogonal s p)\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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p : P} (hp : p ∈ s) {v : V}\n  (hv : v ∈ s.directionᗮ) :\n  orthogonal_projection s (v +ᵥ p) = ⟨p, hp⟩ :=\nbegin\n  have h := vsub_orthogonal_projection_mem_direction_orthogonal s (v +ᵥ 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 ℝ P}\n  [nonempty s] [complete_space s.direction] {p1 : P} (p2 : P) (r : ℝ) (hp : p1 ∈ s) :\n  orthogonal_projection s (r • (p2 -ᵥ orthogonal_projection s p2 : V) +ᵥ p1) = ⟨p1, hp⟩ :=\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 ℝ P} [nonempty s] [complete_space s.direction] {p1 : P}\n  (p2 : P) (hp1 : p1 ∈ 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 [pseudo_metric_space.dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _,\n    dist_eq_norm_vsub V _ p2, ← 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 ℝ P}\n    {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) (r1 r2 : ℝ) {v : V}\n    (hv : v ∈ s.directionᗮ) :\n  dist (r1 • v +ᵥ p1) (r2 • v +ᵥ p2) * dist (r1 • v +ᵥ p1) (r2 • v +ᵥ p2) =\n    dist p1 p2 * dist p1 p2 + (r1 - r2) * (r1 - r2) * (∥v∥ * ∥v∥) :=\ncalc dist (r1 • v +ᵥ p1) (r2 • v +ᵥ p2) * dist (r1 • v +ᵥ p1) (r2 • v +ᵥ p2)\n    = ∥(p1 -ᵥ p2) + (r1 - r2) • v∥ * ∥(p1 -ᵥ p2) + (r1 - r2) • v∥\n  : by { rw [dist_eq_norm_vsub V (r1 • v +ᵥ p1), vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, sub_smul],\n         abel }\n... = ∥p1 -ᵥ p2∥ * ∥p1 -ᵥ p2∥ + ∥(r1 - r2) • v∥ * ∥(r1 - r2) • v∥\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... = ∥(p1 -ᵥ p2 : V)∥ * ∥(p1 -ᵥ p2 : V)∥ + abs (r1 - r2) * abs (r1 - r2) * ∥v∥ * ∥v∥\n  : by { rw [norm_smul, real.norm_eq_abs], ring }\n... = dist p1 p2 * dist p1 p2 + (r1 - r2) * (r1 - r2) * (∥v∥ * ∥v∥)\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.  If\nthe subspace is empty or not complete, `orthogonal_projection` is\ndefined as the identity map, which results in `reflection` being the\nidentity map in that case as well. -/\ndef reflection (s : affine_subspace ℝ P) [nonempty s] [complete_space s.direction] :\n  P ≃ᵢ P :=\n{ to_fun := λ p, (↑(orthogonal_projection s p) -ᵥ p) +ᵥ orthogonal_projection s p,\n  inv_fun := λ p, (↑(orthogonal_projection s p) -ᵥ p) +ᵥ orthogonal_projection s p,\n  left_inv := λ p, by simp [vsub_vadd_eq_vsub_sub, -orthogonal_projection_linear],\n  right_inv := λ p, by simp [vsub_vadd_eq_vsub_sub, -orthogonal_projection_linear],\n  isometry_to_fun := begin\n    dsimp only,\n    rw isometry_emetric_iff_metric,\n    intros p₁ p₂,\n    rw [←mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_eq_norm_vsub V\n          ((↑(orthogonal_projection s p₁) -ᵥ p₁) +ᵥ ↑(orthogonal_projection s p₁)),\n        dist_eq_norm_vsub V p₁, ←inner_self_eq_norm_sq, ←inner_self_eq_norm_sq],\n    calc\n      ⟪((orthogonal_projection s p₁ : P) -ᵥ p₁ +ᵥ (orthogonal_projection s p₁ : P) -ᵥ\n      ((orthogonal_projection s p₂ : P) -ᵥ p₂ +ᵥ orthogonal_projection s p₂)),\n      ((orthogonal_projection s p₁ : P) -ᵥ p₁ +ᵥ (orthogonal_projection s p₁ : P) -ᵥ\n      ((orthogonal_projection s p₂ : P) -ᵥ p₂ +ᵥ orthogonal_projection s p₂))⟫\n        = ⟪(_root_.orthogonal_projection s.direction (p₁ -ᵥ p₂)) +\n          _root_.orthogonal_projection s.direction (p₁ -ᵥ p₂) - (p₁ -ᵥ p₂),\n          _root_.orthogonal_projection s.direction (p₁ -ᵥ p₂) +\n          _root_.orthogonal_projection s.direction (p₁ -ᵥ p₂) - (p₁ -ᵥ p₂)⟫\n        : by { rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_comm, add_sub_assoc,\n          ←vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub, ←add_sub_assoc, ←coe_vsub,\n          ←affine_map.linear_map_vsub], simp }\n    ... = -4 * inner (p₁ -ᵥ p₂ - (_root_.orthogonal_projection s.direction (p₁ -ᵥ p₂) : V))\n                   (_root_.orthogonal_projection s.direction (p₁ -ᵥ p₂)) +\n          ⟪p₁ -ᵥ p₂, p₁ -ᵥ p₂⟫\n        : by { simp [inner_sub_left, inner_sub_right, inner_add_left, inner_add_right,\n                 real_inner_comm (p₁ -ᵥ p₂)], ring }\n    ... = ⟪p₁ -ᵥ p₂, p₁ -ᵥ p₂⟫ : by simp,\n  end }\n\n/-- The result of reflecting. -/\nlemma reflection_apply (s : affine_subspace ℝ P) [nonempty s] [complete_space s.direction] (p : P) :\n  reflection s p = (↑(orthogonal_projection s p) -ᵥ p) +ᵥ orthogonal_projection s p :=\nrfl\n\nlemma eq_reflection_of_eq_subspace {s s' : affine_subspace ℝ 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/-- Reflection is its own inverse. -/\n@[simp] lemma reflection_symm (s : affine_subspace ℝ P) [nonempty s] [complete_space s.direction] :\n  (reflection s).symm = reflection s :=\nrfl\n\n/-- Reflecting twice in the same subspace. -/\n@[simp] lemma reflection_reflection (s : affine_subspace ℝ P) [nonempty s]\n  [complete_space s.direction] (p : P) :\n  reflection s (reflection s p) = p :=\n(reflection s).left_inv p\n\n/-- Reflection is involutive. -/\nlemma reflection_involutive (s : affine_subspace ℝ 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 ℝ P} [nonempty s] [complete_space s.direction]\n  (p : P) : reflection s p = p ↔ p ∈ s :=\nbegin\n  rw [←orthogonal_projection_eq_self_iff, reflection_apply],\n  split,\n  { intro h,\n    rw [←@vsub_eq_zero_iff_eq V, vadd_vsub_assoc,\n        ←two_smul ℝ (↑(orthogonal_projection s p) -ᵥ 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₁ s₂ : affine_subspace ℝ P)\n  [nonempty s₁] [nonempty s₂] [complete_space s₁.direction] [complete_space s₂.direction] (p : P) :\n  reflection s₁ p = reflection s₂ p ↔\n    (orthogonal_projection s₁ p : P) = orthogonal_projection s₂ p :=\nbegin\n  rw [reflection_apply, reflection_apply],\n  split,\n  { intro h,\n    rw [←@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        ←two_smul ℝ ((orthogonal_projection s₁ p : P) -ᵥ orthogonal_projection s₂ 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₁` and the reflection of `p₂` equals that\nbetween the reflection of `p₁` and `p₂`. -/\nlemma dist_reflection (s : affine_subspace ℝ P) [nonempty s] [complete_space s.direction]\n  (p₁ p₂ : P) :\n  dist p₁ (reflection s p₂) = dist (reflection s p₁) p₂ :=\nbegin\n  conv_lhs { rw ←reflection_reflection s p₁ },\n  exact (reflection s).dist_eq _ _\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 ℝ P) [nonempty s] [complete_space s.direction]\n  {p₁ : P} (hp₁ : p₁ ∈ s) (p₂ : P) :\n  dist p₁ (reflection s p₂) = dist p₁ p₂ :=\nbegin\n  rw ←reflection_eq_self_iff p₁ at hp₁,\n  convert (reflection s).dist_eq p₁ p₂,\n  rw hp₁\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₁ s₂ : affine_subspace ℝ P} [nonempty s₁]\n  [complete_space s₁.direction] (hle : s₁ ≤ s₂) {p : P}\n  (hp : p ∈ s₂) : reflection s₁ p ∈ s₂ :=\nbegin\n  rw [reflection_apply],\n  have ho : ↑(orthogonal_projection s₁ p) ∈ s₂ := 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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p : P} (hp : p ∈ s) {v : V}\n  (hv : v ∈ s.directionᗮ) : reflection s (v +ᵥ p) = -v +ᵥ 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 ℝ P} [nonempty s]\n  [complete_space s.direction] {p₁ : P} (p₂ : P) (r : ℝ) (hp₁ : p₁ ∈ s) :\n  reflection s (r • (p₂ -ᵥ orthogonal_projection s p₂) +ᵥ p₁) =\n    -(r • (p₂ -ᵥ orthogonal_projection s p₂)) +ᵥ p₁ :=\nreflection_orthogonal_vadd hp₁\n  (submodule.smul_mem _ _ (vsub_orthogonal_projection_mem_direction_orthogonal s _))\n\nomit V\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∃ (center : P) (radius : ℝ), ∀ p ∈ ps, dist p center = radius\n\n/-- The definition of `cospherical`. -/\nlemma cospherical_def (ps : set P) :\n  cospherical ps ↔ ∃ (center : P) (radius : ℝ), ∀ p ∈ ps, dist p center = radius :=\niff.rfl\n\n/-- A subset of a cospherical set is cospherical. -/\nlemma cospherical_subset {ps₁ ps₂ : set P} (hs : ps₁ ⊆ ps₂) (hc : cospherical ps₂) :\n  cospherical ps₁ :=\nbegin\n  rcases hc with ⟨c, r, hcr⟩,\n  exact ⟨c, r, λ p hp, hcr p (hs hp)⟩\nend\n\ninclude V\n\n/-- The empty set is cospherical. -/\nlemma cospherical_empty : cospherical (∅ : set P) :=\nbegin\n  use add_torsor.nonempty.some,\n  simp,\nend\n\nomit V\n\n/-- A single point is cospherical. -/\nlemma cospherical_singleton (p : P) : cospherical ({p} : set P) :=\nbegin\n  use p,\n  simp\nend\n\ninclude V\n\n/-- Two points are cospherical. -/\nlemma cospherical_insert_singleton (p₁ p₂ : P) : cospherical ({p₁, p₂} : set P) :=\nbegin\n  use [(2⁻¹ : ℝ) • (p₂ -ᵥ p₁) +ᵥ p₁, (2⁻¹ : ℝ) * (dist p₂ p₁)],\n  intro p,\n  rw [set.mem_insert_iff, set.mem_singleton_iff],\n  rintro ⟨_|_⟩,\n  { rw [dist_eq_norm_vsub V p₁, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, norm_neg, norm_smul,\n        dist_eq_norm_vsub V p₂],\n    simp },\n  { rw [H, dist_eq_norm_vsub V p₂, vsub_vadd_eq_vsub_sub, dist_eq_norm_vsub V p₂],\n    conv_lhs { congr, congr, rw ←one_smul ℝ (p₂ -ᵥ p₁ : V) },\n    rw [←sub_smul, norm_smul],\n    norm_num }\nend\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 → P}\n  (hps : set.range p ⊆ s) (hpi : function.injective p) :\n  affine_independent ℝ 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 ⟨v, hv⟩,\n  rw set.forall_range_iff at hv,\n  have hv0 : v ≠ 0,\n  { intro h,\n    have he : p 1 = p 0, by simpa [h] using hv 1,\n    exact (dec_trivial : (1 : fin 3) ≠ 0) (hpi he) },\n  rcases hs with ⟨c, r, hs⟩,\n  have hs' := λ i, hs (p i) (set.mem_of_mem_of_subset (set.mem_range_self _) hps),\n  choose f hf using hv,\n  have hsd : ∀ i, dist ((f i • v) +ᵥ p 0) c = r,\n  { intro i,\n    rw ←hf,\n    exact hs' i },\n  have hf0 : f 0 = 0,\n  { have hf0' := hf 0,\n    rw [eq_comm, ←@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, ←hf j] at hi,\n    exact hpi hi },\n  simp_rw [←hsd 0, hf0, zero_smul, zero_vadd, dist_smul_vadd_eq_dist (p 0) c hv0] at hsd,\n  have hfn0 : ∀ i, i ≠ 0 → f i ≠ 0 := λ i, (hfi.ne_iff' hf0).2,\n  have hfn0' : ∀ i, i ≠ 0 → f i = (-2) * ⟪v, (p 0 -ᵥ c)⟫ / ⟪v, v⟫,\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) ≠ 2) (hfi hf12)\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.949669363129097, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7719551923444508}}
{"text": "/-\nCopyright (c) 2022 Mac Malone. All rights reserved.\nReleased under the MIT license described in the file LICENSE.\nAuthors: Mac Malone\n-/\n\n/-!\nSome additions to `Classical` namespace to provide shorthand definitions\nfor common inference rules in classical logic.\n-/\n\nnamespace Classical\n\n/-- Double negation elimination -/\ntheorem dne {p : Prop} (h : ¬¬p) : p :=\n  Or.elim (em p)\n    (fun hp => hp)\n    (fun hnp => absurd hnp h)\n\n/--\nDe Morgan's law for conjunctions (i.e., `And`):\nthe negation of a conjunction is the disjunction of the negations.\n-/\ntheorem dm_and (h : ¬(p ∧ q)) : ¬p ∨ ¬q :=\n  Or.elim (em p)\n    (fun hp => Or.inr fun hq => h ⟨hp, hq⟩)\n    (fun hnp => Or.inl hnp)\n\n/--\nDe Morgan's law for disjunctions (i.e., `Or`):\nThe negation of a disjunction is the conjunction of the negations\n-/\ntheorem dm_or (h : ¬(p ∨ q)) : ¬p ∧ ¬q :=\n  And.intro\n    (Or.elim (em p)\n      (fun hp => absurd (Or.inl hp) h)\n      (fun hnp => hnp))\n    (Or.elim (em q)\n      (fun hq => absurd (Or.inr hq) h)\n      (fun hnq => hnq))\n", "meta": {"author": "tydeu", "repo": "folktale", "sha": "2a61a29003e5a9d6b704f75eadb8fd117aab3c85", "save_path": "github-repos/lean/tydeu-folktale", "path": "github-repos/lean/tydeu-folktale/folktale-2a61a29003e5a9d6b704f75eadb8fd117aab3c85/Folktale/Classical.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595115, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7719313473588222}}
{"text": "import tactic\nimport data.nat.basic\nimport data.nat.prime\nimport data.real.basic\nimport data.nat.gcd\nimport data.real.sqrt\nimport data.nat.parity\nimport tactic.slim_check\n\nnamespace lecture10\n\nopen nat\n\ndef irrational (r : ℝ) := ∀ (n d : ℕ), (d ≠ 0) -> coprime n d -> ¬ coe n / coe d = r\n\nlemma not_coprime_if_even {a b : ℕ} (even_a : even a) (even_b : even b) : ¬ (coprime a b) := \nbegin\n  intro h_coprime,\n  rw [coprime] at h_coprime,\n  have two_div_coprime : 2 ∣ gcd a b, \n  { exact dvd_gcd even_a even_b },\n  rw h_coprime at two_div_coprime,\n  finish,\nend\n\nlemma even_iff_even_square {a : ℕ} : even a ↔ even (a ^ 2) :=\nbegin\n  fconstructor,\n  {\n    intro h,\n    refine even_iff_two_dvd.mpr _,\n    cases h with k hk,\n    rw hk,\n    rw pow_two,\n    refine dvd_mul_of_dvd_left _ (2 * k),\n    exact dvd.intro k rfl,\n  },\n  {\n    intro h,\n    refine even_iff_two_dvd.mpr _,\n    rw pow_two at h,\n    rw even_mul at h,\n    finish,\n  },\nend\n\nlemma irrational_sqrt_2 : irrational (real.sqrt 2) := \nbegin\n  rw irrational,\n  intros n d d_neq_zero hcoprime,\n  by_contra,\n  have not_coprime : ¬ coprime n d,\n  \n  replace h : n^2 = 2 * d^2,\n  {\n    have x' : (coe n)^2 = (real.sqrt 2)^2 * (coe d)^2,\n    refine tactic.ring_exp.pow_pp_pf_prod _ rfl rfl,\n    refine (div_eq_iff _).mp h,\n    exact cast_ne_zero.mpr d_neq_zero,\n    rw real.sqr_sqrt at x',\n    assumption_mod_cast,\n    norm_num,\n  },\n\n  have even_n : even n,\n  {\n    refine even_iff_even_square.mpr _,\n    refine even_iff_two_dvd.mpr _,\n    exact dvd.intro (d ^ 2) (eq.symm h),\n  },\n\n  refine not_coprime_if_even even_n _,\n  refine even_iff_even_square.mpr _,\n\n  have even_pow_d_2 : even (d^2),\n  { \n    refine even_iff_two_dvd.mpr _,\n    cases even_n with k hk,\n    replace h : 2 * d^2 = 2 * (2 * k^2),\n    calc \n      2 * d^2 = n^2            : h.symm\n          ... = (2 * k)^2      : by rw hk\n          ... = 2^2 * k^2      : by linarith\n          ... = 4 * k^2        : by linarith\n          ... = 2 * (2 * k^2)  : by linarith,\n    replace h := (mul_right_inj' (by norm_num)).1 h,\n    exact dvd.intro (k ^ 2) (eq.symm h),\n  },\n\n  assumption,\n  contradiction,\nend\n\nend lecture10", "meta": {"author": "isovector", "repo": "math135", "sha": "e270f3a9cae435c066c0d2574f03a8adbe40b7b5", "save_path": "github-repos/lean/isovector-math135", "path": "github-repos/lean/isovector-math135/math135-e270f3a9cae435c066c0d2574f03a8adbe40b7b5/src/lecture10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701655, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7719313339724234}}
{"text": "variables p q r : Prop \n\nnamespace mth1001\n\nsection implication_elimination\n\n/-\nThe implication symbol `→` is entered as `\\r` or `\\to`. The statement `p → q`\nhas roughly the same meaning as the English phrase, 'if `p`, then `q`'.\n-/\n\n\n/-\nGiven `h : p → q` and `k : p`, we may deduce `q`. The proof of this is written\nin Lean simply as `h k`.\n-/\nexample (hpq : p → q) (hp : p) : q :=\nhpq hp \n\n/-\nThe same argument can be presented using tactics. The `apply` tactic tries\nto match the goal with the conclusion of the supplied argument. If the\nargument to `apply` involves additional premises, these are introduced as\nnew goals.\n\nHere, `q` is the initial goal. The conclusion of `hpq` is `q`, so `apply hpq`\napplies and replaces the goal `q` with the new goal `p`.\n-/\nexample (hpq : p → q) (hp : p) : q :=\nbegin \n  apply hpq,\n  exact hp,\nend\n\n-- As before, we write the proof term in tactic mode using `exact`.\nexample (hpq : p → q) (hp : p) : q :=\nbegin \n  exact hpq hp,\nend\n\n-- Exercise 022:\n-- We can use subscripts in our names. For example, `h₁` is written `h\\1`.\nexample (h₁ : p ∧ q → r) (h₂ : p) (h₃ : q) : r :=\nbegin \n  apply h₁,\n  sorry  \nend\n\n-- Exercise 023:\n-- Give a tactic-style proof of the following result.\nexample (h₁ : p → q) (h₂ : q → r) (h₃ : p) : r :=\nbegin \n  sorry  \nend\n\n-- Exercise 024:\n-- Give a term-style proof of the same result.\nexample (h₁ : p → q) (h₂ : q → r) (h₃ : p) : r :=\nhave h : q, from \n  sorry,\nsorry \n\n-- Exercise 025:\n/-\nOnce you complete the following example, see if you can write the solution\nas a single proof term.\n-/\nexample (a b c d e f : Prop)\n        (h₁ : d → a) (h₂ : f → b) (h₃ : e → c) (h₄ : e → a)\n        (h₅ : d → e) (h₆ : b → e) (h₇ : c) (h₈ : f) : a :=\nbegin \n  sorry  \nend\n\n\n\n\nend implication_elimination\n\n\nsection implication_introduction \n\n/-\nTo 'prove' a statement `p → q` is to assume (or introduce) a proof of `p` and then to derive `q`.\nThis is called implication introduction.\n-/\n\n-- Here is a one-line term-style derivation of `p → q` on the premise `h : q` \nexample (h : q) : p → q :=\nassume k : p, h\n\n-- We make the proof more readable using `show`\nexample (h : q) : p → q :=\nassume k : p,\nshow q, from h\n\n-- A similar terminology is used in tactic mode.\nexample (h : q) : p → q :=\nbegin\n  assume k : p,\n  exact h,\nend\n\n-- We don't need to specify _what_ we are assuming if we use `intro` instead of `assume`.\n-- Lean is clever enough to determine the type of the assumption from the goal.\nexample (h : q) : p → q :=\nbegin\n  intro k,\n  exact h,\nend\n\n-- Exercise 026:\n/-\nIn the above examples, we've seen that `p → q` can be deduced on the premise `q`. By\nimplication, we can derive `q → (p → q)` without any premise!\n-/\nexample : q → (p → q) :=\nbegin\n  assume h₁ : q,\n  sorry  \nend\n\n-- Exercise 027:\n-- You should be able to complete the following example simply by adding one line \n-- at the beginning to your solution to a previous example.\nexample : p ∧ q → q ∧ p :=\nbegin\n  sorry  \nend\n\nend implication_introduction\n\n/-\nSUMMARY\n\n* Implication elimination.\n* The `apply` tactic for applying an implication.\n\n* Implication introduction \n* Term-style implication introduction using `assume`.\n* Tactic-style implication introduction using `intro`.\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_03_implication.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8670357701094304, "lm_q1q2_score": 0.7719169500647817}}
{"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.parity\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.Algebra.GroupPower.Lemmas\n\n/-!  # Squares, even and odd elements\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves some general facts about squares, even and odd elements of semirings.\n\nIn the implementation, we define `is_square` and we let `even` be the notion transported by\n`to_additive`.  The definition are therefore as follows:\n```lean\nis_square a ↔ ∃ r, a = r * r\neven a ↔ ∃ r, a = r + r\n```\n\nOdd elements are not unified with a multiplicative notion.\n\n## Future work\n\n* TODO: Try to generalize further the typeclass assumptions on `is_square/even`.\n  For instance, in some cases, there are `semiring` assumptions that I (DT) am not convinced are\n  necessary.\n* TODO: Consider moving the definition and lemmas about `odd` to a separate file.\n* TODO: The \"old\" definition of `even a` asked for the existence of an element `c` such that\n  `a = 2 * c`.  For this reason, several fixes introduce an extra `two_mul` or `← two_mul`.\n  It might be the case that by making a careful choice of `simp` lemma, this can be avoided.\n -/\n\n\nopen MulOpposite\n\nvariable {F α β R : Type _}\n\nsection Mul\n\nvariable [Mul α]\n\n#print IsSquare /-\n/-- An element `a` of a type `α` with multiplication satisfies `is_square a` if `a = r * r`,\nfor some `r : α`. -/\n@[to_additive\n      \"An element `a` of a type `α` with addition satisfies `even a` if `a = r + r`,\\nfor some `r : α`.\"]\ndef IsSquare (a : α) : Prop :=\n  ∃ r, a = r * r\n#align is_square IsSquare\n#align even Even\n-/\n\n#print isSquare_mul_self /-\n@[simp, to_additive]\ntheorem isSquare_mul_self (m : α) : IsSquare (m * m) :=\n  ⟨m, rfl⟩\n#align is_square_mul_self isSquare_mul_self\n#align even_add_self even_add_self\n-/\n\n#print isSquare_op_iff /-\n@[to_additive]\ntheorem isSquare_op_iff (a : α) : IsSquare (op a) ↔ IsSquare a :=\n  ⟨fun ⟨c, hc⟩ => ⟨unop c, by rw [← unop_mul, ← hc, unop_op]⟩, fun ⟨c, hc⟩ => by simp [hc]⟩\n#align is_square_op_iff isSquare_op_iff\n#align even_op_iff even_op_iff\n-/\n\nend Mul\n\n/- warning: is_square_one -> isSquare_one is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : MulOneClass.{u1} α], IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α _inst_1) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α _inst_1))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : MulOneClass.{u1} α], IsSquare.{u1} α (MulOneClass.toMul.{u1} α _inst_1) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (MulOneClass.toOne.{u1} α _inst_1)))\nCase conversion may be inaccurate. Consider using '#align is_square_one isSquare_oneₓ'. -/\n@[simp, to_additive]\ntheorem isSquare_one [MulOneClass α] : IsSquare (1 : α) :=\n  ⟨1, (mul_one _).symm⟩\n#align is_square_one isSquare_one\n#align even_zero even_zero\n\n/- warning: is_square.map -> IsSquare.map is a dubious translation:\nlean 3 declaration is\n  forall {F : Type.{u1}} {α : Type.{u2}} {β : Type.{u3}} [_inst_1 : MulOneClass.{u2} α] [_inst_2 : MulOneClass.{u3} β] [_inst_3 : MonoidHomClass.{u1, u2, u3} F α β _inst_1 _inst_2] {m : α} (f : F), (IsSquare.{u2} α (MulOneClass.toHasMul.{u2} α _inst_1) m) -> (IsSquare.{u3} β (MulOneClass.toHasMul.{u3} β _inst_2) (coeFn.{succ u1, max (succ u2) (succ u3)} F (fun (_x : F) => α -> β) (FunLike.hasCoeToFun.{succ u1, succ u2, succ u3} F α (fun (_x : α) => β) (MulHomClass.toFunLike.{u1, u2, u3} F α β (MulOneClass.toHasMul.{u2} α _inst_1) (MulOneClass.toHasMul.{u3} β _inst_2) (MonoidHomClass.toMulHomClass.{u1, u2, u3} F α β _inst_1 _inst_2 _inst_3))) f m))\nbut is expected to have type\n  forall {F : Type.{u1}} {α : Type.{u3}} {β : Type.{u2}} [_inst_1 : MulOneClass.{u3} α] [_inst_2 : MulOneClass.{u2} β] [_inst_3 : MonoidHomClass.{u1, u3, u2} F α β _inst_1 _inst_2] {m : α} (f : F), (IsSquare.{u3} α (MulOneClass.toMul.{u3} α _inst_1) m) -> (IsSquare.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : α) => β) m) (MulOneClass.toMul.{u2} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : α) => β) m) _inst_2) (FunLike.coe.{succ u1, succ u3, succ u2} F α (fun (_x : α) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : α) => β) _x) (MulHomClass.toFunLike.{u1, u3, u2} F α β (MulOneClass.toMul.{u3} α _inst_1) (MulOneClass.toMul.{u2} β _inst_2) (MonoidHomClass.toMulHomClass.{u1, u3, u2} F α β _inst_1 _inst_2 _inst_3)) f m))\nCase conversion may be inaccurate. Consider using '#align is_square.map IsSquare.mapₓ'. -/\n@[to_additive]\ntheorem IsSquare.map [MulOneClass α] [MulOneClass β] [MonoidHomClass F α β] {m : α} (f : F) :\n    IsSquare m → IsSquare (f m) := by\n  rintro ⟨m, rfl⟩\n  exact ⟨f m, by simp⟩\n#align is_square.map IsSquare.map\n#align even.map Even.map\n\nsection Monoid\n\nvariable [Monoid α] {n : ℕ} {a : α}\n\n/- warning: is_square_iff_exists_sq -> isSquare_iff_exists_sq is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (m : α), Iff (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) m) (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) c (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 {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (m : α), Iff (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) m) (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) c (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)))))\nCase conversion may be inaccurate. Consider using '#align is_square_iff_exists_sq isSquare_iff_exists_sqₓ'. -/\n@[to_additive even_iff_exists_two_nsmul]\ntheorem isSquare_iff_exists_sq (m : α) : IsSquare m ↔ ∃ c, m = c ^ 2 := by simp [IsSquare, pow_two]\n#align is_square_iff_exists_sq isSquare_iff_exists_sq\n#align even_iff_exists_two_nsmul even_iff_exists_two_nsmul\n\n/- warning: is_square.exists_sq -> IsSquare.exists_sq is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (m : α), (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) m) -> (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) c (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 {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (m : α), (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) m) -> (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) c (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)))))\nCase conversion may be inaccurate. Consider using '#align is_square.exists_sq IsSquare.exists_sqₓ'. -/\n/- warning: is_square_of_exists_sq -> isSquare_of_exists_sq is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (m : α), (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) c (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))))) -> (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) m)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (m : α), (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) c (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))))) -> (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) m)\nCase conversion may be inaccurate. Consider using '#align is_square_of_exists_sq isSquare_of_exists_sqₓ'. -/\nalias isSquare_iff_exists_sq ↔ IsSquare.exists_sq isSquare_of_exists_sq\n#align is_square.exists_sq IsSquare.exists_sq\n#align is_square_of_exists_sq isSquare_of_exists_sq\n\nattribute\n  [to_additive Even.exists_two_nsmul\n      \"Alias of the forwards direction of\\n`even_iff_exists_two_nsmul`.\"]\n  IsSquare.exists_sq\n\nattribute\n  [to_additive even_of_exists_two_nsmul\n      \"Alias of the backwards direction of\\n`even_iff_exists_two_nsmul`.\"]\n  isSquare_of_exists_sq\n\n/- warning: is_square.pow -> IsSquare.pow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {a : α} (n : Nat), (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) a) -> (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {a : α} (n : Nat), (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) a) -> (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n))\nCase conversion may be inaccurate. Consider using '#align is_square.pow IsSquare.powₓ'. -/\n@[to_additive Even.nsmul]\ntheorem IsSquare.pow (n : ℕ) : IsSquare a → IsSquare (a ^ n) :=\n  by\n  rintro ⟨a, rfl⟩\n  exact ⟨a ^ n, (Commute.refl _).mul_pow _⟩\n#align is_square.pow IsSquare.pow\n#align even.nsmul Even.nsmul\n\n/- warning: even.is_square_pow -> Even.isSquare_pow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {n : Nat}, (Even.{0} Nat Nat.hasAdd n) -> (forall (a : α), IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {n : Nat}, (Even.{0} Nat instAddNat n) -> (forall (a : α), IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n))\nCase conversion may be inaccurate. Consider using '#align even.is_square_pow Even.isSquare_powₓ'. -/\n@[simp, to_additive Even.nsmul']\ntheorem Even.isSquare_pow : Even n → ∀ a : α, IsSquare (a ^ n) :=\n  by\n  rintro ⟨n, rfl⟩ a\n  exact ⟨a ^ n, pow_add _ _ _⟩\n#align even.is_square_pow Even.isSquare_pow\n#align even.nsmul' Even.nsmul'\n\n/- warning: is_square_sq -> IsSquare_sq is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (a : α), IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a (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 {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] (a : α), IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)))\nCase conversion may be inaccurate. Consider using '#align is_square_sq IsSquare_sqₓ'. -/\n@[simp, to_additive even_two_nsmul]\ntheorem IsSquare_sq (a : α) : IsSquare (a ^ 2) :=\n  ⟨a, pow_two _⟩\n#align is_square_sq IsSquare_sq\n#align even_two_nsmul even_two_nsmul\n\nvariable [HasDistribNeg α]\n\n/- warning: even.neg_pow -> Even.neg_pow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {n : Nat} [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))], (Even.{0} Nat Nat.hasAdd n) -> (forall (a : α), Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) a) n) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {n : Nat} [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))], (Even.{0} Nat instAddNat n) -> (forall (a : α), Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) a) n) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n))\nCase conversion may be inaccurate. Consider using '#align even.neg_pow Even.neg_powₓ'. -/\ntheorem Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n :=\n  by\n  rintro ⟨c, rfl⟩ a\n  simp_rw [← two_mul, pow_mul, neg_sq]\n#align even.neg_pow Even.neg_pow\n\n/- warning: even.neg_one_pow -> Even.neg_one_pow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {n : Nat} [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))], (Even.{0} Nat Nat.hasAdd n) -> (Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)))))) n) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] {n : Nat} [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))], (Even.{0} Nat instAddNat n) -> (Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (Monoid.toOne.{u1} α _inst_1)))) n) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (Monoid.toOne.{u1} α _inst_1))))\nCase conversion may be inaccurate. Consider using '#align even.neg_one_pow Even.neg_one_powₓ'. -/\ntheorem Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow]\n#align even.neg_one_pow Even.neg_one_pow\n\nend Monoid\n\n/- warning: is_square.mul -> IsSquare.mul is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : CommSemigroup.{u1} α] {a : α} {b : α}, (IsSquare.{u1} α (Semigroup.toHasMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1)) a) -> (IsSquare.{u1} α (Semigroup.toHasMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1)) b) -> (IsSquare.{u1} α (Semigroup.toHasMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1)) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Semigroup.toHasMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1))) a b))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : CommSemigroup.{u1} α] {a : α} {b : α}, (IsSquare.{u1} α (Semigroup.toMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1)) a) -> (IsSquare.{u1} α (Semigroup.toMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1)) b) -> (IsSquare.{u1} α (Semigroup.toMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1)) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Semigroup.toMul.{u1} α (CommSemigroup.toSemigroup.{u1} α _inst_1))) a b))\nCase conversion may be inaccurate. Consider using '#align is_square.mul IsSquare.mulₓ'. -/\n@[to_additive]\ntheorem IsSquare.mul [CommSemigroup α] {a b : α} : IsSquare a → IsSquare b → IsSquare (a * b) :=\n  by\n  rintro ⟨a, rfl⟩ ⟨b, rfl⟩\n  exact ⟨a * b, mul_mul_mul_comm _ _ _ _⟩\n#align is_square.mul IsSquare.mul\n#align even.add Even.add\n\nvariable (α)\n\n/- warning: is_square_zero -> isSquare_zero is a dubious translation:\nlean 3 declaration is\n  forall (α : Type.{u1}) [_inst_1 : MulZeroClass.{u1} α], IsSquare.{u1} α (MulZeroClass.toHasMul.{u1} α _inst_1) (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (MulZeroClass.toHasZero.{u1} α _inst_1))))\nbut is expected to have type\n  forall (α : Type.{u1}) [_inst_1 : MulZeroClass.{u1} α], IsSquare.{u1} α (MulZeroClass.toMul.{u1} α _inst_1) (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (MulZeroClass.toZero.{u1} α _inst_1)))\nCase conversion may be inaccurate. Consider using '#align is_square_zero isSquare_zeroₓ'. -/\n@[simp]\ntheorem isSquare_zero [MulZeroClass α] : IsSquare (0 : α) :=\n  ⟨0, (MulZeroClass.mul_zero _).symm⟩\n#align is_square_zero isSquare_zero\n\nvariable {α}\n\nsection DivisionMonoid\n\nvariable [DivisionMonoid α] {a : α}\n\n/- warning: is_square_inv -> isSquare_inv is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] {a : α}, Iff (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) (Inv.inv.{u1} α (DivInvMonoid.toHasInv.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)) a)) (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] {a : α}, Iff (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) (Inv.inv.{u1} α (InvOneClass.toInv.{u1} α (DivInvOneMonoid.toInvOneClass.{u1} α (DivisionMonoid.toDivInvOneMonoid.{u1} α _inst_1))) a)) (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) a)\nCase conversion may be inaccurate. Consider using '#align is_square_inv isSquare_invₓ'. -/\n@[simp, to_additive]\ntheorem isSquare_inv : IsSquare a⁻¹ ↔ IsSquare a :=\n  by\n  refine' ⟨fun h => _, fun h => _⟩\n  · rw [← isSquare_op_iff, ← inv_inv a]\n    exact h.map (MulEquiv.inv' α)\n  · exact ((isSquare_op_iff a).mpr h).map (MulEquiv.inv' α).symm\n#align is_square_inv isSquare_inv\n#align even_neg even_neg\n\n/- warning: is_square.inv -> IsSquare.inv is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] {a : α}, (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) a) -> (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) (Inv.inv.{u1} α (DivInvMonoid.toHasInv.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)) a))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] {a : α}, (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) a) -> (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) (Inv.inv.{u1} α (InvOneClass.toInv.{u1} α (DivInvOneMonoid.toInvOneClass.{u1} α (DivisionMonoid.toDivInvOneMonoid.{u1} α _inst_1))) a))\nCase conversion may be inaccurate. Consider using '#align is_square.inv IsSquare.invₓ'. -/\nalias isSquare_inv ↔ _ IsSquare.inv\n#align is_square.inv IsSquare.inv\n\nattribute [to_additive] IsSquare.inv\n\n/- warning: is_square.zpow -> IsSquare.zpow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] {a : α} (n : Int), (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) a) -> (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) a n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] {a : α} (n : Int), (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) a) -> (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) a n))\nCase conversion may be inaccurate. Consider using '#align is_square.zpow IsSquare.zpowₓ'. -/\n@[to_additive Even.zsmul]\ntheorem IsSquare.zpow (n : ℤ) : IsSquare a → IsSquare (a ^ n) :=\n  by\n  rintro ⟨a, rfl⟩\n  exact ⟨a ^ n, (Commute.refl _).mul_zpow _⟩\n#align is_square.zpow IsSquare.zpow\n#align even.zsmul Even.zsmul\n\nvariable [HasDistribNeg α] {n : ℤ}\n\n/- warning: even.neg_zpow -> Even.neg_zpow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))))] {n : Int}, (Even.{0} Int Int.hasAdd n) -> (forall (a : α), Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) _inst_2)) a) n) (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) a n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))))] {n : Int}, (Even.{0} Int Int.instAddInt n) -> (forall (a : α), Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) _inst_2)) a) n) (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) a n))\nCase conversion may be inaccurate. Consider using '#align even.neg_zpow Even.neg_zpowₓ'. -/\ntheorem Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n :=\n  by\n  rintro ⟨c, rfl⟩ a\n  exact zpow_bit0_neg _ _\n#align even.neg_zpow Even.neg_zpow\n\n/- warning: even.neg_one_zpow -> Even.neg_one_zpow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))))] {n : Int}, (Even.{0} Int Int.hasAdd n) -> (Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) _inst_2)) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))))))) n) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : DivisionMonoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))))] {n : Int}, (Even.{0} Int Int.instAddInt n) -> (Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1))) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α _inst_1)))) _inst_2)) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (InvOneClass.toOne.{u1} α (DivInvOneMonoid.toInvOneClass.{u1} α (DivisionMonoid.toDivInvOneMonoid.{u1} α _inst_1)))))) n) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (InvOneClass.toOne.{u1} α (DivInvOneMonoid.toInvOneClass.{u1} α (DivisionMonoid.toDivInvOneMonoid.{u1} α _inst_1))))))\nCase conversion may be inaccurate. Consider using '#align even.neg_one_zpow Even.neg_one_zpowₓ'. -/\ntheorem Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow]\n#align even.neg_one_zpow Even.neg_one_zpow\n\nend DivisionMonoid\n\n/- warning: even_abs -> even_abs is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : SubtractionMonoid.{u1} α] [_inst_2 : LinearOrder.{u1} α] {a : α}, Iff (Even.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (SubtractionMonoid.toSubNegMonoid.{u1} α _inst_1)))) (Abs.abs.{u1} α (Neg.toHasAbs.{u1} α (SubNegMonoid.toHasNeg.{u1} α (SubtractionMonoid.toSubNegMonoid.{u1} α _inst_1)) (SemilatticeSup.toHasSup.{u1} α (Lattice.toSemilatticeSup.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a)) (Even.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (SubtractionMonoid.toSubNegMonoid.{u1} α _inst_1)))) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : SubtractionMonoid.{u1} α] [_inst_2 : LinearOrder.{u1} α] {a : α}, Iff (Even.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (SubtractionMonoid.toSubNegMonoid.{u1} α _inst_1)))) (Abs.abs.{u1} α (Neg.toHasAbs.{u1} α (NegZeroClass.toNeg.{u1} α (SubNegZeroMonoid.toNegZeroClass.{u1} α (SubtractionMonoid.toSubNegZeroMonoid.{u1} α _inst_1))) (SemilatticeSup.toSup.{u1} α (Lattice.toSemilatticeSup.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_2))))) a)) (Even.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (SubNegMonoid.toAddMonoid.{u1} α (SubtractionMonoid.toSubNegMonoid.{u1} α _inst_1)))) a)\nCase conversion may be inaccurate. Consider using '#align even_abs even_absₓ'. -/\ntheorem even_abs [SubtractionMonoid α] [LinearOrder α] {a : α} : Even (|a|) ↔ Even a := by\n  cases abs_choice a <;> simp only [h, even_neg]\n#align even_abs even_abs\n\n/- warning: is_square.div -> IsSquare.div is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : DivisionCommMonoid.{u1} α] {a : α} {b : α}, (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1))))) a) -> (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1))))) b) -> (IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1))))) (HDiv.hDiv.{u1, u1, u1} α α α (instHDiv.{u1} α (DivInvMonoid.toHasDiv.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1)))) a b))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : DivisionCommMonoid.{u1} α] {a : α} {b : α}, (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1))))) a) -> (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1))))) b) -> (IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1))))) (HDiv.hDiv.{u1, u1, u1} α α α (instHDiv.{u1} α (DivInvMonoid.toDiv.{u1} α (DivisionMonoid.toDivInvMonoid.{u1} α (DivisionCommMonoid.toDivisionMonoid.{u1} α _inst_1)))) a b))\nCase conversion may be inaccurate. Consider using '#align is_square.div IsSquare.divₓ'. -/\n@[to_additive]\ntheorem IsSquare.div [DivisionCommMonoid α] {a b : α} (ha : IsSquare a) (hb : IsSquare b) :\n    IsSquare (a / b) := by\n  rw [div_eq_mul_inv]\n  exact ha.mul hb.inv\n#align is_square.div IsSquare.div\n#align even.sub Even.sub\n\n/- warning: even.is_square_zpow -> Even.isSquare_zpow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Group.{u1} α] {n : Int}, (Even.{0} Int Int.hasAdd n) -> (forall (a : α), IsSquare.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (Group.toDivInvMonoid.{u1} α _inst_1)))) (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (Group.toDivInvMonoid.{u1} α _inst_1))) a n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Group.{u1} α] {n : Int}, (Even.{0} Int Int.instAddInt n) -> (forall (a : α), IsSquare.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α (DivInvMonoid.toMonoid.{u1} α (Group.toDivInvMonoid.{u1} α _inst_1)))) (HPow.hPow.{u1, 0, u1} α Int α (instHPow.{u1, 0} α Int (DivInvMonoid.Pow.{u1} α (Group.toDivInvMonoid.{u1} α _inst_1))) a n))\nCase conversion may be inaccurate. Consider using '#align even.is_square_zpow Even.isSquare_zpowₓ'. -/\n@[simp, to_additive Even.zsmul']\ntheorem Even.isSquare_zpow [Group α] {n : ℤ} : Even n → ∀ a : α, IsSquare (a ^ n) :=\n  by\n  rintro ⟨n, rfl⟩ a\n  exact ⟨a ^ n, zpow_add _ _ _⟩\n#align even.is_square_zpow Even.isSquare_zpow\n#align even.zsmul' Even.zsmul'\n\n/- warning: even.tsub -> Even.tsub is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : CanonicallyLinearOrderedAddMonoid.{u1} α] [_inst_2 : Sub.{u1} α] [_inst_3 : OrderedSub.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedAddCommMonoid.toPartialOrder.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1))))) (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) _inst_2] [_inst_4 : ContravariantClass.{u1, u1} α α (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))))) (LE.le.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedAddCommMonoid.toPartialOrder.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1))))))] {m : α} {n : α}, (Even.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) m) -> (Even.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) n) -> (Even.{u1} α (AddZeroClass.toHasAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α _inst_2) m n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : CanonicallyLinearOrderedAddMonoid.{u1} α] [_inst_2 : Sub.{u1} α] [_inst_3 : OrderedSub.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedAddCommMonoid.toPartialOrder.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1))))) (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) _inst_2] [_inst_4 : ContravariantClass.{u1, u1} α α (fun (x._@.Mathlib.Algebra.Parity._hyg.1175 : α) (x._@.Mathlib.Algebra.Parity._hyg.1177 : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1))))))) x._@.Mathlib.Algebra.Parity._hyg.1175 x._@.Mathlib.Algebra.Parity._hyg.1177) (fun (x._@.Mathlib.Algebra.Parity._hyg.1190 : α) (x._@.Mathlib.Algebra.Parity._hyg.1192 : α) => LE.le.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedAddCommMonoid.toPartialOrder.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1))))) x._@.Mathlib.Algebra.Parity._hyg.1190 x._@.Mathlib.Algebra.Parity._hyg.1192)] {m : α} {n : α}, (Even.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) m) -> (Even.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) n) -> (Even.{u1} α (AddZeroClass.toAdd.{u1} α (AddMonoid.toAddZeroClass.{u1} α (AddCommMonoid.toAddMonoid.{u1} α (OrderedAddCommMonoid.toAddCommMonoid.{u1} α (CanonicallyOrderedAddMonoid.toOrderedAddCommMonoid.{u1} α (CanonicallyLinearOrderedAddMonoid.toCanonicallyOrderedAddMonoid.{u1} α _inst_1)))))) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α _inst_2) m n))\nCase conversion may be inaccurate. Consider using '#align even.tsub Even.tsubₓ'. -/\n-- `odd.tsub` requires `canonically_linear_ordered_semiring`, which we don't have\ntheorem Even.tsub [CanonicallyLinearOrderedAddMonoid α] [Sub α] [OrderedSub α]\n    [ContravariantClass α α (· + ·) (· ≤ ·)] {m n : α} (hm : Even m) (hn : Even n) : Even (m - n) :=\n  by\n  obtain ⟨a, rfl⟩ := hm\n  obtain ⟨b, rfl⟩ := hn\n  refine' ⟨a - b, _⟩\n  obtain h | h := le_total a b\n  · rw [tsub_eq_zero_of_le h, tsub_eq_zero_of_le (add_le_add h h), add_zero]\n  · exact (tsub_add_tsub_comm h h).symm\n#align even.tsub Even.tsub\n\n#print even_iff_exists_bit0 /-\ntheorem even_iff_exists_bit0 [Add α] {a : α} : Even a ↔ ∃ b, a = bit0 b :=\n  Iff.rfl\n#align even_iff_exists_bit0 even_iff_exists_bit0\n-/\n\nalias even_iff_exists_bit0 ↔ Even.exists_bit0 _\n#align even.exists_bit0 Even.exists_bit0\n\nsection Semiring\n\nvariable [Semiring α] [Semiring β] {m n : α}\n\n/- warning: even_iff_exists_two_mul -> even_iff_exists_two_mul is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (m : α), Iff (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))))))) c)))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (m : α), Iff (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) (Exists.{succ u1} α (fun (c : α) => Eq.{succ u1} α m (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) c)))\nCase conversion may be inaccurate. Consider using '#align even_iff_exists_two_mul even_iff_exists_two_mulₓ'. -/\ntheorem even_iff_exists_two_mul (m : α) : Even m ↔ ∃ c, m = 2 * c := by\n  simp [even_iff_exists_two_nsmul]\n#align even_iff_exists_two_mul even_iff_exists_two_mul\n\n/- warning: even_iff_two_dvd -> even_iff_two_dvd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, Iff (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a) (Dvd.Dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))))))) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, Iff (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a) (Dvd.dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) a)\nCase conversion may be inaccurate. Consider using '#align even_iff_two_dvd even_iff_two_dvdₓ'. -/\ntheorem even_iff_two_dvd {a : α} : Even a ↔ 2 ∣ a := by simp [Even, Dvd.Dvd, two_mul]\n#align even_iff_two_dvd even_iff_two_dvd\n\n/- warning: even.two_dvd -> Even.two_dvd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a) -> (Dvd.Dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))))))) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a) -> (Dvd.dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) a)\nCase conversion may be inaccurate. Consider using '#align even.two_dvd Even.two_dvdₓ'. -/\nalias even_iff_two_dvd ↔ Even.two_dvd _\n#align even.two_dvd Even.two_dvd\n\n/- warning: even.trans_dvd -> Even.trans_dvd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (Dvd.Dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) m n) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (Dvd.dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) m n) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n)\nCase conversion may be inaccurate. Consider using '#align even.trans_dvd Even.trans_dvdₓ'. -/\ntheorem Even.trans_dvd (hm : Even m) (hn : m ∣ n) : Even n :=\n  even_iff_two_dvd.2 <| hm.two_dvd.trans hn\n#align even.trans_dvd Even.trans_dvd\n\n/- warning: has_dvd.dvd.even -> Dvd.dvd.even is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Dvd.Dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) m n) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Dvd.dvd.{u1} α (semigroupDvd.{u1} α (SemigroupWithZero.toSemigroup.{u1} α (NonUnitalSemiring.toSemigroupWithZero.{u1} α (Semiring.toNonUnitalSemiring.{u1} α _inst_1)))) m n) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n)\nCase conversion may be inaccurate. Consider using '#align has_dvd.dvd.even Dvd.dvd.evenₓ'. -/\ntheorem Dvd.dvd.even (hn : m ∣ n) (hm : Even m) : Even n :=\n  hm.trans_dvd hn\n#align has_dvd.dvd.even Dvd.dvd.even\n\n/- warning: range_two_mul -> range_two_mul is a dubious translation:\nlean 3 declaration is\n  forall (α : Type.{u1}) [_inst_3 : Semiring.{u1} α], Eq.{succ u1} (Set.{u1} α) (Set.range.{u1, succ u1} α α (fun (x : α) => HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3))))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))))))) x)) (setOf.{u1} α (fun (a : α) => Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))) a))\nbut is expected to have type\n  forall (α : Type.{u1}) [_inst_3 : Semiring.{u1} α], Eq.{succ u1} (Set.{u1} α) (Set.range.{u1, succ u1} α α (fun (x : α) => HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_3) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) x)) (setOf.{u1} α (fun (a : α) => Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))) a))\nCase conversion may be inaccurate. Consider using '#align range_two_mul range_two_mulₓ'. -/\n@[simp]\ntheorem range_two_mul (α : Type _) [Semiring α] : (Set.range fun x : α => 2 * x) = { a | Even a } :=\n  by\n  ext x\n  simp [eq_comm, two_mul, Even]\n#align range_two_mul range_two_mul\n\n/- warning: even_bit0 -> even_bit0 is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (a : α), Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (a : α), Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (bit0.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a)\nCase conversion may be inaccurate. Consider using '#align even_bit0 even_bit0ₓ'. -/\n@[simp]\ntheorem even_bit0 (a : α) : Even (bit0 a) :=\n  ⟨a, rfl⟩\n#align even_bit0 even_bit0\n\n/- warning: even_two -> even_two is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α], Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α], Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))))\nCase conversion may be inaccurate. Consider using '#align even_two even_twoₓ'. -/\n@[simp]\ntheorem even_two : Even (2 : α) :=\n  ⟨1, rfl⟩\n#align even_two even_two\n\n/- warning: even.mul_left -> Even.mul_left is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (forall (n : α), Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) n m))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (forall (n : α), Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n m))\nCase conversion may be inaccurate. Consider using '#align even.mul_left Even.mul_leftₓ'. -/\n@[simp]\ntheorem Even.mul_left (hm : Even m) (n) : Even (n * m) :=\n  hm.map (AddMonoidHom.mulLeft n)\n#align even.mul_left Even.mul_left\n\n/- warning: even.mul_right -> Even.mul_right is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (forall (n : α), Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (forall (n : α), Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m n))\nCase conversion may be inaccurate. Consider using '#align even.mul_right Even.mul_rightₓ'. -/\n@[simp]\ntheorem Even.mul_right (hm : Even m) (n) : Even (m * n) :=\n  hm.map (AddMonoidHom.mulRight n)\n#align even.mul_right Even.mul_right\n\n/- warning: even_two_mul -> even_two_mul is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (m : α), Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))))))) m)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (m : α), Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) m)\nCase conversion may be inaccurate. Consider using '#align even_two_mul even_two_mulₓ'. -/\ntheorem even_two_mul (m : α) : Even (2 * m) :=\n  ⟨m, two_mul _⟩\n#align even_two_mul even_two_mul\n\n/- warning: even.pow_of_ne_zero -> Even.pow_of_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (forall {a : Nat}, (Ne.{1} Nat a (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α (MonoidWithZero.toMonoid.{u1} α (Semiring.toMonoidWithZero.{u1} α _inst_1)))) m a)))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (forall {a : Nat}, (Ne.{1} Nat a (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α (MonoidWithZero.toMonoid.{u1} α (Semiring.toMonoidWithZero.{u1} α _inst_1)))) m a)))\nCase conversion may be inaccurate. Consider using '#align even.pow_of_ne_zero Even.pow_of_ne_zeroₓ'. -/\ntheorem Even.pow_of_ne_zero (hm : Even m) : ∀ {a : ℕ}, a ≠ 0 → Even (m ^ a)\n  | 0, a0 => (a0 rfl).elim\n  | a + 1, _ => by\n    rw [pow_succ]\n    exact hm.mul_right _\n#align even.pow_of_ne_zero Even.pow_of_ne_zero\n\nsection WithOdd\n\n#print Odd /-\n/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/\ndef Odd (a : α) : Prop :=\n  ∃ k, a = 2 * k + 1\n#align odd Odd\n-/\n\n/- warning: odd_iff_exists_bit1 -> odd_iff_exists_bit1 is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, Iff (Odd.{u1} α _inst_1 a) (Exists.{succ u1} α (fun (b : α) => Eq.{succ u1} α a (bit1.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) b)))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, Iff (Odd.{u1} α _inst_1 a) (Exists.{succ u1} α (fun (b : α) => Eq.{succ u1} α a (bit1.{u1} α (Semiring.toOne.{u1} α _inst_1) (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) b)))\nCase conversion may be inaccurate. Consider using '#align odd_iff_exists_bit1 odd_iff_exists_bit1ₓ'. -/\ntheorem odd_iff_exists_bit1 {a : α} : Odd a ↔ ∃ b, a = bit1 b :=\n  exists_congr fun b => by\n    rw [two_mul]\n    rfl\n#align odd_iff_exists_bit1 odd_iff_exists_bit1\n\n/- warning: odd.exists_bit1 -> Odd.exists_bit1 is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, (Odd.{u1} α _inst_1 a) -> (Exists.{succ u1} α (fun (b : α) => Eq.{succ u1} α a (bit1.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) b)))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {a : α}, (Odd.{u1} α _inst_1 a) -> (Exists.{succ u1} α (fun (b : α) => Eq.{succ u1} α a (bit1.{u1} α (Semiring.toOne.{u1} α _inst_1) (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) b)))\nCase conversion may be inaccurate. Consider using '#align odd.exists_bit1 Odd.exists_bit1ₓ'. -/\nalias odd_iff_exists_bit1 ↔ Odd.exists_bit1 _\n#align odd.exists_bit1 Odd.exists_bit1\n\n/- warning: odd_bit1 -> odd_bit1 is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (a : α), Odd.{u1} α _inst_1 (bit1.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (a : α), Odd.{u1} α _inst_1 (bit1.{u1} α (Semiring.toOne.{u1} α _inst_1) (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) a)\nCase conversion may be inaccurate. Consider using '#align odd_bit1 odd_bit1ₓ'. -/\n@[simp]\ntheorem odd_bit1 (a : α) : Odd (bit1 a) :=\n  odd_iff_exists_bit1.2 ⟨a, rfl⟩\n#align odd_bit1 odd_bit1\n\n/- warning: range_two_mul_add_one -> range_two_mul_add_one is a dubious translation:\nlean 3 declaration is\n  forall (α : Type.{u1}) [_inst_3 : Semiring.{u1} α], Eq.{succ u1} (Set.{u1} α) (Set.range.{u1, succ u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3))))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3))))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))))))) x) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3))))))))) (setOf.{u1} α (fun (a : α) => Odd.{u1} α _inst_3 a))\nbut is expected to have type\n  forall (α : Type.{u1}) [_inst_3 : Semiring.{u1} α], Eq.{succ u1} (Set.{u1} α) (Set.range.{u1, succ u1} α α (fun (x : α) => HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3))))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_3)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_3) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) x) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (Semiring.toOne.{u1} α _inst_3))))) (setOf.{u1} α (fun (a : α) => Odd.{u1} α _inst_3 a))\nCase conversion may be inaccurate. Consider using '#align range_two_mul_add_one range_two_mul_add_oneₓ'. -/\n@[simp]\ntheorem range_two_mul_add_one (α : Type _) [Semiring α] :\n    (Set.range fun x : α => 2 * x + 1) = { a | Odd a } :=\n  by\n  ext x\n  simp [Odd, eq_comm]\n#align range_two_mul_add_one range_two_mul_add_one\n\n/- warning: even.add_odd -> Even.add_odd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (Odd.{u1} α _inst_1 n) -> (Odd.{u1} α _inst_1 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m) -> (Odd.{u1} α _inst_1 n) -> (Odd.{u1} α _inst_1 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nCase conversion may be inaccurate. Consider using '#align even.add_odd Even.add_oddₓ'. -/\ntheorem Even.add_odd : Even m → Odd n → Odd (m + n) :=\n  by\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩\n  exact ⟨m + n, by rw [mul_add, ← two_mul, add_assoc]⟩\n#align even.add_odd Even.add_odd\n\n/- warning: odd.add_even -> Odd.add_even is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Odd.{u1} α _inst_1 m) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n) -> (Odd.{u1} α _inst_1 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Odd.{u1} α _inst_1 m) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) n) -> (Odd.{u1} α _inst_1 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nCase conversion may be inaccurate. Consider using '#align odd.add_even Odd.add_evenₓ'. -/\ntheorem Odd.add_even (hm : Odd m) (hn : Even n) : Odd (m + n) :=\n  by\n  rw [add_comm]\n  exact hn.add_odd hm\n#align odd.add_even Odd.add_even\n\n/- warning: odd.add_odd -> Odd.add_odd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Odd.{u1} α _inst_1 m) -> (Odd.{u1} α _inst_1 n) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Odd.{u1} α _inst_1 m) -> (Odd.{u1} α _inst_1 n) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nCase conversion may be inaccurate. Consider using '#align odd.add_odd Odd.add_oddₓ'. -/\ntheorem Odd.add_odd : Odd m → Odd n → Even (m + n) :=\n  by\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩\n  refine' ⟨n + m + 1, _⟩\n  rw [two_mul, two_mul]\n  ac_rfl\n#align odd.add_odd Odd.add_odd\n\n#print odd_one /-\n@[simp]\ntheorem odd_one : Odd (1 : α) :=\n  ⟨0, (zero_add _).symm.trans (congr_arg (· + (1 : α)) (MulZeroClass.mul_zero _).symm)⟩\n#align odd_one odd_one\n-/\n\n/- warning: odd_two_mul_add_one -> odd_two_mul_add_one is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (m : α), Odd.{u1} α _inst_1 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))))))) m) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddCommMonoidWithOne.toAddMonoidWithOne.{u1} α (NonAssocSemiring.toAddCommMonoidWithOne.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] (m : α), Odd.{u1} α _inst_1 (HAdd.hAdd.{u1, u1, u1} α α α (instHAdd.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (Semiring.toNatCast.{u1} α _inst_1) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))) m) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (Semiring.toOne.{u1} α _inst_1))))\nCase conversion may be inaccurate. Consider using '#align odd_two_mul_add_one odd_two_mul_add_oneₓ'. -/\n@[simp]\ntheorem odd_two_mul_add_one (m : α) : Odd (2 * m + 1) :=\n  ⟨m, rfl⟩\n#align odd_two_mul_add_one odd_two_mul_add_one\n\n/- warning: odd.map -> Odd.map is a dubious translation:\nlean 3 declaration is\n  forall {F : Type.{u1}} {α : Type.{u2}} {β : Type.{u3}} [_inst_1 : Semiring.{u2} α] [_inst_2 : Semiring.{u3} β] {m : α} [_inst_3 : RingHomClass.{u1, u2, u3} F α β (Semiring.toNonAssocSemiring.{u2} α _inst_1) (Semiring.toNonAssocSemiring.{u3} β _inst_2)] (f : F), (Odd.{u2} α _inst_1 m) -> (Odd.{u3} β _inst_2 (coeFn.{succ u1, max (succ u2) (succ u3)} F (fun (_x : F) => α -> β) (FunLike.hasCoeToFun.{succ u1, succ u2, succ u3} F α (fun (_x : α) => β) (MulHomClass.toFunLike.{u1, u2, u3} F α β (Distrib.toHasMul.{u2} α (NonUnitalNonAssocSemiring.toDistrib.{u2} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} α (Semiring.toNonAssocSemiring.{u2} α _inst_1)))) (Distrib.toHasMul.{u3} β (NonUnitalNonAssocSemiring.toDistrib.{u3} β (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} β (Semiring.toNonAssocSemiring.{u3} β _inst_2)))) (NonUnitalRingHomClass.toMulHomClass.{u1, u2, u3} F α β (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} α (Semiring.toNonAssocSemiring.{u2} α _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u3} β (Semiring.toNonAssocSemiring.{u3} β _inst_2)) (RingHomClass.toNonUnitalRingHomClass.{u1, u2, u3} F α β (Semiring.toNonAssocSemiring.{u2} α _inst_1) (Semiring.toNonAssocSemiring.{u3} β _inst_2) _inst_3)))) f m))\nbut is expected to have type\n  forall {F : Type.{u3}} {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : Semiring.{u2} α] [_inst_2 : Semiring.{u1} β] {m : α} [_inst_3 : RingHomClass.{u3, u2, u1} F α β (Semiring.toNonAssocSemiring.{u2} α _inst_1) (Semiring.toNonAssocSemiring.{u1} β _inst_2)] (f : F), (Odd.{u2} α _inst_1 m) -> (Odd.{u1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : α) => β) m) _inst_2 (FunLike.coe.{succ u3, succ u2, succ u1} F α (fun (_x : α) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : α) => β) _x) (MulHomClass.toFunLike.{u3, u2, u1} F α β (NonUnitalNonAssocSemiring.toMul.{u2} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} α (Semiring.toNonAssocSemiring.{u2} α _inst_1))) (NonUnitalNonAssocSemiring.toMul.{u1} β (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} β (Semiring.toNonAssocSemiring.{u1} β _inst_2))) (NonUnitalRingHomClass.toMulHomClass.{u3, u2, u1} F α β (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u2} α (Semiring.toNonAssocSemiring.{u2} α _inst_1)) (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} β (Semiring.toNonAssocSemiring.{u1} β _inst_2)) (RingHomClass.toNonUnitalRingHomClass.{u3, u2, u1} F α β (Semiring.toNonAssocSemiring.{u2} α _inst_1) (Semiring.toNonAssocSemiring.{u1} β _inst_2) _inst_3))) f m))\nCase conversion may be inaccurate. Consider using '#align odd.map Odd.mapₓ'. -/\ntheorem Odd.map [RingHomClass F α β] (f : F) : Odd m → Odd (f m) :=\n  by\n  rintro ⟨m, rfl⟩\n  exact ⟨f m, by simp [two_mul]⟩\n#align odd.map Odd.map\n\n/- warning: odd.mul -> Odd.mul is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Odd.{u1} α _inst_1 m) -> (Odd.{u1} α _inst_1 n) -> (Odd.{u1} α _inst_1 (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (Distrib.toHasMul.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1))))) m n))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Semiring.{u1} α] {m : α} {n : α}, (Odd.{u1} α _inst_1 m) -> (Odd.{u1} α _inst_1 n) -> (Odd.{u1} α _inst_1 (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α (NonUnitalNonAssocSemiring.toMul.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α _inst_1)))) m n))\nCase conversion may be inaccurate. Consider using '#align odd.mul Odd.mulₓ'. -/\n@[simp]\ntheorem Odd.mul : Odd m → Odd n → Odd (m * n) :=\n  by\n  rintro ⟨m, rfl⟩ ⟨n, rfl⟩\n  refine' ⟨2 * m * n + n + m, _⟩\n  rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc,\n    ← Nat.cast_two, ← Nat.cast_comm]\n#align odd.mul Odd.mul\n\n#print Odd.pow /-\ntheorem Odd.pow (hm : Odd m) : ∀ {a : ℕ}, Odd (m ^ a)\n  | 0 => by\n    rw [pow_zero]\n    exact odd_one\n  | a + 1 => by\n    rw [pow_succ]\n    exact hm.mul Odd.pow\n#align odd.pow Odd.pow\n-/\n\nend WithOdd\n\nend Semiring\n\nsection Monoid\n\nvariable [Monoid α] [HasDistribNeg α] {a : α} {n : ℕ}\n\n/- warning: odd.neg_pow -> Odd.neg_pow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))] {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (forall (a : α), Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) a) n) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n)))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))] {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (forall (a : α), Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) a) n) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) a n)))\nCase conversion may be inaccurate. Consider using '#align odd.neg_pow Odd.neg_powₓ'. -/\ntheorem Odd.neg_pow : Odd n → ∀ a : α, (-a) ^ n = -a ^ n :=\n  by\n  rintro ⟨c, rfl⟩ a\n  simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg]\n#align odd.neg_pow Odd.neg_pow\n\n/- warning: odd.neg_one_pow -> Odd.neg_one_pow is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))] {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)))))) n) (Neg.neg.{u1} α (InvolutiveNeg.toHasNeg.{u1} α (HasDistribNeg.toHasInvolutiveNeg.{u1} α (MulOneClass.toHasMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (MulOneClass.toHasOne.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Monoid.{u1} α] [_inst_2 : HasDistribNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1))] {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Eq.{succ u1} α (HPow.hPow.{u1, 0, u1} α Nat α (instHPow.{u1, 0} α Nat (Monoid.Pow.{u1} α _inst_1)) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (Monoid.toOne.{u1} α _inst_1)))) n) (Neg.neg.{u1} α (InvolutiveNeg.toNeg.{u1} α (HasDistribNeg.toInvolutiveNeg.{u1} α (MulOneClass.toMul.{u1} α (Monoid.toMulOneClass.{u1} α _inst_1)) _inst_2)) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (Monoid.toOne.{u1} α _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align odd.neg_one_pow Odd.neg_one_powₓ'. -/\ntheorem Odd.neg_one_pow (h : Odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow]\n#align odd.neg_one_pow Odd.neg_one_pow\n\nend Monoid\n\nsection CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring α]\n\n/- warning: odd.pos -> Odd.pos is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : CanonicallyOrderedCommSemiring.{u1} α] [_inst_2 : Nontrivial.{u1} α] {n : α}, (Odd.{u1} α (OrderedSemiring.toSemiring.{u1} α (OrderedCommSemiring.toOrderedSemiring.{u1} α (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{u1} α _inst_1))) n) -> (LT.lt.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedAddCommMonoid.toPartialOrder.{u1} α (OrderedSemiring.toOrderedAddCommMonoid.{u1} α (OrderedCommSemiring.toOrderedSemiring.{u1} α (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{u1} α _inst_1)))))) (OfNat.ofNat.{u1} α 0 (OfNat.mk.{u1} α 0 (Zero.zero.{u1} α (MulZeroClass.toHasZero.{u1} α (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} α (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} α (Semiring.toNonAssocSemiring.{u1} α (OrderedSemiring.toSemiring.{u1} α (OrderedCommSemiring.toOrderedSemiring.{u1} α (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{u1} α _inst_1)))))))))) n)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : CanonicallyOrderedCommSemiring.{u1} α] [_inst_2 : Nontrivial.{u1} α] {n : α}, (Odd.{u1} α (OrderedSemiring.toSemiring.{u1} α (OrderedCommSemiring.toOrderedSemiring.{u1} α (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{u1} α _inst_1))) n) -> (LT.lt.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (OrderedSemiring.toPartialOrder.{u1} α (OrderedCommSemiring.toOrderedSemiring.{u1} α (CanonicallyOrderedCommSemiring.toOrderedCommSemiring.{u1} α _inst_1))))) (OfNat.ofNat.{u1} α 0 (Zero.toOfNat0.{u1} α (CommMonoidWithZero.toZero.{u1} α (CommSemiring.toCommMonoidWithZero.{u1} α (CanonicallyOrderedCommSemiring.toCommSemiring.{u1} α _inst_1))))) n)\nCase conversion may be inaccurate. Consider using '#align odd.pos Odd.posₓ'. -/\n-- this holds more generally in a `canonically_ordered_add_monoid` if we refactor `odd` to use\n-- either `2 • t` or `t + t` instead of `2 * t`.\ntheorem Odd.pos [Nontrivial α] {n : α} (hn : Odd n) : 0 < n :=\n  by\n  obtain ⟨k, rfl⟩ := hn\n  rw [pos_iff_ne_zero, Ne.def, add_eq_zero_iff, not_and']\n  exact fun h => (one_ne_zero h).elim\n#align odd.pos Odd.pos\n\nend CanonicallyOrderedCommSemiring\n\nsection Ring\n\nvariable [Ring α] {a b : α} {n : ℕ}\n\n/- warning: even_neg_two -> even_neg_two is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α], Even.{u1} α (Distrib.toHasAdd.{u1} α (Ring.toDistrib.{u1} α _inst_1)) (Neg.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1))))) (OfNat.ofNat.{u1} α 2 (OfNat.mk.{u1} α 2 (bit0.{u1} α (Distrib.toHasAdd.{u1} α (Ring.toDistrib.{u1} α _inst_1)) (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddGroupWithOne.toAddMonoidWithOne.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1)))))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α], Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} α (NonAssocRing.toNonUnitalNonAssocRing.{u1} α (Ring.toNonAssocRing.{u1} α _inst_1))))) (Neg.neg.{u1} α (Ring.toNeg.{u1} α _inst_1) (OfNat.ofNat.{u1} α 2 (instOfNat.{u1} α 2 (NonAssocRing.toNatCast.{u1} α (Ring.toNonAssocRing.{u1} α _inst_1)) (instAtLeastTwoHAddNatInstHAddInstAddNatOfNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))))))\nCase conversion may be inaccurate. Consider using '#align even_neg_two even_neg_twoₓ'. -/\n@[simp]\ntheorem even_neg_two : Even (-2 : α) := by simp only [even_neg, even_two]\n#align even_neg_two even_neg_two\n\n/- warning: odd.neg -> Odd.neg is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α}, (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Neg.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1))))) a))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α}, (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Neg.neg.{u1} α (Ring.toNeg.{u1} α _inst_1) a))\nCase conversion may be inaccurate. Consider using '#align odd.neg Odd.negₓ'. -/\ntheorem Odd.neg (hp : Odd a) : Odd (-a) :=\n  by\n  obtain ⟨k, hk⟩ := hp\n  use -(k + 1)\n  rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add, neg_add_cancel_right, ←\n    neg_add, hk]\n#align odd.neg Odd.neg\n\n/- warning: odd_neg -> odd_neg is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α}, Iff (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Neg.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1))))) a)) (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α}, Iff (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Neg.neg.{u1} α (Ring.toNeg.{u1} α _inst_1) a)) (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a)\nCase conversion may be inaccurate. Consider using '#align odd_neg odd_negₓ'. -/\n@[simp]\ntheorem odd_neg : Odd (-a) ↔ Odd a :=\n  ⟨fun h => neg_neg a ▸ h.neg, Odd.neg⟩\n#align odd_neg odd_neg\n\n/- warning: odd_neg_one -> odd_neg_one is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α], Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Neg.neg.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1))))) (OfNat.ofNat.{u1} α 1 (OfNat.mk.{u1} α 1 (One.one.{u1} α (AddMonoidWithOne.toOne.{u1} α (AddGroupWithOne.toAddMonoidWithOne.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1))))))))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α], Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Neg.neg.{u1} α (Ring.toNeg.{u1} α _inst_1) (OfNat.ofNat.{u1} α 1 (One.toOfNat1.{u1} α (NonAssocRing.toOne.{u1} α (Ring.toNonAssocRing.{u1} α _inst_1)))))\nCase conversion may be inaccurate. Consider using '#align odd_neg_one odd_neg_oneₓ'. -/\n@[simp]\ntheorem odd_neg_one : Odd (-1 : α) := by simp\n#align odd_neg_one odd_neg_one\n\n/- warning: odd.sub_even -> Odd.sub_even is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} {b : α}, (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (Ring.toDistrib.{u1} α _inst_1)) b) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1)))))) a b))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} {b : α}, (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} α (NonAssocRing.toNonUnitalNonAssocRing.{u1} α (Ring.toNonAssocRing.{u1} α _inst_1))))) b) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (Ring.toSub.{u1} α _inst_1)) a b))\nCase conversion may be inaccurate. Consider using '#align odd.sub_even Odd.sub_evenₓ'. -/\ntheorem Odd.sub_even (ha : Odd a) (hb : Even b) : Odd (a - b) :=\n  by\n  rw [sub_eq_add_neg]\n  exact ha.add_even hb.neg\n#align odd.sub_even Odd.sub_even\n\n/- warning: even.sub_odd -> Even.sub_odd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} {b : α}, (Even.{u1} α (Distrib.toHasAdd.{u1} α (Ring.toDistrib.{u1} α _inst_1)) a) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) b) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1)))))) a b))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} {b : α}, (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} α (NonAssocRing.toNonUnitalNonAssocRing.{u1} α (Ring.toNonAssocRing.{u1} α _inst_1))))) a) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) b) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (Ring.toSub.{u1} α _inst_1)) a b))\nCase conversion may be inaccurate. Consider using '#align even.sub_odd Even.sub_oddₓ'. -/\ntheorem Even.sub_odd (ha : Even a) (hb : Odd b) : Odd (a - b) :=\n  by\n  rw [sub_eq_add_neg]\n  exact ha.add_odd hb.neg\n#align even.sub_odd Even.sub_odd\n\n/- warning: odd.sub_odd -> Odd.sub_odd is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} {b : α}, (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) b) -> (Even.{u1} α (Distrib.toHasAdd.{u1} α (Ring.toDistrib.{u1} α _inst_1)) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (SubNegMonoid.toHasSub.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1)))))) a b))\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} {b : α}, (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a) -> (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) b) -> (Even.{u1} α (Distrib.toAdd.{u1} α (NonUnitalNonAssocSemiring.toDistrib.{u1} α (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} α (NonAssocRing.toNonUnitalNonAssocRing.{u1} α (Ring.toNonAssocRing.{u1} α _inst_1))))) (HSub.hSub.{u1, u1, u1} α α α (instHSub.{u1} α (Ring.toSub.{u1} α _inst_1)) a b))\nCase conversion may be inaccurate. Consider using '#align odd.sub_odd Odd.sub_oddₓ'. -/\ntheorem Odd.sub_odd (ha : Odd a) (hb : Odd b) : Even (a - b) :=\n  by\n  rw [sub_eq_add_neg]\n  exact ha.add_odd hb.neg\n#align odd.sub_odd Odd.sub_odd\n\n/- warning: odd_abs -> odd_abs is a dubious translation:\nlean 3 declaration is\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} [_inst_2 : LinearOrder.{u1} α], Iff (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Abs.abs.{u1} α (Neg.toHasAbs.{u1} α (SubNegMonoid.toHasNeg.{u1} α (AddGroup.toSubNegMonoid.{u1} α (AddGroupWithOne.toAddGroup.{u1} α (AddCommGroupWithOne.toAddGroupWithOne.{u1} α (Ring.toAddCommGroupWithOne.{u1} α _inst_1))))) (SemilatticeSup.toHasSup.{u1} α (Lattice.toSemilatticeSup.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a)) (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a)\nbut is expected to have type\n  forall {α : Type.{u1}} [_inst_1 : Ring.{u1} α] {a : α} [_inst_2 : LinearOrder.{u1} α], Iff (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) (Abs.abs.{u1} α (Neg.toHasAbs.{u1} α (Ring.toNeg.{u1} α _inst_1) (SemilatticeSup.toSup.{u1} α (Lattice.toSemilatticeSup.{u1} α (DistribLattice.toLattice.{u1} α (instDistribLattice.{u1} α _inst_2))))) a)) (Odd.{u1} α (Ring.toSemiring.{u1} α _inst_1) a)\nCase conversion may be inaccurate. Consider using '#align odd_abs odd_absₓ'. -/\ntheorem odd_abs [LinearOrder α] : Odd (abs a) ↔ Odd a := by\n  cases' abs_choice a with h h <;> simp only [h, odd_neg]\n#align odd_abs odd_abs\n\nend Ring\n\nsection powers\n\nvariable [LinearOrderedRing R] {a : R} {n : ℕ}\n\n/- warning: even.pow_nonneg -> Even.pow_nonneg is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {n : Nat}, (Even.{0} Nat Nat.hasAdd n) -> (forall (a : R), LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {n : Nat}, (Even.{0} Nat instAddNat n) -> (forall (a : R), LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n))\nCase conversion may be inaccurate. Consider using '#align even.pow_nonneg Even.pow_nonnegₓ'. -/\ntheorem Even.pow_nonneg (hn : Even n) (a : R) : 0 ≤ a ^ n := by\n  cases' hn with k hk <;> simpa only [hk, two_mul] using pow_bit0_nonneg a k\n#align even.pow_nonneg Even.pow_nonneg\n\n/- warning: even.pow_pos -> Even.pow_pos is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Even.{0} Nat Nat.hasAdd n) -> (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 (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))) -> (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Even.{0} Nat instAddNat n) -> (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))) -> (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n))\nCase conversion may be inaccurate. Consider using '#align even.pow_pos Even.pow_posₓ'. -/\ntheorem Even.pow_pos (hn : Even n) (ha : a ≠ 0) : 0 < a ^ n := by\n  cases' hn with k hk <;> simpa only [hk, two_mul] using pow_bit0_pos ha k\n#align even.pow_pos Even.pow_pos\n\n/- warning: odd.pow_nonpos -> Odd.pow_nonpos is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))) -> (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n) (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))) -> (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))))\nCase conversion may be inaccurate. Consider using '#align odd.pow_nonpos Odd.pow_nonposₓ'. -/\ntheorem Odd.pow_nonpos (hn : Odd n) (ha : a ≤ 0) : a ^ n ≤ 0 := by\n  cases' hn with k hk <;> simpa only [hk, two_mul] using pow_bit1_nonpos_iff.mpr ha\n#align odd.pow_nonpos Odd.pow_nonpos\n\n/- warning: odd.pow_neg -> Odd.pow_neg is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))) -> (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n) (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))) -> (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))))\nCase conversion may be inaccurate. Consider using '#align odd.pow_neg Odd.pow_negₓ'. -/\ntheorem Odd.pow_neg (hn : Odd n) (ha : a < 0) : a ^ n < 0 := by\n  cases' hn with k hk <;> simpa only [hk, two_mul] using pow_bit1_neg_iff.mpr ha\n#align odd.pow_neg Odd.pow_neg\n\n/- warning: odd.pow_nonneg_iff -> Odd.pow_nonneg_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n)) (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) a))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n)) (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a))\nCase conversion may be inaccurate. Consider using '#align odd.pow_nonneg_iff Odd.pow_nonneg_iffₓ'. -/\ntheorem Odd.pow_nonneg_iff (hn : Odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=\n  ⟨fun h => le_of_not_lt fun ha => h.not_lt <| hn.pow_neg ha, fun ha => pow_nonneg ha n⟩\n#align odd.pow_nonneg_iff Odd.pow_nonneg_iff\n\n/- warning: odd.pow_nonpos_iff -> Odd.pow_nonpos_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n) (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))) (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))) (LE.le.{u1} R (Preorder.toLE.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))))\nCase conversion may be inaccurate. Consider using '#align odd.pow_nonpos_iff Odd.pow_nonpos_iffₓ'. -/\ntheorem Odd.pow_nonpos_iff (hn : Odd n) : a ^ n ≤ 0 ↔ a ≤ 0 :=\n  ⟨fun h => le_of_not_lt fun ha => h.not_lt <| pow_pos ha _, hn.pow_nonpos⟩\n#align odd.pow_nonpos_iff Odd.pow_nonpos_iff\n\n/- warning: odd.pow_pos_iff -> Odd.pow_pos_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n)) (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) a))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n)) (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a))\nCase conversion may be inaccurate. Consider using '#align odd.pow_pos_iff Odd.pow_pos_iffₓ'. -/\ntheorem Odd.pow_pos_iff (hn : Odd n) : 0 < a ^ n ↔ 0 < a :=\n  ⟨fun h => lt_of_not_le fun ha => h.not_le <| hn.pow_nonpos ha, fun ha => pow_pos ha n⟩\n#align odd.pow_pos_iff Odd.pow_pos_iff\n\n/- warning: odd.pow_neg_iff -> Odd.pow_neg_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n) (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))) (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a (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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (Iff (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))) (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))))\nCase conversion may be inaccurate. Consider using '#align odd.pow_neg_iff Odd.pow_neg_iffₓ'. -/\ntheorem Odd.pow_neg_iff (hn : Odd n) : a ^ n < 0 ↔ a < 0 :=\n  ⟨fun h => lt_of_not_le fun ha => h.not_le <| pow_nonneg ha _, hn.pow_neg⟩\n#align odd.pow_neg_iff Odd.pow_neg_iff\n\n/- warning: even.pow_pos_iff -> Even.pow_pos_iff is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Even.{0} Nat Nat.hasAdd n) -> (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) -> (Iff (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{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 (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))))))))) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n)) (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 (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))))))))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {a : R} {n : Nat}, (Even.{0} Nat instAddNat n) -> (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) -> (Iff (LT.lt.{u1} R (Preorder.toLT.{u1} R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n)) (Ne.{succ u1} R a (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1)))))))))\nCase conversion may be inaccurate. Consider using '#align even.pow_pos_iff Even.pow_pos_iffₓ'. -/\ntheorem Even.pow_pos_iff (hn : Even n) (h₀ : 0 < n) : 0 < a ^ n ↔ a ≠ 0 :=\n  ⟨fun h ha => by\n    rw [ha, zero_pow h₀] at h\n    exact lt_irrefl 0 h, hn.pow_pos⟩\n#align even.pow_pos_iff Even.pow_pos_iff\n\n/- warning: even.pow_abs -> Even.pow_abs is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {p : Nat}, (Even.{0} Nat Nat.hasAdd p) -> (forall (a : R), Eq.{succ u1} R (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) (Abs.abs.{u1} R (Neg.toHasAbs.{u1} R (SubNegMonoid.toHasNeg.{u1} R (AddGroup.toSubNegMonoid.{u1} R (AddGroupWithOne.toAddGroup.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))) (SemilatticeSup.toHasSup.{u1} R (Lattice.toSemilatticeSup.{u1} R (LinearOrder.toLattice.{u1} R (LinearOrderedRing.toLinearOrder.{u1} R _inst_1))))) a) p) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {p : Nat}, (Even.{0} Nat instAddNat p) -> (forall (a : R), Eq.{succ u1} R (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (Abs.abs.{u1} R (Neg.toHasAbs.{u1} R (Ring.toNeg.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))) (SemilatticeSup.toSup.{u1} R (Lattice.toSemilatticeSup.{u1} R (DistribLattice.toLattice.{u1} R (instDistribLattice.{u1} R (LinearOrderedRing.toLinearOrder.{u1} R _inst_1)))))) a) 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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a p))\nCase conversion may be inaccurate. Consider using '#align even.pow_abs Even.pow_absₓ'. -/\ntheorem Even.pow_abs {p : ℕ} (hp : Even p) (a : R) : |a| ^ p = a ^ p :=\n  by\n  rw [← abs_pow, abs_eq_self]\n  exact hp.pow_nonneg _\n#align even.pow_abs Even.pow_abs\n\n/- warning: pow_bit0_abs -> pow_bit0_abs is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] (a : R) (p : Nat), Eq.{succ u1} R (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) (Abs.abs.{u1} R (Neg.toHasAbs.{u1} R (SubNegMonoid.toHasNeg.{u1} R (AddGroup.toSubNegMonoid.{u1} R (AddGroupWithOne.toAddGroup.{u1} R (AddCommGroupWithOne.toAddGroupWithOne.{u1} R (Ring.toAddCommGroupWithOne.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))))) (SemilatticeSup.toHasSup.{u1} R (Lattice.toSemilatticeSup.{u1} R (LinearOrder.toLattice.{u1} R (LinearOrderedRing.toLinearOrder.{u1} R _inst_1))))) a) (bit0.{0} Nat Nat.hasAdd p)) (HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a (bit0.{0} Nat Nat.hasAdd p))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] (a : R) (p : Nat), Eq.{succ u1} R (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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) (Abs.abs.{u1} R (Neg.toHasAbs.{u1} R (Ring.toNeg.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))) (SemilatticeSup.toSup.{u1} R (Lattice.toSemilatticeSup.{u1} R (DistribLattice.toLattice.{u1} R (instDistribLattice.{u1} R (LinearOrderedRing.toLinearOrder.{u1} R _inst_1)))))) a) (bit0.{0} Nat instAddNat 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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a (bit0.{0} Nat instAddNat p))\nCase conversion may be inaccurate. Consider using '#align pow_bit0_abs pow_bit0_absₓ'. -/\n@[simp]\ntheorem pow_bit0_abs (a : R) (p : ℕ) : |a| ^ bit0 p = a ^ bit0 p :=\n  (even_bit0 _).pow_abs _\n#align pow_bit0_abs pow_bit0_abs\n\n/- warning: odd.strict_mono_pow -> Odd.strictMono_pow is a dubious translation:\nlean 3 declaration is\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (StrictMono.{u1, u1} R R (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (PartialOrder.toPreorder.{u1} R (OrderedAddCommGroup.toPartialOrder.{u1} R (StrictOrderedRing.toOrderedAddCommGroup.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1)))) (fun (a : R) => HPow.hPow.{u1, 0, u1} R Nat R (instHPow.{u1, 0} R Nat (Monoid.Pow.{u1} R (Ring.toMonoid.{u1} R (StrictOrderedRing.toRing.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))))) a n))\nbut is expected to have type\n  forall {R : Type.{u1}} [_inst_1 : LinearOrderedRing.{u1} R] {n : Nat}, (Odd.{0} Nat Nat.semiring n) -> (StrictMono.{u1, u1} R R (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))) (PartialOrder.toPreorder.{u1} R (StrictOrderedRing.toPartialOrder.{u1} R (LinearOrderedRing.toStrictOrderedRing.{u1} R _inst_1))) (fun (a : R) => 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 (StrictOrderedSemiring.toSemiring.{u1} R (LinearOrderedSemiring.toStrictOrderedSemiring.{u1} R (LinearOrderedRing.toLinearOrderedSemiring.{u1} R _inst_1))))))) a n))\nCase conversion may be inaccurate. Consider using '#align odd.strict_mono_pow Odd.strictMono_powₓ'. -/\ntheorem Odd.strictMono_pow (hn : Odd n) : StrictMono fun a : R => a ^ n := by\n  cases' hn with k hk <;> simpa only [hk, two_mul] using strictMono_pow_bit1 _\n#align odd.strict_mono_pow Odd.strictMono_pow\n\nend powers\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/Parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220294, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.7719169292637836}}
{"text": "import data.real.basic\n\n/-\nOne of the earliest kind of proofs one encounters while learning mathematics is proving by\na calculation. It may not sound like a proof, but this is actually using lemmas expressing \nproperties of operations on numbers. It also uses the fundamental property of equality: if two\nmathematical objects A and B are equal then, in any statement involving A, one can replace A \nby B. This operation is called rewriting, and the Lean \"tactic\" for this is `rw`.\n\nIn the following exercises, we will use the following two lemmas:\n  mul_assoc a b c : a * b * c = a * (b * c)\n  mul_comm a b : a*b = b*a\n\nHence the command \n  rw mul_assoc a b c,\nwill replace a*b*c by a*(b*c) in the current goal.\n\nIn order to replace backward, we use\n  rw ← mul_assoc a b c,\nreplacing a*(b*c) by a*b*c in the current goal.\n\nOf course we don't want to constantly invoke those lemmas, and we will eventually introduce\nmore powerful solutions.\n-/\n\n-- Uncomment the following line if you want to see parentheses around subexpressions.\n-- set_option pp.parens true\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 0001\nexample (a b c : ℝ) : (c * b) * a = b * (a * c) :=\nbegin\n  rw mul_comm,\n  rw ← mul_assoc,\n  rw mul_comm,\n  -- `finish,` -- slow\n  -- `ring,` -- Finish him!\nend\n\n-- 0002\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  rw ← mul_assoc,\n  rw ← mul_assoc,\n  rw mul_comm a b,\nend\n\n/-\nNow let's return to the preceding example to experiment with what happens\nif we don't give arguments to mul_assoc or mul_comm.\nFor instance, you can start the next proof with\n  rw ← mul_assoc,\nTry to figure out what happens.\n-/\n\n-- 0003\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  sorry -- already did that\nend\n\n/-\nWe can also perform rewriting in an assumption of the local context, using for instance\n  rw mul_comm a b at hyp,\nin order to replace a*b by b*a in assumption hyp.\n\nThe next example will use a third lemma:\n  two_mul a : 2*a = a + a\n\nAlso we use the `exact` tactic, which allows to provide a direct proof term.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm d a at hyp,\n  rw ← two_mul (a*d) at hyp,\n  rw ← mul_assoc 2 a d at hyp,\n  exact hyp, -- Our assumption hyp is now exactly what we have to prove\nend\n\n/-\nAnd the next one can use:\n  sub_self x : x - x = 0\n-/\n\n-- 0004\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  rw hyp' at hyp,\n  rw mul_comm at hyp,\n  calc\n    c   = a*b - a*b : hyp\n    ... = 0 : sub_self (a*b),\nend\n\n/-\nWhat is written in the two preceding example is very far away from what we would write on\npaper. Let's now see how to get a more natural layout.\nInside each pair of curly braces below, the goal is to prove equality with the preceding line.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b : by { rw hyp }\n  ... = d*a + a*d  : by { rw hyp' }\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\n/-\nLet's note there is no comma at the end of each line of calculation. `calc` is really one\ncommand, and the comma comes only after it's fully done.\n\nFrom a practical point of view, when writing such a proof, it is convenient to:\n* pause the tactic state view update in VScode by clicking the Pause icon button\n  in the top right corner of the Lean Goal buffer\n* write the full calculation, ending each line with \": by {}\"\n* resume tactic state update by clicking the Play icon button and fill in proofs between \n  curly braces.\n\nLet's return to the other example using this method. \n-/\n\n-- 0005\nexample (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=\nbegin\n  calc\n  c   = b*a - d : hyp\n  ... = b*a - a*b : by { rw hyp' }\n  -- ... = a*b - a*b : by { rw mul_comm }\n  -- ... = 0 : sub_self (a*b), -- Tada!\n  ... = 0 : by { rw mul_comm, exact sub_self (a*b)},\nend\n\n/-\nThe preceding proofs have exhausted our supply of \"mul_comm\" patience. Now it's time\nto get the computer to work harder. The `ring` tactic will prove any goal that follows by\napplying only the axioms of commutative (semi-)rings, in particular commutativity and \nassociativity of addition and multiplication, as well as distributivity.\n\nWe also note that curly braces are not necessary when we write a single tactic proof, so \nlet's get rid of them.\n-/\n\nexample (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=\nbegin\n  calc c = d*a + b   : by rw hyp\n     ... = d*a + a*d : by rw hyp'\n     ... = 2*a*d     : by ring,\nend\n\n/-\nOf course we can use `ring` outside of `calc`. Let's do the next one in one line.\n-/\n\n-- 0006\nexample (a b c : ℝ) : a * (b * c) = b * (a * c) :=\nbegin\n  by ring,\nend\n\n/-\nThis is too much fun. Let's do it again.\n-/\n\n-- 0007\nexample (a b : ℝ) : (a + b) + a = 2*a + b := by ring\n\n/-\nMaybe this is cheating. Let's try to do the next computation without ring.\nWe could use:\npow_two x : x^2 = x*x\nmul_sub a b c : a*(b-c) = a*b - a*c\nadd_mul a b c : (a+b)*c = a*c + b*c\nadd_sub a b c : a + (b - c) = (a + b) - c\nsub_sub a b c : a - b - c = a - (b + c)\nadd_zero a : a + 0 = a\n-/\n\n-- 0008\nexample (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 :=\nbegin\n  calc\n  (a + b)*(a - b) = (a + b)*a - (a + b)*b : by rw mul_sub\n  ...             = a*a + b*a - a*b - b*b : by { repeat {rw add_mul}, rw sub_sub }\n  ...             = a^2 + b*a - a*b - b^2 : by { repeat {rw pow_two }}\n  ...             = a^2 - b^2 : by { rw mul_comm, rw ← add_sub, \n  rw sub_self, rw add_zero },\nend\n\n/- Let's stick to ring in the end. -/\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/01_equality_rewriting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7719169221517641}}
{"text": "theorem absorb_right_or: ∀(P : Prop), P ∨ true :=\nbegin\n  assume P,\n  exact or.inr true.intro\nend\n\ntheorem absorb_right_or': ∀(P : Prop), P ∨ true :=\n  λ(P), or.inr true.intro\n\ntheorem absorb_left_or: ∀(P : Prop), true ∨ P :=\nbegin\n  assume P,\n  exact or.inl true.intro\nend\n\ntheorem wet'' : \n  ∀(R S W: Prop), \n    (R ∨ S) → (R → W) → (S → W) → W :=\nbegin\n  assume R S W,\n  assume pf_R_or_S,\n  assume pf_R_to_W,\n  assume pf_S_to_W,\n  exact or.elim pf_R_or_S pf_R_to_W pf_S_to_W,\nend\n\ntheorem wet''' : \n  ∀(R S W: Prop), \n    (R ∨ S) → (R → W) → (S → W) → W :=\nbegin\n  assume R S W,\n  assume pf_R_or_S,\n  assume pf_R_to_W,\n  assume pf_S_to_W,\n  cases pf_R_or_S with pf_R pf_S,\n    -- case R\n    exact pf_R_to_W pf_R,\n    -- case S\n    exact pf_S_to_W pf_S,\nend\n\ntheorem id_right_or: ∀(P: Prop), P ∨ false ↔ P :=\nbegin\n  assume P,\n  split,\n    -- P ∨ false → P\n    assume pf_P_or_false,\n    cases pf_P_or_false with pf_P pf_false,\n      -- pf_P\n      assumption,\n      -- pf_false\n      exact false.elim pf_false,\n    -- P → P ∨ false\n    assume pf_P,\n    exact or.inl pf_P,\nend\n\ntheorem id_left_or: ∀(P: Prop), false ∨ P ↔ P :=\nbegin\n  assume P,\n  split,\n    -- false ∨ P → P\n    assume pf_false_or_P,\n    cases pf_false_or_P with pf_false pf_P,\n      -- pf_false\n      exact false.elim pf_false,\n      -- pf_P\n      assumption,\n    -- P → false ∨ P\n    assume pf_P,\n    exact or.intro_right false pf_P,\nend\n\ntheorem disjunctiveSyllogism:\n  ∀(P Q: Prop), P ∨ Q → ¬Q → P :=\nbegin\n  assume P Q,\n  assume pfPOrQ,\n  assume pfNotQ,\n  cases pfPOrQ with pfP pfQ, -- now by cases\n    assumption, -- case where p is true,\n    exact false.elim (pfNotQ pfQ), -- or q true\nend\n\naxiom em: ∀(P: Prop), P ∨ ¬P\n\ntheorem DeMorganOne: ∀(P Q: Prop), ¬(P ∨ Q) ↔ ¬P ∧ ¬Q :=\nbegin\n  assume P Q,\n  split,\n    -- ¬(P ∨ Q) → ¬P ∧ ¬Q\n    assume pf_not__P_or_Q,\n    split,\n      -- prove ¬P\n      cases (em P) with pf_P pf_not_P,\n        -- pf_P\n        have pf_P_or_Q: P ∨ Q := or.inl pf_P,\n        exact false.elim (pf_not__P_or_Q pf_P_or_Q),\n        -- pf_not_P\n        assumption,\n      -- prove ¬Q\n      cases (em Q) with pf_Q pf_not_Q,\n        -- pf_Q\n        have pf_P_or_Q: P ∨ Q := or.inr pf_Q,\n        exact false.elim (pf_not__P_or_Q pf_P_or_Q),\n        -- pf_not_Q,\n        assumption,\n    -- ¬P ∧ ¬Q → ¬(P ∨ Q)\n    assume pf_not_P_and_not_Q,\n    assume pf_P_or_Q,\n    cases pf_P_or_Q with pf_P pf_Q,\n      -- pf_P\n      have pf_not_P: ¬P := pf_not_P_and_not_Q.left,\n      exact pf_not_P pf_P,\n      -- pf_Q\n      have pf_not_Q: ¬Q := pf_not_P_and_not_Q.right,\n      exact pf_not_Q pf_Q,\nend\n\ntheorem DeMorganTwo: ∀(P Q: Prop), ¬(P ∧ Q) ↔ ¬P ∨ ¬Q :=\nbegin\n  assume P Q,\n  split,\n    -- ¬(P ∧ Q) → ¬P ∨ ¬Q\n    assume pf_not__P_and_Q,\n    cases (em P) with pf_P pf_not_P,\n      -- pf_P\n      cases (em Q) with pf_Q pf_not_Q,\n        -- pf_Q\n        have pf_P_and_Q := and.intro pf_P pf_Q,\n        exact false.elim (pf_not__P_and_Q pf_P_and_Q),\n        -- pf_not_Q\n        exact or.inr pf_not_Q,\n      -- pf_not_P\n      exact or.inl pf_not_P,\n    -- ¬P ∨ ¬Q → ¬(P ∧ Q)\n    assume pf_not_P_or_not_Q,\n    assume pf_P_and_Q,\n    cases pf_not_P_or_not_Q with pf_not_P pf_not_Q,\n      -- pf_not_P\n      have pf_P := pf_P_and_Q.left,\n      exact pf_not_P pf_P,\n      -- pf_not_Q\n      have pf_Q := pf_P_and_Q.right,\n      exact pf_not_Q pf_Q,\nend\n\n-- Is disjunction reflexive?\n-- Is A ∨ A true?\n-- No\nexample: ¬∀(A: Prop), A ∨ A :=\nbegin\n  assume pf_forall,\n  have pf_false_or_false := pf_forall false,\n  cases pf_false_or_false,\n    assumption, assumption,\nend\n\n-- Is disjunction symmetric?\n-- Does A ∨ B imply B ∨ A?\nexample: ∀(A B: Prop),\n  (A ∨ B) → (B ∨ A) :=\nbegin\n  assume A B,\n  assume pf_A_or_B,\n  cases pf_A_or_B with pf_A pf_B,\n    exact or.inr pf_A,\n    exact or.inl pf_B,\nend\n\n-- Is disjunction associative?\n-- Are (A ∨ B) ∨ C and A ∨ (B ∨ C) the same?\nexample: ∀(A B C: Prop),\n  (A ∨ B) ∨ C ↔ A ∨ (B ∨ C) :=\nbegin\n  assume A B C,\n  split,\n    -- (A ∨ B) ∨ C → A ∨ (B ∨ C)\n    assume pf_A_or_B__or_C,\n    cases pf_A_or_B__or_C with pf_A_or_B pf_C,\n      -- pf_A_or_B\n      cases pf_A_or_B with pf_A pf_B,\n        -- pf_A\n        exact or.inl pf_A,\n        -- pf_B\n        have pf_B_or_C: B ∨ C := or.inl pf_B,\n        exact or.inr pf_B_or_C,\n      -- pf_C\n      have pf_B_or_C: B ∨ C := or.inr pf_C,\n      exact or.inr pf_B_or_C,\n    -- A ∨ (B ∨ C) → (A ∨ B) ∨ C\n    assume pf_A_or__B_or_C,\n    cases pf_A_or__B_or_C with pf_A pf_B_or_C,\n      -- pf_A\n      have pf_A_or_B := or.intro_left B pf_A,\n      exact or.inl pf_A_or_B,\n      -- pf_B_or_C\n      cases pf_B_or_C with pf_B pf_C,\n        -- pf_B\n        have pf_A_or_B := or.intro_right A pf_B,\n        exact or.inl pf_A_or_B,\n        -- pf_C\n        exact or.inr pf_C,\nend\n\n-- Is disjunction transitive?\n-- Does (A ∨ B) and (B ∨ C) imply (A ∨ C)?\n-- No\nexample: ¬∀(A B C: Prop),\n  (A ∨ B) → (B ∨ C) → (A ∨ C) :=\nbegin\n  assume pf_forall,\n  have pf_falseness := pf_forall false true false,\n  have pf_f_or_t := or.intro_right false true.intro,\n  have pf_t_or_f := or.intro_left false true.intro,\n  have pf_f_or_f := (pf_falseness pf_f_or_t) pf_t_or_f,\n  cases pf_f_or_f with pf_f pf_f,\n    assumption, assumption,\nend\n\n-- Distribution over ∧\nexample: ∀(A B C: Prop),\n  A ∨ (B ∧ C) ↔ (A ∨ B) ∧ (A ∨ C) :=\nbegin\n  assume A B C,\n  split,\n    -- A ∨ (B ∧ C) → (A ∨ B) ∧ (A ∨ C)\n    assume pf_A_or__B_and_C,\n    cases pf_A_or__B_and_C with pf_A pf_B_and_C,\n      -- pf_A\n      have pf_A_or_B: A ∨ B := or.inl pf_A,\n      have pf_A_or_C := or.intro_left C pf_A,\n      exact and.intro pf_A_or_B pf_A_or_C,\n      -- pf_B_and_C\n      have pf_C := pf_B_and_C.left,\n      have pf_A_or_B: A ∨ B := or.inr pf_C,\n      have pf_B := pf_B_and_C.right,\n      have pf_A_or_C: A ∨ C := or.inr pf_B,\n      exact and.intro pf_A_or_B pf_A_or_C,\n    -- (A ∨ B) ∧ (A ∨ C) → A ∨ (B ∧ C)\n    assume pf_A_or_B__and__A_or_C,\n    cases pf_A_or_B__and__A_or_C.left with pf_A pf_B,\n      -- pf_A\n      exact or.inl pf_A,\n      -- pf_B\n      cases pf_A_or_B__and__A_or_C.right with pf_A pf_C,\n        -- pf_A\n        exact or.inl pf_A,\n        -- pf_C\n        have pf_B_and_C := and.intro pf_B pf_C,\n        exact or.inr pf_B_and_C,\nend\n\n-- Distribution over ∨\nexample: ∀(A B C: Prop),\n  A ∧ (B ∨ C) ↔ (A ∧ B) ∨ (A ∧ C) :=\nbegin\n  assume A B C,\n  split,\n    -- A ∧ (B ∨ C) → (A ∧ B) ∨ (A ∧ C)\n    assume pf_A__and_B_or_C,\n    cases pf_A__and_B_or_C.right with pf_B pf_C,\n      -- B\n      have pf_A := pf_A__and_B_or_C.left,\n      have pf_A_and_B := and.intro pf_A pf_B,\n      exact or.inl pf_A_and_B,\n      -- C\n      have pf_A := pf_A__and_B_or_C.left,\n      have pf_A_and_C := and.intro pf_A pf_C,\n      exact or.inr pf_A_and_C,\n    -- (A ∧ B) ∨ (A ∧ C) → A ∧ (B ∨ C)\n    assume pf_A_and_B__or__A_and_C,\n    cases pf_A_and_B__or__A_and_C with pf_A_and_B pf_A_and_C,\n      -- A ∧ B\n      have pf_B := pf_A_and_B.right,\n      have pf_B_or_C: B ∨ C := or.inl pf_B,\n      have pf_A := pf_A_and_B.left,\n      exact and.intro pf_A pf_B_or_C,\n      -- A ∧ C\n      have pf_C := pf_A_and_C.right,\n      have pf_B_or_C: B ∨ C := or.inr pf_C,\n      have pf_A := pf_A_and_C.left,\n      exact and.intro pf_A pf_B_or_C,\nend\n\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/examples/disjunction_properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7719116833221875}}
{"text": "/-\nCopyright (c) 2022 Flemming Hermansen. \nReleased under Apache 2.0 license as described in \nhttps://www.apache.org/licenses/LICENSE-2.0\nAuthors: Flemming Hermansen\n-/\n\nimport algebra.algebra.basic\nimport order.boolean_algebra\n\n/-\nThis file prove that the idempotent elements in a commutative ring \nconstitute a Boolean algebra.\n\nidempotent_cri (A) [cr : comm_ring A] := { a : A // a * a = a}\nsubtype that contains all the idempotent elements from A.\n\ninstance boolean_algebra_comm_ring_idempotents [comm_ring A] : boolean_algebra (idempotent_cri A) \nThe main result telling that elements of subtype 'idempotent_cri A'\ncan be used as elements in a Boolean algebra.\n\n-/\n\nsection comm_ring_idempotents\n\nvariables  {A : Type*} [comm_ring A] \n\nvariables {B : Type*} [boolean_algebra B] \n\nopen_locale classical\n\nnoncomputable theory\n\ndef idempotent_cri (A) [cr : comm_ring A] := { a : A // a * a = a}\n\nnamespace idempotent_cri\n\ninstance coe_idempotent_cri : has_coe (idempotent_cri (A)) A := ⟨λ (e : idempotent_cri (A)), e.val⟩\n\ninstance inhabited_idempotent_cri : inhabited (idempotent_cri A) := ⟨⟨1, mul_one 1⟩⟩\n\ndef property' (e : idempotent_cri A) : (↑e : A) * ↑e = ↑e := by exact e.property.\n\ndef property'' (e : idempotent_cri A) : (e.val : A) * e.val = e.val := by exact e.property.\n\n@[simp, reducible]\ndef prop_inf_cri [hr : comm_ring A] (a : idempotent_cri A) (b : idempotent_cri A) : \n((a.val : A) * b.val) * (a.val * b.val)  = (a.val * b.val) :=\nbegin\n    simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n    simp only [mul_comm _ b.val,  ← mul_assoc, b.property''], -- idempotent b\n    simp only [mul_comm _ a.val,  ← mul_assoc, a.property''], -- idempotent a\nend\n\n@[simp, reducible]\ndef inf_cri [hr : comm_ring A] (a : idempotent_cri A) (b : idempotent_cri A) : idempotent_cri A :=\nbegin\n  exact ⟨ a * b, \n  begin\n    simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n    simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- idempotent b\n    simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n  end ⟩\nend\n\n@[simp, reducible]\ndef sup_cri [hr : comm_ring A] (a : idempotent_cri A) (b : idempotent_cri A) : \nidempotent_cri A :=\nbegin\n  exact ⟨ ↑a + ↑b - ↑a * ↑b, \n  begin \n     simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n    simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- idempotent b\n    simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n    ring,\n  end ⟩,\nend\n\n@[simp, reducible]\ndef le_cri [hr : comm_ring A] (a : idempotent_cri A) (b : idempotent_cri A) := \n(↑a : A) * ↑b = ↑a\n\n@[simp, reducible]\ndef lt_cri [hr : comm_ring A] (a : idempotent_cri A) (b : idempotent_cri A) :=\n(↑a : A) * ↑b = ↑a ∧ (¬(↑a : A)= ↑b)\n\n@[simp, reducible]\ndef top_cri [hr : comm_ring A] : idempotent_cri A := ⟨ 1, by ring ⟩\n\n@[simp, reducible]\ndef bot_cri [hr : comm_ring A] : idempotent_cri A := ⟨ 0, by ring ⟩\n\n@[simp, reducible]\ndef compl_cri [hr : comm_ring A] (a : idempotent_cri A) : idempotent_cri A := \n ⟨ 1 - ↑a, \nby {simp only [sub_mul, mul_sub, mul_one, one_mul, a.property'], ring} ⟩\n\n@[simp, reducible]\ndef sdiff_cri [hr : comm_ring A] (a b: idempotent_cri A) : idempotent_cri A := \nbegin\n  exact ⟨ ↑a - ↑a * ↑b, \n  begin\n    simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n    simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- idempotent b\n    simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n    ring,\n  end ⟩,\nend\n\n@[simp]\ninstance has_le_comm_ring_idempotents [comm_ring A] : has_le (idempotent_cri A) :=\n{ le := le_cri }\n\n@[simp]\ninstance has_sup_comm_ring_idempotents [comm_ring A] : has_sup (idempotent_cri A) :=\n{ sup := sup_cri }\n\n@[simp]\ninstance has_inf_comm_ring_idempotents [comm_ring A] : has_inf (idempotent_cri A) :=\n{ inf := inf_cri }\n\n@[simp]\ninstance has_top_comm_ring_idempotents [comm_ring A] : has_top (idempotent_cri A) :=\n{ top := top_cri }\n\n@[simp]\ninstance has_bot_comm_ring_idempotents [comm_ring A] : has_bot (idempotent_cri A) :=\n{ bot := bot_cri }\n\n@[simp, reducible]\ninstance has_compl_comm_ring_idempotents [comm_ring A] : has_compl (idempotent_cri A) :=\n{ compl := compl_cri }\n\n@[simp]\ninstance has_sdiff_comm_ring_idempotents [comm_ring A] : has_sdiff (idempotent_cri A) :=\n{ sdiff := sdiff_cri }\n\nlemma sup_assoc_cri [comm_ring A] (a b c: idempotent_cri A) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=\nbegin\n  unfold has_sup.sup, simp, ring_nf, \nend\n\nlemma sup_comm_cri [comm_ring A] (a b : idempotent_cri A) : a ⊔ b  = b ⊔ a :=\nbegin\n  unfold has_sup.sup, apply subtype.eq, ring_nf, \nend\n\nlemma inf_assoc_cri [comm_ring A] (a b c: idempotent_cri A) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) :=\nbegin\n  unfold has_inf.inf, apply subtype.eq, simp {proj := tt}, ring, \nend\n\nlemma inf_comm_cri [comm_ring A] (a b : idempotent_cri A) : a ⊓ b  = b ⊓ a :=\nbegin\n  unfold has_inf.inf, apply subtype.eq, ring_nf, \nend\n\nset_option pp.coercions true.\n\nlemma tt [comm_ring A] (a : idempotent_cri A) : ↑ a = a.val := by refl\n\nlemma sup_inf_self_cri [comm_ring A] (a b : idempotent_cri A) : a ⊔ a ⊓ b = a :=\nbegin\n  unfold has_inf.inf, unfold has_sup.sup,-- apply subtype.eq, --simp {proj := tt},\n  rw inf_cri, rw sup_cri, apply subtype.eq, simp  {proj := true},\n    simp  only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n      ← mul_assoc], -- flatten expression\n    simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n    simp,\nend\n\nlemma inf_sup_self_cri [comm_ring A] (a b : idempotent_cri A) : a ⊓ (a ⊔ b) = a :=\nbegin\n  unfold has_inf.inf, unfold has_sup.sup sup_cri, apply subtype.eq, simp {proj := true}, \n       simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n    simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- idempotent b\n    simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n    simp,\nend\n\n@[simp]\ndef inf_sup_le_cri [comm_ring A] (a b c : idempotent_cri A) : \n  a ⊓ (b ⊔ c) ≤ a ⊓ b ⊔ a ⊓ c :=\nbegin\n  unfold has_sup.sup has_inf.inf has_le.le inf_cri sup_cri le_cri, \n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- idempotent b\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n  simp only [mul_comm _ ↑c,  ← mul_assoc, c.property'], -- idempotent c\n  ring,\nend\n\nlemma le_sup_inf_cri [comm_ring A] (a b c : idempotent_cri A) : \n(a ⊔ b) ⊓ (a ⊔ c) ≤ a ⊔ b ⊓ c :=\nbegin\n  unfold has_sup.sup has_inf.inf has_le.le inf_cri sup_cri le_cri,  \n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- idempotent b\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- idempotent a\n  simp only [mul_comm _ ↑c,  ← mul_assoc, c.property'], -- idempotent c\n  ring,\nend\n\nlemma le_sup_left_cri [comm_ring A] (a b : idempotent_cri A) : a ≤ a ⊔ b :=\nbegin\n  unfold has_sup.sup has_le.le compl_cri sup_cri le_cri, \n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- sort, reflatten, a * a = a\n  ring,\nend\n\nlemma sdiff_eq_cri [comm_ring A] (a b : idempotent_cri A) : \na \\ b = a ⊓ bᶜ :=\nbegin \n  apply subtype.eq, unfold has_inf.inf has_sdiff.sdiff has_compl.compl compl_cri, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- sort, reflatten, b * b = b\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- sort, reflatten, a * a = a\n  ring_nf,\nend\n\nlemma top_le_sup_compl_cri [comm_ring A] (a : idempotent_cri A) : \n⊤ ≤ a ⊔ aᶜ :=\nbegin \n  unfold has_sup.sup has_compl.compl has_top.top has_le.le compl_cri sup_cri le_cri, \n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- sort, reflatten, a * a = a\n  ring,\nend\n\nlemma inf_compl_le_bot_cri [comm_ring A] (a : idempotent_cri A) : \na ⊓ aᶜ ≤ ⊥ :=\nbegin \n  unfold has_inf.inf has_compl.compl has_bot.bot has_le.le compl_cri sup_cri le_cri, \n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- sort, reflatten, a * a = a\n  ring,\nend\n\nlemma le_antisym_cri [comm_ring A] (a b : idempotent_cri A) : a ≤ b → b ≤ a → a = b :=\nbegin \n  unfold has_le.le le_cri,\n  intros hab hba,\n  rw mul_comm at hab, rw hab at hba,\n  apply subtype.eq, exact hba,\nend\n\nlemma sup_le_cri [comm_ring A] (a b c : idempotent_cri A) : a ≤ c → b ≤ c → a ⊔ b ≤ c :=\nbegin\n  unfold has_le.le has_sup.sup sup_cri le_cri, \n  intros hac hbc,\n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n    mul_assoc], -- flatten expression\n  rw hac, rw hbc,\nend\n\nlemma le_inf_cri [comm_ring A] (a b c : idempotent_cri A) : a ≤ b → a ≤ c → a ≤ b ⊓ c :=\nbegin\n  unfold has_le.le has_inf.inf, simp only [inf_cri, le_cri],\n  intros haba haca,\n  simp {proj := true}, \n  simp only [ ← mul_assoc], -- flatten expression\n  rw haba, rw haca,\nend\n\nlemma le_top_cri [comm_ring A] (a : idempotent_cri A) : a ≤ ⊤ :=\nbegin \n  unfold has_le.le has_top.top le_cri,\n  simp {proj := true}, \nend\n\nlemma bot_le_cri [comm_ring A] (a : idempotent_cri A) : ⊥ ≤ a :=\nbegin\n  unfold has_le.le has_bot.bot le_cri,\n  simp {proj := true}, \nend\n\nlemma le_sup_right_cri [comm_ring A] (a b : idempotent_cri A) : b ≤ a ⊔ b :=\nbegin\n  unfold has_le.le has_sup.sup le_cri sup_cri,\n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- sort, reflatten, a * a = a\n  ring,\nend\n\nlemma inf_inf_sdiff_cri [comm_ring A] (a b : idempotent_cri A) : a ⊓ b ⊓ a \\ b = ⊥ :=\nbegin\n  unfold has_inf.inf has_sdiff.sdiff inf_cri sdiff_cri,\n  apply subtype.eq, simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- sort, reflatten, b * b = b\n  simp only [mul_comm _ ↑a,  ← mul_assoc, b.property'], -- sort, reflatten, a * a = a\n  ring_nf,\nend\n\nlemma inf_le_left_cri [comm_ring A] (a b : idempotent_cri A) : a ⊓ b ≤ a :=\nbegin\n  unfold has_le.le has_inf.inf inf_cri le_cri,\n  simp {proj := true}, \n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- sort, reflatten, a * a = a\nend\n\nlemma inf_le_right_cri [comm_ring A] (a b : idempotent_cri A) : a ⊓ b ≤ b :=\nbegin\n  unfold has_le.le has_inf.inf inf_cri le_cri,\n  simp {proj := true}, \n  simp only [mul_assoc, b.property'], -- flatten, b * b = b\nend\n\nlemma sup_inf_sdiff_cri [comm_ring A] (a b : idempotent_cri A) : a ⊓ b ⊔ a \\ b = a :=\nbegin\n  unfold has_inf.inf has_sup.sup has_sdiff.sdiff sup_cri inf_cri sdiff_cri,\n  simp {proj := true}, \n  simp only [sub_mul, mul_sub, add_mul, mul_add, -- distributative\n     ← mul_assoc], -- flatten expression\n  simp only [mul_comm _ ↑a,  ← mul_assoc, a.property'], -- sort, reflatten, a * a = a\n  simp only [mul_comm _ ↑b,  ← mul_assoc, b.property'], -- sort, reflatten, b * b = b\n  simp {proj := true}, \nend\n\nlemma le_reflexive_cri [comm_ring A] (a : idempotent_cri A) : a ≤ a :=\nbegin\n  unfold has_le.le le_cri, rw a.property',\nend\n\nlemma le_trans_cri [comm_ring A] (a b c : idempotent_cri A) : a ≤ b → b ≤ c → a ≤ c :=\nbegin  unfold has_le.le le_cri, intros h1 h2, \n  rw ← h1, rw mul_assoc, rw h2,\nend\n\nlemma lt_iff_le_not_le_cri [comm_ring A] (a b : idempotent_cri A) : \n  ( a ≤ b ∧ (¬a.val = b.val)) ↔ a ≤ b ∧ ¬b ≤ a := \n  begin unfold has_lt.lt has_le.le le_cri, \n    split,\n    -- ->\n    intros h, cases h with hle hne,\n    split, assumption,\n    intros b_nle_a, \n    simp at hne {proj := true}, \n    rw ← hle at hne, rw mul_comm at hne,\n    contradiction,\n    -- <-\n    intros h,\n    cases h with aleb bnlea,\n    split, assumption,\n    rw mul_comm at aleb,\n    simp {proj := true}, \n    rw ← aleb,\n    intros h_contra,\n    rw h_contra at bnlea,\n    contradiction,\n  end\n\n@[priority 100]  -- see Note [lower instance priority]\ninstance boolean_algebra_comm_ring_idempotents [comm_ring A] : \nboolean_algebra (idempotent_cri A) :=\n{ sup := sup_cri,\n  le := le_cri,\n  lt := lt_cri,\n  le_refl :=le_reflexive_cri, \n  le_trans := le_trans_cri,\n  lt_iff_le_not_le := lt_iff_le_not_le_cri,\n  le_antisymm := le_antisym_cri,\n  le_sup_left := le_sup_left_cri,\n  le_sup_right := le_sup_right_cri,\n  sup_le := sup_le_cri,\n  inf := inf_cri,\n  inf_le_left := inf_le_left_cri,\n  inf_le_right := inf_le_right_cri,\n  le_inf := le_inf_cri,\n  le_sup_inf := le_sup_inf_cri,\n  sdiff := sdiff_cri,\n  bot := bot_cri,\n  -- The following fields have been removed in the latest version of Mathlib\n  -- sup_inf_sdiff := sup_inf_sdiff_cri,\n  -- inf_inf_sdiff := inf_inf_sdiff_cri,\n  compl := compl_cri,\n  top := top_cri,\n  inf_compl_le_bot := inf_compl_le_bot_cri,\n  top_le_sup_compl := top_le_sup_compl_cri,\n  le_top := le_top_cri,\n  bot_le := bot_le_cri,\n  sdiff_eq := sdiff_eq_cri }\n\n@[reducible]\ndef simp_inf_cri [hr : comm_ring A] (a b : idempotent_cri A) : \n(a ⊓ b) = (⟨ a.val * b.val, prop_inf_cri a b ⟩ :  idempotent_cri A) :=\nbegin\n  let ee := (⟨ a.val * b.val, prop_inf_cri a b ⟩ :  idempotent_cri A),\n  have inf_eq : (a ⊓ b) = ee, by refl,\n  exact inf_eq,\nend\n\nlemma bot_of_inf_sdiff_self {B : Type*} [boolean_algebra B] (e e': B)\n: e ⊓ (e'\\e) = ⊥ :=\nbegin\n  rw sdiff_eq, \n  conv { to_lhs, congr, skip, rw inf_comm },\n  rw ← inf_assoc, rw inf_compl_eq_bot, rw bot_inf_eq,\nend\n\nend idempotent_cri\n\nend comm_ring_idempotents\n", "meta": {"author": "fhermansen", "repo": "Relative_inverses", "sha": "ef6682ab72c243dd829fe1cd7c1c96f003a075fa", "save_path": "github-repos/lean/fhermansen-Relative_inverses", "path": "github-repos/lean/fhermansen-Relative_inverses/Relative_inverses-ef6682ab72c243dd829fe1cd7c1c96f003a075fa/boolean_algebra_of_comm_ring_idempotents.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.77190985948059}}
{"text": "-- La composición de funciones inyectivas es inyectiva\n-- ===================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar que la composición de dos funciones\n-- inyectivas es una función inyectiva.\n-- ----------------------------------------------------\n\nimport tactic\n\nopen function\n\nvariables {X Y Z : Type}\nvariable  {f : X → Y}\nvariable  {g : Y → Z} \n\n-- 1ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nbegin\n  intros x y h,\n  apply Hf,\n  apply Hg,\n  exact h,\nend\n\n-- 2ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nbegin\n  intros x y h,\n  apply Hf,\n  exact Hg h,\nend\n\n-- 3ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nbegin\n  intros x y h,\n  exact Hf (Hg h),\nend\n\n-- 4ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nλ x y h, Hf (Hg h)\n\n-- 5ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nassume x y,\nassume h1 : (g ∘ f) x = (g ∘ f) y,\nhave h2 : f x = f y, from Hg h1,\nshow x = y, from Hf h2\n\n-- 6ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nassume x y,\nassume h1 : (g ∘ f) x = (g ∘ f) y,\nshow x = y, from Hf (Hg h1)\n\n-- 7ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nassume x y,\nassume h1 : (g ∘ f) x = (g ∘ f) y,\nHf (Hg h1)\n\n-- 8ª demostración\nexample \n  (Hf : injective f) \n  (Hg : injective g) \n  : injective (g ∘ f) :=\nλ x y h1, Hf (Hg h1)\n\n-- 9ª demostración\nexample \n  (Hg : injective g) \n  (Hf : injective f) \n  : injective (g ∘ f) :=\n-- by library_search\ninjective.comp Hg Hf\n\n-- 10ª demostración\nexample \n  (Hg : injective g) \n  (Hf : injective f) \n  : injective (g ∘ f) :=\n-- by hint\nby tauto\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_composicion_de_funciones_inyectivas_es_inyectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.771909857822539}}
{"text": "open classical\n\ntheorem double_neg_elim: ∀ { P }, ¬¬P → P := \nbegin\n  assume P : Prop,\n  assume pfNotNotP : ¬¬P,\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\ntheorem double_neg_elim': ∀ {P}, (P ∨ ¬P) → ¬¬P → P :=\nbegin\n    assume P: Prop,\n    assume h: P ∨ ¬P,\n    assume notnotP: ¬¬P,\n    cases h with a b,\n        show P, from a,\n        show P, from false.elim (notnotP b),\nend\n\ntheorem p_b_c' : ∀ P: Prop, (¬P → false) → P := λ P nnP, double_neg_elim nnP\n\ntheorem proof_by_contrapositive: \n    ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) :=\n    begin\n        assume P Q: Prop,\n        assume nqnp: (¬ Q → ¬ P),\n        assume p : P,\n        have nnq : ¬ Q → false :=\n            begin \n                assume nq : ¬Q,\n                have np : ¬P := nqnp nq,\n                show false, from np p\n            end,\n        show Q, from double_neg_elim nnq\n    end\n\ntheorem proof_by_contrapositive': \n    ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) :=\n    begin\n        assume P Q: Prop,\n        assume nqnp: (¬ Q → ¬ P),\n        assume p : P,\n        have nnq : ¬ Q → false :=\n            λ nq : ¬Q, nqnp nq p,\n        show Q, from double_neg_elim nnq\n    end\n\ntheorem proof_by_contrapositive''''': \n    ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) :=\n    begin\n        assume (P Q: Prop) (nqnp: ¬ Q → ¬ P) (p: P),\n        exact double_neg_elim (λ nq : ¬Q, nqnp nq p)\n    end\n\ntheorem proof_by_contrapositive'''': \n    ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) :=\n    begin\n        assume P Q: Prop,\n        assume nqnp: (¬ Q → ¬ P),\n        assume p : P,\n        exact double_neg_elim (λ nq : ¬Q, nqnp nq p)\n    end\n\ntheorem proof_by_contrapositive'': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) :=\n    λ (P Q : Prop) (nqnp : ¬ Q → ¬ P) (p: P), \n        double_neg_elim (λ nq : ¬ Q, nqnp nq p)\n\ntheorem proof_by_contrapositive''': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) :=\n    λ P Q nqnp p, double_neg_elim (λ nq, nqnp nq p)\n\ntheorem z: ∀ { a }, ¬¬a → a := \nλ a b,\nbegin\n  cases em a with c d,\n    exact c,\n    exact false.elim (b d)\nend\n\nvariable k: Prop\n#check em k\n#check or.by_cases\n#check or.cases_on\n\ntheorem double_neg_elim'': ∀ {a}, ¬¬a → a := \nλ a b, or.cases_on (em a) (λ a, a) (λ c, false.elim (b c))\n\nexample {P: Prop} (a: ¬¬P) : double_neg_elim a = double_neg_elim'' a := rfl\n\ntheorem j: ∀ a b : Prop, (¬ b → ¬ a) → (a → b) :=\n    λ a b c d, z (λ e, c e d)\n\n\nvariables P Q: Prop\nvariable q : Q -- proof of Q\nexample : P → Q := λ p : P, q\nexample : P → Q := assume p : P, q\n\n-- def prime (p : ℕ) := p ≥ 2 ∧ ∀ n, n | p → n = 1 ∨ n = p", "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/lesson7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7719098471393444}}
{"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 ℕ\n\nThis file identifies a few functions on `ℕ` 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 : ℕ) : periodic (gcd a) a :=\nby simp only [forall_const, gcd_add_self_right, eq_self_iff_true, periodic]\n\nlemma periodic_coprime (a : ℕ) : periodic (coprime a) a :=\nby simp only [coprime_add_self_right, forall_const, iff_self, eq_iff_iff, periodic]\n\nlemma periodic_mod (a : ℕ) : periodic (λ 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 {α : Type*} {f : ℕ → α} {a : ℕ} (hf : periodic f a) :\n  ∀ n, f (n % a) = f n :=\nλ n, by conv_rhs { rw [← nat.mod_add_div n a, mul_comm, ← 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 : ℕ) (p : ℕ → 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_coe,\n    ←multiset_Ico_map_mod n, ←map_count_true_eq_filter_card, ←map_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 : ℕ) (p : ℕ → 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": "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/periodic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.771909845942874}}
{"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\" (`→`)\n\nWe learn about propositions, and implications `P → Q` between them. You can get\nthis arrow by typing `\\to` or `\\r`. Mathematicians usually write the\nimplication arrow as `P ⇒ 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 `⊢` 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  exact hP,\nend\n\n-- Assume `Q` is true. Prove that `P → Q`. \nexample (hQ : Q) : P → Q :=\nbegin\n  intro fish,\n  exact hQ,\nend\n\n-- Assume `P → Q` and `P` is true. Deduce `Q`.\nexample (h : P → Q) (hP : P) : Q :=\nbegin\n  apply h,\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 → P :=\nbegin\n  intro banana,\n  exact banana,\nend\n\n/-\n\nNote that `→` is not associative: in general `P → (Q → R)` and `(P → Q) → 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 → Q → R` then we'd better know what this means.\nThe convention in Lean is that it means `P → (Q → 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 → P2 → P3 → ... 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 → (Q → P)`.\n\n-/\nexample : P → Q → P :=\nbegin\n  intro hP,\n  intro hQ,\n  assumption,\nend\n\n/-- If we know `P`, and we also know `P → Q`, we can deduce `Q`. \nThis is called \"Modus Ponens\" by logicians. -/\nexample : P → (P → Q) → Q :=\nbegin\n  intros hP hPQ,\n  apply hPQ,\n  exact hP,\nend\n\n/-- `→` is transitive. That is, if `P → Q` and `Q → R` are true, then\n  so is `P → R`. -/\nexample : (P → Q) → (Q → R) → (P → R) :=\nbegin\n  intros hPQ hQR hP,\n  apply hQR,\n  apply hPQ,\n  exact hP,\nend\n\n-- If `h : P → Q → R` with goal `⊢ R` and you `apply h`, you'll get\n-- two goals! Note that tactics operate on only the first goal.\nexample : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  intros hPQR hPQ hP,\n  apply hPQR,\n  { exact hP },\n  { apply hPQ,\n    exact hP }\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 → R) → (S → Q) → (R → T) → (Q → R) → S → T :=\nbegin\n  intros hPR hSQ hRT hQR hS,\n  apply hRT,\n  clear hPR,\n  apply hQR,\n  apply hSQ,\n  exact hS,\nend\n\nexample : (P → Q) → ((P → Q) → P) → Q :=\nbegin\n  intros hPQ hPQP,\n  apply hPQ,\n  apply hPQP,\n  exact hPQ,\nend\n\nexample : ((P → Q) → R) → ((Q → R) → P) → ((R → P) → Q) → P :=\nbegin\n  intros h1 h2 h3,\n  apply h2,\n  intro hQ,\n  apply h1,\n  intro hP,\n  exact hQ,\nend\n\nexample : ((Q → P) → P) → (Q → R) → (R → P) → P :=\nbegin\n  intros h1 h2 h3,\n  apply h1,\n  intro hQ,\n  apply h3,\n  apply h2,\n  exact hQ,\nend\n\nexample : (((P → Q) → Q) → Q) → (P → Q) :=\nbegin\n  intros h1 hP,\n  apply h1,\n  intro hPQ,\n  exact hPQ hP,\nend\n\nexample :\n  (((P → Q → Q) → ((P → Q) → Q)) → R) →\n  ((((P → P) → Q) → (P → P → Q)) → R) →\n  (((P → P → Q) → ((P → P) → Q)) → R) → R :=\nbegin\n  intros h1 h2 h3,\n  apply h2,\n  intros h1 hP h2,\n  apply h1,\n  intro hP,\n  exact h2,\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/section01logic/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7719098436865879}}
{"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_space.ordered\n\n/-!\n# Asymptotic equivalence\n\nIn this file, we define the relation `is_equivalent u v l`, 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 `β`. While the\ndefinition only requires `β` to be a `normed_group`, most interesting properties require it to be a\n`normed_field`.\n\n## Notations\n\nWe introduce the notation `u ~[l] v := is_equivalent u v l`, which you can use by opening the\n`asymptotics` locale.\n\n## Main results\n\nIf `β` is a `normed_group` :\n\n- `_ ~[l] _` is an equivalence relation\n- Equivalent statements for `u ~[l] const _ c` :\n  - If `c ≠ 0`, this is true iff `tendsto u l (𝓝 c)` (see `is_equivalent_const_iff_tendsto`)\n  - For `c = 0`, this is true iff `u =ᶠ[l] 0` (see `is_equivalent_zero_iff_eventually_zero`)\n\nIf `β` is a `normed_field` :\n\n- Alternative characterization of the relation (see `is_equivalent_iff_exists_eq_mul`) :\n\n  `u ~[l] v ↔ ∃ (φ : α → β) (hφ : tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v`\n\n- Provided some non-vanishing hypothesis, this can be seen as `u ~[l] v ↔ tendsto (u/v) l (𝓝 1)`\n  (see `is_equivalent_iff_tendsto_one`)\n- For any constant `c`, `u ~[l] v` implies `tendsto u l (𝓝 c) ↔ tendsto v l (𝓝 c)`\n  (see `is_equivalent.tendsto_nhds_iff`)\n- `*` and `/` are compatible with `_ ~[l] _` (see `is_equivalent.mul` and `is_equivalent.div`)\n\nIf `β` is a `normed_linear_ordered_field` :\n\n- If `u ~[l] v`, we have `tendsto u l at_top ↔ tendsto v l at_top`\n  (see `is_equivalent.tendsto_at_top_iff`)\n\n-/\n\nnamespace asymptotics\n\nopen filter function\nopen_locale topological_space\n\nsection normed_group\n\nvariables {α β : Type*} [normed_group β]\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 (u v : α → β) (l : filter α) := is_o (u - v) v l\n\nlocalized \"notation u ` ~[`:50 l:50 `] `:0 v:50 := asymptotics.is_equivalent u v l\" in asymptotics\n\nvariables {u v w : α → β} {l : filter α}\n\nlemma is_equivalent.is_o (h : u ~[l] v) : is_o (u - v) v l := h\n\nlemma is_equivalent.is_O (h : u ~[l] v) : is_O u v l :=\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) : is_O v u l :=\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 (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 : α → β} {l : filter α} (huv : u ~[l] v)\n  (huw : u =ᶠ[l] w) : w ~[l] v :=\nis_o.congr' (huw.sub (eventually_eq.refl _ _)) (eventually_eq.refl _ _) huv\n\nlemma is_equivalent.congr_right {u v w : α → β} {l : filter α} (huv : u ~[l] v)\n  (hvw : v =ᶠ[l] w) : u ~[l] w :=\n(huv.symm.congr_left hvw).symm\n\nlemma is_equivalent_zero_iff_eventually_zero : u ~[l] 0 ↔ u =ᶠ[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 ↔ is_O u (0 : α → β) l :=\nbegin\n  refine ⟨is_equivalent.is_O, λ h, _⟩,\n  rw [is_equivalent_zero_iff_eventually_zero, eventually_eq_iff_exists_mem],\n  exact ⟨{x : α | u x = 0}, is_O_zero_right_iff.mp h, λ x hx, hx⟩,\nend\n\nlemma is_equivalent_const_iff_tendsto {c : β} (h : c ≠ 0) : u ~[l] const _ c ↔ tendsto u l (𝓝 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 ← sub_self c} ];\n  convert this; try { ext }; simp\nend\n\nlemma is_equivalent.tendsto_const {c : β} (hu : u ~[l] const _ c) : tendsto u l (𝓝 c) :=\nbegin\n  rcases (em $ c = 0) with ⟨rfl, h⟩,\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 : β} (huv : u ~[l] v) :\n  tendsto u l (𝓝 c) ↔ tendsto v l (𝓝 c) := ⟨huv.tendsto_nhds, huv.symm.tendsto_nhds⟩\n\nlemma is_equivalent.add_is_o (huv : u ~[l] v) (hwv : is_o w v l) : (w + u) ~[l] v :=\nbegin\n  rw is_equivalent at *,\n  convert hwv.add huv,\n  ext,\n  simp [add_sub],\nend\n\nlemma is_o.is_equivalent (huv : is_o (u - v) v l) : u ~[l] v := huv\n\nlemma is_equivalent.neg (huv : u ~[l] v) : (λ x, - u x) ~[l] (λ 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_group\n\nopen_locale asymptotics\n\nsection normed_field\n\nvariables {α β : Type*} [normed_field β] {t u v w : α → β} {l : filter α}\n\nlemma is_equivalent_iff_exists_eq_mul : u ~[l] v ↔\n  ∃ (φ : α → β) (hφ : tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v :=\nbegin\n  rw [is_equivalent, is_o_iff_exists_eq_mul],\n  split; rintros ⟨φ, hφ, h⟩; [use (φ + 1), use (φ - 1)]; split,\n  { conv in (𝓝 _) { rw ← zero_add (1 : β) },\n    exact hφ.add (tendsto_const_nhds) },\n  { convert h.add (eventually_eq.refl l v); ext; simp [add_mul] },\n  { conv in (𝓝 _) { rw ← sub_self (1 : β) },\n    exact hφ.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  ∃ (φ : α → β) (hφ : tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v :=\nis_equivalent_iff_exists_eq_mul.mp huv\n\nlemma is_equivalent_of_tendsto_one (hz : ∀ᶠ x in l, v x = 0 → u x = 0)\n  (huv : tendsto (u/v) l (𝓝 1)) : u ~[l] v :=\nbegin\n  rw is_equivalent_iff_exists_eq_mul,\n  refine ⟨u/v, huv, hz.mono $ λ x hz', (div_mul_cancel_of_imp hz').symm⟩,\nend\n\nlemma is_equivalent_of_tendsto_one' (hz : ∀ x, v x = 0 → u x = 0) (huv : tendsto (u/v) l (𝓝 1)) :\n  u ~[l] v :=\nis_equivalent_of_tendsto_one (eventually_of_forall hz) huv\n\nlemma is_equivalent_iff_tendsto_one (hz : ∀ᶠ x in l, v x ≠ 0) :\n  u ~[l] v ↔ tendsto (u/v) l (𝓝 1) :=\nbegin\n  split,\n  { intro hequiv,\n    have := hequiv.is_o.tendsto_0,\n    simp only [pi.sub_apply, sub_div] at this,\n    have key : tendsto (λ x, v x / v x) l (𝓝 1),\n    { exact (tendsto_congr' $ hz.mono $ λ 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 $ λ x hnvz hz, (hnvz hz).elim) }\nend\n\nend normed_field\n\nsection smul\n\nlemma is_equivalent.smul {α E 𝕜 : Type*} [normed_field 𝕜] [normed_group E]\n  [normed_space 𝕜 E] {a b : α → 𝕜} {u v : α → E} {l : filter α} (hab : a ~[l] b) (huv : u ~[l] v) :\n  (λ x, a x • u x) ~[l] (λ x, b x • v x) :=\nbegin\n  rcases hab.exists_eq_mul with ⟨φ, hφ, habφ⟩,\n  have : (λ (x : α), a x • u x) - (λ (x : α), b x • v x) =ᶠ[l] λ x, b x • ((φ x • u x) - v x),\n  { convert (habφ.comp₂ (•) $ eventually_eq.refl _ u).sub (eventually_eq.refl _ (λ x, b x • v x)),\n    ext,\n    rw [pi.mul_apply, mul_comm, mul_smul, ← 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 ⟨C, hC, hCuv⟩,\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φ,\n  intros c hc,\n  specialize hφ ((c/2)/C) (div_pos (by linarith) hC),\n  specialize huv (show 0 < c/2, by linarith),\n  refine hφ.mp (huv.mp $ hCuv.mono $ λ x hCuvx huvx hφx, _),\n\n  have key :=\n    calc ∥φ x - 1∥ * ∥u x∥\n            ≤ (c/2) / C * ∥u x∥ : mul_le_mul_of_nonneg_right hφx.le (norm_nonneg $ u x)\n        ... ≤ (c/2) / C * (C*∥v x∥) : mul_le_mul_of_nonneg_left hCuvx (div_pos (by linarith) hC).le\n        ... = c/2 * ∥v x∥ : by {field_simp [hC.ne.symm], ring},\n\n  calc ∥((λ (x : α), φ x • u x) - v) x∥\n          = ∥(φ x - 1) • u x + (u x - v x)∥ : by simp [sub_smul, sub_add]\n      ... ≤ ∥(φ x - 1) • u x∥ + ∥u x - v x∥ : norm_add_le _ _\n      ... = ∥φ x - 1∥ * ∥u x∥ + ∥u x - v x∥ : by rw norm_smul\n      ... ≤ c / 2 * ∥v x∥ + ∥u x - v x∥ : add_le_add_right key _\n      ... ≤ c / 2 * ∥v x∥ + c / 2 * ∥v x∥ : add_le_add_left huvx _\n      ... = c * ∥v x∥ : by ring,\nend\n\nend smul\n\nsection mul_inv\n\nvariables {α β : Type*} [normed_field β] {t u v w : α → β} {l : filter α}\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) : (λ x, (u x)⁻¹) ~[l] (λ x, (v x)⁻¹) :=\nbegin\n  rw is_equivalent_iff_exists_eq_mul at *,\n  rcases huv with ⟨φ, hφ, h⟩,\n  rw ← inv_one,\n  refine ⟨λ x, (φ x)⁻¹, tendsto.inv₀ hφ (by norm_num) , _⟩,\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  (λ x, t x / v x) ~[l] (λ 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 {α β : Type*} [normed_linear_ordered_field β] {u v : α → β} {l : filter α}\n\nlemma is_equivalent.tendsto_at_top [order_topology β] (huv : u ~[l] v) (hu : tendsto u l at_top) :\n  tendsto v l at_top :=\nlet ⟨φ, hφ, h⟩ := huv.symm.exists_eq_mul in\ntendsto.congr' h.symm ((mul_comm u φ) ▸ (hu.at_top_mul zero_lt_one hφ))\n\nlemma is_equivalent.tendsto_at_top_iff [order_topology β] (huv : u ~[l] v) :\n  tendsto u l at_top ↔ tendsto v l at_top := ⟨huv.tendsto_at_top, huv.symm.tendsto_at_top⟩\n\nlemma is_equivalent.tendsto_at_bot [order_topology β] (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 β] (huv : u ~[l] v) :\n  tendsto u l at_bot ↔ tendsto v l at_bot := ⟨huv.tendsto_at_bot, huv.symm.tendsto_at_bot⟩\n\nend normed_linear_ordered_field\n\nend asymptotics\n\nopen filter asymptotics\nopen_locale asymptotics\n\nvariables {α β : Type*} [normed_group β]\n\nlemma filter.eventually_eq.is_equivalent {u v : α → β} {l : filter α} (h : u =ᶠ[l] v) : u ~[l] v :=\nis_o.congr' h.sub_eq.symm (eventually_eq.refl _ _) (is_o_zero v l)\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/asymptotic_equivalent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.7718684616675399}}
{"text": "import algebra.group_power\nimport data.nat.gcd\nimport data.nat.modeq\nimport number_theory.pell\n\nattribute [elab_as_eliminator] nat.strong_induction_on\nattribute [refl] dvd_refl\nattribute [trans] dvd_trans\nattribute [symm] nat.coprime.symm\n\nopen nat \n\nlemma nat.gcd_add_mul_left (a b n : ℕ) : gcd (a + b * n) b = gcd a b :=\nby rw [nat.gcd_comm, gcd_rec, add_mul_mod_self_left, ← gcd_rec, nat.gcd_comm]\n\nlemma nat.gcd_add_mul_right (a b n : ℕ) : gcd (a + n * b) b = gcd a b :=\nby rw [nat.gcd_comm, gcd_rec, add_mul_mod_self_right, ← gcd_rec, nat.gcd_comm]\n\nlemma nat.gcd_add (a b : ℕ) : gcd (a + b) b = gcd a b :=\nby rw [← nat.gcd_add_mul_left a b 1, mul_one]\n\n@[elab_as_eliminator]\nlemma nat.mod_rec (m n : ℕ) {X : Sort*} {C : ℕ → X}\n  (H : ∀ n, C n = C (n+m)) :\n  C n = C (n%m) :=\nhave H1 : ∀ q r, C (r + m * q) = C r,\n  from λ q, nat.rec_on q (λ r, by rw [mul_zero]; refl) $ λ n ih r,\n    by rw [mul_succ, ← add_assoc, ← H, ih],\nby conv in (C n) { rw [← mod_add_div n m, H1] }\n\ndef nat.mod_add (a b m : ℕ) : (a % m + b % m) % m = (a + b) % m :=\nnat.modeq.modeq_add (nat.mod_mod _ _) (nat.mod_mod _ _)\n\n-- modeq\n-- needs data.nat.modeq\n\n-- #check 2 ≡ 5 [MOD 5] -- notation\n\ninstance nonsquare_five : zsqrtd.nonsquare 5 :=\n⟨λ n, nat.cases_on n dec_trivial $ λ n,\n  nat.cases_on n dec_trivial $ λ n,\n  nat.cases_on n dec_trivial $ λ n,\n  ne_of_lt $ calc 5 < 3 * 3 : dec_trivial\n    ... ≤ 3 * (n+3) : nat.mul_le_mul_left _ (nat.le_add_left _ _)\n    ... ≤ (n+3) * (n+3) : nat.mul_le_mul_right _ (nat.le_add_left _ _)⟩\n\n@[simp] lemma is_ring_hom.map_int {α : Type*} {β : Type*}\n  [ring α] [ring β] (f : α → β)\n  [is_ring_hom f] (i : ℤ) : f i = i :=\nint.induction_on i\n  (is_ring_hom.map_zero f)\n  (λ j H, by simp [is_ring_hom.map_add f, is_ring_hom.map_one f, H]; exact H)\n  (λ j H, by simp_rw [int.cast_sub, is_ring_hom.map_sub f, H, int.cast_one, is_ring_hom.map_one f])\n\n@[simp] lemma units.neg_coe {α : Type*} [ring α] (x : units α) : ((-x : units α) : α) = -↑x :=\nrfl\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/mathlib_someday.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7718605737610693}}
{"text": "-- topological spaces from first principles.\n\nimport tactic\n\nopen set\n\nclass topological_space (X : Type) :=\n(is_open        : set X → Prop)\n(is_open_univ   : is_open univ)\n(is_open_inter  : ∀ (U V : set X), is_open U → is_open V → is_open (U ∩ V))\n(is_open_sUnion : ∀ (𝒞 : set (set X)), (∀U ∈ 𝒞, is_open U) → is_open (⋃₀ 𝒞))\n\nnamespace topological_space\n\nvariables {X : Type} [topological_space X]\n\nvariable {ι : Type}\n\nlemma is_open_Union {f : ι → set X} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=\nbegin\n  apply is_open_sUnion,\n  intros U,\n  intro hU,\n  cases hU with i hi,\n  dsimp at hi,\n  rw ←hi,\n  apply h,\nend\n\n-- remember `U : set X` means \"U is a subset of X\", or \"U is a set of terms of X\"\nvariables (U V : set X)\n\nlemma is_open_union (h₁ : is_open U) (h₂ : is_open V) : is_open (U ∪ V) :=\nbegin\n  let 𝒞 : set (set X) := {U, V},\n  have h𝒞 : ∀ U ∈ 𝒞, is_open U,\n  { intros W hW,\n    rcases hW with rfl | ⟨_, _⟩; assumption},\n  convert is_open_sUnion 𝒞 h𝒞,\n  simp only [sUnion_singleton, sUnion_insert]\nend\n\nlemma is_open_empty : is_open (∅ : set X) :=\nbegin\n  let 𝒞 : set (set X) := ∅,\n  have h𝒞 : ∀ U ∈ 𝒞, is_open U,\n    rintro U ⟨⟩,\n  convert is_open_sUnion 𝒞 h𝒞,\n  apply sUnion_empty.symm,\nend\n\n/-- A set is closed if its complement is open -/\ndef is_closed (U : set X) : Prop := is_open Uᶜ\n\nend topological_space\n\nopen topological_space\n\nvariables {X : Type} [topological_space X] {Y : Type} [topological_space Y]\n\n/-- A function between topological spaces is continuous if the preimage\n  of every open set is open. -/\ndef continuous (f : X → Y) := ∀U, is_open U → is_open (f ⁻¹' U)\n\ntheorem continuous_id : continuous (id : X → X) :=\nbegin\n  intros U hU,\n--  have h1 : U = id '' U := rfl, -- fails\n--  have h2 : U = id ⁻¹' U := rfl, -- works\n  exact hU,\nend\n\nvariables {Z : Type} [topological_space Z]\n\ntheorem continuous.comp {g : Y → Z} {f : X → Y} (hg : continuous g) (hf : continuous f) :\ncontinuous (g ∘ f) :=\n--λ U hU, hf (g⁻¹' U) $ hg _ hU\nbegin\n  intros U hU,\n--  change is_open (f⁻¹' (g⁻¹' U)),\n  apply hf (g⁻¹' U),\n  apply hg,\n  assumption,\nend\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/top_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7718605630846187}}
{"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 : ℕ) (m : ℕ) : ℕ :=\n  n - m + (m - n)\n\ntheorem dist.def (n : ℕ) (m : ℕ) : dist n m = n - m + (m - n) :=\n  rfl\n\ntheorem dist_comm (n : ℕ) (m : ℕ) : dist n m = dist m n := sorry\n\n@[simp] theorem dist_self (n : ℕ) : dist n n = 0 := sorry\n\ntheorem eq_of_dist_eq_zero {n : ℕ} {m : ℕ} (h : dist n m = 0) : n = m := sorry\n\ntheorem dist_eq_zero {n : ℕ} {m : ℕ} (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 : ℕ} {m : ℕ} (h : n ≤ 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)))) (Eq.refl (m - n))))\n\ntheorem dist_eq_sub_of_le_right {n : ℕ} {m : ℕ} (h : m ≤ 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 : ℕ) (m : ℕ) : m ≤ 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 : ℕ) (m : ℕ) : m ≤ n + dist n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (m ≤ n + dist n m)) (add_comm n (dist n m)))) (dist_tri_left n m)\n\ntheorem dist_tri_left' (n : ℕ) (m : ℕ) : n ≤ dist n m + m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (n ≤ dist n m + m)) (dist_comm n m))) (dist_tri_left m n)\n\ntheorem dist_tri_right' (n : ℕ) (m : ℕ) : n ≤ m + dist n m :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (n ≤ m + dist n m)) (dist_comm n m))) (dist_tri_right m n)\n\ntheorem dist_zero_right (n : ℕ) : 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 : ℕ) : 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 : ℕ) (k : ℕ) (m : ℕ) : dist (n + k) (m + k) = dist n m := sorry\n\ntheorem dist_add_add_left (k : ℕ) (n : ℕ) (m : ℕ) : 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))) (dist_add_add_right n k m))\n\ntheorem dist_eq_intro {n : ℕ} {m : ℕ} {k : ℕ} {l : ℕ} (h : n + m = k + l) : dist n k = dist l m := sorry\n\nprotected theorem sub_lt_sub_add_sub (n : ℕ) (m : ℕ) (k : ℕ) : n - k ≤ n - m + (m - k) := sorry\n\ntheorem dist.triangle_inequality (n : ℕ) (m : ℕ) (k : ℕ) : dist n k ≤ dist n m + dist m k := sorry\n\ntheorem dist_mul_right (n : ℕ) (k : ℕ) (m : ℕ) : dist (n * k) (m * k) = dist n m * k := sorry\n\ntheorem dist_mul_left (k : ℕ) (n : ℕ) (m : ℕ) : 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 ≥ 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 : ℕ} : dist (Nat.succ i) (Nat.succ j) = dist i j := sorry\n\ntheorem dist_pos_of_ne {i : ℕ} {j : ℕ} : i ≠ j → 0 < dist i 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/data/nat/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7717161054592101}}
{"text": "\n-- textbook: List\nimport Init\n\nopen List\n\nvariable {α : Type}\nvariable (as bs cs : List α)\nvariable (a b c : α)\n\n#check a :: as\n#check as ++ bs\n\nexample : [] ++ as = as := nil_append as\n\nexample : (a :: as) ++ bs = a :: (as ++ bs) := cons_append a as bs\n-- end: List\n\n\n-- textbook: append_nil'\ntheorem append_nil' : as ++ [] = as := by\n  induction as with\n  | nil => rw [nil_append]\n  | cons a as ih => rw [cons_append, ih]\n-- end: append_nil'\n\n\n-- textbook: append_assoc'\ntheorem append_assoc' : as ++ bs ++ cs = as ++ (bs ++ cs) := by\n  induction as with\n  | nil => rw [nil_append, nil_append]\n  | cons a as ih => rw [cons_append, cons_append, ih, ←cons_append]\n-- end: append_assoc'\n\n\n-- textbook: reverse\ntheorem reverse_def : reverse as = reverseAux as [] := rfl\n\ntheorem reverseAux_nil : reverseAux [] as = as := rfl\n\ntheorem reverseAux_cons : reverseAux (a :: as) bs = reverseAux as (a :: bs) := rfl\n-- end: reverse\n\ntheorem reverse_nil : reverse ([] : List α) = [] := rfl\n\n\n-- textbook: reverse identities\ntheorem reverseAux_append : reverseAux (as ++ bs) cs = reverseAux bs (reverseAux as cs) := by\n  induction as generalizing cs with\n  | nil => rw [nil_append, reverseAux_nil]\n  | cons a as ih => rw [cons_append, reverseAux_cons, reverseAux_cons, ih]\n\ntheorem reverseAux_append' : reverseAux as (bs ++ cs) = reverseAux as bs ++ cs := by\n  induction as generalizing bs with\n  | nil => rw [reverseAux_nil, reverseAux_nil]\n  | cons a as ih => rw [reverseAux_cons, reverseAux_cons, ←cons_append, ih]\n-- end: reverse identities\n\n\n-- textbook: reverse_append\ntheorem reverse_append : reverse (as ++ bs) = reverse bs ++ reverse as := by\n  rw [reverse_def, reverseAux_append, reverse_def, ←reverseAux_append', nil_append,\n      reverse_def]\n-- end: reverse_append", "meta": {"author": "avigad", "repo": "lamr", "sha": "b2795a17fb01b7e45aaa1940d4c4200f46800e16", "save_path": "github-repos/lean/avigad-lamr", "path": "github-repos/lean/avigad-lamr/lamr-b2795a17fb01b7e45aaa1940d4c4200f46800e16/LAMR/Examples/using_lean_as_a_proof_assistant/examples4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7717161016280972}}
{"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\nimport linear_algebra.matrix.nonsingular_inverse\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 × 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\nopen_locale matrix\n\nvariables {l R : Type*}\n\nnamespace matrix\n\nvariables (l) [decidable_eq l] (R) [comm_ring R]\n\nsection J_matrix_lemmas\n\n/-- The matrix defining the canonical skew-symmetric bilinear form. -/\ndef J : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 0 (-1) 1 0\n\n@[simp] lemma J_transpose : (J l R)ᵀ = - (J l R) :=\nbegin\n  rw [J, from_blocks_transpose, ←neg_one_smul R (from_blocks _ _ _ _), from_blocks_smul,\n    matrix.transpose_zero, matrix.transpose_one, transpose_neg],\n  simp [from_blocks],\nend\n\nvariables [fintype l]\n\nlemma J_squared : (J l R) ⬝ (J l R) = -1 :=\nbegin\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 [← neg_zero, ← matrix.from_blocks_neg, ← from_blocks_one],\nend\n\nlemma J_inv : (J l R)⁻¹ = -(J l R) :=\nbegin\n  refine matrix.inv_eq_right_inv _,\n  rw [matrix.mul_neg, J_squared],\n  exact neg_neg 1,\nend\n\nlemma J_det_mul_J_det : (det (J l R)) * (det (J l R)) = 1 :=\nbegin\n  rw [←det_mul, J_squared],\n  rw [←one_smul R (-1 : matrix _ _ R)],\n  rw [smul_neg, ←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 _\nend\n\nlemma is_unit_det_J : is_unit (det (J l R)) :=\nis_unit_iff_exists_inv.mpr ⟨det (J l R), J_det_mul_J_det _ _⟩\n\nend J_matrix_lemmas\n\nvariable [fintype l]\n\n/-- The group of symplectic matrices over a ring `R`. -/\ndef symplectic_group : submonoid (matrix (l ⊕ l) (l ⊕ l)  R) :=\n{ carrier := { A | A ⬝ (J l R) ⬝ Aᵀ = J l R},\n  mul_mem' :=\n  begin\n    intros a b ha hb,\n    simp only [mul_eq_mul, set.mem_set_of_eq, transpose_mul] at *,\n    rw [←matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb],\n    exact ha,\n  end,\n  one_mem' := by simp }\n\nend matrix\n\nnamespace symplectic_group\n\nvariables {l} {R} [decidable_eq l] [fintype l] [comm_ring R]\n\nopen matrix\n\nlemma mem_iff {A : matrix (l ⊕ l) (l ⊕ l)  R} :\n  A ∈ symplectic_group l R ↔ A ⬝ (J l R) ⬝ Aᵀ = J l R :=\nby simp [symplectic_group]\n\ninstance coe_matrix : has_coe (symplectic_group l R) (matrix (l ⊕ l) (l ⊕ l)  R)\n:= by apply_instance\n\nsection symplectic_J\n\nvariables (l) (R)\n\nlemma J_mem : (J l R) ∈ symplectic_group l R :=\nbegin\n  rw [mem_iff, J, from_blocks_multiply, from_blocks_transpose, from_blocks_multiply],\n  simp,\nend\n\n/-- The canonical skew-symmetric matrix as an element in the symplectic group. -/\ndef sym_J : symplectic_group l R := ⟨J l R, J_mem l R⟩\n\nvariables {l} {R}\n\n@[simp] lemma coe_J : ↑(sym_J l R) = J l R := rfl\n\nend symplectic_J\n\nvariables {R} {A : matrix (l ⊕ l) (l ⊕ l) R}\n\nlemma neg_mem (h : A ∈ symplectic_group l R) : -A ∈ symplectic_group l R :=\nbegin\n  rw mem_iff at h ⊢,\n  simp [h],\nend\n\nlemma symplectic_det (hA : A ∈ symplectic_group l R) : is_unit $ det A :=\nbegin\n  rw is_unit_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,\nend\n\nlemma transpose_mem (hA : A ∈ symplectic_group l R) :\n  Aᵀ ∈ symplectic_group l R :=\nbegin\n  rw mem_iff at ⊢ hA,\n  rw transpose_transpose,\n  have huA := symplectic_det hA,\n  have huAT : is_unit (Aᵀ).det :=\n  begin\n    rw matrix.det_transpose,\n    exact huA,\n  end,\n  calc Aᵀ ⬝ J l R ⬝ A\n      = - Aᵀ ⬝ (J l R)⁻¹ ⬝ A  : by {rw J_inv, simp}\n  ... = - Aᵀ ⬝ (A ⬝ J l R ⬝ Aᵀ)⁻¹ ⬝ A : by rw hA\n  ... = - (Aᵀ ⬝ (Aᵀ⁻¹ ⬝ (J l R)⁻¹)) ⬝ A⁻¹ ⬝ A : by simp only [matrix.mul_inv_rev,\n                                                              matrix.mul_assoc, matrix.neg_mul]\n  ... = - (J l R)⁻¹ : by rw [mul_nonsing_inv_cancel_left _ _ huAT,\n                             nonsing_inv_mul_cancel_right _ _ huA]\n  ... = (J l R) : by simp [J_inv]\nend\n\n@[simp] lemma transpose_mem_iff : Aᵀ ∈ symplectic_group l R ↔ A ∈ symplectic_group l R :=\n⟨λ hA, by simpa using transpose_mem hA , transpose_mem⟩\n\nlemma mem_iff' : A ∈ symplectic_group l R ↔ Aᵀ ⬝ (J l R) ⬝ A = J l R :=\nby rw [←transpose_mem_iff, mem_iff, transpose_transpose]\n\ninstance : has_inv (symplectic_group l R) :=\n{ inv := λ A, ⟨- (J l R) ⬝ (A : matrix (l ⊕ l) (l ⊕ l) R)ᵀ ⬝ (J l R),\n  mul_mem (mul_mem (neg_mem $ J_mem _ _) $ transpose_mem A.2) $ J_mem _ _⟩ }\n\nlemma coe_inv (A : symplectic_group l R) :\n  (↑(A⁻¹) : matrix _ _ _) = - J l R ⬝ (↑A)ᵀ ⬝ J l R := rfl\n\nlemma inv_left_mul_aux (hA : A ∈ symplectic_group l R) :\n  -(J l R ⬝ Aᵀ ⬝ J l R ⬝ A) = 1 :=\ncalc -(J l R ⬝ Aᵀ ⬝ J l R ⬝ A)\n    = - J l R ⬝ (Aᵀ ⬝ J l R ⬝ A) : by simp only [matrix.mul_assoc, matrix.neg_mul]\n... = - J l R ⬝ J l R : by {rw mem_iff' at hA, rw hA}\n... = (-1 : R) • (J l R ⬝ J l R) : by simp only [matrix.neg_mul, neg_smul, one_smul]\n... = (-1 : R) • -1 : by rw J_squared\n... = 1 : by simp only [neg_smul_neg, one_smul]\n\nlemma coe_inv' (A : symplectic_group l R) : (↑(A⁻¹) : matrix (l ⊕ l) (l ⊕ l) R) = A⁻¹ :=\nbegin\n  refine (coe_inv A).trans (inv_eq_left_inv _).symm,\n  simp [inv_left_mul_aux, coe_inv],\nend\n\nlemma inv_eq_symplectic_inv (A : matrix (l ⊕ l) (l ⊕ l) R) (hA : A ∈ symplectic_group l R) :\n  A⁻¹ = - (J l R) ⬝ Aᵀ ⬝ (J l R) :=\ninv_eq_left_inv (by simp only [matrix.neg_mul, inv_left_mul_aux hA])\n\ninstance : group (symplectic_group l R) :=\n{ mul_left_inv := λ A,\n  begin\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  end,\n  .. symplectic_group.has_inv,\n  .. submonoid.to_monoid _ }\n\nend symplectic_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/linear_algebra/symplectic_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.771696351029207}}
{"text": "/-\nCopyright (c) 2023 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Jujian Zhang\n-/\nimport tactic\n\nimport topology.subset_properties\nimport ring_theory.int.basic\n\n/-!\n# Proof of infinitude of prime numbers using topology\n\nThis file contains an interesting proof of infinitude of prime numbers.\n\nDefine a topology on `ℤ` by declaring a set `U` is open if and only if \nfor every `x ∈ U`, there exists an `1 ≤ m` such that `mk + x ∈ U` for all `k`. \n\nThen one can see that every nonempty open set is infinite and every arithmetic\nprogression `{mk + a | k ∈ ℤ}` is both open and closed where `1 ≤ m`.\n\nThen suppose there are only finitely many prime numbers, then `⋃_p {pk | k ∈ ℤ}`\nis a finite union of arithmetic progression thus closed, so its complement is open.\nHowever, the complement of `⋃_p {pk | k ∈ ℤ}` is precisely `{-1, 1}` which cannot\nbe open because it is nonempty but finite.\n-/\n\nopen topological_space\n\ndef contains_arith_progression (U : set ℤ) : Prop :=\n∀ (x : ℤ), x ∈ U → ∃ (m : ℤ), 1 ≤ m ∧ ∀ (k : ℤ), m * k + x ∈ U\n\nlemma univ_contains_arith_progression : contains_arith_progression set.univ :=\nsorry\n\nlemma inter_contains_arith_progression (s t : set ℤ) \n  (hs : contains_arith_progression s) (ht : contains_arith_progression t) :\n  contains_arith_progression (s ∩ t) := sorry\n\nlemma sUnion_contains_arith_progression (s : set (set ℤ)) \n  (hs : ∀ i ∈ s, contains_arith_progression i) : contains_arith_progression (⋃₀ s) :=\nsorry\n\ninstance weird_top_on_int : topological_space ℤ :=\n{ is_open := contains_arith_progression,\n  is_open_univ := univ_contains_arith_progression,\n  is_open_inter := inter_contains_arith_progression,\n  is_open_sUnion := sUnion_contains_arith_progression }\n\nlemma is_open_iff_weird (s : set ℤ) : is_open s ↔ contains_arith_progression s := iff.rfl\n\nlemma nonempty_open_is_infinite (s : set ℤ) (hs1 : is_open s) (hs2 : s.nonempty) :\n  s.infinite :=\nsorry\n\ndef arith_progression (a m : ℤ) := {z : ℤ | ∃ k, m * k + a = z }\n\nlemma arith_progression_open (a m : ℤ) (hm : 1 ≤ m) : is_open (arith_progression a m) :=\nsorry\n\nlemma arith_progression_closed (a m : ℤ) (hm : 1 ≤ m) : is_closed (arith_progression a m) :=\nsorry\n\nlemma arith_progression_clopen (a m : ℤ) (hm : 1 ≤ m) :\n  is_clopen (arith_progression a m) :=\nsorry\n\nlemma seteq1 : (⋃ (p : ℕ) (hp : nat.prime p), arith_progression 0 p)ᶜ = {1, -1} :=\nsorry\n\nlemma not_closed : ¬ is_closed (⋃ (p : ℕ) (hp : nat.prime p), arith_progression 0 p) :=\nsorry\n\nlemma not_closed' : ¬ is_closed (⋃ (p : set_of nat.prime), arith_progression 0 (p : ℤ)) :=\nsorry\n\nlemma infinite_prime : (set_of nat.prime).infinite :=\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/section10topological_stuffs/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7716782544491678}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si f es una función de ℝ en ℝ tal que \n-- para cada a, existe un x tal que f x < a, entonces f no tiene cota\n-- inferior.  \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\ndef fn_ub (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, f x ≤ a\ndef fn_lb (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, a ≤ f x\n\ndef fn_has_ub (f : ℝ → ℝ) := ∃ a, fn_ub f a\ndef fn_has_lb (f : ℝ → ℝ) := ∃ a, fn_lb f a\n\nvariable f : ℝ → ℝ\n\nexample \n  (h : ∀ a, ∃ x, f x < a) \n  : ¬ fn_has_lb f :=\nbegin\n  intros fnlb,\n  cases fnlb with a fnlba,\n  cases h a with x hx,\n  have : a ≤ f x,\n    from fnlba x,\n  linarith,\nend\n\n-- Prueba\n-- ------\n\n-- f : ℝ → ℝ,\n-- h : ∀ (a : ℝ), ∃ (x : ℝ), f x < a\n-- ⊢ ¬fn_has_lb f\n--    >> intros fnlb,\n-- fnlb : fn_has_lb f\n-- ⊢ false\n--    >> cases fnlb with a fnlba,\n-- a : ℝ,\n-- fnlba : fn_lb f a\n-- ⊢ false\n--    >> cases h a with x hx,\n-- x : ℝ,\n-- hx : f x < a\n-- ⊢ false\n--    >> have : a ≤ f x,\n--    >>   from fnlba x,\n-- this : a ≤ f x\n-- ⊢ false\n--    >> linarith,\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/Funcion_no_acotada_inferiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7716405240352882}}
{"text": "import tactic\nimport data.set.finite\nimport for_mathlib\n\n\n/-\n# Building topological spaces in Lean\n-/\n\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/-\nDefinition of a topological space\n-/\n@[ext]\nclass topological_space (X : Type) :=\n  (is_open : set X → Prop)\n  (univ_mem : is_open univ)\n  (union : ∀ (Y : set (set X)) (h : ∀ B ∈ Y, is_open B), is_open (⋃₀ Y))\n  (inter : ∀ (A B : set X) (hA : is_open A) (hB : is_open B), is_open (A ∩ B))\n\nnamespace topological_space\n\nvariables {X : Type} [topological_space X]\nvariables (A B : set X)\n\n/-- The empty set is open -/\n@[simp]\nlemma is_open_empty : is_open (∅ : set X) :=\nbegin\n  rw ←sUnion_empty,\n  apply union,\n  tauto,\nend\n\n@[simp]\nlemma is_open_univ : is_open (univ : set X) := univ_mem\n\nlemma is_open_inter (h_A: is_open A) (h_B : is_open B) : is_open (A ∩ B) :=\n  inter A B h_A h_B\n\nlemma is_open_sUnion {s : set (set X)} (h : ∀ A ∈ s, is_open A) : is_open (⋃₀ s) :=\n  union s h\n\n/-- The union of two open sets is open -/\nlemma is_open_union {X : Type} [topological_space X] {U V : set X}\n(hU : is_open U) (hV : is_open V): is_open (U ∪ V) :=\nbegin\n  let I : set (set X) := {U, V},\n  have H : ⋃₀ I = U ∪ V := sUnion_pair U V,\n  rw ←H,\n  apply is_open_sUnion,\n  intros B hB,\n  replace hB : B = U ∨ B = V, by tauto,\n  cases hB; {rw hB, assumption},\nend\n\n/-- The intersection of a finite collection of open sets is open -/\nlemma is_open_sInter {X : Type} [topological_space X] {S : set (set X)} (hfin : finite S)\n(h : ∀ s ∈ S, is_open s) : is_open (sInter S) :=\nbegin\n  revert h,\n  apply finite.induction_on hfin,\n  { simp },\n  {\n    intros U S hUS hSfin hind h,\n    have h : ⋂₀ insert U S = (⋂₀ S) ∩ U,\n    {\n      finish,\n    },\n    rw h, \n    apply is_open_inter;\n    finish\n  }\nend\n\nopen set\n\nlemma is_open_bInter {X α: Type} [topological_space X] {ι : α → set X } (S : set α)\n  (hfin : finite S) (h : ∀ s ∈ S, is_open (ι s)) : is_open (⋂ (s ∈ S), ι s) :=\nbegin\n  set Us := ι '' S with hUs,\n  have H : is_open ⋂₀ Us,\n  { apply is_open_sInter,\n    { exact finite.image ι hfin },\n    { finish } },\n  have eqsets : (⋂ (s : α) (H : s ∈ S), ι s) = ⋂₀ Us,\n  { finish },\n  rw eqsets,\n  assumption,\nend\n\n\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 → Prop\n| univ : generated_open univ\n| generating : ∀ A : set X,  A ∈ g → generated_open A\n| sUnion : ∀ τ : set(set X), (∀ t, t ∈ τ → generated_open t) →\n          generated_open ⋃₀ τ \n| inter : ∀ U V : set X,  generated_open U → generated_open V →\n            generated_open (U ∩ V)\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\ndef is_coarser {X : Type} (τ : topological_space X) (τ' : topological_space X) :=\n  ∀ (U : set X), @is_open _ τ U → @is_open _ τ' U\n\n/-- Given topologies τ and τ' on X, we say that τ ≤ τ' iff τ ⊆ τ' (as subsets) -/\ninstance top_has_le {X : Type} : has_le (topological_space X) :=\n  ⟨λ τ τ', (∀ (U : set X), @is_open _ τ U → @is_open _ τ' U)⟩\n\n/-- The topology generated from a collection of sets is the coarsest topology\n  that contains those sets -/\nlemma generated_open_is_coarsest {X : Type} (g : set (set X)) [τ : topological_space X]\n(h : ∀ U ∈ g,  is_open U) : (generate_from g) ≤ τ :=\nbegin\n  intros U hU,\n  induction hU,\n  { exact is_open_univ },\n  { apply h, assumption },\n  { apply is_open_sUnion; assumption },\n  { apply is_open_inter; assumption },\nend\n\nend topological_space\n\n\n\nnamespace topological_space\n\n@[simp] def is_closed {X : Type} [topological_space X] := λ (C : set X), @is_open X _ (compl C)\n\ndef mk_closed_sets\n  (X : Type)\n  (σ : set (set X))\n  (empty_mem : ∅ ∈ σ)\n  (inter : ∀ B ⊆ σ, ⋂₀ B ∈ σ)\n  (union : ∀ (A B ∈ σ), A ∪ B ∈ σ) :\ntopological_space X := {\n  is_open :=  λ U, compl U ∈ σ,\n  univ_mem := by simpa,\n  union := \n  begin\n    intros Y hY,\n    rw compl_sUnion,\n    apply inter (compl '' Y),\n    simpa using hY,\n  end,\n  inter := \n  begin\n    intros A B hA hB,\n    rw compl_inter,\n    exact union (compl A) (compl B) hA hB,\n  end\n  }\n\nend topological_space\n\nnamespace topological_space\nvariables {X : Type} [topological_space X]\nvariables (A B : set X)\nopen set\n\ndef is_neighborhood (x : X) := ∃ U, is_open U ∧ x ∈ U ∧ U ⊆ A\n\ndef interior := { x : X | is_neighborhood A x }\n\n@[simp] lemma interior_subset_self : interior A ⊆ A :=\nbegin\n  rintros x ⟨_, _⟩,\n  tauto,\nend\n\n\nlemma interior_def' : interior A = ⋃₀ {U : set X | is_open U ∧ U ⊆ A} :=\nbegin\n  simp only [interior, is_neighborhood, sUnion],\n  ext,\n  norm_num,\n  tauto,\nend\n\n/--The interior of a set is open.-/\n@[simp] lemma interior_is_open : is_open (interior A) :=\nbegin\n  rw interior_def',\n  apply union,\n  rintros B ⟨is_open_B, _⟩,\n  exact is_open_B,\nend\n\nlemma interior_maximal (hB : is_open B) (h: B ⊆ A ):  B ⊆ interior A  :=\nbegin\n  intros x x_in_B,\n  rw interior_def',\n  use B,\n  exact ⟨⟨hB, h⟩, x_in_B⟩,\nend\n\n/-- The interior of a set is the biggest open it contains. -/\nlemma interior_is_biggest_open (hB : is_open B) : B ⊆ interior A ↔ (B ⊆ A) :=\nbegin\n  split,\n  { have := interior_subset_self A,\n    tauto },\n  {\n    exact interior_maximal A B hB,\n  }\nend \n\n/-These three properties characterize the interior-/\nlemma interior_def'': is_open B ∧ B ⊆ A ∧ (∀ U, U ⊆ A → is_open U → U ⊆ B) ↔ B = interior A :=   \nbegin\n  split,\n  {\n    rintros ⟨is_open_B, ⟨B_subset_A, B_is_biggest_open⟩⟩,\n    apply subset.antisymm,\n    {\n      simpa [interior_is_biggest_open A B is_open_B],\n    },\n    {\n      intros x ha,\n      exact B_is_biggest_open (interior A) (interior_subset_self A) (interior_is_open A) ha,\n    },\n  },\n  {\n    intro,\n    subst B,\n    exact ⟨interior_is_open A, ⟨interior_subset_self A, λ U hUA hU, interior_maximal A U hU hUA⟩⟩,\n  },\nend \n\n@[simp] lemma eq_interior_iff_is_open : A = interior A ↔ is_open A :=\nbegin\n  rw ← interior_def'',\n  tauto,\nend\n\nlemma interior_empty: interior (∅: set X) = ∅ :=\nbegin\n  apply symm,\n  apply (eq_interior_iff_is_open ∅).mpr,\n  simp,\nend\n\nlemma interior_univ: interior (univ: set X) = univ :=\nbegin\n  apply symm,\n  apply (eq_interior_iff_is_open univ).mpr,\n  simp,\nend\n\n-- Can we simplify this proof?\n@[simp] lemma interior_interior: interior (interior A) = interior A :=\nbegin\n  exact ((eq_interior_iff_is_open (interior A)).mpr (interior_is_open A)).symm,\nend\n\n/-- A point x is an adherent point of A if every neighborhood of x intersects A.-/\ndef is_adherent_point (x : X) := ∀ N, is_neighborhood N x → N ∩ A ≠ ∅\n\n/-- The closure of A is the set of all the adherent points of A -/\ndef closure:= {x | is_adherent_point A x}\n\n@[simp] lemma closure_supset_self : A ⊆ closure A :=\nbegin\n  intros x hx,\n  have hhx : is_adherent_point A x,\n  {\n    intros B hBx hn,\n    unfold is_neighborhood at hBx,\n    rcases hBx with ⟨D, hD, h⟩,\n    exact eq_empty_iff_forall_not_mem.mp hn x (mem_inter (h.2 h.1) hx),\n  },\n  exact hhx,\nend\n\n@[simp] lemma closure_eq_compl_of_interior_compl: closure A = (interior Aᶜ)ᶜ :=\nbegin\n  ext1,\n  unfold interior is_neighborhood closure is_adherent_point is_neighborhood,\n  simp only [not_exists, and_imp, not_and, mem_set_of_eq, ne.def, exists_imp_distrib, mem_compl_eq],\n  split,\n  {\n    intros hx U is_open_U x_in_U hU,\n    let hhh := hx Aᶜ U is_open_U x_in_U hU,\n    finish,\n  },\n  {\n    intros hx U V is_open_V x_in_V hV hU,\n    apply hx V is_open_V x_in_V,\n    intros a a_in_V,\n    exact inter_is_not_is_empty_intersection (hV a_in_V) hU,\n  }\nend\n\n\nlemma closure_def' : closure A = ⋂₀ {C : set X | is_closed C ∧ A ⊆ C} :=\nbegin\n  rw [closure_eq_compl_of_interior_compl, interior_def', compl_sUnion],\n  rw compl_image_set_of,\n  simp only [compl_subset_compl, is_closed],\nend\n\n@[simp]\nlemma subset_closed_inclusion_closure [topological_space X] {A B : set X}  (hB : is_closed B) :\n  closure A ⊆ B ↔ A ⊆ B :=\nbegin\n  split,\n  { \n    have := closure_supset_self A,\n    tauto,\n  },\n  {\n    intros h x hx,\n    rw closure_def' at hx,\n    exact hx B ⟨hB, h⟩\n  }\nend\n\nlemma subset_closed_inclusion_closure' [topological_space X] {A B : set X}  (hB : is_closed B) :\n  A ⊆ B → closure A ⊆ B  := (subset_closed_inclusion_closure hB).mpr\n\n-- Not sure if this should be simp lemma. It is now solvable by simp.\n@[simp] lemma closure_is_closed: is_closed (closure A) :=\nbegin\n  simp only [interior_is_open, compl_compl, closure_eq_compl_of_interior_compl, is_closed],\nend\n\n@[simp] lemma eq_closure_iff_is_closed: A = closure A ↔ is_closed A:=\nbegin\n  rw ←compl_inj_iff,\n  simp only [compl_compl, eq_interior_iff_is_open, closure_eq_compl_of_interior_compl, is_closed],\nend\n\n@[simp] lemma closure_closure: closure (closure A) = closure A :=\nbegin\n  simp only [compl_compl, closure_eq_compl_of_interior_compl, interior_interior],\nend\n\nlemma interior_inter: interior (A ∩ B) = interior A ∩ interior B :=\nbegin\n  unfold interior is_neighborhood,\n  ext,\n  simp only [mem_inter_eq, mem_set_of_eq, subset_inter_iff],\n  split,\n  {\n    intro h,\n    obtain ⟨U, h1⟩ :=h,\n    repeat {use U, tauto},\n  },\n  {\n    rintro ⟨ha, hb⟩,\n    obtain ⟨U, ⟨h1,h2,h3⟩⟩ := ha,\n    obtain ⟨V, ⟨g1,g2,g3⟩⟩ := hb,\n    use U ∩ V,\n    repeat {split},\n    { exact inter U V h1 g1 },\n    repeat {tauto},\n    {\n      apply subset.trans _ h3,\n      apply inter_subset_left,\n    },\n    {\n      apply subset.trans _ g3,\n      apply inter_subset_right,\n    }\n  },\nend\n\n\ndef is_open_map {X Y : Type} [topological_space X] [topological_space Y]\n(f : X → Y) :=  ∀ (V : set X), is_open V → is_open (f '' V)\n\ndef is_closed_map {X Y : Type} [topological_space X] [topological_space Y]\n(f : X → Y) :=  ∀ (V : set Y), is_closed V → is_closed (f⁻¹' V)\n\n/-- A function f : X → Y is continuous iff the preimage of every open set is open -/\ndef is_continuous {X Y : Type} [topological_space X] [topological_space Y]\n(f : X → Y) :=  ∀ (V : set Y), is_open V → is_open (f⁻¹' V)\n\n/-- The identity map is continuous. -/\nlemma id_is_cont {X: Type} [topological_space X]: is_continuous (λ x : X, x) :=\nbegin\n  tauto,\nend\n\n/-- The identity map is open. -/\nlemma id_is_open {X: Type} [topological_space X]: is_open_map (λ x : X, x) :=\nbegin\n  intros V hV,\n  finish,\nend\n\n/-- The identity map is closed. -/\nlemma id_is_closed {X: Type} [topological_space X]: is_closed_map (λ x : X, x) :=\nbegin\n  tauto,\nend\n\n/-- The constant map is continuous. -/\nlemma const_is_cont {X Y: Type} [topological_space X] [topological_space Y] (y: Y)\n: is_continuous (λ x : X, y) :=\nbegin\n  intros V hV,\n  by_cases y ∈ V,\n  {\n    convert univ_mem,\n    ext,\n    tauto,\n  },\n  {\n    convert is_open_empty,\n    ext,\n    tauto,\n  },\nend\n\n/-- The composition of continuous maps is continuous. -/\nlemma comp_cont {X Y Z: Type} [topological_space X] [topological_space Y] [topological_space Z]\n(f: X → Y) (hf: is_continuous f) (g: Y → Z) (hg: is_continuous g): is_continuous (g ∘ f) :=\nbegin\n  intros U hU,\n  specialize hg U hU,\n  exact hf _ hg,\nend\n\n/-- The composition of open maps is open. -/\nlemma comp_open {X Y Z: Type} [topological_space X] [topological_space Y] [topological_space Z]\n(f: X → Y) (hf: is_open_map f) (g: Y → Z) (hg: is_open_map g): is_open_map (g ∘ f) :=\nbegin\n  intros U hU,\n  specialize hf U hU,\n  specialize hg _ hf,\n  rw image_image at hg,\n  exact hg,\nend\n\nstructure homeomorph (X Y : Type) [topological_space X] [topological_space Y]\n  extends X ≃ Y :=\n(continuous_to_fun  : is_continuous to_fun)\n(continuous_inv_fun : is_continuous inv_fun) -- is_open_map to_fun\n\nnotation X `≅` Y := homeomorph X Y\n\n -- definir subespai i espai quocient\ndef top_induced (X Y : Type) [topological_space Y] (f : X → Y) : topological_space X :=\n{ is_open := λ A, ∃ V, is_open V ∧ f⁻¹' V = A,\n  univ_mem := ⟨univ,⟨univ_mem,by tauto⟩⟩,\n  union := \n  begin\n    rintros A hA,\n    use ⋃₀{V : set Y | is_open V ∧ f⁻¹' V ∈ A},\n    split,\n    {\n      rw sUnion,\n      apply union,\n      intros B hB,\n      finish,\n    },\n    {\n      rw preimage_sUnion,\n      ext,\n      norm_num,\n      split,\n      { tauto },\n      { rintros ⟨U, hU, hx⟩,\n        specialize hA U hU,\n        rcases hA with ⟨V, hV, hV₂⟩,\n        use V,\n        rw ←hV₂ at hx hU,\n        tauto },\n    },\n  end,\n  inter := \n  begin\n    intros A B hA hB,\n    cases hA with U hU,\n    cases hB with V hV,\n    have h : f ⁻¹' (U ∩ V) = A ∩ B,\n    {\n      rw [← hV.2, ← hU.2],\n      refl,\n    },\n    exact ⟨U ∩ V, inter U V hU.1 hV.1, h⟩,\n  end\n}\n\n/-- La topologia quocient donada per una aplicació f : X → Y -/\ndef top_quotient (X Y : Type) [topological_space X] (f : X → Y) : topological_space Y :=\n{ is_open := λ V, is_open (f⁻¹' V),\n  univ_mem := \n  begin\n    norm_num,\n  end,\n  union := \n  begin\n    intros A hA,\n    rw preimage_sUnion,\n    apply union,\n    rintros U ⟨hU, _⟩,\n    subst U,\n    apply union,\n    rintros B ⟨hB, _⟩,\n    subst B,\n    exact hA hU hB,\n  end,\n  inter :=\n  begin\n    intros A B hA hB,\n    rw preimage_inter,\n    apply inter;\n    assumption,\n  end,\n}\n\n\n\nexample (A B : set X) : A ⊆ B → interior A ⊆ interior B :=\nbegin\n  intro h,\n  apply (interior_is_biggest_open B (interior A) (interior_is_open _)).2,\n  have h':= interior_subset_self A,\n  tauto\nend\n\n\nend topological_space\n\n\n\n-- Lemes previs de Kuratowski clausura i interior preserva inclusió,...\n-- Definició de la banda de Möbius, via quocient i via subespai.\n--  - demostrar que són homeomorfes.\n", "meta": {"author": "mmasdeu", "repo": "barcelonaleanseminar", "sha": "140478080f6680ea5e3ce61e6523272e7e12219f", "save_path": "github-repos/lean/mmasdeu-barcelonaleanseminar", "path": "github-repos/lean/mmasdeu-barcelonaleanseminar/barcelonaleanseminar-140478080f6680ea5e3ce61e6523272e7e12219f/src/topologia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.771640518505779}}
{"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 {α : Type} : list α → list α → list α\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 {α : Type} :\n  ∀as xs : list α, accurev as xs = reverse xs ++ as\n| as []        := by refl\n| as (x :: xs) := by simp [reverse, accurev, accurev_eq_reverse_append _ xs]\n\n/-! 1.2. Derive the desired equation. -/\n\nlemma accurev_eq_reverse {α : Type} (xs : list α) :\n  accurev [] xs = reverse xs :=\nby simp [accurev_eq_reverse_append]\n\n/-! 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {α : Type} (xs : list α) :\n  accurev [] (accurev [] xs) = xs :=\nby simp [accurev_eq_reverse, reverse_reverse]\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 {α : Type} :\n      ∀as xs : list α, 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/-! We perform the proof by structural induction on `xs` (generalizing `as`).\n\nCase `[]`: The goal is `accurev as [] = reverse [] ++ as`. The left-hand side\nis `as` by definition of `accurev`. The right-hand side is `as` by definition\nof `reverse` and `++`.\n\nCase `x :: xs`: The goal is `accurev as (x :: xs) = reverse (x :: xs) ++ as`.\nThe induction hypothesis is `∀as, accurev as xs = reverse xs ++ as`.\n\nLet us simplify the goal's left-hand side:\n\n      accurev as (x :: xs)\n    = accurev (x :: as) xs        -- by definition of `accurev`\n    = reverse xs ++ (x :: as)     -- by the induction hypothesis\n\nNow let us massage the right-hand side so that it matches the simplified\nleft-hand side:\n\n      reverse (x :: xs) ++ as\n    = (reverse xs ++ [x]) ++ as   -- by definition of `reverse`\n    = reverse xs ++ ([x] ++ as)   -- by associativity of `++`\n    = reverse xs ++ (x :: as)     -- by definition of `++`\n\nThe two sides are equal. QED -/\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 {α : Type} : ℕ → list α → list α\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 {α : Type} : ℕ → list α → list α\n| 0       _         := []\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := x :: take m xs\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 {α : Type} :\n  ∀n : ℕ, drop n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\n\n@[simp] lemma take_nil {α : Type} :\n  ∀n : ℕ, take n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\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, `←add_assoc` might be useful. -/\n\nlemma drop_drop {α : Type} :\n  ∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) _ []        := by simp [drop]\n| (m + 1) n (x :: xs) :=\n  by simp [drop, drop_drop m n xs, ←add_assoc]\n\nlemma take_take {α : Type} :\n  ∀(m : ℕ) (xs : list α), 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 {α : Type} :\n  ∀(n : ℕ) (xs : list α), 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/-! ## Question 3: A Type of λ-Terms\n\n3.1. Define an inductive type corresponding to the untyped λ-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- λ-expression (e.g., `λx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\ninductive term : Type\n| var : string → term\n| lam : string → term → term\n| app : term → term → term\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 → string\n| (term.var s)   := s\n| (term.lam s t) := \"(λ\" ++ s ++ \", \" ++ term.repr t ++ \")\"\n| (term.app t u) := \"(\" ++ term.repr t ++ \" \" ++ term.repr u ++ \")\"\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 `(λx, ((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_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8652240877899776, "lm_q1q2_score": 0.7716164007579679}}
{"text": "-- BOTH:\nimport topology.metric_space.basic\n\n/- TEXT:\n.. _proving_facts_about_algebraic_structures:\n\nProving Facts about Algebraic Structures\n----------------------------------------\n\n.. index:: order relation, partial order\n\nIn :numref:`proving_identities_in_algebraic_structures`,\nwe saw that many common identities governing the real numbers hold\nin more general classes of algebraic structures,\nsuch as commutative rings.\nWe can use any axioms we want to describe an algebraic structure,\nnot just equations.\nFor example, a *partial order* consists of a set with a\nbinary relation that is reflexive and transitive,\nlike ``≤`` on the real numbers.\nLean knows about partial orders:\nTEXT. -/\nsection\n-- QUOTE:\nvariables {α : Type*} [partial_order α]\nvariables x y z : α\n\n-- EXAMPLES:\n#check x ≤ y\n#check (le_refl x : x ≤ x)\n#check (le_trans : x ≤ y → y ≤ z → x ≤ z)\n-- QUOTE.\n\n/- TEXT:\nHere we are adopting the mathlib convention of using\nletters like ``α``, ``β``, and ``γ``\n(entered as ``\\a``, ``\\b``, and ``\\g``)\nfor arbitrary types.\nThe library often uses letters like ``R`` and ``G``\nfor the carries of algebraic structures like rings and groups,\nrespectively,\nbut in general Greek letters are used for types,\nespecially when there is little or no structure\nassociated with them.\n\nAssociated to any partial order, ``≤``,\nthere is also a *strict partial order*, ``<``,\nwhich acts somewhat like ``<`` on the real numbers.\nSaying that ``x`` is less than ``y`` in this order\nis equivalent to saying that it is less-than-or-equal to ``y``\nand not equal to ``y``.\nTEXT. -/\n-- QUOTE:\n#check x < y\n#check (lt_irrefl x : ¬ x < x)\n#check (lt_trans : x < y → y < z → x < z)\n#check (lt_of_le_of_lt : x ≤ y → y < z → x < z)\n#check (lt_of_lt_of_le : x < y → y ≤ z → x < z)\n\nexample : x < y ↔ x ≤ y ∧ x ≠ y :=\nlt_iff_le_and_ne\n-- QUOTE.\n\nend\n\n/- TEXT:\nIn this example, the symbol ``∧`` stands for \"and,\"\nthe symbol ``¬`` stands for \"not,\" and\n``x ≠ y`` abbreviates ``¬ (x = y)``.\nIn :numref:`Chapter %s <logic>`, you will learn how to use\nthese logical connectives to *prove* that ``<``\nhas the properties indicated.\n\n.. index:: lattice\n\nA *lattice* is a structure that extends a partial\norder with operations ``⊓`` and ``⊔`` that are\nanalogous to ``min`` and ``max`` on the real numbers:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {α : Type*} [lattice α]\nvariables x y z : α\n\n-- EXAMPLES:\n#check x ⊓ y\n#check (inf_le_left : x ⊓ y ≤ x)\n#check (inf_le_right : x ⊓ y ≤ y)\n#check (le_inf : z ≤ x → z ≤ y → z ≤ x ⊓ y)\n\n#check x ⊔ y\n#check (le_sup_left : x ≤ x ⊔ y)\n#check (le_sup_right: y ≤ x ⊔ y)\n#check (sup_le : x ≤ z → y ≤ z → x ⊔ y ≤ z)\n-- QUOTE.\n\n/- TEXT:\nThe characterizations of ``⊓`` and ``⊔`` justify calling them\nthe *greatest lower bound* and *least upper bound*, respectively.\nYou can type them in VS code using ``\\glb`` and ``\\lub``.\nThe symbols are also often called then *infimum* and\nthe *supremum*,\nand mathlib refers to them as ``inf`` and ``sup`` in\ntheorem names.\nTo further complicate matters,\nthey are also often called *meet* and *join*.\nTherefore, if you work with lattices,\nyou have to keep the following dictionary in mind:\n\n* ``⊓`` is the *greatest lower bound*, *infimum*, or *meet*.\n\n* ``⊔`` is the *least upper bound*, *supremum*, or *join*.\n\nSome instances of lattices include:\n\n* ``min`` and ``max`` on any total order, such as the integers or real numbers with ``≤``\n\n* ``∩`` and ``∪`` on the collection of subsets of some domain, with the ordering ``⊆``\n\n* ``∧`` and ``∨`` on boolean truth values, with ordering ``x ≤ y`` if either ``x`` is false or ``y`` is true\n\n* ``gcd`` and ``lcm`` on the natural numbers (or positive natural numbers), with the divisibility ordering, ``∣``\n\n* the collection of linear subspaces of a vector space,\n  where the greatest lower bound is given by the intersection,\n  the least upper bound is given by the sum of the two spaces,\n  and the ordering is inclusion\n\n* the collection of topologies on a set (or, in Lean, a type),\n  where the greatest lower bound of two topologies consists of\n  the topology that is generated by their union,\n  the least upper bound is their intersection,\n  and the ordering is reverse inclusion\n\nYou can check that, as with ``min`` / ``max`` and ``gcd`` / ``lcm``,\nyou can prove the commutativity and associativity of the infimum and supremum\nusing only their characterizing axioms,\ntogether with ``le_refl`` and ``le_trans``.\nTEXT. -/\n-- QUOTE:\nexample : x ⊓ y = y ⊓ x := sorry\nexample : x ⊓ y ⊓ z = x ⊓ (y ⊓ z) := sorry\nexample : x ⊔ y = y ⊔ x := sorry\nexample : x ⊔ y ⊔ z = x ⊔ (y ⊔ z) := sorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample : x ⊓ y = y ⊓ x :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply le_inf,\n    { apply inf_le_right },\n    apply inf_le_left }\nend\n\nexample : x ⊓ y ⊓ z = x ⊓ (y ⊓ z) :=\nbegin\n  apply le_antisymm,\n  { apply le_inf,\n    { apply le_trans,\n      apply inf_le_left,\n      apply inf_le_left },\n    apply le_inf,\n    { apply le_trans,\n      apply inf_le_left,\n      apply inf_le_right },\n    apply inf_le_right  },\n  apply le_inf,\n  { apply le_inf,\n    { apply inf_le_left },\n    apply le_trans,\n    apply inf_le_right,\n    apply inf_le_left },\n  apply le_trans,\n  apply inf_le_right,\n  apply inf_le_right\nend\n\nexample : x ⊔ y = y ⊔ x :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply sup_le,\n    { apply le_sup_right },\n    apply le_sup_left }\nend\n\nexample : x ⊔ y ⊔ z = x ⊔ (y ⊔ z) :=\nbegin\n  apply le_antisymm,\n  { apply sup_le,\n    { apply sup_le,\n      apply le_sup_left,\n      { apply le_trans,\n        apply @le_sup_left _ _ y z,\n        apply le_sup_right } },\n    apply le_trans,\n    apply @le_sup_right _ _ y z,\n    apply le_sup_right },\n  apply sup_le,\n  { apply le_trans,\n    apply @le_sup_left _ _ x y,\n    apply le_sup_left },\n  apply sup_le,\n  { apply le_trans,\n    apply @le_sup_right _ _ x y,\n    apply le_sup_left },\n  apply le_sup_right\nend\n\n/- TEXT:\nYou can find these theorems in the mathlib as ``inf_comm``, ``inf_assoc``,\n``sup_comm``, and ``sup_assoc``, respectively.\n\nAnother good exercise is to prove the *absorption laws*\nusing only those axioms:\nTEXT. -/\n-- QUOTE:\ntheorem absorb1 : x ⊓ (x ⊔ y) = x := sorry\ntheorem absorb2 : x ⊔ (x ⊓ y) = x := sorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem absorb1αα : x ⊓ (x ⊔ 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\ntheorem absorb2αα : x ⊔ (x ⊓ 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-- BOTH:\nend\n\n/- TEXT:\nThese can be found in mathlib with the names ``inf_sup_self`` and ``sup_inf_self``.\n\nA lattice that satisfies the additional identities\n``x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z)`` and\n``x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z)``\nis called a *distributive lattice*. Lean knows about these too:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {α : Type*} [distrib_lattice α]\nvariables x y z : α\n\n#check (inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z))\n#check (inf_sup_right : (x ⊔ y) ⊓ z = (x ⊓ z) ⊔ (y ⊓ z))\n#check (sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z))\n#check (sup_inf_right : (x ⊓ y) ⊔ z = (x ⊔ z) ⊓ (y ⊔ z))\n-- QUOTE.\n\nend\n\n/- TEXT:\nThe left and right versions are easily shown to be\nequivalent, given the commutativity of ``⊓`` and ``⊔``.\nIt is a good exercise to show that not every lattice\nis distributive\nby providing an explicit description of a\nnondistributive lattice with finitely many elements.\nIt is also a good exercise to show that in any lattice,\neither distributivity law implies the other:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {α : Type*} [lattice α]\nvariables a b c : α\n\n-- EXAMPLES:\nexample (h : ∀ x y z : α, x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z)) :\n  a ⊔ (b ⊓ c) = (a ⊔ b) ⊓ (a ⊔ c) :=\nsorry\n\nexample (h : ∀ x y z : α, x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z)) :\n  a ⊓ (b ⊔ c) = (a ⊓ b) ⊔ (a ⊓ c) :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : ∀ x y z : α, x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z)) :\n  a ⊔ (b ⊓ c) = (a ⊔ b) ⊓ (a ⊔ c) :=\nby rw [h, @inf_comm _ _ (a ⊔ b), absorb1, @inf_comm _ _ (a ⊔ b), h,\n    ←sup_assoc, @inf_comm _ _ c a, absorb2, inf_comm]\n\nexample (h : ∀ x y z : α, x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z)) :\n  a ⊓ (b ⊔ c) = (a ⊓ b) ⊔ (a ⊓ c) :=\nby rw [h, @sup_comm _ _ (a ⊓ b), absorb2, @sup_comm _ _ (a ⊓ b), h,\n    ←inf_assoc, @sup_comm _ _ c a, absorb1, sup_comm]\n\n-- BOTH:\nend\n\n/- TEXT:\nIt is possible to combine axiomatic structures into larger ones.\nFor example, an *ordered ring* consists of a commutative ring together\nwith a partial order on the carrier\nsatisfying additional axioms that say that the ring operations\nare compatible with the order:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {R : Type*} [ordered_ring R]\nvariables a b c : R\n\n-- EXAMPLES:\n#check (add_le_add_left : a ≤ b → ∀ c, c + a ≤ c + b)\n#check (mul_pos : 0 < a → 0 < b → 0 < a * b)\n-- QUOTE.\n\n/- TEXT:\n:numref:`Chapter %s <logic>` will provide the means to derive the following from ``mul_pos``\nand the definition of ``<``:\nTEXT. -/\n-- QUOTE:\n#check (mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b)\n-- QUOTE.\n\n/- TEXT:\nIt is then an extended exercise to show that many common facts\nused to reason about arithmetic and the ordering on the real\nnumbers hold generically for any ordered ring.\nHere are a couple of examples you can try,\nusing only properties of rings, partial orders, and the facts\nenumerated in the last two examples:\nTEXT. -/\n-- QUOTE:\nexample : a ≤ b → 0 ≤ b - a := sorry\n\nexample : 0 ≤ b - a → a ≤ b := sorry\n\nexample (h : a ≤ b) (h' : 0 ≤ c) : a * c ≤ b * c := sorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem aux1 : a ≤ b → 0 ≤ b - a :=\nbegin\n  intro h,\n  rw [←sub_self a, sub_eq_add_neg, sub_eq_add_neg, add_comm, add_comm b],\n  apply add_le_add_left h\nend\n\ntheorem aux2 : 0 ≤ b - a → a ≤ b :=\nbegin\n  intro h,\n  rw [←add_zero a, ←sub_add_cancel b a, add_comm (b - a)],\n  apply add_le_add_left h\nend\n\nexample (h : a ≤ b) (h' : 0 ≤ c) : a * c ≤ b * c :=\nbegin\n  have h1 : 0 ≤ (b - a) * c,\n  { exact mul_nonneg (aux1 _ _ h) h' },\n  rw sub_mul at h1,\n  exact aux2 _ _ h1\nend\n\n-- BOTH:\nend\n\n/- TEXT:\n.. index:: metric space\n\nFinally, here is one last example.\nA *metric space* consists of a set equipped with a notion of\ndistance, ``dist x y``,\nmapping any pair of elements to a real number.\nThe distance function is assumed to satisfy the following axioms:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {X : Type*} [metric_space X]\nvariables x y z : X\n\n-- EXAMPLES:\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 ≤ dist x y + dist y z)\n-- QUOTE.\n\n/- TEXT:\nHaving mastered this section,\nyou can show that it follows from these axioms that distances are\nalways nonnegative:\nTEXT. -/\n-- QUOTE:\nexample (x y : X) : 0 ≤ dist x y := sorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (x y : X) : 0 ≤ dist x y :=\nbegin\n  have : 0 ≤ dist x y + dist y x,\n  { rw [←dist_self x],\n    apply dist_triangle },\n  linarith [dist_comm x y]\nend\n\n-- BOTH:\nend\n\n/- TEXT:\nWe recommend making use of the theorem ``nonneg_of_mul_nonneg_left``.\nAs you may have guessed, this theorem is called ``dist_nonneg`` in mathlib.\nTEXT. -/", "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/02_Basics/source_05_Proving_Facts_about_Algebraic_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.7716163712722631}}
{"text": "/- \n\n# Proposition world. \n\nA Proposition is a true/false statement, like `2 + 2 = 4` or `2 + 2 = 5`.\nJust like we can have concrete sets in Lean like `mynat`, and abstract\nsets called things like `X`, we can also have concrete propositions like\n`2 + 2 = 5` and abstract propositions called things like `P`. \n\nMathematicians are very good at conflating a theorem with its proof.\nThey might say \"now use theorem 12 and we're done\". What they really\nmean is \"now use the proof of theorem 12...\" (i.e. the fact that we proved\nit already). Particularly problematic is the fact that mathematicians\nuse the word Proposition to mean \"a relatively straightforward statement\nwhich is true\" and computer scientists use it to mean \"a statement of\narbitrary complexity, which might be true or false\". Computer scientists\nare far more careful about distinguishing between a proposition and a proof.\nFor example: `x + 0 = x` is a proposition, and `add_zero x`\nis its proof. The convention we'll use is capital letters for propositions\nand small letters for proofs. \n\nIn this world you will see the local context in the following kind of state:\n\n```\nP : Prop\np : P\n```\n\nHere `P` is the true/false statement (the statement of proposition), and `p` is its proof.\nIt's like `P` being the set and `p` being the element. In fact computer scientists\nsometimes think about the following analogy: propositions are like sets,\nand their proofs are like their elements. \n\n## What's going on in this world? \n\nWe're going to learn about manipulating propositions and proofs.\nFortunately, we don't need to learn a bunch of new tactics -- the\nones we just learnt (`exact`, `intro`, `have`, `apply`) will be perfect.\n\nThe levels in proposition world are \"back to normal\", we're proving\ntheorems, not constructing elements of sets. Or are we?\n\nIf you delete the sorry below then your local context will look like this:\n\n```\nP Q : Prop,\np : P,\nh : P → Q\n⊢ Q\n```\n\nIn this situation, we have true/false statements $P$ and $Q$,\na proof $p$ of $P$, and $h$ is the hypothesis that $P\\implies Q$.\nOur goal is to construct a proof of $Q$. It's clear what to do\n*mathematically* to solve this goal, $P$ is true and $P$ implies $Q$\nso $Q$ is true. But how to do it in Lean?\n\nAdopting a point of view wholly unfamiliar to many mathematicians,\nLean interprets the hypothesis $h$ as a function from proofs\nof $P$ to proofs of $Q$, so the rather surprising approach\n\n`exact h(p),`\n\nworks to close the goal.\n\nNote that `exact h(P),` (with a capital P) won't work;\nthis is a common error I see from beginners. \"We're trying to solve `P`\nso it's exactly `P`\". The goal states the *theorem*, your job is to\nconstruct the *proof*. $P$ is not a proof of $P$, it's $p$ that is a proof of $P$. \n\nIn Lean, Propositions, like sets, are types, and proofs, like elements of sets, are terms.\n\n## Level 1: the `exact` tactic.\n-/\n\n/- Lemma : no-side-bar\nIf $P$ is true, and $P\\implies Q$ is also true, then $Q$ is true.\n-/\nexample (P Q : Prop) (p : P) (h : P → Q) : Q :=\nbegin\nexact h(p),\n\n\n\nend \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/world6/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7715717927835085}}
{"text": "-- Monotonia_de_la_suma_por_la_izquierda.lean\n-- Monotonía de la suma por la izquierda\n-- José A. Alonso Jiménez\n-- Sevilla, 14 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si a, b y c son números reles tales que \n-- a ≤ b, entonces c + a ≤ c + b.\n--\n-- Indicación: Se puede usar el lema\n--    sub_nonneg : 0 ≤ a - b ↔ b ≤ a \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nvariables {a b c : ℝ}\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  have h : (c + b) - (c + a) = b - a, \n  { ring, },  \n  { rw h, \n    rw sub_nonneg,\n    exact hab, },\nend\n\n-- Comentario: Se ha usado el lema\n-- + sub_nonneg : 0 ≤ a - b ↔ b ≤ a \n\n-- 2ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  calc 0   ≤ b - a           : by exact sub_nonneg.mpr hab\n       ... = c + b - (c + a) : by exact (add_sub_add_left_eq_sub b a c).symm, \nend\n\n-- Comentario: Se usa el lema\n-- + add_sub_add_left_eq_sub : c + a - (c + b) = a - b \n\n-- 3ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  calc 0   ≤ b - a           : sub_nonneg.mpr hab\n       ... = c + b - (c + a) : (add_sub_add_left_eq_sub b a c).symm, \nend\n\n-- 4ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  calc 0   ≤ b - a           : sub_nonneg.mpr hab\n       ... = c + b - (c + a) : by ring\nend\n\n-- 5ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  simp,\n  exact hab,\nend\n\n-- 6ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  simp [hab],\nend\n\n-- Comentario: \n-- + La táctica (simp [h]) aplica reglas de simplificación, ampliadas con\n--   h, a la conclusión. \n\n-- 7ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  simp [hab],\nend\n\n-- 8ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nby simp [hab]\n\n-- 9ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nadd_le_add_left hab c\n\n-- Comentario: Se ha usado el lema\n-- + add_le_add_left : a ≤ b → ∀ (c : ℝ), c + a ≤ c + b \n\n-- 10ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nby linarith\n\n-- 11ª demostración\n-- ===============\n\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\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_izquierda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8774767970940975, "lm_q1q2_score": 0.7714308925083591}}
{"text": "-- Pruebas por inducción 1: 0 + n = n\n-- ==================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Sean m y n números naturales. Demostrar que\n--    m + 0 = m\n-- ----------------------------------------------------\n\nimport tactic\n\nopen nat\n\nvariables (m n : ℕ)\n\n-- 1ª demostración\nexample : m + 0 = m :=\nnat.add_zero m\n\n-- 2ª demostración\nexample : m + 0 = m :=\nrfl\n\n-- ----------------------------------------------------\n-- Ej. 2. Sean m y n números naturales. Demostrar que\n--    m + (n + 1) = (m + n) + 1\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : m + (n + 1) = (m + n) + 1 :=\nadd_succ m n\n\n-- 2ª demostración\nexample : m + (n + 1) = (m + n) + 1 :=\nrfl\n\n-- ----------------------------------------------------\n-- Ej. 3. Sean n un número natural. Demostrar que\n--    0 + n = n\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : 0 + n = n :=\nbegin\n  induction n with n HI,\n  { rw nat.add_zero, },\n  { rw add_succ,\n    rw HI, },\nend\n\n-- 2ª demostración\nexample : 0 + n = n :=\nbegin\n  induction n with n HI,\n  { rw nat.add_zero, },\n  { rw [add_succ, HI], },\nend\n\n-- 3ª demostración\nexample : 0 + n = n :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { simp [add_succ, HI], },\nend\n\n-- 4ª demostración\nexample : 0 + n = n :=\nbegin\n  induction n with n HI,\n  { simp only [nat.add_zero], },\n  { simp only [add_succ, HI], },\nend\n\n-- 5ª demostración\nexample : 0 + n = n :=\nby induction n;\n   simp only [*,\n              nat.add_zero,\n              add_succ]\n\n-- 6ª demostración\nexample : 0 + n = n :=\nby induction n;\n   simp\n\n-- 7ª demostración\nexample : 0 + n = n :=\nnat.rec_on n\n  ( show 0 + 0 = 0, from nat.add_zero 0)\n  ( assume n,\n    assume HI : 0 + n = n,\n    show 0 + succ n = succ n, from\n      calc\n        0 + succ n = succ (0 + n) : by rw add_succ\n               ... = succ n       : by rw HI)\n\n-- 8ª demostración\nexample : 0 + n = n :=\nnat.rec_on n\n  ( show 0 + 0 = 0, from rfl)\n  ( assume n,\n    assume HI : 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 HI)\n\n-- 9ª demostración\nexample : 0 + n = n :=\nnat.rec_on n rfl (λ n HI, by rw [add_succ, HI])\n\n-- 10ª demostración\nexample : 0 + n = n :=\nnat.rec_on n rfl (λ n HI, by simp only [add_succ, HI])\n\n-- 11ª demostración\nexample : 0 + n = n :=\n-- by library_search\nzero_add n\n\n-- 12ª demostración\nexample : 0 + n = n :=\n-- by hint\nby simp\n\n-- 13ª demostración\nexample : 0 + n = n :=\nby finish\n\n-- 14ª demostración\nexample : 0 + n = n :=\nby linarith\n\n-- 15ª demostración\nexample : 0 + n = n :=\nby nlinarith\n\n-- 16ª demostración\nexample : 0 + n = n :=\nby norm_num\n\n-- 17ª demostración\nexample : 0 + n = n :=\nby ring\n\n-- 18ª demostración\nexample : 0 + n = n :=\nby omega\n\n-- 19ª demostración\nexample : 0 + n = n :=\nby tidy\n\n-- 20ª demostración\nexample : 0 + n = n :=\n-- by tidy ?\nby simp at *\n\n-- 21ª demostración\nlemma cero_mas : ∀ n : ℕ, 0 + n = n\n| 0     := rfl\n| (n+1) := congr_arg succ (cero_mas n)\n\n-- 22ª demostración\nlemma cero_mas2 : ∀ n : ℕ, 0 + n = n\n| 0     := by simp\n| (n+1) := by simp\n\n-- 23ª demostración\nlemma cero_mas3 : ∀ n : ℕ, 0 + n = n\n| 0     := by simp only [add_zero]\n| (n+1) := by simp only [add_zero, add_succ, cero_mas3 n]\n\n-- 24ª demostración\nlemma cero_mas4 : ∀ n : ℕ, 0 + n = n\n| 0     := by rw [add_zero]\n| (n+1) := by rw [add_succ, cero_mas4 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/6_Naturales/Prueba_por_induccion_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.7713906049589342}}
{"text": "import tactic.ring\nimport data.real.basic\nimport algebra.parity\n\nexample (x y : ℕ) : x + y = y + x := by ring\nexample (x y : ℕ) : x + y + y = 2 * y + x := by ring\nexample (x y : ℕ) : x + id y = y + id x := by ring!\nexample {α} [comm_ring α] (x y : α) : x + y + y - x = 2 * y := by ring\nexample (x y : ℚ) : x / 2 + x / 2 = x := by ring\nexample (x y : ℚ) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring\nexample (x y : ℝ) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring\nexample {α} [comm_semiring α] (x : α) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 15000 {ring}\nexample (n : ℕ) : (n / 2) + (n / 2) = 2 * (n / 2) := by ring\nexample {α} [field α] [char_zero α] (a : α) : a / 2 = a / 2 := by ring\nexample {α} [linear_ordered_field α] (a b c : α) :\n  a * (-c / b) * (-c / b) + -c + c = a * (c / b * (c / b)) := by ring\nexample {α} [linear_ordered_field α] (a b c : α) :\n  b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring\nexample (x : ℚ) : x ^ (2 + 2) = x^4 := by ring_nf -- TODO: ring should work?\nexample {α} [comm_ring α] (x : α) : x ^ 2 = x * x := by ring\nexample {α} [linear_ordered_field α] (a b c : α) :\n  b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring\nexample {α} [linear_ordered_field α] (a b c : α) :\n  b ^ 2 - 4 * a * c = 4 * a * 0 + b * b - 4 * a * c := by ring\nexample {α} [comm_semiring α] (x y z : α) (n : ℕ) :\n  (x + y) * (z * (y * y) + (x * x ^ n + (1 + ↑n) * x ^ n * y)) =\n    x * (x * x ^ n) + ((2 + ↑n) * (x * x ^ n) * y + (x * z + (z * y + (1 + ↑n) * x ^ n)) * (y * y)) := by ring\nexample {α} [comm_ring α] (a b c d e : α) :\n  (-(a * b) + c + d) * e = (c + (d + -a * b)) * e := by ring\nexample (a n s: ℕ) : a * (n - s) = (n - s) * a := by ring\n\nexample (x y z : ℚ) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :\n  x / (y / z) + y ⁻¹ + 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 : ℚ) (hx : x ≠ 0) (hy : y ≠ 0) :\n  a + b / x - c / x^2 + d / x^3 = a + x⁻¹ * (y * b / y + (d / x - c) / x) :=\nbegin\n  field_simp,\n  ring\nend\n\nexample : (876544 : ℤ) * -1 + (1000000 - 123456) = 0 := by ring\n\nexample (x y : ℝ) (hx : x ≠ 0) (hy : y ≠ 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 : ℕ) (H : B * A = 2) : A * B = 2 := by {ring_nf, exact H}\n\nexample (a : ℤ) : odd ((2 * a + 1) ^ 2) :=\nbegin\n  use 2 * a ^ 2 + 2 * a,\n  ring_nf,\nend\n\nexample {x y : ℝ}\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 ⊢,\n  exact hxy\nend\n\nexample {α} [field α] {x y : α}\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 : ℚ} : x * -a = - a * x := by ring_nf\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/ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7713344511200191}}
{"text": "import algebra.field\nimport tactic\n\n/--\nLinear change of variable defined in GTM106,\nalso viewed as a matrix\n```\nu^2   0   r\nu^2*s u^3 t\n0     0   1\n```\n-/\n@[ext]\nstructure linear_change_of_variable (K : Type*) [field K] :=\nmk :: (u r s t : K) (hu : u ≠ 0)\n\nnamespace linear_change_of_variable\n\n@[simp]\nlemma u_non_zero {K : Type*} [field K]\n(C : linear_change_of_variable K) : C.u ≠ 0 := C.hu\n\n-- ================\n-- Linear change of variables form a group\n-- ================\n\ndef identity (K : Type*) [field K] : linear_change_of_variable K :=\n⟨ 1, 0, 0, 0, by simp ⟩\n\ndef composite {K : Type*} [field K]\n(C C' : linear_change_of_variable K) : linear_change_of_variable K :=\n⟨ C.u*C'.u, C.r*C'.u^2 + C'.r, C'.u*C.s + C'.s,\n  C.t*C'.u^3 + C.r*C'.s*C'.u^2 + C'.t, by simp ⟩\n\nlemma comp_assoc {K : Type*} [field K]\n(C C' C'' : linear_change_of_variable K) : ((C.composite C').composite C'') = (C.composite (C'.composite C'')) :=\nbegin\n  simp [composite, ext_iff],\n  split, { ring, }, split, { ring, }, split, { ring, }, ring,\nend\n\n@[simp]\nlemma id_comp {K : Type*} [field K]\n(C : linear_change_of_variable K) : (identity K).composite C = C :=\nbegin\n  simp [composite, identity, ext_iff],\nend\n\n@[simp]\nlemma comp_id {K : Type*} [field K]\n(C : linear_change_of_variable K) : C.composite (identity K) = C :=\nbegin\n  simp [composite, identity, ext_iff],\nend\n\ndef inverse {K : Type*} [field K]\n(C : linear_change_of_variable K) : linear_change_of_variable K :=\n⟨ 1/C.u, -C.r/C.u^2, -C.s/C.u, (C.r*C.s-C.t)/C.u^3, by simp ⟩\n\n@[simp]\nlemma inv_comp {K : Type*} [field K]\n(C : linear_change_of_variable K) : C.inverse.composite C = identity K :=\nbegin\n  simp [composite, inverse, identity, ext_iff],\n  split, { field_simp, ring, },\n  field_simp [pow_succ], ring,\nend\n\n@[simp]\nlemma comp_inv {K : Type*} [field K]\n(C : linear_change_of_variable K) : C.composite C.inverse = identity K :=\nbegin\n  simp [composite, inverse, identity, ext_iff],\n  split, { field_simp [pow_succ], }, split, { field_simp [mul_comm], },\n  field_simp [pow_succ], ring,\nend\n\ninstance to_group (K : Type*) [field K] : group (linear_change_of_variable K)\n:= ⟨ composite, comp_assoc, identity K, id_comp, comp_id, inverse,\n  (λ C C', C.composite (C'.inverse)), by {\n    intros _ _, simp only [has_mul.mul, mul_one_class.mul],\n  }, inv_comp ⟩\n\nend linear_change_of_variable\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/gtm106/weierstrass_equation/linear_change_of_variable/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7713344500321482}}
{"text": "-- Pruebas de la conmutatividad de la intersección\n-- ===============================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    A ∩ B ⊆ B ∩ A\n-- ----------------------------------------------------\n\nimport data.set\n\nvariable  {U : Type}\nvariables A B : set U\nvariable  x : U\n\nopen set\n\n-- 1ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  intros x h,\n  simp at *,\n  split,\n  { exact h.right, },\n  { exact h.left,  },\nend\n\n-- 2ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  intros x h,\n  split,\n  { exact h.right, },\n  { exact h.left,  },\nend\n\n-- 3ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  rintros x ⟨h1, h2⟩,\n  split,\n  { exact h2, },\n  { exact h1, },\nend\n\n-- 4ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  rintros x ⟨h1, h2⟩,\n  exact ⟨h2, h1⟩,\nend\n\n-- 5ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nhave h1 : x ∈ A, from and.left h,\nhave h2 : x ∈ B, from and.right h,\nshow x ∈ B ∩ A,  from and.intro h2 h1\n\n-- 6ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nhave h1 : x ∈ A ∧ x ∈ B, from h,\nhave h2 : x ∈ B ∧ x ∈ A, from and.comm.mp h1,\nshow x ∈ B ∩ A,          from h2 \n\n-- 7ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nshow x ∈ B ∩ A, from and.comm.mp h\n\n-- 8ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nand.comm.mp h\n\n-- 9ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nλ h, and.comm.mp h\n\n-- 10ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nand.comm.mp \n\n-- 10ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nλ _, and.comm.mp \n\n-- 11ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\n-- by hint\nby finish\n\n-- 12ª demostración\nlemma aux : A ∩ B ⊆ B ∩ A :=\nby simp\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar\n--    A ∩ B = B ∩ A\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : A ∩ B = B ∩ A :=\nbegin\n  apply eq_of_subset_of_subset,\n  { exact aux A B, },\n  { exact aux B A, },\nend\n\n-- 2ª demostración\nexample : A ∩ B = B ∩ A :=\neq_of_subset_of_subset (aux A B) (aux B A)\n\n-- 3ª demostración\nexample : A ∩ B = B ∩ A :=\n-- by library_search\ninter_comm A B\n\n-- 4ª demostración\nexample : A ∩ B = B ∩ A :=\n-- by hint\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/3_Conjuntos/Pruebas_de_la_conmutatividad_de_la_interseccion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7713344488969891}}
{"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-/\nimport algebra.char_p.basic\nimport ring_theory.ideal.local_ring\nimport algebra.is_prime_pow\nimport 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/-- In a local ring the characteristics is either zero or a prime power. -/\ntheorem char_p_zero_or_prime_power (R : Type*) [comm_ring R] [local_ring R] (q : ℕ)\n  [char_R_q : char_p R q] : q = 0 ∨ is_prime_pow q :=\nbegin\n  /- Assume `q := char(R)` is not zero. -/\n  apply or_iff_not_imp_left.2,\n  intro q_pos,\n  let K := local_ring.residue_field R,\n  haveI RM_char := ring_char.char_p K,\n\n  let r := ring_char K,\n  let n := (q.factorization) r,\n  /- `r := char(R/m)` is either prime or zero: -/\n  cases char_p.char_is_prime_or_zero K r with r_prime r_zero,\n  { 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\n    have rn_dvd_q: r ^ n ∣ q := ⟨a, q_eq_a_mul_rn⟩,\n    rw mul_comm at q_eq_a_mul_rn,\n    have a_dvd_q : a ∣ q := ⟨r ^ n, q_eq_a_mul_rn⟩,\n    /- ... where `a` is a unit. -/\n    have a_unit : is_unit (a : R) :=\n    begin\n      by_contradiction g,\n      rw ←mem_nonunits_iff at g,\n      rw ←local_ring.mem_maximal_ideal at g,\n      have a_cast_zero := (ideal.quotient.eq_zero_iff_mem).2 g,\n      rw map_nat_cast at a_cast_zero,\n      have r_dvd_a := (ring_char.spec K a).1 a_cast_zero,\n      exact absurd r_dvd_a r_ne_dvd_a,\n    end,\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 : ↑(r ^ n) = (0 : R) :=\n    begin\n      rw [nat.cast_pow, ←@mul_one R _ (r ^ n), mul_comm,\n        ←(classical.some_spec a_unit.exists_left_inv), mul_assoc, ←nat.cast_pow, ←nat.cast_mul,\n        ←q_eq_a_mul_rn, char_p.cast_eq_zero R q],\n      simp,\n    end,\n    have q_eq_rn := nat.dvd_antisymm ((char_p.cast_eq_zero_iff R q (r ^ n)).mp rn_cast_zero)\n      rn_dvd_q,\n    have n_pos : n ≠ 0,\n      from λ n_zero, absurd (by simpa [n_zero] using q_eq_rn) (char_p.char_ne_one R q),\n\n    /- Definition of prime power: `∃ r n, prime r ∧ 0 < n ∧ r ^ n = q`. -/\n    exact ⟨r, ⟨n, ⟨r_prime.prime, ⟨pos_iff_ne_zero.mpr n_pos, q_eq_rn.symm⟩⟩⟩⟩},\n  { haveI K_char_p_0 := ring_char.of_eq r_zero,\n    haveI K_char_zero: char_zero K := char_p.char_p_to_char_zero K,\n    haveI R_char_zero := ring_hom.char_zero (local_ring.residue R),\n    /- Finally, `r = 0` would lead to a contradiction: -/\n    have q_zero := char_p.eq R char_R_q (char_p.of_char_zero R),\n    exact absurd q_zero q_pos}\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/char_p/local_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240160063031, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7713153751729874}}
{"text": "/-\nCopyright (c) 2023 Mantas Bakšys, Yaël Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mantas Bakšys, Yaël Dillies\n-/\nimport algebra.big_operators.order\nimport algebra.order.rearrangement\nimport group_theory.perm.cycle.basic\n\n/-!\n# Chebyshev's sum inequality\n\nThis file proves the Chebyshev sum inequality.\n\nChebyshev's inequality states `(∑ i in s, f i) * (∑ i in s, g i) ≤ s.card * ∑ i in s, f i * g i`\nwhen `f g : ι → α` monovary, and the reverse inequality when `f` and `g` antivary.\n\n\n## Main declarations\n\n* `monovary_on.sum_mul_sum_le_card_mul_sum`: Chebyshev's inequality.\n* `antivary_on.card_mul_sum_le_sum_mul_sum`: Chebyshev's inequality, dual version.\n* `sq_sum_le_card_mul_sum_sq`: Special case of Chebyshev's inequality when `f = g`.\n\n## Implementation notes\n\nIn fact, we don't need much compatibility between the addition and multiplication of `α`, 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 function order_dual\nopen_locale big_operators\n\nvariables {ι α β : Type*}\n\n/-! ### Scalar multiplication versions -/\n\nsection smul\nvariables [linear_ordered_ring α] [linear_ordered_add_comm_group β] [module α β]\n  [ordered_smul α β] {s : finset ι} {σ : perm ι} {f : ι → α} {g : ι → β}\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both\nmonotone/antitone), the scalar product of their sum is less than the size of the set times their\nscalar product. -/\nlemma monovary_on.sum_smul_sum_le_card_smul_sum (hfg : monovary_on f g s) :\n  (∑ i in s, f i) • ∑ i in s, g i ≤ s.card • ∑ i in s, f i • g i :=\nbegin\n  classical,\n  obtain ⟨σ, hσ, hs⟩ := s.countable_to_set.exists_cycle_on,\n  rw [←card_range s.card, sum_smul_sum_eq_sum_perm hσ],\n  exact sum_le_card_nsmul _ _ _ (λ n _, hfg.sum_smul_comp_perm_le_sum_smul $ λ x hx, hs $ λ h, hx $\n    is_fixed_pt.perm_pow h _),\nend\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the\nother is antitone), the scalar product of their sum is less than the size of the set times their\nscalar product. -/\nlemma antivary_on.card_smul_sum_le_sum_smul_sum (hfg : antivary_on f g s) :\n  s.card • ∑ i in s, f i • g i ≤ (∑ i in s, f i) • ∑ i in s, g i :=\nby convert hfg.dual_right.sum_smul_sum_le_card_smul_sum\n\nvariables [fintype ι]\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both\nmonotone/antitone), the scalar product of their sum is less than the size of the set times their\nscalar product. -/\nlemma monovary.sum_smul_sum_le_card_smul_sum (hfg : monovary f g) :\n  (∑ i, f i) • ∑ i, g i ≤ fintype.card ι • ∑ i, f i • g i :=\n(hfg.monovary_on _).sum_smul_sum_le_card_smul_sum\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the\nother is antitone), the scalar product of their sum is less than the size of the set times their\nscalar product. -/\nlemma antivary.card_smul_sum_le_sum_smul_sum (hfg : antivary f g) :\n  fintype.card ι • ∑ i, f i • g i ≤ (∑ i, f i) • ∑ i, g i :=\nby convert (hfg.dual_right.monovary_on _).sum_smul_sum_le_card_smul_sum\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 α] {s : finset ι} {σ : perm ι} {f g : ι → α}\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both\nmonotone/antitone), the product of their sum is less than the size of the set times their scalar\nproduct. -/\nlemma monovary_on.sum_mul_sum_le_card_mul_sum (hfg : monovary_on f g s) :\n  (∑ i in s, f i) * (∑ i in s, g i) ≤ s.card * ∑ i in s, f i * g i :=\nby { rw ←nsmul_eq_mul, exact hfg.sum_smul_sum_le_card_smul_sum }\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the\nother is antitone), the product of their sum is greater than the size of the set times their scalar\nproduct. -/\nlemma antivary_on.card_mul_sum_le_sum_mul_sum (hfg : antivary_on f g s) :\n  (s.card : α) * ∑ i in s, f i * g i ≤ (∑ i in s, f i) * (∑ i in s, g i) :=\nby { rw ←nsmul_eq_mul, exact hfg.card_smul_sum_le_sum_smul_sum }\n\n/-- Special case of **Chebyshev's Sum Inequality** or the **Cauchy-Schwarz Inequality**: The square\nof the sum is less than the size of the set times the sum of the squares. -/\nlemma sq_sum_le_card_mul_sum_sq : (∑ i in s, f i)^2 ≤ s.card * ∑ i in s, f i ^ 2 :=\nby { simp_rw sq, exact (monovary_on_self _ _).sum_mul_sum_le_card_mul_sum }\n\nvariables [fintype ι]\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` monovary together (eg they are both\nmonotone/antitone), the product of their sum is less than the size of the set times their scalar\nproduct. -/\nlemma monovary.sum_mul_sum_le_card_mul_sum (hfg : monovary f g) :\n  (∑ i, f i) * (∑ i, g i) ≤ fintype.card ι * ∑ i, f i * g i :=\n(hfg.monovary_on _).sum_mul_sum_le_card_mul_sum\n\n/-- **Chebyshev's Sum Inequality**: When `f` and `g` antivary together (eg one is monotone, the\nother is antitone), the product of their sum is less than the size of the set times their scalar\nproduct. -/\nlemma antivary.card_mul_sum_le_sum_mul_sum (hfg : antivary f g) :\n  (fintype.card ι : α) * ∑ i, f i * g i ≤ (∑ i, f i) * (∑ i, g i) :=\n(hfg.antivary_on _).card_mul_sum_le_sum_mul_sum\n\nend mul\n\nvariables [linear_ordered_field α] {s : finset ι} {f : ι → α}\n\nlemma sum_div_card_sq_le_sum_sq_div_card :\n  ((∑ i in s, f i) / s.card) ^ 2 ≤ (∑ i in s, f i ^ 2) / s.card :=\nbegin\n  obtain rfl | hs := s.eq_empty_or_nonempty,\n  { simp },\n  rw [←card_pos, ←@nat.cast_pos α] at hs,\n  rw [div_pow, div_le_div_iff (sq_pos_of_ne_zero _ hs.ne') hs, sq (s.card : α), mul_left_comm,\n    ←mul_assoc],\n  exact mul_le_mul_of_nonneg_right (sq_sum_le_card_mul_sum_sq) hs.le,\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/chebyshev.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7713153709059595}}
{"text": "/- LoVe Exercise 3: Structured Proofs and Proof Terms -/\n\nimport .lovelib\n\nnamespace LoVe\n\n\n/- Question 1: Chain of Equalities -/\n\n/- 1.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 `rw`, `simp`, `ac_refl`, and the lemmas `mul_add`,\n`add_mul`, and `two_mul`. -/\n\nlemma binomial_square (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\ncalc (a + b) * (a + b) = a * (a + b) + b * (a + b) :\n  by simp [add_mul]\n... = a * a + a * b + b * a + b * b :\n  by simp [mul_add]\n... = a * a + a * b + a * b + b * b :\n  by ac_refl\n... = a * a + 2 * a * b + b * b :\n  by simp [two_mul, add_mul]; ac_refl\n\n/- 1.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₂ (a b : ℕ) :\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  by simp [add_mul],\nhave h2 : a * (a + b) + b * (a + b) = a * a + a * b + b * a + b * b :=\n  by simp [mul_add],\nhave h3 : a * a + a * b + b * a + b * b = a * a + a * b + a * b + b * b :=\n  by ac_refl,\nhave h4 : a * a + a * b + a * b + b * b = a * a + 2 * a * b + b * b :=\n  by simp [two_mul, add_mul]; ac_refl,\nshow _,\n  by rw [h1, h2, h3, h4]\n\n/- 1.3 (**optional**). Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square₃ (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  simp [add_mul, mul_add, two_mul],\n  ac_refl\nend\n\n\n/- Question 2: Connectives and Quantifiers -/\n\n/- 2.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a → a :=\nassume ha,\nshow a, from ha\n\nlemma K (a b : Prop) :\n  a → b → b :=\nassume ha hb,\nshow b, from hb\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nassume hg hb ha,\nshow c, from hg ha hb\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nassume ha ha',\nshow a, from ha\n\n-- please give a different answer than for `proj_1st`\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nassume ha ha',\nshow a, from ha'\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nassume hg ha hf hb,\nhave hc : c := hf ha,\nshow c, from hc\n\n/- 2.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nassume hab hnb ha,\nhave hb : b := hab ha,\nshow false, from hnb hb\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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7713101164035245}}
{"text": "/-\nThe at-least-k boolean function.\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 cardinality.amk\n\nopen assignment clause amk distinct\nopen list nat\n\nvariables {V : Type*} [decidable_eq V] [inhabited V]\n\ndef alk (k : nat) : constraint := λ l, l.count tt ≥ k\n\nnamespace alk\n\n@[simp] theorem eval_zero : ∀ (τ : assignment V) (l : list (literal V)), \n  (alk 0).eval τ l = tt :=\nassume τ l, by simp only [constraint.eval, alk, ge_iff_le, zero_le, to_bool_true_eq_tt]\n\n@[simp] theorem eval_nil_ff_iff_pos {k : nat} :\n  ∀ τ, ((alk k).eval τ ([] : list (literal V)) = ff ↔ k > 0) :=\nassume τ, by simp [constraint.eval, alk, pos_iff_ne_zero]\n\n@[simp] theorem eval_nil_tt_iff_zero {k : nat} :\n  ∀ τ, ((alk k).eval τ ([] : list (literal V)) = tt ↔ k = 0) :=\nassume τ, by simp [constraint.eval, alk]\n\nvariables {k : nat} {τ : assignment V} {lit : literal V} {l : list (literal V)}\n\ntheorem eval_cons_pos : lit.eval τ = tt → \n  ∀ l, (alk (k + 1)).eval τ (lit :: l) = (alk k).eval τ l :=\nassume hlit l, by simp [constraint.eval, alk, hlit, succ_le_succ_iff]\n\ntheorem eval_cons_neg : lit.eval τ = ff → \n  ∀ l, (alk k).eval τ (lit :: l) = (alk k).eval τ l :=\nassume hlit l, \nby simp only [constraint.eval, alk, hlit, map, count_cons_of_ne, ne.def, not_false_iff]\n\n/-\ntheorem eval_tt_of_gt :\n  (alk k).eval τ l = tt → ∀ ⦃j : nat⦄, j < k → (alk j).eval τ l = tt :=\nbegin\n  intros halk j hj,\n  sorry\nend\n-/\n\n-- TODO: supply k as an explicit arg, or ∀ in conclusion\ntheorem eval_take_tail_pos {i : nat} {Hi : i < length l} : \n  (l.nth_le i Hi).eval τ = tt → \n  (alk (k + 1)).eval τ (l.take (i + 1)) = (alk k).eval τ (l.take i) :=\nbegin\n  intro hl,\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, alk] },\n  { rcases exists_cons_of_ne_nil (ne_nil_of_length_pos (pos_of_gt Hi)) with ⟨l₁, ls, rfl⟩,\n    rw nth_le at hl,\n    cases h₁ : l₁.eval τ,\n    { simp only [take, eval_cons_neg h₁, ih hl] },\n    { cases k,\n      { simp [constraint.eval, alk, h₁, succ_le_succ_iff] },\n      { simp [take, eval_cons_pos h₁],\n        exact ih hl } } }\nend\n\ntheorem eval_take_tail_neg {i : nat} {Hi : i < length l} :\n  (l.nth_le i Hi).eval τ = ff →\n  (alk k).eval τ (l.take (i + 1)) = (alk k).eval τ (l.take i) :=\nbegin\n  intro hl,\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, alk] },\n  { rcases exists_cons_of_ne_nil (ne_nil_of_length_pos (pos_of_gt Hi)) with ⟨l₁, ls, rfl⟩,\n    rw nth_le at hl,\n    cases h₁ : l₁.eval τ,\n    { simp [take, eval_cons_neg h₁, ih hl] },\n    { cases k,\n      { simp [take, constraint.eval, alk] },\n      { simp [take, eval_cons_pos h₁, ih hl] } } }\nend\n\ntheorem alo_eval_tt_iff_exists_eval_tt :\n  (alk 1).eval τ l = tt ↔ ∃ {lit : literal V}, lit ∈ l ∧ lit.eval τ = tt :=\nbegin\n  induction l with lit₁ ls ih,\n  { simp only [eval_nil_tt_iff_zero, nat.one_ne_zero, not_mem_nil, false_and, exists_false] },\n  { cases hlit₁ : lit₁.eval τ,\n    { rw eval_cons_neg hlit₁,\n      split,\n      { intro h,\n        rcases ih.mp h with ⟨lit, hmem, heval⟩,\n        exact ⟨lit, mem_cons_of_mem _ hmem, heval⟩ },\n      { rintro ⟨lit, hmem, heval⟩,\n        rcases eq_or_mem_of_mem_cons hmem with (rfl | hmem),\n        { rw hlit₁ at heval, contradiction },\n        { exact ih.mpr ⟨lit, hmem, heval⟩ } } },\n    { split,\n      { intro _, use [lit₁, mem_cons_self _ _, hlit₁] },\n      { intro _, rw eval_cons_pos hlit₁, exact eval_zero τ ls } } }\nend\n\ntheorem amo_take_of_tt {i : nat} (Hi : i < length l) :\n  (l.nth_le i Hi).eval τ = tt → (alk 1).eval τ (l.take (i + 1)) = tt :=\nassume ht, eval_zero τ l ▸ eval_take_tail_pos ht\n\ntheorem alo_take_tail {i : nat} (Hi : i < length l) :\n  (alk 1).eval τ (l.take (i + 1)) = tt →\n  ((l.nth_le i Hi).eval τ = tt ∨ (alk 1).eval τ (l.take i) = tt) :=\nbegin\n  intro hlk,\n  cases hl : (l.nth_le i Hi).eval τ,\n  { rw eval_take_tail_neg hl at hlk,\n    exact or.inr hlk },\n  { exact or.inl rfl }\nend\n\ntheorem eval_tt_of_ge_of_eval_tt {k₁ k₂ : nat} : k₁ ≥ k₂ → \n  (alk k₁).eval τ l = tt → (alk k₂).eval τ l = tt :=\nbegin\n  simp only [constraint.eval, alk, ge_iff_le, to_bool_iff],\n  intros hk h₁,\n  exact le_trans hk h₁\nend\n\ntheorem eval_tt_of_sublist_of_eval_tt {l₁ l₂ : list (literal V)} :\n  l₁ <+ l₂ → (alk k).eval τ l₁ = tt → (alk k).eval τ l₂ = tt :=\nbegin\n  simp [constraint.eval, alk],\n  intros hls h₁,\n  exact le_trans h₁ (sublist.count_le (sublist.map (literal.eval τ) hls) tt)\nend\n\ntheorem eval_take_succ_tt_of_eval_take_tt {i k : nat} :\n  (alk k).eval τ (l.take i) = tt → (alk k).eval τ (l.take (i + 1)) = tt :=\nλ h, eval_tt_of_sublist_of_eval_tt (take_sublist_of_le (le_succ i) l) h\n\ntheorem amk_alk_take {k : nat} {l : list (literal V)} {i : nat} :\n  i ≤ length l → ∀ {τ : assignment V}, (alk k).eval τ (l.take i) = tt →\n  (amk k).eval τ l = tt → (amk 0).eval τ (l.drop i) = tt :=\nbegin\n  intros hi τ htake hamk,\n  induction l with l₁ ls ih generalizing k i,\n  { simp only [drop_eq_nil_of_le, length, zero_le, amk.eval_nil] },\n  { cases i,\n    { simp at htake, subst htake,\n      rw drop,\n      exact hamk },\n    { cases k,\n      { exact eval_drop hamk _ },\n      { rw [length, succ_le_succ_iff] at hi,\n        cases hl₁ : (l₁.eval τ),\n        { rw [take, eval_cons_neg hl₁] at htake,\n          rw amk.eval_cons_neg hl₁ at hamk,\n          exact ih hi htake hamk },\n        { rw [take, eval_cons_pos hl₁] at htake,\n          rw amk.eval_cons_pos hl₁ at hamk,\n          exact ih hi htake hamk } } } }\nend\n\ntheorem amk_eval_eq_alk_succ_eval (k : nat) (τ : assignment V) (l : list (literal V)) :\n  (amk k).eval τ l = !((alk (k + 1)).eval τ l) :=\nbegin\n  induction l with l₁ ls ih generalizing k,\n  { apply symm, simp },\n  { cases h₁ : l₁.eval τ,\n    { rw [amk.eval_cons_neg h₁, alk.eval_cons_neg h₁],\n      exact ih k },\n    { cases k,\n      { rw [amk.eval_cons_pos_zero h₁, alk.eval_cons_pos h₁, eval_zero],\n        exact bool.bnot_tt.symm },\n      { rw [amk.eval_cons_pos h₁, alk.eval_cons_pos h₁],\n        exact ih k } } }\nend\n\ntheorem alk_split {k : nat} {l : list (literal V)} {τ : assignment V} :\n  (alk (k + 1)).eval τ l = tt → ∃ {i : nat} (Hi : i < length l),\n  (amk 0).eval τ (l.take (i - 1)) = tt ∧ (l.nth_le i Hi).eval τ = tt ∧\n  (alk k).eval τ (l.drop (i + 1)) = tt :=\nbegin\n  intro halk,\n  induction l with l₁ ls ih generalizing k,\n  { simp at halk |-, assumption },\n  { cases h₁ : l₁.eval τ,\n    { rw eval_cons_neg h₁ at halk,\n      rcases ih halk with ⟨i, Hi, htake, he, hdrop⟩,\n      use i + 1,\n      simp [Hi, hdrop],\n      cases i,\n      { simpa },\n      { simp at htake, simpa [amk.eval_cons_neg h₁, htake] } },\n    { rw eval_cons_pos h₁ at halk, use 0, simpa [h₁] } }\nend\n\ntheorem alk_of_amk_of_gt {j : nat} {l : list (literal V)} {τ : assignment V} :\n  (amk j).eval τ l = tt → ∀ {k}, j < k → (alk k).eval τ l = ff :=\nbegin\n  induction l with l₁ ls ih generalizing j,\n  { simp, intros k hk, exact pos_of_gt hk },\n  { intros hmk k hk,\n    cases j,\n    { have ihred := ih (amz_of_amz_cons hmk) hk,\n      rw amz_eval_tt_iff_forall_eval_ff at hmk,\n      rw eval_cons_neg (hmk (mem_cons_self _ _)),\n      exact ihred },\n    { cases hl₁ : l₁.eval τ,\n      { rw amk.eval_cons_neg hl₁ at hmk,\n        rw eval_cons_neg hl₁,\n        exact ih hmk hk },\n      { cases k with k,\n        { linarith },\n        { rw amk.eval_cons_pos hl₁ at hmk,\n          rw eval_cons_pos hl₁,\n          exact ih hmk (succ_lt_succ_iff.mp hk) } } } }\nend\n\n-- Since the at-least-one encoding is so simple, we prove it here\nsection direct_alo\n\nopen encoding\n\ndef direct_alo : enc_fn V := λ l g, ⟨[l], g⟩\n\ntheorem direct_alo_is_wb : is_wb (direct_alo : enc_fn V) :=\nbegin\n  intros l g hdis, simp [direct_alo]\nend\n\ntheorem direct_alo_encodes_alo : encodes (alk 1) (direct_alo : enc_fn V) :=\nbegin\n  split,\n  {\n    intros l g hdis τ,\n    rw alo_eval_tt_iff_exists_eval_tt,\n    split,\n    { intro h,\n      use τ, split,\n      { simp [direct_alo, eval_tt_iff_exists_literal_eval_tt, h] },\n      { refl } },\n    {\n      rintro ⟨σ, hs, hagree_on⟩,\n      simp [direct_alo, eval_tt_iff_exists_literal_eval_tt] at hs,\n      rcases hs with ⟨lit, hmem, hlit⟩,\n      rw ← eval_eq_of_agree_on_of_var_mem hagree_on (mem_vars_of_mem hmem) at hlit,\n      exact ⟨lit, hmem, hlit⟩ } },\n  { exact direct_alo_is_wb }\nend\n\nend direct_alo\n\nend alk", "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/alk.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7712929594681959}}
{"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.finset.nat_antidiagonal\n! leanprover-community/mathlib commit cc70d9141824ea8982d1562ce009952f2c3ece30\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.Card\nimport Mathbin.Data.Multiset.NatAntidiagonal\n\n/-!\n# Antidiagonals in ℕ × ℕ as 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 the antidiagonals of ℕ × ℕ 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\n\nnamespace Finset\n\nnamespace Nat\n\n#print Finset.Nat.antidiagonal /-\n/-- The antidiagonal of a natural number `n` is\n    the finset of pairs `(i, j)` such that `i + j = n`. -/\ndef antidiagonal (n : ℕ) : Finset (ℕ × ℕ) :=\n  ⟨Multiset.Nat.antidiagonal n, Multiset.Nat.nodup_antidiagonal n⟩\n#align finset.nat.antidiagonal Finset.Nat.antidiagonal\n-/\n\n#print Finset.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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := by\n  rw [antidiagonal, mem_def, Multiset.Nat.mem_antidiagonal]\n#align finset.nat.mem_antidiagonal Finset.Nat.mem_antidiagonal\n-/\n\n#print Finset.Nat.card_antidiagonal /-\n/-- The cardinality of the antidiagonal of `n` is `n + 1`. -/\n@[simp]\ntheorem card_antidiagonal (n : ℕ) : (antidiagonal n).card = n + 1 := by simp [antidiagonal]\n#align finset.nat.card_antidiagonal Finset.Nat.card_antidiagonal\n-/\n\n#print Finset.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 finset.nat.antidiagonal_zero Finset.Nat.antidiagonal_zero\n-/\n\n#print Finset.Nat.antidiagonal_succ /-\ntheorem antidiagonal_succ (n : ℕ) :\n    antidiagonal (n + 1) =\n      cons (0, n + 1)\n        ((antidiagonal n).map\n          (Function.Embedding.prodMap ⟨Nat.succ, Nat.succ_injective⟩ (Function.Embedding.refl _)))\n        (by simp) :=\n  by\n  apply eq_of_veq\n  rw [cons_val, map_val]\n  · apply Multiset.Nat.antidiagonal_succ\n#align finset.nat.antidiagonal_succ Finset.Nat.antidiagonal_succ\n-/\n\n#print Finset.Nat.antidiagonal_succ' /-\ntheorem antidiagonal_succ' (n : ℕ) :\n    antidiagonal (n + 1) =\n      cons (n + 1, 0)\n        ((antidiagonal n).map\n          (Function.Embedding.prodMap (Function.Embedding.refl _) ⟨Nat.succ, Nat.succ_injective⟩))\n        (by simp) :=\n  by\n  apply eq_of_veq\n  rw [cons_val, map_val]\n  exact Multiset.Nat.antidiagonal_succ'\n#align finset.nat.antidiagonal_succ' Finset.Nat.antidiagonal_succ'\n-/\n\n#print Finset.Nat.antidiagonal_succ_succ' /-\ntheorem antidiagonal_succ_succ' {n : ℕ} :\n    antidiagonal (n + 2) =\n      cons (0, n + 2)\n        (cons (n + 2, 0)\n            ((antidiagonal n).map\n              (Function.Embedding.prodMap ⟨Nat.succ, Nat.succ_injective⟩\n                ⟨Nat.succ, Nat.succ_injective⟩)) <|\n          by simp)\n        (by simp) :=\n  by\n  simp_rw [antidiagonal_succ (n + 1), antidiagonal_succ', Finset.map_cons, map_map]\n  rfl\n#align finset.nat.antidiagonal_succ_succ' Finset.Nat.antidiagonal_succ_succ'\n-/\n\n#print Finset.Nat.map_swap_antidiagonal /-\ntheorem map_swap_antidiagonal {n : ℕ} :\n    (antidiagonal n).map ⟨Prod.swap, Prod.swap_rightInverse.Injective⟩ = antidiagonal n :=\n  eq_of_veq <| by simp [antidiagonal, Multiset.Nat.map_swap_antidiagonal]\n#align finset.nat.map_swap_antidiagonal Finset.Nat.map_swap_antidiagonal\n-/\n\n#print Finset.Nat.antidiagonal_congr /-\n/-- A point in the antidiagonal is determined by its first co-ordinate. -/\ntheorem antidiagonal_congr {n : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)\n    (hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=\n  by\n  refine' ⟨congr_arg Prod.fst, fun h => Prod.ext h ((add_right_inj q.fst).mp _)⟩\n  rw [mem_antidiagonal] at hp hq\n  rw [hq, ← h, hp]\n#align finset.nat.antidiagonal_congr Finset.Nat.antidiagonal_congr\n-/\n\n#print Finset.Nat.antidiagonal.fst_le /-\ntheorem antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) : kl.1 ≤ n :=\n  by\n  rw [le_iff_exists_add]\n  use kl.2\n  rwa [mem_antidiagonal, eq_comm] at hlk\n#align finset.nat.antidiagonal.fst_le Finset.Nat.antidiagonal.fst_le\n-/\n\n#print Finset.Nat.antidiagonal.snd_le /-\ntheorem antidiagonal.snd_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) : kl.2 ≤ n :=\n  by\n  rw [le_iff_exists_add]\n  use kl.1\n  rwa [mem_antidiagonal, eq_comm, add_comm] at hlk\n#align finset.nat.antidiagonal.snd_le Finset.Nat.antidiagonal.snd_le\n-/\n\n/- warning: finset.nat.filter_fst_eq_antidiagonal -> Finset.Nat.filter_fst_eq_antidiagonal is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (m : Nat), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.filter.{0} (Prod.{0, 0} Nat Nat) (fun (x : Prod.{0, 0} Nat Nat) => Eq.{1} Nat (Prod.fst.{0, 0} Nat Nat x) m) (fun (a : Prod.{0, 0} Nat Nat) => Nat.decidableEq (Prod.fst.{0, 0} Nat Nat a) m) (Finset.Nat.antidiagonal n)) (ite.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (LE.le.{0} Nat Nat.hasLe m n) (Nat.decidableLe m n) (Singleton.singleton.{0, 0} (Prod.{0, 0} Nat Nat) (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasSingleton.{0} (Prod.{0, 0} Nat Nat)) (Prod.mk.{0, 0} Nat Nat m (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n m))) (EmptyCollection.emptyCollection.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasEmptyc.{0} (Prod.{0, 0} Nat Nat))))\nbut is expected to have type\n  forall (n : Nat) (m : Nat), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.filter.{0} (Prod.{0, 0} Nat Nat) (fun (x : Prod.{0, 0} Nat Nat) => Eq.{1} Nat (Prod.fst.{0, 0} Nat Nat x) m) (fun (a : Prod.{0, 0} Nat Nat) => instDecidableEqNat (Prod.fst.{0, 0} Nat Nat a) m) (Finset.Nat.antidiagonal n)) (ite.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (LE.le.{0} Nat instLENat m n) (Nat.decLe m n) (Singleton.singleton.{0, 0} (Prod.{0, 0} Nat Nat) (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instSingletonFinset.{0} (Prod.{0, 0} Nat Nat)) (Prod.mk.{0, 0} Nat Nat m (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n m))) (EmptyCollection.emptyCollection.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instEmptyCollectionFinset.{0} (Prod.{0, 0} Nat Nat))))\nCase conversion may be inaccurate. Consider using '#align finset.nat.filter_fst_eq_antidiagonal Finset.Nat.filter_fst_eq_antidiagonalₓ'. -/\ntheorem filter_fst_eq_antidiagonal (n m : ℕ) :\n    filter (fun x : ℕ × ℕ => x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ :=\n  by\n  ext ⟨x, y⟩\n  simp only [mem_filter, nat.mem_antidiagonal]\n  split_ifs with h h\n  · simp (config := { contextual := true }) [and_comm', eq_tsub_iff_add_eq_of_le h, add_comm]\n  · rw [not_le] at h\n    simp only [not_mem_empty, iff_false_iff, not_and]\n    exact fun hn => ne_of_lt (lt_of_le_of_lt (le_self_add.trans hn.le) h)\n#align finset.nat.filter_fst_eq_antidiagonal Finset.Nat.filter_fst_eq_antidiagonal\n\n/- warning: finset.nat.filter_snd_eq_antidiagonal -> Finset.Nat.filter_snd_eq_antidiagonal is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat) (m : Nat), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.filter.{0} (Prod.{0, 0} Nat Nat) (fun (x : Prod.{0, 0} Nat Nat) => Eq.{1} Nat (Prod.snd.{0, 0} Nat Nat x) m) (fun (a : Prod.{0, 0} Nat Nat) => Nat.decidableEq (Prod.snd.{0, 0} Nat Nat a) m) (Finset.Nat.antidiagonal n)) (ite.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (LE.le.{0} Nat Nat.hasLe m n) (Nat.decidableLe m n) (Singleton.singleton.{0, 0} (Prod.{0, 0} Nat Nat) (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasSingleton.{0} (Prod.{0, 0} Nat Nat)) (Prod.mk.{0, 0} Nat Nat (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n m) m)) (EmptyCollection.emptyCollection.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasEmptyc.{0} (Prod.{0, 0} Nat Nat))))\nbut is expected to have type\n  forall (n : Nat) (m : Nat), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.filter.{0} (Prod.{0, 0} Nat Nat) (fun (x : Prod.{0, 0} Nat Nat) => Eq.{1} Nat (Prod.snd.{0, 0} Nat Nat x) m) (fun (a : Prod.{0, 0} Nat Nat) => instDecidableEqNat (Prod.snd.{0, 0} Nat Nat a) m) (Finset.Nat.antidiagonal n)) (ite.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (LE.le.{0} Nat instLENat m n) (Nat.decLe m n) (Singleton.singleton.{0, 0} (Prod.{0, 0} Nat Nat) (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instSingletonFinset.{0} (Prod.{0, 0} Nat Nat)) (Prod.mk.{0, 0} Nat Nat (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n m) m)) (EmptyCollection.emptyCollection.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instEmptyCollectionFinset.{0} (Prod.{0, 0} Nat Nat))))\nCase conversion may be inaccurate. Consider using '#align finset.nat.filter_snd_eq_antidiagonal Finset.Nat.filter_snd_eq_antidiagonalₓ'. -/\ntheorem filter_snd_eq_antidiagonal (n m : ℕ) :\n    filter (fun x : ℕ × ℕ => x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ :=\n  by\n  have : (fun x : ℕ × ℕ => x.snd = m) ∘ Prod.swap = fun x : ℕ × ℕ => x.fst = m :=\n    by\n    ext\n    simp\n  rw [← map_swap_antidiagonal]\n  simp [filter_map, this, filter_fst_eq_antidiagonal, apply_ite (Finset.map _)]\n#align finset.nat.filter_snd_eq_antidiagonal Finset.Nat.filter_snd_eq_antidiagonal\n\nsection EquivProd\n\n#print Finset.Nat.sigmaAntidiagonalEquivProd /-\n/-- The disjoint union of antidiagonals `Σ (n : ℕ), antidiagonal n` is equivalent to the product\n    `ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps]\ndef sigmaAntidiagonalEquivProd : (Σn : ℕ, antidiagonal n) ≃ ℕ × ℕ\n    where\n  toFun x := x.2\n  invFun x := ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩\n  left_inv := by\n    rintro ⟨n, ⟨k, l⟩, h⟩\n    rw [mem_antidiagonal] at h\n    exact Sigma.subtype_ext h rfl\n  right_inv x := rfl\n#align finset.nat.sigma_antidiagonal_equiv_prod Finset.Nat.sigmaAntidiagonalEquivProd\n-/\n\nend EquivProd\n\nend Nat\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/Data/Finset/NatAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7712790595757912}}
{"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`λ + X i` is equal to a linear combination of the symmetric polynomials `esymm σ 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 σ R)`, which enables us to talk about linear combinations of\n`esymm σ 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\nopen_locale big_operators polynomial\n\nopen finset polynomial fintype\n\nnamespace mv_polynomial\n\nvariables {R : Type*} [comm_semiring R]\nvariables (σ : Type*) [fintype σ]\n\n/-- A sum version of Vieta's formula. Viewing `X i` as variables,\nthe product of linear terms `λ + X i` is equal to a linear combination of\nthe symmetric polynomials `esymm σ R j`. -/\nlemma prod_X_add_C_eq_sum_esymm :\n  (∏ i : σ, (polynomial.C (X i) + polynomial.X) : polynomial (mv_polynomial σ R) )=\n  ∑ j in range (card σ + 1),\n    (polynomial.C (esymm σ R j) * polynomial.X ^ (card σ - j)) :=\nbegin\n  classical,\n  rw [prod_add, sum_powerset],\n  refine sum_congr begin congr end (λ j hj, _),\n  rw [esymm, map_sum, sum_mul],\n  refine sum_congr rfl (λ t ht, _),\n  have h : (univ \\ t).card = card σ - j :=\n  by { rw card_sdiff (mem_powerset_len.mp ht).1, congr, exact (mem_powerset_len.mp ht).2 },\n  rw [map_prod, prod_const, ← h],\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 `∑ 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 : σ → R) : ∏ i : σ, (polynomial.C (r i) + polynomial.X) =\n  ∑ i in range (card σ + 1), (∑ t in powerset_len i (univ : finset σ),\n    ∏ i in t, polynomial.C (r i)) * polynomial.X ^ (card σ - i) :=\nbegin\n  classical,\n  have h := @prod_X_add_C_eq_sum_esymm _ _ σ _,\n  apply_fun (polynomial.map (eval r)) at h,\n  rw [polynomial.map_prod, polynomial.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, polynomial.map_sum, map_sum,\n    polynomial.map_C, polynomial.map_pow, polynomial.map_X, polynomial.map_mul],\n  congr,\n  funext,\n  simp only [eval_prod, eval_X, map_prod],\nend\n\nlemma esymm_to_sum (r : σ → R) (j : ℕ) : polynomial.C (eval r (esymm σ R j)) =\n  ∑ t in powerset_len j (univ : finset σ), ∏ i in t, polynomial.C (r i) :=\nby simp only [esymm, eval_sum, eval_prod, eval_X, map_sum, map_prod]\n\n/-- Vieta's formula for the coefficients of the product of linear terms `X + r i`,\nThe `k`th coefficient is `∑ t in powerset_len (card σ - k) (univ : finset σ), ∏ i in t, r i`,\ni.e. the symmetric polynomial `esymm σ R (card σ - k)` of the constant terms `r i`. -/\n\n\nend mv_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/ring_theory/polynomial/vieta.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7712718238430089}}
{"text": "import tactic -- hide\nopen function nat -- hide\n\n/-\n## More on `rw`\n\nWe have seen that the `rw` tactic replaces occurrences of $a$ with $b$ if we have `h : a = b`.\nIf we want to replace the occurrences of $b$ into $a$, we can use the fact that `h.symm` is a proof of\n$b = a$ (and hence do `rw h.symm`) or use `rw ← h` (type `←` with \\l). Try it below.\n-/\n\n/-\n**Pro tip:** In very rare occasions, we might end up with a goal of the form `a = a`, where\n`a` is a very complicated expression. This can be closed with the `refl` tactic (it means\n*reflexivity*).\n-/\n\n/- Symbol:\n← : \\l\n-/\n/- Lemma : no-side-bar\nIf $a = b + c$ and $a = 3$, then $b + c = 3$.\n-/\nlemma l2 (a b c : ℕ) (h1 : a = b + c) (h2 : a = 3): b + c = 3:=\nbegin\n  rw ← h1,\n  assumption,\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/tutorial_world/02_rw.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.8376199673867853, "lm_q1q2_score": 0.7712718219312957}}
{"text": "-- La suma de dos funciones pares es una función par\n-- =================================================\n\nimport data.real.basic\n\nvariables (x y : ℝ)\nvariables (f g : ℝ → ℝ)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la función\n--    par : (ℝ → ℝ) → Prop\n-- tal que (par f) expresa que f es par.\n-- ----------------------------------------------------\n\ndef par (f : ℝ → ℝ) : Prop :=\n∀ x, f (-x) = f x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Definir la función\n--    suma : (ℝ → ℝ) → (ℝ → ℝ) → (ℝ → ℝ)\n-- tal que (suma f g) es la suma de las funciones f y g.\n-- ----------------------------------------------------\n\n@[simp]\ndef suma (f g: ℝ → ℝ) : ℝ → ℝ :=\nλ x, f x + g x\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Demostrar que la suma de funciones\n-- pares es par.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  par f → par g →  par (suma f g) :=\nbegin\n  intro hf,\n  unfold par at hf,\n  intro hg,\n  unfold par at hg,\n  unfold par,\n  intro x,\n  unfold suma,\n  rw hf,\n  rw hg,\nend\n\n-- 2ª demostración\nexample :\n  par f → par g →  par (suma f g) :=\nbegin\n  intros hf hg x,\n  simp [suma],\n  rw [hf, hg],\nend\n\n-- 3ª demostración\nexample :\n  par f → par g →  par (suma f g) :=\nbegin\n  intros hf hg x,\n  unfold suma,\n  rw [hf, hg],\nend\n\n-- 4ª demostración\nexample :\n  par f → par g →  par (suma f g) :=\nbegin\n  intros hf hg x,\n  calc (f + g) (-x)\n       = f (-x) + g (-x) : rfl\n   ... = f x + g (-x)    : by rw hf\n   ... = f x + g x       : by rw hg\n   ... = (f + g) x       : rfl\nend\n\n-- 5ª demostración\nexample :\n  par f → par g →  par (suma f g) :=\nbegin\n  intros hf hg x,\n  calc (f + g) (-x)\n       = f (-x) + g (-x) : rfl\n   ... = f x + g x       : by rw [hf, hg]\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/3_Cuantificadores/La_suma_de_dos_funciones_pares_es_una_funcion_par.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7712718035422361}}
{"text": "/- LoVe Homework 3: Structured Proofs and Proof Terms -/\n\nimport .love02_tactical_proofs_exercise_sheet\n\nnamespace LoVe\n\n\n/- Question 2: Logic Puzzles -/\n\n/- 2.2 (**optional**). Prove the same lemma again, this time by providing a\nproof term.\n\nHint: There is an easy way. -/\n\nlemma weak_peirce₂ :\n  ∀a b : Prop, ((((a → b) → a) → a) → b) → b :=\nλ(a b : Prop) (habaab : (((a → b) → a) → a) → b),\n  habaab (λ(habaa : (a → b) → a),\n    habaa (λ(ha : a), habaab (λ(haba : (a → b) → a), ha)))\n\n/- The easy way is `#print weak_peirce`. There is an even easier way: to use\n`weak_peirce` as the proof of `weak_peirce₂`. -/\n\n/- 2.3 (**optional**). Prove the same lemma again, this time by providing a\nstructured proof. -/\n\nlemma weak_peirce₃ :\n  ∀a b : Prop, ((((a → b) → a) → a) → b) → b :=\nassume (a b : Prop) (habaab : (((a → b) → a) → a) → b),\nshow b, from habaab\n  (assume (habaa : (a → b) → a),\n   show a, from habaa\n     (assume (ha : a),\n      show b, from habaab\n        (assume (haba : (a → b) → a),\n         show a, from ha)))\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_homework_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7712376366677779}}
{"text": "\nopen classical\nattribute [instance] classical.prop_decidable\n\nnamespace logic\n\nlemma of_contrapositive {P Q : Prop} :\n(¬ Q → ¬ P) → (P → Q) :=\nbegin\nintros H hp,\nby_cases hq : Q,\nassumption,\napply absurd hp,\napply H,\nassumption,\nend\n\nlemma of_cases {P Q : Prop} : (P → Q) → (¬ P → Q) → Q :=\nbegin\nintros ht hf,\nby_cases h : P,\napply ht,\nassumption,\napply hf,\nassumption,\nend\n\nlemma resolve_left {P Q : Prop} :\n(¬ Q → P) → P ∨ Q :=\nbegin\nintro H,\nby_cases hq : Q,\nright,\nassumption,\nleft,\napply H,\nassumption,\nend\n\nlemma double_negation {P : Prop} : P → ¬ ¬ P :=\nbegin\nintros h f,\napply f,\nassumption,\nend\n\nlemma resolve_right {P Q : Prop} :\n(¬ P → Q) → P ∨ Q :=\nbegin\nintro H,\nby_cases hp : P,\nleft,\nassumption,\nright,\napply H,\nassumption,\nend\n\nlemma demorgan_and {P Q : Prop} : ¬ P ∨ ¬ Q → ¬ (P ∧ Q) :=\nbegin\nintros K h,\ncases h with hp hq,\ncases K,\napply K,\nassumption,\napply K,\nassumption,\nend\n\nlemma demorgan_exists {α : Sort*} {P : α → Prop} : (∀ x, ¬ P x) → ¬ (∃ x, P x) :=\nbegin\nintros K h,\ncases h with x hx,\napply K x,\nassumption,\nend\n\nlemma demorgan_forall {α : Sort*} {P : α → Prop} : (∃ x, ¬ P x) → ¬ (∀ x, P x) :=\nbegin\nintros K h,\ncases K with x kx,\napply kx,\napply h,\nend\n\nlemma demorgan_or {P Q : Prop} : ¬ P ∧ ¬ Q → ¬ (P ∨ Q) :=\nbegin\nintros K h,\ncases K with Kp Kq,\ncases h,\napply Kp,\nassumption,\napply Kq,\nassumption,\nend\n\nlemma demorgan_and' {P Q : Prop} : ¬ (P ∧ Q) → ¬ P ∨ ¬ Q :=\nbegin\nintro H,\nby_cases hp : P,\nby_cases hq : Q,\napply absurd _ H,\nsplit; assumption,\nright, assumption,\nleft, assumption,\nend\n\nlemma demorgan_or' {P Q : Prop} : ¬ (P ∨ Q) → ¬ P ∧ ¬ Q :=\nbegin\nintro H,\nby_cases hp : P,\napply absurd _ H,\nleft, assumption,\nby_cases hq : Q,\napply absurd _ H,\nright, assumption,\nsplit,\nassumption,\nassumption,\nend\n\nlemma demorgan_exists' {α : Sort*} {P : α → Prop} : ¬ (∃ x, P x) → (∀ x, ¬ P x) :=\nbegin\nintros H x hx,\napply H,\nexistsi x,\nassumption,\nend\n\nlemma demorgan_forall' {α : Sort*} {P : α → Prop} : ¬ (∀ x, P x) → (∃ x, ¬ P x) :=\nbegin\nintros H,\nby_cases H' : ∃ x, ¬ P x,\nassumption,\napply absurd _ H,\nintro x,\nby_cases P x,\nassumption,\napply absurd _ H',\nexistsi x,\nassumption,\nend\n\nend logic\n\nnamespace tactic\n\nmeta def interactive.resolve_left : tactic unit := `[apply logic.resolve_left]\n\nmeta def interactive.resolve_right : tactic unit := `[apply logic.resolve_right]\n\nmeta def interactive.by_contrapositive : tactic unit :=\n`[apply logic.of_contrapositive]\n\nmeta def interactive.by_demorgan : tactic unit :=\n`[ apply logic.double_negation\n  <|> apply logic.demorgan_and\n  <|> apply logic.demorgan_or\n  <|> apply logic.demorgan_exists\n  <|> apply logic.demorgan_forall]\n\n--meta def interactive.by_demorgan : tactic unit :=\n\n\nend tactic", "meta": {"author": "UVM-M52", "repo": "week-7-maddiehutchinson", "sha": "56c2ba18c8844787fef3c83b66932b0382ed0363", "save_path": "github-repos/lean/UVM-M52-week-7-maddiehutchinson", "path": "github-repos/lean/UVM-M52-week-7-maddiehutchinson/week-7-maddiehutchinson-56c2ba18c8844787fef3c83b66932b0382ed0363/src/utils/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7712045760153435}}
{"text": "-- https://www.codewars.com/kata/5e889a3c0f55ed0032f1879f/train/lean\n\n/-\n  Incidence geometry in Lean, referenced from\n  https://sites.math.washington.edu/~lee/Courses/444-2009/theorems-incidence.pdf\n  and the lecture notes for MATH 4221 (not publicly available on the Internet)\n-/\n\n-- Undefined terms and axioms of incidence geometry\n-- In incidence geometry, there are 3 undefined terms:\n-- - Point\n-- - Line\n-- - \"Incident with\"/\"lies on\", e.g. point P is incident with / lies on line l\n-- And there are 3 axioms:\n-- - I₁: For every pair of distinct points P and Q there is exactly 1 line l such\n--   that P and Q lie on l\n-- - I₂: For every line l there exist at least two distinct points P and Q such\n--   that both P and Q lie on l\n-- - I₃: There exist three points that do not all lie on any one line\n-- Note that the three points in I₃ are implicitly assumed to be distinct, because\n-- otherwise one could construct a trivial model with only one point and no lines\n-- that trivially satisfies the axioms, which is uninteresting, and some of the\n-- theorems stated below do not hold in the trivial model\nimport tactic \n\nclass incidence (point line : Type) (incident_with : point → line → Prop) :=\n  (I₁ : ∀ P Q, P ≠ Q → ∃! l, incident_with P l ∧ incident_with Q l)\n  (I₂ : ∀ l, ∃ P Q, P ≠ Q ∧ incident_with P l ∧ incident_with Q l)\n  (I₃ : ∃ P Q R, P ≠ Q ∧ Q ≠ R ∧ P ≠ R ∧\n    ∀ l, ¬(incident_with P l ∧ incident_with Q l ∧ incident_with R l))\n\n\ntheorem thm_3p6p2 (point line : Type) (incident_with : point → line → Prop)\n  [incidence point line incident_with] (l : line) :\n  ∃ P, ¬incident_with P l := \nbegin \n-- from _inst_1.I₃ extract three points P, Q, R,\n-- the proofs of distinctness hPQ, hQR, hPR, \n-- and the proof of incidence hl of P, Q, R on l\nrcases _inst_1.I₃ with ⟨ P, Q, R, hPQ, hQR, hPR, hl⟩, \nspecialize hl l,\npush_neg at hl,\n\nby_cases hpl: (incident_with P l), \n  by_cases hql: (incident_with Q l),\n\n    -- both P and Q lie on l\n    show ∃ (P : point), ¬incident_with P l, \n      use R,\n      exact hl hpl hql,\n\n    -- P lies on l but Q does not lie on l\n    show ∃ (P : point), ¬incident_with P l,\n      use Q,\n\n    -- P does not lie on l\n    show ∃ (P : point), ¬incident_with P l,\n      use P,\nend ", "meta": {"author": "apurvanakade", "repo": "lean-playground", "sha": "2fe58797031ff8a6c29e1a442cbcc7a0ebc9c768", "save_path": "github-repos/lean/apurvanakade-lean-playground", "path": "github-repos/lean/apurvanakade-lean-playground/lean-playground-2fe58797031ff8a6c29e1a442cbcc7a0ebc9c768/src/codewars/Incidence Geometry #2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7712045706725941}}
{"text": "import data.int.basic\nimport data.nat.prime\n\n/-\nCorrectness 90/90\nStyle: 10/10\nGood work Priya!\n-/\n\n\n\n/- This assignment is due by 11:59pm on Friday, March 10th 2023. -/\n\n/-\nEXERCISE 1. Using the definition `mypow a n`, which is supposed to define\nexponentiation `a^n`, use induction to prove the theorem below.\n\nHint: you can use `nat.add_succ` to unfold the defition of `m + n.succ`.\n-/\n\nsection\nvariables {α : Type*} [comm_monoid α]\n\ndef mypow : α → ℕ → α\n| a 0       := 1\n| a (n + 1) := a * (mypow a n)\n\n#eval mypow 3 5\n\ntheorem mypow_zero (a : α) : mypow a 0 = 1 := rfl\n\ntheorem mypow_succ (a : α) (n : ℕ) : mypow a (n + 1) = a * mypow a n := rfl\n\n-- Exercise 1 [10pts].\ntheorem mypow_add (a : α) (m n : ℕ) : mypow a (m + n) = mypow a m * mypow a n :=\nbegin\n  induction n with n ih,\n  { -- n = 0\n    simp [mypow] },\n  { -- inductive step\n    simp [nat.add_succ, mypow, ih],\n    repeat { rw ←mul_assoc }, -- break up all parentheses\n    simp [mul_comm] }\nend\n\nend\n\n/-\nEXERCISE 2.\n\nIn class, we have used ordinary induction on the natural numbers,\nwhich allows you to prove `p n` for an arbitrary natural number\n`n` by proving `p 0` and `∀ m, p m → p m.succ`.\n\nIt is often more useful to the principle of *complete induction*\nor *strong induction*. This is found in the library under the\nname `nat.strong_induction_on`, but the exercise below asks you\nto prove it independently, using ordinary induction on the natural numbers.\nThe principle is stated in a form that the induction tactic\ncan use it, as illustrated in exercise 3.\n\nThe trick is to prove the stronger claim `∀ n, ∀ m < n, p m` by\ninduction on the natural numbers. The `suffices` step in the proof\nshows that this suffices to establish `p n` for the *particular* `n` in\nthe context. Once we have done that, we throw away the particular `n`,\nand focus on proving the stronger claim by induction.\n-/\n\nsection\n\n-- Exercise 2 [17pts].\ntheorem complete_induction_on {p : ℕ → Prop} (n : ℕ)\n  (h : ∀ n, (∀ m < n, p m) → p n) : p n :=\nbegin\n  suffices : ∀ n, ∀ m < n, p m,\n  { apply h,\n    apply this },\n  clear n,\n  intro n,\n  induction n with n ih,\n  { -- n = 0\n    simp },\n  { -- inductive step\n    intros m mlen,\n    rw nat.lt_succ_iff at mlen,\n    apply h,\n    intros l lltm,\n    apply ih,\n    exact lt_of_lt_of_le lltm mlen }\nend\n\nend\n\n/-\nEXERCISE 3.\n\nIn this exercise, we use the principle of strong induction to show that\nevery natural number greater than or equal to two has a prime divisor.\n\nYou can use the lemma `exists_lt_dvd_of_not_prime`. After the boilerplate\nthat we have set up for you, you should formalize the following argument:\nif `n` is prime, we are done.  If `n` is not prime, the lemma tells us that\nthere it has a nontrivial divisor `m < n`, and we can apply the induction\nhypothesis to that.\n-/\n\n-- This follows straightforwardly from the definition of `nat.prime`.\nlemma exists_lt_dvd_of_not_prime {n : nat} (h : ¬ nat.prime n) (h' : 2 ≤ n) :\n  ∃ m, 2 ≤ m ∧ m < n ∧ m ∣ n :=\nbegin\n  simp [nat.prime_def_lt'] at h,\n  exact h h'\nend\n\n\n-- Exercise 3 [18pts].\ntheorem exists_prime_dvd (n : ℕ) : 2 ≤ n → ∃ p, nat.prime p ∧ p ∣ n :=\nbegin\n  induction n using complete_induction_on with n ih,\n  dsimp at ih,\n  intro nle,\n  by_cases hn : nat.prime n,\n  { -- n prime\n    use n,\n    simp [hn] },\n  { -- n not prime\n    -- m is its nontrivial divisor\n    rcases exists_lt_dvd_of_not_prime hn nle with ⟨m, hm, mltn, mdvdn⟩,\n    -- apply inductive hypothesis to that\n    specialize ih m mltn hm,\n    rcases ih with ⟨p, hp, pdvdm⟩,\n    exact ⟨p, hp, dvd_trans pdvdm mdvdn⟩ }\nend\n\n/-\nEXERCISE 4.\n\nFinally, in this exercise, we define the structure of a `quasigroup`,\nshow that the integers with subtraction form an instance, and prove\nsome basic properties.\n\nYou can find the definition of a quasigroup here:\n\n  https://en.wikipedia.org/wiki/Quasigroup\n\nWe'll use the notation `ldiv a b` for left division (on Wikipedia, `a \\ b`),\nand we'll use `rdiv a b` for right division (on Wikipedia, `a / b`).\n\n(Instantiating the integers as a quasigroup is dangerous, because it\nredefines the notation of multiplication to mean substraction. Such \na thing could destroy the understanding of mathematics for a generation \nof elementary school students, so please make sure your git repositories \nstay private!)\n-/\n\n-- Exercise 4a [10pts].\n/-\nFirst, fill in the remaining axioms. E.g. the first should say,\n\"for any `a`, `b` and `x`, if `x` satisfies the defining equation for `a \\ b`\n(that is, the cancellation law), then it is equal to `a \\ b`.\"\n-/\n\nclass quasigroup (α : Type*) extends has_mul α :=\n(ldiv : α → α → α)\n(rdiv : α → α → α)\n(mul_ldiv_cancel : ∀ a b, a * ldiv a b = b)\n(rdiv_mul_cancel : ∀ a b, rdiv a b * b = a)\n(ldiv_unique : ∀ a b x, a * x = b → x = ldiv a b)\n(rdiv_unique : ∀ a b x, x * b = a → x = rdiv a b)\n\n-- Exercise 4b [15pts].\n/-\nNext, show that the integers with subtraction are an instance. You will\nhave to figure out the right definitions of `ldiv` and `rdiv`. For\nexample, if you decide `ldiv a b` should be `a * b`, write\n`ldiv := λ a b, a * b`.\n\nNote: Be sure to write this out on paper first, and check the identities\nas you see them wikipedia.  This will make the coding much easier, and \nhelp avoid you trying to prove something that is impossible. \n\nNote that in goals within the instance definition, you might see \"multiplication\"\nwhich is really integer subtraction, because that's we defined it as! To check\nwhich one it really is, you can click on the `*` operation in the infoview and look\nfor something like `{mul := int.sub}`.\n\nAlso, the `show` tactic can sometimes be used to unfold definitions. For example\non the goal `⊢ a * b = stuff`, `show a - b = stuff` should work.\n-/\n\ninstance : quasigroup ℤ :=\n{ mul := int.sub,\n  ldiv := λ a b, a - b,\n  rdiv := λ a b, a + b,\n  mul_ldiv_cancel :=\n    begin\n      repeat { simp [int.sub] },\n    end,\n  rdiv_mul_cancel := \n    begin\n      simp [int.sub],\n    end,\n  ldiv_unique :=\n    begin\n      dsimp only [int.sub],\n      intros a b x h,\n      rw ←neg_sub b a,\n      apply eq_neg_of_eq_neg,\n      apply eq.symm,\n      exact eq_sub_of_add_eq' h,\n    end,\n  rdiv_unique :=\n    begin\n      dsimp only [int.sub],\n      intros a b x h,\n      exact eq_add_of_add_neg_eq h,\n    end }\n\n/- Finally, prove that some identities hold in *any* quasigroup. -/\n\nnamespace quasigroup\nvariables {α : Type*} [quasigroup α]\n\n/-\n(mul_ldiv_cancel : ∀ a b, a * ldiv a b = b)\n(rdiv_mul_cancel : ∀ a b, rdiv a b * b = a)\n(ldiv_unique : ∀ a b x, a * x = b → x = ldiv a b)\n(rdiv_unique : ∀ a b x, x * b = a → x = rdiv a b)\n-/\n\n-- Exercise 4c [5pts].\ntheorem eq_ldiv_mul_self (y x : α) : y = ldiv x (x * y) :=\nbegin\n  apply ldiv_unique,\n  simp,\nend\n\n-- Exercise 4d [5pts].\ntheorem eq_mul_rdiv_self (y x : α) : y = rdiv (y * x) x :=\nbegin\n  apply rdiv_unique,\n  simp,\nend\n\n-- Exercise 4e [10pts].\ntheorem left_cancel (a b c : α) (h : a * b = a * c) : b = c :=\nbegin\n  rw (ldiv_unique a (a * c) b) h,\n  rw ←eq_ldiv_mul_self,\nend\n\n-- Exercise 4f [10pts].\ntheorem right_cancel (a b c : α) (h : a * b = c * b) : a = c :=\nbegin\n  rw (rdiv_unique (c * b) b a) h,\n  rw ←eq_mul_rdiv_self,\nend\n\nend quasigroup", "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/assignment7/assignment7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7712045628497574}}
{"text": "/- A toy dialect with basic tensor computations. -/\n\nimport MLIRSemantics.Types\nimport MLIRSemantics.Util.List\n\n/-\n### Tensor reshaping operation\n\nThis operation can reshape (retype) tensors with fully-known dimensions,\nprovided that the number of elements doesn't change.\n-/\n\ndef reshape {α} {D: DimList} (D': DimList)\n    (H: D.known) (H': D'.known) (Hprod: D'.prod = D.prod):\n    RankedTensor α D → RankedTensor α D' :=\n  fun t =>\n    { shape       := D'.project,\n      data        := t.data\n      h_refines   := dim_known_project_refines H',\n      h_data_size := by rw [t.h_data_size, dim_known_prod D' H', Hprod]\n                        rw [dim_known_prod_refines H]\n                        apply t.h_refines }\n\ntheorem reshape_reshape {α} {D: DimList} (D₁ D₂: DimList)\n    (H: D.known) (H₁: D₁.known) (H₂: D₂.known)\n    (Hprod₁: D₁.prod = D.prod) (Hprod₂: D₂.prod = D₁.prod)\n    (t: RankedTensor α D):\n      reshape D₂ H₁ H₂ Hprod₂ (reshape D₁ H H₁ Hprod₁ t) =\n      reshape D₂ H H₂ (Eq.trans Hprod₂ Hprod₁) t :=\n  rfl\n\ntheorem reshape_self {α} D H₁ H₂ Hprod (t: RankedTensor α D):\n    reshape D H₁ H₂ Hprod t = t := by\n  simp [reshape, dim_known_project_eq H₁ t.h_refines]\n\n\n/-\n### Tensor transposition operation\n\nThis operation shuffles the elements of the underlying data without changing\nits size. To keep this clean it's beneficial to separate the dimension logic\nfrom the index manipulation of the transposition itself.\n-/\n\ndef transpose_remap (n m: Nat): Nat → Nat :=\n  fun i => m * (i % n) + (i / n)\n\ntheorem transpose_remap_bound (n m):\n    ∀ i, i < n * m → transpose_remap n m i < n * m := by\n  intro i h\n  simp [transpose_remap]\n  sorry /- m*(≤ n-1)+(< m) -/\n\ntheorem transpose_remap_involutive (n m):\n    ∀i, transpose_remap m n (transpose_remap n m i) = i := by\n  simp [transpose_remap, Function.comp]; intro i\n  sorry /- = (i/n)*n + i%n -/\n\n@[inline]\ndef Matrix α n m :=\n  RankedTensor α [MLIR.AST.Dimension.Known n, MLIR.AST.Dimension.Known m]\n\ndef transpose {α n m} (t: Matrix α n m): Matrix α m n :=\n  { shape := [m, n],\n    data := List.remap t.data (transpose_remap n m)\n        (by intro i h\n            rw [t.h_data_size, dim_known_prod_refines _ t.h_refines] at * <;>\n            simp at *\n            apply transpose_remap_bound; assumption),\n    h_refines := by simp,\n    h_data_size := by\n      simp [shape_prod, List.foldr];\n      rw [t.h_data_size, dim_known_prod_refines _ t.h_refines] <;>\n      simp [Nat.mul_comm] }\n\ntheorem Function.comp_assoc {α β γ δ} (f: α → β) (g: β → γ) (h: γ → δ):\n    (h ∘ g) ∘ f = h ∘ (g ∘ f) :=\n  by funext x; simp\n\ntheorem transpose_involutive {α n m}:\n    ∀ (t: Matrix α n m), transpose (transpose t) = t := by\n  intro t;\n  simp [transpose]\n  apply RankedTensor.eq_of_fields_eq <;> simp\n  . rw [←dim_known_project_eq _ t.h_refines] <;> simp\n  . simp [List.remap_remap]\n    apply List.extF <;> simp\n    simp [transpose_remap_involutive]\n", "meta": {"author": "opencompl", "repo": "lean-mlir-semantics", "sha": "9ec41b134fd89a9799defae9e41de76b7d526266", "save_path": "github-repos/lean/opencompl-lean-mlir-semantics", "path": "github-repos/lean/opencompl-lean-mlir-semantics/lean-mlir-semantics-9ec41b134fd89a9799defae9e41de76b7d526266/MLIRSemantics/Toy/Toy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417878, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7711892359838753}}
{"text": "/-\nExercise 2.\nWhat is the contrapositive of ¬ Q → ¬ P\n-I am suggesting P → Q is the contrapositive of ¬ Q → ¬ P. Is this correct? \nProve that it is correct if you agree with me, otherwise change P → Q into what ever your heart desires!\n\nHere are some basic tactics that might help : http://wwwf.imperial.ac.uk/~buzzard/xena/html/source/tactics/guide.html\n-/\n\nexample (P Q : Prop) : (¬ Q → ¬ P) → (P → Q) :=\nbegin\n    sorry -- Replace the sorry with your proof!\nend", "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/Exercises/Exercies2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7711892321295372}}
{"text": "import algebra.ring\n\nexample {α : Type*} [ring α] (a b c : α) :\n  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 {α : Type*} [group α] {a b : α} (h : a * b = 1) :\na⁻¹ = b :=\nby rw [←(mul_one a⁻¹), ← h, inv_mul_cancel_left]\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.6-3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7710479319006048}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sean a, b y c números reales. Demostrar que\n--    min (min a b) c = min a (min b c)\n-- ----------------------------------------------------------------------\n\nimport data.real.basic tactic\n\nvariables a b c : ℝ\n\n-- 1ª demostración\n-- ===============\n\n-- Se usará el siguiente lema auxilar.\nlemma aux1 : min (min a b) c ≤ min a (min b c) :=\nbegin\n  apply le_min,\n  { show min (min a b) c ≤ a,\n      calc min (min a b) c\n           ≤ min a b : min_le_left (min a b) c\n       ... ≤ a       : min_le_left a b },\n  { show min (min a b) c ≤ min b c,\n    apply le_min,\n    { show min (min a b) c ≤ b,\n        calc min (min a b) c\n             ≤ min a b  : min_le_left (min a b) c\n         ... ≤ b        : min_le_right a b },\n    { show min (min a b) c ≤ c,\n      { by exact min_le_right (min a b) c }}},\nend\n\nexample :\n  min (min a b) c = min a (min b c) :=\nbegin\n  apply le_antisymm,\n  { show min (min a b) c ≤ min a (min b c),\n      by exact aux1 a b c },\n  { show min a (min b c) ≤ min (min a b) c,\n      calc min a (min b c)\n           = min (min b c) a : by apply min_comm\n       ... = min (min c b) a : by {congr' 1, apply min_comm}\n       ... ≤ min c (min b a) : by apply aux1\n       ... = min c (min a b) : by {congr' 1, apply min_comm}\n       ... = min (min a b) c : by apply min_comm },\nend\n\n-- 2ª demostración\n-- ===============\n\n-- Se usará el siguiente lema auxilar.\nlemma aux2 : min (min a b) c ≤ min a (min b c) :=\nbegin\n  apply le_min,\n  { calc min (min a b) c\n         ≤ min a b : by simp [min_le_left]\n     ... ≤ a       : by simp [min_le_left] },\n  { apply le_min,\n    { calc min (min a b) c\n           ≤ min a b  : by simp [min_le_left]\n       ... ≤ b        : by simp [min_le_right] },\n    { simp [min_le_right] }},\nend\n\nexample : min (min a b) c = min a (min b c) :=\nbegin\n  apply le_antisymm,\n  { by exact aux2 a b c },\n  { calc min a (min b c)\n         = min (min b c) a : by simp [min_comm]\n     ... = min (min c b) a : by simp [min_comm]\n     ... ≤ min c (min b a) : by simp [aux2]\n     ... = min c (min a b) : by simp [min_comm]\n     ... = min (min a b) c : by simp [min_comm] },\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : min (min a b) c = min a (min b c) :=\nbegin\n  apply le_antisymm,\n  { by exact aux2 a b c },\n  { calc min a (min b c)\n         = min (min c b) a : by simp [min_comm]\n     ... ≤ min c (min b a) : by simp [aux2]\n     ... = min (min a b) c : by simp [min_comm] },\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/Asociatividad_del_minimo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8705972734445508, "lm_q1q2_score": 0.771028349010803}}
{"text": "import linear_algebra\n\nvariables (R : Type*) (M : Type*) \n\n/-- \nAn abbreviation for linear combinations.\nBy definition, a linear combination is a list of elements of type R × M\n-/\nabbreviation lincomb := list (R × M)\n\nnamespace lincomb\n\nvariables {R M}\n\n/--\nconsts L is the list of constants appearing in the linear combination L.\n-/\ndef consts : lincomb R M → list R := list.map prod.fst\n\n/--\nvects L is the list of vectors (or module elements) appearing in the linear combination L.\n-/\ndef vects : lincomb R M → list M := list.map prod.snd\n\n@[simp]\nlemma vects_cons {t : R × M} {L : lincomb R M} : vects (t :: L)  = t.2 :: vects L := by refl\n\nvariable [semiring R]\n\n/--\nlmul c L is the linear combination obtained by multiplying all the constants of L by c (on the left).\n-/\ndef lmul (c : R) : lincomb R M → lincomb R M\n| [] := []\n| ((a,m)::ls) := (c * a,m) :: (lmul ls)\n\n@[simp]\nlemma lmul_cons {c : R} {l : R × M} {L : lincomb R M} :\n  lmul c (l :: L) = (c * l.1, l.2) :: (lmul c L) := by {cases l, refl}\n\n@[simp]\nlemma vects_lmul {c : R} {L : lincomb R M} : vects (lmul c L) = vects L :=\nbegin\n  induction L with l ls hls,\n  { simpa },\n  { simpa [vects, lmul] }\nend\n\nvariables [add_comm_monoid M] [semimodule R M]\n\n/--\nThe evaluation of a linear combination in the module.\n-/\ndef eval : lincomb R M → M\n| [] := 0\n| ((r,m) :: rest) := r • m + eval rest\n\n@[simp]\nlemma eval_nil : eval ([] : lincomb R M) = 0 := by refl\n\n@[simp]\nlemma eval_cons {l : R × M} {ls : lincomb R M} : eval (l :: ls) = l.1 • l.2 + eval ls :=\n  by {cases l, refl}\n\n@[simp]\nlemma eval_add {L1 L2 : lincomb R M} : eval (L1 ++ L2) = eval L1 + eval L2 :=\nbegin\n  induction L1 with l ls hls,\n  { simp },\n  { have : l :: ls ++ L2 = l :: (ls ++ L2), by refl,\n    rw [this, eval_cons],\n    finish, }\nend\n\n@[simp]\nlemma eval_lmul {c : R} {L : lincomb R M} : eval (lmul c L) = c • (eval L) :=\nbegin\n  induction L with l ls hls,\n  { simpa only [eval_nil, smul_zero] },\n  { rwa [lmul_cons,eval_cons,hls,eval_cons,mul_smul,smul_add] }\nend\n\nopen submodule\nopen_locale classical\n\ntheorem mem_span {L : lincomb R M} : eval L ∈ (span R (↑(list.to_finset (vects L)) : set M)) :=\nbegin\n  induction L with l ls hls,\n  { simp, },\n  { cases l with c v,\n    set vs := vects ls,\n    have : (vects ((c,v) :: ls)).to_finset = insert v vs.to_finset, by simp,\n    rw [this, eval_cons],\n    set H := span R (↑(insert v vs.to_finset) : set M),\n    apply add_mem' H,\n    { simp only [],\n      apply smul_mem' H,\n      apply subset_span,\n      simp, },\n    { suffices : eval ls ∈ span R (↑(vs.to_finset) : set M),\n        by refine span_mono _ this; simp,\n      assumption, }}\nend\n\nend lincomb\n\nvariable {M}\n\nvariables [semiring R] [add_comm_monoid M] [semimodule R M]\n\nopen lincomb\n\n/--\nThe span of a set S defined in terms of linear combinations (using the above definition).\n-/\ndef lcspan (S : set M) : submodule R M :=\nbegin\n  refine_struct {\n    carrier := { m | ∃ L : list (R × M), (eval L) = m ∧ (∀ {l}, l ∈ vects L → l ∈ S)}\n  },\n  { refine ⟨[],_,_⟩,\n    { refl },\n    { intros _ hl, exfalso, exact hl }},\n  { rintros m n ⟨A,hA1,hA2⟩ ⟨B, hB1, hB2⟩,\n    use A ++ B,\n    split,\n    { rwa [eval_add, hA1,hB1] },\n    { intros l hl,\n      unfold vects at hl,\n      rw [list.map_append prod.snd, list.mem_append] at hl,\n      cases hl, {apply hA2, assumption}, {apply hB2, assumption}}},\n  { rintros c m ⟨L,hL1,hL2⟩,\n    refine ⟨lmul c L,_,_⟩,\n    { rwa [eval_lmul,hL1] },\n    { rwa vects_lmul }, }\nend\n\nnamespace lcspan\n\nopen submodule\n\n/--\nlcspan S agrees with span (which is defined as the infemum over all submodules containing S)\n-/\ntheorem lcspan_eq_span {S : set M} : lcspan R S = span R S :=\nbegin\n  ext m,\n  split,\n  { intro hm,\n    rcases hm with ⟨L,rfl,hL2⟩,\n    induction L with l ls hls,\n    { apply zero_mem' (span R S) },\n    { rw eval_cons,\n      apply add_mem' (span R S),\n      { apply smul_mem' (span R S), apply subset_span, apply hL2,\n        rw vects_cons, simp, },\n      { apply hls, intros u hu, apply hL2, rw vects_cons,\n        exact list.mem_cons_of_mem l.snd hu, }}},\n  { intro hm,\n    have claim : lcspan R S ∈ { U : submodule R M | S ⊆ ↑U },\n    { intros s hs,\n      refine ⟨[(1,s)],_,_⟩,\n      { simp, },\n      { intros l hl,\n        simp only [list.mem_cons_iff, vects_cons] at hl,\n        rcases hl with ⟨ rfl,hl⟩,\n        { assumption },\n        { exfalso, exact hl, }}},\n    { apply Inf_le claim,\n      assumption, }\n  }\nend\n\nend lcspan\n", "meta": {"author": "adamtopaz", "repo": "comb_geom", "sha": "e16b629d6de3fbdea54a528755e7305dfb51e902", "save_path": "github-repos/lean/adamtopaz-comb_geom", "path": "github-repos/lean/adamtopaz-comb_geom/comb_geom-e16b629d6de3fbdea54a528755e7305dfb51e902/src/linear_algebra/lincomb.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7710168755375321}}
{"text": "import data.nat.prime\nimport algebra.big_operators\nimport tactic\n\nopen_locale big_operators\n\n\ntheorem two_le {m : ℕ} (h0 : m ≠ 0) (h1 : m ≠ 1) : 2 ≤ m :=\nbegin \n  by_contra' h,\n  interval_cases m; contradiction,\nend\n\nexample {m : ℕ} (h0 : m ≠ 0) (h1 : m ≠ 1) : 2 ≤ m :=\nbegin\n  cases m, contradiction,\n  cases m, contradiction,\n  repeat {apply nat.succ_le_succ},\n  apply zero_le,\nend\n\nexample {m : ℕ} (h0 : m ≠ 0) (h1 : m ≠ 1) : 2 ≤ m :=\nbegin\n  by_contra' h,\n  revert m h h0 h1,\n  dec_trivial,\nend\n\nexample {m : ℕ} (h : m < 2) : m = 0 ∨ m = 1 :=\n  by dec_trivial!\n\nexample {m : ℕ} (h0 : m ≠ 0) (h1 : m ≠ 1) : 2 ≤ m :=\n  by omega\n\n\ntheorem exists_prime_factor {n : ℕ} (h : 2 ≤ n) :\n  ∃ p : ℕ, p.prime ∧ p ∣ n :=\nbegin \n  by_cases np : n.prime,\n  { use [n, np],},\n  { induction n using nat.strong_induction_on with n ih,\n    dsimp at ih,\n    rw nat.prime_def_lt at np,\n    push_neg at np,\n    rcases np h with ⟨m, mltn, mdvdn, mne1⟩,\n    have : m ≠ 0,\n      intro mz,\n      rw [mz, zero_dvd_iff] at mdvdn,\n      linarith,\n    have mgt2 : 2 ≤ m,\n      from two_le this mne1,\n    by_cases mp : m.prime,\n    { use [m, mp, mdvdn],},\n    { rcases ih m mltn mgt2 mp with ⟨k, kp, kdvdm⟩,\n      use [k, kp, dvd_trans kdvdm mdvdn],},}\nend\n\n\ntheorem primes_infinite : ∀ n, ∃ p > n, nat.prime p :=\nbegin\n  intro n,\n  have : 2 ≤ nat.factorial (n + 1) + 1,\n    apply two_le,\n    apply ne_of_gt, linarith,\n    apply ne_of_gt, apply lt_add_of_pos_left, apply nat.factorial_pos,\n\n  rcases exists_prime_factor this with ⟨p, pp, pdvd⟩,\n  refine ⟨p, _, pp⟩,\n  show p > n,\n  by_contra' ple,\n  have : p ∣ nat.factorial (n + 1),\n    apply nat.dvd_factorial,\n    show 0 < p, from nat.prime.pos pp,\n    show p ≤ n + 1, apply le_add_of_le_of_nonneg ple, norm_num,\n\n  have : p ∣ 1,\n    convert nat.dvd_sub' pdvd this,\n    simp,\n\n  show false,\n    from nat.prime.not_dvd_one pp this,\nend\n\n\nopen finset\nsection \n\n\nvariables {α : Type*} [decidable_eq α] (r s t : finset α)\n\nexample : r ∩ (s ∪ t) ⊆ (r ∩ s) ∪ (r ∩ t) := \nbegin \n  rw subset_iff,\n  intro x,\n  rw [mem_inter, mem_union, mem_union, mem_inter, mem_inter],\n  tauto,\nend\n\nexample : r ∩ (s ∪ t) ⊆ (r ∩ s) ∪ (r ∩ t) :=\nby { simp [subset_iff], intro x, tauto }\n\nexample : (r ∪ s) ∩ (r ∪ t) = r ∪ (s ∩ t) :=\nby { ext x, simp, tauto,}\n\nexample : (r \\ s \\ t) = r \\ (s ∪ t) :=\nby { ext x, simp, tauto,}\n\n\nend\n\nexample (s : finset ℕ) (n : ℕ) (h : n ∈ s) : n ∣ (∏ i in s, i) :=\n  finset.dvd_prod_of_mem _ h\n\n\ntheorem nat.prime.eq_of_dvd_of_prime {p q : ℕ} (prime_p : p.prime) (prime_q : q.prime)\n  (h : p ∣ q) : p = q := \nbegin \n  cases nat.prime.eq_one_or_self_of_dvd prime_q p h with h' h',\n  from absurd h' (nat.prime.ne_one prime_p),\n  from h',\nend\n\ntheorem mem_of_dvd_prod_primes {s : finset ℕ} {p : ℕ} (prime_p : p.prime) :\n  (∀ n ∈ s, nat.prime n) → (p ∣ ∏ n in s, n) → p ∈ s := \nbegin \n  intros hp hd,\n  induction s using finset.induction_on with a s ans ih,\n  { simp at hd,\n    linarith [prime_p.two_le],},\n  { simp [prod_insert ans, prime_p.dvd_mul] at hp hd,\n    rw mem_insert,\n    cases hd,\n    { left, apply nat.prime.eq_of_dvd_of_prime,\n      from prime_p, from hp.1, from hd,},\n    { right, apply ih, \n      from hp.2, from hd,}}\nend\n\nexample (s : finset ℕ) (x : ℕ) : x ∈ s.filter nat.prime ↔ x ∈ s ∧ x.prime :=\nmem_filter\n\ntheorem primes_infinite' : ∀ (s : finset nat), ∃ p, nat.prime p ∧ p ∉ s :=\nbegin \n  intro s, \n  by_contra' h,\n  set s' := s.filter nat.prime with s'_def,\n  have mem_s' : ∀ {n : ℕ}, n ∈ s' ↔ n.prime, \n    intro n,\n    simp [s'_def],\n    apply h,\n\n  have : 2 ≤ (∏ i in s', i) + 1,\n     apply nat.succ_le_succ,\n     apply nat.succ_le_of_lt,\n     apply prod_pos,\n     intros n np,\n     rw mem_s' at np,\n     from nat.prime.pos np,\n\n  rcases exists_prime_factor this with ⟨p, pp, pdvd⟩,\n\n  have : p ∣ (∏ i in s', i),\n    apply dvd_prod_of_mem,\n    rw mem_s', from pp,\n\n  have : p ∣ 1,\n    convert nat.dvd_sub' pdvd this,\n    simp,\n\n  show false,\n    from nat.prime.not_dvd_one pp this,\n\nend\n\n\ntheorem bounded_of_ex_finset (Q : ℕ → Prop) :\n  (∃ s : finset ℕ, ∀ k, Q k → k ∈ s) → (∃ n, ∀ k, Q k → k < n) := \nbegin \n  rintros ⟨s, hs⟩,\n  use s.sup id + 1,\n  intros k Qk,\n  apply nat.lt_succ_of_le,\n  show id k ≤ s.sup id,\n  apply le_sup,\n  from hs k Qk,\nend\n\ntheorem ex_finset_of_bounded (Q : ℕ → Prop) [decidable_pred Q] :\n  (∃ n, ∀ k, Q k → k ≤ n) → (∃ s : finset ℕ, ∀ k, Q k ↔ k ∈ s) := \nbegin \n  rintros ⟨n, hn⟩,\n  use (range (n + 1)).filter Q,\n  intro k,\n  split,\n  { intro hk,\n    simp [nat.lt_succ_iff],\n    from ⟨hn k hk, hk⟩,},\n  { simp,}\nend\n\n\n\nexample (n : ℕ) : (4 * n + 3) % 4 = 3 :=\n  by { rw [add_comm, nat.add_mul_mod_self_left], norm_num}\n\ntheorem mod_4_eq_3_or_mod_4_eq_3 {m n : ℕ} (h : m * n % 4 = 3) :\n  m % 4 = 3 ∨ n % 4 = 3 := \nbegin \n  revert h,\n  rw [nat.mul_mod],\n  have : m % 4 < 4 := nat.mod_lt m (by norm_num),\n  interval_cases  m % 4 with hm; simp [hm],\n  have : n % 4 < 4 := nat.mod_lt n (by norm_num),\n  interval_cases n % 4 with hn; simp [hn]; norm_num,\nend\n\ntheorem two_le_of_mod_4_eq_3 {n : ℕ} (h : n % 4 = 3) : 2 ≤ n := \n  by apply two_le; { intro neq, rw neq at h, norm_num at h}\n\ntheorem aux {m n : ℕ} (h₀ : m ∣ n) (h₁ : 2 ≤ m) (h₂ : m < n) :\n  (n / m) ∣ n ∧ (n / m) < n := \nbegin \n  have : 1 < m , apply lt_of_lt_of_le, \n    from (by norm_num : 1 < 2), from h₁,\n  split,\n  from nat.div_dvd_of_dvd h₀,\n  apply nat.div_lt_self,\n  apply lt_trans,\n  show 0 < 1, norm_num,\n  from lt_trans this h₂,\n  from this,\nend\n\ntheorem exists_prime_factor_mod_4_eq_3 {n: ℕ} (h : n % 4 = 3) :\n  ∃ p : ℕ, p.prime ∧ p ∣ n ∧ p % 4 = 3 := \nbegin \n  by_cases np : n.prime,\n  { use [n, np, dvd_rfl, h],},\n\n  induction n using nat.strong_induction_on with n ih,\n  dsimp at ih,\n  rw nat.prime_def_lt at np,\n  push_neg at np,\n  rcases np (two_le_of_mod_4_eq_3 h) with ⟨m, mltn, mdvdn, mne1⟩,\n  have mge : 2 ≤ m,\n    apply two_le _ mne1,\n    intro mz,\n    rw [mz, zero_dvd_iff] at mdvdn, linarith,\n\n  have neq : m * (n / m) = n := nat.mul_div_cancel' mdvdn,\n  have : m % 4 = 3 ∨ (n / m) % 4 = 3,\n    apply mod_4_eq_3_or_mod_4_eq_3,\n    rw [neq, h],\n\n  cases this with h' h',\n  { by_cases mp : m.prime,\n    { use [m, mp, mdvdn, h'],},\n    { rcases ih m mltn h' mp with ⟨k, kp, kdvdm, keq⟩,\n      use [k, kp, dvd_trans kdvdm mdvdn, keq],}},\n  { have : (n / m) ∣ n ∧ (n / m) < n,\n      from aux mdvdn mge mltn,\n    by_cases nmp : (n / m).prime,\n    { use [(n / m), nmp, this.1, h'],},\n    { rcases ih (n /m) this.2 h' nmp with ⟨k, kp, kdvdm, keq⟩,\n      use [k, kp, dvd_trans kdvdm this.1, keq],}}\nend\n\nexample (m n : ℕ) (s : finset ℕ) (h : m ∈ erase s n) : m ≠ n ∧ m ∈ s :=\nby rwa mem_erase at h\n\nexample (m n : ℕ) (s : finset ℕ) (h : m ∈ erase s n) : m ≠ n ∧ m ∈ s :=\nby { simp at h, assumption }\n\n\ntheorem primes_mod_4_eq_3_infinite : ∀ n, ∃ p > n, nat.prime p ∧ p % 4 = 3 :=\nbegin \n  by_contra' h,\n  cases h with n hn,\n  have : ∃ s : finset ℕ, ∀ p : ℕ, p.prime ∧ p % 4 = 3 ↔ p ∈ s, \n    apply ex_finset_of_bounded,\n    use n,\n    contrapose! hn,\n    rcases hn with ⟨p, ⟨pp, p4⟩, pltn⟩,\n    use [p, pltn, pp, p4],\n  \n  cases this with s hs,\n  have h₀ : 2 ≤ 4 * (∏ i in erase s 3, i) + 3,\n    apply two_le; norm_num,\n    \n  have h₁ : (4 * (∏ i in erase s 3, i) + 3) % 4 = 3,\n    rw [add_comm], norm_num,\n\n  rcases exists_prime_factor_mod_4_eq_3 h₁ with ⟨p, pp, pdvd, p4eq⟩,\n\n  have ps : p ∈ s,\n    rw ←hs, use [pp, p4eq],\n\n  have pne3 : p ≠ 3,\n    intro pe3,\n    rw [pe3, ←nat.dvd_add_iff_left (dvd_refl 3)] at pdvd, \n    rw nat.prime_three.dvd_mul at pdvd,\n    cases pdvd, norm_num at pdvd, \n    have : 3 ∈ erase s 3,\n      apply mem_of_dvd_prod_primes,\n      from nat.prime_three,\n      intros n ns,\n      simp at ns,\n      from ((hs n).2 ns.2).1,\n      from pdvd,\n    simpa,\n\n  have : p ∣ 4 * (∏ i in erase s 3, i),\n    rw nat.prime.dvd_mul pp,\n    right, apply dvd_prod_of_mem,\n    simp, split; assumption,\n\n  have : p ∣ 3, \n    convert nat.dvd_sub' pdvd this,\n    simp,\n\n  have : p = 3,\n    apply nat.prime.eq_of_dvd_of_prime pp nat.prime_three this,\n\n  contradiction,\n\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/05_Number_Theory/03_Infinitely_Many_Primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303292, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7710168740163276}}
{"text": "/-\nHOMEWORK #9 \n\nThere is no need to import our previous definitions.\nFor this homework you will just use Lean's built-in\nnotations and definitions. \n-/\n\n/-\nProve the following. Note that you can read each of \nthe propositions to be proved as either a logical\nstatement or as simply a function definition. Use\nwhat you already know about the latter to arrive\nat a proof, and then understand the proof as one\nthat shows that the logical statement is true.\n-/\n\ntheorem t1 {P Q : Prop} (p2q : P → Q) (p : P) : Q :=\n  _\n\n\ntheorem t2 {P Q R : Prop} (p2q : P → Q) (q2r : Q → R): P → R :=\n  λ (p : P), \n    q2r (p2q p)\n\n/-\nUse \"example\" to state and prove the preceding two \ntheorems but using \"cases\" style notation rather\nthan C-style. Remember, \"example\" is a way to state\na proposition/type and give an example of a value.\nHere's an example of the use of \"example\". Give\nyour answers following this example.\n-/\n\n-- example\nexample : ℕ := 5\n\n-- Your two answers here\n\nexample : ∀ (P Q R : Prop), (P → Q) → (Q → R) → P → R :=\nλ P Q R p2q q2r, λ p, _\n\n\n/-\nNow give English-language versions of your two proofs.\n-/\n\n\n/-\nProve the following using case analysis on one\nof the arguments (i.e., use match...with...end\nat a key point in your proof). Use \"cases\" style\nnotation. \n-/\n\ntheorem t3 : ∀ (P : Prop), false → P\n| P f := false.elim _\n\ntheorem t3' : ∀ (P : Prop), false → P\n| P f := match f with /- no cases!-/ end\n\n\n/-\nProve false → true by applying t3 to a proposition.\nYou have to figure out which one.\n-/\ntheorem t4 : false → true := t3 true\n\n/-\nDefine t5 to be the same as t3 but with P taken as\nan implicit argument.\n-/\n\ntheorem t5 : ∀ {P : Prop}, false → P   /- false elimination-/\n| P f := false.elim f\n\n\n/-\nDefine t6 to be a proof of false → true by\napplying t5 to the right argument(s). \n-/\n\ntheorem t6 : false → true := t5\n\n/-\nThat is almost magic. In English, t3 proves \nthat false implies *any* proposition, so just\n*apply* t3 to *true* in particular, but use t5 \ninstead of t3.\n\nWhat you see here is really important: Once \nwe've proved a general theorem (a ∀ proposition)\nwe can *apply the proof* to any *particular* case \nto yield a proof for that specific case. This is \nthe elimination rule for ∀. It is also known as\nuniversal instantiation (UI). \n-/\n\n\n/-\nNext we see the idea that test cases are really\njust equality propositions to be proved. Here, \nfor example, is a definition of the factorial\nfunction.\n-/\n\ndef fac : ℕ → ℕ \n| 0 := 1\n| (n' + 1) := (n' + 1) * fac n'\n\n/-\nUse \"example\" to write test cases for the\nfirst ten natural number arguments to this\nfunction.\n-/\n\nexample : fac 0 = 1 := eq.refl 1\nexample : fac 1 = 1 := eq.refl _  -- Inferred\nexample : fac 2 = 2 := rfl        -- Shorthand\n#check @rfl           -- infers type and value\n\n\n-- The rest of your answers here\n\n/-\nInsight: A test case is an equality proposition.\nIt is proved by \"running\" the program under test\nto reduce the application of the function to input\narguments to produce an output that is then asserted\nto be equal to an expected output. \n\nIn many cases, all we have to do is to simplify\nthe expressions on each side of the eq to see if\nthey reduce to exactly the same value. If so, we\ncan *apply* eq.refl (a universal generalization!)\nto that value. Using rfl we can avoid even having\nto type that value in cases where Lean can infer\nit.\n-/\n\n\n/-\nThe next problem requires thave you give a proof of \na bi-implication, a proposition whose connective is \n↔. To prove a bi-implication requires that one prove\nan implication in each direction. \n\nHere you are asked to prove P ∧ Q ↔ Q ∧ P. What this\nformula asserts is that ∧ is commutative. To construct\na proof of this proposition you will have to apply \niff.intro to two smaller proofs, one of P → Q and \nand of Q → P. \n\nStart by \"assuming\" that P and Q are arbitary but \nspecific propositions (∀ introduction), then apply \niff.intro to two \"stubbed out\" arguments (underscores). \nWe suggest that you put the underscores in parentheses \non different lines. Then recursively fill in each of\nthese stubs with the required types of proofs. Study\nthe context that Lean shows you in its Messages panel\nto see what you have to work with at each point in \nyour proof constructions.\n-/\ntheorem t7 : ∀ {P Q : Prop}, P ∧ Q ↔ Q ∧ P :=\nλ P Q,\n  iff.intro \n    (λ pandq, \n      and.intro _ _\n    ) \n    _\n\n-- P ∧ Q -- and.intro p q\n-- P ↔ Q -- iff.intro p2q q2p\n---- assume P then show Q (P → Q)\n---- assume Q then show P (Q → P)\n\n/-\nIn English, when asked to prove P ↔ Q, one says, \"it\nwill suffice to show P → Q and then to show Q → P.\" One\nthen goes on to give a proof of each implication. It\nthen follows from iff.intro that a proof of P ↔ Q can\nbe constructed, proving the bi-implication.\n-/\n\n\n/-\nThe trick here is to do case analysis on porq\n(use match ... with ... end) and to show that \na proof of R can be constructed *in either case*.\n-/\ntheorem t8 \n          {P Q R : Prop} \n          (p2r : P → R) \n          (q2r : Q → R) \n          (porq : P ∨ Q) : \n          R := match porq with\n                | or.inl p := p2r p\n                | or.inr q := _\n              end\n\ntheorem t8' \n          {P Q R : Prop} \n          (p2r : P → R) \n          (q2r : Q → R) \n          (porq : P ∨ Q) : \n          R := or.elim porq p2r q2r\n\n/-\nProve P ∨ Q → R. Well, it will suffice to\nshow P → R and then to show that Q → R (because\nif we do that then we can use or.elim to get a\nproof of R.)\n-/\n\n/-\nWe suggest that you use  \"let ... in\" to give\nnames to intermediate results that you then combine\nin a final expression to finish the proof.\n-/\ntheorem t9 : ∀ (P Q: Prop), (P → Q) → ¬ (P ∧ ¬ Q) :=\nλ P Q,\n  λ p2q,  \n    -- ¬ (P ∧ ¬ Q) === (P ∧ ¬ Q) → false\n    λ ( pandnotq : (P ∧ ¬ Q)), \n      (\n        let p := pandnotq.left in\n        let nq := pandnotq.right in\n        let q := p2q p in\n        nq q\n      )\n\n/-\nTo prove ¬P, assume P and show that this leads to\na contradiction, then from that derive a proof of \nfalse, and use false.elim to finish the proof. This\nis *proof by negation*.\n-/\n\n/- \nThe following is about proof by contradiction.\nTo prove P, assume ¬ P, and show that leads to\na contradiction. This shows ¬ (¬ P). Now, use \nthe *classical* principle of negation elimination\nto deduce P.\n-/\n\ntheorem neg_elim' : ∀ (P : Prop), ¬ ¬ P → P :=\nλ P,\nλ nnp,\n_           -- STUCK!!\n\n\ntheorem neg_elim : ∀ (P : Prop), (P ∨ ¬ P) → (¬ ¬ P → P):= \nλ P,\n    λ pornotp, \n        λ nnp,\n          match pornotp /- P or ¬P -/ with\n          | or.inl p := p\n          | or.inr np := false.elim (_)\n          end\n        /-\n            match excl_middle with\n            | or.inl p := p\n            | or.inr np := false.elim (nnp np)  -- false elimination\n            end\n        -/\n\n-- nnp : (¬ P) → false\n-- np : ¬ P\n-- nnp np = false!\n\n-- Let's use H to mean There is a sub-exponential time algorithm for Boolean sat.\n-- ¬ H means that there's not one.\n-- H ∨ ¬H\n\n-- make Lean into a classical logic\n-- axiom em : ∀ (P : Prop), P ∨ ¬ P\n#check classical.em\n\n\n\n\ntheorem t10 : ∀ (P : Prop), P ∨ ¬ P :=\n_\n\n\n#check @or.inl\n#check @or.inr\n\n/-\nDeMorgan's Laws\n-/\n\ntheorem t11 : ∀ (P Q : Prop), ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nλ P Q, \n    iff.intro \n        (λ not_porq,\n             match (classical.em P) with\n             | or.inl p := false.elim (not_porq (or.inl p))\n             -- ¬(P ∨ Q) === (P ∨ Q → false)\n             | or.inr np := false.elim (not_porq _)\n             end\n        )\n        (\n          λ npandnq, \n            λ porq,\n              match porq with\n              | or.inl p := _\n              | or.inr q := _\n              end\n        )\n\n\ntheorem t12 : ∀ (P Q : Prop), ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\nλ P Q,\n  iff.intro\n    (λ not_pandq,\n      match (classical.em P) with\n      | or.inl p := match (classical.em Q) with\n                    | or.inl q := false.elim (not_pandq _)\n                    | or.inr nq := _\n                    end\n      | or.inr np := _\n      end \n    )\n    _\n\n/-\nFor the following exercises, we assume that there is \na type called Person and a binary relation, Likes, on\npairs of people.\n-/\naxiom Person : Type\naxiom Likes : Person → Person → Prop\n\n\n/-\nProve the following\n-/\ntheorem t13 : \n  (∃ (p : Person), ∀ (q : Person), Likes q p) → \n  (∀ (p : Person), ∃ (q : Person), Likes p q) :=\n  λ h,\n    λ p, \n      match h with\n      | exists.intro loved pf := exists.intro loved _\n      end\n\n/-\nλ h, \n    match h with\n    | exists.intro p pf := \n        λ q, \n            (exists.intro p (pf q))\n    end\n-/\n\n", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/assignments/hw9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.7708953126308694}}
{"text": "import tactic\nimport data.int.parity\n-- These are some helpful lemmas for coursework 3.\n-- The main result in this file is the first theorem.\n\n/-\nA nonempty set of integers with a lower bound has a minimum.\n-/\ntheorem bdd_below_Z_set_has_minimum {S : set ℤ} (hne : set.nonempty S) (hbdd : bdd_below S) : \n∃ (m ∈ S), ∀(n ∈ S), m ≤ n :=\nbegin\n  cases hne with m hm,\n  change ∃ x, ∀ y ∈ S, x ≤ y  at hbdd,\n  cases hbdd with lb hlb,\n  have hml : lb ≤ m,\n  {\n    specialize hlb m,\n    apply hlb,\n    exact hm,\n  },\n  let T := finset.finite_to_set(finset.Icc lb m),\n  let u := set.finite.inter_of_left T S,\n  let V := set.finite.to_finset u,\n  have minv : m ∈ V,\n  {\n    rw set.finite.mem_to_finset,\n    split,\n    {\n      suffices : m ∈ (finset.Icc lb m),\n      exact finset.mem_coe.mpr this,\n      rw finset.mem_Icc,\n      split, exact hml, refl,\n    },\n    exact hm,\n  },\n  have hnv : V.nonempty,\n  {\n    use m,\n    exact minv,\n  },\n  let M := finset.min' V hnv,\n  have hMm : M ≤ m,\n  {\n    have h2 := finset.min'_le V m minv,\n    exact h2,\n  },\n  use M,\n  split,\n  {\n    have h2 := finset.min'_mem V hnv,\n    rw set.finite.mem_to_finset at h2,\n    exact h2.right,\n  },\n  {\n    intros n hn,\n    by_cases n ≤ m,\n    {\n      apply finset.min'_le,\n      rw set.finite.mem_to_finset,\n      split,\n      {\n        rw finset.mem_coe,\n        rw finset.mem_Icc,\n        specialize hlb n,\n        split,\n        apply hlb, exact hn,\n        exact h,\n      },\n      {\n        exact hn,\n      },\n    },\n    {\n      rw not_le at h,\n      linarith [h, hMm],\n    }\n  }\nend\n\nlemma le_abs_le {a b : ℚ} (h: a ≤  b):a ≤  |b| :=\nbegin\n  have h2 := le_abs_self b,\n  linarith,\nend\n\nnamespace int\nlemma odd_div {a b :ℤ} : a ∣ b → odd b → odd a :=\nbegin\n  intros h1 h2,\n  cases h1 with u hu,\n  rw hu at h2,\n  rw odd_mul at h2,\n  exact h2.left,\nend\n\nend int\n\nlemma sqrt_one_eqn (a : ℤ) : a^2 = 1 ↔ a = 1 ∨ a = -1 :=\nbegin\n  split,\n  {\n    intro h,\n    apply_fun (λ x, x - (1 : ℤ)) at h,\n    rw (by ring : 1 - 1 = (0 : ℤ )) at h,\n    rw (by ring: a^2 - 1 = (a + 1) * (a - 1)) at h,\n    rw eq_comm at h,\n    rw zero_eq_mul at h,\n    cases h,\n      right, linarith,\n      left, linarith,\n  },\n  {\n    intro h,\n    cases h;\n    rw h; norm_num,\n  }\nend\n\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/cw3/utils.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.7708271065717154}}
{"text": "/-\nCopyright (c) 2018 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, 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\nimport algebra.pointwise\n\n/-!\n# Submonoids: membership criteria\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 ∈ S` where `S` is a multiplicative (resp., additive) submonoid and\n  `n` is a natural number, then `x^n` (resp., `n • 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`: the multiplicative (resp., additive) closure\n  of `{x}` consists of powers (resp., natural multiples) of `x`.\n\n## Tags\nsubmonoid, submonoids\n-/\n\nopen_locale big_operators\n\nvariables {M : Type*}\nvariables {A : Type*}\n\nnamespace submonoid\n\nsection assoc\nvariables [monoid M] (S : submonoid M)\n\n@[simp, norm_cast] theorem coe_pow (x : S) (n : ℕ) : ↑(x ^ n) = (x ^ n : M) :=\nS.subtype.map_pow x n\n\n@[simp, norm_cast] theorem coe_list_prod (l : list S) : (l.prod : M) = (l.map coe).prod :=\nS.subtype.map_list_prod l\n\n@[simp, norm_cast] 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] theorem coe_finset_prod {ι M} [comm_monoid M] (S : submonoid M)\n  (f : ι → S) (s : finset ι) :\n  ↑(∏ i in s, f i) = (∏ 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}, (∀x ∈ l, x ∈ S) → l.prod ∈ S\n| []     h := S.one_mem\n| (a::l) h :=\n  suffices a * l.prod ∈ S, by rwa [list.prod_cons],\n  have a ∈ S ∧ (∀ x ∈ l, x ∈ S), from list.forall_mem_cons.1 h,\n  S.mul_mem this.1 (list_prod_mem this.2)\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  (∀a ∈ m, a ∈ S) → m.prod ∈ S :=\nbegin\n  refine quotient.induction_on m (assume l hl, _),\n  rw [multiset.quot_mk_to_coe, multiset.coe_prod],\n  exact S.list_prod_mem hl\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  {ι : Type*} {t : finset ι} {f : ι → M} (h : ∀c ∈ t, f c ∈ S) :\n  ∏ c in t, f c ∈ S :=\nS.multiset_prod_mem (t.1.map f) $ λ x hx, let ⟨i, hi, hix⟩ := multiset.mem_map.1 hx in hix ▸ h i hi\n\nlemma pow_mem {x : M} (hx : x ∈ S) (n : ℕ) : x ^ n ∈ S :=\nby simpa only [coe_pow] using ((⟨x, hx⟩ : S) ^ n).coe_prop\n\nend assoc\n\nsection non_assoc\nvariables [mul_one_class M] (S : submonoid M)\n\nopen set\n\n@[to_additive]\nlemma mem_supr_of_directed {ι} [hι : nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S)\n  {x : M} :\n  x ∈ (⨆ i, S i) ↔ ∃ i, x ∈ S i :=\nbegin\n  refine ⟨_, λ ⟨i, hi⟩, (set_like.le_def.1 $ le_supr S i) hi⟩,\n  suffices : x ∈ closure (⋃ i, (S i : set M)) → ∃ i, x ∈ S i,\n    by simpa only [closure_Union, closure_eq (S _)] using this,\n  refine (λ hx, closure_induction hx (λ _, mem_Union.1) _ _),\n  { exact hι.elim (λ i, ⟨i, (S i).one_mem⟩) },\n  { rintros x y ⟨i, hi⟩ ⟨j, hj⟩,\n    rcases hS i j with ⟨k, hki, hkj⟩,\n    exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ }\nend\n\n@[to_additive]\nlemma coe_supr_of_directed {ι} [nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S) :\n  ((⨆ i, S i : submonoid M) : set M) = ⋃ i, ↑(S i) :=\nset.ext $ λ 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 (≤) S) {x : M} :\n  x ∈ Sup S ↔ ∃ s ∈ S, x ∈ 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 (≤) S) :\n  (↑(Sup S) : set M) = ⋃ s ∈ S, ↑s :=\nset.ext $ λ x, by simp [mem_Sup_of_directed_on Sne hS]\n\n@[to_additive]\nlemma mem_sup_left {S T : submonoid M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T :=\nshow S ≤ S ⊔ T, from le_sup_left\n\n@[to_additive]\nlemma mem_sup_right {S T : submonoid M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T :=\nshow T ≤ S ⊔ T, from le_sup_right\n\n@[to_additive]\nlemma mem_supr_of_mem {ι : Type*} {S : ι → submonoid M} (i : ι) :\n  ∀ {x : M}, x ∈ S i → x ∈ supr S :=\nshow S i ≤ supr S, from le_supr _ _\n\n@[to_additive]\nlemma mem_Sup_of_mem {S : set (submonoid M)} {s : submonoid M}\n  (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ Sup S :=\nshow s ≤ Sup S, from le_Sup hs\n\nend non_assoc\n\nend submonoid\n\nnamespace free_monoid\n\nvariables {α : Type*}\n\nopen submonoid\n\n@[to_additive]\ntheorem closure_range_of : closure (set.range $ @of α) = ⊤ :=\neq_top_iff.2 $ λ x hx, free_monoid.rec_on x (one_mem _) $ λ 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 ⟨multiplicative.of_add 1, pow_one x⟩) $\n  λ x ⟨n, hn⟩, hn ▸ 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 ∈ closure ({x} : set M) ↔ ∃ n:ℕ, x^n=y :=\nby rw [closure_singleton_eq, mem_mrange]; refl\n\nlemma mem_closure_singleton_self {y : M} : y ∈ closure ({y} : set M) :=\nmem_closure_singleton.2 ⟨1, pow_one y⟩\n\nlemma closure_singleton_one : closure ({1} : set M) = ⊥ :=\nby simp [eq_bot_iff_forall, mem_closure_singleton]\n\n@[to_additive]\nlemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s → M)).mrange :=\nby rw [mrange_eq_map, ← free_monoid.closure_range_of, map_mclosure, ← set.range_comp,\n  free_monoid.lift_comp_of, subtype.range_coe]\n\n@[to_additive]\nlemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x ∈ closure s) :\n  ∃ (l : list M) (hl : ∀ y ∈ l, y ∈ s), l.prod = x :=\nbegin\n  rw [closure_eq_mrange, mem_mrange] at hx,\n  rcases hx with ⟨l, hx⟩,\n  exact ⟨list.map coe l, λ y hy, let ⟨z, hz, hy⟩ := list.mem_map.1 hy in hy ▸ z.2, hx⟩\nend\n\n/-- The submonoid generated by an element. -/\ndef powers (n : M) : submonoid M :=\nsubmonoid.copy (powers_hom M n).mrange (set.range ((^) n : ℕ → M)) $\nset.ext (λ n, exists_congr $ λ i, by simp; refl)\n\n@[simp] lemma mem_powers (n : M) : n ∈ powers n := ⟨1, pow_one _⟩\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 ∈ P) : powers n ≤ P :=\nλ x hx, match x, hx with _, ⟨i, rfl⟩ := P.pow_mem h i end\n\nend submonoid\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 ⊔ t = (s.subtype.coprod t.subtype).mrange :=\nby rw [mrange_eq_map, ← 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 ∈ s ⊔ t ↔ ∃ (y ∈ s) (z ∈ 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 nsmul_mem (S : add_submonoid A) {x : A} (hx : x ∈ S) :\n  ∀ n : ℕ, n • x ∈ S\n| 0     := by { rw zero_nsmul, exact S.zero_mem }\n| (n+1) := by { rw [add_nsmul, one_nsmul], exact S.add_mem (nsmul_mem n) hx }\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 ⟨1, one_nsmul x⟩) $\n  λ x ⟨n, hn⟩, hn ▸ 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 ∈ closure ({x} : set A) ↔ ∃ n:ℕ, n • x = y :=\nby rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl\n\nlemma closure_singleton_zero : closure ({0} : set A) = ⊥ :=\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 (λ i, nsmul i x : ℕ → A)) $\nset.ext (λ n, exists_congr $ λ i, by simp; refl)\n\n@[simp] lemma mem_multiples (x : A) : x ∈ multiples x := ⟨1, one_nsmul _⟩\n\nlemma multiples_eq_closure (x : A) : multiples x = closure {x} :=\nby { ext, exact mem_closure_singleton.symm }\n\nlemma multiples_subset {x : A} {P : add_submonoid A} (h : x ∈ P) : multiples x ≤ P :=\nλ x hx, match x, hx with _, ⟨i, rfl⟩ := P.nsmul_mem h i end\n\nattribute [to_additive add_submonoid.multiples] submonoid.powers\nattribute [to_additive add_submonoid.mem_multiples] submonoid.mem_powers\nattribute [to_additive add_submonoid.multiples_eq_closure] submonoid.powers_eq_closure\nattribute [to_additive add_submonoid.multiples_subset] submonoid.powers_subset\n\nend add_submonoid\n\n/-! Lemmas about additive closures of `submonoid`. -/\nnamespace submonoid\n\nvariables {R : Type*} [semiring R] (S : submonoid R) {a b : R}\n\n/-- The product of an element of the additive closure of a multiplicative submonoid `M`\nand an element of `M` is contained in the additive closure of `M`. -/\nlemma mul_right_mem_add_closure\n  (ha : a ∈ add_submonoid.closure (S : set R)) (hb : b ∈ S) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nbegin\n  revert b,\n  refine add_submonoid.closure_induction ha _ _ _; clear ha a,\n  { exact λ r hr b hb, add_submonoid.mem_closure.mpr (λ y hy, hy (S.mul_mem hr hb)) },\n  { exact λ b hb, by simp only [zero_mul, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw add_mul,\n    exact λ 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 ∈ add_submonoid.closure (S : set R)) (hb : b ∈ add_submonoid.closure (S : set R)) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nbegin\n  revert a,\n  refine add_submonoid.closure_induction hb _ _ _; clear hb b,\n  { exact λ r hr b hb, S.mul_right_mem_add_closure hb hr },\n  { exact λ b hb, by simp only [mul_zero, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw mul_add,\n    exact λ 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 ∈ S) (hb : b ∈ add_submonoid.closure (S : set R)) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nS.mul_mem_add_closure (add_submonoid.mem_closure.mpr (λ sT hT, hT ha)) hb\n\n@[to_additive]\nlemma mem_closure_inv {G : Type*} [group G] (S : set G) (x : G) :\n  x ∈ submonoid.closure S⁻¹ ↔ x⁻¹ ∈ submonoid.closure S :=\nbegin\n  suffices : ∀ (S : set G) (x : G), x ∈ submonoid.closure S⁻¹ → x⁻¹ ∈ submonoid.closure S,\n  { refine ⟨this S x, _⟩,\n    have := this S⁻¹ x⁻¹,\n    rw [inv_inv, set.inv_inv] at this,\n    exact this, },\n  intros S x hx,\n  refine submonoid.closure_induction hx (λ x hx, _) _ (λ x y hx hy, _),\n  { exact submonoid.subset_closure (set.mem_inv.mp hx), },\n  { rw one_inv,\n    exact submonoid.one_mem _ },\n  { rw mul_inv_rev x y,\n    exact submonoid.mul_mem _ hy hx },\nend\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 ⟨y, ⟨n, hy1⟩, hy2⟩,\n    use n,\n    simpa [← of_mul_pow, hy1] },\n  { rintros ⟨n, hn⟩,\n    refine ⟨x ^ n, ⟨n, rfl⟩, _⟩,\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": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/submonoid/membership.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8872045907347108, "lm_q1q2_score": 0.7708270953916501}}
{"text": "universe u\n\nnamespace or\n\n  section\n    \n    parameters { p q r : Prop }\n\n    lemma right_neutral\n      {p : Prop} : p ∨ false ↔ p\n    :=\n      begin\n        split,\n        show p → p ∨ false, from or.intro_left false,\n        show p ∨ false → p, by {\n          assume : p ∨ false,\n          cases this,\n            case or.inl {from ‹p›},\n            case or.inr {by {exfalso, assumption}}\n        },\n        done\n      end\n\n    lemma idempotent\n      { p : Prop } : p ∨ p ↔ p\n    := \n      begin\n        split,\n        show p → p ∨ p, by {assume : p, from or.inl ‹p›},\n        show p ∨ p → p, \n          by {\n            assume : p ∨ p, \n            cases this,\n              case or.inl {from ‹p›},\n              case or.inr {from ‹p›}\n          },\n          done\n      end\n\n    lemma equiv_left\n      { p q r : Prop } : (p ↔ q) → (p ∨ r ↔ q ∨ r)\n    :=\n      begin\n        assume : p ↔ q,\n        split,\n        show p ∨ r → q ∨ r,\n          by {\n            assume : p ∨ r,\n            cases this,\n              case or.inl {from or.inl (iff.elim_left ‹p ↔ q› ‹p›)},\n              case or.inr {from or.inr ‹r›},\n          },\n        show q ∨ r → p ∨ r,\n          by {\n            assume : q ∨ r,\n            cases this,\n              case or.inl {from or.inl (iff.elim_right ‹p ↔ q› ‹q›)},\n              case or.inr {from or.inr ‹r›},\n          },\n        done\n      end\n\n  end\n\nend or\n\nsection\n\n  parameters (α : Type u) (x y : α)\n\n  theorem mem_insert\n    {s : set α} : set.mem x (set.insert x s)\n  := \n    begin\n      -- change (set.mem x ({ a | a = x ∨ a ∈ s})),\n      -- change (({ a | a = x ∨ a ∈ s}) x),\n      -- change (x = x ∨ x ∈ s),\n      -- Lean gets here by itself\n      left,\n      refl,\n      done\n    end\n  -- an alternative (more natural/readable?) proof of mem_insert\n  example\n    {s : set α} : set.mem x (set.insert x s)\n  :=\n    begin\n      have : x = x, by trivial, -- specifically, by refl\n      have : x = x ∨ x ∈ s, by {left, from this}, \n                                --from or.intro_left (x ∈ s) this,\n      -- have : ({ a | a = x ∨ a ∈ s}) x, from this,\n      -- have : set.mem x ({ a | a = x ∨ a ∈ s }), from this,\n      -- Lean doesn't need these intermediate steps\n      show set.mem x ({ a | a = x ∨ a ∈ s }), from this,\n      -- show set.mem x (set.insert x s), from this,\n      done\n    end\n\n  theorem singleton_set_mem :\n    x ∈ ({ x } : set α)\n  :=\n    begin\n      -- change (set.mem x (set.insert x ∅)),\n      -- Lean automatically translates the notation x ∈ { x }\n      apply mem_insert,\n      done\n    end\n  -- So, it is just an application of mem_insert\n  example :\n    x ∈ ({ x } : set α)\n  :=\n    by apply mem_insert\n  -- Forward proof of singleton_set_mem\n  example :\n    x ∈ ({ x } : set α)\n  :=\n    begin\n      have : set.mem x (set.insert x ∅), by apply mem_insert,\n      show set.mem x ({ x }), from this,\n      done\n    end\n\n  theorem set_swap\n    {s : set α} {x y : α}\n      : set.insert x (set.insert y s) = set.insert y (set.insert x s)\n  :=\n    calc\n      { a | a = x ∨ a = y ∨ a ∈ s } = { a | a = y ∨ a = x ∨ a ∈ s }\n        : by {congr, funext, from propext or.left_comm}\n  -- Trying to do a more explicit calculational proof\n  example\n    {s : set α} {x y : α}\n      : set.insert x (set.insert y s) = set.insert y (set.insert x s)\n  :=\n      -- Note, refl is the tactic that checks definitional equality\n      calc\n        set.insert x (set.insert y s)\n          -- Don't need these intermediate steps\n          --     = { a | a = x ∨ a ∈ (set.insert y s)}\n          --         : by refl\n          -- ... = { a | a = x ∨ a ∈ { b | b = y ∨ b ∈ s}}\n          --         : by refl\n          -- ... \n              = { a | a = x ∨ a = y ∨ a ∈ s }\n                  : by refl\n\n          -- The key step\n          ... = { a | a = y ∨ a = x ∨ a ∈ s }\n                -- This is really set_of (λ a, a = y ∨ a = x ∨ a ∈ s)\n                  : by {congr, funext, from propext or.left_comm}\n\n          -- Again, we don't need these intermediate steps\n          -- ... = { a | a = y ∨ a ∈ { b | b = x ∨ b ∈ s}}\n          --         : by refl\n          -- ... = { a | a = y ∨ a ∈ (set.insert x s)}\n          --         : by refl\n\n          -- And Lean can even fill in the second half of the calculation\n          -- automatically.\n          ... = set.insert y (set.insert x s)\n                  : by refl\n  -- 'Explicit' proof of set_swap\n  example\n    {s : set α} {x y : α}\n      : set.insert x (set.insert y s) = set.insert y (set.insert x s)\n  :=\n    begin\n      have _1 : set.insert x (set.insert y s) = { a | a = x ∨ a = y ∨ a ∈ s },\n        by refl,\n      have _2 : { a | a = y ∨ a = x ∨ a ∈ s } = set.insert y (set.insert x s),\n        by refl,\n      have _3 : { a | a = x ∨ a = y ∨ a ∈ s } = { a | a = y ∨ a = x ∨ a ∈ s },\n        by {congr, funext, from propext or.left_comm},\n\n      -- Here, we can just tell Lean to use facts in the context, and it\n      -- fills in the necessary chaining of equalities:\n\n      -- show set.insert x (set.insert y s) = set.insert y (set.insert x s),\n      --   by {assumption},\n\n      -- We can also use the tactic language to manipulate the goal and\n      -- apply facts one at a time:\n\n      -- show set.insert x (set.insert y s) = set.insert y (set.insert x s),\n      --   by {transitivity, assumption, transitivity, exact this, assumption},\n\n      -- But although this makes it clear which reasoning principles are being\n      -- used, it isn't at all obvious how these are applied.\n\n      -- Maybe this is better?:\n      show set.insert x (set.insert y s) = set.insert y (set.insert x s),\n        -- from eq.trans (eq.trans _1 _3) _2,\n        from eq.trans \n              (eq.trans\n                ‹set.insert x (set.insert y s) = { a | a = x ∨ a = y ∨ a ∈ s }›\n                ‹{ a | a = x ∨ a = y ∨ a ∈ s } = { a | a = y ∨ a = x ∨ a ∈ s }›)\n                ‹{ a | a = y ∨ a = x ∨ a ∈ s } = set.insert y (set.insert x s)›,\n\n      done\n    end\n\n  -- The set notation { x₁, ..., xₙ } is short-hand for\n  --   fold_left set.insert ∅ [x₁, ..., xₙ]\n  -- So, {x, y} = fold_left set.insert ∅ [x, y] = set.insert y (set.insert x ∅)\n  example :\n    ({x, y} : set α) = set.insert x {y}\n  :=\n    by apply set_swap\n\n  theorem set_eq_iff_subsets\n    {s₁ s₂ : set α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁\n  :=\n    begin\n      split, -- split bi-implication into individual implications\n\n      -- show left-to-right\n      show s₁ = s₂ → s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, by {\n        assume : s₁ = s₂,\n        split, -- show the two conjuncts individually\n\n        show s₁ ⊆ s₂,\n        suffices : ∀ x, x ∈ s₁ → x ∈ s₂, from this, by {\n          intros,\n          show x ∈ s₂, from eq.subst ‹s₁ = s₂› ‹x ∈ s₁›,\n        },\n\n        show s₂ ⊆ s₁,\n        suffices : ∀ x, x ∈ s₂ → x ∈ s₁, from this, by {\n          intros,\n          show x ∈ s₁, from eq.subst (eq.symm ‹s₁ = s₂›) ‹x ∈ s₂›,\n        },\n\n        done\n      },\n\n      -- show right-to-left\n      show s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ → s₁ = s₂, by {\n        assume : s₁ ⊆ s₂ ∧ s₂ ⊆ s₁,\n        have : s₁ ⊆ s₂, from and.left ‹s₁ ⊆ s₂ ∧ s₂ ⊆ s₁›,\n        have : s₂ ⊆ s₁, from and.right ‹s₁ ⊆ s₂ ∧ s₂ ⊆ s₁›,\n\n        have : ∀ x, x ∈ s₁ ↔ x ∈ s₂, by {\n          assume x,\n          split,\n          show x ∈ s₁ → x ∈ s₂,\n            by {assume : x ∈ s₁, show x ∈ s₂, from ‹s₁ ⊆ s₂› this},\n          show x ∈ s₂ → x ∈ s₁,\n            by {assume : x ∈ s₂, show x ∈ s₁, from ‹s₂ ⊆ s₁› this},\n          done\n        },\n\n        show s₁ = s₂,\n        suffices : ∀ (x : α), (x ∈ s₁) = (x ∈ s₂),\n          from funext this,\n        by {\n          assume x,\n          have : x ∈ s₁ ↔ x ∈ s₂, from ‹∀ x, x ∈ s₁ ↔ x ∈ s₂› x,\n          show (x ∈ s₁) = (x ∈ s₂), from propext this,\n          done\n        },\n         \n        done\n      },\n\n      -- and we are done\n      done\n    end\n\n  lemma set_eq_imp_subset_left\n    {s₁ s₂ : set α} : s₁ = s₂ → s₁ ⊆ s₂\n  := \n    λ eq, and.left (iff.elim_left (set_eq_iff_subsets) eq)\n  -- Explicit proof\n  example\n    {s₁ s₂ : set α} : s₁ = s₂ → s₁ ⊆ s₂\n  := \n    begin\n      intros,\n      have : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, from set_eq_iff_subsets,\n      have : s₁ = s₂ → s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, from iff.elim_left this,\n      have : s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, from this ‹s₁ = s₂›,\n      show s₁ ⊆ s₂, from and.elim_left this,\n      done\n    end\n\n  lemma set_eq_imp_subset_right\n    {s₁ s₂ : set α} : s₁ = s₂ → s₂ ⊆ s₁\n  := \n    λ eq, and.right (iff.elim_left (set_eq_iff_subsets) eq)\n  -- Explicit proof\n  example\n    {s₁ s₂ : set α} : s₁ = s₂ → s₂ ⊆ s₁\n  := \n    begin\n      intros,\n      have : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, from set_eq_iff_subsets,\n      have : s₁ = s₂ → s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, from iff.elim_left this,\n      have : s₁ ⊆ s₂ ∧ s₂ ⊆ s₁, from this ‹s₁ = s₂›,\n      show s₂ ⊆ s₁, from and.elim_right this,\n      done\n    end\n\n  -- s₁ ⊆ s₂ is notation for set.subset s₁ s₂, which is definitionally equal to\n  --   ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂\n  -- so we can directly derive (a witness for) x ∈ s₂ by passing (a witness for)\n  -- x ∈ s₁ to (a witness for) s₁ ⊆ s₂, with Lean automatically instantiating\n  -- the universal quantifier\n  example\n    (s₁ s₂ : set α) (x : α) : s₁ ⊆ s₂ → x ∈ s₁ → x ∈ s₂\n  :=\n    begin\n      intros,\n      show x ∈ s₂, from ‹s₁ ⊆ s₂› ‹x ∈ s₁›,\n      done\n    end\n  -- We can make the definition of ⊆ and the instantiation of the universal\n  -- quantifier explicit.\n  example\n    (s₁ s₂ : set α) (x : α) : s₁ ⊆ s₂ → x ∈ s₁ → x ∈ s₂\n  :=\n    begin\n      assume : s₁ ⊆ s₂, assume : x ∈ s₁,\n      have : ∀ y, y ∈ s₁ → y ∈ s₂, from ‹s₁ ⊆ s₂›,\n      have : x ∈ s₁ → x ∈ s₂, from this x,\n      show x ∈ s₂, from this ‹x ∈ s₁›,\n      done\n    end\n\n  lemma set_eq_imp_mem_preserve\n    {s₁ s₂ : set α} {x : α} : s₁ = s₂ → x ∈ s₁ → x ∈ s₂\n  :=\n    begin\n      intros,\n      have : s₁ ⊆ s₂, from set_eq_imp_subset_left ‹s₁ = s₂›,\n      show x ∈ s₂, from ‹s₁ ⊆ s₂› ‹x ∈ s₁›,\n      done\n    end\n\n  lemma singleton_set_case_split\n    {x y : α} : y ∈ ({x} : set α) → y = x\n  :=\n    begin\n      intros,\n      have : { x } = { y | y = x }, by \n        calc\n          { x } \n             -- = { y | y = x ∨ y ∈ ∅ } : by refl ...\n                = { y | y = x ∨ false }\n                    : by refl\n            ... = { y | y = x }\n                    : by {congr, funext, from propext or.right_neutral},\n\n      have : y ∈ { y | y = x },\n        from set_eq_imp_mem_preserve this ‹y ∈ {x}›,\n      show y = x, from this,\n      done\n    end\n\n  lemma two_element_set_case_split\n    {x y z : α} : z ∈ ({x, y} : set α) → z = x ∨ z = y\n  := \n    begin\n\n      have : {x, y} = { b | b = x ∨ b = y },\n        by calc\n          {x, y}\n            --  = { b | b = y ∨ b = x ∨ b ∈ ∅ } : by refl ... \n                = { b | b = y ∨ b = x ∨ false }  : by refl\n            ... = { b | (b = y ∨ b = x) ∨ false }\n                    : by {congr, funext, from eq.symm (propext or.assoc)}\n            ... = { b | b = y ∨ b = x } \n                    : by {congr, funext, from propext or.right_neutral}\n            ... = { b | b = x ∨ b = y}\n                    : by {congr, funext, from propext or.comm},\n\n      assume : z ∈ {x, y},\n\n      have : z ∈ { b | b = x ∨ b = y },\n        from set_eq_imp_mem_preserve ‹{x, y} = { b | b = x ∨ b = y }› this,\n\n      show z = x ∨ z = y, from this,\n\n      done\n\n    end\n\n  lemma remove_duplicates\n    { s : set α } { x : α } : set.insert x (set.insert x s) = set.insert x s\n  := \n    by calc\n      set.insert x (set.insert x s)\n           = { z | z = x ∨ z = x ∨ z ∈ s } : by refl\n       ... = { z | (z = x ∨ z = x) ∨ z ∈ s } \n                : by {congr, funext, from eq.symm (propext or.assoc)}\n       ... = { z | z = x ∨ z ∈ s }\n                : by {congr, funext, from propext (or.equiv_left or.idempotent)}\n       ... = set.insert x s : by refl\n\n  lemma duplicate_to_singleton\n    { x : α } : {x, x} = ({x} : set α)\n  := by apply remove_duplicates\n\nend\n\nsection\n\n  parameters (α : Type u) (a₁ a₂ : α) (b₁ b₂ : α)\n\n  -- The set-theoretic encoding of ordered pairs\n  def pair (x y : α) : set (set α) := {{x}, {x, y}}\n\n  -- Two arbitrary ordered pairs\n  def A := pair a₁ a₂\n  def B := pair b₁ b₂\n\n  -- Soundness\n  -- If the elements are (pairwise) equal, then the ordered pairs are equal.\n  theorem soundness :\n    a₁ = b₁ ∧ a₂ = b₂ → A = B\n  :=\n    begin\n      assume : a₁ = b₁ ∧ a₂ = b₂,\n      have : a₁ = b₁, by {apply and.elim_left, assumption},\n      have : a₂ = b₂, by {apply and.elim_right, assumption},\n      calc\n        A     = {{a₁}, {a₁, a₂}}\n                  : by refl\n          ... = {{b₁}, {b₁, b₂}}\n                  : by {congr,\n                        -- Only need this proposition once\n                        from ‹a₂ = b₂›,\n                        -- But we need this one twice\n                        repeat {from ‹a₁ = b₁›}}\n          ... = B : by refl\n    end\n\n  -- For adequcy, we will need the following collapsing lemma\n  lemma collapse\n    { x y : α } : x = y → ({{x}, {x, y}} : set (set α)) = {{y}}\n  :=\n    begin\n      assume : x = y,\n      calc\n        ({{x}, {x, y}} : set (set α))\n              = {{y}, {y, y}} : by {apply eq.subst ‹x = y›, refl}\n          ... = set.insert {y, y} ({{y}}) : by refl\n          ... = set.insert {y} ({{y}})\n                  : (congr_fun \n                      (congr_arg set.insert (duplicate_to_singleton α)))\n                      {{y}}\n          ... = {{y}, {y}} : by refl\n          ... = {{y}} : by apply duplicate_to_singleton,\n    end\n\n  -- Adequacy\n  -- If the order pairs are equal, then the elements are (pairwise) equal.\n  theorem adequacy :\n    A = B → a₁ = b₁ ∧ a₂ = b₂\n  :=\n    begin\n      assume : A = B,\n\n      -- It doesn't matter in which order we enumerate the elements of sets\n      have : ({{a₁}, {a₁, a₂}} : set (set α)) = {{a₁, a₂}, {a₁}},\n        by apply set_swap,\n      have : ({{b₁}, {b₁, b₂}} : set (set α)) = {{b₁, b₂}, {b₁}},\n        by apply set_swap,\n      have : ({a₁, a₂} : set α) = {a₂, a₁},\n        by apply set_swap,\n      have : ({b₁, b₂} : set α) = {b₂, b₁},\n        by apply set_swap,\n\n      -- We derive some basic facts about (the members of) the members of A\n      have : A = {{a₁}, {a₁, a₂}}, by refl,\n\n      have : {a₁} ∈ A, by {\n        -- since {a₁} ∈ {{a₁, a₂}, {a₁}}, as A = {{a₁, a₂}, {a₁}},\n        apply eq.substr \n          (eq.trans ‹A = {{a₁}, {a₁, a₂}}›\n                        ‹{{a₁}, {a₁, a₂}} = {{a₁, a₂}, {a₁}}›),\n        -- using the mem_insert lemma\n        apply mem_insert,\n        done\n      },\n\n      have : {a₁, a₂} ∈ A, by {\n        apply eq.substr ‹A = {{a₁}, {a₁, a₂}}›,\n        apply mem_insert,\n        done\n      },\n\n      have : a₁ ∈ {a₁, a₂}, by {\n        apply eq.substr ‹{a₁, a₂} = {a₂, a₁}›,\n        apply mem_insert,\n        done\n      },\n\n        -- We need the set α type ascription here\n      have : a₂ ∈ ({a₁, a₂} : set α), by apply mem_insert,\n\n      -- We derive some basic facts about (the members of) the members of B\n      have : B = {{b₁}, {b₁, b₂}}, by refl,\n\n      have : {b₁} ∈ B, by {\n        -- since {b₁} ∈ {{b₁, b₂}, {b₁}}, as B = {{b₁, b₂}, {b₁}},\n        apply eq.substr \n          (eq.trans ‹B = {{b₁}, {b₁, b₂}}›\n                        ‹{{b₁}, {b₁, b₂}} = {{b₁, b₂}, {b₁}}›),\n        -- using the mem_insert lemma\n        apply mem_insert,\n        done\n      },\n\n      have : {b₁, b₂} ∈ B, by {\n        apply eq.substr ‹B = {{b₁}, {b₁, b₂}}›,\n        apply mem_insert,\n      },\n\n      have : b₁ ∈ {b₁, b₂}, by {\n        apply eq.substr ‹{b₁, b₂} = {b₂, b₁}›,\n        apply mem_insert,\n        done\n      },\n\n        -- We need the set α type ascription here\n      have : b₂ ∈ ({b₁, b₂} : set α), by apply mem_insert,\n\n      -- Since A = B, A and B are subsets of one another\n      have : A ⊆ B, by {apply set_eq_imp_subset_left, from ‹A = B›},\n      have : B ⊆ A, by {apply set_eq_imp_subset_right, from ‹A = B›},\n\n      -- Therefore\n      have : {a₁} ∈ B, from ‹A ⊆ B› ‹{a₁} ∈ A›,\n      have : {a₁} ∈ {{b₁}, {b₁, b₂}},\n        by {apply eq.subst ‹B = {{b₁}, {b₁, b₂}}›, from this},\n\n      -- Now there are two possibilities\n      cases two_element_set_case_split (set α) this,\n\n      -- the case that {a₁} = {b₁}\n      case or.inl {\n        have : a₁ ∈ {a₁}, by apply singleton_set_mem,\n        have : a₁ ∈ ({b₁} : set α), \n          by {apply set_eq_imp_mem_preserve α ‹{a₁} = {b₁}›, from this},\n        have : a₁ = b₁, by {apply singleton_set_case_split, from this},\n\n        -- We have to show both a₁ = b₁ and a₂ = b₂\n        split,\n        -- We already have the left-hand conjunct\n        show a₁ = b₁, from this,\n\n        have : {a₁, a₂} ∈ {{b₁}, {b₁, b₂}},\n          by {apply eq.subst ‹B = {{b₁}, {b₁, b₂}}›,\n                from ‹A ⊆ B› ‹{a₁, a₂} ∈ A›},\n\n        cases two_element_set_case_split (set α) this,\n\n        -- The case that {a₁, a₂} = {b₁}\n        case or.inl {\n          have : a₂ = b₁, \n            by {\n              apply singleton_set_case_split,\n              apply set_eq_imp_mem_preserve α ‹{a₁, a₂} = {b₁}›,\n              from ‹a₂ ∈ {a₁, a₂}›\n            },\n          have : a₁ = a₂, from eq.trans ‹a₁ = b₁› (eq.symm this),\n          have : A = {{a₂}},\n            by calc\n              A     = {{a₁}, {a₁, a₂}} : by refl\n                ... = {{a₂}} : by {apply collapse, from this},\n          have : {b₁, b₂} = {a₂},\n            by {\n              -- since {b₁, b₂} ∈ {{a₂}}\n              apply singleton_set_case_split,\n              -- since A = {{a₂}}\n              apply eq.subst this,\n              -- and {b₁, b₂} ∈ B and B ⊆ A\n              from ‹B ⊆ A› ‹{b₁, b₂} ∈ B›,\n            },\n          have : b₂ = a₂,\n            by {\n              -- since b₂ in {a₂}\n              apply singleton_set_case_split,\n              -- since we have just shown {b₁, b₂} = {a₂}\n              apply set_eq_imp_mem_preserve α this,\n              -- and also we have that b₂ ∈ {b₁, b₂}\n              from ‹b₂ ∈ {b₁, b₂}›\n            },\n          -- Thus we have the right-hand conjunct\n          show a₂ = b₂, by {symmetry, from this},\n          done\n        },\n\n        -- The case that {a₁, a₂} = {b₁, b₂}\n        case or.inr {\n          have : {b₁, b₂} = {a₁, a₂}, by {symmetry, from ‹{a₁, a₂} = {b₁, b₂}›},\n          have : b₂ ∈ {a₁, a₂},\n            by {apply set_eq_imp_mem_preserve, from this, from ‹b₂ ∈ {b₁, b₂}›},\n          -- Now, again, we have two further cases\n          cases two_element_set_case_split α this,\n            -- The case that b₂ = a₁\n            case or.inl {\n              have : b₁ = b₂,\n                from eq.trans (eq.symm ‹a₁ = b₁›) (eq.symm ‹b₂ = a₁›),\n              have : {a₁, a₂} = {b₂},\n                by calc\n                  {a₁, a₂} = {b₁, b₂} : by assumption\n                       ... = {b₂, b₂} : by {apply eq.subst ‹b₁ = b₂›, refl}\n                       ... = {b₂}     : by {apply remove_duplicates},\n              -- Therefore, we can show the right-hand conjunct\n              show a₂ = b₂,\n                by {\n                  -- since a₂ ∈ {b₂}\n                  apply singleton_set_case_split,\n                  -- since we have just show that {a₁, a₂} = {b₂}\n                  apply set_eq_imp_mem_preserve α this,\n                  -- and also we have a₂ ∈ {a₁, a₂}\n                  from ‹a₂ ∈ {a₁, a₂}›,\n                },\n                done\n            },\n            -- The case that b₂ = a₂\n            case or.inr {\n              -- immediate\n              show a₂ = b₂, by {symmetry, from ‹b₂ = a₂›}, done\n            },\n           done\n        },\n\n        done\n      },\n\n      -- the case that {a₁} = {b₁, b₂}\n      case or.inr {\n        have : ({b₁, b₂} : set α) ⊆ {a₁},\n          by {apply set_eq_imp_subset_right, from ‹{a₁} = {b₁, b₂}›},\n        have : b₁ ∈ {a₁}, \n          by {apply set_eq_imp_subset_left,\n              from eq.symm ‹{a₁} = {b₁, b₂}›, from ‹b₁ ∈ {b₁, b₂}›},\n        have : b₁ = a₁,\n          by {apply singleton_set_case_split, from this},\n\n        -- We have to show both a₁ = b₁ and a₂ = b₂\n        split,\n        -- We already have the left-hand conjunct\n        show a₁ = b₁, by {symmetry, from this},\n\n        -- Now for the right-hand conjunct\n        have : b₂ ∈ {a₁},\n          by {apply set_eq_imp_subset_left,\n              from eq.symm ‹{a₁} = {b₁, b₂}›, from ‹b₂ ∈ {b₁, b₂}›},\n        have : a₁ = b₂,\n          by {symmetry, apply singleton_set_case_split, from this},\n        have : b₁ = b₂, by {transitivity, from ‹b₁ = a₁›, from ‹a₁ = b₂›},\n        have : B = {{b₂}},\n          by calc\n            B     = {{b₁}, {b₁, b₂}} : by refl\n              ... = {{b₂}} : by {apply collapse, from this},\n        have : {a₁, a₂} ∈ B, \n          by {apply set_eq_imp_mem_preserve, from ‹A = B›, from ‹{a₁, a₂} ∈ A›},\n        have : {a₁, a₂} ∈ {{b₂}}, by {apply eq.subst ‹B = {{b₂}}›, from this},\n        have : {a₁, a₂} = {b₂}, by {apply singleton_set_case_split, from this},\n        have : {a₁, a₂} ⊆ ({b₂} : set α),\n          by {apply set_eq_imp_subset_left, from this},\n        have : a₂ ∈ {b₂}, from this ‹a₂ ∈ {a₁, a₂}›,\n\n        -- This gives the right-hand conjunct\n        show a₂ = b₂, by {apply singleton_set_case_split, from this},\n        done\n      },\n\n      done\n\n    end\n\nend", "meta": {"author": "reubenrowe", "repo": "lean-experiments", "sha": "368760f0e49b674e124f95b18d2879b10ce7ff72", "save_path": "github-repos/lean/reubenrowe-lean-experiments", "path": "github-repos/lean/reubenrowe-lean-experiments/lean-experiments-368760f0e49b674e124f95b18d2879b10ce7ff72/set_pairs/src/pairs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7707195591610124}}
{"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 : ℕ) := (n - m) + (m - n)\n\ntheorem dist.def (n m : ℕ) : dist n m = (n - m) + (m - n) := rfl\n\n@[simp] theorem dist_comm (n m : ℕ) : dist n m = dist m n :=\nby simp [dist.def]\n\n@[simp] theorem dist_self (n : ℕ) : dist n n = 0 :=\nby simp [dist.def, nat.sub_self]\n\ntheorem eq_of_dist_eq_zero {n m : ℕ} (h : dist n m = 0) : n = m :=\nhave n - m = 0, from eq_zero_of_add_eq_zero_right h,\nhave n ≤ m, from nat.le_of_sub_eq_zero this,\nhave m - n = 0, from eq_zero_of_add_eq_zero_left h,\nhave m ≤ n, from nat.le_of_sub_eq_zero this,\nle_antisymm ‹n ≤ m› ‹m ≤ n›\n\ntheorem dist_eq_zero {n m : ℕ} (h : n = m) : dist n m = 0 :=\nbegin rw [h, dist_self] end\n\n\n\ntheorem dist_eq_sub_of_ge {n m : ℕ} (h : n ≥ m) : dist n m = n - m :=\nbegin rw [dist_comm], apply dist_eq_sub_of_le h end\n\ntheorem dist_zero_right (n : ℕ) : dist n 0 = n :=\neq.trans (dist_eq_sub_of_ge (zero_le n)) (nat.sub_zero n)\n\ntheorem dist_zero_left (n : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ} (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 : ℕ) : n - k ≤ (n - m) + (m - k) :=\nor.elim (le_total k m)\n  (assume : k ≤ m,\n    begin rw ←nat.add_sub_assoc this, apply nat.sub_le_sub_right, apply nat.le_sub_add end)\n  (assume : k ≥ 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 : ℕ) : dist n k ≤ 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 : ℕ) : 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 : ℕ) : 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 ≥ 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 ≠ j → 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": "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/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7707194401619285}}
{"text": "import tactic \nimport data.real.basic\n\nsection\n\nvariables {A : Type}\nvariables {R : A → A → Prop}\n\ntheorem represents : (∃ f : A → ℝ, ∀ x , ∀ y, f y ≤ f x ↔ R x y) → transitive R ∧ total R := \nbegin\n  intro h,\n  cases h with f rep,\n  split,\n  {\n    rw [transitive],\n    intros x y z,\n    have repxy : f y ≤ f x ↔ R x y, from rep x y,\n    have repyz : f z ≤ f y ↔ R y z, from rep y z,\n    have repxz : f z ≤ f x ↔ R x z, from rep x z,\n    cases repxy with fxfyRxy Rxyfxfy,\n    cases repyz with fyfzRyz Ryzfyfz,\n    cases repxz with fxfzRxz Rxzfxfz,\n    have trnsF : f z ≤ f y → f y ≤ f x → f z ≤ f x , from le_trans,\n    tauto,\n  },\n  {\n    rw [total],\n    intro x,\n    intro y,\n    have repxy : f y ≤ f x ↔ R x y, from rep x y,\n    have repyx : f x ≤ f y ↔ R y x, from rep y x,\n    cases repxy with fxfyRxy Rxyfxfy,\n    cases repyx with fyfxRyx Ryxfyfx,\n    have compF : f y ≤ f x ∨ f x ≤ f y, from le_total (f y) (f x),\n    tauto,\n   },\nend\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/MWG_1_B_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7706953053560945}}
{"text": "import algebra.group_power algebra.big_operators data.nat.choose\nlocal infix ` ^ ` := monoid.pow\nopen finset nat\nvariable {α : Type*}\n\nlocal notation f ` ∑ ` : 90 n : 90  := finset.sum (finset.range n) f\n\nlemma sum_range_succ [add_comm_monoid α] (f : ℕ → α) (n : ℕ) : f ∑ succ n = f n + f ∑ n :=\nhave h : n ∉ finset.range n := by rw finset.mem_range; exact lt_irrefl _,\nby rw [finset.range_succ, finset.sum_insert h]\n\nlemma sum_range_succ' [add_comm_monoid α] (f : ℕ → α) : \n    ∀ n : ℕ, f ∑ succ n = (λ m, f (succ m)) ∑ n + f 0\n| 0        := by simp\n| (succ n) := by rw [sum_range_succ (λ m, f (succ m)), add_assoc, ← sum_range_succ'];\n                 exact sum_range_succ _ _\n\ntheorem add_pow [comm_semiring α] (x y : α) : ∀ n : ℕ,\n    (x + y)^n = (λ m, x^m * y^(n - m) * choose n m) ∑ succ n\n| 0        := by simp\n| (succ n) :=\nhave h₁ : 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₂ : 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₃ : (λ m, x * (x^m * y^(n - m) * choose n m) + y * (x^succ m * y^(n - succ m)\n    * choose n (succ m))) ∑ n \n    = (λ m, x^succ m * y^(succ n - succ m) * ↑(choose (succ n) (succ m))) ∑ n := \n  finset.sum_congr rfl $ λ m hm, begin \n      rw finset.mem_range at hm,\n      rw [← mul_assoc y, ← mul_assoc y, mul_right_comm y, ← _root_.pow_succ, add_one, ← 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, ← add_assoc (_ ∑ n), ← finset.sum_add_distrib, h₁, h₂, h₃]\n\ntheorem missing [comm_semiring α] (n : ℕ) (f : ℕ → α) (e : ℕ → ℕ) (r : ℕ → α)\n    (s : α) : (∀ i : ℕ, i ≤ n → (f i) ^ (e i) * s = 0) →\n    (sum (range (succ n)) (λ i, f i * r i)) ^ (sum (range (succ n)) e) * s = 0 :=\nnat.rec_on n (λ h, by simp [mul_pow, mul_right_comm, h 0 (le_refl _)])\n$ λ n hi h, begin \n  rw [sum_range_succ, add_pow, sum_mul, ← @sum_const_zero _ _ (range (succ (e ∑ succ (succ n))))],\n  refine finset.sum_congr rfl (λ m hm, _),\n  cases le_total m (e (succ n)) with hm' hm',\n  { rw [sum_range_succ e, add_comm (e _), nat.add_sub_assoc hm', _root_.pow_add],\n    simp only [mul_assoc, mul_left_comm ((λ (i : ℕ), f i * r i) ∑ succ n ^ e ∑ succ n)],\n    rw hi (λ i hi, h i (le_succ_of_le hi)),\n    simp },\n  { rw [← nat.add_sub_cancel' hm', _root_.pow_add, mul_pow],\n    simp only [mul_assoc, mul_left_comm (f (succ n) ^ e (succ n)), h],\n    simp }\nend\n\ntheorem missing1 [comm_semiring α] (n : ℕ) (f : ℕ → α) (e : ℕ → ℕ) (r : ℕ → α)\n    (s : α) : (∀ i : ℕ, i < n → (f i) ^ (e i) * s = 0) → \n    sum (range n) (λ i, f i * r i) = 1 → s = 0 :=\nnat.cases_on n (λ h₁ (h₂ : 0 = 1), mul_zero s ▸ h₂.symm ▸ (mul_one s).symm) $ λ n h₁ h₂, begin\n  have := missing n f e r s (λ i hi, h₁ i (lt_succ_of_le hi)),\n  rwa [sum_range_succ e, _root_.pow_add, h₂, one_pow, one_pow, one_mul, one_mul] at this,\nend\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff1", "sha": "cbcd788b8b1d07b20b2fff4482c870077a13d1c0", "save_path": "github-repos/lean/ChrisHughes24-leanstuff1", "path": "github-repos/lean/ChrisHughes24-leanstuff1/leanstuff1-cbcd788b8b1d07b20b2fff4482c870077a13d1c0/ring_thing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922388, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.7706287028913106}}
{"text": "-- let X, Y, Z be sets.\nvariables {X Y Z : Type} \n\n-- a function f : X → Y is *injective* if f(a) = f(b) → a = b for all a,b in X.\ndef injective (f : X → Y)  : Prop :=\n∀ a b : X, f(a) = f(b) → a = b\n\n-- challenge: the composite of two injective functions is injective\ntheorem challenge1\n  (f : X → Y) (hf : injective f)\n  (g : Y → Z) (hg : injective g) :\ninjective (g ∘ 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 ∘ f) a = (g ∘ f) b\n  intro hab,\n  -- The goal is now ⊢ 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", "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/solution1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922389, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7706286904820382}}
{"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! This file was ported from Lean 3 source module algebra.order.ring.abs\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.Ring.Defs\nimport Mathlib.Algebra.Ring.Divisibility\nimport Mathlib.Algebra.Order.Group.Abs\n\n/-!\n# Absolute values in linear ordered rings.\n-/\n\n\nvariable {α : Type _}\n\nsection LinearOrderedRing\n\nvariable [LinearOrderedRing α] {a b c : α}\n\n@[simp]\ntheorem abs_one : |(1 : α)| = 1 :=\n  abs_of_pos zero_lt_one\n#align abs_one abs_one\n\n@[simp]\ntheorem abs_two : |(2 : α)| = 2 :=\n  abs_of_pos zero_lt_two\n#align abs_two abs_two\n\ntheorem abs_mul (a b : α) : |a * b| = |a| * |b| := by\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_iff, or_true_iff, eq_self_iff_true, neg_mul,\n      mul_neg, neg_neg, *]\n#align abs_mul abs_mul\n\n/-- `abs` as a `MonoidWithZeroHom`. -/\ndef absHom : α →*₀ α :=\n  { toFun := abs\n    map_zero' := abs_zero\n    map_one' := abs_one\n    map_mul' :=  abs_mul }\n#align abs_hom absHom\n\n@[simp]\ntheorem abs_mul_abs_self (a : α) : |a| * |a| = a * a :=\n  abs_by_cases (fun x => x * x = a * a) rfl (neg_mul_neg a a)\n#align abs_mul_abs_self abs_mul_abs_self\n\n@[simp]\ntheorem abs_mul_self (a : α) : |a * a| = a * a := by rw [abs_mul, abs_mul_abs_self]\n#align abs_mul_self abs_mul_self\n\n@[simp]\ntheorem abs_eq_self : |a| = a ↔ 0 ≤ a := by simp [abs_eq_max_neg]\n#align abs_eq_self abs_eq_self\n\n@[simp]\ntheorem abs_eq_neg_self : |a| = -a ↔ a ≤ 0 := by simp [abs_eq_max_neg]\n#align abs_eq_neg_self abs_eq_neg_self\n\n/-- For an element `a` of a linear ordered ring, either `abs a = a` and `0 ≤ a`,\n    or `abs a = -a` and `a < 0`.\n    Use cases on this lemma to automate linarith in inequalities -/\ntheorem abs_cases (a : α) : |a| = a ∧ 0 ≤ a ∨ |a| = -a ∧ a < 0 := by\n  by_cases h : 0 ≤ a\n  · left\n    exact ⟨abs_eq_self.mpr h, h⟩\n  · right\n    push_neg at h\n    exact ⟨abs_eq_neg_self.mpr (le_of_lt h), h⟩\n#align abs_cases abs_cases\n\n@[simp]\ntheorem max_zero_add_max_neg_zero_eq_abs_self (a : α) : max a 0 + max (-a) 0 = |a| := by\n  symm\n  rcases le_total 0 a with (ha | ha) <;> simp [ha]\n#align max_zero_add_max_neg_zero_eq_abs_self max_zero_add_max_neg_zero_eq_abs_self\n\ntheorem abs_eq_iff_mul_self_eq : |a| = |b| ↔ a * a = b * b := by\n  rw [← abs_mul_abs_self, ← abs_mul_abs_self b]\n  exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm\n#align abs_eq_iff_mul_self_eq abs_eq_iff_mul_self_eq\n\ntheorem abs_lt_iff_mul_self_lt : |a| < |b| ↔ a * a < b * b := by\n  rw [← abs_mul_abs_self, ← abs_mul_abs_self b]\n  exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)\n#align abs_lt_iff_mul_self_lt abs_lt_iff_mul_self_lt\n\ntheorem abs_le_iff_mul_self_le : |a| ≤ |b| ↔ a * a ≤ b * b := by\n  rw [← abs_mul_abs_self, ← abs_mul_abs_self b]\n  exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)\n#align abs_le_iff_mul_self_le abs_le_iff_mul_self_le\n\ntheorem abs_le_one_iff_mul_self_le_one : |a| ≤ 1 ↔ a * a ≤ 1 := by\n  simpa only [abs_one, one_mul] using @abs_le_iff_mul_self_le α _ a 1\n#align abs_le_one_iff_mul_self_le_one abs_le_one_iff_mul_self_le_one\n\nend LinearOrderedRing\n\nsection LinearOrderedCommRing\n\nvariable [LinearOrderedCommRing α] {a b c d : α}\n\ntheorem abs_sub_sq (a b : α) : |a - b| * |a - b| = a * a + b * b - (1 + 1) * a * b := by\n  rw [abs_mul_abs_self]\n  simp only [mul_add, add_comm, add_left_comm, mul_comm, sub_eq_add_neg, mul_one, mul_neg,\n    neg_add_rev, neg_neg, add_assoc]\n#align abs_sub_sq abs_sub_sq\n\nend LinearOrderedCommRing\n\nsection\n\nvariable [Ring α] [LinearOrder α] {a b : α}\n\n@[simp]\ntheorem abs_dvd (a b : α) : |a| ∣ b ↔ a ∣ b := by\n  cases' abs_choice a with h h <;> simp only [h, neg_dvd]\n#align abs_dvd abs_dvd\n\ntheorem abs_dvd_self (a : α) : |a| ∣ a :=\n  (abs_dvd a a).mpr (dvd_refl a)\n#align abs_dvd_self abs_dvd_self\n\n@[simp]\ntheorem dvd_abs (a b : α) : a ∣ |b| ↔ a ∣ b := by\n  cases' abs_choice b with h h <;> simp only [h, dvd_neg]\n#align dvd_abs dvd_abs\n\ntheorem self_dvd_abs (a : α) : a ∣ |a| :=\n  (dvd_abs a a).mpr (dvd_refl a)\n#align self_dvd_abs self_dvd_abs\n\ntheorem abs_dvd_abs (a b : α) : |a| ∣ |b| ↔ a ∣ b :=\n  (abs_dvd _ _).trans (dvd_abs _ _)\n#align abs_dvd_abs abs_dvd_abs\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/Algebra/Order/Ring/Abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8670357546485408, "lm_q1q2_score": 0.7705856588803024}}
{"text": "-- Suma_de_funciones_acotadas_inferiormente.lean\n-- La suma de dos funciones acotadas inferiormente también lo está.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 29-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que la suma de dos funciones acotadas inferiormente también\n-- lo está.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {f g : ℝ → ℝ}\nvariables {a b : ℝ}\n\n-- (cota_inferior f a) se verifica si a es una cota inferior de f.\ndef cota_inferior (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, a ≤ f x\n\n-- (acotada_inf f) se verifica si f tiene cota inferior.\ndef acotada_inf (f : ℝ → ℝ) := ∃ a, cota_inferior f a\n\n-- Lema auxiliar\n-- =============\n\nlemma cota_inferior_add\n  (hfa : cota_inferior f a)\n  (hgb : cota_inferior g b)\n  : cota_inferior (f + g) (a + b) :=\nλ x, add_le_add (hfa x) (hgb x)\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (hf : acotada_inf f)\n  (hg : acotada_inf g)\n  : acotada_inf (f + g) :=\nbegin\n  cases hf with a ha,\n  cases hg with b hb,\n  have h1 : cota_inferior (f + g) (a + b) := cota_inferior_add ha hb,\n  have h2 : ∃ z, ∀ x, z ≤ (f + g) x :=\n    by exact Exists.intro (a + b) h1,\n  show acotada_inf (f + g),\n    by exact h2,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (hf : acotada_inf f)\n  (hg : acotada_inf g)\n  : acotada_inf (f + g) :=\nbegin\n  cases hf with a hfa,\n  cases hg with b hgb,\n  use a + b,\n  apply cota_inferior_add hfa hgb,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (hf : acotada_inf f)\n  (hg : acotada_inf g)\n  : acotada_inf (f + g) :=\nbegin\n  rcases hf with ⟨a, hfa⟩,\n  rcases hg with ⟨b, hfb⟩,\n  exact ⟨a + b, cota_inferior_add hfa hfb⟩,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample :\n  acotada_inf f → acotada_inf g → acotada_inf (f + g) :=\nbegin\n  rintros ⟨a, hfa⟩ ⟨b, hfb⟩,\n  exact ⟨a + b, cota_inferior_add hfa hfb⟩,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample :\n  acotada_inf f → acotada_inf g → acotada_inf (f + g) :=\nλ ⟨a, hfa⟩ ⟨b, hfb⟩, ⟨a + b, cota_inferior_add hfa hfb⟩\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_funciones_acotadas_inferiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.7705856527731901}}
{"text": "example (p q : Prop) : p ∨ q → q ∨ p :=\nbegin\n  intro h,\n  cases h with hp hq,\n    right, exact hp,\n  left, exact hq,\nend\n\nexample (p q : Prop) : p ∧ q → q ∧ p :=\nbegin\n  intro h,\n  cases h with hp hq,\n  constructor,\n    exact hq,\n  exact hp,\nend\n\nexample (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\nbegin\n  apply iff.intro,\n    intro h,\n    cases h with hp hqr,\n    cases hqr with hq hr,\n    left, constructor, repeat { assumption },\n    right, constructor, repeat { assumption },\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,\nend\n\nexample (p q : ℕ → Prop) : (∃ x, p x) → ∃ x, p x ∨ q x :=\nbegin\n  intro h,\n  cases h with x px,\n  constructor, left, exact px,\nend\n\nexample (p q : ℕ → Prop) : (∃ x, p x) → ∃ x, p x ∨ q x :=\nbegin\n  intro h,\n  cases h with x px,\n  existsi x, left, assumption,\nend\n\nexample (p q : ℕ → Prop) : (∃ x, p x ∧ q x) → ∃ x, q x ∧ p x :=\nbegin\n  intro h,\n  cases h with x hpq,\n  cases hpq with hp hq,\n  existsi x,\n  -- constructor, assumption, assumption,\n  split; assumption\nend\n\nuniverses u v\n\ndef swap_pair {α : Type u} {β : Type v}: α × β → β × α :=\nbegin\n  intro p,\n  cases p with a b,\n  constructor, exact b, exact a,\nend\n\ndef swap_pair' {α : Type u} {β : Type v}: α ⊕ β → β ⊕ α :=\nbegin\n  intro p,\n  cases p with a b,\n    right, exact a,\n  left, exact b,\nend\n\nopen nat\n\nexample (P : ℕ → Prop) (h₀ : P 0) (h₁ : ∀ n, P (succ n)) (m : ℕ) : P m :=\nbegin\n  cases m with m',\n    exact h₀,\n  exact (h₁ m'),\nend\n\nexample (p q : Prop) : p ∧ ¬ p → q :=\nbegin\n  intro h,\n  cases h with hp hnp,\n  contradiction,\nend", "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.3-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7705856440812435}}
{"text": "import .sets\nimport .axiom_tactics\nimport .lovelib\nnamespace zfc\nnamespace LoVe\n\n/------------------------------------__Cardinality__------------------------------------/\n/-  The cardinality of a set invokes its notion of size. Two sets are cardinally equal -/\n/-                     if there exists a bijection between them.                       -/\n\n/- Two sets `x` and `y` have the same cardinality if there exists\n   a bijective function `f` from `x` to `y`.-/\ndef cardinality_eq : Set → Set → Prop :=\n  (λ(x y : Set), ∃(f : Set → Set),\n    (∀a b, a ∈ x ∧ b ∈ x → (a ≠ b → f(a) ≠ f(b)))          -- injection\n    ∧ (∀c, c ∈ y → ∃d, d ∈ x ∧ f(d) = c)                   -- surjection\n  )\ninfix ` ≃ ` : 110 := cardinality_eq\n\n/- _Cantor's Theorem_: X ≢ P(X) : A set does not have the same cardinality as its power set. -/\n/-Argument Structure:\nLet `f` be a bijection from `X` to `P(X)`. Let `Y = {x ∈ X : ¬x ∈ f(x)}`.\nLet `z ∈ X` be such that `f(z) = Y`. Then `z ∈ Y ↔ ¬z ∈ Y`. Contradiction!\n-/\ntheorem Cantor : ∀(X: Set), ¬(X ≃ P(X)) :=\n  begin\n    intro X,\n    intro p,\n    rw cardinality_eq at p,\n\n    /-Have `f` be some bijection from `X` to `P(X)`.-/\n    let f : Set → Set := classical.some p,\n\n    /-Have `Y = {x ∈ X : ¬x ∈ f(x)}`.-/\n    have pY := (separation (λx, ¬x ∈ f(x)) X),\n    let Y : Set := classical.some pY,\n    have hY := classical.some_spec pY,\n\n    /-Have `I = {x ∈ X : x ∈ f(x)}`.-/\n    have pI := (separation (λx, x ∈ f(x)) X),\n    let I : Set := classical.some pI,\n    have hI := classical.some_spec pI,\n\n    /-Let `zC` be the class of sets that contain all sets `z` such that `f(z) = Y`.\n      (zC really only contains one element.)-/\n    have pzC := (separation (λx, f(x) = Y) X),\n    let zC : Set := classical.some pzC,\n    have hzC := classical.some_spec pzC,\n\n    have zC_nonempty : ∃z, z ∈ zC :=\n      begin\n        have exists_z : ∃x, x ∈ X ∧ f(x) = Y :=\n          begin\n            have hp := classical.some_spec p,\n            have f_is_surj := and.elim_right hp Y,\n            have Y_in_PX : Y ∈ P(X) :=\n              begin\n                have Y_subset_X : Y ⊂ X :=\n                  begin\n                    rw is_subset,\n                    intros x x_in_Y,\n                    have j := iff.elim_left (hY x),\n                    apply and.elim_left (j x_in_Y),\n                  end,\n                rw [P, power_set_of],\n                simp,\n                have hPX := iff.elim_right (classical.some_spec (power_set X) Y),\n                apply hPX Y_subset_X,\n              end,\n            apply f_is_surj Y_in_PX,\n          end,\n        let a := classical.some exists_z,\n        have hzCL := iff.elim_right (hzC a),\n        have ha := classical.some_spec exists_z,\n        simp at hzCL,\n        have a_in_X : a ∈ X := by apply and.elim_left ha,\n        have fa_is_Y : f a = Y := by apply and.elim_right ha,\n        have a_in_zC := (hzCL a_in_X) fa_is_Y,\n        apply exists.intro a,\n        assumption,\n      end,\n\n    /-Have `z` be some (the) element of `zC`.-/\n    let z := classical.some zC_nonempty,\n    have hz := classical.some_spec zC_nonempty,\n\n    have z_in_zC : z ∈ zC := by apply hz,\n\n    have z_in_X : z ∈ X :=\n      begin\n        have hzCR := iff.elim_left (hzC z) z_in_zC,\n        apply and.elim_left hzCR,\n      end,\n\n    simp at *,\n\n    /- We can show that __z ∈ Y ↔ ¬z ∈ Y__. -/\n    have hziy : z ∈ Y ↔ ¬z ∈ Y,\n    {\n      apply iff.intro,\n      {\n        /- Forward Direction: z ∈ Y → ¬z ∈ Y\n        If z ∈ Y, then ¬z ∈ I. But, f(z) = Y, so z ∈ I. Contradiction, thus ¬z ∈ Y. -/\n        intro ziy,\n        intro ziy2,\n        have z_not_in_I : ¬z ∈ I,\n        {\n          intro z_in_I,\n          have z_in_fz : z ∈ f(z) :=\n            begin\n              have hIR := iff.elim_left (hI z) z_in_I,\n              apply and.elim_right hIR,\n            end,\n          have z_not_in_fz : ¬z ∈ f(z) :=\n            begin\n              have hYR := iff.elim_left (hY z) ziy,\n              apply and.elim_right hYR,\n            end,\n            contradiction,     \n        },\n        have fz_is_Y : f(z) = Y :=\n          begin\n            have hzCR := iff.elim_left (hzC z),\n            apply and.elim_right (hzCR z_in_zC),\n          end,\n        have z_in_I : z ∈ I :=\n          begin\n            have z_in_fz : z ∈ f(z) :=\n              begin\n                simp [fz_is_Y, ziy],\n              end,\n            have hIL := iff.elim_right (hI z),\n            apply (hIL (and.intro z_in_X z_in_fz)),\n          end,\n        contradiction,\n      },\n      {\n        /-Backward Direction: ¬z ∈ Y → z ∈ Y\n        If ¬z ∈ Y, then z ∈ f(z). But f(z) = Y, so z ∈ Y.-/\n        intro not_z_in_Y,\n        have z_in_fz : z ∈ f(z) :=\n          begin\n            have hYR := iff.elim_right (hY z),\n            have nhY := not.imp not_z_in_Y hYR,\n            simp at nhY,\n            simp [nhY, z_in_X],\n          end,\n        have fz_is_Y : f(z) = Y :=\n          begin\n            have hzCR := iff.elim_left (hzC z),\n            apply and.elim_right (hzCR z_in_zC),\n          end,\n        have z_in_Y : z ∈ Y :=\n          begin\n            rw (eq.symm fz_is_Y),\n            exact z_in_fz,\n          end,\n        contradiction,\n      },\n    },\n    /-Uh-oh! We have that z ∈ Y ↔ ¬z ∈ Y. We can break into cases, and say that if\n      z ∈ Y, then we have a contradiction, and if ¬z ∈ Y, we also have a contradiction.-/\n    have uhoh : z ∈ Y ∨ ¬z ∈ Y := by apply classical.em,\n    apply or.cases_on uhoh,\n    {\n      intro ziy,\n      have zniy : ¬z ∈ Y,\n      {\n        apply iff.elim_left hziy,\n        assumption,\n      },\n      contradiction\n    },\n    {\n      intro nziy,\n      have ziy : z ∈ Y,\n      {\n        apply iff.elim_right hziy,\n        assumption\n      },\n      contradiction\n    },\n  end\nend LoVe\nend zfc", "meta": {"author": "Beanway144", "repo": "fpv-final-project", "sha": "2d72b50e8c5627f2fc61c597a9c6e4e83f5022ca", "save_path": "github-repos/lean/Beanway144-fpv-final-project", "path": "github-repos/lean/Beanway144-fpv-final-project/fpv-final-project-2d72b50e8c5627f2fc61c597a9c6e4e83f5022ca/src/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697695, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7705694362531245}}
{"text": "/- Exercise 4.1: Mathematics — Foundation -/\n\n/- Question 1: Hilbert choice -/\n\n/- The following command enables noncomputable decidability on every `Prop`. The `priority 0`\nattribute ensures this is used only when necessary; otherwise, it would make some computable\ndefinitions noncomputable for Lean. -/\n\nlocal attribute [instance, priority 0] classical.prop_decidable\n\n/- 1.1. Prove the following lemma. -/\n\nlemma exists_minimal_arg.aux (f : ℕ → ℕ) :\n  ∀x n, f n = x → ∃n, ∀i, f n ≤ f i\n| x n eq :=\n  begin\n    -- this works thanks to `classical.prop_decidable`\n    by_cases (∃n', f n' < x),\n    { cases h with n' h,\n      exact exists_minimal_arg.aux _ n' rfl },\n    { have h' : ∀n', x ≤ f n',\n      { intro n',\n        apply le_of_not_gt _,\n        intro h',\n        exact h ⟨n', h'⟩ },\n      apply exists.intro n,\n      rw eq,\n      exact h' }\n  end\n\n/- Now this interesting lemma falls off: -/\n\nlemma exists_minimal_arg (f : ℕ → ℕ) : ∃n : ℕ, ∀i : ℕ, f n ≤ f i :=\nexists_minimal_arg.aux f _ 0 rfl\n\n/- 1.2. Use what you learned in the lecture notes to define the following function, which returns\nthe (or an) index of the minimal element in `f`'s image. -/\n\nnoncomputable def minimal_arg (f : ℕ → ℕ) : ℕ :=\nclassical.some (exists_minimal_arg f)\n\n/- 1.3. Prove the following characteristic lemma about your definition. -/\n\nlemma minimal_arg_spec (f : ℕ → ℕ) : ∀i : ℕ, f (minimal_arg f) ≤ f i :=\nclassical.some_spec (exists_minimal_arg f)\n\n\n/- Question 2: Integers as quotients -/\n\n/- First, we repeat some material from the lecture. As usual, ignore the `sorry`. -/\n\nnamespace exercise\n\n\nlemma reflexive1 {α: Type} (x: (ℕ × ℕ)) : x.1 + x.2 = x.1 + x.2:= by refl\nlemma symmetry1 {α: Type} (x y: (ℕ × ℕ)) (h1: x.1 + y.2 = y.1 + x.2) :  y.1 + x.2 = x.1 + y.2 := by rw[h1]\nlemma transitive1 {α: Type} (x y z: (ℕ × ℕ)) (h1: y.1 + x.2 = x.1 + y.2) (h2:  z.1 + y.2 = y.1 + z.2) : (x.1 + z.2) + y.2 = (x.1 + y.2) + z.2 := begin calc (x.fst + z.snd) + y.snd = (x.fst + y.snd) + z.snd : by ac_refl  end \n\n\nlemma reflexivelist {α: Type} (xs: list α) : ∀x, x∈xs ↔ x∈xs := begin intro x, apply iff.intro, intro h, assumption, intro h, assumption end\nlemma symmetriclist {α: Type} (xs ys: list α) : ∀x, x∈xs ↔ x∈ys →  x∈ys ↔ x∈xs := begin intro x, apply iff.intro, intro h, cases h, apply h_mpr, intro s, assumption, intro h, apply iff.intro, intros a b, assumption, intro a, assumption end\nlemma transitivelist {α: Type} (xs ys zs: list α) : ∀x, x∈xs ↔ x∈ys →  x∈ys ↔ x∈zs → x ∈xs ↔ x∈zs := begin intro x, apply iff.intro, intro h, cases h, simp[symmetriclist] at h_mp, simp[symmetriclist] at h_mpr, sorry  \n\n\ninstance fin_set.rel (α: Type) : setoid (list α) :={ r :=λxs ys,∀x, x∈xs↔x∈ys,\niseqv := ⟨ (assume xs, by simp*),\n\n ⟩ }\n\ninstance int.rel : setoid (ℕ × ℕ) :=\n{ r     := λa b, a.1 + b.2 = b.1 + a.2,\n  iseqv := ⟨ (assume a, reflexive1 ),\n            (assume a b eq, symmetry1),\n            (assume a b c d e , transitive1)\n  ⟩ }\n\n@[simp] lemma rel_iff (a b : ℕ × ℕ) : a ≈ b ↔ a.1 + b.2 = b.1 + a.2 := iff.rfl\n\ndef int : Type := quotient int.rel\n\n/- 2.1. Define negation using `quotient.lift_on`. -/\n\ndef neg (a : int) : int :=\nquotient.lift_on a (λpn, ⟦(pn.2, pn.1)⟧)\n  begin\n    intros a b h,\n    cases a,\n    cases b,\n    apply quotient.sound,\n    simp at h ⊢,\n    rw [h]\n  end\n\n/- 2.2. Prove the following lemmas. -/\n\nlemma neg_mk (p n : ℕ) : neg ⟦(p, n)⟧ = ⟦(n, p)⟧ :=\nby refl\n\nlemma neg_neg (a : int) : neg (neg a) = a :=\nbegin\n  refine quotient.induction_on a _,\n  intro a,\n  cases a,\n  simp [neg_mk]\nend\n\nend exercise\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/4.1/41_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7704786791857843}}
{"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 data.finsupp.order\nimport data.dfinsupp.lex\nimport data.finsupp.to_dfinsupp\n\n/-!\n# Lexicographic order on finitely supported functions\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 lexicographic order on `finsupp`.\n-/\n\nvariables {α N : Type*}\n\nnamespace finsupp\n\nsection N_has_zero\nvariables [has_zero N]\n\n/-- `finsupp.lex r s` is the lexicographic relation on `α →₀ N`, where `α` is ordered by `r`,\nand `N` is ordered by `s`.\n\nThe type synonym `lex (α →₀ N)` has an order given by `finsupp.lex (<) (<)`.\n-/\nprotected def lex (r : α → α → Prop) (s : N → N → Prop) (x y : α →₀ N) : Prop :=\npi.lex r (λ _, s) x y\n\nlemma _root_.pi.lex_eq_finsupp_lex {r : α → α → Prop} {s : N → N → Prop} (a b : α →₀ N) :\n  pi.lex r (λ _, s) (a : α → N) (b : α → N) = finsupp.lex r s a b :=\nrfl\n\nlemma lex_def {r : α → α → Prop} {s : N → N → Prop} {a b : α →₀ N} :\n  finsupp.lex r s a b ↔ ∃ j, (∀ d, r d j → a d = b d) ∧ s (a j) (b j) := iff.rfl\n\n\n\ninstance [has_lt α] [has_lt N] : has_lt (lex (α →₀ N)) :=\n⟨λ f g, finsupp.lex (<) (<) (of_lex f) (of_lex g)⟩\n\nlemma lex_lt_of_lt_of_preorder [preorder N] (r) [is_strict_order α r]\n  {x y : α →₀ N} (hlt : x < y) : ∃ i, (∀ j, r j i → x j ≤ y j ∧ y j ≤ x j) ∧ x i < y i :=\ndfinsupp.lex_lt_of_lt_of_preorder r (id hlt : x.to_dfinsupp < y.to_dfinsupp)\n\nlemma lex_lt_of_lt [partial_order N] (r) [is_strict_order α r]\n  {x y : α →₀ N} (hlt : x < y) : pi.lex r (λ i, (<)) x y :=\ndfinsupp.lex_lt_of_lt r (id hlt : x.to_dfinsupp < y.to_dfinsupp)\n\ninstance lex.is_strict_order [linear_order α] [partial_order N] :\n  is_strict_order (lex (α →₀ N)) (<) :=\nlet i : is_strict_order (lex (α → N)) (<) := pi.lex.is_strict_order in\n{ irrefl := to_lex.surjective.forall.2 $ λ a, @irrefl _ _ i.to_is_irrefl a,\n  trans := to_lex.surjective.forall₃.2 $ λ a b c, @trans _ _ i.to_is_trans a b c }\n\nvariables [linear_order α]\n\n/-- The partial order on `finsupp`s obtained by the lexicographic ordering.\nSee `finsupp.lex.linear_order` for a proof that this partial order is in fact linear. -/\ninstance lex.partial_order [partial_order N] : partial_order (lex (α →₀ N)) :=\npartial_order.lift (λ x, to_lex ⇑(of_lex x)) finsupp.coe_fn_injective--fun_like.coe_injective\n\n/--  The linear order on `finsupp`s obtained by the lexicographic ordering. -/\ninstance lex.linear_order [linear_order N] : linear_order (lex (α →₀ N)) :=\n{ ..lex.partial_order,\n  ..linear_order.lift' (to_lex ∘ to_dfinsupp ∘ of_lex) finsupp_equiv_dfinsupp.injective }\n\nvariable [partial_order N]\n\nlemma to_lex_monotone : monotone (@to_lex (α →₀ N)) :=\nλ a b h, dfinsupp.to_lex_monotone (id h : ∀ i, of_lex (to_dfinsupp a) i ≤ of_lex (to_dfinsupp b) i)\n\nlemma lt_of_forall_lt_of_lt (a b : lex (α →₀ N)) (i : α) :\n  (∀ j < i, of_lex a j = of_lex b j) → of_lex a i < of_lex b i → a < b :=\nλ h1 h2, ⟨i, h1, h2⟩\n\nend N_has_zero\n\nsection covariants\nvariables [linear_order α] [add_monoid N] [linear_order N]\n\n/-!  We are about to sneak in a hypothesis that might appear to be too strong.\nWe assume `covariant_class` with *strict* inequality `<` also when proving the one with the\n*weak* inequality `≤`.  This is actually necessary: addition on `lex (α →₀ 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. -/\nsection left\nvariables [covariant_class N N (+) (<)]\n\ninstance lex.covariant_class_lt_left : covariant_class (lex (α →₀ N)) (lex (α →₀ N)) (+) (<) :=\n⟨λ f g h ⟨a, lta, ha⟩, ⟨a, λ j ja, congr_arg ((+) _) (lta j ja), add_lt_add_left ha _⟩⟩\n\ninstance lex.covariant_class_le_left : covariant_class (lex (α →₀ N)) (lex (α →₀ N)) (+) (≤) :=\nhas_add.to_covariant_class_left _\n\nend left\n\nsection right\nvariables [covariant_class N N (function.swap (+)) (<)]\n\ninstance lex.covariant_class_lt_right :\n  covariant_class (lex (α →₀ N)) (lex (α →₀ N)) (function.swap (+)) (<) :=\n⟨λ f g h ⟨a, lta, ha⟩, ⟨a, λ j ja, congr_arg (+ (of_lex f j)) (lta j ja), add_lt_add_right ha _⟩⟩\n\ninstance lex.covariant_class_le_right :\n  covariant_class (lex (α →₀ N)) (lex (α →₀ N)) (function.swap (+)) (≤) :=\nhas_add.to_covariant_class_right _\n\nend right\n\nend covariants\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/lex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7704786777931324}}
{"text": "import Mathlib\nimport PnP2023.Lec_02_01.Foundations\nimport PnP2023.Lec_01_13.NatRec\n\n\n/-!\n# Inductive Types\n\nWe see more precisely what are valid (and not valid) definitions for inductive types. We will also see the weak and strong generalizations: \n_parametric inductive types_ and  _indexed inductive types_.\n\nWe have constructed a few examples. We first see some more from Lean core.-/\n\n#check Bool\n\n/-!\nSimplest ones are enumerations\n\n```lean\ninductive Bool : Type where\n  | false : Bool\n  | true : Bool\n```\n-/\n\n#check Nat\n\n/-!\nIn general, the construtors let us construct terms of the inductive type being introduced using terms of that type.\n\n```lean\ninductive Nat where\n  | zero : Nat\n  | succ (n : Nat) : Nat\n```\n\n#check Nat.zero -- ℕ \n#check Nat.succ -- ℕ → ℕ \n-/\n\n#check Nat.zero -- ℕ \n#check Nat.succ -- ℕ → ℕ \n\n#check Unit\n#check Empty \n\n/-!\nTwo more inductive types:\n\n```lean\nabbrev Unit : Type := PUnit\n\ninductive PUnit : Sort u where\n  | unit : PUnit\n\ninductive Empty : Type\n```\n-/\n\n/-!\n## Disallowed types\n \n- constructors should have resulting type the inductive type being introduced.\n-/\n-- inductive Silly where\n--  | what_is_this: ℕ /- unexpected constructor resulting type\n--   ℕ -/\n\n-- inductive Cantor where\n--   | mk : (Cantor → Bool) → Cantor\n--   /-(kernel) arg #1 of 'Cantor.mk' has a non positive occurrence of the datatypes being declared -/\n\n/-!\nThe above is disallowed because with a construction of the above form, we would have an injection (in this case a biection) from the power set on the Cantor set to itself.\n\nIf we had such an inductive type, we could define\n\n```lean\ndiag (x :Cantor): Bool :=  match x with\n| Cantor.mk f => ¬ f x\n```\n\nApply this to `x:= Cantor.mk diag` to get\n```lean\ndiag (Cantor.mk diag) = ¬ diag (Cantor.mk diag)\n``` \n-/\n\n/-!\nA non-trivial __positive__ occurence, which is hence allowed, is in the following binary tree.\n-/\n\ninductive NatBinTree where \n| leaf : ℕ → NatBinTree\n| node : (Bool → NatBinTree) → NatBinTree\n\n/-!\n## Parametrized inductive types\n\nHere we define a family of inductive types. However each member of the family is \"separately defined\", i.e., all constructors only involve that parameter.\n-/\n\nuniverse u\n\ninductive InfiniteTree (α : Type u) where\n| leaf (label: α) : InfiniteTree α\n| node : (ℕ → InfiniteTree α) → InfiniteTree α\n\ninductive FiniteTree (α : Type u) where\n| leaf (label: α) : FiniteTree α\n| node : (List <| FiniteTree α)  → FiniteTree α\n\n-- Does terminate, but Lean does not have enough support yet\npartial def FiniteTree.flatten {α : Type u} : FiniteTree α → List α\n| FiniteTree.leaf label => [label]\n| FiniteTree.node children => \n  children.foldl (fun acc child => acc ++ FiniteTree.flatten child) ([])\n\n\n/-!\n# Indexed inductive type\n\nWe define types `Vec α n` for `α : Type u` and `n: ℕ` with terms of `Vec α n` n-tuples in `α`.\n\n* `α` will be a parameter.\n* `n` will be an index.\n-/\n\ninductive Vec (α : Type u) : \n            ℕ → Type (u + 1) where\n| nil : Vec α 0\n| cons : {n : ℕ} →  \n  (head : α) → (tail : Vec α n) → Vec α (n + 1)  \n\nexample : Vec ℕ 0 := Vec.nil\n\nexample : Vec ℕ 1 := Vec.cons 3 (Vec.nil)\n\n#check List\n\ndef Vec.to_list {α : Type u} {n : ℕ} : Vec α n → List α\n| Vec.nil => []\n| Vec.cons head tail => head :: tail.to_list\n\n/-!\n## `List` is a parametrized inductive type\n\n```lean\ninductive List (α : Type u) where\n  /-- `[]` is the empty list. -/\n  | nil : List α\n  /-- If `a : α` and `l : List α`, then `cons a l`, or `a :: l`, is the\n  list whose first element is `a` and with `l` as the rest of the list. -/\n  | cons (head : α) (tail : List α) : List α\n```\n-/\n\n#check Fin\n\n/-!\nSometimes types include conditions\n\n```lean\nstructure Fin (n : Nat) where\n  /-- If `i : Fin n`, then `i.val : ℕ` is the described number. It can also be\n  written as `i.1` or just `i` when the target type is known. -/\n  val  : Nat\n  /-- If `i : Fin n`, then `i.2` is a proof that `i.1 < n`. -/\n  isLt : LT.lt val n\n```\n-/\n\n#check Vector\n\n/-!\nConditions can be given by a *subtype* of the type.\n\n```lean\ndef Vector (α : Type u) (n : ℕ) :=\n  { l : List α // l.length = n }\n```\n-/\n \n#check Subtype.property\n#check Subtype.val\n#check Subtype.mk\n\n/-!\nWhen an (indexed) inductive type is introduced,\n\n* the type (or family of types) is defined.\n* the constructors are defined.\n* a *recursor* is defined.\n* a rule for simplification of applications of the recursor is introduced.\n\nThe recursor can be conveniently used by pattern matching.\n-/\n\ndef Bool.disagree (b: Bool) : Bool :=\n  match b with\n  | Bool.false => Bool.true\n  | Bool.true => Bool.false\n\n#check Bool.rec -- {motive : Bool → Sort u} → motive false → motive true → (t : Bool) → motive t\n\ndef egFamily (b: Bool) : Type :=\n  match b with\n  | Bool.false => Unit\n  | Bool.true => ℕ\n\ndef egDepFunction (b: Bool) : egFamily b :=\n  match b with\n  | Bool.false => ()\n  | Bool.true => by\n    simp [egFamily]\n    exact 3\n\nset_option pp.motives.all true in\n#reduce egDepFunction\n\nset_option pp.motives.all true in\n#reduce Bool.disagree", "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_02_03/InductiveTypes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.7704748240435688}}
{"text": "/-\nIn Lean, true is a proposition that\nis always true, in the sense that\nthere is a proof of it that doesn't\ndepend on anything else being true.\n-/\n\n#check true\n\n/-\ninductive true : Prop\n| intro : true\n-/\n\n\n/-\nIntroduction rule for true\n-/\nlemma true_is_true : true := true.intro\n\n\n/-\nA function from true to true\n-/\nlemma true_to_true' : true → true := \nλ (t : true), t\n\n\n/-\nA proof that true → true\n-/\nlemma true_to_true : true → true := \nλ t, t\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/true.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7704748168277108}}
{"text": "import tactic\n\nvariables {α β γ : Type} {f : α → β} {g g₁ g₂ : β → α}\n\n-- Problem 4.1. Show that if f : A → B has a left inverse g, then f is\n-- injective.\nlemma problem_4_1 (h : function.left_inverse g f) : function.injective f :=\nbegin\n  intros x y hxy,\n  have : g (f x) = g (f y), from congr_arg g hxy,\n  have hx := h x,\n  have hy := h y,\n  rwa [hx, hy] at this\nend\n\n-- Problem 4.2. Show that if f : A → B has a right inverse h, then f is\n-- surjective.\nlemma problem_4_2 (h : function.right_inverse g f) : function.surjective f :=\nbegin\n  intro y,\n  use g y,\n  rw h y\nend\n\n#check @classical.some\n#check @classical.some_spec\n\n-- Problem 4.3. Prove Proposition 4.18. You have to define f^−1, show that it\n-- is a function, and show that it is an inverse of f, i.e., f^−1(f(x)) = x and\n-- f(f^−1(y)) = y for all x ∈ A and y ∈ B.\n--\n-- Proposition 4.18. If f : A → B is bijective, there is a function\n-- f^−1 : B → A so that for all x ∈ A, f^−1(f(x)) = x and for all y ∈ B,\n-- f(f^−1(y)) = y.\nlemma proposition_4_18 (h : function.bijective f) :\n  ∃ g : β → α, function.left_inverse g f ∧ function.right_inverse g f :=\nbegin\n  obtain ⟨h₁, h₂⟩ := h,\n  let g : β → α := λ y, classical.some (h₂ y),\n  use g,\n  split,\n  { intro x,\n    simp only [g],\n    have := classical.some_spec (h₂ (f x)),\n    have := h₁ this,\n    assumption },\n  { intro y,\n    simp only [g],\n    have := classical.some_spec (h₂ y),\n    assumption }\nend\n\n-- Problem 4.4. Prove Proposition 4.19.\n--\n-- Proposition 4.19. Show that if f : A → B has a left inverse g and a right\n-- inverse h, then h = g .\nlemma proposition_4_19 (hg₁ : function.left_inverse g₁ f) (hg₂ : function.right_inverse g₂ f) :\n  g₁ = g₂ :=\nbegin\n  ext y,\n  have h₁ := hg₁ (g₂ y),\n  have h₂ := hg₂ y,\n  rwa h₂ at h₁\nend\n\n-- Problem 4.5. Show that if f : A → B and g : B → C are both injective, then\n-- g ◦ f : A → C is injective.\nlemma problem_4_5 {g : β → γ} (hf : function.injective f) (hg : function.injective g) :\n  function.injective (g ∘ f) :=\nbegin\n  intros x y h,\n  change g (f x) = g (f y) at h,\n  have := hg h,\n  have := hf this,\n  assumption\nend\n\n-- Problem 4.6. Show that if f : A → B and g : B → C are both surjective, then\n-- g ◦ f : A → C is surjective.\nlemma problem_4_6 {g : β → γ} (hf : function.surjective f) (hg : function.surjective g) :\n  function.surjective (g ∘ f) :=\nbegin\n  intro z,\n  obtain ⟨y, hy⟩ := hg z,\n  obtain ⟨x, hx⟩ := hf y,\n  use x,\n  change g (f x) = z,\n  rw [hx, hy]\nend\n\ndef graph (f : α → β) := λ x y, f x = y\n\ndef relative_product (r : α → β → Prop) (s : β → γ → Prop) := λ a b, ∃ c, r a c ∧ s c b\n\n-- Problem 4.7. Suppose f : A → B and g : B → C. Show that the graph of g ◦ f\n-- is R_f | R_g.\nlemma problem_4_7 (f : α → β) (g : β → γ) :\n  graph (g ∘ f) = relative_product (graph f) (graph g) :=\nbegin\n  ext x z,\n  split,\n  { intro h,\n    change g (f x) = z at h,\n    rwa [relative_product, graph, exists_eq_left'] },\n  { intro h,\n    rwa [relative_product, graph, exists_eq_left'] at 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/04_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7704748112920979}}
{"text": "/-\n    Stalk (of types).\n\n    https://stacks.math.columbia.edu/tag/0078\n\n    Author: Ramon Fernandez Mir\n-/\n\nimport topology.basic\nimport sheaves.opens\nimport sheaves.presheaf\n\nuniverse u\n\nsection stalk\n\nvariables {α : Type u} [topological_space α]\nvariables (F : presheaf α) (x : α)\n\nopen topological_space\n\n-- An element in the stalk is a pair (U, s) under an equivalence relation\n\nstructure stalk.elem :=\n(U   : opens α)\n(HxU : x ∈ U)\n(s   : F U)\n\n-- Equivalence relation on the set of pairs. (U,s) ~ (V,t) iff there exists W\n-- open s.t. x ∈ W ⊆ U ∩ V, and s|W = t|W.\n\ndef stalk.relation : stalk.elem F x → stalk.elem F x → Prop :=\nλ Us Vt,\n    ∃ (W : opens α) (HxW : x ∈ W) (HWU : W ⊆ Us.U) (HWV : W ⊆ Vt.U),\n    F.res Us.U W HWU Us.s = F.res Vt.U W HWV Vt.s\n\nlemma stalk.relation.reflexive : reflexive (stalk.relation F x) :=\nλ ⟨U, HxU, s⟩, ⟨U, HxU, set.subset.refl _, set.subset.refl _, rfl⟩\n\nlemma stalk.relation.symmetric : symmetric (stalk.relation F x) :=\nλ Us Vt ⟨W, HxW, HWU, HWV, Hres⟩, ⟨W, HxW, HWV, HWU, Hres.symm⟩\n\nlemma stalk.relation.transitive : transitive (stalk.relation F x) :=\nλ ⟨U, HxU, sU⟩ ⟨V, HxV, sV⟩ ⟨W, HxW, sW⟩,\nλ ⟨R, HxR, HRU, HRV, HresR⟩ ⟨S, HxS, HSV, HSW, HresS⟩,\n⟨R ∩ S, ⟨HxR, HxS⟩,\nλ y ⟨HyR, _⟩, HRU HyR, λ y ⟨_, HyS⟩, HSW HyS,\nhave HURRS : _ := F.Hcomp U R (R ∩ S) (set.inter_subset_left _ _) HRU,\nhave HVRRS : _ := F.Hcomp V R (R ∩ S) (set.inter_subset_left _ _) HRV,\nhave HVSRS : _ := F.Hcomp V S (R ∩ S) (set.inter_subset_right _ _) HSV,\nhave HWSRS : _ := F.Hcomp W S (R ∩ S) (set.inter_subset_right _ _) HSW,\ncalc  F.res U (R ∩ S) _ sU\n    = F.res R (R ∩ S) _ (F.res U R _ sU) : congr_fun HURRS sU\n... = F.res R (R ∩ S) _ (F.res V R _ sV) : congr_arg _ HresR\n... = F.res V (R ∩ S) _ sV               : congr_fun HVRRS.symm sV\n... = F.res S (R ∩ S) _ (F.res V S _ sV) : congr_fun HVSRS sV\n... = F.res S (R ∩ S) _ (F.res W S _ sW) : congr_arg _ HresS\n... = F.res W (R ∩ S) _ sW               : congr_fun HWSRS.symm sW⟩\n\nlemma stalk.relation.equivalence : equivalence (stalk.relation F x) :=\n⟨stalk.relation.reflexive F x,\nstalk.relation.symmetric F x,\nstalk.relation.transitive F x⟩\n\ninstance stalk.setoid : setoid (stalk.elem F x) :=\n{ r := stalk.relation F x,\n  iseqv := stalk.relation.equivalence F x }\n\n-- We define a stalk as the set of stalk elements under the defined relation.\n\ndefinition stalk := quotient (stalk.setoid F x)\n\nend stalk\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/stalk.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678381, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7703732351965786}}
{"text": "theorem lt_succ_eq_or_succ_lt (x b : Nat) (hb : b ≠ 0) : x < b → Nat.succ x = b ∨ Nat.succ x < b := by\nintro h1\nhave h2 : Nat.succ x ≤ b := Nat.succ_le_of_lt h1\nrw [Eq.symm (Nat.succ_pred hb)] at h2\nhave h3 : Nat.succ x ≤ Nat.pred b ∨ Nat.succ x = Nat.succ (Nat.pred b) := Nat.le_or_eq_or_le_succ h2\nrw [Nat.succ_pred hb] at h3\napply Or.elim h3\nintro h4\nhave h5 : Nat.succ x < Nat.succ (Nat.pred b) := Nat.lt_succ_of_le h4\nrw [Nat.succ_pred hb] at h5\nexact Or.intro_right (Nat.succ x = b) h5\nintro h6\nexact Or.intro_left (Nat.succ x < b) h6\n\ntheorem succ_eq_succ (a b : Nat) : a = b → Nat.succ a = Nat.succ b := by\nintro hp\ninduction a <;> rw [hp]\n\ntheorem division_theorem (a b : Nat) (h : b ≠ 0) : ∃ r q : Nat, a = q*b+r ∧ r < b := by\ninduction a with\n| zero => apply Exists.intro 0\n          apply Exists.intro 0\n          rw [Nat.zero_mul]\n          have h1 : 0 = 0 + 0 := rfl\n          have h2 : 0 < b := Nat.zero_lt_of_ne_zero h\n          apply And.intro h1 h2\n| succ a ha => apply Exists.elim ha\n               intro x hx\n               apply Exists.elim hx\n               intro y hy\n               have shoo : Nat.succ x = b ∨ Nat.succ x < b := lt_succ_eq_or_succ_lt x b h hy.right\n               apply Or.elim shoo\n               intro foo2\n               apply Exists.intro 0\n               apply Exists.intro (y+1)\n               have h9 : 0<b := Nat.zero_lt_of_ne_zero h\n               suffices h : Nat.succ a = (y+1)*b + 0 from And.intro h h9\n               rw [Nat.add_mul,Nat.one_mul,Nat.add_zero,Eq.symm foo2,Nat.succ_eq_add_one x]\n               rw [← Nat.add_assoc,Nat.add_one,Nat.add_one]\n               apply succ_eq_succ\n               rw [foo2]\n               exact hy.left\n               intro hu\n               apply Exists.intro (x+1)\n               apply Exists.intro y\n               apply And.intro\n               rw [← Nat.add_assoc,Nat.add_one]\n               apply succ_eq_succ\n               exact hy.left\n               exact hu\n", "meta": {"author": "Euctemon", "repo": "proofs-in-lean", "sha": "2a6d10e17ae1c15e814ad9ab24a76e937f95586a", "save_path": "github-repos/lean/Euctemon-proofs-in-lean", "path": "github-repos/lean/Euctemon-proofs-in-lean/proofs-in-lean-2a6d10e17ae1c15e814ad9ab24a76e937f95586a/division_theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7703109488365273}}
{"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 5 : \"iff\" (`↔`)\n\nWe learn about how to manipulate `P ↔ Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following two new tactics:\n\n* `refl`\n* `rw`\n\n### The `refl` tactic\n\nIf your goal is `P ↔ P` then `refl,` will solve it.\n\n### The `rw` tactic\n\nIf `h : P ↔ Q` is a hypothesis, you can decompose it\nusing `cases h with hPQ hQP,`. However, if you keep\nit around then you can do `rw h,` which changes all `P`s in the goal to `Q`s.\nVariant: `rw h at h2,` will change all `P`s to `Q`s in hypothesis `h2`.\n\n-/\n\nvariables (P Q R S : Prop)\n\nexample : P ↔ P :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  sorry\nend\n\nexample : P ∧ Q ↔ Q ∧ P :=\nbegin\n  sorry\nend\n\nexample : ((P ∧ Q) ∧ R) ↔ (P ∧ (Q ∧ R)) :=\nbegin\n  sorry\nend\n\nexample : P ↔ (P ∧ true) :=\nbegin\n  sorry\nend\n\nexample : false ↔ (P ∧ false) :=\nbegin\n  sorry\nend\n\nexample : (P ↔ Q) → (R ↔ S) → (P ∧ R ↔ Q ∧ S) :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ↔ ¬ P) :=\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/logic/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7703040150940662}}
{"text": "/-\nThis module defines operations for simplifying equalities between natural numbers.\n\nAfter importing this, simp should reduce all ground number equalities\nto true or false.\n-/\n\nnamespace nat\n\n/- Simplify 0 = succ n to false -/\n@[simp]\ntheorem not_zero_eq_succ (x : ℕ) : ¬ (0 = succ x) :=\nbegin\n  contradiction,\nend\n\n@[simp]\ntheorem succ_eq_zero (x : ℕ) : (succ x = 0) ↔ false :=\nbegin\n  simp [bit0],\n  induction x,\n  contradiction,\n  contradiction\nend\n\n/- Simplify succ n = 0 to false -/\n@[simp]\ntheorem not_succ_eq_zero (n : ℕ) : ¬ (nat.succ n = 0) :=\nbegin\n  contradiction,\nend\n\n-- Simplify successor of two values.\n@[simp]\ntheorem succ_eq_succ (x y : ℕ): succ x = succ y ↔ x = y :=\nbegin\n  apply iff.intro,\n  { intro p,\n    apply @nat.no_confusion _ _ _ p,\n    exact id,\n  },\n  { intro p,\n    rw [p]\n  }\nend\n\n/- Lemmas comparing operations with zero. -/\nsection zero_comparison\n\n/- Simplify comparison of sum of two naturals with 0. -/\ntheorem add_is_zero_iff (m n : ℕ) : m + n = 0 ↔ m = 0 ∧ n = 0 :=\nbegin\n  cases n,\n  case zero { simp, },\n  case succ n ind { simp [add_succ], },\nend\n\n/- Simplify comparison of product of two naturals with 0. -/\ntheorem mul_is_zero_iff (m n : ℕ) : m * n = 0 ↔ m = 0 ∨ n = 0 :=\nbegin\n  induction n,\n  case zero { simp, },\n  case succ n ind {\n    simp [mul_succ, add_is_zero_iff, ind],\n    by_cases m = 0 with h,\n    all_goals { simp [h], },\n  }\nend\n\n/- Simplify comparison of power of two naturals with 0. -/\ntheorem pow_is_zero_iff (m n : ℕ) : m ^ n = 0 ↔ m = 0 ∧ n ≠ 0 :=\nbegin\n  induction n,\n  case zero { simp, },\n  case succ n ind {\n    simp [pow, mul_is_zero_iff, ind],\n    by_cases m = 0 with h,\n    all_goals { simp [h], },\n  }\nend\n\nend zero_comparison\n\n-- Commute bit0 and succ\nprotected\ntheorem bit0_succ (x : ℕ) : bit0 (succ x) = succ (succ (bit0 x)) :=\nbegin\n  simp [bit0, add_succ, succ_add]\nend\n\n-- Commute bit1 and succ\nprotected\ntheorem bit1_succ (x : ℕ) : bit1 (succ x) = succ (succ (bit1 x)) :=\nbegin\n  simp [bit1, nat.bit0_succ],\nend\n\n-- Commute succ and bit1.\nprotected\nlemma succ_bit1 (x:ℕ) : succ (bit1 x) = bit0 (succ x) :=\nbegin\n  induction x,\n  case zero { simp, },\n  case succ x ind {\n    simp [nat.bit0_succ, nat.bit1_succ, bit1, succ_add],\n  }\nend\n\nsection literal_simplification_literals\n\n@[simp]\ntheorem zero_eq_bit0_reduce  (x : ℕ) : (0 = bit0 x) ↔ 0 = x :=\nbegin\n  cases x,\n  refl,\n  simp [nat.bit0_succ]\nend\n\n@[simp]\ntheorem zero_eq_bit1_reduce  (x : ℕ) : (0 = bit1 x) ↔ false :=\nbegin\n  simp [bit1, nat.add_succ]\nend\n\n@[simp]\ntheorem one_eq_bit0_reduce  (x : ℕ) : (1 = bit0 x) ↔ false :=\nbegin\n  simp [bit0],\n  cases x,\n  contradiction,\n  simp [succ_eq_succ],\nend\n\n@[simp]\ntheorem one_eq_bit1_reduce  (x : ℕ) : (1 = bit1 x) ↔ 0 = x :=\nbegin\n  simp [bit1, succ_add, succ_eq_succ],\nend\n\n@[simp]\ntheorem bit0_eq_zero_reduce (x : ℕ) : (bit0 x = 0) ↔ x = 0 :=\nbegin\n  cases x,\n  refl,\n  simp [nat.bit0_succ]\nend\n\n@[simp]\ntheorem bit0_eq_one_reduce  (x : ℕ) : (bit0 x = 1) ↔ false :=\nbegin\n  cases x,\n  simp,\n  simp [nat.bit0_succ, succ_eq_succ]\nend\n\n@[simp]\ntheorem bit0_eq_bit0_reduce (x y : ℕ) : (bit0 x = bit0 y) ↔ x = y :=\nbegin\n  revert y,\n  induction x with x ind,\n  { simp },\n  { intros y,\n    cases y,\n    simp [nat.bit0_succ],\n    simp [nat.bit0_succ, succ_eq_succ, ind],\n  }\nend\n\n@[simp]\ntheorem bit0_eq_bit1_reduce (x y : ℕ) : (bit0 x = bit1 y) ↔ false :=\nbegin\n  revert y,\n  induction x with x ind,\n  { simp },\n  { intros y,\n    cases y,\n    simp [nat.bit0_succ, bit1, succ_eq_succ],\n    simp [nat.bit0_succ, nat.bit1_succ, succ_eq_succ, ind],\n  }\nend\n\n@[simp]\ntheorem bit1_eq_zero_reduce (x : ℕ)   : (bit1 x = 0) ↔ false :=\nbegin\n  simp [bit1, bit0, add_succ],\nend\n\n@[simp]\ntheorem bit1_eq_one_reduce  (x : ℕ)   : (bit1 x = 1) ↔ x = 0 :=\nbegin\n  simp [bit1, bit0, add_succ, succ_eq_succ],\n  cases x,\n  refl,\n  simp\nend\n\n@[simp]\ntheorem bit1_eq_bit0_reduce (x y : ℕ) : (bit1 x = bit0 y) ↔ false :=\nbegin\n  revert y,\n  induction x with x ind,\n  { simp },\n  { intros y,\n    cases y,\n    simp,\n    simp [nat.bit1_succ, nat.bit0_succ, succ_eq_succ, ind],\n  }\nend\n\n@[simp]\ntheorem bit1_eq_bit1_reduce (x y : ℕ) : (bit1 x = bit1 y) ↔ x = y :=\nbegin\n  revert y,\n  induction x with x ind,\n  { simp },\n  { intros y,\n    cases y,\n    simp,\n    simp [nat.bit1_succ, succ_eq_succ, ind],\n  }\nend\n\nend literal_simplification_literals\n\nend nat\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/nat/simplify_eq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220294, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.7703040034730564}}
{"text": "def n : ℕ := 10\n\n@[instance] def cong_rel : setoid ℕ :=\n{ r     := λ(x y : ℕ), x % n = y % n,\n  iseqv :=\n    begin\n      rw equivalence,\n      repeat { apply and.intro }, {\n        rw reflexive,\n        intro x,\n        refl,\n      }, {\n        rw symmetric,\n        intros x y,\n        intro hxy,\n        rw hxy,\n      }, {\n        rw transitive,\n        intros x y z,\n        intros hxy hyz,\n        rw [hxy, hyz],\n      },\n    end }\n\nlemma ℕₙ.rel_iff (x y : ℕ) :\n  x ≈ y ↔\n  x % n = y % n :=\nby refl\n\n/- Define ℤ/nℤ or ℤ_n aka ℕₙ from the congruence relation on ℕ. -/\ndef ℕₙ : Type :=\n  quotient cong_rel\n\ndef ℕₙ.add : ℕₙ → ℕₙ → ℕₙ :=\n  quotient.lift₂ (λ(x y : ℕ), ⟦x + y % n⟧) begin\n      intros x y x' y' hx hy,\n      apply quotient.sound,\n      rw ℕₙ.rel_iff at *,\n      norm_num,\n      rw nat.add_mod,\n      rw [hx, hy],\n      rw ←nat.add_mod,\n    end\n\ndef ℕₙ.sub : ℕₙ → ℕₙ → ℕₙ :=\n  quotient.lift₂ (λ(x y : ℕ), ⟦(x + (n - (y % n)) % n)⟧) begin\n      intros x y x' y' hx hy,\n      apply quotient.sound,\n      rw ℕₙ.rel_iff at *,\n      norm_num,\n      rw nat.add_mod,\n      rw [hx, hy],\n      rw ←nat.add_mod,\n    end\n\ndef ℕₙ.le : ℕₙ → ℕₙ → Prop :=\n  quotient.lift₂ (λ(x y : ℕ), (x % n) ≤ (y % n)) begin\n      intros x y x' y' hx hy,\n      rw ℕₙ.rel_iff at *,\n      norm_num,\n      apply iff.intro, {\n        rw [hx, hy],\n        intro h,\n        assumption,\n      }, {\n        intro h,\n        rw [hx, hy],\n        assumption,\n      },\n    end\n\ndef ℕₙ.ge (a b : ℕₙ) : Prop := ℕₙ.le b a\n\n@[instance] def ℕₙ.has_add : has_add ℕₙ := { add := ℕₙ.add }\n\n@[instance] def ℕₙ.has_sub : has_sub ℕₙ := { sub := ℕₙ.sub }\n\n@[instance] def ℕₙ.has_le : has_le ℕₙ := { le := ℕₙ.le }\n\n-- @[instance] def ℕₙ.has_ge : has_ge ℕₙ := { ge := ℕₙ.ge }\n\n@[instance] def ℕₙ.has_zero : has_zero ℕₙ := { zero := ⟦0⟧ }\n\n@[instance] def ℕₙ.has_one : has_one ℕₙ := { one := ⟦1⟧ }\n\ndef add_mod : ℕₙ → ℕₙ → ℕₙ:=\n  quotient.lift₂ (λ(x y : ℕₙ), ⟦x⟧) begin", "meta": {"author": "wyatt-howe", "repo": "lean-prover-one-time-pad", "sha": "a2ee8b936bd419ff24b4ce971ab547eaff799875", "save_path": "github-repos/lean/wyatt-howe-lean-prover-one-time-pad", "path": "github-repos/lean/wyatt-howe-lean-prover-one-time-pad/lean-prover-one-time-pad-a2ee8b936bd419ff24b4ce971ab547eaff799875/src/quotients_playground.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7703039943705445}}
{"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ël Dillies\n-/\nimport data.nat.basic\nimport data.nat.pow\n\n/-!\n# Factorial and variants\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 factorial, along with the ascending and descending variants.\n\n## Main declarations\n\n* `nat.factorial`: The factorial.\n* `nat.asc_factorial`: 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.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 : ℕ → ℕ\n| 0        := 1\n| (succ n) := succ n * factorial n\n\nlocalized \"notation (name := nat.factorial) n `!`:10000 := nat.factorial n\" in nat\n\nsection factorial\n\nvariables {m n : ℕ}\n\n@[simp] theorem factorial_zero : 0! = 1 := rfl\n\n@[simp] theorem factorial_succ (n : ℕ) : 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) ▸ rfl\n\ntheorem factorial_pos : ∀ n, 0 < n!\n| 0        := zero_lt_one\n| (succ n) := mul_pos (succ_pos _) (factorial_pos n)\n\ntheorem factorial_ne_zero (n : ℕ) : n! ≠ 0 := ne_of_gt (factorial_pos _)\n\ntheorem factorial_dvd_factorial {m n} (h : m ≤ n) : m! ∣ n! :=\nbegin\n  induction n with n IH,\n  { simp [nat.eq_zero_of_le_zero h] },\n  obtain rfl | hl := h.eq_or_lt,\n  { simp },\n  exact (IH (le_of_lt_succ hl)).mul_left _,\nend\n\ntheorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ 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 ≤ n) : m! ≤ n! :=\nle_of_dvd (factorial_pos _) (factorial_dvd_factorial h)\n\nlemma factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m! * m.succ ^ n ≤ (m + n)!\n| m 0     := by simp\n| m (n+1) :=\nby  rw [← add_assoc, nat.factorial_succ, mul_comm (nat.succ _), pow_succ', ← 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 := λ n m, factorial_le\n\n\n\nlemma one_lt_factorial : 1 < n! ↔ 1 < n :=\nfactorial_lt one_pos\n\nlemma factorial_eq_one : n! = 1 ↔ n ≤ 1 :=\nbegin\n  refine ⟨λ h, _, by rintro (_ | _ | _); refl⟩,\n  rw [← not_lt, ← one_lt_factorial, h],\n  apply lt_irrefl\nend\n\nlemma factorial_inj (hn : 1 < n!) : n! = m! ↔ n = m :=\nbegin\n  refine ⟨λ h, _, congr_arg _⟩,\n  obtain hnm | rfl | hnm := lt_trichotomy n m,\n  { rw [← factorial_lt $ pos_of_gt $ one_lt_factorial.mp hn, h] at hnm,\n    cases lt_irrefl _ hnm },\n  { refl },\n  rw [h, one_lt_factorial] at hn,\n  rw [←factorial_lt (lt_trans one_pos hn), h] at hnm,\n  cases lt_irrefl _ hnm\nend\n\nlemma self_le_factorial : ∀ n : ℕ, n ≤ 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 : ℕ} (hi : 3 ≤ n) : n < n! :=\nbegin\n  rw [← 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 : ℕ} (n : ℕ) (hi : 2 ≤ i) :\n  i + (n + 1)! < (i + n + 1)! :=\nbegin\n  rw [factorial_succ (i + _), add_mul, one_mul],\n  have : i ≤ 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 ⟨(i + n).factorial_pos, λ g,\n    nat.not_succ_le_self 1 ((hi.trans this).trans (factorial_eq_one.mp g.symm))⟩))) (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 : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ 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 : ℕ) (n : ℕ) :\n  i + (n + 1)! ≤ (i + (n + 1))! :=\nbegin\n  obtain i2 | _ | i0 := le_or_lt 2 i,\n  { exact (n.add_factorial_succ_lt_factorial_add_succ i2).le },\n  { rw [←add_assoc, factorial_succ (1 + n), 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 [le_zero_iff.mp (nat.succ_le_succ_iff.mp i0), zero_add, zero_add]\nend\n\nlemma add_factorial_le_factorial_add (i : ℕ) {n : ℕ} (n1 : 1 ≤ n) :\n  i + n! ≤ (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 : ℕ} (hnm : n ≤ m) : n! * n ^ (m - n) ≤ m! :=\nbegin\n  suffices : n! * (n + 1) ^ (m - n) ≤ 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 : ℕ) : ℕ → ℕ\n| 0 := 1\n| (k + 1) := (n + k + 1) * asc_factorial k\n\n@[simp] lemma asc_factorial_zero (n : ℕ) : n.asc_factorial 0 = 1 := rfl\n\n@[simp] lemma zero_asc_factorial (k : ℕ) : (0 : ℕ).asc_factorial k = k! :=\nbegin\n  induction k with t ht,\n  { refl },\n  rw [asc_factorial, ht, zero_add, nat.factorial_succ],\nend\n\nlemma asc_factorial_succ {n k : ℕ} : n.asc_factorial k.succ = (n + k + 1) * n.asc_factorial k := rfl\n\nlemma succ_asc_factorial (n : ℕ) :\n  ∀ 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  ←add_assoc]\n\n/-- `n.asc_factorial k = (n + k)! / n!` but without ℕ-division. See `nat.asc_factorial_eq_div` for\nthe version with ℕ-division. -/\ntheorem factorial_mul_asc_factorial (n : ℕ) : ∀ 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, ← add_assoc,\n  factorial]\n\n/-- Avoid in favor of `nat.factorial_mul_asc_factorial` if you can. ℕ-division isn't worth it. -/\nlemma asc_factorial_eq_div (n k : ℕ) : n.asc_factorial k = (n + k)! / n! :=\nbegin\n  apply mul_left_cancel₀ n.factorial_ne_zero,\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 : ℕ} (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 [←ht, h', succ_asc_factorial, asc_factorial_succ],\n  rw [ht, succ_eq_add_one, ←tsub_tsub_assoc (succ_le_of_lt h) (succ_pos _), succ_sub_one],\nend\n\nlemma pow_succ_le_asc_factorial (n : ℕ) : ∀ (k : ℕ), (n + 1)^k ≤ 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 : ℕ) : (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 : ℕ) : ∀ {k : ℕ}, 2 ≤ k → (n + 1)^k < n.asc_factorial k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨⟨⟩⟩)\n| (k + 2) := λ _, pow_lt_asc_factorial' n k\n\nlemma asc_factorial_le_pow_add (n : ℕ) : ∀ (k : ℕ), n.asc_factorial k ≤ (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 : ℕ) : ∀ {k : ℕ}, 2 ≤ k → n.asc_factorial k < (n + k)^k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨⟨⟩⟩)\n| (k + 2) := λ _, begin\n  rw [asc_factorial_succ, pow_succ],\n  refine nat.mul_lt_mul' le_rfl ((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 : ℕ) : 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 : ℕ) : ℕ → ℕ\n| 0 := 1\n| (k + 1) := (n - k) * desc_factorial k\n\n@[simp] lemma desc_factorial_zero (n : ℕ) : n.desc_factorial 0 = 1 := rfl\n\n@[simp] lemma desc_factorial_succ (n k : ℕ) :\n  n.desc_factorial k.succ = (n - k) * n.desc_factorial k := rfl\n\nlemma zero_desc_factorial_succ (k : ℕ) :\n  (0 : ℕ).desc_factorial k.succ = 0 :=\nby rw [desc_factorial_succ, zero_tsub, zero_mul]\n\n@[simp] lemma desc_factorial_one (n : ℕ) :\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 : ℕ) :\n  ∀ k : ℕ, (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 : ℕ) :\n  ∀ 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 : ∀ n : ℕ, 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 : ℕ} : ∀ {k : ℕ}, n.desc_factorial k = 0 ↔ 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 λ h _, h,\nend\n\nalias desc_factorial_eq_zero_iff_lt ↔ _ desc_factorial_of_lt\n\nlemma add_desc_factorial_eq_asc_factorial (n : ℕ) :\n  ∀ k : ℕ, (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 ℕ-division. See `nat.desc_factorial_eq_div`\nfor the version using ℕ-division. -/\ntheorem factorial_mul_desc_factorial : ∀ {n k : ℕ}, k ≤ n → (n - k)! * n.desc_factorial k = n!\n| n        0        := λ _, by rw [desc_factorial_zero, mul_one, tsub_zero]\n| 0        (succ k) := λ h, by { exfalso, exact not_succ_le_zero k h }\n| (succ n) (succ k) := λ h, by rw [succ_desc_factorial_succ, succ_sub_succ, ←mul_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. ℕ-division isn't worth it. -/\nlemma desc_factorial_eq_div {n k : ℕ} (h : k ≤ n) : n.desc_factorial k = n! / (n - k)! :=\nbegin\n  apply mul_left_cancel₀ (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 : ℕ) : ∀ (k : ℕ), (n + 1 - k)^k ≤ 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 : ℕ} :\n  ∀ {k : ℕ}, k + 2 ≤ n → (n - (k + 1))^(k + 2) < n.desc_factorial (k + 2)\n| 0 := λ 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) := λ 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 : ℕ} :\n  ∀ {k : ℕ}, 2 ≤ k → k ≤ n → (n + 1 - k)^k < n.desc_factorial k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨⟨⟩⟩)\n| (k + 2) := λ _ h, by { rw succ_sub_succ, exact pow_sub_lt_desc_factorial' h }\n\nlemma desc_factorial_le_pow (n : ℕ) : ∀ (k : ℕ), n.desc_factorial k ≤ 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 : ℕ} (hn : 1 ≤ n) : ∀ {k : ℕ}, 2 ≤ k → n.desc_factorial k < n^k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨⟨⟩⟩)\n| (k + 2) := λ _, 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": "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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.8397339756938819, "lm_q1q2_score": 0.770290213045361}}
{"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 3 : not in (`∉`) and complement `Aᶜ`\n\nThe definition in Lean of `x ∉ A` is `¬ (x ∈ A)`. In other words,\n`x ∉ A`, `¬ (x ∈ A)` and `(x ∈ A) → false` are all equal *by definition*\nin Lean. \n\nThe complement of a subset `A` of `X` is the subset `Aᶜ`; it's the terms of\ntype `X` which aren't in `A`. The *definition* of `x ∈ Aᶜ` is `x ∉ A`. \n\nFor example, if you have a hypothesis `h : x ∈ Aᶜ` and your goal\nis `false`, then `apply h` will work and will change the goal to `x ∈ A`.\nThink a bit about why.\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 : x ∉ A → (x ∈ A → false) :=\nbegin\n  sorry\nend\n\nexample : x ∈ A → (x ∉ A → false) :=\nbegin\n  sorry\nend\n\nexample : (A ⊆ B) → x ∉ B → x ∉ A :=\nbegin\n  sorry\nend\n\n-- Lean couldn't work out what I meant when I wrote `x ∈ ∅` so I had\n-- to give it a hint by telling it the type of `∅`.\nexample : x ∉ (∅ : set X):=\nbegin\n  sorry\nend\n\nexample : x ∈ Aᶜ → x ∉ A :=\nbegin\n  sorry\nend\n\nexample : (∀ x, x ∈ A) ↔ ¬ (∃ x, x ∈ Aᶜ) :=\nbegin\n  sorry\nend\n\nexample : (∃ x, x ∈ A) ↔ ¬ (∀ x, x ∈ Aᶜ) :=\nbegin\n  sorry\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/section05sets/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7702505228787123}}
{"text": "-- La composición de funciones impares es impar\n-- ============================================\n\nimport data.real.basic\n\nvariables (f g : ℝ → ℝ)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la función\n--    impar : (ℝ → ℝ) → Prop\n-- tal que (impar f) expresa que f es impar.\n-- ----------------------------------------------------\n\ndef impar (f : ℝ → ℝ) : Prop :=\n∀ x, f (-x) = -f x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que la composición de\n-- funciones impares es impar.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  impar f → impar g →  impar (g ∘ f) :=\nbegin\n  intros hf hg,\n  unfold impar at *,\n  intro a,\n  unfold function.comp,\n  specialize hf a,\n  rw hf,\n  specialize hg (f a),\n  rw hg,\nend\n\n-- 2ª demostración\nexample :\n  impar f → impar g →  impar (g ∘ f) :=\nbegin\n  intros hf hg a,\n  simp,\n  rw hf,\n  rw hg,\nend\n\n-- 3ª demostración\nexample :\n  impar f → impar g →  impar (g ∘ f) :=\nbegin\n  intros hf hg a,\n  simp,\n  rw [hf, hg],\nend\n\n-- 4ª demostración\nexample :\n  impar f → impar g →  impar (g ∘ f) :=\nbegin\n  intros hf hg x,\n  calc (g ∘ f) (-x)\n       = g (f (-x))  : rfl\n   ... = g (- f x)   : by rw hf\n   ... = -(g (f x))  : by rw hg\n   ... = -(g ∘ f) x  : rfl,\nend\n\n-- 5ª demostración\nexample :\n  impar f → impar g →  impar (g ∘ f) :=\nbegin\n  intros hf hg x,\n  calc (g ∘ f) (-x)\n       = g (f (-x))  : rfl\n   ... = -(g (f x))  : by rw [hf, hg]\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/3_Cuantificadores/La_composicion_de_funciones_impares_es_impar.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7702505136293284}}
{"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-/\nimport analysis.normed_space.conformal_linear_map\nimport analysis.inner_product_space.basic\n\n/-!\n# Conformal maps between inner product spaces\n\nIn an inner product space, a map is conformal iff it preserves inner products up to a scalar factor.\n-/\n\nvariables {E F : Type*}\nvariables [normed_add_comm_group E] [normed_add_comm_group F]\nvariables [inner_product_space ℝ E] [inner_product_space ℝ F]\n\nopen linear_isometry continuous_linear_map\nopen_locale real_inner_product_space\n\n/-- A map between two inner product spaces is a conformal map if and only if it preserves inner\nproducts up to a scalar factor, i.e., there exists a positive `c : ℝ` such that `⟪f u, f v⟫ = c *\n⟪u, v⟫` for all `u`, `v`. -/\nlemma is_conformal_map_iff (f : E →L[ℝ] F) :\n  is_conformal_map f ↔ ∃ (c : ℝ), 0 < c ∧ ∀ (u v : E), ⟪f u, f v⟫ = c * ⟪u, v⟫ :=\nbegin\n  split,\n  { rintros ⟨c₁, hc₁, li, rfl⟩,\n    refine ⟨c₁ * c₁, mul_self_pos.2 hc₁, λ u v, _⟩,\n    simp only [real_inner_smul_left, real_inner_smul_right, mul_assoc, coe_smul',\n      coe_to_continuous_linear_map, pi.smul_apply, inner_map_map] },\n  { rintros ⟨c₁, hc₁, huv⟩,\n    obtain ⟨c, hc, rfl⟩ : ∃ c : ℝ, 0 < c ∧ c₁ = c * c,\n      from ⟨real.sqrt c₁, real.sqrt_pos.2 hc₁, (real.mul_self_sqrt hc₁.le).symm⟩,\n    refine ⟨c, hc.ne', (c⁻¹ • f : E →ₗ[ℝ] F).isometry_of_inner (λ u v, _), _⟩,\n    { simp only [real_inner_smul_left, real_inner_smul_right, huv, mul_assoc, coe_smul,\n        inv_mul_cancel_left₀ hc.ne', linear_map.smul_apply, continuous_linear_map.coe_coe] },\n    { ext1 x,\n      exact (smul_inv_smul₀ hc.ne' (f x)).symm } }\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/inner_product_space/conformal_linear_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7701615728690269}}
{"text": "-- Minimo_de_suma.lean\n-- Si a, b, c ∈ ℝ, entonces min a b + c = min (a + c) (b + c)\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 4-octubre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Sean a, b y c números reales. Demostrar que\n--    min a b + c = min (a + c) (b + c)\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b c : ℝ\n\n-- 1ª demostración\n-- ===============\n\nlemma aux1a :\n  min a b + c ≤ min (a + c) (b + c) :=\nbegin\n  have h1 : min a b  ≤ a :=\n    min_le_left a b,\n  have h2 : min a b + c ≤ a + c :=\n    add_le_add_right h1 c,\n  have h3 : min a b  ≤ b :=\n    min_le_right a b,\n  have h4 : min a b + c ≤ b + c :=\n    add_le_add_right h3 c,\n  show min a b + c ≤ min (a + c) (b + c),\n    by exact le_min h2 h4,\nend\n\nlemma aux2a :\n  min (a + c) (b + c) ≤ min a b + c :=\nbegin\n  have h1 : min (a + c) (b + c) + -c ≤ min a b,\n  { calc min (a + c) (b + c) + -c\n         ≤ min (a + c + -c) (b + c + -c) : aux1a (a + c) (b + c) (-c)\n     ... = min a b                       : by ring_nf },\n  show min (a + c) (b + c) ≤ min a b + c,\n    by exact add_neg_le_iff_le_add.mp h1,\nend\n\nexample :\n  min a b + c = min (a + c) (b + c) :=\nbegin\n  apply le_antisymm,\n  { exact aux1a a b c, },\n  { exact aux2a a b c, },\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma aux1b :\n  min a b + c ≤ min (a + c) (b + c) :=\nbegin\n  apply le_min,\n  { apply add_le_add_right,\n    exact min_le_left a b, },\n  { apply add_le_add_right,\n    exact min_le_right a b, },\nend\n\nlemma aux2b :\n  min (a + c) (b + c) ≤ min a b + c :=\nbegin\n  have h1 : min (a + c) (b + c) + -c ≤ min a b,\n  { calc min (a + c) (b + c) + -c\n         ≤ min (a + c + -c) (b + c + -c) : aux1b (a + c) (b + c) (-c)\n     ... = min a b                       : by ring_nf },\n  exact add_neg_le_iff_le_add.mp h1,\nend\n\nexample :\n  min a b + c = min (a + c) (b + c) :=\nbegin\n  apply le_antisymm,\n  { exact aux1b a b c, },\n  { exact aux2b a b c, },\nend\n\n-- 3ª demostración\n-- ===============\n\nlemma aux1c :\n  min a b + c ≤ min (a + c) (b + c) :=\nle_min (add_le_add_right (min_le_left a b) c)\n       (add_le_add_right (min_le_right a b) c)\n\nlemma aux2c :\n  min (a + c) (b + c) ≤ min a b + c :=\nbegin\n  have h1 : min (a + c) (b + c) + -c ≤ min a b,\n  { calc min (a + c) (b + c) + -c\n         ≤ min (a + c + -c) (b + c + -c) : aux1c (a + c) (b + c) (-c)\n     ... = min a b                       : by ring_nf },\n  exact add_neg_le_iff_le_add.mp h1,\nend\n\nexample :\n  min a b + c = min (a + c) (b + c) :=\nle_antisymm (aux1b a b c) (aux2b a b c)\n\n-- 4ª demostración\n-- ===============\n\nexample : min a b + c = min (a + c) (b + c) :=\nbegin\n  by_cases (a ≤ b),\n  { have h1 : a + c ≤ b + c,\n      apply add_le_add_right h,\n    calc min a b + c = a + c               : by simp [min_eq_left h]\n                 ... = min (a + c) (b + c) : by simp [min_eq_left h1]},\n  { have h2: b ≤ a,\n      linarith,\n    have h3 : b + c ≤ a + c,\n      { exact add_le_add_right h2 c },\n    calc min a b + c = b + c               : by simp [min_eq_right h2]\n                 ... = min (a + c) (b + c) : by simp [min_eq_right h3]},\nend\n\n-- 5ª demostración\n-- ===============\n\nexample : min a b + c = min (a + c) (b + c) :=\n(min_add_add_right a b c).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/Minimo_de_suma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7700652418088483}}
{"text": "-- Opuesto_del_opuesto.lean\n-- Si R es un anillo y a ∈ R, entonces -(-a) = a.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 9-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si R es un anillo y a ∈ R, entonces\n--    -(-a) = a\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\n\nvariables {R : Type*} [ring R]\nvariable a : R\n\n-- 1ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nbegin\n  calc -(-a)\n       = -(0 - a) : congr_arg (λ x, -x) (zero_sub a).symm\n   ... = a - 0    : neg_sub (0 : R) a\n   ... = a        : sub_zero a\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nbegin\n  calc -(-a)\n       = -(0 - a) : by { congr; rw zero_sub}\n   ... = a - 0    : by rw neg_sub\n   ... = a        : by rw sub_zero\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nby simpa only [zero_sub, sub_zero] using (neg_sub (0 : R) a)\n\n-- 4ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nneg_neg a\n\n-- 5ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nby simp\n\n-- 6ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nbegin\n  apply neg_eq_of_add_eq_zero_right,\n  rw neg_add_self a,\nend\n\n-- 7ª demostración\n-- ===============\n\nexample : -(-a) = a :=\nneg_eq_of_add_eq_zero_right (neg_add_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/Opuesto_del_opuesto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7700652388016748}}
{"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.basic\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] [fintype F] {a : F}\n (ha : a ≠ 0) : ∃ b : F, algebra.trace (zmod (ring_char F)) F (a * b) ≠ 0 :=\nbegin\n  haveI : fact (ring_char F).prime := ⟨char_p.char_is_prime F _⟩,\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": "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/finite/trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7700510370993141}}
{"text": "\n\n\n\n\n\n/-\nTerminology: INTRODUCTION RULES\n-/\n\n/-\nThe constructors of a type implement\nwhat in logic and computation we can\ncall *introduction* rules. They give\nus ways to *introduce* vaues of some\nparticular type.\n-/\n\n\n\n/-\nInference rule notation.\n-/\n\n/-\nThere are two introduction rules for bool\n\n  Γ ⊢ bool.tt : bool   -- bool_intro_tt\n  Γ ⊢ bool.ff : bool   -- bool_intro_ff\n\nThe capital Greek letter Gamma (Γ) stands\nfor an set of definitions assumed already\nto be given. The turnstile character (⊢)\nmeans that \"in this context it is possible\nto deduce the \"type judgement\" after the\nturnstile. Concretely, here, the rules say\nthat \"in any context, without any further\nassumptions, we can deduce that bool.tt is\na value of type bool (and the same goes\nfor bool.ff).\n\nIn logical terms, you can read such a rule\nas *asserting* that if the definitions in \nthe context are assumed to be true (we can\nthink of these as premises or preconditions)\nthen it's possible to derive the truth of\nthe \"judgment\" that comes below the line \n(after the turnstile).\n\n\nThe preceding notation above is \"inline\" \nnotation (context ⊢ judgment) and is used\nfor giving short inference rules. Dispay \nnotation, illustrated below, is generally\nused intead when rules are too long to be\nreadable on one line. Here the context is \nabove the line; the line is used instead \nof the turnstile; a judgment is given below \nthe line; and the name of the inference\nrule is given to the right of the line. \nWe will often attach _intro or _I to the \nname of a rule to indicate that it's an\nintroduction rule. \n\n  Γ\n------ bool_intro.tt\n bool\n\n   Γ\n------ bool_intro.ff\n bool\n\nNote also that if there really are no\npreconditions on the context for the\napplication of a rule, the Γ is often\nleft out.\n\n \n------ bool_intro.tt\n bool\n\n\n------ bool_intro.ff\n bool\n\n\nIn logic, an introduction rule with\nno preconditions is called an axiom.\nIt allows us to make certain judgments\nwithout already knowing anything else\nat all.\n\nThe constructors of inductive types\ncan be read as type-speific axioms.\nThe constructor \"| tt : bool\", for\nexample, says that are given the type\njudgment, tt : bool, \"for free\". We\ncan assume it's true with the need\nfor any prior or additional evidence.\n\nEXERCISE: How many introduction rules\nare there for the day type?\n\nHere are introduction rules for some\nof our other types\n\nWhile constructors can be read as axioms,\nwhich is to say that we can always assume\nthey're valid, sometimes to apply or use\nsuch a rule, we do need certain additional\nassumptions to be true.\n\nConsider the box constructor, mk. A way\nto read it is that \"If we may assume that\nn is a value of type ℕ then we may infer\nthat the term (box_ℕ.mk n) is of type \nbox_ℕ.\"\n\nΓ, (n : ℕ) ⊢ (box_ℕ.mk n) : box_ℕ \n\n     Γ, (n : ℕ)\n---------------------- box_ℕ_intro\n (box_ℕ.mk n) : box_ℕ \n\n Note that such rules often leave out\n the full statement of the type judgment\n below the line (after the turnstile).Type\n\n      Γ, (n : ℕ)\n---------------------- box_ℕ_intro\n        box_ℕ \n\nThis just says that in a context in which\nI have that n is of type nat, I can use the\nbox_ℕ_intro rule to construct a value of \ntype box_ℕ.\n\n NB! There's really nothing new here\n at all. All we're really doing here \n it representing the *types* of available\n constructors (introduction rules) using \n a sort of textual notation (inline or\n display). Here's one of the ways we \n wrote the same information above.\n\n| mk (n : ℕ) : box_ℕ \n\nConstructors are introduction rules \nthat we take as axioms, i.e., as being\ngiven, defined, and available for use.\nThat said, these axioms are often in\nthe form of implications that do require\nsome additional conditions to be true\nbefore they can be used to derive given\nconclusions. For example, the box_ℕ \nintroduction rule does require that we\ncan assume that (n : ℕ). You can think\nof *arguments* to constructors (and to\nfunctions more generally) as assumptions\nthat have to be satisfied before the\nconstructor or function can be used!\n \nConstructors are introductions rules\nthat are accepted as axioms\n\nArguments to constructors are additional\nassumptions that have to be true before \nsuch rules can be applied to derive the\ngiven conclusions.\n\nIn general, inference rules can require\nthat multiple assumptions be true before\na conclusion can be drawn.\n\nΓ, (n : ℕ) (s : string)\n----------------------- prod_ℕ_string_intro\n(mk n s) : prod_ℕ_string\n\nGive a context containing at least the\nassumptions that (n : ℕ) and (s : string)\nthis inference rules allows us to deduce\nthat we can construct and object (mk n s)\nof type prod_ℕ_string. \n\nConstructors are \"introduction\" inference \nrules that end with the construction of a\na new object with the specified type.\n-/\n\n/-\nThere's really nothing mysterious about\nthis notation. It's basically a way of\nexplaining/claiming that in a specified\ncontext, i.e., contingent on a given set\nof assumptions, some object of a certain\ntype can be constructed. \n-/\n\n\n/-\nTerminology: ELIMINATION RULES\n\nWhere introduction rules explain how we can\nform new terms (objects, values) of specific\ntypes, ELIMINAATION rules tell us how we can\nUSE objects of given type (to form objects of\nother types). \n\nTo use an object of some type, we often need to\nDESTRUCTURE it: to take it apart to see both\nthe constructor that was used to form it and\nthe arguments (if any) that were supplied to\nthe constructor when the object was created.\n\nConsider the following elimination rule. \n\n         Γ, (d : day)\n---------------------------- day_elim\n(e, p) : Σ (d : day), e ≠ d\n\nWe assume we're in a context in which we're\ngiven a day d, and we then \"use\" d to pick\na different day, e, which we return as the\nfirst element of a pair, along with evidence\nthat e really is a different day.\n\nCan we prove to ourselves that this rule is\nactually realizable? It seems like it should\nbe possible. For example, given a day, d, we\ncan always pick \"the next\" day as e, and then\nwe just need a little \"proof\" that e really \nis not the same day as d.\n\nNow here's a crucial point. To use a value \nof a sum type, here of type day, we will often \nhave to perform a case analysis, to determine \nwhich of several possible \"forms\" of value \nwe're looking at (which constructor was used\nto introduce the value in the first place).\n-/\n\ndef next_day : day → day\n| sun := mon\n| mon := tue\n| tue := wed\n| wed := thu\n| thu := fri\n| fri := sat\n| sat := sun\n\n#reduce next_day tue\n\ndef exists_different_day (d : day) : ∃ (e : day), e ≠ d :=\n  exists.intro \n    (next_day d) \n    (by begin \n      cases d,          -- consider each possible day, d\n      simp [next_day],  -- apply rules in next_day + \"magic\"\n      simp [next_day],  -- do the same thing for each case\n      simp [next_day],\n      simp [next_day],\n      simp [next_day],\n      simp [next_day],\n      simp [next_day],\n  end) \n\n#reduce (exists_different_day sat)    -- Yikes :-)\n\n\n/-\nLots of things to say, here:\n\n1. Inference rule notation\n\n      Γ, (d : day)\n----------------------- day_elim_different_day\npf : ∃ (e : day), e ≠ d\n\n2. Lean is language in which we can compute with\nlogical propositions and proofs just as easily as\nwe can compute with natural numbers, bools, strings,\nand so forth. This puts it in a completely different\nclass of languages than mere functional languages, \nsuch as Haskell, OCaml, Scheme, etc.\n\n3. We see in this example that in the logical framework\nthat Lean presents, propositions are represented as \ntypes, and proofs of propositions are simply values of \nsuch types. Moreover, the type checker ensures that \nproofs are of the right types -- that the prove the\npropositions they are claimed to prove. If P is a type\nthat represents a proposition, and we have (pf : P), \njust as if (n : ℕ) type checks, we can be *sure* that\nn really is a term of type ℕ!\n\n4. Clearly it's going to be super-important to learn \nabout types. In fact, Lean is really just implements\none particular version of the theoretical field of CS\ncalled type theory.\n\n5. Type theory is so expressive that it provides us\nwith what we call a logical framework, which is a \nlanguage within which we can define and automate many\nother logics, and many other languages, more broadly,\nincluding such languages as C, Python, etc. We have\nalready implemented the syntax and semantics of one\nvery simple language of (a few) Roman numberals.\n\n6. Note that we picked a particular implementation,\nnext day, to pick a \"witness\" to the proposition that\nthere's a different day for each possible argument of\ntype day. The witness selected when d := wed, for \nexample, is thu. We could have used a different \nwitness-picking function, such as one that returns\nthe previous day, as long as it really does *always*\nreturn a day that's different than the one given as \nan argument. \n\n7. If our witness-picking function has a bug, then \nour proof-constructing function will fail, because\nthere will be some day for which the chooser will \nchoose them same day as a \"e\", the intended witness,\nand it will then be impossible to construct the proof\nthat e ≠ d. The lean proof checker can can find bugs\nin programs relative to a logical *specifications* of \ntheir required behaviors.\n\nExercise: make a small change to next_day so that \nit no longer *always* returns a day different from\nthe one given, and then find exactly where the type\nchecker raises an error.\n\nPhew, that was a lot! Some of you don't even have a \nfirm grasp of what we mean by a proposition or a proof.\nNo worries, this was just a little \"exposure.\" Are you\nfeeling sunburned?\n\nTo bring it back to where we started, elimination rules\nare simply \"rules\" (often just funtions) for *consuming* \nrather than *constructing* values of a given type. \n\nEhen the type of object being consumed is a sum type,\nwe generally need to do a case analysis to determine\nwhich variant we've been given as a value. \n\nThe next_day function is a good example: it consumes\na *day* value, does a case analysis to figure out which \nconstructor/variant is assumed to have been given as an\nargument, then computes and returns a result accordingly.  \n\nAs a second example of a day-elimination (day-consuming)\nfunction/rule, we defined different_day as a function\nthat uses/consumes a value of type day and returns (if\nyou prefer, introduces) a value that proves that there \nis *some* day different than the one consumed.\n-/\n\n-- ELIMINATION/USE OF VALUES OF PRODUCT TYPES\n\n/-\nInference rule notation\n\n Γ, (n : ℕ) (s : string)\n------------------------ prod_intro\n ⟨n, s⟩ : Prod_ℕ_string\n\n\nΓ, ⟨n, s⟩ : prod_ℕ_string\n------------------------- prod_elim_fst\n        n : ℕ \n\n\nΓ, ⟨n, s⟩ : prod_ℕ_string\n------------------------- prod_elim_snd\n        s : string\n-/\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/inferenceRules.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7700143904857143}}
{"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\n! This file was ported from Lean 3 source module data.fin.basic\n! leanprover-community/mathlib commit 008af8bb14b3ebef7e04ec3b0d63b947dee4d26a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Algebra.NeZero\nimport Mathlib.Algebra.Order.WithZero\nimport Mathlib.Order.RelIso.Basic\nimport Mathlib.Data.Nat.Order.Basic\nimport Mathlib.Order.Hom.Set\nimport Mathlib.Tactic.Set\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* `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`.\n* `Fin.succRec` : Define `C n i` by induction on  `i : Fin n` interpreted\n  as `(0 : Fin (n - i)).succ.succ…`. 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.succRecOn` : same as `Fin.succRec` 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.inductionOn` : same as `Fin.induction` but with `i : Fin (n + 1)` as the first argument.\n* `Fin.cases` : define `f : Π 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.reverseInduction`: reverse induction on `i : Fin (n + 1)`; given `C (Fin.last n)` and\n  `∀ i : Fin n, C (Fin.succ i) → C (Fin.castSucc i)`, constructs all values `C i` by going down;\n* `Fin.lastCases`: define `f : Π i, Fin (n + 1), C i` by separately handling the cases\n  `i = Fin.last n` and `i = Fin.castSucc j`, a special case of `Fin.reverseInduction`;\n* `Fin.addCases`: define a function on `Fin (m + n)` by separately handling the cases\n  `Fin.castAdd n i` and `Fin.natAdd m i`;\n* `Fin.succAbove_cases`: given `i : Fin (n + 1)`, define a function on `Fin (n + 1)` by separately\n  handling the cases `j = i` and `j = Fin.succAbove i k`, same as `Fin.insertNth` but marked\n  as eliminator and works for `Sort*`. -- Porting note: this is in another file\n\n### Order embeddings and an order isomorphism\n\n* `Fin.orderIsoSubtype` : coercion to `{ i // i < n }` as an `OrderIso`;\n* `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`;\n* `Fin.valOrderEmbedding` : coercion to natural numbers as an `OrderEmbedding`;\n* `Fin.succEmbedding` : `Fin.succ` as an `OrderEmbedding`;\n* `Fin.castLe h` : embed `Fin n` into `Fin m`, `h : n ≤ m`;\n* `Fin.cast` : order isomorphism between `Fin n` and `Fin m` provided that `n = m`,\n  see also `Equiv.finCongr`;\n* `Fin.castAdd m` : embed `Fin n` into `Fin (n+m)`;\n* `Fin.castSucc` : embed `Fin n` into `Fin (n+1)`;\n* `Fin.succAbove p` : embed `Fin n` into `Fin (n + 1)` with a hole around `p`;\n* `Fin.addNat m i` : add `m` on `i` on the right, generalizes `Fin.succ`;\n* `Fin.natAdd n i` adds `n` on `i` on the left;\n\n### Other casts\n\n* `Fin.ofNat'`: given a positive number `n` (deduced from `[NeZero n]`), `Fin.ofNat' i` is\n  `i % n` interpreted as an element of `Fin n`;\n* `Fin.castLt i h` : embed `i` into a `Fin` where `h` proves it belongs into;\n* `Fin.predAbove (p : Fin n) i` : embed `i : Fin (n+1)` into `Fin n` by subtracting one if `p < i`;\n* `Fin.castPred` : embed `Fin (n + 2)` into `Fin (n + 1)` by mapping `Fin.last (n + 1)` to\n  `Fin.last n`;\n* `Fin.subNat i h` : subtract `m` from `i ≥ m`, generalizes `Fin.pred`;\n* `Fin.clamp n m` : `min n m` as an element of `Fin (m + 1)`;\n* `Fin.divNat i` : divides `i : Fin (m * n)` by `n`;\n* `Fin.modNat 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* `Fin.rev : Fin n → Fin n` : the antitone involution given by `i ↦ n-(i+1)`\n\n-/\n\nuniverse u v\n\nopen Fin Nat Function\n\n/-- Elimination principle for the empty set `Fin 0`, dependent version. -/\ndef finZeroElim {α : Fin 0 → Sort _} (x : Fin 0) : α x :=\n  x.elim0\n#align fin_zero_elim finZeroElim\n\nnamespace Fin\n\n/-- A non-dependent variant of `elim0`. -/\ndef elim0' {α : Sort _} (x : Fin 0) : α :=\n  x.elim0\n#align fin.elim0' Fin.elim0'\n\nvariable {n m : ℕ}\n--variable {a b : Fin n} -- this *really* breaks stuff\n\n#align fin.fin_to_nat Fin.coeToNat\n\ntheorem val_injective : Function.Injective (@Fin.val n) :=\n  @Fin.eq_of_veq n\n#align fin.val_injective Fin.val_injective\n\nsection from_ad_hoc\n-- porting note: the next seven lemmas aren't from mathlib3, but the `*_def` ones were in lean3 core\n-- and they were in the ad hoc port of this file\n\n/-- If you actually have an element of `Fin n`, then the `n` is always positive -/\nlemma size_positive : Fin n → 0 < n\n| ⟨x, h⟩ =>\n  match Nat.eq_or_lt_of_le (Nat.zero_le x) with\n  | Or.inl h_eq => h_eq ▸ h\n  | Or.inr h_lt => Nat.lt_trans h_lt h\n\nlemma mod_def : ∀ (a m : Fin n),\n  a % m = Fin.mk ((a.val % m.val) % n) (Nat.mod_lt (a.val % m.val) (a.size_positive))\n| ⟨_, _⟩, ⟨_, _⟩ => rfl\n\nlemma add_def : ∀ (a b : Fin n),\n  a + b = (Fin.mk ((a.val + b.val) % n) (Nat.mod_lt _ (a.size_positive)))\n| ⟨_, _⟩, ⟨_, _⟩ => rfl\n\nlemma mul_def : ∀ (a b : Fin n),\n  a * b = (Fin.mk ((a.val * b.val) % n) (Nat.mod_lt _ (a.size_positive)))\n| ⟨_, _⟩, ⟨_, _⟩ => rfl\n\nlemma sub_def : ∀ (a b : Fin n),\n  a - b = (Fin.mk ((a + (n - b)) % n) (Nat.mod_lt _ (a.size_positive)))\n| ⟨_, _⟩, ⟨_, _⟩ => rfl\n\nlemma size_positive' [Nonempty (Fin n)] : 0 < n :=\n  ‹Nonempty (Fin n)›.elim fun i ↦ Fin.size_positive i\n\nend from_ad_hoc\n\nprotected theorem prop (a : Fin n) : a.val < n :=\n  a.2\n#align fin.prop Fin.prop\n\n@[simp]\ntheorem is_lt (a : Fin n) : (a : ℕ) < n :=\n  a.2\n#align fin.is_lt Fin.is_lt\n\nprotected theorem pos (i : Fin n) : 0 < n :=\n  lt_of_le_of_lt (Nat.zero_le _) i.is_lt\n#align fin.pos Fin.pos\n\ntheorem pos_iff_nonempty {n : ℕ} : 0 < n ↔ Nonempty (Fin n) :=\n  ⟨fun h => ⟨⟨0, h⟩⟩, fun ⟨i⟩ => i.pos⟩\n#align fin.pos_iff_nonempty Fin.pos_iff_nonempty\n\n/-- Equivalence between `Fin n` and `{ i // i < n }`. -/\n@[simps apply symm_apply]\ndef equivSubtype : Fin n ≃ { i // i < n } where\n  toFun a := ⟨a.1, a.2⟩\n  invFun a := ⟨a.1, a.2⟩\n  left_inv := fun ⟨_, _⟩ => rfl\n  right_inv := fun ⟨_, _⟩ => rfl\n#align fin.equiv_subtype Fin.equivSubtype\n#align fin.equiv_subtype_symm_apply Fin.equivSubtype_symm_apply\n#align fin.equiv_subtype_apply Fin.equivSubtype_apply\n\nsection coe\n\n/-!\n### coercions and constructions\n-/\n\n@[simp]\nprotected theorem eta (a : Fin n) (h : (a : ℕ) < n) : (⟨(a : ℕ), h⟩ : Fin n) = a := by\n  cases a; rfl\n#align fin.eta Fin.eta\n\n@[ext]\ntheorem ext {a b : Fin n} (h : (a : ℕ) = b) : a = b :=\n  eq_of_veq h\n#align fin.ext Fin.ext\n\ntheorem ext_iff {a b : Fin n} : a = b ↔ (a : ℕ) = b :=\n  Iff.intro (congr_arg _) Fin.eq_of_veq\n#align fin.ext_iff Fin.ext_iff\n\n#align fin.coe_injective Fin.val_injective\n\ntheorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b :=\n  ext_iff.symm\n#align fin.coe_eq_coe Fin.val_eq_val\n\ntheorem eq_iff_veq (a b : Fin n) : a = b ↔ a.1 = b.1 :=\n  ⟨veq_of_eq, eq_of_veq⟩\n#align fin.eq_iff_veq Fin.eq_iff_veq\n\ntheorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 :=\n  ⟨vne_of_ne, ne_of_vne⟩\n#align fin.ne_iff_vne Fin.ne_iff_vne\n\n-- porting note: I'm not sure if this comment still applies.\n-- built-in reduction doesn't always work\n@[simp, nolint simpNF]\ntheorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' :=\n  ext_iff\n#align fin.mk_eq_mk Fin.mk_eq_mk\n\nprotected theorem mk.inj_iff {n a b : ℕ} {ha : a < n} {hb : b < n} :\n    (⟨a, ha⟩ : Fin n) = ⟨b, hb⟩ ↔ a = b :=\n  eq_iff_veq _ _\n#align fin.mk.inj_iff Fin.mk.inj_iff\n\ntheorem val_mk {m n : ℕ} (h : m < n) : (⟨m, h⟩ : Fin n).val = m :=\n  rfl\n#align fin.mk_val Fin.val_mk\n\ntheorem eq_mk_iff_val_eq {a : Fin n} {k : ℕ} {hk : k < n} : a = ⟨k, hk⟩ ↔ (a : ℕ) = k :=\n  Fin.eq_iff_veq a ⟨k, hk⟩\n#align fin.eq_mk_iff_coe_eq Fin.eq_mk_iff_val_eq\n\n#align fin.coe_mk Fin.val_mk\n\ntheorem mk_val (i : Fin n) : (⟨i, i.isLt⟩ : Fin n) = i :=\n  Fin.eta _ _\n#align fin.mk_coe Fin.mk_val\n\n-- syntactic tautologies now\n#noalign fin.coe_eq_val\n#noalign fin.val_eq_coe\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 theorem heq_fun_iff {α : Sort _} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} :\n    HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by\n  subst h\n  simp [Function.funext_iff]\n#align fin.heq_fun_iff Fin.heq_fun_iff\n\nprotected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} :\n    HEq i j ↔ (i : ℕ) = (j : ℕ) := by\n  subst h\n  simp [val_eq_val]\n#align fin.heq_ext_iff Fin.heq_ext_iff\n\ntheorem exists_iff {p : Fin n → Prop} : (∃ i, p i) ↔ ∃ i h, p ⟨i, h⟩ :=\n  ⟨fun h => Exists.elim h fun ⟨i, hi⟩ hpi => ⟨i, hi, hpi⟩, fun h =>\n    Exists.elim h fun i hi => ⟨⟨i, hi.fst⟩, hi.snd⟩⟩\n#align fin.exists_iff Fin.exists_iff\n\ntheorem forall_iff {p : Fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩ :=\n  ⟨fun h i hi => h ⟨i, hi⟩, fun h ⟨i, hi⟩ => h i hi⟩\n#align fin.forall_iff Fin.forall_iff\n\nend coe\n\nsection Order\n\n/-!\n### order\n-/\n\n\ntheorem is_le (i : Fin (n + 1)) : (i : ℕ) ≤ n :=\n  le_of_lt_succ i.is_lt\n#align fin.is_le Fin.is_le\n\n@[simp]\ntheorem is_le' {a : Fin n} : (a : ℕ) ≤ n :=\n  le_of_lt a.is_lt\n#align fin.is_le' Fin.is_le'\n\ntheorem lt_iff_val_lt_val {a b : Fin n} : a < b ↔ (a : ℕ) < b :=\n  Iff.rfl\n#align fin.lt_iff_coe_lt_coe Fin.lt_iff_val_lt_val\n\ntheorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b :=\n  Iff.rfl\n#align fin.le_iff_coe_le_coe Fin.le_iff_val_le_val\n\ntheorem mk_lt_of_lt_val {b : Fin n} {a : ℕ} (h : a < b) : (⟨a, h.trans b.is_lt⟩ : Fin n) < b :=\n  h\n#align fin.mk_lt_of_lt_coe Fin.mk_lt_of_lt_val\n\ntheorem mk_le_of_le_val {b : Fin n} {a : ℕ} (h : a ≤ b) : (⟨a, h.trans_lt b.is_lt⟩ : Fin n) ≤ b :=\n  h\n#align fin.mk_le_of_le_coe Fin.mk_le_of_le_val\n\n/-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/\n@[norm_cast, simp]\ntheorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=\n  Iff.rfl\n#align fin.coe_fin_lt Fin.val_fin_lt\n\n/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/\n@[norm_cast, simp]\ntheorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=\n  Iff.rfl\n#align fin.coe_fin_le Fin.val_fin_le\n\ninstance {n : ℕ} : LinearOrder (Fin n) :=\n  @LinearOrder.liftWithOrd (Fin n) _ _ ⟨fun x y => ⟨max x y, max_rec' (· < n) x.2 y.2⟩⟩\n    ⟨fun x y => ⟨min x y, min_rec' (· < n) x.2 y.2⟩⟩ _ Fin.val Fin.val_injective (fun _ _ => rfl)\n    (fun _ _ => rfl) (fun _ _ => rfl)\n\n@[simp]\ntheorem mk_le_mk {x y : Nat} {hx} {hy} : (⟨x, hx⟩ : Fin n) ≤ ⟨y, hy⟩ ↔ x ≤ y :=\n  Iff.rfl\n#align fin.mk_le_mk Fin.mk_le_mk\n\n@[simp]\ntheorem mk_lt_mk {x y : Nat} {hx} {hy} : (⟨x, hx⟩ : Fin n) < ⟨y, hy⟩ ↔ x < y :=\n  Iff.rfl\n#align fin.mk_lt_mk Fin.mk_lt_mk\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp\n#align fin.min_coe Fin.min_val\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp\n#align fin.max_coe Fin.max_val\n\ninstance {n : ℕ} : PartialOrder (Fin n) := by infer_instance\n\ntheorem val_strictMono : StrictMono (val : Fin n → ℕ) := fun _ _ => id\n#align fin.coe_strict_mono Fin.val_strictMono\n\n/-- The equivalence `Fin n ≃ { i // i < n }` is an order isomorphism. -/\n@[simps! apply symm_apply]\ndef orderIsoSubtype : Fin n ≃o { i // i < n } :=\n  equivSubtype.toOrderIso (by simp [Monotone]) (by simp [Monotone])\n#align fin.order_iso_subtype Fin.orderIsoSubtype\n#align fin.order_iso_subtype_symm_apply Fin.orderIsoSubtype_symm_apply\n#align fin.order_iso_subtype_apply Fin.orderIsoSubtype_apply\n\n/-- The inclusion map `Fin n → ℕ` is an embedding. -/\n@[simps apply]\ndef valEmbedding : Fin n ↪ ℕ :=\n  ⟨val, val_injective⟩\n#align fin.coe_embedding Fin.valEmbedding\n\n@[simp]\ntheorem equivSubtype_symm_trans_valEmbedding :\n    equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) :=\n  rfl\n#align fin.equiv_subtype_symm_trans_val_embedding Fin.equivSubtype_symm_trans_valEmbedding\n\n/-- The inclusion map `Fin n → ℕ` is an order embedding. -/\n@[simps! apply]\ndef valOrderEmbedding (n) : Fin n ↪o ℕ :=\n  ⟨valEmbedding, Iff.rfl⟩\n#align fin.coe_order_embedding Fin.valOrderEmbedding\n\n/-- The ordering on `Fin n` is a well order. -/\ninstance Lt.isWellOrder (n) : IsWellOrder (Fin n) (· < ·) :=\n  (valOrderEmbedding n).isWellOrder\n#align fin.fin.lt.is_well_order Fin.Lt.isWellOrder\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 `WellFoundedRelation` instance:\n```lean\ndef factorial {n : ℕ} : Fin n → ℕ\n| ⟨0, _⟩ := 1\n| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩\n```\n-/\ninstance {n : ℕ} : WellFoundedRelation (Fin n) :=\n  measure (val : Fin n → ℕ)\n\n/-- Given a positive `n`, `Fin.ofNat' i` is `i % n` as an element of `Fin n`. -/\ndef ofNat'' [NeZero n] (i : ℕ) : Fin n :=\n  ⟨i % n, mod_lt _ <| NeZero.pos n⟩\n#align fin.of_nat' Fin.ofNat''ₓ\n-- porting note: `Fin.ofNat'` conflicts with something in core (there the hypothesis is `n > 0`),\n-- so for now we make this double-prime `''`. This is also the reason for the dubious translation.\n\ninstance {n : ℕ} [NeZero n] : Zero (Fin n) := ⟨ofNat'' 0⟩\ninstance {n : ℕ} [NeZero n] : One (Fin n) := ⟨ofNat'' 1⟩\n\n-- porting note: `fin.val_zero` previously existed in core with statement\n-- `(0 : fin (succ n)).val = 0`, which was less general than the priemd mathlib lemma. We unprime\n-- the name now that there is no clash.\n@[simp]\ntheorem val_zero (n : ℕ) [NeZero n] : ((0 : Fin n) : ℕ) = 0 :=\n  rfl\n#align fin.coe_zero Fin.val_zero\n#align fin.val_zero' Fin.val_zero\n\n@[simp]\ntheorem mk_zero [NeZero n] : (⟨0, NeZero.pos n⟩ : Fin n) = (0 : Fin _) :=\n  rfl\n#align fin.mk_zero Fin.mk_zero\n\n@[simp]\ntheorem zero_le [NeZero n] (a : Fin n) : 0 ≤ a :=\n  Nat.zero_le a.val\n#align fin.zero_le Fin.zero_le\n\ntheorem zero_lt_one : (0 : Fin (n + 2)) < 1 :=\n  Nat.zero_lt_one\n#align fin.zero_lt_one Fin.zero_lt_one\n\n@[simp]\ntheorem not_lt_zero (a : Fin n.succ) : ¬a < 0 :=\n  fun.\n#align fin.not_lt_zero Fin.not_lt_zero\n\ntheorem pos_iff_ne_zero [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by\n  rw [← val_fin_lt, val_zero, _root_.pos_iff_ne_zero, Ne.def, Ne.def, ext_iff, val_zero]\n#align fin.pos_iff_ne_zero Fin.pos_iff_ne_zero\n\ntheorem eq_zero_or_eq_succ {n : ℕ} (i : Fin (n + 1)) : i = 0 ∨ ∃ j : Fin n, i = j.succ := by\n  rcases i with ⟨_ | j, h⟩\n  · left\n    rfl\n  · right\n    exact ⟨⟨j, Nat.lt_of_succ_lt_succ h⟩, rfl⟩\n#align fin.eq_zero_or_eq_succ Fin.eq_zero_or_eq_succ\n\ntheorem eq_succ_of_ne_zero {n : ℕ} {i : Fin (n + 1)} (hi : i ≠ 0) : ∃ j : Fin n, i = j.succ :=\n  (eq_zero_or_eq_succ i).resolve_left hi\n#align fin.eq_succ_of_ne_zero Fin.eq_succ_of_ne_zero\n\n/-- The antitone involution `Fin n → Fin n` given by `i ↦ n-(i+1)`. -/\ndef rev : Equiv.Perm (Fin n) :=\n  (Involutive.toPerm fun i => ⟨n - (i + 1), tsub_lt_self i.pos (Nat.succ_pos _)⟩) fun i =>\n    ext <| by\n      dsimp only\n      rw [← tsub_tsub, tsub_tsub_cancel_of_le (Nat.add_one_le_iff.2 i.is_lt),\n        add_tsub_cancel_right]\n#align fin.rev Fin.rev\n\n-- porting note: dot notation of the form `i.rev` is broken here and throughout\n@[simp]\ntheorem val_rev (i : Fin n) : (rev i : ℕ) = n - (i + 1) :=\n  rfl\n#align fin.coe_rev Fin.val_rev\n\ntheorem rev_involutive : Involutive (@rev n) :=\n  Involutive.toPerm_involutive _\n#align fin.rev_involutive Fin.rev_involutive\n\ntheorem rev_injective : Injective (@rev n) :=\n  rev_involutive.injective\n#align fin.rev_injective Fin.rev_injective\n\ntheorem rev_surjective : Surjective (@rev n) :=\n  rev_involutive.surjective\n#align fin.rev_surjective Fin.rev_surjective\n\ntheorem rev_bijective : Bijective (@rev n) :=\n  rev_involutive.bijective\n#align fin.rev_bijective Fin.rev_bijective\n\n-- @[simp] -- Porting note: simp can prove this\ntheorem rev_inj {i j : Fin n} : rev i = rev j ↔ i = j :=\n  rev_injective.eq_iff\n#align fin.rev_inj Fin.rev_inj\n\n@[simp]\ntheorem rev_rev (i : Fin n) : rev (rev i) = i :=\n  rev_involutive _\n#align fin.rev_rev Fin.rev_rev\n\n@[simp]\ntheorem rev_symm : (@rev n).symm = rev :=\n  rfl\n#align fin.rev_symm Fin.rev_symm\n\ntheorem rev_eq {n a : ℕ} (i : Fin (n + 1)) (h : n = a + i) :\n    rev i = ⟨a, Nat.lt_succ_iff.mpr (Nat.le.intro h.symm)⟩ := by\n  ext\n  dsimp\n  conv_lhs =>\n    congr\n    rw [h]\n  rw [add_assoc, add_tsub_cancel_right]\n#align fin.rev_eq Fin.rev_eq\n\n@[simp]\ntheorem rev_le_rev {i j : Fin n} : rev i ≤ rev j ↔ j ≤ i := by\n  simp only [le_iff_val_le_val, val_rev, tsub_le_tsub_iff_left (Nat.add_one_le_iff.2 j.is_lt),\n    add_le_add_iff_right, iff_self]\n#align fin.rev_le_rev Fin.rev_le_rev\n\n@[simp]\ntheorem rev_lt_rev {i j : Fin n} : rev i < rev j ↔ j < i :=\n  lt_iff_lt_of_le_iff_le rev_le_rev\n#align fin.rev_lt_rev Fin.rev_lt_rev\n\n/-- `Fin.rev n` as an order-reversing isomorphism. -/\n@[simps! apply toEquiv]\ndef revOrderIso {n} : (Fin n)ᵒᵈ ≃o Fin n :=\n  ⟨OrderDual.ofDual.trans rev, rev_le_rev⟩\n#align fin.rev_order_iso Fin.revOrderIso\n#align fin.rev_order_iso_apply Fin.revOrderIso_apply\n#align fin.rev_order_iso_to_equiv Fin.revOrderIso_toEquiv\n\n@[simp]\ntheorem revOrderIso_symm_apply (i : Fin n) : revOrderIso.symm i = OrderDual.toDual (rev i) :=\n  rfl\n#align fin.rev_order_iso_symm_apply Fin.revOrderIso_symm_apply\n\n/-- The greatest value of `Fin (n+1)` -/\ndef last (n : ℕ) : Fin (n + 1) :=\n  ⟨n, n.lt_succ_self⟩\n#align fin.last Fin.last\n\n@[simp, norm_cast]\ntheorem val_last (n : ℕ) : (last n : ℕ) = n :=\n  rfl\n#align fin.coe_last Fin.val_last\n\n-- porting note: this is now syntactically equal to `val_last`\n#align fin.last_val Fin.val_last\n\ntheorem le_last (i : Fin (n + 1)) : i ≤ last n :=\n  le_of_lt_succ i.is_lt\n#align fin.le_last Fin.le_last\n\ninstance : BoundedOrder (Fin (n + 1)) where\n  top := last n\n  le_top := le_last\n  bot := 0\n  bot_le := zero_le\n\ninstance : Lattice (Fin (n + 1)) :=\n  LinearOrder.toLattice\n\ntheorem last_pos : (0 : Fin (n + 2)) < last (n + 1) := by simp [lt_iff_val_lt_val]\n#align fin.last_pos Fin.last_pos\n\ntheorem eq_last_of_not_lt {i : Fin (n + 1)} (h : ¬(i : ℕ) < n) : i = last n :=\n  le_antisymm (le_last i) (not_lt.1 h)\n#align fin.eq_last_of_not_lt Fin.eq_last_of_not_lt\n\ntheorem val_lt_last {i : Fin (n + 1)} (h : i ≠ last n) : (i : ℕ) < n :=\n  by_contra <| mt eq_last_of_not_lt h\n\ntheorem top_eq_last (n : ℕ) : ⊤ = Fin.last n :=\n  rfl\n#align fin.top_eq_last Fin.top_eq_last\n\ntheorem bot_eq_zero (n : ℕ) : ⊥ = (0 : Fin (n + 1)) :=\n  rfl\n#align fin.bot_eq_zero Fin.bot_eq_zero\n\nsection\n\nvariable {α : Type _} [Preorder α]\n\nopen Set\n\n/-- If `e` is an `orderIso` 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 : ℕ) = (i : ℕ)`. -/\n@[simp]\ntheorem coe_orderIso_apply (e : Fin n ≃o Fin m) (i : Fin n) : (e i : ℕ) = i := by\n  rcases i with ⟨i, hi⟩\n  dsimp only\n  induction' i using Nat.strong_induction_on with i h\n  refine' le_antisymm (forall_lt_iff_le.1 fun j hj => _) (forall_lt_iff_le.1 fun j hj => _)\n  · have := e.symm.lt_iff_lt.2 (mk_lt_of_lt_val hj)\n    rw [e.symm_apply_apply] at this\n    -- porting note: convert was abusing definitional equality\n    have : _ < i := this\n    convert this\n    simpa using h _ this (e.symm _).is_lt\n  · rwa [← h j hj (hj.trans hi), ← lt_iff_val_lt_val, e.lt_iff_lt]\n#align fin.coe_order_iso_apply Fin.coe_orderIso_apply\n\ninstance orderIso_subsingleton : Subsingleton (Fin n ≃o α) :=\n  ⟨fun e e' => by\n    ext i\n    rw [← e.symm.apply_eq_iff_eq, e.symm_apply_apply, ← e'.trans_apply, ext_iff,\n      coe_orderIso_apply]⟩\n#align fin.order_iso_subsingleton Fin.orderIso_subsingleton\n\ninstance orderIso_subsingleton' : Subsingleton (α ≃o Fin n) :=\n  OrderIso.symm_injective.subsingleton\n#align fin.order_iso_subsingleton' Fin.orderIso_subsingleton'\n\ninstance orderIsoUnique : Unique (Fin n ≃o Fin n) :=\n  Unique.mk' _\n#align fin.order_iso_unique Fin.orderIsoUnique\n\n/-- Two strictly monotone functions from `Fin n` are equal provided that their ranges\nare equal. -/\ntheorem strictMono_unique {f g : Fin n → α} (hf : StrictMono f) (hg : StrictMono g)\n    (h : range f = range g) : f = g :=\n  have : (hf.orderIso f).trans (OrderIso.setCongr _ _ h) = hg.orderIso g := Subsingleton.elim _ _\n  congr_arg (Function.comp (Subtype.val : range g → α)) (funext <| RelIso.ext_iff.1 this)\n#align fin.strict_mono_unique Fin.strictMono_unique\n\n/-- Two order embeddings of `Fin n` are equal provided that their ranges are equal. -/\ntheorem orderEmbedding_eq {f g : Fin n ↪o α} (h : range f = range g) : f = g :=\n  RelEmbedding.ext <| funext_iff.1 <| strictMono_unique f.strictMono g.strictMono h\n#align fin.order_embedding_eq Fin.orderEmbedding_eq\n\nend\n\nend Order\n\nsection Add\n\n/-!\n### addition, numerals, and coercion from Nat\n-/\n\n\n@[simp] -- Porting note: simp can prove this\n\n\n@[simp]\ntheorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n :=\n  rfl\n#align fin.coe_one' Fin.val_one'\n\n--Porting note: Delete this lemma after porting\ntheorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) :=\n  rfl\n#align fin.one_val Fin.val_one''\n\n@[simp]\ntheorem mk_one : (⟨1, Nat.succ_lt_succ (Nat.succ_pos n)⟩ : Fin (n + 2)) = (1 : Fin _) :=\n  rfl\n#align fin.mk_one Fin.mk_one\n\ninstance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where\n  exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp only [val_one, val_zero])⟩\n\ntheorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by\n  rcases n with (_ | _ | n) <;>\n  simp [←Nat.one_eq_succ_zero, Fin.nontrivial, not_nontrivial, Nat.succ_le_iff]\n-- porting note: here and in the next lemma, had to use `←Nat.one_eq_succ_zero`.\n#align fin.nontrivial_iff_two_le Fin.nontrivial_iff_two_le\n\ntheorem subsingleton_iff_le_one : Subsingleton (Fin n) ↔ n ≤ 1 := by\n  rcases n with (_ | _ | n) <;>\n  simp [IsEmpty.instSubsingleton, Unique.instSubsingleton, ←Nat.one_eq_succ_zero, not_subsingleton]\n#align fin.subsingleton_iff_le_one Fin.subsingleton_iff_le_one\n\nsection Monoid\n\n--Porting note: removing `simp`, `simp` can prove it with AddCommMonoid instance\nprotected theorem add_zero [NeZero n] (k : Fin n) : k + 0 = k := by\n  simp [eq_iff_veq, add_def, mod_eq_of_lt (is_lt k)]\n#align fin.add_zero Fin.add_zero\n\n--Porting note: removing `simp`, `simp` can prove it with AddCommMonoid instance\nprotected theorem zero_add [NeZero n] (k : Fin n) : 0 + k = k := by\n  simp [eq_iff_veq, add_def, mod_eq_of_lt (is_lt k)]\n#align fin.zero_add Fin.zero_add\n\ninstance [NeZero n] : OfNat (Fin n) a where\n  ofNat := Fin.ofNat' a (NeZero.pos n)\n\nsection from_ad_hoc\n\n@[simp] lemma ofNat'_zero [NeZero n] : (Fin.ofNat' 0 h : Fin n) = 0 := rfl\n@[simp] lemma ofNat'_one [NeZero n] : (Fin.ofNat' 1 h : Fin n) = 1 := rfl\n\nend from_ad_hoc\n\ninstance (n) : AddCommSemigroup (Fin n) where\n  add_assoc := by simp [eq_iff_veq, add_def, add_assoc]\n  add_comm := by simp [eq_iff_veq, add_def, add_comm]\n\ninstance addCommMonoid (n : ℕ) [NeZero n] : AddCommMonoid (Fin n)\n    where\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#align fin.add_comm_monoid Fin.addCommMonoid\n\ninstance (n) [NeZero n] : AddMonoidWithOne (Fin n) where\n  __ := inferInstanceAs (AddCommMonoid (Fin n))\n  natCast n := Fin.ofNat'' n\n  natCast_zero := rfl\n  natCast_succ _ := eq_of_veq (add_mod _ _ _)\n\nend Monoid\n\ntheorem val_add {n : ℕ} : ∀ a b : Fin n, (a + b).val = (a.val + b.val) % n\n  | ⟨_, _⟩, ⟨_, _⟩ => rfl\n#align fin.val_add Fin.val_add\n#align fin.coe_add Fin.val_add\n\ntheorem val_add_eq_ite {n : ℕ} (a b : Fin n) :\n    (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by\n  rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2),\n    Nat.mod_eq_of_lt (show ↑b < n from b.2)]\n#align fin.coe_add_eq_ite Fin.val_add_eq_ite\n\nsection deprecated\nset_option linter.deprecated false\n\n@[deprecated]\ntheorem val_bit0 {n : ℕ} (k : Fin n) : ((bit0 k : Fin n) : ℕ) = bit0 (k : ℕ) % n := by\n  cases k\n  rfl\n#align fin.coe_bit0 Fin.val_bit0\n\n@[deprecated]\ntheorem val_bit1 {n : ℕ} [NeZero n] (k : Fin n) :\n    ((bit1 k : Fin n) : ℕ) = bit1 (k : ℕ) % n := by\n  cases n;\n  · cases' k with k h\n    cases k\n    · show _ % _ = _\n      simp\n    cases' h with _ h\n  simp [bit1, Fin.val_bit0, Fin.val_add, Fin.val_one]\n#align fin.coe_bit1 Fin.val_bit1\n\nend deprecated\n\ntheorem val_add_one_of_lt {n : ℕ} {i : Fin n.succ} (h : i < last _) : (↑(i + 1) : ℕ) = i + 1 := by\n  -- First show that `((1 : Fin n.succ) : ℕ) = 1`, because `n.succ` is at least 2.\n  cases n\n  · cases h\n  -- Then just unfold the definitions.\n  rw [Fin.val_add, Fin.val_one, Nat.mod_eq_of_lt (Nat.succ_lt_succ _)]\n  exact h\n#align fin.coe_add_one_of_lt Fin.val_add_one_of_lt\n\n@[simp]\ntheorem last_add_one : ∀ n, last n + 1 = 0\n  | 0 => by simp only\n  | n + 1 => by\n    ext\n    rw [val_add, val_zero, val_last, val_one, Nat.mod_self]\n#align fin.last_add_one Fin.last_add_one\n\ntheorem val_add_one {n : ℕ} (i : Fin (n + 1)) :\n    ((i + 1 : Fin (n + 1)) : ℕ) = if i = last _ then (0 : ℕ) else i + 1 := by\n  rcases(le_last i).eq_or_lt with (rfl | h)\n  · simp\n  · simpa [h.ne] using val_add_one_of_lt h\n#align fin.coe_add_one Fin.val_add_one\n\nsection Bit\nset_option linter.deprecated false\n\n@[simp, deprecated]\ntheorem mk_bit0 {m n : ℕ} (h : bit0 m < n) :\n    (⟨bit0 m, h⟩ : Fin n) = (bit0 ⟨m, (Nat.le_add_right m m).trans_lt h⟩ : Fin _) :=\n  eq_of_veq (Nat.mod_eq_of_lt h).symm\n#align fin.mk_bit0 Fin.mk_bit0\n\n@[simp, deprecated]\ntheorem mk_bit1 {m n : ℕ} [NeZero n] (h : bit1 m < n) :\n    (⟨bit1 m, h⟩ : Fin n) =\n      (bit1 ⟨m, (Nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ : Fin _) := by\n  ext\n  simp only [bit1, bit0] at h\n  simp only [bit1, bit0, val_add, val_one', ← Nat.add_mod, Nat.mod_eq_of_lt h]\n#align fin.mk_bit1 Fin.mk_bit1\n\nend Bit\n\n@[simp]\ntheorem val_two {n : ℕ} : (2 : Fin (n + 3)).val = 2 :=\n  rfl\n#align fin.val_two Fin.val_two\n\n--- porting note: syntactically the same as the above\n#align fin.coe_two Fin.val_two\n\nsection OfNatCoe\n\n@[simp]\ntheorem ofNat_eq_val (n : ℕ) [NeZero n] (a : ℕ) : (Fin.ofNat'' a : Fin n) = a :=\n  rfl\n#align fin.of_nat_eq_coe Fin.ofNat_eq_val\n\n-- porting note: is this the right name for things involving `Nat.cast`?\n/-- Converting an in-range number to `Fin (n + 1)` produces a result\nwhose value is the original number.  -/\ntheorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := by\n  rw [← ofNat_eq_val]\n  exact Nat.mod_eq_of_lt h\n#align fin.coe_val_of_lt Fin.val_cast_of_lt\n\n/-- Converting the value of a `Fin (n + 1)` to `Fin (n + 1)` results\nin the same value.  -/\ntheorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := by\n  rw [Fin.eq_iff_veq]\n  exact val_cast_of_lt a.isLt\n#align fin.coe_val_eq_self Fin.cast_val_eq_self\n\n-- porting note: this is syntactically the same as `val_cast_of_lt`\n#align fin.coe_coe_of_lt Fin.val_cast_of_lt\n\n-- porting note: this is syntactically the same as `cast_val_of_lt`\n#align fin.coe_coe_eq_self Fin.cast_val_eq_self\n\ntheorem cast_nat_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by\n  rw [← Fin.ofNat_eq_val, Fin.ofNat'', Fin.last]\n  simp only [Nat.mod_eq_of_lt n.lt_succ_self]\n#align fin.coe_nat_eq_last Fin.cast_nat_eq_last\n\ntheorem le_val_last (i : Fin (n + 1)) : i ≤ n := by\n  rw [Fin.cast_nat_eq_last]\n  exact Fin.le_last i\n#align fin.le_coe_last Fin.le_val_last\n\nend OfNatCoe\n\ntheorem add_one_pos (i : Fin (n + 1)) (h : i < Fin.last n) : (0 : Fin (n + 1)) < i + 1 := by\n  cases n\n  · exact absurd h (Nat.not_lt_zero _)\n  · rw [lt_iff_val_lt_val, val_last, ← add_lt_add_iff_right 1] at h\n    rw [lt_iff_val_lt_val, val_add, val_zero, val_one, Nat.mod_eq_of_lt h]\n    exact Nat.zero_lt_succ _\n#align fin.add_one_pos Fin.add_one_pos\n\ntheorem one_pos : (0 : Fin (n + 2)) < 1 :=\n  succ_pos 0\n#align fin.one_pos Fin.one_pos\n\ntheorem zero_ne_one : (0 : Fin (n + 2)) ≠ 1 :=\n  ne_of_lt one_pos\n#align fin.zero_ne_one Fin.zero_ne_one\n\n@[simp]\ntheorem zero_eq_one_iff [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by\n  constructor\n  · intro h\n    have := congr_arg ((↑) : Fin n → ℕ) h\n    simp only [val_zero, val_one', @eq_comm _ 0, ← Nat.dvd_iff_mod_eq_zero] at this\n    exact eq_one_of_dvd_one this\n  · rintro rfl\n    rfl\n#align fin.zero_eq_one_iff Fin.zero_eq_one_iff\n\n@[simp]\ntheorem one_eq_zero_iff [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by rw [eq_comm, zero_eq_one_iff]\n#align fin.one_eq_zero_iff Fin.one_eq_zero_iff\n\nend Add\n\nsection Succ\n\n/-!\n### succ and casts into larger Fin types\n-/\n\n@[simp]\ntheorem val_succ (j : Fin n) : (j.succ : ℕ) = j + 1 := by cases j; simp [Fin.succ]\n#align fin.coe_succ Fin.val_succ\n\n@[simp]\ntheorem succ_pos (a : Fin n) : (0 : Fin (n + 1)) < a.succ := by simp [lt_iff_val_lt_val]\n#align fin.succ_pos Fin.succ_pos\n\n/-- `Fin.succ` as an `OrderEmbedding` -/\ndef succEmbedding (n : ℕ) : Fin n ↪o Fin (n + 1) :=\n  (OrderEmbedding.ofStrictMono Fin.succ) fun _ _ h => succ_lt_succ h\n#align fin.succ_embedding Fin.succEmbedding\n\n@[simp]\ntheorem val_succEmbedding : ⇑(succEmbedding n) = Fin.succ :=\n  rfl\n#align fin.coe_succ_embedding Fin.val_succEmbedding\n\n@[simp]\ntheorem succ_le_succ_iff {a b : Fin n} : a.succ ≤ b.succ ↔ a ≤ b :=\n  (succEmbedding n).le_iff_le\n#align fin.succ_le_succ_iff Fin.succ_le_succ_iff\n\n@[simp]\ntheorem succ_lt_succ_iff {a b : Fin n} : a.succ < b.succ ↔ a < b :=\n  (succEmbedding n).lt_iff_lt\n#align fin.succ_lt_succ_iff Fin.succ_lt_succ_iff\n\ntheorem succ_injective (n : ℕ) : Injective (@Fin.succ n) :=\n  (succEmbedding n).injective\n#align fin.succ_injective Fin.succ_injective\n\n@[simp]\ntheorem succ_inj {a b : Fin n} : a.succ = b.succ ↔ a = b :=\n  (succ_injective n).eq_iff\n#align fin.succ_inj Fin.succ_inj\n\ntheorem succ_ne_zero {n} : ∀ k : Fin n, Fin.succ k ≠ 0\n  | ⟨k, _⟩, heq => Nat.succ_ne_zero k <| ext_iff.1 heq\n#align fin.succ_ne_zero Fin.succ_ne_zero\n\n@[simp]\ntheorem succ_zero_eq_one [NeZero n] : Fin.succ (0 : Fin n) = 1 := by\n  cases n\n  · exact (NeZero.ne 0 rfl).elim\n  · rfl\n#align fin.succ_zero_eq_one Fin.succ_zero_eq_one\n\n/-- Version of `succ_zero_eq_one` to be used by `dsimp` -/\n@[simp, nolint simpNF]\ntheorem succ_zero_eq_one' : Fin.succ (0 : Fin (n+1)) = 1 :=\n  rfl\n#align fin.succ_zero_eq_one' Fin.succ_zero_eq_one'\n\n@[simp]\ntheorem succ_one_eq_two [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by\n  cases n\n  · exact (NeZero.ne 0 rfl).elim\n  · rfl\n#align fin.succ_one_eq_two Fin.succ_one_eq_two\n\n/-- Version of `succ_one_eq_two` to be used by `dsimp` -/\n@[simp, nolint simpNF]\ntheorem succ_one_eq_two' : Fin.succ (1 : Fin (n + 2)) = 2 :=\n  rfl\n#align fin.succ_one_eq_two' Fin.succ_one_eq_two'\n\n@[simp]\ntheorem succ_mk (n i : ℕ) (h : i < n) : Fin.succ ⟨i, h⟩ = ⟨i + 1, Nat.succ_lt_succ h⟩ :=\n  rfl\n#align fin.succ_mk Fin.succ_mk\n\ntheorem mk_succ_pos (i : ℕ) (h : i < n) : (0 : Fin (n + 1)) < ⟨i.succ, add_lt_add_right h 1⟩ := by\n  rw [lt_iff_val_lt_val, val_zero]\n  exact Nat.succ_pos i\n#align fin.mk_succ_pos Fin.mk_succ_pos\n\ntheorem one_lt_succ_succ (a : Fin n) : (1 : Fin (n + 2)) < a.succ.succ := by\n  cases n\n  · exact Fin.elim0 a\n  · rw [← succ_zero_eq_one, succ_lt_succ_iff]\n    exact succ_pos a\n#align fin.one_lt_succ_succ Fin.one_lt_succ_succ\n\n@[simp]\ntheorem add_one_lt_iff {n : ℕ} {k : Fin (n + 2)} : k + 1 < k ↔ k = last _ := by\n  simp only [lt_iff_val_lt_val, val_add, val_last, ext_iff]\n  cases' k with k hk\n  rcases(le_of_lt_succ hk).eq_or_lt with (rfl | hk')\n  · simp\n  · simp [hk'.ne, mod_eq_of_lt (succ_lt_succ hk'), le_succ _]\n#align fin.add_one_lt_iff Fin.add_one_lt_iff\n\n@[simp]\ntheorem add_one_le_iff {n : ℕ} {k : Fin (n + 1)} : k + 1 ≤ k ↔ k = last _ := by\n  cases n\n  -- Porting note: added `haveI`\n  · haveI : Subsingleton (Fin (0 + 1)) := by\n      convert_to Subsingleton (Fin 1)\n      infer_instance\n    simp [Subsingleton.elim (k + 1) k, Subsingleton.elim (Fin.last _) k]\n  rw [← not_iff_not, ← add_one_lt_iff, lt_iff_le_and_ne, not_and']\n  refine' ⟨fun h _ => h, fun h => h _⟩\n  rw [Ne.def, ext_iff, val_add_one]\n  split_ifs with hk <;> simp [hk, @eq_comm ℕ 0]\n#align fin.add_one_le_iff Fin.add_one_le_iff\n\n@[simp]\ntheorem last_le_iff {n : ℕ} {k : Fin (n + 1)} : last n ≤ k ↔ k = last n :=\n  top_le_iff\n#align fin.last_le_iff Fin.last_le_iff\n\n@[simp]\ntheorem lt_add_one_iff {n : ℕ} {k : Fin (n + 1)} : k < k + 1 ↔ k < last n := by\n  rw [← not_iff_not]\n  simp\n#align fin.lt_add_one_iff Fin.lt_add_one_iff\n\n@[simp]\ntheorem le_zero_iff {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 :=\n  ⟨fun h => Fin.eq_of_veq $ by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact le_refl _⟩\n#align fin.le_zero_iff Fin.le_zero_iff\n\ntheorem succ_succ_ne_one (a : Fin n) : Fin.succ (Fin.succ a) ≠ 1 :=\n  ne_of_gt (one_lt_succ_succ a)\n#align fin.succ_succ_ne_one Fin.succ_succ_ne_one\n\n/-- `castLt i h` embeds `i` into a `Fin` where `h` proves it belongs into.  -/\ndef castLt (i : Fin m) (h : i.1 < n) : Fin n :=\n  ⟨i.1, h⟩\n#align fin.cast_lt Fin.castLt\n\n@[simp]\ntheorem coe_castLt (i : Fin m) (h : i.1 < n) : (castLt i h : ℕ) = i :=\n  rfl\n#align fin.coe_cast_lt Fin.coe_castLt\n\n@[simp]\ntheorem castLt_mk (i n m : ℕ) (hn : i < n) (hm : i < m) : castLt ⟨i, hn⟩ hm = ⟨i, hm⟩ :=\n  rfl\n#align fin.cast_lt_mk Fin.castLt_mk\n\n/-- `castLe h i` embeds `i` into a larger `Fin` type.  -/\ndef castLe (h : n ≤ m) : Fin n ↪o Fin m :=\n  (OrderEmbedding.ofStrictMono fun a => castLt a (lt_of_lt_of_le a.2 h)) fun _ _ h => h\n#align fin.cast_le Fin.castLe\n\n@[simp]\ntheorem coe_castLe (h : n ≤ m) (i : Fin n) : (castLe h i : ℕ) = i :=\n  rfl\n#align fin.coe_cast_le Fin.coe_castLe\n\n@[simp]\ntheorem castLe_mk (i n m : ℕ) (hn : i < n) (h : n ≤ m) :\n    castLe h ⟨i, hn⟩ = ⟨i, lt_of_lt_of_le hn h⟩ :=\n  rfl\n#align fin.cast_le_mk Fin.castLe_mk\n\n@[simp]\ntheorem castLe_zero {n m : ℕ} (h : n.succ ≤ m.succ) : castLe h 0 = 0 := by simp [eq_iff_veq]\n#align fin.cast_le_zero Fin.castLe_zero\n\n@[simp]\ntheorem range_castLe {n k : ℕ} (h : n ≤ k) : Set.range (castLe h) = { i : Fin k | (i : ℕ) < n } :=\n  Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, Fin.ext rfl⟩⟩\n#align fin.range_cast_le Fin.range_castLe\n\n@[simp]\ntheorem coe_of_injective_castLe_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) :\n    ((Equiv.ofInjective _ (castLe h).injective).symm ⟨i, hi⟩ : ℕ) = i := by\n  rw [← coe_castLe]\n  exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _)\n#align fin.coe_of_injective_cast_le_symm Fin.coe_of_injective_castLe_symm\n\n@[simp]\ntheorem castLe_succ {m n : ℕ} (h : m + 1 ≤ n + 1) (i : Fin m) :\n    castLe h i.succ = (castLe (Nat.succ_le_succ_iff.mp h) i).succ := by simp [Fin.eq_iff_veq]\n#align fin.cast_le_succ Fin.castLe_succ\n\n@[simp]\ntheorem castLe_castLe {k m n} (km : k ≤ m) (mn : m ≤ n) (i : Fin k) :\n    Fin.castLe mn (Fin.castLe km i) = Fin.castLe (km.trans mn) i :=\n  Fin.ext (by simp only [coe_castLe])\n#align fin.cast_le_cast_le Fin.castLe_castLe\n\n@[simp]\ntheorem castLe_comp_castLe {k m n} (km : k ≤ m) (mn : m ≤ n) :\n    Fin.castLe mn ∘ Fin.castLe km = Fin.castLe (km.trans mn) :=\n  funext (castLe_castLe km mn)\n#align fin.cast_le_comp_cast_le Fin.castLe_comp_castLe\n\n/-- `cast eq i` embeds `i` into a equal `Fin` type, see also `Equiv.finCongr`. -/\ndef cast (eq : n = m) : Fin n ≃o Fin m where\n  toEquiv := ⟨castLe eq.le, castLe eq.symm.le, fun _ => eq_of_veq rfl, fun _ => eq_of_veq rfl⟩\n  map_rel_iff' := Iff.rfl\n#align fin.cast Fin.cast\n\n@[simp]\ntheorem symm_cast (h : n = m) : (cast h).symm = cast h.symm := by simp\n#align fin.symm_cast Fin.symm_cast\n\ntheorem coe_cast (h : n = m) (i : Fin n) : (cast h i : ℕ) = i := by simp\n#align fin.coe_cast Fin.coe_cast\n\n@[simp]\ntheorem cast_zero {n' : ℕ} [NeZero n] {h : n = n'} : cast h (0 : Fin n) =\n    by { haveI : NeZero n' := by {rw [← h]; infer_instance}; exact 0} :=\n  ext rfl\n#align fin.cast_zero Fin.cast_zero\n\n@[simp]\ntheorem cast_last {n' : ℕ} {h : n + 1 = n' + 1} : cast h (last n) = last n' :=\n  ext (by rw [coe_cast, val_last, val_last, Nat.succ_injective h])\n#align fin.cast_last Fin.cast_last\n\n@[simp]\ntheorem cast_mk (h : n = m) (i : ℕ) (hn : i < n) :\n    cast h ⟨i, hn⟩ = ⟨i, lt_of_lt_of_le hn h.le⟩ := by\n  ext\n  simp\n#align fin.cast_mk Fin.cast_mk\n\n@[simp]\ntheorem cast_trans {k : ℕ} (h : n = m) (h' : m = k) {i : Fin n} :\n    cast h' (cast h i) = cast (Eq.trans h h') i := by\n  ext\n  simp\n#align fin.cast_trans Fin.cast_trans\n\n@[simp]\ntheorem cast_refl (h : n = n := rfl) : cast h = OrderIso.refl (Fin n) := by\n  ext\n  simp\n#align fin.cast_refl Fin.cast_refl\n\ntheorem castLe_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} :\n    (castLe h' : Fin m → Fin n) = Fin.cast h :=\n  funext fun _ => by ext; simp\n#align fin.cast_le_of_eq Fin.castLe_of_eq\n\n/-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply\na generic theorem about `cast`. -/\ntheorem cast_to_equiv (h : n = m) : (cast h).toEquiv = Equiv.cast (h ▸ rfl) := by\n  subst h\n  simp\n#align fin.cast_to_equiv Fin.cast_to_equiv\n\n/-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply\na generic theorem about `cast`. -/\ntheorem cast_eq_cast (h : n = m) : (cast h : Fin n → Fin m) = cast (h ▸ rfl) := by\n  subst h\n  ext\n  simp\n#align fin.cast_eq_cast Fin.cast_eq_cast\n\n/-- `castAdd m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAdd` and `Fin.addNat`. -/\ndef castAdd (m) : Fin n ↪o Fin (n + m) :=\n  castLe <| Nat.le_add_right n m\n#align fin.cast_add Fin.castAdd\n\n@[simp]\ntheorem coe_castAdd (m : ℕ) (i : Fin n) : (castAdd m i : ℕ) = i :=\n  rfl\n#align fin.coe_cast_add Fin.coe_castAdd\n\n@[simp]\ntheorem castAdd_zero : (castAdd 0 : Fin n → Fin (n + 0)) = cast rfl := by\n  ext\n  simp only [Nat.add_zero, cast_refl, OrderIso.refl_apply]\n  rfl\n#align fin.cast_add_zero Fin.castAdd_zero\n\ntheorem castAdd_lt {m : ℕ} (n : ℕ) (i : Fin m) : (castAdd n i : ℕ) < m := by\n  simp\n#align fin.cast_add_lt Fin.castAdd_lt\n\n@[simp]\ntheorem castAdd_mk (m : ℕ) (i : ℕ) (h : i < n) : castAdd m ⟨i, h⟩ = ⟨i, Nat.lt_add_right i n m h⟩ :=\n  rfl\n#align fin.cast_add_mk Fin.castAdd_mk\n\n@[simp]\ntheorem castAdd_castLt (m : ℕ) (i : Fin (n + m)) (hi : i.val < n) :\n    castAdd m (castLt i hi) = i := by\n  ext\n  simp\n#align fin.cast_add_cast_lt Fin.castAdd_castLt\n\n@[simp]\ntheorem castLt_castAdd (m : ℕ) (i : Fin n) : castLt (castAdd m i) (castAdd_lt m i) = i := by\n  ext\n  simp\n#align fin.cast_lt_cast_add Fin.castLt_castAdd\n\n/-- For rewriting in the reverse direction, see `Fin.cast_castAdd_left`. -/\ntheorem castAdd_cast {n n' : ℕ} (m : ℕ) (i : Fin n') (h : n' = n) :\n    castAdd m (Fin.cast h i) = Fin.cast (congr_arg (. + m) h) (castAdd m i) :=\n  ext rfl\n#align fin.cast_add_cast Fin.castAdd_cast\n\ntheorem cast_castAdd_left {n n' m : ℕ} (i : Fin n') (h : n' + m = n + m) :\n    cast h (castAdd m i) = castAdd m (cast (add_right_cancel h) i) := by\n  ext\n  simp\n#align fin.cast_cast_add_left Fin.cast_castAdd_left\n\n@[simp]\ntheorem cast_castAdd_right {n m m' : ℕ} (i : Fin n) (h : n + m' = n + m) :\n    cast h (castAdd m' i) = castAdd m i := by\n  ext\n  simp\n#align fin.cast_cast_add_right Fin.cast_castAdd_right\n\ntheorem castAdd_castAdd {m n p : ℕ} (i : Fin m) :\n    castAdd p (castAdd n i) = cast (add_assoc _ _ _).symm (castAdd (n + p) i) := by\n  ext\n  simp\n#align fin.cast_add_cast_add Fin.castAdd_castAdd\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]\ntheorem cast_succ_eq {n' : ℕ} (i : Fin n) (h : n.succ = n'.succ) :\n    cast h i.succ = (cast (Nat.succ.inj h) i).succ :=\n  ext <| by simp\n#align fin.cast_succ_eq Fin.cast_succ_eq\n\ntheorem succ_cast_eq {n' : ℕ} (i : Fin n) (h : n = n') :\n    (cast h i).succ = cast (by rw [h]) i.succ :=\n  ext <| by simp\n#align fin.succ_cast_eq Fin.succ_cast_eq\n\n/-- `castSucc i` embeds `i : Fin n` in `Fin (n+1)`. -/\ndef castSucc : Fin n ↪o Fin (n + 1) :=\n  castAdd 1\n#align fin.cast_succ Fin.castSucc\n\n@[simp]\ntheorem coe_castSucc (i : Fin n) : (Fin.castSucc i : ℕ) = i :=\n  rfl\n#align fin.coe_cast_succ Fin.coe_castSucc\n\n@[simp]\ntheorem castSucc_mk (n i : ℕ) (h : i < n) : castSucc ⟨i, h⟩ = ⟨i, Nat.lt.step h⟩ :=\n  rfl\n#align fin.cast_succ_mk Fin.castSucc_mk\n\n@[simp]\ntheorem cast_castSucc {n' : ℕ} {h : n + 1 = n' + 1} {i : Fin n} :\n    cast h (castSucc i) = castSucc (cast (Nat.succ_injective h) i) := by\n  ext\n  simp only [coe_cast, coe_castSucc]\n#align fin.cast_cast_succ Fin.cast_castSucc\n\ntheorem castSucc_lt_succ (i : Fin n) : Fin.castSucc i < i.succ :=\n  lt_iff_val_lt_val.2 <| by simp only [coe_castSucc, val_succ, Nat.lt_succ_self]\n#align fin.cast_succ_lt_succ Fin.castSucc_lt_succ\n\ntheorem le_castSucc_iff {i : Fin (n + 1)} {j : Fin n} : i ≤ Fin.castSucc j ↔ i < j.succ := by\n  simpa [lt_iff_val_lt_val, le_iff_val_le_val] using Nat.succ_le_succ_iff.symm\n#align fin.le_cast_succ_iff Fin.le_castSucc_iff\n\ntheorem castSucc_lt_iff_succ_le {n : ℕ} {i : Fin n} {j : Fin (n + 1)} :\n    Fin.castSucc i < j ↔ i.succ ≤ j := by\n  simpa only [lt_iff_val_lt_val, le_iff_val_le_val, val_succ, Fin.coe_castSucc] using\n    Nat.lt_iff_add_one_le\n#align fin.cast_succ_lt_iff_succ_le Fin.castSucc_lt_iff_succ_le\n\n@[simp]\ntheorem succ_last (n : ℕ) : (last n).succ = last n.succ :=\n  rfl\n#align fin.succ_last Fin.succ_last\n\n@[simp]\ntheorem succ_eq_last_succ {n : ℕ} (i : Fin n.succ) : i.succ = last (n + 1) ↔ i = last n := by\n  rw [← succ_last, (succ_injective _).eq_iff]\n#align fin.succ_eq_last_succ Fin.succ_eq_last_succ\n\n@[simp]\ntheorem castSucc_cast_lt (i : Fin (n + 1)) (h : (i : ℕ) < n) : castSucc (castLt i h) = i :=\n  Fin.eq_of_veq rfl\n#align fin.cast_succ_cast_lt Fin.castSucc_cast_lt\n\n@[simp]\ntheorem cast_lt_castSucc {n : ℕ} (a : Fin n) (h : (a : ℕ) < n) : castLt (castSucc a) h = a := by\n  cases a; rfl\n#align fin.cast_lt_cast_succ Fin.cast_lt_castSucc\n\n@[simp]\ntheorem castSucc_lt_castSucc_iff {a b : Fin n}: Fin.castSucc a < Fin.castSucc b ↔ a < b :=\n  (@castSucc n).lt_iff_lt\n#align fin.cast_succ_lt_cast_succ_iff Fin.castSucc_lt_castSucc_iff\n\ntheorem castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) :=\n  (castSucc : Fin n ↪o _).injective\n#align fin.cast_succ_injective Fin.castSucc_injective\n\ntheorem castSucc_inj {a b : Fin n} : castSucc a = castSucc b ↔ a = b :=\n  (castSucc_injective n).eq_iff\n#align fin.cast_succ_inj Fin.castSucc_inj\n\ntheorem castSucc_lt_last (a : Fin n) : castSucc a < last n :=\n  lt_iff_val_lt_val.mpr a.is_lt\n#align fin.cast_succ_lt_last Fin.castSucc_lt_last\n\n@[simp]\ntheorem castSucc_zero [NeZero n] : castSucc (0 : Fin n) = 0 :=\n  ext rfl\n#align fin.cast_succ_zero Fin.castSucc_zero\n\n@[simp]\ntheorem castSucc_one {n : ℕ} : castSucc (1 : Fin (n + 2)) = 1 :=\n  rfl\n#align fin.cast_succ_one Fin.castSucc_one\n\n/-- `castSucc i` is positive when `i` is positive -/\ntheorem castSucc_pos [NeZero n] {i : Fin n} (h : 0 < i) : 0 < castSucc i := by\n  simpa [lt_iff_val_lt_val] using h\n#align fin.cast_succ_pos Fin.castSucc_pos\n\n@[simp]\ntheorem castSucc_eq_zero_iff [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 :=\n  Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm\n#align fin.cast_succ_eq_zero_iff Fin.castSucc_eq_zero_iff\n\ntheorem castSucc_ne_zero_iff [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 :=\n  not_iff_not.mpr <| castSucc_eq_zero_iff a\n#align fin.cast_succ_ne_zero_iff Fin.castSucc_ne_zero_iff\n\ntheorem castSucc_fin_succ (n : ℕ) (j : Fin n) : castSucc (Fin.succ j) = Fin.succ (castSucc j) := by\n  simp [Fin.ext_iff]\n#align fin.cast_succ_fin_succ Fin.castSucc_fin_succ\n\n@[norm_cast, simp]\ntheorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by\n  ext\n  exact val_cast_of_lt (Nat.lt.step a.is_lt)\n#align fin.coe_eq_cast_succ Fin.coe_eq_castSucc\n\n@[simp]\ntheorem coeSucc_eq_succ {a : Fin n} : (castSucc a) + 1 = a.succ := by\n  cases n\n  · exact @finZeroElim (fun _ => _) a\n  · simp [a.is_lt, eq_iff_veq, add_def, Nat.mod_eq_of_lt]\n#align fin.coe_succ_eq_succ Fin.coeSucc_eq_succ\n\ntheorem lt_succ {a : Fin n} : castSucc a < a.succ := by\n  rw [castSucc, lt_iff_val_lt_val, coe_castAdd, val_succ]\n  exact lt_add_one a.val\n#align fin.lt_succ Fin.lt_succ\n\n@[simp]\ntheorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) =\n    ({ i | (i : ℕ) < n } : Set (Fin n.succ)) :=\n  range_castLe le_self_add\n#align fin.range_cast_succ Fin.range_castSucc\n\ntheorem exists_castSucc_eq {n : ℕ} {i : Fin (n + 1)} : (∃ j, castSucc j = i) ↔ i ≠ last n :=\n  ⟨fun ⟨j, hj⟩ => hj ▸ j.castSucc_lt_last.ne, fun hi => ⟨i.castLt $ Fin.val_lt_last hi, rfl⟩⟩\n\n@[simp]\ntheorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) :\n    ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by\n  rw [← coe_castSucc]\n  exact congr_arg val (Equiv.apply_ofInjective_symm _ _)\n#align fin.coe_of_injective_cast_succ_symm Fin.coe_of_injective_castSucc_symm\n\ntheorem succ_castSucc {n : ℕ} (i : Fin n) : i.castSucc.succ = castSucc i.succ :=\n  Fin.ext (by simp)\n#align fin.succ_cast_succ Fin.succ_castSucc\n\n/-- `addNat m i` adds `m` to `i`, generalizes `Fin.succ`. -/\ndef addNat (m) : Fin n ↪o Fin (n + m) :=\n  (OrderEmbedding.ofStrictMono fun i => ⟨(i : ℕ) + m, add_lt_add_right i.2 _⟩) fun i j h =>\n    add_lt_add_right (show i.val < j.val from h) _\n#align fin.add_nat Fin.addNat\n\n@[simp]\ntheorem coe_addNat (m : ℕ) (i : Fin n) : (addNat m i : ℕ) = i + m :=\n  rfl\n#align fin.coe_add_nat Fin.coe_addNat\n\n@[simp]\ntheorem addNat_one {i : Fin n} : addNat 1 i = i.succ := by\n  ext\n  rw [coe_addNat, val_succ]\n#align fin.add_nat_one Fin.addNat_one\n\ntheorem le_coe_addNat (m : ℕ) (i : Fin n) : m ≤ addNat m i :=\n  Nat.le_add_left _ _\n#align fin.le_coe_add_nat Fin.le_coe_addNat\n\n@[simp]\ntheorem addNat_mk (n i : ℕ) (hi : i < m) : addNat n ⟨i, hi⟩ = ⟨i + n, add_lt_add_right hi n⟩ :=\n  rfl\n#align fin.add_nat_mk Fin.addNat_mk\n\n@[simp]\ntheorem cast_addNat_zero {n n' : ℕ} (i : Fin n) (h : n + 0 = n') :\n    cast h (addNat 0 i) = cast ((add_zero _).symm.trans h) i :=\n  ext <| add_zero _\n#align fin.cast_add_nat_zero Fin.cast_addNat_zero\n\n/-- For rewriting in the reverse direction, see `Fin.cast_addNat_left`. -/\ntheorem addNat_cast {n n' m : ℕ} (i : Fin n') (h : n' = n) :\n    addNat m (cast h i) = cast (congr_arg (. + m) h) (addNat m i) :=\n  ext rfl\n#align fin.add_nat_cast Fin.addNat_cast\n\ntheorem cast_addNat_left {n n' m : ℕ} (i : Fin n') (h : n' + m = n + m) :\n    cast h (addNat m i) = addNat m (cast (add_right_cancel h) i) := by\n  ext\n  simp\n#align fin.cast_add_nat_left Fin.cast_addNat_left\n\n@[simp]\ntheorem cast_addNat_right {n m m' : ℕ} (i : Fin n) (h : n + m' = n + m) :\n    cast h (addNat m' i) = addNat m i :=\n  ext <| (congr_arg ((· + ·) (i : ℕ)) (add_left_cancel h) : _)\n#align fin.cast_add_nat_right Fin.cast_addNat_right\n\n/-- `natAdd n i` adds `n` to `i` \"on the left\". -/\ndef natAdd (n) {m} : Fin m ↪o Fin (n + m) :=\n  (OrderEmbedding.ofStrictMono fun i => ⟨n + (i : ℕ), add_lt_add_left i.2 _⟩) fun i j h =>\n    add_lt_add_left (show i.val < j.val from h) _\n#align fin.nat_add Fin.natAdd\n\n@[simp]\ntheorem coe_natAdd (n : ℕ) {m : ℕ} (i : Fin m) : (natAdd n i : ℕ) = n + i :=\n  rfl\n#align fin.coe_nat_add Fin.coe_natAdd\n\n@[simp]\ntheorem natAdd_mk (n i : ℕ) (hi : i < m) : natAdd n ⟨i, hi⟩ = ⟨n + i, add_lt_add_left hi n⟩ :=\n  rfl\n#align fin.nat_add_mk Fin.natAdd_mk\n\ntheorem le_coe_natAdd (m : ℕ) (i : Fin n) : m ≤ natAdd m i :=\n  Nat.le_add_right _ _\n#align fin.le_coe_nat_add Fin.le_coe_natAdd\n\ntheorem natAdd_zero {n : ℕ} : Fin.natAdd 0 = (Fin.cast (zero_add n).symm).toRelEmbedding := by\n  ext\n  simp\n#align fin.nat_add_zero Fin.natAdd_zero\n\n/-- For rewriting in the reverse direction, see `Fin.cast_natAdd_right`. -/\ntheorem natAdd_cast {n n' : ℕ} (m : ℕ) (i : Fin n') (h : n' = n) :\n    natAdd m (cast h i) = cast (congr_arg _ h) (natAdd m i) := by\n  ext\n  simp\n#align fin.nat_add_cast Fin.natAdd_cast\n\ntheorem cast_natAdd_right {n n' m : ℕ} (i : Fin n') (h : m + n' = m + n) :\n    cast h (natAdd m i) = natAdd m (cast (add_left_cancel h) i) := by\n  ext\n  simp\n#align fin.cast_nat_add_right Fin.cast_natAdd_right\n\n@[simp]\ntheorem cast_natAdd_left {n m m' : ℕ} (i : Fin n) (h : m' + n = m + n) :\n    cast h (natAdd m' i) = natAdd m i :=\n  ext <| (congr_arg (· + (i : ℕ)) (add_right_cancel h) : _)\n#align fin.cast_nat_add_left Fin.cast_natAdd_left\n\ntheorem castAdd_natAdd (p m : ℕ) {n : ℕ} (i : Fin n) :\n    castAdd p (natAdd m i) = cast (add_assoc _ _ _).symm (natAdd m (castAdd p i)) := by\n  ext\n  simp\n#align fin.cast_add_nat_add Fin.castAdd_natAdd\n\ntheorem natAdd_castAdd (p m : ℕ) {n : ℕ} (i : Fin n) :\n    natAdd m (castAdd p i) = cast (add_assoc _ _ _) (castAdd p (natAdd m i)) := by\n  ext\n  simp\n#align fin.nat_add_cast_add Fin.natAdd_castAdd\n\ntheorem natAdd_natAdd (m n : ℕ) {p : ℕ} (i : Fin p) :\n    natAdd m (natAdd n i) = cast (add_assoc _ _ _) (natAdd (m + n) i) :=\n  ext <| (add_assoc _ _ _).symm\n#align fin.nat_add_nat_add Fin.natAdd_natAdd\n\n@[simp]\ntheorem cast_natAdd_zero {n n' : ℕ} (i : Fin n) (h : 0 + n = n') :\n    cast h (natAdd 0 i) = cast ((zero_add _).symm.trans h) i :=\n  ext <| zero_add _\n#align fin.cast_nat_add_zero Fin.cast_natAdd_zero\n\n@[simp]\ntheorem cast_natAdd (n : ℕ) {m : ℕ} (i : Fin m) : cast (add_comm _ _) (natAdd n i) = addNat n i :=\n  ext <| add_comm _ _\n#align fin.cast_nat_add Fin.cast_natAdd\n\n@[simp]\ntheorem cast_addNat {n : ℕ} (m : ℕ) (i : Fin n) : cast (add_comm _ _) (addNat m i) = natAdd m i :=\n  ext <| add_comm _ _\n#align fin.cast_add_nat Fin.cast_addNat\n\n@[simp]\ntheorem natAdd_last {m n : ℕ} : natAdd n (last m) = last (n + m) :=\n  rfl\n#align fin.nat_add_last Fin.natAdd_last\n\ntheorem natAdd_castSucc {m n : ℕ} {i : Fin m} : natAdd n (castSucc i) = castSucc (natAdd n i) :=\n  rfl\n#align fin.nat_add_cast_succ Fin.natAdd_castSucc\n\nend Succ\n\nsection Pred\n\n/-!\n### pred\n-/\n\n\n-- Porting note: taken from lean3port\n/-- Predecessor -/\ndef pred {n : ℕ} : ∀ i : Fin (n + 1), i ≠ 0 → Fin n\n  | ⟨a, h₁⟩, h₂ =>\n    ⟨a.pred,\n      haveI : a ≠ 0 := by\n        have aux₁ := vne_of_ne h₂\n        dsimp at aux₁\n        exact aux₁\n      Nat.pred_lt_pred this h₁⟩\n#align fin.pred Fin.pred\n\n@[simp]\ntheorem coe_pred (j : Fin (n + 1)) (h : j ≠ 0) : (j.pred h : ℕ) = j - 1 := by\n  cases j\n  rfl\n#align fin.coe_pred Fin.coe_pred\n\n@[simp]\ntheorem succ_pred : ∀ (i : Fin (n + 1)) (h : i ≠ 0), (i.pred h).succ = i\n  | ⟨0, h⟩, hi => by simp only [mk_zero, ne_eq, not_true] at hi\n  | ⟨n + 1, h⟩, hi => rfl\n#align fin.succ_pred Fin.succ_pred\n\n@[simp]\ntheorem pred_succ (i : Fin n) {h : i.succ ≠ 0} : i.succ.pred h = i := by\n  cases i\n  rfl\n#align fin.pred_succ Fin.pred_succ\n\ntheorem pred_eq_iff_eq_succ {n : ℕ} (i : Fin (n + 1)) (hi : i ≠ 0) (j : Fin n) :\n    i.pred hi = j ↔ i = j.succ :=\n  ⟨fun h => by simp only [← h, Fin.succ_pred], fun h => by simp only [h, Fin.pred_succ]⟩\n#align fin.pred_eq_iff_eq_succ Fin.pred_eq_iff_eq_succ\n\n--Porting note: removing @[simp]. `pred_mk_succ'` has `simp` attribute instead\ntheorem pred_mk_succ (i : ℕ) (h : i < n + 1) :\n    Fin.pred ⟨i + 1, add_lt_add_right h 1⟩ (ne_of_vne (_root_.ne_of_gt (mk_succ_pos i h))) =\n      ⟨i, h⟩ := by\n  simp only [ext_iff, coe_pred, add_tsub_cancel_right]\n#align fin.pred_mk_succ Fin.pred_mk_succ\n\n--Porting note: new theorem\n@[simp]\ntheorem pred_mk_succ' (i : ℕ) (h₁ : i + 1 < n + 1 + 1) (h₂) :\n    Fin.pred ⟨i + 1, h₁⟩ h₂ = ⟨i, Nat.lt_of_succ_lt_succ h₁⟩ :=\n  pred_mk_succ i _\n\n-- This is not a simp lemma by default, because `pred_mk_succ` is nicer when it applies.\ntheorem pred_mk {n : ℕ} (i : ℕ) (h : i < n + 1) (w) : Fin.pred ⟨i, h⟩ w =\n    ⟨i - 1, by\n      rwa [tsub_lt_iff_right (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero\n        (by simpa using Fin.vne_of_ne w))]⟩ :=\n  rfl\n#align fin.pred_mk Fin.pred_mk\n\n@[simp]\ntheorem pred_le_pred_iff {n : ℕ} {a b : Fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :\n    a.pred ha ≤ b.pred hb ↔ a ≤ b := by rw [← succ_le_succ_iff, succ_pred, succ_pred]\n#align fin.pred_le_pred_iff Fin.pred_le_pred_iff\n\n@[simp]\ntheorem pred_lt_pred_iff {n : ℕ} {a b : Fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :\n    a.pred ha < b.pred hb ↔ a < b := by rw [← succ_lt_succ_iff, succ_pred, succ_pred]\n#align fin.pred_lt_pred_iff Fin.pred_lt_pred_iff\n\n@[simp]\ntheorem pred_inj : ∀ {a b : Fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b\n  | ⟨0, _⟩, _, ha, _ => by simp only [mk_zero, ne_eq, not_true] at ha\n  | ⟨i + 1, _⟩, ⟨0, _⟩, _, hb => by simp only [mk_zero, ne_eq, not_true] at hb\n  | ⟨i + 1, hi⟩, ⟨j + 1, hj⟩, ha, hb => by simp [Fin.eq_iff_veq]\n#align fin.pred_inj Fin.pred_inj\n\n@[simp]\ntheorem pred_one {n : ℕ} : Fin.pred (1 : Fin (n + 2)) (Ne.symm (ne_of_lt one_pos)) = 0 := by\n  ext\n  simp\n#align fin.pred_one Fin.pred_one\n\ntheorem pred_add_one (i : Fin (n + 2)) (h : (i : ℕ) < n + 1) :\n    pred (i + 1) (_root_.ne_of_gt (by exact\n      (add_one_pos _ (lt_iff_val_lt_val.2 h)))) = castLt i h := by\n  rw [ext_iff, coe_pred, coe_castLt, val_add, val_one, mod_eq_of_lt, add_tsub_cancel_right]\n  exact add_lt_add_right h 1\n#align fin.pred_add_one Fin.pred_add_one\n\n/-- `subNat i h` subtracts `m` from `i`, generalizes `Fin.pred`. -/\ndef subNat (m) (i : Fin (n + m)) (h : m ≤ (i : ℕ)) : Fin n :=\n  ⟨(i : ℕ) - m, by\n    rw [tsub_lt_iff_right h]\n    exact i.is_lt⟩\n#align fin.sub_nat Fin.subNat\n\n@[simp]\ntheorem coe_subNat (i : Fin (n + m)) (h : m ≤ i) : (i.subNat m h : ℕ) = i - m :=\n  rfl\n#align fin.coe_sub_nat Fin.coe_subNat\n\n@[simp]\ntheorem subNat_mk {i : ℕ} (h₁ : i < n + m) (h₂ : m ≤ i) :\n    subNat m ⟨i, h₁⟩ h₂ = ⟨i - m, (tsub_lt_iff_right h₂).2 h₁⟩ :=\n  rfl\n#align fin.sub_nat_mk Fin.subNat_mk\n\n@[simp]\ntheorem pred_castSucc_succ (i : Fin n) :\n    pred (castSucc i.succ) (ne_of_gt (castSucc_pos i.succ_pos)) = castSucc i := by\n  simp [eq_iff_veq]\n#align fin.pred_cast_succ_succ Fin.pred_castSucc_succ\n\n@[simp]\ntheorem addNat_subNat {i : Fin (n + m)} (h : m ≤ i) : addNat m (subNat m i h) = i :=\n  ext <| tsub_add_cancel_of_le h\n#align fin.add_nat_sub_nat Fin.addNat_subNat\n\n@[simp]\ntheorem subNat_addNat (i : Fin n) (m : ℕ) (h : m ≤ addNat m i := le_coe_addNat m i) :\n    subNat m (addNat m i) h = i :=\n  ext <| add_tsub_cancel_right (i : ℕ) m\n#align fin.sub_nat_add_nat Fin.subNat_addNat\n\n@[simp]\ntheorem natAdd_subNat_cast {i : Fin (n + m)} (h : n ≤ i) :\n    natAdd n (subNat n (cast (add_comm _ _) i) h) = i := by simp [← cast_addNat]\n#align fin.nat_add_sub_nat_cast Fin.natAdd_subNat_cast\n\nend Pred\n\nsection DivMod\n\n/-- Compute `i / n`, where `n` is a `Nat` and inferred the type of `i`. -/\ndef divNat (i : Fin (m * n)) : Fin m :=\n  ⟨i / n, Nat.div_lt_of_lt_mul <| mul_comm m n ▸ i.prop⟩\n#align fin.div_nat Fin.divNat\n\n@[simp]\ntheorem coe_divNat (i : Fin (m * n)) : (i.divNat : ℕ) = i / n :=\n  rfl\n#align fin.coe_div_nat Fin.coe_divNat\n\n/-- Compute `i % n`, where `n` is a `Nat` and inferred the type of `i`. -/\ndef modNat (i : Fin (m * n)) : Fin n :=\n  ⟨i % n, Nat.mod_lt _ <| pos_of_mul_pos_right i.pos m.zero_le⟩\n#align fin.mod_nat Fin.modNat\n\n@[simp]\ntheorem coe_modNat (i : Fin (m * n)) : (i.modNat : ℕ) = i % n :=\n  rfl\n#align fin.coe_mod_nat Fin.coe_modNat\n\nend DivMod\n\nsection Rec\n\n/-!\n### recursion and induction principles\n-/\n\n\n/-- Define `C n i` by induction on `i : Fin n` interpreted as `(0 : Fin (n - i)).succ.succ…`.\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_elim]\ndef succRec {C : ∀ n, Fin n → Sort _} (H0 : ∀ n, C (n.succ) (0 : Fin (n + 1)))\n    (Hs : ∀ n i, C n i → C n.succ i.succ) : ∀ {n : ℕ} (i : Fin n), C n i\n  | 0, i => i.elim0\n  | Nat.succ n, ⟨0, _⟩ => by rw [mk_zero]; exact H0 n\n  | Nat.succ _, ⟨Nat.succ i, h⟩ => Hs _ _ (succRec H0 Hs ⟨i, lt_of_succ_lt_succ h⟩)\n#align fin.succ_rec Fin.succRec\n\n/-- Define `C n i` by induction on `i : Fin n` interpreted as `(0 : Fin (n - i)).succ.succ…`.\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.succRec` taking `i : Fin n` as the first argument. -/\n@[elab_as_elim]\ndef succRecOn {n : ℕ} (i : Fin n) {C : ∀ n, Fin n → Sort _} (H0 : ∀ n, C (n + 1) 0)\n    (Hs : ∀ n i, C n i → C (Nat.succ n) i.succ) : C n i :=\n  i.succRec H0 Hs\n#align fin.succ_rec_on Fin.succRecOn\n\n@[simp]\ntheorem succRecOn_zero {C : ∀ n, Fin n → Sort _} {H0 Hs} (n) :\n    @Fin.succRecOn (n + 1) 0 C H0 Hs = H0 n := by\n  cases n <;> rfl\n#align fin.succ_rec_on_zero Fin.succRecOn_zero\n\n@[simp]\ntheorem succRecOn_succ {C : ∀ n, Fin n → Sort _} {H0 Hs} {n} (i : Fin n) :\n    @Fin.succRecOn (n + 1) i.succ C H0 Hs = Hs n i (Fin.succRecOn i H0 Hs) := by cases i; rfl\n#align fin.succ_rec_on_succ Fin.succRecOn_succ\n\n/-- Define `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.castSucc`.\n-/\n@[elab_as_elim]\ndef induction {C : Fin (n + 1) → Sort _} (h0 : C 0)\n    (hs : ∀ i : Fin n, C (castSucc i) → C i.succ) :\n    ∀ i : Fin (n + 1), C i := by\n  rintro ⟨i, hi⟩\n  induction' i with i IH\n  · rwa [Fin.mk_zero]\n  · refine' hs ⟨i, lt_of_succ_lt_succ hi⟩ _\n    exact IH (lt_of_succ_lt hi)\n#align fin.induction Fin.induction\n\n--Porting note: This proof became a lot more complicated\n@[simp]\ntheorem induction_zero {C : Fin (n + 1) → Sort _} : ∀ (h0 : C 0)\n    (hs : ∀ i : Fin n, C (castSucc i) → C i.succ),\n    (induction h0 hs : ∀ i : Fin (n + 1), C i) 0 = h0 :=\n  have : ⟨0, Nat.zero_lt_succ n⟩ = (0 : Fin (n + 1)) := by simp only [mk_zero]\n  Eq.recOn (motive := fun (i : Fin (n + 1)) (h : ⟨0, Nat.zero_lt_succ n⟩ = i) =>\n      ∀ (h0 : C i) (hs : ∀ i : Fin n, C (castSucc i) → C i.succ),\n        (show ∀ i : Fin (n + 1), C i from induction\n          (by simp [← h] at h0; exact h0) hs) i = h0)\n    this\n    (by intros h0 _; simp [induction])\n#align fin.induction_zero Fin.induction_zero\n\n@[simp]\ntheorem induction_succ {C : Fin (n + 1) → Sort _} (h0 : C 0)\n    (hs : ∀ i : Fin n, C (castSucc i) → C i.succ) (i : Fin n) :\n    (induction h0 hs : ∀ i : Fin (n+1), C i) i.succ = hs i (induction h0 hs (castSucc i)) :=\n  by cases i; rfl\n#align fin.induction_succ Fin.induction_succ\n\n/-- Define `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.castSucc`.\n\nA version of `Fin.induction` taking `i : Fin (n + 1)` as the first argument.\n-/\n@[elab_as_elim]\ndef inductionOn (i : Fin (n + 1)) {C : Fin (n + 1) → Sort _} (h0 : C 0)\n    (hs : ∀ i : Fin n, C (castSucc i) → C i.succ) : C i :=\n  induction h0 hs i\n#align fin.induction_on Fin.inductionOn\n\n/-- Define `f : Π i : Fin n.succ, C i` by separately handling the cases `i = 0` and\n`i = j.succ`, `j : Fin n`. -/\n@[elab_as_elim]\ndef cases {C : Fin (n + 1) → Sort _} (H0 : C 0) (Hs : ∀ i : Fin n, C i.succ) :\n    ∀ i : Fin (n + 1), C i :=\n  induction H0 fun i _ => Hs i\n#align fin.cases Fin.cases\n\n@[simp]\ntheorem cases_zero {n} {C : Fin (n + 1) → Sort _} {H0 Hs} : @Fin.cases n C H0 Hs 0 = H0 := by\n  cases n <;> rfl\n#align fin.cases_zero Fin.cases_zero\n\n@[simp]\ntheorem cases_succ {n} {C : Fin (n + 1) → Sort _} {H0 Hs} (i : Fin n) :\n    @Fin.cases n C H0 Hs i.succ = Hs i := by cases i; rfl\n#align fin.cases_succ Fin.cases_succ\n\n@[simp]\ntheorem cases_succ' {n} {C : Fin (n + 1) → Sort _} {H0 Hs} {i : ℕ} (h : i + 1 < n + 1) :\n    @Fin.cases n C H0 Hs ⟨i.succ, h⟩ = Hs ⟨i, lt_of_succ_lt_succ h⟩ := by cases i <;> rfl\n#align fin.cases_succ' Fin.cases_succ'\n\ntheorem forall_fin_succ {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ P 0 ∧ ∀ i : Fin n, P i.succ :=\n  ⟨fun H => ⟨H 0, fun _ => H _⟩, fun ⟨H0, H1⟩ i => Fin.cases H0 H1 i⟩\n#align fin.forall_fin_succ Fin.forall_fin_succ\n\ntheorem exists_fin_succ {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ P 0 ∨ ∃ i : Fin n, P i.succ :=\n  ⟨fun ⟨i, h⟩ => Fin.cases Or.inl (fun i hi => Or.inr ⟨i, hi⟩) i h, fun h =>\n    (h.elim fun h => ⟨0, h⟩) fun ⟨i, hi⟩ => ⟨i.succ, hi⟩⟩\n#align fin.exists_fin_succ Fin.exists_fin_succ\n\ntheorem forall_fin_one {p : Fin 1 → Prop} : (∀ i, p i) ↔ p 0 :=\n  @Unique.forall_iff (Fin 1) _ p\n#align fin.forall_fin_one Fin.forall_fin_one\n\ntheorem exists_fin_one {p : Fin 1 → Prop} : (∃ i, p i) ↔ p 0 :=\n  @Unique.exists_iff (Fin 1) _ p\n#align fin.exists_fin_one Fin.exists_fin_one\n\ntheorem forall_fin_two {p : Fin 2 → Prop} : (∀ i, p i) ↔ p 0 ∧ p 1 :=\n  forall_fin_succ.trans <| and_congr_right fun _ => forall_fin_one\n#align fin.forall_fin_two Fin.forall_fin_two\n\ntheorem exists_fin_two {p : Fin 2 → Prop} : (∃ i, p i) ↔ p 0 ∨ p 1 :=\n  exists_fin_succ.trans <| or_congr_right exists_fin_one\n#align fin.exists_fin_two Fin.exists_fin_two\n\ntheorem fin_two_eq_of_eq_zero_iff {a b : Fin 2} (h : a = 0 ↔ b = 0) : a = b := by\n  revert a b\n  simp [forall_fin_two]\n#align fin.fin_two_eq_of_eq_zero_iff Fin.fin_two_eq_of_eq_zero_iff\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_elim]\ndef reverseInduction {C : Fin (n + 1) → Sort _} (hlast : C (Fin.last n))\n    (hs : ∀ i : Fin n, C i.succ → C (castSucc i)) (i : Fin (n + 1)) : C i :=\n  if hi : i = Fin.last n then _root_.cast (congr_arg C hi.symm) hlast\n  else\n    let j : Fin n := ⟨i, lt_of_le_of_ne (Nat.le_of_lt_succ i.2) fun h => hi (Fin.ext h)⟩\n    have _ : n - i < n + 1 - i :=\n      lt_of_eq_of_lt (Nat.add_sub_add_right ..).symm\n        (Nat.sub_lt_sub_left i.2 (Nat.lt_succ_self i))\n    have hi : i = Fin.castSucc j := Fin.ext rfl\n    _root_.cast (congr_arg C hi.symm) (hs _ (reverseInduction hlast hs j.succ))\ntermination_by _ => n + 1 - i\n#align fin.reverse_induction Fin.reverseInduction\n\n@[simp]\ntheorem reverse_induction_last {n : ℕ} {C : Fin (n + 1) → Sort _} (h0 : C (Fin.last n))\n    (hs : ∀ i : Fin n, C i.succ → C (castSucc i)) :\n    (reverseInduction h0 hs (Fin.last n) : C (Fin.last n)) = h0 := by\n  rw [reverseInduction] ; simp\n#align fin.reverse_induction_last Fin.reverse_induction_last\n\n@[simp]\ntheorem reverse_induction_castSucc {n : ℕ} {C : Fin (n + 1) → Sort _} (h0 : C (Fin.last n))\n    (hs : ∀ i : Fin n, C i.succ → C (castSucc i)) (i : Fin n) :\n    (reverseInduction h0 hs (castSucc i) :\n    C (castSucc i)) = hs i (reverseInduction h0 hs i.succ) := by\n  rw [reverseInduction, dif_neg (_root_.ne_of_lt (Fin.castSucc_lt_last i))]\n  cases i\n  rfl\n#align fin.reverse_induction_cast_succ Fin.reverse_induction_castSucc\n\n/-- Define `f : Π i : Fin n.succ, C i` by separately handling the cases `i = Fin.last n` and\n`i = j.castSucc`, `j : Fin n`. -/\n@[elab_as_elim]\ndef lastCases {n : ℕ} {C : Fin (n + 1) → Sort _} (hlast : C (Fin.last n))\n    (hcast : ∀ i : Fin n, C (castSucc i)) (i : Fin (n + 1)) : C i :=\n  reverseInduction hlast (fun i _ => hcast i) i\n#align fin.last_cases Fin.lastCases\n\n@[simp]\ntheorem lastCases_last {n : ℕ} {C : Fin (n + 1) → Sort _} (hlast : C (Fin.last n))\n    (hcast : ∀ i : Fin n, C (castSucc i)) :\n    (Fin.lastCases hlast hcast (Fin.last n) : C (Fin.last n)) = hlast :=\n  reverse_induction_last _ _\n#align fin.last_cases_last Fin.lastCases_last\n\n@[simp]\ntheorem lastCases_castSucc {n : ℕ} {C : Fin (n + 1) → Sort _} (hlast : C (Fin.last n))\n    (hcast : ∀ i : Fin n, C (castSucc i)) (i : Fin n) :\n    (Fin.lastCases hlast hcast (Fin.castSucc i) : C (Fin.castSucc i)) = hcast i :=\n  reverse_induction_castSucc _ _ _\n#align fin.last_cases_cast_succ Fin.lastCases_castSucc\n\n/-- Define `f : Π i : Fin (m + n), C i` by separately handling the cases `i = castAdd n i`,\n`j : Fin m` and `i = natAdd m j`, `j : Fin n`. -/\n@[elab_as_elim]\ndef addCases {m n : ℕ} {C : Fin (m + n) → Sort u} (hleft : ∀ i, C (castAdd n i))\n    (hright : ∀ i, C (natAdd m i)) (i : Fin (m + n)) : C i :=\n  if hi : (i : ℕ) < m then (castAdd_castLt n i hi) ▸ (hleft (castLt i hi))\n  else (natAdd_subNat_cast (le_of_not_lt hi)) ▸ (hright _)\n#align fin.add_cases Fin.addCases\n\n@[simp]\ntheorem addCases_left {m n : ℕ} {C : Fin (m + n) → Sort _} (hleft : ∀ i, C (castAdd n i))\n    (hright : ∀ i, C (natAdd m i)) (i : Fin m) :\n    addCases hleft hright (Fin.castAdd n i) = hleft i := by\n  cases' i with i hi\n  rw [addCases, dif_pos (castAdd_lt _ _)]\n  rfl\n#align fin.add_cases_left Fin.addCases_left\n\n@[simp]\ntheorem addCases_right {m n : ℕ} {C : Fin (m + n) → Sort _} (hleft : ∀ i, C (castAdd n i))\n    (hright : ∀ i, C (natAdd m i)) (i : Fin n) : addCases hleft hright (natAdd m i) = hright i := by\n  have : ¬(natAdd m i : ℕ) < m := (le_coe_natAdd _ _).not_lt\n  rw [addCases, dif_neg this]\n  refine' eq_of_heq ((eq_rec_heq _ _).trans _)\n  congr 1\n  simp\n#align fin.add_cases_right Fin.addCases_right\n\nend Rec\n\ntheorem lift_fun_iff_succ {α : Type _} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} :\n    ((· < ·) ⇒ r) f f ↔ ∀ i : Fin n, r (f (castSucc i)) (f i.succ) := by\n  constructor\n  · intro H i\n    exact H i.castSucc_lt_succ\n  · refine' fun H i => Fin.induction _ _\n    · exact fun h => (h.not_le (zero_le i)).elim\n    · intro j ihj hij\n      rw [← le_castSucc_iff] at hij\n      rcases hij.eq_or_lt with (rfl | hlt)\n      exacts[H j, _root_.trans (ihj hlt) (H j)]\n#align fin.lift_fun_iff_succ Fin.lift_fun_iff_succ\n\n/-- A function `f` on `Fin (n + 1)` is strictly monotone if and only if `f i < f (i + 1)`\nfor all `i`. -/\ntheorem strictMono_iff_lt_succ {α : Type _} [Preorder α] {f : Fin (n + 1) → α} :\n    StrictMono f ↔ ∀ i : Fin n, f (castSucc i) < f i.succ :=\n  lift_fun_iff_succ (· < ·)\n#align fin.strict_mono_iff_lt_succ Fin.strictMono_iff_lt_succ\n\n/-- A function `f` on `Fin (n + 1)` is monotone if and only if `f i ≤ f (i + 1)` for all `i`. -/\ntheorem monotone_iff_le_succ {α : Type _} [Preorder α] {f : Fin (n + 1) → α} :\n    Monotone f ↔ ∀ i : Fin n, f (castSucc i) ≤ f i.succ :=\n  monotone_iff_forall_lt.trans <| lift_fun_iff_succ (· ≤ ·)\n#align fin.monotone_iff_le_succ Fin.monotone_iff_le_succ\n\n/-- A function `f` on `Fin (n + 1)` is strictly antitone if and only if `f (i + 1) < f i`\nfor all `i`. -/\ntheorem strictAnti_iff_succ_lt {α : Type _} [Preorder α] {f : Fin (n + 1) → α} :\n    StrictAnti f ↔ ∀ i : Fin n, f i.succ < f (castSucc i) :=\n  lift_fun_iff_succ (· > ·)\n#align fin.strict_anti_iff_succ_lt Fin.strictAnti_iff_succ_lt\n\n/-- A function `f` on `Fin (n + 1)` is antitone if and only if `f (i + 1) ≤ f i` for all `i`. -/\ntheorem antitone_iff_succ_le {α : Type _} [Preorder α] {f : Fin (n + 1) → α} :\n    Antitone f ↔ ∀ i : Fin n, f i.succ ≤ f (castSucc i) :=\n  antitone_iff_forall_lt.trans <| lift_fun_iff_succ (· ≥ ·)\n#align fin.antitone_iff_succ_le Fin.antitone_iff_succ_le\n\nsection AddGroup\n\nopen Nat Int\n\n/-- Negation on `Fin n` -/\ninstance neg (n : ℕ) : Neg (Fin n) :=\n  ⟨fun a => ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩⟩\n\n/-- Abelian group structure on `Fin n`. -/\ninstance addCommGroup (n : ℕ) [NeZero n] : AddCommGroup (Fin n) :=\n  { Fin.addCommMonoid n, Fin.neg n with\n    add_left_neg := fun ⟨a, ha⟩ =>\n      Fin.ext <|\n        _root_.trans (Nat.mod_add_mod _ _ _) <| by\n          rw [Fin.val_zero, tsub_add_cancel_of_le, Nat.mod_self]\n          exact le_of_lt ha\n    sub_eq_add_neg := fun ⟨a, ha⟩ ⟨b, hb⟩ =>\n      Fin.ext <| show (a + (n - b)) % n = (a + (n - b) % n) % n by simp\n    sub := Fin.sub }\n\nprotected theorem coe_neg (a : Fin n) : ((-a : Fin n) : ℕ) = (n - a) % n :=\n  rfl\n#align fin.coe_neg Fin.coe_neg\n\nprotected theorem coe_sub (a b : Fin n) : ((a - b : Fin n) : ℕ) = (a + (n - b)) % n := by\n  cases a; cases b; rfl\n#align fin.coe_sub Fin.coe_sub\n\ntheorem fin_one_eq_zero (a : Fin 1) : a = 0 := by rw [Subsingleton.elim a 0]\n\n@[simp]\ntheorem coe_fin_one (a : Fin 1) : (a : ℕ) = 0 := by simp [Subsingleton.elim a 0]\n#align fin.coe_fin_one Fin.coe_fin_one\n\n@[simp]\ntheorem coe_neg_one : ↑(-1 : Fin (n + 1)) = n := by\n  cases n\n  · simp\n  rw [Fin.coe_neg, Fin.val_one, Nat.succ_sub_one, Nat.mod_eq_of_lt]\n  constructor\n#align fin.coe_neg_one Fin.coe_neg_one\n\ntheorem coe_sub_one {n} (a : Fin (n + 1)) : ↑(a - 1) = if a = 0 then n else a - 1 := by\n  cases n\n  · simp\n  split_ifs with h\n  · simp [h]\n  rw [sub_eq_add_neg, val_add_eq_ite, coe_neg_one, if_pos, add_comm, add_tsub_add_eq_tsub_left]\n  conv_rhs => rw [add_comm]\n  rw [add_le_add_iff_left, Nat.one_le_iff_ne_zero]\n  rwa [Fin.ext_iff] at h\n#align fin.coe_sub_one Fin.coe_sub_one\n\ntheorem coe_sub_iff_le {n : ℕ} {a b : Fin n} : (↑(a - b) : ℕ) = a - b ↔ b ≤ a := by\n  cases n; · exact @finZeroElim (fun _ => _) a\n  rw [le_iff_val_le_val, Fin.coe_sub, ← add_tsub_assoc_of_le b.is_lt.le a]\n  cases' le_or_lt (b : ℕ) a with h h\n  · simp [← tsub_add_eq_add_tsub h, val_fin_le.mp h,\n      Nat.mod_eq_of_lt ((Nat.sub_le _ _).trans_lt a.is_lt)]\n  · rw [Nat.mod_eq_of_lt, tsub_eq_zero_of_le h.le, tsub_eq_zero_iff_le, ← not_iff_not]\n    · simpa [b.is_lt.trans_le le_add_self] using h\n    · rwa [tsub_lt_iff_left (b.is_lt.le.trans le_add_self), add_lt_add_iff_right]\n#align fin.coe_sub_iff_le Fin.coe_sub_iff_le\n\ntheorem coe_sub_iff_lt {n : ℕ} {a b : Fin n} : (↑(a - b) : ℕ) = n + a - b ↔ a < b := by\n  cases' n with n\n  · exact @finZeroElim (fun _ => _) a\n  rw [lt_iff_val_lt_val, Fin.coe_sub, add_comm]\n  cases' le_or_lt (b : ℕ) a with h h\n  · refine iff_of_false ?_ (not_lt_of_le h)\n    simpa [add_tsub_assoc_of_le h] using\n      ((Nat.mod_lt _ (Nat.succ_pos _)).trans_le le_self_add).ne\n  · simp [← tsub_tsub_assoc b.is_lt.le h.le, ← tsub_add_eq_add_tsub b.is_lt.le,\n      Nat.mod_eq_of_lt (tsub_lt_self (Nat.succ_pos _) (tsub_pos_of_lt h)), val_fin_le.mp _]\n    exact h\n#align fin.coe_sub_iff_lt Fin.coe_sub_iff_lt\n\n@[simp]\ntheorem lt_sub_one_iff {n : ℕ} {k : Fin (n + 2)} : k < k - 1 ↔ k = 0 := by\n  rcases k with ⟨_ | k, hk⟩\n  simp [lt_iff_val_lt_val]\n  have : (k + 1 + (n + 1)) % (n + 2) = k % (n + 2) := by\n    rw [add_right_comm, add_assoc, add_mod_right]\n  simp [lt_iff_val_lt_val, ext_iff, Fin.coe_sub, succ_eq_add_one, this,\n    mod_eq_of_lt ((lt_succ_self _).trans hk)]\n#align fin.lt_sub_one_iff Fin.lt_sub_one_iff\n\n@[simp]\ntheorem le_sub_one_iff {n : ℕ} {k : Fin (n + 1)} : k ≤ k - 1 ↔ k = 0 := by\n  cases n\n  · simp [fin_one_eq_zero k]\n  rw [← lt_sub_one_iff, le_iff_lt_or_eq, lt_sub_one_iff, or_iff_left_iff_imp, eq_comm,\n    sub_eq_iff_eq_add]\n  simp\n#align fin.le_sub_one_iff Fin.le_sub_one_iff\n\n@[simp]\ntheorem sub_one_lt_iff {n : ℕ} {k : Fin (n + 1)} : k - 1 < k ↔ 0 < k :=\n  not_iff_not.1 <| by simp only [not_lt, le_sub_one_iff, le_zero_iff]\n#align fin.sub_one_lt_iff Fin.sub_one_lt_iff\n\ntheorem last_sub (i : Fin (n + 1)) : last n - i = Fin.rev i :=\n  ext <| by rw [coe_sub_iff_le.2 i.le_last, val_last, val_rev, Nat.succ_sub_succ_eq_sub]\n#align fin.last_sub Fin.last_sub\n\nend AddGroup\n\nsection SuccAbove\n\ntheorem succAbove_aux (p : Fin (n + 1)) :\n    StrictMono fun i : Fin n => if (castSucc i) < p then (castSucc i) else i.succ :=\n  (castSucc : Fin n ↪o _).strictMono.ite (succEmbedding n).strictMono\n    (fun _ _ hij hj => lt_trans ((castSucc : Fin n ↪o _).lt_iff_lt.2 hij) hj) fun i =>\n    (castSucc_lt_succ i).le\n#align fin.succ_above_aux Fin.succAbove_aux\n\n/-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/\ndef succAbove (p : Fin (n + 1)) : Fin n ↪o Fin (n + 1) :=\n  OrderEmbedding.ofStrictMono _ p.succAbove_aux\n#align fin.succ_above Fin.succAbove\n\n/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`\nembeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/\ntheorem succAbove_below (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) :\n    p.succAbove i = castSucc i := if_pos h\n#align fin.succ_above_below Fin.succAbove_below\n\n@[simp]\ntheorem succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by\n  rw [Fin.succAbove_below]\n  · simp\n  · simp only [castSucc_zero]\n    exact bot_lt_iff_ne_bot.mpr ha\n#align fin.succ_above_ne_zero_zero Fin.succAbove_ne_zero_zero\n\ntheorem succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) :\n    a.succAbove b = 0 ↔ b = 0 := by\n  simp only [← succAbove_ne_zero_zero ha, OrderEmbedding.eq_iff_eq, iff_self]\n#align fin.succ_above_eq_zero_iff Fin.succAbove_eq_zero_iff\n\ntheorem succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) :\n    a.succAbove b ≠ 0 :=\n  mt (succAbove_eq_zero_iff ha).mp hb\n#align fin.succ_above_ne_zero Fin.succAbove_ne_zero\n\n/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/\n@[simp]\ntheorem succAbove_zero : ⇑(succAbove (0 : Fin (n + 1))) = Fin.succ :=\n  rfl\n#align fin.succ_above_zero Fin.succAbove_zero\n\n/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/\n@[simp]\ntheorem succAbove_last : succAbove (Fin.last n) = castSucc := by\n  ext\n  simp only [succAbove_below, castSucc_lt_last]\n#align fin.succ_above_last Fin.succAbove_last\n\ntheorem succAbove_last_apply (i : Fin n) : succAbove (Fin.last n) i = castSucc i := by\n  rw [succAbove_last]\n#align fin.succ_above_last_apply Fin.succAbove_last_apply\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`. -/\ntheorem succAbove_above (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) :\n    p.succAbove i = i.succ := by simp [succAbove, h.not_lt]\n#align fin.succ_above_above Fin.succAbove_above\n\n/-- Embedding `i : Fin n` into `Fin (n + 1)` is always about some hole `p`. -/\ntheorem succAbove_lt_ge (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p ≤ castSucc i :=\n  lt_or_ge (castSucc i) p\n#align fin.succ_above_lt_ge Fin.succAbove_lt_ge\n\n/-- Embedding `i : Fin n` into `Fin (n + 1)` is always about some hole `p`. -/\ntheorem succAbove_lt_gt (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ :=\n  Or.casesOn (succAbove_lt_ge p i) (fun h => Or.inl h) fun h =>\n    Or.inr (lt_of_le_of_lt h (castSucc_lt_succ i))\n#align fin.succ_above_lt_gt Fin.succAbove_lt_gt\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]\ntheorem succAbove_lt_iff (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ castSucc i < p := by\n  refine' Iff.intro _ _\n  · intro h\n    cases' succAbove_lt_ge p i with H H\n    · exact H\n    · rw [succAbove_above _ _ H] at h\n      exact lt_trans (castSucc_lt_succ i) h\n  · intro h\n    rw [succAbove_below _ _ h]\n    exact h\n#align fin.succ_above_lt_iff Fin.succAbove_lt_iff\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`. -/\ntheorem lt_succAbove_iff (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p ≤ castSucc i := by\n  refine' Iff.intro _ _\n  · intro h\n    cases' succAbove_lt_ge p i with H H\n    · rw [succAbove_below _ _ H] at h\n      exact le_of_lt h\n    · exact H\n  · intro h\n    rw [succAbove_above _ _ h]\n    exact lt_of_le_of_lt h (castSucc_lt_succ i)\n#align fin.lt_succ_above_iff Fin.lt_succAbove_iff\n\n/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`\nnever results in `p` itself -/\ntheorem succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by\n  intro eq\n  by_cases H : castSucc i < p\n  · simp [lt_irrefl, ← succAbove_below _ _ H, eq] at H\n  · simpa [← succAbove_above _ _ (le_of_not_lt H), eq, H] using castSucc_lt_succ i\n#align fin.succ_above_ne Fin.succAbove_ne\n\n/-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/\ntheorem succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by\n  by_cases H : castSucc i < p\n  · simpa [succAbove_below _ _ H] using castSucc_pos h\n  · simp [succAbove_above _ _ (le_of_not_lt H)]\n#align fin.succ_above_pos Fin.succAbove_pos\n\n@[simp]\ntheorem succAbove_castLt {x y : Fin (n + 1)} (h : x < y)\n    (hx : x.1 < n := lt_of_lt_of_le h y.le_last) : y.succAbove (x.castLt hx) = x := by\n  rw [succAbove_below, castSucc_cast_lt]\n  exact h\n#align fin.succ_above_cast_lt Fin.succAbove_castLt\n\n@[simp]\ntheorem succAbove_pred {x y : Fin (n + 1)} (h : x < y) (hy : y ≠ 0 := (x.zero_le.trans_lt h).ne') :\n    x.succAbove (y.pred hy) = y := by\n  rw [succAbove_above, succ_pred]\n  simpa [le_iff_val_le_val] using Nat.le_pred_of_lt h\n#align fin.succ_above_pred Fin.succAbove_pred\n\ntheorem castLt_succAbove {x : Fin n} {y : Fin (n + 1)} (h : castSucc x < y)\n    (h' : (y.succAbove x).1 < n := lt_of_lt_of_le ((succAbove_lt_iff _ _).2 h) (le_last y)) :\n    (y.succAbove x).castLt h' = x := by simp only [succAbove_below _ _ h, cast_lt_castSucc]\n#align fin.cast_lt_succ_above Fin.castLt_succAbove\n\ntheorem pred_succAbove {x : Fin n} {y : Fin (n + 1)} (h : y ≤ castSucc x)\n    (h' : y.succAbove x ≠ 0 := (y.zero_le.trans_lt <| (lt_succAbove_iff _ _).2 h).ne') :\n    (y.succAbove x).pred h' = x := by simp only [succAbove_above _ _ h, pred_succ]\n#align fin.pred_succ_above Fin.pred_succAbove\n\ntheorem exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by\n  cases' h.lt_or_lt with hlt hlt\n  exacts[⟨_, succAbove_castLt hlt⟩, ⟨_, succAbove_pred hlt⟩]\n#align fin.exists_succ_above_eq Fin.exists_succAbove_eq\n\n@[simp]\ntheorem exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x := by\n  refine' ⟨_, exists_succAbove_eq⟩\n  rintro ⟨y, rfl⟩\n  exact succAbove_ne _ _\n#align fin.exists_succ_above_eq_iff Fin.exists_succAbove_eq_iff\n\n/-- The range of `p.succAbove` is everything except `p`. -/\n@[simp]\ntheorem range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}ᶜ :=\n  Set.ext fun _ => exists_succAbove_eq_iff\n#align fin.range_succ_above Fin.range_succAbove\n\n@[simp]\ntheorem range_succ (n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ := by\n  rw [← succAbove_zero]\n  exact range_succAbove (0 : Fin (n + 1))\n#align fin.range_succ Fin.range_succ\n\n@[simp]\ntheorem exists_succ_eq_iff {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := by\n  convert @exists_succAbove_eq_iff n 0 x\n#align fin.exists_succ_eq_iff Fin.exists_succ_eq_iff\n\n/-- Given a fixed pivot `x : Fin (n + 1)`, `x.succAbove` is injective -/\ntheorem succAbove_right_injective {x : Fin (n + 1)} : Injective (succAbove x) :=\n  (succAbove x).injective\n#align fin.succ_above_right_injective Fin.succAbove_right_injective\n\n/-- Given a fixed pivot `x : Fin (n + 1)`, `x.succAbove` is injective -/\ntheorem succAbove_right_inj {x : Fin (n + 1)} : x.succAbove a = x.succAbove b ↔ a = b :=\n  succAbove_right_injective.eq_iff\n#align fin.succ_above_right_inj Fin.succAbove_right_inj\n\n/-- `succAbove` is injective at the pivot -/\ntheorem succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by\n  simpa [range_succAbove] using congr_arg (fun f : Fin n ↪o Fin (n + 1) => Set.range fᶜ) h\n#align fin.succ_above_left_injective Fin.succAbove_left_injective\n\n/-- `succAbove` is injective at the pivot -/\n@[simp]\ntheorem succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y :=\n  succAbove_left_injective.eq_iff\n#align fin.succ_above_left_inj Fin.succAbove_left_inj\n\n@[simp]\ntheorem zero_succAbove {n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := by\n  rfl\n#align fin.zero_succ_above Fin.zero_succAbove\n\n@[simp]\ntheorem succ_succAbove_zero {n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 :=\n  succAbove_below i.succ 0 (by simp only [castSucc_zero, succ_pos])\n#align fin.succ_succ_above_zero Fin.succ_succAbove_zero\n\n@[simp]\ntheorem succ_succAbove_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) :\n    i.succ.succAbove j.succ = (i.succAbove j).succ :=\n  (lt_or_ge (castSucc j) i).elim\n    (fun h => by\n      have h' : castSucc j.succ < i.succ := by simpa [lt_iff_val_lt_val] using h\n      ext\n      simp [succAbove_below _ _ h, succAbove_below _ _ h'])\n    fun h => by\n    have h' : i.succ ≤ castSucc j.succ := by simpa [le_iff_val_le_val] using h\n    ext\n    simp [succAbove_above _ _ h, succAbove_above _ _ h']\n#align fin.succ_succ_above_succ Fin.succ_succAbove_succ\n\n--@[simp] -- porting note: can be proved by `simp`\ntheorem one_succAbove_zero {n : ℕ} : (1 : Fin (n + 2)).succAbove 0 = 0 := by\n  rfl\n#align fin.one_succ_above_zero Fin.one_succAbove_zero\n\n/-- By moving `succ` to the outside of this expression, we create opportunities for further\nsimplification using `succAbove_zero` or `succ_succAbove_zero`. -/\n@[simp]\ntheorem succ_succAbove_one {n : ℕ} [NeZero n] (i : Fin (n + 1)) :\n    i.succ.succAbove 1 = (i.succAbove 0).succ := by\n  rw [← succ_zero_eq_one]\n  exact succ_succAbove_succ i 0\n#align fin.succ_succ_above_one Fin.succ_succAbove_one\n\n@[simp]\ntheorem one_succAbove_succ {n : ℕ} (j : Fin n) :\n    (1 : Fin (n + 2)).succAbove j.succ = j.succ.succ := by\n  have := succ_succAbove_succ 0 j\n  rwa [succ_zero_eq_one, zero_succAbove] at this\n#align fin.one_succ_above_succ Fin.one_succAbove_succ\n\n@[simp]\ntheorem one_succAbove_one {n : ℕ} : (1 : Fin (n + 3)).succAbove 1 = 2 := by\n  have := succ_succAbove_succ (0 : Fin (n + 2)) (0 : Fin (n + 2))\n  simp only [succ_zero_eq_one, val_zero, Nat.cast_zero, zero_succAbove, succ_one_eq_two] at this\n  exact this\n#align fin.one_succ_above_one Fin.one_succAbove_one\n\nend SuccAbove\n\nsection PredAbove\n\n/-- `predAbove p i` embeds `i : Fin (n+1)` into `Fin n` by subtracting one if `p < i`. -/\ndef predAbove (p : Fin n) (i : Fin (n + 1)) : Fin n :=\n  if h : castSucc p < i then i.pred (_root_.ne_of_lt (lt_of_le_of_lt (zero_le (castSucc p)) h)).symm\n  else i.castLt (lt_of_le_of_lt (le_of_not_lt h) p.2)\n#align fin.pred_above Fin.predAbove\n\ntheorem predAbove_right_monotone (p : Fin n) : Monotone p.predAbove := fun a b H => by\n  dsimp [predAbove]\n  split_ifs with ha hb hb\n  all_goals simp only [le_iff_val_le_val, coe_pred]\n  · exact pred_le_pred H\n  · calc\n      _ ≤ _ := Nat.pred_le _\n      _ ≤ _ := H\n  · simp at ha\n    exact le_pred_of_lt (lt_of_le_of_lt ha hb)\n  · exact H\n#align fin.pred_above_right_monotone Fin.predAbove_right_monotone\n\ntheorem predAbove_left_monotone (i : Fin (n + 1)) :\n    Monotone fun p => predAbove p i := fun a b H => by\n  dsimp [predAbove]\n  split_ifs with ha hb hb\n  · rfl\n  · exact pred_le _\n  · have : b < a := castSucc_lt_castSucc_iff.mpr (hb.trans_le (le_of_not_gt ha))\n    exact absurd H this.not_le\n  · rfl\n#align fin.pred_above_left_monotone Fin.predAbove_left_monotone\n\n/-- `castPred` embeds `i : Fin (n + 2)` into `Fin (n + 1)`\nby lowering just `last (n + 1)` to `last n`. -/\ndef castPred (i : Fin (n + 2)) : Fin (n + 1) :=\n  predAbove (last n) i\n#align fin.cast_pred Fin.castPred\n\n@[simp]\ntheorem castPred_zero : castPred (0 : Fin (n + 2)) = 0 :=\n  rfl\n#align fin.cast_pred_zero Fin.castPred_zero\n\n@[simp]\ntheorem castPred_one : castPred (1 : Fin (n + 2)) = 1 := by\n  cases n\n  · rfl\n  · rfl\n#align fin.cast_pred_one Fin.castPred_one\n\n@[simp]\ntheorem predAbove_zero {i : Fin (n + 2)} (hi : i ≠ 0) : predAbove 0 i = i.pred hi := by\n  dsimp [predAbove]\n  rw [dif_pos]\n  simp only [castSucc_zero]\n  exact (pos_iff_ne_zero _).mpr hi\n#align fin.pred_above_zero Fin.predAbove_zero\n\n@[simp]\ntheorem castPred_last : castPred (last (n + 1)) = last n :=\n  eq_of_veq (by simp [castPred, predAbove, castSucc_lt_last])\n#align fin.cast_pred_last Fin.castPred_last\n\n--Porting note: removing @[simp]. `castPred_mk'` has `simp` attribute instead\ntheorem castPred_mk (n i : ℕ) (h : i < n + 1) : castPred ⟨i, lt_succ_of_lt h⟩ = ⟨i, h⟩ := by\n  have : ¬castSucc (last n) < ⟨i, lt_succ_of_lt h⟩ := by\n    simpa [lt_iff_val_lt_val] using le_of_lt_succ h\n  simp [castPred, predAbove, this]\n#align fin.cast_pred_mk Fin.castPred_mk\n\n--Porting note: new lemma\n@[simp]\ntheorem castPred_mk' (n i : ℕ) (h₁ : i < n + 2) (h₂ : i < n + 1) : castPred ⟨i, h₁⟩ = ⟨i, h₂⟩ :=\n  castPred_mk _ _ _\n\ntheorem coe_castPred {n : ℕ} (a : Fin (n + 2)) (hx : a < Fin.last _) :\n  (a.castPred : ℕ) = a := by\n  rcases a with ⟨a, ha⟩\n  rw [castPred_mk]\n  exact hx\n#align fin.coe_cast_pred Fin.coe_castPred\n\ntheorem predAbove_below (p : Fin (n + 1)) (i : Fin (n + 2)) (h : i ≤ castSucc p) :\n    p.predAbove i = i.castPred := by\n  have : i ≤ castSucc (last n) := h.trans p.le_last\n  simp [predAbove, castPred, h.not_lt, this.not_lt]\n#align fin.pred_above_below Fin.predAbove_below\n\n@[simp]\ntheorem predAbove_last : predAbove (Fin.last n) = castPred :=\n  rfl\n#align fin.pred_above_last Fin.predAbove_last\n\ntheorem predAbove_last_apply (i : Fin n) : predAbove (Fin.last n) i = i.castPred := by\n  rw [predAbove_last]\n#align fin.pred_above_last_apply Fin.predAbove_last_apply\n\ntheorem predAbove_above (p : Fin n) (i : Fin (n + 1)) (h : castSucc p < i) :\n    p.predAbove i = i.pred ((castSucc p).zero_le.trans_lt h).ne.symm := by simp [predAbove, h]\n#align fin.pred_above_above Fin.predAbove_above\n\ntheorem castPred_monotone : Monotone (@castPred n) :=\n  predAbove_right_monotone (last _)\n#align fin.cast_pred_monotone Fin.castPred_monotone\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]\ntheorem succAbove_predAbove {p : Fin n} {i : Fin (n + 1)} (h : i ≠ castSucc p) :\n    p.castSucc.succAbove (p.predAbove i) = i := by\n  dsimp [predAbove, succAbove]\n  rcases p with ⟨p, _⟩\n  rcases i with ⟨i, _⟩\n  cases' lt_or_le i p with H H\n  · rw [dif_neg]\n    rw [if_pos]\n    rfl\n    exact H\n    simp\n    apply le_of_lt H\n  · rw [dif_pos]\n    rw [if_neg]\n    · simp\n    · simp only [pred, Fin.mk_lt_mk, not_lt]\n      exact Nat.le_pred_of_lt (h.symm.lt_of_le H)\n    · exact lt_of_le_of_ne H h.symm\n#align fin.succ_above_pred_above Fin.succAbove_predAbove\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]\ntheorem predAbove_succAbove (p : Fin n) (i : Fin n) :\n    p.predAbove ((castSucc p).succAbove i) = i := by\n  dsimp [predAbove, succAbove]\n  rcases p with ⟨p, _⟩\n  rcases i with ⟨i, _⟩\n  dsimp\n  split_ifs with h₁ h₂ h₃\n  · simp only [← val_fin_lt, not_lt] at h₁ h₂\n    exact (lt_le_antisymm h₁ (le_of_lt h₂)).elim\n  · rfl\n  · rfl\n  · simp only [← val_fin_lt, not_lt] at h₁ h₃\n    contradiction\n#align fin.pred_above_succ_above Fin.predAbove_succAbove\n\ntheorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0)\n    (ha' := a.castSucc_ne_zero_iff.mpr ha) : castSucc (a.pred ha) = (castSucc a).pred ha' := by\n  cases a\n  rfl\n#align fin.cast_succ_pred_eq_pred_cast_succ Fin.castSucc_pred_eq_pred_castSucc\n\n/-- `pred` commutes with `succAbove`. -/\ntheorem pred_succAbove_pred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0)\n    (hk := succAbove_ne_zero ha hb) :\n    (a.pred ha).succAbove (b.pred hb) = (a.succAbove b).pred hk := by\n  obtain hbelow | habove := lt_or_le (castSucc b) a\n  -- `rwa` uses them\n  · rw [Fin.succAbove_below]\n    · rwa [castSucc_pred_eq_pred_castSucc, Fin.pred_inj, Fin.succAbove_below]\n    · rwa [castSucc_pred_eq_pred_castSucc, pred_lt_pred_iff]\n  · rw [Fin.succAbove_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.succAbove_above]\n    · rwa [castSucc_pred_eq_pred_castSucc, Fin.pred_le_pred_iff]\n#align fin.pred_succ_above_pred Fin.pred_succAbove_pred\n\n/-- `succ` commutes with `predAbove`. -/\n@[simp]\ntheorem succ_predAbove_succ {n : ℕ} (a : Fin n) (b : Fin (n + 1)) :\n    a.succ.predAbove b.succ = (a.predAbove b).succ := by\n  obtain h₁ | h₂ := lt_or_le (castSucc a) b\n  · rw [Fin.predAbove_above _ _ h₁, Fin.succ_pred, Fin.predAbove_above, Fin.pred_succ]\n    simpa only [lt_iff_val_lt_val, coe_castSucc, val_succ, add_lt_add_iff_right] using\n      h₁\n  · cases' n with n\n    · exfalso\n      exact not_lt_zero' a.is_lt\n    · rw [Fin.predAbove_below a b h₂,\n        Fin.predAbove_below a.succ b.succ\n          (by\n            simpa only [le_iff_val_le_val, val_succ, coe_castSucc, add_le_add_iff_right] using h₂)]\n      ext\n      have h₀ : (b : ℕ) < n + 1 := by\n        simp only [le_iff_val_le_val, coe_castSucc] at h₂\n        simpa only [lt_succ_iff] using h₂.trans a.is_le\n      have h₁ : (b.succ : ℕ) < n + 2 := by\n        rw [← Nat.succ_lt_succ_iff] at h₀\n        simpa only [val_succ] using h₀\n      simp only [coe_castPred b h₀, coe_castPred b.succ h₁, val_succ]\n#align fin.succ_pred_above_succ Fin.succ_predAbove_succ\n\n@[simp]\ntheorem castPred_castSucc (i : Fin (n + 1)) : castPred (castSucc i) = i := by\n  simp [castPred, predAbove, not_lt.mpr (le_last i)]\n#align fin.cast_pred_cast_succ Fin.castPred_castSucc\n\ntheorem castSucc_castPred {i : Fin (n + 2)} (h : i < last (n + 1)) : castSucc i.castPred = i := by\n  rw [castPred, predAbove, dif_neg]\n  · simp [Fin.eq_iff_veq]\n  · exact h.not_le\n#align fin.cast_succ_cast_pred Fin.castSucc_castPred\n\ntheorem coe_castPred_le_self (i : Fin (n + 2)) : (i.castPred : ℕ) ≤ i := by\n  rcases i.le_last.eq_or_lt with (rfl | h)\n  · simp\n  · rw [castPred, predAbove, dif_neg]\n    · simp\n    · simpa [lt_iff_val_lt_val, le_iff_val_le_val, lt_succ_iff] using h\n#align fin.coe_cast_pred_le_self Fin.coe_castPred_le_self\n\ntheorem coe_castPred_lt_iff {i : Fin (n + 2)} : (i.castPred : ℕ) < i ↔ i = Fin.last _ := by\n  rcases i.le_last.eq_or_lt with (rfl | H)\n  · simp\n  · simp only [_root_.ne_of_lt H]\n    rw [← castSucc_castPred H]\n    simp\n#align fin.coe_cast_pred_lt_iff Fin.coe_castPred_lt_iff\n\ntheorem lt_last_iff_coe_castPred {i : Fin (n + 2)} :\n    i < Fin.last _ ↔ (i.castPred : ℕ) = i := by\n  rcases i.le_last.eq_or_lt with (rfl | H)\n  · simp\n  · simp only [H]\n    rw [← castSucc_castPred H]\n    simp\n#align fin.lt_last_iff_coe_cast_pred Fin.lt_last_iff_coe_castPred\n\nend PredAbove\n\n/-- `min n m` as an element of `Fin (m + 1)` -/\ndef clamp (n m : ℕ) : Fin (m + 1) :=\n  Nat.cast <| min n m\n#align fin.clamp Fin.clamp\n\n@[simp]\ntheorem coe_clamp (n m : ℕ) : (clamp n m : ℕ) = min n m :=\n  Nat.mod_eq_of_lt <| Nat.lt_succ_iff.mpr <| min_le_right _ _\n#align fin.coe_clamp Fin.coe_clamp\n\n@[simp]\ntheorem coe_ofNat_eq_mod (m n : ℕ) [NeZero m] :\n    ((n : Fin m) : ℕ) = n % m :=\n  rfl\n#align fin.coe_of_nat_eq_mod Fin.coe_ofNat_eq_mod\n\nsection Mul\n\n/-!\n### mul\n-/\n\ntheorem val_mul {n : ℕ} : ∀ a b : Fin n, (a * b).val = a.val * b.val % n\n  | ⟨_, _⟩, ⟨_, _⟩ => rfl\n#align fin.val_mul Fin.val_mul\n\ntheorem coe_mul {n : ℕ} : ∀ a b : Fin n, ((a * b : Fin n) : ℕ) = a * b % n\n  | ⟨_, _⟩, ⟨_, _⟩ => rfl\n#align fin.coe_mul Fin.coe_mul\n\nprotected theorem mul_one [NeZero n] (k : Fin n) : k * 1 = k := by\n  cases' n with n\n  · simp\n  cases n\n  · simp [fin_one_eq_zero]\n  simp [eq_iff_veq, mul_def, mod_eq_of_lt (is_lt k)]\n#align fin.mul_one Fin.mul_one\n\nprotected theorem mul_comm (a b : Fin n) : a * b = b * a :=\n  Fin.eq_of_veq <| by rw [mul_def, mul_def, mul_comm]\n#align fin.mul_comm Fin.mul_comm\n\n\nprotected theorem one_mul [NeZero n] (k : Fin n) : (1 : Fin n) * k = k := by\n  rw [Fin.mul_comm, Fin.mul_one]\n#align fin.one_mul Fin.one_mul\n\nprotected theorem mul_zero [NeZero n] (k : Fin n) : k * 0 = 0 := by simp [eq_iff_veq, mul_def]\n#align fin.mul_zero Fin.mul_zero\n\nprotected theorem zero_mul [NeZero n] (k : Fin n) : (0 : Fin n) * k = 0 := by\n  simp [eq_iff_veq, mul_def]\n#align fin.zero_mul Fin.zero_mul\n\nend Mul\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/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7700143816100667}}
{"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.real.basic \n\n/-! Defining the plane ℝ² \n\nThis file defines the plane and equips it with the usual addition and scalar multiplication. \n\nSome tactics that would be useful in the remainder:\n\ncases : splits a structure into its component, e.g. if v is a pair of real numbers, cases v will split it \n        into its first component v_x and its second component v_y. \nsimp : The simplifyer. Can be very good in simplifying things it is trained on. The challenge is to train it \n       correctly. (Part of tidy.)\next : The standard tactic to prove more complicated things are equal by splitting it into components. For \n      example, it is already trained to prove that two functions f and g are equal if and only if they agree \n      whenever applied to elements, i.e. f x = g x for all x, or that two subsets U and V of a set X are equal\n      if and only if they have the same elements. (Part of tidy.)\nring : Let's you solve standard equations in rings. \n-/\n\nstructure plane : Type :=\n(x : ℝ) (y : ℝ) \n\nnamespace plane\n\n/- We want to use the standard notation ℝ² for the real plane. -/\nnotation `ℝ²` := plane\n\n/- We want to be able to use the ext tactic to prove when two vectors are equal by comparing their components. -/\n@[ext] theorem ext {v w : ℝ²}\n  (hx : v.x = w.x) (hy : v.y = w.y) : v = w :=\nbegin\n  cases v with vx vy,\n  cases w with wx wy,\n  simp * at *,\nend\n\n/- Now let's define the addition on ℝ² like we are used to. This is done so we can write v + w for vectors v \n  and w in ℝ² without having to specify how they are actually defined. -/\ninstance has_add_plane : has_add ℝ² := ⟨λ v w, ⟨v.x + w.x, v.y + w.y⟩⟩\n\n/- As I said, the simplifyer has to be trained to know things - even if they are trivial. -/\n@[simp] lemma add_x (v w : ℝ²) : (v + w).x = v.x + w.x := rfl\n@[simp] lemma add_y (v w : ℝ²) : (v + w).y = v.y + w.y := rfl\n\nlemma add_assoc (u v w : ℝ²) : u + v + w = u + (v + w) :=\nbegin\n  ext;\n  simp;\n  ring,\nend\n\nlemma add_comm (v w : ℝ²) : v + w = w + v :=\nbegin\n  ext;\n  simp;\n  ring,\nend\n\n/- We want to give at least one example of a vector in ℝ², the zero vector. -/\ndef zero_vector : ℝ² := ⟨0,0⟩\n\n/- In mathematics, it is common to write 0_V for the zero vector of a vector space V, sometimes one even \n  omits the subscript V. We want to be able to use the same abuse of notation in Lean. (With the difference \n  that it should always be clear to Lean what specific 0 we are talking about.)-/\ninstance : has_zero ℝ² := ⟨zero_vector⟩ \n\n/- Again some self-evident lemmas for the simplifyer. -/\n@[simp] lemma zero_x : (0 : ℝ²).x = 0 := rfl\n@[simp] lemma zero_y : (0 : ℝ²).y = 0 := rfl\n\n@[simp] lemma add_zero (v : ℝ²) : v + 0 = v :=\nbegin\n  ext;\n  simp,\nend\n\n@[simp] lemma zero_add (v : ℝ²) : 0 + v = v :=\nbegin\n  ext;\n  simp,\nend\n\n/- Let's define the negation of a vector. -/\ninstance : has_neg ℝ² := ⟨λ v, ⟨-v.x, -v.y⟩⟩\n\n@[simp] lemma neg_x (v : ℝ²) : (-v).x = -v.x := rfl\n@[simp] lemma neg_y (v : ℝ²) : (-v).y = -v.y := rfl\n\n@[simp] lemma add_neg_self (v : ℝ²) : v + -v = 0 :=\nbegin\n  ext;\n  simp,\nend \n\n@[simp] lemma neg_add_self (v : ℝ²) : -v + v = 0 :=\nbegin\n  ext;\n  simp,\nend\n\n/- We also want to define subtraction and scalar multiplication. -/\ninstance : has_sub ℝ² := ⟨λ v w, v + (-w)⟩\n\ninstance : has_scalar ℝ ℝ² := ⟨λ a v, ⟨a * v.x, a * v.y⟩⟩ \n\n@[simp] lemma smul_x (a : ℝ) (v : ℝ²) : (a • v).x = a * v.x := rfl\n@[simp] lemma smul_y (a : ℝ) (v : ℝ²) : (a • v).y = a * v.y := rfl\n\nlemma smul_assoc (a b : ℝ) (v : ℝ²) : (a * b) • v = a • (b • v) :=\nbegin\n  ext;\n  simp;\n  ring,\nend \n\n@[simp] lemma one_smul (v : ℝ²) : (1 : ℝ) • v = v :=\nbegin\n  ext;\n  simp,\nend   \n\n@[simp] lemma smul_add (a : ℝ) (v w : ℝ²) : a • (v + w) = a • v + a • w :=\nbegin\n  ext;\n  simp;\n  ring,\nend \n\n@[simp] lemma add_smul (a b : ℝ) (v : ℝ²) : (a + b) • v = a • v + b • v :=\nbegin\n  ext;\n  simp;\n  ring,\nend\n\nend plane", "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/sheet01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7700004078749575}}
{"text": "variables (α:Type) (p q :α → Prop)\n/-Question-/\nexample: (∀x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\niff.intro\n(assume h: (∀ x,p x ∧ q x), and.intro (assume h1 : α, (h h1).left) (assume h2 : α, (h h2).right))\n(assume h: (∀ x, p x) ∧ (∀ x, q x), assume h1 : α, and.intro (h.left h1) (h.right h1))\n\nexample: (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\nassume h1: (∀ x, p x → q x), assume h2: (∀ x, p x),assume h3: α, (h1 h3) (h2 h3)\n\nexample: (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\nassume h: (∀ x, p x) ∨ (∀ x, q x),assume x : α,\nor.elim h (assume h1 : ∀ x, p x, or.inl (h1 x)) (assume h2 : ∀ x, q x, or.inr (h2 x))\n\n/-Question-/\nvariables (men : Type) (barber : men)\nvariable  (shaves : men → men → Prop)\n\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\nhave h1 : shaves barber barber ↔ ¬shaves barber barber, from (h barber),\nhave h2 : ¬shaves barber barber, from (assume h3 : shaves barber barber, absurd h3 (h1.mp h3)),\nfalse.elim (h2 (h1.mpr h2))\n\n/-Question-/\nnamespace hidden\n\ndef divides (m n : ℕ) : Prop := ∃ k, m * k = n\ninstance : has_dvd nat := ⟨divides⟩\ndef even (n : ℕ) : Prop := 2 ∣ n\n\ndef prime (n : ℕ) : Prop := ∀ m, (m ∣ n) → (m=1) ∨ (m=n) \ndef infinitely_many_primes : Prop := ∀ n, ∃ m, (m > n) ∧ prime m\ndef Fermat_number (n : ℕ) : Prop := ∃ m:nat, n=2^(2^m) + 1\ndef Fermat_prime (n : ℕ) : Prop := prime n ∧ Fermat_number n\ndef infinitely_many_Fermat_primes : Prop := ∀ n, ∃ m,(m > n) ∧ Fermat_prime m\ndef goldbach_conjecture : Prop := ∀ n, (n > 2) → ∃ p q, (p + q = n) ∧ prime p ∧ prime q\ndef Goldbach's_weak_conjecture : Prop := ∀ n, ¬even n ∧ (n > 5) → ∃ p p1 p2, (p + p1 + p2 = n) ∧ prime p ∧ prime p1 ∧ prime p2\ndef Fermat's_last_theorem : Prop := ∀ n, (n > 2) → ¬∃ a b c, a^n + b^n = c^n ∧ (a > 0) ∧ (b > 0) ∧ (c > 0)\n\nend hidden\n\n", "meta": {"author": "enharsha", "repo": "hello-world", "sha": "ef81d688af1aed47ffadf6662b80db5d9eba587d", "save_path": "github-repos/lean/enharsha-hello-world", "path": "github-repos/lean/enharsha-hello-world/hello-world-ef81d688af1aed47ffadf6662b80db5d9eba587d/tutorial 3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7700004067836305}}
{"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.basic\nimport data.multiset.nat_antidiagonal\n\n/-!\n# Antidiagonals in ℕ × ℕ as finsets\n\nThis file defines the antidiagonals of ℕ × ℕ 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 : ℕ) : finset (ℕ × ℕ) :=\n⟨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] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :\n  x ∈ antidiagonal n ↔ 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 : ℕ) : (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 : ℕ} :\n  antidiagonal (n + 1) = insert (0, n + 1) ((antidiagonal n).map\n  (function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ (function.embedding.refl _))) :=\nbegin\n  apply eq_of_veq,\n  rw [insert_val_of_not_mem, map_val],\n  {apply multiset.nat.antidiagonal_succ},\n  { intro con, rcases mem_map.1 con with ⟨⟨a,b⟩, ⟨h1, h2⟩⟩,\n    simp only [prod.mk.inj_iff, function.embedding.coe_prod_map, prod.map_mk] at h2,\n    apply nat.succ_ne_zero a h2.1, }\nend\n\nlemma map_swap_antidiagonal {n : ℕ} :\n  (antidiagonal n).map ⟨prod.swap, prod.swap_right_inverse.injective⟩ = antidiagonal n :=\nbegin\n  ext,\n  simp only [exists_prop, mem_map, mem_antidiagonal, prod.exists],\n  rw add_comm,\n  split,\n  { rintro ⟨b, c, ⟨rfl, rfl⟩⟩,\n    simp },\n  { rintro rfl,\n    use [a.snd, a.fst],\n    simp }\nend\n\n/-- A point in the antidiagonal is determined by its first co-ordinate. -/\nlemma antidiagonal_congr {n : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)\n  (hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=\nbegin\n  refine ⟨congr_arg prod.fst, (λ h, prod.ext h ((add_right_inj q.fst).mp _))⟩,\n  rw mem_antidiagonal at hp hq,\n  rw [hq, ← h, hp],\nend\n\nlemma antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.1 ≤ 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 : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.2 ≤ n :=\nbegin\n  rw le_iff_exists_add,\n  use kl.1,\n  rwa [mem_antidiagonal, eq_comm, add_comm] at hlk\nend\n\nsection equiv_prod\n\n/-- The disjoint union of antidiagonals `Σ (n : ℕ), antidiagonal n` is equivalent to the product\n    `ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps] def sigma_antidiagonal_equiv_prod : (Σ (n : ℕ), antidiagonal n) ≃ ℕ × ℕ :=\n{ to_fun := λ x, x.2,\n  inv_fun := λ x, ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩,\n  left_inv :=\n    begin\n      rintros ⟨n, ⟨k, l⟩, h⟩,\n      rw mem_antidiagonal at h,\n      exact sigma.subtype_ext h rfl,\n    end,\n  right_inv := λ x, rfl }\n\nend equiv_prod\n\nend nat\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/data/finset/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8633916222765627, "lm_q1q2_score": 0.7699821778368918}}
{"text": "-- * Level 1\nexample (P Q : Prop) (p : P) (q : Q) : P ∧ Q :=\n\n\nbegin\n\nsplit,\nexact p,\nexact q\n\nend\n\n\n-- * Level 2\n\nlemma and_symm (P Q : Prop) : P ∧ Q → Q ∧ P :=\n\nbegin\n\nintro h,\ncases h with p q,\nsplit,\nexact q,\nexact p\nend\n\n-- * Level 3\nlemma and_trans (P Q R : Prop) : P ∧ Q → Q ∧ R → P ∧ R :=\n\n\nbegin\n\nintros h q,\ncases h,\ncases q,\nsplit,\nexact h_left,\nexact q_right\n\nend\n-- * Level 4\nlemma iff_trans (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\n\n\nbegin\nintros h g,\ncases h with hpq hqp,\ncases g with gpr grp,\nsplit,\nintro p,\nexact gpr(hpq(p)),\nintro r,\nexact hqp(grp(r))\nend\n-- * Level 5\n\nlemma iff_trans2 (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\n\nbegin\nintros h g,\ncases h with hpq hqp,\ncases g with gpr grp,\nsplit,\nintro p,\nexact gpr(hpq(p)),\nintro r,\nexact hqp(grp(r))\n\nend\n-- * Level 6\nexample (P Q : Prop) : Q → (P ∨ Q) :=\n\nbegin\nintro g,\nright,\nexact g\nend\n\n-- * Level 7\n\nlemma or_symm (P Q : Prop) : P ∨ Q → Q ∨ P :=\n\nbegin\n\nintro h,\ncases h with p q,\nright,\nexact p,\nleft,\nexact q\n\n\nend\n\n-- * Level 8\nlemma and_or_distrib_left (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) :=\n\n\nbegin\nsplit,\nintro h,\ncases h with hp hqor,\ncases hqor with q r,\nleft,\nsplit,\nexact hp,\nexact q,\nright,\nsplit,\nexact hp,\nexact r,\n\nintro g,\nsplit,\ncases g with pq pr,\ncases pq with p q,\nexact p,\ncases pr with p r,\nexact p,\ncases g with pq pr,\nleft,\ncases pq with p q,\nexact q,\nright,\ncases pr with p r,\nexact r\n\nend\n-- * Level 9\nimport tactic.tauto\n\n\nlemma contra (P Q : Prop) : (P ∧ ¬ P) → Q :=\n\n\nbegin\n\nintro h,\nexfalso,\ncases h with p p2,\napply p2,\nexact p\n\n\nend\n\n-- * Level 10\nimport tactic.tauto\nlocal attribute [instance, priority 10] classical.prop_decidable -- we are mathematicians\nlemma contrapositive2 (P Q : Prop) : (¬ Q → ¬ P) → (P → Q) :=\n\nbegin\n\nby_cases p : P; by_cases q : Q,\nrepeat {cc}\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/advanced_proposition_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.7699655153809616}}
{"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-/\nimport analysis.inner_product_space.projection\nimport analysis.normed_space.lp_space\nimport analysis.inner_product_space.pi_L2\n\n/-!\n# Hilbert sum of a family of inner product spaces\n\nGiven a family `(G : ι → Type*) [Π i, inner_product_space 𝕜 (G i)]` of inner product spaces, this\nfile equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those\ndependent functions `f : Π i, G i` for which `∑' i, ‖f i‖ ^ 2`, the sum of the norms-squared, is\nsummable.  This construction is sometimes called the *Hilbert sum* of the family `G`.  By choosing\n`G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction.\n\nWe also define a *predicate* `is_hilbert_sum 𝕜 G V`, where `V : Π i, G i →ₗᵢ[𝕜] E`, expressing that\n`V` is an `orthogonal_family` and that the associated map `lp G 2 →ₗᵢ[𝕜] E` is surjective.\n\n## Main definitions\n\n* `orthogonal_family.linear_isometry`: Given a Hilbert space `E`, a family `G` of inner product\n  spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with\n  mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G`\n  into `E`.\n\n* `is_hilbert_sum`: Given a Hilbert space `E`, a family `G` of inner product\n  spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`,\n  `is_hilbert_sum 𝕜 G V` means that `V` is an `orthogonal_family` and that the above\n  linear isometry is surjective.\n\n* `is_hilbert_sum.linear_isometry_equiv`: If a Hilbert space `E` is a Hilbert sum of the\n  inner product spaces `G i` with respect to the family `V : Π i, G i →ₗᵢ[𝕜] E`, then the\n  corresponding `orthogonal_family.linear_isometry` can be upgraded to a `linear_isometry_equiv`.\n\n* `hilbert_basis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single\n  field `hilbert_basis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert\n  sum of `ι` copies of `𝕜`).  This parallels the definition of `basis`, in `linear_algebra.basis`,\n  as an isomorphism of an `R`-module with `ι →₀ R`.\n\n* `hilbert_basis.has_coe_to_fun`: More conventionally a Hilbert basis is thought of as a family\n  `ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness).  We obtain\n  this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image\n  under `b.repr` of `lp.single 2 i (1:𝕜)`.  This parallels the definition `basis.has_coe_to_fun` in\n  `linear_algebra.basis`.\n\n* `hilbert_basis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors\n  in `E` whose span is dense.  This parallels the definition `basis.mk` in `linear_algebra.basis`.\n\n* `hilbert_basis.mk_of_orthogonal_eq_bot`: Make a Hilbert basis of `E` from an orthonormal family\n  `v : ι → E` of vectors in `E` whose span has trivial orthogonal complement.\n\n## Main results\n\n* `lp.inner_product_space`: Construction of the inner product space instance on the Hilbert sum\n  `lp G 2`.  Note that from the file `analysis.normed_space.lp_space`, the space `lp G 2` already\n  held a normed space instance (`lp.normed_space`), and if each `G i` is a Hilbert space (i.e.,\n  complete), then `lp G 2` was already known to be complete (`lp.complete_space`).  So the work\n  here is to define the inner product and show it is compatible.\n\n* `orthogonal_family.range_linear_isometry`: Given a family `G` of inner product spaces and a family\n  `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal\n  images, the image of the embedding `orthogonal_family.linear_isometry` of the Hilbert sum of `G`\n  into `E` is the closure of the span of the images of the `G i`.\n\n* `hilbert_basis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of\n  `x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`.\n\n* `hilbert_basis.has_sum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be\n  expressed as the \"infinite linear combination\" `∑' i, b.repr x i • b i` of the basis vectors\n  `b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`.\n\n* `exists_hilbert_basis`: A Hilbert space admits a Hilbert basis.\n\n## Keywords\n\nHilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism\n-/\n\nopen is_R_or_C submodule filter\nopen_locale big_operators nnreal ennreal classical complex_conjugate topology\n\nnoncomputable theory\n\nvariables {ι : Type*}\nvariables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*}\nvariables [normed_add_comm_group E] [inner_product_space 𝕜 E] [cplt : complete_space E]\nvariables {G : ι → Type*} [Π i, normed_add_comm_group (G i)] [Π i, inner_product_space 𝕜 (G i)]\nlocal notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y\n\nnotation `ℓ²(`ι`, `𝕜`)` := lp (λ i : ι, 𝕜) 2\n\n/-! ### Inner product space structure on `lp G 2` -/\n\nnamespace lp\n\nlemma summable_inner (f g : lp G 2) : summable (λ i, ⟪f i, g i⟫) :=\nbegin\n  -- Apply the Direct Comparison Test, comparing with ∑' i, ‖f i‖ * ‖g i‖ (summable by Hölder)\n  refine summable_of_norm_bounded (λ i, ‖f i‖ * ‖g i‖) (lp.summable_mul _ f g) _,\n  { rw real.is_conjugate_exponent_iff; norm_num },\n  intros i,\n  -- Then apply Cauchy-Schwarz pointwise\n  exact norm_inner_le_norm _ _,\nend\n\ninstance : inner_product_space 𝕜 (lp G 2) :=\n{ inner := λ f g, ∑' i, ⟪f i, g i⟫,\n  norm_sq_eq_inner := λ f, begin\n    calc ‖f‖ ^ 2 = ‖f‖ ^ (2:ℝ≥0∞).to_real : by norm_cast\n    ... = ∑' i, ‖f i‖ ^ (2:ℝ≥0∞).to_real : lp.norm_rpow_eq_tsum _ f\n    ... = ∑' i, ‖f i‖ ^ 2 : by norm_cast\n    ... = ∑' i, re ⟪f i, f i⟫ : by simp only [@norm_sq_eq_inner 𝕜]\n    ... = re (∑' i, ⟪f i, f i⟫) : (is_R_or_C.re_clm.map_tsum _).symm\n    ... = _ : by congr,\n    { norm_num },\n    { exact summable_inner f f },\n  end,\n  conj_symm := λ f g, begin\n    calc conj _ = conj ∑' i, ⟪g i, f i⟫ : by congr\n    ... = ∑' i, conj ⟪g i, f i⟫ : is_R_or_C.conj_cle.map_tsum\n    ... = ∑' i, ⟪f i, g i⟫ : by simp only [inner_conj_symm]\n    ... = _ : by congr,\n  end,\n  add_left := λ f₁ f₂ g, begin\n    calc _ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ : _\n    ... = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) :\n          by simp only [inner_add_left, pi.add_apply, coe_fn_add]\n    ... = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ : tsum_add _ _\n    ... = _ : by congr,\n    { congr, },\n    { exact summable_inner f₁ g },\n    { exact summable_inner f₂ g }\n  end,\n  smul_left := λ f g c, begin\n    calc _ = ∑' i, ⟪c • f i, g i⟫ : _\n    ... = ∑' i, conj c * ⟪f i, g i⟫ : by simp only [inner_smul_left]\n    ... = conj c * ∑' i, ⟪f i, g i⟫ : tsum_mul_left\n    ... = _ : _,\n    { simp only [coe_fn_smul, pi.smul_apply] },\n    { congr },\n  end,\n  .. lp.normed_space }\n\nlemma inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ := rfl\n\nlemma has_sum_inner (f g : lp G 2) : has_sum (λ i, ⟪f i, g i⟫) ⟪f, g⟫ :=\n(summable_inner f g).has_sum\n\nlemma inner_single_left (i : ι) (a : G i) (f : lp G 2) : ⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ :=\nbegin\n  refine (has_sum_inner (lp.single 2 i a) f).unique _,\n  convert has_sum_ite_eq i ⟪a, f i⟫,\n  ext j,\n  rw lp.single_apply,\n  split_ifs,\n  { subst h },\n  { simp }\nend\n\nlemma inner_single_right (i : ι) (a : G i) (f : lp G 2) : ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ :=\nby simpa [inner_conj_symm] using congr_arg conj (@inner_single_left _ 𝕜 _ _ _ _ i a f)\n\nend lp\n\n/-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/\n\nnamespace orthogonal_family\nvariables {V : Π i, G i →ₗᵢ[𝕜] E} (hV : orthogonal_family 𝕜 G V)\n\ninclude cplt hV\n\nprotected lemma summable_of_lp (f : lp G 2) : summable (λ i, V i (f i)) :=\nbegin\n  rw hV.summable_iff_norm_sq_summable,\n  convert (lp.mem_ℓp f).summable _,\n  { norm_cast },\n  { norm_num }\nend\n\n/-- A mutually orthogonal family of subspaces of `E` induce a linear isometry from `lp 2` of the\nsubspaces into `E`. -/\nprotected def linear_isometry : lp G 2 →ₗᵢ[𝕜] E :=\n{ to_fun := λ f, ∑' i, V i (f i),\n  map_add' := λ f g, by simp only [tsum_add (hV.summable_of_lp f) (hV.summable_of_lp g),\n    lp.coe_fn_add, pi.add_apply, linear_isometry.map_add],\n  map_smul' := λ c f, by simpa only [linear_isometry.map_smul, pi.smul_apply, lp.coe_fn_smul]\n    using tsum_const_smul c (hV.summable_of_lp f),\n  norm_map' := λ f, begin\n    classical, -- needed for lattice instance on `finset ι`, for `filter.at_top_ne_bot`\n    have H : 0 < (2:ℝ≥0∞).to_real := by norm_num,\n    suffices : ‖∑' (i : ι), V i (f i)‖ ^ ((2:ℝ≥0∞).to_real) = ‖f‖ ^ ((2:ℝ≥0∞).to_real),\n    { exact real.rpow_left_inj_on H.ne' (norm_nonneg _) (norm_nonneg _) this },\n    refine tendsto_nhds_unique  _ (lp.has_sum_norm H f),\n    convert (hV.summable_of_lp f).has_sum.norm.rpow_const (or.inr H.le),\n    ext s,\n    exact_mod_cast (hV.norm_sum f s).symm,\n  end }\n\nprotected lemma linear_isometry_apply (f : lp G 2) :\n  hV.linear_isometry f = ∑' i, V i (f i) :=\nrfl\n\nprotected lemma has_sum_linear_isometry (f : lp G 2) :\n  has_sum (λ i, V i (f i)) (hV.linear_isometry f) :=\n(hV.summable_of_lp f).has_sum\n\n@[simp] protected lemma linear_isometry_apply_single {i : ι} (x : G i) :\n  hV.linear_isometry (lp.single 2 i x) = V i x :=\nbegin\n  rw [hV.linear_isometry_apply, ← tsum_ite_eq i (V i x)],\n  congr,\n  ext j,\n  rw [lp.single_apply],\n  split_ifs,\n  { subst h },\n  { simp }\nend\n\n@[simp] protected \n\n/-- The canonical linear isometry from the `lp 2` of a mutually orthogonal family of subspaces of\n`E` into E, has range the closure of the span of the subspaces. -/\nprotected lemma range_linear_isometry [Π i, complete_space (G i)] :\n  hV.linear_isometry.to_linear_map.range = (⨆ i, (V i).to_linear_map.range).topological_closure :=\nbegin\n  refine le_antisymm _ _,\n  { rintros x ⟨f, rfl⟩,\n    refine mem_closure_of_tendsto (hV.has_sum_linear_isometry f) (eventually_of_forall _),\n    intros s,\n    rw set_like.mem_coe,\n    refine sum_mem _,\n    intros i hi,\n    refine mem_supr_of_mem i _,\n    exact linear_map.mem_range_self _ (f i) },\n  { apply topological_closure_minimal,\n    { refine supr_le _,\n      rintros i x ⟨x, rfl⟩,\n      use lp.single 2 i x,\n      exact hV.linear_isometry_apply_single x },\n    exact hV.linear_isometry.isometry.uniform_inducing.is_complete_range.is_closed }\nend\n\nend orthogonal_family\n\nsection is_hilbert_sum\n\nvariables (𝕜 G) (V : Π i, G i →ₗᵢ[𝕜] E) (F : ι → submodule 𝕜 E)\ninclude cplt\n\n/-- Given a family of Hilbert spaces `G : ι → Type*`, a Hilbert sum of `G` consists of a Hilbert\nspace `E` and an orthogonal family `V : Π i, G i →ₗᵢ[𝕜] E` such that the induced isometry\n`Φ : lp G 2 → E` is surjective.\n\nKeeping in mind that `lp G 2` is \"the\" external Hilbert sum of `G : ι → Type*`, this is analogous\nto `direct_sum.is_internal`, except that we don't express it in terms of actual submodules. -/\n@[protect_proj] structure is_hilbert_sum : Prop := of_surjective ::\n(orthogonal_family : orthogonal_family 𝕜 G V)\n(surjective_isometry : function.surjective (orthogonal_family.linear_isometry))\n\nvariables {𝕜 G V}\n\n/-- If `V : Π i, G i →ₗᵢ[𝕜] E` is an orthogonal family such that the supremum of the ranges of\n`V i` is dense, then `(E, V)` is a Hilbert sum of `G`. -/\nlemma is_hilbert_sum.mk [Π i, complete_space $ G i]\n  (hVortho : orthogonal_family 𝕜 G V)\n  (hVtotal : ⊤ ≤ (⨆ i, (V i).to_linear_map.range).topological_closure) :\n  is_hilbert_sum 𝕜 G V :=\n{ orthogonal_family := hVortho,\n  surjective_isometry :=\n  begin\n    rw [←linear_isometry.coe_to_linear_map],\n    exact linear_map.range_eq_top.mp (eq_top_iff.mpr $\n      hVtotal.trans_eq hVortho.range_linear_isometry.symm)\n  end }\n\n/-- This is `orthogonal_family.is_hilbert_sum` in the case of actual inclusions from subspaces. -/\nlemma is_hilbert_sum.mk_internal [Π i, complete_space $ F i]\n  (hFortho : orthogonal_family 𝕜 (λ i, F i) (λ i, (F i).subtypeₗᵢ))\n  (hFtotal : ⊤ ≤ (⨆ i, (F i)).topological_closure) :\n  is_hilbert_sum 𝕜 (λ i, F i) (λ i, (F i).subtypeₗᵢ) :=\nis_hilbert_sum.mk hFortho (by simpa [subtypeₗᵢ_to_linear_map, range_subtype] using hFtotal)\n\n/-- *A* Hilbert sum `(E, V)` of `G` is canonically isomorphic to *the* Hilbert sum of `G`,\ni.e `lp G 2`.\n\nNote that this goes in the opposite direction from `orthogonal_family.linear_isometry`. -/\nnoncomputable def is_hilbert_sum.linear_isometry_equiv (hV : is_hilbert_sum 𝕜 G V) :\n  E ≃ₗᵢ[𝕜] lp G 2 :=\nlinear_isometry_equiv.symm $\nlinear_isometry_equiv.of_surjective\nhV.orthogonal_family.linear_isometry hV.surjective_isometry\n\n/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,\na vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`. -/\nprotected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply\n  (hV : is_hilbert_sum 𝕜 G V) (w : lp G 2) :\n  hV.linear_isometry_equiv.symm w = ∑' i, V i (w i) :=\nby simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.linear_isometry_apply]\n\n/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,\na vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`, and this\nsum indeed converges. -/\nprotected lemma is_hilbert_sum.has_sum_linear_isometry_equiv_symm\n  (hV : is_hilbert_sum 𝕜 G V) (w : lp G 2) :\n  has_sum (λ i, V i (w i)) (hV.linear_isometry_equiv.symm w) :=\nby simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.has_sum_linear_isometry]\n\n/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and\n`lp G 2`, an \"elementary basis vector\" in `lp G 2` supported at `i : ι` is the image of the\nassociated element in `E`. -/\n@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply_single\n  (hV : is_hilbert_sum 𝕜 G V) {i : ι} (x : G i) :\n  hV.linear_isometry_equiv.symm (lp.single 2 i x) = V i x :=\nby simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.linear_isometry_apply_single]\n\n/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and\n`lp G 2`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of\nelements of `E`. -/\n@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply_dfinsupp_sum_single\n  (hV : is_hilbert_sum 𝕜 G V) (W₀ : Π₀ (i : ι), G i) :\n  hV.linear_isometry_equiv.symm (W₀.sum (lp.single 2)) = (W₀.sum (λ i, V i)) :=\nby simp [is_hilbert_sum.linear_isometry_equiv,\n  orthogonal_family.linear_isometry_apply_dfinsupp_sum_single]\n\n/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and\n`lp G 2`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of\nelements of `E`. -/\n@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_apply_dfinsupp_sum_single\n  (hV : is_hilbert_sum 𝕜 G V) (W₀ : Π₀ (i : ι), G i) :\n  (hV.linear_isometry_equiv (W₀.sum (λ i, V i)) : Π i, G i) = W₀ :=\nbegin\n  rw ← hV.linear_isometry_equiv_symm_apply_dfinsupp_sum_single,\n  rw linear_isometry_equiv.apply_symm_apply,\n  ext i,\n  simp [dfinsupp.sum, lp.single_apply] {contextual := tt},\nend\n\n/-- Given a total orthonormal family `v : ι → E`, `E` is a Hilbert sum of `λ i : ι, 𝕜` relative to\nthe family of linear isometries `λ i, λ k, k • v i`. -/\nlemma orthonormal.is_hilbert_sum {v : ι → E} (hv : orthonormal 𝕜 v)\n  (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :\n  is_hilbert_sum 𝕜 (λ i : ι, 𝕜) (λ i, linear_isometry.to_span_singleton 𝕜 E (hv.1 i)) :=\nis_hilbert_sum.mk hv.orthogonal_family\nbegin\n  convert hsp,\n  simp [← linear_map.span_singleton_eq_range, ← submodule.span_Union],\nend\n\nlemma submodule.is_hilbert_sum_orthogonal (K : submodule 𝕜 E) [hK : complete_space K] :\n  is_hilbert_sum 𝕜 (λ b, ↥(cond b K Kᗮ)) (λ b, (cond b K Kᗮ).subtypeₗᵢ) :=\nbegin\n  haveI : Π b, complete_space ↥(cond b K Kᗮ),\n  { intro b,\n    cases b;\n    exact orthogonal.complete_space K <|> assumption },\n  refine is_hilbert_sum.mk_internal _ K.orthogonal_family_self _,\n  refine le_trans _ (submodule.le_topological_closure _),\n  rw [supr_bool_eq, cond, cond],\n  refine codisjoint.top_le _,\n  exact submodule.is_compl_orthogonal_of_complete_space.codisjoint\nend\n\nend is_hilbert_sum\n\n/-! ### Hilbert bases -/\n\nsection\nvariables (ι) (𝕜) (E)\n\n/-- A Hilbert basis on `ι` for an inner product space `E` is an identification of `E` with the `lp`\nspace `ℓ²(ι, 𝕜)`. -/\nstructure hilbert_basis := of_repr :: (repr : E ≃ₗᵢ[𝕜] ℓ²(ι, 𝕜))\n\nend\n\nnamespace hilbert_basis\n\ninstance {ι : Type*} : inhabited (hilbert_basis ι 𝕜 ℓ²(ι, 𝕜)) :=\n⟨of_repr (linear_isometry_equiv.refl 𝕜 _)⟩\n\n/-- `b i` is the `i`th basis vector. -/\ninstance : has_coe_to_fun (hilbert_basis ι 𝕜 E) (λ _, ι → E) :=\n{ coe := λ b i, b.repr.symm (lp.single 2 i (1:𝕜)) }\n\n@[simp] protected lemma repr_symm_single (b : hilbert_basis ι 𝕜 E) (i : ι) :\n  b.repr.symm (lp.single 2 i (1:𝕜)) = b i :=\nrfl\n\n@[simp] protected lemma repr_self (b : hilbert_basis ι 𝕜 E) (i : ι) :\n  b.repr (b i) = lp.single 2 i (1:𝕜) :=\nby rw [← b.repr_symm_single, linear_isometry_equiv.apply_symm_apply]\n\nprotected lemma repr_apply_apply (b : hilbert_basis ι 𝕜 E) (v : E) (i : ι) :\n  b.repr v i = ⟪b i, v⟫ :=\nbegin\n  rw [← b.repr.inner_map_map (b i) v, b.repr_self, lp.inner_single_left],\n  simp,\nend\n\n@[simp] protected lemma orthonormal (b : hilbert_basis ι 𝕜 E) : orthonormal 𝕜 b :=\nbegin\n  rw orthonormal_iff_ite,\n  intros i j,\n  rw [← b.repr.inner_map_map (b i) (b j), b.repr_self, b.repr_self, lp.inner_single_left,\n    lp.single_apply],\n  simp,\nend\n\nprotected lemma has_sum_repr_symm (b : hilbert_basis ι 𝕜 E) (f : ℓ²(ι, 𝕜)) :\n  has_sum (λ i, f i • b i) (b.repr.symm f) :=\nbegin\n  suffices H : (λ (i : ι), f i • b i) =\n    (λ (b_1 : ι), (b.repr.symm.to_continuous_linear_equiv) ((λ (i : ι), lp.single 2 i (f i)) b_1)),\n  { rw H,\n    have : has_sum (λ (i : ι), lp.single 2 i (f i)) f := lp.has_sum_single ennreal.two_ne_top f,\n    exact (↑(b.repr.symm.to_continuous_linear_equiv) : ℓ²(ι, 𝕜) →L[𝕜] E).has_sum this },\n  ext i,\n  apply b.repr.injective,\n  letI : normed_space 𝕜 ↥(lp (λ i : ι, 𝕜) 2) := by apply_instance,\n  have : lp.single 2 i (f i * 1) = f i • lp.single 2 i 1 := lp.single_smul 2 i (1:𝕜) (f i),\n  rw mul_one at this,\n  rw [linear_isometry_equiv.map_smul, b.repr_self, ← this,\n    linear_isometry_equiv.coe_to_continuous_linear_equiv],\n  exact (b.repr.apply_symm_apply (lp.single 2 i (f i))).symm,\nend\n\nprotected lemma has_sum_repr (b : hilbert_basis ι 𝕜 E) (x : E) :\n  has_sum (λ i, b.repr x i • b i) x :=\nby simpa using b.has_sum_repr_symm (b.repr x)\n\n@[simp] protected lemma dense_span (b : hilbert_basis ι 𝕜 E) :\n  (span 𝕜 (set.range b)).topological_closure = ⊤ :=\nbegin\n  classical,\n  rw eq_top_iff,\n  rintros x -,\n  refine mem_closure_of_tendsto (b.has_sum_repr x) (eventually_of_forall _),\n  intros s,\n  simp only [set_like.mem_coe],\n  refine sum_mem _,\n  rintros i -,\n  refine smul_mem _ _ _,\n  exact subset_span ⟨i, rfl⟩\nend\n\nprotected lemma has_sum_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :\n  has_sum (λ i, ⟪x, b i⟫ * ⟪b i, y⟫) ⟪x, y⟫ :=\nbegin\n  convert (b.has_sum_repr y).mapL (innerSL _ x),\n  ext i,\n  rw [innerSL_apply, b.repr_apply_apply, inner_smul_right, mul_comm]\nend\n\nprotected lemma summable_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :\n  summable (λ i, ⟪x, b i⟫ * ⟪b i, y⟫) :=\n(b.has_sum_inner_mul_inner x y).summable\n\nprotected lemma tsum_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :\n  ∑' i, ⟪x, b i⟫ * ⟪b i, y⟫ = ⟪x, y⟫ :=\n(b.has_sum_inner_mul_inner x y).tsum_eq\n\n-- Note : this should be `b.repr` composed with an identification of `lp (λ i : ι, 𝕜) p` with\n-- `pi_Lp p (λ i : ι, 𝕜)` (in this case with `p = 2`), but we don't have this yet (July 2022).\n/-- A finite Hilbert basis is an orthonormal basis. -/\nprotected def to_orthonormal_basis [fintype ι] (b : hilbert_basis ι 𝕜 E) :\n  orthonormal_basis ι 𝕜 E :=\northonormal_basis.mk b.orthonormal\nbegin\n  refine eq.ge _,\n  have := (span 𝕜 (finset.univ.image b : set E)).closed_of_finite_dimensional,\n  simpa only [finset.coe_image, finset.coe_univ, set.image_univ, hilbert_basis.dense_span] using\n    this.submodule_topological_closure_eq.symm\nend\n\n@[simp] lemma coe_to_orthonormal_basis [fintype ι] (b : hilbert_basis ι 𝕜 E) :\n  (b.to_orthonormal_basis : ι → E) = b :=\northonormal_basis.coe_mk _ _\n\nprotected lemma has_sum_orthogonal_projection {U : submodule 𝕜 E}\n  [complete_space U] (b : hilbert_basis ι 𝕜 U) (x : E) :\n  has_sum (λ i, ⟪(b i : E), x⟫ • b i) (orthogonal_projection U x) :=\nby simpa only [b.repr_apply_apply, inner_orthogonal_projection_eq_of_mem_left]\n  using b.has_sum_repr (orthogonal_projection U x)\n\nlemma finite_spans_dense (b : hilbert_basis ι 𝕜 E) :\n  (⨆ J : finset ι, span 𝕜 (J.image b : set E)).topological_closure = ⊤ :=\neq_top_iff.mpr $ b.dense_span.ge.trans\nbegin\n  simp_rw [← submodule.span_Union],\n  exact topological_closure_mono (span_mono $ set.range_subset_iff.mpr $\n    λ i, set.mem_Union_of_mem {i} $ finset.mem_coe.mpr $ finset.mem_image_of_mem _ $\n    finset.mem_singleton_self i)\nend\n\nvariables {v : ι → E} (hv : orthonormal 𝕜 v)\ninclude hv cplt\n\n/-- An orthonormal family of vectors whose span is dense in the whole module is a Hilbert basis. -/\nprotected def mk (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :\n  hilbert_basis ι 𝕜 E :=\nhilbert_basis.of_repr $\n(hv.is_hilbert_sum hsp).linear_isometry_equiv\n\nlemma _root_.orthonormal.linear_isometry_equiv_symm_apply_single_one (h i) :\n  (hv.is_hilbert_sum h).linear_isometry_equiv.symm (lp.single 2 i 1) = v i :=\nby rw [is_hilbert_sum.linear_isometry_equiv_symm_apply_single,\n  linear_isometry.to_span_singleton_apply, one_smul]\n\n@[simp] protected lemma coe_mk (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :\n  ⇑(hilbert_basis.mk hv hsp) = v :=\nby apply (funext $ orthonormal.linear_isometry_equiv_symm_apply_single_one hv hsp)\n\n/-- An orthonormal family of vectors whose span has trivial orthogonal complement is a Hilbert\nbasis. -/\nprotected def mk_of_orthogonal_eq_bot (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) : hilbert_basis ι 𝕜 E :=\nhilbert_basis.mk hv\n(by rw [← orthogonal_orthogonal_eq_closure, ← eq_top_iff, orthogonal_eq_top_iff, hsp])\n\n@[simp] protected lemma coe_of_orthogonal_eq_bot_mk (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) :\n  ⇑(hilbert_basis.mk_of_orthogonal_eq_bot hv hsp) = v :=\nhilbert_basis.coe_mk hv _\n\nomit hv\n\n-- Note : this should be `b.repr` composed with an identification of `lp (λ i : ι, 𝕜) p` with\n-- `pi_Lp p (λ i : ι, 𝕜)` (in this case with `p = 2`), but we don't have this yet (July 2022).\n/-- An orthonormal basis is an Hilbert basis. -/\nprotected def _root_.orthonormal_basis.to_hilbert_basis [fintype ι] (b : orthonormal_basis ι 𝕜 E) :\n  hilbert_basis ι 𝕜 E :=\nhilbert_basis.mk b.orthonormal $\nby simpa only [← orthonormal_basis.coe_to_basis, b.to_basis.span_eq, eq_top_iff]\n  using @subset_closure E _ _\n\n@[simp] lemma _root_.orthonormal_basis.coe_to_hilbert_basis [fintype ι]\n  (b : orthonormal_basis ι 𝕜 E) : (b.to_hilbert_basis : ι → E) = b :=\nhilbert_basis.coe_mk _ _\n\n/-- A Hilbert space admits a Hilbert basis extending a given orthonormal subset. -/\nlemma _root_.orthonormal.exists_hilbert_basis_extension\n  {s : set E} (hs : orthonormal 𝕜 (coe : s → E)) :\n  ∃ (w : set E) (b : hilbert_basis w 𝕜 E), s ⊆ w ∧ ⇑b = (coe : w → E) :=\nlet ⟨w, hws, hw_ortho, hw_max⟩ := exists_maximal_orthonormal hs in\n⟨ w,\n  hilbert_basis.mk_of_orthogonal_eq_bot hw_ortho\n    (by simpa [maximal_orthonormal_iff_orthogonal_complement_eq_bot hw_ortho] using hw_max),\n  hws,\n  hilbert_basis.coe_of_orthogonal_eq_bot_mk _ _ ⟩\n\nvariables (𝕜 E)\n\n/-- A Hilbert space admits a Hilbert basis. -/\nlemma _root_.exists_hilbert_basis :\n  ∃ (w : set E) (b : hilbert_basis w 𝕜 E), ⇑b = (coe : w → E) :=\nlet ⟨w, hw, hw', hw''⟩ := (orthonormal_empty 𝕜 E).exists_hilbert_basis_extension in ⟨w, hw, hw''⟩\n\nend hilbert_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/analysis/inner_product_space/l2_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222396, "lm_q2_score": 0.8198933337131077, "lm_q1q2_score": 0.7699001866018437}}
{"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 linear_algebra.free_module.finite.rank\n\n/-!\n# Rank of matrices\n\nThe rank of a matrix `A` is defined to be the rank of range of the linear map corresponding to `A`.\nThis definition does not depend on the choice of basis, see `matrix.rank_eq_finrank_range_to_lin`.\n\n## Main declarations\n\n* `matrix.rank`: the rank of a matrix\n\n## TODO\n\n* Show that `matrix.rank` is equal to the row-rank and column-rank\n* Generalize away from fields\n\n-/\n\nopen_locale matrix\n\nnamespace matrix\n\nopen finite_dimensional\n\nvariables {m n o K : Type*} [m_fin : fintype m] [fintype n] [fintype o]\nvariables [decidable_eq n] [decidable_eq o] [field K]\nvariables (A : matrix m n K)\n\n/-- The rank of a matrix is the rank of its image. -/\nnoncomputable def rank : ℕ := finrank K A.to_lin'.range\n\n@[simp] lemma rank_one : rank (1 : matrix n n K) = fintype.card n :=\nby rw [rank, to_lin'_one, linear_map.range_id, finrank_top, module.free.finrank_pi]\n\n@[simp] lemma rank_zero : rank (0 : matrix n n K) = 0 :=\nby rw [rank, linear_equiv.map_zero, linear_map.range_zero, finrank_bot]\n\nlemma rank_le_card_width : A.rank ≤ fintype.card n :=\nbegin\n  convert le_of_add_le_left (A.to_lin'.finrank_range_add_finrank_ker).le,\n  exact (module.free.finrank_pi K).symm,\nend\n\nlemma rank_le_width {m n : ℕ} (A : matrix (fin m) (fin n) K) : A.rank ≤ n :=\nA.rank_le_card_width.trans $ (fintype.card_fin n).le\n\nlemma rank_mul_le (B : matrix n o K) : (A ⬝ B).rank ≤ A.rank :=\nbegin\n  refine linear_map.finrank_le_finrank_of_injective (submodule.of_le_injective _),\n  rw [to_lin'_mul],\n  exact linear_map.range_comp_le_range _ _,\nend\n\nlemma rank_unit (A : (matrix n n K)ˣ) :\n  (A : matrix n n K).rank = fintype.card n :=\nbegin\n  refine le_antisymm (rank_le_card_width A) _,\n  have := rank_mul_le (A : matrix n n K) (↑A⁻¹ : matrix n n K),\n  rwa [← mul_eq_mul, ← units.coe_mul, mul_inv_self, units.coe_one, rank_one] at this,\nend\n\nlemma rank_of_is_unit (A : matrix n n K) (h : is_unit A) :\n  A.rank = fintype.card n :=\nby { obtain ⟨A, rfl⟩ := h, exact rank_unit A }\n\ninclude m_fin\n\nlemma rank_eq_finrank_range_to_lin\n  {M₁ M₂ : Type*} [add_comm_group M₁] [add_comm_group M₂]\n  [module K M₁] [module K M₂] (v₁ : basis m K M₁) (v₂ : basis n K M₂) :\n  A.rank = finrank K (to_lin v₂ v₁ A).range :=\nbegin\n  let e₁ := (pi.basis_fun K m).equiv v₁ (equiv.refl _),\n  let e₂ := (pi.basis_fun K n).equiv v₂ (equiv.refl _),\n  have range_e₂ : (e₂ : (n → K) →ₗ[K] M₂).range = ⊤,\n  { rw linear_map.range_eq_top, exact e₂.surjective },\n  refine linear_equiv.finrank_eq (e₁.of_submodules _ _ _),\n  rw [← linear_map.range_comp, ← linear_map.range_comp_of_range_eq_top (to_lin v₂ v₁ A) range_e₂],\n  congr' 1,\n  apply linear_map.pi_ext', rintro i, apply linear_map.ext_ring,\n  have aux₁ := to_lin_self (pi.basis_fun K n) (pi.basis_fun K m) A i,\n  have aux₂ := basis.equiv_apply (pi.basis_fun K n) i v₂,\n  rw [to_lin_eq_to_lin'] at aux₁,\n  rw [pi.basis_fun_apply, linear_map.coe_std_basis] at aux₁ aux₂,\n  simp only [linear_map.comp_apply, e₁, e₂, linear_equiv.coe_coe, equiv.refl_apply, aux₁, aux₂,\n    linear_map.coe_single, to_lin_self, linear_equiv.map_sum, linear_equiv.map_smul,\n    basis.equiv_apply],\nend\n\nlemma rank_le_card_height : A.rank ≤ fintype.card m :=\n(submodule.finrank_le _).trans (module.free.finrank_pi K).le\n\nomit m_fin\n\nlemma rank_le_height {m n : ℕ} (A : matrix (fin m) (fin n) K) : A.rank ≤ m :=\nA.rank_le_card_height.trans $ (fintype.card_fin m).le\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/data/matrix/rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7698908981365994}}
{"text": "-- Suma de desigualdades (en Lean)\n-- ===============================\n\n-- Demostrar si a, b, c y d son números reales tales que\n-- a ≤ b y c ≤ d, entonces a + c ≤ b + d.\n\nimport data.real.basic\n\nvariables (a b c d : ℝ)\n\n-- 1ª demostración\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nbegin\n  calc\n    a + c ≤ b + c : add_le_add_right hab c\n    ...   ≤ b + d : add_le_add_left hcd b,\nend\n\n-- 2ª demostración\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nbegin\n  have h1 : a + c ≤ b + c := \n    add_le_add_right hab c,\n  have h2 : b + c ≤ b + d :=\n    add_le_add_left hcd b,\n  show a + c ≤ b + d, \n    from le_trans h1 h2,\nend\n\n-- 3ª demostración\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nadd_le_add hab hcd\n\n-- 4ª demostración\nexample  \n  (hab : a ≤ b) \n  (hcd : c ≤ d) \n  : a + c ≤ b + d :=\nby linarith\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/Suma_de_desigualdades_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.7698723985004317}}
{"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 → Ab which is the left adjoint\nof the forgetful functor Ab → 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⁻¹*q⁻¹` -/\ndef commutator (G : Type u) [group G] : subgroup G :=\n  subgroup.normal_closure (set_of fun (x : G) => ∃ (p : G), ∃ (q : G), p * q * (p⁻¹) * (q⁻¹) = x)\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup -/\ndef abelianization (G : Type u) [group G] :=\n  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 →* abelianization G :=\n  monoid_hom.mk quotient_group.mk sorry sorry\n\n-- so far -- built Gᵃᵇ and proved it's an abelian group.\n\n-- defined `of : G → Gᵃᵇ`\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 →* A) : commutator G ≤ monoid_hom.ker f := sorry\n\n/-- If `f : G → 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 →* A) : abelianization G →* 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 →* A) (x : G) : 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 →* A) (φ : abelianization G →* A) (hφ : ∀ (x : G), coe_fn φ (coe_fn of x) = coe_fn f x) {x : abelianization G} : coe_fn φ x = coe_fn (lift f) x :=\n  quotient_group.induction_on x hφ\n\n/-- See note [partially-applied ext lemmas]. -/\ntheorem hom_ext {G : Type u} [group G] {A : Type v} [monoid A] (φ : abelianization G →* A) (ψ : abelianization G →* A) (h : monoid_hom.comp φ of = monoid_hom.comp ψ of) : φ = ψ := 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/abelianization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816422, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7698033591819501}}
{"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-/\nimport tactic.ring\n\n/-!\n# Identities\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 \"named\" commutative ring identities.\n-/\n\nvariables {R : Type*} [comm_ring R]\n{a b x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈ y₁ y₂ y₃ y₄ y₅ y₆ y₇ y₈ n : R}\n\n/--\nBrahmagupta-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₁^2 + x₂^2) * (y₁^2 + y₂^2) = (x₁*y₁ - x₂*y₂)^2 + (x₁*y₂ + x₂*y₁)^2 :=\nby ring\n\n/--\nBrahmagupta's identity, see <https://en.wikipedia.org/wiki/Brahmagupta%27s_identity>\n-/\ntheorem sq_add_mul_sq_mul_sq_add_mul_sq :\n  (x₁^2 + n*x₂^2) * (y₁^2 + n*y₂^2) = (x₁*y₁ - n*x₂*y₂)^2 + n*(x₁*y₂ + x₂*y₁)^2 :=\nby ring\n\n/--\nSophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.\n-/\ntheorem pow_four_add_four_mul_pow_four : a^4 + 4*b^4 = ((a - b)^2 + b^2) * ((a + b)^2 + b^2) :=\nby ring\n\n/--\nSophie 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) :=\nby ring\n\n/--\nEuler'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 : (x₁^2 + x₂^2 + x₃^2 + x₄^2) * (y₁^2 + y₂^2 + y₃^2 + y₄^2) =\n  (x₁*y₁ - x₂*y₂ - x₃*y₃ - x₄*y₄)^2 + (x₁*y₂ + x₂*y₁ + x₃*y₄ - x₄*y₃)^2 +\n  (x₁*y₃ - x₂*y₄ + x₃*y₁ + x₄*y₂)^2 + (x₁*y₄ + x₂*y₃ - x₃*y₂ + x₄*y₁)^2 :=\nby ring\n\n/--\nDegen'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 : (x₁^2 + x₂^2 + x₃^2 + x₄^2 + x₅^2 + x₆^2 + x₇^2 + x₈^2) *\n  (y₁^2 + y₂^2 + y₃^2 + y₄^2 + y₅^2 + y₆^2 + y₇^2 + y₈^2) =\n  (x₁*y₁ - x₂*y₂ - x₃*y₃ - x₄*y₄ - x₅*y₅ - x₆*y₆ - x₇*y₇ - x₈*y₈)^2 +\n  (x₁*y₂ + x₂*y₁ + x₃*y₄ - x₄*y₃ + x₅*y₆ - x₆*y₅ - x₇*y₈ + x₈*y₇)^2 +\n  (x₁*y₃ - x₂*y₄ + x₃*y₁ + x₄*y₂ + x₅*y₇ + x₆*y₈ - x₇*y₅ - x₈*y₆)^2 +\n  (x₁*y₄ + x₂*y₃ - x₃*y₂ + x₄*y₁ + x₅*y₈ - x₆*y₇ + x₇*y₆ - x₈*y₅)^2 +\n  (x₁*y₅ - x₂*y₆ - x₃*y₇ - x₄*y₈ + x₅*y₁ + x₆*y₂ + x₇*y₃ + x₈*y₄)^2 +\n  (x₁*y₆ + x₂*y₅ - x₃*y₈ + x₄*y₇ - x₅*y₂ + x₆*y₁ - x₇*y₄ + x₈*y₃)^2 +\n  (x₁*y₇ + x₂*y₈ + x₃*y₅ - x₄*y₆ - x₅*y₃ + x₆*y₄ + x₇*y₁ - x₈*y₂)^2 +\n  (x₁*y₈ - x₂*y₇ + x₃*y₆ + x₄*y₅ - x₅*y₄ - x₆*y₃ + x₇*y₂ + x₈*y₁)^2 :=\nby 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/group_power/identities.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693645535723, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7696869836600349}}
{"text": "-- BOTH:\nimport algebra.ring\nimport data.real.basic\nimport tactic\n\n/- TEXT:\n.. _proving_identities_in_algebraic_structures:\n\nProving Identities in Algebraic Structures\n------------------------------------------\n\n.. index:: ring (algebraic structure)\n\nMathematically, a ring consists of a collection of objects,\n:math:`R`, operations :math:`+` :math:`\\times`, and constants :math:`0`\nand :math:`1`, and an operation :math:`x \\mapsto -x` such that:\n\n* :math:`R` with :math:`+` is an *abelian group*, with :math:`0`\n  as the additive identity and negation as inverse.\n* Multiplication is associative with identity :math:`1`,\n  and multiplication distributes over addition.\n\nIn Lean, the collection of objects is represented as a *type*, ``R``.\nThe ring axioms are as follows:\nTEXT. -/\nsection\n-- QUOTE:\nvariables (R : Type*) [ring R]\n\n#check (add_assoc : ∀ a b c : R, a + b + c = a + (b + c))\n#check (add_comm : ∀ a b : R, a + b = b + a)\n#check (zero_add : ∀ a : R, 0 + a = a)\n#check (add_left_neg : ∀ a : R, -a + a = 0)\n#check (mul_assoc : ∀ a b c : R, a * b * c = a * (b * c))\n#check (mul_one : ∀ a : R, a * 1 = a)\n#check (one_mul : ∀ a : R, 1 * a = a)\n#check (mul_add : ∀ a b c : R, a * (b + c) = a * b + a * c)\n#check (add_mul : ∀ a b c : R, (a + b) * c = a * c + b * c)\n-- QUOTE.\nend\n\n/- TEXT:\nYou will learn more about the square brackets in the first line later,\nbut for the time being,\nsuffice it to say that the declaration gives us a type, ``R``,\nand a ring structure on ``R``.\nLean then allows us to use generic ring notation with elements of ``R``,\nand to make use of a library of theorems about rings.\n\nThe names of some of the theorems should look familiar:\nthey are exactly the ones we used to calculate with the real numbers\nin the last section.\nLean is good not only for proving things about concrete mathematical\nstructures like the natural numbers and the integers,\nbut also for proving things about abstract structures,\ncharacterized axiomatically, like rings.\nMoreover, Lean supports *generic reasoning* about\nboth abstract and concrete structures,\nand can be trained to recognized appropriate instances.\nSo any theorem about rings can be applied to concrete rings\nlike the integers, ``ℤ``, the rational numbers,  ``ℚ``,\nand the complex numbers ``ℂ``.\nIt can also be applied to any instance of an abstract\nstructure that extends rings,\nsuch as any *ordered ring* or any *field*.\n\n.. index:: commutative ring\n\nNot all important properties of the real numbers hold in an\narbitrary ring, however.\nFor example, multiplication on the real numbers\nis commutative,\nbut that does not hold in general.\nIf you have taken a course in linear algebra,\nyou will recognize that, for every :math:`n`,\nthe :math:`n` by :math:`n` matrices of real numbers\nform a ring in which commutativity usually fails. If we declare ``R`` to be a\n*commutative* ring, in fact, all the theorems\nin the last section continue to hold when we replace\n``ℝ`` by ``R``.\nTEXT. -/\nsection\n-- QUOTE:\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\n-- QUOTE.\nend\n\n/- TEXT:\nWe leave it to you to check that all the other proofs go through unchanged.\n\nThe goal of this section is to strengthen the skills\nyou have developed in the last section\nand apply them to reasoning axiomatically about rings.\nWe will start with the axioms listed above,\nand use them to derive other facts.\nMost of the facts we prove are already in ``mathlib``.\nWe will give the versions we prove the same names\nto help you learn the contents of the library\nas well as the naming conventions.\n\n.. index:: namespace, open, command ; open\n\nLean provides an organizational mechanism similar\nto those used in programming languages:\nwhen a definition or theorem ``foo`` is introduced in a *namespace*\n``bar``, its full name is ``bar.foo``.\nThe command ``open bar`` later *opens* the namespace,\nwhich allows us to use the shorter name ``foo``.\nTo avoid errors due to name clashes,\nin the next example we put our versions of the library\ntheorems in a new namespace called ``my_ring.``\n\nThe next example shows that we do not need ``add_zero`` or ``add_right_neg``\nas ring axioms, because they follow from the other axioms.\nTEXT. -/\n-- QUOTE:\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-- QUOTE.\n\n/- TEXT:\nThe net effect is that we can temporarily reprove a theorem in the library,\nand then go on using the library version after that.\nBut don't cheat!\nIn the exercises that follow, take care to use only the\ngeneral facts about rings that we have proved earlier in this section.\n\n(If you are paying careful attention, you may have noticed that we\nchanged the round brackets in ``(R : Type*)`` for\ncurly brackets in ``{R : Type*}``.\nThis declares ``R`` to be an *implicit argument*.\nWe will explain what this means in a moment,\nbut don't worry about it in the meanwhile.)\n\nHere is a useful theorem:\nTEXT. -/\n-- BOTH:\nnamespace my_ring\nvariables {R : Type*} [ring R]\n\n-- EXAMPLES:\n-- QUOTE:\ntheorem neg_add_cancel_left (a b : R) : -a + (a + b) = b :=\nby rw [←add_assoc, add_left_neg, zero_add]\n-- QUOTE.\n\n/- TEXT:\nProve the companion version:\nTEXT. -/\n/- Prove these: -/\n\n-- QUOTE:\ntheorem add_neg_cancel_right (a b : R) : (a + b) + -b = a :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem add_neg_cancel_rightαα (a b : R) : (a + b) + -b = a :=\nby rw [add_assoc, add_right_neg, add_zero]\n\n/- TEXT:\nUse these to prove the following:\nTEXT. -/\n-- QUOTE:\ntheorem add_left_cancel {a b c : R} (h : a + b = a + c) : b = c :=\nsorry\n\ntheorem add_right_cancel {a b c : R} (h : a + b = c + b) : a = c :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem add_left_cancelαα {a b c : R} (h : a + b = a + c) : b = c :=\nby rw [←neg_add_cancel_left a b, h, neg_add_cancel_left]\n\ntheorem add_right_cancelαα {a b c : R} (h : a + b = c + b) : a = c :=\nby rw [←add_neg_cancel_right a b, h, add_neg_cancel_right]\n\n/- TEXT:\nWith enough planning, you can do each of them with three rewrites.\n\n.. index:: implicit argument\n\nWe can now explain the use of the curly braces.\nImagine you are in a situation where you have ``a``, ``b``, and ``c``\nin your context,\nas well as a hypothesis ``h : a + b = a + c``,\nand you would like to draw the conclusion ``b = c``.\nIn Lean, you can apply a theorem to hypotheses and facts just\nthe same way that you can apply them to objects,\nso you might think that ``add_left_cancel a b c h`` is a\nproof of the fact ``b = c``.\nBut notice that explicitly writing ``a``, ``b``, and ``c``\nis redundant, because the hypothesis ``h`` makes it clear that\nthose are the objects we have in mind.\nIn this case, typing a few extra characters is not onerous,\nbut if we wanted to apply ``add_left_cancel`` to more complicated expressions,\nwriting them would be tedious.\nIn cases like these,\nLean allows us to mark arguments as *implicit*,\nmeaning that they are supposed to be left out and inferred by other means,\nsuch as later arguments and hypotheses.\nThe curly brackets in ``{a b c : R}`` do exactly that.\nSo, given the statement of the theorem above,\nthe correct expression is simply ``add_left_cancel h``.\n\nTo illustrate, let us show that ``a * 0 = 0``\nfollows from the ring axioms.\nTEXT. -/\n-- QUOTE:\ntheorem mul_zero (a : R) : a * 0 = 0 :=\nbegin\n  have h : a * 0 + a * 0 = a * 0 + 0,\n  { rw [←mul_add, add_zero, add_zero] },\n  rw add_left_cancel h\nend\n-- QUOTE.\n\n/- TEXT:\n.. index:: have, tactics ; have\n\nWe have used a new trick!\nIf you step through the proof,\nyou can see what is going on.\nThe ``have`` tactic introduces a new goal,\n``a * 0 + a * 0 = a * 0 + 0``,\nwith the same context as the original goal.\nIn the next line, we could have omitted the curly brackets,\nwhich serve as an inner ``begin ... end`` pair.\nUsing them promotes a modular style of proof:\nthe part of the proof inside the brackets establishes the goal\nthat was introduced by the ``have``.\nAfter that, we are back to proving the original goal,\nexcept a new hypothesis ``h`` has been added:\nhaving proved it, we are now free to use it.\nAt this point, the goal is exactly the result of ``add_left_cancel h``.\nWe could equally well have closed the proof with\n``apply add_left_cancel h`` or ``exact add_left_cancel h``.\n\nRemember that multiplication is not assumed to be commutative,\nso the following theorem also requires some work.\nTEXT. -/\n-- QUOTE:\ntheorem zero_mul (a : R) : 0 * a = 0 :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem zero_mulαα (a : R) : 0 * a = 0 :=\nbegin\n  have h : 0 * a + 0 * a = 0 * a + 0,\n  { rw [←add_mul, add_zero, add_zero] },\n  rw add_left_cancel h\nend\n\n/- TEXT:\nBy now, you should also be able replace each ``sorry`` in the next\nexercise with a proof,\nstill using only facts about rings that we have\nestablished in this section.\nTEXT. -/\n-- QUOTE:\ntheorem neg_eq_of_add_eq_zero {a b : R} (h : a + b = 0) : -a = b :=\nsorry\n\ntheorem eq_neg_of_add_eq_zero {a b : R} (h : a + b = 0) : a = -b :=\nsorry\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 :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem neg_eq_of_add_eq_zeroαα {a b : R} (h : a + b = 0) : -a = b :=\nby rw [←neg_add_cancel_left a b, h, add_zero]\n\ntheorem eq_neg_of_add_eq_zeroαα {a b : R} (h : a + b = 0) : a = -b :=\nbegin\n  symmetry,\n  apply neg_eq_of_add_eq_zero,\n  rw [add_comm, h]\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  apply neg_eq_of_add_eq_zero,\n  rw add_left_neg\nend\n\n-- BOTH:\nend my_ring\n\n/- TEXT:\nWe had to use the annotation ``(-0 : R)`` instead of ``0`` in the third theorem\nbecause without specifying ``R``\nit is impossible for Lean to infer which ``0`` we have in mind,\nand by default it would be interpreted as a natural number.\n\nIn Lean, subtraction in a ring is provably equal to\naddition of the additive inverse.\nTEXT. -/\n/- Examples. -/\n\nsection\nvariables {R : Type*} [ring R]\n\n-- QUOTE:\nexample (a b : R) : a - b = a + -b :=\nsub_eq_add_neg a b\n-- QUOTE.\n\nend\n\n/- TEXT:\nOn the real numbers, it is *defined* that way:\nTEXT. -/\n-- QUOTE:\nexample (a b : ℝ) : a - b = a + -b :=\nrfl\n\nexample (a b : ℝ) : a - b = a + -b :=\nby reflexivity\n-- QUOTE.\n\n/- TEXT:\n.. index:: rfl, reflexivity, tactics ; refl and reflexivity, definitional equality\n\nThe proof term ``rfl`` is short for ``reflexivity``.\nPresenting it as a proof of ``a - b = a + -b`` forces Lean\nto unfold the definition and recognize both sides as being the same.\nThe ``reflexivity`` tactic, which can be abbreviated as ``refl``,\ndoes the same.\nThis is an instance of what is known as a *definitional equality*\nin Lean's underlying logic.\nThis means that not only can one rewrite with ``sub_eq_add_neg``\nto replace ``a - b = a + -b``,\nbut in some contexts, when dealing with the real numbers,\nyou can use the two sides of the equation interchangeably.\nFor example, you now have enough information to prove the theorem\n``self_sub`` from the last section:\nTEXT. -/\n-- BOTH:\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\n\n-- EXAMPLES:\n-- QUOTE:\ntheorem self_sub (a : R) : a - a = 0 :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem self_subαα (a : R) : a - a = 0 :=\nby rw [sub_eq_add_neg, add_right_neg]\n\n/- TEXT:\nShow that you can prove this using ``rw``,\nbut if you replace the arbitrary ring ``R`` by\nthe real numbers, you can also prove it\nusing either ``apply`` or ``exact``.\n\nFor another example of definitional equality,\nLean knows that ``1 + 1 = 2`` holds in any ring.\nWith a bit of effort,\nyou can use that to prove the theorem ``two_mul`` from\nthe last section:\nTEXT. -/\n-- QUOTE:\nlemma one_add_one_eq_two : 1 + 1 = (2 : R) :=\nby refl\n\ntheorem two_mul (a : R) : 2 * a = a + a :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nlemma one_add_one_eq_twoαα : 1 + 1 = (2 : R) :=\nby refl\n\ntheorem two_mulαα (a : R) : 2 * a = a + a :=\nby rw [←one_add_one_eq_two, add_mul, one_mul]\n\n-- BOTH:\nend my_ring\n\n/- TEXT:\n.. index:: group (algebraic structure)\n\nWe close this section by noting that some of the facts about\naddition and negation that we established above do not\nneed the full strength of the ring axioms, or even\ncommutativity of addition. The weaker notion of a *group*\ncan be axiomatized as follows:\nTEXT. -/\nsection\n-- QUOTE:\nvariables (A : Type*) [add_group A]\n\n#check (add_assoc : ∀ a b c : A, a + b + c = a + (b + c))\n#check (zero_add : ∀ a : A, 0 + a = a)\n#check (add_left_neg : ∀ a : A, -a + a = 0)\n-- QUOTE.\nend\n\n/- TEXT:\nIt is conventional to use additive notation when\nthe group operation is commutative,\nand multiplicative notation otherwise.\nSo Lean defines a multiplicative version as well as the\nadditive version (and also their abelian variants,\n``add_comm_group`` and ``comm_group``).\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {G : Type*} [group G]\n\n-- EXAMPLES:\n#check (mul_assoc : ∀ a b c : G, a * b * c = a * (b * c))\n#check (one_mul : ∀ a : G, 1 * a = a)\n#check (mul_left_inv : ∀ a : G, a⁻¹ * a = 1)\n-- QUOTE.\n\n/- TEXT:\nIf you are feeling cocky, try proving the following facts about\ngroups, using only these axioms.\nYou will need to prove a number of helper lemmas along the way.\nThe proofs we have carried out in this section provide some hints.\nTEXT. -/\n-- BOTH:\nnamespace my_group\n\n-- EXAMPLES:\n-- QUOTE:\ntheorem mul_right_inv (a : G) : a * a⁻¹ = 1 :=\nsorry\n\ntheorem mul_one (a : G) : a * 1 = a :=\nsorry\n\ntheorem mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a ⁻¹ :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem mul_right_invαα (a : G) : a * a⁻¹ = 1 :=\nbegin\n  have h : (a * a⁻¹)⁻¹ * ((a * a⁻¹) * (a * a⁻¹)) = 1,\n  { rw [mul_assoc, ←mul_assoc a⁻¹ a, mul_left_inv, one_mul, mul_left_inv] },\n  rw [←h, ←mul_assoc, mul_left_inv, one_mul]\nend\n\ntheorem mul_oneαα (a : G) : a * 1 = a :=\nby rw [←mul_left_inv a, ←mul_assoc, mul_right_inv, one_mul]\n\ntheorem mul_inv_revαα (a b : G) : (a * b)⁻¹ = b⁻¹ * a ⁻¹ :=\nby rw [←one_mul (b⁻¹ * a⁻¹), ←mul_left_inv (a * b), mul_assoc, mul_assoc,\n        ←mul_assoc b b⁻¹, mul_right_inv, one_mul, mul_right_inv, mul_one]\n\n-- BOTH:\nend my_group\nend\n\n/- TEXT:\n.. index:: group (tactic), tactics ; group, tactics ; noncomm_ring, tactics ; abel\n\nExplicitly invoking those lemmas is tedious, so mathlib provides\ntactics similar to `ring` in order to cover most uses: `group`\nis for non-commutative multiplicative groups, `abel` for abelian\nadditive groups, and `noncomm_ring` for non-commutative groups.\nIt may seem odd that the algebraic structures are called\n`ring` and `comm_ring` while the tactics are named\n`noncomm_ring` and `ring`. This is partly for historical reasons,\nbut also for the convenience of using a shorter name for the\ntactic that deals with commutative rings, since it is used more often.\nTEXT. -/", "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/02_Basics/source_02_Proving_Identities_in_Algebraic_Structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.8705972583359806, "lm_q1q2_score": 0.7696421802690167}}
{"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, α, is reflexive, we\nmean that for any value, a, of type, α, _______.\n\nANSWER:  a = a\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    1 = 1\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:  reflexive, equals, 1 \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    begin\n        apply eq.refl 1,\n    end\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 : Prop := 2+2 = 4\n\ndef proof_two_plus_two_eq_four : two_plus_two_eq_four :=\n    begin\n        apply eq.refl 4,\n    end\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: zero is even and (2 + 0 = 2) → even 2\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α → Prop, where α 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 ℕ → 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 ∀ 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 : ℕ → Prop\n| pf_zero_is_even : (is_even 0)\n| pf_even_plus_two_is_even : \n    ∀ (n : ℕ), is_even n → 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    begin\n        apply pf_zero_is_even,\n    end\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 0 zero_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    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_zero_is_even,\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\ninductive is_odd : ℕ → Prop \n| one_odd : is_odd 1\n| two_plus_odd : ∀(n : ℕ), is_odd n → is_odd (nat.succ (nat.succ n))\n\n-- ANSWER\n\nopen is_odd\n\n-- ANSWER\nexample : is_odd 7 :=\n    begin\n        apply two_plus_odd,\n        apply two_plus_odd,\n        apply two_plus_odd,\n        apply one_odd,\n    end\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 : ℕ | 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 : ℕ, n : ℕ) | m = n }\n\nWe formalize binary relations as predicates with \n*two* arguments. The type of such a predicate in \nLean is thus α → β → Prop, where α and β 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 : ℕ → ℕ → Prop\n| mk : ∀ (n m : ℕ), n = m → 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 3 3 (eq.refl 3)\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    it will never be true that 3=5\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 {α : Type} (r : α → α → Prop) :=\n    ∀ (a : α), 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 : ℕ)\". Remember that to prove a ∀\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\n    unfold reflexive,\n    assume (a : ℕ),\n    apply id_nat_relation.mk,\n    apply eq.refl a,\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\ndef symmetric {α : Type} (r : α → α → Prop) :=\n    ∀(a b: α), r a b → r b a\n\ndef transitive {α : Type} (r : α → α → Prop) :=\n    ∀(a b c : α), (r a b ∧ r b c) → r a c\n\n\nend hw8", "meta": {"author": "derekjohnsonva", "repo": "CS2102", "sha": "b3f507d4be824a2511838a1054d04fc9aef3304c", "save_path": "github-repos/lean/derekjohnsonva-CS2102", "path": "github-repos/lean/derekjohnsonva-CS2102/CS2102-b3f507d4be824a2511838a1054d04fc9aef3304c/ExamPractice/hw8_intro_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7696201933708078}}
{"text": "import tactic\nimport data.real.basic\nimport number_theory.padics\nimport data.int.gcd\n\n/-!\n## Exercises about numbers and casts\n-/\n\n/-!\n## First exercises\nThese first examples are just to get you comfortable with\n`norm_num`, `norm_cast`, and friends.\n-/\n\n\nexample : 12345 < 67890 :=\nbegin\n  norm_num,\nend\n\nexample {α : Type} [linear_ordered_field α] : 123 + 45 < 67890/3 :=\nbegin\n  norm_num,\nend\n\nexample : nat.prime 17 :=\nbegin\n  norm_num,\nend\n\n-- prove either this or its negation!\nexample : ¬ 7/3 > 2 :=\nbegin\n  norm_num,\nend\n\n\nexample (x : ℝ) (hx : x < 50*50) : x < 25*100 :=\nbegin\n  norm_num at *,\n  assumption,\nend\n\nexample (x : ℤ) (hx : (x : ℝ) < 25*100) : x < 25*100 :=\nbegin\n  norm_cast at *,\n  assumption,\nend\n\nexample (x : ℤ) (hx : (x : ℝ) < 2500) : x < 25*100 :=\nbegin\n  norm_cast at *,\n  norm_num,\n  assumption,\nend\n\nexample (p q r : ℕ) (h : r < p - q) (hpq : q ≤ p) : (r : ℝ) < p - q :=\nbegin\n  norm_cast at *,\n  from h,\nend\n\nexample (p q r : ℕ) (hr : r < p + 2 - p) : (r : ℤ) < 5 :=\nbegin\n  norm_cast at *,\n  simp at hr,\n  from lt_trans hr (by norm_num : 2 < 5),\nend\n\n\n/-!\n## Exercise 2\nThis comes from the development of the p-adic numbers.\n`norm_cast` is very useful here, since we need to talk about values in\nℕ, ℤ, ℚ, ℚ_p, and ℤ_p.\nWe've done some work to get you started. You might look for the lemmas:\n-/\n\nopen padic_val_rat\n\n#check zpow_le_of_le\n#check zpow_nonneg\n#check of_int_multiplicity\n\n\nexample {p n : ℕ} (hp : p.prime) {z : ℤ} (hd : ↑(p^n) ∣ z) : padic_norm p z ≤ ↑p ^ (-n : ℤ) :=\nbegin\n  -- This lemma will be useful later in the proof.\n  -- Ignore the \"inst\" argument; just use `apply aux_lemma` when you need it!\n  -- Note that we haven't finished it. Fill in that final sorry.\n  have aux_lemma : ∀ inst, (n : ℤ) ≤ (multiplicity ↑p z).get inst,\n  { intro,\n    norm_cast,\n    rw [← enat.coe_le_coe, enat.coe_get],\n    apply multiplicity.le_multiplicity_of_pow_dvd,\n    norm_cast, from hd, },\n\n  unfold padic_norm, split_ifs with hz hz,\n  { apply zpow_nonneg,\n    norm_cast,\n    apply zero_le,},\n  { apply zpow_le_of_le,\n    norm_cast, apply le_trans, from (by norm_num : 1 ≤ 2),\n    apply nat.prime.two_le hp, \n    apply neg_le_neg, rw of_int_multiplicity,\n    apply aux_lemma, \n    from nat.prime.ne_one hp,\n    norm_cast at hz,\n    }\nend\n\n\n\n\n\n/-!\n## Exercise 3\nThis seems like a very natural way to write the theorem\n\"If `a` and `b` are coprime, then there are coefficients `u` and `v` such that `u*a + v*b = 1`.\"\nBut I've made a mistake! What did I do wrong? Correct the statement of the theorem and prove it.\nI've started you off with a lemma that will be useful.\nYou might find the `specialize` tactic to be handy as well:\nif you have `h : ∀ (x y : T), R x y` and `a, b : T` in the context, then\n`specialize h a b` will change the type of `h` to `R a b`.\n-/\n\nexample (a b : ℕ) (h : nat.coprime a b) : ∃ u v : ℤ, u * a + v * b = 1 :=\nbegin\n  have := nat.gcd_eq_gcd_ab,\n  specialize this a b, \n  unfold nat.coprime at h,\n  rw h at this,\n  norm_cast at this,\n  use [a.gcd_a b, a.gcd_b b],\n  rw this, ring,\nend\n\n\n\n\n\n\n/-!\n## Exercise 4\nWe did an example together that was similar to this.\nThis one takes a bit more arithmetic work.\nTo save you some time, here are some lemmas that may be useful!\n(You may not need all of them, depending on how you approach it.)\nRemember you can also use `library_search` to try to find useful lemmas.\nA hint: you might find it helpful to do this once you've introduced `n`.\n```\nhave n_pos: 0 < n,\n{ ... }\n```\n-/\n\n#check sub_le_iff_le_add\n#check add_le_add_iff_left\n#check div_le_iff\n#check mul_one_div_cancel\n#check mul_le_mul_left\n\n\nnotation `|`x`|` := abs x\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\n-- n ≥ ⌈1 / ε⌉₊\n\nexample : seq_limit (λ n : ℕ, (n+1)/n) 1 :=\nbegin\n  intros ε epos,  \n  dsimp,\n  use nat.ceil (1 / ε),\n  intros n nge, \n\n  have npos : 0 < n,\n    apply lt_of_lt_of_le,\n    show 0 < ⌈1 / ε⌉₊, \n      rw nat.lt_ceil,\n      apply div_pos,\n      norm_num, from epos,\n    from nge,\n  have : (0 : ℝ) ≤ (n + 1) / n - 1,\n    norm_cast,\n    norm_num,\n    rw le_div_iff,\n    norm_num, norm_cast, from npos,\n    \n  simp [abs_of_nonneg this], norm_cast,\n  rw div_le_iff, simp [add_mul, add_comm _ (n : ℝ)], \n  calc \n    1 = ε * (1 / ε) : by { field_simp; rw div_self; from ne_of_gt epos, }\n    ... ≤ ε * nat.ceil (1 / ε) : \n      by { apply mul_le_mul, apply le_refl, apply nat.le_ceil,\n          apply le_of_lt, apply div_pos, norm_num, from epos, from le_of_lt epos, }\n    ... ≤ ε * n : \n      by { apply mul_le_mul, apply le_refl, norm_cast, from nge, \n          norm_cast, apply nat.zero_le, from le_of_lt epos, },\n  norm_cast,\n  from npos,\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/LftCM2020/exercises/02_Tuesday/02_Numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.7696201871496325}}
{"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 tactic\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 : ℕ`. 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 `∅`.\n\n## Tags\ndivisors, perfect numbers\n\n-/\n\nopen_locale classical\nopen_locale big_operators\nopen finset\n\nnamespace nat\nvariable (n : ℕ)\n\n/-- `divisors n` is the `finset` of divisors of `n`. As a special case, `divisors 0 = ∅`. -/\ndef divisors : finset ℕ := finset.filter (λ x : ℕ, x ∣ 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 = ∅`. -/\ndef proper_divisors : finset ℕ := finset.filter (λ x : ℕ, x ∣ 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 = ∅`. -/\ndef divisors_antidiagonal : finset (ℕ × ℕ) :=\n((finset.Ico 1 (n + 1)).product (finset.Ico 1 (n + 1))).filter (λ x, x.fst * x.snd = n)\n\nvariable {n}\n\nlemma proper_divisors.not_self_mem : ¬ n ∈ proper_divisors n :=\nbegin\n  rw proper_divisors,\n  simp,\nend\n\n@[simp]\nlemma mem_proper_divisors {m : ℕ} : n ∈ proper_divisors m ↔ n ∣ m ∧ n < m :=\nbegin\n  rw [proper_divisors, finset.mem_filter, finset.Ico.mem, 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, finset.Ico.succ_top h, finset.filter_insert, if_pos (dvd_refl n)]\n\n@[simp]\nlemma mem_divisors {m : ℕ} :\n  n ∈ divisors m ↔ (n ∣ m ∧ m ≠ 0) :=\nbegin\n  cases m,\n  { simp [divisors] },\n  simp only [divisors, finset.Ico.mem, 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 dvd_of_mem_divisors {m : ℕ} (h : n ∈ divisors m) : n ∣ m :=\nbegin\n  cases m,\n  { apply dvd_zero },\n  { simp [mem_divisors.1 h], }\nend\n\n@[simp]\nlemma mem_divisors_antidiagonal {x : ℕ × ℕ} :\n  x ∈ divisors_antidiagonal n ↔ x.fst * x.snd = n ∧ n ≠ 0 :=\nbegin\n  simp only [divisors_antidiagonal, finset.Ico.mem, 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 ⟨le_mul_of_pos_right (nat.pos_of_ne_zero h.2),\n      le_mul_of_pos_left (nat.pos_of_ne_zero h.1)⟩ }\nend\n\nvariable {n}\n\nlemma divisor_le {m : ℕ}:\nn ∈ divisors m → n ≤ 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 : ℕ} (hzero : n ≠ 0) (h : m ∣ n) : divisors m ⊆ divisors n :=\nfinset.subset_iff.2 $ λ x hx, nat.mem_divisors.mpr (⟨dvd.trans (nat.mem_divisors.mp hx).1 h, hzero⟩)\n\nlemma divisors_subset_proper_divisors {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) (hdiff : m ≠ n) :\n  divisors m ⊆ proper_divisors n :=\nbegin\n  apply finset.subset_iff.2,\n  intros x hx,\n  exact nat.mem_proper_divisors.2 (⟨dvd.trans (nat.mem_divisors.1 hx).1 h,\n    lt_of_le_of_lt (divisor_le hx) (lt_of_le_of_ne (divisor_le (nat.mem_divisors.2\n    ⟨h, hzero⟩)) hdiff)⟩)\nend\n\n@[simp]\nlemma divisors_zero : divisors 0 = ∅ := by { ext, simp }\n\n@[simp]\nlemma proper_divisors_zero : proper_divisors 0 = ∅ := by { ext, simp }\n\nlemma proper_divisors_subset_divisors : proper_divisors n ⊆ 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 = ∅ :=\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 : ℕ} (h : m ∈ n.divisors) : 0 < m :=\nbegin\n  cases m,\n  { rw [mem_divisors, zero_dvd_iff] at h,\n    rcases h with ⟨rfl, h⟩,\n    exfalso,\n    apply h rfl },\n  apply nat.succ_pos,\nend\n\nlemma pos_of_mem_proper_divisors {m : ℕ} (h : m ∈ 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 ∈ n.proper_divisors ↔ 1 < n :=\nby rw [mem_proper_divisors, and_iff_right (one_dvd _)]\n\n@[simp]\nlemma divisors_antidiagonal_zero : divisors_antidiagonal 0 = ∅ := 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 : ℕ × ℕ} (h : x ∈ divisors_antidiagonal n) :\n  x.swap ∈ 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 : ℕ × ℕ} (h : x ∈ divisors_antidiagonal n) :\n  x.snd ∈ 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 ⟨prod.swap, prod.swap_right_inverse.injective⟩\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 ⟨x, y, ⟨⟨rfl, h⟩, rfl⟩⟩,\n    simp [mul_comm, h], },\n  { rintros ⟨rfl, h⟩,\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∑ i in divisors n, i = ∑ 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 : ℕ` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`\n  is positive. -/\ndef perfect (n : ℕ) : Prop := (∑ i in proper_divisors n, i = n) ∧ 0 < n\n\ntheorem perfect_iff_sum_proper_divisors (h : 0 < n) :\n  perfect n ↔ ∑ 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 ↔ ∑ 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 : ℕ} (pp : p.prime) (k : ℕ) {x : ℕ} :\n  x ∈ divisors (p ^ k) ↔ ∃ (j : ℕ) (H : j ≤ 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 : ℕ} (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 ⟨pp.2 a, λ h, _⟩,\n  rcases h; subst h,\n  apply one_dvd,\nend\n\nlemma prime.proper_divisors {p : ℕ} (pp : p.prime) :\n  proper_divisors p = {1} :=\nby rw [← erase_insert (proper_divisors.not_self_mem),\n    ← divisors_eq_proper_divisors_insert_self_of_pos pp.pos,\n    pp.divisors, insert_singleton_comm, erase_insert (λ con, pp.ne_one (mem_singleton.1 con))]\n\nlemma divisors_prime_pow {p : ℕ} (pp : p.prime) (k : ℕ) :\n  divisors (p ^ k) = (finset.range (k + 1)).map ⟨pow p, pow_right_injective pp.two_le⟩ :=\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 ℕ} (hsub : s ⊆ n.proper_divisors) :\n  ∑ x in s, x = ∑ x in n.proper_divisors, x → s = n.proper_divisors :=\nbegin\n  cases n,\n  { rw [proper_divisors_zero, subset_empty] at hsub,\n    simp [hsub] },\n  classical,\n  rw [← sum_sdiff hsub],\n  intros h,\n  apply subset.antisymm hsub,\n  rw [← sdiff_eq_empty_iff_subset],\n  contrapose h,\n  rw [← ne.def, ← nonempty_iff_ne_empty] at h,\n  apply ne_of_lt,\n  rw [← zero_add (∑ x in s, x), ← add_assoc, add_zero],\n  apply add_lt_add_right,\n  have hlt := sum_lt_sum_of_nonempty h (λ 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 : ∑ x in n.proper_divisors, x ∣ n) :\n  (∑ x in n.proper_divisors, x = 1) ∨ (∑ 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 : ∑ 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 [← mem_singleton, eq_proper_divisors_of_subset_of_sum_eq_sum (singleton_subset_iff.2\n        (mem_proper_divisors.2 ⟨h, hlt⟩)) sum_singleton, mem_proper_divisors],\n  refine ⟨one_dvd _, nat.succ_lt_succ (nat.succ_pos _)⟩,\nend\n\n@[simp]\nlemma prime.sum_proper_divisors {α : Type*} [add_comm_monoid α] {p : ℕ} {f : ℕ → α} (h : p.prime) :\n  ∑ x in p.proper_divisors, f x = f 1 :=\nby simp [h.proper_divisors]\n\n@[simp]\nlemma prime.sum_divisors {α : Type*} [add_comm_monoid α] {p : ℕ} {f : ℕ → α} (h : p.prime) :\n  ∑ x in p.divisors, f x = f p + f 1 :=\nby rw [divisors_eq_proper_divisors_insert_self_of_pos h.pos,\n       sum_insert proper_divisors.not_self_mem, h.sum_proper_divisors]\n\nlemma proper_divisors_eq_singleton_one_iff_prime :\n  n.proper_divisors = {1} ↔ n.prime :=\n⟨λ h, begin\n  have h1 := mem_singleton.2 rfl,\n  rw [← h, mem_proper_divisors] at h1,\n  refine ⟨h1.2, _⟩,\n  intros m hdvd,\n  rw [← mem_singleton, ← 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 ⟨hdvd, h_1⟩ },\n  { right,\n    exact h_1 }\nend, prime.proper_divisors⟩\n\nlemma sum_proper_divisors_eq_one_iff_prime :\n  ∑ x in n.proper_divisors, x = 1 ↔ n.prime :=\nbegin\n  cases n,\n  { simp [nat.not_prime_zero] },\n  cases n,\n  { simp [nat.not_prime_one] },\n  rw [← proper_divisors_eq_singleton_one_iff_prime],\n  refine ⟨λ h, _, λ h, h.symm ▸ sum_singleton⟩,\n  rw [@eq_comm (finset ℕ) _ _],\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\n@[simp]\nlemma prod_divisors_prime {α : Type*} [comm_monoid α] {p : ℕ} {f : ℕ → α} (h : p.prime) :\n  ∏ x in p.divisors, f x = f p * f 1 :=\n@prime.sum_divisors (additive α) _ _ _ h\n\n@[simp]\nlemma sum_divisors_prime_pow {α : Type*} [add_comm_monoid α] {k p : ℕ} {f : ℕ → α} (h : p.prime) :\n  ∑ x in (p ^ k).divisors, f x = ∑ x in range (k + 1), f (p ^ x) :=\nby simp [h, divisors_prime_pow]\n\n@[simp]\nlemma prod_divisors_prime_pow {α : Type*} [comm_monoid α] {k p : ℕ} {f : ℕ → α} (h : p.prime) :\n  ∏ x in (p ^ k).divisors, f x = ∏ x in range (k + 1), f (p ^ x) :=\n@sum_divisors_prime_pow (additive α) _ _ _ _ h\n\n@[simp]\nlemma filter_dvd_eq_divisors {n : ℕ} (h : n ≠ 0) :\n  finset.filter (λ (x : ℕ), x ∣ n) (finset.range (n : ℕ).succ) = (n : ℕ).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 ⟨ha, h⟩))\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/number_theory/divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.76962018371286}}
{"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 analysis.inner_product_space.gram_schmidt_ortho\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* `orthonormal_basis.adjust_to_orientation` takes an orthonormal basis and an orientation, and\n  returns an orthonormal basis with that orientation: either the original orthonormal basis, or one\n  constructed by negating a single (arbitrary) basis vector.\n* `orientation.fin_orthonormal_basis` is an orthonormal basis, indexed by `fin n`, with the given\n  orientation.\n* `orientation.volume_form` is a nonvanishing top-dimensional alternating form on an oriented real\n  inner product space, uniquely defined by compatibility with the orientation and inner product\n  structure.\n\n## Main theorems\n\n* `orientation.volume_form_apply_le` states that the result of applying the volume form to a set of\n  `n` vectors, where `n` is the dimension the inner product space, is bounded by the product of the\n  lengths of the vectors.\n* `orientation.abs_volume_form_apply_of_pairwise_orthogonal` states that the result of applying the\n  volume form to a set of `n` orthogonal vectors, where `n` is the dimension the inner product\n  space, is equal up to sign to the product of the lengths of the vectors.\n\n-/\n\nnoncomputable theory\n\nvariables {E : Type*} [normed_add_comm_group E] [inner_product_space ℝ E]\n\nopen finite_dimensional\nopen_locale big_operators real_inner_product_space\n\nnamespace orthonormal_basis\nvariables {ι : Type*} [fintype ι] [decidable_eq ι] [ne : nonempty ι] (e f : orthonormal_basis ι ℝ E)\n  (x : orientation ℝ E ι)\n\n/-- The change-of-basis matrix between two orthonormal bases with the same orientation has\ndeterminant 1. -/\nlemma det_to_matrix_orthonormal_basis_of_same_orientation\n  (h : e.to_basis.orientation = f.to_basis.orientation) :\n  e.to_basis.det f = 1 :=\nbegin\n  apply (e.det_to_matrix_orthonormal_basis_real f).resolve_right,\n  have : 0 < e.to_basis.det f,\n  { rw e.to_basis.orientation_eq_iff_det_pos at h,\n    simpa using h },\n  linarith,\nend\n\n/-- The change-of-basis matrix between two orthonormal bases with the opposite orientations has\ndeterminant -1. -/\nlemma det_to_matrix_orthonormal_basis_of_opposite_orientation\n  (h : e.to_basis.orientation ≠ f.to_basis.orientation) :\n  e.to_basis.det f = -1 :=\nbegin\n  contrapose! h,\n  simp [e.to_basis.orientation_eq_iff_det_pos,\n    (e.det_to_matrix_orthonormal_basis_real f).resolve_right h],\nend\n\nvariables {e f}\n\n/-- Two orthonormal bases with the same orientation determine the same \"determinant\" top-dimensional\nform on `E`, and conversely. -/\nlemma same_orientation_iff_det_eq_det :\n  e.to_basis.det = f.to_basis.det ↔ e.to_basis.orientation = f.to_basis.orientation :=\nbegin\n  split,\n  { intros h,\n    dsimp [basis.orientation],\n    congr' },\n  { intros h,\n    rw e.to_basis.det.eq_smul_basis_det f.to_basis,\n    simp [e.det_to_matrix_orthonormal_basis_of_same_orientation f h], },\nend\n\nvariables (e f)\n\n/-- Two orthonormal bases with opposite orientations determine opposite \"determinant\"\ntop-dimensional forms on `E`. -/\nlemma det_eq_neg_det_of_opposite_orientation\n  (h : e.to_basis.orientation ≠ f.to_basis.orientation) :\n  e.to_basis.det = -f.to_basis.det :=\nbegin\n  rw e.to_basis.det.eq_smul_basis_det f.to_basis,\n  simp [e.det_to_matrix_orthonormal_basis_of_opposite_orientation f h],\nend\n\nsection adjust_to_orientation\ninclude ne\n\n/-- `orthonormal_basis.adjust_to_orientation`, applied to an orthonormal basis, preserves the\nproperty of orthonormality. -/\nlemma orthonormal_adjust_to_orientation : orthonormal ℝ (e.to_basis.adjust_to_orientation x) :=\nbegin\n  apply e.orthonormal.orthonormal_of_forall_eq_or_eq_neg,\n  simpa using e.to_basis.adjust_to_orientation_apply_eq_or_eq_neg x\nend\n\n/-- Given an orthonormal basis and an orientation, return an orthonormal basis giving that\norientation: either the original basis, or one constructed by negating a single (arbitrary) basis\nvector. -/\ndef adjust_to_orientation : orthonormal_basis ι ℝ E :=\n(e.to_basis.adjust_to_orientation x).to_orthonormal_basis (e.orthonormal_adjust_to_orientation x)\n\nlemma to_basis_adjust_to_orientation :\n  (e.adjust_to_orientation x).to_basis = e.to_basis.adjust_to_orientation x :=\n(e.to_basis.adjust_to_orientation x).to_basis_to_orthonormal_basis _\n\n/-- `adjust_to_orientation` gives an orthonormal basis with the required orientation. -/\n@[simp] lemma orientation_adjust_to_orientation :\n  (e.adjust_to_orientation x).to_basis.orientation = x :=\nbegin\n  rw e.to_basis_adjust_to_orientation,\n  exact e.to_basis.orientation_adjust_to_orientation x,\nend\n\n/-- Every basis vector from `adjust_to_orientation` is either that from the original basis or its\nnegation. -/\nlemma adjust_to_orientation_apply_eq_or_eq_neg (i : ι) :\n  e.adjust_to_orientation x i = e i ∨ e.adjust_to_orientation x i = -(e i) :=\nby simpa [← e.to_basis_adjust_to_orientation]\n  using e.to_basis.adjust_to_orientation_apply_eq_or_eq_neg x i\n\nlemma det_adjust_to_orientation :\n  (e.adjust_to_orientation x).to_basis.det = e.to_basis.det\n  ∨ (e.adjust_to_orientation x).to_basis.det = -e.to_basis.det :=\nby simpa using e.to_basis.det_adjust_to_orientation x\n\nlemma abs_det_adjust_to_orientation (v : ι → E) :\n  |(e.adjust_to_orientation x).to_basis.det v| = |e.to_basis.det v| :=\nby simp [to_basis_adjust_to_orientation]\n\nend adjust_to_orientation\n\nend orthonormal_basis\n\nnamespace orientation\nvariables {n : ℕ}\n\nopen orthonormal_basis\n\n/-- An orthonormal basis, indexed by `fin n`, with the given orientation. -/\nprotected def fin_orthonormal_basis (hn : 0 < n) (h : finrank ℝ E = n)\n  (x : orientation ℝ E (fin n)) : orthonormal_basis (fin n) ℝ E :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  haveI := finite_dimensional_of_finrank (h.symm ▸ hn : 0 < finrank ℝ E),\n  exact ((std_orthonormal_basis _ _).reindex $ fin_congr h).adjust_to_orientation x\nend\n\n/-- `orientation.fin_orthonormal_basis` gives a basis with the required orientation. -/\n@[simp] lemma fin_orthonormal_basis_orientation (hn : 0 < n)\n  (h : finrank ℝ E = n) (x : orientation ℝ E (fin n)) :\n  (x.fin_orthonormal_basis hn h).to_basis.orientation = x :=\nbegin\n  haveI := fin.pos_iff_nonempty.1 hn,\n  haveI := finite_dimensional_of_finrank (h.symm ▸ hn : 0 < finrank ℝ E),\n  exact ((std_orthonormal_basis _ _).reindex $ fin_congr h).orientation_adjust_to_orientation x\nend\n\nsection volume_form\nvariables [_i : fact (finrank ℝ E = n)] (o : orientation ℝ E (fin n))\n\ninclude _i o\n\n/-- The volume form on an oriented real inner product space, a nonvanishing top-dimensional\nalternating form uniquely defined by compatibility with the orientation and inner product structure.\n-/\n@[irreducible] def volume_form : alternating_map ℝ E ℝ (fin n) :=\nbegin\n  classical,\n  unfreezingI { cases n },\n  { let opos : alternating_map ℝ E ℝ (fin 0) := alternating_map.const_of_is_empty ℝ E (1:ℝ),\n    exact o.eq_or_eq_neg_of_is_empty.by_cases (λ _, opos) (λ _, -opos) },\n  { exact (o.fin_orthonormal_basis n.succ_pos _i.out).to_basis.det }\nend\n\nomit _i o\n\n@[simp] lemma volume_form_zero_pos [_i : fact (finrank ℝ E = 0)] :\n  orientation.volume_form (positive_orientation : orientation ℝ E (fin 0))\n  = alternating_map.const_linear_equiv_of_is_empty 1 :=\nby simp [volume_form, or.by_cases, if_pos]\n\nlemma volume_form_zero_neg [_i : fact (finrank ℝ E = 0)] :\n  orientation.volume_form (-positive_orientation : orientation ℝ E (fin 0))\n  = - alternating_map.const_linear_equiv_of_is_empty 1 :=\nbegin\n  dsimp [volume_form, or.by_cases, positive_orientation],\n  apply if_neg,\n  rw [ray_eq_iff, same_ray_comm],\n  intros h,\n  simpa using\n    congr_arg alternating_map.const_linear_equiv_of_is_empty.symm (eq_zero_of_same_ray_self_neg h),\nend\n\ninclude _i o\n\n/-- The volume form on an oriented real inner product space can be evaluated as the determinant with\nrespect to any orthonormal basis of the space compatible with the orientation. -/\nlemma volume_form_robust (b : orthonormal_basis (fin n) ℝ E) (hb : b.to_basis.orientation = o) :\n  o.volume_form = b.to_basis.det :=\nbegin\n  unfreezingI { cases n },\n  { classical,\n    have : o = positive_orientation := hb.symm.trans b.to_basis.orientation_is_empty,\n    simp [volume_form, or.by_cases, dif_pos this] },\n  { dsimp [volume_form],\n    rw [same_orientation_iff_det_eq_det, hb],\n    exact o.fin_orthonormal_basis_orientation _ _ },\nend\n\n/-- The volume form on an oriented real inner product space can be evaluated as the determinant with\nrespect to any orthonormal basis of the space compatible with the orientation. -/\nlemma volume_form_robust_neg (b : orthonormal_basis (fin n) ℝ E)\n  (hb : b.to_basis.orientation ≠ o) :\n  o.volume_form = - b.to_basis.det :=\nbegin\n  unfreezingI { cases n },\n  { classical,\n    have : positive_orientation ≠ o := by rwa b.to_basis.orientation_is_empty at hb,\n    simp [volume_form, or.by_cases, dif_neg this.symm] },\n  let e : orthonormal_basis (fin n.succ) ℝ E := o.fin_orthonormal_basis n.succ_pos (fact.out _),\n  dsimp [volume_form],\n  apply e.det_eq_neg_det_of_opposite_orientation b,\n  convert hb.symm,\n  exact o.fin_orthonormal_basis_orientation _ _,\nend\n\n@[simp] lemma volume_form_neg_orientation : (-o).volume_form = - o.volume_form :=\nbegin\n  unfreezingI { cases n },\n  { refine o.eq_or_eq_neg_of_is_empty.elim _ _; rintros rfl; simp [volume_form_zero_neg] },\n  let e : orthonormal_basis (fin n.succ) ℝ E := o.fin_orthonormal_basis n.succ_pos (fact.out _),\n  have h₁ : e.to_basis.orientation = o := o.fin_orthonormal_basis_orientation _ _,\n  have h₂ : e.to_basis.orientation ≠ -o,\n  { symmetry,\n    rw [e.to_basis.orientation_ne_iff_eq_neg, h₁] },\n  rw [o.volume_form_robust e h₁, (-o).volume_form_robust_neg e h₂],\nend\n\nlemma volume_form_robust' (b : orthonormal_basis (fin n) ℝ E) (v : fin n → E) :\n  |o.volume_form v| = |b.to_basis.det v| :=\nbegin\n  unfreezingI { cases n },\n  { refine o.eq_or_eq_neg_of_is_empty.elim _ _; rintros rfl; simp },\n  { rw [o.volume_form_robust (b.adjust_to_orientation o) (b.orientation_adjust_to_orientation o),\n      b.abs_det_adjust_to_orientation] },\nend\n\n/-- Let `v` be an indexed family of `n` vectors in an oriented `n`-dimensional real inner\nproduct space `E`. The output of the volume form of `E` when evaluated on `v` is bounded in absolute\nvalue by the product of the norms of the vectors `v i`. -/\nlemma abs_volume_form_apply_le (v : fin n → E) : |o.volume_form v| ≤ ∏ i : fin n, ‖v i‖ :=\nbegin\n  unfreezingI { cases n },\n  { refine o.eq_or_eq_neg_of_is_empty.elim _ _; rintros rfl; simp },\n  haveI : finite_dimensional ℝ E := fact_finite_dimensional_of_finrank_eq_succ n,\n  have : finrank ℝ E = fintype.card (fin n.succ) := by simpa using _i.out,\n  let b : orthonormal_basis (fin n.succ) ℝ E := gram_schmidt_orthonormal_basis this v,\n  have hb : b.to_basis.det v = ∏ i, ⟪b i, v i⟫ := gram_schmidt_orthonormal_basis_det this v,\n  rw [o.volume_form_robust' b, hb, finset.abs_prod],\n  apply finset.prod_le_prod,\n  { intros i hi,\n    positivity },\n  intros i hi,\n  convert abs_real_inner_le_norm (b i) (v i),\n  simp [b.orthonormal.1 i],\nend\n\nlemma volume_form_apply_le (v : fin n → E) : o.volume_form v ≤ ∏ i : fin n, ‖v i‖ :=\n(le_abs_self _).trans (o.abs_volume_form_apply_le v)\n\n/-- Let `v` be an indexed family of `n` orthogonal vectors in an oriented `n`-dimensional\nreal inner product space `E`. The output of the volume form of `E` when evaluated on `v` is, up to\nsign, the product of the norms of the vectors `v i`. -/\nlemma abs_volume_form_apply_of_pairwise_orthogonal\n  {v : fin n → E} (hv : pairwise (λ i j, ⟪v i, v j⟫ = 0)) :\n  |o.volume_form v| = ∏ i : fin n, ‖v i‖ :=\nbegin\n  unfreezingI { cases n },\n  { refine o.eq_or_eq_neg_of_is_empty.elim _ _; rintros rfl; simp },\n  haveI : finite_dimensional ℝ E := fact_finite_dimensional_of_finrank_eq_succ n,\n  have hdim : finrank ℝ E = fintype.card (fin n.succ) := by simpa using _i.out,\n  let b : orthonormal_basis (fin n.succ) ℝ E := gram_schmidt_orthonormal_basis hdim v,\n  have hb : b.to_basis.det v = ∏ i, ⟪b i, v i⟫ := gram_schmidt_orthonormal_basis_det hdim v,\n  rw [o.volume_form_robust' b, hb, finset.abs_prod],\n  by_cases h : ∃ i, v i = 0,\n  obtain ⟨i, hi⟩ := h,\n  { rw [finset.prod_eq_zero (finset.mem_univ i), finset.prod_eq_zero (finset.mem_univ i)];\n    simp [hi] },\n  push_neg at h,\n  congr,\n  ext i,\n  have hb : b i = ‖v i‖⁻¹ • v i := gram_schmidt_orthonormal_basis_apply_of_orthogonal hdim hv (h i),\n  simp only [hb, inner_smul_left, real_inner_self_eq_norm_mul_norm, is_R_or_C.conj_to_real],\n  rw abs_of_nonneg,\n  { have : ‖v i‖ ≠ 0 := by simpa using h i,\n    field_simp },\n  { positivity },\nend\n\n/-- The output of the volume form of an oriented real inner product space `E` when evaluated on an\northonormal basis is ±1. -/\nlemma abs_volume_form_apply_of_orthonormal (v : orthonormal_basis (fin n) ℝ E) :\n  |o.volume_form v| = 1 :=\nby simpa [o.volume_form_robust' v v] using congr_arg abs v.to_basis.det_self\n\nlemma volume_form_map {F : Type*}\n  [normed_add_comm_group F] [inner_product_space ℝ F] [fact (finrank ℝ F = n)]\n  (φ : E ≃ₗᵢ[ℝ] F) (x : fin n → F) :\n  (orientation.map (fin n) φ.to_linear_equiv o).volume_form x = o.volume_form (φ.symm ∘ x) :=\nbegin\n  unfreezingI { cases n },\n  { refine o.eq_or_eq_neg_of_is_empty.elim _ _; rintros rfl; simp },\n  let e : orthonormal_basis (fin n.succ) ℝ E := o.fin_orthonormal_basis n.succ_pos (fact.out _),\n  have he : e.to_basis.orientation = o :=\n    (o.fin_orthonormal_basis_orientation n.succ_pos (fact.out _)),\n  have heφ : (e.map φ).to_basis.orientation = orientation.map (fin n.succ) φ.to_linear_equiv o,\n  { rw ← he,\n    exact (e.to_basis.orientation_map φ.to_linear_equiv) },\n  rw (orientation.map (fin n.succ) φ.to_linear_equiv o).volume_form_robust (e.map φ) heφ,\n  rw o.volume_form_robust e he,\n  simp,\nend\n\n/-- The volume form is invariant under pullback by a positively-oriented isometric automorphism. -/\nlemma volume_form_comp_linear_isometry_equiv (φ : E ≃ₗᵢ[ℝ] E)\n  (hφ : 0 < (φ.to_linear_equiv : E →ₗ[ℝ] E).det) (x : fin n → E) :\n  o.volume_form (φ ∘ x) = o.volume_form x :=\nbegin\n  convert o.volume_form_map φ (φ ∘ x),\n  { symmetry,\n    rwa ← o.map_eq_iff_det_pos φ.to_linear_equiv at hφ,\n    rw [_i.out, fintype.card_fin] },\n  { ext,\n    simp }\nend\n\nend volume_form\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/analysis/inner_product_space/orientation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7696201821249478}}
{"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 `μ(F) = c * μ(E)`\nfor two sets `E` and `F`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be\nthe characteristic functions of `E` and `F`.\nAssume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`\npreserves the measure `μ.prod ν`, which means that\n```\n  ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ\n```\nIf we apply this to `h x y := e x * f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E)`, we can rewrite the RHS to\n`μ(F)`, and the LHS to `c * μ(E)`, where `c = c(ν)` does not depend on `μ`.\nApplying this to `μ` and to `ν` gives `μ (F) / μ (E) = ν (F) / ν (E)`, which is the uniqueness up to\nscalar multiplication.\n\nThe proof in [Halmos] seems to contain an omission in §60 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₂ G]\nvariables (μ ν : measure G) [sigma_finite ν] [sigma_finite μ] {E : set G}\n\n/-- The map `(x, y) ↦ (x, xy)` as a `measurable_equiv`. This is a shear mapping. -/\n@[to_additive \"The map `(x, y) ↦ (x, x + y)` as a `measurable_equiv`.\nThis is a shear mapping.\"]\nprotected def measurable_equiv.shear_mul_right [has_measurable_inv G] : G × G ≃ᵐ G × 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\nvariables {G}\n\nnamespace measure_theory\n\nopen measure\n\n/-- A shear mapping preserves the measure `μ.prod ν`.\nThis condition is part of the definition of a measurable group in [Halmos, §59].\nThere, the map in this lemma is called `S`. -/\n@[to_additive map_prod_sum_eq /-\" An additive shear mapping preserves the measure `μ.prod ν`. \"-/]\nlemma map_prod_mul_eq [is_mul_left_invariant ν] :\n  map (λ z : G × G, (z.1, z.1 * z.2)) (μ.prod ν) = μ.prod ν :=\n((measure_preserving.id μ).skew_product measurable_mul\n  (filter.eventually_of_forall $ map_mul_left_eq_self ν)).map_eq\n\n/-- The function we are mapping along is `SR` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_add_eq_swap /-\"  \"-/]\nlemma map_prod_mul_eq_swap [is_mul_left_invariant μ] :\n  map (λ z : G × G, (z.2, z.2 * z.1)) (μ.prod ν) = ν.prod μ :=\nbegin\n  rw [← prod_swap],\n  simp_rw [map_map (measurable_snd.prod_mk (measurable_snd.mul measurable_fst)) measurable_swap],\n  exact map_prod_mul_eq ν μ\nend\n\n@[to_additive]\nlemma measurable_measure_mul_right (hE : measurable_set E) :\n  measurable (λ x, μ ((λ y, y * x) ⁻¹' E)) :=\nbegin\n  suffices : measurable (λ y,\n    μ ((λ x, (x, y)) ⁻¹' ((λ z : G × G, ((1 : G), z.1 * z.2)) ⁻¹' ((univ : set G) ×ˢ 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\nvariables [has_measurable_inv G]\n\n/-- The function we are mapping along is `S⁻¹` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq`. -/\n@[to_additive map_prod_neg_add_eq]\nlemma map_prod_inv_mul_eq [is_mul_left_invariant ν] :\n  map (λ z : G × G, (z.1, z.1⁻¹ * z.2)) (μ.prod ν) = μ.prod ν :=\n(measurable_equiv.shear_mul_right G).map_apply_eq_iff_map_symm_apply_eq.mp $ map_prod_mul_eq μ ν\n\n@[to_additive]\nlemma quasi_measure_preserving_div [is_mul_right_invariant μ] :\n  quasi_measure_preserving (λ (p : G × G), p.1 / p.2) (μ.prod μ) μ :=\nbegin\n  refine quasi_measure_preserving.prod_of_left measurable_div _,\n  simp_rw [div_eq_mul_inv],\n  apply eventually_of_forall,\n  refine λ y, ⟨measurable_mul_const y⁻¹, (map_mul_right_eq_self μ y⁻¹).absolutely_continuous⟩\nend\n\nvariables [is_mul_left_invariant μ]\n\n/-- The function we are mapping along is `S⁻¹R` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_neg_add_eq_swap]\nlemma map_prod_inv_mul_eq_swap : map (λ z : G × G, (z.2, z.2⁻¹ * z.1)) (μ.prod ν) = ν.prod μ :=\nbegin\n  rw [← 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 ν μ\nend\n\n/-- The function we are mapping along is `S⁻¹RSR` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_add_neg_eq]\nlemma map_prod_mul_inv_eq [is_mul_left_invariant ν] :\n  map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod ν) = μ.prod ν :=\nbegin\n  suffices : map ((λ z : G × G, (z.2, z.2⁻¹ * z.1)) ∘ (λ z : G × G, (z.2, z.2 * z.1))) (μ.prod ν) =\n    μ.prod ν,\n  { convert this, ext1 ⟨x, y⟩, simp },\n  simp_rw [← 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 μ ν,\n    map_prod_inv_mul_eq_swap ν μ]\nend\n\n@[to_additive] lemma quasi_measure_preserving_inv :\n  quasi_measure_preserving (has_inv.inv : G → G) μ μ :=\nbegin\n  refine ⟨measurable_inv, absolutely_continuous.mk $ λ s hsm hμs, _⟩,\n  rw [map_apply measurable_inv hsm, inv_preimage],\n  have hf : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=\n    (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  suffices : map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (s⁻¹ ×ˢ s⁻¹) = 0,\n  { simpa only [map_prod_mul_inv_eq μ μ, prod_prod, mul_eq_zero, or_self] using this },\n  have hsm' : measurable_set (s⁻¹ ×ˢ s⁻¹) := 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μs, lintegral_zero]\nend\n\n@[to_additive]\nlemma map_inv_absolutely_continuous : map has_inv.inv μ ≪ μ :=\n(quasi_measure_preserving_inv μ).absolutely_continuous\n\n@[to_additive]\nlemma measure_inv_null : μ E⁻¹ = 0 ↔ μ E = 0 :=\nbegin\n  refine ⟨λ hE, _, (quasi_measure_preserving_inv μ).preimage_null⟩,\n  convert (quasi_measure_preserving_inv μ).preimage_null hE,\n  exact (inv_inv _).symm\nend\n\n@[to_additive]\nlemma absolutely_continuous_map_inv : μ ≪ map has_inv.inv μ :=\nbegin\n  refine absolutely_continuous.mk (λ s hs, _),\n  simp_rw [map_apply measurable_inv hs, inv_preimage, measure_inv_null, imp_self]\nend\n\n@[to_additive]\nlemma lintegral_lintegral_mul_inv [is_mul_left_invariant ν]\n  (f : G → G → ℝ≥0∞) (hf : ae_measurable (uncurry f) (μ.prod ν)) :\n  ∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ :=\nbegin\n  have h : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=\n  (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  have h2f : ae_measurable (uncurry $ λ x y, f (y * x) x⁻¹) (μ.prod ν),\n  { apply hf.comp_measurable' h (map_prod_mul_inv_eq μ ν).absolutely_continuous },\n  simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],\n  conv_rhs { rw [← map_prod_mul_inv_eq μ ν] },\n  symmetry,\n  exact lintegral_map' (hf.mono' (map_prod_mul_inv_eq μ ν).absolutely_continuous) h.ae_measurable,\nend\n\n@[to_additive]\nlemma measure_mul_right_null (y : G) :\n  μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ E = 0 :=\ncalc μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ ((λ x, y⁻¹ * x) ⁻¹' E⁻¹)⁻¹ = 0 :\n  by simp_rw [← inv_preimage, preimage_preimage, mul_inv_rev, inv_inv]\n... ↔ μ E = 0 : by simp only [measure_inv_null μ, measure_preimage_mul]\n\n@[to_additive]\nlemma measure_mul_right_ne_zero\n  (h2E : μ E ≠ 0) (y : G) : μ ((λ x, x * y) ⁻¹' E) ≠ 0 :=\n(not_iff_not_of_iff (measure_mul_right_null μ y)).mpr h2E\n\n@[to_additive] lemma quasi_measure_preserving_mul_right (g : G) :\n  quasi_measure_preserving (λ h : G, h * g) μ μ :=\nbegin\n  refine ⟨measurable_mul_const g, absolutely_continuous.mk $ λ s hs, _⟩,\n  rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null], exact id,\nend\n\n@[to_additive]\nlemma map_mul_right_absolutely_continuous (g : G) : map (* g) μ ≪ μ :=\n(quasi_measure_preserving_mul_right μ g).absolutely_continuous\n\n@[to_additive]\nlemma absolutely_continuous_map_mul_right (g : G) : μ ≪ map (* g) μ :=\nbegin\n  refine absolutely_continuous.mk (λ s hs, _),\n  rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null], exact id\nend\n\n@[to_additive] lemma quasi_measure_preserving_div_left (g : G) :\n  quasi_measure_preserving (λ h : G, g / h) μ μ :=\nbegin\n  refine ⟨measurable_const.div measurable_id, _⟩,\n  simp_rw [div_eq_mul_inv],\n  rw [← map_map (measurable_const_mul g) measurable_inv],\n  refine ((map_inv_absolutely_continuous μ).map $ measurable_const_mul g).trans _,\n  rw [map_mul_left_eq_self],\nend\n\n@[to_additive]\nlemma map_div_left_absolutely_continuous (g : G) : map (λ h, g / h) μ ≪ μ :=\n(quasi_measure_preserving_div_left μ g).absolutely_continuous\n\n@[to_additive]\nlemma absolutely_continuous_map_div_left (g : G) : μ ≪ map (λ h, g / h) μ :=\nbegin\n  simp_rw [div_eq_mul_inv],\n  rw [← map_map (measurable_const_mul g) measurable_inv],\n  conv_lhs { rw [← map_mul_left_eq_self μ g] },\n  exact (absolutely_continuous_map_inv μ).map (measurable_const_mul g)\nend\n\n/-- This is the computation performed in the proof of [Halmos, §60 Th. A]. -/\n@[to_additive]\nlemma measure_mul_lintegral_eq\n  [is_mul_left_invariant ν] (Em : measurable_set E) (f : G → ℝ≥0∞) (hf : measurable f) :\n  μ E * ∫⁻ y, f y ∂ν = ∫⁻ x, ν ((λ z, z * x) ⁻¹' E) * f (x⁻¹) ∂μ :=\nbegin\n  rw [← set_lintegral_one, ← lintegral_indicator _ Em,\n    ← lintegral_lintegral_mul (measurable_const.indicator Em).ae_measurable hf.ae_measurable,\n    ← lintegral_lintegral_mul_inv μ ν],\n  swap, { exact (((measurable_const.indicator Em).comp measurable_fst).mul\n      (hf.comp measurable_snd)).ae_measurable },\n  have mE : ∀ x : G, measurable (λ y, ((λ z, z * x) ⁻¹' E).indicator (λ z, (1 : ℝ≥0∞)) y) :=\n  λ x, measurable_const.indicator (measurable_mul_const _ Em),\n  have : ∀ x y, E.indicator (λ (z : G), (1 : ℝ≥0∞)) (y * x) =\n    ((λ z, z * x) ⁻¹' E).indicator (λ (b : G), 1) y,\n  { intros x y, symmetry, convert indicator_comp_right (λ y, y * x), ext1 z, refl },\n  simp_rw [this, lintegral_mul_const _ (mE _), lintegral_indicator _ (measurable_mul_const _ Em),\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 ν] (hν : ν ≠ 0) :\n  μ ≪ ν :=\nbegin\n  refine absolutely_continuous.mk (λ E Em hνE, _),\n  have h1 := measure_mul_lintegral_eq μ ν Em 1 measurable_one,\n  simp_rw [pi.one_apply, lintegral_one, mul_one, (measure_mul_right_null ν _).mpr hνE,\n    lintegral_zero, mul_eq_zero, measure_univ_eq_zero.not.mpr hν, or_false] at h1,\n  exact h1\nend\n\n@[to_additive]\nlemma ae_measure_preimage_mul_right_lt_top [is_mul_left_invariant ν]\n  (Em : measurable_set E) (hμE : μ E ≠ ∞) :\n  ∀ᵐ x ∂μ, ν ((λ y, y * x) ⁻¹' E) < ∞ :=\nbegin\n  refine ae_of_forall_measure_lt_top_ae_restrict' ν.inv _ _,\n  intros A hA h2A h3A,\n  simp only [ν.inv_apply] at h3A,\n  apply ae_lt_top (measurable_measure_mul_right ν Em),\n  have h1 := measure_mul_lintegral_eq μ ν Em (A⁻¹.indicator 1) (measurable_one.indicator hA.inv),\n  rw [lintegral_indicator _ hA.inv] at h1,\n  simp_rw [pi.one_apply, set_lintegral_one, ← image_inv, indicator_image inv_injective, image_inv,\n    ← indicator_mul_right _ (λ x, ν ((λ y, y * x) ⁻¹' E)), function.comp, pi.one_apply,\n    mul_one] at h1,\n  rw [← lintegral_indicator _ hA, ← h1],\n  exact ennreal.mul_ne_top hμE h3A.ne,\nend\n\n@[to_additive]\nlemma ae_measure_preimage_mul_right_lt_top_of_ne_zero [is_mul_left_invariant ν]\n  (Em : measurable_set E) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞) :\n  ∀ᵐ x ∂μ, ν ((λ y, y * x) ⁻¹' E) < ∞ :=\nbegin\n  refine (ae_measure_preimage_mul_right_lt_top ν ν Em h3E).filter_mono _,\n  refine (absolutely_continuous_of_is_mul_left_invariant μ ν _).ae_le,\n  refine mt _ h2E,\n  intro hν,\n  rw [hν, measure.coe_zero, pi.zero_apply]\nend\n\n/-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A].\n  Note that if `f` is the characteristic function of a measurable set `F` this states that\n  `μ F = c * μ E` for a constant `c` that does not depend on `μ`.\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⁻¹)ν(Ex⁻¹) = f(x)` holds if we can prove that\n  `0 < ν(Ex⁻¹) < ∞`. The first inequality follows from §59, 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]\nlemma measure_lintegral_div_measure [is_mul_left_invariant ν]\n  (Em : measurable_set E) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞)\n  (f : G → ℝ≥0∞) (hf : measurable f) :\n  μ E * ∫⁻ y, f y⁻¹ / ν ((λ x, x * y⁻¹) ⁻¹' E) ∂ν = ∫⁻ x, f x ∂μ :=\nbegin\n  set g := λ y, f y⁻¹ / ν ((λ x, x * y⁻¹) ⁻¹' E),\n  have hg : measurable g := (hf.comp measurable_inv).div\n    ((measurable_measure_mul_right ν Em).comp measurable_inv),\n  simp_rw [measure_mul_lintegral_eq μ ν Em g hg, g, inv_inv],\n  refine lintegral_congr_ae _,\n  refine (ae_measure_preimage_mul_right_lt_top_of_ne_zero μ ν Em h2E h3E).mono (λ x hx , _),\n  simp_rw [ennreal.mul_div_cancel' (measure_mul_right_ne_zero ν h2E _) hx.ne]\nend\n\n@[to_additive]\nlemma measure_mul_measure_eq [is_mul_left_invariant ν] {E F : set G}\n  (hE : measurable_set E) (hF : measurable_set F) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞) :\n    μ E * ν F = ν E * μ F :=\nbegin\n  have h1 := measure_lintegral_div_measure ν ν hE h2E h3E (F.indicator (λ x, 1))\n    (measurable_const.indicator hF),\n  have h2 := measure_lintegral_div_measure μ ν hE h2E h3E (F.indicator (λ x, 1))\n    (measurable_const.indicator hF),\n  rw [lintegral_indicator _ hF, set_lintegral_one] at h1 h2,\n  rw [← 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 ν]\n  (hE : measurable_set E) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞) : μ = (μ E / ν E) • ν :=\nbegin\n  ext1 F hF,\n  rw [smul_apply, smul_eq_mul, mul_comm, ← mul_div_assoc, mul_comm,\n    measure_mul_measure_eq μ ν hE hF h2E h3E, mul_div_assoc, ennreal.mul_div_cancel' h2E h3E]\nend\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/group/prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7695940844478377}}
{"text": "import basic\nimport group_theory.order_of_element\n\nnamespace myint\n\nlemma add_pair_eq {a b : ℕ × ℕ} : ⟦a⟧ + ⟦b⟧ = add_pair a b := rfl\n\n/-\n`quotient.ind` gives the correspondence between elements of a quotient type and equivalence classes\nof the underlying type. It states that to prove `β q` for every `q` in a quotient type, it suffices\nto prove `β ⟦a⟧` for every `a` in the underlying type. \n-/\n\nprotected lemma add_comm : ∀ n m : myint, n + m = m + n :=\nby { apply quotient.ind₂, intros, simp [add_pair_eq, add_pair], congr' 1; apply nat.add_comm }\n\nprotected lemma zero_add : ∀ a : myint, 0 + a = a :=\nbegin\n  apply quotient.ind, rintros ⟨a₁, a₂⟩, dsimp [myint.has_zero_myint, mk], rw add_pair_eq,\n  dsimp [add_pair], congr'; apply nat.zero_add,\nend\n\nprotected lemma add_zero : ∀ a : myint, a + 0 = a :=\nby { intro, rw [myint.add_comm, myint.zero_add], }\n\nprotected lemma add_left_neg : ∀ a : myint, -a + a = 0 :=\nbegin\n  apply quotient.ind, rintro ⟨a₁, a₂⟩,\n  dsimp [myint.has_zero_myint, myint.has_neg_myint, neg, myint.neg_pair, mk], simp [add_pair_eq, add_pair],\n  apply quot.sound, dsimp [setoid.r, myintrel], rw [add_zero, zero_add, add_comm],\nend\n\nprotected lemma neg_pair' (a b : ℕ) : - [[a,b]] = [[b,a]] := by { apply quotient.sound, dsimp, refl, }\n\n-- Proving `add_assoc` requires three applications of `quotient.ind`.\nprotected lemma add_assoc (n m k : myint) : n + m + k = n + (m + k) :=\nquotient.ind (λ a₁, quotient.ind (λ a₂, quotient.ind\n  (λ a₃, by { simp [add_pair_eq, add_pair, mk], congr' 3; simp [nat.add_assoc] } ) k) m) n \n\n-- Here, `nsmul` is multiplication of a `myint` on the left by a `nat`.\nprotected def nsmul : ℕ → myint → myint \n| 0 x            := 0\n| (nat.succ n) x := x + (nsmul n x)\n\ninstance add_semigroup_myint : add_semigroup myint :=\n{ add := add,\n  add_assoc := myint.add_assoc }\n\ninstance add_monoid_myint : add_monoid myint :=\n{ zero := myint.has_zero_myint.zero,\n  zero_add := myint.zero_add,\n  add_zero := myint.add_zero,\n  nsmul := myint.nsmul,\n  nsmul_zero' := λ _, rfl,\n  nsmul_succ' := λ _ _, rfl,\n  ..myint.add_semigroup_myint }\n\nprotected lemma nsmul_eq_nsmul {n : ℕ} {a : myint} : n • a = nsmul n a := rfl\n\nlemma nsmul_myint_pair {n a b : ℕ} : n • ([[a, b]] : myint) = [[n • a, n • b]] :=\nbegin\n  repeat {rw myint.nsmul_eq_nsmul },\n  induction n with n ih,\n  { simpa [add_monoid.nsmul_zero'], },\n  { rw [add_monoid.nsmul_succ', ih], dsimp [mk],\n    rw [add_pair_eq, add_pair, nat.succ_eq_add_one, mk], \n    congr'; linarith,  }\nend\n\ninstance add_comm_semigroup_myint : add_comm_semigroup myint :=\n{ add_comm := myint.add_comm,\n  ..myint.add_semigroup_myint }\n\ninstance sub_neg_monoid_myint : sub_neg_monoid myint :=\n{  ..myint.add_monoid_myint, ..myint.has_neg_myint, ..myint.has_sub_myint }\n\ninstance add_group_myint : add_group myint :=\n{ add_left_neg := myint.add_left_neg, ..myint.sub_neg_monoid_myint }\n\ninstance add_comm_monoid_myint : add_comm_monoid myint :=\n{ ..myint.add_comm_semigroup_myint, ..myint.add_monoid_myint }\n\ninstance add_comm_group_myint : add_comm_group myint :=\n{ ..myint.add_group_myint, ..myint.add_comm_monoid_myint }\n\n-- Having proved that `myint` is a `add_comm_group`, we can use the simplifier to prove theorems\n-- auomatically!\nexample (a b : myint) : a + b - a = b := by simp\n\n-- Replacing `simp` above with `squeeze_simp` shows exactly which lemmas are needed. I used this\n-- to get the following.\nexample (a b : myint) : a + b - a = b := by simp only [add_sub_cancel']\n\n-- The `ac_refl` tactic proves results that need only associativity and commutativity.\nexample (a b c d : myint) : (a + b) + (c + d) = b + (c + a) + d := by ac_refl \n\n-- The `•` symbol below is written `\\smul` and represents the scalar multiplication `nsmul`.\nexample : 3 • (-7 : myint) = -21 := dec_trivial\n\nlemma nonneg_or_neg : ∀ a : myint, ∃ n : ℕ, a = [[n, 0]] ∨ a = [[0, n.succ]] :=\nbegin\n  apply quotient.ind,\n  rintro ⟨a₁, a₂⟩,\n  cases (le_or_lt a₂ a₁) with nonneg neg,\n  { use a₁ - a₂, left, apply quot.sound,\n    dsimp [setoid.r, myintrel], simp [nat.sub_add_cancel, nonneg], },\n  { use (a₂ - a₁).pred, right, apply quot.sound,\n    dsimp [setoid.r, myintrel], simp [nat.add_sub_of_le, neg],\n    rw nat.succ_pred_eq_of_pos,\n    { exact nat.add_sub_of_le (le_of_lt neg) },\n    { exact nat.sub_pos_of_lt neg }, },\nend\n\ndef prod_nat_to_int (n : ℕ × ℕ) : ℤ := n.1 - n.2\n\n/-- A funtion from myint to int. -/\ndef myint_to_int (n : myint) : ℤ :=\nbegin\n  apply quotient.lift_on n prod_nat_to_int, intros a b h,\n  dsimp [has_equiv.equiv, setoid.r, myintrel] at h,\n  dsimp [prod_nat_to_int], linarith,\nend\n\nlemma myint_to_int_of_pair (n m : ℕ) : myint_to_int [[n, m]] = n - m := rfl\n\nexample : myint_to_int [[6,13]] = -7 := rfl\n\n/-- The function `myint_to_int` is additive. -/\nprotected lemma map_add_myint_to_int : ∀ n m : myint, myint_to_int (n + m) = myint_to_int n + myint_to_int m :=\nbegin\n  apply quotient.ind₂,\n  rintro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩,\n  rw [add_pair_eq, add_pair, ←mk, ←mk],\n  repeat { rw myint_to_int_of_pair },\n  push_cast, linarith,\nend\n\n/-- Wwe define `myint_to_int_hom`, an (additve group) homomorphism from `myint` to `int`. -/\ndef myint_to_int_add_monoid_hom : myint →+ ℤ :=\n{ to_fun := myint_to_int,\n  map_zero' := rfl,\n  map_add' := myint.map_add_myint_to_int }\n\n/-- The function `myint_to_int` has an inverse function. We first define a function `int_to_prod_nat` -/\ndef int_to_prod_nat : ℤ → ℕ × ℕ\n| (int.of_nat n)          := (n, 0)\n| (int.neg_succ_of_nat n) := (0, nat.succ n)\n\nexample : int_to_prod_nat (-5) = (0,5) := rfl\n\n/-- `int_my_myint` is the composite of `quotient.mk` and `int_to_prod_nat`.-/\ndef int_to_myint (n : ℤ) :  myint := ⟦int_to_prod_nat n⟧\n\nexample : int_to_myint (-5) = [[0, 5]] := rfl\n\n/-- We show that `myint_to_int` is an equivalence. Here, `myint ≃ int` is notation for `equiv myint int`. -/\ndef myint_to_int_equiv : myint ≃ int := \n{ to_fun := myint_to_int,\n  inv_fun := int_to_myint,\n  left_inv :=\n  by { intro n, rcases (nonneg_or_neg n) with ⟨a, rfl | rfl⟩; { rw myint_to_int_of_pair, norm_cast, }, },\n  right_inv := by {rintro ⟨_, _⟩; refl, }, }\n\n/-\nFor free, we have an additive equivalence (i.e. a group isomomorphism) from `myint` to `int`.\nHere, `myint ≃+ int` is notation for `add_equiv myint int`.\n-/\ndef myint_to_int_add_equiv : myint ≃+ int :=\n{ ..myint_to_int_equiv, ..myint_to_int_add_monoid_hom }\n\n/-\nUsing this equivalence, we get (for free) that the equivalence respects orders of elements.\n-/\nexample (a : myint) : add_order_of (myint_to_int a) = add_order_of a :=\nlet f := myint_to_int_add_equiv in add_order_of_injective (f.to_add_monoid_hom) (f.injective) a\n\nend myint", "meta": {"author": "gihanmarasingha", "repo": "myint", "sha": "eba85880a500a7977cc4e23c9fa51877dfc82b58", "save_path": "github-repos/lean/gihanmarasingha-myint", "path": "github-repos/lean/gihanmarasingha-myint/myint-eba85880a500a7977cc4e23c9fa51877dfc82b58/src/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430812881347, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7695781621013998}}
{"text": "import algebra.invertible\nimport tactic.linarith\nimport tactic.field_simp\nimport order.filter.at_top_bot\n\nsection fields\nvariables {F : Type*}\n\ndef cube_root_unity_a [field F] (root_three_i : F) : F :=\n  (-1 + root_three_i)/2\n\ndef cube_root_unity_b [field F] (root_three_i : F) : F :=\n  (-1 - root_three_i)/2\n\nlemma multiply_out_cubed [field F] (x y : F) : (x + y) * (x + y) * (x + y) =\n        (x * x * x) + (3 * x * x * y) + (3 * x * y * y) + (y * y * y) :=\nbegin\n  ring,\nend\n\n/- If F isn't of characteristic 2, 2^3 ≠ 0 also.-/\nlemma eight_ne_zero [field F] (two_ne_zero : (2 : F) ≠ (0 : F)) : (8 : F) ≠ (0 : F) :=\nbegin\n  have cubed : (2 : F) * (2 : F) * (2 : F) = (8 : F),\n    ring,\n  rw <- cubed, clear cubed,\n  exact mul_ne_zero (mul_ne_zero two_ne_zero two_ne_zero) two_ne_zero,\nend\n\nlemma twenty_seven_ne_zero [field F] (three_ne_zero : (3 : F) ≠ (0 : F)) :\n  (27 : F) ≠ (0 : F) :=\nbegin\n  have cubed : (3 : F) * (3 : F) * (3 : F) = (27 : F),\n    ring,\n  rw <- cubed, clear cubed,\n  exact mul_ne_zero (mul_ne_zero three_ne_zero three_ne_zero) three_ne_zero,\nend\n\n@[simp] lemma cubrt_unity_a_correct [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    (cube_root_unity_a root_three_i) * (cube_root_unity_a root_three_i) * (cube_root_unity_a root_three_i)\n     = 1 :=\nbegin\n  unfold cube_root_unity_a,\n  have simp_numerator : (-1 + root_three_i) * (-1 + root_three_i) * (-1 + root_three_i) = 8,\n    rw multiply_out_cubed, rw rt3_i_correct,\n    repeat {rw mul_neg_one}, repeat {rw neg_neg},\n    rw mul_assoc (-3) root_three_i root_three_i, rw rt3_i_correct,\n    ring,\n  calc (-1 + root_three_i) / 2 * ((-1 + root_three_i) / 2) * ((-1 + root_three_i) / 2)\n       = (-1 + root_three_i) * (-1 + root_three_i) / (2 * 2) * ((-1 + root_three_i) / 2)\n          : by rw div_mul_div\n   ... = ((-1 + root_three_i) * (-1 + root_three_i) * (-1 + root_three_i) / (2 * 2 * 2))\n          : by rw div_mul_div\n   ... = 8 / (2 * 2 * 2) : by rw simp_numerator\n   ... = 8 / 8 : by ring_nf\n   ... = 1 : by rw div_self (eight_ne_zero two_ne_zero),\nend\n\n@[simp] lemma cubrt_unity_b_correct [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    (cube_root_unity_b root_three_i) * (cube_root_unity_b root_three_i) * (cube_root_unity_b root_three_i)\n     = 1 :=\nbegin\n  have switch_roots : (cube_root_unity_b root_three_i) = (cube_root_unity_a (- root_three_i)),\n    unfold cube_root_unity_b, unfold cube_root_unity_a, ring_nf,\n  rw switch_roots, clear switch_roots,\n  have neg_rt3_i_correct : (-root_three_i) * (-root_three_i) = (-3),\n    rw neg_mul_neg, exact rt3_i_correct,\n  exact cubrt_unity_a_correct (-root_three_i) neg_rt3_i_correct two_ne_zero,\nend\n\n@[simp] lemma cube_roots_unity_sum_zero [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    (cube_root_unity_a root_three_i) + (cube_root_unity_b root_three_i) = -1 :=\nbegin\n  unfold cube_root_unity_a, unfold cube_root_unity_b,\n  field_simp, ring,\nend\n\n@[simp] lemma cubrt_unity_a_ne_zero [field F] (root_three_i : F)\n  (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n  (cube_root_unity_a root_three_i) ≠ 0 :=\nbegin\n  have one_ne_zero : 1 ≠ (0 : F), simp,\n  intros h, rw <- cubrt_unity_a_correct at one_ne_zero,\n  rw h at one_ne_zero, simp at one_ne_zero, cc,\n  repeat {assumption},\nend\n\n@[simp] lemma cubrt_unity_a_reciprocal [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    1/(cube_root_unity_a root_three_i) = (cube_root_unity_b root_three_i) :=\nbegin\n  have root_ne_zero : (cube_root_unity_a root_three_i) ≠ 0,\n    exact cubrt_unity_a_ne_zero root_three_i rt3_i_correct two_ne_zero,\n  field_simp, unfold cube_root_unity_a, unfold cube_root_unity_b,\n  field_simp, rw left_distrib, rw sub_eq_add_neg, repeat {rw right_distrib},\n  rw neg_mul_comm root_three_i root_three_i,\n  rw <- neg_mul_eq_mul_neg root_three_i root_three_i,\n  rw rt3_i_correct, ring,\nend\n\n@[simp] lemma cubrt_unity_b_ne_zero [field F] (root_three_i : F)\n  (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n  (cube_root_unity_b root_three_i) ≠ 0 :=\nbegin\n  rw <- cubrt_unity_a_reciprocal root_three_i rt3_i_correct two_ne_zero, apply one_div_ne_zero,\n  exact cubrt_unity_a_ne_zero root_three_i rt3_i_correct two_ne_zero,\nend\n\n@[simp] lemma cubrt_unity_b_reciprocal [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    1/(cube_root_unity_b root_three_i) = (cube_root_unity_a root_three_i) :=\nbegin\n  have tmp : ∀(a b : F), 1 / a = 1 / b -> a = b,\n    intros a b h, simp at h, exact h,\n  apply tmp, rw one_div_one_div, symmetry,\n  exact cubrt_unity_a_reciprocal root_three_i rt3_i_correct two_ne_zero,\nend\n\n@[simp] lemma cubrts_unity_mul_one [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    (cube_root_unity_a root_three_i) * (cube_root_unity_b root_three_i) = 1 :=\nbegin\n  rw <- cubrt_unity_a_reciprocal root_three_i rt3_i_correct two_ne_zero,\n  rw mul_div_cancel',\n  exact cubrt_unity_a_ne_zero root_three_i rt3_i_correct two_ne_zero,\nend\n\n@[simp] lemma cubrt_unity_a_squ [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    (cube_root_unity_a root_three_i) * (cube_root_unity_a root_three_i) = (cube_root_unity_b root_three_i)\n :=\nbegin\n  have h : (cube_root_unity_a root_three_i) *\n              (cube_root_unity_a root_three_i) *\n              (cube_root_unity_a root_three_i)\n               / (cube_root_unity_a root_three_i) = 1 * (cube_root_unity_b root_three_i),\n    rw cubrt_unity_a_correct root_three_i rt3_i_correct two_ne_zero,\n    rw cubrt_unity_a_reciprocal root_three_i rt3_i_correct two_ne_zero,\n    rw one_mul,\n  rw mul_div_cancel at h, rw one_mul at h, exact h,\n  exact cubrt_unity_a_ne_zero root_three_i rt3_i_correct two_ne_zero,\nend\n\n@[simp] lemma cubrt_unity_b_squ [field F] (root_three_i : F)\n    (rt3_i_correct : root_three_i * root_three_i = (-3))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) :\n    (cube_root_unity_b root_three_i) * (cube_root_unity_b root_three_i) = (cube_root_unity_a root_three_i)\n :=\nbegin\n  have h : (cube_root_unity_a root_three_i) ≠ 0,\n    exact cubrt_unity_a_ne_zero root_three_i rt3_i_correct two_ne_zero,\n  rw [<- cubrt_unity_a_reciprocal] {occs := occurrences.pos [2]},\n  field_simp, rw cubrt_unity_a_squ, repeat {assumption},\nend\n\ndef depressed_cubic_solution_sqrt [field F] (c d : F) : F :=\n  ((d * d) / (2 * 2)) + ((c * c * c)/27)\n\ndef depressed_cubic_solution_cube_root [field F] (d root  : F) : F :=\n  -(d / 2) + root\n\ndef depressed_cubic_solution [field F] (c cubrt : F) : F :=\n  cubrt + (-c / (3 * cubrt))\n\nlemma add_three_thirds [field F] (x : F) (three_ne_zero : (3 : F) ≠ (0 : F)) :\n  (x / 3) + (x / 3) + (x / 3) = x :=\nbegin\n  repeat {rw div_add_div_same}, ring_nf, rw mul_comm, rw mul_div_cancel x three_ne_zero,\nend\n\nlemma rationalise_denominator [field F] (num den sqrt square : F) :\n  (den - sqrt ≠ (0 : F)) ->\n  (sqrt * sqrt = square) ->\n  (num / (den + sqrt)) = (num * (den - sqrt)) / ((den * den) - square) :=\nbegin\n  intros ne_zero h_sqrt, rw <- h_sqrt, clear h_sqrt,\n  have two_squares : (den * den - sqrt * sqrt) = (den + sqrt) * (den - sqrt),\n    ring,\n  rw two_squares, clear two_squares,\n  rw <- div_mul_div, rw div_self ne_zero, simp,\nend\n\nlemma tmp_nonzero [field F] (c d sqrt : F) (not_char_three : (3 : F) ≠ (0 : F)):\n    (sqrt * sqrt = depressed_cubic_solution_sqrt c d) ->\n    (c ≠ (0 : F)) ->\n       (sqrt -(d / 2) ≠ (0 : F)) :=\nbegin\n  intros h_sqrt c_ne_zero, intros h,\n  rw sub_eq_zero at h, symmetry' at h,\n  have h_squ : (-(d / 2)) * (-(d / 2)) = (sqrt * sqrt),\n    rw h, clear h,\n    rw neg_mul_neg,\n  clear h,\n  rw h_sqrt at h_squ, unfold depressed_cubic_solution_sqrt at h_squ,\n  have tmp2 : -(d / 2) * -(d / 2) = (d * d) / (2 * 2),\n    rw neg_mul_neg, rw div_mul_div,\n  rw tmp2 at h_squ, clear tmp2, symmetry' at h_squ,\n  have h_iszero : c * c * c / 27 = 0,\n    rw add_right_eq_self at h_squ, exact h_squ,\n  clear h_sqrt,\n  have ne_zero : c * c * c ≠ (0 : F),\n    exact mul_ne_zero (mul_ne_zero c_ne_zero c_ne_zero) c_ne_zero,\n  exact div_ne_zero ne_zero (twenty_seven_ne_zero not_char_three) h_iszero,\nend\n\n/- The cubic formula involves dividing by multiples of three and of two,\n     so we need additional arguments to assert that the relevant field\n     is neither of characteristic 2 nor 3.-/\nlemma depressed_cubic_solution_correct [field F] (c d x sqrt cubrt : F)\n    (c_ne_zero : c ≠ (0 : F))\n    (two_ne_zero : (2 : F) ≠ (0 : F)) (three_ne_zero : (3 : F) ≠ (0 : F)) :\n  (sqrt * sqrt) = (depressed_cubic_solution_sqrt c d) ->\n  (cubrt * cubrt * cubrt) = (depressed_cubic_solution_cube_root d sqrt) ->\n  (x = (depressed_cubic_solution c cubrt) -> (x * x * x) + (c * x) + d = 0) :=\nbegin\n  intros h_sqrt h_cubrt, unfold depressed_cubic_solution,\n  have cubrt_ne_zero : cubrt ≠ (0 : F),\n    intros h, unfold depressed_cubic_solution_cube_root at h_cubrt,\n    symmetry' at h_cubrt, rw h at h_cubrt, rw mul_zero at h_cubrt,\n    rw add_comm at h_cubrt, rw <- sub_eq_add_neg at h_cubrt,\n    exact tmp_nonzero c d sqrt three_ne_zero h_sqrt c_ne_zero h_cubrt,\n  intros h,\n  rw h, clear h, repeat {rw right_distrib},\n                 repeat {rw left_distrib}, repeat {rw right_distrib},\n  rw h_cubrt,\n  rw neg_div, repeat {rw <- neg_mul_eq_mul_neg}, repeat {rw <- neg_mul_eq_neg_mul},\n  repeat {rw neg_neg}, repeat {rw div_mul_div},\n  repeat {rw mul_assoc}, repeat {rw mul_comm (3 : F) (_ * _)},\n  rw mul_comm (3 : F) cubrt, repeat {rw <- mul_assoc},\n  rw h_cubrt, clear h_cubrt,\n\n  /- We need to do some boring rearranging to eliminate the fractional powers\n      of the cube root.-/\n  rw div_mul_eq_mul_div_comm cubrt c (cubrt * 3),\n  have cancel_cubrt : (c / (cubrt * 3)) * cubrt = c / 3,\n    rw mul_comm _ cubrt, rw mul_div_comm,\n    rw div_mul_right (3 : F) cubrt_ne_zero,\n    rw <- div_eq_mul_one_div,\n  rw mul_assoc _ cubrt (c / (cubrt * 3)),\n  rw mul_assoc _ (c / (cubrt * 3)) cubrt,\n  repeat {rw mul_comm cubrt (c / (cubrt * 3))},\n  repeat {rw cancel_cubrt}, clear cancel_cubrt,\n  rw div_mul_right (3 : F) cubrt_ne_zero,\n  rw mul_div_comm c 1 3, rw one_mul,\n  rw mul_comm (c / 3) cubrt,\n  repeat {rw add_assoc}, rw add_comm (c / 3 * (c / (cubrt * 3))) _,\n  rw <- add_assoc (-(cubrt * (c / 3))) (-(cubrt * (c / 3))) _,\n  rw <- neg_add, rw add_assoc, rw <- add_assoc (-_) (-(cubrt * (c / 3))) _,\n  rw <- neg_add,\n  rw <- mul_div_assoc, rw add_three_thirds (cubrt * c) three_ne_zero,\n  repeat {rw <- add_assoc _ (c * cubrt) _, rw add_comm _ (c * cubrt),\n          rw add_assoc (c * cubrt) _ _},\n  rw mul_comm cubrt c,\n  rw add_assoc (c * cubrt) _ _, rw <- add_assoc (-(c * cubrt)) (c * cubrt),\n  rw <- sub_eq_neg_add (c * cubrt) (c * cubrt), rw sub_self, rw zero_add,\n\n  repeat {rw mul_assoc cubrt _ _}, rw mul_comm ((c * c)/_) cubrt,\n  rw mul_div_comm cubrt (c * c), rw div_mul_right _ cubrt_ne_zero,\n  rw add_comm (-(c * c * c / _)) _,\n  rw add_comm _ (c / 3 * (c / (cubrt * 3))),\n\n  have tmp_1 : (c * c * (1 / (cubrt * (3 * 3)))) = ((c * (c / (cubrt * 3))) / 3),\n    field_simp, ring,\n  rw tmp_1, clear tmp_1,\n  have tmp_2 : (c / 3 * (c / (cubrt * 3))) = ((c * (c / (cubrt * 3))) / 3),\n    field_simp, ring,\n  rw tmp_2, clear tmp_2,\n  repeat {rw add_assoc},\n  rw <- add_assoc (c * (c / (cubrt * 3)) / 3) (c * (c / (cubrt * 3)) / 3) _,\n  rw <- add_assoc (c * (c / (cubrt * 3)) / 3 + c * (c / (cubrt * 3)) / 3) (c * (c / (cubrt * 3)) / 3) _,\n  rw add_three_thirds _ three_ne_zero,\n  rw <- add_assoc (c * _) (-_) _, rw add_comm (c * _) (-_),\n  rw <- sub_eq_neg_add, rw sub_self, rw zero_add,\n\n  unfold depressed_cubic_solution_cube_root,\n  have tmp : (c * c * c / ((-(d / 2) + sqrt) * 3 * 3 * 3)) =\n             (c * c * c) / (-(d / 2) + sqrt) * 1 / (3 * 3 * 3),\n    field_simp, ring_nf, rw <- mul_assoc, rw <- mul_assoc,\n  rw tmp, clear tmp,\n  have neg_sqrt : -sqrt * -sqrt = depressed_cubic_solution_sqrt c d,\n    rw neg_mul_neg, exact h_sqrt,\n  have nonzero : -(d / 2) - sqrt ≠ 0,\n    rw sub_eq_add_neg, rw add_comm, rw <- sub_eq_add_neg,\n    exact tmp_nonzero c d (-sqrt) three_ne_zero neg_sqrt c_ne_zero,\n  rw rationalise_denominator (c * c * c) (-(d/2)) sqrt (depressed_cubic_solution_sqrt c d)\n\t    nonzero h_sqrt,\n  unfold depressed_cubic_solution_sqrt,\n  rw neg_mul_neg, rw div_mul_div, rw sub_add_eq_sub_sub,\n  rw sub_self,\n  field_simp, ring,\nend\n\ndef depressed_cubic_x [field F] (a b x : F) : F :=\n    x + (b / (3 * a))\n\ndef depressed_cubic_x_term [field F] (a b c : F) : F :=\n    (3 * a * c - (b * b)) / (3 * a * a)\n\ndef depressed_cubic_constant [field F] (a b c d : F) : F :=\n    (((2 * b * b * b) - (9 * a * b * c)) / (27 * a * a * a)) + (d / a)\n\nlemma convert_cubic_to_depressed [field F] (a b c d x : F)\n    (a_ne_zero : a ≠ 0) (three_ne_zero : (3 : F) ≠ (0 : F)) :\n  (a * x * x * x) + (b * x * x) + (c * x) + d =\n  a * (((depressed_cubic_x a b x) * (depressed_cubic_x a b x) * (depressed_cubic_x a b x))\n  + (depressed_cubic_x_term a b c) * (depressed_cubic_x a b x)\n  + (depressed_cubic_constant a b c d)) :=\nbegin\n  unfold depressed_cubic_constant, unfold depressed_cubic_x_term,\n  unfold depressed_cubic_x,\n  have tmp : ∀ (a b : F), (a - b = 0) -> (a = b),\n    intros a b h, have h1 : (a - b + b) = (0 + b), rw h, simp at h1, exact h1,\n  apply tmp, field_simp, clear tmp,\n  rw mul_div_assoc, rw div_mul_left a_ne_zero,\n  have tmp : 3 * a * (3 * a) * (3 * a) = (27 * a * a) * a,\n    ring,\n  rw tmp, clear tmp, repeat {rw mul_assoc (27 * a * a)},\n  have den_ne_zero : (27 * a * a) ≠ 0,\n    repeat {apply mul_ne_zero}, exact twenty_seven_ne_zero three_ne_zero, repeat {assumption},\n  field_simp, ring,\nend\n\ndef cubic_formula [field F] (a b c cubrt : F) : F :=\n  depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt - (b / (3 * a))\n\ndef cubic_formula_cubrt [field F] (a b c d sqrt : F) : F :=\n  depressed_cubic_solution_cube_root (depressed_cubic_constant a b c d) sqrt\n\ndef cubic_formula_sqrt [field F] (a b c d : F) : F :=\n  depressed_cubic_solution_sqrt (depressed_cubic_x_term a b c) (depressed_cubic_constant a b c d)\n\nlemma cubic_solution [field F] (a b c d x sqrt cubrt : F)\n  (a_ne_zero : a ≠ 0) (two_ne_zero : (2 : F) ≠ 0) (three_ne_zero : (3 : F) ≠ 0)\n  (int_quantity_ne_zero : (depressed_cubic_x_term a b c ≠ 0)):\n\n  (sqrt * sqrt = (cubic_formula_sqrt a b c d)) ->\n  (cubrt * cubrt * cubrt = (cubic_formula_cubrt a b c d sqrt)) ->\n  (x = (cubic_formula a b c cubrt)) ->\n  (a * x * x * x) + (b * x * x) + (c * x) + d = 0 :=\nbegin\n  intros h_sqrt h_cubrt h_x,\n  unfold cubic_formula at h_x,\n  rw convert_cubic_to_depressed a b c d x a_ne_zero three_ne_zero,\n  have h : depressed_cubic_x a b x = depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt,\n    unfold depressed_cubic_x, rw h_x, ring,\n  rw h,\n  have triv : depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt =\n              depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt,\n    refl,\n  unfold cubic_formula_sqrt at h_sqrt,\n  unfold cubic_formula_cubrt at h_cubrt,\n  have eq_zero : (depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt * depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt * depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt + depressed_cubic_x_term a b c * depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt + depressed_cubic_constant a b c d)\n                  = 0,\n    exact depressed_cubic_solution_correct (depressed_cubic_x_term a b c) (depressed_cubic_constant a b c d) (depressed_cubic_solution (depressed_cubic_x_term a b c) cubrt) sqrt cubrt int_quantity_ne_zero two_ne_zero three_ne_zero h_sqrt h_cubrt triv,\n  rw eq_zero, ring,\nend\n\nlemma multiply_out_cubic [field F] (x a b c : F) :\n  (x + a) * (x + b) * (x + c) =\n  x * x * x + (a + b + c) * x * x + (a * b + a * c + b * c) * x + (a * b * c) :=\nbegin\n  ring,\nend\n\nlemma depressed_cubic_solution_unique [field F] (c d x sqrt cubrt rt3_i : F)\n      (two_ne_zero : (2 : F) ≠ (0 : F)) (three_ne_zero : (3 : F) ≠ (0 : F))\n      (c_ne_zero : c ≠ (0 : F)) :\n  (sqrt * sqrt) = (depressed_cubic_solution_sqrt c d) ->\n  (cubrt * cubrt * cubrt) = (depressed_cubic_solution_cube_root d sqrt) ->\n  (rt3_i * rt3_i = (-3)) ->\n  (x ≠ (depressed_cubic_solution c cubrt)) ->\n   (x ≠ (depressed_cubic_solution c (cubrt * (cube_root_unity_a rt3_i)))) ->\n   (x ≠ (depressed_cubic_solution c (cubrt * (cube_root_unity_b rt3_i)))) ->\n  ((x * x * x) + (c * x) + d ≠ 0) :=\nbegin\n  intros h_sqrt h_cubrt h_rt3i,\n  have cubrt_ne_zero : cubrt ≠ 0,\n    intros cubrt_zero, rw cubrt_zero at h_cubrt, rw mul_zero at h_cubrt,\n    symmetry' at h_cubrt, unfold depressed_cubic_solution_cube_root at h_cubrt,\n    rw add_comm at h_cubrt, rw <- sub_eq_add_neg at h_cubrt,\n    exact tmp_nonzero c d sqrt three_ne_zero h_sqrt c_ne_zero h_cubrt,\n  have h : (x - depressed_cubic_solution c cubrt) *\n           (x - depressed_cubic_solution c (cubrt * cube_root_unity_a rt3_i)) *\n           (x - depressed_cubic_solution c (cubrt * cube_root_unity_b rt3_i))\n           =\n           x * x * x + c * x + d,\n    repeat {rw sub_eq_add_neg}, rw multiply_out_cubic,\n    have x_squ : (-depressed_cubic_solution c cubrt + -depressed_cubic_solution c (cubrt * cube_root_unity_a rt3_i) + -depressed_cubic_solution c (cubrt * cube_root_unity_b rt3_i))\n                  = 0,\n      unfold depressed_cubic_solution, field_simp,\n      repeat {rw <- mul_assoc}, rw div_mul_eq_div_mul_one_div _ _ (cube_root_unity_a _),\n      rw cubrt_unity_a_reciprocal,\n      rw div_mul_eq_div_mul_one_div _ _ (cube_root_unity_b _),\n      rw cubrt_unity_b_reciprocal,\n      field_simp,\n      unfold cube_root_unity_a, unfold cube_root_unity_b, field_simp, ring,\n      repeat {assumption},\n    repeat {rw <- add_assoc}, repeat {rw mul_comm _ cubrt}, rw x_squ, clear x_squ,\n    repeat {rw zero_mul}, rw add_zero,\n    have x_term : (-depressed_cubic_solution c cubrt *\n                        -depressed_cubic_solution c (cubrt * cube_root_unity_a rt3_i) +\n                   -depressed_cubic_solution c cubrt *\n                        -depressed_cubic_solution c (cubrt * cube_root_unity_b rt3_i) +\n                    -depressed_cubic_solution c (cubrt * cube_root_unity_a rt3_i) *\n                        -depressed_cubic_solution c (cubrt * cube_root_unity_b rt3_i))\n                  = c,\n      unfold depressed_cubic_solution, field_simp,\n      repeat {rw <- mul_assoc}, rw div_mul_eq_div_mul_one_div _ _ (cube_root_unity_a _),\n      rw cubrt_unity_a_reciprocal,\n      rw div_mul_eq_div_mul_one_div _ _ (cube_root_unity_b _),\n      rw cubrt_unity_b_reciprocal,\n      field_simp,\n      repeat {rw mul_comm _ (cube_root_unity_a _)}, repeat {rw mul_comm _ (cube_root_unity_b _)},\n      simp only [left_distrib, right_distrib, <- neg_mul_eq_mul_neg, <- neg_mul_eq_neg_mul],\n      rw mul_comm (cube_root_unity_b rt3_i) c, rw mul_assoc c (cube_root_unity_b _) _,\n      rw <- mul_assoc (cube_root_unity_b _) (cube_root_unity_a _) _,\n      rw mul_comm (cube_root_unity_b _) (cube_root_unity_a _), rw cubrts_unity_mul_one,\n      rw mul_assoc (cube_root_unity_a rt3_i), rw mul_comm (cube_root_unity_a rt3_i),\n      rw mul_assoc (cube_root_unity_b rt3_i), repeat {rw mul_assoc _ (cube_root_unity_a _)},\n      rw <- mul_assoc (cube_root_unity_a _) (cube_root_unity_b _) _,\n      rw cubrts_unity_mul_one,\n      rw <- mul_assoc (cube_root_unity_a _) (cube_root_unity_a _) _,\n      rw cubrt_unity_a_squ,\n      repeat {rw mul_assoc _ (cube_root_unity_b _) _},\n      rw <- mul_assoc (cube_root_unity_b _) (cube_root_unity_b _) _,\n      rw cubrt_unity_b_squ,\n      unfold cube_root_unity_a, unfold cube_root_unity_b, field_simp, ring,\n      repeat {assumption},\n    repeat {rw mul_comm _ cubrt}, rw x_term, clear x_term,\n    have constant_term : (-depressed_cubic_solution c cubrt * -depressed_cubic_solution c (cubrt * cube_root_unity_a rt3_i) * -depressed_cubic_solution c (cubrt * cube_root_unity_b rt3_i))\n                          = d,\n      have four_ne_zero : (4 : F) ≠ 0,\n        have tmp : (4 : F) = 2 * 2, ring, rw tmp,\n        exact mul_ne_zero two_ne_zero two_ne_zero,\n      have twenty_seven_ne_zero : (27 : F) ≠ 0,\n        have tmp : (27 : F) = 3 * (3 * 3), ring, rw tmp,\n        exact mul_ne_zero three_ne_zero (mul_ne_zero three_ne_zero three_ne_zero),\n      unfold depressed_cubic_solution,\n      repeat {rw div_mul_eq_div_mul_one_div},\n      repeat {rw cubrt_unity_a_reciprocal}, repeat {rw cubrt_unity_b_reciprocal},\n      field_simp,\n      have unfold : (c + -(cubrt * (3 * cubrt))) * (c * cube_root_unity_b rt3_i + -(cubrt * cube_root_unity_a rt3_i * (3 * cubrt))) * (c * cube_root_unity_a rt3_i + -(cubrt * cube_root_unity_b rt3_i * (3 * cubrt)))\n              =\n              c ^ 3 * ((cube_root_unity_a rt3_i) * (cube_root_unity_b rt3_i)) -\n              3 * (c * cubrt) ^ 2 * (((cube_root_unity_a rt3_i) * (cube_root_unity_b rt3_i)) + ((cube_root_unity_a rt3_i) * (cube_root_unity_a rt3_i)) + ((cube_root_unity_b rt3_i) * (cube_root_unity_b rt3_i))) +\n              9 * c * cubrt ^ 4 * (((cube_root_unity_a rt3_i) * (cube_root_unity_b rt3_i)) + ((cube_root_unity_a rt3_i) * (cube_root_unity_a rt3_i)) + ((cube_root_unity_b rt3_i) * (cube_root_unity_b rt3_i))) -\n              27 * (cubrt ^ 6) * ((cube_root_unity_a rt3_i) * (cube_root_unity_b rt3_i)),\n        ring,\n      rw unfold, clear unfold,\n      rw cubrts_unity_mul_one, rw cubrt_unity_a_squ, rw cubrt_unity_b_squ,\n      rw add_assoc _ (cube_root_unity_b rt3_i) (cube_root_unity_a rt3_i),\n      rw add_comm (cube_root_unity_b rt3_i) (cube_root_unity_a rt3_i),\n      rw cube_roots_unity_sum_zero, rw add_right_neg, repeat {rw mul_zero},\n      rw mul_one, rw sub_zero, rw add_zero, rw mul_one,\n      have tmp : (cubrt ^ 6) = (cubrt * cubrt * cubrt) * (cubrt * cubrt * cubrt),\n        ring, rw tmp, clear tmp,\n      have tmp : (3 * cubrt * (3 * cubrt) * (3 * cubrt)) = 27 * (cubrt * cubrt * cubrt),\n        ring, rw tmp, clear tmp,\n      rw h_cubrt, unfold depressed_cubic_solution_cube_root,\n      have unfold : ((-(d / 2) + sqrt) * (-(d / 2) + sqrt)) =\n                      d * d / 4 - d * sqrt + sqrt * sqrt,\n        field_simp, ring,\n      rw unfold, clear unfold, rw h_sqrt, unfold depressed_cubic_solution_sqrt,\n      field_simp, ring,\n      repeat {assumption},\n    rw constant_term,\n  intros h_s1 h_s2 h_s3, rw <- sub_ne_zero at h_s1, rw <- sub_ne_zero at h_s2, rw <- sub_ne_zero at h_s3,\n  rw <- h, clear h,\n  apply mul_ne_zero, apply mul_ne_zero, repeat {assumption},\nend\n\nlemma cubic_solution_unique [field F] (a b c d x sqrt cubrt rt3_i : F)\n      (a_ne_zero : a ≠ (0 : F))\n      (one_ne_zero : (1 : F) ≠ (0 : F)) (two_ne_zero : (2 : F) ≠ (0 : F)) (three_ne_zero : (3 : F) ≠ (0 : F))\n      (int_quantity_ne_zero : (depressed_cubic_x_term a b c ≠ 0)) :\n  (sqrt * sqrt = (cubic_formula_sqrt a b c d)) ->\n  (cubrt * cubrt * cubrt = (cubic_formula_cubrt a b c d sqrt)) ->\n  (rt3_i * rt3_i = (-3)) ->\n  (x ≠ (cubic_formula a b c cubrt)) ->\n   (x ≠ (cubic_formula a b c (cubrt * (cube_root_unity_a rt3_i)))) ->\n   (x ≠ (cubic_formula a b c (cubrt * (cube_root_unity_b rt3_i)))) ->\n  ((a * x * x * x) + (b * x * x) + (c * x) + d ≠ 0) :=\nbegin\n  have twenty_seven_ne_zero : (27 : F) ≠ 0,\n    have tmp : (27 : F) = 3 * (3 * 3), ring, rw tmp, clear tmp,\n    exact mul_ne_zero three_ne_zero (mul_ne_zero three_ne_zero three_ne_zero),\n\n  unfold cubic_formula, intros h_sqrt h_cubrt h_rt3i h_solution1 h_solution2 h_solution3,\n  /- Divide through by the a (which we know isn't zero)... -/\n  have tmp : (1 * x * x * x) + (b / a * x * x) + (c / a * x) + (d / a) ≠ 0 ->\n             (a * x * x * x) + (b * x * x)     + (c * x)     + d       ≠ 0,\n    intros h_tmp, field_simp at h_tmp, field_simp,\n    have tmp_tmp : a * x * x * x = x * x * x * a, ring,\n    rw tmp_tmp, exact h_tmp,\n  apply tmp, clear tmp,\n  rw convert_cubic_to_depressed, rw one_mul,\n\n  have x_term_simplify : (depressed_cubic_x_term a b c) = (depressed_cubic_x_term 1 (b / a) (c / a)),\n    unfold depressed_cubic_x_term, field_simp, ring,\n  rw <- x_term_simplify, clear x_term_simplify,\n  have minor : b / a / (3 * 1) = b / (3 * a), field_simp, left, rw mul_comm,\n  apply depressed_cubic_solution_unique\n        (depressed_cubic_x_term a b c)\n        (depressed_cubic_constant 1 (b / a) (c / a) (d / a))\n        (depressed_cubic_x 1 (b / a) x) sqrt cubrt rt3_i,\n  repeat {assumption},\n\n  rw h_sqrt, unfold cubic_formula_sqrt, unfold depressed_cubic_x_term,\n             unfold depressed_cubic_constant, unfold depressed_cubic_solution_sqrt,\n  field_simp, ring,\n\n  rw h_cubrt, unfold cubic_formula_cubrt,\n              unfold depressed_cubic_constant, unfold depressed_cubic_solution_cube_root,\n  field_simp, ring,\n\n  all_goals {unfold depressed_cubic_x, rw minor},\n  all_goals {have tmp : ∀ (rt : F),\n                \tx ≠ depressed_cubic_solution (depressed_cubic_x_term a b c) rt - b / (3 * a) ->\n                \tx + b / (3 * a) ≠ depressed_cubic_solution (depressed_cubic_x_term a b c) rt,\n    intros rt h1 h2, rw <- h2 at h1, simp at h1, cc},\n  exact tmp _ h_solution1,\n  exact tmp _ h_solution2,\n  exact tmp _ h_solution3,\nend\n\nend fields\n", "meta": {"author": "anonymousLeanDocsHosting", "repo": "lean-polynomials", "sha": "361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613", "save_path": "github-repos/lean/anonymousLeanDocsHosting-lean-polynomials", "path": "github-repos/lean/anonymousLeanDocsHosting-lean-polynomials/lean-polynomials-361ef4cb7b68ef47d43b85cfa2d13f2ea0a47613/mathlib/cubic_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7695640360164712}}
{"text": "-- Declare our domain of discourse \nvariable (α : Type) \n\n-- Declare some predicates \nvariable (P Q : α → Prop) \n\n#check ∀ (x:α), P x \n\ntheorem test (x : α) : P x := sorry \n\n-- ∀ (x:α), P x is fun (x: α) => P x \n#check test \n\n-- Introduction rule is just to a map a function \nexample : ∀ x, P x → P x := fun x => fun (h : P x) => h\n\n-- Elimination rule is function application \nexample (h₁ : ∀ x, P x → Q x) (h₂ : ∀ x, P x) : ∀ x, Q x := fun (x:α) => h₁ x (h₂ x)\n\n-- Once more slowly in tactic mode \nexample (h₁ : ∀ x, P x → Q x) (h₂ : ∀ x, P x) : ∀ x, Q x := by\n  intro (x : α) \n  have g₁ : P x := by exact h₂ x \n  have g₂ : P x → Q x := by exact h₁ x \n  exact g₂ g₁\n\n--  \n#check ∃ (x:α), P x\n\n#check exists (x:α), P x\n\n-- ∃ introduction is a built-in structure\nexample (x:α) (h:P x) : ∃ y, P y := Exists.intro x h \n\n#check @Exists α \n#check @Exists.intro α \n\n-- Guess\n#check @Exists.elim α \n\nexample (h : ∃ y, ¬ P y) :  ¬ (∀ x, P x) := by \n  intro (g : ∀ x, P x)\n  apply Exists.elim h \n  intro (a : α) \n  intro (l : ¬ P a)   \n  exact l (g a) \n\n-- Equality: reflexivity, symmetry, and transitivity \n#check @Eq α \n#check @Eq.refl\n#check @Eq.symm \n#check @Eq.trans\n\n#check @rfl\n\n-- Substituion for predicates \n#check @Eq.subst \n\nexample (x y : α) (h : x = y) (g : P x) : P y := Eq.subst h g \n\n-- Substitution for functions \nexample (β : Type) (x y : α) (h : x = y) (f : α → β) : f x = f y := congrArg f h \n\n#check @congrArg\n\n-- Can use the rewrite tactic - rw \nexample (β : Type) (x y : α) (h : x = y) (f : α → β) : f x = f y := by \n  rw [h]\n\nexample (x: α) : x=x := by \n  rfl \n\nvariable (A B : Prop)\ntheorem not_true : A → B := sorry\n#check not_true\n\nexample : ∀ (x : α), P x → ∃ (y : α), P y := by \n  intro (a : α)\n  intro (h : P a)\n  exact ⟨a, h⟩\n\nvariable (C : α → α → Prop) \n\nexample : (∃ (x:α), ∀ (y:α), C x y) → ∀ (v:α), ∃ (u:α), C u v := by \n  intro h v \n  apply Exists.elim h \n  intro g f \n  apply Exists.intro \n  exact f v \n\nvariable (P : α → Prop)\n\nexample : (¬ ∃ y, P y) → ∀ x, ¬ P x := by \n  intro h a n \n  exact h ⟨a,n⟩\n\nexample (f : α → α) (x y : α) (h₁ : x = y) (h₂ : P (f x)) : P (f y) := by \n  rw [h₁] at h₂ \n  assumption \n\nvariable (x y z : α) \n\nexample (h₁ : x = y) (h₂ : z = x) (f : α → α) : f y = f z := by \n  rw [← h₁, h₂] \n  -- calc\n  --   f y = f y := by rfl \n  --   _ = f x := by rw [←h₁]\n  --   _ = f z := by rw \n  --\nexample : (∀ x, P x → ¬ Q x) → ¬ ∃ y, P y ∧ Q y := by \n  intro h n \n  apply Exists.elim n \n  intro a g \n  exact h a g.left g.right \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-notes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8519528076067261, "lm_q1q2_score": 0.7695640310604043}}
{"text": "-- Igualdad_de_bloques_de_una_particion_cuando_tienen_elementos_comunes.lean\n-- Igualdad de bloques de una partición cuando tienen elementos comunes\n-- José A. Alonso Jiménez\n-- Sevilla, 30 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Este ejercicio es el primero de una serie cuyo objetivo es demostrar\n-- que el tipo de las particiones de un conjunto `X` es isomorfo al tipo\n-- de las relaciones de equivalencia sobre `X`. El desarrollo de dicha\n-- serie está basado en la [cuarta parte](https://bit.ly/3AQWY7o) de la\n-- primera sesión del curso de Kevin Buzzard\n-- \"Formalising mathematics: workshop 1 — logic, sets, functions,\n-- relations\" (https://bit.ly/3kJo231).\n--\n-- Una [partición](https://bit.ly/3uplABS) de un conjunto A es un conjunto\n-- de subconjuntos no vacíos de A tal que todo elemento de A está\n-- exactamente en uno de dichos subconjuntos. Es decir, una famila de\n-- conjuntos C es una partición de A si se verifican las siguientes\n-- condiciones:\n-- + Los conjuntos de C son no vacíos; es decir,\n--      ∀ X ∈ C, X ≠ ∅.\n-- + Los conjuntos de C recubren A; es decir,\n--      ∀ a ∈ A, ∃ X ∈ C, a ∈ X\n-- + Los conjuntos de C son disjuntos entre sí; es decir,\n--      ∀ X Y ∈ C, X ∩ Y ≠ ∅ → X = Y\n--\n-- En Lean, se puede definir el tipo de las particiones sobre un tipo A\n-- mediante una estructura con 4 campos:\n-- +  Un conjunto de subconjuntos de A llamados los bloques de la partición.\n-- + Una prueba de que los bloques son no vacíos.\n-- + Una prueba de que cada término de tipo A está en uno de los bloques.\n-- + Una prueba de que dos bloques con intersección no vacía son iguales.\n-- Su definición es\n--     @[ext] structure particion (A : Type) :=\n--     (Bloques    : set (set A))\n--     (Hno_vacios : ∀ X ∈ Bloques, (X : set A).nonempty)\n--     (Hrecubren  : ∀ a, ∃ X ∈ Bloques, a ∈ X)\n--     (Hdisjuntos : ∀ X Y ∈ Bloques, (X ∩ Y : set A).nonempty → X = Y)\n--\n-- Con la definición anterior,\n-- + `P : particion A` expresa que `P` es una partición de `A`.\n-- + `Bloques P` es el conjunto de los bloque de P.\n-- + `Hno_vacios P` prueba que los bloques de `P` son no vacíos.\n-- + `Hrecubren P` prueba que los bloque de `P` recubren a `A`.\n-- + `Hdisjuntos p` prueba que los bloques de `P` son disjuntos entre sí\n--\n-- Demostrar que si dos bloques de una partición tienen un elemento en\n-- común, entonces son iguales.\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n@[ext] structure particion (A : Type) :=\n(Bloques    : set (set A))\n(Hno_vacios : ∀ X ∈ Bloques, (X : set A).nonempty)\n(Hrecubren  : ∀ a, ∃ X ∈ Bloques, a ∈ X)\n(Hdisjuntos : ∀ X Y ∈ Bloques, (X ∩ Y : set A).nonempty → X = Y)\n\nnamespace particion\n\nvariable  {A : Type}\nvariable  {P : particion A}\nvariables {X Y : set A}\n\n-- 1ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nbegin\n  apply P.Hdisjuntos,\n  { exact hX, },\n  { exact hY, },\n  { rw set.nonempty_def,\n    use a,\n    split,\n    { exact haX, },\n    { exact haY, }},\nend\n\n-- 2ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nbegin\n  apply P.Hdisjuntos,\n  { exact hX, },\n  { exact hY, },\n  { use a,\n    exact ⟨haX, haY⟩, },\nend\n\n-- 3ª demostración\nexample\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nbegin\n  apply P.Hdisjuntos,\n  { exact hX, },\n  { exact hY, },\n  { exact ⟨a, haX, haY⟩, },\nend\n\n-- 4ª demostración\nlemma iguales_si_comun\n  (hX : X ∈ Bloques P)\n  (hY : Y ∈ Bloques P)\n  {a : A}\n  (haX : a ∈ X)\n  (haY : a ∈ Y)\n  : X = Y :=\nHdisjuntos P X hX Y hY ⟨a, haX, haY⟩\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/Igualdad_de_bloques_de_una_particion_cuando_tienen_elementos_comunes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7695640298829001}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, 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 : ℚ) : ℚ := rat.mk (int.sqrt q.num) (nat.sqrt q.denom)\n\n/-* Let $q$ be rational, then the square root of $q * q$ is $|q|$. *-/\ntheorem sqrt_eq (q : ℚ) : rat.sqrt (q*q) = |q| :=\nby rw [sqrt, mul_self_num, mul_self_denom, int.sqrt_eq, nat.sqrt_eq, abs_def]\n\n/-* Let $x$ be rational, then there exists a rational number $q$ such that $q * q$ equals to $x$\nif and only if the square of square root of $x$ equals to $x$. *-/\ntheorem exists_mul_self (x : ℚ) : (∃ q, q * q = x) ↔ rat.sqrt x * rat.sqrt x = x :=\n⟨λ ⟨n, hn⟩, by rw [← hn, sqrt_eq, abs_mul_abs_self],\nλ h, ⟨rat.sqrt x, h⟩⟩\n\n/-* Let $q$ be rational, then the square root of $q$ is non negative. *-/\ntheorem sqrt_nonneg (q : ℚ) : 0 ≤ rat.sqrt q :=\nnonneg_iff_zero_le.1 $ (mk_nonneg _ $ int.coe_nat_pos.2 $\nnat.pos_of_ne_zero $ λ 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": "subfish-zhou", "repo": "N2Lean", "sha": "8e858cc5b01f1ad921094dc355db3cb9473a42fd", "save_path": "github-repos/lean/subfish-zhou-N2Lean", "path": "github-repos/lean/subfish-zhou-N2Lean/N2Lean-8e858cc5b01f1ad921094dc355db3cb9473a42fd/data/rat/sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7695140517530119}}
{"text": "/-\n  Definition of diagonally dominant matrices and tactic.\n-/\n\nimport data.matrix.basic \nimport data.matrix.notation\nimport data.rat.basic \nimport data.finset.basic\n\nimport tactic.fin_cases\nimport tactic.linarith\n\nopen_locale big_operators\n\ndef diagdom {n : ℕ} (A : matrix (fin n) (fin n) ℚ) : Prop :=\n∀ i, (∑ j, if i ≠ j then abs (A i j) else 0) ≤ abs (A i i)\n\nnamespace diagdom \n\nopen tactic\nopen interactive (parse)\nopen lean.parser (ident)\n\nprivate meta def unfold_matrix : tactic unit :=\ndo \n  `(diagdom %%M) ← target,\n  dunfold_target [name.from_string M.to_string] {}\n\nmeta def prove_diagdom : tactic unit :=\n`[unfold_matrix, intros i, fin_cases i; simp only [fin.sum_univ_succ]; dec_trivial]\n\ndef I2 : matrix (fin 2) (fin 2) ℚ := \n![![1, 0], \n  ![0, 1]]\n\ndef I4 : matrix (fin 4) (fin 4) ℚ :=\n![![1, 0, 0, 0], \n  ![0, 1, 0, 0], \n  ![0, 0, 1, 0], \n  ![0, 0, 0, 1]]\n\ndef A : matrix (fin 3) (fin 3) ℚ :=\n![![ 3, -2,  1],\n  ![ 1, -3,  2],\n  ![-1,  2,  4]]\n\ndef F : matrix (fin 9) (fin 9) ℚ :=\n![![1, 0.04, 0.05, 0.04, 0.02, 0.01, 0.02, 0.05, 0.03], \n  ![0.02, 1, 0.02, 0.02, 0.03, 0.02, 0.04, 0.04, 0.02], \n  ![0.04, 0.02, 1, 0.05, 0.05, 0.04, 0.03, 0.05, 0.03], \n  ![0.05, 0.04, 0.03, 1, 0.02, 0.05, 0.03, 0.02, 0.03], \n  ![0.03, 0.03, 0.05, 0.03, 1, 0.02, 0.04, 0.01, 0.03], \n  ![0.05, 0.04, 0.02, 0.01, 0.03, 1, 0.04, 0.05, 0.04], \n  ![0.03, 0.04, 0.04, 0.02, 0.02, 0.03, 1, 0.01, 0.01], \n  ![0.04, 0.03, 0.01, 0.02, 0.05, 0.02, 0.02, 1, 0.02], \n  ![0.05, 0.01, 0.03, 0.04, 0.04, 0.05, 0.03, 0.03, 1]]\n\nset_option profiler true\n\nset_option timeout 10000000\n\nexample : diagdom I2 := by prove_diagdom \n\nexample : diagdom I4 := by prove_diagdom\n\nexample : diagdom A := by prove_diagdom\n\n--example : diagdom F := by prove_diagdom\n\nend diagdom\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/lib/diagdom.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7694575061867309}}
{"text": "-- Ejercicios sobre aritmética real\n-- ================================\n\n-- ------------------------------------------------------\n-- Ejercicio 1. Ejecutar las siguientes acciones:\n-- 1. Importar la teoría de los números reales.\n-- 2. Declarar a, b, c y d como variables sobre los \n--    reales. \n-- ------------------------------------------------------\n\nimport data.real.basic     -- 1\nvariables (a b c d : ℝ)    -- 2\n\n-- -------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    (c * b) * a = b * (a * c)\n-- -------------------------------------------------------\n\n-- 1ª demostración\nexample : (c * b) * a = b * (a * c) :=\nbegin\n  rw mul_comm c b,\n  rw mul_assoc,\n  rw mul_comm c a,\nend\n\n-- 2ª demostración\nexample : (c * b) * a = b * (a * c) :=\nbegin\n  calc (c * b) * a = (b * c) * a : by rw mul_comm c b\n               ... = b * (c * a) : by rw mul_assoc\n               ... = b * (a * c) : by rw mul_comm c a,\nend\n\n-- 3ª demostración\nexample : (c * b) * a = b * (a * c) :=\nby linarith\n\n-- 4ª demostración\nexample : (c * b) * a = b * (a * c) :=\nby finish\n\n-- 5ª demostración\nexample : (c * b) * a = b * (a * c) :=\nby ring\n\n-- -------------------------------------------------------\n-- Ejercicio 3. Demostrar que si\n--    c = b * a - d \n--    d = a * b\n-- entonces c = 0.\n-- -------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (h1 : c = b * a - d) \n  (h2 : d = a * b) \n  : c = 0 :=\nbegin\n  rw h2 at h1,\n  rw mul_comm b a at h1,\n  rw sub_self (a * b) at h1,\n  exact h1,\nend\n\n-- 2ª demostración\nexample \n  (h1 : c = b * a - d) \n  (h2 : d = a * b) \n  : c = 0 :=\nbegin\n  calc c = b * a - d     : by rw h1\n     ... = b * a - a * b : by rw h2 \n     ... = a * b - a * b : by rw mul_comm a b\n     ... = 0             : by rw sub_self (a*b),\nend\n\n-- 3ª demostración\nexample \n  (h1 : c = b * a - d) \n  (h2 : d = a * b) \n  : c = 0 :=\nbegin\n  calc c = b * a - d     : by rw h1\n     ... = b * a - a * b : by rw h2 \n     ... = 0             : by ring,\nend\n\n-- -------------------------------------------------------\n-- Ejercicio 4. Demostrar que\n--    (a + b) + a = 2 * a + b\n-- -------------------------------------------------------\n\n-- 1ª demostración\nexample : (a + b) + a = 2 * a + b :=\nbegin\n  calc (a + b) + a = a + (b + a) : by rw add_assoc\n               ... = a + (a + b) : by rw add_comm b a\n               ... = (a + a) + b : by rw ← add_assoc\n               ... = 2 * a + b   : by rw two_mul,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : (a + b) + a = 2 * a + b :=\nby ring\n\n-- -------------------------------------------------------\n-- Ejercicio 5. Demostrar que\n--    (a + b) * (a - b) = a^2 - b^2\n-- -------------------------------------------------------\n\n-- 1ª demostración\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nbegin\n  rw pow_two a,\n  rw pow_two b,\n  rw mul_sub (a + b) a b,\n  rw add_mul a b a,\n  rw add_mul a b b,\n  rw mul_comm b a,\n  rw ← sub_sub,\n  rw ← add_sub,\n  rw sub_self,\n  rw add_zero,\nend\n\n-- 2ª demostración\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nbegin\n  calc (a + b) * (a - b) \n           = (a + b) * a - (a + b) * b       \n                : by rw mul_sub (a + b) a b\n       ... = a * a + b * a - (a + b) * b     \n                : by rw add_mul a b a\n       ... = a * a + b * a - (a * b + b * b) \n                : by rw add_mul a b b\n       ... = a * a + a * b - (a * b + b * b) \n                : by rw mul_comm b a\n       ... = a * a + a * b - a * b - b * b   \n                : by rw sub_sub\n       ... = a * a + (a * b - a * b) - b * b \n                : by rw add_sub\n       ... = a * a + 0 - b * b               \n                : by rw sub_self\n       ... = a * a - b * b                   \n                : by rw add_zero\n       ... = a^2 - b * b                     \n                : by rw pow_two a\n       ... = a^2 - b^2                       \n                : by rw pow_two b,\nend\n\n-- 3ª demostración\nexample : (a + b) * (a - b) = a^2 - b^2 :=\nby ring\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/Ejercicios_sobre_aritmetica_real_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7692883511978146}}
{"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 ring_theory.polynomial.chebyshev\nimport data.complex.exponential\n\n/-!\n# Multiple angle formulas in terms of Chebyshev polynomials\n\n* `polynomial.chebyshev.T_complex_cos`: the `n`-th Chebyshev polynomial evaluates on `complex.cos θ`\n  to the value `complex.cos (n * θ)`.\n-/\n\nnamespace polynomial.chebyshev\n\nopen polynomial complex\n\n/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the\nvalue `cos (n * θ)`. -/\nlemma T_complex_cos (θ : ℂ) :\n  ∀ n, (T ℂ n).eval (cos θ) = cos (n * θ)\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 θ * sin θ = 1 - cos θ * cos θ,\n  { rw ← sin_sq_add_cos_sq θ, 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 * θ)` is equal to the `n`-th Chebyshev polynomial of the first kind evaluated\non `cos θ`. -/\nlemma cos_nat_mul (n : ℕ) (θ : ℂ) :\n  cos (n * θ) = (T ℂ n).eval (cos θ) :=\n(T_complex_cos θ n).symm\n\n/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the\nvalue `sin ((n+1) * θ) / sin θ`. -/\nlemma U_complex_cos (θ : ℂ) (n : ℕ) :\n  (U ℂ n).eval (cos θ) * sin θ = sin ((n+1) * θ) :=\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) * θ)` is equal to `sin θ` multiplied with the `n`-th Chebyshev polynomial of the\nsecond kind evaluated on `cos θ`. -/\nlemma sin_nat_succ_mul (n : ℕ) (θ : ℂ) :\n  sin ((n + 1) * θ) = (U ℂ n).eval (cos θ) * sin θ :=\n(U_complex_cos θ n).symm\n\nend polynomial.chebyshev\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/trigonometric/chebyshev.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.7692381013929472}}
{"text": "import .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 (7 points): Even Numbers as a Subtype\n\nUsually, the most convenient way to represent even natural numbers is to use the\nlarger type `ℕ`, 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ℕ` of even natural numbers, using the `even`\npredicate introduced in the lecture 5 demo. -/\n\n#print even\n\ndef evℕ : 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 : ℕ} (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ℕ.zero : evℕ :=\nsorry\n\ndef evℕ.add (m n : evℕ) : evℕ :=\nsorry\n\n/-! 1.4 (4 points). Prove that addition of even numbers is commutative and\nassociative, and has 0 as an identity element. -/\n\nlemma evℕ.add_comm (m n : evℕ) :\n  evℕ.add m n = evℕ.add n m :=\nsorry\n\nlemma evℕ.add_assoc (l m n : evℕ) :\n  evℕ.add (evℕ.add l m) n = evℕ.add l (evℕ.add m n) :=\nsorry\n\nlemma evℕ.add_iden_left (n : evℕ) :\n  evℕ.add evℕ.zero n = n :=\nsorry\n\nlemma evℕ.add_iden_right (n : evℕ) :\n  evℕ.add n evℕ.zero = n :=\nsorry\n\n\n/-! ## Question 2 (2 points + 1 bonus point): Hilbert Choice\n\n2.1 (1 bonus point). Prove the following lemma. -/\n\nlemma exists_minimal_arg.aux (f : ℕ → ℕ) :\n  ∀x m, f m = x → ∃n, ∀i, f n ≤ f i\n| x m eq :=\n  begin\n    cases' classical.em (∃n, f n < x),\n    sorry, sorry\n  end\n\n/-! Now this interesting lemma falls off: -/\n\nlemma exists_minimal_arg (f : ℕ → ℕ) :\n  ∃n : ℕ, ∀i : ℕ, f n ≤ f i :=\nexists_minimal_arg.aux f _ 0 (by refl)\n\n/-! 2.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 : ℕ → ℕ) : ℕ :=\nsorry\n\n/-! 2.3 (1 point). Prove the following characteristic lemma about your\ndefinition. -/\n\nlemma minimal_arg_spec (f : ℕ → ℕ) :\n  ∀i : ℕ, f (minimal_arg f) ≤ f i :=\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/love11_logical_foundations_of_mathematics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7692180514612861}}
{"text": "import algebra.big_operators algebra.group_power data.pnat M3P14.Arithmetic_functions.phi\n\n-- positive naturals\n-- todo: add all the properties of dirichlet conv\n\nnamespace nat\n\nopen list\n\n/-- returns the finset of divisors of a positive natural -/\ndefinition factors_new (d : ℕ+) : list ℕ := \n  filter (λ e, e ∣ d) (range (d+1))\n\n#eval factors_new 6 -- [1, 2, 3, 6]\n\nlemma mem_factors_iff_divides (d : ℕ+) (e : ℕ) : e ∈ factors_new d ↔ e ∣ d :=\n by simp [factors_new, -add_comm, nat.lt_succ_iff];\n    exact and_iff_right_of_imp (le_of_dvd d.2)\n\nlemma nodup_factors (d : ℕ+) : nodup (factors_new 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  {β : Type*} [add_comm_monoid β] (f : ℕ → β) (d : ℕ+) : β := \nfinset.sum (⟨quotient.mk (factors_new d),nodup_factors d⟩) f\n\ndef perfect_num (n : ℕ+) : Prop :=  divisor_sum id n = 2*n\n\n--theorem perfect_number_iff_mersenne (n p: ℕ+) (hp: prime p) : perfect_num n ↔ n = 2^(p-1)*((2^p)-1)\n\ninstance : decidable_pred perfect_num := λ _, by unfold perfect_num; apply_instance\n\ntheorem divisor_sum_phi (n : ℕ+) : divisor_sum (phi) n = n := sorry \n\n#eval divisor_sum (id) (6) -- it's a perfect number!\n#reduce (perfect_num 6 : bool)\n#eval (perfect_num 5 : bool)\n\n--dirichlet convolution\ndef conv (f g : ℕ → ℕ) := λ (n : pnat), divisor_sum (λ d, f d * g (n / d)) n\n\n--#eval conv phi id\n\n-- lemmas about conv\n\nlemma conv_is_comm (f g : ℕ → ℕ) : conv f g = conv g f := sorry\n--lemma conv_is_assoc (f g h : ℕ → ℕ) : conv (conv f g) h = conv f (conv g h) := sorry\n\n--lemma conv_is_add_dist (f g h : ℕ → ℕ) : conv f (g + h) = conv f g + conv f h\n\n--lemma conv_id_is_conv (f : ℕ → ℕ) : conv f id = f := sorry\n\n--lemma conv_mul_is_mul (f g : ℕ → ℕ) : is_mult f \n\n--lemma conv_has_inv (f : ℕ → ℕ) (hp : f 1 ≠ 0) : ∃ g : conv f g = id := sorry\nend nat \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/sum_over_divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391621868804, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7691912286449021}}
{"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\n\nopen function polynomial finsupp finset\nopen_locale big_operators classical\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}\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 ≠ 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = ⊤`. -/\ndef trailing_degree (p : polynomial R) : with_top ℕ := p.support.inf some\n\nlemma trailing_degree_lt_wf : well_founded\n(λp 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 `ℕ`, by defining\n`nat_trailing_degree ⊤ = 0`. -/\ndef nat_trailing_degree (p : polynomial R) : ℕ := (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 ↔ 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) = ⊤ := rfl\n\n@[simp] lemma trailing_coeff_zero : trailing_coeff (0 : polynomial R) = 0 := 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 = ⊤ ↔ p = 0 :=\n⟨λ h, by rw [trailing_degree, ← min_eq_inf_with_top] at h;\n  exact support_eq_empty.1 (min_eq_none.1 h),\nλ h, by simp [h]⟩\n\nlemma trailing_degree_eq_nat_trailing_degree (hp : p ≠ 0) :\n  trailing_degree p = (nat_trailing_degree p : with_top ℕ) :=\nlet ⟨n, hn⟩ :=\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 : ℕ} (hp : p ≠ 0) :\n  p.trailing_degree = n ↔ 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 : ℕ} (hn : 0 < n) :\n  p.trailing_degree = n ↔ p.nat_trailing_degree = n :=\nbegin\n  split,\n  { intro H, rwa ← 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 : ℕ}\n  (h : trailing_degree p = n) : nat_trailing_degree p = n :=\nhave hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,\noption.some_inj.1 $ show (nat_trailing_degree p : with_top ℕ) = n,\n  by rwa [← trailing_degree_eq_nat_trailing_degree hp0]\n\n@[simp] lemma nat_trailing_degree_le_trailing_degree :\n  ↑(nat_trailing_degree p) ≤ trailing_degree p :=\nbegin\n  by_cases hp : p = 0, { rw [hp, trailing_degree_zero], 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 ≠ 0) : trailing_degree p ≤ n :=\nshow @has_le.le (with_top ℕ) _ (p.support.inf some : with_top ℕ) (some n : with_top ℕ),\nfrom finset.inf_le (mem_support_iff.2 h)\n\nlemma nat_trailing_degree_le_of_ne_zero (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n :=\nbegin\n  rw [← with_top.coe_le_coe, ← 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) ≠ 0) :\n  trailing_degree q ≤ 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 : ℕ} :\n  p.nat_trailing_degree ≠ n → trailing_degree p ≠ n :=\nmt $ λ h, by rw [nat_trailing_degree, h, option.get_or_else_coe]\n\ntheorem nat_trailing_degree_le_of_trailing_degree_le {n : ℕ} {hp : p ≠ 0}\n  (H : (n : with_top ℕ) ≤ trailing_degree p) : n ≤ 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 ≠ 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 ≠ 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) ≤ n :=\nif ha : a = 0 then by simp [ha] else (nat_trailing_degree_monomial ha).le\n\nlemma le_trailing_degree_monomial : ↑n ≤ 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 ≠ 0) : trailing_degree (C a) = (0 : with_top ℕ) :=\ntrailing_degree_monomial ha\n\nlemma le_trailing_degree_C : (0 : with_top ℕ) ≤ trailing_degree (C a) :=\nle_trailing_degree_monomial\n\nlemma trailing_degree_one_le : (0 : with_top ℕ) ≤ trailing_degree (1 : polynomial R) :=\nby rw [← 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 : ℕ) : nat_trailing_degree (n : polynomial R) = 0 :=\nby simp only [←C_eq_nat_cast, nat_trailing_degree_C]\n\n@[simp] lemma trailing_degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 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 : ℕ) (a : R) :\n  (n : with_top ℕ) ≤ 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 ℕ) < 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 : ℕ}\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  { rw [hp, trailing_degree_zero], 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 ℕ) < 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 : ℕ) :\n  (n : with_top ℕ) ≤ 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 ℕ) ≤ trailing_degree (X : polynomial R) :=\nle_trailing_degree_monomial\n\nlemma nat_trailing_degree_X_le : (X : polynomial R).nat_trailing_degree ≤ 1 :=\nnat_trailing_degree_monomial_le\n\n@[simp] lemma trailing_coeff_eq_zero : trailing_coeff p = 0 ↔ p = 0 :=\n⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1\n  (not_not.2 h) (mem_of_min (trailing_degree_eq_nat_trailing_degree hp)),\nλ h, h.symm ▸ leading_coeff_zero⟩\n\nlemma trailing_coeff_nonzero_iff_nonzero : trailing_coeff p ≠ 0 ↔ p ≠ 0 :=\nnot_congr trailing_coeff_eq_zero\n\nlemma nat_trailing_degree_mem_support_of_nonzero : p ≠ 0 → nat_trailing_degree p ∈ p.support :=\n(mem_support_iff.mpr ∘ trailing_coeff_nonzero_iff_nonzero.mpr)\n\nlemma nat_trailing_degree_le_of_mem_supp (a : ℕ) :\n  a ∈ p.support → nat_trailing_degree p ≤ a:=\nnat_trailing_degree_le_of_ne_zero ∘ mem_support_iff.mp\n\nlemma nat_trailing_degree_eq_support_min' (h : p ≠ 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 ≤ 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 ≠ 0) (n : ℕ) :\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 (λ h, mt trailing_coeff_eq_zero.mp hp _),\n    rwa [trailing_coeff, ←coeff_mul_X_pow] },\n  { rw [nat_trailing_degree_eq_support_min' (λ h, hp (mul_X_pow_eq_zero h)), finset.le_min'_iff],\n    intros y hy,\n    have key : n ≤ y,\n    { rw [mem_support_iff, coeff_mul_X_pow'] at hy,\n      exact by_contra (λ 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) },\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 ℕ) :=\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 : ℤ) : nat_trailing_degree (n : polynomial R) = 0 :=\nby simp only [←C_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} {ι : 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 ℕ} (h : trailing_degree p < n) : p ≠ 0 :=\nλ h₀, h.not_le (by simp [h₀])\n\nend semiring\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/trailing_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7689984576741539}}
{"text": "import data.set.basic\nimport data.nat.basic\nimport logic.basic\n\nopen set\nopen nat\n\nuniverse u\n\n-- Exercise 1\n-- Exercise 2\n-- Exercise 3\n--   I know I shouldn't, but I'm skipping these because I want to learn how to\n--   prove things I can't just show using a normal programming language.\n\n-- Exercise 4\nsection\n    lemma union_empty (α : Type u) (A : set α) :\n        A ∪ ∅ = A :=\n        begin\n            rw union_def,\n            ext a,\n            rw mem_set_of_eq,\n            rw mem_empty_eq,\n            rw or_false,\n        end\n\n    lemma intersection_empty (α : Type u) (A : set α) :\n        A ∩ ∅ = ∅ :=\n        begin\n            rw inter_def,\n            ext a,\n            rw mem_set_of_eq,\n            repeat {rw mem_empty_eq},\n            rw and_false,\n        end\nend\n\n-- Exercise 5\nsection\n    lemma union_comm (α : Type u) (A B : set α) :\n        A ∪ B = B ∪ A :=\n        begin\n            repeat {rw union_def},\n            ext,\n            repeat {rw mem_set_of_eq},\n            rw or_comm,\n        end\n\n    lemma intersection_comm (α : Type u) (A B : set α) :\n        A ∩ B = B ∩ A :=\n        begin\n            repeat {rw inter_def},\n            ext,\n            repeat {rw mem_set_of_eq},\n            rw and_comm,\n        end\nend\n\n-- Exercise 6\nsection\n    lemma union_distrib (α : Type u) (A B C : set α) :\n        A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) :=\n        begin\n            repeat {rw inter_def},\n            repeat {rw union_def},\n\n            ext a,\n\n            repeat {rw mem_set_of_eq},\n            rw or_and_distrib_left,\n        end\nend\n\n-- Exercise 7\nsection\n    lemma inter_distrib (α : Type u) (A B C : set α) :\n        A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=\n        begin\n            repeat {rw inter_def},\n            repeat {rw union_def},\n\n            ext a,\n\n            repeat {rw mem_set_of_eq},\n            rw and_or_distrib_left,\n        end\nend\n\n-- Exercise 8\n-- TODO: this is horrible\nsection\n    lemma subset_inter (α : Type u) (A B : set α) :\n        (A ⊆ B) ↔ (A ∩ B = A) :=\n        begin\n            split,\n\n            {\n                assume h,\n                ext,\n                rw inter_def,\n                rw mem_set_of_eq,\n\n                split,\n\n                -- Proving x ∈ A ∧ x ∈ B → x ∈ A\n                assume h',\n                cases h' with hl hr,\n                apply hl,\n\n                -- Proving x ∈ A → x ∈ A ∧ x ∈ B\n                assume hl,\n                rw subset_def at h,\n                have hr : x ∈ B, from (h x) hl,\n                apply and.intro hl hr,\n            },\n\n            {\n                assume h,\n                rw <- h,\n                assume x : α,\n                rw [inter_def, mem_set_of_eq],\n                assume h',\n                cases h' with hl hr,\n                apply hr,\n            },\n        end\nend\n\n-- Exercise 9\n-- TODO: Syntax for complement?\n-- section\n--     lemma complement_inter (α : Type u) (A B : set α) :\n--         (A ∩ B)\n-- end\n\n-- Exercise 10\nsection\n    lemma union_minus_identity (α : Type u) (A B : set α) :\n        (A ∪ B) = (A ∩ B) ∪ (A \\ B) ∪ (B \\ A) :=\n        begin\n            sorry,\n        end\nend\n\n-- Exercise 11\n-- section\n--     lemma right_times_dist (α : Type u) (A B C : set α) :\n--         (A ∪ B) × C = (A × C) ∪ (B × C) :=\n--         begin\n--             sorry,\n--         end\n-- end\n\n-- Exercise 12\nsection\n    lemma cap_minus_empty (α : Type u) (A B : set α) :\n        (A ∩ B) \\ B = ∅ :=\n        begin\n            ext,\n            rw diff_eq,\n            rw inter_assoc,\n            rw inter_compl_self,\n            rw inter_empty,\n        end\nend\n\n-- Exercise 13\nsection\n    lemma union_minus_identity' (α : Type u) (A B : set α) :\n        (A ∪ B) \\ B = A \\ B :=\n        begin\n            ext,\n\n            rw diff_eq,\n            rw inter_comm,\n            rw inter_distrib,\n            rw [inter_comm (-B) A, inter_comm (-B) B],\n            rw inter_compl_self,\n            rw set.union_empty,\n            rw <- diff_eq,\n        end\nend\n\n-- Exercise 14\n\n-- Exercise 15\n\n-- Exercise 16\n\n-- Exercise 17\n\n-- Exercise 18\n\n-- Exercise 19\n\n-- Exercise 20\n\n-- Exercise 21\n\n-- Exercise 22\n\n-- Exercise 23\n\n-- Exercise 24\n\n-- Exercise 25\n\n-- Exercise 26\n\n-- Exercise 27\n\n-- Exercise 28\n\n-- Exercise 29\n\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/aata/chapter1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7689755096480926}}
{"text": "import Scripts.set_theory\n--===========================--\n------ CONJUNTOS FINITOS ------\n--===========================--\n\nstructure finite {α : Type u} {β : Type v} [Membership α β] (b : β) where\n  list : List α\n  all_in_list : ∀ {a}, a ∈ b → a ∈ list  -- a ∈ list es equivalente a List.Mem \n                                        --a list (hay una instancia de Membership \n                                        -- para listas con mem = List.Mem)\n\n\ninductive is_finite {α : Type u} {β : Type v} [Membership α β] (b : β) : Prop where\n  | intro : finite b → is_finite b\n\n\n----------------------------------------\n--- Propiedades de conjuntos finitos ---\n----------------------------------------\n\n-- El conjunto vacío es finito\ntheorem is_finite_empty {α : Type u} : is_finite (∅ : Set α) := \n  let list := []\n  have all_in_list : ∀ {a}, a ∈ (∅ : Set α) → a ∈ list := fun h => h.elim\n  is_finite.intro ⟨list, all_in_list⟩\n\n-- Los conjuntos unitatios son finitos\ntheorem is_finite_singleton (a : α) : is_finite { a } :=\n  let list := [a]\n  have obv : a ∈ list := List.Mem.head  []\n  have all_in_list : ∀ {b}, b ∈ ({ a } : Set α) → b ∈ list := fun h => h ▸ obv\n  is_finite.intro ⟨list, all_in_list⟩\n\n-- La unión de conjuntos finitos es finito\ntheorem is_finite_union {s t : Set α} : is_finite s → is_finite t → is_finite (s ∪ t) :=\n  fun (is_finite.intro ⟨list_s, all_in_list_s⟩) (is_finite.intro ⟨list_t, all_in_list_t⟩) =>\n    let list := list_s ++ list_t \n    have all_in_list : ∀ {a}, a ∈ (s ∪ t) → a ∈ list := fun hunion => \n      hunion.elim (fun hsa => List.mem_append_of_mem_left list_t (all_in_list_s hsa))\n                  (fun hta => List.mem_append_of_mem_right list_s (all_in_list_t hta))\n    is_finite.intro ⟨list, all_in_list⟩\n\n#check @List.mem_append_of_mem_right -- ∀ {α : Type u_1} {b : α} {bs : List α} (as : List α), b ∈ bs → b ∈ as ++ bs\n\n\n--------------------------------------------------\n--- Conjuntos finitos (definición alternativa) ---\n--------------------------------------------------\ninductive is_finite_alt : Set α → Prop where\n  | empty : is_finite_alt ∅\n  | singleton : ∀ a, is_finite_alt { a }\n  | union : ∀ {s t}, is_finite_alt s → is_finite_alt t → is_finite_alt (s ∪ t)\n\n-----------------------------------------------------------------\n--- Propiedades de conjuntos finitos (definición alternativa) ---\n-----------------------------------------------------------------\n\ntheorem is_finite_inter_with_finite  {s t : Set α} : is_finite_alt t → is_finite_alt (s ∩ t) := \n  fun hfinitet =>\n    match hfinitet with \n    | is_finite_alt.empty => \n      (eq_inter_empty s).symm ▸ is_finite_alt.empty\n    | is_finite_alt.singleton a =>\n      empty_or_singleton_eq_inter_singleton.elim\n      (fun h_empty => h_empty ▸ is_finite_alt.empty)\n      (fun h_single => h_single ▸ is_finite_alt.singleton a)\n    | is_finite_alt.union ht1 ht2 =>\n      eq_inter_union ▸ is_finite_alt.union (is_finite_inter_with_finite ht1) (is_finite_inter_with_finite ht2)\n\ntheorem subset_of_finite {s t : Set α} : s ⊆ t → is_finite_alt t → is_finite_alt s :=\n  fun hsub hfinitet => eq_subset_inter_subset hsub ▸ is_finite_inter_with_finite hfinitet\n\n-- EQUIVALENCIA DE AMBAS DEFINICIONES\n\n-- La siguiete implicación es directa a partir de las propiedades probadas para 'is_finite'\ntheorem is_finite_of_is_finite_alt {s : Set α} : is_finite_alt s → is_finite s :=\n  fun h =>\n    match h with \n    | is_finite_alt.empty => is_finite_empty\n    | is_finite_alt.singleton _ => is_finite_singleton _\n    | is_finite_alt.union ht1 ht2 => is_finite_union (is_finite_of_is_finite_alt ht1) (is_finite_of_is_finite_alt ht2)\n\n-- La implicación contraria requiere de algunos lemas previos\n\ntheorem lemma1 {s : Set α} (h : ∀ {a}, a ∈ s → a ∈ []) : s = ∅ := \n  eq_empty_of_subset_empty (fun hsa => have contr := h hsa; by contradiction)\n\ntheorem lemma2 {a : α} {as : List α} : \n  (fun b => b ∈ (a::as)) = { a } ∪ (fun b => b ∈ as) :=\n    setext \n      ⟨fun hbinlist => \n      match hbinlist with \n      | List.Mem.head as =>\n        Or.inl rfl\n      | List.Mem.tail a h_b_in_as => \n        Or.inr h_b_in_as, \n      fun hunionb =>\n        hunionb.elim\n        (fun hsingle =>\n          hsingle ▸ List.Mem.head as)\n        (fun hbintail =>\n          List.Mem.tail a hbintail)⟩\n\ntheorem lemma3 : ∀ as : List α, is_finite_alt (fun a => a ∈ as) \n  | [] =>\n    have hempty : (fun a => a ∈ []) = (∅ : Set α) := lemma1 id\n    hempty ▸ is_finite_alt.empty\n  | a::as => \n    have div : (fun b => b ∈ (a::as)) = { a } ∪ (fun b => b ∈ as) := lemma2\n    div ▸ is_finite_alt.union (is_finite_alt.singleton a) (lemma3 as)\n\n\ntheorem is_finite_alt_of_is_finite {s : Set α} : is_finite s → is_finite_alt s :=\n  fun (is_finite.intro ⟨list, all_in_list⟩) =>\n  -- 'list' es una lista con los elementos de 's'\n  -- 'all_in_list' es la prueba de que todos los \n  -- elementos de 's' están en 'list'\n    let finiteSet : Set α := (fun b => b ∈ list)\n    have hsub : s ⊆ finiteSet := all_in_list\n    have hfin : is_finite_alt finiteSet := lemma3 list\n    subset_of_finite hsub hfin\n\ntheorem is_finite_iff_is_finite_alt {s : Set α} : is_finite s ↔ is_finite_alt s :=\n  ⟨is_finite_alt_of_is_finite,is_finite_of_is_finite_alt⟩", "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/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7689401027209806}}
{"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 `μ(F) = c * μ(E)`\nfor two sets `E` and `F`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be\nthe characteristic functions of `E` and `F`.\nAssume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`\npreserves the measure `μ.prod ν`, which means that\n```\n  ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ\n```\nIf we apply this to `h x y := e x * f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E)`, we can rewrite the RHS to\n`μ(F)`, and the LHS to `c * μ(E)`, where `c = c(ν)` does not depend on `μ`.\nApplying this to `μ` and to `ν` gives `μ (F) / μ (E) = ν (F) / ν (E)`, which is the uniqueness up to\nscalar multiplication.\n\nThe proof in [Halmos] seems to contain an omission in §60 Th. A, see\n`measure_theory.measure_lintegral_div_measure`.\n\n-/\n\nnoncomputable theory\nopen set (hiding prod_eq) function measure_theory\nopen_locale classical ennreal pointwise measure_theory\n\nvariables (G : Type*) [measurable_space G]\nvariables [group G] [has_measurable_mul₂ G]\nvariables (μ ν : measure G) [sigma_finite ν] [sigma_finite μ]\n\n/-- The map `(x, y) ↦ (x, xy)` as a `measurable_equiv`. This is a shear mapping. -/\n@[to_additive \"The map `(x, y) ↦ (x, x + y)` as a `measurable_equiv`.\nThis is a shear mapping.\"]\nprotected def measurable_equiv.shear_mul_right [has_measurable_inv G] : G × G ≃ᵐ G × 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\nvariables {G}\n\nnamespace measure_theory\n\nopen measure\n\n/-- This condition is part of the definition of a measurable group in [Halmos, §59].\n  There, the map in this lemma is called `S`. -/\n@[to_additive map_prod_sum_eq]\nlemma map_prod_mul_eq [is_mul_left_invariant ν] :\n  map (λ z : G × G, (z.1, z.1 * z.2)) (μ.prod ν) = μ.prod ν :=\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 [measure_preimage_mul, lintegral_indicator _ hs, set_lintegral_const, mul_comm]\nend\n\n/-- The function we are mapping along is `SR` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_add_eq_swap]\nlemma map_prod_mul_eq_swap [is_mul_left_invariant μ] :\n  map (λ z : G × G, (z.2, z.2 * z.1)) (μ.prod ν) = ν.prod μ :=\nbegin\n  rw [← prod_swap],\n  simp_rw [map_map (measurable_snd.prod_mk (measurable_snd.mul measurable_fst)) measurable_swap],\n  exact map_prod_mul_eq ν μ\nend\n\n@[to_additive]\nlemma measurable_measure_mul_right {E : set G} (hE : measurable_set E) :\n  measurable (λ x, μ ((λ y, y * x) ⁻¹' E)) :=\nbegin\n  suffices : measurable (λ y,\n    μ ((λ x, (x, y)) ⁻¹' ((λ z : G × G, ((1 : G), z.1 * z.2)) ⁻¹' ((univ : set G) ×ˢ 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\nvariables [has_measurable_inv G]\n\n/-- The function we are mapping along is `S⁻¹` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq`. -/\n@[to_additive map_prod_neg_add_eq]\nlemma map_prod_inv_mul_eq [is_mul_left_invariant ν] :\n  map (λ z : G × G, (z.1, z.1⁻¹ * z.2)) (μ.prod ν) = μ.prod ν :=\n(measurable_equiv.shear_mul_right G).map_apply_eq_iff_map_symm_apply_eq.mp $ map_prod_mul_eq μ ν\n\n/-- The function we are mapping along is `S⁻¹R` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_neg_add_eq_swap]\nlemma map_prod_inv_mul_eq_swap [is_mul_left_invariant μ] :\n  map (λ z : G × G, (z.2, z.2⁻¹ * z.1)) (μ.prod ν) = ν.prod μ :=\nbegin\n  rw [← 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 ν μ\nend\n\n/-- The function we are mapping along is `S⁻¹RSR` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_add_neg_eq]\nlemma map_prod_mul_inv_eq [is_mul_left_invariant μ] [is_mul_left_invariant ν] :\n  map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod ν) = μ.prod ν :=\nbegin\n  suffices : map ((λ z : G × G, (z.2, z.2⁻¹ * z.1)) ∘ (λ z : G × G, (z.2, z.2 * z.1))) (μ.prod ν) =\n    μ.prod ν,\n  { convert this, ext1 ⟨x, y⟩, simp },\n  simp_rw [← 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 μ ν,\n    map_prod_inv_mul_eq_swap ν μ]\nend\n\n@[to_additive] lemma quasi_measure_preserving_inv [is_mul_left_invariant μ] :\n  quasi_measure_preserving (has_inv.inv : G → G) μ μ :=\nbegin\n  refine ⟨measurable_inv, absolutely_continuous.mk $ λ s hsm hμs, _⟩,\n  rw [map_apply measurable_inv hsm, inv_preimage],\n  have hf : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=\n    (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  suffices : map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (s⁻¹ ×ˢ s⁻¹) = 0,\n  { simpa only [map_prod_mul_inv_eq μ μ, prod_prod, mul_eq_zero, or_self] using this },\n  have hsm' : measurable_set (s⁻¹ ×ˢ s⁻¹) := 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μs, lintegral_zero]\nend\n\n@[to_additive]\nlemma measure_inv_null [is_mul_left_invariant μ] {E : set G} :\n  μ ((λ x, x⁻¹) ⁻¹' E) = 0 ↔ μ E = 0 :=\nbegin\n  refine ⟨λ hE, _, (quasi_measure_preserving_inv μ).preimage_null⟩,\n  convert (quasi_measure_preserving_inv μ).preimage_null hE,\n  exact (inv_inv _).symm\nend\n\n@[to_additive]\nlemma lintegral_lintegral_mul_inv [is_mul_left_invariant μ] [is_mul_left_invariant ν]\n  (f : G → G → ℝ≥0∞) (hf : ae_measurable (uncurry f) (μ.prod ν)) :\n  ∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ :=\nbegin\n  have h : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=\n  (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  have h2f : ae_measurable (uncurry $ λ x y, f (y * x) x⁻¹) (μ.prod ν),\n  { apply hf.comp_measurable' h (map_prod_mul_inv_eq μ ν).absolutely_continuous },\n  simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],\n  conv_rhs { rw [← map_prod_mul_inv_eq μ ν] },\n  symmetry,\n  exact lintegral_map' (hf.mono' (map_prod_mul_inv_eq μ ν).absolutely_continuous) h,\nend\n\n@[to_additive]\nlemma measure_mul_right_null [is_mul_left_invariant μ] {E : set G} (y : G) :\n  μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ E = 0 :=\ncalc μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ (has_inv.inv ⁻¹' ((λ x, y⁻¹ * x) ⁻¹' (has_inv.inv ⁻¹' E))) = 0 :\n  by simp only [preimage_preimage, mul_inv_rev, inv_inv]\n... ↔ μ E = 0 : by simp only [measure_inv_null μ, measure_preimage_mul]\n\n@[to_additive]\nlemma measure_mul_right_ne_zero [is_mul_left_invariant μ] {E : set G}\n  (h2E : μ E ≠ 0) (y : G) : μ ((λ x, x * y) ⁻¹' E) ≠ 0 :=\n(not_iff_not_of_iff (measure_mul_right_null μ y)).mpr h2E\n\n/-- This is the computation performed in the proof of [Halmos, §60 Th. A]. -/\n@[to_additive]\nlemma measure_mul_lintegral_eq [is_mul_left_invariant μ]\n  [is_mul_left_invariant ν] {E : set G} (Em : measurable_set E) (f : G → ℝ≥0∞) (hf : measurable f) :\n  μ E * ∫⁻ y, f y ∂ν = ∫⁻ x, ν ((λ z, z * x) ⁻¹' E) * f (x⁻¹) ∂μ :=\nbegin\n  rw [← set_lintegral_one, ← lintegral_indicator _ Em,\n    ← lintegral_lintegral_mul (measurable_const.indicator Em).ae_measurable hf.ae_measurable,\n    ← lintegral_lintegral_mul_inv μ ν],\n  swap, { exact (((measurable_const.indicator Em).comp measurable_fst).mul\n      (hf.comp measurable_snd)).ae_measurable },\n  have mE : ∀ x : G, measurable (λ y, ((λ z, z * x) ⁻¹' E).indicator (λ z, (1 : ℝ≥0∞)) y) :=\n  λ x, measurable_const.indicator (measurable_mul_const _ Em),\n  have : ∀ x y, E.indicator (λ (z : G), (1 : ℝ≥0∞)) (y * x) =\n    ((λ z, z * x) ⁻¹' E).indicator (λ (b : G), 1) y,\n  { intros x y, symmetry, convert indicator_comp_right (λ y, y * x), ext1 z, refl },\n  simp_rw [this, lintegral_mul_const _ (mE _), lintegral_indicator _ (measurable_mul_const _ Em),\n    set_lintegral_one],\nend\n\n/-- Any two nonzero left-invariant measures are absolutely continuous w.r.t. each other. -/\n@[to_additive]\nlemma absolutely_continuous_of_is_mul_left_invariant\n  [is_mul_left_invariant μ] [is_mul_left_invariant ν] (hν : ν ≠ 0) : μ ≪ ν :=\nbegin\n  refine absolutely_continuous.mk (λ E Em hνE, _),\n  have h1 := measure_mul_lintegral_eq μ ν Em 1 measurable_one,\n  simp_rw [pi.one_apply, lintegral_one, mul_one, (measure_mul_right_null ν _).mpr hνE,\n    lintegral_zero, mul_eq_zero, measure_univ_eq_zero.not.mpr hν, or_false] at h1,\n  exact h1\nend\n\n@[to_additive]\nlemma ae_measure_preimage_mul_right_lt_top [is_mul_left_invariant μ] [is_mul_left_invariant ν]\n  {E : set G} (Em : measurable_set E) (hμE : μ E ≠ ∞) :\n  ∀ᵐ x ∂μ, ν ((λ y, y * x) ⁻¹' E) < ∞ :=\nbegin\n  refine ae_of_forall_measure_lt_top_ae_restrict' ν.inv _ _,\n  intros A hA h2A h3A,\n  simp only [ν.inv_apply] at h3A,\n  apply ae_lt_top (measurable_measure_mul_right ν Em),\n  have h1 := measure_mul_lintegral_eq μ ν Em (A⁻¹.indicator 1) (measurable_one.indicator hA.inv),\n  rw [lintegral_indicator _ hA.inv] at h1,\n  simp_rw [pi.one_apply, set_lintegral_one, ← image_inv, indicator_image inv_injective, image_inv,\n    ← indicator_mul_right _ (λ x, ν ((λ y, y * x) ⁻¹' E)), function.comp, pi.one_apply,\n    mul_one] at h1,\n  rw [← lintegral_indicator _ hA, ← h1],\n  exact ennreal.mul_ne_top hμE h3A.ne,\nend\n\n@[to_additive]\nlemma ae_measure_preimage_mul_right_lt_top_of_ne_zero [is_mul_left_invariant μ]\n  [is_mul_left_invariant ν] {E : set G} (Em : measurable_set E) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞) :\n  ∀ᵐ x ∂μ, ν ((λ y, y * x) ⁻¹' E) < ∞ :=\nbegin\n  refine (ae_measure_preimage_mul_right_lt_top ν ν Em h3E).filter_mono _,\n  refine (absolutely_continuous_of_is_mul_left_invariant μ ν _).ae_le,\n  refine mt _ h2E,\n  intro hν,\n  rw [hν, measure.coe_zero, pi.zero_apply]\nend\n\n/-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A].\n  Note that if `f` is the characteristic function of a measurable set `F` this states that\n  `μ F = c * μ E` for a constant `c` that does not depend on `μ`.\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⁻¹)ν(Ex⁻¹) = f(x)` holds if we can prove that\n  `0 < ν(Ex⁻¹) < ∞`. The first inequality follows from §59, 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]\nlemma measure_lintegral_div_measure [is_mul_left_invariant μ]\n  [is_mul_left_invariant ν] {E : set G} (Em : measurable_set E) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞)\n  (f : G → ℝ≥0∞) (hf : measurable f) :\n  μ E * ∫⁻ y, f y⁻¹ / ν ((λ x, x * y⁻¹) ⁻¹' E) ∂ν = ∫⁻ x, f x ∂μ :=\nbegin\n  set g := λ y, f y⁻¹ / ν ((λ x, x * y⁻¹) ⁻¹' E),\n  have hg : measurable g := (hf.comp measurable_inv).div\n    ((measurable_measure_mul_right ν Em).comp measurable_inv),\n  simp_rw [measure_mul_lintegral_eq μ ν Em g hg, g, inv_inv],\n  refine lintegral_congr_ae _,\n  refine (ae_measure_preimage_mul_right_lt_top_of_ne_zero μ ν Em h2E h3E).mono (λ x hx , _),\n  simp_rw [ennreal.mul_div_cancel' (measure_mul_right_ne_zero ν h2E _) hx.ne]\nend\n\n@[to_additive]\nlemma measure_mul_measure_eq [is_mul_left_invariant μ]\n  [is_mul_left_invariant ν] {E F : set G}\n  (hE : measurable_set E) (hF : measurable_set F) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞) :\n    μ E * ν F = ν E * μ F :=\nbegin\n  have h1 := measure_lintegral_div_measure ν ν hE h2E h3E (F.indicator (λ x, 1))\n    (measurable_const.indicator hF),\n  have h2 := measure_lintegral_div_measure μ ν hE h2E h3E (F.indicator (λ x, 1))\n    (measurable_const.indicator hF),\n  rw [lintegral_indicator _ hF, set_lintegral_one] at h1 h2,\n  rw [← 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]\nlemma measure_eq_div_smul [is_mul_left_invariant μ]\n  [is_mul_left_invariant ν] {E : set G}\n  (hE : measurable_set E) (h2E : ν E ≠ 0) (h3E : ν E ≠ ∞) : μ = (μ E / ν E) • ν :=\nbegin\n  ext1 F hF,\n  rw [smul_apply, smul_eq_mul, mul_comm, ← mul_div_assoc, mul_comm,\n    measure_mul_measure_eq μ ν hE hF h2E h3E, mul_div_assoc, ennreal.mul_div_cancel' h2E h3E]\nend\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/group/prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237605, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7689400986501336}}
{"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 topology real\nlocal notation (name := abs) `|`x`|` := abs x\n\n/-- This theorem establishes **Leibniz's series for `π`**: The alternating sum of the reciprocals\n  of the odd numbers is `π/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 - ∑ i in finset.range k, (-(1:ℝ))^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 `+∞`. 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 (λ k, ∑ i in finset.range k, ((-(1:ℝ))^i / (2*i+1))) at_top (𝓝 (π/4)) :=\nbegin\n  rw [tendsto_iff_norm_tendsto_zero, ← 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 `+∞`\n  let u := λ k : ℕ, (k:nnreal) ^ (-1 / (2 * (k:ℝ) + 1)),\n  have H : tendsto (λ k : ℕ, (1:ℝ) - (u k) + (u k) ^ (2 * (k:ℝ) + 1)) at_top (𝓝 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 [← rpow_mul (nat.cast_nonneg k) ((-1)/(2*(k:ℝ)+1)) (2*(k:ℝ)+1),\n         @div_mul_cancel _ _ (2*(k:ℝ)+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 := λ (i:ℕ) x, (-(1:ℝ))^i * x^(2*i+1) / (2*i+1),\n  let f := λ x, arctan x - (∑ i in finset.range k, b i x),\n  suffices f_bound : |f 1 - f 0| ≤ (1:ℝ) - U + U ^ (2 * (k:ℝ) + 1),\n  { rw ← 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:ℝ) ≤ 1,\n  { by_cases hk : k = 0,\n    { simp [u, U, hk] },\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:ℝ)) (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' := λ x : ℝ, (-x^2) ^ k / (1 + x^2),\n  have has_deriv_at_f : ∀ x, has_deriv_at f (f' x) x,\n  { intro x,\n    have has_deriv_at_b : ∀ i ∈ finset.range k, (has_deriv_at (b i) ((-x^2)^i) x),\n    { intros i hi,\n      convert has_deriv_at.const_mul ((-1:ℝ)^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 [← mul_assoc, @div_mul_cancel _ _ (2*(i:ℝ)+1) _ (by { norm_cast, linarith }),\n            pow_mul x 2 i, ← 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 [f'] at g_sum ⊢,\n    rw [g_sum, ← 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 : ∀ x ∈ Icc (U:ℝ) 1, has_deriv_within_at f (f' x) (Icc (U:ℝ) 1) x :=\n    λ x hx, (has_deriv_at_f x).has_deriv_within_at,\n  have hderiv2 : ∀ x ∈ Icc 0 (U:ℝ), has_deriv_within_at f (f' x) (Icc 0 (U:ℝ)) x :=\n    λ 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 : ∀ x ∈ Icc (-1:ℝ) 1, |f' x| ≤ |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        ← 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 : ℝ) ≤ _),\n    exact (le_add_of_nonneg_right (sq_nonneg x) : (1 : ℝ) ≤ _) },\n  have hbound1 : ∀ x ∈ Ico (U:ℝ) 1, |f' x| ≤ 1,\n  { rintros x ⟨hx_left, hx_right⟩,\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), ← abs_of_nonneg (le_trans hU2 hx_left)] at hincr,\n    rw ← 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 : ∀ x ∈ Ico 0 (U:ℝ), |f' x| ≤ U ^ (2*k),\n  { rintros x ⟨hx_left, hx_right⟩,\n    have hincr := pow_le_pow_of_le_left hx_left (le_of_lt hx_right) (2*k),\n    rw ← abs_of_nonneg hx_left at hincr hx_right,\n    rw ← 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               ... ≤ 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:ℝ)+1) : by { rw [← pow_succ' (U:ℝ) (2*k)], norm_cast },\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/data/real/pi/leibniz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521252, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7689400864375914}}
{"text": "/- Copyright (c) 2020 Floris van Doorn. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Orlando Cau\n-/\nimport linear_algebra.basic linear_algebra.finite_dimensional    \nimport algebra.module  \n/-!\n  We fix a notation composition of linear_map.\n-/\nnotation f ` ⊚ `:80 g:80 :=  linear_map.comp f g\n\nuniverse variables u v w \n   \nopen linear_map  \n\n/-- A representation of a group `G` on an `R`-module `M` is a group homomorphism from `G` to\n  `GL(M)`. \n  -/\n\ndef group_representation (G R M : Type*) [group G] [ring R] [add_comm_group M] [module R M] :\n  Type* :=       G →* M →ₗ[R] M \n\nvariables {G : Type u} [group G]\n          {R : Type v} [ring R]\n          {M : Type w}[add_comm_group M] [module R M] \n\ninstance  : has_coe_to_fun (group_representation G R M) := ⟨_, λ ρ , ρ.to_fun⟩\n\nvariables (ρ : group_representation G R M)\n\n\n@[simp]lemma map_comp (s t : G) : ρ (s * t) = ρ s ⊚ ρ t :=  ρ.map_mul _ _ \n\ndef gr.to_equiv' (g : G) :  M ≃ₗ[R] M := { to_fun := ρ g,\n  add := (ρ g).map_add ,\n  smul := (ρ g).map_smul,\n  inv_fun := (ρ g⁻¹ ),\n  left_inv := begin intro, change (ρ g⁻¹ ⊚ ρ g) x = _, erw ←  map_comp, rw inv_mul_self, erw ρ.map_one, exact rfl end, \n  right_inv :=  begin intro, change (ρ g ⊚ ρ g⁻¹ ) x = _, erw ←  map_comp, rw mul_inv_self, erw ρ.map_one, exact rfl end, }\n\nlemma gr.to_equiv : G →* M ≃ₗ[R] M := { to_fun := gr.to_equiv' ρ  ,\n  map_one' := begin\n      unfold gr.to_equiv', congr,erw ρ.map_one, exact rfl, rw one_inv, rw ρ.map_one,  exact rfl,\n   end,\n  map_mul' := begin\n    intros, unfold gr.to_equiv', congr, rw map_comp, exact rfl,\n    rw mul_inv_rev, rw map_comp, exact rfl,\n   end } \n\n@[simp] lemma rho_symm_apply (x : M)(g : G) : ρ g ((gr.to_equiv ρ g).inv_fun x) = x := begin \n  dunfold gr.to_equiv, change (ρ g ⊚ ρ g⁻¹) x = x, rw ← map_comp, rw mul_inv_self, rw ρ.map_one, exact rfl,\nend\n\n@[simp] lemma symm_eq_inv (ρ : group_representation G R M) (g : G) : ρ g⁻¹ = (gr.to_equiv ρ g).symm :=\nbegin \n  ext, conv_lhs{\n    erw ← rho_symm_apply ρ x g,\n  },\n  change (ρ g⁻¹ * ρ g) _ = _,\n  erw ← ρ.map_mul, rw inv_mul_self, rw ρ.map_one, exact rfl, \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_rep_2/basic_definitions/group_representation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7689400813183529}}
{"text": "import ..prooflab\nimport lectures.lec4_equality_of_functions\n\n\n/-! # Homework 3 \nHomework must be done individually.\nReplace the placeholders (e.g., `:= sorry`) with your solutions using only the tactics we have learned so far. -/\n\n\nnamespace PROOFS\n\n\n/- \nWe know that we can add any two natural numbers and get a natural number. In fact, as we have already seen we have the following function which takes __any__ two natural numbers `m` and `n` as input and returns `m + n`. \n-/\n\n#check nat.add \n\n\n/-\nSometimes this fact is phrased as \"natural numbers are closed under addition\". But natural numbers are not closed under subtraction; we know that 4 subtracted from 3 is not a natural number. However, Lean has a notion of truncated subtraction which defined `m - n` to be `0` if `m < n` and if `n ≤ m`, it returns the usual nonnegative subtraction `m - n`. \n-/\n\n#eval 4 - 3 \n#eval 3 - 4\n\n\n\ndef add_one (n : ℕ) := \nn + 1 \n\ndef sub_one (n : ℕ) :=\nn - 1\n\n\n/-! ## Question 1 (20 points): \nProve the following equality of functions.  \n-/\n\n\nexample : \n  sub_one ∘ add_one = id :=\nbegin\n  sorry, \nend \n\n\n\n\n\n\n\n/-! ## Question 2 (20 points): \nFill in   \n-/\n  \n\nexample (f : bool → bool) (h : f ∘ f = f) : \n   f ∘ f ∘ f = f :=\nbegin\n  sorry, \nend \n\n\n\n\n\n\n\n/-\n### Question 3 (30 points): \n1. Compose functions `square` and `add_one` to define two functions `square_succ` and `succ_square` where the first function maps `n : ℕ` to `(n + 1) * (n + 1)` and the second function maps `n : ℕ` to `n * n + 1`. \n\n2. Prove that the function `square_succ` is the same as `shift_plus1 square` where `shift_plus1` is defined in below. \n-/\n\n#check square \n#check add_one\n\ndef square_succ := sorry\n#eval square_succ 20\n\ndef succ_square := sorry\n#eval succ_square 20\n\n\n\ndef shift_plus1 := λ f : ℕ → ℕ, λ n, f(n + 1)\ndef shift_minus1 := λ f : ℕ → ℕ, λ n, f(n - 1)\n\nexample : \n  shift_plus1 square = square_succ := \nbegin\n  sorry, \nend \n\n\n\n\n\n/- ### Question 4 (30 points): \nA functions `f` is a __left inverse__ to a function `g` if `f ∘ g = id`.  \n-/\n@[simp] def left_inv {A B : Type} (f : A → B) (g : B → A)  := f ∘ g = id \n\n#check left_inv\n\n\n/-\nA functions `g` is a __right inverse__ to a function `f` if `f ∘ g = id`. \n-/\n\n@[simp] def right_inv {A B : Type} (g : B → A) (f : A → B) := f ∘ g = id\n\n\n/- Complete the proof of the lemma \n`inv_of_left_inv_and_right_inv` in below which says that if a function has both a left inverse and a right inverse, then they are equal. \n-/\n\nlemma inv_of_left_inv_and_right_inv {A B : Type} (f : A → B) (g : B → A) (k : A → B) (h₁ : left_inv f g) (h₂ : right_inv k g ) : \nk = f :=\n-- the statement above says that if `f` is a left inverse of `g` and `k` is a right inverse of `g` then `k = f`. \nbegin\n   funext, \n   calc \n   k x = (id ∘ k) x : sorry\n   ... = ((f ∘ g) ∘ k) x : sorry \n   ... = f ((g ∘ k) x) : sorry \n   ... = f (id x) : sorry \n   ... = f x : by 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/hw3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7689268841809657}}
{"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.W.basic\nimport set_theory.cardinal.ordinal\n\n/-!\n# Cardinality of W-types\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves some theorems about the cardinality of W-types. The main result is\n`cardinal_mk_le_max_aleph_0_of_fintype` which says that if for any `a : α`,\n`β a` is finite, then the cardinality of `W_type β` is at most the maximum of the\ncardinality of `α` and `ℵ₀`.\nThis can be used to prove theorems about the cardinality of algebraic constructions such as\npolynomials. There is a surjection from a `W_type` to `mv_polynomial` for example, and\nthis surjection can be used to put an upper bound on the cardinality of `mv_polynomial`.\n\n## Tags\n\nW, W type, cardinal, first order\n-/\nuniverse u\n\nvariables {α : Type u} {β : α → Type u}\n\nnoncomputable theory\n\nnamespace W_type\n\nopen_locale cardinal\n\nopen cardinal\n\nlemma cardinal_mk_eq_sum : #(W_type β) = sum (λ a : α, #(W_type β) ^ #(β a)) :=\nbegin\n  simp only [cardinal.power_def, ← cardinal.mk_sigma],\n  exact mk_congr (equiv_sigma β)\nend\n\n/-- `#(W_type β)` is the least cardinal `κ` such that `sum (λ a : α, κ ^ #(β a)) ≤ κ` -/\nlemma cardinal_mk_le_of_le {κ : cardinal.{u}} (hκ : sum (λ a : α, κ ^ #(β a)) ≤ κ) :\n  #(W_type β) ≤ κ :=\nbegin\n  induction κ using cardinal.induction_on with γ,\n  simp only [cardinal.power_def, ← cardinal.mk_sigma, cardinal.le_def] at hκ,\n  cases hκ,\n  exact cardinal.mk_le_of_injective (elim_injective _ hκ.1 hκ.2)\nend\n\n/-- If, for any `a : α`, `β a` is finite, then the cardinality of `W_type β`\n  is at most the maximum of the cardinality of `α` and `ℵ₀`  -/\nlemma cardinal_mk_le_max_aleph_0_of_finite [∀ a, finite (β a)] : #(W_type β) ≤ max (#α) ℵ₀ :=\n(is_empty_or_nonempty α).elim\n  (begin\n    introI h,\n    rw [cardinal.mk_eq_zero (W_type β)],\n    exact zero_le _\n  end) $\nλ hn, let m := max (#α) ℵ₀ in cardinal_mk_le_of_le $\ncalc cardinal.sum (λ a, m ^ #(β a))\n    ≤ #α * ⨆ a, m ^ #(β a) : cardinal.sum_le_supr _\n... ≤ m * ⨆ a, m ^ #(β a) : mul_le_mul' (le_max_left _ _) le_rfl\n... = m : mul_eq_left.{u} (le_max_right _ _)\n  (csupr_le' $ λ i, pow_le (le_max_right _ _) (lt_aleph_0_of_finite _)) $\n  pos_iff_ne_zero.1 $ order.succ_le_iff.1\n    begin\n      rw succ_zero,\n      obtain ⟨a⟩ : nonempty α, from hn,\n      refine le_trans _ (le_csupr (bdd_above_range.{u u} _) a),\n      rw ←power_zero,\n      exact power_le_power_left (pos_iff_ne_zero.1\n        (aleph_0_pos.trans_le (le_max_right _ _))) (zero_le _)\n    end\n\nend W_type\n", "meta": {"author": "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/W/cardinal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778024535095, "lm_q2_score": 0.803173791645582, "lm_q1q2_score": 0.7688604422547356}}
{"text": "import data.nat.prime algebra.big_operators M3P14.Arithmetic_functions.sum_over_divisors\n\nopen nat \n\n-- mobius function\n\n-- taken from M3P14 sheet 1\ndef square_free_int (n : ℕ) := ∀ p : ℕ, prime p ∧ (p ∣ n → ¬ (p^2 ∣ n))\n\n-- number of prime divisors of n, not counting multiplicities\ndef primes_div_nodup (n : ℕ) := n.factors.erase_dup.length\nlocal notation `ω` := primes_div_nodup\n--#eval ω 30\n\n--number of prime divisors of n, counting multiplicities\ndef primes_div_dup (n : ℕ) := n.factors.length\nlocal notation `Ω` := primes_div_dup\n--#eval Ω 300\n\nlocal attribute [instance] classical.prop_decidable\n\nnoncomputable def mobius (n : ℕ) : int := \nif square_free_int n ∧ (2 ∣ ω n) then 1 else \nif square_free_int n ∧ ¬(2 ∣ ω n) then -1 \nelse 0\n\nlocal notation `μ`  := mobius\n\ntheorem mob_mul (m n : ℕ) : μ (m*n) = (μ m ) * (μ n) := sorry\n\nlemma non_coprime (m n : ℕ) : (gcd m n) > 1 → μ (m * n) = 0 := sorry\n\n--theorem mob_sum (n d : ℕ) (hp : n ≠ 1) (hq: d ∣ n) : divisor_sum mobius n = 0 := sorry\n\n--def mertens_func (n k : ℕ) := sum k μ n \n\n--theorem mobius_inv (m n : ℕ) (f : ℕ → ℕ) (g : ℕ → ℕ) : (g n = sum f d) → (f n = sum (μ d) * g (n / d) ) := 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/M3P14/Arithmetic_functions/mobius.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.7688109389899834}}
{"text": "/-\nCopyright (c) 2023 Huub Vromen. All rights reserved.\nAuthor: Huub Vromen\n-/\n\nimport data.set.basic\n/-- A set-theoretic semantics for Aristotle's assertoric syllogisms is used by \n    many authors. See, for instance, Smith, 1989.\n    Terms are interpreted as non-empty subsets of some set of individuals. -/\n\nvariable {α : Type}\nvariable {x : α}\nvariables {A B C : set α}\n-- *** how can I stipulate that these sets have to be nonempty?\n\n/-- semantics of the `a` relation -/\ndef universal_affirmative (A: set α) (B: set α) : Prop := \n  A ∩ B = B\ninfixr ` a ` : 80 := universal_affirmative\n\n/-- semantics of the `e` relation -/\ndef universal_negative (A: set α) (B: set α) : Prop := \n  A ∩ B = ∅ \ninfixr ` e ` : 80 := universal_negative\n\n/-- semantics of the `i` relation -/\ndef particular_affirmative (A: set α) (B: set α) : Prop := \n  (A ∩ B).nonempty \ninfixr ` i ` : 80 := particular_affirmative\n\n/-- semantics of the `o` relation -/\ndef particular_negative (A: set α) (B: set α) : Prop :=  \n  A ∩ B ≠ B\ninfixr ` o ` : 80 := particular_negative\n\n/-- semantics of contradictory: contradictory is defined as negation -/\ndef c (p : Prop) : Prop := ¬ p\n\n/-- first, we prove a helpful lemma -/\nlemma inter_empty (h1 : A e B) : x ∈ B → x ∉ A :=\nbegin\nrw universal_negative at h1,\nintro h2,\nby_contra h3,\nhave h4 : x ∈ A ∩ B, from set.mem_inter h3 h2,\nhave h5 : (A ∩ B).nonempty, from exists.intro x h4,\nhave h6 : A ∩ B ≠ ∅, from set.nonempty.ne_empty h5,\nshow false, from h6 h1\nend\n\n\n/--  Now, we prove the soundness of the axiom system DR -/\n\nlemma Barbara₁ : A a B → B a C → A a C :=\nbegin\nintros h1 h2,\nrw universal_affirmative at *,\ncalc A ∩ C \n    = A ∩ (B ∩ C) : by rw h2\n... = (A ∩ B) ∩ C : by tidy\n... = B ∩ C : by rw h1\n... = C : by rw h2\nend\n\n\nlemma Celarent₁ : A e B → B a C → A e C :=\nbegin\n  intros h1 h2,\n  rw universal_negative at *,\n  rw universal_affirmative at h2,\n  calc A ∩ C \n      = A ∩ (B ∩ C): by rw h2\n  ... = (A ∩ B) ∩ C: by tidy\n  ... = ∅ ∩ C : by rw h1\n  ... = ∅ : by simp,\nend\n\n\nlemma e_conv : A e B → B e A :=\nbegin\nintro h1,\nrw universal_negative at *,\ncc,\nend\n\n\nlemma a_conv : (A a B ∧ B.nonempty) → B i A :=\n  begin\n  intro h1,\n  cases h1.2 with p hp,\n  rw particular_affirmative,\n  rw universal_affirmative at h1,\n  cc,\n  end \n\n\nlemma contr {p r : Prop} : (c r → c p) → p → 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 := \nbegin\nsimp [c, particular_affirmative, universal_negative],\nexact set.ne_empty_iff_nonempty\nend\n\nlemma contr_i : c (A i B) = A e B :=\nbegin\nsimp [c, particular_affirmative, universal_negative],\nexact set.not_nonempty_iff_eq_empty\nend\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₁ : A a B → B i C → A i C :=\nbegin\nintros h1 h2,\n--simp [universal_affirmation, particular_affirmation] at *,\n--by_contra h3,\ncases h2 with p hp,\ncases hp,\nrw universal_affirmative at h1,\nhave h4 : p ∈ A ∩ B, by cc,\nexact exists.intro p (and.intro h4.left hp_right),\nend\n\nlemma Ferio₁ : A e B → B i C → A o C :=\nbegin\n  intros h1 h2,\n  cases h2 with p h,\n  rw particular_negative,\n  cases h with hb hc,\n  have h3 : p ∉ A, by exact inter_empty h1 hb,\n  simp,\n  by_contra h4,\n  rw ← h4 at hc,\n  show false, from h3 hc.1\nend\n\nlemma i_conv : A i B → B i A :=\nbegin\nintros h1,\ncases h1 with p h2,\ncases h2 with q r,\nexact exists.intro p (and.intro r q)\nend\n\n#lint", "meta": {"author": "hjvromen", "repo": "aristotle", "sha": "fdc6c68ce2edcf6faaa638457cb593e922bfa521", "save_path": "github-repos/lean/hjvromen-aristotle", "path": "github-repos/lean/hjvromen-aristotle/aristotle-fdc6c68ce2edcf6faaa638457cb593e922bfa521/src/aristotle_SET_semantics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7688109352645224}}
{"text": "-- Example for seminar announcement\n\nimport data.zmod.basic -- import relevant part of the library\n\n-- First state and prove the two lemmas that we will need.\n\n/- The first lemma says that `7` is not a sum of three squares in `ℤ/8ℤ`.\nThis is a finite problem; `dec_trivial` can prove such statements. -/\nlemma three_squares_mod_8 : ∀ a b c : zmod 8, a^2 + b^2 + c^2 ≠ 7 := dec_trivial\n\n-- The second lemma says that when `x^2 + y^2 + z^2` is divisible by `4`\n-- (where `x`, `y`, `z` are in `ℕ`), then `x`, `y` and `z` are even.\nlemma three_squares_even : ∀ x y z : ℕ, 4 ∣ x^2 + y^2 + z^2 → 2 ∣ x ∧ 2 ∣ y ∧ 2 ∣ z :=\nbegin\n  -- we first formulate the corresponding statement in `ℤ/4ℤ`\n  have h₂ : ∀ a b c : zmod 4,\n            a^2 + b^2 + c^2 = 0 → (a = 0 ∨ a = 2) ∧ (b = 0 ∨ b = 2) ∧ (c = 0 ∨ c = 2)\n  := dec_trivial, -- again a finite problem\n  -- now we need a statement that allows us to translate from `ℤ/4ℤ` to `ℕ`\n  have h₄ : ∀ x : ℕ, (x : zmod 4) = 0 ∨ (x : zmod 4) = 2 → 2 ∣ x :=\n  begin\n    rintros x (hx₁ | hx₂), -- two goals with different assumptions on `x`\n    { -- here we assume that `x ≡ 0 mod 4`\n      have hx₁' := (zmod.nat_coe_zmod_eq_zero_iff_dvd x 4).mp hx₁,\n      rw (show 4 = 2*2, from by norm_num) at hx₁',\n      exact dvd_of_mul_left_dvd hx₁', },\n    { -- here we assume that `x ≡ 2 mod 4`\n      have hx₂' : x % 4 = 2 % 4 := (zmod.nat_coe_eq_nat_coe_iff' _ _ _).mp hx₂,\n      apply_fun (λ z, z % 2) at hx₂', -- reduce mod `2`\n      rw [nat.mod_mod_of_dvd _ (by norm_num : 2 ∣ 4)] at hx₂',\n      norm_num at hx₂', -- replace `2 % 4 % 2` by `0`\n      exact nat.dvd_of_mod_eq_zero hx₂', },\n  end,\n  -- now use `h₂` and `h₄` to prove the claim\n  intros x y z h,\n  have h' := (zmod.nat_coe_zmod_eq_zero_iff_dvd _ _).mpr h, -- write as equality in `ℤ/4ℤ`\n  push_cast at h',\n  cases h₂ x y z h' with hx hyz,\n  cases hyz with hy hz,\n  split,\n  { apply h₄ x, exact hx, },\n  split,\n  { apply h₄ y, exact hy, },\n  apply h₄ z, exact hz,\n  -- rcases h₂ x y z h' with ⟨hx, hy, hz⟩,\n  -- exact ⟨h₄ x hx, h₄ y hy, h₄ z hz⟩,\nend\n\n-- Now we state the theorem:\n-- A natural number of the form `4^k * (8*m + 7)` is not a sum of three squares\ntheorem three_squares (k m : ℕ) : ¬ ∃ x y z : ℕ, x^2 + y^2 + z^2 = 4^k*(8*m + 7) :=\nbegin\n  push_neg, -- change to `∀ x y z, x^2 + y^2 + z^2 ≠ 4^k*(8*m+7)`\n  intros x y z hxyz, -- now we have to show a contradiction\n  -- we do induction on `k`, but with the statement `∀ x y z, ...`\n  induction k with k ih generalizing x y z,\n  { -- the base case: `k = 0`\n    apply_fun (coe : ℕ → zmod 8) at hxyz, -- reduce mod `8`\n    norm_num at hxyz, -- simplify and apply `three_squares_mod_8`\n    exact three_squares_mod_8 x y z hxyz, },\n  { -- the inductive step; `ih` is the induction hypothesis\n    rw [pow_succ _ k, mul_assoc] at hxyz, -- replace `4^(k+1)*...` by `4*(4^k*...)`\n    have h : 4 ∣ x^2 + y^2 + z^2 := \n    begin\n      change ∃ a : ℕ, x^2 + y^2 + z^2 = 4*a,\n      use 4 ^ k * (8 * m + 7),\n      exact hxyz,\n    end,\n    -- ⟨4^k*(8*m+7), hxyz⟩,\n    -- it follows that `x`, `y` and `z` are divisible by `2`\n    -- we need to spell this out, so that we can replace `x` by `2*x₁` etc.\n    rcases three_squares_even x y z h with ⟨⟨x₁, hx₁⟩, ⟨y₁, hy₁⟩, ⟨z₁, hz₁⟩⟩,\n    rw [hx₁, hy₁, hz₁,\n        -- the following does the calculation that allows us to cancel `4*...`\n        (by ring : (2*x₁)^2 + (2*y₁)^2 + (2*z₁)^2 = 4*(x₁^2 + y₁^2 + z₁^2))] at hxyz,\n    exact ih x₁ y₁ z₁ (mul_left_cancel₀ (by norm_num : 4 ≠ 0) hxyz), },\nend\n\nopen nat\n\n/-- Helper lemma for gcds -/\nlemma gcd_mul_coprime {a b : ℕ} (c : ℕ) (h₁ : gcd a b = 1) : (gcd a c) * (gcd b c) = gcd (a*b) c :=\nbegin\n  -- this is `nat.coprime.gcd_mul` up to the symmetry of `gcd`\n  rw [gcd_comm a, gcd_comm b, gcd_comm (a*b), coprime.gcd_mul _ h₁],\nend\n\n/- Descent Lemma -/\nlemma descent {a b c : ℕ} (h₁ : gcd a b = 1) (h₂ : a*b = c^2) : ∃ u v, a = u^2 ∧ b = v^2 ∧ c = u*v :=\nbegin\n  cases eq_or_ne c 0 with hc hc,\n  -- first deal with the case `c = 0`\n  { simp [hc] at *,\n    cases h₂ with h₀ h₀,\n    all_goals { simp [h₀] at *, simp [h₁] },\n    { use [0, 1], simp, },\n    { use [1, 0], simp, } },\n  -- now `c ≠ 0`; this implies that `a*b ≠ 0`\n  have h₀ : a*b ≠ 0,\n  { intro h, rw h at h₂, exact hc (pow_eq_zero h₂.symm), },\n  -- we can take `u = gcd a c` and `v = gcd b c`\n  use [gcd a c, gcd b c],\n  -- prove the last statement\n  have h₃ : (gcd a c) * (gcd b c) = c,\n  { rw [gcd_mul_coprime c h₁, h₂, pow_two, gcd_mul_left_left], },\n  -- this implies `u^2 * v^2 = a*b`\n  have h₄ : (gcd a c)^2 * (gcd b c)^2 = a*b,\n  { rw h₂, conv_rhs {rw [← h₃]}, ring, },\n  -- since `a` and `b` are coprime, `a` is coprime to `v^2`\n  have ha : coprime a ((gcd b c)^2),\n  { rw [coprime_pow_right_iff (by norm_num : 0 < 2), nat.gcd_comm],\n    exact coprime.gcd_right c h₁, },\n  -- similarly, `b` is coprime to `u^2`\n  have hb : coprime b ((gcd a c)^2),\n  { rw [coprime_pow_right_iff (by norm_num : 0 < 2), nat.gcd_comm],\n    have h₁' : gcd b a = 1, { rw nat.gcd_comm, exact h₁, },\n    exact coprime.gcd_right c h₁', },\n  -- we deduce that `a` divides `u^2` and `b` divides `v^2`\n  have ha' : a ∣ (gcd a c)^2,\n  { refine coprime.dvd_of_dvd_mul_left ha _,\n    rw [mul_comm, h₄],\n    exact dvd_mul_right a b, },\n  have hb' : b ∣ (gcd b c)^2,\n  { refine coprime.dvd_of_dvd_mul_left hb _,\n    rw [h₄],\n    exact dvd_mul_left b a, },\n  -- write `u^2 = a * r` and `v^2 = b * s`\n  cases ha' with r hr,\n  cases hb' with s hs,\n  -- then `(a*b) * (r*s) = a*b`, which implies `r*s = 1`\n  rw [hr, hs, mul_comm b, mul_assoc, ← mul_assoc r, mul_comm _ b, ← mul_assoc] at h₄,\n  nth_rewrite 1 ← mul_one (a * b) at h₄,\n  have hrs := mul_left_cancel₀ h₀ h₄,\n  -- and therefore `r = s = 1`\n  rw [eq_one_of_mul_eq_one_right hrs, mul_one] at hr,\n  rw [eq_one_of_mul_eq_one_left hrs, mul_one] at hs,\n  exact ⟨hr.symm, hs.symm, h₃.symm⟩,\nend\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/example.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.768775849940355}}
{"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\nuniverse u\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) := ⟨[arbitrary (literal V)]⟩\n\ninstance has_decidable_eq [decidable_eq V] : decidable_eq (clause V)\n| []        []        := is_true rfl\n| (a :: as) []        := is_false (λ h, list.no_confusion h)\n| []        (b :: bs) := is_false (λ 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 (λ h, list.no_confusion h (λ _ ha, absurd ha hf))\n    end\n  | is_false hf := is_false (λ h, list.no_confusion h (λ hab _, absurd hab hf))\n  end\n\ninstance : has_mem (literal V) (clause V) := ⟨list.mem⟩\ninstance : has_emptyc (clause V) := ⟨list.nil⟩ -- Refactor empty into [] below?\ninstance [decidable_eq V] : has_union (clause V) := ⟨list.union⟩\ninstance [decidable_eq V] : has_inter (clause V) := ⟨list.inter⟩\ninstance : has_singleton (literal V) (clause V) := ⟨λ l, [l]⟩ \ninstance [decidable_eq V] : has_insert (literal V) (clause V) := ⟨list.insert⟩\ninstance : has_append (clause V) := ⟨list.append⟩\ninstance : has_subset (clause V) := ⟨list.subset⟩\ninstance [has_repr V] : has_repr (clause V) := ⟨list.repr⟩\n\ninstance [decidable_eq V] (l : literal V) (c : clause V) : decidable (l ∈ c) :=\nby apply_instance\n\n/-! # eval -/\nsection eval\n\nvariables (τ : assignment V) (l : literal V) (c c₁ c₂ : clause V)\n\nprotected def eval : bool := c.foldr (λ l b, b || (l.eval τ)) ff\n\n@[simp] theorem eval_nil : clause.eval τ [] = ff := rfl\n\n@[simp] theorem eval_singleton : clause.eval τ [l] = l.eval τ :=\nby simp only [clause.eval, foldr, ff_bor]\n\n@[simp] theorem eval_cons : clause.eval τ (l :: c) = (l.eval τ) || (c.eval τ) :=\nby simp only [clause.eval, foldr, bool.bor_comm]\n\ntheorem eval_append : clause.eval τ (c₁ ++ c₂) = c₁.eval τ || c₂.eval τ :=\nbegin\n  unfold clause.eval,\n  rw foldr_append,\n  cases foldr (λ l b, b || literal.eval τ l) ff c₂,\n  { rw bor_ff },\n  { rw [bor_tt, foldr_bor_tt] }\nend\n\ntheorem eval_tt_iff_exists_literal_eval_tt {τ : assignment V} {c : clause V} : \n  c.eval τ = tt ↔ ∃ l, l ∈ c ∧ literal.eval τ 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 ⟨l₂, hl, he⟩,\n        use [l₂, mem_cons_of_mem l hl, he] } },\n    { rintros ⟨l₂, (rfl | hl), he⟩,\n      { exact or.inl he },\n      { exact or.inr (ih.mpr ⟨l₂, hl, he⟩) } } }\nend\n\ntheorem eval_ff_iff_forall_literal_eval_ff {τ : assignment V} {c : clause V} : \n  clause.eval τ c = ff ↔ ∀ l, l ∈ c → literal.eval τ 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 ∈ c → l.flip ∈ c → ∀ (τ : assignment V), clause.eval τ c = tt :=\nbegin\n  intros hl hlf τ,\n  apply eval_tt_iff_exists_literal_eval_tt.mpr,\n  cases h : (literal.eval τ l),\n  { exact ⟨l.flip, hlf, eval_flip_of_eval h⟩ },\n  { exact ⟨l, hl, h⟩ }\nend\n\ntheorem eval_tt_of_subset_eval_tt {τ : assignment V} {c₁ c₂ : clause V} :\n  c₁ ⊆ c₂ → clause.eval τ c₁ = tt → clause.eval τ c₂ = tt :=\nbegin\n  intros h₁ h₂,\n  apply eval_tt_iff_exists_literal_eval_tt.mpr,\n  rcases eval_tt_iff_exists_literal_eval_tt.mp h₂ with ⟨l, hl, he⟩,\n  exact ⟨l, h₁ hl, he⟩\nend\n\ntheorem eval_ff_of_superset_eval_ff {τ : assignment V} {c₁ c₂ : clause V} :\n  c₁ ⊆ c₂ → clause.eval τ c₂ = ff → clause.eval τ c₁ = ff :=\nbegin\n  intros h₁ h₂,\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₂) l (h₁ hl)\nend\n\ntheorem eval_tt_of_sublist_eval_tt {τ : assignment V} {c₁ c₂ : clause V} :\n  c₁ <+ c₂ → clause.eval τ c₁ = tt → clause.eval τ c₂ = tt :=\nassume h₁, eval_tt_of_subset_eval_tt (sublist.subset h₁)\n\ntheorem eval_ff_of_superlist_eval_ff {τ : assignment V} {c₁ c₂ : clause V} :\n  c₁ <+ c₂ → clause.eval τ c₂ = ff → clause.eval τ c₁ = ff :=\nassume h₁, eval_ff_of_superset_eval_ff (sublist.subset h₁)\n\ntheorem eval_tt_cons_of_eval_tt {τ : assignment V} {c : clause V} (l : literal V) :\n  clause.eval τ c = tt → clause.eval τ (l :: c) = tt :=\nassume h, eval_tt_of_sublist_eval_tt (sublist_cons l c) h\n\ntheorem eval_ff_of_eval_ff_cons {τ : assignment V} {c : clause V} {l : literal V} :\n  clause.eval τ (l :: c) = ff → clause.eval τ 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 (τ : assignment V) (l : literal V) (c c₁ c₂ : clause V)\n\nprotected def count_tt : nat := c.countp (literal.is_true τ)\nprotected def count_ff : nat := c.countp (literal.is_false τ)\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 τ [] = 0 := rfl\n@[simp] lemma count_ff_nil : clause.count_ff τ [] = 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 τ [l] = cond (l.eval τ) 1 0 :=\nby cases h : (l.eval τ); simp [h, clause.count_tt, literal.is_true]\n\n@[simp] theorem count_ff_singleton : clause.count_ff τ [l] = cond (l.eval τ) 0 1 :=\nby cases h : (l.eval τ); 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 τ (l :: c) = cond (l.eval τ) (1 + c.count_tt τ) (c.count_tt τ) :=\nby cases h : (l.eval τ); simp [h, literal.is_true, clause.count_tt, add_comm]\n\n@[simp] theorem count_ff_cons : clause.count_ff τ (l :: c) = cond (l.eval τ) (c.count_ff τ) (1 + c.count_ff τ) :=\nby cases h : (l.eval τ); 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 τ (c₁ ++ c₂) = clause.count_tt τ c₁ + clause.count_tt τ c₂ :=\nbegin\n  induction c₁ with l ls ih,\n  { simp only [count_tt_nil, zero_add, nil_append] },\n  { cases h : (literal.eval τ l); simp [h, ih, add_assoc] }\nend\n\ntheorem count_ff_append : clause.count_ff τ (c₁ ++ c₂) = clause.count_ff τ c₁ + clause.count_ff τ c₂ :=\nbegin\n  induction c₁ with l ls ih,\n  { simp only [count_ff_nil, zero_add, nil_append] },\n  { cases h : (literal.eval τ l); { simp [h, ih, add_assoc] } }\nend\n\ntheorem count_pos_append : clause.count_pos (c₁ ++ c₂) = clause.count_pos c₁ + clause.count_pos c₂ :=\nbegin\n  induction c₁ 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₁ ++ c₂) = clause.count_neg c₁ + clause.count_neg c₂ :=\nbegin\n  induction c₁ 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 τ ≤ c.length :=\nby simp only [clause.count_tt, countp_eq_length_filter, length_filter]\n\ntheorem count_ff_le_length : c.count_ff τ ≤ c.length :=\nby simp only [clause.count_ff, countp_eq_length_filter, length_filter]\n\ntheorem count_pos_le_length : c.count_pos ≤ c.length :=\nby simp only [count_pos, countp_eq_length_filter, length_filter]\n\ntheorem count_neg_le_length : c.count_neg ≤ c.length :=\nby simp only [count_neg, countp_eq_length_filter, length_filter]\n\ntheorem count_tt_plus_count_ff_eq_length (τ : assignment V) (c : clause V) :\n  c.count_tt τ + c.count_ff τ = c.length :=\nbegin\n  induction c with l ls ih,\n  { simp },\n  { cases h : (l.eval τ);\n    simp [count_tt_cons, count_ff_cons, h, ← ih],\n    { rw [add_assoc, add_comm (clause.count_ff τ ls) 1] },\n    { rw [add_comm (clause.count_tt τ ls + clause.count_ff τ ls) 1, ← add_assoc] } }\nend\n\ntheorem count_tt_eq_length_sub_count_ff : c.count_tt τ = c.length - c.count_ff τ :=\neq_tsub_of_add_eq (count_tt_plus_count_ff_eq_length τ c)\n\ntheorem count_ff_eq_length_sub_count_tt : c.count_ff τ = c.length - c.count_tt τ :=\neq_tsub_of_add_eq (add_comm (c.count_tt τ) (c.count_ff τ) ▸ count_tt_plus_count_ff_eq_length τ 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, ← ih],\n    { rw [add_comm (count_pos ls + count_neg ls) 1, ← 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) ▸ count_pos_plus_count_neg_eq_length c)\n\ntheorem count_tt_eq_zero_iff_eval_ff {τ : assignment V} {c : clause V} : \n  c.count_tt τ = 0 ↔ c.eval τ = 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 {τ : assignment V} {c : clause V} :\n  c.count_tt τ > 0 ↔ c.eval τ = 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 ⟨l, hl, he⟩,\n    exact ⟨l, hl, he⟩ },\n  { rintro ⟨l, hl, he⟩,\n    exact (countp_pos _).mpr ⟨l, hl, he⟩ } \nend\n\nend counting\n\n/-! # falsify and truthify -/\nsection falsify\n\nvariables (τ : assignment V) (v : V) (l : list V) {c c₁ c₂ : 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 (λ v, cond (τ v) (Neg v) (Pos v))\ndef truthify : clause V := l.map (λ v, cond (τ v) (Pos v) (Neg v))\n\n@[simp] lemma falsify_nil : falsify τ [] = [] := rfl\n@[simp] lemma truthify_nil : truthify τ [] = [] := rfl\n\n@[simp] lemma falsify_singleton : falsify τ [v] = cond (τ v) [Neg v] [Pos v] :=\nby cases h : τ v; simp [h, falsify]\n\n@[simp] lemma truthify_singleton : truthify τ [v] = cond (τ v) [Pos v] [Neg v] :=\nby cases h : τ v; simp [h, truthify]\n\n@[simp] theorem falsify_cons : falsify τ (v :: l) = cond (τ v) (Neg v :: falsify τ l) (Pos v :: falsify τ l) :=\nby cases h : τ v; simp [falsify, map_cons, h]\n\n@[simp] theorem truthify_cons : truthify τ (v :: l) = cond (τ v) (Pos v :: truthify τ l) (Neg v :: truthify τ l) :=\nby cases h : τ v; simp [truthify, map_cons, h]\n\ntheorem falsify_eval_ff : clause.eval τ (falsify τ l) = ff :=\nbegin\n  induction l with v vs ih,\n  { rw [falsify_nil, eval_nil] },\n  { cases h : (τ v); simp [h, eval_cons, literal.eval, ih] }\nend\n\ntheorem truthify_eval_tt {l : list V} (hl : l ≠ []) : clause.eval τ (truthify τ l) = tt :=\nbegin\n  induction l with v vs ih,\n  { contradiction },\n  { cases h : (τ v); simp [h, literal.eval, eval_cons] }\nend\n\ntheorem flip_truthify_eq_falsify : map literal.flip (truthify τ l) = falsify τ l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : (τ v); simp [h, literal.eval, ih, literal.flip] }\nend\n\ntheorem falsify_map_var_eq : map var (falsify τ l) = l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : (τ 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 τ l) = l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : (τ 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 τ (falsify τ l) = 0 :=\ncount_tt_eq_zero_iff_eval_ff.mpr (falsify_eval_ff τ l)\n\nlemma count_tt_truthify : clause.count_tt τ (truthify τ l) = length l :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { cases h : τ v; simp [literal.eval, h, ih, add_comm] }\nend\n\ntheorem count_tt_sublist : c₁ <+ c₂ → c₁.count_tt τ ≤ c₂.count_tt τ :=\nassume h, by simp [clause.count_tt, sublist.countp_le (literal.is_true τ) h]\n\ntheorem count_ff_sublist : c₁ <+ c₂ → c₁.count_ff τ ≤ c₂.count_ff τ :=\nassume h, by simp [clause.count_ff, sublist.countp_le (literal.is_false τ) h]\n\ntheorem count_pos_sublist : c₁ <+ c₂ → c₁.count_pos ≤ c₂.count_pos :=\nassume h, by simp [count_pos, sublist.countp_le literal.is_pos h]\n\ntheorem count_neg_sublist : c₁ <+ c₂ → c₁.count_neg ≤ c₂.count_neg :=\nassume h, by simp [count_neg, sublist.countp_le literal.is_neg h]\n\ntheorem pos_count_tt_iff_exists_tt {τ} : c.count_tt τ > 0 ↔ ∃ l, l ∈ c ∧ literal.is_true τ l :=\nby simp [clause.count_tt, countp_pos]\n\ntheorem pos_count_ff_iff_exists_ff {τ} : c.count_ff τ > 0 ↔ ∃ l, l ∈ c ∧ literal.is_false τ l :=\nby simp [clause.count_ff, countp_pos]\n\ntheorem pos_count_pos_iff_exists_pos : c.count_pos > 0 ↔ ∃ l, l ∈ c ∧ literal.is_pos l :=\nby simp [count_pos, countp_pos]\n\ntheorem pos_count_neg_iff_exists_neg : c.count_neg > 0 ↔ ∃ l, l ∈ c ∧ literal.is_neg l :=\nby simp [count_neg, countp_pos]\n\ntheorem count_tt_perm : c₁ ~ c₂ → ∀ (τ : assignment V), c₁.count_tt τ = c₂.count_tt τ :=\nbegin\n  intros hp τ,\n  induction hp with x l₂ l₂' p IH  x y l₂  l₂ m₂ r₂ p₁ p₂ IH₁ IH₂,\n  { refl },\n  { simp [count_tt_cons, IH] },\n  { simp [count_tt_cons], cases literal.eval τ x; cases literal.eval τ y; simp },\n  { exact eq.trans IH₁ IH₂ }\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 → clause V → 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₁ c₂ : clause V) (l₁ l₂ : literal V) :\n  count_flips (l₁ :: c₁) (l₂ :: c₂) = ite (l₁.flip = l₂) \n    (1 + count_flips c₁ c₂) (count_flips c₁ c₂) :=\nby by_cases l₁.flip = l₂; 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₁ c₂ : clause V) : count_flips c₁ c₂ = count_flips c₂ c₁ :=\nbegin\n  induction c₁ with l ls ih generalizing c₂,\n  { cases c₂; simp [count_flips] },\n  { cases c₂,\n    { refl },\n    { simp [count_flips, ih c₂_tl],\n      by_cases h : (l.flip = c₂_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₁ c₂ : clause V} :\n  map var c₁ = map var c₂ → c₁ ≠ c₂ → count_flips c₁ c₂ > 0 :=\nbegin\n  intros h hne,\n  induction c₁ with l ls ih generalizing c₂,\n  { exact absurd (eq_nil_of_map_eq_nil h.symm).symm hne },\n  { rcases exists_map_cons_of_map_cons h.symm with ⟨x, xs, rfl, hxl, hxs⟩,\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 (τ : assignment V) (c : clause V) :\n  count_flips c (falsify τ (map var c)) = clause.count_tt τ c :=\nbegin\n  induction c with l ls ih,\n  { simp },\n  { cases l; { cases h : (τ 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 {τ : assignment V} {l : list V} {c : clause V} :\n  map var c = l → clause.count_tt τ (map Pos l) ≠ count_neg c → c.eval τ = 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 ⟨l, ls, rfl, rfl, hls⟩,\n    cases l,\n    { cases h : τ 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 : τ 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 {τ : assignment V} {l : list V} {c : clause V} : \n  map var c = l → (clause.count_tt τ (map Pos l)).bodd ≠ (count_neg c).bodd → c.eval τ = tt :=\nλ 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 {τ : assignment V} {c₁ c₂ : clause V} :\n  map var c₁ = map var c₂ → c₁.count_tt τ ≠ count_flips c₁ c₂ → c₂.eval τ = tt :=\nbegin\n  induction c₁ with l ls ih generalizing c₂,\n  { simp },\n  { intros hc₂ hne,\n    rcases exists_map_cons_of_map_cons hc₂.symm with ⟨m, ms, rfl, hm, hms⟩,\n    cases m,\n    { cases h : (τ m),\n      { cases l;\n        { unfold var at hm,\n          simp [literal.eval, literal.flip, ← 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 : (τ 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, ← 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 → finset V\n| []        := ∅\n| (l :: ls) := {l.var} ∪ (vars ls) \n--| (l :: ls) := insert l.var (vars ls) -- Use insert instead?\n\n@[simp] theorem vars_nil : clause.vars ([] : clause V) = ∅ := rfl\n\n@[simp] theorem vars_singleton (l : literal V) : clause.vars [l] = {l.var} := rfl\n\ntheorem mem_vars_cons_self (l : literal V) (c : clause V) : l.var ∈ 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 ∈ c.vars → v ∈ clause.vars (l :: c) :=\nassume h, finset.mem_union.mpr (or.inr h)\n\ntheorem vars_append (c₁ c₂ : clause V) : (c₁ ++ c₂).vars = c₁.vars ∪ c₂.vars :=\nbegin\n  induction c₁ 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₁ c₂ : clause V} : c₁ ~ c₂ → c₁.vars = c₂.vars :=\nbegin\n  intro hp,\n  induction hp with _ _ _ _ IH  x y _  _ _ _ _ _ IH₁ IH₂,\n  { refl },\n  { unfold clause.vars, rw IH },\n  { unfold clause.vars,\n    rw [← finset.union_assoc, ← finset.union_assoc, finset.union_comm {x.var} {y.var}] },\n  { exact eq.trans IH₁ IH₂ }\nend\n\ntheorem mem_vars_of_mem {c : clause V} {l : literal V} : l ∈ c → l.var ∈ 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 ∈ c.vars → ∃ (l : literal V), l ∈ c ∧ 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₁| h₂,\n      { exact absurd (finset.mem_singleton.mp h₁).symm h },\n      { rcases ih h₂ with ⟨m, hm, hv⟩, 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 ⊆ clause.vars (l :: c) :=\nfinset.subset_union_right _ _\n\ntheorem vars_subset_of_subset {c₁ c₂ : clause V} : c₁ ⊆ c₂ → c₁.vars ⊆ c₂.vars :=\nbegin\n  intros h v hv,\n  rcases exists_mem_clause_of_mem_vars hv with ⟨l, hl, rfl⟩,\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 ∈ c.vars ↔ v ∈ 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 ⟨l, hmem, hv⟩,\n    exact hv ▸ mem_vars_of_mem hmem }\nend\n\ntheorem not_mem_vars_iff_not_mem_map_vars : v ∉ map var c ↔ v ∉ c.vars :=\nby simp [mem_vars_iff_mem_map_vars]\n\ntheorem mem_vars_iff_pos_or_neg_mem_clause : v ∈ c.vars ↔ (Pos v) ∈ c ∨ (Neg v) ∈ c :=\nbegin\n  split,\n  { intro h,\n    rcases exists_mem_clause_of_mem_vars h with ⟨l, hmem, hv⟩,\n    cases l; { rw ← hv, simp [var, hmem] } },\n  { rintros (h | h); { exact mem_vars_of_mem h } }\nend\n\ntheorem vars_append_subset_left (c₁ c₂ : clause V) : c₁.vars ⊆ (c₁ ++ c₂).vars :=\nby { rw vars_append, exact finset.subset_union_left _ _ }\n\ntheorem vars_append_subset_right (c₁ c₂ : clause V) : c₂.vars ⊆ (c₁ ++ c₂).vars :=\nby { rw vars_append, exact finset.subset_union_right _ _ }\n\ntheorem mem_vars_append_left {c₁ : clause V} (c₂) : v ∈ c₁.vars → v ∈ (c₁ ++ c₂).vars :=\nassume h, vars_append_subset_left c₁ c₂ h\n\ntheorem mem_vars_append_right (c₁) {c₂ : clause V} : v ∈ c₂.vars → v ∈ (c₁ ++ c₂).vars :=\nassume h, vars_append_subset_right c₁ c₂ h\n\ntheorem mem_left_or_right_of_mem_vars_append {c₁ c₂ : clause V} :\n  v ∈ (c₁ ++ c₂).vars → (v ∈ c₁.vars) ∨ (v ∈ c₂.vars) :=\nby { rw vars_append, exact finset.mem_union.mp }\n\ntheorem not_mem_vars_append_left {c₁ c₂ : clause V} : v ∉ (c₁ ++ c₂).vars → v ∉ c₁.vars :=\nassume h, mt (mem_vars_append_left c₂) h\n\ntheorem not_mem_vars_append_right {c₁ c₂ : clause V} : v ∉ (c₁ ++ c₂).vars → v ∉ c₂.vars :=\nassume h, mt (mem_vars_append_right c₁) h\n\ntheorem not_mem_vars_append_of_not_mem_of_not_mem {c₁ c₂ : clause V} :\n  v ∉ c₁.vars → v ∉ c₂.vars → v ∉ (c₁ ++ c₂).vars :=\nbegin\n  intros h₁ h₂ hcon,\n  rcases mem_left_or_right_of_mem_vars_append hcon; { contradiction }\nend\n\nend mem_vars_lemmas\n\nopen assignment\n\nvariables {τ₁ τ₂ : assignment V} {c : clause V}\n\ntheorem eval_eq_of_eqod : (eqod τ₁ τ₂ c.vars) → c.eval τ₁ = c.eval τ₂ :=\nbegin\n  intro h,\n  cases hev : (c.eval τ₂),\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 ▸ eval_eq_of_eqod_of_var_mem h (mem_vars_of_mem hl) },\n  { rcases eval_tt_iff_exists_literal_eval_tt.mp hev with ⟨l, hl, htt⟩,\n    apply eval_tt_iff_exists_literal_eval_tt.mpr,\n    use [l, hl],\n    exact htt ▸ eval_eq_of_eqod_of_var_mem h (mem_vars_of_mem hl) }  \nend\n\ntheorem count_tt_eq_of_eqod : (eqod τ₁ τ₂ c.vars) → c.count_tt τ₁ = c.count_tt τ₂ :=\nbegin\n  induction c with l ls ih,\n  { simp only [count_tt_nil, eqod_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, eqod_union_left h l (finset.mem_singleton_self l), ih (eqod_union_right h)] } }\nend\n\ntheorem count_tt_ite (c : clause V) : c.count_tt (assignment.ite c.vars τ₁ τ₂) = c.count_tt τ₁ :=\ncount_tt_eq_of_eqod (ite_eqod c.vars τ₁ τ₂)\n\nend vars\n\nend clause", "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/clause.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7686725577023652}}
{"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! This file was ported from Lean 3 source module main\n-/\nimport Mathlib.Data.Int.Parity\nimport Mathlib.RingTheory.Int.Basic\n\n--set_option synthInstance.etaExperiment true\n\nsection\n\nvariable {R : Type _} [CommRing R] {x y z : R}\n\ntheorem coprime_add_self_pow {n : ℕ} (hn : 0 < n) (hsoln : x ^ n + y ^ n = z ^ n)\n    (hxx : IsCoprime x y) : IsCoprime x z := by\n  have := IsCoprime.mul_add_left_right (hxx.pow (n := n) (m := n)) 1\n  rwa [mul_one, hsoln, IsCoprime.pow_iff hn hn] at this\n#align coprime_add_self_pow coprime_add_self_pow\n\nend\n\n-- Edwards p49 introduction\ntheorem Int.factor_div (a x : ℤ) (hodd : Odd x) :\n    ∃ m c : ℤ, c + m * x = a ∧ 2 * c.natAbs < x.natAbs :=\n  by\n  have h0' : x ≠ 0 := by\n    rintro rfl\n    simp only [even_zero, not_true, Int.odd_iff_not_even] at hodd\n  set c := a % x with hc\n  by_cases H : 2 * c.natAbs < x.natAbs\n  · exact ⟨a / x, c, Int.emod_add_ediv' a x, H⟩\n  · push_neg  at H\n    refine' ⟨(a + abs x) / x, c - abs x, _, _⟩\n    · have := self_dvd_abs x\n      rw [Int.add_ediv_of_dvd_right this, add_mul, Int.ediv_mul_cancel this, sub_add_add_cancel, hc,\n        Int.emod_add_ediv']\n    · rw [← Int.ofNat_lt]\n      replace H := Int.ofNat_le_ofNat_of_le H\n      have ofNat_two : ((2 : Nat) : Int) = 2 := rfl\n      rw [Int.ofNat_mul, ofNat_two] at H⊢\n      have hcnonneg := Int.emod_nonneg a h0'\n      have := Int.emod_lt a h0'\n      rw [Int.natAbs_of_nonneg hcnonneg] at H\n      rw [← Int.natAbs_neg, neg_sub, Int.natAbs_of_nonneg (sub_nonneg_of_le this.le), mul_sub,\n        sub_lt_iff_lt_add, two_mul, Int.abs_eq_natAbs, add_lt_add_iff_left]\n      apply lt_of_le_of_ne H\n      contrapose! hodd with heqtwomul\n      rw [← Int.even_iff_not_odd, ← Int.natAbs_even, ← Int.even_coe_nat, even_iff_two_dvd]\n      exact ⟨_, heqtwomul⟩\n#align int.factor_div Int.factor_div\n\ntheorem two_not_cube (r : ℕ) : r ^ 3 ≠ 2 := by\n  have : 1 ≤ 3 := by norm_num\n  apply Monotone.ne_of_lt_of_lt_nat (Nat.pow_left_strictMono this).monotone 1 <;> norm_num\n#align two_not_cube two_not_cube\n\nnonrec theorem Int.two_not_cube (r : ℤ) : r ^ 3 ≠ 2 := by\n  intro H\n  apply two_not_cube r.natAbs\n  rw [← Int.natAbs_pow, H]\n  norm_num\n#align int.two_not_cube Int.two_not_cube\n\n-- todo square neg_square and neg_pow_bit0\nsection\n\nvariable {R : Type _} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] [GCDMonoid R]\n\ntheorem Irreducible.coprime_of_not_dvd_of_dvd {p k m : R} (hp : Irreducible p) (hdvd1 : ¬p ∣ m)\n    (hdvd2 : k ∣ m) : IsCoprime p k :=\n  (Irreducible.coprime_iff_not_dvd hp).mpr fun hdvd1' => hdvd1 (hdvd1'.trans hdvd2)\n#align irreducible.coprime_of_not_dvd_of_dvd Irreducible.coprime_of_not_dvd_of_dvd\n\ntheorem Irreducible.dvd_of_dvd_mul_left {p k m n : R} (hdvd1 : ¬p ∣ m) (hdvd2 : k ∣ m)\n    (hp : Irreducible p) (h : k ∣ p * n) : k ∣ n :=\n  (hp.coprime_of_not_dvd_of_dvd hdvd1 hdvd2).symm.dvd_of_dvd_mul_left h\n#align irreducible.dvd_of_dvd_mul_left Irreducible.dvd_of_dvd_mul_left\n\nend\n\ntheorem Int.dvd_mul_cancel_prime' {p k m n : ℤ} (hdvd1 : ¬p ∣ m) (hdvd2 : k ∣ m) (hp : Prime p)\n    (h : k ∣ p * n) : k ∣ n :=\n  Irreducible.dvd_of_dvd_mul_left hdvd1 hdvd2 hp.irreducible h\n#align int.dvd_mul_cancel_prime' Int.dvd_mul_cancel_prime'\n\n", "meta": {"author": "Ruben-VandeVelde", "repo": "flt4", "sha": "4dcb33f3b55ade25b865446ebde5e57d2f327e36", "save_path": "github-repos/lean/Ruben-VandeVelde-flt4", "path": "github-repos/lean/Ruben-VandeVelde-flt4/flt4-4dcb33f3b55ade25b865446ebde5e57d2f327e36/Flt/Primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564152, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7686384481224496}}
{"text": "import algebra.ring.boolean_ring\n\ntheorem decide_diophantine2_1 (a b n x y : ℕ): a*x+b*y =n → 0 < a → x < n/a + 1 :=\n  λ h, λ ha: 0 < a,\n  have hh: x*a ≤ n, from\n    calc _ = a*x + 0    : by ring\n       ... ≤ a*x + (b*y) : add_le_add_left (nat.zero_le  _) (a*x)\n       ... = _           : h,\n  calc _ ≤ n/a           : (nat.le_div_iff_mul_le ha).mpr hh\n     ... < _             : lt_add_one (n/a)\n\ntheorem decide_diophantine2_2 (a b n x y : ℕ):\n  a*x+b*y =n → 0 < a → 0 < b → x < n/a + 1 ∧ y < n/b + 1 :=\n  λ g1, λ ha hb,\n  have g2:b*y+a*x =n, from calc _ = a*x+b*y : by ring\n                              ... = _       : g1,\n  have h1: x < n/a + 1, from decide_diophantine2_1 a b n x y g1 ha,\n  have h2: y < n/b + 1, from decide_diophantine2_1 b a n y x g2 hb,\n  and.intro h1 h2\n\ninstance example_1_59 :\n  decidable (∀ x y : ℕ, 2*x+3*y=7 ∧ (x>0→ y>0) ↔ x=2∧  y=1) :=\n  decidable_of_iff \n  (∀ x : fin (7/2+1), ∀ y: fin(7/3+1), 2*x.1+3*y.1=7 ∧ (x.1>0→ y.1>0) ↔ x.1=2∧  y.1=1)\n  (\n    iff.intro (\n      λ h x y, iff.intro (\n        λ h1,\n        have H: 2 * x + 3 * y = 7 ∧ (x > 0 → y > 0) ↔ x = 2 ∧ y = 1, from\n          h ⟨ x,\n            (decide_diophantine2_2 2 3 7 x y h1.1 (two_pos) three_pos).1\n          ⟩ ⟨y,\n            (decide_diophantine2_2 2 3 7 x y h1.1 (two_pos) three_pos).2\n          ⟩,\n        H.mp h1\n      )\n      (\n        λ hxy, and.intro (\n          calc 2 * x + 3 * y = 2 * x + 3 * 1: by rw hxy.2\n                         ... = 2 * 2 + 3 * 1: by rw hxy.1\n                         ... = 7: dec_trivial\n        ) (\n          λ hx, calc y = 1: hxy.2\n                   ... > 0: one_pos\n        )\n      )\n    ) (\n      λ h, λ x y, h x.val y.val\n    )\n  )\n\nexample : (∀ x y : ℕ, 2*x+3*y=7 ∧ (x>0→ y>0) ↔ x=2∧  y=1) := dec_trivial\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/2x+3y=7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202038, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.76845925557637}}
{"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 data.nat.parity\nimport order.filter.at_top_bot\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 ≡ d [MOD n]` frequently as `m → ∞`.\n-/\n\nopen filter\n\nnamespace nat\n\n/-- Infinitely many natural numbers are equal to `d` mod `n`. -/\n\n\nlemma frequently_mod_eq {d n : ℕ} (h : d < n) : ∃ᶠ m in at_top, m % n = d :=\nby simpa only [nat.modeq, mod_eq_of_lt h] using frequently_modeq h.ne_bot d\n\nlemma frequently_even : ∃ᶠ m : ℕ in at_top, even m :=\nby simpa only [even_iff] using frequently_mod_eq zero_lt_two\n\nlemma frequently_odd : ∃ᶠ m : ℕ in at_top, odd m :=\nby simpa only [odd_iff] using frequently_mod_eq one_lt_two\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/order/filter/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133515091157, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7684491743831389}}
{"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 analysis.special_functions.log.base\nimport measure_theory.measure.measure_space_def\n\n/-!\n# Doubling measures\n\nA doubling measure `μ` on a metric space is a measure for which there exists a constant `C` such\nthat for all sufficiently small radii `ε`, and for any centre, the measure of a ball of radius\n`2 * ε` is bounded by `C` times the measure of the concentric ball of radius `ε`.\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\nnoncomputable theory\n\nopen set filter metric measure_theory topological_space\nopen_locale ennreal nnreal topology\n\n/-- A measure `μ` is said to be a doubling measure if there exists a constant `C` such that for\nall sufficiently small radii `ε`, and for any centre, the measure of a ball of radius `2 * ε` is\nbounded by `C` times the measure of the concentric ball of radius `ε`.\n\nNote: it is important that this definition makes a demand only for sufficiently small `ε`. 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 `ε` is `A(ε) = 2π(cosh(ε) - 1)` so `A(2ε)/A(ε) ~ exp(ε)`.\n-/\nclass is_doubling_measure {α : Type*} [metric_space α] [measurable_space α] (μ : measure α) :=\n(exists_measure_closed_ball_le_mul [] :\n  ∃ (C : ℝ≥0), ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closed_ball x (2 * ε)) ≤ C * μ (closed_ball x ε))\n\nnamespace is_doubling_measure\n\nvariables {α : Type*} [metric_space α] [measurable_space α] (μ : measure α) [is_doubling_measure μ]\n\n/-- A doubling constant for a doubling measure.\n\nSee also `is_doubling_measure.scaling_constant_of`. -/\ndef doubling_constant : ℝ≥0 := classical.some $ exists_measure_closed_ball_le_mul μ\n\nlemma exists_measure_closed_ball_le_mul' :\n  ∀ᶠ ε in 𝓝[>] 0, ∀ x, μ (closed_ball x (2 * ε)) ≤ doubling_constant μ * μ (closed_ball x ε) :=\nclassical.some_spec $ exists_measure_closed_ball_le_mul μ\n\nlemma exists_eventually_forall_measure_closed_ball_le_mul (K : ℝ) :\n  ∃ (C : ℝ≥0), ∀ᶠ ε in 𝓝[>] 0, ∀ x t (ht : t ≤ K),\n    μ (closed_ball x (t * ε)) ≤ C * μ (closed_ball x ε) :=\nbegin\n  let C := doubling_constant μ,\n  have hμ : ∀ (n : ℕ), ∀ᶠ ε in 𝓝[>] 0, ∀ x,\n    μ (closed_ball x (2^n * ε)) ≤ ↑(C^n) * μ (closed_ball x ε),\n  { intros n,\n    induction n with n ih, { simp, },\n    replace ih := eventually_nhds_within_pos_mul_left (two_pos : 0 < (2 : ℝ)) ih,\n    refine (ih.and (exists_measure_closed_ball_le_mul' μ)).mono (λ ε hε x, _),\n    calc μ (closed_ball x (2^(n + 1) * ε))\n          = μ (closed_ball x (2^n * (2 * ε))) : by rw [pow_succ', mul_assoc]\n      ... ≤ ↑(C^n) * μ (closed_ball x (2 * ε)) : hε.1 x\n      ... ≤ ↑(C^n) * (C * μ (closed_ball x ε)) : ennreal.mul_left_mono (hε.2 x)\n      ... = ↑(C^(n + 1)) * μ (closed_ball x ε) : by rw [← mul_assoc, pow_succ', ennreal.coe_mul], },\n  rcases lt_or_le K 1 with hK | hK,\n  { refine ⟨1, _⟩,\n    simp only [ennreal.coe_one, one_mul],\n    exact eventually_mem_nhds_within.mono (λ ε hε x t ht,\n      measure_mono $ closed_ball_subset_closed_ball (by nlinarith [mem_Ioi.mp hε])), },\n  { refine ⟨C^⌈real.logb 2 K⌉₊, ((hμ ⌈real.logb 2 K⌉₊).and eventually_mem_nhds_within).mono\n      (λ ε hε x t ht, le_trans (measure_mono $ closed_ball_subset_closed_ball _) (hε.1 x))⟩,\n    refine mul_le_mul_of_nonneg_right (ht.trans _) (mem_Ioi.mp hε.2).le,\n    conv_lhs { rw ← real.rpow_logb two_pos (by norm_num) (by linarith : 0 < K), },\n    rw ← real.rpow_nat_cast,\n    exact real.rpow_le_rpow_of_exponent_le one_le_two (nat.le_ceil (real.logb 2 K)), },\nend\n\n/-- A variant of `is_doubling_measure.doubling_constant` which allows for scaling the radius by\nvalues other than `2`. -/\ndef scaling_constant_of (K : ℝ) : ℝ≥0 :=\nmax (classical.some $ exists_eventually_forall_measure_closed_ball_le_mul μ K) 1\n\n@[simp] lemma one_le_scaling_constant_of (K : ℝ) : 1 ≤ scaling_constant_of μ K :=\nle_max_of_le_right $ le_refl 1\n\nlemma eventually_measure_mul_le_scaling_constant_of_mul (K : ℝ) :\n  ∃ (R : ℝ), 0 < R ∧ ∀ x t r (ht : t ∈ Ioc 0 K) (hr : r ≤ R),\n    μ (closed_ball x (t * r)) ≤ scaling_constant_of μ K * μ (closed_ball x r) :=\nbegin\n  have h := classical.some_spec (exists_eventually_forall_measure_closed_ball_le_mul μ K),\n  rcases mem_nhds_within_Ioi_iff_exists_Ioc_subset.1 h with ⟨R, Rpos, hR⟩,\n  refine ⟨R, Rpos, λ x t r ht hr, _⟩,\n  rcases lt_trichotomy r 0 with rneg|rfl|rpos,\n  { have : t * r < 0, from mul_neg_of_pos_of_neg ht.1 rneg,\n    simp only [closed_ball_eq_empty.2 this, measure_empty, zero_le'] },\n  { simp only [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  { apply (hR ⟨rpos, hr⟩ x t ht.2).trans _,\n    exact mul_le_mul_right' (ennreal.coe_le_coe.2 (le_max_left _ _)) _ }\nend\n\nlemma eventually_measure_le_scaling_constant_mul (K : ℝ) :\n  ∀ᶠ r in 𝓝[>] 0, ∀ x,\n    μ (closed_ball x (K * r)) ≤ scaling_constant_of μ K * μ (closed_ball x r) :=\nbegin\n  filter_upwards [classical.some_spec (exists_eventually_forall_measure_closed_ball_le_mul μ K)]\n    with r hr x,\n  exact (hr x K le_rfl).trans (mul_le_mul_right' (ennreal.coe_le_coe.2 (le_max_left _ _)) _)\nend\n\nlemma eventually_measure_le_scaling_constant_mul' (K : ℝ) (hK : 0 < K) :\n  ∀ᶠ r in 𝓝[>] 0, ∀ x,\n    μ (closed_ball x r) ≤ scaling_constant_of μ K⁻¹ * μ (closed_ball x (K * r)) :=\nbegin\n  convert eventually_nhds_within_pos_mul_left hK (eventually_measure_le_scaling_constant_mul μ K⁻¹),\n  ext,\n  simp [inv_mul_cancel_left₀ hK.ne'],\nend\n\n/-- A scale below which the doubling measure `μ` 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 scaling_scale_of (K : ℝ) : ℝ :=\n(eventually_measure_mul_le_scaling_constant_of_mul μ K).some\n\nlemma scaling_scale_of_pos (K : ℝ) : 0 < scaling_scale_of μ K :=\n(eventually_measure_mul_le_scaling_constant_of_mul μ K).some_spec.1\n\nlemma measure_mul_le_scaling_constant_of_mul {K : ℝ} {x : α} {t r : ℝ}\n  (ht : t ∈ Ioc 0 K) (hr : r ≤ scaling_scale_of μ K) :\n  μ (closed_ball x (t * r)) ≤ scaling_constant_of μ K * μ (closed_ball x r) :=\n(eventually_measure_mul_le_scaling_constant_of_mul μ K).some_spec.2 x t r ht hr\n\nend is_doubling_measure\n", "meta": {"author": "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/doubling.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.8267118026095992, "lm_q1q2_score": 0.7683793565015328}}
{"text": "/-\nCopyright (c) 2021 Ivan Sadofschi Costa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ivan Sadofschi Costa\n-/\nimport data.fin.tuple\nimport data.finsupp.basic\n\n/-!\n# `cons` and `tail` for maps `fin n →₀ M`\n\nWe interpret maps `fin n →₀ M` as `n`-tuples of elements of `M`,\nWe define the following operations:\n* `finsupp.tail` : the tail of a map `fin (n + 1) →₀ M`, i.e., its last `n` entries;\n* `finsupp.cons` : adding an element at the beginning of an `n`-tuple, to get an `n + 1`-tuple;\n\nIn this context, we prove some usual properties of `tail` and `cons`, analogous to those of\n`data.fin.tuple.basic`.\n-/\n\nnoncomputable theory\n\nnamespace finsupp\n\nvariables {n : ℕ} (i : fin n) {M : Type*} [has_zero M] (y : M)\n  (t : fin (n + 1) →₀ M) (s : fin n →₀ M)\n\n/-- `tail` for maps `fin (n + 1) →₀ M`. See `fin.tail` for more details. -/\ndef tail (s : fin (n + 1) →₀ M) : fin n →₀ M :=\nfinsupp.equiv_fun_on_fintype.inv_fun (fin.tail s.to_fun)\n\n/-- `cons` for maps `fin n →₀ M`. See `fin.cons` for more details. -/\ndef cons (y : M) (s : fin n →₀ M) : fin (n + 1) →₀ M :=\nfinsupp.equiv_fun_on_fintype.inv_fun (fin.cons y s.to_fun)\n\nlemma tail_apply : tail t i = t i.succ :=\nbegin\n  simp only [tail, equiv_fun_on_fintype_symm_apply_to_fun, equiv.inv_fun_as_coe],\n  refl,\nend\n\n@[simp] lemma cons_zero : cons y s 0 = y :=\nby simp [cons, finsupp.equiv_fun_on_fintype]\n\n@[simp] lemma cons_succ : cons y s i.succ = s i :=\nbegin\n  simp only [finsupp.cons, fin.cons, finsupp.equiv_fun_on_fintype, fin.cases_succ, finsupp.coe_mk],\n  refl,\nend\n\n@[simp] lemma tail_cons : tail (cons y s) = s :=\nbegin\n  simp only [finsupp.cons, fin.cons, finsupp.tail, fin.tail],\n  ext,\n  simp only [equiv_fun_on_fintype_symm_apply_to_fun, equiv.inv_fun_as_coe,\n    finsupp.coe_mk, fin.cases_succ, equiv_fun_on_fintype],\n  refl,\nend\n\n@[simp] lemma cons_tail : cons (t 0) (tail t) = t :=\nbegin\n  ext,\n  by_cases c_a : a = 0,\n  { rw [c_a, cons_zero] },\n  { rw [←fin.succ_pred a c_a, cons_succ, ←tail_apply] },\nend\n\n@[simp] lemma cons_zero_zero : cons 0 (0 : fin n →₀ M) = 0 :=\nbegin\n  ext,\n  by_cases c : a = 0,\n  { simp [c] },\n  { rw [←fin.succ_pred a c, cons_succ],\n    simp },\nend\n\nvariables {s} {y}\n\nlemma cons_ne_zero_of_left (h : y ≠ 0) : cons y s ≠ 0 :=\nbegin\n  contrapose! h with c,\n  rw [←cons_zero y s, c, finsupp.coe_zero, pi.zero_apply],\nend\n\nlemma cons_ne_zero_of_right (h : s ≠ 0) : cons y s ≠ 0 :=\nbegin\n  contrapose! h with c,\n  ext,\n  simp [ ← cons_succ a y s, c],\nend\n\nlemma cons_ne_zero_iff : cons y s ≠ 0 ↔ y ≠ 0 ∨ s ≠ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, h.cases_on cons_ne_zero_of_left cons_ne_zero_of_right⟩,\n  refine imp_iff_not_or.1 (λ h' c, h _),\n  rw [h', c, finsupp.cons_zero_zero],\nend\n\nend finsupp\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/finsupp/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782094, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.7683610267871063}}
{"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\ntheorem h : \"Hello\" = \"He\" ++ \"llo\" := rfl\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": "Mnormansell", "repo": "Discrete-Notes", "sha": "61f13b98be590269fc4822be7b47924a6ddc1261", "save_path": "github-repos/lean/Mnormansell-Discrete-Notes", "path": "github-repos/lean/Mnormansell-Discrete-Notes/Discrete-Notes-61f13b98be590269fc4822be7b47924a6ddc1261/01_Equality/05_automation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.880797076413356, "lm_q1q2_score": 0.7683610201565434}}
{"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 Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.linear_algebra.dual\nimport Mathlib.PostPort\n\nuniverses u v \n\nnamespace Mathlib\n\n/-!\n# Contractions\n\nGiven modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps:\n$M^* \\otimes M \\to R$, $M \\otimes M^* \\to R$, and $M^* \\otimes N → Hom(M, N)$, as well as proving\nsome basic properties of these maps.\n\n## Tags\n\ncontraction, dual module, tensor product\n-/\n\n/-- The natural left-handed pairing between a module and its dual. -/\ndef contract_left (R : Type u) (M : Type v) [comm_ring R] [add_comm_group M] [module R M] : linear_map R (tensor_product R (module.dual R M) M) R :=\n  linear_map.to_fun (tensor_product.uncurry R (module.dual R M) M R) linear_map.id\n\n/-- The natural right-handed pairing between a module and its dual. -/\ndef contract_right (R : Type u) (M : Type v) [comm_ring R] [add_comm_group M] [module R M] : linear_map R (tensor_product R M (module.dual R M)) R :=\n  linear_map.to_fun (tensor_product.uncurry R M (module.dual R M) R) (linear_map.flip linear_map.id)\n\n/-- The natural map associating a linear map to the tensor product of two modules. -/\ndef dual_tensor_hom (R : Type u) (M : Type v) (N : Type v) [comm_ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N] : linear_map R (tensor_product R (module.dual R M) N) (linear_map R M N) :=\n  let M' : Type (max v u) := module.dual R M;\n  coe_fn (tensor_product.uncurry R M' N (linear_map R M N)) linear_map.smul_rightₗ\n\n@[simp] theorem contract_left_apply {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (f : module.dual R M) (m : M) : coe_fn (contract_left R M) (tensor_product.tmul R f m) = coe_fn f m :=\n  tensor_product.uncurry_apply linear_map.id f m\n\n@[simp] theorem contract_right_apply {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (f : module.dual R M) (m : M) : coe_fn (contract_right R M) (tensor_product.tmul R m f) = coe_fn f m :=\n  tensor_product.uncurry_apply (linear_map.flip linear_map.id) m f\n\n@[simp] theorem dual_tensor_hom_apply {R : Type u} {M : Type v} {N : Type v} [comm_ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N] (f : module.dual R M) (m : M) (n : N) : coe_fn (coe_fn (dual_tensor_hom R M N) (tensor_product.tmul R f n)) m = coe_fn f m • 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/linear_algebra/contraction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7683510218433137}}
{"text": "/-\nThe goal of this file is to prove the following.  If S ⊆ ℂ^n is a subspace and L : S → V is\nan isometry, then there exists an isometry M : ℂ^n → ℂ^n such that M(s) = L(s) for every s ∈ S.\n\n-- Checked over by: \n-- Hans\n-/\n\nimport analysis.inner_product_space.pi_L2\nopen_locale complex_conjugate\n\nvariable {n : ℕ}\n\nlocal notation `ℂ^` n := euclidean_space ℂ (fin n)\n\nvariables (S : submodule ℂ (ℂ^n)) (L : S →ₗᵢ[ℂ] ℂ^n)\n\nlocal notation `dim ` S := finite_dimensional.finrank ℂ S\n\nlocal notation `range ` L := L.to_linear_map.range\n\nlocal notation `proj ` S := orthogonal_projection S\n\n/-\ndim L(S) = dim S\n-/\nlemma dim_range_eq_dim : (dim (range L)) = (dim S) :=\nbegin\n  have equiv_of_image := linear_equiv.of_injective (L.to_linear_map) L.injective,\n  have : (dim S) = (dim (range L)) :=\n  begin\n    apply finite_dimensional.nonempty_linear_equiv_iff_finrank_eq.1,\n    use equiv_of_image,\n    exact finite_dimensional.finite_dimensional_submodule S,\n    exact finite_dimensional.finite_dimensional_submodule (L.to_linear_map).range,\n  end,\n  rw this,\nend \n\n/-\n(dim Sᗮ) = (dim ℂ^n) - (dim S)\n-/\nlemma finrank_orthogonal_eq_finrank_sub (S : submodule ℂ (ℂ^n)) :\n  (dim Sᗮ) = (dim ℂ^n) - (dim S) :=\nbegin\n  have : (dim S) + (dim Sᗮ) = (dim ℂ^n) := S.finrank_add_finrank_orthogonal,\n  symmetry,\n  rw nat.sub_eq_iff_eq_add,\n  rw add_comm,\n  symmetry,\n  exact this,\n  apply submodule.finrank_le,\nend\n\n/-\ndim L(S)ᗮ = dim Sᗮ\n-/\nlemma dim_orthogonal_range_eq_dim_orthogonal : (dim (range L)ᗮ) = (dim Sᗮ) :=\nbegin\n  exact calc (dim (range L)ᗮ) = (dim ℂ^n) - (dim (range L)) : finrank_orthogonal_eq_finrank_sub (range L)\n  ...                         = (dim ℂ^n) - (dim S)         : by rw dim_range_eq_dim\n  ...                         = (dim Sᗮ)                     : by rw ← finrank_orthogonal_eq_finrank_sub S,\nend\n\n/-\nWe have an isometry L' between Sᗮ and L(S)ᗮ by mapping through Euclidean space.\n-/\nlemma complementary_isometry : ∃ (L' : (Sᗮ →ₗᵢ[ℂ] (range L)ᗮ)), true :=\nbegin\n  have : (dim Sᗮ) = (dim Sᗮ) := by simp only [eq_self_iff_true],\n  let L1 := (linear_isometry_equiv.of_inner_product_space this).to_linear_isometry,\n  let L2 := (linear_isometry_equiv.of_inner_product_space (dim_orthogonal_range_eq_dim_orthogonal S L)).symm.to_linear_isometry,\n  use (L2.comp L1),\nend\n\n\nnoncomputable def L' := (range L)ᗮ.subtypeₗᵢ.comp (complementary_isometry S L).some\n\n/-\nWe build a linear map on ℂ^n by projecting and applying our isometries.\n-/\n\nlocal notation `extend ` L := \n  L.to_linear_map.comp (proj S).to_linear_map + (L' S L).to_linear_map.comp (proj Sᗮ).to_linear_map\n\n/-\nThe Pythagorean theorem, applied to members of S and Sᗮ.\n-/\nlemma norm_add_sq_orthogonal (x y : ℂ^n) (hx : x ∈ S) (hy : y ∈ Sᗮ) : ∥ x + y ∥^2 = ∥ x ∥^2 + ∥ y ∥^2 :=\nbegin\n  iterate {rw sq},  \n  apply norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero x y (submodule.inner_right_of_mem_orthogonal hx hy),\nend\n\n/-\nThe extension (extend L) is an isometry.\n-/\nlemma extend_isometry : ∀ (x : ℂ^n), ∥ (extend L) x ∥^2 = ∥ x ∥^2 :=\nbegin\n  intro x,\n  have x_decomp : x = ↑((proj S) x) + ↑((proj Sᗮ) x) := eq_sum_orthogonal_projection_self_orthogonal_complement S x,\n  conv\n  begin\n    to_rhs,\n    rw x_decomp,\n  end,\n  have h_xS : ↑((proj S) x) ∈ S := set_like.coe_mem ((proj S) x),\n  have h_xSperp : ↑((proj Sᗮ) x) ∈ Sᗮ := set_like.coe_mem ((proj Sᗮ) x),\n  rw norm_add_sq_orthogonal S ((proj S) x) ((proj Sᗮ) x) h_xS h_xSperp,\n\n  have Mx_decomp : (extend L) x = L ((proj S) x) + (L' S L)((proj Sᗮ) x) :=\n  begin\n    simp only [linear_isometry.coe_to_linear_map, continuous_linear_map.to_linear_map_eq_coe,\n      add_left_inj, eq_self_iff_true, function.comp_app, linear_map.coe_comp, linear_isometry.map_eq_iff,\n      continuous_linear_map.coe_coe, linear_map.add_apply],\n  end,\n  rw Mx_decomp,\n  have h_Lx : L ((proj S) x) ∈ (range L) := L.to_linear_map.mem_range_self ((proj S) x),\n  have h_L'x : (L' S L)((proj Sᗮ) x) ∈ (range L)ᗮ :=\n  begin\n    rw L',\n    simp only [ submodule.subtype_apply, linear_isometry.coe_comp,\n      function.comp_app, submodule.coe_mem, submodule.coe_subtypeₗᵢ ],\n  end,\n  rw norm_add_sq_orthogonal (range L) (L ((proj S) x)) ((L' S L) ((proj Sᗮ) x)) h_Lx h_L'x,\n  simp only [linear_isometry.norm_map, submodule.coe_norm],\nend\n\n/-\nThe extension (extend L) agrees with L on S.\n-/\n\nlemma extend_on_submodule : ∀ (s : S), (extend L) s = L s :=\nbegin\n  intro s,\n  simp only [add_right_eq_self,\n    linear_isometry.coe_to_linear_map,\n    continuous_linear_map.to_linear_map_eq_coe,\n    function.comp_app,\n    orthogonal_projection_mem_subspace_eq_self,\n    linear_map.coe_comp,\n    continuous_linear_map.coe_coe,\n    linear_map.add_apply],\n  rw orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,\n  simp only [eq_self_iff_true, linear_isometry.map_zero],\n  simp only [submodule.orthogonal_orthogonal, submodule.coe_mem],\nend\n\n/-\nThere exists an isometry that extends L, namely (extend L).\n-/\ntheorem isometry_extend : ∃ (M : (ℂ^n) →ₗᵢ[ℂ] (ℂ^n)), (∀ (s : S), M s = L s) :=\nbegin\n  let M := (extend L),\n  use M,\n  have : ∀ (x : ℂ^n), ∥ M x ∥^2 = ∥ x ∥^2 := extend_isometry S L,\n  intro x,\n  specialize this x,\n  rw sq_eq_sq at this,\n  exact this,\n  exact norm_nonneg _,\n  exact norm_nonneg _,\n  exact extend_on_submodule S L,\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/isometry_extend.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7683510087948084}}
{"text": "meta def few_shot_prompt : string := \"Natural language version: \\\"If $z_1, \\\\dots, z_n$ are complex, then $|z_1 + z_2 + \\\\dots + z_n|\\\\leq |z_1| + |z_2| + \\\\dots + |z_n|$.\\\" Translate the natural language version to a Lean mathlib version:\ntheorem abs_sum_leq_sum_abs (n : ℕ) (f : ℕ → ℂ) :\n  abs (∑ i in finset.range n, f i) ≤ ∑ i in finset.range n, abs (f i) :=\n  \nNatural language version: \\\"If x and y are in $\\\\mathbb{R}^n$, then $|x+y|^2 + |x-y|^2 = 2|x|^2 + 2|y|^2$.\\\" Translate the natural language version to a Lean mathlib version: \ntheorem sum_add_square_sub_square_eq_sum_square (n : ℕ) (x y : euclidean_space ℝ (fin n)) :\n  ∥x + y∥^2 + ∥x - y∥^2 = 2*∥x∥^2 + 2*∥y∥^2 :=\n  \nNatural language version: \\\"If $x$ is an element of infinite order in $G$, prove that the elements $x^n$, $n\\\\in\\\\mathbb{Z}$ are all distinct.\\\" Translate the natural language version to a Lean mathlib version:\ntheorem distinct_powers_of_infinite_order_element (G : Type*) [group G] (x : G)\n  (hx : x ≠ 1) (hx_inf : ∀ n : ℕ, x ^ n ≠ 1) :\n  ∀ m n : ℤ, m ≠ n → x ^ m ≠ x ^ n :=\n  \nNatural language version: \\\"Let $X$ be a topological space; let $A$ be a subset of $X$. Suppose that for each $x\\\\in A$ there is an open set $U$ containing $x$ such that $U\\\\subset A$. Show that $A$ is open in $X$.\\\" Translate the natural language version to a Lean mathlib version:\ntheorem subset_of_open_subset_is_open (X : Type*) [topological_space X] \n  (A : set X) (hA : ∀ x ∈ A, ∃ U : set X, is_open U ∧ x ∈ U ∧ U ⊆ A): \n  is_open A :=\"\n\nmeta def prompt_of_nl_statement (nl few_shot_prompt : string):= \nfew_shot_prompt ++ \"\\n\\nNatural language version: \\\"\" ++ nl ++ \"\\\" Translate the natural language version to a Lean mathlib version:\\ntheorem\"\n\nmeta def example_nl := \"Let $a,b\\\\in G$, Show that $ab$ and $ba$ have the same order.\"\n\nmeta def example_prompt := prompt_of_nl_statement example_nl few_shot_prompt\n", "meta": {"author": "zhangir-azerbayev", "repo": "lean-chat", "sha": "cc2832852e1858b879234b0a0f3ac7017df4a195", "save_path": "github-repos/lean/zhangir-azerbayev-lean-chat", "path": "github-repos/lean/zhangir-azerbayev-lean-chat/lean-chat-cc2832852e1858b879234b0a0f3ac7017df4a195/src/prompting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7683462003829015}}
{"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\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\nopen list set\n\nuniverse u\n\nvariables {α β γ : Type*} [dec : decidable_eq α]\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 (α : Type u) : Type u\n| zero : regular_expression\n| epsilon : regular_expression\n| char : α → regular_expression\n| plus : regular_expression → regular_expression → regular_expression\n| comp : regular_expression → regular_expression → regular_expression\n| star : regular_expression → regular_expression\n\nnamespace regular_expression\nvariables {a b : α}\n\ninstance : inhabited (regular_expression α) := ⟨zero⟩\n\ninstance : has_add (regular_expression α) := ⟨plus⟩\ninstance : has_mul (regular_expression α) := ⟨comp⟩\ninstance : has_one (regular_expression α) := ⟨epsilon⟩\ninstance : has_zero (regular_expression α) := ⟨zero⟩\ninstance : has_pow (regular_expression α) ℕ := ⟨λ n r, npow_rec r n⟩\n\nattribute [pattern] has_mul.mul\n\n@[simp] lemma zero_def : (zero : regular_expression α) = 0 := rfl\n@[simp] lemma one_def : (epsilon : regular_expression α) = 1 := rfl\n\n@[simp] lemma plus_def (P Q : regular_expression α) : plus P Q = P + Q := rfl\n@[simp] lemma comp_def (P Q : regular_expression α) : comp P Q = P * Q := rfl\n\n/-- `matches P` provides a language which contains all strings that `P` matches -/\n@[simp] def matches : regular_expression α → language α\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 : (0 : regular_expression α).matches = 0 := rfl\n@[simp] lemma matches_epsilon : (1 : regular_expression α).matches = 1 := rfl\n@[simp] lemma matches_char (a : α) : (char a).matches = {[a]} := rfl\n@[simp] lemma matches_add (P Q : regular_expression α) :\n  (P + Q).matches = P.matches + Q.matches := rfl\n@[simp] lemma matches_mul (P Q : regular_expression α) :\n  (P * Q).matches = P.matches * Q.matches := rfl\n@[simp] lemma matches_pow (P : regular_expression α) :\n  ∀ n : ℕ, (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@[simp] lemma matches_star (P : regular_expression α) : 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 α → 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 α → α → regular_expression α\n| 0 _ := 0\n| 1 _ := 0\n| (char a₁) a₂ := if a₁ = a₂ 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@[simp] lemma deriv_zero (a : α) : deriv 0 a = 0 := rfl\n@[simp] lemma deriv_one (a : α) : deriv 1 a = 0 := rfl\n@[simp] lemma deriv_char_self (a : α) : deriv (char a) a = 1 := if_pos rfl\n@[simp] lemma deriv_char_of_ne (h : a ≠ b) : deriv (char a) b = 0 := if_neg h\n@[simp] lemma deriv_add (P Q : regular_expression α) (a : α) :\n  deriv (P + Q) a = deriv P a + deriv Q a := rfl\n@[simp] lemma deriv_star (P : regular_expression α) (a : α) :\n  deriv (P.star) a = deriv P a * star P := rfl\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 α → list α → bool\n| P [] := match_epsilon P\n| P (a::as) := rmatch (P.deriv a) as\n\n@[simp] lemma zero_rmatch (x : list α) : rmatch 0 x = ff :=\nby induction x; simp [rmatch, match_epsilon, *]\n\n\n\nlemma char_rmatch_iff (a : α) (x : list α) : rmatch (char a) x ↔ 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 α) (x : list α) :\n  (P + Q).rmatch x ↔ P.rmatch x ∨ Q.rmatch x :=\nbegin\n  induction x with _ _ ih generalizing P Q,\n  { simp only [rmatch, match_epsilon, bor_coe_iff] },\n  { repeat {rw rmatch},\n    rw deriv,\n    exact ih _ _ }\nend\n\nlemma mul_rmatch_iff (P Q : regular_expression α) (x : list α) :\n  (P * Q).rmatch x ↔ ∃ t u : list α, x = t ++ u ∧ P.rmatch t ∧ 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 ⟨ [], [], rfl, _ ⟩,\n      rw [rmatch, rmatch],\n      rwa band_coe_iff at h },\n    { rintro ⟨ t, u, h₁, h₂ ⟩,\n      cases list.append_eq_nil.1 h₁.symm with ht hu,\n      subst ht,\n      subst hu,\n      repeat {rw rmatch at h₂},\n      simp [h₂] } },\n  { rw [rmatch, deriv],\n    split_ifs with hepsilon,\n    { rw [add_rmatch_iff, ih],\n      split,\n      { rintro (⟨ t, u, _ ⟩ | h),\n        { exact ⟨ a :: t, u, by tauto ⟩ },\n        { exact ⟨ [], a :: x, rfl, hepsilon, h ⟩ } },\n      { rintro ⟨ t, u, h, hP, hQ ⟩,\n        cases t with b t,\n        { right,\n          rw list.nil_append at h,\n          rw ←h at hQ,\n          exact hQ },\n        { left,\n          simp only [list.cons_append] at h,\n          refine ⟨ t, u, h.2, _, hQ ⟩,\n          rw rmatch at hP,\n          convert hP,\n          exact h.1 } } },\n    { rw ih,\n      split;\n      rintro ⟨ t, u, h, hP, hQ ⟩,\n      { exact ⟨ a :: t, u, by tauto ⟩ },\n      { cases t with b t,\n        { contradiction },\n        { simp only [list.cons_append] at h,\n          refine ⟨ t, u, h.2, _, hQ ⟩,\n          rw rmatch at hP,\n          convert hP,\n          exact h.1 } } } }\nend\n\nlemma star_rmatch_iff (P : regular_expression α) : ∀ (x : list α),\n  (star P).rmatch x ↔ ∃ S : list (list α), x = S.join ∧ ∀ t ∈ S, t ≠ [] ∧ P.rmatch t\n| x :=\nbegin\n  have A : ∀ (m n : ℕ), 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 := λ 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 ⟨ t, u, hs, ht, hu ⟩,\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 ⟨ S', hsum, helem ⟩,\n      use (a :: t) :: S',\n      split,\n      { simp [hs, hsum] },\n      { intros t' ht',\n        cases ht' with ht' ht',\n        { rw ht',\n          exact ⟨ dec_trivial, ht ⟩ },\n        { exact helem _ ht' } } } },\n  { rintro ⟨ S, hsum, helem ⟩,\n    cases x with a x,\n    { dec_trivial },\n    { rw [rmatch, deriv, mul_rmatch_iff],\n      cases S with t' U,\n      { exact ⟨ [], [], by tauto ⟩ },\n      { cases t' with b t,\n        { simp only [forall_eq_or_imp, list.mem_cons_iff] at helem,\n          simp only [eq_self_iff_true, not_true, ne.def, false_and] at helem,\n          cases helem },\n        simp only [list.join, list.cons_append] at hsum,\n        refine ⟨ t, U.join, hsum.2, _, _ ⟩,\n        { specialize helem (b :: t) (by simp),\n          rw rmatch at helem,\n          convert helem.2,\n          exact hsum.1 },\n        { have hwf : U.join.length < (list.cons a x).length,\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 ⟨ U, rfl, λ t h, helem t _ ⟩,\n          right,\n          assumption } } } }\nend\nusing_well_founded\n{ rel_tac := λ _ _, `[exact ⟨(λ L₁ L₂ : list _, L₁.length < L₂.length), inv_image.wf _ nat.lt_wf⟩] }\n\n@[simp] lemma rmatch_iff_matches (P : regular_expression α) :\n  ∀ x : list α, P.rmatch x ↔ x ∈ 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₁ ih₂\n  { rw [add_rmatch_iff, ih₁, ih₂],\n    refl },\n  case comp : P Q ih₁ ih₂\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 ⟨ x, y, hsum, hmatch₁, hmatch₂ ⟩,\n      rw ih₁ at hmatch₁,\n      rw ih₂ at hmatch₂,\n      exact ⟨ x, hmatch₁, y, hmatch₂, hsum.symm ⟩ },\n    { rintro ⟨ x, hmatch₁, y, hmatch₂, hsum ⟩,\n      rw ←ih₁ at hmatch₁,\n      rw ←ih₂ at hmatch₂,\n      exact ⟨ x, y, hsum.symm, hmatch₁, hmatch₂ ⟩ } },\n  case star : _ ih\n  { rw [star_rmatch_iff, language.star_def_nonempty],\n    split,\n    all_goals\n    { rintro ⟨ S, hx, hS ⟩,\n      refine ⟨ S, hx, _ ⟩,\n      intro y,\n      specialize hS y },\n    { rw ←ih y,\n      tauto },\n    { rw ih y,\n      tauto } }\nend\n\ninstance (P : regular_expression α) : decidable_pred P.matches :=\nbegin\n  intro x,\n  change decidable (x ∈ P.matches),\n  rw ←rmatch_iff_matches,\n  exact eq.decidable _ _\nend\n\nomit dec\n\n/-- Map the alphabet of a regular expression. -/\n@[simp] def map (f : α → β) : regular_expression α → regular_expression β\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\n@[simp] protected lemma map_pow (f : α → β) (P : regular_expression α) :\n  ∀ n : ℕ, map f (P ^ n) = map f P ^ n\n| 0 := rfl\n| (n + 1) := (congr_arg ((*) (map f P)) (map_pow n) : _)\n\n@[simp] lemma map_id : ∀ (P : regular_expression α), 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\n@[simp] lemma map_map (g : β → γ) (f : α → β) :\n  ∀ (P : regular_expression α), (P.map f).map g = P.map (g ∘ 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\n/-- The language of the map is the map of the language. -/\n@[simp] lemma matches_map (f : α → β) :\n  ∀ P : regular_expression α, (P.map f).matches = language.map f P.matches\n| 0 := (map_zero _).symm\n| 1 := (map_one _).symm\n| (char a) := by { rw eq_comm, 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) := begin\n    simp_rw [map, matches, matches_map],\n    rw [language.star_eq_supr_pow, language.star_eq_supr_pow],\n    simp_rw ←map_pow,\n    exact image_Union.symm,\n  end\n\nend regular_expression\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/regular_expressions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7683461930226391}}
{"text": "import tactic\nimport data.set.finite\nimport data.real.basic\n\nimport topological_spaces\nimport neighbourhoods\nimport topological_spaces2\nimport t2_spaces\n\nnoncomputable theory\nopen set\n\n-- Definition d'un espace métrique :\nclass metric_space (X : Type) :=\n  (dist : X → X → ℝ)\n  (dist_eq_zero_iff : ∀ x y, dist x y = 0 ↔ x = y)\n  (dist_symm : ∀ x y, dist x y = dist y x)\n  (triangle : ∀ x y z, dist x z ≤ dist x y + dist y z)\n\nnamespace metric_space\nopen topological_space\n\n-- Preuve que la distance est positive à partir des autres axiomes :\nlemma dist_nonneg {X : Type} [metric_space X] (x y : X) : 0 ≤ dist x y :=\nbegin\n  have :=\n  calc 0 = dist x x : by rw (dist_eq_zero_iff x x).2 rfl\n     ... ≤ dist x y + dist y x : triangle x y x\n     ... = dist x y + dist x y : by rw dist_symm x y\n     ... = 2 * dist x y : by linarith,\n  linarith,\nend\n\n-- Topologie induite par la distance :\ninstance {X : Type} [metric_space X] : topological_space X :=\ngenerate_from X { B | ∃ (x : X) r, B = {y | dist x y < r} }\n\n-- Caractérisation des ouverts pour la distance :\nlemma is_open_metric_iff {X : Type} [metric_space X] {U : set X}:\nis_open U ↔ ∀ x ∈ U, ∃ r > 0, {y | dist x y < r} ⊆ U :=\nbegin\n  split,\n  { intro hyp,\n    intros x hx,\n    induction hyp with G hG A B hA1 hB1 hA2 hB2 C hC1 hC2,\n    { rcases hG with ⟨xG, r, hG⟩,\n      rw hG at hx, simp at hx,\n      use [r - dist xG x, by linarith [hx]],\n      intros y hy, simp at hy,\n      rw hG,\n      calc dist xG y ≤ dist xG x + dist x y      : triangle xG x y\n                 ... < dist xG x + r - dist xG x : by linarith [hy]\n                 ... = r                         : by linarith, },\n    { rcases hA2 hx.1 with ⟨r1, hr1, hA⟩,\n      rcases hB2 hx.2 with ⟨r2, hr2, hB⟩,\n      use min r1 r2, split,\n      exact lt_min hr1 hr2,\n      intros y hy, split,\n      apply hA,\n      calc dist x y < min r1 r2 : hy\n                ... ≤ r1        : min_le_left r1 r2,\n      apply hB,\n      calc dist x y < min r1 r2 : hy\n                ... ≤ r2        : min_le_right r1 r2, },\n    { rcases hx with ⟨c, hcC, hxc⟩,\n      rcases hC2 c hcC hxc with ⟨r, hr, hc⟩,\n      use [r, hr],\n      intros y hy,\n      use [c, hcC, hc hy], },\n    { use [1, by linarith], simp, }, },\n  { intro hyp,\n    choose φ hφ using hyp,\n    have clef : U = ⋃₀ { ({y : X | dist x y < φ x H}) | (x : X) (H : x ∈ U) },\n    { apply le_antisymm,\n      { intros x hx,\n        use {y : X | dist x y < φ x hx}, split,\n        use [x, hx],\n        specialize hφ x hx, rw exists_prop at hφ,\n        calc dist x x = 0      : (dist_eq_zero_iff x x).2 rfl\n                  ... < φ x hx : by linarith [hφ.1], },\n      { apply sUnion_subset,\n        rintros B ⟨x, hx, hB⟩,\n        rw ← hB,\n        specialize hφ x hx, rw exists_prop at hφ,\n        exact hφ.2, }, },\n    rw clef,\n    apply union,\n    rintros B ⟨x, hx, hB⟩,\n    rw ← hB,\n    apply generated_open.generator,\n    use [x, φ x hx], },\nend\n\nend metric_space\n\nopen topological_space\nopen metric_space\n\n-- Espace métrique ℝ :\ninstance metric_space_R : metric_space ℝ :=\n{ dist := λ x y,  abs (x - y),\n  dist_eq_zero_iff :=\n  begin\n    intros x y,\n    split,\n    intro hyp,\n    linarith [abs_eq_zero.1 hyp],\n    intro hyp,\n    simp [hyp],\n  end,\n  dist_symm := abs_sub,\n  triangle :=\n  begin\n    intros x y z,\n    have clef : x - z = (x - y) + (y - z), linarith,\n    calc abs (x - z) = abs ((x - y) + (y - z))   : by simp [clef]\n                 ... ≤ abs (x - y) + abs (y - z) : abs_add _ _,\n  end }\n\n\n-- Produit de deux espaces métriques :\ninstance prod.metric_space (X Y : Type) [metric_space X] [metric_space Y] :\nmetric_space (X × Y) :=\n{ dist := λ u v, max (dist u.fst v.fst) (dist u.snd v.snd),\n  dist_eq_zero_iff :=\n  begin\n    intros u v,\n    split,\n    { intro hyp,\n      have := dist_nonneg u.fst v.fst,\n      have := dist_nonneg u.snd v.snd,\n      have := max_le_iff.1 (le_of_eq hyp),\n      ext; rw ← dist_eq_zero_iff; linarith, },\n    { intro hyp,\n      rw [hyp, (dist_eq_zero_iff _ _).mpr, (dist_eq_zero_iff _ _).mpr, max_self]; refl },\n  end,\n  dist_symm :=\n  begin\n    intros u v,\n    rw [dist_symm u.fst v.fst, dist_symm u.snd v.snd],\n  end,\n  triangle :=\n  begin\n    intros u v w,\n    have := triangle u.fst v.fst w.fst,\n    have := triangle u.snd v.snd w.snd,\n    unfold max, split_ifs;\n    linarith,\n  end\n  }\n\n-- Tout espace métrique est séparé :\ninstance metric_t2 {X : Type} [metric_space X] : t2_space X :=\n{ t2 :=\nbegin\n  intros x y hxy,\n  let r := dist x y,\n  have r_strict_pos : r > 0,\n  { cases le_or_gt r 0 with h1 h2,\n    exfalso, exact hxy ((dist_eq_zero_iff x y).1 (le_antisymm h1 (dist_nonneg x y))),\n    exact h2, },\n  let Ux := {z : X | dist x z < r/2},\n  let Uy := {z : X | dist y z < r/2},\n  use [Ux, Uy],\n  repeat {split},\n  apply generated_open.generator, use [x, r/2],\n  apply generated_open.generator, use [y, r/2],\n  calc dist x x = 0   : (dist_eq_zero_iff x x).2 rfl\n            ... < r/2 : by linarith,\n  calc dist y y = 0   : (dist_eq_zero_iff y y).2 rfl\n            ... < r/2 : by linarith,\n  apply le_antisymm,\n  { rintros z ⟨ hzUx, hzUy ⟩,\n    have hxz : dist x z < r/2, exact hzUx,\n    have hyz : dist y z < r/2, exact hzUy,\n    have :=\n    calc dist x y ≤ dist x z + dist z y : triangle x z y\n              ... = dist x z + dist y z : by linarith [dist_symm y z]\n              ... < r/2 + r/2           : by linarith [hxz, hyz]\n              ... = r                   : by linarith,\n    linarith, },\n  { intros x hx, exfalso, exact hx, },\nend }\n\n-- Convergence d'une suite dans un espace métrique :\nlemma seq_lim_metric {X : Type} [metric_space X] (u : ℕ → X) (l : X) :\nseq_lim u l ↔ ∀ ε > 0, ∃ (N : ℕ), ∀ n ≥ N, dist (u n) l < ε :=\nbegin\n  split,\n  { intro hyp,\n    intros ε εpos,\n    let V := { x | dist l x < ε },\n    have hV : V ∈ neighbourhoods l,\n    { apply generated_filter.generator, split,\n      apply generated_open.generator,\n      use [l, ε],\n      calc dist l l = 0 : (dist_eq_zero_iff l l).2 rfl\n                ... < ε : by linarith [εpos], },\n    cases hyp V hV with N hN,\n    use N,\n    intros n hn,\n    calc dist (u n) l = dist l (u n) : dist_symm (u n) l\n                  ... < ε            : hN n hn, },\n  { intro hyp,\n    intros V hV,\n    rcases (is_neighbourhood_iff l).1 hV with ⟨U, hU, hlU, hUV⟩,\n    rcases is_open_metric_iff.1 hU l hlU with ⟨ε, εpos, H⟩,\n    cases hyp ε εpos with N hN,\n    use N,\n    intros n hn,\n    apply hUV,\n    apply H,\n    calc dist l (u n) = dist (u n) l : dist_symm l (u n)\n                  ... < ε            : hN n hn, },\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/metric_spaces.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7683461928920653}}
{"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 1ead22342e1a078bd44744ace999f85756555d35\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.Card\nimport Mathbin.GroupTheory.Finiteness\nimport Mathbin.GroupTheory.GroupAction.Quotient\n\n/-!\n# Index of a Subgroup\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 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 ∣ fintype.card G`\n- `index_eq_mul_of_le` : If `H ≤ K`, then `H.index = K.index * (H.subgroup_of K).index`\n- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ 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#print Subgroup.index /-\n/-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/\n@[to_additive\n      \"The index of a subgroup as a natural number,\\nand returns 0 if the index is infinite.\"]\nnoncomputable def index : ℕ :=\n  Nat.card (G ⧸ H)\n#align subgroup.index Subgroup.index\n#align add_subgroup.index AddSubgroup.index\n-/\n\n#print Subgroup.relindex /-\n/-- The relative index of a subgroup as a natural number,\n  and returns 0 if the relative index is infinite. -/\n@[to_additive\n      \"The relative index of a subgroup as a natural number,\\n  and returns 0 if the relative index is infinite.\"]\nnoncomputable def relindex : ℕ :=\n  (H.subgroupOf K).index\n#align subgroup.relindex Subgroup.relindex\n#align add_subgroup.relindex AddSubgroup.relindex\n-/\n\n/- warning: subgroup.index_comap_of_surjective -> Subgroup.index_comap_of_surjective is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))}, (Function.Surjective.{succ u2, succ u1} G' G (coeFn.{max (succ u1) (succ u2), max (succ u2) (succ u1)} (MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (fun (_x : MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) => G' -> G) (MonoidHom.hasCoeToFun.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) f)) -> (Eq.{1} Nat (Subgroup.index.{u2} G' _inst_2 (Subgroup.comap.{u2, u1} G' _inst_2 G _inst_1 f H)) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))}, (Function.Surjective.{succ u2, succ u1} G' G (FunLike.coe.{max (succ u1) (succ u2), succ u2, succ u1} (MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) G' (fun (_x : G') => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G') => G) _x) (MulHomClass.toFunLike.{max u1 u2, u2, u1} (MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) G' G (MulOneClass.toMul.{u2} G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (MonoidHomClass.toMulHomClass.{max u1 u2, u2, u1} (MonoidHom.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (MonoidHom.monoidHomClass.{u2, u1} G' G (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))))) f)) -> (Eq.{1} Nat (Subgroup.index.{u2} G' _inst_2 (Subgroup.comap.{u2, u1} G' _inst_2 G _inst_1 f H)) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_comap_of_surjective Subgroup.index_comap_of_surjectiveₓ'. -/\n@[to_additive]\ntheorem index_comap_of_surjective {G' : Type _} [Group G'] {f : G' →* G}\n    (hf : Function.Surjective f) : (H.comap f).index = H.index :=\n  by\n  letI := QuotientGroup.leftRel H\n  letI := QuotientGroup.leftRel (H.comap f)\n  have key : ∀ x y : G', Setoid.r x y ↔ Setoid.r (f x) (f y) :=\n    by\n    simp only [QuotientGroup.leftRel_apply]\n    exact fun x y => iff_of_eq (congr_arg (· ∈ 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) ⟨_, _⟩)\n  · simp_rw [← Quotient.eq''] at key\n    refine' Quotient.ind' fun x => _\n    refine' Quotient.ind' fun y => _\n    exact (key x y).mpr\n  · refine' Quotient.ind' fun x => _\n    obtain ⟨y, hy⟩ := hf x\n    exact ⟨y, (Quotient.map'_mk'' f _ y).trans (congr_arg Quotient.mk'' hy)⟩\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#print Subgroup.index_comap /-\n@[to_additive]\ntheorem index_comap {G' : Type _} [Group G'] (f : G' →* 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\n#print Subgroup.relindex_comap /-\n@[to_additive]\ntheorem relindex_comap {G' : Type _} [Group G'] (f : G' →* G) (K : Subgroup G') :\n    relindex (comap f H) K = relindex H (map f K) := by\n  rw [relindex, subgroup_of, comap_comap, index_comap, ← f.map_range, K.subtype_range]\n#align subgroup.relindex_comap Subgroup.relindex_comap\n#align add_subgroup.relindex_comap AddSubgroup.relindex_comap\n-/\n\nvariable {H K L}\n\n/- warning: subgroup.relindex_mul_index -> Subgroup.relindex_mul_index is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.index.{u1} G _inst_1 K)) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.index.{u1} G _inst_1 K)) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_mul_index Subgroup.relindex_mul_indexₓ'. -/\n@[to_additive relindex_mul_index]\ntheorem relindex_mul_index (h : H ≤ 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/- warning: subgroup.index_dvd_of_le -> Subgroup.index_dvd_of_le is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Subgroup.index.{u1} G _inst_1 K) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Subgroup.index.{u1} G _inst_1 K) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_dvd_of_le Subgroup.index_dvd_of_leₓ'. -/\n@[to_additive]\ntheorem index_dvd_of_le (h : H ≤ K) : K.index ∣ 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/- warning: subgroup.relindex_dvd_index_of_le -> Subgroup.relindex_dvd_index_of_le is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_dvd_index_of_le Subgroup.relindex_dvd_index_of_leₓ'. -/\n@[to_additive]\ntheorem relindex_dvd_index_of_le (h : H ≤ K) : H.relindex K ∣ 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/- warning: subgroup.relindex_subgroup_of -> Subgroup.relindex_subgroupOf is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) K L) -> (Eq.{1} Nat (Subgroup.relindex.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) L) (Subgroup.toGroup.{u1} G _inst_1 L) (Subgroup.subgroupOf.{u1} G _inst_1 H L) (Subgroup.subgroupOf.{u1} G _inst_1 K L)) (Subgroup.relindex.{u1} G _inst_1 H K))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) K L) -> (Eq.{1} Nat (Subgroup.relindex.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x L)) (Subgroup.toGroup.{u1} G _inst_1 L) (Subgroup.subgroupOf.{u1} G _inst_1 H L) (Subgroup.subgroupOf.{u1} G _inst_1 K L)) (Subgroup.relindex.{u1} G _inst_1 H K))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_subgroup_of Subgroup.relindex_subgroupOfₓ'. -/\n@[to_additive]\ntheorem relindex_subgroupOf (hKL : K ≤ 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/- warning: subgroup.relindex_mul_relindex -> Subgroup.relindex_mul_relindex is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) (L : Subgroup.{u1} G _inst_1), (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) K L) -> (Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.relindex.{u1} G _inst_1 K L)) (Subgroup.relindex.{u1} G _inst_1 H L))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) (L : Subgroup.{u1} G _inst_1), (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) K L) -> (Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.relindex.{u1} G _inst_1 K L)) (Subgroup.relindex.{u1} G _inst_1 H L))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_mul_relindex Subgroup.relindex_mul_relindexₓ'. -/\n@[to_additive relindex_mul_relindex]\ntheorem relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) :\n    H.relindex K * K.relindex L = H.relindex L :=\n  by\n  rw [← relindex_subgroup_of 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/- warning: subgroup.inf_relindex_right -> Subgroup.inf_relindex_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K) K) (Subgroup.relindex.{u1} G _inst_1 H K)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K) K) (Subgroup.relindex.{u1} G _inst_1 H K)\nCase conversion may be inaccurate. Consider using '#align subgroup.inf_relindex_right Subgroup.inf_relindex_rightₓ'. -/\n@[to_additive]\ntheorem inf_relindex_right : (H ⊓ K).relindex K = H.relindex K := by\n  rw [relindex, relindex, inf_subgroup_of_right]\n#align subgroup.inf_relindex_right Subgroup.inf_relindex_right\n#align add_subgroup.inf_relindex_right AddSubgroup.inf_relindex_right\n\n/- warning: subgroup.inf_relindex_left -> Subgroup.inf_relindex_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K) H) (Subgroup.relindex.{u1} G _inst_1 K H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K) H) (Subgroup.relindex.{u1} G _inst_1 K H)\nCase conversion may be inaccurate. Consider using '#align subgroup.inf_relindex_left Subgroup.inf_relindex_leftₓ'. -/\n@[to_additive]\ntheorem inf_relindex_left : (H ⊓ 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/- warning: subgroup.relindex_inf_mul_relindex -> Subgroup.relindex_inf_mul_relindex is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) (L : Subgroup.{u1} G _inst_1), Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.relindex.{u1} G _inst_1 H (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) K L)) (Subgroup.relindex.{u1} G _inst_1 K L)) (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K) L)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) (L : Subgroup.{u1} G _inst_1), Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.relindex.{u1} G _inst_1 H (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) K L)) (Subgroup.relindex.{u1} G _inst_1 K L)) (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K) L)\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_inf_mul_relindex Subgroup.relindex_inf_mul_relindexₓ'. -/\n@[to_additive relindex_inf_mul_relindex]\ntheorem relindex_inf_mul_relindex : H.relindex (K ⊓ L) * K.relindex L = (H ⊓ K).relindex L := by\n  rw [← inf_relindex_right H (K ⊓ L), ← inf_relindex_right K L, ← inf_relindex_right (H ⊓ K) L,\n    inf_assoc, relindex_mul_relindex (H ⊓ (K ⊓ L)) (K ⊓ 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/- warning: subgroup.relindex_sup_right -> Subgroup.relindex_sup_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) [_inst_2 : Subgroup.Normal.{u1} G _inst_1 K], Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K (Sup.sup.{u1} (Subgroup.{u1} G _inst_1) (SemilatticeSup.toHasSup.{u1} (Subgroup.{u1} G _inst_1) (Lattice.toSemilatticeSup.{u1} (Subgroup.{u1} G _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.completeLattice.{u1} G _inst_1))))) H K)) (Subgroup.relindex.{u1} G _inst_1 K H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) [_inst_2 : Subgroup.Normal.{u1} G _inst_1 K], Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K (Sup.sup.{u1} (Subgroup.{u1} G _inst_1) (SemilatticeSup.toSup.{u1} (Subgroup.{u1} G _inst_1) (Lattice.toSemilatticeSup.{u1} (Subgroup.{u1} G _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K)) (Subgroup.relindex.{u1} G _inst_1 K H)\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_sup_right Subgroup.relindex_sup_rightₓ'. -/\n@[simp, to_additive]\ntheorem relindex_sup_right [K.Normal] : K.relindex (H ⊔ 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/- warning: subgroup.relindex_sup_left -> Subgroup.relindex_sup_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) [_inst_2 : Subgroup.Normal.{u1} G _inst_1 K], Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K (Sup.sup.{u1} (Subgroup.{u1} G _inst_1) (SemilatticeSup.toHasSup.{u1} (Subgroup.{u1} G _inst_1) (Lattice.toSemilatticeSup.{u1} (Subgroup.{u1} G _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.completeLattice.{u1} G _inst_1))))) K H)) (Subgroup.relindex.{u1} G _inst_1 K H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1) [_inst_2 : Subgroup.Normal.{u1} G _inst_1 K], Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K (Sup.sup.{u1} (Subgroup.{u1} G _inst_1) (SemilatticeSup.toSup.{u1} (Subgroup.{u1} G _inst_1) (Lattice.toSemilatticeSup.{u1} (Subgroup.{u1} G _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) K H)) (Subgroup.relindex.{u1} G _inst_1 K H)\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_sup_left Subgroup.relindex_sup_leftₓ'. -/\n@[simp, to_additive]\ntheorem relindex_sup_left [K.Normal] : K.relindex (K ⊔ 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#print Subgroup.relindex_dvd_index_of_normal /-\n@[to_additive]\ntheorem relindex_dvd_index_of_normal [H.Normal] : H.relindex K ∣ H.index :=\n  relindex_sup_right K H ▸ 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-/\n\nvariable {H K}\n\n/- warning: subgroup.relindex_dvd_of_le_left -> Subgroup.relindex_dvd_of_le_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} (L : Subgroup.{u1} G _inst_1), (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Subgroup.relindex.{u1} G _inst_1 K L) (Subgroup.relindex.{u1} G _inst_1 H L))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} (L : Subgroup.{u1} G _inst_1), (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Subgroup.relindex.{u1} G _inst_1 K L) (Subgroup.relindex.{u1} G _inst_1 H L))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_dvd_of_le_left Subgroup.relindex_dvd_of_le_leftₓ'. -/\n@[to_additive]\ntheorem relindex_dvd_of_le_left (hHK : H ≤ K) : K.relindex L ∣ H.relindex L :=\n  inf_of_le_left hHK ▸ 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/- warning: subgroup.index_eq_two_iff -> Subgroup.index_eq_two_iff is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) (Exists.{succ u1} G (fun (a : G) => forall (b : G), Xor' (Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{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))))) b a) H) (Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) b H)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) (Exists.{succ u1} G (fun (a : G) => forall (b : G), Xor' (Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{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))))) b a) H) (Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) b H)))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_eq_two_iff Subgroup.index_eq_two_iffₓ'. -/\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\n      \"/-- An additive subgroup has index two if and only if there exists `a` such that for\\nall `b`, exactly one of `b + a` and `b` belong to `H`. -/\"]\ntheorem index_eq_two_iff : H.index = 2 ↔ ∃ a, ∀ b, Xor' (b * a ∈ H) (b ∈ H) :=\n  by\n  simp only [index, Nat.card_eq_two_iff' ((1 : G) : G ⧸ 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 => ⟨fun ha b => ⟨fun hba hb => _, fun hb => _⟩, fun ha => ⟨_, fun b hb => _⟩⟩\n  · exact ha.1 ((mul_mem_cancel_left hb).1 hba)\n  · exact inv_inv b ▸ ha.2 _ (mt inv_mem_iff.1 hb)\n  · rw [← inv_mem_iff, ← ha, inv_mul_self]\n    exact one_mem _\n  · rwa [ha, inv_mem_iff]\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/- warning: subgroup.mul_mem_iff_of_index_two -> Subgroup.mul_mem_iff_of_index_two is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) -> (forall {a : G} {b : G}, Iff (Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{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) H) (Iff (Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) a H) (Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) b H)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) -> (forall {a : G} {b : G}, Iff (Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{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) H) (Iff (Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) a H) (Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) b H)))\nCase conversion may be inaccurate. Consider using '#align subgroup.mul_mem_iff_of_index_two Subgroup.mul_mem_iff_of_index_twoₓ'. -/\n@[to_additive]\ntheorem mul_mem_iff_of_index_two (h : H.index = 2) {a b : G} : a * b ∈ H ↔ (a ∈ H ↔ b ∈ H) :=\n  by\n  by_cases ha : a ∈ H; · simp only [ha, true_iff_iff, mul_mem_cancel_left ha]\n  by_cases hb : b ∈ H; · 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 ⟨c, hc⟩\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/- warning: subgroup.mul_self_mem_of_index_two -> Subgroup.mul_self_mem_of_index_two is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) -> (forall (a : G), Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{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 a) H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) -> (forall (a : G), Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{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 a) H)\nCase conversion may be inaccurate. Consider using '#align subgroup.mul_self_mem_of_index_two Subgroup.mul_self_mem_of_index_twoₓ'. -/\n@[to_additive]\ntheorem mul_self_mem_of_index_two (h : H.index = 2) (a : G) : a * a ∈ 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/- warning: subgroup.sq_mem_of_index_two -> Subgroup.sq_mem_of_index_two is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) -> (forall (a : G), Membership.Mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.hasMem.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) (HPow.hPow.{u1, 0, u1} G Nat G (instHPow.{u1, 0} G Nat (Monoid.Pow.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne))))) H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) -> (forall (a : G), Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) (HPow.hPow.{u1, 0, u1} G Nat G (instHPow.{u1, 0} G Nat (Monoid.Pow.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) a (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2))) H)\nCase conversion may be inaccurate. Consider using '#align subgroup.sq_mem_of_index_two Subgroup.sq_mem_of_index_twoₓ'. -/\n@[to_additive two_smul_mem_of_index_two]\ntheorem sq_mem_of_index_two (h : H.index = 2) (a : G) : a ^ 2 ∈ H :=\n  (pow_two a).symm ▸ 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/- warning: subgroup.index_top -> Subgroup.index_top is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G], Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasTop.{u1} G _inst_1))) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G], Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instTopSubgroup.{u1} G _inst_1))) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_top Subgroup.index_topₓ'. -/\n@[simp, to_additive]\ntheorem index_top : (⊤ : Subgroup G).index = 1 :=\n  Cardinal.toNat_eq_one_iff_unique.mpr ⟨QuotientGroup.subsingleton_quotient_top, ⟨1⟩⟩\n#align subgroup.index_top Subgroup.index_top\n#align add_subgroup.index_top AddSubgroup.index_top\n\n/- warning: subgroup.index_bot -> Subgroup.index_bot is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G], Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasBot.{u1} G _inst_1))) (Nat.card.{u1} G)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G], Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instBotSubgroup.{u1} G _inst_1))) (Nat.card.{u1} G)\nCase conversion may be inaccurate. Consider using '#align subgroup.index_bot Subgroup.index_botₓ'. -/\n@[simp, to_additive]\ntheorem index_bot : (⊥ : 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/- warning: subgroup.index_bot_eq_card -> Subgroup.index_bot_eq_card is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] [_inst_2 : Fintype.{u1} G], Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasBot.{u1} G _inst_1))) (Fintype.card.{u1} G _inst_2)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] [_inst_2 : Fintype.{u1} G], Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instBotSubgroup.{u1} G _inst_1))) (Fintype.card.{u1} G _inst_2)\nCase conversion may be inaccurate. Consider using '#align subgroup.index_bot_eq_card Subgroup.index_bot_eq_cardₓ'. -/\n@[to_additive]\ntheorem index_bot_eq_card [Fintype G] : (⊥ : 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/- warning: subgroup.relindex_top_left -> Subgroup.relindex_top_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasTop.{u1} G _inst_1)) H) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instTopSubgroup.{u1} G _inst_1)) H) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_top_left Subgroup.relindex_top_leftₓ'. -/\n@[simp, to_additive]\ntheorem relindex_top_left : (⊤ : 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/- warning: subgroup.relindex_top_right -> Subgroup.relindex_top_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasTop.{u1} G _inst_1))) (Subgroup.index.{u1} G _inst_1 H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instTopSubgroup.{u1} G _inst_1))) (Subgroup.index.{u1} G _inst_1 H)\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_top_right Subgroup.relindex_top_rightₓ'. -/\n@[simp, to_additive]\ntheorem relindex_top_right : H.relindex ⊤ = H.index := by\n  rw [← relindex_mul_index (show H ≤ ⊤ 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/- warning: subgroup.relindex_bot_left -> Subgroup.relindex_bot_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasBot.{u1} G _inst_1)) H) (Nat.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instBotSubgroup.{u1} G _inst_1)) H) (Nat.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H)))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_bot_left Subgroup.relindex_bot_leftₓ'. -/\n@[simp, to_additive]\ntheorem relindex_bot_left : (⊥ : Subgroup G).relindex H = Nat.card H := by\n  rw [relindex, bot_subgroup_of, 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/- warning: subgroup.relindex_bot_left_eq_card -> Subgroup.relindex_bot_left_eq_card is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) [_inst_2 : Fintype.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H)], Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasBot.{u1} G _inst_1)) H) (Fintype.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H) _inst_2)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) [_inst_2 : Fintype.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H))], Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instBotSubgroup.{u1} G _inst_1)) H) (Fintype.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H)) _inst_2)\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_bot_left_eq_card Subgroup.relindex_bot_left_eq_cardₓ'. -/\n@[to_additive]\ntheorem relindex_bot_left_eq_card [Fintype H] : (⊥ : 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/- warning: subgroup.relindex_bot_right -> Subgroup.relindex_bot_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasBot.{u1} G _inst_1))) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instBotSubgroup.{u1} G _inst_1))) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_bot_right Subgroup.relindex_bot_rightₓ'. -/\n@[simp, to_additive]\ntheorem relindex_bot_right : H.relindex ⊥ = 1 := by rw [relindex, subgroup_of_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#print Subgroup.relindex_self /-\n@[simp, to_additive]\ntheorem relindex_self : H.relindex H = 1 := by rw [relindex, subgroup_of_self, index_top]\n#align subgroup.relindex_self Subgroup.relindex_self\n#align add_subgroup.relindex_self AddSubgroup.relindex_self\n-/\n\n/- warning: subgroup.index_ker -> Subgroup.index_ker is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Type.{u2}} [_inst_2 : Group.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))), Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (MonoidHom.ker.{u1, u2} G _inst_1 H (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2))) f)) (Nat.card.{u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} H) Type.{u2} (Set.hasCoeToSort.{u2} H) (Set.range.{u2, succ u1} H G (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) (fun (_x : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) => G -> H) (MonoidHom.hasCoeToFun.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) f))))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Type.{u2}} [_inst_2 : Group.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))), Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 (MonoidHom.ker.{u1, u2} G _inst_1 H (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2))) f)) (Nat.card.{u2} (Set.Elem.{u2} H (Set.range.{u2, succ u1} H G (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => H) _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) G H (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (MulOneClass.toMul.{u2} H (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) (MonoidHomClass.toMulHomClass.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2))) (MonoidHom.monoidHomClass.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))))) f))))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_ker Subgroup.index_kerₓ'. -/\n@[to_additive]\ntheorem index_ker {H} [Group H] (f : G →* H) : f.ker.index = Nat.card (Set.range f) :=\n  by\n  rw [← 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/- warning: subgroup.relindex_ker -> Subgroup.relindex_ker is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Type.{u2}} [_inst_2 : Group.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) (K : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (MonoidHom.ker.{u1, u2} G _inst_1 H (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2))) f) K) (Nat.card.{u2} (coeSort.{succ u2, succ (succ u2)} (Set.{u2} H) Type.{u2} (Set.hasCoeToSort.{u2} H) (Set.image.{u1, u2} G H (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) (fun (_x : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) => G -> H) (MonoidHom.hasCoeToFun.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) f) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) (Subgroup.{u1} G _inst_1) (Set.{u1} G) (HasLiftT.mk.{succ u1, succ u1} (Subgroup.{u1} G _inst_1) (Set.{u1} G) (CoeTCₓ.coe.{succ u1, succ u1} (Subgroup.{u1} G _inst_1) (Set.{u1} G) (SetLike.Set.hasCoeT.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) K))))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Type.{u2}} [_inst_2 : Group.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) (K : Subgroup.{u1} G _inst_1), Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (MonoidHom.ker.{u1, u2} G _inst_1 H (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2))) f) K) (Nat.card.{u2} (Set.Elem.{u2} H (Set.image.{u1, u2} G H (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => H) _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) G H (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (MulOneClass.toMul.{u2} H (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) (MonoidHomClass.toMulHomClass.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))) G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2))) (MonoidHom.monoidHomClass.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_2)))))) f) (SetLike.coe.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1) K))))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_ker Subgroup.relindex_kerₓ'. -/\n@[to_additive]\ntheorem relindex_ker {H} [Group H] (f : G →* H) (K : Subgroup G) :\n    f.ker.relindex K = Nat.card (f '' K) :=\n  by\n  rw [← 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/- warning: subgroup.card_mul_index -> Subgroup.card_mul_index is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Nat.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H)) (Subgroup.index.{u1} G _inst_1 H)) (Nat.card.{u1} G)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1), Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Nat.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H))) (Subgroup.index.{u1} G _inst_1 H)) (Nat.card.{u1} G)\nCase conversion may be inaccurate. Consider using '#align subgroup.card_mul_index Subgroup.card_mul_indexₓ'. -/\n@[simp, to_additive card_mul_index]\ntheorem card_mul_index : Nat.card H * H.index = Nat.card G :=\n  by\n  rw [← relindex_bot_left, ← 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/- warning: subgroup.nat_card_dvd_of_injective -> Subgroup.nat_card_dvd_of_injective is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} {H : Type.{u2}} [_inst_2 : Group.{u1} G] [_inst_3 : Group.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))), (Function.Injective.{succ u1, succ u2} G H (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) (fun (_x : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) => G -> H) (MonoidHom.hasCoeToFun.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) f)) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Nat.card.{u1} G) (Nat.card.{u2} H))\nbut is expected to have type\n  forall {G : Type.{u2}} {H : Type.{u1}} [_inst_2 : Group.{u2} G] [_inst_3 : Group.{u1} H] (f : MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))), (Function.Injective.{succ u2, succ u1} G H (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => H) _x) (MulHomClass.toFunLike.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G H (MulOneClass.toMul.{u2} G (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2)))) (MulOneClass.toMul.{u1} H (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) (MonoidHomClass.toMulHomClass.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3))) (MonoidHom.monoidHomClass.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))))) f)) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Nat.card.{u2} G) (Nat.card.{u1} H))\nCase conversion may be inaccurate. Consider using '#align subgroup.nat_card_dvd_of_injective Subgroup.nat_card_dvd_of_injectiveₓ'. -/\n@[to_additive]\ntheorem nat_card_dvd_of_injective {G H : Type _} [Group G] [Group H] (f : G →* H)\n    (hf : Function.Injective f) : Nat.card G ∣ Nat.card H :=\n  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/- warning: subgroup.nat_card_dvd_of_le -> Subgroup.nat_card_dvd_of_le is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1), (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Nat.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H)) (Nat.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) K)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) (K : Subgroup.{u1} G _inst_1), (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Nat.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H))) (Nat.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x K))))\nCase conversion may be inaccurate. Consider using '#align subgroup.nat_card_dvd_of_le Subgroup.nat_card_dvd_of_leₓ'. -/\n@[to_additive]\ntheorem nat_card_dvd_of_le (hHK : H ≤ K) : Nat.card H ∣ 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/- warning: subgroup.nat_card_dvd_of_surjective -> Subgroup.nat_card_dvd_of_surjective is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} {H : Type.{u2}} [_inst_2 : Group.{u1} G] [_inst_3 : Group.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))), (Function.Surjective.{succ u1, succ u2} G H (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) (fun (_x : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) => G -> H) (MonoidHom.hasCoeToFun.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) f)) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Nat.card.{u2} H) (Nat.card.{u1} G))\nbut is expected to have type\n  forall {G : Type.{u2}} {H : Type.{u1}} [_inst_2 : Group.{u2} G] [_inst_3 : Group.{u1} H] (f : MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))), (Function.Surjective.{succ u2, succ u1} G H (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => H) _x) (MulHomClass.toFunLike.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G H (MulOneClass.toMul.{u2} G (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2)))) (MulOneClass.toMul.{u1} H (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) (MonoidHomClass.toMulHomClass.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3))) (MonoidHom.monoidHomClass.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))))) f)) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Nat.card.{u1} H) (Nat.card.{u2} G))\nCase conversion may be inaccurate. Consider using '#align subgroup.nat_card_dvd_of_surjective Subgroup.nat_card_dvd_of_surjectiveₓ'. -/\n@[to_additive]\ntheorem nat_card_dvd_of_surjective {G H : Type _} [Group G] [Group H] (f : G →* H)\n    (hf : Function.Surjective f) : Nat.card H ∣ Nat.card G :=\n  by\n  rw [← 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/- warning: subgroup.card_dvd_of_surjective -> Subgroup.card_dvd_of_surjective is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} {H : Type.{u2}} [_inst_2 : Group.{u1} G] [_inst_3 : Group.{u2} H] [_inst_4 : Fintype.{u1} G] [_inst_5 : Fintype.{u2} H] (f : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))), (Function.Surjective.{succ u1, succ u2} G H (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) (fun (_x : MonoidHom.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) => G -> H) (MonoidHom.hasCoeToFun.{u1, u2} G H (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_2))) (Monoid.toMulOneClass.{u2} H (DivInvMonoid.toMonoid.{u2} H (Group.toDivInvMonoid.{u2} H _inst_3)))) f)) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Fintype.card.{u2} H _inst_5) (Fintype.card.{u1} G _inst_4))\nbut is expected to have type\n  forall {G : Type.{u2}} {H : Type.{u1}} [_inst_2 : Group.{u2} G] [_inst_3 : Group.{u1} H] [_inst_4 : Fintype.{u2} G] [_inst_5 : Fintype.{u1} H] (f : MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))), (Function.Surjective.{succ u2, succ u1} G H (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => H) _x) (MulHomClass.toFunLike.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G H (MulOneClass.toMul.{u2} G (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2)))) (MulOneClass.toMul.{u1} H (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) (MonoidHomClass.toMulHomClass.{max u2 u1, u2, u1} (MonoidHom.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))) G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3))) (MonoidHom.monoidHomClass.{u2, u1} G H (Monoid.toMulOneClass.{u2} G (DivInvMonoid.toMonoid.{u2} G (Group.toDivInvMonoid.{u2} G _inst_2))) (Monoid.toMulOneClass.{u1} H (DivInvMonoid.toMonoid.{u1} H (Group.toDivInvMonoid.{u1} H _inst_3)))))) f)) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Fintype.card.{u1} H _inst_5) (Fintype.card.{u2} G _inst_4))\nCase conversion may be inaccurate. Consider using '#align subgroup.card_dvd_of_surjective Subgroup.card_dvd_of_surjectiveₓ'. -/\n@[to_additive]\ntheorem card_dvd_of_surjective {G H : Type _} [Group G] [Group H] [Fintype G] [Fintype H]\n    (f : G →* H) (hf : Function.Surjective f) : Fintype.card H ∣ Fintype.card G := by\n  simp only [← 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/- warning: subgroup.index_map -> Subgroup.index_map is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] (f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))), Eq.{1} Nat (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.index.{u1} G _inst_1 (Sup.sup.{u1} (Subgroup.{u1} G _inst_1) (SemilatticeSup.toHasSup.{u1} (Subgroup.{u1} G _inst_1) (Lattice.toSemilatticeSup.{u1} (Subgroup.{u1} G _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.completeLattice.{u1} G _inst_1))))) H (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f))) (Subgroup.index.{u2} G' _inst_2 (MonoidHom.range.{u1, u2} G _inst_1 G' _inst_2 f)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] (f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))), Eq.{1} Nat (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.index.{u1} G _inst_1 (Sup.sup.{u1} (Subgroup.{u1} G _inst_1) (SemilatticeSup.toSup.{u1} (Subgroup.{u1} G _inst_1) (Lattice.toSemilatticeSup.{u1} (Subgroup.{u1} G _inst_1) (ConditionallyCompleteLattice.toLattice.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toConditionallyCompleteLattice.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f))) (Subgroup.index.{u2} G' _inst_2 (MonoidHom.range.{u1, u2} G _inst_1 G' _inst_2 f)))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_map Subgroup.index_mapₓ'. -/\n@[to_additive]\ntheorem index_map {G' : Type _} [Group G'] (f : G →* G') :\n    (H.map f).index = (H ⊔ f.ker).index * f.range.index := by\n  rw [← 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/- warning: subgroup.index_map_dvd -> Subgroup.index_map_dvd is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))}, (Function.Surjective.{succ u1, succ u2} G G' (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) (fun (_x : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) => G -> G') (MonoidHom.hasCoeToFun.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) f)) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))}, (Function.Surjective.{succ u1, succ u2} G G' (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => G') _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) G G' (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (MulOneClass.toMul.{u2} G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) (MonoidHomClass.toMulHomClass.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (MonoidHom.monoidHomClass.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))))) f)) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_map_dvd Subgroup.index_map_dvdₓ'. -/\n@[to_additive]\ntheorem index_map_dvd {G' : Type _} [Group G'] {f : G →* G'} (hf : Function.Surjective f) :\n    (H.map f).index ∣ H.index :=\n  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/- warning: subgroup.dvd_index_map -> Subgroup.dvd_index_map is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f) H) -> (Dvd.Dvd.{0} Nat Nat.hasDvd (Subgroup.index.{u1} G _inst_1 H) (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f) H) -> (Dvd.dvd.{0} Nat Nat.instDvdNat (Subgroup.index.{u1} G _inst_1 H) (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)))\nCase conversion may be inaccurate. Consider using '#align subgroup.dvd_index_map Subgroup.dvd_index_mapₓ'. -/\n@[to_additive]\ntheorem dvd_index_map {G' : Type _} [Group G'] {f : G →* G'} (hf : f.ker ≤ H) :\n    H.index ∣ (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/- warning: subgroup.index_map_eq -> Subgroup.index_map_eq is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))}, (Function.Surjective.{succ u1, succ u2} G G' (coeFn.{max (succ u2) (succ u1), max (succ u1) (succ u2)} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) (fun (_x : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) => G -> G') (MonoidHom.hasCoeToFun.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) f)) -> (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f) H) -> (Eq.{1} Nat (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] {f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))}, (Function.Surjective.{succ u1, succ u2} G G' (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) G (fun (_x : G) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.2391 : G) => G') _x) (MulHomClass.toFunLike.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) G G' (MulOneClass.toMul.{u1} G (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1)))) (MulOneClass.toMul.{u2} G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) (MonoidHomClass.toMulHomClass.{max u1 u2, u1, u2} (MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) (MonoidHom.monoidHomClass.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))))) f)) -> (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f) H) -> (Eq.{1} Nat (Subgroup.index.{u2} G' _inst_2 (Subgroup.map.{u1, u2} G _inst_1 G' _inst_2 f H)) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_map_eq Subgroup.index_map_eqₓ'. -/\n@[to_additive]\ntheorem index_map_eq {G' : Type _} [Group G'] {f : G →* G'} (hf1 : Function.Surjective f)\n    (hf2 : f.ker ≤ 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#print Subgroup.index_eq_card /-\n@[to_additive]\ntheorem index_eq_card [Fintype (G ⧸ H)] : H.index = Fintype.card (G ⧸ 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\n/- warning: subgroup.index_mul_card -> Subgroup.index_mul_card is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) [_inst_2 : Fintype.{u1} G] [hH : Fintype.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H)], Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.index.{u1} G _inst_1 H) (Fintype.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H) hH)) (Fintype.card.{u1} G _inst_2)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] (H : Subgroup.{u1} G _inst_1) [_inst_2 : Fintype.{u1} G] [hH : Fintype.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H))], Eq.{1} Nat (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.index.{u1} G _inst_1 H) (Fintype.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H)) hH)) (Fintype.card.{u1} G _inst_2)\nCase conversion may be inaccurate. Consider using '#align subgroup.index_mul_card Subgroup.index_mul_cardₓ'. -/\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 [← relindex_bot_left_eq_card, ← 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#print Subgroup.index_dvd_card /-\n@[to_additive]\ntheorem index_dvd_card [Fintype G] : H.index ∣ Fintype.card G := by\n  classical exact ⟨Fintype.card H, H.index_mul_card.symm⟩\n#align subgroup.index_dvd_card Subgroup.index_dvd_card\n#align add_subgroup.index_dvd_card AddSubgroup.index_dvd_card\n-/\n\nvariable {H K L}\n\n/- warning: subgroup.relindex_eq_zero_of_le_left -> Subgroup.relindex_eq_zero_of_le_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_eq_zero_of_le_left Subgroup.relindex_eq_zero_of_le_leftₓ'. -/\n@[to_additive]\ntheorem relindex_eq_zero_of_le_left (hHK : H ≤ K) (hKL : K.relindex L = 0) : H.relindex L = 0 :=\n  eq_zero_of_zero_dvd (hKL ▸ 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/- warning: subgroup.relindex_eq_zero_of_le_right -> Subgroup.relindex_eq_zero_of_le_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) K L) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H K) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) K L) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H K) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_eq_zero_of_le_right Subgroup.relindex_eq_zero_of_le_rightₓ'. -/\n@[to_additive]\ntheorem relindex_eq_zero_of_le_right (hKL : K ≤ 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#print Subgroup.index_eq_zero_of_relindex_eq_zero /-\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\n/- warning: subgroup.relindex_le_of_le_left -> Subgroup.relindex_le_of_le_left is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (LE.le.{0} Nat Nat.hasLe (Subgroup.relindex.{u1} G _inst_1 K L) (Subgroup.relindex.{u1} G _inst_1 H L))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (LE.le.{0} Nat instLENat (Subgroup.relindex.{u1} G _inst_1 K L) (Subgroup.relindex.{u1} G _inst_1 H L))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_le_of_le_left Subgroup.relindex_le_of_le_leftₓ'. -/\n@[to_additive]\ntheorem relindex_le_of_le_left (hHK : H ≤ K) (hHL : H.relindex L ≠ 0) :\n    K.relindex L ≤ 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/- warning: subgroup.relindex_le_of_le_right -> Subgroup.relindex_le_of_le_right is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) K L) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (LE.le.{0} Nat Nat.hasLe (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.relindex.{u1} G _inst_1 H L))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) K L) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (LE.le.{0} Nat instLENat (Subgroup.relindex.{u1} G _inst_1 H K) (Subgroup.relindex.{u1} G _inst_1 H L))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_le_of_le_right Subgroup.relindex_le_of_le_rightₓ'. -/\n@[to_additive]\ntheorem relindex_le_of_le_right (hKL : K ≤ L) (hHL : H.relindex L ≠ 0) :\n    H.relindex K ≤ 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#print Subgroup.relindex_ne_zero_trans /-\n@[to_additive]\ntheorem relindex_ne_zero_trans (hHK : H.relindex K ≠ 0) (hKL : K.relindex L ≠ 0) :\n    H.relindex L ≠ 0 := fun h =>\n  mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K ⊓ L ≤ 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\n/- warning: subgroup.relindex_inf_ne_zero -> Subgroup.relindex_inf_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K) L) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 K L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Ne.{1} Nat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K) L) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_inf_ne_zero Subgroup.relindex_inf_ne_zeroₓ'. -/\n@[to_additive]\ntheorem relindex_inf_ne_zero (hH : H.relindex L ≠ 0) (hK : K.relindex L ≠ 0) :\n    (H ⊓ K).relindex L ≠ 0 :=\n  by\n  replace hH : H.relindex (K ⊓ L) ≠ 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH\n  rw [← inf_relindex_right] at hH hK⊢\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/- warning: subgroup.index_inf_ne_zero -> Subgroup.index_inf_ne_zero is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (Ne.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Ne.{1} Nat (Subgroup.index.{u1} G _inst_1 K) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Ne.{1} Nat (Subgroup.index.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K)) (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, (Ne.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Ne.{1} Nat (Subgroup.index.{u1} G _inst_1 K) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Ne.{1} Nat (Subgroup.index.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K)) (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_inf_ne_zero Subgroup.index_inf_ne_zeroₓ'. -/\n@[to_additive]\ntheorem index_inf_ne_zero (hH : H.index ≠ 0) (hK : K.index ≠ 0) : (H ⊓ K).index ≠ 0 :=\n  by\n  rw [← relindex_top_right] at hH hK⊢\n  exact relindex_inf_ne_zero hH hK\n#align subgroup.index_inf_ne_zero Subgroup.index_inf_ne_zero\n#align add_subgroup.index_inf_ne_zero AddSubgroup.index_inf_ne_zero\n\n/- warning: subgroup.relindex_inf_le -> Subgroup.relindex_inf_le is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, LE.le.{0} Nat Nat.hasLe (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K) L) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.relindex.{u1} G _inst_1 H L) (Subgroup.relindex.{u1} G _inst_1 K L))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} {L : Subgroup.{u1} G _inst_1}, LE.le.{0} Nat instLENat (Subgroup.relindex.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K) L) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.relindex.{u1} G _inst_1 H L) (Subgroup.relindex.{u1} G _inst_1 K L))\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_inf_le Subgroup.relindex_inf_leₓ'. -/\n@[to_additive]\ntheorem relindex_inf_le : (H ⊓ K).relindex L ≤ H.relindex L * K.relindex L :=\n  by\n  by_cases h : H.relindex L = 0\n  · exact (le_of_eq (relindex_eq_zero_of_le_left inf_le_left h)).trans (zero_le _)\n  rw [← inf_relindex_right, inf_assoc, ← 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/- warning: subgroup.index_inf_le -> Subgroup.index_inf_le is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, LE.le.{0} Nat Nat.hasLe (Subgroup.index.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasInf.{u1} G _inst_1) H K)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) (Subgroup.index.{u1} G _inst_1 H) (Subgroup.index.{u1} G _inst_1 K))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, LE.le.{0} Nat instLENat (Subgroup.index.{u1} G _inst_1 (Inf.inf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instInfSubgroup.{u1} G _inst_1) H K)) (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) (Subgroup.index.{u1} G _inst_1 H) (Subgroup.index.{u1} G _inst_1 K))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_inf_le Subgroup.index_inf_leₓ'. -/\n@[to_additive]\ntheorem index_inf_le : (H ⊓ K).index ≤ H.index * K.index := by\n  simp_rw [← 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#print Subgroup.relindex_infᵢ_ne_zero /-\n@[to_additive]\ntheorem relindex_infᵢ_ne_zero {ι : Type _} [hι : Finite ι] {f : ι → Subgroup G}\n    (hf : ∀ i, (f i).relindex L ≠ 0) : (⨅ i, f i).relindex L ≠ 0 :=\n  haveI := Fintype.ofFinite ι\n  (finset.prod_ne_zero_iff.mpr fun i hi => hf i) ∘\n    nat.card_pi.symm.trans ∘\n      Finite.card_eq_zero_of_embedding (quotient_infi_subgroup_of_embedding f L)\n#align subgroup.relindex_infi_ne_zero Subgroup.relindex_infᵢ_ne_zero\n#align add_subgroup.relindex_infi_ne_zero AddSubgroup.relindex_infᵢ_ne_zero\n-/\n\n#print Subgroup.relindex_infᵢ_le /-\n@[to_additive]\ntheorem relindex_infᵢ_le {ι : Type _} [Fintype ι] (f : ι → Subgroup G) :\n    (⨅ i, f i).relindex L ≤ ∏ i, (f i).relindex L :=\n  le_of_le_of_eq\n    (Finite.card_le_of_embedding' (quotientInfᵢSubgroupOfEmbedding f L) fun h =>\n      let ⟨i, hi, h⟩ := Finset.prod_eq_zero_iff.mp (Nat.card_pi.symm.trans h)\n      relindex_eq_zero_of_le_left (infᵢ_le f i) h)\n    Nat.card_pi\n#align subgroup.relindex_infi_le Subgroup.relindex_infᵢ_le\n#align add_subgroup.relindex_infi_le AddSubgroup.relindex_infᵢ_le\n-/\n\n#print Subgroup.index_infᵢ_ne_zero /-\n@[to_additive]\ntheorem index_infᵢ_ne_zero {ι : Type _} [Finite ι] {f : ι → Subgroup G}\n    (hf : ∀ i, (f i).index ≠ 0) : (⨅ i, f i).index ≠ 0 :=\n  by\n  simp_rw [← relindex_top_right] at hf⊢\n  exact relindex_infi_ne_zero hf\n#align subgroup.index_infi_ne_zero Subgroup.index_infᵢ_ne_zero\n#align add_subgroup.index_infi_ne_zero AddSubgroup.index_infᵢ_ne_zero\n-/\n\n#print Subgroup.index_infᵢ_le /-\n@[to_additive]\ntheorem index_infᵢ_le {ι : Type _} [Fintype ι] (f : ι → Subgroup G) :\n    (⨅ i, f i).index ≤ ∏ i, (f i).index := by simp_rw [← relindex_top_right, relindex_infi_le]\n#align subgroup.index_infi_le Subgroup.index_infᵢ_le\n#align add_subgroup.index_infi_le AddSubgroup.index_infᵢ_le\n-/\n\n/- warning: subgroup.index_eq_one -> Subgroup.index_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Eq.{succ u1} (Subgroup.{u1} G _inst_1) H (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasTop.{u1} G _inst_1)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Subgroup.index.{u1} G _inst_1 H) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Eq.{succ u1} (Subgroup.{u1} G _inst_1) H (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instTopSubgroup.{u1} G _inst_1)))\nCase conversion may be inaccurate. Consider using '#align subgroup.index_eq_one Subgroup.index_eq_oneₓ'. -/\n@[simp, to_additive index_eq_one]\ntheorem index_eq_one : H.index = 1 ↔ H = ⊤ :=\n  ⟨fun h =>\n    QuotientGroup.subgroup_eq_top_of_subsingleton H (Cardinal.toNat_eq_one_iff_unique.mp h).1,\n    fun h => (congr_arg index h).trans index_top⟩\n#align subgroup.index_eq_one Subgroup.index_eq_one\n#align add_subgroup.index_eq_one AddSubgroup.index_eq_one\n\n/- warning: subgroup.relindex_eq_one -> Subgroup.relindex_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H K) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) K H)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Subgroup.relindex.{u1} G _inst_1 H K) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) K H)\nCase conversion may be inaccurate. Consider using '#align subgroup.relindex_eq_one Subgroup.relindex_eq_oneₓ'. -/\n@[simp, to_additive relindex_eq_one]\ntheorem relindex_eq_one : H.relindex K = 1 ↔ K ≤ 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/- warning: subgroup.card_eq_one -> Subgroup.card_eq_one is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Nat.card.{u1} (coeSort.{succ u1, succ (succ u1)} (Subgroup.{u1} G _inst_1) Type.{u1} (SetLike.hasCoeToSort.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)) H)) (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (Eq.{succ u1} (Subgroup.{u1} G _inst_1) H (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasBot.{u1} G _inst_1)))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1}, Iff (Eq.{1} Nat (Nat.card.{u1} (Subtype.{succ u1} G (fun (x : G) => Membership.mem.{u1, u1} G (Subgroup.{u1} G _inst_1) (SetLike.instMembership.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.instSetLikeSubgroup.{u1} G _inst_1)) x H))) (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (Eq.{succ u1} (Subgroup.{u1} G _inst_1) H (Bot.bot.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instBotSubgroup.{u1} G _inst_1)))\nCase conversion may be inaccurate. Consider using '#align subgroup.card_eq_one Subgroup.card_eq_oneₓ'. -/\n@[simp, to_additive card_eq_one]\ntheorem card_eq_one : Nat.card H = 1 ↔ H = ⊥ :=\n  H.relindex_bot_left ▸ 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#print Subgroup.index_ne_zero_of_finite /-\n@[to_additive]\ntheorem index_ne_zero_of_finite [hH : Finite (G ⧸ H)] : H.index ≠ 0 :=\n  by\n  cases nonempty_fintype (G ⧸ 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\n#print Subgroup.fintypeOfIndexNeZero /-\n/-- Finite index implies finite quotient. -/\n@[to_additive \"Finite index implies finite quotient.\"]\nnoncomputable def fintypeOfIndexNeZero (hH : H.index ≠ 0) : Fintype (G ⧸ H) :=\n  (Cardinal.lt_aleph0_iff_fintype.mp (lt_of_not_ge (mt Cardinal.toNat_apply_of_aleph0_le hH))).some\n#align subgroup.fintype_of_index_ne_zero Subgroup.fintypeOfIndexNeZero\n#align add_subgroup.fintype_of_index_ne_zero AddSubgroup.fintypeOfIndexNeZero\n-/\n\n/- warning: subgroup.one_lt_index_of_ne_top -> Subgroup.one_lt_index_of_ne_top is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} [_inst_2 : Finite.{succ u1} (HasQuotient.Quotient.{u1, u1} G (Subgroup.{u1} G _inst_1) (QuotientGroup.Subgroup.hasQuotient.{u1} G _inst_1) H)], (Ne.{succ u1} (Subgroup.{u1} G _inst_1) H (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.hasTop.{u1} G _inst_1))) -> (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) (Subgroup.index.{u1} G _inst_1 H))\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} [_inst_2 : Finite.{succ u1} (HasQuotient.Quotient.{u1, u1} G (Subgroup.{u1} G _inst_1) (QuotientGroup.instHasQuotientSubgroup.{u1} G _inst_1) H)], (Ne.{succ u1} (Subgroup.{u1} G _inst_1) H (Top.top.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instTopSubgroup.{u1} G _inst_1))) -> (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) (Subgroup.index.{u1} G _inst_1 H))\nCase conversion may be inaccurate. Consider using '#align subgroup.one_lt_index_of_ne_top Subgroup.one_lt_index_of_ne_topₓ'. -/\n@[to_additive one_lt_index_of_ne_top]\ntheorem one_lt_index_of_ne_top [Finite (G ⧸ H)] (hH : H ≠ ⊤) : 1 < H.index :=\n  Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨index_ne_zero_of_finite, mt index_eq_one.mp hH⟩\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#print Subgroup.FiniteIndex /-\n/-- Typeclass for finite index subgroups. -/\nclass FiniteIndex : Prop where\n  FiniteIndex : H.index ≠ 0\n#align subgroup.finite_index Subgroup.FiniteIndex\n-/\n\n#print AddSubgroup.FiniteIndex /-\n/-- Typeclass for finite index subgroups. -/\nclass AddSubgroup.FiniteIndex {G : Type _} [AddGroup G] (H : AddSubgroup G) : Prop where\n  FiniteIndex : H.index ≠ 0\n#align add_subgroup.finite_index AddSubgroup.FiniteIndex\n-/\n\n#print Subgroup.fintypeQuotientOfFiniteIndex /-\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 ⧸ 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\n#print Subgroup.finite_quotient_of_finiteIndex /-\n@[to_additive]\ninstance finite_quotient_of_finiteIndex [FiniteIndex H] : Finite (G ⧸ 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\n#print Subgroup.finiteIndex_of_finite_quotient /-\n@[to_additive]\ntheorem finiteIndex_of_finite_quotient [Finite (G ⧸ H)] : FiniteIndex H :=\n  ⟨index_ne_zero_of_finite⟩\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\n#print Subgroup.finiteIndex_of_finite /-\n@[to_additive]\ninstance (priority := 100) finiteIndex_of_finite [Finite G] : FiniteIndex H :=\n  finiteIndex_of_finite_quotient H\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\n@[to_additive]\ninstance : FiniteIndex (⊤ : Subgroup G) :=\n  ⟨ne_of_eq_of_ne index_top one_ne_zero⟩\n\n@[to_additive]\ninstance [FiniteIndex H] [FiniteIndex K] : FiniteIndex (H ⊓ K) :=\n  ⟨index_inf_ne_zero FiniteIndex.finiteIndex FiniteIndex.finiteIndex⟩\n\nvariable {H K}\n\n/- warning: subgroup.finite_index_of_le -> Subgroup.finiteIndex_of_le is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} [_inst_2 : Subgroup.FiniteIndex.{u1} G _inst_1 H], (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (SetLike.partialOrder.{u1, u1} (Subgroup.{u1} G _inst_1) G (Subgroup.setLike.{u1} G _inst_1)))) H K) -> (Subgroup.FiniteIndex.{u1} G _inst_1 K)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {H : Subgroup.{u1} G _inst_1} {K : Subgroup.{u1} G _inst_1} [_inst_2 : Subgroup.FiniteIndex.{u1} G _inst_1 H], (LE.le.{u1} (Subgroup.{u1} G _inst_1) (Preorder.toLE.{u1} (Subgroup.{u1} G _inst_1) (PartialOrder.toPreorder.{u1} (Subgroup.{u1} G _inst_1) (CompleteSemilatticeInf.toPartialOrder.{u1} (Subgroup.{u1} G _inst_1) (CompleteLattice.toCompleteSemilatticeInf.{u1} (Subgroup.{u1} G _inst_1) (Subgroup.instCompleteLatticeSubgroup.{u1} G _inst_1))))) H K) -> (Subgroup.FiniteIndex.{u1} G _inst_1 K)\nCase conversion may be inaccurate. Consider using '#align subgroup.finite_index_of_le Subgroup.finiteIndex_of_leₓ'. -/\n@[to_additive]\ntheorem finiteIndex_of_le [FiniteIndex H] (h : H ≤ K) : FiniteIndex K :=\n  ⟨ne_zero_of_dvd_ne_zero FiniteIndex.finiteIndex (index_dvd_of_le h)⟩\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/- warning: subgroup.finite_index_ker -> Subgroup.finiteIndex_ker is a dubious translation:\nlean 3 declaration is\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] (f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) [_inst_3 : Finite.{succ u2} (coeSort.{succ u2, succ (succ u2)} (Subgroup.{u2} G' _inst_2) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Subgroup.{u2} G' _inst_2) G' (Subgroup.setLike.{u2} G' _inst_2)) (MonoidHom.range.{u1, u2} G _inst_1 G' _inst_2 f))], Subgroup.FiniteIndex.{u1} G _inst_1 (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f)\nbut is expected to have type\n  forall {G : Type.{u1}} [_inst_1 : Group.{u1} G] {G' : Type.{u2}} [_inst_2 : Group.{u2} G'] (f : MonoidHom.{u1, u2} G G' (Monoid.toMulOneClass.{u1} G (DivInvMonoid.toMonoid.{u1} G (Group.toDivInvMonoid.{u1} G _inst_1))) (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2)))) [_inst_3 : Finite.{succ u2} (Subtype.{succ u2} G' (fun (x : G') => Membership.mem.{u2, u2} G' (Subgroup.{u2} G' _inst_2) (SetLike.instMembership.{u2, u2} (Subgroup.{u2} G' _inst_2) G' (Subgroup.instSetLikeSubgroup.{u2} G' _inst_2)) x (MonoidHom.range.{u1, u2} G _inst_1 G' _inst_2 f)))], Subgroup.FiniteIndex.{u1} G _inst_1 (MonoidHom.ker.{u1, u2} G _inst_1 G' (Monoid.toMulOneClass.{u2} G' (DivInvMonoid.toMonoid.{u2} G' (Group.toDivInvMonoid.{u2} G' _inst_2))) f)\nCase conversion may be inaccurate. Consider using '#align subgroup.finite_index_ker Subgroup.finiteIndex_kerₓ'. -/\n@[to_additive]\ninstance finiteIndex_ker {G' : Type _} [Group G'] (f : G →* 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\n#print Subgroup.finiteIndex_normalCore /-\ninstance finiteIndex_normalCore [H.FiniteIndex] : H.normalCore.FiniteIndex :=\n  by\n  rw [normal_core_eq_ker]\n  infer_instance\n#align subgroup.finite_index_normal_core Subgroup.finiteIndex_normalCore\n-/\n\nvariable (G)\n\n#print Subgroup.finiteIndex_center /-\ninstance finiteIndex_center [Finite (commutatorSet G)] [Group.Fg G] : FiniteIndex (center G) :=\n  by\n  obtain ⟨S, -, hS⟩ := Group.rank_spec G\n  exact ⟨mt (Finite.card_eq_zero_of_embedding (quotient_center_embedding hS)) finite.card_pos.ne'⟩\n#align subgroup.finite_index_center Subgroup.finiteIndex_center\n-/\n\n#print Subgroup.index_center_le_pow /-\ntheorem index_center_le_pow [Finite (commutatorSet G)] [Group.Fg G] :\n    (center G).index ≤ Nat.card (commutatorSet G) ^ Group.rank G :=\n  by\n  obtain ⟨S, hS1, hS2⟩ := Group.rank_spec G\n  rw [← hS1, ← Fintype.card_coe, ← Nat.card_eq_fintype_card, ← Finset.coe_sort_coe, ← Nat.card_fun]\n  exact Finite.card_le_of_embedding (quotient_center_embedding hS2)\n#align subgroup.index_center_le_pow Subgroup.index_center_le_pow\n-/\n\nend FiniteIndex\n\nend Subgroup\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/Index.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7683293002545936}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    (P → Q) ↔ ¬ P ∨ Q \n-- ----------------------------------------------------------------------\n\nimport tactic\n\nopen_locale classical\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (P Q : Prop) \n  : (P → Q) ↔ ¬ P ∨ Q :=\nbegin\n  split,\n  { intro h1,\n    by_cases h2: P,\n    { right,\n      apply h1,\n      exact h2 },\n    { left,\n      exact h2 }},\n  { intros h3 h4,\n    cases h3,\n    { contradiction },\n    { assumption }},\nend\n\n-- Prueba\n-- ======\n\n/-\nP Q : Prop\n⊢ P → Q ↔ ¬P ∨ Q\n  >> split,\n| 2 goals\n| P Q : Prop\n| ⊢ (P → Q) → ¬P ∨ Q\n|   >> { intro h1,\n| h1 : P → Q\n| ⊢ ¬P ∨ Q\n|   >>   by_cases h2: P,\n| | 2 goals\n| | P Q : Prop,\n| | h1 : P → Q,\n| | h2 : P\n| | ⊢ ¬P ∨ Q\n| |   >>   { right,\n| | ⊢ Q\n| |   >>     apply h1,\n| | ⊢ P\n| |   >>     exact h2 },\n| P Q : Prop,\n| h1 : P → Q,\n| h2 : ¬P\n| ⊢ ¬P ∨ Q\n|   >>   { left,\n| ⊢ ¬P\n|   >>     exact h2 }},\nP Q : Prop\n⊢ ¬P ∨ Q → P → Q\n  >> { intros h3 h4,\nh3 : ¬P ∨ Q,\nh4 : P\n⊢ Q\n  >>   cases h3,\n| 2 goals\n| case or.inl\n| P Q : Prop,\n| h4 : P,\n| h3 : ¬P\n| ⊢ Q\n|   >>   { contradiction },\ncase or.inr\nP Q : Prop,\nh4 : P,\nh3 : Q\n⊢ Q\n  >>   { assumption }},\nno goals\n-/\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (P Q : Prop) \n  : (P → Q) ↔ ¬ P ∨ Q :=\nimp_iff_not_or\n\n-- 3ª demostración\n-- ===============\n\nexample \n  (P Q : Prop) \n  : (P → Q) ↔ ¬ P ∨ Q :=\nby tauto\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/Implicacion_mediante_disyuncion_y_negacion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8615382023207901, "lm_q1q2_score": 0.7683292923283492}}
{"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 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:\n\n* `trivial`\n* `exfalso`\n\n### The `trivial` tactic\n\nIf your goal is `⊢ true` then `trivial,` will solve it. \n\n### The `exfalso` tactic\n\nThe tactic `exfalso,` turns any goal `⊢ P` into `⊢ false`. \nThis is mathematically valid because `false` implies any goal.\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  trivial,\nend\n\nexample : true → true :=\nbegin\n  intro h,\n  trivial,\nend\n\nexample : false → true :=\nbegin\n  trivial,\nend\n\nexample : false → false :=\nbegin\n  trivial,\nend\n\nexample : (true → false) → false :=\nbegin\n  intro h,\n  exact h trivial,                    /-remember such usage-/\nend\n\nexample : false → P :=\nbegin\n  trivial,\nend\n\nexample : true → false → true → false → true → false :=\nbegin\n  intros h1 h2 h3 h4 h5,\n  exfalso,\n  exact h2,\nend\n\nexample : P → ((P → false) → false) :=\nbegin\n  intro hP,\n  intro hPf,\n  exact hPf hP,\nend\n\nexample : (P → false) → P → Q :=\nbegin\n  intros hPf hP,\n  exfalso,\n  exact hPf hP,\nend\n\nexample : (true → false) → P :=\nbegin\n  intro h,\n  exfalso,\n  exact h trivial,\nend\n\n/-\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\n/-!\n\n# Logic in Lean, example sheet 3 : \"not\" (`¬`)\n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# Important : the definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → false`. So `¬ P` and `P → false`\nare *the same thing* and can be used interchangeably. You can change\nfrom one to the other for free.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following tactics:\n\n* `change` (optional)\n* `by_contra`\n* `by_cases`\n\n### The `change` tactic\n\nThe `change` tactic changes a goal to a goal which\nis *equal to it by definition*. The example you need to know\nis that `¬ P` and `P → false` are equal by definition.\n\nIf your goal is `⊢ ¬ P` then `change P → false,` will\nchange it to `P → false`. Similarly if you have a hypothesis\n`h : ¬ P` then `change P → false at h,` will change it to `h : P → false`.\n\nNote that this tactic is just for psychological purposes. If you finish\na proof which uses this tactic, try commenting out the `change` lines\nand note that it doesn't break.\n\n### The `by_contra` tactic\n\nIf your goal is `⊢ P` and you want to prove it by contradiction,\n`by_contra h,` will change the goal to `false` and add a hypothesis\n`h : ¬ P`.\n\n### The `by_cases` tactic\n\nIf `P : Prop` is a true-false statement then `by_cases hP : P,`\nturns your goal into two goals, one with hypothesis `hP : P`\nand the other with hypothesis `hP : ¬ P`.\n\n-/\n\n-- Throughout this sheet, `P`, `Q` and `R` will denote propositions.\n\nexample : ¬ P → (P → false) :=\nbegin\n  intro h,\n  change P → false at h,\n  trivial,\nend\n\nexample : ¬ true → false :=\nbegin\n  intro h,\n  change true → false at h,\n  exact h trivial,\nend\n\nexample : false → ¬ true :=\nbegin\n  intro h,\n  change true → false,\n  intro ht,\n  exact h,\nend\n\nexample : ¬ false → true :=\nbegin\n  intro h,\n  change false → false at h,\n  trivial,\nend\n\nexample : true → ¬ false :=\nbegin\n  intro h,\n  change false → false,\n  trivial,\nend\n\nexample : false → ¬ P :=\nbegin\n  intro h,\n  change P → false,\n  intro P, \n  exact h,\nend\n\nexample : P → ¬ P → false :=\nbegin\n  intros hP hP',\n  change P → false at hP',\n  exact hP' hP,\nend\n\nexample : P → ¬ (¬ P) :=\nbegin\n  intro hP,\n  change ¬P → false,\n  intro hP',\n  change P → false at hP',\n  exact hP' hP,\nend\n\nexample : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  intro hPQ,\n  intro hQ,\n  change Q → false at hQ,\n  change P → false,\n  intro hP,\n  apply hQ,\n  exact hPQ hP,\nend\n\nexample : ¬ ¬ false → false :=\nbegin\n  by_cases false,\n  {intro h,\n    change ¬ false → false at h,\n    exact h,},\n  {intro h,\n  change ¬ false → false at h,\n  exact h_1 h,},\nend\n\nexample : ¬ ¬ P → P :=\nbegin\n  by_cases P,\n  {intro h,\n  change ¬ P → false at h,\n  exact h},\n  {intro h,\n  change ¬ P → false at h,\n  exfalso,\n  exact h_1 h,},\nend\n\nexample : (¬ Q → ¬ P) → (P → Q) :=\nbegin\n  intro h,\n  intro hP,\n  by_contra hP,\n  have hP': ¬ P, apply h hP,\n  trivial,\nend", "meta": {"author": "Siesta233", "repo": "LeanPractice", "sha": "3795eeb8763edacf2c74b9c8925f642d6cc56daf", "save_path": "github-repos/lean/Siesta233-LeanPractice", "path": "github-repos/lean/Siesta233-LeanPractice/LeanPractice-3795eeb8763edacf2c74b9c8925f642d6cc56daf/src/PS2&3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361275, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7683292765724252}}
{"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⁻¹ = b`. -/\ndef is_conj {α : Type u} [group α] (a : α) (b : α) :=\n  ∃ (c : α), c * a * (c⁻¹) = b\n\ntheorem is_conj_refl {α : Type u} [group α] (a : α) : is_conj a a := sorry\n\ntheorem is_conj_symm {α : Type u} [group α] {a : α} {b : α} : is_conj a b → is_conj b a := sorry\n\ntheorem is_conj_trans {α : Type u} [group α] {a : α} {b : α} {c : α} : is_conj a b → is_conj b c → is_conj a c := sorry\n\n@[simp] theorem is_conj_one_right {α : Type u} [group α] {a : α} : is_conj 1 a ↔ a = 1 := sorry\n\n@[simp] theorem is_conj_one_left {α : Type u} [group α] {a : α} : is_conj a 1 ↔ a = 1 :=\n  iff.trans { mp := is_conj_symm, mpr := is_conj_symm } is_conj_one_right\n\n@[simp] theorem conj_inv {α : Type u} [group α] {a : α} {b : α} : b * a * (b⁻¹)⁻¹ = b * (a⁻¹) * (b⁻¹) :=\n  Eq.symm (mul_equiv.map_inv (coe_fn mul_aut.conj b) a)\n\n@[simp] theorem conj_mul {α : Type u} [group α] {a : α} {b : α} {c : α} : b * a * (b⁻¹) * (b * c * (b⁻¹)) = b * (a * c) * (b⁻¹) :=\n  Eq.symm (mul_equiv.map_mul (coe_fn mul_aut.conj b) a c)\n\ntheorem conj_injective {α : Type u} [group α] {x : α} : function.injective fun (g : α) => x * g * (x⁻¹) :=\n  mul_equiv.injective (coe_fn mul_aut.conj x)\n\n@[simp] theorem is_conj_iff_eq {α : Type u_1} [comm_group α] {a : α} {b : α} : is_conj a b ↔ a = b := sorry\n\nprotected theorem monoid_hom.map_is_conj {α : Type u} {β : Type v} [group α] [group β] (f : α →* β) {a : α} {b : α} : is_conj a b → is_conj (coe_fn f a) (coe_fn f b) := 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/conj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7682935550129594}}
{"text": "/- Yair Gueta : 208624908 : t4\n    Exercise 4\n-/\n\n\n---- Question 1\n\n--- Chapter 3:\nnamespace C3\nvariables p q r : Prop\n-- First proof first try:\nexample : p ∨ false ↔ p := \nbegin\n  simp,\nend\n\n-- First proof 2nd try:\nexample : p ∨ false ↔ p := \nbegin\n  apply iff.intro,\n    intro h,\n      apply or.elim h,\n      intro hp, \n      exact hp,\n    intro hfalse,\n    apply false.elim,\n    exact hfalse,\n  intro hp,\n  exact or.inl hp,\nend\n\nexample : p ∧ false ↔ false := \nbegin\n  apply iff.intro,\n    intro h,\n    exact h.right,\n  intro hf,\n  exact false.elim hf,\nend\n\nexample : (p → q) → (¬q → ¬p) := \nbegin\n  intro h,\n  intro hnq,\n  apply not.intro,\n  intro hp,\n  exact absurd (h hp) hnq\nend\n\nend C3\n\n\n--- Chapter 4:\nnamespace C4\nopen classical\nvariables (α : Type*) (p q : α → Prop)\nvariable r : Prop\n\nexample : α → ((∀ x : α, r) ↔ r) := \nbegin\n  intro ha,\n  apply iff.intro,\n    intro h,\n    exact h ha,\n  intro h,\n  intro haa,\n  exact h,\nend\n\nexample : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=\nbegin\n  apply iff.intro,\n    intro h,\n    apply or.elim (em r),\n      intro hr,\n      exact or.inr hr,\n    intro hnr,\n    left,\n      intro l,\n      cases (h l) with a b,\n        exact a,\n      show p l, from absurd b hnr,\n  intro h,\n  intro hx,\n  cases h with h₁ h₂,\n    exact or.inl (h₁ hx),\n  exact or.inr h₂,\nend\n\nexample : (∀ x, r → p x) ↔ (r → ∀ x, p x) := \nbegin\n  apply iff.intro,\n    intro h,\n    intro hr,\n    intro hx,\n    exact (h hx) hr,\n  intro h,\n  intro hx,\n  intro hr,\n  exact (h hr) hx, \nend\n\nend C4\n\n\n--- Question 2:\nexample (p q r : Prop) (hp : p) :\n(p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) :=\nby {repeat {split}, repeat{left, assumption}, repeat{right, left, assumption}, repeat{right, right, assumption}}", "meta": {"author": "yairgueta", "repo": "Lean", "sha": "af8a4fa24f76edfdd0dd33f013db194e611e6a86", "save_path": "github-repos/lean/yairgueta-Lean", "path": "github-repos/lean/yairgueta-Lean/Lean-af8a4fa24f76edfdd0dd33f013db194e611e6a86/src/t4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7682935423425371}}
{"text": "def hello := \"world\"\n\nuniverse v u u₁ u₂\n#check Sort 0\nclass Category (Ob : Type u) where\n  hom : Ob → Ob → Sort v\n  id : ∀ A : Ob, hom A A\n  comp : ∀ {A B C : Ob}, (hom A B) → (hom B C) → (hom A C)\n  comp_assoc : ∀ {A B C D : Ob} (f : hom A B) (g : hom B C) (h : hom C D),\n    comp f (comp g h) = comp (comp f g) h\n  l_unit : ∀ {A B : Ob} (f : hom A B), comp (id A) f = f\n  r_unit : ∀ {A B : Ob} (f : hom A B), comp f (id B) = f\n\nexport Category (hom id comp)\n\nstructure functor (C : Type u₁) (D : Type u₂) [Category C] [Category D] where\n  ob_map : C → D\n  hom_map : ∀ {A B : C}, (hom A B) → (hom (ob_map A) (ob_map B))\n  preserve_units : ∀ {A : C}, hom_map (Category.id A) = Category.id (ob_map A)\n  preserve_comp : ∀ {X Y Z : C} (f : hom X Y) (g : hom Y Z),\n    hom_map (comp f g) = comp (hom_map f) (hom_map g)\n\n#check functor\n\nsection CategoryOne\n\ninductive One where\n  | one : One\n\ninductive OneId where\n  | mk : One → One → OneId\n\ninstance : ToString One where\n  toString one := \"•\"\n\ninstance : ToString OneId where\n  toString _ := \"id•\"\n\nopen One\n\ninstance : Category One where\n  hom (X Y : One) := OneId\n  id _ := OneId.mk one one\n  comp := fun (OneId.mk one one) (OneId.mk one one) => OneId.mk one one\n  comp_assoc f g h := by simp\n  l_unit f := by simp\n  r_unit f := by simp\n\n#eval Category.id one\n#eval comp (Category.id one) (Category.id one)\n\ndef endo_one : functor One One := {\n  ob_map := fun _ => one,\n  hom_map := fun _ => OneId.mk one one,\n  preserve_units := by\n    simp\n    rfl\n  preserve_comp := by\n    simp\n    intros\n    rfl\n}\n\n#check endo_one\n#eval endo_one.ob_map one\n\ndef functor_to_one (C : Type u) [Category C] : (functor C One) := { \n  ob_map := fun _ => one, \n  hom_map := fun _ => OneId.mk one one\n  preserve_units := by\n    simp\n    rfl\n  preserve_comp := by\n    simp\n    intros\n    rfl  \n}\n\nend CategoryOne\n\n-- The category of Lean types (in universe 1) and functions between them\nsection LeanCat\n\ninstance : Category Type where\n  hom (X Y : Type) := X → Y\n  id A := fun (x : A) => x\n  comp f g := fun x => g (f x)\n  comp_assoc f g h := by simp\n  l_unit f := by simp\n  r_unit f := by simp\n\ndef list_length (l : List Nat) : Nat :=\n  match l with\n  | x::xs => 1 + (list_length xs)\n  | nil => 0\n\n#eval list_length [1,2,3,4]\n\ndef double (x : Nat) : Nat := x * 2\n\n#eval (Category.id Nat) 7\n#eval (Category.id (List Nat)) [1,2,3]\n\n\ndef doubleH := Category.comp (Category.id Nat) double\ndef lengthH := Category.comp (Category.id (List Nat)) list_length\n\n#check comp lengthH doubleH\n#eval (comp lengthH doubleH) [1,2,3,4]\n\ndef F := functor_to_one Type\n#check F\n\n#eval F.ob_map Nat\n#eval F.hom_map lengthH\n\nend LeanCat\n\nsection CatMonoid\n\nclass Monoid (α : Type u) where\n  unit : α\n  op : α → α → α\n  op_assoc: ∀ a b c : α, op a (op b c) = op (op a b) c\n  l_unit : ∀ a : α, op unit a = a\n  r_unit : ∀ a : α, op a unit = a\n\ninstance cat_of_monoid (α : Type u) (M : Monoid α) : Category Unit where\n  hom := fun (_ _ : Unit) => α\n  id := fun (x : Unit) => M.unit\n  comp := fun (f g : α) => M.op f g\n  comp_assoc := by simp; intros; apply M.op_assoc\n  l_unit := by simp; intros; apply M.l_unit\n  r_unit := by simp; intros; apply M.r_unit\n     \ninstance NatsUnderPlus : Monoid Nat where\n  unit := 0\n  op x y := x + y\n  l_unit x := by simp\n  r_unit x := by simp\n  op_assoc a b c := by\n    simp\n    rw [Nat.add_assoc]\n\ndef NatsUnderPlusCat := cat_of_monoid Nat NatsUnderPlus\n\n-- TODO: Figure out how to evaluate homs in these categories\n\nend CatMonoid\n\nsection PreorderCats\n\nclass Preorder (Ob : Type u) where\n  leq : Ob → Ob → Prop\n  leq_ref : ∀ a : Ob, leq a a\n  leq_trans : ∀ a b c : Ob, (leq a b) → (leq b c) → (leq a c)\n\n-- Construct a thin category from a preorder\ninstance cat_of_preorder (α : Type u) (P : Preorder α) : Category.{0} α where\n  hom := P.leq\n  id a := by apply P.leq_ref\n  comp := by apply P.leq_trans \n  comp_assoc := by intros; rfl\n  l_unit := by intros; rfl\n  r_unit := by intros; rfl\n\n-- Examples\n\ninstance NatPreorder : Preorder Nat where\n  leq := Nat.le\n  leq_ref := by simp \n  leq_trans := by \n    simp\n    apply Nat.le_trans\n\ninstance NatMod4Preorder : Preorder Nat where\n  leq a b := a / 4 ≤ b / 4\n  leq_ref := by simp\n  leq_trans a b c := by\n    simp\n    apply Nat.le_trans\n\n-- Top and Bottom\n\nstructure bottom (C : Type u) (P : Preorder C) where\n  el : C\n  is_bottom : ∀ x : C, P.leq el x\n\nstructure top (C : Type u) (P : Preorder C) where\n  el : C\n  is_top : ∀ x : C, P.leq x el\n\n-- Can set el to 0-3 and this will hold because 0-3 are isomorphic in this preorder\ndef nat_bottom : bottom Nat NatMod4Preorder := {\n  el := 0\n  is_bottom := by\n    intro x\n    apply Nat.zero_le\n}\n\n#check nat_bottom\n\n-- Meets and joins. TODO: restate these as degenerate cases of products/co-products in thin cats\n\nstructure join (C : Type u) (a b : C) (P : Preorder C) where\n  j : C\n  upper_bound : (P.leq a j) ∧ (P.leq b j)\n  least: ∀ x : C, (P.leq a x) → (P.leq b x) → (P.leq j x)\n\nstructure has_all_joins (C : Type u) (P : Preorder C) where\n  pf : ∀ (a b : C), ∃ (j : C),\n    (P.leq a j) ∧ (P.leq b j) ∧ (∀ x : C, (P.leq a x) → (P.leq b x) → (P.leq j x))\n\nstructure meet (C : Type u) (P : Preorder C) (a b : C) where\n  m : C\n  lower_bound : (P.leq m a) ∧ (P.leq m b)\n  greatest: ∀ x : C, (P.leq x a) → (P.leq x b) → (P.leq x m)\n\nstructure has_all_meets (C : Type u) (P : Preorder C) where\n  pf : ∀ (a b : C), ∃ (m : C),\n    (P.leq m a ∧ P.leq m b) ∧ (∀ x : C, (P.leq x a) → (P.leq x b) → (P.leq x m))\n\n-- examples\n\ndef nat_meet (a b : Nat) : meet Nat NatPreorder a b := {\n  m := if a ≤ b then a else b\n  lower_bound := by\n    apply And.intro\n    case left =>\n      split\n      case inl h =>\n        apply Nat.le_refl\n      case inr h =>\n        rw [Nat.not_le_eq] at h\n        revert h\n        apply Nat.le_of_succ_le\n    case right =>\n      split\n      case inl h =>\n        exact h\n      case inr h =>\n        apply Nat.le_refl\n  greatest := by\n    intros x xle_a xle_b\n    split\n    case inl h =>\n      exact xle_a\n    case inr h =>\n      exact xle_b\n}\n\n#eval (nat_meet 5 6).m\n\ntheorem nat_all_meets : has_all_meets Nat NatPreorder := {\n  pf := by\n    intros a b\n    let m := nat_meet a b\n    exists m.m\n    apply And.intro\n    case left =>\n      exact m.lower_bound\n    case right =>\n      exact m.greatest\n}\n\n-- TODO: get rid of sorrys :(\ndef natmod4_meet (a b : Nat) : meet Nat NatMod4Preorder a b := {\n  m := if a ≤ b then a else b\n  lower_bound := by\n    apply And.intro\n    case left =>\n      split\n      case inl h =>\n        apply Nat.le_refl\n      case inr h =>\n        show b / 4 ≤ a / 4\n        rw [Nat.not_le_eq] at h\n        apply Nat.le_of_succ_le\n        rw [← Nat.succ_eq_add_one] at h\n        sorry\n    case right =>\n      split\n      case inl h =>\n        show a / 4 ≤ b / 4\n        sorry\n      case inr h =>\n        sorry\n  greatest := by\n    intros x xle_a xle_b\n    split\n    case inl h =>\n      exact xle_a\n    case inr h =>\n      exact xle_b\n}\n\ntheorem natmod4_all_meets : has_all_meets Nat NatMod4Preorder := {\n  pf := by\n    intros a b\n    let m := natmod4_meet a b\n    exists m.m\n    apply And.intro\n    case left =>\n      exact m.lower_bound\n    case right =>\n      exact m.greatest\n}\n\nend PreorderCats\n\n-- Category of Binary relations between types\nsection CatRel\n\ndef rel := Type u\n--instance : inhabited rel := by unfold rel;\n\ninstance Rel : Category (Type u) where\n  hom A B := A → B → Prop\n  id A := fun (a b : A) => a = b\n  comp := fun R S a c => ∃ b, R a b ∧ S b c\n  comp_assoc := by\n    simp\n    intro A B C D f g h\n    --have a : A. TODO: I think this proof requires that types are inhabited\n    sorry\n  l_unit := by\n    simp\n    intro A B f\n    sorry\n  r_unit := by\n    sorry \n\nend CatRel\n\n-- Heyting algebra of propositional provability \nsection IPL\n\ninductive prop where\n  | T : prop\n  | F : prop\n  | p_or : prop → prop → prop\n  | p_and : prop → prop → prop\n  | p_impl : prop → prop → prop\n\nopen prop\ndef Γ_t := List (prop × Bool)\nsection\nset_option hygiene false\nlocal notation:10 Γ \" ⊢ \" p \" : \" b => judgement Γ p b\n\ninductive judgement : Γ_t → prop → Bool → Prop where\n  | true_i : ∀ Γ : Γ_t, Γ ⊢ T : true\n  | and_i : ∀ (Γ : Γ_t) (A B : prop), \n      (Γ ⊢ A : true) → (Γ ⊢ B : true) → (Γ ⊢ (p_and A B) : true)\n  | and_e1 : ∀ (Γ : Γ_t) (A B : prop),\n      (Γ ⊢ (p_and A B) : true) → (Γ ⊢ A : true)\n  | and_e2 : ∀ (Γ : Γ_t) (A B : prop),\n      (Γ ⊢ (p_and A B) : true) → (Γ ⊢ B : true)\n  | impl_i : ∀ (Γ : Γ_t) (A B : prop),\n      ((A, true)::Γ ⊢ B : true) → (Γ ⊢ (p_impl A B) : true)\n  | impl_e : ∀ (Γ : Γ_t) (A B : prop),\n      (Γ ⊢ (p_impl A B) : true) → (Γ ⊢ A : true) → (Γ ⊢ B : true)\n  | false_e : ∀ (Γ : Γ_t) (A : prop), (Γ ⊢ F : true) → (Γ ⊢ A : true)\n  | or_i1 : ∀ (Γ : Γ_t) (A B : prop), (Γ ⊢ A : true) → (Γ ⊢ (p_or A B) : true)\n  | or_i2 : ∀ (Γ : Γ_t) (A B : prop), (Γ ⊢ B : true) → (Γ ⊢ (p_or A B) : true)\n  | or_e : ∀ (Γ : Γ_t) (A B C : prop),\n      (Γ ⊢ (p_or A B) : true) → \n      ((A, true)::Γ ⊢ C : true) → \n      ((B, true)::Γ ⊢ C : true) → (Γ ⊢ C : true)\n\n  -- structural rules\n  | entailment_refl : ∀ (Γ : Γ_t) (A : prop), (A, true)::Γ ⊢ A : true\n  --TODO: Use this more proper definition of transitivity (needs weakening to apply)\n  --| entailment_trans : ∀ (Γ₁ Γ₂ : Γ_t) (A B : prop),\n      --(Γ₁ ⊢ A : true) → ((A, true)::Γ₂ ⊢ B : true) → ((List.append Γ₁ Γ₂) ⊢ B : true)\n  | entailment_trans : ∀ (Γ : Γ_t) (A B C : prop),\n      ((A, true)::Γ ⊢ B : true) → ((B, true)::Γ ⊢ C : true) → ((A, true)::Γ ⊢ C : true)\n\nend\n\nnotation:10 Γ \" ⊢ \" p \" : \" b => judgement Γ p b\n\naxiom impl_inversion : ∀ (Γ : Γ_t) (A B : prop), \n  (Γ ⊢ (p_impl A B) : true) → ((A, true)::Γ ⊢ B : true)\n\ninstance : Preorder prop where\n  leq A B := ∀ Γ : Γ_t, Γ ⊢ (p_impl A B) : true\n  leq_ref := by\n    intro A Γ\n    apply judgement.impl_i\n    apply judgement.entailment_refl\n  leq_trans := by\n    intro A B C h1 h2 Γ\n    apply judgement.impl_i\n    let h1 := impl_inversion Γ A B (h1 Γ)\n    let h2 := impl_inversion Γ B C (h2 Γ)\n    apply judgement.entailment_trans Γ A B C h1 h2\n\nend IPL\n\nsection AlgCorrectness\n\ndef list_max (l : List Nat) : Nat := \n  List.foldl (fun (max el : Nat) => if max ≤ el then el else max) 0 l\n\n#eval list_max [5,7,12,2,4]\n\nend AlgCorrectness\n", "meta": {"author": "tylerhanks", "repo": "AwodeyCT", "sha": "ffa5f8f3d29fc44555e4bc483c1be2d08af4e387", "save_path": "github-repos/lean/tylerhanks-AwodeyCT", "path": "github-repos/lean/tylerhanks-AwodeyCT/AwodeyCT-ffa5f8f3d29fc44555e4bc483c1be2d08af4e387/AwodeyCT.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.768273414353928}}
{"text": "\ntheorem Eq.comm {α : Sort _} {a b : α} : a = b ↔ b = a := ⟨Eq.symm, Eq.symm⟩\n\ntheorem Or.assoc : p ∨ q ∨ r ↔ (p ∨ q) ∨ r :=\n  ⟨fun pq_r => Or.elim pq_r\n    (fun x => Or.inl (Or.inl x))\n    (fun qr => Or.elim qr\n      (fun x => Or.inl (Or.inr x))\n      (fun x => Or.inr x)),\n  fun pq_r => Or.elim pq_r\n    (fun pq => Or.elim pq\n      (fun x => Or.inl x)\n      (fun x => Or.inr (Or.inl x)))\n    (fun x => Or.inr (Or.inr x))⟩\n\ntheorem Or.comm : p ∨ q → q ∨ p := fun h => Or.elim h Or.inr Or.inl\n\ntheorem Or.comm' : p ∨ q ↔ q ∨ p := ⟨Or.comm, Or.comm⟩\n\ntheorem Or.left_comm (h : a ∨ (b ∨ c)) : b ∨ (a ∨ c) :=\n  Or.elim h (fun h => Or.inr (Or.inl h)) (Or.elim · Or.inl (fun h => Or.inr (Or.inr h)))\n\ntheorem Or.left_comm' : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) :=\n  ⟨Or.left_comm, Or.left_comm⟩\n\ntheorem And.assoc : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  ⟨fun ⟨⟨ha, hb⟩, hc⟩ => ⟨ha, ⟨hb, hc⟩⟩, fun ⟨ha, ⟨hb, hc⟩⟩ => ⟨⟨ha, hb⟩, hc⟩⟩\n\ntheorem And.comm : a ∧ b → b ∧ a := fun ⟨p, q⟩ => ⟨q, p⟩\n\ntheorem And.comm' : a ∧ b ↔ b ∧ a := ⟨And.comm, And.comm⟩\n\ntheorem And.left_comm : a ∧ (b ∧ c) → b ∧ (a ∧ c) :=\n  fun ⟨ha, hb, hc⟩ => ⟨hb, ha, hc⟩\n\ntheorem And.imp (hac : a → c) (hbd : b → d) (hab : a ∧ b) : c ∧ d :=\n  ⟨hac hab.left, hbd hab.right⟩\n\ntheorem And.imp_left (h : a → b) : a ∧ c → b ∧ c :=\n  And.imp h id\n\ntheorem And.imp_right (h : a → b) : c ∧ a → c ∧ b :=\n  And.imp id h\n\ntheorem Or.resolve_left {a b : Prop} (h : a ∨ b) (na : ¬ a) : b :=\n  Or.elim h (fun ha => absurd ha na) id\n\ntheorem Or.neg_resolve_left {a b : Prop} (h : ¬ a ∨ b) (ha : a) : b :=\n  Or.elim h (fun na => absurd ha na) id\n\ntheorem Or.resolve_right {a b : Prop} (h : a ∨ b) (nb : ¬ b) : a :=\n  Or.elim h id (fun hb => absurd hb nb)\n\ntheorem Or.neg_resolve_right {a b : Prop} (h : a ∨ ¬ b) (hb : b) : a :=\n  Or.elim h id (fun nb => absurd hb nb)\n\ntheorem Or.imp (h₂ : a → c) (h₃ : b → d) : a ∨ b → c ∨ d :=\n  Or.rec (fun h => Or.inl (h₂ h)) (fun h => Or.inr (h₃ h))\n\ntheorem Or.imp_left (h : a → b) : a ∨ c → b ∨ c :=\n  Or.imp h id\n\ntheorem Or.imp_right (h : a → b) : c ∨ a → c ∨ b :=\n  Or.imp id h\n\ntheorem Exists.imp {p q : α → Prop} (h : ∀ a, (p a → q a)) (p : ∃ a, p a) : ∃ a, q a :=\n  Exists.elim p (fun a hp => ⟨a, h a hp⟩)\n\ntheorem Iff.or (h₁ : a ↔ b) (h₂ : c ↔ d) : a ∨ c ↔ b ∨ d :=\n  ⟨fun h => Or.imp h₁.mp h₂.mp h, fun h => Or.imp h₁.mpr h₂.mpr h⟩\n\ntheorem Iff.and (h₁ : a ↔ b) (h₂ : c ↔ d) : a ∧ c ↔ b ∧ d :=\n  ⟨fun h => And.imp h₁.mp h₂.mp h, fun h => And.imp h₁.mpr h₂.mpr h⟩\n\nnamespace M4R\n\n  theorem and_or_distrib_left : a ∧ (b ∨ c) ↔ (a ∧ b) ∨ (a ∧ c) :=\n    ⟨fun ⟨ha, hbc⟩ => hbc.imp (And.intro ha ·) (And.intro ha ·),\n      Or.rec (And.imp_right Or.inl) (And.imp_right Or.inr)⟩\n\n  theorem or_and_distrib_right : (a ∨ b) ∧ c ↔ (a ∧ c) ∨ (b ∧ c) :=\n    (And.comm'.trans and_or_distrib_left).trans (And.comm'.or And.comm')\n\n  theorem or_and_distrib_left : a ∨ (b ∧ c) ↔ (a ∨ b) ∧ (a ∨ c) :=\n    ⟨Or.rec (fun ha => And.intro (Or.inl ha) (Or.inl ha)) (And.imp Or.inr Or.inr),\n    And.rec (Or.rec ((fun h _ => h) ∘ Or.inl) (Or.imp_right ∘ And.intro))⟩\n\n  theorem and_or_distrib_right : (a ∧ b) ∨ c ↔ (a ∨ c) ∧ (b ∨ c) :=\n    (Or.comm'.trans or_and_distrib_left).trans (Or.comm'.and Or.comm')\n\n  @[simp] theorem exists_imp_distrib {p : α → Prop} : ((∃ x, p x) → b) ↔ ∀ x, p x → b :=\n    ⟨fun h x hpx => h ⟨x, hpx⟩, fun h ⟨x, hpx⟩ => h x hpx⟩\n\n  theorem not_exists {p : α → Prop} : (¬ ∃ x, p x) ↔ ∀ x, ¬ p x :=\n    exists_imp_distrib\n\n  theorem and_imp : (a ∧ b → c) ↔ (a → b → c) :=\n    Iff.intro (fun h ha hb => h ⟨ha, hb⟩) (fun h ⟨ha, hb⟩ => h ha hb)\n\n  @[simp] theorem not_and : ¬ (a ∧ b) ↔ (a → ¬ b) := and_imp\n\n  theorem or_iff_right_of_imp (ha : a → b) : (a ∨ b) ↔ b :=\n    ⟨Or.rec ha id, Or.inr⟩\n\n  theorem or_iff_left_of_imp (hb : b → a) : (a ∨ b) ↔ a :=\n    ⟨Or.rec id hb, Or.inl⟩\n\n  open Classical\n\n  @[simp] theorem not_and_iff_or_not : ¬(p ∧ q) ↔ ¬p ∨ ¬q := Decidable.not_and_iff_or_not p q\n\n  @[simp] theorem not_or_iff_and_not : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n    ⟨fun h => ⟨fun ha => h (Or.inl ha), fun hb => h (Or.inr hb)⟩, fun ⟨h₁, h₂⟩ h => Or.elim h h₁ h₂⟩\n\n  theorem or_iff_not_imp_left : a ∨ b ↔ (¬ a → b) :=\n    ⟨Or.resolve_left, fun h => dite _ Or.inl (Or.inr ∘ h)⟩\n\n  theorem or_iff_not_imp_right : a ∨ b ↔ (¬ b → a) :=\n    Or.comm'.trans or_iff_not_imp_left\n\n  @[simp] theorem of_not_not : ¬ ¬ p → p := Decidable.of_not_not\n\n  theorem iff_not_not : ¬ ¬ p ↔ p := ⟨of_not_not, fun _ _ => by contradiction⟩\n\n  theorem not_imp_symm (h : ¬a → b) (hb : ¬b) : a := byContradiction (hb ∘ h)\n\n  theorem iff_not_comm : (a ↔ ¬ b) ↔ (b ↔ ¬ a) :=\n    ⟨fun h =>\n      ⟨fun hb ha => absurd hb (h.mp ha),\n      fun ha => of_not_not (mt h.mpr ha)⟩,\n    fun h =>\n      ⟨fun ha hb => absurd ha (h.mp hb),\n      fun hb => of_not_not (mt h.mpr hb)⟩⟩\n\n  theorem imp_not_comm : (a → ¬b) ↔ (b → ¬a) :=\n    ⟨fun h hb ha => absurd hb (h ha), fun h ha hb => absurd ha (h hb)⟩\n\n  theorem not_forall {p : α → Prop} : (¬ ∀ x, p x) ↔ ∃ x, ¬ p x :=\n    ⟨by apply not_imp_symm; intro nE x; apply not_imp_symm _ nE; exact fun h => ⟨x, h⟩,\n    fun ⟨x, hn⟩ hA => hn (hA x)⟩\n\n  @[simp] theorem not_iff_not : (¬p ↔ ¬q) ↔ (p ↔ q) :=\n    have h : ∀ p q, (p ↔ q) → (¬ p ↔ ¬ q) := fun p q h => ⟨mt h.mpr, mt h.mp⟩\n    ⟨by\n      have := h (¬p) (¬q)\n      simp only [iff_not_not] at this\n      exact this, h p q⟩\n\n  theorem iff_of_true (ha : a) (hb : b) : a ↔ b :=\n    ⟨fun _ => hb, fun _ => ha⟩\n\n  theorem iff_of_false (ha : ¬a) (hb : ¬b) : a ↔ b :=\n    ⟨fun h => absurd h ha, fun h => absurd h hb⟩\n\n  theorem eq_self_iff_true (a : α) : a = a ↔ True :=\n    ⟨fun _ => trivial, fun _ => rfl⟩\n\n  theorem forall_true_iff : α → True ↔ True :=\n    ⟨fun _ => trivial, fun _ _ => trivial⟩\n\n  theorem forall_true_iff' {p : α → Prop} (h : ∀ a, p a ↔ True) : (∀ a, p a) ↔ True :=\n    ⟨fun _ => trivial, fun t a => (h a).mpr t⟩\n\n  @[simp] theorem forall_2_true_iff {β : α → Sort _} : (∀ a, β a → True) ↔ True :=\n    forall_true_iff' fun _ => forall_true_iff\n\n  @[simp] theorem forall_3_true_iff {β : α → Sort _} {γ : ∀ a, β a → Sort _} :\n    (∀ (a : α) (b : β a), γ a b → True) ↔ True :=\n      forall_true_iff' fun _ => forall_2_true_iff\n\n  @[simp] theorem not_and_self (a : Prop) : (¬a ∧ a) ↔ False :=\n    ⟨fun h => h.left h.right, fun h => False.rec (fun _ => ¬a ∧ a) h⟩\n\n  @[simp] theorem and_not_self (a : Prop) : (a ∧ ¬a) ↔ False := by\n    rw [And.comm']; exact not_and_self a\n\n  @[simp] theorem and_self (a : Prop) : a ∧ a ↔ a :=\n    ⟨And.left, fun h => ⟨h, h⟩⟩\n\n  theorem funext_iff {β : α → Sort _} {f₁ f₂ : ∀ (x : α), β x} : (∀ x, f₁ x = f₂ x) ↔ f₁ = f₂ :=\n    ⟨funext, congrFun⟩\n\n  theorem propext_iff {a b : Prop} : (a ↔ b) ↔ a = b :=\n    ⟨propext, fun h => h ▸ Iff.rfl⟩\n\n  theorem forall_congr' {p q : α → Prop} (h : ∀ a, p a ↔ q a) : (∀ a, p a) ↔ (∀ a, q a) :=\n    propext_iff.mpr (forall_congr fun a => propext (h a))\n\nend M4R\n\n@[simp] theorem Quotient.eq [r : Setoid α] {x y : α} : Quotient.mk x = Quotient.mk y ↔ x ≈ y :=\n  ⟨Quotient.exact, Quotient.sound⟩\n\n@[simp] protected theorem Subtype.exists {p : α → Prop} {q : {a // p a} → Prop} : (∃ x, q x) ↔ (∃ a b, q ⟨a, b⟩) :=\n  ⟨fun ⟨⟨a, b⟩, h⟩ => ⟨a, b, h⟩, fun ⟨a, b, h⟩ => ⟨⟨a, b⟩, h⟩⟩\n\ndef Option.guard (p : α → Prop) [DecidablePred p] (a : α) : Option α :=\n  if p a then some a else none\n", "meta": {"author": "Hop311", "repo": "M4R", "sha": "ebd1b04af344f9737d290bf8b48b3cde35e9787b", "save_path": "github-repos/lean/Hop311-M4R", "path": "github-repos/lean/Hop311-M4R/M4R-ebd1b04af344f9737d290bf8b48b3cde35e9787b/M4R/Logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.768273412519176}}
{"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 data.nat.prime\nimport data.finsupp.multiset\nimport algebra.big_operators.finsupp\nimport tactic.linarith\nimport tactic.interval_cases\n\n/-!\n# Prime factorizations\n\n `n.factorization` is the finitely supported function `ℕ →₀ ℕ`\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 : ℕ`.\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 `ℕ →₀ ℕ`\n mapping each prime factor of `n` to its multiplicity in `n`. -/\nnoncomputable def factorization (n : ℕ) : ℕ →₀ ℕ := (n.factors : multiset ℕ).to_finsupp\n\n/-! ### Basic facts about factorization -/\n\n@[simp] lemma factorization_prod_pow_eq_self {n : ℕ} (hn : n ≠ 0) : n.factorization.prod pow = n :=\nbegin\n  simp only [←prod_to_multiset, factorization, multiset.coe_prod, multiset.to_finsupp_to_multiset],\n  exact prod_factors hn,\nend\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.\nHowever, since `factorization` is a finsupp it's noncomputable.  This theorem can also\nbe used in reverse to compute values of `factorization n p` when required. -/\n@[simp] lemma factors_count_eq {n p : ℕ} : n.factors.count p = n.factorization p :=\nby simp [factorization]\n\nlemma eq_of_factorization_eq {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0)\n  (h : ∀ p : ℕ, 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 : ℕ | x ≠ 0 } :=\nλ a ha b hb h, eq_of_factorization_eq ha hb (λ p, by simp [h])\n\n@[simp] lemma factorization_zero : factorization 0 = 0 :=\nby simp [factorization]\n\n@[simp] lemma factorization_one : factorization 1 = 0 :=\nby simp [factorization]\n\n/-- The support of `n.factorization` is exactly `n.factors.to_finset` -/\n@[simp] lemma support_factorization {n : ℕ} : n.factorization.support = n.factors.to_finset :=\nby simpa [factorization, multiset.to_finsupp_support]\n\nlemma factor_iff_mem_factorization {n p : ℕ} : p ∈ n.factorization.support ↔ p ∈ n.factors :=\nby simp only [support_factorization, list.mem_to_finset]\n\nlemma prime_of_mem_factorization {n p : ℕ} (hp : p ∈ n.factorization.support) : p.prime :=\nprime_of_mem_factors (factor_iff_mem_factorization.mp hp)\n\nlemma pos_of_mem_factorization {n p : ℕ} (hp : p ∈ n.factorization.support) : 0 < p :=\nprime.pos (prime_of_mem_factorization hp)\n\nlemma le_of_mem_factorization {n p : ℕ} (h : p ∈ n.factorization.support) : p ≤ n :=\nle_of_mem_factors (factor_iff_mem_factorization.mp h)\n\nlemma factorization_eq_zero_of_non_prime (n p : ℕ) (hp : ¬p.prime) : n.factorization p = 0 :=\nnot_mem_support_iff.1 (mt prime_of_mem_factorization hp)\n\nlemma prime.factorization_pos_of_dvd {n p : ℕ} (hp : p.prime) (hn : n ≠ 0) (h : p ∣ n) :\n  0 < n.factorization p :=\nby rwa [←factors_count_eq, count_pos, mem_factors_iff_dvd hn hp]\n\n/-- The only numbers with empty prime factorization are `0` and `1` -/\nlemma factorization_eq_zero_iff (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 :=\nby simp [factorization, add_equiv.map_eq_zero_iff, multiset.coe_eq_zero]\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 : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :\n  (a * b).factorization = a.factorization + b.factorization :=\nby { ext p, simp only [add_apply, ←factors_count_eq,\n                       perm_iff_count.mp (perm_factors_mul ha hb) p, count_append] }\n\nlemma factorization_mul_support {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :\n  (a * b).factorization.support = a.factorization.support ∪ 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/-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/\n@[simp] lemma factorization_pow (n k : ℕ) :\n  factorization (n^k) = k • 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/-- The only prime factor of prime `p` is `p` itself, with multiplicity `1` -/\n@[simp] lemma prime.factorization {p : ℕ} (hp : prime p) :\n  p.factorization = single p 1 :=\nbegin\n  ext q,\n  rw [←factors_count_eq, factors_prime hp, single_apply, count_singleton', if_congr eq_comm];\n  refl,\nend\n\n/-- For prime `p` the only prime factor of `p^k` is `p` with multiplicity `k` -/\nlemma prime.factorization_pow {p k : ℕ} (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 : ℕ} (hn : n ≠ 0)\n  (h : n.factorization = finsupp.single p k) : n = p ^ k :=\nby { rw [←nat.factorization_prod_pow_eq_self hn, h], simp }\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 : ℕ} {β : Type*} [comm_monoid β] (f : ℕ → β) :\n  n.factorization.prod (λ p k, f p) = ∏ p in n.factors.to_finset, (f p) :=\nby { apply prod_congr support_factorization, simp }\n\n/-- For any `p : ℕ` and any function `g : α → ℕ` that's non-zero on `S : finset α`,\nthe power of `p` in `S.prod g` equals the sum over `x ∈ 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 {α : Type*} {S : finset α} {g : α → ℕ} (hS : ∀ x ∈ S, g x ≠ 0) :\n  (S.prod g).factorization = S.sum (λ 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 ≠ 0 := prod_ne_zero_iff.mpr (λ x hx, hS x (hTS hx)),\n    simp [prod_insert hxT, sum_insert hxT, ←IH, factorization_mul (hS x hxS) hT] }\nend\n\n/-! ### Equivalence between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/\n\n/-- Any finsupp `f : ℕ →₀ ℕ` whose support is in the primes is equal to the factorization of\nthe product `∏ (a : ℕ) in f.support, a ^ f a`. -/\nlemma prod_pow_factorization_eq_self {f : ℕ →₀ ℕ} (hf : ∀ (p : ℕ), p ∈ f.support → prime p) :\n  (f.prod pow).factorization = f :=\nbegin\n  have h : ∀ x : ℕ, x ∈ f.support → x ^ f x ≠ 0 := λ 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 (λ p hp, prime.factorization_pow (hf p hp)),\nend\n\nlemma eq_factorization_iff {n : ℕ} {f : ℕ →₀ ℕ} (hn : n ≠ 0) (hf : ∀ p ∈ f.support, prime p) :\n  f = n.factorization ↔ f.prod pow = n :=\n⟨λ h, by rw [h, factorization_prod_pow_eq_self hn],\n λ h, by rw [←h, prod_pow_factorization_eq_self hf]⟩\n\n/-- The equiv between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/\nnoncomputable\ndef factorization_equiv : ℕ+ ≃ {f : ℕ →₀ ℕ | ∀ p ∈ f.support, prime p} :=\n{ to_fun    := λ ⟨n, hn⟩, ⟨n.factorization, λ _, prime_of_mem_factorization⟩,\n  inv_fun   := λ ⟨f, hf⟩, ⟨f.prod pow,\n    prod_pow_pos_of_zero_not_mem_support (λ H, not_prime_zero (hf 0 H))⟩,\n  left_inv  := λ ⟨x, hx⟩, subtype.ext $ factorization_prod_pow_eq_self hx.ne.symm,\n  right_inv := λ ⟨f, hf⟩, subtype.ext $ prod_pow_factorization_eq_self hf }\n\nlemma factorization_equiv_apply (n : ℕ+) : (factorization_equiv n).1 = n.1.factorization :=\nby { cases n, refl }\n\nlemma factorization_equiv_inv_apply {f : ℕ →₀ ℕ} (hf : ∀ p ∈ f.support, prime p) :\n  (factorization_equiv.symm ⟨f, hf⟩).1 = f.prod pow := rfl\n\n/-! ### Factorization and divisibility -/\n\nlemma dvd_of_mem_factorization {n p : ℕ} (h : p ∈ n.factorization.support) : p ∣ n :=\nbegin\n  rcases eq_or_ne n 0 with rfl | hn, { simp },\n  simp [←mem_factors_iff_dvd hn (prime_of_mem_factorization h), factor_iff_mem_factorization.mp h],\nend\n\nlemma pow_factorization_dvd (n p : ℕ) : p ^ n.factorization p ∣ n :=\nbegin\n  by_cases hp : p.prime, swap, { simp [factorization_eq_zero_of_non_prime n p hp] },\n  rw ←factors_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_repeat hq],\nend\n\nlemma pow_succ_factorization_not_dvd {n p : ℕ} (hn : n ≠ 0) (hp : p.prime) :\n  ¬ p ^ (n.factorization p + 1) ∣ n :=\nbegin\n  intro h,\n  have := factors_sublist_of_dvd h hn,\n  rw [hp.factors_pow, ←le_count_iff_repeat_sublist, factors_count_eq] at this,\n  linarith\nend\n\nlemma factorization_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :\n  d.factorization ≤ n.factorization ↔ d ∣ n :=\nbegin\n  split,\n  { intro hdn,\n    set K := n.factorization - d.factorization with hK,\n    use K.prod pow,\n    rw [←factorization_prod_pow_eq_self hn, ←factorization_prod_pow_eq_self hd,\n        ←finsupp.prod_add_index' pow_zero pow_add, hK, add_tsub_cancel_of_le hdn] },\n  { rintro ⟨c, rfl⟩, rw factorization_mul hd (right_ne_zero_of_mul hn), simp },\nend\n\nlemma factorization_le_factorization_mul_left {a b : ℕ} (hb : b ≠ 0) :\n  a.factorization ≤ (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 : ℕ} (ha : a ≠ 0) :\n  b.factorization ≤ (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 : ℕ} (pp : prime p) (hn : n ≠ 0) :\n  p ^ k ∣ n ↔ k ≤ n.factorization p :=\nby rw [←factorization_le_iff_dvd (pow_pos pp.pos k).ne' hn, pp.factorization_pow, single_le_iff]\n\nlemma prime.pow_dvd_iff_dvd_pow_factorization {p k n : ℕ} (pp : prime p) (hn : n ≠ 0) :\n  p ^ k ∣ n ↔ p ^ k ∣ p ^ n.factorization p :=\nby rw [pow_dvd_pow_iff_le_right pp.one_lt, pp.pow_dvd_iff_le_factorization hn]\n\nlemma exists_factorization_lt_of_lt {a b : ℕ} (ha : a ≠ 0) (hab : a < b) :\n  ∃ p : ℕ, a.factorization p < b.factorization p :=\nbegin\n  have hb : b ≠ 0 := (ha.bot_lt.trans hab).ne',\n  contrapose! hab,\n  rw [←finsupp.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 : ℕ} (h : d ∣ 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      ←nat.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_iff_div_factorization_eq_tsub (d n : ℕ) (hd : d ≠ 0) (hdn : d ≤ n) :\n  d ∣ n ↔ (n / d).factorization = n.factorization - d.factorization :=\nbegin\n  refine ⟨factorization_div, _⟩,\n  rcases eq_or_lt_of_le hdn with rfl | hd_lt_n, { simp },\n  have h1 : n / d ≠ 0 := λ 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, ←lt_tsub_iff_right, h, tsub_apply,\n    lt_self_iff_false] at hp\nend\n\nlemma dvd_iff_prime_pow_dvd_dvd {n d : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :\n  d ∣ n ↔ ∀ p k : ℕ, prime p → p ^ k ∣ d → p ^ k ∣ n :=\nbegin\n  refine ⟨λ h p k _ hpkd, dvd_trans hpkd h, _⟩,\n  rw [←factorization_le_iff_dvd hd hn, finsupp.le_def],\n  intros h p,\n  by_cases pp : prime p, swap, { simp [factorization_eq_zero_of_non_prime d p pp] },\n  rw ←pp.pow_dvd_iff_le_factorization hn,\n  exact h p _ pp (pow_factorization_dvd _ _)\nend\n\nlemma prod_prime_factors_dvd (n : ℕ) : (∏ (p : ℕ) in n.factors.to_finset, p) ∣ 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 ℕ),\nend\n\nlemma factorization_gcd {a b : ℕ} (ha_pos : a ≠ 0) (hb_pos : b ≠ 0) :\n  (gcd a b).factorization = a.factorization ⊓ b.factorization :=\nbegin\n  let dfac := a.factorization ⊓ b.factorization,\n  let d := dfac.prod pow,\n  have dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → prime p,\n  { intros p hp,\n    have : p ∈ a.factors ∧ p ∈ 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 ≠ 0 := (factorization_equiv.inv_fun ⟨dfac, dfac_prime⟩).2.ne.symm,\n  suffices : d = (gcd a b), { rwa ←this },\n  apply gcd_greatest,\n  { rw [←factorization_le_iff_dvd hd_pos ha_pos, h1], exact inf_le_left },\n  { rw [←factorization_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 [←factorization_le_iff_dvd he_pos hd_pos, h1, hea', heb'] },\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 : ℕ} (hab : coprime a b)  :\n  (a * b).factorization p = a.factorization p + b.factorization p :=\nby simp only [←factors_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 : ℕ} (hab : coprime a b) :\n  (a * b).factorization = a.factorization + b.factorization :=\nbegin\n  ext q,\n  simp only [finsupp.coe_add, add_apply, ←factors_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 : ℕ} (hab : coprime a b) (hpa : p ∈ a.factors) :\n  (a * b).factorization p = a.factorization p :=\nbegin\n  rw [factorization_mul_apply_of_coprime hab, ←factors_count_eq, ←factors_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 : ℕ} (hab : coprime a b) (hpb : p ∈ 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 : ℕ} (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 : ℕ} (hab : coprime a b) :\n  (a * b).factorization.support = a.factorization.support ∪ 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 : ℕ → Sort*} (h0 : P 0) (h1 : P 1)\n  (h : ∀ a p n : ℕ, p.prime → ¬ p ∣ a → 0 < n → P a → P (p ^ n * a)) : ∀ (a : ℕ), P a :=\nλ a, nat.strong_rec_on a $ λ n,\n  match n with\n  | 0     := λ _, h0\n  | 1     := λ _, h1\n  | (k+2) := λ 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 ∣ k + 2 := by { rw ht, exact pow_factorization_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, ←pow_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 : ℕ → Sort*} (hp : ∀ p n : ℕ, prime p → 0 < n → P (p ^ n))\n  (h0 : P 0) (h1 : P 1) (h : ∀ a b, 1 < a → 1 < b → coprime a b → P a → P b → P (a * b)) :\n  ∀ 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 (prime.one_lt hp').le (succ_le_iff.mpr hn)))\n    _ _ (hp _ _ hp' hn) hPa,\n  { refine lt_of_not_ge (λ (h : a ≤ 1), _),\n    interval_cases a,\n    { simpa only [dvd_zero, not_true] using hpa },\n    { contradiction } },\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 : ℕ → Sort*} (h0 : P 0) (hp : ∀ p n : ℕ, prime p → P (p ^ n))\n  (h : ∀ a b, 1 < a → 1 < b → coprime a b → P a → P b → P (a * b)) : ∀ a, P a :=\nrec_on_pos_prime_pos_coprime (λ 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 : ℕ → Sort*} (h0 : P 0) (h1 : P 1)\n  (hp : ∀ p, prime p → P p) (h : ∀ a b, P a → P b → P (a * b)) : ∀ a, P a :=\nlet hp : ∀ p n : ℕ, prime p → P (p ^ n) :=\n  λ 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 $ λ a b _ _ _, h a b\n\n/-- For any multiplicative function `f` with `f 1 = 1` and any `n ≠ 0`,\nwe can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/\nlemma multiplicative_factorization {β : Type*} [comm_monoid β] (f : ℕ → β)\n  (h_mult : ∀ x y : ℕ, coprime x y → f (x * y) = f x * f y) (hf : f 1 = 1) :\n  ∀ {n : ℕ}, n ≠ 0 → f n = n.factorization.prod (λ 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, ←prod_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' {β : Type*} [comm_monoid β] (f : ℕ → β)\n  (h_mult : ∀ x y : ℕ, coprime x y → f (x * y) = f x * f y) (hf0 : f 0 = 1) (hf1 : f 1 = 1) :\n  ∀ {n : ℕ}, f n = n.factorization.prod (λ 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, ←prod_add_index_of_disjoint],\n    convert (factorization_disjoint_of_coprime hab) },\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/factorization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7682734087359678}}
{"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-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.logic\n\nuniverses u \n\nnamespace Mathlib\n\nnamespace nat\n\n\nnotation:1024 \"ℕ\" => Mathlib.nat\n\ninductive less_than_or_equal (a : ℕ) : ℕ → Prop where\n| refl : less_than_or_equal a a\n| step : ∀ {b : ℕ}, less_than_or_equal a b → less_than_or_equal a (Nat.succ b)\n\nprotected instance has_le : HasLessEq ℕ := { LessEq := less_than_or_equal }\n\nprotected def le (n : ℕ) (m : ℕ) := less_than_or_equal n m\n\nprotected def lt (n : ℕ) (m : ℕ) := less_than_or_equal (Nat.succ n) m\n\nprotected instance has_lt : HasLess ℕ := { Less := nat.lt }\n\ndef pred : ℕ → ℕ := Nat.pred\n\nprotected def sub : ℕ → ℕ → ℕ := Nat.sub\n\nprotected def mul : ℕ → ℕ → ℕ := Nat.mul\n\nprotected instance has_sub : Sub ℕ := { sub := Nat.sub }\n\nprotected instance has_mul : Mul ℕ := { mul := Nat.mul }\n\n-- defeq to the instance provided by comm_semiring\n\nprotected instance has_dvd : has_dvd ℕ := has_dvd.mk fun (a b : ℕ) => ∃ (c : ℕ), b = a * c\n\nprotected instance decidable_eq : DecidableEq ℕ := sorry\n\ndef repeat {α : Type u} (f : ℕ → α → α) : ℕ → α → α := sorry\n\nprotected instance inhabited : Inhabited ℕ := { default := 0 }\n\n@[simp] theorem nat_zero_eq_zero : 0 = 0 := rfl\n\n/- properties of inequality -/\n\nprotected def le_refl (a : ℕ) : a ≤ a := less_than_or_equal.refl\n\ntheorem le_succ (n : ℕ) : n ≤ Nat.succ n := less_than_or_equal.step (nat.le_refl n)\n\ntheorem succ_le_succ {n : ℕ} {m : ℕ} : n ≤ m → Nat.succ n ≤ Nat.succ m :=\n  fun (h : n ≤ m) =>\n    less_than_or_equal._oldrec (nat.le_refl (Nat.succ n))\n      (fun (a : ℕ) (b : less_than_or_equal n a) => less_than_or_equal.step) h\n\ntheorem zero_le (n : ℕ) : 0 ≤ n := sorry\n\ntheorem zero_lt_succ (n : ℕ) : 0 < Nat.succ n := succ_le_succ (zero_le n)\n\ndef succ_pos (n : ℕ) : 0 < Nat.succ n := zero_lt_succ\n\ntheorem not_succ_le_zero (n : ℕ) : Nat.succ n ≤ 0 → False := sorry\n\ntheorem not_lt_zero (a : ℕ) : ¬a < 0 := not_succ_le_zero a\n\ntheorem pred_le_pred {n : ℕ} {m : ℕ} : n ≤ m → Nat.pred n ≤ Nat.pred m := sorry\n\ntheorem le_of_succ_le_succ {n : ℕ} {m : ℕ} : Nat.succ n ≤ Nat.succ m → n ≤ m := pred_le_pred\n\nprotected instance decidable_le (a : ℕ) (b : ℕ) : Decidable (a ≤ b) := sorry\n\nprotected instance decidable_lt (a : ℕ) (b : ℕ) : Decidable (a < b) :=\n  nat.decidable_le (Nat.succ a) b\n\nprotected theorem eq_or_lt_of_le {a : ℕ} {b : ℕ} (h : a ≤ b) : a = b ∨ a < b :=\n  less_than_or_equal.cases_on h (Or.inl rfl)\n    fun (n : ℕ) (h : less_than_or_equal a n) => Or.inr (succ_le_succ h)\n\ntheorem lt_succ_of_le {a : ℕ} {b : ℕ} : a ≤ b → a < Nat.succ b := succ_le_succ\n\n@[simp] theorem succ_sub_succ_eq_sub (a : ℕ) (b : ℕ) : Nat.succ a - Nat.succ b = a - b :=\n  nat.rec_on b ((fun (this : Nat.succ a - 1 = a - 0) => this) (Eq.refl (Nat.succ a - 1)))\n    fun (b : ℕ) => congr_arg Nat.pred\n\ntheorem not_succ_le_self (n : ℕ) : ¬Nat.succ n ≤ n :=\n  Nat.rec (not_succ_le_zero 0)\n    (fun (a : ℕ) (b : ¬Nat.succ a ≤ a) (c : Nat.succ (Nat.succ a) ≤ Nat.succ a) =>\n      b (le_of_succ_le_succ c))\n    n\n\nprotected theorem lt_irrefl (n : ℕ) : ¬n < n := not_succ_le_self n\n\nprotected theorem le_trans {n : ℕ} {m : ℕ} {k : ℕ} (h1 : n ≤ m) : m ≤ k → n ≤ k :=\n  less_than_or_equal._oldrec h1 fun (p : ℕ) (h2 : less_than_or_equal m p) => less_than_or_equal.step\n\ntheorem pred_le (n : ℕ) : Nat.pred n ≤ n :=\n  nat.cases_on n (idRhs (less_than_or_equal (Nat.pred 0) (Nat.pred 0)) less_than_or_equal.refl)\n    fun (n : ℕ) =>\n      idRhs (less_than_or_equal (Nat.pred (Nat.succ n)) (Nat.succ n))\n        (less_than_or_equal.step less_than_or_equal.refl)\n\ntheorem pred_lt {n : ℕ} : n ≠ 0 → Nat.pred n < n := sorry\n\ntheorem sub_le (a : ℕ) (b : ℕ) : a - b ≤ a :=\n  nat.rec_on b (nat.le_refl (a - 0)) fun (b₁ : ℕ) => nat.le_trans (pred_le (a - b₁))\n\ntheorem sub_lt {a : ℕ} {b : ℕ} : 0 < a → 0 < b → a - b < a := sorry\n\nprotected theorem lt_of_lt_of_le {n : ℕ} {m : ℕ} {k : ℕ} : n < m → m ≤ k → n < k := nat.le_trans\n\n/- Basic nat.add lemmas -/\n\nprotected theorem zero_add (n : ℕ) : 0 + n = n := sorry\n\ntheorem succ_add (n : ℕ) (m : ℕ) : Nat.succ n + m = Nat.succ (n + m) := sorry\n\ntheorem add_succ (n : ℕ) (m : ℕ) : n + Nat.succ m = Nat.succ (n + m) := rfl\n\nprotected theorem add_zero (n : ℕ) : n + 0 = n := rfl\n\ntheorem add_one (n : ℕ) : n + 1 = Nat.succ n := rfl\n\ntheorem succ_eq_add_one (n : ℕ) : Nat.succ n = n + 1 := rfl\n\n/- Basic lemmas for comparing numerals -/\n\nprotected theorem bit0_succ_eq (n : ℕ) : bit0 (Nat.succ n) = Nat.succ (Nat.succ (bit0 n)) :=\n  (fun (this : Nat.succ (Nat.succ n + n) = Nat.succ (Nat.succ (n + n))) => this)\n    (congr_arg Nat.succ (succ_add n n))\n\nprotected theorem zero_lt_bit0 {n : ℕ} : n ≠ 0 → 0 < bit0 n := sorry\n\nprotected theorem zero_lt_bit1 (n : ℕ) : 0 < bit1 n := zero_lt_succ (bit0 n)\n\nprotected theorem bit0_ne_zero {n : ℕ} : n ≠ 0 → bit0 n ≠ 0 := sorry\n\nprotected theorem bit1_ne_zero (n : ℕ) : bit1 n ≠ 0 :=\n  (fun (this : Nat.succ (n + n) ≠ 0) => this) fun (h : Nat.succ (n + n) = 0) => nat.no_confusion h\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/Lean3Lib/init/data/nat/basic_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7682734074697347}}
{"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 data.finite.card\nimport group_theory.finiteness\nimport group_theory.group_action.quotient\n\n/-!\n# Index of a Subgroup\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 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 ∣ fintype.card G`\n- `index_eq_mul_of_le` : If `H ≤ K`, then `H.index = K.index * (H.subgroup_of K).index`\n- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ H.index`\n- `relindex_mul_relindex` : `relindex` is multiplicative in towers\n\n-/\n\nnamespace subgroup\n\nopen_locale big_operators 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 : ℕ :=\nnat.card (G ⧸ 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 : ℕ :=\n(H.subgroup_of K).index\n\n@[to_additive] lemma index_comap_of_surjective {G' : Type*} [group G'] {f : G' →* 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 : ∀ x y : G', setoid.r x y ↔ setoid.r (f x) (f y),\n  { simp only [quotient_group.left_rel_apply],\n    exact λ x y, iff_of_eq (congr_arg (∈ H) (by rw [f.map_mul, f.map_inv])) },\n  refine cardinal.to_nat_congr (equiv.of_bijective (quotient.map' f (λ x y, (key x y).mp)) ⟨_, _⟩),\n  { simp_rw [←quotient.eq'] at key,\n    refine quotient.ind' (λ x, _),\n    refine quotient.ind' (λ y, _),\n    exact (key x y).mpr },\n  { refine quotient.ind' (λ x, _),\n    obtain ⟨y, hy⟩ := hf x,\n    exact ⟨y, (quotient.map'_mk' f _ y).trans (congr_arg quotient.mk' hy)⟩ },\nend\n\n@[to_additive] lemma index_comap {G' : Type*} [group G'] (f : G' →* 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\n@[to_additive] lemma relindex_comap {G' : Type*} [group G'] (f : G' →* G) (K : subgroup G') :\n  relindex (comap f H) K = relindex H (map f K) :=\nby rw [relindex, subgroup_of, comap_comap, index_comap, ← f.map_range, K.subtype_range]\n\nvariables {H K L}\n\n@[to_additive relindex_mul_index] lemma relindex_mul_index (h : H ≤ K) :\n  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 ≤ K) : K.index ∣ H.index :=\ndvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)\n\n@[to_additive] lemma relindex_dvd_index_of_le (h : H ≤ K) : H.relindex K ∣ H.index :=\ndvd_of_mul_right_eq K.index (relindex_mul_index h)\n\n@[to_additive] lemma relindex_subgroup_of (hKL : K ≤ 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\nvariables (H K L)\n\n@[to_additive relindex_mul_relindex] lemma relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) :\n  H.relindex K * K.relindex L = H.relindex L :=\nbegin\n  rw [←relindex_subgroup_of hKL],\n  exact relindex_mul_index (λ x hx, hHK hx),\nend\n\n@[to_additive] lemma inf_relindex_right : (H ⊓ K).relindex K = H.relindex K :=\nby rw [relindex, relindex, inf_subgroup_of_right]\n\n@[to_additive] lemma inf_relindex_left : (H ⊓ K).relindex H = K.relindex H :=\nby rw [inf_comm, inf_relindex_right]\n\n@[to_additive relindex_inf_mul_relindex]\nlemma relindex_inf_mul_relindex : H.relindex (K ⊓ L) * K.relindex L = (H ⊓ K).relindex L :=\nby rw [←inf_relindex_right H (K ⊓ L), ←inf_relindex_right K L, ←inf_relindex_right (H ⊓ K) L,\n  inf_assoc, relindex_mul_relindex (H ⊓ (K ⊓ L)) (K ⊓ L) L inf_le_right inf_le_right]\n\n@[simp, to_additive]\nlemma relindex_sup_right [K.normal] : K.relindex (H ⊔ K) = K.relindex H  :=\nnat.card_congr (quotient_group.quotient_inf_equiv_prod_normal_quotient H K).to_equiv.symm\n\n@[simp, to_additive]\nlemma relindex_sup_left [K.normal] : K.relindex (K ⊔ H) = K.relindex H  :=\nby rw [sup_comm, relindex_sup_right]\n\n@[to_additive] lemma relindex_dvd_index_of_normal [H.normal] : H.relindex K ∣ H.index :=\nrelindex_sup_right K H ▸ relindex_dvd_index_of_le le_sup_right\n\nvariables {H K}\n\n@[to_additive] lemma relindex_dvd_of_le_left (hHK : H ≤ K) : K.relindex L ∣ H.relindex L :=\ninf_of_le_left hHK ▸ dvd_of_mul_left_eq _ (relindex_inf_mul_relindex _ _ _)\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 for\nall `b`, exactly one of `b + a` and `b` belong to `H`. -/\"]\nlemma index_eq_two_iff : H.index = 2 ↔ ∃ a, ∀ b, xor (b * a ∈ H) (b ∈ H) :=\nbegin\n  simp only [index, nat.card_eq_two_iff' ((1 : G) : G ⧸ H), exists_unique, inv_mem_iff,\n    quotient_group.exists_coe, quotient_group.forall_coe, ne.def, quotient_group.eq, mul_one,\n    xor_iff_iff_not],\n  refine exists_congr (λ a, ⟨λ ha b, ⟨λ hba hb, _, λ hb, _⟩, λ ha, ⟨_, λ b hb, _⟩⟩),\n  { exact ha.1 ((mul_mem_cancel_left hb).1 hba) },\n  { exact inv_inv b ▸ ha.2 _ (mt inv_mem_iff.1 hb) },\n  { rw [← inv_mem_iff, ← ha, inv_mul_self], exact one_mem _ },\n  { rwa [ha, inv_mem_iff] }\nend\n\n@[to_additive] lemma mul_mem_iff_of_index_two (h : H.index = 2) {a b : G} :\n  a * b ∈ H ↔ (a ∈ H ↔ b ∈ H) :=\nbegin\n  by_cases ha : a ∈ H, { simp only [ha, true_iff, mul_mem_cancel_left ha] },\n  by_cases hb : b ∈ H, { simp only [hb, iff_true, mul_mem_cancel_right hb] },\n  simp only [ha, hb, iff_self, iff_true],\n  rcases index_eq_two_iff.1 h with ⟨c, hc⟩,\n  refine (hc _).or.resolve_left _,\n  rwa [mul_assoc, mul_mem_cancel_right ((hc _).or.resolve_right hb)]\nend\n\n@[to_additive] lemma mul_self_mem_of_index_two (h : H.index = 2) (a : G) : a * a ∈ H :=\nby rw [mul_mem_iff_of_index_two h]\n\n@[to_additive two_smul_mem_of_index_two]\nlemma sq_mem_of_index_two (h : H.index = 2) (a : G) : a ^ 2 ∈ H :=\n(pow_two a).symm ▸ mul_self_mem_of_index_two h a\n\nvariables (H K)\n\n@[simp, to_additive] lemma index_top : (⊤ : subgroup G).index = 1 :=\ncardinal.to_nat_eq_one_iff_unique.mpr ⟨quotient_group.subsingleton_quotient_top, ⟨1⟩⟩\n\n@[simp, to_additive] lemma index_bot : (⊥ : 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] : (⊥ : subgroup G).index = fintype.card G :=\nindex_bot.trans nat.card_eq_fintype_card\n\n@[simp, to_additive] lemma relindex_top_left : (⊤ : subgroup G).relindex H = 1 :=\nindex_top\n\n@[simp, to_additive] lemma relindex_top_right : H.relindex ⊤ = H.index :=\nby rw [←relindex_mul_index (show H ≤ ⊤, from le_top), index_top, mul_one]\n\n@[simp, to_additive] lemma relindex_bot_left : (⊥ : 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  (⊥ : 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 ⊥ = 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@[to_additive] lemma index_ker {H} [group H] (f : G →* H) :\n  f.ker.index = nat.card (set.range f) :=\nby { rw [← monoid_hom.comap_bot, index_comap, relindex_bot_left], refl }\n\n@[to_additive] lemma relindex_ker {H} [group H] (f : G →* H) (K : subgroup G) :\n  f.ker.relindex K = nat.card (f '' K) :=\nby { rw [← monoid_hom.comap_bot, relindex_comap, relindex_bot_left], refl }\n\n@[simp, to_additive card_mul_index]\nlemma card_mul_index : nat.card H * H.index = nat.card G :=\nby { rw [←relindex_bot_left, ←index_bot], exact relindex_mul_index bot_le }\n\n@[to_additive] lemma nat_card_dvd_of_injective {G H : Type*} [group G] [group H] (f : G →* H)\n  (hf : function.injective f) : nat.card G ∣ nat.card H :=\nbegin\n  rw nat.card_congr (monoid_hom.of_injective hf).to_equiv,\n  exact dvd.intro f.range.index f.range.card_mul_index,\nend\n\n@[to_additive] lemma nat_card_dvd_of_le (hHK : H ≤ K) : nat.card H ∣ nat.card K :=\nnat_card_dvd_of_injective (inclusion hHK) (inclusion_injective hHK)\n\n@[to_additive] lemma nat_card_dvd_of_surjective {G H : Type*} [group G] [group H] (f : G →* H)\n  (hf : function.surjective f) : nat.card H ∣ nat.card G :=\nbegin\n  rw ← nat.card_congr (quotient_group.quotient_ker_equiv_of_surjective f hf).to_equiv,\n  exact dvd.intro_left (nat.card f.ker) f.ker.card_mul_index,\nend\n\n@[to_additive] lemma card_dvd_of_surjective {G H : Type*} [group G] [group H] [fintype G]\n  [fintype H] (f : G →* H) (hf : function.surjective f) : fintype.card H ∣ fintype.card G :=\nby simp only [←nat.card_eq_fintype_card, nat_card_dvd_of_surjective f hf]\n\n@[to_additive] lemma index_map {G' : Type*} [group G'] (f : G →* G') :\n  (H.map f).index = (H ⊔ f.ker).index * f.range.index :=\nby rw [←comap_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 →* G'}\n  (hf : function.surjective f) : (H.map f).index ∣ 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 →* G'}\n  (hf : f.ker ≤ H) : H.index ∣ (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 →* G'}\n  (hf1 : function.surjective f) (hf2 : f.ker ≤ 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 ⧸ H)] :\n  H.index = fintype.card (G ⧸ 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 [←relindex_bot_left_eq_card, ←index_bot_eq_card, mul_comm]; exact relindex_mul_index bot_le\n\n@[to_additive] lemma index_dvd_card [fintype G] : H.index ∣ fintype.card G :=\nbegin\n  classical,\n  exact ⟨fintype.card H, H.index_mul_card.symm⟩,\nend\n\nvariables {H K L}\n\n@[to_additive]\nlemma relindex_eq_zero_of_le_left (hHK : H ≤ K) (hKL : K.relindex L = 0) : H.relindex L = 0 :=\neq_zero_of_zero_dvd (hKL ▸ (relindex_dvd_of_le_left L hHK))\n\n@[to_additive]\nlemma relindex_eq_zero_of_le_right (hKL : K ≤ L) (hHK : H.relindex K = 0) : H.relindex L = 0 :=\nfinite.card_eq_zero_of_embedding (quotient_subgroup_of_embedding_of_le H hKL) hHK\n\n@[to_additive] \n\n@[to_additive] lemma relindex_le_of_le_left (hHK : H ≤ K) (hHL : H.relindex L ≠ 0) :\n  K.relindex L ≤ H.relindex L :=\nnat.le_of_dvd (nat.pos_of_ne_zero hHL) (relindex_dvd_of_le_left L hHK)\n\n@[to_additive] lemma relindex_le_of_le_right (hKL : K ≤ L) (hHL : H.relindex L ≠ 0) :\n  H.relindex K ≤ H.relindex L :=\nfinite.card_le_of_embedding' (quotient_subgroup_of_embedding_of_le H hKL) (λ h, (hHL h).elim)\n\n@[to_additive] lemma relindex_ne_zero_trans (hHK : H.relindex K ≠ 0) (hKL : K.relindex L ≠ 0) :\n  H.relindex L ≠ 0 :=\nλ h, mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K ⊓ L ≤ 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\n@[to_additive] lemma relindex_inf_ne_zero (hH : H.relindex L ≠ 0) (hK : K.relindex L ≠ 0) :\n  (H ⊓ K).relindex L ≠ 0 :=\nbegin\n  replace hH : H.relindex (K ⊓ L) ≠ 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH,\n  rw ← inf_relindex_right at hH hK ⊢,\n  rw inf_assoc,\n  exact relindex_ne_zero_trans hH hK,\nend\n\n@[to_additive] lemma index_inf_ne_zero (hH : H.index ≠ 0) (hK : K.index ≠ 0) : (H ⊓ K).index ≠ 0 :=\nbegin\n  rw ← relindex_top_right at hH hK ⊢,\n  exact relindex_inf_ne_zero hH hK,\nend\n\n@[to_additive] lemma relindex_inf_le : (H ⊓ K).relindex L ≤ H.relindex L * K.relindex L :=\nbegin\n  by_cases h : H.relindex L = 0,\n  { exact (le_of_eq (relindex_eq_zero_of_le_left (by exact inf_le_left) h)).trans (zero_le _) },\n  rw [←inf_relindex_right, inf_assoc, ←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),\nend\n\n@[to_additive] lemma index_inf_le : (H ⊓ K).index ≤ H.index * K.index :=\nby simp_rw [←relindex_top_right, relindex_inf_le]\n\n@[to_additive] lemma relindex_infi_ne_zero {ι : Type*} [hι : finite ι] {f : ι → subgroup G}\n  (hf : ∀ i, (f i).relindex L ≠ 0) : (⨅ i, f i).relindex L ≠ 0 :=\nbegin\n  haveI := fintype.of_finite ι,\n  exact finset.prod_ne_zero_iff.mpr (λ i hi, hf i) ∘ nat.card_pi.symm.trans ∘\n    finite.card_eq_zero_of_embedding (quotient_infi_subgroup_of_embedding f L),\nend\n\n@[to_additive] lemma relindex_infi_le {ι : Type*} [fintype ι] (f : ι → subgroup G) :\n  (⨅ i, f i).relindex L ≤ ∏ i, (f i).relindex L :=\nle_of_le_of_eq (finite.card_le_of_embedding' (quotient_infi_subgroup_of_embedding f L)\n  (λ h, let ⟨i, hi, h⟩ := finset.prod_eq_zero_iff.mp (nat.card_pi.symm.trans h) in\n    relindex_eq_zero_of_le_left (infi_le f i) h)) nat.card_pi\n\n@[to_additive] lemma index_infi_ne_zero {ι : Type*} [finite ι] {f : ι → subgroup G}\n  (hf : ∀ i, (f i).index ≠ 0) : (⨅ i, f i).index ≠ 0 :=\nbegin\n  simp_rw ← relindex_top_right at hf ⊢,\n  exact relindex_infi_ne_zero hf,\nend\n\n@[to_additive] lemma index_infi_le {ι : Type*} [fintype ι] (f : ι → subgroup G) :\n  (⨅ i, f i).index ≤ ∏ i, (f i).index :=\nby simp_rw [←relindex_top_right, relindex_infi_le]\n\n@[simp, to_additive index_eq_one] lemma index_eq_one : H.index = 1 ↔ H = ⊤ :=\n⟨λ h, quotient_group.subgroup_eq_top_of_subsingleton H (cardinal.to_nat_eq_one_iff_unique.mp h).1,\n  λ h, (congr_arg index h).trans index_top⟩\n\n@[simp, to_additive relindex_eq_one] lemma relindex_eq_one : H.relindex K = 1 ↔ K ≤ H :=\nindex_eq_one.trans subgroup_of_eq_top\n\n@[simp, to_additive card_eq_one] lemma card_eq_one : nat.card H = 1 ↔ H = ⊥ :=\nH.relindex_bot_left ▸ (relindex_eq_one.trans le_bot_iff)\n\n@[to_additive] lemma index_ne_zero_of_finite [hH : finite (G ⧸ H)] : H.index ≠ 0 :=\nby { casesI nonempty_fintype (G ⧸ H), rw index_eq_card, exact fintype.card_ne_zero }\n\n/-- Finite index implies finite quotient. -/\n@[to_additive \"Finite index implies finite quotient.\"]\nnoncomputable def fintype_of_index_ne_zero (hH : H.index ≠ 0) : fintype (G ⧸ H) :=\n(cardinal.lt_aleph_0_iff_fintype.mp (lt_of_not_ge (mt cardinal.to_nat_apply_of_aleph_0_le hH))).some\n\n@[to_additive one_lt_index_of_ne_top]\nlemma one_lt_index_of_ne_top [finite (G ⧸ H)] (hH : H ≠ ⊤) : 1 < H.index :=\nnat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨index_ne_zero_of_finite, mt index_eq_one.mp hH⟩\n\nsection finite_index\n\nvariables (H K)\n\n/-- Typeclass for finite index subgroups. -/\nclass finite_index : Prop :=\n(finite_index : H.index ≠ 0)\n\n/-- Typeclass for finite index subgroups. -/\nclass _root_.add_subgroup.finite_index {G : Type*} [add_group G] (H : add_subgroup G) : Prop :=\n(finite_index : H.index ≠ 0)\n\n/-- A finite index subgroup has finite quotient. -/\n@[to_additive \"A finite index subgroup has finite quotient\"]\nnoncomputable def fintype_quotient_of_finite_index [finite_index H] :\n  fintype (G ⧸ H) :=\nfintype_of_index_ne_zero finite_index.finite_index\n\n@[to_additive] instance finite_quotient_of_finite_index\n  [finite_index H] : finite (G ⧸ H) :=\nH.fintype_quotient_of_finite_index.finite\n\n@[to_additive] lemma finite_index_of_finite_quotient [finite (G ⧸ H)] : finite_index H :=\n⟨index_ne_zero_of_finite⟩\n\n@[priority 100, to_additive] instance finite_index_of_finite [finite G] : finite_index H :=\nfinite_index_of_finite_quotient H\n\n@[to_additive] instance : finite_index (⊤ : subgroup G) :=\n⟨ne_of_eq_of_ne index_top one_ne_zero⟩\n\n@[to_additive] instance [finite_index H] [finite_index K] : finite_index (H ⊓ K) :=\n⟨index_inf_ne_zero finite_index.finite_index finite_index.finite_index⟩\n\nvariables {H K}\n\n@[to_additive] lemma finite_index_of_le [finite_index H] (h : H ≤ K) : finite_index K :=\n⟨ne_zero_of_dvd_ne_zero finite_index.finite_index (index_dvd_of_le h)⟩\n\nvariables (H K)\n\n@[to_additive] instance finite_index_ker {G' : Type*} [group G'] (f : G →* G') [finite f.range] :\n  f.ker.finite_index :=\n@finite_index_of_finite_quotient G _ f.ker\n  (finite.of_equiv f.range (quotient_group.quotient_ker_equiv_range f).symm)\n\ninstance finite_index_normal_core [H.finite_index] : H.normal_core.finite_index :=\nbegin\n  rw normal_core_eq_ker,\n  apply_instance,\nend\n\nvariables (G)\n\ninstance finite_index_center [finite (commutator_set G)] [group.fg G] : finite_index (center G) :=\nbegin\n  obtain ⟨S, -, hS⟩ := group.rank_spec G,\n  exact ⟨mt (finite.card_eq_zero_of_embedding (quotient_center_embedding hS)) finite.card_pos.ne'⟩,\nend\n\nlemma index_center_le_pow [finite (commutator_set G)] [group.fg G] :\n  (center G).index ≤ (nat.card (commutator_set G)) ^ group.rank G :=\nbegin\n  obtain ⟨S, hS1, hS2⟩ := group.rank_spec G,\n  rw [←hS1, ←fintype.card_coe, ←nat.card_eq_fintype_card, ←finset.coe_sort_coe, ←nat.card_fun],\n  exact finite.card_le_of_embedding (quotient_center_embedding hS2),\nend\n\nend finite_index\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/index.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359675, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.768260154722971}}
{"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# Bijections\n\nLike finiteness, there are two ways to say that a function is bijective in Lean.\nFurthermore, you will have heard of both of them, although it may well not\nhave occurred to you that these two ways were particularly different. It turns\nout that one of them is more constructive than the other. Let's talk about\nthe nonconstructive (propositional) way of talking about bijections.\n\nLet `X` and `Y` be types, and say `f : X → Y` is a function. \n\n-/\n\nvariables (X Y : Type) (f : X → Y)\n\n-- The `Prop`-valued way of saying that `f` is bijective is simply\n-- to say literally that `f` is bijective, i.e., injective and surjective.\n\nexample : Prop := function.bijective f\n\n-- Because `f` is a function type, a little Lean hack introduced recently\n-- actually enables you to use dot notation for this.\n\nexample : Prop := f.bijective \n\n-- The definition of `function.bijective f` is \n-- `function.injective f ∧ function.surjective f`, and the definitions of\n-- injective and surjective are what you think they are.\n\nexample : f.bijective ↔ f.injective ∧ f.surjective :=\nbegin\n  refl\nend\n\nexample : f.bijective ↔ (∀ x₁ x₂ : X, f x₁ = f x₂ → x₁ = x₂) ∧ \n  (∀ y : Y, ∃ x : X, f x = y) :=\nbegin\n  refl\nend\n\n-- It's a theorem that `f` is bijective if and only if it has a two-sided\n-- inverse. One way is not hard to prove: see if you can do it. Make\n-- sure you know the maths proof first! If you can't do this then\n-- please ask. There's lots of little Lean tricks which make this\n-- question not too bad, but there are lots of little pitfalls too.\n\nexample : (∃ g : Y → X, f ∘ g = id ∧ g ∘ f = id) → f.bijective :=\nbegin\n  rintro ⟨g, hfg, hgf⟩,\n  split,\n  { -- injectivity\n    intros a b h,\n    -- want to get from `g ∘ f = id` to `∀ x, g (f x) = x`.\n    -- Use `simp_rw` to rewrite under the binder.\n    simp_rw [function.funext_iff, function.comp_apply] at hgf,\n    -- `apply_fun` can change a hypothesis `x = y` to `g x = g y`.\n    apply_fun g at h,\n    -- now use `hgf` to turn `h` into `id a = id b`, and then\n    -- use `h` to close the goal (note `id a` is definitionally `a`)\n    rwa [hgf, hgf] at h, },\n  { -- surjectivity\n    intro y, \n    use g y, -- pretty much the only element of x available!\n    -- instead of rewrites let's use `change`\n    change (f ∘ g) y = id y,\n    rw hfg, },\nend\n\n-- The other way is harder in Lean, unless you know about the `choose`\n-- tactic. Given `f` and a proof that it's a bijection, how do you\n-- prove the existence of a two-sided inverse `g`? You'll have to construct\n-- `g`, and the `choose` tactic does this for you.\n-- If `hfs` is a proof that `f` is surjective, try `choose g hg using hfs`.\nexample : f.bijective → ∃ g : Y → X, f ∘ g = id ∧ g ∘ f = id :=\nbegin\n  -- f is injective and surjective\n  rintro ⟨hfi, hfs⟩,\n  -- construct `g` a one-sided inverse (because `f` is surjective)\n  choose g hg using hfs,\n  -- now you have to use `hg` to prove both f ∘ g = id and g ∘ f = id\n  use g,\n  split,\n  { -- f ∘ g is straightforward\n    ext y, -- use functional extensionality\n    exact hg y, },-- abuse of defeq\n  { -- g ∘ f needs a trick\n    ext x, \n    -- here we use injectivity\n    apply hfi,\n    -- and here we abuse definitional equality\n    exact hg (f x), },\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/section09bijections_and_isomorphisms/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7682601403011675}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport order.filter.basic\n\n/-!\n# Filtros\nLa definición de `filtro` en Lean es la siguiente:\n\nstructure filter (α : Type*) :=\n(sets                   : set (set α))\n(univ_sets              : set.univ ∈ sets)\n(sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets)\n(inter_sets {x y}       : x ∈ sets → y ∈ sets → x ∩ y ∈ sets)\n\n\n## Notación y resultados útiles.\n\nFijamos `α : Type`, `F : filter α` y `S : set α`.\n\nPor definición, la notación `S ∈ F` significa `S ∈ F.sets`. \n(La intuición es `F ⊆ 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ólo si \n`∀ S, S ∈ F ↔ S ∈ G`. \n\nLos lemas correspondientes a las condiciones que\naparecen en la definición de filtro son:\n\n`univ_mem : univ ∈ F`\n`mem_of_superset : S ∈ F → S ⊆ T → T ∈ F`\n`inter_mem : S ∈ F → T ∈ F → S ∩ T ∈ F`\n\nEstos lemas están en el espacio de nombres `filter`.\n-/\n\n-- Abrimos los espacios de nombres `filter` y `set`.\nopen filter set \n\n--  Sea `α` un tipo, `F` un filtro sobre `α`, y `S` y `T` dos subconjuntos de `α`.\nvariables (α : Type) (F : filter α) (S T : set α)\n\n/-\nDos subconjuntos `S` y `T` están en un filtro `F` si y sólo\nsi su intersección está en `F`.\n\nLos lemas `inter_subset_left S T : S ∩ T ⊆ S` e `inter_subset_right S T : S ∩ T ⊆ S`\nson útiles para esta demostración.\n-/\nexample : S ∩ T ∈ F ↔ S ∈ F ∧ T ∈ F :=\nbegin\n  split,\n  { intro hST,\n    exact ⟨mem_of_superset hST (inter_subset_left S T), \n      mem_of_superset hST (inter_subset_right S T) ⟩, },\n  { rintro ⟨hS, hT⟩,\n    exact inter_mem hS hT }\nend\n\n/-! ## Ejemplos de filtros -/\n\n/- ### Filtros principales\nDado un subconjunto `X` de `α`, el filtro principal de `X` es la \ncolección de subconjuntos de `α` que contienen `X`.\nEstá definido en mathlib, y denotado mediante `𝓟 X`, pero en \neste ejemplo vamos a demostrar nosotros mismos que es un filtro.\n\nLemas útiles:\n`mem_univ s : s ∈ univ`\n`subset.trans : A ⊆ B → B ⊆ C → A ⊆ C`\n`subset_inter : X ⊆ S → X ⊆ T → X ⊆ S ∩ T`\n`mem_set_of_eq : x ∈ {a : α | p a} = p x`\n-/\n\n-- El filtro principal de `X`.\nexample (X : set α) : filter α :=\n{ sets := {S : set α | X ⊆ S},\n  univ_sets := begin\n    exact subset_univ _,\n  end,\n  sets_of_superset := begin\n    intros S T hS hST,\n    exact subset.trans hS hST,\n  end,\n  inter_sets := begin\n    intros S T hS hT,\n    exact subset_inter hS hT,\n  end }\n\n/-- ### EL filtro `at_top` en un conjunto totalmente ordenado\n\nSea `L` un conjunto linearmente ordenado no vacío.\nVamos a construir un filtro `at_top` que representa un\n\"entorno infinitesimal\" de `∞`. En concreto, los conjuntos \npertenecientes a este filtro serán aquellos `X : set L`\npara los que existe un `x : L` tal que para todo `y ≥ x`, `y ∈ X`.\n-/\ndef at_top (L : Type) [linear_order L] (e : L) : filter L :=\n{ sets := {X : set L | ∃ x : L, ∀ y, x ≤ y → y ∈ X},\n  univ_sets := begin\n    use e,\n    rintros y -,\n    exact mem_univ _,\n  end,\n  sets_of_superset := begin\n    intros S T hS hST,\n    simp only [mem_set_of_eq] at hS ⊢,\n    obtain ⟨s, hs⟩ := hS,\n    use s,\n    intros x hx,\n    exact hST (hs x hx),\n  end,\n  inter_sets := begin\n    rintros S T ⟨s, hs⟩ ⟨t, ht⟩,\n    use max s t,\n    intros x hx,\n    exact ⟨hs _ (le_trans (le_max_left s t) hx), ht _ (le_trans (le_max_right s t) hx)⟩,\n  end }\n\n/-! ### El filtro cofinito\nEl filtro cofinito en un tipo `α` es la colección de subconjuntos `S : set α`\ncon la propiedad de que el complemento `Sᶜ`de `S` es finito.\n\nLemas útiles:\n`compl_univ : univᶜ = ∅`\n`finite_empty : finite ∅`\n`compl_subset_compl : Xᶜ ⊆ Yᶜ ↔ Y ⊆ X`\n`finite.subset : S.finite → ∀ {T : set α}, T ⊆ S → T.finite`\n`compl_inter S T : (S ∩ T)ᶜ = Sᶜ ∪ Tᶜ`\n`finite.union : S.finite → T.finite → (S ∪ T).finite`.\n-/\ndef cofinite (α : Type) : filter α :=\n{ sets := { S : set α | (Sᶜ).finite },\n  univ_sets := begin\n    simp only [mem_set_of_eq, compl_univ, finite_empty],\n  end,\n  sets_of_superset := begin\n    intros S T hS hST,\n    rw ← compl_subset_compl at hST, \n    exact finite.subset hS hST,\n  end,\n  inter_sets := begin\n    intros S T hS hT,\n    rw [mem_set_of_eq, compl_inter],\n    exact finite.union hS hT,\n  end }\n\n-- Esta instrucción nos permite acceder a la notación `𝓟 X` para el filtro principal\nopen_locale filter\n\n/-!\n## El orden (≤) sobre los filtros de `α`\nLos filtros están parcialmente ordenados, mediante la relación `≤`\ndefinida mediante `F ≤ G` si y sólo si `G.sets ⊆ F.sets`. \n(Cuanto más pequeño es el filtro `F`, más grande es la colección\n`F.sets`, ya que el \"conjunto generalizado\" `F` está \"contenido\"\nen más conjuntos).\n\nEn este ejemplo vamos a demostrar que `𝓟 S ≤ 𝓟 T ↔ S ⊆ T`.\nEsto es lo que dice el lema `principal_mono` de mathlib,\npero vamos a demostrarlo utilizando los lemas:\n`mem_principal : T ∈ 𝓟 S ↔ S ⊆ T`\n`mem_principal_self S : S ∈ 𝓟 S`\n`le_def : F ≤ G ↔ ∀ (S : set α), S ∈ G → S ∈ F`\n-/\n\nexample (S T : set α) : 𝓟 S ≤ 𝓟 T ↔ S ⊆ T :=\nbegin\n  split; -- La siguiente instrucción se aplica a todas las metas abiertas (por el ;).\n  intro hST,\n  { rw ← mem_principal, -- Puedes comentarla y la prueba sigue funcionando\n    rw le_def at hST,\n    exact hST T (mem_principal_self T), },\n  { intros X hX,\n    rw mem_principal at hX ⊢, -- Puedes comentarla y la prueba sigue funcionando\n    exact subset.trans hST hX, },\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 α) (S : set α) : F ≤ 𝓟 S ↔ S ∈ F :=\nbegin\n  rw le_def,\n  exact ⟨λ h, h S (mem_principal_self S), λ h T hT, mem_of_superset h hT⟩,\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/soluciones/filtros.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7682501618204955}}
{"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-/\nimport analysis.asymptotics.asymptotic_equivalent\nimport analysis.asymptotics.specific_asymptotics\nimport data.polynomial.ring_division\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 +∞.\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\nopen filter finset asymptotics\nopen_locale asymptotics polynomial topological_space\n\nnamespace polynomial\n\nvariables {𝕜 : Type*} [normed_linear_ordered_field 𝕜] (P Q : 𝕜[X])\n\nlemma eventually_no_roots (hP : P ≠ 0) : ∀ᶠ x in filter.at_top, ¬ P.is_root x :=\nbegin\n  obtain ⟨x₀, hx₀⟩ := exists_max_root P hP,\n  refine filter.eventually_at_top.mpr (⟨x₀ + 1, λ x hx h, _⟩),\n  exact absurd (hx₀ x h) (not_le.mpr (lt_of_lt_of_le (lt_add_one x₀) hx)),\nend\n\nvariables [order_topology 𝕜]\n\nsection polynomial_at_top\n\nlemma is_equivalent_at_top_lead :\n  (λ x, eval x P) ~[at_top] (λ x, P.leading_coeff * x ^ P.nat_degree) :=\nbegin\n  by_cases h : P = 0,\n  { simp [h] },\n  { conv_lhs\n    { funext,\n      rw [polynomial.eval_eq_sum_range, sum_range_succ] },\n    exact is_equivalent.refl.add_is_o (is_o.sum $ λ i hi, is_o.const_mul_left\n      (is_o.const_mul_right (λ hz, h $ leading_coeff_eq_zero.mp hz) $\n        is_o_pow_pow_at_top_of_lt (mem_range.mp hi)) _) }\nend\n\nlemma tendsto_at_top_of_leading_coeff_nonneg (hdeg : 1 ≤ P.degree) (hnng : 0 ≤ P.leading_coeff) :\n  tendsto (λ x, eval x P) at_top at_top :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_top\n  (tendsto_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)\n    (lt_of_le_of_ne hnng $ ne.symm $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))\n\nlemma tendsto_at_top_iff_leading_coeff_nonneg :\n  tendsto (λ x, eval x P) at_top at_top ↔ 1 ≤ P.degree ∧ 0 ≤ P.leading_coeff :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_at_top_of_leading_coeff_nonneg P h.1 h.2⟩,\n  have : tendsto (λ x, P.leading_coeff * x ^ P.nat_degree) at_top at_top :=\n    is_equivalent.tendsto_at_top (is_equivalent_at_top_lead P) h,\n  rw tendsto_const_mul_pow_at_top_iff P.leading_coeff P.nat_degree at this,\n  rw [degree_eq_nat_degree (leading_coeff_ne_zero.mp (ne_of_lt this.2).symm), ← nat.cast_one],\n  refine ⟨with_bot.coe_le_coe.mpr this.1, le_of_lt this.2⟩,\nend\n\nlemma tendsto_at_bot_of_leading_coeff_nonpos (hdeg : 1 ≤ P.degree) (hnps : P.leading_coeff ≤ 0) :\n  tendsto (λ x, eval x P) at_top at_bot :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_bot\n  (tendsto_neg_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)\n    (lt_of_le_of_ne hnps $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))\n\nlemma tendsto_at_bot_iff_leading_coeff_nonpos :\n  tendsto (λ x, eval x P) at_top at_bot ↔ 1 ≤ P.degree ∧ P.leading_coeff ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_at_bot_of_leading_coeff_nonpos P h.1 h.2⟩,\n  have : tendsto (λ x, P.leading_coeff * x ^ P.nat_degree) at_top at_bot :=\n    (is_equivalent.tendsto_at_bot (is_equivalent_at_top_lead P) h),\n  rw tendsto_neg_const_mul_pow_at_top_iff P.leading_coeff P.nat_degree at this,\n  rw [degree_eq_nat_degree (leading_coeff_ne_zero.mp (ne_of_lt this.2)), ← nat.cast_one],\n  refine ⟨with_bot.coe_le_coe.mpr this.1, le_of_lt this.2⟩,\nend\n\nlemma abs_tendsto_at_top (hdeg : 1 ≤ P.degree) :\n  tendsto (λ x, abs $ eval x P) at_top at_top :=\nbegin\n  by_cases hP : 0 ≤ P.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.tendsto_at_top_of_leading_coeff_nonneg hdeg hP)},\n  { push_neg at hP,\n    exact tendsto_abs_at_bot_at_top.comp (P.tendsto_at_bot_of_leading_coeff_nonpos hdeg hP.le)}\nend\n\nlemma abs_is_bounded_under_iff :\n  is_bounded_under (≤) at_top (λ x, |eval x P|) ↔ P.degree ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, ⟨|P.coeff 0|, eventually_map.mpr (eventually_of_forall\n    (forall_imp (λ _, le_of_eq) (λ x, congr_arg abs $ trans (congr_arg (eval x)\n    (eq_C_of_degree_le_zero h)) (eval_C))))⟩⟩,\n  contrapose! h,\n  exact not_is_bounded_under_of_tendsto_at_top\n    (abs_tendsto_at_top P (nat.with_bot.one_le_iff_zero_lt.2 h))\nend\n\nlemma abs_tendsto_at_top_iff :\n  tendsto (λ x, abs $ eval x P) at_top at_top ↔ 1 ≤ P.degree :=\n⟨λ h, nat.with_bot.one_le_iff_zero_lt.2 (not_le.mp ((mt (abs_is_bounded_under_iff P).mpr)\n  (not_is_bounded_under_of_tendsto_at_top h))), abs_tendsto_at_top P⟩\n\nlemma tendsto_nhds_iff {c : 𝕜} :\n  tendsto (λ x, eval x P) at_top (𝓝 c) ↔ P.leading_coeff = c ∧ P.degree ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { have := P.is_equivalent_at_top_lead.tendsto_nhds h,\n    by_cases hP : P.leading_coeff = 0,\n    { simp only [hP, zero_mul, tendsto_const_nhds_iff] at this,\n      refine ⟨trans hP this, by simp [leading_coeff_eq_zero.1 hP]⟩ },\n    { rw [tendsto_const_mul_pow_nhds_iff hP, nat_degree_eq_zero_iff_degree_le_zero] at this,\n      exact this.symm } },\n  { 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 }\nend\n\nend polynomial_at_top\n\nsection polynomial_div_at_top\n\nlemma is_equivalent_at_top_div :\n  (λ x, (eval x P)/(eval x Q)) ~[at_top]\n    λ x, P.leading_coeff/Q.leading_coeff * x^(P.nat_degree - Q.nat_degree : ℤ) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP] },\n  by_cases hQ : Q = 0,\n  { simp [hQ] },\n  refine (P.is_equivalent_at_top_lead.symm.div\n          Q.is_equivalent_at_top_lead.symm).symm.trans\n         (eventually_eq.is_equivalent ((eventually_gt_at_top 0).mono $ λ x hx, _)),\n  simp [← div_mul_div_comm₀, hP, hQ, zpow_sub₀ hx.ne.symm]\nend\n\nlemma div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP, tendsto_const_nhds] },\n  rw ←  nat_degree_lt_nat_degree_iff hP at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw ← mul_zero,\n  refine (tendsto_zpow_at_top_zero _).const_mul _,\n  linarith\nend\n\nlemma div_tendsto_zero_iff_degree_lt (hQ : Q ≠ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) ↔ P.degree < Q.degree :=\nbegin\n  refine ⟨λ h, _, div_tendsto_zero_of_degree_lt P Q⟩,\n  by_cases hPQ : P.leading_coeff / Q.leading_coeff = 0,\n  { simp only [div_eq_mul_inv, inv_eq_zero, mul_eq_zero] at hPQ,\n    cases hPQ with hP0 hQ0,\n    { rw [leading_coeff_eq_zero.1 hP0, degree_zero],\n      exact bot_lt_iff_ne_bot.2 (λ hQ', hQ (degree_eq_bot.1 hQ')) },\n    { exact absurd (leading_coeff_eq_zero.1 hQ0) hQ } },\n  { have := (is_equivalent_at_top_div P Q).tendsto_nhds h,\n    rw tendsto_const_mul_zpow_at_top_zero_iff hPQ at this,\n    cases this with h h,\n    { exact absurd h.2 hPQ },\n    { rw [sub_lt_iff_lt_add, zero_add, int.coe_nat_lt] at h,\n      exact degree_lt_degree h.1 } }\nend\n\nlemma div_tendsto_leading_coeff_div_of_degree_eq (hdeg : P.degree = Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 $ P.leading_coeff / Q.leading_coeff) :=\nbegin\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw show (P.nat_degree : ℤ) = Q.nat_degree, by simp [hdeg, nat_degree],\n  simp [tendsto_const_nhds]\nend\n\nlemma div_tendsto_at_top_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hpos : 0 < P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hpos, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_top _,\n  apply tendsto.const_mul_at_top hpos,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnng : 0 ≤ P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nhave ratio_pos : 0 < P.leading_coeff/Q.leading_coeff,\n  from lt_of_le_of_ne hnng\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)).symm,\ndiv_tendsto_at_top_of_degree_gt' P Q hdeg ratio_pos\n\nlemma div_tendsto_at_bot_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hneg : P.leading_coeff/Q.leading_coeff < 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hneg, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_bot _,\n  apply tendsto.neg_const_mul_at_top hneg,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_bot_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnps : P.leading_coeff/Q.leading_coeff ≤ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nhave ratio_neg : P.leading_coeff/Q.leading_coeff < 0,\n  from lt_of_le_of_ne hnps\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)),\ndiv_tendsto_at_bot_of_degree_gt' P Q hdeg ratio_neg\n\nlemma abs_div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) :\n  tendsto (λ x, |(eval x P)/(eval x Q)|) at_top at_top :=\nbegin\n  by_cases h : 0 ≤ P.leading_coeff/Q.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.div_tendsto_at_top_of_degree_gt Q hdeg hQ h) },\n  { 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) }\nend\n\nend polynomial_div_at_top\n\ntheorem is_O_of_degree_le (h : P.degree ≤ Q.degree) :\n  is_O (λ x, eval x P) (λ x, eval x Q) filter.at_top :=\nbegin\n  by_cases hp : P = 0,\n  { simpa [hp] using is_O_zero (λ x, eval x Q) filter.at_top },\n  { have hq : Q ≠ 0 := ne_zero_of_degree_ge_degree h hp,\n    have hPQ : ∀ᶠ (x : 𝕜) in at_top, eval x Q = 0 → eval x P = 0 :=\n      filter.mem_of_superset (polynomial.eventually_no_roots Q hq) (λ x h h', absurd h' h),\n    cases le_iff_lt_or_eq.mp h with h h,\n    { exact is_O_of_div_tendsto_nhds hPQ 0 (div_tendsto_zero_of_degree_lt P Q h) },\n    { exact is_O_of_div_tendsto_nhds hPQ _ (div_tendsto_leading_coeff_div_of_degree_eq P Q h) } }\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/analysis/special_functions/polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7682501601725539}}
{"text": "/- \nWritten by Congzhou M Sha (cms6712@psu.edu)\n\nCopyright 2022 Congzhou M Sha\n\nPermission is hereby granted, free of charge, to any person obtaining a copy \nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell \ncopies of the Software, and to permit persons to whom the Software is \nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n-/\nimport tactic\nimport data.real.basic\nimport number_theory.bernoulli\nimport special_constants\nimport lemmas0\n\nopen_locale big_operators\n\n/- Chapter 0.1: Finite sums -/\nnamespace chapter0_1\n  @[simp] theorem arithmetic_progression_0_111 (n : ℕ) (a r : ℝ) :\n    ∑ (k : ℕ) in finset.range n, (a + k * r) = n * (a + (n - 1) * r / 2) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem geometric_progression_0_112 (n : ℕ) (a q : ℝ) (h : q ≠ 1) :\n    ∑ (k : ℕ) in finset.range n, a * q ^ k = a * (q ^ n - 1) / (q - 1) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    {\n      rw [finset.sum_range_succ, ih, pow_succ],\n      repeat {rw div_eq_mul_inv},\n      repeat {rw mul_sub_left_distrib},\n      repeat {rw mul_sub_right_distrib},\n      repeat {rw mul_one},\n      rw ne_zero_iff_sub_ne_zero at h,\n      have := mul_inv_cancel h,\n      nth_rewrite_lhs 1 ← mul_one (a * q ^ n),\n      nth_rewrite_lhs 2 ← this,\n      rw ← mul_assoc (a * q ^ n),\n      ring_exp,\n    },\n  end\n\n  @[simp] lemma pure_geometric_progression (n : ℕ) (q : ℝ) (h : q ≠ 1) : \n    ∑ (k : ℕ) in finset.range n, q ^ k = (q ^ n - 1) / (q - 1) := \n  begin\n    have := geometric_progression_0_112 n 1 q h,\n    simp at this,\n    exact this,\n  end\n\n  /-\n    An inelegant method of proving the derivatives except at 1 are equal for two functions\n    which agree except at 1.\n    TODO: I've written helper theorems in lemma0.lean which can simplify this argument.\n  -/\n  @[simp] lemma deriv_except_at_one (n : ℕ) (q : ℝ) (h : q ≠ 1) :\n      has_deriv_at (λ (x : ℝ), (finset.range n).sum (pow x)) \n        (∑ (k : ℕ) in finset.range n, power_rule.x_to_n' k q) q\n      ↔ has_deriv_at (λ (x : ℝ), (x ^ n - 1) / (x - 1)) \n        (∑ (k : ℕ) in finset.range n, power_rule.x_to_n' k q) q :=\n  begin\n    split,\n    {\n      intro p,\n      rw [has_deriv_at, has_deriv_at_filter, has_fderiv_at_filter,\n      asymptotics.is_o_iff] at *,\n      intros c r,\n      have := h,\n      rw ne_zero_iff_sub_ne_zero at this,\n      rw ← abs_pos at this,\n      replace : 0 < |q - 1| / 2, by linarith,\n      specialize p r,\n      rw metric.eventually_nhds_iff_ball at *,\n      cases p with ε h₁,\n      cases h₁ with h₁ h₂,\n      use min ε (|q - 1| / 2),\n      split,\n      { \n        rw [gt_iff_lt, lt_min_iff],\n        split,\n        repeat {linarith},\n      },\n      {\n        intros x' q₁,\n        simp at q₁,\n        unfold dist at q₁,\n        rw abs_sub_comm at this,\n        have q₁' := q₁.2,\n        nth_rewrite_rhs 0 abs_sub_comm at q₁',\n        have := half_bound q x' q₁' h,\n        specialize h₂ x' q₁.1,\n        rw ← pure_geometric_progression n q h,\n        rw ← pure_geometric_progression n x' this,\n        assumption,\n      },\n    },\n    {\n      intro p,\n      rw [has_deriv_at, has_deriv_at_filter, has_fderiv_at_filter,\n      asymptotics.is_o_iff] at *,\n      intros c r,\n      have := h,\n      rw ne_zero_iff_sub_ne_zero at this,\n      rw ← abs_pos at this,\n      replace : 0 < |q - 1| / 2, by linarith,\n      specialize p r,\n      rw metric.eventually_nhds_iff_ball at *,\n      cases p with ε h₁,\n      cases h₁ with h₁ h₂,\n      use min ε (|q - 1| / 2),\n      split,\n      { \n        rw [gt_iff_lt, lt_min_iff],\n        split,\n        repeat {linarith},\n      },\n      {\n        intros x' q₁,\n        simp at q₁,\n        unfold dist at q₁,\n        rw abs_sub_comm at this,\n        have q₁' := q₁.2,\n        nth_rewrite_rhs 0 abs_sub_comm at q₁',\n        have := half_bound q x' q₁' h,\n        specialize h₂ x' q₁.1,\n        rw pure_geometric_progression n q h,\n        rw pure_geometric_progression n x' this,\n        assumption,\n      },\n    },\n  end\n\n  lemma deriv_of_geometric (n : ℕ) (x : ℝ) (h : x ≠ 1):\n    ∑ (k : ℕ) in finset.range n, (↑k + 1) * x ^ k = \n    ((↑n + 1) * x ^ n * (x - 1) - (x ^ (n + 1) - 1)) / (x - 1) ^ 2 :=\n  begin\n    have p₁ := deriv_sum_powers (n + 1) x,\n    replace p₁ := (deriv_except_at_one (n + 1) x h).1 p₁,\n    have p₂ := deriv_geom_at_ne_one n x h,\n    rename_var x y at p₁,\n    replace p₁ := has_deriv_at.unique p₁ p₂,\n    clear p₂,\n    rw sum_x_to_n'_eq_deriv_sum n x at p₁,\n    assumption,\n  end\n\n  lemma deriv_of_geometric_rv (n : ℕ) (x : ℝ) (h : x ≠ 1):\n    ((↑n + 1) * x ^ n * (x - 1) - (x ^ (n + 1) - 1)) / (x - 1) ^ 2 =\n    ∑ (k : ℕ) in finset.range n, (↑k + 1) * x ^ k := (deriv_of_geometric n x h).symm\n\n  /- \n    Proof through linearity of sums and differentiating both sides of the geometric series\n    equation. \"Differentiating both sides\" is equivalent to \"the derivative is unique\"\n  -/\n  theorem arithmetic_geometric_progression_0_113 {n : ℕ} {a q r : ℝ} (h : q ≠ 1) :\n    ∑ (k : ℕ) in finset.range (n + 1), ((a + k * r) * q ^ k) = \n      (a - (a + n * r) * q ^ (n + 1)) / (1 - q) + r * q * (1 - q ^ n) / (1 - q) ^ 2 :=\n  begin\n    rw arith_geom_progression_split_sum (n + 1) a q r,\n    rw geometric_progression_0_112 (n + 1) a q h,\n    rw ← deriv_sub_geom_eq_sum,\n    have p₁ := deriv_of_geometric (n + 1) q h,\n    rw p₁,\n    rw pure_geometric_progression (n + 1) q h,\n    rw ← neg_sub 1 q,\n    have q₁ : (-(1 - q)) ^ 2 = (1 - q) ^ 2, by ring_nf,\n    rw q₁,\n    simp only [nat.cast_add, nat.cast_one, div_eq_mul_inv, left_distrib, right_distrib,\n      mul_sub_left_distrib, mul_sub_right_distrib, mul_one, one_mul],\n    rw [sub_eq_neg_add, mul_comm, ← neg_inv, neg_mul, neg_neg, mul_comm,\n      sub_eq_add_neg (a * (1 - q)⁻¹)],\n    nth_rewrite_lhs 0 add_assoc,\n    nth_rewrite_rhs 0 add_assoc,\n    rw [add_right_inj, mul_neg, neg_add],\n    nth_rewrite_rhs 0 add_assoc,\n    simp only [mul_neg, neg_mul],\n    rw [add_right_inj],\n    rw ne_zero_iff_sub_ne_zero at h,\n    repeat {rw mul_assoc},\n    have := h,\n    rw sub_ne_zero_iff_sub_ne_zero at this,\n    rw [mul_comm (1 - q), inv_mul_eq_div, \n      cancel_power (1 - q) this, pow_one, mul_div, mul_one],\n    repeat {rw ← mul_comm (1 - q)⁻¹},\n    repeat {rw inv_mul_eq_div},\n    rw ← mul_assoc,\n    nth_rewrite_rhs 0 ← mul_assoc,\n    rw [mul_comm r (↑n), add_assoc, add_sub_assoc, add_sub_assoc, add_right_inj],\n    repeat {rw sub_eq_add_neg},\n    rw [neg_neg, add_assoc (-(r * (q ^ (n + 1) / (1 + -q))) + -(r * (q ^ (n + 1) / (1 + -q)))),\n      add_comm (-(r * (q ^ (n + 1 + 1) * ((1 + -q) ^ 2)⁻¹) + -(r * ((1 + -q) ^ 2)⁻¹))),\n      ← add_assoc (-(r * (q ^ (n + 1) / (1 + -q))) + -(r * (q ^ (n + 1) / (1 + -q)))),\n      neg_add, neg_neg, ← add_assoc, add_assoc (-(r * (q ^ (n + 1) / (1 + -q)))), \n      neg_add_self, add_zero, neg_add, neg_neg, add_comm (-(r * (q ^ (n + 1 + 1) * ((1 + -q) ^ 2)⁻¹))),\n      ← add_assoc, add_comm (-(r * (q ^ (n + 1) / (1 + -q))) + -(r / (1 + -q)))],\n    \n    \n    have m₁ := mul_ne_zero this this,\n    have m₂ := mul_inv_cancel m₁,\n    \n    rw mul_self_eq_square at m₁,\n    rw mul_self_eq_square at m₂,\n    have m₃ := mul_self_pos.2 this,\n    rw mul_self_eq_square at m₃,\n    have m₄ : (r * ((1 + -q) ^ 2)⁻¹ + (-(r * (q ^ (n + 1) / (1 + -q))) + -(r / (1 + -q))) +\n      -(r * (q ^ (n + 1 + 1) * ((1 + -q) ^ 2)⁻¹))) * (1 - q) ^ 2 = (r * (q * ((1 + -q) ^ 2)⁻¹) + -(r * (q * (q ^ n * ((1 + -q) ^ 2)⁻¹)))) * (1 - q) ^ 2 ↔\n      (r * ((1 + -q) ^ 2)⁻¹ + (-(r * (q ^ (n + 1) / (1 + -q))) + -(r / (1 + -q))) +\n      -(r * (q ^ (n + 1 + 1) * ((1 + -q) ^ 2)⁻¹)) =\n      r * (q * ((1 + -q) ^ 2)⁻¹) + -(r * (q * (q ^ n * ((1 + -q) ^ 2)⁻¹))))\n      := (mul_right_cancel_iff_of_pos m₃),\n    rw ← m₄,\n    clear m₄,\n    repeat {rw right_distrib},\n    repeat {rw tactic.ring.add_neg_eq_sub},\n    rw mul_comm at m₂,\n    rw [mul_assoc r, m₂, mul_one, neg_mul, mul_assoc r, div_mul, \n      cancel_power (1 - q) this, pow_one, ← div_mul, div_one, neg_mul,\n      div_mul, cancel_power (1 - q) this, \n      pow_one, ← div_mul, div_one, ← neg_add, ← sub_eq_add_neg,\n      sub_add_eq_sub_sub, neg_mul, mul_assoc, mul_assoc, m₂, mul_one,\n      mul_assoc r, mul_assoc q, m₂, ← mul_assoc, ← mul_assoc, ← mul_assoc, \n      ← mul_assoc, ← neg_mul, ← neg_mul, ← neg_mul, mul_assoc (-(r * q) * q ^ n), m₂,\n      sub_eq_add_neg, pow_succ q (n + 1)],\n    simp only [left_distrib, right_distrib, mul_one, mul_sub_right_distrib, mul_sub_left_distrib],\n    ring_nf,\n    simp only [left_distrib, right_distrib],\n    rw [one_mul, add_left_inj, mul_comm (-q ^ n), pow_succ, ← mul_neg],\n  end\n\n  /-\n    Surprisingly, though the calculus proof (differentiating the geometric series twice)\n    is easier to follow on paper, the induction proof has far less tedious algebra.\n  -/\n  theorem k_squared_geometric_progression_0_114 {n : ℕ} {x : ℝ} (h : x ≠ 1) :\n    ∑ (k : ℕ) in finset.range n, ↑k ^ 2 * x ^ k =\n    ((-n ^ 2 + 2 * n - 1) * x ^ (n + 2) + (2 * n ^ 2 - 2 * n - 1) * x ^ (n + 1) \n    - n ^ 2 * x ^ n + x ^ 2 + x) / (1 - x) ^ 3 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    {\n      rw [finset.sum_range_succ, nat.succ_eq_add_one, ih],\n      rw ne_zero_iff_sub_ne_zero at h,\n      have h' := h,\n      rw sub_ne_zero_iff_sub_ne_zero at h',\n      have trip := mul_ne_zero (mul_ne_zero h' h') h',\n      rw mul_self_twice_eq_cube at trip,\n\n      -- Multiply both sides by (1 - x) ^ 3 (nonzero). \n      -- TODO: replace this with easier to use multiply_both_sides_by_ne_zero (lemma0.lean)\n      have :\n      (((-↑n ^ 2 + 2 * ↑n - 1) * x ^ (n + 2) + (2 * ↑n ^ 2 - 2 * ↑n - 1) * x ^ (n + 1) - ↑n ^ 2 * x ^ n + x ^ 2 +\n         x) /\n      (1 - x) ^ 3 +\n      ↑n ^ 2 * x ^ n) * (1 - x) ^ 3 =\n      (((-↑(n + 1) ^ 2 + 2 * ↑(n + 1) - 1) * x ^ (n + 1 + 2) +\n              (2 * ↑(n + 1) ^ 2 - 2 * ↑(n + 1) - 1) * x ^ (n + 1 + 1) -\n            ↑(n + 1) ^ 2 * x ^ (n + 1) +\n          x ^ 2 +\n        x) /\n      (1 - x) ^ 3) * (1 - x) ^ 3 ↔\n      ((-↑n ^ 2 + 2 * ↑n - 1) * x ^ (n + 2) + (2 * ↑n ^ 2 - 2 * ↑n - 1) * x ^ (n + 1) - ↑n ^ 2 * x ^ n + x ^ 2 +\n          x) /\n        (1 - x) ^ 3 +\n      ↑n ^ 2 * x ^ n =\n      ((-↑(n + 1) ^ 2 + 2 * ↑(n + 1) - 1) * x ^ (n + 1 + 2) +\n              (2 * ↑(n + 1) ^ 2 - 2 * ↑(n + 1) - 1) * x ^ (n + 1 + 1) -\n            ↑(n + 1) ^ 2 * x ^ (n + 1) +\n          x ^ 2 +\n        x) /\n      (1 - x) ^ 3\n        := mul_right_cancel_iff_ne_zero trip,\n      rw ← this, clear this,\n      have cancel := mul_inv_cancel trip,\n      rw mul_comm at cancel,\n      rw [right_distrib, div_eq_mul_inv, mul_assoc, cancel, mul_one, div_eq_mul_inv],\n      nth_rewrite_rhs 0 mul_assoc,\n      rw [cancel],\n      simp only [right_distrib, left_distrib, mul_sub_right_distrib, \n        mul_sub_left_distrib, one_mul, mul_one, ← mul_self_eq_square, nat.cast_add, nat.cast_one],\n      rw [add_right_comm (-(↑n * ↑n) * x ^ (n + 2) + 2 * ↑n * x ^ (n + 2) - x ^ (n + 2) +\n        (2 * (↑n * ↑n) * x ^ (n + 1) - 2 * ↑n * x ^ (n + 1) - x ^ (n + 1)) -\n        ↑n * ↑n * x ^ n +\n        x * x), add_left_inj, add_right_comm (-(↑n * ↑n) * x ^ (n + 2) + 2 * ↑n * x ^ (n + 2) - x ^ (n + 2) +\n        (2 * (↑n * ↑n) * x ^ (n + 1) - 2 * ↑n * x ^ (n + 1) - x ^ (n + 1)) -\n        ↑n * ↑n * x ^ n), add_left_inj],\n      have : n + 1 + 1 = n + 2, by linarith,\n      rw this, clear this,\n      have : n + 1 + 2 = n + 3, by linarith,\n      rw this, clear this,\n      ring_nf,\n      rw add_left_inj,\n      simp only [right_distrib, left_distrib, mul_sub_right_distrib, \n        mul_sub_left_distrib],\n      rw add_left_inj,\n      ring_exp,\n    }\n  end\n\n  /-\n    Sums of powers of integers\n  -/\n  @[simp] theorem sum_integers_0_121_1 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) = ↑n * (n + 1) / 2 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_integers_0_121_2 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) ^ 2 = (↑n * (n + 1) * (2 * n + 1)) / 6 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_integers_0_121_3 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) ^ 3 = (n * (n + 1) / 2) ^ 2 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_integers_0_121_4 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) ^ 4 = n * (n + 1) * (2 * n + 1) * (3 * n ^ 2 + 3 * n - 1) / 30 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_integers_0_121_5 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) ^ 5 = n ^ 2 * (n + 1) ^ 2 * (2 * n ^ 2 + 2 * n - 1) / 12 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n  \n  @[simp] theorem sum_integers_0_121_6 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) ^ 6 = n * (n + 1) * (2 * n + 1) * (3 * n ^ 4 + 6 * n ^ 3 - 3 * n + 1) / 42 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_integers_0_121_7 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑k : ℝ) ^ 7 = n ^ 2 * (n + 1) ^ 2 * (3 * n ^ 4 + 6 * n ^ 3 - n ^ 2 - 4 * n + 2) / 24 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  def sum_integers_0_121 {n q : ℕ} := sum_range_pow n q\n\n  -- convert proof over ℝ to proof over ℕ, if desired\n  theorem convert_proof_real_to_nat (n : ℕ) (f g : ℕ → ℕ) :\n    ∑ (k : ℕ) in finset.range (n + 1), (↑(f k) : ℝ) = ↑(g n) →\n    ∑ (k : ℕ) in finset.range (n + 1), f k = g n :=\n  begin\n    intro p,\n    rw ← nat.cast_sum (finset.range (n + 1)) f at p,\n    rw nat.cast_inj at p,\n    assumption,\n  end\n\n  /- All the above proofs using reals may be turned into proofs on nats. -/\n  @[simp] lemma sum_integers_0_121_1_nat {n : ℕ} : \n    ∑ (k : ℕ) in finset.range (n + 1), (k : ℝ) = n * (n + 1) / 2 :=\n  begin\n    have a := sum_integers_0_121_1,\n    have b := convert_proof_real_to_nat n (λ (k : ℕ), k) (λ (n : ℕ), n * (n + 1) / 2),\n    simp at b,\n    rw nat.cast_div at b,\n    { exact a, },\n    { exact mul_consecutive_nats_even n, },\n    { norm_num, },\n  end\n\n\n  @[simp] theorem sum_2k_sub_one_0_122_1 {n : ℕ} : \n    ∑ (k : ℕ) in finset.range n, (↑2 * (k + 1) - 1 : ℝ) = ↑n ^ 2 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_2k_sub_one_0_122_2 {n : ℕ} : \n    ∑ (k : ℕ) in finset.range n, (↑2 * (k + 1) - 1 : ℝ) ^ 2 = ↑n * (4 * n ^ 2 - 1) / 3 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_2k_sub_one_0_122_3 {n : ℕ} : \n    ∑ (k : ℕ) in finset.range n, (↑2 * (k + 1) - 1 : ℝ) ^ 3 = ↑n ^ 2 * (2 * n ^ 2 - 1) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_mk_sub_one_0_122_4 {m n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (↑m * (k + 1) - 1 : ℝ) = ↑n / 2 * (m * (n + 1) - 2) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_mk_sub_one_0_122_5 {m n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (↑m * (k + 1) - 1 : ℝ) ^ 2 = \n    ↑n / 6 * (m ^ 2 * (n + 1) * (2 * n + 1) - 6 * m * (n + 1)+ 6) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_mk_sub_one_0_122_6 {m n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (↑m * (k + 1) - 1 : ℝ) ^ 3 = \n    ↑n / 4 * (m ^ 3 * n * (n + 1) ^ 2 - 2 * m ^ 2 * (n + 1) * (2 * n + 1) + 6 * m * (n + 1) - 4) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  /- Add the powers of the first n odd integers, and use the sum of powers formula to rewrite as a difference -/\n  theorem sum_2k_sub_one_0_122 {n q : ℕ} :\n    ∑ (k : ℕ) in finset.range n, ((2 : ℚ) * k + 1) ^ q\n    = ∑ (i : ℕ) in finset.range (q + 1),\n      bernoulli i * ↑((q + 1).choose i) * ↑(2 * n) ^ (q + 1 - i) / (q + 1) - \n      2 ^ q * ∑ (i : ℕ) in finset.range (q + 1), bernoulli i * ↑((q + 1).choose i) * ↑n ^ (q + 1 - i) / (↑q + 1) :=\n  begin\n    rw [← sum_integers_0_121, ← sum_integers_0_121, finset.mul_sum],\n    rename_var x k,\n    induction n with n ih,\n    { simp, },\n    {\n      rw [nat.succ_eq_add_one, left_distrib 2 n 1, mul_one],\n      repeat {rw finset.sum_range_succ},\n      rename_var x k,\n      rw ih,\n      have : (2 ^ q : ℚ) * ↑n ^ q = (2 * n) ^ q, by ring_exp,\n      rw [this, sub_eq_add_neg, add_assoc, add_assoc, add_sub_assoc, \n        add_right_inj, ← sub_sub, sub_eq_add_neg, sub_eq_add_neg, \n        add_comm (↑(2 * n) ^ q + ↑(2 * n + 1) ^ q), add_assoc,\n        add_right_inj],\n      field_simp,\n    },\n  end\n\n  @[simp] theorem sum_k_mul_k_add_one_sq_0_123 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (↑k + (1 : ℝ)) * (k + 2) ^ 2 = ↑n / 12 * (n + 1) * (n + 2) * (3 * n + 5) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  theorem sum_k_mul_n_sq_sub_k_sq_0_124_1 (q n k : ℕ) :\n    ∑ (k : ℕ) in finset.range q, (↑k + (1 : ℝ)) * (n ^ 2 - (k + 1) ^ 2) = q / 4 * (q + 1) * (2 * n ^ 2 - q ^ 2 - q) :=\n  begin\n    induction q with q ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_k_mul_k_add_one_cube_0_124_2 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (↑k + (1 : ℝ)) * (k + 2) ^ 3 = ↑n / 60 * (n + 1) * (12 * n ^ 3 + 63 * n ^ 2 + 107 * n + 58) :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih],\n      simp, ring,\n    },\n  end\n\n  @[simp] theorem sum_k_mul_k_fact_0_125 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (↑k : ℝ) * (nat.factorial k) = (nat.factorial n) - 1 :=\n  begin\n    induction n with n ih,\n    { simp, },\n    { rw [finset.sum_range_succ, ih, nat.factorial_succ],\n      simp, ring,\n    },\n  end\n\n  /-\n  TODO : 0_126: Need more development of Bessel functions before proving this one\n  @[simp] theorem sum_0_126 {n k : ℕ} :\n    ∑ (k : ℕ) in finset.range (n + 1), (n + k).factorial / (k.factorial * (n - k).factorial = \n  -/\n\n  @[simp] theorem sum_of_reciprocals_0_131 {n : ℕ} :\n    ∑ (k : ℕ) in finset.range n, (1 : ℝ) / (↑k + 1) = \n    special_constants.γ + real.log n + (1 : ℝ) / (2 * n) -\n    sum\n\n\nend chapter0_1\n\nnamespace chapter0_2\n\nend chapter0_2", "meta": {"author": "mikesha2", "repo": "identitylib", "sha": "6fb9c7913b0b85fafb14f1f34bca0f7af47fa190", "save_path": "github-repos/lean/mikesha2-identitylib", "path": "github-repos/lean/mikesha2-identitylib/identitylib-6fb9c7913b0b85fafb14f1f34bca0f7af47fa190/src/chapter0.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7682501580201306}}
{"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.rotate\n/-!\n\n# Graph connectivity\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\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* `simple_graph.is_bridge` for whether an edge is a bridge edge\n\n## Main statements\n\n* `simple_graph.is_bridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of\n  there being no cycle containing them.\n\n## Tags\nwalks, trails, paths, circuits, cycles, bridge edges\n\n-/\n\nopen function\n\nuniverses u v w\n\nnamespace simple_graph\nvariables {V : Type u} {V' : Type v} {V'' : Type w}\nvariables (G : simple_graph 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 → V → 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\n@[simps] instance walk.inhabited (v : V) : inhabited (G.walk v v) := ⟨walk.nil⟩\n\n/-- The one-edge walk associated to a pair of adjacent vertices. -/\n@[pattern, reducible] def adj.to_walk {G : simple_graph V} {u v : V} (h : G.adj u v) :\n  G.walk u v := walk.cons h walk.nil\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\n/-- Change the endpoints of a walk using equalities. This is helpful for relaxing\ndefinitional equality constraints and to be able to state otherwise difficult-to-state\nlemmas. While this is a simple wrapper around `eq.rec`, it gives a canonical way to write it.\n\nThe simp-normal form is for the `copy` to be pushed outward. That way calculations can\noccur within the \"copy context.\" -/\nprotected def copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') : G.walk u' v' :=\neq.rec (eq.rec p hv) hu\n\n@[simp] lemma copy_rfl_rfl {u v} (p : G.walk u v) :\n  p.copy rfl rfl = p := rfl\n\n@[simp] lemma copy_copy {u v u' v' u'' v''} (p : G.walk u v)\n  (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') :\n  (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') :=\nby { subst_vars, refl }\n\n@[simp] lemma copy_nil {u u'} (hu : u = u') : (walk.nil : G.walk u u).copy hu hu = walk.nil :=\nby { subst_vars, refl }\n\nlemma copy_cons {u v w u' w'} (h : G.adj u v) (p : G.walk v w) (hu : u = u') (hw : w = w') :\n  (walk.cons h p).copy hu hw = walk.cons (by rwa ← hu) (p.copy rfl hw) :=\nby { subst_vars, refl }\n\n@[simp]\nlemma cons_copy {u v w v' w'} (h : G.adj u v) (p : G.walk v' w') (hv : v' = v) (hw : w' = w) :\n  walk.cons h (p.copy hv hw) = (walk.cons (by rwa hv) p).copy rfl hw :=\nby { subst_vars, refl }\n\nlemma exists_eq_cons_of_ne : Π {u v : V} (hne : u ≠ v) (p : G.walk u v),\n  ∃ (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') := ⟨_, h, p', rfl⟩\n\n/-- The length of a walk is the number of edges/darts along it. -/\ndef length : Π {u v : V}, G.walk u v → ℕ\n| _ _ nil := 0\n| _ _ (cons _ q) := q.length.succ\n\n/-- The concatenation of two compatible walks. -/\n@[trans]\ndef append : Π {u v w : V}, G.walk u v → G.walk v w → G.walk u w\n| _ _ _ nil q := q\n| _ _ _ (cons h p) q := cons h (p.append q)\n\n/-- The reversed version of `simple_graph.walk.cons`, concatenating an edge to\nthe end of a walk. -/\ndef concat {u v w : V} (p : G.walk u v) (h : G.adj v w) : G.walk u w := p.append (cons h nil)\n\nlemma concat_eq_append {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  p.concat h = p.append (cons h nil) := rfl\n\n/-- The concatenation of the reverse of the first walk with the second walk. -/\nprotected def reverse_aux : Π {u v w : V}, G.walk u v → G.walk u w → 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 : Π {u v : V} (p : G.walk u v) (n : ℕ), 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 : ℕ} (hi : w.length ≤ 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 : ℕ} (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 : Π {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 : Π {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 append_copy_copy {u v w u' v' w'} (p : G.walk u v) (q : G.walk v w)\n  (hu : u = u') (hv : v = v') (hw : w = w') :\n  (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by { subst_vars, refl }\n\nlemma concat_nil {u v : V} (h : G.adj u v) : nil.concat h = cons h nil := rfl\n\n@[simp] lemma concat_cons {u v w x : V} (h : G.adj u v) (p : G.walk v w) (h' : G.adj w x) :\n  (cons h p).concat h' = cons h (p.concat h') := rfl\n\nlemma append_concat {u v w x : V} (p : G.walk u v) (q : G.walk v w) (h : G.adj w x) :\n  p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _\n\nlemma concat_append {u v w x : V} (p : G.walk u v) (h : G.adj v w) (q : G.walk w x) :\n  (p.concat h).append q = p.append (cons h q) :=\nby rw [concat_eq_append, ← append_assoc, cons_nil_append]\n\n/-- A non-trivial `cons` walk is representable as a `concat` walk. -/\nlemma exists_cons_eq_concat : Π {u v w : V} (h : G.adj u v) (p : G.walk v w),\n  ∃ (x : V) (q : G.walk u x) (h' : G.adj x w), cons h p = q.concat h'\n| _ _ _ h nil := ⟨_, nil, h, rfl⟩\n| _ _ _ h (cons h' p) :=\n  begin\n    obtain ⟨y, q, h'', hc⟩ := exists_cons_eq_concat h' p,\n    refine ⟨y, cons h q, h'', _⟩,\n    rw [concat_cons, hc],\n  end\n\n/-- A non-trivial `concat` walk is representable as a `cons` walk. -/\nlemma exists_concat_eq_cons : Π {u v w : V} (p : G.walk u v) (h : G.adj v w),\n  ∃ (x : V) (h' : G.adj u x) (q : G.walk x w), p.concat h = cons h' q\n| _ _ _ nil h := ⟨_, h, nil, rfl⟩\n| _ _ _ (cons h' p) h := ⟨_, h', walk.concat p h, concat_cons _ _ _⟩\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 : Π {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 : Π {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_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).reverse = p.reverse.copy hv hu := by { subst_vars, refl }\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_concat {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  (p.concat h).reverse = cons (G.symm h) p.reverse :=\nby simp [concat_eq_append]\n\n@[simp] lemma reverse_reverse : Π {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_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).length = p.length :=\nby { subst_vars, refl }\n\n@[simp] lemma length_append : Π {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] lemma length_concat {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  (p.concat h).length = p.length + 1 := length_append _ _\n\n@[simp] protected lemma length_reverse_aux : Π {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 : Π {u v : V} {p : G.walk u v}, p.length = 0 → u = v\n| _ _ nil _ := rfl\n\n@[simp] lemma exists_length_eq_zero_iff {u v : V} : (∃ (p : G.walk u v), p.length = 0) ↔ u = v :=\nbegin\n  split,\n  { rintro ⟨p, hp⟩,\n    exact eq_of_length_eq_zero hp, },\n  { rintro rfl,\n    exact ⟨nil, rfl⟩, },\nend\n\n@[simp] lemma length_eq_zero_iff {u : V} {p : G.walk u u} : p.length = 0 ↔ p = nil :=\nby cases p; simp\n\nsection concat_rec\n\nvariables\n  {motive : Π (u v : V), G.walk u v → Sort*}\n  (Hnil : Π {u : V}, motive u u nil)\n  (Hconcat : Π {u v w : V} (p : G.walk u v) (h : G.adj v w), motive u v p → motive u w (p.concat h))\n\n/-- Auxiliary definition for `simple_graph.walk.concat_rec` -/\ndef concat_rec_aux : Π {u v : V} (p : G.walk u v), motive v u p.reverse\n| _ _ nil := Hnil\n| _ _ (cons h p) := eq.rec (Hconcat p.reverse (G.symm h) (concat_rec_aux p)) (reverse_cons h p).symm\n\n/-- Recursor on walks by inducting on `simple_graph.walk.concat`.\n\nThis is inducting from the opposite end of the walk compared\nto `simple_graph.walk.rec`, which inducts on `simple_graph.walk.cons`. -/\n@[elab_as_eliminator]\ndef concat_rec {u v : V} (p : G.walk u v) : motive u v p :=\neq.rec (concat_rec_aux @Hnil @Hconcat p.reverse) (reverse_reverse p)\n\n@[simp] lemma concat_rec_nil (u : V) :\n  @concat_rec _ _ motive @Hnil @Hconcat _ _ (nil : G.walk u u) = Hnil := rfl\n\n@[simp] lemma concat_rec_concat {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  @concat_rec _ _ motive @Hnil @Hconcat _ _ (p.concat h)\n  = Hconcat p h (concat_rec @Hnil @Hconcat p) :=\nbegin\n  simp only [concat_rec],\n  apply eq_of_heq,\n  apply rec_heq_of_heq,\n  transitivity concat_rec_aux @Hnil @Hconcat (cons h.symm p.reverse),\n  { congr, simp },\n  { rw [concat_rec_aux, rec_heq_iff_heq],\n    congr; simp [heq_rec_iff_heq], }\nend\n\nend concat_rec\n\nlemma concat_ne_nil {u v : V} (p : G.walk u v) (h : G.adj v u) :\n  p.concat h ≠ nil :=\nby cases p; simp [concat]\n\nlemma concat_inj {u v v' w : V}\n  {p : G.walk u v} {h : G.adj v w} {p' : G.walk u v'} {h' : G.adj v' w}\n  (he : p.concat h = p'.concat h') :\n  ∃ (hv : v = v'), p.copy rfl hv = p' :=\nbegin\n  induction p,\n  { cases p',\n    { exact ⟨rfl, rfl⟩ },\n    { exfalso,\n      simp only [concat_nil, concat_cons] at he,\n      obtain ⟨rfl, he⟩ := he,\n      simp only [heq_iff_eq] at he,\n      exact concat_ne_nil _ _ he.symm, } },\n  { rw concat_cons at he,\n    cases p',\n    { exfalso,\n      simp only [concat_nil] at he,\n      obtain ⟨rfl, he⟩ := he,\n      rw [heq_iff_eq] at he,\n      exact concat_ne_nil _ _ he, },\n    { rw concat_cons at he,\n      simp only at he,\n      obtain ⟨rfl, he⟩ := he,\n      rw [heq_iff_eq] at he,\n      obtain ⟨rfl, rfl⟩ := p_ih he,\n      exact ⟨rfl, rfl⟩, } }\nend\n\n/-- The `support` of a walk is the list of vertices it visits in order. -/\ndef support : Π {u v : V}, G.walk u v → 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 : Π {u v : V}, G.walk u v → list G.dart\n| u v nil := []\n| u v (cons h p) := ⟨(u, _), h⟩ :: 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\n@[simp] lemma support_concat {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  (p.concat h).support = p.support.concat w := by induction p; simp [*, concat_nil]\n\n@[simp] lemma support_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).support = p.support := by { subst_vars, refl }\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 ≠ [] :=\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 ∈ p.support :=\nby cases p; simp\n\n@[simp] lemma end_mem_support {u v : V} (p : G.walk u v) : v ∈ p.support :=\nby induction p; simp [*]\n\n@[simp] lemma support_nonempty {u v : V} (p : G.walk u v) : {w | w ∈ p.support}.nonempty :=\n⟨u, by simp⟩\n\nlemma mem_support_iff {u v w : V} (p : G.walk u v) :\n  w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail :=\nby cases p; simp\n\nlemma mem_support_nil_iff {u v : V} : u ∈ (nil : G.walk v v).support ↔ 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 ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ 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 ≠ v) (p : G.walk u v) :\n  v ∈ p.support.tail :=\nby { obtain ⟨_, _, _, rfl⟩ := 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 ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ 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\n@[simp]\nlemma subset_support_append_left {V : Type u} {G : simple_graph V} {u v w : V}\n  (p : G.walk u v) (q : G.walk v w) :\n  p.support ⊆ (p.append q).support :=\nby simp only [walk.support_append, list.subset_append_left]\n\n@[simp]\nlemma subset_support_append_right {V : Type u} {G : simple_graph V} {u v w : V}\n  (p : G.walk u v) (q : G.walk v w) :\n  q.support ⊆ (p.append q).support :=\nby { intro h, simp only [mem_support_append_iff, or_true, implies_true_iff] { contextual := tt }}\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, ←multiset.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, ←multiset.coe_add],\n  simp only [coe_support],\n  rw add_comm {v},\n  simp only [← add_assoc, add_tsub_cancel_right],\nend\n\nlemma chain_adj_support : Π {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 : Π {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 : Π {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 : Π {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 `⊆`) to avoid unsightly coercions. -/\nlemma edges_subset_edge_set : Π {u v : V} (p : G.walk u v) ⦃e : sym2 V⦄\n  (h : e ∈ p.edges), e ∈ G.edge_set\n| _ _ (cons h' p') e h := by rcases h with ⟨rfl, h⟩; solve_by_elim\n\nlemma adj_of_mem_edges {u v x y : V} (p : G.walk u v) (h : ⟦(x, y)⟧ ∈ p.edges) : G.adj x y :=\nedges_subset_edge_set p h\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 = ⟨(u, v), h⟩ :: p.darts := rfl\n\n@[simp] lemma darts_concat {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p; simp [*, concat_nil]\n\n@[simp] lemma darts_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).darts = p.darts := by { subst_vars, refl }\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 mem_darts_reverse {u v : V} {d : G.dart} {p : G.walk u v} :\n  d ∈ p.reverse.darts ↔ d.symm ∈ p.darts :=\nby simp\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 = ⟦(u, v)⟧ :: p.edges := rfl\n\n@[simp] lemma edges_concat {u v w : V} (p : G.walk u v) (h : G.adj v w) :\n  (p.concat h).edges = p.edges.concat ⟦(v, w)⟧ := by simp [edges]\n\n@[simp] lemma edges_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).edges = p.edges := by { subst_vars, refl }\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  Π {u v : V} (p : G.walk u v) {d : G.dart}, d ∈ p.darts → d.fst ∈ p.support\n| u v (cons h p') d hd := begin\n  simp only [support_cons, darts_cons, list.mem_cons_iff] at hd ⊢,\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 {u v : V} (p : G.walk u v) {d : G.dart} (h : d ∈ p.darts) :\n  d.snd ∈ p.support :=\nby simpa using p.reverse.dart_fst_mem_support_of_mem_darts (by simp [h] : d.symm ∈ p.reverse.darts)\n\nlemma fst_mem_support_of_mem_edges {t u v w : V} (p : G.walk v w) (he : ⟦(t, u)⟧ ∈ p.edges) :\n  t ∈ p.support :=\nbegin\n  obtain ⟨d, hd, he⟩ := list.mem_map.mp he,\n  rw dart_edge_eq_mk_iff' at he,\n  rcases he with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩,\n  { exact dart_fst_mem_support_of_mem_darts _ hd, },\n  { exact dart_snd_mem_support_of_mem_darts _ hd, },\nend\n\nlemma snd_mem_support_of_mem_edges {t u v w : V} (p : G.walk v w) (he : ⟦(t, u)⟧ ∈ p.edges) :\n  u ∈ p.support :=\nby { rw sym2.eq_swap at he, exact p.fst_mem_support_of_mem_edges he }\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 ⊢,\n    refine ⟨λ h', h.1 (dart_fst_mem_support_of_mem_darts p_p h'), p_ih h.2⟩, }\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 ⊢,\n    exact ⟨λ h', h.1 (fst_mem_support_of_mem_edges p_p h'), p_ih h.2⟩, }\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 ≠ 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 ↔ p.edges.nodup :=\n⟨is_trail.edges_nodup, λ h, ⟨h⟩⟩\n\n@[simp] lemma is_trail_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).is_trail ↔ p.is_trail := by { subst_vars, refl }\n\nlemma is_path.mk' {u v : V} {p : G.walk u v} (h : p.support.nodup) : is_path p :=\n⟨⟨edges_nodup_of_support_nodup h⟩, h⟩\n\nlemma is_path_def {u v : V} (p : G.walk u v) : p.is_path ↔ p.support.nodup :=\n⟨is_path.support_nodup, is_path.mk'⟩\n\n@[simp] lemma is_path_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).is_path ↔ p.is_path := by { subst_vars, refl }\n\nlemma is_circuit_def {u : V} (p : G.walk u u) :\n  p.is_circuit ↔ is_trail p ∧ p ≠ nil :=\niff.intro (λ h, ⟨h.1, h.2⟩) (λ h, ⟨h.1, h.2⟩)\n\n@[simp] lemma is_circuit_copy {u u'} (p : G.walk u u) (hu : u = u') :\n  (p.copy hu hu).is_circuit ↔ p.is_circuit := by { subst_vars, refl }\n\nlemma is_cycle_def {u : V} (p : G.walk u u) :\n  p.is_cycle ↔ is_trail p ∧ p ≠ nil ∧ p.support.tail.nodup :=\niff.intro (λ h, ⟨h.1.1, h.1.2, h.2⟩) (λ h, ⟨⟨h.1, h.2.1⟩, h.2.2⟩)\n\n@[simp] lemma is_cycle_copy {u u'} (p : G.walk u u) (hu : u = u') :\n  (p.copy hu hu).is_cycle ↔ p.is_cycle := by { subst_vars, refl }\n\n@[simp] lemma is_trail.nil {u : V} : (nil : G.walk u u).is_trail :=\n⟨by simp [edges]⟩\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 → 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 ↔ p.is_trail ∧ ⟦(u, v)⟧ ∉ 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 ↔ 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 ⟨h.1⟩ }\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 ⟨h.2.1⟩ }\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 ≤ 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 ∈ p.edges) :\n  p.edges.count e = 1 :=\nlist.count_eq_one_of_mem h.edges_nodup he\n\nlemma 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 → 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 ↔ p.is_path ∧ u ∉ p.support :=\nby split; simp [is_path_def] { contextual := tt }\n\n@[simp] lemma is_path_iff_eq_nil {u : V} (p : G.walk u u) : p.is_path ↔ p = nil :=\nby { cases p; simp [is_path.nil] }\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 ↔ 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 → 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 ←is_path_reverse_iff at h ⊢,\n  rw reverse_append at h,\n  apply h.of_append_left,\nend\n\n@[simp] lemma is_cycle.not_of_nil {u : V} : ¬ (nil : G.walk u u).is_cycle :=\nλ h, h.ne_nil rfl\n\nlemma cons_is_cycle_iff {u v : V} (p : G.walk v u) (h : G.adj u v) :\n  (walk.cons h p).is_cycle ↔ p.is_path ∧ ¬ ⟦(u, v)⟧ ∈ p.edges :=\nbegin\n  simp only [walk.is_cycle_def, walk.is_path_def, walk.is_trail_def, edges_cons, list.nodup_cons,\n             support_cons, list.tail_cons],\n  have : p.support.nodup → p.edges.nodup := edges_nodup_of_support_nodup,\n  tauto,\nend\n\n/-! ### About paths -/\n\ninstance [decidable_eq V] {u v : V} (p : G.walk u v) : decidable p.is_path :=\nby { rw is_path_def, apply_instance }\n\nlemma is_path.length_lt [fintype V] {u v : V} {p : G.walk u v} (hp : p.is_path) :\n  p.length < fintype.card V :=\nby { rw [nat.lt_iff_add_one_le, ← length_support], exact hp.support_nodup.length_le_card }\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 : Π {v w : V} (p : G.walk v w) (u : V) (h : u ∈ 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 (λ 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 : Π {v w : V} (p : G.walk v w) (u : V) (h : u ∈ 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 (λ 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 ∈ 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\nlemma mem_support_iff_exists_append {V : Type u} {G : simple_graph V} {u v w : V}\n  {p : G.walk u v} :\n  w ∈ p.support ↔ ∃ (q : G.walk u w) (r : G.walk w v), p = q.append r :=\nbegin\n  classical,\n  split,\n  { exact λ h, ⟨_, _, (p.take_spec h).symm⟩ },\n  { rintro ⟨q, r, rfl⟩,\n    simp only [mem_support_append_iff, end_mem_support, start_mem_support, or_self], },\nend\n\n@[simp]\nlemma count_support_take_until_eq_one {u v w : V} (p : G.walk v w) (h : u ∈ 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 ∈ p.support) (x : V) :\n  (p.take_until u h).edges.count ⟦(u, x)⟧ ≤ 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 (⟨rfl,rfl⟩|⟨rfl,rfl⟩) := h'',\n          { exact (h' rfl).elim },\n          { cases p'; simp! } },\n        { apply ih, } } } },\nend\n\n@[simp] lemma take_until_copy {u v w v' w'} (p : G.walk v w)\n  (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) :\n  (p.copy hv hw).take_until u h = (p.take_until u (by { subst_vars, exact h })).copy hv rfl :=\nby { subst_vars, refl }\n\n@[simp] lemma drop_until_copy {u v w v' w'} (p : G.walk v w)\n  (hv : v = v') (hw : w = w') (h : u ∈ (p.copy hv hw).support) :\n  (p.copy hv hw).drop_until u h = (p.drop_until u (by { subst_vars, exact h })).copy rfl hw :=\nby { subst_vars, refl }\n\nlemma support_take_until_subset {u v w : V} (p : G.walk v w) (h : u ∈ p.support) :\n  (p.take_until u h).support ⊆ p.support :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.drop_until u h).support ⊆ p.support :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.take_until u h).darts ⊆ p.darts :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.drop_until u h).darts ⊆ p.darts :=\nλ x hx, by { rw [← 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 ∈ p.support) :\n  (p.take_until u h).edges ⊆ 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 ∈ p.support) :\n  (p.drop_until u h).edges ⊆ 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 ∈ p.support) :\n  (p.take_until u h).length ≤ 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 ∈ p.support) :\n  (p.drop_until u h).length ≤ 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 ∈ p.support) :\n  (p.take_until u h).is_trail :=\nis_trail.of_append_left (by rwa ← 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 ∈ p.support) :\n  (p.drop_until u h).is_trail :=\nis_trail.of_append_right (by rwa ← 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 ∈ p.support) :\n  (p.take_until u h).is_path :=\nis_path.of_append_left (by rwa ← 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 ∈ p.support) :\n  (p.drop_until u h).is_path :=\nis_path.of_append_right (by rwa ← 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 ∈ 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 ∈ 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 [←tail_support_append, take_spec],\nend\n\nlemma rotate_darts {u v : V} (c : G.walk v v) (h : u ∈ 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 [←darts_append, take_spec],\nend\n\nlemma rotate_edges {u v : V} (c : G.walk v v) (h : u ∈ 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 ∈ 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 ∈ c.support) :\n  (c.rotate h).is_circuit :=\nbegin\n  refine ⟨hc.to_trail.rotate _, _⟩,\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, ← 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 ∈ c.support) :\n  (c.rotate h).is_cycle :=\nbegin\n  refine ⟨hc.to_circuit.rotate _, _⟩,\n  rw list.is_rotated.nodup_iff (support_rotate _ _),\n  exact hc.support_nodup,\nend\n\nend walk_decomp\n\n/--\nGiven a set `S` and a walk `w` from `u` to `v` such that `u ∈ S` but `v ∉ S`,\nthere exists a dart in the walk whose start is in `S` but whose end is not.\n-/\nlemma exists_boundary_dart\n  {u v : V} (p : G.walk u v) (S : set V) (uS : u ∈ S) (vS : v ∉ S) :\n  ∃ (d : G.dart), d ∈ p.darts ∧ d.fst ∈ S ∧ d.snd ∉ S :=\nbegin\n  induction p with _ x y w a p' ih,\n  { exact absurd uS vS },\n  { by_cases h : y ∈ S,\n    { obtain ⟨d, hd, hcd⟩ := ih h vS,\n      exact ⟨d, or.inr hd, hcd⟩ },\n    { exact ⟨⟨(x, y), a⟩, or.inl rfl, uS, h⟩ } }\nend\n\n\nend walk\n\n/-! ### Type of 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 path\nvariables {G G'}\n\n@[simp] protected lemma is_path {u v : V} (p : G.path u v) : (p : G.walk u v).is_path :=\np.property\n\n@[simp] protected lemma is_trail {u v : V} (p : G.path u v) : (p : G.walk u v).is_trail :=\np.property.to_trail\n\n/-- The length-0 path at a vertex. -/\n@[refl, simps] protected def nil {u : V} : G.path u u := ⟨walk.nil, walk.is_path.nil⟩\n\n/-- The length-1 path between a pair of adjacent vertices. -/\n@[simps] def singleton {u v : V} (h : G.adj u v) : G.path u v :=\n⟨walk.cons h walk.nil, by simp [h.ne]⟩\n\nlemma mk_mem_edges_singleton {u v : V} (h : G.adj u v) :\n  ⟦(u, v)⟧ ∈ (singleton h : G.walk u v).edges := by simp [singleton]\n\n/-- The reverse of a path is another path.  See also `simple_graph.walk.reverse`. -/\n@[symm, simps] def reverse {u v : V} (p : G.path u v) : G.path v u :=\n⟨walk.reverse p, p.property.reverse⟩\n\n\n\nlemma count_edges_eq_one [decidable_eq V] {u v : V} {p : G.path u v} (e : sym2 V)\n  (hw : e ∈ (p : G.walk u v).edges) : (p : G.walk u v).edges.count e = 1 :=\nlist.count_eq_one_of_mem p.property.to_trail.edges_nodup hw\n\n@[simp] lemma nodup_support {u v : V} (p : G.path u v) : (p : G.walk u v).support.nodup :=\n(walk.is_path_def _).mp p.property\n\nlemma loop_eq {v : V} (p : G.path v v) : p = path.nil :=\nbegin\n  obtain ⟨_|_, this⟩ := p,\n  { refl },\n  { simpa },\nend\n\nlemma not_mem_edges_of_loop {v : V} {e : sym2 V} {p : G.path v v} :\n  ¬ e ∈ (p : G.walk v v).edges :=\nby simp [p.loop_eq]\n\nlemma cons_is_cycle {u v : V} (p : G.path v u) (h : G.adj u v)\n  (he : ¬ ⟦(u, v)⟧ ∈ (p : G.walk v u).edges) : (walk.cons h ↑p).is_cycle :=\nby simp [walk.is_cycle_def, walk.cons_is_trail_iff, he]\n\nend path\n\n/-! ### Walks to paths -/\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 : Π {u v : V}, G.walk u v → 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 ∈ p'.support\n     then p'.drop_until u hs\n     else cons ha p'\n\n@[simp] lemma bypass_copy {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).bypass = p.bypass.copy hu hv := by { subst_vars, refl }\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 ≤ 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 := ⟨p.bypass, p.bypass_is_path⟩\n\nlemma support_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.support ⊆ 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 ⊆ p.support :=\nsupport_bypass_subset _\n\nlemma darts_bypass_subset {u v : V} (p : G.walk u v) : p.bypass.darts ⊆ 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 ⊆ 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 ⊆ 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 ⊆ p.edges :=\nedges_bypass_subset _\n\nend walk\n\n/-! ### Mapping paths -/\n\nnamespace walk\nvariables {G G' G''}\n\n/-- Given a graph homomorphism, map walks to walks. -/\nprotected def map (f : G →g G') : Π {u v : V}, G.walk u v → G'.walk (f u) (f v)\n| _ _ nil := nil\n| _ _ (cons h p) := cons (f.map_adj h) (map p)\n\nvariables (f : G →g G') (f' : G' →g G'') {u v 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 map_copy (hu : u = u') (hv : v = v') :\n  (p.copy hu hv).map f = (p.map f).copy (by rw hu) (by rw hv) := by { subst_vars, refl }\n\n@[simp] lemma map_id (p : G.walk u v) : p.map hom.id = p := by { induction p; simp [*] }\n\n@[simp] lemma map_map : (p.map f).map f' = p.map (f'.comp f) := by { induction p; simp [*] }\n\n/-- Unlike categories, for graphs vertex equality is an important notion, so needing to be able to\nto work with equality of graph homomorphisms is a necessary evil. -/\nlemma map_eq_of_eq {f : G →g G'} (f' : G →g G') (h : f = f') :\n  p.map f = (p.map f').copy (by rw h) (by rw h) := by { subst_vars, refl }\n\n@[simp] lemma map_eq_nil_iff {p : G.walk u u} : p.map f = nil ↔ p = nil :=\nby cases p; simp\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 →g 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 ⟨ih hp1, _⟩,\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 ↔ p.is_path :=\n⟨is_path.of_map, map_is_path_of_injective hinj⟩\n\nlemma map_is_trail_iff_of_injective (hinj : function.injective f) :\n  (p.map f).is_trail ↔ p.is_trail :=\nbegin\n  induction p with w u v w huv hvw ih,\n  { simp },\n  { rw [map_cons, cons_is_trail_iff, cons_is_trail_iff, edges_map],\n    change _ ∧ sym2.map f ⟦(u, v)⟧ ∉ _ ↔ _,\n    rw list.mem_map_of_injective (sym2.map.injective hinj),\n    exact and_congr_left' ih, },\nend\n\nalias map_is_trail_iff_of_injective ↔ _ map_is_trail_of_injective\n\nlemma map_is_cycle_iff_of_injective {p : G.walk u u} (hinj : function.injective f) :\n  (p.map f).is_cycle ↔ p.is_cycle :=\nby rw [is_cycle_def, is_cycle_def, map_is_trail_iff_of_injective hinj, ne.def, map_eq_nil_iff,\n       support_map, ← list.map_tail, list.nodup_map_iff hinj]\n\nalias map_is_cycle_iff_of_injective ↔ _ map_is_cycle_of_injective\n\nvariables (p f)\n\nlemma map_injective_of_injective {f : G →g G'} (hinj : function.injective f) (u v : V) :\n  function.injective (walk.map f : G.walk u v → 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\n/-- The specialization of `simple_graph.walk.map` for mapping walks to supergraphs. -/\n@[reducible] def map_le {G G' : simple_graph V} (h : G ≤ G') {u v : V} (p : G.walk u v) :\n  G'.walk u v := p.map (hom.map_spanning_subgraphs h)\n\n@[simp] lemma map_le_is_trail {G G' : simple_graph V} (h : G ≤ G') {u v : V} {p : G.walk u v} :\n  (p.map_le h).is_trail ↔ p.is_trail := map_is_trail_iff_of_injective (function.injective_id)\n\nalias map_le_is_trail ↔ is_trail.of_map_le is_trail.map_le\n\n@[simp] lemma map_le_is_path {G G' : simple_graph V} (h : G ≤ G') {u v : V} {p : G.walk u v} :\n  (p.map_le h).is_path ↔ p.is_path := map_is_path_iff_of_injective (function.injective_id)\n\nalias map_le_is_path ↔ is_path.of_map_le is_path.map_le\n\n@[simp] lemma map_le_is_cycle {G G' : simple_graph V} (h : G ≤ G') {u : V} {p : G.walk u u} :\n  (p.map_le h).is_cycle ↔ p.is_cycle := map_is_cycle_iff_of_injective (function.injective_id)\n\nalias map_le_is_cycle ↔ is_cycle.of_map_le is_cycle.map_le\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 →g G') (hinj : function.injective f) {u v : V} (p : G.path u v) :\n  G'.path (f u) (f v) :=\n⟨walk.map f p, walk.map_is_path_of_injective hinj p.2⟩\n\nlemma map_injective {f : G →g G'} (hinj : function.injective f) (u v : V) :\n  function.injective (path.map f hinj : G.path u v → G'.path (f u) (f v)) :=\nbegin\n  rintros ⟨p, hp⟩ ⟨p', hp'⟩ 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 ↪g 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 ↪g G') (u v : V) :\n  function.injective (path.map_embedding f : G.path u v → G'.path (f u) (f v)) :=\nmap_injective f.injective u v\n\nend path\n\n/-! ### Transferring between graphs -/\n\nnamespace walk\n\nvariables {G}\n\n/-- The walk `p` transferred to lie in `H`, given that `H` contains its edges. -/\n@[protected, simp] def transfer : Π {u v : V} (p : G.walk u v) (H : simple_graph V)\n  (h : ∀ e, e ∈ p.edges → e ∈ H.edge_set), H.walk u v\n| _ _ (walk.nil) H h := walk.nil\n| _ _ (walk.cons' u v w a p) H h :=\n  walk.cons (h (⟦(u, v)⟧ : sym2 V) (by simp)) (p.transfer H (λ e he, h e (by simp [he])))\n\nvariables {u v w : V} (p : G.walk u v) (q : G.walk v w)\n  {H : simple_graph V}\n  (hp : ∀ e, e ∈ p.edges → e ∈ H.edge_set)\n  (hq : ∀ e, e ∈ q.edges → e ∈ H.edge_set)\n\nlemma transfer_self : p.transfer G p.edges_subset_edge_set = p :=\nby { induction p; simp only [*, transfer, eq_self_iff_true, heq_iff_eq, and_self], }\n\nlemma transfer_eq_map_of_le (GH : G ≤ H) :\n  p.transfer H hp = p.map (simple_graph.hom.map_spanning_subgraphs GH) :=\nby { induction p; simp only [*, transfer, map_cons, hom.map_spanning_subgraphs_apply,\n                             eq_self_iff_true, heq_iff_eq, and_self, map_nil], }\n\n@[simp] lemma edges_transfer : (p.transfer H hp).edges = p.edges :=\nby { induction p; simp only [*, transfer, edges_nil, edges_cons, eq_self_iff_true, and_self], }\n\n@[simp] lemma support_transfer : (p.transfer H hp).support = p.support :=\nby { induction p; simp only [*, transfer, eq_self_iff_true, and_self, support_nil, support_cons], }\n\n@[simp] lemma length_transfer : (p.transfer H hp).length = p.length :=\nby induction p; simp [*]\n\nvariables {p}\n\nprotected lemma is_path.transfer (pp : p.is_path) : (p.transfer H hp).is_path :=\nbegin\n  induction p;\n  simp only [transfer, is_path.nil, cons_is_path_iff, support_transfer] at pp ⊢,\n  { tauto, },\nend\n\nprotected lemma is_cycle.transfer {p : G.walk u u} (pc : p.is_cycle) (hp) :\n  (p.transfer H hp).is_cycle :=\nbegin\n  cases p;\n  simp only [transfer, is_cycle.not_of_nil, cons_is_cycle_iff, transfer, edges_transfer] at pc ⊢,\n  { exact pc, },\n  { exact ⟨pc.left.transfer _, pc.right⟩, },\nend\n\nvariables (p)\n\n@[simp] lemma transfer_transfer {K : simple_graph V} (hp' : ∀ e, e ∈ p.edges → e ∈ K.edge_set) :\n  (p.transfer H hp).transfer K (by { rw p.edges_transfer hp, exact hp', }) = p.transfer K hp' :=\nby { induction p; simp only [transfer, eq_self_iff_true, heq_iff_eq, true_and], apply p_ih, }\n\n@[simp] lemma transfer_append (hpq) :\n  (p.append q).transfer H hpq =\n  (p.transfer H (λ e he, by { apply hpq, simp [he] })).append\n    (q.transfer H (λ e he, by { apply hpq, simp [he] })) :=\nbegin\n  induction p;\n  simp only [transfer, nil_append, cons_append, eq_self_iff_true, heq_iff_eq, true_and],\n  apply p_ih,\nend\n\n@[simp] lemma reverse_transfer :\n  (p.transfer H hp).reverse =\n  p.reverse.transfer H (by { simp only [edges_reverse, list.mem_reverse], exact hp, }) :=\nbegin\n  induction p;\n  simp only [*, transfer_append, transfer, reverse_nil, reverse_cons],\n  refl,\nend\n\nend walk\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@[reducible]\ndef to_delete_edges (s : set (sym2 V))\n  {v w : V} (p : G.walk v w) (hp : ∀ e, e ∈ p.edges → ¬ e ∈ s) : (G.delete_edges s).walk v w :=\np.transfer _ (by\n  { simp only [edge_set_delete_edges, set.mem_diff],\n    exact λ e ep, ⟨edges_subset_edge_set p ep, hp e ep⟩, })\n\n@[simp] lemma to_delete_edges_nil (s : set (sym2 V)) {v : V} (hp) :\n  (walk.nil : G.walk v v).to_delete_edges s hp = walk.nil := rfl\n\n@[simp] lemma to_delete_edges_cons (s : set (sym2 V))\n  {u v w : V} (h : G.adj u v) (p : G.walk v w) (hp) :\n  (walk.cons h p).to_delete_edges s hp =\n    walk.cons ⟨h, hp _ (or.inl rfl)⟩ (p.to_delete_edges s $ λ _ he, hp _ $ or.inr he) := rfl\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 ∉ p.edges) :\n  (G.delete_edges {e}).walk v w :=\np.to_delete_edges {e} (λ 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 rw [←transfer_eq_map_of_le, transfer_transfer, transfer_self]\n\nprotected lemma 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 := h.transfer _\n\nprotected lemma is_cycle.to_delete_edges (s : set (sym2 V))\n  {v : V} {p : G.walk v v} (h : p.is_cycle) (hp) :\n  (p.to_delete_edges s hp).is_cycle := h.transfer _\n\n@[simp] lemma to_delete_edges_copy (s : set (sym2 V))\n  {u v u' v'} (p : G.walk u v) (hu : u = u') (hv : v = v') (h) :\n  (p.copy hu hv).to_delete_edges s h\n    = (p.to_delete_edges s (by { subst_vars, exact h })).copy hu hv :=\nby { subst_vars, refl }\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 ↔ (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 → 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 → p) : p :=\nbegin\n  classical,\n  exact h.elim (λ q, hp q.to_path),\nend\n\nprotected lemma walk.reachable {G : simple_graph V} {u v : V} (p : G.walk u v) :\n  G.reachable u v := ⟨p⟩\n\nprotected lemma adj.reachable {u v : V} (h : G.adj u v) :\n  G.reachable u v := h.to_walk.reachable\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 (λ p, ⟨p.reverse⟩)\n\nlemma reachable_comm {u v : V} : G.reachable u v ↔ G.reachable v u :=\n⟨reachable.symm, reachable.symm⟩\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 (λ puv, hvw.elim (λ pvw, ⟨puv.append pvw⟩))\n\nlemma reachable_iff_refl_trans_gen (u v : V) :\n  G.reachable u v ↔ relation.refl_trans_gen G.adj u v :=\nbegin\n  split,\n  { rintro ⟨h⟩,\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 ⟨walk.cons ha walk.nil⟩, }, },\nend\n\nprotected lemma reachable.map {G : simple_graph V} {G' : simple_graph V'}\n  (f : G →g G') {u v : V} (h : G.reachable u v) : G'.reachable (f u) (f v) :=\nh.elim (λ p, ⟨p.map f⟩)\n\nlemma iso.reachable_iff {G : simple_graph V} {G' : simple_graph V'}\n  {φ : G ≃g G'} {u v : V} : G'.reachable (φ u) (φ v) ↔ G.reachable u v :=\n⟨λ r, (φ.left_inv u) ▸ (φ.left_inv v) ▸ (r.map φ.symm.to_hom), reachable.map φ.to_hom⟩\n\nlemma iso.symm_apply_reachable {G : simple_graph V} {G' : simple_graph V'}\n  {φ : G ≃g G'} {u : V} {v : V'} : G.reachable (φ.symm v) u ↔ G'.reachable v (φ u) :=\nby rw [← iso.reachable_iff, rel_iso.apply_symm_apply]\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 := ∀ (u v : V), G.reachable u v\n\nlemma preconnected.map {G : simple_graph V} {H : simple_graph V'} (f : G →g H) (hf : surjective f)\n  (hG : G.preconnected) : H.preconnected :=\nhf.forall₂.2 $ λ a b, nonempty.map (walk.map _) $ hG _ _\n\nlemma iso.preconnected_iff {G : simple_graph V} {H : simple_graph V'} (e : G ≃g H) :\n  G.preconnected ↔ H.preconnected :=\n⟨preconnected.map e.to_hom e.to_equiv.surjective,\n  preconnected.map e.symm.to_hom e.symm.to_equiv.surjective⟩\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, mk_iff]\nstructure connected : Prop :=\n(preconnected : G.preconnected)\n[nonempty : nonempty V]\n\ninstance : has_coe_to_fun G.connected (λ _, Π (u v : V), G.reachable u v) :=\n⟨λ h, h.preconnected⟩\n\nlemma connected.map {G : simple_graph V} {H : simple_graph V'} (f : G →g H) (hf : surjective f)\n  (hG : G.connected) : H.connected :=\nby { haveI := hG.nonempty.map f, exact ⟨hG.preconnected.map f hf⟩ }\n\nlemma iso.connected_iff {G : simple_graph V} {H : simple_graph V'} (e : G ≃g H) :\n  G.connected ↔ H.connected :=\n⟨connected.map e.to_hom e.to_equiv.surjective,\n  connected.map e.symm.to_hom e.symm.to_equiv.surjective⟩\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\nvariables {V' G G' G''}\n\nnamespace connected_component\n\n@[simps] instance inhabited [inhabited V] : inhabited G.connected_component :=\n⟨G.connected_component_mk default⟩\n\n@[elab_as_eliminator]\nprotected lemma ind {β : G.connected_component → Prop}\n  (h : ∀ (v : V), β (G.connected_component_mk v)) (c : G.connected_component) : β c :=\nquot.ind h c\n\n@[elab_as_eliminator]\nprotected lemma ind₂ {β : G.connected_component → G.connected_component → Prop}\n  (h : ∀ (v w : V), β (G.connected_component_mk v) (G.connected_component_mk w))\n  (c d : G.connected_component) : β c d :=\nquot.induction_on₂ c d h\n\nprotected lemma sound {v w : V} :\n  G.reachable v w → G.connected_component_mk v = G.connected_component_mk w := quot.sound\n\nprotected lemma exact {v w : V} :\n  G.connected_component_mk v = G.connected_component_mk w → G.reachable v w :=\n@quotient.exact _ G.reachable_setoid _ _\n\n@[simp] protected lemma eq {v w : V} :\n  G.connected_component_mk v = G.connected_component_mk w ↔ G.reachable v w :=\n@quotient.eq _ G.reachable_setoid _ _\n\nlemma connected_component_mk_eq_of_adj {v w : V} (a : G.adj v w) :\n  G.connected_component_mk v = G.connected_component_mk w :=\nconnected_component.sound a.reachable\n\n/-- The `connected_component` specialization of `quot.lift`. Provides the stronger\nassumption that the vertices are connected by a path. -/\nprotected def lift {β : Sort*} (f : V → β)\n  (h : ∀ (v w : V) (p : G.walk v w), p.is_path → f v = f w) : G.connected_component → β :=\nquot.lift f (λ v w (h' : G.reachable v w), h'.elim_path (λ hp, h v w hp hp.2))\n\n@[simp] protected lemma lift_mk {β : Sort*} {f : V → β}\n  {h : ∀ (v w : V) (p : G.walk v w), p.is_path → f v = f w} {v : V} :\n  connected_component.lift f h (G.connected_component_mk v) = f v := rfl\n\nprotected lemma «exists» {p : G.connected_component → Prop} :\n  (∃ (c : G.connected_component), p c) ↔ ∃ v, p (G.connected_component_mk v) :=\n(surjective_quot_mk G.reachable).exists\n\nprotected lemma «forall» {p : G.connected_component → Prop} :\n  (∀ (c : G.connected_component), p c) ↔ ∀ v, p (G.connected_component_mk v) :=\n(surjective_quot_mk G.reachable).forall\n\nlemma _root_.simple_graph.preconnected.subsingleton_connected_component (h : G.preconnected) :\n  subsingleton G.connected_component :=\n⟨connected_component.ind₂ (λ v w, connected_component.sound (h v w))⟩\n\n/-- The map on connected components induced by a graph homomorphism. -/\ndef map (φ : G →g G') (C : G.connected_component) : G'.connected_component :=\nC.lift (λ v, G'.connected_component_mk (φ v)) $ λ v w p _,\n  connected_component.eq.mpr (p.map φ).reachable\n\n@[simp] lemma map_mk (φ : G →g G') (v : V) :\n  (G.connected_component_mk v).map φ = G'.connected_component_mk (φ v) := rfl\n\n@[simp] lemma map_id (C : connected_component G) : C.map hom.id = C :=\nby { refine C.ind _, exact (λ _, rfl) }\n\n@[simp] lemma map_comp (C : G.connected_component)\n  (φ : G →g G') (ψ : G' →g G'') : (C.map φ).map ψ = C.map (ψ.comp φ) :=\nby { refine C.ind _, exact (λ _, rfl), }\n\n\nvariables {φ : G ≃g G'} {v : V} {v' : V'}\n\n@[simp] lemma iso_image_comp_eq_map_iff_eq_comp\n  {C : G.connected_component} :\n  G'.connected_component_mk (φ v) = C.map (↑(↑φ : G ↪g G'))  ↔ (G.connected_component_mk v) = C :=\nbegin\n  refine C.ind (λ u, _),\n  simp only [iso.reachable_iff, connected_component.map_mk,\n    rel_embedding.coe_coe_fn, rel_iso.coe_coe_fn, connected_component.eq],\nend\n\n@[simp] lemma iso_inv_image_comp_eq_iff_eq_map\n  {C : G.connected_component} :\n  G.connected_component_mk (φ.symm v') = C ↔\n    G'.connected_component_mk v' = C.map φ :=\nbegin\n  refine C.ind (λ u, _),\n  simp only [iso.symm_apply_reachable, connected_component.eq, coe_coe,\n    connected_component.map_mk, rel_embedding.coe_coe_fn, rel_iso.coe_coe_fn],\nend\n\nend connected_component\n\nnamespace iso\n\n/-- An isomorphism of graphs induces a bijection of connected components. -/\n@[simps]\ndef connected_component_equiv (φ : G ≃g G') : G.connected_component ≃ G'.connected_component :=\n{ to_fun := connected_component.map φ,\n  inv_fun := connected_component.map φ.symm,\n  left_inv := λ C, connected_component.ind\n    (λ v, congr_arg (G.connected_component_mk) (equiv.left_inv φ.to_equiv v)) C,\n  right_inv := λ C, connected_component.ind\n    (λ v, congr_arg (G'.connected_component_mk) (equiv.right_inv φ.to_equiv v)) C }\n\n@[simp] lemma connected_component_equiv_refl :\n  (iso.refl : G ≃g G).connected_component_equiv = equiv.refl _ :=\nby { ext ⟨v⟩, refl, }\n\n@[simp] lemma connected_component_equiv_symm (φ : G ≃g G') :\n  φ.symm.connected_component_equiv = φ.connected_component_equiv.symm := by { ext ⟨_⟩, refl, }\n\n@[simp] lemma connected_component_equiv_trans (φ : G ≃g G') (φ' : G' ≃g G'') :\n  connected_component_equiv (φ.trans φ') =\n  φ.connected_component_equiv.trans φ'.connected_component_equiv := by { ext ⟨_⟩, refl, }\n\nend iso\n\nnamespace connected_component\n\n/-- The set of vertices in a connected component of a graph. -/\ndef supp (C : G.connected_component) :=\n  { v | G.connected_component_mk v = C }\n\n@[ext] lemma supp_injective :\n  function.injective (connected_component.supp : G.connected_component → set V) :=\nbegin\n  refine connected_component.ind₂ _,\n  intros v w,\n  simp only [connected_component.supp, set.ext_iff, connected_component.eq, set.mem_set_of_eq],\n  intro h,\n  rw [reachable_comm, h],\nend\n\n@[simp]\nlemma supp_inj {C D : G.connected_component} : C.supp = D.supp ↔ C = D :=\nconnected_component.supp_injective.eq_iff\n\ninstance : set_like G.connected_component V :=\n{ coe := connected_component.supp,\n  coe_injective' := connected_component.supp_injective, }\n\n@[simp] lemma mem_supp_iff (C : G.connected_component) (v : V) :\n  v ∈ C.supp ↔ G.connected_component_mk v = C := iff.rfl\n\nlemma connected_component_mk_mem {v : V} :\n  v ∈ G.connected_component_mk v := by exact rfl\n\n/--\nThe equivalence between connected components, induced by an isomorphism of graphs,\nitself defines an equivalence on the supports of each connected component.\n-/\ndef iso_equiv_supp (φ : G ≃g G') (C : G.connected_component) :\n  C.supp ≃ (φ.connected_component_equiv C).supp :=\n{ to_fun := λ v, ⟨φ v, connected_component.iso_image_comp_eq_map_iff_eq_comp.mpr v.prop⟩,\n  inv_fun := λ v', ⟨φ.symm v', connected_component.iso_inv_image_comp_eq_iff_eq_map.mpr v'.prop⟩,\n  left_inv := λ v, subtype.ext_val (φ.to_equiv.left_inv ↑v),\n  right_inv := λ v, subtype.ext_val (φ.to_equiv.right_inv ↑v), }\n\nend connected_component\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 singleton_subgraph_connected {v : V} : (G.singleton_subgraph v).connected :=\nbegin\n  split,\n  rintros ⟨a, ha⟩ ⟨b, hb⟩,\n  simp only [singleton_subgraph_verts, set.mem_singleton_iff] at ha hb,\n  subst_vars\nend\n\n@[simp] lemma subgraph_of_adj_connected {v w : V} (hvw : G.adj v w) :\n  (G.subgraph_of_adj hvw).connected :=\nbegin\n  split,\n  rintro ⟨a, ha⟩ ⟨b, hb⟩,\n  simp only [subgraph_of_adj_verts, set.mem_insert_iff, set.mem_singleton_iff] at ha hb,\n  obtain (rfl|rfl) := ha; obtain (rfl|rfl) := hb;\n    refl <|> { apply adj.reachable, simp },\nend\n\nlemma preconnected.set_univ_walk_nonempty (hconn : G.preconnected) (u v : V) :\n  (set.univ : set (G.walk u v)).nonempty :=\nby { rw ← 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 as subgraphs -/\n\nnamespace walk\nvariables {G G'} {u v w : V}\n\n/-- The subgraph consisting of the vertices and edges of the walk. -/\n@[simp] protected def to_subgraph : Π {u v : V}, G.walk u v → G.subgraph\n| u _ nil := G.singleton_subgraph u\n| _ _ (cons h p) := G.subgraph_of_adj h ⊔ p.to_subgraph\n\nlemma to_subgraph_cons_nil_eq_subgraph_of_adj (h : G.adj u v) :\n  (cons h nil).to_subgraph = G.subgraph_of_adj h :=\nby simp\n\nlemma mem_verts_to_subgraph (p : G.walk u v) :\n  w ∈ p.to_subgraph.verts ↔ w ∈ p.support :=\nbegin\n  induction p with _ x y z h p' ih,\n  { simp },\n  { have : w = y ∨ w ∈ p'.support ↔ w ∈ p'.support :=\n      ⟨by rintro (rfl | h); simp [*], by simp { contextual := tt}⟩,\n    simp [ih, or_assoc, this] }\nend\n\n@[simp] lemma verts_to_subgraph (p : G.walk u v) : p.to_subgraph.verts = {w | w ∈ p.support} :=\nset.ext (λ _, p.mem_verts_to_subgraph)\n\nlemma mem_edges_to_subgraph (p : G.walk u v) {e : sym2 V} :\n  e ∈ p.to_subgraph.edge_set ↔ e ∈ p.edges :=\nby induction p; simp [*]\n\n@[simp] lemma edge_set_to_subgraph (p : G.walk u v) : p.to_subgraph.edge_set = {e | e ∈ p.edges} :=\nset.ext (λ _, p.mem_edges_to_subgraph)\n\n@[simp] lemma to_subgraph_append (p : G.walk u v) (q : G.walk v w) :\n  (p.append q).to_subgraph = p.to_subgraph ⊔ q.to_subgraph :=\nby induction p; simp [*, sup_assoc]\n\n@[simp] lemma to_subgraph_reverse (p : G.walk u v) :\n  p.reverse.to_subgraph = p.to_subgraph :=\nbegin\n  induction p,\n  { simp },\n  { simp only [*, walk.to_subgraph, reverse_cons, to_subgraph_append, subgraph_of_adj_symm],\n    rw [sup_comm],\n    congr,\n    ext; simp [-set.bot_eq_empty], }\nend\n\n@[simp] lemma to_subgraph_rotate [decidable_eq V] (c : G.walk v v) (h : u ∈ c.support) :\n  (c.rotate h).to_subgraph = c.to_subgraph :=\nby rw [rotate, to_subgraph_append, sup_comm, ← to_subgraph_append, take_spec]\n\n@[simp] lemma to_subgraph_map (f : G →g G') (p : G.walk u v) :\n  (p.map f).to_subgraph = p.to_subgraph.map f :=\nby induction p; simp [*, subgraph.map_sup]\n\n@[simp] lemma finite_neighbor_set_to_subgraph (p : G.walk u v) :\n  (p.to_subgraph.neighbor_set w).finite :=\nbegin\n  induction p,\n  { rw [walk.to_subgraph, neighbor_set_singleton_subgraph],\n    apply set.to_finite, },\n  { rw [walk.to_subgraph, subgraph.neighbor_set_sup],\n    refine set.finite.union _ p_ih,\n    refine set.finite.subset _ (neighbor_set_subgraph_of_adj_subset p_h),\n    apply set.to_finite, },\nend\n\nend walk\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 ≠ v) :\n  {p : G.walk u v | p.length = 0} = ∅ :=\nbegin\n  ext p,\n  simp only [set.mem_set_of_eq, set.mem_empty_iff_false, iff_false],\n  exact λ h', absurd (walk.eq_of_length_eq_zero h') h,\nend\n\nlemma set_walk_length_succ_eq (u v : V) (n : ℕ) :\n  {p : G.walk u v | p.length = n.succ} =\n    ⋃ (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 ⟨w, huw, pwv, rfl, rfl, heq.rfl⟩, },\n    { rintro ⟨w, huw, pwv, rfl, rfl, rfl⟩,\n      refl, } },\nend\n\nvariables (G) [decidable_eq V]\n\nsection locally_finite\nvariables [locally_finite G]\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 : Π (n : ℕ) (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 ∅\n| (n+1) u v := finset.univ.bUnion (λ (w : G.neighbor_set u),\n                 (finset_walk_length n w v).map ⟨λ p, walk.cons w.property p, λ p q, by simp⟩)\n\nlemma coe_finset_walk_length_eq (n : ℕ) (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 [mem_neighbor_set, finset.coe_map, embedding.coe_fn_mk, set.Union_coe_set,\n      set.mem_Union, set.mem_image, finset.mem_coe, set.mem_set_of_eq],\n    congr' with w,\n    congr' with h,\n    congr' with q,\n    have := set.ext_iff.mp (ih w v) q,\n    simp only [finset.mem_coe, set.mem_set_of_eq] at this,\n    rw ← this,\n    refl, },\nend\n\nvariables {G}\n\nlemma walk.mem_finset_walk_length_iff_length_eq {n : ℕ} {u v : V} (p : G.walk u v) :\n  p ∈ G.finset_walk_length n u v ↔ p.length = n :=\nset.ext_iff.mp (G.coe_finset_walk_length_eq n u v) p\n\nvariables (G)\n\ninstance fintype_set_walk_length (u v : V) (n : ℕ) : fintype {p : G.walk u v | p.length = n} :=\nfintype.of_finset (G.finset_walk_length n u v) $ λ p,\nby rw [←finset.mem_coe, coe_finset_walk_length_eq]\n\nlemma set_walk_length_to_finset_eq (n : ℕ) (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 [←coe_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 : ℕ) :\n  fintype.card {p : G.walk u v | p.length = n} = (G.finset_walk_length n u v).card :=\nfintype.card_of_finset (G.finset_walk_length n u v) $ λ p,\n  by rw [←finset.mem_coe, coe_finset_walk_length_eq]\n\ninstance fintype_set_path_length (u v : V) (n : ℕ) :\n  fintype {p : G.walk u v | p.is_path ∧ p.length = n} :=\nfintype.of_finset ((G.finset_walk_length n u v).filter walk.is_path) $\n  by simp [walk.mem_finset_walk_length_iff_length_eq, and_comm]\n\nend locally_finite\n\nsection finite\nvariables [fintype V] [decidable_rel G.adj]\n\nlemma reachable_iff_exists_finset_walk_length_nonempty (u v : V) :\n  G.reachable u v ↔ ∃ (n : fin (fintype.card V)), (G.finset_walk_length n u v).nonempty :=\nbegin\n  split,\n  { intro r,\n    refine r.elim_path (λ p, _),\n    refine ⟨⟨_, p.is_path.length_lt⟩, p, _⟩,\n    simp [walk.mem_finset_walk_length_iff_length_eq], },\n  { rintro ⟨_, p, _⟩, use p },\nend\n\ninstance : decidable_rel G.reachable :=\nλ u v, decidable_of_iff' _ (reachable_iff_exists_finset_walk_length_nonempty G u v)\n\ninstance : fintype G.connected_component :=\n@quotient.fintype _ _ G.reachable_setoid (infer_instance : decidable_rel G.reachable)\n\ninstance : decidable G.preconnected :=\nby { unfold preconnected, apply_instance }\n\ninstance : decidable G.connected :=\nby { rw [connected_iff, ← finset.univ_nonempty_iff], exact and.decidable }\n\nend finite\n\nend walk_counting\n\nsection bridge_edges\n\n/-! ### Bridge edges -/\n\n/-- An edge of a graph is a *bridge* if, after removing it, its incident vertices\nare no longer reachable from one another. -/\ndef is_bridge (G : simple_graph V) (e : sym2 V) : Prop :=\ne ∈ G.edge_set ∧\nsym2.lift ⟨λ v w, ¬ (G \\ from_edge_set {e}).reachable v w, by simp [reachable_comm]⟩ e\n\nlemma is_bridge_iff {u v : V} :\n  G.is_bridge ⟦(u, v)⟧ ↔ G.adj u v ∧ ¬ (G \\ from_edge_set {⟦(u, v)⟧}).reachable u v := iff.rfl\n\nlemma reachable_delete_edges_iff_exists_walk {v w : V} :\n  (G \\ from_edge_set {⟦(v, w)⟧}).reachable v w ↔ ∃ (p : G.walk v w), ¬ ⟦(v, w)⟧ ∈ p.edges :=\nbegin\n  split,\n  { rintro ⟨p⟩,\n    use p.map (hom.map_spanning_subgraphs (by simp)),\n    simp_rw [walk.edges_map, list.mem_map, hom.map_spanning_subgraphs_apply, sym2.map_id', id.def],\n    rintro ⟨e, h, rfl⟩,\n    simpa using p.edges_subset_edge_set h, },\n  { rintro ⟨p, h⟩,\n    refine ⟨p.transfer _ (λ e ep, _)⟩,\n    simp only [edge_set_sdiff, edge_set_from_edge_set, edge_set_sdiff_sdiff_is_diag,\n               set.mem_diff, set.mem_singleton_iff],\n    exact ⟨p.edges_subset_edge_set ep, λ h', h (h' ▸ ep)⟩,  },\nend\n\nlemma is_bridge_iff_adj_and_forall_walk_mem_edges {v w : V} :\n  G.is_bridge ⟦(v, w)⟧ ↔ G.adj v w ∧ ∀ (p : G.walk v w), ⟦(v, w)⟧ ∈ p.edges :=\nbegin\n  rw [is_bridge_iff, and_congr_right'],\n  rw [reachable_delete_edges_iff_exists_walk, not_exists_not],\nend\n\nlemma reachable_delete_edges_iff_exists_cycle.aux [decidable_eq V]\n  {u v w : V}\n  (hb : ∀ (p : G.walk v w), ⟦(v, w)⟧ ∈ p.edges)\n  (c : G.walk u u)\n  (hc : c.is_trail)\n  (he : ⟦(v, w)⟧ ∈ c.edges)\n  (hw : w ∈ (c.take_until v (c.fst_mem_support_of_mem_edges he)).support) :\n  false :=\nbegin\n  have hv := c.fst_mem_support_of_mem_edges he,\n  -- decompose c into\n  --      puw     pwv     pvu\n  --   u ----> w ----> v ----> u\n  let puw := (c.take_until v hv).take_until w hw,\n  let pwv := (c.take_until v hv).drop_until w hw,\n  let pvu := c.drop_until v hv,\n  have : c = (puw.append pwv).append pvu := by simp,\n  -- We have two walks from v to w\n  --      pvu     puw\n  --   v ----> u ----> w\n  --   |               ^\n  --    `-------------'\n  --      pwv.reverse\n  -- so they both contain the edge ⟦(v, w)⟧, but that's a contradiction since c is a trail.\n  have hbq := hb (pvu.append puw),\n  have hpq' := hb pwv.reverse,\n  rw [walk.edges_reverse, list.mem_reverse] at hpq',\n  rw [walk.is_trail_def, this, walk.edges_append, walk.edges_append,\n      list.nodup_append_comm, ← list.append_assoc, ← walk.edges_append] at hc,\n  exact list.disjoint_of_nodup_append hc hbq hpq',\nend\n\nlemma adj_and_reachable_delete_edges_iff_exists_cycle {v w : V} :\n  G.adj v w ∧ (G \\ from_edge_set {⟦(v, w)⟧}).reachable v w ↔\n  ∃ (u : V) (p : G.walk u u), p.is_cycle ∧ ⟦(v, w)⟧ ∈ p.edges :=\nbegin\n  classical,\n  rw reachable_delete_edges_iff_exists_walk,\n  split,\n  { rintro ⟨h, p, hp⟩,\n    refine ⟨w, walk.cons h.symm p.to_path, _, _⟩,\n    { apply path.cons_is_cycle,\n      rw [sym2.eq_swap],\n      intro h,\n      exact absurd (walk.edges_to_path_subset p h) hp, },\n    simp only [sym2.eq_swap, walk.edges_cons, list.mem_cons_iff, eq_self_iff_true, true_or], },\n  { rintro ⟨u, c, hc, he⟩,\n    have hvc : v ∈ c.support := walk.fst_mem_support_of_mem_edges c he,\n    have hwc : w ∈ c.support := walk.snd_mem_support_of_mem_edges c he,\n    let puv := c.take_until v hvc,\n    let pvu := c.drop_until v hvc,\n    obtain (hw | hw') : w ∈ puv.support ∨ w ∈ pvu.support,\n    { rwa [← walk.mem_support_append_iff, walk.take_spec] },\n    { by_contra' h,\n      specialize h (c.adj_of_mem_edges he),\n      exact reachable_delete_edges_iff_exists_cycle.aux h c hc.to_trail he hw, },\n    { by_contra' hb,\n      specialize hb (c.adj_of_mem_edges he),\n      have hb' : ∀ (p : G.walk w v), ⟦(w, v)⟧ ∈ p.edges,\n      { intro p,\n        simpa [sym2.eq_swap] using hb p.reverse, },\n      apply reachable_delete_edges_iff_exists_cycle.aux hb' (pvu.append puv)\n        (hc.to_trail.rotate hvc) _ (walk.start_mem_support _),\n      rwa [walk.edges_append, list.mem_append, or_comm, ← list.mem_append,\n           ← walk.edges_append, walk.take_spec, sym2.eq_swap], } },\nend\n\nlemma is_bridge_iff_adj_and_forall_cycle_not_mem {v w : V} :\n  G.is_bridge ⟦(v, w)⟧ ↔ G.adj v w ∧ ∀ ⦃u : V⦄ (p : G.walk u u), p.is_cycle → ⟦(v, w)⟧ ∉ p.edges :=\nbegin\n  rw [is_bridge_iff, and.congr_right_iff],\n  intro h,\n  rw ← not_iff_not,\n  push_neg,\n  rw ← adj_and_reachable_delete_edges_iff_exists_cycle,\n  simp only [h, true_and],\nend\n\nlemma is_bridge_iff_mem_and_forall_cycle_not_mem {e : sym2 V} :\n  G.is_bridge e ↔ e ∈ G.edge_set ∧ ∀ ⦃u : V⦄ (p : G.walk u u), p.is_cycle → e ∉ p.edges :=\nsym2.ind (λ v w, is_bridge_iff_adj_and_forall_cycle_not_mem) e\n\nend bridge_edges\n\nend simple_graph\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/src/combinatorics/simple_graph/connectivity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7682501541272698}}
{"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 `≤`-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 {α : Type uu} {r : α → α → Prop}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `≤`-like relation (transitive and antisymmetric or asymmetric) -/\ndef sorted := @pairwise\n\ninstance decidable_sorted [decidable_rel r] (l : list α) : decidable (sorted r l) :=\nlist.decidable_pairwise _\n\n@[simp] theorem sorted_nil : sorted r [] := pairwise.nil\n\ntheorem sorted_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) → sorted r l :=\npairwise_of_pairwise_cons\n\ntheorem sorted.tail {r : α → α → Prop} {l : list α} (h : sorted r l) : sorted r l.tail :=\nh.tail\n\ntheorem rel_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) →\n  ∀ b ∈ l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : α} {l : list α} :\n  sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ sorted r l :=\npairwise_cons\n\nprotected theorem sorted.nodup {r : α → α → Prop} [is_irrefl α r] {l : list α} (h : sorted r l) :\n  nodup l :=\nh.nodup\n\ntheorem eq_of_perm_of_sorted [is_antisymm α r]\n  {l₁ l₂ : list α} (p : l₁ ~ l₂) (s₁ : sorted r l₁) (s₂ : sorted r l₂) : l₁ = l₂ :=\nbegin\n  induction s₁ with a l₁ h₁ s₁ IH generalizing l₂,\n  { exact p.nil_eq },\n  { have : a ∈ l₂ := p.subset (mem_cons_self _ _),\n    rcases mem_split this with ⟨u₂, v₂, rfl⟩,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    have := IH p' (pairwise_of_sublist (by simp) s₂), subst l₁,\n    change a::u₂ ++ v₂ = u₂ ++ ([a] ++ v₂), rw ← append_assoc, congr,\n    have : ∀ (x : α) (h : x ∈ u₂), x = a := λ x m,\n      antisymm ((pairwise_append.1 s₂).2.2 _ m a (mem_cons_self _ _))\n        (h₁ _ (by simp [m])),\n    rw [(@eq_repeat _ a (length u₂ + 1) (a::u₂)).2,\n        (@eq_repeat _ a (length u₂ + 1) (u₂++[a])).2];\n    split; simp [iff_true_intro this, or_comm] }\nend\n\n@[simp] theorem sorted_singleton (a : α) : sorted r [a] := pairwise_singleton _ _\n\nlemma sorted.rel_nth_le_of_lt {l : list α}\n  (h : l.sorted r) {a b : ℕ} (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 α r] {l : list α}\n  (h : l.sorted r) {a b : ℕ} (ha : a < l.length) (hb : b < l.length) (hab : a ≤ 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 α} (h : list.sorted r l)\n  {k : ℕ} {x y : α} (hx : x ∈ list.take k l) (hy : y ∈ list.drop k l) :\n  r x y :=\nbegin\n  obtain ⟨iy, hiy, rfl⟩ := nth_le_of_mem hy,\n  obtain ⟨ix, hix, rfl⟩ := 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 {α : Type uu} (r : α → α → Prop) [decidable_rel r]\nlocal infix ` ≼ ` : 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 : α) : list α → list α\n| []       := [a]\n| (b :: l) := if a ≼ 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 α → list α\n| []       := []\n| (b :: l) := ordered_insert r b (insertion_sort l)\n\n@[simp] lemma ordered_insert_nil (a : α) : [].ordered_insert r a = [a] := rfl\n\ntheorem ordered_insert_length : Π (L : list α) (a : α), (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 : α) : ∀ l : list α,\n  l.ordered_insert r a = l.take_while (λ b, ¬(a ≼ b)) ++ (a :: l.drop_while (λ b, ¬(a ≼ 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 : α) (l : list α) :\n  insertion_sort r (a :: l) = (insertion_sort r l).take_while (λ b, ¬(a ≼ b)) ++\n    (a :: (insertion_sort r l).drop_while (λ b, ¬(a ≼ b))) :=\nordered_insert_eq_take_drop r a _\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : ∀ l : list α, ordered_insert r a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a ≼ 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 α] (L : list α) (a b : α) :\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 : ∀ l : list α, 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 : ∀ {l : list α} (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 α r] [is_trans α r]\n\ntheorem sorted.ordered_insert (a : α) : ∀ l, sorted r l → sorted r (ordered_insert r a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a ≼ b,\n  { simpa [ordered_insert, h', h] using λ b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : ∀ (b' : α), b' ∈ ordered_insert r a l → r b b',\n    { simpa [ordered_insert, h', (sorted_of_sorted_cons h).ordered_insert l] },\n    intros b' bm,\n    cases (show b' = a ∨ b' ∈ 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 : ∀ 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 α → list α × list α\n| []       := ([], [])\n| (a :: l) := let (l₁, l₂) := split l in (a :: l₂, l₁)\n\ntheorem split_cons_of_eq (a : α) {l l₁ l₂ : list α} (h : split l = (l₁, l₂)) :\n  split (a :: l) = (a :: l₂, l₁) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : ∀ {l l₁ l₂ : list α},\n  split l = (l₁, l₂) → length l₁ ≤ length l ∧ length l₂ ≤ length l\n| []     ._  ._  rfl := ⟨nat.le_refl 0, nat.le_refl 0⟩\n| (a::l) l₁' l₂' h   := begin\n  cases e : split l with l₁ l₂,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂',\n  cases length_split_le e with h₁ h₂,\n  exact ⟨nat.succ_le_succ h₂, nat.le_succ_of_le h₁⟩\nend\n\ntheorem length_split_lt {a b} {l l₁ l₂ : list α} (h : split (a::b::l) = (l₁, l₂)) :\n  length l₁ < length (a::b::l) ∧ length l₂ < length (a::b::l) :=\nbegin\n  cases e : split l with l₁' l₂',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l₁ l₂,\n  cases length_split_le e with h₁ h₂,\n  exact ⟨nat.succ_le_succ (nat.succ_le_succ h₁), nat.succ_le_succ (nat.succ_le_succ h₂)⟩\nend\n\ntheorem perm_split : ∀ {l l₁ l₂ : list α}, split l = (l₁, l₂) → l ~ l₁ ++ l₂\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l₁' l₂' h   := begin\n  cases e : split l with l₁ l₂,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂',\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 α → list α → list α\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a ≼ 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 α → list α\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  exact merge r (merge_sort l₁) (merge_sort l₂)\nend\nusing_well_founded\n{ rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l₁ l₂ : list α}\n  (h : split (a::b::l) = (l₁, l₂)) :\n  merge_sort r (a::b::l) = merge r (merge_sort r l₁) (merge_sort r l₂) :=\nbegin\n  suffices : ∀ (L : list α) h1, @@and.rec\n    (λ a a (_ : length l₁ < length l + 1 + 1 ∧\n      length l₂ < 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 : ∀ (l l' : list α), 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 ≼ 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 : ∀ l : list α, 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₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact ((perm_merge_sort l₁).append (perm_merge_sort l₂)).trans (perm_split e).symm\nend\nusing_well_founded\n{ rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\n@[simp] lemma length_merge_sort (l : list α) : (merge_sort r l).length = l.length :=\n(perm_merge_sort r _).length_eq\n\nsection total_and_transitive\nvariables {r} [is_total α r] [is_trans α r]\n\ntheorem sorted.merge : ∀ {l l' : list α}, sorted r l → sorted r l' → sorted r (merge r l l')\n| []       []        h₁ h₂ := by simp [merge]\n| []       (b :: l') h₁ h₂ := by simpa [merge] using h₂\n| (a :: l) []        h₁ h₂ := by simpa [merge] using h₁\n| (a :: l) (b :: l') h₁ h₂ := begin\n  by_cases a ≼ b,\n  { suffices : ∀ (b' : α) (_ : b' ∈ merge r l (b :: l')), r a b',\n    { simpa [merge, h, (sorted_of_sorted_cons h₁).merge h₂] },\n    intros b' bm,\n    rcases (show b' = b ∨ b' ∈ l ∨ b' ∈ 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₁ _ bl },\n    { exact trans h (rel_of_sorted_cons h₂ _ bl') } },\n  { suffices : ∀ (b' : α) (_ : b' ∈ merge r (a :: l) l'), r b b',\n    { simpa [merge, h, h₁.merge (sorted_of_sorted_cons h₂)] },\n    intros b' bm,\n    have ba : b ≼ a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a ∨ b' ∈ l ∨ b' ∈ 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₁ _ bl) },\n    { exact rel_of_sorted_cons h₂ _ bl' } }\nend\n\nvariable (r)\n\ntheorem sorted_merge_sort : ∀ l : list α, 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₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  rw [merge_sort_cons_cons r e],\n  exact (sorted_merge_sort l₁).merge (sorted_merge_sort l₂)\nend\nusing_well_founded\n{ rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm α r] {l : list α} : sorted r l → 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 α r] (l : list α) :\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\nend merge_sort\nend sort\n\n/- try them out! -/\n\n--#eval insertion_sort (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\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/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7682392962989955}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Floris van Doorn, Sébastien Gouëzel\n-/\nimport data.list.basic\n\n/-!\n# Sums and products from lists\n\nThis file provides basic results about `list.prod` and `list.sum`, which calculate the product and\nsum of elements of a list. These are defined in [`data.list.defs`](./data/list/defs).\n-/\n\nvariables {α β γ : Type*}\n\nnamespace list\nsection monoid\nvariables [monoid α] {l l₁ l₂ : list α} {a : α}\n\n@[simp, to_additive]\nlemma prod_nil : ([] : list α).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₁ ++ l₂).prod = l₁.prod * l₂.prod :=\ncalc (l₁ ++ l₂).prod = foldl (*) (foldl (*) 1 l₁ * 1) l₂ : by simp [list.prod]\n  ... = l₁.prod * l₂.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_cons, prod_nil, mul_one]\n\n@[simp, to_additive]\nlemma prod_join {l : list (list α)} : l.join.prod = (l.map list.prod).prod :=\nby induction l; [refl, simp only [*, list.join, map, prod_append, prod_cons]]\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 {M₀ : Type*} [monoid_with_zero M₀] {L : list M₀} (h : (0 : M₀) ∈ L) :\n  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 ∈ L`. See also\n`list.prod_eq_zero` for an implication that needs weaker typeclass assumptions. -/\n@[simp] lemma prod_eq_zero_iff {M₀ : Type*} [monoid_with_zero M₀] [nontrivial M₀]\n  [no_zero_divisors M₀] {L : list M₀} :\n  L.prod = 0 ↔ (0 : M₀) ∈ L :=\nbegin\n  induction L with a L ihL,\n  { simp },\n  { rw [prod_cons, mul_eq_zero, ihL, mem_cons_iff, eq_comm] }\nend\n\nlemma prod_ne_zero {M₀ : Type*} [monoid_with_zero M₀] [nontrivial M₀] [no_zero_divisors M₀]\n  {L : list M₀} (hL : (0 : M₀) ∉ L) : L.prod ≠ 0 :=\nmt prod_eq_zero_iff.1 hL\n\n@[to_additive]\nlemma prod_eq_foldr : l.prod = foldr (*) 1 l :=\nlist.rec_on l rfl $ λ a l ihl, by rw [prod_cons, foldr_cons, ihl]\n\n@[to_additive]\nlemma prod_hom_rel {α β γ : Type*} [monoid β] [monoid γ] (l : list α) {r : β → γ → Prop}\n  {f : α → β} {g : α → γ} (h₁ : r 1 1) (h₂ : ∀⦃a b c⦄, r b c → r (f a * b) (g a * c)) :\n  r (l.map f).prod (l.map g).prod :=\nlist.rec_on l h₁ (λ a l hl, by simp only [map_cons, prod_cons, h₂ hl])\n\n@[to_additive]\nlemma prod_hom [monoid β] (l : list α) (f : α →* β) :\n  (l.map f).prod = f l.prod :=\nby { simp only [prod, foldl_map, f.map_one.symm],\n  exact l.foldl_hom _ _ _ 1 f.map_mul }\n\n@[to_additive]\nlemma prod_is_unit [monoid β] : Π {L : list β} (u : ∀ m ∈ 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 (λ m mt, u m (mem_cons_of_mem h mt)))\nend\n\n@[simp, to_additive]\nlemma prod_take_mul_prod_drop :\n  ∀ (L : list α) (i : ℕ), (L.take i).prod * (L.drop i).prod = L.prod\n| [] i := by simp\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  ∀ (L : list α) (i : ℕ) (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]\nlemma length_pos_of_prod_ne_one (L : list α) (h : L.prod ≠ 1) : 0 < L.length :=\nby { cases L, { simp at h, cases h }, { simp } }\n\n@[to_additive]\nlemma prod_update_nth : ∀ (L : list α) (n : ℕ) (a : α),\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]\n\nopen mul_opposite\n\nlemma _root_.mul_opposite.op_list_prod : ∀ (l : list α), op (l.prod) = (l.map op).reverse.prod\n| [] := rfl\n| (x :: xs) := by rw [list.prod_cons, list.map_cons, list.reverse_cons', list.prod_concat, op_mul,\n                      _root_.mul_opposite.op_list_prod]\n\nlemma _root_.mul_opposite.unop_list_prod (l : list αᵐᵒᵖ) :\n  (l.prod).unop = (l.map unop).reverse.prod :=\nby rw [← op_inj, op_unop, mul_opposite.op_list_prod, map_reverse, map_map, reverse_reverse,\n  op_comp_unop, map_id]\n\nend monoid\n\nsection group\nvariables [group α]\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 : ∀ (L : list α), L.prod⁻¹ = (L.map (λ x, x⁻¹)).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 : ∀ (L : list α), L.reverse.prod = (L.map (λ x, x⁻¹)).prod⁻¹ :=\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  ∀ (L : list α) (i : ℕ) (p), (L.drop (i + 1)).prod = (L.nth_le i p)⁻¹ * (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 α]\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 : ∀ (L : list α), L.prod⁻¹ = (L.map (λ x, x⁻¹)).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 α) (n : ℕ) (a : α) :\n  (L.update_nth n a).prod =\n    L.prod * (if hn : n < L.length then (L.nth_le n hn)⁻¹ * 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      ← 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\nlemma eq_of_sum_take_eq [add_left_cancel_monoid α] {L L' : list α} (h : L.length = L'.length)\n  (h' : ∀ i ≤ L.length, (L.take i).sum = (L'.take i).sum) : L = L' :=\nbegin\n  apply ext_le h (λ i h₁ h₂, _),\n  have : (L.take (i + 1)).sum = (L'.take (i + 1)).sum := h' _ (nat.succ_le_of_lt h₁),\n  rw [sum_take_succ L i h₁, sum_take_succ L' i h₂, h' i (le_of_lt h₁)] at this,\n  exact add_left_cancel this\nend\n\nlemma monotone_sum_take [canonically_ordered_add_monoid α] (L : list α) :\n  monotone (λ i, (L.take i).sum) :=\nbegin\n  apply monotone_nat_of_le_succ (λ n, _),\n  by_cases h : n < L.length,\n  { rw sum_take_succ _ _ h,\n    exact le_self_add },\n  { push_neg at h,\n    simp [take_all_of_le h, take_all_of_le (le_trans h (nat.le_succ _))] }\nend\n\n@[to_additive sum_nonneg]\nlemma one_le_prod_of_one_le [ordered_comm_monoid α] {l : list α} (hl₁ : ∀ x ∈ l, (1 : α) ≤ x) :\n  1 ≤ l.prod :=\nbegin\n  induction l with hd tl ih,\n  { simp },\n  rw prod_cons,\n  exact one_le_mul (hl₁ hd (mem_cons_self hd tl)) (ih (λ x h, hl₁ x (mem_cons_of_mem hd h))),\nend\n\n@[to_additive sum_pos]\nlemma one_lt_prod_of_one_lt [ordered_comm_monoid α] :\n  ∀ (l : list α) (hl : ∀ x ∈ l, (1 : α) < x) (hl₂ : l ≠ []), 1 < l.prod\n| [] _ h := (h rfl).elim\n| [b] h _ := by simpa using h\n| (a :: b :: l) hl₁ hl₂ :=\nbegin\n  simp only [forall_eq_or_imp, list.mem_cons_iff _ a] at hl₁,\n  rw list.prod_cons,\n  apply one_lt_mul_of_lt_of_le' hl₁.1,\n  apply le_of_lt ((b :: l).one_lt_prod_of_one_lt hl₁.2 (l.cons_ne_nil b)),\nend\n@[to_additive]\nlemma single_le_prod [ordered_comm_monoid α] {l : list α} (hl₁ : ∀ x ∈ l, (1 : α) ≤ x) :\n  ∀ x ∈ l, x ≤ l.prod :=\nbegin\n  induction l,\n  { simp },\n  simp_rw [prod_cons, forall_mem_cons] at ⊢ hl₁,\n  split,\n  { exact le_mul_of_one_le_right' (one_le_prod_of_one_le hl₁.2) },\n  { exact λ x H, le_mul_of_one_le_of_le hl₁.1 (l_ih hl₁.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 α]\n  {l : list α} (hl₁ : ∀ x ∈ l, (1 : α) ≤ x) (hl₂ : l.prod = 1) {x : α} (hx : x ∈ l) :\n  x = 1 :=\nle_antisymm (hl₂ ▸ single_le_prod hl₁ _ hx) (hl₁ x hx)\n\nlemma sum_eq_zero_iff [canonically_ordered_add_monoid α] (l : list α) :\n  l.sum = 0 ↔ ∀ x ∈ l, x = (0 : α) :=\n⟨all_zero_of_le_zero_le_of_sum_eq_zero (λ _ _, zero_le _),\nbegin\n  induction l,\n  { simp },\n  { intro h,\n    rw [sum_cons, add_eq_zero_iff],\n    rw forall_mem_cons at h,\n    exact ⟨h.1, l_ih h.2⟩ },\nend⟩\n\n/-- If all elements in a list are bounded below by `1`, then the length of the list is bounded\nby the sum of the elements. -/\nlemma length_le_sum_of_one_le (L : list ℕ) (h : ∀ i ∈ L, 1 ≤ i) : L.length ≤ L.sum :=\nbegin\n  induction L with j L IH h, { simp },\n  rw [sum_cons, length, add_comm],\n  exact add_le_add (h _ (set.mem_insert _ _)) (IH (λ i hi, h i (set.mem_union_right _ hi)))\nend\n\n/-- A list with positive sum must have positive length. -/\n-- This is an easy consequence of `length_pos_of_sum_ne_zero`, but often useful in applications.\nlemma length_pos_of_sum_pos [ordered_cancel_add_comm_monoid α] (L : list α) (h : 0 < L.sum) :\n  0 < L.length :=\nlength_pos_of_sum_ne_zero L h.ne'\n\n-- TODO: develop theory of tropical rings\nlemma sum_le_foldr_max [add_monoid α] [add_monoid β] [linear_order β] (f : α → β)\n  (h0 : f 0 ≤ 0) (hadd : ∀ x y, f (x + y) ≤ max (f x) (f y)) (l : list α) :\n  f l.sum ≤ (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, le_max_iff, list.foldr] at IH ⊢,\n  cases le_or_lt (f tl.sum) (f hd),\n  { left,\n    refine (hadd _ _).trans _,\n    simpa using h },\n  { right,\n    refine (hadd _ _).trans _,\n    simp only [IH, max_le_iff, and_true, h.le.trans IH] }\nend\n\n@[simp, to_additive]\nlemma prod_erase [decidable_eq α] [comm_monoid α] {a} :\n  ∀ {l : list α}, a ∈ l → a * (l.erase a).prod = l.prod\n| (b :: l) h :=\n  begin\n    obtain rfl | ⟨ne, h⟩ := 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\nlemma dvd_prod [comm_monoid α] {a} {l : list α} (ha : a ∈ l) : a ∣ l.prod :=\nlet ⟨s, t, h⟩ := mem_split ha in\nby { rw [h, prod_append, prod_cons, mul_left_comm], exact dvd_mul_right _ _ }\n\n@[simp] lemma sum_const_nat (m n : ℕ) : sum (list.repeat m n) = m * n :=\nby induction n; [refl, simp only [*, repeat_succ, sum_cons, nat.mul_succ, add_comm]]\n\nlemma dvd_sum [comm_semiring α] {a} {l : list α} (h : ∀ x ∈ l, a ∣ x) : a ∣ l.sum :=\nbegin\n  induction l with x l ih,\n  { exact dvd_zero _ },\n  { rw [list.sum_cons],\n    exact dvd_add (h _ (mem_cons_self _ _)) (ih (λ x hx, h x (mem_cons_of_mem _ hx))) }\nend\n\nlemma exists_lt_of_sum_lt [linear_ordered_cancel_add_comm_monoid β] {l : list α} (f g : α → β)\n  (h : (l.map f).sum < (l.map g).sum) :\n  ∃ x ∈ l, f x < g x :=\nbegin\n  induction l with x l,\n  { exact (lt_irrefl _ h).elim },\n  obtain h' | h' := lt_or_le (f x) (g x),\n  { exact ⟨x, mem_cons_self _ _, h'⟩ },\n  simp at h,\n  obtain ⟨y, h1y, h2y⟩ := l_ih (lt_of_add_lt_add_left (h.trans_le $ add_le_add_right h' _)),\n  exact ⟨y, mem_cons_of_mem x h1y, h2y⟩,\nend\n\nlemma exists_le_of_sum_le [linear_ordered_cancel_add_comm_monoid β] {l : list α} (hl : l ≠ [])\n  (f g : α → β) (h : (l.map f).sum ≤ (l.map g).sum) :\n  ∃ x ∈ l, f x ≤ g x :=\nbegin\n  cases l with x l,\n  { contradiction },\n  obtain h' | h' := le_or_lt (f x) (g x),\n  { exact ⟨x, mem_cons_self _ _, h'⟩ },\n  obtain ⟨y, h1y, h2y⟩ := exists_lt_of_sum_lt f g _,\n  exact ⟨y, mem_cons_of_mem x h1y, le_of_lt h2y⟩, simp at h,\n  exact lt_of_add_lt_add_left (h.trans_lt $ add_lt_add_right h' _),\nend\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` and state the lemma for `ℕ` as\n -/\n@[to_additive]\nlemma nth_zero_mul_tail_prod [monoid α] (l : list α) :\n  (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]\nlemma head_mul_tail_prod_of_ne_nil [monoid α] [inhabited α] (l : list α) (h : l ≠ []) :\n  l.head * l.tail.prod = l.prod :=\nby cases l; [contradiction, simp]\n\n/-- The product of a list of positive natural numbers is positive,\nand likewise for any nontrivial ordered semiring. -/\nlemma prod_pos [ordered_semiring α] [nontrivial α] (l : list α) (h : ∀ a ∈ l, (0 : α) < a) :\n  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 $ λ a ha, h a $ mem_cons_of_mem _ ha) }\nend\n\n/-!\nSeveral lemmas about sum/head/tail for `list ℕ`.\nThese are hard to generalize well, as they rely on the fact that `default ℕ = 0`.\nIf desired, we could add a class stating that `default α = 0`.\n-/\n\n/-- This relies on `default ℕ = 0`. -/\nlemma head_add_tail_sum (L : list ℕ) : L.head + L.tail.sum = L.sum :=\nby { cases L, { simp, refl }, { simp } }\n\n/-- This relies on `default ℕ = 0`. -/\nlemma head_le_sum (L : list ℕ) : L.head ≤ L.sum := nat.le.intro (head_add_tail_sum L)\n\n/-- This relies on `default ℕ = 0`. -/\nlemma tail_sum (L : list ℕ) : L.tail.sum = L.sum - L.head :=\nby rw [← head_add_tail_sum L, add_comm, add_tsub_cancel_right]\n\nsection alternating\nvariables {G : Type*} [comm_group G]\n\n@[simp, to_additive] lemma alternating_prod_nil : alternating_prod ([] : list G) = 1 := rfl\n\n@[simp, to_additive] lemma alternating_prod_singleton (g : G) : alternating_prod [g] = g := rfl\n\n@[simp, to_additive alternating_sum_cons_cons']\nlemma alternating_prod_cons_cons (g h : G) (l : list G) :\n  alternating_prod (g :: h :: l) = g * h⁻¹ * alternating_prod l := rfl\n\nlemma alternating_sum_cons_cons {G : Type*} [add_comm_group G] (g h : G) (l : list G) :\n  alternating_sum (g :: h :: l) = g - h + alternating_sum l :=\nby rw [sub_eq_add_neg, alternating_sum]\n\nend alternating\n\n@[to_additive]\nlemma _root_.monoid_hom.map_list_prod [monoid α] [monoid β] (f : α →* β) (l : list α) :\n  f l.prod = (l.map f).prod :=\n(l.prod_hom f).symm\n\nopen mul_opposite\n\n/-- A morphism into the opposite monoid acts on the product by acting on the reversed elements -/\nlemma _root_.monoid_hom.unop_map_list_prod {α β : Type*} [monoid α] [monoid β] (f : α →* βᵐᵒᵖ)\n  (l : list α) :\n  unop (f l.prod) = (l.map (unop ∘ f)).reverse.prod :=\nby rw [f.map_list_prod l, unop_list_prod, list.map_map]\n\n@[to_additive]\nlemma prod_map_hom [monoid β] [monoid γ] (L : list α) (f : α → β) (g : β →* γ) :\n  (L.map (g ∘ f)).prod = g ((L.map f).prod) :=\nby {rw g.map_list_prod, exact congr_arg _ (map_map _ _ _).symm}\n\nlemma sum_map_mul_left [semiring α] (L : list β) (f : β → α) (r : α) :\n  (L.map (λ b, r * f b)).sum = r * (L.map f).sum :=\nsum_map_hom L f $ add_monoid_hom.mul_left r\n\nlemma sum_map_mul_right [semiring α] (L : list β) (f : β → α) (r : α) :\n  (L.map (λ b, f b * r)).sum = (L.map f).sum * r :=\nsum_map_hom L f $ add_monoid_hom.mul_right r\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/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.7682392847189956}}
{"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.bounded_order\nimport data.set.intervals.basic\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 a `bounded_order`\n  * `set.Ici.bounded_order`, within a `bounded_order`\n\n-/\n\nvariable {α : Type*}\n\nnamespace set\n\nnamespace Ico\n\nvariables {a b : α}\n\ninstance [semilattice_inf α] : semilattice_inf (Ico a b) :=\nsubtype.semilattice_inf (λ x y hx hy, ⟨le_inf hx.1 hy.1, lt_of_le_of_lt inf_le_left hx.2⟩)\n\n/-- `Ico a b` has a bottom element whenever `a < b`. -/\ndef order_bot [partial_order α] (h : a < b) : order_bot (Ico a b) :=\n{ bot := ⟨a, ⟨le_refl a, h⟩⟩,\n  bot_le := λ x, x.prop.1 }\n\nend Ico\n\nnamespace Iio\n\ninstance [semilattice_inf α] {a : α} : semilattice_inf (Iio a) :=\nsubtype.semilattice_inf (λ x y hx hy, lt_of_le_of_lt inf_le_left hx)\n\nend Iio\n\nnamespace Ioc\n\nvariables {a b : α}\n\ninstance [semilattice_sup α] : semilattice_sup (Ioc a b) :=\nsubtype.semilattice_sup (λ x y hx hy, ⟨lt_of_lt_of_le hx.1 le_sup_left, sup_le hx.2 hy.2⟩)\n\n/-- `Ioc a b` has a top element whenever `a < b`. -/\ndef order_top [partial_order α] (h : a < b) : order_top (Ioc a b) :=\n{ top := ⟨b, ⟨h, le_refl b⟩⟩,\n  le_top := λ x, x.prop.2 }\n\nend Ioc\n\nnamespace Iio\n\ninstance [semilattice_sup α] {a : α} : semilattice_sup (Ioi a) :=\nsubtype.semilattice_sup (λ x y hx hy, lt_of_lt_of_le hx le_sup_left)\n\nend Iio\n\nnamespace Iic\n\nvariables {a : α}\n\ninstance [semilattice_inf α] : semilattice_inf (Iic a) :=\nsubtype.semilattice_inf (λ x y hx hy, le_trans inf_le_left hx)\n\ninstance [semilattice_sup α] : semilattice_sup (Iic a) :=\nsubtype.semilattice_sup (λ x y hx hy, sup_le hx hy)\n\ninstance [lattice α] : lattice (Iic a) :=\n{ .. Iic.semilattice_inf,\n  .. Iic.semilattice_sup }\n\ninstance [preorder α] : order_top (Iic a) :=\n{ top := ⟨a, le_refl a⟩,\n  le_top := λ x, x.prop }\n\n@[simp] lemma coe_top [partial_order α] {a : α} : ↑(⊤ : Iic a) = a := rfl\n\ninstance [preorder α] [order_bot α] : order_bot (Iic a) :=\n{ bot := ⟨⊥, bot_le⟩,\n  bot_le := λ ⟨_,_⟩, subtype.mk_le_mk.2 bot_le }\n\n@[simp] lemma coe_bot [preorder α] [order_bot α] {a : α} : ↑(⊥ : Iic a) = (⊥ : α) := rfl\n\ninstance [partial_order α] [no_bot_order α] {a : α} : no_bot_order (Iic a) :=\n⟨λ x, let ⟨y, hy⟩ := no_bot x.1 in ⟨⟨y, le_trans hy.le x.2⟩, hy⟩ ⟩\n\ninstance [preorder α] [bounded_order α] : bounded_order (Iic a) :=\n{ .. Iic.order_top,\n  .. Iic.order_bot }\n\nend Iic\n\nnamespace Ici\n\nvariables {a : α}\n\ninstance [semilattice_inf α] : semilattice_inf (Ici a) :=\nsubtype.semilattice_inf (λ x y hx hy, le_inf hx hy)\n\ninstance [semilattice_sup α] : semilattice_sup (Ici a) :=\nsubtype.semilattice_sup (λ x y hx hy, le_trans hx le_sup_left)\n\ninstance [lattice α] : lattice (Ici a) :=\n{ .. Ici.semilattice_inf,\n  .. Ici.semilattice_sup }\n\ninstance [preorder α] : order_bot (Ici a) :=\n{ bot := ⟨a, le_refl a⟩,\n  bot_le := λ x, x.prop }\n\n@[simp] lemma coe_bot [partial_order α] {a : α} : ↑(⊥ : Ici a) = a := rfl\n\ninstance [preorder α] [order_top α] : order_top (Ici a) :=\n{ top := ⟨⊤, le_top⟩,\n  le_top := λ ⟨_,_⟩, subtype.mk_le_mk.2 le_top }\n\n@[simp] lemma coe_top [preorder α] [order_top α] {a : α} : ↑(⊤ : Ici a) = (⊤ : α) := rfl\n\ninstance [partial_order α] [no_top_order α] {a : α} : no_top_order (Ici a) :=\n⟨λ x, let ⟨y, hy⟩ := no_top x.1 in ⟨⟨y, le_trans x.2 hy.le⟩, hy⟩ ⟩\n\ninstance [preorder α] [bounded_order α] : bounded_order (Ici a) :=\n{ .. Ici.order_top,\n  .. Ici.order_bot }\n\nend Ici\n\nnamespace Icc\n\ninstance [semilattice_inf α] {a b : α} : semilattice_inf (Icc a b) :=\nsubtype.semilattice_inf (λ x y hx hy, ⟨le_inf hx.1 hy.1, le_trans inf_le_left hx.2⟩)\n\ninstance [semilattice_sup α] {a b : α} : semilattice_sup (Icc a b) :=\nsubtype.semilattice_sup (λ x y hx hy, ⟨le_trans hx.1 le_sup_left, sup_le hx.2 hy.2⟩)\n\ninstance [lattice α] {a b : α} : lattice (Icc a b) :=\n{ .. Icc.semilattice_inf,\n  .. Icc.semilattice_sup }\n\n/-- `Icc a b` has a bottom element whenever `a ≤ b`. -/\ndef order_bot [preorder α] {a b : α} (h : a ≤ b) : order_bot (Icc a b) :=\n{ bot := ⟨a, ⟨le_refl a, h⟩⟩,\n  bot_le := λ x, x.prop.1 }\n\n/-- `Icc a b` has a top element whenever `a ≤ b`. -/\ndef order_top [preorder α] {a b : α} (h : a ≤ b) : order_top (Icc a b) :=\n{ top := ⟨b, ⟨h, le_refl b⟩⟩,\n  le_top := λ x, x.prop.2 }\n\n/-- `Icc a b` is a `bounded_order` whenever `a ≤ b`. -/\ndef bounded_order [preorder α] {a b : α} (h : a ≤ 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": "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/lattice_intervals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8705972600147105, "lm_q1q2_score": 0.7682392746203536}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro hp,\n  apply not_not_intro,\n  assumption,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro hp,\n  by_contradiction h,\n  contradiction,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  { intro hp,\n    apply doubleneg_elim,\n    assumption,\n  },\n  {intro hp,\n  apply doubleneg_intro,\n  assumption,\n  }\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hor,\n  cases hor with hp hq,\n  { right,\n    assumption,\n  },\n  { left,\n    assumption,\n  }\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro h,\n  cases h with hp hq,\n  split,\n  { \n    assumption,\n  },\n  { \n    assumption,\n  }\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro pq,\n  intro hp,\n  cases pq with p q,\n  case or.inr{\n    assumption\n  },\n  case or.inl{\n    by contradiction\n  },\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro pq,\n  intro hp,\n  cases pq with p q,\n  case or.inr{\n    assumption\n  },\n  case or.inl{\n    by contradiction\n  },\n\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro pq,\n  intro nq,\n  intro hp,\n  apply nq,\n  apply pq,\n  assumption,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intros nqnp p,\n  by_cases h : Q,\n  {\n    assumption,\n  },\n  {\n    by_contra,\n    apply nqnp,\n    assumption,\n    exact p,\n  },\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,{\n    intro pq,\n    apply impl_as_contrapositive,\n    assumption,\n  },\n  {\n    intro npnq,\n    apply impl_as_contrapositive_converse,\n    assumption,\n  },\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P ∨ ¬P)  :=\nbegin\n  intro npnp, \n  apply npnp,\n  right,\n  intro p,\n  apply npnp,\n  left,\n  assumption,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intros pqp np,\n  apply np,\n  apply pqp,\n  intro p,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P ∨ Q → ¬(¬P ∧ ¬Q)  :=\nbegin\n  intro pvq,\n  cases pvq with p q,\n  case or.inl{\n    intro npeq,\n    cases npeq with np nq,\n    by contradiction,\n  },\n  case or.inr{\n    intro npeq,\n    cases npeq with np nq,\n    by contradiction,\n  }\nend\n\ntheorem conj_as_negdisj :\n  P ∧ Q → ¬(¬P ∨ ¬Q)  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  intro nnpvq,\n  cases nnpvq with np nq,\n  case or.inl{\n    by contradiction,\n    },\n  case or.inr{\n    by contradiction,\n  }\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P ∨ Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro npvnq,\n  split,\n  {\n    intro p,\n    apply npvnq,\n    left,\n    assumption,\n  },\n  {\n    intro q,\n    apply npvnq,\n    right,\n    assumption,\n  }\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P ∨ Q)  :=\nbegin\n  intro npenq,\n  cases npenq with np nq,\n  {\n   intro pvq,\n   cases pvq with p q,\n   case or.inl{\n    by contradiction,\n   },\n   case or.inr{\n     by contradiction,\n   }, \n  }\nend\n\ntheorem demorgan_conj :\n  ¬(P ∧ Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro npeq,\n  by_cases h : P,\n  {\n    left,\n    intro q,\n    apply npeq,\n    split,\n    assumption,\n    assumption,\n  },\n  {\n    right,\n    assumption,\n  }\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P ∧ Q)  :=\nbegin\n  intro npvnq,\n  cases npvnq with nq np,\n  case or.inl{\n    intro peq,\n    cases peq with p q,\n    by contradiction,\n  },\n  case or.inr{\n    intro peq,\n    cases peq with p q,\n    by contradiction,\n  },\nend\n\ntheorem demorgan_conj_law :\n  ¬(P ∧ Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,{\n    intro npeq,\n    apply demorgan_conj,\n    assumption,\n  },\n  {\n    intro npvnq,\n    apply demorgan_conj_converse,\n    assumption,\n  },\nend\n\ntheorem demorgan_disj_law :\n  ¬(P ∨ Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,{\n    intro npvq,\n    apply demorgan_disj,\n    assumption,\n  },\n  {\n    intro npenq,\n    apply demorgan_disj_converse,\n    assumption,\n  },\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P ∧ (Q ∨ R) → (P ∧ Q) ∨ (P ∧ R)  :=\nbegin\n  intro peqvr,\n  cases peqvr with p qvr,\n  cases qvr with q r,\n  case or.inl{\n    left,\n    split,{\n      assumption,\n    },\n    {\n      assumption,\n    },\n  },\n  case or.inr{\n    right,\n    split,{\n      assumption,\n    },\n    {\n      assumption,\n    },\n  },\nend\n\ntheorem distr_conj_disj_converse :\n  (P ∧ Q) ∨ (P ∧ R) → P ∧ (Q ∨ R)  :=\nbegin\n  intro peqvper,\n  cases peqvper with peq per,\n  case or.inl{\n    split,{\n      cases peq with p q,\n      assumption,\n    },\n    {\n      cases peq with p q,\n      left,\n      assumption,\n    },\n  },\n  case or.inr{\n    split,{\n      cases per with p r,\n      assumption,\n    },\n    {\n      cases per with p r,\n      right,\n      assumption,\n    },\n  },\nend\n\ntheorem distr_disj_conj :\n  P ∨ (Q ∧ R) → (P ∨ Q) ∧ (P ∨ R)  :=\nbegin\n  intro pvqer,\n  cases pvqer with p per,\n  case or.inr{\n    split,{\n      cases per with q r,\n      right,{\n        assumption,\n      },\n    },\n      cases per with q r,\n      right,{\n        assumption,\n    },\n  },\n  case or.inl{\n    split,\n    left,{\n      assumption,\n    },\n    left,{\n      assumption,\n    },\n  },\nend\n\ntheorem distr_disj_conj_converse :\n  (P ∨ Q) ∧ (P ∨ R) → P ∨ (Q ∧ R)  :=\nbegin\n  intro pvqepvr,\n  cases pvqepvr with pvq pvr,\n  cases pvq with p q,{\n    cases pvr with p r,{\n      left,\n      assumption,\n    },\n    left,\n    assumption,\n  },\n  case or.inr{\n    cases pvr with p r,{\n      case or.inl{\n        left,\n        assumption,\n      },\n    },\n    case or.inr or.inr{\n      right,\n      split,\n      assumption,\n      assumption,\n    },\n  },\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P ∧ Q) → R) → (P → (Q → R))  :=\nbegin\n  intros peqr p q,\n  apply peqr,\n  split,\n  assumption,\n  assumption,\nend\n\ntheorem uncurry_prop :\n  (P → (Q → R)) → ((P ∧ Q) → R)  :=\nbegin\n  intros pqr peq,\n  cases peq with p q,\n  apply pqr,\n  assumption,\n  assumption,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P ∨ Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P ∨ Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P ∧ Q) → P  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P ∧ Q) → Q  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P ∧ P) ↔ P :=\nbegin\n  split,{\n    intro pep,\n    cases pep with p,\n    exact p,\n    },\n    {\n      intro p,\n      split,\n      exact p,\n      exact p,\n    },\nend\n\ntheorem disj_idempot :\n  (P ∨ P) ↔ P  :=\nbegin\n  split,{\n    intro pvp,\n    cases pvp with p p',\n    case or.inl{\n      exact p,\n    },\n    case or.inr{\n      exact p',\n    },\n  },\n  intro p'',\n  right,\n  exact p'',\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intros nexu u,\n  by_contradiction boom,\n  apply nexu,\n  existsi u,\n  assumption,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intros ptxu exu,\n  cases exu with u pu,\n  apply ptxu,\n  assumption,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  rw contrapositive_law,\n  rw doubleneg_law,\n  intro npx,\n  intro u,\n  by_contradiction boom,\n  apply npx,\n  existsi u,\n  apply boom,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intros enpx ptx,\n  cases enpx with u npu,\n  apply npu,\n  exact ptx u,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n    split,{\n      intro nptx,\n      apply demorgan_forall,\n      assumption,\n    },\n    {\n      intro enpx,\n      apply demorgan_forall_converse,\n      assumption,\n    },\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,{\n    intros npex u pu,\n    apply npex,\n    existsi u,\n    assumption, \n  },\n  {\n  intros ptxnp exu,\n  cases exu with u pu,\n  apply ptxnp,\n  assumption,\n  },\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intros pex ptx,\n  cases pex with u pu,\n  apply ptx,\n  assumption,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intros ptx eunp,\n  by_contradiction boom,\n  cases eunp with u npu,\n  apply npu,\n  exact ptx u,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intros nex u,\n  by_contradiction boom,\n  apply nex,\n  existsi u,\n  assumption,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro nptnx,\n  by_contradiction boom,\n  apply nptnx,\n  intro u,\n  by_cases h : P u,\n  intro q,\n  apply boom,\n  split,{\n    exact h\n  },\n  assumption,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,{\n    intros ptx enx,\n    cases enx with u npu,\n    apply npu,\n    exact ptx u,\n  },\n  {\n    intros nenpx u,\n    by_contradiction boom,\n    apply nenpx,\n    existsi u,\n    assumption,\n  },\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,{\n    intros pex nptx,\n    cases pex with u pu,\n    apply nptx,\n    exact pu,\n  },\n  {\n    intro nptpx,\n    by_contradiction boom,\n    apply nptpx,\n    intro u,\n    by_cases h : P u,\n    intro pu,\n    apply boom,\n    split,{\n      exact h\n    },\n    assumption,\n  },\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro expeq,\n  cases expeq with u peq,{\n    cases peq with pu qu,{\n      split,{\n        split,{\n          exact pu,\n        },\n      },\n      split,{\n        exact qu,\n      },\n      },\n    },\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro expvq,\n  cases expvq with u puvqu,{\n    cases puvqu with pu qu,{\n      case or.inl{\n        left,{\n          split,{\n            exact pu,\n          },\n        },\n      },\n    },\n    case or.inr{\n      right,{\n        split,{\n          exact qu,\n        },\n      },\n    },\n  },\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro epxveqx,\n  cases epxveqx with epx eqx,{\n    cases epx with u pu,{\n      split,{\n        left,{\n          exact pu,\n        },\n      },\n    },\n  },\n  case or.inr{\n    cases eqx with u qu,{\n      split,{\n        right,{\n          exact qu,\n        },\n      },\n    },\n  },\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro ptpeq,\n  split,{\n    intro u,\n    by_cases h : P u,{\n      assumption,\n    },\n    {\n      sorry,\n    },\n  },\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intros ptpeq u,\n  cases ptpeq with px qx,{\n    split,{\n      exact px u,\n    },\n    {\n      exact qx u,\n    },\n  },\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intros ptpvq u,\n  cases ptpvq with px qx,\n    case or.inl{\n      left,{\n        exact px u,\n      },\n    },\n    case or.inr{\n      right,{\n        exact qx u,\n      },\n    },\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "Gabrielfer14", "repo": "fmclean", "sha": "8e45b307396ee00299e122203df3abc35f4782ea", "save_path": "github-repos/lean/Gabrielfer14-fmclean", "path": "github-repos/lean/Gabrielfer14-fmclean/fmclean-8e45b307396ee00299e122203df3abc35f4782ea/fmclean/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065459, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.768155308107604}}
{"text": "import ring_theory.polynomial.basic\n-- The contents of this file is not needed anymore\n\nlemma is_unit_sub_of_is_unit_of_is_nilpotent {M : Type*} [comm_ring M] {a b : M}\n  (ha : is_unit a) (hb : is_nilpotent b) : is_unit (a - b) :=\nbegin\n  refine @is_unit_of_mul_is_unit_left _ _ _ ↑(ha.unit⁻¹) _,\n  rw [sub_mul, is_unit.mul_coe_inv],\n  obtain ⟨n, hn⟩ := commute.is_nilpotent_mul_left (mul_comm b ↑(ha.unit)⁻¹) hb,\n  exact is_unit_of_mul_eq_one _ _ ((mul_neg_geom_sum _ n).trans $ hn.symm ▸ sub_zero 1)\nend\n\nlemma is_unit_add_of_is_unit_of_is_nilpotent {M : Type*} [comm_ring M] {a b : M}\n  (ha : is_unit a) (hb : is_nilpotent b) : is_unit (a + b) :=\nsub_neg_eq_add a b ▸ is_unit_sub_of_is_unit_of_is_nilpotent ha hb.neg\n\nlemma is_nilpotent.sum {M : Type*} [comm_semiring M] {ι : Type*} (s : finset ι)\n  (f : ι → M) (hf : ∀ i ∈ s, is_nilpotent (f i)) : is_nilpotent (s.sum f) :=\nbegin\n  classical,\n  induction s using finset.induction_on with a s h₁ h₂,\n  { rw finset.sum_empty, exact is_nilpotent.zero },\n  { rw [finset.sum_insert h₁],\n    exact commute.is_nilpotent_add (mul_comm _ _) (hf a (finset.mem_insert_self _ _))\n      (h₂ $ λ i hi, hf _ (finset.mem_insert_of_mem hi)) }\nend\n\nopen_locale polynomial\n\nlemma polynomial.is_unit_iff' {R : Type*} [comm_ring R] {p : R[X]} : \n  is_unit p ↔ is_unit (p.coeff 0) ∧ ∀ i ≠ 0, is_nilpotent (p.coeff i) :=\nbegin\n  split,\n  { intro h,\n    rw polynomial.coeff_zero_eq_eval_zero,\n    refine ⟨(polynomial.eval_ring_hom (0 : R)).is_unit_map h, λ i hi, _⟩,\n    change p.coeff i ∈ nilradical R,\n    rw [nilradical_eq_Inf, ideal.mem_Inf],\n    rintros I (hI : I.is_prime),\n    have := ring_hom.is_unit_map (polynomial.map_ring_hom I^.quotient.mk) h,\n    resetI,\n    obtain ⟨r, h₁, h₂⟩ := polynomial.is_unit_iff.mp this,\n    apply_fun (λ x, polynomial.coeff x i) at h₂,\n    rwa [polynomial.coeff_C_ne_zero hi, polynomial.coe_map_ring_hom, polynomial.coeff_map,\n      ← ideal.quotient.mk_eq_mk, eq_comm, submodule.quotient.mk_eq_zero] at h₂ },\n  { rintro ⟨h₁, h₂⟩, \n    casesI subsingleton_or_nontrivial R, { exact is_unit_of_subsingleton _ }, \n    have : 0 ∈ p.support,\n    { rw [polynomial.mem_support_iff], intro e, rw e at h₁, exact not_is_unit_zero h₁ },\n    rw [← p.sum_monomial_eq, polynomial.sum, ← finset.sum_filter_add_sum_filter_not _ (eq 0),\n      finset.filter_eq p.support 0, if_pos this, finset.sum_singleton,\n      polynomial.monomial_zero_left],\n    apply is_unit_add_of_is_unit_of_is_nilpotent (polynomial.C.is_unit_map h₁),\n    apply is_nilpotent.sum,\n    intros i hi, rw [← mul_one (p.coeff i), ← polynomial.C_mul_monomial],\n    exact commute.is_nilpotent_mul_left (mul_comm _ _)\n      ((h₂ i $ ne_comm.mp (finset.mem_filter.mp hi).2).map polynomial.C) }\nend\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/for_mathlib/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7681121711975425}}
{"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 Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.set.lattice\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\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\nnamespace set\n\n\n@[simp] theorem Iic_disjoint_Ioi {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : disjoint (Iic a) (Ioi b) := sorry\n\n@[simp] theorem Iic_disjoint_Ioc {α : Type u} [preorder α] {a : α} {b : α} {c : α} (h : a ≤ b) : disjoint (Iic a) (Ioc b c) :=\n  disjoint.mono (le_refl (Iic a)) (fun (_x : α) => and.left) (Iic_disjoint_Ioi h)\n\n@[simp] theorem Ioc_disjoint_Ioc_same {α : Type u} [preorder α] {a : α} {b : α} {c : α} : disjoint (Ioc a b) (Ioc b c) :=\n  disjoint.mono (fun (_x : α) => and.right) (le_refl (Ioc b c)) (Iic_disjoint_Ioc (le_refl b))\n\n@[simp] theorem Ico_disjoint_Ico_same {α : Type u} [preorder α] {a : α} {b : α} {c : α} : disjoint (Ico a b) (Ico b c) :=\n  fun (x : α) (hx : x ∈ Ico a b ⊓ Ico b c) => not_le_of_lt (and.right (and.left hx)) (and.left (and.right hx))\n\n@[simp] theorem Ico_disjoint_Ico {α : Type u} [linear_order α] {a₁ : α} {a₂ : α} {b₁ : α} {b₂ : α} : disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := sorry\n\n@[simp] theorem Ioc_disjoint_Ioc {α : Type u} [linear_order α] {a₁ : α} {a₂ : α} {b₁ : α} {b₂ : α} : disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := sorry\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. -/\ntheorem eq_of_Ico_disjoint {α : Type u} [linear_order α] {x₁ : α} {x₂ : α} {y₁ : α} {y₂ : α} (h : disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) : y₁ = 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/intervals/disjoint.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7681121693871164}}
{"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 algebra.algebra.tower\nimport ring_theory.norm -- for norms\nimport ring_theory.trace -- for traces\n\n/-\n\n# Extensions of extensions\n\nThe problem with making every field a type and using `algebra` to\nfix the embeddings from a smaller field to a bigger one, is that\nwhen you have three or more extensions, you need to have a way of\nsaying that those maps are compatible.\n\nOn paper we might write \"Let `E ⊆ F ⊆ K` be a tower of fields\"\nbut in Lean we make each each pair into an `algebra` structure\nand now we want to somehow explain that the `algebra_map` from\n`E` to `F` composed with the one from `F` to `K` equals the\none from `E` to `K`. We assert this compatibility with\nthe `is_scalar_tower E F K` typeclass. Here's the proof\nthat in the presence of this prop-valued hypothesis, the\ndiagram commutes.\n\n-/\n\nexample (E F K : Type) [field E] [field F] [field K] [algebra E F] [algebra F K]\n  [algebra E K] [is_scalar_tower E F K] (e : E) : \n  algebra_map E K e = algebra_map F K (algebra_map E F e) := is_scalar_tower.algebra_map_apply E F K e\n\n/-\n\nFor me, what is surprising is that the definition of `is_scalar_tower` is\nnot at all what one would expect. The idea is due to Kenny Lau (a former Imperial\nundergraduate) in 2020; Eric Wieser wrote a paper on how the system works in 2021\nhttps://arxiv.org/abs/2108.10700  (this is Eric on the Discord). Guess what the\ndefinition is and then right click on `is_scalar_tower` and jump to definition\nto find out the truth (which might surprise you).\n\nNow we have three compatible field extensions we can ask how the basic constructions\nsuch as degree, norm and trace behave.\n\n-/\n\nvariables (E F K : Type) [field E] [field F] [field K] [algebra E F] [algebra F K]\n  [algebra E K] [is_scalar_tower E F K] \n\n-- There is a mathematically correct tower law, involving cardinals:\nexample : module.rank E F * module.rank F K = module.rank E K := dim_mul_dim E F K\n\n-- But this is a pain to use, because cardinals are not a particularly well-behaved\n-- object. So let's put in a finite-dimensional hypothesis and use `finrank`.\n\nopen finite_dimensional\n\n-- Tower law for dimensions, natural number case.\nexample [finite_dimensional E F] : finrank E F * finrank F K = finrank E K := finrank_mul_finrank E F K\n\n/- Note that if K/F is infinite-dimensional then `finrank F K = 0` as does `finrank E K`.\nThe same argument should apply if F/E is infinite-dimensional; this seems to be a minor\nglitch in mathlib!\n-/\n\n-- Tricky exercise: look at proof of `finrank_mul_finrank` in mathlib and see if you\n-- can generalise it by removing the `[finite_dimensional E F]` condition in the case\n-- where everything is a field.\nexample : finrank E F * finrank F K = finrank E K :=\nbegin\n  sorry,\nend\n\n-- trace of trace is trace in a tower\nexample [finite_dimensional E F] [finite_dimensional F K] (k : K) : \n  (algebra.trace E F) ((algebra.trace F K) k) = (algebra.trace E K) k := algebra.trace_trace k\n\n-- I can't find the norm version though :-/ \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/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7681121599468981}}
{"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.\n\n## Implementation\n\nAs with many other families of polynomials, even though the coefficients are always in `ℕ`,\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* Defining Bernstein polynomials (e.g. as one way to prove Weierstrass' theorem).\n-/\n\nuniverses u v\n\nopen polynomial\n\nsection\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 : ℕ → 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]\nlemma pochhammer_succ_left (n : ℕ) : pochhammer S (n+1) = X * (pochhammer S n).comp (X+1) :=\nby { dsimp [pochhammer], refl, }\n\nsection\nvariables {S} {T : Type v} [semiring T]\n@[simp] lemma pochhammer_map (f : S →+* T) (n : ℕ) : (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 : ℕ) :\n  ((pochhammer ℕ n).eval k : S) = (pochhammer S n).eval k :=\nbegin\n  rw [←pochhammer_map (algebra_map ℕ S), eval_map, ←(algebra_map ℕ S).eq_nat_cast,\n    eval₂_at_nat_cast, nat.cast_id, ring_hom.eq_nat_cast],\nend\n\nlemma pochhammer_eval_zero {n : ℕ} : (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 : ℕ} (h : n ≠ 0) : (pochhammer S n).eval 0 = 0 :=\nby simp [pochhammer_eval_zero, h]\n\nlemma pochhammer_succ_right (n : ℕ) : pochhammer S (n+1) = pochhammer S n * (X + n) :=\nbegin\n  suffices h : pochhammer ℕ (n+1) = pochhammer ℕ n * (X + n),\n  { apply_fun polynomial.map (algebra_map ℕ S) at h,\n    simpa only [pochhammer_map, map_mul, map_add, map_X, map_nat_cast] using h, },\n  induction n with n ih,\n  { simp, },\n  { conv_lhs {\n    rw [pochhammer_succ_left, ih, mul_comp, ←mul_assoc, ←pochhammer_succ_left, add_comp, X_comp,\n      nat_cast_comp, add_assoc, add_comm (1 : polynomial ℕ)], },\n    refl, },\nend\n\nlemma polynomial.mul_X_add_nat_cast_comp {p q : polynomial S} {n : ℕ} :\n  (p * (X + n)).comp q = (p.comp q) * (q + n) :=\nby rw [mul_add, add_comp, mul_X_comp, ←nat.cast_comm, nat_cast_mul_comp, nat.cast_comm, mul_add]\n\nlemma pochhammer_mul (n m : ℕ) :\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, ←mul_assoc, ih,\n      nat.succ_eq_add_one, ←add_assoc, pochhammer_succ_right, nat.cast_add, add_assoc], }\nend\n\nend\n\nsection\nvariables {S : Type*} [ordered_semiring S] [nontrivial S]\n\nlemma pochhammer_pos (n : ℕ) (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, ←nat.cast_comm, eval_nat_cast_mul, eval_mul_X,\n      nat.cast_comm, ←mul_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\n\nsection factorial\n\nopen_locale nat\n\n/-- Preliminary version of `pochhammer_eval_one` specialized to `S = ℕ`. -/\nlemma pochhammer_eval_one' (n : ℕ) : (pochhammer ℕ n).eval 1 = n! :=\nbegin\n  induction n with n ih,\n  { simp, },\n  { simp [ih, mul_comm, nat.succ_eq_add_one, add_comm, pochhammer_succ_right], },\nend\n\n@[simp]\nlemma pochhammer_eval_one (S : Type*) [semiring S] (n : ℕ) :\n  (pochhammer S n).eval (1 : S) = (n! : S) :=\nby simpa using congr_arg (algebra_map ℕ S) (pochhammer_eval_one' n)\n\n/-- Preliminary version of `factorial_mul_pochhammer` specialized to `S = ℕ`. -/\nlemma factorial_mul_pochhammer' (r n : ℕ) :\n  r! * (pochhammer ℕ n).eval (r+1) = (r + n)! :=\nby simpa [add_comm 1 r, pochhammer_eval_one'] using congr_arg (eval 1) (pochhammer_mul ℕ r n)\n\nlemma factorial_mul_pochhammer (S : Type*) [semiring S] (r n : ℕ) :\n  (r! : S) * (pochhammer S n).eval (r+1) = (r + n)! :=\nby simpa using congr_arg (algebra_map ℕ S) (factorial_mul_pochhammer' r n)\n\nlemma pochhammer_eval_eq_factorial_div_factorial {r n : ℕ} :\n  (pochhammer ℕ n).eval (r+1) = (r + n)! / r! :=\n(nat.div_eq_of_eq_mul_right (nat.factorial_pos _) (factorial_mul_pochhammer' r n).symm).symm\n\nlemma pochhammer_eval_eq_choose_mul_factorial {r n : ℕ} :\n  (pochhammer ℕ n).eval (r+1) = (r + n).choose n * n! :=\nbegin\n  rw pochhammer_eval_eq_factorial_div_factorial,\n  -- TODO we need a `clear_denominators` tactic!\n  apply nat.div_eq_of_eq_mul_right (nat.factorial_pos _),\n  rw [mul_comm],\n  convert (nat.choose_mul_factorial_mul_factorial (nat.le_add_left n r)).symm,\n  simp,\nend\n\nlemma choose_eq_pochhammer_eval_div_factorial {r n : ℕ} :\n  (r + n).choose n = (pochhammer ℕ n).eval (r+1) / n! :=\nbegin\n  symmetry,\n  apply nat.div_eq_of_eq_mul_right (nat.factorial_pos _),\n  rw [mul_comm, pochhammer_eval_eq_choose_mul_factorial],\nend\n\nend factorial\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/pochhammer.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572634, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7680940601140169}}
{"text": "variables (P Q R : Prop)\n\n-- proof term\nexample: ∀  (P Q: Prop), ∀ (p : P), Q :=\n    λ (p0: P),\n        _\n\n--proof script \nexample: ∀ (P Q: Prop), ∀ (p:P), Q :=\nbegin\nintros,\n_\nend\n\n-- both of the above are the same\n\n/-\nFORALL ELIMINATION\n\n-/\nexample :\n    (∀ (p:P), Q) → \n    (P → Q):=\n    λ h, \n        λ p,\n            (h p)\n\n\n\nexample:\n    (∀ (p:P), Q) →  -- arrows are right associative \n    P → \n    Q :=\nλ (f : ∀ (p:P), Q), -- proof of ∀ \n    λ  (p:P),       -- proof of P\n    (f p)              -- ∀ elimination \n\n/-\nto show x ⇒ y\n\nassume x, show y\n\na proof of this is a function from x → y.  \nX is a parameter \n-/\n\nexample: P → Q → P ∧ Q :=\n\nλ (p:P),\n    λ (q: Q),\n        and.intro p q \n\nexample: (P ∧ Q) → P :=\nλ (h: P ∧ Q), -- given proof of p ∧ q\n    and.elim_left h -- return Q proof \n\n-- if you know 2 things are equal then you can make certain substitutions in the process  -> elimination or *rewrite*\n\naxiom L: P → Prop -- assume some predicate L \n\nexample : ∀ (a b:P), a = b → (L a → L b) :=\n    λ a b, -- assume a and b are values of P\n    λ heq, -- assume a proof of a = b\n    λ la, -- assume a proof of (L a)\n    (eq.subst heq la)  -- deduce proof of (L b)\n\nexample : P ∧ Q → Q ∧ P :=\nλ (pq : P ∧ Q), -- assume proof P ∧ Q\n    and.intro       -- apply and.intro\n        pq.right  -- proof of Q\n        pq.left     -- proof of P \n\n/-\nwhat does it mean to say ¬ P?\n¬ p is true when there are no proofs of P,\n\nMeet \"false\". - a proposition itself which is never true\n\na proposition with no proofs\n\nit is literally an empty type.\na type with no values\n\ninductive false: Prop \n-/\n\n#check false \n\ndef f: false → 0 = 1\n| p := false.elim p \n\n/-\n¬ P === P → false \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/Notes/11.21.2019.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7680940413760536}}
{"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\nimport analysis.inner_product_space.projection\nimport order.well_founded_set\nimport analysis.inner_product_space.pi_L2\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\n## TODO\n  Construct a version with an orthonormal basis from Gram-Schmidt process.\n-/\n\nopen_locale big_operators\nopen finset\n\nvariables (𝕜 : Type*) {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]\nvariables {ι : Type*} [linear_order ι] [locally_finite_order_bot ι] [is_well_order ι (<)]\n\nlocal attribute [instance] is_well_order.to_has_well_founded\n\nlocal notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ 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 gram_schmidt (f : ι → E) : ι → E\n| n := f n - ∑ i : Iio n, orthogonal_projection (𝕜 ∙ gram_schmidt i) (f n)\nusing_well_founded { dec_tac := `[exact mem_Iio.1 i.2] }\n\n/-- This lemma uses `∑ i in` instead of `∑ i :`.-/\nlemma gram_schmidt_def (f : ι → E) (n : ι):\n  gram_schmidt 𝕜 f n = f n - ∑ i in Iio n,\n    orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=\nby { rw [←sum_attach, attach_eq_univ, gram_schmidt], refl }\n\nlemma gram_schmidt_def' (f : ι → E) (n : ι):\n  f n = gram_schmidt 𝕜 f n + ∑ i in Iio n,\n    orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=\nby rw [gram_schmidt_def, sub_add_cancel]\n\n@[simp] lemma gram_schmidt_zero {ι : Type*} [linear_order ι] [locally_finite_order ι]\n  [order_bot ι] [is_well_order ι (<)] (f : ι → E) : gram_schmidt 𝕜 f ⊥ = f ⊥ :=\nby rw [gram_schmidt_def, Iio_eq_Ico, finset.Ico_self, finset.sum_empty, sub_zero]\n\n/-- **Gram-Schmidt Orthogonalisation**:\n`gram_schmidt` produces an orthogonal system of vectors. -/\ntheorem gram_schmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) :\n  ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0 :=\nbegin\n  suffices : ∀ a b : ι, a < b → ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0,\n  { cases h₀.lt_or_lt with ha hb,\n    { exact this _ _ ha, },\n    { rw inner_eq_zero_sym,\n      exact this _ _ hb, }, },\n  clear h₀ a b,\n  intros a b h₀,\n  revert a,\n  apply well_founded.induction (@is_well_order.wf ι (<) _) b,\n  intros b ih a h₀,\n  simp only [gram_schmidt_def 𝕜 f b, inner_sub_right, inner_sum,\n    orthogonal_projection_singleton, inner_smul_right],\n  rw finset.sum_eq_single_of_mem a (finset.mem_Iio.mpr h₀),\n  { by_cases h : gram_schmidt 𝕜 f a = 0,\n    { simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero], },\n    { rw [← inner_self_eq_norm_sq_to_K, div_mul_cancel, sub_self],\n      rwa [ne.def, inner_self_eq_zero], }, },\n  simp_intros 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₁ hia₂,\n  { rw inner_eq_zero_sym,\n    exact ih a h₀ i hia₁ },\n  { exact ih i (mem_Iio.1 hi) a hia₂ }\nend\n\n/-- This is another version of `gram_schmidt_orthogonal` using `pairwise` instead. -/\ntheorem gram_schmidt_pairwise_orthogonal (f : ι → E) :\n  pairwise (λ a b, ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0) :=\nλ a b, gram_schmidt_orthogonal 𝕜 f\n\nopen submodule set order\n\nlemma mem_span_gram_schmidt (f : ι → E) {i j : ι} (hij : i ≤ j) :\n  f i ∈ span 𝕜 (gram_schmidt 𝕜 f '' Iic j) :=\nbegin\n  rw [gram_schmidt_def' 𝕜 f i],\n  simp_rw orthogonal_projection_singleton,\n  exact submodule.add_mem _ (subset_span $ mem_image_of_mem _ hij)\n    (submodule.sum_mem _ $ λ k hk, smul_mem (span 𝕜 (gram_schmidt 𝕜 f '' Iic j)) _ $\n    subset_span $ mem_image_of_mem (gram_schmidt 𝕜 f) $ (finset.mem_Iio.1 hk).le.trans hij),\nend\n\nlemma gram_schmidt_mem_span (f : ι → E) :\n  ∀ {j i}, i ≤ j → gram_schmidt 𝕜 f i ∈ span 𝕜 (f '' Iic j)\n| j := λ i hij,\nbegin\n  rw [gram_schmidt_def 𝕜 f i],\n  simp_rw orthogonal_projection_singleton,\n  refine submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij))\n    (submodule.sum_mem _ $ λ k hk, _),\n  let hkj : k < j := (finset.mem_Iio.1 hk).trans_le hij,\n  exact smul_mem _ _ (span_mono (image_subset f $ Iic_subset_Iic.2 hkj.le) $\n    gram_schmidt_mem_span le_rfl),\nend\nusing_well_founded { dec_tac := `[assumption] }\n\nlemma span_gram_schmidt_Iic (f : ι → E) (c : ι) :\n  span 𝕜 (gram_schmidt 𝕜 f '' Iic c) = span 𝕜 (f '' Iic c) :=\nspan_eq_span (set.image_subset_iff.2 $ λ i, gram_schmidt_mem_span _ _) $\n  set.image_subset_iff.2 $ λ i, mem_span_gram_schmidt _ _\n\nlemma span_gram_schmidt_Iio (f : ι → E) (c : ι) :\n  span 𝕜 (gram_schmidt 𝕜 f '' Iio c) = span 𝕜 (f '' Iio c) :=\nspan_eq_span\n  (set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $\n    gram_schmidt_mem_span _ _ le_rfl) $\n  set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $\n    mem_span_gram_schmidt _ _ le_rfl\n\n/-- `gram_schmidt` preserves span of vectors. -/\nlemma span_gram_schmidt (f : ι → E) : span 𝕜 (range (gram_schmidt 𝕜 f)) = span 𝕜 (range f) :=\nspan_eq_span (range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $\n  gram_schmidt_mem_span _ _ le_rfl) $\n  range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $ mem_span_gram_schmidt _ _ le_rfl\n\nlemma gram_schmidt_ne_zero_coe\n    (f : ι → E) (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :\n  gram_schmidt 𝕜 f n ≠ 0 :=\nbegin\n  by_contra h,\n  have h₁ : f n ∈ span 𝕜 (f '' Iio n),\n  { rw [← span_gram_schmidt_Iio 𝕜 f n, gram_schmidt_def' _ f, h, zero_add],\n    apply submodule.sum_mem _ _,\n    simp_intros a ha only [finset.mem_Ico],\n    simp only [set.mem_image, set.mem_Iio, orthogonal_projection_singleton],\n    apply submodule.smul_mem _ _ _,\n    rw finset.mem_Iio at ha,\n    refine subset_span ⟨a, ha, by refl⟩ },\n  have h₂ : (f ∘ (coe : set.Iic n → ι)) ⟨n, le_refl n⟩\n    ∈ span 𝕜 (f ∘ (coe : set.Iic n → ι) '' Iio ⟨n, le_refl n⟩),\n  { rw [image_comp],\n    convert h₁ using 3,\n    ext i,\n    simpa using @le_of_lt _ _ i n },\n  apply linear_independent.not_mem_span_image h₀ _ h₂,\n  simp only [set.mem_Iio, lt_self_iff_false, not_false_iff]\nend\n\n/-- If the input vectors of `gram_schmidt` are linearly independent,\nthen the output vectors are non-zero. -/\nlemma gram_schmidt_ne_zero (f : ι → E) (n : ι) (h₀ : linear_independent 𝕜 f) :\n  gram_schmidt 𝕜 f n ≠ 0 :=\ngram_schmidt_ne_zero_coe _ _ _ (linear_independent.comp h₀ _ subtype.coe_injective)\n\n/-- `gram_schmidt` produces a triangular matrix of vectors when given a basis. -/\nlemma gram_schmidt_triangular {i j : ι} (hij : i < j) (b : basis ι 𝕜 E) :\n  b.repr (gram_schmidt 𝕜 b i) j = 0 :=\nbegin\n  have : gram_schmidt 𝕜 b i ∈ span 𝕜 (gram_schmidt 𝕜 b '' set.Iio j),\n    from subset_span ((set.mem_image _ _ _).2 ⟨i, hij, rfl⟩),\n  have : gram_schmidt 𝕜 b i ∈ span 𝕜 (b '' set.Iio j),\n    by rwa [← span_gram_schmidt_Iio 𝕜 b j],\n  have : ↑(((b.repr) (gram_schmidt 𝕜 b i)).support) ⊆ set.Iio j,\n    from basis.repr_support_subset_of_mem_span b (set.Iio j) this,\n  exact (finsupp.mem_supported' _ _).1\n    ((finsupp.mem_supported 𝕜 _).2 this) j (not_mem_Iio.2 (le_refl j)),\nend\n\n/-- `gram_schmidt` produces linearly independent vectors when given linearly independent vectors. -/\nlemma gram_schmidt_linear_independent (f : ι → E) (h₀ : linear_independent 𝕜 f) :\n  linear_independent 𝕜 (gram_schmidt 𝕜 f) :=\nlinear_independent_of_ne_zero_of_inner_eq_zero\n    (λ i, gram_schmidt_ne_zero _ _ _ h₀) (λ i j, gram_schmidt_orthogonal 𝕜 f)\n\n/-- When given a basis, `gram_schmidt` produces a basis. -/\nnoncomputable def gram_schmidt_basis (b : basis ι 𝕜 E) : basis ι 𝕜 E :=\nbasis.mk\n  (gram_schmidt_linear_independent 𝕜 b b.linear_independent)\n  ((span_gram_schmidt 𝕜 b).trans b.span_eq)\n\nlemma coe_gram_schmidt_basis (b : basis ι 𝕜 E) :\n  (gram_schmidt_basis 𝕜 b : ι → E) = gram_schmidt 𝕜 b := basis.coe_mk _ _\n\n/-- the normalized `gram_schmidt`\n(i.e each vector in `gram_schmidt_normed` has unit length.) -/\nnoncomputable def gram_schmidt_normed (f : ι → E) (n : ι) : E :=\n(∥gram_schmidt 𝕜 f n∥ : 𝕜)⁻¹ • (gram_schmidt 𝕜 f n)\n\nlemma gram_schmidt_normed_unit_length_coe\n    (f : ι → E) (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :\n  ∥gram_schmidt_normed 𝕜 f n∥ = 1 :=\nby simp only [gram_schmidt_ne_zero_coe 𝕜 f n h₀,\n  gram_schmidt_normed, norm_smul_inv_norm, ne.def, not_false_iff]\n\nlemma gram_schmidt_normed_unit_length (f : ι → E) (n : ι) (h₀ : linear_independent 𝕜 f) :\n  ∥gram_schmidt_normed 𝕜 f n∥ = 1 :=\ngram_schmidt_normed_unit_length_coe _ _ _ (linear_independent.comp h₀ _ subtype.coe_injective)\n\n/-- **Gram-Schmidt Orthonormalization**:\n`gram_schmidt_normed` produces an orthornormal system of vectors. -/\ntheorem gram_schmidt_orthonormal (f : ι → E) (h₀ : linear_independent 𝕜 f) :\n  orthonormal 𝕜 (gram_schmidt_normed 𝕜 f) :=\nbegin\n  unfold orthonormal,\n  split,\n  { simp only [gram_schmidt_normed_unit_length, h₀, eq_self_iff_true, implies_true_iff], },\n  { intros i j hij,\n    simp only [gram_schmidt_normed, inner_smul_left, inner_smul_right, is_R_or_C.conj_inv,\n      is_R_or_C.conj_of_real, mul_eq_zero, inv_eq_zero, is_R_or_C.of_real_eq_zero, norm_eq_zero],\n    repeat { right },\n    exact gram_schmidt_orthogonal 𝕜 f hij }\nend\n\nlemma span_gram_schmidt_normed (f : ι → E) (s : set ι) :\n  span 𝕜 (gram_schmidt_normed 𝕜 f '' s) = span 𝕜 (gram_schmidt 𝕜 f '' s) :=\nbegin\n  refine span_eq_span (set.image_subset_iff.2 $ λ i hi, smul_mem _ _ $ subset_span $\n    mem_image_of_mem _ hi)\n    (set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ singleton_subset_set_iff.2 hi) _),\n  simp only [coe_singleton, set.image_singleton],\n  by_cases h : gram_schmidt 𝕜 f i = 0,\n  { simp [h] },\n  { refine mem_span_singleton.2 ⟨∥gram_schmidt 𝕜 f i∥, smul_inv_smul₀ _ _⟩,\n    exact_mod_cast (norm_ne_zero_iff.2 h) }\nend\n\nlemma span_gram_schmidt_normed_range (f : ι → E) :\n  span 𝕜 (range (gram_schmidt_normed 𝕜 f)) = span 𝕜 (range (gram_schmidt 𝕜 f)) :=\nby simpa only [image_univ.symm] using span_gram_schmidt_normed 𝕜 f univ\n\n/-- When given a basis, `gram_schmidt_normed` produces an orthonormal basis. -/\nnoncomputable def gram_schmidt_orthonormal_basis [fintype ι] (b : basis ι 𝕜 E) :\n  orthonormal_basis ι 𝕜 E :=\northonormal_basis.mk\n  (gram_schmidt_orthonormal 𝕜 b b.linear_independent)\n  (((span_gram_schmidt_normed_range 𝕜 b).trans (span_gram_schmidt 𝕜 b)).trans b.span_eq)\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/gram_schmidt_ortho.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7679553741628434}}
{"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.char_p.basic\n\n/-!\n# Invertibility of elements given a characteristic\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\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 : ℕ} (not_dvd : ¬(ring_char K ∣ t)) : invertible (t : K) :=\ninvertible_of_nonzero (λ h, not_dvd ((ring_char.spec K t).mp h))\n\nlemma not_ring_char_dvd_of_invertible {t : ℕ} [invertible (t : K)] :\n  ¬(ring_char K ∣ t) :=\nbegin\n  rw [← ring_char.spec, ← 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 : ℕ} [char_p K p]\n  {t : ℕ} (not_dvd : ¬(p ∣ t)) : invertible (t : K) :=\ninvertible_of_nonzero (λ h, not_dvd ((char_p.cast_eq_zero_iff K p t).mp h))\n\n-- warning: this could potentially loop with `ne_zero.invertible` - if there is weird type-class\n-- loops, watch out for that.\ninstance invertible_of_pos [char_zero K] (n : ℕ) [ne_zero n] : invertible (n : K) :=\ninvertible_of_nonzero $ ne_zero.out\n\nend field\n\nsection division_ring\nvariables [division_ring K] [char_zero K]\n\ninstance invertible_succ (n : ℕ) : 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 ≠ 0))\n\ninstance invertible_three : invertible (3 : K) :=\ninvertible_of_nonzero (by exact_mod_cast (dec_trivial : 3 ≠ 0))\n\nend division_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/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8856314813647587, "lm_q1q2_score": 0.7678741734782492}}
{"text": "\nimport tactic --hide\n\nlemma not_iff_imp_false (P : Prop) : ¬ P ↔ P → false := iff.rfl -- hide\nlemma contra (P Q : Prop) : (P ∧ ¬ P) → Q := by {cc} --hide\nlemma P_not_P_false (P : Prop) : P ∧ ¬ P → false := by {cc} --hide\n\n/-\nWe proved earlier that `(P → Q) → (¬ Q → ¬ P)`. The converse,\nthat `(¬ Q → ¬ P) → (P → Q)` is certainly true, but trying to prove\nit using the tactics we've learnt so far is impossible. \n-/\n\n/-Hint : Why is this impossible?\n \nSuppose we tried to prove this with the tactics we have seen so far, then our proof might look \nsomething like:\n```\nintro h,\nintro p,\nrw not_iff_imp_false at h,\nrw not_iff_imp_false at h,\n```\nYou are then left with the following state:\n```\nP Q : Prop,\nh : (Q → false) → P → false\np : P\n⊢ Q\n```\nand now we are stuck. In fact, using tactics such as `intro` and `apply` you will never be able to \nprove this lemma as this is not provable in \"constructive logic\". The key in proving this is to use \nLean's version of a truth table!\n\n-/\n\n/-\nIn order to continue we need a new tactic.\n\n## The `by_cases` tactic\n\nThe tactic <mark style =\"background-color : #ebdef0 \">`by_cases`</mark> allows us to create Lean's \nversion of a truth table.\n\nFor example, if you have `P Q : Prop`, then <mark style =\"background-color : #ebdef0 \">`by_cases hp : P; by_cases hq : Q,`</mark>\nwill create four goals, one for each of the four  possibilities for `P,Q`, i.e., \n\n```md\n| `P`     | `Q`     |\n| --------|---------|\n| `true`  | `true`  | \n| `true`  | `false` |   \n| `false` | `true`  |   \n| `false` | `false` |   \n```\n\n**Note the semicolon**! It means \"do the next tactic to all the goals, not just the first\".\n\n-/\n\n\n/- Lemma :\nIf $P$ and $Q$ are logical statements, then\n$(\\lnot Q\\implies \\lnot P)\\implies(P\\implies Q).$\n-/\nlemma contrapositive_2 (P Q : Prop) : (¬ Q → ¬ P) → (P → Q) :=\nbegin\n  by_cases p : P; by_cases q : Q,\n  intros h hh,\n  exact q,\n  intros h hh,\n  exfalso,\n  rw not_iff_imp_false at h,\n  rw not_iff_imp_false at h,\n  rw not_iff_imp_false at q,\n  apply h,\n  exact q,\n  apply p,\n  intros h hh,\n  exact q,\n  intros h hh,\n  exfalso,\n  apply P_not_P_false P,\n  split,\n  exact hh,\n  apply h,\n  exact q,\n\n\nend\n\n/-Hint : +1 Intelligence\nThe `by_cases` tactic works by adding the assumption `P ∨ ¬ P` and then doing `cases` on this.\nThe fact that `P ∨ ¬ P` is true is called the *law of the excluded middle*, and it cannot be proven \nby just using tactics such as `intro` and `apply`.\n-/\n\n/-Tactic : by_cases\n \nThe ``by_cases`` tactic is a simple truth table tactic: ``by_cases P`` turns one goal into two goals, \nwith ``P`` is assumed in the first, and ``¬P`` in the second.\n\nExamples\n--------\n\n1) If ``P`` is a proposition, then ``by_cases P`` turns your goal into two goals, \nand in each of your new tactic states you have one extra hypothesis. \nIn the first one you have a new hypothesis ``h : P`` and in the second you have a new hypothesis ``h : ¬P``.\n\n2) If you already have a hypothesis ``h`` then this can get a bit confusing, \nso you can also do ``by_cases hP : P``; then your new hypotheses will be ``hP : P`` and ``hP : ¬P``.\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/notlogic2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628703, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.767849109791924}}
{"text": "-- Las partes estrictas son irreflexivas\n-- =====================================\n\n-- ----------------------------------------------------\n-- Ej. 1. La parte estricta de una relación R es la \n-- relación R' definida por\n--    R' a b := R a b ∧ a ≠ b \n-- \n-- Demostrar que la parte estricta de cualquier \n-- relación es irreflexiva.\n-- ----------------------------------------------------\n\nimport tactic\n\nsection\n\nparameter {A : Type} \nparameter (R : A → A → Prop)\n\ndefinition R' (a b : A) : Prop := \n  R a b ∧ a ≠ b\n\n#reduce irreflexive R\n\n-- 1ª demostración\nexample : \n  irreflexive R' :=\nbegin\n  intros a h,\n  cases h with h1 h2,\n  apply h2,\n  refl,\nend\n\n-- 2ª demostración\nexample :\n  irreflexive R' :=\nassume a,\nassume : R' a a,\nhave a ≠ a, from and.right this,\nhave a = a, from rfl,\nshow false, from ‹a ≠ a› ‹a = a›\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/4_Relaciones/Las_partes_estrictas_son_irreflexivas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.767849105274223}}
{"text": "-- P, Q, Rを命題としたとき，以下が同値であることを示す:\n-- (i)  P または Q ならば R\n-- (ii) P ならば R かつ Q ならば R\n\n-- structured proofによる証明\nexample (p q r : Prop) : ((p ∨ q) → r) ↔ ((p → r) ∧ (q → r)) :=\nbegin\n\tsplit, -- 十分性と必要性に分ける\n\n\t-- 十分性(i) => (ii)が成り立つことを示す．\n\t{ intro h, -- 「P または Q ならば R」が成り立つと仮定し，それを仮定hとおく．\n\t\tsplit, -- 「P ならば R かつ Q ならば R」を「P ならば R」と「Q ならば R」に分割する\n\t\t\n\t\t-- 「P ならば R」が成り立つことを示す．\n\t\t{\tintro hp,  -- Pが成り立つと仮定し，これを仮定hpとおく\n\t\t  apply h,   -- 今，仮定h「P または Q ならば R」が成立している．\n\t\t\tleft,      -- 「P または Q」の左側「P」が成り立つことを示す．\n\t\t\tassumption -- 仮定hpより「P」は真．\n\t\t}, \n\t\t\n\t\t-- 「Q ならば R」が成り立つことを示す．\n\t\t{\tintro hq,  -- Qが成り立つと仮定し，これを仮定hqとおく\n\t\t  apply h,   -- 今，仮定h「PまたはQならばR」が成立している．\n\t\t\tright,     -- 「P または Q」の右側「Q」が成り立つことを示す．\n\t\t\tassumption -- 仮定hqより「Q」は真．\n\t\t}\n\t},\n\t\n\t-- 必要性(ii) => (i)が成り立つことを示す．\n\t{ intro h, -- 「P ならば R かつ Q ならば R」が成り立つと仮定し，それを仮定hとおく．\n\t  cases h with hpr hqr, -- hを「PならばR」が成り立つという仮定hprと「QならばR」が成り立つという仮定hqrに分ける\n\t\tintro hpq, -- 「P または Q」 が成り立つと仮定し，これを仮定hpqとおく．\n\t\tcases hpq with hp hq, -- 仮定hpqを「Pが成り立つ」という仮定hpと「Qが成り立つ」という仮定hqに分ける．\n\n\t\t-- 仮定hp「Pが成り立つ」の下で「Rが成り立つ」ことを示す．\n\t\t{ apply hpr, -- 今、「PならばR」が成り立っている\n\t\t  assumption -- 仮定よりPが成り立っているので、示された．\n\t\t},\n\t\t-- 仮定hp「Qが成り立つ」の下で「Rが成り立つ」ことを示す．\n\t\t{ apply hqr, -- 今、「Q ならば R」が成り立っている\n\t\t  assumption -- 仮定よりQが成り立っているので，示された．\n\t\t}\n\t}\nend\n\n-- 函数定義による証明\n-- 「P型かQ型の値を受け取ってR型の値を返す関数」を引数に取って\n-- 「P型の値を受け取ってR型の値を返す関数」と「Q型の値を受け取ってR型の値を返す関数」のペアを返す関数\n-- と\n-- 「P型の値を受け取ってR型の値を返す関数」と「Q型の値を受け取ってR型の値を返す関数」のペアを返す関数を引数に取って\n-- 「P型かQ型の値を受け取ってR型の値を返す関数」を返す関数\n-- のペアが定義出来れば命題が示せたことになる．\nexample (p q r : Prop)  : ((p ∨ q) → r) ↔ ((p → r) ∧ (q → r)) :=\n⟨ λ h, ⟨ λ hp, h $ or.inl hp, λ hq, h $ or.inr hq ⟩, λ ⟨ hpr, hqr ⟩ hpq, hpq.elim hpr hqr ⟩\n-- 第一成分のλ式「λ h, ⟨ λ hp, h $ or.inl hp, λ hq, h $ or.inr hq ⟩」について\n-- 引数hは「P型かQ型の値を受け取ってR型の値を返す関数」\n-- 戻り値は「⟨ λ hp, h $ or.inl hp, λ hq, h $ or.inr hq ⟩」\n-- (この第一成分が「P型の値を引数に取ってR型の値を返す関数」、\n-- 第二成分が「Q型の値を引数に取ってR型の値を返す関数」となっていればよい)\n--   第一成分のλ式「λ hp, h $ or.inl hp」について\n--   引数hpは「P型の値」\n--   or.inlは「任意の型Aを型Aまたは任意の型Bの値へ写す関数」\n--   or.inl hpは「型Pの値hpを「型Pまたは任意の型B」の値と見る」\n--   ただしhは「型Pまたは型Qの値」を引数に取るので、\n--   型推論により「or.inl hp」は「型Pまたは型Qの値」となる．\n--   関数hにより、型Pまたは型Qの値「or.inl hp」は「R型の値」へ写される\n--   よって、第一成分は「P型の値を引数に取ってR型の値を返す関数」\n--\n--   第二成分のλ式「λ hq, h $ or.inr hq」について\n--   引数hqは「Q型の値」\n--   or.inrは「任意の型Bを型Aまたは任意の型Bの値へ写す関数」\n--   or.inr hqは「型Qの値hqを「型Aまたは任意の型Q」の値と見る」\n--   ただしhは「型Pまたは型Qの値」を引数に取るので、\n--   型推論により「or.inr hq」は「型Pまたは型Qの値」となる．\n--   関数hにより、型Pまたは型Qの値「or.inr hq」は「R型の値」へ写される\n--   よって、第二成分は「Q型の値を引数に取ってR型の値を返す関数」\n--    \n-- 第二成分のλ式「λ ⟨ hpr, hqr ⟩ hpq, hpq.elim hpr hqr」について\n-- 引数⟨ hpr, hqr ⟩は「P型の値を受け取ってR型の値を返す関数」hprと\n-- 「Q型の値を受け取ってR型の値を返す関数」hqrとの対\n-- 戻り値は「hpq, hpq.elim hpr hqr」\n-- (この第一成分が「P型の値を引数に取ってR型の値を返す関数」、\n-- 第二成分が「Q型の値を引数に取ってR型の値を返す関数」となっていればよい)", "meta": {"author": "PotassiumIodide", "repo": "learning-lean", "sha": "d26a6b01819b63b5435fbdf1a9c7edabb8e6fcd9", "save_path": "github-repos/lean/PotassiumIodide-learning-lean", "path": "github-repos/lean/PotassiumIodide-learning-lean/learning-lean-d26a6b01819b63b5435fbdf1a9c7edabb8e6fcd9/src/or_implies.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037241905732, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7678490994024568}}
{"text": "import data.nat.modeq\n\n/-\n(a) Find r with 0 ≤ r ≤ 10 such that 7^137 ≡ r mod 11.\n(b) Find r with 0 ≤ r < 645 such that 2^81 ≡ r mod 645.\n(c) Find the last two digits of 3^124 (when expressed in decimal notation).\n(d) Show that there is a multiple of 21 which has 241 as its last three digits.\n-/\n\nlemma part_a : ∃r : ℕ, 0 ≤ r ∧ r ≤ 10 ∧ 7^137 ≡ r [MOD 11] :=\nbegin\n  use 6,\n  unfold nat.modeq,\n  norm_num,\nend\n\nlemma part_b : ∃r : ℕ, 0 ≤ r ∧ r < 645 ∧ 2^81 ≡ r [MOD 645] :=\nbegin\n  use 242,\n  unfold nat.modeq,\n  norm_num,\nend\n\n-- Once you compute the last two digits, change 37 below to them.\nlemma part_c : 3^124 ≡ 81 [MOD 100] :=\nbegin\n  unfold nat.modeq,\n  norm_num,\nend\n\nlemma part_d : ∃k : ℕ, 21 ∣ k ∧ k ≡ 241 [MOD 1000] :=\nbegin\n  unfold nat.modeq,\n  use 17241,\n  split,\n  {norm_num, },\n  {norm_num, },\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/exercise01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810481379379, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7678323623266288}}
{"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,∞) → (0,∞)` (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 = λ x, x` or `f = λ x, 1/x`\n-/\n\nopen real\n\nlemma abs_eq_one_of_pow_eq_one (x : ℝ) (n : ℕ) (hn : n ≠ 0) (h : x ^ n = 1) : |x| = 1 :=\nby rw [← 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 : ℝ → ℝ)\n  (H₁ : ∀ x > 0, f(x) > 0) :\n  (∀ w x y z : ℝ, 0 < w → 0 < x → 0 < y → 0 < z → w * x = y * z →\n    (f(w) ^ 2 + f(x) ^ 2) / (f(y ^ 2) + f(z ^ 2)) = (w ^ 2 + x ^ 2) / (y ^ 2 + z ^ 2)) ↔\n  ((∀ x > 0, f(x) = x) ∨ (∀ 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 ≠ 0 := ne_of_gt (add_pos (pow_pos hy 2) (pow_pos hz 2)),\n      have hz2y2 : z ^ 2 + y ^ 2 ≠ 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 (w * x + y * z)*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₂,\n  have h₀ : f(1) ≠ 0, { specialize H₁ 1 zero_lt_one, exact ne_of_gt H₁ },\n\n  have h₁ : f(1) = 1,\n  { specialize H₂ 1 1 1 1 zero_lt_one zero_lt_one zero_lt_one zero_lt_one rfl,\n    norm_num [← two_mul] at H₂,\n    rw mul_div_mul_left (f(1) ^ 2) (f 1) two_ne_zero at H₂,\n    rwa ← (div_eq_iff h₀).mpr (sq (f 1)) },\n\n  have h₂ : ∀ 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₂ 1 x (sqrt x) (sqrt x) zero_lt_one hx (sqrt_pos.mpr hx) (sqrt_pos.mpr hx) h1xss,\n    rw [h₁, one_pow 2, sq_sqrt (le_of_lt hx), ← two_mul (f(x)), ← two_mul x] at H₂,\n    have hx_ne_0 : x ≠ 0 := ne_of_gt hx,\n    have hfx_ne_0 : f(x) ≠ 0, { specialize H₁ x hx, exact ne_of_gt H₁ },\n    field_simp at H₂ ⊢,\n    linear_combination 1/2 * H₂ },\n\n  have h₃ : ∀ x > 0, f(x) = x ∨ f(x) = 1 / x, { simpa [sub_eq_zero] using h₂ },\n\n  by_contra' h,\n  rcases h with ⟨⟨b, hb, hfb₁⟩, ⟨a, ha, hfa₁⟩⟩,\n  obtain hfa₂ := or.resolve_right (h₃ a ha) hfa₁, -- f(a) ≠ 1/a, f(a) = a\n  obtain hfb₂ := or.resolve_left (h₃ b hb) hfb₁,  -- f(b) ≠ 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₂ 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), ← two_mul (f(a * b)), ← two_mul (a * b)] at H₂,\n  rw [hfa₂, hfb₂] at H₂,\n\n  have h2ab_ne_0 : 2 * (a * b) ≠ 0 := mul_ne_zero two_ne_zero (ne_of_gt hab),\n\n  specialize h₃ (a * b) hab,\n  cases h₃ with hab₁ hab₂,\n\n  -- f(ab) = ab → b^4 = 1 → b = 1 → f(b) = b → false\n  { field_simp [hab₁] at H₂,\n    field_simp [ne_of_gt hb] at H₂,\n    have hb₁ : b ^ 4 = 1 := by linear_combination -H₂,\n    obtain hb₂ := abs_eq_one_of_pow_eq_one b 4 (show 4 ≠ 0, by norm_num) hb₁,\n    rw abs_of_pos hb at hb₂, rw hb₂ at hfb₁, exact hfb₁ h₁ },\n\n  -- f(ab) = 1/ab → a^4 = 1 → a = 1 → f(a) = 1/a → false\n  { have hb_ne_0 : b ≠ 0 := ne_of_gt hb,\n    field_simp [hab₂] at H₂,\n    have H₃ : 2 * b ^ 4 * (a ^ 4 - 1) = 0 := by linear_combination (H₂),\n    have h2b4_ne_0 : 2 * (b ^ 4) ≠ 0 := mul_ne_zero two_ne_zero (pow_ne_zero 4 hb_ne_0),\n    have ha₁ : a ^ 4 = 1, { simpa [sub_eq_zero, h2b4_ne_0] using H₃ },\n    obtain ha₂ := abs_eq_one_of_pow_eq_one a 4 (show 4 ≠ 0, by norm_num) ha₁,\n    rw abs_of_pos ha at ha₂, rw ha₂ at hfa₁, norm_num at hfa₁ },\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_q4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7677740528371619}}
{"text": "import ..lectures.love12_basic_mathematical_structures_demo\n\n\n/-! # LoVe Exercise 12: Basic Mathematical Structures -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Question 1: Type Classes\n\nRecall the inductive type `btree` we introduced earlier: -/\n\n#check btree\n\n/-! The following function takes two trees and attaches copies of the second\ntree to each leaf of the first tree. -/\n\ndef btree.graft {α : Type} : btree α → btree α → btree α\n| btree.empty        u := u\n| (btree.node a l r) u := btree.node a (btree.graft l u) (btree.graft r u)\n\n#reduce btree.graft (btree.node 1 btree.empty btree.empty)\n  (btree.node 2 btree.empty btree.empty)\n\n/-! 1.1. Prove the following two lemmas by structural induction on `t`. -/\n\nlemma btree.graft_assoc {α : Type} (t u v : btree α) :\n  btree.graft (btree.graft t u) v = btree.graft t (btree.graft u v) :=\nsorry\n\nlemma btree.graft_empty {α : Type} (t : btree α) :\n  btree.graft t btree.empty = t :=\nsorry\n\n/-! 1.2. Declare btree an instance of `add_monoid` using `graft` as addition\noperator. -/\n\n#print add_monoid\n\n@[instance] def btree.add_monid {α : Type} : add_monoid (btree α) :=\nsorry\n\n/-! 1.3. Explain why `btree` with `graft` as addition cannot be declared an\ninstance of `add_group`. -/\n\n#print add_group\n\n/-! 1.4 (**optional**). Prove the following lemma illustrating why `btree` with\n`graft` as addition does not constitute an `add_group`. -/\n\nlemma btree.add_left_neg_counterexample :\n  ∃x : btree ℕ, ∀y : btree ℕ, btree.graft y x ≠ btree.empty :=\nsorry\n\n\n/-! ## Question 2: Multisets and Finsets\n\nRecall the following definitions from the lecture: -/\n\n#check multiset.elems\n#check finset.elems\n#check list.elems\n\n/-! 2.1. Prove that the multiset of nodes does not change when mirroring a tree.\n\nHints:\n\n* Perform structural induction on `t`.\n\n* The `cc` tactic also works with set operations. -/\n\nlemma multiset.elems_mirror (t : btree ℕ) :\n  multiset.elems (mirror t) = multiset.elems t :=\nsorry\n\n/-! 2.2. Prove that the finite set of nodes does not change when mirroring a\ntree. -/\n\nlemma finset.elems_mirror (t : btree ℕ) :\n  finset.elems (mirror t) = finset.elems t :=\nsorry\n\n/-! 2.3. Show that this does not hold for the list of nodes by providing a\ntree `t` for which `nodes_list t ≠ nodes_list (mirror t)`.\n\nIf you define a suitable counterexample, the proof below will succeed. -/\n\ndef rotten_tree : btree ℕ :=\nsorry\n\n#eval list.elems rotten_tree\n#eval list.elems (mirror rotten_tree)\n\nlemma list.elems_mirror_counterexample :\n  ∃t : btree ℕ, list.elems t ≠ list.elems (mirror t) :=\nbegin\n  apply exists.intro rotten_tree,\n  exact dec_trivial\nend\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/love12_basic_mathematical_structures_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7677740336874566}}
{"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.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`λ + X i` is equal to a linear combination of the symmetric polynomials `esymm σ 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 σ R)`, which enables us to talk about linear combinations of\n`esymm σ 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 (σ : Type u) [fintype σ]\n\n/-- A sum version of Vieta's formula. Viewing `X i` as variables,\nthe product of linear terms `λ + X i` is equal to a linear combination of\nthe symmetric polynomials `esymm σ R j`. -/\nlemma prod_X_add_C_eq_sum_esymm :\n  (∏ i : σ, (polynomial.C (X i) + polynomial.X) : polynomial (mv_polynomial σ R) )=\n  ∑ j in range (card σ + 1),\n    (polynomial.C (esymm σ R j) * polynomial.X ^ (card σ - j)) :=\nbegin\n  classical,\n  rw [prod_add, sum_powerset],\n  refine sum_congr begin congr end (λ j hj, _),\n  rw [esymm, polynomial.C.map_sum, sum_mul],\n  refine sum_congr rfl (λ t ht, _),\n  have h : (univ \\ t).card = card σ - 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 σ R →+* polynomial _).map_prod, prod_const, ← 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 `∑ 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 : σ → R) : ∏ i : σ, (polynomial.C (r i) + polynomial.X) =\n  ∑ i in range (card σ + 1), (∑ t in powerset_len i (univ : finset σ),\n    ∏ i in t, polynomial.C (r i)) * polynomial.X ^ (card σ - i) :=\nbegin\n  classical,\n  have h := @prod_X_add_C_eq_sum_esymm _ _ σ _,\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, 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, map_mul],\n  congr,\n  funext,\n  simp only [eval_prod, eval_X, (polynomial.C : R →+* polynomial R).map_prod],\nend\n\nlemma esymm_to_sum (r : σ → R) (j : ℕ) : polynomial.C (eval r (esymm σ R j)) =\n  ∑ t in powerset_len j (univ : finset σ), ∏ 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 →+* 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 `∑ t in powerset_len (card σ - k) (univ : finset σ), ∏ i in t, r i`,\ni.e. the symmetric polynomial `esymm σ R (card σ - k)` of the constant terms `r i`. -/\n\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/polynomial/vieta.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7677227176730613}}
{"text": "import tactic\n\nnamespace qary_hamming\n-- Setup for defining vectors over a finite alphabet 𝒜\nuniverse u\nvariables {𝒜 : Type u} [fintype 𝒜] [decidable_eq 𝒜] [field_𝒜: field 𝒜]\n\ndef distance : Π {n : ℕ}, vector 𝒜 n → vector 𝒜 n → ℕ\n| 0       _ _ := 0\n| (n + 1) x y :=\n  if x.head = y.head then\n    distance x.tail y.tail\n  else\n    nat.succ (distance x.tail y.tail)\n\nvariable (n : ℕ)\n\n@[simp]\nlemma distance_self_zero (x : vector 𝒜 n) : distance x x = 0 :=\nbegin\n  induction n with k ih,\n    refl,\n  unfold distance, simp, apply ih, \nend\n\nlemma distance_zero_eq (x y : vector 𝒜 n) : distance x y = 0 ↔ (x = y) :=\nbegin\n  split,\n    {intro h,\n    induction n with k ih,\n      simp,\n    unfold distance at h,\n    by_cases h' : x.head = y.head,\n      {rw h' at h, simp at h,\n      have : x.tail = y.tail, from ih _ _ h,\n      rw [(vector.cons_head_tail x).symm, (vector.cons_head_tail y).symm, h', this]},\n      {by_contradiction hneq,\n      simp only [if_congr, h', if_false] at h, \n      rw ← nat.add_one at h, simp at h,\n      exact h,}},\n  intro h, rw h, simp,\nend\n\ndef weight : Π {n : ℕ}, vector 𝒜 n → ℕ \n| 0 _ := 0\n| (n + 1) x :=\n  if x.head = field_𝒜.zero then\n    weight x.tail\n  else\n    nat.succ (weight x.tail)\n\nend qary_hamming\n\n-- Some examples, using an alphabet of size 4\n@[derive [decidable_eq, fintype]]\ninductive D : Type\n| a : D\n| b : D\n| c : D\n| d : D\n\nopen D\n\n#eval qary_hamming.distance ⟨[a,a,a,a], rfl⟩ ⟨[a,b,b,a], rfl⟩ -- 2\n#eval qary_hamming.distance ⟨[a,b,c,d], rfl⟩ ⟨[d,c,b,a], rfl⟩ -- 4\n", "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/qary_codes_example.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.767722716277954}}
{"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\nHere we define an inductive type of nonempty lists, and subtypes\nof lists with specified starting and ending points.  These can be \nused for paths in a graph, or a more constructive approach to \nthe equivalence relation generated by an arbitrary relation,\nor for ordered simplices in a simplicial complex, for example.\n\nAn alternative approach would be to define \n`(pos_list α) := (list α) × α`.  That might be better.\n\n-/\n\nimport data.list.basic\n\ninductive pos_list (α : Type) : Type \n| const : α → pos_list\n| cons : α → pos_list → pos_list\n\nnamespace pos_list\n\nvariable {α : Type}\nvariables (p q r : pos_list α)\n\ndef steps : pos_list α → list (α × α) \n| (const a) := list.nil\n| (cons a (const b)) := [⟨a,b⟩]\n| (cons a (cons b p)) := ⟨a,b⟩ :: (cons b p).steps\n\ndef length : pos_list α → ℕ \n| (const a) := 0\n| (cons a p) := p.length.succ\n\nlemma steps_length : ∀ p : pos_list α, p.steps.length = p.length\n| (const a) := rfl\n| (cons a (const b)) := rfl\n| (cons a (cons b p)) := by {\n    rw[steps,length,← steps_length (cons b p),list.length],\n  }\n\ndef to_list : pos_list α → list α \n| (const a) := [a]\n| (cons a p) := list.cons a (to_list p)\n\nlemma to_list_length : ∀ p : pos_list α, p.to_list.length = p.length.succ\n| (const a) := rfl\n| (cons a p) := by {rw[to_list,length,list.length,p.to_list_length],}\n\ndef head : pos_list α → α \n| (const a) := a\n| (cons a p) := a\n\ndef foot : pos_list α → α \n| (const a) := a\n| (cons a p) := p.foot\n\ndef append : pos_list α → pos_list α → pos_list α\n| (const a) q := cons a q\n| (cons a p) q := cons a (append p q)\n\nlemma head_append : ∀ (p q : pos_list α),\n head (append p q) = head p\n| (const a) q := rfl\n| (cons a p) q := rfl\n\nlemma foot_append : ∀ (p q : pos_list α),\n foot (append p q) = foot q\n| (const a) q := rfl\n| (cons a p) q := foot_append p q\n\nlemma append_assoc : ∀ (p q r : pos_list α), \n append (append p q) r = append p (append q r)\n| (const a) q r := rfl\n| (cons a p) q r := by {dsimp[append],rw[append_assoc p q r],}\n\nlemma length_append : ∀ (p q : pos_list α), \n length (append p q) = p.length + q.length + 1\n| (const a) q := by {rw[append,length,length,zero_add],}\n| (cons a p) q := by {\n    rw[append,length,length,length_append p q,← nat.add_one,← nat.add_one],\n    rw[add_assoc p.length 1 q.length,add_comm 1 q.length],\n    repeat { rw[add_assoc] },\n  }\n\nlemma steps_cons : ∀ (a : α) (p : pos_list α), \n steps (cons a p) = ⟨a,p.head⟩ :: p.steps\n| a (const b) := rfl\n| a (cons b p) := rfl\n\nlemma steps_append : ∀ (p q : pos_list α) , \n steps (append p q) = p.steps ++ (⟨p.foot,q.head⟩ :: q.steps)\n| (const a) q := by {rw[append,steps,foot,steps_cons],refl}\n| (cons a p) q := by {\n    rw[append,steps_cons,steps_cons,foot,head_append],\n    rw[steps_append p q,list.cons_append],repeat {rw[list.append_assoc]},\n}\n\ndef reverse : pos_list α → pos_list α \n| (const a) := const a\n| (cons a p) := p.reverse.append (const a)\n\nlemma head_reverse : ∀ (p : pos_list α), p.reverse.head = p.foot\n| (const a) := rfl\n| (cons a p) := by {dsimp[reverse,foot],rw[head_append,head_reverse p],}\n\nlemma foot_reverse : ∀ (p : pos_list α), p.reverse.foot = p.head\n| (const a) := rfl\n| (cons a p) := by {dsimp[reverse,head],rw[foot_append],refl,}\n\nlemma reverse_append : ∀ (p q : pos_list α),\n reverse (append p q) = append (reverse q) (reverse p) \n| (const a) q := rfl\n| (cons a p) q := by {dsimp[append,reverse],rw[reverse_append p q,append_assoc],}\n\nlemma reverse_reverse : ∀ (p : pos_list α), p.reverse.reverse = p\n| (const a) := rfl\n| (cons a p) := begin \n dsimp[reverse],rw[reverse_append,reverse_reverse p],refl,\nend\n\nlemma length_reverse : ∀ (p : pos_list α), p.reverse.length = p.length\n| (const a) := rfl\n| (cons a p) := by {\n    rw[reverse,length_append,length,length,length_reverse p],\n    rw[← nat.add_one,add_zero (length p)],\n}\n\ndef swap : (α × α) → (α × α) \n| ⟨a,b⟩ := ⟨b,a⟩\n\nlemma steps_reverse : ∀ (p : pos_list α), \n p.reverse.steps = (p.steps.map swap).reverse \n| (const a) := rfl\n| (cons a p) := by {\n rw[reverse,steps_append,steps_reverse p,foot_reverse,head,steps],\n rw[steps_cons,list.map,swap,list.reverse_cons],\n}\n\ndef all (r : α → Prop) : pos_list α → Prop\n| (const a) := r a\n| (cons a p) := (r a) ∧ (all p)\n\ndef chain (r : α → α → Prop) : pos_list α → Prop\n| (const a) := true\n| (cons a (const b)) := r a b\n| (cons a (cons b p)) := (r a b) ∧ (chain (cons b p))\n\ndef pairwise (r : α → α → Prop) : pos_list α → Prop\n| (const a) := true\n| (cons a p) := (all (r a) p) ∧ (pairwise p)\n\ndef splice0 : ∀ (p q : pos_list α), pos_list α \n| (const a) q := q\n| (cons a p) q := cons a (splice0 p q)\n\nlemma length_splice0 : ∀ (p q : pos_list α),\n (splice0 p q).length = p.length + q.length\n| (const a) q := by {rw[splice0,length,zero_add],}\n| (cons a p) q := by {\n    rw[splice0,length,length,length_splice0 p q,← nat.add_one,← nat.add_one],\n    rw[add_assoc,add_assoc,add_comm 1],\n}\n\nlemma head_splice0 : ∀ (p q : pos_list α) (e : p.foot = q.head),\n (splice0 p q).head = p.head\n| (const a) q e := e.symm\n| (cons a p) q e := rfl\n\nlemma foot_splice0 : ∀ (p q : pos_list α),\n foot (splice0 p q) = q.foot\n| (const a) q := rfl\n| (cons a p) q := foot_splice0 p q\n\nlemma splice0_cons_append : ∀ (p : pos_list α) (b : α) (q : pos_list α) (e : p.foot = b),\n splice0 p (cons b q) = append p q\n| (const a) b q e := by {rw[splice0,append,← e],refl}\n| (cons a p) b q e := by {rw[splice0,append,splice0_cons_append p b q e],}\n\nlemma const_splice0 (a : α) (q : pos_list α) :\n splice0 (const a) q = q := rfl\n\nlemma splice0_const : ∀ (p : pos_list α) (b : α) (e : p.foot = b),\n splice0 p (const b) = p\n| (const a) b e := by {rw[splice0],congr,exact e.symm}\n| (cons a p) b e := by {rw[splice0,splice0_const p b e],}\n\nlemma splice0_append : ∀ (p q r : pos_list α), \n splice0 p (append q r) = append (splice0 p q) r \n| (const a) q r := rfl\n| (cons a p) q r := by {rw[splice0,splice0,append,splice0_append p q r],}\n\nlemma splice0_assoc : ∀ (p q r : pos_list α),\n splice0 (splice0 p q) r = splice0 p (splice0 q r)\n| (const a) q r := rfl\n| (cons a p) q r := by {rw[splice0,splice0,splice0,splice0_assoc p q r],}\n\nlemma steps_splice0 : ∀ (p q : pos_list α) (e : p.foot = q.head),\n (splice0 p q).steps = p.steps ++ q.steps\n| (const a) q e := by {rw[splice0,steps],refl}\n| (cons a p) q e := by {\n    change p.foot = q.head at e,\n    rw[splice0,steps_cons,steps_cons,steps_splice0 p q e,list.cons_append,head_splice0],\n    exact e\n  }\n\nlemma reverse_splice0 : ∀ (p q : pos_list α) (e : p.foot = q.head),\n (splice0 p q).reverse = splice0 q.reverse p.reverse\n| (const a) q e := by {\n    rw[reverse,splice0,splice0_const q.reverse a (q.foot_reverse.trans e.symm)],\n  }\n| (cons a p) q e := by {\n    rw[splice0,reverse,reverse_splice0 p q e,reverse,splice0_append],\n  }\n\ndef list_between (a b : α) : Type* := \n { p : pos_list α // p.head = a ∧ p.foot = b }\n\nnamespace list_between\n\ndef const (a : α) : list_between a a := ⟨pos_list.const a,⟨rfl,rfl⟩⟩\n\ndef reverse {a b : α} (p : list_between a b) : list_between b a := \n ⟨p.val.reverse,⟨p.val.head_reverse.trans p.property.right,\n                p.val.foot_reverse.trans p.property.left⟩⟩\n\ndef match_eq {a b c : α} (p : list_between a b) (q : list_between b c) :\n p.val.foot = q.val.head := p.property.right.trans q.property.left.symm\n  \ndef splice {a b c : α} (p : list_between a b) (q : list_between b c) :\n (list_between a c) := ⟨splice0 p.val q.val,begin\n   rw[head_splice0 p.val q.val (match_eq p q),foot_splice0],\n   exact ⟨p.property.left,q.property.right⟩\n  end⟩ \n\ndef length {a b : α} (p : list_between a b) : ℕ := p.val.length\n\nlemma length_const (a : α) : (const a).length = 0 := rfl\n\nlemma length_reverse {a b : α} (p : list_between a b) :\n p.reverse.length = p.length := \n  p.val.length_reverse\n\nlemma length_splice {a b c : α} (p : list_between a b) (q : list_between b c) :\n (splice p q).length = p.length + q.length := \n  pos_list.length_splice0 p.val q.val\n\nlemma const_splice {a b : α} (p : list_between a b) : \n splice (const a) p = p := \n  subtype.eq (const_splice0 a p.val)\n\nlemma splice_const {a b : α} (p : list_between a b) : \n splice p (const b) = p := \n  subtype.eq (splice0_const p.val b p.property.right)\n\nlemma reverse_splice {a b c : α} (p : list_between a b) (q : list_between b c) :\n (splice p q).reverse = splice q.reverse p.reverse := \n  subtype.eq (reverse_splice0 p.val q.val (match_eq p q)) \n\nlemma splice_assoc {a b c d : α}\n (p : list_between a b) (q : list_between b c) (r : list_between c d) :\n  splice (splice p q) r = splice p (splice q r) := \n   subtype.eq (splice0_assoc p.val q.val r.val)\n\nend list_between\n\n\n\n\nend pos_list\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/pos_list.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7675339154615665}}
{"text": "/-\nA formalization of Hao Huang's sensitivity theorem: in the hypercube of\ndimension n ≥ 1, if one colors more than half the vertices then at least one\nvertex has at least √n colored neighbors.\n\nA fun summer collaboration by\nReid Barton, Johan Commelin, Jesse Han, Chris Hughes, Rob Lewis, and Patrick Massot,\nbased on Don Knuth's account of the story\n(https://www.cs.stanford.edu/~knuth/papers/huang.pdf),\nusing the Lean theorem prover (http://leanprover.github.io/),\nby Leonardo de Moura at Microsoft Research, and his collaborators\n(https://leanprover.github.io/people/),\nand using Lean's user maintained mathematics library\n(https://github.com/leanprover-community/mathlib).\n-/\nimport tactic.fin_cases\nimport tactic.apply_fun\nimport linear_algebra.finite_dimensional\nimport analysis.normed_space.basic\nimport for_mathlib\n\n-- The next three lines assert we do not want to give a constructive proof,\n-- but rather use classical logic.\nnoncomputable theory\nlocal attribute [instance, priority 1] classical.prop_decidable\nlocal attribute [instance, priority 0] set.decidable_mem_of_fintype\n\nnotation `|`x`|` := abs x\nnotation `√` := real.sqrt\n\nopen function bool linear_map fintype finite_dimensional dual_pair\n\n/- -------------------------------------------------------------------------\\\n|  The hypercube.                                                           |\n\\---------------------------------------------------------------------------/\n\n/-\nNotations:\nℕ denotes natural numbers (including zero).\nfin n = {0, ⋯ , n - 1}.\nbool = {tt, ff}.\n-/\n\n/-- The hypercube in dimension n. -/\ndef Q (n : ℕ) := fin n → bool\n\n/-- The projection from Q (n + 1) to Q n forgetting the first value\n(ie. the image of zero). -/\ndef π {n : ℕ} : Q (n + 1) → Q n := λ p, p ∘ fin.succ\n\nnamespace Q\n-- n will always denote a natural number.\nvariable (n : ℕ)\n\n/-- Q n is not empty -/\ninstance : inhabited (Q n) := ⟨λ i, tt⟩\n\n/-- Q 0 has a unique element. -/\ninstance : unique (Q 0) :=\n⟨⟨λ _, tt⟩, by { intro, ext x, fin_cases x }⟩\n\n/-- Q n is finite. -/\ninstance : fintype (Q n) := by delta Q; apply_instance\n\n/-- Q n has 2^n elements. -/\nlemma card : card (Q n) = 2^n :=\nby simp [Q]\n\n/-- The ℝ-module structure on functions from Q n to ℝ (with finite support). -/\ninstance coeffs_module (n) : module ℝ (Q n →₀ ℝ) := finsupp.module (Q n) ℝ\n\n-- Until the end of this namespace, n will be an implicit argument (still\n-- a natural number).\nvariable {n}\n\nlemma succ_n_eq (p q : Q (n+1)) : p = q ↔ (p 0 = q 0 ∧ π p = π q) :=\nbegin\n  split,\n  { intro h, rw h, exact ⟨rfl, rfl⟩, },\n  { rintros ⟨h₀, h⟩,\n    ext x,\n    by_cases hx : x = 0,\n    { rwa hx },\n    { rw ← fin.succ_pred x hx,\n      convert congr_fun h (fin.pred x hx) } }\nend\n\n/-- The adjacency relation defining the graph structure on Q n:\np.adjacent q if there is an edge from p to q in Q n -/\ndef adjacent {n : ℕ} (p : Q n) : set (Q n) := λ q, ∃! i, p i ≠ q i\n\n/-- In Q 0, no two vertices are adjacent. -/\nlemma not_adjacent_zero (p q : Q 0) : ¬ p.adjacent q :=\nby rintros ⟨v, _⟩; apply fin_zero_elim v\n\n/-- If p and q in Q (n+1) have different values at zero then they are adjacent\niff their projections to Q n are equal. -/\nlemma adj_succ_of_zero_neq {p q : Q (n+1)} (h₀ : p 0 ≠ q 0) :\n  p.adjacent q ↔ π p = π q :=\nbegin\n  split,\n  { rintros ⟨i, h_eq, h_uni⟩,\n    ext x, by_contradiction hx,\n    apply fin.succ_ne_zero x,\n    rw [h_uni _ hx, h_uni _ h₀] },\n    { intro heq,\n    use [0, h₀],\n    intros y hy,\n    contrapose! hy,\n    rw ←fin.succ_pred _ hy,\n    apply congr_fun heq }\nend\n\n/-- If p and q in Q (n+1) have the same value at zero then they are adjacent\niff their projections to Q n are adjacent. -/\nlemma adj_succ_of_zero_eq {p q : Q (n+1)} (h₀ : p 0 = q 0) :\n  p.adjacent q ↔ (π p).adjacent (π q) :=\nbegin\n  split,\n  { rintros ⟨i, h_eq, h_uni⟩,\n    have h_i : i ≠ 0, from λ h_i, absurd h₀ (by rwa h_i at h_eq),\n    use [i.pred h_i,\n         show p (fin.succ (fin.pred i _)) ≠ q (fin.succ (fin.pred i _)),\n           by rwa fin.succ_pred],\n    intros y hy,\n    simp [eq.symm (h_uni _ hy)] },\n  { rintros ⟨i, h_eq, h_uni⟩,\n    use [i.succ, h_eq],\n    intros y hy,\n    rw [←fin.pred_inj, fin.pred_succ],\n    { apply h_uni,\n      change p (fin.pred _ _).succ ≠ q (fin.pred _ _).succ,\n      simp [hy] },\n    { contrapose! hy,\n      rw [hy, h₀] },\n    { apply fin.succ_ne_zero } }\nend\n\n@[symm] lemma adjacent.symm {p q : Q n} : p.adjacent q ↔ q.adjacent p :=\nby simp only [adjacent, ne_comm]\n\nend Q\n\n/- -------------------------------------------------------------------------\\\n|  The vector space.                                                        |\n\\---------------------------------------------------------------------------/\n\n/-- The free vector space on vertices of a hypercube, defined inductively. -/\ndef V : ℕ → Type\n| 0 := ℝ\n| (n+1) := V n × V n\n\nnamespace V\nvariables (n : ℕ)\n\n-- V n is a real vector space whose equality relation is computable.\n\ninstance : decidable_eq (V n) :=\nby { induction n ; { dunfold V, resetI, apply_instance } }\n\ninstance : add_comm_group (V n) :=\nby { induction n ; { dunfold V, resetI, apply_instance } }\n\ninstance : vector_space ℝ (V n) :=\nby { induction n ; { dunfold V, resetI, apply_instance } }\n\n-- The next five definitions are short circuits helping Lean to quickly find\n-- relevant structures on V n\ndef module : module ℝ (V n) := by apply_instance\ndef add_comm_semigroup : add_comm_semigroup (V n) := by apply_instance\ndef add_comm_monoid : add_comm_monoid (V n) := by apply_instance\ndef has_scalar : has_scalar ℝ (V n) := by apply_instance\ndef has_add : has_add (V n) := by apply_instance\n\nend V\n\nlocal attribute [instance, priority 100000]\n  V.module V.add_comm_semigroup V.add_comm_monoid V.has_scalar V.has_add\n\n/-- The basis of V indexed by the hypercube, defined inductively. -/\nnoncomputable def e : Π {n}, Q n → V n\n| 0     := λ _, (1:ℝ)\n| (n+1) := λ x, cond (x 0) (e (π x), 0) (0, e (π x))\n\n@[simp] lemma e_zero_apply (x : Q 0) : e x = (1 : ℝ) := rfl\n\n/-- The dual basis to e, defined inductively. -/\nnoncomputable def ε : Π {n : ℕ} (p : Q n), V n →ₗ[ℝ] ℝ\n| 0 _ := linear_map.id\n| (n+1) p := cond (p 0) ((ε $ π p).comp $ linear_map.fst _ _ _) ((ε $ π p).comp $ linear_map.snd _ _ _)\n\nvariable {n : ℕ}\n\nlemma duality (p q : Q n) : ε p (e q) = if p = q then 1 else 0 :=\nbegin\n  induction n with n IH,\n  { rw (show p = q, from subsingleton.elim p q),\n    dsimp [ε, e],\n    simp },\n  { dsimp [ε, e],\n    cases hp : p 0 ; cases hq : q 0,\n    all_goals {\n      repeat {rw cond_tt},\n      repeat {rw cond_ff},\n      simp only [linear_map.fst_apply, linear_map.snd_apply, linear_map.comp_apply, IH],\n      try { congr' 1, rw Q.succ_n_eq, finish },\n      try {\n        erw (ε _).map_zero,\n        have : p ≠ q, { intro h, rw p.succ_n_eq q at h, finish },\n        simp [this] } } }\nend\n\n/-- Any vector in V n annihilated by all ε p's is zero. -/\nlemma epsilon_total {v : V n} (h : ∀ p : Q n, (ε p) v = 0) : v = 0 :=\nbegin\n  induction n with n ih,\n  { dsimp [ε] at h, exact h (λ _, tt) },\n  { cases v with v₁ v₂,\n    ext ; change _ = (0 : V n) ; simp only [] ; apply ih ; intro p ;\n    [ let q : Q (n+1) := λ i, if h : i = 0 then tt else p (i.pred h),\n      let q : Q (n+1) := λ i, if h : i = 0 then ff else p (i.pred h)],\n    all_goals {\n      specialize h q,\n      rw [ε, show q 0 = tt, from rfl, cond_tt] at h <|> rw [ε, show q 0 = ff, from rfl, cond_ff] at h,\n      rwa show p = π q, by { ext, simp [q, fin.succ_ne_zero, π] } } }\nend\n\n/-- e and ε are dual families of vectors. It implies that e is indeed a basis\nand ε computes coefficients of decompositions of vectors on that basis. -/\ndef dual_pair_e_ε (n : ℕ) : dual_pair (@e n) (@ε n) :=\n{ eval := duality,\n  total := @epsilon_total _ }\n\n-- We will now derive the dimension of V, first as a cardinal in dim_V and,\n-- since this cardinal is finite, as a natural number in findim_V\n\nlemma dim_V : vector_space.dim ℝ (V n) = 2^n :=\nhave vector_space.dim ℝ (V n) = ↑(2^n : ℕ),\n  by convert dim_eq_card (dual_pair_e_ε _).is_basis using 1; rw Q.card,\nby assumption_mod_cast\n\ninstance : finite_dimensional ℝ (V n) :=\nfin_dim_of_finite_basis (dual_pair_e_ε _).is_basis\n\n-- TODO: fix this in mathlib\nlocal attribute [-elim_cast] cardinal.nat_cast_pow\nlocal attribute [move_cast] cardinal.nat_cast_pow\n\nlemma findim_V : findim ℝ (V n) = 2^n :=\nhave _ := @dim_V n,\nby rw ←findim_eq_dim at this; assumption_mod_cast\n\n/- -------------------------------------------------------------------------\\\n|  The linear map.                                                          |\n\\---------------------------------------------------------------------------/\n\n/-- The linear operator f_n corresponding to Huang's matrix A_n,\ndefined inductively as a ℝ-linear map from V n to V n. -/\nnoncomputable def f : Π n, V n →ₗ[ℝ] V n\n| 0 := 0\n| (n+1) := linear_map.pair\n             (linear_map.copair (f n) linear_map.id)\n             (linear_map.copair linear_map.id (-f n))\n\n-- The preceding definition use linear map constructions to automatically\n-- get that f is linear, but its values are somewhat buried as a side-effect.\n-- The next two lemmas unbury them.\n\n@[simp] lemma f_zero : f 0 = 0 := rfl\n\nlemma f_succ_apply (v : V (n+1)) :\n  (f (n+1) : V (n+1) → V (n+1)) v = (f n v.1 + v.2, v.1 - f n v.2) :=\nbegin\n  cases v,\n  rw f,\n  simp only [linear_map.id_apply, linear_map.pair_apply, prod.mk.inj_iff,\n    linear_map.neg_apply, sub_eq_add_neg, linear_map.copair_apply],\n  exact ⟨rfl, rfl⟩\nend\n\n-- In the next statement, the explicit conversion (n : ℝ) of n to a real number\n-- is necessary since otherwise `n • v` refers to the multiplication defined\n-- using only the addition of V.\n\nlemma f_squared : ∀ v : V n, (f n) (f n v) = (n : ℝ) • v :=\nbegin\n  induction n with n IH; intro,\n  { simpa only [nat.cast_zero, zero_smul] },\n  { cases v, simp [f_succ_apply, IH, add_smul] }\nend\n\n-- We now compute the matrix of f in the e basis (p is the line index,\n-- q the column index.)\n\nlemma f_matrix :\n  ∀ p q : Q n, |ε q (f n (e p))| = if q.adjacent p then 1 else 0 :=\nbegin\n  induction n with n IH,\n  { intros p q,\n    dsimp [f],\n    simp [Q.not_adjacent_zero] },\n  { intros p q,\n    have ite_nonneg : ite (π q = π p) (1 : ℝ) 0 ≥ 0,\n    { split_ifs ; norm_num },\n    have f_map_zero := (show linear_map ℝ (V (n+0)) (V n), from f n).map_zero,\n    dsimp [e, ε, f], cases hp : p 0 ; cases hq : q 0,\n    all_goals\n    { repeat {rw cond_tt}, repeat {rw cond_ff},\n      simp [f_map_zero, hp, hq, IH, duality, abs_of_nonneg ite_nonneg, Q.adj_succ_of_zero_neq,\n            Q.adj_succ_of_zero_eq],\n      congr' 1 } }\nend\n\n/-- The linear operator g_m corresponding to Knuth's matrix B_m. -/\nnoncomputable def g (m : ℕ) : V m →ₗ[ℝ] V (m+1) :=\nlinear_map.pair (f m + √(m+1) • linear_map.id) linear_map.id\n\n-- in the following lemmas, m will denote a natural number\nvariables {m : ℕ}\n\n-- again we unpack what are the values of g\nlemma g_apply : ∀ v, g m v = (f m v + √(m+1) • v, v) :=\nby delta g; simp\n\nlemma g_injective : injective (g m) :=\nbegin\n  rw g,\n  intros x₁ x₂ h,\n  simp only [linear_map.pair_apply, linear_map.id_apply, prod.mk.inj_iff] at h,\n  exact h.right\nend\n\nlemma f_image_g (w : V (m + 1)) (hv : ∃ v, g m v = w) :\n  (f (m + 1) : _) w = √(m + 1) • w :=\nbegin\n  rcases hv with ⟨v, rfl⟩,\n  have : √(m+1) * √(m+1) = m+1 :=\n    real.mul_self_sqrt (by exact_mod_cast zero_le _),\n  simp [-add_comm, this, f_succ_apply, g_apply, f_squared, smul_add, add_smul, smul_smul],\nend\n\n/- -------------------------------------------------------------------------\\\n|  The main proof.                                                          |\n\\---------------------------------------------------------------------------/\n\n-- In this section, in order to enforce that n is positive, we write it as\n-- m + 1 for some natural number m.\n\n-- dim X will denote the dimension of a subspace X as a cardinal\nnotation `dim` X:70 := vector_space.dim ℝ ↥X\n-- fdim X will denote the (finite) dimension of a subspace X as a natural number\nnotation `fdim` := findim ℝ\n\n-- Span S will denote the ℝ-subspace spanned by S\nnotation `Span` := submodule.span ℝ\n\n-- Card X will denote the cardinal of a subset of a finite type, as a\n-- natural number.\nnotation `Card` X:70 := X.to_finset.card\n\n-- In the following, ⊓ and ⊔ will denote intersection and sums of ℝ-subspaces,\n-- equipped with their subspace structures. The notations come from the general\n-- theory of lattices, with inf and sup (also known as meet and join).\n\n/-- If a subset H of Q (m+1) has cardinal at least 2^m + 1 then the\nsubspace of V (m+1) spanned by the corresponding basis vectors non-trivially\nintersects the range of g m. -/\nlemma exists_eigenvalue (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) :\n  ∃ y ∈ Span (e '' H) ⊓ (g m).range, y ≠ (0 : _) :=\nbegin\n  let W := Span (e '' H),\n  let img := (g m).range,\n  suffices : 0 < dim (W ⊓ img),\n  { simp only [exists_prop],\n    exact_mod_cast exists_mem_ne_zero_of_dim_pos this },\n  have dim_le : dim (W ⊔ img) ≤ 2^(m + 1),\n  { convert ← dim_submodule_le (W ⊔ img),\n    apply dim_V },\n  have dim_add : dim (W ⊔ img) + dim (W ⊓ img) = dim W + 2^m,\n  { convert ← dim_sup_add_dim_inf_eq W img,\n    rw ← dim_eq_injective (g m) g_injective,\n    apply dim_V },\n  have dimW : dim W = card H,\n  { have li : linear_independent ℝ (restrict e H) :=\n      linear_independent.comp (dual_pair_e_ε _).is_basis.1 _ subtype.val_injective,\n    have hdW := dim_span li,\n    rw set.range_restrict at hdW,\n    convert hdW,\n    rw [cardinal.mk_image_eq ((dual_pair_e_ε _).is_basis.injective zero_ne_one), cardinal.fintype_card] },\n  rw ← findim_eq_dim ℝ at ⊢ dim_le dim_add dimW,\n  rw [← findim_eq_dim ℝ, ← findim_eq_dim ℝ] at dim_add,\n  norm_cast at ⊢ dim_le dim_add dimW,\n  rw nat.pow_succ at dim_le,\n  rw set.to_finset_card at hH,\n  linarith\nend\n\ntheorem huang_degree_theorem (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) :\n  ∃ q, q ∈ H ∧ √(m + 1) ≤ Card (H ∩ q.adjacent) :=\nbegin\n  rcases exists_eigenvalue H hH with ⟨y, ⟨⟨y_mem_H, y_mem_g⟩, y_ne⟩⟩,\n  have coeffs_support : ((dual_pair_e_ε (m+1)).coeffs y).support ⊆ H.to_finset,\n  { intros p p_in,\n    rw finsupp.mem_support_iff at p_in,\n    rw set.mem_to_finset,\n    exact (dual_pair_e_ε _).mem_of_mem_span y_mem_H p p_in },\n  obtain ⟨q, H_max⟩ : ∃ q : Q (m+1), ∀ q' : Q (m+1), |(ε q' : _) y| ≤ |ε q y|,\n    from fintype.exists_max _,\n  have H_q_pos : 0 < |ε q y|,\n  { contrapose! y_ne,\n    exact epsilon_total (λ p, abs_nonpos_iff.mp (le_trans (H_max p) y_ne)) },\n  refine ⟨q, (dual_pair_e_ε _).mem_of_mem_span y_mem_H q (abs_pos_iff.mp H_q_pos), _⟩,\n  let s := √(m+1),\n  suffices : s * |ε q y| ≤ ↑(_) * |ε q y|,\n    from (mul_le_mul_right H_q_pos).mp ‹_›,\n\n  let coeffs := (dual_pair_e_ε (m+1)).coeffs,\n  let φ : V (m+1) → V (m+1) := f (m+1),\n  calc\n    s * (abs (ε q y))\n        = abs (ε q (s • y)) : by rw [map_smul, smul_eq_mul, abs_mul, abs_of_nonneg (real.sqrt_nonneg _)]\n    ... = abs (ε q (φ y)) : by rw [← f_image_g y (by simpa using y_mem_g)]\n    ... = abs (ε q (φ (lc _ (coeffs y)))) : by rw (dual_pair_e_ε _).decomposition y\n    ... = abs ((coeffs y).sum (λ (i : Q (m + 1)) (a : ℝ), a • ((ε q) ∘ (f (m + 1)) ∘ λ (i : Q (m + 1)), e i) i)): by\n                  { dsimp only [φ],\n                    erw [(f $ m+1).map_finsupp_total, (ε q).map_finsupp_total, finsupp.total_apply] ; apply_instance }\n    ... ≤ (coeffs y).support.sum (λ p,\n           |(coeffs y p) * (ε q $ φ $ e p)| ) : norm_triangle_sum _ $ λ p, coeffs y p * _\n    ... = (coeffs y).support.sum (λ p, |coeffs y p| * ite (q.adjacent p) 1 0) : by simp only [abs_mul, f_matrix]\n    ... = ((coeffs y).support ∩ (Q.adjacent q).to_finset).sum (λ p, |coeffs y p| ) : finset.sum_ite _ _ _\n    ... ≤ ((coeffs y).support ∩ (Q.adjacent q).to_finset).sum (λ p, |coeffs y q| ) : finset.sum_le_sum (λ p _, H_max p)\n    ... = (finset.card ((coeffs y).support ∩ (Q.adjacent q).to_finset): ℝ) * |coeffs y q| : by rw [← smul_eq_mul, ← finset.sum_const']\n    ... ≤ (finset.card ((H ∩ Q.adjacent q).to_finset )) * |ε q y| :\n     (mul_le_mul_right H_q_pos).mpr (by {\n             norm_cast,\n             exact finset.card_le_of_subset (by rw finset.to_finset_inter ; apply finset.inter_subset_inter_right coeffs_support) })\nend\n", "meta": {"author": "leanprover-community", "repo": "lean-sensitivity", "sha": "295adaf3f496166bbf97869c49de5373dd6b6d85", "save_path": "github-repos/lean/leanprover-community-lean-sensitivity", "path": "github-repos/lean/leanprover-community-lean-sensitivity/lean-sensitivity-295adaf3f496166bbf97869c49de5373dd6b6d85/src/sensitivity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7675265038449348}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov\n-/\nimport topology.bases\nimport data.finset.order\nimport data.set.accumulate\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 two 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\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 “too simple to be simple”\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 {α : Type u} {β : Type v} [topological_space α] {s t : set α}\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 ∈ s` such that every set of `f` meets every neighborhood of `a`. -/\ndef is_compact (s : set α) := ∀ ⦃f⦄ [ne_bot f], f ≤ 𝓟 s → ∃a∈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`𝓝 a ⊓ f`, `a ∈ s`. -/\nlemma is_compact.compl_mem_sets (hs : is_compact s) {f : filter α} (hf : ∀ a ∈ s, sᶜ ∈ 𝓝 a ⊓ f) :\n  sᶜ ∈ f :=\nbegin\n  contrapose! hf,\n  simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc, ← exists_prop] at hf ⊢,\n  exact @hs _ hf inf_le_right\nend\n\n/-- The complement to a compact set belongs to a filter `f` if each `a ∈ s` has a neighborhood `t`\nwithin `s` such that `tᶜ` belongs to `f`. -/\nlemma is_compact.compl_mem_sets_of_nhds_within (hs : is_compact s) {f : filter α}\n  (hf : ∀ a ∈ s, ∃ t ∈ 𝓝[s] a, tᶜ ∈ f) :\n  sᶜ ∈ f :=\nbegin\n  refine hs.compl_mem_sets (λ a ha, _),\n  rcases hf a ha with ⟨t, ht, hst⟩,\n  replace ht := mem_inf_principal.1 ht,\n  refine mem_inf_sets.2 ⟨_, ht, _, hst, _⟩,\n  rintros x ⟨h₁, h₂⟩ hs,\n  exact h₂ (h₁ hs)\nend\n\n/-- If `p : set α → 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 α} (hs : is_compact s) {p : set α → Prop} (he : p ∅)\n  (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t))\n  (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) :\n  p s :=\nlet f : filter α :=\n  { sets := {t | p tᶜ},\n    univ_sets := by simpa,\n    sets_of_superset := λ t₁ t₂ ht₁ ht, hmono (compl_subset_compl.2 ht) ht₁,\n    inter_sets := λ t₁ t₂ ht₁ ht₂, by simp [compl_inter, hunion ht₁ ht₂] } in\nhave sᶜ ∈ 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 ∩ t) :=\nbegin\n  introsI f hnf hstf,\n  obtain ⟨a, hsa, ha⟩ : ∃ a ∈ s, cluster_pt a f :=\n    hs (le_trans hstf (le_principal_iff.2 (inter_subset_left _ _))),\n  have : a ∈ t :=\n    (ht.mem_of_nhds_within_ne_bot $ ha.mono $\n      le_trans hstf (le_principal_iff.2 (inter_subset_right _ _))),\n  exact ⟨a, ⟨hsa, this⟩, ha⟩\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 ∩ t) :=\ninter_comm t s ▸ ht.inter_right hs\n\n/-- The set difference of a compact set and an open set is a compact set. -/\nlemma 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 ⊆ s) :\n  is_compact t :=\ninter_eq_self_of_subset_right h ▸ hs.inter_right ht\n\nlemma is_compact.adherence_nhdset {f : filter α}\n  (hs : is_compact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : is_open t) (ht₂ : ∀a∈s, cluster_pt a f → a ∈ t) :\n  t ∈ f :=\nclassical.by_cases mem_sets_of_eq_bot $\n  assume : f ⊓ 𝓟 tᶜ ≠ ⊥,\n  let ⟨a, ha, (hfa : cluster_pt a $ f ⊓ 𝓟 tᶜ)⟩ := @@hs ⟨this⟩ $ inf_le_left_of_le hf₂ in\n  have a ∈ t,\n    from ht₂ a ha (hfa.of_inf_left),\n  have tᶜ ∩ t ∈ 𝓝[tᶜ] a,\n    from inter_mem_nhds_within _ (mem_nhds_sets ht₁ this),\n  have A : 𝓝[tᶜ] a = ⊥,\n    from empty_in_sets_eq_bot.1 $ compl_inter_self t ▸ this,\n  have 𝓝[tᶜ] a ≠ ⊥,\n    from hfa.of_inf_right.ne,\n  absurd A this\n\nlemma compact_iff_ultrafilter_le_nhds :\n  is_compact s ↔ (∀f : ultrafilter α, ↑f ≤ 𝓟 s → ∃a∈s, ↑f ≤ 𝓝 a) :=\nbegin\n  refine (forall_ne_bot_le_iff _).trans _,\n  { rintro f g hle ⟨a, has, haf⟩,\n    exact ⟨a, has, haf.mono hle⟩ },\n  { simp only [ultrafilter.cluster_pt_iff] }\nend\n\nalias compact_iff_ultrafilter_le_nhds ↔ 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 {ι : Type v} [hι : nonempty ι] (hs : is_compact s)\n  (U : ι → set α) (hUo : ∀i, is_open (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : directed (⊆) U) :\n  ∃ i, s ⊆ U i :=\nhι.elim $ λ i₀, is_compact.induction_on hs ⟨i₀, empty_subset _⟩\n  (λ s₁ s₂ hs ⟨i, hi⟩, ⟨i, subset.trans hs hi⟩)\n  (λ s₁ s₂ ⟨i, hi⟩ ⟨j, hj⟩, let ⟨k, hki, hkj⟩ := hdU i j in\n    ⟨k, union_subset (subset.trans hi hki) (subset.trans hj hkj)⟩)\n  (λ x hx, let ⟨i, hi⟩ := mem_Union.1 (hsU hx) in\n    ⟨U i, mem_nhds_within_of_mem_nhds (mem_nhds_sets (hUo i) hi), i, subset.refl _⟩)\n\n/-- For every open cover of a compact set, there exists a finite subcover. -/\nlemma is_compact.elim_finite_subcover {ι : Type v} (hs : is_compact s)\n  (U : ι → set α) (hUo : ∀i, is_open (U i)) (hsU : s ⊆ ⋃ i, U i) :\n  ∃ t : finset ι, s ⊆ ⋃ i ∈ t, U i :=\nhs.elim_directed_cover _ (λ t, is_open_bUnion $ λ i _, hUo i) (Union_eq_Union_finset U ▸ hsU)\n  (directed_of_sup $ λ t₁ t₂ h, bUnion_subset_bUnion_left h)\n\nlemma is_compact.elim_nhds_subcover' (hs : is_compact s) (U : Π x ∈ s, set α)\n  (hU : ∀ x ∈ s, U x ‹x ∈ s› ∈ 𝓝 x) :\n  ∃ t : finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 :=\n(hs.elim_finite_subcover (λ x : s, interior (U x x.2)) (λ x, is_open_interior)\n  (λ x hx, mem_Union.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 $ hU _ _⟩)).imp $ λ t ht,\nsubset.trans ht $ bUnion_subset_bUnion_right $ λ _ _, interior_subset\n\nlemma is_compact.elim_nhds_subcover (hs : is_compact s) (U : α → set α) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) :\n  ∃ t : finset α, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x :=\nlet ⟨t, ht⟩ := hs.elim_nhds_subcover' (λ x _, U x) hU\nin ⟨t.image coe, λ x hx, let ⟨y, hyt, hyx⟩ := finset.mem_image.1 hx in hyx ▸ y.2,\n  by rwa finset.set_bUnion_finset_image⟩\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 α} {ι : Type v} (hs : is_compact s)\n  (Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : s ∩ (⋂ i, Z i) = ∅) :\n  ∃ t : finset ι, s ∩ (⋂ i ∈ t, Z i) = ∅ :=\nlet ⟨t, ht⟩ := hs.elim_finite_subcover (λ i, (Z i)ᶜ) (λ 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⟨t, 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⟩\n\n/-- If `s` is a compact set in a topological space `α` and `f : ι → set α` is a locally finite\nfamily of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/\nlemma locally_finite.finite_nonempty_inter_compact {ι : Type*} {f : ι → set α}\n  (hf : locally_finite f) {s : set α} (hs : is_compact s) :\n  finite {i | (f i ∩ s).nonempty} :=\nbegin\n  choose U hxU hUf using hf,\n  rcases hs.elim_nhds_subcover U (λ x _, hxU x) with ⟨t, -, hsU⟩,\n  refine (t.finite_to_set.bUnion (λ x _, hUf x)).subset _,\n  rintro i ⟨x, hx⟩,\n  rcases mem_bUnion_iff.1 (hsU hx.2) with ⟨c, hct, hcx⟩,\n  exact mem_bUnion hct ⟨x, hx.1, hcx⟩\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 α} {ι : Type v} (hs : is_compact s)\n  (Z : ι → set α) (hZc : ∀i, is_closed (Z i)) (hsZ : ∀ t : finset ι, (s ∩ ⋂ i ∈ t, Z i).nonempty) :\n  (s ∩ ⋂ i, Z i).nonempty :=\nbegin\n  simp only [← ne_empty_iff_nonempty] at hsZ ⊢,\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  {ι : Type v} [hι : nonempty ι] (Z : ι → set α) (hZd : directed (⊇) Z)\n  (hZn : ∀ i, (Z i).nonempty) (hZc : ∀ i, is_compact (Z i)) (hZcl : ∀ i, is_closed (Z i)) :\n  (⋂ i, Z i).nonempty :=\nbegin\n  apply hι.elim,\n  intro i₀,\n  let Z' := λ i, Z i ∩ Z i₀,\n  suffices : (⋂ i, Z' i).nonempty,\n  { exact nonempty.mono (Inter_subset_Inter $ assume i, inter_subset_left (Z i) (Z i₀)) this },\n  rw ← ne_empty_iff_nonempty,\n  intro H,\n  obtain ⟨t, ht⟩ : ∃ (t : finset ι), ((Z i₀) ∩ ⋂ (i ∈ t), Z' i) = ∅,\n    from (hZc i₀).elim_finite_subfamily_closed Z'\n      (assume i, is_closed_inter (hZcl i) (hZcl i₀)) (by rw [H, inter_empty]),\n  obtain ⟨i₁, hi₁⟩ : ∃ i₁ : ι, Z i₁ ⊆ Z i₀ ∧ ∀ i ∈ t, Z i₁ ⊆ Z' i,\n  { rcases directed.finset_le hZd t with ⟨i, hi⟩,\n    rcases hZd i i₀ with ⟨i₁, hi₁, hi₁₀⟩,\n    use [i₁, hi₁₀],\n    intros j hj,\n    exact subset_inter (subset.trans hi₁ (hi j hj)) hi₁₀ },\n  suffices : ((Z i₀) ∩ ⋂ (i ∈ t), Z' i).nonempty,\n  { rw ← ne_empty_iff_nonempty at this, contradiction },\n  refine nonempty.mono _ (hZn i₁),\n  exact subset_inter hi₁.left (subset_bInter hi₁.right)\nend\n\n/-- Cantor's intersection theorem for sequences indexed by `ℕ`:\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 : ℕ → set α) (hZd : ∀ i, Z (i+1) ⊆ Z i)\n  (hZn : ∀ i, (Z i).nonempty) (hZ0 : is_compact (Z 0)) (hZcl : ∀ i, is_closed (Z i)) :\n  (⋂ i, Z i).nonempty :=\nhave Zmono : _, from @monotone_of_monotone_nat (order_dual _) _ Z hZd,\nhave hZd : directed (⊇) Z, from directed_of_sup Zmono,\nhave ∀ i, Z i ⊆ Z 0, from assume i, Zmono $ zero_le i,\nhave hZc : ∀ 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 β} {c : β → set α}\n  (hs : is_compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) :\n  ∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i :=\nbegin\n  rcases hs.elim_finite_subcover (λ i, c i : b → set α) _ _ with ⟨d, hd⟩;\n    [skip, simpa using hc₁, simpa using hc₂],\n  refine ⟨↑(d.image coe), _, finset.finite_to_set _, _⟩; simp *\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 compact_of_finite_subfamily_closed\n  (h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →\n    s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) :\n  is_compact s :=\nassume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, cluster_pt x f),\n  have hf : ∀x∈s, 𝓝 x ⊓ f = ⊥,\n    by simpa only [cluster_pt, not_exists, not_not, ne_bot_iff],\n  have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,\n    from assume ⟨x, hxs, hx⟩,\n    have ∅ ∈ 𝓝 x ⊓ f, by rw [empty_in_sets_eq_bot, hf x hxs],\n    let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_sets] at this; exact this in\n    have ∅ ∈ 𝓝[t₂] x,\n      from (𝓝[t₂] x).sets_of_superset (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,\n    have 𝓝[t₂] x = ⊥,\n      by rwa [empty_in_sets_eq_bot] at this,\n    by simp only [closure_eq_cluster_pts] at hx; exact (hx t₂ ht₂).ne this,\n  let ⟨t, ht⟩ := h (λ i : f.sets, closure i.1) (λ i, is_closed_closure)\n    (by simpa [eq_empty_iff_forall_not_mem, not_exists]) in\n  have (⋂i∈t, subtype.val i) ∈ f,\n    from t.Inter_mem_sets.2 $ assume i hi, i.2,\n  have s ∩ (⋂i∈t, subtype.val i) ∈ f,\n    from inter_mem_sets (le_principal_iff.1 hfs) this,\n  have ∅ ∈ f,\n    from mem_sets_of_superset this $ assume x ⟨hxs, hx⟩,\n    let ⟨i, hit, hxi⟩ := (show ∃i ∈ t, x ∉ 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 ∈ closure i.val, from subset_closure (mem_bInter_iff.mp hx i hit),\n    show false, from hxi this,\n  hfn.ne $ by rwa [empty_in_sets_eq_bot] at this\n\n/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/\nlemma compact_of_finite_subcover\n  (h : Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) →\n    s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) :\n  is_compact s :=\ncompact_of_finite_subfamily_closed $\n  assume ι Z hZc hsZ,\n  let ⟨t, ht⟩ := h (λ i, (Z i)ᶜ) (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  ⟨t, 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⟩\n\n/-- A set `s` is compact if and only if\nfor every open cover of `s`, there exists a finite subcover. -/\nlemma compact_iff_finite_subcover :\n  is_compact s ↔ (Π {ι : Type u} (U : ι → (set α)), (∀ i, is_open (U i)) →\n    s ⊆ (⋃ i, U i) → (∃ (t : finset ι), s ⊆ (⋃ i ∈ t, U i))) :=\n⟨assume hs ι, hs.elim_finite_subcover, compact_of_finite_subcover⟩\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 compact_iff_finite_subfamily_closed :\n  is_compact s ↔ (Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →\n    s ∩ (⋂ i, Z i) = ∅ → (∃ (t : finset ι), s ∩ (⋂ i ∈ t, Z i) = ∅)) :=\n⟨assume hs ι, hs.elim_finite_subfamily_closed, compact_of_finite_subfamily_closed⟩\n\n@[simp]\nlemma compact_empty : is_compact (∅ : set α) :=\nassume f hnf hsf, not.elim hnf.ne $\nempty_in_sets_eq_bot.1 $ le_principal_iff.1 hsf\n\n@[simp]\nlemma compact_singleton {a : α} : is_compact ({a} : set α) :=\nλ f hf hfa, ⟨a, rfl, cluster_pt.of_le_nhds'\n  (hfa.trans $ by simpa only [principal_singleton] using pure_le_nhds a) hf⟩\n\nlemma set.subsingleton.is_compact {s : set α} (hs : s.subsingleton) : is_compact s :=\nsubsingleton.induction_on hs compact_empty $ λ x, compact_singleton\n\nlemma set.finite.compact_bUnion {s : set β} {f : β → set α} (hs : finite s)\n  (hf : ∀i ∈ s, is_compact (f i)) :\n  is_compact (⋃i ∈ s, f i) :=\ncompact_of_finite_subcover $ assume ι U hUo hsU,\n  have ∀i : subtype s, ∃t : finset ι, f i ⊆ (⋃ j ∈ t, U j), from\n    assume ⟨i, hi⟩, (hf i hi).elim_finite_subcover _ hUo\n      (calc f i ⊆ ⋃i ∈ s, f i : subset_bUnion_of_mem hi\n            ... ⊆ ⋃j, U j     : hsU),\n  let ⟨finite_subcovers, h⟩ := 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 (⋃i ∈ s, f i) ⊆ (⋃ i ∈ t, U i), from bUnion_subset $\n    assume i hi, calc\n    f i ⊆ (⋃ j ∈ finite_subcovers ⟨i, hi⟩, U j) : (h ⟨i, hi⟩)\n    ... ⊆ (⋃ j ∈ t, U j) : bUnion_subset_bUnion_left $\n      assume j hj, finset.mem_bUnion.mpr ⟨_, finset.mem_univ _, hj⟩,\n  ⟨t, this⟩\n\nlemma finset.compact_bUnion (s : finset β) {f : β → set α} (hf : ∀i ∈ s, is_compact (f i)) :\n  is_compact (⋃i ∈ s, f i) :=\ns.finite_to_set.compact_bUnion hf\n\nlemma compact_accumulate {K : ℕ → set α} (hK : ∀ n, is_compact (K n)) (n : ℕ) :\n  is_compact (accumulate K n) :=\n(finite_le_nat n).compact_bUnion $ λ k _, hK k\n\nlemma compact_Union {f : β → set α} [fintype β]\n  (h : ∀i, is_compact (f i)) : is_compact (⋃i, f i) :=\nby rw ← bUnion_univ; exact finite_univ.compact_bUnion (λ i _, h i)\n\nlemma set.finite.is_compact (hs : finite s) : is_compact s :=\nbUnion_of_singleton s ▸ hs.compact_bUnion (λ _ _, compact_singleton)\n\nlemma finite_of_is_compact_of_discrete [discrete_topology α] (s : set α) (hs : is_compact s) :\n  s.finite :=\nbegin\n  have := hs.elim_finite_subcover (λ x : α, ({x} : set α))\n    (λ x, is_open_discrete _),\n  simp only [set.subset_univ, forall_prop_of_true, set.Union_of_singleton] at this,\n  rcases this with ⟨t, ht⟩,\n  suffices : (⋃ (i : α) (H : i ∈ t), {i} : set α) = (t : set α),\n  { rw this at ht, exact t.finite_to_set.subset ht },\n  ext x,\n  simp only [exists_prop, set.mem_Union, set.mem_singleton_iff, exists_eq_right', finset.mem_coe]\nend\n\nlemma is_compact.union (hs : is_compact s) (ht : is_compact t) : is_compact (s ∪ t) :=\nby rw union_eq_Union; exact compact_Union (λ b, by cases b; assumption)\n\nlemma is_compact.insert (hs : is_compact s) (a) : is_compact (insert a s) :=\ncompact_singleton.union hs\n\n/-- `filter.cocompact` is the filter generated by complements to compact sets. -/\ndef filter.cocompact (α : Type*) [topological_space α] : filter α :=\n⨅ (s : set α) (hs : is_compact s), 𝓟 (sᶜ)\n\nlemma filter.has_basis_cocompact : (filter.cocompact α).has_basis is_compact compl :=\nhas_basis_binfi_principal'\n  (λ s hs t ht, ⟨s ∪ t, hs.union ht, compl_subset_compl.2 (subset_union_left s t),\n    compl_subset_compl.2 (subset_union_right s t)⟩)\n  ⟨∅, compact_empty⟩\n\nlemma filter.mem_cocompact : s ∈ filter.cocompact α ↔ ∃ t, is_compact t ∧ tᶜ ⊆ s :=\nfilter.has_basis_cocompact.mem_iff.trans $ exists_congr $ λ t,  exists_prop\n\nlemma filter.mem_cocompact' : s ∈ filter.cocompact α ↔ ∃ t, is_compact t ∧ sᶜ ⊆ t :=\nfilter.mem_cocompact.trans $ exists_congr $ λ t, and_congr_right $ λ ht, compl_subset_comm\n\nlemma is_compact.compl_mem_cocompact (hs : is_compact s) : sᶜ ∈ filter.cocompact α :=\nfilter.has_basis_cocompact.mem_of_mem hs\n\nsection tube_lemma\n\nvariables [topological_space β]\n\n/-- `nhds_contain_boxes s t` means that any open neighborhood of `s × t` in `α × β` includes\na product of an open neighborhood of `s` by an open neighborhood of `t`. -/\ndef nhds_contain_boxes (s : set α) (t : set β) : Prop :=\n∀ (n : set (α × β)) (hn : is_open n) (hp : set.prod s t ⊆ n),\n∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n\n\nlemma nhds_contain_boxes.symm {s : set α} {t : set β} :\n  nhds_contain_boxes s t → nhds_contain_boxes t s :=\nassume H n hn hp,\n  let ⟨u, v, uo, vo, su, tv, p⟩ :=\n    H (prod.swap ⁻¹' n)\n      (hn.preimage continuous_swap)\n      (by rwa [←image_subset_iff, image_swap_prod]) in\n  ⟨v, u, vo, uo, tv, su,\n    by rwa [←image_subset_iff, image_swap_prod] at p⟩\n\nlemma nhds_contain_boxes.comm {s : set α} {t : set β} :\n  nhds_contain_boxes s t ↔ nhds_contain_boxes t s :=\niff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm\n\nlemma nhds_contain_boxes_of_singleton {x : α} {y : β} :\n  nhds_contain_boxes ({x} : set α) ({y} : set β) :=\nassume n hn hp,\n  let ⟨u, v, uo, vo, xu, yv, hp'⟩ :=\n    is_open_prod_iff.mp hn x y (hp $ by simp) in\n  ⟨u, v, uo, vo, by simpa, by simpa, hp'⟩\n\nlemma nhds_contain_boxes_of_compact {s : set α} (hs : is_compact s) (t : set β)\n  (H : ∀ x ∈ s, nhds_contain_boxes ({x} : set α) t) : nhds_contain_boxes s t :=\nassume n hn hp,\nhave ∀x : subtype s, ∃uv : set α × set β,\n     is_open uv.1 ∧ is_open uv.2 ∧ {↑x} ⊆ uv.1 ∧ t ⊆ uv.2 ∧ set.prod uv.1 uv.2 ⊆ n,\n  from assume ⟨x, hx⟩,\n    have set.prod {x} t ⊆ n, from\n      subset.trans (prod_mono (by simpa) (subset.refl _)) hp,\n    let ⟨ux,vx,H1⟩ := H x hx n hn this in ⟨⟨ux,vx⟩,H1⟩,\nlet ⟨uvs, h⟩ := classical.axiom_of_choice this in\nhave us_cover : s ⊆ ⋃i, (uvs i).1, from\n  assume x hx, subset_Union _ ⟨x,hx⟩ (by simpa using (h ⟨x,hx⟩).2.2.1),\nlet ⟨s0, s0_cover⟩ :=\n  hs.elim_finite_subcover _ (λi, (h i).1) us_cover in\nlet u := ⋃(i ∈ s0), (uvs i).1 in\nlet v := ⋂(i ∈ s0), (uvs i).2 in\nhave is_open u, from is_open_bUnion (λi _, (h i).1),\nhave is_open v, from is_open_bInter s0.finite_to_set (λi _, (h i).2.1),\nhave t ⊆ v, from subset_bInter (λi _, (h i).2.2.2.1),\nhave set.prod u v ⊆ n, from assume ⟨x',y'⟩ ⟨hx',hy'⟩,\n  have ∃i ∈ s0, x' ∈ (uvs i).1, by simpa using hx',\n  let ⟨i,is0,hi⟩ := this in\n  (h i).2.2.2.2 ⟨hi, (bInter_subset_of_mem is0 : v ⊆ (uvs i).2) hy'⟩,\n⟨u, v, ‹is_open u›, ‹is_open v›, s0_cover, ‹t ⊆ v›, ‹set.prod u v ⊆ n›⟩\n\n/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist\nopen neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`. -/\nlemma generalized_tube_lemma {s : set α} (hs : is_compact s) {t : set β} (ht : is_compact t)\n  {n : set (α × β)} (hn : is_open n) (hp : set.prod s t ⊆ n) :\n  ∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ 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 (α : Type*) [topological_space α] : Prop :=\n(compact_univ : is_compact (univ : set α))\n\n@[priority 10] -- see Note [lower instance priority]\ninstance subsingleton.compact_space [subsingleton α] : compact_space α :=\n⟨subsingleton_univ.is_compact⟩\n\nlemma compact_univ [h : compact_space α] : is_compact (univ : set α) := h.compact_univ\n\nlemma cluster_point_of_compact [compact_space α] (f : filter α) [ne_bot f] :\n  ∃ x, cluster_pt x f :=\nby simpa using compact_univ (show f ≤ 𝓟 univ, by simp)\n\nlemma compact_space.elim_nhds_subcover {α : Type*} [topological_space α] [compact_space α]\n  (U : α → set α) (hU : ∀ x, U x ∈ 𝓝 x) :\n  ∃ t : finset α, (⋃ x ∈ t, U x) = ⊤ :=\nbegin\n  obtain ⟨t, -, s⟩ := is_compact.elim_nhds_subcover compact_univ U (λ x m, hU x),\n  exact ⟨t, by { rw eq_top_iff, exact s }⟩,\nend\n\ntheorem compact_space_of_finite_subfamily_closed {α : Type u} [topological_space α]\n  (h : Π {ι : Type u} (Z : ι → (set α)), (∀ i, is_closed (Z i)) →\n    (⋂ i, Z i) = ∅ → ∃ (t : finset ι), (⋂ i ∈ t, Z i) = ∅) :\n  compact_space α :=\n{ compact_univ :=\n  begin\n    apply compact_of_finite_subfamily_closed,\n    intros ι Z, specialize h Z,\n    simpa using h\n  end }\n\nlemma is_closed.compact [compact_space α] {s : set α} (h : is_closed s) :\n  is_compact s :=\ncompact_of_is_closed_subset compact_univ h (subset_univ _)\n\n/-- A compact discrete space is finite. -/\nnoncomputable\ndef fintype_of_compact_of_discrete [compact_space α] [discrete_topology α] :\n  fintype α :=\nfintype_of_univ_finite $ finite_of_is_compact_of_discrete _ compact_univ\n\nlemma finite_cover_nhds_interior [compact_space α] {U : α → set α} (hU : ∀ x, U x ∈ 𝓝 x) :\n  ∃ t : finset α, (⋃ x ∈ t, interior (U x)) = univ :=\nlet ⟨t, ht⟩ := compact_univ.elim_finite_subcover (λ x, interior (U x)) (λ x, is_open_interior)\n  (λ x _, mem_Union.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩)\nin ⟨t, univ_subset_iff.1 ht⟩\n\nlemma finite_cover_nhds [compact_space α] {U : α → set α} (hU : ∀ x, U x ∈ 𝓝 x) :\n  ∃ t : finset α, (⋃ x ∈ t, U x) = univ :=\nlet ⟨t, ht⟩ := finite_cover_nhds_interior hU in ⟨t, univ_subset_iff.1 $\n  ht ▸ bUnion_subset_bUnion_right (λ x hx, interior_subset)⟩\n\n/-- If `α` is a compact space, then a locally finite family of sets of `α` can have only finitely\nmany nonempty elements. -/\nlemma locally_finite.finite_nonempty_of_compact {ι : Type*} [compact_space α] {f : ι → set α}\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 `α` is a compact space, then a locally finite family of nonempty sets of `α` can have only\nfinitely many elements, `set.finite` version. -/\nlemma locally_finite.finite_of_compact {ι : Type*} [compact_space α] {f : ι → set α}\n  (hf : locally_finite f) (hne : ∀ i, (f i).nonempty) :\n  finite (univ : set ι) :=\nby simpa only [hne] using hf.finite_nonempty_of_compact\n\n/-- If `α` is a compact space, then a locally finite family of nonempty sets of `α` can have only\nfinitely many elements, `fintype` version. -/\nnoncomputable def locally_finite.fintype_of_compact {ι : Type*} [compact_space α] {f : ι → set α}\n  (hf : locally_finite f) (hne : ∀ i, (f i).nonempty) :\n  fintype ι :=\nfintype_of_univ_finite (hf.finite_of_compact hne)\n\nvariables [topological_space β]\n\nlemma is_compact.image_of_continuous_on {f : α → β} (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 ⊓ 𝓟 s) :=\n    comap_inf_principal_ne_bot_of_image_mem lne (le_principal_iff.1 ls),\n  obtain ⟨a, has, ha⟩ : ∃ a ∈ s, cluster_pt a (l.comap f ⊓ 𝓟 s) := @@hs this inf_le_right,\n  use [f a, mem_image_of_mem f has],\n  have : tendsto f (𝓝 a ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f a) ⊓ 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 : α → β} (hs : is_compact s) (hf : continuous f) :\n  is_compact (f '' s) :=\nhs.image_of_continuous_on hf.continuous_on\n\nlemma compact_range [compact_space α] {f : α → β} (hf : continuous f) :\n  is_compact (range f) :=\nby rw ← image_univ; exact compact_univ.image hf\n\n/-- If X is is_compact then pr₂ : X × Y → Y is a closed map -/\ntheorem is_closed_proj_of_compact\n  {X : Type*} [topological_space X] [compact_space X]\n  {Y : Type*} [topological_space Y]  :\n  is_closed_map (prod.snd : X × Y → Y) :=\nbegin\n  set πX := (prod.fst : X × Y → X),\n  set πY := (prod.snd : X × Y → Y),\n  assume C (hC : is_closed C),\n  rw is_closed_iff_cluster_pt at hC ⊢,\n  assume y (y_closure : cluster_pt y $ 𝓟 (πY '' C)),\n  have : ne_bot (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)),\n  { suffices : ne_bot (map πY (comap πY (𝓝 y) ⊓ 𝓟 C)),\n      by simpa only [map_ne_bot_iff],\n    convert y_closure,\n    calc map πY (comap πY (𝓝 y) ⊓ 𝓟 C) =\n       𝓝 y ⊓ map πY (𝓟 C) : filter.push_pull' _ _ _\n      ... = 𝓝 y ⊓ 𝓟 (πY '' C) : by rw map_principal },\n  resetI,\n  obtain ⟨x, hx⟩ : ∃ x, cluster_pt x (map πX (comap πY (𝓝 y) ⊓ 𝓟 C)),\n    from cluster_point_of_compact _,\n  refine ⟨⟨x, y⟩, _, by simp [πY]⟩,\n  apply hC,\n  rw [cluster_pt, ← filter.map_ne_bot_iff πX],\n  convert hx,\n  calc map πX (𝓝 (x, y) ⊓ 𝓟 C)\n      = map πX (comap πX (𝓝 x) ⊓ comap πY (𝓝 y) ⊓ 𝓟 C) : by rw [nhds_prod_eq, filter.prod]\n  ... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C ⊓ comap πX (𝓝 x)) : by ac_refl\n  ... = map πX (comap πY (𝓝 y) ⊓ 𝓟 C) ⊓ 𝓝 x            : by rw filter.push_pull\n  ... = 𝓝 x ⊓ map πX (comap πY (𝓝 y) ⊓ 𝓟 C)            : by rw inf_comm\nend\n\nlemma embedding.compact_iff_compact_image {f : α → β} (hf : embedding f) :\n  is_compact s ↔ is_compact (f '' s) :=\niff.intro (assume h, h.image hf.continuous) $ assume h, begin\n  rw compact_iff_ultrafilter_le_nhds at ⊢ h,\n  intros u us',\n  have : ↑(u.map f) ≤ 𝓟 (f '' s), begin\n    rw [ultrafilter.coe_map, map_le_iff_le_comap, comap_principal], convert us',\n    exact preimage_image_eq _ hf.inj\n  end,\n  rcases h (u.map f) this with ⟨_, ⟨a, ha, ⟨⟩⟩, _⟩,\n  refine ⟨a, ha, _⟩,\n  rwa [hf.induced, nhds_induced, ←map_le_iff_le_comap]\nend\n\nlemma compact_iff_compact_in_subtype {p : α → Prop} {s : set {a // p a}} :\n  is_compact s ↔ is_compact ((coe : _ → α) '' s) :=\nembedding_subtype_coe.compact_iff_compact_image\n\nlemma compact_iff_compact_univ {s : set α} : is_compact s ↔ is_compact (univ : set s) :=\nby rw [compact_iff_compact_in_subtype, image_univ, subtype.range_coe]; refl\n\nlemma compact_iff_compact_space {s : set α} : is_compact s ↔ compact_space s :=\ncompact_iff_compact_univ.trans ⟨λ h, ⟨h⟩, @compact_space.compact_univ _ _⟩\n\nlemma is_compact.prod {s : set α} {t : set β} (hs : is_compact s) (ht : is_compact t) :\n  is_compact (set.prod s t) :=\nbegin\n  rw compact_iff_ultrafilter_le_nhds at hs ht ⊢,\n  intros f hfs,\n  rw le_principal_iff at hfs,\n  obtain ⟨a : α, sa : a ∈ s, ha : map prod.fst ↑f ≤ 𝓝 a⟩ :=\n    hs (f.map prod.fst) (le_principal_iff.2 $ mem_map.2 $ mem_sets_of_superset hfs (λ x, and.left)),\n  obtain ⟨b : β, tb : b ∈ t, hb : map prod.snd ↑f ≤ 𝓝 b⟩ :=\n    ht (f.map prod.snd) (le_principal_iff.2 $ mem_map.2 $\n      mem_sets_of_superset hfs (λ x, and.right)),\n  rw map_le_iff_le_comap at ha hb,\n  refine ⟨⟨a, b⟩, ⟨sa, tb⟩, _⟩,\n  rw nhds_prod_eq, exact le_inf ha hb\nend\n\nlemma inducing.is_compact_iff {f : α → β} (hf : inducing f) {s : set α} :\n  is_compact (f '' s) ↔ is_compact s :=\nbegin\n  split,\n  { introsI hs F F_ne_bot F_le,\n    obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : cluster_pt (f x) (map f F)⟩ :=\n      hs (calc map f F ≤ map f (𝓟 s) : map_mono F_le\n                  ... = 𝓟 (f '' s) : map_principal),\n    use [x, x_in],\n    suffices : (map f (𝓝 x ⊓ F)).ne_bot, by simpa [filter.map_ne_bot_iff],\n    rwa calc map f (𝓝 x ⊓ F) = map f ((comap f $ 𝓝 $ f x) ⊓ F) : by rw hf.nhds_eq_comap\n                          ... = 𝓝 (f x) ⊓ map f F : filter.push_pull' _ _ _ },\n  { intro hs,\n    exact hs.image hf.continuous }\nend\n\n/-- Finite topological spaces are compact. -/\n@[priority 100] instance fintype.compact_space [fintype α] : compact_space α :=\n{ compact_univ := finite_univ.is_compact }\n\n/-- The product of two compact spaces is compact. -/\ninstance [compact_space α] [compact_space β] : compact_space (α × β) :=\n⟨by { rw ← univ_prod_univ, exact compact_univ.prod compact_univ }⟩\n\n/-- The disjoint union of two compact spaces is compact. -/\ninstance [compact_space α] [compact_space β] : compact_space (α ⊕ β) :=\n⟨begin\n  rw ← range_inl_union_range_inr,\n  exact (compact_range continuous_inl).union (compact_range continuous_inr)\nend⟩\n\n/-- The coproduct of the cocompact filters on two topological spaces is the cocompact filter on\ntheir product. -/\nlemma filter.coprod_cocompact {β : Type*} [topological_space β]:\n  (filter.cocompact α).coprod (filter.cocompact β) = filter.cocompact (α × β) :=\nbegin\n  ext S,\n  simp only [mem_coprod_iff, exists_prop, mem_comap_sets, filter.mem_cocompact],\n  split,\n  { rintro ⟨⟨A, ⟨t, ht, hAt⟩, hAS⟩, B, ⟨t', ht', hBt'⟩, hBS⟩,\n    refine ⟨t.prod t', ht.prod ht', _⟩,\n    refine subset.trans _ (union_subset hAS hBS),\n    rw compl_subset_comm at ⊢ 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 ⟨t, ht, htS⟩,\n    refine ⟨⟨(prod.fst '' t)ᶜ, _, _⟩, ⟨(prod.snd '' t)ᶜ, _, _⟩⟩,\n    { exact ⟨prod.fst '' t, ht.image continuous_fst, subset.rfl⟩ },\n    { rw preimage_compl,\n      rw compl_subset_comm at ⊢ htS,\n      exact subset.trans htS (subset_preimage_image prod.fst _) },\n    { exact ⟨prod.snd '' t, ht.image continuous_snd, subset.rfl⟩ },\n    { rw preimage_compl,\n      rw compl_subset_comm at ⊢ htS,\n      exact subset.trans htS (subset_preimage_image prod.snd _) } }\nend\n\nsection tychonoff\nvariables {ι : Type*} {π : ι → Type*} [∀ i, topological_space (π i)]\n\n/-- Tychonoff's theorem -/\nlemma compact_pi_infinite {s : Π i, set (π i)} :\n  (∀ i, is_compact (s i)) → is_compact {x : Π i, π i | ∀ i, x i ∈ s i} :=\nbegin\n  simp only [compact_iff_ultrafilter_le_nhds, nhds_pi, exists_prop, mem_set_of_eq, le_infi_iff,\n    le_principal_iff],\n  intros h f hfs,\n  have : ∀i:ι, ∃a, a∈s i ∧ tendsto (λx:Πi:ι, π i, x i) f (𝓝 a),\n  { refine λ i, h i (f.map _) (mem_map.2 _),\n    exact mem_sets_of_superset hfs (λ x hx, hx i) },\n  choose a ha,\n  exact  ⟨a, assume i, (ha i).left, assume i, (ha i).right.le_comap⟩\nend\n\n/-- A version of Tychonoff's theorem that uses `set.pi`. -/\nlemma compact_univ_pi {s : Π i, set (π i)} (h : ∀ i, is_compact (s i)) :\n  is_compact (pi univ s) :=\nby { convert compact_pi_infinite h, simp only [pi, forall_prop_of_true, mem_univ] }\n\ninstance pi.compact_space [∀ i, compact_space (π i)] : compact_space (Πi, π i) :=\n⟨by { rw [← pi_univ univ], exact compact_univ_pi (λ i, compact_univ) }⟩\n\n/-- Product of compact sets is compact -/\nlemma filter.Coprod_cocompact {δ : Type*} {κ : δ → Type*} [Π d, topological_space (κ d)] :\n  filter.Coprod (λ d, filter.cocompact (κ d)) = filter.cocompact (Π d, κ d) :=\nbegin\n  ext S,\n  simp only [mem_coprod_iff, exists_prop, mem_comap_sets, filter.mem_cocompact],\n  split,\n  { intros h,\n    rw filter.mem_Coprod_iff at h,\n    choose t ht1 ht2 using h,\n    choose t1 ht11 ht12 using λ d, filter.mem_cocompact.mp (ht1 d),\n    refine ⟨set.pi set.univ t1, _, _⟩,\n    { convert compact_pi_infinite ht11,\n      ext,\n      simp },\n    { refine subset.trans _ (set.Union_subset ht2),\n      intros x,\n      simp only [mem_Union, mem_univ_pi, exists_imp_distrib, mem_compl_eq, not_forall],\n      intros d h,\n      exact ⟨d, ht12 d h⟩ } },\n  { rintros ⟨t, h1, h2⟩,\n    rw filter.mem_Coprod_iff,\n    intros d,\n    refine ⟨((λ (k : Π (d : δ), κ d), k d) '' t)ᶜ, _, _⟩,\n    { rw filter.mem_cocompact,\n      refine ⟨(λ (k : Π (d : δ), κ d), k d) '' t, _, set.subset.refl _⟩,\n      exact is_compact.image h1 (continuous_pi_iff.mp (continuous_id) d) },\n    refine subset.trans _ h2,\n    intros x hx,\n    simp only [not_exists, mem_image, mem_preimage, mem_compl_eq] at hx,\n    simpa using mt (hx x) },\nend\n\nend tychonoff\n\ninstance quot.compact_space {r : α → α → Prop} [compact_space α] :\n  compact_space (quot r) :=\n⟨by { rw ← range_quot_mk, exact compact_range continuous_quot_mk }⟩\n\ninstance quotient.compact_space {s : setoid α} [compact_space α] :\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) × X → Y` to be continuous for all `Y` when `C(X, Y)` is given the\ncompact-open topology. -/\nclass locally_compact_space (α : Type*) [topological_space α] : Prop :=\n(local_compact_nhds : ∀ (x : α) (n ∈ 𝓝 x), ∃ s ∈ 𝓝 x, s ⊆ n ∧ is_compact s)\n\nlemma compact_basis_nhds [locally_compact_space α] (x : α) :\n  (𝓝 x).has_basis (λ s, s ∈ 𝓝 x ∧ is_compact s) (λ s, s) :=\nhas_basis_self.2 $ by simpa only [and_comm] using locally_compact_space.local_compact_nhds x\n\nlemma locally_compact_space_of_has_basis {ι : α → Type*} {p : Π x, ι x → Prop}\n  {s : Π x, ι x → set α} (h : ∀ x, (𝓝 x).has_basis (p x) (s x))\n  (hc : ∀ x i, p x i → is_compact (s x i)) :\n  locally_compact_space α :=\n⟨λ x t ht, let ⟨i, hp, ht⟩ := (h x).mem_iff.1 ht in ⟨s x i, (h x).mem_of_mem hp, ht, hc x i hp⟩⟩\n\ninstance locally_compact_space.prod (α : Type*) (β : Type*) [topological_space α]\n  [topological_space β] [locally_compact_space α] [locally_compact_space β] :\n  locally_compact_space (α × β) :=\nhave _ := λ x : α × β, (compact_basis_nhds x.1).prod_nhds' (compact_basis_nhds x.2),\nlocally_compact_space_of_has_basis this $ λ x s ⟨⟨_, h₁⟩, _, h₂⟩, h₁.prod h₂\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 α] {x : α} {U : set α}\n  (hU : is_open U) (hx : x ∈ U) : ∃ (K : set α), is_compact K ∧ x ∈ interior K ∧ K ⊆ U :=\nbegin\n  rcases locally_compact_space.local_compact_nhds x U (mem_nhds_sets hU hx) with ⟨K, h1K, h2K, h3K⟩,\n  exact ⟨K, h3K, mem_interior_iff_mem_nhds.2 h1K, h2K⟩,\nend\n\n/-- In a locally compact space every point has a compact neighborhood. -/\nlemma exists_compact_mem_nhds [locally_compact_space α] (x : α) :\n  ∃ K, is_compact K ∧ K ∈ 𝓝 x :=\nlet ⟨K, hKc, hx, H⟩ := exists_compact_subset is_open_univ (mem_univ x)\nin ⟨K, hKc, mem_interior_iff_mem_nhds.1 hx⟩\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 α] {K : set α} (hK : is_compact K) :\n  ∃ K', is_compact K' ∧ K ⊆ interior K' :=\nbegin\n  choose U hUc hxU using λ x : K, exists_compact_mem_nhds (x : α),\n  have : K ⊆ ⋃ x, interior (U x),\n    from λ x hx, mem_Union.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 (hxU _)⟩,\n  rcases hK.elim_finite_subcover _ _ this with ⟨t, ht⟩,\n  { refine ⟨_, t.compact_bUnion (λ x _, hUc x), λ x hx, _⟩,\n    rcases mem_bUnion_iff.1 (ht hx) with ⟨y, hyt, hy⟩,\n    exact interior_mono (subset_bUnion_of_mem hyt) hy },\n  { exact λ _, is_open_interior }\nend\n\nlemma ultrafilter.le_nhds_Lim [compact_space α] (F : ultrafilter α) :\n  ↑F ≤ 𝓝 (@Lim _ _ (F : filter α).nonempty_of_ne_bot F) :=\nbegin\n  rcases compact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩,\n  exact le_nhds_Lim ⟨x,h⟩,\nend\n\ntheorem is_closed.exists_minimal_nonempty_closed_subset [compact_space α]\n  {S : set α} (hS : is_closed S) (hne : S.nonempty) :\n  ∃ (V : set α),\n    V ⊆ S ∧ V.nonempty ∧ is_closed V ∧\n      (∀ (V' : set α), V' ⊆ V → V'.nonempty → is_closed V' → V' = V) :=\nbegin\n  let opens := {U : set α | Sᶜ ⊆ U ∧ is_open U ∧ Uᶜ.nonempty},\n  obtain ⟨U, ⟨Uc, Uo, Ucne⟩, h⟩ := zorn.zorn_subset opens (λ c hc hz, begin\n    by_cases hcne : c.nonempty,\n    { obtain ⟨U₀, hU₀⟩ := hcne,\n      haveI : nonempty {U // U ∈ c} := ⟨⟨U₀, hU₀⟩⟩,\n      obtain ⟨U₀compl, U₀opn, U₀ne⟩ := hc hU₀,\n      use ⋃₀ c,\n      refine ⟨⟨_, _, _⟩, λ U hU a ha, ⟨U, hU, ha⟩⟩,\n      { exact λ a ha, ⟨U₀, hU₀, U₀compl ha⟩ },\n      { exact is_open_sUnion (λ _ h, (hc h).2.1) },\n      { convert_to (⋂(U : {U // U ∈ c}), U.1ᶜ).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 ⟨U, hU⟩ ⟨U', hU'⟩,\n          obtain ⟨V, hVc, hVU, hVU'⟩ := zorn.chain.directed_on hz U hU U' hU',\n          exact ⟨⟨V, hVc⟩, set.compl_subset_compl.mpr hVU, set.compl_subset_compl.mpr hVU'⟩, },\n        { exact λ U, (hc U.2).2.2, },\n        { exact λ U, is_closed.compact (is_closed_compl_iff.mpr (hc U.2).2.1), },\n        { exact λ U, (is_closed_compl_iff.mpr (hc U.2).2.1), } } },\n    { use Sᶜ,\n      refine ⟨⟨set.subset.refl _, is_open_compl_iff.mpr hS, _⟩, λ U Uc, (hcne ⟨U, Uc⟩).elim⟩,\n      rw compl_compl,\n      exact hne, }\n  end),\n  refine ⟨Uᶜ, set.compl_subset_comm.mp Uc, Ucne, is_closed_compl_iff.mpr Uo, _⟩,\n  intros V' V'sub V'ne V'cls,\n  have : V'ᶜ = U,\n  { refine h V'ᶜ ⟨_, is_open_compl_iff.mpr V'cls, _⟩ (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 [←this, compl_compl],\nend\n\n/-- A σ-compact space is a space that is the union of a countable collection of compact subspaces.\n  Note that a locally compact separable T₂ space need not be σ-compact.\n  The sequence can be extracted using `topological_space.compact_covering`. -/\nclass sigma_compact_space (α : Type*) [topological_space α] : Prop :=\n(exists_compact_covering : ∃ K : ℕ → set α, (∀ n, is_compact (K n)) ∧ (⋃ n, K n) = univ)\n\n@[priority 200] -- see Note [lower instance priority]\ninstance compact_space.sigma_compact [compact_space α] : sigma_compact_space α :=\n⟨⟨λ _, univ, λ _, compact_univ, Union_const _⟩⟩\n\nlemma sigma_compact_space.of_countable (S : set (set α)) (Hc : countable S)\n  (Hcomp : ∀ s ∈ S, is_compact s) (HU : ⋃₀ S = univ) : sigma_compact_space α :=\n⟨(exists_seq_cover_iff_countable ⟨_, compact_empty⟩).2 ⟨S, Hc, Hcomp, HU⟩⟩\n\n@[priority 100] -- see Note [lower instance priority]\ninstance sigma_compact_space_of_locally_compact_second_countable [locally_compact_space α]\n  [second_countable_topology α] : sigma_compact_space α :=\nbegin\n  choose K hKc hxK using λ x : α, exists_compact_mem_nhds x,\n  rcases countable_cover_nhds hxK with ⟨s, hsc, hsU⟩,\n  refine sigma_compact_space.of_countable _ (hsc.image K) (ball_image_iff.2 $ λ x _, hKc x) _,\n  rwa sUnion_image\nend\n\nvariables (α) [sigma_compact_space α]\nopen sigma_compact_space\n\n/-- A choice of compact covering for a σ-compact space, chosen to be monotone. -/\ndef compact_covering : ℕ → set α :=\naccumulate exists_compact_covering.some\n\nlemma is_compact_compact_covering (n : ℕ) : is_compact (compact_covering α n) :=\ncompact_accumulate (classical.some_spec sigma_compact_space.exists_compact_covering).1 n\n\nlemma Union_compact_covering : (⋃ n, compact_covering α 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 ⦃m n : ℕ⦄ (h : m ≤ n) :\n  compact_covering α m ⊆ compact_covering α n :=\nmonotone_accumulate h\n\nvariable {α}\n\n/-- If `α` is a `σ`-compact space, then a locally finite family of nonempty sets of `α` can have\nonly countably many elements, `set.countable` version. -/\nlemma locally_finite.countable_of_sigma_compact {ι : Type*} {f : ι → set α} (hf : locally_finite f)\n  (hne : ∀ i, (f i).nonempty) :\n  countable (univ : set ι) :=\nbegin\n  have := λ n, hf.finite_nonempty_inter_compact (is_compact_compact_covering α n),\n  refine (countable_Union (λ n, (this n).countable)).mono (λ i hi, _),\n  rcases hne i with ⟨x, hx⟩,\n  rcases Union_eq_univ_iff.1 (Union_compact_covering α) x with ⟨n, hn⟩,\n  exact mem_Union.2 ⟨n, x, hx, hn⟩\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 ∈ s`, cover the whole space. -/\nlemma countable_cover_nhds_of_sigma_compact {f : α → set α}\n  (hf : ∀ x, f x ∈ 𝓝 x) : ∃ s : set α, countable s ∧ (⋃ x ∈ s, f x) = univ :=\nbegin\n  choose t ht hsub using λ n, (is_compact_compact_covering α n).elim_nhds_subcover f (λ x _, hf x),\n  refine ⟨⋃ n, (t n : set α), countable_Union $ λ n, (t n).countable_to_set, _⟩,\n  simp only [eq_univ_iff_forall, mem_Union, exists_prop],\n  intro x,\n  rcases Union_eq_univ_iff.1 (Union_compact_covering α) x with ⟨n, hn⟩,\n  rcases mem_bUnion_iff.1 (hsub n hn) with ⟨c, hct, hfx⟩,\n  exact ⟨c, ⟨n, hct⟩, hfx⟩\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 ⊆ interior (K (n + 1))` and\n`(⋃ 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 : ℕ → set X)\n(is_compact' : ∀ n, is_compact (to_fun n))\n(subset_interior_succ' : ∀ n, to_fun n ⊆ interior (to_fun (n + 1)))\n(Union_eq' : (⋃ n, to_fun n) = univ)\n\nnamespace compact_exhaustion\n\ninstance : has_coe_to_fun (compact_exhaustion α) := ⟨_, to_fun⟩\n\nvariables {α} (K : compact_exhaustion α)\n\nprotected lemma is_compact (n : ℕ) : is_compact (K n) := K.is_compact' n\n\nlemma subset_interior_succ (n : ℕ) : K n ⊆ interior (K (n + 1)) :=\nK.subset_interior_succ' n\n\nlemma subset_succ (n : ℕ) : K n ⊆ K (n + 1) :=\nsubset.trans (K.subset_interior_succ n) interior_subset\n\n@[mono] protected lemma subset ⦃m n : ℕ⦄ (h : m ≤ n) : K m ⊆ K n :=\nshow K m ≤ K n, from monotone_of_monotone_nat K.subset_succ h\n\nlemma subset_interior ⦃m n : ℕ⦄ (h : m < n) : K m ⊆ interior (K n) :=\nsubset.trans (K.subset_interior_succ m) $ interior_mono $ K.subset h\n\nlemma Union_eq : (⋃ n, K n) = univ := K.Union_eq'\n\nlemma exists_mem (x : α) : ∃ n, x ∈ K n := Union_eq_univ_iff.1 K.Union_eq x\n\n/-- The minimal `n` such that `x ∈ K n`. -/\nprotected noncomputable def find (x : α) : ℕ := nat.find (K.exists_mem x)\n\nlemma mem_find (x : α) : x ∈ K (K.find x) := nat.find_spec (K.exists_mem x)\n\nlemma mem_iff_find_le {x : α} {n : ℕ} : x ∈ K n ↔ K.find x ≤ n :=\n⟨λ h, nat.find_min' (K.exists_mem x) h, λ h, K.subset h $ K.mem_find x⟩\n\n/-- Prepend the empty set to a compact exhaustion `K n`. -/\ndef shiftr : compact_exhaustion α :=\n{ to_fun := λ n, nat.cases_on n ∅ K,\n  is_compact' := λ n, nat.cases_on n compact_empty K.is_compact,\n  subset_interior_succ' := λ n, nat.cases_on n (empty_subset _) K.subset_interior_succ,\n  Union_eq' := Union_eq_univ_iff.2 $ λ x, ⟨K.find x + 1, K.mem_find x⟩ }\n\n@[simp] lemma find_shiftr (x : α) : K.shiftr.find x = K.find x + 1 :=\nnat.find_comp_succ _ _ (not_mem_empty _)\n\nlemma mem_diff_shiftr_find (x : α) : x ∈ K.shiftr (K.find x + 1) \\ K.shiftr (K.find x) :=\n⟨K.mem_find _, mt K.shiftr.mem_iff_find_le.1 $\n  by simp only [find_shiftr, not_le, nat.lt_succ_self]⟩\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 : ℕ → {s : set X // is_compact s} :=\n    λ n, nat.rec_on n ⟨∅, compact_empty⟩\n      (λ n s, ⟨(exists_compact_superset s.2).some ∪ compact_covering X n,\n        (exists_compact_superset s.2).some_spec.1.union (is_compact_compact_covering _ _)⟩),\n  refine ⟨⟨λ n, K n, λ n, (K n).2, λ n, _, _⟩⟩,\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 ▸ _),\n    exact Union_subset_Union2 (λ n, ⟨n + 1, subset_union_right _ _⟩) }\nend\n\nnoncomputable instance [locally_compact_space α] [sigma_compact_space α] :\n  inhabited (compact_exhaustion α) :=\n⟨compact_exhaustion.choice α⟩\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 α) : Prop :=\nis_open s ∧ is_closed s\n\ntheorem is_clopen_union {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∪ t) :=\n⟨is_open_union hs.1 ht.1, is_closed_union hs.2 ht.2⟩\n\ntheorem is_clopen_inter {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ t) :=\n⟨is_open_inter hs.1 ht.1, is_closed_inter hs.2 ht.2⟩\n\n@[simp] theorem is_clopen_empty : is_clopen (∅ : set α) :=\n⟨is_open_empty, is_closed_empty⟩\n\n@[simp] theorem is_clopen_univ : is_clopen (univ : set α) :=\n⟨is_open_univ, is_closed_univ⟩\n\ntheorem is_clopen_compl {s : set α} (hs : is_clopen s) : is_clopen sᶜ :=\n⟨hs.2.is_open_compl, is_closed_compl_iff.2 hs.1⟩\n\n@[simp] theorem is_clopen_compl_iff {s : set α} : is_clopen sᶜ ↔ is_clopen s :=\n⟨λ h, compl_compl s ▸ is_clopen_compl h, is_clopen_compl⟩\n\ntheorem is_clopen_diff {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s \\ t) :=\nis_clopen_inter hs (is_clopen_compl ht)\n\nlemma is_clopen_Inter {β : Type*} [fintype β] {s : β → set α}\n  (h : ∀ i, is_clopen (s i)) : is_clopen (⋂ i, s i) :=\n⟨(is_open_Inter (forall_and_distrib.1 h).1), (is_closed_Inter (forall_and_distrib.1 h).2)⟩\n\nlemma is_clopen_bInter {β : Type*} {s : finset β} {f : β → set α} (h : ∀i∈s, is_clopen (f i)) :\n  is_clopen (⋂i∈s, f i) :=\n⟨ is_open_bInter ⟨finset_coe.fintype s⟩ (λ i hi, (h i hi).1),\n  by {show is_closed (⋂ (i : β) (H : i ∈ (↑s : set β)), f i), rw bInter_eq_Inter,\n    apply is_closed_Inter, rintro ⟨i, hi⟩, exact (h i hi).2}⟩\n\nlemma continuous_on.preimage_clopen_of_clopen {β: Type*} [topological_space β]\n  {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_clopen s)\n  (ht : is_clopen t) : is_clopen (s ∩ f⁻¹' t) :=\n⟨continuous_on.preimage_open_of_open hf hs.1 ht.1,\n  continuous_on.preimage_closed_of_closed hf hs.2 ht.2⟩\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 α} (h : is_clopen Z)\n  (cover : Z ⊆ a ∪ b) (ha : is_open a) (hb : is_open b) (hab : a ∩ b = ∅) : is_clopen (Z ∩ a) :=\nbegin\n  refine ⟨is_open_inter h.1 ha, _⟩,\n  have : is_closed (Z ∩ bᶜ) := 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 ⟨hx₁, hx₂⟩,\n    exact ⟨hx₁, by simpa [not_mem_of_mem_compl hx₂] using cover hx₁⟩ }\nend\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 α) : Prop :=\n∀ (u v : set α), is_open u → is_open v →\n  (s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ 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 α) : Prop :=\ns.nonempty ∧ is_preirreducible s\n\nlemma is_irreducible.nonempty {s : set α} (h : is_irreducible s) :\n  s.nonempty := h.1\n\nlemma is_irreducible.is_preirreducible {s : set α} (h : is_irreducible s) :\n  is_preirreducible s := h.2\n\ntheorem is_preirreducible_empty : is_preirreducible (∅ : set α) :=\nλ _ _ _ _ _ ⟨x, h1, h2⟩, h1.elim\n\ntheorem is_irreducible_singleton {x} : is_irreducible ({x} : set α) :=\n⟨singleton_nonempty x,\n λ u v _ _ ⟨y, h1, h2⟩ ⟨z, h3, h4⟩, by rw mem_singleton_iff at h1 h3;\n substs y z; exact ⟨x, rfl, h2, h4⟩⟩\n\ntheorem is_preirreducible.closure {s : set α} (H : is_preirreducible s) :\n  is_preirreducible (closure s) :=\nλ u v hu hv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,\nlet ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in\nlet ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in\nlet ⟨r, hrs, hruv⟩ := H u v hu hv ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in\n⟨r, subset_closure hrs, hruv⟩\n\nlemma is_irreducible.closure {s : set α} (h : is_irreducible s) :\n  is_irreducible (closure s) :=\n⟨h.nonempty.closure, h.is_preirreducible.closure⟩\n\ntheorem exists_preirreducible (s : set α) (H : is_preirreducible s) :\n  ∃ t : set α, is_preirreducible t ∧ s ⊆ t ∧ ∀ u, is_preirreducible u → t ⊆ u → u = t :=\nlet ⟨m, hm, hsm, hmm⟩ := zorn.zorn_subset_nonempty {t : set α | is_preirreducible t}\n  (λ c hc hcc hcn, let ⟨t, htc⟩ := hcn in\n    ⟨⋃₀ c, λ u v hu hv ⟨y, hy, hyu⟩ ⟨z, hz, hzv⟩,\n      let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy,\n          ⟨q, hqc, hzq⟩ := mem_sUnion.1 hz in\n      or.cases_on (zorn.chain.total hcc hpc hqc)\n        (assume hpq : p ⊆ q, let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv\n            ⟨y, hpq hyp, hyu⟩ ⟨z, hzq, hzv⟩ in\n          ⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩)\n        (assume hqp : q ⊆ p, let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv\n            ⟨y, hyp, hyu⟩ ⟨z, hqp hzq, hzv⟩ in\n          ⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩),\n    λ x hxc, subset_sUnion_of_mem hxc⟩) s H in\n⟨m, hm, hsm, λ u hu hmu, hmm _ hu hmu⟩\n\n/-- A maximal irreducible set that contains a given point. -/\ndef irreducible_component (x : α) : set α :=\nclassical.some (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)\n\nlemma irreducible_component_property (x : α) :\n  is_preirreducible (irreducible_component x) ∧ {x} ⊆ (irreducible_component x) ∧\n  ∀ u, is_preirreducible u → (irreducible_component x) ⊆ u → u = (irreducible_component x) :=\nclassical.some_spec (exists_preirreducible {x} is_irreducible_singleton.is_preirreducible)\n\ntheorem mem_irreducible_component {x : α} : x ∈ irreducible_component x :=\nsingleton_subset_iff.1 (irreducible_component_property x).2.1\n\ntheorem is_irreducible_irreducible_component {x : α} : is_irreducible (irreducible_component x) :=\n⟨⟨x, mem_irreducible_component⟩, (irreducible_component_property x).1⟩\n\ntheorem eq_irreducible_component {x : α} :\n  ∀ {s : set α}, is_preirreducible s → irreducible_component x ⊆ s → s = irreducible_component x :=\n(irreducible_component_property x).2.2\n\ntheorem is_closed_irreducible_component {x : α} :\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 (α : Type u) [topological_space α] : Prop :=\n(is_preirreducible_univ [] : is_preirreducible (univ : set α))\n\n/-- An irreducible space is one that is nonempty\nand where there is no non-trivial pair of disjoint opens. -/\nclass irreducible_space (α : Type u) [topological_space α] extends preirreducible_space α : Prop :=\n(to_nonempty [] : nonempty α)\n\n-- see Note [lower instance priority]\nattribute [instance, priority 50] irreducible_space.to_nonempty\n\ntheorem nonempty_preirreducible_inter [preirreducible_space α] {s t : set α} :\n  is_open s → is_open t → s.nonempty → t.nonempty → (s ∩ t).nonempty :=\nby simpa only [univ_inter, univ_subset_iff] using\n  @preirreducible_space.is_preirreducible_univ α _ _ s t\n\ntheorem is_preirreducible.image [topological_space β] {s : set α} (H : is_preirreducible s)\n  (f : α → β) (hf : continuous_on f s) : is_preirreducible (f '' s) :=\nbegin\n  rintros u v hu hv ⟨_, ⟨⟨x, hx, rfl⟩, hxu⟩⟩ ⟨_, ⟨⟨y, hy, rfl⟩, hyv⟩⟩,\n  rw ← mem_preimage at hxu hyv,\n  rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,\n  rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,\n  have := H u' v' hu' hv',\n  rw [inter_comm s u', ← u'_eq] at this,\n  rw [inter_comm s v', ← v'_eq] at this,\n  rcases this ⟨x, hxu, hx⟩ ⟨y, hyv, hy⟩ with ⟨z, hzs, hzu', hzv'⟩,\n  refine ⟨f z, mem_image_of_mem f hzs, _, _⟩,\n  all_goals\n  { rw ← mem_preimage,\n    apply mem_of_mem_inter_left,\n    show z ∈ _ ∩ s,\n    simp [*] }\nend\n\ntheorem is_irreducible.image [topological_space β] {s : set α} (H : is_irreducible s)\n  (f : α → β) (hf : continuous_on f s) : is_irreducible (f '' s) :=\n⟨nonempty_image_iff.mpr H.nonempty, H.is_preirreducible.image f hf⟩\n\nlemma subtype.preirreducible_space {s : set α} (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 ⟨u, hu, rfl⟩,\n    rcases hv with ⟨v, hv, rfl⟩,\n    rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,\n    rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,\n    rcases h u v hu hv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,\n    exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩\n  end }\n\nlemma subtype.irreducible_space {s : set α} (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 α} :\n  is_irreducible s ↔\n  ∀ (U : finset (set α)) (hU : ∀ u ∈ U, is_open u) (H : ∀ u ∈ U, (s ∩ u).nonempty),\n  (s ∩ ⋂₀ ↑U).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 ∅ _ _; 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 α} :\n  is_preirreducible s ↔\n  ∀ (z₁ z₂ : set α), is_closed z₁ → is_closed z₂ → s ⊆ z₁ ∪ z₂ → s ⊆ z₁ ∨ s ⊆ z₂ :=\nbegin\n  split,\n  all_goals\n  { intros h t₁ t₂ ht₁ ht₂,\n    specialize h t₁ᶜ t₂ᶜ,\n    simp only [is_open_compl_iff, is_closed_compl_iff] at h,\n    specialize h ht₁ ht₂ },\n  { contrapose!, simp only [not_subset],\n    rintro ⟨⟨x, hx, hx'⟩, ⟨y, hy, hy'⟩⟩,\n    rcases h ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩ with ⟨z, hz, hz'⟩,\n    rw ← compl_union at hz',\n    exact ⟨z, hz, hz'⟩ },\n  { rintro ⟨x, hx, hx'⟩ ⟨y, hy, hy'⟩,\n    rw ← 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 ⟨hz, hz'⟩ },\n    { split; intro H; refine H _ ‹_›; 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 α} :\n  is_irreducible s ↔\n  ∀ (Z : finset (set α)) (hZ : ∀ z ∈ Z, is_closed z) (H : s ⊆ ⋃₀ ↑Z),\n  ∃ z ∈ Z, s ⊆ 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 ⟨x, hx⟩,\n      exfalso, tauto },\n    { intros z Z hz IH hZ H,\n      cases h.2 z (⋃₀ ↑Z) _ _ _\n        with h' h',\n      { exact ⟨z, finset.mem_insert_self _ _, h'⟩ },\n      { rcases IH _ h' with ⟨z', hz', hsz'⟩,\n        { exact ⟨z', finset.mem_insert_of_mem hz', hsz'⟩ },\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 ∅ _ _,\n      { intro z, simp },\n      { simpa [set.nonempty] using hs } },\n    intros z₁ z₂ hz₁ hz₂ H,\n    have := h {z₁, z₂} _ _,\n    simp only [exists_prop, finset.mem_insert, finset.mem_singleton] at this,\n    { rcases this with ⟨z, rfl|rfl, hz⟩; tauto },\n    { intro t,\n      rw [finset.mem_insert, finset.mem_singleton],\n      rintro (rfl|rfl); assumption },\n    { simpa using H } }\nend\n\nend preirreducible\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/subset_properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7675218719905675}}
{"text": "open Nat\n\n\n/-\nThe function `skip n` function maps `Nat` to `Nat` skipping the natural number `n`, \nwith numbers less than `n` mapped to themselves and those above mapped to the next number. \nThe image is the complement of `n` among natural numbers. \n\nWe need various properties of `skip`, so we define first a function with associated identities,\nand project to the value and the desired properties. The structure `ProvedSkip` consists of the\nresult of `skip` and the associated identities.\n-/\nstructure ProvedSkip(n m: Nat) where\n  result : Nat\n  lt : m < n → result = m\n  ge : n ≤ m → result = m + 1\n\ndef provedSkip (n m : Nat) : ProvedSkip n m := \n  if c : m < n then\n    ⟨m, fun _ => rfl, fun hyp => False.elim (Nat.lt_irrefl m (Nat.lt_of_lt_of_le c hyp))⟩\n  else\n    ⟨m + 1, fun hyp => absurd hyp c, fun _ => rfl⟩\n\n-- the `skip` function\ndef skip: Nat → Nat → Nat \n  | n, m => (provedSkip n m).result\n\n-- equations for `skip` below and above the skipped value\n\ntheorem skip_below_eq(n m : Nat) : m < n → (skip n m = m)\n  | hyp => (provedSkip n m).lt hyp \n\ntheorem skip_above_eq(n m : Nat) : n ≤ m → (skip n m = m + 1)\n  | hyp => (provedSkip n m).ge hyp\n\ntheorem skip_not_below_eq(n m : Nat) : Not (m < n) → (skip n m = m + 1) \n  | hyp =>\n    let lem : n ≤ m :=\n      match Nat.lt_or_ge m n with\n      | Or.inl lt => absurd lt hyp\n      | Or.inr ge => ge \n    skip_above_eq n m lem\n\n/- We prove that skip has an inverse for points different from the point skipped.\nWe need some helpers. As usual, we have a proved version of the function first.\n-/\nstructure NatSucc (n: Nat) where\n  pred: Nat\n  eqn : n = succ (pred)\n\ndef posSucc : (n : Nat) → Not (zero = n) → NatSucc n \n  | zero, w => absurd rfl w\n  | l + 1, _ => ⟨l, rfl⟩\n\nstructure SkipProvedInv(n m : Nat) where\n  k : Nat\n  eqn : skip n k = m\n\ndef provedSkipInverse : (n : Nat) → (m : Nat) → (m ≠ n) →  SkipProvedInv n m :=\n  fun n m eqn =>\n  if m_lt_n : m < n then\n    ⟨m, skip_below_eq n m m_lt_n⟩\n  else \n    have n_lt_m : n < m := \n        match Nat.lt_or_ge m n with\n        | Or.inl p => absurd p m_lt_n\n        | Or.inr p => \n          match Nat.eq_or_lt_of_le p with\n          | Or.inl q => absurd (Eq.symm q) eqn\n          | Or.inr q => q\n    have notZero : Not (zero = m) := by\n        intro hyp\n        let nLt0 : n < zero := by\n          rw [hyp]\n          exact n_lt_m\n        let n_lt_n : n < n :=\n          Nat.lt_of_lt_of_le nLt0 (Nat.zero_le _)\n        exact Nat.lt_irrefl n n_lt_n\n    let ⟨p, seq⟩ := posSucc m notZero\n    have n_le_p : n ≤ p := \n      Nat.le_of_succ_le_succ (by\n        rw [← seq]\n        exact n_lt_m)\n    have imeq : skip n p = m := by\n      rw [seq]\n      exact (skip_above_eq n p n_le_p)\n    ⟨p, imeq⟩\n\ndef skipInverse (n m : Nat) : (m ≠ n) → Nat := \n        fun eqn =>  (provedSkipInverse n m eqn).k\n\ntheorem skip_inverse_eq(n m : Nat)(eqn : m ≠ n): skip n (skipInverse n m eqn) = m  := \n        (provedSkipInverse n m eqn).eqn\n\n-- Various bounds on the `skip` function.\ntheorem skip_lt: (k j: Nat) →  skip k j < j + 2 :=\n    fun k j =>\n      if c : j < k then\n        let eqn := skip_below_eq k j c \n        by \n          rw [eqn]\n          apply Nat.le_step\n          apply Nat.le_refl\n      else \n        let eqn := skip_not_below_eq k j c\n        by \n          rw [eqn]\n          apply Nat.le_refl\n\ntheorem skip_ge :(k j: Nat) →  j ≤ skip k j  :=\n    fun k j =>\n      if c : j < k then\n        let eqn := skip_below_eq k j c  \n          by \n            rw [eqn]\n            apply Nat.le_refl\n      else \n        let eqn := skip_not_below_eq k j c\n        by \n          rw [eqn]\n          apply Nat.le_step\n          apply Nat.le_refl\n\ntheorem skip_gt_or_arg_below :(k j: Nat) →  Or (j + 1 ≤ skip k j) (j <  k)  :=\n    fun k j =>\n      if c : j < k then Or.inr c\n      else\n          let eqn := skip_not_below_eq k j c\n          Or.inl (by \n                    rw [eqn]\n                    apply Nat.le_refl)\n\ntheorem skip_le_succ {n k j : Nat} : j < n → skip k j < n + 1 := \n   by\n    intro hyp \n    apply Nat.le_trans (skip_lt k j)\n    apply Nat.succ_lt_succ\n    exact hyp\n\ntheorem skip_preimage_lt {i j k n : Nat}: (k < n + 1) → (j < n + 1) → \n                                skip k i = j → i < n :=\n          fun kw jw eqn =>\n            match skip_gt_or_arg_below k i with\n              | Or.inl ineq =>\n                by \n                  have lem1 : i <  j :=\n                  by\n                    rw [← eqn]\n                    exact ineq                \n                  apply Nat.lt_of_lt_of_le lem1\n                  apply Nat.le_of_succ_le_succ\n                  apply jw\n              | Or.inr ineqn => by\n                  apply Nat.lt_of_lt_of_le ineqn \n                  apply Nat.le_of_succ_le_succ\n                  apply kw\n\n-- Injectivity and image of the skip function.\ntheorem skip_injective: (n: Nat) → (j1 : Nat) → (j2 : Nat) → \n                              (skip n j1 = skip n j2) → j1 = j2 :=\n      fun n j1 j2 hyp =>\n        match Nat.lt_or_ge j1 n with\n        | Or.inl p1 => \n          let eq1 : skip n j1 = j1 := skip_below_eq n j1 p1\n          match Nat.lt_or_ge j2 n with\n          | Or.inl p2 => \n            let eq2 : skip n j2 = j2 := skip_below_eq n j2 p2\n            by\n              rw [← eq1]\n              rw [← eq2]\n              exact hyp\n              done\n          | Or.inr p2 => \n            let ineq1 : j1 < j2 := Nat.lt_of_lt_of_le p1 p2\n            let ineq2 : j1 < skip n j2 := Nat.lt_of_lt_of_le ineq1 (skip_ge n j2)\n            let ineq3 : j1 < skip n j1 := Nat.lt_of_lt_of_le ineq2 (Nat.le_of_eq (Eq.symm hyp))\n            let ineq4 : j1 < j1 := Nat.lt_of_lt_of_le ineq3 (Nat.le_of_eq eq1)\n            False.elim (Nat.lt_irrefl j1 ineq4)\n        | Or.inr p1 => \n          let eq1 : skip n j1 = succ j1 := skip_above_eq n j1 p1\n          match Nat.lt_or_ge j2 n with\n          | Or.inl p2 =>\n            let ineq1 : j2 < j1 := Nat.lt_of_lt_of_le p2 p1 \n            let ineq2 : j2 < skip n j1 := Nat.lt_of_lt_of_le ineq1 (skip_ge n j1)\n            let ineq3 : j2 < skip n j2 := Nat.lt_of_lt_of_le ineq2 (Nat.le_of_eq (hyp))\n            let eq2 : skip n j2 = j2 := skip_below_eq n j2 p2\n            let ineq4 : j2 < j2 := Nat.lt_of_lt_of_le ineq3 (Nat.le_of_eq eq2)\n            False.elim (Nat.lt_irrefl j2 ineq4)\n          | Or.inr p2 => \n            let eq2 : skip n j2 = succ j2 := skip_above_eq n j2 p2\n            let eq3 : succ j1 = succ j2 := by\n              rw [← eq1]\n              rw [← eq2]\n              exact hyp\n              done\n            by\n              injection eq3\n              assumption\n              done\n\ntheorem skip_no_fixedpoints (k: Nat) : (j: Nat) → Not (skip k j = k) :=\n  fun j =>\n    if c : j < k then\n      let eqn := skip_below_eq k j c  \n      fun hyp =>\n        let lem1 : k ≤  j := by\n          rw [←hyp] \n          rw [eqn]\n          apply Nat.le_refl\n          done\n        let lem2  := Nat.lt_of_lt_of_le c lem1\n        not_succ_le_self j lem2\n    else \n      let eqn := skip_not_below_eq k j c \n      fun hyp => \n        let lemEq : j + 1 = k := by\n          rw [←hyp]\n          rw [eqn]\n        let lemIneq : j < k := by\n          rw [←lemEq]\n          apply Nat.lt_succ_self\n        c lemIneq\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/Skip.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.7675218615174281}}
{"text": "open classical\n\nvariables { α : Type } { p q : α → Prop }\nvariable { a : α }\nvariable { r: Prop }\n\n\ntheorem not_all_iff_ex_not : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) :=\nby { split; intro h,\n    { apply by_contradiction, intro h1, apply h,\n        intro h2, apply by_contradiction, intro h3, \n        apply h1, split, exact h3 },\n    { intro h1, cases h with h2 h3, exact h3 (h1 h2) } }\n\ntheorem not_ex_iff_all_not : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) :=\nby { split; intro h,\n    { intros _ h1, apply h, split, exact h1 },\n    { intro h1, cases h1 with h2 h3, exact h h2 h3 } }\n\ntheorem not_all_not_iff_ex : (¬ ∀ x, ¬ p x) ↔ (∃ x, p x) :=\nby { split; intro h,\n    { apply by_contradiction, intro h1, apply h,\n        intros _ h2, apply h1, split, exact h2 },\n    { intro h1, cases h with h h2, exact h1 h h2 } }\n\ntheorem not_ex_not_iff_all : (¬ ∃ x, ¬ p x) ↔ (∀ x, p x) :=\nby { split; intros h h1,\n    { apply by_contradiction, intro h2, \n        apply h, split, exact h2 },\n    { cases h1 with h1 h2, exact h2 (h h1) } }\n\ntheorem all_and_iff_and_all : \n    (∀ x, p x ∧ q x) ↔ ((∀ x, p x) ∧ (∀ x, q x)) :=\nby { split; intro h,\n    { split; intro h1, exact (h h1).left, exact (h h1).right },\n    { intro, split, apply h.left, apply h.right } }\n\ntheorem ex_or_iff_or_ex : \n    (∃ x, (p x ∨ q x)) ↔ ((∃ x, p x) ∨ (∃ x, q x)) :=\nby { split; intro h,\n    { cases h with _ h, cases h with h h,\n        { left, constructor, exact h },\n        { right, constructor, exact h } },\n    { cases h with h h; cases h with _ h; constructor,\n        { left, exact h }, { right, exact h } } }\n\ntheorem ex_and_reduce : (∃ x, r ∧ p x) ↔ (r ∧ ∃ x, p x) :=\nby { split; intro h,\n    { cases h with _ h, split, exact h.left, \n        { split, exact h.right } },\n    { cases h with h h1, cases h1 with h1 h2, \n        existsi h1, split, exact h, exact h2 } }\n\ntheorem all_or_reduce : (∀ x, r ∨ p x) ↔ (r ∨ ∀ x, p x) :=\nby { split; intro h,\n    { apply @by_cases r; intro h1,\n        { left, exact h1 },\n        { right, intro h2, cases (h h2) with h h, \n            exact absurd h h1, exact h } },\n    { intro h1, cases h with h h,\n        { left, exact h }, { right, exact h h1 } } }\n\ntheorem all_mp_reduce_all : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=\nby { split; intros h h1 h2; exact h h2 h1 }\n\ntheorem all_mpr_reduce_ex : (∀ x, p x → r) ↔ ((∃ x, p x) → r) :=\nby { split; intro h,\n    { intro h1, cases h1 with h1 h2, exact h h1 h2 },\n    { intros h1 h2, apply h, split, exact h2 } }\n\ninclude a\ntheorem all_not_free_reduce : (∀ x : α, r) ↔ r :=\nby { split; intro h, exact h a, { intro, exact h } }\n\ntheorem ex_not_free_reduce : (∃ x : α, r) ↔ r :=\nby { split; intro h, \n    { cases h with _ h, exact h}, \n    { existsi a, exact h } }\n\ntheorem ex_mp_reduce_ex : (∃ x, r → p x) ↔ (r → ∃ x, p x) :=\nby { split; intro h,\n    { intro h1, cases h with h h2, existsi h, exact h2 h1},\n    { apply @by_cases r; intro h1,\n        { cases (h h1) with _ h, split, intro, exact h },\n        { existsi a, intro h2, exact absurd h2 h1 } } }\n\ntheorem ex_mpr_reduce_all : (∃ x, p x → r) ↔ ((∀ x, p x) → r) :=\nby { split; intro h,\n    { intro h1, cases h with h h2, exact h2 (h1 h) },\n    { apply @by_cases (∀ (x : α), p x); intro h1,\n        { existsi a, intro, exact h h1 },\n        { have h2 := not_all_iff_ex_not.mp h1, cases h2 with h2 h3,  \n            existsi h2, intro h4, exact absurd h4 h3 } } }\nomit a", "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/predicate_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.7674566684553651}}
{"text": "import data.nat.basic\nimport data.nat.parity\nimport data.int.basic\nimport data.equiv.denumerable\nimport data.int.modeq\nimport tactic\n\n\n-- Determine all possible colorings of the integers that satisfy these rules.\n\n\nstructure coloring := \n-- Each integer on the number line is colored with exactly one of three possible colors—red, green or blue\n(red green blue : set ℤ)\n(total : ∀ n, red n ∨ blue n ∨ green n)\n--according to the following two rules: \n-- the negative of a red number must be colored blue, \n(neg_red : ∀ n, red n → blue (-n))\n--and the sum of two blue numbers (not necessarily distinct) must be colored red.\n(add_blue : ∀ n m ∈ blue, n + m ∈ red)\n\n-- Show that the negative of a blue number must be colored red \n\nlemma neg_blue (x : coloring) : ∀ n, x.blue n → x.red (-n) := begin\nintros n hn, \nhave calc1 := x.add_blue _ _ hn hn,\nhave calc2 := x.neg_red _ calc1,\nhave calc3 := x.add_blue _ _ hn calc2,\nhave calc4 : n + -(n + n) = (-n), ring,\nrw calc4 at calc3, exact calc3,\nend\n\n-- and the sum of two red numbers must be colored blue.\n\nlemma add_red (x : coloring) : ∀ n m ∈ x.red, n + m ∈ x.blue := \nbegin\nintros n m hn hm,\nhave calc1 := x.neg_red _ hn,\nhave calc2 := x.neg_red _ hm,\nhave calc3 := x.add_blue _ _ calc1 calc2,\nhave calc4 := x.neg_red _ calc3,\nsimp only [neg_add_rev, neg_neg] at calc4,\nrw add_comm, exact calc4,\nend\n\n-- Determine all possible colorings of the integers that satisfy these rules.\n#print notation ≡\n\n-- if x is blue, then 2^n * x is blue when n is even and red when n is odd\n-- so coloring behavior is determined by behavior on 2 and odd numbers\n-- if 2 is blue and 1 is red, then all numbers 1 mod 4 are red and 3 mod 4 are blue\n\nexample : 3 - 5 = 0 := \nbegin\nnorm_num,\nend\n\nexample : (3 : ℤ) - 5 ≠ 0 := \nbegin\nnorm_num,\nend\n\n\nlemma mod_four (x : coloring) (h1 : x.red 1) : ∀ n, x.red n ↔ n ≡ 1 [ZMOD 4] := begin\n\nend\n\n", "meta": {"author": "jalex-stark", "repo": "live-stream", "sha": "066c55911cf5610a4363acaca87d50a9b6ec71de", "save_path": "github-repos/lean/jalex-stark-live-stream", "path": "github-repos/lean/jalex-stark-live-stream/live-stream-066c55911cf5610a4363acaca87d50a9b6ec71de/MathcampQQuiz/2012_q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.952574129515172, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7674243833509177}}
{"text": "inductive aexpr : Type\n| const : ℕ → aexpr\n| var : ℕ → aexpr\n| plus : aexpr → aexpr → aexpr\n| times : aexpr → aexpr → aexpr\n\nopen aexpr\n\ndef sample_aexpr : aexpr :=\nplus (times (var 0) (const 7)) (times (const 2) (var 1))\n\n-- BEGIN\ndef aeval (v : ℕ → ℕ) : aexpr → ℕ\n| (const n)    := n\n| (var n)      := v n\n| (plus e₁ e₂)  := (aeval e₁) + (aeval e₂)\n| (times e₁ e₂) := (aeval e₁) * (aeval e₂)\n\ndef sample_val : ℕ → ℕ\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-- END\n\n-- BEGIN\ndef simp_const : aexpr → aexpr\n| (plus (const n₁) (const n₂))  := const (n₁ + n₂)\n| (times (const n₁) (const n₂)) := const (n₁ * n₂)\n| e                             := e\n\ndef fuse : aexpr → aexpr\n| (plus e₁ e₂)  := simp_const (plus (fuse e₁) (fuse e₂))\n| (times e₁ e₂) := simp_const (times (fuse e₁) (fuse e₂))\n| e := e\n\n#eval aeval sample_val (fuse sample_aexpr)\n\ntheorem simp_const_eq (v : ℕ → ℕ) :\n  ∀ e : aexpr, aeval v (simp_const e) = aeval v e\n| (const n) := rfl\n| (var n) := rfl\n| (plus e1 e2) := begin\n  cases e1, {\n    cases e2, reflexivity,\n    repeat { dsimp [simp_const], reflexivity }      \n  }, \n  repeat {\n    dsimp [simp_const], reflexivity\n  }\nend\n| (times e1 e2) := begin\n  cases e1, {\n    cases e2, reflexivity,\n    repeat { dsimp [simp_const], reflexivity }      \n  }, \n  repeat {\n    dsimp [simp_const], reflexivity\n  }\nend\n\ntheorem fuse_eq (v : ℕ → ℕ) :\n  ∀ e : aexpr, aeval v (fuse e) = aeval v e\n| (plus e1 e2) := begin\n  dsimp [fuse],\n  simp [simp_const_eq],\n  dsimp [aeval],\n  simp [fuse_eq e1, fuse_eq e2],\nend\n| (times e1 e2) := begin\n  dsimp [fuse],\n  simp [simp_const_eq],\n  dsimp [aeval],\n  simp [fuse_eq e1, fuse_eq e2],\nend\n| (const _) := rfl\n| (var _) := rfl\n-- END\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/8.9.6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7673751174111294}}
{"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 algebra.order.archimedean\nimport group_theory.subgroup.basic\n\n/-!\n# Archimedean groups\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file proves a few facts about ordered groups which satisfy the `archimedean` property, that is:\n`class archimedean (α) [ordered_add_comm_monoid α] : Prop :=`\n`(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y)`\n\nThey are placed here in a separate file (rather than incorporated as a continuation of\n`algebra.order.archimedean`) because they rely on some imports from `group_theory` -- bundled\nsubgroups in 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 `ℤ`\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 `ℝ`.\n-/\n\nvariables {G : Type*} [linear_ordered_add_comm_group G] [archimedean G]\nopen linear_ordered_add_comm_group\n\n/-- Given a subgroup `H` of a decidable linearly ordered archimedean abelian group `G`, if there\nexists a minimal element `a` of `H ∩ G_{>0}` then `H` is generated by `a`. -/\nlemma add_subgroup.cyclic_of_min {H : add_subgroup G} {a : G}\n  (ha : is_least {g : G | g ∈ H ∧ 0 < g} a) : H = add_subgroup.closure {a} :=\nbegin\n  obtain ⟨⟨a_in, a_pos⟩, a_min⟩ := ha,\n  refine le_antisymm _ (H.closure_le.mpr $ by simp [a_in]),\n  intros g g_in,\n  obtain ⟨k, ⟨nonneg, lt⟩, _⟩ : ∃! k, 0 ≤ g - k • a ∧ g - k • a < a :=\n    exists_unique_zsmul_near_of_pos' a_pos g,\n  have h_zero : g - k • a = 0,\n  { by_contra h,\n    have h : a ≤ g - k • a,\n    { refine a_min ⟨_, _⟩,\n      { exact add_subgroup.sub_mem H g_in (add_subgroup.zsmul_mem H a_in k) },\n      { exact lt_of_le_of_ne nonneg (ne.symm h) } },\n    have h' : ¬ (a ≤ g - k • a) := not_le.mpr lt,\n    contradiction },\n  simp [sub_eq_zero.mp h_zero, add_subgroup.mem_closure_singleton],\nend\n\n/-- Every subgroup of `ℤ` is cyclic. -/\nlemma int.subgroup_cyclic (H : add_subgroup ℤ) : ∃ a, H = add_subgroup.closure {a} :=\nbegin\n  cases add_subgroup.bot_or_exists_ne_zero H with h h,\n  { use 0,\n    rw h,\n    exact add_subgroup.closure_singleton_zero.symm },\n  let s := {g : ℤ | g ∈ H ∧ 0 < g},\n  have h_bdd : ∀ g ∈ s, (0 : ℤ) ≤ g := λ _ h, le_of_lt h.2,\n  obtain ⟨g₀, g₀_in, g₀_ne⟩ := h,\n  obtain ⟨g₁, g₁_in, g₁_pos⟩ : ∃ g₁ : ℤ, g₁ ∈ H ∧ 0 < g₁,\n  { cases lt_or_gt_of_ne g₀_ne with Hg₀ Hg₀,\n    { exact ⟨-g₀, H.neg_mem g₀_in, neg_pos.mpr Hg₀⟩ },\n    { exact ⟨g₀, g₀_in, Hg₀⟩ } },\n  obtain ⟨a, ha, ha'⟩ := int.exists_least_of_bdd ⟨(0 : ℤ), h_bdd⟩ ⟨g₁, g₁_in, g₁_pos⟩,\n  exact ⟨a, add_subgroup.cyclic_of_min ⟨ha, ha'⟩⟩,\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/group_theory/archimedean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7673517007587803}}
{"text": "/-\nCopyright (c) 2021 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris Van Doorn, Yury Kudryashov\n-/\n\nimport measure_theory.constructions.borel_space\n\n/-!\n# Regular measures\n\nA measure is `outer_regular` if the measure of any measurable set `A` is the infimum of `μ 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 `μ 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 `μ F` over all compact 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 `μ`, and this implication is recorded as an instance.\n\nIn order to avoid code duplication, we also define a measure `μ` to be `inner_regular` for sets\nsatisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set\n`U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ 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 `ℝ × ℝ` 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 `ℝ × {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 μ`: a typeclass registering that a measure `μ` on a\n  topological space is outer regular.\n* `measure_theory.measure.regular μ`: a typeclass registering that a measure `μ` on a topological\n  space is regular.\n* `measure_theory.measure.weakly_regular μ`: a typeclass registering that a measure `μ` on a\n  topological space is weakly regular.\n* `measure_theory.measure.inner_regular μ p q`: a non-typeclass predicate saying that a measure `μ`\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 `μ` 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 `μ` is outer regular, for every set `s`\n  and `r > μ s` there exists an open superset `U ⊇ 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* `measure_theory.measure.outer_regular.of_sigma_compact_space_of_is_locally_finite_measure`:\n  a locally finite measure on a `σ`-compact metric (or even pseudo emetric) space 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 < μ U`, there exists a closed `F ⊆ 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 < μ F` and `μ s < μ F + ε`, 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_sigma_compact_space_of_locally_finite`\n  is an instance registering that a locally finite measure on a `σ`-compact metric space (or even\n  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 < μ U`, there exists a compact `K ⊆ 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 < μ K` and `μ s < μ K + ε`, 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 `σ`-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 `σ`-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, §52][halmos1950measure]. Note that Halmos uses an unusual definition of\nBorel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his\nproofs or statements do not apply directly.\n\n[Billingsley, Convergence of Probability Measures][billingsley1999]\n-/\n\nopen set filter\nopen_locale ennreal topological_space nnreal big_operators\n\nnamespace measure_theory\nnamespace measure\n\n/-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : set α → Prop`,\nif for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ 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 inner_regular {α} {m : measurable_space α} (μ : measure α) (p q : set α → Prop) :=\n∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K ⊆ U, p K ∧ r < μ K\n\nnamespace inner_regular\n\nvariables {α : Type*} {m : measurable_space α} {μ : measure α} {p q : set α → Prop}\n  {U : set α} {ε : ℝ≥0∞}\n\nlemma measure_eq_supr (H : inner_regular μ p q) (hU : q U) : μ U = ⨆ (K ⊆ U) (hK : p K), μ K :=\nbegin\n  refine le_antisymm (le_of_forall_lt (λ r hr, _)) (bsupr_le $ λ K hK, supr_le $ λ _, μ.mono hK),\n  simpa only [lt_supr_iff, exists_prop] using H hU r hr\nend\n\nlemma exists_subset_lt_add (H : inner_regular μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞)\n  (hε : ε ≠ 0) :\n  ∃ K ⊆ U, p K ∧ μ U < μ K + ε :=\nbegin\n  cases eq_or_ne (μ U) 0 with h₀ h₀,\n  { refine ⟨∅, empty_subset _, h0, _⟩,\n    rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero] },\n  { rcases H hU _ (ennreal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩,\n    exact ⟨K, hKU, hKc, ennreal.lt_add_of_sub_lt (or.inl hμU) hrK⟩ }\nend\n\nlemma map {α β} [measurable_space α] [measurable_space β] {μ : measure α} {pa qa : set α → Prop}\n  (H : inner_regular μ pa qa) (f : α ≃ β) (hf : measurable f)\n  {pb qb : set β → Prop} (hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K))\n  (hB₁ : ∀ K, pb K → measurable_set K) (hB₂ : ∀ U, qb U → measurable_set U) :\n  inner_regular (map f μ) pb qb :=\nbegin\n  intros U hU r hr,\n  rw [map_apply hf (hB₂ _ hU)] at hr,\n  rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩,\n  refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, _⟩,\n  rwa [map_apply hf (hB₁ _ $ hAB' _ hKc), f.preimage_image]\nend\n\nlemma smul (H : inner_regular μ p q) (c : ℝ≥0∞) : inner_regular (c • μ) p q :=\nbegin\n  intros U hU r hr,\n  rw [smul_apply, H.measure_eq_supr hU] at hr,\n  simpa only [ennreal.mul_supr, lt_supr_iff, exists_prop] using hr\nend\n\nlemma trans {q' : set α → Prop} (H : inner_regular μ p q) (H' : inner_regular μ q q') :\n  inner_regular μ p q' :=\nbegin\n  intros U hU r hr,\n  rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩, rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩,\n  exact ⟨K, hKF.trans hFU, hpK, hrK⟩\nend\n\nend inner_regular\n\nvariables {α β : Type*} [measurable_space α] [topological_space α] {μ : measure α}\n\n/-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ 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] class outer_regular (μ : measure α) : Prop :=\n(outer_regular : ∀ ⦃A : set α⦄, measurable_set A → ∀ r > μ A, ∃ U ⊇ A, is_open U ∧ μ U < r)\n\n/-- A measure `μ` is regular if\n  - it is finite on all compact sets;\n  - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;\n  - it is inner regular for open sets, using compact sets:\n    `μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/\n@[protect_proj] class regular (μ : measure α) extends outer_regular μ : Prop :=\n(lt_top_of_is_compact : ∀ ⦃K : set α⦄, is_compact K → μ K < ∞)\n(inner_regular : inner_regular μ is_compact is_open)\n\n/-- A measure `μ` is weakly regular if\n  - it is outer regular: `μ(A) = inf { μ(U) | A ⊆ U open }` for `A` measurable;\n  - it is inner regular for open sets, using closed sets:\n    `μ(U) = sup {μ(F) | F ⊆ U compact}` for `U` open. -/\n@[protect_proj] class weakly_regular (μ : measure α) extends outer_regular μ : Prop :=\n(inner_regular : inner_regular μ is_closed is_open)\n\n/-- A regular measure is weakly regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance regular.weakly_regular [t2_space α] [regular μ] : weakly_regular μ :=\n{ inner_regular := λ U hU r hr, let ⟨K, hKU, hcK, hK⟩ := regular.inner_regular hU r hr\n  in ⟨K, hKU, hcK.is_closed, hK⟩ }\n\nnamespace outer_regular\n\ninstance zero : outer_regular (0 : measure α) :=\n⟨λ A hA r hr, ⟨univ, subset_univ A, is_open_univ, hr⟩⟩\n\n/-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with\nmeasure less than `r`. -/\nlemma _root_.set.exists_is_open_lt_of_lt [outer_regular μ] (A : set α) (r : ℝ≥0∞) (hr : μ A < r) :\n  ∃ U ⊇ A, is_open U ∧ μ U < r :=\nbegin\n  rcases outer_regular.outer_regular (measurable_set_to_measurable μ A) r\n    (by rwa measure_to_measurable) with ⟨U, hAU, hUo, hU⟩,\n  exact ⟨U, (subset_to_measurable _ _).trans hAU, hUo, hU⟩\nend\n\n/-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets\ncontaining it. -/\nlemma _root_.set.measure_eq_infi_is_open (A : set α) (μ : measure α) [outer_regular μ] :\n  μ A = (⨅ (U : set α) (h : A ⊆ U) (h2 : is_open U), μ U) :=\nbegin\n  refine le_antisymm (le_binfi $ λ s hs, le_infi $ λ h2s, μ.mono hs) _,\n  refine le_of_forall_lt' (λ r hr, _),\n  simpa only [infi_lt_iff, exists_prop] using A.exists_is_open_lt_of_lt r hr\nend\n\nlemma _root_.set.exists_is_open_lt_add [outer_regular μ] (A : set α) (hA : μ A ≠ ∞)\n  {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ U ⊇ A, is_open U ∧ μ U < μ A + ε :=\nA.exists_is_open_lt_of_lt _ (ennreal.lt_add_right hA hε)\n\nlemma _root_.set.exists_is_open_le_add (A : set α) (μ : measure α) [outer_regular μ]\n  {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ U ⊇ A, is_open U ∧ μ U ≤ μ A + ε :=\nbegin\n  rcases le_or_lt ∞ (μ A) with H|H,\n  { exact ⟨univ, subset_univ _, is_open_univ,\n      by simp only [top_le_iff.mp H, ennreal.top_add, le_top]⟩ },\n  { rcases A.exists_is_open_lt_add H.ne hε with ⟨U, AU, U_open, hU⟩,\n    exact ⟨U, AU, U_open, hU.le⟩ }\nend\n\nlemma _root_.measurable_set.exists_is_open_diff_lt [opens_measurable_space α]\n  [outer_regular μ] {A : set α} (hA : measurable_set A)\n  (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ U ⊇ A, is_open U ∧ μ U < ∞ ∧ μ (U \\ A) < ε :=\nbegin\n  rcases A.exists_is_open_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩,\n  use [U, hAU, hUo, hU.trans_le le_top],\n  exact measure_diff_lt_of_lt_add hA hUo.measurable_set hAU hA' hU,\nend\n\nprotected lemma map [opens_measurable_space α] [measurable_space β] [topological_space β]\n  [borel_space β] (f : α ≃ₜ β) (μ : measure α) [outer_regular μ] :\n  (measure.map f μ).outer_regular :=\nbegin\n  refine ⟨λ A hA r hr, _⟩,\n  rw [map_apply f.measurable hA, ← f.image_symm] at hr,\n  rcases set.exists_is_open_lt_of_lt _ r hr with ⟨U, hAU, hUo, hU⟩,\n  have : is_open (f.symm ⁻¹' U), from hUo.preimage f.symm.continuous,\n  refine ⟨f.symm ⁻¹' U, image_subset_iff.1 hAU, this, _⟩,\n  rwa [map_apply f.measurable this.measurable_set, f.preimage_symm, f.preimage_image],\nend\n\nprotected lemma smul (μ : measure α) [outer_regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) :\n  (x • μ).outer_regular :=\nbegin\n  rcases eq_or_ne x 0 with rfl|h0,\n  { rw zero_smul, exact outer_regular.zero },\n  { refine ⟨λ A hA r hr, _⟩,\n    rw [smul_apply, A.measure_eq_infi_is_open] at hr,\n    simpa only [ennreal.mul_infi_of_ne h0 hx, gt_iff_lt, infi_lt_iff, exists_prop] using hr }\nend\n\nend outer_regular\n\n/-- If a measure `μ` admits finite spanning open sets such that the restriction of `μ` to each set\nis outer regular, then the original measure is outer regular as well. -/\nprotected lemma finite_spanning_sets_in.outer_regular [opens_measurable_space α] {μ : measure α}\n  (s : μ.finite_spanning_sets_in {U | is_open U ∧ outer_regular (μ.restrict U)}) :\n  outer_regular μ :=\nbegin\n  refine ⟨λ A hA r hr, _⟩,\n  have hm : ∀ n, measurable_set (s.set n), from λ n, (s.set_mem n).1.measurable_set,\n  haveI : ∀ n, outer_regular (μ.restrict (s.set n)) := λ n, (s.set_mem n).2,\n  -- Note that `A = ⋃ n, A ∩ disjointed s n`. We replace `A` with this sequence.\n  obtain ⟨A, hAm, hAs, hAd, rfl⟩ : ∃ A' : ℕ → set α, (∀ n, measurable_set (A' n)) ∧\n    (∀ n, A' n ⊆ s.set n) ∧ pairwise (disjoint on A') ∧ A = ⋃ n, A' n,\n  { refine ⟨λ n, A ∩ disjointed s.set n, λ n, hA.inter (measurable_set.disjointed hm _),\n      λ n, (inter_subset_right _ _).trans (disjointed_subset _ _),\n      (disjoint_disjointed s.set).mono (λ k l hkl, hkl.mono inf_le_right inf_le_right), _⟩,\n    rw [← inter_Union, Union_disjointed, s.spanning, inter_univ] },\n  rcases ennreal.exists_pos_sum_of_encodable' (tsub_pos_iff_lt.2 hr).ne' ℕ with ⟨δ, δ0, hδε⟩,\n  rw [lt_tsub_iff_right, add_comm] at hδε,\n  have : ∀ n, ∃ U ⊇ A n, is_open U ∧ μ U < μ (A n) + δ n,\n  { intro n,\n    have H₁ : ∀ t, μ.restrict (s.set n) t = μ (t ∩ s.set n), from λ t, restrict_apply' (hm n),\n    have Ht : μ.restrict (s.set n) (A n) ≠ ⊤,\n    { rw H₁, exact ((measure_mono $ inter_subset_right _ _).trans_lt (s.finite n)).ne },\n    rcases (A n).exists_is_open_lt_add Ht (δ0 n).ne' with ⟨U, hAU, hUo, hU⟩,\n    rw [H₁, H₁, inter_eq_self_of_subset_left (hAs _)] at hU,\n    exact ⟨U ∩ s.set n, subset_inter hAU (hAs _), hUo.inter (s.set_mem n).1, hU⟩ },\n  choose U hAU hUo hU,\n  refine ⟨⋃ n, U n, Union_subset_Union hAU, is_open_Union hUo, _⟩,\n  calc μ (⋃ n, U n) ≤ ∑' n, μ (U n)             : measure_Union_le _\n                ... ≤ ∑' n, (μ (A n) + δ n)     : ennreal.tsum_le_tsum (λ n, (hU n).le)\n                ... = ∑' n, μ (A n) + ∑' n, δ n : ennreal.tsum_add\n                ... = μ (⋃ n, A n) + ∑' n, δ n  : congr_arg2 (+) (measure_Union hAd hAm).symm rfl\n                ... < r                         : hδε\nend\n\nnamespace inner_regular\n\nvariables {p q : set α → Prop} {U s : set α} {ε r : ℝ≥0∞}\n\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. -/\nlemma measurable_set_of_open [opens_measurable_space α] [outer_regular μ]\n  (H : inner_regular μ p is_open) (h0 : p ∅) (hd : ∀ ⦃s U⦄, p s → is_open U → p (s \\ U)) :\n  inner_regular μ p (λ s, measurable_set s ∧ μ s ≠ ∞) :=\nbegin\n  rintros s ⟨hs, hμs⟩ r hr,\n  obtain ⟨ε, hε, hεs, rfl⟩ : ∃ ε ≠ 0, ε + ε ≤ μ s ∧ r = μ s - (ε + ε),\n  { use (μ s - r) / 2, simp [*, hr.le, ennreal.add_halves, ennreal.sub_sub_cancel, le_add_right] },\n  rcases hs.exists_is_open_diff_lt hμs hε with ⟨U, hsU, hUo, hUt, hμU⟩,\n  rcases (U \\ s).exists_is_open_lt_of_lt _ hμU with ⟨U', hsU', hU'o, hμU'⟩,\n  replace hsU' := diff_subset_comm.1 hsU',\n  rcases H.exists_subset_lt_add h0 hUo hUt.ne hε with ⟨K, hKU, hKc, hKr⟩,\n  refine ⟨K \\ U', λ x hx, hsU' ⟨hKU hx.1, hx.2⟩, hd hKc hU'o, ennreal.sub_lt_of_lt_add hεs _⟩,\n  calc μ s ≤ μ U                   : μ.mono hsU\n       ... < μ K + ε               : hKr\n       ... ≤ μ (K \\ U') + μ U' + ε :\n    add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _\n       ... ≤ μ (K \\ U') + ε + ε    : by { mono*, exacts [hμU'.le, le_rfl] }\n       ... = μ (K \\ U') + (ε + ε)  : add_assoc _ _ _\nend\n\nopen finset\n\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. -/\nlemma weakly_regular_of_finite [borel_space α] (μ : measure α) [is_finite_measure μ]\n  (H : inner_regular μ is_closed is_open) : weakly_regular μ :=\nbegin\n  have hfin : ∀ {s}, μ s ≠ ⊤ := measure_ne_top μ,\n  suffices : ∀ s, measurable_set s → ∀ ε ≠ 0,\n    ∃ (F ⊆ s) (U ⊇ s), is_closed F ∧ is_open U ∧ μ s ≤ μ F + ε ∧ μ U ≤ μ s + ε,\n  { refine { outer_regular := λ s hs r hr, _, inner_regular := H },\n    rcases exists_between hr with ⟨r', hsr', hr'r⟩,\n    rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with ⟨-, -, U, hsU, -, hUo, -, H⟩,\n    refine ⟨U, hsU, hUo, _⟩,\n    rw [add_tsub_cancel_of_le hsr'.le] at H, exact H.trans_lt hr'r },\n  refine measurable_set.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  { intros U hU ε hε,\n    rcases H.exists_subset_lt_add is_closed_empty hU hfin hε with ⟨F, hsF, hFc, hF⟩,\n    exact ⟨F, hsF, U, subset.rfl, hFc, hU, hF.le, le_self_add⟩ },\n  -- check for complements\n  { rintros s hs H ε hε,\n    rcases H ε hε with ⟨F, hFs, U, hsU, hFc, hUo, hF, hU⟩,\n    refine ⟨Uᶜ, compl_subset_compl.2 hsU, Fᶜ, compl_subset_compl.2 hFs,\n      hUo.is_closed_compl, hFc.is_open_compl, _⟩,\n    simp only [measure_compl_le_add_iff, *, hUo.measurable_set, hFc.measurable_set, true_and] },\n  -- check for disjoint unions\n  { intros s hsd hsm H ε ε0, have ε0' : ε / 2 ≠ 0, from (ennreal.half_pos ε0).ne',\n    rcases ennreal.exists_pos_sum_of_encodable' ε0' ℕ with ⟨δ, δ0, hδε⟩,\n    choose F hFs U hsU hFc hUo hF hU using λ n, H n (δ n) (δ0 n).ne',\n    -- the approximating closed set is constructed by considering finitely many sets `s i`, which\n    -- cover all the measure up to `ε/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 (λ t, ∑ k in t, μ (s k) + ε / 2) at_top (𝓝 $ μ (⋃ n, s n) + ε / 2),\n    { rw measure_Union hsd hsm, exact tendsto.add ennreal.summable.has_sum tendsto_const_nhds },\n    rcases (this.eventually $ lt_mem_nhds $ ennreal.lt_add_right hfin ε0').exists with ⟨t, ht⟩,\n    -- the approximating open set is constructed by taking for each `s n` an approximating open set\n    -- `U n` with measure at most `μ (s n) + δ n` for a summable `δ`, and taking the union of these.\n    refine ⟨⋃ k ∈ t, F k, Union_subset_Union $ λ k, Union_subset $ λ _, hFs _,\n      ⋃ n, U n, Union_subset_Union hsU, is_closed_bUnion t.finite_to_set $ λ k _, hFc k,\n      is_open_Union hUo, ht.le.trans _, _⟩,\n    { calc ∑ k in t, μ (s k) + ε / 2 ≤ ∑ k in t, μ (F k) + ∑ k in t, δ k + ε / 2 :\n        by { rw ← sum_add_distrib, exact add_le_add_right (sum_le_sum $ λ k hk, hF k) _ }\n      ... ≤ ∑ k in t, μ (F k) + ε / 2 + ε / 2 :\n        add_le_add_right (add_le_add_left ((ennreal.sum_le_tsum _).trans hδε.le) _) _\n      ... = μ (⋃ k ∈ t, F k) + ε : _,\n      rw [measure_bUnion_finset, add_assoc, ennreal.add_halves],\n      exacts [λ k _ n _ hkn, (hsd k n hkn).mono (hFs k) (hFs n), λ k hk, (hFc k).measurable_set] },\n    { calc μ (⋃ n, U n) ≤ ∑' n, μ (U n) : measure_Union_le _\n      ... ≤ ∑' n, (μ (s n) + δ n) : ennreal.tsum_le_tsum hU\n      ... = μ (⋃ n, s n) + ∑' n, δ n : by rw [measure_Union hsd hsm, ennreal.tsum_add]\n      ... ≤ μ (⋃ n, s n) + ε : add_le_add_left (hδε.le.trans ennreal.half_le_self) _ } }\nend\n\n/-- In a metric space (or even a pseudo emetric space), an open set can be approximated from inside\nby closed sets. -/\nlemma of_pseudo_emetric_space {X : Type*} [pseudo_emetric_space X] [measurable_space X]\n  [opens_measurable_space X] (μ : measure X) :\n  inner_regular μ is_closed is_open :=\nbegin\n  intros U hU r hr,\n  rcases hU.exists_Union_is_closed with ⟨F, F_closed, -, rfl, F_mono⟩,\n  rw measure_Union_eq_supr (λ n, (F_closed n).measurable_set) F_mono.directed_le at hr,\n  rcases lt_supr_iff.1 hr with ⟨n, hn⟩,\n  exact ⟨F n, subset_Union _ _, F_closed n, hn⟩\nend\n\n/-- In a `σ`-compact space, any closed set can be approximated by a compact subset. -/\nlemma is_compact_is_closed {X : Type*} [topological_space X] [t2_space X]\n  [sigma_compact_space X] [measurable_space X] [opens_measurable_space X] (μ : measure X) :\n  inner_regular μ is_compact is_closed :=\nbegin\n  intros F hF r hr,\n  set B : ℕ → set X := compact_covering X,\n  have hBc : ∀ n, is_compact (F ∩ B n), from λ n, (is_compact_compact_covering X n).inter_left hF,\n  have hBU : (⋃ n, F ∩ B n) = F, by rw [← inter_Union, Union_compact_covering, set.inter_univ],\n  have : μ F = ⨆ n, μ (F ∩ B n),\n  { rw [← measure_Union_eq_supr, hBU],\n    exacts [λ n, (hBc n).measurable_set, monotone.directed_le $\n      λ m n h, inter_subset_inter_right _ (compact_covering_subset _ h)] },\n  rw this at hr, rcases lt_supr_iff.1 hr with ⟨n, hn⟩,\n  exact ⟨_, inter_subset_left _ _, hBc n, hn⟩\nend\n\nend inner_regular\n\nnamespace regular\n\ninstance zero : regular (0 : measure α) :=\n⟨λ K hK, ennreal.coe_lt_top, λ U hU r hr, ⟨∅, empty_subset _, is_compact_empty, hr⟩⟩\n\n/-- If `μ` is a regular measure, then any open set can be approximated by a compact subset. -/\nlemma _root_.is_open.exists_lt_is_compact [regular μ] ⦃U : set α⦄ (hU : is_open U)\n  {r : ℝ≥0∞} (hr : r < μ U) :\n  ∃ K ⊆ U, is_compact K ∧ r < μ K :=\nregular.inner_regular hU r hr\n\n/-- The measure of an open set is the supremum of the measures of compact sets it contains. -/\nlemma _root_.is_open.measure_eq_supr_is_compact ⦃U : set α⦄ (hU : is_open U)\n  (μ : measure α) [regular μ] :\n  μ U = (⨆ (K : set α) (h : K ⊆ U) (h2 : is_compact K), μ K) :=\nregular.inner_regular.measure_eq_supr hU\n\nlemma exists_compact_not_null [regular μ] : (∃ K, is_compact K ∧ μ K ≠ 0) ↔ μ ≠ 0 :=\nby simp_rw [ne.def, ← measure_univ_eq_zero, is_open_univ.measure_eq_supr_is_compact,\n    ennreal.supr_eq_zero, not_forall, exists_prop, subset_univ, true_and]\n\n/-- If `μ` 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`. -/\nlemma inner_regular_measurable [opens_measurable_space α] [regular μ] :\n  inner_regular μ is_compact (λ s, measurable_set s ∧ μ s ≠ ∞) :=\nregular.inner_regular.measurable_set_of_open is_compact_empty (λ _ _, is_compact.diff)\n\n/-- If `μ` 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`. -/\nlemma _root_.measurable_set.exists_is_compact_lt_add [opens_measurable_space α]\n  [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ K ⊆ A, is_compact K ∧ μ A < μ K + ε :=\nregular.inner_regular_measurable.exists_subset_lt_add is_compact_empty ⟨hA, h'A⟩ h'A hε\n\n/-- If `μ` 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`. -/\nlemma _root_.measurable_set.exists_is_compact_diff_lt [opens_measurable_space α] [t2_space α]\n  [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ K ⊆ A, is_compact K ∧ μ (A \\ K) < ε :=\nbegin\n  rcases hA.exists_is_compact_lt_add h'A hε with ⟨K, hKA, hKc, hK⟩,\n  exact ⟨K, hKA, hKc, measure_diff_lt_of_lt_add hKc.measurable_set hA hKA\n    (ne_top_of_le_ne_top h'A $ measure_mono hKA) hK⟩\nend\n\n/-- If `μ` 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`. -/\nlemma _root_.measurable_set.exists_lt_is_compact_of_ne_top [regular μ]\n  [opens_measurable_space α] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞)\n  {r : ℝ≥0∞} (hr : r < μ A) :\n  ∃ K ⊆ A, is_compact K ∧ r < μ K :=\nregular.inner_regular_measurable ⟨hA, h'A⟩ _ hr\n\n/-- Given a regular measure, any measurable set of finite mass can be approximated from\ninside by compact sets. -/\nlemma _root_.measurable_set.measure_eq_supr_is_compact_of_ne_top\n  [opens_measurable_space α] [regular μ]\n  ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) :\n  μ A = (⨆ (K ⊆ A) (h : is_compact K), μ K) :=\nregular.inner_regular_measurable.measure_eq_supr ⟨hA, h'A⟩\n\nprotected lemma map [opens_measurable_space α] [measurable_space β] [topological_space β]\n  [t2_space β] [borel_space β] [regular μ] (f : α ≃ₜ β) :\n  (measure.map f μ).regular :=\nbegin\n  haveI := outer_regular.map f μ,\n  split,\n  { intros K hK, rw [map_apply f.measurable hK.measurable_set],\n    apply regular.lt_top_of_is_compact,\n    rwa f.compact_preimage },\n  { exact regular.inner_regular.map f.to_equiv f.measurable (λ U hU, hU.preimage f.continuous)\n      (λ K hK, hK.image f.continuous) (λ K hK, hK.measurable_set) (λ U hU, hU.measurable_set) }\nend\n\nprotected lemma smul [regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) :\n  (x • μ).regular :=\nbegin\n  haveI := outer_regular.smul μ hx,\n  exact ⟨λ K hK, ennreal.mul_lt_top hx (regular.lt_top_of_is_compact hK).ne,\n    regular.inner_regular.smul x⟩\nend\n\n/-- A regular measure in a σ-compact space is σ-finite. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance sigma_finite [sigma_compact_space α] [regular μ] : sigma_finite μ :=\n⟨⟨{ set := compact_covering α,\n  set_mem := λ n, trivial,\n  finite := λ n, regular.lt_top_of_is_compact $ is_compact_compact_covering α n,\n  spanning := Union_compact_covering α }⟩⟩\n\nend regular\n\nnamespace weakly_regular\n\n/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/\nlemma _root_.is_open.exists_lt_is_closed [weakly_regular μ] ⦃U : set α⦄ (hU : is_open U)\n  {r : ℝ≥0∞} (hr : r < μ U) :\n  ∃ F ⊆ U, is_closed F ∧ r < μ F :=\nweakly_regular.inner_regular hU r hr\n\n/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/\nlemma _root_.is_open.measure_eq_supr_is_closed ⦃U : set α⦄ (hU : is_open U)\n  (μ : measure α) [weakly_regular μ] :\n  μ U = (⨆ (F ⊆ U) (h : is_closed F), μ F) :=\nweakly_regular.inner_regular.measure_eq_supr hU\n\nlemma inner_regular_measurable [opens_measurable_space α] [weakly_regular μ] :\n  inner_regular μ is_closed (λ s, measurable_set s ∧ μ s ≠ ∞) :=\nweakly_regular.inner_regular.measurable_set_of_open is_closed_empty\n  (λ _ _ h₁ h₂, h₁.inter h₂.is_closed_compl)\n\n/-- If `s` is a measurable set, a weakly regular measure `μ` is finite on `s`, and `ε` is a positive\nnumber, then there exist a closed set `K ⊆ s` such that `μ s < μ K + ε`. -/\nlemma _root_.measurable_set.exists_is_closed_lt_add [weakly_regular μ]\n  [opens_measurable_space α] {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞)\n  {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ K ⊆ s, is_closed K ∧ μ s < μ K + ε :=\ninner_regular_measurable.exists_subset_lt_add is_closed_empty ⟨hs, hμs⟩ hμs hε\n\nlemma _root_.measurable_set.exists_is_closed_diff_lt [opens_measurable_space α]\n  [weakly_regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ F ⊆ A, is_closed F ∧ μ (A \\ F) < ε :=\nbegin\n  rcases hA.exists_is_closed_lt_add h'A hε with ⟨F, hFA, hFc, hF⟩,\n  exact ⟨F, hFA, hFc, measure_diff_lt_of_lt_add hFc.measurable_set hA hFA\n    (ne_top_of_le_ne_top h'A $ measure_mono hFA) hF⟩\nend\n\n/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from\ninside by closed sets. -/\nlemma _root_.measurable_set.exists_lt_is_closed_of_ne_top [weakly_regular μ]\n  [opens_measurable_space α] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞)\n  {r : ℝ≥0∞} (hr : r < μ A) :\n  ∃ K ⊆ A, is_closed K ∧ r < μ K :=\ninner_regular_measurable ⟨hA, h'A⟩ _ hr\n\n/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from\ninside by closed sets. -/\nlemma _root_.measurable_set.measure_eq_supr_is_closed_of_ne_top [opens_measurable_space α]\n  [weakly_regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) :\n  μ A = (⨆ (K ⊆ A) (h : is_closed K), μ K) :=\ninner_regular_measurable.measure_eq_supr ⟨hA, h'A⟩\n\n/-- The restriction of a weakly regular measure to a measurable set of finite measure is\nweakly regular. -/\nlemma restrict_of_measurable_set [borel_space α] [weakly_regular μ] (A : set α)\n  (hA : measurable_set A) (h'A : μ A ≠ ∞) : weakly_regular (μ.restrict A) :=\nbegin\n  haveI : fact (μ A < ∞) := ⟨h'A.lt_top⟩,\n  refine inner_regular.weakly_regular_of_finite _ (λ V V_open, _),\n  simp only [restrict_apply' hA], intros r hr,\n  have : μ (V ∩ A) ≠ ∞, from ne_top_of_le_ne_top h'A (measure_mono $ inter_subset_right _ _),\n  rcases (V_open.measurable_set.inter hA).exists_lt_is_closed_of_ne_top this hr\n    with ⟨F, hFVA, hFc, hF⟩,\n  refine ⟨F, hFVA.trans (inter_subset_left _ _), hFc, _⟩,\n  rwa inter_eq_self_of_subset_left (hFVA.trans $ inter_subset_right _ _)\nend\n\n/-- Any finite measure on a metric space (or even a pseudo emetric space) is weakly regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance of_pseudo_emetric_space_of_is_finite_measure {X : Type*} [pseudo_emetric_space X]\n  [measurable_space X] [borel_space X] (μ : measure X) [is_finite_measure μ] :\n  weakly_regular μ :=\n(inner_regular.of_pseudo_emetric_space μ).weakly_regular_of_finite μ\n\n/-- Any locally finite measure on a `σ`-compact metric space (or even a pseudo emetric space) is\nweakly regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance of_pseudo_emetric_sigma_compact_space_of_locally_finite {X : Type*}\n  [pseudo_emetric_space X] [sigma_compact_space X] [measurable_space X] [borel_space X]\n  (μ : measure X) [is_locally_finite_measure μ] :\n  weakly_regular μ :=\nbegin\n  haveI : outer_regular μ,\n  { refine (μ.finite_spanning_sets_in_open.mono' $ λ U hU, _).outer_regular,\n    haveI : fact (μ U < ∞), from ⟨hU.2⟩,\n    exact ⟨hU.1, infer_instance⟩ },\n  exact ⟨inner_regular.of_pseudo_emetric_space μ⟩\nend\n\nend weakly_regular\n\n/-- Any locally finite measure on a `σ`-compact (e)metric space is regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance regular.of_sigma_compact_space_of_is_locally_finite_measure {X : Type*}\n  [emetric_space X] [sigma_compact_space X] [measurable_space X] [borel_space X] (μ : measure X)\n  [is_locally_finite_measure μ] : regular μ :=\n{ lt_top_of_is_compact := λ K hK, hK.measure_lt_top,\n  inner_regular := (inner_regular.is_compact_is_closed μ).trans\n    (inner_regular.of_pseudo_emetric_space μ) }\n\nend measure\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/regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086368, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7673516989638116}}
{"text": "import analysis.real tactic.norm_num algebra.group_power\n\nlemma avg_lt_max {mn mx: ℝ} (H : mn < mx) : (mn+mx) / 2 < mx :=\nbegin\n  apply (mul_lt_mul_right (show (0:ℝ)<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: ℝ} (H : mn < mx) : mn < (mn+mx) / 2 :=\nbegin\n  apply (mul_lt_mul_right (show (0:ℝ)<2, by norm_num)).1,\n  rw [div_mul_cancel _ (two_ne_zero)],\n  simp [H,mul_two],\nend\n\nlemma lub_open (y : ℝ) : is_lub {x : ℝ | 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 ∈ {x : ℝ | 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 ℝ := {x : ℝ | x<0}\n\ntheorem Q3a : is_lub (S3a) 0 := lub_open 0\n\ndef S3b : set ℝ := {x : ℝ | ∃ y : ℚ, x = ↑y}\n\ntheorem Q3b : ∀ b : ℝ, ¬ (is_lub (S3b) b) :=\nbegin\nintros b Hlub,\nhave Hbub : b ∈ upper_bounds S3b := Hlub.left,\nhave H : b < (b+1) := calc b = b+0 : (add_zero _).symm\n                         ... < b+1 : add_lt_add_left zero_lt_one _,\n--have H2 := exists_rat_btwn H,\n--cases H2 with q Hq,\ncases (exists_rat_btwn H) with q Hq,\nhave Hwrong := Hbub ↑q,\nhave Hqin : ↑q ∈ S3b := ⟨q,rfl⟩,\nexact not_lt.2 (Hwrong Hqin) (Hq.left),\nend\n\nlemma pow_two_eq_mul_self {x : ℝ} : x^2=x*x :=\nbegin\nunfold monoid.pow,simp,\nend\n\ndef S3c : set ℝ := {x : ℝ | (x+1)^2 < x^2} -- x<-0.5\n\ntheorem Q3c : is_lub (S3c) (-1/2) :=\nbegin\nhave : S3c = {x : ℝ | x < -1/2},\n{ apply set.ext,\n  intro x,\n  show (x+1)^2 < x^2 ↔ x < -1/2,\n  rw [←add_zero (x^2),pow_two_eq_mul_self,mul_add,add_mul,add_mul,pow_two_eq_mul_self,mul_one,one_mul],\n  rw [add_assoc],\n  -- ask Mario why I can't do this -- I only want\n  -- to change one thing\n  exact calc\n    x * x + (x + (x + 1 * 1)) < x * x + 0 ↔ (x + (x + 1 * 1)) < 0 : add_lt_add_iff_left (x*x)\n    ... ↔ x * 2 + 1 < 0 : by rw [mul_one,←add_assoc,←mul_two]\n    ... ↔ x * 2 < -1 : by rw[←lt_sub_right_iff_add_lt,zero_sub]\n    ... ↔ x < (-1) / 2 : (lt_div_iff (show (0:ℝ) < 2, by norm_num)).symm },\nrw this,\nexact lub_open ((-1)/2),\nend\n\ndef S3d : set ℝ := {x : ℝ | (∃ q : ℚ, x=↑q) ∧ 1 < x ∧ x < 2}\n\ntheorem Q3d : is_lub S3d 2 :=\nbegin\nsplit,\n{ intros z Hz,\n  exact le_of_lt Hz.right.right },\nintros y Hy,\nrefine le_of_not_gt _,\nintro Hylt2,\nhave onelt2 : (1:ℝ) < 2 := by norm_num,\nhave := max_lt onelt2 Hylt2,\ncases (exists_rat_btwn this) with q Hq,\nhave := Hy ↑q,\nhave Hq_in : ↑q ∈ S3d,\n{ split,\n  { existsi q,refl},\n  split,\n  { exact lt_of_le_of_lt (le_max_left _ _) Hq.left },\n  exact Hq.right,\n},\nhave this2 := this Hq_in,\n\nunfold upper_bounds at Hy,\napply (not_lt.2 this2),\nexact lt_of_le_of_lt (le_max_right 1 y) Hq.left,\nend\n\ntheorem Q4 (S : set ℝ) (x : ℝ) (H1 : x ∈ upper_bounds S) (H2 : x ∈ S) : is_lub S x :=\nbegin\nsplit,exact H1,\nintro y,\nintro H,\nhave := H x,\nexact this H2,\nend\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/M1F/problem_bank/PB0601/S0601.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7673516915986723}}
{"text": "-- begin header\nimport M40001.M40001_C1\nimport data.real.basic\n\nnamespace M40001\n\nopen function \nuniverse u\n-- end header\n\n/- Section\nFunctions\n-/\n\n/- Sub-section\n2.2.1 Function Composition\n-/\n\n/- Definition\nGiven two functions $f : A → B$, $g : B → C$ where $A, B, C$ are sets, then $(g ∘ f)(x)$ (the composition of $g$ and $f$) is $g(f(x))$.\n-/\ndef my_composition {A B C : Type u} (f : A → B) (g : B → C) := λ x : A, g (f x)\n\n/-\nRemark. Here, to define $\\tt{my\\\\_composition}$ we used something called lambda abstraction $\\tt{λ x : A, g (f x)}$. \nThis is essentially saying we are mapping $\\tt{x}$ with type $\\tt{A}$ to $\\tt{g(f(x))}$. \nRead more about lambda abstraction <a href = \"shorturl.at/hGPX1\">here</a> or <a href = \"https://en.wikipedia.org/wiki/Lambda_calculus\">here</a>.\n-/\n\n/- Sub-section\n2.3 Injectivity, Surjectivity and Bijectivity\n-/\n\n/- Definition\nA function $f : X → Y$ is called injective if distinct elements of $X$ get mapped to distinct elements of $Y$. More formally, $f$ is injective if $∀ a, b ∈ X, f(a) = f(b) ⇒ a = b$.\n-/\ndef my_injective {X Y : Type u} (f : X → Y) := ∀ a b : X, f(a) = f(b) → a = b\n\n/- Definition\nA function $f : X → Y$ is called surjective if every element of $Y$ gets \"hit\" by $f$. More formally, $f$ is surjective if $∀ y ∈ Y, ∃ x ∈ X$ such that $f(x) = y$.\n-/\ndef my_surjective {X Y : Type u} (f : X → Y) := ∀ y : Y, ∃ x : X, f(x) = y\n\n/- Definition\nA function $f : X → Y$ is called bijective if it is both injective and surjective.\n-/\ndef my_bijective {X Y : Type u} (f : X → Y) := injective f ∧ surjective f\n\n/- \nRemark. Although we have defined some lovely properties for our functions, it turns out that these definitions are already defined in the LEAN maths library.\nSo while our effort might be wasted, we can now use some theorems already written without going through them ourselves!\n-/\n\n/- Section\nBijectivity and Composition\n-/\n\n/-Theorem\nLet $f : X → Y$ and $g : Y → Z$ be functions, then if $f$ and $g$ are both injective, then so is $g ∘ f$.\n-/\ntheorem both_injective \n    (X Y Z : Type u) (f : X → Y) (g : Y → Z) : injective f ∧ injective g → injective (g ∘ f) :=\nbegin\n    -- Suppose that $f$ and $g$ are injective functions, we need to show that $g ∘ f$ is also injective, i.e. if $(g ∘ f)(a) = (g ∘ f)(b)$, then $a = b$.\n    intros h a b ha,\n    -- Since $g$ is injective, we have $f(a) = f(b)$.\n    apply h.left,\n    -- Similarly, since $f$ is injective, $a = b$, which is exactly what we wanted!\n    apply h.right,\n    assumption\nend\n\n/-\nRemark. Notice that in step 2, LEAN knew that by definition, $(g ∘ f)(x) = g(f(x))$, so we have $g (f(a)) = g (f(b))$, how smart is that!\n-/\n\n/-Theorem\nLet $f : X → Y$ and $g : Y → Z$ be functions, then if $f$ and $g$ are both surjective, then so is $g ∘ f$.\n-/\ntheorem both_surjective\n    (X Y Z : Type u) (f : X → Y) (g : Y → Z) : surjective f ∧ surjective g → surjective (g ∘ f) :=\nbegin\n    -- Suppose that $f$ and $g$ are surjective functions, we need to show that $g ∘ f$ is also surjective, i.e. $∀ z ∈ Z, ∃ x ∈ X, (g ∘ f)(x) = z$. \n    intros h z,\n    -- Since $g$ is surjective, there is a $y ∈ Y$ such that $g(y) = z$.\n    have ha : ∃ y : Y, g(y) = z, apply h.right,\n    cases ha with y hy,\n    -- Similarly, as $f$ is surjective, there is a $x ∈ X$ such that $f(x) = y$.\n    have hb : ∃ x : X, f(x) = y, apply h.left,\n    cases hb with x hx,\n    -- But by definition, $(g ∘ f)(x) = g(f(x)) = g(y) = z$ So we are done!\n    existsi x,\n    rwa [←hy, ←hx]\nend\n\n/-Theorem\nLet $f : X → Y$ and $g : Y → Z$ be functions, then if $f$ and $g$ are both bijective, then so is $g ∘ f$.\n-/\ntheorem both_bijective\n    (X Y Z : Type u) (f : X → Y) (g : Y → Z) : bijective f ∧ bijective g → bijective (g ∘ f) :=\nbegin\n    -- Since $f$ and $g$ are bijective, they are also injective and surjective.\n    rintro ⟨⟨hfi, hfs⟩, hgi, hgs⟩,\n    split,\n    -- But since $f$ and $g$ are injective, $g ∘ f$ is injective by our previous theorem.\n    apply both_injective,\n    split,\n    repeat {assumption},\n    -- Similarly, since $f$ and $g$ surjective, $g ∘ f$ is surjective.\n    apply both_surjective,\n    split,\n    -- Hence, since $g ∘ f$ is injective and surjective, $g ∘ f$ is bijective.\n    repeat {assumption}\nend\n\n/-Sub-section\n2.4 Inverses\n-/\n\n/- Definition\nBy digging through $\\tt{functions}$, it turns out that the brilliant people of LEAN has not yet defined two sided inverse as the time of writting this. \nSo let's define $g : Y → X$ to be the two sided inverse of $f : X → Y$ if and only if $∀ x ∈ X, (g ∘ f)(x) = x$ and $∀ y ∈ Y, (f ∘ g)(y) = y$.\n-/\ndef two_sided_inverse {X Y : Type u} (f : X → Y) (g : Y → X) := (∀ x : X, (g ∘ f)(x) = x) ∧ (∀ y : Y, (f ∘ g)(y) = y)\n\n\n/-Theorem\nA function $f : X → Y$ has a two-sided inverse if and only if it is a bijection.\n-/\ntheorem exist_two_sided_inverse\n    (X Y : Type u) (f : X → Y) : (∃ g : Y → X, two_sided_inverse f g) ↔ bijective f :=\nbegin\n    -- Again, since the question is in the form of 'if and only if', we need to prove both sides of the implications. \n    split,\n    -- $(⇒)$ Suppose the function $f : X → Y$ has a two sided inverse $g$, we need to show that $f$ is bijective, i.e. it is injective and surjective.\n    rintro ⟨g, ⟨hlinv, hrinv⟩⟩,\n    -- So lets first show that $f$ is injective.\n    have hfinj : injective f,\n    -- Suppose we have $f(p) = f(q)$ for some $p q ∈ X$, then $f$ is injective if $p = q$.\n        intros p q hf,\n    -- Since $f(p) = f(q)$, we have $g(f(p)) = g(f(q))$.\n        replace hf : g (f p) = g (f q), rw hf,\n    -- But since $g$ is a double sided inverse of $f$, $∀ x ∈ X, g(f(x)) = x$, hence $p = g(f(p))= g(f(q)) = q$ which is exactly what we need!\n        have ha : g (f p) = p := hlinv p,\n        have hb : g (f q) = q := hlinv q,\n        rw [ha, hb] at hf,\n        assumption,\n    -- Now we need to show that $f$ is surjective, i.e. $∀ y ∈ Y, ∃ x ∈ X, f(x) = y$.\n    have hfbsur : surjective f,\n        intro y,\n    -- Since we have $g(y) ∈ X$, suppose we choose $x$ to be $g(y)$.\n        existsi g y,\n    -- But, as $g$ is a double inverse of $f$, $f(g(y)) = y$ which is exactly what we need!\n        exact hrinv y,\n    -- Thus, as $f$ is both injective and surjective, $f$ is bijective!\n    split,\n    all_goals {try {assumption}},\n    -- $(⇐)$ Now lets prove the reverse implication, i.e. if $f$ is bijective, then $f$ has a two-sided inverse.\n    rintro ⟨hfinj, hfsur⟩,\n    -- Since $f$ is surjective, $∀ y ∈ Y, ∃ x ∈ X$ such that $f(x) = y$, lets choose this $x$ to be our output of $g(y)$.\n    choose g hg using hfsur,\n    existsi g,\n    -- Now we need to show that $g$ is a double sided inverse of $f$ so let's first show that $g$ is a left inverse of $f$.\n    split,\n    intro a,\n    -- Consider that since, by definition of $g$, $∀ y ∈ Y, f(g(y)) = y$ we have $f(g(f(a))) = f(a)$,\n    have ha : f (g (f a)) = f a,\n        rw hg (f a),\n    -- therefore, as $f$ is injective, we have $f(g(f(a))) = f(a) ⇒ g(f(a)) = f(a)$. Thus, $g$ is a left inverse of $f$.\n    exact hfinj ha,\n    -- Now, all we have left to prove is that $g$ is a right inverse of $f$. But that is true by definition, so we are done!\n    assumption\nend\n\n/-Sub-section\n2.5 Binary Relations\n-/\nvariables {X V : Type u}\n\n/- Definition\nA binary relation $R$ on a set $X$ is a function $R : X^2 → \\tt{Prop}$.\n-/\ndef bin_rel (X) := X → X → Prop\n\n/- Sub-section \n2.6 Common Predicates on Binary Relations\n-/\n\n/- Definition\nA binary relation $R$ on $X$ is called relfexive if $∀ x ∈ X, R(x, x)$.\n-/\ndef reflexive (r : bin_rel X) := ∀ x : X, r x x\n\n/- Theorem\n$≤$ is reflexive on $ℝ$.\n-/\n@[simp] theorem le_refl : reflexive ((≤) : ℝ → ℝ → Prop) := \nbegin\n    -- To prove that the binary relation $≤$ on $ℝ$ is reflexive, we need to show given arbitary $x ∈ ℝ$, $x ≤ x$.\n    intro,\n    -- But this obviously true, so we're done!\n    refl\nend\n\n/- Definition\nA binary relation $R$ on $X$ is called symmetric if $∀a, b ∈ X, R(a, b) ⇒ R(b, a)$.\n-/\ndef symmetric (r : bin_rel X) := ∀ x y : X, r x y → r y x\n\n/- Theorem\n$=$ is symmetric on $ℝ$.\n-/\ntheorem eq_symm : symmetric ((=) : ℝ → ℝ → Prop) :=\nbegin\n    -- To prove that $=$ is a symmetric binary relation on $ℝ$, we need to show that given $x = y$, $y = x$.\n    intros x y h,\n    -- But if $x = y$, then we can re-write $y$ as $x$ and $x$ as $y$, thus, $y = x$. \n    rwa h\nend\n\n/- Definition\nA binary relation $R$ on $X$ is called antisymmetric if $∀ a, b ∈ X, R(a, b) ∧ R(b, a) ⇒ a = b$.\n-/\ndef antisymmetric (r : bin_rel X) := ∀ x y : X, r x y ∧ r y x → x = y\n\n/- Theorem\n$≤$ is anti-symmetric on $R$.\n-/\n@[simp] theorem le_antisymm : antisymmetric ((≤) : ℝ → ℝ → Prop) :=\nbegin\n-- Suppose we have $x, y ∈ ℝ$ where $x ≤ y$ and $y ≤ x$, then we need to show that $x = y$.\n    intros x y h,\n    have h0 : (x < y ∨ x = y) ∧ (y < x ∨ y = x),\n        repeat {rw ←le_iff_lt_or_eq}, assumption,\n-- By the trichotomy axioms, either $x < y$, $y < x$ or $x = y$.\n    cases lt_trichotomy x y with ha hb,\n-- Let's first suppose that $x < y$, then obviously $¬ (y < x)$. But since we have $y ≤ x$, $x$ must therefore equal to $y$!\n    {suffices : ¬ (y < x),\n        cases h0.right with hc hd, contradiction, rwa hd,\n    simp, from h.left},\n    {cases hb with he hf,\n-- Let's now consider the other two cases. If $x = y$ then there is nothing left to prove so lets suppose $y < x$.\n    {assumption},\n-- Similar to before, $(y < x) ⇒ ¬ (x < y)$. But $(x ≤ y)$, therefore $x = y$!\n    {suffices : ¬ (x < y),\n        cases h0.left with hc hd, contradiction, rwa hd,\n    simp, from h.right}\n    }\nend\n\n/-\nRemark. Notice that in the above proof I used a lot of curly bracket. This will limit the tactic state to only show the the goal within the brackets and thus also limit clutter.\nRead more about how to structure LEAN proofs nicely <a href = \"https://leanprover.github.io/theorem_proving_in_lean/tactics.html#structuring-tactic-proofs\">here</a>.\n-/\n\n/- Definition\nA binary relation $R$ on $X$ is called transitive if $∀ a, b, c ∈ X, R(a, b) ∧ R(b, c) ⇒ R(a, c)$. \n-/\ndef transitive (r : bin_rel X) := ∀ x y z : X, r x y ∧ r y z → r x z\n\n/- Theorem\n$⇒$ is transitive on the set of propositions.\n-/\ntheorem imply_trans : transitive ((→) : Prop → Prop → Prop) :=\nbegin\n    -- Let $P, Q, R$ be propositions such that $P ⇒ Q$ and $Q ⇒ R$. We then need to prove that $P ⇒ R$. Suppose $P$ is true.\n    intros P Q R h hp, \n    -- Then as $P ⇒ Q$, $Q$ must also be true. And again as $Q ⇒ R$, $R$ must also be true. Thus $P ⇒ R$, and we are done!\n    from h.right (h.left hp)\nend\n\n/- Theorem\n$≤$ is transitive on $ℝ$.\n-/\n@[simp] theorem le_trans : transitive ((≤) : ℝ → ℝ → Prop) :=\nbegin\n    -- This one is a bit tricky and require us to delve into how ordering is defined on the reals in LEAN.\n    intros x y z h, \n    -- However, with the power that is mathlib, we see that there is something called $\\tt{le_trans}$, so why don't we just steal that for our use here!\n    from le_trans h.left h.right\nend\n\n/- Sub-section\n2.7 Partial and Total Orders\n-/\n\n/-\nLet $R$ be a binary relation on the set $X$.\n-/\n\n/- Definition\nWe call $R$ a partial order if it is reflexive, antisymmetric, and transitive.\n-/\ndef partial_order (r : bin_rel X) := reflexive r ∧ antisymmetric r ∧ transitive r\n\n/- Definition\nWe call $R$ total if $∀ a, b ∈ X, R(a, b) ∨ R(b, a)$.\n-/\ndef total (r : bin_rel X) := ∀ x y : X, r x y ∨ r y x\n\n/- Definition\nWe call $R$ a total order if it is total and a partial order.\n-/\ndef total_order (r : bin_rel X) := partial_order r ∧ total r\n\n/- \nLet's now prove that $≤$ is a total order. As we already have already proven that $≤$ is reflexive, symmetric, and transitive, i.e. its a partial order, we only need to show $≤$ is total to prove that $≤$ is a total order.\n-/\n\n/- Lemma\n$≤$ is total on $ℝ$.\n-/\n@[simp] theorem le_total : total ((≤) : ℝ → ℝ → Prop) :=\nbegin\n    -- Suppose we have $x, y ∈ ℝ$, by the trichotomy axiom, either $x < y$, $y < x$ or $x = y$.\n    intros x y,\n    cases lt_trichotomy x y,\n    -- If $x < y$ then $x ≤ y$.\n    repeat {rw le_iff_lt_or_eq},\n    {left, left, assumption},\n    -- If $x = y$ then also $x ≤ y$. However, if $y > x$, then we have $y ≤ x$. Thus, by considering all the cases, we see either $x ≤ y$ or $y ≤ x$. \n    {cases h, repeat { {left, assumption} <|> right <|> assumption }, rwa h}\nend\n\n/-\nRemark. The last line of this LEAN proof uses something called $\\tt{tactic combinators}$. Read about is <a href = \"https://leanprover.github.io/theorem_proving_in_lean/tactics.html#tactic-combinators\">here</a>.\n-/\n\n/- Theorem\n$≤$ is a total order on $ℝ$.\n-/\ntheorem le_total_order : total_order ((≤) : ℝ → ℝ → Prop) :=\nbegin\n    -- As $≤$ is a partial order and is total, it is a total order!\n    repeat {split},\n    repeat {simp}\nend\n\n/-\nRemark. Notice how I tagged some of the theorems above with $\\tt{@[simp]}$? This tells LEAN to try to uses theses theorems whenever I use the tactive $\\tt{simp}$. Read more about it <a href = \"https://leanprover.github.io/theorem_proving_in_lean/tactics.html#using-the-simplifier\">here</a>.\n-/\n\n/- Sub-section\n2.7 Equivalence Relations\n-/\n\n/- Definition\nA binary relation $R$ on the set $X$ is called an equivalence relation if it is reflexive, symmetric, and transitive.\n-/\ndef equivalence (r : bin_rel X) := reflexive r ∧ symmetric r ∧ transitive r\n\n/- \nWe'll present some examples of equivalence relations below.\n-/\n\n/- Definition\nSuppose we define a binary relation $R(m, n)$, $m, n ∈ ℤ$, where $R(m, n)$ is true if and only if $m - n$ is even.\n-/\ndef R (m n : ℤ) := 2 ∣ (m - n)\n\n/- Lemma\n(1) $R$ is reflexive.\n-/\nlemma R_refl : reflexive R :=\nbegin\n    -- We have for any $m ∈ ℝ$, $m - m = 0$.\n    intro,\n    unfold R, \n    -- As $2 ∣ 0$, we have $R(m, m)$ is true!\n    simp,\nend\n\n/- Lemma\n(2) $R$ is symmetric.\n-/\nlemma R_symm : symmetric R :=\nbegin\n    -- Suppose we have $m, n ∈ ℝ$ such that $R(m, n)$ is true.\n    intros m n,\n    -- As $R(m, n)$ implies $2 ∣ m - n$, $∃ x ∈ ℤ, 2 x = m - n$.\n    rintro ⟨x, hx⟩,\n    existsi -x,\n    -- But this means $2 (-x) = n - m$, i.e. $2 ∣ n - m$, thus $R(n, m)$ is also true!\n    simp, rw ←hx, ring,\nend\n\n/- Lemma\n(3) $R$ is transitive.\n-/\nlemma R_trans : transitive R :=\nbegin\n    -- Suppose we have $l, m, n ∈ ℝ$ such that $R(m, l)$ and $R(l, n)$, we need to show $R(m, n)$ is true.\n    intros l m n,\n    -- Since $R(m, l)$ and $R(l, n)$ implies $2 ∣ m - l$ and $2 ∣ l - n$, $∃ x, y ∈ ℤ, 2 x = m - l, 2 y = l - n$.\n    rintro ⟨⟨x, hx⟩, ⟨y, hy⟩⟩,\n    existsi x + y,\n    -- But then $2 (x + y) = 2 x + 2 y = m - l + l - n = m - n$. Thus $2 ∣ m - n$, i.e. $R(m, n)$.\n    ring, rw [←hx, ←hy], ring,\nend\n\n/- Theorem\n$R$ is an equivalence relation.\n-/\ntheorem R_equiv : equivalence R :=\nbegin\n    -- This follows directly from lemma (1), (2), and (3).\n    repeat {split},\n    {from R_refl},\n    {from R_symm},\n    {from R_trans}\nend\n\n/- Definition\nLet $X$ be a set of sets, where $A, B ∈ X$. Let's define $<\\mathtt{\\sim}$ such that $A <~ B$ if an only if $∃ g: A → B$, $g$ is an injection.\n-/\ndef brel (A B : Type*) := ∃ g : A → B, function.bijective g\ninfix ` <~ `: 50 := brel\n\n/- Lemma\n$<\\mathtt{\\sim}$ is reflexive.\n-/\n@[simp] lemma brel_refl : reflexive (<~) := \nbegin\n    -- To prove $<\\mathtt{\\sim}$ is reflexive we need to show there exists a bijection between a set $X$ and itself.\n    intro X,\n    -- Luckily, we can simply choose the identity function! \n    let g : X → X := id,\n    existsi g,\n    -- Since the identity function is bijective, $<\\mathtt{\\sim}$ is reflexive as required.\n    from function.bijective_id\nend\n\n/- Lemma\n$<\\mathtt{\\sim}$ is symmetric.\n-/\n@[simp] lemma brel_symm : symmetric (<~) :=\nbegin\n    -- To prove $<\\mathtt{\\sim}$ is symmetric we need to show that, for sets $X, Y$, $X <~ Y ⇒ Y <~ X$.\n    intros X Y,\n    -- Suppose $X <~ Y$, then by definition, $∃ f : X → Y$, where $f$ is bijective.\n    rintro ⟨f, hf⟩,\n    -- As proven ealier, $f$ is bijective implies $f$ has a two sided inverse $g$, let's choose that as our function.\n    have hg : ∃ g : Y → X, two_sided_inverse f g,\n        {rwa exist_two_sided_inverse\n    },\n    {cases hg with g hg,\n    existsi g,\n    -- Since $g$ is bijective if and only if $g$ has a two sided inverse, it suffices to prove that such an inverse exist.\n    rw ←exist_two_sided_inverse,\n    -- But as $g$ is the two sided inverse of $f$ by construction, we have $f$ is the two sided inverse of $g$ by definition, thus such an inverse does exist!\n    existsi f,\n    split,\n    {from hg.right},\n    {from hg.left}\n    }\nend\n\n/- Lemma\n$<\\mathtt{\\sim}$ is transitive.\n-/\n@[simp] lemma brel_trans : transitive (<~) :=\nbegin\n    -- Given three sets $X, Y, Z$ where $X <~ Y$ and $Y <~ Z$ we need to show that $X <~ Z$.\n    intros X Y Z,\n    -- Since $X <~ Y$ and $Y <~ Z$ there exists bijective functions $f : X → Y$ and $g : Y → Z$.\n    rintro ⟨⟨f, hf⟩, g, hg⟩,\n    -- But as proven ealier, the composition of two bijective functions is also bijective. Thus, $g ∘ f : X → Z$ is a bijective function which is exactly what we need!\n    existsi (g ∘ f),\n    apply both_bijective,\n    split, repeat {assumption}\nend\n\n/-\nWith that, we can conclude that $<\\mathtt{\\sim}$ is an equivalence relation!\n-/\n\n/- Theorem\n$<\\mathtt{\\sim}$ is an equivalence relation\n-/\ntheorem brel_equiv : equivalence (<~) :=\nbegin\n    -- This follows as $<\\mathtt{\\sim}$ is reflexive, symmetric and transitive!\n    repeat {split},\n    repeat {simp}\nend\n\n/-\nExercise. I have defined one more binary relation $\\mathtt{\\sim}>$. Can you try to prove it <a href = \"https://leanprover-community.github.io/lean-web-editor/#url=https%3A%2F%2Fraw.githubusercontent.com%2FJasonKYi%2FM4000x_LEAN_formalisation%2Fmaster%2Fsrc%2FExercises%2FExercies3.lean\">here</a>?\n-/\n\n/- Sub-section\n2.9 Quotients and Equivalence Classes\n-/\n\n/- Sub-section\n2.9.1 Equivalence Classes\n-/\n\n/- Definition\nLet $X$ be a set and let $\\mathtt{\\sim}$ be an equivalence relation on $X$. Let $s ∈ X$ be an arbitrary element. We define the equivalence class of $s$, written $cl(s)$ as $cl(s) = \\{x ∈ X ∣ s \\mathtt{\\sim} x\\}.\n-/\ndef cls (r : bin_rel X) (s : X) := {x : X | r s x}\n\n/- Lemma\n(1) Let $X$ be a set and let $R$ be an equivalence relation on $X$. Then, for $s, t ∈ X$, $R(s, t) ⇒ cl(t) ⊆ cl(s)$.\n-/\nlemma class_relate_lem_a \n    (s t : X) (R : bin_rel X) (h : equivalence R) : R s t → cls R t ⊆ cls R s :=\nbegin\n    -- Given that $R$ is an equivalence relation, we know that it is reflexive, symmetric and transitive.\n    rcases h with ⟨href, ⟨hsym, htrans⟩⟩,\n    -- Thus, given an element $x$ in $cl(t)$ (i.e. $R(t, x)$ is true), we have, by transitivit, $R(s, x)$.\n    intros ha x hb,\n    have hc : R t x := hb,\n    replace hc : R s t ∧ R t x, by {split, repeat {assumption}},\n    replace hc : R s x := htrans s t x hc,\n    -- Hence $x ∈ cl(s)$ by definition.\n    from hc\nend\n\n/-\nWith lemma (1) in place, it is quite easy to see that, not only is $cl(t) ⊆ cl(s)$, in fact, $cl(t) = cl(s)$.\n-/\n\n/- Lemma\n(2) Let $X$ be a set and let $R$ be an equivalence relation on $X$. Then, for $s, t ∈ X$, $R(s, t) ⇒ cl(t) = cl(s)$.\n-/\nlemma class_relate_lem_b \n    (s t : X) (R : bin_rel X) (h : equivalence R) : R s t → cls R t = cls R s :=\nbegin\n    -- By lemma (1), $cl(t) ⊆ cl(s), and thus, we only need to prove that $cl(s) ⊆ cl(t)$ in order for $cl(t) = cl(s)$.\n    intro h0,\n    rw le_antisymm_iff,\n    split,\n        all_goals {apply class_relate_lem_a,\n        repeat {assumption}\n        },\n    -- But, since $R$ is and equivalence relation, it is symmetric.\n        {rcases h with ⟨href, ⟨hsym, htrans⟩⟩,\n    -- Hence, $R(s, t) ↔ R(t, s)$ which by lemma (1) implies $cl(s) ⊆ cl(t)$ as required.\n        from hsym s t h0\n    }\nend\n\n/- Lemma\n(3) Let $X$ be a set and let $R$ be an equivalence relation on $X$. Then, for $s, t ∈ X$, $¬ R(s, t) ⇒ cl(t) ∩ cl(s) = ∅$. \n-/\nlemma class_not_relate\n    (s t : X) (R : bin_rel X) (h : equivalence R) : ¬ R s t → cls R t ∩ cls R s = ∅ :=\nbegin\n    have : (cls R t ∩ cls R s = ∅) ↔ ¬ ¬ (cls R t ∩ cls R s = ∅), rwa classical.not_not, rw this,\n    -- We prove by contradiction. Suppose $cl(t) ∩ cl(s) ≠ ∅$.\n    intros ha hb,\n    -- Then, there must be some $x$ in $cl(t) ∩ cl(s)$.\n    have hx : ∃ x, x ∈ cls R t ∩ cls R s := set.ne_empty_iff_nonempty.1 hb,\n    rcases hx with ⟨x, ⟨hα, hβ⟩⟩,\n    -- Thus, by definition, $R(t, x)$ and $R(s, t)$ must both be true!\n    rcases h with ⟨href, ⟨hsym, htrans⟩⟩,\n    have hc : R s x ∧ R x t, by {split, \n        from hβ,\n        apply hsym, from hα},\n    -- But this means $R(s, t)$ must also be true by transitivity, a contradiction to $¬ R(s, t)$!\n    have hd : R s t, by {from htrans s x t hc},\n    contradiction,\nend\n\n/-\nWe now formally define a partition of a set $X$\n-/\n\n/-\nPartition of a set $X$ is a set $A$ of non-empty subsets of $X$ with the property that each element of $X$ is in exacctly one of the subsets.\n-/\ndef partition (A : set (set X)) : Prop := (∀ x : X, (∃ B ∈ A, x ∈ B ∧ ∀ C ∈ A, x ∈ C → B = C)) ∧ ∅ ∉ A\n\nlemma equiv_refl (R : bin_rel X) (h : equivalence R) (x : X): R x x :=\nby {rcases h with ⟨href, ⟨hsym, htrans⟩⟩, from href x}\n\nlemma equiv_symm (R : bin_rel X) (h : equivalence R) (x y : X): R x y ↔ R y x :=\nby {rcases h with ⟨href, ⟨hsym, htrans⟩⟩, split, from hsym x y, from hsym y x}\n\nlemma equiv_trans (R : bin_rel X) (h : equivalence R) (x y z : X): R x y ∧ R y z → R x z :=\nby {rcases h with ⟨href, ⟨hsym, htrans⟩⟩, from htrans x y z}\n\nlemma itself_in_cls (R : bin_rel X) (h : equivalence R) (x : X) : x ∈ cls R x :=\nby {unfold cls, rw set.mem_set_of_eq, from equiv_refl R h x}\n\n/- Theorem\nLet $X$ be a set and let $R$ be an equivalence relation on $X$. Then the set $V$ of equivalence classes $\\{cl(s) | s ∈ X\\}$ for $R$ is a partition of $X$. \n-/\ntheorem equiv_relation_partition -- or replace the set with (set.range (cls R))\n    (R : bin_rel X) (h : equivalence R) : partition {a : set X | ∃ s : X, a = cls R s} := \nbegin\n    -- To show that the equivalence classes of $R$ form a partition of $X$, we need to show that every $x ∈ X$ is in exactly one equivalence class of $R$, AND, none of the equivalence classes are empty.\n    split,\n    -- So let's first show that every $x ∈ X$ is in exactly one equivalence class of $R$. Let $y$ be and element of $X$.\n    {simp, intro y,\n    existsi cls R y,\n    split,\n    -- Then obviously $y ∈ cl(y)$ since $R(y, y)$ is true by reflexivity.\n    {use y},\n        {split,\n            {from itself_in_cls R h y},\n    -- Okay. So now we need to prove uniqueness. Suppose there is a $x ∈ X$, $x ∈ cl(y)$, we then need to show $cl(y) = cl(x)$.\n            {intros C x hC hy_in_C, rw hC,\n    -- But this is true by lemma (2)!\n            apply class_relate_lem_b, assumption,\n            have : y ∈ cls R x, rwa ←hC,\n            unfold cls at this,\n            rwa set.mem_set_of_eq at this}\n            }\n        },\n    -- Now we have to prove that none of the equivalence classes are empty. But this is quite simple. Suppose there is an equivalence class $cl(x)$ where $x ∈ X$ that is empty.\n    {simp, intros x hx,\n    -- But then $x ∈ cl(x)$ as $R(x, x)$ is true by reflexivity. Ah ha! Contradiction! Hence, such empty equivalence class does not in fact exist! And we are done. \n    rw set.empty_def at hx,\n    have : x ∈ {x : X | false}, by {rw hx, from itself_in_cls R h x},\n    rwa set.mem_set_of_eq at this\n    }\nend\n\ndef rs (A : set (set(X))) (s t : X) := ∃ B ∈ A, s ∈ B ∧ t ∈ B\n\n/-\nBonus Exercise. Furthermore, it turns out that if $X$ is a set and $R$ an equivalence relation on $X$. Then any partition of $X$ can form a equivalence relation. Try to prove it <a href = \"https://leanprover-community.github.io/lean-web-editor/#url=https%3A%2F%2Fraw.githubusercontent.com%2FJasonKYi%2FM4000x_LEAN_formalisation%2Fmaster%2Fsrc%2FExercises%2FExercies4.lean\">here</a> and if you get stuck, <a href = \"https://raw.githubusercontent.com/JasonKYi/M4000x_LEAN_formalisation/master/src/Exercises/Exercies4_sol.lean\">here</a> are the solutions.\n-/\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/M40001_C2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7672452106259904}}
{"text": "import linear_algebra.finite_dimensional\nimport missing_mathlib.linear_algebra.dimension\n\nuniverses u v v' w\nopen_locale classical\n\nopen vector_space cardinal submodule module function\n\nvariables {K : Type u} {V : Type v} [field K] [add_comm_group V] [vector_space K V]\n{V₂ : Type v'} [add_comm_group V₂] [vector_space K V₂]\n\nnamespace finite_dimensional\n\nlemma findim_bot [finite_dimensional K V] : \n  findim K (⊥ : submodule K V) = 0 :=\nbegin\n  apply cardinal.nat_cast_inj.1,\n  rw findim_eq_dim,\n  rw dim_bot,\n  refl,\nend\n\nlemma bot_of_findim_zero [finite_dimensional K V]\n  (s : submodule K V) (h : findim K s = 0) : s = ⊥ :=\nbegin\n  apply submodule.bot_of_dim_zero,\n  rw ←findim_eq_dim,\n  apply cardinal.nat_cast_inj.2 h,\nend\n\n@[simp] lemma findim_top [finite_dimensional K V] : \n  findim K (⊤ : submodule K V) = findim K V :=\nbegin\n  apply cardinal.nat_cast_inj.1,\n  rw [findim_eq_dim, findim_eq_dim, dim_top]\nend\n\nlemma exists_mem_ne_zero_of_findim_pos\n  [finite_dimensional K V] (h_dim : 0 < findim K V) : ∃ x : V, x ≠ 0 :=\nbegin\n  apply @exists_mem_ne_zero_of_dim_pos' K V (by apply_instance),\n  rw ←findim_eq_dim,\n  rw ←cardinal.nat_cast_lt at h_dim,\n  apply h_dim\nend\n\nlemma findim_sup_add_findim_inf_eq [finite_dimensional K V] (s t : submodule K V) :\n  findim K (s ⊔ t : submodule K V) + findim K (s ⊓ t : submodule K V) \n    = findim K s + findim K t :=\nbegin\n  have := s.dim_sup_add_dim_inf_eq t,\n  repeat { rw ←findim_eq_dim at this },\n  exact this,\nend\n\nlemma eq_top_of_disjoint [finite_dimensional K V] (s t : submodule K V) \n  (hdim : findim K s + findim K t = findim K V)\n  (hdisjoint : disjoint s t) : s ⊔ t = ⊤ :=\nbegin\n  have h_findim_inf : findim K ↥(s ⊓ t) = 0,\n  { rw [disjoint, le_bot_iff] at hdisjoint,\n    rw [hdisjoint, findim_bot] },\n  apply eq_top_of_findim_eq,\n  rw ←hdim,\n  convert findim_sup_add_findim_inf_eq s t,\n  rw h_findim_inf,\n  refl,\nend\n\nlemma lt_omega_of_linear_independent {ι : Type w} [finite_dimensional K V]\n  {v : ι → V} (h : linear_independent K v) : \n  cardinal.mk ι < cardinal.omega :=\nbegin\n  apply cardinal.lift_lt.1,\n  apply lt_of_le_of_lt,\n  apply linear_independent_le_dim h,\n  rw [←findim_eq_dim, cardinal.lift_omega, cardinal.lift_nat_cast],\n  apply cardinal.nat_lt_omega,\nend\n\nend finite_dimensional", "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/finite_dimensional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642906, "lm_q2_score": 0.8397339616560073, "lm_q1q2_score": 0.7672452086521447}}
{"text": "namespace fol_17\n\n-- Facts useful for calculation proofs:\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\n-- Sub-example 1:\ntheorem t1 : x - x = 0 :=\ncalc\nx - x   = x + -x : by rw sub_eq_add_neg\n    ... = 0      : by rw add_right_neg\n\n-- Sub-example 2:\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 fol_17 (h : x + y = z + y) : x = z :=\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    ... = (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\n\nend fol_17", "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_first_order/fol_17.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7672452045629039}}
{"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\n! This file was ported from Lean 3 source module data.nat.gcd.big_operators\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.GCD.Basic\nimport Mathlib.Algebra.BigOperators.Basic\n\n/-! # Lemmas about coprimality with big products.\n\nThese lemmas are kept separate from `Data.Nat.GCD.Basic` in order to minimize imports.\n-/\n\n\nnamespace Nat\n\nopen BigOperators\n\n/-- See `IsCoprime.prod_left` for the corresponding lemma about `IsCoprime` -/\ntheorem coprime_prod_left {ι : Type _} {x : ℕ} {s : ι → ℕ} {t : Finset ι} :\n    (∀ i : ι, i ∈ t → coprime (s i) x) → coprime (∏ i : ι in t, s i) x :=\n  Finset.prod_induction s (fun y ↦ y.coprime x) (fun a b ↦ coprime.mul) (by simp)\n#align nat.coprime_prod_left Nat.coprime_prod_left\n\n/-- See `IsCoprime.prod_right` for the corresponding lemma about `IsCoprime` -/\ntheorem coprime_prod_right {ι : Type _} {x : ℕ} {s : ι → ℕ} {t : Finset ι} :\n    (∀ i : ι, i ∈ t → coprime x (s i)) → coprime x (∏ i : ι in t, s i) :=\n  Finset.prod_induction s (fun y ↦ x.coprime y) (fun a b ↦ coprime.mul_right) (by simp)\n#align nat.coprime_prod_right Nat.coprime_prod_right\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/GCD/BigOperators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7672088779770629}}
{"text": "import data.nat.basic\nimport tactic\n\n\ndef fibo : ℕ → ℕ\n| 0 := 0\n| 1 := 1\n| (n+2) := (fibo (n+1)) + (fibo n)\n\n#eval fibo 5\n\n\ndef ff : ℕ → (ℕ × ℕ)\n| 0 := (0, 1)\n| (n+1) := let a := (ff n) in (a.2, a.1 + a.2)\n\ndef fibo_fast : ℕ → ℕ\n| 0 := 0\n| (n+1) := (ff n).2\n\n#eval fibo_fast 5\n\n\n\nprivate lemma fibo_ff_aux (n : ℕ) : (ff n) = (fibo n, fibo n.succ)\n  :=\nbegin\n  induction n with n ih,\n    refl,\n\n    unfold fibo,\n    have unfolding_ff: (ff n.succ) = ((ff n).2, (ff n).1 + (ff n).2),\n      refl,\n    rw unfolding_ff,\n    rw ih,\n    simp,\n    apply add_comm,\nend\n\n\nlemma fibo_eq : ∀ n : ℕ, fibo n = fibo_fast n \n  :=\nbegin\n  intro n,\n  cases n,\n    refl,\n\n    unfold fibo_fast,\n    rw fibo_ff_aux,\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/Fibonacci.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7671775859010681}}
{"text": "import data.real.basic\n\ndef converges_to (s : ℕ → ℝ) (a : ℝ) :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, abs (s n - a) < ε\n\nvariables {s t : ℕ → ℝ} {a b c: ℝ}\n\ntheorem converges_to_ze\n  (cs : converges_to (abs s) 0): converges_to (λ n, s n ) (0) :=\nbegin\nintros ε εpos, --Introduce the hypotheses ε:ℝ and εpos:ε>0 \ndsimp,\ncases cs _ εpos with h₁ h₂,\nuse h₁,\nintros n h₃,\nspecialize @h₂ n h₃,\nrw sub_zero,\nrw sub_zero at h₂,\napply lt_of_abs_lt h₂,\nend\n\ntheorem squeeze (cs :converges_to s 0) \n(h₁: ∀ (e:ℕ), (abs t e) < s e ): converges_to (λ n, t n) (0):=\nbegin\nintros ε εpos, \ndsimp,\ncases cs ε εpos with h₂ h₃,\nuse h₂,\nintros n h₄,\nspecialize @h₃ n h₄,\nrw sub_zero,\nrw sub_zero at h₃,\nspecialize @h₁ n,\nhave h₅: s n ≤  |s n|,\nexact le_abs_self (s n),\napply lt_trans (lt_of_lt_of_le h₁ h₆) h₃,\nend\n\ntheorem conv_inv (cs : converges_to s a) (h₁: a ≠ 0) (h₂: ∀(m:ℕ), s m ≠ 0) : converges_to(λ n, 1/(s n))(1/a):=\nbegin\nintros ε εpos,\nhave inv_εpos: 1/ε > 0,\nfinish,\ndsimp,\ncases cs (1/ε) inv_εpos with N h₃,\nuse N,\nintro n,\nintro h₄,\nspecialize @h₃ n h₄,\nsorry,\n\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/Convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391558355999, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7671775753434232}}
{"text": "/-\nThis file contains the definition of the \"explode\" operation, which\ncreates a \"powerset\" of literals from a list of variables. Associated\ntheorems dealing with the contents of explode are also included.\n\nAuthors: Cayden Codel, Jeremy Avigad, Marijn Heule\nCarnegie Mellon University\n-/\n\nimport cnf.literal\nimport cnf.clause\nimport cnf.cnf\n\nimport data.nat.basic\nimport data.nat.pow\n\n-- Represents the parametric type of the variable stored in the literal\nvariables {V : Type*}\n\nopen literal clause\nopen list function\n\nnamespace explode\n\nvariables {v : V} {l : list V} {c : clause V}\n\n/-! # Explode -/\n\n-- Produces a list of all possible polarities on a list of variables, maintaining order\ndef explode : list V → list (clause V)\n| []        := [[]]\n| (v :: l) := (explode l).map (cons (Pos v)) ++ (explode l).map (cons (Neg v))\n\n@[simp] theorem explode_nil : explode ([] : list V) = [[]] := rfl\n\n@[simp] theorem explode_singleton (v : V) : explode [v] = [[Pos v], [Neg v]] := rfl\n\ntheorem length_explode (l : list V) : length (explode l) = 2^(length l) :=\nbegin\n  induction l with v vs ih,\n  { refl },\n  { simp only [explode, length_cons, length_append, length_map, pow_succ, two_mul, ih] }\nend\n\ntheorem length_explode_pos (l : list V) : length (explode l) > 0 :=\nby { rw length_explode, exact pow_pos zero_lt_two _ }\n\ntheorem exists_mem_explode (l : list V) : ∃ (c : clause V), c ∈ explode l :=\nexists_mem_of_length_pos (length_explode_pos _)\n\ntheorem length_eq_of_mem_explode : c ∈ explode l → length c = length l :=\nbegin\n  induction l with v vs ih generalizing c,\n  { rw [explode_nil, mem_singleton],\n    rintro rfl, refl },\n  { simp only [explode, mem_append, mem_map],\n    rintros (⟨c, hc, rfl⟩ | ⟨c, hc, rfl⟩);\n    { simp [ih hc, length_cons] } }\nend\n\ntheorem cons_mem_explode_cons_of_mem_explode (lit : literal V) : \n  c ∈ explode l → (lit :: c) ∈ explode (lit.var :: l) :=\nassume hc, by { cases lit; simp [explode, literal.var, hc] }\n\nvariable [decidable_eq V]\n\ntheorem mem_of_mem_explode_of_mem_vars : c ∈ explode l → v ∈ c.vars → v ∈ l :=\nbegin\n  induction l with v vs ih generalizing c,\n  { rw [explode_nil, mem_singleton],\n    rintros rfl hv, \n    rw clause.vars_nil at hv,\n    exact absurd hv (finset.not_mem_empty _) },\n  { simp only [explode, mem_append, mem_map],\n    rintros (⟨a, ha, rfl⟩ | ⟨a, ha, rfl⟩);\n    { rw [clause.vars, finset.mem_union, mem_cons_iff],\n      rintros (hv | hv),\n      { rw [var, finset.mem_singleton] at hv,\n        exact or.inl hv },\n      { exact or.inr (ih ha hv) } } }\nend\n\ntheorem mem_vars_of_mem_explode_of_mem : c ∈ explode l → v ∈ l → v ∈ c.vars :=\nbegin\n  induction l with v vs ih generalizing c,\n  { intros _ hv, exact absurd hv (not_mem_nil v) } ,\n  { simp only [explode, mem_append, mem_map],\n    rintros (⟨a, ha, rfl⟩ | ⟨a, ha, rfl⟩) hv;\n    { unfold clause.vars var,\n      rcases eq_or_mem_of_mem_cons hv with rfl | hv,\n      { exact finset.mem_union.mpr (or.inl (mem_singleton_self _)) },\n      { exact finset.mem_union.mpr (or.inr (ih ha hv)) } } }\nend\n\ntheorem not_mem_vars_of_mem_explode_of_not_mem : c ∈ explode l → v ∉ l → v ∉ c.vars :=\nλ h hv, mt (mem_of_mem_explode_of_mem_vars h) hv\n\ntheorem not_mem_of_mem_explode_of_not_mem_vars : c ∈ explode l → v ∉ c.vars → v ∉ l :=\nλ h hv, mt (mem_vars_of_mem_explode_of_mem h) hv\n\ntheorem pos_or_neg_of_mem_explode_of_mem : c ∈ explode l → v ∈ l → Pos v ∈ c ∨ Neg v ∈ c :=\nλ h hv, mem_vars_iff_pos_or_neg_mem_clause.mp (mem_vars_of_mem_explode_of_mem h hv)\n\ntheorem pos_and_neg_not_mem_of_mem_explode_of_not_mem : c ∈ explode l → v ∉ l → Pos v ∉ c ∧ Neg v ∉ c :=\nbegin\n  intro h,\n  contrapose,\n  rw not_and_distrib,\n  simp only [not_not],\n  intro hv,\n  exact mem_of_mem_explode_of_mem_vars h \n    (mem_vars_iff_pos_or_neg_mem_clause.mpr hv)\nend\n\n-- If the variables in a clause match the input to explode, then it's in explode\ntheorem map_var_eq_iff_mem_explode : c.map var = l ↔ c ∈ explode l :=\nbegin\n  induction l with v vs ih generalizing c,\n  { simp only [map_eq_nil, explode_nil, mem_singleton] },\n  { split,\n    { intro h,\n      rcases exists_cons_of_map_cons h with ⟨l, ls, rfl, hl, hls⟩,\n      cases l; simp only [explode, mem_append, mem_map],\n      { rw var at hl, subst hl, left, use [ls, ih.mp hls] },\n      { rw var at hl, subst hl, right, use [ls, ih.mp hls] } },\n    { simp only [explode, mem_map, mem_append],\n      rintros (⟨a, ha, rfl⟩ | ⟨a, ha, rfl⟩);\n      { simp only [ih.mpr ha, var, map, eq_self_iff_true, and_self] } } }\nend\n\n/-! # nodup properties of explode -/\n\ntheorem explode_nodup (l : list V) : nodup (explode l) :=\nbegin\n  induction l with v vs ih,\n  { rw explode_nil, exact nodup_singleton nil },\n  { simp only [explode, nodup_cons, nodup_append, (nodup_map_iff (cons_injective)).mpr ih, true_and],\n    intros x hxp hxn,\n    rcases mem_map.mp hxp with ⟨c, _, rfl⟩,\n    rcases mem_map.mp hxn with ⟨d, _, h⟩,\n    have := head_eq_of_cons_eq h,\n    contradiction }\nend\n\ntheorem nodup_of_nodup_of_mem (h : nodup l) : c ∈ explode l → nodup c :=\nbegin\n  induction l with n ns ih generalizing c,\n  { rw [explode_nil, mem_singleton], rintro rfl, exact nodup_nil },\n  { simp only [explode, mem_append, mem_map],\n    rintro (⟨a, ha, rfl⟩ | ⟨a, ha, rfl⟩);\n    rw nodup_cons;\n    have := pos_and_neg_not_mem_of_mem_explode_of_not_mem ha ((nodup_cons.mp h).1),\n    { exact ⟨this.1, ih (nodup_cons.mp h).2 ha⟩ },\n    { exact ⟨this.2, ih (nodup_cons.mp h).2 ha⟩ } }\nend\n\ntheorem xor_pos_neg_mem_clause_of_nodup_of_mem_explode_of_mem (h : nodup l) :\n  c ∈ explode l → v ∈ l → xor (Pos v ∈ c) (Neg v ∈ c) :=\nbegin\n  induction l with v vs ih generalizing c,\n  { intros _ h, exact absurd h (not_mem_nil _) },\n  { simp only [explode, mem_append, mem_map],\n    rintros (⟨a, ha, rfl⟩ | ⟨a, ha, rfl⟩) hc;\n    { rcases eq_or_mem_of_mem_cons hc with (rfl | hv),\n      { simp [pos_and_neg_not_mem_of_mem_explode_of_not_mem ha (nodup_cons.mp h).1] },\n      { rcases ih (nodup_cons.mp h).2 ha hv with ⟨hp, hn⟩ | ⟨hp, hn⟩;\n        { simp [hp, hn, ne_of_mem_of_not_mem hv (nodup_cons.mp h).1] } } } }\nend\n\nend explode", "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/explode.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7671144915783972}}
{"text": "-- Conectivas y desigualdades \n-- ==========================\n\n-- En esta relación se formulan algunas de las \n-- anteriores propiedades de las desigualdades de los \n-- números reales formuladas con conectivas.\n\nimport data.real.basic\n\nvariables (a b c : ℝ)\n\n-- Ej1. Demostrar que\n--    0 ≤ a → b ≤ a + b\n\n-- 1ª demostración\n-- ===============\n\nexample : 0 ≤ a → b ≤ a + b :=\nbegin\n  intro ha,\n  exact le_add_of_nonneg_left ha,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : 0 ≤ a → b ≤ a + b :=\nle_add_of_nonneg_left\n\n-- 3ª demostración\n-- ===============\n\nexample : 0 ≤ a → b ≤ a + b :=\nby finish\n\n-- Ej2. Demostrar que\n--    0 ≤ b → a ≤ a + b\n\n-- 1ª demostración\n-- ===============\n\nexample: 0 ≤ b → a ≤ a + b :=\nbegin\n  intro hb,\n  exact le_add_of_nonneg_right hb,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample: 0 ≤ b → a ≤ a + b :=\nle_add_of_nonneg_right\n\n-- 3ª demostración\n-- ===============\n\nexample: 0 ≤ b → a ≤ a + b :=\nby finish\n\n-- Ej3. Demostrar que\n--    (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b\n\n-- 1ª demostración\n-- ===============\n\nexample : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b :=\nbegin\n  intros hab,\n  cases hab with ha hb,\n  exact add_nonneg ha hb,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b :=\nbegin\n  rintros ⟨ha, hb⟩,\n  exact add_nonneg ha hb,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b :=\nλ ⟨ha, hb⟩, add_nonneg ha hb\n\n-- Ej4. Demostrar que\n--    0 ≤ a → (0 ≤ b → 0 ≤ a + b)\n\n-- 1ª demostración\n-- ===============\n\nexample : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) := \nbegin\n  intro ha,\n  intro hb,\n  exact add_nonneg ha hb,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) := \nbegin\n  intros ha hb,\n  exact add_nonneg ha hb,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) := \nλ ha hb, add_nonneg ha hb\n\n-- 4ª demostración\n-- ===============\n\nexample : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) := \nadd_nonneg\n\n-- 5ª demostración\n-- ===============\n\nexample : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) := \nby intros ; linarith \n\n-- Ej5. Demostrar que si\n--   (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b\n-- entonces \n--   0 ≤ a → (0 ≤ b → 0 ≤ a + b)\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) \n  : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=\nbegin\n  intro ha,\n  intro hb,\n  apply H,\n  split,\n  { exact ha, },\n  { exact hb, },\nend\n\n-- 2ª demostración\n-- ===============\n\nexample \n  (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) \n  : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=\nbegin\n  intros ha hb,\n  apply H,\n  split,\n  { exact ha, },\n  { exact hb, },\nend\n\n-- 3ª demostración\n-- ===============\n\nexample \n  (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) \n  : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=\nbegin\n  intros ha hb,\n  exact H ⟨ha, hb⟩,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample \n  (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) \n  : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=\nλ ha hb, H ⟨ha, hb⟩\n\n-- 5ª demostración\n-- ===============\n\nexample \n  (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) \n  : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=\nby tauto\n\n-- 6ª demostración\n-- ===============\n\nexample \n  (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) \n  : 0 ≤ a → (0 ≤ b → 0 ≤ 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_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7671144868067975}}
{"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ël 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* `nat.factorial`: The factorial.\n* `nat.asc_factorial`: 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.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 : ℕ → ℕ\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 : ℕ}\n\n@[simp] theorem factorial_zero : 0! = 1 := rfl\n\n@[simp] theorem factorial_succ (n : ℕ) : 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) ▸ rfl\n\ntheorem factorial_pos : ∀ n, 0 < n!\n| 0        := zero_lt_one\n| (succ n) := mul_pos (succ_pos _) (factorial_pos n)\n\ntheorem factorial_ne_zero (n : ℕ) : n! ≠ 0 := ne_of_gt (factorial_pos _)\n\ntheorem factorial_dvd_factorial {m n} (h : m ≤ n) : m! ∣ n! :=\nbegin\n  induction n with n IH,\n  { simp [nat.eq_zero_of_le_zero h] },\n  obtain rfl | hl := h.eq_or_lt,\n  { simp },\n  exact (IH (le_of_lt_succ hl)).mul_left _,\nend\n\ntheorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ 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 ≤ n) : m! ≤ n! :=\nle_of_dvd (factorial_pos _) (factorial_dvd_factorial h)\n\nlemma factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m! * m.succ ^ n ≤ (m + n)!\n| m 0     := by simp\n| m (n+1) :=\nby  rw [← add_assoc, nat.factorial_succ, mul_comm (nat.succ _), pow_succ', ← 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 := λ n m, factorial_le\n\n\n\nlemma one_lt_factorial : 1 < n! ↔ 1 < n :=\nfactorial_lt one_pos\n\nlemma factorial_eq_one : n! = 1 ↔ n ≤ 1 :=\nbegin\n  refine ⟨λ h, _, by rintro (_ | ⟨_, _ | _⟩); refl⟩,\n  rw [← not_lt, ← one_lt_factorial, h],\n  apply lt_irrefl\nend\n\nlemma factorial_inj (hn : 1 < n!) : n! = m! ↔ n = m :=\nbegin\n  refine ⟨λ h, _, congr_arg _⟩,\n  obtain hnm | rfl | hnm := lt_trichotomy n m,\n  { rw [← factorial_lt $ pos_of_gt $ one_lt_factorial.mp hn, h] at hnm,\n    cases lt_irrefl _ hnm },\n  { refl },\n  rw [h, one_lt_factorial] at hn,\n  rw [←factorial_lt (lt_trans one_pos hn), h] at hnm,\n  cases lt_irrefl _ hnm\nend\n\nlemma self_le_factorial : ∀ n : ℕ, n ≤ 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 : ℕ} (hi : 3 ≤ n) : n < n! :=\nbegin\n  rw [← 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 : ℕ} (n : ℕ) (hi : 2 ≤ i) :\n  i + (n + 1)! < (i + n + 1)! :=\nbegin\n  rw [factorial_succ (i + _), add_mul, one_mul],\n  have : i ≤ 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 ⟨(i + n).factorial_pos, λ g,\n    nat.not_succ_le_self 1 ((hi.trans this).trans (factorial_eq_one.mp g.symm))⟩))) (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 : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ 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 : ℕ) (n : ℕ) :\n  i + (n + 1)! ≤ (i + (n + 1))! :=\nbegin\n  obtain i2 | (_ | ⟨_, i0⟩) := le_or_lt 2 i,\n  { exact (n.add_factorial_succ_lt_factorial_add_succ i2).le },\n  { rw [←add_assoc, factorial_succ (1 + n), 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 : ℕ) {n : ℕ} (n1 : 1 ≤ n) :\n  i + n! ≤ (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 : ℕ} (hnm : n ≤ m) : n! * n ^ (m - n) ≤ m! :=\nbegin\n  suffices : n! * (n + 1) ^ (m - n) ≤ 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 : ℕ) : ℕ → ℕ\n| 0 := 1\n| (k + 1) := (n + k + 1) * asc_factorial k\n\n@[simp] lemma asc_factorial_zero (n : ℕ) : n.asc_factorial 0 = 1 := rfl\n\n@[simp] lemma zero_asc_factorial (k : ℕ) : (0 : ℕ).asc_factorial k = k! :=\nbegin\n  induction k with t ht,\n  { refl },\n  rw [asc_factorial, ht, zero_add, nat.factorial_succ],\nend\n\nlemma asc_factorial_succ {n k : ℕ} : n.asc_factorial k.succ = (n + k + 1) * n.asc_factorial k := rfl\n\nlemma succ_asc_factorial (n : ℕ) :\n  ∀ 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  ←add_assoc]\n\n/-- `n.asc_factorial k = (n + k)! / n!` but without ℕ-division. See `nat.asc_factorial_eq_div` for\nthe version with ℕ-division. -/\ntheorem factorial_mul_asc_factorial (n : ℕ) : ∀ 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, ← add_assoc,\n  factorial]\n\n/-- Avoid in favor of `nat.factorial_mul_asc_factorial` if you can. ℕ-division isn't worth it. -/\nlemma asc_factorial_eq_div (n k : ℕ) : n.asc_factorial k = (n + k)! / n! :=\nbegin\n  apply mul_left_cancel₀ n.factorial_ne_zero,\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 : ℕ} (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 [←ht, h', succ_asc_factorial, asc_factorial_succ],\n  rw [ht, succ_eq_add_one, ←tsub_tsub_assoc (succ_le_of_lt h) (succ_pos _), succ_sub_one],\nend\n\nlemma pow_succ_le_asc_factorial (n : ℕ) : ∀ (k : ℕ), (n + 1)^k ≤ 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 : ℕ) : (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 : ℕ) : ∀ {k : ℕ}, 2 ≤ k → (n + 1)^k < n.asc_factorial k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨_, ⟨⟩⟩)\n| (k + 2) := λ _, pow_lt_asc_factorial' n k\n\nlemma asc_factorial_le_pow_add (n : ℕ) : ∀ (k : ℕ), n.asc_factorial k ≤ (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 : ℕ) : ∀ {k : ℕ}, 2 ≤ k → n.asc_factorial k < (n + k)^k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨_, ⟨⟩⟩)\n| (k + 2) := λ _, begin\n  rw [asc_factorial_succ, pow_succ],\n  refine nat.mul_lt_mul' le_rfl ((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 : ℕ) : 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 : ℕ) : ℕ → ℕ\n| 0 := 1\n| (k + 1) := (n - k) * desc_factorial k\n\n@[simp] lemma desc_factorial_zero (n : ℕ) : n.desc_factorial 0 = 1 := rfl\n\n@[simp] lemma desc_factorial_succ (n k : ℕ) :\n  n.desc_factorial k.succ = (n - k) * n.desc_factorial k := rfl\n\nlemma zero_desc_factorial_succ (k : ℕ) :\n  (0 : ℕ).desc_factorial k.succ = 0 :=\nby rw [desc_factorial_succ, zero_tsub, zero_mul]\n\n@[simp] lemma desc_factorial_one (n : ℕ) :\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 : ℕ) :\n  ∀ k : ℕ, (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 : ℕ) :\n  ∀ 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 : ∀ n : ℕ, 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 : ℕ} : ∀ {k : ℕ}, n.desc_factorial k = 0 ↔ 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 λ h _, h,\nend\n\nalias nat.desc_factorial_eq_zero_iff_lt ↔ _ nat.desc_factorial_of_lt\n\nlemma add_desc_factorial_eq_asc_factorial (n : ℕ) :\n  ∀ k : ℕ, (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 ℕ-division. See `nat.desc_factorial_eq_div`\nfor the version using ℕ-division. -/\ntheorem factorial_mul_desc_factorial : ∀ {n k : ℕ}, k ≤ n → (n - k)! * n.desc_factorial k = n!\n| n        0        := λ _, by rw [desc_factorial_zero, mul_one, tsub_zero]\n| 0        (succ k) := λ h, by { exfalso, exact not_succ_le_zero k h }\n| (succ n) (succ k) := λ h, by rw [succ_desc_factorial_succ, succ_sub_succ, ←mul_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. ℕ-division isn't worth it. -/\nlemma desc_factorial_eq_div {n k : ℕ} (h : k ≤ n) : n.desc_factorial k = n! / (n - k)! :=\nbegin\n  apply mul_left_cancel₀ (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 : ℕ) : ∀ (k : ℕ), (n + 1 - k)^k ≤ 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 : ℕ} :\n  ∀ {k : ℕ}, k + 2 ≤ n → (n - (k + 1))^(k + 2) < n.desc_factorial (k + 2)\n| 0 := λ 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) := λ 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 : ℕ} :\n  ∀ {k : ℕ}, 2 ≤ k → k ≤ n → (n + 1 - k)^k < n.desc_factorial k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨_, ⟨⟩⟩)\n| (k + 2) := λ _ h, by { rw succ_sub_succ, exact pow_sub_lt_desc_factorial' h }\n\nlemma desc_factorial_le_pow (n : ℕ) : ∀ (k : ℕ), n.desc_factorial k ≤ 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 : ℕ} (hn : 1 ≤ n) : ∀ {k : ℕ}, 2 ≤ k → n.desc_factorial k < n^k\n| 0 := by rintro ⟨⟩\n| 1 := by rintro (_ | ⟨_, ⟨⟩⟩)\n| (k + 2) := λ _, 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": "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/factorial/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.767114482447078}}
{"text": "import .love06_monads_demo\n\n\n/-! # LoVe Homework 6: Monads\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): Better Exceptions\n\nThe __error monad__ is a monad stores either a value of type `α` or an error of\ntype `ε`. This corresponds to the following type: -/\n\ninductive error (ε α : Type) : Type\n| good : α → error\n| bad  : ε → error\n\n/-! The error monad generalizes the option monad seen in the lecture. The `good`\nconstructor, corresponding to `option.some`, stores the current result of the\ncomputation. But instead of having a single bad state `option.none`, the error\nmonad has many bad states of the form `bad e`, where `e` is an \"exception\" of\ntype `ε`.\n\n1.1 (1 point). Implement a variant of `list.nth` that returns an error\nmessage of the form \"index _i_ out of range\" instead of `option.none` on\nfailure.\n\nHint: For this, you will only need pattern matching (no `do` syntax). -/\n\n#check list.nth\n\ndef list.nth_error {α : Type} (as : list α) (i : ℕ) : error string α :=\nmatch list.nth as i with\n| option.none     := error.bad (\"index \" ++ nat.repr i ++ \" out of range\")\n| (option.some a) := error.good a\nend\n\n/-! 1.2 (1 point). Complete the definitions of the `pure` and `bind` operations\non the error monad: -/\n\ndef error.pure {ε α : Type} : α → error ε α :=\nerror.good\n\ndef error.bind {ε α β : Type} : error ε α → (α → error ε β) → error ε β\n| (error.good a) f := f a\n| (error.bad e)  f := error.bad e\n\n/-! The following type class instance makes it possible to use `>>=` and `do`\nnotations in conjunction with error monads: -/\n\n@[instance] def error.monad {ε : Type} : monad (error ε) :=\n{ pure := @error.pure ε,\n  bind := @error.bind ε }\n\n/-! 1.3 (2 point). Prove the three laws for the error monad. -/\n\nlemma error.pure_bind {ε α β : Type} (a : α) (f : α → error ε β) :\n  (pure a >>= f) = f a :=\nby refl\n\nlemma error.bind_pure {ε α : Type} (ma : error ε α) :\n  (ma >>= pure) = ma :=\nbegin\n  cases' ma with a e,\n  { refl },\n  { refl }\nend\n\nlemma error.bind_assoc {ε α β γ : Type} (f : α → error ε β) (g : β → error ε γ)\n    (ma : error ε α) :\n  ((ma >>= f) >>= g) = (ma >>= (λa, f a >>= g)) :=\nbegin\n  cases' ma with a e,\n  { refl },\n  { refl }\nend\n\n/-! 1.4 (1 point). Define the following two operations on the error monad.\n\nThe `throw` operation raises an exception `e`, leaving the monad in a bad state\nstoring `e`.\n\nThe `catch` operation can be used to recover from an earlier exception. If the\nmonad is currently in a bad state storing `e`, `catch` invokes some\nexception-handling code (the second argument to `catch`), passing `e` as\nargument; this code might in turn raise a new exception. If `catch` is applied\nto a good state, nothing happens—the monad remains in the good state. As a\nconvenient alternative to `error.catch ma g`, Lean lets us write\n`ma.catch g`. -/\n\ndef error.throw {ε α : Type} : ε → error ε α :=\nerror.bad\n\ndef error.catch {ε α : Type} : error ε α → (ε → error ε α) → error ε α\n| (error.good a) g := error.good a\n| (error.bad e)  g := g e\n\n/-! 1.5 (1 point). Using `list.nth_error`, the monad operations on `error`, and\nthe special `error.catch` operation, write a `do` program that swaps the values\nat indexes `i` and `j` in the input list `as`. If either index is out of range,\nreturn `as` unchanged. -/\n\ndef list.swap {α : Type} (as : list α) (i j : ℕ) : error string (list α) :=\ndo {\n  a ← list.nth_error as i,\n  b ← list.nth_error as j,\n  pure (list.update_nth (list.update_nth as j a) i b) }\n.catch (λe,\n  pure as)\n\n#reduce list.swap [3, 1, 4, 1] 0 2   -- expected: error.good [4, 1, 3, 1]\n#reduce list.swap [3, 1, 4, 1] 0 7   -- expected: error.good [3, 1, 4, 1]\n\n\n/-! ## Question 2 (3 points + 1 bonus point): Properties of `mmap`\n\nWe will prove some properties of the `mmap` function introduced in the\nlecture's demo. -/\n\n#check mmap\n\n/-! 2.1 (1 point). Prove the following identity law about `mmap` for an\narbitrary monad `m`.\n\nHint: You will need the lemma `lawful_monad.pure_bind` in the induction step. -/\n\nlemma mmap_pure {m : Type → Type} [lawful_monad m] {α : Type} (as : list α) :\n  mmap (@pure m _ _) as = pure as :=\nbegin\n  induction' as,\n  { refl },\n  { simp [mmap, ih, lawful_monad.pure_bind] }\nend\n\n/-! Commutative monads are monads for which we can reorder actions that do not\ndepend on each others. Formally: -/\n\n@[class] structure comm_lawful_monad (m : Type → Type)\n  extends lawful_monad m : Type 1 :=\n(bind_comm {α β γ δ : Type} (ma : m α) (f : α → m β) (g : α → m γ)\n     (h : α → β → γ → m δ) :\n   (ma >>= (λa, f a >>= (λb, g a >>= (λc, h a b c)))) =\n   (ma >>= (λa, g a >>= (λc, f a >>= (λb, h a b c)))))\n\n/-! 2.2 (1 point). Prove that `option` is a commutative monad. -/\n\nlemma option.bind_comm {α β γ δ : Type} (ma : option α) (f : α → option β)\n    (g : α → option γ) (h : α → β → γ → option δ) :\n  (ma >>= λa, f a >>= λb, g a >>= λc, h a b c) =\n  (ma >>= λa, g a >>= λc, f a >>= λb, h a b c) :=\nbegin\n  cases' ma with a,\n  { refl },\n  { simp [bind, option.bind],\n    cases' f a,\n    { cases' g a,\n      { refl },\n      { refl } },\n    { refl } }\nend\n\n/-! 2.3 (1 point). Explain why `error` is not a commutative monad. -/\n\n/-! Consider the two `do` programs given in the statement of the `bind_comm`\nproperty. Suppose that `f` throws exception 42 and `g` throws exception 999.\nThen the first program below will throw 42, whereas the second program will\nthrow 999.\n\nLet us try it out: -/\n\ndef prog1 (n : ℕ) : error ℕ ℕ :=\ndo\n  a ← pure n,\n  b ← @error.throw _ ℕ 42,\n  c ← @error.throw _ ℕ 999,\n  pure (a + b + c)\n\ndef prog2 (n : ℕ) : error ℕ ℕ :=\ndo\n  a ← pure n,\n  c ← @error.throw _ ℕ 999,\n  b ← @error.throw _ ℕ 42,\n  pure (a + b + c)\n\n#reduce prog1 0   -- result: error.bad 42\n#reduce prog2 0   -- result: error.bad 999\n\n/-! 2.4 (1 bonus point). Prove the following composition law for `mmap`, which\nholds for commutative monads.\n\nHint: You will need structural induction. -/\n\nlemma mmap_mmap {m : Type → Type} [comm_lawful_monad m]\n    {α β γ : Type} (f : α → m β) (g : β → m γ) (as : list α) :\n  (mmap f as >>= mmap g) = mmap (λa, f a >>= g) as :=\nbegin\n  induction' as,\n  case nil {\n    simp [mmap, lawful_monad.pure_bind] },\n  case cons : a as ih {\n    simp [mmap],\n    rw ←ih,\n    simp [lawful_monad.pure_bind, lawful_monad.bind_assoc],\n    apply comm_lawful_monad.bind_comm }\nend\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/love06_monads_homework_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7670577706102765}}
{"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.big_operators.nat_antidiagonal\nimport data.polynomial.ring_division\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\nnamespace polynomial\nopen_locale polynomial\n\nsection semiring\n\nvariables {R : Type*} [semiring R] (p q : R[X])\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\n@[simp] lemma mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror]\n\nlemma mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = (monomial n a) :=\nbegin\n  classical,\n  by_cases ha : a = 0,\n  { rw [ha, monomial_zero_right, mirror_zero] },\n  { rw [mirror, reverse, nat_degree_monomial n a, if_neg ha, nat_trailing_degree_monomial ha,\n        ← C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, rev_at_le (le_refl n), tsub_self, pow_zero,\n        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 : R[X]) :=\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  nontriviality R,\n  rw [mirror, nat_degree_mul', reverse_nat_degree, nat_degree_X_pow,\n      tsub_add_cancel_of_le p.nat_trailing_degree_le_nat_degree],\n  rwa [leading_coeff_X_pow, mul_one, reverse_leading_coeff, ne, trailing_coeff_eq_zero]\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 : ℕ) :\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 ≤ p.nat_degree + p.nat_trailing_degree,\n    { rw [rev_at_le h1, coeff_eq_zero_of_lt_nat_trailing_degree],\n      exact (tsub_lt_iff_left h1).mpr (nat.add_lt_add_right h2 _) },\n    { rw [←rev_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 ≤ n,\n  { rw [←tsub_add_eq_add_tsub h2, ←tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow',\n        if_pos h3, coeff_reverse, rev_at_le (tsub_le_self.trans h2)] },\n  rw not_le at h3,\n  rw coeff_eq_zero_of_nat_degree_lt (lt_tsub_iff_right.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 (λ n, by rw [coeff_mirror, coeff_mirror,\n  mirror_nat_degree, mirror_nat_trailing_degree, rev_at_invol])\n\nvariables {p q}\n\nlemma mirror_involutive : function.involutive (mirror : R[X] → R[X]) :=\nmirror_mirror\n\nlemma mirror_eq_iff : p.mirror = q ↔ p = q.mirror :=\nmirror_involutive.eq_iff\n\n@[simp] lemma mirror_inj : p.mirror = q.mirror ↔ p = q :=\nmirror_involutive.injective.eq_iff\n\n@[simp] lemma mirror_eq_zero : p.mirror = 0 ↔ p = 0 :=\n⟨λ h, by rw [←p.mirror_mirror, h, mirror_zero], λ h, by rw [h, mirror_zero]⟩\n\nvariables (p q)\n\n@[simp] lemma 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 _ _), add_tsub_cancel_right]\n\n@[simp] lemma mirror_leading_coeff : p.mirror.leading_coeff = p.trailing_coeff :=\nby rw [←p.mirror_mirror, mirror_trailing_coeff, p.mirror_mirror]\n\nlemma coeff_mul_mirror :\n  (p * p.mirror).coeff (p.nat_degree + p.nat_trailing_degree) = p.sum (λ n, (^ 2)) :=\nbegin\n  rw [coeff_mul, finset.nat.sum_antidiagonal_eq_sum_range_succ_mk],\n  refine (finset.sum_congr rfl (λ n hn, _)).trans (p.sum_eq_of_subset (λ n, (^ 2))\n    (λ n, zero_pow zero_lt_two) _ (λ n hn, finset.mem_range_succ_iff.mpr\n    ((le_nat_degree_of_mem_supp n hn).trans (nat.le_add_right _ _)))).symm,\n  rw [coeff_mirror, ←rev_at_le (finset.mem_range_succ_iff.mp hn), rev_at_invol, ←sq],\nend\n\nvariables [no_zero_divisors R]\n\nlemma nat_degree_mul_mirror : (p * p.mirror).nat_degree = 2 * p.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, zero_mul, nat_degree_zero, mul_zero] },\n  rw [nat_degree_mul hp (mt mirror_eq_zero.mp hp), mirror_nat_degree, two_mul],\nend\n\nlemma nat_trailing_degree_mul_mirror :\n  (p * p.mirror).nat_trailing_degree = 2 * p.nat_trailing_degree :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, zero_mul, nat_trailing_degree_zero, mul_zero] },\n  rw [nat_trailing_degree_mul hp (mt mirror_eq_zero.mp hp), mirror_nat_trailing_degree, two_mul],\nend\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [ring R] (p q : R[X])\n\nlemma mirror_neg : (-p).mirror = -(p.mirror) :=\nby rw [mirror, mirror, reverse_neg, nat_trailing_degree_neg, neg_mul_eq_neg_mul]\n\nvariables [no_zero_divisors R]\n\nlemma mirror_mul_of_domain : (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  rw [mul_assoc, ←mul_assoc q.reverse],\n  conv_lhs { congr, skip, congr, rw [←X_pow_mul] },\n  repeat { rw [mul_assoc], },\nend\n\nlemma mirror_smul (a : R) : (a • p).mirror = a • p.mirror :=\nby rw [←C_mul', ←C_mul', mirror_mul_of_domain, mirror_C]\n\nend ring\n\nsection comm_ring\n\nvariables {R : Type*} [comm_ring R] [no_zero_divisors R] {f : R[X]}\n\nlemma irreducible_of_mirror (h1 : ¬ is_unit f)\n  (h2 : ∀ k, f * f.mirror = k * k.mirror → k = f ∨ k = -f ∨ k = f.mirror ∨ k = -f.mirror)\n  (h3 : ∀ g, g ∣ f → g ∣ f.mirror → 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, ←mul_assoc] },\n    have g_dvd_f : g ∣ f,\n    { rw fgh,\n      exact dvd_mul_right g h },\n    have h_dvd_f : h ∣ f,\n    { rw fgh,\n      exact dvd_mul_left h g },\n    have g_dvd_k : g ∣ k,\n    { exact dvd_mul_right g h.mirror },\n    have h_dvd_k_rev : h ∣ 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 ← hk)) },\n    { exact or.inr (h3 h h_dvd_f (by rwa [← neg_eq_iff_eq_neg.mpr hk, mirror_neg, dvd_neg])) },\n    { exact or.inl (h3 g g_dvd_f (by rwa ← hk)) },\n    { exact or.inl (h3 g g_dvd_f (by rwa [← neg_eq_iff_eq_neg.mpr hk, dvd_neg])) } },\nend\n\nend comm_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/mirror.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.767057765142792}}
{"text": "-- Razonamiento con tipos abreviados: Posiciones\n-- =============================================\n\nimport tactic\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir el tipo Pos como una abreviatura\n-- de pares de enteros para representar posiciones.\n-- ----------------------------------------------------\n\n-- 1ª definición\n-- abbreviation Pos : Type := ℤ × ℤ\n\n-- 2ª definición\n-- notation `Pos` := ℤ × ℤ\n\n-- 3ª definición\n-- local notation `Pos` := ℤ × ℤ\n\n-- 4ª definición\ndef Pos := ℤ × ℤ\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Definir la posición origen.\n-- ----------------------------------------------------\n\ndef origen : Pos :=\n(0,0)\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Definir la función\n--    izquierda : Pos → Pos\n-- tal que (izquierda p) esla posición que se encuentra\n-- a la izquierda de p. Por ejemplo,\n--    izquierda (3,5) = (2,5)\n-- ----------------------------------------------------\n\n-- 1ª definición\n@[simp]\ndef izquierda : Pos → Pos :=\nλ ⟨x,y⟩, (x-1,y)\n\n-- 2ª definición\n@[simp]\ndef izquierda_2 : Pos → Pos\n| (x,y) := (x-1,y)\n\n-- #eval izquierda (3,5)\n-- Da: (2,5)\n\n-- ----------------------------------------------------\n-- Ejercicio 4. Definir la función\n--    derecha : Pos → Pos\n-- tal que (derecha p) esla posición que se encuentra\n-- a la derecha de p. Por ejemplo,\n--    derecha (3,5) = (4,5)\n-- ----------------------------------------------------\n\n-- 1ª definición\n@[simp]\ndef derecha : Pos → Pos :=\nλ ⟨x,y⟩, (x+1,y)\n\n-- 2ª definición\n@[simp]\ndef derecha_2 : Pos → Pos\n| (x,y) := (x+1,y)\n\n-- #eval derecha (3,5)\n-- Da: (4, 5)\n\n-- ----------------------------------------------------\n-- Ejercicio 5. Demostrar que para cualquier posición p,\n--    izquierda (derecha p) = p\n-- ----------------------------------------------------\n\n-- 1ª demostración\nlemma izquierda_derecha :\n  ∀ p : Pos, izquierda (derecha p) = p\n| (x,y) := by calc izquierda (derecha (x, y))\n                   = izquierda (x+1, y)       :by simp\n               ... = (x+1-1, y)               :by simp\n               ... = (x, y)                   :by simp\n\n-- 2ª demostración\nlemma izquierda_derecha_2 :\n  ∀ p : Pos, izquierda (derecha p) = p :=\nλ ⟨x,y⟩, by simp\n\n-- ----------------------------------------------------\n-- Ejercicio 6. Definir el tipo Movimiento para\n-- representar los movimientos com funciones desde la\n-- posición inicial a la final.\n-- ----------------------------------------------------\n\ndef Movimiento : Type := Pos → Pos\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_abreviados:_Posiciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201267, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.767057765142792}}
{"text": "import lib.m154\n\nnamespace m154\nopen nat M154\n/-\n# Equivalences \n\nCe fichier aborde l'étude du connecteur logique `↔` (équivalence logique, notée ⇔ sur papier).\nL'énoncé `P ↔ Q` si lit « `P` est vrai si et seulement si `Q` est vrai ».\nIl affirme donc à la fois `P → Q` et `Q → P`.\n\nPour démontrer une équivalence par double implication on utilise\n`Montrons que` suivi de l'implication directe.\nUne fois celle-ci démontrée, on peut utiliser\n`Montrons que` suivi de l'implication inverse, mais ce n'est pas obligatoire.\n-/\n\n-- Dans toute la suite, x, a, b, c et d désignent des nombres réels.\nvariables {x a b c d : ℝ}\n\n\n/- Les lemmes `inferieur_diff_pos` et `diff_pos_inferieur` se combinent \nen une équivalence. -/\n\nlemma inferieur_pos_ssi (x y : ℝ) : x ≤ y ↔ 0 ≤ y - x :=\nbegin\n  Montrons que x ≤ y → 0 ≤ y - x,\n  On conclut par inferieur_diff_pos,\n  Montrons que 0 ≤ y - x → x ≤ y,\n  On conclut par diff_pos_inferieur,\nend\n\n/-\nFaites de même avec `inferieur_add_gauche` et `inferieur_simpl_gauche`.\n-/\n\nlemma inferieur_add_gauche_ssi : a ≤ b ↔ c + a ≤ c + b :=\nbegin\n  sorry\nend\n\n/-\nPour utiliser une équivalence on peut accéder aux deux implications de façons complètement\nanalogue au connecteur `∧`, avec `Par ... on obtient ...` ou via le suffixe\n`.1` pour l'implication de gauche à droite et `.2` pour l'autre sens.\n\nVérifions par exemple que le lemme ci-dessus permet de retrouver l'énoncé `inferieur_add_gauche`.\n-/\n\nexample (h : a ≤ b) : c + a ≤ c + b :=\nbegin\n  Par inferieur_add_gauche_ssi on obtient \n    (imp₁ : a ≤ b → c + a ≤ c + b) (imp₂ : c + a ≤ c + b → a ≤ b),\n  On conclut par imp₁ appliqué à h,\nend\n\n/- Ou de façon plus concise. -/\n\nexample (h : a ≤ b) : c + a ≤ c + b :=\nbegin\n  On conclut par inferieur_add_gauche_ssi.1 appliqué à h,\nend\n\nexample (h : 2 + a ≤ 2 + b) : a ≤ b :=\nbegin\n  sorry\nend\n\n/-\nOn peut également utiliser une équivalence pour réécrire le but ou une hypothèse, \nde même qu'une égalité peut servir à réécrire le but ou une hypothèse. La syntaxe est\nla même que pour les égalités.\n\nPar exemple, l'équivalence donnée par\n\n`abs_inferieur_ssi : |x| ≤ y ↔ -y ≤ x ∧ x ≤ y`\n\nest utilisée pour réécrire l'hypothèse `h` dans la démonstration suivante.\n-/\n\nexample (h : |a| ≤ 1) : a ≤ 1 :=\nbegin\n  On réécrit via abs_inferieur_ssi dans h,\n  On conclut par h.2,\nend\n\nexample (h : |a| ≤ 1) : -1 ≤ a :=\nbegin\n  sorry\nend\n\n\n/-\n## Exercice de synthèse sur =, →, ∧, ↔\n\nOn a la relation de divisibilité sur les entiers naturels :\n`a ∣ b` si `b` est un multiple de `a`. Attention la barre verticale n'est pas celle du\nclavier mais s'obtient par ,|\n\nCette relation est réflexive et antisymétrique, c'est à dire qu'on a les deux énoncés :\n`divise_refl (a : ℕ) : a ∣ a`\net\n`divise_antisym {a b : ℕ} (h: a ∣ b) (h' : b ∣ a) : a = b`\n\nDe plus on a une fonction `pgcd` qui, à deux entiers naturels associde un troisième entier\n(leur plus grand diviseur commun). Cette fonction est liée à la relation\nde divisibilité par :\n\n`divise_pgcd_ssi {a b c : ℕ} : c ∣ pgcd a b ↔ c ∣ a ∧ c ∣ b`\n\nDans l'exercice suivant, le jeu est de n'utiliser que ces trois énoncés, sans essayer\nde faire avouer à Lean la définition de la divisibilité ou du pgcd.\n\nCet exercice est plus difficile que les exercices rencontrés jusqu'ici et nécessite \nde combiner beaucoup de manipulations logiques.\n-/\n\nexample (a b : ℕ) : a ∣ b ↔ pgcd a b = a :=\nbegin\n  sorry\nend\n\nend m154\n\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/04_equivalence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.896251362048962, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7670577611234589}}
{"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\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] →ₗ[R] R[X] :=\n{ to_fun := λ 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, 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 [← C_1, taylor_C]\n\n@[simp] lemma taylor_monomial (i : ℕ) (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 : ℕ) : (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, ← C_eq_nat_cast, mul_assoc, ← C_pow, ← 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\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 (λ i a, C a * (X - C r) ^ i) = f :=\nby rw [←comp_eq_sum_left, sub_eq_add_neg, ←C_neg, ←taylor_apply, taylor_taylor, neg_add_self,\n       taylor_zero]\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/taylor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7670577569046482}}
{"text": "import .love02_backward_proofs_demo\n\n\n/- # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nsorry\n\nlemma K (a b : Prop) :\n  a → b → b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nsorry\n\n/- Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nsorry\n\n/- 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nsorry\n\n/- 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nsorry\n\n\n/- ## Question 2: Natural Numbers\n\n2.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nsorry\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nsorry\n\n/- 2.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nsorry\n\n/- 2.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nsorry\n\n\n/- ## Question 3 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation :=\n∀a : Prop, (¬¬ a) → a\n\n/- For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, because this would defeat the purpose of the exercise.\n\n3.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nsorry\n\n/- 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nsorry\n\n/- We leave the missing implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.767022498723384}}
{"text": "import data.set.lattice\n\n/- Good work!\n90/90 Correctness\n10/10 Style\n-/\n\n\n/- This assignment is due by 11:59pm on Friday, March 3, 2023 . -/\n\n/-\nEXERCISE 1.\n\nA function `F : set α → set α` is called a *monotone operator* if for every\npair of sets `s ⊆ t`, we have `F s ⊆ F t`.\n\nEvery such operator has a *least fixed point*, i.e. a set `s` satisfying:\n- `F s = s`\n- For every `t`, if `F t = t`, then `s ⊆ t`.\n\nThis exercise has you prove that fact. In fact, the least fixed point is\nthe intersection of all sets `s` such that `F s ⊆ s`.\n\nThis theorem, or the generalization to monotone operators on a complete lattice,\nis called *Tarski's theorem* or the *Knaster-Tarski Theorem*. Feel free to use\nGoogle to find more information.\n-/\nnamespace monotone_set_operator\nopen set\n\n-- You will need these. The full names are `set.mem_sInter`, etc.\n#check @mem_sInter\n#check @subset_sInter\n#check @subset_sInter_iff\n\nvariable {α : Type*}\n\ndef lfp (F : set α → set α) := ⋂₀ { t | F t ⊆ t }\n\nvariable {F : set α → set α}\n-- The monotonicity assumption:\nvariable (monoF : ∀ ⦃s t⦄, s ⊆ t → F s ⊆ F t)\n\n/-\nThis follows immediately from the definition of `lfp F`.\n-/\n-- Exercise 1a. [8pts]\nlemma aux0 {s : set α} (h : F s ⊆ s) : lfp F ⊆ s :=\nbegin\n  apply sInter_subset_of_mem,\n  exact h\nend\n\n/-\nAll the remaining theorems in this section need the monotonicity assumption.\nAfter you prove `aux1`, you have to write `aux1 monoF` to use it in a\nlater theorem.\n-/\ninclude monoF\n\n/-\nTo show this next statement, it suffices to show that `F (lfp F)` is contained\nin every set `t` such that `F t ⊆ t`. So suppose `t` has this property.\nThen by `aux0`, `lfp F ⊆ t`, and by monotonicity, we have `F (lfp F) ⊆ F t ⊆ t`.\n-/\n-- Exercise 1b. [10pts]\nlemma aux1 : F (lfp F) ⊆ lfp F :=\nbegin\n  apply subset_sInter,\n  intros t ht,\n  apply subset_trans _ ht,\n  apply monoF,\n  exact aux0 ht,\nend\n\n-- Hint: The remaining exercise 1 proofs below can be done in at most three\n-- lines each.\n\n/- To show this, use `aux0`. -/\n-- Exercise 1c. [5pts]\nlemma aux2 : lfp F ⊆ F (lfp F) :=\nbegin\n  apply aux0,\n  apply monoF,\n  exact aux1 monoF,\nend\n\n/- Follows from `aux1` and `aux2`. -/\n-- Exercise 1d. [5pts]\ntheorem lfp_fixed_point : F (lfp F) = lfp F :=\nbegin\n  apply subset_antisymm,\n  { -- F (lfp F) ⊆ lfp F\n    exact aux1 monoF },\n  { -- lfp F ⊆ F (lfp F)\n    exact aux2 monoF },\nend\n\n-- Exercise 1e. [5pts]\ntheorem lfp_least_fixed_point (s : set α) (h : F s = s) : lfp F ⊆ s :=\nbegin\n  apply aux0,\n  exact eq.subset h\nend\n\nend monotone_set_operator\n\n/-\nEXERCISE 2.\n\nA `complete lattice` is a partial order such that every subset has a greatest\nlower bound (`Inf`) and a least upper bound (`Sup`). In fact, the existence\nof either implies the other.\n\nThe proofs above carry over to this more general setting, if you replace\n`α` by `set α`, `⊆` by `≤`, `⋂₀` by `Inf`, and make some small adjustments\nto the proof.\n\nReally, start by cutting and pasting the proofs above.\n-/\n\nnamespace monotone_operator\n\n#check @le_Inf\n#check @le_Inf_iff\n#check @Inf_le\n\nvariables {α : Type*} [complete_lattice α]\n\ndef lfp (F : α → α) := Inf { s | F s ≤ s }\n\nvariables {F : α → α} (monoF : ∀ ⦃s t⦄, s ≤ t → F s ≤ F t)\n\n-- Exercise 2a. [5pts]\nlemma aux0 {s : α} (h : F s ≤ s) : lfp F ≤ s :=\nbegin\n  apply Inf_le,\n  exact h\nend\n\ninclude monoF\n\n-- Exercise 2b. [5pts]\nlemma aux1 : F (lfp F) ≤ lfp F :=\nbegin\n  apply le_Inf,\n  intros t ht,\n  apply le_trans,\n  { -- F (lfp F) ≤ F t\n    apply monoF,\n    apply aux0 ht },\n  { -- F t ≤ t\n    exact ht },\nend\n\n-- Exercise 2c. [3pts]\nlemma aux2 : lfp F ≤ F (lfp F) :=\nbegin\n  apply aux0,\n  apply monoF,\n  exact aux1 monoF,\nend\n\n-- Exercise 2d. [2pts]\ntheorem lfp_fixed_point : F (lfp F) = lfp F :=\nbegin\n  apply le_antisymm,\n  { -- F (lfp F) ≤ lfp F\n    exact aux1 monoF },\n  { -- lfp F ≤ F (lfp F)\n    exact aux2 monoF },\nend\n\n-- Exercise 2e. [2pts]\ntheorem lfp_least_fixed_point (s : α) (h : F s = s) : lfp F ≤ s :=\nbegin\n  apply aux0,\n  exact eq.le h\nend\n\nend monotone_operator\n\n/-\nEXERCISE 3.\n\nSuppose `A 0, A 1, A 2, ...` is a sequence of sets. For each `n`, suppose\n`B n = ⋃ i < n, A i`. Then the sequence `B 0, B 1, B 2, ...` is a monotone\nsequence with the same union.\n-/\n\nnamespace set_sequences\n\nvariable  {α : Type*}\nvariables (A B : ℕ → set α)\nvariable (B_def : ∀ n, B n = ⋃ i < n, A i)\n\n/-\nRemember, a (bounded) union corresponds to a (bounded) existential quantifier.\nUse the simplifier with `simp only [set.mem_Union]` to do the translation for\nyou. You can also write `simp only [set.mem_Union] at h` to simplify a\nhypothesis. You can also just use `simp`. However, mathlib conventions\ndiscourage \"non-terminal\" calls, i.e. ones which don't close a goal, to `simp`\nwithout `only`.\n-/\nexample (x : α) (n : ℕ) : (x ∈ ⋃ i < n, A i) ↔ ∃ i < n, x ∈ A i :=\n  by simp only [set.mem_Union]\n\n-- This might be helpful to you:\nexample (i : ℕ) : i < i + 1 := nat.lt_succ_self _\n\ninclude B_def\n\n-- Exercise 3a. [10pts]\ntheorem monotone_B : ∀ i j, i ≤ j → B i ⊆ B j :=\nbegin\n  intros,\n  rw B_def i,\n  rw B_def j,\n  apply set.Union_mono,\n  intro k,\n  apply set.Union_subset_Union_const,\n  intros,\n  apply lt_of_lt_of_le,\n  repeat { assumption },\nend\n\n-- Exercise 3b. [15pts]\ntheorem Union_B_eq_Union_A : (⋃ i, B i) = (⋃ i, A i) :=\nbegin\n  apply subset_antisymm,\n  { -- (⋃ i, B i) ⊆ (⋃ i, A i)\n    intro x,\n    rw [set.mem_Union, exists_imp_distrib],\n    intros _ hx,\n    rw [B_def, set.mem_Union] at hx,\n    cases hx with _ hx,\n    rw set.mem_Union at hx,\n    cases hx with _ hx,\n    apply set.mem_Union_of_mem,\n    exact hx, },\n  { -- (⋃ i, A i) ⊆ (⋃ i, B i)\n    apply set.Union_mono',\n    intros i,\n    use i + 1,\n    rw B_def,\n    repeat { apply set.subset_Union_of_subset },\n    apply nat.lt_succ_self,\n    refl },\nend\n\nend set_sequences\n\n/-\nEXERCISE 4.\n\nSuppose `A 0, A 1, A 2, ...` is a sequence of sets. For each `n`, suppose\n`C n = A n \\ (⋃ i < n, A i)`. Then whenever `i ≠ j`, the sets `C i` and `C j` are\ndisjoint, but the sequence still has the same union.\n-/\n\nnamespace set_sequences\n\nvariable  {α : Type*}\nvariables (A C : ℕ → set α)\nvariable (C_def : ∀ n, C n = A n \\ (⋃ i < n, A i))\n\n-- This may be useful.\n-- #check @set.eq_empty_of_forall_not_mem\n\n/-\nUse the lemma `aux` below to show that if `x` is in some `A i`, then there\nis a least `i` with that property.\n-/\nsection\nopen_locale classical\n\nlemma aux {A : ℕ → set α} {x : α} (h : ∃ i, x ∈ A i) :\n  ∃ i, x ∈ A i ∧ ∀ j < i, x ∉ A j :=\nsubtype.exists_of_subtype (nat.find_x h)\nend\n\ninclude C_def\n\n-- Exercise 4a. [10pts]\ntheorem disjoint_C_of_lt : ∀ i j, i < j → C i ∩ C j = ∅ :=\nbegin\n  intros,\n  rw [C_def, C_def, set.eq_empty_iff_forall_not_mem],\n  by_contra hx,\n  push_neg at hx,\n  rcases hx with ⟨x, ⟨⟨xinCi, _⟩, ⟨_, xinCj⟩⟩⟩,\n  apply xinCj,\n  repeat { apply set.mem_Union_of_mem <|> assumption },\nend\n\n-- Exercise 4b. [15pts]\ntheorem Union_C_eq_Union_A : (⋃ i, C i) = (⋃ i, A i) :=\nbegin\n  apply subset_antisymm,\n  { -- (⋃ i, C i) ⊆ (⋃ i, A i)\n    apply set.Union_mono,\n    intro i,\n    rw C_def,\n    apply set.diff_subset },\n  { -- (⋃ i, A i) ⊆ (⋃ i, C i)\n    intro x,\n    rw set.mem_Union,\n    intro xinUnionA,\n    rw set.mem_Union,\n    obtain ⟨i, ⟨xinAi, hj⟩⟩ := aux xinUnionA,\n    use i,\n    rw C_def,\n    split, { by exact xinAi },\n    by_contra h,\n    rw set.mem_Union at h,\n    cases h with j h,\n    rw set.mem_Union at h,\n    cases h,\n    apply hj,\n    repeat { assumption } },\nend\n\nend set_sequences", "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/assignment6/assignment6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.7670028462218037}}
{"text": "import tactic\n\n-- Этот файл переведен и адаптирован из второй недели курса Formalising Mathematics: https://github.com/ImperialCollegeLondon/formalising-mathematics/tree/master/src/week_2\n-- Там же есть продолжение про подгруппы, скачайте репозиторий с помощью\n-- `leanproject get ImperialCollegeLondon/formalising-mathematics`\n-- И самостоятельно пройдите то, что там есть \n\nnamespace itmo.lean\n\n/-\nОпределим группу как тайпкласс (подробнее: https://leanprover.github.io/theorem_proving_in_lean/type_classes.html), расширяющий `has_mul`, `has_one` и `has_inv`. \n\n`has_mul G` означает, что на `G` определено умножение `* : G → G → G`\n`has_one G` означает, что в `G` есть единица `1 : G`\n`has_inv G` означает, что есть функция, выдающая обратный для элемента `G`: `⁻¹ : G → G`\n\nВсе эти определения - просто нотация, свойства и взаимодействие этих функций надо будет добавить. Определим класс `group` с аксиомами групп:\n-/\n\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))\n(one_mul : ∀ (a : G), 1 * a = a)\n(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)\n\n/-\nФормально, `group G` это структура, в которой есть умножение, 1, обратный элемент, и доказательства аксиом групп. Поскольку `group G` это тайпкласс, то добавить в сигнатуру функции \"пусть `G` - группа\" нужно, как `(G : Type) [group G]`. Квадратные скобки используются для тайпклассов и автоматически (насколько получится) находятся соответствующие инстансы для `G`.\n\nОбратите внимание, что набор использованных аксиом минимален, например, нет аксиом \n`mul_one : ∀ (a : G), a * 1 = a` и \n`mul_right_inv : ∀ (a : G), a * a⁻¹ = 1`.\n\nНа самом деле, эти аксиомы следуют из основных, и мы это докажем.\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  sorry,\nend\n\n-- Доказательства из длинных цепочек равенств или неравенств часто можно заменить на `calc` (справка по `calc`: https://leanprover-community.github.io/extras/calc.html)\n-- Пример решения задачи с IMO 2020 с использованием `calc`: https://github.com/leanprover-community/mathlib/blob/master/archive/imo/imo2020_q2.lean\n\nexample (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin\n calc b = 1 * b         : by rw one_mul\n    ... = (a⁻¹ * a) * b : by rw ← mul_left_inv a\n    ... = a⁻¹ * (a * b) : by rw ← mul_assoc\n    ... = a⁻¹ * (a * c) : by rw Habac\n    ... = (a⁻¹ * a) * c : by rw ← mul_assoc\n    ... = 1 * c         : by rw mul_left_inv a\n    ... = c             : by rw one_mul,\nend\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=\nbegin\n  sorry,\nend\n\nvariables (a b c x y : G)\n\n/-\nПопробуйте начать доказательство с `apply mul_eq_of_eq_inv_mul`.\n-/\n\n@[simp] theorem mul_one : a * 1 = a :=\nbegin\n  sorry,\nend\n\n@[simp] theorem mul_right_inv : a * a⁻¹ = 1 :=\nbegin\n  sorry,\nend\n\n\n/-\n\nХорошей идеей было бы научить `simp` работать с леммами вида `A = B` или `A ↔ B`, которые мы описали выше. Для этого мы написали атрибут `@[simp]` перед леммой. В идеале, хочется, чтобы равенства в группах решались автоматически:\n\n`example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1`\n\nТактика `simp` будет пытаться \"упростить\" цель как можно больше, в идеале закрыть цель с помощью известных ей лемм. `simp` работает переписываниями, только используя переписывания слева направо (если хочется изменить направление, можно дать дополнительный аргумент `simp [← h] at ...`). Поэтому, в тождествах, помеченных `simp`, правая часть должна быть \"проще\", чем левая. В частности, `add_comm (a b : ℕ) : a + b = b + a` - плохая лемма для `simp`. Обратите внимание, что во всех леммах выше, например,\n\n`@[simp] theorem mul_one (a : G) : a * 1 = a`\n`@[simp] theorem mul_right_inv (a : G) : a * a⁻¹ = 1`\n\nправая часть проще левой. Помечать равенство  `a = a * 1` тегом `@[simp]` - плохая идея.\n\nУже определенным функциям (или определенным в другом файле) можно ретроспективно проставить атрибуты вручную.\n-/\n\nattribute [simp] one_mul mul_left_inv mul_assoc\n\n/-\nНаучим `simp` использовать следующие пять лемм: \n\n`inv_mul_cancel_left : a⁻¹ * (a * b) = b`\n`mul_inv_cancel_left : a * (a⁻¹ * b) = b`\n`inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹`\n`one_inv : (1 : G)⁻¹ = 1`\n`inv_inv : (a⁻¹)⁻¹ = a`\n\nОбратите внимание, что везде правая часть \"проще\" левой.\n-/\n\n@[simp] lemma inv_mul_cancel_left : a⁻¹ * (a * b) = b :=\nbegin\n  rw ← mul_assoc,\n  -- Здесь уже `simp` сможет переписать `a⁻¹ * a = 1` и `1 * b = b`\n  simp,\nend\n\n@[simp] lemma mul_inv_cancel_left : a * (a⁻¹ * b) = b :=\nbegin\n  sorry,\nend\n\n@[simp] lemma inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\nbegin\n  sorry,\nend\n\n@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=\nbegin\n  sorry,\nend\n\n@[simp] lemma inv_inv : a ⁻¹ ⁻¹ = a :=\nbegin\n  sorry,\nend\n\n/-\nЭти 5 лемм выбраны неспроста: это вывод алгоритма Кнута-Бендикса для переписываний в группе:\n\nhttps://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group\n-/\n\n-- Сложный пример теперь решается автоматически\nexample : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1 := by simp\n\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c⁻¹ :=\nbegin\n  sorry,\nend\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b⁻¹ * c :=\nbegin\n  sorry,\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b ↔ a = 1 :=\nbegin\n  sorry,\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a ↔ b = 1 :=\nbegin\n  sorry,\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b⁻¹ :=\ncalc  a = a * 1 : by rw mul_one\n    ... = b⁻¹   : by sorry\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a⁻¹ = b :=\nbegin\n  sorry,\nend\n\nlemma unique_left_id {e : G} (h : ∀ 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⁻¹ :=\nbegin\n  sorry,\nend\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y ↔ x = y :=\nbegin\n  sorry,\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  ... = y : by sorry\n\n@[simp] theorem inv_inj_iff {a b : G}: a⁻¹ = b⁻¹ ↔ a = b :=\nbegin\n  sorry,\nend   \n\ntheorem inv_eq {a b : G}: a⁻¹ = b ↔ b⁻¹ = a :=\nbegin\n  sorry,\nend  \n\nend group\n\nend itmo.lean\n\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/week04/e01_groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530492, "lm_q2_score": 0.8791467564270272, "lm_q1q2_score": 0.7669213765965128}}
{"text": "import game.world10.level4 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\n## Level 5: `le_trans`\n\nAnother straightforward one. \n-/\n\n\n/- Lemma\n≤ is transitive. In other words, if $a\\leq b$ and $b\\leq c$ then $a\\leq c$. \n-/\ntheorem le_trans (a b c : mynat) (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=\nbegin [nat_num_game]\n  cases hab with d hd,\n  cases hbc with e he,\n  use (d + e),\n  rw ←add_assoc,\n  rw ←hd,\n  assumption,\nend\n\n/-\nCongratulations -- you just got a collectible. You proved that the\nnatural numbers are a preorder.\n-/\ninstance : preorder mynat := by structure_helper\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/level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465116437761, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7668843675503786}}
{"text": "import data.set\nimport tactic\n\n-- dEAduction imports\nimport logics\nimport structures\nimport definitions\n\n-- import definitions_test\n\n\n----------------------------------------------\nnamespace set_theory -- Course title\n/- dEAduction\nSection\n    Set Theory\n-/\n\n\nvariables {X : Type} {Y : Type}\n\n\n\nlemma definition.inclusion (A B : set X) : A ⊆ B ↔ ∀ {{x:X}}, x ∈ A → x ∈ B := \niff.rfl\n\n\n\nlemma definition.egalite_ensembles {A A' : set X} : (A = A') ↔ ( ∀ x, x ∈ A ↔ x ∈ A' ) :=\n/- dEAduction\nPrettyName\n    Egalité d'ensembles    \n-/\nby exact set.ext_iff\n\nlemma theorem.double_inclusion {A A' : set X} : (A = A') ↔ (A ⊆ A' ∧ A' ⊆ A) :=\nbegin\n    exact le_antisymm_iff\nend\n\n\n----------------------------------------------\nnamespace unions_and_intersections -- section 1\n-- pretty name for dEAduction will be computed from lean name\n\n\nlemma definition.intersection_deux  (A B : set X) (x : X) :  x ∈ A ∩ B ↔ ( x ∈ A ∧ x ∈ B) := \niff.rfl\n/- dEAduction\nPrettyName\n    Intersection de deux ensembles\n-/\n\nlemma theorem.intersection_ensemble  (A B C : set X) : C ⊆ A ∩ B ↔ C ⊆ A ∧ C ⊆ B := \nbegin\n    exact ball_and_distrib\nend\n\nlemma definition.intersection_quelconque (I : Type) (O : I → set X)  (x : X) : (x ∈ set.Inter O) ↔ (∀ i:I, x ∈ O i) :=\nset.mem_Inter\n/- dEAduction\nPrettyName\n    Intersection quelconque    \n-/\n\n-- Les deux lemmes suivants seront à regroupé au sein d'une même tactique : essayer le premier, \n-- en cas d'échec essayer le second. Un seul bouton dans l'interface graphique\nlemma definition.union  (A : set X) (B : set X) (x : X) :  x ∈ A ∪ B ↔ ( x ∈ A ∨ x ∈ B) := \niff.rfl\n/- dEAduction\nPrettyName\n    Union de deux ensembles\n-/\n\nlemma definition.union_quelconque (I : Type) (O : I → set X)  (x : X) : (x ∈ set.Union O) ↔ (∃ i:I, x ∈ O i) :=\nset.mem_Union\n/- dEAduction\nPrettyName\n    Union quelconque\n-/\n\n\n\n\n\nlemma exercise.union_distributive_inter (X : Type) (A B C : set X) : A ∩ (B ∪ C)  = (A ∩ B) ∪ (A ∩ C) := \n/- dEAduction\nPrettyName  \n    Intersection d'unions\nDescription \n    L'intersection est distributive par rapport à l'union\n    et ça continue sur la ligne suivante\nTools->Logic\n    $ALL -implicate -negate\nTools->ProofTechniques\n    $ALL -contradiction\nTools->Definitions\n    $UNTIL_NOW\nTools->Theorems\n    double_inclusion, Riemann_hypothesis\nExpectedVarsNumber \n    X=3, A=1, B=1\n-/\nbegin\n    sorry\nend    \n\n\nvariables {A B C : set X}\n\nlemma exercise.inter_distributive_union : A ∪ (B ∩ C)  = (A ∪ B) ∩ (A ∪ C) := \n/- dEAduction\nPrettyName \n    Union d'intersections\nDescription \n    L'union est distributive par rapport à l'intersection \nTools->Logic \n    $ALL\nTools->ProofTechniques\n    $ALL -choice\nTools->Statements\n    $UNTIL_NOW\n-/\nbegin\n    sorry\nend\n\nend unions_and_intersections\n\n-----------------------------------------\nnamespace complements -- section 2\n/- dEAduction\nSection\n    Complementaires\n-/\n\n\n\nlemma definition.complement {A : set X} {x : X} : x ∈ set.univ \\ A ↔ x ∉ A := \nby finish\n\nlemma definition.complement_1 {A : set X} {x : X} : x ∈ set.compl A ↔ x ∉ A := \nby finish\n\nlemma definition.complement_2 {A B : set X} {x : X} : x ∈ B \\ A ↔ (x ∈ B ∧ x ∉ A) :=\niff.rfl\n\nlemma exercise.complement_complement {A : set X} : - - A = A :=\n/- dEAduction\nPrettyName \n    Complémentaire du complémentaire\nDescription \n    Tout ensemble est égal au complémentaire de son complémentaire \n    et réciproquement.\n-/\nbegin\n    sorry\nend\n\nend complements\n\nend set_theory", "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/trash/exercises_test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.935346511643776, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7668843675503785}}
{"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 group_theory.submonoid.operations\nimport group_theory.subsemigroup.center\nimport data.fintype.basic\n\n/-!\n# Centers of monoids\n\n## Main definitions\n\n* `submonoid.center`: the center of a monoid\n* `add_submonoid.center`: the center of an additive monoid\n\nWe provide `subgroup.center`, `add_subgroup.center`, `subsemiring.center`, and `subring.center` in\nother files.\n-/\n\nnamespace submonoid\nsection\nvariables (M : Type*) [monoid M]\n\n/-- The center of a monoid `M` is the set of elements that commute with everything in `M` -/\n@[to_additive \"The center of a monoid `M` is the set of elements that commute with everything in\n`M`\"]\ndef center : submonoid M :=\n{ carrier := set.center M,\n  one_mem' := set.one_mem_center M,\n  mul_mem' := λ a b, set.mul_mem_center }\n\n@[to_additive] lemma coe_center : ↑(center M) = set.center M := rfl\n\n@[simp]\nlemma center_to_subsemigroup : (center M).to_subsemigroup = subsemigroup.center M := rfl\n\nlemma _root_.add_submonoid.center_to_add_subsemigroup (M) [add_monoid M] :\n  (add_submonoid.center M).to_add_subsemigroup = add_subsemigroup.center M := rfl\n\nattribute [to_additive add_submonoid.center_to_add_subsemigroup] submonoid.center_to_subsemigroup\n\nvariables {M}\n\n@[to_additive] lemma mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl\n\ninstance decidable_mem_center [decidable_eq M] [fintype M] : decidable_pred (∈ center M) :=\nλ _, decidable_of_iff' _ mem_center_iff\n\n/-- The center of a monoid is commutative. -/\ninstance : comm_monoid (center M) :=\n{ mul_comm := λ a b, subtype.ext $ b.prop _,\n  .. (center M).to_monoid }\n\n/-- The center of a monoid acts commutatively on that monoid. -/\ninstance center.smul_comm_class_left : smul_comm_class (center M) M M :=\n{ smul_comm := λ m x y, (commute.left_comm (m.prop x) y).symm }\n\n/-- The center of a monoid acts commutatively on that monoid. -/\ninstance center.smul_comm_class_right : smul_comm_class M (center M) M :=\nsmul_comm_class.symm _ _ _\n\n/-! Note that `smul_comm_class (center M) (center M) M` is already implied by\n`submonoid.smul_comm_class_right` -/\nexample : smul_comm_class (center M) (center M) M := by apply_instance\n\nend\n\nsection\nvariables (M : Type*) [comm_monoid M]\n\n@[simp] lemma center_eq_top : center M = ⊤ :=\nset_like.coe_injective (set.center_eq_univ M)\n\nend\n\nend submonoid\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/submonoid/center.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797081106935, "lm_q2_score": 0.8705972734445508, "lm_q1q2_score": 0.7668195372696165}}
{"text": "import data.nat.prime\n       data.nat.parity\n       tactic\n\ntheorem even_of_prime_succ_pow (a b : ℕ) (ha : a > 1) (hb : b > 1) (hp : nat.prime (a^b + 1)) : 2 ∣ a :=\nbegin\n  refine nat.prime.dvd_of_dvd_pow nat.prime_two (show 2 ∣ a^b, from _),\n  by_contra h,\n  have hab2 : a^b % 2 = 1, from nat.not_even_iff.mp h,\n  set k := (a^b)/2 with hk,\n  have habk : (a^b) = 1 + 2*k, by rw [←nat.mod_add_div (a^b) 2, hab2],\n  rw [habk,\n      show 1 + 2 * k + 1 = 2*(k + 1), by ring] at hp,\n  refine nat.not_prime_mul one_lt_two _ hp,\n  { suffices : k ≠ 0, by omega,\n    intro h,\n    rw [h, mul_zero, add_zero] at habk,\n    have : 1^b < a ^ b, from nat.pow_lt_pow_of_lt_left ha (lt_trans zero_lt_one hb),\n    rw [nat.one_pow, ←habk] at this,\n    exact nat.lt_irrefl _ this }\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/2_even_of_prime_succ_pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475810629193, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7668164137306517}}
{"text": "import data.real.basic\n\n\n--OUTPUT 1\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ 9 / 2, from by auto [div_eq_mul_inv, add_div],\n  have h2 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (9 / 2) * ((a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b)), from by auto [div_le_div_of_mul_le, lt_of_lt_of_le (ha + hb + hc) (by auto [add_pos]), mul_le_mul_of_nonneg_right (by auto [add_nonneg, add_nonneg, add_nonneg, add_nonneg, add_nonneg, add_nonneg, add_nonneg]), mul_self_nonneg, mul_self_nonneg, mul_self_nonneg, mul_self_nonneg, mul_self_nonneg, mul_self_nonneg, mul_self_nonneg, mul_self_nonneg, mul_self_nonneg],\n  have h3 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (1 / 2) * ((a + b + c) / (b + c) + (a + b + c) + (a + b + c) / (a + b)), from by auto [mul_le_mul_of_nonneg_left (by auto [half_pos]), h2],\n  have h4 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (1 / 2) * ((a + b + c) + (a + b + c) + (a + b + c)), from by auto [mul_le_mul_of_nonneg_right (by auto [add_pos]), h3],\n  have h5 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ ((1 / 2) * (a + b + c) + (1 / 2) * (a + b + c) + (1 / 2) * (a + b + c)), from by auto [mul_le_mul_of_nonneg_left (by auto [half_pos]), h4],\n  have h6 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ ((1 / 2) * (a + b + c) + (1 / 2) * (a + b + c) + (1 / 2) * (a + b + c)) / (b + c + a + b), from by auto [mul_le_mul_of_nonneg_right, add_pos, add_pos, add_pos, h5],\n  have h7 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ ((1 / 2) * (a + b + c) + (1 / 2) * (a + b + c) + (1 / 2) * (a + b + c)) / (b + c + a + b), from by auto [add_le_add_iff_left, add_le_add_iff_left, h6],\n  have h8 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ ((1 / 2) * (a + b + c) + (1 / 2) * (a + b + c) + (1 / 2) * (a + b + c)) / (b + c + a + b), from by auto [add_le_add_iff_right, h7],\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by auto [div_eq_mul_inv, add_div, h8],\nend\n\n--OUTPUT 2\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : 0 < (b + c) + (a + c) + (a + b), from by auto [add_pos],\n  have h2 : 0 < (b + c) + (a + c) + (a + b) / 3, from by auto [add_pos, div_pos],\n  have h3 : (a + b + c) / ((b + c) + (a + c) + (a + b) / 3) = 1 / 2, from by auto [div_eq_iff],\n\n  calc (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (a + b + c) / ((b + c) + (a + c) + (a + b)) : by auto [mul_div_mul_left, div_add_div_left, div_add_div_left, div_add_div_left, add_pos, add_pos, add_pos, h1, h2, h3]\n  ... ≥ (a + b + c) / ((b + c) + (a + c) + (a + b) / 3) : by auto [div_le_div_right, h1, h2, add_pos, add_pos, add_pos]\n  ... = 1 / 2 : by auto [h3]\n  ... = 3 / 6 : by auto [div_eq_iff, mul_comm]\n  ... = 3 / 2 : by auto [div_eq_iff, mul_comm]\nend\n\n--OUTPUT 3\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) ≥ (9 / 2), from by auto [div_add_div_same, div_add_div_same, add_mul_div_left, add_mul_div_left, add_mul_div_left, mul_self_inj, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add_halves, add\nend --Needs more than 2000 tokens!\n\n--OUTPUT 4\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : a + b + c > 0, from by auto [add_pos, ha, hb, hc],\n  have h2 : (a + b + c) / 3 = (1 / 2) * (a + b + c), from by auto [mul_div_cancel, three],\n  have h3 : (a + b + c) / (b + c) = (1 / 2) * (a + b + c), from by auto [mul_div_cancel, two],\n  have h4 : (a + b + c) / (a + c) = (1 / 2) * (a + b + c), from by auto [mul_div_cancel, two],\n  have h5 : (a + b + c) / (a + b) = (1 / 2) * (a + b + c), from by auto [mul_div_cancel, two],\n  have h6 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) > 0, from by auto [add_pos, one_div_pos, ha, hb, hc],\n  have h7 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) = (b + c) + (a + c) + (a + b) / ((b + c) * (a + c) * (a + b)), from by auto [one_div_mul, mul_comm, mul_add],\n  have h8 : (3 / 2) * (b + c) * (a + c) * (a + b) = (3 / 2) * ((b + c) + (a + c) + (a + b)), from by auto [mul_div_cancel, two, mul_comm, mul_add],\n  have h9 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) ≥ (3 / 2) / ((b + c) + (a + c) + (a + b)), from by auto [arithmetic_mean_never_less_than_harmonic_mean, h6],\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 auto [h3, h4, h5]\n  ... = 1 / 2 * (a + b + c) + 1 / 2 * (a + b + c) + 1 / 2 * (a + b + c) : by auto [add_mul, h3, h4, h5]\n  ... = (1 / 2) * (3 * (a + b + c)) : by auto [mul_add, three, mul_comm, mul_assoc]\n  ... = (1 / 2) * (3 / 3) * (a + b + c) : by auto [mul_div_cancel, three]\n  ... = (1 / 2) * (1 / 2) * (a + b + c) : by auto [mul_div_cancel, two]\n  ... = (1 / 2) * (a + b + c) / 2 : by auto [mul_div_cancel, two]\n  ... = (1 / 2) * ((a + b + c) / 3) : by auto [mul_div_cancel, two]\n  ... = (1 / 2) * (1 / 2) * (a + b + c) : by auto [h2]\n  ... = (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) : by auto [one_div_mul, mul_comm, mul_add]\n  ... ≥ (3 / 2) / ((b + c) + (a + c) + (a + b)) : by auto [h9]\n  ... = (3 / 2) * ((b + c) + (a + c) + (a + b)) / ((b + c) * (a + c) * (a + b)) : by auto [div_mul_cancel, h6]\n  ... = (3 / 2) * (b + c) * (a + c) * (a + b) / ((b + c) * (a + c) * (a + b)) : by auto [mul_comm, mul_add]\n  ... = (3 / 2) : by auto [h8],\nend\n\n--OUTPUT 5\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : 0 < b + c, from by exact add_pos hb hc,\n  have h2 : 0 < a + c, from by exact add_pos ha hc,\n  have h3 : 0 < a + b, from by exact add_pos ha hb,\n  have h4 : 0 < (b + c) + (a + c) + (a + b), from by exact add_pos h1 h2 h3,\n  have h5 : 0 < 3, from by exact is_pos_three,\n  have h6 : 0 < (b + c) + (a + c) + (a + b), from by exact add_pos h1 h2 h3,\n  have h7 : 0 < (a + b + c), from by exact add_pos ha hb hc,\n\n  have h8 : (a + b + c) / (b + c) = (a + b + c) * ((b + c)⁻¹), from by auto [div],\n  have h9 : (a + b + c) / (a + c) = (a + b + c) * ((a + c)⁻¹), from by auto [div],\n  have h10 : (a + b + c) / (a + b) = (a + b + c) * ((a + b)⁻¹), from by auto [div],\n\n  have h11 : (a + b + c) / (b + c) = (a + b + c) * (1 / (b + c)), from by auto [one_div],\n  have h12 : (a + b + c) / (a + c) = (a + b + c) * (1 / (a + c)), from by auto [one_div],\n  have h13 : (a + b + c) / (a + b) = (a + b + c) * (1 / (a + b)), from by auto [one_div],\n\n  have h14 : (a + b + c) / (b + c) = a + b + c - (a / (b + c)) + (b / (b + c)), from by auto [add_div, add_comm, add_mul, add_comm (a + b + c) (a / (b + c))],\n  have h15 : (a + b + c) / (a + c) = a + b + c - (a / (a + c)) + (c / (a + c)), from by auto [add_div, add_comm, add_mul, add_comm (a + b + c) (a / (a + c))],\n  have h16 : (a + b + c) / (a + b) = a + b + c - (c / (a + b)) + (b / (a + b)), from by auto [add_div, add_comm, add_mul, add_comm (a + b + c) (c / (a + b))],\n\n  have h17 : (a + b + c) / (b + c) = a + b + c + (-a / (b + c)) + (b / (b + c)), from by auto [neg_div, add_mul, add_comm (a + b + c) (-a / (b + c))],\n  have h18 : (a + b + c) / (a + c) = a + b + c + (-a / (a + c)) + (c / (a + c)), from by auto [neg_div, add_mul, add_comm (a + b + c) (-a / (a + c))],\n  have h19 : (a + b + c) / (a + b) = a + b + c + (-c / (a + b)) + (b / (a + b)), from by auto [neg_div, add_mul, add_comm (a + b + c) (-c / (a + b))],\n\n  have h20 : (a + b + c) / (b + c) = a + b + c + (-a / (b + c)) + b * (1 / (b + c)), from by auto [h17, h11],\n  have h21 : (a + b + c) / (a + c) = a + b + c + (-a / (a + c)) + c * (1 / (a + c)), from by auto [h18, h12],\n  have h22 : (a + b + c) / (a + b) = a + b + c + (-c / (a + b)) + b * (1 / (a + b)), from by auto [h19, h13],\n\n  have h23 : (a + b + c) / (b + c) = a + b + c + (1 / (b + c)) + b * (1 / (b + c)), from by auto [h20, neg_div, add_mul],\n  have h24 : (a + b + c) / (a + c) = a + b + c + (1 / (a + c)) + c * (1 / (a + c)), from by auto [h21, neg_div, add_mul],\n  have h25 : (a + b + c) / (a + b) = a + b + c + (1 / (a + b)) + b * (1 / (a + b)), from by auto [h22, neg_div, add_mul],\n\n  have h26 : (a + b + c) / (b + c) = a + b + c + (1 / (b + c)) + (b / (b + c)), from by auto [h23, mul_one],\n  have h27 : (a + b + c) / (a + c) = a + b + c + (1 / (a + c)) + (c / (a + c)), from by auto [h24, mul_one],\n  have h28 : (a + b + c) / (a + b) = a + b + c + (1 / (a + b)) + (b / (a + b)), from by auto [h25, mul_one],\n\n  have h29 : (a + b + c) / (b + c) = a + b + c + (1 / (b + c)) + (b / (b + c)) + (-a / (b + c)), from by auto [h26, add_comm],\n  have h30 : (a + b + c) / (a + c) = a + b + c + (1 / (a + c)) + (c / (a + c)) + (-a / (a + c)), from by auto [h27, add_comm],\n  have h31 : (a + b + c) / (a + b) = a + b + c + (1 / (a + b)) + (b / (a + b)) + (-c / (a + b)), from by auto [h28, add_comm],\n\n  have h32 : (a + b + c) / (b + c) = a + b + c + (1 / (b + c)) - (a / (b + c)) + (b / (b + c)), from by auto [h29, add_comm (-a / (b + c))],\n  have h33 : (a + b + c) / (a + c) = a + b + c + (1 / (a + c)) - (a / (a + c)) + (c / (a + c)), from by auto [h30, add_comm (-a / (a + c))],\n  have h34 : (a + b + c) / (a + b) = a + b + c + (1 / (a + b)) - (c / (a + b)) + (b / (a + b)), from by auto [h31, add_comm (-c / (a + b))],\n\n  have h35 : (a + b + c) / (b + c) = a + b + c + (1 / (b + c)) - (a / (b + c)) + (b / (b + c)) + c, from by auto [h32, add_right_inj],\n  have h36 : (a + b + c) / (a + c) = a + b + c + (1 / (a + c)) - (a / (a + c)) + (c / (a + c)) + b, from by auto [h33, add_right_inj],\n  have h37 : (a + b + c) / (a + b) = a + b + c + (1 / (a + b\nend --Needs more than 2000 tokens!\n\n--OUTPUT 6\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) := \nbegin\n  have h1 : a + b + c > 0, from by auto [ha, hb, hc, add_pos],\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 simp\n  ... = (a + b + c) / (b + c) + (a + b + c) / (a + c) + (a + b + c) / (a + b) : by auto [add_div_cancel_left] using [h1]\n  ... ≥ (9 * (a + b + c)) / ((b + c) + (a + c) + (a + b)) : by auto [div_le_div_of_le_of_pos, add_pos, div_le_div_of_le_of_pos, add_pos, div_le_div_of_le_of_pos, add_pos, le_div_iff, mul_pos] using [h1, ha, hb, hc, arithmetic_mean_is_never_less_than_harmonic_mean]\n  ... = 3 / 2 : by auto [div_eq_iff_mul_eq, mul_comm, mul_assoc, mul_left_cancel, mul_div_cancel, mul_one] using [h1],\nend\n\n--OUTPUT 7\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : 0 < a + b + c, from by auto [add_pos],\n  have h2 : 0 < b + c, from by auto [add_pos],\n  have h3 : 0 < a + c, from by auto [add_pos],\n  have h4 : 0 < a + b, from by auto [add_pos],\n\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 auto [div_add_div_same, add_assoc, add_assoc, add_assoc, add_assoc] using [field]\n  ... ≥ 9 / 2 : by auto [add_pos, div_le_div_iff_le_of_pos, mul_pos] using [arithmetic_mean_harmonic_mean]\n  ... ≥ 3 / 2 : by auto [div_le_div_iff_le_of_pos, div_pos] using [field]\nend\n\n--OUTPUT 8\ntheorem nesbitt_inequality {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2) :=\nbegin\n  have h1 : (a + b + c) / ((b + c) + (a + c) + (a + b)) = (1 / 2), from by auto [div_eq_mul_inv, add_mul, mul_comm, mul_assoc],\n  have h2 : (9 / 2) * ((a + b + c) / ((b + c) + (a + c) + (a + b))) = (9 / 2) * (1 / 2), from by auto [mul_assoc, h1],\n  have h3 : ((a + b + c) / (b + c)) + ((a + b + c) / (a + c)) + ((a + b + c) / (a + b)) = (9 / 2) * (1 / 2), from by auto [mul_one, add_mul, add_mul, add_mul, add_assoc, add_assoc, add_comm, add_assoc, add_comm, add_comm, add_assoc, add_comm, add_assoc, add_assoc, add_comm, add_assoc, add_assoc, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, h2, !mul_one],\n  have h4 : (1 / (b + c)) + (1 / (a + c)) + (1 / (a + b)) = (9 / 2) * (1 / 2), from by auto [h3, div_eq_mul_inv, mul_one, mul_one, mul_one, add_mul, add_mul, add_mul, add_assoc, add_assoc, add_comm, add_assoc, add_comm, add_comm, add_assoc, add_comm, add_assoc, add_assoc, add_comm, add_assoc, add_assoc, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, !mul_one],\n  have h5 : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / (b + c) + (a + c) + (a + b)), from by auto [arithmetic_mean_harmonic_mean, h4],\n  show (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (3 / 2), from by auto [h5, div_eq_mul_inv, mul_one, mul_one, mul_one, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, mul_comm, !mul_one],\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 {α : Type*} (S : set α) : ∀ A B ∈ 𝒫 S, (A ∩ B) ∈ 𝒫 S :=\nbegin\n  assume (A : set α) (hA : A ∈ 𝒫 S) (B : set α) (hB : B ∈ 𝒫 S),\n  have h1 : (A ⊆ S) ∧ (B ⊆ S), from by auto [set.subset_of_mem_powerset, set.subset_of_mem_powerset],\n  have h2 : (A ∩ B) ⊆ A, from by auto [set.inter_subset_left],\n  have h3 : (A ∩ B) ⊆ S, from by auto [set.subset.trans],\n  show (A ∩ B) ∈  𝒫 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 : ℝ) : (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] : ∃! e : G, ∀ a : G, e * a = a ∧ a * e = a :=\nbegin\n  have h1 : ∀ a b : G, ∃! x : G, a * x = b, from by auto using [use (a⁻¹ * b)],\n  have h2 : ∀ a b : G, ∃! y : G, y * a = b, from by auto using [use b * a⁻¹], \n\n  have h3 : ∀ a : G, ∃! x : G, a * x = a, from by auto [h1],\n  have h4 : ∀ a : G, ∃! y : G, y * a = a, from by auto [h2],\n\n  have h5 : ∀ 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 : ∀ 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 ∃! e : G, ∀ a : G, e * a = a ∧ 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 : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : (a / (b + c)) + (b / (a + c)) + (c / (a + b)) ≥ (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.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.9433475778774728, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7668164111413064}}
{"text": "\nsection pred_logic\n\nvariables X Y Z : Prop\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 ∨ false) and (X ∧ 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 ∀ (P : Prop), P ∨ 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 → X is\nalways true, no matter whether X is true or false.\nSo, false → false is true, and false → true is true.\n\nNow suppose P is any proposition in first-order logic.\nThe elimination rule for \"false\" is false ⊢ 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 → false\ndef p2 : Prop := false → true\ndef p3 : Prop := true → true\ndef p4 : Prop := true → false\ndef p5 : Prop := false → 2 = 3\ndef p6 : Prop := false → 0 = 0\ndef p7 : Prop := ∀ (P : Prop), true → P\ndef p8 : Prop := ∀ (P : Prop), false → 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 → false\ntheorem x : p1 := \nbegin\n  unfold p1,\n  assume f : false,\n  exact f,\nend\n\n-- false → 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", "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/06_rules_for_true_false.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7667781924452037}}
{"text": "/-\nReferences:\n\nLectures on the Curry-Howard Isomorphism\nMorten Heine Sørensen\nPawel Urzyczyn\nJul 2006\nElsevier\nhttps://play.google.com/store/books/details/Morten_Heine_S%C3%B8rensen_Lectures_on_the_Curry_Howard?id=_mtnm-9KtbEC&hl=en\n-/\n\nimport tactic\n\ndef var := ℕ\n\ninductive term : Type\n| var : var → term\n| app : term → term → term\n-- term.abs y P = λ y . P\n| abs : var → term → term\n\n\ndef FV : term → set var\n| (term.var x) := {x}\n| (term.app P Q) := (FV P) ∪ (FV Q)\n| (term.abs x P) := (FV P) \\ {x}\n\n\nlemma simp_term_var\n(x : var) (y : var) :\nx ∈ FV (term.var y) ↔ x = y :=\nbegin\nunfold FV,\nsimp only [set.mem_singleton_iff]\nend\n\nlemma simp_term_app\n(x : var) (P : term) (Q : term) :\nx ∈ FV (term.app P Q) ↔ x ∈ FV P ∨ x ∈ FV Q :=\nbegin\nunfold FV,\nsimp only [set.mem_union_eq]\nend\n\nlemma simp_term_app_not\n(x : var) (P : term) (Q : term) :\nx ∉ FV (term.app P Q) ↔ x ∉ FV P ∧ x ∉ FV Q :=\nbegin\nunfold FV,\nsimp only [set.mem_union_eq],\npush_neg,\nexact iff.rfl\nend\n\nlemma simp_term_abs\n(x : var) (y : var) (P : term) :\nx ∈ FV (term.abs y P) ↔ x ∈ FV P ∧ x ≠ y :=\nbegin\nunfold FV,\nsimp only [set.mem_diff, set.mem_singleton_iff]\nend\n\nlemma misc_1\n{x : var} {y : var} {P : term}\n(H1 : x ∈ FV P)\n(H2 : x ≠ y) :\nx ∈ FV (term.abs y P) :=\nbegin\nsimp only [simp_term_abs],\nexact and.intro H1 H2\nend\n\nlemma misc_2\n{x : var} {y : var} {P : term}\n(H1 : x ∈ FV (term.abs y P)) :\nx ∈ FV P :=\nbegin\nsimp only [simp_term_abs] at H1,\ncases H1,\nexact H1_left\nend\n\nlemma misc_3\n{x : var} {y : var} {P : term}\n(H1 : x ∈ FV (term.abs y P)) :\nx ≠ y :=\nbegin\nsimp only [simp_term_abs] at H1,\ncases H1,\nexact H1_right\nend\n\nlemma misc_4\n{x : var} {y : var} {P : term}\n(H1 : x = y) :\nx ∉ FV (term.abs y P) :=\nbegin\nsimp only [simp_term_abs],\npush_neg,\nintro, exact H1\nend\n\nlemma misc_5\n{x : var} {y : var} {P : term}\n(H1 : x ∉ FV P) :\nx ∉ FV (term.abs y P) :=\nbegin\nsimp only [simp_term_abs],\npush_neg,\nintro H2, by_contradiction, apply H1, exact H2\nend\n\nlemma misc_6\n{x : var} {y : var} {P : term}\n(H1 : x ∉ FV (term.abs y P))\n(H2 : x ∈ FV P) :\nx = y :=\nbegin\nsimp only [simp_term_abs] at H1,\npush_neg at H1,\nexact H1 H2\nend\n\nlemma misc_7\n{x : var} {y : var} {P : term}\n(H1 : x ∉ FV (term.abs y P))\n(H2 : x ≠ y) :\nx ∉ FV P :=\nbegin\nsimp only [simp_term_abs] at H1,\npush_neg at H1,\nintro H3, apply H2, exact H1 H3\nend\n\n\n-- sub_is_def M x N means M [ x := N ] is defined\ninductive sub_is_def : term → var → term → Prop\n\n-- y [ x := N ] is defined\n| var {y : var} {x : var} {N : term} :\n  sub_is_def (term.var y) x N\n\n-- P [ x := N ] is defined → Q [ x := N ] is defined → (P Q) [ x := N ] is defined\n| app {P : term} {Q : term} {x : var} {N : term} :\n  sub_is_def P x N → sub_is_def Q x N → sub_is_def (term.app P Q) x N\n\n-- x = y → ( λ y . P ) [ x := N ] is defined\n| abs_same {y : var} {P : term} {x : var} {N : term} :\n  x = y → sub_is_def (term.abs y P) x N\n\n-- x ≠ y → x ∉ FV ( λ y . P ) → ( λ y . P ) [ x := N ] is defined\n| abs_diff_nel {y : var} {P : term} {x : var} {N : term} :\n  x ≠ y → x ∉ FV (term.abs y P) → sub_is_def (term.abs y P) x N\n\n-- x ≠ y → y ∉ FV ( N ) → P [ x := N ] is defined → ( λ y . P ) [ x := N ] is defined\n| abs_diff {y : var} {P : term} {x : var} {N : term} :\n  x ≠ y → y ∉ FV N → sub_is_def P x N → sub_is_def (term.abs y P) x N\n\nnotation M `[` x `:=` N `]` `is_def` := sub_is_def M x N\n\n\n-- M [ x := N ]\ndef sub : term → var → term → term\n-- if x = y then y [ x := N ] = N else y [ x := N ] = y\n| (term.var y) x N := if x = y then N else term.var y\n\n-- (P Q) [ x := N ] = (P [ x := N ] Q [ x := N ])\n| (term.app P Q) x N := term.app (sub P x N) (sub Q x N)\n\n-- if x = y then ( λ y . P ) [ x := N ] = ( λ y . P ) else ( λ y . P ) [ x := N ] = ( λ y . P [ x := N ] )\n| (term.abs y P) x N := if x = y then term.abs y P else term.abs y (sub P x N)\n\nnotation M `[` x `:=` N `]` := sub M x N\n\n\n-- is_sub M x N L means M [ x := N ] = L\ninductive is_sub : term → var → term → term → Prop\n\n-- if x = y then y [ x := N ] = N\n| var_same {y : var} {x : var} {N : term} :\n  x = y → is_sub (term.var y) x N N\n\n-- if x ≠ y then y [ x := N ] = y\n| var_diff {y : var} {x : var} {N : term} :\n  x ≠ y → is_sub (term.var y) x N (term.var y)\n\n-- (P Q) [ x := N ] = (P [ x := N ] Q [ x := N ])\n| app {P : term} {Q : term} {x : var} {N : term} {P' : term} {Q' : term} :\n  is_sub P x N P' → is_sub Q x N Q' → is_sub (term.app P Q) x N (term.app P' Q')\n\n-- if x = y then ( λ y . P ) [ x := N ] = ( λ y . P )\n| abs_same {y : var} {P : term} {x : var} {N : term} :\n  x = y → is_sub (term.abs y P) x N (term.abs y P)\n\n-- if x ≠ y then ( λ y . P ) [ x := N ] = ( λ y . P [ x := N ] )\n\n| abs_diff_nel {y : var} {P : term} {x : var} {N : term} {P' : term} :\n  x ≠ y → x ∉ FV (term.abs y P) → is_sub P x N P' → is_sub (term.abs y P) x N (term.abs y P')\n\n| abs_diff {y : var} {P : term} {x : var} {N : term} {P' : term} :\n  x ≠ y → y ∉ FV N → is_sub P x N P' → is_sub (term.abs y P) x N (term.abs y P')\n\n\nlemma simp_var_same\n{y : var} {x : var} {N : term}\n(H1 : x = y) :\n(term.var y) [ x := N ] = N := if_pos H1\n\nlemma simp_var_diff\n{y : var} {x : var} {N : term}\n(H1 : x ≠ y) :\n(term.var y) [ x := N ] = term.var y := if_neg H1\n\nlemma simp_abs_same\n{y : var} {P : term} {x : var} {N : term}\n(H1 : x = y) :\n(term.abs y P) [ x := N ] = term.abs y P := if_pos H1\n\nlemma simp_abs_diff\n{y : var} {P : term} {x : var} {N : term}\n(H1 : x ≠ y) :\n(term.abs y P) [ x := N ] = term.abs y (P [ x := N ]) := if_neg H1\n\n\nlemma lemma_1_2_5_i_a\n{M : term} {x : var} {N : term}\n(H1 : x ∉ FV M) :\nM [ x := N ] is_def :=\nbegin\ninduction M,\ncase term.var : y\n{\n  exact sub_is_def.var\n},\ncase term.app : P Q IH_P IH_Q\n{\n  simp only [simp_term_app_not] at H1,\n  cases H1,\n  specialize IH_P H1_left,\n  specialize IH_Q H1_right,\n  exact sub_is_def.app IH_P IH_Q\n},\ncase term.abs : y P\n{\n  by_cases h_xy : x = y,\n  exact sub_is_def.abs_same h_xy,\n  exact sub_is_def.abs_diff_nel h_xy H1\n}\nend\n\n\nlemma lemma_1_2_5_i_b\n{M : term} {x : var} {N : term}\n(H1 : x ∉ FV M) :\nM [ x := N ] = M :=\nbegin\ninduction M,\ncase term.var : y\n{\n  exact if_neg H1\n},\ncase term.app : P Q IH_P IH_Q\n{\n  unfold sub,\n  simp only [simp_term_app_not] at H1,\n  cases H1,\n  specialize IH_P H1_left,\n  specialize IH_Q H1_right,\n  rewrite IH_P, rewrite IH_Q\n},\ncase term.abs : y P IH\n{\n  by_cases h_xy : x = y,\n  {\n    exact if_pos h_xy\n  },\n  {\n    have s1 : x ∉ FV P, exact misc_7 H1 h_xy,\n    specialize IH s1,\n    rewrite simp_abs_diff h_xy,\n    rewrite IH\n  }\n}\nend\n\n\nlemma lemma_1_2_5_i\n{M : term} {x : var} {N : term}\n(H1 : x ∉ FV M) :\nis_sub M x N M :=\nbegin\ninduction M,\ncase term.var : y\n{\n  simp only [simp_term_var] at H1,\n  exact is_sub.var_diff H1\n},\ncase term.app : P Q IH_P IH_Q\n{\n  simp only [simp_term_app_not] at H1,\n  cases H1,\n  specialize IH_P H1_left,\n  specialize IH_Q H1_right,\n  exact is_sub.app IH_P IH_Q\n},\ncase term.abs : y P IH\n{\n  by_cases h_xy : x = y,\n  {\n    exact is_sub.abs_same h_xy\n  },\n  {\n    have s1 : x ∉ FV P, exact misc_7 H1 h_xy,\n    specialize IH s1,\n    exact is_sub.abs_diff_nel h_xy H1 IH\n  }\n}\nend\n\n\nexample\n(M : term) (x : var) (N : term) (L : term)\n(H1 : is_sub M x N L) :\nM [ x := N ] = L :=\nbegin\ninduction H1,\nexact if_pos H1_ᾰ,\nexact if_neg H1_ᾰ,\nunfold sub, rewrite H1_ih_ᾰ, rewrite H1_ih_ᾰ_1,\nexact if_pos H1_ᾰ,\nrewrite <- H1_ih, exact if_neg H1_ᾰ,\nrewrite <- H1_ih, exact if_neg H1_ᾰ,\nend\n\n\nexample\n(M : term) (x : var) (N : term)\n(H1 : ∃ (L : term), is_sub M x N L) :\nM [ x := N ] is_def :=\nbegin\napply exists.elim H1,\nintros L,\nintros h,\ninduction h,\ncase is_sub.var_same : y x N h\n{\n  exact sub_is_def.var\n},\ncase is_sub.var_diff : y x N h\n{\n  exact sub_is_def.var\n},\ncase is_sub.app : P Q x N P' Q' IH_P' IH_Q' IH_P IH_Q\n{\n  apply sub_is_def.app, apply IH_P, existsi P', exact IH_P', apply IH_Q, existsi Q', exact IH_Q'\n},\ncase is_sub.abs_same : y P x N h\n{\n  exact sub_is_def.abs_same h\n},\ncase is_sub.abs_diff_nel : y P x N P' h1 h2 h3 IH\n{\n  exact sub_is_def.abs_diff_nel h1 h2\n},\ncase is_sub.abs_diff : y P x N P' h1 h2 h3 IH\n{\n  apply sub_is_def.abs_diff h1 h2, apply IH, existsi P', exact h3\n}\nend\n\n\nexample\n(M : term) (x : var) (N : term)\n(H1 : M [ x := N ] is_def) :\nis_sub M x N (M [ x := N ]) :=\nbegin\ninduction M,\ncase term.var : y\n{\n  by_cases h_xy : x = y,\n  {\n    rewrite simp_var_same h_xy,\n    exact is_sub.var_same h_xy\n  },\n  {\n    rewrite simp_var_diff h_xy,\n    exact is_sub.var_diff h_xy\n  }\n},\ncase term.app : P Q IH_P IH_Q\n{\n  unfold sub,\n  cases H1,\n  specialize IH_P H1_ᾰ,\n  specialize IH_Q H1_ᾰ_1,\n  exact is_sub.app IH_P IH_Q\n},\ncase term.abs : y P IH\n{\n  cases H1,\n  {\n    rewrite simp_abs_same H1_ᾰ,\n    exact is_sub.abs_same H1_ᾰ\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ,\n    have s1 : x ∉ FV P, exact misc_7 H1_ᾰ_1 H1_ᾰ,\n    have s2 : P [ x := N ] is_def, exact lemma_1_2_5_i_a s1,\n    specialize IH s2,\n    exact is_sub.abs_diff_nel H1_ᾰ H1_ᾰ_1 IH\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ,\n    specialize IH H1_ᾰ_2,\n    exact is_sub.abs_diff H1_ᾰ H1_ᾰ_1 IH\n  }\n}\nend\n\n\nlemma misc_5'\n{x : var} {y : var} {P : term} {N : term}\n(H1 : x ∉ FV P) :\n(term.abs y P) [ x := N ] = term.abs y P :=\nbegin\nhave s1 : x ∉ FV (term.abs y P), exact misc_5 H1,\nexact lemma_1_2_5_i_b s1\nend\n\nlemma misc_7'\n{x : var} {y : var} {P : term} {N : term}\n(H1 : x ∉ FV (term.abs y P))\n(H2 : x ≠ y) :\nP [ x := N ] = P :=\nbegin\nhave s1 : x ∉ FV P, exact misc_7 H1 H2,\nexact lemma_1_2_5_i_b s1\nend\n\n\nlemma lemma_1_2_5_ii_right\n(M : term) (x : var) (N : term) (z : var)\n(H1 : M [ x := N ] is_def)\n(H2 : z ∈ FV (M [ x := N ])) :\n(z ∈ FV M ∧ x ≠ z) ∨ (z ∈ FV N ∧ x ∈ FV M) :=\nbegin\ninduction H1,\ncase sub_is_def.var : y x N\n{\n  simp only [simp_term_var],\n  by_cases h_xy : x = y,\n  {\n    rewrite simp_var_same h_xy at H2,\n    apply or.intro_right, exact and.intro H2 h_xy,\n  },\n  {\n    rewrite simp_var_diff h_xy at H2,\n    simp only [simp_term_var] at H2,\n    rewrite <- H2 at h_xy,\n    apply or.intro_left, exact and.intro H2 h_xy,\n  }\n},\ncase sub_is_def.app : P Q x N H1_P H1_Q IH_P IH_Q\n{\n  unfold sub at H2,\n  simp only [simp_term_app] at H2,\n  simp only [simp_term_app],\n  cases H2,\n  {\n    specialize IH_P H2,\n    cases IH_P,\n    {\n      cases IH_P,\n      apply or.intro_left,\n      apply and.intro,\n      apply or.intro_left, exact IH_P_left,\n      exact IH_P_right\n    },\n    {\n      cases IH_P,\n      apply or.intro_right,\n      apply and.intro,\n      exact IH_P_left,\n      apply or.intro_left, exact IH_P_right\n    }\n  },\n  {\n    specialize IH_Q H2,\n    cases IH_Q,\n    {\n      cases IH_Q,\n      apply or.intro_left,\n      apply and.intro,\n      apply or.intro_right, exact IH_Q_left,\n      exact IH_Q_right\n    },\n    {\n      cases IH_Q,\n      apply or.intro_right,\n      apply and.intro,\n      exact IH_Q_left,\n      apply or.intro_right, exact IH_Q_right\n    }\n  }\n},\ncase sub_is_def.abs_same : y P x N IH_1\n{\n  rewrite simp_abs_same IH_1 at H2,\n  apply or.intro_left,\n  apply and.intro,\n  exact H2,\n  rewrite IH_1, symmetry, exact misc_3 H2\n},\ncase sub_is_def.abs_diff_nel : y P x N IH_1 IH_2\n{\n  rewrite lemma_1_2_5_i_b IH_2 at H2,\n  apply or.intro_left,\n  apply and.intro,\n  exact H2,\n  intros h, apply IH_2, rewrite h, exact H2\n},\ncase sub_is_def.abs_diff : y P x N IH_1 IH_2 IH_3 IH_4\n{\n  simp only [simp_term_abs],\n  rewrite simp_abs_diff IH_1 at H2,\n  simp only [simp_term_abs] at H2,\n  cases H2,\n  specialize IH_4 H2_left,\n  cases IH_4,\n  {\n    cases IH_4,\n    apply or.intro_left,\n    apply and.intro,\n    exact and.intro IH_4_left H2_right,\n    exact IH_4_right\n  },\n  {\n    cases IH_4,\n    apply or.intro_right,\n    apply and.intro,\n    exact IH_4_left,\n    exact and.intro IH_4_right IH_1\n  }\n}\nend\n\nlemma lemma_1_2_5_ii_left\n(M : term) (x : var) (N : term) (z : var)\n(H1 : M [ x := N ] is_def)\n(H2 : (z ∈ FV M ∧ x ≠ z) ∨ (z ∈ FV N ∧ x ∈ FV M)) :\nz ∈ FV (M [ x := N ]) :=\nbegin\ninduction H1,\ncase sub_is_def.var : y x N\n{\n  simp only [simp_term_var] at H2,\n  cases H2,\n  {\n    cases H2,\n    rewrite H2_left at H2_right,\n    rewrite simp_var_diff H2_right,\n    simp only [simp_term_var],\n    exact H2_left,\n  },\n  {\n    cases H2,\n    rewrite simp_var_same H2_right,\n    exact H2_left\n  }\n},\ncase sub_is_def.app : P Q x N H1_P H1_Q IH_P IH_Q\n{\n  unfold sub,\n  simp only [simp_term_app],\n  simp only [simp_term_app] at H2,\n  cases H2,\n  {\n    cases H2,\n    cases H2_left,\n    {\n      apply or.intro_left,\n      apply IH_P,\n      apply or.intro_left, exact and.intro H2_left H2_right\n    },\n    {\n      apply or.intro_right,\n      apply IH_Q,\n      apply or.intro_left, exact and.intro H2_left H2_right\n    }\n  },\n  {\n    cases H2,\n    cases H2_right,\n    {\n      apply or.intro_left,\n      apply IH_P,\n      apply or.intro_right, exact and.intro H2_left H2_right\n    },\n    {\n      apply or.intro_right,\n      apply IH_Q,\n      apply or.intro_right, exact and.intro H2_left H2_right\n    }\n  }\n},\ncase sub_is_def.abs_same : y P x N IH_1\n{\n  rewrite simp_abs_same IH_1,\n  cases H2,\n  {\n    cases H2, exact H2_left\n  },\n  {\n    cases H2,\n    simp only [simp_term_abs] at H2_right,\n    cases H2_right, specialize H2_right_right IH_1, contradiction\n  }\n},\ncase sub_is_def.abs_diff_nel : y P x N IH_1 IH_2\n{\n  rewrite lemma_1_2_5_i_b IH_2,\n  cases H2,\n  cases H2, exact H2_left,\n  cases H2, specialize IH_2 H2_right, contradiction\n},\ncase sub_is_def.abs_diff : y P x N IH_1 IH_2 IH_3 IH_4\n{\n  rewrite simp_abs_diff IH_1,\n  simp only [simp_term_abs] at H2,\n  simp only [simp_term_abs],\n  cases H2,\n  {\n    cases H2, cases H2_left,\n    apply and.intro,\n    apply IH_4, apply or.intro_left, exact and.intro H2_left_left H2_right,\n    exact H2_left_right\n  },\n  {\n    cases H2, cases H2_right,\n    apply and.intro,\n    apply IH_4, apply or.intro_right, exact and.intro H2_left H2_right_left,\n    intros h, apply IH_2, rewrite <- h, exact H2_left\n  }\n}\nend\n\nlemma lemma_1_2_5_ii\n{M : term} {x : var} {N : term} {z : var}\n(H1 : M [ x := N ] is_def) :\nz ∈ FV (M [ x := N ]) ↔ (z ∈ FV M ∧ x ≠ z) ∨ (z ∈ FV N ∧ x ∈ FV M) :=\niff.intro (lemma_1_2_5_ii_right M x N z H1) (lemma_1_2_5_ii_left M x N z H1)\n\n\nlemma lemma_1_2_5_iii_a\n{M : term} {x : var} :\nM [ x  := (term.var x) ] is_def :=\nbegin\ninduction M,\ncase term.var : y\n{\n  exact sub_is_def.var\n},\ncase term.app : P Q IH_P IH_Q\n{\n  exact sub_is_def.app IH_P IH_Q\n},\ncase term.abs : y P IH\n{\n  by_cases h_xy : x = y,\n  {\n    exact sub_is_def.abs_same h_xy\n  },\n  {\n    have s1 : y ≠ x, intro h2, apply h_xy, symmetry, exact h2,\n    have s2 : y ∉ FV (term.var x), simp only [simp_term_var], exact s1,\n    exact sub_is_def.abs_diff h_xy s2 IH\n  }\n}\nend\n\nlemma lemma_1_2_5_iii_b\n{M : term} {x : var} :\nM [ x := (term.var x) ] = M :=\nbegin\ninduction M,\ncase term.var : y\n{\n  by_cases h_xy : x = y,\n  rewrite h_xy, apply if_pos, reflexivity,\n  exact if_neg h_xy\n},\ncase term.app : P Q IH_P IH_Q\n{\n  unfold sub, rewrite IH_P, rewrite IH_Q\n},\ncase term.abs : y P IH\n{\n  by_cases h_xy : x = y,\n  {\n    rewrite <- IH,\n    exact if_pos h_xy\n  },\n  {\n    rewrite simp_abs_diff h_xy,\n    rewrite IH\n  }\n}\nend\n\nlemma lemma_1_2_5_iii\n{M : term} {x : var} :\nis_sub M x (term.var x) M :=\nbegin\ninduction M,\ncase term.var : y\n{\n  by_cases h_xy : x = y,\n  rewrite h_xy, apply is_sub.var_same, reflexivity,\n  exact is_sub.var_diff h_xy\n},\ncase term.app : P Q IH_P IH_Q\n{\n  exact is_sub.app IH_P IH_Q\n},\ncase term.abs : y P IH\n{\n  by_cases h_xy : x = y,\n  exact is_sub.abs_same h_xy,\n  apply is_sub.abs_diff h_xy,\n  intro h, apply h_xy, symmetry, simp only [simp_term_var] at h, exact h, exact IH\n}\nend\n\n\nlemma lemma_1_2_6_a_left\n(M N L : term) (x y : var)\n(H1 : M [ x := N ] is_def)\n(H2 : N [ y := L ] is_def)\n(H3 : (M [ x := N ]) [ y := L ] is_def)\n(H4 : x ≠ y)\n(H5 : x ∉ FV L ∨ y ∉ FV M) :\nM [ y := L ] is_def :=\nbegin\ninduction M,\ncase term.var : z\n{\n  exact sub_is_def.var\n},\ncase term.app : P Q IH_P IH_Q\n{\n  cases H1,\n  cases H3,\n  simp only [simp_term_app_not] at H5,\n  apply sub_is_def.app,\n  {\n    apply IH_P H1_ᾰ H3_ᾰ,\n    cases H5,\n    apply or.intro_left, exact H5,\n    cases H5, apply or.intro_right, exact H5_left,\n  },\n  {\n    apply IH_Q H1_ᾰ_1 H3_ᾰ_1,\n    cases H5,\n    apply or.intro_left, exact H5,\n    cases H5, apply or.intro_right, exact H5_right\n  }\n},\ncase term.abs : z P\n{\n  cases H1,\n  {\n    rewrite simp_abs_same H1_ᾰ at H3,\n    exact H3\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ at H3,\n    have s1 : P [ x := N ] = P, exact misc_7' H1_ᾰ_1 H1_ᾰ,\n    rewrite s1 at H3,\n    exact H3\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ at H3,\n    cases H3,\n    {\n      exact sub_is_def.abs_same H3_ᾰ\n    },\n    {\n      apply sub_is_def.abs_diff_nel H3_ᾰ,\n      have s1 : y ∉ FV (P [ x := N ]), exact misc_7 H3_ᾰ_1 H3_ᾰ,\n      have s2 : y ∉ FV P,\n      simp only [lemma_1_2_5_ii H1_ᾰ_2] at s1,\n      push_neg at s1,\n      cases s1, intros h, specialize s1_left h, apply H4, exact s1_left,\n      exact misc_5 s2\n    },\n    {\n      apply sub_is_def.abs_diff H3_ᾰ H3_ᾰ_1,\n      apply M_ih H1_ᾰ_2 H3_ᾰ_2,\n      cases H5,\n      apply or.intro_left, exact H5,\n      apply or.intro_right, exact misc_7 H5 H3_ᾰ\n    }\n  }\n}\nend\n\nlemma lemma_1_2_6_a_right\n(M N L : term) (x y : var)\n(H1 : M [ x := N ] is_def)\n(H2 : N [ y := L ] is_def)\n(H3 : (M [ x := N ]) [ y := L ] is_def)\n(H4 : x ≠ y)\n(H5 : x ∉ FV L ∨ y ∉ FV M) :\n(M [ y := L ]) [ x := N [ y := L ] ] is_def :=\nbegin\ninduction M,\ncase term.var : z\n{\n  by_cases h_yz : y = z,\n  {\n    rewrite simp_var_same h_yz,\n    cases H5,\n    exact lemma_1_2_5_i_a H5,\n    simp only [simp_term_var] at H5, specialize H5 h_yz, contradiction\n  },\n  {\n    rewrite simp_var_diff h_yz,\n    exact sub_is_def.var\n  }\n},\ncase term.app : P Q IH_1 IH_2\n{\n  cases H1,\n  cases H3,\n  simp only [simp_term_app_not] at H5,\n  apply sub_is_def.app,\n  apply IH_1 H1_ᾰ H3_ᾰ,\n  cases H5,\n  apply or.intro_left, exact H5,\n  cases H5, apply or.intro_right, exact H5_left,\n  apply IH_2 H1_ᾰ_1 H3_ᾰ_1,\n  cases H5,\n  apply or.intro_left, exact H5,\n  cases H5, apply or.intro_right, exact H5_right\n},\ncase term.abs : z P\n{\n  cases H1,\n  {\n    have s1 : y ≠ z, rewrite H1_ᾰ at H4, symmetry, exact H4,\n    rewrite simp_abs_diff s1,\n    exact sub_is_def.abs_same H1_ᾰ\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ at H3,\n    have s1 : x ∉ FV P, exact misc_7 H1_ᾰ_1 H1_ᾰ,\n    rewrite lemma_1_2_5_i_b s1 at H3,\n    cases H3,\n    {\n      rewrite simp_abs_same H3_ᾰ,\n      apply sub_is_def.abs_diff_nel H1_ᾰ, exact misc_5 s1\n    },\n    {\n      rewrite lemma_1_2_5_i_b H3_ᾰ_1,\n      exact lemma_1_2_5_i_a H1_ᾰ_1\n    },\n    {\n      rewrite simp_abs_diff H3_ᾰ,\n      apply sub_is_def.abs_diff_nel H1_ᾰ,\n      apply misc_5,\n      simp only [lemma_1_2_5_ii H3_ᾰ_2], push_neg,\n      apply and.intro,\n      intros, specialize s1 ᾰ, contradiction,\n      intros,\n      cases H5,\n      specialize H5 ᾰ, contradiction,\n      exact misc_7 H5 H3_ᾰ\n    }\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ at H3,\n    cases H3,\n    {\n      rewrite simp_abs_same H3_ᾰ,\n      apply sub_is_def.abs_diff H1_ᾰ,\n      rewrite H3_ᾰ, rewrite lemma_1_2_5_i_b H1_ᾰ_1, exact H1_ᾰ_1,\n      rewrite H3_ᾰ, rewrite lemma_1_2_5_i_b H1_ᾰ_1, exact H1_ᾰ_2\n    },\n    {\n      rewrite simp_abs_diff H3_ᾰ,\n      have s1 : y ∉ FV (P [ x := N ]), exact misc_7 H3_ᾰ_1 H3_ᾰ,\n      simp only [lemma_1_2_5_ii H1_ᾰ_2] at s1, push_neg at s1, cases s1,\n      have s2 : y ∉ FV P, intros h, specialize s1_left h, apply H4, exact s1_left,\n      rewrite lemma_1_2_5_i_b s2,\n      by_cases y ∈ FV N,\n      {\n        specialize s1_right h,\n        have s3 : x ∉ FV (term.abs z P), exact misc_5 s1_right,\n        exact lemma_1_2_5_i_a s3\n      },\n      {\n        rewrite lemma_1_2_5_i_b h,\n        exact sub_is_def.abs_diff H1_ᾰ H1_ᾰ_1 H1_ᾰ_2\n      }\n    },\n    {\n      rewrite simp_abs_diff H3_ᾰ,\n      apply sub_is_def.abs_diff H1_ᾰ,\n      simp only [lemma_1_2_5_ii H2], push_neg,\n      apply and.intro,\n      intros, specialize H1_ᾰ_1 ᾰ, contradiction,\n      intros, specialize H3_ᾰ_1 ᾰ, contradiction,\n      apply M_ih H1_ᾰ_2 H3_ᾰ_2,\n      cases H5,\n      apply or.intro_left, exact H5,\n      apply or.intro_right, exact misc_7 H5 H3_ᾰ\n    }\n  }\n}\nend\n\n\nlemma lemma_1_2_6_b\n(M N L : term) (x y : var)\n(H1 : M [ x := N ] is_def)\n(H2 : N [ y := L ] is_def)\n(H3 : (M [ x := N ]) [ y := L ] is_def)\n(H4 : x ≠ y)\n(H5 : x ∉ FV L ∨ y ∉ FV M) :\nM [ x := N ] [ y := L ] = M [ y := L ] [ x := N [ y := L ] ] :=\nbegin\ninduction M,\ncase term.var : z\n{\n  by_cases h_xz : x = z,\n  {\n    have s1 : y ≠ z, rewrite <- h_xz, symmetry, exact H4,\n    rewrite simp_var_diff s1,\n    rewrite simp_var_same h_xz, rewrite simp_var_same h_xz\n  },\n  {\n    rewrite simp_var_diff h_xz,\n    by_cases h_yz : y = z,\n    {\n      rewrite simp_var_same h_yz,\n      cases H5,\n      {\n        rewrite lemma_1_2_5_i_b H5,\n      },\n      {\n        simp only [simp_term_var] at H5,\n        specialize H5 h_yz, contradiction\n      }\n    },\n    {\n      rewrite simp_var_diff h_yz,\n      rewrite simp_var_diff h_xz\n    }\n  }\n},\ncase term.app : P Q IH_P IH_Q\n{\n  cases H1,\n  cases H3,\n  simp only [simp_term_app_not] at H5,\n  cases H5,\n  {\n    have s1 : P [ x := N ] [ y := L ] = P [ y := L ] [ x:= N [ y:= L ] ],\n    apply IH_P H1_ᾰ H3_ᾰ, apply or.intro_left, exact H5,\n    have s2 : Q [ x := N ] [ y := L ] = Q [ y := L ] [ x:= N [ y:= L ] ],\n    apply IH_Q H1_ᾰ_1 H3_ᾰ_1, apply or.intro_left, exact H5,\n    unfold sub, rewrite s1, rewrite s2\n  },\n  {\n    cases H5,\n    have s1 : P [ x := N ] [ y := L ] = P [ y := L ] [ x:= N [ y:= L ] ],\n    apply IH_P H1_ᾰ H3_ᾰ, apply or.intro_right, exact H5_left,\n    have s2 : Q [ x := N ] [ y := L ] = Q [ y := L ] [ x:= N [ y:= L ] ],\n    apply IH_Q H1_ᾰ_1 H3_ᾰ_1, apply or.intro_right, exact H5_right,\n    unfold sub, rewrite s1, rewrite s2\n  }\n},\ncase term.abs : z P\n{\n  cases H1,\n  {\n    rewrite simp_abs_same H1_ᾰ,\n    have s1 : y ≠ z, rewrite <- H1_ᾰ, symmetry, exact H4,\n    rewrite simp_abs_diff s1,\n    rewrite simp_abs_same H1_ᾰ\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ,\n    rewrite simp_abs_diff H1_ᾰ at H3,\n    cases H3,\n    {\n      have s1 : x ∉ FV P, exact misc_7 H1_ᾰ_1 H1_ᾰ,\n      rewrite lemma_1_2_5_i_b s1,\n      rewrite simp_abs_same H3_ᾰ,\n      rewrite simp_abs_diff H1_ᾰ,\n      rewrite lemma_1_2_5_i_b s1\n    },\n    {\n      have s1 : x ∉ FV P, exact misc_7 H1_ᾰ_1 H1_ᾰ,\n      rewrite lemma_1_2_5_i_b s1,\n      rewrite lemma_1_2_5_i_b s1 at H3_ᾰ_1,\n      rewrite simp_abs_diff H3_ᾰ,\n      have s2 : y ∉ FV P, exact misc_7 H3_ᾰ_1 H3_ᾰ,\n      rewrite lemma_1_2_5_i_b s2,\n      rewrite simp_abs_diff H1_ᾰ,\n      rewrite lemma_1_2_5_i_b s1,\n    },\n    {\n      have s1 : x ∉ FV P, exact misc_7 H1_ᾰ_1 H1_ᾰ,\n      rewrite lemma_1_2_5_i_b s1,\n      rewrite simp_abs_diff H3_ᾰ,\n      rewrite simp_abs_diff H1_ᾰ,\n      have s2 : P [ x := N ] is_def, exact lemma_1_2_5_i_a s1,\n      have s3 : x ∉ FV L ∨ y ∉ FV P, cases H5, apply or.intro_left, exact H5, apply or.intro_right, exact misc_7 H5 H3_ᾰ,\n      specialize M_ih s2 H3_ᾰ_2 s3,\n      rewrite <- M_ih, rewrite lemma_1_2_5_i_b s1\n    }\n  },\n  {\n    rewrite simp_abs_diff H1_ᾰ,\n    rewrite simp_abs_diff H1_ᾰ at H3,\n    cases H3,\n    {\n      rewrite simp_abs_same H3_ᾰ,\n      rewrite simp_abs_same H3_ᾰ,\n      rewrite simp_abs_diff H1_ᾰ,\n      rewrite <- H3_ᾰ at H1_ᾰ_1,\n      rewrite lemma_1_2_5_i_b H1_ᾰ_1\n    },\n    {\n      rewrite simp_abs_diff H3_ᾰ,\n      rewrite simp_abs_diff H3_ᾰ,\n      rewrite simp_abs_diff H1_ᾰ,\n      have s1 : y ∉ FV (P [ x := N ]), exact misc_7 H3_ᾰ_1 H3_ᾰ,\n      have s2 : P [ x := N ] [ y := L ] is_def, exact lemma_1_2_5_i_a s1,\n      have s3 : x ∉ FV L ∨ y ∉ FV P, cases H5, apply or.intro_left, exact H5, apply or.intro_right, exact misc_7 H5 H3_ᾰ,\n      specialize M_ih H1_ᾰ_2 s2 s3,\n      rewrite M_ih\n    },\n    {\n      rewrite simp_abs_diff H3_ᾰ,\n      rewrite simp_abs_diff H3_ᾰ,\n      rewrite simp_abs_diff H1_ᾰ,\n      have s1 : x ∉ FV L ∨ y ∉ FV P, cases H5, apply or.intro_left, exact H5, apply or.intro_right, exact misc_7 H5 H3_ᾰ,\n      specialize M_ih H1_ᾰ_2 H3_ᾰ_2 s1,\n      rewrite M_ih\n    }\n  }\n}\nend\n", "meta": {"author": "pthomas505", "repo": "lean3", "sha": "eb449be2b9a92becda4be38aac76e080194e3f7c", "save_path": "github-repos/lean/pthomas505-lean3", "path": "github-repos/lean/pthomas505-lean3/lean3-eb449be2b9a92becda4be38aac76e080194e3f7c/src/metalogic/lambda/lambda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7667781796111403}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_zero\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport Mathlib.Tactic.Relation.Rfl -- rfl tactic\nimport AdditionWorld.Level4 -- add_comm\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\nHere's a nice easy one.\n\n## Level 2: le_refl\n\n## Lemma :\nThe `≤` relation is reflexive. In other words, if `x` is a natural number,\nthen `x ≤ x`.\n-/\nlemma le_refl_mynat (x : MyNat) : x ≤ x := by\n  use 0\n\n/-!\n## Upgrading the `rfl` tactic\n\nNow with the following incantation you can teach the MathLib rfl tactic\nabout our new lemma.\n-/\nattribute [refl] MyNat.le_refl_mynat\n/-!\nNow we find that the `rfl` tactic will close all goals\nof the form `a ≤ a` as well as all goals of the form `a = a`.\n-/\nexample : (0 : MyNat) ≤ 0 := by\n  rfl\n\n/-!\n## Pro tip\n\n-- BUGBUG in lean4 `use 0` closes the proof, so no need for all this stuff\nbelow -- so I need to move this info to another place where it makes sense.\n\nDid you skip `rw [le_iff_exists_add]` in your proof of `le_refl_mynat` above?\nInstead of `rw [add_zero]` or `ring` or `exact add_zero x` at the end there,\nwhat happens if you just try `rfl`? The *definition* of `x + 0` is `x`,\nso you don't need to `rw add_zero` either! The proof\n\n```\nuse 0\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 ≤ b` by `∃ c, b = c + a` (rather\nthan `a + c`) all the same theorems would be true, but `rfl` would work in\ndifferent places. `rfl` closes a goal of the form `X = Y` if `X` and `Y` are\ndefinitionally equal.\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/InequalityWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8688267728417087, "lm_q1q2_score": 0.7666769635363798}}
{"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 linear_algebra.matrix.absolute_value\n! leanprover-community/mathlib commit ab0a2959c83b06280ef576bc830d4aa5fe8c8e61\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.AbsoluteValue\nimport Mathbin.LinearAlgebra.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 × 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 × 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 × 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\n\nopen BigOperators\n\nopen Matrix\n\nnamespace Matrix\n\nopen Equiv Finset\n\nvariable {R S : Type _} [CommRing R] [Nontrivial R] [LinearOrderedCommRing S]\n\nvariable {n : Type _} [Fintype n] [DecidableEq n]\n\ntheorem det_le {A : Matrix n n R} {abv : AbsoluteValue R S} {x : S} (hx : ∀ i j, abv (A i j) ≤ x) :\n    abv A.det ≤ Nat.factorial (Fintype.card n) • x ^ Fintype.card n :=\n  calc\n    abv A.det = abv (∑ σ : Perm n, _) := congr_arg abv (det_apply _)\n    _ ≤ ∑ σ : Perm n, abv _ := (abv.sum_le _ _)\n    _ = ∑ σ : Perm n, ∏ i, abv (A (σ i) i) :=\n      (sum_congr rfl fun σ hσ => by rw [abv.map_units_int_smul, abv.map_prod])\n    _ ≤ ∑ σ : Perm n, ∏ i : n, x :=\n      (sum_le_sum fun _ _ => prod_le_prod (fun _ _ => abv.NonNeg _) fun _ _ => hx _ _)\n    _ = ∑ σ : Perm n, x ^ Fintype.card n :=\n      (sum_congr rfl fun _ _ => by rw [prod_const, Finset.card_univ])\n    _ = Nat.factorial (Fintype.card n) • x ^ Fintype.card n := by\n      rw [sum_const, Finset.card_univ, Fintype.card_perm]\n    \n#align matrix.det_le Matrix.det_le\n\ntheorem det_sum_le {ι : Type _} (s : Finset ι) {A : ι → Matrix n n R} {abv : AbsoluteValue R S}\n    {x : S} (hx : ∀ k i j, abv (A k i j) ≤ x) :\n    abv (det (∑ k in s, A k)) ≤\n      Nat.factorial (Fintype.card n) • (Finset.card s • x) ^ Fintype.card n :=\n  det_le fun i j =>\n    calc\n      abv ((∑ k in s, A k) i j) = abv (∑ k in s, A k i j) := by simp only [sum_apply]\n      _ ≤ ∑ k in s, abv (A k i j) := (abv.sum_le _ _)\n      _ ≤ ∑ k in s, x := (sum_le_sum fun k _ => hx k i j)\n      _ = s.card • x := sum_const _\n      \n#align matrix.det_sum_le Matrix.det_sum_le\n\ntheorem det_sum_smul_le {ι : Type _} (s : Finset ι) {c : ι → R} {A : ι → Matrix n n R}\n    {abv : AbsoluteValue R S} {x : S} (hx : ∀ k i j, abv (A k i j) ≤ x) {y : S}\n    (hy : ∀ k, abv (c k) ≤ y) :\n    abv (det (∑ k in s, c k • A k)) ≤\n      Nat.factorial (Fintype.card n) • (Finset.card s • y * x) ^ Fintype.card n :=\n  by\n  simpa only [smul_mul_assoc] using\n    det_sum_le s fun k i j =>\n      calc\n        abv (c k * A k i j) = abv (c k) * abv (A k i j) := abv.map_mul _ _\n        _ ≤ y * x := mul_le_mul (hy k) (hx k i j) (abv.nonneg _) ((abv.nonneg _).trans (hy k))\n        \n#align matrix.det_sum_smul_le Matrix.det_sum_smul_le\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/AbsoluteValue.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.766657631273768}}
{"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 5 : \"iff\" (`↔`)\n\nWe learn about how to manipulate `P ↔ Q` in Lean.\n\n## Tactics\n\nYou'll need to know about the tactics from the previous sheets,\nand also the following two new tactics:\n\n* `refl`\n* `rw`\n\n-/\n\nvariables (P Q R S : Prop)\n\nexample : P ↔ P :=\nbegin\n  refl,\nend\n\nexample : (P ↔ Q) → (Q ↔ P) :=\nbegin\n  intro h,\n  rw h,\nend\n\nexample : (P ↔ Q) ↔ (Q ↔ P) :=\nbegin\n  split;\n  { intro h,\n    rw h}\nend\n\nexample : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=\nbegin\n  intros h1 h2,\n  rwa h1, -- rwa is rw + assumption\nend\n\nexample : P ∧ Q ↔ Q ∧ P :=\nbegin\n  split;\n  { rintro ⟨h1, h2⟩,\n    exact ⟨h2, h1⟩ }\nend\n\nexample : ((P ∧ Q) ∧ R) ↔ (P ∧ (Q ∧ R)) :=\nbegin\n  split,\n  { intro h,\n    cases h with hPaQ hR,\n    cases hPaQ with hP hQ,\n    split,\n    { exact hP },\n    { split,\n      { exact hQ },\n      { exact hR } } },\n  { rintro ⟨hP, hQ, hR⟩,\n    exact ⟨⟨hP, hQ⟩, hR⟩ }\nend\n\nexample : P ↔ (P ∧ true) :=\nbegin\n  split,\n  { intro hP,\n    split,\n    { exact hP },\n    { triv } },\n  { rintro ⟨hP, -⟩,\n    exact hP }\nend\n\nexample : false ↔ (P ∧ false) :=\nbegin\n  split,\n  { rintro ⟨⟩ },\n  { rintro ⟨-,⟨⟩⟩ }\nend\n\nexample : (P ↔ Q) → (R ↔ S) → (P ∧ R ↔ Q ∧ S) :=\nbegin\n  intros h1 h2,\n  rw h1,\n  rw h2,\nend\n\nexample : ¬ (P ↔ ¬ P) :=\nbegin\n  intro h,\n  cases h with h1 h2,\n  by_cases hP : P,\n  { apply h1; assumption },\n  { apply hP,\n    apply h2,\n    exact hP }\nend\n\n-- constructive proof\nexample : ¬ (P ↔ ¬ P) :=\nbegin\n  intro h,\n  have hnP : ¬ P,\n  { cases h with h1 h2,\n    intro hP,\n    apply h1;\n    assumption },\n  apply hnP,\n  rw h,\n  exact hnP,\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/section01logic/sheet5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7666576264641266}}
{"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\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\n@[simp] lemma mirror_zero : (0 : polynomial R).mirror = 0 := by simp [mirror]\n\nlemma mirror_monomial (n : ℕ) (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        ←C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, rev_at_le (le_refl n),\n        tsub_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        tsub_add_cancel_of_le 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 : ℕ) :\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 ≤ p.nat_degree + p.nat_trailing_degree,\n    { rw [rev_at_le h1, coeff_eq_zero_of_lt_nat_trailing_degree],\n      exact (tsub_lt_iff_left h1).mpr (nat.add_lt_add_right h2 _) },\n    { rw [←rev_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 ≤ n,\n  { rw [←tsub_add_eq_add_tsub h2, ←tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow',\n        if_pos h3, coeff_reverse, rev_at_le (tsub_le_self.trans h2)] },\n  rw not_le at h3,\n  rw coeff_eq_zero_of_nat_degree_lt (lt_tsub_iff_right.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 (λ 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 ↔ p = 0 :=\n⟨λ h, by rw [←p.mirror_mirror, h, mirror_zero], λ h, by rw [h, mirror_zero]⟩\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 _ _), add_tsub_cancel_right]\n\nlemma mirror_leading_coeff : p.mirror.leading_coeff = p.trailing_coeff :=\nby rw [←p.mirror_mirror, mirror_trailing_coeff, p.mirror_mirror]\n\nlemma mirror_mul_of_domain {R : Type*} [ring R] [is_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  rw [mul_assoc, ←mul_assoc q.reverse],\n  conv_lhs { congr, skip, congr, rw [←X_pow_mul] },\n  repeat { rw [mul_assoc], },\nend\n\nlemma mirror_smul {R : Type*} [ring R] [is_domain R] (p : polynomial R) (a : R) :\n  (a • p).mirror = a • p.mirror :=\nby rw [←C_mul', ←C_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*} [comm_ring R] [is_domain R] {f : polynomial R}\n  (h1 : ¬ is_unit f)\n  (h2 : ∀ k, f * f.mirror = k * k.mirror → k = f ∨ k = -f ∨ k = f.mirror ∨ k = -f.mirror)\n  (h3 : ∀ g, g ∣ f → g ∣ f.mirror → 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, ←mul_assoc] },\n    have g_dvd_f : g ∣ f,\n    { rw fgh,\n      exact dvd_mul_right g h },\n    have h_dvd_f : h ∣ f,\n    { rw fgh,\n      exact dvd_mul_left h g },\n    have g_dvd_k : g ∣ k,\n    { exact dvd_mul_right g h.mirror },\n    have h_dvd_k_rev : h ∣ 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 ← 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 ← 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": "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/mirror.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7666576263299268}}
{"text": "import 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 : ∀ x, x ∈ A ∩ C → x ∈ A ∪ B :=\n  assume a,\n  assume h1 : a ∈ A ∩ C,\n\n  show a ∈ A ∪ B, from or.inl (and.left h1)\n\n  example : ∀ x, x ∈ (A ∪ B)ᶜ → x ∈ Aᶜ :=\n  \n  assume a,\n  assume h1 : a ∈ (A ∪ B)ᶜ,\n\n  show ¬ (a ∈ A), from \n      (\n      assume h2 : a ∈ A,\n      have h3 : a ∈ A ∪ B, from or.inl h2,\n      show false, from h1 h3\n      )\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 := ∀ ⦃x⦄, x ∈ A → x ∈ B → false\n\n  example (A B : set U) (h : ∀ x, ¬ (x ∈ A ∧ x ∈ B)) : disj A B :=\n  assume x,\n  assume h1 : x ∈ A,\n  assume h2 : x ∈ B,\n  have h3 : x ∈ A ∧ x ∈ 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 ∈ A) (h3 : x ∈ B) : false :=\n  h1 h2 h3\n\n  -- the same is true of ⊆\n  example (A B : set U) (x : U) (h : A ⊆ B) (h1 : x ∈ A) : x ∈ B :=\n  h h1\n\n  example (A B C D : set U) (h1 : disj A B) (h2 : C ⊆ A) (h3 : D ⊆ B) : disj C D :=\n  assume a,\n  assume e1 : a ∈ C,\n  assume e2 : a ∈ D,\n\n  have e3 : a ∈ A, from h2 e1,\n  have e4 : a ∈ B, from h3 e2,\n\n  show false, from h1 e3 e4\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 → set U} {B : I → set U} {C : set U}\n\n  theorem Inter.intro {x : U} (h : ∀ i, x ∈ A i) : x ∈ ⋂ i, A i :=\n  by simp; assumption\n\n  @[elab_simple]\n  theorem Inter.elim {x : U} (h : x ∈ ⋂ i, A i) (i : I) : x ∈ A i :=\n  by simp at h; apply h\n\n  theorem Union.intro {x : U} (i : I) (h : x ∈ A i) : x ∈ ⋃ i, A i :=\n  by {simp, existsi i, exact h}\n\n  theorem Union.elim {b : Prop} {x : U}\n  (h₁ : x ∈ ⋃ i, A i) (h₂ : ∀ (i : I), x ∈ A i → b) : b :=\n  by {simp at h₁, cases h₁ with i h, exact h₂ i h}\n\n  example : (⋂ i, A i) ∩ (⋂ i, B i) ⊆ (⋂ i, A i ∩ B i) :=\n\n  assume a,\n\n  assume h1 : a ∈ ((⋂ i, A i) ∩ (⋂ i, B i)),\n  \n\n  show a ∈ (⋂ i, A i ∩ B i), from Inter.intro \n    (\n      assume i : I,\n\n      have h2 : a ∈ (⋂ i, B i), from and.right h1,\n      have h3 : a ∈ (⋂ i, A i), from and.left h1,\n\n      have h4 : a ∈ (B i), from Inter.elim h2 i,\n      have h5 : a ∈ (A i), from Inter.elim h3 i,\n\n      show a ∈ (A i ∩ B i), from and.intro h5 h4\n    )\n\n  example : C ∩ (⋃i, A i) ⊆ ⋃i, C ∩ A i :=\n\n  assume a,\n  assume h1 : a ∈ C ∩ (⋃i, A i),\n\n  have h2 : a ∈ (⋃i, A i), from and.right h1,\n  have h3 : a ∈ C, from and.left h1,\n\n  Union.elim h2 \n  (\n    assume i : I,\n    assume temp1 : a ∈ A i,\n    have temp2 : a ∈ C ∩ A i, from and.intro h3 temp1,\n    show a ∈ ⋃i, C ∩ A i, from Union.intro i temp2\n  )\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  -- For this exercise these two facts are useful\n  example (h1 : A ⊆ B) (h2 : B ⊆ C) : A ⊆ C :=\n  subset.trans h1 h2\n\n  example : A ⊆ A :=\n  subset.refl A\n\n  example (h : A ⊆ B) : powerset A ⊆ powerset B :=\n  assume a,\n  assume h1 : a ∈ powerset A,\n\n  show a ∈ powerset B, from subset.trans h1 h\n\n  example (h : powerset A ⊆ powerset B) : A ⊆ B :=\n  \n  show A ⊆ B, from h (subset.refl A)\nend\n\n-- 5. Replace the sorry commands in the following proofs to show that\n-- we can create a partial order R'​ out of a strict partial order R.\nsection\n  parameters {A : Type} {R : A → A → Prop}\n  parameter (irreflR : irreflexive R)\n  parameter (transR : transitive R)\n\n  def R' (a b : A) : Prop := R a b ∨ a = b\n\n  theorem reflR' (a : A) : R' a a :=\n  have h1: a = a, from rfl,\n  or.inr h1 \n\n  theorem transR' {a b c : A} (h1 : R' a b) (h2 : R' b c): R' a c :=\n\n  or.elim h1\n  (\n    assume temp1 : R a b, \n\n    or.elim h2\n     (\n      assume temp2 : R b c,\n        have temp3 : R a c, from transR temp1 temp2,\n        show R' a c, from or.inl temp3\n     )\n\n     (\n      assume temp2 : b = c,\n        show R' a c, from eq.subst temp2 h1\n     )\n\n  )\n  (\n    assume temp1 : a = b,\n      have temp2 : b = a, from symm temp1,\n      show R' a c, from eq.subst temp2 h2\n  )\n\n  theorem antisymmR' {a b : A} (h1 : R' a b) (h2 : R' b a) : a = b :=\n\n  or.elim h1\n  (\n    assume temp1 : R a b,\n\n    or.elim h2\n      (\n        assume temp2 : R b a,\n          have temp3 : R a a, from transR temp1 temp2,\n          show a = b, from false.elim (irreflR a temp3)\n      )\n      (\n        assume temp2 : b = a,\n          show a = b, from symm temp2\n      )\n  )\n  (\n    assume temp1 : a = b,\n      show a = b, from temp1\n  )\nend\n\n-- 6\nsection\n  parameters {A : Type} {R : A → A → Prop}\n  parameter (reflR : reflexive R)\n  parameter (transR : transitive R)\n\n  def S (a b : A) : Prop := R a b ∧ R b a\n\n  example : transitive S :=\n  \n  assume x y z : A,\n  assume a1 : S x y,\n  assume a2 : S y z,\n\n  have h1 : R x z, from transR a1.left a2.left,\n  have h2 : R z x, from transR a2.right a1.right,\n\n  show S x z, from ⟨h1, h2⟩\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 → A → Prop}\n  parameter (Rab : R a b)\n  parameter (Rbc : R b c)\n  parameter (nRac : ¬ R a c)\n\n  theorem R_is_strict_partial_order : irreflexive R ∧ transitive R :=\n  sorry\n\n  theorem R_is_not_strict_partial_order : ¬(irreflexive R ∧ transitive R) :=\n  assume h1 : irreflexive R ∧ transitive R,\n\n  show false, from nRac (h1.right Rab Rbc)\nend\n\n-- 8\nsection\n  open nat\n\n  example : 1 ≤ 4 :=\n\n  have h1 : 1 ≤ 2, from nat.le_succ 1,\n  have h2 : 2 ≤ 3, from nat.le_succ 2,\n\n  have h3 : 1 ≤ 3, from nat.le_trans h1 h2,\n  have h4 : 3 ≤ 4, from nat.le_succ 3,\n\n  show 1 ≤ 4, from nat.le_trans h3 h4\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/hw3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.859663754105328, "lm_q1q2_score": 0.7666576238580062}}
{"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.invariants\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.Basic\nimport Mathbin.RepresentationTheory.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\n\nopen BigOperators\n\nopen MonoidAlgebra\n\nopen Representation\n\nnamespace GroupAlgebra\n\nvariable (k G : Type _) [CommSemiring k] [Group G]\n\nvariable [Fintype G] [Invertible (Fintype.card G : k)]\n\n/-- The average of all elements of the group `G`, considered as an element of `monoid_algebra k G`.\n-/\nnoncomputable def average : MonoidAlgebra k G :=\n  ⅟ (Fintype.card G : k) • ∑ g : G, of k G g\n#align group_algebra.average GroupAlgebra.average\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 : MonoidAlgebra k G) = average k G :=\n  by\n  simp only [mul_one, Finset.mul_sum, Algebra.mul_smul_comm, average, MonoidAlgebra.of_apply,\n    Finset.sum_congr, MonoidAlgebra.single_mul_single]\n  set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1\n  show (⅟ ↑(Fintype.card G) • ∑ x : G, f (g * x)) = ⅟ ↑(Fintype.card G) • ∑ x : G, f x\n  rw [Function.Bijective.sum_comp (Group.mulLeft_bijective g) _]\n#align group_algebra.mul_average_left GroupAlgebra.mul_average_left\n\n/-- `average k G` is invariant under right multiplication by elements of `G`.\n-/\n@[simp]\ntheorem mul_average_right (g : G) : average k G * Finsupp.single g 1 = average k G :=\n  by\n  simp only [mul_one, Finset.sum_mul, Algebra.smul_mul_assoc, average, MonoidAlgebra.of_apply,\n    Finset.sum_congr, MonoidAlgebra.single_mul_single]\n  set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1\n  show (⅟ ↑(Fintype.card G) • ∑ x : G, f (x * g)) = ⅟ ↑(Fintype.card G) • ∑ x : G, f x\n  rw [Function.Bijective.sum_comp (Group.mulRight_bijective g) _]\n#align group_algebra.mul_average_right GroupAlgebra.mul_average_right\n\nend GroupAlgebra\n\nnamespace Representation\n\nsection Invariants\n\nopen GroupAlgebra\n\nvariable {k G V : Type _} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V]\n\nvariable (ρ : Representation k G V)\n\n/-- The subspace of invariants, consisting of the vectors fixed by all elements of `G`.\n-/\ndef invariants : Submodule k V\n    where\n  carrier := setOf fun v => ∀ g : G, ρ g v = v\n  zero_mem' g := by simp only [map_zero]\n  add_mem' v w hv hw g := by simp only [hv g, hw g, map_add]\n  smul_mem' r v hv g := by simp only [hv g, LinearMap.map_smulₛₗ, RingHom.id_apply]\n#align representation.invariants Representation.invariants\n\n@[simp]\ntheorem mem_invariants (v : V) : v ∈ invariants ρ ↔ ∀ g : G, ρ g v = v := by rfl\n#align representation.mem_invariants Representation.mem_invariants\n\ntheorem invariants_eq_inter : (invariants ρ).carrier = ⋂ g : G, Function.fixedPoints (ρ g) :=\n  by\n  ext\n  simp [Function.IsFixedPt]\n#align representation.invariants_eq_inter Representation.invariants_eq_inter\n\nvariable [Fintype G] [Invertible (Fintype.card G : k)]\n\n/-- The action of `average k G` gives a projection map onto the subspace of invariants.\n-/\n@[simp]\nnoncomputable def averageMap : V →ₗ[k] V :=\n  asAlgebraHom ρ (average k G)\n#align representation.average_map Representation.averageMap\n\n/-- The `average_map` sends elements of `V` to the subspace of invariants.\n-/\ntheorem averageMap_invariant (v : V) : averageMap ρ v ∈ invariants ρ := fun g => by\n  rw [average_map, ← as_algebra_hom_single_one, ← LinearMap.mul_apply, ← map_mul (as_algebra_hom ρ),\n    mul_average_left]\n#align representation.average_map_invariant Representation.averageMap_invariant\n\n/-- The `average_map` acts as the identity on the subspace of invariants.\n-/\ntheorem averageMap_id (v : V) (hv : v ∈ invariants ρ) : averageMap ρ v = v :=\n  by\n  rw [mem_invariants] at hv\n  simp [average, map_sum, hv, Finset.card_univ, nsmul_eq_smul_cast k _ v, smul_smul]\n#align representation.average_map_id Representation.averageMap_id\n\ntheorem isProj_averageMap : LinearMap.IsProj ρ.invariants ρ.averageMap :=\n  ⟨ρ.averageMap_invariant, ρ.averageMap_id⟩\n#align representation.is_proj_average_map Representation.isProj_averageMap\n\nend Invariants\n\nnamespace LinHom\n\nuniverse u\n\nopen CategoryTheory Action\n\nsection Rep\n\nvariable {k : Type u} [CommRing k] {G : GroupCat.{u}}\n\ntheorem mem_invariants_iff_comm {X Y : Rep k G} (f : X.V →ₗ[k] Y.V) (g : G) :\n    (linHom X.ρ Y.ρ) g f = f ↔ f.comp (X.ρ g) = (Y.ρ g).comp f :=\n  by\n  dsimp\n  erw [← ρ_Aut_apply_inv]\n  rw [← LinearMap.comp_assoc, ← ModuleCat.comp_def, ← ModuleCat.comp_def, iso.inv_comp_eq,\n    ρ_Aut_apply_hom]\n  exact comm\n#align representation.lin_hom.mem_invariants_iff_comm Representation.linHom.mem_invariants_iff_comm\n\n/-- The invariants of the representation `lin_hom X.ρ Y.ρ` correspond to the the representation\nhomomorphisms from `X` to `Y` -/\n@[simps]\ndef invariantsEquivRepHom (X Y : Rep k G) : (linHom X.ρ Y.ρ).invariants ≃ₗ[k] X ⟶ Y\n    where\n  toFun f := ⟨f.val, fun g => (mem_invariants_iff_comm _ g).1 (f.property g)⟩\n  map_add' _ _ := rfl\n  map_smul' _ _ := rfl\n  invFun f := ⟨f.hom, fun g => (mem_invariants_iff_comm _ g).2 (f.comm g)⟩\n  left_inv _ := by\n    ext\n    rfl\n  right_inv _ := by\n    ext\n    rfl\n#align representation.lin_hom.invariants_equiv_Rep_hom Representation.linHom.invariantsEquivRepHom\n\nend Rep\n\nsection FdRep\n\nvariable {k : Type u} [Field k] {G : GroupCat.{u}}\n\n/-- The invariants of the representation `lin_hom X.ρ Y.ρ` correspond to the the representation\nhomomorphisms from `X` to `Y` -/\ndef invariantsEquivFdRepHom (X Y : FdRep k G) : (linHom X.ρ Y.ρ).invariants ≃ₗ[k] X ⟶ Y :=\n  by\n  rw [← FdRep.forget₂_ρ, ← FdRep.forget₂_ρ]\n  exact lin_hom.invariants_equiv_Rep_hom _ _ ≪≫ₗ FdRep.forget₂HomLinearEquiv X Y\n#align representation.lin_hom.invariants_equiv_fdRep_hom Representation.linHom.invariantsEquivFdRepHom\n\nend FdRep\n\nend LinHom\n\nend Representation\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/Invariants.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7666065793605564}}
{"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.section14polynomials.sheet01degree\n\n/-!\n\n# Noetherian rings\n\n`is_noetherian_ring R` is the predicate that `R` is Noetherian,\ni.e., that all ideals of `R` are finitely generated. The theorem\nsaying that a ring is Noetherian iff all ideals are finitely\ngenerated is called `is_noetherian_ring_iff_ideal_fg R`. \n\nLet me explain the definition of `gens` below. \n\n`is_noetherian_ring_iff_ideal_fg R` is the statement that R is \n  Noetherian ↔ all ideals are finitely generated. An `↔` statement\n  is made in Lean by giving two things; the `→` implication and the `←`\n  implication.\n\n`(is_noetherian_ring_iff_ideal_fg R).1` is the first implication,\nnamely that if `R` is Noetherian then all ideals are finitely generated.\n\nIf `hR : is_noetherian_ring R` then\n`(is_noetherian_ring_iff_ideal_fg R).1 hR` is thus the statement\nthat for all ideals of `R`, they're finitely generated. So it's\na function which eats an ideal of `R` and returns a proof that\nit's finitely generated.\n\nIf furthermore `J` is an ideal of `R` then\n`(is_noetherian_ring_iff_ideal_fg R).1 hR J` is thus the proof that `J`\nis finitely-generated. In other words, it's a proof there exists\na finite set `S : finset R` of elements of `R` such that `S` generates `J`\nas an ideal.\n\n`exists.some` is the function which takes a proof\nthat there exists something with a property, and spits out\na something. It moves from the `Prop` universe to the `Type` universe\nand is hence noncomputable. The proof that the something satisfies\nthe property is `exists.some_spec`.\n\nWith that in mind, I present `is_noetherian_ring.gens`, a function\nwhich eats an ideal of a Noetherian ring and produces a finite\ngenerating set.\n\n-/\n\nvariables {R : Type} [comm_ring R] (I : ideal (polynomial R))\n\nopen polynomial\n\n-- this definition and these lemmas should perhaps be in mathlib?\nnamespace is_noetherian_ring\n\n/-- If `hR : is_noetherian_ring R` and `J : ideal R` then `hR.gens J` is a finite generating set for `J`,\n  expressed as a term of type `finset R`. See `hR.span_gens J` for a proof that it spans. -/\nnoncomputable def gens (hR : is_noetherian_ring R) (J : ideal R) : finset R :=\n((is_noetherian_ring_iff_ideal_fg R).1 hR J).some\n\n/-\n\nThe `gens` function spits out a `finset`, which is the type of finite subsets\nof `R`. There's a coercion to `set R` of course. \n\nThe proof that the generating set does actually span is the same as the\ndefinition, except that you change `some` to `some_spec`.\n\n-/\n\nlemma span_gens (hR : is_noetherian_ring R) (J : ideal R) : ideal.span (hR.gens J : set R) = J :=\n((is_noetherian_ring_iff_ideal_fg R).1 hR J).some_spec\n\n/-\n\nSee if you can prove the useful lemma that the generators of `J` are a subset\nof `J`. The lemma you need from the library is called `ideal.subset_span`.\n-/\n\nlemma gens_subset (hR : is_noetherian_ring R) (J : ideal R) :\n  (hR.gens J : set R) ⊆ J :=\nbegin\n  have h := hR.span_gens J,\n  nth_rewrite 1 ← h,\n  exact ideal.subset_span,\nend\n\nend is_noetherian_ring\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/sheet02noetherian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7666065760658599}}
{"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.convex.integral\nimport measure_theory.integral.interval_integral\n\n/-!\n# Integral average over an interval\n\nIn this file we introduce notation `⨍ x in a..b, f x` for the average `⨍ x in Ι a b, f x` of `f`\nover the interval `Ι a b = set.Ioc (min a b) (max a b)` w.r.t. the Lebesgue measure, then prove\nformulas for this average:\n\n* `interval_average_eq`: `⨍ x in a..b, f x = (b - a)⁻¹ • ∫ x in a..b, f x`;\n* `interval_average_eq_div`: `⨍ x in a..b, f x = (∫ x in a..b, f x) / (b - a)`.\n\nWe also prove that `⨍ x in a..b, f x = ⨍ x in b..a, f x`, see `interval_average_symm`.\n\n## Notation\n\n`⨍ x in a..b, f x`: average of `f` over the interval `Ι a b` w.r.t. the Lebesgue measure.\n\n-/\n\nopen measure_theory set topological_space\nopen_locale interval\n\nvariables {E : Type*} [normed_group E] [normed_space ℝ E] [complete_space E]\n\nnotation `⨍` binders ` in ` a `..` b `, `\n  r:(scoped:60 f, average (measure.restrict volume (Ι a b)) f) := r\n\nlemma interval_average_symm (f : ℝ → E) (a b : ℝ) : ⨍ x in a..b, f x = ⨍ x in b..a, f x :=\nby rw [set_average_eq, set_average_eq, interval_oc_swap]\n\nlemma interval_average_eq (f : ℝ → E) (a b : ℝ) : ⨍ x in a..b, f x = (b - a)⁻¹ • ∫ x in a..b, f x :=\nbegin\n  cases le_or_lt a b with h h,\n  { rw [set_average_eq, interval_oc_of_le h, real.volume_Ioc, interval_integral.integral_of_le h,\n      ennreal.to_real_of_real (sub_nonneg.2 h)] },\n  { rw [set_average_eq, interval_oc_of_lt h, real.volume_Ioc, interval_integral.integral_of_ge h.le,\n     ennreal.to_real_of_real (sub_nonneg.2 h.le), smul_neg, ← neg_smul, ← inv_neg, neg_sub] }\nend\n\nlemma interval_average_eq_div (f : ℝ → ℝ) (a b : ℝ) :\n  ⨍ x in a..b, f x = (∫ x in a..b, f x) / (b - a) :=\nby rw [interval_average_eq, smul_eq_mul, div_eq_inv_mul]\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/integral/interval_average.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7665534648699167}}
{"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\nimport tactic.group\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 : α` and a subset `s ⊆ α`, 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 : α` and a subset `s ⊆ α`, 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 `α` to `α/s` for a subgroup `s` of `α`, 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 ⧸ 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 {α : Type*}\n\n/-- The left coset `a * s` for an element `a : α` and a subset `s : set α` -/\n@[to_additive left_add_coset \"The left coset `a+s` for an element `a : α`\nand a subset `s : set α`\"]\ndef left_coset [has_mul α] (a : α) (s : set α) : set α := (λ x, a * x) '' s\n\n/-- The right coset `s * a` for an element `a : α` and a subset `s : set α` -/\n@[to_additive right_add_coset \"The right coset `s+a` for an element `a : α`\nand a subset `s : set α`\"]\ndef right_coset [has_mul α] (s : set α) (a : α) : set α := (λ 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 α]\n\n@[to_additive mem_left_add_coset]\nlemma mem_left_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a *l s :=\nmem_image_of_mem (λ b : α, a * b) hxS\n\n@[to_additive mem_right_add_coset]\nlemma mem_right_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ s *r a :=\nmem_image_of_mem (λ b : α, 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 α) (a b : α) := a *l s = b *l s\n\n@[to_additive left_add_coset_equivalence_rel]\nlemma left_coset_equivalence_rel (s : set α) : equivalence (left_coset_equivalence s) :=\nmk_equivalence (left_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ 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 α) (a b : α) := s *r a = s *r b\n\n@[to_additive right_add_coset_equivalence_rel]\nlemma right_coset_equivalence_rel (s : set α) : equivalence (right_coset_equivalence s) :=\nmk_equivalence (right_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans)\n\nend coset_mul\n\nsection coset_semigroup\nvariable [semigroup α]\n\n@[simp, to_additive left_add_coset_assoc] lemma left_coset_assoc (s : set α) (a b : α) :\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 α) (a b : α) :\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 α) (a b : α) : 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 α] (s : set α)\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 α] (s : submonoid α)\n\n@[to_additive mem_own_left_add_coset]\nlemma mem_own_left_coset (a : α) : a ∈ a *l s :=\nsuffices a * 1 ∈ 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 : α) : a ∈ (s : set α) *r a :=\nsuffices 1 * a ∈ (s : set α) *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 : α} (ha : a *l s = s) : a ∈ s :=\nby rw [←set_like.mem_coe, ←ha]; 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 : α} (ha : (s : set α) *r a = s) : a ∈ s :=\nby rw [←set_like.mem_coe, ←ha]; exact mem_own_right_coset s a\n\nend coset_submonoid\n\nsection coset_group\nvariables [group α] {s : set α} {x : α}\n\n@[to_additive mem_left_add_coset_iff]\nlemma mem_left_coset_iff (a : α) : x ∈ a *l s ↔ a⁻¹ * x ∈ s :=\niff.intro\n  (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb])\n  (assume h, ⟨a⁻¹ * x, h, by simp⟩)\n\n@[to_additive mem_right_add_coset_iff]\nlemma mem_right_coset_iff (a : α) : x ∈ s *r a ↔ x * a⁻¹ ∈ s :=\niff.intro\n  (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb])\n  (assume h, ⟨x * a⁻¹, h, by simp⟩)\n\nend coset_group\n\nsection coset_subgroup\nopen subgroup\n\nvariables [group α] (s : subgroup α)\n\n@[to_additive left_add_coset_mem_left_add_coset]\nlemma left_coset_mem_left_coset {a : α} (ha : a ∈ 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 : α} (ha : a ∈ s) : (s : set α) *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 : α) : 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 : ∀ g : α, g *l s = s *r g) : s.normal :=\n⟨assume a ha g, show g * a * g⁻¹ ∈ (s : set α),\n  by rw [← mem_right_coset_iff, ← h]; exact mem_left_coset g ha⟩\n\n@[to_additive normal_iff_eq_add_cosets]\ntheorem normal_iff_eq_cosets : s.normal ↔ ∀ g : α, g *l s = s *r g :=\n⟨@eq_cosets_of_normal _ _ s, normal_of_eq_cosets s⟩\n\n@[to_additive left_add_coset_eq_iff]\nlemma left_coset_eq_iff {x y : α} : left_coset x s = left_coset y s ↔ x⁻¹ * y ∈ 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 ←mul_inv_cancel_right x⁻¹ 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 : α} : right_coset ↑s x = right_coset s y ↔ y * x⁻¹ ∈ 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 ←inv_mul_cancel_left y x⁻¹, rw ←mul_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 α] (s : subgroup α)\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 α :=\n⟨λ x y, x⁻¹ * y ∈ s, by { simp_rw ←left_coset_eq_iff, exact left_coset_equivalence_rel s }⟩\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 (∈ s)] :\n  decidable_rel (left_rel s).r := λ x y, ‹decidable_pred (∈ s)› _\n\n/-- `α ⧸ s` is the quotient type representing the left cosets of `s`.\n  If `s` is a normal subgroup, `α ⧸ s` is a group -/\n@[to_additive \"`α ⧸ s` is the quotient type representing the left cosets of `s`.  If `s` is a\nnormal subgroup, `α ⧸ s` is a group\"]\ninstance : has_quotient α (subgroup α) := ⟨λ s, quotient (left_rel s)⟩\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 α :=\n⟨λ x y, y * x⁻¹ ∈ s, by { simp_rw ←right_coset_eq_iff, exact right_coset_equivalence_rel s }⟩\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 (∈ s)] :\n  decidable_rel (right_rel s).r := λ x y, ‹decidable_pred (∈ s)› _\n\n/-- Right cosets are in bijection with left cosets. -/\n@[to_additive \"Right cosets are in bijection with left cosets.\"]\ndef quotient_right_rel_equiv_quotient_left_rel : quotient (quotient_group.right_rel s) ≃ α ⧸ s :=\n{ to_fun := quotient.map' (λ g, g⁻¹) (λ a b h, (congr_arg (∈ s) (by group)).mp (s.inv_mem h)),\n  inv_fun := quotient.map' (λ g, g⁻¹) (λ a b h, (congr_arg (∈ s) (by group)).mp (s.inv_mem h)),\n  left_inv := λ g, quotient.induction_on' g (λ g, quotient.sound' (by\n  { simp only [inv_inv],\n    exact quotient.exact' rfl })),\n  right_inv := λ g, quotient.induction_on' g (λ g, quotient.sound' (by\n  { simp only [inv_inv],\n    exact quotient.exact' rfl })) }\n\nend quotient_group\n\nnamespace quotient_group\n\nvariables [group α] {s : subgroup α}\n\n@[to_additive]\ninstance fintype [fintype α] (s : subgroup α) [decidable_rel (left_rel s).r] :\n  fintype (α ⧸ s) :=\nquotient.fintype (left_rel s)\n\n/-- The canonical map from a group `α` to the quotient `α ⧸ s`. -/\n@[to_additive \"The canonical map from an `add_group` `α` to the quotient `α ⧸ s`.\"]\nabbreviation mk (a : α) : α ⧸ s :=\nquotient.mk' a\n\n@[to_additive]\nlemma mk_surjective : function.surjective $ @mk _ _ s := quotient.surjective_quotient_mk'\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on {C : α ⧸ s → Prop} (x : α ⧸ s)\n  (H : ∀ z, C (quotient_group.mk z)) : C x :=\nquotient.induction_on' x H\n\n@[to_additive]\ninstance : has_coe_t α (α ⧸ s) := ⟨mk⟩ -- note [use has_coe_t]\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on' {C : α ⧸ s → Prop} (x : α ⧸ s)\n  (H : ∀ z : α, C z) : C x :=\nquotient.induction_on' x H\n\n@[simp, to_additive]\nlemma quotient_lift_on_coe {β} (f : α → β) (h) (x : α) :\n  quotient.lift_on' (x : α ⧸ s) f h = f x := rfl\n\n@[to_additive]\nlemma forall_coe {C : α ⧸ s → Prop} :\n  (∀ x : α ⧸ s, C x) ↔ ∀ x : α, C x :=\n⟨λ hx x, hx _, quot.ind⟩\n\n@[to_additive]\ninstance (s : subgroup α) : inhabited (α ⧸ s) :=\n⟨((1 : α) : α ⧸ s)⟩\n\n@[to_additive quotient_add_group.eq]\nprotected lemma eq {a b : α} : (a : α ⧸ s) = b ↔ a⁻¹ * b ∈ s :=\nquotient.eq'\n\n@[to_additive quotient_add_group.eq']\nlemma eq' {a b : α} : (mk a : α ⧸ s) = mk b ↔ a⁻¹ * b ∈ s :=\nquotient_group.eq\n\n@[to_additive quotient_add_group.out_eq']\nlemma out_eq' (a : α ⧸ s) : mk a.out' = a :=\nquotient.out_eq' a\n\nvariables (s)\n\n/- It can be useful to write `obtain ⟨h, H⟩ := 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⁻¹ * (mk g).out'`. -/\n@[to_additive quotient_add_group.mk_out'_eq_mul]\nlemma mk_out'_eq_mul (g : α) : ∃ h : s, (mk g : α ⧸ s).out' = g * h :=\n⟨⟨g⁻¹ * (mk g).out', eq'.mp (mk g).out_eq'.symm⟩, by rw [s.coe_mk, mul_inv_cancel_left]⟩\n\nvariables {s}\n\n@[to_additive quotient_add_group.mk_mul_of_mem]\nlemma mk_mul_of_mem (g₁ g₂ : α) (hg₂ : g₂ ∈ s) : (mk (g₁ * g₂) : α ⧸ s) = mk g₁ :=\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 α) (g : α) :\n  {x : α | (x : α ⧸ s) = g} = left_coset g s :=\nset.ext $ λ 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 α) (s : set α) :\n  coe ⁻¹' ((coe : α → α ⧸ N) '' s) = ⋃ x : N, (λ y : α, y * x) ⁻¹' 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, ← eq_inv_mul_iff_mul_eq],\n  exact ⟨λ ⟨y, hs, hN⟩, ⟨_, N.inv_mem hN, by simpa using hs⟩,\n         λ ⟨z, hz, hxz⟩, ⟨x*z, hxz, by simpa using hz⟩⟩,\nend\n\nend quotient_group\n\nnamespace subgroup\nopen quotient_group\nvariables [group α] {s : subgroup α}\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 : α) : left_coset g s ≃ s :=\n⟨λ x, ⟨g⁻¹ * x.1, (mem_left_coset_iff _).1 x.2⟩,\n λ x, ⟨g * x.1, x.1, x.2, rfl⟩,\n λ ⟨x, hx⟩, subtype.eq $ by simp,\n λ ⟨g, hg⟩, subtype.eq $ by simp⟩\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 : α) : right_coset ↑s g ≃ s :=\n⟨λ x, ⟨x.1 * g⁻¹, (mem_right_coset_iff _).1 x.2⟩,\n λ x, ⟨x.1 * g, x.1, x.2, rfl⟩,\n λ ⟨x, hx⟩, subtype.eq $ by simp,\n λ ⟨g, hg⟩, subtype.eq $ by simp⟩\n\n/-- A (non-canonical) bijection between a group `α` and the product `(α/s) × s` -/\n@[to_additive \"A (non-canonical) bijection between an add_group `α` and the product `(α/s) × s`\"]\nnoncomputable def group_equiv_quotient_times_subgroup :\n  α ≃ (α ⧸ s) × s :=\ncalc α ≃ Σ L : α ⧸ s, {x : α // (x : α ⧸ s) = L} :\n  (equiv.sigma_preimage_equiv quotient_group.mk).symm\n    ... ≃ Σ L : α ⧸ s, left_coset (quotient.out' L) s :\n  equiv.sigma_congr_right (λ L,\n    begin\n      rw ← eq_class_eq_left_coset,\n      show _root_.subtype (λ x : α, quotient.mk' x = L) ≃\n        _root_.subtype (λ x : α, quotient.mk' x = quotient.mk' _),\n      simp [-quotient.eq'],\n    end)\n    ... ≃ Σ L : α ⧸ s, s :\n  equiv.sigma_congr_right (λ L, left_coset_equiv_subgroup _)\n    ... ≃ (α ⧸ s) × s :\n  equiv.sigma_equiv_prod _ _\n\nvariables {t : subgroup α}\n\n/-- If `H ≤ K`, then `G/H ≃ G/K × K/H` constructively, using the provided right inverse\nof the quotient map `G → G/K`. The classical version is `quotient_equiv_prod_of_le`. -/\n@[to_additive \"If `H ≤ K`, then `G/H ≃ G/K × K/H` constructively, using the provided right inverse\nof the quotient map `G → G/K`. The classical version is `quotient_equiv_prod_of_le`.\", simps]\ndef quotient_equiv_prod_of_le' (h_le : s ≤ t)\n  (f : α ⧸ t → α) (hf : function.right_inverse f quotient_group.mk) :\n  α ⧸ s ≃ (α ⧸ t) × (t ⧸ s.subgroup_of t) :=\n{ to_fun := λ a, ⟨a.map' id (λ b c h, h_le h),\n    a.map' (λ g : α, ⟨(f (quotient.mk' g))⁻¹ * g, quotient.exact' (hf g)⟩) (λ b c h, by\n    { change ((f b)⁻¹ * b)⁻¹ * ((f c)⁻¹ * c) ∈ 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] })⟩,\n  inv_fun := λ a, a.2.map' (λ b, f a.1 * b) (λ b c h, by\n  { change (f a.1 * b)⁻¹ * (f a.1 * c) ∈ s,\n    rwa [mul_inv_rev, mul_assoc, inv_mul_cancel_left] }),\n  left_inv := by\n  { refine quotient.ind' (λ 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' (λ a, _),\n    refine quotient.ind' (λ b, _),\n    have key : quotient.mk' (f (quotient.mk' a) * b) = quotient.mk' a :=\n      (quotient_group.mk_mul_of_mem (f a) ↑b 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 ≤ K`, then `G/H ≃ G/K × K/H` nonconstructively.\nThe constructive version is `quotient_equiv_prod_of_le'`. -/\n@[to_additive \"If `H ≤ K`, then `G/H ≃ G/K × K/H` nonconstructively.\nThe constructive version is `quotient_equiv_prod_of_le'`.\", simps]\nnoncomputable def quotient_equiv_prod_of_le (h_le : s ≤ t) :\n  α ⧸ s ≃ (α ⧸ t) × (t ⧸ s.subgroup_of t) :=\nquotient_equiv_prod_of_le' h_le quotient.out' quotient.out_eq'\n\n/-- If `K ≤ L`, then there is an embedding `K ⧸ (H.subgroup_of K) ↪ L ⧸ (H.subgroup_of L)`. -/\n@[to_additive \"If `K ≤ L`, then there is an embedding\n  `K ⧸ (H.add_subgroup_of K) ↪ L ⧸ (H.add_subgroup_of L)`.\"]\ndef quotient_subgroup_of_embedding_of_le (H : subgroup α) {K L : subgroup α} (h : K ≤ L) :\n  K ⧸ (H.subgroup_of K) ↪ L ⧸ (H.subgroup_of L) :=\n{ to_fun := quotient.map' (set.inclusion h) (λ a b, id),\n  inj' := by refine quotient.ind₂' (λ a b, _); exact quotient.eq'.mpr ∘ quotient.eq'.mp }\n\n@[to_additive] lemma card_eq_card_quotient_mul_card_subgroup\n  [fintype α] (s : subgroup α) [fintype s] [decidable_pred (λ a, a ∈ s)] :\n  fintype.card α = fintype.card (α ⧸ s) * fintype.card s :=\nby rw ← fintype.card_prod;\n  exact fintype.card_congr (subgroup.group_equiv_quotient_times_subgroup)\n\n/-- **Lagrange's Theorem**: The order of a subgroup divides the order of its ambient group. -/\n@[to_additive] lemma card_subgroup_dvd_card [fintype α] (s : subgroup α) [fintype s] :\n  fintype.card s ∣ fintype.card α :=\nby classical; simp [card_eq_card_quotient_mul_card_subgroup s, @dvd_mul_left ℕ]\n\n@[to_additive] lemma card_quotient_dvd_card [fintype α] (s : subgroup α)\n  [decidable_pred (λ a, a ∈ s)] [fintype s] : fintype.card (α ⧸ s) ∣ fintype.card α :=\nby simp [card_eq_card_quotient_mul_card_subgroup s, @dvd_mul_right ℕ]\n\nopen fintype\n\nvariables {H : Type*} [group H]\n\n@[to_additive] lemma card_dvd_of_injective [fintype α] [fintype H] (f : α →* H)\n  (hf : function.injective f) : card α ∣ card H :=\nby classical;\ncalc card α = card (f.range : subgroup H) : card_congr (equiv.of_injective f hf)\n...∣ card H : card_subgroup_dvd_card _\n\n@[to_additive] lemma card_dvd_of_le {H K : subgroup α} [fintype H] [fintype K] (hHK : H ≤ K) :\n  card H ∣ 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 : α →* H) [fintype (K.comap f)] (hf : function.injective f) :\n  fintype.card (K.comap f) ∣ 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... ∣ fintype.card K : card_dvd_of_le (map_comap_le _ _)\n\nend subgroup\n\nnamespace quotient_group\n\nvariables [group α]\n\n-- FIXME -- why is there no `to_additive`?\n\n/-- If `s` is a subgroup of the group `α`, and `t` is a subset of `α/s`, then\nthere is a (typically non-canonical) bijection between the preimage of `t` in\n`α` and the product `s × t`. -/\nnoncomputable def preimage_mk_equiv_subgroup_times_set\n  (s : subgroup α) (t : set (α ⧸ s)) : quotient_group.mk ⁻¹' t ≃ s × t :=\nhave h : ∀ {x : α ⧸ s} {a : α}, x ∈ t → a ∈ s →\n  (quotient.mk' (quotient.out' x * a) : α ⧸ s) = quotient.mk' (quotient.out' x) :=\n    λ x a hx ha, quotient.sound' (show (quotient.out' x * a)⁻¹ * quotient.out' x ∈ s,\n      from (s.inv_mem_iff).1 $\n        by rwa [mul_inv_rev, inv_inv, ← mul_assoc, inv_mul_self, one_mul]),\n{ to_fun := λ ⟨a, ha⟩, ⟨⟨(quotient.out' (quotient.mk' a))⁻¹ * a,\n    @quotient.exact' _ (left_rel s) _ _ $ (quotient.out_eq' _)⟩,\n      ⟨quotient.mk' a, ha⟩⟩,\n  inv_fun := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, ⟨quotient.out' x * a, show quotient.mk' _ ∈ t,\n    by simp [h hx ha, hx]⟩,\n  left_inv := λ ⟨a, ha⟩, subtype.eq $ show _ * _ = a, by simp,\n  right_inv := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, 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": "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/coset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7665534635379574}}
{"text": "import tactic data.nat.basic\nopen nat\n\n/--------------------------------------------------------------------------\n\n  ``rw``\n\n    If ``f`` is a term of type ``P = Q`` (or ``P ↔ Q``), then\n    ``rw f`` replaces ``P`` with ``Q`` in the target.\n    Other variants:\n      ``rw f at hp``, ``rw ←f``, ``rw ←f at hr``.\n\n  Delete the ``sorry,`` below and replace them with a legitimate proof.\n\n  --------------------------------------------------------------------------/\n\ntheorem add_self_self_eq_double\n  (x : ℕ)\n: x + x = 2 * x :=\nbegin\n  rw two_mul,\nend\n\n/-\nFor the following problem, use\n  mul_comm a b : a * b = b * a\n-/\n\nexample (a b c d : ℕ)\n  (hyp : c = d * a + b)\n  (hyp' : b = a * d)\n: c = 2 * (a * d) :=\nbegin\n  sorry,\nend\n\n/-\nFor the following problem, use\n  nat.sub_self (x : ℕ) : x - x = 0\n-/\n\nexample (a b c d : ℕ)\n  (hyp : c = b * a - d)\n  (hyp' : d = a * b)\n: c = 0 :=\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/day2/rw_examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7665519784920014}}
{"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\n! This file was ported from Lean 3 source module number_theory.prime_counting\n! leanprover-community/mathlib commit 16de0889b9e841c59af6cfece272b9276f9bf5ae\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.PrimeFin\nimport Mathbin.Data.Nat.Totient\nimport Mathbin.Data.Finset.LocallyFinite\nimport Mathbin.Data.Nat.Count\nimport Mathbin.Data.Nat.Nth\n\n/-!\n# The Prime Counting Function\n\nIn this file we define the prime counting function: the function on natural numbers that returns\nthe number of primes less than or equal to its input.\n\n## Main Results\n\nThe main definitions for this file are\n\n- `nat.prime_counting`: The prime counting function π\n- `nat.prime_counting'`: π(n - 1)\n\nWe then prove that these are monotone in `nat.monotone_prime_counting` and\n`nat.monotone_prime_counting'`. The last main theorem `nat.prime_counting'_add_le` is an upper\nbound on `π'` which arises by observing that all numbers greater than `k` and not coprime to `k`\nare not prime, and so only at most `φ(k)/k` fraction of the numbers from `k` to `n` are prime.\n\n## Notation\n\nWe use the standard notation `π` to represent the prime counting function (and `π'` to represent\nthe reindexed version).\n\n-/\n\n\nnamespace Nat\n\nopen Finset\n\n/-- A variant of the traditional prime counting function which gives the number of primes\n*strictly* less than the input. More convenient for avoiding off-by-one errors.\n-/\ndef primeCounting' : ℕ → ℕ :=\n  Nat.count Prime\n#align nat.prime_counting' Nat.primeCounting'\n\n/-- The prime counting function: Returns the number of primes less than or equal to the input. -/\ndef primeCounting (n : ℕ) : ℕ :=\n  primeCounting' (n + 1)\n#align nat.prime_counting Nat.primeCounting\n\n-- mathport name: prime_counting\nscoped notation \"π\" => Nat.primeCounting\n\n-- mathport name: prime_counting'\nscoped notation \"π'\" => Nat.primeCounting'\n\ntheorem monotone_primeCounting' : Monotone primeCounting' :=\n  count_monotone Prime\n#align nat.monotone_prime_counting' Nat.monotone_primeCounting'\n\ntheorem monotone_primeCounting : Monotone primeCounting :=\n  monotone_primeCounting'.comp (monotone_id.AddConst _)\n#align nat.monotone_prime_counting Nat.monotone_primeCounting\n\n@[simp]\ntheorem primeCounting'_nth_eq (n : ℕ) : π' (nth Prime n) = n :=\n  count_nth_of_infinite _ infinite_setOf_prime _\n#align nat.prime_counting'_nth_eq Nat.primeCounting'_nth_eq\n\n@[simp]\ntheorem prime_nth_prime (n : ℕ) : Prime (nth Prime n) :=\n  nth_mem_of_infinite _ infinite_setOf_prime _\n#align nat.prime_nth_prime Nat.prime_nth_prime\n\n/-- A linear upper bound on the size of the `prime_counting'` function -/\ntheorem primeCounting'_add_le {a k : ℕ} (h0 : 0 < a) (h1 : a < k) (n : ℕ) :\n    π' (k + n) ≤ π' k + Nat.totient a * (n / a + 1) :=\n  calc\n    π' (k + n) ≤ ((range k).filterₓ Prime).card + ((Ico k (k + n)).filterₓ Prime).card :=\n      by\n      rw [prime_counting', count_eq_card_filter_range, range_eq_Ico, ←\n        Ico_union_Ico_eq_Ico (zero_le k) le_self_add, filter_union]\n      apply card_union_le\n    _ ≤ π' k + ((Ico k (k + n)).filterₓ Prime).card := by\n      rw [prime_counting', count_eq_card_filter_range]\n    _ ≤ π' k + ((Ico k (k + n)).filterₓ (coprime a)).card :=\n      by\n      refine' add_le_add_left (card_le_of_subset _) k.prime_counting'\n      simp only [subset_iff, and_imp, mem_filter, mem_Ico]\n      intro p succ_k_le_p p_lt_n p_prime\n      constructor\n      · exact ⟨succ_k_le_p, p_lt_n⟩\n      · rw [coprime_comm]\n        exact coprime_of_lt_prime h0 (gt_of_ge_of_gt succ_k_le_p h1) p_prime\n    _ ≤ π' k + totient a * (n / a + 1) :=\n      by\n      rw [add_le_add_iff_left]\n      exact Ico_filter_coprime_le k n h0\n    \n#align nat.prime_counting'_add_le Nat.primeCounting'_add_le\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/PrimeCounting.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563335, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7664936801974974}}
{"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! This file was ported from Lean 3 source module linear_algebra.affine_space.slope\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.LinearAlgebra.AffineSpace.AffineMap\nimport Mathlib.Tactic.FieldSimp\n\n/-!\n# Slope of a function\n\nIn this file we define the slope of a function `f : k → 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\n-- Porting note: Workaround for lean4#2074\nattribute [-instance] Ring.toNonAssocRing\n\nopen AffineMap\n\nvariable {k E PE : Type _} [Field k] [AddCommGroup E] [Module k E] [AddTorsor E PE]\n\n/-- `slope f a b = (b - a)⁻¹ • (f b -ᵥ 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 → PE) (a b : k) : E :=\n  (b - a)⁻¹ • (f b -ᵥ f a)\n#align slope slope\n\ntheorem slope_fun_def (f : k → PE) : slope f = fun a b => (b - a)⁻¹ • (f b -ᵥ f a) :=\n  rfl\n#align slope_fun_def slope_fun_def\n\ntheorem slope_def_field (f : k → k) (a b : k) : slope f a b = (f b - f a) / (b - a) :=\n  (div_eq_inv_mul _ _).symm\n#align slope_def_field slope_def_field\n\ntheorem slope_fun_def_field (f : k → k) (a : k) : slope f a = fun b => (f b - f a) / (b - a) :=\n  (div_eq_inv_mul _ _).symm\n#align slope_fun_def_field slope_fun_def_field\n\n@[simp]\ntheorem slope_same (f : k → PE) (a : k) : (slope f a a : E) = 0 := by\n  rw [slope, sub_self, inv_zero, zero_smul]\n#align slope_same slope_same\n\ntheorem slope_def_module (f : k → E) (a b : k) : slope f a b = (b - a)⁻¹ • (f b - f a) :=\n  rfl\n#align slope_def_module slope_def_module\n\n@[simp]\ntheorem sub_smul_slope (f : k → PE) (a b : k) : (b - a) • slope f a b = f b -ᵥ f a := by\n  rcases eq_or_ne a b with (rfl | hne)\n  · rw [sub_self, zero_smul, vsub_self]\n  · rw [slope, smul_inv_smul₀ (sub_ne_zero.2 hne.symm)]\n#align sub_smul_slope sub_smul_slope\n\ntheorem sub_smul_slope_vadd (f : k → PE) (a b : k) : (b - a) • slope f a b +ᵥ f a = f b := by\n  rw [sub_smul_slope, vsub_vadd]\n#align sub_smul_slope_vadd sub_smul_slope_vadd\n\n@[simp]\ntheorem slope_vadd_const (f : k → E) (c : PE) : (slope fun x => f x +ᵥ c) = slope f := by\n  ext (a b)\n  simp only [slope, vadd_vsub_vadd_cancel_right, vsub_eq_sub]\n#align slope_vadd_const slope_vadd_const\n\n@[simp]\ntheorem slope_sub_smul (f : k → E) {a b : k} (h : a ≠ b) :\n    slope (fun x => (x - a) • f x) a b = f b := by\n  simp [slope, inv_smul_smul₀ (sub_ne_zero.2 h.symm)]\n#align slope_sub_smul slope_sub_smul\n\ntheorem eq_of_slope_eq_zero {f : k → PE} {a b : k} (h : slope f a b = (0 : E)) : f a = f b := by\n  rw [← sub_smul_slope_vadd f a b, h, smul_zero, zero_vadd]\n#align eq_of_slope_eq_zero eq_of_slope_eq_zero\n\ntheorem AffineMap.slope_comp {F PF : Type _} [AddCommGroup F] [Module k F] [AddTorsor F PF]\n    (f : PE →ᵃ[k] PF) (g : k → PE) (a b : k) : slope (f ∘ g) a b = f.linear (slope g a b) := by\n  simp only [slope, (· ∘ ·), f.linear.map_smul, f.linearMap_vsub]\n#align affine_map.slope_comp AffineMap.slope_comp\n\ntheorem LinearMap.slope_comp {F : Type _} [AddCommGroup F] [Module k F] (f : E →ₗ[k] F) (g : k → E)\n    (a b : k) : slope (f ∘ g) a b = f (slope g a b) :=\n  f.toAffineMap.slope_comp g a b\n#align linear_map.slope_comp LinearMap.slope_comp\n\ntheorem slope_comm (f : k → PE) (a b : k) : slope f a b = slope f b a := by\n  rw [slope, slope, ← neg_vsub_eq_vsub_rev, smul_neg, ← neg_smul, neg_inv, neg_sub]\n#align slope_comm slope_comm\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 ≠ c`, then the sum of the coefficients is `1`, so it is\nactually an affine combination, see `lineMap_slope_slope_sub_div_sub`. -/\ntheorem sub_div_sub_smul_slope_add_sub_div_sub_smul_slope (f : k → PE) (a b c : k) :\n    ((b - a) / (c - a)) • slope f a b + ((c - b) / (c - a)) • slope f b c = slope f a c := by\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;\n  · subst hbc\n    simp [sub_ne_zero.2 (Ne.symm hab)]\n  rw [add_comm]\n  simp_rw [slope, div_eq_inv_mul, mul_smul, ← smul_add,\n    smul_inv_smul₀ (sub_ne_zero.2 <| Ne.symm hab), smul_inv_smul₀ (sub_ne_zero.2 <| Ne.symm hbc),\n    vsub_add_vsub_cancel]\n#align sub_div_sub_smul_slope_add_sub_div_sub_smul_slope sub_div_sub_smul_slope_add_sub_div_sub_smul_slope\n\n/-- `slope f a c` is an affine combination of `slope f a b` and `slope f b c`. This version uses\n`lineMap` to express this property. -/\ntheorem lineMap_slope_slope_sub_div_sub (f : k → PE) (a b c : k) (h : a ≠ c) :\n    lineMap (slope f a b) (slope f b c) ((c - b) / (c - a)) = slope f a c := by\n  field_simp [sub_ne_zero.2 h.symm, ← sub_div_sub_smul_slope_add_sub_div_sub_smul_slope f a b c,\n    lineMap_apply_module]\n#align line_map_slope_slope_sub_div_sub lineMap_slope_slope_sub_div_sub\n\n/-- `slope f a b` is an affine combination of `slope f a (lineMap a b r)` and\n`slope f (lineMap a b r) b`. We use `lineMap` to express this property. -/\ntheorem lineMap_slope_lineMap_slope_lineMap (f : k → PE) (a b r : k) :\n    lineMap (slope f (lineMap a b r) b) (slope f a (lineMap a b r)) r = slope f a b := by\n  obtain rfl | hab : a = b ∨ a ≠ b := Classical.em _; · simp\n  rw [slope_comm _ a, slope_comm _ a, slope_comm _ _ b]\n  convert lineMap_slope_slope_sub_div_sub f b (lineMap a b r) a hab.symm using 2\n  rw [lineMap_apply_ring, eq_div_iff (sub_ne_zero.2 hab), sub_mul, one_mul, mul_sub, ← sub_sub,\n    sub_sub_cancel]\n#align line_map_slope_line_map_slope_line_map lineMap_slope_lineMap_slope_lineMap\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/Slope.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011833, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.7664936714738911}}
{"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-- import the definition and basic properties of ℂ\nimport complex.Level_00_basic\n\n/-! # Level 1 : the map from ℝ to ℂ\n\nThis file sets up the coercion from the reals to the complexes,\nsending `r` to `⟨r, 0⟩`. Mathematically it is straightforward.\n\nAll the proofs below are sorried. You can try them in tactic mode\nby replacing `sorry` with `begin sorry end` and then starting to write \ntactics in the `begin end` block.\n\n-/\n\nnamespace complex\n\n-- fill in the definition of the map below,\n-- sending the real number r to the complex number ⟨r, 0⟩\n\n/-- The canonical map from ℝ to ℂ. -/\ndef of_real (r : ℝ) : ℂ := ⟨r, 0⟩\n\n/-\nWe make this map into a *coercion*, which means that if `(r : ℝ)` is a real\nnumber, then `(r : ℂ)` or `(↑r : ℂ)` 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 ℝ to ℂ sending `r` to the complex number `⟨r, 0⟩` -/\ninstance : has_coe ℝ ℂ := ⟨of_real⟩\n\n/-\nAs usual, we need to train the `simp` tactic. But we also need to train\nthe `norm_cast` tactic. The `norm_cast` tactic enables Lean to prove\nresults like r^2=2*s for reals `r` and `s`, if it knows that\n`(r : ℂ)^2 = 2*(s : ℂ)`. Such results are intuitive for matheamticians\nbut involve \"invisible maps\" in Lean\n-/\n\n@[simp, norm_cast] lemma of_real_re (r : ℝ) : (r : ℂ).re = r :=\nbegin\n  refl\nend\n\n@[simp, norm_cast] lemma of_real_im (r : ℝ) : (r : ℂ).im = 0 := rfl\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\nlocal attribute [simp] ext_iff\n\n@[simp, norm_cast] theorem of_real_inj {r s : ℝ} : (r : ℂ) = s ↔ r = s :=\nbegin\n  simp\nend\n\n\n-- what does norm_cast do?? Here are two examples of usage:\n\n/-\n\nexample (r s : ℝ) (h : (r : ℂ) = s) : r = s :=\nbegin\n  norm_cast at h,\n  exact h,\nend\n\nexample (r s : ℝ) (h : r = s) : (r : ℂ) = (s : ℂ) :=\nbegin\n  norm_cast,\n  exact h,\nend\n\n-/\n\n/-\nWe now go through all the basic constants and constructions we've defined so\nfar, namely 0, 1, +, -, *, and tell the simplifier how they behave with respect\nto this new function. \n-/\n\n/-! ## zero -/\n\n@[simp, norm_cast] lemma of_real_zero : ((0 : ℝ) : ℂ) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {r : ℝ} : (r : ℂ) = 0 ↔ r = 0 :=\nbegin\n  simp,\nend\n\ntheorem of_real_ne_zero {r : ℝ} : (r : ℂ) ≠ 0 ↔ r ≠ 0 :=\nbegin\n  simp\nend\n\n/-! ## one -/\n\n@[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 1 := rfl\n\n/-! ## add -/\n\n@[simp, norm_cast] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s :=\nbegin\n  simp\nend\n\n/-! ## neg -/\n\n@[simp, norm_cast] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r :=\nbegin\n  simp\nend\n\n/-! ## mul -/\n\n@[simp, norm_cast] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s :=\nbegin\n  simp  \nend\n\n/-- The canonical ring homomorphism from ℝ to ℂ -/\ndef Of_real : ℝ →+* ℂ :=\n{ to_fun := coe, -- use the coercion from ℝ to ℂ\n  map_zero' := of_real_zero,\n  map_one' := of_real_one,\n  map_add' := of_real_add,\n  map_mul' := of_real_mul,\n}\n\n/-! ## numerals.\n\nThis is quite a computer-sciency bit.\n\nThese last two lemmas are to do with the canonical map from numerals\ninto the complexes, e.g. `(23 : ℂ)`. Lean stores the numeral in binary.\nSee for example\n\nset_option pp.numerals false\n#check (37 : ℂ)-- bit1 (bit0 (bit1 (bit0 (bit0 has_one.one)))) : ℂ\n\n`bit0 x` is defined to be `x + x`, and `bit1 x` is defined to be `bit0 x + 1`.\n\nWe need these results so that `norm_cast` can prove results such\nas (↑(37 : ℝ) : ℂ) = 37 : ℂ (i.e. coercion commutes with numerals)\n\n-/\n\n@[simp, norm_cast] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r :=\nbegin\n  simp [bit0],\nend\n\n@[simp, norm_cast] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r :=\nbegin\n  simp [bit1],\nend\n\nend complex\n\n/-! ## norm_cast examples \n\nThe idea is that the \"invisible map\" from the reals to the complexes should not\ncreate any trouble to mathematicians who just want things to work as normal\n\nhttps://xenaproject.wordpress.com/2020/04/30/the-invisible-map/\n\n\nexample (a b c : ℝ) : ((a * b : ℝ) : ℂ) * c = (a : ℂ) * b * c :=\nbegin\n  norm_cast,\nend\n\nexample (a b c : ℝ) : ((a : ℂ) + b) * c = ((a + b) * c : ℝ) :=\nbegin\n  norm_cast,\nend\n\nexample : (37 : ℂ) = (37 : ℝ) :=\nbegin\n  norm_cast,\nend\n\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/src/complex/kb_solutions/Level_01_of_real.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.8840392695254319, "lm_q1q2_score": 0.7664936688599612}}
{"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-/\nimport algebra.regular.smul\nimport linear_algebra.matrix.adjugate\nimport linear_algebra.matrix.polynomial\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⁻¹` (`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⁻¹` (`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* `⅟A` (`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 `⁻¹` 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 `⅟A` and `ring.inverse A`.\nThe rest of the results in the file are then about `A⁻¹`\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\nnamespace matrix\nuniverses u u' v\nvariables {m : Type u} {n : Type u'} {α : Type v}\nopen_locale matrix big_operators\nopen equiv equiv.perm finset\n\n/-! ### Matrices are `invertible` iff their determinants are -/\n\nsection invertible\nvariables [fintype n] [decidable_eq n] [comm_ring α]\n\n/-- A copy of `inv_of_mul_self` using `⬝` not `*`. -/\nprotected lemma inv_of_mul_self (A : matrix n n α) [invertible A] : ⅟A ⬝ A = 1 := inv_of_mul_self A\n\n/-- A copy of `mul_inv_of_self` using `⬝` not `*`. -/\nprotected lemma mul_inv_of_self (A : matrix n n α) [invertible A] : A ⬝ ⅟A = 1 := mul_inv_of_self A\n\n/-- A copy of `inv_of_mul_self_assoc` using `⬝` not `*`. -/\nprotected lemma inv_of_mul_self_assoc (A : matrix n n α) (B : matrix n m α) [invertible A] :\n  ⅟A ⬝ (A ⬝ B) = B :=\nby rw [←matrix.mul_assoc, matrix.inv_of_mul_self, matrix.one_mul]\n\n/-- A copy of `mul_inv_of_self_assoc` using `⬝` not `*`. -/\nprotected lemma mul_inv_of_self_assoc (A : matrix n n α) (B : matrix n m α) [invertible A] :\n  A ⬝ (⅟A ⬝ B) = B :=\nby rw [←matrix.mul_assoc, matrix.mul_inv_of_self, matrix.one_mul]\n\n/-- A copy of `mul_inv_of_mul_self_cancel` using `⬝` not `*`. -/\nprotected lemma mul_inv_of_mul_self_cancel (A : matrix m n α) (B : matrix n n α)\n  [invertible B] : A ⬝ ⅟B ⬝ B = A :=\nby rw [matrix.mul_assoc, matrix.inv_of_mul_self, matrix.mul_one]\n\n/-- A copy of `mul_mul_inv_of_self_cancel` using `⬝` not `*`. -/\nprotected lemma mul_mul_inv_of_self_cancel (A : matrix m n α) (B : matrix n n α)\n  [invertible B] : A ⬝ B ⬝ ⅟B = A :=\nby rw [matrix.mul_assoc, matrix.mul_inv_of_self, matrix.mul_one]\n\nvariables (A : matrix n n α) (B : matrix n n α)\n\n/-- If `A.det` has a constructive inverse, produce one for `A`. -/\ndef invertible_of_det_invertible [invertible A.det] : invertible A :=\n{ inv_of := ⅟A.det • A.adjugate,\n  mul_inv_of_self :=\n    by rw [mul_smul_comm, matrix.mul_eq_mul, mul_adjugate, smul_smul, inv_of_mul_self, one_smul],\n  inv_of_mul_self :=\n    by rw [smul_mul_assoc, matrix.mul_eq_mul, adjugate_mul, smul_smul, inv_of_mul_self, one_smul] }\n\nlemma inv_of_eq [invertible A.det] [invertible A] : ⅟A = ⅟A.det • A.adjugate :=\nby { letI := invertible_of_det_invertible A, convert (rfl : ⅟A = _) }\n\n/-- `A.det` is invertible if `A` has a left inverse. -/\ndef det_invertible_of_left_inverse (h : B ⬝ A = 1) : invertible A.det :=\n{ inv_of := B.det,\n  mul_inv_of_self := by rw [mul_comm, ← det_mul, h, det_one],\n  inv_of_mul_self := by rw [← det_mul, h, det_one] }\n\n/-- `A.det` is invertible if `A` has a right inverse. -/\ndef det_invertible_of_right_inverse (h : A ⬝ B = 1) : invertible A.det :=\n{ inv_of := B.det,\n  mul_inv_of_self := by rw [← det_mul, h, det_one],\n  inv_of_mul_self := by rw [mul_comm, ← det_mul, h, det_one] }\n\n/-- If `A` has a constructive inverse, produce one for `A.det`. -/\ndef det_invertible_of_invertible [invertible A] : invertible A.det :=\ndet_invertible_of_left_inverse A (⅟A) (inv_of_mul_self _)\n\nlemma det_inv_of [invertible A] [invertible A.det] : (⅟A).det = ⅟A.det :=\nby { letI := det_invertible_of_invertible A, convert (rfl : _ = ⅟A.det) }\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 invertible_equiv_det_invertible : invertible A ≃ invertible A.det :=\n{ to_fun := @det_invertible_of_invertible _ _ _ _ _ A,\n  inv_fun := @invertible_of_det_invertible _ _ _ _ _ A,\n  left_inv := λ _, subsingleton.elim _ _,\n  right_inv := λ _, subsingleton.elim _ _ }\n\nvariables {A B}\n\nlemma mul_eq_one_comm : A ⬝ B = 1 ↔ B ⬝ A = 1 :=\nsuffices ∀ A B, A ⬝ B = 1 → B ⬝ A = 1, from ⟨this A B, this B A⟩, assume A B h,\nbegin\n  letI : invertible B.det := det_invertible_of_left_inverse _ _ h,\n  letI : invertible B := invertible_of_det_invertible B,\n  calc B ⬝ A = (B ⬝ A) ⬝ (B ⬝ ⅟B) : by rw [matrix.mul_inv_of_self, matrix.mul_one]\n        ... = B ⬝ ((A ⬝ B) ⬝ ⅟B) : by simp only [matrix.mul_assoc]\n        ... = B ⬝ ⅟B : by rw [h, matrix.one_mul]\n        ... = 1 : matrix.mul_inv_of_self B,\nend\n\nvariables (A B)\n\n/-- We can construct an instance of invertible A if A has a left inverse. -/\ndef invertible_of_left_inverse (h : B ⬝ A = 1) : invertible A :=\n⟨B, h, mul_eq_one_comm.mp h⟩\n\n/-- We can construct an instance of invertible A if A has a right inverse. -/\ndef invertible_of_right_inverse (h : A ⬝ B = 1) : invertible A :=\n⟨B, mul_eq_one_comm.mp h, h⟩\n\n/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(matrix n n α)ˣ`-/\ndef unit_of_det_invertible [invertible A.det] : (matrix n n α)ˣ :=\n@unit_of_invertible _ _ A (invertible_of_det_invertible A)\n\n/-- When lowered to a prop, `matrix.invertible_equiv_det_invertible` forms an `iff`. -/\nlemma is_unit_iff_is_unit_det : is_unit A ↔ is_unit A.det :=\nbegin\n  split; rintros ⟨x, hx⟩; refine @is_unit_of_invertible _ _ _ (id _),\n  { haveI : invertible A := hx.rec x.invertible,\n    apply det_invertible_of_invertible, },\n  { haveI : invertible A.det := hx.rec x.invertible,\n    apply invertible_of_det_invertible, },\nend\n\n/-! #### Variants of the statements above with `is_unit`-/\n\nlemma is_unit_det_of_invertible [invertible A] : is_unit A.det :=\n@is_unit_of_invertible _ _ _ (det_invertible_of_invertible A)\n\nvariables {A B}\n\nlemma is_unit_det_of_left_inverse (h : B ⬝ A = 1) : is_unit A.det :=\n@is_unit_of_invertible _ _ _ (det_invertible_of_left_inverse _ _ h)\n\nlemma is_unit_det_of_right_inverse (h : A ⬝ B = 1) : is_unit A.det :=\n@is_unit_of_invertible _ _ _ (det_invertible_of_right_inverse _ _ h)\n\nlemma det_ne_zero_of_left_inverse [nontrivial α] (h : B ⬝ A = 1) : A.det ≠ 0 :=\n(is_unit_det_of_left_inverse h).ne_zero\n\nlemma det_ne_zero_of_right_inverse [nontrivial α] (h : A ⬝ B = 1) : A.det ≠ 0 :=\n(is_unit_det_of_right_inverse h).ne_zero\n\nend invertible\n\nvariables [fintype m] [fintype n] [decidable_eq m] [decidable_eq n] [comm_ring α]\nvariables (A : matrix n n α) (B : matrix n n α)\n\nlemma is_unit_det_transpose (h : is_unit A.det) : is_unit Aᵀ.det :=\nby { rw det_transpose, exact h, }\n\n/-! ### A noncomputable `has_inv` instance  -/\n\n/-- The inverse of a square matrix, when it is invertible (and zero otherwise).-/\nnoncomputable instance : has_inv (matrix n n α) := ⟨λ A, ring.inverse A.det • A.adjugate⟩\n\nlemma inv_def (A : matrix n n α) : A⁻¹ = ring.inverse A.det • A.adjugate := rfl\n\nlemma nonsing_inv_apply_not_is_unit (h : ¬ is_unit A.det) :\n  A⁻¹ = 0 :=\nby rw [inv_def, ring.inverse_non_unit _ h, zero_smul]\n\nlemma nonsing_inv_apply (h : is_unit A.det) :\n  A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate :=\nby rw [inv_def, ←ring.inverse_unit h.unit, is_unit.unit_spec]\n\n/-- The nonsingular inverse is the same as `inv_of` when `A` is invertible. -/\n@[simp] lemma inv_of_eq_nonsing_inv [invertible A] : ⅟A = A⁻¹ :=\nbegin\n  letI := det_invertible_of_invertible A,\n  rw [inv_def, ring.inverse_invertible, inv_of_eq],\nend\n\n/-- Coercing the result of `units.has_inv` is the same as coercing first and applying the\nnonsingular inverse. -/\n@[simp, norm_cast] lemma coe_units_inv (A : (matrix n n α)ˣ) :\n  ↑(A⁻¹) = (A⁻¹ : matrix n n α) :=\nbegin\n  letI := A.invertible,\n  rw [←inv_of_eq_nonsing_inv, inv_of_units],\nend\n\n/-- The nonsingular inverse is the same as the general `ring.inverse`. -/\nlemma nonsing_inv_eq_ring_inverse : A⁻¹ = ring.inverse A :=\nbegin\n  by_cases h_det : is_unit A.det,\n  { casesI (A.is_unit_iff_is_unit_det.mpr h_det).nonempty_invertible,\n    rw [←inv_of_eq_nonsing_inv, ring.inverse_invertible], },\n  { 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], },\nend\n\nlemma transpose_nonsing_inv : (A⁻¹)ᵀ = (Aᵀ)⁻¹ :=\nby rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]\n\nlemma conj_transpose_nonsing_inv [star_ring α] : (A⁻¹)ᴴ = (Aᴴ)⁻¹ :=\nby rw [inv_def, inv_def, conj_transpose_smul, det_conj_transpose, adjugate_conj_transpose,\n       ring.inverse_star]\n\n/-- The `nonsing_inv` of `A` is a right inverse. -/\n@[simp] lemma mul_nonsing_inv (h : is_unit A.det) : A ⬝ A⁻¹ = 1 :=\nbegin\n  casesI (A.is_unit_iff_is_unit_det.mpr h).nonempty_invertible,\n  rw [←inv_of_eq_nonsing_inv, matrix.mul_inv_of_self],\nend\n\n/-- The `nonsing_inv` of `A` is a left inverse. -/\n@[simp] lemma nonsing_inv_mul (h : is_unit A.det) : A⁻¹ ⬝ A = 1 :=\nbegin\n  casesI (A.is_unit_iff_is_unit_det.mpr h).nonempty_invertible,\n  rw [←inv_of_eq_nonsing_inv, matrix.inv_of_mul_self],\nend\n\n@[simp] lemma mul_inv_of_invertible [invertible A] : A ⬝ A⁻¹ = 1 :=\nmul_nonsing_inv A (is_unit_det_of_invertible A)\n\n@[simp] lemma inv_mul_of_invertible [invertible A] : A⁻¹ ⬝ A = 1 :=\nnonsing_inv_mul A (is_unit_det_of_invertible A)\n\nlemma nonsing_inv_cancel_or_zero :\n  (A⁻¹ ⬝ A = 1 ∧ A ⬝ A⁻¹ = 1) ∨ A⁻¹ = 0 :=\nbegin\n  by_cases h : is_unit A.det,\n  { exact or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩ },\n  { exact or.inr (nonsing_inv_apply_not_is_unit _ h) }\nend\n\nlemma det_nonsing_inv_mul_det (h : is_unit A.det) : A⁻¹.det * A.det = 1 :=\nby rw [←det_mul, A.nonsing_inv_mul h, det_one]\n\n@[simp] lemma det_nonsing_inv : A⁻¹.det = ring.inverse A.det :=\nbegin\n  by_cases h : is_unit A.det,\n  { casesI h.nonempty_invertible, letI := invertible_of_det_invertible A,\n    rw [ring.inverse_invertible, ←inv_of_eq_nonsing_inv, det_inv_of] },\n  casesI is_empty_or_nonempty n,\n  { rw [det_is_empty, det_is_empty, ring.inverse_one] },\n  { rw [ring.inverse_non_unit _ h, nonsing_inv_apply_not_is_unit _ h, det_zero ‹_›] },\nend\n\nlemma is_unit_nonsing_inv_det (h : is_unit A.det) : is_unit A⁻¹.det :=\nis_unit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)\n\n@[simp] lemma nonsing_inv_nonsing_inv (h : is_unit A.det) : (A⁻¹)⁻¹ = A :=\ncalc (A⁻¹)⁻¹ = 1 ⬝ (A⁻¹)⁻¹        : by rw matrix.one_mul\n         ... = A ⬝ A⁻¹ ⬝ (A⁻¹)⁻¹  : by rw A.mul_nonsing_inv h\n         ... = A                  : by { rw [matrix.mul_assoc,\n                                         (A⁻¹).mul_nonsing_inv (A.is_unit_nonsing_inv_det h),\n                                         matrix.mul_one], }\n\nlemma is_unit_nonsing_inv_det_iff {A : matrix n n α} :\n  is_unit A⁻¹.det ↔ is_unit A.det :=\nby rw [matrix.det_nonsing_inv, is_unit_ring_inverse]\n\n/- `is_unit.invertible` lifts the proposition `is_unit A` to a constructive inverse of `A`. -/\n\n/-- A version of `matrix.invertible_of_det_invertible` with the inverse defeq to `A⁻¹` that is\ntherefore noncomputable. -/\nnoncomputable def invertible_of_is_unit_det (h : is_unit A.det) : invertible A :=\n⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩\n\n/-- A version of `matrix.units_of_det_invertible` with the inverse defeq to `A⁻¹` that is therefore\nnoncomputable. -/\nnoncomputable def nonsing_inv_unit (h : is_unit A.det) : (matrix n n α)ˣ :=\n@unit_of_invertible _ _ _ (invertible_of_is_unit_det A h)\n\nlemma unit_of_det_invertible_eq_nonsing_inv_unit [invertible A.det] :\n  unit_of_det_invertible A = nonsing_inv_unit A (is_unit_of_invertible _) :=\nby { ext, refl }\n\nvariables {A} {B}\n\n/-- If matrix A is left invertible, then its inverse equals its left inverse. -/\nlemma inv_eq_left_inv (h : B ⬝ A = 1) : A⁻¹ = B :=\nbegin\n  letI := invertible_of_left_inverse _ _ h,\n  exact inv_of_eq_nonsing_inv A ▸ inv_of_eq_left_inv h,\nend\n\n/-- If matrix A is right invertible, then its inverse equals its right inverse. -/\nlemma inv_eq_right_inv (h : A ⬝ B = 1) : A⁻¹ = B :=\ninv_eq_left_inv (mul_eq_one_comm.2 h)\n\nsection inv_eq_inv\n\nvariables {C : matrix n n α}\n\n/-- The left inverse of matrix A is unique when existing. -/\n\n\n/-- The right inverse of matrix A is unique when existing. -/\nlemma right_inv_eq_right_inv (h : A ⬝ B = 1) (g : A ⬝ C = 1) : B = C :=\nby rw [←inv_eq_right_inv h, ←inv_eq_right_inv g]\n\n/-- The right inverse of matrix A equals the left inverse of A when they exist. -/\nlemma right_inv_eq_left_inv (h : A ⬝ B = 1) (g : C ⬝ A = 1) : B = C :=\nby rw [←inv_eq_right_inv h, ←inv_eq_left_inv g]\n\nlemma inv_inj (h : A⁻¹ = B⁻¹) (h' : is_unit A.det) : A = B :=\nbegin\n  refine left_inv_eq_left_inv (mul_nonsing_inv _ h') _,\n  rw h,\n  refine mul_nonsing_inv _ _,\n  rwa [←is_unit_nonsing_inv_det_iff, ←h, is_unit_nonsing_inv_det_iff]\nend\n\nend inv_eq_inv\n\nvariable (A)\n\n@[simp] lemma inv_zero : (0 : matrix n n α)⁻¹ = 0 :=\nbegin\n  casesI (subsingleton_or_nontrivial α) with ht ht,\n  { simp },\n  cases (fintype.card n).zero_le.eq_or_lt with hc hc,\n  { rw [eq_comm, fintype.card_eq_zero_iff] at hc,\n    haveI := hc,\n    ext i,\n    exact (is_empty.false i).elim },\n  { have hn : nonempty n := fintype.card_pos_iff.mp hc,\n    refine nonsing_inv_apply_not_is_unit _ _,\n    simp [hn] },\nend\n\n@[simp] lemma inv_one : (1 : matrix n n α)⁻¹ = 1 :=\ninv_eq_left_inv (by simp)\n\nlemma inv_smul (k : α) [invertible k] (h : is_unit A.det) : (k • A)⁻¹ = ⅟k • A⁻¹ :=\ninv_eq_left_inv (by simp [h, smul_smul])\n\nlemma inv_smul' (k : αˣ) (h : is_unit A.det) : (k • A)⁻¹ = k⁻¹ • A⁻¹ :=\ninv_eq_left_inv (by simp [h, smul_smul])\n\nlemma inv_adjugate (A : matrix n n α) (h : is_unit A.det) :\n  (adjugate A)⁻¹ = h.unit⁻¹ • A :=\nbegin\n  refine inv_eq_left_inv _,\n  rw [smul_mul, mul_adjugate, units.smul_def, smul_smul, h.coe_inv_mul, one_smul]\nend\n\n@[simp] lemma inv_inv_inv (A : matrix n n α) : A⁻¹⁻¹⁻¹ = A⁻¹ :=\nbegin\n  by_cases h : is_unit A.det,\n  { rw [nonsing_inv_nonsing_inv _ h] },\n  { simp [nonsing_inv_apply_not_is_unit _ h] }\nend\n\nlemma mul_inv_rev (A B : matrix n n α) : (A ⬝ B)⁻¹ = B⁻¹ ⬝ A⁻¹ :=\nbegin\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],\nend\n\n/-- A version of `list.prod_inv_reverse` for `matrix.has_inv`. -/\nlemma list_prod_inv_reverse : ∀ l : list (matrix n n α), l.prod⁻¹ = (l.reverse.map has_inv.inv).prod\n| [] := by rw [list.reverse_nil, list.map_nil, list.prod_nil, inv_one]\n| (A :: Xs) := by rw [list.reverse_cons', list.map_concat, list.prod_concat, list.prod_cons,\n                      matrix.mul_eq_mul, matrix.mul_eq_mul, mul_inv_rev, list_prod_inv_reverse]\n\n/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/\n@[simp] lemma det_smul_inv_mul_vec_eq_cramer (A : matrix n n α) (b : n → α) (h : is_unit A.det) :\n  A.det • A⁻¹.mul_vec b = cramer A b :=\nbegin\n  rw [cramer_eq_adjugate_mul_vec, A.nonsing_inv_apply h, ← smul_mul_vec_assoc,\n      smul_smul, h.mul_coe_inv, one_smul]\nend\n\n/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/\n@[simp] lemma det_smul_inv_vec_mul_eq_cramer_transpose\n  (A : matrix n n α) (b : n → α) (h : is_unit A.det) :\n  A.det • A⁻¹.vec_mul b = cramer Aᵀ b :=\nby rw [← (A⁻¹).transpose_transpose, vec_mul_transpose, transpose_nonsing_inv, ← det_transpose,\n    Aᵀ.det_smul_inv_mul_vec_eq_cramer _ (is_unit_det_transpose A h)]\n\n/-! ### More results about determinants -/\n\n/-- A variant of `matrix.det_units_conj`. -/\nlemma det_conj {M : matrix m m α} (h : is_unit M) (N : matrix m m α) :\n  det (M ⬝ N ⬝ M⁻¹) = det N :=\nby rw [←h.unit_spec, ←coe_units_inv, det_units_conj]\n\n/-- A variant of `matrix.det_units_conj'`. -/\nlemma det_conj' {M : matrix m m α} (h : is_unit M) (N : matrix m m α) :\n  det (M⁻¹ ⬝ N ⬝ M) = det N :=\nby rw [←h.unit_spec, ←coe_units_inv, det_units_conj']\n\n/-- Determinant of a 2×2 block matrix, expanded around an invertible top left element in terms of\nthe Schur complement. -/\nlemma det_from_blocks₁₁ (A : matrix m m α) (B : matrix m n α) (C : matrix n m α) (D : matrix n n α)\n  [invertible A] : (matrix.from_blocks A B C D).det = det A * det (D - C ⬝ (⅟A) ⬝ B) :=\nbegin\n  have : from_blocks A B C D =\n    from_blocks 1 0 (C ⬝ ⅟A) 1 ⬝ from_blocks A 0 0 (D - C ⬝ (⅟A) ⬝ B) ⬝ from_blocks 1 (⅟A ⬝ B) 0 1,\n  { simp only [from_blocks_multiply, matrix.mul_zero, matrix.zero_mul, add_zero, zero_add,\n      matrix.one_mul, matrix.mul_one, matrix.inv_of_mul_self, matrix.mul_inv_of_self_assoc,\n        matrix.mul_inv_of_mul_self_cancel, matrix.mul_assoc, add_sub_cancel'_right] },\n  rw [this, det_mul, det_mul, det_from_blocks_zero₂₁, det_from_blocks_zero₂₁,\n    det_from_blocks_zero₁₂, det_one, det_one, one_mul, one_mul, mul_one],\nend\n\n@[simp] lemma det_from_blocks_one₁₁ (B : matrix m n α) (C : matrix n m α) (D : matrix n n α) :\n  (matrix.from_blocks 1 B C D).det = det (D - C ⬝ B) :=\nbegin\n  haveI : invertible (1 : matrix m m α) := invertible_one,\n  rw [det_from_blocks₁₁, inv_of_one, matrix.mul_one, det_one, one_mul],\nend\n\n/-- Determinant of a 2×2 block matrix, expanded around an invertible bottom right element in terms\nof the Schur complement. -/\nlemma det_from_blocks₂₂ (A : matrix m m α) (B : matrix m n α) (C : matrix n m α) (D : matrix n n α)\n  [invertible D] : (matrix.from_blocks A B C D).det = det D * det (A - B ⬝ (⅟D) ⬝ C) :=\nbegin\n  have : from_blocks A B C D = (from_blocks D C B A).minor (sum_comm _ _) (sum_comm _ _),\n  { ext i j,\n    cases i; cases j; refl },\n  rw [this, det_minor_equiv_self, det_from_blocks₁₁],\nend\n\n@[simp] lemma det_from_blocks_one₂₂ (A : matrix m m α) (B : matrix m n α) (C : matrix n m α) :\n  (matrix.from_blocks A B C 1).det = det (A - B ⬝ C) :=\nbegin\n  haveI : invertible (1 : matrix n n α) := invertible_one,\n  rw [det_from_blocks₂₂, inv_of_one, matrix.mul_one, det_one, one_mul],\nend\n\n/-- The **Weinstein–Aronszajn identity**. Note the `1` on the LHS is of shape m×m, while the `1` on\nthe RHS is of shape n×n. -/\nlemma det_one_add_mul_comm (A : matrix m n α) (B : matrix n m α) :\n  det (1 + A ⬝ B) = det (1 + B ⬝ A) :=\ncalc  det (1 + A ⬝ B)\n    = det (from_blocks 1 (-A) B 1) : by rw [det_from_blocks_one₂₂, matrix.neg_mul, sub_neg_eq_add]\n... = det (1 + B ⬝ A)              : by rw [det_from_blocks_one₁₁, matrix.mul_neg, sub_neg_eq_add]\n\n/-- Alternate statement of the **Weinstein–Aronszajn identity** -/\nlemma det_mul_add_one_comm (A : matrix m n α) (B : matrix n m α) :\n  det (A ⬝ B + 1) = det (B ⬝ A + 1) :=\nby rw [add_comm, det_one_add_mul_comm, add_comm]\n\nlemma det_one_sub_mul_comm (A : matrix m n α) (B : matrix n m α) :\n  det (1 - A ⬝ B) = det (1 - B ⬝ A) :=\nby rw [sub_eq_add_neg, ←matrix.neg_mul, det_one_add_mul_comm, matrix.mul_neg, ←sub_eq_add_neg]\n\n/-- A special case of the **Matrix determinant lemma** for when `A = I`.\n\nTODO: show this more generally. -/\nlemma det_one_add_col_mul_row (u v : m → α) : det (1 + col u ⬝ row v) = 1 + v ⬝ᵥ u :=\nby 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\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/nonsingular_inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7664152362360629}}
{"text": "import data.real.basic\nopen function\nopen real\n\n/-\nClassic eps-delta definition of continuity.\nUse it to prove continuity at one point for a simple function.\nTo be proved equivalent to topological definition in topology world.\n\nWork in progress.\n-/\n\nnotation `|` x `|` := abs x\n\ndef continuous_at_x (f : ℝ → ℝ) (x : ℝ) := \n    ∀ ε : ℝ, 0 < ε → ∃ δ : ℝ, 0 < δ ∧ ∀ y : ℝ, |x - y| < δ → |f x - f y| < ε\ndef square_f (x : ℝ) := x^2\n\n/- Lemma\nThe function $f(x) = x^2$ is continuous at $x=3$.\n-/\nlemma square_continuous_at_3 : continuous_at_x square_f (3:ℝ) :=\nbegin\n    intros ε hε,\n    set d := min (1:ℝ) (ε/7) with hdefd,\n    use d,\n    split,\n    { -- prove this d is positive\n        have h1 : 0 < (1:ℝ), linarith,\n        have h2 : 0 < (ε/7), linarith,\n        simp, split, exact h1, exact h2, \n    },\n    intros y hy,\n    unfold square_f,\n    have H : 3^2 - y^2 = (3-y)*(3+y), ring,\n    have G : | 3^2 - y^2 | = | (3-y)*(3+y) |, rw H,\n    have F : | (3-y)*(3+y) | = |3-y| * |3+y|, exact abs_mul _ _,\n    rw F at G, rw G,\n    have h1 := abs_lt.1 hy,\n    cases h1 with h11 h12,\n    have h1y : y < 3 + d, linarith,\n    have h2y : 3 - d < y, linarith,\n    have hdd : d ≤ 1, exact min_le_left (1:ℝ) (ε/7),\n    have h3y : y < 4, linarith,\n    have h4y : 2 < y, linarith,\n    have h44 : 0 < |3+y|, \n        have h45 : 0 < 3 + y, linarith, \n        have h46 := abs_of_pos h45,\n        rw ← h46 at h45, exact h45,\n    have h5y :=  (mul_lt_mul_right h44).mpr hy,\n    have h6y : 3+y < 7, linarith, \n    have h7y : |3+y| < 7, \n        have h45 : 0 < 3 + y, linarith, --reusing, should only do once\n        have h46 := abs_of_pos h45,\n        rw ← h46 at h6y, exact h6y,\n    -- I shouldn't need to prove this twice, how to fix?\n    have hd : 0 < d,\n    { -- prove this d is positive\n        have h1 : 0 < (1:ℝ), linarith,\n        have h2 : 0 < (ε/7), linarith,\n        simp, split, exact h1, exact h2, \n    },\n    have D := (mul_lt_mul_right hd).mpr h7y,\n    rw mul_comm at D, rw mul_comm 7 d at D,\n    have h9y : |3 - y| * |3 + y| <  d * 7, linarith,\n    have h10y : d ≤ (ε/7), exact min_le_right (1:ℝ) (ε/7),\n    have h11y : |3 - y| * |3 + y| < (ε/7) * 7, linarith,\n    have h12y : (ε/7) * 7 = ε, linarith,\n    rw h12y at h11y, exact h11y,\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/classicContinDef.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7664152333130384}}
{"text": "import SciLean.Basic\nimport SciLean.Tactic\n-- import Lean\n\n-- open Lean\n-- open Lean.Meta\n\nset_option synthInstance.maxHeartbeats 5000\n-- set_option synthInstance.maxSize 1000\n\n-- set_option trace.Meta.Tactic.simp true\n-- set_option trace.Meta.synthInstance true \n\nnamespace SciLean.NDVector.Tests\n\nsection NDVector\n\n  variable {α β γ : Type}\n  variable {X Y Z : Type} [Vec X] [Vec Y] [Vec Z]\n\n  variable {dims} (x dx : NDVector dims) (i : Fin dims.product)\n  example : ∂ (λ x => x[i]) x dx = dx[i] := by simp done\n  example : ∂ (λ x => x[i]*x[i]) x dx = dx[i]*x[i] + x[i]*dx[i] := by simp done\n  example : ∂ (λ x i => x[i]*x[i]) x dx i = dx[i]*x[i] + x[i]*dx[i] := by simp done\n\n  example : Vec (NDVector dims) := by infer_instance\n  example : Hilbert (NDVector dims) := by infer_instance\n\n  example : (λ x : NDVector dims => sum fun i => getOp x i)† 1 = (lmk fun i => 1) := by autoadjoint done\n  example (a : Fin _) [NonZero dims.product] : (fun (x : NDVector dims) i => x[i - a])† = (fun x => lmk fun i => x (i + a)) := by autoadjoint done\n  example (x : NDVector dims) (i) : (fun (y : NDVector dims) => y[i] * x[i])† 1 = (lmk (λ j => (kron i j) * x[i])) := by autoadjoint simp done\n\n  example (x) : gradient (λ (x : ℝ) => x) x = 1 := by autograd done\n  example : ∇ (λ (x : NDVector dims) => x[i]) x = (lmk fun j => kron i j) := by autograd done\n  example {dims} (i) (x : NDVector dims) : ∇ (λ (x : NDVector dims) => x[i]) x = lmk (kron i) := by autograd done\n  example {dims} (i) (x : NDVector dims) : ∇ (λ (x : NDVector dims) => x[i]*x[i]) x = ((2 : ℝ) * lmk fun j => kron i j * x[i]) := by autograd done\n\nend NDVector\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/Data/Tests.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7663912800391146}}
{"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 : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε\n\nexample {a : ℕ → ℝ} {l : ℝ} (c : ℝ) (ha : is_limit a l) :\n  is_limit (λ i, a i + c) (l + c) :=\nbegin\n  sorry,\nend\n\n\nexample (a : ℕ → ℝ) (l : ℝ) :\n  is_limit a l ↔ is_limit (λ i, a i - l) 0 :=\nbegin\n  sorry,\nend\n\n\n/- Helpful things:\n`abs_pos : 0 < |a| ↔ a ≠ 0`\n`div_pos : 0 < a → 0 < b → 0 < a / b`\n`abs_mul x y : |x * y| = |x| * |y|`\n`lt_div_iff' : 0 < c → (a < b / c ↔ 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-/\ntheorem is_limit_add {a b : ℕ → ℝ} {l m : ℝ}\n  (h1 : is_limit a l) (h2 : is_limit b m) :\n  is_limit (a + b) (l + m) := sorry\n\n\n-- And now, over to you!\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 : ℕ → ℝ} {l c : ℝ} (h : is_limit a l) :\n  is_limit (λ n, c * (a n)) (c * l) :=\nbegin\n  sorry,\nend\n\ntheorem sandwich (a b c : ℕ → ℝ)\n  (l : ℝ) (ha : is_limit a l) (hc : is_limit c l) \n  (hab : ∀ n, a n ≤ b n) (hbc : ∀ n, b n ≤ c n) : is_limit b l :=\nbegin\n  sorry,\nend\n\nexample (a : ℕ → ℝ) (b : ℕ → ℝ) (α β c d : ℝ) \n    (ha : is_limit a α) (hb : is_limit b β) : \n    is_limit ( λ n, c * (a n) + d * (b n) ) (c * α + d * β) :=\nbegin\n  -- intros ε hε,**BAD IDEA**, you can do this much faster using the above theorems!\n  sorry,\nend\n\nexample (a : ℕ → ℝ) (b : ℕ → ℝ)\n  (l : ℝ) (m : ℝ) (hl : is_limit a l) (hm : is_limit b m) \n  (hle : ∀ n, a n ≤ b n) : l ≤ m :=\nbegin\n  sorry,\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/Exercices.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642533380189, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7663607476709016}}
{"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) : (∀ x₁, x₁ < x → Nat → Nat) → Nat → 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 <;> simp [gcd_succ]\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": "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/Gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849805, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7663607437280137}}
{"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.continuum\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. `#ℝ = 𝔠`.\n\nWe show that `#ℝ ≤ 𝔠` by noting that every real number is determined by a Cauchy-sequence of the\nform `ℕ → ℚ`, which has cardinality `𝔠`. To show that `#ℝ ≥ 𝔠` we define an injection from\n`{0, 1} ^ ℕ` to `ℝ` with `f ↦ Σ 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} ^ ℕ` to `ℝ` by\n  `f ↦ Σ' n, f n * (1 / 3) ^ n`\n\n## Main statements\n\n* `cardinal.mk_real : #ℝ = 𝔠`: 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 ∈ {i,o,c}` state that intervals on the reals\n  have cardinality continuum.\n\n## Notation\n\n* `𝔠` : 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 : ℝ} {f g : ℕ → bool} {n : ℕ}\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 : ℝ) (f : ℕ → bool) (n : ℕ) : ℝ := 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 ≤ c) : 0 ≤ 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 : ℕ → bool) :\n  (λ n, cantor_function_aux c f (n + 1)) = λ n, c * cantor_function_aux c (λ n, f (n + 1)) n :=\nby { ext n, cases h : f (n + 1); simp [h, pow_succ] }\n\nlemma summable_cantor_function (f : ℕ → bool) (h1 : 0 ≤ 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 : ℕ → bool)` is `Σ 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 : ℝ) (f : ℕ → bool) : ℝ := ∑' n, cantor_function_aux c f n\n\nlemma cantor_function_le (h1 : 0 ≤ c) (h2 : c < 1) (h3 : ∀ n, f n → g n) :\n  cantor_function c f ≤ 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 : ℕ → bool) (h1 : 0 ≤ c) (h2 : c < 1) :\n  cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (λ 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 `ℕ → 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 : ℕ} {f g : ℕ → bool}\n  (hn : ∀(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 : ℕ → bool := λ n, nat.rec ff (λ _ _, tt) n,\n    have hf_max : ∀n, f n → f_max n,\n    { intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },\n    let g_min : ℕ → bool := λ n, nat.rec tt (λ _ _, ff) n,\n    have hg_min : ∀n, g_min n → 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          ←tsum_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 (λ 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 : ∃n, f n ≠ g n,\n  { rw [←not_forall], intro h', apply h, ext, apply h' },\n  let n := nat.find this,\n  have hn : ∀ (k : ℕ), k < n → 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 [←fn], apply ne.symm, exact nat.find_spec this },\n  { apply ne_of_gt, refine increasing_cantor_function h1 h2 (λ k hk, (hn k hk).symm) _ fn,\n    apply eq_ff_of_not_eq_tt, rw [←fn], apply ne.symm, exact nat.find_spec this }\nend\n\n/-- The cardinality of the reals, as a type. -/\nlemma mk_real : #ℝ = 𝔠 :=\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 [← power_def, mk_nat, mk_rat, omega_power_omega] },\n  { convert mk_le_of_injective (cantor_function_injective _ _),\n    rw [←power_def, mk_bool, mk_nat, two_power_omega], 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 ℝ) = 𝔠 :=\nby rw [mk_univ, mk_real]\n\n/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/\nlemma not_countable_real : ¬ countable (set.univ : set ℝ) :=\nby { rw [← mk_set_le_omega, not_le, mk_univ_real], apply cantor }\n\n/-- The cardinality of the interval (a, ∞). -/\nlemma mk_Ioi_real (a : ℝ) : #(Ioi a) = 𝔠 :=\nbegin\n  refine le_antisymm (mk_real ▸ mk_set_le _) _,\n  rw [← not_lt], intro h,\n  refine ne_of_lt _ mk_univ_real,\n  have hu : Iio a ∪ {a} ∪ Ioi a = set.univ,\n  { convert Iic_union_Ioi, exact Iio_union_right },\n  rw ← 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 : (λ x, a + a - x) '' Ioi a = Iio a,\n  { convert image_const_sub_Ioi _ _, simp },\n  rw ← 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, ∞). -/\nlemma mk_Ici_real (a : ℝ) : #(Ici a) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Ioi_real a ▸ mk_le_mk_of_subset Ioi_subset_Ici_self)\n\n/-- The cardinality of the interval (-∞, a). -/\nlemma mk_Iio_real (a : ℝ) : #(Iio a) = 𝔠 :=\nbegin\n  refine le_antisymm (mk_real ▸ mk_set_le _) _,\n  have h2 : (λ x, a + a - x) '' Iio a = Ioi a,\n  { convert image_const_sub_Iio _ _, simp },\n  exact mk_Ioi_real a ▸ h2 ▸ mk_image_le\nend\n\n/-- The cardinality of the interval (-∞, a]. -/\nlemma mk_Iic_real (a : ℝ) : #(Iic a) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Iio_real a ▸ mk_le_mk_of_subset Iio_subset_Iic_self)\n\n/-- The cardinality of the interval (a, b). -/\nlemma mk_Ioo_real {a b : ℝ} (h : a < b) : #(Ioo a b) = 𝔠 :=\nbegin\n  refine le_antisymm (mk_real ▸ mk_set_le _) _,\n  have h1 : #((λ x, x - a) '' Ioo a b) ≤ #(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)) ≤ #(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 : ℝ} (h : a < b) : #(Icc a b) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Icc_self)\n\n/-- The cardinality of the interval (a, b]. -/\nlemma mk_Ioc_real {a b : ℝ} (h : a < b) : #(Ioc a b) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Ioc_self)\n\nend cardinal\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/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7663607420969029}}
{"text": "/-\n  Presheaf (of types).\n\n  https://stacks.math.columbia.edu/tag/006D \n-/\n\nimport topology.basic\nimport topology.opens\n\nuniverses u v\n\n-- Definition of a presheaf.\n\nopen topological_space lattice\n\nstructure presheaf (α : Type u) [topological_space α] := \n(F     : opens α → Type v)\n(res   : ∀ (U V) (HVU : V ⊆ U), F U → F V)\n(Hid   : ∀ (U), res U U (set.subset.refl U) = id)\n(Hcomp : ∀ (U V W) (HWV : W ⊆ V) (HVU : V ⊆ U),\n  res U W (set.subset.trans HWV HVU) = res V W HWV ∘ res U V HVU)\n\nnamespace presheaf\n\nvariables {α : Type u} [topological_space α]\n\ninstance : has_coe_to_fun (presheaf α) :=\n{ F := λ _, opens α → Type v,\n  coe := presheaf.F }\n\n-- Simplification lemmas for Hid and Hcomp.\n\n@[simp] lemma Hcomp' (F : presheaf α) :\n∀ (U V W) (HWV : W ⊆ V) (HVU : V ⊆ U) (s : F U),\n  (F.res U W (set.subset.trans HWV HVU)) s = \n  (F.res V W HWV) ((F.res U V HVU) s) :=\nλ U V W HWV HVU s, by rw F.Hcomp U V W HWV HVU\n\n@[simp] lemma Hid' (F : presheaf α) :\n∀ (U) (s : F U),\n  (F.res U U (set.subset.refl U)) s = s := \nλ U s, by rw F.Hid U; simp\n\n-- Morphism of presheaves.\n\nstructure morphism (F G : presheaf α) :=\n(map      : ∀ (U), F U → G U)\n(commutes : ∀ (U V) (HVU : V ⊆ U),\n  (G.res U V HVU) ∘ (map U) = (map V) ∘ (F.res U V HVU))\n\ninfix `⟶`:80 := morphism \n\nsection morphism\n\ndef comp {F G H : presheaf α} (fg : F ⟶ G) (gh : G ⟶ H) : F ⟶ H :=\n{ map := λ U, gh.map U ∘ fg.map U,\n  commutes := λ U V HVU,\n    begin\n      rw [←function.comp.assoc, gh.commutes U V HVU], symmetry,\n      rw [function.comp.assoc, ←fg.commutes U V HVU]\n    end }\n\ninfix `⊚`:80 := comp\n\ndef id (F : presheaf α) : F ⟶ F :=\n{ map := λ U, id,\n  commutes := λ U V HVU, by simp, }\n\nstructure iso (F G : presheaf α) :=\n(mor : F ⟶ G)\n(inv : G ⟶ F)\n(mor_inv_id : mor ⊚ inv = id F)\n(inv_mor_id : inv ⊚ mor = id G)\n\ninfix `≅`:80 := λ A B, nonempty (iso A B)\n\nend morphism \n\n-- Equality lemma\n\nlemma presheaf_eq_of_subset_eq (F : presheaf α) (U V : opens α) \n: U = V → F U = F V :=\nλ h, by rw h\n\nend presheaf\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/presheaf.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539553, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7663393083511892}}
{"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\n! This file was ported from Lean 3 source module data.finsupp.pwo\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.Data.Finsupp.Order\nimport Mathlib.Order.WellFoundedSet\n\n/-!\n# Partial well ordering on finsupps\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.WellFoundedSet`.\n\n## Main statements\n\n* `Finsupp.isPwo` - 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\n/-- A version of **Dickson's lemma** any subset of functions `σ →₀ α` is partially well\nordered, when `σ` is `Finite` and `α` is a linear well order.\nThis version uses finsupps on a finite type as it is intended for use with `MVPowerSeries`.\n-/\ntheorem Finsupp.isPwo {α σ : Type _} [Zero α] [LinearOrder α] [IsWellOrder α (· < ·)] [Finite σ]\n    (S : Set (σ →₀ α)) : S.IsPwo :=\n  Finsupp.equivFunOnFinite.symm_image_image S ▸\n    Set.PartiallyWellOrderedOn.image_of_monotone_on (Pi.isPwo _) fun _a _b _ha _hb => id\n#align finsupp.is_pwo Finsupp.isPwo\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/Pwo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7662882133209272}}
{"text": "import data.real.basic\nimport data.nat.prime\n\nopen nat\n\n-- BEGIN\nexample : ∃ x : ℝ, 2 < x ∧ x < 4 :=\nbegin\n  use 5 / 2,\n  split, \n  norm_num,\n  norm_num,\nend\n\nexample : ∃ m n : ℕ,\n  4 < m ∧ m < n ∧ n < 10 ∧ nat.prime m ∧ nat.prime n :=\nbegin\n  use [5, 7],\n  split; norm_num\nend\n\nexample {x y : ℝ} : x ≤ y ∧ x ≠ y → x ≤ y ∧ ¬ y ≤ x :=\nbegin\n  rintros ⟨h₀, h₁⟩,\n  use [h₀, λ h', h₁ (le_antisymm h₀ h')]\nend\n\n/- Alternatively, the proof can be spelled out as done eariler -/\nexample {x y : ℝ} : x ≤ y ∧ x ≠ y → x ≤ y ∧ ¬ y ≤ x :=\nbegin\n  intro h,\n  cases h with h1 h2,\n  split,\n  exact h1,\n  contrapose! h2,\n  apply le_antisymm h1 h2,\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/ex1_use _num.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422227627597, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7662707820794398}}
{"text": "\n/-\n\nIn lean we represent: (1) propositions as\n\ntypes and (2) predicates as parameterized\n\npropositions.\n\n \n\nA parameterized type gives rise to a whole\n\nfamily of proposition, once for each value\n\nof each parameter.\n\n \n\nWe can think of one-parameter predicates \n\nas specifying *properties* of objects. As\n\nan example, as defined, is_even : ℕ → Prop\n\nexpresses the property of a natural number\n\n(an argument value) \"being even\". We define\n\nthe constructors to ensure that there is a\n\nproof of (is_even n) if and only if (n : ℕ)\n\nis (a term that represents) an even number.\n\n \n\nOne-parameter predicates thus also specify \n\n*sets* of objects: namely all and only those\n\nvalues of a given argument type that have the \n\nspecified property as shown by the existence\n\nof a proof that such a value \"satisfies the \n\npredicate\" (makes the resulting proposition\n\ntrue).\n\n \n\nThe is_even predicate thus specifies the\n\nset of all even natural numbers, which we\n\ncan write as {0, 2, 4, 6, ...} or, better,\n\nas { n : ℕ | is_even n }.\n\n \n\nWe can think of two-parameter predicates as \n\nspecifying binary relations, that is, sets of\n\n*pairs* of argument values that make a given\n\nproposition true.\n\n \n\nThe most commonplace example of a two-argument\n\npredicate is equals. We can write (_ = _) to \n\nmake it clear that equals takes two values and\n\nyields a proposition that the first equals the\n\nsecond. For example, if a and b are of type ℕ, \n\nthen (a = b) is a proposition that has a proof\n\nif and only if the two terms really are equal\n\n(when reduced). So, for example, 4 = 2 + 2 is\n\ntrue, there is a proof of it, because reducing\n\n2 + 2 to 4 reduces the whole proposition to \n\n4 = 4, and there is a proof of this proposition.\n\n \n\nThe proposition, a = b, in Lean is just a nice\n\nshorthand notation for (eq a b). The two-place\n\npredicate, eq, implements the equality relation. \n\nIt's polymorphic: it takes a *type parameter*, α,\n\nimplicitly. It then explicitly takes two values,\n\na and b, of type α, and yields the proposition, \n\na = b (which is of course itself a type).\n\n \n\nThe eq \"type builder\" (taking α and two values,\n\na and b of type α) and yielding the proposition\n\n(a type), a = b, provides a single constructor\n\nwith which to build proofs. It's called refl,\n\nand it establishes the \"reflexive\" property of\n\nthe eq relation, by taking *any* value, a : α,\n\nfor any type, α, and by returning a proof of\n\n(eq a a), that is, of a = a. So, by applying\n\neq.refl to any value, a, of any type, we get\n\na proof of (a = a), and those are the *only*\n\nproofs of equality that can be constructed.\n\nThere's thus no way to prove that 0 = 1, for\n\nexample, because those terms don't reduce to\n\nthe same values, and we can only use eq.refl\n\nto construct proofs that two terms are equal\n\nif they really do reduce to exactly the same\n\nvalue.\n\n \n\nFinally, we will represent some, but no all,\n\nof the logical connetives, including \"and\",\n\n\"or\", and \"iff\", as polymorphic propositions.\n\nWhereas a predicate, such as eq, will take\n\nvalues of arbitrary types as arguments (e.g.,\n\neq can take values of type ℕ), connectives\n\nare like polymorphic types: they take types\n\nas arguments, but in this case the types are\n\nof type Prop.\n\n \n\nConsider \"and\" for example. If P and Q are\n\nany two pre-existing propositions (types of\n\ntype Prop), then we can form the proposition,\n\nP ∧ Q, and it, too, will be a proposition (a\n\ntype of type, Prop). The type of \"and\" is thus\n\nProp → Prop → Prop: it takes two propositions\n\n(types of type Prop) as arguments and yields\n\na new proposition (a new type of type Prop).\n\n \n\nTo enforce the logical meaning of \"and\", we\n\ndefine the \"and\" type builder to have just\n\none constructor, which we call \"intro\", that\n\nif applied to a proof, p, of P and to a proof,\n\nq, of Q yields a term, (and.intro p q), that\n\nis axiomatically accepted as being a \"proof\"\n\nof (and P Q), which we write using an infix\n\nnotation as (P ∧ Q). \n\n \n\nFinally, we note that if we're given a term,\n\n(and.intro p q), of type (P ∧ Q), that is, if\n\nwe're given a proof of (P ∧ Q), we can get a\n\nproof of P from it, by \"destructuring\" the\n\nterm using pattern matching. For example, we\n\ncan obtain \"p\" (the proof of P \"contained \n\ninside\" the proof of P ∧ Q) with the following\n\nrule: | (and.intro p _) := p. This is how we\n\nimplement the two \"elimination rules\" for and.\n\n-/\n\n \n\n/-\n\nHere's a statement of the proposition that\n\n2 + 2 = 4 and a proof of it. \n\n-/\n\n \n\nlemma proof_of_two_plus_two_eq_four : 2 + 2 = 4 :=\n\n    eq.refl 4\n\n \n\n/-\n\n1. State and prove the proposition that the\n\nstring,\"Lean!\", appended to the string, \"Hello, \"\n\nis equal to the string, \"Hello, Lean!\". You may\n\nand should use the Lean library-provided string \n\nappend operator, ++, as an infix notation for \n\nappend.\n\n-/\n\n \n\n-- string append example\n\n#eval \"Hi \" ++ \"There!\"\n\n \n\n-- fill in the blanks\n\nlemma proof1 : _ = _\n\n \n\n/-\n\n2.  Sometimes we want to state and prove a \n\nproposition without binding a name to the proof.\n\nFor that, instead of using def, theorem, or\n\nlemma, we can use \"example.\" Here's an example. \n\n-/\n\n \n\nexample : 1 = 1 := _    -- Fill blank with proof.\n\n \n\n/-\n\nNote that we can use example for ordinary types\n\nas well.\n\n-/\n\n \n\nexample : ℕ := 5\n\n \n\n/-\n\n2. State and prove the proposition that 3 * 4 = 12,\n\nusing \"example.\"\n\n-/\n\n \n\n-- Answer Here\n\n \n\n/-\n\n3. Use example to formally state and prove the\n\nproposition that 1 = 1 ∧ 0 = 0. \n\n-/\n\n \n\n-- Here\n\n\n \n\n/-\n\n4. Complete the following program to show that\n\nif P and Q are arbitrary propositions, and *if* \n\nyou're given a proof of P and Q, then you can \n\nobtain and return a proof of P.\n\n \n\nHint: In Lean, and.intro is the one introduction\n\n(proof creating) rule for and, and and.elim_left\n\nand and.elim_right are the two elimination rules.\n\nThey are functions. Use one of them!\n\n-/\n\n \n\ntheorem P_and_Q_imp_P {P Q : Prop} (pq : P ∧ Q) : P :=\n\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/Notes/newquiz1-prep.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7662523228978785}}
{"text": "import Mathlib.Tactic.Basic\nimport Mathlib.Tactic.Cases\nimport Mathlib.Init.Data.Nat.Basic\n/-!\n## Structural Induction\n\n_Structural induction_ is a generalization of mathematical induction to arbitrary inductive types.\nTo prove a goal `n : ℕ ⊢ P[n]` by structural induction on `n`, it suffces to show two subgoals,\ntraditionally called the base case and the induction step:\n```lean\n⊢ P[0]\nk : ℕ,ih : P[k] ⊢ P[k + 1]\n```\nWe can of course also write `Nat.zero` and `Nat.succ k`.\n\nIn general, the situation is more complex. The goal might contain some extra hypotheses (e.g., `Q`)\nthat do not depend on `n` and others (e.g., `R[n]`) that do. Assuming we have one hypothesis of each\nkind, this gives the initial goal\n```lean\nhQ : Q, n : N, hR : R[n] ⊢ S[n]\n```\nStructural induction on `n` then produces the two subgoals\n```lean\nhQ : Q, hR : R[0] ⊢ S[0]\nhQ : Q, k : N, ih : R[k] → S[k], hR : R[k + 1] ⊢ S[k + 1]\n```\nThe hypothesis `Q` is simply carried over unchanged from the initial goal, whereas\n`R[n] ⊢ S[n]` is treated almost the same as if the goal’s target had been\n`R[n] → S[n]`. This is easy to check by taking `P[n] := R[n] → S[n]` in the first example\nabove. Since this general format is very verbose and hardly informative (now that\nwe understand how it works), from now on we will present goals in the simplest\nform possible, without extra hypotheses.\n\nFor lists, given a goal `xs : List α ⊢ P[xs]`, structural induction on `xs` yields\n```lean\n⊢ P[[]]\ny : α, ys : List α, ih : P[ys] ⊢ P[y :: ys]\n```\nWe can of course also write `List.nil` and `List.cons y ys`. There is no induction hypothesis\nassociated with `y`, because `y` is not of List type.\n\nFor arithmetic expressions, the base cases are\n```\ni : ℤ ⊢ P[Aexp.num i]                    x : string ⊢ P[Aexp.var x]\n```\nand the induction steps for `add`, `sub`, `mul` and `div` are\n```\ne₁ e₂ : Aexp, ih₁ : P[e₁], ih₂ : P[e₂] ⊢ P[Aexp.add e₁ e₂]\ne₁ e₂ : Aexp, ih₁ : P[e₁], ih₂ : P[e₂] ⊢ P[Aexp.sub e₁ e₂]\ne₁ e₂ : Aexp, ih₁ : P[e₁], ih₂ : P[e₂] ⊢ P[Aexp.mul e₁ e₂]\ne₁ e₂ : Aexp, ih₁ : P[e₁], ih₂ : P[e₂] ⊢ P[Aexp.div e₁ e₂]\n```\nNotice the two induction hypotheses, about e₁ and e₂.\n\nIn general, structural induction produces one subgoal per constructor. In each subgoal, induction\nhypotheses are available for all constructor arguments of the type we are performing the induction\non.\n\nRegardless of the inductive type `τ`, the procedure to compute the subgoals is\nalways the same:\n\n1. Replace the hole in `P[ ]` with each possible constructor applied to fresh\nvariables (e.g., `y :: ys`), yielding as many subgoals as there are constructors.\n2. Add these new variables (e.g., `y`, `ys`) to the local context.\n3. Add induction hypotheses for all new variables of type `τ`.\n\nAs an example, we will prove that `Nat.succ n ≠ n` for all `n : ℕ`. We start with\nan informal proof, because these require us to understand what we are doing:\n\nThe proof is by structural induction on `n`.\n\n`Case 0`: We must show `Nat.succ 0 ≠ 0`. This follows from the “no confusion” property\nof the constructors of inductive types.\n\n`Case Nat.succ k`: The induction hypothesis is `Nat.succ k ≠ k`. We\nmust show `Nat.succ (Nat.succ k) ≠ Nat.succ k`. By the injectivity of\n`Nat.succ`, we have that `Nat.succ (Nat.succ k) = Nat.succ k` is equivalent to\n`Nat.succ k = k`. Thus, it suffces to prove `Nat.succ k ≠ k`,\nwhich corresponds exactly to the induction hypothesis. <span class=qed></span>\n\nNotice the main features of this informal proof, which you should aim to reproduce in your own\ninformal arguments:\n\n- The proof starts with an unambiguous announcement of the type of proof we are carrying out (e.g.,\n  which kind of induction and on which variable).\n- The cases are clearly identified, and for each case, both the goal’s target and the hypotheses are\n  stated.\n- The key lemmas on which the proof relies are explicitly invoked (e.g., injectivity of `Nat.succ`).\n\nNow let us carry out the proof in Lean:\n-/\nlemma nat.succ_neq_self (n : ℕ) :\n  Nat.succ n ≠ n := by\n  induction' n with n ih  -- ih: Nat.succ n ≠ n\n  { simp }           -- ⊢ Nat.succ Nat.zero ≠ Nat.zero\n  { simp [ih] }      -- ⊢ Nat.succ (Nat.succ n) ≠ Nat.succ n\n/-!\nThe routine reasoning about constructors is all carried out by `simp` automatically,\nwhich is usually what we want.\n\nWe can supply our own names, and reorder the cases, by using the case tactic\nin front of each case, together with the case’s name and the desired names for\nthe variables and hypotheses introduced by `induction’`. For example:\n-/\nlemma nat.succ_neq_self2 (n : ℕ) :\n  Nat.succ n ≠ n := by\n  induction' n with m IH\n  case succ  => { simp [IH] }\n  case zero => { simp }\n/-!\nInstead of `n` and `ih`, we chose the names `m` and `IH` and we moved the zero\ncase to the end.\n-/\n", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/FunctionalProgramming/StructuralInduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.766252314777063}}
{"text": "/-\nCopyright (c) 2021 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel\n-/\nimport analysis.normed.group.pointwise\nimport analysis.normed.group.add_torsor\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\nvariables {𝕜 E : Type*} [normed_field 𝕜]\n\nsection semi_normed_group\nvariables [semi_normed_group E] [normed_space 𝕜 E]\n\ntheorem smul_ball {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :\n  c • ball x r = ball (c • x) (∥c∥ * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem₀ hc,\n  conv_lhs { rw ←inv_smul_smul₀ hc x },\n  simp [← div_eq_inv_mul, div_lt_iff (norm_pos_iff.2 hc), mul_comm _ r, dist_smul],\nend\n\nlemma smul_unit_ball {c : 𝕜} (hc : c ≠ 0) : c • ball (0 : E) (1 : ℝ) = ball (0 : E) (∥c∥) :=\nby rw [smul_ball hc, smul_zero, mul_one]\n\ntheorem smul_sphere' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :\n  c • sphere x r = sphere (c • x) (∥c∥ * r) :=\nbegin\n  ext y,\n  rw mem_smul_set_iff_inv_smul_mem₀ hc,\n  conv_lhs { rw ←inv_smul_smul₀ hc x },\n  simp only [mem_sphere, dist_smul, norm_inv, ← div_eq_inv_mul,\n    div_eq_iff (norm_pos_iff.2 hc).ne', mul_comm r],\nend\n\ntheorem smul_closed_ball' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :\n  c • closed_ball x r = closed_ball (c • x) (∥c∥ * r) :=\nby simp only [← 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 : 𝕜) :\n  bounded (c • s) :=\nbegin\n  obtain ⟨R, hR⟩ : ∃ (R : ℝ), ∀ x ∈ s, ∥x∥ ≤ R := hs.exists_norm_le,\n  refine (bounded_iff_exists_norm_le).2 ⟨∥c∥ * R, _⟩,\n  assume z hz,\n  obtain ⟨y, ys, rfl⟩ : ∃ (y : E), y ∈ s ∧ c • y = z := mem_smul_set.1 hz,\n  calc ∥c • y∥ = ∥c∥ * ∥y∥ : norm_smul _ _\n  ... ≤ ∥c∥ * 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 • 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 ∈ 𝓝 x) :\n  ∀ᶠ r in 𝓝 (0 : 𝕜), {x} + r • s ⊆ u :=\nbegin\n  obtain ⟨ε, εpos, hε⟩ : ∃ ε (hε : 0 < ε), closed_ball x ε ⊆ u :=\n    nhds_basis_closed_ball.mem_iff.1 hu,\n  obtain ⟨R, Rpos, hR⟩ : ∃ (R : ℝ), 0 < R ∧ s ⊆ closed_ball 0 R := hs.subset_ball_lt 0 0,\n  have : metric.closed_ball (0 : 𝕜) (ε / R) ∈ 𝓝 (0 : 𝕜) :=\n    closed_ball_mem_nhds _ (div_pos εpos Rpos),\n  filter_upwards [this] with r hr,\n  simp only [image_add_left, singleton_add],\n  assume y hy,\n  obtain ⟨z, zs, hz⟩ : ∃ (z : E), z ∈ s ∧ r • z = -x + y, by simpa [mem_smul_set] using hy,\n  have I : ∥r • z∥ ≤ ε := calc\n    ∥r • z∥ = ∥r∥ * ∥z∥ : norm_smul _ _\n    ... ≤ (ε / 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 εpos Rpos).le\n    ... = ε : by field_simp [Rpos.ne'],\n  have : y = x + r • z, by simp only [hz, add_neg_cancel_left],\n  apply hε,\n  simpa only [this, dist_eq_norm, add_sub_cancel', mem_closed_ball] using I,\nend\n\n/-- Any ball is the image of a ball centered at the origin under a shift. -/\nlemma vadd_ball_zero (x : E) (r : ℝ) : x +ᵥ ball 0 r = ball x r :=\nby rw [vadd_ball, vadd_eq_add, add_zero]\n\n/-- Any closed ball is the image of a closed ball centered at the origin under a shift. -/\nlemma vadd_closed_ball_zero (x : E) (r : ℝ) : x +ᵥ closed_ball 0 r = closed_ball x r :=\nby rw [vadd_closed_ball, vadd_eq_add, add_zero]\n\nvariables [normed_space ℝ E]\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 : ℝ} (hr : 0 < r) : r • ball 0 1 = ball (0 : E) r :=\nby rw [smul_unit_ball hr.ne', real.norm_of_nonneg hr.le]\n\nend semi_normed_group\n\nsection normed_group\nvariables [normed_group E] [normed_space 𝕜 E]\n\ntheorem smul_closed_ball (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) :\n  c • closed_ball x r = closed_ball (c • x) (∥c∥ * r) :=\nbegin\n  rcases eq_or_ne c 0 with rfl|hc,\n  { simp [hr, zero_smul_set, set.singleton_zero, ← nonempty_closed_ball] },\n  { exact smul_closed_ball' hc x r }\nend\n\nlemma smul_closed_unit_ball (c : 𝕜) : c • closed_ball (0 : E) (1 : ℝ) = closed_ball (0 : E) (∥c∥) :=\nby rw [smul_closed_ball _ _ zero_le_one, smul_zero, mul_one]\n\nvariables [normed_space ℝ 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 : ℝ} (hr : 0 ≤ r) :\n  r • 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 : ℝ} :\n  (sphere x r).nonempty ↔ 0 ≤ r :=\nbegin\n  obtain ⟨y, hy⟩ := exists_ne x,\n  refine ⟨λ h, nonempty_closed_ball.1 (h.mono sphere_subset_closed_ball), λ hr,\n    ⟨r • ∥y - x∥⁻¹ • (y - x) + x, _⟩⟩,\n  have : ∥y - x∥ ≠ 0, by simpa [sub_eq_zero],\n  simp [norm_smul, this, real.norm_of_nonneg hr],\nend\n\nlemma smul_sphere [nontrivial E] (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) :\n  c • sphere x r = sphere (c • x) (∥c∥ * 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 `λ y, x + r • y`. -/\nlemma affinity_unit_ball {r : ℝ} (hr : 0 < r) (x : E) : x +ᵥ r • 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 ≤ r` is the image of the unit closed ball under\n`λ y, x + r • y`. -/\nlemma affinity_unit_closed_ball {r : ℝ} (hr : 0 ≤ r) (x : E) :\n  x +ᵥ r • 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": "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/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8577680977182187, "lm_q1q2_score": 0.7662523050322367}}
{"text": "import data.fintype.basic data.fintype.card \nimport algebra.big_operators.basic algebra.big_operators.order\nimport tactic.squeeze\n\nnamespace MAS114\n\nuniverses u v\nvariables {α : Type u} {β : Type v} (p : α → β) \nvariables [fintype α] [fintype β] [decidable_eq α] [decidable_eq β]\n\ndef fiber (b : β) : Type* := { a : α // p a = b } \n\ninstance (b : β) : fintype (fiber p b) := \n by { dsimp[fiber], apply_instance }\n\ndef fiber' (b : β) : finset α := finset.univ.filter (λ a, p a = b) \n\nlemma mem_fiber' (b : β) (a : α) : a ∈ fiber' p b ↔ p a = b := \n ⟨λ h,(finset.mem_filter.mp h).right,\n  λ h,finset.mem_filter.mpr ⟨finset.mem_univ a,h⟩⟩ \n\nlemma card_fiber (b : β) : fintype.card (fiber p b) = (fiber' p b).card := \n fintype.subtype_card (fiber' p b) (mem_fiber' p b)\n\ndef equiv_fibre_sigma : α ≃ Σ (b : β), (fiber p b) := {\n  to_fun := λ a, ⟨p a,⟨a,rfl⟩⟩,\n  inv_fun := λ x, x.2.val,\n  left_inv := λ a, by { refl },\n  right_inv := by { rintro ⟨b,⟨a,⟨e⟩⟩⟩, simp only[heq_iff_eq],split; refl }\n}\n\nlemma card_eq_fiber_sum :\n fintype.card α = finset.univ.sum (λ b, fintype.card (fiber p b)) := \n (fintype.card_congr (equiv_fibre_sigma p)).trans (fintype.card_sigma (fiber p))\n\nlemma card_eq_fiber_sum' :\n fintype.card α = finset.univ.sum (λ b, finset.card (fiber' p b)) := \nbegin\n let e0 := card_eq_fiber_sum p,\n let e1 : ∀ b : β, b ∈ finset.univ → fintype.card (fiber p b) = finset.card (fiber' p b)\n  := λ b _, card_fiber p b,\n let e2 := @finset.sum_congr ℕ β finset.univ _ _ _ _ rfl e1,\n exact e0.trans e2,\nend\n\nvariable {p}\n\nlemma fiber_nonempty_of_surjective \n (p_surj : function.surjective p) (b : β) : nonempty (fiber p b) := \nbegin\n rcases p_surj b with ⟨a,e⟩,\n exact ⟨⟨a,e⟩⟩,\nend\n\nlemma card_le_of_surjective :\n function.surjective p → (fintype.card β) ≤ (fintype.card α) := \nbegin\n intro p_surj,\n let c : β → ℕ := λ b, 1,\n have h0 : ∀ b, b ∈ finset.univ → (c b) ≤ fintype.card (fiber p b) := \n  λ b _, fintype.card_pos_iff.mpr (fiber_nonempty_of_surjective p_surj b),\n have h1 := @finset.sum_le_sum β ℕ _ c _ finset.univ h0,\n let h2 := calc \n  finset.sum finset.univ (λ b : β, 1) = \n   add_monoid.nsmul finset.univ.card 1 : finset.sum_const 1\n  ... = ↑finset.univ.card : nsmul_one _\n  ... = finset.univ.card : nat.cast_id _\n  ... = fintype.card β : rfl,\n rw[h2,← card_eq_fiber_sum p] at h1,\n exact h1\nend\n\nend MAS114\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/undergraduate/MAS114/fiber.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359676, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7662489346965451}}
{"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ölzl\n-/\nimport algebra.order.group.defs\nimport algebra.hom.equiv.units.basic\n\n/-!\n# Inverse and multiplication as order isomorphisms 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-/\n\nset_option old_structure_cmd true\nopen function\n\nuniverse u\nvariable {α : Type u}\n\n\nsection group\nvariables [group α]\n\nsection typeclasses_left_right_le\nvariables [has_le α] [covariant_class α α (*) (≤)] [covariant_class α α (swap (*)) (≤)]\n  {a b c d : α}\n\nsection\n\nvariable (α)\n\n/-- `x ↦ x⁻¹` as an order-reversing equivalence. -/\n@[to_additive \"`x ↦ -x` as an order-reversing equivalence.\", simps]\ndef order_iso.inv : α ≃o αᵒᵈ :=\n{ to_equiv := (equiv.inv α).trans order_dual.to_dual,\n  map_rel_iff' := λ a b, @inv_le_inv_iff α _ _ _ _ _ _ }\n\nend\n\n@[to_additive neg_le]\nlemma inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=\n(order_iso.inv α).symm_apply_le\n\nalias inv_le' ↔ 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 ≤ b⁻¹ ↔ b ≤ a⁻¹ :=\n(order_iso.inv α).le_symm_apply\n\nend typeclasses_left_right_le\n\nend group\n\nalias le_inv' ↔ le_inv_of_le_inv _\nattribute [to_additive] le_inv_of_le_inv\n\nsection group\nvariables [group α] [has_le α]\n\nsection right\nvariables [covariant_class α α (swap (*)) (≤)] {a b c d : α}\n\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 : α) : α ≃o α :=\n{ map_rel_iff' := λ _ _, mul_le_mul_iff_right a, to_equiv := equiv.mul_right a }\n\n@[simp, to_additive] lemma order_iso.mul_right_symm (a : α) :\n  (order_iso.mul_right a).symm = order_iso.mul_right a⁻¹ :=\nby { ext x, refl }\n\nend right\n\nsection left\nvariables [covariant_class α α (*) (≤)]\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 : α) : α ≃o α :=\n{ map_rel_iff' := λ _ _, mul_le_mul_iff_left a, to_equiv := equiv.mul_left a }\n\n@[simp, to_additive] lemma order_iso.mul_left_symm (a : α) :\n  (order_iso.mul_left a).symm = order_iso.mul_left a⁻¹ :=\nby { ext x, refl }\n\nend left\n\nend 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/order_iso.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7662036366062044}}
{"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.group.pointwise\nimport analysis.mean_inequalities\nimport analysis.mean_inequalities_pow\nimport topology.algebra.ordered.liminf_limsup\n\n/-!\n# ℓp space\n\nThis file describes properties of elements `f` of a pi-type `Π i, E i` with finite \"norm\",\ndefined for `p:ℝ≥0∞` as the size of the support of `f` if `p=0`, `(∑' a, ∥f a∥^p) ^ (1/p)` for\n`0 < p < ∞` and `⨆ a, ∥f a∥` for `p=∞`.\n\nThe Prop-valued `mem_ℓp f p` states that a function `f : Π i, E i` has finite norm according\nto the above definition; that is, `f` has finite support if `p = 0`, `summable (λ a, ∥f a∥^p)` if\n`0 < p < ∞`, and `bdd_above (norm '' (set.range f))` if `p = ∞`.\n\nThe space `lp E p` is the subtype of elements of `Π i : α, E i` which satisfy `mem_ℓp f p`. For\n`1 ≤ p`, the \"norm\" is genuinely a norm and `lp` is a complete metric space.\n\n## Main definitions\n\n* `mem_ℓp f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported\n  if `p = 0`, `summable (λ a, ∥f a∥^p)` if `0 < p < ∞`, and `bdd_above (norm '' (set.range f))` if\n  `p = ∞`\n* `lp E p` : elements of `Π i : α, E i` such that `mem_ℓp f p`. Defined as an `add_subgroup` of\n  a type synonym `pre_lp` for `Π i : α, E i`, and equipped with a `normed_group` structure; also\n  equipped with `normed_space 𝕜` and `complete_space` instances under appropriate conditions\n\n## Main results\n\n* `mem_ℓp.of_exponent_ge`: For `q ≤ p`, a function which is `mem_ℓp` for `q` is also `mem_ℓp` for\n  `p`\n* `lp.mem_ℓp_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with\n  `lp` norm `≤ C`, is itself in `lp` and has `lp` norm `≤ C`.\n* `lp.tsum_mul_le_mul_norm`: basic form of Hölder'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 `∥-f∥ = ∥f∥`, instead of the non-working `f.norm_neg`.\n\n## TODO\n\n* More versions of Hölder's inequality (for example: the case `p = 1`, `q = ∞`; a version for normed\n  rings which has `∥∑' i, f i * g i∥` rather than `∑' i, ∥f i∥ * g i∥` on the RHS; a version for\n  three exponents satisfying `1 / r = 1 / p + 1 / q`)\n* Equivalence with `pi_Lp`, for `α` finite\n* Equivalence with `measure_theory.Lp`, for `f : α → E` (i.e., functions rather than pi-types) and\n  the counting measure on `α`\n* Equivalence with `bounded_continuous_function`, for `f : α → E` (i.e., functions rather than\n  pi-types) and `p = ∞`, and the discrete topology on `α`\n\n-/\n\nnoncomputable theory\nopen_locale nnreal ennreal big_operators\n\nvariables {α : Type*} {E : α → Type*} {p q : ℝ≥0∞} [Π i, normed_group (E i)]\n\n/-!\n### `mem_ℓp` predicate\n\n-/\n\n/-- The property that `f : Π i : α, E i`\n* is finitely supported, if `p = 0`, or\n* admits an upper bound for `set.range (λ i, ∥f i∥)`, if `p = ∞`, or\n* has the series `∑' i, ∥f i∥ ^ p` be summable, if `0 < p < ∞`. -/\ndef mem_ℓp (f : Π i, E i) (p : ℝ≥0∞) : Prop :=\nif p = 0 then (set.finite {i | f i ≠ 0}) else\n  (if p = ∞ then bdd_above (set.range (λ i, ∥f i∥)) else summable (λ i, ∥f i∥ ^ p.to_real))\n\nlemma mem_ℓp_zero_iff {f : Π i, E i} : mem_ℓp f 0 ↔ set.finite {i | f i ≠ 0} :=\nby dsimp [mem_ℓp]; rw [if_pos rfl]\n\nlemma mem_ℓp_zero {f : Π i, E i} (hf : set.finite {i | f i ≠ 0}) : mem_ℓp f 0 :=\nmem_ℓp_zero_iff.2 hf\n\nlemma mem_ℓp_infty_iff {f : Π i, E i} : mem_ℓp f ∞ ↔ bdd_above (set.range (λ i, ∥f i∥)) :=\nby dsimp [mem_ℓp]; rw [if_neg ennreal.top_ne_zero, if_pos rfl]\n\nlemma mem_ℓp_infty {f : Π i, E i} (hf : bdd_above (set.range (λ i, ∥f i∥))) : mem_ℓp f ∞ :=\nmem_ℓp_infty_iff.2 hf\n\nlemma mem_ℓp_gen_iff (hp : 0 < p.to_real) {f : Π i, E i} :\n  mem_ℓp f p ↔ summable (λ i, ∥f i∥ ^ p.to_real) :=\nbegin\n  rw ennreal.to_real_pos_iff at hp,\n  dsimp [mem_ℓp],\n  rw [if_neg hp.1.ne', if_neg hp.2.ne],\nend\n\nlemma mem_ℓp_gen {f : Π i, E i} (hf : summable (λ i, ∥f i∥ ^ p.to_real)) :\n  mem_ℓp f p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_ℓp_zero,\n    have H : summable (λ i : α, (1:ℝ)) := by simpa using hf,\n    exact (finite_of_summable_const (by norm_num) H).subset (set.subset_univ _) },\n  { apply mem_ℓp_infty,\n    have H : summable (λ i : α, (1:ℝ)) := by simpa using hf,\n    simpa using ((finite_of_summable_const (by norm_num) H).image (λ i, ∥f i∥)).bdd_above },\n  exact (mem_ℓp_gen_iff hp).2 hf\nend\n\nlemma mem_ℓp_gen' {C : ℝ} {f : Π i, E i} (hf : ∀ s : finset α, ∑ i in s, ∥f i∥ ^ p.to_real ≤ C) :\n  mem_ℓp f p :=\nbegin\n  apply mem_ℓp_gen,\n  use ⨆ s : finset α, ∑ i in s, ∥f i∥ ^ 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 - ⟨s, rfl⟩,\n  exact hf s\nend\n\nlemma zero_mem_ℓp : mem_ℓp (0 : Π i, E i) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_ℓp_zero,\n    simp },\n  { apply mem_ℓp_infty,\n    simp only [norm_zero, pi.zero_apply],\n    exact bdd_above_singleton.mono set.range_const_subset, },\n  { apply mem_ℓp_gen,\n    simp [real.zero_rpow hp.ne', summable_zero], }\nend\n\nlemma zero_mem_ℓp' : mem_ℓp (λ i : α, (0 : E i)) p := zero_mem_ℓp\n\nnamespace mem_ℓp\n\nlemma finite_dsupport {f : Π i, E i} (hf : mem_ℓp f 0) : set.finite {i | f i ≠ 0} :=\nmem_ℓp_zero_iff.1 hf\n\nlemma bdd_above {f : Π i, E i} (hf : mem_ℓp f ∞) : bdd_above (set.range (λ i, ∥f i∥)) :=\nmem_ℓp_infty_iff.1 hf\n\nlemma summable (hp : 0 < p.to_real) {f : Π i, E i} (hf : mem_ℓp f p) :\n  summable (λ i, ∥f i∥ ^ p.to_real) :=\n(mem_ℓp_gen_iff hp).1 hf\n\nlemma neg {f : Π i, E i} (hf : mem_ℓp f p) : mem_ℓp (-f) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_ℓp_zero,\n    simp [hf.finite_dsupport] },\n  { apply mem_ℓp_infty,\n    simpa using hf.bdd_above },\n  { apply mem_ℓp_gen,\n    simpa using hf.summable hp },\nend\n\n@[simp] lemma neg_iff {f : Π i, E i} : mem_ℓp (-f) p ↔ mem_ℓp f p :=\n⟨λ h, neg_neg f ▸ h.neg, mem_ℓp.neg⟩\n\nlemma of_exponent_ge {p q : ℝ≥0∞} {f : Π i, E i}\n  (hfq : mem_ℓp f q) (hpq : q ≤ p) :\n  mem_ℓp f p :=\nbegin\n  rcases ennreal.trichotomy₂ hpq with ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, hp⟩ | ⟨rfl, rfl⟩ | ⟨hq, rfl⟩\n    | ⟨hq, hp, hpq'⟩,\n  { exact hfq },\n  { apply mem_ℓp_infty,\n    obtain ⟨C, hC⟩ := (hfq.finite_dsupport.image (λ i, ∥f i∥)).bdd_above,\n    use max 0 C,\n    rintros x ⟨i, rfl⟩,\n    by_cases hi : f i = 0,\n    { simp [hi] },\n    { exact (hC ⟨i, hi, rfl⟩).trans (le_max_right _ _) } },\n  { apply mem_ℓp_gen,\n    have : ∀ i ∉ hfq.finite_dsupport.to_finset, ∥f i∥ ^ 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_ℓp_infty,\n    obtain ⟨A, hA⟩ := (hfq.summable hq).tendsto_cofinite_zero.bdd_above_range_of_cofinite,\n    use A ^ (q.to_real⁻¹),\n    rintros x ⟨i, rfl⟩,\n    have : 0 ≤ ∥f i∥ ^ q.to_real := real.rpow_nonneg_of_nonneg (norm_nonneg _) _,\n    simpa [← real.rpow_mul, mul_inv_cancel hq.ne'] using\n      real.rpow_le_rpow this (hA ⟨i, rfl⟩) (inv_nonneg.mpr hq.le) },\n  { apply mem_ℓp_gen,\n    have hf' := hfq.summable hq,\n    refine summable_of_norm_bounded_eventually _ hf' (@set.finite.subset _ {i | 1 ≤ ∥f i∥} _ _ _),\n    { have H : {x : α | 1 ≤ ∥f x∥ ^ q.to_real}.finite,\n      { simpa using eventually_lt_of_tendsto_lt (by norm_num : (0:ℝ) < 1)\n          hf'.tendsto_cofinite_zero },\n      exact H.subset (λ i hi, real.one_le_rpow hi hq.le) },\n    { show ∀ i, ¬ (|∥f i∥ ^ p.to_real| ≤ ∥f i∥ ^ q.to_real) → 1 ≤ ∥f i∥,\n      intros i hi,\n      have : 0 ≤ ∥f i∥ ^ 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 : Π i, E i} (hf : mem_ℓp f p) (hg : mem_ℓp g p) : mem_ℓp (f + g) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_ℓp_zero,\n    refine (hf.finite_dsupport.union hg.finite_dsupport).subset (λ i, _),\n    simp only [pi.add_apply, ne.def, set.mem_union_eq, set.mem_set_of_eq],\n    contrapose!,\n    rintros ⟨hf', hg'⟩,\n    simp [hf', hg'] },\n  { apply mem_ℓp_infty,\n    obtain ⟨A, hA⟩ := hf.bdd_above,\n    obtain ⟨B, hB⟩ := hg.bdd_above,\n    refine ⟨A + B, _⟩,\n    rintros a ⟨i, rfl⟩,\n    exact le_trans (norm_add_le _ _) (add_le_add (hA ⟨i, rfl⟩) (hB ⟨i, rfl⟩)) },\n  apply mem_ℓp_gen,\n  let C : ℝ := if p.to_real < 1 then 1 else 2 ^ (p.to_real - 1),\n  refine summable_of_nonneg_of_le _ (λ i, _) (((hf.summable hp).add (hg.summable hp)).mul_left C),\n  { exact λ 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 (∥f i∥₊) (∥g i∥₊) hp h.le) },\n    { let F : fin 2 → ℝ≥0 := ![∥f i∥₊, ∥g i∥₊],\n      have : ∀ i, (0:ℝ) ≤ F i := λ 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        (λ i _, (F i).coe_nonneg) } }\nend\n\nlemma sub {f g : Π i, E i} (hf : mem_ℓp f p) (hg : mem_ℓp g p) : mem_ℓp (f - g) p :=\nby { rw sub_eq_add_neg, exact hf.add hg.neg }\n\nlemma finset_sum {ι} (s : finset ι) {f : ι → Π i, E i} (hf : ∀ i ∈ s, mem_ℓp (f i) p) :\n  mem_ℓp (λ a, ∑ i in s, f i a) p :=\nbegin\n  haveI : decidable_eq ι := classical.dec_eq _,\n  revert hf,\n  refine finset.induction_on s _ _,\n  { simp only [zero_mem_ℓp', 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 (λ j hj, hf j (finset.mem_insert_of_mem hj))), },\nend\n\nsection normed_space\n\nvariables {𝕜 : Type*} [normed_field 𝕜] [Π i, normed_space 𝕜 (E i)]\n\nlemma const_smul {f : Π i, E i} (hf : mem_ℓp f p) (c : 𝕜) : mem_ℓp (c • f) p :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { apply mem_ℓp_zero,\n    refine hf.finite_dsupport.subset (λ i, (_ : ¬c • f i = 0 → ¬f i = 0)),\n    exact not_imp_not.mpr (λ hf', hf'.symm ▸ (smul_zero c)) },\n  { obtain ⟨A, hA⟩ := hf.bdd_above,\n    refine mem_ℓp_infty ⟨∥c∥ * A, _⟩,\n    rintros a ⟨i, rfl⟩,\n    simpa [norm_smul] using mul_le_mul_of_nonneg_left (hA ⟨i, rfl⟩) (norm_nonneg c) },\n  { apply mem_ℓp_gen,\n    convert (hf.summable hp).mul_left (∥c∥ ^ 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 : α → 𝕜} (hf : mem_ℓp f p) (c : 𝕜) : mem_ℓp (λ x, c * f x) p :=\n@mem_ℓp.const_smul α (λ i, 𝕜) _ _ 𝕜 _ _ _ hf c\n\nend normed_space\n\nend mem_ℓp\n\n/-!\n### lp space\n\nThe space of elements of `Π i, E i` satisfying the predicate `mem_ℓp`.\n-/\n\n/-- We define `pre_lp E` to be a type synonym for `Π i, E i` which, importantly, does not inherit\nthe `pi` topology on `Π 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 `Π 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 : α → Type*) [Π i, normed_group (E i)] : Type* := Π i, E i\n\ninstance pre_lp.unique [is_empty α] : unique (pre_lp E) := pi.unique_of_is_empty E\n\n/-- lp space -/\ndef lp (E : α → Type*) [Π i, normed_group (E i)]\n  (p : ℝ≥0∞) : add_subgroup (pre_lp E) :=\n{ carrier := {f | mem_ℓp f p},\n  zero_mem' := zero_mem_ℓp,\n  add_mem' := λ f g, mem_ℓp.add,\n  neg_mem' := λ f, mem_ℓp.neg }\n\nnamespace lp\n\ninstance : has_coe (lp E p) (Π i, E i) := coe_subtype\ninstance : has_coe_to_fun (lp E p) (λ _, Π i, E i) := ⟨λ f, ((f : Π i, E i) : Π i, E i)⟩\n\n@[ext] lemma ext {f g : lp E p} (h : (f : Π i, E i) = g) : f = g :=\nsubtype.ext h\n\nprotected lemma ext_iff {f g : lp E p} : f = g ↔ (f : Π i, E i) = g :=\nsubtype.ext_iff\n\nlemma eq_zero' [is_empty α] (f : lp E p) : f = 0 := subsingleton.elim f 0\n\nprotected lemma monotone {p q : ℝ≥0∞} (hpq : q ≤ p) : lp E q ≤ lp E p :=\nλ f hf, mem_ℓp.of_exponent_ge hf hpq\n\nprotected lemma mem_ℓp (f : lp E p) : mem_ℓp f p := f.prop\n\nvariables (E p)\n@[simp] lemma coe_fn_zero : ⇑(0 : lp E p) = 0 := rfl\nvariables {E p}\n\n@[simp] lemma coe_fn_neg (f : lp E p) : ⇑(-f) = -f := rfl\n\n@[simp] lemma coe_fn_add (f g : lp E p) : ⇑(f + g) = f + g := rfl\n\n@[simp] lemma coe_fn_sum {ι : Type*} (f : ι → lp E p) (s : finset ι) :\n  ⇑(∑ i in s, f i) = ∑ i in s, ⇑(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) : ⇑(f - g) = f - g := rfl\n\ninstance : has_norm (lp E p) :=\n{ norm := λ f, if hp : p = 0 then by subst hp; exact (lp.mem_ℓp f).finite_dsupport.to_finset.card\n   else (if p = ∞ then ⨆ i, ∥f i∥ else (∑' i, ∥f i∥ ^ p.to_real) ^ (1/p.to_real)) }\n\nlemma norm_eq_card_dsupport (f : lp E 0) : ∥f∥ = (lp.mem_ℓp f).finite_dsupport.to_finset.card :=\ndif_pos rfl\n\nlemma norm_eq_csupr (f : lp E ∞) : ∥f∥ = ⨆ i, ∥f i∥ :=\nbegin\n  dsimp [norm],\n  rw [dif_neg ennreal.top_ne_zero, if_pos rfl]\nend\n\nlemma is_lub_norm [nonempty α] (f : lp E ∞) : is_lub (set.range (λ i, ∥f i∥)) ∥f∥ :=\nbegin\n  rw lp.norm_eq_csupr,\n  exact is_lub_csupr (lp.mem_ℓp f)\nend\n\nlemma norm_eq_tsum_rpow (hp : 0 < p.to_real) (f : lp E p) :\n  ∥f∥ = (∑' i, ∥f i∥ ^ 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  ∥f∥ ^ p.to_real = ∑' i, ∥f i∥ ^ p.to_real :=\nbegin\n  rw [norm_eq_tsum_rpow hp, ← real.rpow_mul],\n  { field_simp [hp.ne'] },\n  apply tsum_nonneg,\n  intros i,\n  calc (0:ℝ) = 0 ^ p.to_real : by rw real.zero_rpow hp.ne'\n  ... ≤ _ : 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 (λ i, ∥f i∥ ^ p.to_real) (∥f∥ ^ p.to_real) :=\nbegin\n  rw norm_rpow_eq_tsum hp,\n  exact ((lp.mem_ℓp f).summable hp).has_sum\nend\n\nlemma norm_nonneg' (f : lp E p) : 0 ≤ ∥f∥ :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport f] },\n  { cases is_empty_or_nonempty α with _i _i; resetI,\n    { rw lp.norm_eq_csupr,\n      simp [real.csupr_empty] },\n    inhabit α,\n    exact (norm_nonneg (f default)).trans ((lp.is_lub_norm f).1 ⟨default, rfl⟩) },\n  { rw lp.norm_eq_tsum_rpow hp f,\n    refine real.rpow_nonneg_of_nonneg (tsum_nonneg _) _,\n    exact λ i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\nend\n\n@[simp] lemma norm_zero : ∥(0 : lp E p)∥ = 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 ≠ 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 ⦃f : lp E p⦄ : ∥f∥ = 0 ↔ f = 0 :=\nbegin\n  classical,\n  refine ⟨λ h, _, by { rintros rfl, exact norm_zero }⟩,\n  rcases p.trichotomy with rfl | rfl | hp,\n  { ext i,\n    have : {i : α | ¬f i = 0} = ∅ := by simpa [lp.norm_eq_card_dsupport f] using h,\n    have : (¬ (f i = 0)) = false := congr_fun this i,\n    tauto },\n  { cases is_empty_or_nonempty α with _i _i; resetI,\n    { simp },\n    have H : is_lub (set.range (λ i, ∥f i∥)) 0,\n    { simpa [h] using lp.is_lub_norm f },\n    ext i,\n    have : ∥f i∥ = 0 := le_antisymm (H.1 ⟨i, rfl⟩) (norm_nonneg _),\n    simpa using this },\n  { have hf : has_sum (λ (i : α), ∥f i∥ ^ p.to_real) 0,\n    { have := lp.has_sum_norm hp f,\n      rwa [h, real.zero_rpow hp.ne'] at this },\n    have : ∀ i, 0 ≤ ∥f i∥ ^ p.to_real := λ 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 ∧ p.to_real ≠ 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 ↔ ⇑f = 0 :=\nby rw [lp.ext_iff, coe_fn_zero]\n\n@[simp] lemma norm_neg ⦃f : lp E p⦄ : ∥-f∥ = ∥f∥ :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { simp [lp.norm_eq_card_dsupport] },\n  { cases is_empty_or_nonempty α; 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 : ∥-f∥ ^ p.to_real = ∥f∥ ^ 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 ≤ p)] : normed_group (lp E p) :=\nnormed_group.of_core _\n{ norm_eq_zero_iff := norm_eq_zero_iff,\n  triangle := λ f g, begin\n    unfreezingI { rcases p.dichotomy with rfl | hp' },\n    { cases is_empty_or_nonempty α; resetI,\n      { simp [lp.eq_zero' f] },\n      refine (lp.is_lub_norm (f + g)).2 _,\n      rintros x ⟨i, rfl⟩,\n      refine le_trans _ (add_mem_upper_bounds_add (lp.is_lub_norm f).1 (lp.is_lub_norm g).1\n        ⟨_, _, ⟨i, rfl⟩, ⟨i, rfl⟩, rfl⟩),\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₁ : ∀ i, 0 ≤ ∥f i∥ := λ i, norm_nonneg _,\n      have hg₁ : ∀ i, 0 ≤ ∥g i∥ := λ i, norm_nonneg _,\n      have hf₂ := lp.has_sum_norm hp'' f,\n      have hg₂ := lp.has_sum_norm hp'' g,\n      -- apply Minkowski's inequality\n      obtain ⟨C, hC₁, hC₂, hCfg⟩ :=\n        real.Lp_add_le_has_sum_of_nonneg hp' hf₁ hg₁ (norm_nonneg' _) (norm_nonneg' _) hf₂ hg₂,\n      refine le_trans _ hC₂,\n      rw ← real.rpow_le_rpow_iff (norm_nonneg' (f + g)) hC₁ 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 = ∞`.\n/-- Hölder inequality -/\nprotected \n\nprotected lemma summable_mul {p q : ℝ≥0∞}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  summable (λ i, ∥f i∥ * ∥g i∥) :=\n(lp.tsum_mul_le_mul_norm hpq f g).1\n\nprotected lemma tsum_mul_le_mul_norm' {p q : ℝ≥0∞}\n  (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p) (g : lp E q) :\n  ∑' i, ∥f i∥ * ∥g i∥ ≤ ∥f∥ * ∥g∥ :=\n(lp.tsum_mul_le_mul_norm hpq f g).2\n\nsection compare_pointwise\n\nlemma norm_apply_le_norm (hp : p ≠ 0) (f : lp E p) (i : α) : ∥f i∥ ≤ ∥f∥ :=\nbegin\n  rcases eq_or_ne p ∞ with rfl | hp',\n  { haveI : nonempty α := ⟨i⟩,\n    exact (is_lub_norm f).1 ⟨i, rfl⟩ },\n  have hp'' : 0 < p.to_real := ennreal.to_real_pos hp hp',\n  have : ∀ i, 0 ≤ ∥f i∥ ^ p.to_real,\n  { exact λ i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  rw ← real.rpow_le_rpow_iff (norm_nonneg _) (norm_nonneg' _) hp'',\n  convert le_has_sum (has_sum_norm hp'' f) i (λ i hi, this i),\nend\n\nlemma sum_rpow_le_norm_rpow (hp : 0 < p.to_real) (f : lp E p) (s : finset α) :\n  ∑ i in s, ∥f i∥ ^ p.to_real ≤ ∥f∥ ^ p.to_real :=\nbegin\n  rw lp.norm_rpow_eq_tsum hp f,\n  have : ∀ i, 0 ≤ ∥f i∥ ^ p.to_real,\n  { exact λ i, real.rpow_nonneg_of_nonneg (norm_nonneg _) _ },\n  refine sum_le_tsum _ (λ i hi, this i) _,\n  exact (lp.mem_ℓp f).summable hp\nend\n\nlemma norm_le_of_forall_le' [nonempty α] {f : lp E ∞} (C : ℝ) (hCf : ∀ i, ∥f i∥ ≤ C) : ∥f∥ ≤ C :=\nbegin\n  refine (is_lub_norm f).2 _,\n  rintros - ⟨i, rfl⟩,\n  exact hCf i,\nend\n\nlemma norm_le_of_forall_le {f : lp E ∞} {C : ℝ} (hC : 0 ≤ C) (hCf : ∀ i, ∥f i∥ ≤ C) : ∥f∥ ≤ C :=\nbegin\n  casesI is_empty_or_nonempty α,\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 : ℝ} (hC : 0 ≤ C) {f : lp E p}\n  (hf : ∑' i, ∥f i∥ ^ p.to_real ≤ C ^ p.to_real) :\n  ∥f∥ ≤ C :=\nbegin\n  rw [← 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 : ℝ} (hC : 0 ≤ C) {f : lp E p}\n  (hf : ∀ s : finset α, ∑ i in s, ∥f i∥ ^ p.to_real ≤ C ^ p.to_real) :\n  ∥f∥ ≤ C :=\nnorm_le_of_tsum_le hp hC (tsum_le_of_sum_le ((lp.mem_ℓp f).summable hp) hf)\n\nend compare_pointwise\n\nsection normed_space\n\nvariables {𝕜 : Type*} [normed_field 𝕜] [Π i, normed_space 𝕜 (E i)]\n\ninstance : module 𝕜 (pre_lp E) := pi.module α E 𝕜\n\nlemma mem_lp_const_smul (c : 𝕜) (f : lp E p) : c • (f : pre_lp E) ∈ lp E p :=\n(lp.mem_ℓp f).const_smul c\n\nvariables (E p 𝕜)\n\n/-- The `𝕜`-submodule of elements of `Π i : α, E i` whose `lp` norm is finite.  This is `lp E p`,\nwith extra structure. -/\ndef lp_submodule : submodule 𝕜 (pre_lp E) :=\n{ smul_mem' := λ c f hf, by simpa using mem_lp_const_smul c ⟨f, hf⟩,\n  .. lp E p }\n\nvariables {E p 𝕜}\n\nlemma coe_lp_submodule : (lp_submodule E p 𝕜).to_add_subgroup = lp E p := rfl\n\ninstance : module 𝕜 (lp E p) :=\n{ .. (lp_submodule E p 𝕜).module }\n\n@[simp] lemma coe_fn_smul (c : 𝕜) (f : lp E p) : ⇑(c • f) = c • f := rfl\n\nlemma norm_const_smul (hp : p ≠ 0) {c : 𝕜} (f : lp E p) : ∥c • f∥ = ∥c∥ * ∥f∥ :=\nbegin\n  rcases p.trichotomy with rfl | rfl | hp,\n  { exact absurd rfl hp },\n  { cases is_empty_or_nonempty α; resetI,\n    { simp [lp.eq_zero' f], },\n    apply (lp.is_lub_norm (c • 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 : ∥c • f∥ ^ p.to_real = (∥c∥ * ∥f∥) ^ 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 • f)).unique,\n    convert (lp.has_sum_norm hp f).mul_left (∥c∥ ^ p.to_real),\n    { simp [coe_fn_smul, norm_smul, real.mul_rpow (norm_nonneg c) (norm_nonneg _)] },\n    have hf : 0 ≤ ∥f∥ := lp.norm_nonneg' f,\n    simp [coe_fn_smul, norm_smul, real.mul_rpow (norm_nonneg c) hf] }\nend\n\ninstance [fact (1 ≤ p)] : normed_space 𝕜 (lp E p) :=\n{ norm_smul_le := λ 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 {𝕜' : Type*} [normed_field 𝕜']\n\ninstance [Π i, normed_space 𝕜' (E i)] [has_scalar 𝕜' 𝕜] [Π i, is_scalar_tower 𝕜' 𝕜 (E i)] :\n  is_scalar_tower 𝕜' 𝕜 (lp E p) :=\nbegin\n  refine ⟨λ r c f, _⟩,\n  ext1,\n  exact (lp.coe_fn_smul _ _).trans (smul_assoc _ _ _)\nend\n\nend normed_space\n\nsection single\nvariables {𝕜 : Type*} [normed_field 𝕜] [Π i, normed_space 𝕜 (E i)]\nvariables [decidable_eq α]\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 : α) (a : E i) : lp E p :=\n⟨ λ j, if h : j = i then eq.rec a h.symm else 0,\n  begin\n    refine (mem_ℓp_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 ⟩\n\nprotected lemma single_apply (p) (i : α) (a : E i) (j : α) :\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 : α) (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 : α) (a : E i) {j : α} (hij : j ≠ 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 : α) (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 : α) (a : E i) (c : 𝕜) :\n  lp.single p i (c • a) = c • 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 : Π i, E i) (s : finset α) :\n  ∥∑ i in s, lp.single p i (f i)∥ ^ p.to_real = ∑ i in s, ∥f i∥ ^ p.to_real :=\nbegin\n  refine (has_sum_norm hp (∑ 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 : ∀ i ∉ s, ∥ite (i ∈ s) (f i) 0∥ ^ p.to_real = 0,\n  { intros i hi,\n    simp [if_neg hi, real.zero_rpow hp.ne'], },\n  have h' : ∀ i ∈ s, ∥f i∥ ^ p.to_real = ∥ite (i ∈ s) (f i) 0∥ ^ 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 : Π i, E i) (i : α) :\n  ∥lp.single p i (f i)∥ = ∥f i∥ :=\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 α) :\n  ∥f∥ ^ p.to_real - ∥f - ∑ i in s, lp.single p i (f i)∥ ^ p.to_real = ∑ i in s, ∥f i∥ ^ p.to_real :=\nbegin\n  refine ((has_sum_norm hp f).sub (has_sum_norm hp (f - ∑ i in s, lp.single p i (f i)))).unique _,\n  let F : α → ℝ := λ i, ∥f i∥ ^ p.to_real - ∥(f - ∑ i in s, lp.single p i (f i)) i∥ ^ p.to_real,\n  have hF : ∀ i ∉ s, F i = 0,\n  { intros i hi,\n    suffices : ∥f i∥ ^ p.to_real - ∥f i - ite (i ∈ s) (f i) 0∥ ^ p.to_real = 0,\n    { simpa [F, coe_fn_sum, lp.single_apply] using this, },\n    simp [if_neg hi] },\n  have hF' : ∀ i ∈ s, F i = ∥f i∥ ^ 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 (∑ 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 α) :\n  ∥f - ∑ i in s, lp.single p i (f i)∥ ^ p.to_real = ∥f∥ ^ p.to_real - ∑ i in s, ∥f i∥ ^ 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 ≤ p)] (hp : p ≠ ⊤) (f : lp E p) :\n  has_sum (λ i : α, lp.single p i (f i : E i)) f :=\nbegin\n  have hp₀ : 0 < p := ennreal.zero_lt_one.trans_le (fact.out _),\n  have hp' : 0 < p.to_real := ennreal.to_real_pos hp₀.ne' hp,\n  have := lp.has_sum_norm hp' f,\n  dsimp [has_sum] at this ⊢,\n  rw metric.tendsto_nhds at this ⊢,\n  intros ε hε,\n  refine (this _ (real.rpow_pos_of_pos hε p.to_real)).mono _,\n  intros s hs,\n  rw ← real.rpow_lt_rpow_iff dist_nonneg (le_of_lt hε) hp',\n  rw dist_comm at hs,\n  simp only [dist_eq_norm, real.norm_eq_abs] at hs ⊢,\n  have H : ∥∑ i in s, lp.single p i (f i : E i) - f∥ ^ p.to_real\n    = ∥f∥ ^ p.to_real - ∑ i in s, ∥f i∥ ^ p.to_real,\n  { simpa using lp.norm_compl_sum_single hp' (-f) s },\n  rw ← H at hs,\n  have : |∥∑ i in s, lp.single p i (f i : E i) - f∥ ^ p.to_real|\n    = ∥∑ i in s, lp.single p i (f i : E i) - f∥ ^ 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 `Π i, E i` is uniformly continuous. -/\nlemma uniform_continuous_coe [_i : fact (1 ≤ p)] : uniform_continuous (coe : lp E p → Π i, E i) :=\nbegin\n  have hp : p ≠ 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 ε hε,\n  refine ⟨ε, hε, _⟩,\n  rintros f g (hfg : ∥f - g∥ < ε),\n  have : ∥f i - g i∥ ≤ ∥f - g∥ := norm_apply_le_norm hp (f - g) i,\n  exact this.trans_lt hfg,\nend\n\nvariables {ι : Type*} {l : filter ι} [filter.ne_bot l]\n\nlemma norm_apply_le_of_tendsto {C : ℝ} {F : ι → lp E ∞} (hCF : ∀ᶠ k in l, ∥F k∥ ≤ C)\n  {f : Π a, E a} (hf : tendsto (id (λ i, F i) : ι → Π a, E a) l (𝓝 f)) (a : α) :\n  ∥f a∥ ≤ C :=\nbegin\n  have : tendsto (λ k, ∥F k a∥) l (𝓝 ∥f a∥) :=\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 ≤ p)]\n\ninclude _i\n\nlemma sum_rpow_le_of_tendsto (hp : p ≠ ∞) {C : ℝ} {F : ι → lp E p} (hCF : ∀ᶠ k in l, ∥F k∥ ≤ C)\n  {f : Π a, E a} (hf : tendsto (id (λ i, F i) : ι → Π a, E a) l (𝓝 f)) (s : finset α) :\n  ∑ (i : α) in s, ∥f i∥ ^ p.to_real ≤ C ^ p.to_real :=\nbegin\n  have hp' : p ≠ 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 : (Π a, E a) → ℝ := λ f, ∑ a in s, ∥f a∥ ^ p.to_real,\n  have hG : continuous G,\n  { refine continuous_finset_sum s _,\n    intros a ha,\n    have : continuous (λ f : Π a, E a, f a):= continuous_apply a,\n    exact this.norm.rpow_const (λ _, 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 `≤ C`, then the pointwise limit, if it exists, also has `lp` norm `≤ C`. -/\nlemma norm_le_of_tendsto {C : ℝ} {F : ι → lp E p} (hCF : ∀ᶠ k in l, ∥F k∥ ≤ C) {f : lp E p}\n  (hf : tendsto (id (λ i, F i) : ι → Π a, E a) l (𝓝 f)) :\n  ∥f∥ ≤ C :=\nbegin\n  obtain ⟨i, hi⟩ := hCF.exists,\n  have hC : 0 ≤ 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_ℓp_of_tendsto {F : ι → lp E p} (hF : metric.bounded (set.range F)) {f : Π a, E a}\n  (hf : tendsto (id (λ i, F i) : ι → Π a, E a) l (𝓝 f)) :\n  mem_ℓp f p :=\nbegin\n  obtain ⟨C, hC, hCF'⟩ := hF.exists_pos_norm_le,\n  have hCF : ∀ k, ∥F k∥ ≤ C := λ k, hCF' _ ⟨k, rfl⟩,\n  unfreezingI { rcases eq_top_or_lt_top p with rfl | hp },\n  { apply mem_ℓp_infty,\n    use C,\n    rintros _ ⟨a, rfl⟩,\n    refine norm_apply_le_of_tendsto (eventually_of_forall hCF) hf a, },\n  { apply mem_ℓp_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 : ℕ → lp E p} (hF : cauchy_seq F) {f : lp E p}\n  (hf : tendsto (id (λ i, F i) : ℕ → Π a, E a) at_top (𝓝 f)) :\n  tendsto F at_top (𝓝 f) :=\nbegin\n  rw metric.nhds_basis_closed_ball.tendsto_right_iff,\n  intros ε hε,\n  have hε' : {p : (lp E p) × (lp E p) | ∥p.1 - p.2∥ < ε} ∈ 𝓤 (lp E p),\n  { exact normed_group.uniformity_basis_dist.mem_of_mem hε },\n  refine (hF.eventually_eventually hε').mono _,\n  rintros n (hn : ∀ᶠ l in at_top, ∥(λ f, F n - f) (F l)∥ < ε),\n  refine norm_le_of_tendsto (hn.mono (λ 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 [Π 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 ⟨f, hf⟩ := 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_ℓp f p := mem_ℓp_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 ⟨⟨f, hf'⟩, tendsto_lp_of_tendsto_pi hF hf⟩\nend\n\nend topology\n\nend lp\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/lp_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545377452442, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7661725975244777}}
{"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ébastien Gouëzel, Frédéric Dupuis\n\n! This file was ported from Lean 3 source module analysis.inner_product_space.basic\n! leanprover-community/mathlib commit 6e272cd89fa32c72a25dbefd319394c48dce1576\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Algebra.DirectSum.Module\nimport Mathbin.Analysis.Complex.Basic\nimport Mathbin.Analysis.Convex.Uniform\nimport Mathbin.Analysis.NormedSpace.Completion\nimport Mathbin.Analysis.NormedSpace.BoundedLinearMaps\nimport Mathbin.LinearAlgebra.BilinearForm\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 𝕜 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 `ℝ^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 → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `euclidean_space` in\n`analysis.inner_product_space.pi_L2`.\n\n## Main results\n\n- We define the class `inner_product_space 𝕜 E` extending `normed_space 𝕜 E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ`\n  or `ℂ`, 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ₛₗ` for the non-continuous version).\n- We define `orthonormal`, a predicate on a function `v : ι → 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 `⟪v i, x⟫` 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 `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `⟪·, ·⟫` 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ément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]\n\nThe Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>\n-/\n\n\nnoncomputable section\n\nopen IsROrC Real Filter\n\nopen BigOperators Topology ComplexConjugate\n\nvariable {𝕜 E F : Type _} [IsROrC 𝕜]\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass HasInner (𝕜 E : Type _) where\n  inner : E → E → 𝕜\n#align has_inner HasInner\n\nexport HasInner (inner)\n\n-- mathport name: «expr⟪ , ⟫_ℝ»\nnotation \"⟪\" x \", \" y \"⟫_ℝ\" => @inner ℝ _ _ x y\n\n-- mathport name: «expr⟪ , ⟫_ℂ»\nnotation \"⟪\" x \", \" y \"⟫_ℂ\" => @inner ℂ _ _ x y\n\nsection Notations\n\n-- mathport name: inner.real\nscoped[RealInnerProductSpace] notation \"⟪\" x \", \" y \"⟫\" => @inner ℝ _ _ x y\n\n-- mathport name: inner.complex\nscoped[ComplexInnerProductSpace] notation \"⟪\" x \", \" y \"⟫\" => @inner ℂ _ _ x y\n\nend Notations\n\n/-- An 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 `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass InnerProductSpace (𝕜 : Type _) (E : Type _) [IsROrC 𝕜] [NormedAddCommGroup E] extends\n  NormedSpace 𝕜 E, HasInner 𝕜 E where\n  norm_sq_eq_inner : ∀ x : E, ‖x‖ ^ 2 = re (inner x x)\n  conj_symm : ∀ x y, conj (inner y x) = inner x y\n  add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z\n  smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y\n#align inner_product_space InnerProductSpace\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 `ℝ`), 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\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 InnerProductSpace.Core (𝕜 : Type _) (F : Type _) [IsROrC 𝕜] [AddCommGroup F]\n  [Module 𝕜 F] where\n  inner : F → F → 𝕜\n  conj_symm : ∀ x y, conj (inner y x) = inner x y\n  nonneg_re : ∀ x, 0 ≤ re (inner x x)\n  definite : ∀ x, inner x x = 0 → x = 0\n  add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z\n  smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y\n#align inner_product_space.core InnerProductSpace.Core\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] InnerProductSpace.Core\n\nnamespace InnerProductSpace.ofCore\n\nvariable [AddCommGroup F] [Module 𝕜 F] [c : InnerProductSpace.Core 𝕜 F]\n\ninclude c\n\n-- mathport name: «expr⟪ , ⟫»\nlocal notation \"⟪\" x \", \" y \"⟫\" => @inner 𝕜 F _ x y\n\n-- mathport name: exprnorm_sqK\nlocal notation \"norm_sqK\" => @IsROrC.normSq 𝕜 _\n\n-- mathport name: exprreK\nlocal notation \"reK\" => @IsROrC.re 𝕜 _\n\n-- mathport name: exprabsK\nlocal notation \"absK\" => @IsROrC.abs 𝕜 _\n\n-- mathport name: exprext_iff\nlocal notation \"ext_iff\" => @IsROrC.ext_iff 𝕜 _\n\n-- mathport name: «expr †»\nlocal postfix:90 \"†\" => starRingEnd _\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef toHasInner : HasInner 𝕜 F where inner := c.inner\n#align inner_product_space.of_core.to_has_inner InnerProductSpace.OfCore.toHasInner\n\nattribute [local instance] to_has_inner\n\n/-- The norm squared function for `inner_product_space.core` structure. -/\ndef normSq (x : F) :=\n  reK ⟪x, x⟫\n#align inner_product_space.of_core.norm_sq InnerProductSpace.OfCore.normSq\n\n-- mathport name: exprnorm_sqF\nlocal notation \"norm_sqF\" => @normSq 𝕜 F _ _ _ _\n\ntheorem inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ :=\n  c.conj_symm x y\n#align inner_product_space.of_core.inner_conj_symm InnerProductSpace.OfCore.inner_conj_symm\n\ntheorem inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ :=\n  c.nonneg_re _\n#align inner_product_space.of_core.inner_self_nonneg InnerProductSpace.OfCore.inner_self_nonneg\n\ntheorem inner_self_nonneg_im (x : F) : im ⟪x, x⟫ = 0 := by\n  rw [← @of_real_inj 𝕜, im_eq_conj_sub] <;> simp [inner_conj_symm]\n#align inner_product_space.of_core.inner_self_nonneg_im InnerProductSpace.OfCore.inner_self_nonneg_im\n\ntheorem inner_self_im_zero (x : F) : im ⟪x, x⟫ = 0 :=\n  inner_self_nonneg_im _\n#align inner_product_space.of_core.inner_self_im_zero InnerProductSpace.OfCore.inner_self_im_zero\n\ntheorem inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=\n  c.add_left _ _ _\n#align inner_product_space.of_core.inner_add_left InnerProductSpace.OfCore.inner_add_left\n\ntheorem inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by\n  rw [← inner_conj_symm, inner_add_left, RingHom.map_add] <;> simp only [inner_conj_symm]\n#align inner_product_space.of_core.inner_add_right InnerProductSpace.OfCore.inner_add_right\n\ntheorem inner_normSq_eq_inner_self (x : F) : (norm_sqF x : 𝕜) = ⟪x, x⟫ :=\n  by\n  rw [ext_iff]\n  exact ⟨by simp only [of_real_re] <;> rfl, by simp only [inner_self_nonneg_im, of_real_im]⟩\n#align inner_product_space.of_core.inner_norm_sq_eq_inner_self InnerProductSpace.OfCore.inner_normSq_eq_inner_self\n\ntheorem inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]\n#align inner_product_space.of_core.inner_re_symm InnerProductSpace.OfCore.inner_re_symm\n\ntheorem inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]\n#align inner_product_space.of_core.inner_im_symm InnerProductSpace.OfCore.inner_im_symm\n\ntheorem inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=\n  c.smul_left _ _ _\n#align inner_product_space.of_core.inner_smul_left InnerProductSpace.OfCore.inner_smul_left\n\ntheorem inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by\n  rw [← inner_conj_symm, inner_smul_left] <;>\n    simp only [conj_conj, inner_conj_symm, RingHom.map_mul]\n#align inner_product_space.of_core.inner_smul_right InnerProductSpace.OfCore.inner_smul_right\n\ntheorem inner_zero_left (x : F) : ⟪0, x⟫ = 0 := by\n  rw [← zero_smul 𝕜 (0 : F), inner_smul_left] <;>\n    simp only [MulZeroClass.zero_mul, RingHom.map_zero]\n#align inner_product_space.of_core.inner_zero_left InnerProductSpace.OfCore.inner_zero_left\n\ntheorem inner_zero_right (x : F) : ⟪x, 0⟫ = 0 := by\n  rw [← inner_conj_symm, inner_zero_left] <;> simp only [RingHom.map_zero]\n#align inner_product_space.of_core.inner_zero_right InnerProductSpace.OfCore.inner_zero_right\n\ntheorem inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 :=\n  Iff.intro (c.definite _)\n    (by\n      rintro rfl\n      exact inner_zero_left _)\n#align inner_product_space.of_core.inner_self_eq_zero InnerProductSpace.OfCore.inner_self_eq_zero\n\ntheorem inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=\n  inner_self_eq_zero.Not\n#align inner_product_space.of_core.inner_self_ne_zero InnerProductSpace.OfCore.inner_self_ne_zero\n\ntheorem inner_self_re_to_K (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := by\n  norm_num [ext_iff, inner_self_nonneg_im]\n#align inner_product_space.of_core.inner_self_re_to_K InnerProductSpace.OfCore.inner_self_re_to_K\n\ntheorem inner_abs_conj_symm (x y : F) : abs ⟪x, y⟫ = abs ⟪y, x⟫ := by\n  rw [← inner_conj_symm, abs_conj]\n#align inner_product_space.of_core.inner_abs_conj_symm InnerProductSpace.OfCore.inner_abs_conj_symm\n\ntheorem inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ :=\n  by\n  rw [← neg_one_smul 𝕜 x, inner_smul_left]\n  simp\n#align inner_product_space.of_core.inner_neg_left InnerProductSpace.OfCore.inner_neg_left\n\ntheorem inner_neg_right (x y : F) : ⟪x, -y⟫ = -⟪x, y⟫ := by\n  rw [← inner_conj_symm, inner_neg_left] <;> simp only [RingHom.map_neg, inner_conj_symm]\n#align inner_product_space.of_core.inner_neg_right InnerProductSpace.OfCore.inner_neg_right\n\ntheorem inner_sub_left (x y z : F) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by\n  simp [sub_eq_add_neg, inner_add_left, inner_neg_left]\n#align inner_product_space.of_core.inner_sub_left InnerProductSpace.OfCore.inner_sub_left\n\ntheorem inner_sub_right (x y z : F) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by\n  simp [sub_eq_add_neg, inner_add_right, inner_neg_right]\n#align inner_product_space.of_core.inner_sub_right InnerProductSpace.OfCore.inner_sub_right\n\ntheorem inner_mul_conj_re_abs (x y : F) : re (⟪x, y⟫ * ⟪y, x⟫) = abs (⟪x, y⟫ * ⟪y, x⟫) :=\n  by\n  rw [← inner_conj_symm, mul_comm]\n  exact re_eq_abs_of_mul_conj (inner y x)\n#align inner_product_space.of_core.inner_mul_conj_re_abs InnerProductSpace.OfCore.inner_mul_conj_re_abs\n\n/-- Expand `inner (x + y) (x + y)` -/\ntheorem inner_add_add_self (x y : F) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by\n  simp only [inner_add_left, inner_add_right] <;> ring\n#align inner_product_space.of_core.inner_add_add_self InnerProductSpace.OfCore.inner_add_add_self\n\n-- Expand `inner (x - y) (x - y)`\ntheorem inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by\n  simp only [inner_sub_left, inner_sub_right] <;> ring\n#align inner_product_space.of_core.inner_sub_sub_self InnerProductSpace.OfCore.inner_sub_sub_self\n\n/-- **Cauchy–Schwarz 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 (x y : F) : abs ⟪x, y⟫ * abs ⟪y, x⟫ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=\n  by\n  by_cases hy : y = 0\n  · rw [hy]\n    simp only [IsROrC.abs_zero, inner_zero_left, MulZeroClass.mul_zero, AddMonoidHom.map_zero]\n  · change y ≠ 0 at hy\n    have hy' : ⟪y, y⟫ ≠ 0 := inner_self_ne_zero.mpr hy\n    set T := ⟪y, x⟫ / ⟪y, y⟫ with hT\n    have h₁ : re ⟪y, x⟫ = re ⟪x, y⟫ := inner_re_symm _ _\n    have h₂ : im ⟪y, x⟫ = -im ⟪x, y⟫ := inner_im_symm _ _\n    have h₃ : ⟪y, x⟫ * ⟪x, y⟫ * ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = ⟪y, x⟫ * ⟪x, y⟫ / ⟪y, y⟫ :=\n      by\n      rw [mul_div_assoc]\n      have : ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = 1 / ⟪y, y⟫ := by\n        rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul]\n      rw [this, div_eq_mul_inv, one_mul, ← div_eq_mul_inv]\n    have h₄ : ⟪y, y⟫ = re ⟪y, y⟫ := by simp only [inner_self_re_to_K]\n    have h₅ : re ⟪y, y⟫ > 0 :=\n      by\n      refine' lt_of_le_of_ne inner_self_nonneg _\n      intro H\n      apply hy'\n      rw [ext_iff]\n      exact ⟨by simp only [H, zero_re'], by simp only [inner_self_nonneg_im, AddMonoidHom.map_zero]⟩\n    have h₆ : re ⟪y, y⟫ ≠ 0 := ne_of_gt h₅\n    have hmain :=\n      calc\n        0 ≤ re ⟪x - T • y, x - T • y⟫ := inner_self_nonneg\n        _ = re ⟪x, x⟫ - re ⟪T • y, x⟫ - re ⟪x, T • y⟫ + re ⟪T • y, T • y⟫ := by\n          simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h₁, h₂, neg_mul,\n            AddMonoidHom.map_add, mul_re, conj_im, AddMonoidHom.map_sub, mul_neg, conj_re, neg_neg]\n        _ = re ⟪x, x⟫ - re (T† * ⟪y, x⟫) - re (T * ⟪x, y⟫) + re (T * T† * ⟪y, y⟫) := by\n          simp only [inner_smul_left, inner_smul_right, mul_assoc]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ / ⟪y, y⟫ * ⟪y, x⟫) := by\n          field_simp [-mul_re, inner_conj_symm, hT, map_div₀, h₁, h₃]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / ⟪y, y⟫) := by rw [← mul_div_right_comm]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / re ⟪y, y⟫) := by conv_lhs => rw [h₄]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫ := by rw [div_re_of_real]\n        _ = re ⟪x, x⟫ - abs (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫ := by rw [inner_mul_conj_re_abs]\n        _ = re ⟪x, x⟫ - abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫ := by rw [IsROrC.abs_mul]\n        \n    have hmain' : abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫ ≤ re ⟪x, x⟫ := by linarith\n    have := (mul_le_mul_right h₅).mpr hmain'\n    rwa [div_mul_cancel (abs ⟪x, y⟫ * abs ⟪y, x⟫) h₆] at this\n#align inner_product_space.of_core.inner_mul_inner_self_le InnerProductSpace.OfCore.inner_mul_inner_self_le\n\n/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root\nof the scalar product. -/\ndef toHasNorm : Norm F where norm x := sqrt (re ⟪x, x⟫)\n#align inner_product_space.of_core.to_has_norm InnerProductSpace.OfCore.toHasNorm\n\nattribute [local instance] to_has_norm\n\ntheorem norm_eq_sqrt_inner (x : F) : ‖x‖ = sqrt (re ⟪x, x⟫) :=\n  rfl\n#align inner_product_space.of_core.norm_eq_sqrt_inner InnerProductSpace.OfCore.norm_eq_sqrt_inner\n\ntheorem inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by\n  rw [norm_eq_sqrt_inner, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg]\n#align inner_product_space.of_core.inner_self_eq_norm_mul_norm InnerProductSpace.OfCore.inner_self_eq_norm_mul_norm\n\ntheorem sqrt_normSq_eq_norm (x : F) : sqrt (norm_sqF x) = ‖x‖ :=\n  rfl\n#align inner_product_space.of_core.sqrt_norm_sq_eq_norm InnerProductSpace.OfCore.sqrt_normSq_eq_norm\n\n/-- Cauchy–Schwarz inequality with norm -/\ntheorem abs_inner_le_norm (x y : F) : abs ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=\n  nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _))\n    (by\n      have H : ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) = re ⟪y, y⟫ * re ⟪x, x⟫ :=\n        by\n        simp only [inner_self_eq_norm_mul_norm]\n        ring\n      rw [H]\n      conv =>\n        lhs\n        congr\n        rw [inner_abs_conj_symm]\n      exact inner_mul_inner_self_le y x)\n#align inner_product_space.of_core.abs_inner_le_norm InnerProductSpace.OfCore.abs_inner_le_norm\n\n/-- Normed group structure constructed from an `inner_product_space.core` structure -/\ndef toNormedAddCommGroup : NormedAddCommGroup F :=\n  AddGroupNorm.toNormedAddCommGroup\n    { toFun := fun x => sqrt (re ⟪x, x⟫)\n      map_zero' := by simp only [sqrt_zero, inner_zero_right, map_zero]\n      neg' := fun x => by simp only [inner_neg_left, neg_neg, inner_neg_right]\n      add_le' := fun x y =>\n        by\n        have h₁ : abs ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := abs_inner_le_norm _ _\n        have h₂ : re ⟪x, y⟫ ≤ abs ⟪x, y⟫ := re_le_abs _\n        have h₃ : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := by linarith\n        have h₄ : re ⟪y, x⟫ ≤ ‖x‖ * ‖y‖ := by rwa [← inner_conj_symm, conj_re]\n        have : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) :=\n          by\n          simp only [← inner_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      eq_zero_of_map_eq_zero' := fun x hx =>\n        (inner_self_eq_zero : ⟪x, x⟫ = 0 ↔ x = 0).1 <|\n          by\n          change sqrt (re ⟪x, x⟫) = 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#align inner_product_space.of_core.to_normed_add_comm_group InnerProductSpace.OfCore.toNormedAddCommGroup\n\nattribute [local instance] to_normed_add_comm_group\n\n/-- Normed space structure constructed from a `inner_product_space.core` structure -/\ndef toNormedSpace : NormedSpace 𝕜 F\n    where norm_smul_le r x :=\n    by\n    rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ← mul_assoc]\n    rw [conj_mul_eq_norm_sq_left, of_real_mul_re, sqrt_mul, ← inner_norm_sq_eq_inner_self,\n      of_real_re]\n    · simp [sqrt_norm_sq_eq_norm, IsROrC.sqrt_normSq_eq_norm]\n    · exact norm_sq_nonneg r\n#align inner_product_space.of_core.to_normed_space InnerProductSpace.OfCore.toNormedSpace\n\nend InnerProductSpace.ofCore\n\nsection\n\nattribute [local instance] InnerProductSpace.OfCore.toNormedAddCommGroup\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 InnerProductSpace.ofCore [AddCommGroup F] [Module 𝕜 F] (c : InnerProductSpace.Core 𝕜 F) :\n    InnerProductSpace 𝕜 F :=\n  letI : NormedSpace 𝕜 F := @InnerProductSpace.OfCore.toNormedSpace 𝕜 F _ _ _ c\n  { c with\n    norm_sq_eq_inner := fun x =>\n      by\n      have h₁ : ‖x‖ ^ 2 = sqrt (re (c.inner x x)) ^ 2 := rfl\n      have h₂ : 0 ≤ re (c.inner x x) := InnerProductSpace.OfCore.inner_self_nonneg\n      simp [h₁, sq_sqrt, h₂] }\n#align inner_product_space.of_core InnerProductSpace.ofCore\n\nend\n\n/-! ### Properties of inner product spaces -/\n\n\nvariable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]\n\nvariable [NormedAddCommGroup F] [InnerProductSpace ℝ F]\n\nvariable [dec_E : DecidableEq E]\n\n-- mathport name: «expr⟪ , ⟫»\nlocal notation \"⟪\" x \", \" y \"⟫\" => @inner 𝕜 _ _ x y\n\n-- mathport name: exprIK\nlocal notation \"IK\" => @IsROrC.i 𝕜 _\n\n-- mathport name: exprabsR\nlocal notation \"absR\" => Abs.abs\n\n-- mathport name: exprabsK\nlocal notation \"absK\" => @IsROrC.abs 𝕜 _\n\n-- mathport name: «expr †»\nlocal postfix:90 \"†\" => starRingEnd _\n\nexport InnerProductSpace (norm_sq_eq_inner)\n\nsection BasicProperties\n\n@[simp]\ntheorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ :=\n  InnerProductSpace.conj_symm _ _\n#align inner_conj_symm inner_conj_symm\n\ntheorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ :=\n  @inner_conj_symm ℝ _ _ _ _ x y\n#align real_inner_comm real_inner_comm\n\ntheorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 :=\n  ⟨fun h => by simp [← inner_conj_symm, h], fun h => by simp [← inner_conj_symm, h]⟩\n#align inner_eq_zero_symm inner_eq_zero_symm\n\n@[simp]\ntheorem inner_self_nonneg_im (x : E) : im ⟪x, x⟫ = 0 := by\n  rw [← @of_real_inj 𝕜, im_eq_conj_sub] <;> simp\n#align inner_self_nonneg_im inner_self_nonneg_im\n\ntheorem inner_self_im_zero (x : E) : im ⟪x, x⟫ = 0 :=\n  inner_self_nonneg_im _\n#align inner_self_im_zero inner_self_im_zero\n\ntheorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=\n  InnerProductSpace.add_left _ _ _\n#align inner_add_left inner_add_left\n\ntheorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ :=\n  by\n  rw [← inner_conj_symm, inner_add_left, RingHom.map_add]\n  simp only [inner_conj_symm]\n#align inner_add_right inner_add_right\n\ntheorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]\n#align inner_re_symm inner_re_symm\n\ntheorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]\n#align inner_im_symm inner_im_symm\n\ntheorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=\n  InnerProductSpace.smul_left _ _ _\n#align inner_smul_left inner_smul_left\n\ntheorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ :=\n  inner_smul_left _ _ _\n#align real_inner_smul_left real_inner_smul_left\n\ntheorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ :=\n  by\n  rw [inner_smul_left, conj_of_real, Algebra.smul_def]\n  rfl\n#align inner_smul_real_left inner_smul_real_left\n\ntheorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by\n  rw [← inner_conj_symm, inner_smul_left, RingHom.map_mul, conj_conj, inner_conj_symm]\n#align inner_smul_right inner_smul_right\n\ntheorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=\n  inner_smul_right _ _ _\n#align real_inner_smul_right real_inner_smul_right\n\ntheorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ :=\n  by\n  rw [inner_smul_right, Algebra.smul_def]\n  rfl\n#align inner_smul_real_right inner_smul_real_right\n\n/-- The inner product as a sesquilinear form.\n\nNote that in the case `𝕜 = ℝ` this is a bilinear form. -/\n@[simps]\ndef sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=\n  LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫)\n    (fun x y z => inner_add_right _ _ _) (fun r x y => inner_smul_right _ _ _)\n    (fun x y z => inner_add_left _ _ _) fun r x y => inner_smul_left _ _ _\n#align sesq_form_of_inner sesqFormOfInner\n\n/-- The real inner product as a bilinear form. -/\n@[simps]\ndef bilinFormOfRealInner : BilinForm ℝ F\n    where\n  bilin := inner\n  bilin_add_left := inner_add_left\n  bilin_smul_left a x y := inner_smul_left _ _ _\n  bilin_add_right := inner_add_right\n  bilin_smul_right a x y := inner_smul_right _ _ _\n#align bilin_form_of_real_inner bilinFormOfRealInner\n\n/-- An inner product with a sum on the left. -/\ntheorem sum_inner {ι : Type _} (s : Finset ι) (f : ι → E) (x : E) :\n    ⟪∑ i in s, f i, x⟫ = ∑ i in s, ⟪f i, x⟫ :=\n  (sesqFormOfInner x).map_sum\n#align sum_inner sum_inner\n\n/-- An inner product with a sum on the right. -/\ntheorem inner_sum {ι : Type _} (s : Finset ι) (f : ι → E) (x : E) :\n    ⟪x, ∑ i in s, f i⟫ = ∑ i in s, ⟪x, f i⟫ :=\n  (LinearMap.flip sesqFormOfInner x).map_sum\n#align inner_sum inner_sum\n\n/-- An inner product with a sum on the left, `finsupp` version. -/\ntheorem Finsupp.sum_inner {ι : Type _} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :\n    ⟪l.Sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.Sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ :=\n  by\n  convert sum_inner l.support (fun a => l a • v a) x\n  simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]\n#align finsupp.sum_inner Finsupp.sum_inner\n\n/-- An inner product with a sum on the right, `finsupp` version. -/\ntheorem Finsupp.inner_sum {ι : Type _} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :\n    ⟪x, l.Sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.Sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ :=\n  by\n  convert inner_sum l.support (fun a => l a • v a) x\n  simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]\n#align finsupp.inner_sum Finsupp.inner_sum\n\ntheorem Dfinsupp.sum_inner {ι : Type _} [dec : DecidableEq ι] {α : ι → Type _}\n    [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)\n    (l : Π₀ i, α i) (x : E) : ⟪l.Sum f, x⟫ = l.Sum fun i a => ⟪f i a, x⟫ := by\n  simp (config := { contextual := true }) only [Dfinsupp.sum, sum_inner, smul_eq_mul]\n#align dfinsupp.sum_inner Dfinsupp.sum_inner\n\ntheorem Dfinsupp.inner_sum {ι : Type _} [dec : DecidableEq ι] {α : ι → Type _}\n    [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)\n    (l : Π₀ i, α i) (x : E) : ⟪x, l.Sum f⟫ = l.Sum fun i a => ⟪x, f i a⟫ := by\n  simp (config := { contextual := true }) only [Dfinsupp.sum, inner_sum, smul_eq_mul]\n#align dfinsupp.inner_sum Dfinsupp.inner_sum\n\n@[simp]\ntheorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by\n  rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, MulZeroClass.zero_mul]\n#align inner_zero_left inner_zero_left\n\ntheorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by\n  simp only [inner_zero_left, AddMonoidHom.map_zero]\n#align inner_re_zero_left inner_re_zero_left\n\n@[simp]\ntheorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by\n  rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero]\n#align inner_zero_right inner_zero_right\n\ntheorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by\n  simp only [inner_zero_right, AddMonoidHom.map_zero]\n#align inner_re_zero_right inner_re_zero_right\n\ntheorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ := by\n  rw [← norm_sq_eq_inner] <;> exact pow_nonneg (norm_nonneg x) 2\n#align inner_self_nonneg inner_self_nonneg\n\ntheorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ :=\n  @inner_self_nonneg ℝ F _ _ _ x\n#align real_inner_self_nonneg real_inner_self_nonneg\n\n@[simp]\ntheorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 :=\n  by\n  constructor\n  · intro h\n    have h₁ : re ⟪x, x⟫ = 0 := by rw [IsROrC.ext_iff] at h <;> simp only [h.1, zero_re']\n    rw [← norm_sq_eq_inner x] at h₁\n    rw [← norm_eq_zero]\n    exact pow_eq_zero h₁\n  · rintro rfl\n    exact inner_zero_left _\n#align inner_self_eq_zero inner_self_eq_zero\n\ntheorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=\n  inner_self_eq_zero.Not\n#align inner_self_ne_zero inner_self_ne_zero\n\n@[simp]\ntheorem inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 :=\n  by\n  constructor\n  · intro h\n    rw [← @inner_self_eq_zero 𝕜]\n    have H₁ : re ⟪x, x⟫ ≥ 0 := inner_self_nonneg\n    have H₂ : re ⟪x, x⟫ = 0 := le_antisymm h H₁\n    rw [IsROrC.ext_iff]\n    exact ⟨by simp [H₂], by simp [inner_self_nonneg_im]⟩\n  · rintro rfl\n    simp only [inner_zero_left, AddMonoidHom.map_zero]\n#align inner_self_nonpos inner_self_nonpos\n\ntheorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 :=\n  by\n  have h := @inner_self_nonpos ℝ F _ _ _ x\n  simpa using h\n#align real_inner_self_nonpos real_inner_self_nonpos\n\n@[simp]\ntheorem inner_self_re_to_K (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=\n  IsROrC.ext_iff.2 ⟨by simp only [of_real_re], by simp only [inner_self_nonneg_im, of_real_im]⟩\n#align inner_self_re_to_K inner_self_re_to_K\n\ntheorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ ^ 2 : 𝕜) :=\n  by\n  suffices (IsROrC.re ⟪x, x⟫ : 𝕜) = ‖x‖ ^ 2 by simpa only [inner_self_re_to_K] using this\n  exact_mod_cast (norm_sq_eq_inner x).symm\n#align inner_self_eq_norm_sq_to_K inner_self_eq_norm_sq_to_K\n\ntheorem inner_self_re_abs (x : E) : re ⟪x, x⟫ = abs ⟪x, x⟫ :=\n  by\n  conv_rhs => rw [← inner_self_re_to_K]\n  symm\n  exact IsROrC.abs_of_nonneg inner_self_nonneg\n#align inner_self_re_abs inner_self_re_abs\n\ntheorem inner_self_abs_to_K (x : E) : (absK ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=\n  by\n  rw [← inner_self_re_abs]\n  exact inner_self_re_to_K _\n#align inner_self_abs_to_K inner_self_abs_to_K\n\ntheorem real_inner_self_abs (x : F) : absR ⟪x, x⟫_ℝ = ⟪x, x⟫_ℝ :=\n  by\n  have h := @inner_self_abs_to_K ℝ F _ _ _ x\n  simpa using h\n#align real_inner_self_abs real_inner_self_abs\n\ntheorem inner_abs_conj_symm (x y : E) : abs ⟪x, y⟫ = abs ⟪y, x⟫ := by\n  rw [← inner_conj_symm, abs_conj]\n#align inner_abs_conj_symm inner_abs_conj_symm\n\n@[simp]\ntheorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ :=\n  by\n  rw [← neg_one_smul 𝕜 x, inner_smul_left]\n  simp\n#align inner_neg_left inner_neg_left\n\n@[simp]\ntheorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by\n  rw [← inner_conj_symm, inner_neg_left] <;> simp only [RingHom.map_neg, inner_conj_symm]\n#align inner_neg_right inner_neg_right\n\ntheorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp\n#align inner_neg_neg inner_neg_neg\n\n@[simp]\ntheorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := by\n  rw [IsROrC.ext_iff] <;> exact ⟨by rw [conj_re], by rw [conj_im, inner_self_im_zero, neg_zero]⟩\n#align inner_self_conj inner_self_conj\n\ntheorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by\n  simp [sub_eq_add_neg, inner_add_left]\n#align inner_sub_left inner_sub_left\n\ntheorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by\n  simp [sub_eq_add_neg, inner_add_right]\n#align inner_sub_right inner_sub_right\n\ntheorem inner_mul_conj_re_abs (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = abs (⟪x, y⟫ * ⟪y, x⟫) :=\n  by\n  rw [← inner_conj_symm, mul_comm]\n  exact re_eq_abs_of_mul_conj (inner y x)\n#align inner_mul_conj_re_abs inner_mul_conj_re_abs\n\n/-- Expand `⟪x + y, x + y⟫` -/\ntheorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by\n  simp only [inner_add_left, inner_add_right] <;> ring\n#align inner_add_add_self inner_add_add_self\n\n/-- Expand `⟪x + y, x + y⟫_ℝ` -/\ntheorem real_inner_add_add_self (x y : F) : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ :=\n  by\n  have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm] <;> rfl\n  simp only [inner_add_add_self, this, add_left_inj]\n  ring\n#align real_inner_add_add_self real_inner_add_add_self\n\n-- Expand `⟪x - y, x - y⟫`\ntheorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by\n  simp only [inner_sub_left, inner_sub_right] <;> ring\n#align inner_sub_sub_self inner_sub_sub_self\n\n/-- Expand `⟪x - y, x - y⟫_ℝ` -/\ntheorem real_inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ :=\n  by\n  have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm] <;> rfl\n  simp only [inner_sub_sub_self, this, add_left_inj]\n  ring\n#align real_inner_sub_sub_self real_inner_sub_sub_self\n\nvariable (𝕜)\n\ninclude 𝕜\n\ntheorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by\n  rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]\n#align ext_inner_left ext_inner_left\n\ntheorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by\n  rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)]\n#align ext_inner_right ext_inner_right\n\nomit 𝕜\n\nvariable {𝕜}\n\n/-- Parallelogram law -/\ntheorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by\n  simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]\n#align parallelogram_law parallelogram_law\n\n/- ./././Mathport/Syntax/Translate/Tactic/Builtin.lean:69:18: unsupported non-interactive tactic tactic.field_simp.ne_zero -/\n/-- Cauchy–Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\ntheorem inner_mul_inner_self_le (x y : E) : abs ⟪x, y⟫ * abs ⟪y, x⟫ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=\n  by\n  by_cases hy : y = 0\n  · rw [hy]\n    simp only [IsROrC.abs_zero, inner_zero_left, MulZeroClass.mul_zero, AddMonoidHom.map_zero]\n  · have hy' : ⟪y, y⟫ ≠ 0 := inner_self_eq_zero.not.2 hy\n    set T := ⟪y, x⟫ / ⟪y, y⟫ with hT\n    have h₁ : re ⟪y, x⟫ = re ⟪x, y⟫ := inner_re_symm _ _\n    have h₂ : im ⟪y, x⟫ = -im ⟪x, y⟫ := inner_im_symm _ _\n    have h₃ : ⟪y, x⟫ * ⟪x, y⟫ * ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = ⟪y, x⟫ * ⟪x, y⟫ / ⟪y, y⟫ :=\n      by\n      rw [mul_div_assoc]\n      have : ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = 1 / ⟪y, y⟫ := by\n        rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul]\n      rw [this, div_eq_mul_inv, one_mul, ← div_eq_mul_inv]\n    have h₄ : ⟪y, y⟫ = re ⟪y, y⟫ := (inner_self_re_to_K _).symm\n    have h₅ : re ⟪y, y⟫ > 0 :=\n      by\n      refine' lt_of_le_of_ne inner_self_nonneg _\n      intro H\n      apply hy'\n      rw [IsROrC.ext_iff]\n      exact ⟨by simp only [H, zero_re'], by simp only [inner_self_nonneg_im, AddMonoidHom.map_zero]⟩\n    have h₆ : re ⟪y, y⟫ ≠ 0 := ne_of_gt h₅\n    have hmain :=\n      calc\n        0 ≤ re ⟪x - T • y, x - T • y⟫ := inner_self_nonneg\n        _ = re ⟪x, x⟫ - re ⟪T • y, x⟫ - re ⟪x, T • y⟫ + re ⟪T • y, T • y⟫ := by\n          simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h₁, h₂, neg_mul,\n            AddMonoidHom.map_add, conj_im, AddMonoidHom.map_sub, mul_neg, conj_re, neg_neg, mul_re]\n        _ = re ⟪x, x⟫ - re (T† * ⟪y, x⟫) - re (T * ⟪x, y⟫) + re (T * T† * ⟪y, y⟫) := by\n          simp only [inner_smul_left, inner_smul_right, mul_assoc]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ / ⟪y, y⟫ * ⟪y, x⟫) := by\n          simp (disch :=\n            run_tac\n              tactic.field_simp.ne_zero) only [map_div₀,\n            h₃, inner_conj_symm, sub_add_cancel, field_simps]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / ⟪y, y⟫) := by rw [← mul_div_right_comm]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / re ⟪y, y⟫) := by conv_lhs => rw [h₄]\n        _ = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫ := by rw [div_re_of_real]\n        _ = re ⟪x, x⟫ - abs (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫ := by rw [inner_mul_conj_re_abs]\n        _ = re ⟪x, x⟫ - abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫ := by rw [IsROrC.abs_mul]\n        \n    have hmain' : abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫ ≤ re ⟪x, x⟫ := by linarith\n    have := (mul_le_mul_right h₅).mpr hmain'\n    rwa [div_mul_cancel (abs ⟪x, y⟫ * abs ⟪y, x⟫) h₆] at this\n#align inner_mul_inner_self_le inner_mul_inner_self_le\n\n/-- Cauchy–Schwarz inequality for real inner products. -/\ntheorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=\n  by\n  have h₁ : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm] <;> rfl\n  have h₂ := @inner_mul_inner_self_le ℝ F _ _ _ x y\n  dsimp at h₂\n  have h₃ := abs_mul_abs_self ⟪x, y⟫_ℝ\n  rw [h₁] at h₂\n  simpa [h₃] using h₂\n#align real_inner_mul_inner_self_le real_inner_mul_inner_self_le\n\n/-- A family of vectors is linearly independent if they are nonzero\nand orthogonal. -/\ntheorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type _} {v : ι → E} (hz : ∀ i, v i ≠ 0)\n    (ho : ∀ i j, i ≠ j → ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v :=\n  by\n  rw [linearIndependent_iff']\n  intro s g hg i hi\n  have h' : g i * inner (v i) (v i) = inner (v i) (∑ j in s, g j • v j) :=\n    by\n    rw [inner_sum]\n    symm\n    convert Finset.sum_eq_single i _ _\n    · rw [inner_smul_right]\n    · intro j hj hji\n      rw [inner_smul_right, ho i j hji.symm, MulZeroClass.mul_zero]\n    · exact fun h => False.elim (h hi)\n  simpa [hg, hz] using h'\n#align linear_independent_of_ne_zero_of_inner_eq_zero linearIndependent_of_ne_zero_of_inner_eq_zero\n\nend BasicProperties\n\nsection OrthonormalSets\n\nvariable {ι : Type _} [dec_ι : DecidableEq ι] (𝕜)\n\ninclude 𝕜\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef Orthonormal (v : ι → E) : Prop :=\n  (∀ i, ‖v i‖ = 1) ∧ ∀ {i j}, i ≠ j → ⟪v i, v j⟫ = 0\n#align orthonormal Orthonormal\n\nomit 𝕜\n\nvariable {𝕜}\n\ninclude dec_ι\n\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\ntheorem orthonormal_iff_ite {v : ι → E} :\n    Orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1 : 𝕜) else (0 : 𝕜) :=\n  by\n  constructor\n  · intro hv i j\n    split_ifs\n    · simp [h, inner_self_eq_norm_sq_to_K, hv.1]\n    · exact hv.2 h\n  · intro h\n    constructor\n    · intro i\n      have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner 𝕜, h i i]\n      have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _\n      have h₂ : (0 : ℝ) ≤ 1 := zero_le_one\n      rwa [sq_eq_sq h₁ h₂] at h'\n    · intro i j hij\n      simpa [hij] using h i j\n#align orthonormal_iff_ite orthonormal_iff_ite\n\nomit dec_ι\n\ninclude dec_E\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 𝕜 (coe : s → E) ↔ ∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = if v = w then 1 else 0 :=\n  by\n  rw [orthonormal_iff_ite]\n  constructor\n  · intro h v hv w hw\n    convert h ⟨v, hv⟩ ⟨w, hw⟩ using 1\n    simp\n  · rintro h ⟨v, hv⟩ ⟨w, hw⟩\n    convert h v hv w hw using 1\n    simp\n#align orthonormal_subtype_iff_ite orthonormal_subtype_iff_ite\n\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. -/\ntheorem Orthonormal.inner_right_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) :\n    ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = l i := by\n  classical simp [Finsupp.total_apply, Finsupp.inner_sum, orthonormal_iff_ite.mp hv]\n#align orthonormal.inner_right_finsupp Orthonormal.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. -/\ntheorem Orthonormal.inner_right_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι}\n    {i : ι} (hi : i ∈ s) : ⟪v i, ∑ i in s, l i • v i⟫ = l i := by\n  classical simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi]\n#align orthonormal.inner_right_sum Orthonormal.inner_right_sum\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_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜)\n    (i : ι) : ⟪v i, ∑ i : ι, l i • v i⟫ = l i :=\n  hv.inner_right_sum l (Finset.mem_univ _)\n#align orthonormal.inner_right_fintype Orthonormal.inner_right_fintype\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 {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) :\n    ⟪Finsupp.total ι E 𝕜 v l, v i⟫ = conj (l i) := by rw [← inner_conj_symm, hv.inner_right_finsupp]\n#align orthonormal.inner_left_finsupp Orthonormal.inner_left_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. -/\ntheorem Orthonormal.inner_left_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι}\n    {i : ι} (hi : i ∈ s) : ⟪∑ i in s, l i • v i, v i⟫ = conj (l i) := by\n  classical simp only [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole,\n      Finset.sum_ite_eq', if_true]\n#align orthonormal.inner_left_sum Orthonormal.inner_left_sum\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_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜)\n    (i : ι) : ⟪∑ i : ι, l i • v i, v i⟫ = conj (l i) :=\n  hv.inner_left_sum l (Finset.mem_univ _)\n#align orthonormal.inner_left_fintype Orthonormal.inner_left_fintype\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum over the first `finsupp`. -/\ntheorem Orthonormal.inner_finsupp_eq_sum_left {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) :\n    ⟪Finsupp.total ι E 𝕜 v l₁, Finsupp.total ι E 𝕜 v l₂⟫ = l₁.Sum fun i y => conj y * l₂ i := by\n  simp only [l₁.total_apply _, Finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul]\n#align orthonormal.inner_finsupp_eq_sum_left Orthonormal.inner_finsupp_eq_sum_left\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum over the second `finsupp`. -/\ntheorem Orthonormal.inner_finsupp_eq_sum_right {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) :\n    ⟪Finsupp.total ι E 𝕜 v l₁, Finsupp.total ι E 𝕜 v l₂⟫ = l₂.Sum fun i y => conj (l₁ i) * y := by\n  simp only [l₂.total_apply _, Finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul]\n#align orthonormal.inner_finsupp_eq_sum_right Orthonormal.inner_finsupp_eq_sum_right\n\n/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as\na sum. -/\ntheorem Orthonormal.inner_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι → 𝕜) (s : Finset ι) :\n    ⟪∑ i in s, l₁ i • v i, ∑ i in s, l₂ i • v i⟫ = ∑ i in s, conj (l₁ i) * l₂ i :=\n  by\n  simp_rw [sum_inner, inner_smul_left]\n  refine' Finset.sum_congr rfl fun i hi => _\n  rw [hv.inner_right_sum l₂ hi]\n#align orthonormal.inner_sum Orthonormal.inner_sum\n\n/--\nThe double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the\nsum of the weights.\n-/\ntheorem Orthonormal.inner_left_right_finset {s : Finset ι} {v : ι → E} (hv : Orthonormal 𝕜 v)\n    {a : ι → ι → 𝕜} : (∑ i in s, ∑ j in s, a i j • ⟪v j, v i⟫) = ∑ k in s, a k k := by\n  classical simp [orthonormal_iff_ite.mp hv, Finset.sum_ite_of_true]\n#align orthonormal.inner_left_right_finset Orthonormal.inner_left_right_finset\n\n/-- An orthonormal set is linearly independent. -/\ntheorem Orthonormal.linearIndependent {v : ι → E} (hv : Orthonormal 𝕜 v) : LinearIndependent 𝕜 v :=\n  by\n  rw [linearIndependent_iff]\n  intro l hl\n  ext i\n  have key : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = ⟪v i, 0⟫ := by rw [hl]\n  simpa only [hv.inner_right_finsupp, inner_zero_right] using key\n#align orthonormal.linear_independent Orthonormal.linearIndependent\n\n/-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an\northonormal family. -/\ntheorem Orthonormal.comp {ι' : Type _} {v : ι → E} (hv : Orthonormal 𝕜 v) (f : ι' → ι)\n    (hf : Function.Injective f) : Orthonormal 𝕜 (v ∘ f) := by\n  classical\n    rw [orthonormal_iff_ite] at hv⊢\n    intro i j\n    convert hv (f i) (f j) using 1\n    simp [hf.eq_iff]\n#align orthonormal.comp Orthonormal.comp\n\n/-- An injective family `v : ι → E` is orthonormal if and only if `coe : (range v) → E` is\northonormal. -/\ntheorem orthonormal_subtype_range {v : ι → E} (hv : Function.Injective v) :\n    Orthonormal 𝕜 (coe : Set.range v → E) ↔ Orthonormal 𝕜 v :=\n  by\n  let f : ι ≃ Set.range v := Equiv.ofInjective v hv\n  refine' ⟨fun h => h.comp f f.injective, fun h => _⟩\n  rw [← Equiv.self_comp_ofInjective_symm hv]\n  exact h.comp f.symm f.symm.injective\n#align orthonormal_subtype_range orthonormal_subtype_range\n\n/-- If `v : ι → E` is an orthonormal family, then `coe : (range v) → E` is an orthonormal\nfamily. -/\ntheorem Orthonormal.to_subtype_range {v : ι → E} (hv : Orthonormal 𝕜 v) :\n    Orthonormal 𝕜 (coe : Set.range v → E) :=\n  (orthonormal_subtype_range hv.LinearIndependent.Injective).2 hv\n#align orthonormal.to_subtype_range Orthonormal.to_subtype_range\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 {v : ι → E} (hv : Orthonormal 𝕜 v) {s : Set ι} {i : ι}\n    (hi : i ∉ s) {l : ι →₀ 𝕜} (hl : l ∈ Finsupp.supported 𝕜 𝕜 s) :\n    ⟪Finsupp.total ι E 𝕜 v l, v i⟫ = 0 :=\n  by\n  rw [Finsupp.mem_supported'] at hl\n  simp only [hv.inner_left_finsupp, hl i hi, map_zero]\n#align orthonormal.inner_finsupp_eq_zero Orthonormal.inner_finsupp_eq_zero\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. -/\ntheorem Orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : ι → E} (hv : Orthonormal 𝕜 v)\n    (hw : ∀ i, w i = v i ∨ w i = -v i) : Orthonormal 𝕜 w := by\n  classical\n    rw [orthonormal_iff_ite] at *\n    intro 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, neg_neg, eq_self_iff_true,\n        neg_eq_zero] using hv i j\n#align orthonormal.orthonormal_of_forall_eq_or_eq_neg Orthonormal.orthonormal_of_forall_eq_or_eq_neg\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. -/\nvariable (𝕜 E)\n\ntheorem orthonormal_empty : Orthonormal 𝕜 (fun x => x : (∅ : Set E) → E) := by\n  classical simp [orthonormal_subtype_iff_ite]\n#align orthonormal_empty orthonormal_empty\n\nvariable {𝕜 E}\n\ntheorem orthonormal_unionᵢ_of_directed {η : Type _} {s : η → Set E} (hs : Directed (· ⊆ ·) s)\n    (h : ∀ i, Orthonormal 𝕜 (fun x => x : s i → E)) : Orthonormal 𝕜 (fun x => x : (⋃ i, s i) → E) :=\n  by\n  classical\n    rw [orthonormal_subtype_iff_ite]\n    rintro x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩\n    obtain ⟨k, hik, hjk⟩ := hs i j\n    have h_orth : Orthonormal 𝕜 (fun x => x : s k → E) := h k\n    rw [orthonormal_subtype_iff_ite] at h_orth\n    exact h_orth x (hik hxi) y (hjk hyj)\n#align orthonormal_Union_of_directed orthonormal_unionᵢ_of_directed\n\ntheorem orthonormal_unionₛ_of_directed {s : Set (Set E)} (hs : DirectedOn (· ⊆ ·) s)\n    (h : ∀ a ∈ s, Orthonormal 𝕜 (fun x => x : (a : Set E) → E)) :\n    Orthonormal 𝕜 (fun x => x : ⋃₀ s → E) := by\n  rw [Set.unionₛ_eq_unionᵢ] <;>\n    exact orthonormal_unionᵢ_of_directed hs.directed_coe (by simpa using h)\n#align orthonormal_sUnion_of_directed orthonormal_unionₛ_of_directed\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (w «expr ⊇ » s) -/\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (u «expr ⊇ » w) -/\n/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set\ncontaining it. -/\ntheorem exists_maximal_orthonormal {s : Set E} (hs : Orthonormal 𝕜 (coe : s → E)) :\n    ∃ (w : _)(_ : w ⊇ s),\n      Orthonormal 𝕜 (coe : w → E) ∧ ∀ (u) (_ : u ⊇ w), Orthonormal 𝕜 (coe : u → E) → u = w :=\n  by\n  obtain ⟨b, bi, sb, h⟩ := zorn_subset_nonempty { b | Orthonormal 𝕜 (coe : b → E) } _ _ hs\n  · refine' ⟨b, sb, bi, _⟩\n    exact fun u hus hu => h u hu hus\n  · refine' fun c hc cc c0 => ⟨⋃₀ c, _, _⟩\n    · exact orthonormal_unionₛ_of_directed cc.directed_on fun x xc => hc xc\n    · exact fun _ => Set.subset_unionₛ_of_mem\n#align exists_maximal_orthonormal exists_maximal_orthonormal\n\ntheorem Orthonormal.ne_zero {v : ι → E} (hv : Orthonormal 𝕜 v) (i : ι) : v i ≠ 0 :=\n  by\n  have : ‖v i‖ ≠ 0 := by\n    rw [hv.1 i]\n    norm_num\n  simpa using this\n#align orthonormal.ne_zero Orthonormal.ne_zero\n\nopen FiniteDimensional\n\n/-- A family of orthonormal vectors with the correct cardinality forms a basis. -/\ndef basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v)\n    (card_eq : Fintype.card ι = finrank 𝕜 E) : Basis ι 𝕜 E :=\n  basisOfLinearIndependentOfCardEqFinrank hv.LinearIndependent card_eq\n#align basis_of_orthonormal_of_card_eq_finrank basisOfOrthonormalOfCardEqFinrank\n\n@[simp]\ntheorem coe_basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E}\n    (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) :\n    (basisOfOrthonormalOfCardEqFinrank hv card_eq : ι → E) = v :=\n  coe_basisOfLinearIndependentOfCardEqFinrank _ _\n#align coe_basis_of_orthonormal_of_card_eq_finrank coe_basisOfOrthonormalOfCardEqFinrank\n\nend OrthonormalSets\n\nsection Norm\n\ntheorem norm_eq_sqrt_inner (x : E) : ‖x‖ = sqrt (re ⟪x, x⟫) :=\n  calc\n    ‖x‖ = sqrt (‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm\n    _ = sqrt (re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_inner _)\n    \n#align norm_eq_sqrt_inner norm_eq_sqrt_inner\n\ntheorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = sqrt ⟪x, x⟫_ℝ :=\n  by\n  have h := @norm_eq_sqrt_inner ℝ F _ _ _ x\n  simpa using h\n#align norm_eq_sqrt_real_inner norm_eq_sqrt_real_inner\n\ntheorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by\n  rw [@norm_eq_sqrt_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫),\n    sqrt_mul_self inner_self_nonneg]\n#align inner_self_eq_norm_mul_norm inner_self_eq_norm_mul_norm\n\ntheorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by\n  rw [pow_two, inner_self_eq_norm_mul_norm]\n#align inner_self_eq_norm_sq inner_self_eq_norm_sq\n\ntheorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ :=\n  by\n  have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x\n  simpa using h\n#align real_inner_self_eq_norm_mul_norm real_inner_self_eq_norm_mul_norm\n\ntheorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by\n  rw [pow_two, real_inner_self_eq_norm_mul_norm]\n#align real_inner_self_eq_norm_sq real_inner_self_eq_norm_sq\n\nvariable (𝕜)\n\n/-- Expand the square -/\ntheorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 :=\n  by\n  repeat' rw [sq, ← @inner_self_eq_norm_mul_norm 𝕜]\n  rw [inner_add_add_self, two_mul]\n  simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add]\n  rw [← inner_conj_symm, conj_re]\n#align norm_add_sq norm_add_sq\n\nalias norm_add_sq ← norm_add_pow_two\n#align norm_add_pow_two norm_add_pow_two\n\n/-- Expand the square -/\ntheorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 :=\n  by\n  have h := @norm_add_sq ℝ _ _ _ _ x y\n  simpa using h\n#align norm_add_sq_real norm_add_sq_real\n\nalias norm_add_sq_real ← norm_add_pow_two_real\n#align norm_add_pow_two_real norm_add_pow_two_real\n\n/-- Expand the square -/\ntheorem norm_add_mul_self (x y : E) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ :=\n  by\n  repeat' rw [← sq]\n  exact norm_add_sq _ _\n#align norm_add_mul_self norm_add_mul_self\n\n/-- Expand the square -/\ntheorem norm_add_mul_self_real (x y : F) :\n    ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ :=\n  by\n  have h := @norm_add_mul_self ℝ _ _ _ _ x y\n  simpa using h\n#align norm_add_mul_self_real norm_add_mul_self_real\n\n/-- Expand the square -/\ntheorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 :=\n  by\n  repeat' rw [sq, ← @inner_self_eq_norm_mul_norm 𝕜]\n  rw [inner_sub_sub_self]\n  calc\n    re (⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫) = re ⟪x, x⟫ - re ⟪x, y⟫ - re ⟪y, x⟫ + re ⟪y, y⟫ := by\n      simp only [map_add, map_sub]\n    _ = -re ⟪y, x⟫ - re ⟪x, y⟫ + re ⟪x, x⟫ + re ⟪y, y⟫ := by ring\n    _ = -re (⟪x, y⟫†) - re ⟪x, y⟫ + re ⟪x, x⟫ + re ⟪y, y⟫ := by rw [inner_conj_symm]\n    _ = -re ⟪x, y⟫ - re ⟪x, y⟫ + re ⟪x, x⟫ + re ⟪y, y⟫ := by rw [conj_re]\n    _ = re ⟪x, x⟫ - 2 * re ⟪x, y⟫ + re ⟪y, y⟫ := by ring\n    \n#align norm_sub_sq norm_sub_sq\n\nalias norm_sub_sq ← norm_sub_pow_two\n#align norm_sub_pow_two norm_sub_pow_two\n\n/-- Expand the square -/\ntheorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 :=\n  @norm_sub_sq ℝ _ _ _ _ _ _\n#align norm_sub_sq_real norm_sub_sq_real\n\nalias norm_sub_sq_real ← norm_sub_pow_two_real\n#align norm_sub_pow_two_real norm_sub_pow_two_real\n\n/-- Expand the square -/\ntheorem norm_sub_mul_self (x y : E) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ :=\n  by\n  repeat' rw [← sq]\n  exact norm_sub_sq _ _\n#align norm_sub_mul_self norm_sub_mul_self\n\n/-- Expand the square -/\ntheorem norm_sub_mul_self_real (x y : F) :\n    ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ :=\n  by\n  have h := @norm_sub_mul_self ℝ _ _ _ _ x y\n  simpa using h\n#align norm_sub_mul_self_real norm_sub_mul_self_real\n\n/-- Cauchy–Schwarz inequality with norm -/\ntheorem abs_inner_le_norm (x y : E) : abs ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=\n  nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _))\n    (by\n      have : ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) = re ⟪x, x⟫ * re ⟪y, y⟫\n      simp only [inner_self_eq_norm_mul_norm]; ring\n      rw [this]\n      conv_lhs =>\n        congr\n        skip\n        rw [inner_abs_conj_symm]\n      exact inner_mul_inner_self_le _ _)\n#align abs_inner_le_norm abs_inner_le_norm\n\ntheorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ :=\n  (IsROrC.norm_eq_abs _).le.trans (abs_inner_le_norm x y)\n#align norm_inner_le_norm norm_inner_le_norm\n\ntheorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ :=\n  norm_inner_le_norm x y\n#align nnnorm_inner_le_nnnorm nnnorm_inner_le_nnnorm\n\ntheorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=\n  le_trans (re_le_abs (inner x y)) (abs_inner_le_norm x y)\n#align re_inner_le_norm re_inner_le_norm\n\n/-- Cauchy–Schwarz inequality with norm -/\ntheorem abs_real_inner_le_norm (x y : F) : absR ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=\n  by\n  have h := @abs_inner_le_norm ℝ F _ _ _ x y\n  simpa using h\n#align abs_real_inner_le_norm abs_real_inner_le_norm\n\n/-- Cauchy–Schwarz inequality with norm -/\ntheorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=\n  le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)\n#align real_inner_le_norm real_inner_le_norm\n\ninclude 𝕜\n\nvariable (𝕜)\n\ntheorem parallelogram_law_with_norm (x y : E) :\n    ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) :=\n  by\n  simp only [← @inner_self_eq_norm_mul_norm 𝕜]\n  rw [← re.map_add, parallelogram_law, two_mul, two_mul]\n  simp only [re.map_add]\n#align parallelogram_law_with_norm parallelogram_law_with_norm\n\ntheorem parallelogram_law_with_nnnorm (x y : E) :\n    ‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) :=\n  Subtype.ext <| parallelogram_law_with_norm 𝕜 x y\n#align parallelogram_law_with_nnnorm parallelogram_law_with_nnnorm\n\nvariable {𝕜}\n\nomit 𝕜\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 (x y : E) :\n    re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=\n  by\n  rw [@norm_add_mul_self 𝕜]\n  ring\n#align re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two\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 (x y : E) :\n    re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=\n  by\n  rw [@norm_sub_mul_self 𝕜]\n  ring\n#align re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two\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 (x y : E) :\n    re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 :=\n  by\n  rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜]\n  ring\n#align re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four\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 (x y : E) :\n    im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 :=\n  by\n  simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re]\n  ring\n#align im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four\n\n/-- Polarization identity: The inner product, in terms of the norm. -/\ntheorem inner_eq_sum_norm_sq_div_four (x y : E) :\n    ⟪x, y⟫ = (‖x + y‖ ^ 2 - ‖x - y‖ ^ 2 + (‖x - IK • y‖ ^ 2 - ‖x + IK • y‖ ^ 2) * IK) / 4 :=\n  by\n  rw [← re_add_im ⟪x, y⟫, 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, ← mul_div_right_comm, ← add_div]\n#align inner_eq_sum_norm_sq_div_four inner_eq_sum_norm_sq_div_four\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. -/\ntheorem dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) :\n    dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y :=\n  have hx' : ‖x‖ ≠ 0 := norm_ne_zero_iff.2 hx\n  have hy' : ‖y‖ ≠ 0 := norm_ne_zero_iff.2 hy\n  calc\n    dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) =\n        sqrt (‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) :=\n      by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]\n    _ = sqrt ((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) :=\n      (congr_arg sqrt <|\n        by\n        field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right,\n          Real.norm_of_nonneg (mul_self_nonneg _)]\n        ring)\n    _ = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := by\n      rw [sqrt_mul (sq_nonneg _), sqrt_sq (norm_nonneg _),\n        sqrt_sq (div_nonneg (sq_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _))),\n        dist_eq_norm]\n    \n#align dist_div_norm_sq_smul dist_div_norm_sq_smul\n\n-- See note [lower instance priority]\ninstance (priority := 100) InnerProductSpace.to_uniformConvexSpace : UniformConvexSpace F :=\n  ⟨fun ε hε =>\n    by\n    refine'\n      ⟨2 - sqrt (4 - ε ^ 2), sub_pos_of_lt <| (sqrt_lt' zero_lt_two).2 _, fun x hx y hy hxy => _⟩\n    · norm_num\n      exact pow_pos hε _\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 ℝ x y), ← sq ‖x - y‖, hx, hy]\n    norm_num\n    exact pow_le_pow_of_le_left hε.le hxy _⟩\n#align inner_product_space.to_uniform_convex_space InnerProductSpace.to_uniformConvexSpace\n\nsection Complex\n\nvariable {V : Type _} [NormedAddCommGroup V] [InnerProductSpace ℂ V]\n\n/-- A complex polarization identity, with a linear map\n-/\ntheorem inner_map_polarization (T : V →ₗ[ℂ] V) (x y : V) :\n    ⟪T y, x⟫_ℂ =\n      (⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ +\n            Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ -\n          Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) /\n        4 :=\n  by\n  simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left,\n    inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right,\n    mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub]\n  ring\n#align inner_map_polarization inner_map_polarization\n\ntheorem inner_map_polarization' (T : V →ₗ[ℂ] V) (x y : V) :\n    ⟪T x, y⟫_ℂ =\n      (⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ -\n            Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ +\n          Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) /\n        4 :=\n  by\n  simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left,\n    inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right,\n    mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub]\n  ring\n#align inner_map_polarization' inner_map_polarization'\n\n/-- A linear map `T` is zero, if and only if the identity `⟪T x, x⟫_ℂ = 0` holds for all `x`.\n-/\ntheorem inner_map_self_eq_zero (T : V →ₗ[ℂ] V) : (∀ x : V, ⟪T x, x⟫_ℂ = 0) ↔ T = 0 :=\n  by\n  constructor\n  · intro hT\n    ext x\n    simp only [LinearMap.zero_apply, ← @inner_self_eq_zero ℂ, inner_map_polarization, hT]\n    norm_num\n  · rintro rfl x\n    simp only [LinearMap.zero_apply, inner_zero_left]\n#align inner_map_self_eq_zero inner_map_self_eq_zero\n\n/--\nTwo linear maps `S` and `T` are equal, if and only if the identity `⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ` holds\nfor all `x`.\n-/\ntheorem ext_inner_map (S T : V →ₗ[ℂ] V) : (∀ x : V, ⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ) ↔ S = T :=\n  by\n  rw [← sub_eq_zero, ← inner_map_self_eq_zero]\n  refine' forall_congr' fun x => _\n  rw [LinearMap.sub_apply, inner_sub_left, sub_eq_zero]\n#align ext_inner_map ext_inner_map\n\nend Complex\n\nsection\n\nvariable {ι : Type _} {ι' : Type _} {ι'' : Type _}\n\nvariable {E' : Type _} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E']\n\nvariable {E'' : Type _} [NormedAddCommGroup E''] [InnerProductSpace 𝕜 E'']\n\n/-- A linear isometry preserves the inner product. -/\n@[simp]\ntheorem LinearIsometry.inner_map_map (f : E →ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ := by\n  simp [inner_eq_sum_norm_sq_div_four, ← f.norm_map]\n#align linear_isometry.inner_map_map LinearIsometry.inner_map_map\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp]\ntheorem LinearIsometryEquiv.inner_map_map (f : E ≃ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ :=\n  f.toLinearIsometry.inner_map_map x y\n#align linear_isometry_equiv.inner_map_map LinearIsometryEquiv.inner_map_map\n\n/-- A linear map that preserves the inner product is a linear isometry. -/\ndef LinearMap.isometryOfInner (f : E →ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E →ₗᵢ[𝕜] E' :=\n  ⟨f, fun x => by simp only [@norm_eq_sqrt_inner 𝕜, h]⟩\n#align linear_map.isometry_of_inner LinearMap.isometryOfInner\n\n@[simp]\ntheorem LinearMap.coe_isometryOfInner (f : E →ₗ[𝕜] E') (h) : ⇑(f.isometryOfInner h) = f :=\n  rfl\n#align linear_map.coe_isometry_of_inner LinearMap.coe_isometryOfInner\n\n@[simp]\ntheorem LinearMap.isometryOfInner_toLinearMap (f : E →ₗ[𝕜] E') (h) :\n    (f.isometryOfInner h).toLinearMap = f :=\n  rfl\n#align linear_map.isometry_of_inner_to_linear_map LinearMap.isometryOfInner_toLinearMap\n\n/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/\ndef LinearEquiv.isometryOfInner (f : E ≃ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E ≃ₗᵢ[𝕜] E' :=\n  ⟨f, ((f : E →ₗ[𝕜] E').isometryOfInner h).norm_map⟩\n#align linear_equiv.isometry_of_inner LinearEquiv.isometryOfInner\n\n@[simp]\ntheorem LinearEquiv.coe_isometryOfInner (f : E ≃ₗ[𝕜] E') (h) : ⇑(f.isometryOfInner h) = f :=\n  rfl\n#align linear_equiv.coe_isometry_of_inner LinearEquiv.coe_isometryOfInner\n\n@[simp]\ntheorem LinearEquiv.isometryOfInner_toLinearEquiv (f : E ≃ₗ[𝕜] E') (h) :\n    (f.isometryOfInner h).toLinearEquiv = f :=\n  rfl\n#align linear_equiv.isometry_of_inner_to_linear_equiv LinearEquiv.isometryOfInner_toLinearEquiv\n\n/-- A linear isometry preserves the property of being orthonormal. -/\ntheorem LinearIsometry.orthonormal_comp_iff {v : ι → E} (f : E →ₗᵢ[𝕜] E') :\n    Orthonormal 𝕜 (f ∘ v) ↔ Orthonormal 𝕜 v := by\n  classical simp_rw [orthonormal_iff_ite, LinearIsometry.inner_map_map]\n#align linear_isometry.orthonormal_comp_iff LinearIsometry.orthonormal_comp_iff\n\n/-- A linear isometry preserves the property of being orthonormal. -/\ntheorem Orthonormal.comp_linearIsometry {v : ι → E} (hv : Orthonormal 𝕜 v) (f : E →ₗᵢ[𝕜] E') :\n    Orthonormal 𝕜 (f ∘ v) := by rwa [f.orthonormal_comp_iff]\n#align orthonormal.comp_linear_isometry Orthonormal.comp_linearIsometry\n\n/-- A linear isometric equivalence preserves the property of being orthonormal. -/\ntheorem Orthonormal.comp_linearIsometryEquiv {v : ι → E} (hv : Orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') :\n    Orthonormal 𝕜 (f ∘ v) :=\n  hv.comp_linearIsometry f.toLinearIsometry\n#align orthonormal.comp_linear_isometry_equiv Orthonormal.comp_linearIsometryEquiv\n\n/-- A linear isometric equivalence, applied with `basis.map`, preserves the property of being\northonormal. -/\ntheorem Orthonormal.map_linearIsometryEquiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v)\n    (f : E ≃ₗᵢ[𝕜] E') : Orthonormal 𝕜 (v.map f.toLinearEquiv) :=\n  hv.comp_linearIsometryEquiv f\n#align orthonormal.map_linear_isometry_equiv Orthonormal.map_linearIsometryEquiv\n\n/-- A linear map that sends an orthonormal basis to orthonormal vectors is a linear isometry. -/\ndef LinearMap.isometryOfOrthonormal (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v)\n    (hf : Orthonormal 𝕜 (f ∘ v)) : E →ₗᵢ[𝕜] E' :=\n  f.isometryOfInner fun x y => by\n    rw [← v.total_repr x, ← v.total_repr y, Finsupp.apply_total, Finsupp.apply_total,\n      hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left]\n#align linear_map.isometry_of_orthonormal LinearMap.isometryOfOrthonormal\n\n@[simp]\ntheorem LinearMap.coe_isometryOfOrthonormal (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E}\n    (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : ⇑(f.isometryOfOrthonormal hv hf) = f :=\n  rfl\n#align linear_map.coe_isometry_of_orthonormal LinearMap.coe_isometryOfOrthonormal\n\n@[simp]\ntheorem LinearMap.isometryOfOrthonormal_toLinearMap (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E}\n    (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) :\n    (f.isometryOfOrthonormal hv hf).toLinearMap = f :=\n  rfl\n#align linear_map.isometry_of_orthonormal_to_linear_map LinearMap.isometryOfOrthonormal_toLinearMap\n\n/-- A linear equivalence that sends an orthonormal basis to orthonormal vectors is a linear\nisometric equivalence. -/\ndef LinearEquiv.isometryOfOrthonormal (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v)\n    (hf : Orthonormal 𝕜 (f ∘ v)) : E ≃ₗᵢ[𝕜] E' :=\n  f.isometryOfInner fun x y => by\n    rw [← LinearEquiv.coe_coe] at hf\n    rw [← v.total_repr x, ← v.total_repr y, ← LinearEquiv.coe_coe, Finsupp.apply_total,\n      Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left]\n#align linear_equiv.isometry_of_orthonormal LinearEquiv.isometryOfOrthonormal\n\n@[simp]\ntheorem LinearEquiv.coe_isometryOfOrthonormal (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E}\n    (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : ⇑(f.isometryOfOrthonormal hv hf) = f :=\n  rfl\n#align linear_equiv.coe_isometry_of_orthonormal LinearEquiv.coe_isometryOfOrthonormal\n\n@[simp]\ntheorem LinearEquiv.isometryOfOrthonormal_toLinearEquiv (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E}\n    (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) :\n    (f.isometryOfOrthonormal hv hf).toLinearEquiv = f :=\n  rfl\n#align linear_equiv.isometry_of_orthonormal_to_linear_equiv LinearEquiv.isometryOfOrthonormal_toLinearEquiv\n\n/-- A linear isometric equivalence that sends an orthonormal basis to a given orthonormal basis. -/\ndef Orthonormal.equiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'}\n    (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : E ≃ₗᵢ[𝕜] E' :=\n  (v.Equiv v' e).isometryOfOrthonormal hv\n    (by\n      have h : v.equiv v' e ∘ v = v' ∘ e := by\n        ext i\n        simp\n      rw [h]\n      exact hv'.comp _ e.injective)\n#align orthonormal.equiv Orthonormal.equiv\n\n@[simp]\ntheorem Orthonormal.equiv_toLinearEquiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v)\n    {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') :\n    (hv.Equiv hv' e).toLinearEquiv = v.Equiv v' e :=\n  rfl\n#align orthonormal.equiv_to_linear_equiv Orthonormal.equiv_toLinearEquiv\n\n@[simp]\ntheorem Orthonormal.equiv_apply {ι' : Type _} {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v)\n    {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') (i : ι) :\n    hv.Equiv hv' e (v i) = v' (e i) :=\n  Basis.equiv_apply _ _ _ _\n#align orthonormal.equiv_apply Orthonormal.equiv_apply\n\n@[simp]\ntheorem Orthonormal.equiv_refl {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) :\n    hv.Equiv hv (Equiv.refl ι) = LinearIsometryEquiv.refl 𝕜 E :=\n  v.ext_linearIsometryEquiv fun i => by\n    simp only [Orthonormal.equiv_apply, Equiv.coe_refl, id.def, LinearIsometryEquiv.coe_refl]\n#align orthonormal.equiv_refl Orthonormal.equiv_refl\n\n@[simp]\ntheorem Orthonormal.equiv_symm {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'}\n    (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.Equiv hv' e).symm = hv'.Equiv hv e.symm :=\n  v'.ext_linearIsometryEquiv fun i =>\n    (hv.Equiv hv' e).Injective <| by\n      simp only [LinearIsometryEquiv.apply_symm_apply, Orthonormal.equiv_apply, e.apply_symm_apply]\n#align orthonormal.equiv_symm Orthonormal.equiv_symm\n\n@[simp]\ntheorem Orthonormal.equiv_trans {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'}\n    (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') {v'' : Basis ι'' 𝕜 E''} (hv'' : Orthonormal 𝕜 v'')\n    (e' : ι' ≃ ι'') : (hv.Equiv hv' e).trans (hv'.Equiv hv'' e') = hv.Equiv hv'' (e.trans e') :=\n  v.ext_linearIsometryEquiv fun i => by\n    simp only [LinearIsometryEquiv.trans_apply, Orthonormal.equiv_apply, e.coe_trans]\n#align orthonormal.equiv_trans Orthonormal.equiv_trans\n\ntheorem Orthonormal.map_equiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'}\n    (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') :\n    v.map (hv.Equiv hv' e).toLinearEquiv = v'.reindex e.symm :=\n  v.mapEquiv _ _\n#align orthonormal.map_equiv Orthonormal.map_equiv\n\nend\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 (x y : F) :\n    ⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=\n  re_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#align real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two\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 (x y : F) :\n    ⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=\n  re_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#align real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two\n\n/-- Pythagorean theorem, if-and-only-if vector inner product form. -/\ntheorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n    ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 :=\n  by\n  rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_right_eq_self, mul_eq_zero]\n  norm_num\n#align norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero\n\n/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/\ntheorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :\n    ‖x + y‖ = sqrt (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by\n  rw [← norm_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#align norm_add_eq_sqrt_iff_real_inner_eq_zero norm_add_eq_sqrt_iff_real_inner_eq_zero\n\n/-- Pythagorean theorem, vector inner product form. -/\ntheorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) :\n    ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=\n  by\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']\n#align norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero\n\n/-- Pythagorean theorem, vector inner product form. -/\ntheorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :\n    ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=\n  (norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n#align norm_add_sq_eq_norm_sq_add_norm_sq_real norm_add_sq_eq_norm_sq_add_norm_sq_real\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector\ninner product form. -/\ntheorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :\n    ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 :=\n  by\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\n#align norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero\n\n/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square\nroots. -/\ntheorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :\n    ‖x - y‖ = sqrt (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by\n  rw [← norm_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#align norm_sub_eq_sqrt_iff_real_inner_eq_zero norm_sub_eq_sqrt_iff_real_inner_eq_zero\n\n/-- Pythagorean theorem, subtracting vectors, vector inner product\nform. -/\ntheorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :\n    ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=\n  (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h\n#align norm_sub_sq_eq_norm_sq_add_norm_sq_real norm_sub_sq_eq_norm_sq_add_norm_sq_real\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 (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ :=\n  by\n  conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]\n  simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x,\n    sub_eq_zero, re_to_real]\n  constructor\n  · intro h\n    rw [add_comm] at h\n    linarith\n  · intro h\n    linarith\n#align real_inner_add_sub_eq_zero_iff real_inner_add_sub_eq_zero_iff\n\n/-- Given two orthogonal vectors, their sum and difference have equal norms. -/\ntheorem norm_sub_eq_norm_add {v w : E} (h : ⟪v, w⟫ = 0) : ‖w - v‖ = ‖w + v‖ :=\n  by\n  rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]\n  simp only [h, ← @inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re',\n    zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm,\n    zero_add]\n#align norm_sub_eq_norm_add norm_sub_eq_norm_add\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 (x y : F) : absR (⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)) ≤ 1 :=\n  by\n  rw [_root_.abs_div]\n  by_cases h : 0 = absR (‖x‖ * ‖y‖)\n  · rw [← h, div_zero]\n    norm_num\n  · change 0 ≠ absR (‖x‖ * ‖y‖) at h\n    rw [div_le_iff' (lt_of_le_of_ne (ge_iff_le.mp (_root_.abs_nonneg (‖x‖ * ‖y‖))) 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]\n#align abs_real_inner_div_norm_mul_norm_le_one abs_real_inner_div_norm_mul_norm_le_one\n\n/-- The inner product of a vector with a multiple of itself. -/\ntheorem real_inner_smul_self_left (x : F) (r : ℝ) : ⟪r • x, x⟫_ℝ = r * (‖x‖ * ‖x‖) := by\n  rw [real_inner_smul_left, ← real_inner_self_eq_norm_mul_norm]\n#align real_inner_smul_self_left real_inner_smul_self_left\n\n/-- The inner product of a vector with a multiple of itself. -/\ntheorem real_inner_smul_self_right (x : F) (r : ℝ) : ⟪x, r • x⟫_ℝ = r * (‖x‖ * ‖x‖) := by\n  rw [inner_smul_right, ← real_inner_self_eq_norm_mul_norm]\n#align real_inner_smul_self_right real_inner_smul_self_right\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 {x : E} {r : 𝕜} (hx : x ≠ 0)\n    (hr : r ≠ 0) : abs ⟪x, r • x⟫ / (‖x‖ * ‖r • x‖) = 1 :=\n  by\n  have hx' : ‖x‖ ≠ 0 := by simp [norm_eq_zero, hx]\n  have hr' : abs r ≠ 0 := by simp [IsROrC.abs_eq_zero, hr]\n  rw [inner_smul_right, IsROrC.abs_mul, ← inner_self_re_abs, inner_self_eq_norm_mul_norm, norm_smul]\n  rw [IsROrC.norm_eq_abs, ← mul_assoc, ← div_div, mul_div_cancel _ hx', ← div_div, mul_comm,\n    mul_div_cancel _ hr', div_self hx']\n#align abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\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 {x : F} {r : ℝ}\n    (hx : x ≠ 0) (hr : r ≠ 0) : absR ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = 1 :=\n  by\n  rw [← abs_to_real]\n  exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr\n#align abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul\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 {x : F} {r : ℝ} (hx : x ≠ 0)\n    (hr : 0 < r) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = 1 :=\n  by\n  rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, 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) fun h => hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h))\n#align real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul\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 {x : F} {r : ℝ} (hx : x ≠ 0)\n    (hr : r < 0) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = -1 :=\n  by\n  rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, 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) fun h => hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h))\n#align real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul\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 (x y : E) :\n    abs (⟪x, y⟫ / (‖x‖ * ‖y‖)) = 1 ↔ x ≠ 0 ∧ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :=\n  by\n  constructor\n  · intro h\n    have hx0 : x ≠ 0 := by\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 := ⟪x, y⟫ / (‖x‖ * ‖x‖) with hr\n    use r\n    set t := y - r • x with ht\n    have ht0 : ⟪x, t⟫ = 0 :=\n      by\n      rw [ht, inner_sub_right, inner_smul_right, hr]\n      norm_cast\n      rw [← @inner_self_eq_norm_mul_norm 𝕜, inner_self_re_to_K,\n        div_mul_cancel _ fun h => hx0 ((@inner_self_eq_zero 𝕜 _ _ _ _ _).1 h), sub_self]\n    replace h : ‖r • x‖ / ‖t + r • x‖ = 1\n    · rw [← sub_add_cancel y (r • x), ← ht, inner_add_right, ht0, zero_add, inner_smul_right,\n        IsROrC.abs_div, IsROrC.abs_mul, ← inner_self_re_abs, 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, ← mul_assoc, mul_comm,\n        mul_div_mul_left _ _ fun h => hx0 (norm_eq_zero.1 h), ← IsROrC.norm_eq_abs, ← norm_smul] at\n        h\n    have hr0 : r ≠ 0 := by\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 : ‖r • x‖ ^ 2 = ‖t + r • x‖ ^ 2 := by rw [eq_of_div_eq_one h]\n    replace h2 : ⟪r • x, r • x⟫ = ⟪t, t⟫ + ⟪t, r • x⟫ + ⟪r • x, t⟫ + ⟪r • x, r • x⟫\n    · rw [sq, sq, ← @inner_self_eq_norm_mul_norm 𝕜, ← @inner_self_eq_norm_mul_norm 𝕜] at h2\n      have h2' := congr_arg (fun z : ℝ => (z : 𝕜)) h2\n      simp_rw [inner_self_re_to_K, inner_add_add_self] at h2'\n      exact h2'\n    conv at h2 in ⟪r • x, t⟫ => rw [inner_smul_left, ht0, MulZeroClass.mul_zero]\n    symm at h2\n    have h₁ : ⟪t, r • x⟫ = 0 :=\n      by\n      rw [inner_smul_right, ← inner_conj_symm, ht0]\n      simp\n    rw [add_zero, h₁, 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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩\n    rw [hy, IsROrC.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\n#align abs_inner_div_norm_mul_norm_eq_one_iff abs_inner_div_norm_mul_norm_eq_one_iff\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 (x y : F) :\n    absR (⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)) = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r ≠ 0 ∧ y = r • x :=\n  by\n  have := @abs_inner_div_norm_mul_norm_eq_one_iff ℝ F _ _ _ x y\n  simpa [coe_real_eq_id] using this\n#align abs_real_inner_div_norm_mul_norm_eq_one_iff abs_real_inner_div_norm_mul_norm_eq_one_iff\n\n/-- If 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 `⟪x, y⟫ = ‖x‖ * ‖y‖`. -/\ntheorem abs_inner_eq_norm_iff (x y : E) (hx0 : x ≠ 0) (hy0 : y ≠ 0) :\n    abs ⟪x, y⟫ = ‖x‖ * ‖y‖ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :=\n  by\n  have hxy0 : ‖x‖ * ‖y‖ ≠ 0 := mul_ne_zero (norm_eq_zero.not.2 hx0) (norm_eq_zero.not.2 hy0)\n  have h₁ : abs ⟪x, y⟫ = ‖x‖ * ‖y‖ ↔ abs (⟪x, y⟫ / (‖x‖ * ‖y‖)) = 1 :=\n    by\n    rw [← algebraMap.coe_mul, IsROrC.abs_div, IsROrC.abs_of_nonneg, div_eq_one_iff_eq hxy0]\n    positivity\n  rw [h₁, abs_inner_div_norm_mul_norm_eq_one_iff x y]\n  exact and_iff_right hx0\n#align abs_inner_eq_norm_iff abs_inner_eq_norm_iff\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 (x y : F) :\n    ⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x :=\n  by\n  constructor\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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩\n    use hx, r\n    refine' And.intro _ hy\n    by_contra 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\n      h\n    norm_num at h\n  · intro h\n    rcases h with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩\n    rw [hy]\n    exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr\n#align real_inner_div_norm_mul_norm_eq_one_iff real_inner_div_norm_mul_norm_eq_one_iff\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 (x y : F) :\n    ⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = -1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x :=\n  by\n  constructor\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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩\n    use hx, r\n    refine' And.intro _ hy\n    by_contra 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\n      h\n    norm_num at h\n  · intro h\n    rcases h with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩\n    rw [hy]\n    exact real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx hr\n#align real_inner_div_norm_mul_norm_eq_neg_one_iff real_inner_div_norm_mul_norm_eq_neg_one_iff\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`⟪x, y⟫ = ‖x‖ * ‖y‖`), 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 ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/\ntheorem inner_eq_norm_mul_iff {x y : E} :\n    ⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ : 𝕜) • x = (‖x‖ : 𝕜) • y :=\n  by\n  by_cases h : x = 0 ∨ y = 0\n  -- WLOG `x` and `y` are nonzero\n  · cases h <;> simp [h]\n  calc\n    ⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ ‖x‖ * ‖y‖ = re ⟪x, y⟫ :=\n      by\n      norm_cast\n      constructor\n      · intro h'\n        simp [h']\n      · have cauchy_schwarz := abs_inner_le_norm x y\n        intro h'\n        rw [h'] at cauchy_schwarz⊢\n        rwa [re_eq_self_of_le]\n    _ ↔ 2 * ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖ - re ⟪x, y⟫) = 0 := by\n      simp [h, show (2 : ℝ) ≠ 0 by norm_num, sub_eq_zero]\n    _ ↔ ‖(‖y‖ : 𝕜) • x - (‖x‖ : 𝕜) • y‖ * ‖(‖y‖ : 𝕜) • x - (‖x‖ : 𝕜) • y‖ = 0 :=\n      by\n      simp only [@norm_sub_mul_self 𝕜, inner_smul_left, inner_smul_right, norm_smul, conj_of_real,\n        IsROrC.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    _ ↔ (‖y‖ : 𝕜) • x = (‖x‖ : 𝕜) • y := by simp [norm_sub_eq_zero_iff]\n    \n#align inner_eq_norm_mul_iff inner_eq_norm_mul_iff\n\n/-- If the inner product of two vectors is equal to the product of their norms (i.e.,\n`⟪x, y⟫ = ‖x‖ * ‖y‖`), 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 ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/\ntheorem inner_eq_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ = ‖x‖ * ‖y‖ ↔ ‖y‖ • x = ‖x‖ • y :=\n  inner_eq_norm_mul_iff\n#align inner_eq_norm_mul_iff_real inner_eq_norm_mul_iff_real\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 {x y : E} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :\n    ⟪x, y⟫ = 1 ↔ x = y := by convert inner_eq_norm_mul_iff using 2 <;> simp [hx, hy]\n#align inner_eq_norm_mul_iff_of_norm_one inner_eq_norm_mul_iff_of_norm_one\n\ntheorem inner_lt_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ‖y‖ • x ≠ ‖x‖ • y :=\n  calc\n    ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ ≠ ‖x‖ * ‖y‖ :=\n      ⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩\n    _ ↔ ‖y‖ • x ≠ ‖x‖ • y := not_congr inner_eq_norm_mul_iff_real\n    \n#align inner_lt_norm_mul_iff_real inner_lt_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 {x y : F} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :\n    ⟪x, y⟫_ℝ < 1 ↔ x ≠ y := by convert inner_lt_norm_mul_iff_real <;> simp [hx, hy]\n#align inner_lt_one_iff_real_of_norm_one inner_lt_one_iff_real_of_norm_one\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 {ι₁ : Type _} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ}\n    (v₁ : ι₁ → F) (h₁ : (∑ i in s₁, w₁ i) = 0) {ι₂ : Type _} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ}\n    (v₂ : ι₂ → F) (h₂ : (∑ i in s₂, w₂ i) = 0) :\n    ⟪∑ i₁ in s₁, w₁ i₁ • v₁ i₁, ∑ i₂ in s₂, w₂ i₂ • v₂ i₂⟫_ℝ =\n      (-∑ i₁ in s₁, ∑ i₂ in s₂, w₁ i₁ * w₂ i₂ * (‖v₁ i₁ - v₂ i₂‖ * ‖v₁ i₁ - v₂ i₂‖)) / 2 :=\n  by\n  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, ← div_sub_div_same,\n    ← div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib,\n    Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul, h₁, h₂, MulZeroClass.zero_mul,\n    MulZeroClass.mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div,\n    Finset.sum_div, mul_div_assoc, mul_assoc]\n#align inner_sum_smul_sum_smul_of_sum_eq_zero inner_sum_smul_sum_smul_of_sum_eq_zero\n\nvariable (𝕜)\n\n/-- The inner product as a sesquilinear map. -/\ndef innerₛₗ : E →ₗ⋆[𝕜] E →ₗ[𝕜] 𝕜 :=\n  LinearMap.mk₂'ₛₗ _ _ (fun v w => ⟪v, w⟫) inner_add_left (fun _ _ _ => inner_smul_left _ _ _)\n    inner_add_right fun _ _ _ => inner_smul_right _ _ _\n#align innerₛₗ innerₛₗ\n\n@[simp]\ntheorem innerₛₗ_apply_coe (v : E) : ⇑(innerₛₗ 𝕜 v) = fun w => ⟪v, w⟫ :=\n  rfl\n#align innerₛₗ_apply_coe innerₛₗ_apply_coe\n\n@[simp]\ntheorem innerₛₗ_apply (v w : E) : innerₛₗ 𝕜 v w = ⟪v, w⟫ :=\n  rfl\n#align innerₛₗ_apply innerₛₗ_apply\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 →L⋆[𝕜] E →L[𝕜] 𝕜 :=\n  LinearMap.mkContinuous₂ (innerₛₗ 𝕜) 1 fun x y => by\n    simp only [norm_inner_le_norm, one_mul, innerₛₗ_apply]\n#align innerSL innerSL\n\n@[simp]\ntheorem innerSL_apply_coe (v : E) : ⇑(innerSL 𝕜 v) = fun w => ⟪v, w⟫ :=\n  rfl\n#align innerSL_apply_coe innerSL_apply_coe\n\n@[simp]\ntheorem innerSL_apply (v w : E) : innerSL 𝕜 v w = ⟪v, w⟫ :=\n  rfl\n#align innerSL_apply innerSL_apply\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]\ntheorem innerSL_apply_norm (x : E) : ‖innerSL 𝕜 x‖ = ‖x‖ :=\n  by\n  refine'\n    le_antisymm ((innerSL 𝕜 x).opNorm_le_bound (norm_nonneg _) fun 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\n      ‖x‖ * ‖x‖ = ‖x‖ ^ 2 := by ring\n      _ = re ⟪x, x⟫ := (norm_sq_eq_inner _)\n      _ ≤ abs ⟪x, x⟫ := (re_le_abs _)\n      _ = ‖⟪x, x⟫‖ := by rw [← IsROrC.norm_eq_abs]\n      _ ≤ ‖innerSL 𝕜 x‖ * ‖x‖ := (innerSL 𝕜 x).le_opNorm _\n      \n#align innerSL_apply_norm innerSL_apply_norm\n\n/-- The inner product as a continuous sesquilinear map, with the two arguments flipped. -/\ndef innerSLFlip : E →L[𝕜] E →L⋆[𝕜] 𝕜 :=\n  @ContinuousLinearMap.flipₗᵢ' 𝕜 𝕜 𝕜 E E 𝕜 _ _ _ _ _ _ _ _ _ (RingHom.id 𝕜) (starRingEnd 𝕜) _ _\n    (innerSL 𝕜)\n#align innerSL_flip innerSLFlip\n\n@[simp]\ntheorem innerSLFlip_apply (x y : E) : innerSLFlip 𝕜 x y = ⟪y, x⟫ :=\n  rfl\n#align innerSL_flip_apply innerSLFlip_apply\n\nvariable {𝕜}\n\nnamespace ContinuousLinearMap\n\nvariable {E' : Type _} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E']\n\n/-- Given `f : E →L[𝕜] E'`, construct the continuous sesquilinear form `λ x y, ⟪x, A y⟫`, given\nas a continuous linear map. -/\ndef toSesqForm : (E →L[𝕜] E') →L[𝕜] E' →L⋆[𝕜] E →L[𝕜] 𝕜 :=\n  ↑(ContinuousLinearMap.flipₗᵢ' E E' 𝕜 (starRingEnd 𝕜) (RingHom.id 𝕜)).toContinuousLinearEquiv ∘L\n    ContinuousLinearMap.compSL E E' (E' →L⋆[𝕜] 𝕜) (RingHom.id 𝕜) (RingHom.id 𝕜) (innerSLFlip 𝕜)\n#align continuous_linear_map.to_sesq_form ContinuousLinearMap.toSesqForm\n\n@[simp]\ntheorem toSesqForm_apply_coe (f : E →L[𝕜] E') (x : E') : toSesqForm f x = (innerSL 𝕜 x).comp f :=\n  rfl\n#align continuous_linear_map.to_sesq_form_apply_coe ContinuousLinearMap.toSesqForm_apply_coe\n\ntheorem toSesqForm_apply_norm_le {f : E →L[𝕜] E'} {v : E'} : ‖toSesqForm f v‖ ≤ ‖f‖ * ‖v‖ :=\n  by\n  refine' op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _\n  intro x\n  have h₁ : ‖f x‖ ≤ ‖f‖ * ‖x‖ := le_op_norm _ _\n  have h₂ := @norm_inner_le_norm 𝕜 E' _ _ _ v (f x)\n  calc\n    ‖⟪v, f x⟫‖ ≤ ‖v‖ * ‖f x‖ := h₂\n    _ ≤ ‖v‖ * (‖f‖ * ‖x‖) := (mul_le_mul_of_nonneg_left h₁ (norm_nonneg v))\n    _ = ‖f‖ * ‖v‖ * ‖x‖ := by ring\n    \n#align continuous_linear_map.to_sesq_form_apply_norm_le ContinuousLinearMap.toSesqForm_apply_norm_le\n\nend ContinuousLinearMap\n\n/-- When an inner product space `E` over `𝕜` 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 ℝ E` instance. We will later establish\nsuch an instance by restriction-of-scalars, `inner_product_space.is_R_or_C_to_real 𝕜 E`, but this\ninstance may be not definitionally equal to some other “natural” instance. So, we assume\n`[normed_space ℝ E]`.\n-/\ntheorem isBoundedBilinearMapInner [NormedSpace ℝ E] :\n    IsBoundedBilinearMap ℝ fun p : E × E => ⟪p.1, p.2⟫ :=\n  { add_left := inner_add_left\n    smul_left := fun r x y => by\n      simp only [← algebraMap_smul 𝕜 r x, algebra_map_eq_of_real, inner_smul_real_left]\n    add_right := inner_add_right\n    smul_right := fun r x y => by\n      simp only [← algebraMap_smul 𝕜 r y, algebra_map_eq_of_real, inner_smul_real_right]\n    bound :=\n      ⟨1, zero_lt_one, fun x y => by\n        rw [one_mul]\n        exact norm_inner_le_norm x y⟩ }\n#align is_bounded_bilinear_map_inner isBoundedBilinearMapInner\n\nend Norm\n\nsection BesselsInequality\n\nvariable {ι : Type _} (x : E) {v : ι → E}\n\n/-- Bessel's inequality for finite sums. -/\ntheorem Orthonormal.sum_inner_products_le {s : Finset ι} (hv : Orthonormal 𝕜 v) :\n    (∑ i in s, ‖⟪v i, x⟫‖ ^ 2) ≤ ‖x‖ ^ 2 :=\n  by\n  have h₂ :\n    (∑ i in s, ∑ j in s, ⟪v i, x⟫ * ⟪x, v j⟫ * ⟪v j, v i⟫) = (∑ k in s, ⟪v k, x⟫ * ⟪x, v k⟫ : 𝕜) :=\n    hv.inner_left_right_finset\n  have h₃ : ∀ z : 𝕜, re (z * conj z) = ‖z‖ ^ 2 :=\n    by\n    intro z\n    simp only [mul_conj, norm_sq_eq_def']\n    norm_cast\n  suffices hbf : ‖x - ∑ i in s, ⟪v i, x⟫ • v i‖ ^ 2 = ‖x‖ ^ 2 - ∑ i in s, ‖⟪v i, x⟫‖ ^ 2\n  · rw [← sub_nonneg, ← hbf]\n    simp only [norm_nonneg, pow_nonneg]\n  rw [@norm_sub_sq 𝕜, sub_add]\n  simp only [@InnerProductSpace.norm_sq_eq_inner 𝕜, inner_sum]\n  simp only [sum_inner, two_mul, inner_smul_right, inner_conj_symm, ← mul_assoc, h₂, ← h₃,\n    inner_conj_symm, AddMonoidHom.map_sum, Finset.mul_sum, ← Finset.sum_sub_distrib,\n    inner_smul_left, add_sub_cancel']\n#align orthonormal.sum_inner_products_le Orthonormal.sum_inner_products_le\n\n/-- Bessel's inequality. -/\ntheorem Orthonormal.tsum_inner_products_le (hv : Orthonormal 𝕜 v) :\n    (∑' i, ‖⟪v i, x⟫‖ ^ 2) ≤ ‖x‖ ^ 2 :=\n  by\n  refine' tsum_le_of_sum_le' _ fun s => hv.sum_inner_products_le x\n  simp only [norm_nonneg, pow_nonneg]\n#align orthonormal.tsum_inner_products_le Orthonormal.tsum_inner_products_le\n\n/-- The sum defined in Bessel's inequality is summable. -/\ntheorem Orthonormal.inner_products_summable (hv : Orthonormal 𝕜 v) :\n    Summable fun i => ‖⟪v i, x⟫‖ ^ 2 :=\n  by\n  use ⨆ s : Finset ι, ∑ i in s, ‖⟪v i, x⟫‖ ^ 2\n  apply hasSum_of_isLUB_of_nonneg\n  · intro b\n    simp only [norm_nonneg, pow_nonneg]\n  · refine' isLUB_csupᵢ _\n    use ‖x‖ ^ 2\n    rintro y ⟨s, rfl⟩\n    exact hv.sum_inner_products_le x\n#align orthonormal.inner_products_summable Orthonormal.inner_products_summable\n\nend BesselsInequality\n\n/-- A field `𝕜` satisfying `is_R_or_C` is itself a `𝕜`-inner product space. -/\ninstance IsROrC.innerProductSpace : InnerProductSpace 𝕜 𝕜\n    where\n  inner x y := conj x * y\n  norm_sq_eq_inner x := by\n    unfold inner\n    rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def']\n  conj_symm x y := by simp only [mul_comm, map_mul, starRingEnd_self_apply]\n  add_left x y z := by simp only [add_mul, map_add]\n  smul_left x y z := by simp only [mul_assoc, smul_eq_mul, map_mul]\n#align is_R_or_C.inner_product_space IsROrC.innerProductSpace\n\n@[simp]\ntheorem IsROrC.inner_apply (x y : 𝕜) : ⟪x, y⟫ = conj x * y :=\n  rfl\n#align is_R_or_C.inner_apply IsROrC.inner_apply\n\n/-! ### Inner product space structure on subspaces -/\n\n\n/-- Induced inner product on a submodule. -/\ninstance Submodule.innerProductSpace (W : Submodule 𝕜 E) : InnerProductSpace 𝕜 W :=\n  { Submodule.normedSpace W with\n    inner := fun x y => ⟪(x : E), (y : E)⟫\n    conj_symm := fun _ _ => inner_conj_symm _ _\n    norm_sq_eq_inner := fun x => norm_sq_eq_inner (x : E)\n    add_left := fun _ _ _ => inner_add_left _ _ _\n    smul_left := fun _ _ _ => inner_smul_left _ _ _ }\n#align submodule.inner_product_space Submodule.innerProductSpace\n\n/-- The inner product on submodules is the same as on the ambient space. -/\n@[simp]\ntheorem Submodule.coe_inner (W : Submodule 𝕜 E) (x y : W) : ⟪x, y⟫ = ⟪(x : E), ↑y⟫ :=\n  rfl\n#align submodule.coe_inner Submodule.coe_inner\n\ntheorem Orthonormal.codRestrict {ι : Type _} {v : ι → E} (hv : Orthonormal 𝕜 v) (s : Submodule 𝕜 E)\n    (hvs : ∀ i, v i ∈ s) : @Orthonormal 𝕜 s _ _ _ ι (Set.codRestrict v s hvs) :=\n  s.subtypeₗᵢ.orthonormal_comp_iff.mp hv\n#align orthonormal.cod_restrict Orthonormal.codRestrict\n\ntheorem orthonormal_span {ι : Type _} {v : ι → E} (hv : Orthonormal 𝕜 v) :\n    @Orthonormal 𝕜 (Submodule.span 𝕜 (Set.range v)) _ _ _ ι fun i : ι =>\n      ⟨v i, Submodule.subset_span (Set.mem_range_self i)⟩ :=\n  hv.codRestrict (Submodule.span 𝕜 (Set.range v)) fun i =>\n    Submodule.subset_span (Set.mem_range_self i)\n#align orthonormal_span orthonormal_span\n\n/-! ### Families of mutually-orthogonal subspaces of an inner product space -/\n\n\nsection OrthogonalFamily\n\nvariable {ι : Type _} [dec_ι : DecidableEq ι] (𝕜)\n\nopen DirectSum\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 : ι → submodule 𝕜 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 : ι → E`,\nwe have an associated orthogonal family of one-dimensional subspaces of `E`, which it is convenient\nto be able to discuss using `ι → 𝕜` rather than `Π i : ι, span 𝕜 (v i)`. -/\ndef OrthogonalFamily (G : ι → Type _) [∀ i, NormedAddCommGroup (G i)]\n    [∀ i, InnerProductSpace 𝕜 (G i)] (V : ∀ i, G i →ₗᵢ[𝕜] E) : Prop :=\n  ∀ ⦃i j⦄, i ≠ j → ∀ v : G i, ∀ w : G j, ⟪V i v, V j w⟫ = 0\n#align orthogonal_family OrthogonalFamily\n\nvariable {𝕜} {G : ι → Type _} [∀ i, NormedAddCommGroup (G i)] [∀ i, InnerProductSpace 𝕜 (G i)]\n  {V : ∀ i, G i →ₗᵢ[𝕜] E} (hV : OrthogonalFamily 𝕜 G V) [dec_V : ∀ (i) (x : G i), Decidable (x ≠ 0)]\n\ntheorem Orthonormal.orthogonalFamily {v : ι → E} (hv : Orthonormal 𝕜 v) :\n    OrthogonalFamily 𝕜 (fun i : ι => 𝕜) fun i => LinearIsometry.toSpanSingleton 𝕜 E (hv.1 i) :=\n  fun i j hij a b => by simp [inner_smul_left, inner_smul_right, hv.2 hij]\n#align orthonormal.orthogonal_family Orthonormal.orthogonalFamily\n\ninclude hV dec_ι\n\ntheorem OrthogonalFamily.eq_ite {i j : ι} (v : G i) (w : G j) :\n    ⟪V i v, V j w⟫ = ite (i = j) ⟪V i v, V j w⟫ 0 :=\n  by\n  split_ifs\n  · rfl\n  · exact hV h v w\n#align orthogonal_family.eq_ite OrthogonalFamily.eq_ite\n\ninclude dec_V\n\ntheorem OrthogonalFamily.inner_right_dfinsupp (l : ⨁ i, G i) (i : ι) (v : G i) :\n    ⟪V i v, l.Sum fun j => V j⟫ = ⟪v, l i⟫ :=\n  calc\n    ⟪V i v, l.Sum fun j => V j⟫ = l.Sum fun j => fun w => ⟪V i v, V j w⟫ :=\n      Dfinsupp.inner_sum (fun j => V j) l (V i v)\n    _ = l.Sum fun j => fun w => ite (i = j) ⟪V i v, V j w⟫ 0 :=\n      (congr_arg l.Sum <| funext fun j => funext <| hV.eq_ite v)\n    _ = ⟪v, l i⟫ :=\n      by\n      simp only [Dfinsupp.sum, Submodule.coe_inner, Finset.sum_ite_eq, ite_eq_left_iff,\n        Dfinsupp.mem_support_toFun]\n      split_ifs with h h\n      · simp only [LinearIsometry.inner_map_map]\n      · simp only [of_not_not h, inner_zero_right]\n    \n#align orthogonal_family.inner_right_dfinsupp OrthogonalFamily.inner_right_dfinsupp\n\nomit dec_ι dec_V\n\ntheorem OrthogonalFamily.inner_right_fintype [Fintype ι] (l : ∀ i, G i) (i : ι) (v : G i) :\n    ⟪V i v, ∑ j : ι, V j (l j)⟫ = ⟪v, l i⟫ := by\n  classical calc\n      ⟪V i v, ∑ j : ι, V j (l j)⟫ = ∑ j : ι, ⟪V i v, V j (l j)⟫ := by rw [inner_sum]\n      _ = ∑ j, ite (i = j) ⟪V i v, V j (l j)⟫ 0 :=\n        (congr_arg (Finset.sum Finset.univ) <| funext fun j => hV.eq_ite v (l j))\n      _ = ⟪v, l i⟫ := by\n        simp only [Finset.sum_ite_eq, Finset.mem_univ, (V i).inner_map_map, if_true]\n      \n#align orthogonal_family.inner_right_fintype OrthogonalFamily.inner_right_fintype\n\ntheorem OrthogonalFamily.inner_sum (l₁ l₂ : ∀ i, G i) (s : Finset ι) :\n    ⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫ = ∑ i in s, ⟪l₁ i, l₂ i⟫ := by\n  classical calc\n      ⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫ = ∑ j in s, ∑ i in s, ⟪V i (l₁ i), V j (l₂ j)⟫ :=\n        by simp only [sum_inner, inner_sum]\n      _ = ∑ j in s, ∑ i in s, ite (i = j) ⟪V i (l₁ i), V j (l₂ j)⟫ 0 :=\n        by\n        congr with i\n        congr with j\n        apply hV.eq_ite\n      _ = ∑ i in s, ⟪l₁ i, l₂ i⟫ := by\n        simp only [Finset.sum_ite_of_true, Finset.sum_ite_eq', LinearIsometry.inner_map_map,\n          imp_self, imp_true_iff]\n      \n#align orthogonal_family.inner_sum OrthogonalFamily.inner_sum\n\ntheorem OrthogonalFamily.norm_sum (l : ∀ i, G i) (s : Finset ι) :\n    ‖∑ i in s, V i (l i)‖ ^ 2 = ∑ i in s, ‖l i‖ ^ 2 :=\n  by\n  have : (‖∑ i in s, V i (l i)‖ ^ 2 : 𝕜) = ∑ i in s, ‖l i‖ ^ 2 := by\n    simp only [← inner_self_eq_norm_sq_to_K, hV.inner_sum]\n  exact_mod_cast this\n#align orthogonal_family.norm_sum OrthogonalFamily.norm_sum\n\n/-- The composition of an orthogonal family of subspaces with an injective function is also an\northogonal family. -/\ntheorem OrthogonalFamily.comp {γ : Type _} {f : γ → ι} (hf : Function.Injective f) :\n    OrthogonalFamily 𝕜 (fun g => G (f g)) fun g => V (f g) := fun i j hij v w => hV (hf.Ne hij) v w\n#align orthogonal_family.comp OrthogonalFamily.comp\n\ntheorem OrthogonalFamily.orthonormal_sigma_orthonormal {α : ι → Type _} {v_family : ∀ i, α i → G i}\n    (hv_family : ∀ i, Orthonormal 𝕜 (v_family i)) :\n    Orthonormal 𝕜 fun a : Σi, α i => V a.1 (v_family a.1 a.2) :=\n  by\n  constructor\n  · rintro ⟨i, v⟩\n    simpa only [LinearIsometry.norm_map] using (hv_family i).left v\n  rintro ⟨i, v⟩ ⟨j, w⟩ hvw\n  by_cases hij : i = j\n  · subst hij\n    have : v ≠ w := fun h => by\n      subst h\n      exact hvw rfl\n    simpa only [LinearIsometry.inner_map_map] using (hv_family i).2 this\n  · exact hV hij (v_family i v) (v_family j w)\n#align orthogonal_family.orthonormal_sigma_orthonormal OrthogonalFamily.orthonormal_sigma_orthonormal\n\ninclude dec_ι\n\ntheorem OrthogonalFamily.norm_sq_diff_sum (f : ∀ i, G i) (s₁ s₂ : Finset ι) :\n    ‖(∑ i in s₁, V i (f i)) - ∑ i in s₂, V i (f i)‖ ^ 2 =\n      (∑ i in s₁ \\ s₂, ‖f i‖ ^ 2) + ∑ i in s₂ \\ s₁, ‖f i‖ ^ 2 :=\n  by\n  rw [← Finset.sum_sdiff_sub_sum_sdiff, sub_eq_add_neg, ← Finset.sum_neg_distrib]\n  let F : ∀ i, G i := fun i => if i ∈ s₁ then f i else -f i\n  have hF₁ : ∀ i ∈ s₁ \\ s₂, F i = f i := fun i hi => if_pos (Finset.sdiff_subset _ _ hi)\n  have hF₂ : ∀ i ∈ s₂ \\ s₁, F i = -f i := fun i hi => if_neg (finset.mem_sdiff.mp hi).2\n  have hF : ∀ i, ‖F i‖ = ‖f i‖ := by\n    intro i\n    dsimp only [F]\n    split_ifs <;> simp only [eq_self_iff_true, norm_neg]\n  have :\n    ‖(∑ i in s₁ \\ s₂, V i (F i)) + ∑ i in s₂ \\ s₁, V i (F i)‖ ^ 2 =\n      (∑ i in s₁ \\ s₂, ‖F i‖ ^ 2) + ∑ i in s₂ \\ s₁, ‖F i‖ ^ 2 :=\n    by\n    have hs : Disjoint (s₁ \\ s₂) (s₂ \\ s₁) := disjoint_sdiff_sdiff\n    simpa only [Finset.sum_union hs] using hV.norm_sum F (s₁ \\ s₂ ∪ s₂ \\ s₁)\n  convert this using 4\n  · refine' Finset.sum_congr rfl fun i hi => _\n    simp only [hF₁ i hi]\n  · refine' Finset.sum_congr rfl fun i hi => _\n    simp only [hF₂ i hi, LinearIsometry.map_neg]\n  · simp only [hF]\n  · simp only [hF]\n#align orthogonal_family.norm_sq_diff_sum OrthogonalFamily.norm_sq_diff_sum\n\nomit dec_ι\n\n/-- A family `f` of mutually-orthogonal elements of `E` is summable, if and only if\n`(λ i, ‖f i‖ ^ 2)` is summable. -/\ntheorem OrthogonalFamily.summable_iff_norm_sq_summable [CompleteSpace E] (f : ∀ i, G i) :\n    (Summable fun i => V i (f i)) ↔ Summable fun i => ‖f i‖ ^ 2 := by\n  classical\n    simp only [summable_iff_cauchySeq_finset, NormedAddCommGroup.cauchySeq_iff, Real.norm_eq_abs]\n    constructor\n    · intro hf ε hε\n      obtain ⟨a, H⟩ := hf _ (sqrt_pos.mpr hε)\n      use a\n      intro s₁ hs₁ s₂ hs₂\n      rw [← Finset.sum_sdiff_sub_sum_sdiff]\n      refine' (_root_.abs_sub _ _).trans_lt _\n      have : ∀ i, 0 ≤ ‖f i‖ ^ 2 := fun i : ι => sq_nonneg _\n      simp only [Finset.abs_sum_of_nonneg' this]\n      have : ((∑ i in s₁ \\ s₂, ‖f i‖ ^ 2) + ∑ i in s₂ \\ s₁, ‖f i‖ ^ 2) < sqrt ε ^ 2 :=\n        by\n        rw [← hV.norm_sq_diff_sum, sq_lt_sq, _root_.abs_of_nonneg (sqrt_nonneg _),\n          _root_.abs_of_nonneg (norm_nonneg _)]\n        exact H s₁ hs₁ s₂ hs₂\n      have hη := sq_sqrt (le_of_lt hε)\n      linarith\n    · intro hf ε hε\n      have hε' : 0 < ε ^ 2 / 2 := half_pos (sq_pos_of_pos hε)\n      obtain ⟨a, H⟩ := hf _ hε'\n      use a\n      intro s₁ hs₁ s₂ hs₂\n      refine' (abs_lt_of_sq_lt_sq' _ (le_of_lt hε)).2\n      have has : a ≤ s₁ ⊓ s₂ := le_inf hs₁ hs₂\n      rw [hV.norm_sq_diff_sum]\n      have Hs₁ : (∑ x : ι in s₁ \\ s₂, ‖f x‖ ^ 2) < ε ^ 2 / 2 :=\n        by\n        convert H _ hs₁ _ has\n        have : s₁ ⊓ s₂ ⊆ s₁ := Finset.inter_subset_left _ _\n        rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg']\n        · simp\n        · exact fun i => sq_nonneg _\n      have Hs₂ : (∑ x : ι in s₂ \\ s₁, ‖f x‖ ^ 2) < ε ^ 2 / 2 :=\n        by\n        convert H _ hs₂ _ has\n        have : s₁ ⊓ s₂ ⊆ s₂ := Finset.inter_subset_right _ _\n        rw [← Finset.sum_sdiff this, add_tsub_cancel_right, Finset.abs_sum_of_nonneg']\n        · simp\n        · exact fun i => sq_nonneg _\n      linarith\n#align orthogonal_family.summable_iff_norm_sq_summable OrthogonalFamily.summable_iff_norm_sq_summable\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. -/\ntheorem OrthogonalFamily.independent {V : ι → Submodule 𝕜 E}\n    (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ) :\n    CompleteLattice.Independent V := by\n  classical\n    apply CompleteLattice.independent_of_dfinsupp_lsum_injective\n    rw [← @LinearMap.ker_eq_bot _ _ _ _ _ _ (DirectSum.addCommGroup fun i => V i),\n      Submodule.eq_bot_iff]\n    intro v hv\n    rw [LinearMap.mem_ker] at hv\n    ext i\n    suffices ⟪(v i : E), v i⟫ = 0 by simpa only [inner_self_eq_zero] using this\n    calc\n      ⟪(v i : E), v i⟫ = ⟪(v i : E), Dfinsupp.lsum ℕ (fun i => (V i).Subtype) v⟫ := by\n        simpa only [Dfinsupp.sumAddHom_apply, Dfinsupp.lsum_apply_apply] using\n          (hV.inner_right_dfinsupp v i (v i)).symm\n      _ = 0 := by simp only [hv, inner_zero_right]\n      \n#align orthogonal_family.independent OrthogonalFamily.independent\n\ninclude dec_ι\n\ntheorem DirectSum.IsInternal.collectedBasis_orthonormal {V : ι → Submodule 𝕜 E}\n    (hV : OrthogonalFamily 𝕜 (fun i => V i) fun i => (V i).subtypeₗᵢ)\n    (hV_sum : DirectSum.IsInternal fun i => V i) {α : ι → Type _}\n    {v_family : ∀ i, Basis (α i) 𝕜 (V i)} (hv_family : ∀ i, Orthonormal 𝕜 (v_family i)) :\n    Orthonormal 𝕜 (hV_sum.collectedBasis v_family) := by\n  simpa only [hV_sum.collected_basis_coe] using hV.orthonormal_sigma_orthonormal hv_family\n#align direct_sum.is_internal.collected_basis_orthonormal DirectSum.IsInternal.collectedBasis_orthonormal\n\nend OrthogonalFamily\n\nsection IsROrCToReal\n\nvariable {G : Type _}\n\nvariable (𝕜 E)\n\ninclude 𝕜\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 `𝕜 = ℝ`. -/\ndef HasInner.isROrCToReal : HasInner ℝ E where inner x y := re ⟪x, y⟫\n#align has_inner.is_R_or_C_to_real HasInner.isROrCToReal\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 `𝕜 = ℝ`, but in can be used in a\nproof to obtain a real inner product space structure from a given `𝕜`-inner product space\nstructure. -/\ndef InnerProductSpace.isROrCToReal : InnerProductSpace ℝ E :=\n  { HasInner.isROrCToReal 𝕜 E,\n    NormedSpace.restrictScalars ℝ 𝕜\n      E with\n    norm_sq_eq_inner := norm_sq_eq_inner\n    conj_symm := fun x y => inner_re_symm _ _\n    add_left := fun x y z => by\n      change re ⟪x + y, z⟫ = re ⟪x, z⟫ + re ⟪y, z⟫\n      simp only [inner_add_left, map_add]\n    smul_left := fun x y r => by\n      change re ⟪(r : 𝕜) • x, y⟫ = r * re ⟪x, y⟫\n      simp only [inner_smul_left, conj_of_real, of_real_mul_re] }\n#align inner_product_space.is_R_or_C_to_real InnerProductSpace.isROrCToReal\n\nvariable {E}\n\ntheorem real_inner_eq_re_inner (x y : E) :\n    @HasInner.inner ℝ E (HasInner.isROrCToReal 𝕜 E) x y = re ⟪x, y⟫ :=\n  rfl\n#align real_inner_eq_re_inner real_inner_eq_re_inner\n\ntheorem real_inner_i_smul_self (x : E) :\n    @HasInner.inner ℝ E (HasInner.isROrCToReal 𝕜 E) x ((i : 𝕜) • x) = 0 := by\n  simp [real_inner_eq_re_inner, inner_smul_right]\n#align real_inner_I_smul_self real_inner_i_smul_self\n\nomit 𝕜\n\n/-- A complex inner product implies a real inner product -/\ninstance InnerProductSpace.complexToReal [NormedAddCommGroup G] [InnerProductSpace ℂ G] :\n    InnerProductSpace ℝ G :=\n  InnerProductSpace.isROrCToReal ℂ G\n#align inner_product_space.complex_to_real InnerProductSpace.complexToReal\n\n@[simp]\nprotected theorem Complex.inner (w z : ℂ) : ⟪w, z⟫_ℝ = (conj w * z).re :=\n  rfl\n#align complex.inner Complex.inner\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. -/\ntheorem inner_map_complex [NormedAddCommGroup G] [InnerProductSpace ℝ G] (f : G ≃ₗᵢ[ℝ] ℂ)\n    (x y : G) : ⟪x, y⟫_ℝ = (conj (f x) * f y).re := by rw [← Complex.inner, f.inner_map_map]\n#align inner_map_complex inner_map_complex\n\nend IsROrCToReal\n\nsection Continuous\n\n/-!\n### Continuity of the inner product\n-/\n\n\ntheorem continuous_inner : Continuous fun p : E × E => ⟪p.1, p.2⟫ :=\n  letI : InnerProductSpace ℝ E := InnerProductSpace.isROrCToReal 𝕜 E\n  is_bounded_bilinear_map_inner.continuous\n#align continuous_inner continuous_inner\n\nvariable {α : Type _}\n\ntheorem Filter.Tendsto.inner {f g : α → E} {l : Filter α} {x y : E} (hf : Tendsto f l (𝓝 x))\n    (hg : Tendsto g l (𝓝 y)) : Tendsto (fun t => ⟪f t, g t⟫) l (𝓝 ⟪x, y⟫) :=\n  (continuous_inner.Tendsto _).comp (hf.prod_mk_nhds hg)\n#align filter.tendsto.inner Filter.Tendsto.inner\n\nvariable [TopologicalSpace α] {f g : α → E} {x : α} {s : Set α}\n\ninclude 𝕜\n\ntheorem ContinuousWithinAt.inner (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) :\n    ContinuousWithinAt (fun t => ⟪f t, g t⟫) s x :=\n  hf.inner hg\n#align continuous_within_at.inner ContinuousWithinAt.inner\n\ntheorem ContinuousAt.inner (hf : ContinuousAt f x) (hg : ContinuousAt g x) :\n    ContinuousAt (fun t => ⟪f t, g t⟫) x :=\n  hf.inner hg\n#align continuous_at.inner ContinuousAt.inner\n\ntheorem ContinuousOn.inner (hf : ContinuousOn f s) (hg : ContinuousOn g s) :\n    ContinuousOn (fun t => ⟪f t, g t⟫) s := fun x hx => (hf x hx).inner (hg x hx)\n#align continuous_on.inner ContinuousOn.inner\n\n@[continuity]\ntheorem Continuous.inner (hf : Continuous f) (hg : Continuous g) : Continuous fun t => ⟪f t, g t⟫ :=\n  continuous_iff_continuousAt.2 fun x => hf.ContinuousAt.inner hg.ContinuousAt\n#align continuous.inner Continuous.inner\n\nend Continuous\n\nsection ReApplyInnerSelf\n\n/-- Extract a real bilinear form from an operator `T`, by taking the pairing `λ x, re ⟪T x, x⟫`. -/\ndef ContinuousLinearMap.reApplyInnerSelf (T : E →L[𝕜] E) (x : E) : ℝ :=\n  re ⟪T x, x⟫\n#align continuous_linear_map.re_apply_inner_self ContinuousLinearMap.reApplyInnerSelf\n\ntheorem ContinuousLinearMap.reApplyInnerSelf_apply (T : E →L[𝕜] E) (x : E) :\n    T.reApplyInnerSelf x = re ⟪T x, x⟫ :=\n  rfl\n#align continuous_linear_map.re_apply_inner_self_apply ContinuousLinearMap.reApplyInnerSelf_apply\n\ntheorem ContinuousLinearMap.reApplyInnerSelf_continuous (T : E →L[𝕜] E) :\n    Continuous T.reApplyInnerSelf :=\n  reClm.Continuous.comp <| T.Continuous.inner continuous_id\n#align continuous_linear_map.re_apply_inner_self_continuous ContinuousLinearMap.reApplyInnerSelf_continuous\n\ntheorem ContinuousLinearMap.reApplyInnerSelf_smul (T : E →L[𝕜] E) (x : E) {c : 𝕜} :\n    T.reApplyInnerSelf (c • x) = ‖c‖ ^ 2 * T.reApplyInnerSelf x := by\n  simp only [ContinuousLinearMap.map_smul, ContinuousLinearMap.reApplyInnerSelf_apply,\n    inner_smul_left, inner_smul_right, ← mul_assoc, mul_conj, norm_sq_eq_def', ← smul_re,\n    Algebra.smul_def (‖c‖ ^ 2) ⟪T x, x⟫, algebra_map_eq_of_real]\n#align continuous_linear_map.re_apply_inner_self_smul ContinuousLinearMap.reApplyInnerSelf_smul\n\nend ReApplyInnerSelf\n\nnamespace UniformSpace.Completion\n\nopen UniformSpace Function\n\ninstance {𝕜' E' : Type _} [TopologicalSpace 𝕜'] [UniformSpace E'] [HasInner 𝕜' E'] :\n    HasInner 𝕜' (Completion E')\n    where inner := curry <| (denseInducing_coe.Prod denseInducing_coe).extend (uncurry inner)\n\n@[simp]\ntheorem inner_coe (a b : E) : inner (a : Completion E) (b : Completion E) = (inner a b : 𝕜) :=\n  (denseInducing_coe.Prod denseInducing_coe).extend_eq\n    (continuous_inner : Continuous (uncurry inner : E × E → 𝕜)) (a, b)\n#align uniform_space.completion.inner_coe UniformSpace.Completion.inner_coe\n\nprotected theorem continuous_inner : Continuous (uncurry inner : Completion E × Completion E → 𝕜) :=\n  by\n  let inner' : E →+ E →+ 𝕜 :=\n    { toFun := fun x => (innerₛₗ 𝕜 x).toAddMonoidHom\n      map_zero' := by ext x <;> exact inner_zero_left _\n      map_add' := fun x y => by ext z <;> exact inner_add_left _ _ _ }\n  have : Continuous fun p : E × E => inner' p.1 p.2 := continuous_inner\n  rw [completion.has_inner, uncurry_curry _]\n  change\n    Continuous\n      (((dense_inducing_to_compl E).Prod (dense_inducing_to_compl E)).extend fun p : E × E =>\n        inner' p.1 p.2)\n  exact (dense_inducing_to_compl E).extend_Z_bilin (dense_inducing_to_compl E) this\n#align uniform_space.completion.continuous_inner UniformSpace.Completion.continuous_inner\n\nprotected theorem Continuous.inner {α : Type _} [TopologicalSpace α] {f g : α → Completion E}\n    (hf : Continuous f) (hg : Continuous g) : Continuous (fun x : α => inner (f x) (g x) : α → 𝕜) :=\n  UniformSpace.Completion.continuous_inner.comp (hf.prod_mk hg : _)\n#align uniform_space.completion.continuous.inner UniformSpace.Completion.Continuous.inner\n\ninstance : InnerProductSpace 𝕜 (Completion E)\n    where\n  norm_sq_eq_inner x :=\n    Completion.induction_on x\n      (isClosed_eq (continuous_norm.pow 2)\n        (continuous_re.comp (Continuous.inner continuous_id' continuous_id')))\n      fun a => by simp only [norm_coe, inner_coe, inner_self_eq_norm_sq]\n  conj_symm x y :=\n    Completion.induction_on₂ x y\n      (isClosed_eq (continuous_conj.comp (Continuous.inner continuous_snd continuous_fst))\n        (Continuous.inner continuous_fst continuous_snd))\n      fun a b => by simp only [inner_coe, inner_conj_symm]\n  add_left x y z :=\n    Completion.induction_on₃ x y z\n      (isClosed_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      fun a b c => by simp only [← coe_add, inner_coe, inner_add_left]\n  smul_left x y c :=\n    Completion.induction_on₂ x y\n      (isClosed_eq (Continuous.inner (continuous_fst.const_smul c) continuous_snd)\n        ((continuous_mul_left _).comp (Continuous.inner continuous_fst continuous_snd)))\n      fun a b => by simp only [← coe_smul c a, inner_coe, inner_smul_left]\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/Analysis/InnerProductSpace/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996141, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7661329083690587}}
{"text": "import data.real.basic algebra.group_power tactic.ring\n\nvariable {x : ℝ}\ndef f : ℝ → ℝ := λ x, x^2 + 3\ndef g : ℝ → ℝ := λ x, 2*x\n\ndef h1 : ℝ → ℝ := g ∘ f\ntheorem Q1005i : h1 x = 2*x^2 + 6 := sorry \n\ndef h2 : ℝ → ℝ := f ∘ g\ntheorem Q1005ii : h2 x = 4*x^2 + 3 := sorry\n\ndef h3 : ℝ → ℝ := λ x, f x * g x\ntheorem Q1005iii : h3 x = 2*x^3 + 6*x := sorry \n\ndef h4 : ℝ → ℝ := λ x, f x + g x\ntheorem Q1005iv : h4 x = x^2 + 2*x + 3 := sorry\n\ndef h5 : ℝ → ℝ := λ x, f (g x)\ntheorem Q1005v : h5 x = h2 x := 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/PB1005/Q1005.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951698485603, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7661043810929099}}
{"text": "/- First-class functions -/\n\ndef twice (f : Nat → Nat) (a : Nat) :=\n  f (f a)\n\n#check twice\n-- (Nat → Nat) → Nat → Nat\n\n#eval twice (fun x => x + 2) 10\n\ntheorem twice_add_2 (a : Nat) : twice (fun x => x + 2) a = a + 4 := rfl\n\n-- `(· + 2)` is syntax sugar for `(fun x => x + 2)`.\n#eval twice (· + 2) 10\n", "meta": {"author": "leanprover", "repo": "lean4", "sha": "742d053a97bdd109a41a921facd1cd6a55e89bc7", "save_path": "github-repos/lean/leanprover-lean4", "path": "github-repos/lean/leanprover-lean4/lean4-742d053a97bdd109a41a921facd1cd6a55e89bc7/doc/examples/NFM2022/nfm2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951625409308, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7661043751014331}}
{"text": "import data.nat.basic\nimport data.nat.parity\nimport data.int.basic\nimport tactic\n\n@[ext]\nstructure frog :=\n  -- A frog hangs out on the natural number line of lily pads\n  (location : ℕ → ℕ)\n  -- At time 0, it sits on location 0\n  (location_zero : location 0 = 0) \n  -- For some fixed step size, \n  (step_size : ℕ)\n  -- the frog jumps `step_size` units to the right each second.\n  (step : ∀ n, location (n+1) = location n + step_size)\n\nlemma frog_explicit_formula (f : frog) :\n-- Show that the position of the frog at time n is n * step_size.\n∀ n, f.location n = n * f.step_size := \nbegin\n  intros, induction n with d hd,\n  rw f.location_zero, norm_num,\n  rw [f.step, hd, ← nat.add_one],\n  ring,\nend\n\n-- We can define a frog just by giving its step size\nlocal attribute [simp]\ndef frog_of_step_size (step_size : ℕ) : frog :=\n{ location := λ n, n * step_size, \n  location_zero := by simp, \n  step_size := step_size, \n  step := by {intro, ring} }\n\n-- and every frog can be defined in this way\nlemma frog_eq_frog_of_step_size (f : frog) : \nf = frog_of_step_size f.step_size :=\nbegin\n  ext, \n  { rw frog_explicit_formula, simp },\n  simp,\nend\n\nlemma catch_the_frog : \n-- Show that there is a way to check one lily pad each second\n  ∃ (strategy : ℕ → ℕ), \n-- so that no matter how fast the frog travels,\n  ∀ step_size, \n-- you'll eventually catch it. \n  ∃ catch_time > 0, \n  strategy catch_time = (frog_of_step_size step_size).location catch_time :=\nbegin\n  use λ n, n * (n - 1),\n  intro k, use k + 1,\n  split, { linarith, },\n  simp,\nend\n\n", "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/qquiz_2012_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217417, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.766057013998408}}
{"text": "-- One way in which Lean’s dependent type theory extends simple type theory is that types themselves\n-- entities like nat and bool, are first-class citizens\n-- which is to say that they themselves are objects of study which means that they \n-- also have types \n\n#check nat \n#check bool\n#check nat → bool\n#check nat × bool\n#check nat → nat \n#check nat × nat → nat \n#check nat → nat → nat\n#check nat → (nat → nat)\n#check nat → nat → bool \n#check (nat → nat) → nat \n\n\n-- We can also declare new constants and constructors for types:\nconstants α β : Type\nconstant F : Type → Type\nconstant G : Type → Type → Type \n\n#check α\n#check F α \n#check F nat\n#check G α \n#check G α β \n#check G α nat \n\n-- Indeed, we have already seen an example of a function of type Type → Type → Type, namely,\n-- the Cartesian product.\n\nconstants χ μ : Type\n\n#check prod χ μ \n#check prod nat nat \n\n\n-- Here is another example: given any type α, \n-- the type list α denotes the type of lists of elements of type α.\n\nconstant γ : Type\n\n#check list γ \n#check list nat\n\n\n-- Given that every expression in Lean has a type,\n-- it is natural to ask: what type does Type itself have?\n#check Type \n\n-- We have actually come up against one of the most subtle aspects of Lean’s typing system.\n-- Lean’s underlying foundation has an infinite hierarchy of types:\n\n#check Type     -- Type 1\n#check Type 1   -- Type 2\n#check Type 2   -- Type 3\n#check Type 3   -- Type 4\n#check Type 4   -- Type 5\n\n#check Prop\n\n\n\n-- We want some operations, however, to be polymorphic over type universes.\n-- For example, list α should make sense for any type α, no matter which type universe α lives in.\n#check list\n\n-- The function prod is similarly polymorphic:\n#check prod\n\n\n\n-- To define polymorphic constants and variables,\n-- Lean allows us to declare universe variables explicitly: \nuniverse u \nconstant ζ : Type u\n#check ζ \n\n-- Equivalently, we can write Type _ or Type* to avoid giving the arbitrary universe a name:\nconstant σ : Type _\n#check σ \n\nconstant κ : Type*\n#check κ \n\n", "meta": {"author": "0x-Inf", "repo": "theorem_proving_in_lean", "sha": "ffba957d08381aa846eb33cd1c855dd30eaca52f", "save_path": "github-repos/lean/0x-Inf-theorem_proving_in_lean", "path": "github-repos/lean/0x-Inf-theorem_proving_in_lean/theorem_proving_in_lean-ffba957d08381aa846eb33cd1c855dd30eaca52f/code_examples/part2/types_as_objects.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7660089818936889}}
{"text": "-- Lista 7: Capítulo 14\n\n-- Lucas Moschen\n\n-- Exercício 1\n\nsection\n    parameters {A : Type} {R : A → A → Prop}\n    parameter (irreflR : irreflexive R)\n    parameter (transR : transitive R)\n\n    variables a b c : A\n\n    local infix < := R\n\n    def R' (a b : A) : Prop := R a b ∨ a = b\n    local infix ≤ := R'\n\n    theorem reflR' (a : A) : a ≤ 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 ≤ b) (h2 : b ≤ c):\n    a ≤ 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 ≤ b) (h2 : b ≤ a) :\n    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-- Exercício 2\n\nsection\n    parameters {A : Type} {R : A → A → Prop}\n    parameter (reflR : reflexive R)\n    parameter (transR : transitive R)\n\n    def S (a b : A) : Prop := R a b ∧ 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-- Exercício 3\n\nsection\n  parameters {A : Type} {a b c : A} {R : A → A → Prop}\n  parameter (Rab : R a b)\n  parameter (Rbc : R b c)\n  parameter (nRac : ¬ R a c)\n\n  -- Prove one of the following two theorems:\n\n  theorem R_is_not_strict_partial_order :\n    ¬(irreflexive R ∧ transitive R) :=\n  assume h: irreflexive R ∧ transitive R, \n  show false, from nRac (h.right Rab Rbc)\nend\n\n-- Exercício 4\n\nopen nat\n\nexample : 1 ≤ 4 :=\nhave 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 ≤ (1 + 1 + 1) + 1, from le_of_lt (lt_trans h1 (lt_trans h2 h3)),\neq.subst h4 h5 ", "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/cap14-LucasMoschen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762114, "lm_q2_score": 0.8519527982093668, "lm_q1q2_score": 0.7660089779008732}}
{"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! This file was ported from Lean 3 source module data.list.rdrop\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.Data.List.Basic\nimport Mathlib.Data.List.Infix\n/-!\n\n# Dropping or taking from lists on the right\n\nTaking or removing element from the tail end of a list\n\n## Main defintions\n\n- `rdrop n`: drop `n : ℕ` elements from the tail\n- `rtake n`: take `n : ℕ` elements from the tail\n- `rdropWhile p`: remove all the elements from the tail of a list until it finds the first element\n  for which `p : α → Bool` returns false. This element and everything before is returned.\n- `rtakeWhile p`:  Returns the longest terminal segment of a list for which `p : α → Bool` returns\n  true.\n\n## Implementation detail\n\nThe two predicate-based methods operate by performing the regular \"from-left\" operation on\n`List.reverse`, followed by another `List.reverse`, so they are not the most performant.\nThe other two rely on `List.length l` so they still traverse the list twice. One could construct\nanother function that takes a `L : ℕ` and use `L - n`. Under a proof condition that\n`L = l.length`, the function would do the right thing.\n\n-/\n\n\nvariable {α : Type _} (p : α → Bool) (l : List α) (n : ℕ)\n\nnamespace List\n\n/-- Drop `n` elements from the tail end of a list. -/\ndef rdrop : List α :=\n  l.take (l.length - n)\n#align list.rdrop List.rdrop\n\n@[simp]\ntheorem rdrop_nil : rdrop ([] : List α) n = [] := by simp [rdrop]\n#align list.rdrop_nil List.rdrop_nil\n\n@[simp]\ntheorem rdrop_zero : rdrop l 0 = l := by simp [rdrop]\n#align list.rdrop_zero List.rdrop_zero\n\ntheorem rdrop_eq_reverse_drop_reverse : l.rdrop n = reverse (l.reverse.drop n) := by\n  rw [rdrop]\n  induction' l using List.reverseRecOn with xs x IH generalizing n\n  · simp\n  · cases n\n    · simp [take_append]\n    · simp [take_append_eq_append_take, IH]\n#align list.rdrop_eq_reverse_drop_reverse List.rdrop_eq_reverse_drop_reverse\n\n@[simp]\ntheorem rdrop_concat_succ (x : α) : rdrop (l ++ [x]) (n + 1) = rdrop l n := by\n  simp [rdrop_eq_reverse_drop_reverse]\n#align list.rdrop_concat_succ List.rdrop_concat_succ\n\n/-- Take `n` elements from the tail end of a list. -/\ndef rtake : List α :=\n  l.drop (l.length - n)\n#align list.rtake List.rtake\n\n@[simp]\ntheorem rtake_nil : rtake ([] : List α) n = [] := by simp [rtake]\n#align list.rtake_nil List.rtake_nil\n\n@[simp]\ntheorem rtake_zero : rtake l 0 = [] := by simp [rtake]\n#align list.rtake_zero List.rtake_zero\n\ntheorem rtake_eq_reverse_take_reverse : l.rtake n = reverse (l.reverse.take n) := by\n  rw [rtake]\n  induction' l using List.reverseRecOn with xs x IH generalizing n\n  · simp\n  · cases n\n    · exact drop_length _\n    · simp [drop_append_eq_append_drop, IH]\n#align list.rtake_eq_reverse_take_reverse List.rtake_eq_reverse_take_reverse\n\n@[simp]\ntheorem rtake_concat_succ (x : α) : rtake (l ++ [x]) (n + 1) = rtake l n ++ [x] := by\n  simp [rtake_eq_reverse_take_reverse]\n#align list.rtake_concat_succ List.rtake_concat_succ\n\n/-- Drop elements from the tail end of a list that satisfy `p : α → Bool`.\nImplemented naively via `List.reverse` -/\ndef rdropWhile : List α :=\n  reverse (l.reverse.dropWhile p)\n#align list.rdrop_while List.rdropWhile\n\n@[simp]\ntheorem rdropWhile_nil : rdropWhile p ([] : List α) = [] := by simp [rdropWhile, dropWhile]\n#align list.rdrop_while_nil List.rdropWhile_nil\n\ntheorem rdropWhile_concat (x : α) :\n    rdropWhile p (l ++ [x]) = if p x then rdropWhile p l else l ++ [x] := by\n  simp only [rdropWhile, dropWhile, reverse_append, reverse_singleton, singleton_append]\n  split_ifs with h <;> simp [h]\n#align list.rdrop_while_concat List.rdropWhile_concat\n\n@[simp]\ntheorem rdropWhile_concat_pos (x : α) (h : p x) : rdropWhile p (l ++ [x]) = rdropWhile p l := by\n  rw [rdropWhile_concat, if_pos h]\n#align list.rdrop_while_concat_pos List.rdropWhile_concat_pos\n\n@[simp]\ntheorem rdropWhile_concat_neg (x : α) (h : ¬p x) : rdropWhile p (l ++ [x]) = l ++ [x] := by\n  rw [rdropWhile_concat, if_neg h]\n#align list.rdrop_while_concat_neg List.rdropWhile_concat_neg\n\ntheorem rdropWhile_singleton (x : α) : rdropWhile p [x] = if p x then [] else [x] := by\n  rw [← nil_append [x], rdropWhile_concat, rdropWhile_nil]\n#align list.rdrop_while_singleton List.rdropWhile_singleton\n\ntheorem rdropWhile_last_not (hl : l.rdropWhile p ≠ []) : ¬p ((rdropWhile p l).getLast hl) := by\n  simp_rw [rdropWhile]\n  rw [getLast_reverse]\n  exact dropWhile_nthLe_zero_not _ _ _\n#align list.rdrop_while_last_not List.rdropWhile_last_not\n\ntheorem rdropWhile_prefix : l.rdropWhile p <+: l := by\n  rw [← reverse_suffix, rdropWhile, reverse_reverse]\n  exact dropWhile_suffix _\n#align list.rdrop_while_prefix List.rdropWhile_prefix\n\nvariable {p} {l}\n\n@[simp]\ntheorem rdropWhile_eq_nil_iff : rdropWhile p l = [] ↔ ∀ x ∈ l, p x := by simp [rdropWhile]\n#align list.rdrop_while_eq_nil_iff List.rdropWhile_eq_nil_iff\n\n-- it is in this file because it requires `List.Infix`\n@[simp]\ntheorem dropWhile_eq_self_iff : dropWhile p l = l ↔ ∀ hl : 0 < l.length, ¬p (l.nthLe 0 hl) := by\n  cases' l with hd tl\n  · simp only [dropWhile, true_iff]\n    intro h\n    by_contra\n    rwa [length_nil, lt_self_iff_false] at h\n  · rw [dropWhile]\n    refine' ⟨fun h => _, fun h => _⟩\n    · intro _ H\n      rw [nthLe, get] at H\n      refine' (cons_ne_self hd tl) (Sublist.antisymm _ (sublist_cons _ _))\n      rw [← h]\n      simp only [H]\n      exact List.isSuffix.sublist (dropWhile_suffix p)\n    · have := h (by simp only [length, Nat.succ_pos])\n      rw [nthLe, get] at this\n      simp_rw [this]\n#align list.drop_while_eq_self_iff List.dropWhile_eq_self_iff\n\n/- porting note: This proof is longer than it used to be because `simp` refuses to rewrite\n the `l ≠ []` condition if `hl` is not `intro`'d yet -/\n@[simp]\ntheorem rdropWhile_eq_self_iff : rdropWhile p l = l ↔ ∀ hl : l ≠ [], ¬p (l.getLast hl) := by\n  simp only [rdropWhile, reverse_eq_iff, dropWhile_eq_self_iff, getLast_eq_get]\n  refine' ⟨fun h hl => _, fun h hl => _⟩\n  · rw [← length_pos, ← length_reverse] at hl\n    have := h hl\n    rwa [nthLe, get_reverse'] at this\n  · rw [length_reverse, length_pos] at hl\n    have := h hl\n    rwa [nthLe, get_reverse']\n#align list.rdrop_while_eq_self_iff List.rdropWhile_eq_self_iff\n\nvariable (p) (l)\n\ntheorem dropWhile_idempotent : dropWhile p (dropWhile p l) = dropWhile p l := by\n  simp only [dropWhile_eq_self_iff]\n  exact fun h => dropWhile_nthLe_zero_not p l h\n\n#align list.drop_while_idempotent List.dropWhile_idempotent\n\ntheorem rdropWhile_idempotent : rdropWhile p (rdropWhile p l) = rdropWhile p l :=\n  rdropWhile_eq_self_iff.mpr (rdropWhile_last_not _ _)\n#align list.rdrop_while_idempotent List.rdropWhile_idempotent\n\n/-- Take elements from the tail end of a list that satisfy `p : α → Bool`.\nImplemented naively via `List.reverse` -/\ndef rtakeWhile : List α :=\n  reverse (l.reverse.takeWhile p)\n#align list.rtake_while List.rtakeWhile\n\n@[simp]\ntheorem rtakeWhile_nil : rtakeWhile p ([] : List α) = [] := by simp [rtakeWhile, takeWhile]\n#align list.rtake_while_nil List.rtakeWhile_nil\n\ntheorem rtakeWhile_concat (x : α) :\n    rtakeWhile p (l ++ [x]) = if p x then rtakeWhile p l ++ [x] else [] := by\n  simp only [rtakeWhile, takeWhile, reverse_append, reverse_singleton, singleton_append]\n  split_ifs with h <;> simp [h]\n#align list.rtake_while_concat List.rtakeWhile_concat\n\n@[simp]\ntheorem rtakeWhile_concat_pos (x : α) (h : p x) :\n    rtakeWhile p (l ++ [x]) = rtakeWhile p l ++ [x] := by rw [rtakeWhile_concat, if_pos h]\n#align list.rtake_while_concat_pos List.rtakeWhile_concat_pos\n\n@[simp]\ntheorem rtakeWhile_concat_neg (x : α) (h : ¬p x) : rtakeWhile p (l ++ [x]) = [] := by\n  rw [rtakeWhile_concat, if_neg h]\n#align list.rtake_while_concat_neg List.rtakeWhile_concat_neg\n\ntheorem rtakeWhile_suffix : l.rtakeWhile p <:+ l := by\n  rw [← reverse_prefix, rtakeWhile, reverse_reverse]\n  exact takeWhile_prefix _\n#align list.rtake_while_suffix List.rtakeWhile_suffix\n\nvariable {p} {l}\n\n@[simp]\ntheorem rtakeWhile_eq_self_iff : rtakeWhile p l = l ↔ ∀ x ∈ l, p x := by\n  simp [rtakeWhile, reverse_eq_iff]\n#align list.rtake_while_eq_self_iff List.rtakeWhile_eq_self_iff\n\n-- Porting note: This needed a lot of rewriting.\n@[simp]\n\n\ntheorem mem_rtakeWhile_imp {x : α} (hx : x ∈ rtakeWhile p l) : p x := by\n  rw [rtakeWhile, mem_reverse] at hx\n  exact mem_takeWhile_imp hx\n\n#align list.mem_rtake_while_imp List.mem_rtakeWhile_imp\n\nvariable (p) (l)\n\ntheorem rtakeWhile_idempotent : rtakeWhile p (rtakeWhile p l) = rtakeWhile p l :=\n  rtakeWhile_eq_self_iff.mpr fun _ => mem_rtakeWhile_imp\n#align list.rtake_while_idempotent List.rtakeWhile_idempotent\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/Rdrop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8633916064587, "lm_q1q2_score": 0.7660049968519754}}
{"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 {𝕜 : Type*} [linear_ordered_field 𝕜]\n\nlemma pow_div_pow_eventually_eq_at_top {p q : ℕ} :\n  (λ x : 𝕜, x^p / x^q) =ᶠ[at_top] (λ x, x^((p : ℤ) -q)) :=\nbegin\n  apply ((eventually_gt_at_top (0 : 𝕜)).mono (λ x hx, _)),\n  simp [fpow_sub hx.ne'],\nend\n\nlemma pow_div_pow_eventually_eq_at_bot {p q : ℕ} :\n  (λ x : 𝕜, x^p / x^q) =ᶠ[at_bot] (λ x, x^((p : ℤ) -q)) :=\nbegin\n  apply ((eventually_lt_at_bot (0 : 𝕜)).mono (λ x hx, _)),\n  simp [fpow_sub hx.ne'.symm],\nend\n\nlemma tendsto_fpow_at_top_at_top {n : ℤ}\n  (hn : 0 < n) : tendsto (λ x : 𝕜, x^n) at_top at_top :=\nbegin\n  lift n to ℕ using hn.le,\n  simp only [gpow_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 : ℕ}\n  (hpq : q < p) : tendsto (λ x : 𝕜, x^p / x^q) at_top at_top :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_fpow_at_top_at_top,\n  linarith\nend\n\nlemma tendsto_pow_div_pow_at_top_zero [topological_space 𝕜] [order_topology 𝕜] {p q : ℕ}\n  (hpq : p < q) : tendsto (λ x : 𝕜, x^p / x^q) at_top (𝓝 0) :=\nbegin\n  rw tendsto_congr' pow_div_pow_eventually_eq_at_top,\n  apply tendsto_fpow_at_top_zero,\n  linarith\nend\n\nend linear_ordered_field\n\nsection normed_linear_ordered_field\n\nvariables {𝕜 : Type*} [normed_linear_ordered_field 𝕜]\n\nlemma asymptotics.is_o_pow_pow_at_top_of_lt\n  [order_topology 𝕜] {p q : ℕ} (hpq : p < q) :\n  is_o (λ x : 𝕜, x^p) (λ 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 (λ x hx hxq, (pow_ne_zero q hx.ne' hxq).elim),\nend\n\nlemma asymptotics.is_O.trans_tendsto_norm_at_top {α : Type*} {u v : α → 𝕜} {l : filter α}\n  (huv : is_O u v l) (hu : tendsto (λ x, ∥u x∥) l at_top) : tendsto (λ x, ∥v x∥) l at_top :=\nbegin\n  rcases huv.exists_pos with ⟨c, hc, hcuv⟩,\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": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/analysis/asymptotics/specific_asymptotics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.863391599428538, "lm_q1q2_score": 0.7660049880398078}}
{"text": "-- Pruebas de y = x → y = z → x = z\n-- ================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    y = x → y = z → x = z\n-- ----------------------------------------------------\n\nimport tactic\n\nvariables (U : Type) \nvariables (x y z : U)\n\n-- 1ª demostración\nexample : y = x → y = z → x = z :=\nassume h1 : y = x,\nassume h2 : y = z,\nhave h3 : x = y, from eq.symm h1,\nshow x = z,      from eq.trans h3 h2\n\n-- 2ª demostración\nexample : y = x → y = z → x = z :=\nassume h1 : y = x,\nassume h2 : y = z,\nhave h3 : x = y, from eq.symm h1,\neq.trans h3 h2\n\n-- 3ª demostración\nexample : y = x → y = z → x = z :=\nassume h1 : y = x,\nassume h2 : y = z,\neq.trans (eq.symm h1) h2\n\n-- 4ª demostración\nexample : y = x → y = z → x = z :=\nλ h1 h2, eq.trans (eq.symm h1) h2\n\n-- 5ª demostración\nexample : y = x → y = z → x = z :=\nλ h1 h2, eq.trans h1.symm h2\n\n-- 6ª demostración\nexample : y = x → y = z → x = z :=\n-- by library_search\nλ h, h.congr_left.mp\n\n-- 7ª demostración\nexample : y = x → y = z → x = z :=\nbegin\n  intros h1 h2,\n  rwa ←h1,\nend\n\n-- 8ª demostración\nexample : y = x → y = z → x = z :=\nbegin\n  intros h1 h2,\n  rw h1 at h2,\n  assumption,\nend\n\n-- 9ª demostración\nexample : y = x → y = z → x = z :=\nbegin\n  intros h1 h2,\n  rwa h1 at h2,\nend\n\n-- 10ª demostración\nexample : y = x → y = z → x = z :=\nbegin\n  intros h1 h2,\n  calc x = y : h1.symm\n     ... = z : h2,\nend\n\n-- 11ª demostración\nexample : y = x → y = z → x = z :=\n-- by hint\nby finish\n\n-- 12ª demostración\nexample : y = x → y = z → x = z :=\nassume h1 : y = x,\nassume h2 : y = z,\nshow x = z,\n  begin\n    rw ←h1,\n    rw h2\n  end\n\n-- 13ª demostración\nexample : y = x → y = z → x = z :=\nassume h1 : y = x,\nassume h2 : y = z,\nshow x = z,\n  begin\n    rw [←h1, h2]\n  end\n\n-- 14ª demostración\nexample : y = x → y = z → x = z :=\nassume h1 : y = x,\nassume h2 : y = z,\nshow x = z, by rw [←h1, h2]\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/Pruebas_de_yIx→yIz→xIz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7659830550504412}}
{"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.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 `≈` on `X`, then for every other type `Y` and every function `h : X → Y` such that \n`x ≈ x' → f x = f x'` there is a unique function `h : X/≈  → Y` such that `f = h ∘ q`. In standard maths courses \nthe existence of such `h` in examples is often justified as follows: For each equivalence class `⟦x⟧` of \nthe quotient, choose a representative `x : X` and define `h(⟦x⟧) := f(x)`. One has to then prove that this \nis well-defined by invoking the assumption `x ≈ x' → f x = f x'`. In Lean, the function `h` can be produced \nautomatically using `quotient.lift` applied to the assumption `x ≈ x' → 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\ndef neg : myint → myint := _\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/≈₂` and we are given \na function `g : X → Z`. Consider the function `f = q₂ ∘ g` where `q₂ : Z → Z/≈₂` is the surjection.  \nThen `x ≈ x' → f x = f x'` can be checked on `Z` instead, i.e. it can be checked that `x ≈ x' → g x ≈₂ 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 ≈ x' → g x ≈₂ g x'` and defines a function `X/≈ → Z/≈₂`.\n\n-/\n\ndef neg2 : myint → myint := _\nbegin \n  sorry\nend\n\n/- Why do the two definitions just defined agree? -/\nlemma defn_neg_agree : neg = neg2 :=\nbegin\n  sorry\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×R → R` and `*: R×R → 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) `∃ 0 : x+0=x=0+x` for all `x : R`\n(R4) `∀ x ∃ -x : x + (-x) = (-x) + x = 0`\n(R5) `(x * y) * z = x * (y * z)`\n(R6) `∃ 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×R → R`, but rather a function `R → (R → R)`, or \n`R → R → R` as in contrast to addition and multiplication, `→` is right associative in Lean.  \nThe function `R → (R → R)` takes a ring element `x : R` and sends it to the function `R → R` \nwhich sends `y : R` to `x + y`, in λ-notation `λ y, x+y`. In computer science, the correspondence \nbetween functions `R×R → R` and `R → (R → 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  `- × R` and taking Hom in the category of sets \n`Hom(R,-)` are adjoint to each other.    \n\nWe want to define addition `myint × myint → myint` or equivalently `myint → myint → 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 × Y` given by `(x,y) ≈ (x',y')` iff `x ≈ x'` and `y ≈ 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₂`. \n\n-/\n\ndef add : myint → myint → myint := _\nbegin \n  sorry\nend \n\ninstance : has_add myint :=\n{ add := add }\n\ndef mul : myint → myint → myint := _\nbegin\n  sorry\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₂ r s`, `quotient.induction_on₃ 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_\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/sheet10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7659830509371421}}
{"text": "/-\nCopyright (c) 2021 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 data.real.pi.wallis\n! leanprover-community/mathlib commit 980755c33b9168bc82f774f665eaa27878140fac\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.Integrals\n\n/-! # The Wallis formula for Pi\n\nThis file establishes the Wallis product for `π` (`real.tendsto_prod_pi_div_two`). Our proof is\nlargely about analyzing the behaviour of the sequence `∫ x in 0..π, sin x ^ n` as `n → ∞`.\nSee: https://en.wikipedia.org/wiki/Wallis_product\n\nThe proof can be broken down into two pieces. The first step (carried out in\n`analysis.special_functions.integrals`) is to use repeated integration by parts to obtain an\nexplicit formula for this integral, which is rational if `n` is odd and a rational multiple of `π`\nif `n` is even.\n\nThe second step, carried out here, is to estimate the ratio\n`∫ (x : ℝ) in 0..π, sin x ^ (2 * k + 1) / ∫ (x : ℝ) in 0..π, sin x ^ (2 * k)` and prove that\nit converges to one using the squeeze theorem. The final product for `π` is obtained after some\nalgebraic manipulation.\n\n## Main statements\n\n* `real.wallis.W`: the product of the first `k` terms in Wallis' formula for `π`.\n* `real.wallis.W_eq_integral_sin_pow_div_integral_sin_pow`: express `W n` as a ratio of integrals.\n* `real.wallis.W_le` and `real.wallis.le_W`: upper and lower bounds for `W n`.\n* `real.tendsto_prod_pi_div_two`: the Wallis product formula.\n -/\n\n\nopen Real Topology BigOperators Nat\n\nopen Filter Finset intervalIntegral\n\nnamespace Real\n\nnamespace Wallis\n\n/-- The product of the first `k` terms in Wallis' formula for `π`. -/\nnoncomputable def w (k : ℕ) : ℝ :=\n  ∏ i in range k, (2 * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3))\n#align real.wallis.W Real.Wallis.w\n\ntheorem w_succ (k : ℕ) :\n    w (k + 1) = w k * ((2 * k + 2) / (2 * k + 1) * ((2 * k + 2) / (2 * k + 3))) :=\n  prod_range_succ _ _\n#align real.wallis.W_succ Real.Wallis.w_succ\n\ntheorem w_pos (k : ℕ) : 0 < w k := by\n  induction' k with k hk\n  · unfold W\n    simp\n  · rw [W_succ]\n    refine' mul_pos hk (mul_pos (div_pos _ _) (div_pos _ _)) <;> positivity\n#align real.wallis.W_pos Real.Wallis.w_pos\n\ntheorem w_eq_factorial_ratio (n : ℕ) : w n = 2 ^ (4 * n) * n ! ^ 4 / ((2 * n)! ^ 2 * (2 * n + 1)) :=\n  by\n  induction' n with n IH\n  ·\n    simp only [W, prod_range_zero, Nat.factorial_zero, MulZeroClass.mul_zero, pow_zero,\n      algebraMap.coe_one, one_pow, mul_one, algebraMap.coe_zero, zero_add, div_self, Ne.def,\n      one_ne_zero, not_false_iff]\n  · unfold W at IH⊢\n    rw [prod_range_succ, IH, _root_.div_mul_div_comm, _root_.div_mul_div_comm]\n    refine' (div_eq_div_iff _ _).mpr _\n    any_goals exact ne_of_gt (by positivity)\n    simp_rw [Nat.mul_succ, Nat.factorial_succ, pow_succ]\n    push_cast\n    ring_nf\n#align real.wallis.W_eq_factorial_ratio Real.Wallis.w_eq_factorial_ratio\n\ntheorem w_eq_integral_sin_pow_div_integral_sin_pow (k : ℕ) :\n    (π / 2)⁻¹ * w k = (∫ x : ℝ in 0 ..π, sin x ^ (2 * k + 1)) / ∫ x : ℝ in 0 ..π, sin x ^ (2 * k) :=\n  by\n  rw [integral_sin_pow_even, integral_sin_pow_odd, mul_div_mul_comm, ← prod_div_distrib, inv_div]\n  simp_rw [div_div_div_comm, div_div_eq_mul_div, mul_div_assoc]\n  rfl\n#align real.wallis.W_eq_integral_sin_pow_div_integral_sin_pow Real.Wallis.w_eq_integral_sin_pow_div_integral_sin_pow\n\ntheorem w_le (k : ℕ) : w k ≤ π / 2 :=\n  by\n  rw [← div_le_one pi_div_two_pos, div_eq_inv_mul]\n  rw [W_eq_integral_sin_pow_div_integral_sin_pow, div_le_one (integral_sin_pow_pos _)]\n  apply integral_sin_pow_succ_le\n#align real.wallis.W_le Real.Wallis.w_le\n\ntheorem le_w (k : ℕ) : ((2 : ℝ) * k + 1) / (2 * k + 2) * (π / 2) ≤ w k :=\n  by\n  rw [← le_div_iff pi_div_two_pos, div_eq_inv_mul (W k) _]\n  rw [W_eq_integral_sin_pow_div_integral_sin_pow, le_div_iff (integral_sin_pow_pos _)]\n  convert integral_sin_pow_succ_le (2 * k + 1)\n  rw [integral_sin_pow (2 * k)]\n  simp only [sin_zero, zero_pow', Ne.def, Nat.succ_ne_zero, not_false_iff, MulZeroClass.zero_mul,\n    sin_pi, tsub_zero, Nat.cast_mul, Nat.cast_bit0, algebraMap.coe_one, zero_div, zero_add]\n#align real.wallis.le_W Real.Wallis.le_w\n\ntheorem tendsto_w_nhds_pi_div_two : Tendsto w atTop (𝓝 <| π / 2) :=\n  by\n  refine' tendsto_of_tendsto_of_tendsto_of_le_of_le _ tendsto_const_nhds le_W W_le\n  have : 𝓝 (π / 2) = 𝓝 ((1 - 0) * (π / 2)) := by rw [sub_zero, one_mul]\n  rw [this]\n  refine' tendsto.mul _ tendsto_const_nhds\n  have h : ∀ n : ℕ, ((2 : ℝ) * n + 1) / (2 * n + 2) = 1 - 1 / (2 * n + 2) :=\n    by\n    intro n\n    rw [sub_div' _ _ _\n        (ne_of_gt\n          (add_pos_of_nonneg_of_pos (mul_nonneg (two_pos : 0 < (2 : ℝ)).le (Nat.cast_nonneg _))\n            two_pos)),\n      one_mul]\n    congr 1\n    ring\n  simp_rw [h]\n  refine' (tendsto_const_nhds.div_at_top _).const_sub _\n  refine' tendsto.at_top_add _ tendsto_const_nhds\n  exact tendsto_coe_nat_at_top_at_top.const_mul_at_top two_pos\n#align real.wallis.tendsto_W_nhds_pi_div_two Real.Wallis.tendsto_w_nhds_pi_div_two\n\nend Wallis\n\nend Real\n\n/-- Wallis' product formula for `π / 2`. -/\ntheorem Real.tendsto_prod_pi_div_two :\n    Tendsto (fun k => ∏ i in range k, ((2 : ℝ) * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3)))\n      atTop (𝓝 (π / 2)) :=\n  Real.Wallis.tendsto_w_nhds_pi_div_two\n#align real.tendsto_prod_pi_div_two Real.tendsto_prod_pi_div_two\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/Wallis.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7659643689740576}}
{"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_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 ≡ 1 [MOD 7],\n  rw ←zmod.eq_iff_modeq_nat,\n  exact_mod_cast five_to_thirty_is_one,\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/p229.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947070591977, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7658982832024923}}
{"text": "import ..lectures.love02_backward_proofs_demo\n\n\n/-! # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nsorry\n\nlemma K (a b : Prop) :\n  a → b → b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nsorry\n\n/-! Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nsorry\n\n/-! 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nsorry\n\n/-! 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nsorry\n\nend backward_proofs\n\nnamespace existentials\n\n/-! ## Question 2: Existentials\n\nIn this section, you'll practice using `exists.intro` and `exists.elim`.\n-/\n\n#check @exists.intro\n#check @exists.elim\n\n/-! 2.1. Prove that we can \"flip\" the existential and universal quantifiers.\n(Note that this only works in one direction!)\n-/\n\nlemma website_icon {α β : Sort _} {p : α → β → Prop} :\n  (∃ a, ∀ b, p a b) → (∀ b, ∃ a, p a b) :=\nsorry\n\n/-! 2.2 Prove, using the definition of `isEven` below, that adding two to an\neven number gives another even number.\n-/\n\n-- Here is a definition and helper lemma for exercise 2.2\ndef isEven (n : ℕ) := ∃ k, n = 2 * k\nlemma add_two_eq (m n : ℕ) : m = n → m + 2 = n + 2 :=\ncongr_arg (λ x, x + 2)\n\n-- You may also find the following lemmas helpful:\n#check mul_add\n#check mul_one\n\nlemma even_add_two : ∀ n : ℕ, isEven n → isEven (n + 2) :=\nsorry\n\n/- 2.3. Prove that two consecutive natural numbers cannot be even.\n\nHints:\n* You can use `and.elim` to extract the two sides of a conjunction.\n* `eq.symm` reverses the sides of an equality.\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 ←h` (note the `←`).\n-/\naxiom no_odd_doubles : ∀ (n : ℕ), ¬ ∃ (m : ℕ), 2 * n = 2 * m + 1\n\nlemma no_consecutive_evens (n : ℕ) : ¬(isEven n ∧ isEven (n + 1)) :=\nsorry\n\nend existentials\n\nnamespace backward_proofs\n\n/-! ## Question 3: Natural Numbers\n\n3.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nsorry\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nsorry\n\n/-! 3.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nsorry\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nsorry\n\n/-! 3.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nsorry\n\n\n/-! ## Question 4 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle : Prop :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce : Prop :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation : Prop :=\n∀a : Prop, (¬¬ a) → a\n\n/-! For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, as this would defeat the purpose of the exercise.\n\n4.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nsorry\n\n/-! 4.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nsorry\n\n/-! We leave the remaining implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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/exercises/love02_backward_proofs_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851154320682, "lm_q2_score": 0.8947894724152068, "lm_q1q2_score": 0.7658066028405488}}
{"text": "/-\nCOMP2009-ACE\n\nExercise 04 (Bool)\n\n    This exercise has 2+1 parts. \n\n    The first part is \"logic chess\" which has slightly different rules\n    than logic poker but see below. The 2nd part asks you to define\n    implication on booleans and prove it correct. You are not supposed\n    to use classical logic for this exercise.\n\n    Part 1+2 count for 80% of the mark (40% each). If you think you should get\n    100% and are prepared to put a lot of extra effort in then try\n    part 3. But you have been warned. They will be no help with this\n    one.  \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, dsimp, contradiction, calc)\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-/\n\nnamespace ex04\n\ndef bnot : bool → bool \n| tt := ff\n| ff := tt \n\ndef band : bool → bool → bool \n| tt b := b\n| ff b := ff\n\ndef bor : bool → bool → bool \n| tt b := tt\n| ff b := b\n\nlocal notation x && y := band x y\nlocal notation x || y := bor x y\n\n/-\nPART I (40%)\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) ∀ x : bool, x=x\n\nthen you just go ahead and prove it -/\n\ntheorem chx0 : ∀ x : bool, x=x :=\nbegin\n  assume x,\n  reflexivity,\nend\n\n/- However, if the proposition is false, e.g.\n\nchx1) ∀ x : bool, x ≠ x\n\nthen  you prove its negation -/\n\ntheorem chx1 : ¬ (∀ x : bool, x ≠ x) :=\nbegin\n  assume h,\n  have g : tt ≠ 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) ∀ x : bool, bnot (bnot x) = x\nch02) ∀ x:bool,∃ y:bool, x ≠ y\nch03) ∃ x:bool,∀ y:bool, x ≠ y\nch04) ∀ x y : bool, x=y ∨ x ≠ y\nch05) ∃ x:bool, x=bnot x\nch06) ∀ x y z : bool, x=y ∨ x=z ∨ y=z\nch07) ∀ y:bool, ∃ x:bool, y = bnot x\nch08) ∀ x y : bool, bnot x = bnot y → x=y\nch09) ∃ b : bool, ∀ y:bool, b && y = y\nch10) ∃ b : bool, ∀ y:bool, b && y = b\n-/\n\n-- insert answer here\ntheorem ch01 : ∀ x : bool, bnot (bnot x) = x  :=\nbegin\n  assume x,\n  cases x,\n  refl,\n  refl,\nend\n\ntheorem ch02 : ∀ x:bool, ∃ y:bool, x ≠ y  :=\nbegin\n  assume x,\n  cases x,\n  existsi tt,\n  assume h,\n  contradiction,\n  existsi ff,\n  assume h2,\n  contradiction,\nend\n\ntheorem ch03 : ¬ (∃ x:bool,∀ y:bool, x ≠ y)  :=\n--to prove its negation\nbegin\n  assume x,\n  cases x with x h,\n  apply h,\n  reflexivity,\nend\n\ntheorem ch04: ∀ x y : bool, x=y ∨ x ≠ y :=\nbegin\n  assume x y,\n  cases x,\n  cases y,\n  left,\n  reflexivity,\n  right,\n  assume fftt,\n  contradiction,\n  \n  cases y,\n  right,\n  assume ttff,\n  contradiction,\n  left,\n  reflexivity,\nend\n\ntheorem ch05: ¬ (∃ x:bool, x = bnot x) :=\n--to prove negation\nbegin\n  assume h,\n  cases h with x h,\n  cases x,\n  dsimp[bnot] at h,\n  contradiction,\n  dsimp[bnot] at h,\n  contradiction,\nend\n\ntheorem ch06: ∀ x y z : bool, x=y ∨ x=z ∨ y=z :=\nbegin\n  assume x y z,\n  cases x,\n  cases y,\n  left,\n  reflexivity,\n\n  right,\n  cases z,\n  left,\n  reflexivity,\n\n  right,\n  reflexivity,\n\n  cases y,\n  cases z,\n  right,\n  right,\n  reflexivity,\n  \n  right,\n  left,\n  reflexivity,\n\n  left,\n  reflexivity,\nend\n\ntheorem ch07: ∀ y:bool, ∃ x:bool, y = bnot x :=\nbegin\n  assume y,\n  cases y,\n  existsi tt,\n  reflexivity,\n  existsi ff,\n  reflexivity,\nend\n\ntheorem ch08: ∀ x y : bool, bnot x = bnot y → x=y :=\nbegin\n  assume x y,\n  assume h,\n  cases x,\n  cases y,\n  reflexivity,\n  dsimp[bnot] at h,\n  rewrite h,\n\n  cases y,\n  dsimp[bnot] at h,\n  rewrite h,\n  reflexivity,\nend\n\ntheorem ch09: ∃ b : bool, ∀ y:bool, b && y = y :=\nbegin\n  existsi tt,\n  assume y,\n  dsimp [(&&),band],\n  refl,\nend\n\ntheorem ch10: ∃ b : bool, ∀ y:bool, b && y = b :=\nbegin\n  existsi ff,\n  assume y,\n  dsimp [(&&),band],\n  refl,\nend\n\n/- \nPART II (40%)\n=============\n\nDefine the operation \n\nimplb :   bool → bool → bool \n\nby pattern matching on bool and show that it corresponds to\nimplication on Prop, i.e. prove\n\ntheorem implb_ok : ∀ x y : bool , implb x y = tt ↔ (x = tt) → (y = tt) \n\n-/\n\n-- insert answer here\ndef implb : bool → bool → bool\n| tt y := y\n| ff y := tt\n\ntheorem implb_ok : ∀ x y : bool , implb x y = tt ↔ (x = tt) → (y = tt) :=\nbegin\n  assume x y,\n  constructor,\n  assume h1,\n  assume xtt,\n  cases x,\n  contradiction,\n\n  dsimp[implb] at h1,\n  exact h1,\n\n  assume xttytt,\n  cases x,\n  dsimp[implb],\n  reflexivity,\n\n  dsimp[implb],\n  apply xttytt,\n  reflexivity,\nend\n\n/-\nPART III (20%)\n==============\n\n(only for the criminally insane)\n\nProve the following theorem about functions  bool → bool.\n\nHint: Use \"cases e:b\" on a boolean expression b. This also adds\nequations \"e:b = tt\" and \"e:b = ff\" to the cases.\n\n-/\n\ntheorem weird : ∀ f : bool → bool, ∀ x:bool, f (f (f x)) = f x :=\nbegin\n  assume f,\n  assume x,\n  cases x,\n  cases g : f ff,\n  rewrite g,\n  exact g,\n\n  cases ftt: f tt,\n  exact g,\n\n  exact ftt,\n\n  cases o : f (f (f tt)),\n  cases r : f tt,\n  reflexivity,\n  rewrite ← o,\n  rewrite r,\n  rewrite r,\n  exact r,\n\n  cases t : f tt,\n  rewrite ← o,\n  rewrite t,\n  cases w : f ff,\n  exact w,\n  \n  rewrite t,\n  reflexivity,  \nend\n\nend ex04\n", "meta": {"author": "kyrran", "repo": "Lean", "sha": "915f45d695eb01a80e58916f03e8f7c1e878be8b", "save_path": "github-repos/lean/kyrran-Lean", "path": "github-repos/lean/kyrran-Lean/Lean-915f45d695eb01a80e58916f03e8f7c1e878be8b/ex04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8947894604912848, "lm_q1q2_score": 0.7658065860556813}}
{"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 `α`, 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 ≤ 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\nopen_locale pointwise\n\nnamespace set\n\nsection linear_order\n\nvariables {α : Type u} [linear_order α] {a a₁ a₂ b b₁ b₂ c x : α}\n\n/-- `interval a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. -/\ndef interval (a b : α) := Icc (min a b) (max a b)\n\nlocalized \"notation `[`a `, ` b `]` := set.interval a b\" in interval\n\n@[simp] lemma interval_of_le (h : a ≤ 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 ≤ a) : [a, b] = Icc b a :=\nby { rw [interval, min_eq_right h, max_eq_left h] }\n\nlemma interval_swap (a b : α) : [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 : ¬ a ≤ b) : [a, b] = Icc b a :=\ninterval_of_gt (lt_of_not_ge h)\n\nlemma interval_of_not_ge (h : ¬ b ≤ 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 ∈ [a, b] :=\nby { rw [interval, mem_Icc], exact ⟨min_le_left _ _, le_max_left _ _⟩ }\n\n@[simp] lemma right_mem_interval : b ∈ [a, b] :=\nby { rw interval_swap, exact left_mem_interval }\n\nlemma Icc_subset_interval : Icc a b ⊆ [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 ⊆ [a, b] :=\nby { rw interval_swap, apply Icc_subset_interval }\n\nlemma mem_interval_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [a, b] :=\nIcc_subset_interval ⟨ha, hb⟩\n\nlemma mem_interval_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [a, b] :=\nIcc_subset_interval' ⟨hb, ha⟩\n\nlemma not_mem_interval_of_lt (ha : c < a) (hb : c < b) : c ∉ interval a b :=\nnot_mem_Icc_of_lt $ lt_min_iff.mpr ⟨ha, hb⟩\n\nlemma not_mem_interval_of_gt (ha : a < c) (hb : b < c) : c ∉ interval a b :=\nnot_mem_Icc_of_gt $ max_lt_iff.mpr ⟨ha, hb⟩\n\nlemma interval_subset_interval (h₁ : a₁ ∈ [a₂, b₂]) (h₂ : b₁ ∈ [a₂, b₂]) : [a₁, b₁] ⊆ [a₂, b₂] :=\nIcc_subset_Icc (le_min h₁.1 h₂.1) (max_le h₁.2 h₂.2)\n\nlemma interval_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [a₁, b₁] ⊆ Icc a₂ b₂ :=\nIcc_subset_Icc (le_min ha.1 hb.1) (max_le ha.2 hb.2)\n\nlemma interval_subset_interval_iff_mem : [a₁, b₁] ⊆ [a₂, b₂] ↔ a₁ ∈ [a₂, b₂] ∧ b₁ ∈ [a₂, b₂] :=\niff.intro (λh, ⟨h left_mem_interval, h right_mem_interval⟩) (λ h, interval_subset_interval h.1 h.2)\n\nlemma interval_subset_interval_iff_le :\n  [a₁, b₁] ⊆ [a₂, b₂] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ :=\nby { rw [interval, interval, Icc_subset_Icc_iff], exact min_le_max }\n\nlemma interval_subset_interval_right (h : x ∈ [a, b]) : [x, b] ⊆ [a, b] :=\ninterval_subset_interval h right_mem_interval\n\nlemma interval_subset_interval_left (h : x ∈ [a, b]) : [a, x] ⊆ [a, b] :=\ninterval_subset_interval left_mem_interval h\n\n/-- A sort of triangle inequality. -/\nlemma interval_subset_interval_union_interval : [a, c] ⊆ [a, b] ∪ [b, c] :=\nbegin\n  rintro x hx,\n  obtain hac | hac := le_total a c,\n  { rw interval_of_le hac at hx,\n    obtain hb | hb := le_total x b,\n    { exact or.inl (mem_interval_of_le hx.1 hb) },\n    { exact or.inr (mem_interval_of_le hb hx.2) } },\n  { rw interval_of_ge hac at hx,\n    obtain hb | hb := le_total x b,\n    { exact or.inr (mem_interval_of_ge hx.1 hb) },\n    { exact or.inl (mem_interval_of_ge hb hx.2) } }\nend\n\nlemma bdd_below_bdd_above_iff_subset_interval (s : set α) :\n  bdd_below s ∧ bdd_above s ↔ ∃ a b, s ⊆ [a, b] :=\nbegin\n  rw [bdd_below_bdd_above_iff_subset_Icc],\n  split,\n  { rintro ⟨a, b, h⟩, exact ⟨a, b, λ x hx, Icc_subset_interval (h hx)⟩ },\n  { rintro ⟨a, b, h⟩, exact ⟨min a b, max a b, h⟩ }\nend\n\n/-- The open-closed interval with unordered bounds. -/\ndef interval_oc : α → α → set α := λ a b, Ioc (min a b) (max a b)\n\n-- Below is a capital iota\nlocalized \"notation `Ι` := set.interval_oc\" in interval\n\nlemma interval_oc_of_le (h : a ≤ b) : Ι a b = Ioc a b :=\nby simp [interval_oc, h]\n\nlemma interval_oc_of_lt (h : b < a) : Ι a b = Ioc b a :=\nby simp [interval_oc, le_of_lt h]\n\nlemma forall_interval_oc_iff  {P : α → Prop} :\n  (∀ x ∈ Ι a b, P x) ↔ (∀ x ∈ Ioc a b, P x) ∧ (∀ x ∈ Ioc b a, P x) :=\nby { dsimp [interval_oc], cases le_total a b with hab hab ; simp [hab] }\n\nend linear_order\n\nopen_locale interval\n\nsection ordered_add_comm_group\n\nvariables {α : Type u} [linear_ordered_add_comm_group α] (a b c x y : α)\n\n@[simp] lemma preimage_const_add_interval : (λ x, a + x) ⁻¹' [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 : (λ x, x + a) ⁻¹' [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 : (λ x, x - a) ⁻¹' [b, c] = [b + a, c + a] :=\nby simp [sub_eq_add_neg]\n\n@[simp] lemma preimage_const_sub_interval : (λ x, a - x) ⁻¹' [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 : (λ x, a + x) '' [b, c] = [a + b, a + c] :=\nby simp [add_comm]\n\n@[simp] lemma image_add_const_interval : (λ x, x + a) '' [b, c] = [b + a, c + a] :=\nby simp\n\n@[simp] lemma image_const_sub_interval : (λ x, a - x) '' [b, c] = [a - b, a - c] :=\nby simp [sub_eq_add_neg, image_comp (λ x, a + x) (λ x, -x)]\n\n@[simp] lemma image_sub_const_interval : (λ 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] ⊆ [a, b]) : |y - x| ≤ |b - a| :=\nbegin\n  rw [← max_sub_min_eq_abs, ← 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 ∈ [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 ∈ [a, b]) : |x - a| ≤ |b - a| :=\nabs_sub_le_of_subinterval (interval_subset_interval_left h)\n\n/-- If `x ∈ [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 ∈ [a, b]) : |b - x| ≤ |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 ≠ 0) (b c : k) :\n  (λ x, x * a) ⁻¹' [b, c] = [b / a, c / a] :=\n(lt_or_gt_of_ne ha).elim\n  (λ ha, by simp [interval, ha, ha.le, min_div_div_right_of_nonpos, max_div_div_right_of_nonpos])\n  (λ (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 ≠ 0) (b c : k) :\n  (λ x, a * x) ⁻¹' [b, c] = [b / a, c / a] :=\nby simp only [← preimage_mul_const_interval ha, mul_comm]\n\n@[simp] lemma preimage_div_const_interval (ha : a ≠ 0) (b c : k) :\n  (λ x, x / a) ⁻¹' [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) : (λ x, x * a) '' [b, c] = [b * a, c * a] :=\nif ha : a = 0 then by simp [ha] else\ncalc (λ x, x * a) '' [b, c] = (λ x, x * a⁻¹) ⁻¹' [b, c] :\n  (units.mk0 a ha).mul_right.image_eq_preimage _\n... = (λ x, x / a) ⁻¹' [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) : (λ 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) : (λ 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": "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/unordered_interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8947894597898776, "lm_q1q2_score": 0.7658065788756159}}
{"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 linear_algebra.free_module.finite.rank\n\n/-!\n# Rank of matrices\n\nThe rank of a matrix `A` is defined to be the rank of range of the linear map corresponding to `A`.\nThis definition does not depend on the choice of basis, see `matrix.rank_eq_finrank_range_to_lin`.\n\n## Main declarations\n\n* `matrix.rank`: the rank of a matrix\n\n## TODO\n\n* Show that `matrix.rank` is equal to the row-rank and column-rank\n* Generalize away from fields\n\n-/\n\nopen_locale matrix\n\nnamespace matrix\n\nopen finite_dimensional\n\nvariables {m n o K : Type*} [m_fin : fintype m] [fintype n] [fintype o]\nvariables [decidable_eq n] [decidable_eq o] [field K]\nvariables (A : matrix m n K)\n\n/-- The rank of a matrix is the rank of its image. -/\nnoncomputable def rank : ℕ := finrank K A.to_lin'.range\n\n@[simp] lemma rank_one : rank (1 : matrix n n K) = fintype.card n :=\nby rw [rank, to_lin'_one, linear_map.range_id, finrank_top, module.free.finrank_pi]\n\n@[simp] lemma rank_zero : rank (0 : matrix n n K) = 0 :=\nby rw [rank, linear_equiv.map_zero, linear_map.range_zero, finrank_bot]\n\nlemma rank_le_card_width : A.rank ≤ fintype.card n :=\nbegin\n  convert nat.le_of_add_le_left (A.to_lin'.finrank_range_add_finrank_ker).le,\n  exact (module.free.finrank_pi K).symm,\nend\n\nlemma rank_le_width {m n : ℕ} (A : matrix (fin m) (fin n) K) : A.rank ≤ n :=\nA.rank_le_card_width.trans $ (fintype.card_fin n).le\n\nlemma rank_mul_le (B : matrix n o K) : (A ⬝ B).rank ≤ A.rank :=\nbegin\n  refine linear_map.finrank_le_finrank_of_injective (submodule.of_le_injective _),\n  rw [to_lin'_mul],\n  exact linear_map.range_comp_le_range _ _,\nend\n\nlemma rank_unit (A : (matrix n n K)ˣ) :\n  (A : matrix n n K).rank = fintype.card n :=\nbegin\n  refine le_antisymm (rank_le_card_width A) _,\n  have := rank_mul_le (A : matrix n n K) (↑A⁻¹ : matrix n n K),\n  rwa [← mul_eq_mul, ← units.coe_mul, mul_inv_self, units.coe_one, rank_one] at this,\nend\n\nlemma rank_of_is_unit (A : matrix n n K) (h : is_unit A) :\n  A.rank = fintype.card n :=\nby { obtain ⟨A, rfl⟩ := h, exact rank_unit A }\n\ninclude m_fin\n\nlemma rank_eq_finrank_range_to_lin\n  {M₁ M₂ : Type*} [add_comm_group M₁] [add_comm_group M₂]\n  [module K M₁] [module K M₂] (v₁ : basis m K M₁) (v₂ : basis n K M₂) :\n  A.rank = finrank K (to_lin v₂ v₁ A).range :=\nbegin\n  let e₁ := (pi.basis_fun K m).equiv v₁ (equiv.refl _),\n  let e₂ := (pi.basis_fun K n).equiv v₂ (equiv.refl _),\n  have range_e₂ : (e₂ : (n → K) →ₗ[K] M₂).range = ⊤,\n  { rw linear_map.range_eq_top, exact e₂.surjective },\n  refine linear_equiv.finrank_eq (e₁.of_submodules _ _ _),\n  rw [← linear_map.range_comp, ← linear_map.range_comp_of_range_eq_top (to_lin v₂ v₁ A) range_e₂],\n  congr' 1,\n  apply linear_map.pi_ext', rintro i, apply linear_map.ext_ring,\n  have aux₁ := to_lin_self (pi.basis_fun K n) (pi.basis_fun K m) A i,\n  have aux₂ := basis.equiv_apply (pi.basis_fun K n) i v₂,\n  rw [to_lin_eq_to_lin'] at aux₁,\n  rw [pi.basis_fun_apply, linear_map.coe_std_basis] at aux₁ aux₂,\n  simp only [linear_map.comp_apply, e₁, e₂, linear_equiv.coe_coe, equiv.refl_apply, aux₁, aux₂,\n    linear_map.coe_single, to_lin_self, linear_equiv.map_sum, linear_equiv.map_smul,\n    basis.equiv_apply],\nend\n\nlemma rank_le_card_height : A.rank ≤ fintype.card m :=\n(submodule.finrank_le _).trans (module.free.finrank_pi K).le\n\nomit m_fin\n\nlemma rank_le_height {m n : ℕ} (A : matrix (fin m) (fin n) K) : A.rank ≤ m :=\nA.rank_le_card_height.trans $ (fintype.card_fin m).le\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/rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.765786222384991}}
{"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–Hamilton 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] (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] [fintype n] (M : matrix n n R) (i : n) : char_matrix M i i = polynomial.X - coe_fn polynomial.C (M i i) := sorry\n\n@[simp] theorem char_matrix_apply_ne {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n] [fintype n] (M : matrix n n R) (i : n) (j : n) (h : i ≠ j) : char_matrix M i j = -coe_fn polynomial.C (M i j) := sorry\n\ntheorem mat_poly_equiv_char_matrix {R : Type u} [comm_ring R] {n : Type w} [DecidableEq n] [fintype n] (M : matrix n n R) : coe_fn mat_poly_equiv (char_matrix M) = polynomial.X - coe_fn polynomial.C M := 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] (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] (M : matrix n n R) : coe_fn (polynomial.aeval M) (char_poly M) = 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/linear_algebra/char_poly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7657862108160308}}
{"text": "import tactic\nimport data.nat.prime\nimport topology.continuous_function.compact\n\n/-!\n\n∀\n∀ x : ℕ, x = 37\n-/\n\n#check ∀ x : ℕ, x = 37\n\nlemma easy : 2 + 2 = 4 :=\nbegin\n  norm_num,\nend\n\n#check 2 + 2 = 4\n#check easy\n\n/-!\n# Infinte unions\n\nWant to do ⋃ A₁, A₂, ... are all sets\nand i is a natural\n-/\n\nvariable (X : Type)\nvariables (U V : set X)\n\n#check U \n#check U ∪ V\n#print notation ∪\n#print notation ⋃\n\nvariable (A : ℕ → set X)\n\n#check A(0)\n -- want to take union of all the A(i)\n#check ⋃ (i : ℕ), A i\n\nvariable (B : ℕ → ℕ → set X)\n\n-- set_option pp.notation false (to disable unicode notation)\n#check ⋃ (i : ℕ), ⋃ (j : ℕ), B i j\n#check ⋃ (i : ℕ) (j : ℕ), B i j\n#check ⋃ (i j : ℕ), B i j\n\n#check nat.prime\n#check nat.prime 6\n\ndef primes : Type := {n : ℕ // nat.prime n} -- // creates a dependent pair\ndef primes_set : set ℕ  := {n : ℕ | nat.prime n}\n\nvariables (x : primes)\n#check x.1\n#check x.2\n\ndef two : primes := ⟨2, begin\n  exact nat.prime_two,\nend⟩\n\nexample : 2 ∈ primes_set :=\nbegin\n  unfold primes_set,\n  dsimp, -- definition simplification\n  exact nat.prime_two,\nend\n\n#check ⋃ (p: primes), A (p.1)\n#check ⋃ (p ∈ primes_set), A p --- exciting new development\n-- ⋃ (p ∈ S), ... works!\n\n#check set.mem_bUnion\n\nexample (a : X) : a ∈ (⋃(i : ℕ), A i) ↔ ∃ j, a ∈ A j :=\nbegin\n  exact set.mem_Union, -- key fact for unions\nend\n\nexample (a : X) : a ∈ (⋃ (p ∈ primes_set), A p) ↔ ∃ p : ℕ, nat.prime p ∧ a ∈ A p :=\nbegin\n  rw set.mem_Union,\n  simp_rw set.mem_Union,\n  split,\n    --intro h,\n    --cases h with i hi,\n    --cases hi with h1 h2,\n    --use i,\n    --split,\n    --  exact h1, exact h2,\n    { \n      rintro ⟨i, h1, h2⟩,\n      exact ⟨i, h1, h2⟩\n    },\n--  unfold primes_set,\n  {sorry}\nend\n\n\n\n\n/-!\n## Second hour\nThings to know\n\nWell I'm now rep for the class\n\nOpenAI have been in touch with Buzzard, and want to give money\nfor people who formalise olympid questions on the Xena dicord\n\nCheck on Twitter of OpenAI for link to blog\n\nAnd Meta (Facebook) want our emai;l address to have a meeting where they show off\ntheir extension for VSCode to guess the next line of a Lean \n\nPDF where fine for the project\n\nCan Buzzard share the projects for:\n- next year students\n- to the world\n\n\nAnd NOW\n## Topology\ncheck the sheets of the formalising course (section 7)\n\n -/\n\n-- Let X be a topologycal space\nvariables (Z : Type) [topological_space X]\n\n\n\n\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-15session-hour1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122263731811, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7656763425431123}}
{"text": "import data.set\nopen set\n/-\nNOTE: The final exam is comprehensive, but this practice\nexam is not. In addition to working through this practice\nexam, you should revisit the exam1 and exam2 practice\nexams.\n-/\n\n/- SETS -/\nnamespace sets\n\n/-\n1.\n\nProve that 1 is in the set {1, 2, 3, 4, 5}.\n-/\n\nexample: 1 ∈ ({1, 2, 3, 4, 5}: set ℕ) :=\nbegin\n  right, right, right, right, left,\n  exact rfl,\nend\n\n/-\n2.\n\nProve that 1 is not in the set {2, 3, 4}.\n-/\n\nexample: 1 ∉ ({2, 3, 4}: set ℕ) :=\nbegin\n  assume pf_in,\n  cases pf_in with one_is_4 pf_in,\n    -- case with hypothesis 1 = 4\n    have one_isnt_4: 1 ≠ 4 := dec_trivial,\n    exact one_isnt_4 one_is_4,\n    -- case with hypothesis 1 ∈ {2, 3}\n    cases pf_in with one_is_3 pf_in,\n      -- case with hypothesis 1 = 3\n      have one_isnt_3: 1 ≠ 3 := dec_trivial,\n      exact one_isnt_3 one_is_3,\n      -- case with hypothesis 1 ∈ {2}\n      cases pf_in with one_is_2 pf_in,\n        -- case with hypothesis 1 = 2\n        have one_isnt_2: 1 ≠ 2 := dec_trivial,\n        exact one_isnt_2 one_is_2,\n        -- case with hypothesis 1 ∈ ∅\n        assumption\nend\n\n/-\n3.\n\nProve that there does not exist any natural number that is\na member of the empty set of natural numbers.\n-/\n\nexample: ¬(∃ n:ℕ, n ∈ (∅: set ℕ)) :=\nbegin\n  assume pf_exists_n,\n  apply exists.elim pf_exists_n,\n  assume w pf_w_in_empty,\n  assumption\nend\n\n/-\n4.\n\nProve that the intersection of the sets of natural numbers\n{1, 2} and {3, 4} is empty by showing that for all natural\nnumbers, they are not in the intersection of {1, 2} and\n{3, 4}.\n-/\n\n#reduce 2 ∈ ({3, 4}: set ℕ)\n\nexample: ∀n: ℕ, n ∉ ({1, 2}: set ℕ) ∩ ({3, 4}: set ℕ) :=\nbegin\n  intros n,\n  assume pf_n_in_intersection,\n  cases pf_n_in_intersection with pf_n_in_12 pf_n_in_34,\n    cases pf_n_in_12 with pf_n_is_2 pf_n_in_1,\n      rw pf_n_is_2 at pf_n_in_34,\n      cases pf_n_in_34 with pf_2_is_4 pf_2_in_3,\n        have pf_2_isnt_4: 2 ≠ 4 := dec_trivial,\n        exact pf_2_isnt_4 pf_2_is_4,\n\n        cases pf_2_in_3 with pf_2_is_3 pf_2_in_empty,\n          have pf_2_isnt_3: 2 ≠ 3 := dec_trivial,\n          exact pf_2_isnt_3 pf_2_is_3,\n\n          assumption,\n\n      cases pf_n_in_1 with pf_n_is_1 pf_n_in_empty,\n        rw pf_n_is_1 at pf_n_in_34,\n        cases pf_n_in_34 with pf_1_is_4 pf_1_in_3,\n          have pf_1_isnt_4: 1 ≠ 4 := dec_trivial,\n          exact pf_1_isnt_4 pf_1_is_4,\n\n          cases pf_1_in_3 with pf_1_is_3 pf_1_in_empty,\n            have pf_1_isnt_3: 1 ≠ 3 := dec_trivial,\n            exact pf_1_isnt_3 pf_1_is_3,\n\n            assumption,\n        \n        assumption,\nend\n\n/-\n5.\n\nProve that 1 is in the difference between {1, 2, 3} and {3, 4}\n-/\n\nexample: 1 ∈ ({1, 2, 3}: set ℕ) \\ ({3, 4}: set ℕ) :=\nbegin\n  split,\n    right, right, left,\n    exact rfl,\n\n    assume pf_1_in_34,\n    cases pf_1_in_34 with pf_1_is_4 pf_1_in_3,\n      have pf_1_isnt_4: 1 ≠ 4 := dec_trivial,\n      exact pf_1_isnt_4 pf_1_is_4,\n\n      cases pf_1_in_3 with pf_1_is_3 pf_1_in_empty,\n        have pf_1_isnt_3: 1 ≠ 3 := dec_trivial,\n        exact pf_1_isnt_3 pf_1_is_3,\n\n        assumption,\nend\n\n/-\n6.\n\nProve that {2, 3} is a subset of the union of {1, 2} and {3, 4}\nNote: use ⊆ not ⊂\n-/\n\nexample: ({2, 3}: set ℕ) ⊆ ({1, 2}: set ℕ) ∪ ({3, 4}: set ℕ) :=\nbegin\n  intros a,\n  assume pf_a_in_23,\n  cases pf_a_in_23 with pf_a_is_3 pf_a_in_2,\n    apply or.inr,\n    right, left, assumption,\n\n    cases pf_a_in_2 with pf_a_is_2 pf_false,\n      apply or.inl,\n      left, assumption,\n\n      exact false.elim pf_false,\nend\n\n/-\n7.\n\nProve that {2, 3} is an element of the powerset of {1, 2, 3, 4}\n-/\n\n#reduce {2, 3} ∈ 𝒫({1, 2, 3, 4}: set ℕ)\n-- ∀ ⦃a : ℕ⦄, a = 3 ∨ a = 2 ∨ false → a = 4 ∨ a = 3 ∨ a = 2 ∨ a = 1 ∨ false\n\nexample: {2, 3} ∈ 𝒫({1, 2, 3, 4}: set ℕ) :=\nbegin\n  change ∀(a : ℕ), a = 3 ∨ a = 2 ∨ false → a = 4 ∨ a = 3 ∨ a = 2 ∨ a = 1 ∨ false,\n  intros a,\n  assume pf_a_in_23,\n  cases pf_a_in_23 with pf_a_is_3 pf_a_in_2,\n    right, left, assumption,\n\n    cases pf_a_in_2 with pf_a_is_2 pf_false,\n      right, right, left, assumption,\n      exact false.elim pf_false,\nend\n\nend sets\n\n/- RELATIONS -/\nnamespace relations\n\n/-\n1.\n\nProve that disjunction has the symmetric property\n-/\n\nexample: symmetric or :=\nbegin\n  unfold symmetric,\n  intros x y,\n  assume pf_x_or_y,\n  cases pf_x_or_y with pf_x pf_y,\n    exact or.inr pf_x,\n    exact or.inl pf_y\nend\n\n/-\n2.\n\nProve that conjunction is a subrelation of disjunction\n-/\n\nexample: subrelation and or :=\nbegin\n  unfold subrelation,\n  intros x y,\n  assume pf_x_and_y,\n  have pf_x := and.elim_left pf_x_and_y,\n  exact or.inl pf_x,\nend\n\nend relations\n\n/-\n===================================================\nInductive types, functions, properties, and proofs.\n====================================================\n-/\n\n/-\n1.\n\nCreate sub_mynat that subtracts two mynats n and m with\nthe condition that if m > n that it returns 0, otherwise\nit returns n - m\nHint: 3 - 2 = 2 - 1 = 1 - 0\n-/\n\nnamespace mynat\n\ninductive mynat : Type \n| zero : mynat\n| succ : mynat → mynat\n\ndef sub_mynat: mynat → mynat → mynat\n| n mynat.zero := n\n| mynat.zero m := mynat.zero\n| (mynat.succ n') (mynat.succ m') := \n    sub_mynat n' m'\n\n/-\n2.\n\nProve that ∀ n, sub_mynat n n = 0.\n-/\n\nexample: ∀(n: mynat), sub_mynat n n = mynat.zero :=\nbegin\n  intros n,\n  induction n with n' h,\n    -- base case\n    simp [sub_mynat],\n\n    simp [sub_mynat],\n    assumption\nend\n\n/-\n3.\n\nWe give you a copy of the add_mynat function\nbelow. Show that our definition of add_mynat \nis associative. \n-/\n\ndef add_mynat: mynat → mynat → mynat\n| mynat.zero m := m\n| (mynat.succ n') m :=\n    mynat.succ (add_mynat n' m)\n\nexample: ∀(a b c: mynat),\n  add_mynat a (add_mynat b c) = add_mynat (add_mynat a b) c :=\nbegin\n  intros a b c,\n  induction a with a' h,\n    -- base case\n    simp [add_mynat],\n\n    have h': add_mynat (mynat.succ a') (add_mynat b c) =\n      mynat.succ (add_mynat a' (add_mynat b c)) :=\n        begin\n          simp [add_mynat],\n        end,\n\n    have h'': add_mynat (mynat.succ a') b =\n      mynat.succ (add_mynat a' b) :=\n        begin\n          simp [add_mynat],\n        end,\n    \n    rw h',\n    rw h'',\n\n    have h''': add_mynat (mynat.succ (add_mynat a' b)) c =\n      mynat.succ (add_mynat (add_mynat a' b) c):=\n        begin\n          simp [add_mynat],\n        end,\n    \n    rw h''',\n    rw h,\nend\n\nend mynat\n\n\n\n/-\nSimple inductive types.\n-----------------------\n-/\n\n/-\n3.\n\nDefine a new type called day having\nthese seven constant constructors: \nsunday, monday, tuesday, wednesday,\nthursday, friday, saturday. We will\ninterpret these constructors as \nrepresenting the actual days of the\nweek. Write your code below here now.\n-/\n\ninductive day : Type\n| sunday\n| monday\n| tuesday\n| wednesday\n| thursday\n| friday\n| saturday\n\n-- We suggest you open the day namespace\n\nopen day\n\n\n/-\n4.\n\nDefine a function, nextday : day → day,\nthat, when given a value, d : day, returns \nthe day value that represents the next day\nof the week. Hint: either write a function\nusing a match d with ... end, or, if you\ncan use a tactic script (to write code!).\nUse cases d and for each possible case of\nd, specify the exact day to be returned in\nthat case. For extra credit do it both ways\nand write a single sentence to describe how\nthese two representations correspond.\n-/\n\ndef nextday (d : day) : day :=\nbegin\n  cases d,\n    exact monday,\n    exact tuesday,\n    exact wednesday,\n    exact thursday,\n    exact friday,\n    exact saturday,\n    exact sunday,\nend\n\n\ndef nextday' (d : day) :=\nmatch d with\n| sunday := monday\n| monday := tuesday\n| tuesday := wednesday\n| wednesday := thursday\n| thursday := friday\n| friday := saturday\n| saturday := sunday\nend\n\n/-\n5.\n\nFormalize and prove the proposition that \nfor any day, d, if you apply nextday to d\nthen nextday to the result, seven times, \nthe result is that very same d. \n-/\n\nexample : ∀ d : day, \nnextday ( nextday ( nextday (nextday (nextday (nextday (nextday d)))))) = d :=\nbegin\n  assume d,\n  cases d,\n  repeat { apply rfl }, -- don't write it 7 times!\nend\n\n\n\n/-\nRecursive (nested) inductive types.\n-----------------------------------\n-/\n\n/-\n6.\n\nGive an inductive type definition for nat_list,\nso that values of this type represent lists of\nvalues of type ℕ.\n\nWhile there's an infinity of such lists, we can\ncleverly define the set inductively with just two\nrules.\n\nFirst, there is an empty list of natural numbers. We will represent it with the constant constructor, \nnil_nat. Make it one of the nat_list constructors.\n\nSecond, if we are given a nat_list value, l, and \na ℕ value, e : ℕ, we can always construct a list\nthat is one longer than by prepending e to l. To\ndo this, define a constructor called nat_cons. It take arguments, e : ℕ and l : ₤st_nat, and yield a \nnat_list.\n-/\n\ninductive nat_list : Type \n| nat_nil : nat_list\n| nat_cons : ℕ → nat_list → nat_list \n\n-- we suggest you open the nat_list namespace\n\nopen nat_list\n\n\n/-\n7.\n\nDefine X to be the nat_list value that we\ninterpret as representing the empty list of\nnatural numbers, []; Y to be the nat_list \nvalue that represents the list, [1]; and\nfinally Z to represent the list, [2, 1].\n-/\n\ndef X := nat_nil\ndef Y := (nat_cons 1 nat_nil)\ndef Z := (nat_cons 2 Y)\n\n\n/-\n8.\n\nDefine a function (it will be recursive)\nthat takes any nat_list value and that\nreturns its length (a natural number that\nindicates how many values are in the list). \nCall the function, length.\n\nThe challenge is to see the recursion in \nthe definition of the length of a list.\nHint questions: What is the length of the\nempty list? What is the length of a list\nthat is not empty, and that thus must be\nof the form (nat_cons h t), where h is the\nvalue at the head of the list and t is the\nrest of the list.\n-/\n\n\ndef length : nat_list → ℕ \n| nat_nil := 0\n| (nat_cons h t) := 1 + length t\n\n\n/-\nThe stuff that follows is challenging\nGet solid on the basic stuff before \ngoing here.\n-/\n\n/-\n9.\n\nDefine a function, app (short for \"append\"), \nthat takes two nat_list values, let's call them\nl1 and l2, and that returns the nat_list with \nthe elements of the first list followed by the\nelements of the second list. For example, \n(app Y Z) should return the list [1, 2, 1].\n\nHint: Consider the possible forms of l1. It \ncan only be either nat_nil or (nat_cons h t),\nwhere, once again, h is is first element in \nl1, and t is the rest of the list. Write the \nfunction recursively accordingly.\n-/\n\ndef app : nat_list → nat_list → nat_list\n| nat_nil l2 := l2\n| (nat_cons h t) l2 := nat_cons h (app t l2)\n\n\n/-\n10.\n\nProve the following\n\n∀ l1 l2 : nat_list, \n(length l1 + length l2) = length (append l1 l2)\n\nHint: use proof by induction on l1. There will be\ntwo cases. In the first, l1 will be nat_nil, and\nits length will reduce directly to 0. In the second\ncase, you will show that the property is true for a\nnext bigger list: one in the form of (nat_cons h t).\n-/\n\nexample : ∀ l1 l2 : nat_list, \n(length l1 + length l2) = \nlength (app l1 l2) :=\nbegin\n  intros l1 l2,\n  induction l1 with l1' n h,\n    -- base case\n    -- simplify using rules in app and length defs\n    simp [app],\n    simp [length],\n\n    -- inductive case\n    -- simplify using app and length rules in one line\n    simp [app,length],\n    -- now use induction hypothesis to rewrite goal\n    rw <-h,\n    -- and the rest is simple arithmetic manipulation\n    simp,\n    --rw \nend\n\n/- Formal Languages -/\n\nnamespace formal\n/-\n1.\n\nExtend the following formal language to incorporate \"or\"\n-/\n\ninductive pVar : Type \n| mk : ℕ → pVar\n\ninductive pExp : Type\n| mk_lit_pexp : bool → pExp\n| mk_var_pexp : pVar → pExp\n| mk_not_pexp : pExp → pExp\n| mk_and_pexp : pExp → pExp → pExp\n-- ADD THIS\n| mk_or_pexp :  pExp → pExp → pExp\n\nopen pExp\n\ndef pInterp := pVar → bool\n\ndef pEval : pExp → pInterp → 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-- AND ADD THIS\n| (mk_or_pexp e1 e2) i := \n    bor (pEval e1 i) (pEval e2 i)\n\nend formal\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/exam3-practice-key.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.874077222043951, "lm_q1q2_score": 0.7655054664294175}}
{"text": "import game.order.level02\n\nnamespace xena -- hide\n\n/-\n# Chapter 2 : Order\n\n## Level 3\n\nAnother 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| ≤ c ↔ -c ≤ a ≤ c$$.\n-/\ntheorem abs_le (a c : ℝ) (h : 0 ≤ c): |a| ≤ c ↔ (-c) ≤ a ∧ a ≤ c :=\nbegin\n    split,\n    intro j,\n    rcases lt_trichotomy a 0 with han | haz | hap,\n    swap,\n    rw haz,\n    split,\n    linarith,\n    exact h,\n    split,\n    have h1 : | a | = - a, exact abs_of_neg han,\n    rw h1 at j,\n    linarith,\n    linarith,\n    split,\n    have h2 : | a | = a, exact abs_of_pos hap,\n    rw h2 at j,\n    linarith,\n    have h2 : | a | = a, exact abs_of_pos hap,\n    rw h2 at j,\n    exact j,\n    intro k,\n    cases k with d hd,\n    rcases lt_trichotomy a 0 with han | haz | hap,\n    have h1 : | a | = - a, exact abs_of_neg han,\n    rw h1,\n    linarith,\n    rw haz,\n    norm_num,\n    exact h,\n    have h1 : | a | = a, exact abs_of_pos hap,\n    rw h1,\n    linarith,\nend\n\nend xena --hide\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/-\nsplit,\n    rcases lt_trichotomy a 0 with haNeg | haZero | haPos,\n    { -- case a < 0\n        intro H, \n        have h1 : | a | = - a, exact abs_of_neg haNeg,\n        rw h1 at H, split, linarith, linarith,\n    },\n    { -- case a = 0\n        intro H, rw haZero, split, linarith, exact h,\n    },\n    { -- case 0 < a\n        intro H,\n        have h1 : |a| = a, exact abs_of_pos haPos,\n        rw h1 at H, split, linarith, exact H,\n    },\n    \n    \n    rcases lt_trichotomy a 0 with haNeg | haZero | haPos,\n    { -- case a < 0\n        intro H, \n        have h1 : | a | = - a, exact abs_of_neg haNeg,\n        rw abs_le, \n        exact H,\n    },\n    { -- case a = 0\n        intro H,\n        rw abs_le, exact H,\n    },\n    { -- case 0 < a\n        intro H,\n        rw abs_le, exact H,\n    },\n    \n\n    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/level03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.7655054664294173}}
{"text": "import order.filter.basic\n\n/-\n\n# tendsto\n\nHere's an overview of the main definition we're learning today.\n\nIf `X` and `Y` are types, `φ : X → Y` is a function,\nand `F : filter X` and `G : filter Y` are filters, then\n\n`filter.tendsto φ F G`\n\nis a true-false statement, which is pronounced something like\n\"`F` tends to `G` along `φ`\". Of course we will `open filter`\nin this file, so you can just write `tendsto φ F G`, or if\nyou like the dot notation you can even write `F.tendsto φ G`.\n\n## Geometric meaning of `tendsto`.\n\nLet's start by thinking about the easy case where `F` and `G`\nare actually subsets of `X` and `Y` (that is, principal filters,\nassociated to sets which we will also call `F` and `G`). In this case,\n`tendsto φ F G` simply means \"`φ` restricts to a function\nfrom `F` to `G`\", or in other words `∀ x ∈ F, φ(x) ∈ G`.\n\nThere are two other ways of writing this predicate. The first\ninvolves pushing a set forward along a map. If `F` is a subset of `X`\nthen let `φ(F)` denote the image of `F` under `φ`, that\nis, the subset `{y : Y | ∃ x : X, φ x = y}` of `Y`.\nThen `tendsto φ F G` simply means `φ(F) ⊆ G`.\n\nThe second involves pulling a set back along a map. If `G` is a subset\nof `Y` then let `φ⁻¹(G)` denote the preimage of `G` under `φ`,\nthat is, the subset `{x : X | φ x ∈ G}` of `Y`. Then `tendsto φ F G`\nsimply means `F ⊆ φ⁻¹(G)`. \n\nThis is how it all works in the case of sets. What we need to\ndo today is to figure out how to push forward and pull back\nfilters along a map `φ`. Once we have done this, then we can\nprove `φ(F) ≤ G ↔ F ≤ φ⁻¹(G)` and use either one of these\nas our definition of `tendsto φ F G` -- it doesn't matter which.\n\n## Digression : adjoint functors.\n\nThe discussion below is not needed to be able to do this week's\nproblems, but it might provide some helpful background for some.\nAlso note that anyone who still doens't like the word \"type\" can\nliterally just change it for the word \"set\" (and change \"term of\ntype\" to \"element of set\"), which is how arguments\nof the below kind would appear in the traditional mathematical\nliterature.\n\nPartially ordered types, such as the type of subsets of a fixed\ntype `X` or the type of filters on `X`, are actually very simple\nexamples of categories. In general if `P` is a partially ordered type\nand `x,y` are terms of type `P` then the idea is that we can\ndefine `Hom(x,y)` to have exactly one element if `x ≤ y` is true,\nand no elements at all if `x ≤ y` is false. The structure/axioms for\na category are that `Hom(x,x)` is supposed to have an identity\nelement, which follows from reflexivity of `≤`, and that one can\ncompose morphisms, which follows from transitivity of `≤`.\nAntisymmetry states that if two objects are isomorphic (i.e.,\nin this case, if `Hom(x,y)` and `Hom(y,x)` are both nonempty),\nthen they are equal. If `φ : X → Y` is a map of types, then\npushing forward subsets and pulling back subsets are both\nfunctors from `set X` to `set Y`, because `S ⊆ T → φ(S) ⊆ φ(T)`\nand `U ⊆ V → φ⁻¹(U) ⊆ φ⁻¹(V)`. The statement that\n`φ(S) ≤ U ↔ S ≤ φ⁻¹(U)` is simply the statement that these functors\nare adjoint to each other. Today we will define pushforward and\npullback of filters, and show that they are also a pair of\nadjoint functors, but we will not use this language. In fact there\nis a special language for adjoint functors in this simple situation:\nwe will say that pushforward and pullback form a Galois connection.\n\n-/\n\n/-\n\n## Warm-up: pushing forward and pulling back subsets.\n\nSay `X` and `Y` are types, and `f : X → Y`.\n\n-/\n\nvariables (X Y : Type) (f : X → Y)\n\n/-\n\n### images\n\nIn Lean, the image `f(S)` of a subset `S : set X` cannot\nbe denoted `f S`, because `f` expects an _element_ of `X` as\nan input, not a subset of `X`, so we need new notation.\n\nNotation : `f '' S` is the image of `S` under `f`. Let's\ncheck this.\n\n-/\n\nexample (S : set X) : f '' S = {y : Y | ∃ x : X, x ∈ S ∧ f x = y} :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-\n\n### preimages\n\nIn Lean, the preimage `f⁻¹(T)` of a subset `T : set Y` cannot\nbe denoted `f⁻¹ T` because `⁻¹` is the inverse notation in group\ntheory, so if anything would be a function from `Y` to `X`,\nnot a function on subsets of `Y`. \n\nNotation : `f ⁻¹' T` is the preimage of `T` under `f`. Let's\ncheck this.\n\nPro shortcut: `\\-'` for `⁻¹'` \n\n-/\n\nexample (T : set Y) : f ⁻¹' T = {x : X | f x ∈ T} :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-\n\nI claim that the following conditions on `S : set X` and `T : set Y`\nare equivalent:\n\n1) `f '' S ⊆ T`\n2) `S ⊆ f⁻¹' T`\n\nIndeed, they both say that `f` restricts to a function from `S` to `T`.\nLet's check this. You might find\n\n`mem_preimage : a ∈ f ⁻¹' s ↔ f a ∈ s`\n\nand \n\n-/\n\nopen set\n\nexample (S : set X) (T : set Y) : f '' S ⊆ T ↔ S ⊆ f⁻¹' T :=\nbegin\n  sorry,\nend\n\n/-\n\n## Pushing forward filters.\n\nPushing forward is easy, so let's do that first.\nIt's called `filter.map` in Lean.\n\nWe define the pushforward filter `map f F` on `Y` to be the\nobvious thing: a subset of `Y` is in the filter iff `f⁻¹(Y)`\nis in `F`. Let's check this is a filter.  \n\nReminder of some helpful lemmas:\n\nIn `set`:\n`mem_set_of_eq : a ∈ {x : α | p x} = p a` -- definitional\n\nIn `filter`:\n`univ_mem_sets : univ ∈ F`\n`mem_sets_of_superset : S ∈ F → S ⊆ T → T ∈ F`\n`inter_mem_sets : S ∈ F → T ∈ F → S ∩ T ∈ F`\n\n-/\n\nopen filter\n\n-- this is called `F.map f` or `filter.map f F` \n-- or just `map f F` if `filter` is open.\nexample (F : filter X) : filter Y :=\n{ sets := {T : set Y | f ⁻¹' T ∈ F },\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-- this is `filter.mem_map` and it's true by definition.\n-- It's useful in the form `rw mem_map` if you want to figure out\n-- what's going on in a proof, but often you'll find you can\n-- delete it at the end.\nexample (F : filter X) (T : set Y) : T ∈ F.map f ↔ f ⁻¹' T ∈ F :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- Let's check that `map` satisfies some basic functorialities.\n-- Recall that if your goal is to check two filters are\n-- equal then you can use the `ext` tactic, e.g. with `ext S`.\n\n-- pushing along the identity map id : X → X doesn't change the filter.\n-- this is `filter.map_id` but see if you can prove it yourself.\nexample (F : filter X) : F.map id = F :=\nbegin\n  sorry\nend\n\n-- pushing along g ∘ f is the same as pushing along f and then g\n-- for some reason this isn't in mathlib, instead they have `map_map` which\n-- has the equality the other way.\nvariables (Z : Type) (g : Y → Z)\n\n-- this isn't in mathlib, but `filter.map_map` is the equality the other\n-- way around. See if you can prove it yourself.\nexample (F : filter X) : F.map (g ∘ f) = (F.map f).map g :=\nbegin\n  sorry,\nend\n\nopen_locale filter -- for 𝓟 notation\n\n-- pushing the principal filter `𝓟 S` along `f` gives `𝓟 (f '' S)`\n-- this is `filter.map_principal` but see if you can prove it yourself.\nexample (S : set X) : (𝓟 S).map f = 𝓟 (f '' S) :=\nbegin\n  sorry,\nend\n\n/-\n\n## tendsto\n\nThe definition: if `f : X → Y` and `F : filter X` and `G : filter Y`\nthen `tendsto f F G : Prop := map f F ≤ G`. It's pronounced something\nlike \"`F` tends to `G` along `f`\". This is a *definition* (it\nhas type `Prop`), not the proof of a theorem. It is a true-false statement\nattached to `f`, `F` and `G`, it's a bit like saying \"f is continuous at x\"\nor something like that, it might be true and it might be false.\n\nThe mental model you might want to have of the definition is that\n`tendsto f F G` means that the function `f` restricts to a function\nfrom the generalized set `F` to the generalized set `G`.\n\n-/\n\n-- this is `filter.tendsto_def`\nexample (F : filter X) (G : filter Y) :\n  tendsto f F G ↔ ∀ T : set Y, T ∈ G → f ⁻¹' T ∈ F :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- Let's make a basic API for `tendsto`\n\n-- this is `tendsto_id` but see if you can prove it yourself.\nexample (F : filter X) : tendsto id F F :=\nbegin\n  sorry,\nend\n\n-- this is `tendsto.comp` but see if you can prove it yourself\nexample (F : filter X) (G : filter Y) (H : filter Z)\n  (f : X → Y) (g : Y → Z)\n  (hf : tendsto f F G) (hg : tendsto g G H) : tendsto (g ∘ f) F H :=\nbegin\n  sorry,\nend\n\n-- I would recommend looking at the model answer to this one if\n-- you get stuck.\nlemma tendsto_comp_map (g : Y → Z) (F : filter X) (G : filter Z) :\n  tendsto (g ∘ f) F G ↔ tendsto g (F.map f) G :=\nbegin\n  sorry,\nend\n\n/-\n\n## Pulling back filters\n\nWe don't use this in the next part.\n\nSay `f : X → Y` and `G : filter Y`, and we want a filter on `X`. Let's make a\nnaive definition. We want a collection of subsets of `X` corresponding to the\nfilter obtained by pulling back `G` along `f`. When should `S : set X` be\nin this filter? Perhaps it is when `f '' S ∈ G`. However, there is no reason\nthat the collection of `S` satisfying this property should be a filter\non `X`. For example, there is no reason to espect that `f '' univ ∈ G`\nif `f` is not surjective. Our naive guess doesn't work.\n\nHere's a way of fixing this, by coming up with a less naive guess which\nis informed by our mental model. Remember that our model of a filter `G` is some\nkind of generalised notion of a set. If `T : set Y` then `T ∈ G` is supposed to\nmean that the \"set\" `G` is a subset of `T`. So this should imply\nthat `f⁻¹(G) ⊆ f⁻¹(T)`. In particular, if `T ∈ G` and `f⁻¹(T) ⊆ S` then this\nshould mean `f⁻¹(G) ⊆ S` and hence `S ∈ f⁻¹(G)`. Let's try this condition\n(defining `S ∈ f⁻¹(G)` to mean `∃ T ∈ G, f⁻¹(T) ⊆ S`) and see if it works.\n\nRandom useful lemmas (you might be getting to the point where you can\nguess the names of the lemmas):\n\n`subset_univ S : S ⊆ univ`\n`subset.trans : A ⊆ B → B ⊆ C → A ⊆ C`\n-/\n\n-- this is called filter.comap\nexample (G : filter Y) : filter X :=\n{ sets := {S : set X | ∃ T ∈ G, f ⁻¹' T ⊆ 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-- Let's call this mem_comap\nlemma mem_comap (f : X → Y) (G : filter Y) (S : set X) :\n  S ∈ comap f G ↔ ∃ T ∈ G, f ⁻¹' T ⊆ S :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- If you want to, you can check some preliminary properties of `comap`. \n\n-- this is comap_id\nexample (G : filter Y) : comap id G = G :=\nbegin\n  sorry\nend\n\n-- this is comap_comap but the other way around\nlemma comap_comp (H : filter Z) : comap (g ∘ f) H = comap f (comap g H) :=\nbegin\n  sorry\nend\n\n-- this is comap_principal. Remember `mem_principal_sets`! It's true by definition...\nexample (T : set Y) : comap f (𝓟 T) = 𝓟 (f ⁻¹' T) :=\nbegin\n  sorry\nend\n\n\n-- This is the proof that `map f` and `comap f` are adjoint functors,\n-- or in other words form a Galois connection. It is the \"generalised set\"\n-- analogue of the assertion that if S is a subset of X and T is a subset of Y\n-- then f(S) ⊆ T ↔ S ⊆ f⁻¹(T), these both being ways to say that `f` restricts\n-- to a function from `S` to `T`.\nlemma filter.galois_connection (F : filter X) (G : filter Y) : \n  map f F ≤ G ↔ F ≤ comap f G :=\nbegin\n  sorry,\nend\n\n-- indeed, `map f` and `comap f` form a Galois connection.\nexample : galois_connection (map f) (comap f) :=\nfilter.galois_connection X Y f \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_A_tendsto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767938900121, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7654645760349587}}
{"text": "/-\n# Goal:\n\nProve the equivalence of a pair of definitions for **flat modules**.\n\n## Definition 1 (ideal_def):\n\nThe definition of a *flat module* implemented in Lean is:\n\nLet `R` be a commutative ring, and `M` and `R`-module. The module is *flat* if for all finitely\ngenerated ideals `I` of `R`, the canonical map `I ⊗ M →ₗ M` is injective. \n\n## Definition 2 (ses_def):\n\nThe goal definition is that given in the Stacks project <https://stacks.math.columbia.edu/tag/00HB>:\n\nAn `R`-module `M` is called *flat* if when `N₁ →ₗ N₂ →ₗ N₃` is an exact sequence of R-modules, the\ninduced sequence obtained by tensoring `N₁ ⊗ M →ₗ N₂ ⊗ M →ₗ N₃ ⊗ M` is exact.\n\n## Main Theorem:\n\nThe main theorem of this Lean document is that **ideal_def** and **ses_def** are equivalent. \nThis has as a consequence the more general [theorem](https://stacks.math.columbia.edu/tag/00HD):\n\nLet `M` be an `R`-module. TFAE:\n\n1. `M` is flat over `R` (according to **ses_def**)\n2. For every injection `N →ₗ N'` of `R`-modules, the map `N ⊗ M →ₗ N' ⊗ M` is injective. \n3. For every idea `I` of `R`, the induced map `I ⊗ M →ₗ M` is injective.\n4. `M` is flat over `R` in the Lean sense (**ideal_def**)\n\n## Proof Sketch: \n\nThe proof sketch in the Stacks project goes as follows:\n\n1. **ses_def** implies **ideal_def**. \n\n    This argument is straightforward, because `I` and `R` fit into the exact sequence \n    `I →ₗ R →ₗ R / I`, and exactness in the middle of `I ⊗ M →ₗ R ⊗ M ≃ₗ M →ₗ (R / I) ⊗ M` \n    implies that the left map is injective.\n\n    New goal (1): Show **ideal_def** implies **ses_def**\n\n2. Show that in order to prove **ses_def** it is sufficient to prove `_ ⊗ M` preserves injectives.\n    \n    Given any exact sequence of the form  `N₁ →ₗ N₂ →ₗ N₃`, let `K = ker N₂ →ₗ N₃` \n    and `Q = im N₂ →ₗ N₃`. Then after tensoring with `M` everything fits into a sequence\n    `N₁ ⊗ M →ₗ K ⊗ M →ₗ N₂ ⊗ M →ₗ  Q ⊗ M →ₗ N₃ ⊗ M`. Then show that\n    \n    * The first and third maps are surjective always. \n    * If we show the second and forth maps are injective, then **ses_def** follows. (footnote 1)\n\n    New goal (2): If `K →ₗ N` is injective, then `K ⊗ M →ₗ N ⊗ M` is injective.\n\n3. Show that in order to prove (2) it is enough to show `_ ⊗ M` preserves injective maps `K →ₗ N`\nwhen `K` is a finite `R`-module. \n\n    Given an a general `K`, it can be written as a limit of its finite submodules. So in order to\n    show that `x : ker (K ⊗ M →ₗ N ⊗ M)` is zero, we can restrict to a finite submodule `K'`\n    of `K` that contains `x`.\n\n    New goal (3): If `K →ₗ N` is injective with `K` finite, show `K ⊗ M →ₗ N ⊗ M` is injective.\n\n4. In order to show (3) it suffces to show that `_ ⊗ M` preserves injective maps `K →ₗ N` when both\n`K` and `N` are finite `R`-modules.\n\n    Again, `N` can be written as a limit of its finite submodules, which is a directed system\n    becuase any two finite submodules are contained in the finite submodule \n\n    The result then follows by the following [lemma](https://stacks.math.columbia.edu/tag/00D7):\n    If `(M i, μ i j)` is a directed system of modules with `M = lim M i` (write `μ i : M i →ₗ M` for\n    the associated map) then `x i : M i` maps to zero in `M` via `μ i` if and only if there exists\n    a `j ≥ i` such that `μ i j (x i) = 0`. (this lemma also may follow from \n    [something else](https://stacks.math.columbia.edu/tag/00D6)) \n    [note this is already done!!!!]\n\n    New goal (4): If `K →ₗ N` is injective with with `K` and `N` finite, show `K ⊗ M →ₗ N ⊗ M`\n    is injective.\n\n5. In order to show (4) it suffices to show that `_ ⊗ M` preserves injective maps of the form\n`L →ₗ ⊕ⁿ R`.\n\n    Because `N` is finite, we can write it as `⊗ⁿ R / L`, and `K = L'/L` for some submodules `L`\n    and `L'` of `⊕ⁿ R`. In order to show `K ⊗ M →ₗ N ⊗ M` is injective it suffices to show both\n    `L ⊗ M →ₗ ⊕ⁿ M` and `L' ⊗ M →ₗ ⊕ⁿ M` are injective.\n\n    New goal (5): Given `L →ₗ ⊕ⁿ R` injective, show that `L ⊗ M →ₗ ⊕ⁿ M` is injective. \n\n6. We now prove (5) by induction on `n`. \n\n    The `n = 1` case, we are considering submodules `L →ₗ R`, which we can repeat the same argument\n    as in (3) to reduce to the case when `L` is a finite submodule (finitely generated ideal), \n    which is precisely **ideal_def**\n\n    For the induction step if we consider the meet of the submodules `L` and `R ⊕ 0ⁿ⁻¹` written\n    as `L'`, then `L'' = L'/L` is a submodule of `⊕ⁿ⁻¹ R` and we obtain the diagram\n\n            `L' ⊗ M` -----> `L ⊗ M` -----> `L'' ⊗ M` -----> `0`\n              |                 |                |\n              |                 |                |\n              |                 |                |\n              v                 v                v\n    `0` ---> `M` ----------> `⊕ⁿ M` -----> `⊕ⁿ⁻¹ M` -------> `0`\n\n    where the bottom row is obviously exact, the top row is exact as well, and our induction\n    hypothesis implies the left and right vertical arrows are injective. Hence the middle arrow\n    is injective as well. \n\n## Todo:\n\n* Show that any module is a direct limit of its finitely generated submodules. \n\n## Progress:\n\n* Proved that `0 ⊗ M = 0`\n* Defined and proved that finite submodules are a directed system\n* Showed that if the components of a map out of a direct limit are injective, then the map itself is\n\n## Where to go from here?:\n\n* Maybe defining `Tor`?\n-/\n\n/-\n## Subgoal 1: Prove that any module equivalent to the direct limit of its finite submodules.\n\nThis is a lemma that is used repeatedly in the argument above, and can generally play an important\nrule in strengthening theorems in commutative algebra about finitely generated/finite things.\n\n### Pieces\n\n* Have `linear_map.ker_eq_bot_of_injective`, but it appears that the converse isn't implemented\nin mathlib yet?\nOk that's not true, we have `mono_iff_ker_eq_bot` and `mono_iff_injective` which we can use to\ntranslate back and forth, so the lemma should be super easy. \n* Want to prove some basic stuff about `0 ⊗ m = 0`\n-/\n\n-- theorem main_result : injective f → injective (tensor_product.map (@linear_map.id R P _ _ _) f) :=\n-- begin\n-- intro h,\n-- sorry\n-- end", "meta": {"author": "eric-wieser", "repo": "flatstuff", "sha": "265b4d82dc06220bba8e1941a7039e698ba2392a", "save_path": "github-repos/lean/eric-wieser-flatstuff", "path": "github-repos/lean/eric-wieser-flatstuff/flatstuff-265b4d82dc06220bba8e1941a7039e698ba2392a/src/flatness.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473713594992, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.7654645759764509}}
{"text": "constants (p q : Prop) (H : p ∧ q)\ntheorem t_proof_left : p := and.elim_left H\ntheorem t_proof_right : q := and.elim_right H\ncheck t_proof_left    -- t_proof_left : p\ncheck t_proof_right   -- t_proof_right : q\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/and-elim.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541561135441, "lm_q2_score": 0.8128673110375458, "lm_q1q2_score": 0.765439881807346}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández 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 `# R[X] * ℵ₀`.\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 set\nopen_locale cardinal polynomial\n\nnamespace algebraic\n\nlemma infinite_of_char_zero (R A : Type*) [comm_ring R] [is_domain R]\n  [ring A] [algebra R A] [char_zero A] : {x : A | is_algebraic R x}.infinite :=\ninfinite_of_injective_forall_mem nat.cast_injective is_algebraic_nat\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] : ℵ₀ ≤ #{x : A // is_algebraic R x} :=\ninfinite_iff.1 (set.infinite_coe_iff.2 $ infinite_of_char_zero R A)\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} (#{x : A // is_algebraic R x}) ≤ cardinal.lift.{v} #(R[X]) * ℵ₀ :=\nbegin\n  rw [←mk_ulift, ←mk_ulift],\n  choose g hg₁ hg₂ using λ x : {x : A | is_algebraic R x}, x.coe_prop,\n  refine lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le g (λ f, _),\n  rw [lift_le_aleph_0, le_aleph_0_iff_set_countable],\n  suffices : maps_to coe (g ⁻¹' {f}) (f.root_set A),\n    from 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 ⟨hg₁ x, hg₂ x⟩\nend\n\ntheorem cardinal_mk_lift_le_max :\n  cardinal.lift.{u} (#{x : A // is_algebraic R x}) ≤ max (cardinal.lift.{v} (#R)) ℵ₀ :=\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\n@[simp] lemma cardinal_mk_lift_of_infinite [infinite R] :\n  cardinal.lift.{u} (#{x : A // is_algebraic R x}) = cardinal.lift.{v} (#R) :=\n((cardinal_mk_lift_le_max R A).trans_eq (max_eq_left $ aleph_0_le_mk _)).antisymm $\n  lift_mk_le'.2 ⟨⟨λ x, ⟨algebra_map R A x, is_algebraic_algebra_map _⟩,\n    λ x y h, no_zero_smul_divisors.algebra_map_injective R A (subtype.ext_iff.1 h)⟩⟩\n\nvariable [countable R]\n\n@[simp] protected theorem countable : set.countable {x : A | is_algebraic R x} :=\nbegin\n  rw [←le_aleph_0_iff_set_countable, ←lift_le],\n  apply (cardinal_mk_lift_le_max R A).trans,\n  simp\nend\n\n@[simp] theorem cardinal_mk_of_countble_of_char_zero [char_zero A] [is_domain R] :\n  #{x : A // is_algebraic R x} = ℵ₀ :=\n(algebraic.countable R A).le_aleph_0.antisymm (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} ≤ #R[X] * ℵ₀ :=\nby { rw [←lift_id (#_), ←lift_id #R[X]], exact cardinal_mk_lift_le_mul R A }\n\ntheorem cardinal_mk_le_max : #{x : A // is_algebraic R x} ≤ max (#R) ℵ₀ :=\nby { rw [←lift_id (#_), ←lift_id (#R)], exact cardinal_mk_lift_le_max R A }\n\n@[simp] theorem cardinal_mk_of_infinite [infinite R] : #{x : A // is_algebraic R x} = #R :=\nlift_inj.1 $ cardinal_mk_lift_of_infinite R A\n\nend non_lift\n\nend algebraic\n", "meta": {"author": "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/algebraic_card.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.76542436102129}}
{"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-/\nimport analysis.normed_space.conformal_linear_map\nimport analysis.inner_product_space.basic\n\n/-!\n# Conformal maps between inner product spaces\n\nIn an inner product space, a map is conformal iff it preserves inner products up to a scalar factor.\n-/\n\nvariables {E F : Type*} [inner_product_space ℝ E] [inner_product_space ℝ F]\n\nopen linear_isometry continuous_linear_map\nopen_locale real_inner_product_space\n\n/-- A map between two inner product spaces is a conformal map if and only if it preserves inner\nproducts up to a scalar factor, i.e., there exists a positive `c : ℝ` such that `⟪f u, f v⟫ = c *\n⟪u, v⟫` for all `u`, `v`. -/\nlemma is_conformal_map_iff (f : E →L[ℝ] F) :\n  is_conformal_map f ↔ ∃ (c : ℝ), 0 < c ∧ ∀ (u v : E), ⟪f u, f v⟫ = c * ⟪u, v⟫ :=\nbegin\n  split,\n  { rintros ⟨c₁, hc₁, li, rfl⟩,\n    refine ⟨c₁ * c₁, mul_self_pos.2 hc₁, λ u v, _⟩,\n    simp only [real_inner_smul_left, real_inner_smul_right, mul_assoc, coe_smul',\n      coe_to_continuous_linear_map, pi.smul_apply, inner_map_map] },\n  { rintros ⟨c₁, hc₁, huv⟩,\n    obtain ⟨c, hc, rfl⟩ : ∃ c : ℝ, 0 < c ∧ c₁ = c * c,\n      from ⟨real.sqrt c₁, real.sqrt_pos.2 hc₁, (real.mul_self_sqrt hc₁.le).symm⟩,\n    refine ⟨c, hc.ne', (c⁻¹ • f : E →ₗ[ℝ] F).isometry_of_inner (λ u v, _), _⟩,\n    { simp only [real_inner_smul_left, real_inner_smul_right, huv, mul_assoc, coe_smul,\n        inv_mul_cancel_left₀ hc.ne', linear_map.smul_apply, continuous_linear_map.coe_coe] },\n    { ext1 x,\n      exact (smul_inv_smul₀ hc.ne' (f x)).symm } }\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/conformal_linear_map.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7653944945953977}}
{"text": "import .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 {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nbegin\n  intros a₁ a₂ 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 {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nbegin\n  intros a₁ a₂ 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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing {} : regex\n| empty {}   : regex\n| atom       : α → regex\n| concat     : regex → regex → regex\n| alt        : regex → regex → regex\n| star       : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n| (regex.concat r₁ r₂) := rel_of_regex r₁ ◯ rel_of_regex r₂\n| (regex.alt r₁ r₂)    := rel_of_regex r₁ ∪ rel_of_regex r₂\n| (regex.star r)       := lfp (λX, (rel_of_regex r ◯ X) ∪ Id)\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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": "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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7653921796383637}}
{"text": "/-- These are lemmas i found myself proving in the course of producing full_proof, i am aware that\n    there is heavy redundency -/\n\nlemma lt_irrfl : ∀ n : ℕ, ¬ n < n :=\nbegin\n intro n,\n induction n with n hn,\n { intro hz, cases hz with r hr, },\n { intro h,\n   apply hn,\n   exact nat.lt_of_succ_lt_succ h, },\nend\n\nlemma add_succ_commute : ∀ m n : ℕ, nat.add m (nat.succ n) = nat.succ (nat.add m n) :=\nbegin\n intros m n,\n exact rfl,\nend\n\nlemma add_succ_commute' : ∀ m n : ℕ, nat.add (nat.succ m) n = nat.succ (nat.add m n) :=\nbegin\n intros m n,\n exact nat.succ_add m n,\nend\n\n-- i think this one could be tidied up\nlemma lt_succ_add : ∀ m n : ℕ, m < nat.succ (nat.add m n) :=\nbegin\n intros m n,\n apply nat.lt_succ_of_le,\n induction n with n hn,\n { have h : nat.add m 0 = m,\n   { exact nat.add_zero m, },\n   apply nat.le_of_eq,\n   rw h, },\n { calc\n    m     ≤ nat.add m n : by exact hn\n      ... ≤ nat.succ (nat.add m n) : by exact nat.le_of_lt (nat.lt_succ_of_le (nat.le_of_eq rfl))\n      ... = nat.add m (nat.succ n) : by { symmetry, exact add_succ_commute m n },\n },\nend\n\nlemma succ_add_nlt : ∀ m n : ℕ, ¬ nat.succ (nat.add m n) < m :=\nbegin\n intros m n h,\n have h' := lt_succ_add m n,\n have h'' := lt_irrfl m,\n apply h'',\n exact nat.lt_trans h' h,\nend\n\n-- again, could be tidied up\nlemma succ_add_minus_is_succ : ∀ m n : ℕ, nat.succ (nat.add m n) - m = nat.succ n :=\nbegin\n intros m n,\n induction n with n hn,\n { have h : nat.add m 0 = m,\n   { exact nat.add_zero m, },\n   have h' : 1 = nat.succ (m - m),\n   { rw nat.sub_self m, },\n   calc\n    nat.succ (nat.add m 0) - m     = nat.succ m - m : by rw h\n                               ... = nat.succ (m - m) : by exact nat.succ_sub (nat.le_of_eq rfl)\n                               ... = 1 : by { symmetry, exact h' },\n },\n {\n   calc\n    nat.succ (nat.add m (nat.succ n)) - m     \n        = nat.succ (nat.succ (nat.add m n)) - m : by rw add_succ_commute\n    ... = nat.succ (nat.succ (nat.add m n) - m) : by exact nat.succ_sub \n                                                     (nat.le_of_lt (lt_succ_add m n))\n    ... = nat.succ (nat.succ n)                 : by rw hn,\n },\nend\n\nlemma lt_decidable : ∀ m n : ℕ, n < m ∨ ¬ n < m :=\nbegin\n intros m n,\n have h : n ≤ m ∨ m ≤ n,\n { exact nat.le_total, },\n { cases h,\n   have h' : n = m ∨ n < m,\n   { exact nat.eq_or_lt_of_le h, },\n   cases h',\n   { right,\n     rw h',\n     exact lt_irrfl m, },\n   { left,\n     exact h', },\n { right,\n   have h' : m = n ∨ m < n,\n   { exact nat.eq_or_lt_of_le h, },\n   cases h',\n   { rw h',\n     exact lt_irrfl n, },\n   { intro h'',\n     apply lt_irrfl m,\n     exact nat.lt_trans h' h'', },},},\nend\n\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/natural_number_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7653921757534841}}
{"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 ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)`, and `A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ 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 ⊓ (B ⊔ C) = (A ⊔ B) ⊓ (A ⊔ C)` nor `A ⊓ (B ⊔ C) = (A ⊓ B) ⊔ (A ⊓ 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\nexample (L : Type) [lattice L] : \n  (∀ a b c : L, a ⊔ (b ⊓ c) = (a ⊔ b) ⊓ (a ⊔ c)) ↔ (∀ a b c : L, a ⊓ (b ⊔ c) = (a ⊓ b) ⊔ (a ⊓ 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/section06orderings_and_lattices/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7653921700920371}}
{"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## Orderings and lattices\n\nIn the last section we saw how subsets of a type worked, and we saw that \nthings like `⊆` and `∪` and `∩` made sense for subsets, and they satisfied\ntheorems such as `A ∩ B ⊆ B`. But it turns out that there is a more general\nabstraction called a *lattice* which captures these kinds of ideas, and I'd\nlike to explain this concept in this section. Note that the word \"lattice\" \nunfortunately means several things in mathematics; this is the use of the\nword in the context of partial orders. So let me start by talking about\npartial orders.\n\n## Partial orders\n\nA partial order (or a partially ordered type) is a type `X` equipped with\na concept of `≤` satisying some axioms. More precisely `X` is equipped\nwith a true-false statement `a ≤ b` for each `a b : X`, satisfying\nthe following axioms:\n\n`le_refl a : a ≤ a`\n`le_antisymm : a ≤ b → b ≤ a → a = b`\n`le_trans : a ≤ b → b ≤ c → a ≤ c`\n\nExamples of partial orders include the natural numbers and the real numbers. However\nthese examples are not quite representative, because a partial order does *not* have\nthe axiom that for all `a b : X` we have either `a ≤ b` or `b ≤ a`. A perhaps more\nrepresentative example of a partial order is the type `set X` of subsets of a type `X`,\nwith `a ≤ b` defined to mean `a ⊆ b`. For two general subsets `a` and `b` of `X`,\nboth `a ⊆ b` and `b ⊆ a` might be false. \n\n-/\n\n-- Let `X` be a partial order.\nvariables (X : Type) [partial_order X]\n\n-- You can prove transitivity directly using the axiom\nexample (a b c : X) (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=\nbegin\n  exact le_trans hab hbc\nend\n\n-- or you can use the `transitivity` tactic\nexample (a b c : X) (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=\nbegin\n  transitivity b,\n  { exact hab, },\n  { exact hbc, },\nend\n\n-- Let a,b,c,d be arbitrary elements of `X`\nvariables (a b c d : X)\n\n-- See if you can prove these basic facts about partial orders.\nexample : a ≤ a :=\nbegin\n  sorry\nend\n\nexample (hab : a ≤ b) (hbc : b ≤ c) (hcd : c ≤ d) : a ≤ d :=\nbegin\n  sorry\nend\n\nexample (hab : a ≤ b) (hbc : b ≤ c) (hca : c ≤ a) : a = b :=\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/section06orderings_and_lattices/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7653204719362795}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que la función identidad no está acotada\n-- superiormente. \n-- ----------------------------------------------------------------------\n\n\nimport .Funcion_no_acotada_superiormente\n\nexample : ¬ fn_has_ub (λ x, x) :=\nbegin\n  apply no_has_ub,\n  intro a,\n  use a + 1,\n  linarith,\nend\n\n-- Prueba\n-- ------\n\n-- ⊢ ¬fn_has_ub (λ (x : ℝ), x)\n--    >> apply no_has_ub,\n-- ⊢ ∀ (a : ℝ), ∃ (x : ℝ), x > a\n--    >> intro a,\n-- a : ℝ\n-- ⊢ ∃ (x : ℝ), x > a\n--    >> use a + 1,\n-- ⊢ a + 1 > a\n--    >> linarith,\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/La_identidad_no_esta_acotada_superiormente.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.765313703681633}}
{"text": "section propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro p,\n  intro q,\n  exact q p,\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  by_cases h : P,\n  intro j,\n  exact h,\n  intro g,\n  exfalso,\n  exact g h,\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  by_cases h : P,\n  intro j,\n  exact h,\n  intro g,\n  exfalso,\n  exact g h,\n  intro p,\n  intro q,\n  exact q p,\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro poq,\n  cases poq with p q,\n  right,\n  exact p,\n  left,\n  exact q,\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  split,\n  exact q,\n  exact p, \nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h,\n  intro p,\n  cases h with notp q,\n  exfalso,\n  exact notp p,\n  exact q, \nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro poq,\n  intro notp,\n  cases poq with p q,\n  exfalso,\n  exact notp p,\n  exact q,\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro piq,\n  intro nq,\n  intro p,\n  have q : Q := piq p,\n  exact nq q,\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro nqinp,\n  intro p,\n  by_contradiction hboom,\n  have np := nqinp hboom,\n  exact np p,\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  intro piq,\n  intro nq,\n  by_contradiction hboom,\n  have q := piq hboom,\n  exact nq q,\n  intro nqinp,\n  intro p,\n  by_contradiction hboom,\n  have np := nqinp hboom,\n  exact np p,\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro n_ponq,\n  have r: P∨¬P,\n  by_cases p:P,\n  left,\n  exact p,\n  right,\n  exact p,\n  exact n_ponq r,\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro piq_i_p,\n  intro np,\n  have piq : (P → Q),\n  intro p,\n  exfalso,\n  exact np p,\n  exact np(piq_i_p(piq)),\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro poq,\n  by_contradiction npenq,\n  cases npenq with np nq,\n  cases poq with p q,\n  exact np p,\n  exact nq q,\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro peq,\n  by_contradiction nponq,\n  cases peq with p q,\n  cases nponq with np nq,\n  exact np p,\n  exact nq q,\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro n_poq,\n  split,\n  intro p,\n  have poq : (P∨Q),\n  left,\n  exact p,\n  exact n_poq poq,\n  intro q,\n  have poq : (P∨Q),\n  right,\n  exact q,\n  exact n_poq poq,\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro npenq,\n  cases npenq with np nq,\n  by_contradiction poq,\n  cases poq with p q,\n  exact np p,\n  exact nq q,\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\nsorry,\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro nqonp,\n  by_contradiction peq,\n  cases nqonp with nq np,\n  cases peq with p q,\n  exact nq q,\n  cases peq with p q,\n  exact np p,\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  sorry,\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro pe_qor,\n  cases pe_qor with p qor,\n  cases qor with q r,\n  left,\n  split,\n  exact p,\n  exact q,\n  right,\n  split,\n  exact p,\n  exact r,\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro peq_o_pe_qor,\n  cases peq_o_pe_qor with peq per,\n  cases peq with p q,\n  split,\n  exact p,\n  left,\n  exact q,\n  split,\n  cases per with p r,\n  exact p,\n  cases per with p r,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro po_qer,\n  cases po_qer with p qer,\n  split,\n  left,\n  exact p,\n  left,\n  exact p,\n  cases qer with q r,\n  split,\n  right,\n  exact q,\n  right,\n  exact r,\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro poq_e_por,\n  cases poq_e_por with poq por,\n  cases poq with p q,\n  left,\n  exact p,\n  cases por with p r,\n  left,\n  exact p,\n  right,\n  split,\n  exact q,\n  exact r,\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro peq_i_r,\n  intro p,\n  intro q,\n  have peq : P∧Q,\n  split,\n  exact p,\n  exact q,\n  exact peq_i_r peq,\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro piqir,\n  intro peq,\n  cases peq with p q,\n  have qir := piqir p,\n  exact qir q,\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  exact p,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  exact p,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  exact q,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  exact p,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  exact q,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  intro pep,\n  cases pep with p1 p2,\n  exact p1,\n  intro p,\n  split,\n  exact p,\n  exact p,\nend\n\ntheorem disj_idemp :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  intro pop,\n  cases pop with p1 p2,\n  exact p1,\n  exact p2,\n  intro p,\n  left,\n  exact p,  \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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro none_P,\n  intro x,\n  intro P,\n  apply none_P,\n  existsi x,\n  exact P,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro all_nP,\n  intro some_P,\n  cases some_P with x P,\n  have nP := all_nP x,\n  exact nP P,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro some_dont_P, --exists x such that not P of x\n  intro all_P,  --for all x, P of x\n  cases some_dont_P with x nPx,\n  have Px := all_P x,\n  exact nPx Px,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  sorry,\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro some_P,\n  intro all_nP,\n  cases some_P with x Px,\n  have nPx := all_nP x, \n  exact nPx Px,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro all_P,\n  intro some_nP,\n  cases some_nP with x nPx,\n  have Px := all_P x,\n  exact nPx Px,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro none_nP,\n  by_contradiction n_all_P,\n  apply n_all_P,\n  intro x,\n  by_contradiction n_P,\n  apply none_nP,\n  existsi x,\n  exact n_P,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  intro n_all_nP,\n  by_contradiction none_P,\n  apply n_all_nP,\n  intro x,\n  intro p,\n  apply none_P,\n  existsi x,\n  exact p,  \nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  intro all_P,\n  intro some_nP,\n  cases some_nP with x nP,\n  apply nP,\n  exact all_P x,\n  intro none_nP,\n  by_contradiction n_all_P,\n  apply none_nP,\n  sorry,\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  sorry,\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro some_P_e_Q,\n  cases some_P_e_Q with x P_e_Q,\n  cases P_e_Q with P Q,\n  split,\n  existsi x,\n  exact P,\n  existsi x,\n  exact Q,\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  intro some_PoQ,\n  cases some_PoQ with x P_o_Q,\n  cases P_o_Q with P Q,\n  left,\n  existsi x,\n  exact P,\n  right,\n  existsi x,\n  exact Q,\n\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  intro someP_or_someQ,\n  cases someP_or_someQ with some_P some_Q,\n  cases some_P with x Px,\n  existsi x,\n  left,\n  exact Px,\n  cases some_Q with x Qx,\n  existsi x,\n  right,\n  exact Qx,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  intro allP_e_allQ,\n  split,\n  intro x,\n  have P_e_Q := allP_e_allQ x,\n  cases P_e_Q with P Q,\n  exact P,\n  intro x,\n  have P_e_Q := allP_e_allQ x,\n  cases P_e_Q with P Q,\n  exact Q,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  intro allP_e_allQ,\n  cases allP_e_allQ with allP allQ,\n  intro x,\n  split,\n  exact allP x,\n  exact allQ x,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  intro allP_or_allQ,\n  intro x,\n  cases allP_or_allQ with allP allQ,\n  left,\n  exact allP x,\n  right,\n  exact allQ x,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "sammarques-bti", "repo": "fmclean", "sha": "8aaf547711de845669a711fc832100205d24800d", "save_path": "github-repos/lean/sammarques-bti-fmclean", "path": "github-repos/lean/sammarques-bti-fmclean/fmclean-8aaf547711de845669a711fc832100205d24800d/src/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7653136962744643}}
{"text": "import tactic\n\ndef fib : ℕ -> ℤ\n| 0 := 0\n| 1 := 1\n| (x+2) := fib (x) + fib (x+1)\n\nlemma fib_rule (n : ℕ) : fib(n + 2) = fib(n) + fib(n + 1) := rfl\n\ntheorem strong_induction {P : ℕ → Prop} {H : ∀ n : ℕ, (∀ m : ℕ, m < n → P m) → P n} (n : ℕ) : P n := sorry, -- this is already proven\n\nlemma fib_rule' (n : ℕ) (h : 0 < n) : fib (n + 1) = fib n + fib (n - 1) := sorry\n\ntheorem fib_add (m n : ℕ) (hm : 0 < m) : fib(m + n) = fib(n + 1) * fib(m) + fib(n) * fib(m - 1) :=\nbegin\n  apply strong_induction n,\n  -- use `intros` instead of `intro`\n  intros k h,\n  -- using by_cases instead of cases for... my eyes\n  cases k,\n  { simp [fib], },\n  { cases k,\n    { -- see how `fib_rule'` takes arguments, so i supply them? in `fib_rule' m hm`\n      simp [fib, fib_rule' m hm],\n    },\n    { simp only [nat.succ_eq_add_one, add_assoc],\n      norm_num,\n      -- we \"massage\" things into the right form, then expand everything\n      rw [← add_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      -- and then ring gets rid of everything\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\nexample (m n : ℕ) (hm : m > 0) (h : m ∣ n): fib(m) ∣ fib(n) :=\nbegin\n  rcases h with ⟨k, rfl⟩,\n  induction k with k hk,\n  { simp only [fib, mul_zero, dvd_zero], },\n  { rw [nat.succ_eq_add_one, mul_add, add_comm, mul_one, fib_add m _ hm],\n    simp only [dvd_add, dvd_mul_left, dvd_mul_of_dvd_left hk], },\nend", "meta": {"author": "grhkm21", "repo": "lean", "sha": "52fe0ba1b5c78344c640b0813f11db71338fcba2", "save_path": "github-repos/lean/grhkm21-lean", "path": "github-repos/lean/grhkm21-lean/lean-52fe0ba1b5c78344c640b0813f11db71338fcba2/sketch/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8376199653600371, "lm_q1q2_score": 0.7653136939543339}}
{"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 data.fin.tuple.bubble_sort_induction\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.Data.Fin.Tuple.Sort\nimport Mathbin.Data.Fintype.Perm\nimport Mathbin.Order.WellFounded\n\n/-!\n# \"Bubble sort\" induction\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe implement the following induction principle `tuple.bubble_sort_induction`\non tuples with values in a linear order `α`.\n\nLet `f : fin n → α` and let `P` be a predicate on `fin n → α`. Then we can show that\n`f ∘ sort f` satisfies `P` if `f` satisfies `P`, and whenever some `g : fin n → α`\nsatisfies `P` and `g i > g j` for some `i < j`, then `g ∘ swap i j` also satisfies `P`.\n\nWe deduce it from a stronger variant `tuple.bubble_sort_induction'`, which\nrequires the assumption only for `g` that are permutations of `f`.\n\nThe latter is proved by well-founded induction via `well_founded.induction_bot'`\nwith respect to the lexicographic ordering on the finite set of all permutations of `f`.\n-/\n\n\nnamespace Tuple\n\n#print Tuple.bubble_sort_induction' /-\n/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`\nif `f` satsifies `P` and `P` is preserved on permutations of `f` when swapping two\nantitone values. -/\ntheorem bubble_sort_induction' {n : ℕ} {α : Type _} [LinearOrder α] {f : Fin n → α}\n    {P : (Fin n → α) → Prop} (hf : P f)\n    (h :\n      ∀ (σ : Equiv.Perm (Fin n)) (i j : Fin n),\n        i < j → (f ∘ σ) j < (f ∘ σ) i → P (f ∘ σ) → P (f ∘ σ ∘ Equiv.swap i j)) :\n    P (f ∘ sort f) :=\n  by\n  letI := @Preorder.lift _ (Lex (Fin n → α)) _ fun σ : Equiv.Perm (Fin n) => toLex (f ∘ σ)\n  refine'\n    @WellFounded.induction_bot' _ _ _ (@Finite.Preorder.wellFounded_lt (Equiv.Perm (Fin n)) _ _)\n      (Equiv.refl _) (sort f) P (fun σ => f ∘ σ) (fun σ hσ hfσ => _) hf\n  obtain ⟨i, j, hij₁, hij₂⟩ := antitone_pair_of_not_sorted' hσ\n  exact ⟨σ * Equiv.swap i j, Pi.lex_desc hij₁ hij₂, h σ i j hij₁ hij₂ hfσ⟩\n#align tuple.bubble_sort_induction' Tuple.bubble_sort_induction'\n-/\n\n#print Tuple.bubble_sort_induction /-\n/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`\nif `f` satsifies `P` and `P` is preserved when swapping two antitone values. -/\ntheorem bubble_sort_induction {n : ℕ} {α : Type _} [LinearOrder α] {f : Fin n → α}\n    {P : (Fin n → α) → Prop} (hf : P f)\n    (h : ∀ (g : Fin n → α) (i j : Fin n), i < j → g j < g i → P g → P (g ∘ Equiv.swap i j)) :\n    P (f ∘ sort f) :=\n  bubble_sort_induction' hf fun σ => h _\n#align tuple.bubble_sort_induction Tuple.bubble_sort_induction\n-/\n\nend Tuple\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/Fin/Tuple/BubbleSortInduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7653136846953733}}
{"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\nThe complex numbers, modelled as R^2 in the obvious way.\n-/\nimport complex.basic -- tutorial level\n/-! \n\n# Level 1: I \n\nI find it unbelievable that we have written quite a lot 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. \nWhy don't you supply the definition, and make the 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\nnamespace complex\n\n/-- complex.I is the square root of -1 above the imaginary axis -/\ndef I : ℂ := ⟨0, 1⟩\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  refl,\nend\n\n/-- im(I) = 1 -/\n@[simp] lemma I_im : im(I) = 1 :=\nbegin\n  refl,\nend\n\n/-- I*I = -1 -/\n@[simp] lemma I_mul_I : I * I = -1 :=\nbegin\n  ext;\n  simp,\nend\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 : ∀ {z w : ℂ}, z = w ↔ z.re = w.re ∧ z.im = w.im\n-/\n/-- I is non-zero -/\nlemma I_ne_zero : (I : ℂ) ≠ 0 :=\nbegin\n  intro h,\n  rw ext_iff at h,\n  rw I_im at h,\n  rw zero_im at h,\n  cases h,\n  simp at h_right,\n  contradiction,\nend\n\nend complex", "meta": {"author": "tabsg", "repo": "complexNoGame", "sha": "6d765d2e75e99ccab2dda70f44ff06aa286f5bdd", "save_path": "github-repos/lean/tabsg-complexNoGame", "path": "github-repos/lean/tabsg-complexNoGame/complexNoGame-6d765d2e75e99ccab2dda70f44ff06aa286f5bdd/I.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7653079430763733}}
{"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.normed_space.ray\nimport topology.local_extr\n\n/-!\n# (Local) maximums in a normed space\n\nIn this file we prove the following lemma, see `is_max_filter.norm_add_same_ray`. If `f : α → E` is\na function such that `norm ∘ f` has a maximum along a filter `l` at a point `c` and `y` is a vector\non the same ray as `f c`, then the function `λ x, ‖f x + y‖` has a maximul along `l` at `c`.\n\nThen we specialize it to the case `y = f c` and to different special cases of `is_max_filter`:\n`is_max_on`, `is_local_max_on`, and `is_local_max`.\n\n## Tags\n\nlocal maximum, normed space\n-/\n\nvariables {α X E : Type*} [seminormed_add_comm_group E] [normed_space ℝ E] [topological_space X]\n\nsection\n\nvariables {f : α → E} {l : filter α} {s : set α} {c : α} {y : E}\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a maximum along a filter `l` at a point\n`c` and `y` is a vector on the same ray as `f c`, then the function `λ x, ‖f x + y‖` has a maximul\nalong `l` at `c`. -/\nlemma is_max_filter.norm_add_same_ray (h : is_max_filter (norm ∘ f) l c) (hy : same_ray ℝ (f c) y) :\n  is_max_filter (λ x, ‖f x + y‖) l c :=\nh.mono $ λ x hx,\ncalc ‖f x + y‖ ≤ ‖f x‖ + ‖y‖ : norm_add_le _ _\n           ... ≤ ‖f c‖ + ‖y‖ : add_le_add_right hx _\n           ... = ‖f c + y‖   : hy.norm_add.symm\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a maximum along a filter `l` at a point\n`c`, then the function `λ x, ‖f x + f c‖` has a maximul along `l` at `c`. -/\nlemma is_max_filter.norm_add_self (h : is_max_filter (norm ∘ f) l c) :\n  is_max_filter (λ x, ‖f x + f c‖) l c :=\nh.norm_add_same_ray same_ray.rfl\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a maximum on a set `s` at a point `c` and\n`y` is a vector on the same ray as `f c`, then the function `λ x, ‖f x + y‖` has a maximul on `s` at\n`c`. -/\nlemma is_max_on.norm_add_same_ray (h : is_max_on (norm ∘ f) s c) (hy : same_ray ℝ (f c) y) :\n  is_max_on (λ x, ‖f x + y‖) s c :=\nh.norm_add_same_ray hy\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a maximum on a set `s` at a point `c`,\nthen the function `λ x, ‖f x + f c‖` has a maximul on `s` at `c`. -/\nlemma is_max_on.norm_add_self (h : is_max_on (norm ∘ f) s c) : is_max_on (λ x, ‖f x + f c‖) s c :=\nh.norm_add_self\n\nend\n\nvariables {f : X → E} {s : set X} {c : X} {y : E}\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a local maximum on a set `s` at a point\n`c` and `y` is a vector on the same ray as `f c`, then the function `λ x, ‖f x + y‖` has a local\nmaximul on `s` at `c`. -/\nlemma is_local_max_on.norm_add_same_ray (h : is_local_max_on (norm ∘ f) s c)\n  (hy : same_ray ℝ (f c) y) : is_local_max_on (λ x, ‖f x + y‖) s c :=\nh.norm_add_same_ray hy\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a local maximum on a set `s` at a point\n`c`, then the function `λ x, ‖f x + f c‖` has a local maximul on `s` at `c`. -/\nlemma is_local_max_on.norm_add_self (h : is_local_max_on (norm ∘ f) s c) :\n  is_local_max_on (λ x, ‖f x + f c‖) s c :=\nh.norm_add_self\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a local maximum at a point `c` and `y` is\na vector on the same ray as `f c`, then the function `λ x, ‖f x + y‖` has a local maximul at `c`. -/\nlemma is_local_max.norm_add_same_ray (h : is_local_max (norm ∘ f) c)\n  (hy : same_ray ℝ (f c) y) : is_local_max (λ x, ‖f x + y‖) c :=\nh.norm_add_same_ray hy\n\n/-- If `f : α → E` is a function such that `norm ∘ f` has a local maximum at a point `c`, then the\nfunction `λ x, ‖f x + f c‖` has a local maximul at `c`. -/\nlemma is_local_max.norm_add_self (h : is_local_max (norm ∘ f) c) :\n  is_local_max (λ x, ‖f x + f c‖) c :=\nh.norm_add_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/extr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909756, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7653079338052157}}
{"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önne, Benjamin Davidson\n-/\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 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ 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 ℂ sin :=\nλx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ λ 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ 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 ℂ cos :=\nλx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=\nfunext $ λ 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ n sinh :=\n(cont_diff_exp.sub cont_diff_neg.cexp).div_const\n\nlemma differentiable_sinh : differentiable ℂ sinh :=\nλx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ λ 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ n cosh :=\n(cont_diff_exp.add cont_diff_neg.cexp).div_const\n\nlemma differentiable_cosh : differentiable ℂ cosh :=\nλx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ λ x, (has_deriv_at_cosh x).deriv\n\nend complex\n\nsection\n/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/\n\nvariables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/\n\nvariables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ}\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 (λ x, complex.cos (f x)) (- complex.sin (f x) • 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 (λ x, complex.cos (f x)) (- complex.sin (f x) • 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 (λ x, complex.cos (f x)) (- complex.sin (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.cos (f x)) x :=\nhc.has_fderiv_at.ccos.differentiable_at\n\nlemma differentiable_on.ccos (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.cos (f x)) s :=\nλx h, (hc x h).ccos\n\n@[simp] lemma differentiable.ccos (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.cos (f x)) :=\nλx, (hc x).ccos\n\nlemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.ccos.fderiv_within hxs\n\n@[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.ccos.fderiv\n\nlemma cont_diff.ccos {n} (h : cont_diff ℂ n f) :\n  cont_diff ℂ n (λ x, complex.cos (f x)) :=\ncomplex.cont_diff_cos.comp h\n\nlemma cont_diff_at.ccos {n} (hf : cont_diff_at ℂ n f x) :\n  cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  cont_diff_within_at ℂ n (λ 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 (λ x, complex.sin (f x)) (complex.cos (f x) • 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 (λ x, complex.sin (f x)) (complex.cos (f x) • 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 (λ x, complex.sin (f x)) (complex.cos (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.sin (f x)) x :=\nhc.has_fderiv_at.csin.differentiable_at\n\nlemma differentiable_on.csin (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.sin (f x)) s :=\nλx h, (hc x h).csin\n\n@[simp] lemma differentiable.csin (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.sin (f x)) :=\nλx, (hc x).csin\n\nlemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.csin.fderiv_within hxs\n\n@[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.csin.fderiv\n\nlemma cont_diff.csin {n} (h : cont_diff ℂ n f) :\n  cont_diff ℂ n (λ x, complex.sin (f x)) :=\ncomplex.cont_diff_sin.comp h\n\nlemma cont_diff_at.csin {n} (hf : cont_diff_at ℂ n f x) :\n  cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  cont_diff_within_at ℂ n (λ 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 (λ x, complex.cosh (f x)) (complex.sinh (f x) • 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 (λ x, complex.cosh (f x)) (complex.sinh (f x) • 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 (λ x, complex.cosh (f x)) (complex.sinh (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.cosh (f x)) x :=\nhc.has_fderiv_at.ccosh.differentiable_at\n\nlemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.cosh (f x)) s :=\nλx h, (hc x h).ccosh\n\n@[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.cosh (f x)) :=\nλx, (hc x).ccosh\n\nlemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.ccosh.fderiv_within hxs\n\n@[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.ccosh.fderiv\n\nlemma cont_diff.ccosh {n} (h : cont_diff ℂ n f) :\n  cont_diff ℂ n (λ x, complex.cosh (f x)) :=\ncomplex.cont_diff_cosh.comp h\n\nlemma cont_diff_at.ccosh {n} (hf : cont_diff_at ℂ n f x) :\n  cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  cont_diff_within_at ℂ n (λ 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 (λ x, complex.sinh (f x)) (complex.cosh (f x) • 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 (λ x, complex.sinh (f x)) (complex.cosh (f x) • 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 (λ x, complex.sinh (f x)) (complex.cosh (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.sinh (f x)) x :=\nhc.has_fderiv_at.csinh.differentiable_at\n\nlemma differentiable_on.csinh (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.sinh (f x)) s :=\nλx h, (hc x h).csinh\n\n@[simp] lemma differentiable.csinh (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.sinh (f x)) :=\nλx, (hc x).csinh\n\nlemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.csinh.fderiv_within hxs\n\n@[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.csinh.fderiv\n\nlemma cont_diff.csinh {n} (h : cont_diff ℂ n f) :\n  cont_diff ℂ n (λ x, complex.sinh (f x)) :=\ncomplex.cont_diff_sinh.comp h\n\nlemma cont_diff_at.csinh {n} (hf : cont_diff_at ℂ n f x) :\n  cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  cont_diff_within_at ℂ n (λ 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 : ℝ}\n\nlemma has_strict_deriv_at_sin (x : ℝ) : 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 : ℝ) : 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 ℝ n sin :=\ncomplex.cont_diff_sin.real_of_complex\n\nlemma differentiable_sin : differentiable ℝ sin :=\nλx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin : differentiable_at ℝ sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ λ x, (has_deriv_at_sin x).deriv\n\nlemma has_strict_deriv_at_cos (x : ℝ) : 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 : ℝ) : 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 ℝ n cos :=\ncomplex.cont_diff_cos.real_of_complex\n\nlemma differentiable_cos : differentiable ℝ cos :=\nλx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos : differentiable_at ℝ 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 = (λ x, - sin x) :=\nfunext $ λ _, deriv_cos\n\nlemma has_strict_deriv_at_sinh (x : ℝ) : 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 : ℝ) : 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 ℝ n sinh :=\ncomplex.cont_diff_sinh.real_of_complex\n\nlemma differentiable_sinh : differentiable ℝ sinh :=\nλx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh : differentiable_at ℝ sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ λ x, (has_deriv_at_sinh x).deriv\n\nlemma has_strict_deriv_at_cosh (x : ℝ) : 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 : ℝ) : 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 ℝ n cosh :=\ncomplex.cont_diff_cosh.real_of_complex\n\nlemma differentiable_cosh : differentiable ℝ cosh :=\nλx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh : differentiable_at ℝ cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ λ 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, `∀ a b, sinh a = sinh b → a = b`. -/\nlemma sinh_injective : function.injective sinh := sinh_strict_mono.injective\n\n@[simp] lemma sinh_inj : sinh x = sinh y ↔ x = y := sinh_injective.eq_iff\n@[simp] lemma sinh_le_sinh : sinh x ≤ sinh y ↔ x ≤ y := sinh_strict_mono.le_iff_le\n@[simp] lemma sinh_lt_sinh : sinh x < sinh y ↔ x < y := sinh_strict_mono.lt_iff_lt\n\n@[simp] lemma sinh_pos_iff : 0 < sinh x ↔ 0 < x :=\nby simpa only [sinh_zero] using @sinh_lt_sinh 0 x\n\n@[simp] lemma sinh_nonpos_iff : sinh x ≤ 0 ↔ x ≤ 0 :=\nby simpa only [sinh_zero] using @sinh_le_sinh x 0\n\n@[simp] lemma sinh_neg_iff : sinh x < 0 ↔ x < 0 :=\nby simpa only [sinh_zero] using @sinh_lt_sinh x 0\n\n@[simp] lemma sinh_nonneg_iff : 0 ≤ sinh x ↔ 0 ≤ x :=\nby simpa only [sinh_zero] using @sinh_le_sinh 0 x\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 $ λ 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 ≤ cosh y ↔ |x| ≤ |y| :=\ncosh_abs x ▸ cosh_abs y ▸ 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 ↔ |x| < |y| :=\nlt_iff_lt_of_le_iff_le cosh_le_cosh\n\n@[simp] lemma one_le_cosh (x : ℝ) : 1 ≤ cosh x :=\ncosh_zero ▸ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg])\n\n@[simp] lemma one_lt_cosh : 1 < cosh x ↔ x ≠ 0 :=\ncosh_zero ▸ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos])\n\nlemma sinh_sub_id_strict_mono : strict_mono (λ x, sinh x - x) :=\nbegin\n  refine strict_mono_of_odd_strict_mono_on_nonneg (λ x, by simp) _,\n  refine (convex_Ici _).strict_mono_on_of_deriv_pos _ (λ 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 ≤ sinh x ↔ 0 ≤ x :=\ncalc x ≤ sinh x ↔ sinh 0 - 0 ≤ sinh x - x : by simp\n... ↔ 0 ≤ x : sinh_sub_id_strict_mono.le_iff_le\n\n@[simp] lemma sinh_le_self_iff : sinh x ≤ x ↔ x ≤ 0 :=\ncalc sinh x ≤ x ↔ sinh x - x ≤ sinh 0 - 0 : by simp\n... ↔ x ≤ 0 : sinh_sub_id_strict_mono.le_iff_le\n\n@[simp] lemma self_lt_sinh_iff : x < sinh x ↔ 0 < x :=\nlt_iff_lt_of_le_iff_le sinh_le_self_iff\n\n@[simp] lemma sinh_lt_self_iff : sinh x < x ↔ x < 0 :=\nlt_iff_lt_of_le_iff_le self_le_sinh_iff\n\nend real\n\nsection\n/-! ### Simp lemmas for derivatives of `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/\n\nvariables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 `λ x, real.cos (f x)` etc., `f : E → ℝ` -/\n\nvariables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}\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 (λ x, real.cos (f x)) (- real.sin (f x) • 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 (λ x, real.cos (f x)) (- real.sin (f x) • 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 (λ x, real.cos (f x)) (- real.sin (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.cos (f x)) x :=\nhc.has_fderiv_at.cos.differentiable_at\n\nlemma differentiable_on.cos (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.cos (f x)) s :=\nλx h, (hc x h).cos\n\n@[simp] lemma differentiable.cos (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.cos (f x)) :=\nλx, (hc x).cos\n\nlemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.cos.fderiv_within hxs\n\n@[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.cos.fderiv\n\nlemma cont_diff.cos {n} (h : cont_diff ℝ n f) :\n  cont_diff ℝ n (λ x, real.cos (f x)) :=\nreal.cont_diff_cos.comp h\n\nlemma cont_diff_at.cos {n} (hf : cont_diff_at ℝ n f x) :\n  cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  cont_diff_within_at ℝ n (λ 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 (λ x, real.sin (f x)) (real.cos (f x) • 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 (λ x, real.sin (f x)) (real.cos (f x) • 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 (λ x, real.sin (f x)) (real.cos (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.sin (f x)) x :=\nhc.has_fderiv_at.sin.differentiable_at\n\nlemma differentiable_on.sin (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.sin (f x)) s :=\nλx h, (hc x h).sin\n\n@[simp] lemma differentiable.sin (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.sin (f x)) :=\nλx, (hc x).sin\n\nlemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.sin.fderiv_within hxs\n\n@[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.sin.fderiv\n\nlemma cont_diff.sin {n} (h : cont_diff ℝ n f) :\n  cont_diff ℝ n (λ x, real.sin (f x)) :=\nreal.cont_diff_sin.comp h\n\nlemma cont_diff_at.sin {n} (hf : cont_diff_at ℝ n f x) :\n  cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  cont_diff_within_at ℝ n (λ 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 (λ x, real.cosh (f x)) (real.sinh (f x) • 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 (λ x, real.cosh (f x)) (real.sinh (f x) • 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 (λ x, real.cosh (f x)) (real.sinh (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.cosh (f x)) x :=\nhc.has_fderiv_at.cosh.differentiable_at\n\nlemma differentiable_on.cosh (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.cosh (f x)) s :=\nλx h, (hc x h).cosh\n\n@[simp] lemma differentiable.cosh (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.cosh (f x)) :=\nλx, (hc x).cosh\n\nlemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.cosh.fderiv_within hxs\n\n@[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.cosh.fderiv\n\nlemma cont_diff.cosh {n} (h : cont_diff ℝ n f) :\n  cont_diff ℝ n (λ x, real.cosh (f x)) :=\nreal.cont_diff_cosh.comp h\n\nlemma cont_diff_at.cosh {n} (hf : cont_diff_at ℝ n f x) :\n  cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  cont_diff_within_at ℝ n (λ 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 (λ x, real.sinh (f x)) (real.cosh (f x) • 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 (λ x, real.sinh (f x)) (real.cosh (f x) • 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 (λ x, real.sinh (f x)) (real.cosh (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.sinh (f x)) x :=\nhc.has_fderiv_at.sinh.differentiable_at\n\nlemma differentiable_on.sinh (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.sinh (f x)) s :=\nλx h, (hc x h).sinh\n\n@[simp] lemma differentiable.sinh (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.sinh (f x)) :=\nλx, (hc x).sinh\n\nlemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.sinh.fderiv_within hxs\n\n@[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.sinh.fderiv\n\nlemma cont_diff.sinh {n} (h : cont_diff ℝ n f) :\n  cont_diff ℝ n (λ x, real.sinh (f x)) :=\nreal.cont_diff_sinh.comp h\n\nlemma cont_diff_at.sinh {n} (hf : cont_diff_at ℝ n f x) :\n  cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  cont_diff_within_at ℝ n (λ 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": "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/trigonometric/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.765282290787932}}
{"text": "import tactic                 \nimport data.set.basic  \nimport data.real.basic\nimport algebra.order.floor\nimport data.real.irrational\nimport data.set.basic\nimport data.real.basic\nimport data.rat.basic\nimport .greg_lemmas\n\n\n-- TO DO\n--O prove union part\n\n\n-- definition of a Beatty seq\ndef B : ℝ → set ℤ  := λ r, { n | ∃ m : ℤ , (m ≥ 1 ) ∧ ((n : ℤ ) = int.floor ((m : ℝ)  * r) ) }\n\n\nlemma mem_b_iff {q : ℝ} {k : ℤ }  : (k ∈ (B q)) ↔ ∃ m : ℤ   , (m ≥ 1 ) ∧ (k : ℤ )  = int.floor ((m : ℝ) * q ) :=\nbegin\n  split, \n  intro hk,\n  rw set.mem_def at hk,\n  exact hk,\n  intro h,\n  rw set.mem_def,\n  assumption,\nend\n\n\n-- good examples of easy lemmas in lean\nlemma self_div_self_sub_one_neq_one (q : ℝ ) (hq : q > 1) : q/(q-1) ≠ 1 :=\nbegin\n  by_contra hc,\n  have hc' : (q - 1) * (q / (q - 1)) = (q - 1 ) * 1 := congr_arg (has_mul.mul (q - 1)) hc,\n  rw [← mul_div_assoc, mul_one, mul_comm, mul_div_assoc, div_self, mul_one] at hc',\n  repeat {linarith,},\nend \n\nlemma self_div_self_sub_one_neq_zero (q : ℝ ) (hq : q > 1) : q/(q-1) ≠ 0 :=\nbegin\n  by_contra hc,\n  have hc' : (q - 1) * (q / (q - 1)) = (q - 1 ) * 0 := congr_arg (has_mul.mul (q - 1)) hc,\n  rw mul_zero at hc',\n  rw ← mul_div_assoc at hc',\n  rw mul_comm at hc',\n  rw mul_div_assoc at hc',\n  rw div_self at hc',\n  rw mul_one at hc',\n  linarith,\n  linarith,\nend \n\nlemma irrat_mul_sub_irrat (a b : ℤ) (q : ℝ) (hsub : (a : ℝ)  - ↑b ≠ 0) (hq : irrational q) :\n  irrational (q *(↑a - ↑b)) :=\nbegin\n  have hsub' : a - b ≠ 0,\n  {\n    norm_cast at *,\n  },\n  norm_cast,\n  rw irrational_mul_int_iff,\n  exact ⟨hsub', hq⟩,\nend\n\nlemma irrat_div_irrat_sub_one_irrat (q : ℝ) (hq : irrational q) (h_q_gt_one : q > 1) :\n  irrational (q / (q - 1)) :=\nbegin\n  rw irrational_iff_ne_rational,\n  by_contra hc, push_neg at hc,\n  rcases hc with ⟨a, b, hf⟩,\n  change (q / (q - 1)) = ↑a / ↑b at hf,\n\n  have hf1 : (q - 1) * (q / (q - 1)) = (q - 1) * (↑a / ↑b) := congr_arg (has_mul.mul (q - 1)) hf,\n  rw mul_div at hf1,\n  rw mul_comm (q - 1) q at hf1,\n  rw ← mul_div at hf1,\n  rw div_self at hf1,\n  rw mul_one at hf1,\n\n  have hf2 : q * ↑b  = ((q - 1) * (↑a / ↑b)) * ↑b  := congr_fun (congr_arg has_mul.mul hf1) ↑b,\n  rw mul_assoc at hf2,\n  rw div_mul at hf2,\n  rw div_self at hf2,\n  rw div_one at hf2,\n  rw sub_mul at hf2,\n  rw one_mul at hf2,  \n  have hf3 : ↑a = q * ↑a - q * ↑b  := by linarith,\n  rw ← mul_sub at hf3,\n  have h_a_neq_b : (a : ℝ)  - ↑b ≠ 0 , {\n    by_contra hc,\n    have hr : (a : ℝ)  / ↑b = 1,\n    {\n      rw sub_eq_zero at hc,\n      have hdiv: (b : ℝ) / ↑b = ↑a / ↑b := congr_fun (congr_arg has_div.div (eq.symm hc)) ↑b, \n      rw div_self at hdiv,\n      exact hdiv.symm,\n      by_contra hc,\n      rw hc at hf,\n      rw div_zero at hf,\n      apply self_div_self_sub_one_neq_zero q h_q_gt_one,\n      exact hf,\n    },\n    rw hr at hf,\n    apply self_div_self_sub_one_neq_one q h_q_gt_one,\n    exact hf,\n  },    \n  have h_irrational : irrational (q * (↑a - ↑b)) := irrat_mul_sub_irrat a b q h_a_neq_b hq,\n  rw ← hf3 at h_irrational,\n  have h_rational : ¬ (irrational ↑a) := int.not_irrational a,\n  exact hq (false.rec (q ∈ set.range coe) (h_rational h_irrational)),\n  tactic.swap,\n  linarith,\n  by_contra hc,\n  rw hc at hf,\n  rw div_zero at hf,\n  apply self_div_self_sub_one_neq_zero q h_q_gt_one,\n  exact hf,\nend\n\nlemma mul_sum_reciprocals (q p a : ℝ) : a / p + a / q = a* (1 / p + 1 / q) :=\nbegin\n rw mul_add,\n repeat {rw ← mul_div_assoc, rw mul_one},\nend\n\nlemma add_one_mul_sum_reciprocals (q p : ℝ) (x : ℤ) : (↑x  + 1) / p + (↑x  + 1) / q = (↑x  + 1)* (1 / p + 1 / q) :=\nbegin\n rw mul_add,\n repeat {rw ← mul_div_assoc, rw mul_one},\nend\n\nlemma sum_reciprocals_eq_one (q : ℝ) (hq : q > 1) : 1/ (q/(q-1)) + 1 / q = 1 :=\nbegin\n ring_nf,\n simp,\n rw mul_sub,\n simp,\n rwa inv_mul_cancel,\n linarith,\nend\n\nlemma floor_ge_one (m : ℤ ) (hm : m ≥ 1 ) (q : ℝ) (hq : q > 1) : ⌊↑m * q⌋ ≥ 1 :=\nbegin\n sorry,\nend\n\nlemma h_p_gt_one (q : ℝ) :  ( q/(q-1) > 1)  :=\nbegin\n sorry,\nend\n\ndef Zpos := {z : ℤ | z > 0 }\n\n\n-- proof I am basing off assumes an equivalent definition to B p U B q = Zpos\nlemma rephrase_union (q p : ℝ) :  (∀ x ∈ Zpos, (∃ (m n : ℤ), (x = ⌊↑m * q⌋ ∨ x = ⌊↑n * p⌋)))\n  ↔ (∀ x ∈ Zpos, (∃ (k l : ℤ), (x < ⌊↑k * q⌋ ∨ x + 1 > ⌊↑(k + 1) * q⌋) ∨ (x < ⌊↑l * q⌋ ∨ x + 1 > ⌊↑(l + 1) * q⌋))) :=\nbegin\n  split, {\n    intros hx x,\n    intro hx',\n    specialize hx x,\n    specialize hx hx',\n    rcases hx with ⟨m, n, hmn⟩, \n    cases hmn, {\n      have hmn' : ⌊↑m * q⌋ = x := eq.symm hmn, clear hmn,\n      rw int.floor_eq_iff at hmn',\n      cases hmn' with hle hlt,\n      sorry,\n    }, {\n      have hmn' : ⌊↑n * p⌋ = x := eq.symm hmn, clear hmn,\n      rw int.floor_eq_iff at hmn',\n      cases hmn' with hle hlt,\n      sorry,\n    },\n    \n  }, {\n    intros hx x hx',\n    specialize hx x hx',\n    rcases hx with ⟨k, l, hkl⟩, \n    sorry,\n  }\nend\n\n-- proof of rephrased union condition, in progress\nlemma anti_collisions (q p : ℝ) (k l : ℤ) (h_irrat : irrational q ∧ irrational p ) (hpq : 1/p + 1/q = 1) (x : ℤ) (hx : x > 0)  :\n  (∃ (k l : ℤ), (x < ⌊↑k * q⌋ ∨ x + 1 > ⌊↑(k + 1) * q⌋) ∨ (x < ⌊↑l * p⌋ ∨ x + 1 > ⌊↑(l + 1) * p⌋)) := \nbegin\n  by_contra hc, push_neg at hc,\n  specialize hc k l,\n  rcases hc with ⟨ ⟨hq1, hq2⟩, ⟨hp1, hp2⟩ ⟩,\n  sorry,\nend\n\n      \n\nlemma beatty_theorem_forward_union' ( q : ℝ ) (hq : irrational q) (h_q_gt_one : q > 1) (h_inter : (B q) ∩ (B ( q/(q-1))) = ∅) : \n(B q) ∪ (B ( q/(q-1))) = {n : ℤ | n ≥ 1 } :=\nbegin\n  have h_p_gt_one := h_p_gt_one q,\n  set p := (q/(q-1)),\n  ext,\n  split, {\n    intro hx,\n    repeat {rw set.mem_union at hx},\n    cases hx with hxq hxp,\n    {\n      rw mem_b_iff at hxq,\n      cases hxq with m hm,\n      cases hm with hm hx',\n      change x ≥ 1,\n      have hge := floor_ge_one m hm q h_q_gt_one,\n      rwa ← hx' at hge,\n    }, {\n      rw mem_b_iff at hxp,\n      cases hxp with m hm,\n      cases hm with hm hx',\n      change x ≥ 1,\n      have hge := floor_ge_one m hm p h_p_gt_one,\n      rwa ← hx' at hge,\n    },\n  }, {\n    intro hx,\n    have hx' : x ≥ 1 := set.mem_def.mp hx, clear hx,\n    rw set.mem_union,\n    repeat {rw mem_b_iff},\n    apply or_iff_not_imp_left.mpr,\n    intro h,\n    push_neg at h,\n    have h0 := h,\n    \n\n  },\n\nend\n\nlemma beatty_theorem_forward_inter ( q : ℝ ) (hq : irrational q) (h_q_gt_one : q > 1) : \n(((B q) ∩ (B (q/(q-1)))) = ∅) :=\nbegin\n  -- let p be defined as\n  set p := (q/(q-1)),\n  -- by contradiction\n  by_contra h, \n  -- rewrite to unfold definitions\n  change B q ∩ B p ≠ ∅ at h,\n  rw ← set.nonempty_iff_ne_empty at h,\n  rw set.nonempty_def at h,\n  -- introduce variables from existence\n  rcases h with ⟨x, hxq, hxp⟩,\n  rw mem_b_iff at *,\n\n  cases hxq with m hm,\n  cases hxp with l hl,\n\n  have hm2 := int.floor_eq_iff.mp (hm.2).symm, \n  cases hm2 with hm_le hm_gt,\n\n  --inequality can't be true because of irrationality\n  have hm_neq : ↑x ≠ ↑m * q,\n  {\n    -- use irrationality\n    have h_m_neq_zero : m ≠ 0 := by linarith,\n    have h_m_neq_zero' : (m : ℚ)  ≠ 0 := int.cast_ne_zero.mpr h_m_neq_zero,\n    have h_rhs : irrational (↑(m : ℚ) * q) := irrational.rat_mul hq h_m_neq_zero',\n    exact (irrational.ne_int h_rhs x).symm,\n  },\n  -- manipulate inequalities\n  have hm_lt : ↑x < ↑m * q := ne.lt_of_le hm_neq hm_le,\n  have hq_pos : q > 0 := by linarith,\n  have hm_lt2 : ↑x/q < ↑m := (div_lt_iff hq_pos).mpr hm_lt,\n  have hl_gt2 : ↑m  < (↑x + 1)/q  := (lt_div_iff hq_pos).mpr hm_gt,\n\n  have hl2 := int.floor_eq_iff.mp (hl.2).symm,\n  cases hl2 with hl_le hl_gt,\n  have hl_neq : ↑x ≠ ↑l * p,\n  {\n    -- use irrationality\n    have hp : irrational p,\n    {\n      change irrational (q/(q-1)),\n      exact irrat_div_irrat_sub_one_irrat q hq h_q_gt_one,\n    },\n    have h_l_neq_zero : l ≠ 0 := by linarith,\n    have h_l_neq_zero' : (l : ℚ)  ≠ 0 := int.cast_ne_zero.mpr h_l_neq_zero,\n    have h_rhs : irrational (↑(l : ℚ) * p) := irrational.rat_mul hp h_l_neq_zero',\n    exact (irrational.ne_int h_rhs x).symm,\n  },\n  have hl_lt : ↑x < ↑l * p := ne.lt_of_le hl_neq hl_le,\n  have hp_pos : p > 0 := p_is_positive q h_q_gt_one,\n  have hl_lt2 : ↑x/p < ↑l := (div_lt_iff hp_pos).mpr hl_lt,\n  have hl_gt2 : ↑l  < (↑x + 1)/p  := (lt_div_iff hp_pos).mpr hl_gt,\n\n  have h_lt : ↑x/p + ↑x/q < ↑m + ↑l := by linarith,\n  have h_gt : ↑m + ↑l  < (↑x + 1)/p + (↑x + 1)/q  := by linarith,\n\n  have hqp : 1/p + 1/q = 1 := sum_reciprocals_eq_one q h_q_gt_one,\n\n  have hs0 : (↑x + 1) / p + (↑x + 1) / q = (↑x + 1) * (1 / p + 1 / q) := add_one_mul_sum_reciprocals q p x,\n  rw hs0 at h_gt,\n  rw hqp at h_gt,\n  rw mul_one at h_gt,\n\n  have hs1 : ↑x  / p + ↑x / q = ↑x  * (1 / p + 1 / q) := mul_sum_reciprocals q p (x : ℝ),\n  rw hs1 at h_lt,\n  rw hqp at h_lt,\n  rw mul_one at h_lt,\n\n  norm_cast at *,\n  linarith,\nend\n\n\n\n-- Forward direction:\n-- complementary beatty sequences partition ℕ \n\ntheorem beatty_theorem_forward ( q : ℝ ) (hq : irrational q) (h_q_gt_one : q > 1) :\n ((B q) ∪ (B ( q/(q-1))) = {n : ℤ | n ≥ 1 }) ∧ (((B q) ∩ (B (q/(q-1)))) = ∅) := \nbegin\n  exact ⟨ beatty_theorem_forward_union' q hq h_q_gt_one, beatty_theorem_forward_inter q hq h_q_gt_one⟩,\nend\n\n\n-- Converse direction\n-- if two beatty sequence B p, B q partition ℕ, then 1/p + 1/ q = 1\n\n-- In progress...\n\n  \n\n\n-- Upensky's theorem \n-- https://mathweb.ucsd.edu/~fan/ron/papers/63_01_uspensky.pdf\n\n-- if a set S of positive real numbers has the property that the beatty sequences formed by these numbers \n-- partition the positive natural numbers, then |S| < 3\n\n\ndef P : finset ℝ → Prop := λ S,  ((⋃ (r : S) , B r) = {n : ℤ | n > 1 }) ∧ ((⋂ (r : S) , B r) = ∅)\n\nlemma p_is_true (S : finset ℝ ) : P S ↔ ((⋃ (r : S) , B r) = {n : ℤ | n > 1 }) ∧ ((⋂ (r : S) , B r) = ∅) :=\nbegin\n  refl,\nend\n \ntheorem upensky (S : finset ℝ ) (hS : P S) : ∀ s ∈ (P⁻¹'({true})), finset.card s < 3 :=\nbegin\n  by_contra hc, push_neg at hc,\n  cases hc with S hn,\n  cases hn,\n  rewrite set.mem_preimage at hn_left,\n  rw p_is_true at hn_left,\n  dsimp at hn_left,\n  sorry,\n  \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\n\n\n\n\n\n\n\n\n-- lemma beatty_theorem_forward_union'' ( q : ℝ ) (hq : irrational q) (h_q_gt_one : q > 1) (h_inter : (B q) ∩ (B ( q/(q-1))) = ∅) : \n-- (B q) ∪ (B ( q/(q-1))) = {n : ℤ | n ≥ 1 } :=\n-- begin\n--   have h_p_gt_one := h_p_gt_one q,\n--   set p := (q/(q-1)),\n--   ext,\n--   split, {\n--     intro hx,\n--     repeat {rw set.mem_union at hx},\n--     cases hx with hxq hxp,\n--     {\n--       rw mem_b_iff at hxq,\n--       cases hxq with m hm,\n--       cases hm with hm hx',\n--       change x ≥ 1,\n--       have hge := floor_ge_one m hm q h_q_gt_one,\n--       rwa ← hx' at hge,\n--     }, {\n--       rw mem_b_iff at hxp,\n--       cases hxp with m hm,\n--       cases hm with hm hx',\n--       change x ≥ 1,\n--       have hge := floor_ge_one m hm p h_p_gt_one,\n--       rwa ← hx' at hge,\n--     },\n--   }, {\n--     intro hx,\n--     have hx' : x ≥ 1 := set.mem_def.mp hx, clear hx,\n--     rw set.mem_union,\n--     repeat {rw mem_b_iff},\n--     sorry,\n    \n    \n\n--   },\n\n-- end", "meta": {"author": "Vilin97", "repo": "LLL", "sha": "ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9", "save_path": "github-repos/lean/Vilin97-LLL", "path": "github-repos/lean/Vilin97-LLL/LLL-ddaac9dd76e85c6b7404ca8ebeab5fbdd7355ac9/Zachary/beatty.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7652822881954356}}
{"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\n! This file was ported from Lean 3 source module data.nat.bits\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.Init.Data.Nat.Bitwise\nimport Mathlib.Init.Data.List.Basic\nimport Mathlib.Data.Nat.Basic\n\n/-!\n# Additional properties of binary recursion on `Nat`\n\nThis file documents additional properties of binary recursion,\nwhich allows us to more easily work with operations which do depend\non the number of leading zeros in the binary representation of `n`.\nFor example, we can more easily work with `Nat.bits` and `Nat.size`.\n\nSee also: `Nat.bitwise`, `Nat.pow` (for various lemmas about `size` and `shiftl`/`shiftr`),\nand `Nat.digits`.\n-/\n\n-- As this file is all about `bit0` and `bit1`,\n-- we turn off the deprecated linter for the whole file.\nset_option linter.deprecated false\n\nnamespace Nat\n\nuniverse u\n\nvariable {n : ℕ}\n\n/-! ### `boddDiv2_eq` and `bodd` -/\n\n\n@[simp]\ntheorem boddDiv2_eq (n : ℕ) : boddDiv2 n = (bodd n, div2 n) := by\n  unfold bodd div2; cases boddDiv2 n; rfl\n#align nat.bodd_div2_eq Nat.boddDiv2_eq\n\n@[simp]\ntheorem bodd_bit0 (n) : bodd (bit0 n) = false :=\n  bodd_bit false n\n#align nat.bodd_bit0 Nat.bodd_bit0\n\n@[simp]\ntheorem bodd_bit1 (n) : bodd (bit1 n) = true :=\n  bodd_bit true n\n#align nat.bodd_bit1 Nat.bodd_bit1\n\n@[simp]\ntheorem div2_bit0 (n) : div2 (bit0 n) = n :=\n  div2_bit false n\n#align nat.div2_bit0 Nat.div2_bit0\n\n@[simp]\ntheorem div2_bit1 (n) : div2 (bit1 n) = n :=\n  div2_bit true n\n#align nat.div2_bit1 Nat.div2_bit1\n\n/-! ### `bit0` and `bit1` -/\n\n-- There is no need to prove `bit0_eq_zero : bit0 n = 0 ↔ n = 0`\n-- as this is true for any `[Semiring R] [NoZeroDivisors R] [CharZero R]`\n-- However the lemmas `bit0_eq_bit0`, `bit1_eq_bit1`, `bit1_eq_one`, `one_eq_bit1`\n-- need `[Ring R] [NoZeroDivisors R] [CharZero R]` in general,\n-- so we prove `ℕ` specialized versions here.\n@[simp]\n\n\n@[simp]\ntheorem bit1_eq_bit1 {m n : ℕ} : bit1 m = bit1 n ↔ m = n :=\n  ⟨Nat.bit1_inj, fun h => by subst h; rfl⟩\n#align nat.bit1_eq_bit1 Nat.bit1_eq_bit1\n\n@[simp]\ntheorem bit1_eq_one {n : ℕ} : bit1 n = 1 ↔ n = 0 :=\n  ⟨@Nat.bit1_inj n 0, fun h => by subst h; rfl⟩\n#align nat.bit1_eq_one Nat.bit1_eq_one\n\n@[simp]\ntheorem one_eq_bit1 {n : ℕ} : 1 = bit1 n ↔ n = 0 :=\n  ⟨fun h => (@Nat.bit1_inj 0 n h).symm, fun h => by subst h; rfl⟩\n#align nat.one_eq_bit1 Nat.one_eq_bit1\n\ntheorem bit_add : ∀ (b : Bool) (n m : ℕ), bit b (n + m) = bit false n + bit b m\n  | true => bit1_add\n  | false => bit0_add\n#align nat.bit_add Nat.bit_add\n\ntheorem bit_add' : ∀ (b : Bool) (n m : ℕ), bit b (n + m) = bit b n + bit false m\n  | true => bit1_add'\n  | false => bit0_add\n#align nat.bit_add' Nat.bit_add'\n\ntheorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 := by\n  cases b <;> [exact Nat.bit0_ne_zero h, exact Nat.bit1_ne_zero _]\n#align nat.bit_ne_zero Nat.bit_ne_zero\n\ntheorem bit0_mod_two : bit0 n % 2 = 0 := by\n  rw [Nat.mod_two_of_bodd]\n  simp\n#align nat.bit0_mod_two Nat.bit0_mod_two\n\ntheorem bit1_mod_two : bit1 n % 2 = 1 := by\n  rw [Nat.mod_two_of_bodd]\n  simp\n#align nat.bit1_mod_two Nat.bit1_mod_two\n\ntheorem pos_of_bit0_pos {n : ℕ} (h : 0 < bit0 n) : 0 < n := by\n  cases n\n  · cases h\n  · apply succ_pos\n#align nat.pos_of_bit0_pos Nat.pos_of_bit0_pos\n\n@[simp]\ntheorem bitCasesOn_bit {C : ℕ → Sort u} (H : ∀ b n, C (bit b n)) (b : Bool) (n : ℕ) :\n    bitCasesOn (bit b n) H = H b n :=\n  eq_of_heq <| (eq_rec_heq _ _).trans <| by rw [bodd_bit, div2_bit]\n#align nat.bit_cases_on_bit Nat.bitCasesOn_bit\n\n@[simp]\ntheorem bitCasesOn_bit0 {C : ℕ → Sort u} (H : ∀ b n, C (bit b n)) (n : ℕ) :\n    bitCasesOn (bit0 n) H = H false n :=\n  bitCasesOn_bit H false n\n#align nat.bit_cases_on_bit0 Nat.bitCasesOn_bit0\n\n@[simp]\ntheorem bitCasesOn_bit1 {C : ℕ → Sort u} (H : ∀ b n, C (bit b n)) (n : ℕ) :\n    bitCasesOn (bit1 n) H = H true n :=\n  bitCasesOn_bit H true n\n#align nat.bit_cases_on_bit1 Nat.bitCasesOn_bit1\n\ntheorem bit_cases_on_injective {C : ℕ → Sort u} :\n    Function.Injective fun H : ∀ b n, C (bit b n) => fun n => bitCasesOn n H := by\n  intro H₁ H₂ h\n  ext (b n)\n  simpa only [bitCasesOn_bit] using congr_fun h (bit b n)\n#align nat.bit_cases_on_injective Nat.bit_cases_on_injective\n\n@[simp]\ntheorem bit_cases_on_inj {C : ℕ → Sort u} (H₁ H₂ : ∀ b n, C (bit b n)) :\n    ((fun n => bitCasesOn n H₁) = fun n => bitCasesOn n H₂) ↔ H₁ = H₂ :=\n  bit_cases_on_injective.eq_iff\n#align nat.bit_cases_on_inj Nat.bit_cases_on_inj\n\nprotected theorem bit0_eq_zero {n : ℕ} : bit0 n = 0 ↔ n = 0 :=\n  ⟨Nat.eq_zero_of_add_eq_zero_left, fun h => by simp [h]⟩\n#align nat.bit0_eq_zero Nat.bit0_eq_zero\n\ntheorem bit_eq_zero_iff {n : ℕ} {b : Bool} : bit b n = 0 ↔ n = 0 ∧ b = false := by\n  constructor\n  · cases b <;> simp [Nat.bit, Nat.bit0_eq_zero, Nat.bit1_ne_zero]\n  · rintro ⟨rfl, rfl⟩\n    rfl\n#align nat.bit_eq_zero_iff Nat.bit_eq_zero_iff\n\n/--\nThe same as `binaryRec_eq`,\nbut that one unfortunately requires `f` to be the identity when appending `false` to `0`.\nHere, we allow you to explicitly say that that case is not happening,\ni.e. supplying `n = 0 → b = true`. -/\ntheorem binaryRec_eq' {C : ℕ → Sort _} {z : C 0} {f : ∀ b n, C n → C (bit b n)} (b n)\n    (h : f false 0 z = z ∨ (n = 0 → b = true)) :\n    binaryRec z f (bit b n) = f b n (binaryRec z f n) := by\n  rw [binaryRec]\n  split_ifs with h'\n  · rcases bit_eq_zero_iff.mp h' with ⟨rfl, rfl⟩\n    rw [binaryRec_zero]\n    simp only [imp_false, or_false_iff, eq_self_iff_true, not_true] at h\n    exact h.symm\n  · dsimp only []\n    -- Porting note: this line was `generalize_proofs e`:\n    generalize @id (C (bit b n) = C (bit (bodd (bit b n)) (div2 (bit b n))))\n      (Eq.symm (bit_decomp (bit b n)) ▸ Eq.refl (C (bit b n))) = e\n    revert e\n    rw [bodd_bit, div2_bit]\n    intros\n    rfl\n#align nat.binary_rec_eq' Nat.binaryRec_eq'\n\n/-- The same as `binaryRec`, but the induction step can assume that if `n=0`,\n  the bit being appended is `true`-/\n@[elab_as_elim]\ndef binaryRec' {C : ℕ → Sort _} (z : C 0) (f : ∀ b n, (n = 0 → b = true) → C n → C (bit b n)) :\n    ∀ n, C n :=\n  binaryRec z fun b n ih =>\n    if h : n = 0 → b = true then f b n h ih\n    else by\n      convert z\n      rw [bit_eq_zero_iff]\n      simpa using h\n#align nat.binary_rec' Nat.binaryRec'\n\n/-- The same as `binaryRec`, but special casing both 0 and 1 as base cases -/\n@[elab_as_elim]\ndef binaryRecFromOne {C : ℕ → Sort _} (z₀ : C 0) (z₁ : C 1) (f : ∀ b n, n ≠ 0 → C n → C (bit b n)) :\n    ∀ n, C n :=\n  binaryRec' z₀ fun b n h ih =>\n    if h' : n = 0 then by\n      rw [h', h h']\n      exact z₁\n    else f b n h' ih\n#align nat.binary_rec_from_one Nat.binaryRecFromOne\n\n@[simp]\ntheorem zero_bits : bits 0 = [] := by simp [Nat.bits]\n#align nat.zero_bits Nat.zero_bits\n\n@[simp]\ntheorem bits_append_bit (n : ℕ) (b : Bool) (hn : n = 0 → b = true) :\n    (bit b n).bits = b :: n.bits := by\n  rw [Nat.bits, binaryRec_eq']\n  simpa\n#align nat.bits_append_bit Nat.bits_append_bit\n\n@[simp]\ntheorem bit0_bits (n : ℕ) (hn : n ≠ 0) : (bit0 n).bits = false :: n.bits :=\n  bits_append_bit n false fun hn' => absurd hn' hn\n#align nat.bit0_bits Nat.bit0_bits\n\n@[simp]\ntheorem bit1_bits (n : ℕ) : (bit1 n).bits = true :: n.bits :=\n  bits_append_bit n true fun _ => rfl\n#align nat.bit1_bits Nat.bit1_bits\n\n@[simp]\ntheorem one_bits : Nat.bits 1 = [true] := by\n  convert bit1_bits 0\n#align nat.one_bits Nat.one_bits\n\n-- TODO Find somewhere this can live.\n-- example : bits 3423 = [true, true, true, true, true, false, true, false, true, false, true, true]\n-- := by norm_num\n\ntheorem bodd_eq_bits_head (n : ℕ) : n.bodd = n.bits.headI := by\n  induction' n using Nat.binaryRec' with b n h _; · simp\n  simp [bodd_bit, bits_append_bit _ _ h]\n#align nat.bodd_eq_bits_head Nat.bodd_eq_bits_head\n\ntheorem div2_bits_eq_tail (n : ℕ) : n.div2.bits = n.bits.tail := by\n  induction' n using Nat.binaryRec' with b n h _; · simp\n  simp [div2_bit, bits_append_bit _ _ h]\n#align nat.div2_bits_eq_tail Nat.div2_bits_eq_tail\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/Bits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7652822868564688}}
{"text": "import data.sym2 -- allows us to use unordered pairs\n\n/-\nWe begin by defining a graph as a triple:\n- vertices;\n- edges;\n- and an endpoint map taking each edge to the unordered pair of its endpoints.\n-/\n\nstructure graph :=\n  (vertices : Type)\n  (edges : Type)\n  (endpoints : edges → sym2 vertices)\n\n/-\nNow we can define adjacency.\n-/\n\ndef are_adjacent (G : graph) (a b : G.vertices) : Prop := ∃ e : G.edges, G.endpoints(e) = ⟦(a,b)⟧\n\n/-\nWe now define a morphism of graphs to be a triple:\n- a map on vertices;\n- a map on edges;\n- and a compatability condition between the two maps.\n-/\n\nstructure morphism (G : graph) (H : graph) :=\n  (vertex_map : G.vertices → H.vertices)\n  (edge_map : G.edges → H.edges)\n  (compatability : H.endpoints ∘ edge_map = sym2.map vertex_map ∘ G.endpoints)\n\n/-\nWe want a convenient infix notation for a morphism.\n-/\n\ninfix `↦` :50 := morphism\n\n/-\nWe want to define composition of morphisms, so your first task is to prove that the\ncompatability condition needed holds when we do the `obvious' thing ... you will want \nto use the result sym2.map_comp.\n-/\n\n/- Lemma :\nFor all graphs $G$, $H$ and $K$ and for all morphisms $α : G → H$ and $β : H → K$, we have\n$ε_K ∘ β_e ∘ α_e = sym2 (β_v ∘ α_v) ∘ ε_G$.\n-/\nlemma compatability {G H K : graph} (α : G ↦ H) (β : H ↦ K) : K.endpoints ∘ β.edge_map ∘ α.edge_map = sym2.map (β.vertex_map ∘ α.vertex_map) ∘ G.endpoints :=\nbegin\n  sorry,\n\n\n\n\n  \nend", "meta": {"author": "barriecooper", "repo": "lean-graphs", "sha": "3f7be961f99fe084f950f52fe17c53e8093b5337", "save_path": "github-repos/lean/barriecooper-lean-graphs", "path": "github-repos/lean/barriecooper-lean-graphs/lean-graphs-3f7be961f99fe084f950f52fe17c53e8093b5337/src/game/morphisms-world/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008906, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7652822785756992}}
{"text": "-- Las funciones inyectivas tienen inversa por la izquierda\n-- ========================================================\n\nimport tactic\n\nopen classical function\n\nlocal attribute [instance] prop_decidable\n\nvariables {X Y : Type}\n\n-- ----------------------------------------------------\n-- Ej. 1. Definir la función\n--    inversa :: (X → Y) → X → (Y → X)\n-- tal que (inversa f d) es la función que a cada\n-- y ∈ Y le asigna\n-- + alguno de los elementos x tales que f(x) = y, si\n--   existen dichos elementos y\n-- + d, en caso contrario.\n-- ----------------------------------------------------\n\nnoncomputable def inversa (f : X → Y) (d : X) : Y → X :=\nλ y, if h : ∃ x, f x = y then some h else d\n\n-- Notación:\nvariable (f : X → Y)\nvariable (d : X)\nvariable (y : Y)\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar que si\n--    ∃ x, f x = y\n-- entonces,\n--    f ((inversa f d) y) = y\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample\n  (h : ∃ x, f x = y)\n  : f ((inversa f d) y) = y :=\ncalc f ((inversa f d) y)\n         = f (some h)  : congr rfl (dif_pos h)\n     ... = y           : some_spec h\n\n-- 2ª demostración\nlemma inversa_cuando_existe\n  (h : ∃ x, f x = y)\n  : f ((inversa f d) y) = y :=\nhave h1 : (inversa f d) y = some h,\n  from dif_pos h,\nhave h2 : f (some h) = y,\n  from some_spec h,\nshow f (inversa f d y) = y,\n  from eq.subst (eq.symm h1) h2\n\n-- ----------------------------------------------------\n-- Ej. 3. Demostrar que si f es inyectiva, entonces\n-- (inversa f d) es inversa de f por la izquierda.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample\n  (h : injective f)\n  : left_inverse (inversa f d) f :=\nbegin\n  intro x,\n  apply h,\n  rw inversa_cuando_existe f d,\n  use x,\nend\n\n-- 2ª demostración\nlemma inversa_es_inversa_por_la_izquierda\n  (h : injective f)\n  : left_inverse (inversa f d) f :=\nlet g := (inversa f d) in\nassume x,\nhave h1 : ∃ x', f x' = f x,\n  from exists.intro x rfl,\nhave h2 : f (g (f x)) = f x,\n  from inversa_cuando_existe f d (f x) h1,\nshow g (f x) = x,\n  from h h2\n\n-- ----------------------------------------------------\n-- Ej. 4. Demostrar que si f es inyectiva, entonces\n-- f tiene inversa por la izquierda.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample\n  (d : X)\n  (h : injective f)\n  : has_left_inverse f :=\nbegin\n  unfold has_left_inverse,\n  use (inversa f d),\n  exact (inversa_es_inversa_por_la_izquierda f d h),\nend\n\n-- 2ª demostración\nexample\n  (d : X)\n  (h : injective f)\n  : has_left_inverse f :=\nhave h1 : left_inverse (inversa f d) f,\n  from inversa_es_inversa_por_la_izquierda f d h,\nhave h2 : ∃ g, left_inverse g f,\n  from exists.intro (inversa f d) h1,\nshow has_left_inverse f,\n  from h2\n\n-- 3ª demostración\nexample\n  (d : X)\n  (h : injective f)\n  : has_left_inverse f :=\nhave h1 : left_inverse (inversa f d) f,\n  from inversa_es_inversa_por_la_izquierda f d h,\nshow has_left_inverse f,\n  from exists.intro (inversa f d) h1\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/Las_funciones_inyectivas_tienen_inversa_por_la_izquierda.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7652822776545757}}
{"text": "\nsection propositional\n\nvariables P Q R : Prop\n\n\n------------------------------------------------\n-- Proposições de dupla negaço:\n------------------------------------------------\n\ntheorem doubleneg_intro :\n  P → ¬¬P  :=\nbegin\n  intro h,\n  intro hnp,\n  contradiction,\n\nend\n\ntheorem doubleneg_elim :\n  ¬¬P → P  :=\nbegin\n  intro nnp,\n  by_contradiction hboom,\n  contradiction,\n\n\nend\n\ntheorem doubleneg_law :\n  ¬¬P ↔ P  :=\nbegin\n  split,\n  {\n    intro h,\n    by_contradiction hboom,\n    contradiction,\n  },\n  {\n    intro h,\n    intro hnp,\n    contradiction,\n  }\nend\n\n------------------------------------------------\n-- Comutatividade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_comm :\n  (P ∨ Q) → (Q ∨ P)  :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  {\n    right,\n    assumption\n\n  },\n  {\n    left,\n    assumption,\n  }\n\n\nend\n\ntheorem conj_comm :\n  (P ∧ Q) → (Q ∧ P)  :=\nbegin\n  intro h,\n  split,\n  {\n    cases h,\n    assumption\n  },\n  {\n    cases h,\n    assumption\n  }\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos →,∨:\n------------------------------------------------\n\ntheorem impl_as_disj_converse :\n  (¬P ∨ Q) → (P → Q)  :=\nbegin\n  intro h,\n  intro hp,\n  cases h with hnp hq,\n  {\n    contradiction,  \n  },\n  {\n    assumption,\n  }\nend\n\ntheorem disj_as_impl :\n  (P ∨ Q) → (¬P → Q)  :=\nbegin\n  intro h,\n  intro hnp,\n  cases h with hp hq,\n  {\n    contradiction,\n  },\n  {\n    assumption,\n  }\nend\n\n\n------------------------------------------------\n-- Proposições de contraposição:\n------------------------------------------------\n\ntheorem impl_as_contrapositive :\n  (P → Q) → (¬Q → ¬P)  :=\nbegin\n  intro h,\n  intro hq,\n  by_cases r : P,\n  {\n    have hq: Q := h r,\n    contradiction,\n  },\n  {\n    assumption,\n  }\nend\n\ntheorem impl_as_contrapositive_converse :\n  (¬Q → ¬P) → (P → Q)  :=\nbegin\n  intro h,\n  intro p,\n  by_cases r : Q,\n  {\n    assumption,\n  },\n  {\n    have hnp:¬P := h r,\n    contradiction,\n  }\nend\n\ntheorem contrapositive_law :\n  (P → Q) ↔ (¬Q → ¬P)  :=\nbegin\n  split,\n  {\n    intro h,\n    intro hnq,\n    by_contradiction hboom,\n    have hq:Q := h hboom,\n    contradiction, \n  },\n  {\n    intro h,\n    intro hp,\n    by_cases r: Q,\n    {\n      assumption,\n    },\n    {\n      have hnp:¬P := h r,\n      contradiction,\n    }\n  }\nend\n\n\n------------------------------------------------\n-- A irrefutabilidade do LEM:\n------------------------------------------------\n\ntheorem lem_irrefutable :\n  ¬¬(P∨¬P)  :=\nbegin\n  intro h,\n  by_cases x:P,\n  {\n    apply h,\n    left,\n    assumption\n  },\n  {\n    apply h,\n    right,\n    assumption,\n  }\n\nend\n\n\n------------------------------------------------\n-- A lei de Peirce\n------------------------------------------------\n\ntheorem peirce_law_weak :\n  ((P → Q) → P) → ¬¬P  :=\nbegin\n  intro h,\n  intro np,\n  apply np,\n  apply h,\n  intro p,\n  contradiction,\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∨,∧:\n------------------------------------------------\n\ntheorem disj_as_negconj :\n  P∨Q → ¬(¬P∧¬Q)  :=\nbegin\n  intro hpq,\n  intro npq,\n  cases npq with np nq,\n  cases hpq with hp hq,\n  {\n    contradiction,\n  },\n  {\n    contradiction,\n  }\nend\n\ntheorem conj_as_negdisj :\n  P∧Q → ¬(¬P∨¬Q)  :=\nbegin\n  intro hpq,\n  intro norpq,\n  cases hpq with p q,\n  cases norpq with np nq,\n  {\n    contradiction,\n  },\n  {\n    contradiction,\n  }\nend\n\n\n------------------------------------------------\n-- As leis de De Morgan para ∨,∧:\n------------------------------------------------\n\ntheorem demorgan_disj :\n  ¬(P∨Q) → (¬P ∧ ¬Q)  :=\nbegin\n  intro nhpq,\n  split,\n  {\n    intro np,\n    apply nhpq,\n    left,\n    assumption\n  },\n  {\n    intro nq,\n    apply nhpq,\n    right,\n    assumption,\n\n  }\nend\n\ntheorem demorgan_disj_converse :\n  (¬P ∧ ¬Q) → ¬(P∨Q)  :=\nbegin\n  intro cnpq,\n  intro porq,\n  cases cnpq with np nq,\n  cases porq with hp hq,\n  {\n    contradiction,\n  },\n  {\n    contradiction,\n  }\nend\n\ntheorem demorgan_conj :\n  ¬(P∧Q) → (¬Q ∨ ¬P)  :=\nbegin\n  intro nepq,\n  by_cases h:P,\n  {\n    left,\n    intro q,\n    apply nepq,\n    split,\n    {\n      assumption,\n    },\n    {\n      assumption,\n    }\n  },\n  {\n    right,\n    assumption,\n  }\nend\n\ntheorem demorgan_conj_converse :\n  (¬Q ∨ ¬P) → ¬(P∧Q)  :=\nbegin\n  intro nopq,\n  intro peq,\n  cases peq with p q,\n  cases nopq with nq np,\n  {\n    contradiction,\n  },\n  {\n    contradiction,\n  }\nend\n\ntheorem demorgan_conj_law :\n  ¬(P∧Q) ↔ (¬Q ∨ ¬P)  :=\nbegin\n  split,\n  {\n    intro npeq,\n    by_cases h:P,\n    {\n      left,\n      intro q,\n      apply npeq,\n      split,\n      {\n        assumption,\n      },\n      {\n        assumption,\n      }\n    },\n    {\n      right,\n      assumption,\n    },\n    \n    \n  },\n  {\n    intro norpq,\n    intro peq,\n    cases peq with p q,\n    cases norpq with np nq,\n    {\n      contradiction,\n    },\n    {\n      contradiction,\n    }\n  }\n  \nend\n\ntheorem demorgan_disj_law :\n  ¬(P∨Q) ↔ (¬P ∧ ¬Q)  :=\nbegin\n  split,\n  {\n    intro nopq,\n    split,\n    {\n      intro p,\n      apply nopq,\n      left,\n      assumption,\n    },\n    {\n      intro q,\n      apply nopq,\n      right,\n      assumption,\n    },\n  },\n  {\n    intro nepq,\n    intro pouq,\n    cases nepq with np nq,\n    cases pouq with p q,\n    {\n      contradiction,\n    },\n    {\n      contradiction,\n    }\n  }\nend\n\n------------------------------------------------\n-- Proposições de distributividade dos ∨,∧:\n------------------------------------------------\n\ntheorem distr_conj_disj :\n  P∧(Q∨R) → (P∧Q)∨(P∧R)  :=\nbegin\n  intro peqor,\n  cases peqor with p qr,\n  cases qr with q r,\n  {\n    left,\n    split,\n    {\n      assumption\n    },\n    {\n      assumption,\n    },\n  },\n  {\n    right,\n    split,\n    {\n      assumption,\n    },\n    {\n      assumption,\n    }\n  }\nend\n\ntheorem distr_conj_disj_converse :\n  (P∧Q)∨(P∧R) → P∧(Q∨R)  :=\nbegin\n  intro peqoper,\n  split,\n  {\n    cases peqoper with peq per,\n    {\n      cases peq with p q,\n      assumption,\n    },\n    {\n      cases per with p r,\n      assumption,\n    },\n  },\n  {\n    cases peqoper with peq per,\n    {\n      cases peq with p q,\n      left,\n      assumption,\n    },\n    {\n      cases per with p r,\n      right,\n      assumption,\n\n    }\n  }\nend\n\ntheorem distr_disj_conj :\n  P∨(Q∧R) → (P∨Q)∧(P∨R)  :=\nbegin\n  intro poqer,\n  split,\n  {\n    cases poqer with p qer,\n    {\n      left,\n      assumption,\n    },\n    {\n      cases qer with q r,\n      right,\n      assumption,\n    },\n  },\n  {\n    cases poqer with p qer,\n    {\n      left,\n      assumption,\n    },\n    {\n      cases qer with q r,\n      right,\n      assumption,\n    }\n  }\nend\n\ntheorem distr_disj_conj_converse :\n  (P∨Q)∧(P∨R) → P∨(Q∧R)  :=\nbegin\n  intro hpoqepor,\n  cases hpoqepor with hpoq por,\n  cases hpoq with p q,\n  {\n    left,\n    assumption,\n  },\n  {\n    cases por with p r,\n    {\n      left,\n      assumption,\n    },\n    {\n      right,\n      split,\n      {\n        assumption,\n      },\n      {\n        assumption,\n      },\n    }\n  }\n\nend\n\n\n------------------------------------------------\n-- Currificação\n------------------------------------------------\n\ntheorem curry_prop :\n  ((P∧Q)→R) → (P→(Q→R))  :=\nbegin\n  intro peq_tor,\n  intro p,\n  intro q,\n  apply peq_tor,\n  split,\n  {\n    assumption,\n  },\n  {\n    assumption,\n  }\n\nend\n\ntheorem uncurry_prop :\n  (P→(Q→R)) → ((P∧Q)→R)  :=\nbegin\n  intro p_to_q_to_r,\n  intro peq,\n  cases peq with p q,\n  apply p_to_q_to_r,\n  {\n    assumption,\n  },\n  {\n    assumption,\n  },\n\nend\n\n\n------------------------------------------------\n-- Reflexividade da →:\n------------------------------------------------\n\ntheorem impl_refl :\n  P → P  :=\nbegin\n  intro p,\n  assumption,\nend\n\n------------------------------------------------\n-- Weakening and contraction:\n------------------------------------------------\n\ntheorem weaken_disj_right :\n  P → (P∨Q)  :=\nbegin\n  intro p,\n  left,\n  assumption,\nend\n\ntheorem weaken_disj_left :\n  Q → (P∨Q)  :=\nbegin\n  intro q,\n  right,\n  assumption,\nend\n\ntheorem weaken_conj_right :\n  (P∧Q) → P  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  assumption,\nend\n\ntheorem weaken_conj_left :\n  (P∧Q) → Q  :=\nbegin\n  intro peq,\n  cases peq with p q,\n  assumption,\nend\n\ntheorem conj_idempot :\n  (P∧P) ↔ P :=\nbegin\n  split,\n  {\n    intro pep,\n    cases pep with p p',\n    {\n      assumption,\n    },\n  },\n  {\n    intro p,\n    split,\n    {\n      assumption,\n    },\n    {\n      assumption,\n    },\n  }\nend\n\ntheorem disj_idempot :\n  (P∨P) ↔ P  :=\nbegin\n  split,\n  {\n    intro pop,\n    cases pop with p p',\n    {\n      assumption\n    },\n    {\n      assumption,\n    },\n  },\n  {\n    intro p,\n    left,\n    assumption,\n  }\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 ∃,∀:\n------------------------------------------------\n\ntheorem demorgan_exists :\n  ¬(∃x, P x) → (∀x, ¬P x)  :=\nbegin\n  intro epx,\n  intro x,\n  by_contradiction hboom,\n  apply epx,\n  existsi x,\n  assumption,\nend\n\ntheorem demorgan_exists_converse :\n  (∀x, ¬P x) → ¬(∃x, P x)  :=\nbegin\n  intro napx,\n  intro nepx,\n  cases nepx with t ht,\n  exact(napx t) ht,\nend\n\ntheorem demorgan_forall :\n  ¬(∀x, P x) → (∃x, ¬P x)  :=\nbegin\n  rw contrapositive_law,\n  rw doubleneg_law,\n  intro epx,\n  intro x,\n  by_contradiction nPx,\n  apply epx,\n  existsi x,\n  exact nPx,\nend\n\ntheorem demorgan_forall_converse :\n  (∃x, ¬P x) → ¬(∀x, P x)  :=\nbegin\n  intro epx,\n  intro apx,\n  cases epx with x npx,\n  apply npx,\n  apply apx,\nend\n\ntheorem demorgan_forall_law :\n  ¬(∀x, P x) ↔ (∃x, ¬P x)  :=\nbegin\n  split,\n  {\n  rw contrapositive_law,\n  rw doubleneg_law,\n  intro epx,\n  intro x,\n  by_contradiction nPx,\n  apply epx,\n  existsi x,\n  exact nPx,\n  },\n  {\n    intro epx,\n    intro apx,\n    cases epx with x npx,\n    apply npx,\n    apply apx,\n  }\nend\n\ntheorem demorgan_exists_law :\n  ¬(∃x, P x) ↔ (∀x, ¬P x)  :=\nbegin\n  split,\n  {\n    intro epx,\n  intro x,\n  by_contradiction hboom,\n  apply epx,\n  existsi x,\n  assumption,\n  },\n  {\n    intro napx,\n  intro nepx,\n  cases nepx with t ht,\n  exact(napx t) ht,\n  }\nend\n\n\n------------------------------------------------\n-- Proposições de interdefinabilidade dos ∃,∀:\n------------------------------------------------\n\ntheorem exists_as_neg_forall :\n  (∃x, P x) → ¬(∀x, ¬P x)  :=\nbegin\n  intro epx,\n  intro apx,\n  cases epx with x Px,\n  exact(apx x) Px,\nend\n\ntheorem forall_as_neg_exists :\n  (∀x, P x) → ¬(∃x, ¬P x)  :=\nbegin\n  intro apx,\n  intro nepx,\n  cases nepx with x npx,\n  apply npx,\n  apply apx,\nend\n\ntheorem forall_as_neg_exists_converse :\n  ¬(∃x, ¬P x) → (∀x, P x)  :=\nbegin\n  intro nepx,\n  intro x,\n  by_contradiction hboom,\n  apply nepx,\n  existsi x,\n  exact hboom,\nend\n\ntheorem exists_as_neg_forall_converse :\n  ¬(∀x, ¬P x) → (∃x, P x)  :=\nbegin\n  rw contrapositive_law,\n  rw doubleneg_law,\n  intro nepx,\n  intro x,\n  by_contradiction pboom,\n  apply nepx,\n  existsi x,\n  exact pboom,\nend\n\ntheorem forall_as_neg_exists_law :\n  (∀x, P x) ↔ ¬(∃x, ¬P x)  :=\nbegin\n  split,\n  {\n    intro apx,\n  intro nepx,\n  cases nepx with x npx,\n  apply npx,\n  apply apx,\n  },\n  {\n    intro nepx,\n  intro x,\n  by_contradiction hboom,\n  apply nepx,\n  existsi x,\n  exact hboom,\n  }\nend\n\ntheorem exists_as_neg_forall_law :\n  (∃x, P x) ↔ ¬(∀x, ¬P x)  :=\nbegin\n  split,\n  {\n    intro epx,\n    intro apx,\n    cases epx with x Px,\n    exact(apx x) Px,\n  },\n  {\n    rw contrapositive_law,\n    rw doubleneg_law,\n    intro nepx,\n    intro x,\n    by_contradiction pboom,\n    apply nepx,\n    existsi x,\n    exact pboom,\n  }\nend\n\n\n------------------------------------------------\n--  Proposições de distributividade de quantificadores:\n------------------------------------------------\n\ntheorem exists_conj_as_conj_exists :\n  (∃x, P x ∧ Q x) → (∃x, P x) ∧ (∃x, Q x)  :=\nbegin\n  intro epq,\n  split,\n  {\n    sorry,\n  }\nend\n\ntheorem exists_disj_as_disj_exists :\n  (∃x, P x ∨ Q x) → (∃x, P x) ∨ (∃x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem exists_disj_as_disj_exists_converse :\n  (∃x, P x) ∨ (∃x, Q x) → (∃x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall :\n  (∀x, P x ∧ Q x) → (∀x, P x) ∧ (∀x, Q x)  :=\nbegin\n  sorry,\nend\n\ntheorem forall_conj_as_conj_forall_converse :\n  (∀x, P x) ∧ (∀x, Q x) → (∀x, P x ∧ Q x)  :=\nbegin\n  sorry,\nend\n\n\ntheorem forall_disj_as_disj_forall_converse :\n  (∀x, P x) ∨ (∀x, Q x) → (∀x, P x ∨ Q x)  :=\nbegin\n  sorry,\nend\n\n\n/- NOT THEOREMS --------------------------------\n\ntheorem forall_disj_as_disj_forall :\n  (∀x, P x ∨ Q x) → (∀x, P x) ∨ (∀x, Q x)  :=\nbegin\nend\n\ntheorem exists_conj_as_conj_exists_converse :\n  (∃x, P x) ∧ (∃x, Q x) → (∃x, P x ∧ Q x)  :=\nbegin\nend\n\n---------------------------------------------- -/\n\nend predicate\n", "meta": {"author": "Iojuara", "repo": "fmc1repo", "sha": "6576d5d22062c831bd50c0aa950b4c38472efe8b", "save_path": "github-repos/lean/Iojuara-fmc1repo", "path": "github-repos/lean/Iojuara-fmc1repo/fmc1repo-6576d5d22062c831bd50c0aa950b4c38472efe8b/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.8104789040926007, "lm_q1q2_score": 0.7652354258428119}}
{"text": "-- Prueba por induccion 7: (∀ n ∈ ℕ) n ≠ 0 → succ (pred n) = n\n-- ===========================================================\n\nimport data.nat.basic\nopen nat\n\nvariable (n : ℕ)\n\n-- ?ª demostración\nexample : n ≠ 0 → succ (pred n) = n :=\nbegin\n  cases n,\n  { intro h,\n    contradiction, },\n  { intro h,\n    rw pred_succ, },\nend\n\n-- ?ª demostración\nexample : n ≠ 0 → succ (pred n) = n :=\nby cases n; simp\n\n-- ?ª demostración\nexample : n ≠ 0 → succ (pred n) = n :=\nnat.cases_on n\n  (assume h : 0 ≠ 0,\n    show succ (pred 0) = 0,\n      from absurd rfl h)\n  (assume n,\n    assume h : succ n ≠ 0,\n    show succ (pred (succ n)) = succ n,\n      by rw pred_succ)\n\n-- ?ª demostración\nexample : n ≠ 0 → succ (pred n) = n :=\nnat.cases_on n\n  (λ h, absurd rfl h)\n  (λ n h, by rw pred_succ)\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_7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7651429884020131}}
{"text": "/-\nM1F 2017-18 Sheet 1 Question 2 to 4 solutions.\nAuthor : Kevin Buzzard\nThis file should work with any version of lean -- whether you installed it yourself\nor are running the version on https://leanprover.github.io/live/latest/\n-/\n-- We probably need the \"law of the excluded middle\" for this question -- every\n-- proposition is either true or false! Don't even ask me to explain what the\n-- other options are, but Lean does not come with this axiom by default (blame\n-- the computer scientists) and mathematicians have to add it themselves.\n-- It's easy to add though. \"em\" for excluded middle.\n\naxiom em (X : Prop) : X ∨ ¬ X\n\n\nvariables P Q R S : Prop -- A \"Prop\" is a proposition, that is, a true/false statement.\n\n-- Sheet 1 Q3. Prove one result and delete the other.\n\n-- theorem m1f_sheet01_q03_is_T (HP : P) (HnQ : ¬ Q) (HnR : ¬ R) (HS : S) : (R → S) → (P → Q) :=\n\ntheorem m1f_sheet01_q03_is_F (HP : P) (HnQ : ¬ Q) (HnR : ¬ R) (HS : S) : ¬ ((R → S) → (P → Q)) :=\nbegin\nintro H,\nhave HRS : R → S,\n  intro HR,\n  contradiction,\nhave HPQ : P → Q,\n  exact H HRS,\nhave HQ : Q,\n  exact HPQ HP,\n-- now we have Q and not Q\ncontradiction,\nend\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/0103/S0103.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7651429864516556}}
{"text": "/-\nCopyright (c) 2019 Jean Lo. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Jean Lo\n-/\nimport topology.metric_space.hausdorff_distance\n\n/-!\n# Riesz's lemma\n\nRiesz's lemma, stated for a normed space over a normed field: for any\nclosed proper subspace F of E, there is a nonzero x such that ∥x - F∥\nis at least r * ∥x∥ for any r < 1.\n-/\n\nvariables {𝕜 : Type*} [normed_field 𝕜]\nvariables {E : Type*} [normed_group E] [normed_space 𝕜 E]\n\n/-- Riesz's lemma, which usually states that it is possible to find a\nvector with norm 1 whose distance to a closed proper subspace is\narbitrarily close to 1. The statement here is in terms of multiples of\nnorms, since in general the existence of an element of norm exactly 1\nis not guaranteed. -/\nlemma riesz_lemma {F : subspace 𝕜 E} (hFc : is_closed (F : set E))\n  (hF : ∃ x : E, x ∉ F) {r : ℝ} (hr : r < 1) :\n  ∃ x₀ : E, x₀ ∉ F ∧ ∀ y ∈ F, r * ∥x₀∥ ≤ ∥x₀ - y∥ :=\nbegin\n  classical,\n  obtain ⟨x, hx⟩ : ∃ x : E, x ∉ F := hF,\n  let d := metric.inf_dist x F,\n  have hFn : (F : set E).nonempty, from ⟨_, F.zero_mem⟩,\n  have hdp : 0 < d,\n    from lt_of_le_of_ne metric.inf_dist_nonneg (λ heq, hx\n    ((metric.mem_iff_inf_dist_zero_of_closed hFc hFn).2 heq.symm)),\n  let r' := max r 2⁻¹,\n  have hr' : r' < 1, by { simp [r', hr], norm_num },\n  have hlt : 0 < r' := lt_of_lt_of_le (by norm_num) (le_max_right r 2⁻¹),\n  have hdlt : d < d / r', from (lt_div_iff hlt).mpr ((mul_lt_iff_lt_one_right hdp).2 hr'),\n  obtain ⟨y₀, hy₀F, hxy₀⟩ : ∃ y ∈ F, dist x y < d / r' :=\n    metric.exists_dist_lt_of_inf_dist_lt hdlt hFn,\n  have x_ne_y₀ : x - y₀ ∉ F,\n  { by_contradiction h,\n    have : (x - y₀) + y₀ ∈ F, from F.add_mem h hy₀F,\n    simp only [neg_add_cancel_right, sub_eq_add_neg] at this,\n    exact hx this },\n  refine ⟨x - y₀, x_ne_y₀, λy hy, le_of_lt _⟩,\n  have hy₀y : y₀ + y ∈ F, from F.add_mem hy₀F hy,\n  calc\n    r * ∥x - y₀∥ ≤ r' * ∥x - y₀∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _)\n    ... < d : by { rw ←dist_eq_norm, exact (lt_div_iff' hlt).1 hxy₀ }\n    ... ≤ dist x (y₀ + y) : metric.inf_dist_le_dist_of_mem hy₀y\n    ... = ∥x - y₀ - y∥ : by { rw [sub_sub, dist_eq_norm] }\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/normed_space/riesz_lemma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8670357683915538, "lm_q1q2_score": 0.7650965205606501}}
{"text": "import game.world8.level7 -- hide\nnamespace mynat -- hide\n\n/-\n\n# Advanced Addition World\n\n## Level 8: `eq_zero_of_add_right_eq_self`\n\nThe lemma you're about to prove will be useful when we want to prove that $\\leq$ is antisymmetric.\nThere are some wrong paths that you can take with this one.\n-/\n\n/- Lemma\nIf $a$ and $b$ are natural numbers such that \n$$ a + b = a, $$\nthen $b = 0$.\n-/\n\nlemma eq_zero_of_add_right_eq_self {a b : mynat} : a + b = a → b = 0 :=\nbegin [nat_num_game]\n  intro h,\n  apply add_left_cancel a,\n  rw h,\n  rw add_zero,\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/level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693702514737, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.765084222427817}}
{"text": "import .group_representation\nimport .sub_module\nimport linear_algebra.determinant\nimport linear_algebra.matrix\nimport group_theory.group_action\nimport init.algebra.functions\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 `•` an action of `G` on `X`. Let `R` be a ring, \n    let `M = R → X` be the free-module over `M` of base `X`. For `v : R → X` and `g ∈ G` the formula  \n    `ρ g v := g⁻¹ • v` define a permutation de representation.  \n -/\n\ndef rho  (g : G)  : (X → R) → (X → R)  := λ  v x,  v (g⁻¹ •  x)\n\ndef rho_linear (g : G) : (X → R) →ₗ[R] (X → R) := { to_fun := rho R X g,\n  add := by { intros, exact rfl},\n  smul := by {intros, exact rfl}\n  }\n\nlemma rho_apply (g : G)(v : X → R)(x : X) : rho R  X g v x  = v (g⁻¹ • x) := rfl  \n\nlemma rho_mul (σ τ  : G) : rho R X (σ * τ) = rho R X σ  ∘  rho R X τ := begin \n        ext v x, rw rho_apply, rw  mul_inv_rev, rw  mul_smul, exact rfl,    \nend \nlemma rho_one  : rho R X (1 : G) = id := begin \n   ext x v, rw rho_apply, rw one_inv, rw one_smul, exact rfl,\nend\nlemma rho_right_inv (g : G) : (rho R X g : (X → R) →  (X → R)) ∘  (rho R X g⁻¹) = id  := begin \n    rw ← rho_mul, rw mul_inv_self, rw rho_one,\nend\n\nlemma rho_left_inv  (g : G) : (  rho R X (g⁻¹ )  : \n(X → R) → (X → R) ) ∘    (rho R X g : (X → R) → (X → R))  = id  :=  \nbegin \n    rw ← rho_mul, rw inv_mul_self, rw rho_one, \nend\n\n/--\n    a linear equivalence is a structure that formalize `M ≃ₗ[R]M` : group of invertible \n    linear morphism  `f : M →ₗ M`  \n-/\ndef rho_equiv (g : G) : (X → R) ≃ (X → R) := { to_fun := rho R X g,\n  inv_fun := rho R X g⁻¹ ,\n  left_inv :=  begin intros x,ext, change (rho R X g⁻¹ ∘ rho R X g ) x x_1 = x x_1, rw rho_left_inv , exact rfl,   end,\n  right_inv := begin intros x,ext, erw ← function.comp_apply (rho R X g)  _, rw rho_right_inv, exact rfl, end }\n\ndef rho_equiv_lin (g : G) : (X → R) ≃ₗ[R] (X → R) := {\n   .. rho_linear R X g,   .. rho_equiv R X g\n}\n\nlemma rho_equiv_lin_ext ( g : G): ((rho_equiv_lin R X g) : (X → R) → (X → R) ) =  rho R X g  := rfl\n\ndef Perm : group_representation G R (X → R) := { \n  to_fun :=  rho_equiv_lin R X ,\n  map_one' := begin  ext,rw rho_equiv_lin_ext, rw rho_one, exact rfl, end,\n  map_mul' := begin  intros,ext,rw rho_equiv_lin_ext, rw rho_mul, exact rfl, end }\nvariables (g : G) (x y : X → R)\n#check Perm R X  \n\nexample (g : G) (x y : X → R) (r : R) : true := begin \n        let ρ := @Perm G R X,\n        have f : ρ 1 = 1,\n            rw ρ.map_one,  \n        have : ρ g (x+y) = ρ g x +ρ g y, \n            rw (ρ g).map_add,\n        \n        trivial,\n        end", "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/action.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693688269984, "lm_q2_score": 0.8056321889812553, "lm_q1q2_score": 0.7650842124165418}}
{"text": "#eval 1+1\n\nconstant m : nat\n#check m\n\n\ndef sum_of_first_n_nat : ℕ → ℕ\n| 0 := 0\n| (nat.succ n) := (nat.succ n) + sum_of_first_n_nat n\n\n\n#eval sum_of_first_n_nat 5\n\n\ntheorem closed_eq_sum_of_first_n_nat (n : ℕ) :\n    2 * (sum_of_first_n_nat n) = n * (nat.succ n) :=\nbegin\n\ninduction n with d hd,\nrw sum_of_first_n_nat,\nrw nat.mul_zero,\nrw nat.zero_mul,\n\nrw sum_of_first_n_nat,\nrw nat.left_distrib,\nrw hd,\n\n--rewrites nat.succ n to n + 1:\nrw nat.succ_eq_add_one,\n--rewrites nat.succ (n + m) to n + nat.succ m (from defn of addition)     \n--note rw usually rewrites from left to right over an equality; ← (\\l) does right to left\nrw ← nat.add_succ,\n--rewrites nat.succ 1 to 2 (for clarity)\nrw (show nat.succ 1 = 2, by refl),\n--multiplies out d + 1\nrw left_distrib (d + 1) d 2,\n--moving things around with commutativity\nrw mul_comm 2 (d + 1),\nrw mul_comm d (d + 1),\nrw add_comm,\n\n\n\nend\n", "meta": {"author": "lionel-git", "repo": "TestLean", "sha": "83d79fb0575b89571e473ea342e28344399f31eb", "save_path": "github-repos/lean/lionel-git-TestLean", "path": "github-repos/lean/lionel-git-TestLean/TestLean-83d79fb0575b89571e473ea342e28344399f31eb/Lean3/src/testProof.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191309994468, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.7649163808252913}}
{"text": "import data.real.basic\nopen function\n\n/-\n# Chapter 6 : Functions\n\n## Level 2\n\nA classical result in composition of functions.\n-/\n\n/- Lemma\nIf $f : X \\to Y$ and $g : Y \\to Z$ are both surjective functions, then\nthe function resulting from their composition is also surjective.\n-/\ntheorem both_surjective\n    (X Y Z : set ℝ) (f : X → Y) (g : Y → Z) : \n    surjective f ∧ surjective g → surjective (g ∘ f) :=\nbegin\n    intros H z,\n    cases H with sf sg,\n    have hy : ∃ y : Y, g y = z, from sg z,\n    cases hy with y gy,\n    have hx : ∃ x : X, f x = y, from sf y,\n    cases hx with x fx,\n    use x, rw ← gy, rw ← fx, done\nend\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/bothSurjective.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7649137348643733}}
{"text": "import data.real.basic\n\nvariables a b c : ℝ\n\n#check mul_comm b a\n#check mul_assoc c b a\n\nexample (a b c : ℝ) : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b, \n  /- mul_comm a b refers to the commutative law for multiplication \n  on a and b: a * b = b * a. 'rw mul_comm a b' tells Lean to replace\n  a * b with b * a in the goal. Now the goal becomes (b * a) * c = \n  b * (a * c). -/\n  \n  rw mul_assoc b a c,\n  /- mul_assoc b a c refers to the associative law for multiplication \n  on b, a, and c: b * a * c = b * (a * c). Note that Lean leaves out \n  parentheses when possible. Since multiplication is left-associative,\n  the left-hand side of mul_assoc b * a * c refers to (b * a) * c. \n  'rw mul_assoc b a c' solves the goal b * a * c = b * (a * c), and hence, \n  completes the proof. -/\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/1_rw/ex1_rw_mul_comm_assoc.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966732132747, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7649137317064271}}
{"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 : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε\n\n\n/-- The limit of a constant sequence is the constant. -/\ntheorem is_limit_const (c : ℝ) : is_limit (λ n, c) c :=\nbegin\n  intros e se,\n  use 0,\n  intros n sn,\n  simp,\n  exact se,\nend\n\n-- We will chose ε later...\ntheorem is_limit_add {a b : ℕ → ℝ} {l m : ℝ}\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| ↔ a ≠ 0`\n-- `div_pos : 0 < a → 0 < b → 0 < a / b`\n-- `abs_mul x y : |x * y| = |x| * |y|`\n-- `lt_div_iff' : 0 < c → (a < b / c ↔ 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 : ℕ → ℝ} {l c : ℝ} (h : is_limit a l) :\n  is_limit (λ n, c * (a n)) (c * l) :=\nbegin\n  sorry,\nend\n\ntheorem sandwich (a b c : ℕ → ℝ)\n  (l : ℝ) (ha : is_limit a l) (hc : is_limit c l) \n  (hab : ∀ n, a n ≤ b n) (hbc : ∀ n, b n ≤ c n) : is_limit b l :=\nbegin\n  sorry,\nend\n\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/Ccourse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7648978569617813}}
{"text": "namespace hidden\n\n-- BEGIN\ninductive nat : Type\n| zero : nat\n| succ : nat → nat\n-- END\n\n@[pattern]\ndef Z := nat.zero\n@[pattern]\ndef S := nat.succ\n\ndef K₁ := S Z\ndef K₂ := S K₁\ndef K₃ := S K₂\ndef K₄ := S K₃\ndef K₅ := S K₄\n\ndef pred: nat -> nat\n| Z := Z\n| (S n) := n\n.\ntheorem pr₀ : pred Z = Z := rfl.\ntheorem pr₁ : pred K₁ = Z := rfl.\ntheorem pr₂ : pred K₂ = K₁ := rfl.\n\ntheorem pred_succ_zero (n: nat): pred (S n) = n := rfl.\n\ndef sub: nat -> nat -> nat\n| n Z := n\n| n (S m) := pred (sub n m)\n.\n#reduce sub Z K₂\n#reduce sub K₅ K₂\n\nexample: sub Z K₅ = Z := rfl.\ntheorem sub_n_0: ∀(n: nat), sub n Z = n\n| Z := rfl\n| (S n) := rfl\n\ntheorem sub_0_m: ∀ (m:nat), sub Z m = Z\n| Z := rfl\n| (S m) := by rw[sub, sub_0_m]; reflexivity.\n\nlemma sub_succ (n m: nat): sub (S n) (S m) = sub n m := begin\ninduction m,\ncase nat.zero: {\n  reflexivity\n},\ncase nat.succ: m ih {\n  have: sub (S n) (S (S m)) = pred (sub (S n) (S m)), from rfl,\n  have: sub (S n) (S (S m)) = pred (sub n m), by rw[this, ih],\n  have: pred (sub n m) = sub n (S m), by reflexivity,\n  assumption\n}\nend\n\ntheorem sub_n_n: ∀(n: nat), sub n n = Z\n| Z := rfl\n| (S n) := by rw[sub_succ, sub_n_n]\n.\n\ndef add: nat -> nat -> nat\n| m Z := m\n| m (S n) := S (add m n)\n.\n\nlemma add_n_succ (m n: nat): add m (S n) = S (add m n) := rfl.\nlemma add_m_succ (m: nat): ∀ (n: nat), add (S m) n = S (add m n)\n| Z := rfl\n| (S n) := begin\n  simp [add_n_succ],\n  rw add_m_succ,\nend\n\nlemma add_m_0 (m: nat): add m Z = m := rfl. \nlemma add_0_n: ∀ (n: nat), add Z n = n\n| Z := rfl\n| (S n) := by simp [add_n_succ, add_0_n n]\n.\n\ntheorem add_assoc (a b: nat): ∀(c: nat), add (add a b) c = add a (add b c)\n| Z := rfl\n| (S c) := by simp[add_n_succ, add_assoc c]\n.\n\ntheorem add_comm (m: nat): ∀(n: nat), add m n = add n m\n| Z := by simp[add_m_0, add_0_n]\n| (S n) := by simp[add_n_succ, add_m_succ, add_comm n]\n.\n\n#reduce add K₁ K₂\n\ndef mul: nat -> nat -> nat\n| _ Z := Z\n| m (S n) := add m (mul m n)\n.\n#reduce mul Z K₂\n#reduce mul K₂ Z\n#reduce mul K₁ K₂\n#reduce mul K₂ K₂\n#reduce mul K₅ K₂\n\nlemma mul_succ_n (m n: nat): mul m (S n) = add m (mul m n) := rfl.\nlemma mul_succ_m (m: nat): ∀ (n: nat), mul (S m) n = add (mul m n) n\n| Z := rfl\n| (S n) := by simp[mul_succ_n, mul_succ_m n, add_n_succ, add_m_succ, add_assoc]\n.\n\ntheorem mul_m_0 (m: nat): mul m Z = Z := rfl.\ntheorem mul_0_n: ∀ (n: nat), mul Z n = Z\n| Z := rfl\n| (S n) := by simp[mul_succ_n, mul_0_n n]; reflexivity\n.\n\ntheorem mul_m_1 (m: nat): mul m K₁ = m := rfl\ntheorem mul_1_n (n: nat): mul K₁ n = n := begin\n  rw [K₁],\n  simp [mul_succ_m, mul_0_n, add_0_n],\nend\n\ntheorem mul_comm (m: nat): ∀(n: nat), mul m n = mul n m\n| Z := by simp[mul_m_0, mul_0_n]\n| (S n) := by simp [mul_succ_n, mul_succ_m, mul_comm n, add_comm]\n.\n\ntheorem mul_dist (b c: nat): ∀ (a: nat), mul a (add b c) = add (mul a b) (mul a c) \n| Z := by simp [mul_0_n]; reflexivity\n| (S a) := begin\n  simp[mul_succ_m, add_assoc, mul_dist a],\n  rw [<-add_assoc (mul a c), add_comm (mul a c), <-add_assoc b],\nend\n\ntheorem mul_assoc (a b: nat): ∀(c: nat), mul (mul a b) c = mul a (mul b c)\n| Z := rfl\n| (S c) := by simp[mul_succ_n, mul_assoc c, mul_dist]\n.\n\ntheorem succ_nonzero (n: nat): S n ≠ Z := by trivial.\ndef nonzero := {n: nat // n ≠ Z}\ndef nonzero.mk (n: nat) (h: n ≠ Z): nonzero := ⟨n,h⟩\ndef nz := nonzero.mk.\n#check nz K₂ (by apply succ_nonzero)\n\ndef pow: nonzero -> nat -> nat\n| _ Z := K₁\n| m (S n) := mul m.val (pow m n)\n\ndef nzK₁ := nz (S Z) (by apply succ_nonzero)\ndef nzK₂ := nz (S K₁) (by apply succ_nonzero)\ndef nzK₃ := nz (S K₂) (by apply succ_nonzero)\ndef nzK₄ := nz (S K₃) (by apply succ_nonzero)\ndef nzK₅ := nz (S K₄) (by apply succ_nonzero)\n\n#reduce pow nzK₂ Z\n#reduce pow nzK₁ K₂\n#reduce pow nzK₂ K₂\n#reduce pow nzK₃ K₂\n\ntheorem pow_by_0 (m: nonzero): pow m Z = K₁ := rfl.\ntheorem pow_by_1 (m: nonzero): pow m K₁ = m.val := rfl.\ntheorem pow_by_succ (m: nonzero) (n: nat): pow m (S n) = mul m.val (pow m n) := rfl.\ntheorem pow_of_1: ∀ (n: nat), pow nzK₁ n = K₁\n| Z := rfl\n| (S n) := begin\n  have o: nzK₁.val = K₁, from rfl,\n  have: pow nzK₁ (S n) = mul nzK₁.val (pow nzK₁ n), by rw [pow_by_succ],\n  simp [o, mul_1_n] at this,\n  simp [pow_of_1 n] at this, assumption\nend\n\ntheorem pow_by_add (m: nonzero) (a: nat): ∀(b: nat), pow m (add a b) = mul (pow m a) (pow m b)\n| Z := rfl\n| (S b) := by simp [add_n_succ, pow_by_succ, pow_by_add b, mul_comm, mul_assoc].\n\nend hidden", "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/8.9.2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7648978545983875}}
{"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ölzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.polynomial.basic\nimport data.finset.nat_antidiagonal\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 : ℕ}\n\nvariables [semiring R] {p q r : polynomial R}\n\nsection coeff\n\nlemma coeff_one (n : ℕ) : 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 : ℕ) : coeff (p + q) n = coeff p n + coeff q n := rfl\n\nlemma coeff_sum [semiring S] (n : ℕ) (f : ℕ → R → polynomial S) :\n  coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) := finsupp.sum_apply\n\nlemma sum_def [add_comm_monoid S] (f : ℕ → R → S) :\n  p.sum f = ∑ n in p.support, f n (p.coeff n) :=\nrfl\n\n@[simp] lemma coeff_smul (p : polynomial R) (r : R) (n : ℕ) :\ncoeff (r • p) n = r * coeff p n := finsupp.smul_apply _ _ _\n\n@[simp] lemma mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 :=\nby simp [support, coeff]\n\nlemma not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 :=\nby simp\n\nvariable (R)\n/-- The nth coefficient, as a linear map. -/\ndef lcoeff (n : ℕ) : polynomial R →ₗ[R] R :=\nfinsupp.lapply n\nvariable {R}\n\n@[simp] lemma lcoeff_apply (n : ℕ) (f : polynomial R) : lcoeff R n f = coeff f n := rfl\n\n@[simp] lemma finset_sum_coeff {ι : Type*} (s : finset ι) (f : ι → polynomial R) (n : ℕ) :\n  coeff (∑ b in s, f b) n = ∑ b in s, coeff (f b) n :=\n(s.sum_hom (λ q : polynomial R, lcoeff R n q)).symm\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 : ℕ) :\n  coeff (p * q) n = ∑ x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=\nadd_monoid_algebra.mul_apply_antidiagonal p q n _ (λ x, nat.mem_antidiagonal)\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 : ℕ) :\n  coeff (C x * X^k : polynomial R) n = if n = k then x else 0 :=\nby rw [← single_eq_C_mul_X]; simp [monomial, single, eq_comm, coeff]; congr\n\n@[simp] lemma coeff_C_mul (p : polynomial R) : coeff (C a * p) n = a * coeff p n :=\nadd_monoid_algebra.single_zero_mul_apply p a n\n\nlemma C_mul' (a : R) (f : polynomial R) : C a * f = a • f :=\next $ λ n, coeff_C_mul f\n\n@[simp] lemma coeff_mul_C (p : polynomial R) (n : ℕ) (a : R) :\n  coeff (p * C a) n = coeff p n * a :=\nadd_monoid_algebra.mul_single_zero_apply p a n\n\nlemma coeff_X_pow (k n : ℕ) :\n  coeff (X^k : polynomial R) n = if n = k then 1 else 0 :=\nby { simp only [X_pow_eq_monomial, monomial, single, eq_comm], congr }\n\n@[simp]\nlemma coeff_X_pow_self (n : ℕ) :\n  coeff (X^n : polynomial R) n = 1 :=\nby simp [coeff_X_pow]\n\ntheorem coeff_mul_X_pow (p : polynomial R) (n d : ℕ) :\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 ⟨i,j⟩ 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 λ h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }\nend\n\nlemma coeff_mul_X_pow' (p : polynomial R) (n d : ℕ) :\n  (p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 :=\nbegin\n  split_ifs,\n  { rw [←@nat.sub_add_cancel d n h, coeff_mul_X_pow, nat.add_sub_cancel] },\n  { refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ 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 : ℕ) :\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 : ℕ}\n  (H : p * X ^ n = 0) : p = 0 :=\next $ λ 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 : ℕ) : C c * X^n = monomial n c :=\nby { ext1, rw [monomial_eq_smul_X, coeff_smul, coeff_C_mul] }\n\nlemma support_mul_X_pow (c : R) (n : ℕ) (H : c ≠ 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 : ℕ} : (C c * X^n).support ⊆ singleton n :=\nby { rw [C_mul_X_pow_eq_monomial], exact support_monomial' n c }\n\nlemma C_dvd_iff_dvd_coeff (r : R) (φ : polynomial R) :\n  C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i :=\nbegin\n  split,\n  { rintros ⟨φ, rfl⟩ c, rw coeff_C_mul, apply dvd_mul_right },\n  { intro h,\n    choose c hc using h,\n    classical,\n    let c' : ℕ → R := λ i, if i ∈ φ.support then c i else 0,\n    let ψ : polynomial R := ∑ i in φ.support, monomial i (c' i),\n    use ψ,\n    ext i,\n    simp only [ψ, 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\nend coeff\n\nopen submodule polynomial set\n\nvariables {f : polynomial R} {I : submodule (polynomial R) (polynomial R)}\n\n/--  If the coefficients of a polynomial belong to n ideal contains the submodule span of the\ncoefficients of a polynomial. -/\nlemma span_le_of_coeff_mem_C_inverse (cf : ∀ (i : ℕ), f.coeff i ∈ (C ⁻¹' I.carrier)) :\n  (span (polynomial R) {g | ∃ i, g = C (f.coeff i)}) ≤ I :=\nbegin\n  refine bInter_subset_of_mem _,\n  rintros _ ⟨i, rfl⟩,\n  exact set_like.mem_coe.mpr (cf i),\nend\n\nlemma mem_span_C_coeff :\n  f ∈ span (polynomial R) {g : polynomial R | ∃ i : ℕ, g = (C (coeff f i))} :=\nbegin\n  rw [← f.sum_single] {occs := occurrences.pos [1]},\n  refine sum_mem _ (λ i hi, _),\n  change monomial i _ ∈ span _ _,\n  rw [← C_mul_X_pow_eq_monomial, ← X_pow_mul, ← smul_eq_mul],\n  exact smul_mem _ _ (subset_span ⟨i, rfl⟩),\nend\n\nlemma exists_coeff_not_mem_C_inverse :\n  f ∉ I → ∃ i : ℕ , coeff f i ∉ (C ⁻¹'  I.carrier) :=\nimp_of_not_imp_not _ _\n  (λ cf, not_not.mpr ((span_le_of_coeff_mem_C_inverse (not_exists_not.mp cf)) mem_span_C_coeff))\n\nsection cast\n\n@[simp] lemma nat_cast_coeff_zero {n : ℕ} {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 : ℕ} {R : Type*} [semiring R] [char_zero R] : (↑m : polynomial R) = ↑n ↔ m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (λ p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\n@[simp] lemma int_cast_coeff_zero {i : ℤ} {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 : ℤ} {R : Type*} [ring R] [char_zero R] : (↑m : polynomial R) = ↑n ↔ m = n :=\nbegin\n  fsplit,\n  { intro h,\n    apply_fun (λ p, p.coeff 0) at h,\n    simpa using h, },\n  { rintro rfl, refl, },\nend\n\nend cast\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/coeff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582997, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7648978507124155}}
{"text": "/-\nCOMP2009-ACE\n\nExercise 02 (Propositional logic)\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  and type checker. \n    In the 2nd part we play logic poker again :-) but this time for\n    predicate logic. \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-/\n\nnamespace family\n\n-- Given the following type, predicates and relations:\n\nconstant People : Type\nconstants Male Female : People → Prop\n-- Male x means x is male\n-- Female x means x is fmeale\nconstant Parent : People → People → Prop\n-- Parent x y means x is a parent of y\nconstant Married : People → People → Prop\n-- Married x y means x is married to y\n\n/-\nDefine the following relations (People → People → 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 in t\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 ∧ Male x\n\n-- insert your definitions here\ndef Sibling (x y :People) :Prop\n  := (x ≠ y) ∧ ( ∃ h : People, Parent h x ∧ Parent h y )\n  \ndef Brother (x y : People) : Prop\n--two person have same parent\n  := Male x ∧ Sibling  x y \n\ndef Mother (x y : People) : Prop\n  := Parent x y ∧ Female x\n\ndef Grandmother (x y : People) : Prop\n--the mother of one's father or mother.\n  := ∃ z : People, Mother x z ∧ Parent z y \n\ndef FatherInLaw (x y : People) : Prop \n--the father of one's husband or wife.\n  := ∃ h : People, Father x h ∧  Married y h\n\ndef SisterInLaw (x y : People) : Prop \n--the wife of one's brother or sister\n  := Female x ∧ (∃ z : People, Married x z ∧ Sibling z y )\n\ndef Uncle (x y : People) : Prop\n--the brother of one's father or mother\n  := ∃ z : People, Brother x z ∧ Parent z y\n  \nend family\n\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 ∨ ¬ P or raa : ¬¬ P → 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 → Prop\nvariables RR : A → A → Prop\nvariables P Q R : Prop\n\nopen classical\n\ntheorem raa : ¬ ¬ P → 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 : (∀ x:A, ∃ y : A , RR x y) → (∃ y : A, ∀ x : A, RR x y) :=\nbegin-- c)  not provable classically\n  sorry,\nend\n\ntheorem ex02 :  (∃ y : A, ∀ x : A, RR x y) → (∀ x:A, ∃ y : A , RR x y) :=\nbegin --a) provable intuitionistically\n  assume h,\n  assume x,\n  cases h with y rr,\n  existsi y,\n  apply rr,\nend\n\ntheorem ex03 : ∀ x y : A, x = y → RR x y → RR x x :=\nbegin --b) provable classically\n  assume a b pp,\n  assume hab,\n  apply raa,\n  assume h,\n  have h1: ¬ RR a b,\n  rewrite ← pp,\n  exact h,\n  apply h1,\n  exact hab,\nend\n\ntheorem ex04 : ∀ x y z : A, x ≠ y → x ≠ z → y ≠ z :=\nbegin -- c) not provable classically\n  sorry,\nend\n\ntheorem ex05 : ∀ x y z : A, x = y → x ≠ z → y ≠ z :=\nbegin --a) provable intuitionistically\n  assume x y z pp,\n  assume xz,\n  rewrite ← pp,\n  exact xz,\nend\n\ntheorem ex06 : ∀ x y z : A, x ≠ y → (x ≠ z ∨ y ≠ z) :=\nbegin --b) provable classically\n  assume x y z xy,\n  cases(em (y=z)) with xz nxz,\n  left,\n  rewrite ← xz,\n  exact xy,\n  right,\n  assume yz,\n  apply nxz,\n  exact yz,\nend\n\ntheorem ex07 : ¬ ¬ (∀ x : A, PP x) → ∀ x : A, ¬ ¬ PP x :=\nbegin --a) provable intuitionistically\n  assume h,\n  assume a npp,\n  apply h,\n  assume pp,\n  apply npp,\n  apply pp,\nend\n\ntheorem ex08 : (∀ x : A, ¬ ¬ PP x) → ¬ ¬ ∀ x : A, PP x :=\nbegin --b) provable classically\n  assume nnpp,\n  assume npp,\n  apply npp,\n  assume a,\n  apply raa,\n  assume nppa,\n  apply nnpp,\n  exact nppa,\nend\n\ntheorem ex09 : (∃ x : A, true) → (∃ x:A, PP x) → ∀ x : A,PP x :=\nbegin ---c) not provable classically\n  sorry\nend\n\n\ntheorem aux_thm: (¬ ∀ (x : A), PP x) →   ∃ x : A, ¬ 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 ex10 : (∃ x : A,  true) → (∃ x:A, (PP x → ∀ x : A,PP x)) :=\nbegin ---b) provable classically\n  assume atr,\n  cases atr with a tr,\n  cases em (∀ x : A, PP x) with app napp,\n  existsi a,\n  assume ppa,\n  exact app,\n\n  have h :(∃ x: A, ¬ PP x),\n  apply aux_thm,\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  cases f,\nend\n\nend poker\n", "meta": {"author": "kyrran", "repo": "Lean", "sha": "915f45d695eb01a80e58916f03e8f7c1e878be8b", "save_path": "github-repos/lean/kyrran-Lean", "path": "github-repos/lean/kyrran-Lean/Lean-915f45d695eb01a80e58916f03e8f7c1e878be8b/ex03(sisterinlaw).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825635346563, "lm_q2_score": 0.9086178975514609, "lm_q1q2_score": 0.7648978388935168}}
{"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-/\nprelude\nimport init.quot init.logic\n\nnamespace function\n  variables {A : Type} {B : A → Type}\n\n  protected definition equiv (f₁ f₂ : Πx : A, B x) : Prop := ∀x, f₁ x = f₂ x\n\n  namespace equiv_notation\n    infix `~` := function.equiv\n  end equiv_notation\n  open equiv_notation\n\n  protected theorem equiv.refl (f : Πx : A, B x) : f ~ f := take x, rfl\n\n  protected theorem equiv.symm {f₁ f₂ : Πx: A, B x} : f₁ ~ f₂ → f₂ ~ f₁ :=\n  λH x, eq.symm (H x)\n\n  protected theorem equiv.trans {f₁ f₂ f₃ : Πx: A, B x} : f₁ ~ f₂ → f₂ ~ f₃ → f₁ ~ f₃ :=\n  λH₁ H₂ x, eq.trans (H₁ x) (H₂ x)\n\n  protected theorem equiv.is_equivalence (A : Type) (B : A → Type) : equivalence (@function.equiv A B) :=\n  mk_equivalence (@function.equiv A B) (@equiv.refl A B) (@equiv.symm A B) (@equiv.trans A B)\nend function\n\nsection\n  open quot\n  variables {A : Type} {B : A → Type}\n\n  private definition fun_setoid [instance] (A : Type) (B : A → Type) : setoid (Πx : A, B x) :=\n  setoid.mk (@function.equiv A B) (function.equiv.is_equivalence A B)\n\n  private definition extfun (A : Type) (B : A → Type) : Type :=\n  quot (fun_setoid A B)\n\n  private definition fun_to_extfun (f : Πx : A, B x) : extfun A B :=\n  ⟦f⟧\n\n  private definition extfun_app (f : extfun A B) : Πx : A, B x :=\n  take x,\n  quot.lift_on f\n    (λf : Πx : A, B x, f x)\n    (λf₁ f₂ H, H x)\n\n  theorem funext {f₁ f₂ : Πx : A, B x} : (∀x, f₁ x = f₂ x) → f₁ = f₂ :=\n  assume H, calc\n     f₁ = extfun_app ⟦f₁⟧ : rfl\n    ... = extfun_app ⟦f₂⟧ : {sound H}\n    ... = f₂              : rfl\nend\n\nattribute funext [intro!]\n\nopen function.equiv_notation\n\ndefinition subsingleton_pi [instance] {A : Type} {B : A → Type} (H : ∀ a, subsingleton (B a)) :\n  subsingleton (Π a, B a) :=\nsubsingleton.intro (take f₁ f₂,\n  have eqv : f₁ ~ f₂, from\n    take a, subsingleton.elim (f₁ a) (f₂ a),\n  funext eqv)\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/funext.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.764794017339431}}
{"text": "namespace hidden\n\ninductive nat : Type\n| zero : nat\n| succ : nat → nat\n\nnamespace nat\n\ndef add (m n : nat) : nat :=\nnat.rec_on n m (fun n add_m_n, succ add_m_n)\n\ninstance : has_zero nat := has_zero.mk zero\ninstance : has_add nat := has_add.mk add\n\ntheorem add_zero (m : nat) : m + nat.zero = m := rfl\ntheorem add_succ (m n : nat) : m + succ n = succ (m + n) := rfl\n\ntheorem zero_add (n : nat) : nat.zero + n = n :=\nnat.rec_on n rfl (λ n ih, by rw [add_succ, ih])\n\ntheorem add_assoc (m n k : nat) : m + n + k = m + (n + k) :=\nnat.rec_on k rfl (λ k ih, by simp only [add_succ, ih])\n\ntheorem succ_add (m n : nat) : succ m + n = succ (m + n) :=\nnat.rec_on n rfl (λ n ih, by simp only [add_succ, ih])\n\ntheorem add_comm (m n : nat) : m + n = n + m :=\nnat.rec_on n\n  (begin\n    simp only [zero_add, add_zero]\n  end)\n  (λ n ih, by simp only [add_succ, ih, succ_add])\n\n-- Exercise\n\ndef mul (m n : nat) : nat :=\nnat.rec_on n 0 (λ n mul_m_n, mul_m_n + m)\n\ndef pred (n : nat) : nat :=\nnat.rec_on n 0 (λ n x, n)\n\ndef sub (m n : nat) : nat :=\nnat.rec_on n m (λ n sub_m_n, pred sub_m_n)\n\ninstance : has_mul nat := has_mul.mk mul\ninstance : has_sub nat := has_sub.mk sub\ninstance : has_one nat := has_one.mk (succ zero)\n\ndef pow (m n : nat) : nat :=\nnat.rec_on n (succ zero) (λ n pow_m_n, pow_m_n * m)\n\ntheorem mul_zero (n : nat) : n * zero = zero := rfl\ntheorem mul_succ (n m : nat) : n * (succ m) = (n * m) + n := rfl\n\ntheorem zero_mul (n : nat) : zero * n = zero :=\nbegin\n    induction n,\n        refl,\n    show zero * succ n_a = zero, from\n    calc zero * succ n_a\n        = (zero * n_a) + zero : by rw mul_succ\n    ... = zero * n_a : by rw add_zero\n    ... = zero : n_ih\nend\n\ntheorem one_mul (n : nat) : (succ zero) * n = n :=\nbegin\n    induction n,\n        refl,\n    rw mul_succ,\n    rw n_ih,\n    refl\nend\n\ntheorem mul_one (n : nat) : n * (succ zero) = n :=\nbegin\n    induction n,\n        rw zero_mul,\n    rw mul_succ,\n    rw [mul_zero, zero_add]\nend\n\ntheorem mul_dist (m n k : nat) : m * n + m * k = m * (n + k) :=\nbegin\n    induction k,\n        simp [add_zero, mul_zero],\n    simp [mul_succ],\n    rw [←add_assoc],\n    rw k_ih,\n    rw ←mul_succ,\n    rw add_succ\nend\n\ntheorem mul_assoc (m n k : nat) : (m * n) * k = m * (n * k) :=\nbegin\n    induction k,\n        simp [mul_zero],\n    simp [mul_succ, k_ih],\n    simp [mul_dist]\nend\n\ntheorem succ_mul (n m : nat) : (succ n) * m = (n * m) + m :=\nbegin\n    induction m,\n        simp [mul_zero, add_zero],\n    simp [mul_succ, m_ih],\n    simp [add_succ],\n    simp [add_assoc, add_comm m_a n]\nend\n\ntheorem mul_comm (m n : nat) : m * n = n * m :=\nbegin\n    induction n,\n        simp [mul_zero, zero_mul],\n    simp [mul_succ],\n    rw [n_ih],\n    simp [succ_mul]\nend\n\ntheorem dist_mul (m n k : nat) : m * k + n * k = (m + n) * k :=\nbegin\n    simp [mul_comm],\n    rw ←mul_dist,\n    simp [mul_comm]\nend\n\ninstance : has_pow nat nat := has_pow.mk pow\n\ntheorem pow_succ (m n : nat) : m ^ (succ n) = m ^ n * m := rfl\ntheorem pow_zero (m : nat) : m ^ zero = (succ zero) := rfl\n\ntheorem pow_mul (m n k : nat) : m ^ n * m ^ k = m ^ (n + k) :=\nbegin\n    induction k,\n        simp [add_zero, pow_zero, mul_one],\n    rw [pow_succ, ←mul_assoc],\n    rw k_ih,\n    rw [←pow_succ],\n    rw [add_succ]\nend\n\ntheorem pow_pow (m n k : nat) : (m ^ n) ^ k = m ^ (n * k) :=\nbegin\n    induction k,\n        simp [mul_zero, pow_zero],\n    simp [pow_succ],\n    rw k_ih,\n    simp [pow_mul, mul_succ]\nend\n\nend nat\n\nend hidden\n", "meta": {"author": "zeptometer", "repo": "LearnLean", "sha": "bb84d5dbe521127ba134d4dbf9559b294a80b9f7", "save_path": "github-repos/lean/zeptometer-LearnLean", "path": "github-repos/lean/zeptometer-LearnLean/LearnLean-bb84d5dbe521127ba134d4dbf9559b294a80b9f7/bluejam/chap7/exercise7.1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7647891705531337}}
{"text": "import Mathlib\nimport LeanCodePrompts.CheckParse\n\n/-\nIf every proper closed set of a topological space is compact, then the space itself is compact.\n-/\ntheorem compact_if_all_proper_compact {α : Type _} [TopologicalSpace α] : (∀ (s : Set α), (s ≠ Set.univ) → IsCompact s) → CompactSpace α := sorry\n\n/-\nEvery prime that is one greater than a multiple of four can be expressed as the sum of two squares.\n-/\ntheorem fermat_two_square : ∀ p : ℕ, Nat.Prime p → (p % 4 = 1) → ∃ a b : ℕ, a ^ 2 + b ^ 2 = p := sorry\n\n/-\nFor every subset of the Euclidean plane, there is a line segment of unit length whose endpoints are either both inside the subset or both outside it.\n-/\n-- theorem unit_line_in_or_out_of_euclidean_plane_subset : ∀ (S : Set $ EuclideanSpace ℝ (Finₓ 2)), ∃ (x y : EuclideanSpace ℝ (Finₓ 2)), (∥x - y∥ = (1 : ℝ)) → (x ∈ S ∧ y ∈ S) ∨ (x ∉ S ∧ y ∉ S) := sorry\n\n/-\nThe product of two numbers, each of which is the sum of four squares, is itself a sum of four squares.\n-/\ntheorem euler_four_square_identity : let is_sum_of_four_squares : ℕ → Prop := λ n : ℕ => ∃ (a b c d : ℕ), n = a^2 + b^2 + c^2 + d^2;\n  ∀ (x y : ℕ), is_sum_of_four_squares x → is_sum_of_four_squares y → is_sum_of_four_squares (x * y) := sorry\n\n/-\nA ring with all elements idempotent is commutative.\n-/\ntheorem all_idempotent_implies_commutative {R : Type _} [Ring R] : (∀ x : R, HMul.hMul x x = 1) → CommRing R := sorry\n\n/-\nThere are infinitely many pairs of primes that differ exactly by two.\n-/\ntheorem twin_prime_conjecture : ∀ n : ℕ, ∃ p : ℕ, p > n → Nat.Prime p → Nat.Prime (p + 2) := sorry\n\n/-\nIf `I` is a collection of intervals of real numbers with lengths that sum to less than one, then the union of the intervals cannot be all of the unit interval.\n-/\n\n\n/-\nEvery finite division ring is a field.\n-/\n--ERROR-- theorem fin_div_ring_is_field {R : Type _} [Finite R] [DivisionRing R] : Field R := sorry\n\n/-\nThe product of two positive numbers is at most the square of their average.\n-/\n-- theorem am_gm_ineq : ∀ (a b : ℝ), a > 0 → b > 0 → a * b ≤ ((a + b)/(1 + 1))^2 := sorry\n\n/-\nIn any configuration of points on the plane, not all on a line, there is a line which contains exactly two of the points.\n-/\n-- theorem sylvester_gallai {P L : Type _} [HasMem P L] [Membership P L] [Configuration.Nondegenerate P L] : ∃ (l : L) (p q : P), p ∈ l → q ∈ l → (∀ r : P, r ∈ l → r = p ∨ r = q) := sorry\n\n/-\nIf each of two types can be mapped injectively into the other, then there is a bijection between them.\n-/\ntheorem cantor_schroeder_bernstein {α β : Type _} (f : α → β) (g : β → α) : Function.Injective f → Function.Injective g → (∃ h : α → β, Function.Bijective h) := sorry\n\n/-\nA finite graph in which every two vertices have precisely one common neighbour contains a vertex that is adjacent to all other vertices.\n-/\ntheorem graph_unique_common_neighbour_implies_universal_adjacent_vertex {V : Type _} [Finite V] (G : SimpleGraph V) : (∀ v w : V, ∃! x : V, G.Adj v x ∧ G.Adj w x) → (∃ c : V, ∀ v : V, G.Adj c v) := sorry\n\n/-\nThe number of partitions with odd parts is equal to the number of partitions with distinct parts.\n-/\ntheorem partition_odd_distincts : ∀ n : ℕ, Finset.card (Nat.Partition.odds n) = Finset.card (Nat.Partition.distincts n) := sorry\n\n/-\nEvery non-empty poset in which every chain has an upper bound contains a maximal element.\n-/\nlemma zorn {α : Type _} [PartialOrder α] [Nonempty α] : (∀ c : Set α, IsChain LE.le c → (∃ b : α, ∀ a ∈ c, a ≤ b)) → (∃ m : α, ∀ a : α, m ≤ a → a = m) := sorry\n\n/-\nA group whose automorphism group is cyclic is Abelian.\n-/\ntheorem aut_group_cyclic_implies_abelian {G : Type _} [Group G] : IsCyclic (G → G) → CommGroup G := sorry\n\n/-\nA uniformly continuous function of a uniformly continuous function is uniformly continuous.\n* This translation may be incorrect\n-/\ntheorem uniformcts_of_uniformcts {α β γ : Type _} [UniformSpace α] [UniformSpace β] [UniformSpace γ] (f : α → β) (g : β → γ) : UniformContinuous f → UniformContinuous g → UniformContinuous (g ∘ f) := sorry\n\n/-\nThe image of a union of sets is the union of the images.\n-/\ntheorem image_union (f : α → β) (S : Set (Set α)) : (f <$> (⋃₀ S)) = (⋃₀ ((Functor.map f) <$> S)) := sorry\n\n/-\nA topological space is normal if and only if any two disjoint closed subsets can be separated by a continuous function.\n-/\n--ERROR-- lemma urysohn {X : Type _} [TopologicalSpace X] [TopologicalSpace ℝ] : NormalSpace X ↔ ( ∀ {S T : Set X}, IsClosed S → IsClosed T → Disjoint S T → (∃ f : X → ℝ, Continuous f → (∀ x ∈ S, f x = 0) ∧ (∀ x ∈ T, f x = 1)) ) := sorry\n\n/-\nThe only field automorphism of the reals is the identity.\n-/\n-- theorem real_field_aut_trivial : ∀ (f : ℝ ≃+* ℝ), (∀ x : ℝ, f x = x) := sorry\n\n/-\nIf a function from the unit interval to itself has a point of period three, then it has points of all positive periods.\n-/\ntheorem period_three_implies_chaos : ∀ f : Set.IccCat 0 1 → Set.IccCat 0 1, (∃ x : Set.IccCat 0 1, Function.IsPeriodicPt f 3 x) → (∀ n : ℕ, n > 0 → ∃ y : Set.IccCat 0 1, Function.IsPeriodicPt f n y) := sorry\n\n/-\nA terminal object in a category is unique up to unique isomorphism.\n-/\ntheorem terminal_unique_iso {C : Type _} [CategoryTheory.Category C] : ∀ T₁ T₂ : C, CategoryTheory.Limits.IsTerminal T₁ → CategoryTheory.Limits.IsTerminal T₂ → (∃ ι : CategoryTheory.Iso T₁ T₂, ∀ ι' : CategoryTheory.Iso T₁ T₂, ι = ι') := sorry\n\n/-\nA finitely-presented group containing a torsion element is finite.\n-/\ntheorem torsion_in_fg_group_implies_finite {G : Type _} [Group G] : Group.Fg G → Finite G := sorry\n\n/-\nThe complement of the union of two sets is the intersection of their complements.\n-/\ntheorem compl_union {α : Type _} (S T : Set α) : (S ∪ T).compl = S.compl ∩ T.compl := sorry\n\n/-\nThe sum of the cubes of two positive integers is never equal to the cube of a third integer.\n-/\ntheorem flt_3 : ∀ a b c : ℕ, a > 0 → b > 0 → ¬(a^3 + b^3 = c^3) := sorry\n\n\n/-\nIf every element of a group `G` has order two, then every pair of elements of `G` commutes.\n-/\ntheorem elems_order_two_implies_commutative {G: Type _}[Group G] : (∀ x y : G, HMul.hMul x x = 1) → (∀ x y : G, Commute x y) := sorry\n\n/-\nEvery prime number is either `2` or odd.\n-/\ntheorem prime_eq_two_or_odd {n: Nat} : Nat.Prime n → n = 2 ∨ Odd n := sorry\n\n/-\nEvery odd degree polynomial over `ℝ` has a zero\n-/\ntheorem poly_odd_degree_has_zero (p : Polynomial ℝ) : Odd (WithBot.unbot' 0 p.degree) → ∃ x, p.IsRoot x := sorry\n\n/-\nThe product of two consequitive natural numbers is even.\n-/\ntheorem product_conseq_odd (n: Nat): Even <| n * (n + 1) := sorry\n\n/-\nEvery constant function `f x = c` from real numbers to real numbers is differentiable.\n-/\n-- theorem constant_is_differentiable  {f: ℝ → ℝ}: ∃ c: ℝ, (∀ x : ℝ, f x = c) → Differentiable ℝ f := sorry \n\n/-\nEvery index 2 subgroup of a group is normal\n-/\ntheorem index_two_subgroup {G : Type _} [Group G] (H : Subgroup G): \n      H.index = 2 → Subgroup.Normal H := sorry\n\n/-\nEvery subgroup of a free group is free\n-/\n-- theorem subgpFree {G : Type _} [Groupₓ G] :       (K : Subgroup G) → Σ β, FreeGroup β ≃* ↥K := sorry\n\n/-\nEvery free group is torsion free\n-/\ntheorem free_group_torsion_free {α : Type} :\n  Monoid.IsTorsionFree (FreeGroup α) := sorry\n\n/-\nEvery non-empty subgroup of `ℤ` is isomorphic to `ℤ`\n-/\n-- theorem integer_subgroups (H : AddSubgroup ℤ) : H.Carrier.Nonempty  →   ↥H ≃+ ℤ := sorry\n\n/- If the coefficients of a polynomial over rationals are integral, every rational root is integral.-/\n-- theorem int_poly_rat_zeros_int (p: Polynomial ℚ) :\n--   ∀ n: ℕ, IsIntegral ℚ (p.coeff n) →  \n--   ∀ x: ℚ, p.IsRoot x →  IsIntegral ℚ x := sorry\n\n/-\nEvery natural number greater than `1` is divisible by a prime number. \n-/\ntheorem has_prime_factor(n: ℕ) :\n  n > 1 → ∃ p: ℕ, Nat.Prime p ∧ (∃ d: ℕ, HMul.hMul p d = n) := sorry\n\n/-\nSix is not the sum of two prime numbers.\n-/\ntheorem six_not_prime_sum : \n  ¬ (∃ n m: Nat, Nat.Prime n ∧ Nat.Prime m ∧ n ≠ m ∧ 6 = n + m) := sorry\n\n/-\nA finite torsion-free group is trivial\n-/\ntheorem fin_torsionfree {G: Type _}[Group G][Finite G] :\n  Monoid.IsTorsionFree G → IsSubgroup.Trivial G := sorry\n\n/-\nAny homomorphism from the additive group of rational numbers to `ℤ` is trivial\n-/\n-- theorem hom_rat_Z_trivial (f : ℚ → ℤ) : \n--   IsAddGroupHom f →  ∀ x: ℚ, f x = 0 := sorry\n\n/-\nEvery finite division ring is a field.\n-/\n--ERROR--theorem fin_int_domain_ring_is_field {R : Type _} [Ring R] : IsDomain R → Finite R → Field R := sorry\n\n/-\nEvery finite topological space is compact\n-/\ntheorem finite_space_compact{X : Type _}[TopologicalSpace X][Finite X] :\n  CompactSpace X := sorry\n\n/-\nEvery surjective homomorphism from a finitely generated free group to itself is injective\n-/\ntheorem freegroup_hopfian {α : Type _} [Finite α]: (f: FreeGroup α → FreeGroup α) → (IsGroupHom f) → f.Surjective → f.Injective := sorry\n\n/-\nEvery polynomial of positive degree over reals is unbounded.\n-/\ntheorem polys_unbounded(p: Polynomial ℝ) : p.degree > 0 → \n    ∀ m: ℝ, ∃ x: ℝ, p.eval x  > m ∨ p.eval x < -m  := sorry\n\n/-\nA homomorphism between fields is either injective or trivial.\n-/\n-- theorem field_hom_inj_or_trivial {F F' : Type _} [Field F] [Field F'] : ∀ ϕ : F →+* F', ϕ.toFun.Injective ∨ (∀ x : F, ϕ x = 0) := sorry\n\n/-\nAny homomorphism from a group $G$ to an Abelian group factors through the Abelianisation of $G$.\n-/\n-- typeclass difficulties\n--theorem abelianisation_factor {G : Type _} [Groupₓ G] [NonAssocSemiringₓ G] {A : Type _} [CommGroup A] [NonAssocSemiringₓ A] [NonAssocSemiringₓ (Abelianization G)] : ∀ ϕ : G →+* A, ∃! (ϕ' : Abelianization G →+* A), ϕ = ϕ' ∘ (@Abelianization.of G _) := sorry\n\n/-\nEvery ascending chain of sub-modules of a Noetherian module eventually stabilises.\n-/\n-- theorem noetherian_implies_ascending_chain_condition {R M : Type _} [Ringₓ R] [AddCommMonoidₓ M] [Module R M] : IsNoetherian R M → ∀ (f : ℕ →o Submodule R M), ∃ n : ℕ, ∀ m : ℕ, n < m → f n = f m := sorry\n\n/-\nDifferentiability implies continuity.\n-/\n-- theorem differentiability_implies_continuity [TopologicalSpace ℝ] : ∀ f : ℝ → ℝ, Differentiable ℝ f → Continuous f := sorry\n\n/-\nLeft adjoint functors preserve colimits.\n-/\n-- open CategoryTheory in\n-- theorem left_adjoints_preserve_colimits {C D J : Type _} [Category C] [Category D] [Category J] (F : Functor C D) [IsLeftAdjoint F] (K : Functor J C) :\n-- ∀ c : Limits.Cocone K, Limits.IsColimit c → ( Limits.IsColimit $ Functor.mapCocone F c) := sorry\n\n/-\nThe angles of a triangle add up to two right angles.\n-/\n-- theorem angle_sum_pi {p q r : EuclideanSpace ℝ (Finₓ 2)} : EuclideanGeometry.angle p q r + EuclideanGeometry.angle q r p + EuclideanGeometry.angle r p q = Real.pi := sorry\n\n/-\nEvery Lebesgue measurable function is equal almost everywhere to a Borel measurable function.\n-/\n\n\n/-\nFor any prime divisor $p$ of the order of a finite group $G$, there is a subgroup of $G$ whose order is $p$.\n-/\n-- theorem cauchy {G : Type _} [Groupₓ G] [Fintype G] : ∀ p : ℕ, Prime p → (Fintype.card G % p = 0) → ∃ H : Subgroup G, Monoidₓ.exponent (↥H) = p := sorry\n\n/-\nAny locally-small category $C$ can be embedded into the category of contravariant functors from $C$ to $Set$.\n-/\n\n\n/-\nEvery positive even integer can be written as the sum of two primes.\n-/\ntheorem goldbach : ∀ n : ℕ, n > 0 → Even n → ∃ p q : ℕ, Nat.Prime p → Nat.Prime q → n = p + q := sorry\n\n/-\nA complex function that is once differentiable is infinitely differentiable.\n-/\n\n\n/-\nThe elements of any finite distributive lattice can be represented as finite sets, in such a way that the meet and join lattice operations correspond to unions and intersections of sets.\n-/\n\n/-\nEvery matrix satisfies its own characteristic polynomial.\n-/\n--ERROR-- theorem cayley_hamilton {R : Type _} [CommRing R] {n : Type _} [DecidableEq n] [Fintype n] (M : Matrix n n R) : Polynomial.aeval M M.charpoly = 0 := sorry\n\n/-\nThe square root of an irrational number is irrational.\n-/\ntheorem sqrt_of_irrat_irrat (x : ℝ) : Irrational x → Irrational (Real.sqrt x) := sorry\n\n/-\nAmong all rectangles of a given area $A$, the square of side √A has the smallest perimeter.\n-/\n\n/-\nIf each strongly-connected component of a graph is contracted to a single vertex, the resulting graph is a directed acyclic graph.\n-/\n\n/-\nIf $n$ infinitely long straight lines are lying on a plane such that no two lines are parallel and no three lines intersect at a single point, then the lines divide the plane into $(n^2 + n + 2)/2$ regions.\n-/\n\n/-\nThe tangent bundle of the circle is trivial.\n-/\n\n/-\nThe number of binary strings of length $n$ with no consecutive zeros is equal to the $n+2$th Fibonacci number.\n-/\n\n/-\nIf a sub-sequence of a Cauchy sequence in a metric space converges to a point, then the full sequence also converges to the same point.\n-/\n\n/-\nEvery finite Abelian group is isomorphic to the product of cyclic groups.\n-/\n\n/-\nIf the square of a number is even, the number itself is even.\n-/\ntheorem sq_even_implies_num_even : ∀ n : ℕ, Even (n^2) → Even n := sorry\n\n/-\nIn a finite commutative ring, all prime ideals are maximal.\n-/\ntheorem finite_ring_prime_implies_maximal {R : Type _} [CommRing R] [Fintype R] : ∀ (Idl : Ideal R), Idl.IsPrime → Idl.IsMaximal := sorry\n\n/-\nAn integer polynomial with a root in the integers has a root modulo every prime.\n-/\n\n/-\nThe number of Sylow-2 subgroups of a dihedral group is equal to the largest odd number dividing the order of the group.\n-/\n\n/-\nA topological space $X$ is Hausdorff if and only if the diagonal is a closed set in $X × X$.\n-/\n--ERROR-- theorem hausdorff_iff_diag_closed {X : Type _} [TopologicalSpace X] : T2Space X ↔ IsClosed (Set.Diagonal X) := sorry\n\n/-\nIf every point of a subset of a topological space is contained in some open set, the subset itself is open.\n-/\ntheorem open_iff_open_nhd_all_pt {X : Type _} [TopologicalSpace X] (S : Set X) : (∀ x ∈ S, ∃ U : Set X, IsOpen U) → IsOpen S := sorry\n\n/-\nThe product of a complex number with its conjugate is a real number.\n-/\n-- theorem complex_conj_prod_real : ∀ z : ℂ, ∃ r : ℝ, z * (starRingEnd ℂ $ z) = (r : ℂ) := sorry\n\n/-\nEvery non-identity element of a free group is of infinite order.\n-/\ntheorem non_id_implies_infinite_order {G : Type _} [Group G] : FreeGroup G → (∀ g : G, g ≠ 1 → orderOf g = 0) := sorry\n\n/-\nAny sub-ring of a field that contains the identity is an integral domain.\n-/\n-- theorem sub_ring_field_with_id_is_int_domain {F : Type _} [Field F] : ∀ R : Subring F, 1 ∈ R.Carrier → IsDomain ↥R := sorry\n\n/-\nAn element of a discrete valuation ring is a unit if and only if it has a valuation of zero.\n-/\n--ERROR--theorem dvr_unit_iff_val_zero {R : Type _} [CommRing R] : IsDomain R → DiscreteValuationRing R → ∀ r : R, IsUnit r → DiscreteValuationRing.addVal R r = 0 := sorry\n\n/-\nEvery automorphism of a tree fixes a vertex or an edge.\n-/\n\n/-\nIf $e$ is an idempotent in a commutative ring $R$ with identity, the $R$ is isomorphic to the product of the ideals generated by $e$ and $1-e$.\n-/\n\n/-\nThe number of leaves in any tree is at least the maximum degree.\n-/\n\n/-\nThe exponential function is convex.\n-/\ntheorem exp_convex : ConvexOn ℝ Set.univ Real.exp := sorry\n\n/-\nFor every natural number $k$, there is a natural number $n$ such that any partition of the first $n$ natural numbers into $k$ sets has a set containing numbers $x, y, z$ such that $x + y = z$.\n-/\n\n/-\nNo non-constant polynomial of a complex variable can take imaginary values only.\n-/\n\n/-\nFor any two relatively prime positive integers $a$ and $b$, every sufficiently large natural number $N$ can be written as a linear combination $ax + by$ of $a$ and $b$, where both $x$ and $y$ are natural numbers.\n-/\ntheorem coprime_integer_span_sylvester_coin : ∀ a b : ℕ, a > 0 → b > 0 → Nat.coprime a b → ∃ m : ℕ, ∀ N : ℕ, N > m → ∃ x y : ℕ, N = HMul.hMul a x + HMul.hMul b y := sorry\n\n/-\nAn integer-valued polynomial need not have all integer coefficients.\n-/\n\n/-\nFor a module $M$, if a sub-module $N$ and the quotient $M/N$ are both finitely generated, then so is $M$.\n-/\n-- theorem module_fg_if_sub_and_quot_fg {M R : Type _} [Ringₓ R] [AddCommGroupₓ M] [Module R M] : ∀ N : Submodule R M, N.Fg → (N.Quotient.Module.Fg) → M.Fg := sorry\n\n/-\nIf $ϕ$ is a linear transformation from a finite dimensional vector space to itself, there is an integer $m$ such that the intersection of the image of $ϕ^m$ with the kernel of $ϕ^m$ is trivial.\n-/\n\n/-\nThe eigenvalues of an orthogonal matrix have absolute value $1$.\n-/\n\n/-\nIn a commutative ring with prime characteristic $p$, the $p$th power of the sum of two elements is equal to the sum of the $p$th powers of the elements.\n-/\n-- theorem frobenius_pow_sum_eq_sum_pow {R : Type _} [CommRingₓ R] : (p : ℕ) → Prime p → CharP R p → ∀ a b : R, (a + b)^p = a^p + b^p := sorry\n\n/-\nEvery alternating $n$ tensor over a vector space of dimension $n$ is a scalar multiple of the determinant.\n-/\n\n/-\nAn absolutely convergent sequence is convergent.\n-/\n\n/-\nThe combinator (S K K) is equal to the identity combinator.\n-/\n-- Library/Init/Core.lean not yet ported\n-- theorem combinator_I_derivable_from_S_K : Combinator.S Combinator.K Combinator.K = Combinator.I := sorry\n\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/Scratch.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370312, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7647154278175295}}
{"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 data.polynomial.ring_division\nimport data.mv_polynomial.rename\nimport ring_theory.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 `φ ψ : mv_polynomial σ R`\n  over an infinite integral domain `R` are equal if `eval x φ = eval x ψ` for all `x : σ → R`.\n\n-/\n\nnamespace mv_polynomial\n\nvariables {R : Type*} [integral_domain R] [infinite R]\n\nprivate lemma funext_fin {n : ℕ} {p : mv_polynomial (fin n) R}\n  (h : ∀ x : fin n → R, eval x p = 0) : p = 0 :=\nbegin\n  unfreezingI { revert R },\n  induction n with n ih,\n  { introsI R _ _ p h,\n    let e := (rename_equiv R fin_zero_equiv').to_ring_equiv.trans\n      (mv_polynomial.pempty_ring_equiv R),\n    apply e.injective,\n    rw ring_equiv.map_zero,\n    convert h fin_zero_elim,\n    suffices : (eval₂_hom (ring_hom.id _) pempty.elim) (rename fin_zero_equiv' p) =\n      (eval fin_zero_elim : mv_polynomial (fin 0) R →+* R) p,\n    { rw [← this],\n      simp only [coe_eval₂_hom, pempty_ring_equiv_apply,\n        ring_equiv.trans_apply],\n      erw alg_equiv.coe_ring_equiv, },\n    rw [eval₂_hom_rename],\n    exact eval₂_hom_congr rfl (subsingleton.elim _ _) rfl },\n  { introsI R _ _ p h,\n    let e := (fin_succ_equiv R n).to_ring_equiv,\n    apply e.injective,\n    simp only [ring_equiv.map_zero],\n    apply polynomial.funext,\n    intro q,\n    rw [polynomial.eval_zero],\n    apply ih, swap, { apply_instance },\n    intro x,\n    dsimp [e],\n    rw [fin_succ_equiv_apply],\n    calc _ = eval _ p : _\n       ... = 0 : h _,\n    { intro i, exact fin.cases (eval x q) x i },\n    apply induction_on p,\n    { intro r,\n      simp only [eval_C, polynomial.eval_C, ring_hom.coe_comp, eval₂_hom_C], },\n    { intros, simp only [*, ring_hom.map_add, polynomial.eval_add] },\n    { intros φ i hφ, simp only [*, eval_X, polynomial.eval_mul, ring_hom.map_mul, eval₂_hom_X'],\n      congr' 1,\n      by_cases hi : i = 0,\n      { subst hi, simp only [polynomial.eval_X, fin.cases_zero] },\n      { rw [← fin.succ_pred i hi], simp only [eval_X, polynomial.eval_C, fin.cases_succ] } } }\nend\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. -/\nlemma funext {σ : Type*} {p q : mv_polynomial σ R}\n  (h : ∀ x : σ → R, eval x p = eval x q) : p = q :=\nbegin\n  suffices : ∀ p, (∀ (x : σ → R), eval x p = 0) → p = 0,\n  { rw [← sub_eq_zero, this (p - q)], simp only [h, ring_hom.map_sub, forall_const, sub_self] },\n  clear h p q,\n  intros p h,\n  obtain ⟨n, f, hf, p, rfl⟩ := exists_fin_rename p,\n  suffices : p = 0, { rw [this, alg_hom.map_zero] },\n  apply funext_fin,\n  intro x,\n  classical,\n  convert h (function.extend f x 0),\n  simp only [eval, eval₂_hom_rename, function.extend_comp hf]\nend\n\nlemma funext_iff {σ : Type*} {p q : mv_polynomial σ R} :\n  p = q ↔ (∀ x : σ → R, eval x p = eval x q) :=\n⟨by rintro rfl; simp only [forall_const, eq_self_iff_true], funext⟩\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/funext.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7646467871364032}}
{"text": "/- \nHomeowork 8  \nSina Hazratpour\nIntroduction to Proof  \nMATH 301, Johns Hopkins University, Fall 2022   \n-/\n\n\nimport ..prooflab\nimport lectures.lec11_type_classes\n\n\n/-! # Homework 8: ...\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-/\n\n\nvariables {X Y : Type} {f : X → Y} {p : Y → X}\n\n\nopen PROOFS \nopen PROOFS.STR \nopen PROOFS.type_classes\n\n\n\nlocal notation `𝟙` := unit -- type as \\b1\nlocal notation `⋆` := unit.star\n\n\n\nlemma unit_unique (x : 𝟙) : \n   x = ⋆ := \nbegin\n  exact unit.ext,\nend \n\n\n/- \nA map is __constant__ if it maps all points in the domain to the same point in the codomain.\n-/\ndef is_constant (f : X → Y) := ∀ x x' : X, f x = f x' \n\n/- \nA map `f : X → Y` is __constant at a point__ `y` of `Y` if `f` maps all points in `X` to `y`. \n-/\ndef is_constant_at (f : X → Y) (y : Y) := ∀ x : X, f x = y\n\n/-! ## Question 1 (20 pts):\nShow that if a function is constant at a point then it is constant. \n-/\nlemma constant_at_point_implies_constant {f : X → Y} :  \n   (∃ y : Y,  is_constant_at f y)  → is_constant f := \nbegin\n  sorry, \nend  \n\n\n\n\n\n\n\n/-! ## Question 2 (20 pts):\nProve that a function which factors through a type which is equivalent to the one-point type is constant. \n\nFeel free to use the lemma `ptwise.left_inv`\n-/\n\n#check @ptwise.left_inv\n\ntheorem constant_of_factor_unit  {f : X → Y} {Φ : fun_fact f} {α : fun_equiv Φ.node 𝟙} :  \n   is_constant f :=\nbegin\n   unfold is_constant, \nend \n\n\n\n\n\n\n\n\n\n\n/- For every type `X` there is a unique function \nfrom `X` to `𝟙` which takes all points of `X` to `⋆`. \n-/\n@[simp]\ndef to_terminal (X : Type) : X → 𝟙 := λ x, ⋆\n\nnotation ` ! ` := to_terminal\ninfix ` ≅ `:35 := fun_equiv\n\n\n/-! ## Question 3 (20 pts):\nProve that the unique function `X → 𝟙` is surjective iff `X` is pointed by filling the `sorry` placeholder. \n-/ \n\ndef is_surj_of_pointed_type {X : pointed_type} : \n  is_surjective (! X.type) :=  \nbegin\n   sorry, \nend \n\n\n\n/-\n**Formalize the converse**, that is if `! X : X → 𝟙` is surjective then `X` is pointed (i.e. it admits the structure of a pointed type). Then **prove** the converse statement. \n-/\n\n\n\n\n#check classical.some\nnoncomputable\ndef is_pointed_of_surj {X : Type} {h : is_surjective (! X)} : pointed_type :=\n{\n   type := X,\n   point := let h' : (∃ x : X, true) := by {unfold is_surjective at h,\n      simp at *, assumption} in classical.some h' , \n}\n\n\n\n\n\n\n\n\n/-! ## Question 4 (20 pts):\nProve that the image of the unique function `X → 𝟙` is equivalent to to `𝟙` if `X` is pointed. \n\nFeel free to use the lemma `ptwise.left_inv`\n-/\n\ndef truncation_of_pointed_type {X : pointed_type} : \n  𝟙  ≅ (fun_image (! X.type)) := \n{\n  to_fun := sorry,\n  inv_fun := sorry, \n  left_inv := by {sorry},\n  right_inv := by {sorry},\n}  \n\n\n\n\n\n/- \nWe say a type is __inhabited__ if there is some element in it. \n-/ \n\n@[simp]\ndef is_inhabited (X : Type) :=  ∃ x : X, true\n\n\n\n/-\nThe __fibre at a point__ `x : X` of a function  `p : Y → X` is the preimage of `x` under `p`. \n-/\n@[simp]\ndef fibre_at (x : X) := { y : Y // p y = x}\n\n#check @fibre_at\n\n\nlocal notation ` p⁻¹ ` : 15 := λ x, @fibre_at X Y p x\n#check p⁻¹\n\n\n\n/-!  ## Question 5 (20 pts): \nLet `p : Y → X` be a function. Prove that if all the fibres of `p` are inhabited then `p` is surjective.  \n-/\n\n\ndef surj_of_pointed_fibres {ptd_fibres : ∀ x : X, is_inhabited (p⁻¹ x) } : is_surjective p := \nbegin\n   sorry,  \nend \n\n\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/homework/hw8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7645757295246239}}
{"text": "\nimport order.boolean_algebra \nimport tactic \nopen boolean_algebra \n\nvariables {α : Type*} [boolean_algebra α]\n\n\n@[simp] def symm_diff (X Y : α) : α := (X \\ Y) ⊔ (Y \\ X) \n@[simp] lemma sdiff_eq {X Y : α} : X \\ Y = X ⊓ Yᶜ := sdiff_eq \n\n-- commutativity/associativity with explicit params for easier rewriting \nlemma inf_comm' (X Y : α) : X ⊓ Y = Y ⊓ X := by apply inf_comm \nlemma inf_assoc' (X Y Z : α) : X ⊓ Y ⊓ Z = X ⊓ (Y ⊓ Z) := by apply inf_assoc  \n\nlemma inf_right_comm (X Y Z : α) : X ⊓ Y ⊓ Z = X ⊓ Z ⊓ Y := by rw [inf_assoc, inf_comm' Y, ←inf_assoc]\n\nlocal attribute [simp] symm_diff sdiff_eq \n\nlemma symm_diff_comm (X Y : α) : symm_diff X Y = symm_diff Y X := \n  by simp [sup_comm] \n\n-- 'Normal form' for associativity \nlemma symm_diff_three (X Y Z : α) : \n  symm_diff (symm_diff X Y) Z = X ⊓ Yᶜ ⊓ Zᶜ ⊔ Y ⊓ Xᶜ ⊓ Zᶜ ⊔ (Z ⊓ (Xᶜ ⊓ Yᶜ) ⊔ Z ⊓ (Y ⊓ X)) :=\nbegin\n  simp only [symm_diff, sdiff_eq, inf_sup_right, compl_sup,compl_inf,compl_compl'],\n  repeat {rw inf_sup_left},\n  repeat {rw inf_sup_right},\n  rw [inf_compl_eq_bot, inf_comm' Xᶜ X, inf_compl_eq_bot], \n  simp, \nend\n\nlemma symm_diff_assoc (X Y Z : α) : 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 [inf_comm' Y Xᶜ, inf_comm' Z, inf_comm' Z, inf_comm' Y X, inf_right_comm Y, \n      inf_assoc' Z, inf_comm' Y, inf_comm' Z, inf_comm' Yᶜ, inf_comm' Z Y],\n    nth_rewrite 1 ←sup_assoc, \n    nth_rewrite 4 sup_comm,  \n    repeat {rw ←sup_assoc},\n    repeat {rw ←inf_assoc},\nend\n\nlemma inf_distrib_diff (X Y Z : α) : X ⊓ (Y \\ Z) = (X ⊓ Y) \\ (X ⊓ Z) := \n  by {simp only [sdiff_eq, compl_inf, inf_sup_left], rw [inf_right_comm _ Y, ←inf_assoc], simp,  }\n\nlemma symm_diff_distrib_inf_left (X Y Z : α) : X ⊓ (symm_diff Y Z)  = symm_diff (X ⊓ Y) (X ⊓ Z) := \n  by simp only [symm_diff, inf_sup_left, inf_sup_right, inf_distrib_diff] \n    \nlemma symm_diff_distrib_inf_right (X Y Z : α) : (symm_diff X Y) ⊓ Z  = symm_diff (X ⊓ Z) (Y ⊓ Z) := \n  by {rw [inf_comm', inf_comm' X, inf_comm' Y], apply symm_diff_distrib_inf_left}\n\nlemma symm_diff_inter (X Y : α) : \n  symm_diff X (X ⊓ Y) = X \\ Y := \n  by simp [inf_right_comm X Y, ←inf_assoc' _ Xᶜ, inf_sup_left]\n\nlemma sup_sdiff (X Y : α) : \n  X ⊔ (X \\ Y) = X :=\n  by simp  \n\nlemma top_symm_diff (X : α) : \n  symm_diff ⊤ X = Xᶜ := \n  by simp \n\nlemma symm_diff_self (X : α) : \n  symm_diff X X = ⊥ := \n  by simp \n\n@[simp] lemma bot_diff (X : α) :\n  ⊥ \\ X = ⊥ := \n  by simp\n\n@[simp] lemma diff_bot (X : α) :\n  X \\ ⊥ = X := \n  by simp  \n\n@[simp] lemma le_iff_inf (X Y : α) : \n  X ≤ Y ↔ X ⊓ Y = X := \n  inf_eq_left.symm\n\n-----------------------------------------------\n\n@[simp] instance to_comm_ring : comm_ring α := \n{ \n  add := λ X Y, symm_diff X Y, \n  add_assoc := λ X Y Z, symm_diff_assoc X Y Z,\n  zero := ⊥,\n  zero_add := λ X, by simp [has_add.add],\n  add_zero := λ X, by simp [has_add.add],\n  neg := λ X, X, \n  add_left_neg := λ X, symm_diff_self X, \n  add_comm := λ X Y, symm_diff_comm X Y, \n  mul := λ X Y, X ⊓ Y,\n  mul_assoc := λ X Y Z, inf_assoc,\n  one := ⊤,\n  one_mul := λ X, top_inf_eq,\n  mul_one := λ X, inf_top_eq,\n  left_distrib := λ X Y Z, symm_diff_distrib_inf_left X Y Z,\n  right_distrib := λ X Y Z, symm_diff_distrib_inf_right X Y Z, \n  mul_comm := λ X Y, inf_comm, \n}\n\nlemma one_add (X : α) : 1 + X = Xᶜ := \n  top_symm_diff X \n\nlemma add_one (X : α) : X + 1 = Xᶜ := \n  by {rw add_comm, from top_symm_diff X} \n\nlemma top_to_ring: (⊤ : α) = (1 : α) := rfl\n\nlemma bot_to_ring : (⊥ : α) = (0 : α) := rfl\n\nlemma symm_diff_to_ring {X Y : α} : (X \\ Y) ⊔ (Y \\ X) = X + Y := rfl \n\nlemma inf_to_ring {X Y : α} : X ⊓ Y = X * Y := rfl \n\nlemma sup_to_ring {X Y : α} : X ⊔ Y = (X + Y) + X*Y := \nbegin \n  rw [add_assoc], \n  nth_rewrite 1 ←one_mul Y, \n  rw [←right_distrib, one_add, ←symm_diff_to_ring, ←inf_to_ring],\n  rw [sdiff_eq, sdiff_eq, inf_right_comm, compl_inf, inf_sup_left], \n  simp only [compl_compl', inf_idem],\n  rw [←sdiff_eq, inf_comm' Xᶜ, ←sdiff_eq, sup_sdiff, sup_sdiff_same], \nend \n\nlemma compl_to_ring {X : α} : \n  Xᶜ = X + 1 := \n  (add_one X).symm \n\nlemma le_to_ring {X Y : α} : \n  X ≤ Y ↔ X*Y = X := \n  by {rw ←inf_to_ring, from inf_eq_left.symm} \n\nlemma diff_to_ring {X Y : α} : \n  X \\ Y = X*(Y + 1) := \n  by rw [add_one, ←inf_to_ring, sdiff_eq]\n---------------------\n\n@[simp] lemma mul_idem (X : α) : \n  X*X = X := \n  inf_idem \n\n@[simp] lemma two_eq_zero : \n  (2 : α) = (0 : α) := \n  let h : (2:α) = (1:α) + (1:α) := rfl in\n  by rw [h, one_add, ←top_to_ring, ←bot_to_ring, compl_top]\n\n@[simp] lemma add_self (X : α) : \n  X + X = 0 := \n  by {ring SOP, rw two_eq_zero, from mul_zero X}\n\nlemma add_self_left (X Y : α) :\n   X + (X + Y) = Y :=  \n   by rw [←add_assoc, add_self, zero_add]\n\n@[simp] lemma prod_comp_cancel (X : α) : X*(X+1) = 0 := \n  by {ring SOP, simp}\n  \nlemma expand_product {X₁ X₂ Y₁ Y₂ S : α} : \n  (X₁ * S + X₂ * (S+1)) * (Y₁ * S + Y₂ * (S+1)) = X₁ * Y₁ * S + X₂ * Y₂ * (S+1) :=\n  begin\n    simp only [←mul_assoc, mul_comm _ S, prod_comp_cancel, mul_idem, left_distrib, right_distrib, mul_one],\n    ring SOP, \n    simp [mul_comm, two_eq_zero, (by ring : (3:α) = (2:α) + (1:α)), mul_left_comm],\n  end\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/set_tactic/make_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475730993028, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7645633072239376}}
{"text": "import algebra.group_power data.real.basic\n\nsection M1F_Sheet02\n\ndef countable_union_from_zero {α : Type} (X : nat → set α ) := { t : α | exists i, t ∈ X i}\ndef countable_union_from_one {α : Type} (X : nat → set α ) := { t : α | exists i, i > 0 ∧ t ∈ X i}\n\ndef Q0201a_sets : ℕ → set ℝ := λ n x, ↑n ≤ x ∧ x < (n+1)\n\ntheorem Q0201a : countable_union_from_zero Q0201a_sets = { x | 0 ≤ x} := sorry\n\ndef Q0201b_sets : ℕ → set ℝ := λ n x, 1/(↑n) ≤ x ∧ x ≤ 1\n\ntheorem Q0201b : countable_union_from_one Q0201b_sets = { x | 0 < x ∧ x ≤ 1} := sorry \n\ndef Q0201c_sets : ℕ → set ℝ := λ n x, -↑n < x ∧ x < n\n\ntheorem Q0201c : countable_union_from_one Q0201c_sets = { x | true } := sorry\n\ndef countable_intersection_from_one {α : Type} (X : nat → set α ) := { t : α | ∀ i, i>0 → t ∈ X i}\n\ntheorem Q0201d : countable_intersection_from_one Q0201c_sets = {x | -1<x ∧ x<1} := sorry\n\nend M1F_Sheet02", "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/0201/Q0201.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475715065793, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7645633037738775}}
{"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\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 ∈ R` is `M`-regular if the smultiplication map\n`M → M`, defined by `m ↦ a • 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 → M`. -/\ndef is_smul_regular [has_scalar R M] (c : R) := function.injective ((•) c : M → 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 ↔ 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ᵐᵒᵖ`-regularity of `R` itself. -/\nlemma is_right_regular_iff [has_mul R] {a : R} :\n  is_right_regular a ↔ is_smul_regular R (mul_opposite.op a) := iff.rfl\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 • s) :=\nλ 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 • s)) :\n  is_smul_regular M s :=\n@function.injective.of_comp _ _ _ (λ m : M, a • m) _ (λ 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 • b) ↔ is_smul_regular M b :=\n⟨of_smul _, ha.smul⟩\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 ← 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) ↔ is_smul_regular M b :=\n⟨of_mul, ha.mul⟩\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) ∧ is_smul_regular M (b * a) ↔\n  is_smul_regular M a ∧ is_smul_regular M b :=\nbegin\n  refine ⟨_, _⟩,\n  { rintros ⟨ab, ba⟩,\n    refine ⟨ba.of_mul, ab.of_mul⟩ },\n  { rintros ⟨ha, hb⟩,\n    exact ⟨ha.mul hb, hb.mul ha⟩ }\nend\n\nend has_scalar\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λ 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 : ℕ) (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 : ℕ} (n0 : 0 < n) :\n  is_smul_regular M (a ^ n) ↔ is_smul_regular M a :=\nbegin\n  refine ⟨_, pow n⟩,\n  rw [← nat.succ_pred_eq_of_pos n0, pow_succ', ← smul_eq_mul],\n  exact of_smul _,\nend\n\nend monoid\n\nsection monoid_smul\n\nvariables [monoid S] [has_scalar R M] [has_scalar 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 • 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⟨λ a b, h (by repeat { rw mul_action_with_zero.zero_smul })⟩\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) ↔ subsingleton M :=\n⟨λ h, h.subsingleton, λ H a b h, @subsingleton.elim _ H a b⟩\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\nlemma not_zero_iff : ¬ is_smul_regular M (0 : R) ↔ 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_scalar 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) ↔\n  is_smul_regular M a ∧ is_smul_regular M b :=\nbegin\n  rw ← mul_and_mul_iff,\n  exact ⟨λ ab, ⟨ab, by rwa mul_comm⟩, λ rab, rab.1⟩\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 ((•) g⁻¹) h using 1;\n  simp [←smul_assoc]\nend\n\nend group\n\nsection units\n\nvariables [monoid R] [mul_action R M]\n\n/-- Any element in `Rˣ` is `M`-regular. -/\nlemma units.is_smul_regular (a : Rˣ) : 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 ⟨a, rfl⟩,\n  exact a.is_smul_regular M\nend\n\nend units\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/regular/smul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7645603752551448}}
{"text": "import .src_09_or_elimination\n\nnamespace mth1001\n\nsection applications_to_even_and_odd\n\n/-\nIn this section, we'll show applications of the law of the excluded middle, contradiction, \nand contrapositive.\n-/\n\n/-\nHere's a very short proof that `0 ≠ 1`, where `≠` is typed as `\\ne`. The goal is closed using\nthe `linarith` tactic, which can solve linear equations and inequalities.\n\nNote the use of `by` instead of the `begin` … `end` block. Also note that we type `(0 : ℤ)`; this\nspecifies that the theorem refers to the `0` in `ℤ` rather than any other `0`.\n-/\ntheorem zero_ne_one : (0 : ℤ) ≠ 1 := by linarith\n\n/-\nWe use this to prove that `0` is not odd. Again, you don't need to understand the details\nof the proof.\n-/\ntheorem not_odd_zero : ¬(odd (0 : ℤ)) :=\nbegin \n  rintro ⟨k, hk⟩,\n  apply zero_ne_one,\n  rw [←(int.zero_mod 2), hk, add_comm, int.add_mul_mod_self_left],\n  refl,\nend\n\nexample : ¬(odd (0 : ℤ)) :=\nbegin \n  rintro ⟨k, hk⟩,\n  apply zero_ne_one,\n  rw [←(int.zero_mod 2), hk, add_comm, int.add_mul_mod_self_left],\n  refl,\nend\n\n\n-- Exercise 074:\n/-\nIn a previous section, we proved that every integer `n` is even or odd. However, we haven't\nyet discounted the possiblity that there is some integer `n` that is *both* even and odd.\n\nUse `linarith` to solve any equations that arise.\n-/\ntheorem not_exists_even_and_odd : ¬ (∃ m, even m ∧ odd m) :=\nbegin \n  intro h,\n  cases h with k hk,\n  cases hk with evenk oddk,\n  cases evenk with a ha,\n  cases oddk with b hb,\n  sorry  \nend \n\n/-\nFor those wishing to spend the least amount of time typing, note that Lean offers tactics\n`rcases` and `rintro`. Their use use best illustrated by the following in which I have\nreplaced the first five lines of the above example with only two.\n-/\nexample : ¬(∃ m, even m ∧ odd m) :=\nbegin \n  rintro ⟨k, hk⟩,\n  rcases hk with ⟨⟨a, ha⟩, ⟨b, hb⟩⟩, \n  sorry  \nend \n\n-- Exercise 075:\n/-\nAs a consequence, we'll show an integer is even if and only if it is not odd.\n-/\ntheorem even_iff_not_odd {a : ℤ} : even a ↔ ¬(odd a) :=\nbegin \n  sorry    \nend \n\n-- Exercise 076:\n-- We need an auxiliary result, that the square of an odd number is odd.\ntheorem odd_square_of_odd {b : ℤ} : odd b → odd (b*b) :=\nbegin\n  sorry  \nend\n\n/-\nGiven a statement `p → q`, its *converse* is the statement `q → p`. Given an integer `a`, we've\nproved `even a → even (a*a)`. Our aim is to prove the converse of the statement, namely\n`even (a*a) → even a`.\n-/\n\n-- Exercise 077:\n/-\nThe following theorem can be proved using only `contrapose`, `contrapose!`, `intro`, `apply`, and\n`exact`, together with the results `even_iff_not_odd` and `odd_square_of_odd`.\n\nRecall that if `h : p ↔ q`, then `h.mp : p → q` and `h.mpr : q → p`.\n-/\nexample (b : ℤ) : even (b*b) → even b :=\nbegin \n  contrapose,\n  intro hneven,\n  have h₁ : odd (b*b) → ¬(even (b*b)),\n  { sorry, }, \n  sorry  \nend \n\nend applications_to_even_and_odd\n\n/-\nSUMMARY:\n\n* Applications of previous work.\n* Using `rcases` and `rintro` as recursive versions of `cases` and `intro`.\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_13_applications_to_even_and_odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7645603734766669}}
{"text": "/-\nThis is a d∃∀duction 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\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éorie des ensembles\nAuthor\n    Frédéric Le Roux\nInstitution\n    Université de France\nDescription\n    Ce cours correspond à un cours standard de théorie \"élémentaire\" 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éorie des ensembles\n-/\n\nnamespace generalites\n/- dEAduction\nPrettyName\n    Généralités\n-/\n\n------------------------\n-- COURSE DEFINITIONS --\n------------------------\nlemma definition.inclusion {A B : set X} : A ⊆ B ↔ ∀ {x:X}, x ∈ A → x ∈ 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') ↔ ( ∀ x, x ∈ A ↔ x ∈ A' ) :=\n/- dEAduction\nPrettyName\n    Egalité 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 = ∅) ↔ ∀ x : X, x ∉ 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 ≠ ∅) ↔ ∃ x : X, x ∈ A\n-- :=\n-- begin\n--     todo\n-- end\n\nlemma definition.ensemble_extension {X: Type}  {P : X → Prop} {x:X} :\n x ∈ {x | P x} ↔ 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' ↔ (A ⊆ A' ∧ A' ⊆ A) :=\n/- dEAduction\nPrettyName\n    Egalité 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 ⊆ B ∧ B ⊆ C) → A ⊆ C\n:=\n/- dEAduction\nPrettyName\n    Transitivité 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éfinitions\n-/\n\nlemma definition.intersection_deux_ensembles {A B : set X} {x : X} :\nx ∈ A ∩ B ↔ ( x ∈ A ∧ x ∈ 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 : Type} {E : I → set X}  {x : X} :\n(x ∈ set.Inter E) ↔ (∀ i:I, x ∈ E i) :=\n/- dEAduction\nPrettyName\n    Intersection d'une famille quelconque d'ensembles\n-/\nbegin\n    exact set.mem_Inter\nend\n\nlemma definition.union_deux_ensembles  {A : set X} {B : set X} {x : X} :\nx ∈ A ∪ B ↔ ( x ∈ A ∨ x ∈ 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 : Type} {E : I → set X}  {x : X} :\n(x ∈ set.Union (λ i, E i)) ↔ (∃ i:I, x ∈ 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 ∩ B ⊆ 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 ∩ (B ∪ C)  = (A ∩ B) ∪ (A ∩ C) :=\n/- dEAduction\nPrettyName\n    Intersection avec une union\nDescription\n    L'intersection est distributive par rapport à 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 ∪ (B ∩ C)  = (A ∪ B) ∩ (A ∪ C) :=\n/- dEAduction\nPrettyName\n    Union avec une intersection\nDescription\n    L'union est distributive par rapport à 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émentaire\n-/\n\n\n-- variables complementaire --\nvariables  {A B : set X}\nvariables {I : index_set} {E F : I → set X}\n-- notation `∁`A := set.compl A\n\n-----------------\n-- DEFINITIONS --\n-----------------\nlemma definition.complement {A : set X} {x : X} : x ∈ set.compl A ↔ x ∉ A :=\n/- dEAduction\nPrettyName\n    Complémentaire\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émentaire du complémentaire\nDescription\n    Tout ensemble est égal au complémentaire de son complémentaire\nAvailableDefinitions\n    $UNTIL_NOW -union_quelconque_ensembles -intersection_quelconque_ensembles\n-/\nbegin\n    todo\nend\n\nlemma exercise.complement_union_deux :\nset.compl (A ∪ B) = (set.compl A) ∩ (set.compl B) :=\n/- dEAduction\nPrettyName\n    Complémentaire d'union I\nDescription\n    Le complémentaire de l'union de deux ensembles égale l'intersection des complémentaires\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 (λ i, E i)) = set.Inter (λ i, set.compl (E i)) :=\n/- dEAduction\nPrettyName\n    Complémentaire d'union II\nDescription\n    Le complémentaire d'une réunion quelconque égale l'intersection des complémentaires\n-/\nbegin\n    -- hypo_analysis,\nend\n\n\nlemma exercise.inclusion_complement_I :\nA ⊆ B → set.compl B ⊆ set.compl A\n:=\n/- dEAduction\nPrettyName\n    Le passage au complémentaire renverse les inclusions, implication\nDescription\n    Si A est inclus dans B, alors le complémentaire de A contient le complémentaire de B\n-/\nbegin\n    todo\nend\n\nlemma exercise.inclusion_complement_II :\nA ⊆ B ↔ set.compl B ⊆ set.compl A\n:=\n/- dEAduction\nPrettyName\n    Le passage au complémentaire renverse les inclusions, équivalence\nDescription\n    Si A est inclus dans B, alors le complémentaire de A contient le complémentaire de B\n-/\nbegin\n    todo\nend\n\n/- Autres : différence-/\n\nend complementaire\n\n\n\n-- Ajouter :  4. relations ?\n\nnamespace produits_cartesiens\n/- dEAduction\nPrettyName\n    Produits cartésiens\n-/\n\n\n-- Peut-on en faire une définition ?\nlemma theorem.type_produit :\n∀ z:X × Y, ∃ x:X, ∃ y:Y, z = (x,y)\n:=\n/- dEAduction\nPrettyName\n    Element d'un produit cartésien 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) ∈ set.prod A B ↔ x ∈ A ∧ y ∈ B\n:=\n/- dEAduction\nPrettyName\n    Produit cartésien 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 ∩ C) = (set.prod A B) ∩ (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érations ensemblistes\n-/\n\n\n-- variables applications --\n\nvariables  {A A': set X}\nvariables {f: X → Y} {B B': set Y}\n-- variables {I : Type} {E : I → set X} {F : I → set Y}\nvariables {I : index_set} {E : set_family I X} {F : set_family I Y}\nvariables (g : Y → Z) (h : X → Z)\n\n-- a-t-on besoin de ceci ?\n-- lemma theorem.egalite_fonctions : f = f' ↔ ∀ x : X, f(x) = f'(x) :=\n--  function.funext_iff\n\n\n-----------------\n-- DEFINITIONS --\n-----------------\nnamespace definitions\n/- dEAduction\nPrettyName\n    Définitions\n-/\n\nlemma definition.image_directe (y : Y) : y ∈ f '' A ↔ ∃ x : X, x ∈ A ∧  f x = y :=\nbegin\n    todo\nend\n\nlemma definition.image_reciproque (x:X) : x ∈ f  ⁻¹' B ↔ f(x) ∈ 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 → Y) :\nf = f' ↔ ∀ x, f x = f' x :=\n/- dEAduction\nPrettyName\n    Egalité de deux fonctions\n-/\nbegin\n    exact function.funext_iff,\nend\n\n\nlemma definition.Identite (f₀: X → X) :\nf₀ = Identite ↔ ∀ x, f₀ x = x :=\n/- dEAduction\nPrettyName\n    Application identité\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 ⁻¹' B)  ⊆ B :=\n/- dEAduction\nPrettyName\n    Image de l'image réciproque\n-/\nbegin\n    todo\nend\n\nlemma exercise.reciproque_de_image : A ⊆ f ⁻¹' (f '' A) :=\n/- dEAduction\nPrettyName\n    Image réciproque de l'image\n-/\nbegin\n    todo\nend\n\nlemma exercise.image_reciproque_inter :  f ⁻¹'  (B∩B') = f ⁻¹'  (B) ∩ f ⁻¹'  (B') :=\n/- dEAduction\nPrettyName\n    Image réciproque d'une intersection de deux ensembles\n-/\nbegin\n    todo\nend\n\nlemma  exercise.image_reciproque_union  : f ⁻¹' (B ∪ B') = f ⁻¹' B ∪ f ⁻¹' B'\n:=\n/- dEAduction\nPrettyName\n    Image réciproque 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 ⁻¹'  (set.Inter (F))) = set.Inter (λ i, f ⁻¹' (F i): set_family I X)\n-- (f ⁻¹'  (set.Inter (λ i, F i))) = set.Inter (λ i, f ⁻¹' (F i))\n:=\n/- dEAduction\nPrettyName\n    Image réciproque d'une intersection quelconque\n-/\nbegin\n    todo\nend\n\nlemma exercise.image_reciproque_union_quelconque :\n(f ⁻¹'  (set.Union (λ i, F i))) = set.Union (λ i, f ⁻¹' (F i))\n:=\n/- dEAduction\nPrettyName\n    Image réciproque d'une union quelconque\n-/\nbegin\n    todo\nend\n\nlemma exercise.image_inter_inclus_inter_images :\nf '' (A∩A') ⊆ f '' (A) ∩ f '' (A')\n:=\n/- dEAduction\nPrettyName\n    Image d'une intersection\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.reciproque_complementaire_I :\nf ⁻¹' (set.compl B) ⊆ set.compl (f ⁻¹' B)\n:=\n/- dEAduction\nPrettyName\n    Image réciproque du complémentaire, inclusion\n-/\nbegin\n    todo\nend\n\nlemma exercise.reciproque_complementaire_II :\nf ⁻¹' (set.compl B) = set.compl (f ⁻¹' B)\n:=\n/- dEAduction\nPrettyName\n    Image réciproque du complémentaire, égalité\n-/\nbegin\n    todo\nend\n\nlemma exercices.image_reciproque.composition\n(C: set Z)\n:\n((composition g f) )⁻¹' C = f ⁻¹' (g ⁻¹' 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 → Y) (g : Y → Z) (h : X → Z)\n\n-----------------\n-- DEFINITIONS --\n-----------------\nnamespace definitions\n/- dEAduction\nPrettyName\n    Définitions\n-/\n\nlemma definition.injectivite :\ninjective f ↔ ∀ x y : X, (f x = f y → x = y)\n:=\n/- dEAduction\nPrettyName\n    Application injective\nImplicitUse\n    True\n-/\nbegin\n    refl,\nend\n\nlemma definition.surjectivite :\nsurjective f ↔ ∀ y : Y, ∃ 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 à enlever de tous les exos où ça ne sert pas !\nlemma definition.existe_un_unique\n(P : X → Prop) :\n(∃! (λx,  P x)) ↔  (∃ x : X, (P x ∧ (∀ x' : X, P x' → x' = x)))\n:=\n/- dEAduction\nPrettyName\n    ∃! : existence et unicité\n-/\nbegin\n    todo\nend\n\nlemma definition.bijectivite_1 :\nbijective f ↔ (injective f ∧ surjective f)\n:=\n/- dEAduction\nPrettyName\n    Application bijective (première définition)\n-/\nbegin\n    todo\nend\n\nlemma definition.bijectivite_2 :\nbijective f ↔ ∀ y : Y, exists_unique (λ x, y = f x)\n:=\n/- dEAduction\nPrettyName\n    Application bijective (seconde définition)\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) ↔\n∃ F: Y → X, (composition F f) = Identite :=\n/- dEAduction\nPrettyName\n    (x) Injectivité et inverse à gauche\n-/\nbegin\n    todo\nend\n\nlemma exercise.surjective_ssi_inverse_droite : (surjective f) ↔\n∃ F: Y → X, (composition f F) = Identite :=\n/- dEAduction\nPrettyName\n    (*) Surjectivité et inverse à droite\n-/\nbegin\n    todo\nend\n\nlemma exercise.bijective_ssi_inverse :\n(bijective f) ↔ ∃ g : Y → X,\ncomposition g f = Identite ∧ composition f g  = Identite\n:=\n/- dEAduction\nPrettyName\n    (**) Bijectivité et existence d'une application réciproque\n-/\nbegin\n    todo\nend\n\nlemma exercise.unicite_inverse :\n(bijective f) → exists_unique (λ g : Y → X,\ncomposition g f = Identite)\n:=\n/- dEAduction\nPrettyName\n    (+) Unicité de la réciproque d'une application bijective\n-/\nbegin\n    todo\nend\n\n\n\nlemma exercise.Cantor (f : X → set X):\n ¬ surjective f\n:=\n/- dEAduction\nPrettyName\n    (+) Théorème 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 ∉ f x}, have H15 : A = {x | x ∉ 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 ∉ 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 ∈ 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 égales ou disjointes\n-- les images réciproques des singletons forment une partition\n-- bijective ssi inversible à g et d et inverses coincident\n\n\nlemma exercise.exercice_ensembles_1\n(A B : set X) :\nA ⊆ B ↔ A ∩ B = A\n:=\n/- dEAduction\nPrettyName\n    Caractérisation 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 ∩  B) = (set.compl A) ∪ (set.compl B)\n:=\n/- dEAduction\nPrettyName\n    Complémentaire d'une intersection\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.exercice_ensembles_3\n(A B : set X) :\nA ∩ B = A ∪ B → A = B\n:=\n/- dEAduction\nPrettyName\n    Quand l'intersection égale l'union\n-/\nbegin\n    todo\nend\n\nlemma exercise.exercice_ensembles_4a\n(A B C : set X) :\nA ∩ B = A ∩ C ∧ (set.compl A) ∩ B = (set.compl A) ∩ C → B ⊆ C\n:=\n/- dEAduction\nPrettyName\n    Caractérisation par intersection avec A et son complémentaire, I\n-/\nbegin\n    todo\nend\n\nlemma exercise.exercice_ensembles_4b\n(A B C : set X) :\nA ∩ B = A ∩ C ∧ (set.compl A) ∩ B = (set.compl A) ∩ C → B = C\n:=\n/- dEAduction\nPrettyName\n    Caractérisaton par intersection avec A et son complémentaire, II\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.exercice_ensembles_5\n(A B C : set X) :\nA ∩ B = A ∩ C ∧ A ∪ B = A ∪ C → B = C\n:=\n/- dEAduction\nPrettyName\n    Même union et même intersection\n-/\nbegin\n    todo\nend\n\n--def diff {X : Type} (A B : set X) := {x ∈ A | ¬ x ∈ B}\n--notation A `\\\\` B := diff A B\n\n-- def symmetric_difference {X : Type} (A B : set X) := (A ∪ B) \\ (A ∩ B)\n-- notation A `Δ` B := symmetric_difference A B\n\nnamespace difference_et_difference_symetrique\n/- dEAduction\nPrettyName\n    Différence et différence symétrique\n-/\n\nnamespace definitions\n/- dEAduction\nPrettyName\n    Définitions\n-/\n\n\nlemma definition.difference\n(A B : set X) (x : X) :\nx ∈ (A \\ B) ↔ x ∈ A ∧ x ∉ B\n:=\n/- dEAduction\nPrettyName\n    Différence de deux ensembles\n-/\nbegin\n    refl,\nend\n\n\nlemma definition.difference_symetrique\n(A B : set X) :\n(A Δ B) =  (A ∪ B) \\ (A ∩ B)\n:=\n/- dEAduction\nPrettyName\n    Différence symétrique 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 Δ B) = (A \\ B) ∪ (B \\ A)\n:=\n/- dEAduction\nPrettyName\n    Différence symétrique I\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_2\n(A B : set X) :\n(A Δ B) = (B Δ A)\n:=\n/- dEAduction\nPrettyName\n    (*) Différence symétrique II\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_3\n(A B C : set X) :\n((A Δ B) Δ C) = (A Δ (B Δ C))\n:=\n/- dEAduction\nPrettyName\n    (**) Différence symétrique III\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_4 :\n∃! (λE : set X, ∀ A : set X, (A Δ E) = A) :=\n/- dEAduction\nPrettyName\n    (+) Différence symétrique VI\n-/\nbegin\n    todo\nend\n\n\nlemma exercise.difference_symetrique_5 (A : set X) :\nexists_unique (λA' : set X, (A Δ A') = set.univ)\n:=\n/- dEAduction\nPrettyName\n    (+) Différence symétrique V\n-/\nbegin\n    todo\nend\n\nlemma exercise.difference_symetrique_6\n(A B : set X) :\n(A Δ B) = ∅ ↔ A = B\n:=\n/- dEAduction\nPrettyName\n    (+) Différence symétrique VI\n-/\nbegin\n    todo\nend\n\nend exercices\n\nend difference_et_difference_symetrique\n\n-- applications\nvariable (f: X → Y)\n\nnamespace applications\n\nlemma exercise.exercice_applications_1\n(A B : set X) :\nA ⊆ B → f '' A ⊆ 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 ∪ B)  = f '' A ∪ 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 → Z) (h: X → Z) :\n(∃ f: X → Y, h = (composition g f)) ↔ h '' set.univ ⊆ 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 → Y) (h: X → Z) :\n(∃ g: Y → Z, h = (composition g f)) ↔ (∀ x y, (f x = f y → 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 → Y) (g: Y → Z)\n(H1 : injective (composition g f)) (H2 : surjective f)\n:\ninjective g\n:=\n/- dEAduction\nPrettyName\n    Injectivité et surjectivité I\n-/\nbegin\n    todo\nend\n\nlemma exercise.injectivite_surjecivite_2 (f: X → Y) (g: Y → Z)\n(H1 : surjective (composition g f)) (H2 : injective g)\n:\nsurjective f\n:=\n/- dEAduction\nPrettyName\n    Injectivité et surjectivité II\n-/\nbegin\n    todo\nend\n\n\n\nlemma exercise.injectivite_categorielle\n(f: Y → Z):\n(injective f) → (∀X: Type, ∀ g h : X → Y, (composition f g) = (composition f h) → g = h)\n:=\n/- dEAduction\nPrettyName\n    Injectivité catégorielle\n-/\nbegin\n    todo\nend\n\nlemma exercise.surjectivite_categorielle\n(f: X → Y):\n(surjective f) →  (∀Z: Type, ∀ g h : Y → Z, (composition g f ) = (composition h f ) → g = h)\n:=\n/- dEAduction\nPrettyName\n    Surjectivité catégorielle\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/exercices_theorie_des_ensembles.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543488, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7645398814104761}}
{"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 α, presented_group constructs the group with\ngenerators α and relations rels as a quotient of free_group α.-/\ndef presented_group {α : Type} (rels : set (free_group α)) :=\n  quotient_group.quotient (subgroup.normal_closure rels)\n\nnamespace presented_group\n\n\nprotected instance group {α : Type} (rels : set (free_group α)) : group (presented_group rels) :=\n  quotient_group.quotient.group (subgroup.normal_closure rels)\n\n/-- `of x` is the canonical map from α to a presented group with generators α. The term x is\nmapped to the equivalence class of the image of x in free_group α. -/\ndef of {α : Type} {rels : set (free_group α)} (x : α) : presented_group rels :=\n  quotient_group.mk (free_group.of x)\n\n/-\nPresented groups satisfy a universal property. If β is a group and f : α → β 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 β\n-/\n\ntheorem closure_rels_subset_ker {α : Type} {β : Type} [group β] {f : α → β} {rels : set (free_group α)} (h : ∀ (r : free_group α), r ∈ rels → coe_fn (free_group.to_group f) r = 1) : subgroup.normal_closure rels ≤ monoid_hom.ker (free_group.to_group f) :=\n  subgroup.normal_closure_le_normal\n    fun (x : free_group α) (w : x ∈ rels) => iff.mpr (monoid_hom.mem_ker (free_group.to_group f)) (h x w)\n\ntheorem to_group_eq_one_of_mem_closure {α : Type} {β : Type} [group β] {f : α → β} {rels : set (free_group α)} (h : ∀ (r : free_group α), r ∈ rels → coe_fn (free_group.to_group f) r = 1) (x : free_group α) (H : x ∈ 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 : α → β that satisfies the given relations to a group homomorphism\nfrom presented_group rels → β. -/\ndef to_group {α : Type} {β : Type} [group β] {f : α → β} {rels : set (free_group α)} (h : ∀ (r : free_group α), r ∈ rels → coe_fn (free_group.to_group f) r = 1) : presented_group rels →* β :=\n  quotient_group.lift (subgroup.normal_closure rels) (monoid_hom.of ⇑(free_group.to_group f))\n    (to_group_eq_one_of_mem_closure h)\n\n@[simp] theorem to_group.of {α : Type} {β : Type} [group β] {f : α → β} {rels : set (free_group α)} (h : ∀ (r : free_group α), r ∈ rels → coe_fn (free_group.to_group f) r = 1) {x : α} : coe_fn (to_group h) (of x) = f x :=\n  free_group.to_group.of\n\ntheorem to_group.unique {α : Type} {β : Type} [group β] {f : α → β} {rels : set (free_group α)} (h : ∀ (r : free_group α), r ∈ rels → coe_fn (free_group.to_group f) r = 1) (g : presented_group rels →* β) (hg : ∀ (x : α), coe_fn g (of x) = f x) {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 α) =>\n      free_group.to_group.unique (monoid_hom.comp g (quotient_group.mk' (subgroup.normal_closure rels))) hg\n\nprotected instance inhabited {α : Type} (rels : set (free_group α)) : Inhabited (presented_group rels) :=\n  { default := 1 }\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/presented_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7645398798330127}}
{"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\n! This file was ported from Lean 3 source module algebra.euclidean_domain.defs\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.Logic.Nontrivial\nimport Mathlib.Algebra.Divisibility.Basic\nimport Mathlib.Algebra.Group.Basic\nimport Mathlib.Algebra.Ring.Defs\n\n/-!\n# Euclidean domains\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 `ℕ` 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* `EuclideanDomain`: Defines Euclidean domain with functions `quotient` and `remainder`. Instances\n  of `Div` and `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.EuclideanDomain.Basic` for most of the theorems about Eucliean domains,\nincluding Bézout's lemma.\n\nSee `Algebra.EuclideanDomain.Instances` for the facts that `ℤ` is a Euclidean domain,\nas is any field.\n\n## Notation\n\n`≺` denotes the well founded relation on the Euclidean domain, e.g. in the example of the polynomial\nring over a field, `p ≺ 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, `EuclideanDomain` is implemented with the existence of a well\nfounded relation `r` on the integral domain `R`, which in the example of `ℤ` would correspond to\nsetting `i ≺ 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 à valeurs finies*]\n  [MR399081]\n* [M. Nagata, *On Euclid algorithm*][MR541021]\n\n\n## Tags\n\nEuclidean domain, transfinite Euclidean domain, Bézout's lemma\n-/\n\n\nuniverse u\n\n/-- A `EuclideanDomain` 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 → ℕ`.\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.  -/\nclass EuclideanDomain (R : Type u) extends CommRing R, Nontrivial R where\n  /-- A division function (denoted `/`) on `R`.\n    This satisfies the property `b * (a / b) + a % b = a`, where `%` denotes `remainder`. -/\n  protected quotient : R → R → R\n  /-- Division by zero should always give zero by convention. -/\n  protected quotient_zero : ∀ a, quotient a 0 = 0\n  /-- A remainder function (denoted `%`) on `R`.\n    This satisfies the property `b * (a / b) + a % b = a`, where `/` denotes `quotient`. -/\n  protected remainder : R → R → R\n  /-- The property that links the quotient and remainder functions.\n    This allows us to compute GCDs and LCMs. -/\n  protected quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a\n  /-- A well-founded relation on `R`, satisfying `r (a % b) b`.\n    This ensures that the GCD algorithm always terminates. -/\n  protected r : R → R → Prop\n  /-- The relation `r` must be well-founded.\n    This ensures that the GCD algorithm always terminates. -/\n  r_wellFounded : WellFounded r\n  /-- The relation `r` satisfies `r (a % b) b`. -/\n  protected remainder_lt : ∀ (a) {b}, b ≠ 0 → r (remainder a b) b\n  /-- An additional constraint on `r`. -/\n  mul_left_not_lt : ∀ (a) {b}, b ≠ 0 → ¬r (a * b) a\n#align euclidean_domain EuclideanDomain\n#align euclidean_domain.quotient EuclideanDomain.quotient\n#align euclidean_domain.quotient_zero EuclideanDomain.quotient_zero\n#align euclidean_domain.remainder EuclideanDomain.remainder\n#align euclidean_domain.quotient_mul_add_remainder_eq EuclideanDomain.quotient_mul_add_remainder_eq\n#align euclidean_domain.r EuclideanDomain.r\n#align euclidean_domain.r_well_founded EuclideanDomain.r_wellFounded\n#align euclidean_domain.remainder_lt EuclideanDomain.remainder_lt\n#align euclidean_domain.mul_left_not_lt EuclideanDomain.mul_left_not_lt\n\nnamespace EuclideanDomain\n\nvariable {R : Type u} [EuclideanDomain R]\n\n/-- Abbreviated notation for the well-founded relation `r` in a Euclidean domain. -/\nlocal infixl:50 \" ≺ \" => EuclideanDomain.r\n\n-- see Note [lower instance priority]\ninstance (priority := 70) : Div R :=\n  ⟨EuclideanDomain.quotient⟩\n\n-- see Note [lower instance priority]\ninstance (priority := 70) : Mod R :=\n  ⟨EuclideanDomain.remainder⟩\n\ntheorem div_add_mod (a b : R) : b * (a / b) + a % b = a :=\n  EuclideanDomain.quotient_mul_add_remainder_eq _ _\n#align euclidean_domain.div_add_mod EuclideanDomain.div_add_mod\n\ntheorem mod_add_div (a b : R) : a % b + b * (a / b) = a :=\n  (add_comm _ _).trans (div_add_mod _ _)\n#align euclidean_domain.mod_add_div EuclideanDomain.mod_add_div\n\ntheorem mod_add_div' (m k : R) : m % k + m / k * k = m := by\n  rw [mul_comm]\n  exact mod_add_div _ _\n#align euclidean_domain.mod_add_div' EuclideanDomain.mod_add_div'\n\ntheorem div_add_mod' (m k : R) : m / k * k + m % k = m := by\n  rw [mul_comm]\n  exact div_add_mod _ _\n#align euclidean_domain.div_add_mod' EuclideanDomain.div_add_mod'\n\ntheorem mod_eq_sub_mul_div {R : Type _} [EuclideanDomain R] (a b : R) : a % b = a - b * (a / b) :=\n  calc\n    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#align euclidean_domain.mod_eq_sub_mul_div EuclideanDomain.mod_eq_sub_mul_div\n\ntheorem mod_lt : ∀ (a) {b : R}, b ≠ 0 → a % b ≺ b :=\n  EuclideanDomain.remainder_lt\n#align euclidean_domain.mod_lt EuclideanDomain.mod_lt\n\ntheorem mul_right_not_lt {a : R} (b) (h : a ≠ 0) : ¬a * b ≺ b := by\n  rw [mul_comm]\n  exact mul_left_not_lt b h\n#align euclidean_domain.mul_right_not_lt EuclideanDomain.mul_right_not_lt\n\n@[simp]\ntheorem mod_zero (a : R) : a % 0 = a := by simpa only [zero_mul, zero_add] using div_add_mod a 0\n#align euclidean_domain.mod_zero EuclideanDomain.mod_zero\n\ntheorem lt_one (a : R) : a ≺ (1 : R) → a = 0 :=\n  haveI := Classical.dec\n  not_imp_not.1 fun h => by simpa only [one_mul] using mul_left_not_lt 1 h\n#align euclidean_domain.lt_one EuclideanDomain.lt_one\n\ntheorem val_dvd_le : ∀ a b : R, b ∣ a → a ≠ 0 → ¬a ≺ b\n  | _, b, ⟨d, rfl⟩, ha => mul_left_not_lt b (mt (by rintro rfl; exact mul_zero _) ha)\n#align euclidean_domain.val_dvd_le EuclideanDomain.val_dvd_le\n\n@[simp]\ntheorem div_zero (a : R) : a / 0 = 0 :=\n  EuclideanDomain.quotient_zero a\n#align euclidean_domain.div_zero EuclideanDomain.div_zero\n\nsection\n\nopen Classical\n\n@[elab_as_elim]\ntheorem GCD.induction {P : R → R → Prop} :\n    ∀ a b : R, (H0 : ∀ x, P 0 x) → (H1 : ∀ a b, a ≠ 0 → P (b % a) a → P a b) → P a b\n  | a => fun b H0 H1 =>\n    if a0 : a = 0 then by\n      -- Porting note: required for hygiene, the equation compiler introduces a dummy variable `x`\n      -- See https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unnecessarily.20tombstoned.20argument/near/314573315\n      change P a b\n      exact a0.symm ▸ H0 b\n    else\n      have _ := mod_lt b a0\n      H1 _ _ a0 (GCD.induction (b % a) a H0 H1)\n  termination_by' ⟨_, r_wellFounded⟩\n#align euclidean_domain.gcd.induction EuclideanDomain.GCD.induction\n\nend\n\nsection GCD\n\nvariable [DecidableEq R]\n\n/-- `gcd a b` is a (non-unique) element such that `gcd a b ∣ a` `gcd a b ∣ b`, and for\n  any element `c` such that `c ∣ a` and `c ∣ b`, then `c ∣ gcd a b` -/\ndef gcd : R → R → R\n  | a => fun b =>\n    if a0 : a = 0 then b\n    else\n      have _ := mod_lt b a0\n      gcd (b % a) a\n  termination_by' ⟨_, r_wellFounded⟩\n#align euclidean_domain.gcd EuclideanDomain.gcd\n\n@[simp]\ntheorem gcd_zero_left (a : R) : gcd 0 a = a := by\n  rw [gcd]\n  exact if_pos rfl\n#align euclidean_domain.gcd_zero_left EuclideanDomain.gcd_zero_left\n\n/-- An 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 `xgcdAux` takes in two triples, and from these recursively computes the next triple:\n```\nxgcdAux (r, s, t) (r', s', t') = xgcdAux (r' % r, s' - (r' / r) * s, t' - (r' / r) * t) (r, s, t)\n```\n-/\ndef xgcdAux : R → R → R → R → R → R → R × R × R\n  | r => fun s t r' s' t' =>\n    if _hr : r = 0 then (r', s', t')\n    else\n      let q := r' / r\n      xgcdAux (r' % r) (s' - q * s) (t' - q * t) r s t\n  termination_by' ⟨_, r_wellFounded⟩\n  decreasing_by (exact mod_lt _ _hr)\n#align euclidean_domain.xgcd_aux EuclideanDomain.xgcdAux\n\n@[simp]\ntheorem xgcd_zero_left {s t r' s' t' : R} : xgcdAux 0 s t r' s' t' = (r', s', t') := by\n  unfold xgcdAux\n  exact if_pos rfl\n#align euclidean_domain.xgcd_zero_left EuclideanDomain.xgcd_zero_left\n\ntheorem xgcdAux_rec {r s t r' s' t' : R} (h : r ≠ 0) :\n    xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by\n  conv =>\n    lhs\n    rw [xgcdAux]\n  exact if_neg h\n#align euclidean_domain.xgcd_aux_rec EuclideanDomain.xgcdAux_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 : R) : R × R :=\n  (xgcdAux x 1 0 y 0 1).2\n#align euclidean_domain.xgcd EuclideanDomain.xgcd\n\n/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcdA (x y : R) : R :=\n  (xgcd x y).1\n#align euclidean_domain.gcd_a EuclideanDomain.gcdA\n\n/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/\ndef gcdB (x y : R) : R :=\n  (xgcd x y).2\n#align euclidean_domain.gcd_b EuclideanDomain.gcdB\n\n@[simp]\ntheorem gcdA_zero_left {s : R} : gcdA 0 s = 0 := by\n  unfold gcdA\n  rw [xgcd, xgcd_zero_left]\n#align euclidean_domain.gcd_a_zero_left EuclideanDomain.gcdA_zero_left\n\n@[simp]\ntheorem gcdB_zero_left {s : R} : gcdB 0 s = 1 := by\n  unfold gcdB\n  rw [xgcd, xgcd_zero_left]\n#align euclidean_domain.gcd_b_zero_left EuclideanDomain.gcdB_zero_left\n\ntheorem xgcd_val (x y : R) : xgcd x y = (gcdA x y, gcdB x y) :=\n  Prod.mk.eta.symm\n#align euclidean_domain.xgcd_val EuclideanDomain.xgcd_val\n\nend GCD\n\nsection LCM\n\nvariable [DecidableEq R]\n\n/-- `lcm a b` is a (non-unique) element such that `a ∣ lcm a b` `b ∣ lcm a b`, and for\n  any element `c` such that `a ∣ c` and `b ∣ c`, then `lcm a b ∣ c` -/\ndef lcm (x y : R) : R :=\n  x * y / gcd x y\n#align euclidean_domain.lcm EuclideanDomain.lcm\n\nend LCM\n\nend EuclideanDomain\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/EuclideanDomain/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533126145178, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.764512259114941}}
{"text": "import algebra.group_power \n-- Need to start off with some fake reals to do Q1,2\n\nconstant fake_reals : Type\n\n@[instance] constant fake_reals_comm_ring : comm_ring fake_reals\n@[instance] constant fake_reals_have_lt : has_lt fake_reals\n-- we define a<=b to mean a<b or a=b. Axiom 3 says that at most one occurs.\n@[instance] noncomputable definition fake_reals_have_le : has_le fake_reals := ⟨λ a b, (a<b) ∨ (a=b)⟩\naxiom A1 {a b t : fake_reals} : a < b → a+t < b+t\naxiom A2 {a b c : fake_reals} : a < b → b < c → a < c\naxiom A3 {a b : fake_reals} : (a < b ∨ a = b ∨ b < a)\n                                   ∧ (a < b → ¬ (a = b))\n                                   ∧ (a < b → ¬ (b < a))\n                                   ∧ (a = b → ¬ (b < a))\naxiom A4 {a b : fake_reals} : a > 0 → b > 0  → (a*b) > 0\n\naxiom A0 : (0 : fake_reals) ≠ (1 : fake_reals)\n\ntheorem one_pos : (1:fake_reals) > 0 :=\nbegin\ncases (@A3 0 1).left with H1pos H1nonpos,\n  assumption,\ncases H1nonpos with H1zero H1neg,\n  exfalso,\n  exact A0 H1zero,\nhave H : (1:fake_reals) + (-1) < 0 + (-1),\n  exact A1 H1neg,\n  rw [add_neg_self,zero_add] at H,\nhave H2 : (-1:fake_reals) * (-1) > 0,\n  exact A4 H H,\nrw [←neg_eq_neg_one_mul] at H2,\n-- exact H2, -- oops\nrw [neg_neg] at H2,\nexact H2,\nend\n\ntheorem Q1 : ∀ x y : fake_reals, 0<x ∧ 0<y → 0<(x+y) := sorry\n\ntheorem n_pos : ∀ n : ℕ, n ≠ 0 → (n : fake_reals) > 0 :=\nbegin\nintro n,\ncases n with m,\n  by norm_num,\ninduction m with p Hp,\n  intro,rw [nat.cast_one],\n  exact one_pos,\nhave H0 : nat.succ p ≠ 0,\n  intro H,\n  exact nat.no_confusion H,\nhave H1 : ↑(nat.succ p) > (0:fake_reals),\n  exact Hp H0,\nintro H,clear Hp H0 H,\n  rw [nat.succ_eq_add_one,nat.cast_add,nat.cast_one],\n  exact Q1 (nat.succ p) 1 ⟨H1,one_pos⟩,\nend\n-- a) We proved in lectures that if x > y and c > 0 then cx > cy. Deduce from this that the\n-- product of a positive number and a negative number is negative.\n\n-- #check @lt_of_sub_pos\n\ntheorem mul_pos_lt_of_lt {x y c : fake_reals} : (y < x) → (0 < c) → c*y < c*x :=\nbegin\nintros Hx_gt_y Hc_gt_zero,\nhave Hsub_gt_zero : 0 < (x-y),\n  rw [sub_eq_add_neg,←(add_neg_self y)],\n  exact A1 Hx_gt_y, -- is apply OK to finish a goal?\nhave H2 : c*(x-y) > 0 := A4 Hc_gt_zero Hsub_gt_zero,\nrw [mul_sub,sub_eq_add_neg] at H2,\nhave H3 : c*x + -(c*y)+c*y>0+c*y := A1 H2,\nrwa [zero_add,add_assoc,neg_add_self,add_zero] at H3,\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/M1F/problem_bank/0301/Q0301.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7645122586015344}}
{"text": "import tactic.finish game.world7.level7 -- hide\nnamespace mynat -- hide\n/- \n# Advanced proposition world. \n\n## Level 8: `and_or_distrib_left`\n\nWe know that `x(y+z)=xy+xz` for numbers, and this\nis called distributivity of multiplication over addition.\nThe same is true for `∧` and `∨` -- in fact `∧` distributes\nover `∨` and `∨` distributes over `∧`. Let's prove one of these.\n-/\n\n/- Lemma\nIf $P$. $Q$ and $R$ are true/false statements, then\n$$P\\land(Q\\lor R)\\iff(P\\land Q)\\lor (P\\land R).$$ \n-/\nlemma and_or_distrib_left (P Q R : Prop) : P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) :=\nbegin\n  split,\n  intro h,\n  cases h with hp hqr,\n  cases hqr with q r,\n  left, split, assumption, assumption,\n  right, split, assumption, assumption,\n  intro h,\n  cases h with hpq hpr,\n  cases hpq with p q,\n  split, assumption,\n  left, assumption,\n  cases hpr with hp hr,\n  split, assumption,\n  right, assumption,\n\n\n\n\nend\n\n/-\n## Pro tip\n\nDid you spot the import? What do you think it does?\n\nIf you follow the instructions at\n<a href=\"https://github.com/leanprover-community/mathlib#installation\" target=\"blank\">the mathlib github page</a>\nyou will be able to install Lean and mathlib on your own system, and then you can create a new project\nand experiment with such imports yourself.\n-/\nend mynat", "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/level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374444, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7645122555241443}}
{"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 combinatorics.simple_graph.basic -- definition of graph\n/-\n\n# Graph theory\n\nA year ago Lean's graph theory was a bit patchy, but now I think\nit's robust enough to be taken seriously as a topic for a final project.\nThis sheet is just an overview of the basic API for graphs; there are\nno sorrys.\n\nSo, how do graphs work in Lean? Actually it took a long time\nto come up with a definition people were happy with. One issue\nis that different people mean different things by \"graph\". In this\nsection we're going to stick to \"simple graphs\", which means\nthat you have a type of vertices `V`, and edges go between two\ndistinct vertices in `V`. The rules for a simple graph:\n\n1) Edges are undirected (so they don't have a source and a target, they\njust have two ends, which are vertices)\n2) You can't have more than one edge between two distinct vertices.\n3) You can't have an edge going from a vertex to itself.\n\nBecause of rule 2, you can represent an edge as a yes/no question:\n\"is there an edge between `v` and `w` or not?\". In other words\nyou can represent edges as a function `adj: V → V → Prop`, and you\ndon't need a separate set or type `E` for edges. `adj` is short\nfor \"adjacent\", so `adj v w` means \"there's an edge between `v` and `w`,\ni.e. \"`v` is adjacent to `w`\".\n\nRule 1 means that `adj` is symmetric (if `v` is adjacent to `w` then\n`w` is adjacent to `v`), and rule 3 means that it is irreflexive,\ni.e. `∀ v, ¬ adj v v`.\n\nHere's how to say \"let `G` be a (simple) graph with vertex set `V`\"\n\n-/\n\nvariables (V : Type) (G : simple_graph V)\n\n-- Here's how to say two edges are adjacent\n\nexample (v w : V) : Prop := G.adj v w\n\n-- If v is adjacent to w then w is adjacent to v\nexample (v w : V) : G.adj v w → G.adj w v := G.adj_symm\n\n-- v isn't adjacent to itself\nexample (v : V) : ¬ G.adj v v := G.irrefl\n\n/-\n\nLongish interlude: here's how to make a square graph. It's quite laborious. \nLean is better at proving theorems than making explicit examples!\n\nv1 -- v2\n|     |\n|     |\nv3 -- v4\n-/\n\nsection square_graph\n\n-- the vertex set of the square graph; we make it a type with four terms\ninductive sqV : Type\n| v1 : sqV\n| v2 : sqV\n| v3 : sqV\n| v4 : sqV\n\nopen sqV -- so I can write `v1` not `sqV.v1`\n\n-- here's one boring way of making the edges -- an inductive proposition\ninductive sqE : sqV → sqV → Prop\n| e12 : sqE v1 v2\n| e21 : sqE v2 v1\n| e24 : sqE v2 v4\n| e42 : sqE v4 v2\n| e34 : sqE v3 v4\n| e43 : sqE v4 v3\n| e13 : sqE v1 v3\n| e31 : sqE v3 v1\n\n-- Now let's make the graph\ndef sqG : simple_graph sqV :=\n{ adj := sqE,\n  symm := begin\n    -- do all the cases for the two vertices and the edge\n    rintro (_ | _ | _ | _) (_ | _ | _ | _) (_ | _ | _ | _ | _ | _ | _ | _),\n    -- now 8 goals; find the right constructor for sqE in all cases\n    repeat {constructor}, \n  end,\n  loopless := begin\n    rintro (_ | _ | _ | _) (_ | _ | _ | _ | _ | _ | _ | _),\n  end }\n\nend square_graph\n\n-- Here's how to make a triangle graph; it's rather easier\n\n-- Here `fin 3` is the \"canonical\" type with 3 terms; to give a term of type `fin 3`\n-- is to give a pair consisting of a natural `n` and a proof that `n < 3`.\n-- Here the `complete_graph` function is doing all the work for you.\nexample : simple_graph (fin 3) := complete_graph (fin 3)\n\n-- The collection of all simple graphs on a fixed vertex set `V` form a Boolean algebra\n-- (whatever that is)\nexample : boolean_algebra (simple_graph V) := by apply_instance\n\n-- and in particular they form a lattice, so you can do stuff like this:\n\nexample : simple_graph V := ⊥ -- empty graph\nexample : simple_graph V := ⊤ -- complete graph\nexample (G H : simple_graph V) : simple_graph V := G ⊔ H -- union of vertices\n-- etc etc, and you can even do this\nexample (G : simple_graph V) : simple_graph V := Gᶜ -- complement, i.e. an edge exists in `Gᶜ` between\n                                                    -- distinct vertices `v` and `w` iff it doesn't\n                                                    -- exist in `G`\n\n-- The *support* of a graph is the vertices that have an edge coming from them.\n\nexample (v : V) : v ∈ G.support ↔ ∃ w, G.adj v w := \nbegin\n  refl, -- true by definition\nend\n\n\n\n-- The `neighbor_set` of a vertex is all the vertices connected to it by an edge.\n\nexample (v : V) : set V := G.neighbor_set v\n\nexample (v w : V) : w ∈ G.neighbor_set v ↔ G.adj v w := iff.rfl -- true by defn\n\n-- The type `sym2 V` is the type of unordered pairs of elements of `V`, i.e. `V × V`\n-- modulo the equivalence relation generated by `(v,w)~(w,v)`.\n-- So you can regard the edges as a subset of `sym2 V`, and that's `G.edge_set`\n\nexample : set (sym2 V) := G.edge_set\n\n-- You can use `v ∈ e` notation if `e : sym2 v`\n-- For example, `G.incidence_set v` is the set of edges coming out of `v`,\n-- regarded as elements of `sym2 V`\n\nexample (v : V) : G.incidence_set v = {e ∈ G.edge_set | v ∈ e} := rfl\n\n-- You can delete a set of edges from `G` using `G.delete_edges`\n\nexample (E : set (sym2 V)) : simple_graph V := G.delete_edges E \n\n-- if E contains edges not in G then this doesn't matter, they're just ignored.\n\n-- You can push a graph forward along an injection\n\nexample (W : Type) (f : V ↪ W) : simple_graph W := G.map f \n\n-- and pull it back along an arbitrary map\n\nexample (U : Type) (g : U → V) : simple_graph U := G.comap g \n\n-- The degree of a vertex is the size of its neighbor_set.\n-- Better assume some finiteness conditions to make this work.\n\nvariable [G.locally_finite]\n\n-- now we have `finset` versions of some `set` things. For example\nexample (v : V) : G.degree v = finset.card (G.neighbor_finset v) := rfl \n\n-- If `H` is another graph on a vertex set `W` \nvariables (W : Type) (H : simple_graph W)\n\n-- then we can consider types of various maps between graphs\n\nexample : Type := G →g H -- maps f:V → W such that v₁~v₂ -> f(v₁)~f(v₂)\nexample : Type := G ↪g H -- injections f : V → W such that v₁~v₂ ↔ f(v₁)~f(v₂)\nexample : Type := G ≃g H -- isomorphisms of graphs", "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/section18graph_theory/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7645122462907536}}
{"text": "import data.real.basic data.real.sqrt data.fintype.basic \n         algebra.big_operators data.nat.modeq data.int.modeq data.fin.basic\n         data.zmod.basic\nimport tactic.find tactic.squeeze \nimport combinatorics.fiber\n\nnamespace MAS114\nnamespace exercises_1\nnamespace Q2\n\n/- part (i) \n We are asked about the following definition:\n  f : ℕ → ℝ is given by f n = sqrt n.\n\n There are two wrinkles when formalising this in Lean.\n\n Firstly, like most things with reals, we need to mark the \n definition as noncomputable.  In Lean, \"computation\" means\n \"exact computation\", and we do not have algorithms for\n exact computation with real numbers.\n\n Secondly, the Lean library defines a function \n real.sqrt : ℝ → ℝ, which is the ordinary square root for\n nonnegative arguments, but is zero for negative arguments,\n so it does not satisfy (real.sqrt x) ^ 2 = x in general.\n Because of this, we feel obliged to provide a proof that\n our function f has the expected property (f n) ^ 2 = n.\n Note here that the right hand side of this equation involves\n an implicit cast from ℕ to ℝ.  We will have to do quite a\n lot of messing around with casts like this.\n-/\n\nnoncomputable def f : ℕ → ℝ := λ n, real.sqrt n\n\nlemma f_spec : ∀ n : ℕ, (f n) ^ 2 = n := \nbegin\n intro n,\n have h0 : (0 : ℝ) ≤ (n : ℝ) := nat.cast_le.mpr (nat.zero_le n),\n exact real.sq_sqrt h0,\nend\n\n/- f is injective -/\nlemma f_inj : function.injective f := \nbegin\n intros n₀ n₁ e,\n let n_R₀ := (n₀ : ℝ),\n let n_R₁ := (n₁ : ℝ),\n have e₁ : n_R₀ = n_R₁ := calc \n  n_R₀  = (f n₀) ^ 2 : (f_spec n₀).symm\n    ... = (f n₁) ^ 2 : by rw[e]\n    ... = n_R₁ : (f_spec n₁),\n exact nat.cast_inj.mp e₁,\nend\n\n/- f is not surjective -/\nlemma f_not_surj : ¬ (function.surjective f) := \nbegin\n intro f_surj,\n rcases (f_surj (1/2)) with ⟨n,e0⟩,\n let n_R := (n : ℝ),\n have e1 : 4 * n_R  = (((4 * n) : ℕ) : ℝ) := by\n  { dsimp[n_R],rw[nat.cast_mul,nat.cast_bit0,nat.cast_bit0,nat.cast_one] },\n let e2 := calc \n  4 * n_R = 4 * ((f n) ^ 2) : by rw[f_spec n]\n  ... = 4 * ((1 / 2) ^ 2) : by rw[e0]\n  ... = 1 : by ring \n  ... = ((1 : ℕ) : ℝ) : by rw[nat.cast_one],\n let e3 : 4 * n = 1 := nat.cast_inj.mp (e1.symm.trans e2),\n let e4 := calc \n  0 = (4 * n) % 4 : (nat.mul_mod_right 4 n).symm\n  ... = 1 % 4 : by rw[e3]\n  ... = 1 : rfl,\n injection e4,\nend\n\n/- part (ii) -/\n\n/-\n We are asked to pass judgement on the following \"definition\" : \n\n  g : ℤ → ℝ is given by g n = sqrt n.\n\n We do this by proving that there is no map g : ℤ → ℝ such that \n (g n) ^ 2 = n for all n.\n-/\n\nlemma square_nonneg {α : Type*} [linear_ordered_ring α] (x : α) : 0 ≤ x * x := \nbegin \n rcases (le_or_gt 0 x) with x_nonneg | x_neg,\n {exact mul_nonneg x_nonneg x_nonneg,},\n {have x_nonpos : x ≤ 0 := le_of_lt x_neg,\n  exact mul_nonneg_of_nonpos_of_nonpos x_nonpos x_nonpos\n }\nend\n\n/-\n I am surprised that this does not seem to be in the library.\n Perhaps I did not look in the right way.\n-/\nlemma neg_one_not_square {α : Type*} [linear_ordered_ring α] (x : α) :\n x * x ≠ -1 :=\nbegin\n intro e0,\n have e1 : (0 : α) ≤ -1 := e0.subst (square_nonneg x),\n have e2 : (-1 : α) < 0 := neg_neg_of_pos zero_lt_one,\n exact not_le_of_gt e2 e1,\nend\n\nlemma g_does_not_exist : ¬ ∃ (g : ℤ → ℝ), (∀ n : ℤ, (g n) ^ 2 = n) := \nbegin\n rintro ⟨g,g_spec⟩,\n let x := g ( -1 ),\n have e0 : -1 = (( -1 : ℤ ) : ℝ) := by simp, \n have e1 : x * x = -1 := \n  by { rw[← pow_two], dsimp[x], rw[e0], exact g_spec ( -1 )},\n exact neg_one_not_square x e1,\nend\n\n/- part (iii) -/\n\n/-\n We are asked about the following definition:\n\n  h : ℤ → ℕ is given by h(n) = |n|.\n\n There is no problem with formalising the definition.  Note,\n however, that the Lean library defines both \n int.abs : ℤ → ℤ and int.nat_abs : ℤ → ℕ; we need the\n latter here.\n-/\n\ndef h : ℤ → ℕ := int.nat_abs\n\n/- h is not injective -/\nlemma h_not_inj : ¬ (function.injective h) := \nbegin\n intro h_inj,\n let e : (1 : ℤ) = (-1 : ℤ) := @h_inj (1 : ℤ) (-1 : ℤ) rfl,\n injection e,\nend\n\n/- h is surjective -/\nlemma h_surj : function.surjective h := \nbegin\n intro n,use n,refl,\nend\n\n/- part (iv) -/\n\n/-\n We are asked to pass judgement on the following \"definition\" : \n\n  i : ℕ → ℕ is given by i n = 100 - n.\n\n We do this by proving that there is no map i : ℕ → ℕ such that \n (i n) + n = 100 for all n.\n\n  Note, however, that Lean would happily accept the definition\n   def i (n : ℕ) : ℕ := 100 - n, but it would interpret the \n  minus sign as truncated subtraction, so that i n = 0 for n ≥ 100.\n-/\n\nlemma i_does_not_exist : ¬ ∃ (i : ℕ → ℕ), (∀ n : ℕ, (i n) + n = 100) := \nbegin\n rintro ⟨i,i_spec⟩,\n have e0 : 101 ≤ 100 := (i_spec 101).subst (nat.le_add_left 101 (i 101)),\n let e1 : 100 < 101 := nat.lt_succ_self 100,\n exact not_le_of_gt e1 e0,\nend\n\n/- part (v) -/\n\n/-\n We are asked about the following definition:\n\n  j : ℤ → ℤ is given by j(n) = - n.\n\n There is no problem with formalising the definition.  We \n then prove that j j = 1, so j is self-inverse.  We use \n theorems from the library to deduce from this that j is\n injective, surjective and bijective, rather than working\n directly from the definitions. \n-/\n\ndef j : ℤ → ℤ := λ n, - n\n\nlemma jj (n : ℤ) : j (j n) = n := by simp[j]\n\nlemma j_inj : function.injective j := function.left_inverse.injective jj\n\nlemma j_surj : function.surjective j := function.right_inverse.surjective jj\n\nlemma j_bij : function.bijective j := ⟨j_inj,j_surj⟩\n\n/- part (vi) -/\n\n/-\n We are asked to pass judgement on the following \"definition\" : \n\n  k : ℝ → ℤ sends x ∈ ℝ to the closest integer.\n\n We define precisely what it means for n to be the closest\n integer to x : we should have | x - m | > | x - n | for any\n integer m ≠ n.  We then show that if m ∈ ℤ, there is no \n closest integer to m + 1/2.  From this we deduce that there\n is no function k with the expected properties.\n\n This is much harder work than you might think.  A lot of the \n problem is caused by the cast maps ℤ → ℚ → ℝ\n-/\n\ndef is_closest_integer (n : ℤ) (x : ℝ) := \n ∀ m : ℤ, m ≠ n → abs ( x - m ) > abs ( x - n )\n\n/-\n Even basic identities like 1/2 - 1 = -1/2 cannot easily be \n proved directly in ℝ, because there are no general algorithms\n for exact calculation in ℝ.  We need to work in ℚ and then \n apply the cast map.\n-/\n\ndef half_Q : ℚ := 1 / 2\ndef neg_half_Q : ℚ := - half_Q\nnoncomputable def half_R : ℝ := half_Q\nnoncomputable def neg_half_R : ℝ := neg_half_Q\n\n/-\n Here is a small identity that could in principle be proved \n by a long string of applications of the commutative ring axioms.\n The \"ring\" tactic automates the process of finding this string.\n\n For reasons that I do not fully understand, the ring tactic\n seems to work more reliably if we do it in a separate lemma \n so that the terms are just free variables.  We can then \n substitute values for this variables as an extra step.  In \n particular, we will substitute h = 1/2, and then give a \n separate argument that the final term 2 * h - 1 is zero.\n-/\nlemma misc_identity (m n h : ℝ) :\n (m + h) - (2 * m + 1 - n) = - ((m + h) - n) + (2 * h - 1) := \n  by ring \n\n/-\n We now prove that there is no closest integer to m + 1/2.\n The obvious approach would be to focus attention on the \n candidates n = m and n = m + 1, but it turns out that that\n creates more work than necessary.  It is more efficient to \n prove that for all n, the integer k = 2 m + 1 - n is different\n from n and lies at the same distance from m + 1/2, so \n n does not have the required property.  \n-/\nlemma no_closest_integer (n m : ℤ) : \n ¬ (is_closest_integer n ((m : ℝ) + half_R)) := \nbegin\n intro h0,\n let x_Q : ℚ := (m : ℚ) + half_Q, \n let x_R : ℝ := (m : ℝ) + half_R, \n let k := 2 * m + 1 - n,\n by_cases e0 : k = n,\n {-- In this block we consider the possibility that k = n, and \n  -- show that it is impossible.\n  exfalso,\n  dsimp[k] at e0,\n  let e1 := calc \n   (1 : ℤ) = (2 * m + 1 - n) + n - 2 * m : by ring\n   ... = n + n - 2 * m : by rw[e0]\n   ... = 2 * (n - m) : by ring,\n  have e2 := calc \n   (1 : ℤ) = int.mod 1 2 : rfl\n   ... = int.mod (2 * (n - m)) 2 : congr_arg (λ x, int.mod x 2) e1\n   ... = 0 : int.mul_mod_right 2 (n - m),\n  exact (dec_trivial : (1 : ℤ) ≠ 0) e2,\n },{\n  let h1 := ne_of_gt (h0 k e0),\n  let u_R := x_R - n,\n  let v_R := x_R - k,\n  have h2 : v_R = - u_R + (2 * half_R - 1) := begin\n   dsimp[u_R,v_R,x_R,k],\n   rw[int.cast_sub,int.cast_add,int.cast_mul,int.cast_bit0,int.cast_one],\n   exact misc_identity (↑ m) (↑ n) half_R,\n  end,\n  have h3 : 2 * half_R - 1 = 0 := by { dsimp[half_R,half_Q], norm_num },\n  rw[h3,add_zero] at h2,\n  have h4 : abs v_R = abs u_R := by rw[h2,abs_neg],\n  exact h1 h4,\n }\nend\n\nlemma k_does_not_exist : ¬ ∃ (k : ℝ → ℤ), (∀ x : ℝ, is_closest_integer (k x) x) := \nbegin\n rintro ⟨k,k_spec⟩,\n let x : ℝ := (0 : ℤ) + half_R, \n exact no_closest_integer (k x) 0 (k_spec x)\nend\n\nend Q2\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q3\n\n/-\n Here we ask various questions about functions between the\n sets A = {1,2,..,10} and B = {1,2,...,100}.\n\n Everything would be a bit easier if we modified the question\n and used the sets {0,...,9} and {0,...,99} instead, because \n Lean starts things at zero by default.  However, we have \n decided to bite the bullet and deal with the extra complexity.\n-/\n\ndef A0 : finset ℕ := (finset.range 11).erase 0\ndef B0 : finset ℕ := (finset.range 101).erase 0\n\ndef A := {n // n ∈ A0}\ndef B := {n // n ∈ B0}\n\ninstance A_fintype : fintype A := by {dsimp[A],apply_instance}\ninstance B_fintype : fintype B := by {dsimp[B],apply_instance}\n\nlemma A_card : fintype.card A = 10 := \n fintype.subtype_card A0 (by {intro H,refl})\n\nlemma B_card : fintype.card B = 100 := \n fintype.subtype_card B0 (by {intro H,refl})\n\nlemma A_in_B {i : ℕ} (i_in_A : i ∈ A0) : i ∈ B0 := \nbegin\n rcases (finset.mem_erase.mp i_in_A) with ⟨i_ne_0,i_in_range_11⟩,\n have i_lt_11 := finset.mem_range.mp i_in_range_11,\n have : 11 < 101 := dec_trivial,\n have i_lt_101 : i < 101 := lt_trans i_lt_11 this,\n have i_in_range_101 := finset.mem_range.mpr i_lt_101,\n exact finset.mem_erase.mpr ⟨i_ne_0,i_in_range_101⟩\nend\n\n/-\n We want to define f : A → B to be the inclusion.  \n In Lean, the proof that A is contained in B has to be \n wrapped in to the definition of f.\n-/\n\ndef f : A → B := λ ⟨i,i_in_A⟩, ⟨i,A_in_B i_in_A⟩\n\n/- f is injective -/\nlemma f_inj : function.injective f := \nbegin\n rintros ⟨i,i_in_A⟩ ⟨j,j_in_A⟩ e,\n dsimp[f] at e,\n have e1 : i = j := congr_arg subtype.val e,\n exact subtype.eq e1\nend\n\n/-\n We now want to define g : B → A by g n = n for n ≤ 10, \n and g n = 10 for n > 10.  We first define this as a \n map g0 : B → ℕ, then give the proof that g0 B ⊆ A, \n then use this to construct g as a map B → A.\n-/\ndef g0 : B → ℕ := λ ⟨j,j_in_B⟩, if j < 11 then j else 10\n\nlemma g0_in_A : ∀ b : B, (g0 b ∈ A0) \n| ⟨j,j_in_B⟩ := begin\n rcases (finset.mem_erase.mp j_in_B) with ⟨j_ne_0,j_in_range_101⟩,\n have j_lt_101 := finset.mem_range.mp j_in_range_101,\n by_cases h : j < 11,\n {have : g0 ⟨j,j_in_B⟩ = j := by {dsimp[g0],rw[if_pos h]},\n  rw[this],\n  let j_in_range_11 := finset.mem_range.mpr h,\n  exact finset.mem_erase.mpr ⟨j_ne_0,j_in_range_11⟩, \n },{\n  have : g0 ⟨j,j_in_B⟩ = 10 := by {dsimp[g0],rw[if_neg h]},\n  rw[this],\n  exact finset.mem_erase.mpr ⟨dec_trivial,finset.mem_range.mpr dec_trivial⟩, \n } \nend\n\ndef g (b : B) : A := ⟨g0 b,g0_in_A b⟩\n\n/- We have g f a = a for all a ∈ A, so g is a left inverse for f -/\n\nlemma gf : function.left_inverse g f \n| ⟨i,i_in_A⟩ := begin\n rcases (finset.mem_erase.mp i_in_A) with ⟨i_ne_0,i_in_range_11⟩,\n have i_lt_11 := finset.mem_range.mp i_in_range_11,\n apply subtype.eq,\n dsimp[f,g,g0],\n rw[if_pos i_lt_11],\nend\n\n/- g is surjective (because it has a right inverse) -/\nlemma g_surj : function.surjective g := function.right_inverse.surjective gf\n\n/- There is no injective map j : B → A, because |B| > |A|.\n   We use the library theorem fintype.card_le_of_injective\n   for this.\n-/\nlemma no_injection : ¬ ∃ j : B → A, function.injective j := \nbegin\n rintro ⟨j,j_inj⟩,\n let h := fintype.card_le_of_injective j j_inj,\n rw[A_card,B_card] at h,\n exact not_lt_of_ge h dec_trivial,\nend\n\n/- There is no surjective map p : A → B, because |B| > |A|.\n   We use the theorem card_le_of_projective for this.\n   Surprisingly, this does not seem to be in the standard\n   library.  It is proved in the separate file fiber.lean\n   distributed alongside this one.\n-/\nlemma no_surjection : ¬ ∃ p : A → B, function.surjective p := \nbegin \n rintro ⟨p,p_surj⟩,\n let h := combinatorics.card_le_of_surjective p_surj,\n rw[A_card,B_card] at h,\n exact not_lt_of_ge h dec_trivial,\nend\n\nend Q3\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q4\n\n/-\n This question is about \"gappy sets\", ie subsets s in \n fin n = {0,...,n-1} such that s contains no adjacent pairs\n {i,i+1}.  \n-/\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 : ℕ} : fin (n.succ) := 0\n\nlemma fin.z_val {n : ℕ} : (@fin.z n).val = 0 := rfl\n\nlemma fin.succ_ne_z {n : ℕ} (a : fin n) : a.succ ≠ fin.z := \nbegin\n cases a with a_val a_is_lt,\n intro e,\n replace e := fin.veq_of_eq e, cases e\nend\n\ndef is_gappy : ∀ {n : ℕ} (s : finset (fin n)), Prop \n| 0 _ := true\n| (nat.succ n) s := ∀ a : fin n, ¬ (a.cast_succ ∈ s ∧ a.succ ∈ s)\n\ninstance is_gappy_decidable :\n forall {n : ℕ} (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 : ℕ) : finset (finset (fin n)) := \n finset.univ.filter is_gappy\n\ndef gappy (n : ℕ) : Type := \n { s : finset (fin n) // is_gappy s }\n\ninstance {n : ℕ} : fintype (gappy n) := \n by { dsimp[gappy], apply_instance }\n\ninstance {n : ℕ} : decidable_eq (gappy n) := \n by { dsimp[gappy], apply_instance }\n\ninstance {n : ℕ} : has_repr (gappy n) := \n ⟨λ (s : gappy n), repr s.val⟩\n\ninstance {n : ℕ} : has_mem (fin n) (gappy n) := ⟨λ i s, i ∈ s.val⟩\n\ndef shift {n : ℕ} (s : finset (fin n)) : finset (fin n.succ) := \n s.image fin.succ\n\ndef unshift {n : ℕ} (s : finset (fin n.succ)) : finset (fin n) := \n finset.univ.filter (λ a, a.succ ∈ s)\n\nlemma mem_shift {n : ℕ} (s : finset (fin n)) (a : fin n.succ) :\n a ∈ shift s ↔ ∃ b : fin n, b ∈ s ∧ b.succ = a := \nbegin\n rw[shift],split,\n {intro a_in_shift,\n  rcases finset.mem_image.mp a_in_shift with ⟨b,⟨b_in_s,e⟩⟩,\n  use b,\n  exact ⟨b_in_s,e⟩, \n },{\n  rintro ⟨b,⟨b_in_s,e⟩⟩,\n  exact finset.mem_image.mpr ⟨b,⟨b_in_s,e⟩⟩, \n }\nend\n\nlemma zero_not_in_shift {n : ℕ} (s : finset (fin n)) : \n fin.z ∉ shift s := \nbegin\n intro h0,\n rcases ((mem_shift s) 0).mp h0 with ⟨⟨b,b_is_lt⟩,⟨b_in_s,e⟩⟩,\n cases congr_arg subtype.val e\nend\n\nlemma succ_mem_shift_iff {n : ℕ} (s : finset (fin n)) (a : fin n) : \n a.succ ∈ shift s ↔ a ∈ s := \nbegin\n rw[mem_shift s a.succ],\n split,{\n   rintro ⟨b,⟨b_in_s,u⟩⟩,\n   rw[(fin.succ_inj.mp u).symm],\n   exact b_in_s,\n },{\n   intro a_in_s,use a,exact ⟨a_in_s,rfl⟩,\n }\nend\n\nlemma mem_unshift {n : ℕ} (s : finset (fin n.succ)) (a : fin n) :\n a ∈ unshift s ↔ a.succ ∈ s := \nbegin\n rw[unshift,finset.mem_filter],\n split,\n {intro h,exact h.right},\n {intro h,exact ⟨finset.mem_univ a,h⟩ }\nend\n\nlemma unshift_shift {n : ℕ} (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 : ℕ} (s : finset (fin n.succ)) : \n unshift (insert fin.z s) = unshift s := \nbegin\n ext,rw[mem_unshift,mem_unshift,finset.mem_insert],\n split,\n {intro h,rcases h with h0 | h1,\n  {exfalso,exact fin.succ_ne_z a h0},\n  {exact h1}\n },\n {exact λ h,or.inr h}\nend\n\nlemma shift_unshift0 {n : ℕ} (s : finset (fin n.succ)) (h : fin.z ∉ s) :\n shift (unshift s) = s := \nbegin\n ext, \n rcases a with ⟨_ | b_val,a_is_lt⟩,\n {have e : @fin.z n = ⟨0,a_is_lt⟩ := fin.eq_of_veq rfl,\n  rw[← e],simp only[zero_not_in_shift,h],\n },{\n  let b : fin n := ⟨b_val,nat.lt_of_succ_lt_succ a_is_lt⟩,\n  have e : b.succ = ⟨b_val.succ,a_is_lt⟩ := \n    by { apply fin.eq_of_veq, refl },\n  rw[← e,succ_mem_shift_iff (unshift s) b,mem_unshift s b],\n }\nend\n\nlemma shift_unshift1 {n : ℕ} (s : finset (fin n.succ)) (h : fin.z ∈ s) :\n insert fin.z (shift (unshift s)) = s :=\nbegin\n ext, \n rw[finset.mem_insert],\n rcases a with ⟨_ | b_val,a_is_lt⟩,\n {have e : @fin.z n = ⟨0,a_is_lt⟩ := fin.eq_of_veq rfl,\n  rw[← e],simp only[h,eq_self_iff_true,true_or],\n },{\n  let b : fin n := ⟨b_val,nat.lt_of_succ_lt_succ a_is_lt⟩,\n  have e : b.succ = ⟨b_val.succ,a_is_lt⟩ := \n    by { apply fin.eq_of_veq, refl, },\n  rw[← e,succ_mem_shift_iff (unshift s) b,mem_unshift s b],\n  split,\n  {rintro (u0 | u1),\n   {exfalso,exact fin.succ_ne_z b u0,},\n   {exact u1}\n  },\n  {intro h,right,exact h,}\n }\nend\n\nlemma shift_gappy : ∀ {n : ℕ} {s : finset (fin n)},\n is_gappy s → is_gappy (shift s)\n| 0 _ _ := λ a, fin.elim0 a\n| (nat.succ n) s s_gappy := begin\n rintros ⟨a,a_is_lt⟩ ⟨a_in_shift,a_succ_in_shift⟩,\n let a₀ : fin n.succ := ⟨a,a_is_lt⟩,\n let a_in_s : a₀ ∈ s := \n   (succ_mem_shift_iff s a₀).mp a_succ_in_shift,\n rcases (mem_shift s a₀.cast_succ).mp a_in_shift with ⟨⟨b,b_is_lt⟩,⟨b_in_s,eb⟩⟩,\n let b₀ : fin n.succ := ⟨b,b_is_lt⟩,\n replace eb := congr_arg subtype.val eb,\n change b.succ = a at eb,\n let c_is_lt : b < n :=\n  nat.lt_of_succ_lt_succ (eb.symm ▸ a_is_lt), \n let c₀ : fin n := ⟨b,c_is_lt⟩,\n have ebc : b₀ = fin.cast_succ c₀ := fin.eq_of_veq rfl,\n have eac : a₀ = fin.succ c₀ := \n   fin.eq_of_veq (nat.succ.inj (by { change a.succ = b.succ.succ, rw[← eb],})),\n change b₀ ∈ s at b_in_s, rw[ebc] at b_in_s,\n rw[eac] at a_in_s,\n exact s_gappy c₀ ⟨b_in_s,a_in_s⟩, \nend\n\nlemma unshift_gappy : ∀ {n : ℕ} {s : finset (fin n.succ)},\n is_gappy s → is_gappy (unshift s)\n| 0 _ _ := trivial\n| (nat.succ n) s s_gappy := begin\n rintros ⟨a,a_is_lt⟩ ⟨a_in_unshift,a_succ_in_unshift⟩,\n let a₀ : fin n := ⟨a,a_is_lt⟩,\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 := fin.eq_of_veq rfl,\n rw[e] at a_succ_in_s,\n exact s_gappy a₀.succ ⟨a_succ_in_s,a_succ_succ_in_s⟩,\nend\n\nlemma insert_gappy : ∀ {n : ℕ} {s : finset (fin n.succ.succ)}, \n is_gappy s → (∀ (a : fin n.succ.succ), a ∈ s → a.val ≥ 2) → \n  is_gappy (insert fin.z s) := \nbegin\n rintros n s s_gappy s_big ⟨a,a_is_lt⟩ ⟨a_in_t,a_succ_in_t⟩,\n rcases finset.mem_insert.mp a_succ_in_t with a_succ_zero | a_succ_in_s;\n let a₀ : fin n.succ := ⟨a,a_is_lt⟩,\n {exact fin.succ_ne_z a₀ a_succ_zero},\n let a_pos : 0 < a := nat.lt_of_succ_lt_succ (s_big a₀.succ a_succ_in_s),\n rcases finset.mem_insert.mp a_in_t with a_zero | a_in_s,\n {replace a_zero : a = 0 := congr_arg subtype.val a_zero,\n  rw[a_zero] at a_pos,\n  exact lt_irrefl 0 a_pos,\n },{\n  exact s_gappy a₀ ⟨a_in_s,a_succ_in_s⟩, \n }\nend\n\ndef i {n : ℕ} (s : gappy n) : gappy n.succ := \n ⟨shift s.val,shift_gappy s.property⟩ \n\nlemma i_val {n : ℕ} (s : gappy n) : (i s).val = shift s.val := rfl\n\nlemma zero_not_in_i {n : ℕ} (s : gappy n) : fin.z ∉ (i s) := \n zero_not_in_shift s.val\n\nlemma shift_big {n : ℕ} (s : finset (fin n)) : \n ∀ (a : fin n.succ.succ), a ∈ shift (shift s) → a.val ≥ 2 := \nbegin\n rintro ⟨a,a_is_lt⟩ ma,\n rcases (mem_shift (shift s) ⟨a,a_is_lt⟩).mp ma with ⟨⟨b,b_is_lt⟩,⟨mb,eb⟩⟩,\n rcases (mem_shift s ⟨b,b_is_lt⟩).mp mb with ⟨⟨c,c_is_lt⟩,⟨mc,ec⟩⟩,\n rw[← eb,← ec],\n apply nat.succ_le_succ,\n apply nat.succ_le_succ,\n exact nat.zero_le c\nend\n\ndef j {n : ℕ} (s : gappy n) : gappy n.succ.succ := \n ⟨insert fin.z (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⟩\n\nlemma j_val {n : ℕ} (s : gappy n) :\n (j s).val = insert fin.z (shift (shift s.val)) := rfl\n\nlemma zero_in_j {n : ℕ} (s : gappy n) : fin.z ∈ (j s) := \n finset.mem_insert_self _ _\n\ndef p {n : ℕ} : (gappy n) ⊕ (gappy n.succ) → gappy n.succ.succ \n| (sum.inl s) := j s\n| (sum.inr s) := i s\n\ndef q {n : ℕ} (s : gappy n.succ.succ) : (gappy n) ⊕ (gappy n.succ) := \nif fin.z ∈ s then\n sum.inl ⟨unshift (unshift s.val),unshift_gappy (unshift_gappy s.property)⟩\nelse\n sum.inr ⟨unshift s.val,unshift_gappy s.property⟩ \n\nlemma qp {n : ℕ} (s : (gappy n) ⊕ (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)],\n  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 : ℕ} (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 fin.z (shift (shift (unshift (unshift s.val )))) = s.val,\n  have z_not_in_us : fin.z ∉ unshift s.val := begin\n   intro z_in_us,\n   let z_succ_in_s := (mem_unshift s.val fin.z).mp z_in_us,\n   exact s.property fin.z ⟨h,z_succ_in_s⟩,\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 : ℕ} :\n ((gappy n) ⊕ (gappy n.succ)) ≃ (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 : ℕ) :\n fintype.card (gappy n.succ.succ) =\n  fintype.card (gappy n) + fintype.card (gappy n.succ) := \nby rw[← fintype.card_congr (@gappy_equiv n),fintype.card_sum]\n\ndef fibonacci : ℕ → ℕ \n| 0 := 0\n| 1 := 1\n| (nat.succ (nat.succ n)) := (fibonacci n) + (fibonacci n.succ)\n\nlemma gappy_card : ∀ (n : ℕ), 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 Q4\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q5\n\ndef A : finset ℕ := [0,1,2].to_finset\ndef B : finset ℕ := [0,1,2,3].to_finset\ndef C : finset ℤ := [-2,-1,0,1,2].to_finset\ndef D : finset ℤ := [-3,-2,-1,0,1,2,3].to_finset\n\nlemma int.lt_succ_iff {n m : ℤ} : n < m + 1 ↔ n ≤ m := \n ⟨int.le_of_lt_add_one,int.lt_add_one_of_le⟩ \n\nlemma nat.square_le {n m : ℕ} : m ^ 2 ≤ n ↔ m ≤ n.sqrt := \n ⟨λ h0, le_of_not_gt (λ h1, not_le_of_gt ((pow_two m).symm.subst (nat.sqrt_lt.mp h1)) h0),\n  λ h0, le_of_not_gt (λ h1,not_le_of_gt (nat.sqrt_lt.mpr ((pow_two m).subst h1)) h0)⟩ \n\nlemma nat.square_lt {n m : ℕ} : m ^ 2 < n.succ ↔ m ≤ n.sqrt :=\n (@nat.lt_succ_iff (m ^ 2) n).trans (@nat.square_le n m)\n\nlemma int.abs_le {n m : ℤ} : abs m ≤ n ↔ (- n ≤ m ∧ m ≤ n) := \nbegin\n by_cases hm : 0 ≤ m,\n { rw[abs_of_nonneg hm],\n   exact ⟨ \n     λ hmn, ⟨le_trans (neg_nonpos_of_nonneg (le_trans hm hmn)) hm,hmn⟩,\n     λ hmn, hmn.right\n      ⟩ \n },{\n   let hma := le_of_lt (lt_of_not_ge hm),\n   let hmb := neg_nonneg_of_nonpos hma,\n   rw[abs_of_nonpos hma],\n   exact ⟨ \n     λ hmn, ⟨(neg_neg m) ▸ (neg_le_neg hmn),le_trans (le_trans hma hmb) hmn⟩,\n     λ hmn, (neg_neg n) ▸ (neg_le_neg hmn.left), \n    ⟩\n }\nend\n\nlemma int.abs_le' {n : ℕ} {m : ℤ} : m.nat_abs ≤ n ↔ (- (n : ℤ) ≤ m ∧ m ≤ n) := \nbegin\n let h := @int.abs_le n m,\n rw[int.abs_eq_nat_abs,int.coe_nat_le] at h,\n exact h,\nend\n\nlemma int.abs_square (n : ℤ) : n ^ 2 = (abs n) ^ 2 := begin\n by_cases h0 : n ≥ 0,\n {rw[abs_of_nonneg h0]},\n {rw[abs_of_neg (lt_of_not_ge h0),pow_two,pow_two,neg_mul_neg],}\nend\n\nlemma int.abs_square' (n : ℤ) : n ^ 2 = ((int.nat_abs n) ^ 2 : ℕ) :=\n calc \n   n ^ 2 = n * n : pow_two n\n   ... = ↑ (n.nat_abs * n.nat_abs) : int.nat_abs_mul_self.symm\n   ... = ↑ (n.nat_abs ^ 2 : ℕ) : by rw[(pow_two n.nat_abs).symm]\n\nlemma int.square_le {n : ℕ} {m : ℤ} : \n m ^ 2 ≤ n ↔ - (n.sqrt : ℤ) ≤ m ∧ m ≤ n.sqrt := \nbegin\n rw[int.abs_square',int.coe_nat_le,nat.square_le,int.abs_le'],\nend\n\nlemma int.square_lt {n : ℕ} {m : ℤ} : \n m ^ 2 < n.succ ↔ - (n.sqrt : ℤ) ≤ m ∧ m ≤ n.sqrt := \nbegin\n rw[int.abs_square',int.coe_nat_lt,nat.square_lt,int.abs_le'],\nend\n\nlemma A_spec (n : ℕ) : n ∈ A ↔ n ^ 2 < 9 := begin\n have sqrt_8 : 2 = nat.sqrt 8 := nat.eq_sqrt.mpr ⟨dec_trivial,dec_trivial⟩,\n exact calc\n  n ∈ A ↔ n ∈ finset.range 3 : by rw[(dec_trivial : A = finset.range 3)]\n  ... ↔ n < 3 : finset.mem_range\n  ... ↔ n ≤ 2 : by rw[nat.lt_succ_iff]\n  ... ↔ n ≤ nat.sqrt 8 : by rw[← sqrt_8]\n  ... ↔ n ^ 2 < 9 : by rw[nat.square_lt]\nend\n\nlemma B_spec (n : ℕ) : n ∈ B ↔ n ^ 2 ≤ 9 := begin\n have sqrt_9 : 3 = nat.sqrt 9 := nat.eq_sqrt.mpr ⟨dec_trivial,dec_trivial⟩,\n exact calc\n  n ∈ B ↔ n ∈ finset.range 4 : by rw[(dec_trivial : B = finset.range 4)]\n  ... ↔ n < 4 : finset.mem_range\n  ... ↔ n ≤ 3 : by rw[nat.lt_succ_iff]\n  ... ↔ n ≤ nat.sqrt 9 : by rw[← sqrt_9]\n  ... ↔ n ^ 2 ≤ 9 : by rw[nat.square_le]\nend\n\nlemma C_spec (n : ℤ) : n ∈ C ↔ n ^ 2 < 9 := begin\n have sqrt_8 : 2 = nat.sqrt 8 := nat.eq_sqrt.mpr ⟨dec_trivial,dec_trivial⟩,\n have e0 : (3 : ℤ) = ((2 : ℕ) : ℤ) + (1 : ℤ) := rfl,\n have e1 : (-2 : ℤ) = - ((2 : ℕ) : ℤ) := rfl, \n have e2 : ((nat.succ 8) : ℤ)  = 9 := rfl,\n let e3 := @int.square_lt 8 n,\n let J := finset.Ico (-2 : ℤ) (3 : ℤ),\n exact calc\n  n ∈ C ↔ n ∈ J :\n   by rw[(dec_trivial : C = J)]\n  ... ↔ -2 ≤ n ∧ n < 3 : finset.mem_Ico\n  ... ↔ - ((2 : ℕ) : ℤ) ≤ n ∧ n < (2 : ℕ) + 1 : by rw[e0,e1]\n  ... ↔ - ((2 : ℕ) : ℤ) ≤ n ∧ n ≤ (2 : ℕ) : by rw[int.lt_succ_iff]\n  ... ↔ - (nat.sqrt 8 : ℤ) ≤ n ∧ n ≤ nat.sqrt 8 : by rw[← sqrt_8]\n  ... ↔ n ^ 2 < nat.succ 8 : by rw[e3]\n  ... ↔ n ^ 2 < 9 : by rw[e2],\nend\n\nlemma D_spec (n : ℤ) : n ∈ D ↔ n ^ 2 ≤ 9 := begin\n have sqrt_9 : 3 = nat.sqrt 9 := nat.eq_sqrt.mpr ⟨dec_trivial,dec_trivial⟩,\n have e0 : (4 : ℤ) = ((3 : ℕ) : ℤ) + (1 : ℤ) := rfl,\n have e1 : (-3 : ℤ) = - ((3 : ℕ) : ℤ) := rfl, \n have e2 : ((9 : ℕ) : ℤ)  = 9 := rfl,\n let e3 := @int.square_le 9 n,\n let J := finset.Ico (-3 : ℤ) (4 : ℤ),\n exact calc\n  n ∈ D ↔ n ∈ J :\n   by rw[(dec_trivial : D = J)]\n  ... ↔ -3 ≤ n ∧ n < 4 : finset.mem_Ico\n  ... ↔ - ((3 : ℕ) : ℤ) ≤ n ∧ n < (3 : ℕ) + 1 : by rw[e0,e1]\n  ... ↔ - ((3 : ℕ) : ℤ) ≤ n ∧ n ≤ (3 : ℕ) : by rw[int.lt_succ_iff]\n  ... ↔ - (nat.sqrt 9 : ℤ) ≤ n ∧ n ≤ nat.sqrt 9 : by rw[← sqrt_9]\n  ... ↔ n ^ 2 ≤ (9 : ℕ) : by rw[e3]\n  ... ↔ n ^ 2 ≤ 9 : by rw[e2]\nend\n\nend Q5\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q6\n\ndef A : finset ℕ := [1,2,4].to_finset\ndef B : finset ℕ := [2,3,5].to_finset\ndef C : finset ℕ := [1,2,3,4,5].to_finset\ndef D : finset ℕ := [2].to_finset\ndef E : finset ℕ := [3,4].to_finset\n\nlemma L1 : A ∪ B = C := dec_trivial\nlemma L2 : A ∩ B = D := dec_trivial \nlemma L3 : D ∩ E = ∅ := dec_trivial \n\nend Q6\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q7\n\nlocal attribute [instance] classical.prop_decidable\n\nlemma L1 (U : Type) (A B : set U) : (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ :=\n by { simp }\n\nlemma L2 (U : Type) (A B : set U) : (A ∩ B)ᶜ = Aᶜ ∪ Bᶜ := \nbegin\n ext x,\n rw[set.mem_union,set.mem_compl_iff,set.mem_compl_iff,set.mem_compl_iff],\n by_cases hA : (x ∈ A); by_cases hB : (x ∈ B); simp[hA,hB], \nend\n\nend Q7\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q8\n\nend Q8\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q9\n\ndef even (n : ℤ) := ∃ k : ℤ, n = 2 * k\n\ndef odd (n : ℤ) := ∃ k : ℤ, n = 2 * k + 1\n\nlemma L1 (n : ℤ) : even n → even (n ^ 2) := \nbegin\n rintro ⟨k,e⟩,\n use n * k,\n rw[e,pow_two],ring,\nend\n\nlemma L2 (n m : ℤ) : even n → even m → even (n + m) := \nbegin\n rintros ⟨k,ek⟩ ⟨l,el⟩,\n use k + l,\n rw[ek,el],\n ring,\nend\n\nlemma L3 (n m : ℤ) : odd n → odd m → odd (n * m) := \nbegin\n rintros ⟨k,ek⟩ ⟨l,el⟩,\n use k + l + 2 * k * l,\n rw[ek,el],\n ring,\nend\n\n/- Do the converses -/\n\nend Q9\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q10 \n\ndef f : ℝ → ℝ := λ x, x ^ 2 - 7 * x + 10 \ndef f_alt : ℝ → ℝ := λ x, (x - 2) * (x - 5)\n\nlemma f_eq (x : ℝ) : f x = f_alt x := by {dsimp[f,f_alt],ring}\nlemma f_two  : f 2 = 0 := by {dsimp[f],ring}\nlemma f_five : f 5 = 0 := by {dsimp[f],ring}\nlemma two_ne_five : (2 : ℝ) ≠ (5 : ℝ) := \nbegin\n intro e,\n have h2 : (2 : ℝ) = ((2 : ℕ) : ℝ) := by {simp}, \n have h5 : (5 : ℝ) = ((5 : ℕ) : ℝ) := by {simp}, \n rw[h5,h2] at e,\n exact (dec_trivial : 2 ≠ 5) (nat.cast_inj.mp e),\nend\n\ndef P1 (x : ℝ) : Prop := f x = 0 → x = 2 ∧ x = 5\ndef P2 (x : ℝ) : Prop := f x = 0 → x = 2 ∨ x = 5\n\nlemma L1 : ¬ (∀ x : ℝ, P1 x) := \nbegin\n intro h_P1,\n exact two_ne_five (h_P1 2 f_two).right,\nend\n\nlemma L2 : ∀ x : ℝ, P2 x := \nbegin\n intros x fx,\n rw[f_eq x] at fx,\n dsimp[f_alt] at fx,\n rcases eq_zero_or_eq_zero_of_mul_eq_zero fx with x_eq_2 | x_eq_5,\n {exact or.inl (sub_eq_zero.mp x_eq_2)},\n {exact or.inr (sub_eq_zero.mp x_eq_5)}\nend\n\nend Q10 \n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q11\n\nend Q11\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q12\n\ndef f : ℚ → ℚ := λ x, x * (x + 1) * (2 * x + 1) / 6\n\nlemma f_step (x : ℚ) : f (x + 1) = (f x) + (x + 1) ^ 2 := \nbegin\n dsimp[f],\n apply sub_eq_zero.mp,\n rw[pow_two],\n ring,\nend\n\nlemma sum_of_squares : ∀ (n : ℕ), \n (((finset.range n.succ).sum (λ i, i ^ 2)) : ℚ) = f n\n| 0 := begin\n   rw[finset.sum_range_succ,finset.sum_range_zero,f],simp, \n  end\n| (n + 1) := begin\n  rw[finset.sum_range_succ,sum_of_squares n],\n  have : (((n + 1) : ℕ) : ℚ) = ((n + 1) : ℚ ) := by simp, \n  rw[this,f_step n],\n end\n\nend Q12\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q13\n\nend Q13\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q14\n\ndef f : ℚ → ℚ := λ x, (x + 1) / (2 * x)\n\nlemma f_step (x : ℚ) : x > 1 → (1 - 1 / (x ^ 2)) * f (x - 1) = f x := \nbegin\n intro x_big,\n let d := 2 * (x - 1) * (x ^ 2) ,\n let nz_2 : (2 : ℚ) ≠ 0 := by norm_num,\n /- Prove that all relevant denominators are nonzero -/\n let nz_x  : x ≠ 0     := (ne_of_lt (by linarith [x_big])).symm,\n let nz_2x : 2 * x ≠ 0 := mul_ne_zero nz_2 nz_x,\n let nz_x2 : x ^ 2 ≠ 0 := by {rw[pow_two], exact mul_ne_zero nz_x nz_x},\n let nz_y  : x - 1 ≠ 0 := (ne_of_lt (by linarith [x_big])).symm,\n let nz_2y : 2 * (x - 1) ≠ 0 := mul_ne_zero nz_2 nz_y,\n let nz_d : d ≠ 0 := mul_ne_zero nz_2y nz_x2,\n let e0 := calc\n  (x ^ 2) * (1 - 1 / (x ^ 2)) = (x ^ 2) * 1 - (x ^ 2) * (1 / (x ^ 2)) : \n   by rw[mul_sub] \n  ... = x ^ 2 - 1 : by rw[mul_one,mul_div_cancel' 1 nz_x2],\n let e1 := calc \n  d * (1 - 1 / (x ^ 2)) = (2 * (x - 1)) * ((x ^ 2) * (1 - 1 / (x ^ 2))) :\n   by rw[mul_assoc]\n  ... = (2 * (x - 1)) * (x ^ 2 - 1) : by rw[e0]\n  ... = (x ^ 2 - 1) * (2 * (x - 1)) : by rw[mul_comm],\n let e2 : (x - 1) + 1 = x := by ring,\n let e3 := calc \n  (2 * (x - 1)) * f (x - 1) = (2 * (x - 1)) * (((x - 1) + 1) / (2 * (x - 1))) : rfl\n  ... = (2 * (x - 1)) * (x / (2 * (x - 1))) : by rw[e2]\n  ... = x * (2 * (x - 1) / (2 * (x - 1))) : mul_div_left_comm (2 * (x - 1)) x (2 * (x - 1))\n  ... = x : by rw[div_self nz_2y,mul_one],\n let e4 := calc\n  d * ((1 - 1 / (x ^ 2)) * f (x - 1)) = (d * (1 - 1 / (x ^ 2))) * f (x - 1) :\n   by rw[← mul_assoc]\n  ... = (x ^ 2 - 1) * (2 * (x - 1)) * f (x - 1) : by rw[e1]\n  ... = (x ^ 2 - 1) * x : by rw[mul_assoc,e3]\n  ... = (x ^ 2) * x - 1 * x : by rw[sub_mul]\n  ... = x ^ 3 - x : by rw[← pow_succ',one_mul],\n let e5 : d = (x * x - x) * (2 * x) := by {dsimp[d],ring},\n let e6 := calc \n  d * f x = d * ((x + 1) / (2 * x)) : rfl \n  ... = ((x * x - x) * (2 * x)) * ((x + 1) / (2 * x)) : by rw[e5]\n  ... = (x * x - x) * ((2 * x) * ((x + 1) / (2 * x))) : by rw[mul_assoc]\n  ... = (x * x - x) * (x + 1) : by rw[mul_div_left_comm,div_self nz_2x,mul_one]\n  ... = x ^ 3 - x : by ring,\n  exact (mul_right_inj' nz_d).mp (e4.trans e6.symm)\nend\n\nlemma product_formula : ∀ (n : ℕ), \n (finset.range n).prod (λ k, ((1 - 1 / ((k + 2) ^ 2)) : ℚ)) = f (n + 1)\n| 0 := by { rw[finset.prod_range_zero,f], norm_num }\n| (n + 1) := begin\n have e0 : 1 < n + 2 := by linarith,\n have e1 : (1 : ℚ) < ((n + 2) : ℕ) := by {\n  have : (1 : ℚ) = (1 : ℕ) := by norm_num, rw[this],\n  exact nat.cast_lt.mpr e0,\n }, \n rw[nat.cast_add,nat.cast_bit0,nat.cast_one] at e1,\n rw[finset.prod_range_succ,product_formula n],\n let e2 := f_step (n + 2) e1,\n have e3 : (n : ℚ) + 2 - 1 = n + 1 := by ring,\n have e4 : (((n + 1) : ℕ) : ℚ) + 1 = (n : ℚ) + 2 :=\n  by { rw[nat.cast_add,nat.cast_one],ring},\n rw[e3] at e2,\n rw[mul_comm,e2,e4],\nend\n\nend Q14\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q15\n\nend Q15 \n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q16\n\nlemma nat.bodd_even (n : ℕ) : (2 * n).bodd = ff := \n by {rw[nat.bodd_mul,nat.bodd_two,band],} \n\nlemma nat.bodd_odd (n : ℕ) : (2 * n + 1).bodd = tt := \n by {rw[nat.bodd_add,nat.bodd_even],refl} \n\nlemma nat.div2_even : ∀ (n : ℕ), (2 * n).div2 = n \n| 0 := rfl\n| (n + 1) := begin \n have : 2 * (n + 1) = (2 * n + 1).succ := by ring_nf,\n rw[this,nat.div2_succ,nat.bodd_odd,bool.cond_tt],\n rw[nat.div2_succ,nat.bodd_even,bool.cond_ff],\n rw[nat.div2_even n],\nend\n\nlemma nat.div2_odd (n : ℕ) : (2 * n + 1).div2 = n := \nby {rw[nat.div2_succ,nat.bodd_even,bool.cond_ff,nat.div2_even]}\n\nlemma wf_lemma : ∀ (m : ℕ), m.succ.div2 < m.succ \n| 0 := dec_trivial\n| (nat.succ m) := begin\n rw[nat.div2_succ],\n cases m.succ.bodd; simp only[bool.cond_tt,bool.cond_ff],\n exact lt_trans (wf_lemma m) m.succ.lt_succ_self,\n exact nat.succ_lt_succ (wf_lemma m)\nend\n\nlemma wf_lemma' (m : ℕ) :\n cond (nat.bodd m) (nat.succ (nat.div2 m)) (nat.div2 m) < nat.succ m :=\nbegin\n cases m,\n {exact dec_trivial,},\n let u := wf_lemma m,\n cases m.succ.bodd; simp only[bool.cond_tt,bool.cond_ff],\n exact lt_trans u m.succ.lt_succ_self,\n exact nat.succ_lt_succ u,\nend\n\ndef f : bool → ℕ → ℕ \n| ff u := 4 * u + 1\n| tt u := 9 * u + 2\n\ndef a : ℕ → ℕ \n| 0 := 0 \n| (nat.succ m) := \n   have cond (nat.bodd m) (nat.succ (nat.div2 m)) (nat.div2 m) < nat.succ m := wf_lemma' m,\n   f m.succ.bodd (a m.succ.div2)\n\nlemma a_even (n : ℕ) : n > 0 → a (2 * n) = 4 * (a n) + 1 := \nbegin\n intro n_pos,\n let k := n.pred,\n have e0 : n = k + 1 := (nat.succ_pred_eq_of_pos n_pos).symm,\n let m := 2 * k + 1,\n have e1 : 2 * n = m.succ := calc\n  2 * n = 2 * (k + 1) : by rw[e0]\n  ... = 2 * k + 2 : by rw[mul_add,mul_one]\n  ... = m.succ : rfl,\n rw[e1,a,← e1,nat.bodd_even,nat.div2_even,f],\nend\n\nlemma a_odd (n : ℕ) : a (2 * n + 1) = 9 * (a n) + 2 := \nbegin\n change a (2 * n).succ = 9 * (a n) + 2,\n rw[a,nat.bodd_odd,nat.div2_odd,f],\nend\n\nlemma a_even_step (n : ℕ) : n > 0 → n ^ 2 ≤ a n → (2 * n) ^ 2 ≤ a (2 * n) := \nbegin\n intros n_pos ih,\n rw[a_even n n_pos],\n exact calc\n  (2 * n) ^ 2 = 4 * n ^ 2 : by ring\n  ... ≤ 4 * a n : nat.mul_le_mul_left 4 ih\n  ... ≤ 4 * a n + 1 : nat.le_succ _ \nend\n\nlemma a_odd_step (n : ℕ) : n ^ 2 ≤ a n → (2 * n + 1) ^ 2 ≤ a (2 * n + 1) := \nbegin\n intro ih,\n rw[a_odd n],\n exact calc\n  (2 * n + 1) ^ 2 = 4 * n + (4 * n ^ 2 + 1) : by ring\n   ... ≤ 4 * n ^ 2 + (4 * n ^ 2 + 1) : \n      by {apply (nat.add_le_add_iff_le_right _ _ _).mpr,\n          rw[pow_two],\n          exact nat.mul_le_mul_left 4 (nat.le_mul_self n),} \n   ... = 8 * n ^ 2 + 1 : by ring\n   ... ≤ (8 * n ^ 2 + 1) + (n ^ 2 + 1) : le_self_add \n   ... = 9 * n ^ 2 + 2 : by ring\n   ... ≤ 9 * a n + 2 : \n      by {apply (nat.add_le_add_iff_le_right _ _ _).mpr,\n          exact nat.mul_le_mul_left 9 ih,}  \nend\n\nlemma square_le : ∀ n, n ^ 2 ≤ a n \n| 0 := by { norm_num }\n| (nat.succ m) := \n   have cond (nat.bodd m) (nat.succ (nat.div2 m)) (nat.div2 m) < nat.succ m := wf_lemma' m,\n   begin\n    let e := nat.bodd_add_div2 m.succ,\n    rw[nat.bodd_succ] at e,\n    rw[← e],\n    rcases m.bodd;\n    simp only[bnot,bool.cond_ff,bool.cond_tt,zero_add],\n    {intros u0 u1,\n     rw[nat.add_comm 1],\n     exact a_odd_step m.succ.div2 (square_le m.succ.div2),\n    },{\n     intros u0 u1,\n     by_cases h : m.succ.div2 = 0,\n     {exfalso,rw[h,mul_zero] at u0,exact nat.succ_ne_zero m u0.symm},\n     exact a_even_step m.succ.div2 (nat.pos_of_ne_zero h) (square_le m.succ.div2),\n    }\n   end\n\nend Q16\n\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n/- --------------------------------------------------------- -/\n\nnamespace Q17\n\n/- This is the basic definition of fibonacci numbers.  It \n   is not good for efficient evaluation.\n-/\n\ndef fibonacci : ℕ → ℕ \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 : ℕ × ℕ → ℕ × ℕ := \n λ ⟨a,b⟩, ⟨b, a + b⟩\n\ndef fibonacci_pair : ℕ → ℕ × ℕ \n| 0 := ⟨0,1⟩ \n| (n + 1) := fibonacci_step (fibonacci_pair n)\n\nlemma fibonacci_pair_spec : ∀ n , \n fibonacci_pair n = ⟨fibonacci n,fibonacci n.succ⟩ \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 : ℕ) : \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 : ℕ) : \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 : ∀ 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\nlemma F2013_even : (fibonacci 2013).bodd = ff := calc\n (fibonacci 2013).bodd = bnot (2013 % 3 = 0) : fibonacci_bodd _\n  ... = ff : by norm_num\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 : ℕ) : ℕ × ℕ → ℕ × ℕ := \n λ ⟨a,b⟩, ⟨a % p,b % p⟩ \n\nlemma pair_mod_mod (p : ℕ) : ∀ (c : ℕ × ℕ), \n pair_mod p (pair_mod p c) = pair_mod p c := \nλ ⟨a,b⟩, by {simp[pair_mod,nat.mod_mod],}\n\ndef fibonacci_pair_mod (p : ℕ) : ℕ → ℕ × ℕ \n| 0 := pair_mod p ⟨0,1⟩ \n| (n + 1) := pair_mod p (fibonacci_step (fibonacci_pair_mod n))\n\nlemma fibonacci_pair_mod_mod (p : ℕ) : ∀ 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 : ℕ) : ∀ (c : ℕ × ℕ), \n pair_mod p (fibonacci_step c) = \n  pair_mod p (fibonacci_step (pair_mod p c)) :=\nλ ⟨a,b⟩, begin\n change (⟨b % p,(a + b) % p⟩ : ℕ × ℕ) = \n  ⟨b % p % p,(a % p + b % p) % p⟩,\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 : ℕ) : ∀ 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[← mod_step_mod],\nend\n\nlemma fibonacci_mod_spec (p : ℕ) (n : ℕ) :\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₀ {p : ℕ} {d : ℕ} \n (h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) :\n  ∀ 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,← add_assoc],\n  rw[fibonacci_pair_mod,fibonacci_pair_mod],\n  rw[fibonacci_pair_period₀ n],\n}\n\nlemma fibonacci_pair_period₁ {p : ℕ} {d : ℕ} \n (h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) (m : ℕ) :\n  ∀ 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₀ h,fibonacci_pair_period₁],\n}\n\nlemma fibonacci_pair_period {p : ℕ} {d : ℕ} \n (h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) (n : ℕ) : \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₁ h (n % d) (n / d)\n\nlemma fibonacci_period  {p : ℕ} {d : ℕ} \n (h : fibonacci_pair_mod p d = pair_mod p ⟨0,1⟩) (n : ℕ) : \n  (fibonacci n) ≡ (fibonacci (n % d)) [MOD p] := \nbegin\n rw[nat.modeq,← fibonacci_mod_spec,← fibonacci_mod_spec],\n rw[fibonacci_pair_period],\n exact h,\nend\n\nlemma prime_89 : nat.prime 89 := by { norm_num, }\n\nlemma L89_dvd_F2013 : 89 ∣ (fibonacci 2013) := \nbegin\n apply (nat.dvd_iff_mod_eq_zero _ _).mpr,\n have h0 : fibonacci_pair_mod 89 44 = ⟨0,1⟩ :=\n  by {unfold fibonacci_pair_mod fibonacci_step pair_mod; norm_num},\n have h1 : fibonacci_pair_mod 89 33 = ⟨0,34⟩ :=\n  by {unfold fibonacci_pair_mod fibonacci_step pair_mod; norm_num},\n have h2 : 2013 % 44 = 33 := by {norm_num},\n let h3 := (fibonacci_mod_spec 89 2013).symm,\n let h4 := congr_arg prod.fst (fibonacci_pair_period h0 2013),\n let h5 := congr_arg prod.fst (congr_arg (fibonacci_pair_mod 89) h2),\n let h6 := congr_arg prod.fst h1,\n exact ((h3.trans h4).trans h5).trans h6,\nend\n\n\nend Q17\n\nnamespace Q18\n\nvariables (a b c d : ℤ)\n\nlemma L_i : a ∣ b → b ∣ c → a ∣ c := \nby { rintros ⟨uab,hab⟩ ⟨ubc,hbc⟩, use uab * ubc, rw[← mul_assoc,← hab,← hbc] }\n\nlemma L_ii : a ∣ b → a ∣ c → a ∣ (b + c) := \nby { rintros ⟨uab,hab⟩ ⟨uac,hac⟩, use uab + uac, rw[mul_add,hab,hac] }\n\nlemma L_iii_false : ¬ (∀ a b c : ℤ, (a ∣ (b + c)) → (a ∣ b) ∧ (a ∣ c)) := \nbegin\n intro h₀,\n have h₁ :    (2 : ℤ) ∣ 1  := (h₀ 2 1 1 dec_trivial).left,\n have h₂ : ¬ ((2 : ℤ) ∣ 1) := dec_trivial,\n exact h₂ h₁\nend\n\nlemma L_iv : a ∣ b → a ∣ c → a ∣ (b * c) := \nby { rintros ⟨uab,hab⟩ ⟨uac,hac⟩, use uab * c, rw[← mul_assoc,hab] }\n\nlemma L_v_false : ¬ (∀ a b c : ℤ, (a ∣ (b * c)) → (a ∣ b) ∧ (a ∣ c)) := \nbegin\n intro h₀,\n have h₁ :    (4 : ℤ) ∣ 2  := (h₀ 4 2 2 dec_trivial).left,\n have h₂ : ¬ ((4 : ℤ) ∣ 2) := dec_trivial,\n exact h₂ h₁\nend\n\nlemma L_vi : a ∣ b → c ∣ d → (a * c) ∣ (b * d) := \nby { rintros ⟨uab,hab⟩ ⟨ucd,hcd⟩, use uab * ucd, rw[hab,hcd], ring }\n\nend Q18\n\nnamespace Q19\ndef f (n : ℤ) : ℤ := n * (n + 1) * (n + 2) * (n + 3)\n\nlemma f_mod (p n₀ n₁ : ℤ) (h0 : n₀ ≡ n₁ [ZMOD p]) : f n₀ ≡ f n₁ [ZMOD p] := \nbegin\n have h1 : n₀ + 1 ≡ n₁ + 1 [ZMOD p] := int.modeq.add h0 rfl,\n have h2 : n₀ + 2 ≡ n₁ + 2 [ZMOD p] := int.modeq.add h0 rfl,\n have h3 : n₀ + 3 ≡ n₁ + 3 [ZMOD p] := int.modeq.add h0 rfl,\n have h01 : n₀ * (n₀ + 1) ≡ n₁ * (n₁ + 1) [ZMOD p] := \n  int.modeq.mul h0 h1,\n have h02 : n₀ * (n₀ + 1) * (n₀ + 2) ≡ n₁ * (n₁ + 1) * (n₁ + 2) [ZMOD p] := \n  int.modeq.mul h01 h2,\n exact int.modeq.mul h02 h3,\nend\n\nlemma f_mod_3 (n : ℕ) : f n ≡ 0 [ZMOD 3] := \nbegin\n have three_pos : (3 : ℤ) > 0 := dec_trivial,\n rcases int.exists_unique_equiv_nat n three_pos with ⟨r,⟨r_is_lt,r_equiv⟩⟩,\n let e := (f_mod 3 r n r_equiv).symm,\n suffices : f r ≡ 0 [ZMOD 3],\n {exact e.trans this,},\n rcases r with _ | _ | _ | r0; rw[f]; try {refl},\n {exfalso,\n  have : (3 : ℤ) = ((3 : ℕ) : ℤ) := rfl,\n  rw[this] at r_is_lt,\n  let h0 := int.coe_nat_lt.mp r_is_lt,\n  replace h0 := nat.lt_of_succ_lt_succ h0,\n  replace h0 := nat.lt_of_succ_lt_succ h0,\n  replace h0 := nat.lt_of_succ_lt_succ h0,\n  exact nat.not_lt_zero r0 h0,\n }\nend\n\nlemma f_mod_8 (n : ℕ) : f n ≡ 0 [ZMOD 8] := \nbegin\n have eight_pos : (8 : ℤ) > 0 := dec_trivial,\n rcases int.exists_unique_equiv_nat n eight_pos with ⟨r,⟨r_is_lt,r_equiv⟩⟩,\n let e := (f_mod 8 r n r_equiv).symm,\n suffices : f r ≡ 0 [ZMOD 8],\n {exact e.trans this,},\n rcases r with _ | _ | _ | _ | _ | _ | _ | _ | r0;\n  rw[int.modeq,f]; try {norm_num},\n {exfalso,\n  have : (8 : ℤ) = ((8 : ℕ) : ℤ) := rfl,\n  rw[this] at r_is_lt,\n  let h0 := int.coe_nat_lt.mp r_is_lt,\n  repeat { replace h0 := nat.lt_of_succ_lt_succ h0 },\n  exact nat.not_lt_zero r0 h0,\n }\nend\n\nlemma f_mod_24 (n : ℕ) : f n ≡ 0 [ZMOD 24] := \nbegin\n let i3 : ℤ := 3,\n let i8 : ℤ := 8,\n have : (24 : ℤ) = i3 * i8 := rfl,\n rw[this],\n have cp : nat.coprime i3.nat_abs i8.nat_abs := by {dsimp[i3,i8], norm_num},\n exact (int.modeq_and_modeq_iff_modeq_mul cp).mp ⟨f_mod_3 n,f_mod_8 n⟩,\nend\n\n/- ----------- Part (ii) ------------- -/\n\ndef h {R : Type} [comm_ring R] (a b c d : R) : R := \n (a - b) * (a - c) * (a - d) * (b - c) * (b - d) * (c - d) \n\nlemma h_shift {R : Type} [comm_ring R] (a b c d : R) : \n h a b c d = h (a - d) (b - d) (c - d) 0 := \nbegin\n have e : ∀ x y z : R, (x - z) - (y - z) = x - y := \n  by {intros, ring},\n dsimp[h],\n rw[sub_zero,sub_zero,sub_zero,e,e,e]\nend\n\nlemma h_zero_shift {R : Type} [comm_ring R] : \n (∀ a b c : R, h a b c 0 = 0) → (∀ a b c d : R, h a b c d = 0) := \n  λ p a b c d, (h_shift a b c d).trans (p (a - d) (b - d) (c - d))\n\nlemma h_zero_3 : ∀ a b c d : zmod 3, h a b c d = 0 := \n h_zero_shift dec_trivial\n\nlemma h_zero_4 : ∀ a b c d : zmod 4, h a b c d = 0 :=\n h_zero_shift dec_trivial\n\nlemma h_map {R S : Type} [comm_ring R] [comm_ring S] \n (φ : R →+* S) (a b c d : R) :\n  φ (h a b c d) = h (φ a) (φ b) (φ c) (φ d) := \nbegin\n dsimp[h],\n let em := φ.map_mul,\n let es := φ.map_sub,\n rw[em,em,em,em,em,es,es,es,es,es,es]\nend\n\nlemma h_zero_mod (p : ℕ+) :\n (∀ a b c d : zmod p, h a b c d = 0) → \n  (∀ a b c d : ℤ, h a b c d ≡ 0 [ZMOD p]) := \nbegin\n intros e a b c d,\n have h₀ := eq_iff_modeq_int (zmod p) (p : ℕ),\n have : (p : ℤ) = ((p : ℕ) : ℤ) := by norm_cast,\n rw [← this] at h₀, rw[← h₀],\n let π : ℤ →+* (zmod p) := int.cast_ring_hom _,\n exact calc \n  π (h a b c d) = h (π a) (π b) (π c) (π d) : by rw[h_map π]\n  ... = 0 : e (π a) (π b) (π c) (π d),\nend\n\nlemma h_zero_12 : ∀ (a b c d : ℤ), h a b c d ≡ 0 [ZMOD 12] := \nbegin\n intros,\n let i3 : ℤ := 3,\n let i4 : ℤ := 4,\n let h3 := h_zero_mod 3 h_zero_3 a b c d,\n let h4 := h_zero_mod 4 h_zero_4 a b c d,\n have : (12 : ℤ) = i3 * i4 := rfl,\n rw[this],\n have cp : nat.coprime i3.nat_abs i4.nat_abs := by {dsimp[i3,i4], norm_num},\n exact (int.modeq_and_modeq_iff_modeq_mul cp).mp ⟨h3,h4⟩\nend\n\n/-\n Here are partial results for a more general case\n-/\n\ndef π (m : ℕ+) : ℤ →+* (zmod m) := int.cast_ring_hom _\n\ndef F (n : ℕ) := { ij : (fin n) × (fin n) // ij.1.val < ij.2.val }\n\ninstance (n : ℕ) : fintype (F n) := by { dsimp[F], apply_instance,}\n\ndef g (n : ℕ) (u : (fin n) → ℤ) : ℤ := \n (@finset.univ (F n) _).prod (λ ij, (u ij.val.2) - (u ij.val.1))\n\ndef g_mod (n : ℕ) (m : ℕ+) (u : (fin n) → ℤ) : zmod m := \n (@finset.univ (F n) _).prod (λ ij, (π m (u ij.val.2)) - (π m (u ij.val.1)))\n\nlemma g_mod_spec (n : ℕ) (m : ℕ+) (u : (fin n) → ℤ) : \n π m (g n u) = g_mod n m u := \nbegin\n dsimp[g,g_mod],\n let ms := (π m).map_sub,\n let ma := (π m).map_add,\n conv\n begin\n  to_rhs, congr, skip, funext, rw[← ms],\n end,\n rw[ ← (π m).map_prod ],\nend\n\nlemma must_repeat (n : ℕ) (m : ℕ+) (m_lt_n : m.val < n)\n (u : fin n → ℤ) : ∃ i j : fin n, (i.val < j.val ∧ (π m (u i)) = (π m (u j))) := \nbegin\n let P := { ij : (fin n) × (fin n) // ij.1 ≠ ij.2 },\n let p : P → Prop := λ ij, π m (u ij.val.1) = π m (u ij.val.2),\n let q := exists ij, p ij,\n by_cases h : q,\n { rcases h with ⟨⟨⟨i,j⟩,i_ne_j⟩,eq_mod⟩,\n   change i ≠ j at i_ne_j,\n   let i_ne_j_val : i.val ≠ j.val := λ e,i_ne_j (fin.eq_of_veq e),\n   change (π m (u i)) = (π m (u j)) at eq_mod,\n   by_cases hij : i.val < j.val,\n   {use i,use j,exact ⟨hij,eq_mod⟩},\n   { let hij' := lt_of_le_of_ne (le_of_not_gt hij) i_ne_j_val.symm,\n    use j,use i,exact ⟨hij',eq_mod.symm⟩ } },\n { exfalso,\n   let v : fin n → zmod m := λ i, π m (u i),\n   have v_inj : function.injective v := \n   begin \n     intros i j ev,\n     by_cases hij : i = j,\n     { exact hij },\n     { exfalso, exact h ⟨⟨⟨i,j⟩,hij⟩,ev⟩ }\n   end,  \n   haveI : fact (0 < (m : ℕ)) := ⟨m.property⟩,\n   let e := calc\n     n = fintype.card (fin n) : (fintype.card_fin n).symm\n     ... ≤ fintype.card (zmod m) : fintype.card_le_of_injective v v_inj\n     ... = m : zmod.card m\n     ... < n : m_lt_n,\n   exact lt_irrefl _ e }\nend\n\nlemma g_mod_zero (n : ℕ) (m : ℕ+) (m_lt_n : m.val < n)\n (u : fin n → ℤ) : g_mod n m u = 0 := \nbegin\n  rcases must_repeat n m m_lt_n u with ⟨i,j,i_lt_j,e⟩,\n  dsimp[π] at e,\n  let ij : F n := ⟨⟨i,j⟩,i_lt_j⟩,\n  dsimp[g_mod],\n  apply finset.prod_eq_zero (finset.mem_univ ij),\n  dsimp[ij],\n  change π m (u i) = π m (u j) at e,\n  rw[e,sub_self],\nend\n\nend Q19\n\nnamespace Q20\nlemma L1 : nat.gcd 896 1200 = 16 := \nbegin\n have e0 : 1200 % 896 = 304 := by norm_num,\n have e1 :  896 % 304 = 288 := by norm_num,\n have e2 :  304 % 288 =  16 := by norm_num,\n have e3 :  288 %  16 =   0 := by norm_num,\n exact calc\n  nat.gcd 896 1200 = nat.gcd 304 896 : by rw[nat.gcd_rec,e0]\n               ... = nat.gcd 288 304 : by rw[nat.gcd_rec,e1] \n               ... = nat.gcd  16 288 : by rw[nat.gcd_rec,e2] \n               ... = nat.gcd   0  16 : by rw[nat.gcd_rec,e3] \n               ... = 16 : nat.gcd_zero_left 16\nend\n\nlemma L2 : nat.gcd 123456789 987654321 = 9 := \nbegin\n have e0 : 987654321 % 123456789 = 9 := by norm_num,\n have e1 : 123456789 % 9 = 0 := by norm_num,\n exact calc\n  nat.gcd 123456789 987654321 \n       = nat.gcd 9 123456789  : by rw[nat.gcd_rec,e0]\n   ... = nat.gcd 0 9          : by rw[nat.gcd_rec,e1]\n   ... = 9 : nat.gcd_zero_left 9\nend\n\nend Q20\n\nnamespace Q21\n\ndef u (n : ℕ) : ℕ := 2 ^ n\ndef a (n : ℕ) : ℕ := 2 ^ (u n) + 1\n\nlemma u_ge_1 (n : ℕ) : u n ≥ 1 := \n by {\n  let e := @nat.pow_le_pow_of_le_right 2 dec_trivial 0 n (nat.zero_le n),\n  rw[pow_zero] at e,\n  exact e,\n }\n\nlemma u_step (n : ℕ) : u (n + 1) = 2 * (u n) := \n by {dsimp[u],rw[pow_succ],}\n\ndef a_pos (n : ℕ) : ℕ+ := ⟨a n,nat.zero_lt_succ _⟩\n\nlemma a_step (n : ℕ) : a (n + 1) + 2 * (a n) = 2 + (a n) * (a n) := \nbegin\n have h : ∀ (x : ℕ), x ^ 2 + 1 + 2 * (x + 1) \n   = 2 + (x + 1) * (x + 1) := by {intro, ring,},\n rw[a,a,u_step,mul_comm 2 (u n),pow_mul,h (2 ^ (u n))]\nend\n\nlemma a_ge_3 (n : ℕ) : a n ≥ 3 := \nbegin\n let e := @nat.pow_le_pow_of_le_right 2 dec_trivial _ _ (u_ge_1 n),\n rw[pow_one] at e,\n exact nat.succ_le_succ e,\nend\n\nlemma a_ne_1 (n : ℕ) : a n ≠ 1 := ne_of_gt (lt_trans dec_trivial (a_ge_3 n))\n\nlemma a_odd (n : ℕ) : (a n) % 2 = 1 := \nbegin\n dsimp[a],\n rw[← nat.add_sub_of_le (u_ge_1 n),pow_add,pow_one],\n rw[add_comm _ 1,nat.add_mul_mod_self_left],\n refl,\nend\n\nlemma a_mod_a : ∀ (n m : ℕ), a (n + m + 1) ≡ 2 [MOD (a n)] \n| n 0 := begin \n   rw[add_zero n],\n   let e : (a (n + 1) + 2 * (a n)) % (a n) = \n           (2 + (a n) * (a n)) % (a n) :=\n            congr_arg (λ i, i % (a n)) (a_step n),\n   rw[nat.add_mul_mod_self_right] at e,\n   rw[nat.add_mul_mod_self_right] at e,\n   exact e,\n  end\n| n (m + 1) := begin\n   rw[← (add_assoc n m 1)],\n   let e := a_step (n + m + 1),\n   replace e : (a (n + m + 1 + 1) + 2 * a (n + m + 1)) % (a n) = \n             (2 + a (n + m + 1) * a (n + m + 1)) % (a n) := by {rw[e]},\n   let ih := a_mod_a n m,\n   let ih1 : 2 * a (n + m + 1) ≡ 4 [MOD (a n)] := \n    nat.modeq.mul rfl ih,\n   let ih2 : a (n + m + 1) * a (n + m + 1) ≡ 4 [MOD (a n)] := \n    nat.modeq.mul ih ih,\n   let ih3 : a (n + m + 1 + 1) + 2 * a (n + m + 1) ≡\n             a (n + m + 1 + 1) + 4 [MOD (a n)] := nat.modeq.add rfl ih1, \n   let ih4 : 2 + a (n + m + 1) * a (n + m + 1) ≡ 2 + 4 [MOD (a n)] := \n    nat.modeq.add rfl ih2,\n   let e1 := (ih3.symm.trans e).trans ih4,\n   exact nat.modeq.add_right_cancel rfl e1,\n  end\n\nlemma a_coprime_aux (n m : ℕ) : nat.coprime (a n) (a (n + m + 1)) := \nbegin\n let u := a n,\n let v := a (n + m + 1),\n change (nat.gcd u v) = 1,\n let q := v / u,\n let r := v % u,\n have e0 : r + u * q = v := nat.mod_add_div (a (n + m + 1)) (a n),\n have e1 : r = 2 % (a n) := a_mod_a n m,\n have e2 : 2 % (a n) = 2 := @nat.mod_eq_of_lt 2 (a n) (a_ge_3 n),\n rw[e2] at e1,\n have e3 : nat.gcd u v = nat.gcd r u := nat.gcd_rec u v,\n rw[e1] at e3,\n have e4 : nat.gcd 2 u = nat.gcd (u % 2) 2 := nat.gcd_rec 2 u,\n have e5 : u % 2 = 1 := a_odd n,\n have e6 : nat.gcd 1 2 = 1 := by norm_num,\n rw[e5,e6] at e4,\n rw[e4] at e3,\n exact e3,\nend\n\nlemma a_coprime {n m : ℕ} : n ≠ m → nat.coprime (a n) (a m) := \nbegin\n cases (lt_or_ge n m) with h h,\n {let k := m - n.succ,\n  have e0 : (n + 1) + k = m := add_tsub_cancel_of_le h,\n  have : (n + 1) + k = n + k + 1 := by ring,\n  rw[this] at e0,\n  rw[← e0],\n  intro,\n  exact a_coprime_aux n k,  \n },{\n  intro h0,   \n  let h1 := lt_of_le_of_ne h h0.symm,\n  let k := n - m.succ,\n  have e0 : (m + 1) + k = n := nat.add_sub_of_le h1,\n  have : (m + 1) + k = m + k + 1 := by ring,\n  rw[this] at e0,\n  rw[← e0],\n  exact (a_coprime_aux m k).symm,  \n }\nend\n\ndef b (n : ℕ) : ℕ := nat.min_fac (a n)\n\ndef b_prime (n : ℕ) : nat.prime (b n) := nat.min_fac_prime (a_ne_1 n)\n\nlemma b_inj : function.injective b := begin\n intros i j e0,\n by_cases e1 : i = j,\n {assumption},\n {exfalso,\n  have e2 : nat.gcd (a i) (a j) = 1 := a_coprime e1,\n  have e3 : (b i) ∣ (a i) := nat.min_fac_dvd (a i),\n  have e4 : (b j) ∣ (a j) := nat.min_fac_dvd (a j),\n  rw[← e0] at e4,\n  let e5 := nat.dvd_gcd e3 e4,\n  rw[e2] at e5,\n  exact nat.prime.not_dvd_one (b_prime i) e5\n }\nend\n\nend Q21\n\nend exercises_1\nend MAS114", "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/undergraduate/MAS114/Semester 1/exercises_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742805, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7643846918573423}}
{"text": "/- Yair Gueta : 208624908 : t1\nExercises\n1. Define the function Do_Twice, as described in Section 2.4.\n2. Define the functions curry and uncurry, as described in Section 2.4.\n3. Above, we used the example vec α n for vectors of elements of type α\n   of length n. Declare a constant vec_add that could represent a \n   function that adds two vectors of natural numbers of the same length,\n   and a constant vec_reverse that can represent a function that \n   reverses its argument. Use implicit arguments for parameters that \n   can be inferred. Declare some variables and check some expressions \n   involving the constants that you have declared.\n4. Similarly, declare a constant matrix so that matrix α m n could\n   represent the type of m by n matrices. Declare some constants to \n   represent functions on this type, such as matrix addition and \n   multiplication, and (using vec) multiplication of a matrix by a \n   vector. Once again, declare some variables and check some \n   expressions involving the constants that you have declared.-/\n\ndef double : ℕ → ℕ := λ x, x + x\ndef square : ℕ → ℕ := λ x, x * x\ndef do_twice : (ℕ → ℕ) → ℕ → ℕ := λ f x, f (f x)\n\n\n-- chapter 2 ex 1: \ndef Do_twice : ((ℕ → ℕ) → (ℕ → ℕ)) → (ℕ → ℕ) → (ℕ → ℕ) := λ F f, F (F f)\n#check Do_twice\n#check Do_twice do_twice\n#check Do_twice do_twice double\n#eval Do_twice do_twice double 2\n\n\n-- chapter 2 ex 2:\ndef curry (α β γ : Type*) (f : α × β → γ) : α → β → γ := λ a : α, (λ b : β, f (a,b))\ndef uncurry (α β γ : Type*) (f : α → β → γ) : α × β → γ := λ cr : α × β, f cr.1 cr.2\n\nconstants f g : ℕ → ℕ → ℕ \nconstants f' g' : ℕ × ℕ → ℕ \n#check uncurry ℕ ℕ ℕ f\n#check uncurry ℕ ℕ ℕ g\n#check curry ℕ ℕ ℕ f'\n#check curry ℕ ℕ ℕ g'\n\ndef sum1 (a b : ℕ ) : ℕ := a+b\ndef sum2 (t : ℕ×ℕ ) : ℕ := t.1+t.2\n\n#check sum1\n#check uncurry ℕ ℕ ℕ sum1\n#eval sum1 3 7\n#eval uncurry ℕ ℕ ℕ sum1 (3,7) \n\n#check sum2\n#check curry ℕ ℕ ℕ sum2\n#eval sum2 (3,7)\n#eval curry ℕ ℕ ℕ sum2 3 7 \n\n\n-- chapter 2 ex 3:\nuniverse u\nconstant vec : Type u → ℕ → Type u\n\nnamespace vec\n  constant empty : Π α : Type u, vec α 0\n  constant cons :\n    Π (α : Type u) (n : ℕ), α → vec α n → vec α (n + 1)\n  constant append :\n    Π (α : Type u) (n m : ℕ),  vec α m → vec α n → vec α (n + m)\n  constant vec_add        : Π {α : Type} {n : ℕ} (v1 v2 : vec α n), vec α n\n  constant vec_reverse    : Π {α : Type} {n : ℕ} (v : vec α n), vec α n\n  \nend vec\n\n\n\nconstants v1 v2 : vec ℕ 5\nconstants v3 v4 : vec ℕ 7\n#check vec.vec_add\n#check vec.vec_add v1\n#check vec.vec_add v1 v2\n-- #check vec.vec_add v1 v3 \n-- #check vec.vec_add v4 v2\n#check vec.vec_add v3 v4\n\n#check vec.vec_reverse v1\n#check vec.vec_reverse v3\n-- #check vec.vec_reverse v1 v2\n-- #check vec.vec_reverse v1 v3\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/t1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7643846841029683}}
{"text": "import data.real.basic\n\nopen_locale classical\n\n/-\nTheoretical negations.\n\nThis file is for people interested in logic who want to fully understand\nnegations.\n\nHere we don't use `contrapose` or `push_neg`. The goal is to prove lemmas\nthat are used by those tactics. Of course we can use\n`exfalso`, `by_contradiction` and `by_cases`.\n\nIf this doesn't sound like fun then skip ahead to the next file.\n-/\n\nsection negation_prop\n\nvariables P Q : Prop\n\n-- 0055\nexample : (P → Q) ↔ (¬ Q → ¬ P) :=\nbegin\n  split,\n  intros a b,\n  by_contradiction H,\n  apply b,\n  apply a,\n  exact H,\n  intros a b,\n  by_contradiction H,\n  apply a,\n  exact H,\n  exact b,\nend\n\n-- 0056\nlemma non_imp (P Q : Prop) : ¬ (P → Q) ↔ P ∧ ¬ Q :=\nbegin\n  split,\n  intro h,\n  by_contradiction H,\n  apply h,\n  intro p,\n  by_contradiction HH,\n  apply H,\n  exact ⟨p, HH⟩,\n  intros h a,\n  apply h.right,\n  apply a,\n  exact h.left,\nend\n\n-- In the next one, let's use the axiom\n-- propext {P Q : Prop} : (P ↔ Q) → P = Q\n\n-- 0057\nexample (P : Prop) : ¬ P ↔ P = false :=\nbegin\n  split,\n  intro h,\n  apply propext,\n  split,\n  apply h,\n  intro f,\n  exfalso,\n  apply f,\n  intro h,\n  by_contradiction H,\n  rw ← h,\n  exact H,\nend\n\nend negation_prop\n\nsection negation_quantifiers\nvariables (X : Type) (P : X → Prop)\n\n-- 0058\nexample : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x :=\nbegin\n  split,\n  intro h,\n  by_contradiction H,\n  apply h,\n  intro x,\n  by_contradiction HH,\n  apply H,\n  use x,\n  intro h,\n  by_contradiction H,\n  cases h with x hx,\n  specialize H x,\n  apply hx,\n  exact H,\nend\n\n-- 0059\nexample : ¬ (∃ x, P x) ↔ ∀ x, ¬ P x :=\nbegin\n  split,\n  intros h x hx,\n  apply h,\n  use x,\n  exact hx,\n  intros h hx,\n  cases hx with x hhx,\n  specialize h x,\n  apply h,\n  exact hhx,\nend\n\n-- 0060\nexample (P : ℝ → Prop) : ¬ (∃ ε > 0, P ε) ↔ ∀ ε > 0, ¬ P ε :=\nbegin\n  split,\n  intros h ε ε_pos hε,\n  apply h,\n  use ε,\n  exact ⟨ε_pos, hε⟩,\n  intros h hx,\n  cases hx with ε hh,\n  cases hh with ε_pos hε,\n  specialize h ε ε_pos,\n  apply h,\n  exact hε,\nend\n\n-- 0061\nexample (P : ℝ → Prop) : ¬ (∀ x > 0, P x) ↔ ∃ x > 0, ¬ P x :=\nbegin\n  split,\n  intro h,\n  by_contradiction H,\n  apply h,\n  intros x x_pos,\n  by_contradiction HH,\n  apply H,\n  use x,\n  exact ⟨x_pos, HH⟩,\n  intros h hx,\n  cases h with x hhx,\n  cases hhx with hxx hh,\n  specialize hx x hxx,\n  apply hh,\n  exact hx,\nend\n\nend negation_quantifiers\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/07bis_abstract_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320035, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7643846820349446}}
{"text": "import logic.relation\n\nnamespace cs2120\n\nsection functions\n\nvariables\n  {α β : Type}        -- any two data types\n  (r : α → β → Prop)  -- any binary relation\n/-\nI've simplified α and β to be ordinary types\ncompared to what I presented in lecture. This\njust makes things a little simpler here.\n-/\n\n-- Single-valued in \"relational algebra\" means not one-to-many\ndef single_valued := ∀ (a : α) (b c : β), r a b → r a c → b = c \n\n-- A function is a single-valued relation; these are synonyms\ndef function := @single_valued α β  \n\n/-\nNote: Compared to lecture, I've related single_value with\nfunction in the following definitions. The meanigns are of\ncourse equivalent, but the meaning is expressed more clearly\nhere, as the term, injective (and surjective and bijective,\nbelow) apply only to relations that are also functions. \n-/\n\n-- A function is injective if it's not many-to-one\ndef injective := ∀ (a b : α) (c : β), \n  function r → r a c → r b c → a = b\n\n/- \nA function is total if it is defined for every element \nof the domain: that is, if every \"input/α\" value has\na corresponding \"output/β\" value.\n-/\ndef total_function := \n  function r → ∀ (a : α), ∃ (b : β), r a b \n\n\n/-\nA strictly partial function is one for which there is\nsome input/α value with no corresponding output/β value. \nMathematicians sometimes consider total functions also\nto be partial functions, so we use the term \"strictly\npartial\" to refer to functions that are not total.\n-/\ndef strictly_partial := function r → ∃ a, ¬ ∃ b, r a b\n-- In lecture I omitted the condition that r is a function \n\n/-\nA function is said to be surjective if it \"covers\" the\nco-domain, which is to say the set in which the output\nvalues \"live.\" In other words, for every element of the\noutput/β set/type, there is some element in the input/α \nset/type that is related to that output value.\n-/\ndef surjective := function r → ∀ b, ∃ a, r a b\n\n/-\nA function is said to be bijective if it is injective\n(one to one, not many-to-one) and and surjective (the\noutput/co-domain set/type is covered).\n-/\ndef bijective := injective r ∧ surjective r\n\n\n/-\nIn Lean, \"functions\" that compute are necessarily total.\nFor *any* value of their input type, they have to return\nsome value of the output type. You can see this clearly \nin the definition of the function type notation, α → β,\nas ∀ (a : α), β -- that for *every* value of type α such\na function must return some value of type β. \n\nSo how do we represent a strictly partial function in \nLean or in a similar proof assistant? Rather than using\na computation definition, we use a logical definition!\n\nHere we will define a partial relation between values \nof two types, Person and ℕ. Think of it as returning\nthe driver's license id number of a given person. No\nperson has several id_numbers (or they shouldn't in \nany case!) so the relation is a function. However not\neery person has an id_number, so we have a strictly\npartial function.\n\nTo keep things simple, we'll model a toy world in \nwhich there are only three people. Let's just call\nthem p1, p2, and p3. We'll thus define Person as a\ndata type with just three values. \n-/\n\ninductive Person : Type\n| p1 : Person\n| p2 : Person\n| p3 : Person\n\n-- To avoid having to type Person.p1, etc. we ...\nopen Person   -- ... open the person namespace.\n\n\n/-\nNow comes the new part! We define the id_number\nrelation as a kind of parameterized data type.\nThat's what \"inductive\" means in the following\ndefinition. id_number takes a person and an id\nnumber as parameters and yields a *proposition*,\nthat we understand as asserting that that person\nhas that id number. The trick is that we go on\nto define the proofs that are available to prove\nsuch propositions. In this case, we define pf1\nto be a proof of id_number p1 1 (that the person\np1 has id number 1), and pf2 to be a proof that\nperson p2 has id_number 2. *We do not define a\nproof that p3 has a corresponding id number, so\nit doesn't!* We thus specify the strictly partial \nfunction, id_number = { (p1, 1), (p2, 2) }. \n-/\ninductive id_number : Person → ℕ → Prop \n| pf1 : id_number p1 1\n| pf2 : id_number p2 2\n\nopen id_number  -- open the namespace\n\n\n/-\nNow with all this machinery set up, we are in a\nplace where we can state and prove propositions\nsuch as this: id_number is an injective function. \nYou can easily see that it's injective, in that\nno two distinct \"people\" with the same id. Now\nwe'll prove it.\n-/\n\nexample : injective id_number := \nbegin\n-- By the definition of injective ...\nunfold injective,\n\n-- we are to ...\nshow ∀ (p1 p2 : Person) (idn : ℕ), \n  function id_number → \n  id_number p1 idn → \n  id_number p2 idn → \n  p1 = p2,\n\n-- Let person1 and person2 be arbitrary persons \nintros person1 person2,\n\n-- Assume id is an arbitrary id number (nat), ...\nintro id,\n\n-- that id_number is a function, ...\nassume id_number_is_func,\n\n-- and that p1 and p2 each have id number \"id\"\nassume person1_id person2_id,\n\n-- To show id_number is injective we must ...\nshow person1 = person2,\n\n/-\nFrom here the proof is by case analysis on \nperson1 and person2, each of which can have\none of three values (p1, p2, p3), giving us\nnine cases to consider. All the cases where\nperson1 ≠ person2 yield contradictions and \nso can be ignored as impossibilities, while\nthere are proofs in the three cases where\nperson1 = person2. That'll do it. Here it\ngoes\n-/\n-- case analysis person1 (p1, p2, p3)\ncases person1,\n\n-- case person1 = p1\n\n    -- case analysis person2 (p1, p2, p3)\n    cases person2,\n\n    -- case #1: person1 = p1, person2 = p1\n    exact rfl,    -- they're the same person\n\n    -- case #2: person1 = p1, person2 = p2\n\n    /-\n    Remember that case analysis gives you\n    one case for each way a given value/proof\n    can be constructed, including arguments \n    to the presumed constructors. Here case\n    analysis on person1_id reveals that the only\n    way to construct this proof is if id_num\n    is 1. \n    -/\n    cases person1_id,\n    /- \n    But now there is no way to construct \n    person2_id. With no cases to consider due\n    to contradiction, we can just ignore \n    this case, a form of false elimination.\n    -/ \n    cases person2_id,\n\n\n    -- case #3: person1 = p1, person2 = p3\n    -- Proof is same style as case #2\n    cases person1_id,\n    -- but now person2_id cannot be \n    cases person2_id,\n\n\n\n-- case person1 = p2\n\n    -- case analysis person2 (p1, p2, p3)\n    cases person2,\n\n    -- case #4: person1 = p2, person2 = p1\n    cases person1_id,\n    cases person2_id,\n\n    -- case #5: person1 = p2, person2 = p2\n    exact rfl,\n\n    -- case #6: person1 = p2, person2 = p3\n    -- p3 has no id, so no cases to consider\n    cases person2_id,\n\n-- case: person1 = p3\n\n  -- case analysis person2 (p1, p2, p3)\n  cases person2,\n\n  -- case #7: p3 has no id\n  cases person1_id,\n  -- case #8: p3 has no id\n  cases person1_id,\n  -- case #9: p3 has no id\n  cases person1_id,\n\n/- \nThe only way that the conditions can be\nsatisfied is if person1 = person2, which\nshows that the function is injective: no\ntwo distinct people have the same id in\nthe *partial function* specified by the \ndefinition of id_number.\n\nQED.\n-/\n\nend\n\nend functions\n\nend cs2120", "meta": {"author": "kevinsullivan", "repo": "cs2120f22", "sha": "8710cf4262e905ffe2b1dee165473ee1f940440b", "save_path": "github-repos/lean/kevinsullivan-cs2120f22", "path": "github-repos/lean/kevinsullivan-cs2120f22/cs2120f22-8710cf4262e905ffe2b1dee165473ee1f940440b/src/instructor/04_Functions/01_properties_of_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.764384680419926}}
{"text": "import Mathlib.Tactic.Basic\nimport Mathlib.Init.Data.Nat.Basic\n/-!\n## Calculation Proofs\n\nIn informal mathematics, we often express proofs as transitive chains of equalities, inequalities,\nor equivalences (e.g., `a = b = c`, `a ≥ b ≥ c`, or `a ↔ b ↔ c`). In Lean, such _calculational proofs_ are\nsupported by the `calc` command. It provides a lightweight syntax and takes care of applying\ntransitivity lemmas for preregistered relations, such as equality and the arithmetic comparison\noperators.\n\nThe general syntax is as follows:\n\n```lean\ncalc\n  term₀ op₁ term₁ : proof1\n  _     op₂ term₂ : proof₂\n  .\n  .\n  .\n  _     opₙ termₙ : proofₙ\n```\n\nEach _proofᵢ_ justifies the statement _termᵢ-₁ opᵢ termᵢ_.\nThe operators _opᵢ_ need not be identical, but they must be compatible.\nThe underscore (_) is a placeholder for the previous term.\nFor example, =, <, and ≤ are compatible with each other, whereas > and < are not.\n\nA simple example follows:\n-/\naxiom two_mul (n : ℕ) : 2 * n = n + n\n\nlemma two_mul_example (m n : ℕ) :\n  2 * m + n = m + n + m :=\n  calc\n    2 * m + n = (m + m) + n := by rw [two_mul]\n    _ = m + n + m := by rw [Nat.add_right_comm]\n\n/-!\nMathematicians (assuming they would condescend to offer a justification for such\na trivial result) could have written the above proofs roughly as follows:\n\n```\n2 * m + n\n= (m + m) + n       (since 2 * m = m + m)\n= m + n + m         (by associativity and commutativity of +)\n```\n\nIn the Lean proof, the underscore stands for the prior term₁ `(m + m) + n`, which we\nwould have had to repeat had we written the proof without `calc`:\n\n-/\nlemma two_mul_example2 (m n : ℕ) :\n2 * m + n = m + n + m :=\n  have h1 : 2 * m + n = (m + m) + n :=\n  by rw [two_mul]\n  have h2 : m + m + n = m + n + m :=\n  by rw [Nat.add_right_comm]\n  show _ from\n  Eq.trans h1 h2\n/-!\nNotice that with `have`s, we also need to explicitly invoke `Eq.trans` and to give\nnames to the two intermediate steps.\n\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/ForwardProofs/CalculationProofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7643545038107437}}
{"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# Figuring out how to use the reals\n\n## The `library_search` tactic\n\nWe saw in the previous sheet that we couldn't even prove something\nas simple as \"if `aₙ → L` then `-aₙ → -L`\" because when you write down\nthe proof carefully, it relies on the fact that `|x - y| = |y - x|`\nor, equivalently, that `|(-x)| = |x|`. I say \"equivalently\" because\n`ring` will prove that `-(x - y) = y - x`.\n\nYou don't want to be proving stuff like `|x - y| = |y - x|` from first\nprinciples. Someone else has already done all the hard work for you.\nAll you need to do is to learn how to find out the *names* of the lemmas,\nand then you can `rw` them! The `library_search` tactic tells you\nthe names of all these lemmas.  See where the output says \"try this\"?\nClick on \"try this\" and Lean will replace\n`library_search` with the actual name of the lemma. Once you've done\nthat, you can hover over the lemma name to see in what generality it holds.\n\n## The `linarith` tactic\n\nSome of the results below are bare inequalities which are too complex\nto be in the library. The library contains \"natural\" or \"standard\"\nresults, but it doesn't contain a random inequality fact just because\nit happens to be true -- the library just contains \"beautiful\" facts.\n\nThe `linarith` tactic is a tactic which can solve some equalities and inequalities\nin ordered structures like the naturals or reals. Unlike `ring`, `linarith`\ndoes look at hypotheses in the tactic state. For example if you have\nhypotheses `h1 : a < b` and `h2 : b ≤ c` then `linarith` would prove\na goal of `⊢ a < c`.\n\nHowever `linarith` doesn't know about anything other than `=`, `≠`,\n`<` and `≤`, so don't expect it to prove any results about `|x|` or\n`max A B`.\n\nExperiment with the `library_search` and `linarith` tactics below.\nTry and learn something about the naming convention which Lean uses;\nsee if you can start beginning to guess what various lemmas should be called.\n\n-/\n\nexample (x : ℝ) : |(-x)| = |x| :=\nbegin\n  sorry\nend\n\nexample (x y : ℝ) : |x - y| = |y - x| :=\nbegin\n  sorry\nend \n\nexample (A B C : ℕ) : max A B ≤ C ↔ A ≤ C ∧ B ≤ C :=\nbegin\n  sorry\nend\n\nexample (x y : ℝ) : |x| < y ↔ -y < x ∧ x < y :=\nbegin\n  sorry\nend\n\nexample (ε : ℝ) (hε : 0 < ε) : 0 < ε / 2 :=\nbegin\n  sorry,\nend\n\nexample (a b x y : ℝ) (h1 : a < x) (h2 : b < y) : a + b < x + y :=\nbegin\n  sorry,\nend\n\nexample (ε : ℝ) (hε : 0 < ε) : 0 < ε / 3 :=\nbegin\n  sorry,\nend\n\nexample (a b c d x y : ℝ) (h1 : a + c < x) (h2 : b + d < y) :\n  a + b + c + d < x + y :=\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/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7642747446964078}}
{"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.basic\n\n/-!\n## Counit morphisms for multivariate polynomials\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nOne may consider the ring of multivariate polynomials `mv_polynomial A R` with coefficients in `R`\nand variables indexed by `A`. If `A` is not just a type, but an algebra over `R`,\nthen there is a natural surjective algebra homomorphism `mv_polynomial A R →ₐ[R] A`\nobtained by `X a ↦ a`.\n\n### Main declarations\n\n* `mv_polynomial.acounit R A` is the natural surjective algebra homomorphism\n  `mv_polynomial A R →ₐ[R] A` obtained by `X a ↦ a`\n* `mv_polynomial.counit` is an “absolute” variant with `R = ℤ`\n* `mv_polynomial.counit_nat` is an “absolute” variant with `R = ℕ`\n\n-/\n\nnamespace mv_polynomial\nopen function\n\nvariables (A B R : Type*) [comm_semiring A] [comm_semiring B] [comm_ring R] [algebra A B]\n\n/-- `mv_polynomial.acounit A B` is the natural surjective algebra homomorphism\n`mv_polynomial B A →ₐ[A] B` obtained by `X a ↦ a`.\n\nSee `mv_polynomial.counit` for the “absolute” variant with `A = ℤ`,\nand `mv_polynomial.counit_nat` for the “absolute” variant with `A = ℕ`. -/\nnoncomputable def acounit : mv_polynomial B A →ₐ[A] B :=\naeval id\n\nvariables {B}\n\n@[simp] lemma acounit_X (b : B) : acounit A B (X b) = b := aeval_X _ b\n\nvariables {A} (B)\n\n@[simp] lemma acounit_C (a : A) : acounit A B (C a) = algebra_map A B a := aeval_C _ a\n\nvariables (A)\n\nlemma acounit_surjective : surjective (acounit A B) := λ b, ⟨X b, acounit_X A b⟩\n\n/-- `mv_polynomial.counit R` is the natural surjective ring homomorphism\n`mv_polynomial R ℤ →+* R` obtained by `X r ↦ r`.\n\nSee `mv_polynomial.acounit` for a “relative” variant for algebras over a base ring,\nand `mv_polynomial.counit_nat` for the “absolute” variant with `R = ℕ`. -/\nnoncomputable def counit : mv_polynomial R ℤ →+* R :=\nacounit ℤ R\n\n/-- `mv_polynomial.counit_nat A` is the natural surjective ring homomorphism\n`mv_polynomial A ℕ →+* A` obtained by `X a ↦ a`.\n\nSee `mv_polynomial.acounit` for a “relative” variant for algebras over a base ring\nand `mv_polynomial.counit` for the “absolute” variant with `A = ℤ`. -/\nnoncomputable def counit_nat : mv_polynomial A ℕ →+* A :=\nacounit ℕ A\n\n\nlemma counit_surjective : surjective (counit R) := acounit_surjective ℤ R\nlemma counit_nat_surjective : surjective (counit_nat A) := acounit_surjective ℕ A\n\n\n\nvariables {R A}\n\n@[simp] lemma counit_X (r : R) : counit R (X r) = r := acounit_X _ _\n@[simp] lemma counit_nat_X (a : A) : counit_nat A (X a) = a := acounit_X _ _\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/counit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.8376199572530449, "lm_q1q2_score": 0.7642747437181951}}
{"text": "import tutorial_world.level07_split --hide\nopen IncidencePlane --hide\nopen set --hide\n\n/- Tactic : use\n\n## Summary\nThe `use` tactic works on the goal that looks like `⊢ ∃ x, P x`, where the symbol **`∃`** is read as **\"there exists\"** and\n**`P x`** can be understood as **\"P is an element of x\"**, which could also be written as **`P ∈ x`**.\nIn this case, the whole goal can be interpreted as **\"there exists x such that P is an element of x\"**.\nThen, the `use` tactic is useful. If we know that an object `a` satisfies the  property `x`, then `use a` \nwill simplify the goal into ⊢ P a.\n\n## Example\nIf your goal is `⊢ ∃ n : natural_numbers, 1 + x = x + n` then `use 1` will \nturn the goal into `⊢ 1 + x = x + 1`, and the rather more unwise `use 0` will \nturn it into the impossible-to-prove `⊢ 1 + x = x + 0`.\n-/\n\n/-\n# Tutorial World\n\n## Level 8: the `use` tactic.\n\nIn further proofs, we will need to prove that there exists an object satisfying certain properties.\nThe goal will then look like `⊢ ∃ x, P x`, where the symbol **`∃`** is read as **\"there exists\"** and\n**`P x`** can be understood as **\"P is an element of x\"**, which could also be written as **`P ∈ x`**.\nIn this case, the whole goal can be interpreted as **\"there exists x such that P is an element of x\"**.\nThen, the `use` tactic is useful. If we know that an object `a` satisfies the  property `x`, then `use a` \nwill simplify the goal into ⊢ P a.\n\nLet's look at this level to understand it better! Delete the `sorry` to see the goal `⊢ ∃ (ℓ : Line Ω), P ∈ ℓ`.\nWhat does this mean? You can read it as **\"there exists a line ℓ that lies in the plane Ω, such that the point P is an element of the line ℓ\"**. \n[**Tip:** do a drawing if it feels very abstract to you.] Then, we have to \nfind an object **?** that satisfies the property `ℓ`, so that we can type `use ?,` to simplify the goal into \n`⊢ P ∈ ?`. Now, we should take a look at our \"Theorem statements\" section to ask ourselves if there is any statement\nthat has a similar structure to the goal `⊢ P ∈ ?`. At this point, I am sure that you thought about `line_through_right`\nor `line_through_left`. The statement `⊢ P ∈ line_through P Q` is very similar to that in `⊢ P ∈ ?`, isn't it?\n\nThen, why don't we type `use line_through P Q,`. If you try that, you will see that an error appears. This is\nbecause we don't have such point called Q in this level. We only have one point! And it's called P! What does this mean?\nDo we have to create a line that goes from the point P to the point P again? Exactly! You may be wondering how is \nthat possible if a line cannot close itself as if it was a circle... in the plane! However, it **is** possible. We have not\ndefined what is a plane yet! The computer doesn't know how a plane looks like! Because of this reason, you can type `use \nline_through P P,` and see how the goal changes into `⊢ P ∈ line_through P P`. Now, try to finish the proof by your own! It's \nonly one more line of code! In case you get stuck, click on the grey box right below to look for a \"Hint\".\n \n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nBecause the goal is now `⊢ P ∈ line_through P P`, it shows the same structure as `line_through_left` and `line_through_right`\nstatements. Try any of both to finish the proof by using the `exact` tactic. Remember to type the variables that we are using \nbefore the comma! Still bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution. \n-/\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\n\n/- Lemma : no-side-bar\nGiven a point, there is always a line containing it.\n-/\nlemma line_containing_point (P : Ω) : ∃ ℓ : Line Ω, P ∈ ℓ :=\nbegin\n  use line_through P P,\n  exact line_through_left P P,\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/level08_use.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7642747432826628}}
{"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\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 + √(2n)`.\n\n# Solution\nWe first prove the following lemma: for every prime `p > 20`, satisfying `p ≡ 1 [MOD 4]`,\nthere exists `n ∈ ℕ` such that `p ∣ n^2 + 1` and `p > 2n + √(2n)`. Then the statement of the\nproblem follows from the fact that there exist infinitely many primes `p ≡ 1 [MOD 4]`.\n\nTo prove the lemma, notice that `p ≡ 1 [MOD 4]` implies `∃ n ∈ ℕ` such that `n^2 ≡ -1 [MOD p]`\nand we can take this `n` such that `n ≤ p/2`. Let `k = p - 2n ≥ 0`. Then we have:\n`k^2 + 4 = (p - 2n)^2 + 4 ≣ 4n^2 + 4 ≡ 0 [MOD p]`. Then `k^2 + 4 ≥ p` and so `k ≥ √(p - 4) > 4`.\nThen `p = 2n + k ≥ 2n + √(p - 4) = 2n + √(2n + k - 4) > √(2n)` and we are done.\n-/\n\nlemma p_lemma (p : ℕ) (hpp : nat.prime p) (hp_mod_4_eq_1 : p ≡ 1 [MOD 4]) (hp_gt_20 : p > 20) :\n  ∃ n : ℕ, p ∣ n^2 + 1 ∧ (p : ℝ) > 2*n + real.sqrt(2*n) :=\nbegin\n  haveI := fact.mk hpp,\n  have hp_mod_4_ne_3 : p % 4 ≠ 3, { linarith [(show p % 4 = 1, by exact hp_mod_4_eq_1)]},\n  obtain ⟨y, hy⟩ := (zmod.exists_pow_two_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₁ : p ∣ n^2 + 1,\n  { refine int.coe_nat_dvd.mp _,\n    simp only [int.nat_abs_pow_two, 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₂ : n ≤ p/2 := zmod.nat_abs_val_min_abs_le y,\n  have hnat₃ : p ≥ 2*n, { linarith [nat.div_mul_le_self p 2] },\n\n  set k : ℕ := p - 2*n with hnat₄,\n\n  have hnat₅ : p ∣ k^2 + 4,\n  { cases hnat₁ with x hx,\n    let p₁ := (p : ℤ), let n₁ := (n : ℤ), let k₁ := (k : ℤ), let x₁ := (x : ℤ),\n    have : p₁ ∣ k₁^2 + 4,\n    { use p₁ - 4*n₁ + 4*x₁,\n      calc  k₁^2 + 4\n          = (p₁ - 2*n₁)^2 + 4             : by rw (show k₁ = p₁ - 2*n₁, by assumption_mod_cast)\n      ... = p₁^2 - 4*p₁*n₁ + 4*(n₁^2 + 1) : by ring\n      ... = p₁^2 - 4*p₁*n₁ + 4*(p₁*x₁)    : by rw (show n₁^2 + 1 = p₁*x₁, by assumption_mod_cast)\n      ... = p₁*(p₁ - 4*n₁ + 4*x₁)         : by ring },\n    assumption_mod_cast },\n\n  have hnat₆ : k^2 + 4 ≥ p := nat.le_of_dvd (k^2 + 3).succ_pos hnat₅,\n\n  let p₀ := (p : ℝ), let n₀ := (n : ℝ), let k₀ := (k : ℝ),\n\n  have hreal₁ : p₀ = 2*n₀ + k₀, { linarith [(show k₀ = p₀ - 2*n₀, by assumption_mod_cast)] },\n  have hreal₂ : p₀ > 20,        { assumption_mod_cast },\n  have hreal₃ : k₀^2 + 4 ≥ p₀,  { assumption_mod_cast },\n\n  have hreal₄ : k₀ ≥ real.sqrt(p₀ - 4),\n  { calc  k₀ = real.sqrt(k₀^2)    : eq.symm (real.sqrt_sqr (nat.cast_nonneg k))\n    ...      ≥ real.sqrt(p₀-4)    : real.sqrt_le_sqrt (by linarith [hreal₃]) },\n\n  have hreal₅ : k₀ > 4,\n  { calc k₀ ≥ real.sqrt(p₀-4)     : hreal₄\n    ...     > real.sqrt(4^2)      : (real.sqrt_lt (by linarith)).mpr (by linarith [hreal₂])\n    ...     = 4                   : real.sqrt_sqr (by linarith) },\n\n  have hreal₆ : p₀ > 2*n₀ + real.sqrt(2*n),\n  { calc p₀ = 2*n₀ + k₀                   : hreal₁\n    ...     ≥ 2*n₀ + real.sqrt(p₀-4)      : by linarith [hreal₄]\n    ...     = 2*n₀ + real.sqrt(2*n₀+k₀-4) : by rw hreal₁\n    ...     > 2*n₀ + real.sqrt(2*n₀)      : by { refine add_lt_add_left _ (2*n₀),\n                                                 refine (real.sqrt_lt _).mpr _,\n                                                 refine mul_nonneg zero_le_two (nat.cast_nonneg n),\n                                                 linarith [hreal₅] } },\n\n  exact ⟨n, hnat₁, hreal₆⟩,\nend\n\n\ntheorem imo2008_q3 : ∀ N : ℕ, ∃ n : ℕ, n ≥ N ∧\n  ∃ p : ℕ, nat.prime p ∧ p ∣ n^2 + 1 ∧ (p : ℝ) > 2*n + real.sqrt(2*n) :=\nbegin\n  intro N,\n  obtain ⟨p, hpp, hineq₁, hp_mod_4_eq_1⟩ := nat.exists_prime_ge_modeq_one 4 (N^2+21) zero_lt_four,\n  obtain ⟨n, hnat, hreal⟩ := p_lemma p hpp hp_mod_4_eq_1 (by linarith [hineq₁, nat.zero_le (N^2)]),\n\n  have hineq₂  : n^2 + 1 ≥ p := nat.le_of_dvd (n^2).succ_pos hnat,\n  have hineq₃  : n*n ≥ N*N,  { linarith [hineq₁, hineq₂, (pow_two n), (pow_two N)] },\n  have hn_ge_N : n ≥ N       := nat.mul_self_le_mul_self_iff.mpr hineq₃,\n\n  exact ⟨n, hn_ge_N, p, hpp, hnat, hreal⟩,\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_q3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7642747336007386}}
{"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# The real numbers in Lean\n\nLean has a copy of of the real numbers. It's called `real`, \nbut we use the usual notation `ℝ`. Put your cursor on the `ℝ` to find\nout how to type it in VS Code.\n\nIn this sheet you will prove some basic equalities and inequalities\nbetween \"numerical expressions\" in Lean. A numeral is something like `37`,\nand a numerical expression is something like `(37 + 6) / 4`. To make\nthings a bit harder, I will throw in some `∃` statements. To make\nprogress on an `∃` goal, use the `use` tactic.\n\n## Tactics\n\nNew tactics you'll need to know about:\n\n* `norm_num` (proves equalities and inequalities involving numerical expressions)\n* `use` (if the goal is `∃ x, x + 37 = 42` then `use 8` will change the goal\n*        to `8 + 37 = 42`, and `use 10` will change it to `10 + 37 = 42`.\n\n-/\n\nexample : (2 : ℝ) + 2 = 4 :=\nbegin\n  norm_num,\nend\n\nexample : (2 : ℝ) + 2 ≠ 5 :=\nbegin\n  norm_num,\nend\n\nexample : (2 : ℝ) + 2 < 5 :=\nbegin\n  norm_num,\nend\n\nexample : ∃ (x : ℝ), 3 * x + 7 = 12 :=\nbegin\n  use 5/3,\n  norm_num,\nend\n\nexample : ∃ (x : ℝ), 3 * x + 7 ≠ 12 :=\nbegin\n use 1,\n norm_num,\nend\n\nexample : ∃ (x y : ℝ), 2 * x + 3 * y = 7 ∧ x + 2 * y = 4 :=\nbegin\n  use [2,1],\n  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/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012762876287, "lm_q2_score": 0.8080672158638528, "lm_q1q2_score": 0.7642710040902226}}
{"text": "import data.real.basic\n\nvariables a b c d e: ℝ\n\n#check mul_comm\n#check mul_assoc\n#check add_comm\n#check add_assoc (d * e)\n#check add_mul\n#check mul_add\n#check two_mul\n\n-- BEGIN\nexample : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw [mul_add, add_mul, add_mul],\n  rw [←add_assoc, add_assoc (a * a)],\n  rw [mul_comm b a, ←two_mul],\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 [←add_assoc, add_assoc (a * a)]\n  ... = a * a + 2 * (a * b) + b * b     :\n          by rw [mul_comm b a, ←two_mul]\n\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    begin\n      rw add_mul,\n      rw [mul_add, mul_add],\n      rw mul_comm b a,\n    end\n  ... = a * a + (b * a + a * b) + b * b : by rw [←add_assoc, add_assoc (a * a)]\n  ... = a * a + 2 * (a * b) + b * b     : by rw [mul_comm a b, ←two_mul]\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/ex22_rw_perfect_squr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012747599251, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7642710028557355}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nimport MultiplicationWorld.Level1\nimport MultiplicationWorld.Level6\nnamespace MyNat\nopen MyNat\n\n/-!\n# Multiplication World\n\n## Level 8: `mul_comm`\n\nFinally, the boss level of multiplication world. But you are well-prepared for it -- you have\n`zero_mul` and `mul_zero`, as well as `succ_mul` and `mul_succ`. After this level you can of course\nthrow away one of each pair if you like, but I would recommend you hold on to them, sometimes it's\nconvenient to have exactly the right tools to do a job.\n\n## Lemma\nMultiplication is commutative.\n-/\nlemma mul_comm (a b : MyNat) : a * b = b * a := by\n  induction b with\n  | zero =>\n    rw [zero_is_0]\n    rw [zero_mul]\n    rw [mul_zero]\n  | succ b ih =>\n    rw [succ_mul]\n    rw [←ih]\n    rw [mul_succ]\n\n/-!\nYou've now proved that the natural numbers are a commutative semiring!\nThat's the last collectible in Multiplication World.\n-/\n-- instance MyNat.comm_semiring : comm_semiring MyNat := by structure_helper\n-- BUGBUG\n/-!\nBut don't leave multiplication just yet -- prove `mul_left_comm`, the last\nlevel of the world, and then we can beef up the power of `simp`.\n\nOn to [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/MultiplicationWorld/Level8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012701768144, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7642709947806111}}
{"text": "import tactic\nimport data.nat.prime\nimport data.set.finite\n\nopen nat\n\nprivate def generate_naturals_satisfying_down (pred : ℕ → Prop) [decidable_pred pred] : ℕ → list ℕ\n| 0     := []\n| (n+1) := if pred n\n           then n :: generate_naturals_satisfying_down n\n           else      generate_naturals_satisfying_down n\n\ndef generate_naturals_satisfying_under (pred : ℕ → Prop) [decidable_pred pred] (z : ℕ) : list ℕ :=\nlist.reverse (generate_naturals_satisfying_down pred z)\n\ndef generate_primes_under (z : ℕ) : list ℕ :=\ngenerate_naturals_satisfying_under nat.prime z\n\n#eval generate_primes_under 40\n\nlemma generated_exactly_naturals_satisfying_under (pred : ℕ → Prop) [decidable_pred pred] (z : ℕ) :\n  ∀ n : ℕ,  n ∈ generate_naturals_satisfying_under pred z  ↔  n < z  ∧  pred n  :=\nbegin\n  unfold generate_naturals_satisfying_under,\n  induction z with y ih,\n  {\n    intro n,\n    unfold generate_naturals_satisfying_down,\n    simp,\n  },\n  intro n,\n  specialize ih n,\n  rw list.mem_reverse at *,\n  split,\n  {\n    intro ass,\n    unfold generate_naturals_satisfying_down at ass,\n    by_cases n = y,\n    {\n      rename h n_eq_y,\n      rw n_eq_y at *,\n      have y_not_in : y ∉ generate_naturals_satisfying_down pred y,\n      {\n        by_contradiction,\n        have hyp := (ih.1 h).left,\n        exact (ne_of_lt hyp) rfl,\n      },\n      split_ifs at ass,\n      {\n        split,\n        {\n          exact lt_add_one y,\n        },\n        {\n          exact h,\n        },\n      },\n      {\n        exfalso,\n        exact y_not_in ass,\n      }\n    },\n    {\n      rename h n_neq_y,\n      have n_in : n ∈ generate_naturals_satisfying_down pred y,\n      {\n        split_ifs at ass,\n        {\n          cases ass,\n          {\n            exfalso,\n            exact n_neq_y ass,\n          },\n          {\n            exact ass,\n          }\n        },\n        {\n          exact ass,\n        }\n      },\n      have hyp := ih.1 n_in,\n      split,\n      {\n        exact nat.lt.step hyp.left,\n      },\n      {\n        exact hyp.right,\n      },\n    },\n  },\n  {\n    rintro ⟨ n_small, n_prime ⟩,\n    by_cases n < y,\n    {\n      rename h n_lt_y,\n      have hyp := ih.2 (and.intro n_lt_y n_prime),\n      unfold generate_naturals_satisfying_down,\n      split_ifs,\n      {\n        exact list.mem_cons_of_mem y hyp,\n      },\n      {\n        exact hyp,\n      },\n    },\n    {\n      have n_eq_y := nat.eq_of_lt_succ_of_not_lt n_small h,\n      clear h,\n      rw n_eq_y at *,\n      unfold generate_naturals_satisfying_down,\n      split_ifs,\n      exact list.mem_cons_self y _,\n    }\n  },\nend\n\ntheorem generated_exactly_primes_under (z : ℕ) :\n  ∀ n : ℕ,  n ∈ generate_primes_under z  ↔  n < z  ∧  nat.prime n  :=\ngenerated_exactly_naturals_satisfying_under nat.prime z\n\n\nprivate def is_prime_aux (n : ℕ) (k : ℕ) : ℕ → bool\n| zero     := tt\n| (succ d) := if (k - d) ∣ n\n              then ff\n              else is_prime_aux d\n\n-- It is not really fast, but why?\ndef is_prime_fast (n : ℕ) : bool :=\nif n > 1\nthen is_prime_aux n (nat.sqrt n) (nat.sqrt n - 1)\nelse ff\n\ndef generate_primes_under_fast (z : ℕ) : list ℕ :=\ngenerate_naturals_satisfying_under (λ x, is_prime_fast x) z\n\n#eval generate_primes_under_fast 40\n\n#eval list.length $ generate_primes_under 100000\n#eval list.length $ generate_primes_under_fast 100000\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/Primes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7642272615201056}}
{"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.list.basic data.vector data.finset data.nat.choose\nimport data.fintype.basic\nimport combinatorics.shift\n\nimport tactic.squeeze\nnamespace combinatorics\n\n/- @latex: defn-binseq -/\ndef binseq := list bool\n\nnamespace binseq\n\ninstance : has_append binseq := \n  by { dsimp[binseq], apply_instance }\n\ndef repr' : binseq → string\n| [] := \"\"\n| (ff :: u) := \"0\" ++ (repr' u)\n| (tt :: u) := \"1\" ++ (repr' u)\n\ninstance : has_repr binseq := \n ⟨λ u, if u = [] then \"∅\" else repr' u⟩ \n\ndef of_string (s : string) : binseq := \n s.fold [] (λ l c, if c = '0' then (l ++ [ff])\n                    else (if c = '1' then (l ++ [tt]) else l))\n\ndef rank : ∀ (u : binseq), ℕ \n| [] := 0\n| (ff :: v) := (rank v)\n| (tt :: v) := (rank v).succ\n\ndef enum_by_length : ∀ (n : ℕ), list binseq \n| 0 := [[]]\n| (n + 1) := ((enum_by_length n).map (list.cons ff)) ++ \n             ((enum_by_length n).map (list.cons tt))\n\ndef enum_by_length_and_rank : ∀ (n k : ℕ), list binseq \n| 0 0 := [[]]\n| 0 (k + 1) := []\n| (n + 1) 0 := \n   (enum_by_length_and_rank n 0).map (list.cons ff)\n| (n + 1) (k + 1) :=\n   (enum_by_length_and_rank n (k + 1)).map (list.cons ff) ++\n   (enum_by_length_and_rank n k).map (list.cons tt)\n\nnamespace eg\n\n/- @latex: eg-binseq -/\ndef a := binseq.of_string \"010110\"\n#eval a\n#eval a.length\n#eval a.rank\n\n#eval enum_by_length 3\n#eval enum_by_length_and_rank 5 3\n\nend eg\n\nnamespace enum_by_length\n\nlemma length (n : ℕ) : (enum_by_length n).length = 2 ^ n := \nbegin\n  induction n with n ih; rw[enum_by_length],\n  { simp },\n  { rw[list.length_append, list.length_map, list.length_map,\n       ih, pow_succ, two_mul] }\nend\n\nlemma nodup (n : ℕ) : (enum_by_length n).nodup := \nbegin\n  induction n with n ih; rw[enum_by_length],\n  { exact list.nodup_singleton _ },\n  { rw[list.nodup_append], split,\n    { exact list.nodup.map list.cons_injective ih },\n    split,\n    { exact list.nodup.map list.cons_injective ih },\n    { intros u hff htt,\n      rcases list.mem_map.mp hff with ⟨v,⟨mv,ev⟩⟩,\n      rcases list.mem_map.mp htt with ⟨w,⟨mw,ew⟩⟩,\n      injection (ev.trans ew.symm) with hb ht,\n      cases hb }\n  }\nend\n\nlemma mem_iff {n : ℕ} {u : binseq} : u ∈ (enum_by_length n) ↔ u.length = n := \nbegin\n  induction n with n ih generalizing u; rw[enum_by_length],\n  { rw[list.mem_singleton], symmetry, exact list.length_eq_zero },\n  { rw[list.mem_append],\n    split,\n    rintro (hff|htt),\n    { rcases list.mem_map.mp hff with ⟨v,⟨mv,ev⟩⟩,\n      rw[← ev, list.length, ih.mp mv] },\n    { rcases list.mem_map.mp htt with ⟨v,⟨mv,ev⟩⟩,\n      rw[← ev, list.length, ih.mp mv] },\n    { intro mu,\n      cases u with b v,\n      {cases mu},\n      {cases b; rw[list.length] at mu; replace mu := nat.succ_inj'.mp mu;\n       let hu := ih.mpr mu,\n       { left , apply list.mem_map.mpr, use v, exact ⟨hu,rfl⟩ },\n       { right, apply list.mem_map.mpr, use v, exact ⟨hu,rfl⟩ } } } }\nend\n\nend enum_by_length\n\ndef elems_by_length (n : ℕ) : finset binseq := \n ⟨enum_by_length n,enum_by_length.nodup n⟩ \n\nnamespace elems_by_length\n\n/- @latex: prop-binseq -/\nlemma card (n : ℕ) : (elems_by_length n).card = 2 ^ n := \n  enum_by_length.length n\n\nlemma mem_iff {n : ℕ} {u : binseq} : u ∈ (elems_by_length n) ↔ u.length = n := \n  enum_by_length.mem_iff\n\ninstance (n : ℕ) : fintype { u : binseq // u.length = n } := \nfintype.of_finset (elems_by_length n) (@elems_by_length.mem_iff n)\n\nend elems_by_length\n\n/- @latex: prop-binseq -/\nlemma card_by_length (n : ℕ) : \n  fintype.card { u : binseq // u.length = n } = 2 ^ n := \n(fintype.card_of_finset (elems_by_length n) (@elems_by_length.mem_iff n)).trans\n (elems_by_length.card n)\n\nnamespace enum_by_length_and_rank\n\nlemma length : ∀ (n k : ℕ),\n (enum_by_length_and_rank n k).length = n.choose k :=\nbegin\n  intro n,\n  induction n with n ih_n,\n  { rintro ⟨_|k⟩; simp[enum_by_length_and_rank] },\n  { rintro ⟨_|k⟩; simp[enum_by_length_and_rank, nat.choose], \n    { rw[ih_n, nat.choose_zero_right] },\n    { rw[ih_n, ih_n, add_comm] } }\nend\n\nlemma nodup : forall (n k : ℕ) , (enum_by_length_and_rank n k).nodup := \nbegin\n  intro n,\n  induction n with n ih; rintro ⟨_|k⟩; rw[enum_by_length_and_rank],\n  { exact list.nodup_singleton _ },\n  { exact list.nodup_nil},\n  { have : function.injective (list.cons ff) := λ _ _ h, (list.cons_inj ff).mp h,\n    exact list.nodup.map list.cons_injective (ih 0) },\n  { rw[list.nodup_append], split,\n    { exact list.nodup.map list.cons_injective (ih (k + 1)) },\n    split,\n    { exact list.nodup.map list.cons_injective (ih k) },\n    { intros u hff htt,\n      rcases list.mem_map.mp hff with ⟨v,⟨mv,ev⟩⟩,\n      rcases list.mem_map.mp htt with ⟨w,⟨mw,ew⟩⟩,\n      injection (ev.trans ew.symm) with hb ht,\n      cases hb }\n  }\nend\n\nlemma mem_iff {n k : ℕ} {u : binseq} :\n u ∈ (enum_by_length_and_rank n k) ↔ u.length = n ∧ u.rank = k := \nbegin\n  have L : ∀ (u : binseq) (x y : bool) (l : list binseq), \n    x :: u ∈ l.map (list.cons y) ↔ x = y ∧ u ∈ l := \n  begin\n    intros u x y l,\n    rw[list.mem_map],\n    split; intro h,\n    { rcases h with ⟨v,⟨h_mem,h_eq⟩⟩,\n      injection h_eq with hxy hvu, \n      rw[← hvu],\n      exact ⟨hxy.symm,h_mem⟩ },\n    { use u, rw[h.left], exact ⟨h.right,rfl⟩ }\n  end,\n  revert n k,\n  induction u with b u ih,\n  { rintro ⟨_|n⟩ ⟨_|k⟩; simp [enum_by_length_and_rank, rank]; \n    intros; exact (nat.succ_ne_zero _).symm },\n  { rintro ⟨_|n⟩ ⟨_|k⟩; cases b; \n    simp only\n     [enum_by_length_and_rank, list.length, rank, L,\n      list.not_mem_nil, list.mem_singleton, list.mem_append,\n      nat.succ_ne_zero,\n      ih, nat.succ_inj', eq_self_iff_true,\n      true_and, false_and, and_false, false_or, or_false, iff_self]\n   }\nend\n\nend enum_by_length_and_rank\n\ndef elems_by_length_and_rank (n k : ℕ) : finset binseq := \n ⟨enum_by_length_and_rank n k,enum_by_length_and_rank.nodup n k⟩ \n\nnamespace elems_by_length_and_rank\n\n/- @latex: prop-binseq -/\nlemma card (n k : ℕ) : (elems_by_length_and_rank n k).card = n.choose k := \n  enum_by_length_and_rank.length n k\n\nlemma mem_iff {n k : ℕ} {u : binseq} : \n  u ∈ (elems_by_length_and_rank n k) ↔ u.length = n ∧ u.rank = k := \n  enum_by_length_and_rank.mem_iff\n\ninstance (n k : ℕ) : fintype { u : binseq // u.length = n ∧ u.rank = k } := \nfintype.of_finset (elems_by_length_and_rank n k)\n (@elems_by_length_and_rank.mem_iff n k)\n\nend elems_by_length_and_rank\n\nlemma card_by_length_and_rank (n k : ℕ) : \n  fintype.card { u : binseq // u.length = n ∧ u.rank = k } = n.choose k := \n(fintype.card_of_finset (elems_by_length_and_rank n k) \n  (@elems_by_length_and_rank.mem_iff n k)).trans\n (elems_by_length_and_rank.card n k)\n\ndef to_nat_list : ∀ (u : binseq), list ℕ \n| [] := [] \n| (ff :: u) := (to_nat_list u).map nat.succ\n| (tt :: u) := 0 :: ((to_nat_list u).map nat.succ)\n\nnamespace to_nat_list\n\nlemma length (u : binseq) : u.to_nat_list.length = u.rank := \nbegin\n  induction u with b u ih,\n  simp [to_nat_list, rank],\n  cases b; simp[to_nat_list, rank, ih]\nend\n\nlemma mem_iff {u : binseq} {i : ℕ} :\n i ∈ u.to_nat_list ↔ tt ∈ u.nth i := \nbegin\n  revert i,\n  induction u with b u ih,\n  { simp [to_nat_list], },\n  cases b; rintro ⟨_|i⟩ ; \n  rw [to_nat_list, list.nth],\n  { rw [option.mem_def, option.some_inj, list.mem_map],\n    { split, { rintro ⟨k,⟨h,⟨_⟩⟩⟩ }, { rintro ⟨_⟩ } } },\n  { rw [list.mem_map],\n    { split,\n     { rintro ⟨j,⟨hm,he⟩⟩, rw [nat.succ_inj'.mp he] at hm, exact ih.mp hm },\n     { intro h, use i, exact ⟨ih.mpr h,rfl⟩ } } },\n  { rw [option.mem_def, eq_self_iff_true, iff_true],\n    exact list.mem_cons_self _ _ },\n  { split, \n    { intro h, rw [list.mem_cons_iff] at h, rcases h with ⟨⟨_⟩|h⟩,\n      rcases list.mem_map.mp h with ⟨j,⟨hm,he⟩⟩,\n      rw [nat.succ_inj'.mp he] at hm, exact ih.mp hm },\n    { intro h, apply list.mem_cons_of_mem, apply list.mem_map_of_mem,\n      exact ih.mpr h } } \nend\n\nlemma bound (u : binseq) (i : ℕ) : i ∈ u.to_nat_list → i < u.length := \nbegin\n  revert i,\n  induction u with b u ih,\n  { simp [to_nat_list] },\n  { cases b; rintro ⟨_|i⟩; \n    simp only [to_nat_list, list.length, nat.zero_lt_succ, imp_true_iff],\n    { intro h, rcases list.mem_map.mp h with ⟨j,⟨hm,he⟩⟩,\n      rw [← he],\n      exact nat.succ_lt_succ (ih j hm) },\n    { intro h, rw[list.mem_cons_iff] at h,\n      rcases h with ⟨⟨_⟩|h⟩,\n      rcases list.mem_map.mp h with ⟨j,⟨hm,he⟩⟩,\n      rw [← he],\n      exact nat.succ_lt_succ (ih j hm) } }  \nend\n\nlemma sorted (u : binseq) : list.sorted has_lt.lt u.to_nat_list := \nbegin\n  induction u with b u ih,\n  { exact list.sorted_nil },\n  { have h : ((to_nat_list u).map nat.succ).sorted has_lt.lt := \n      list.pairwise.map nat.succ @nat.succ_lt_succ ih,\n    cases b; rw[to_nat_list],\n    { exact h },\n    { rw [list.sorted_cons], split,\n      { intros i hi, rcases list.mem_map.mp hi with ⟨j,⟨hm,he⟩⟩,\n        rw[← he], exact nat.zero_lt_succ _ },\n      { exact h } } }\nend\n\nlemma nodup (u : binseq) : u.to_nat_list.nodup := \nbegin\n  have h : ∀ i j : ℕ, i < j → i ≠ j := λ _ _ p, ne_of_lt p,\n  exact list.pairwise.imp h (sorted u)\nend\n\nend to_nat_list\n\ndef to_nat_finset (u : binseq) : finset ℕ := \n  ⟨to_nat_list u, to_nat_list.nodup u⟩\n\nnamespace to_nat_finset\n\nlemma card (u : binseq) : u.to_nat_finset.card = u.rank := \n  to_nat_list.length u\n\nlemma mem_iff {u : binseq} {i : ℕ} : i ∈ u.to_nat_finset ↔ tt ∈ (u.nth i) := \n  to_nat_list.mem_iff \n\nlemma bound (u : binseq) (i : ℕ) : i ∈ u.to_nat_finset → i < u.length := \n  to_nat_list.bound u i\n\nlemma nil : to_nat_finset list.nil = ∅ := \nbegin\n  apply finset.eq_empty_of_forall_not_mem, intro i,\n  rw [mem_iff, list.nth], exact option.not_mem_none tt\nend\n\nlemma ff_cons (u : binseq) :\n to_nat_finset (ff :: u) = (to_nat_finset u).map nat.succ_emb :=\nby { rw[to_nat_finset, to_nat_finset, finset.map], congr } \n\nlemma tt_cons (u : binseq) :\n to_nat_finset (tt :: u) = insert 0 ((to_nat_finset u).map nat.succ_emb) :=\nby { rw[to_nat_finset, to_nat_finset, finset.map],\n     congr, rw [to_nat_list], symmetry,\n     apply list.insert_neg, intro h,\n     rcases (list.mem_map.mp h) with ⟨i,⟨_,⟨_⟩⟩⟩ } \n\nlemma cons (b : bool) (u : binseq) : \n  to_nat_finset (b :: u) = \n    cond b (insert 0 ((to_nat_finset u).map nat.succ_emb)) \n           ((to_nat_finset u).map nat.succ_emb) := \nbegin\n  cases b; rw[cond], apply ff_cons, apply tt_cons\nend\n\nend to_nat_finset\n\ndef to_fin_list {n : ℕ} (u : binseq) (h : u.length = n) : list (fin n) := \nbegin\n  have hb : ∀ i : ℕ, i ∈ u.to_nat_list → i < n := \n    λ i hi, h ▸ (to_nat_list.bound u i hi),\n  exact list.pmap fin.mk u.to_nat_list hb\nend\n\nnamespace to_fin_list\n\nvariables {n : ℕ} (u : binseq) (h : u.length = n)\n\nlemma val : (u.to_fin_list h).map subtype.val = u.to_nat_list := \nbegin\n  rw[to_fin_list, list.map_pmap],\n  have : (λ (i : ℕ) (h : i < n), (fin.mk i h).val) = \n         (λ (i : ℕ) (h : i < n), id i) := \n    by { funext i h, refl },\n  rw [this, list.pmap_eq_map, list.map_id]\nend\n\nlemma length : (u.to_fin_list h).length = u.rank := \nby { rw[to_fin_list, list.length_pmap, to_nat_list.length u] }\n\nvariables {u h}\n\nlemma mem_iff {i : fin n} : \n  i ∈ u.to_fin_list h ↔ u.nth_le i.val (h.symm ▸ i.is_lt) = tt := \nbegin\n  have hi : i.val < u.length := h.symm ▸ i.is_lt,\n  have hn : u.nth i.val = some (u.nth_le i.val hi) := list.nth_le_nth _,\n  rw [to_fin_list, list.mem_pmap],\n  split,\n  { rintro ⟨j,⟨hj,he⟩⟩,\n    let ho := option.mem_def.mp (to_nat_list.mem_iff.mp hj),\n    have hv : i.val = j := by { rw[← he], refl },\n    rw [← hv] at ho,\n    rw [ho] at hn,\n    exact (option.some_inj.mp hn).symm },\n  { intro hv, rw[hv] at hn, use i.val,\n    use to_nat_list.mem_iff.mpr hn, apply fin.eq_of_veq, refl }\nend\n\nvariables (u h)\n\nlemma sorted : (u.to_fin_list h).sorted has_lt.lt := \nbegin\n  change list.pairwise _ _,\n  apply list.pairwise.pmap (to_nat_list.sorted u),\n  intros i hi j hj hij,\n  exact hij\nend\n\nlemma nodup : (u.to_fin_list h).nodup := \nbegin\n  have hp : ∀ i j : (fin n), i < j → i ≠ j := λ _ _ p, ne_of_lt p,\n  exact list.pairwise.imp hp (sorted u h)\nend\n\nend to_fin_list\n\ndef to_fin_finset {n : ℕ} (u : binseq) (h : u.length = n): finset (fin n) := \n  ⟨to_fin_list u h, to_fin_list.nodup u h⟩\n\nnamespace to_fin_finset\n\nvariables {n : ℕ} (u : binseq) (h : u.length = n)\n\nlemma val :\n  (to_fin_finset u h).map (fin.val_emb n) = to_nat_finset u := \nbegin\n  rw [to_fin_finset, finset.map, to_nat_finset, ← finset.val_inj],\n  simp only [multiset.coe_map, multiset.coe_eq_coe, list.map],\n  rw [← to_fin_list.val u h], refl\nend\n\nlemma card : (to_fin_finset u h).card = u.rank := \n  to_fin_list.length u h\n\nlemma mem_iff {i : fin n} : i ∈ (to_fin_finset u h) ↔ u.nth_le i.val (h.symm ▸ i.is_lt) = tt := \n  to_fin_list.mem_iff\n\nlemma nil (h : list.nil.length = 0) : to_fin_finset list.nil h = ∅ := rfl\n\nlemma ff_cons : \n  to_fin_finset (ff :: u) (by { rw[list.length, h] }) = \n   shift (to_fin_finset u h) :=\nbegin\n  have hi : ∀ (p : ℕ) (l m : list (fin p)), \n    l.map subtype.val = m.map subtype.val → l = m :=\n  begin\n    intros p l m e,\n    exact list.map_injective_iff.mpr\n      (λ (i j : fin p) (e₀ : i.val = j.val), fin.eq_of_veq e₀) e,\n  end,\n  rw [to_fin_finset, to_fin_finset], congr,\n  apply hi,\n  rw [to_fin_list.val, to_nat_list, list.map_map],\n  have : subtype.val ∘ (fin.succ_emb n) = \n         nat.succ ∘ subtype.val := \n  begin\n    ext ⟨i,hi⟩, unfold_coes, simp [fin.succ_emb]\n  end,\n  rw [this, ← list.map_map nat.succ subtype.val, to_fin_list.val]\nend\n\nlemma tt_cons : \n  to_fin_finset (tt :: u) (by { rw[list.length, h] }) = \n   insert (0 : fin n.succ) (shift (to_fin_finset u h)) :=\nbegin\n  have hi : ∀ (p : ℕ) (l m : list (fin p)), \n    l.map subtype.val = m.map subtype.val → l = m :=\n  begin\n    intros p l m e,\n    exact list.map_injective_iff.mpr\n      (λ (i j : fin p) (e₀ : i.val = j.val), fin.eq_of_veq e₀) e,\n  end,\n  rw [to_fin_finset, to_fin_finset], congr,\n  have hn : (0 : fin n.succ) ∉ (to_fin_list u h).map (fin.succ_emb n) := \n  begin\n    intro hm,\n    rcases list.mem_map.mp hm with ⟨i,⟨_,he⟩⟩,\n    exact fin.succ_ne_zero _ he,\n  end,\n  apply hi,\n  let hh := congr_arg (list.map subtype.val) (list.insert_of_not_mem hn),\n  rw [to_fin_list.val, to_nat_list], \n  have : (list.insert 0 (list.map ⇑(fin.succ_emb n) (to_fin_list u h))) = \n         (insert 0 (list.map ⇑(fin.succ_emb n) (to_fin_list u h))) := rfl,\n  rw [this, hh, list.map, list.map_map],\n  have : subtype.val ∘ (fin.succ_emb n) = \n         nat.succ ∘ subtype.val := \n  begin\n    ext ⟨i,hi⟩, unfold_coes, simp [fin.succ_emb]\n  end,\n  rw [this, ← list.map_map nat.succ subtype.val, to_fin_list.val],\n  have : (0 : fin n.succ).val = 0 := rfl,\n  rw [this],\nend\n\nlemma cons (b : bool) : \n  to_fin_finset (b :: u) (by { rw[list.length, h] }) =\n   let s := (shift (to_fin_finset u h)) in (cond b (insert 0 s) s) := \nbegin\n  cases b, apply ff_cons, apply tt_cons\nend\n\nend to_fin_finset\n\ndef of_fin_finset : ∀ {n : ℕ} (s : finset (fin n)), binseq \n| 0 _ := []\n| (n + 1) s :=\n  (if (0 : (fin n.succ)) ∈ s then tt else ff) :: \n          (of_fin_finset (unshift s))\n\nnamespace of_fin_finset\n\nlemma ff_step {n : ℕ} {s : finset (fin n.succ)} (h : (0 : fin n.succ) ∉ s) :\n  of_fin_finset s = ff :: (of_fin_finset (unshift s)) := \nby rw [of_fin_finset, if_neg h]\n\nlemma tt_step {n : ℕ} {s : finset (fin n.succ)} (h : (0 : fin n.succ) ∈ s) :\n  of_fin_finset s = tt :: (of_fin_finset (unshift s)) := \nby rw [of_fin_finset, if_pos h]\n\nlemma length {n : ℕ} (s : (finset (fin n))) : (of_fin_finset s).length = n :=\nbegin\n  induction n with n ih,\n  { rw [of_fin_finset, list.length ] },\n  { rw [of_fin_finset, list.length, ih] }\nend\n\nlemma rank {n : ℕ} (s : (finset (fin n))) : (of_fin_finset s).rank = s.card :=\nbegin\n  induction n with n ih,\n  { have : s = ∅ := finset.eq_empty_of_forall_not_mem (λ i, fin.elim0 i),\n    rw [of_fin_finset, rank, this, finset.card_empty] },\n  { rw [of_fin_finset], split_ifs; rw [rank],\n    { rw [ih (unshift s)], exact (unshift_card1 h).symm },\n    { rw [ih (unshift s)], exact (unshift_card0 h).symm } }\nend\n\nlemma shift {n : ℕ} (s : (finset (fin n))) :\n  of_fin_finset (combinatorics.shift s) = ff :: of_fin_finset s :=\nbegin\n  induction n with n ih,\n  { have : s = ∅ := finset.eq_empty_of_forall_not_mem (λ i, fin.elim0 i),\n    rw [this], refl },\n  { rw [of_fin_finset],\n    split_ifs,\n    { exfalso, exact zero_not_mem_shift s h },\n    { rw[unshift_shift] } }\nend\n\nlemma insert {n : ℕ} (s : (finset (fin n))) :\n  of_fin_finset (insert (0 : fin n.succ) (combinatorics.shift s)) = tt :: of_fin_finset s :=\nbegin\n  induction n with n ih,\n  { have : s = ∅ := finset.eq_empty_of_forall_not_mem (λ i, fin.elim0 i),\n    rw [this], refl },\n  { rw [of_fin_finset],\n    split_ifs,\n    { rw[unshift_insert, unshift_shift], },\n    { exfalso, exact h (finset.mem_insert_self _ _) } }\nend\n\nend of_fin_finset\n\nlemma of_to_fin_finset {n : ℕ} (u : binseq) (h : u.length = n) : \n  of_fin_finset (to_fin_finset u h) = u := \nbegin\n  revert u,\n  induction n with n ih,\n  { intro u, cases u with b u, \n    { intro h, refl },\n    { intro h, exfalso, exact nat.succ_ne_zero u.length h } },\n  { intro u, cases u with b u,\n    { intro h, exfalso, exact nat.succ_ne_zero n h.symm },\n    { intro h, have hl := nat.succ_inj'.mp h, \n      cases b,\n      { rw [to_fin_finset.ff_cons u hl, of_fin_finset.shift, ih u hl] },\n      { rw [to_fin_finset.tt_cons u hl, of_fin_finset.insert, ih u hl] } } }\nend\n\nlemma to_of_fin_finset {n : ℕ} (s : finset (fin n)) :\n  to_fin_finset (of_fin_finset s) (of_fin_finset.length s) = s := \nbegin\n  induction n with n ih,\n  { have : s = ∅ := finset.eq_empty_of_forall_not_mem (λ i, fin.elim0 i),\n    rw [this], refl },\n  { have he : ∀ (u₀ u₁ : binseq) (h₀ : u₀.length = n.succ) (e : u₀ = u₁),  \n      to_fin_finset u₀ h₀ = \n      to_fin_finset u₁ ((congr_arg list.length e).symm.trans h₀) := \n    by { intros, cases e, refl },\n    let t := unshift s,\n    by_cases h : (0 : fin n.succ) ∈ s,\n    { have : s = insert (0 : fin n.succ) (shift t) := (shift_unshift1 s h).symm,\n      rw [this] at *,\n      have ht := of_fin_finset.insert t,  \n      have hf := he (of_fin_finset (insert (0 : fin n.succ) (shift t)))\n        (tt :: of_fin_finset t) _ ht,\n      let hc := to_fin_finset.tt_cons (of_fin_finset t) (of_fin_finset.length t),\n      rw [hf, hc, ih t] },\n    { have : s = shift t := (shift_unshift0 s h).symm, \n      rw [this] at *,\n      have ht := of_fin_finset.shift t,\n      have hf := he (of_fin_finset (shift t))\n        (ff :: of_fin_finset t) _ ht,\n      let hc := to_fin_finset.ff_cons (of_fin_finset t) (of_fin_finset.length t),\n      rw [hf, hc, ih t] } }\nend\n\ndef finset_equiv (n k : ℕ) : \n { u : binseq // u.length = n ∧ u.rank = k } ≃ \n { s : finset (fin n) // s.card = k } := \n { to_fun    := λ u, ⟨to_fin_finset u.val u.property.left,\n                     (to_fin_finset.card u.val u.property.left).trans\n                      u.property.right⟩,\n   inv_fun   := λ s, ⟨\n    of_fin_finset s.val,\n    ⟨of_fin_finset.length s.val,(of_fin_finset.rank s.val).trans s.property⟩⟩,\n  left_inv  := λ u, subtype.eq (of_to_fin_finset u.val u.property.left),\n  right_inv := λ s, subtype.eq (to_of_fin_finset s.val) }\n\n\nend binseq\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/binseq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7642272540382705}}
{"text": "import data.int.gcd\nimport data.list.zip\nopen int (hiding gcd_a gcd_b gcd_eq_gcd_ab) (hiding mul_neg_eq_neg_mul_symm) euclidean_domain list\n\nlemma zip_with_mul_map_mul_right {α : Type*} [comm_ring α] (l₁ l₂ : list α) (r : α) :\n\tzip_with (*) l₁ (l₂.map ((*) r)) = (zip_with (*) l₁ l₂).map ((*) r) :=\nbegin\n\tinduction l₁ with x₁ tl₁ ih₁ generalizing l₂, { simp },\n\tinduction l₂ with x₂ tl₂ ih₂, { simp },\n\tsimp, split,\n\t{\trw mul_left_comm },\n\texact ih₁ tl₂,\nend\n\n/- Given a list of integers x₁,...,xₙ, it produces a list of integers a₁,...,aₙ such that\nx₁ * a₁ + ⋯ + xₙ * aₙ = gcd (x₁,...,xₙ). -/\ndef bezout_factors : list ℤ → list ℤ\n| []        := []\n| (x :: tl) := let g := tl.foldr gcd 0 in\n  gcd_a x g :: (bezout_factors tl).map ((*) (gcd_b x g))\n\nlemma bezout_eq_gcd : Π (l : list ℤ), (l.zip_with (*) (bezout_factors l)).sum = l.foldr gcd 0\n| []        := by simp\n| (x :: tl) := begin\n\tsimp [bezout_factors, zip_with_mul_map_mul_right, sum_map_mul_left],\n\tshow _ + _ * (map id _).sum = _,\n\trw [map_id, bezout_eq_gcd tl, gcd_eq_gcd_ab, mul_comm (gcd_b _ _)],\nend\n\n#eval bezout_factors [-20, -15, -12]\n#eval (zip_with (*) [-20, -15, -12] (bezout_factors [-20, -15, -12])).sum\n\nlemma int.eq_gcd_iff (a b : ℤ) (n : ℕ) :\n\ta.gcd b = n ↔ ↑n ∣ a ∧ ↑n ∣ b ∧ ∀ m, m ∣ a → m ∣ b → m ∣ ↑n :=\nbegin\n\tsplit,\n\t{\trintro rfl, use [gcd_dvd_left a b, gcd_dvd_right a b],\n\t\tintros m hma hmb, apply int.dvd_gcd hma hmb },\n\trintro ⟨hna, hnb, hm⟩,\n\tapply nat.dvd_antisymm,\n\t{\trw ← int.coe_nat_dvd,\n\t\tapply hm, exact gcd_dvd_left a b, exact gcd_dvd_right a b },\n\trw ← int.coe_nat_dvd,\n\tapply int.dvd_gcd hna hnb,\nend\n\nlemma int.gcd_add_mul_self (m n k : ℤ) : m.gcd (n + k * m) = m.gcd n :=\nbegin\n\trw int.eq_gcd_iff,\n\tuse gcd_dvd_left m n, split,\n\t{\tapply dvd_add, exact gcd_dvd_right m n,\n\t\tapply dvd_mul_of_dvd_right, exact gcd_dvd_left m n },\n\tintros a ham han,\n\tapply int.dvd_gcd ham,\n\thave hakm : a ∣ k * m := dvd_mul_of_dvd_right ham k,\n\trwa ← dvd_add_left hakm,\nend\n\nlemma int.gcd_mod (a b : ℤ) : int.gcd a b = int.gcd (b % a) a :=\nby rw [gcd_comm _ a, int.mod_def, sub_eq_add_neg, neg_mul_eq_mul_neg,\n\tmul_comm a, int.gcd_add_mul_self]\n\nlemma int.gcd_eq_abs_gcd (a b : ℤ) : int.gcd a b = (euclidean_domain.gcd a b).nat_abs :=\ngcd.induction a b (λ x, by simp) (λ a b ha ih, by rw [gcd_val, ← ih, int.gcd_mod])\n\ndef abs_bezout_factors : list ℤ → list ℤ :=\nλ l, ite (0 ≤ l.foldr gcd 0) (bezout_factors l) ((bezout_factors l).map int.neg)\n\nlemma zip_with_mul_map_neg (l₁ l₂ : list ℤ) :\n\tzip_with (*) l₁ (l₂.map int.neg) = (zip_with (*) l₁ l₂).map int.neg :=\nbegin\n\tinduction l₁ with x₁ tl₁ ih₁ generalizing l₂, { simp },\n\tinduction l₂ with x₂ tl₂ ih₂, { simp },\n\tsimp, split,\n\t{\tchange _ * -_ = -_, rw [mul_neg_eq_neg_mul_symm] },\n\texact ih₁ tl₂,\nend\n\ntheorem abs_bezout_eq_gcd (l : list ℤ) :\n\t(l.zip_with (*) (abs_bezout_factors l)).sum = abs (l.foldr gcd 0) :=\nbegin\n\tsimp [abs_bezout_factors],\n\tsplit_ifs,\n\t{\trw [bezout_eq_gcd, abs_of_nonneg h] },\n\trw zip_with_mul_map_neg,\n\tconv in (int.neg) {change λ x : ℤ, -x},\n\trw [← sum_neg, abs_of_neg (lt_of_not_ge h), bezout_eq_gcd],\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/bezout.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7642272420787057}}
{"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.category.Top\nimport topology.algebra.monoid\n\n\n\n/-!\n# Some lemma about injective group homomorphisms\n\n\n## Main Statement\n\n- `iso_range_of_injective` : For an injective group homomorphism, \n    the domain is iśomorphic to its range.\n\n\n## Tags \n\n-/\n\nlemma iso_range_of_injective_inverse_ex \n  {G H:Type*} [group G] [group H]\n  (i : H →* G)\n  : ∀ (x: i.range), ∃ h : H, i h = x\n:= begin \n  assume x,\n  rw ← monoid_hom.mem_range,\n  by refine set_like.coe_mem x,\nend \n\nnoncomputable def iso_range_of_injective_inverse \n  {G H:Type*} [group G] [group H]\n  (i : H →* G)\n  : i.range → H \n:= (λ x, classical.some (iso_range_of_injective_inverse_ex i x))\n\n@[simp]\nlemma iso_range_of_injective_inverse_spec \n  {G H:Type*} [group G] [group H]\n  (i : H →* G)\n  : ∀ x, i (iso_range_of_injective_inverse i x) = x \n:= begin \n  assume x,\n  unfold iso_range_of_injective_inverse,\n  exact classical.some_spec (iso_range_of_injective_inverse_ex i x),\nend \n\n@[simp]\nlemma iso_range_of_injective_inverse_spec' \n  {G H:Type*} [group G] [group H]\n  (i : H →* G)\n  : ∀ x, i.range_restrict (iso_range_of_injective_inverse i x) = x \n:= begin \n  assume x,\n  rw ← set_like.coe_eq_coe,\n  exact  iso_range_of_injective_inverse_spec i x,\nend \n\n/-- If G → H is a monoid homomorphism between groups, \n    then G is isomorphic (as monoid) to the range-/\nnoncomputable lemma iso_range_of_injective \n  {G H:Type*} [group G] [group H]\n  {i : H →* G}\n  (i_inj : function.injective i)\n  : H ≃* i.range \n:= mul_equiv.mk i.range_restrict (iso_range_of_injective_inverse i)\n  (begin \n    unfold function.left_inverse,\n    assume x,\n    apply i_inj,\n    rw iso_range_of_injective_inverse_spec,\n    simp,\n  end)\n  (begin\n    unfold function.right_inverse, \n    unfold function.left_inverse,\n    assume x,\n    simp,\n  end )\n  (begin \n    assume x y,\n    simp,\n  end)\n\n  noncomputable lemma iso_range_of_injective' \n  {G H:Type*} [group G] [group H]\n  {i : H →* G}\n  (i_inj : function.injective i)\n  : i.range ≃* H  \n:= (iso_range_of_injective i_inj).symm \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/aux_lemmas_iso_range.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7642167946027586}}
{"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 : ℕ) : finset (ℕ × ℕ) :=\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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ prod.fst x + prod.snd x = n := sorry\n\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp] theorem card_antidiagonal (n : ℕ) : 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) :=\n  rfl\n\ntheorem antidiagonal_succ {n : ℕ} : antidiagonal (n + 1) =\n  insert (0, n + 1)\n    (map (function.embedding.prod_map (function.embedding.mk Nat.succ nat.succ_injective) (function.embedding.refl ℕ))\n      (antidiagonal n)) := sorry\n\ntheorem map_swap_antidiagonal {n : ℕ} : map (function.embedding.mk prod.swap (function.right_inverse.injective prod.swap_right_inverse)) (antidiagonal n) =\n  antidiagonal 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/data/finset/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7642167829147792}}
{"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.nat.parity\nimport data.zmod.basic\n/-!\n# Relating parity to natural numbers mod 2\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\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\nlemma eq_zero_iff_even {n : ℕ} : (n : zmod 2) = 0 ↔ even n :=\n(char_p.cast_eq_zero_iff (zmod 2) 2 n).trans even_iff_two_dvd.symm\n\nlemma eq_one_iff_odd {n : ℕ} : (n : zmod 2) = 1 ↔ odd n :=\nby { rw [← @nat.cast_one (zmod 2), zmod.eq_iff_modeq_nat, nat.odd_iff, nat.modeq], norm_num }\n\n\n\nend zmod\n", "meta": {"author": "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/zmod/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218262741297, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7642167761411871}}
{"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 tactic.noncomm_ring\nimport field_theory.is_alg_closed.basic\nimport algebra.star.pointwise\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 → A`: the resolvent function is `λ r, ring.inverse (↑ₐr - a)`, and hence\n  when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - 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 `σ (a*b)` coincide with those in `σ (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* `σ a` : `spectrum R a` of `a : A`\n-/\n\nopen set\n\nuniverses u v\n\nsection defs\n\nvariables (R : Type u) {A : Type v}\nvariables [comm_semiring R] [ring A] [algebra R A]\n\nlocal notation `↑ₐ` := algebra_map R A\n\n-- definition and basic properties\n\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•1 - a` is a unit of the\nalgebra `A`.  -/\ndef resolvent_set (a : A) : set R :=\n{ r : R | is_unit (↑ₐr - a) }\n\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•1 - 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(resolvent_set R a)ᶜ\n\nvariable {R}\n/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is\n    a map `R → A` which sends `r : R` to `(algebra_map R A r - a)⁻¹` when\n    `r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/\nnoncomputable def resolvent (a : A) (r : R) : A :=\nring.inverse (↑ₐr - a)\n\n/-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/\n@[simps]\nnoncomputable def is_unit.sub_inv_smul {r : Rˣ} {s : R} {a : A}\n  (h : is_unit $ r • ↑ₐs  - a) : Aˣ :=\n{ val := ↑ₐs - r⁻¹ • a,\n  inv := r • ↑h.unit⁻¹,\n  val_inv := by rw [mul_smul_comm, ←smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_coe_inv],\n  inv_val := by rw [smul_mul_assoc, ←mul_smul_comm, smul_sub, smul_inv_smul, h.coe_inv_mul], }\n\nend defs\n\nnamespace spectrum\nopen_locale polynomial\n\nsection scalar_semiring\n\nvariables {R : Type u} {A : Type v}\nvariables [comm_semiring R] [ring A] [algebra R A]\n\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma mem_iff {r : R} {a : A} :\n  r ∈ σ a ↔ ¬ is_unit (↑ₐr - a) :=\niff.rfl\n\nlemma not_mem_iff {r : R} {a : A} :\n  r ∉ σ a ↔ is_unit (↑ₐr - a) :=\nby { apply not_iff_not.mp, simp [set.not_not_mem, mem_iff] }\n\nlemma mem_resolvent_set_of_left_right_inverse {r : R} {a b c : A}\n  (h₁ : (↑ₐr - a) * b = 1) (h₂ : c * (↑ₐr - a) = 1) :\n  r ∈ resolvent_set R a :=\nunits.is_unit ⟨↑ₐr - a, b, h₁, by rwa ←left_inv_eq_right_inv h₂ h₁⟩\n\nlemma mem_resolvent_set_iff {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (↑ₐr - a) :=\niff.rfl\n\n@[simp] lemma resolvent_set_of_subsingleton [subsingleton A] (a : A) :\n  resolvent_set R a = set.univ :=\nby simp_rw [resolvent_set, subsingleton.elim (algebra_map R A _ - a) 1, is_unit_one,\n  set.set_of_true]\n\n@[simp] lemma of_subsingleton [subsingleton A] (a : A) :\n  spectrum R a = ∅ :=\nby rw [spectrum, resolvent_set_of_subsingleton, set.compl_univ]\n\nlemma resolvent_eq {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  resolvent a r = ↑h.unit⁻¹ :=\nring.inverse_unit h.unit\n\nlemma units_smul_resolvent {r : Rˣ} {s : R} {a : A} :\n  r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) :=\nbegin\n  by_cases h : s ∈ spectrum R a,\n  { rw [mem_iff] at h,\n    simp only [resolvent, algebra.algebra_map_eq_smul_one] at *,\n    rw [smul_assoc, ←smul_sub],\n    have h' : ¬ is_unit (r⁻¹ • (s • 1 - a)),\n      from λ hu, h (by simpa only [smul_inv_smul] using is_unit.smul r hu),\n    simp only [ring.inverse_non_unit _ h, ring.inverse_non_unit _ h', smul_zero] },\n  { simp only [resolvent],\n    have h' : is_unit (r • (algebra_map R A (r⁻¹ • s)) - a),\n      { simpa [algebra.algebra_map_eq_smul_one, smul_assoc] using not_mem_iff.mp h },\n    rw [←h'.coe_sub_inv_smul, ←(not_mem_iff.mp h).unit_spec, ring.inverse_unit, ring.inverse_unit,\n      h'.coe_inv_sub_inv_smul],\n    simp only [algebra.algebra_map_eq_smul_one, smul_assoc, smul_inv_smul], },\nend\n\nlemma units_smul_resolvent_self {r : Rˣ} {a : A} :\n  r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) :=\nby simpa only [units.smul_def, algebra.id.smul_eq_mul, units.inv_mul]\n  using @units_smul_resolvent _ _ _ _ _ r r a\n\n/-- The resolvent is a unit when the argument is in the resolvent set. -/\nlemma is_unit_resolvent {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (resolvent a r) :=\nis_unit_ring_inverse.symm\n\nlemma inv_mem_resolvent_set {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolvent_set R (a : A)) :\n  (↑r⁻¹ : R) ∈ resolvent_set R (↑a⁻¹ : A) :=\nbegin\n  rw [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one, ←units.smul_def] at h ⊢,\n  rw [is_unit.smul_sub_iff_sub_inv_smul, inv_inv, is_unit.sub_iff],\n  have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • 1 - a,\n  { rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one], },\n  have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • 1 - a,\n  { rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul], },\n  have hcomm : commute (a : A) (r • (↑a⁻¹ : A) - 1), { rwa ←h₂ at h₁ },\n  exact (hcomm.is_unit_mul_iff.mp (h₁.symm ▸ h)).2,\nend\n\nlemma inv_mem_iff {r : Rˣ} {a : Aˣ} :\n  (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) :=\nbegin\n  simp only [mem_iff, not_iff_not, ←mem_resolvent_set_iff],\n  exact ⟨λ h, inv_mem_resolvent_set h, λ h, by simpa using inv_mem_resolvent_set h⟩,\nend\n\nlemma zero_mem_resolvent_set_of_unit (a : Aˣ) : 0 ∈ resolvent_set R (a : A) :=\nby { rw [mem_resolvent_set_iff, is_unit.sub_iff], simp }\n\nlemma ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 :=\nλ hn, (hn ▸ hr) (zero_mem_resolvent_set_of_unit a)\n\nlemma add_mem_iff {a : A} {r s : R} :\n  r ∈ σ a ↔ r + s ∈ σ (↑ₐs + a) :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff],\n  have h_eq : ↑ₐ(r + s) - (↑ₐs + a) = ↑ₐr - a,\n    { simp, noncomm_ring },\n  rw h_eq,\nend\n\nlemma smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} :\n  r • s ∈ σ (r • a) ↔ s ∈ σ a :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one],\n  have h_eq : (r • s) • (1 : A) = r • s • 1, by simp,\n  rw [h_eq, ←smul_sub, is_unit_smul_iff],\nend\n\nopen_locale pointwise polynomial\n\ntheorem unit_smul_eq_smul (a : A) (r : Rˣ) :\n  σ (r • a) = r • σ a :=\nbegin\n  ext,\n  have x_eq : x = r • r⁻¹ • x, by simp,\n  nth_rewrite 0 x_eq,\n  rw smul_mem_smul_iff,\n  split,\n    { exact λ h, ⟨r⁻¹ • x, ⟨h, by simp⟩⟩},\n    { rintros ⟨_, _, x'_eq⟩, simpa [←x'_eq],}\nend\n\n-- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ`\ntheorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : Rˣ} :\n  ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one],\n  have coe_smul_eq : ↑r • 1 = r • (1 : A), from rfl,\n  rw coe_smul_eq,\n  simp only [is_unit.smul_sub_iff_sub_inv_smul],\n  have right_inv_of_swap : ∀ {x y z : A} (h : (1 - x * y) * z = 1),\n    (1 - y * x) * (1 + y * z * x) = 1, from λ x y z h,\n      calc (1 - y * x) * (1 + y * z * x) = 1 - y * x + y * ((1 - x * y) * z) * x : by noncomm_ring\n      ...                                = 1                                     : by simp [h],\n  have left_inv_of_swap : ∀ {x y z : A} (h : z * (1 - x * y) = 1),\n    (1 + y * z * x) * (1 - y * x) = 1, from λ x y z h,\n      calc (1 + y * z * x) * (1 - y * x) = 1 - y * x + y * (z * (1 - x * y)) * x : by noncomm_ring\n      ...                                = 1                                     : by simp [h],\n  have is_unit_one_sub_mul_of_swap : ∀ {x y : A} (h : is_unit (1 - x * y)),\n    is_unit (1 - y * x), from λ x y h, by\n      { let h₁ := right_inv_of_swap h.unit.val_inv,\n        let h₂ := left_inv_of_swap h.unit.inv_val,\n        exact ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, h₁, h₂⟩, rfl⟩, },\n  have is_unit_one_sub_mul_iff_swap : ∀ {x y : A},\n    is_unit (1 - x * y) ↔ is_unit (1 - y * x), by\n      { intros, split, repeat {apply is_unit_one_sub_mul_of_swap}, },\n  rw [←smul_mul_assoc, ←mul_smul_comm r⁻¹ b a, is_unit_one_sub_mul_iff_swap],\nend\n\ntheorem preimage_units_mul_eq_swap_mul {a b : A} :\n  (coe : Rˣ → R) ⁻¹' σ (a * b) = coe ⁻¹'  σ (b * a) :=\nby { ext, exact unit_mem_mul_iff_mem_swap_mul, }\n\nsection star\n\nvariables [has_involutive_star R] [star_ring A] [star_module R A]\n\nlemma star_mem_resolvent_set_iff {r : R} {a : A} :\n  star r ∈ resolvent_set R a ↔ r ∈ resolvent_set R (star a) :=\nby refine ⟨λ h, _, λ h, _⟩;\n   simpa only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one, star_sub, star_smul,\n     star_star, star_one] using is_unit.star h\n\nprotected lemma map_star (a : A) : σ (star a) = star (σ a) :=\nby { ext, simpa only [set.mem_star, mem_iff, not_iff_not] using star_mem_resolvent_set_iff.symm }\n\nend star\n\nend scalar_semiring\n\nsection scalar_ring\n\nvariables {R : Type u} {A : Type v}\nvariables [comm_ring R] [ring A] [algebra R A]\n\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\ntheorem left_add_coset_eq (a : A) (r : R) :\n  left_add_coset r (σ a) = σ (↑ₐr + a) :=\nby { ext, rw [mem_left_add_coset_iff, neg_add_eq_sub, add_mem_iff],\n     nth_rewrite 1 ←sub_add_cancel x r, }\n\nopen polynomial\n\nlemma exists_mem_of_not_is_unit_aeval_prod [is_domain R] {p : R[X]} {a : A} (hp : p ≠ 0)\n  (h : ¬is_unit (aeval a (multiset.map (λ (x : R), X - C x) p.roots).prod)) :\n  ∃ k : R, k ∈ σ a ∧ eval k p = 0 :=\nbegin\n  rw [←multiset.prod_to_list, alg_hom.map_list_prod] at h,\n  replace h := mt list.prod_is_unit h,\n  simp only [not_forall, exists_prop, aeval_C, multiset.mem_to_list,\n    list.mem_map, aeval_X, exists_exists_and_eq_and, multiset.mem_map, alg_hom.map_sub] at h,\n  rcases h with ⟨r, r_mem, r_nu⟩,\n  exact ⟨r, by rwa [mem_iff, ←is_unit.sub_iff], by rwa [←is_root.def, ←mem_roots hp]⟩\nend\n\nend scalar_ring\n\nsection scalar_field\n\nvariables {𝕜 : Type u} {A : Type v}\nvariables [field 𝕜] [ring A] [algebra 𝕜 A]\n\nlocal notation `σ` := spectrum 𝕜\nlocal notation `↑ₐ` := algebra_map 𝕜 A\n\n/-- Without the assumption `nontrivial A`, then `0 : A` would be invertible. -/\n@[simp] lemma zero_eq [nontrivial A] : σ (0 : A) = {0} :=\nbegin\n  refine set.subset.antisymm _ (by simp [algebra.algebra_map_eq_smul_one, mem_iff]),\n  rw [spectrum, set.compl_subset_comm],\n  intros k hk,\n  rw set.mem_compl_singleton_iff at hk,\n  have : is_unit (units.mk0 k hk • (1 : A)) := is_unit.smul (units.mk0 k hk) is_unit_one,\n  simpa [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one]\nend\n\n@[simp] theorem scalar_eq [nontrivial A] (k : 𝕜) : σ (↑ₐk) = {k} :=\nbegin\n  have coset_eq : left_add_coset k {0} = {k}, by\n    { ext, split,\n      { intro hx, simp [left_add_coset] at hx, exact hx, },\n      { intro hx, simp at hx, exact ⟨0, ⟨set.mem_singleton 0, by simp [hx]⟩⟩, }, },\n  calc σ (↑ₐk) = σ (↑ₐk + 0)                  : by simp\n    ...        = left_add_coset k (σ (0 : A)) : by rw ←left_add_coset_eq\n    ...        = left_add_coset k {0}         : by rw zero_eq\n    ...        = {k}                          : coset_eq,\nend\n\n@[simp] lemma one_eq [nontrivial A] : σ (1 : A) = {1} :=\ncalc σ (1 : A) = σ (↑ₐ1) : by simp [algebra.algebra_map_eq_smul_one]\n  ...          = {1}     : scalar_eq 1\n\nopen_locale pointwise\n\n/-- the assumption `(σ a).nonempty` is necessary and cannot be removed without\n    further conditions on the algebra `A` and scalar field `𝕜`. -/\ntheorem smul_eq_smul [nontrivial A] (k : 𝕜) (a : A) (ha : (σ a).nonempty) :\n  σ (k • a) = k • (σ a) :=\nbegin\n  rcases eq_or_ne k 0 with rfl | h,\n  { simpa [ha, zero_smul_set] },\n  { exact unit_smul_eq_smul a (units.mk0 k h) },\nend\n\ntheorem nonzero_mul_eq_swap_mul (a b : A) : σ (a * b) \\ {0} = σ (b * a) \\ {0} :=\nbegin\n  suffices h : ∀ (x y : A), σ (x * y) \\ {0} ⊆ σ (y * x) \\ {0},\n  { exact set.eq_of_subset_of_subset (h a b) (h b a) },\n  { rintros _ _ k ⟨k_mem, k_neq⟩,\n    change k with ↑(units.mk0 k k_neq) at k_mem,\n    exact ⟨unit_mem_mul_iff_mem_swap_mul.mp k_mem, k_neq⟩ },\nend\n\nprotected lemma map_inv (a : Aˣ) : (σ (a : A))⁻¹ = σ (↑a⁻¹ : A) :=\nbegin\n  refine set.eq_of_subset_of_subset (λ k hk, _) (λ k hk, _),\n  { rw set.mem_inv at hk,\n    have : k ≠ 0,\n    { simpa only [inv_inv] using inv_ne_zero (ne_zero_of_mem_of_unit hk), },\n    lift k to 𝕜ˣ using is_unit_iff_ne_zero.mpr this,\n    rw ←units.coe_inv k at hk,\n    exact inv_mem_iff.mp hk },\n  { lift k to 𝕜ˣ using is_unit_iff_ne_zero.mpr (ne_zero_of_mem_of_unit hk),\n    simpa only [units.coe_inv] using inv_mem_iff.mp hk, }\nend\n\nopen polynomial\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. -/\n\n\n/-- The *spectral mapping theorem* for polynomials.  Note: the assumption `degree p > 0`\nis necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side,\nassuming `[nontrivial A]`, is `{k}` where `p = polynomial.C k`. -/\ntheorem map_polynomial_aeval_of_degree_pos [is_alg_closed 𝕜] (a : A) (p : 𝕜[X])\n  (hdeg : 0 < degree p) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  /- handle the easy direction via `spectrum.subset_polynomial_aeval` -/\n  refine set.eq_of_subset_of_subset (λ k hk, _) (subset_polynomial_aeval a p),\n  /- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`. -/\n  have hprod := eq_prod_roots_of_splits_id (is_alg_closed.splits (C k - p)),\n  have h_ne : C k - p ≠ 0, from 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 (↑ₐ).to_monoid_hom (units.mk0 _ lead_ne)).is_unit,\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) = ↑ₐk - aeval a p,\n    by simp only [aeval_C, alg_hom.map_sub, sub_left_inj],\n  rw [mem_iff, ←p_a_eq, hprod, aeval_mul,\n    ((commute.all _ _).map (aeval a)).is_unit_mul_iff, 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 ⟨r, r_mem, r_ev⟩,\n  exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩,\nend\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. Note: the\nassumption `[nontrivial A]` is necessary for the same reason as in `spectrum.zero_eq`. -/\ntheorem map_polynomial_aeval_of_nonempty [is_alg_closed 𝕜] [nontrivial A] (a : A) (p : 𝕜[X])\n  (hnon : (σ a).nonempty) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  refine or.elim (le_or_gt (degree p) 0) (λ h, _) (map_polynomial_aeval_of_degree_pos a p),\n  { 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] },\nend\n\nvariable (𝕜)\n/--\nEvery element `a` in a nontrivial finite-dimensional algebra `A`\nover an algebraically closed field `𝕜` has non-empty spectrum. -/\n-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.\nlemma nonempty_of_is_alg_closed_of_finite_dimensional [is_alg_closed 𝕜]\n  [nontrivial A] [I : finite_dimensional 𝕜 A] (a : A) :\n  ∃ k : 𝕜, k ∈ σ a :=\nbegin\n  obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := is_integral_of_noetherian (is_noetherian.iff_fg.2 I) a,\n  have nu : ¬ is_unit (aeval a p), { rw [←aeval_def] at h_eval_p, rw h_eval_p, simp, },\n  rw [eq_prod_roots_of_monic_of_splits_id h_mon (is_alg_closed.splits p)] at nu,\n  obtain ⟨k, hk, _⟩ := exists_mem_of_not_is_unit_aeval_prod (monic.ne_zero h_mon) nu,\n  exact ⟨k, hk⟩\nend\n\nend scalar_field\n\nend spectrum\n\nnamespace alg_hom\n\nsection comm_semiring\n\nvariables {R : Type*} {A B : Type*} [comm_ring R] [ring A] [algebra R A] [ring B] [algebra R B]\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma mem_resolvent_set_apply (φ : A →ₐ[R] B) {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  r ∈ resolvent_set R (φ a) :=\nby simpa only [map_sub, commutes] using h.map φ\n\nlemma spectrum_apply_subset (φ : A →ₐ[R] B) (a : A) : σ (φ a) ⊆ σ a :=\nλ _, mt (mem_resolvent_set_apply φ)\n\nend comm_semiring\n\nsection comm_ring\n\nvariables {R : Type*} {A B : Type*} [comm_ring R] [ring A] [algebra R A] [ring B] [algebra R B]\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma apply_mem_spectrum [nontrivial R] (φ : A →ₐ[R] R) (a : A) : φ a ∈ σ a :=\nbegin\n  have h : ↑ₐ(φ a) - a ∈ φ.to_ring_hom.ker,\n  { simp only [ring_hom.mem_ker, coe_to_ring_hom, commutes, algebra.id.map_eq_id,\n               to_ring_hom_eq_coe, ring_hom.id_apply, sub_self, map_sub] },\n  simp only [spectrum.mem_iff, ←mem_nonunits_iff,\n             coe_subset_nonunits (φ.to_ring_hom.ker_ne_top) h],\nend\n\nend comm_ring\n\nend alg_hom\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/algebra/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7641349063340921}}
{"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ölzl\n\n! This file was ported from Lean 3 source module dynamics.fixed_points.topology\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.Dynamics.FixedPoints.Basic\nimport Mathlib.Topology.Separation\n\n/-!\n# Topological properties of fixed points\n\nCurrently this file contains two lemmas:\n\n- `isFixedPt_of_tendsto_iterate`: if `f^n(x) → y` and `f` is continuous at `y`, then `f y = y`;\n- `isClosed_fixedPoints`: the set of fixed points of a continuous map is a closed set.\n\n## TODO\n\nfixed points, iterates\n-/\n\n\nvariable {α : Type _} [TopologicalSpace α] [T2Space α] {f : α → α}\n\nopen Function Filter\n\nopen 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`. -/\ntheorem isFixedPt_of_tendsto_iterate {x y : α} (hy : Tendsto (fun n => (f^[n]) x) atTop (𝓝 y))\n    (hf : ContinuousAt f y) : IsFixedPt f y := by\n  refine' tendsto_nhds_unique ((tendsto_add_atTop_iff_nat 1).1 _) hy\n  simp only [iterate_succ' f]\n  exact hf.tendsto.comp hy\n#align is_fixed_pt_of_tendsto_iterate isFixedPt_of_tendsto_iterate\n\n/-- The set of fixed points of a continuous map is a closed set. -/\ntheorem isClosed_fixedPoints (hf : Continuous f) : IsClosed (fixedPoints f) :=\n  isClosed_eq hf continuous_id\n#align is_closed_fixed_points isClosed_fixedPoints\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/Dynamics/FixedPoints/Topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7641349006234596}}
{"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) :\n    finsupp.support (erase_lead f) = finset.erase (finsupp.support f) (nat_degree f) :=\n  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 : ℕ) :\n    coeff (erase_lead f) i = ite (i = nat_degree f) 0 (coeff f i) :=\n  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} :\n    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 : ℕ)\n    (hi : i ≠ 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]\n    (f : polynomial R) : erase_lead f + coe_fn (monomial (nat_degree f)) (leading_coeff f) = f :=\n  sorry\n\n@[simp] theorem erase_lead_add_C_mul_X_pow {R : Type u_1} [semiring R] (f : polynomial R) :\n    erase_lead f + coe_fn C (leading_coeff f) * X ^ nat_degree f = f :=\n  sorry\n\n@[simp] theorem self_sub_monomial_nat_degree_leading_coeff {R : Type u_1} [ring R]\n    (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) :\n    f - coe_fn C (leading_coeff f) * X ^ nat_degree f = erase_lead f :=\n  sorry\n\ntheorem erase_lead_ne_zero {R : Type u_1} [semiring R] {f : polynomial R}\n    (f0 : bit0 1 ≤ finset.card (finsupp.support f)) : erase_lead f ≠ 0 :=\n  sorry\n\n@[simp] theorem nat_degree_not_mem_erase_lead_support {R : Type u_1} [semiring R]\n    {f : polynomial R} : ¬nat_degree f ∈ finsupp.support (erase_lead f) :=\n  sorry\n\ntheorem ne_nat_degree_of_mem_erase_lead_support {R : Type u_1} [semiring R] {f : polynomial R}\n    {a : ℕ} (h : a ∈ finsupp.support (erase_lead f)) : a ≠ nat_degree f :=\n  sorry\n\ntheorem erase_lead_support_card_lt {R : Type u_1} [semiring R] {f : polynomial R} (h : f ≠ 0) :\n    finset.card (finsupp.support (erase_lead f)) < finset.card (finsupp.support f) :=\n  sorry\n\ntheorem erase_lead_card_support {R : Type u_1} [semiring R] {f : polynomial R} {c : ℕ}\n    (fc : finset.card (finsupp.support f) = c) :\n    finset.card (finsupp.support (erase_lead f)) = c - 1 :=\n  sorry\n\ntheorem erase_lead_card_support' {R : Type u_1} [semiring R] {f : polynomial R} {c : ℕ}\n    (fc : finset.card (finsupp.support f) = c + 1) :\n    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 : ℕ) (r : R) :\n    erase_lead (coe_fn (monomial i) r) = 0 :=\n  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 : ℕ) : 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\n      (id (Eq._oldrec (Eq.refl (erase_lead (coe_fn (monomial n) 1) = 0)) (erase_lead_monomial n 1)))\n      (Eq.refl 0))\n\n@[simp] theorem erase_lead_C_mul_X_pow {R : Type u_1} [semiring R] (r : R) (n : ℕ) :\n    erase_lead (coe_fn C r * X ^ n) = 0 :=\n  eq.mpr\n    (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\n      (id (Eq._oldrec (Eq.refl (erase_lead (coe_fn (monomial n) r) = 0)) (erase_lead_monomial n r)))\n      (Eq.refl 0))\n\ntheorem erase_lead_degree_le {R : Type u_1} [semiring R] {f : polynomial R} :\n    degree (erase_lead f) ≤ degree f :=\n  sorry\n\ntheorem erase_lead_nat_degree_le {R : Type u_1} [semiring R] {f : polynomial R} :\n    nat_degree (erase_lead f) ≤ 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}\n    (f0 : bit0 1 ≤ 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\n      (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]\n    (f : polynomial R) : nat_degree (erase_lead f) < nat_degree f ∨ erase_lead f = 0 :=\n  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 → Prop} (N : ℕ)\n    (P_0 : P 0) (P_C_mul_pow : ∀ (n : ℕ) (r : R), r ≠ 0 → n ≤ N → P (coe_fn C r * X ^ n))\n    (P_C_add : ∀ (f g : polynomial R), nat_degree f ≤ N → nat_degree g ≤ N → P f → P g → P (f + g))\n    (f : polynomial R) : nat_degree f ≤ N → P 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/erase_lead_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7640798285992555}}
{"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 2f3994e1b117b1e1da49bcfb67334f33460c3ce4\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\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.descFactorial_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/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial\ncoefficients. -/\ndef choose : ℕ → ℕ → ℕ\n  | _, 0 => 1\n  | 0, _ + 1 => 0\n  | n + 1, k + 1 => choose n k + choose n (k + 1)\n#align nat.choose Nat.choose\n\n@[simp]\ntheorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl\n#align nat.choose_zero_right Nat.choose_zero_right\n\n@[simp]\ntheorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 :=\n  rfl\n#align nat.choose_zero_succ Nat.choose_zero_succ\n\ntheorem choose_succ_succ (n k : ℕ) : 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\ntheorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=\n  rfl\n\ntheorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0\n  | _, 0, hk => absurd hk (Nat.not_lt_zero _)\n  | 0, k + 1, _ => 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@[simp]\ntheorem choose_self (n : ℕ) : 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@[simp]\ntheorem choose_succ_self (n : ℕ) : 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@[simp]\ntheorem choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, add_comm]\n#align nat.choose_one_right Nat.choose_one_right\n\n-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number\ntheorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by\n  rw [← add_mul_div_left, mul_comm 2 n, ← 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/-- `choose n 2` is the `n`-th triangle number. -/\ntheorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by\n  induction' n with n ih\n  . simp\n  · rw [triangle_succ n, choose, ih]\n    simp [add_comm]\n#align nat.choose_two_right Nat.choose_two_right\n\n\n\ntheorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k :=\n  ⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩\n#align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff\n\ntheorem succ_mul_choose_eq : ∀ 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 [choose, mul_succ, succ_eq_add_one, add_comm]\n  | n + 1, k + 1 => by\n    rw [choose_succ_succ (succ n) (succ k), add_mul, ← succ_mul_choose_eq n, mul_succ, ←\n      succ_mul_choose_eq n, add_right_comm, ← mul_add, ← choose_succ_succ, ← succ_mul]\n#align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq\n\ntheorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n !\n  | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]\n  | n + 1, 0, _ => by simp\n  | n + 1, succ k, hk => by\n    cases' lt_or_eq_of_le hk with hk₁ hk₁\n    · have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by\n        rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)];\n          simp [factorial_succ, mul_comm, mul_left_comm, mul_assoc]\n      have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by\n        rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ]\n      have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by\n        rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)];\n          simp [factorial_succ, mul_comm, mul_left_comm, mul_assoc]\n      have h₃ : k * n ! ≤ 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₁, h₂, add_mul, tsub_mul,\n        factorial_succ, ← add_tsub_assoc_of_le h₃, add_assoc, ← add_mul, add_tsub_cancel_left,\n        add_comm]\n    · rw [hk₁]; simp [hk₁, mul_comm, choose, tsub_self]\n#align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial\n\ntheorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :\n    n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=\n  have h : (n - k)! * (k - s)! * s ! ≠ 0 := by apply_rules [factorial_ne_zero, mul_ne_zero]\n  mul_right_cancel₀ 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, ← mul_assoc]\n\n#align nat.choose_mul Nat.choose_mul\n\ntheorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :\n    choose n k = n ! / (k ! * (n - k)!) := by\n  rw [← 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\ntheorem add_choose (i j : ℕ) : (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\ntheorem add_choose_mul_factorial_mul_factorial (i j : ℕ) :\n    (i + j).choose j * i ! * j ! = (i + j)! := by\n  rw [← 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\ntheorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by\n  rw [← 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\ntheorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by\n  suffices : i ! * (i + j - i) ! ∣ (i + j)!\n  . rwa [add_tsub_cancel_left i j] at this\n  exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)\n#align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add\n\n@[simp]\ntheorem choose_symm {n k : ℕ} (hk : k ≤ 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\ntheorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by\n  suffices : choose n (n - b) = choose n b\n  . rw [h, add_tsub_cancel_right] at this; rwa [h]\n  exact choose_symm (h ▸ le_add_left _ _)\n#align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add\n\ntheorem choose_symm_add {a b : ℕ} : 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\ntheorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := 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\ntheorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by\n  have e : (n + 1) * choose n k = choose n k * (k + 1) + choose n (k + 1) * (k + 1)\n  rw [← right_distrib, ← choose_succ_succ, succ_mul_choose_eq]\n  rw [← tsub_eq_of_eq_add_rev e, mul_comm, ← mul_tsub, add_tsub_add_eq_tsub_right]\n#align nat.choose_succ_right_eq Nat.choose_succ_right_eq\n\n@[simp]\ntheorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1\n  | 0 => rfl\n  | n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self]\n#align nat.choose_succ_self_right Nat.choose_succ_self_right\n\ntheorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by\n  cases k with\n  | zero => simp\n  | succ k =>\n    obtain hk | hk := le_or_lt (k + 1) (n + 1)\n    · rw [choose_succ_succ, add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_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,\n        zero_mul]\n#align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq\n\ntheorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) :\n    n.ascFactorial k = k ! * (n + k).choose k := by\n  rw [mul_comm]\n  apply mul_right_cancel₀ (factorial_ne_zero (n + k - k))\n  rw [choose_mul_factorial_mul_factorial, add_tsub_cancel_right, ← factorial_mul_ascFactorial,\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\ntheorem factorial_dvd_ascFactorial (n k : ℕ) : k ! ∣ n.ascFactorial k :=\n  ⟨(n + k).choose k, ascFactorial_eq_factorial_mul_choose _ _⟩\n#align nat.factorial_dvd_asc_factorial Nat.factorial_dvd_ascFactorial\n\ntheorem choose_eq_asc_factorial_div_factorial (n k : ℕ) :\n    (n + k).choose k = n.ascFactorial k / k ! := by\n  apply mul_left_cancel₀ (factorial_ne_zero k)\n  rw [← ascFactorial_eq_factorial_mul_choose]\n  exact (Nat.mul_div_cancel' <| factorial_dvd_ascFactorial _ _).symm\n#align nat.choose_eq_asc_factorial_div_factorial Nat.choose_eq_asc_factorial_div_factorial\n\ntheorem descFactorial_eq_factorial_mul_choose (n k : ℕ) : n.descFactorial k = k ! * n.choose k := by\n  obtain h | h := Nat.lt_or_ge n k\n  · rw [descFactorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, mul_zero]\n  rw [mul_comm]\n  apply mul_right_cancel₀ (factorial_ne_zero (n - k))\n  rw [choose_mul_factorial_mul_factorial h, ← factorial_mul_descFactorial h, mul_comm]\n#align nat.desc_factorial_eq_factorial_mul_choose Nat.descFactorial_eq_factorial_mul_choose\n\ntheorem factorial_dvd_descFactorial (n k : ℕ) : k ! ∣ n.descFactorial k :=\n  ⟨n.choose k, descFactorial_eq_factorial_mul_choose _ _⟩\n#align nat.factorial_dvd_desc_factorial Nat.factorial_dvd_descFactorial\n\ntheorem choose_eq_descFactorial_div_factorial (n k : ℕ) : n.choose k = n.descFactorial k / k ! := by\n  apply mul_left_cancel₀ (factorial_ne_zero k)\n  rw [← descFactorial_eq_factorial_mul_choose]\n  exact (Nat.mul_div_cancel' <| factorial_dvd_descFactorial _ _).symm\n#align nat.choose_eq_desc_factorial_div_factorial Nat.choose_eq_descFactorial_div_factorial\n\n/-! ### Inequalities -/\n\n\n/-- Show that `Nat.choose` is increasing for small values of the right argument. -/\ntheorem choose_le_succ_of_lt_half_left {r n : ℕ} (h : r < n / 2) :\n    choose n r ≤ choose n (r + 1) := 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 [← choose_succ_right_eq]\n  apply Nat.mul_le_mul_left\n  rw [← Nat.lt_iff_add_one_le, lt_tsub_iff_left, ← 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/-- 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 : ℕ} (hr : r ≤ n / 2) :\n    choose n r ≤ choose n (n / 2) :=\n  decreasingInduction\n    (fun _ k a =>\n      (eq_or_lt_of_le a).elim (fun t => t.symm ▸ le_rfl) fun h =>\n        (choose_le_succ_of_lt_half_left h).trans (k h))\n    hr (fun _ => le_rfl) hr\n\n/-- `choose n r` is maximised when `r` is `n/2`. -/\ntheorem choose_le_middle (r n : ℕ) : choose n r ≤ choose n (n / 2) := by\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 [← 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  · rw [choose_eq_zero_of_lt b]\n    apply zero_le\n#align nat.choose_le_middle Nat.choose_le_middle\n\n/-! #### Inequalities about increasing the first argument -/\n\n\ntheorem choose_le_succ (a c : ℕ) : choose a c ≤ choose a.succ c := by\n  cases c <;> simp [Nat.choose_succ_succ]\n#align nat.choose_le_succ Nat.choose_le_succ\n\ntheorem choose_le_add (a b c : ℕ) : choose a c ≤ choose (a + b) c := by\n  induction' b with b_n b_ih\n  · 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\ntheorem choose_le_choose {a b : ℕ} (c : ℕ) (h : a ≤ b) : choose a c ≤ choose b c :=\n  add_tsub_cancel_of_le h ▸ choose_le_add a (b - a) c\n#align nat.choose_le_choose Nat.choose_le_choose\n\ntheorem choose_mono (b : ℕ) : Monotone fun a => choose a b := fun _ _ => choose_le_choose b\n#align nat.choose_mono Nat.choose_mono\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--Porting note: `termination_by` required here where it wasn't before\n/--\n`multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`. -/\ndef multichoose : ℕ → ℕ → ℕ\n  | _, 0 => 1\n  | 0, _ + 1 => 0\n  | n + 1, k + 1 =>\n    multichoose n (k + 1) + multichoose (n + 1) k\n  termination_by multichoose a b => (a, b)\n#align nat.multichoose Nat.multichoose\n\n@[simp]\ntheorem multichoose_zero_right (n : ℕ) : multichoose n 0 = 1 := by cases n <;> simp [multichoose]\n#align nat.multichoose_zero_right Nat.multichoose_zero_right\n\n@[simp]\ntheorem multichoose_zero_succ (k : ℕ) : multichoose 0 (k + 1) = 0 := by simp [multichoose]\n#align nat.multichoose_zero_succ Nat.multichoose_zero_succ\n\ntheorem multichoose_succ_succ (n k : ℕ) :\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@[simp]\ntheorem multichoose_one (k : ℕ) : multichoose 1 k = 1 := by\n  induction' k with k IH; · simp\n  simp [multichoose_succ_succ 0 k, IH]\n#align nat.multichoose_one Nat.multichoose_one\n\n@[simp]\ntheorem multichoose_two (k : ℕ) : multichoose 2 k = k + 1 := by\n  induction' k with k IH; · simp\n  rw [multichoose, IH]\n  simp [add_comm, succ_eq_add_one]\n#align nat.multichoose_two Nat.multichoose_two\n\n@[simp]\ntheorem multichoose_one_right (n : ℕ) : multichoose n 1 = n := by\n  induction' n with n IH; · simp\n  simp [multichoose_succ_succ n 0, IH]\n#align nat.multichoose_one_right Nat.multichoose_one_right\n\ntheorem multichoose_eq : ∀ n k : ℕ, multichoose n k = (n + k - 1).choose k\n  | _, 0 => by simp\n  | 0, k + 1 => by simp\n  | n + 1, k + 1 => by\n    have : n + (k + 1) < (n + 1) + (k + 1) := add_lt_add_right (Nat.lt_succ_self _) _\n    have : (n + 1) + k < (n + 1) + (k + 1) := add_lt_add_left (Nat.lt_succ_self _) _\n    erw [multichoose_succ_succ, add_comm, Nat.succ_add_sub_one, ← add_assoc, Nat.choose_succ_succ]\n    simp [multichoose_eq n (k+1), multichoose_eq (n+1) k]\n  termination_by multichoose_eq a b => a + b\n  decreasing_by { assumption }\n#align nat.multichoose_eq Nat.multichoose_eq\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/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7640798219910334}}
{"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 algebra.gcd_monoid.finset\nimport number_theory.padics.padic_norm\n\n/-!\n# Basic results about setwise gcds on ℕ\n\nThis file proves some basic results about `finset.gcd` on `ℕ`.\n\n## Main results\n* `finset.coprime_of_div_gcd`: The elements of a set divided through by their gcd are coprime.\n\n-/\n\ninstance : is_idempotent ℕ gcd_monoid.gcd := ⟨nat.gcd_self⟩\n\nnamespace finset\n\ntheorem coprime_of_div_gcd (s : finset ℕ) {x : ℕ} (hx : x ∈ s) (hnz : x ≠ 0) :\n  s.gcd (/ (s.gcd id)) = 1 :=\nbegin\n  rw nat.eq_one_iff_not_exists_prime_dvd,\n  intros p hp hdvd,\n  haveI : fact p.prime := ⟨hp⟩,\n  rw dvd_gcd_iff at hdvd,\n  replace hdvd : ∀ b ∈ s, s.gcd id * p ∣ b,\n  { intros b hb,\n    specialize hdvd b hb,\n    rwa nat.dvd_div_iff at hdvd,\n    apply gcd_dvd hb },\n  have : s.gcd id ≠ 0 := (not_iff_not.mpr gcd_eq_zero_iff).mpr (λ h, hnz $ h x hx),\n  apply @pow_succ_padic_val_nat_not_dvd p _ _ this.bot_lt,\n  apply dvd_gcd,\n  intros b hb,\n  obtain ⟨k, rfl⟩ := hdvd b hb,\n  rw [id, mul_right_comm, pow_succ', mul_dvd_mul_iff_right hp.ne_zero],\n  apply dvd_mul_of_dvd_left,\n  exact pow_padic_val_nat_dvd\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/algebra/gcd_monoid/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8397339616560073, "lm_q1q2_score": 0.764079810815808}}
{"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\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\n@[simp] lemma mirror_zero : (0 : polynomial R).mirror = 0 := by simp [mirror]\n\nlemma mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = (monomial n a) :=\nbegin\n  classical,\n  by_cases ha : a = 0,\n  { rw [ha, monomial_zero_right, mirror_zero] },\n  { rw [mirror, reverse, nat_degree_monomial n a, if_neg ha, nat_trailing_degree_monomial ha,\n        ←C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, rev_at_le (le_refl n),\n        tsub_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        tsub_add_cancel_of_le 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 : ℕ) :\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 ≤ p.nat_degree + p.nat_trailing_degree,\n    { rw [rev_at_le h1, coeff_eq_zero_of_lt_nat_trailing_degree],\n      exact (tsub_lt_iff_left h1).mpr (nat.add_lt_add_right h2 _) },\n    { rw [←rev_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 ≤ n,\n  { rw [←tsub_add_eq_add_tsub h2, ←tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow',\n        if_pos h3, coeff_reverse, rev_at_le (tsub_le_self.trans h2)] },\n  rw not_le at h3,\n  rw coeff_eq_zero_of_nat_degree_lt (lt_tsub_iff_right.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 (λ 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 ↔ p = 0 :=\n⟨λ h, by rw [←p.mirror_mirror, h, mirror_zero], λ h, by rw [h, mirror_zero]⟩\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 _ _), add_tsub_cancel_right]\n\nlemma mirror_leading_coeff : p.mirror.leading_coeff = p.trailing_coeff :=\nby rw [←p.mirror_mirror, mirror_trailing_coeff, p.mirror_mirror]\n\nlemma mirror_mul_of_domain {R : Type*} [ring R] [is_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  rw [mul_assoc, ←mul_assoc q.reverse],\n  conv_lhs { congr, skip, congr, rw [←X_pow_mul] },\n  repeat { rw [mul_assoc], },\nend\n\nlemma mirror_smul {R : Type*} [ring R] [is_domain R] (p : polynomial R) (a : R) :\n  (a • p).mirror = a • p.mirror :=\nby rw [←C_mul', ←C_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*} [comm_ring R] [is_domain R] {f : polynomial R}\n  (h1 : ¬ is_unit f)\n  (h2 : ∀ k, f * f.mirror = k * k.mirror → k = f ∨ k = -f ∨ k = f.mirror ∨ k = -f.mirror)\n  (h3 : ∀ g, g ∣ f → g ∣ f.mirror → 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, ←mul_assoc] },\n    have g_dvd_f : g ∣ f,\n    { rw fgh,\n      exact dvd_mul_right g h },\n    have h_dvd_f : h ∣ f,\n    { rw fgh,\n      exact dvd_mul_left h g },\n    have g_dvd_k : g ∣ k,\n    { exact dvd_mul_right g h.mirror },\n    have h_dvd_k_rev : h ∣ 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 ← 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 ← 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": "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/mirror.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7640721427666173}}
{"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.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 `α` by natural numbers.\n\nThis file also provides a few instances of this typeclass. More instances can be found in other\nfiles.\n-/\n\nopen function\nuniverses u v\nvariables {α : Sort u} {β : Sort v}\n\n/-!\n### Definition and basic properties\n-/\n\n/-- A type `α` is countable if there exists an injective map `α → ℕ`. -/\n@[mk_iff countable_iff_exists_injective] class countable (α : Sort u) : Prop :=\n(exists_injective_nat [] : ∃ f : α → ℕ, injective f)\n\ninstance : countable ℕ := ⟨⟨id, injective_id⟩⟩\n\nexport countable (exists_injective_nat)\n\nprotected lemma function.injective.countable [countable β] {f : α → β} (hf : injective f) :\n  countable α :=\nlet ⟨g, hg⟩ := exists_injective_nat β in ⟨⟨g ∘ f, hg.comp hf⟩⟩\n\nprotected lemma function.surjective.countable [countable α] {f : α → β} (hf : surjective f) :\n  countable β :=\n(injective_surj_inv hf).countable\n\nlemma exists_surjective_nat (α : Sort u) [nonempty α] [countable α] : ∃ f : ℕ → α, surjective f :=\nlet ⟨f, hf⟩ := exists_injective_nat α in ⟨inv_fun f, inv_fun_surjective hf⟩\n\nlemma countable_iff_exists_surjective [nonempty α] : countable α ↔ ∃ f : ℕ → α, surjective f :=\n⟨@exists_surjective_nat _ _, λ ⟨f, hf⟩, hf.countable⟩\n\nlemma countable.of_equiv (α : Sort*) [countable α] (e : α ≃ β) : countable β :=\ne.symm.injective.countable\n\nlemma equiv.countable_iff (e : α ≃ β) : countable α ↔ countable β :=\n⟨λ h, @countable.of_equiv _ _ h e, λ h, @countable.of_equiv _ _ h e.symm⟩\n\ninstance {β : Type v} [countable β] : countable (ulift.{u} β) :=\ncountable.of_equiv _ equiv.ulift.symm\n\n/-!\n### Operations on `Sort*`s\n-/\n\ninstance [countable α] : countable (plift α) := equiv.plift.injective.countable\n\n@[priority 100]\ninstance subsingleton.to_countable [subsingleton α] : countable α :=\n⟨⟨λ _, 0, λ x y h, subsingleton.elim x y⟩⟩\n\n@[priority 500]\ninstance [countable α] {p : α → Prop} : countable {x // p x} := subtype.val_injective.countable\n\ninstance {n : ℕ} : countable (fin n) :=\nfunction.injective.countable (@fin.eq_of_veq n)\n\n@[priority 100]\ninstance finite.to_countable [finite α] : countable α :=\nlet ⟨n, ⟨e⟩⟩ := finite.exists_equiv_fin α in countable.of_equiv _ e.symm\n\ninstance : countable punit.{u} := subsingleton.to_countable\n\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 := subsingleton.to_countable\n\ninstance bool.countable : countable bool :=\n⟨⟨λ b, cond b 0 1, bool.injective_iff.2 nat.one_ne_zero⟩⟩\n\ninstance Prop.countable' : countable Prop := countable.of_equiv bool equiv.Prop_equiv_bool.symm\n\n@[priority 500] instance [countable α] {r : α → α → Prop} : countable (quot r) :=\n(surjective_quot_mk r).countable\n\n@[priority 500] instance [countable α] {s : setoid α} : countable (quotient s) := quot.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/data/countable/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7640721320544279}}
{"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 ℓᵖ spaces\n\n/-\n\n# ℓᵖ 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 `‖v‖` makes sense and\nis a real number).\n\nThen given `p : ℝ≥0∞` (i.e. an element `p` of `[0,∞]`) there is a theory\nof ℓᵖ spaces, which is the subspace of `Π i, E i` (the product) consisting of the\nsections `vᵢ` such that `∑ᵢ ‖vᵢ‖ᵖ < ∞`. For `p=∞` this means \"the ‖vᵢ‖ are\nbounded\".\n\n-/\n\nopen_locale ennreal -- to get notation ℝ≥0∞\n\nvariables (I : Type) (E : I → Type) [∀ i, normed_add_comm_group (E i)] (p : ℝ≥0∞)\n\n-- Here's how to say that an element of the product of the Eᵢ is in the ℓᵖ space\n\nexample (v : Π i, E i) : Prop := mem_ℓp v p\n\n-- Technical note: 0^0=1 and x^0=0 for x>0, so ℓ⁰ is the functions with finite support.\n\nvariable (v : Π i, E i)\n\nexample : mem_ℓp v 0 ↔ set.finite {i | v i ≠ 0} :=\nbegin\n  exact mem_ℓp_zero_iff,\nend\n\nexample : mem_ℓp v ∞ ↔ bdd_above (set.range (λ i, ‖v i‖)) :=\nbegin\n  exact mem_ℓp_infty_iff,\nend\n\n-- The function ennreal.to_real sends x<∞ to x and ∞ to 0. \n-- So `0 < p.to_real` is a way of saying `0 < p < ∞`. \n\nexample (hp : 0 < p.to_real) : \n  mem_ℓp v p ↔ summable (λ i, ‖v i‖ ^ p.to_real) :=\nbegin\n  exact mem_ℓp_gen_iff hp\nend\n\n-- It's a theorem in the library that if p ≤ q then mem_ℓp v p → mem_ℓp v q\n\nexample (q : ℝ≥0∞) (hpq : p ≤ q) : mem_ℓp v p → mem_ℓp v q := \nbegin\n  intro h,\n  exact h.of_exponent_ge hpq,\nend\n\n\n-- The space of all `v` satisfying `mem_ℓp 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) : ℝ := ‖v‖  \n\n-- It's a `normed_add_comm_group` if `1 ≤ p` but I've not stated this correctly.\n\nnoncomputable example (h : 1 ≤ p) : normed_add_comm_group (lp E p) :=\nbegin\n  sorry,\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 : ℝ) (hp : 1 < p) (hq : 1 < q) (hpq : 1 / p + 1 / q = 1) : \n  p.is_conjugate_exponent q :=\nsorry -- it's a structure\n\n-- We have a verison of Hoelder's inequality.\n\nexample (q : ℝ≥0∞) (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p)\n  (g : lp E q) : ∑' (i : I), ‖f i‖ * ‖g i‖ ≤ ‖f‖ * ‖g‖ :=\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 `∑' (i : I), ‖f i‖ * ‖g i‖` diverged,\n-- because in Lean if a sum diverges then by definition the `∑'` of it is 0. \n-- So we also need this:\n\nexample (q : ℝ≥0∞) (hpq : p.to_real.is_conjugate_exponent q.to_real) (f : lp E p)\n  (g : lp E q) : summable (λ i, ‖f i‖ * ‖g i‖) :=\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/section17curves_and_surfaces/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7640446808860415}}
{"text": "import data.real.basic\n\nvariables a b : ℝ\n\n#check le_antisymm\n#check le_min\n#check min_le_left\n#check min_le_right\n\n-- BEGIN\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left }\nend\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  { show min a b ≤ min b a,\n    apply le_min,\n    { apply min_le_right },\n    apply min_le_left },\n  { show min b a ≤ min a b,\n    apply le_min,\n    { apply min_le_right },\n    apply min_le_left }\nend\n\nexample : min a b = min b a :=\nbegin\n  have h : ∀ x y, min x y ≤ min y x,\n  { intros x y,\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left },\n  apply le_antisymm, apply h, apply h\nend\n\nexample : max a b = max b a :=\nbegin\n  apply le_antisymm,\n  { show max a b ≤ max b a,\n    apply max_le,\n      apply le_max_right, \n      apply le_max_left },\n  { show max b a ≤ max a b, \n    apply max_le,\n      apply le_max_right,\n      apply le_max_left },\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/ex8_apply_min_max_comm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107914029487, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7640446781085581}}
{"text": "import Mathlib.Tactic.Basic\n\n/-!\n## Tactic Mode\n\nIn Chapter 1, whenever a proof was required, we simply put a `sorry` placeholder.\nFor a tactical proof, we will now write `by` to enter tactic mode. In this mode,\nwe can apply a sequence of tactics, separated by semicolons or new lines.\n\nTactics operate on the goal, which consists of the proposition `Q` that we want to\nprove and of a local context `C`. The local context consists of variable declarations\nof the form `c : τ` and hypotheses of the form `h : P`. We write `C ⊢ Q` to denote a\ngoal, where `C` is a list of variables and hypotheses and `Q` is the goal’s target.\n\nTo make things more concrete, consider the following Lean example:\n\n-/\n\nlemma fst_of_two_props :\n  ∀ a b : Prop, a → b → a := by\n  intros a b\n  intros ha hb\n  apply ha\n\n/-!\nNote that the implication arrow `→` is right-associative; this means that `a → b → a`\nis the same as `a → (b → a)`. Intuitively speaking, it has the meaning “`a` implies\nthat `b` implies `a`,” or equivalently “`a` and `b` imply `a`.” In the example, three tactics\nare invoked, each on its own line. Let us trace their behavior:\n\n1. Initially, the goal is simply the lemma statement:\n    ```lean\n    ⊢ ∀ a b : Prop, a → b → a\n    ```\n\n2.  The `intros a b` tactic tells Lean to fix two free variables, `a` and `b`,\ncorresponding to the two bound variables of the same names. Offen, we name the free\nvariables after the bound variables. The tactic mimics how mathematicians\nwork on paper: To prove a ∀-quantified proposition, it suffices to prove it for\nsome arbitrary but fixed value of the bound variable. The goal becomes\n    ```lean\n    a b : Prop ⊢ a → b → a\n    ```\n\n3. The `intros ha hb` tactic tells Lean to move the assumptions `a` and `b` to the\nlocal context and to call these hypotheses `ha` and `hb`. Indeed, to prove an\nimplication, it suffices to take its left-hand side as hypothesis and prove its\nright-hand side. The goal becomes\n    ```lean\n    a b : Prop, ha : a, hb : b ⊢ a\n    ```\n\n4. The `apply ha` tactic tells Lean to match the hypothesis `a`, called `ha`, against\nthe goal `⊢ a`. Since `a` is syntactically equal to `a`, we have a match, and this\ncompletes the proof.\n\nInformally, in a style reminiscent of pen-and-paper mathematics, we could\nwrite the proof as follows:\n\n- Let `a` and `b` be propositions.\n- Assume `(ha) a` and `(hb) b` are true.\n- To prove `a`, we use hypothesis `ha`. <span class=\"qed\"></span>\n\n(Mathematicians would probably use numeric tags such as (1) and (2) for the hypotheses\ninstead of informative names.)\n\nGoing back to the Lean proof, we can avoid the `intros` invocations by declaring\nthe variables and hypotheses as parameters of the lemma, as follows:\n-/\nlemma fst_of_two_props₂ (a b : Prop) (ha : a) (hb : b) :\n  a := by\n  apply ha\n/-!\nHere is an example with multiple `apply`s in sequence:\n-/\nlemma prop_comp (a b c : Prop) (hab : a → b) (hbc : b → c) :\n  a → c := by\n  intro ha\n  apply hbc\n  apply hab\n  apply ha\n/-!\nPutting on our mathematician’s hat, we can verbalize the last proof as follows:\n\n- Assume `(ha) a` is true.\n- To prove `c`, by hypothesis `hbc` it suffices to prove `b`.\n- To prove `b`, by hypothesis `hab` it suffices to prove `a`.\n- To prove `a`, we use hypothesis `ha`. <span class=\"qed\"></span>\n-/", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/BackwardProofs/TacticMode.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8596637577007393, "lm_q1q2_score": 0.7640337317021806}}
{"text": "import .src_10_false_and_negation\n\nvariables p q r : Prop\n\nnamespace mth1001\n\nsection lem \n\n/-\nThe law of the excluded middle asserts `p ∨ ¬p`, for any proposition `p`. Together with \nor elimination, this leads to a proof method called 'proof by cases' or 'proof by exhaustion'.\n\nSuppose we wish to prove `q`. By the law of the excluded middle, we have `p ∨ ¬p` (for any `p`).\nIf we can prove both `p → q` and `¬p → q`, then, by or elimination, we have a proof of `q`.\n\nIn summary, to prove `q`, it suffices to show both `p → q` and `¬p → q`.\n-/\n\n/-\nThis pattern of reasoning is caputured by the tactic `by_cases`. If `p` is a propostion and if `q`\nis the current goal, then `by_cases k : p` replaces the goal `q` with two subgoals, both to solve\n`q`, but with `k : p` in the  context of the first subgoal and `k : ¬p` in the context of the\nsecond. There is nothing special here about the names `p`, `q`, or `k`.\n-/\n\n/-\nTo use `by_cases`, we first open the `classical` namespace and then\ninstruct Lean to treat all propostions as 'decidable'. You don't need to know what this means.\n-/\nopen classical\nlocal attribute [instance] prop_decidable\n\nexample (h₁ : p → q) (h₂ : ¬p → q) : q :=\nbegin \n  by_cases k : p,\n  { exact h₁ k, },\n  { exact h₂ k, },\nend\n\n/-\nThe following term-style proof explicitly uses or elimnation and the law of the excluded middle. \nHere, `classical.em p` is a proof of `p ∨ ¬p`.\n-/\nexample (h₁ : p → q) (h₂ : ¬p → q) : q :=\nor.elim (classical.em p) h₁ h₂ \n\n\n-- Exercise 063:\n-- Complete the following proof of one direction of one of De Morgan's laws.\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\nbegin \n  intro h,\n  by_cases k : p,\n  { right,\n    intro hq,\n    exact h ⟨k, hq⟩, },\n  { sorry, }, \nend \n\n-- Exercise 064:\n-- We'll now show one can deduce `¬p ∨ q` from `p → q`.\nexample : (p → q) → (¬p ∨ q) :=\nbegin \n  sorry  \nend\n\nend lem \n\n\nsection reductio \n\n/-\nProof by contradiction is another method of reasoning closely associated with the\nlaw of the excluded middle. \n\nIf, on the assumption of `¬p`, one can derive `false`, then one has `p`.\n-/\n\nopen classical\nlocal attribute [instance] prop_decidable\n\n/-\nIf the current goal is to prove `p`, the `by_contradiction` tactic introduces a new premise\n`a : ¬p` into the context and replaces the goal with `false`.\n\nBelow, we invoke the tactic as `by_contradiction k`. With this variant, we specify the name\nof the new premise to be `k`, thereby introducing `k : ¬p` into the context.\n-/\nexample (h : ¬p → false) : p :=\nbegin \n  by_contradiction k,\n  exact h k,\nend \n\n-- Exercise 065:\n-- Using proof by contradiction, we have the remaining part of the law of double negation.\ntheorem self_of_not_not : ¬¬p → p :=\nbegin \n  intro hnnp,\n  by_contradiction hnp,\n  sorry  \nend\n\n-- Exercise 066:\n-- Combine our two previous results to show `¬¬p ↔ p`.\ntheorem not_not {p : Prop} : ¬¬p ↔ p :=\nbegin\n  sorry  \nend\n\n-- Exercise 067:\n-- We show the remaining part of the equivalence of `p → q` with its contrapositive. \nexample : (¬q → ¬p) → (p → q) :=\nbegin \n  sorry  \nend\n\n-- Exercise 068:\n/- \nWe can prove one direction of one of of De Morgan's laws using proof by contradiction.\nComplete the following proof using only the `intro`, `by_contradiction`, `apply`, `split`,\n`exact`, `left`, and `right` tacitcs. You may need to use `by_contradiction` more than once.\n -/\ntheorem not_or_not_of_not_and : ¬(p ∧ q) → ¬p ∨ ¬q :=\nbegin \n  sorry  \nend\n\nend reductio\n\n/-\nSUMMARY:\n\n* The law of the excluded middle: `p ∨ ¬p` holds for every `p`.\n* Proof `by_contradiction`. To prove `p`, we assume `¬p` and derive `false`.\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_11_lem_reductio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.859663754105328, "lm_q1q2_score": 0.7640337310396869}}
{"text": "/-\nTake funtion as argument and use it in implementation.\n-/\n\ndef apply_nat_to_nat (f : ℕ → ℕ) (n : ℕ) : ℕ := \n    f n\n\n#eval apply_nat_to_nat nat.succ 1\n#eval apply_nat_to_nat nat.pred 1\n\n/-\nMake idea completely general using polymorphism\n-/\n\ndef apply {α β : Type} (f : α → β) (a : α) : β := \n    f a\n\n#eval apply nat.succ 1\n#eval apply nat.pred 1\n#eval apply string.length \"I love logic!\"\n\n\n/-\nReturn function as a result\n-/\n\ndef apply_twice {α : Type} (f : α → α ) : α → α := \n    λ a, f (f a)\n\n#reduce (apply_twice nat.succ) \n#reduce apply_twice nat.pred\n\ndef double (n : ℕ) := 2 * n\n\ndef square (n : ℕ) := n ^ 2\n\n#eval apply_twice nat.succ 3    -- application is left associative\n#eval apply_twice nat.pred 3    \n#eval (apply_twice double) 3  \n\ndef square_twice := apply_twice square\ndef double_twice := apply_twice double\n\n#eval square_twice 5\n\n/-\nThat's composition of a function with itself,\nbut we can also compose different functions.\nHere's a special case.\n-/\n\ndef compose_1 {α : Type} (g : α → α ) (f : α → α ): α → α := \n    λ a, g (f a)\n\ndef double_inc := compose_1 double nat.succ\n#reduce double_inc\n#eval double_inc 3\n\n-- Define and try out inc_double (first double then increment)\n\ndef is_even (n : ℕ) : bool := n % 2 = 0\n\n#eval is_even 6\n\ndef compose {α β γ : Type} (g : β → γ) (f : α → β) : α → γ :=\n    λ (a : α), g (f a)\n\ndef even_length := compose is_even string.length\n#eval even_length \"I love logic!!!!!!!\"\n\ndef even_length' := is_even ∘ string.length     -- math notation\n\n/-\nFunctions are objects, too, and there are associated \noperations that apply to functions. Composition is one\nsuch operation. Differentiation is another example of \na function of functions.\n-/\n\n/-\nExercise: apply_n\n-/\n\n/-\nList map.\n-/\n\ndef list_map {α β : Type} : (α → β) → list α → list β \n| f [] := []\n| f (h :: t) := list.cons (f h) (list_map f t)\n\n-- exercise box_map\n-- exercise option_map\n-- exercise tree_map", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/higher_order_funcs/higher_order_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8596637433190939, "lm_q1q2_score": 0.7640337062555671}}
{"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 6 : \"or\" (∨`)\n\nWe learn about how to manipulate `P ∨ 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-/\n\n-- Throughout this sheet, `P`, `Q`, `R` and `S` will denote propositions.\n\nvariables (P Q R S : Prop)\n\nexample : P → P ∨ Q :=\nbegin\n  sorry\nend\n\nexample : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\nexample : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  sorry\nend\n\n-- symmetry of `or`\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n-- associativity of `or`\nexample : (P ∨ Q) ∨ R ↔ P ∨ (Q ∨ R) :=\nbegin\n  sorry,\nend\n\nexample : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\nexample : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\nexample : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\nend\n\n-- de Morgan's laws\nexample : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\nbegin\n  sorry\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/section01logic/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7639376388149645}}
{"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\nThis file contains a few simple lemmas about `set.indicator` and `norm`.\n\n## Tags\nindicator, norm\n-/\n\nvariables {α E : Type*} [normed_group E] {s t : set α} (f : α → E) (a : α)\n\nopen set\n\nlemma norm_indicator_eq_indicator_norm :\n  ∥indicator s f a∥ = indicator s (λa, ∥f a∥) a :=\nflip congr_fun a (indicator_comp_of_zero norm_zero).symm\n\nlemma nnnorm_indicator_eq_indicator_nnnorm :\n  nnnorm (indicator s f a) = indicator s (λa, nnnorm (f a)) a :=\nflip congr_fun a (indicator_comp_of_zero nnnorm_zero).symm\n\nlemma norm_indicator_le_of_subset (h : s ⊆ t) (f : α → E) (a : α) :\n  ∥indicator s f a∥ ≤ ∥indicator t f a∥ :=\nbegin\n  simp only [norm_indicator_eq_indicator_norm],\n  exact indicator_le_indicator_of_subset ‹_› (λ _, norm_nonneg _) _\nend\n\nlemma indicator_norm_le_norm_self : indicator s (λa, ∥f a∥) a ≤ ∥f a∥ :=\nindicator_le_self' (λ _ _, norm_nonneg _) a\n\nlemma norm_indicator_le_norm_self : ∥indicator s f a∥ ≤ ∥f a∥ :=\nby { rw norm_indicator_eq_indicator_norm, apply indicator_norm_le_norm_self }\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/indicator_function.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083608, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7639288956681685}}
{"text": "\nopen classical\n\ntheorem de_morgan {p q : Prop} : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  iff.intro\n    (assume h : ¬(p ∨ q),\n      and.intro\n        (assume hp : p,\n          have hpq : p ∨ q, from or.inl hp,\n          absurd hpq h)\n        (assume hq : q,\n          have hpq : p ∨ q, from or.inr hq,\n          absurd hpq h))\n    (assume h : ¬p ∧ ¬q,\n      have hnp : ¬p, from h.left,\n      have hnq : ¬q, from h.right,\n      assume hpq : p ∨ q,\n      hpq.elim\n        (assume hp : p,\n          absurd hp hnp)\n        (assume hq : q,\n          absurd hq hnq))\n\n-- BEGIN\ntheorem dne {p : Prop} (h : ¬¬p) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : ¬p, absurd hnp h)\n-- END\n\n\ntheorem em' (p : Prop) : p ∨ ¬p :=\nhave hnnponp : ¬¬(p ∨ ¬p), from (\n    assume hnponp : ¬(p ∨ ¬p),\n    have hnpahnnp : ¬p ∧ ¬¬p, from de_morgan.elim_left hnponp,\n    have hnp : ¬p, from and.elim_left hnpahnnp,\n    have hp : p, from dne (and.elim_right hnpahnnp),\n    absurd hp hnp\n),\nshow p ∨ ¬p, from dne hnnponp\n\ntheorem em'' (p: Prop) : p ∨ ¬p :=\nsuffices hdnem : ¬¬(p ∨ ¬p), from dne hdnem,\nshow ¬¬(p ∨ ¬p), from (\n  assume hnem : ¬(p ∨ ¬p),\n  have false : ¬p ∧ ¬¬p, from de_morgan.elim_left hnem,\n  absurd (and.elim_left false) (and.elim_right false)\n)", "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/classical.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067147399245, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7638818135768649}}
{"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 order.monotone.odd\n! leanprover-community/mathlib commit 9116dd6709f303dcf781632e15fdef382b0fc579\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Monotone.Union\nimport Mathlib.Algebra.Order.Group.Instances\n\n/-!\n# Monotonicity of odd functions\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_monotoneOn_nonneg`. We also\nprove versions of this lemma for `Antitone`, `StrictMono`, and `StrictAnti`.\n-/\n\n\nopen Set\n\nvariable {G H : Type _} [LinearOrderedAddCommGroup G] [OrderedAddCommGroup 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`. -/\ntheorem strictMono_of_odd_strictMonoOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)\n    (h₂ : StrictMonoOn f (Ici 0)) : StrictMono f := by\n  refine' StrictMonoOn.Iic_union_Ici (fun x hx y hy hxy => neg_lt_neg_iff.1 _) h₂\n  rw [← h₁, ← h₁]\n  exact h₂ (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_lt_neg hxy)\n#align strict_mono_of_odd_strict_mono_on_nonneg strictMono_of_odd_strictMonoOn_nonneg\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`. -/\ntheorem strictAnti_of_odd_strictAntiOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)\n    (h₂ : StrictAntiOn f (Ici 0)) : StrictAnti f :=\n  @strictMono_of_odd_strictMonoOn_nonneg G Hᵒᵈ _ _ _ h₁ h₂\n#align strict_anti_of_odd_strict_anti_on_nonneg strictAnti_of_odd_strictAntiOn_nonneg\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`. -/\ntheorem monotone_of_odd_of_monotoneOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)\n    (h₂ : MonotoneOn f (Ici 0)) : Monotone f := by\n  refine' MonotoneOn.Iic_union_Ici (fun x hx y hy hxy => neg_le_neg_iff.1 _) h₂\n  rw [← h₁, ← h₁]\n  exact h₂ (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_le_neg hxy)\n#align monotone_of_odd_of_monotone_on_nonneg monotone_of_odd_of_monotoneOn_nonneg\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`. -/\ntheorem antitone_of_odd_of_monotoneOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)\n    (h₂ : AntitoneOn f (Ici 0)) : Antitone f :=\n  @monotone_of_odd_of_monotoneOn_nonneg G Hᵒᵈ _ _ _ h₁ h₂\n#align antitone_of_odd_of_monotone_on_nonneg antitone_of_odd_of_monotoneOn_nonneg\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/Odd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506716354847, "lm_q2_score": 0.8104788995148791, "lm_q1q2_score": 0.7638818062566586}}
{"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 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 ∈ 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) ⊆ (polynomial.lcoeff R n)'' \n    (finset.image (λ (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 : ℕ} {r : R} [decidable (r ∈ aux_ideal I n)]\n\nopen polynomial\n\nnamespace aux_ideal\n\nlemma coeff_span_lift_gens [∀ r, decidable (r ∈ aux_ideal I n)] [decidable_eq (polynomial R)] \n  (hR : is_noetherian_ring R) {c : R} (hcI : c ∈ aux_ideal I n) :\n∃ (y : polynomial R), y ∈ submodule.span R ((λ (r : R), lift I n r) '' ↑(hR.gens (aux_ideal I n))) ∧\n  (lcoeff R n) y = c :=\nbegin\n  sorry\nend\n\n/-\n\nThe conclusion of the previous lemma says that there's some polynomial\nin `submodule.span R ((λ (r : R), lift I n r) '' ↑(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 [∀ r, decidable (r ∈ aux_ideal I n)] \n  (hR : is_noetherian_ring R) {p : polynomial R}\n  (hp : p ∈ submodule.span R ((λ (r : R), lift I n r) '' (hR.gens (aux_ideal I n)))) :\np.nat_degree ≤ n :=\nbegin\n  sorry,\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/section14polynomials/sheet04more_aux_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.8688267745399465, "lm_q1q2_score": 0.7638262586157595}}
{"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.basic\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 : ℕ}\n  {a b : R} (h : (p : R) ∣ a - b) (k : ℕ) :\n  (p^(k+1) : R) ∣ 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, ← geom_sum₂_mul, pow_succ],\n  refine mul_dvd_mul _ ih,\n  let I : ideal R := span {p},\n  let f : R →+* ideal.quotient I := mk I,\n  have hp : (p : ideal.quotient I) = 0,\n  { rw [← f.map_nat_cast, eq_zero_iff_mem, mem_span_singleton] },\n  rw [← mem_span_singleton, ← ideal.quotient.eq] at h,\n  rw [← mem_span_singleton, ← eq_zero_iff_mem, ring_hom.map_geom_sum₂,\n      ring_hom.map_pow, ring_hom.map_pow, h, geom_sum₂_self, hp, zero_mul],\nend\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/number_theory/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7637986968250862}}
{"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 ring_theory.localization.cardinality\n! leanprover-community/mathlib commit 3b09a2601bb7690643936643e99bba0fedfbf6ed\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.Ordinal\nimport Mathbin.RingTheory.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\n\nopen Cardinal nonZeroDivisors\n\nuniverse u v\n\nnamespace IsLocalization\n\nvariable {R : Type u} [CommRing R] (S : Submonoid R) {L : Type u} [CommRing L] [Algebra R L]\n  [IsLocalization S L]\n\ninclude S\n\n/-- A localization always has cardinality less than or equal to the base ring. -/\ntheorem card_le : (#L) ≤ (#R) := by\n  classical\n    cases fintypeOrInfinite R\n    · exact Cardinal.mk_le_of_surjective (IsArtinianRing.localization_surjective S _)\n    erw [← Cardinal.mul_eq_self <| Cardinal.aleph0_le_mk R]\n    set f : R × R → L := fun aa => IsLocalization.mk' _ aa.1 (if h : aa.2 ∈ S then ⟨aa.2, h⟩ else 1)\n    refine' @Cardinal.mk_le_of_surjective _ _ f fun a => _\n    obtain ⟨x, y, h⟩ := IsLocalization.mk'_surjective S a\n    use (x, y)\n    dsimp [f]\n    rwa [dif_pos <| show ↑y ∈ S from y.2, SetLike.eta]\n#align is_localization.card_le IsLocalization.card_le\n\nvariable (L)\n\n/-- If you do not localize at any zero-divisors, localization preserves cardinality. -/\ntheorem card (hS : S ≤ R⁰) : (#R) = (#L) :=\n  (Cardinal.mk_le_of_injective (IsLocalization.injective L hS)).antisymm (card_le S)\n#align is_localization.card IsLocalization.card\n\nend IsLocalization\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/Localization/Cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8418256432832332, "lm_q1q2_score": 0.7637986944056465}}
{"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* `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⁻¹*q⁻¹`. -/\n@[derive subgroup.normal]\ndef commutator : subgroup G :=\nsubgroup.normal_closure {x | ∃ p q, p * q * p⁻¹ * q⁻¹ = x}\n\n/-- The abelianization of G is the quotient of G by its commutator subgroup. -/\ndef abelianization : Type u :=\nG ⧸ (commutator G)\n\nnamespace abelianization\n\nlocal attribute [instance] quotient_group.left_rel\n\ninstance : comm_group (abelianization G) :=\n{ mul_comm := λ x y, quotient.induction_on₂' x y $ λ a b,\n  begin\n    apply quotient.sound,\n    apply subgroup.subset_normal_closure,\n    use b⁻¹, use a⁻¹,\n    group,\n  end,\n.. quotient_group.quotient.group _ }\n\ninstance : inhabited (abelianization G) := ⟨1⟩\n\ninstance [fintype G] [decidable_pred (∈ 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 →* abelianization G :=\n{ to_fun := quotient_group.mk,\n  map_one' := rfl,\n  map_mul' := λ 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ᵃᵇ and proved it's an abelian group.\n-- Furthremore we defined the canonical projection `of : G → Gᵃᵇ`\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 →* A)\n\nlemma commutator_subset_ker : commutator G ≤ f.ker :=\nbegin\n  apply subgroup.normal_closure_le_normal,\n  rintros x ⟨p, q, rfl⟩,\n  simp [monoid_hom.mem_ker, mul_right_comm (f p) (f q)],\nend\n\n/-- If `f : G → 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 →* A) ≃ (abelianization G →* A) :=\n{ to_fun := λ f, quotient_group.lift _ f (λ x h, f.mem_ker.2 $ commutator_subset_ker _ h),\n  inv_fun := λ F, F.comp of,\n  left_inv := λ f, monoid_hom.ext $ λ x, rfl,\n  right_inv := λ F, monoid_hom.ext $ λ x, quotient_group.induction_on x $ λ z, rfl }\n\n@[simp] lemma lift.of (x : G) : lift f (of x) = f x :=\nrfl\n\ntheorem lift.unique\n  (φ : abelianization G →* A)\n  -- hφ : φ agrees with f on the image of G in Gᵃᵇ\n  (hφ : ∀ (x : G), φ (of x) = f x)\n  {x : abelianization G} :\n  φ x = lift f x :=\nquotient_group.induction_on x hφ\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 (φ ψ : abelianization G →* A)\n  (h : φ.comp of = ψ.comp of) : φ = ψ :=\nmonoid_hom.ext $ λ x, quotient_group.induction_on x $ monoid_hom.congr_fun h\n\nsection map\n\nvariables {H : Type v} [group H] (f : G →* H)\n\n/-- The map operation of the `abelianization` functor -/\ndef map : abelianization G →* 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 →* 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 →* 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 ≃* H)\n\n/-- Equivalent groups have equivalent abelianizations -/\ndef mul_equiv.abelianization_congr : abelianization G ≃* 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 ⟨a⟩, simp },\n  right_inv := by { rintros ⟨a⟩, 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₂ : H ≃* I) :\n  e.abelianization_congr.trans e₂.abelianization_congr = (e.trans e₂).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 ≃* abelianization H :=\n{ to_fun    := abelianization.of,\n  inv_fun   := abelianization.lift (monoid_hom.id H),\n  left_inv  := λ a, rfl,\n  right_inv := by { rintros ⟨a⟩, refl, },\n  .. abelianization.of }\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/abelianization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7637986931672855}}
{"text": "import Mynat.Add\n\nnamespace mynat\n\n-- Not sure if I'm correct by writing these lines...\n-- Seems like I cannot copy directly from https://github.com/ImperialCollegeLondon/natural_number_game/blob/master/src/mynat/definition.lean\naxiom zero_ne_succ (m : mynat) : (0 : mynat) ≠ succ m\naxiom succ_inj {m n : mynat} (h : succ m = succ n) : m = n\n\ntheorem succ_inj' {a b : mynat} (hs : (succ a) = (succ b)) : a = b := by\n  apply succ_inj\n  exact hs\n\ntheorem succ_succ_inj {a b : mynat} (h : succ (succ a) = succ (succ b)) : a = b := by\n  apply succ_inj\n  apply succ_inj\n  exact h\n\ntheorem succ_eq_succ_of_eq {a b : mynat} : a = b → (succ a) = (succ b) := by\n  intro h\n  rw [h]\n\ntheorem succ_eq_succ_iff (a b : mynat) : succ a = succ b ↔ a = b := by\n  apply Iff.intro\n  . exact succ_inj'\n  . exact succ_eq_succ_of_eq\n\ntheorem add_right_cancel (a t b : mynat) : a + t = b + t → a = b := by\n  cases t\n  case zero =>\n    rw [mynat_zero_eq_zero]\n    rw [add_zero]\n    rw [add_zero]\n    intro H\n    exact H\n  case succ t' =>\n    rw [add_succ]\n    rw [add_succ]\n    intro h\n    have hh := succ_inj h\n    exact (add_right_cancel a t' b) hh\n\ntheorem add_left_cancel (t a b : mynat) : t + a = t + b → a = b := by\n  rw [add_comm t a]\n  rw [add_comm t b]\n  exact add_right_cancel a t b\n\ntheorem add_right_cancel_iff (t a b : mynat) :  a + t = b + t ↔ a = b := by\n  apply Iff.intro\n  . exact add_right_cancel a t b\n  . intro H\n    rw [H]\n\ntheorem eq_zero_of_add_right_eq_self {a b : mynat} : a + b = a → b = 0 := by\n  intro h\n  conv at h =>\n    rhs\n    rw [← add_zero a]\n  have hcanc := add_left_cancel a b 0\n  exact hcanc h\n\ntheorem succ_ne_zero (a : mynat) : succ a ≠ 0 := by\n  intro h\n  have hfalse := zero_ne_succ a\n  exact hfalse (Eq.symm h)\n\ntheorem add_left_eq_zero {{a b : mynat}} (H : a + b = 0) : b = 0 := by\n  cases b\n  case zero =>\n    rfl\n  case succ b' =>\n    rw [add_succ] at H\n    have h' := (succ_ne_zero (a+b')) H\n    apply False.elim\n    exact h'\n\ntheorem add_right_eq_zero {a b : mynat} : a + b = 0 → a = 0 := by\n  rw [add_comm]\n  intro h\n  exact add_left_eq_zero h\n\ntheorem add_one_eq_succ (d : mynat) : d + 1 = succ d := by\n  rw [succ_eq_add_one]\n\ntheorem ne_succ_self (n : mynat) : n ≠ succ n := by\n  intro H\n  rw [← add_one_eq_succ n] at H\n  conv at H =>\n    lhs\n    rw [← add_zero n]\n  have hfalse := add_left_cancel n 0 1 H\n  rw [one_eq_succ_zero] at hfalse\n  exact zero_ne_succ 0 hfalse\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/AddAdv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7637021652378868}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport sesion_4.soluciones.limites\n\nimport topology.instances.real\n\n/-\n# Límites de secuencias en Lean\n\nAhora que sabemos cómo utilizar filtros en Lean, podemos reescribir\nlas soluciones de los ejercicios de límites de la sesión 4.\n\n-/\n\nopen filter\n\nopen_locale topology -- para acceder a la notación 𝓝 \n\nnamespace limites\n\n-- Nuestra definición `tends_to` es equivalente a `filter.tendsto`\nlemma tends_to_iff_tendsto (a : ℕ → ℝ) (l : ℝ) :\n  tends_to a l ↔ tendsto a at_top (𝓝 l) :=\nbegin\n  rw metric.tendsto_at_top,\n  rw tends_to,\n  congr',\nend\n\n/-- El límite de la secuencia constante con valor `c` es `c`. -/\ntheorem tends_to_const (c : ℝ) : tends_to (λ n, c) c :=\nbegin\n  rw tends_to_iff_tendsto,\n  sorry,\nend\n\n/-- Si `a(n)` tiende a `L` entonces `a(n) + c` tiende a `t + c` -/\ntheorem tends_to_add_const {a : ℕ → ℝ} {L : ℝ} (c : ℝ)\n  (h : tends_to a L) :\n  tends_to (λ n, a n + c) (L + c) :=\nbegin\n  rw tends_to_iff_tendsto at *,\n  sorry,\nend\n\n/-- Si `a(n)` tiende a `L`, entonces `-a(n)` tiende a `-L`.\nSi simplificar la expresión dentro del valor absoluto te está\ndando problemas, ve a la hoja `reales.lean`.\n-/\ntheorem tends_to_neg {a : ℕ → ℝ} {L : ℝ} (ha : tends_to a L) :\n  tends_to (λ n, - a n) (-L) :=\nbegin\n  sorry,\nend\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) + b(n)` \n  tiende a `La + Lb`. -/\ntheorem tends_to_add {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n + b n) (La + Lb) :=\nbegin\n  sorry,\nend\n\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) - b(n)`\ntiende a `La - Lb`. -/\ntheorem tends_to_sub {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n - b n) (La - Lb) :=\nbegin\n  sorry,\nend\n\n/-- Si `a(n)` tiende a `L`, entonces `c*a(n)` tiende a `c*L`.\n-/\nlemma tends_to_mul_const_left {a : ℕ → ℝ} {L c : ℝ} (h : tends_to a L) :\n  tends_to (λ n, c * (a n)) (c * L) := \nbegin\n  sorry\nend\n\n/- Lema del sandwich. \n  Probad a buscar `sandwich` o `squeeze` en la documentación de mathlib.\n-/\ntheorem sandwich (a b c : ℕ → ℝ) (L : ℝ) (ha : tends_to a L) (hc : tends_to c L) \n  (hab : ∀ n, a n ≤ b n) (hbc : ∀ n, b n ≤ c n) : \n  tends_to b L :=\nbegin\n  sorry\nend\n\n/-- Si `a(n)` tiende a `La` y `b(n)` tiende a `Lb` entonces `a(n) * b(n)` \n  tiende a `La * Lb`. -/\ntheorem tends_to_mul {a b : ℕ → ℝ} {La Lb : ℝ}\n  (ha : tends_to a La) (hb : tends_to b Lb) :\n  tends_to (λ n, a n * b n) (La * Lb) :=\nbegin\n  sorry\nend\n\nend limites", "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/limites.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7637021558903228}}
{"text": "import tactic\nimport .«2_1_part_ii_natural_numbers»\n\nnamespace notes\n\n-- Add this line in the beginning of each file to override the default ℕ\nlocal notation `ℕ` : 1024 := mynat\n\nuniverse u\n\n--------------------------------------------------------------------------------\n-- # Integers\n\nnamespace myint\n\n-- The equivalence relation\n  def eqv : ℕ × ℕ → ℕ × ℕ → Prop :=\n    λ ⟨a, b⟩ ⟨c, d⟩, a + d = c + b\n\n  local infix `∼` : 50 := eqv\n\n  lemma eqv_refl : ∀ x, x ∼ x :=\n    λ ⟨a, b⟩, rfl\n\n  lemma eqv_symm : ∀ x y, x ∼ y → y ∼ x :=\n    λ ⟨a, b⟩ ⟨c, d⟩ h, h.symm\n\n  lemma eqv_trans : ∀ x y z, x ∼ y → y ∼ z → x ∼ z :=\n    λ ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ h₁ h₂, by\n    { unfold eqv at *,\n      have h : (d + c) + (a + f) = (d + c) + (e + b),\n      { -- `rewrite_search` is my dream tactic!\n        /- rewrite_search? [h₁, h₂] -/\n        conv_lhs { congr, skip, erw [mynat.add_comm] },\n        conv_lhs { erw [mynat.add_assoc, mynat.add_comm] },\n        conv_lhs { congr, erw [←mynat.add_assoc] },\n        conv_lhs { erw [mynat.add_assoc] },\n        conv_lhs { congr, erw [h₂] },\n        conv_rhs { erw [←mynat.add_assoc] },\n        conv_rhs { congr, erw [mynat.add_comm, ←mynat.add_assoc] },\n        conv_rhs { erw [mynat.add_assoc] },\n        conv_rhs { congr, skip, erw [←h₁] }\n        /- end -/ },\n      exact mynat.add_left_cancel _ _ _ h }\n\n  lemma eqv_equivalence_relation : is_equivalence_relation (∼) :=\n    ⟨eqv_refl, eqv_symm, eqv_trans⟩\n\nend myint\n\n-- Definition of ℤ as a quotient type\n-- (i.e. equivalence classes under the equivalence relation)\ndef myint : Type :=\n  @quot (ℕ × ℕ) myint.eqv\n\n-- Add this line in the beginning of each file to override the default ℤ\nlocal notation `ℤ` : 1024 := myint\n\nnamespace myint\nsection\n  local infix ` ∼ ` : 50 := eqv\n\n-- Addition\n  def add_fn : ℕ × ℕ → ℕ × ℕ → ℕ × ℕ :=\n    λ ⟨a, b⟩ ⟨c, d⟩, (a + c, b + d)\n\n  lemma add_respects_fst :\n    ∀ (x₁ x₂ y : ℕ × ℕ), (x₁ ∼ x₂) → (add_fn x₁ y ∼ add_fn x₂ y)\n  :=\n  begin\n    rintros ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨c, d⟩ h,\n    unfold add_fn at *,\n    unfold eqv at *,\n    /- rewrite_search? [h] -/\n    conv_lhs { congr, erw [mynat.add_comm] },\n    conv_lhs { erw [mynat.add_assoc] },\n    conv_lhs { congr, skip, erw [←mynat.add_assoc] },\n    conv_lhs { congr, skip, congr, erw [h] },\n    conv_rhs { congr, erw [mynat.add_comm] },\n    conv_rhs { erw [mynat.add_assoc] },\n    conv_rhs { congr, skip, erw [←mynat.add_assoc] }\n    /- end -/\n  end\n\n  lemma add_respects_snd :\n    ∀ (x y₁ y₂ : ℕ × ℕ), (y₁ ∼ y₂) → (add_fn x y₁ ∼ add_fn x y₂)\n  :=\n  begin\n    rintros ⟨a, b⟩ ⟨c₁, d₁⟩ ⟨c₂, d₂⟩ h,\n    unfold add_fn at *,\n    unfold eqv at *,\n    /- rewrite_search? [h] -/\n    conv_lhs { congr, skip, erw [mynat.add_comm] },\n    conv_lhs { erw [mynat.add_assoc] },\n    conv_lhs { congr, skip, erw [←mynat.add_assoc] },\n    conv_lhs { congr, skip, congr, erw [h] },\n    conv_rhs { congr, skip, erw [mynat.add_comm] },\n    conv_rhs { erw [mynat.add_assoc] },\n    conv_rhs { congr, skip, erw [←mynat.add_assoc] }\n    /- end -/\n  end\n\n  def add : ℤ → ℤ → ℤ :=\n    quot.map₂ add_fn add_respects_snd add_respects_fst\n  instance : has_add ℤ := ⟨add⟩\n\n-- Negation\n  def neg_fn : ℕ × ℕ → ℕ × ℕ :=\n    λ ⟨a, b⟩, (b, a)\n  \n  lemma neg_respects :\n    ∀ (x₁ x₂ : ℕ × ℕ), (x₁ ∼ x₂) → (neg_fn x₁ ∼ neg_fn x₂)\n  :=\n  begin\n    rintros ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ h,\n    unfold neg_fn at *,\n    unfold eqv at *,\n    rw [mynat.add_comm, ← h, mynat.add_comm]\n  end\n\n  def neg : ℤ → ℤ :=\n    quot.map neg_fn neg_respects\n  instance : has_neg ℤ := ⟨neg⟩\n\n-- Multiplication\n  def mul_fn : ℕ × ℕ → ℕ × ℕ → ℕ × ℕ :=\n    λ ⟨a, b⟩ ⟨c, d⟩, (a * c + b * d, a * d + b * c)\n\n  lemma mul_respects_fst :\n    ∀ (x₁ x₂ y : ℕ × ℕ), (x₁ ∼ x₂) → (mul_fn x₁ y ∼ mul_fn x₂ y)\n  :=\n  begin\n    rintros ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨c, d⟩ h,\n    unfold mul_fn at *,\n    unfold eqv at *,\n    have : (a₁ + b₂) * c + (a₂ + b₁) * d = (a₂ + b₁) * c + (a₁ + b₂) * d,\n    { rw h },\n    calc  a₁ * c + b₁ * d + (a₂ * d + b₂ * c)\n        = (a₁ + b₂) * c + (a₂ + b₁) * d : by\n        { /- rewrite_search? -/\n          conv_lhs { congr, skip, erw [mynat.add_comm] },\n          conv_lhs { erw [mynat.add_assoc] },\n          conv_lhs { congr, skip, erw [mynat.add_comm, mynat.add_assoc] },\n          conv_rhs { congr, erw [mynat.add_mul], skip, erw [mynat.add_mul] },\n          conv_rhs { erw [mynat.add_assoc] }\n          /- end -/ }\n    ... = (a₂ + b₁) * c + (a₁ + b₂) * d : by rw h\n    ... = a₂ * c + b₂ * d + (a₁ * d + b₁ * c) : by\n        { /- rewrite_search? -/\n          conv_lhs { congr, erw [mynat.add_mul], skip, erw [mynat.add_mul] },\n          conv_lhs { erw [mynat.add_assoc] },\n          conv_rhs { erw [mynat.add_assoc] },\n          conv_rhs { congr, skip, erw [←mynat.add_assoc, mynat.add_comm] },\n          conv_rhs { congr, skip, congr, skip, erw [mynat.add_comm] }\n          /- end -/ }\n  end\n\n  lemma mul_respects_snd :\n    ∀ (x y₁ y₂ : ℕ × ℕ), (y₁ ∼ y₂) → (mul_fn x y₁ ∼ mul_fn x y₂)\n  :=\n  begin\n    rintros ⟨a, b⟩ ⟨c₁, d₁⟩ ⟨c₂, d₂⟩ h,\n    have : mul_fn ⟨a, b⟩ ⟨c₁, d₁⟩ = mul_fn ⟨c₁, d₁⟩ ⟨a, b⟩,\n    { unfold mul_fn at *, cc },\n    rw this,\n    have : mul_fn ⟨a, b⟩ ⟨c₂, d₂⟩ = mul_fn ⟨c₂, d₂⟩ ⟨a, b⟩,\n    { unfold mul_fn at *, cc },\n    rw this,\n    exact mul_respects_fst _ _ _ h,\n  end\n\n  def mul : ℤ → ℤ → ℤ :=\n    quot.map₂ mul_fn mul_respects_snd mul_respects_fst\n  instance : has_mul ℤ := ⟨mul⟩\n\n-- Less or equal than\n  def le_fn : ℕ × ℕ → ℕ × ℕ → Prop :=\n    λ ⟨a, b⟩ ⟨c, d⟩, a + d ≤ c + b\n\n  lemma le_respects_fst :\n    ∀ (x₁ x₂ y : ℕ × ℕ), x₁ ∼ x₂ → le_fn x₁ y = le_fn x₂ y\n  :=\n  begin\n    rintros ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨c, d⟩ h,\n    unfold le_fn at *,\n    unfold eqv at *,\n    apply propext,\n    split,\n    { intros h₁, sorry },\n    { intros h₁, sorry }\n  end\n\n  lemma le_respects_snd :\n    ∀ (x y₁ y₂ : ℕ × ℕ), (y₁ ∼ y₂) → le_fn x y₁ = le_fn x y₂\n  :=\n  begin\n    rintros ⟨a, b⟩ ⟨c₁, d₁⟩ ⟨c₂, d₂⟩ h,\n    unfold le_fn at *,\n    unfold eqv at *,\n    sorry\n  end\n\n  def le : ℤ → ℤ → Prop :=\n    quot.lift₂ le_fn le_respects_snd le_respects_fst\n  instance : has_le ℤ := ⟨le⟩\n\n-- Less than\n  def lt_fn : ℕ × ℕ → ℕ × ℕ → Prop :=\n    λ ⟨a, b⟩ ⟨c, d⟩, a + d < c + b\n\n  lemma lt_respects_fst :\n    ∀ (x₁ x₂ y : ℕ × ℕ), x₁ ∼ x₂ → lt_fn x₁ y = lt_fn x₂ y\n  :=\n  begin\n    rintros ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨c, d⟩ h,\n    unfold lt_fn at *,\n    unfold eqv at *,\n    sorry\n  end\n\n  lemma lt_respects_snd :\n    ∀ (x y₁ y₂ : ℕ × ℕ), (y₁ ∼ y₂) → lt_fn x y₁ = lt_fn x y₂\n  :=\n  begin\n    rintros ⟨a, b⟩ ⟨c₁, d₁⟩ ⟨c₂, d₂⟩ h,\n    unfold lt_fn at *,\n    unfold eqv at *,\n    sorry\n  end\n\n  def lt : ℤ → ℤ → Prop :=\n    quot.lift₂ lt_fn lt_respects_snd lt_respects_fst\n  instance : has_lt ℤ := ⟨lt⟩\n\nend\n\nsection\n-- TODO: ℕ as a subset of ℤ\n\n  def zero : ℤ := quot.mk eqv (0, 0)\n  def one : ℤ := quot.mk eqv (1, 0)\n\n  instance : has_zero ℤ := ⟨zero⟩\n  instance : has_one ℤ := ⟨one⟩\n\n  lemma zero_ne_one :\n    (0 : ℤ) ≠ 1\n  :=\n  begin\n    intros h,\n    let f : ℕ × ℕ → Prop := λ ⟨a, b⟩, ite (b = 0) false true,\n    sorry\n  end\nend\n\nsection\n  local infix ` ∼ ` : 50 := eqv\n  variables (x y z : ℤ)\n\n  @[simp, rewrite]\n  theorem add_assoc :\n    (x + y) + z = x + (y + z)\n  :=\n  begin\n    revert x y z, rintros ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩,\n    change (quot.mk eqv (a + c + e, b + d + f) =\n            quot.mk eqv (a + (c + e), b + (d + f))),\n    rw [add_assoc, add_assoc]\n  end\n\n  @[simp, rewrite]\n  theorem zero_add :\n    0 + x = x\n  :=\n  begin\n    revert x, rintros ⟨a, b⟩,\n    change (quot.mk eqv (0 + a, 0 + b) = quot.mk eqv (a, b)),\n    rw [zero_add, zero_add]\n  end\n\n  @[simp, rewrite]\n  theorem add_zero :\n    x + 0 = x\n  :=\n  begin\n    revert x, rintros ⟨a, b⟩,\n    change (quot.mk eqv (a + 0, b + 0) = quot.mk eqv (a, b)),\n    refl\n  end\n\n  @[simp, rewrite]\n  theorem neg_add :\n    (-x) + x = 0\n  :=\n  begin\n    revert x, rintros ⟨a, b⟩,\n    change (quot.mk eqv (b + a, a + b) = quot.mk eqv (0, 0)),\n    rw add_comm,\n    apply quot.sound,\n    unfold eqv,\n    simp\n  end\n\n  @[simp, rewrite]\n  theorem add_neg :\n    x + (-x) = 0\n  :=\n  begin\n    revert x, rintros ⟨a, b⟩,\n    change (quot.mk eqv (a + b, b + a) = quot.mk eqv (0, 0)),\n    rw add_comm,\n    apply quot.sound,\n    unfold eqv,\n    simp\n  end\n\n  @[rewrite]\n  theorem add_comm :\n    x + y = y + x\n  :=\n  begin\n    revert x y, rintros ⟨a, b⟩ ⟨c, d⟩,\n    change (quot.mk eqv (a + c, b + d) = quot.mk eqv (c + a, d + b)),\n    rw [add_comm a c, add_comm b d]\n  end\n\n  @[simp, rewrite]\n  theorem mul_assoc :\n    (x * y) * z = x * (y * z)\n  :=\n  begin\n    revert x y z, rintros ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩,\n    change (quot.mk eqv ((a * c + b * d) * e + (a * d + b * c) * f, (a * c + b * d) * f + (a * d + b * c) * e) =\n            quot.mk eqv (a * (c * e + d * f) + b * (c * f + d * e), a * (c * f + d * e) + b * (c * e + d * f))),\n    simp only [mynat.mul_assoc, mynat.add_assoc, mynat.mul_add, mynat.add_mul],\n    apply quot.sound,\n    unfold eqv,\n    simp only [mynat.add_assoc, add_right_inj],\n    /- TODO: how to automate here? `ac_refl` does not work... -/\n    conv_lhs { rw mynat.add_comm }, simp only [mynat.add_assoc],\n    conv_lhs { congr, skip, congr, skip, rw mynat.add_comm, congr, rw mynat.add_comm, congr, rw mynat.add_comm, congr, rw mynat.add_comm }, simp only [mynat.add_assoc],\n    conv_lhs { congr, skip, congr, skip, congr, skip, rw mynat.add_comm, congr, rw mynat.add_comm, congr, rw mynat.add_comm }, simp only [mynat.add_assoc],\n    conv_lhs { congr, skip, congr, skip, congr, skip, congr, skip, rw mynat.add_comm, congr, rw mynat.add_comm }, simp only [mynat.add_assoc],\n    conv_lhs { congr, skip, congr, skip, congr, skip, congr, skip, congr, skip, rw mynat.add_comm },\n    /- rhs: `a * (d * f) + (b * (c * f) + (b * (d * e) + (a * (c * f) + (b * (d * f) + (a * (d * e) + b * (c * e))))))` -/\n  end\n\n  @[simp, rewrite]\n  theorem one_mul :\n    1 * x = x\n  :=\n  begin\n    revert x, rintros ⟨a, b⟩,\n    change (quot.mk eqv (1 * a + 0 * b, 1 * b + 0 * a) = quot.mk eqv (a, b)),\n    simp\n  end\n\n  @[simp, rewrite]\n  theorem mul_one :\n    x * 1 = x\n  :=\n  begin\n    revert x, rintros ⟨a, b⟩,\n    change (quot.mk eqv (a * 1 + b * 0, a * 0 + b * 1) = quot.mk eqv (a, b)),\n    simp\n  end\n\n  @[rewrite]\n  theorem mul_comm :\n    x * y = y * x\n  :=\n  begin\n    revert x y, rintros ⟨a, b⟩ ⟨c, d⟩,\n    change (quot.mk eqv (a * c + b * d, a * d + b * c) =\n            quot.mk eqv (c * a + d * b, c * b + d * a)),\n    rw [mul_comm a c, mul_comm b d, mul_comm a d, mul_comm b c, mynat.add_comm (d * a)]\n  end\n\n  @[simp, rewrite]\n  theorem add_mul :\n    (x + y) * z = x * z + y * z\n  :=\n  begin\n    revert x y z, rintros ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩,\n    change (quot.mk eqv ((a + c) * e + (b + d) * f, (a + c) * f + (b + d) * e) =\n            quot.mk eqv ((a * e + b * f) + (c * e + d * f), (a * f + b * e) + (c * f + d * e))),\n    simp only [add_mul],\n    ac_refl\n  end\n\n  @[simp, rewrite]\n  lemma mul_add : x * (y + z) = x * y + x * z :=\n    by rw [mul_comm, add_mul, mul_comm y x, mul_comm z x]\n\nend\n\nsection\n  local infix ` ∼ ` : 50 := eqv\n  variables (x y z : ℤ)\n\n  theorem add_right_cancel :\n    x + z = y + z → x = y\n  :=\n  begin\n    intros h,\n    calc  x\n        = x + z + -z : by rw [add_assoc, add_neg, add_zero]\n    ... = y + z + -z : by rw h\n    ... = y          : by rw [add_assoc, add_neg, add_zero]\n  end\n\n  lemma add_left_cancel : z + x = z + y → x = y :=\n    by { rw [add_comm z x, add_comm z y], exact add_right_cancel _ _ _ }\n\n  theorem mul_right_cancel :\n    z ≠ 0 → x * z = y * z → x = y\n  :=\n  begin\n    revert x y z, rintros ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ hef h,\n    rcases mynat.lt_trichotomy e f with ⟨g, hg⟩ | ⟨g, hg₁, hg₂⟩ | ⟨g, hg₁, hg₂⟩,\n    apply quot.sound,\n    { sorry },\n    { have h := calc\n            quot.mk eqv (a * g, b * g)\n          = quot.mk eqv (a * e + b * f, a * f + b * e) : by sorry\n      ... = quot.mk eqv (c * e + d * f, c * f + d * e) : h\n      ... = quot.mk eqv (c * g, d * g) : by sorry,\n      -- change a * g + d * g = c * g + b * g at h,\n      sorry },\n    { sorry }\n  end\n\n  lemma mul_left_cancel : x ≠ 0 → x * y = x * z → y = z :=\n    by { rw [mul_comm x y, mul_comm x z], exact mul_right_cancel _ _ _ }\n\nend\n\n-- TODO: lemmas related to le, lt...\n\nend myint\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/1_intro_to_uni_maths/2_2_part_ii_integers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037231733433, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7637021500196525}}
{"text": "import tactic\n\n/-!\n\n# Groups\n\nDefinition and basic properties of a group.\n\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\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 → G → G`\n`has_one G` means that `G` has a `1 : G`\n`has_inv G` means that `G` has an `⁻¹ : G → G`\n\nAll of `*`, `1` and `⁻¹` 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-/\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 : ∀ (a b c : G), a * b * c = a * (b * c))\n(one_mul : ∀ (a : G), 1 * a = a)\n(mul_left_inv : ∀ (a : G), a⁻¹ * 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 : ∀ (a : G), a * 1 = a`\nand `mul_right_inv : ∀ (a : G), a * a⁻¹ = 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 : ∀ (a b c : G), a * b = a * c → b = c`\n`mul_eq_of_eq_inv_mul {a x y : G} : x = a⁻¹ * y → a * x = y`\n`mul_one (a : G) : a * 1 = a`\n`mul_right_inv (a : G) : a * a⁻¹ = 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 : ∀ a b c, a * b = a * c → 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\n`mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c)`\n`one_mul : ∀ (a : G), 1 * a = a`\n`mul_left_inv : ∀ (a : G), a⁻¹ * a = 1`\n\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⁻¹ * a) * b : by sorry -- replace `sorry` with `rw X` as appropriate\n    ... = a⁻¹ * (a * b) : by sorry\n    ... = a⁻¹ * (a * c) : by sorry\n    ... = (a⁻¹ * a) * c : by sorry\n    ... = 1 * c         : by sorry\n    ... = c             : by sorry\nend\n\n/-\nNext we prove that if `x = a⁻¹ * 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⁻¹ * (a * x) = a⁻¹ * y.`\nNow use associativity and left cancellation on on the left, to reduce\nto `h`. \n\nNote that `mul_left_cancel` is a function, and its first input is \ncalled `a`, but you had better give it `a⁻¹` instead.  \n-/\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a⁻¹, \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⁻¹ = 1 :=\nbegin\n  sorry\nend\n\n-- Now let's talk about what that `@[simp]` means.\n\n/-\n\n## Lean's simplifier\n\nA human sees `a * a⁻¹` 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 ↔ Q` (by tagging them with the `@[simp]` attribute) and then give\nit a complicated goal, like\n\n`example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * 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⁻¹ = 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⁻¹ * (a * b) = b`\n`mul_inv_cancel_left : a * (a⁻¹ * b) = b`\n`inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹`\n`one_inv : (1 : G)⁻¹ = 1`\n`inv_inv : (a⁻¹)⁻¹ = 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⁻¹ * (a * b) = b :=\nbegin\n  rw ← 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⁻¹ * a to 1 and then 1 * b to b\nend\n\n@[simp] lemma mul_inv_cancel_left : a * (a⁻¹ * b) = b :=\nbegin\n  sorry\nend\n\n@[simp] lemma inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\nbegin\n  sorry\nend\n\n@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=\nbegin\n  sorry\nend\n\n@[simp] lemma inv_inv : a ⁻¹ ⁻¹ = a :=\nbegin\n  sorry\nend\n\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\n\nhttps://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group\n\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öbner bases.\n\n-/\n\n-- Now let's try our example...\nexample : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * 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⁻¹ :=\nbegin\n  sorry\nend\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b⁻¹ * c :=\nbegin\n  sorry\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b ↔ a = 1 :=\nbegin\n  sorry\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a ↔ b = 1 :=\nbegin\n  sorry\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b⁻¹ :=\nbegin\n  sorry\nend\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a⁻¹ = b :=\nbegin\n  sorry,\nend\n\nlemma unique_left_id {e : G} (h : ∀ 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⁻¹ :=\nbegin\n  sorry\nend\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y ↔ 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-- `↔` lemmas are good simp lemmas too.\n@[simp] theorem inv_inj_iff {a b : G}: a⁻¹ = b⁻¹ ↔ a = b :=\nbegin\n  sorry\nend   \n\ntheorem inv_eq {a b : G}: a⁻¹ = b ↔ b⁻¹ = a :=\nbegin\n  sorry\nend  \n\nend group\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_2/Part_A_groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7636825721882875}}
{"text": "-- Eliminacion_de_la_disyuncion.lean\n-- Eliminación de la disyunción.\n-- José A. Alonso Jiménez\n-- Sevilla, 13 de agosto de 2020\n-- ---------------------------------------------------------------------\n\n-- En este relación se muestra distintas formas de demostrar un teorema\n-- con eliminación de la disyunción\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones:\n-- 1. Importar la librería de tácticas.\n-- 2. Declarar P, Q y R como variables sobre proposiciones. \n-- ----------------------------------------------------------------------\n\nimport tactic              -- 1\nvariables (P Q R : Prop)   -- 2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si\n--    P → R y \n--    Q → R \n-- entonces\n--    P ∨ Q → R \n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample \n  (hPR : P → R) \n  (hQR : Q → R) \n  : P ∨ Q → R :=\nbegin\n  intro h,\n  cases h with hP hQ,\n  { exact hPR hP },\n  { exact hQR hQ },\nend\n\n-- Comentario\n-- ----------\n\n-- La táctica (cases h with h1 h2), cuando la hipótesis h es una\n-- disyunción aplica la regla de eliminación de la disyunción; es decir,\n-- si h es (P ∨ Q), entonces elimina h y crea dos casos: uno añadiendo\n-- la hipótesis (h1 : P)   y otro añadiendo la hipótesis (h2 : Q).   \n\n-- 2ª demostración\n-- ===============\n\nexample \n  (hPR : P → R) \n  (hQR : Q → R) \n  : P ∨ Q → R :=\nbegin\n  rintro (hP | hQ),\n  { exact hPR hP },\n  { exact hQR hQ },\nend\n\n-- Comentario\n-- ----------\n\n-- La táctica (rintro (h1 | h2)), cuando la conclusión es una\n-- implicación cuyo antecedente es una disyunción, aplica las regla des\n-- introducción de la implicación y de eliminación de la disyunción; es\n-- decir, si la conclusión es (P ∨ Q → R) entonces crea dos casos: en el\n-- primero añade la hipótesis (h1 : P) y cambia a conclusión a R; en el\n-- segundo añade la hipótesis (h2 : Q) y cambia la conclusión a R.\n\n-- 3ª demostración\n-- ===============\n\nexample \n  (hPR : P → R) \n  (hQR : Q → R) \n  : P ∨ Q → R :=\nλ h, or.elim h hPR hQR \n\n-- Comentario: Se ha usado el lema\n-- + or.elim : P ∨ Q → (P → R) → (Q → R) → R\n\n-- 3ª demostración\n-- ===============\n\nexample \n  (hPR : P → R) \n  (hQR : Q → R) \n  : P ∨ Q → R :=\nor.rec hPR hQR\n\n-- Comentario: Se ha usado el lema\n-- + or.rec    : (P → R) → (Q → R) → P ∨ Q → R \n\n-- 4ª demostración\n-- ===============\n\nexample \n  (hPR : P → R) \n  (hQR : Q → R) \n  : P ∨ Q → R :=\nby tauto\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_disyuncion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357632379241, "lm_q2_score": 0.8807970826714614, "lm_q1q2_score": 0.7636825708317875}}
{"text": "import analysis.specific_limits\nimport data.int.parity\nimport topology.sequences\n\nattribute [instance] classical.prop_decidable\n\n/- \nLemmas from that file were hidden in my course, or restating things which\nwere proved without name in previous files.\n-/\n\nnotation `|`x`|` := abs x\n\n-- The mathlib version is unusable because it is stated in terms of ≤\nlemma ge_max_iff {α : Type*} [linear_order α] {p q r : α} : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\n/- No idea why this is not in mathlib-/\nlemma eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h, \n  apply eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\nlemma unique_limit {u l l'} : seq_limit u l → seq_limit u l' → l = l' :=\nbegin\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros ε ε_pos,\n  specialize hl (ε/2) (by linarith),\n  cases hl with N hN,\n  specialize hl' (ε/2) (by linarith),\n  cases hl' with N' hN',\n  specialize hN (max N N') (le_max_left _ _),\n  specialize hN' (max N N') (le_max_right _ _),\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring_nf\n  ... ≤ |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  ... ≤ ε/2 + ε/2 : by linarith\n  ... = ε : by ring,\nend\n\nlemma le_of_le_add_all {x y : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\ndef upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y\n\nlemma lt_sup {A : set ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\nlemma squeeze {u v w : ℕ → ℝ} {l} (hu : seq_limit u l) (hw : seq_limit w l)\n(h : ∀ n, u n ≤ v n)\n(h' : ∀ n, v n ≤ w n) : seq_limit v l :=\nbegin\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases hw ε ε_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 ; linarith\nend\n\ndef extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m\n\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\nlemma lim_le {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\nlemma inv_succ_le_all :  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    intros h ε ε_pos,\n    cases h (ε/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n    specialize hN n hn,\n    linarith,\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\nlemma limit_const (x : ℝ) : seq_limit (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\nlemma limit_of_sub_le_inv_succ {u : ℕ → ℝ} {x : ℝ} (h : ∀ n, |u n - x| ≤ 1/(n+1)) :\nseq_limit u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\nlemma limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ; linarith [@nat.one_div_pos_of_nat ℝ _ n])\n\nlemma limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\nlemma id_le_extraction {φ}: extraction φ → ∀ n, n ≤ φ 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\nlemma seq_limit_id : tendsto_infinity (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N, exact_mod_cast hn, \n  linarith,\nend\n\nvariables {u : ℕ → ℝ} {l : ℝ} {φ : ℕ → ℕ}\n\nopen set filter\n\ndef cluster_point (u : ℕ → ℝ) (a : ℝ) :=\n∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a\n\nlemma bolzano_weierstrass {a b : ℝ} {u : ℕ → ℝ} (h : ∀ n, u n ∈ Icc a b) :\n∃ c ∈ Icc a b, cluster_point u c :=\nbegin\n  rcases (is_compact_Icc : is_compact (Icc a b)).tendsto_subseq h with ⟨c, c_in, φ, hφ, lim⟩,\n  use [c, c_in, φ, hφ],\n  simp_rw [metric.tendsto_nhds, eventually_at_top, real.dist_eq] at lim,\n  intros ε ε_pos,\n  rcases lim ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  exact le_of_lt (hN n hn)\nend\n\nlemma not_seq_limit_of_tendstoinfinity {u : ℕ → ℝ} :\n  tendsto_infinity u → ∀ x, ¬ seq_limit u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\nopen real \n\nlemma sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :\n  ∃ x ∈ Icc a b, is_sup A x :=\nbegin\n  have b_maj :  ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : upper_bound A (Sup A),\n  { intro x,\n    apply le_cSup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply cSup_le hnonvide b_maj } },\n  { exact ⟨Sup_maj, λ y, cSup_le hnonvide⟩ },\nend\n\nlemma subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn \n     ... ≤ φ n : id_le_extraction hφ n, \nend\nnamespace tactic.interactive\nopen tactic\n\nmeta def check_me : tactic unit :=\n`[ { repeat { unfold seq_limit},\n   repeat { unfold continue_en },\n   push_neg,\n   try { simp only [exists_prop] },\n   try { exact iff.rfl },\n   done } <|> fail \"That's not quite right. Please try again.\" ]\n\nend tactic.interactive\n", "meta": {"author": "bollu", "repo": "CASette", "sha": "cb19729abed5f3f9a58e095791fd498aa98b23dd", "save_path": "github-repos/lean/bollu-CASette", "path": "github-repos/lean/bollu-CASette/CASette-cb19729abed5f3f9a58e095791fd498aa98b23dd/schreier/src/solutions/tuto_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.7636825540839824}}
{"text": "import tactic\nimport number_theory.divisors -- added to make Bhavik's proof work\n\n/-\n\n# Find all integers x ≠ 3 such that x - 3 divides x^3 - 3\n\nThis is the second question in Sierpinski's book \"250 elementary problems\nin number theory\".\n\nmy solution: x - 3 divides x^3-27, and hence if it divides x^3-3\nthen it also divides the difference, which is 24. Conversely,\nif x-3 divides 24 then because it divides x^3-27 it also divides x^3-3\n\n-/\n\nexample (x : ℤ) : x - 3 ∣ x^3 - 3 ↔ x - 3 ∣ 24 :=\nbegin\n  have h : x-3∣x^3-27,\n  { use x^2+3*x+9,\n    ring, },\n  split,\n  { intro h1,\n    have h2 := dvd_sub h1 h,\n    convert h2,\n    ring },\n  { intro h1,\n    convert dvd_add h h1,\n    ring },\nend\n\nexample (a : ℤ) : a ∣ 24 ↔ a ∈ ({-1,-2,-3,-4,-6,-8,-12,-24,1,2,3,4,6,8,12,24} : set ℤ) :=\nbegin\n  split,\n  { intro h,\n    have h1 : a ≤ 24 := int.le_of_dvd (by norm_num) h,\n    have h2 : -a ∣ 24,\n    exact (neg_dvd a 24).mpr h,\n    have h3 : -a ≤ 24 := int.le_of_dvd (by norm_num) h2,\n    have h4 : -24 ≤ a := by linarith,\n--    interval_cases a,\n    sorry },\n  { intro h,\n    rcases h with (rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl | h);\n    try {norm_num},\n    change a = 24 at h,\n    rw h },\nend\n\n-- Thanks to Bhavik Mehta for showing me how to prove this in Lean\nlemma int_dvd_iff (x : ℤ) (n : ℤ) (hn : n ≠ 0) :\n  x ∣ n ↔ x.nat_abs ∈ n.nat_abs.divisors :=\nby simp [hn]\n\nexample (x : ℤ) : x ∣ 24 ↔ x ∈ ({-1,-2,-3,-4,-6,-8,-12,-24,1,2,3,4,6,8,12,24} : set ℤ) :=\nbegin\n  suffices : x ∣ 24 ↔ x.nat_abs ∈ ({1,2,3,4,6,8,12,24} : finset ℕ),\n  { simp only [this, int.nat_abs_eq_iff, set.mem_insert_iff, set.mem_singleton_iff,\n      finset.mem_insert, finset.mem_singleton],\n    norm_cast,\n    rw ←eq_iff_iff,\n    ac_refl },\n  exact int_dvd_iff _ 24 (by norm_num),\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/example02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8807970701552504, "lm_q1q2_score": 0.7636825509011804}}
{"text": "/- TACTICS -/\n\nnamespace TBA\n\n-- definitions from last week\n-- NOTE: We renamed it from `Nat'` for consistency. The new namespace makes sure we don't use the\n-- standard library `Nat`.\ninductive Nat : Type\n  | zero : Nat\n  | succ (n : Nat) : Nat\n\nopen Nat\n\ndef add (m n : Nat) : Nat :=\n  match n with\n  | zero   => m\n  | succ n => succ (add m n)\n\n-- With this command we add a notation for `add`. From now on we will be able to write `m + n` for\n-- `add m n`. The 65 denotes how strongly the operator should bind to what's adjacent to it.\n-- The `priority` means that Lean will prefer it over the built-in `+`.\ninfix:65 (priority := high) \" + \" => add\n\ndef mul (m n : Nat) : Nat :=\n  match n with\n  | zero   => zero\n  | succ n => (mul m n) + m\n\n-- We also want a notation for `mul`, with a higher binding strength than addition so that\n-- `a + b * c` means `a + (b * c`)`.\ninfix:70 (priority := high) \" * \" => mul\n\ninductive LE : Nat → Nat → Prop where\n  | refl (n : Nat) : LE n n\n  | succ : LE m n → LE m (succ n)\n\n-- lower binding strength than either addition or multiplication\ninfix:50 (priority := high) \" ≤ \" => LE\n\n-- Let's start by reproving some theorems from last week, but this time with tactics!\n-- useful tactics:\n-- * `induction ... with ...`\n-- * `simp only [f]` to unfold applications of a function `f`\n-- * `rw [h]` to rewrite every `a` to `b` if `h : a = b`\n-- * `apply/exact`\n-- * `simp/simp_all`... are powerful and basically always useful, though make sure that you could also\n--   do the proof without them\ntheorem zero_add : zero + n = n := by\n  induction n with\n  | zero      =>\n  | succ n ih =>\n\ntheorem le_add : m ≤ m + n := by\n\n-- Alright, let's start automating more!\nattribute [simp] add mul\n-- These definitions will now automatically be unfolded when you use `simp/simp_all`\n\n\n-- This one is a bit more tricky, you might need to prove a helper lemma!\ntheorem add_comm : n + m = m + n := by\n\n-- Associativity can be proven in a similar way.\ntheorem add_assoc : (m + n) + k = m + (n + k) := by\n\ndef one := succ zero\n\ntheorem mul_one : m * one = m := by\n\n-- To prove associativity of multiplication, you might have to come up with\n-- some more lemmas about multiplication first. Some are similar to the above laws of\n-- addition, some use both addition and multiplication (\"distributivity\" is the keyword).\n\ntheorem mul_assoc : (m * n) * k = m * (n * k) := by \n\n-- Remember the structures for semigroups and monoids which we defined last week?\nstructure Semigroup (α : Type) where\n  mul   : α → α → α\n  assoc : mul (mul a b) c = mul a (mul b c)\n\nstructure Monoid (α : Type) extends Semigroup α where\n  e     : α\n  e_mul : mul e a = a\n  mul_e : mul a e = a\n\n\n-- You should now be able to instantiate two of them,  including proofs!\ndef Nat_add_Monoid : Monoid Nat := _\n\ndef Nat_mul_Monoid : Monoid Nat := _\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/Exercise4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7636659885895236}}
{"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 6: `add_left_cancel`\n\nThe theorem `add_left_cancel` is the theorem that you can cancel on the left\nwhen you're doing addition -- if `t + a = t + b` then `a = b`.\nThere is a three-line proof which ends in `exact add_right_cancel a t b` (or even\n`exact add_right_cancel _ _ _`); this\nstrategy involves changing the goal to the statement of `add_right_cancel`.\n\n## Theorem : add_left_cancel\nOn the set of natural numbers, addition has the left cancellation property.\nIn other words, if there are natural numbers `a, b` and `t` such that\nif `t + a = t + b` then we have `a = b`.\n-/\ntheorem add_left_cancel (t a b : MyNat) : t + a = t + b → a = b := by\n  rw [add_comm]\n  rw [add_comm t]\n  exact add_right_cancel a t b\n\n\n/-!\nNext up [Level 7](./Level7.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/Level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620596782469, "lm_q2_score": 0.7956581000631542, "lm_q1q2_score": 0.7636424569162935}}
{"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 : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n-/\n\n-- In this section, u denotes a sequence of real numbers\n-- f is a function from ℝ to ℝ\n-- x₀ and l are real numbers\nvariables (u : ℕ → ℝ) (f : ℝ → ℝ) (x₀ l : ℝ)\n\n/- Negation of \"u tends to l\" -/\n-- 0062\nexample : ¬ (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε) ↔\n  ∃ ε > 0, ∀ N, ∃ n ≥ N, |u n - l| > ε\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is continuous at x₀\" -/\n-- 0063\nexample : ¬ (∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ →  |f x - f x₀| ≤ ε) ↔\n  ∃ ε > 0, ∀ δ > 0, ∃ x, |x - x₀| ≤ δ ∧ |f x - f x₀| > ε\n:=\nbegin\n  check_me,\nend\n\n/-\nIn the next exercise, we need to keep in mind that\n`∀ x x', ...` is the abbreviation of\n`∀ x, ∀ x', ... `.\n\nAlso, `∃ x x', ...` is the abbreviation of `∃ x, ∃ x', ...`.\n-/\n\n/- Negation of \"f is uniformly continuous on ℝ\" -/\n-- 0064\nexample : ¬ (∀ ε > 0, ∃ δ > 0, ∀ x x', |x' - x| ≤ δ →  |f x' - f x| ≤ ε) ↔\n  ∃ ε > 0, ∀ δ > 0, ∃ x x', |x' - x| ≤ δ ∧ |f x' - f x| > ε\n:=\nbegin\n  check_me,\nend\n\n/- Negation of \"f is sequentially continuous at x₀\" -/\n-- 0065\nexample : ¬ (∀ u : ℕ → ℝ, (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - x₀| ≤ ε) → (∀ ε > 0, ∃ N, ∀ n ≥ N, |(f ∘ u) n - f x₀| ≤ ε))  ↔\n  ∃ u : ℕ → ℝ,\n    (∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - x₀| ≤ ε) ∧\n    ∃ ε > 0, ∀ N, ∃ n ≥ N, |(f ∘ u) n - f x₀| > ε\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 : ℝ) : |x| ≤ y ↔ -y ≤ x ∧ x ≤ y\n\nge_max_iff (p q r) : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q\n\nle_max_left p q : p ≤ max p q\n\nle_max_right p q : q ≤ max p q\n\n/-- The sequence `u` tends to `+∞`. -/\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n-/\n\n-- 0066\nexample {u : ℕ → ℝ} : tendsto_infinity u → ∀ l, ¬ seq_limit u l :=\nbegin\n  intros tend l lim,\n  cases lim 1 (by linarith) with nlim hlim,\n  cases tend (l+2) with ntend htend,\n  let n := max nlim ntend,\n  specialize hlim n (le_max_left _ _),\n  specialize htend n (le_max_right _ _),\n  rw abs_le at hlim,\n  linarith,\nend\n\ndef nondecreasing_seq (u : ℕ → ℝ) := ∀ n m, n ≤ m → u n ≤ u m\n\n-- 0067\nexample (u : ℕ → ℝ) (l : ℝ) (h : seq_limit u l) (h' : nondecreasing_seq u) :\n  ∀ n, u n ≤ l :=\nbegin\n  intro n,\n  by_contradiction hc,\n  cases h ((u n - l)/2) (by linarith) with nlim hlim,\n  let n' := max n nlim,\n  specialize hlim n' (le_max_right _ _),\n  specialize h' n n' (le_max_left _ _),\n  rw abs_le at hlim,\n  linarith,\nend\n\n/-\nIn the following exercises, `A : set ℝ` means that A is a set of real numbers.\nWe can use the usual notation x ∈ A.\n\nThe notation `∀ x ∈ A, ...` is the abbreviation of `∀ x, x ∈ A → ... `\n\nThe notation `∃ x ∈ A, ...` is the abbreviation of `∃ x, x ∈ A ∧ ... `.\nMore precisely it is the abbreviation of `∃ x (H : x ∈ A), ...`\nwhich is Lean's strange way of saying `∃ x, x ∈ A ∧ ... `.\nYou can convert between these forms using the lemma\n  exists_prop {p q : Prop} : (∃ (h : p), q) ↔ p ∧ 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 ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ 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 ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\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 : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y - x) / 2,\n  split; linarith,\nend\n\n-- 0070\nexample {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all',\n  intros ε ε_pos,\n  cases hu ε ε_pos with n hn,\n  specialize hn n (by linarith),\n  rw abs_le at hn,\n  linarith [ineg n],\nend\n\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/tutorials/src/exercises/08_limits_negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7636202286142701}}
{"text": "variables AA AB AP MA MB MP CA CB CP : Prop\n\n--estas variáveis são suposições naturais. \n--Existem várias outras, mas não são necessárias no momento. \nvariables (h1 : AP ↔ ¬ AA ∧ ¬ AB)\n          (h2 : AA ↔ ¬ AB ∧ ¬ AP)\n          (h3 : AB ↔ ¬ AA ∧ ¬ AP)\n          (h4 : MB ↔ ¬ AB ∧ ¬ CB)\n          (h5 : MA ↔ (AP ∧ CB) ∨ (AB ∧ CP))\n\n-- estas variáveis são as falas, vistas do ponto de Ana.\n-- Como Ana sempre diz a verdade, todas essas afirmações são verdadeiras.\n-- Considerar as falas de Maria não faz sentido do ponto de vista lógico. \nvariables (f1: AA → AB)\n          (f2: AB → MB)\n          (f3: AP → CB)\n\ndef triple_and(A B C: Prop): Prop :=\n(A ∧ B) ∧ C\n\nexample : triple_and AP CB MA :=  -- quero provar que Ana usa preto, \n                                  -- Cláudia usa branco e \n                                  -- Maria usa azul\nhave  a1: ¬ AA, from\n   assume a2: AA, \n   have a3: AB, from f1 a2,\n   have a4: ¬AA, from and.left (iff.elim_left h3 a3),\n   show false, from a4 a2,\n   \nhave a5: ¬ AB, from \n  assume a6: AB, \n  have a7: MB, from f2 a6,\n  have a8: ¬ AB, from and.left (iff.elim_left h4 a7),\n  show false, from a8 a6,\n\nhave a9: AP, from iff.elim_right h1 (and.intro a1 a5),\n\nhave c1: CB, from f3 a9,\n\nhave u1: AP ∧ CB, from and.intro a9 c1,\n\nhave m1: MA, from iff.elim_right h5 (or.inl u1),\n\nshow (AP ∧ CB) ∧ MA, from and.intro u1 m1\n\n", "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 2/vestidos-LucasMoschen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7636192413268379}}
{"text": "/-\nCopyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël Dillies, Bhavik Mehta\n-/\nimport algebra.big_operators.order\nimport combinatorics.simple_graph.density\n\n/-!\n# Energy of a partition\n\nThis file defines the energy of a partition.\n\nThe energy is the auxiliary quantity that drives the induction process in the proof of Szemerédi's\nRegularity Lemma. As long as we do not have a suitable equipartition, we will find a new one that\nhas an energy greater than the previous one plus some fixed constant.\n-/\n\nopen finset\nopen_locale big_operators\n\nvariables {α : Type*} [decidable_eq α] {s : finset α} (P : finpartition s) (G : simple_graph α)\n  [decidable_rel G.adj]\n\nnamespace finpartition\n\n/-- The energy of a partition, also known as index. Auxiliary quantity for Szemerédi's regularity\nlemma.  -/\ndef energy : ℚ := (∑ uv in P.parts.off_diag, G.edge_density uv.1 uv.2 ^ 2) / P.parts.card ^ 2\n\nlemma energy_nonneg : 0 ≤ P.energy G :=\ndiv_nonneg (finset.sum_nonneg $ λ _ _, sq_nonneg _) $ sq_nonneg _\n\nlemma energy_le_one : P.energy G ≤ 1 :=\ndiv_le_of_nonneg_of_le_mul (sq_nonneg _) zero_le_one $\n  calc ∑ uv in P.parts.off_diag, G.edge_density uv.1 uv.2^2\n        ≤ P.parts.off_diag.card • 1\n        : sum_le_card_nsmul _ _ 1 $ λ uv _, (sq_le_one_iff $ G.edge_density_nonneg _ _).2 $\n            G.edge_density_le_one _ _\n    ... = P.parts.off_diag.card : nat.smul_one_eq_coe _\n    ... ≤ _ : by { rw [off_diag_card, one_mul, ←nat.cast_pow, nat.cast_le, sq], exact tsub_le_self }\n\nend finpartition\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/regularity/energy.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7634166729932831}}
{"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önne, 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 : ℂ} (h : cos x ≠ 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 ← sin_sq_add_cos_sq x,\n  ring,\nend\n\nlemma has_deriv_at_tan {x : ℂ} (h : cos x ≠ 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 : ℂ} (hx : cos x = 0) :\n  tendsto (λ x, abs (tan x)) (𝓝[{x}ᶜ] x) at_top :=\nbegin\n  simp only [tan_eq_sin_div_cos, ← norm_eq_abs, normed_field.norm_div],\n  have A : sin x ≠ 0 := λ h, by simpa [*, sq] using sin_sq_add_cos_sq x,\n  have B : tendsto cos (𝓝[{x}ᶜ] (x)) (𝓝[{0}ᶜ] 0),\n  { refine tendsto_inf.2 ⟨tendsto.mono_left _ inf_le_left, tendsto_principal.2 _⟩,\n    exacts [continuous_cos.tendsto' x 0 hx,\n      hx ▸ (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 : ℤ) :\n  tendsto (λ x, abs (tan x)) (𝓝[{(2 * k + 1) * π / 2}ᶜ] ((2 * k + 1) * π / 2)) at_top :=\ntendsto_abs_tan_of_cos_eq_zero $ cos_eq_zero_iff.2 ⟨k, rfl⟩\n\n@[simp] lemma continuous_at_tan {x : ℂ} : continuous_at tan x ↔ cos x ≠ 0 :=\nbegin\n  refine ⟨λ hc h₀, _, λ h, (has_deriv_at_tan h).continuous_at⟩,\n  exact not_tendsto_nhds_of_tendsto_at_top (tendsto_abs_tan_of_cos_eq_zero h₀) _\n    (hc.norm.tendsto.mono_left inf_le_left)\nend\n\n@[simp] lemma differentiable_at_tan {x : ℂ} : differentiable_at ℂ tan x ↔ cos x ≠ 0 :=\n⟨λ h, continuous_at_tan.1 h.continuous_at, λ h, (has_deriv_at_tan h).differentiable_at⟩\n\n@[simp] lemma deriv_tan (x : ℂ) : deriv tan x = 1 / (cos x)^2 :=\nif h : cos x = 0 then\n  have ¬differentiable_at ℂ 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 : ℂ} {n : with_top ℕ} :\n  times_cont_diff_at ℂ n tan x ↔ cos x ≠ 0 :=\n⟨λ 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⟩\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/trigonometric/complex_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096090086367, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7634166672925129}}
{"text": "/- AND\n-- X, Y ⊢ X ∧ Y              -- and introduction\n-- X ∧ Y ⊢ X                 -- and elimination left\n-- X ∧ Y ⊢ Y                 -- and elimination right\n-/\n#check @and.intro       -- ∀ {a b : Prop}, a → b → a ∧ b\n#check @and.elim_left   -- ∀ {a b : Prop}, a ∧ b → a\n#check @and.elim_right  -- ∀ {a b : Prop}, a ∧ b → b\n\n\n\n/- OR\n-- X ⊢ X ∨ Y                -- or introduction left\n-- Y ⊢ X ∨ Y                -- or introduction right\n-- X ∨ Y, X → Z, Y → Z ⊢ Z  -- or elimination\n-/\n#check @or.inl          -- ∀ {a b : Prop}, a → a ∨ b\n#check @or.inr          -- ∀ {a b : Prop}, b → a ∨ b\n#check @or.intro_left   -- ∀ {a : Prop} (b : Prop), a → a ∨ b\n#check @or.intro_right  -- ∀ (a : Prop) {b : Prop}, b → a ∨ b\n#check @or.elim         -- ∀ {a b c : Prop}, a ∨ b → (a → c) → (b → c) → c\n\n/-\nUse inl or inr when Lean can infer the other disjunct,\notherwise use intro_left or intro_right, where you have\nto give the other disjunct (a proposition, not a proof)\nas an explicit argument.\n-/\n\n/- FORALL, ARROW\nArrow is a special case of ∀ in Lean, and ∀ is built\ninto the very core of the logic. There are no rules\ncalled forall.intro or forall.elim. Rather, you prove\na forall or arrow proposition by *defining a function*\nthat takes a value/proof of the premise/argument and\nthat returns a value/proof of the conclusion. On the\nother hand, forall/arrow elimination is by *applying*\nsuch a \"function/proof\" to an argument of the right \nkind to obtain a result of the right kind.\n\nInsight: Whenever you define a function (in Python,\nfor example), you declare formal parameters (arguments)\nand then, within the body of the function, you *assume*\nthat you've been given actual parameter values of the\nright types, and then you write a that constructs and\nreturns a result of the right type . That is exactly\nwhat you're doing when you use forall/arrow introduction: \nassume you've been given actual arguments of the right\ntypes then  show that you can construct and return a \nvalue of the specified \"return\" type. This works in\nLean whether the types and values you're working with\nare computational (numbers, strings, etc) or logical\n(propositions, proofs). \n-/\n\n/-\nThere are several formats for writing functions in \nLean. Let's start with a computational example: a\nsimple function that takes a string, str, and returns\nits length. The following four definitions are all\nequivalent!\n-/\n\n-- use → introduction\ndef slength1 : string → nat :=\nbegin\nassume (str : string),  -- assume given s of type string\nexact (str.length)      -- defined in Lean's libraries\nend\n\ndef slength2 : string → nat \n| str := str.length     -- matches str to first argument\n\n-- ∀ introduction\ndef slength3 : ∀ (s : string), nat :=\nbegin\nintro str,              -- assume given (str : string)\nexact (str.length)      -- defined in Lean's libraries\nend\n\n-- almost ordinary function definition\n-- argument declared/named *before* the color\ndef slength4 (str : string) : nat := \nbegin\n  exact str.length\nend\n\n-- Python/C++ style\ndef slength5 (str : string) : nat := str.length\n\n-- ∀/→ introduction is function definition\n-- ∀/→ elimination is function application \n\n#eval slength1 \"Lean is actually very cool!\"\n#eval slength2 \"Lean is actually very cool!\"\n#eval slength3 \"Lean is actually very cool!\"\n#eval slength4 \"Lean is actually very cool!\"\n#eval slength5 \"Lean is actually very cool!\"\n\n/-\nAnd of course it works for logical types and\nproofs just as well as for data/computational\ntypes and ordinary data values. Here are three\nways to prove that any proposition P implies\ntrue, for example.\n-/\n\n-- Using → \nlemma foo0 : Prop → true :=\nbegin\n  assume (P : Prop),  -- bind name to assume argument\n  exact true.intro    -- return result of right type (true)\nend\n\nlemma foo1 : Prop → true\n| P := true.intro\n\n-- Using ∀ \nlemma foo2 : ∀ (P : Prop), true :=\nbegin \nintro P,          \nexact true.intro, \nend\n\n-- Python/C style but using script to generate proof \"term\"\nlemma foo3 (P : Prop) : true :=\nbegin\nexact true.intro\nend\n\n-- Python/C style returning exact proof term\nlemma foo4 (P : Prop) : true := true.intro\n\n-- Each function is a proof of Prop → true\n#check foo0\n#check foo1\n#check foo2\n#check foo3\n\n\n\n/- NOT\n-- ¬X means (X → false)   -- negation introduction\n-- ¬¬X ⊢ X                -- negation elimination \n-/\n-- introduction: to prove ¬X, use → introduction\n-- (double) ¬ elimination is proof by contradiction \n#check @classical.by_contradiction  -- ∀ {p : Prop}, (¬p → false) → p\n\n\n/- IFF\n-- X → Y, Y → X ⊢ X ↔ Y     -- iff introduction\n-- X ↔ Y ⊢ X → Y            -- iff elimination left\n-- X ↔ Y ⊢ Y → X            -- iff elimination right\n-/\n#check @iff.intro     -- ∀ {a b : Prop}, (a → b) → (b → a) → (a ↔ b)\n#check @iff.mp        -- ∀ {a b : Prop}, (a ↔ b) → a → b\n#check @iff.mpr       -- ∀ {a b : Prop}, (a ↔ b) → b → a\n\n\n/- EXISTS\n\nThe one remaining set of inference rules we have\nto cover are for ∃. We will cover them after the\nmid-term.\n-/\n\n/-\nYay! Except for exists, you have now learned *all* of the\ninference rules of higher-order predicate logic in Lean, \nwhich are all also inference rules in classical first-order\nlogic.  Yay, again! Good work.\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_inference_rules_in_Lean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480248488136, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7633884769677157}}
{"text": "import algebra.big_operators data.fintype\nimport tactic.ring\n\n-- https://xenaproject.wordpress.com/2018/03/30/proofs-by-induction/\n\nopen nat\n\ndef odd : ℕ → ℕ := λ i, 2 * i + 1\ndef square : ℕ → ℕ := λ i, i ^ 2\ntheorem odd_square_inductive_step (d : ℕ) :\n  square d + odd d = square (succ d) :=\nby dsimp [square, odd, pow]; rw [succ_eq_add_one]; ring\n\nnamespace def1\n\ndefinition my_sum_to_n (summand : ℕ → ℕ) : ℕ → ℕ\n| 0 := 0\n| (succ n) := my_sum_to_n n + summand n\n\ntheorem my_zero_theorem (summand : ℕ → ℕ) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\ntheorem my_successor_theorem (summand : ℕ → ℕ) (n : ℕ) :\n  my_sum_to_n summand (succ n) = my_sum_to_n summand n + summand n :=\nrfl\n\ntheorem my_odd_square_theorem : ∀ (n : ℕ), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by unfold my_sum_to_n; rw [my_odd_square_theorem n]; exact odd_square_inductive_step n\n\nend def1\n\nnamespace def2\n\ndefinition my_sum_to_n (summand : ℕ → ℕ) : ℕ → ℕ :=\nλ n, ((list.range n).map summand).sum\n\ntheorem my_zero_theorem (summand : ℕ → ℕ) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\ntheorem my_successor_theorem (summand : ℕ → ℕ) (n : ℕ) :\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 : ∀ (n : ℕ), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by rw [my_successor_theorem, my_odd_square_theorem n]; exact odd_square_inductive_step n\n\nend def2\n\nnamespace def3\n\ndefinition my_sum_to_n (summand : ℕ → ℕ) : ℕ → ℕ :=\nλ n, (finset.range n).sum summand\n\ntheorem my_zero_theorem (summand : ℕ → ℕ) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\ntheorem my_successor_theorem (summand : ℕ → ℕ) (n : ℕ) :\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 : ∀ (n : ℕ), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by rw [my_successor_theorem, my_odd_square_theorem n]; 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 : ℕ) (f : ℕ → ℕ) (g : fin n → ℕ) (h : ∀ i : fin n, f i.1  = g i) :\n    (range n).sum f = univ.sum g :=\nsum_bij\n  (λ i h, ⟨i, mem_range.1 h⟩)\n  (λ i h, mem_univ _)\n  (λ a ha, h ⟨a, _⟩)\n  (λ _ _ _ _, fin.veq_of_eq)\n  (λ ⟨b, hb⟩ _, ⟨b, mem_range.2 hb, rfl⟩)\n\ndefinition my_sum_to_n (summand : ℕ → ℕ) : ℕ → ℕ :=\nλ n, (@finset.univ (fin n) _).sum (summand ∘ fin.val)\n\ntheorem my_zero_theorem (summand : ℕ → ℕ) :\n  my_sum_to_n summand 0 = 0 :=\nrfl\n\n-- Credits to Mario Carneiro\ntheorem my_successor_theorem (summand : ℕ → ℕ) (n : ℕ) :\n  my_sum_to_n summand (succ n) = my_sum_to_n summand n + summand n :=\nby unfold my_sum_to_n;\nrw [← chris _ _ _ (λ _, rfl), ← chris _ _ _ (λ _, rfl)]; simp\n\ntheorem my_odd_square_theorem : ∀ (n : ℕ), my_sum_to_n odd n = square n\n| 0        := rfl\n| (succ n) := by rw [my_successor_theorem, my_odd_square_theorem n]; 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 $ λ summand, funext $ λ n, nat.rec_on n rfl $\nλ 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 $ λ summand, funext $ λ n, nat.rec_on n rfl $\nλ 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 $ λ summand, funext $ λ n, nat.rec_on n rfl $\nλ m ih, by rw [def3.my_successor_theorem, def4.my_successor_theorem, ih]\n\nend equality\n", "meta": {"author": "kckennylau", "repo": "Lean", "sha": "907d0a4d2bd8f23785abd6142ad53d308c54fdcb", "save_path": "github-repos/lean/kckennylau-Lean", "path": "github-repos/lean/kckennylau-Lean/Lean-907d0a4d2bd8f23785abd6142ad53d308c54fdcb/proofs_by_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7633616878434777}}
{"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\n! This file was ported from Lean 3 source module data.nat.periodic\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.Algebra.Periodic\nimport Mathlib.Data.Nat.Count\nimport Mathlib.Data.Nat.Interval\n\n/-!\n# Periodic Functions on ℕ\n\nThis file identifies a few functions on `ℕ` which are periodic, and also proves a lemma about\nperiodic predicates which helps determine their cardinality when filtering intervals over them.\n-/\n\n\nnamespace Nat\n\nopen Nat Function\n\ntheorem periodic_gcd (a : ℕ) : Periodic (gcd a) a := by\n  simp only [forall_const, gcd_add_self_right, eq_self_iff_true, Periodic]\n#align nat.periodic_gcd Nat.periodic_gcd\n\ntheorem periodic_coprime (a : ℕ) : Periodic (coprime a) a := by\n  simp only [coprime_add_self_right, forall_const, iff_self_iff, eq_iff_iff, Periodic]\n#align nat.periodic_coprime Nat.periodic_coprime\n\ntheorem periodic_mod (a : ℕ) : Periodic (fun n => n % a) a := by\n  simp only [forall_const, eq_self_iff_true, add_mod_right, Periodic]\n#align nat.periodic_mod Nat.periodic_mod\n\ntheorem Function.Periodic.map_mod_nat {α : Type _} {f : ℕ → α} {a : ℕ} (hf : Periodic f a) :\n    ∀ n, f (n % a) = f n := fun n => by\n  conv_rhs => rw [← Nat.mod_add_div n a, mul_comm, ← Nat.nsmul_eq_mul, hf.nsmul]\n#align function.periodic.map_mod_nat Nat.Function.Periodic.map_mod_nat\n\nsection Multiset\n\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. -/\ntheorem filter_multiset_Ico_card_eq_of_periodic (n a : ℕ) (p : ℕ → Prop) [DecidablePred p]\n    (pp : Periodic p a) : card (filter p (Ico n (n + a))) = a.count p := by\n  rw [count_eq_card_filter_range, Finset.card, Finset.filter_val, Finset.range_val, ←\n    multiset_Ico_map_mod n, ← map_count_True_eq_filter_card, ← map_count_True_eq_filter_card,\n    map_map]\n  congr; funext n\n  exact (Function.Periodic.map_mod_nat pp n).symm\n#align nat.filter_multiset_Ico_card_eq_of_periodic Nat.filter_multiset_Ico_card_eq_of_periodic\n\nend Multiset\n\nsection Finset\n\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. -/\ntheorem filter_Ico_card_eq_of_periodic (n a : ℕ) (p : ℕ → Prop) [DecidablePred p]\n    (pp : Periodic p a) : ((Ico n (n + a)).filter p).card = a.count p :=\n  filter_multiset_Ico_card_eq_of_periodic n a p pp\n#align nat.filter_Ico_card_eq_of_periodic Nat.filter_Ico_card_eq_of_periodic\n\nend Finset\n\nend Nat\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/Nat/Periodic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088025362857, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7633276301712418}}
{"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\n\n/-\n\n# Representation theory\n\nThere are two ways to do representation theory -- the way you might guess\n(involving vector spaces `(V : Type) [add_comm_group V] [module k V]`) and\na funkier way using category theory. Let's start with the vector space way.\n\n## `representation k G V`\n\nLet `k` be a field (or a commutative ring), let `G` be a group (or a monoid)\nand let `V` be a vector space (or module) over `k`. \n\nThen `representation k G V` is the type of representations of `G` on `V`,\nwhere `G` acts `k`-linearly. It's not a class, because one group `G` can act\nin more than one way on a vector space `V`.\n\n-/\n\n-- Let k be a field, G a group and V a k-vector space\nvariables (k : Type) [field k] (G : Type) [group G] \n  (V : Type) [add_comm_group V] [module k V]\n\n-- Let `ρ` be a representation of `G` on `V`.\nvariable (ρ : representation k G V)\n\n-- If `g : G` and `v : V` then `ρ(g)v` is done like this:\n\nvariables (g : G) (v : V)\n\nexample : V := ρ g v\n\n-- Here are the names of some basic lemmas\n\nvariables (h : G) (w : V) (c : k)\n\nexample : ρ g (v + w) = ρ g v + ρ g w := map_add (ρ g) v w\nexample : ρ g (c • w) = c • ρ g w := (ρ g).map_smul c w\n\n-- I was quite surprised to find that this doesn't seem to be in the library\nexample : ρ (g * h) v = ρ g (ρ h v) := \nbegin\n  rw map_mul,\n  rw linear_map.mul_apply,\nend\n\n/- Let's talk about this previous proof. `map_mul` is the statement that if `f`\nis a group homomorphism then `f(g*h)=f(g)*f(h)`. What is happening is that\nthe definition of `representation` is this:\n\n`abbreviation representation := G →* (V →ₗ[k] V)`\n\nWhat's going on here? `V →ₗ[k] V` is the type of `k`-linear maps from `V` to `V`.\nThis space has a multiplication, given by function composition (composite of two\nlinear maps is a linear map). This doesn't make it a group! Maps like the zero map\nhave no inverse (if dim(V)>0). But it does have an identity, namely the \nidentity map from `V` to `V`. So it is a monoid, which is a \"group without inverses\". \nAnd `G →* (V →ₗ[k] V)` means the `*`-preserving maps from `G` to `V →ₗ[k] V`, or\nthe monoid homomorphisms if you'd rather, so it's maps `ρ` satisfying `ρ(gh)=ρ(g)*ρ(h)`,\nor in other words `ρ(gh)=ρ(g)∘ρ(h)`. If two functions are equal, then they take the\nsame values everywhere, so we deduce that for all `v`, `ρ(gh)(v)=ρ(g)(ρ(h)v)`, and\nthat should be what the proof looks like in Lean. \n\nIf `representation` were defined as a `def` then this proof wouldn't work, because\n`representation k G V` would be definitionally, but not syntactically, `G →* (V →ₗ[k] V)`,\nand the `rw` tactic works up to syntactic equality. One would have to start with\nthe line `unfold representation` to get `rw map_mul` to work. But because it's\ndefined as an `abbreviation`, this means that Lean *does* unfold it internally. \nLean has three kinds of \"reducibility settings\" for definitions. There is `irreducible`,\nwhich means \"never unfold\", there is `semireducible`, which is the default, and so\nthe behaviour that you're used to, and there is `reducible`, which basically means \n\"unfold the moment you think it might help\". Making a definition with `abbreviation`\nmakes it `reducible`. So the rewrite works anyway.\n\nNote that the proof of `linear_map.mul_apply` is `refl`, because `f ∘ g` is *defined*\nto mean `λ x, f (g x)`, so `(f ∘ g) (x) = f (g x)` is definitionally true. So this\nproof works as well:\n\n-/\n\nexample : ρ (g * h) v = ρ g (ρ h v) := \nbegin\n  rw map_mul,\n  -- ⊢ `⇑(⇑ρ g * ⇑ρ h) v = ⇑(⇑ρ g) (⇑(⇑ρ h) v)`\n  -- and note `ρ g * ρ h` is definitionally `ρ g ∘ ρ h`,\n  -- which is definitionally `λ v, (ρ g) (ρ h v)`. So this works:\n  refl,\nend\n\n-- Let's make a representation! Because internally it's a group homomorphism,\n-- which is a structure, we just have to fill in the fields. Let's start with\n-- the trivial representation.\n\nexample : representation k G V :=\n{ to_fun := λ g, 1,\n  map_one' := rfl,\n  map_mul' := λ g h, by simp }\n\n-- If we have a group homomorphism `χ : G → kˣ` then we can make a representation\n-- of `G` on `V` by defining ρ(g)v=χ(g)•v.\n\nexample (χ : G →* kˣ) : representation k G V :=\n{ to_fun := λ g, \n  { to_fun := λ v, (χ g) • v,\n    map_add' := smul_add (χ g),\n    map_smul' := begin\n      intros,\n      simp only [smul_comm (χ g) r x, ring_hom.id_apply],\n    end },\n  map_one' := begin\n    ext v,\n    simp,\n  end,\n  map_mul' := begin\n    intros g h,\n    ext v,\n    dsimp,\n    simp only [map_mul, mul_smul],\n  end }\n\n/- If `G` is finite then `G → k` is a vector space with a natural basis indexed by `G`:\n   for `g : G` define the function `δᵍ : G → k` sending `g` to `1` and everything else to `0`,\n   and then the `δᵍ` are a basis. Now `G` acts naturally on these basis elements\n   and hence gives us a representation of `G` on this space. Note that I've done the\n   typical mathematician's thing of leaving out some of the details. See if you can\n   work them out. -/\n\n  example : representation k G (G → k) :=\n  { to_fun := λ g, \n    { to_fun := λ f h, f (h * g),\n      map_add' := λ φ ψ, begin\n        ext j,\n        refl,\n      end,\n      map_smul' := λ r f, begin\n        ext h,\n        simp,\n      end },\n  map_one' := begin\n    intros, ext, simp,\n  end,\n  map_mul' := begin\n    intros g h,\n    ext f j,\n    simp [mul_assoc],\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/section20representation_theory/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320945, "lm_q2_score": 0.8221891392358014, "lm_q1q2_score": 0.7633276260731314}}
{"text": "import definitions\nimport point3\n\n-- 2F(m+n) = F(m) L(n) + L(m) F(n)\nlemma two_mul_Fib_add (m n : ℤ) : 2 * Fib (m + n) = Fib m * Luc n + Luc m * Fib n :=\nby rw [Fib, Fib, Fib, Luc, Luc, gpow_add, units.coe_mul, Zalpha.mul_r, two_mul];\n  rw [α_Fib, α_Fib, β_Fib, β_Fib];\n  have Hm := Fib_add_two (m-1);\n  have Hn := Fib_add_two (n-1);\n  rw [bit0, ← add_assoc, sub_add_cancel] at Hm Hn;\n  simp [Hm, Hn, mul_add, add_mul]\n\nlemma two_mul_fib_add (m n : ℕ) : 2 * fib (m + n) = fib m * luc n + luc m * fib n :=\nint.coe_nat_inj $ by rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_mul, int.coe_nat_mul];\n  rw [← fib_down, ← fib_down, ← fib_down, ← luc_down, ← luc_down, ← two_mul_Fib_add]; refl\n\n-- L(4n) + 2 = L(2n)^2\nlemma Luc_four_mul (n : ℤ) : Luc (4 * n) = Luc (2 * n) * Luc (2 * n) - 2 :=\nZalpha.of_int_inj.1 $ by have := Luc_αβ; simp at this;\n  simp [this, add_mul, mul_add];\n  rw [← units.coe_mul, ← units.coe_mul, ← units.coe_mul, ← units.coe_mul];\n  rw [← mul_gpow, ← mul_gpow, ← mul_gpow, ← mul_gpow]; simp;\n  rw [gpow_mul (-1 : units ℤα)];\n  have : (-1 : units ℤα)^(2:ℤ) = 1 := rfl;\n  simp [this]; rw [bit0, add_mul, gpow_add, gpow_add, mul_gpow, mul_gpow]; ring\n\nlemma luc_four_mul (n : ℕ) : luc (4 * n) + 2 = luc (2 * n) * luc (2 * n) :=\nint.coe_nat_inj $ begin\n  simp, rw [← luc_down, ← luc_down],\n  change (2 : ℤ) + Luc (4 * n) = _,\n  rw [Luc_four_mul]; ring end\n\n-- F(2n) = F(n) L(n)\nlemma fib_two_mul (n : ℕ) : fib (2 * n) = fib n * luc n :=\nnat.bit0_inj $ by rw [bit0, ← two_mul, two_mul n, two_mul_fib_add, mul_comm]; refl\n\n-- L(2n) ∣ 2(F(m+4n) + F(m))\nlemma luc_two_mul_dvd (m n : ℕ) : luc (2 * n) ∣ 2 * (fib (m + 4 * n) + fib m) :=\n⟨luc (2 * n) * fib m + luc m * fib (2 * n),\nby rw [mul_add, mul_add, two_mul_fib_add, mul_comm (fib m), add_right_comm, ← add_mul, luc_four_mul];\nconv in (4 * n) { change ((2 * 2) * n) };\nrw [mul_assoc 2, fib_two_mul]; ac_refl⟩\n\n-- TODO: if ¬(3 ∣ n) then fib (m + 4*n) ≡ −fib m [MOD (luc (2*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/point6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248242542283, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7633025838890385}}
{"text": "open classical\n\nvariables p q r s : Prop\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p := begin\n    apply iff.intro,\n    intro h,\n    split,\n        apply and.right,\n        exact h,\n        apply and.left,\n        exact h,\n    intro h,\n    split,\n        apply and.right,\n        exact h,\n    apply and.left,\n    exact h,\nend\n\nexample : p ∨ q ↔ q ∨ p := begin\n    apply iff.intro,\n    intro h,\n    cases h with hp hq,\n    right,\n    exact hp,\n    left,\n    exact hq,\n    intro h,\n    cases h with hq hp,\n    right,\n    exact hq,\n    left,\n    exact hp,\nend\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := begin\n    apply iff.intro,\n    intro h,\n    apply and.intro,\n    apply and.left,\n    apply and.left,\n    exact h,\n    apply and.intro,\n    exact (and.right (and.left h)),\n    exact (and.right h),\n    intro h,\n    split,\n    split,\n    exact (and.left h),\n    exact (and.left (and.right h)),\n    exact (and.right (and.right h))\nend\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := begin\n    split,\n    intro h,\n    cases h with a b,\n    cases a with c d,\n    left, assumption,\n    right, left, assumption,\n    right, right, assumption,\n    intro h,\n    cases h with a b,\n    left, left, assumption,\n    cases b with c d,\n    left, right, assumption,\n    right, assumption\nend\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := begin\n    split,\n    intros,\n    have h : q ∨ r, from and.right a,\n    cases h with hq hr,\n    left,\n    split,\n    exact (and.left a),\n    assumption,\n    right,\n    split,\n    exact (and.left a),\n    assumption,\n    intros,\n    cases a,\n    split,\n    exact (and.left a),\n    left,\n    exact (and.right a),\n    split,\n    exact (and.left a),\n    right,\n    exact (and.right a),\nend\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := begin\n    split,\n    intros,\n    split,\n    cases a with b c,\n    apply or.inl,\n    assumption,\n    apply or.inr,\n    apply and.left,\n    assumption,\n    cases a with b c,\n    apply or.inl,\n    assumption,\n    exact or.inr (and.right c),\n    intro a,\n    have h : p ∨ q,\n    from and.left a,\n    have i : p ∨ r,\n    from and.right a,\n    cases h with b c,\n    exact or.inl b,\n    cases i with d e,\n    exact or.inl d,\n    exact or.inr (and.intro c e)\nend\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := begin\n    split,\n    intros h i,\n    simp *,\n    intros h i j,\n    simp *\nend\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := begin\n    split,\n    show ((p ∨ q) → r) → (p → r) ∧ (q → r), begin\n        intro a,\n        split,\n        intro b,\n        simp *,\n        intro b,\n        simp *,\n    end,\n    show (p → r) ∧ (q → r) → ((p ∨ q) → r), begin\n        intros a b,\n        have al : p → r,\n        from and.left a,\n        have ar : q → r,\n        from and.right a,\n        exact or.elim b al ar,\n    end\nend\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := sorry\nexample : ¬p ∨ ¬q → ¬(p ∧ q) := sorry\nexample : ¬(p ∧ ¬p) := sorry\nexample : p ∧ ¬q → ¬(p → q) := sorry\nexample : ¬p → (p → q) := sorry\nexample : (¬p ∨ q) → (p → q) := sorry\nexample : p ∨ false ↔ p := sorry\nexample : p ∧ false ↔ false := sorry\nexample : ¬(p ↔ ¬p) := sorry\nexample : (p → q) → (¬q → ¬p) := sorry\n\n-- these require classical reasoning\nopen classical\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) := sorry\nexample : ¬(p ∧ q) → ¬p ∨ ¬q := sorry\nexample : ¬(p → q) → p ∧ ¬q := sorry\nexample : (p → q) → (¬p ∨ q) := sorry\nexample : (¬q → ¬p) → (p → q) := sorry\nexample : p ∨ ¬p := begin\n    exact em p\nend\n\nexample : (((p → q) → p) → p) := \n    λ a : (p → q) → p,\n    begin\n        have h : p ∨ ¬ p, from em p,\n        cases h with hl hr,\n        show p,\n            from hl,\n        show p,\n            from a (λb : p, false.elim (hr b))\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/tactics-ex3.6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7632899545295451}}
{"text": "import MyNat\nimport MyNat.proposition_world\n\nopen MyNat\n\nexample (P Q : Prop) (p : P) (q : Q) : P ∧ Q := by\n  constructor \n  exact p\n  exact q\n\nlemma and_symm (P Q : Prop) : P ∧ Q → Q ∧ P := by\n  intro h\n  cases h with\n  | intro p q =>\n    constructor\n    exact q\n    exact p\n\nlemma and_trans (P Q R : Prop) : P ∧ Q → Q ∧ R → P ∧ R := by\n  intro h1 h2\n  cases h1 with \n  | intro p q => \n  cases h2 with \n  | intro q r =>\n  constructor\n  exact p\n  exact r\n\nlemma iff_trans (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := by\n  intro h1 h2\n  cases h1 with\n  | intro pq qp => \n  cases h2 with\n  | intro qr rq => \n  constructor\n  intro p\n  exact (qr (pq p))\n  intro r\n  exact (qp (rq r))\n\nexample (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := by\n  intro hpq hqr\n  constructor \n  intro p\n  apply (Iff.mp hqr)\n  apply (Iff.mp hpq)\n  exact p\n  intro r\n  rewrite [hpq, hqr]\n  exact r\n\nexample (P Q : Prop) : Q → (P ∨ Q) := by\n intro q\n exact (Or.inr q)\n\nlemma or_symm (P Q : Prop) : P ∨ Q -> Q ∨ P := by\n  intro pq\n  exact (\n    Or.elim \n    pq\n    (Or.inr)\n    (Or.inl)\n  ) \n\nlemma alexs_discovery (P Q R : Prop) : \n  P → (P ∨ Q) ∧ (P ∨ R) := by\n  intro p\n  exact ⟨Or.inl p, Or.inl p⟩\n\nlemma and_or_distrib_left (P Q R : Prop) : \n  P ∧ (Q ∨ R) ↔ (P ∧ Q) ∨ (P ∧ R) := by\n  constructor \n  intro p_and_qr\n  let p := (p_and_qr.left)\n  let qr := (p_and_qr.right)\n  exact (\n    Or.elim qr\n    (fun q => Or.inl (And.intro p q))\n    (fun r => Or.inr (And.intro p r))\n  )\n  intro p_and_q_or_p_and_r\n  exact (\n    Or.elim p_and_q_or_p_and_r\n    (fun pq => \n      And.intro pq.left (Or.inl pq.right)\n    )\n    (fun pr =>\n      And.intro pr.left (Or.inr pr.right)\n    )\n  )\n\nlemma contra (P Q : Prop) : (P ∧ ¬ P) → Q := by\n  intro pandnotp\n  let p := pandnotp.left\n  let notp := pandnotp.right\n  -- rewrite [not_iff_imp_false] at notp\n  -- let false := (notp p)\n  -- exact False.elim false\n  exact (absurd p notp)\n\nlemma contrapositive2 (P Q : Prop) : \n  (¬Q → ¬P) → (P → Q) := by \n  intro h p\n  by_cases p : P\n  case inl p' => \n    . by_cases q : Q\n      . case inl => exact q\n      . case inr => exact absurd p (h q)\n  case inr p' => \n    . by_cases q : Q\n      . case _ => exact q\n      . case inr => exact absurd p' p\n\nlemma full_contrapositive (P Q : Prop) : \n  (¬Q → ¬P) ↔ (P → Q) := by\n  constructor\n  exact contrapositive2 P Q\n  exact contrapositive  P Q", "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_proposition_world.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7632782912422252}}
{"text": "/- LoVe Demo 2: Tactical Proofs -/\n\nimport .love01_definitions_and_lemma_statements_demo\n\nnamespace LoVe\n\n\n/- Tactic Mode -/\n\nlemma fst_of_two_props :\n  ∀a b : Prop, a → b → a :=\nbegin\n  intros a b,\n  intros ha hb,\n  apply ha\nend\n\nlemma fst_of_two_props₂ (a b : Prop) (ha : a) (hb : b) :\n  a :=\nbegin\n  apply ha\nend\n\n\n/- Basic Tactics -/\n\nlemma prop_comp (a b c : Prop) (hab : a → b) (hbc : b → c) :\n  a → c :=\nbegin\n  intro ha,\n  apply hbc,\n  apply hab,\n  exact ha\nend\n\nlemma prop_comp₂ (a b c : Prop) (hab : a → b) (hbc : b → c) :\n  a → c :=\nbegin\n  intro,\n  apply hbc,\n  apply hab,\n  assumption\nend\n\nlemma α_example {α β : Type} (f : α → β) :\n  (λx, f x) = (λy, f y) :=\nby refl\n\nlemma β_example {α β : Type} (f : α → β) (a : α) :\n  (λx, f x) a = f a :=\nby refl\n\ndef double (n : ℕ) : ℕ :=\nn + n\n\nlemma δ_example (m : ℕ) :\n  double m = m + m :=\nby refl\n\nlemma ζ_example :\n  (let n : ℕ := 2 in n + n) = 4 :=\nby refl\n\nlemma η_example {α β : Type} (f : α → β) :\n  (λx, f x) = f :=\nby refl\n\nlemma ι_example {α β : Type} (a : α) (b : β) :\n  prod.fst (a, b) = a :=\nby refl\n\nlemma nat_exists_double_iden :\n  ∃n : ℕ, double n = n :=\nbegin\n  use 0,\n  refl\nend\n\n\n/- Proofs about Logical Connectives and Quantifiers -/\n\n-- introduction rules\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#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 `¬` and related lemmas\n#print not\n#check classical.em\n#check classical.by_contradiction\n\nlemma and_swap (a b : Prop) :\n  a ∧ b → b ∧ 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\nlemma and_swap₂ :\n  ∀a b : Prop, a ∧ b → b ∧ 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\nlemma or_swap (a b : Prop) :\n  a ∨ b → b ∨ a :=\nbegin\n  intros hab,\n  apply or.elim hab,\n  { intros ha,\n    exact or.intro_right _ ha },\n  { intros hb,\n    exact or.intro_left _ hb }\nend\n\nlemma modus_ponens (a b : Prop) :\n  (a → b) → a → b :=\nbegin\n  intros hab ha,\n  apply hab,\n  exact ha\nend\n\nlemma modus_ponens₂ (a b : Prop) (hab : a → b) (hp : a) :\n  b :=\nbegin\n  apply hab,\n  assumption\nend\n\nlemma proof_of_negation (a : Prop) :\n  a → ¬¬ a :=\nbegin\n  intro ha,\n  apply not.intro,\n  intro hna,\n  apply hna,\n  exact ha\nend\n\nlemma proof_of_negation₂ (a : Prop) :\n  a → ¬¬ a :=\nbegin\n  intros ha hna,\n  apply hna,\n  exact ha\nend\n\nlemma proof_by_contradiction (a : Prop) :\n  ¬¬ a → a :=\nbegin\n  intro hnna,\n  apply classical.by_contradiction,\n  exact hnna\nend\n\nlemma nat_exists_double_iden₂ :\n  ∃n : ℕ, double n = n :=\nbegin\n  apply exists.intro 0,\n  refl\nend\n\n\n/- Rewriting Tactics -/\n\nlemma proof_of_negation₃ (a : Prop) :\n  a → ¬¬ a :=\nbegin\n  dunfold not,\n  intro ha,\n  apply not.intro,\n  intro hna,\n  apply hna,\n  exact ha\nend\n\n\n/- Proofs about Natural Numbers -/\n\nlemma add_zero (n : ℕ) :\n  add 0 n = n :=\nbegin\n  induction n,\n  { refl },\n  { simp [add, n_ih] }\nend\n\nlemma add_zero₂ (n : ℕ) :\n  add 0 n = n :=\nbegin\n  induction n,\n  case nat.zero {\n    refl },\n  case nat.succ : m ih {\n    simp [add, ih] }\nend\n\nlemma add_zero₃ (n : ℕ) :\n  add 0 n = n :=\nby induction n; simp [add, *]\n\nlemma add_succ (m n : ℕ) :\n  add (nat.succ m) n = nat.succ (add m n) :=\nbegin\n  induction n,\n  case nat.zero {\n    refl },\n  case nat.succ : m ih {\n    simp [add, ih] }\nend\n\nlemma add_comm (m n : ℕ) :\n  add m n = add n m :=\nbegin\n  induction n,\n  case nat.zero {\n    simp [add, add_zero] },\n  case nat.succ : m ih {\n    simp [add, add_succ, ih] }\nend\n\nlemma add_assoc (l m n : ℕ) :\n  add (add l m) n = add l (add m n) :=\nbegin\n  induction n,\n  case nat.zero {\n    refl },\n  case nat.succ : m ih {\n    simp [add, ih] }\nend\n\n-- type classes (useful for `ac_refl` below)\ninstance : is_commutative ℕ add := ⟨add_comm⟩\ninstance : is_associative ℕ add := ⟨add_assoc⟩\n\nlemma mul_add (l m n : ℕ) :\n  mul l (add m n) = add (mul l m) (mul l n) :=\nbegin\n  induction n,\n  case nat.zero {\n    refl },\n  case nat.succ : m ih {\n    simp [add, mul, ih],\n    ac_refl }\nend\n\n\n/- Management Tactics -/\n\nlemma cleanup_example (a b c : Prop) (ha : a) (hb : b)\n  (hab : a → b) (hbc : b → c) :\n  c :=\nbegin\n  revert a b c ha hb hab hbc,\n  intros x y z hx hy hxy hyz,\n  clear hx hxy x,\n  apply hyz,\n  clear hyz z,\n  rename hy h,\n  exact h\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/love02_tactical_proofs_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7632575126775036}}
{"text": "import analysis.special_functions.log.basic \n\nopen real\nvariables (a b c d e f: ℝ)\n\n#check (le_refl : ∀ a : ℝ, a ≤ a)\n#check (le_trans : a ≤ b → b ≤ c → a ≤ c)\n\n\nvariables (h : a ≤ b) (h' : b ≤ c)\n\n#check (le_refl : ∀ a : real, a ≤ a)\n#check (le_refl a : a ≤ a)\n#check (le_trans : a ≤ b → b ≤ c → a ≤ c)\n#check (le_trans h : b ≤ c → a ≤ c)\n#check (le_trans h h' : a ≤ c)\n\n\n\nexample (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=\nbegin \n  apply le_trans,\n  exact h₀,\n  exact h₁,\nend\n\n\nexample (x y z : ℝ) (h₀ : x ≤ y) (h₁ : y ≤ z) : x ≤ z :=\nbegin \n  apply le_trans h₀,\n  exact h₁,\nend\n\n\nexample (x : ℝ) : x ≤ x :=\n  by apply le_refl\n\n\n#check (le_refl  : ∀ a, a ≤ a)\n#check (le_trans : a ≤ b → b ≤ c → a ≤ c)\n#check (lt_of_le_of_lt : a ≤ b → b < c → a < c)\n#check (lt_of_lt_of_le : a < b → b ≤ c → a < c)\n#check (lt_trans : a < b → b < c → a < c)\n\nexample (h₀ : a ≤ b) (h₁ : b < c) (h₂ : c ≤ d) (h₃ : d < e) :\n  a < e :=\nbegin \n  apply lt_of_le_of_lt h₀,\n  apply lt_trans h₁,\n  apply lt_of_le_of_lt h₂ h₃,\nend\n\nexample (h₀ : a ≤ b) (h₁ : b < c) (h₂ : c ≤ d) (h₃ : d < e) :\n  a < e := by linarith\n\nexample (h : 1 ≤ a) (h' : b ≤ c) :\n    2 + a + exp b ≤ 3 * a + exp c :=\n  by linarith [exp_le_exp.mpr h']\n\n\n#check (exp_le_exp : exp a ≤ exp b ↔ a ≤ b)\n#check (exp_lt_exp : exp a < exp b ↔ a < b)\n#check (log_le_log : 0 < a → 0 < b → (log a ≤ log b ↔ a ≤ b))\n#check (log_lt_log : 0 < a → a < b → log a < log b)\n#check (add_le_add : a ≤ b → c ≤ d → a + c ≤ b + d)\n#check (add_le_add_left : a ≤ b → ∀ c, c + a ≤ c + b)\n#check (add_le_add_right : a ≤ b → ∀ c, a + c ≤ b + c)\n#check (add_lt_add_of_le_of_lt : a ≤ b → c < d → a + c < b + d)\n#check (add_lt_add_of_lt_of_le : a < b → c ≤ d → a + c < b + d)\n#check (add_lt_add_left : a < b → ∀ c, c + a < c + b)\n#check (add_lt_add_right : a < b → ∀ c, a + c < b + c)\n#check (add_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a + b)\n#check (add_pos : 0 < a → 0 < b → 0 < a + b)\n#check (add_pos_of_pos_of_nonneg : 0 < a → 0 ≤ b → 0 < a + b)\n#check (exp_pos : ∀ a, 0 < exp a)\n\n\nexample (h₀ : a ≤ b) (h₁ : c < d) : a + exp c + e < b + exp d + e :=\nbegin \n  apply add_lt_add_right,\n  apply add_lt_add_of_le_of_lt,\n  { exact h₀},\n  { exact exp_lt_exp.mpr h₁}\nend\n\nexample (h₀ : d ≤ e) : c + exp (a + d) ≤ c + exp (a + e) :=\nbegin\n  apply add_le_add_left,\n  apply exp_le_exp.mpr,\n  apply add_le_add_left h₀,\nend\n\nexample : (0 : ℝ) < 1 :=\nby norm_num\n\nexample (h : a ≤ b) : log (1 + exp a) ≤ log (1 + exp b) :=\nbegin\n  have h₀ : 0 < 1 + exp a,\n  { apply add_pos,\n    norm_num,\n    apply exp_pos, },\n  have h₁ : 0 < 1 + exp b,\n  { apply add_pos,\n    norm_num,\n    apply exp_pos, },\n  apply (log_le_log h₀ h₁).mpr,\n  apply add_le_add_left,\n  apply exp_le_exp.mpr h,\nend\n\nexample : 0 ≤ a^2 :=\nbegin\n  exact sq_nonneg a,\nend\n\nexample (h : a ≤ b) : c - exp b ≤ c - exp a :=\nbegin \n  apply add_le_add_left,\n  apply neg_le_neg,\n  exact exp_le_exp.mpr h,\nend\n\nexample : 2*a*b ≤ a^2 + b^2 :=\nbegin \n  have : 0 ≤ a^2 - 2*a*b + b^2,\n  calc \n    a^2 - 2*a*b + b^2 = (a - b)^2 : by ring\n    ... ≥ 0 : by apply sq_nonneg,\n  calc \n    2*a*b \n        = 2*a*b + 0 : by ring \n    ... ≤ 2*a*b + (a^2 - 2*a*b + b^2) : add_le_add (le_refl _) this\n    ... = a^2 + b^2 : by ring,  \nend\n\nexample : |a*b| ≤ (a^2 + b^2) / 2 :=\nbegin \n  have : 0 ≤ a^2 - 2*a*b + b^2,\n  calc \n    a^2 - 2*a*b + b^2 = (a - b)^2 : by ring\n    ... ≥ 0 : by apply sq_nonneg,\n  have h₀ : a*b ≤ (a^2 + b^2) / 2,\n    by linarith,\n\n  have : 0 ≤ a^2 + 2*a*b + b^2,\n  calc \n    a^2 + 2*a*b + b^2 = (a + b)^2 : by ring\n    ... ≥ 0 : by apply sq_nonneg,\n  have h₁ : -(a*b) ≤ (a^2 + b^2) / 2,\n    by linarith,\n\n  apply abs_le'.mpr,\n  constructor,\n  exact h₀,\n  exact h₁,\nend\n\n#check abs_le'.mpr\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/03_Using_Theorems_Lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7632575011977251}}
{"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.nat.multiplicity\n! leanprover-community/mathlib commit 290a7ba01fbcab1b64757bdaa270d28f4dcede35\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.Intervals\nimport Mathbin.Algebra.GeomSum\nimport Mathbin.Data.Nat.Bitwise\nimport Mathbin.Data.Nat.Log\nimport Mathbin.Data.Nat.Parity\nimport Mathbin.Data.Nat.Prime\nimport Mathbin.RingTheory.Multiplicity\n\n/-!\n# Natural number multiplicity\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 the multiplicity function (the maximum prime power dividing a\nnumber) when applied to naturals, in particular calculating it for factorials and binomial\ncoefficients.\n\n## Multiplicity calculations\n\n* `nat.multiplicity_factorial`: Legendre's Theorem. The multiplicity of `p` in `n!` is\n  `n/p + ... + n/p^b` for any `b` such that `n/p^(b + 1) = 0`.\n* `nat.multiplicity_factorial_mul`: The multiplicity of `p` in `(p * n)!` is `n` more than that of\n  `n!`.\n* `nat.multiplicity_choose`: The multiplicity of `p` in `n.choose k` is the number of carries when\n  `k` and`n - k` are added in base `p`.\n\n## Other declarations\n\n* `nat.multiplicity_eq_card_pow_dvd`: The multiplicity of `m` in `n` is the number of positive\n  natural numbers `i` such that `m ^ i` divides `n`.\n* `nat.multiplicity_two_factorial_lt`: The multiplicity of `2` in `n!` is strictly less than `n`.\n* `nat.prime.multiplicity_something`: Specialization of `multiplicity.something` to a prime in the\n  naturals. Avoids having to provide `p ≠ 1` and other trivialities, along with translating between\n  `prime` and `nat.prime`.\n\n## Tags\n\nLegendre, p-adic\n-/\n\n\nopen Finset Nat multiplicity\n\nopen BigOperators Nat\n\nnamespace Nat\n\n/- warning: nat.multiplicity_eq_card_pow_dvd -> Nat.multiplicity_eq_card_pow_dvd is a dubious translation:\nlean 3 declaration is\n  forall {m : Nat} {n : Nat} {b : Nat}, (Ne.{1} Nat m (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) -> (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) n) -> (LT.lt.{0} Nat Nat.hasLt (Nat.log m n) b) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) m n) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) (Finset.card.{0} Nat (Finset.filter.{0} Nat (fun (i : Nat) => Dvd.Dvd.{0} Nat Nat.hasDvd (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) m i) n) (fun (a : Nat) => Nat.decidableDvd (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) m a) n) (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b)))))\nbut is expected to have type\n  forall {m : Nat} {n : Nat} {b : Nat}, (Ne.{1} Nat m (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) -> (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) n) -> (LT.lt.{0} Nat instLTNat (Nat.log m n) b) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) m n) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) (Finset.card.{0} Nat (Finset.filter.{0} Nat (fun (i : Nat) => Dvd.dvd.{0} Nat Nat.instDvdNat (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) m i) n) (fun (a : Nat) => Nat.decidable_dvd (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) m a) n) (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b)))))\nCase conversion may be inaccurate. Consider using '#align nat.multiplicity_eq_card_pow_dvd Nat.multiplicity_eq_card_pow_dvdₓ'. -/\n/-- The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i`\ndivides `n`. This set is expressed by filtering `Ico 1 b` where `b` is any bound greater than\n`log m n`. -/\ntheorem multiplicity_eq_card_pow_dvd {m n b : ℕ} (hm : m ≠ 1) (hn : 0 < n) (hb : log m n < b) :\n    multiplicity m n = ↑((Finset.Ico 1 b).filterₓ fun i => m ^ i ∣ n).card :=\n  calc\n    multiplicity m n = ↑(Ico 1 <| (multiplicity m n).get (finite_nat_iff.2 ⟨hm, hn⟩) + 1).card := by\n      simp\n    _ = ↑((Finset.Ico 1 b).filterₓ fun i => m ^ i ∣ n).card :=\n      congr_arg coe <|\n        congr_arg card <|\n          Finset.ext fun i =>\n            by\n            rw [mem_filter, mem_Ico, mem_Ico, lt_succ_iff, ← @PartENat.coe_le_coe i,\n              PartENat.natCast_get, ← pow_dvd_iff_le_multiplicity, and_right_comm]\n            refine' (and_iff_left_of_imp fun h => lt_of_le_of_lt _ hb).symm\n            cases m\n            · rw [zero_pow, zero_dvd_iff] at h\n              exacts[(hn.ne' h.2).elim, h.1]\n            exact\n              le_log_of_pow_le (one_lt_iff_ne_zero_and_ne_one.2 ⟨m.succ_ne_zero, hm⟩)\n                (le_of_dvd hn h.2)\n    \n#align nat.multiplicity_eq_card_pow_dvd Nat.multiplicity_eq_card_pow_dvd\n\nnamespace Prime\n\n/- warning: nat.prime.multiplicity_one -> Nat.Prime.multiplicity_one is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (OfNat.ofNat.{0} PartENat 0 (OfNat.mk.{0} PartENat 0 (Zero.zero.{0} PartENat PartENat.hasZero))))\nbut is expected to have type\n  forall {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (OfNat.ofNat.{0} PartENat 0 (Zero.toOfNat0.{0} PartENat PartENat.instZeroPartENat)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_one Nat.Prime.multiplicity_oneₓ'. -/\ntheorem multiplicity_one {p : ℕ} (hp : p.Prime) : multiplicity p 1 = 0 :=\n  multiplicity.one_right hp.Prime.not_unit\n#align nat.prime.multiplicity_one Nat.Prime.multiplicity_one\n\n/- warning: nat.prime.multiplicity_mul -> Nat.Prime.multiplicity_mul is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {m : Nat} {n : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) m n)) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.hasAdd) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p m) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p n)))\nbut is expected to have type\n  forall {p : Nat} {m : Nat} {n : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) m n)) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.instAddPartENat) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p m) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p n)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_mul Nat.Prime.multiplicity_mulₓ'. -/\ntheorem multiplicity_mul {p m n : ℕ} (hp : p.Prime) :\n    multiplicity p (m * n) = multiplicity p m + multiplicity p n :=\n  multiplicity.mul hp.Prime\n#align nat.prime.multiplicity_mul Nat.Prime.multiplicity_mul\n\n/- warning: nat.prime.multiplicity_pow -> Nat.Prime.multiplicity_pow is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {m : Nat} {n : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) m n)) (SMul.smul.{0, 0} Nat PartENat (AddMonoid.SMul.{0} PartENat (AddMonoidWithOne.toAddMonoid.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))) n (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p m)))\nbut is expected to have type\n  forall {p : Nat} {m : Nat} {n : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) m n)) (HSMul.hSMul.{0, 0, 0} Nat PartENat PartENat (instHSMul.{0, 0} Nat PartENat (AddMonoid.SMul.{0} PartENat (AddMonoidWithOne.toAddMonoid.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)))) n (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p m)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_pow Nat.Prime.multiplicity_powₓ'. -/\ntheorem multiplicity_pow {p m n : ℕ} (hp : p.Prime) :\n    multiplicity p (m ^ n) = n • multiplicity p m :=\n  multiplicity.pow hp.Prime\n#align nat.prime.multiplicity_pow Nat.Prime.multiplicity_pow\n\n/- warning: nat.prime.multiplicity_self -> Nat.Prime.multiplicity_self is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p p) (OfNat.ofNat.{0} PartENat 1 (OfNat.mk.{0} PartENat 1 (One.one.{0} PartENat PartENat.hasOne))))\nbut is expected to have type\n  forall {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p p) (OfNat.ofNat.{0} PartENat 1 (One.toOfNat1.{0} PartENat PartENat.instOnePartENat)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_self Nat.Prime.multiplicity_selfₓ'. -/\ntheorem multiplicity_self {p : ℕ} (hp : p.Prime) : multiplicity p p = 1 :=\n  multiplicity_self hp.Prime.not_unit hp.NeZero\n#align nat.prime.multiplicity_self Nat.Prime.multiplicity_self\n\n/- warning: nat.prime.multiplicity_pow_self -> Nat.Prime.multiplicity_pow_self is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) n))\nbut is expected to have type\n  forall {p : Nat} {n : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p n)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) n))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_pow_self Nat.Prime.multiplicity_pow_selfₓ'. -/\ntheorem multiplicity_pow_self {p n : ℕ} (hp : p.Prime) : multiplicity p (p ^ n) = n :=\n  multiplicity_pow_self hp.NeZero hp.Prime.not_unit n\n#align nat.prime.multiplicity_pow_self Nat.Prime.multiplicity_pow_self\n\n/- warning: nat.prime.multiplicity_factorial -> Nat.Prime.multiplicity_factorial is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (Nat.Prime p) -> (forall {n : Nat} {b : Nat}, (LT.lt.{0} Nat Nat.hasLt (Nat.log p n) b) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.factorial n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) n (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i))))))\nbut is expected to have type\n  forall {p : Nat}, (Nat.Prime p) -> (forall {n : Nat} {b : Nat}, (LT.lt.{0} Nat instLTNat (Nat.log p n) b) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.factorial n)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) n (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i))))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_factorial Nat.Prime.multiplicity_factorialₓ'. -/\n/-- **Legendre's Theorem**\n\nThe multiplicity of a prime in `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed\nover the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/\ntheorem multiplicity_factorial {p : ℕ} (hp : p.Prime) :\n    ∀ {n b : ℕ}, log p n < b → multiplicity p n ! = (∑ i in Ico 1 b, n / p ^ i : ℕ)\n  | 0, b, hb => by simp [Ico, hp.multiplicity_one]\n  | n + 1, b, hb =>\n    calc\n      multiplicity p (n + 1)! = multiplicity p n ! + multiplicity p (n + 1) := by\n        rw [factorial_succ, hp.multiplicity_mul, add_comm]\n      _ =\n          (∑ i in Ico 1 b, n / p ^ i : ℕ) +\n            ((Finset.Ico 1 b).filterₓ fun i => p ^ i ∣ n + 1).card :=\n        by\n        rw [multiplicity_factorial ((log_mono_right <| le_succ _).trans_lt hb), ←\n          multiplicity_eq_card_pow_dvd hp.ne_one (succ_pos _) hb]\n      _ = (∑ i in Ico 1 b, n / p ^ i + if p ^ i ∣ n + 1 then 1 else 0 : ℕ) :=\n        by\n        rw [sum_add_distrib, sum_boole]\n        simp\n      _ = (∑ i in Ico 1 b, (n + 1) / p ^ i : ℕ) :=\n        congr_arg coe <| Finset.sum_congr rfl fun _ _ => (succ_div _ _).symm\n      \n#align nat.prime.multiplicity_factorial Nat.Prime.multiplicity_factorial\n\n/- warning: nat.prime.multiplicity_factorial_mul_succ -> Nat.Prime.multiplicity_factorial_mul_succ is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.factorial (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) p (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))))))) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.hasAdd) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.hasAdd) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.factorial (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) p n))) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (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)))))) (OfNat.ofNat.{0} PartENat 1 (OfNat.mk.{0} PartENat 1 (One.one.{0} PartENat PartENat.hasOne)))))\nbut is expected to have type\n  forall {n : Nat} {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.factorial (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) p (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)))))) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.instAddPartENat) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.instAddPartENat) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.factorial (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) p n))) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))) (OfNat.ofNat.{0} PartENat 1 (One.toOfNat1.{0} PartENat PartENat.instOnePartENat))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_factorial_mul_succ Nat.Prime.multiplicity_factorial_mul_succₓ'. -/\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`. -/\ntheorem multiplicity_factorial_mul_succ {n p : ℕ} (hp : p.Prime) :\n    multiplicity p (p * (n + 1))! = multiplicity p (p * n)! + multiplicity p (n + 1) + 1 :=\n  by\n  have hp' := hp.prime\n  have h0 : 2 ≤ p := hp.two_le\n  have h1 : 1 ≤ p * n + 1 := Nat.le_add_left _ _\n  have h2 : p * n + 1 ≤ p * (n + 1)\n  linarith\n  have h3 : p * n + 1 ≤ p * (n + 1) + 1\n  linarith\n  have hm : multiplicity p (p * n)! ≠ ⊤ :=\n    by\n    rw [Ne.def, eq_top_iff_not_finite, Classical.not_not, finite_nat_iff]\n    exact ⟨hp.ne_one, factorial_pos _⟩\n  revert hm\n  have h4 : ∀ m ∈ Ico (p * n + 1) (p * (n + 1)), multiplicity p m = 0 :=\n    by\n    intro m hm\n    rw [multiplicity_eq_zero, ← not_dvd_iff_between_consec_multiples _ hp.pos]\n    rw [mem_Ico] at hm\n    exact ⟨n, lt_of_succ_le hm.1, hm.2⟩\n  simp_rw [← prod_Ico_id_eq_factorial, multiplicity.Finset.prod hp', ← sum_Ico_consecutive _ h1 h3,\n    add_assoc]\n  intro h\n  rw [PartENat.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, add_comm (1 : PartENat)]\n#align nat.prime.multiplicity_factorial_mul_succ Nat.Prime.multiplicity_factorial_mul_succ\n\n/- warning: nat.prime.multiplicity_factorial_mul -> Nat.Prime.multiplicity_factorial_mul is a dubious translation:\nlean 3 declaration is\n  forall {n : Nat} {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.factorial (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat Nat.hasMul) p n))) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.hasAdd) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.factorial n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) n)))\nbut is expected to have type\n  forall {n : Nat} {p : Nat}, (Nat.Prime p) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.factorial (HMul.hMul.{0, 0, 0} Nat Nat Nat (instHMul.{0} Nat instMulNat) p n))) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.instAddPartENat) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.factorial n)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) n)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_factorial_mul Nat.Prime.multiplicity_factorial_mulₓ'. -/\n/-- The multiplicity of `p` in `(p * n)!` is `n` more than that of `n!`. -/\ntheorem multiplicity_factorial_mul {n p : ℕ} (hp : p.Prime) :\n    multiplicity p (p * n)! = multiplicity p n ! + n :=\n  by\n  induction' n with n ih\n  · simp\n  · simp only [succ_eq_add_one, multiplicity.mul, hp, hp.prime, ih, multiplicity_factorial_mul_succ,\n      ← add_assoc, Nat.cast_one, Nat.cast_add, factorial_succ]\n    congr 1\n    rw [add_comm, add_assoc]\n#align nat.prime.multiplicity_factorial_mul Nat.Prime.multiplicity_factorial_mul\n\n#print Nat.Prime.pow_dvd_factorial_iff /-\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` -/\ntheorem pow_dvd_factorial_iff {p : ℕ} {n r b : ℕ} (hp : p.Prime) (hbn : log p n < b) :\n    p ^ r ∣ n ! ↔ r ≤ ∑ i in Ico 1 b, n / p ^ i := by\n  rw [← PartENat.coe_le_coe, ← hp.multiplicity_factorial hbn, ← pow_dvd_iff_le_multiplicity]\n#align nat.prime.pow_dvd_factorial_iff Nat.Prime.pow_dvd_factorial_iff\n-/\n\n/- warning: nat.prime.multiplicity_factorial_le_div_pred -> Nat.Prime.multiplicity_factorial_le_div_pred is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (Nat.Prime p) -> (forall (n : Nat), LE.le.{0} PartENat PartENat.hasLe (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.factorial n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) n (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))))))\nbut is expected to have type\n  forall {p : Nat}, (Nat.Prime p) -> (forall (n : Nat), LE.le.{0} PartENat PartENat.instLEPartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.factorial n)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) (HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) n (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_factorial_le_div_pred Nat.Prime.multiplicity_factorial_le_div_predₓ'. -/\ntheorem multiplicity_factorial_le_div_pred {p : ℕ} (hp : p.Prime) (n : ℕ) :\n    multiplicity p n ! ≤ (n / (p - 1) : ℕ) :=\n  by\n  rw [hp.multiplicity_factorial (lt_succ_self _), PartENat.coe_le_coe]\n  exact Nat.geom_sum_Ico_le hp.two_le _ _\n#align nat.prime.multiplicity_factorial_le_div_pred Nat.Prime.multiplicity_factorial_le_div_pred\n\n/- warning: nat.prime.multiplicity_choose_aux -> Nat.Prime.multiplicity_choose_aux is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat} {b : Nat} {k : Nat}, (Nat.Prime p) -> (LE.le.{0} Nat Nat.hasLe k n) -> (Eq.{1} Nat (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) n (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i))) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i))) (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.hasDiv) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i)))) (Finset.card.{0} Nat (Finset.filter.{0} Nat (fun (i : Nat) => LE.le.{0} Nat Nat.hasLe (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i)))) (fun (a : Nat) => Nat.decidableLe (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p a) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p a)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p a)))) (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b)))))\nbut is expected to have type\n  forall {p : Nat} {n : Nat} {b : Nat} {k : Nat}, (Nat.Prime p) -> (LE.le.{0} Nat instLENat k n) -> (Eq.{1} Nat (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) n (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i))) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i))) (Finset.sum.{0, 0} Nat Nat Nat.addCommMonoid (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b) (fun (i : Nat) => HDiv.hDiv.{0, 0, 0} Nat Nat Nat (instHDiv.{0} Nat Nat.instDivNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i)))) (Finset.card.{0} Nat (Finset.filter.{0} Nat (fun (i : Nat) => LE.le.{0} Nat instLENat (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i)))) (fun (a : Nat) => Nat.decLe (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p a) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p a)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p a)))) (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b)))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_choose_aux Nat.Prime.multiplicity_choose_auxₓ'. -/\ntheorem multiplicity_choose_aux {p n b k : ℕ} (hp : p.Prime) (hkn : k ≤ n) :\n    (∑ i in Finset.Ico 1 b, n / p ^ i) =\n      ((∑ i in Finset.Ico 1 b, k / p ^ i) + ∑ i in Finset.Ico 1 b, (n - k) / p ^ i) +\n        ((Finset.Ico 1 b).filterₓ fun i => p ^ i ≤ k % p ^ i + (n - k) % p ^ i).card :=\n  calc\n    (∑ i in Finset.Ico 1 b, n / p ^ i) = ∑ i in Finset.Ico 1 b, (k + (n - k)) / p ^ i := by\n      simp only [add_tsub_cancel_of_le hkn]\n    _ =\n        ∑ i in Finset.Ico 1 b,\n          k / p ^ i + (n - k) / p ^ i + if p ^ i ≤ 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#align nat.prime.multiplicity_choose_aux Nat.Prime.multiplicity_choose_aux\n\n/- warning: nat.prime.multiplicity_choose -> Nat.Prime.multiplicity_choose is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat} {k : Nat} {b : Nat}, (Nat.Prime p) -> (LE.le.{0} Nat Nat.hasLe k n) -> (LT.lt.{0} Nat Nat.hasLt (Nat.log p n) b) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.choose n k)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) (Finset.card.{0} Nat (Finset.filter.{0} Nat (fun (i : Nat) => LE.le.{0} Nat Nat.hasLe (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p i)))) (fun (a : Nat) => Nat.decidableLe (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p a) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat Nat.hasAdd) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p a)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.hasMod) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p a)))) (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring))) Nat.locallyFiniteOrder (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) b)))))\nbut is expected to have type\n  forall {p : Nat} {n : Nat} {k : Nat} {b : Nat}, (Nat.Prime p) -> (LE.le.{0} Nat instLENat k n) -> (LT.lt.{0} Nat instLTNat (Nat.log p n) b) -> (Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.choose n k)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) (Finset.card.{0} Nat (Finset.filter.{0} Nat (fun (i : Nat) => LE.le.{0} Nat instLENat (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p i)))) (fun (a : Nat) => Nat.decLe (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p a) (HAdd.hAdd.{0, 0, 0} Nat Nat Nat (instHAdd.{0} Nat instAddNat) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p a)) (HMod.hMod.{0, 0, 0} Nat Nat Nat (instHMod.{0} Nat Nat.instModNat) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n k) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p a)))) (Finset.Ico.{0} Nat (PartialOrder.toPreorder.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring)) instLocallyFiniteOrderNatToPreorderToPartialOrderStrictOrderedSemiring (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) b)))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_choose Nat.Prime.multiplicity_chooseₓ'. -/\n/-- The multiplicity 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`. -/\ntheorem multiplicity_choose {p n k b : ℕ} (hp : p.Prime) (hkn : k ≤ n) (hnb : log p n < b) :\n    multiplicity p (choose n k) =\n      ((Ico 1 b).filterₓ fun i => p ^ i ≤ k % p ^ i + (n - k) % p ^ i).card :=\n  have h₁ :\n    multiplicity p (choose n k) + multiplicity p (k ! * (n - k)!) =\n      ((Finset.Ico 1 b).filterₓ fun i => p ^ i ≤ k % p ^ i + (n - k) % p ^ i).card +\n        multiplicity p (k ! * (n - k)!) :=\n    by\n    rw [← hp.multiplicity_mul, ← mul_assoc, choose_mul_factorial_mul_factorial hkn,\n      hp.multiplicity_factorial hnb, hp.multiplicity_mul,\n      hp.multiplicity_factorial ((log_mono_right hkn).trans_lt hnb),\n      hp.multiplicity_factorial (lt_of_le_of_lt (log_mono_right tsub_le_self) hnb),\n      multiplicity_choose_aux hp hkn]\n    simp [add_comm]\n  (PartENat.add_right_cancel_iff\n        (PartENat.ne_top_iff_dom.2 <|\n          finite_nat_iff.2\n            ⟨ne_of_gt hp.one_lt, mul_pos (factorial_pos k) (factorial_pos (n - k))⟩)).1\n    h₁\n#align nat.prime.multiplicity_choose Nat.Prime.multiplicity_choose\n\n/- warning: nat.prime.multiplicity_le_multiplicity_choose_add -> Nat.Prime.multiplicity_le_multiplicity_choose_add is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (Nat.Prime p) -> (forall (n : Nat) (k : Nat), LE.le.{0} PartENat PartENat.hasLe (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p n) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.hasAdd) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.choose n k)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p k)))\nbut is expected to have type\n  forall {p : Nat}, (Nat.Prime p) -> (forall (n : Nat) (k : Nat), LE.le.{0} PartENat PartENat.instLEPartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p n) (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.instAddPartENat) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.choose n k)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p k)))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_le_multiplicity_choose_add Nat.Prime.multiplicity_le_multiplicity_choose_addₓ'. -/\n/-- A lower bound on the multiplicity of `p` in `choose n k`. -/\ntheorem multiplicity_le_multiplicity_choose_add {p : ℕ} (hp : p.Prime) :\n    ∀ n k : ℕ, multiplicity p n ≤ multiplicity p (choose n k) + multiplicity p k\n  | _, 0 => by simp\n  | 0, _ + 1 => by simp\n  | n + 1, k + 1 => by\n    rw [← hp.multiplicity_mul]\n    refine' multiplicity_le_multiplicity_of_dvd_right _\n    rw [← succ_mul_choose_eq]\n    exact dvd_mul_right _ _\n#align nat.prime.multiplicity_le_multiplicity_choose_add Nat.Prime.multiplicity_le_multiplicity_choose_add\n\nvariable {p n k : ℕ}\n\n/- warning: nat.prime.multiplicity_choose_prime_pow_add_multiplicity -> Nat.Prime.multiplicity_choose_prime_pow_add_multiplicity is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat} {k : Nat}, (Nat.Prime p) -> (LE.le.{0} Nat Nat.hasLe k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p n)) -> (Ne.{1} Nat k (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))) -> (Eq.{1} PartENat (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.hasAdd) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.choose (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p n) k)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p k)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) n))\nbut is expected to have type\n  forall {p : Nat} {n : Nat} {k : Nat}, (Nat.Prime p) -> (LE.le.{0} Nat instLENat k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p n)) -> (Ne.{1} Nat k (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (Eq.{1} PartENat (HAdd.hAdd.{0, 0, 0} PartENat PartENat PartENat (instHAdd.{0} PartENat PartENat.instAddPartENat) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.choose (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p n) k)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p k)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) n))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_choose_prime_pow_add_multiplicity Nat.Prime.multiplicity_choose_prime_pow_add_multiplicityₓ'. -/\ntheorem multiplicity_choose_prime_pow_add_multiplicity (hp : p.Prime) (hkn : k ≤ p ^ n)\n    (hk0 : k ≠ 0) : multiplicity p (choose (p ^ n) k) + multiplicity p k = n :=\n  le_antisymm\n    (by\n      have hdisj :\n        Disjoint ((Ico 1 n.succ).filterₓ fun i => p ^ i ≤ k % p ^ i + (p ^ n - k) % p ^ i)\n          ((Ico 1 n.succ).filterₓ fun i => p ^ i ∣ k) :=\n        by\n        simp (config := { contextual := true }) [disjoint_right, *, dvd_iff_mod_eq_zero,\n          Nat.mod_lt _ (pow_pos hp.pos _)]\n      rw [multiplicity_choose hp hkn (lt_succ_self _),\n        multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) hk0.bot_lt\n          (lt_succ_of_le (log_mono_right hkn)),\n        ← Nat.cast_add, PartENat.coe_le_coe, log_pow hp.one_lt, ← card_disjoint_union hdisj,\n        filter_union_right]\n      have filter_le_Ico := (Ico 1 n.succ).card_filter_le _\n      rwa [card_Ico 1 n.succ] at filter_le_Ico)\n    (by rw [← hp.multiplicity_pow_self] <;> exact multiplicity_le_multiplicity_choose_add hp _ _)\n#align nat.prime.multiplicity_choose_prime_pow_add_multiplicity Nat.Prime.multiplicity_choose_prime_pow_add_multiplicity\n\n/- warning: nat.prime.multiplicity_choose_prime_pow -> Nat.Prime.multiplicity_choose_prime_pow is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {n : Nat} {k : Nat} (hp : Nat.Prime p), (LE.le.{0} Nat Nat.hasLe k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p n)) -> (forall (hk0 : Ne.{1} Nat k (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero)))), Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p (Nat.choose (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p n) k)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat Nat.hasSub) n (Part.get.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) p k) (Iff.mpr (multiplicity.Finite.{0} Nat Nat.monoid p k) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) k)) (multiplicity.finite_nat_iff p k) (And.intro (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne)))) (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 0 (OfNat.mk.{0} Nat 0 (Zero.zero.{0} Nat Nat.hasZero))) k) (Nat.Prime.ne_one p hp) (Ne.bot_lt.{0} Nat (OrderedCancelAddCommMonoid.toPartialOrder.{0} Nat (StrictOrderedSemiring.toOrderedCancelAddCommMonoid.{0} Nat Nat.strictOrderedSemiring)) Nat.orderBot k hk0)))))))\nbut is expected to have type\n  forall {p : Nat} {n : Nat} {k : Nat} (hp : Nat.Prime p), (LE.le.{0} Nat instLENat k (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p n)) -> (forall (hk0 : Ne.{1} Nat k (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))), Eq.{1} PartENat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p (Nat.choose (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p n) k)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) (HSub.hSub.{0, 0, 0} Nat Nat Nat (instHSub.{0} Nat instSubNat) n (Part.get.{0} Nat (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) p k) (Iff.mpr (multiplicity.Finite.{0} Nat Nat.monoid p k) (And (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) k)) (multiplicity.finite_nat_iff p k) (And.intro (Ne.{1} Nat p (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))) (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0)) k) (Nat.Prime.ne_one p hp) (Ne.bot_lt.{0} Nat (StrictOrderedSemiring.toPartialOrder.{0} Nat Nat.strictOrderedSemiring) Nat.orderBot k hk0)))))))\nCase conversion may be inaccurate. Consider using '#align nat.prime.multiplicity_choose_prime_pow Nat.Prime.multiplicity_choose_prime_powₓ'. -/\ntheorem multiplicity_choose_prime_pow {p n k : ℕ} (hp : p.Prime) (hkn : k ≤ p ^ n) (hk0 : k ≠ 0) :\n    multiplicity p (choose (p ^ n) k) =\n      ↑(n - (multiplicity p k).get (finite_nat_iff.2 ⟨hp.ne_one, hk0.bot_lt⟩)) :=\n  PartENat.eq_natCast_sub_of_add_eq_natCast <|\n    multiplicity_choose_prime_pow_add_multiplicity hp hkn hk0\n#align nat.prime.multiplicity_choose_prime_pow Nat.Prime.multiplicity_choose_prime_pow\n\n#print Nat.Prime.dvd_choose_pow /-\ntheorem dvd_choose_pow (hp : Prime p) (hk : k ≠ 0) (hkp : k ≠ p ^ n) : p ∣ (p ^ n).choose k :=\n  by\n  obtain hkp | hkp := hkp.symm.lt_or_lt\n  · simp [choose_eq_zero_of_lt hkp]\n  refine' multiplicity_ne_zero.1 fun h => hkp.not_le <| Nat.le_of_dvd hk.bot_lt _\n  have H := hp.multiplicity_choose_prime_pow_add_multiplicity hkp.le hk\n  rw [h, zero_add, eq_coe_iff] at H\n  exact H.1\n#align nat.prime.dvd_choose_pow Nat.Prime.dvd_choose_pow\n-/\n\n#print Nat.Prime.dvd_choose_pow_iff /-\ntheorem dvd_choose_pow_iff (hp : Prime p) : p ∣ (p ^ n).choose k ↔ k ≠ 0 ∧ k ≠ p ^ n := by\n  refine' ⟨fun h => ⟨_, _⟩, fun h => dvd_choose_pow hp h.1 h.2⟩ <;> rintro rfl <;>\n    simpa [hp.ne_one] using h\n#align nat.prime.dvd_choose_pow_iff Nat.Prime.dvd_choose_pow_iff\n-/\n\nend Prime\n\n/- warning: nat.multiplicity_two_factorial_lt -> Nat.multiplicity_two_factorial_lt 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)))) -> (LT.lt.{0} PartENat (Preorder.toLT.{0} PartENat (PartialOrder.toPreorder.{0} PartENat PartENat.partialOrder)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidableDvd a b) (OfNat.ofNat.{0} Nat 2 (OfNat.mk.{0} Nat 2 (bit0.{0} Nat Nat.hasAdd (One.one.{0} Nat Nat.hasOne)))) (Nat.factorial n)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat PartENat (HasLiftT.mk.{1, 1} Nat PartENat (CoeTCₓ.coe.{1, 1} Nat PartENat (Nat.castCoe.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.addCommMonoidWithOne))))) n))\nbut is expected to have type\n  forall {n : Nat}, (Ne.{1} Nat n (OfNat.ofNat.{0} Nat 0 (instOfNatNat 0))) -> (LT.lt.{0} PartENat (Preorder.toLT.{0} PartENat (PartialOrder.toPreorder.{0} PartENat PartENat.partialOrder)) (multiplicity.{0} Nat Nat.monoid (fun (a : Nat) (b : Nat) => Nat.decidable_dvd a b) (OfNat.ofNat.{0} Nat 2 (instOfNatNat 2)) (Nat.factorial n)) (Nat.cast.{0} PartENat (AddMonoidWithOne.toNatCast.{0} PartENat (AddCommMonoidWithOne.toAddMonoidWithOne.{0} PartENat PartENat.instAddCommMonoidWithOnePartENat)) n))\nCase conversion may be inaccurate. Consider using '#align nat.multiplicity_two_factorial_lt Nat.multiplicity_two_factorial_ltₓ'. -/\ntheorem multiplicity_two_factorial_lt : ∀ {n : ℕ} (h : n ≠ 0), multiplicity 2 n ! < n :=\n  by\n  have h2 := prime_two.prime\n  refine' binary_rec _ _\n  · contradiction\n  · intro b n ih h\n    by_cases hn : n = 0\n    · subst hn\n      simp at h\n      simp [h, one_right h2.not_unit]\n    have : multiplicity 2 (2 * n)! < (2 * n : ℕ) :=\n      by\n      rw [prime_two.multiplicity_factorial_mul]\n      refine' (PartENat.add_lt_add_right (ih hn) (PartENat.natCast_ne_top _)).trans_le _\n      rw [two_mul]\n      norm_cast\n    cases b\n    · simpa [bit0_eq_two_mul n]\n    · suffices multiplicity 2 (2 * n + 1) + multiplicity 2 (2 * n)! < ↑(2 * n) + 1 by\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.2 (two_not_dvd_two_mul_add_one n), zero_add]\n      refine' this.trans _\n      exact_mod_cast lt_succ_self _\n#align nat.multiplicity_two_factorial_lt Nat.multiplicity_two_factorial_lt\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/Multiplicity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7632223094028304}}
{"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 data.nat.interval\n\nnamespace combinatorics\n\n/- @latex: defn_intervals -/\ndef Ico (n m : ℕ) : finset ℕ := (finset.Ico n m)\ndef Icc (n m : ℕ) : finset ℕ := Ico n m.succ\ndef Ioo (n m : ℕ) : finset ℕ := Ico n.succ m\ndef Ioc (n m : ℕ) : finset ℕ := Ico n.succ m.succ\n\nlemma mem_Ico { n m k : ℕ } : k ∈ (Ico n m) ↔ (n ≤ k ∧ k < m) := \n finset.mem_Ico\n\nlemma mem_Icc { n m k : ℕ } : k ∈ (Icc n m) ↔ (n ≤ k ∧ k ≤ m) := \nby { rw[Icc, ← @nat.lt_succ_iff k m], exact finset.mem_Ico }\n\nlemma mem_Ioo { n m k : ℕ } : k ∈ (Ioo n m) ↔ (n < k ∧ k < m) := \nby { rw[Ioo, ← @nat.succ_le_iff n k], exact finset.mem_Ico }\n\nlemma mem_Ioc { n m k : ℕ } : k ∈ (Ioc n m) ↔ (n < k ∧ k ≤ m) := \nby { rw[Ioc, ← @nat.lt_succ_iff k m, ← @nat.succ_le_iff n k],\n      exact finset.mem_Ico } \n\nlemma Ico_card (n m : ℕ) : (Ico n m).card = m - n := nat.card_Ico n m\n\nlemma Icc_card (n m : ℕ) : (Icc n m).card = m.succ - n := \nby { rw[Icc, Ico_card] }\n\nlemma Ioo_card (n m : ℕ) : (Ioo n m).card = (m - n).pred := \nby { rw[Ioo, Ico_card, nat.sub_succ] }\n\nlemma Ioc_card (n m : ℕ) : (Ioc n m).card = m - n := \nby { rw[Ioc, Ico_card, nat.succ_sub_succ] }\n\nend combinatorics\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_interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331958, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7631492094184986}}
{"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\" (∨`)\n\nWe learn about how to manipulate `P ∨ 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-/\n\n-- Throughout this sheet, `P`, `Q`, `R` and `S` will denote propositions.\n\nvariables (P Q R S : Prop)\n\nexample : P → P ∨ Q :=\nbegin\n  sorry\nend\n\nexample : Q → P ∨ Q :=\nbegin\n  sorry,\nend\n\nexample : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  sorry\nend\n\n-- symmetry of `or`\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n-- associativity of `or`\nexample : (P ∨ Q) ∨ R ↔ P ∨ (Q ∨ R) :=\nbegin\n  sorry,\nend\n\nexample : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\nexample : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\nexample : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\nend\n\n-- de Morgan's laws\nexample : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\nbegin\n  sorry\nend\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/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308091776495, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.763149206950934}}
{"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.circulant\n! leanprover-community/mathlib commit 806bbb0132ba63b93d5edbe4789ea226f8329979\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.Symmetric\n\n/-!\n# Circulant matrices\n\nThis file contains the definition and basic results about circulant matrices.\nGiven a vector `v : n → α` 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 → α`.\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\n\nvariable {α β m n R : Type _}\n\nnamespace Matrix\n\nopen Function\n\nopen Matrix BigOperators\n\n/-- Given the condition `[has_sub n]` and a vector `v : n → α`,\n    we define `circulant v` to be the circulant matrix generated by `v` of type `matrix n n α`.\n    The `(i,j)`th entry is defined to be `v (i - j)`. -/\n@[simp]\ndef circulant [Sub n] (v : n → α) : Matrix n n α\n  | i, j => v (i - j)\n#align matrix.circulant Matrix.circulant\n\ntheorem circulant_col_zero_eq [AddGroup n] (v : n → α) (i : n) : circulant v i 0 = v i :=\n  congr_arg v (sub_zero _)\n#align matrix.circulant_col_zero_eq Matrix.circulant_col_zero_eq\n\ntheorem circulant_injective [AddGroup n] : Injective (circulant : (n → α) → Matrix n n α) :=\n  by\n  intro v w h\n  ext k\n  rw [← circulant_col_zero_eq v, ← circulant_col_zero_eq w, h]\n#align matrix.circulant_injective Matrix.circulant_injective\n\ntheorem Fin.circulant_injective : ∀ n, Injective fun v : Fin n → α => circulant v\n  | 0 => by decide\n  | n + 1 => circulant_injective\n#align matrix.fin.circulant_injective Matrix.Fin.circulant_injective\n\n@[simp]\ntheorem circulant_inj [AddGroup n] {v w : n → α} : circulant v = circulant w ↔ v = w :=\n  circulant_injective.eq_iff\n#align matrix.circulant_inj Matrix.circulant_inj\n\n@[simp]\ntheorem Fin.circulant_inj {n} {v w : Fin n → α} : circulant v = circulant w ↔ v = w :=\n  (Fin.circulant_injective n).eq_iff\n#align matrix.fin.circulant_inj Matrix.Fin.circulant_inj\n\ntheorem transpose_circulant [AddGroup n] (v : n → α) : (circulant v)ᵀ = circulant fun i => v (-i) :=\n  by ext <;> simp\n#align matrix.transpose_circulant Matrix.transpose_circulant\n\ntheorem conjTranspose_circulant [Star α] [AddGroup n] (v : n → α) :\n    (circulant v)ᴴ = circulant (star fun i => v (-i)) := by ext <;> simp\n#align matrix.conj_transpose_circulant Matrix.conjTranspose_circulant\n\ntheorem Fin.transpose_circulant : ∀ {n} (v : Fin n → α), (circulant v)ᵀ = circulant fun i => v (-i)\n  | 0 => by decide\n  | n + 1 => transpose_circulant\n#align matrix.fin.transpose_circulant Matrix.Fin.transpose_circulant\n\ntheorem Fin.conjTranspose_circulant [Star α] :\n    ∀ {n} (v : Fin n → α), (circulant v)ᴴ = circulant (star fun i => v (-i))\n  | 0 => by decide\n  | n + 1 => conjTranspose_circulant\n#align matrix.fin.conj_transpose_circulant Matrix.Fin.conjTranspose_circulant\n\ntheorem map_circulant [Sub n] (v : n → α) (f : α → β) :\n    (circulant v).map f = circulant fun i => f (v i) :=\n  ext fun _ _ => rfl\n#align matrix.map_circulant Matrix.map_circulant\n\ntheorem circulant_neg [Neg α] [Sub n] (v : n → α) : circulant (-v) = -circulant v :=\n  ext fun _ _ => rfl\n#align matrix.circulant_neg Matrix.circulant_neg\n\n@[simp]\ntheorem circulant_zero (α n) [Zero α] [Sub n] : circulant 0 = (0 : Matrix n n α) :=\n  ext fun _ _ => rfl\n#align matrix.circulant_zero Matrix.circulant_zero\n\ntheorem circulant_add [Add α] [Sub n] (v w : n → α) :\n    circulant (v + w) = circulant v + circulant w :=\n  ext fun _ _ => rfl\n#align matrix.circulant_add Matrix.circulant_add\n\ntheorem circulant_sub [Sub α] [Sub n] (v w : n → α) :\n    circulant (v - w) = circulant v - circulant w :=\n  ext fun _ _ => rfl\n#align matrix.circulant_sub Matrix.circulant_sub\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`. -/\ntheorem circulant_mul [Semiring α] [Fintype n] [AddGroup n] (v w : n → α) :\n    circulant v ⬝ circulant w = circulant (mulVec (circulant v) w) :=\n  by\n  ext (i j)\n  simp only [mul_apply, mul_vec, circulant, dot_product]\n  refine' Fintype.sum_equiv (Equiv.subRight j) _ _ _\n  intro x\n  simp only [Equiv.subRight_apply, sub_sub_sub_cancel_right]\n#align matrix.circulant_mul Matrix.circulant_mul\n\ntheorem Fin.circulant_mul [Semiring α] :\n    ∀ {n} (v w : Fin n → α), circulant v ⬝ circulant w = circulant (mulVec (circulant v) w)\n  | 0 => by decide\n  | n + 1 => circulant_mul\n#align matrix.fin.circulant_mul Matrix.Fin.circulant_mul\n\n/-- Multiplication of circulant matrices commutes when the elements do. -/\ntheorem circulant_mul_comm [CommSemigroup α] [AddCommMonoid α] [Fintype n] [AddCommGroup n]\n    (v w : n → α) : circulant v ⬝ circulant w = circulant w ⬝ circulant v :=\n  by\n  ext (i j)\n  simp only [mul_apply, circulant, mul_comm]\n  refine' Fintype.sum_equiv ((Equiv.subLeft i).trans (Equiv.addRight j)) _ _ _\n  intro x\n  congr 2\n  · simp\n  · simp only [Equiv.coe_addRight, Function.comp_apply, Equiv.coe_trans, Equiv.subLeft_apply]\n    abel\n#align matrix.circulant_mul_comm Matrix.circulant_mul_comm\n\ntheorem Fin.circulant_mul_comm [CommSemigroup α] [AddCommMonoid α] :\n    ∀ {n} (v w : Fin n → α), circulant v ⬝ circulant w = circulant w ⬝ circulant v\n  | 0 => by decide\n  | n + 1 => circulant_mul_comm\n#align matrix.fin.circulant_mul_comm Matrix.Fin.circulant_mul_comm\n\n/-- `k • circulant v` is another circulant matrix `circulant (k • v)`. -/\ntheorem circulant_smul [Sub n] [SMul R α] (k : R) (v : n → α) :\n    circulant (k • v) = k • circulant v := by ext <;> simp\n#align matrix.circulant_smul Matrix.circulant_smul\n\n@[simp]\ntheorem circulant_single_one (α n) [Zero α] [One α] [DecidableEq n] [AddGroup n] :\n    circulant (Pi.single 0 1 : n → α) = (1 : Matrix n n α) :=\n  by\n  ext (i j)\n  simp [one_apply, Pi.single_apply, sub_eq_zero]\n#align matrix.circulant_single_one Matrix.circulant_single_one\n\n@[simp]\ntheorem circulant_single (n) [Semiring α] [DecidableEq n] [AddGroup n] [Fintype n] (a : α) :\n    circulant (Pi.single 0 a : n → α) = scalar n a :=\n  by\n  ext (i j)\n  simp [Pi.single_apply, one_apply, sub_eq_zero]\n#align matrix.circulant_single Matrix.circulant_single\n\n/-- Note we use `↑i = 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`. -/\ntheorem Fin.circulant_ite (α) [Zero α] [One α] :\n    ∀ n, circulant (fun i => ite (↑i = 0) 1 0 : Fin n → α) = 1\n  | 0 => by decide\n  | n + 1 => by\n    rw [← circulant_single_one]\n    congr with j\n    simp only [Pi.single_apply, Fin.ext_iff]\n    congr\n#align matrix.fin.circulant_ite Matrix.Fin.circulant_ite\n\n/-- A circulant of `v` is symmetric iff `v` equals its reverse. -/\ntheorem circulant_isSymm_iff [AddGroup n] {v : n → α} : (circulant v).IsSymm ↔ ∀ i, v (-i) = v i :=\n  by rw [IsSymm, transpose_circulant, circulant_inj, funext_iff]\n#align matrix.circulant_is_symm_iff Matrix.circulant_isSymm_iff\n\ntheorem Fin.circulant_isSymm_iff : ∀ {n} {v : Fin n → α}, (circulant v).IsSymm ↔ ∀ i, v (-i) = v i\n  | 0 => fun v => by simp [is_symm.ext_iff, IsEmpty.forall_iff]\n  | n + 1 => fun v => circulant_isSymm_iff\n#align matrix.fin.circulant_is_symm_iff Matrix.Fin.circulant_isSymm_iff\n\n/-- If `circulant v` is symmetric, `∀ i j : I, v (- i) = v i`. -/\ntheorem circulant_isSymm_apply [AddGroup n] {v : n → α} (h : (circulant v).IsSymm) (i : n) :\n    v (-i) = v i :=\n  circulant_isSymm_iff.1 h i\n#align matrix.circulant_is_symm_apply Matrix.circulant_isSymm_apply\n\ntheorem Fin.circulant_isSymm_apply {n} {v : Fin n → α} (h : (circulant v).IsSymm) (i : Fin n) :\n    v (-i) = v i :=\n  Fin.circulant_isSymm_iff.1 h i\n#align matrix.fin.circulant_is_symm_apply Matrix.Fin.circulant_isSymm_apply\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/Circulant.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526934, "lm_q2_score": 0.826711791935942, "lm_q1q2_score": 0.7630873562981142}}
{"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ölzl\n-/\nimport algebra.order.monoid.lemmas\nimport order.bounded_order\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\nset_option old_structure_cmd true\nopen function\n\nuniverse u\nvariables {α : Type u} {β : Type*}\n\n/-- An ordered commutative monoid is a commutative monoid\nwith a partial order such that `a ≤ b → c * a ≤ c * b` (multiplication is monotone)\n-/\n@[protect_proj, ancestor comm_monoid partial_order]\nclass ordered_comm_monoid (α : Type*) extends comm_monoid α, partial_order α :=\n(mul_le_mul_left       : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b)\n\n/-- An ordered (additive) commutative monoid is a commutative monoid\n  with a partial order such that `a ≤ b → c + a ≤ c + b` (addition is monotone)\n-/\n@[protect_proj, ancestor add_comm_monoid partial_order]\nclass ordered_add_comm_monoid (α : Type*) extends add_comm_monoid α, partial_order α :=\n(add_le_add_left       : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ 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 (*) (≤) :=\n{ elim := λ 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 ℕ` does not\npick up a `covariant_class M M (function.swap (*)) (≤)` 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 (*)) (≤) :=\ncovariant_swap_mul_le_of_covariant_mul_le M\n\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 (*) (≤)` implies\n`covariant_class M M (*) (<)`, see `left_cancel_semigroup.covariant_mul_lt_of_covariant_mul_le`. -/\n@[to_additive] lemma has_mul.to_covariant_class_left\n  (M : Type*) [has_mul M] [partial_order M] [covariant_class M M (*) (<)] :\n  covariant_class M M (*) (≤) :=\n⟨covariant_le_of_covariant_lt _ _ _ covariant_class.elim⟩\n\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 (*)) (≤)`, see\n`right_cancel_semigroup.covariant_swap_mul_lt_of_covariant_swap_mul_le`. -/\n@[to_additive] lemma has_mul.to_covariant_class_right\n  (M : Type*) [has_mul M] [partial_order M] [covariant_class M M (swap (*)) (<)] :\n  covariant_class M M (swap (*)) (≤) :=\n⟨covariant_le_of_covariant_lt _ _ _ covariant_class.elim⟩\n\nend ordered_instances\n\nlemma bit0_pos [ordered_add_comm_monoid α] {a : α} (h : 0 < a) : 0 < bit0 a :=\nadd_pos' h h\n\n/-- A linearly ordered additive commutative monoid. -/\n@[protect_proj, ancestor linear_order ordered_add_comm_monoid]\nclass linear_ordered_add_comm_monoid (α : Type*)\n  extends linear_order α, ordered_add_comm_monoid α.\n\n/-- A linearly ordered commutative monoid. -/\n@[protect_proj, ancestor linear_order ordered_comm_monoid, to_additive]\nclass linear_ordered_comm_monoid (α : Type*)\n  extends linear_order α, ordered_comm_monoid α.\n\n/-- A linearly ordered commutative monoid with an additively absorbing `⊤` 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 (α : Type*)\n  extends linear_ordered_add_comm_monoid α, has_top α :=\n(le_top : ∀ x : α, x ≤ ⊤)\n(top_add' : ∀ x : α, ⊤ + x = ⊤)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_ordered_add_comm_monoid_with_top.to_order_top (α : Type u)\n  [h : linear_ordered_add_comm_monoid_with_top α] : order_top α :=\n{ ..h }\n\nsection linear_ordered_add_comm_monoid_with_top\nvariables [linear_ordered_add_comm_monoid_with_top α] {a b : α}\n\n@[simp]\nlemma top_add (a : α) : ⊤ + a = ⊤ := linear_ordered_add_comm_monoid_with_top.top_add' a\n\n@[simp]\nlemma add_top (a : α) : a + ⊤ = ⊤ :=\ntrans (add_comm _ _) (top_add _)\n\nend linear_ordered_add_comm_monoid_with_top\n", "meta": {"author": "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/defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8499711813581708, "lm_q1q2_score": 0.7630151209530384}}
{"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.polynomial.degree.definitions\n\n/-!\n# Cancel the leading terms of two polynomials\n\n## Definition\n\n* `cancel_leads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting.\n\n## Main Results\nThe degree of `cancel_leads` is less than that of the larger of the two polynomials being cancelled.\nThus it is useful for induction or minimal-degree arguments.\n-/\nnamespace polynomial\nnoncomputable theory\nopen_locale polynomial\n\nvariables {R : Type*}\n\nsection comm_ring\nvariables [ring R] (p q : R[X])\n\n/-- `cancel_leads p q` is formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting. -/\ndef cancel_leads : R[X] :=\nC p.leading_coeff * X ^ (p.nat_degree - q.nat_degree) * q -\nC q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p\n\nvariables {p q}\n\n@[simp] lemma neg_cancel_leads : - p.cancel_leads q = q.cancel_leads p := neg_sub _ _\n\nend comm_ring\n\nsection comm_ring\nvariables [comm_ring R] {p q : R[X]}\n\nlemma dvd_cancel_leads_of_dvd_of_dvd {r : R[X]} (pq : p ∣ q) (pr : p ∣ r) :\n  p ∣ q.cancel_leads r :=\ndvd_sub (pr.trans (dvd.intro_left _ rfl)) (pq.trans (dvd.intro_left _ rfl))\n\nend comm_ring\n\nlemma nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree [comm_ring R] [is_domain R]\n  {p q : R[X]} (h : p.nat_degree ≤ q.nat_degree) (hq : 0 < q.nat_degree) :\n  (p.cancel_leads q).nat_degree < q.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { convert hq,\n    simp [hp, cancel_leads], },\n  rw [cancel_leads, sub_eq_add_neg, tsub_eq_zero_iff_le.mpr h, pow_zero, mul_one],\n  by_cases h0 :\n      C p.leading_coeff * q + -(C q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p) = 0,\n  { convert hq,\n    simp only [h0, nat_degree_zero], },\n  have hq0 : ¬ q = 0,\n  { contrapose! hq,\n    simp [hq] },\n  apply lt_of_le_of_ne,\n  { rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree h0, ← degree_eq_nat_degree hq0],\n    apply le_trans (degree_add_le _ _),\n    rw ← leading_coeff_eq_zero at hp hq0,\n    simp only [max_le_iff, degree_C hp, degree_C hq0, le_refl q.degree, true_and, nat.cast_with_bot,\n      nsmul_one, degree_neg, degree_mul, zero_add, degree_X, degree_pow],\n    rw leading_coeff_eq_zero at hp hq0,\n    rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq0, ← with_bot.coe_add, with_bot.coe_le_coe,\n      tsub_add_cancel_of_le h], },\n  { contrapose! h0,\n    rw [← leading_coeff_eq_zero, leading_coeff, h0, mul_assoc, mul_comm _ p,\n      ← tsub_add_cancel_of_le h, add_comm _ p.nat_degree],\n    simp only [coeff_mul_X_pow, coeff_neg, coeff_C_mul, add_tsub_cancel_left, coeff_add],\n    rw [add_comm p.nat_degree, tsub_add_cancel_of_le h, ← leading_coeff, ← leading_coeff,\n      mul_comm _ q.leading_coeff, ← sub_eq_add_neg, ← mul_sub, sub_self, mul_zero] }\nend\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/cancel_leads.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7630151198678102}}
{"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-/\nimport algebra.ring.defs\nimport group_theory.subsemigroup.operations\n\n/-!\n# Centers 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.center`: the center of a magma\n* `subsemigroup.center`: the center of a semigroup\n* `set.add_center`: the center of an additive magma\n* `add_subsemigroup.center`: the center of an additive semigroup\n\nWe provide `submonoid.center`, `add_submonoid.center`, `subgroup.center`, `add_subgroup.center`,\n`subsemiring.center`, and `subring.center` in other files.\n-/\n\nvariables {M : Type*}\n\nnamespace set\n\nvariables (M)\n\n/-- The center of a magma. -/\n@[to_additive add_center /-\" The center of an additive magma. \"-/]\ndef center [has_mul M] : set M := {z | ∀ m, m * z = z * m}\n\n@[to_additive mem_add_center]\nlemma mem_center_iff [has_mul M] {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl\n\ninstance decidable_mem_center [has_mul M]  [∀ a : M, decidable $ ∀ b : M, b * a = a * b] :\n  decidable_pred (∈ center M) :=\nλ _, decidable_of_iff' _ (mem_center_iff M)\n\n@[simp, to_additive zero_mem_add_center]\nlemma one_mem_center [mul_one_class M] : (1 : M) ∈ set.center M := by simp [mem_center_iff]\n\n@[simp]\nlemma zero_mem_center [mul_zero_class M] : (0 : M) ∈ set.center M := by simp [mem_center_iff]\n\nvariables {M}\n\n@[simp, to_additive add_mem_add_center]\nlemma mul_mem_center [semigroup M] {a b : M}\n  (ha : a ∈ set.center M) (hb : b ∈ set.center M) : a * b ∈ set.center M :=\nλ g, by rw [mul_assoc, ←hb g, ← mul_assoc, ha g, mul_assoc]\n\n@[simp, to_additive neg_mem_add_center]\nlemma inv_mem_center [group M] {a : M} (ha : a ∈ set.center M) : a⁻¹ ∈ set.center M :=\nλ g, by rw [← inv_inj, mul_inv_rev, inv_inv, ← ha, mul_inv_rev, inv_inv]\n\n@[simp]\nlemma add_mem_center [distrib M] {a b : M}\n  (ha : a ∈ set.center M) (hb : b ∈ set.center M) : a + b ∈ set.center M :=\nλ c, by rw [add_mul, mul_add, ha c, hb c]\n\n@[simp]\nlemma neg_mem_center [ring M] {a : M} (ha : a ∈ set.center M) : -a ∈ set.center M :=\nλ c, by rw [←neg_mul_comm, ha (-c), neg_mul_comm]\n\n@[to_additive subset_add_center_add_units]\nlemma subset_center_units [monoid M] :\n  (coe : Mˣ → M) ⁻¹' center M ⊆ set.center Mˣ :=\nλ a ha b, units.ext $ ha _\n\nlemma center_units_subset [group_with_zero M] :\n  set.center Mˣ ⊆ (coe : Mˣ → M) ⁻¹' center M :=\nλ a ha b, begin\n  obtain rfl | hb := eq_or_ne b 0,\n  { rw [zero_mul, mul_zero], },\n  { exact units.ext_iff.mp (ha (units.mk0 _ hb)) }\nend\n\n/-- In a group with zero, the center of the units is the preimage of the center. -/\nlemma center_units_eq [group_with_zero M] :\n  set.center Mˣ = (coe : Mˣ → M) ⁻¹' center M :=\nsubset.antisymm center_units_subset subset_center_units\n\n@[simp]\nlemma inv_mem_center₀ [group_with_zero M] {a : M} (ha : a ∈ set.center M) : a⁻¹ ∈ set.center M :=\nbegin\n  obtain rfl | ha0 := eq_or_ne a 0,\n  { rw inv_zero, exact zero_mem_center M },\n  rcases is_unit.mk0 _ ha0 with ⟨a, rfl⟩,\n  rw ←units.coe_inv,\n  exact center_units_subset (inv_mem_center (subset_center_units ha)),\nend\n\n@[simp, to_additive sub_mem_add_center]\nlemma div_mem_center [group M] {a b : M} (ha : a ∈ set.center M) (hb : b ∈ set.center M) :\n  a / b ∈ set.center M :=\nbegin\n  rw [div_eq_mul_inv],\n  exact mul_mem_center ha (inv_mem_center hb),\nend\n\n@[simp]\nlemma div_mem_center₀ [group_with_zero M] {a b : M} (ha : a ∈ set.center M)\n  (hb : b ∈ set.center M) : a / b ∈ set.center M :=\nbegin\n  rw div_eq_mul_inv,\n  exact mul_mem_center ha (inv_mem_center₀ hb),\nend\n\nvariables (M)\n\n@[simp, to_additive add_center_eq_univ]\nlemma center_eq_univ [comm_semigroup M] : center M = set.univ :=\nsubset.antisymm (subset_univ _) $ λ x _ y, mul_comm y x\n\nend set\n\nnamespace subsemigroup\nsection\nvariables (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 \"The center of a semigroup `M` is the set of elements that commute with everything in\n`M`\"]\ndef center : subsemigroup M :=\n{ carrier := set.center M,\n  mul_mem' := λ a b, set.mul_mem_center }\n\n@[to_additive] lemma coe_center : ↑(center M) = set.center M := rfl\n\nvariables {M}\n\n@[to_additive] lemma mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl\n\n@[to_additive]\ninstance decidable_mem_center (a) [decidable $ ∀ b : M, b * a = a * b] :\n  decidable (a ∈ center M) :=\ndecidable_of_iff' _ mem_center_iff\n\n/-- The center of a semigroup is commutative. -/\n@[to_additive \"The center of an additive semigroup is commutative.\"]\ninstance : comm_semigroup (center M) :=\n{ mul_comm := λ a b, subtype.ext $ b.prop _,\n  .. mul_mem_class.to_semigroup (center M) }\n\nend\n\nsection\nvariables (M) [comm_semigroup M]\n\n@[to_additive, simp] lemma center_eq_top : center M = ⊤ :=\nset_like.coe_injective (set.center_eq_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/center.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7630151194031529}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport data.real.basic -- Importamos los números reales.\n\n/-!\nAlgunos de estos ejemplos se han adaptado de la charla de estructuras y classes de LftCM 2022:\n<https://icerm.brown.edu/video_archive/?play=2897>\n-/\n\n\nnoncomputable theory \n\n/-! # Clases\n\nReferencia : Theorem Proving in Lean.\n\nCualquier estructura en Lean se puede marcar como una *clase de tipos*.\nPodemos declarar *instancias* de una clase.\nCuando el elaborador está buscando un elemento de una clase, puede consultar una tabla con las \ninstancias declaradas para encontrar un elemento apropiado.\n-/\n\n/-! ## Variables -/\n\n--En Lean, podemos usar distintos tipos de variables\nvariable (r : ℝ) -- variable explícita.\nvariable {n : ℕ} -- variable implícita. Para argumentos que se pueden inferir a partir de otros.\nvariable (G : Type*)\nvariable [group G] -- argumentos entre `[ ]` son inferidos por el mecanismo de inferencia de clases.\n\n/- Las variables que acabamos de declarar estarán visibles hasta el final del fichero. No es posible\ntener dos variables visibles con el mismo nombre. \n\nPodemos modificar este comportamiento utilizando secciones:\n-/\nsection ejemplo\nvariable (a : ℕ)\n--variable (a : ℝ) -- da error\nend ejemplo\n\nvariable (a : ℕ)\n\n-- Ejemplos\nlemma nat.add_pos (n m : ℕ) (hm : 0 < m) : \n  0 < n + m :=\nsorry\n\nlemma nat.add_pos' (n : ℕ) {m : ℕ} (hm : 0 < m) : \n  0 < n + m :=\nsorry\n\nexample (n m : ℕ) (hm : 0 < m) : \n  0 < m + n :=\nbegin\n  rw add_comm, -- ¿por qué funciona esto?\n  sorry\n  --exact nat.add_pos n m hm,\n  --exact nat.add_pos n _ hm, -- Lean puede deducir m a partir de hm\n  --exact nat.add_pos' n hm -- con la segunda variante, la barra _ no es necesara.\nend\n\n/- ¿Por qué hemos podido utilizar `add_comm` en el ejemplo anterior?\n  `add_comm` es un teorema sobre semigrupos aditivos conmutativos.\n  Lean ha encontrado automáticamente la estructura de semigrupo de `ℕ`, mediante un proceso\n  llamado *inferencia de clases*. -/\n\n/- Cualquier estructura en Lean se puede marcar como una *clase de tipos*. Por ejemplo,\n  `add_group` es la clase de grupos aditivos. -/\n--#check add_group\n\n/- Podemos declarar *instancias* de una clase. Por ejemplo, la estructura de grupo aditivo de `ℤ`\nestá registrada en la instancia `int.add_group`. -/\n--#check int.add_group\n\n/-Cuando el elaborador está buscando un elemento de una clase, puede consultar una tabla con las \ninstancias declaradas para encontrar un elemento apropiado. -/\n--#check add_comm -- tiene un argumento [add_comm_semigroup G]\n\n/- En Lean utilizamos clases para registrar estructuras algebraicas, topológicas, analíticas, ... -/\n\n-- Ejemplo: Podemos crear una clase para indicar que un tipo es no vacío.\nclass no_vacio (A : Type) : Prop :=\n(has_val : ∃ x : A, true)\n\ninstance : no_vacio ℤ :=\n{ has_val := ⟨0, trivial⟩ }\n\ninstance {A B : Type} [ha : no_vacio A] [hb : no_vacio B] :\n  no_vacio (A × B) :=\nbegin\n  cases ha.has_val with a _,\n  cases hb.has_val with b _,\n  apply no_vacio.mk,\n  use (a, b)\nend\n\n-- Ejemplo\ninstance producto_de_grupos {G H : Type*} [group G] [group H] : group (G × H) := infer_instance\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_3/clases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.763005363545346}}
{"text": "import .lub_prodSets\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 10\n-/\n\n\n-- main result in lemma sup_mem_prod_of_sets\n-- hide\n--def mem_prod_sets (A : set ℝ) (B : set ℝ) := { x : ℝ | ∃ y ∈ A, ∃ z ∈ B, x = y * z}\n\n\n/-\nIntermediary result `zero_in_prod` proved in sets_level08.\n\nIntermediary result `mem_prod_sets_lub_proof` in previous level.\n-/\n\n\n/- Lemma\nFor two non-empty sets of reals $A$ and $B$, it is not in general true that\n$$ \\textrm{sup} (A \\cdot B) = \\textrm{sup} (A) \\cdot \\textrm{sup}(B)$$\nwhere $A \\cdot B$ is defined pointwise as above.\n-/\nlemma sup_mem_prod_of_sets : ¬ ( ∀ (A B : set ℝ) (a b : ℝ),\n  A.nonempty ∧ B.nonempty → bdd_below A ∧ bdd_below B →\n  is_lub A a ∧ is_lub B b → \n  is_lub (mem_prod_sets A B) (a * b) ) :=\nbegin\n  intro H,\n  -- do an example with A = [-2,-1], B = [0,3]\n  set A1 : set ℝ := set.Icc (-2:ℝ) (-1:ℝ) with hA,\n  set B1 : set ℝ := set.Icc (0:ℝ) (3:ℝ) with hB,\n  set a : ℝ := (-1:ℝ) with ha,\n  set b : ℝ := (3 : ℝ) with hb,\n  have G := H A1 B1,\n  have h1A : A1.nonempty, simp, norm_num,\n  have h1B : B1.nonempty, simp, norm_num,\n  have F := G a b (and.intro h1A h1B),\n  have h11 : ((-2:ℝ) ≤ -1), norm_num,\n  have h21 : (0:ℝ) ≤ (3:ℝ), norm_num,\n  have h2A : bdd_below A1, \n    -- use the definition in bounds.lean\n    have h12 := is_glb_Icc h11,\n    cases h12 with hh hhh,\n    existsi (-2:ℝ), exact hh,\n  have h2B : bdd_below B1, \n    have h22 := is_glb_Icc h21,\n    cases h22 with hh hhh,\n    existsi (0:ℝ), exact hh,\n  have E := F (and.intro h2A h2B),\n  have h1 : is_lub A1 a, \n    exact is_lub_Icc h11,\n  have h2 : is_lub B1 b, \n    exact is_lub_Icc h21,\n  have D := E (and.intro h1 h2),\n  rw ha at h1, rw hb at h2, rw ha at D, rw hb at D,\n  have E : is_lub (mem_prod_sets A1 B1) 0, \n    exact mem_prod_sets_lub_proof,\n  have E1 := is_lub.unique D E,\n  linarith, 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/supProdSets.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073577, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.762997319233812}}
{"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ölzl, Scott Morrison, Jens Wagemaker\n-/\nimport data.fintype.big_operators\nimport data.nat.with_bot\nimport data.polynomial.monomial\nimport data.polynomial.coeff\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 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\nnoncomputable theory\n\nopen finsupp finset\nopen_locale big_operators classical polynomial\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}\n\nsection semiring\nvariables [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 ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise\n`degree 0 = ⊥`. -/\ndef degree (p : R[X]) : with_bot ℕ := p.support.max\n\nlemma degree_lt_wf : well_founded (λp q : R[X], degree p < degree q) :=\ninv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)\n\ninstance : has_well_founded R[X] := ⟨_, degree_lt_wf⟩\n\n/-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/\ndef nat_degree (p : R[X]) : ℕ := (degree p).unbot' 0\n\n/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/\ndef leading_coeff (p : R[X]) : R := coeff p (nat_degree p)\n\n/-- a polynomial is `monic` if its leading coefficient is 1 -/\ndef monic (p : R[X]) := leading_coeff p = (1 : R)\n\n@[nontriviality] lemma monic_of_subsingleton [subsingleton R] (p : R[X]) : monic p :=\nsubsingleton.elim _ _\n\nlemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl\n\ninstance monic.decidable [decidable_eq R] : decidable (monic p) :=\nby unfold monic; apply_instance\n\n@[simp] lemma monic.leading_coeff {p : R[X]} (hp : p.monic) :\n  leading_coeff p = 1 := hp\n\nlemma monic.coeff_nat_degree {p : R[X]} (hp : p.monic) : p.coeff p.nat_degree = 1 := hp\n\n@[simp] lemma degree_zero : degree (0 : R[X]) = ⊥ := rfl\n\n@[simp] lemma nat_degree_zero : nat_degree (0 : R[X]) = 0 := rfl\n\n@[simp] lemma coeff_nat_degree : coeff p (nat_degree p) = leading_coeff p := rfl\n\nlemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=\n⟨λ h, support_eq_empty.1 (finset.max_eq_bot.1 h),\nλ h, h.symm ▸ rfl⟩\n\n@[nontriviality] lemma degree_of_subsingleton [subsingleton R] : degree p = ⊥ :=\nby rw [subsingleton.elim p 0, degree_zero]\n\n@[nontriviality] lemma nat_degree_of_subsingleton [subsingleton R] : nat_degree p = 0 :=\nby rw [subsingleton.elim p 0, nat_degree_zero]\n\nlemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=\nlet ⟨n, hn⟩ :=\n  not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in\nhave hn : degree p = some n := not_not.1 hn,\nby rw [nat_degree, hn]; refl\n\nlemma degree_eq_iff_nat_degree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :\n  p.degree = n ↔ p.nat_degree = n :=\nby rw [degree_eq_nat_degree hp, with_bot.coe_eq_coe]\n\nlemma degree_eq_iff_nat_degree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :\n  p.degree = n ↔ p.nat_degree = n :=\nbegin\n  split,\n  { intro H, rwa ← degree_eq_iff_nat_degree_eq, rintro rfl,\n    rw degree_zero at H, exact option.no_confusion H },\n  { intro H, rwa degree_eq_iff_nat_degree_eq, rintro rfl,\n    rw nat_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }\nend\n\nlemma nat_degree_eq_of_degree_eq_some {p : R[X]} {n : ℕ}\n  (h : degree p = n) : nat_degree p = n :=\nhave hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,\noption.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,\n  by rwa [← degree_eq_nat_degree hp0]\n\n@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=\nwith_bot.gi_unbot'_bot.gc.le_u_l _\n\nlemma nat_degree_eq_of_degree_eq [semiring S] {q : S[X]} (h : degree p = degree q) :\n  nat_degree p = nat_degree q :=\nby unfold nat_degree; rw h\n\nlemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=\nshow @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),\nfrom finset.le_sup (mem_support_iff.2 h)\n\nlemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p :=\nbegin\n  rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],\n  exact le_degree_of_ne_zero h,\n  { assume h, subst h, exact h rfl }\nend\n\nlemma le_nat_degree_of_mem_supp (a : ℕ) :\n  a ∈ p.support → a ≤ nat_degree p:=\nle_nat_degree_of_ne_zero ∘ mem_support_iff.mp\n\nlemma degree_eq_of_le_of_coeff_ne_zero (pn : p.degree ≤ n) (p1 : p.coeff n ≠ 0) :\n  p.degree = n :=\npn.antisymm (le_degree_of_ne_zero p1)\n\nlemma nat_degree_eq_of_le_of_coeff_ne_zero (pn : p.nat_degree ≤ n) (p1 : p.coeff n ≠ 0) :\n  p.nat_degree = n :=\npn.antisymm (le_nat_degree_of_ne_zero p1)\n\nlemma degree_mono [semiring S] {f : R[X]} {g : S[X]}\n  (h : f.support ⊆ g.support) : f.degree ≤ g.degree := finset.sup_mono h\n\nlemma supp_subset_range (h : nat_degree p < m) : p.support ⊆ finset.range m :=\nλ n hn, mem_range.2 $ (le_nat_degree_of_mem_supp _ hn).trans_lt h\n\nlemma supp_subset_range_nat_degree_succ : p.support ⊆ finset.range (nat_degree p + 1) :=\nsupp_subset_range (nat.lt_succ_self _)\n\nlemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q :=\nbegin\n  by_cases hp : p = 0,\n  { rw hp, exact bot_le },\n  { rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h }\nend\n\nlemma degree_ne_of_nat_degree_ne {n : ℕ} :\n  p.nat_degree ≠ n → degree p ≠ n :=\nmt $ λ h, by rw [nat_degree, h, with_bot.unbot'_coe]\n\ntheorem nat_degree_le_iff_degree_le {n : ℕ} : nat_degree p ≤ n ↔ degree p ≤ n :=\nwith_bot.unbot'_bot_le_iff\n\nlemma nat_degree_lt_iff_degree_lt (hp : p ≠ 0) :\n  p.nat_degree < n ↔ p.degree < ↑n :=\nwith_bot.unbot'_lt_iff $ degree_eq_bot.not.mpr hp\n\nalias nat_degree_le_iff_degree_le ↔ ..\n\nlemma nat_degree_le_nat_degree [semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :\n  p.nat_degree ≤ q.nat_degree :=\nwith_bot.gi_unbot'_bot.gc.monotone_l hpq\n\nlemma nat_degree_lt_nat_degree {p q : R[X]} (hp : p ≠ 0) (hpq : p.degree < q.degree) :\n  p.nat_degree < q.nat_degree :=\nbegin\n  by_cases hq : q = 0, { exact (not_lt_bot $ hq.subst hpq).elim },\n  rwa [degree_eq_nat_degree hp, degree_eq_nat_degree hq, with_bot.coe_lt_coe] at hpq\nend\n\n@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=\nby rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,\n    with_bot.coe_zero]\n\nlemma degree_C_le : degree (C a) ≤ 0 :=\nbegin\n  by_cases h : a = 0,\n  { rw [h, C_0], exact bot_le },\n  { rw [degree_C h], exact le_rfl }\nend\n\nlemma degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt $ with_bot.coe_lt_coe.mpr zero_lt_one\n\nlemma degree_one_le : degree (1 : R[X]) ≤ (0 : with_bot ℕ) :=\nby rw [← C_1]; exact degree_C_le\n\n@[simp] lemma nat_degree_C (a : R) : nat_degree (C a) = 0 :=\nbegin\n  by_cases ha : a = 0,\n  { have : C a = 0, { rw [ha, C_0] },\n    rw [nat_degree, degree_eq_bot.2 this],\n    refl },\n  { rw [nat_degree, degree_C ha], refl }\nend\n\n@[simp] lemma nat_degree_one : nat_degree (1 : R[X]) = 0 := nat_degree_C 1\n\n@[simp] lemma nat_degree_nat_cast (n : ℕ) : nat_degree (n : R[X]) = 0 :=\nby simp only [←C_eq_nat_cast, nat_degree_C]\n\n@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n :=\nby rw [degree, support_monomial n ha]; refl\n\n@[simp] lemma degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=\nby rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]\n\nlemma degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 :=\nby simpa only [pow_one] using degree_C_mul_X_pow 1 ha\n\nlemma degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=\nif h : a = 0 then by rw [h, (monomial n).map_zero]; exact bot_le else le_of_eq (degree_monomial n h)\n\nlemma degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n :=\nby { rw C_mul_X_pow_eq_monomial, apply degree_monomial_le }\n\nlemma degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 :=\nby simpa only [pow_one] using degree_C_mul_X_pow_le 1 a\n\n@[simp] lemma nat_degree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : nat_degree (C a * X ^ n) = n :=\nnat_degree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)\n\n@[simp] lemma nat_degree_C_mul_X (a : R) (ha : a ≠ 0) : nat_degree (C a * X) = 1 :=\nby simpa only [pow_one] using nat_degree_C_mul_X_pow 1 a ha\n\n@[simp] lemma nat_degree_monomial [decidable_eq R] (i : ℕ) (r : R) :\n  nat_degree (monomial i r) = if r = 0 then 0 else i :=\nbegin\n  split_ifs with hr,\n  { simp [hr] },\n  { rw [← C_mul_X_pow_eq_monomial, nat_degree_C_mul_X_pow i r hr] }\nend\n\nlemma nat_degree_monomial_le (a : R) {m : ℕ} : (monomial m a).nat_degree ≤ m :=\nbegin\n  rw polynomial.nat_degree_monomial,\n  split_ifs,\n  exacts [nat.zero_le _, rfl.le],\nend\n\nlemma nat_degree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) :\n  (monomial i r).nat_degree = i :=\neq.trans (nat_degree_monomial _ _) (if_neg r0)\n\nlemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=\nnot_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))\n\nlemma coeff_eq_zero_of_nat_degree_lt {p : R[X]} {n : ℕ} (h : p.nat_degree < n) :\n  p.coeff n = 0 :=\nbegin\n  apply coeff_eq_zero_of_degree_lt,\n  by_cases hp : p = 0,\n  { subst hp, exact with_bot.bot_lt_coe n },\n  { rwa [degree_eq_nat_degree hp, with_bot.coe_lt_coe] }\nend\n\nlemma ext_iff_nat_degree_le {p q : R[X]} {n : ℕ} (hp : p.nat_degree ≤ n) (hq : q.nat_degree ≤ n) :\n  p = q ↔ (∀ i ≤ n, p.coeff i = q.coeff i) :=\nbegin\n  refine iff.trans polynomial.ext_iff _,\n  refine forall_congr (λ i, ⟨λ h _, h, λ h, _⟩),\n  refine (le_or_lt i n).elim h (λ k, _),\n  refine (coeff_eq_zero_of_nat_degree_lt (hp.trans_lt k)).trans\n    (coeff_eq_zero_of_nat_degree_lt (hq.trans_lt k)).symm,\nend\n\nlemma ext_iff_degree_le {p q : R[X]} {n : ℕ} (hp : p.degree ≤ n) (hq : q.degree ≤ n) :\n  p = q ↔ (∀ i ≤ n, p.coeff i = q.coeff i)  :=\next_iff_nat_degree_le (nat_degree_le_of_degree_le hp) (nat_degree_le_of_degree_le hq)\n\n@[simp] lemma coeff_nat_degree_succ_eq_zero {p : R[X]} : p.coeff (p.nat_degree + 1) = 0 :=\ncoeff_eq_zero_of_nat_degree_lt (lt_add_one _)\n\n-- We need the explicit `decidable` argument here because an exotic one shows up in a moment!\nlemma ite_le_nat_degree_coeff (p : R[X]) (n : ℕ) (I : decidable (n < 1 + nat_degree p)) :\n  @ite _ (n < 1 + nat_degree p) I (coeff p n) 0 = coeff p n :=\nbegin\n  split_ifs,\n  { refl },\n  { exact (coeff_eq_zero_of_nat_degree_lt (not_le.1 (λ w, h (nat.lt_one_add_iff.2 w)))).symm, }\nend\n\nlemma as_sum_support (p : R[X]) :\n  p = ∑ i in p.support, monomial i (p.coeff i) :=\n(sum_monomial_eq p).symm\n\nlemma as_sum_support_C_mul_X_pow (p : R[X]) :\n  p = ∑ i in p.support, C (p.coeff i) * X^i :=\ntrans p.as_sum_support $ by simp only [C_mul_X_pow_eq_monomial]\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-/\nlemma sum_over_range' [add_comm_monoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0)\n  (n : ℕ) (w : p.nat_degree < n) :\n  p.sum f = ∑ (a : ℕ) in range n, f a (coeff p a) :=\nbegin\n  rcases p,\n  have := supp_subset_range w,\n  simp only [polynomial.sum, support, coeff, nat_degree, degree] at ⊢ this,\n  exact finsupp.sum_of_support_subset _ this _ (λ n hn, h n)\nend\n\n/--\nWe can reexpress a sum over `p.support` as a sum over `range (p.nat_degree + 1)`.\n-/\nlemma sum_over_range [add_comm_monoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) :\n  p.sum f = ∑ (a : ℕ) in range (p.nat_degree + 1), f a (coeff p a) :=\nsum_over_range' p h (p.nat_degree + 1) (lt_add_one _)\n\n-- TODO this is essentially a duplicate of `sum_over_range`, and should be removed.\nlemma sum_fin [add_comm_monoid S]\n  (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) {n : ℕ} {p : R[X]} (hn : p.degree < n) :\n  ∑ (i : fin n), f i (p.coeff i) = p.sum f :=\nbegin\n  by_cases hp : p = 0,\n  { rw [hp, sum_zero_index, finset.sum_eq_zero], intros i _, exact hf i },\n  rw [sum_over_range' _ hf n ((nat_degree_lt_iff_degree_lt hp).mpr hn),\n    fin.sum_univ_eq_sum_range (λ i, f i (p.coeff i))],\nend\n\nlemma as_sum_range' (p : R[X]) (n : ℕ) (w : p.nat_degree < n) :\n  p = ∑ i in range n, monomial i (coeff p i) :=\np.sum_monomial_eq.symm.trans $ p.sum_over_range' monomial_zero_right _ w\n\nlemma as_sum_range (p : R[X]) :\n  p = ∑ i in range (p.nat_degree + 1), monomial i (coeff p i) :=\np.sum_monomial_eq.symm.trans $ p.sum_over_range $ monomial_zero_right\n\nlemma as_sum_range_C_mul_X_pow (p : R[X]) :\n  p = ∑ i in range (p.nat_degree + 1), C (coeff p i) * X ^ i :=\np.as_sum_range.trans $ by simp only [C_mul_X_pow_eq_monomial]\n\nlemma coeff_ne_zero_of_eq_degree (hn : degree p = n) :\n  coeff p n ≠ 0 :=\nλ h, mem_support_iff.mp (mem_of_max hn) h\n\nlemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) :\n  p = C (p.coeff 1) * X + C (p.coeff 0) :=\next (λ n, nat.cases_on n (by simp)\n  (λ n, nat.cases_on n (by simp [coeff_C])\n    (λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial,\n      by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X,\n        nat.succ_inj', @eq_comm ℕ 0])))\n\nlemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) :\n  p = C (p.leading_coeff) * X + C (p.coeff 0) :=\n(eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_rfl)).trans\n  (by simp only [leading_coeff, nat_degree_eq_of_degree_eq_some h])\n\nlemma eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :\n  p = C (p.coeff 1) * X + C (p.coeff 0) :=\neq_X_add_C_of_degree_le_one $ degree_le_of_nat_degree_le h\n\nlemma monic.eq_X_add_C (hm : p.monic) (hnd : p.nat_degree = 1) : p = X + C (p.coeff 0) :=\nby rw [←one_mul X, ←C_1, ←hm.coeff_nat_degree, hnd, ←eq_X_add_C_of_nat_degree_le_one hnd.le]\n\nlemma exists_eq_X_add_C_of_nat_degree_le_one (h : nat_degree p ≤ 1) :\n  ∃ a b, p = C a * X + C b :=\n⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_nat_degree_le_one h⟩\n\ntheorem degree_X_pow_le (n : ℕ) : degree (X^n : R[X]) ≤ n :=\nby simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1:R)\n\ntheorem degree_X_le : degree (X : R[X]) ≤ 1 :=\ndegree_monomial_le _ _\n\nlemma nat_degree_X_le : (X : R[X]).nat_degree ≤ 1 :=\nnat_degree_le_of_degree_le degree_X_le\n\nlemma mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ (C c * X ^ n).support) : a = n :=\nmem_singleton.1 $ support_C_mul_X_pow' n c h\n\nlemma card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : (C c * X ^ n).support.card ≤ 1 :=\nbegin\n  rw ← card_singleton n,\n  apply card_le_of_subset (support_C_mul_X_pow' n c),\nend\n\nlemma card_supp_le_succ_nat_degree (p : R[X]) : p.support.card ≤ p.nat_degree + 1 :=\nbegin\n  rw ← finset.card_range (p.nat_degree + 1),\n  exact finset.card_le_of_subset supp_subset_range_nat_degree_succ,\nend\n\nlemma le_degree_of_mem_supp (a : ℕ) :\n  a ∈ p.support → ↑a ≤ degree p :=\nle_degree_of_ne_zero ∘ mem_support_iff.mp\n\nlemma nonempty_support_iff : p.support.nonempty ↔ p ≠ 0 :=\nby rw [ne.def, nonempty_iff_ne_empty, ne.def, ← support_eq_empty]\n\nend semiring\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma degree_one : degree (1 : R[X]) = (0 : with_bot ℕ) :=\ndegree_C (show (1 : R) ≠ 0, from zero_ne_one.symm)\n\n@[simp] lemma degree_X : degree (X : R[X]) = 1 :=\ndegree_monomial _ one_ne_zero\n\n@[simp] lemma nat_degree_X : (X : R[X]).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some degree_X\n\nend nonzero_semiring\n\nsection ring\nvariables [ring R]\n\nlemma coeff_mul_X_sub_C {p : R[X]} {r : R} {a : ℕ} :\n  coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r :=\nby simp [mul_sub]\n\n@[simp] lemma degree_neg (p : R[X]) : degree (-p) = degree p :=\nby unfold degree; rw support_neg\n\n@[simp] lemma nat_degree_neg (p : R[X]) : nat_degree (-p) = nat_degree p :=\nby simp [nat_degree]\n\n@[simp] lemma nat_degree_int_cast (n : ℤ) : nat_degree (n : R[X]) = 0 :=\nby rw [←C_eq_int_cast, nat_degree_C]\n\n@[simp] lemma leading_coeff_neg (p : R[X]) : (-p).leading_coeff = -p.leading_coeff :=\nby rw [leading_coeff, leading_coeff, nat_degree_neg, coeff_neg]\n\nend ring\n\nsection semiring\nvariables [semiring R]\n\n/-- The second-highest coefficient, or 0 for constants -/\ndef next_coeff (p : R[X]) : R :=\nif p.nat_degree = 0 then 0 else p.coeff (p.nat_degree - 1)\n\n@[simp]\nlemma next_coeff_C_eq_zero (c : R) :\n  next_coeff (C c) = 0 := by { rw next_coeff, simp }\n\nlemma next_coeff_of_pos_nat_degree (p : R[X]) (hp : 0 < p.nat_degree) :\n  next_coeff p = p.coeff (p.nat_degree - 1) :=\nby { rw [next_coeff, if_neg], contrapose! hp, simpa }\n\nvariables {p q : R[X]} {ι : Type*}\n\nlemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) :\n  coeff p (nat_degree q) = 0 :=\ncoeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)\n\nlemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=\nmt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))\n\nlemma ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 :=\npolynomial.ne_zero_of_degree_gt (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr\n  (by rwa [ne.def, polynomial.degree_eq_bot])) hpq : q.degree > ⊥)\n\nlemma ne_zero_of_nat_degree_gt {n : ℕ} (h : n < nat_degree p) : p ≠ 0 :=\nλ H, by simpa [H, nat.not_lt_zero] using h\n\nlemma degree_lt_degree (h : nat_degree p < nat_degree q) : degree p < degree q :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp],\n    rw bot_lt_iff_ne_bot,\n    intro hq,\n    simpa [hp, degree_eq_bot.mp hq, lt_irrefl] using h },\n  { rw [degree_eq_nat_degree hp, degree_eq_nat_degree $ ne_zero_of_nat_degree_gt h],\n    exact_mod_cast h }\nend\n\nlemma nat_degree_lt_nat_degree_iff (hp : p ≠ 0) :\n  nat_degree p < nat_degree q ↔ degree p < degree q :=\n⟨degree_lt_degree, begin\n  intro h,\n  have hq : q ≠ 0 := ne_zero_of_degree_gt h,\n  rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq] at h,\n  exact_mod_cast h\nend⟩\n\nlemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) :=\nbegin\n  ext (_|n), { simp },\n  rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt],\n  exact h.trans_lt (with_bot.some_lt_some.2 n.succ_pos),\nend\n\nlemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=\neq_C_of_degree_le_zero (h ▸ le_rfl)\n\nlemma degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) :=\n⟨eq_C_of_degree_le_zero, λ h, h.symm ▸ degree_C_le⟩\n\nlemma degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) :=\ncalc degree (p + q) = ((p + q).support).sup some : rfl\n  ... ≤ (p.support ∪ q.support).sup some : sup_mono support_add\n  ... = p.support.sup some ⊔ q.support.sup some : sup_union\n\nlemma degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n)\n  (hq : degree q ≤ n) : degree (p + q) ≤ n :=\n(degree_add_le p q).trans $ max_le hp hq\n\nlemma nat_degree_add_le (p q : R[X]) :\n  nat_degree (p + q) ≤ max (nat_degree p) (nat_degree q) :=\nbegin\n  cases le_max_iff.1 (degree_add_le p q);\n  simp [nat_degree_le_nat_degree h]\nend\n\nlemma nat_degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : nat_degree p ≤ n)\n  (hq : nat_degree q ≤ n) : nat_degree (p + q) ≤ n :=\n(nat_degree_add_le p q).trans $ max_le hp hq\n\n@[simp] lemma leading_coeff_zero : leading_coeff (0 : R[X]) = 0 := rfl\n\n@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=\n⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1\n  (not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),\nλ h, h.symm ▸ leading_coeff_zero⟩\n\nlemma leading_coeff_ne_zero : leading_coeff p ≠ 0 ↔ p ≠ 0 :=\nby rw [ne.def, leading_coeff_eq_zero]\n\nlemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ :=\nby rw [leading_coeff_eq_zero, degree_eq_bot]\n\nlemma nat_degree_mem_support_of_nonzero (H : p ≠ 0) : p.nat_degree ∈ p.support :=\nby { rw mem_support_iff, exact (not_congr leading_coeff_eq_zero).mpr H }\n\nlemma nat_degree_eq_support_max' (h : p ≠ 0) :\n  p.nat_degree = p.support.max' (nonempty_support_iff.mpr h) :=\n(le_max' _ _ $ nat_degree_mem_support_of_nonzero h).antisymm $\n  max'_le _ _ _ le_nat_degree_of_mem_supp\n\nlemma nat_degree_C_mul_X_pow_le (a : R) (n : ℕ) : nat_degree (C a * X ^ n) ≤ n :=\nnat_degree_le_iff_degree_le.2 $ degree_C_mul_X_pow_le _ _\n\nlemma degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p :=\nle_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $\n  begin\n    rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, add_zero],\n    exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)\n  end\n\nlemma degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=\nby rw [add_comm, degree_add_eq_left_of_degree_lt h]\n\nlemma nat_degree_add_eq_left_of_nat_degree_lt (h : nat_degree q < nat_degree p) :\n  nat_degree (p + q) = nat_degree p :=\nnat_degree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt (degree_lt_degree h))\n\nlemma nat_degree_add_eq_right_of_nat_degree_lt (h : nat_degree p < nat_degree q) :\n  nat_degree (p + q) = nat_degree q :=\nnat_degree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt (degree_lt_degree h))\n\nlemma degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=\nadd_comm (C a) p ▸ degree_add_eq_right_of_degree_lt $ lt_of_le_of_lt degree_C_le hp\n\nlemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :\n  degree (p + q) = max p.degree q.degree :=\nle_antisymm (degree_add_le _ _) $\n  match lt_trichotomy (degree p) (degree q) with\n  | or.inl hlt :=\n    by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_rfl\n  | or.inr (or.inl heq) :=\n    le_of_not_gt $\n      assume hlt : max (degree p) (degree q) > degree (p + q),\n      h $ show leading_coeff p + leading_coeff q = 0,\n      begin\n        rw [heq, max_self] at hlt,\n        rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add],\n        exact coeff_nat_degree_eq_zero_of_degree_lt hlt\n      end\n  | or.inr (or.inr hlt) :=\n    by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_rfl\n  end\n\nlemma degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p :=\nby { rcases p, simp only [erase, degree, coeff, support], convert sup_mono (erase_subset _ _) }\n\nlemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=\nbegin\n  apply lt_of_le_of_ne (degree_erase_le _ _),\n  rw [degree_eq_nat_degree hp, degree, support_erase],\n  exact λ h, not_mem_erase _ _ (mem_of_max h),\nend\n\nlemma degree_update_le (p : R[X]) (n : ℕ) (a : R) :\n  degree (p.update n a) ≤ max (degree p) n :=\nbegin\n  rw [degree, support_update],\n  split_ifs,\n  { exact (finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) },\n  { rw [max_insert, max_comm],\n    exact le_rfl },\nend\n\nlemma degree_sum_le (s : finset ι) (f : ι → R[X]) :\n  degree (∑ i in s, f i) ≤ s.sup (λ b, degree (f b)) :=\nfinset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $\n  assume a s has ih,\n  calc degree (∑ i in insert a s, f i) ≤ max (degree (f a)) (degree (∑ i in s, f i)) :\n    by rw sum_insert has; exact degree_add_le _ _\n  ... ≤ _ : by rw [sup_insert, sup_eq_max]; exact max_le_max le_rfl ih\n\nlemma degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q :=\ncalc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) :\n    begin\n      simp only [← C_mul_X_pow_eq_monomial.symm],\n      convert degree_sum_le _ _,\n      exact mul_eq_sum_sum\n    end\n  ... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) :\n    finset.sup_mono_fun (assume i hi,  degree_sum_le _ _)\n  ... ≤ degree p + degree q :\n    begin\n      refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_C_mul_X_pow_le _ _) _)),\n      rw [with_bot.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    end\n\nlemma degree_pow_le (p : R[X]) : ∀ (n : ℕ), degree (p ^ n) ≤ n • (degree p)\n| 0     := by rw [pow_zero, zero_nsmul]; exact degree_one_le\n| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :\n    by rw pow_succ; exact degree_mul_le _ _\n  ... ≤ _ : by rw succ_nsmul; exact add_le_add le_rfl (degree_pow_le _)\n\n@[simp] lemma leading_coeff_monomial (a : R) (n : ℕ) : leading_coeff (monomial n a) = a :=\nbegin\n  by_cases ha : a = 0,\n  { simp only [ha, (monomial n).map_zero, leading_coeff_zero] },\n  { rw [leading_coeff, nat_degree_monomial, if_neg ha, coeff_monomial], simp }\nend\n\nlemma leading_coeff_C_mul_X_pow (a : R) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=\nby rw [C_mul_X_pow_eq_monomial, leading_coeff_monomial]\n\nlemma leading_coeff_C_mul_X (a : R) : leading_coeff (C a * X) = a :=\nby simpa only [pow_one] using leading_coeff_C_mul_X_pow a 1\n\n@[simp] \n\n@[simp] lemma leading_coeff_X_pow (n : ℕ) : leading_coeff ((X : R[X]) ^ n) = 1 :=\nby simpa only [C_1, one_mul] using leading_coeff_C_mul_X_pow (1 : R) n\n\n@[simp] lemma leading_coeff_X : leading_coeff (X : R[X]) = 1 :=\nby simpa only [pow_one] using @leading_coeff_X_pow R _ 1\n\n@[simp] lemma monic_X_pow (n : ℕ) : monic (X ^ n : R[X]) := leading_coeff_X_pow n\n\n@[simp] lemma monic_X : monic (X : R[X]) := leading_coeff_X\n\n@[simp] lemma leading_coeff_one : leading_coeff (1 : R[X]) = 1 :=\nleading_coeff_C 1\n\n@[simp] lemma monic_one : monic (1 : R[X]) := leading_coeff_C _\n\nlemma monic.ne_zero {R : Type*} [semiring R] [nontrivial R] {p : R[X]} (hp : p.monic) :\n  p ≠ 0 :=\nby { rintro rfl, simpa [monic] using hp }\n\nlemma monic.ne_zero_of_ne (h : (0:R) ≠ 1) {p : R[X]} (hp : p.monic) :\n  p ≠ 0 :=\nby { nontriviality R, exact hp.ne_zero }\n\nlemma monic_of_nat_degree_le_of_coeff_eq_one (n : ℕ) (pn : p.nat_degree ≤ n) (p1 : p.coeff n = 1) :\n  monic p :=\nbegin\n  nontriviality,\n  refine (congr_arg _ $ nat_degree_eq_of_le_of_coeff_ne_zero pn _).trans p1,\n  exact ne_of_eq_of_ne p1 one_ne_zero,\nend\n\nlemma monic_of_degree_le_of_coeff_eq_one (n : ℕ) (pn : p.degree ≤ n) (p1 : p.coeff n = 1) :\n  monic p :=\nmonic_of_nat_degree_le_of_coeff_eq_one n (nat_degree_le_of_degree_le pn) p1\n\nlemma monic.ne_zero_of_polynomial_ne {r} (hp : monic p) (hne : q ≠ r) : p ≠ 0 :=\nby { haveI := nontrivial.of_polynomial_ne hne, exact hp.ne_zero }\n\nlemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :\n  leading_coeff (p + q) = leading_coeff q :=\nhave coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h,\nby simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h),\n  this, coeff_add, zero_add]\n\nlemma leading_coeff_add_of_degree_eq (h : degree p = degree q)\n  (hlc : leading_coeff p + leading_coeff q ≠ 0) :\n  leading_coeff (p + q) = leading_coeff p + leading_coeff q :=\nhave nat_degree (p + q) = nat_degree p,\n  by apply nat_degree_eq_of_degree_eq;\n    rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],\nby simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add]\n\n@[simp] lemma coeff_mul_degree_add_degree (p q : R[X]) :\n  coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=\ncalc coeff (p * q) (nat_degree p + nat_degree q) =\n    ∑ x in nat.antidiagonal (nat_degree p + nat_degree q),\n    coeff p x.1 * coeff q x.2 : coeff_mul _ _ _\n... = coeff p (nat_degree p) * coeff q (nat_degree q) :\n  begin\n    refine finset.sum_eq_single (nat_degree p, nat_degree q) _ _,\n    { rintro ⟨i,j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁,\n      by_cases H : nat_degree p < i,\n      { rw [coeff_eq_zero_of_degree_lt\n          (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 H)), zero_mul] },\n      { rw not_lt_iff_eq_or_lt at H, cases H,\n        { subst H, rw add_left_cancel_iff at h₁, dsimp at h₁, subst h₁, exfalso, exact h₂ rfl },\n        { suffices : nat_degree q < j,\n          { rw [coeff_eq_zero_of_degree_lt\n              (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 this)), mul_zero] },\n          { by_contra H', rw not_lt at H',\n            exact ne_of_lt (nat.lt_of_lt_of_le\n              (nat.add_lt_add_right H j) (nat.add_le_add_left H' _)) h₁ } } } },\n    { intro H, exfalso, apply H, rw nat.mem_antidiagonal }\n  end\n\nlemma degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  degree (p * q) = degree p + degree q :=\nhave hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul],\nhave hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero],\nle_antisymm (degree_mul_le _ _)\nbegin\n  rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],\n  refine le_degree_of_ne_zero _,\n  rwa coeff_mul_degree_add_degree\nend\n\nlemma monic.degree_mul (hq : monic q) : degree (p * q) = degree p + degree q :=\nif hp : p = 0 then by simp [hp]\nelse degree_mul' $ by rwa [hq.leading_coeff, mul_one, ne.def, leading_coeff_eq_zero]\n\nlemma nat_degree_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  nat_degree (p * q) = nat_degree p + nat_degree q :=\nhave hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]),\nhave hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]),\nnat_degree_eq_of_degree_eq_some $\n  by rw [degree_mul' h, with_bot.coe_add, degree_eq_nat_degree hp, degree_eq_nat_degree hq]\n\nlemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  leading_coeff (p * q) = leading_coeff p * leading_coeff q :=\nbegin\n  unfold leading_coeff,\n  rw [nat_degree_mul' h, coeff_mul_degree_add_degree],\n  refl\nend\n\nlemma monomial_nat_degree_leading_coeff_eq_self (h : p.support.card ≤ 1) :\n  monomial p.nat_degree p.leading_coeff = p :=\nbegin\n  rcases card_support_le_one_iff_monomial.1 h with ⟨n, a, rfl⟩,\n  by_cases ha : a = 0;\n  simp [ha]\nend\n\nlemma C_mul_X_pow_eq_self (h : p.support.card ≤ 1) :\n  C p.leading_coeff * X^p.nat_degree = p :=\nby rw [C_mul_X_pow_eq_monomial, monomial_nat_degree_leading_coeff_eq_self h]\n\nlemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →\n  leading_coeff (p ^ n) = leading_coeff p ^ n :=\nnat.rec_on n (by simp) $\nλ n ih h,\nhave h₁ : leading_coeff p ^ n ≠ 0 :=\n  λ h₁, h $ by rw [pow_succ, h₁, mul_zero],\nhave h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=\n  by rwa [pow_succ, ← ih h₁] at h,\nby rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]\n\nlemma degree_pow' : ∀ {n : ℕ}, leading_coeff p ^ n ≠ 0 →\n  degree (p ^ n) = n • (degree p)\n| 0     := λ h, by rw [pow_zero, ← C_1] at *;\n  rw [degree_C h, zero_nsmul]\n| (n+1) := λ h,\nhave h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $\n  by rw [pow_succ, h₁, mul_zero],\nhave h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=\n  by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,\nby rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁]\n\nlemma nat_degree_pow' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) :\n  nat_degree (p ^ n) = n * nat_degree p :=\nif hp0 : p = 0 then\n  if hn0 : n = 0 then by simp *\n  else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp\nelse\nhave hpn : p ^ n ≠ 0, from λ hpn0,  have h1 : _ := h,\n  by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h;\n  exact h rfl,\noption.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ),\n  by rw [← degree_eq_nat_degree hpn, degree_pow' h, degree_eq_nat_degree hp0,\n    ← with_bot.coe_nsmul]; simp\n\ntheorem leading_coeff_monic_mul {p q : R[X]} (hp : monic p) :\n  leading_coeff (p * q) = leading_coeff q :=\nbegin\n  rcases eq_or_ne q 0 with rfl|H,\n  { simp },\n  { rw [leading_coeff_mul', hp.leading_coeff, one_mul],\n    rwa [hp.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero] }\nend\n\ntheorem leading_coeff_mul_monic {p q : R[X]} (hq : monic q) :\n  leading_coeff (p * q) = leading_coeff p :=\ndecidable.by_cases\n  (λ H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero])\n  (λ H : leading_coeff p ≠ 0,\n    by rw [leading_coeff_mul', hq.leading_coeff, mul_one];\n      rwa [hq.leading_coeff, mul_one])\n\n@[simp] theorem leading_coeff_mul_X_pow {p : R[X]} {n : ℕ} :\n  leading_coeff (p * X ^ n) = leading_coeff p :=\nleading_coeff_mul_monic (monic_X_pow n)\n\n@[simp] theorem leading_coeff_mul_X {p : R[X]} :\n  leading_coeff (p * X) = leading_coeff p :=\nleading_coeff_mul_monic monic_X\n\nlemma nat_degree_mul_le {p q : R[X]} : nat_degree (p * q) ≤ nat_degree p + nat_degree q :=\nbegin\n  apply nat_degree_le_of_degree_le,\n  apply le_trans (degree_mul_le p q),\n  rw with_bot.coe_add,\n  refine add_le_add _ _; apply degree_le_nat_degree,\nend\n\nlemma nat_degree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).nat_degree ≤ n * p.nat_degree :=\nbegin\n  induction n with i hi,\n  { simp },\n  { rw [pow_succ, nat.succ_mul, add_comm],\n    apply le_trans nat_degree_mul_le,\n    exact add_le_add_left hi _ }\nend\n\n@[simp] lemma coeff_pow_mul_nat_degree (p : R[X]) (n : ℕ) :\n  (p ^ n).coeff (n * p.nat_degree) = p.leading_coeff ^ n :=\nbegin\n  induction n with i hi,\n  { simp },\n  { rw [pow_succ', pow_succ', nat.succ_mul],\n    by_cases hp1 : p.leading_coeff ^ i = 0,\n    { rw [hp1, zero_mul],\n      by_cases hp2 : p ^ i = 0,\n      { rw [hp2, zero_mul, coeff_zero] },\n      { apply coeff_eq_zero_of_nat_degree_lt,\n        have h1 : (p ^ i).nat_degree < i * p.nat_degree,\n        { apply lt_of_le_of_ne nat_degree_pow_le (λ h, hp2 _),\n          rw [←h, hp1] at hi,\n          exact leading_coeff_eq_zero.mp hi },\n        calc (p ^ i * p).nat_degree ≤ (p ^ i).nat_degree + p.nat_degree : nat_degree_mul_le\n                                ... < i * p.nat_degree + p.nat_degree : add_lt_add_right h1 _ } },\n    { rw [←nat_degree_pow' hp1, ←leading_coeff_pow' hp1],\n      exact coeff_mul_degree_add_degree _ _ } }\nend\n\nlemma zero_le_degree_iff : 0 ≤ degree p ↔ p ≠ 0 :=\nby rw [← not_lt, nat.with_bot.lt_zero_iff, degree_eq_bot]\n\nlemma nat_degree_eq_zero_iff_degree_le_zero : p.nat_degree = 0 ↔ p.degree ≤ 0 :=\nby rw [← nonpos_iff_eq_zero, nat_degree_le_iff_degree_le, with_bot.coe_zero]\n\ntheorem degree_le_iff_coeff_zero (f : R[X]) (n : with_bot ℕ) :\n  degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 :=\nby simp only [degree, finset.max, finset.sup_le_iff, mem_support_iff, ne.def, ← not_le,\n    not_imp_comm]\n\ntheorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :\n  degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 :=\nbegin\n  refine ⟨λ hf m hm, coeff_eq_zero_of_degree_lt (lt_of_lt_of_le hf (with_bot.coe_le_coe.2 hm)), _⟩,\n  simp only [degree, finset.sup_lt_iff (with_bot.bot_lt_coe n), mem_support_iff,\n    with_bot.some_eq_coe, with_bot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe],\n  exact λ h m, mt (h m),\nend\n\nlemma degree_smul_le (a : R) (p : R[X]) : degree (a • p) ≤ degree p :=\nbegin\n  apply (degree_le_iff_coeff_zero _ _).2 (λ m hm, _),\n  rw degree_lt_iff_coeff_zero at hm,\n  simp [hm m le_rfl],\nend\n\nlemma nat_degree_smul_le (a : R) (p : R[X]) : nat_degree (a • p) ≤ nat_degree p :=\nnat_degree_le_nat_degree (degree_smul_le a p)\n\nlemma degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree :=\nby haveI := nontrivial.of_polynomial_ne hp; exact\nhave leading_coeff p * leading_coeff X ≠ 0, by simpa,\nby erw [degree_mul' this, degree_eq_nat_degree hp,\n    degree_X, ← with_bot.coe_one, ← with_bot.coe_add, with_bot.coe_lt_coe];\n  exact nat.lt_succ_self _\n\nlemma nat_degree_pos_iff_degree_pos :\n  0 < nat_degree p ↔ 0 < degree p :=\nlt_iff_lt_of_le_iff_le nat_degree_le_iff_degree_le\n\nlemma eq_C_of_nat_degree_le_zero (h : nat_degree p ≤ 0) : p = C (coeff p 0) :=\neq_C_of_degree_le_zero $ degree_le_of_nat_degree_le h\n\nlemma eq_C_of_nat_degree_eq_zero (h : nat_degree p = 0) : p = C (coeff p 0) :=\neq_C_of_nat_degree_le_zero h.le\n\nlemma ne_zero_of_coe_le_degree (hdeg : ↑n ≤ p.degree) : p ≠ 0 :=\nzero_le_degree_iff.mp $ (with_bot.coe_le_coe.mpr n.zero_le).trans hdeg\n\nlemma le_nat_degree_of_coe_le_degree (hdeg : ↑n ≤ p.degree) :\n  n ≤ p.nat_degree :=\nwith_bot.coe_le_coe.mp ((degree_eq_nat_degree $ ne_zero_of_coe_le_degree hdeg) ▸ hdeg)\n\nlemma degree_sum_fin_lt {n : ℕ} (f : fin n → R) :\n  degree (∑ i : fin n, C (f i) * X ^ (i : ℕ)) < n :=\n(degree_sum_le _ _).trans_lt $ (finset.sup_lt_iff $ with_bot.bot_lt_coe n).2 $\n  λ k hk, (degree_C_mul_X_pow_le _ _).trans_lt $ with_bot.coe_lt_coe.2 k.is_lt\n\nlemma degree_linear_le : degree (C a * X + C b) ≤ 1 :=\ndegree_add_le_of_degree_le (degree_C_mul_X_le _) $ le_trans degree_C_le nat.with_bot.coe_nonneg\n\nlemma degree_linear_lt : degree (C a * X + C b) < 2 :=\ndegree_linear_le.trans_lt $ with_bot.coe_lt_coe.mpr one_lt_two\n\nlemma degree_C_lt_degree_C_mul_X (ha : a ≠ 0) : degree (C b) < degree (C a * X) :=\nby simpa only [degree_C_mul_X ha] using degree_C_lt\n\n@[simp] lemma degree_linear (ha : a ≠ 0) : degree (C a * X + C b) = 1 :=\nby rw [degree_add_eq_left_of_degree_lt $ degree_C_lt_degree_C_mul_X ha, degree_C_mul_X ha]\n\nlemma nat_degree_linear_le : nat_degree (C a * X + C b) ≤ 1 :=\nnat_degree_le_of_degree_le degree_linear_le\n\n@[simp] lemma nat_degree_linear (ha : a ≠ 0) : nat_degree (C a * X + C b) = 1 :=\nnat_degree_eq_of_degree_eq_some $ degree_linear ha\n\n@[simp] lemma leading_coeff_linear (ha : a ≠ 0): leading_coeff (C a * X + C b) = a :=\nby rw [add_comm, leading_coeff_add_of_degree_lt (degree_C_lt_degree_C_mul_X ha),\n       leading_coeff_C_mul_X]\n\nlemma degree_quadratic_le : degree (C a * X ^ 2 + C b * X + C c) ≤ 2 :=\nby simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 2 a)\n  (le_trans degree_linear_le $ with_bot.coe_le_coe.mpr one_le_two)\n\nlemma degree_quadratic_lt : degree (C a * X ^ 2 + C b * X + C c) < 3 :=\ndegree_quadratic_le.trans_lt $ with_bot.coe_lt_coe.mpr $ lt_add_one 2\n\nlemma degree_linear_lt_degree_C_mul_X_sq (ha : a ≠ 0) :\n  degree (C b * X + C c) < degree (C a * X ^ 2) :=\nby simpa only [degree_C_mul_X_pow 2 ha] using degree_linear_lt\n\n@[simp] lemma degree_quadratic (ha : a ≠ 0) : degree (C a * X ^ 2 + C b * X + C c) = 2 :=\nbegin\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  refl\nend\n\nlemma nat_degree_quadratic_le : nat_degree (C a * X ^ 2 + C b * X + C c) ≤ 2 :=\nnat_degree_le_of_degree_le degree_quadratic_le\n\n@[simp] lemma nat_degree_quadratic (ha : a ≠ 0) : nat_degree (C a * X ^ 2 + C b * X + C c) = 2 :=\nnat_degree_eq_of_degree_eq_some $ degree_quadratic ha\n\n@[simp] lemma leading_coeff_quadratic (ha : a ≠ 0) :\n  leading_coeff (C a * X ^ 2 + C b * X + C c) = a :=\nby rw [add_assoc, add_comm, leading_coeff_add_of_degree_lt $\n         degree_linear_lt_degree_C_mul_X_sq ha, leading_coeff_C_mul_X_pow]\n\nlemma degree_cubic_le : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 :=\nby simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 3 a)\n  (le_trans degree_quadratic_le $ with_bot.coe_le_coe.mpr $ nat.le_succ 2)\n\nlemma degree_cubic_lt : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) < 4 :=\ndegree_cubic_le.trans_lt $ with_bot.coe_lt_coe.mpr $ lt_add_one 3\n\nlemma degree_quadratic_lt_degree_C_mul_X_cb (ha : a ≠ 0) :\n  degree (C b * X ^ 2 + C c * X + C d) < degree (C a * X ^ 3) :=\nby simpa only [degree_C_mul_X_pow 3 ha] using degree_quadratic_lt\n\n@[simp] lemma degree_cubic (ha : a ≠ 0) : degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 :=\nbegin\n  rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), degree_add_eq_left_of_degree_lt $\n        degree_quadratic_lt_degree_C_mul_X_cb ha, degree_C_mul_X_pow 3 ha],\n  refl\nend\n\nlemma nat_degree_cubic_le : nat_degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) ≤ 3 :=\nnat_degree_le_of_degree_le degree_cubic_le\n\n@[simp] lemma nat_degree_cubic (ha : a ≠ 0) :\n  nat_degree (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = 3 :=\nnat_degree_eq_of_degree_eq_some $ degree_cubic ha\n\n@[simp] lemma leading_coeff_cubic (ha : a ≠ 0):\n  leading_coeff (C a * X ^ 3 + C b * X ^ 2 + C c * X + C d) = a :=\nby rw [add_assoc, add_assoc, ← add_assoc (C b * X ^ 2), add_comm, leading_coeff_add_of_degree_lt $\n         degree_quadratic_lt_degree_C_mul_X_cb ha, leading_coeff_C_mul_X_pow]\n\nend semiring\n\nsection nontrivial_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma degree_X_pow (n : ℕ) : degree ((X : R[X]) ^ n) = n :=\nby rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]\n\n@[simp] lemma nat_degree_X_pow (n : ℕ) : nat_degree ((X : R[X]) ^ n) = n :=\nnat_degree_eq_of_degree_eq_some (degree_X_pow n)\n\n/-  This lemma explicitly does not require the `nontrivial R` assumption. -/\nlemma nat_degree_X_pow_le {R : Type*} [semiring R] (n : ℕ) :\n  (X ^ n : R[X]).nat_degree ≤ n :=\nbegin\n  nontriviality R,\n  rwa polynomial.nat_degree_X_pow,\nend\n\ntheorem not_is_unit_X : ¬ is_unit (X : R[X]) :=\nλ ⟨⟨_, g, hfg, hgf⟩, rfl⟩, zero_ne_one' R $\nby { change g * monomial 1 1 = 1 at hgf, rw [← coeff_one_zero, ← hgf], simp }\n\n@[simp] lemma degree_mul_X : degree (p * X) = degree p + 1 := by simp [monic_X.degree_mul]\n\n@[simp] lemma degree_mul_X_pow : degree (p * X ^ n) = degree p + n :=\nby simp [(monic_X_pow n).degree_mul]\n\nend nontrivial_semiring\n\nsection ring\nvariables [ring R] {p q : R[X]}\n\nlemma degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) :=\nby simpa only [degree_neg q] using degree_add_le p (-q)\n\nlemma nat_degree_sub_le (p q : R[X]) : nat_degree (p - q) ≤ max (nat_degree p) (nat_degree q) :=\nby simpa only [← nat_degree_neg q] using nat_degree_add_le p (-q)\n\nlemma degree_sub_lt (hd : degree p = degree q)\n  (hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :\n  degree (p - q) < degree p :=\nhave hp : monomial (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=\n  monomial_add_erase _ _,\nhave hq : monomial (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=\n  monomial_add_erase _ _,\nhave hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,\nhave hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),\ncalc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :\n  by conv { to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg] }\n... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))\n  : degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _\n... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩\n\nlemma degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 :=\n(degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))\n\nlemma nat_degree_X_sub_C_le (r : R) : (X - C r).nat_degree ≤ 1 :=\nnat_degree_le_iff_degree_le.2 $ degree_X_sub_C_le r\n\nlemma degree_sub_eq_left_of_degree_lt (h : degree q < degree p) : degree (p - q) = degree p :=\nby { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_left_of_degree_lt h] }\n\nlemma degree_sub_eq_right_of_degree_lt (h : degree p < degree q) : degree (p - q) = degree q :=\nby { rw ← degree_neg q at h, rw [sub_eq_add_neg, degree_add_eq_right_of_degree_lt h, degree_neg] }\n\nlemma nat_degree_sub_eq_left_of_nat_degree_lt (h : nat_degree q < nat_degree p) :\n  nat_degree (p - q) = nat_degree p :=\nnat_degree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt (degree_lt_degree h))\n\nlemma nat_degree_sub_eq_right_of_nat_degree_lt (h : nat_degree p < nat_degree q) :\n  nat_degree (p - q) = nat_degree q :=\nnat_degree_eq_of_degree_eq (degree_sub_eq_right_of_degree_lt (degree_lt_degree h))\n\nend ring\n\nsection nonzero_ring\nvariables [nontrivial R]\n\nsection semiring\nvariable [semiring R]\n\n@[simp] lemma degree_X_add_C (a : R) : degree (X + C a) = 1 :=\nhave degree (C a) < degree (X : R[X]),\nfrom calc degree (C a) ≤ 0 : degree_C_le\n                   ... < 1 : with_bot.some_lt_some.mpr zero_lt_one\n                   ... = degree X : degree_X.symm,\nby rw [degree_add_eq_left_of_degree_lt this, degree_X]\n\n@[simp] lemma nat_degree_X_add_C (x : R) : (X + C x).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some $ degree_X_add_C x\n\n@[simp]\nlemma next_coeff_X_add_C [semiring S] (c : S) : next_coeff (X + C c) = c :=\nbegin\n  nontriviality S,\n  simp [next_coeff_of_pos_nat_degree]\nend\n\nlemma degree_X_pow_add_C {n : ℕ} (hn : 0 < n) (a : R) :\n  degree ((X : R[X]) ^ n + C a) = n :=\nhave degree (C a) < degree ((X : R[X]) ^ n),\n  from degree_C_le.trans_lt $ by rwa [degree_X_pow, with_bot.coe_pos],\nby rw [degree_add_eq_left_of_degree_lt this, degree_X_pow]\n\nlemma X_pow_add_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :\n  (X : R[X]) ^ n + C a ≠ 0 :=\nmt degree_eq_bot.2 (show degree ((X : R[X]) ^ n + C a) ≠ ⊥,\n  by rw degree_X_pow_add_C hn a; exact dec_trivial)\n\ntheorem X_add_C_ne_zero (r : R) : X + C r ≠ 0 :=\npow_one (X : R[X]) ▸ X_pow_add_C_ne_zero zero_lt_one r\n\ntheorem zero_nmem_multiset_map_X_add_C {α : Type*} (m : multiset α) (f : α → R) :\n  (0 : R[X]) ∉ m.map (λ a, X + C (f a)) :=\nλ mem, let ⟨a, _, ha⟩ := multiset.mem_map.mp mem in X_add_C_ne_zero _ ha\n\nlemma nat_degree_X_pow_add_C {n : ℕ} {r : R} :\n  (X ^ n + C r).nat_degree = n :=\nbegin\n  by_cases hn : n = 0,\n  { rw [hn, pow_zero, ←C_1, ←ring_hom.map_add, nat_degree_C] },\n  { exact nat_degree_eq_of_degree_eq_some (degree_X_pow_add_C (pos_iff_ne_zero.mpr hn) r) },\nend\n\nlemma X_pow_add_C_ne_one {n : ℕ} (hn : 0 < n) (a : R) : (X : R[X]) ^ n + C a ≠ 1 :=\nλ h, hn.ne' $ by simpa only [nat_degree_X_pow_add_C, nat_degree_one] using congr_arg nat_degree h\n\ntheorem X_add_C_ne_one (r : R) : X + C r ≠ 1 :=\npow_one (X : R[X]) ▸ X_pow_add_C_ne_one zero_lt_one r\n\nend semiring\nend nonzero_ring\n\nsection semiring\nvariable [semiring R]\n\n@[simp] lemma leading_coeff_X_pow_add_C {n : ℕ} (hn : 0 < n) {r : R} :\n  (X ^ n + C r).leading_coeff = 1 :=\nbegin\n  nontriviality R,\n  rw [leading_coeff, nat_degree_X_pow_add_C, coeff_add, coeff_X_pow_self,\n    coeff_C, if_neg (pos_iff_ne_zero.mp hn), add_zero]\nend\n\n@[simp] lemma leading_coeff_X_add_C [semiring S] (r : S) :\n  (X + C r).leading_coeff = 1 :=\nby rw [←pow_one (X : S[X]), leading_coeff_X_pow_add_C zero_lt_one]\n\n@[simp] lemma leading_coeff_X_pow_add_one {n : ℕ} (hn : 0 < n) :\n  (X ^ n + 1 : R[X]).leading_coeff = 1 :=\nleading_coeff_X_pow_add_C hn\n\n@[simp] lemma leading_coeff_pow_X_add_C (r : R) (i : ℕ) :\n  leading_coeff ((X + C r) ^ i) = 1 :=\nby { nontriviality, rw leading_coeff_pow'; simp }\n\nend semiring\n\nsection ring\nvariable [ring R]\n\n@[simp] lemma leading_coeff_X_pow_sub_C {n : ℕ} (hn : 0 < n) {r : R} :\n  (X ^ n - C r).leading_coeff = 1 :=\nby rw [sub_eq_add_neg, ←map_neg C r, leading_coeff_X_pow_add_C hn]; apply_instance\n\n@[simp] lemma leading_coeff_X_pow_sub_one {n : ℕ} (hn : 0 < n) :\n  (X ^ n - 1 : R[X]).leading_coeff = 1 :=\nleading_coeff_X_pow_sub_C hn\n\nvariables [nontrivial R]\n\n@[simp] lemma degree_X_sub_C (a : R) : degree (X - C a) = 1 :=\nby rw [sub_eq_add_neg, ←map_neg C a, degree_X_add_C]\n\n@[simp] lemma nat_degree_X_sub_C (x : R) : (X - C x).nat_degree = 1 :=\nnat_degree_eq_of_degree_eq_some $ degree_X_sub_C x\n\n@[simp]\nlemma next_coeff_X_sub_C [ring S] (c : S) : next_coeff (X - C c) = - c :=\nby rw [sub_eq_add_neg, ←map_neg C c, next_coeff_X_add_C]\n\nlemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :\n  degree ((X : R[X]) ^ n - C a) = n :=\nby rw [sub_eq_add_neg, ←map_neg C a, degree_X_pow_add_C hn]; apply_instance\n\nlemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :\n  (X : R[X]) ^ n - C a ≠ 0 :=\nby { rw [sub_eq_add_neg, ←map_neg C a], exact X_pow_add_C_ne_zero hn _ }\n\ntheorem X_sub_C_ne_zero (r : R) : X - C r ≠ 0 :=\npow_one (X : R[X]) ▸ X_pow_sub_C_ne_zero zero_lt_one r\n\ntheorem zero_nmem_multiset_map_X_sub_C {α : Type*} (m : multiset α) (f : α → R) :\n  (0 : R[X]) ∉ m.map (λ a, X - C (f a)) :=\nλ mem, let ⟨a, _, ha⟩ := multiset.mem_map.mp mem in X_sub_C_ne_zero _ ha\n\nlemma nat_degree_X_pow_sub_C {n : ℕ} {r : R} :\n  (X ^ n - C r).nat_degree = n :=\nby rw [sub_eq_add_neg, ←map_neg C r, nat_degree_X_pow_add_C]\n\n@[simp] lemma leading_coeff_X_sub_C [ring S] (r : S) :\n  (X - C r).leading_coeff = 1 :=\nby rw [sub_eq_add_neg, ←map_neg C r, leading_coeff_X_add_C]\n\nend ring\n\nsection no_zero_divisors\nvariables [semiring R] [no_zero_divisors R] {p q : R[X]}\n\n@[simp] lemma degree_mul : degree (p * q) = degree p + degree q :=\nif hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add]\nelse if hq0 : q = 0 then  by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot]\nelse degree_mul' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)\n    (mt leading_coeff_eq_zero.1 hq0)\n\n/-- `degree` as a monoid homomorphism between `R[X]` and `multiplicative (with_bot ℕ)`.\n  This is useful to prove results about multiplication and degree. -/\ndef degree_monoid_hom [nontrivial R] : R[X] →* multiplicative (with_bot ℕ) :=\n{ to_fun := degree,\n  map_one' := degree_one,\n  map_mul' := λ _ _, degree_mul }\n\n@[simp] lemma degree_pow [nontrivial R] (p : R[X]) (n : ℕ) :\n  degree (p ^ n) = n • (degree p) :=\nmap_pow (@degree_monoid_hom R _ _ _) _ _\n\n@[simp] lemma leading_coeff_mul (p q : R[X]) : leading_coeff (p * q) =\n  leading_coeff p * leading_coeff q :=\nbegin\n  by_cases hp : p = 0,\n  { simp only [hp, zero_mul, leading_coeff_zero] },\n  { by_cases hq : q = 0,\n    { simp only [hq, mul_zero, leading_coeff_zero] },\n    { rw [leading_coeff_mul'],\n      exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }\nend\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[X] →* R :=\n{ to_fun := leading_coeff,\n  map_one' := by simp,\n  map_mul' := leading_coeff_mul }\n\n@[simp] lemma leading_coeff_hom_apply (p : R[X]) :\n  leading_coeff_hom p = leading_coeff p := rfl\n\n@[simp] lemma leading_coeff_pow (p : R[X]) (n : ℕ) :\n  leading_coeff (p ^ n) = leading_coeff p ^ n :=\n(leading_coeff_hom : R[X] →* R).map_pow p n\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/definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7629973111778218}}
{"text": "import tutorial_world.level16_exfalso --hide\nopen IncidencePlane --hide\n\n/- Tactic : by_cases\n\n## Summary\n\nGenerates two goals corresponding to a given statement being\ntrue or false\n\n## Details\n\nSuppose that we want to prove a statement `P x`, where `x`\nis some number. We may know how to prove it when `x ≤ 5`\nand also when `x > 5`, but using a different method.\nIn this situation, using `by_cases h : x ≤ 5,` will produce\ntwo new goals, the first one with `h : x ≤ 5` in the context\nand the second one with `h : ¬ x ≤ 5`.\n-/\n\n/-\n# Tutorial World \n\n## Level 17: the `by_cases` tactic.\n\nIn this level, we introduce the `by_cases` tactic. Mathematicians would use it to provide a **proof by cases**.\nThis is useful when we need to split a proof into different cases.\nFor example, if we are asked to solve a goal of the form `⊢ P ∨ ¬ P`, then `by_cases h : P` will split the goal into two cases, \nassuming `h : P` in the first branch, and `h : ¬ P` in the second branch. With that being said, let's try to solve this level!\n\n[**Tip:** You may want to write the `∈` symbol to solve this level. To do so, type **`\\in`** and then hit the space bar. Analogously, \nyou can write the `∉` symbol by typing **`\\notin`** and then hitting the space bar.]\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nStarting the proof by typing `by_cases h : A ∈ r` will split the goal into two cases, assuming `h : A ∈ r` in the first branch, \nand h : A ∉ r` in the second branch. Then, try to look for a tactic that changes the goal from `⊢ P ∨ Q` to either `⊢ P` or `⊢ Q`.\nStill bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution. \n-/\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\n\n/- Lemma : no-side-bar\nEither a point is in a line or it is not.\n-/\nlemma point_in_line_or_not {A : Ω}\t{r : Line Ω} : A ∈ r ∨ A ∉ r :=\nbegin\n\n  by_cases h : A ∈ r,\n  { \n    left,\n    exact h,\n  },\n  { \n    right,\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/level17_by_cases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7629729877860147}}
{"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 linear_algebra.matrix\nimport data.rel\nimport combinatorics.simple_graph.basic\n\n/-!\n# Adjacency Matrices\n\nThis module defines the adjacency matrix of a graph, and provides theorems connecting graph\nproperties to computational properties of the matrix.\n\n## Main definitions\n\n* `adj_matrix` is the adjacency matrix of a `simple_graph` with coefficients in a given semiring.\n\n-/\n\nopen_locale big_operators matrix\nopen finset matrix simple_graph\n\nuniverses u v\nvariables {α : Type u} [fintype α]\nvariables (R : Type v) [semiring R]\n\nnamespace simple_graph\n\nvariables (G : simple_graph α) (R) [decidable_rel G.adj]\n\n/-- `adj_matrix G R` is the matrix `A` such that `A i j = (1 : R)` if `i` and `j` are\n  adjacent in the simple graph `G`, and otherwise `A i j = 0`. -/\ndef adj_matrix : matrix α α R\n| i j := if (G.adj i j) then 1 else 0\n\nvariable {R}\n\n@[simp]\nlemma adj_matrix_apply (v w : α) : G.adj_matrix R v w = if (G.adj v w) then 1 else 0 := rfl\n\n@[simp]\ntheorem transpose_adj_matrix : (G.adj_matrix R)ᵀ = G.adj_matrix R :=\nby { ext, simp [edge_symm] }\n\n@[simp]\nlemma adj_matrix_dot_product (v : α) (vec : α → R) :\n  dot_product (G.adj_matrix R v) vec = ∑ u in G.neighbor_finset v, vec u :=\nby simp [neighbor_finset_eq_filter, dot_product, sum_filter]\n\n@[simp]\nlemma dot_product_adj_matrix (v : α) (vec : α → R) :\n  dot_product vec (G.adj_matrix R v) = ∑ u in G.neighbor_finset v, vec u :=\nby simp [neighbor_finset_eq_filter, dot_product, sum_filter, sum_apply]\n\n@[simp]\nlemma adj_matrix_mul_vec_apply (v : α) (vec : α → R) :\n  ((G.adj_matrix R).mul_vec vec) v = ∑ u in G.neighbor_finset v, vec u :=\nby rw [mul_vec, adj_matrix_dot_product]\n\n@[simp]\nlemma adj_matrix_vec_mul_apply (v : α) (vec : α → R) :\n  ((G.adj_matrix R).vec_mul vec) v = ∑ u in G.neighbor_finset v, vec u :=\nbegin\n  rw [← dot_product_adj_matrix, vec_mul],\n  refine congr rfl _, ext,\n  rw [← transpose_apply (adj_matrix R G) x v, transpose_adj_matrix],\nend\n\n@[simp]\nlemma adj_matrix_mul_apply (M : matrix α α R) (v w : α) :\n  (G.adj_matrix R ⬝ M) v w = ∑ u in G.neighbor_finset v, M u w :=\nby simp [mul_apply, neighbor_finset_eq_filter, sum_filter]\n\n@[simp]\n\n\nvariable (R)\ntheorem trace_adj_matrix : matrix.trace α R R (G.adj_matrix R) = 0 := by simp\nvariable {R}\n\ntheorem adj_matrix_mul_self_apply_self (i : α) :\n  ((G.adj_matrix R) ⬝ (G.adj_matrix R)) i i = degree G i :=\nby simp [degree]\n\nvariable {G}\n\n@[simp]\nlemma adj_matrix_mul_vec_const_apply {r : R} {v : α} :\n  (G.adj_matrix R).mul_vec (function.const _ r) v = G.degree v * r :=\nby simp [degree]\n\nlemma adj_matrix_mul_vec_const_apply_of_regular {d : ℕ} {r : R} (hd : G.is_regular_of_degree d)\n  {v : α} :\n  (G.adj_matrix R).mul_vec (function.const _ r) v = (d * r) :=\nby simp [hd v]\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/adj_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384593, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7629729803013252}}
{"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 analysis.special_functions.trigonometric.deriv\nimport analysis.special_functions.log.basic\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 definitions\n\n- `real.arsinh`: The inverse function of `real.sinh`.\n\n- `real.sinh_equiv`, `real.sinh_order_iso`, `real.sinh_homeomorph`: `real.sinh` as an `equiv`,\n  `order_iso`, and `homeomorph`, respectively.\n\n## Main Results\n\n- `real.sinh_surjective`, `real.sinh_bijective`: `real.sinh` is surjective and bijective;\n\n- `real.arsinh_injective`, `real.arsinh_surjective`, `real.arsinh_bijective`: `real.arsinh` is\n  injective, surjective, and bijective;\n\n- `real.continuous_arsinh`, `real.differentiable_arsinh`, `real.cont_diff_arsinh`: `real.arsinh` is\n  continuous, differentiable, and continuously differentiable; we also provide dot notation\n  convenience lemmas like `filter.tendsto.arsinh` and `cont_diff_at.arsinh`.\n\n## Tags\n\narsinh, arcsinh, argsinh, asinh, sinh injective, sinh bijective, sinh surjective\n-/\nnoncomputable theory\n\nopen function filter set\nopen_locale topological_space\n\nnamespace real\n\nvariables {x y : ℝ}\n\n/-- `arsinh` is defined using a logarithm, `arsinh x = log (x + sqrt(1 + x^2))`. -/\n@[pp_nodot] def arsinh (x : ℝ) := log (x + sqrt (1 + x^2))\n\nlemma exp_arsinh (x : ℝ) : exp (arsinh x) = x + sqrt (1 + x^2) :=\nbegin\n  apply exp_log,\n  rw [← neg_lt_iff_pos_add'],\n  calc -x ≤ sqrt (x ^ 2) : le_sqrt_of_sq_le (neg_pow_bit0 _ _).le\n  ... < sqrt (1 + x ^ 2) : sqrt_lt_sqrt (sq_nonneg _) (lt_one_add _)\nend\n\n@[simp] lemma arsinh_zero : arsinh 0 = 0 := by simp [arsinh]\n\n@[simp] lemma arsinh_neg (x : ℝ) : arsinh (-x) = -arsinh x :=\nbegin\n  rw [← exp_eq_exp, exp_arsinh, exp_neg, exp_arsinh],\n  apply eq_inv_of_mul_eq_one_left,\n  rw [neg_sq, neg_add_eq_sub, add_comm x, mul_comm, ← sq_sub_sq, sq_sqrt, add_sub_cancel],\n  exact add_nonneg zero_le_one (sq_nonneg _)\nend\n\n/-- `arsinh` is the right inverse of `sinh`. -/\n@[simp] lemma sinh_arsinh (x : ℝ) : sinh (arsinh x) = x :=\nby { rw [sinh_eq, ← arsinh_neg, exp_arsinh, exp_arsinh, neg_sq], field_simp }\n\n@[simp] lemma cosh_arsinh (x : ℝ) : cosh (arsinh x) = sqrt (1 + x^2) :=\nby rw [← sqrt_sq (cosh_pos _).le, cosh_sq', sinh_arsinh]\n\n/-- `sinh` is surjective, `∀ b, ∃ a, sinh a = b`. In this case, we use `a = arsinh b`. -/\nlemma sinh_surjective : surjective sinh := left_inverse.surjective sinh_arsinh\n\n/-- `sinh` is bijective, both injective and surjective. -/\nlemma sinh_bijective : bijective sinh := ⟨sinh_injective, sinh_surjective⟩\n\n/-- `arsinh` is the left inverse of `sinh`. -/\n@[simp] lemma arsinh_sinh (x : ℝ) : arsinh (sinh x) = x :=\nright_inverse_of_injective_of_left_inverse sinh_injective sinh_arsinh x\n\n/-- `real.sinh` as an `equiv`. -/\n@[simps] def sinh_equiv : ℝ ≃ ℝ :=\n{ to_fun := sinh,\n  inv_fun := arsinh,\n  left_inv := arsinh_sinh,\n  right_inv := sinh_arsinh }\n\n/-- `real.sinh` as an `order_iso`. -/\n@[simps { fully_applied := ff }] def sinh_order_iso : ℝ ≃o ℝ :=\n{ to_equiv := sinh_equiv,\n  map_rel_iff' := @sinh_le_sinh }\n\n/-- `real.sinh` as a `homeomorph`. -/\n@[simps { fully_applied := ff }] def sinh_homeomorph : ℝ ≃ₜ ℝ := sinh_order_iso.to_homeomorph\n\nlemma arsinh_bijective : bijective arsinh := sinh_equiv.symm.bijective\nlemma arsinh_injective : injective arsinh := sinh_equiv.symm.injective\nlemma arsinh_surjective : surjective arsinh := sinh_equiv.symm.surjective\n\nlemma arsinh_strict_mono : strict_mono arsinh := sinh_order_iso.symm.strict_mono\n\n@[simp] lemma arsinh_inj : arsinh x = arsinh y ↔ x = y := arsinh_injective.eq_iff\n@[simp] lemma arsinh_le_arsinh : arsinh x ≤ arsinh y ↔ x ≤ y := sinh_order_iso.symm.le_iff_le\n@[simp] lemma arsinh_lt_arsinh : arsinh x < arsinh y ↔ x < y := sinh_order_iso.symm.lt_iff_lt\n\n@[simp] lemma arsinh_eq_zero_iff : arsinh x = 0 ↔ x = 0 :=\narsinh_injective.eq_iff' arsinh_zero\n\n@[simp] lemma arsinh_nonneg_iff : 0 ≤ arsinh x ↔ 0 ≤ x :=\nby rw [← sinh_le_sinh, sinh_zero, sinh_arsinh]\n\n@[simp] lemma arsinh_nonpos_iff : arsinh x ≤ 0 ↔ x ≤ 0 :=\nby rw [← sinh_le_sinh, sinh_zero, sinh_arsinh]\n\n@[simp] lemma arsinh_pos_iff : 0 < arsinh x ↔ 0 < x :=\nlt_iff_lt_of_le_iff_le arsinh_nonpos_iff\n\n@[simp] lemma arsinh_neg_iff : arsinh x < 0 ↔ x < 0 :=\nlt_iff_lt_of_le_iff_le arsinh_nonneg_iff\n\nlemma has_strict_deriv_at_arsinh (x : ℝ) : has_strict_deriv_at arsinh (sqrt (1 + x ^ 2))⁻¹ x :=\nbegin\n  convert sinh_homeomorph.to_local_homeomorph.has_strict_deriv_at_symm (mem_univ x)\n    (cosh_pos _).ne' (has_strict_deriv_at_sinh _),\n  exact (cosh_arsinh _).symm\nend\n\nlemma has_deriv_at_arsinh (x : ℝ) : has_deriv_at arsinh (sqrt (1 + x ^ 2))⁻¹ x :=\n(has_strict_deriv_at_arsinh x).has_deriv_at\n\nlemma differentiable_arsinh : differentiable ℝ arsinh :=\nλ x, (has_deriv_at_arsinh x).differentiable_at\n\nlemma cont_diff_arsinh {n : with_top ℕ} : cont_diff ℝ n arsinh :=\nsinh_homeomorph.cont_diff_symm_deriv (λ x, (cosh_pos x).ne') has_deriv_at_sinh cont_diff_sinh\n\n@[continuity] lemma continuous_arsinh : continuous arsinh := sinh_homeomorph.symm.continuous\n\nend real\n\nopen real\n\nlemma filter.tendsto.arsinh {α : Type*} {l : filter α} {f : α → ℝ} {a : ℝ}\n  (h : tendsto f l (𝓝 a)) : tendsto (λ x, arsinh (f x)) l (𝓝 (arsinh a)) :=\n(continuous_arsinh.tendsto _).comp h\n\nsection continuous\n\nvariables {X : Type*} [topological_space X] {f : X → ℝ} {s : set X} {a : X}\n\nlemma continuous_at.arsinh (h : continuous_at f a) : continuous_at (λ x, arsinh (f x)) a := h.arsinh\n\nlemma continuous_within_at.arsinh (h : continuous_within_at f s a) :\n  continuous_within_at (λ x, arsinh (f x)) s a :=\nh.arsinh\n\nlemma continuous_on.arsinh (h : continuous_on f s) : continuous_on (λ x, arsinh (f x)) s :=\nλ x hx, (h x hx).arsinh\n\nlemma continuous.arsinh (h : continuous f) : continuous (λ x, arsinh (f x)) :=\ncontinuous_arsinh.comp h\n\nend continuous\n\nsection fderiv\n\nvariables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {s : set E} {a : E}\n  {f' : E →L[ℝ] ℝ} {n : with_top ℕ}\n\nlemma has_strict_fderiv_at.arsinh (hf : has_strict_fderiv_at f f' a) :\n  has_strict_fderiv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_strict_deriv_at_arsinh _).comp_has_strict_fderiv_at a hf\n\nlemma has_fderiv_at.arsinh (hf : has_fderiv_at f f' a) :\n  has_fderiv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_deriv_at_arsinh _).comp_has_fderiv_at a hf\n\nlemma has_fderiv_within_at.arsinh (hf : has_fderiv_within_at f f' s a) :\n  has_fderiv_within_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') s a :=\n(has_deriv_at_arsinh _).comp_has_fderiv_within_at a hf\n\nlemma differentiable_at.arsinh (h : differentiable_at ℝ f a) :\n  differentiable_at ℝ (λ x, arsinh (f x)) a :=\n(differentiable_arsinh _).comp a h\n\nlemma differentiable_within_at.arsinh (h : differentiable_within_at ℝ f s a) :\n  differentiable_within_at ℝ (λ x, arsinh (f x)) s a :=\n(differentiable_arsinh _).comp_differentiable_within_at a h\n\nlemma differentiable_on.arsinh (h : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λ x, arsinh (f x)) s :=\nλ x hx, (h x hx).arsinh\n\nlemma differentiable.arsinh (h : differentiable ℝ f) :\n  differentiable ℝ (λ x, arsinh (f x)) :=\ndifferentiable_arsinh.comp h\n\nlemma cont_diff_at.arsinh (h : cont_diff_at ℝ n f a) :\n  cont_diff_at ℝ n (λ x, arsinh (f x)) a :=\ncont_diff_arsinh.cont_diff_at.comp a h\n\nlemma cont_diff_within_at.arsinh (h : cont_diff_within_at ℝ n f s a) :\n  cont_diff_within_at ℝ n (λ x, arsinh (f x)) s a :=\ncont_diff_arsinh.cont_diff_at.comp_cont_diff_within_at a h\n\nlemma cont_diff.arsinh (h : cont_diff ℝ n f) : cont_diff ℝ n (λ x, arsinh (f x)) :=\ncont_diff_arsinh.comp h\n\nlemma cont_diff_on.arsinh (h : cont_diff_on ℝ n f s) : cont_diff_on ℝ n (λ x, arsinh (f x)) s :=\nλ x hx, (h x hx).arsinh\n\nend fderiv\n\nsection deriv\n\nvariables {f : ℝ → ℝ} {s : set ℝ} {a f' : ℝ}\n\nlemma has_strict_deriv_at.arsinh (hf : has_strict_deriv_at f f' a) :\n  has_strict_deriv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_strict_deriv_at_arsinh _).comp a hf\n\nlemma has_deriv_at.arsinh (hf : has_deriv_at f f' a) :\n  has_deriv_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') a :=\n(has_deriv_at_arsinh _).comp a hf\n\nlemma has_deriv_within_at.arsinh (hf : has_deriv_within_at f f' s a) :\n  has_deriv_within_at (λ x, arsinh (f x)) ((sqrt (1 + (f a) ^ 2))⁻¹ • f') s a :=\n(has_deriv_at_arsinh _).comp_has_deriv_within_at a hf\n\nend 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/arsinh.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7629729723379809}}
{"text": "def Set (α : Type u) := α → Prop\ndef Set.in (s : Set α) (a : α) := s a\n\nnotation:50 a \" ∈ \" s:50 => Set.in s a\n\ndef Set.pred (p : α → Prop) : Set α := p\n\nnotation \"{\" a \"|\" p \"}\" => Set.pred (fun a => p)\n\ntheorem ex1 : (1, 3) ∈ { (n, m) | n < 2 ∧ m < 5 } := by\n  simp [Set.in, Set.pred]\n\ndef Set.union (s₁ s₂ : Set α) : Set α :=\n  { a | a ∈ s₁ ∨ a ∈ s₂ }\n\ninfix:65 \" ∪ \" => Set.union\n\ndef Set.inter (s₁ s₂ : Set α) : Set α :=\n  { a | a ∈ s₁ ∧ a ∈ s₂ }\n\ninfix:70 \" ∩ \" => Set.inter\n\ninstance (s : Set α) [h : Decidable (s a)] : Decidable (a ∈ Set.pred s) :=\n  h\n\ninstance (s₁ s₂ : Set α) [Decidable (a ∈ s₁)] [Decidable (a ∈ s₂)] : Decidable (a ∈ s₁ ∩ s₂) :=\n  inferInstanceAs (Decidable (_ ∧ _))\n\ninstance (s₁ s₂ : Set α) [Decidable (a ∈ s₁)] [Decidable (a ∈ s₂)] : Decidable (a ∈ s₁ ∪ s₂) :=\n  inferInstanceAs (Decidable (_ ∨ _))\n\ntheorem ex2 : (1, 3) ∈ { (x, y) | x < y } :=\n  by decide\n\ntheorem ex3 : (10000, 300000) ∈ { (x, y) | x < y } ∩ { (x, y) | x = 10000 } :=\n  by decide\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/set.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7628168838507647}}
{"text": "import data.real.basic\n\n#check mul_lt_mul_right\n#check @lt_of_lt_of_le\n\n-- BEGIN\nlemma my_lemma : ∀ {x y ε : ℝ},\n  0 < ε → ε ≤ 1 → abs x < ε → abs y < ε → abs (x * y) < ε :=\nbegin\n  intros x y ε epos ele1 xlt ylt,\n  calc\n    abs (x * y) = abs x * abs y : by rw abs_mul\n    ... ≤ abs x * ε             : mul_le_mul_of_nonneg_left (le_of_lt ylt) (abs_nonneg x)\n    ... < 1 * ε                 : mul_lt_mul_of_pos_right (lt_of_le_of_lt' ele1 xlt) epos\n    ... = ε                     : by rw one_mul,\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)/ex11_intro_vari_h_abs_x_y.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7628168736519598}}
{"text": "import tactic --hide\n\n/-\n## The `cases` tactic\n\n`cases` is a very general-purpose tactic for \"deconstructing\" hypotheses.\nIf `h` is an assumption which somehow \"bundles up\" two pieces of information,\nthen  <mark style =\"background-color : #ebdef0 \">`cases h with h1 h2`</mark>  will make the \nassumption `h` vanish and will replace it with the two \"components\" which made the proof of `h` in the first place.\nAn example of this occurring is if you have the assumption `h : P ∧ Q` which contains a \nproof of `P` and a proof of `Q`.\n\n\n\nFor example, if you have an assumption\n\n```\nh : P ∧ Q\n```\n\nthen\n\n`cases h with hP hQ,`\n\nwill delete `h` and replace it with\n\n```\nhP : P\nhQ : Q\n```\nTry it out below.\n\n-/\n\n\n/- Lemma\nIf $P,Q$ are logical statements and $P ∧ Q$ is true then so is $P$.\n-/\n\nlemma cases_and_example (P Q : Prop) (h : P ∧ Q) : P :=\nbegin \n  cases h with hP hQ,\n  exact hP,\nend\n\n/- Tactic : cases\n\nIf you have a hypothesis\n\n```\nh : P ∧ Q\n```\n\nthen\n\n`cases h with hP hQ,`\n\nwill delete `h` 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 ∨ 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/casestac.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7628082964562566}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot\n-/\nimport algebra.order.field\nimport data.finset.preimage\nimport data.set.intervals.disjoint\nimport order.filter.bases\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 → +∞`;\n* `at_bot`: corresponds to `n → -∞`.\n\nThen we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”.\n-/\n\nvariables {ι ι' α β γ : Type*}\n\nopen set\nopen_locale classical filter big_operators\n\nnamespace filter\n/-- `at_top` is the filter representing the limit `→ ∞` on an ordered set.\n  It is generated by the collection of up-sets `{b | a ≤ 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 α] : filter α := ⨅ a, 𝓟 (Ici a)\n\n/-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set.\n  It is generated by the collection of down-sets `{b | b ≤ 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 α] : filter α := ⨅ a, 𝓟 (Iic a)\n\nlemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ @at_top α _ :=\nmem_infi_of_mem a $ subset.refl _\n\nlemma Ici_mem_at_top [preorder α] (a : α) : Ici a ∈ (at_top : filter α) := mem_at_top a\n\nlemma Ioi_mem_at_top [preorder α] [no_max_order α] (x : α) : Ioi x ∈ (at_top : filter α) :=\nlet ⟨z, hz⟩ := exists_gt x in mem_of_superset (mem_at_top z) $ λ y h,  lt_of_lt_of_le hz h\n\nlemma mem_at_bot [preorder α] (a : α) : {b : α | b ≤ a} ∈ @at_bot α _ :=\nmem_infi_of_mem a $ subset.refl _\n\nlemma Iic_mem_at_bot [preorder α] (a : α) : Iic a ∈ (at_bot : filter α) := mem_at_bot a\n\nlemma Iio_mem_at_bot [preorder α] [no_min_order α] (x : α) : Iio x ∈ (at_bot : filter α) :=\nlet ⟨z, hz⟩ := exists_lt x in mem_of_superset (mem_at_bot z) $ λ y h, lt_of_le_of_lt h hz\n\nlemma disjoint_at_bot_principal_Ioi [preorder α] (x : α) : disjoint at_bot (𝓟 (Ioi x)) :=\ndisjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_at_bot x) (mem_principal_self _)\n\nlemma disjoint_at_top_principal_Iio [preorder α] (x : α) : disjoint at_top (𝓟 (Iio x)) :=\n@disjoint_at_bot_principal_Ioi αᵒᵈ _ _\n\nlemma disjoint_at_top_principal_Iic [preorder α] [no_max_order α] (x : α) :\n  disjoint at_top (𝓟 (Iic x)) :=\ndisjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_at_top x) (mem_principal_self _)\n\nlemma disjoint_at_bot_principal_Ici [preorder α] [no_min_order α] (x : α) :\n  disjoint at_bot (𝓟 (Ici x)) :=\n@disjoint_at_top_principal_Iic αᵒᵈ _ _ _\n\nlemma disjoint_at_bot_at_top [partial_order α] [nontrivial α] :\n  disjoint (at_bot : filter α) at_top :=\nbegin\n  rcases exists_pair_ne α with ⟨x, y, hne⟩,\n  by_cases hle : x ≤ y,\n  { refine disjoint_of_disjoint_of_mem _ (Iic_mem_at_bot x) (Ici_mem_at_top y),\n    exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_le },\n  { refine disjoint_of_disjoint_of_mem _ (Iic_mem_at_bot y) (Ici_mem_at_top x),\n    exact Iic_disjoint_Ici.2 hle }\nend\n\nlemma disjoint_at_top_at_bot [partial_order α] [nontrivial α] :\n  disjoint (at_top : filter α) at_bot :=\ndisjoint_at_bot_at_top.symm\n\nlemma at_top_basis [nonempty α] [semilattice_sup α] :\n  (@at_top α _).has_basis (λ _, true) Ici :=\nhas_basis_infi_principal (directed_of_sup $ λ a b, Ici_subset_Ici.2)\n\nlemma at_top_basis' [semilattice_sup α] (a : α) :\n  (@at_top α _).has_basis (λ x, a ≤ x) Ici :=\n⟨λ t, (@at_top_basis α ⟨a⟩ _).mem_iff.trans\n  ⟨λ ⟨x, _, hx⟩, ⟨x ⊔ a, le_sup_right, λ y hy, hx (le_trans le_sup_left hy)⟩,\n    λ ⟨x, _, hx⟩, ⟨x, trivial, hx⟩⟩⟩\n\nlemma at_bot_basis [nonempty α] [semilattice_inf α] : (@at_bot α _).has_basis (λ _, true) Iic :=\n@at_top_basis αᵒᵈ _ _\n\nlemma at_bot_basis' [semilattice_inf α] (a : α) : (@at_bot α _).has_basis (λ x, x ≤ a) Iic :=\n@at_top_basis' αᵒᵈ _ _\n\n@[instance]\nlemma at_top_ne_bot [nonempty α] [semilattice_sup α] : ne_bot (at_top : filter α) :=\nat_top_basis.ne_bot_iff.2 $ λ a _, nonempty_Ici\n\n@[instance]\nlemma at_bot_ne_bot [nonempty α] [semilattice_inf α] : ne_bot (at_bot : filter α) :=\n@at_top_ne_bot αᵒᵈ _ _\n\n@[simp]\nlemma mem_at_top_sets [nonempty α] [semilattice_sup α] {s : set α} :\n  s ∈ (at_top : filter α) ↔ ∃a:α, ∀b≥a, b ∈ s :=\nat_top_basis.mem_iff.trans $ exists_congr $ λ _, exists_const _\n\n@[simp]\nlemma mem_at_bot_sets [nonempty α] [semilattice_inf α] {s : set α} :\n  s ∈ (at_bot : filter α) ↔ ∃a:α, ∀b≤a, b ∈ s :=\n@mem_at_top_sets αᵒᵈ _ _ _\n\n@[simp]\nlemma eventually_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} :\n  (∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ b ≥ a, p b) :=\nmem_at_top_sets\n\n@[simp]\nlemma eventually_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} :\n  (∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ b ≤ a, p b) :=\nmem_at_bot_sets\n\nlemma eventually_ge_at_top [preorder α] (a : α) : ∀ᶠ x in at_top, a ≤ x := mem_at_top a\n\nlemma eventually_le_at_bot [preorder α] (a : α) : ∀ᶠ x in at_bot, x ≤ a := mem_at_bot a\n\nlemma eventually_gt_at_top [preorder α] [no_max_order α] (a : α) :\n  ∀ᶠ x in at_top, a < x :=\nIoi_mem_at_top a\n\nlemma eventually_ne_at_top [preorder α] [no_max_order α] (a : α) :\n  ∀ᶠ x in at_top, x ≠ a :=\n(eventually_gt_at_top a).mono $ λ x, ne_of_gt\n\nlemma tendsto.eventually_gt_at_top [preorder β] [no_max_order β] {f : α → β} {l : filter α}\n  (hf : tendsto f l at_top) (c : β) : ∀ᶠ x in l, c < f x :=\nhf.eventually (eventually_gt_at_top c)\n\nlemma tendsto.eventually_ge_at_top [preorder β] {f : α → β} {l : filter α}\n  (hf : tendsto f l at_top) (c : β) : ∀ᶠ x in l, c ≤ f x :=\nhf.eventually (eventually_ge_at_top c)\n\nlemma tendsto.eventually_ne_at_top [preorder β] [no_max_order β] {f : α → β} {l : filter α}\n  (hf : tendsto f l at_top) (c : β) : ∀ᶠ x in l, f x ≠ c :=\nhf.eventually (eventually_ne_at_top c)\n\nlemma eventually_lt_at_bot [preorder α] [no_min_order α] (a : α) :\n  ∀ᶠ x in at_bot, x < a :=\nIio_mem_at_bot a\n\nlemma eventually_ne_at_bot [preorder α] [no_min_order α] (a : α) :\n  ∀ᶠ x in at_bot, x ≠ a :=\n(eventually_lt_at_bot a).mono $ λ x, ne_of_lt\n\nlemma tendsto.eventually_lt_at_bot [preorder β] [no_min_order β] {f : α → β} {l : filter α}\n  (hf : tendsto f l at_bot) (c : β) : ∀ᶠ x in l, f x < c :=\nhf.eventually (eventually_lt_at_bot c)\n\nlemma tendsto.eventually_le_at_bot [preorder β] {f : α → β} {l : filter α}\n  (hf : tendsto f l at_bot) (c : β) : ∀ᶠ x in l, f x ≤ c :=\nhf.eventually (eventually_le_at_bot c)\n\nlemma tendsto.eventually_ne_at_bot [preorder β] [no_min_order β] {f : α → β} {l : filter α}\n  (hf : tendsto f l at_bot) (c : β) :  ∀ᶠ x in l, f x ≠ c :=\nhf.eventually (eventually_ne_at_bot c)\n\nlemma at_top_basis_Ioi [nonempty α] [semilattice_sup α] [no_max_order α] :\n  (@at_top α _).has_basis (λ _, true) Ioi :=\nat_top_basis.to_has_basis (λ a ha, ⟨a, ha, Ioi_subset_Ici_self⟩) $\n  λ a ha, (exists_gt a).imp $ λ b hb, ⟨ha, Ici_subset_Ioi.2 hb⟩\n\nlemma at_top_countable_basis [nonempty α] [semilattice_sup α] [encodable α] :\n  has_countable_basis (at_top : filter α) (λ _, true) Ici :=\n{ countable := countable_encodable _,\n  .. at_top_basis }\n\nlemma at_bot_countable_basis [nonempty α] [semilattice_inf α] [encodable α] :\n  has_countable_basis (at_bot : filter α) (λ _, true) Iic :=\n{ countable := countable_encodable _,\n  .. at_bot_basis }\n\n@[priority 200]\ninstance at_top.is_countably_generated [preorder α] [encodable α] :\n  (at_top : filter $ α).is_countably_generated :=\nis_countably_generated_seq _\n\n@[priority 200]\ninstance at_bot.is_countably_generated [preorder α] [encodable α] :\n  (at_bot : filter $ α).is_countably_generated :=\nis_countably_generated_seq _\n\nlemma order_top.at_top_eq (α) [partial_order α] [order_top α] : (at_top : filter α) = pure ⊤ :=\nle_antisymm (le_pure_iff.2 $ (eventually_ge_at_top ⊤).mono $ λ b, top_unique)\n  (le_infi $ λ b, le_principal_iff.2 le_top)\n\n\n\n@[nontriviality]\nlemma subsingleton.at_top_eq (α) [subsingleton α] [preorder α] : (at_top : filter α) = ⊤ :=\nbegin\n  refine top_unique (λ s hs x, _),\n  letI : unique α := ⟨⟨x⟩, λ y, subsingleton.elim y x⟩,\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 (α) [subsingleton α] [preorder α] : (at_bot : filter α) = ⊤ :=\n@subsingleton.at_top_eq αᵒᵈ _ _\n\nlemma tendsto_at_top_pure [partial_order α] [order_top α] (f : α → β) :\n  tendsto f at_top (pure $ f ⊤) :=\n(order_top.at_top_eq α).symm ▸ tendsto_pure_pure _ _\n\nlemma tendsto_at_bot_pure [partial_order α] [order_bot α] (f : α → β) :\n  tendsto f at_bot (pure $ f ⊥) :=\n@tendsto_at_top_pure αᵒᵈ _ _ _ _\n\nlemma eventually.exists_forall_of_at_top [semilattice_sup α] [nonempty α] {p : α → Prop}\n  (h : ∀ᶠ x in at_top, p x) : ∃ a, ∀ b ≥ a, p b :=\neventually_at_top.mp h\n\nlemma eventually.exists_forall_of_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop}\n  (h : ∀ᶠ x in at_bot, p x) : ∃ a, ∀ b ≤ a, p b :=\neventually_at_bot.mp h\n\nlemma frequently_at_top [semilattice_sup α] [nonempty α] {p : α → Prop} :\n  (∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b ≥ a, p b) :=\nby simp [at_top_basis.frequently_iff]\n\nlemma frequently_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop} :\n  (∃ᶠ x in at_bot, p x) ↔ (∀ a, ∃ b ≤ a, p b) :=\n@frequently_at_top αᵒᵈ _ _ _\n\nlemma frequently_at_top' [semilattice_sup α] [nonempty α] [no_max_order α] {p : α → Prop} :\n  (∃ᶠ x in at_top, p x) ↔ (∀ a, ∃ b > a, p b) :=\nby simp [at_top_basis_Ioi.frequently_iff]\n\nlemma frequently_at_bot' [semilattice_inf α] [nonempty α] [no_min_order α] {p : α → Prop} :\n  (∃ᶠ x in at_bot, p x) ↔ (∀ a, ∃ b < a, p b) :=\n@frequently_at_top' αᵒᵈ _ _ _ _\n\nlemma frequently.forall_exists_of_at_top [semilattice_sup α] [nonempty α] {p : α → Prop}\n  (h : ∃ᶠ x in at_top, p x) : ∀ a, ∃ b ≥ a, p b :=\nfrequently_at_top.mp h\n\nlemma frequently.forall_exists_of_at_bot [semilattice_inf α] [nonempty α] {p : α → Prop}\n  (h : ∃ᶠ x in at_bot, p x) : ∀ a, ∃ b ≤ a, p b :=\nfrequently_at_bot.mp h\n\nlemma map_at_top_eq [nonempty α] [semilattice_sup α] {f : α → β} :\n  at_top.map f = (⨅a, 𝓟 $ f '' {a' | a ≤ a'}) :=\n(at_top_basis.map _).eq_infi\n\nlemma map_at_bot_eq [nonempty α] [semilattice_inf α] {f : α → β} :\n  at_bot.map f = (⨅a, 𝓟 $ f '' {a' | a' ≤ a}) :=\n@map_at_top_eq αᵒᵈ _ _ _ _\n\nlemma tendsto_at_top [preorder β] {m : α → β} {f : filter α} :\n  tendsto m f at_top ↔ (∀b, ∀ᶠ a in f, b ≤ m a) :=\nby simp only [at_top, tendsto_infi, tendsto_principal, mem_Ici]\n\nlemma tendsto_at_bot [preorder β] {m : α → β} {f : filter α} :\n  tendsto m f at_bot ↔ (∀b, ∀ᶠ a in f, m a ≤ b) :=\n@tendsto_at_top α βᵒᵈ _ m f\n\nlemma tendsto_at_top_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) :\n  tendsto f₁ l at_top → tendsto f₂ l at_top :=\nassume h₁, tendsto_at_top.2 $ λ b, mp_mem (tendsto_at_top.1 h₁ b)\n  (monotone_mem (λ a ha ha₁, le_trans ha₁ ha) h)\n\nlemma tendsto_at_bot_mono' [preorder β] (l : filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) :\n  tendsto f₂ l at_bot → tendsto f₁ l at_bot :=\n@tendsto_at_top_mono' _ βᵒᵈ _ _ _ _ h\n\nlemma tendsto_at_top_mono [preorder β] {l : filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :\n  tendsto f l at_top → tendsto g l at_top :=\ntendsto_at_top_mono' l $ eventually_of_forall h\n\nlemma tendsto_at_bot_mono [preorder β] {l : filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :\n  tendsto g l at_bot → tendsto f l at_bot :=\n@tendsto_at_top_mono _ βᵒᵈ _ _ _ _ h\n\n/-!\n### Sequences\n-/\n\nlemma inf_map_at_top_ne_bot_iff [semilattice_sup α] [nonempty α] {F : filter β} {u : α → β} :\n  ne_bot (F ⊓ (map u at_top)) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ 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 α] [nonempty α] {F : filter β} {u : α → β} :\n  ne_bot (F ⊓ (map u at_bot)) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U :=\n@inf_map_at_top_ne_bot_iff αᵒᵈ _ _ _ _ _\n\nlemma extraction_of_frequently_at_top' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=\nbegin\n  choose u hu using h,\n  cases forall_and_distrib.mp hu with hu hu',\n  exact ⟨u ∘ (nat.rec 0 (λ n v, u v)), strict_mono_nat_of_lt_succ (λ n, hu _), λ n, hu' _⟩,\nend\n\nlemma extraction_of_frequently_at_top {P : ℕ → Prop} (h : ∃ᶠ n in at_top, P n) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ 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 : ℕ → Prop} (h : ∀ᶠ n in at_top, P n) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P (φ n) :=\nextraction_of_frequently_at_top h.frequently\n\nlemma extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in at_top, P n k) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P n (φ n) :=\nbegin\n  simp only [frequently_at_top'] at h,\n  choose u hu hu' using h,\n  use (λ n, nat.rec_on n (u 0 0) (λ n v, u (n+1) v) : ℕ → ℕ),\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 : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in at_top, P n k) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P n (φ n) :=\nextraction_forall_of_frequently (λ n, (h n).frequently)\n\nlemma extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, P n (φ n) :=\nextraction_forall_of_eventually (by simp [eventually_at_top, h])\n\nlemma exists_le_of_tendsto_at_top [semilattice_sup α] [preorder β] {u : α → β}\n  (h : tendsto u at_top at_top) (a : α) (b : β) : ∃ a' ≥ a, b ≤ u a' :=\nbegin\n  have : ∀ᶠ x in at_top, a ≤ x ∧ b ≤ u x :=\n    (eventually_ge_at_top a).and (h.eventually $ eventually_ge_at_top b),\n  haveI : nonempty α := ⟨a⟩,\n  rcases this.exists with ⟨a', ha, hb⟩,\n  exact ⟨a', ha, hb⟩\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_le_of_tendsto_at_bot [semilattice_sup α] [preorder β] {u : α → β}\n  (h : tendsto u at_top at_bot) : ∀ a b, ∃ a' ≥ a, u a' ≤ b :=\n@exists_le_of_tendsto_at_top _ βᵒᵈ _ _ _ h\n\nlemma exists_lt_of_tendsto_at_top [semilattice_sup α] [preorder β] [no_max_order β]\n  {u : α → β} (h : tendsto u at_top at_top) (a : α) (b : β) : ∃ a' ≥ 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 ⟨a', ha', ha''⟩,\n  exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩\nend\n\n@[nolint ge_or_gt] -- see Note [nolint_ge]\nlemma exists_lt_of_tendsto_at_bot [semilattice_sup α] [preorder β] [no_min_order β]\n  {u : α → β} (h : tendsto u at_top at_bot) : ∀ a b, ∃ a' ≥ 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-/\nlemma high_scores [linear_order β] [no_max_order β] {u : ℕ → β}\n  (hu : tendsto u at_top at_top) : ∀ N, ∃ n ≥ N, ∀ k < n, u k < u n :=\nbegin\n  intros N,\n  obtain ⟨k : ℕ, hkn : k ≤ N, hku : ∀ l ≤ N, u l ≤ u k⟩ : ∃ k ≤ N, ∀ l ≤ N, u l ≤ u k,\n    from exists_max_image _ u (finite_le_nat N) ⟨N, le_refl N⟩,\n  have ex : ∃ n ≥ N, u k < u n,\n    from exists_lt_of_tendsto_at_top hu _ _,\n  obtain ⟨n : ℕ, hnN : n ≥ N, hnk : u k < u n, hn_min : ∀ m, m < n → N ≤ m → u m ≤ u k⟩ :\n    ∃ n ≥ N, u k < u n ∧ ∀ m, m < n → N ≤ m → u m ≤ u k,\n  { rcases nat.find_x ex with ⟨n, ⟨hnN, hnk⟩, hn_min⟩,\n    push_neg at hn_min,\n    exact ⟨n, hnN, hnk, hn_min⟩ },\n  use [n, hnN],\n  rintros (l : ℕ) (hl : l < n),\n  have hlk : u l ≤ u k,\n  { cases (le_total l N : l ≤ N ∨ N ≤ l) with H H,\n    { exact hku l H },\n    { exact hn_min l hl H } },\n  calc u l ≤ 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 β] [no_min_order β] {u : ℕ → β}\n  (hu : tendsto u at_top at_bot) : ∀ N, ∃ n ≥ N, ∀ k < n, 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-/\nlemma frequently_high_scores [linear_order β] [no_max_order β] {u : ℕ → β}\n  (hu : tendsto u at_top at_top) : ∃ᶠ n in at_top, ∀ 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 β] [no_min_order β] {u : ℕ → β}\n  (hu : tendsto u at_top at_bot) : ∃ᶠ n in at_top, ∀ k < n, u n < u k :=\n@frequently_high_scores βᵒᵈ _ _ _ hu\n\nlemma strict_mono_subseq_of_tendsto_at_top\n  {β : Type*} [linear_order β] [no_max_order β]\n  {u : ℕ → β} (hu : tendsto u at_top at_top) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) :=\nlet ⟨φ, h, h'⟩ := extraction_of_frequently_at_top (frequently_high_scores hu) in\n⟨φ, h, λ n m hnm, h' m _ (h hnm)⟩\n\nlemma strict_mono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ strict_mono (u ∘ φ) :=\nstrict_mono_subseq_of_tendsto_at_top (tendsto_at_top_mono hu tendsto_id)\n\nlemma _root_.strict_mono.tendsto_at_top {φ : ℕ → ℕ} (h : strict_mono φ) :\n  tendsto φ 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 β] {l : filter α} {f g : α → β}\n\nlemma tendsto_at_top_add_nonneg_left' (hf : ∀ᶠ x in l, 0 ≤ f x) (hg : tendsto g l at_top) :\n  tendsto (λ x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (hf.mono (λ x, le_add_of_nonneg_left)) hg\n\nlemma tendsto_at_bot_add_nonpos_left' (hf : ∀ᶠ x in l, f x ≤ 0) (hg : tendsto g l at_bot) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left' _ βᵒᵈ _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : tendsto g l at_top) :\n  tendsto (λ 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 : ∀ x, f x ≤ 0) (hg : tendsto g l at_bot) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_left _ βᵒᵈ _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right' (hf : tendsto f l at_top) (hg : ∀ᶠ x in l, 0 ≤ g x) :\n  tendsto (λ x, f x + g x) l at_top :=\ntendsto_at_top_mono' l (monotone_mem (λ x, le_add_of_nonneg_right) hg) hf\n\nlemma tendsto_at_bot_add_nonpos_right' (hf : tendsto f l at_bot) (hg : ∀ᶠ x in l, g x ≤ 0) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right' _ βᵒᵈ _ _ _ _ hf hg\n\nlemma tendsto_at_top_add_nonneg_right (hf : tendsto f l at_top) (hg : ∀ x, 0 ≤ g x) :\n  tendsto (λ 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 : ∀ x, g x ≤ 0) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_nonneg_right _ βᵒᵈ _ _ _ _ hf hg\n\nlemma tendsto_at_top_add (hf : tendsto f l at_top) (hg : tendsto g l at_top) :\n  tendsto (λ 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 (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add _ βᵒᵈ _ _ _ _ hf hg\n\nlemma tendsto.nsmul_at_top (hf : tendsto f l at_top) {n : ℕ} (hn : 0 < n) :\n  tendsto (λ x, n • f x) l at_top :=\ntendsto_at_top.2 $ λ y, (tendsto_at_top.1 hf y).mp $ (tendsto_at_top.1 hf 0).mono $ λ x h₀ hy,\ncalc y ≤ f x : hy\n... = 1 • f x : (one_nsmul _).symm\n... ≤  n • f x : nsmul_le_nsmul h₀ hn\n\nlemma tendsto.nsmul_at_bot (hf : tendsto f l at_bot) {n : ℕ} (hn : 0 < n) :\n  tendsto (λ x, n • f x) l at_bot :=\n@tendsto.nsmul_at_top α βᵒᵈ _ l f hf n hn\n\nlemma tendsto_bit0_at_top : tendsto bit0 (at_top : filter β) at_top :=\ntendsto_at_top_add tendsto_id tendsto_id\n\nlemma tendsto_bit0_at_bot : tendsto bit0 (at_bot : filter β) 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 β] {l : filter α} {f g : α → β}\n\nlemma tendsto_at_top_of_add_const_left (C : β) (hf : tendsto (λ 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 (λ x, le_of_add_le_add_left)\n\nlemma tendsto_at_bot_of_add_const_left (C : β) (hf : tendsto (λ x, C + f x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_left _ βᵒᵈ _ _ _ C hf\n\nlemma tendsto_at_top_of_add_const_right (C : β) (hf : tendsto (λ 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 (λ x, le_of_add_le_add_right)\n\nlemma tendsto_at_bot_of_add_const_right (C : β) (hf : tendsto (λ x, f x + C) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_const_right _ βᵒᵈ _ _ _ C hf\n\nlemma tendsto_at_top_of_add_bdd_above_left' (C) (hC : ∀ᶠ x in l, f x ≤ C)\n  (h : tendsto (λ 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 (λ x hx, add_le_add_right hx (g x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_left' (C) (hC : ∀ᶠ x in l, C ≤ f x)\n  (h : tendsto (λ x, f x + g x) l at_bot) :\n  tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left' _ βᵒᵈ _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) :\n  tendsto (λ x, f x + g x) l at_top → 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 : ∀ x, C ≤ f x) :\n  tendsto (λ x, f x + g x) l at_bot → tendsto g l at_bot :=\n@tendsto_at_top_of_add_bdd_above_left _ βᵒᵈ _ _ _ _ C hC\n\nlemma tendsto_at_top_of_add_bdd_above_right' (C) (hC : ∀ᶠ x in l, g x ≤ C)\n  (h : tendsto (λ 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 (λ x hx, add_le_add_left hx (f x))) h)\n\nlemma tendsto_at_bot_of_add_bdd_below_right' (C) (hC : ∀ᶠ x in l, C ≤ g x)\n  (h : tendsto (λ x, f x + g x) l at_bot) :\n  tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right' _ βᵒᵈ _ _ _ _ C hC h\n\nlemma tendsto_at_top_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) :\n  tendsto (λ x, f x + g x) l at_top → 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 : ∀ x, C ≤ g x) :\n  tendsto (λ x, f x + g x) l at_bot → tendsto f l at_bot :=\n@tendsto_at_top_of_add_bdd_above_right _ βᵒᵈ _ _ _ _ C hC\n\nend ordered_cancel_add_comm_monoid\n\nsection ordered_group\n\nvariables [ordered_add_comm_group β] (l : filter α) {f g : α → β}\n\nlemma tendsto_at_top_add_left_of_le' (C : β) (hf : ∀ᶠ x in l, C ≤ f x) (hg : tendsto g l at_top) :\n  tendsto (λ x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_left' _ _ _ l (λ x, -(f x)) (λ x, f x + g x) (-C)\n  (by simpa) (by simpa)\n\nlemma tendsto_at_bot_add_left_of_ge' (C : β) (hf : ∀ᶠ x in l, f x ≤ C) (hg : tendsto g l at_bot) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le' _ βᵒᵈ _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : tendsto g l at_top) :\n  tendsto (λ 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 : β) (hf : ∀ x, f x ≤ C) (hg : tendsto g l at_bot) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_left_of_le _ βᵒᵈ _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le' (C : β) (hf : tendsto f l at_top) (hg : ∀ᶠ x in l, C ≤ g x) :\n  tendsto (λ x, f x + g x) l at_top :=\n@tendsto_at_top_of_add_bdd_above_right' _ _ _ l (λ x, f x + g x) (λ x, -(g x)) (-C)\n  (by simp [hg]) (by simp [hf])\n\nlemma tendsto_at_bot_add_right_of_ge' (C : β) (hf : tendsto f l at_bot) (hg : ∀ᶠ x in l, g x ≤ C) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le' _ βᵒᵈ _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_right_of_le (C : β) (hf : tendsto f l at_top) (hg : ∀ x, C ≤ g x) :\n  tendsto (λ 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 : β) (hf : tendsto f l at_bot) (hg : ∀ x, g x ≤ C) :\n  tendsto (λ x, f x + g x) l at_bot :=\n@tendsto_at_top_add_right_of_le _ βᵒᵈ _ _ _ _ C hf hg\n\nlemma tendsto_at_top_add_const_left (C : β) (hf : tendsto f l at_top) :\n  tendsto (λ x, C + f x) l at_top :=\ntendsto_at_top_add_left_of_le' l C (univ_mem' $ λ _, le_refl C) hf\n\nlemma tendsto_at_bot_add_const_left (C : β) (hf : tendsto f l at_bot) :\n  tendsto (λ x, C + f x) l at_bot :=\n@tendsto_at_top_add_const_left _ βᵒᵈ _ _ _ C hf\n\nlemma tendsto_at_top_add_const_right (C : β) (hf : tendsto f l at_top) :\n  tendsto (λ x, f x + C) l at_top :=\ntendsto_at_top_add_right_of_le' l C hf (univ_mem' $ λ _, le_refl C)\n\nlemma tendsto_at_bot_add_const_right (C : β) (hf : tendsto f l at_bot) :\n  tendsto (λ x, f x + C) l at_bot :=\n@tendsto_at_top_add_const_right _ βᵒᵈ _ _ _ C hf\n\nlemma tendsto_neg_at_top_at_bot : tendsto (has_neg.neg : β → β) at_top at_bot :=\nbegin\n  simp only [tendsto_at_bot, neg_le],\n  exact λ b, eventually_ge_at_top _\nend\n\nlemma tendsto_neg_at_bot_at_top : tendsto (has_neg.neg : β → β) at_bot at_top :=\n@tendsto_neg_at_top_at_bot βᵒᵈ _\n\nlemma tendsto_at_top_iff_tends_to_neg_at_bot : tendsto f l at_top ↔ tendsto (-f) l at_bot :=\nhave hf : f = has_neg.neg ∘ -f, { ext, simp, },\n⟨tendsto_neg_at_top_at_bot.comp, λ h, hf.symm ▸ tendsto_neg_at_bot_at_top.comp h⟩\n\nlemma tendsto_at_bot_iff_tends_to_neg_at_top : tendsto f l at_bot ↔ tendsto (-f) l at_top :=\n@tendsto_at_top_iff_tends_to_neg_at_bot α βᵒᵈ _ l f\n\nend ordered_group\n\nsection ordered_semiring\n\nvariables [ordered_semiring α] {l : filter β} {f g : β → α}\n\nlemma tendsto_bit1_at_top : tendsto bit1 (at_top : filter α) at_top :=\ntendsto_at_top_add_nonneg_right tendsto_bit0_at_top (λ _, 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 (λ 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 (λ x : α, x * x) at_top at_top :=\ntendsto_id.at_top_mul_at_top tendsto_id\n\n/-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`.\nA version for positive real powers exists as `tendsto_rpow_at_top`. -/\nlemma tendsto_pow_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ n) at_top at_top :=\nbegin\n  refine tendsto_at_top_mono' _ ((eventually_ge_at_top 1).mono $ λ 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 α] :\n  (λ n : ℕ, (0 : α) ^ n) =ᶠ[at_top] (λ n, 0) :=\neventually_at_top.2 ⟨1, λ n hn, zero_pow (zero_lt_one.trans_le hn)⟩\n\nsection ordered_ring\n\nvariables [ordered_ring α] {l : filter β} {f g : β → α}\n\nlemma tendsto.at_top_mul_at_bot (hf : tendsto f l at_top) (hg : tendsto g l at_bot) :\n  tendsto (λ 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 [(∘), 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 (λ x, f x * g x) l at_bot :=\nhave tendsto (λ 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 [(∘), 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 (λ x, f x * g x) l at_top :=\nhave tendsto (λ 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 α]\n\n/-- $\\lim_{x\\to+\\infty}|x|=+\\infty$ -/\nlemma tendsto_abs_at_top_at_top : tendsto (abs : α → α) 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 : α → α) 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 : α → α) at_top = at_bot ⊔ 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 ⟨a, b⟩ -,\n  refine ⟨max (-a) b, trivial, λ x hx, _⟩,\n  rw [mem_preimage, mem_Ici, le_abs', max_le_iff, ← 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 α] {l : filter β} {f : β → α}\n\nlemma tendsto.at_top_of_const_mul {c : α} (hc : 0 < c) (hf : tendsto (λ x, c * f x) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ λ b, (tendsto_at_top.1 hf (c * b)).mono $ λ x hx, le_of_mul_le_mul_left hx hc\n\nlemma tendsto.at_top_of_mul_const {c : α} (hc : 0 < c) (hf : tendsto (λ x, f x * c) l at_top) :\n  tendsto f l at_top :=\ntendsto_at_top.2 $ λ b, (tendsto_at_top.1 hf (b * c)).mono $ λ 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 α] {a : α}\n  (h : ∀ᶠ n in at_top, 0 ≤ a ^ (n : ℕ)) : 0 ≤ a :=\nlet ⟨n, hn⟩ := (tendsto_bit1_at_top.eventually h).exists in pow_bit1_nonneg_iff.1 hn\n\nsection linear_ordered_field\n\nvariables [linear_ordered_field α] {l : filter β} {f : β → α} {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. For a version working in `ℕ` or `ℤ`, 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 (λx, 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 `ℕ` or `ℤ`, 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 (λx, 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 (λx, 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 (λ x, r * f x) l at_bot :=\nby simpa only [(∘), 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 (λ 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 (λx, r * f x) l at_bot :=\nby simpa only [(∘), 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 (λx, 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 (λx, 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 (λ x, r * f x) l at_top :=\nby simpa only [(∘), 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 (λ 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 : α} {n : ℕ}\n  (hn : 1 ≤ n) (hc : 0 < c) : tendsto (λ 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 : α) (n : ℕ) :\n  tendsto (λ x, c * x^n) at_top at_top ↔ 1 ≤ n ∧ 0 < c :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_const_mul_pow_at_top h.1 h.2⟩,\n  simp only [tendsto_at_top, eventually_at_top] at h,\n  have : 0 < c := let ⟨x, hx⟩ := 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 ⟨nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (λ hn, _))), this⟩,\n  obtain ⟨x, hx⟩ := 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 : α} {n : ℕ}\n  (hn : 1 ≤ n) (hc : c < 0) : tendsto (λ 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 : α) (n : ℕ) :\n  tendsto (λ x, c * x^n) at_top at_bot ↔ 1 ≤ n ∧ c < 0 :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_neg_const_mul_pow_at_top h.1 h.2⟩,\n  simp only [tendsto_at_bot, eventually_at_top] at h,\n  have : c < 0 := let ⟨x, hx⟩ := 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 ⟨nat.succ_le_iff.mp (lt_of_le_of_ne (zero_le n) (ne.symm (λ hn, _))), this⟩,\n  obtain ⟨x, hx⟩ := 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 α] [semilattice_sup α] {f : α → β} {l : filter β} :\n  tendsto f at_top l ↔ (∀s ∈ l, ∃a, ∀b≥a, f b ∈ s) :=\nby simp only [tendsto_def, mem_at_top_sets]; refl\n\nlemma tendsto_at_bot' [nonempty α] [semilattice_inf α] {f : α → β} {l : filter β} :\n  tendsto f at_bot l ↔ (∀s ∈ l, ∃a, ∀b≤a, f b ∈ s) :=\n@tendsto_at_top' αᵒᵈ _ _ _ _ _\n\ntheorem tendsto_at_top_principal [nonempty β] [semilattice_sup β] {f : β → α} {s : set α} :\n  tendsto f at_top (𝓟 s) ↔ ∃N, ∀n≥N, f n ∈ s :=\nby rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_at_top_sets]; refl\n\ntheorem tendsto_at_bot_principal [nonempty β] [semilattice_inf β] {f : β → α} {s : set α} :\n  tendsto f at_bot (𝓟 s) ↔ ∃N, ∀n≤N, f n ∈ s :=\n@tendsto_at_top_principal _ βᵒᵈ _ _ _ _\n\n/-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_top_at_top [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} :\n  tendsto f at_top at_top ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=\niff.trans tendsto_infi $ forall_congr $ assume b, tendsto_at_top_principal\n\nlemma tendsto_at_top_at_bot [nonempty α] [semilattice_sup α] [preorder β] {f : α → β} :\n  tendsto f at_top at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), i ≤ a → f a ≤ b :=\n@tendsto_at_top_at_top α βᵒᵈ _ _ _ f\n\nlemma tendsto_at_bot_at_top [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} :\n  tendsto f at_bot at_top ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), a ≤ i → b ≤ f a :=\n@tendsto_at_top_at_top αᵒᵈ β _ _ _ f\n\nlemma tendsto_at_bot_at_bot [nonempty α] [semilattice_inf α] [preorder β] {f : α → β} :\n  tendsto f at_bot at_bot ↔ ∀ (b : β), ∃ (i : α), ∀ (a : α), a ≤ i → f a ≤ b :=\n@tendsto_at_top_at_top αᵒᵈ βᵒᵈ _ _ _ f\n\nlemma tendsto_at_top_at_top_of_monotone [preorder α] [preorder β] {f : α → β} (hf : monotone f)\n  (h : ∀ b, ∃ a, b ≤ f a) :\n  tendsto f at_top at_top :=\ntendsto_infi.2 $ λ b, tendsto_principal.2 $ let ⟨a, ha⟩ := h b in\nmem_of_superset (mem_at_top a) $ λ a' ha', le_trans ha (hf ha')\n\nlemma tendsto_at_bot_at_bot_of_monotone [preorder α] [preorder β] {f : α → β} (hf : monotone f)\n  (h : ∀ b, ∃ a, f a ≤ b) :\n  tendsto f at_bot at_bot :=\ntendsto_infi.2 $ λ b, tendsto_principal.2 $ let ⟨a, ha⟩ := h b in\nmem_of_superset (mem_at_bot a) $ λ a' ha', le_trans (hf ha') ha\n\nlemma tendsto_at_top_at_top_iff_of_monotone [nonempty α] [semilattice_sup α] [preorder β]\n  {f : α → β} (hf : monotone f) :\n  tendsto f at_top at_top ↔ ∀ b : β, ∃ a : α, b ≤ f a :=\ntendsto_at_top_at_top.trans $ forall_congr $ λ b, exists_congr $ λ a,\n  ⟨λ h, h a (le_refl a), λ h a' ha', le_trans h $ hf ha'⟩\n\nlemma tendsto_at_bot_at_bot_iff_of_monotone [nonempty α] [semilattice_inf α] [preorder β]\n  {f : α → β} (hf : monotone f) :\n  tendsto f at_bot at_bot ↔ ∀ b : β, ∃ a : α, f a ≤ b :=\ntendsto_at_bot_at_bot.trans $ forall_congr $ λ b, exists_congr $ λ a,\n  ⟨λ h, h a (le_refl a), λ h a' ha', le_trans (hf ha') h⟩\n\nalias tendsto_at_top_at_top_of_monotone ← monotone.tendsto_at_top_at_top\nalias tendsto_at_bot_at_bot_of_monotone ← monotone.tendsto_at_bot_at_bot\nalias tendsto_at_top_at_top_iff_of_monotone ← monotone.tendsto_at_top_at_top_iff\nalias tendsto_at_bot_at_bot_iff_of_monotone ← monotone.tendsto_at_bot_at_bot_iff\n\nlemma comap_embedding_at_top [preorder β] [preorder γ] {e : β → γ}\n  (hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, c ≤ e b) :\n  comap e at_top = at_top :=\nle_antisymm\n  (le_infi $ λ b, le_principal_iff.2 $ mem_comap.2 ⟨Ici (e b), mem_at_top _, λ x, (hm _ _).1⟩)\n  (tendsto_at_top_at_top_of_monotone (λ _ _, (hm _ _).2) hu).le_comap\n\nlemma comap_embedding_at_bot [preorder β] [preorder γ] {e : β → γ}\n  (hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, e b ≤ c) :\n  comap e at_bot = at_bot :=\n@comap_embedding_at_top βᵒᵈ γᵒᵈ _ _ e (function.swap hm) hu\n\nlemma tendsto_at_top_embedding [preorder β] [preorder γ]\n  {f : α → β} {e : β → γ} {l : filter α}\n  (hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, c ≤ e b) :\n  tendsto (e ∘ f) l at_top ↔ tendsto f l at_top :=\nby rw [← comap_embedding_at_top hm hu, tendsto_comap_iff]\n\n/-- A function `f` goes to `-∞` independent of an order-preserving embedding `e`. -/\nlemma tendsto_at_bot_embedding [preorder β] [preorder γ]\n  {f : α → β} {e : β → γ} {l : filter α}\n  (hm : ∀b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀c, ∃b, e b ≤ c) :\n  tendsto (e ∘ f) l at_bot ↔ tendsto f l at_bot :=\n@tendsto_at_top_embedding α βᵒᵈ γᵒᵈ _ _ 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 α) = ⨅ x : α, 𝓟 (Ici {x}) :=\nbegin\n  refine le_antisymm (le_infi (λ i, le_principal_iff.2 $ mem_at_top {i})) _,\n  refine le_infi (λ s, le_principal_iff.2 $ mem_infi_of_Inter s.finite_to_set\n                  (λ 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 λ 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 β]\n  {f : β → finset α} (h : monotone f) (h' : ∀ x : α, ∃ n, x ∈ 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 ⟨b, hb⟩,\n  exact eventually.mono (mem_at_top b)\n    (λ b' hb', le_trans (finset.singleton_subset_iff.2 hb) (h hb')),\nend\n\nalias tendsto_at_top_finset_of_monotone ← monotone.tendsto_at_top_finset\n\nlemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (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  ⟨{i a}, by simp only [finset.image_singleton, h a, finset.mem_singleton]⟩\n\nlemma tendsto_finset_preimage_at_top_at_top {f : α → β} (hf : function.injective f) :\n  tendsto (λ s : finset β, s.preimage f (hf.inj_on _)) at_top at_top :=\n(finset.monotone_preimage hf).tendsto_at_top_finset $\n  λ x, ⟨{f x}, finset.mem_preimage.2 $ finset.mem_singleton_self _⟩\n\nlemma prod_at_top_at_top_eq {β₁ β₂ : Type*} [semilattice_sup β₁] [semilattice_sup β₂] :\n  (at_top : filter β₁) ×ᶠ (at_top : filter β₂) = (at_top : filter (β₁ × β₂)) :=\nbegin\n  casesI (is_empty_or_nonempty β₁).symm,\n  casesI (is_empty_or_nonempty β₂).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 {β₁ β₂ : Type*} [semilattice_inf β₁] [semilattice_inf β₂] :\n  (at_bot : filter β₁) ×ᶠ (at_bot : filter β₂) = (at_bot : filter (β₁ × β₂)) :=\n@prod_at_top_at_top_eq β₁ᵒᵈ β₂ᵒᵈ _ _\n\nlemma prod_map_at_top_eq {α₁ α₂ β₁ β₂ : Type*} [semilattice_sup β₁] [semilattice_sup β₂]\n  (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) :\n  (map u₁ at_top) ×ᶠ (map u₂ at_top) = map (prod.map u₁ u₂) at_top :=\nby rw [prod_map_map_eq, prod_at_top_at_top_eq, prod.map_def]\n\nlemma prod_map_at_bot_eq {α₁ α₂ β₁ β₂ : Type*} [semilattice_inf β₁] [semilattice_inf β₂]\n  (u₁ : β₁ → α₁) (u₂ : β₂ → α₂) :\n  (map u₁ at_bot) ×ᶠ (map u₂ at_bot) = map (prod.map u₁ u₂) at_bot :=\n@prod_map_at_top_eq _ _ β₁ᵒᵈ β₂ᵒᵈ _ _ _ _\n\nlemma tendsto.subseq_mem {F : filter α} {V : ℕ → set α} (h : ∀ n, V n ∈ F) {u : ℕ → α}\n  (hu : tendsto u at_top F) : ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ n, u (φ n) ∈ V n :=\nextraction_forall_of_eventually' (λ n, tendsto_at_top'.mp hu _ (h n) : ∀ n, ∃ N, ∀ k ≥ N, u k ∈ V n)\n\nlemma tendsto_at_bot_diagonal [semilattice_inf α] : tendsto (λ a : α, (a, a)) at_bot at_bot :=\nby { rw ← prod_at_bot_at_bot_eq, exact tendsto_id.prod_mk tendsto_id }\n\nlemma tendsto_at_top_diagonal [semilattice_sup α] : tendsto (λ a : α, (a, a)) at_top at_top :=\nby { rw ← prod_at_top_at_top_eq, exact tendsto_id.prod_mk tendsto_id }\n\nlemma tendsto.prod_map_prod_at_bot [semilattice_inf γ] {F : filter α} {G : filter β}\n  {f : α → γ} {g : β → γ} (hf : tendsto f F at_bot) (hg : tendsto g G at_bot) :\n  tendsto (prod.map f g) (F ×ᶠ G) at_bot :=\nby { rw ← prod_at_bot_at_bot_eq, exact hf.prod_map hg, }\n\nlemma tendsto.prod_map_prod_at_top [semilattice_sup γ] {F : filter α} {G : filter β}\n  {f : α → γ} {g : β → γ} (hf : tendsto f F at_top) (hg : tendsto g G at_top) :\n  tendsto (prod.map f g) (F ×ᶠ G) at_top :=\nby { rw ← prod_at_top_at_top_eq, exact hf.prod_map hg, }\n\nlemma tendsto.prod_at_bot [semilattice_inf α] [semilattice_inf γ]\n  {f g : α → γ} (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 ← prod_at_bot_at_bot_eq, exact hf.prod_map_prod_at_bot hg, }\n\nlemma tendsto.prod_at_top [semilattice_sup α] [semilattice_sup γ]\n  {f g : α → γ} (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 ← prod_at_top_at_top_eq, exact hf.prod_map_prod_at_top hg, }\n\nlemma eventually_at_bot_prod_self [semilattice_inf α] [nonempty α] {p : α × α → Prop} :\n  (∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ k l, k ≤ a → l ≤ a → p (k, l)) :=\nby simp [← prod_at_bot_at_bot_eq, at_bot_basis.prod_self.eventually_iff]\n\nlemma eventually_at_top_prod_self [semilattice_sup α] [nonempty α] {p : α × α → Prop} :\n  (∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ k l, a ≤ k → a ≤ l → p (k, l)) :=\nby simp [← prod_at_top_at_top_eq, at_top_basis.prod_self.eventually_iff]\n\nlemma eventually_at_bot_prod_self' [semilattice_inf α] [nonempty α] {p : α × α → Prop} :\n  (∀ᶠ x in at_bot, p x) ↔ (∃ a, ∀ k ≤ a, ∀ l ≤ 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 α] [nonempty α] {p : α × α → Prop} :\n  (∀ᶠ x in at_top, p x) ↔ (∃ a, ∀ k ≥ a, ∀ l ≥ 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 α] [semilattice_sup β] {p : α × β → Prop}\n  (hp : ∀ᶠ (x : α × β) in filter.at_top, p x) :\n  ∀ᶠ k in at_top, ∀ᶠ l in at_top, p (k, l) :=\nbegin\n  rw ← prod_at_top_at_top_eq at hp,\n  exact hp.curry,\nend\n\nlemma eventually_at_bot_curry [semilattice_inf α] [semilattice_inf β] {p : α × β → Prop}\n  (hp : ∀ᶠ (x : α × β) in filter.at_bot, p x) :\n  ∀ᶠ k in at_bot, ∀ᶠ l in at_bot, p (k, l) :=\n@eventually_at_top_curry αᵒᵈ βᵒᵈ _ _ _ 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 α] [semilattice_sup β] {f : α → β} (g : β → α) (b' : β)\n  (hf : monotone f) (gc : ∀a, ∀b≥b', f a ≤ b ↔ a ≤ g b) (hgi : ∀b≥b', b ≤ f (g b)) :\n  map f at_top = at_top :=\nbegin\n  refine le_antisymm\n    (hf.tendsto_at_top_at_top $ λ b, ⟨g (b ⊔ b'), le_sup_left.trans $ hgi _ le_sup_right⟩) _,\n  rw [@map_at_top_eq _ _ ⟨g b'⟩],\n  refine le_infi (λ a, infi_le_of_le (f a ⊔ b') $ principal_mono.2 $ λ b hb, _),\n  rw [mem_Ici, sup_le_iff] at hb,\n  exact ⟨g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 le_rfl) (hgi _ hb.2)⟩\nend\n\nlemma map_at_bot_eq_of_gc [semilattice_inf α] [semilattice_inf β] {f : α → β} (g : β → α) (b' : β)\n  (hf : monotone f) (gc : ∀a, ∀b≤b', b ≤ f a ↔ g b ≤ a) (hgi : ∀b≤b', f (g b) ≤ b) :\n  map f at_bot = at_bot :=\n@map_at_top_eq_of_gc αᵒᵈ βᵒᵈ _ _ _ _ _ hf.dual gc hgi\n\nlemma map_coe_at_top_of_Ici_subset [semilattice_sup α] {a : α} {s : set α} (h : Ici a ⊆ s) :\n  map (coe : s → α) at_top = at_top :=\nbegin\n  have : directed (≥) (λ x : s, 𝓟 (Ici x)),\n  { intros x y,\n    use ⟨x ⊔ y ⊔ a, h le_sup_right⟩,\n    simp only [ge_iff_le, principal_mono, Ici_subset_Ici, ← subtype.coe_le_coe, subtype.coe_mk],\n    exact ⟨le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left⟩ },\n  haveI : nonempty s := ⟨⟨a, h le_rfl⟩⟩,\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 ⟨x ⊔ a, h le_sup_right⟩ (mem_principal_self _)) _,\n    rintro _ ⟨y, hy, rfl⟩,\n    exact le_trans le_sup_left (subtype.coe_le_coe.2 hy) },\n  { intro x,\n    filter_upwards [mem_at_top (↑x ⊔ a)] with b hb,\n    exact ⟨⟨b, h $ le_sup_right.trans hb⟩, subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl⟩, },\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 α] (a : α) :\n  map (coe : Ici a → α) 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 α] [no_max_order α] (a : α) :\n  map (coe : Ioi a → α) at_top = at_top :=\nlet ⟨b, hb⟩ := 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 α] (a : α) :\n  at_top = comap (coe : Ioi a → α) at_top :=\nbegin\n  nontriviality,\n  rcases nontrivial_iff_nonempty.1 ‹_› with ⟨b, hb⟩,\n  rw [← 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 α] (a : α) :\n  at_top = comap (coe : Ici a → α) at_top :=\nby rw [← 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 α] [no_min_order α] (a : α) :\n  map (coe : Iio a → α) at_bot = at_bot :=\n@map_coe_Ioi_at_top αᵒᵈ _ _ _\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 α] (a : α) : at_bot = comap (coe : Iio a → α) at_bot :=\n@at_top_Ioi_eq αᵒᵈ _ _\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 α] (a : α) :\n  map (coe : Iic a → α) at_bot = at_bot :=\n@map_coe_Ici_at_top αᵒᵈ _ _\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 α] (a : α) :\n  at_bot = comap (coe : Iic a → α) at_bot :=\n@at_top_Ici_eq αᵒᵈ _ _\n\nlemma tendsto_Ioi_at_top [semilattice_sup α] {a : α} {f : β → Ioi a}\n  {l : filter β} :\n  tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l at_top :=\nby rw [at_top_Ioi_eq, tendsto_comap_iff]\n\nlemma tendsto_Iio_at_bot [semilattice_inf α] {a : α} {f : β → Iio a}\n  {l : filter β} :\n  tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l at_bot :=\nby rw [at_bot_Iio_eq, tendsto_comap_iff]\n\nlemma tendsto_Ici_at_top [semilattice_sup α] {a : α} {f : β → Ici a} {l : filter β} :\n  tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l at_top :=\nby rw [at_top_Ici_eq, tendsto_comap_iff]\n\nlemma tendsto_Iic_at_bot [semilattice_inf α] {a : α} {f : β → Iic a} {l : filter β} :\n  tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l at_bot :=\nby rw [at_bot_Iic_eq, tendsto_comap_iff]\n\n@[simp] lemma tendsto_comp_coe_Ioi_at_top [semilattice_sup α] [no_max_order α] {a : α}\n  {f : α → β} {l : filter β} :\n  tendsto (λ x : Ioi a, f x) at_top l ↔ tendsto f at_top l :=\nby rw [← map_coe_Ioi_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Ici_at_top [semilattice_sup α] {a : α}\n  {f : α → β} {l : filter β} :\n  tendsto (λ x : Ici a, f x) at_top l ↔ tendsto f at_top l :=\nby rw [← map_coe_Ici_at_top a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iio_at_bot [semilattice_inf α] [no_min_order α] {a : α}\n  {f : α → β} {l : filter β} :\n  tendsto (λ x : Iio a, f x) at_bot l ↔ tendsto f at_bot l :=\nby rw [← map_coe_Iio_at_bot a, tendsto_map'_iff]\n\n@[simp] lemma tendsto_comp_coe_Iic_at_bot [semilattice_inf α] {a : α}\n  {f : α → β} {l : filter β} :\n  tendsto (λ x : Iic a, f x) at_bot l ↔ tendsto f at_bot l :=\nby rw [← map_coe_Iic_at_bot a, tendsto_map'_iff]\n\nlemma map_add_at_top_eq_nat (k : ℕ) : map (λa, a + k) at_top = at_top :=\nmap_at_top_eq_of_gc (λa, 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 : ℕ) : map (λa, a - k) at_top = at_top :=\nmap_at_top_eq_of_gc (λa, 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 : ℕ) : tendsto (λa, a + k) at_top at_top :=\nle_of_eq (map_add_at_top_eq_nat k)\n\nlemma tendsto_sub_at_top_nat (k : ℕ) : tendsto (λa, 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 : ℕ → α} {l : filter α} (k : ℕ) :\n  tendsto (λn, f (n + k)) at_top l ↔ tendsto f at_top l :=\nshow tendsto (f ∘ (λn, n + k)) at_top l ↔ tendsto f at_top l,\n  by rw [← tendsto_map'_iff, map_add_at_top_eq_nat]\n\nlemma map_div_at_top_eq_nat (k : ℕ) (hk : 0 < k) : map (λa, a / k) at_top = at_top :=\nmap_at_top_eq_of_gc (λb, b * k + (k - 1)) 1\n  (assume a b h, nat.div_le_div_right h)\n  (assume a b _,\n    calc a / k ≤ b ↔ a / k < b + 1 : by rw [← nat.succ_eq_add_one, nat.lt_succ_iff]\n      ... ↔ a < (b + 1) * k : nat.div_lt_iff_lt_mul hk\n      ... ↔ _ :\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      ... ≤ (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 ι] [linear_order α]\n  {u : ι → α} (h : monotone u) (H : ¬bdd_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 ⟨_, ⟨N, rfl⟩, hN⟩,\n  exact ⟨N, le_of_lt hN⟩,\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 ι] [linear_order α]\n  {u : ι → α} (h : monotone u) (H : ¬bdd_below (range u)) :\n  tendsto u at_bot at_bot :=\n@tendsto_at_top_at_top_of_monotone' ιᵒᵈ αᵒᵈ _ _ _ h.dual H\n\nlemma unbounded_of_tendsto_at_top [nonempty α] [semilattice_sup α] [preorder β] [no_max_order β]\n  {f : α → β} (h : tendsto f at_top at_top) :\n  ¬ bdd_above (range f) :=\nbegin\n  rintros ⟨M, hM⟩,\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  ... ≤ M : hM (set.mem_range_self a)\nend\n\nlemma unbounded_of_tendsto_at_bot [nonempty α] [semilattice_sup α] [preorder β] [no_min_order β]\n  {f : α → β} (h : tendsto f at_top at_bot) :\n  ¬ bdd_below (range f) :=\n@unbounded_of_tendsto_at_top _ βᵒᵈ _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_top' [nonempty α] [semilattice_inf α] [preorder β] [no_max_order β]\n  {f : α → β} (h : tendsto f at_bot at_top) :\n  ¬ bdd_above (range f) :=\n@unbounded_of_tendsto_at_top αᵒᵈ _ _ _ _ _ _ h\n\nlemma unbounded_of_tendsto_at_bot' [nonempty α] [semilattice_inf α] [preorder β] [no_min_order β]\n  {f : α → β} (h : tendsto f at_bot at_bot) :\n  ¬ bdd_below (range f) :=\n@unbounded_of_tendsto_at_top αᵒᵈ βᵒᵈ _ _ _ _ _ h\n\n/-- If a monotone function `u : ι → α` 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 ι] [preorder α] {l : filter ι}\n  {u : ι → α} (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 $ λ b, (hu.eventually (mem_at_top b)).exists\n\n/-- If a monotone function `u : ι → α` 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 ι] [preorder α] {l : filter ι}\n  {u : ι → α} (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 ιᵒᵈ αᵒᵈ _ _ _ _ h.dual _ hu\n\nlemma tendsto_at_top_of_monotone_of_subseq [preorder ι] [preorder α] {u : ι → α}\n  {φ : ι' → ι} (h : monotone u) {l : filter ι'} [ne_bot l]\n  (H : tendsto (u ∘ φ) 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 ι] [preorder α] {u : ι → α}\n  {φ : ι' → ι} (h : monotone u) {l : filter ι'} [ne_bot l]\n  (H : tendsto (u ∘ φ) 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 (λ s, ∏ b in s, f b)` with\n`at_top.map (λ s, ∏ b in s, g b)`. This is useful to compare the set of limit points of\n`Π b in s, f b` as `s → at_top` with the similar set for `g`. -/\n@[to_additive \"Let `f` and `g` be two maps to the same commutative additive monoid. This lemma gives\na sufficient condition for comparison of the filter `at_top.map (λ s, ∑ b in s, f b)` with\n`at_top.map (λ s, ∑ b in s, g b)`. This is useful to compare the set of limit points of\n`∑ b in s, f b` as `s → at_top` with the similar set for `g`.\"]\nlemma map_at_top_finset_prod_le_of_prod_eq [comm_monoid α] {f : β → α} {g : γ → α}\n  (h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∏ x in u', g x = ∏ b in v', f b) :\n  at_top.map (λs:finset β, ∏ b in s, f b) ≤ at_top.map (λs:finset γ, ∏ x in s, g x) :=\nby rw [map_at_top_eq, map_at_top_eq];\nfrom (le_infi $ assume b, let ⟨v, hv⟩ := h_eq b in infi_le_of_le v $\n  by simp [set.image_subset_iff]; exact hv)\n\nlemma has_antitone_basis.eventually_subset [preorder ι] {l : filter α}\n  {s : ι → set α} (hl : l.has_antitone_basis s) {t : set α} (ht : t ∈ l) :\n  ∀ᶠ i in at_top, s i ⊆ t :=\nlet ⟨i, _, hi⟩ := hl.to_has_basis.mem_iff.1 ht\nin (eventually_ge_at_top i).mono $ λ j hj, (hl.antitone hj).trans hi\n\nprotected lemma has_antitone_basis.tendsto [preorder ι] {l : filter α}\n  {s : ι → set α} (hl : l.has_antitone_basis s) {φ : ι → α}\n  (h : ∀ i : ι, φ i ∈ s i) : tendsto φ at_top l  :=\nλ t ht, mem_map.2 $ (hl.eventually_subset ht).mono $ λ i hi, hi (h i)\n\nlemma has_antitone_basis.comp_mono [semilattice_sup ι] [nonempty ι] [preorder ι'] {l : filter α}\n  {s : ι' → set α} (hs : l.has_antitone_basis s)\n  {φ : ι → ι'} (φ_mono : monotone φ) (hφ : tendsto φ at_top at_top) :\n  l.has_antitone_basis (s ∘ φ) :=\n⟨hs.to_has_basis.to_has_basis\n  (λ n hn, (hφ.eventually (eventually_ge_at_top n)).exists.imp $ λ m hm, ⟨trivial, hs.antitone hm⟩)\n  (λ n hn, ⟨φ n, trivial, subset.rfl⟩), hs.antitone.comp_monotone φ_mono⟩\n\nlemma has_antitone_basis.comp_strict_mono {l : filter α} {s : ℕ → set α}\n  (hs : l.has_antitone_basis s) {φ : ℕ → ℕ} (hφ : strict_mono φ) :\n  l.has_antitone_basis (s ∘ φ) :=\nhs.comp_mono hφ.monotone hφ.tendsto_at_top\n\n/-- Given an antitone basis `s : ℕ → set α` of a filter, extract an antitone subbasis `s ∘ φ`,\n`φ : ℕ → ℕ`, such that `m < n` implies `r (φ m) (φ n)`. This lemma can be used to extract an\nantitone basis with basis sets decreasing \"sufficiently fast\". -/\nlemma has_antitone_basis.subbasis_with_rel {f : filter α} {s : ℕ → set α}\n  (hs : f.has_antitone_basis s) {r : ℕ → ℕ → Prop} (hr : ∀ m, ∀ᶠ n in at_top, r m n) :\n  ∃ φ : ℕ → ℕ, strict_mono φ ∧ (∀ ⦃m n⦄, m < n → r (φ m) (φ n)) ∧ f.has_antitone_basis (s ∘ φ) :=\nbegin\n  suffices : ∃ φ : ℕ → ℕ, strict_mono φ ∧ ∀ m n, m < n → r (φ m) (φ n),\n  { rcases this with ⟨φ, hφ, hrφ⟩,\n    exact ⟨φ, hφ, hrφ, hs.comp_strict_mono hφ⟩ },\n  have : ∀ t : set ℕ, t.finite → ∀ᶠ n in at_top, ∀ m ∈ t, m < n ∧ r m n,\n    from λ t ht, (eventually_all_finite ht).2 (λ m hm, (eventually_gt_at_top m).and (hr _)),\n  rcases seq_of_forall_finite_exists (λ t ht, (this t ht).exists) with ⟨φ, hφ⟩,\n  simp only [ball_image_iff, forall_and_distrib, mem_Iio] at hφ,\n  exact ⟨φ, forall_swap.2 hφ.1, forall_swap.2 hφ.2⟩\nend\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 α) [is_countably_generated f] [ne_bot f] :\n  ∃ x : ℕ → α, tendsto x at_top f :=\nbegin\n  obtain ⟨B, h⟩ := f.exists_antitone_basis,\n  choose x hx using λ n, filter.nonempty_of_mem (h.mem n),\n  exact ⟨x, h.tendsto hx⟩\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 ∘ u` tends to `l`. -/\nlemma tendsto_iff_seq_tendsto {f : α → β} {k : filter α} {l : filter β} [k.is_countably_generated] :\n  tendsto f k l ↔ (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) :=\nbegin\n  refine ⟨λ h x hx, h.comp hx, λ H s hs, _⟩,\n  contrapose! H,\n  haveI : ne_bot (k ⊓ 𝓟 (f ⁻¹' sᶜ)), by simpa [ne_bot_iff,  inf_principal_eq_bot],\n  rcases (k ⊓ 𝓟 (f ⁻¹' sᶜ)).exists_seq_tendsto with ⟨x, hx⟩,\n  rw [tendsto_inf, tendsto_principal] at hx,\n  refine ⟨x, hx.1, λ h, _⟩,\n  rcases (hx.2.and (h hs)).exists with ⟨N, hnmem, hmem⟩,\n  exact hnmem hmem\nend\n\nlemma tendsto_of_seq_tendsto {f : α → β} {k : filter α} {l : filter β} [k.is_countably_generated] :\n  (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l :=\ntendsto_iff_seq_tendsto.2\n\nlemma tendsto_iff_forall_eventually_mem {α ι : Type*} {x : ι → α} {f : filter α} {l : filter ι} :\n  tendsto x l f ↔ ∀ s ∈ f, ∀ᶠ n in l, x n ∈ s :=\nby { rw tendsto_def, refine forall_congr (λ s, imp_congr_right (λ hsf, _)), refl, }\n\nlemma not_tendsto_iff_exists_frequently_nmem {α ι : Type*} {x : ι → α} {f : filter α}\n  {l : filter ι} :\n  ¬ tendsto x l f ↔ ∃ s ∈ f, ∃ᶠ n in l, x n ∉ s :=\nbegin\n  rw tendsto_iff_forall_eventually_mem,\n  push_neg,\n  refine exists_congr (λ s, _),\n  rw [not_eventually, exists_prop],\nend\n\nlemma frequently_iff_seq_frequently {ι : Type*} {l : filter ι} {p : ι → Prop}\n  [hl : l.is_countably_generated] :\n  (∃ᶠ n in l, p n) ↔ ∃ (x : ℕ → ι), tendsto x at_top l ∧ ∃ᶠ (n : ℕ) in at_top, p (x n) :=\nbegin\n  refine ⟨λ h_freq, _, λ h_exists_freq, _⟩,\n  { haveI : ne_bot (l ⊓ 𝓟 {x : ι | p x}), by simpa [ne_bot_iff, inf_principal_eq_bot],\n    obtain ⟨x, hx⟩ := exists_seq_tendsto (l ⊓ (𝓟 {x : ι | p x})),\n    rw tendsto_inf at hx,\n    cases hx with hx_l hx_p,\n    refine ⟨x, hx_l, _⟩,\n    rw tendsto_principal at hx_p,\n    exact hx_p.frequently, },\n  { obtain ⟨x, hx_tendsto, hx_freq⟩ := h_exists_freq,\n    simp_rw [filter.frequently, filter.eventually] at hx_freq ⊢,\n    have : {n : ℕ | ¬p (x n)} = {n | x n ∈ {y | ¬ p y}} := rfl,\n    rw [this, ← mem_map'] at hx_freq,\n    contrapose! hx_freq,\n    exact hx_tendsto hx_freq, },\nend\n\nlemma eventually_iff_seq_eventually {ι : Type*} {l : filter ι} {p : ι → Prop}\n  [hl : l.is_countably_generated] :\n  (∀ᶠ n in l, p n) ↔ ∀ (x : ℕ → ι), tendsto x at_top l → ∀ᶠ (n : ℕ) in at_top, p (x n) :=\nbegin\n  have : (∀ᶠ n in l, p n) ↔ ¬ ∃ᶠ n in l, ¬(p n),\n  { rw not_frequently, simp_rw not_not, },\n  rw [this, frequently_iff_seq_frequently],\n  push_neg,\n  simp_rw [not_frequently, not_not],\nend\n\nlemma subseq_forall_of_frequently {ι : Type*} {x : ℕ → ι} {p : ι → Prop} {l : filter ι}\n  (h_tendsto : tendsto x at_top l) (h : ∃ᶠ n in at_top, p (x n)) :\n  ∃ ns : ℕ → ℕ, tendsto (λ n, x (ns n)) at_top l ∧ ∀ n, p (x (ns n)) :=\nbegin\n  rw tendsto_iff_seq_tendsto at h_tendsto,\n  choose ns hge hns using frequently_at_top.1 h,\n  exact ⟨ns, h_tendsto ns (tendsto_at_top_mono hge tendsto_id), hns⟩,\nend\n\nlemma exists_seq_forall_of_frequently {ι : Type*} {l : filter ι} {p : ι → Prop}\n  [hl : l.is_countably_generated] (h : ∃ᶠ n in l, p n) :\n  ∃ ns : ℕ → ι, tendsto ns at_top l ∧ ∀ n, p (ns n) :=\nbegin\n  rw frequently_iff_seq_frequently at h,\n  obtain ⟨x, hx_tendsto, hx_freq⟩ := h,\n  obtain ⟨n_to_n, h_tendsto, h_freq⟩ := subseq_forall_of_frequently hx_tendsto hx_freq,\n  exact ⟨x ∘ n_to_n, h_tendsto, h_freq⟩,\nend\n\n/-- A sequence converges if every subsequence has a convergent subsequence. -/\nlemma tendsto_of_subseq_tendsto {α ι : Type*}\n  {x : ι → α} {f : filter α} {l : filter ι} [l.is_countably_generated]\n  (hxy : ∀ ns : ℕ → ι, tendsto ns at_top l →\n    ∃ ms : ℕ → ℕ, tendsto (λ n, x (ns $ ms n)) at_top f) :\n  tendsto x l f :=\nbegin\n  by_contra h,\n  obtain ⟨s, hs, hfreq⟩ : ∃ s ∈ f, ∃ᶠ n in l, x n ∉ s,\n    by rwa not_tendsto_iff_exists_frequently_nmem at h,\n  obtain ⟨y, hy_tendsto, hy_freq⟩ := exists_seq_forall_of_frequently hfreq,\n  specialize hxy y hy_tendsto,\n  obtain ⟨ms, hms_tendsto⟩ := hxy,\n  specialize hms_tendsto hs,\n  rw mem_map at hms_tendsto,\n  have hms_freq : ∀ (n : ℕ), x (y (ms n)) ∉ s, from λ n, hy_freq (ms n),\n  have h_empty : (λ (n : ℕ), x (y (ms n))) ⁻¹' s = ∅,\n  { ext1 n,\n    simp only [set.mem_preimage, set.mem_empty_eq, iff_false],\n    exact hms_freq n, },\n  rw h_empty at hms_tendsto,\n  exact empty_not_mem at_top hms_tendsto,\nend\n\nlemma subseq_tendsto_of_ne_bot {f : filter α} [is_countably_generated f] {u : ℕ → α}\n  (hx : ne_bot (f ⊓ map u at_top)) :\n  ∃ (θ : ℕ → ℕ), (strict_mono θ) ∧ (tendsto (u ∘ θ) at_top f) :=\nbegin\n  obtain ⟨B, h⟩ := f.exists_antitone_basis,\n  have : ∀ N, ∃ n ≥ N, u n ∈ B N,\n    from λ N, filter.inf_map_at_top_ne_bot_iff.mp hx _ (h.to_has_basis.mem_of_mem trivial) N,\n  choose φ hφ using this,\n  cases forall_and_distrib.mp hφ with φ_ge φ_in,\n  have lim_uφ : tendsto (u ∘ φ) at_top f,\n    from h.tendsto φ_in,\n  have lim_φ : tendsto φ at_top at_top,\n    from (tendsto_at_top_mono φ_ge tendsto_id),\n  obtain ⟨ψ, hψ, hψφ⟩ : ∃ ψ : ℕ → ℕ, strict_mono ψ ∧ strict_mono (φ ∘ ψ),\n    from strict_mono_subseq_of_tendsto_at_top lim_φ,\n  exact ⟨φ ∘ ψ, hψφ, lim_uφ.comp hψ.tendsto_at_top⟩,\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) : ∃ x ≥ 0, a < x * x :=\nlet ⟨x, hxa, hx0⟩ :=((tendsto_mul_self_at_top.eventually (eventually_gt_at_top a)).and\n  (eventually_ge_at_top 0)).exists\nin ⟨x, hx0, hxa⟩\n\nlemma exists_le_mul_self (a : R) : ∃ x ≥ 0, a ≤ x * x :=\nlet ⟨x, hx0, hxa⟩ := exists_lt_mul_self a in ⟨x, hx0, hxa.le⟩\n\nend\n\nnamespace order_iso\n\nvariables [preorder α] [preorder β]\n\n@[simp] lemma comap_at_top (e : α ≃o β) : comap e at_top = at_top :=\nby simp [at_top, ← e.surjective.infi_comp]\n\n@[simp] lemma comap_at_bot (e : α ≃o β) : comap e at_bot = at_bot :=\ne.dual.comap_at_top\n\n@[simp] lemma map_at_top (e : α ≃o β) : map (e : α → β) at_top = at_top :=\nby rw [← e.comap_at_top, map_comap_of_surjective e.surjective]\n\n@[simp] lemma map_at_bot (e : α ≃o β) : map (e : α → β) at_bot = at_bot :=\ne.dual.map_at_top\n\nlemma tendsto_at_top (e : α ≃o β) : tendsto e at_top at_top :=\ne.map_at_top.le\n\nlemma tendsto_at_bot (e : α ≃o β) : tendsto e at_bot at_bot :=\ne.map_at_bot.le\n\n@[simp] lemma tendsto_at_top_iff {l : filter γ} {f : γ → α} (e : α ≃o β) :\n  tendsto (λ x, e (f x)) l at_top ↔ tendsto f l at_top :=\nby rw [← e.comap_at_top, tendsto_comap_iff]\n\n@[simp] lemma tendsto_at_bot_iff {l : filter γ} {f : γ → α} (e : α ≃o β) :\n  tendsto (λ x, e (f x)) l at_bot ↔ tendsto f l at_bot :=\ne.dual.tendsto_at_top_iff\n\nend order_iso\n\n/-- Let `g : γ → β` be an injective function and `f : β → α` 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 (λ s, ∏ i in s, f (g i))` and `at_top.map (λ s, ∏ i in s, f i)` coincide.\n\nThe additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under\nthe same assumptions.-/\n@[to_additive]\nlemma function.injective.map_at_top_finset_prod_eq [comm_monoid α] {g : γ → β}\n  (hg : function.injective g) {f : β → α} (hf : ∀ x ∉ set.range g, f x = 1) :\n  map (λ s, ∏ i in s, f (g i)) at_top = map (λ s, ∏ i in s, f i) at_top :=\nbegin\n  apply le_antisymm; refine map_at_top_finset_prod_le_of_prod_eq (λ s, _),\n  { refine ⟨s.preimage g (hg.inj_on _), λ t ht, _⟩,\n    refine ⟨t.image g ∪ s, finset.subset_union_right _ _, _⟩,\n    rw [← 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 λ y hy hyt, hf y (mt _ hyt),\n    rintros ⟨x, rfl⟩,\n    exact ⟨x, ht (finset.mem_preimage.2 $ hy.resolve_left hyt), rfl⟩ },\n  { refine ⟨s.image g, λ t ht, _⟩,\n    simp only [← prod_preimage _ _ (hg.inj_on _) _ (λ x _, hf x)],\n    exact ⟨_, (image_subset_iff_subset_preimage _).1 ht, rfl⟩ }\nend\n\n/-- Let `g : γ → β` be an injective function and `f : β → α` 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 (λ s, ∑ i in s, f (g i))` and `at_top.map (λ s, ∑ i in s, f i)` coincide.\n\nThis lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under\nthe same assumptions.-/\nadd_decl_doc function.injective.map_at_top_finset_sum_eq\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/filter/at_top_bot.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.762808295057143}}
{"text": "import data.finset\nimport data.fintype.basic\nimport data.set.finite\nimport tactic.derive_fintype\n\n\nsection intro\n\nvariable {α : Type*}\n-- Конечность типа или множества представлена в mathlib тремя основными типами: `A : finset α`, `fintype A` и `finite A`\n\n-- 1. finset - конструктивно конечное множество\n-- `finset` = `multiset` + `nodup`\n-- `multiset` = классы эквивалентности `list` по отношению \"a - перестановка b\"\n-- Для того, чтобы применять большинство операций (добавление/объединение/...), нужен инстанс `decidable_eq α`: нужно уметь разрешимо сравнивать элементы (чтобы, например, знать `card`)\n\nvariable (A : finset α)\n\n#check A.card\n#reduce ({0,1,2,3} : finset ℕ).card\n#check @finset.card_insert_of_mem\n\n\n-- 2. fintype α - класс, говорящий о том, что α - конечный тип\n-- fintype α = (elems [] : finset α) (complete : ∀ x : α, x ∈ elems)\n-- Можно использовать @[derive fintype], для новосозданных `inductive`\n-- https://github.com/leanprover-community/mathlib/pull/3772\n\nvariable [fintype α]\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 (α : Type) [fintype α] : Type\n| c1 : bool → test\n| c2 : (fin 2) → (fin 3) → test\n| c3 : α × α → test\n\n-- 3. finite B - доказательство конечности множества B\n-- def finite (s : set α) : Prop := nonempty (fintype s)\n-- `nonempty (fintype s)` - Prop-версия того, что существует элемент типа `fintype s`\n-- `fintype s` - то же самое, что `fintype {x : α // x ∈ s}` или `fintype (subtype s)` - подтип `α` состоящий из пар `⟨x, h : x ∈ s⟩`\n-- Удобно использовать тогда, когда в API `finset` нет того, что хочется делать с множествами, а в `set` есть\n\nopen set\n\nvariables (β : Type) (B : set β) (hB : finite B)\n\n#check @finite.of_fintype\nend intro \n\n-- Докажем несколько лемм про `finset`\nnamespace finset\n\nvariables {α : Type} {A B : finset α} [decidable_eq α]\n\nlemma card_erase_of_mem' {x} (h : x ∈ A) : (A.erase x).card + 1 = A.card :=\nbegin\n  rw [card_erase_of_mem h, nat.add_one, nat.succ_pred_eq_of_pos],\n  refine card_pos.2 ⟨_, h⟩,\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/solutions/e00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7626976307254154}}
{"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 data.fintype.big_operators\nimport data.fintype.perm\nimport data.fintype.prod\nimport dynamics.fixed_points.basic\n\n/-!\n# Formalization of IMO 1987, Q1\n\nLet $p_{n, k}$ be the number of permutations of a set of cardinality `n ≥ 1` that fix exactly `k`\nelements. Prove that $∑_{k=0}^n k p_{n,k}=n!$.\n\nTo prove this identity, we show that both sides are equal to the cardinality of the set\n`{(x : α, σ : perm α) | σ x = x}`, regrouping by `card (fixed_points σ)` for the left hand side and\nby `x` for the right hand side.\n\nThe original problem assumes `n ≥ 1`. It turns out that a version with `n * (n - 1)!` in the RHS\nholds true for `n = 0` as well, so we first prove it, then deduce the original version in the case\n`n ≥ 1`. -/\n\nvariables (α : Type*) [fintype α] [decidable_eq α]\n\nopen_locale big_operators nat\nopen equiv fintype function finset (range sum_const) set (Iic)\n\nnamespace imo_1987_q1\n\n/-- The set of pairs `(x : α, σ : perm α)` such that `σ x = x` is equivalent to the set of pairs\n`(x : α, σ : perm {x}ᶜ)`. -/\ndef fixed_points_equiv :\n  {σx : α × perm α // σx.2 σx.1 = σx.1} ≃ Σ x : α, perm ({x}ᶜ : set α) :=\ncalc {σx : α × perm α // σx.2 σx.1 = σx.1} ≃ Σ x : α, {σ : perm α // σ x = x} :\n  set_prod_equiv_sigma _\n... ≃ Σ x : α, {σ : perm α // ∀ y : ({x} : set α), σ y = equiv.refl ↥({x} : set α) y} :\n  sigma_congr_right (λ x, equiv.set.of_eq $ by { simp only [set_coe.forall], dsimp, simp })\n... ≃ Σ x : α, perm ({x}ᶜ : set α) :\n  sigma_congr_right (λ x, by apply equiv.set.compl)\n\ntheorem card_fixed_points :\n  card {σx : α × perm α // σx.2 σx.1 = σx.1} = card α * (card α - 1)! :=\nby simp [card_congr (fixed_points_equiv α), card_perm, finset.filter_not, finset.card_sdiff,\n  finset.filter_eq', finset.card_univ]\n\n/-- Given `α : Type*` and `k : ℕ`, `fiber α k` is the set of permutations of `α` with exactly `k`\nfixed points. -/\n@[derive fintype]\ndef fiber (k : ℕ) : set (perm α) := {σ : perm α | card (fixed_points σ) = k}\n\n@[simp] lemma mem_fiber {σ : perm α} {k : ℕ} : σ ∈ fiber α k ↔ card (fixed_points σ) = k := iff.rfl\n\n/-- `p α k` is the number of permutations of `α` with exactly `k` fixed points. -/\ndef p (k : ℕ) := card (fiber α k)\n\n/-- The set of triples `(k ≤ card α, σ ∈ fiber α k, x ∈ fixed_points σ)` is equivalent\nto the set of pairs `(x : α, σ : perm α)` such that `σ x = x`. The equivalence sends\n`(k, σ, x)` to `(x, σ)` and `(x, σ)` to `(card (fixed_points σ), σ, x)`.\n\nIt is easy to see that the cardinality of the LHS is given by\n`∑ k : fin (card α + 1), k * p α k`. -/\ndef fixed_points_equiv' :\n  (Σ (k : fin (card α + 1)) (σ : fiber α k), fixed_points σ.1) ≃\n    {σx : α × perm α // σx.2 σx.1 = σx.1} :=\n{ to_fun := λ p, ⟨⟨p.2.2, p.2.1⟩, p.2.2.2⟩,\n  inv_fun := λ p,\n    ⟨⟨card (fixed_points p.1.2), (card_subtype_le _).trans_lt (nat.lt_succ_self _)⟩,\n     ⟨p.1.2, rfl⟩, ⟨p.1.1, p.2⟩⟩,\n  left_inv := λ ⟨⟨k, hk⟩, ⟨σ, hσ⟩, ⟨x, hx⟩⟩, by { simp only [mem_fiber, fin.coe_mk] at hσ,\n    subst k, refl },\n  right_inv := λ ⟨⟨x, σ⟩, h⟩, rfl }\n\n/-- Main statement for any `(α : Type*) [fintype α]`. -/\ntheorem main_fintype :\n  ∑ k in range (card α + 1), k * p α k = card α * (card α - 1)! :=\nhave A : ∀ k (σ : fiber α k), card (fixed_points ⇑(↑σ : perm α)) = k := λ k σ, σ.2,\nby simpa [A, ← fin.sum_univ_eq_sum_range, -card_of_finset, finset.card_univ,\n  card_fixed_points, mul_comm] using card_congr (fixed_points_equiv' α)\n\n/-- Main statement for permutations of `fin n`, a version that works for `n = 0`. -/\ntheorem main₀ (n : ℕ) :\n  ∑ k in range (n + 1), k * p (fin n) k = n * (n - 1)! :=\nby simpa using main_fintype (fin n)\n\n/-- Main statement for permutations of `fin n`. -/\ntheorem main {n : ℕ} (hn : 1 ≤ n) :\n  ∑ k in range (n + 1), k * p (fin n) k = n! :=\nby rw [main₀, nat.mul_factorial_pred (zero_lt_one.trans_le hn)]\n\nend imo_1987_q1\n", "meta": {"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/imo1987_q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818985, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7626976304423245}}
{"text": "import .lovelib\n\n\n/- # LoVe Demo 13: Rational and Real Numbers\n\nWe review the construction of `ℚ` and `ℝ` as quotient types.\n\nA procedure to construct types with specific properties:\n\n1. Create a new type that can represent all elements, but not necessarily in a\n   unique manner.\n\n2. Quotient this representation, equating elements that should be equal.\n\n3. Define operators on the quotient type by lifting functions from the base\n   type and prove that they are compatible with the quotient relation.\n\nWe used this approach in lecture 11 to construct `ℤ`. It can be used for\n`ℚ` and `ℝ` as well. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/- ## Rational Numbers\n\n**Step 1:** A rational number is a number that can be expressed as a fraction\n`n / d` of integers `n` and `d ≠ 0`: -/\n\nstructure fraction :=\n(num           : ℤ)\n(denom         : ℤ)\n(denom_ne_zero : denom ≠ 0)\n\n/- The number `n` is called the numerator, and the number `d` is called the\ndenominator.\n\nThe representation of a rational number as a fraction is not unique—e.g.,\n`1 / 2 = 2 / 4 = -1 / -2`.\n\n**Step 2:** Two fractions `n₁ / d₁` and `n₂ / d₂` represent the same rational\nnumber if the ratio between numerator and denominator are the same—i.e.,\n`n₁ * d₂ = n₂ * d₁`. This will be our equivalence relation `≈` on fractions. -/\n\nnamespace fraction\n\n@[instance] def setoid : setoid fraction :=\n{ r     := λa b : fraction, num a * denom b = num b * denom a,\n  iseqv :=\n    begin\n      repeat { apply and.intro },\n      { intros a; refl },\n      { intros a b h; cc },\n      { intros a b c eq_ab eq_bc,\n        apply int.eq_of_mul_eq_mul_right (denom_ne_zero b),\n        cc }\n    end }\n\nlemma setoid_iff (a b : fraction) :\n  a ≈ b ↔ num a * denom b = num b * denom a :=\nby refl\n\n/- **Step 3:** Define `0 := 0 / 1`, `1 := 1 / 1`, addition, multiplication, etc.\n\n    `n₁ / d₁ + n₂ / d₂`     := `(n₁ * d₂ + n₂ * d₁) / (d₁ * d₂)`\n    `(n₁ / d₁) * (n₂ / d₂)` := `(n₁ * n₂) / (d₁ * d₂)`\n\nThen show that they are compatible with `≈`. -/\n\ndef of_int (i : ℤ) : fraction :=\n{ num           := i,\n  denom         := 1,\n  denom_ne_zero := by simp }\n\n@[instance] def has_zero : has_zero fraction :=\n{ zero := of_int 0 }\n\n@[instance] def has_one : has_one fraction :=\n{ one := of_int 1 }\n\n@[instance] def has_add : has_add fraction :=\n{ add := λa b : fraction,\n    { num           := num a * denom b + num b * denom a,\n      denom         := denom a * denom b,\n      denom_ne_zero :=\n        by apply mul_ne_zero; exact denom_ne_zero _ } }\n\n@[simp] lemma add_num (a b : fraction) :\n  num (a + b) = num a * denom b + num b * denom a :=\nby refl\n\n@[simp] lemma add_denom (a b : fraction) :\n  denom (a + b) = denom a * denom b :=\nby refl\n\nlemma add_equiv_add {a a' b b' : fraction} (ha : a ≈ a')\n    (hb : b ≈ b') :\n  a + b ≈ a' + b' :=\nbegin\n  simp [setoid_iff, add_denom, add_num] at *,\n  calc  (num a * denom b + num b * denom a)\n          * (denom a' * denom b')\n      = num a * denom a' * denom b * denom b'\n          + num b * denom b' * denom a * denom a' :\n    by simp [add_mul, mul_add]; ac_refl\n  ... = num a' * denom a * denom b * denom b'\n          + num b' * denom b * denom a * denom a' :\n    by simp [*]\n  ... = (num a' * denom b' + num b' * denom a')\n          * (denom a * denom b) :\n    by simp [add_mul, mul_add]; ac_refl\nend\n\n@[instance] def has_neg : has_neg fraction :=\n{ neg := λa : fraction,\n    { num := - num a,\n      ..a } }\n\n@[simp] lemma neg_num (a : fraction) :\n  num (- a) = - num a :=\nby refl\n\n@[simp] lemma neg_denom (a : fraction) :\n  denom (- a) = denom a :=\nby refl\n\nlemma setoid_neg {a a' : fraction} (hab : a ≈ a') :\n  - a ≈ - a' :=\nby simp [setoid_iff] at hab ⊢; exact hab\n\n@[instance] def has_mul : has_mul fraction :=\n{ mul := λa b : fraction,\n    { num           := num a * num b,\n      denom         := denom a * denom b,\n      denom_ne_zero :=\n        mul_ne_zero (denom_ne_zero a) (denom_ne_zero b) } }\n\n@[simp] lemma mul_num (a b : fraction) :\n  num (a * b) = num a * num b :=\nby refl\n\n@[simp] lemma mul_denom (a b : fraction) :\n  denom (a * b) = denom a * denom b :=\nby refl\n\nlemma setoid_mul {a a' b b' : fraction} (ha : a ≈ a')\n    (hb : b ≈ b') :\n  a * b ≈ a' * b' :=\nby simp [setoid_iff] at ha hb ⊢; cc\n\n@[instance] def has_inv : has_inv fraction :=\n{ inv := λa : fraction,\n    if ha : num a = 0 then\n      0\n    else\n      { num           := denom a,\n        denom         := num a,\n        denom_ne_zero := ha } }\n\nlemma inv_def (a : fraction) (ha : num a ≠ 0) :\n  a⁻¹ =\n  { num           := denom a,\n    denom         := num a,\n    denom_ne_zero := ha } :=\ndif_neg ha\n\nlemma inv_zero (a : fraction) (ha : num a = 0) :\n  a⁻¹ = 0 :=\ndif_pos ha\n\n@[simp] lemma inv_num (a : fraction) (ha : num a ≠ 0) :\n  num (a⁻¹) = denom a :=\nby rw inv_def a ha\n\n@[simp] lemma inv_denom (a : fraction) (ha : num a ≠ 0) :\n  denom (a⁻¹) = num a :=\nby rw inv_def a ha\n\nlemma setoid_inv {a a' : fraction} (ha : a ≈ a') :\n  a⁻¹ ≈ a'⁻¹ :=\nbegin\n  cases' classical.em (num a = 0),\n  case inl : ha0 {\n    cases' classical.em (num a' = 0),\n    case inl : ha'0 {\n      simp [ha0, ha'0, inv_zero] },\n    case inr : ha'0 {\n      simp [ha0, ha'0, setoid_iff, denom_ne_zero] at ha,\n      cc } },\n  case inr : ha0 {\n    cases' classical.em (num a' = 0),\n    case inl : ha'0 {\n      simp [setoid_iff, ha'0, denom_ne_zero] at ha,\n      cc },\n    case inr : ha'0 {\n      simp [setoid_iff, ha0, ha'0] at ha ⊢,\n      cc } }\nend\n\nend fraction\n\ndef rat : Type :=\nquotient fraction.setoid\n\nnamespace rat\n\n@[instance] def has_zero : has_zero rat :=\n{ zero := ⟦0⟧ }\n\n@[instance] def has_one : has_one rat :=\n{ one := ⟦1⟧ }\n\n@[instance] def has_add : has_add rat :=\n{ add := quotient.lift₂ (λa b : fraction, ⟦a + b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact fraction.add_equiv_add ha hb\n    end }\n\n@[instance] def has_neg : has_neg rat :=\n{ neg := quotient.lift (λa : fraction, ⟦- a⟧)\n    begin\n      intros a a' ha,\n      apply quotient.sound,\n      exact fraction.setoid_neg ha\n    end }\n\n@[instance] def has_mul : has_mul rat :=\n{ mul := quotient.lift₂ (λa b : fraction, ⟦a * b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact fraction.setoid_mul ha hb\n    end }\n\n@[instance] def has_inv : has_inv rat :=\n{ inv := quotient.lift (λa : fraction, ⟦a⁻¹⟧)\n    begin\n      intros a a' ha,\n      apply quotient.sound,\n      exact fraction.setoid_inv ha\n    end }\n\nend rat\n\n\n/- ### Alternative Definitions of `ℚ`\n\n**Alternative 1:** Define `ℚ` as a subtype of `fraction`, with the requirement\nthat the numerator and the denominator have no common divisors except `1` and\n`-1`: -/\n\nnamespace alternative_1\n\ndef rat.is_canonical (a : fraction) : Prop :=\nnat.coprime (int.nat_abs (fraction.num a))\n  (int.nat_abs (fraction.denom a))\n\ndef rat := {a : fraction // rat.is_canonical a}\n\nend alternative_1\n\n/- This is more or less the `mathlib` definition.\n\nAdvantages:\n\n* no quotient required;\n* more efficient computation;\n* more properties are syntactic equalities up to computation.\n\nDisadvantage:\n\n* more complicated function definitions.\n\n**Alternative 2**: Define all elements syntactically, including the desired\noperations: -/\n\nnamespace alternative_2\n\ninductive pre_rat : Type\n| zero : pre_rat\n| one  : pre_rat\n| add  : pre_rat → pre_rat → pre_rat\n| sub  : pre_rat → pre_rat → pre_rat\n| mul  : pre_rat → pre_rat → pre_rat\n| div  : pre_rat → pre_rat → pre_rat\n\n/- Then quotient `pre_rat` to enforce congruence rules and the field axioms: -/\n\ninductive rat.rel : pre_rat → pre_rat → Prop\n| add_congr {a b c d : pre_rat} :\n  rat.rel a b → rat.rel c d →\n  rat.rel (pre_rat.add a c) (pre_rat.add b d)\n| add_assoc {a b c : pre_rat} :\n  rat.rel (pre_rat.add a (pre_rat.add b c))\n    (pre_rat.add (pre_rat.add a b) c)\n| zero_add {a : pre_rat} :\n  rat.rel (pre_rat.add pre_rat.zero a) a\n-- etc.\n\ndef rat : Type :=\nquot rat.rel\n\nend alternative_2\n\n/- Advantages:\n\n* no dependency on `ℤ`;\n* easy proofs of the field axioms;\n* general recipe reusable for other algebraic constructions (e.g., free monoids,\n  free groups).\n\nDisadvantage:\n\n* the definition of orders and lemmas about them are more complicated.\n\n\n### Real Numbers\n\nSome sequences of rational numbers seem to converge because the numbers in the\nsequence get closer and closer to each other, and yet do not converge to a\nrational number.\n\nExample:\n\n    `a₀ = 1`\n    `a₁ = 1.4`\n    `a₂ = 1.41`\n    `a₃ = 1.414`\n    `a₄ = 1.4142`\n    `a₅ = 1.41421`\n    `a₆ = 1.414213`\n    `a₇ = 1.4142135`\n       ⋮\n\nThis sequence seems to converge because each `a_n` is at most `10^-n` away from\nany of the following numbers. But the limit is `√2`, which is not a rational\nnumber.\n\nThe rational numbers are incomplete, and the reals are their  __completion__.\n\nTo construct the reals, we need to fill in the gaps that are revealed by these\nsequences that seem to converge, but do not.\n\nMathematically, a sequence `a₀, a₁, …` of rational numbers is __Cauchy__ if for\nany `ε > 0`, there exists an `N ∈ ℕ` such that for all `m ≥ N`, we have\n`|a_N - a_m| < ε`.\n\nIn other words, no matter how small we choose `ε`, we can always find a point in\nthe sequence from which all following numbers deviate less than by `ε`. -/\n\ndef is_cau_seq (f : ℕ → ℚ) : Prop :=\n∀ε > 0, ∃N, ∀m ≥ N, abs (f N - f m) < ε\n\n/- Not every sequence is a Cauchy sequence: -/\n\nlemma id_not_cau_seq :\n  ¬ is_cau_seq (λn : ℕ, (n : ℚ)) :=\nbegin\n  rw is_cau_seq,\n  intro h,\n  cases' h 1 zero_lt_one with i hi,\n  have hi_succi :=\n    hi (i + 1) (by simp),\n  simp [←sub_sub] at hi_succi,\n  linarith\nend\n\n/- We define a type of Cauchy sequences as a subtype: -/\n\ndef cau_seq : Type :=\n{f : ℕ → ℚ // is_cau_seq f}\n\ndef seq_of (f : cau_seq) : ℕ → ℚ :=\nsubtype.val f\n\n/- Cauchy sequences represent real numbers:\n\n* `a_n = 1 / n` represents the real number `0`;\n* `1, 1.4, 1.41, …` represents the real number `√2`;\n* `a_n = 0` also represents the real number `0`.\n\nSince different Cauchy sequences can represent the same real number, we need to\ntake the quotient. Formally, two sequences represent the same real number when\ntheir difference converges to zero: -/\n\nnamespace cau_seq\n\n@[instance] def setoid : setoid cau_seq :=\n{ r     := λf g : cau_seq,\n    ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε,\n  iseqv :=\n    begin\n      apply and.intro,\n      { intros f ε hε,\n        apply exists.intro 0,\n        finish },\n      apply and.intro,\n      { intros f g hfg ε hε,\n        cases' hfg ε hε with N hN,\n        apply exists.intro N,\n        intros m hm,\n        rw abs_sub,\n        apply hN m hm },\n      { intros f g h hfg hgh ε hε,\n        cases' hfg (ε / 2) (half_pos hε) with N₁ hN₁,\n        cases' hgh (ε / 2) (half_pos hε) with N₂ hN₂,\n        apply exists.intro (max N₁ N₂),\n        intros m hm,\n        calc  abs (seq_of f m - seq_of h m)\n            ≤ abs (seq_of f m - seq_of g m)\n              + abs (seq_of g m - seq_of h m) :\n          by apply abs_sub_le\n        ... < ε / 2 + ε / 2 :\n          add_lt_add (hN₁ m (le_of_max_le_left hm))\n            (hN₂ m (le_of_max_le_right hm))\n        ... = ε :\n          by simp }\n    end }\n\nlemma setoid_iff (f g : cau_seq) :\n  f ≈ g ↔\n  ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε :=\nby refl\n\n/- We can define constants such as `0` and `1` as a constant sequence. Any\nconstant sequence is a Cauchy sequence: -/\n\ndef const (q : ℚ) : cau_seq :=\nsubtype.mk (λ_ : ℕ, q) (by rw is_cau_seq; intros ε hε; finish)\n\n/- Defining addition of real numbers requires a little more effort. We define\naddition on Cauchy sequences as pairwise addition: -/\n\n@[instance] def has_add : has_add cau_seq :=\n{ add := λf g : cau_seq,\n    subtype.mk (λn : ℕ, seq_of f n + seq_of g n) sorry }\n\n/- Above, we omit the proof that the addition of two Cauchy sequences is again\na Cauchy sequence.\n\nNext, we need to show that this addition is compatible with `≈`: -/\n\nlemma add_equiv_add {f f' g g' : cau_seq} (hf : f ≈ f')\n    (hg : g ≈ g') :\n  f + g ≈ f' + g' :=\nbegin\n  intros ε₀ hε₀,\n  simp [setoid_iff],\n  cases' hf (ε₀ / 2) (half_pos hε₀) with Nf hNf,\n  cases' hg (ε₀ / 2) (half_pos hε₀) with Ng hNg,\n  apply exists.intro (max Nf Ng),\n  intros m hm,\n  calc  abs (seq_of (f + g) m - seq_of (f' + g') m)\n      = abs ((seq_of f m + seq_of g m)\n           - (seq_of f' m + seq_of g' m)) :\n    by refl\n  ... = abs ((seq_of f m - seq_of f' m)\n           + (seq_of g m - seq_of g' m)) :\n    begin\n      have arg_eq :\n        seq_of f m + seq_of g m - (seq_of f' m + seq_of g' m) =\n        seq_of f m - seq_of f' m + (seq_of g m - seq_of g' m),\n        by linarith,\n      rw arg_eq\n    end\n  ... ≤ abs (seq_of f m - seq_of f' m)\n      + abs (seq_of g m - seq_of g' m) :\n    by apply abs_add\n  ... < ε₀ / 2 + ε₀ / 2 :\n    add_lt_add (hNf m (le_of_max_le_left hm))\n      (hNg m (le_of_max_le_right hm))\n  ... = ε₀ :\n    by simp\nend\n\nend cau_seq\n\n/- The real numbers are the quotient: -/\n\ndef real : Type :=\nquotient cau_seq.setoid\n\nnamespace real\n\n@[instance] def has_zero : has_zero real :=\n{ zero := ⟦cau_seq.const 0⟧ }\n\n@[instance] def has_one : has_one real :=\n{ one := ⟦cau_seq.const 1⟧ }\n\n@[instance] def has_add : has_add real :=\n{ add := quotient.lift₂ (λa b : cau_seq, ⟦a + b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact cau_seq.add_equiv_add ha hb,\n    end }\n\nend real\n\n\n/- ### Alternative Definitions of `ℝ`\n\n* Dedekind cuts: `r : ℝ` is represented essentially as `{x : ℚ | x < r}`.\n\n* Binary sequences `ℕ → bool` can represent the interval `[0, 1]`. This can be\n  used to build `ℝ`. -/\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_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7626854766141825}}
{"text": "import tactic.interactive\n\n-- \"set X\" means the power set of X\n-- a : X means a ∈ X\n\ntheorem useful (X : Type) (f : X → set X) : ∃ S : set X, ∀ x : X, ¬ (f x = S) :=\nbegin\n  let S := {a : X | a ∉ f a},\n  use S,\n  intro x,\n  intro H,\n  have H2 : x ∈ f x ↔ x ∈ S,\n    simp [H],\n  change x ∈ f x ↔ ¬ (x ∈ f x) at H2,\n  cc,\nend\n\nopen function\n\ntheorem cantor (X : Type) : ¬ (∃ f : X → set X, bijective f) :=\nbegin\n  intro H,\n  cases H with f Hf,\n  cases Hf with Hi Hs,\n  cases (useful X f) with S HS,\n  have H2 := Hs S,\n  cases H2 with a Ha,\n  apply HS a,\n  assumption,\nend\n\ntheorem uncountable : ¬ (∃ f : ℕ → set ℕ, bijective f) :=\ncantor ℕ\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/M1F/room_342_group_projects/Cantor/M1F_cantor_13dec.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.7956581097540519, "lm_q1q2_score": 0.7626683162223847}}
{"text": "variables (real : Type) [ordered_ring real]\nvariables (log exp : real → real)\nvariable log_exp_eq : ∀ x, log (exp x) = x\nvariable exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x\nvariable exp_pos : ∀ x, exp x > 0\nvariable exp_add : ∀ 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) : exp (x + y + z) = exp x * exp y * exp z :=\n  by rw [exp_add, exp_add]\n\nexample (y : real) (h : y > 0)  : exp (log y) = y :=\n  exp_log_eq h\n\ntheorem log_mul {x y : real} (hx : x > 0) (hy : y > 0) : log (x * y) = log x + log y :=\n  by rw [←exp_log_eq hx, ←exp_log_eq hy, ←exp_add, log_exp_eq, log_exp_eq, log_exp_eq]\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/ex0606.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7626683046110208}}
{"text": "import algebra.order.ring\n\n#check sub_nonneg\n#check sub_mul\n\nvariables {R : Type*} [ordered_ring R]\nvariables a b c : R\n\nexample (h : a ≤ b) (h' : 0 ≤ c) : a * c ≤ b * c := \nbegin\n  rw ← sub_nonneg,\n  rw ← sub_mul,\n  have h'' : 0 ≤ b - a := sub_nonneg.2 h,\n  exact mul_nonneg h'' h',\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/7_have/ex5_have_mul_pos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377284730285, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7626683032311558}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker, Alexey Soloyev, Junyan Xu\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.real.irrational\nimport Mathlib.data.nat.fib\nimport Mathlib.data.matrix.notation\nimport Mathlib.tactic.ring_exp\nimport Mathlib.algebra.linear_recurrence\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# The golden ratio and its conjugate\n\nThis file defines the golden ratio `φ := (1 + √5)/2` and its conjugate\n`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.\n\nAlong with various computational facts about them, we prove their\nirrationality, and we link them to the Fibonacci sequence by proving\nBinet's formula.\n-/\n\n/-- The golden ratio `φ := (1 + √5)/2`. -/\ndef golden_ratio : ℝ := (1 + real.sqrt (bit1 (bit0 1))) / bit0 1\n\n/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/\ndef golden_conj : ℝ := (1 - real.sqrt (bit1 (bit0 1))) / bit0 1\n\n/-- The inverse of the golden ratio is the opposite of its conjugate. -/\ntheorem inv_gold : golden_ratio⁻¹ = -golden_conj := sorry\n\n/-- The opposite of the golden ratio is the inverse of its conjugate. -/\ntheorem inv_gold_conj : golden_conj⁻¹ = -golden_ratio := sorry\n\n@[simp] theorem gold_mul_gold_conj : golden_ratio * golden_conj = -1 := sorry\n\n@[simp] theorem gold_conj_mul_gold : golden_conj * golden_ratio = -1 :=\n  eq.mpr\n    (id\n      (Eq._oldrec (Eq.refl (golden_conj * golden_ratio = -1)) (mul_comm golden_conj golden_ratio)))\n    gold_mul_gold_conj\n\n@[simp] theorem gold_add_gold_conj : golden_ratio + golden_conj = 1 := sorry\n\ntheorem one_sub_gold_conj : 1 - golden_ratio = golden_conj := sorry\n\ntheorem one_sub_gold : 1 - golden_conj = golden_ratio := sorry\n\n@[simp] theorem gold_sub_gold_conj : golden_ratio - golden_conj = real.sqrt (bit1 (bit0 1)) := sorry\n\n@[simp] theorem gold_sq : golden_ratio ^ bit0 1 = golden_ratio + 1 := sorry\n\n@[simp] theorem gold_conj_sq : golden_conj ^ bit0 1 = golden_conj + 1 := sorry\n\ntheorem gold_pos : 0 < golden_ratio := sorry\n\ntheorem gold_ne_zero : golden_ratio ≠ 0 := ne_of_gt gold_pos\n\ntheorem one_lt_gold : 1 < golden_ratio := sorry\n\ntheorem gold_conj_neg : golden_conj < 0 := sorry\n\ntheorem gold_conj_ne_zero : golden_conj ≠ 0 := ne_of_lt gold_conj_neg\n\ntheorem neg_one_lt_gold_conj : -1 < golden_conj :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-1 < golden_conj)) (propext neg_lt)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-golden_conj < 1)) (Eq.symm inv_gold)))\n      (inv_lt_one one_lt_gold))\n\n/-!\n## Irrationality\n-/\n\n/-- The golden ratio is irrational. -/\ntheorem gold_irrational : irrational golden_ratio := sorry\n\n/-- The conjugate of the golden ratio is irrational. -/\ntheorem gold_conj_irrational : irrational golden_conj := sorry\n\n/-!\n## Links with Fibonacci sequence\n-/\n\n/-- The recurrence relation satisfied by the Fibonacci sequence. -/\ndef fib_rec {α : Type u_1} [comm_semiring α] : linear_recurrence α :=\n  linear_recurrence.mk (bit0 1) (matrix.vec_cons 1 (matrix.vec_cons 1 matrix.vec_empty))\n\n/-- The characteristic polynomial of `fib_rec` is `X² - (X + 1)`. -/\ntheorem fib_rec_char_poly_eq {β : Type u_1} [comm_ring β] :\n    linear_recurrence.char_poly fib_rec = polynomial.X ^ bit0 1 - (polynomial.X + 1) :=\n  sorry\n\n/-- As expected, the Fibonacci sequence is a solution of `fib_rec`. -/\ntheorem fib_is_sol_fib_rec {α : Type u_1} [comm_semiring α] :\n    linear_recurrence.is_solution fib_rec fun (x : ℕ) => ↑(nat.fib x) :=\n  sorry\n\n/-- The geometric sequence `λ n, φ^n` is a solution of `fib_rec`. -/\ntheorem geom_gold_is_sol_fib_rec : linear_recurrence.is_solution fib_rec (pow golden_ratio) := sorry\n\n/-- The geometric sequence `λ n, ψ^n` is a solution of `fib_rec`. -/\ntheorem geom_gold_conj_is_sol_fib_rec : linear_recurrence.is_solution fib_rec (pow golden_conj) :=\n  sorry\n\n/-- Binet's formula as a function equality. -/\ntheorem real.coe_fib_eq' :\n    (fun (n : ℕ) => ↑(nat.fib n)) =\n        fun (n : ℕ) => (golden_ratio ^ n - golden_conj ^ n) / real.sqrt (bit1 (bit0 1)) :=\n  sorry\n\n/-- Binet's formula as a dependent equality. -/\ntheorem real.coe_fib_eq (n : ℕ) :\n    ↑(nat.fib n) = (golden_ratio ^ n - golden_conj ^ n) / real.sqrt (bit1 (bit0 1)) :=\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/real/golden_ratio_auto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240125464115, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7625703541304697}}
{"text": "import data.nat.basic\nimport data.fin\n\nimport tactic.linarith\n\nopen fin\n\n---------------------------------------------------------------------------------------------\n-- nat lemmas\n\nlemma nat_add_mul_left_div_left {a b : ℕ} {c : ℕ} (c_pos : 0 < c) : (c * a + b) / c = a + b/c\n:= begin\n    rw add_comm,\n    rw nat.add_mul_div_left _ _ c_pos,\n    ring,\nend\n\nlemma nat_add_mul_left_mod_left {a b : ℕ} {c : ℕ} : (c * a + b) % c = b%c\n:= begin\n    rw add_comm,\n    rw nat.add_mul_mod_self_left,\nend\n\nlemma add_mul_congr_factor_lt_contra {a b c d e : ℕ}\n    : c < a → b < d → ¬ a * b + c = a * d + e\n:= begin\n    intros cp ep h,\n    have h3: a * b + c < a * (b + 1), {\n        apply add_lt_add_left; linarith,\n    },\n    have h4: a * (b + 1) ≤ a * d, {\n        apply mul_le_mul; linarith,\n    },\n    linarith,\nend\n\nlemma add_mul_congr_factor {a b c d e : ℕ}\n    : c < a → e < a → a * b + c = a * d + e → b = d\n:= begin\n    intros cp ep h,\n    by_contradiction h1,\n    cases (ne.lt_or_lt h1) with h2 h2, {\n        apply add_mul_congr_factor_lt_contra cp h2 h,\n    }, {\n        apply add_mul_congr_factor_lt_contra ep h2 (eq.symm h),\n    }\nend\n\nlemma add_mul_congr {a b c d e : ℕ}\n    : a * b + c = a * d + e → c < a → e < a → b = d ∧ c = e\n:= begin\n    intros h cp ep,\n    cases (add_mul_congr_factor cp ep h),\n    split, {\n        refl,\n    }, {\n        rw add_right_inj at h,\n        exact h,\n    }\nend\n\n\n------------------------------------------------------------------------------\n-- nat.mod lemmas\n\nsection nat_mod\n\nvariables (n : ℕ) {m : ℕ}\n\nlemma nat_decomposable_mul_add : 0 < m → ∃ r s, s < m ∧ n = m * r + s\n:= begin\n    intros mh,\n    induction n, {\n        use 0,\n        use 0,\n        split,\n        assumption,\n        simp,\n    }, {\n        rcases n_ih with ⟨r', ⟨s', ⟨h1, h2⟩⟩⟩,\n\n        by_cases c: s' + 1 < m, {\n            use r',\n            use (s' + 1),\n            split, {\n                assumption,\n            }, {\n                rw h2,\n                rw <- nat.add_one,\n                ring,\n            }\n        }, {\n            have c': m = s' + 1, {\n                linarith,\n            },\n            use (r' + 1),\n            use (s' + 1 - m),\n            rw c',\n            split, {\n                linarith,\n            }, {\n                simp,\n                rw h2,\n                rw <- nat.add_one,\n                rw c',\n                ring,\n            }\n        }\n    }\nend\n\nlemma nat_decompose_mul_add : 0 < m → n = m * (n / m) + (n % m)\n:= begin\n    intros mh,\n    rcases (nat_decomposable_mul_add n mh) with ⟨r, ⟨s, ⟨h1,h2⟩⟩⟩,\n    apply eq.trans h2,\n    congr, {\n        rw h2,\n        rw add_comm,\n        rw nat.add_mul_div_left; try {assumption},\n        rw nat.div_eq_of_lt; assumption <|> simp,\n    }, {\n        rw h2,\n        rw nat.add_mod, simp,\n        rw nat.mod_eq_of_lt h1,\n    }\nend\n\nend nat_mod\n\n\n------------------------------------------------------------------------------\n-- fin coe simplication lemmas\n\n@[simp]\nlemma fin_coe_coe_nat_eq_self (n : ℕ) : ((n : fin n.succ) : ℕ) = n\n:= begin\n    rw coe_eq_val,\n    rw coe_val_of_lt, simp,\nend\n\n\n------------------------------------------------------------------------------\n-- fin lemmas\n\nlemma fin_has_zero {n} (i : fin n) : 0 < n\n:= begin\n    cases i,\n    linarith,\nend\n\nlemma fin_mul_left_has_zero {m p} (i : fin (m*p)) : 0 < m\n:= begin\n    have f1: 0 < m * p, {\n        apply fin_has_zero i,\n    },\n    apply pos_of_mul_pos_right f1; simp,\nend\n\nlemma fin_mul_right_has_zero {m p} (i : fin (m*p)) : 0 < p\n:= begin\n    have f1: 0 < m * p, {\n        apply fin_has_zero i,\n    },\n    apply pos_of_mul_pos_left f1; simp,\nend\n\nlemma fin_add_mul_lt {m p : ℕ} (r : fin m) (v : fin p) : p * (r : ℕ) + (v : ℕ) < m * p\n:= begin\n    cases r with r hr,\n    cases v with v hv,\n    simp,\n    have f1: p * (r + 1) ≤ p * m, {\n        apply mul_le_mul; linarith,\n    },\n    calc p * r + v < p * r + p : by linarith\n               ... = p * (r + 1) : by ring\n               ... ≤ p * m : f1\n               ... = m * p : by ring,\nend\n\n\n------------------------------------------------------------------------------\n-- `cast` reduction: `fin n` cast to `fin n'` coe'd to `ℕ`.\n\nlemma coe_cast_fin_h {n n'} (h : n = n') (i : fin n)\n    : (((cast (congr_arg fin h) (i : fin n)) : fin n') : ℕ) = (i : fin n)\n:= begin\n    congr; assumption <|> apply h.symm <|> skip,\n    exact cast_heq (congr_arg fin h) i,\nend\n\nlemma coe_cast_fin {n n'} (h : n = n') (i : fin n)\n    : (((cast (congr_arg fin h) (i : fin n)) : fin n') : ℕ) = i\n:= begin\n    rw coe_cast_fin_h; simp,\nend\n\n\n------------------------------------------------------------------------------------------------\n-- `cast` helpers\n\nsection cast\n\nvariables {A B : Type}\nvariables {a : A}\nvariables {b : B}\n\nlemma cast_roundtrip (H1 : A = B) : cast H1.symm (cast H1 a) = a\n:= begin\n    cases H1,\n    refl,\nend\n\nlemma cast_eq_of_heq (H1: A = B) : a == b → cast H1 a = b\n:= begin\n    intros h,\n    cases h,\n    refl,\nend\n\nend cast\n\nsection fun_cast\n\nvariables {A1 A2 R : Type}\nvariables (f : A1 → R)\n\nlemma congr_heq_arg {x' : A2} {x : A1} (h : x' == x) : (A1 → R) = (A2 → R)\n:= begin\n    cases h, cc,\nend\n\nlemma cast_fun_apply_eq_of_heq_arg (x' : A2) (x : A1) (h : x' == x) : cast (congr_heq_arg h) f x' = f x\n:= begin\n    cases h; refl,\nend\n\ntheorem cast_apply (h : A1 = A2) (x' : A2) : cast (congr_arg _ h) f x' = f (cast h.symm x')\n:= begin\n    rw cast_fun_apply_eq_of_heq_arg,\n    apply heq_of_eq_mp; refl,\nend\n\nvariables {B1 B2 : Type}\nvariables (f2 : A1 → B1 → R)\n\nlemma congr_heq_arg2 {x' : A2} {y' : B2} {x : A1} {y : B1} (h1 : x' == x) (h2 : y' == y)\n        : (A1 → B1 → R) = (A2 → B2 → R)\n:= begin\n    cases h1, cases h2, cc,\nend\n\nlemma cast_fun_apply_eq_of_heq_arg2 (x1 : A2) (x2 : B2) (y1 : A1) (y2 : B1) (h1 : x1 == y1) (h2 : x2 == y2)\n        : cast (congr_heq_arg2 h1 h2) f2 x1 x2 = f2 y1 y2\n:= begin\n    cases h1, cases h2, refl,\nend\n\ntheorem cast_apply2 (ha : A1 = A2) (hb : B1 = B2) (x : A2) (y : B2)\n            : cast (congr_arg2 _ ha hb) f2 x y = f2 (cast ha.symm x) (cast hb.symm y)\n:= begin\n    rw cast_fun_apply_eq_of_heq_arg2; apply heq_of_eq_mp; refl,\nend\n\nend fun_cast\n", "meta": {"author": "duckki", "repo": "lean-quantum", "sha": "160cabcbd22bf24819b72930f56578e23b109a27", "save_path": "github-repos/lean/duckki-lean-quantum", "path": "github-repos/lean/duckki-lean-quantum/lean-quantum-160cabcbd22bf24819b72930f56578e23b109a27/src/common_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465098415279, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7625248699230794}}
{"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 set_finset_fintype\nimport matrix_basic\n\n/-!\n# Symmetric matrices\n\nThis file contains basic results about symmetric matrices.\nSee `matrix_basic.lean` for the definition of symmetric matrices. \n\n## Tags\n\nsym, symmetric, matrix\n-/\n\nnamespace matrix\n\nopen_locale matrix \n\nvariables {α I J R : Type*} [fintype I] [fintype J] \n\nlemma is_sym.eq {A : matrix I I α} (h : A.is_sym) : Aᵀ = A := h\n\nlemma is_sym.ext_iff {A : matrix I I α} : A.is_sym ↔ ∀ i j, Aᵀ i j = A i j :=\nby rw [is_sym, matrix.ext_iff]\n\nlemma is_sym.ext_iff' {A : matrix I I α} : A.is_sym ↔ ∀ i j, A j i = A i j :=\nis_sym.ext_iff\n\nlemma is_sym.apply {A : matrix I I α} (h : A.is_sym) (i j : I) : Aᵀ i j = A i j := \nis_sym.ext_iff.1 h i j\n\nlemma is_sym.apply' {A : matrix I I α} (h : A.is_sym) (i j : I) : A j i = A i j := \nis_sym.apply h i j\n\nlemma is_sym.ext {A : matrix I I α} : (∀ i j, Aᵀ i j = A i j) → A.is_sym := \nis_sym.ext_iff.2\n\nlemma is_sym.ext' {A : matrix I I α} : (∀ i j, Aᵀ i j = A i j) → A.is_sym := \nis_sym.ext\n\n/-- A block matrix `A.from_blocks B C D` is symmetric, if `A` and `D` are symmetric and `Bᵀ = C`. -/\nlemma is_sym_of_block_conditions\n{A : matrix I I α} {B : matrix I J α} {C : matrix J I α} {D : matrix J J α} :\n(A.is_sym) ∧ (D.is_sym) ∧ (Bᵀ = C) → (A.from_blocks B C D).is_sym :=\nbegin\n  rintros ⟨h1, h2, h3⟩, \n  have h4 : Cᵀ = B, {rw ← h3, simp},\n  unfold matrix.is_sym,\n  rw from_blocks_transpose,\n  congr;\n  assumption\nend\n\n/-- `A ⬝ Aᵀ` is symmertric. -/\nlemma mul_transpose_self_is_sym [comm_semiring α] (A : matrix I I α) : \n(A ⬝ Aᵀ).is_sym :=\nby simp [matrix.is_sym, transpose_mul]\n\n/-- The identity matrix is symmetric. -/\n@[simp] lemma is_sym_of_one [decidable_eq I] [has_zero α] [has_one α] : \n(1 : matrix I I α).is_sym := by {ext, simp}\n\n/-- The negtive identity matrix is symmetric. -/\n@[simp] lemma is_sym_of_neg_one [decidable_eq I] [has_zero α] [has_one α] [has_neg α] : \n(-1 : matrix I I α).is_sym := by {ext, simp}\n\n/-- The identity matrix multiplied by any scalar `k` is symmetric. -/\n@[simp] lemma is_sym_of_smul_one\n[decidable_eq I] [monoid R] [add_monoid α] [has_one α] [distrib_mul_action R α] (k : R) : \n(k • (1 : matrix I I α)).is_sym := \nby { ext, simp [is_sym_of_one.apply'] }\n\n/-- If a block matrix `A.from_blocks B C D` is symmetric,-/\nlemma block_conditions_of_is_sym\n{A : matrix I I α} {B : matrix I J α} {C : matrix J I α} {D : matrix J J α} :\n(A.from_blocks B C D).is_sym → (A.is_sym) ∧ (D.is_sym) ∧ (Cᵀ = B) ∧ (Bᵀ = C) :=\nbegin\n  rintros h, \n  unfold matrix.is_sym at h,\n  rw from_blocks_transpose at h,\n  have h1 : (Aᵀ.from_blocks Cᵀ Bᵀ Dᵀ).to_blocks₁₁ = (A.from_blocks B C D).to_blocks₁₁, {rw h},\n  have h2 : (Aᵀ.from_blocks Cᵀ Bᵀ Dᵀ).to_blocks₁₂ = (A.from_blocks B C D).to_blocks₁₂, {rw h},\n  have h3 : (Aᵀ.from_blocks Cᵀ Bᵀ Dᵀ).to_blocks₂₁ = (A.from_blocks B C D).to_blocks₂₁, {rw h},\n  have h4 : (Aᵀ.from_blocks Cᵀ Bᵀ Dᵀ).to_blocks₂₂ = (A.from_blocks B C D).to_blocks₂₂, {rw h},\n  simp at *,\n  use ⟨h1, h4, h2, h3⟩\nend\n\nend matrix", "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/symmetric_matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7624259508514178}}
{"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 data.fintype.card_embedding\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.Data.Fintype.BigOperators\nimport Mathlib.Logic.Equiv.Embedding\nimport Mathlib.Logic.Embedding.Set\n\n/-!\n# Number of embeddings\n\nThis file establishes the cardinality of `α ↪ β` in full generality.\n-/\n\n\nlocal notation \"|\" x \"|\" => Finset.card x\n\nlocal notation \"‖\" x \"‖\" => Fintype.card x\n\nopen Function\n\nopen Nat BigOperators\n\nnamespace Fintype\n\ntheorem card_embedding_eq_of_unique {α β : Type _} [Unique α] [Fintype β] [Fintype (α ↪ β)] :\n    ‖α ↪ β‖ = ‖β‖ :=\n  card_congr Equiv.uniqueEmbeddingEquivResult\n#align fintype.card_embedding_eq_of_unique Fintype.card_embedding_eq_of_unique\n\n-- Establishes the cardinality of the type of all injections between two finite types.\n-- porting note: `induction'` is broken so instead we make an ugly refine and `dsimp` a lot.\n@[simp]\ntheorem card_embedding_eq {α β : Type _} [Fintype α] [Fintype β] [emb : Fintype (α ↪ β)] :\n    ‖α ↪ β‖ = ‖β‖.descFactorial ‖α‖ := by\n  rw [Subsingleton.elim emb Embedding.fintype]\n  refine' Fintype.induction_empty_option (P := fun t ↦ ‖t ↪ β‖ = ‖β‖.descFactorial ‖t‖)\n        (fun α₁ α₂ h₂ e ih ↦ ?_) (?_) (fun γ h ih ↦ ?_) α <;> dsimp only <;> clear! α\n  · letI := Fintype.ofEquiv _ e.symm\n    rw [← card_congr (Equiv.embeddingCongr e (Equiv.refl β)), ih, card_congr e]\n  · rw [card_pempty, Nat.descFactorial_zero, card_eq_one_iff]\n    exact ⟨Embedding.ofIsEmpty, fun x ↦ FunLike.ext _ _ isEmptyElim⟩\n  · classical\n    dsimp only at ih\n    rw [card_option, Nat.descFactorial_succ, card_congr (Embedding.optionEmbeddingEquiv γ β),\n        card_sigma, ←ih]\n    simp only [Fintype.card_compl_set, Fintype.card_range, Finset.sum_const, Finset.card_univ,\n      smul_eq_mul, mul_comm]\n#align fintype.card_embedding_eq Fintype.card_embedding_eq\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]\ntheorem card_embedding_eq_of_infinite {α β : Type _} [Infinite α] [Fintype β] [Fintype (α ↪ β)] :\n    ‖α ↪ β‖ = 0 :=\n  card_eq_zero\n#align fintype.card_embedding_eq_of_infinite Fintype.card_embedding_eq_of_infinite\n\nend Fintype\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/CardEmbedding.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8479677622198946, "lm_q1q2_score": 0.7624259422476635}}
{"text": "import data.real.basic\nimport data.set.basic\nimport tactic\n\nnamespace mth1001\n\n/-\nWe'll only deal with real-valued sequences. Such a sequence is merely a function from `ℕ` to `ℝ`\nWe'll use the Lean built-in real number type rather than the type we've constructed.\n-/\n\nsection convergence\n\n-- `convergesto f a` means\ndef convergesto (f : ℕ → ℝ) (a : ℝ) := ∀ ε > 0, ∃ N, ∀ n ≥ N, abs (f n - a) < ε\n\n/-\nWe'll prove that the sequence `f₁ : ℕ → R` given by `f₁(n) = 5` converges to `5`.\n-/\n\ndef f₁ : ℕ → ℝ := λ n, (5 : ℝ)\n\nexample : convergesto f₁ 5 :=\nbegin\n  assume ε : ℝ,\n  assume εpos : ε > 0, -- It suffices to prove `∃ N, ∀ n ≥ N, abs (f₁ n - 5) < ε`.\n  use 1, -- Take `N := 1`.\n  assume n : ℕ,\n  assume hn : n ≥ 1,\n  unfold f₁, -- By unfolding, it suffices to show `abs (5 - 5) < ε`.\n  rw sub_self, -- That is, to prove `abs 0 < ε`.\n  rw abs_zero, -- But `abs 0 = 0`, so it suffices to prove `0 < ε`.\n  exact εpos, -- This holds by `εpos`.\nend\n\n/-\nMore generally, we'll show a constant sequence converges.\n-/\n\n-- Exercise 219:\nlemma convergesto_const (c : ℝ) : convergesto (λ n, c) c :=\nbegin\n  assume ε : ℝ,\n  assume εpos : ε > 0,\n  sorry  \nend\n\nend convergence\n\nsection uniqueness_of_limits\n\nvariables {f : ℕ → ℝ} {a b : ℝ}\n\n-- We proved the following result earlier for our own real number type.\nlemma zero_of_non_neg_of_lt_pos' {a : ℝ} (h : 0 ≤ a) (h₂ : ∀ ε > 0, a < ε) : a = 0 :=\nbegin\n  apply eq_of_le_of_forall_le_of_dense h,\n  intros ε εpos,\n  specialize h₂ ε εpos,\n  exact le_of_lt h₂,\nend\n\n-- We'll need the following results for the proof of the next lemma.\nexample (x y : ℝ) : abs (x + y) ≤ abs x + abs y := abs_add x y\nexample (x : ℝ) : abs (-x) = abs x := abs_neg x\nexample (a b c : ℝ) (h : a < b) : a + c < b + c := add_lt_add_right h c\nexample (a b c : ℝ) (h : a < b) : c + a < c + b := add_lt_add_left h c\n\n-- Exercise 220:\nlemma convergesto_unique (h₁ : convergesto f a) (h₂ : convergesto f b) : a = b :=\nbegin\n  suffices h : abs (a - b) = 0,\n  { rwa [←sub_eq_zero, ←abs_eq_zero] },\n  have k₁ : abs (a - b) ≥ 0, from abs_nonneg (a - b),\n  suffices h : ∀ ε > 0, abs (a - b) < ε, from zero_of_non_neg_of_lt_pos' k₁ h,\n  sorry  \nend\n\nend uniqueness_of_limits\n\nsection algebra_of_limits\n\nvariables (f g : ℕ → ℝ) -- `f` and `g` are sequences\nvariables (a b c : ℝ)\n\n-- The following result will often come in handy!\nlemma div_abs_pos_of_pos_of_non_zero {ε c : ℝ} (εpos : ε > 0) (h : c ≠ 0) : ε / abs c > 0 :=\nbegin\n  have h₂ : 0 < abs c, from  abs_pos_iff.mpr h,\n  have h₃ : 0 < (abs c)⁻¹, from inv_pos.mpr h₂,\n  exact mul_pos εpos h₃,\nend\n\nexample (a b c : ℝ) (h₁ : a < b / c) (h₂ : 0 < c): a * c < b := (lt_div_iff h₂).mp h₁\n\nexample (a b : ℝ) : abs (a*b) = abs a * abs b := abs_mul a b\n\nexample (x y : ℝ) : x ≤ max x y := le_max_left x y\n\nexample (x y : ℝ) : y ≤ max x y := le_max_right x y\n\ntheorem convergesto_scalar_mul (h : convergesto f a) : convergesto (λ n, c * (f n)) (c * a) :=\nbegin\n  by_cases h₂ : c = 0,\n  { simp only [h₂, zero_mul], -- `simp` is a simiplying tactic.\n    exact convergesto_const 0, },\n  { assume ε : ℝ,\n    assume εpos : ε > 0,\n    have h₃ : ε / abs c > 0, from div_abs_pos_of_pos_of_non_zero εpos h₂,\n    cases h (ε/ abs c) h₃ with N hN,\n    use N,\n    intros n hn,\n    specialize hN n hn,\n    have h₄ : abs c > 0, from abs_pos_iff.mpr h₂,\n    have h₅ : abs (f n -a) * abs c < ε, from (lt_div_iff h₄).mp hN,\n    have h₆ : abs ((f n - a)* c) < ε, { rwa abs_mul, },\n    rwa [←mul_sub, mul_comm], },\nend\n\ntheorem convergesto_add (h₁ : convergesto f a) (h₂ : convergesto g b )\n: convergesto (λ n, f n + g n) (a + b) :=\nbegin\n  assume ε : ℝ,\n  assume εpos : ε > 0,\n  cases h₁ (ε/2) (by linarith) with N₁ hN₁,\n  cases h₂ (ε/2) (by linarith) with N₂ hN₂,\n  use (max N₁ N₂),\n  intros n hn,\n  have k₁ : n ≥ N₁, from le_trans (le_max_left N₁ N₂) hn,\n  have k₂ : n ≥ N₂, from le_trans (le_max_right N₁ N₂) hn,\n  have m₁ : abs (f n - a) < ε/2, from hN₁ n k₁,\n  have m₂ : abs (g n - b) < ε/2, from hN₂ n k₂,\n  have h₃ : (f n + g n) - (a + b) = (f n - a) + (g n - b), ring,\n  rw h₃,\n  calc abs (f n - a + (g n - b))\n        ≤ abs (f n - a) + abs (g n - b) : abs_add _ _\n    ... < ε/2 + ε/2                     : by linarith\n    ... = ε                             : by linarith,\nend\n\n-- The same proof can be written more briefly using `congr'` and by giving arguments to `linarith`.\nexample (h₁ : convergesto f a) (h₂ : convergesto g b ) : convergesto (λ n, f n + g n) (a + b) :=\nbegin\n  intros ε εpos,\n  cases h₁ (ε/2) (by linarith) with N₁ hN₁,\n  cases h₂ (ε/2) (by linarith) with N₂ hN₂,\n  use (max N₁ N₂),\n  intros n hn,\n  have k₁ : n ≥ N₁, from le_trans (le_max_left N₁ N₂) hn,\n  have k₂ : n ≥ N₂, from le_trans (le_max_right N₁ N₂) hn,\n  calc abs ((f n + g n) - (a + b))\n        = abs (f n - a + (g n - b))     : by {congr', ring}\n    ... ≤ abs (f n - a) + abs (g n - b) : abs_add _ _\n    ... < ε/2 + ε/2                     : by linarith [hN₁ n k₁, hN₂ n k₂]\n    ... = ε                             : by linarith,\nend\n\nend algebra_of_limits\n\nsection specific_example\n\n/-\nIn Lean, it's often harder to work with particular examples than with general theorems.\nHere, we show convergence of a particular sequence.\n\nWe'll need the corollorary to the Archimedean property. In Lean,this is `exists_nat_one_div_lt`.\nNote the use of `↑n` to indicate the embedding (or coercion) of the natural number `n`\nas a real number.\n-/\n\nexample (ε : ℝ) (h : 0 < ε) : ∃ n : ℕ, 1/(↑n + 1) < ε := exists_nat_one_div_lt h\n\nexample (x : ℝ) (h : x > 0) : abs x = x := abs_of_pos h\n\nexample (x : ℝ) (h : 0 < x) : 0 < x⁻¹ := by {rwa inv_pos}\n\nexample (x : ℝ) (h : 0 < x) : x⁻¹ = (1 : ℝ) / x := inv_eq_one_div x\n\n-- Now we'll show the sequence given by `λ n, 3 + 1/n` converges to `3`.\nexample : convergesto (λ n, 3 + 1/n) 3 :=\nbegin\n  unfold convergesto,\n  assume ε εpos,\n  have h : ∃ N : ℕ, 1/(↑N + 1) < ε, from exists_nat_one_div_lt εpos,\n  cases h with N hN, -- By `∃` elim. on `h`, STP the goal assuming `N : ℕ` and `hN : 1/(↑N+1) < ε`.\n  use N + 1, -- By `∃` intro on `N + 1`, it suffices to prove\n  -- `∀ n ≥ N + 1, n ≥ N + 1 → abs (3 + 1/↑n - 3) < ε`.\n  assume n hn, -- assume `n : ℕ` and `hn : n ≥ N`.\n  have h₂ : abs ((3 : ℝ) + 1 / ↑n - 3)  = abs (↑n)⁻¹, ring,\n  rw h₂,\n  have : N + 1 > 0, linarith,\n  have : n > 0, linarith,\n  have :  (0 : ℝ) < ↑n, { rwa nat.cast_pos },\n  have : (0 : ℝ) < N + 1, {change (0 : ℝ) < ↑(N + 1), rw nat.cast_pos, linarith, },\n  have : (0 : ℝ) < (↑n)⁻¹, { rwa inv_pos },\n  rw abs_of_pos this,\n  have : (↑n)⁻¹ ≤ (↑N + (1 : ℝ))⁻¹,\n  { rw inv_le_inv, \n    change ↑(N + 1) ≤ ↑n,\n    rwa nat.cast_le,\n    repeat { assumption }, },\n  apply lt_of_le_of_lt,\n  { assumption, },\n  { rwa inv_eq_one_div, },\nend\n\nend specific_example\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_40_sequences.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.7624259410528861}}
{"text": "-- Un_numero_es_par_syss_lo_es_su_cuadrado.lean\n-- Un número es par si y solo si lo es su cuadrado\n-- José A. Alonso Jiménez\n-- Sevilla, 24 de julio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que un número es par si y solo si lo es su cuadrado.\n-- ---------------------------------------------------------------------\n\nimport data.int.parity\nimport tactic\nopen int\n\nvariable (n : ℤ)\n\n-- 1ª demostración\nexample :\n  even (n^2) ↔ even n :=\nbegin\n  split,\n  { contrapose,\n    rw ← odd_iff_not_even,\n    rw ← odd_iff_not_even,\n    unfold odd,\n    intro h,\n    cases h with k hk,\n    use 2*k*(k+1),\n    rw hk,\n    ring, },\n  { unfold even,\n    intro h,\n    cases h with k hk,\n    use 2*k^2,\n    rw hk,\n    ring, },\nend\n\n-- 2ª demostración\nexample :\n  even (n^2) ↔ even n :=\nbegin\n  split,\n  { contrapose,\n    rw ← odd_iff_not_even,\n    rw ← odd_iff_not_even,\n    rintro ⟨k, rfl⟩,\n    use 2*k*(k+1),\n    ring, },\n  { rintro ⟨k, rfl⟩,\n    use 2*k^2,\n    ring, },\nend\n\n-- 3ª demostración\nexample :\n  even (n^2) ↔ even n :=\niff.intro\n  ( have h : ¬even n → ¬even (n^2),\n      { assume h1 : ¬even n,\n        have h2 : odd n,\n          from odd_iff_not_even.mpr h1,\n        have h3: odd (n^2), from\n          exists.elim h2\n            ( assume k,\n              assume hk : n = 2*k+1,\n              have h4 : n^2 = 2*(2*k*(k+1))+1, from\n                calc  n^2\n                    = (2*k+1)^2       : by rw hk\n                ... = 4*k^2+4*k+1     : by ring\n                ... = 2*(2*k*(k+1))+1 : by ring,\n              show odd (n^2),\n                from exists.intro (2*k*(k+1)) h4),\n        show ¬even (n^2),\n          from odd_iff_not_even.mp h3 },\n    show even (n^2) → even n,\n      from not_imp_not.mp h )\n  ( assume h1 : even n,\n    show even (n^2), from\n      exists.elim h1\n        ( assume k,\n          assume hk : n = k + k ,\n          have h2 : n^2 = 2*k^2 + 2*k^2, from\n            calc  n^2\n                = (k + k)^2  : by rw hk\n            ... = 2*k^2 + 2*k^2 : by ring,\n          show even (n^2),\n            from exists.intro (2*k^2) h2 ))\n\n-- 4ª demostración\nexample :\n  even (n^2) ↔ even n :=\ncalc even (n^2)\n     ↔ even (n * n)      : iff_of_eq (congr_arg even (sq n))\n ... ↔ (even n ∨ even n) : int.even_mul\n ... ↔ even n            : or_self (even n)\n\n-- 5ª demostración\nexample :\n  even (n^2) ↔ even n :=\ncalc even (n^2)\n     ↔ even (n * n)      : by ring_nf\n ... ↔ (even n ∨ even n) : int.even_mul\n ... ↔ even n            : by simp\n\n-- 6ª demostración\nexample :\n  even (n^2) ↔ even n :=\nbegin\n  split,\n  { contrapose,\n    intro h,\n    rw ← odd_iff_not_even at *,\n    cases h with k hk,\n    use 2*k*(k+1),\n    calc n^2\n         = (2*k+1)^2       : by rw hk\n     ... = 4*k^2+4*k+1     : by ring\n     ... = 2*(2*k*(k+1))+1 : by ring, },\n  { intro h,\n    cases h with k hk,\n    use 2*k^2,\n    calc n^2\n         = (k + k)^2     : by rw hk\n     ... = 2*k^2 + 2*k^2 : by ring, },\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/Un_numero_es_par_syss_lo_es_su_cuadrado.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7624259347737637}}
{"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.cardinal.finite\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 ∣ fintype.card G`\n- `index_eq_mul_of_le` : If `H ≤ K`, then `H.index = K.index * (H.subgroup_of K).index`\n- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ 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 : ℕ :=\nnat.card (G ⧸ 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 : ℕ :=\n(H.subgroup_of K).index\n\n@[to_additive] lemma index_comap_of_surjective {G' : Type*} [group G'] {f : G' →* 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 : ∀ x y : G', setoid.r x y ↔ setoid.r (f x) (f y) :=\n  λ x y, iff_of_eq (congr_arg (∈ H) (by rw [f.map_mul, f.map_inv])),\n  refine cardinal.to_nat_congr (equiv.of_bijective (quotient.map' f (λ x y, (key x y).mp)) ⟨_, _⟩),\n  { simp_rw [←quotient.eq'] at key,\n    refine quotient.ind' (λ x, _),\n    refine quotient.ind' (λ y, _),\n    exact (key x y).mpr },\n  { refine quotient.ind' (λ x, _),\n    obtain ⟨y, hy⟩ := hf x,\n    exact ⟨y, (quotient.map'_mk' f _ y).trans (congr_arg quotient.mk' hy)⟩ },\nend\n\n@[to_additive] lemma index_comap {G' : Type*} [group G'] (f : G' →* 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 relindex_mul_index] lemma relindex_mul_index (h : H ≤ K) :\n  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 ≤ K) : K.index ∣ H.index :=\ndvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)\n\n@[to_additive] lemma relindex_dvd_index_of_le (h : H ≤ K) : H.relindex K ∣ H.index :=\ndvd_of_mul_right_eq K.index (relindex_mul_index h)\n\n@[to_additive] lemma relindex_subgroup_of (hKL : K ≤ 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\nvariables (H K L)\n\n@[to_additive relindex_mul_relindex] lemma relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) :\n  H.relindex K * K.relindex L = H.relindex L :=\nbegin\n  rw [←relindex_subgroup_of hKL],\n  exact relindex_mul_index (λ x hx, hHK hx),\nend\n\n@[to_additive] lemma inf_relindex_right : (H ⊓ K).relindex K = H.relindex K :=\nbegin\n  rw [←subgroup_of_map_subtype, relindex, relindex, subgroup_of, comap_map_eq_self_of_injective],\n  exact subtype.coe_injective,\nend\n\n@[to_additive] lemma inf_relindex_left : (H ⊓ K).relindex H = K.relindex H :=\nby rw [inf_comm, inf_relindex_right]\n\n@[to_additive relindex_inf_mul_relindex]\nlemma relindex_inf_mul_relindex : H.relindex (K ⊓ L) * K.relindex L = (H ⊓ K).relindex L :=\nby rw [←inf_relindex_right H (K ⊓ L), ←inf_relindex_right K L, ←inf_relindex_right (H ⊓ K) L,\n  inf_assoc, relindex_mul_relindex (H ⊓ (K ⊓ L)) (K ⊓ L) L inf_le_right inf_le_right]\n\n@[to_additive]\nlemma inf_relindex_eq_relindex_sup [K.normal] : (H ⊓ K).relindex H = K.relindex (H ⊔ K) :=\ncardinal.to_nat_congr (quotient_group.quotient_inf_equiv_prod_normal_quotient H K).to_equiv\n\n@[to_additive] lemma relindex_eq_relindex_sup [K.normal] : K.relindex H = K.relindex (H ⊔ K) :=\nby rw [←inf_relindex_left, inf_relindex_eq_relindex_sup]\n\n@[to_additive] lemma relindex_dvd_index_of_normal [H.normal] : H.relindex K ∣ H.index :=\n(relindex_eq_relindex_sup K H).symm ▸ relindex_dvd_index_of_le le_sup_right\n\nvariables {H K}\n\n@[to_additive] lemma relindex_dvd_of_le_left (hHK : H ≤ K) : K.relindex L ∣ H.relindex L :=\nbegin\n  apply dvd_of_mul_left_eq ((H ⊓ L).relindex (K ⊓ L)),\n  rw [←inf_relindex_right H L, ←inf_relindex_right K L],\n  exact relindex_mul_relindex (H ⊓ L) (K ⊓ L) L (inf_le_inf_right L hHK) inf_le_right,\nend\n\nvariables (H K)\n\n@[simp, to_additive] lemma index_top : (⊤ : subgroup G).index = 1 :=\ncardinal.to_nat_eq_one_iff_unique.mpr ⟨quotient_group.subsingleton_quotient_top, ⟨1⟩⟩\n\n@[simp, to_additive] lemma index_bot : (⊥ : 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] : (⊥ : subgroup G).index = fintype.card G :=\nindex_bot.trans nat.card_eq_fintype_card\n\n@[simp, to_additive] lemma relindex_top_left : (⊤ : subgroup G).relindex H = 1 :=\nindex_top\n\n@[simp, to_additive] lemma relindex_top_right : H.relindex ⊤ = H.index :=\nby rw [←relindex_mul_index (show H ≤ ⊤, from le_top), index_top, mul_one]\n\n@[simp, to_additive] lemma relindex_bot_left : (⊥ : 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  (⊥ : 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 ⊥ = 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 [←relindex_bot_left, ←index_bot], exact relindex_mul_index bot_le }\n\n@[to_additive] lemma index_map {G' : Type*} [group G'] (f : G →* G') :\n  (H.map f).index = (H ⊔ f.ker).index * f.range.index :=\nby rw [←comap_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 →* G'}\n  (hf : function.surjective f) : (H.map f).index ∣ 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 →* G'}\n  (hf : f.ker ≤ H) : H.index ∣ (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 →* G'}\n  (hf1 : function.surjective f) (hf2 : f.ker ≤ 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 ⧸ H)] :\n  H.index = fintype.card (G ⧸ 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 [←relindex_bot_left_eq_card, ←index_bot_eq_card, mul_comm]; exact relindex_mul_index bot_le\n\n@[to_additive] lemma index_dvd_card [fintype G] : H.index ∣ fintype.card G :=\nbegin\n  classical,\n  exact ⟨fintype.card H, H.index_mul_card.symm⟩,\nend\n\nvariables {H K L}\n\n@[to_additive]\nlemma relindex_eq_zero_of_le_left (hHK : H ≤ K) (hKL : K.relindex L = 0) : H.relindex L = 0 :=\neq_zero_of_zero_dvd (hKL ▸ (relindex_dvd_of_le_left L hHK))\n\n@[to_additive]\nlemma relindex_eq_zero_of_le_right (hKL : K ≤ L) (hHK : H.relindex K = 0) : H.relindex L = 0 :=\ncardinal.to_nat_apply_of_aleph_0_le (le_trans (le_of_not_lt (λ h, cardinal.mk_ne_zero _\n  ((cardinal.cast_to_nat_of_lt_aleph_0 h).symm.trans (cardinal.nat_cast_inj.mpr hHK))))\n    (quotient_subgroup_of_embedding_of_le H hKL).cardinal_le)\n\n@[to_additive] lemma relindex_le_of_le_left (hHK : H ≤ K) (hHL : H.relindex L ≠ 0) :\n  K.relindex L ≤ H.relindex L :=\nnat.le_of_dvd (nat.pos_of_ne_zero hHL) (relindex_dvd_of_le_left L hHK)\n\n@[to_additive] lemma relindex_le_of_le_right (hKL : K ≤ L) (hHL : H.relindex L ≠ 0) :\n  H.relindex K ≤ H.relindex L :=\ncardinal.to_nat_le_of_le_of_lt_aleph_0 (lt_of_not_ge (mt cardinal.to_nat_apply_of_aleph_0_le hHL))\n  (cardinal.mk_le_of_injective (quotient_subgroup_of_embedding_of_le H hKL).2)\n\n@[to_additive] lemma relindex_ne_zero_trans (hHK : H.relindex K ≠ 0) (hKL : K.relindex L ≠ 0) :\n  H.relindex L ≠ 0 :=\nλ h, mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K ⊓ L ≤ 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\n@[to_additive] lemma relindex_inf_ne_zero (hH : H.relindex L ≠ 0) (hK : K.relindex L ≠ 0) :\n  (H ⊓ K).relindex L ≠ 0 :=\nbegin\n  replace hH : H.relindex (K ⊓ L) ≠ 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH,\n  rw ← inf_relindex_right at hH hK ⊢,\n  rw inf_assoc,\n  exact relindex_ne_zero_trans hH hK,\nend\n\n@[to_additive] lemma index_inf_ne_zero (hH : H.index ≠ 0) (hK : K.index ≠ 0) : (H ⊓ K).index ≠ 0 :=\nbegin\n  rw ← relindex_top_right at hH hK ⊢,\n  exact relindex_inf_ne_zero hH hK,\nend\n\n@[to_additive] lemma relindex_inf_le : (H ⊓ K).relindex L ≤ H.relindex L * K.relindex L :=\nbegin\n  by_cases h : H.relindex L = 0,\n  { exact (le_of_eq (relindex_eq_zero_of_le_left (by exact inf_le_left) h)).trans (zero_le _) },\n  rw [←inf_relindex_right, inf_assoc, ←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),\nend\n\n@[to_additive] lemma index_inf_le : (H ⊓ K).index ≤ H.index * K.index :=\nby simp_rw [←relindex_top_right, relindex_inf_le]\n\n@[simp, to_additive index_eq_one] lemma index_eq_one : H.index = 1 ↔ H = ⊤ :=\n⟨λ h, quotient_group.subgroup_eq_top_of_subsingleton H (cardinal.to_nat_eq_one_iff_unique.mp h).1,\n  λ h, (congr_arg index h).trans index_top⟩\n\n@[to_additive] lemma index_ne_zero_of_fintype [hH : fintype (G ⧸ H)] : H.index ≠ 0 :=\nby { rw index_eq_card, exact fintype.card_ne_zero }\n\n/-- Finite index implies finite quotient. -/\n@[to_additive \"Finite index implies finite quotient.\"]\nnoncomputable def fintype_of_index_ne_zero (hH : H.index ≠ 0) : fintype (G ⧸ H) :=\n(cardinal.lt_aleph_0_iff_fintype.mp (lt_of_not_ge (mt cardinal.to_nat_apply_of_aleph_0_le hH))).some\n\n@[to_additive one_lt_index_of_ne_top]\nlemma one_lt_index_of_ne_top [fintype (G ⧸ H)] (hH : H ≠ ⊤) : 1 < H.index :=\nnat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨index_ne_zero_of_fintype, mt index_eq_one.mp hH⟩\n\nend subgroup\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/index.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7624094776980085}}
{"text": "/-\n\nOne of the reference works for proving theorems about programming languages is\nPhil Wadler's Programming Language Foundations in Agda.\n\nInference rules are frequently used in the programming languages community to express\nseveral aspects of programming like type checking and semantics, among others.\n\n\nBy defining our rules as axioms, we are building a logical framework on top of \nwhich we will prove theorems.\n\n-/\n\n\n/-\n\nThis micro-language receives strings from the user, has an escape operator\nand a consume function, that should receive only escaped values. Think of this\nlanguage as a safe alternative to my_sql_escape in PHP that prevents SQL\ninjection.\n -/\ninductive Expr : Type\n| from_user : string → Expr\n| escape : Expr → Expr\n| consume : Expr → Expr\n| concat : Expr → Expr → Expr\n\nopen Expr\n\n/- This axiom will allow us to express whether a given expression is safe or not. -/\naxiom is_safe : Expr → Prop\n\n\n/-\n\nBelow are our inference rules that define our \"type system\".\nNotice how we are abusing lean's comments to fake the horizontal line.\n\n -/\n\naxiom from_user_unsafe {s}:\n\n------------------------\n¬ is_safe (from_user s)\n\n\naxiom escape_makes_it_safe {e}:\n\n-------------------------\nis_safe (escape e)\n\n\naxiom consume_requires_safe {e}:\nis_safe e ↔\n---------------------------\nis_safe (consume e)\n\n\naxiom concat_requires_both_safe {e1 e2}:\nis_safe e1 ∧ is_safe e2 ↔\n---------------------------\nis_safe (concat e1 e2)\n\n\n\n\n\n/-\n\nLet us prove that a simple program is valid.\n\nApply works by applying a function from the goal towards the context. In Haskell it is similar to:\n\nbToC :: b -> c\n\nf :: a -> b -> c\nf x = bToC\n\nIn lean, we would write \"apply bToC\" to bring the goal of writing f from c to b. The last step of\nthe proof is done, we just have to get to point b.\n\n\n-/\n\nexample :\n    is_safe (consume (concat (escape (from_user \"a\")) (escape (from_user \"b\")))) :=\nbegin\n    apply consume_requires_safe.mp,\n    apply concat_requires_both_safe.mp,\n    {\n        split,\n        {\n            apply escape_makes_it_safe,\n        }, {\n            apply escape_makes_it_safe,\n        }\n    }\nend\n\n\ndef has_any_escape : Expr → Prop\n| (from_user s) := false\n| (escape e) := true\n| (consume e) := has_any_escape e\n| (concat e1 e2) := has_any_escape e1 ∨ has_any_escape e2\n\n\n/-\n\nThe is_safe was written in the second language.\nhas_any_escape was written in the first language, but could as well be written in the second.\n\nHere is the proof that any program that is safe, has at least one escape.\n\n-/\n\ntheorem if_is_safe_has_some_escape {e} :\n    is_safe e → has_any_escape e :=\nbegin\n    intro ise,\n    induction e,\n    {\n        -- from_user\n        have useful_proof := from_user_unsafe ise,\n        rw has_any_escape,\n        exact useful_proof,\n    },\n    {\n        -- escape\n        rw has_any_escape,\n        cc,\n    },\n    {\n        -- consume\n        rw has_any_escape,\n        apply e_ih,\n        apply consume_requires_safe.mpr ise,\n    },\n    {\n        -- concat\n        rw has_any_escape,\n        left,\n        apply e_ih_a,\n        have helper := concat_requires_both_safe.mpr ise,\n        have helper_ex := helper.left,\n        exact helper_ex,\n    }\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/05_inference_rules.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7623489527578026}}
{"text": "constants p q : Prop\n\ntheorem t1 : p → q → p := λ hp : p, λ hq : q, hp\n\n#print t1\n\ntheorem t1' :  p → q → p :=\nassume hp : p,\nassume hq : q,\nshow p, from hp\n\ntheorem t1'' (hp : p) (hq : q) : p := hp\n\naxiom hp : p\ntheorem t2 :  q → p := t1 hp\n\ntheorem t1''' : ∀ (p q : Prop), p → q → p :=\n  λ (p q : Prop) (hp : p) (hq : q), hp\n\nvariables p q r s : Prop\n\ntheorem t2' (h₁ : q → r) (h₂ : p → q) : p → r :=\n  assume h₃ : p,\n  show r, from h₁ (h₂ h₃)\n\nexample (hp : p) (hq : q) : p ∧ q := and.intro hp hq\n#check assume (hp : p) (hq : q), and.intro hp hq\n\nvariables (hp : p) (hq : q)\n#check (⟨hp, hq⟩ : p ∧ q)\n\nvariable l : list ℕ\n#check list.head l\n#check l.head\n\nexample (h : p ∧ q) : q ∧ p := ⟨h.right, h.left⟩\n\nexample (h : p ∨ q) : q ∨ p :=\nor.elim h\n  (assume hp : p, show q ∨ p, from or.intro_right q hp)\n  (assume hq : q, show q ∨ p, from or.intro_left p hq)\n\nexample (h : p ∨ q) : q ∨ p :=\nh.elim (assume hp : p, or.inr hp) (assume hq : q, or.inl hq)\n\nexample : (p → q) → ¬q → ¬p :=\nassume hpq : p → q,\nassume hnq : ¬q,\nassume hp : p,\nshow false, from hnq (hpq hp)\n\n/- false.elim -- absurd -/\n/- true.elim -- trivial -/\n\nexample (hp : p) (hnp : ¬p) : q := absurd hp hnp\n\ntheorem and_swap : p ∧ q ↔ q ∧ p :=\niff.intro\n  (assume h : p ∧ q,\n    show q ∧ p, from and.intro (and.right h) (and.left h))\n  (λ h, ⟨h.right, h.left⟩)\n\nexample (h : p ∧ q) : q ∧ p :=\nhave hp : p, from and.left h,\nhave hq : q, from and.right h,\nshow q ∧ p, from and.intro hq hp\n\nexample (h : p ∧ q) : q ∧ p :=\nhave hp : p, from and.left h,\nsuffices hq : q, from and.intro hq hp,\nshow q, from and.right h\n\nsection excluded_middle\nopen classical\n\ntheorem dne {p : Prop} (h : ¬¬p) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : ¬p, absurd hnp h)\n\n#check em\n\nexample (h : ¬¬p) : p :=\nby_cases\n  (assume h1 : p, h1)\n  (assume h1 : ¬p, absurd h1 h)\n\nexample (h : ¬¬p) : p :=\nby_contradiction\n  (assume h1 : ¬p,\n    show false, from h h1)\n\nexample (h : ¬¬p) : p :=\nby_contradiction (λ h1, h h1)\nend excluded_middle\n\n-- theorem em' {p : Prop} : (¬¬p → p) → p ∨ ¬p :=\n-- assume dne : ¬¬p → p,\n-- assume hnnp : ¬¬p,\n-- show p ∨ ¬p, from or.inl (dne hnnp)\n\nexample : p ∧ q ↔ q ∧ p :=\niff.intro\n(λ hpq, ⟨hpq.right, hpq.left⟩)\n(λ hqp, ⟨hqp.right, hqp.left⟩)\n\nopen classical\n\nexample : (¬q → ¬p) → (p → q) :=\nassume h : ¬q → ¬p,\nassume hp : p,\n-- show q, from\n--   by_contradiction\n--     (assume hnq: ¬q,\n--       show false, from absurd hp (h hnq))\nby_contradiction (λ hnq, absurd hp (h hnq))\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/tpil/props.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7623489509345293}}
{"text": "variable (p q r : Prop)\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p := \n⟨λ h => ⟨h.right, h.left⟩, λ h => ⟨h.right, h.left⟩⟩\nexample : p ∨ q ↔ q ∨ p := \n⟨λ h => h.elim Or.inr Or.inl, λ h => h.elim Or.inr Or.inl⟩\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n⟨λ h => ⟨h.left.left, ⟨h.left.right, h.right⟩⟩, \nλ h => ⟨⟨h.left, h.right.left⟩, h.right.right⟩⟩\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n⟨λ h => h.elim (λ g => g.elim Or.inl (Or.inr ∘ Or.inl)) (Or.inr ∘ Or.inr), \nλ h => h.elim (Or.inl ∘ Or.inl) (λ g => g.elim (Or.inl ∘ Or.inr) Or.inr)⟩\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n⟨λ h => h.right.elim (Or.inl ∘ (λ hq => ⟨h.left, hq⟩)) (Or.inr ∘ (λ hr => ⟨h.left, hr⟩)), \nλ h => h.elim (λ hpq => ⟨hpq.left, Or.inl hpq.right⟩) (λ hpr => ⟨hpr.left, Or.inr hpr.right⟩)⟩\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := \n⟨λ l => l.elim (λ hp => ⟨Or.inl hp, Or.inl hp⟩) (λ hqr => ⟨Or.inr hqr.left, Or.inr hqr.right⟩), \nλ r => r.left.elim Or.inl (λ hq => r.right.elim Or.inl (λ hr => Or.inr ⟨hq, hr⟩))⟩\n\n-- other properties\nexample : (p → (q → r)) ↔ (p ∧ q → r) := \n⟨λ p_q_r => (λ hpq => p_q_r hpq.left hpq.right), \nλ paq_r => (λ hp => (λ hq => paq_r ⟨hp, hq⟩))⟩\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \n⟨λ poq_r => ⟨poq_r ∘ Or.inl, poq_r ∘ Or.inr⟩, \nλ pr_qr => (λ hpq => hpq.elim pr_qr.left pr_qr.right)⟩\n\n-- note: ¬p is equivalent to p → False\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \n⟨λ npq => ⟨λ hp => npq (Or.inl hp), λ hq => npq (Or.inr hq)⟩, \nλ npnq => (λ hpq => hpq.elim npnq.left npnq.right)⟩\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) := \nλ npnq => npnq.elim (λ hnp => (λ hpq => hnp hpq.left)) (λ hnq => (λ hpq => hnq hpq.right))\n\nexample : ¬(p ∧ ¬p) := \nλ pnp => pnp.right pnp.left\n\nexample : p ∧ ¬q → ¬(p → q) := \nλ pnq => (λ hpq => pnq.right (hpq pnq.left))\n\n-- ex falso\nexample : ¬p → (p → q) := \nλ hnp => λ hp => False.elim (hnp hp)\n\nexample : (¬p ∨ q) → (p → q) := \nλ npq => λ hp => npq.elim (λ np => False.elim (np hp)) id\n\nexample : p ∨ False ↔ p := \n⟨λ hpf => hpf.elim id False.elim, Or.inl⟩\n\nexample : p ∧ False ↔ False := \n⟨And.right, False.elim⟩\n\nexample : (p → q) → (¬q → ¬p) := \nλ hpq => λ hnq => λ hp => hnq (hpq hp)\n\nsection classical\n    open Classical\n    variable (p q r : Prop)\n\n    example : (p → q ∨ r) → ((p → q) ∨ (p → r)) := \n    λ p_qr => byCases\n        (λ (hq : q) => Or.inl (λ _ => hq)) \n        (λ (hnq : ¬q) => byCases \n        (λ (hr : r) => Or.inr (λ _ => hr)) \n        (λ (hnr : ¬r) => (Or.inl (λ p => (p_qr p).elim (False.elim ∘ hnq) (False.elim ∘ hnr)))))\n\n    example : ¬(p ∧ q) → ¬p ∨ ¬q := \n    λ hnpq => byCases \n        (λ (hp : p) => byCases\n        (λ (hq : q) => False.elim (hnpq ⟨hp, hq⟩))\n        (λ (hnq : ¬q) => Or.inr hnq))\n        (λ (hnp : ¬p) => Or.inl hnp)\n\n    example : ¬(p → q) → p ∧ ¬q := \n    λ npq => byCases\n        (λ (hq : q) => False.elim (npq (λ _ => hq)))\n        (λ (hnq : ¬q) => byCases \n        (λ (hp : p) => ⟨hp, hnq⟩)\n        (λ (hnp : ¬p) => False.elim (npq (λ hp => absurd hp hnp))))\n\n    example : (p → q) → (¬p ∨ q) := \n    λ hpq => byCases \n        (λ (hq : q) => Or.inr hq)\n        (λ (hnq : ¬q) => byCases \n        (λ (hp : p) => False.elim (hnq (hpq hp)))\n        (λ (hnp : ¬p) => Or.inl hnp))\n\n    example : (¬q → ¬p) → (p → q) := \n    λ hnqnp => byCases\n        (λ (hq : q) => λ _ => hq)\n        (λ (hnq : ¬q) => byCases \n        (λ (hp : p) => False.elim ((hnqnp hnq) hp))\n        (λ (hnp : ¬p) => λ hp => absurd hp hnp))\n\n    example : p ∨ ¬p := byCases\n    (λ (hp : p) => Or.inl hp)\n    (λ (hnp : ¬p) => Or.inr hnp)\n\n    example : (((p → q) → p) → p) := byCases\n    (λ (hp : p) => λ _ => hp)\n    (λ (hnp : ¬p) => λ hpqp => hpqp (λ hp => absurd hp hnp))\nend classical\n\nexample: ¬(p ↔ ¬p) :=\nλ h => \n    have hnp : ¬p := λ hp => (h.mp hp) hp;\n    have hnnp : ¬¬p := λ hnp => hnp (h.mpr hnp);\n    hnnp hnp\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/Chap3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7623273951827055}}
{"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(ζₙ)` and `(zmod n)ˣ`;\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\n  in `K`, then `aut_to_pow` is a `mul_equiv` (for example, in `ℚ` and certain `𝔽ₚ`).\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 : ℕ+} (K : Type*) [field K] {L : Type*} [field L] {μ : L} (hμ : is_primitive_root μ n)\n          [algebra K L] [is_cyclotomic_extension {n} K L]\n\nopen polynomial 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. -/\nlemma aut_to_pow_injective : function.injective $ hμ.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ζ at hf hg,\n  suffices : f hμ.to_roots_of_unity = g hμ.to_roots_of_unity,\n  { apply alg_equiv.coe_alg_hom_injective,\n    apply (hμ.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 [←roots_of_unity.coe_pow _ hf'.some, ←roots_of_unity.coe_pow _ hg'.some],\n  congr' 1,\n  rw [pow_eq_pow_iff_modeq],\n  convert hfg,\n  rw [hμ.eq_order_of],\n  rw [←hμ.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 : comm_group (L ≃ₐ[K] L) :=\n((zeta_spec 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)ˣ` such that\n  `f μ = μ ^ k`. A stronger version of `is_primitive_root.aut_to_pow`. -/\n@[simps] noncomputable def aut_equiv_pow : (L ≃ₐ[K] L) ≃* (zmod n)ˣ :=\nlet hζ := zeta_spec n K L,\n    hμ := λ t, hζ.pow_of_coprime _ (zmod.val_coe_unit_coprime t) in\n{ inv_fun := λ t, (hζ.power_basis K).equiv_of_minpoly ((hμ t).power_basis K)\n  begin\n    haveI := is_cyclotomic_extension.ne_zero' n K L,\n    simp only [is_primitive_root.power_basis_gen],\n    have hr := is_primitive_root.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  end,\n  left_inv := λ f, begin\n    simp only [monoid_hom.to_fun_eq_coe],\n    apply alg_equiv.coe_alg_hom_injective,\n    apply (hζ.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 := λ x, begin\n    simp only [monoid_hom.to_fun_eq_coe],\n    generalize_proofs _ _ _ h,\n    have key := hζ.aut_to_pow_spec K ((hζ.power_basis K).equiv_of_minpoly\n                                      ((hμ x).power_basis K) h),\n    have := (hζ.power_basis K).equiv_of_minpoly_gen ((hμ x).power_basis K) h,\n    rw hζ.power_basis_gen K at this,\n    rw [this, is_primitive_root.power_basis_gen] at key,\n    rw ← hζ.coe_to_roots_of_unity_coe at key {occs := occurrences.pos [1, 5]},\n    simp only [←coe_coe, ←roots_of_unity.coe_pow] at key,\n    replace key := roots_of_unity.coe_injective key,\n    rw [pow_eq_pow_iff_modeq, ←order_of_subgroup, ←order_of_units, hζ.coe_to_roots_of_unity_coe,\n        ←(zeta_spec n K L).eq_order_of, ←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  end,\n  .. (zeta_spec n K L).aut_to_pow K }\n\ninclude hμ\n\nvariables {L}\n\n/-- Maps `μ` to the `alg_equiv` that sends `is_cyclotomic_extension.zeta` to `μ`. -/\nnoncomputable def from_zeta_aut : L ≃ₐ[K] L :=\nlet hζ := (zeta_spec n K L).eq_pow_of_pow_eq_one hμ.pow_eq_one n.pos in\n(aut_equiv_pow L h).symm $ zmod.unit_of_coprime hζ.some $\n((zeta_spec n K L).pow_iff_coprime n.pos hζ.some).mp $ hζ.some_spec.some_spec.symm ▸ hμ\n\nlemma from_zeta_aut_spec : from_zeta_aut hμ h (zeta n K L) = μ :=\nbegin\n  simp_rw [from_zeta_aut, aut_equiv_pow_symm_apply],\n  generalize_proofs _ _ hζ h _ hμ _,\n  rw [←hζ.power_basis_gen K] {occs := occurrences.pos [4]},\n  rw [power_basis.equiv_of_minpoly_gen, hμ.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)ˣ` if `cyclotomic n K` is irreducible in\nthe base field. -/\nnoncomputable def gal_cyclotomic_equiv_units_zmod :\n  (cyclotomic n K).gal ≃* (zmod n)ˣ :=\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)ˣ` if `cyclotomic n K` is irreducible in the\nbase field. -/\nnoncomputable def gal_X_pow_equiv_units_zmod :\n  (X ^ (n : ℕ) - 1).gal ≃* (zmod n)ˣ :=\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": "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/cyclotomic/gal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7623273874099838}}
{"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 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.Option.Basic\nimport Mathlib.Data.Nat.Basic\n\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-/\n\n\nnamespace Nat\n\n/-- Partial predecessor operation. Returns `ppred n = some m`\n  if `n = m + 1`, otherwise `none`. -/\ndef ppred : ℕ → Option ℕ\n  | 0 => none\n  | n + 1 => some n\n#align nat.ppred Nat.ppred\n\n@[simp]\ntheorem ppred_zero : ppred 0 = none := rfl\n\n@[simp]\ntheorem ppred_succ : ppred (succ n) = some n := rfl\n\n/-- Partial subtraction operation. Returns `psub m n = some k`\n  if `m = n + k`, otherwise `none`. -/\ndef psub (m : ℕ) : ℕ → Option ℕ\n  | 0 => some m\n  | n + 1 => psub m n >>= ppred\n#align nat.psub Nat.psub\n\n@[simp]\ntheorem psub_zero : psub m 0 = some m := rfl\n\n@[simp]\ntheorem psub_succ : psub m (succ n) = psub m n >>= ppred := rfl\n\ntheorem pred_eq_ppred (n : ℕ) : pred n = (ppred n).getD 0 := by cases n <;> rfl\n#align nat.pred_eq_ppred Nat.pred_eq_ppred\n\ntheorem sub_eq_psub (m : ℕ) : ∀ 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 m n, psub]; cases psub m n <;> rfl\n#align nat.sub_eq_psub Nat.sub_eq_psub\n\n@[simp]\ntheorem ppred_eq_some {m : ℕ} : ∀ {n}, ppred n = some m ↔ succ m = n\n  | 0 => by constructor <;> intro h <;> contradiction\n  | n + 1 => by constructor <;> intro h <;> injection h <;> subst m <;> rfl\n#align nat.ppred_eq_some Nat.ppred_eq_some\n\n-- Porting note: `contradiction` required an `intro` for the goals\n-- `ppred (n + 1) = none → n + 1 = 0` and `n + 1 = 0 → ppred (n + 1) = none`\n\n@[simp]\ntheorem ppred_eq_none : ∀ {n : ℕ}, ppred n = none ↔ n = 0\n  | 0 => by simp\n  | n + 1 => by constructor <;> intro <;> contradiction\n#align nat.ppred_eq_none Nat.ppred_eq_none\n\ntheorem psub_eq_some {m : ℕ} : ∀ {n k}, psub m n = some k ↔ k + n = m\n  | 0, k => by simp [eq_comm]\n  | n + 1, k => by\n    apply Option.bind_eq_some.trans\n    simp only [psub_eq_some, ppred_eq_some]\n    simp [add_comm, add_left_comm, Nat.succ_eq_add_one]\n#align nat.psub_eq_some Nat.psub_eq_some\n\ntheorem psub_eq_none {m n : ℕ} : psub m n = none ↔ m < n := by\n  cases s : psub m n <;> simp [eq_comm]\n  · 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  · show n ≤ m\n    rw [← psub_eq_some.1 s]\n    apply Nat.le_add_left\n#align nat.psub_eq_none Nat.psub_eq_none\n\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\ntheorem psub_eq_sub {m n} (h : n ≤ 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-- Porting note: we only have the simp lemma `Option.bind_some` which uses `Option.bind` not `>>=`\ntheorem psub_add (m n k) :\n    psub m (n + k) = (do psub (← psub m n) k) := by\n    induction k\n    simp [Option.bind_eq_bind, Option.bind_some]\n    simp [*, Nat.add_succ]\n\n#align nat.psub_add Nat.psub_add\n\n/-- Same as `psub`, but with a more efficient implementation. -/\n@[inline]\ndef psub' (m n : ℕ) : Option ℕ :=\n  if n ≤ m then some (m - n) else none\n#align nat.psub' Nat.psub'\n\ntheorem psub'_eq_psub (m n) : psub' m n = psub m n := by\n  rw [psub']\n  split_ifs with h\n  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\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/PSub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7623254023109509}}
{"text": "-- Next time: let's see how the graph theory theorem about the sum of degrees being even is coded in lean.\n\nimport combinatorics.simple_graph.connectivity\n\nopen_locale classical\n\nuniverse u\nvariables {V : Type u} (G : simple_graph V)\n\n#print simple_graph.walk -- prints the definition\n#check nonempty -- prints the type of the object\n\n-- simple_graph.walk u v  is the type of all walks from u to v\n\n-- prove that if u is adjacent to v then the set of walks from u to v is non-empty\n\ndef simple_graph.walks_of_len (G : simple_graph V) (u v : V) (n : ℕ) := \n  { x : G.walk u v // x.length = n }\n\ntheorem adjacent_to_walk {u v : V} (h : G.adj u v) : nonempty (G.walks_of_len u v 1) :=\nbegin\n  apply nonempty.intro,\n  split, \n  swap,\n  { have p := @simple_graph.walk.nil _ _ v,\n    exact simple_graph.walk.cons h p },\n  simp only [simple_graph.walk.length_nil, simple_graph.walk.length_cons],\nend\n\n-- lemma len_of_cons_ge_one {}\n\ntheorem eq_of_len_zero {u v : V} (w : G.walks_of_len u v 0) : u = v :=\nbegin \n  cases w with w h,\n  induction w,\n  { refl },\n  { exfalso,\n    simp only [nat.succ_ne_zero, simple_graph.walk.length_cons] at *,\n    exact h, }\nend \n\ntheorem exists_walk_of_len {u v : V} (n : ℕ) (w : G.walk u v) (h : w.length = n + 1) : \n  ∃ (v' : V) (w' : G.walk u v'), (w'.length = n) ∧ (G.adj v' v) := \nbegin \n  sorry,\nend \n\n\ntheorem non_eq_of_len_one {u v : V} (w : G.walk u v) (h : w.length = 1) : G.adj u v := \nbegin \n  \nend\n\n\ntheorem non_eq_of_len_one {u v : V} (w : G.walks_of_len u v 1) : u ≠ v := \nbegin \n  cases w with w h,\n  sorry,\n  -- induction w,\n  -- {intro h,\n  -- contradiction,},\n  -- simp,\n  -- contradiction,\n\nend\n\n\ntheorem adj_of_len_one {u v : V} (w : G.walks_of_len u v 1) : G.adj u v := \nbegin \n  cases w with w h,\n  sorry,\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/meetings/2022-02-10.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769414, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7623253963428449}}
{"text": "import tactic.core\nimport data.nat.basic\nnamespace nat\n/-\nIn Lean the natural numbers `ℕ` are defined as follows:\n\ninductive nat\n| zero : nat\n| succ (n : nat) : nat\n\nThis means that there are two ways to construct a natural number `n:ℕ`\nEither `n` is `zero` or it is the successor of a previously constructed \nnatural number `succ n`. -/\n\n--#check zero\n--#reduce succ 3\n--#check succ (succ zero)\n--#check zero.succ\nend nat \n\n\n/-\nAddition is defined inductively in Lean:\n\ndef add : ℕ → ℕ → ℕ\n| a  zero     := a                    --  a + 0 := a\n| a  (succ b) := succ (add a b)       --  a + (b + 1) := (a + b) + 1\n\n-/\n\n-- We will use the `dot` notation for the successor function.\n/--  n + 1 = n.succ -/\nlemma Succ_eq_add_one (n : ℕ) :  n.succ = n + 1  :=\nbegin \n  sorry,\nend\n\n/- \nWe are now proving lemmas/theorems that already exist in `mathlib`.\n\nTo avoid clashes we will use the same names as `mathlib` but they will be Capitalised.\n\nWe won't use high level tactics such as `norm_num` or `linarith` but we will \nneed to use earlier results as we progress (mainly with `rw` and `apply` tactics).   \n\nFor a much more complete tour of the natural numbers check out the Natural Numbers Game:\n\nhttps://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/\n\n-/\n\nlemma Add_zero (n : ℕ) : n + 0 = n :=\nbegin\n  sorry,\nend\n\n/-- a + (b + 1) = (a + b) + 1 -/\nlemma Add_succ (a b : ℕ) : a + b.succ = (a + b).succ:=\nbegin\n  sorry,\nend\n\n/-\n# New tactic for ℕ: induction \n\nIf we want to prove `∀ (n:ℕ), P n` then we can use \n`induction n` which requires us to prove two things: \n`P 0` and `P n →  P n.succ`\n\n# New tactic for structured proofs: have \n\nSometimes we want to prove intermediate results within a proof.\n\nWe can do this using the `have` tactic. \n\nIf we need to prove `h : P` (ie a proof that the proposition P is true)\nthen we can do this as follows:\n\n.... middle of a proof\nhave h : P, \n{\n  proof of P,\n},\n.... continue proof\n\nWe now have `h : P` in the local context.\n\n# Variant of rw : rwa \n\nIf we have term in the local context `h1 : P` and after `rw h2` our goal becomes `⊢ P`\nthen `rwa h2` will do the `rw h2, exact h1` in one step. \n\n(The `a` in `rwa` stands for `assumption` which is yet another tactic that will work whenever \nour goal is closed by a term in the local context.) -/\n\nlemma Zero_add (n : ℕ) : 0 + n = n :=\nbegin\n  induction n with n hn,\n  { \n    -- prove 0 + 0 = 0\n    \n    sorry,\n  },\n  { -- ⊢ 0 + n.succ = n.succ  and we have `hn : 0 + n = n` our inductive hypothesis \n    -- a useful intermediate step is to prove `0 + n.succ = (0 + n).succ`\n    have h : 0 + n.succ = (0 + n).succ,\n    {\n      \n      sorry,\n    },\n\n    sorry,\n  },\nend\n\nlemma Succ_add (a b : ℕ) : a.succ + b = (a + b).succ:=\nbegin\n  induction b with b hb,\n  { \n    sorry\n  },\n  {\n    sorry\n  },\nend\n\n\n/- Digression: how do we know that 0 ≠ 1? \nThis is one of the axioms of the natural numbers (Peano arithmetic)\nand it is built into Lean's model of ℕ.  -/\n\ntheorem Succ_ne_zero (n : ℕ) : n.succ ≠ 0 :=\nbegin \n  intro h, \n  --exact nat.no_confusion h, \n  contradiction,\nend\n\n-- Lean also knows that the successor function is injective (by definition)\ntheorem Succ.inj (n m : ℕ) : n.succ = m.succ → n = m :=\nbegin\n  exact nat.succ.inj,\nend\n\n/- Our next result says that `+` is `associative`\n\nIn Lean `a + b + c` is defined as `(a + b) + c` so whenever you see an expression such as `a + b + c + d`\nyou need to remember how this is read by Lean: `((a + b) + c) + d`\n\nWe know that the brackets aren't required, but in Lean you need to prove this.\n-/\n--#check 1 + (2 + 4) -- brackets\n--#check (1 + 2) + 4 -- no brackets\n\nlemma Add_assoc (a b c : ℕ) : (a + b) + c = a + (b + c):=\nbegin\n  induction c with c hc,\n  {\n    sorry\n  },\n  {\n    sorry\n  },\nend\n\nlemma Add_comm (m n : ℕ) : m + n = n + m :=\nbegin\n  sorry,\nend\n\n/-\nMultiplication is also defined inductively in Lean.\n\ndef mul : ℕ → ℕ → ℕ\n| a 0     := 0                      --  a * 0 := 0\n| a (b + 1) := (mul a b) + a        --  a * (b + 1) = (a * b) + a  -/\n\nlemma Mul_zero (n : ℕ) : n * 0 = 0:=\nbegin\n  sorry,\nend\n\n\nlemma Mul_succ (m n : ℕ) : m * n.succ = m * n + m:=\nbegin\n  sorry,\nend\n\nlemma Succ_mul (m n : ℕ) : m.succ * n = m * n + n:=\nbegin\n  induction n with n hn,\n  {\n    sorry\n  },\n  {\n    sorry,\n  },\nend\n\nlemma Zero_mul (n : ℕ) : 0 * n = 0:=\nbegin\n  sorry,\nend\n\nlemma Mul_one (n : ℕ) : n * 1 = n:=\nbegin\n  sorry,\nend\n\nlemma One_mul (n : ℕ) : 1 * n = n:=\nbegin\n  sorry,\nend\n\nlemma Mul_add (a b c: ℕ) : a*(b + c) = a*b + a*c:=\nbegin\n  induction a with a ha,\n  {\n    sorry\n  },\n  {\n    sorry\n  },\nend\n \nlemma Add_mul (a b c: ℕ) : (b + c)*a = b*a +c*a:=\nbegin\n  sorry,\nend\n\nlemma Mul_comm (a b : ℕ) : a * b = b * a :=\nbegin\n  sorry,\nend\n\nlemma Mul_assoc (a b c : ℕ) : a * b * c = a * (b * c):=\nbegin\n  sorry,\nend\n\nlemma Pow_zero (n : ℕ) : n ^ 0 = 1:=\nbegin\n  sorry,\nend\n\nlemma Pow_succ (a b : ℕ) : a^b.succ= a* a^b:=\nbegin\n  sorry,\nend\n\nlemma Pow_one (n : ℕ) : n ^ 1 = n:=\nbegin \n  sorry,\nend\n\n/-\n# New use of tactic : cases \n\nWe don't need induction to prove our next result, but we do need to consider the cases of zero and \nsuccessor separately. The `cases n` tactic does exactly this.   -/\n\nlemma Zero_pow (n : ℕ) (h : n ≠ 0): 0 ^ n = 0:=\nbegin\n  cases n with n hn,\n  {\n    sorry\n  },\n  {\n    sorry\n  },\nend\n\n\nlemma One_pow (n : ℕ) : 1 ^ n = 1:=\nbegin\n  sorry,\nend\n\n\nlemma Pow_add (a b c: ℕ): a^(b + c)=a^b*a^c:=\nbegin\n  induction c with c hc,\n  {\n    sorry\n  },\n  {\n    sorry\n  },\nend\n\nlemma Pow_mul (a b c : ℕ) : a^(b * c) = (a^b)^c :=\nbegin\n  sorry,\nend\n\n\nlemma Two_eq_one_add_one : 2 = 1 + 1:=\nbegin\n  sorry,\nend\n\nlemma Two_mul (n : ℕ) : 2*n = n + n:=\nbegin\n  sorry,\nend\n\nlemma Three_mul (n : ℕ) : 3*n = n + n + n:=\nbegin\n  have : 3 = 2 + 1, {\n    sorry,\n  },\n  sorry,\nend\n\nlemma Pow_two (n : ℕ) : n^2 = n*n:=\nbegin\n  sorry,\nend\n\nlemma Add_sq (a b : ℕ) : (a + b)^2 = a^2 + 2*a*b + b^2 :=\nbegin\n  sorry,\nend\n\nlemma Pow_three (n : ℕ) : n^3 = n*n*n:=\nbegin\n  have : 3 = 2 + 1, {\n    sorry,\n  },\n  sorry,\nend\n\nlemma Add_cube (a b : ℕ) : (a + b)^3 = a^3 + 3*a^2*b + 3*a*b^2 + b^3:=\nbegin\n  sorry, -- ring\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/4_numbers/nats_add_mul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7623253924846458}}
{"text": "/-\nThis cheat sheet summarizes the \ncrucial introduction and elimination\nreasoning rules for each connective \nand quantifier in predicate logic.\n\n* true\n* false\n* P ∧ Q\n* ∀ p : P, Q  -- predicate Q usually involves p\n* P → Q (view as function type)\n* P → Q (viewed as implication)\n* ¬ P\n* P ↔ Q\n* P ∨ Q\n* ∃ p : P, Q  -- predicate Q usually involves p\n\nIntroduction rules are used when\nyour goal is to prove a proposition \n(below the line or to the right of \nthe turnstile) that contains a given \nconnective or quantifier. For example,\nyou would use the introduction rule\nfor ∧ to prove a propopsition of the\nform, P ∧ Q.\n\nElimination rules are used to prove\nsomething else when you are given,\nas an assumption, a proof of a \nproposition that uses a given \nconnective or quantifier.  You would\nuse an elimination rule for ∧, for\nexample to prove P when you already\nhave a proof of P ∧ Q. \n-/\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n\nvariables P Q : Type\n#check (P → Q)\n\n/- **** -/\n/- true -/\n/- **** -/\n\n/-\nThe proposition, true, has\na single proof and can thus\nalways be judged to be true. \n\nThe introduction rule gives us\na proof without conditions.\n\n  ---------------- (true.intro)\n  true.intro: true\n\nHaving a proof of true isn't\nvery useful. One is always\navailable, and no information\ncan be obtained from a proof\nof true. We thus don't see a\nproof of true very often in\npractice.\n-/\n\n/- ----------------- -/\n/- true introduction -/\n/- ----------------- -/\n\n\ntheorem trueIsTrue : true := \n    true.intro\n\ntheorem \ntrueIsTrue' : true := \nbegin\nexact (true.intro),\nend\n\n/- ----------------- -/\n/- true elimination  -/\n/- ----------------- -/\n\n/-\nA proof of true, true.intro, doesn't tell\nyou anything meaningful, so a proof of true\nnever really helps to prove anything else.\nA proof of true is both free and worthless.\nElimination rules let you deduce something\nmeaningful from a proof of something else.\nFor example from a proof of P ∧ Q one can\nobtain a proof of P (which can be useful!).\nThere is thus no meaningful elimination \nrule for true.\n-/\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/-*******-/\n/- false -/\n/-*******-/\n\n/-\nThe proposition, false, has no\nproofs, and can thus be judged \nto be false. \n-/\n\n/- false introduction -/\n\n/-\nBecause there is no proof of false, \nthere is no introduction rule for \nfalse. \n-/\n\n/- false elimination -/\n\n/-\nOn the other hand, it often happens\nin real proofs that one ends up with \ninconsistent assumptions. When this\nhappens, it shows that in reality \nsuch a case can't occur. \n\nWhen one ends up in such a situation, \na proof of false can be derived from \nthe contradiction, and the elimination \nrule for false can then be used to \nfinish off the proof of the current \nproof goal.\n\nIt might seem a bit like magic that \nfalse elimination can be used to prove\nanything at all, but all that it really\nsays is \"we can safely ignore this case\nbecause it can never really happen.\"\n\nWhat the rule technically says is that\nfrom an assumed proof of false (or from \na proof of false that is obtained from \na contradiction), any proposition, P, \ncan be proved by applying false.elim to\nthe proof of false.\n\n  P : Prop, f : false\n  ------------------- false.elim\n        pf : P\n-/\n\ndef fromFalse (P: Prop) (f: false) : P :=\n    false.elim f\n\ntheorem fromFalse': ∀ P : Prop, false → P := \nλ P f, \n    false.elim f\n\ntheorem  fromFalse'': ∀ P : Prop, false → P := \nbegin\n  assume P,\n  assume f,\n  show P,\n  from false.elim f,\nend\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/-**** -/\n/- and -/\n/-**** -/\n\n/-\nIf P and Q are propositions, then\nP ∧ Q is a proposition. It is read\nas asserting that both P and Q are\ntrue. \n\nTo prove P ∧ Q, one applies the \nintroduction rule for ∧ to a proof \nof P and to a proof of Q. \n\n{ P, Q : Prop } (p: P) (q: Q)\n----------------------------- and.intro\n       ⟨ p, q ⟩ : P ∧ Q\n\nFrom a proof of P and Q one can derive \nproofs of P and of Q by applying the left\nand right elimination rules, respectively.\n\n{ P Q: Prop } (pq : P ∧ Q)\n--------------------------- and.elim_left\n          p : P\n\n\n{ P Q: Prop } (pq : P ∧ Q)\n--------------------------- and.elim_right\n          q : Q\n-/\n\n\n/- and introduction -/\n\ndef PandQ (P Q : Prop) (p: P) (q: Q) : P ∧ Q :=\n    and.intro p q\n\n#check PandQ -- P → Q → P ∧ Q\n\ntheorem PandQ' : ∀ ( P Q : Prop ), P → Q → P ∧ Q  := \nλ P Q p q, \n    ⟨ p, q ⟩ -- shorthand for and.intro p q\n\n#check PandQ'\n\ntheorem PandQ'' : ∀ { P Q : Prop }, P → Q → P ∧ Q := \nbegin\n  assume P Q p q,\n  show P ∧ Q,\n  from ⟨ p, q ⟩, -- again shorthand for and.intro p q\nend\n\n\n/- and elimination -/\n\ndef PfromPandQ (P Q: Prop) (pq: P ∧ Q) : P :=\n    and.elim_left pq\n\ndef QfromPandQ (P Q: Prop) (pq: P ∧ Q) : Q :=\n    and.elim_right pq\n\ntheorem PfromPandQ' : ∀ { P Q : Prop }, P ∧ Q → P := \nλ P Q pq, \n    pq.left -- shorthand for and.elim_left pq\n\ntheorem QfromPandQ' : ∀ { P Q : Prop }, P ∧ Q → Q := \nλ P Q pq, \n    pq.right -- shorthand for and.elim_right pq\n\ntheorem PfromPandQ'' : ∀ { P Q : Prop }, P ∧ Q → P := \nbegin\n  assume P Q pq, \n  show P,\n  from pq.left\nend \n\ntheorem QfromPandQ'' : ∀ { P Q : Prop }, P ∧ Q → Q := \nbegin\n  assume P Q pq, \n  show Q,\n  from pq.right\nend \n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- ********* -/\n/- functions -/\n/- ********* -/\n\n/-\nIf P and Q are arbitrary types (examples of which include\nbool, nat, and string), then P → Q is the type of a total \nfunction that takes, as an argument, any value of type P, \nand that always then returns some value of type Q. \n\nThe type judgment, f : P → Q, asserts that the identifier, \nf, will bound to a value of type, P → Q: that is to say, f \nis (bound to) some function that takes values of type P as \narguments and that returns values of type Q as results.\n\nTo \"prove\" (which means to provide a value of) type P → Q,\nyou have to provide a lambda abstraction that defines some\nparticular function from type P to type Q.\n-/\n\n/- → introduction -/\n\n/-\nTo \"prove\" a function type, P → Q, you provide a lambda\nabstraction that defines a particular function value of \nthis type. The particular lambda expressions selected as\na proof is significant, as their are many functions values\nof most function types. For example, a function that takes\na ℕ, n, and that returns n + 1, and a function that takes\na ℕ, n and returns n * n, are both of type ℕ → ℕ, but in\nmost cases would not be interchangeable in a program. So, \nwhen \"proving\" a function type, we're almost always very\ncareful to pick a specific function definition of interest\nas a proof.  \n-/\n\n/-\nFor example, we could exhibit a proof, inc, of ℕ → ℕ, \nwhich is to say that we could define a function, inc,\nthat simply increments its argument, with the lambda \nabstraction, λ n, n + 1. This is the function that \nadds one to its argument, n, of type ℕ. Let's look at\ndifferent ways this function can be defined in Lean.\n-/\n\n/-\nFirst, we define inc to be a value of type ℕ → ℕ,\nnamely the value, λ n : ℕ, n + 1.\n-/\n\ndef inc : ℕ → ℕ := λ n : ℕ, (n + 1 : ℕ)\n\n#check inc  -- type: ℕ → ℕ \n#reduce inc -- value/proof: λ n : ℕ, n + 1\n#check inc 3\n#reduce inc 3\n\n/-\nTypically we would drop explicit types in places where \nLean can infer them.\n-/\n\ndef inc' : ℕ → ℕ := λ n, n + 1\n\n/-\nWe can also write such a function in a more Python-like\nstyle.\n-/\n\ndef inc'' (n : ℕ) : ℕ := n + 1\n\n-- It really is the same function type and value\n#check inc''\n#reduce inc''\n\n/-\nAgain we can often simplify code by leaving out explicit types\n-/\n\ndef inc''' (n : ℕ) := n + 1\n\n/-\nWe can confirm that the type of this function is still ℕ → ℕ. \n-/\n\n#check inc'''\n\n/-\nYou must be able to express function values using both \nPython-like expressions and lambda abstractions. \n-/\n\n/-\nWe note that we can even construct function values\nusing tactic scripts.\n\nKnowing how to do this can be useful both in handling\nunexpected proof states, and might be useful for\nsome who like to create functions in an imperative style.\n-/\n\ndef inc'''' (n : ℕ) : ℕ := \nbegin\n  exact n + 1\nend \n\ndef inc''''' : ℕ → ℕ :=\nbegin\n  assume n,\n  show ℕ,\n  from n + 1\nend\n\n-- these are all exactly the same function\n#reduce inc\n#reduce inc'\n#reduce inc'''\n#reduce inc''''\n#reduce inc'''''\n\n\n/- multiple arguments -/\n\n/-\nIf P, Q, and R are types, then P → Q → R is\nalso a type. Because → is right associative,\nthis type can also be written as P → (Q → R).\nThis is the type of functions that take values\nof type P as arguments and that return values\nof type (Q → R) as results.  \n\nIf we have a function, f, of type P → Q → R,\nwe can apply it to a value p : P and get back\nsome function of type Q → R. \n\nSo the result of (f p) is a function of type \nQ → R. The function (f p) can thus be applied\nto an value, q, of type Q to obtain a result,\nr, of type R, with the expression (f p) q.\n\nBecause function application is left associative\nthe parenthesis can be dropped and you can just\nwrite f p q, giving the impression that f is a\nfunction that takes two arguments, one of type P\nand one of type Q (and that then returns a value\nof type R).\n\nHere's an example.\n-/\n\ndef plus (n m: ℕ) : ℕ := n + m\n\n#check plus\n#reduce plus\n\n#check plus 3\n#reduce plus 3 -- a function taking one argument!\n\n#reduce (plus 3) 4 -- that function applied to 4\n#reduce plus 3 4 -- the parentheses were redundant\n\n/-\nThe following section addresses implication, \nwhere, if P and Q are propositions, P → Q, is\nthe logical implication, if there is a proof of\nP then a proof of Q can be constructed. A proof\nof this proposition is given by any function of \ntype P → Q. \n\nEverything in this section about function types \nand values/implementations (lambda expressions)\napplies to implications, so bear the lessons of\nthis section in mind as you read the next one.\n-/\n\n/- → elimination -/\n\n/-\nThe elimination rule for functions is easy. The\napplication of a function, f : P → Q, to a value,\np : P, will produce a value of type Q. \n-/\n\n#check inc 3\n#reduce inc 3\n\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- *********** -/\n/- implication -/\n/-************ -/\n\n/-\nIf P and Q are propositions, then P → Q\nis a proposition. It read as asserting\nthat if P is true then Q is true. \n\nTo prove P → Q, one must show that there\nis a (total) function that, when given a \nproof of P as an argument, constructs a\nproof of Q as a result. NB: Functions can\nbe defined to take argument of types that\nhave no value! See the false elimination\nexamples above. It is very important to\nunderstand that P → Q being true does not \nnecessarily mean that P is true, but only\nthat *if* P is true (there is a proof of \nP) then Q is true (a proof of Q can be \nconstructed).\n\nTo prove P → Q, provide a function that\nshows that from an assumed proof of P\none can construct a proof of Q. The type\nof such a function is P → Q. \n-/\n\n-- implication introduction\n\ndef falseImpliesTrue (f : false) : true :=\n    true.intro\n\n#check falseImpliesTrue\n\nexample : false → true :=\n    λ f : false, true.intro\n\nexample : false → true :=\n    falseImpliesTrue\n\n/- → implication elimination -/\n\n/-\nFrom a proof of P → Q and a proof of P \none can derive a proof of Q. This is done\nby \"applying\" the proof of the implication\n(which in Lean is a function) to the proof\nof P, the result of which is a proof of Q.\n\n(P Q : Prop) (p2q: P → Q) (p : P)\n--------------------------------- → elim\n         (p2q p) : Q\n-/\n\ndef arrowElim {P Q : Prop} (p2q: P → Q) (p : P) : Q :=\n    p2q p \n\ntheorem arrowElim': ∀ { P Q : Prop}, (P → Q) → P → Q :=\nλ P Q p2q p, \n    p2q p\n\ntheorem arrowElim'': ∀ { P Q : Prop}, (P → Q) → P → Q :=\nbegin\n  assume P Q p2q p,\n  show Q,\n  from p2q p\nend\n\n\n/- ********** -/\n/- forall (∀) -/\n/- ********** -/\n\n/-\nIf P is a type and Q is a predicate,\nthen ∀ p : P, Q is a proposition. It\nis read as stating that the predicate,\nQ, is true for any value, p, in the \nset of values (domain of discourse)\ngiven by the type, P. The predicate,\nQ, is usually one that takes a value\nof type, P, as an argument, but this\nis not always the case. For example,\none could write, ∀ n : ℕ, true. Here\nthe predicate, true, is a predicate\nthat takes no arguments at all, and\nso it is simply a proposition, and it\nis true for every value of n, so the \nproposition, ∀ n : ℕ, true, is true.\nMore commonly, the predicate part of\na universally quantified proposition\nwill be \"about\" the values over which\nthe quantification ranges. Here is an\nexample: \n\n∀ n : ℕ : (n > 2 ∧ prime n) → odd n\n\nThis proposition asserts that any n\ngreater than 2 and prime is also odd\n(which also happens to be true). The\npredicate, (n > 2 ∧ prime n) → odd n,\nin this case takes n as an argument,\nand is thus \"about\" each of the values\nover which the ∀ ranges.\n-/\n\n/- ∀ introduction -/\n\n/-\nTo prove a proposition, ∀ p : P, Q, \nassume an arbitrary value, p : P,\nand shows that the predicate, Q, is\ntrue for that assumed value. As the\nvalue was chosen arbitrarily, it thus\nfollows that the predicate is true\nfor *any* such value, proving the ∀.  \n\nTo see this principle in action, \nstudy the following proof script.\n-/\n\ntheorem allNEqualSelf: ∀ n : ℕ, n = n :=\nbegin\n  assume n, -- assume an arbitrary n\n  show n = n, -- show predicate true for n\n  from rfl, -- thus proving ∀ n, n = n\nend\n\n/- ∀ elimination -/\n\n/-\n∀ elimination reasons that if some\npredicate, Q, is true for every value of \nsome type, then it must also be true for \nany particular value of that type. So \nfrom a proof, p2q, of ∀ P, Q and a proof,\np : P, we conclude Q. \n\nP : Type, Q : P → Prop, p2q : ∀ p : P, Q, p : P\n-----------------------------------------------\n            (p2q p) :  Q p\n\nForall elimination is just another form \nof arrow elimination. In constructive \nlogic this is function application. Study \nthe following examples carefully to see \nhow this works.\n-/\n\ndef forallElim (p2q: ∀ n : nat, n = n) (p : nat) : p = p :=\n    p2q p\n\ndef forallElim' (p2q: ∀ n : nat, n = n) (p : nat) : p = p :=\nbegin\n  exact (p2q p)\nend\n\n#reduce forallElim allNEqualSelf 7\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- ************** -/\n/- ** Negation ** -/\n/- ************** -/\n\n/-\nIf P is a proposition, then ¬ P is one, too.\nWe read ¬ P as asserting that P is false. In\nconstructive logic this means that there is\nno proof of P. In constructive logic, ¬ P is\nthus actually defined as P → false. So ¬ P\nmeans P → false, and a proof of ¬ P is just\na proof of P → false. \n\n\nTo prove ¬ P, one thus assumes a proof of P\nand shows that, in that context, one can \nconstruct a proof of false. That is, one\nexhibits a function that takes a proof of \nP as an argument and constructs and returns\na proof of false as a result. \n\nThis is the introduction rule for ¬. Another \nway to say this: To prove ¬ P, assume P and \nshow that this leads to a contradiction.\n\nThis is of course just the principle of proof\nby negation, equivalent to the introduction \nrule for false.\n\nP: Prop, f2p : P → false\n------------------------ false introduction\n        np : ¬ P\n\nWe discuss the elimination rule for ¬ below.\nThe key idea is that it's really a rule for\ndouble negation elimination, and it requires\nclassical reasoning. More on this later.\n-/\n\n\n-- negation introduction \n\n/-\nThat Lean accepts the following function definition\nshows that a proof of P → false *is* a proof of ¬ P\n-/\n\ndef notIntro (P : Prop) (p2f: P → false) : ¬P :=\n    p2f \n\n/-\nAn equivalent proof script.\n-/\ntheorem notIntro':\n ∀ P : Prop, (P → false) → ¬P :=\nbegin\n  assume P : Prop,\n  assume p2f : P → false,\n  show ¬P,\n  from p2f\nend\n\n/- \nExample: from the assumption that a \nproposition, P, is true, we can deduce \nthat ¬ ¬ P is true, as well. This is\na rule for double negation introduction,\nthough not a rule that is commonly needed.\n-/\n\ntheorem doubleNegIntro : ∀ P : Prop, P → ¬¬P :=\nbegin\n  assume P : Prop,\n  assume p : P,\n  assume np : ¬P, -- ¬¬P means ¬P → false, so assume ¬P\n  show false,\n  --from np p,\n  contradiction,\nend\n\ntheorem doubleNegIntro' : ∀ P : Prop, P → ¬¬P :=\n    λ P p np, \n        np p\n\n\n/- negation elimination -/\n\n/-\nThe rule for negation elimination in\nnatural deduction is really a rule \nfor double negation elimination: it\nstates that, ∀ P : Prop, ¬ (¬ P) → P. \nBecause ¬ is right associative, we \ncan drop the parenthesis: ¬ ¬ P → P.\n\nThis rule is not valid in constructive \nlogic. You can't prove the following \nunless you also accept the axiom of \nthe excluded middle, or equivalent.\n-/\n\nexample: ∀ P : Prop, ¬¬P → P :=\nbegin\n  assume P nnp,\n  /- \n  No way to get from ¬¬P to P.\n  stuck and giving up on this proof.\n  -/\n  end \n\n/-\nHowever, if we accept the axiom of the \nexcluded middle, which we can do by \n\"opening\" Lean's \"classical\" module, \nthen we can prove that double negation \nelimination is valid. \n-/\n\nopen classical\n#check em\n\n/-\nNow em is the axiom of the excluded middle.\nWhat em tells us is that if P is any\nproposition, then either one of P or ¬ P is \ntrue, and there are no other possibilities. \n\nAnd from em we can now prove double negation \nelimination.  The proof is by \"case analysis.\" \nWe consider each of the two possible cases for \nP (true and false) in turn. \n\nIf we assume P is true, then we are done, \nas our goal is to show P (from ¬ ¬ P). On \nthe other hand, if we assume P is false, \ni.e., ¬ P, then we reach a contradiction.\nWe have already assumed ¬ ¬ P is true and\nwe are trying to prove P. But now if we\nalso assume that ¬ P is true, then clearly\nwe have a contradiction (between ¬ P and \n¬ ¬ P). Using false elimination finishes\nthis case leaving us with the conclusion\nthat P is true in either case.\n-/\n\ntheorem doubleNegationElim: \n ∀(P : Prop), ¬¬P → P :=\nbegin\n  assume P nnp,\n  show P,\n  from \n    begin\n        -- preview: we study case analysis later\n        -- proof by case analysis for P\n        cases (em P) with pf_P pf_nP, -- (em P) is (P ∨ ¬ P)\n        -- case with P is assumed to be true\n        exact pf_P,\n        -- case with P is assumed to be false\n        exact false.elim (nnp pf_nP)\n        -- em says there are no other cases\n    end,\nend \n\n/-\nDouble negation elimination is the fundamental\noperation needed in a proof by contradiction. \nIn a proof by contradiction, on tries to prove\nP by assuming ¬ P and showing that that leads\nto a contradiction, thus to a proof that ¬ P\nis not true, that is, ¬ (¬ P). The negation\nelimination rule lets us then conclude P. \n-/\n\n/-\nNote: The law of the excluded middle\nallows you to conclude P ∨ ¬ P \"for free,\" \nwithout giving a proof of either P or of\n¬ P. It is in this precise sense that em\nis not \"constructive.\" When using em, you\ndo not build a \"bigger\" proof (of P ∨ ¬ P)\nfrom one or more \"smaller\" proofs (of P or \nof ¬ P). Whereas constructive proofs are\n\"informative,\" in that they contain the\nsmaller proofs needed to justify a given\nconclusion, classical proofs are not, in\ngeneral. Accepting that P ∨ ¬ P by using\nem gives you a proof but such a proof does \nnot tell you anything at all about which\ncase is true, whereas a constructive proof\ndoes.\n-/\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- *************** -/\n/- bi-implication  -/\n/- *************** -/\n\n/-\nIf P and Q are propositions then so is P ↔ Q.\nWe read P ↔ Q as asserting P → Q ∧ Q → P. To\nprove P ↔ Q, we have to provide proofs of both\nconjunctions, and from a proof of P ↔ Q we can\nobtain proofs of P → Q and of Q → P by use of\nthe elimination rule for ↔.\n\nThe ↔ symbol is pronounced as is equivalent \nto,\" or as \"if and only if,\" In mathematical \nwriting it is often written as \"iff\". And to \nget the ↔ symbol in Lean, use backslash-iff.\n\nIts introduction and elimination rules are \nequivalent to those for conjunction, but \nspecialized to the case where each of the \nconjuncts is an implication and where one \nis the other going in the other direction.\n-/\n\n/- iff introduction -/\n\n/-\nTo prove P ↔ Q (introduction), apply iff.intro\nto proofs of P and Q. \n\n(P Q : Prop), (pq : P → Q) (qp : Q → P)\n--------------------------------------- iff.intro\n        pqEquiv: P ↔ Q\n    -/\n\ntheorem iffIntro:\n  ∀(P Q: Prop), (P → Q) → (Q → P) → (P ↔ Q) :=\nbegin\n  assume P Q : Prop,\n  assume p2q q2p,\n  apply iff.intro p2q q2p\nend\n\ntheorem iffIntro':\n  ∀(P Q : Prop), (P → Q) → (Q → P) → (P ↔ Q) :=\nλ P Q pq qp, \n    iff.intro pq qp\n\ntheorem iffIntro'':\n  ∀(P Q: Prop), (P → Q) → (Q → P) → (P ↔ Q) :=\nbegin\n  assume P Q : Prop,\n  assume p2q q2p,\n  apply iff.intro,\n    exact p2q,\n    \n    exact q2p\nend\n\n/- iff elimination -/\n\n/-\nSimilarly, the left and right iff elimination \nrules are equivalent to the and elimination \nrules but for the special case where the \nconjunction is a bi-implication in particular.\n-/\n\ntheorem iffElimLeft:\n  ∀(P Q : Prop), (P ↔ Q) → P → Q :=\nbegin\n  assume P Q : Prop,\n  assume bi : P ↔ Q,\n  show P → Q,\n  from iff.elim_left bi -- bi.1 is a shorthand\nend\n\n\ntheorem iffElimLeft':\n  ∀(P Q : Prop), (P ↔ Q) → P → Q :=\nλ P Q bi, \n    iff.elim_left bi\n\ntheorem iffElimRight:\n  ∀(P Q : Prop), (P ↔ Q) → Q → P :=\nλ P Q bi, \n    iff.elim_right bi\n\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- **************** -/\n/- or (disjunction) -/\n/- **************** -/\n\n/-\nIf P and Q are propositions, then so is P ∨ Q.\nP ∨ Q asserts that at least one of P, Q is true,\nbut it does not indicate which case holds.\n-/\n\n/- introduction rules for or -/\n\n/-\nTo prove P ∨ Q, in constructive logic\none either applies the or.intro_left rule\nto a proof of P or the or.intro_right rule\nto a proof of Q. In either case, one must\nalso provide, as the first argument, the\nproposition that is not being proved. The\nshorthand or.inl and or.inr rules infer\nthese propositional arguments and are\neasier and clearer to use in practice.\n-/\n\ntheorem orIntroLeft (P Q : Prop) (p : P) : P ∨ Q :=\n    or.intro_left Q p -- args: proposition Q, proof of P\n\ntheorem orIntroLeft': forall P Q: Prop, P → (P ∨ Q) :=\nλ P Q p, \n    or.inl p -- shorthand\n\ntheorem orIntroLeft'' (P Q : Prop) (p : P) : P ∨ Q :=\nbegin\n  apply or.intro_left,\n  assumption\nend\n\ntheorem orIntroRight: forall P Q: Prop, Q → (P ∨ Q) :=\nλ P Q q, \n    or.inr q\n\n\n/- or elimination -/\n\n/-\nThe elimination rule for or says that if\n(1) P ∨ Q is true, (2) P → R, and (3) Q → R,\nthen you can conclude R. \n\nThe reasoning in by \"case analysis.\" In\none case, if P ∨ Q because P is, then use \nP → R to prove R. Otherwise, if P ∨ Q is \ntrue because Q is, then use Q → R to prove\nR. Usually you don't know which case holds\nso to prove R from P ∨ Q you have to show\nthat R follows \"in either case\", and to \ndo that, you need both P → R and Q → R.\n\npfPQ: P ∨ Q, pfPR: P → R, pfQR: Q → R\n-------------------------------------- or.elim\n                 R\n                 \nSo, for example if (1) \"it's raining or the \nfire hydrant is running\" (P ∨ Q), (2)\"if it's \nraining then the streets are wet\", and (3)  \n\"if the fire hydrant is running then the \nstreets are wet\", then the streets are wet!\n-/\n\ntheorem orElim : \n  ∀(P Q R: Prop), \n    (P ∨ Q) → (P → R) → (Q → R) → R \n:=\nbegin\n  assume P Q R,\n  assume PorQ: (P ∨ Q),\n  assume pr: (P → R),\n  assume qr: (Q → R),\n  show R,\n  from or.elim PorQ pr qr \nend\n\ntheorem orElim' : \n  ∀(P Q R: Prop), \n    (P ∨ Q) → (P → R) → (Q → R) → R \n:=\nbegin\n  assume P Q R,\n  assume PorQ: (P ∨ Q),\n  assume pr: (P → R),\n  assume qr: (Q → R),\n  show R,\n  from \n    -- compare carefully with previous example\n    begin\n      cases PorQ with p q,\n        exact (pr p),\n        exact (qr q)\n    end  \nend\n\n-- Same proof, different identifiers\ntheorem orElimExample' : \nforall Rain Hydrant Wet: Prop, \n    (Rain ∨ Hydrant) → -- raining or hydrant on;\n    (Rain → Wet) →     -- if raining then wet;\n    (Hydrant → Wet) →  -- if hydrant on then wet;\n    Wet                -- then wet\n:=\nbegin\n-- setup\n  assume Rain Hydrant Wet,\n  assume RainingOrHydrantRunning: (Rain ∨ Hydrant),\n  assume RainMakesWet: (Rain → Wet),\n  assume HydrantMakesWet: (Hydrant → Wet),\n-- the core of the proof\n  cases RainingOrHydrantRunning with raining running,\n    show Wet, from RainMakesWet raining,\n    show Wet, from HydrantMakesWet running,\nend\n\n/-\nNote: The axiom of the excluded middle allows\nus to do case analysis even if we don't have an\nexplicit disjunction to work with, because we\ncan always apply em to any proposition P to get\na proof of P ∨ ¬ P.\n\nHere's an example. (There is a more direct\nproof, but we're showing how to apply em to a\nproposition to get a disjunction to do case\nanalysis on.\n-/\nopen classical\n\nexample : ∀(P : Prop), P ∨ ¬ P :=\nbegin\n  assume P : Prop,\n  cases (em P) with p np,   --(em P) is a proof of P ∨ ¬ P\n    exact or.inl p,         -- case where P assumed true\n    exact or.inr np,        -- case where ¬ P assumed true\nend\n\nexample : ∀(P : Prop), P ∨ ¬ P :=\nbegin\n  assume P : Prop,\n  apply em P\nend\n\n/-\nGo back and without fail see where\nthis trick was used to prove one of\nthe DeMorgan laws and the validity of\ndouble negation elimination.\n-/\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- ********** -/\n/- Predicates -/\n/- ********** -/\n\n/-\nA predicate is a proposition with parameters\nwhose values need to be supplied to reduce the\npredicate to a proposition.\n\nFor example, even (n : ℕ) : Prop, could be \na predicate that takes a value, n : ℕ, and\nthat reduces to a proposition that in general\nwill assert something about the particular n\nthat was supplied as an argument.\n\nSo, even 3, for example would reduce to the\nproposition that we would interpret as \"three\nis even\", while \"even 7\" would be (reduce to)\na proposition that 7 is even. \n\nWe formalize predicates as functions that\ntake arguments and that return propositions\nabout those arguments. If this is unclear,\nre-read the preceding paragraph.\n\nA predicate thus generates a whole family\nof propositions, one for each combination \nof values of its arguments. The \"even n\"\npredicate, for example, gives rise to a\nwhole family of propositions, one for each\nℕ value of n.\n\nNote that you can think of a predicate with\nno parameters as just a proposition. \n\nA predicate with one parameter can be read\nas defining a \"property\" of the values of\nits argument type. A sensibly defined even n\npredicate, for example, will generate a\nproposition that is true for every even\nnatural number and that is false for every\nodd natural number. \n\nSuch a predicate can also be understood to \ndefine a set, namely the set of all values\nfor which the corresponding propositions are\ntrue.\n\nA predicate with multiple parameters can\nbe read as defining a property of, and thus\na set of, ordered pairs (for two arguments)\nor more generally tuples of arguments. We\ncall a set of pairs (or tuples) a relation.\n\nAs an example, a predicate \"lessThan m n\"\ncould be defined to reduce to a proposition\nthat is true whenever m is less than n and\nthat is false otherwise. This predicate \nimplicitly \"picks out\" the set of (m, n)\npairs where m is less than n and excludes\nall pairs where m is not less than n. The\npair (3, 4) is in the lessThan relation in\nthat the proposition, lessThan 3 4, would \nbe true, while (4, 3) would not be in the\nrelation, in that \"lessThan 4 3\" would not\nbe a true/provable proposition.\n\nWe formalize predicates as functions from\nargument values to propositions. Here are \nsome examples.\n-/\n\n/-\nFirst, we define zEqz as a predicate\nwith no arguments. That is to say, it\nis just a plain old proposition. No\nmore need be said.\n-/\ndef zEqz : Prop := 0 = 0\n\n/-\nNext, we generalize by making one of\nthe zero values into a parameter. The\npredicate, when provided with a value\nfor n, reduces to the proposition that\nthat zero is equal to that particular\nn. -/\n\ndef nEqz (n : ℕ) : Prop := 0 = n\n\n\n/-\nNote that we could have written this \ndefinition using a lambda abstraction. \nA benefit is that this way of writing\nthe same thing makes the nature of \nzEqz'clear by expressing its type \nexplicitly: ℕ → Prop.\n-/\ndef nEqz' : ℕ → Prop := λ n, 0 = n\n\n/-\nThe only value of n that satisfies this\npredicate, in the sense that it makes the\ncorresponding proposition true, is n = 0.\nThis predicate thus implicitly represents\nthe set, { 0 }. \n-/\n\n/-\nWe can further generalize this predicate\nby making both values to be compared into\narguments.\n-/\n\ndef nEqm (n m: ℕ) : Prop := n = m\n\ndef isSquare (n m : ℕ) := n^2 = m\n\n#check isSquare\n#check isSquare 3 9\n#reduce isSquare 3 9\n\n\n\n/- *****************************************-/\n/- *****************************************-/\n/- *****************************************-/\n\n/- ******* -/\n/- Exists  -/\n/- ******* -/\n\n/-\nIf P is a type and Q is a predicate, \nthen ∃ p : P, Q is a proposition. It \nasserts that there is some value, \np : P, that makes the predicate, Q, \ntrue.\n-/\n\n/- ∃ introduction -/\n\n/-\nTo prove a proposition of the form,\n∃ p : P, Q, one must provide two things:\n(1) a specific value, w : P, that we\noften call a \"witness\", and a proof that \nQ is true for that specific w.\n\nSo, for example, to prove that there\nexists an object, o, that is a cat, it\nwould suffice to exhibit some object\n(the witness), let's call it Nifty, and\na proof, pf, of the proposition, Nifty\nis a cat. Then the pair, ⟨ nifty, pf ⟩ \nwould be a proof of ∃ o: Object, Cat o. \n\nThe proposition, ∃ o: Object, Cat o, does \nnot refer to Nifty or any other object in \nparticular. It just asserts that *some*\nobject out there is a cat. To prove it,\nthough, you do need to exhibit a specific\nobject and give a proof that that object\nis a cat. You can then conclude that there\nis some object that is a cat.\n\nHere's the exists.intro rule, after which \nwe give some very simple examples of how it\nwould be used in code.\n\n(T : Type), (P : T → Prop), (t : T), (pf: P t)\n---------------------------------------------- exists.intro\n          ⟨ t, pf ⟩ : exists t : T, P t\n-/\n\n#check exists.intro\n\ntheorem existsIntro :\n  ∀(T : Type),     -- suppose T is a type\n  ∀(P : T → Prop), -- suppose P is a property of values of type T\n/-\nnow if for any t : T, we can show that t has property P,\nthen we can construct a proof that *there exists* an x : T \nwith property P\n-/\n  ∀(t : T), (P t) → ∃ x : T, P x\n:=\nbegin\n  assume T: Type,         -- assume T is some type\n  assume P: T → Prop,     -- and P is a property\n-- show that if there's a t with property P (P t), the ∃ is true\n  show ∀ (t : T), P t → (∃ (x : T), P x), from\n    begin\n      assume t : T,           -- assume t is some object of type T\n      assume pf : P t,        -- and that t has property P\n      show ∃ x, P x, from     -- now we can show ∃ x, P x\n        (exists.intro t pf) -- using exists.intro\n    --  ⟨ t, pf ⟩  would be a shorthand for (exists.intro t pf)\n    end,\nend\n\n\n/- existential elimination -/\n\n/-\nThe reasoning about existential elimination goes\nlike this. If we know that (∃ x : T, P x), that\nthere is some value, x of type T with property P, \nthen we can temporarily assume that there is some \nspecific value, that we will call it by an otherwise \nunused name, u, where u has property P, which is to\nsay that we also have a proof of (P u).\n\nIf the meaning of \"a proof of (P u)\" doesn't make\nsense, go back and review the class material on \npredicates. P is a predicate, i.e., a function \nfrom T to Prop, u is the name we've given to some\nvalue of type T with property P such that u has\nproperty P, which is to say there is a proof of \nthe proposition, (P u).\n\nNow, if from u and a proof of (P u) we can \nconstruct a proof of some proposition S (a\nproposition that does not involve u in any\nway), then we can conclude that S follows from\nthe mere existence of such a u, i.e., from the\ntruth of ∃ x : T, P x.  \n\nHere is slightly simplified version of the \nexists.elim rule.\n\n{T : Type}, {P : T → Prop}, {Q : Prop}, (ex: ∃ x : T, P x) (p2q: ∀ t : T, P t → Q)\n---------------------------------------------------------------------------------- ∃.intro\n                                    q : Q\n\nLet's unpack this. The assumptions are that T \nis any type and P is any property of values of\nthat type. Q is the proposition that we want to\nprove follows from ∃ x : T, P x. The additional\nfact that is needed to conclude that Q is true\nis a proof, p2q, f that if any t : T has property \nP, then Q follows. If we combine this fact, p2q,\nwith the fact, ex, that there exists such a t,\nthen we can conclude that Q must be true.\n-/\n\n#check exists.elim\n\n/-\nHere's some code that illustrates the use of \nthe exists.elim principle in Lean.\n-/\n\ndef existElimExample\n(T : Type)                      -- Suppose T is any type\n(P S : T → Prop)                -- and P, S are properties of T\n(ex : exists x, P x ∧ S x)      -- and there is an x with P and S\n: (exists y, S y ∧ P y)         -- show there is a y with P\n:=\nbegin\n/-\nThe only thing we have to work with is ex. So we will \napply exists.elim to it. We supply the first argument,\nnamely the proof of exists x, P x ∧ Q x-/\n  apply exists.elim ex,\n/-\nWhat we then have to provide is the proof required as\nthe second argument to exists.elim. This is a proof of\nthe proposition that that for any object, a : T, if a\nhas properties P and S, then (∃ (y : T), S y ∧ P y) is\ntrue. We will now prove this proposition to finish off\nthe proof. What we have to prove is an implication, so\nwe will start by assuming its premises: that a is some \nvalue of type T and that we have a proof that a has the\nproperties P and S.\n-/\n  assume w : T,\n  assume pfa : P w ∧ S w,\n\n/- \nGiven these assumption we now need to show the final\nconclusion, that (∃ (y : T), S y ∧ P y). This is a job\nfor exists.intro. The arguments we will give it are, \na, as a witness, and a proof of (S a ∧ P a) as a proof.\nThat is then all that we need to prove the final goal, \n(∃ (y : T), S y ∧ P y), using exists.intro.  \n-/\n    show (∃ (y : T), S y ∧ P y), from\n    begin\n        have pa := pfa.left,\n        have qa := pfa.right,\n        have qp := and.intro qa pa,\n        exact exists.intro w qp,\n    end,\nend ", "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/CheatSheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7623253892291387}}
{"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 tactic.noncomm_ring\nimport field_theory.is_alg_closed.basic\nimport algebra.star.pointwise\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 → A`: the resolvent function is `λ r, ring.inverse (↑ₐr - a)`, and hence\n  when `r ∈ resolvent R A`, it is actually the inverse of the unit `(↑ₐr - 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 `σ (a*b)` coincide with those in `σ (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* `σ a` : `spectrum R a` of `a : A`\n-/\n\nuniverses u v\n\n\nsection defs\n\nvariables (R : Type u) {A : Type v}\nvariables [comm_semiring R] [ring A] [algebra R A]\n\nlocal notation `↑ₐ` := algebra_map R A\n\n-- definition and basic properties\n\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•1 - a` is a unit of the\nalgebra `A`.  -/\ndef resolvent_set (a : A) : set R :=\n{ r : R | is_unit (↑ₐr - a) }\n\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•1 - 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(resolvent_set R a)ᶜ\n\nvariable {R}\n/-- Given an `a : A` where `A` is an `R`-algebra, the *resolvent* is\n    a map `R → A` which sends `r : R` to `(algebra_map R A r - a)⁻¹` when\n    `r ∈ resolvent R A` and `0` when `r ∈ spectrum R A`. -/\nnoncomputable def resolvent (a : A) (r : R) : A :=\nring.inverse (↑ₐr - a)\n\n/-- The unit `1 - r⁻¹ • a` constructed from `r • 1 - a` when the latter is a unit. -/\n@[simps]\nnoncomputable def is_unit.sub_inv_smul {r : Rˣ} {s : R} {a : A}\n  (h : is_unit $ r • ↑ₐs  - a) : Aˣ :=\n{ val := ↑ₐs - r⁻¹ • a,\n  inv := r • ↑h.unit⁻¹,\n  val_inv := by rw [mul_smul_comm, ←smul_mul_assoc, smul_sub, smul_inv_smul, h.mul_coe_inv],\n  inv_val := by rw [smul_mul_assoc, ←mul_smul_comm, smul_sub, smul_inv_smul, h.coe_inv_mul], }\n\n-- products of scalar units and algebra units\nlemma is_unit.smul_sub_iff_sub_inv_smul {r : Rˣ} {a : A} :\n  is_unit (r • 1 - a) ↔ is_unit (1 - r⁻¹ • a) :=\nby rw [←@is_unit_smul_iff _ _ _ _ _ _ _ r (1 - r⁻¹ • a), smul_sub, smul_inv_smul]\n\nend defs\n\nnamespace spectrum\nopen_locale polynomial\n\nsection scalar_ring\n\nvariables {R : Type u} {A : Type v}\nvariables [comm_ring R] [ring A] [algebra R A]\n\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma mem_iff {r : R} {a : A} :\n  r ∈ σ a ↔ ¬ is_unit (↑ₐr - a) :=\niff.rfl\n\nlemma not_mem_iff {r : R} {a : A} :\n  r ∉ σ a ↔ is_unit (↑ₐr - a) :=\nby { apply not_iff_not.mp, simp [set.not_not_mem, mem_iff] }\n\nlemma mem_resolvent_set_of_left_right_inverse {r : R} {a b c : A}\n  (h₁ : (↑ₐr - a) * b = 1) (h₂ : c * (↑ₐr - a) = 1) :\n  r ∈ resolvent_set R a :=\nunits.is_unit ⟨↑ₐr - a, b, h₁, by rwa ←left_inv_eq_right_inv h₂ h₁⟩\n\nlemma mem_resolvent_set_iff {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (↑ₐr - a) :=\niff.rfl\n\nlemma resolvent_eq {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  resolvent a r = ↑h.unit⁻¹ :=\nring.inverse_unit h.unit\n\nlemma units_smul_resolvent {r : Rˣ} {s : R} {a : A} :\n  r • resolvent a (s : R) = resolvent (r⁻¹ • a) (r⁻¹ • s : R) :=\nbegin\n  by_cases h : s ∈ spectrum R a,\n  { rw [mem_iff] at h,\n    simp only [resolvent, algebra.algebra_map_eq_smul_one] at *,\n    rw [smul_assoc, ←smul_sub],\n    have h' : ¬ is_unit (r⁻¹ • (s • 1 - a)),\n      from λ hu, h (by simpa only [smul_inv_smul] using is_unit.smul r hu),\n    simp only [ring.inverse_non_unit _ h, ring.inverse_non_unit _ h', smul_zero] },\n  { simp only [resolvent],\n    have h' : is_unit (r • (algebra_map R A (r⁻¹ • s)) - a),\n      { simpa [algebra.algebra_map_eq_smul_one, smul_assoc] using not_mem_iff.mp h },\n    rw [←h'.coe_sub_inv_smul, ←(not_mem_iff.mp h).unit_spec, ring.inverse_unit, ring.inverse_unit,\n      h'.coe_inv_sub_inv_smul],\n    simp only [algebra.algebra_map_eq_smul_one, smul_assoc, smul_inv_smul], },\nend\n\nlemma units_smul_resolvent_self {r : Rˣ} {a : A} :\n  r • resolvent a (r : R) = resolvent (r⁻¹ • a) (1 : R) :=\nby simpa only [units.smul_def, algebra.id.smul_eq_mul, units.inv_mul]\n  using @units_smul_resolvent _ _ _ _ _ r r a\n\n/-- The resolvent is a unit when the argument is in the resolvent set. -/\nlemma is_unit_resolvent {r : R} {a : A} :\n  r ∈ resolvent_set R a ↔ is_unit (resolvent a r) :=\nis_unit_ring_inverse.symm\n\nlemma inv_mem_resolvent_set {r : Rˣ} {a : Aˣ} (h : (r : R) ∈ resolvent_set R (a : A)) :\n  (↑r⁻¹ : R) ∈ resolvent_set R (↑a⁻¹ : A) :=\nbegin\n  rw [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one, ←units.smul_def] at h ⊢,\n  rw [is_unit.smul_sub_iff_sub_inv_smul, inv_inv, is_unit.sub_iff],\n  have h₁ : (a : A) * (r • (↑a⁻¹ : A) - 1) = r • 1 - a,\n  { rw [mul_sub, mul_smul_comm, a.mul_inv, mul_one], },\n  have h₂ : (r • (↑a⁻¹ : A) - 1) * a = r • 1 - a,\n  { rw [sub_mul, smul_mul_assoc, a.inv_mul, one_mul], },\n  have hcomm : commute (a : A) (r • (↑a⁻¹ : A) - 1), { rwa ←h₂ at h₁ },\n  exact (hcomm.is_unit_mul_iff.mp (h₁.symm ▸ h)).2,\nend\n\nlemma inv_mem_iff {r : Rˣ} {a : Aˣ} :\n  (r : R) ∈ σ (a : A) ↔ (↑r⁻¹ : R) ∈ σ (↑a⁻¹ : A) :=\nbegin\n  simp only [mem_iff, not_iff_not, ←mem_resolvent_set_iff],\n  exact ⟨λ h, inv_mem_resolvent_set h, λ h, by simpa using inv_mem_resolvent_set h⟩,\nend\n\nlemma zero_mem_resolvent_set_of_unit (a : Aˣ) : 0 ∈ resolvent_set R (a : A) :=\nby { rw [mem_resolvent_set_iff, is_unit.sub_iff], simp }\n\nlemma ne_zero_of_mem_of_unit {a : Aˣ} {r : R} (hr : r ∈ σ (a : A)) : r ≠ 0 :=\nλ hn, (hn ▸ hr) (zero_mem_resolvent_set_of_unit a)\n\nlemma add_mem_iff {a : A} {r s : R} :\n  r ∈ σ a ↔ r + s ∈ σ (↑ₐs + a) :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff],\n  have h_eq : ↑ₐ(r + s) - (↑ₐs + a) = ↑ₐr - a,\n    { simp, noncomm_ring },\n  rw h_eq,\nend\n\nlemma smul_mem_smul_iff {a : A} {s : R} {r : Rˣ} :\n  r • s ∈ σ (r • a) ↔ s ∈ σ a :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one],\n  have h_eq : (r • s) • (1 : A) = r • s • 1, by simp,\n  rw [h_eq, ←smul_sub, is_unit_smul_iff],\nend\n\nopen_locale pointwise polynomial\n\ntheorem unit_smul_eq_smul (a : A) (r : Rˣ) :\n  σ (r • a) = r • σ a :=\nbegin\n  ext,\n  have x_eq : x = r • r⁻¹ • x, by simp,\n  nth_rewrite 0 x_eq,\n  rw smul_mem_smul_iff,\n  split,\n    { exact λ h, ⟨r⁻¹ • x, ⟨h, by simp⟩⟩},\n    { rintros ⟨_, _, x'_eq⟩, simpa [←x'_eq],}\nend\n\ntheorem left_add_coset_eq (a : A) (r : R) :\n  left_add_coset r (σ a) = σ (↑ₐr + a) :=\nby { ext, rw [mem_left_add_coset_iff, neg_add_eq_sub, add_mem_iff],\n     nth_rewrite 1 ←sub_add_cancel x r, }\n\n-- `r ∈ σ(a*b) ↔ r ∈ σ(b*a)` for any `r : Rˣ`\ntheorem unit_mem_mul_iff_mem_swap_mul {a b : A} {r : Rˣ} :\n  ↑r ∈ σ (a * b) ↔ ↑r ∈ σ (b * a) :=\nbegin\n  apply not_iff_not.mpr,\n  simp only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one],\n  have coe_smul_eq : ↑r • 1 = r • (1 : A), from rfl,\n  rw coe_smul_eq,\n  simp only [is_unit.smul_sub_iff_sub_inv_smul],\n  have right_inv_of_swap : ∀ {x y z : A} (h : (1 - x * y) * z = 1),\n    (1 - y * x) * (1 + y * z * x) = 1, from λ x y z h,\n      calc (1 - y * x) * (1 + y * z * x) = 1 - y * x + y * ((1 - x * y) * z) * x : by noncomm_ring\n      ...                                = 1                                     : by simp [h],\n  have left_inv_of_swap : ∀ {x y z : A} (h : z * (1 - x * y) = 1),\n    (1 + y * z * x) * (1 - y * x) = 1, from λ x y z h,\n      calc (1 + y * z * x) * (1 - y * x) = 1 - y * x + y * (z * (1 - x * y)) * x : by noncomm_ring\n      ...                                = 1                                     : by simp [h],\n  have is_unit_one_sub_mul_of_swap : ∀ {x y : A} (h : is_unit (1 - x * y)),\n    is_unit (1 - y * x), from λ x y h, by\n      { let h₁ := right_inv_of_swap h.unit.val_inv,\n        let h₂ := left_inv_of_swap h.unit.inv_val,\n        exact ⟨⟨1 - y * x, 1 + y * h.unit.inv * x, h₁, h₂⟩, rfl⟩, },\n  have is_unit_one_sub_mul_iff_swap : ∀ {x y : A},\n    is_unit (1 - x * y) ↔ is_unit (1 - y * x), by\n      { intros, split, repeat {apply is_unit_one_sub_mul_of_swap}, },\n  rw [←smul_mul_assoc, ←mul_smul_comm r⁻¹ b a, is_unit_one_sub_mul_iff_swap],\nend\n\ntheorem preimage_units_mul_eq_swap_mul {a b : A} :\n  (coe : Rˣ → R) ⁻¹' σ (a * b) = coe ⁻¹'  σ (b * a) :=\nby { ext, exact unit_mem_mul_iff_mem_swap_mul, }\n\nsection star\n\nvariables [star_add_monoid R] [star_ring A] [star_module R A]\n\nlemma star_mem_resolvent_set_iff {r : R} {a : A} :\n  star r ∈ resolvent_set R a ↔ r ∈ resolvent_set R (star a) :=\nby refine ⟨λ h, _, λ h, _⟩;\n   simpa only [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one, star_sub, star_smul,\n     star_star, star_one] using is_unit.star h\n\nprotected lemma map_star (a : A) : σ (star a) = star (σ a) :=\nby { ext, simpa only [set.mem_star, mem_iff, not_iff_not] using star_mem_resolvent_set_iff.symm }\n\nend star\n\nend scalar_ring\n\nsection scalar_field\n\nvariables {𝕜 : Type u} {A : Type v}\nvariables [field 𝕜] [ring A] [algebra 𝕜 A]\n\nlocal notation `σ` := spectrum 𝕜\nlocal notation `↑ₐ` := algebra_map 𝕜 A\n\n/-- Without the assumption `nontrivial A`, then `0 : A` would be invertible. -/\n@[simp] lemma zero_eq [nontrivial A] : σ (0 : A) = {0} :=\nbegin\n  refine set.subset.antisymm _ (by simp [algebra.algebra_map_eq_smul_one, mem_iff]),\n  rw [spectrum, set.compl_subset_comm],\n  intros k hk,\n  rw set.mem_compl_singleton_iff at hk,\n  have : is_unit (units.mk0 k hk • (1 : A)) := is_unit.smul (units.mk0 k hk) is_unit_one,\n  simpa [mem_resolvent_set_iff, algebra.algebra_map_eq_smul_one]\nend\n\n@[simp] theorem scalar_eq [nontrivial A] (k : 𝕜) : σ (↑ₐk) = {k} :=\nbegin\n  have coset_eq : left_add_coset k {0} = {k}, by\n    { ext, split,\n      { intro hx, simp [left_add_coset] at hx, exact hx, },\n      { intro hx, simp at hx, exact ⟨0, ⟨set.mem_singleton 0, by simp [hx]⟩⟩, }, },\n  calc σ (↑ₐk) = σ (↑ₐk + 0)                  : by simp\n    ...        = left_add_coset k (σ (0 : A)) : by rw ←left_add_coset_eq\n    ...        = left_add_coset k {0}         : by rw zero_eq\n    ...        = {k}                          : coset_eq,\nend\n\n@[simp] lemma one_eq [nontrivial A] : σ (1 : A) = {1} :=\ncalc σ (1 : A) = σ (↑ₐ1) : by simp [algebra.algebra_map_eq_smul_one]\n  ...          = {1}     : scalar_eq 1\n\nopen_locale pointwise\n\n/-- the assumption `(σ a).nonempty` is necessary and cannot be removed without\n    further conditions on the algebra `A` and scalar field `𝕜`. -/\ntheorem smul_eq_smul [nontrivial A] (k : 𝕜) (a : A) (ha : (σ a).nonempty) :\n  σ (k • a) = k • (σ a) :=\nbegin\n  rcases eq_or_ne k 0 with rfl | h,\n  { simpa [ha, zero_smul_set] },\n  { exact unit_smul_eq_smul a (units.mk0 k h) },\nend\n\ntheorem nonzero_mul_eq_swap_mul (a b : A) : σ (a * b) \\ {0} = σ (b * a) \\ {0} :=\nbegin\n  suffices h : ∀ (x y : A), σ (x * y) \\ {0} ⊆ σ (y * x) \\ {0},\n  { exact set.eq_of_subset_of_subset (h a b) (h b a) },\n  { rintros _ _ k ⟨k_mem, k_neq⟩,\n    change k with ↑(units.mk0 k k_neq) at k_mem,\n    exact ⟨unit_mem_mul_iff_mem_swap_mul.mp k_mem, k_neq⟩ },\nend\n\nprotected lemma map_inv (a : Aˣ) : (σ (a : A))⁻¹ = σ (↑a⁻¹ : A) :=\nbegin\n  refine set.eq_of_subset_of_subset (λ k hk, _) (λ k hk, _),\n  { rw set.mem_inv at hk,\n    have : k ≠ 0,\n    { simpa only [inv_inv] using inv_ne_zero (ne_zero_of_mem_of_unit hk), },\n    lift k to 𝕜ˣ using is_unit_iff_ne_zero.mpr this,\n    rw ←units.coe_inv' k at hk,\n    exact inv_mem_iff.mp hk },\n  { lift k to 𝕜ˣ using is_unit_iff_ne_zero.mpr (ne_zero_of_mem_of_unit hk),\n    simpa only [units.coe_inv'] using inv_mem_iff.mp hk, }\nend\n\nopen polynomial\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. -/\n\n\nlemma exists_mem_of_not_is_unit_aeval_prod {p : 𝕜[X]} {a : A} (hp : p ≠ 0)\n  (h : ¬is_unit (aeval a (multiset.map (λ (x : 𝕜), X - C x) p.roots).prod)) :\n  ∃ k : 𝕜, k ∈ σ a ∧ eval k p = 0 :=\nbegin\n  rw [←multiset.prod_to_list, alg_hom.map_list_prod] at h,\n  replace h := mt list.prod_is_unit h,\n  simp only [not_forall, exists_prop, aeval_C, multiset.mem_to_list,\n    list.mem_map, aeval_X, exists_exists_and_eq_and, multiset.mem_map, alg_hom.map_sub] at h,\n  rcases h with ⟨r, r_mem, r_nu⟩,\n  exact ⟨r, by rwa [mem_iff, ←is_unit.sub_iff], by rwa [←is_root.def, ←mem_roots hp]⟩\nend\n\n/-- The *spectral mapping theorem* for polynomials.  Note: the assumption `degree p > 0`\nis necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side,\nassuming `[nontrivial A]`, is `{k}` where `p = polynomial.C k`. -/\ntheorem map_polynomial_aeval_of_degree_pos [is_alg_closed 𝕜] (a : A) (p : 𝕜[X])\n  (hdeg : 0 < degree p) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  /- handle the easy direction via `spectrum.subset_polynomial_aeval` -/\n  refine set.eq_of_subset_of_subset (λ k hk, _) (subset_polynomial_aeval a p),\n  /- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`. -/\n  have hprod := eq_prod_roots_of_splits_id (is_alg_closed.splits (C k - p)),\n  have h_ne : C k - p ≠ 0, from 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 (↑ₐ).to_monoid_hom (units.mk0 _ lead_ne)).is_unit,\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) = ↑ₐk - aeval a p,\n    by simp only [aeval_C, alg_hom.map_sub, sub_left_inj],\n  rw [mem_iff, ←p_a_eq, hprod, aeval_mul,\n    ((commute.all _ _).map (aeval a)).is_unit_mul_iff, 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 ⟨r, r_mem, r_ev⟩,\n  exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩,\nend\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. Note: the\nassumption `[nontrivial A]` is necessary for the same reason as in `spectrum.zero_eq`. -/\ntheorem map_polynomial_aeval_of_nonempty [is_alg_closed 𝕜] [nontrivial A] (a : A) (p : 𝕜[X])\n  (hnon : (σ a).nonempty) : σ (aeval a p) = (λ k, eval k p) '' (σ a) :=\nbegin\n  refine or.elim (le_or_gt (degree p) 0) (λ h, _) (map_polynomial_aeval_of_degree_pos a p),\n  { 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] },\nend\n\nvariable (𝕜)\n/--\nEvery element `a` in a nontrivial finite-dimensional algebra `A`\nover an algebraically closed field `𝕜` has non-empty spectrum. -/\n-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.\nlemma nonempty_of_is_alg_closed_of_finite_dimensional [is_alg_closed 𝕜]\n  [nontrivial A] [I : finite_dimensional 𝕜 A] (a : A) :\n  ∃ k : 𝕜, k ∈ σ a :=\nbegin\n  obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := is_integral_of_noetherian (is_noetherian.iff_fg.2 I) a,\n  have nu : ¬ is_unit (aeval a p), { rw [←aeval_def] at h_eval_p, rw h_eval_p, simp, },\n  rw [eq_prod_roots_of_monic_of_splits_id h_mon (is_alg_closed.splits p)] at nu,\n  obtain ⟨k, hk, _⟩ := exists_mem_of_not_is_unit_aeval_prod (monic.ne_zero h_mon) nu,\n  exact ⟨k, hk⟩\nend\n\nend scalar_field\n\nend spectrum\n\nnamespace alg_hom\n\nvariables {R : Type*} {A B : Type*} [comm_ring R] [ring A] [algebra R A] [ring B] [algebra R B]\nlocal notation `σ` := spectrum R\nlocal notation `↑ₐ` := algebra_map R A\n\nlemma apply_mem_spectrum [nontrivial R] (φ : A →ₐ[R] R) (a : A) : φ a ∈ σ a :=\nbegin\n  have h : ↑ₐ(φ a) - a ∈ φ.to_ring_hom.ker,\n  { simp only [ring_hom.mem_ker, coe_to_ring_hom, commutes, algebra.id.map_eq_id,\n               to_ring_hom_eq_coe, ring_hom.id_apply, sub_self, map_sub] },\n  simp only [spectrum.mem_iff, ←mem_nonunits_iff,\n             coe_subset_nonunits (φ.to_ring_hom.ker_ne_top) h],\nend\n\nlemma mem_resolvent_set_apply (φ : A →ₐ[R] B) {a : A} {r : R} (h : r ∈ resolvent_set R a) :\n  r ∈ resolvent_set R (φ a) :=\nby simpa only [map_sub, commutes] using h.map φ\n\nlemma spectrum_apply_subset (φ : A →ₐ[R] B) (a : A) : σ (φ a) ⊆ σ a :=\nλ _, mt (mem_resolvent_set_apply φ)\n\nend alg_hom\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/spectrum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361604769413, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7623253888675237}}
{"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 algebra.big_operators.nat_antidiagonal\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.Finset.NatAntidiagonal\nimport Mathlib.Algebra.BigOperators.Basic\n\n/-!\n# Big operators for `NatAntidiagonal`\n\nThis file contains theorems relevant to big operators over `Finset.NatAntidiagonal`.\n-/\n\nopen BigOperators\n\nvariable {M N : Type _} [CommMonoid M] [AddCommMonoid N]\n\nnamespace Finset\n\nnamespace Nat\n\ntheorem prod_antidiagonal_succ {n : ℕ} {f : ℕ × ℕ → M} :\n    (∏ p in antidiagonal (n + 1), f p) = f (0, n + 1) * ∏ p in antidiagonal n, f (p.1 + 1, p.2) :=\n  by rw [antidiagonal_succ, prod_cons, prod_map]; rfl\n#align finset.nat.prod_antidiagonal_succ Finset.Nat.prod_antidiagonal_succ\n\ntheorem sum_antidiagonal_succ {n : ℕ} {f : ℕ × ℕ → N} :\n    (∑ p in antidiagonal (n + 1), f p) = f (0, n + 1) + ∑ p in antidiagonal n, f (p.1 + 1, p.2) :=\n  @prod_antidiagonal_succ (Multiplicative N) _ _ _\n#align finset.nat.sum_antidiagonal_succ Finset.Nat.sum_antidiagonal_succ\n\n@[to_additive]\ntheorem prod_antidiagonal_swap {n : ℕ} {f : ℕ × ℕ → M} :\n    (∏ p in antidiagonal n, f p.swap) = ∏ p in antidiagonal n, f p := by\n  conv_lhs => rw [← map_swap_antidiagonal, Finset.prod_map]\n#align finset.nat.prod_antidiagonal_swap Finset.Nat.prod_antidiagonal_swap\n#align finset.nat.sum_antidiagonal_swap Finset.Nat.sum_antidiagonal_swap\n\ntheorem prod_antidiagonal_succ' {n : ℕ} {f : ℕ × ℕ → M} :\n    (∏ p in antidiagonal (n + 1), f p) = f (n + 1, 0) * ∏ p in antidiagonal n, f (p.1, p.2 + 1) :=\n  by\n  rw [← prod_antidiagonal_swap, prod_antidiagonal_succ, ← prod_antidiagonal_swap]\n  rfl\n#align finset.nat.prod_antidiagonal_succ' Finset.Nat.prod_antidiagonal_succ'\n\n\n\n@[to_additive]\ntheorem prod_antidiagonal_subst {n : ℕ} {f : ℕ × ℕ → ℕ → M} :\n    (∏ p in antidiagonal n, f p n) = ∏ p in antidiagonal n, f p (p.1 + p.2) :=\n  prod_congr rfl fun p hp ↦ by rw [Nat.mem_antidiagonal.1 hp]\n#align finset.nat.prod_antidiagonal_subst Finset.Nat.prod_antidiagonal_subst\n#align finset.nat.sum_antidiagonal_subst Finset.Nat.sum_antidiagonal_subst\n\n@[to_additive]\ntheorem prod_antidiagonal_eq_prod_range_succ_mk {M : Type _} [CommMonoid M] (f : ℕ × ℕ → M)\n    (n : ℕ) : (∏ ij in Finset.Nat.antidiagonal n, f ij) = ∏ k in range n.succ, f (k, n - k) :=\n  Finset.prod_map (range n.succ) ⟨fun i ↦ (i, n - i), fun _ _ h ↦ (Prod.mk.inj h).1⟩ f\n#align finset.nat.prod_antidiagonal_eq_prod_range_succ_mk Finset.Nat.prod_antidiagonal_eq_prod_range_succ_mk\n#align finset.nat.sum_antidiagonal_eq_sum_range_succ_mk Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk\n\n/-- This lemma matches more generally than `Finset.Nat.prod_antidiagonal_eq_prod_range_succ_mk` when\nusing `rw ←`. -/\n@[to_additive \"This lemma matches more generally than\n`Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk` when using `rw ←`.\"]\ntheorem prod_antidiagonal_eq_prod_range_succ {M : Type _} [CommMonoid M] (f : ℕ → ℕ → M) (n : ℕ) :\n    (∏ ij in Finset.Nat.antidiagonal n, f ij.1 ij.2) = ∏ k in range n.succ, f k (n - k) :=\n  prod_antidiagonal_eq_prod_range_succ_mk _ _\n#align finset.nat.prod_antidiagonal_eq_prod_range_succ Finset.Nat.prod_antidiagonal_eq_prod_range_succ\n#align finset.nat.sum_antidiagonal_eq_sum_range_succ Finset.Nat.sum_antidiagonal_eq_sum_range_succ\nend Nat\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/NatAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7623184019349794}}
{"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\nVariants: `rw ← 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\nImportant note: if `h` is not a proof of the form `A = B`\nor `A ↔ 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 ←h` (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 ∪ C\n⊢ A ∪ B = B ∪ C\n```\n\nthen\n\n`rw h,`\n\nwill change the goal into `⊢ B ∪ C ∪ B = 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 D : set X\nh1 : A = B ∩ C\nh2 : B ∪ A = D\n⊢ D = B\n```\nthen `rw h1 at h2` will turn `h2` into `h2 : B ∪ B ∩ C = D` (remember operator precedence).\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 : x = 3` and we want to prove `⊢ x + 1 = 4`, then after `rw h` the goal\nwill become `⊢ 3 + 1 = 4`, which seems reasonable.\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 ∪ C = B ∪ C.\n-/\nlemma union_eq (A B C: set X) (h : A = B) : A ∪ C = B ∪ C :=\nbegin\n  rw h,\n  \nend\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/set_theory_world/level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8947894527758053, "lm_q1q2_score": 0.7623183881909651}}
{"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 measure_theory.integral.interval_integral\nimport measure_theory.integral.average\n\n/-!\n# Integral average over an interval\n\nIn this file we introduce notation `⨍ x in a..b, f x` for the average `⨍ x in Ι a b, f x` of `f`\nover the interval `Ι a b = set.Ioc (min a b) (max a b)` w.r.t. the Lebesgue measure, then prove\nformulas for this average:\n\n* `interval_average_eq`: `⨍ x in a..b, f x = (b - a)⁻¹ • ∫ x in a..b, f x`;\n* `interval_average_eq_div`: `⨍ x in a..b, f x = (∫ x in a..b, f x) / (b - a)`.\n\nWe also prove that `⨍ x in a..b, f x = ⨍ x in b..a, f x`, see `interval_average_symm`.\n\n## Notation\n\n`⨍ x in a..b, f x`: average of `f` over the interval `Ι a b` w.r.t. the Lebesgue measure.\n\n-/\n\nopen measure_theory set topological_space\nopen_locale interval\n\nvariables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] [complete_space E]\n\nnotation `⨍` binders ` in ` a `..` b `, `\n  r:(scoped:60 f, average (measure.restrict volume (Ι a b)) f) := r\n\nlemma interval_average_symm (f : ℝ → E) (a b : ℝ) : ⨍ x in a..b, f x = ⨍ x in b..a, f x :=\nby rw [set_average_eq, set_average_eq, uIoc_swap]\n\nlemma interval_average_eq (f : ℝ → E) (a b : ℝ) : ⨍ x in a..b, f x = (b - a)⁻¹ • ∫ x in a..b, f x :=\nbegin\n  cases le_or_lt a b with h h,\n  { rw [set_average_eq, uIoc_of_le h, real.volume_Ioc, interval_integral.integral_of_le h,\n      ennreal.to_real_of_real (sub_nonneg.2 h)] },\n  { rw [set_average_eq, uIoc_of_lt h, real.volume_Ioc, interval_integral.integral_of_ge h.le,\n     ennreal.to_real_of_real (sub_nonneg.2 h.le), smul_neg, ← neg_smul, ← inv_neg, neg_sub] }\nend\n\nlemma interval_average_eq_div (f : ℝ → ℝ) (a b : ℝ) :\n  ⨍ x in a..b, f x = (∫ x in a..b, f x) / (b - a) :=\nby rw [interval_average_eq, smul_eq_mul, div_eq_inv_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/measure_theory/integral/interval_average.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7623183837005996}}
{"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\" (λs, 0) ;;\nwhile (λs, s \"n\" ≠ 0)\n  (assign \"r\" (λs, s \"r\" + s \"n\") ;;\n   assign \"n\" (λs, s \"n\" - 1))\n\n/- The summation function: -/\n\ndef sum_upto : ℕ → ℕ\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 : ℕ) :\n  {* λs, s \"n\" = n *} GAUSS {* λs, s \"r\" = sum_upto n *} :=\nshow\n  {* λs, s \"n\" = n *}\n  assign \"r\" (λs, 0) ;;\n  while_inv (λs, s \"r\" + sum_upto (s \"n\") = sum_upto n) (λs, s \"n\" ≠ 0)\n    (assign \"r\" (λs, s \"r\" + s \"n\") ;;\n     assign \"n\" (λs, s \"n\" - 1))\n  {* λs, s \"r\" = sum_upto n *},\nbegin\n  vcg;\n    simp [sum_upto] { contextual := tt },\n  intro s,\n  cases s \"n\",\n  { simp },\n  { simp [nat.succ_eq_add_one, sum_upto, mul_assoc] { contextual := tt } }\nend\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\" (λs, 0) ;;\nwhile (λs, s \"n\" ≠ 0)\n  (assign \"r\" (λs, s \"r\" + s \"m\") ;;\n   assign \"n\" (λs, 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 : ℕ) :\n  {* λs, s \"n\" = n ∧ s \"m\" = m *} MUL {* λs, s \"r\" = n * m *} :=\nshow\n  {* λs, s \"n\" = n ∧ s \"m\" = m *}\n  assign \"r\" (λs, 0) ;;\n  while_inv (λs, s \"m\" = m ∧ s \"r\" + s \"n\" * s \"m\" = n * s \"m\") (λs, s \"n\" ≠ 0)\n    (assign \"r\" (λs, s \"r\" + s \"m\") ;;\n     assign \"n\" (λs, s \"n\" - 1))\n  {* λs, s \"r\" = n * m *},\nbegin\n  vcg;\n    simp { contextual := tt },\n  intro s,\n  cases s \"n\",\n  { simp },\n  { simp [nat.succ_eq_add_one, add_mul] { contextual := tt } }\nend\n\nend MUL\n\n\n/- Question 2: Hoare Triples for Total Correctness -/\n\ndef total_hoare (P : state → Prop) (p : program) (Q : state → Prop) : Prop :=\n∀s, P s → ∃t, (p, s) ⟹ t ∧ Q t\n\nnotation `[* ` P : 1 ` *] ` p : 1 ` [* ` Q : 1 ` *]` := total_hoare P p Q\n\nnamespace total_hoare\n\nvariables {P P' P₁ P₂ P₃ Q Q' : state → Prop} {x : string}\nvariables {S S₀ S₁ S₂ : program}\nvariables {b : state → Prop} {a : state → ℕ} {s s₀ s₁ s₂ t u : state}\n\n/- 2.1. Prove the consequence rule. -/\n\nlemma consequence (h : [* P *] S [* Q *]) (hp : ∀s, P' s → P s)\n    (hq : ∀s, Q s → Q' s) :\n  [* P' *] S [* Q' *] :=\nbegin\n  intros s hs,\n  specialize h s (hp s hs),\n  cases h with t ht,\n  use 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 :\n  [* P *] skip [* P *] :=\nbegin\n  intros s hs,\n  use s,\n  apply and.intro big_step.skip hs\nend\n\n/- 2.3. Prove the rule for `assign`. -/\n\nlemma assign_intro (P : state → Prop) :\n  [* λs, P (s{x ↦ a s}) *] assign x a [* P *] :=\nbegin\n  intros s hs, \n  use s{x ↦ a s}, \n  exact and.intro big_step.assign hs\nend\n\n/- 2.4. Prove the rule for `seq`. -/\n\nlemma seq_intro (h₁ : [* P₁ *] S₁ [* P₂ *])\n    (h₂ : [* P₂ *] S₂ [* P₃ *]) :\n  [* P₁ *] S₁ ;; S₂ [* P₃ *] :=\nbegin\n  intros s hs,\n  specialize h₁ s hs,\n  cases h₁ with t h₁,\n  specialize h₂ t (and.elim_right h₁),\n  cases h₂ with u h₂,\n  use u,\n  apply and.intro,\n  { exact big_step.seq (and.elim_left h₁) (and.elim_left h₂) },\n  { exact and.elim_right h₂ }\nend\n\n/- 2.5 **optional**. Prove the rule for `ite`. This requires `b s ∨ ¬ b s`.\n`classical.em (b s)` provides a proof, even when `b` is not decidable. -/\n\nlemma ite_intro (h₁ : [* λs, P s ∧ b s *] S₁ [* Q *])\n  (h₂ : [* λs, P s ∧ ¬ b s *] S₂ [* Q *]) :\n  [* P *] ite b S₁ S₂ [* Q *] :=\nbegin\n  intros s hs,\n  cases classical.em (b s),\n  { cases h₁ s (and.intro hs h) with t ht,\n    use t,\n    apply and.intro,\n    { exact big_step.ite_true h (and.elim_left ht) },\n    { exact and.elim_right ht } },\n  { cases h₂ s (and.intro hs h) with t ht,\n    use 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\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 : ∃u, (while c p, t) ⟹ u ∧ I u ∧ ¬ c u :=\n      have M < n := …,\n        -- necessary for Lean to figure out the well-founded induction\n      while_intro.aux M …,\n\nSimilar to `ite`, this requires `c s ∨ ¬ c s`. `classical.em (c s)` provides a\nproof. -/\n\nlemma while_intro.aux\n  (I : state → Prop)\n  (V : state → ℕ)\n  (h_inv : ∀n, [* λs, I s ∧ b s ∧ V s = n *] S [* λs, I s ∧ V s < n *]) :\n  ∀n s, V s = n → I s → ∃t, (while b S, s) ⟹ t ∧ I t ∧ ¬ b t\n| n s V_eq hs :=\n  begin\n    cases classical.em (b s) with hcs hncs,\n    { have h_inv : ∃ t, (S, s) ⟹ t ∧ I t ∧ V t < n :=\n        h_inv n s (and.intro hs (and.intro hcs V_eq)),\n      cases h_inv with t ht,\n      have ih : ∃u, (while b S, t) ⟹ u ∧ I u ∧ ¬ b u :=\n        have V t < n := and.elim_right (and.elim_right ht),\n        while_intro.aux (V t) t rfl (and.elim_left (and.elim_right ht)),\n      cases ih with u hu,\n      use 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    { use s, \n      apply and.intro,\n      { exact big_step.while_false hncs }, \n      { exact and.intro hs hncs } }\n  end\n\nlemma while_intro\n  (I : state → Prop)   -- invariant in the loop\n  (V : state → ℕ)      -- variant in the loop body (a.k.a. termination measure)\n  (h_inv : ∀n, [* λs, I s ∧ b s ∧ V s = n *] S [* λs, I s ∧ V s < n *]) :\n  [* I *] while b S [* λs, I s ∧ ¬ b s *] :=\nbegin\n  intros s hs,\n  exact while_intro.aux I V h_inv (V s) s rfl hs\nend\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_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.7622516900760442}}
{"text": "import data.finset data.set.finite data.fintype\n--universes u v \n\n/-- sum_from_one_to n f sums f(i) for 1<=i<=n -/\ndefinition sum_from_one_to {α : Type*} [add_comm_monoid α] (n : ℕ) (f : ℕ → α) : α :=\nfinset.sum (finset.Ico 1 (n+1)) f \n\ntheorem sum_from_one_to.rec {α : Type*} [add_comm_monoid α]\n  (n : ℕ) (f : ℕ → α) : sum_from_one_to (n+1) f = f (n+1) + sum_from_one_to n f  :=\nbegin\n  unfold sum_from_one_to,\n  rw finset.Ico.succ_top (show 1 ≤ n + 1, by simp),\n  rw finset.sum_insert,\n  simp,\nend\n\n/-- sum_from_zero_to n f sums f(i) for 0<=i<=n -/\ndefinition sum_from_zero_to {α : Type*} [add_comm_monoid α] (n : ℕ) (f : ℕ → α) : α :=\nfinset.sum (finset.range (n + 1)) f\n\ntheorem sum_from_zero_to.rec {α : Type*} [add_comm_monoid α] \n  (n : ℕ) (f : ℕ → α) : sum_from_zero_to (n+1) f = f (n+1) + sum_from_zero_to n f  :=\nbegin\n  unfold sum_from_zero_to,\n  rw finset.range_succ,\n  rw finset.sum_insert,\n  simp,\nend\n\n/-- sum_from_to a n f sums f(i) for a<=i<=n, if a <= n + 1 -/\ndefinition sum_from_to {α : Type*} [add_comm_monoid α] \n  (a : ℕ) (n : ℕ) (f : ℕ → α) : α :=\nfinset.sum (finset.Ico a (n + 1)) f\n\ntheorem sum_from_to.rec {α : Type*} [add_comm_monoid α]\n  (a : ℕ) (n : ℕ) (f : ℕ → α) (H : a ≤ n + 1) :\nsum_from_to a (n+1) f = f (n+1) + sum_from_to a n f  :=\nbegin\n  unfold sum_from_to,\n  rw finset.Ico.succ_top H,\n  rw finset.sum_insert,\n  simp,\nend\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/M1F/easy_for_mathematicians/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7621636597955425}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio 1. Realizar las siguientes acciones:\n-- 1. Importar la librería de los números reales.\n-- 2. Declarar x, y, a y b como variables sobre los reales.\n-- 3. Crear el espacio de nombres my_abs.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic    -- 1\nvariables {x y a b : ℝ}   -- 2\nnamespace my_abs          -- 3\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    x ≤ abs x\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : x ≤ abs x :=\nbegin\n  cases (le_or_gt 0 x) with h1 h2,\n  { rw abs_of_nonneg h1 },\n  { rw abs_of_neg h2,\n    apply left.self_le_neg,\n    apply le_of_lt h2 },\nend\n\n-- Prueba\n-- ======\n\n/-\nx : ℝ\n⊢ x ≤ abs x\n  >> cases (le_or_gt 0 x) with h1 h2,\n| h1 : 0 ≤ x\n| ⊢ x ≤ abs x\n  >> { rw abs_of_nonneg h1 },\nh2 : 0 > x\n⊢ x ≤ abs x\n  >> { rw abs_of_neg h2,\n⊢ x ≤ -x\n  >>   apply self_le_neg,\n⊢ x ≤ 0\n  >>   apply le_of_lt h2 },\nno goals\n-/\n\n-- Comentario: Se han usado los siguientes lemas\n-- + le_or_gt x y : x ≤ y ∨ x > y\n-- + abs_of_nonneg : 0 ≤ x → abs x = x\n-- + abs_of_neg : x < 0 → abs x = -x\n-- + self_le_neg : x ≤ 0 → x ≤ -x\n-- + le_of_lt : x < y → x ≤ y\n\n-- Comprobación\n-- #check (@le_or_gt ℝ _ x y)\n-- #check (@abs_of_nonneg ℝ _ x)\n-- #check (@abs_of_neg ℝ _ x)\n-- #check (@self_le_neg ℝ _ x)\n-- #check (@le_of_lt ℝ _ x y)\n\n-- 2ª demostración\n-- ===============\n\nexample : x ≤ abs x :=\nbegin\n  unfold abs,\n  exact le_max_left x (-x),\nend\n\n-- Comentarios:\n-- 1. La táctica (unfold e) despliega la definición de e.\n-- 2. La definición de abs\n--    + abs (a : α) : α := max a (-a)\n-- 3. Se ha usado el lema\n--    + le_max_left x y : x ≤ max x y\n\n-- Comprobación\n-- #check (@le_max_left ℝ _ x y)\n-- #print abs\n\n-- 3ª demostración\n-- ===============\n\nexample : x ≤ abs x :=\nle_max_left x (-x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que\n--    -x ≤ abs x\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\ntheorem neg_le_abs_self : -x ≤ abs x :=\nbegin\n  cases (le_or_gt 0 x) with h1 h2,\n  { rw abs_of_nonneg h1,\n    apply neg_le_self h1 },\n  { rw abs_of_neg h2 },\nend\n\n-- Prueba\n-- ======\n\n/-\nx : ℝ\n⊢ -x ≤ abs x\n  >> cases (le_or_gt 0 x) with h1 h2,\n| h1 : 0 ≤ x\n| ⊢ -x ≤ abs x\n|   >> { rw abs_of_nonneg h1,\n| ⊢ -x ≤ x\n|   >>   apply neg_le_self h1 },\nh2 : 0 > x\n⊢ -x ≤ abs x\n  >> { rw abs_of_neg h2 },\nno goals\n-/\n\n-- Comentario: Los lemas utilizados son\n-- + le_or_gt x y : x ≤ y ∨ x > y\n-- + abs_of_nonneg : 0 ≤ x → abs x = x\n-- + neg_le_self : 0 ≤ x → -x ≤ x\n-- + abs_of_neg : x < 0 → abs x = -x\n\n-- Comprobación\n-- #check (@le_or_gt ℝ _ x y)\n-- #check (@abs_of_nonneg ℝ _ x)\n-- #check (@neg_le_self ℝ _ x)\n-- #check (@abs_of_neg ℝ _ x)\n\n-- 2ª demostración\n-- ===============\n\nexample : -x ≤ abs x :=\nbegin\n  unfold abs,\n  exact le_max_right x (-x),\nend\n\n-- Comentarios:\n-- 1. La táctica (unfold e) despliega la definición de e.\n-- 2. La definición de abs\n--    + abs (a : α) : α := max a (-a)\n-- 3. Se ha usado el lema\n--    + le_max_right x y : y ≤ max x y\n\n-- Comprobación:\n-- #check (@le_max_right ℝ _ x y)\n\n-- 3ª demostración\n-- ===============\n\nexample : -x ≤ abs x :=\nle_max_right x (-x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que si\n--    0 ≤ a + b\n--    0 ≤ a\n-- entonces\n--    abs (a + b) ≤ abs a + abs b\n-- ----------------------------------------------------------------------\n\nopen_locale classical\n\nlemma aux1\n  (h1 : 0 ≤ a + b)\n  (h2 : 0 ≤ a)\n  : abs (a + b) ≤ abs a + abs b :=\nbegin\n  by_cases h3 : 0 ≤ b,\n  show abs (a + b) ≤ abs a + abs b,\n    calc\n      abs (a + b) ≤ abs (a + b)   : by apply le_refl\n              ... = a + b         : by rw (abs_of_nonneg h1)\n              ... = abs a + b     : by rw (abs_of_nonneg h2)\n              ... = abs a + abs b : by rw (abs_of_nonneg h3),\n  have h4 : b ≤ 0,\n    from le_of_lt (lt_of_not_ge h3),\n  show abs (a + b) ≤ abs a + abs b,\n    calc\n      abs (a + b) = a + b         : by rw (abs_of_nonneg h1)\n              ... = abs a + b     : by rw (abs_of_nonneg h2)\n              ... ≤ abs a + 0     : add_le_add_left h4 _\n              ... ≤ abs a + -b    : add_le_add_left (neg_nonneg_of_nonpos h4) _\n              ... = abs a + abs b : by rw (abs_of_nonpos h4),\nend\n\n-- Prueba\n-- ======\n\n/-\na b : ℝ,\nh1 : 0 ≤ a + b,\nh2 : 0 ≤ a\n⊢ abs (a + b) ≤ abs a + abs b\n  >> by_cases h3 : 0 ≤ b,\n| h3 : 0 ≤ b\n| ⊢ abs (a + b) ≤ abs a + abs b\n|   >> show abs (a + b) ≤ abs a + abs b, calc\n|   >>   abs (a + b) ≤ abs (a + b)   : by apply le_refl\n|   >>           ... = a + b         : by rw (abs_of_nonneg h1)\n|   >>           ... = abs a + b     : by rw (abs_of_nonneg h2)\n|   >>           ... = abs a + abs b : by rw (abs_of_nonneg h3),\nh3 : ¬0 ≤ b\n⊢ abs (a + b) ≤ abs a + abs b\n  >> have h4 : b ≤ 0,\n  >>   from le_of_lt (lt_of_not_ge h3),\nh4 : b ≤ 0\n⊢ abs (a + b) ≤ abs a + abs b\n  >> show abs (a + b) ≤ abs a + abs b, calc\n  >>   abs (a + b) = a + b         : by rw (abs_of_nonneg h1)\n  >>           ... = abs a + b     : by rw (abs_of_nonneg h2)\n  >>           ... ≤ abs a + 0     : add_le_add_left h4 _\n  >>           ... ≤ abs a + -b    : add_le_add_left (neg_nonneg_of_nonpos h4)\n  >>           ... = abs a + abs b : by rw (abs_of_nonpos h4),\n-/\n\n-- Comentarios:\n-- 1. La táctica (by_cases h : p) aplica el principio de tercio excluso\n--    sobre p; es decir, considera dos casos: en el primero le añade la\n--    hipótesis (h : p) y en el segundo, (h : ¬p).\n-- 2. Para aplicar la táctica by_cases hay que habilitar la lógica\n--    clásica.\n-- 3. Se han usado los siguientes lemas\n--    + le_refl x : x ≤ x\n--    + abs_of_nonneg : 0 ≤ x → abs x = x\n--    + le_of_lt : x < y → x ≤ y\n--    + lt_of_not_ge : ¬x ≥ y → x < y\n--    + add_le_add_left : x ≤ y → ∀ (c : ℝ), c + x ≤ c + y\n--    + neg_nonneg_of_nonpos : x ≤ 0 → 0 ≤ -x\n--    + abs_of_nonpos : x ≤ 0 → abs x = -x\n\n-- Comprobación:\n-- #check (@le_refl ℝ _ x)\n-- #check (@abs_of_nonneg ℝ _ x)\n-- #check (@le_of_lt ℝ _ x y)\n-- #check (@lt_of_not_ge ℝ _ x y)\n-- #check (@add_le_add_left ℝ _ x y)\n-- #check (@neg_nonneg_of_nonpos ℝ _ x)\n-- #check (@abs_of_nonpos ℝ _ x)\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que si\n--    0 ≤ a + b\n-- entonces\n--    abs (a + b) ≤ abs a + abs b\n-- ----------------------------------------------------------------------\n\nlemma aux2\n  (h1 : 0 ≤ a + b)\n  : abs (a + b) ≤ abs a + abs b :=\nbegin\n  by_cases h2 : 0 ≤ a,\n    exact @aux1 a b h1 h2,\n  rw add_comm at h1,\n  have h3 : 0 ≤ b,\n    linarith,\n  rw add_comm,\n  rw add_comm (abs a),\n  exact @aux1 b a h1 h3,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que\n--    abs (x + y) ≤ abs x + abs y\n-- ----------------------------------------------------------------------\n\ntheorem abs_add : abs (x + y) ≤ abs x + abs y :=\nbegin\n  by_cases h2 : 0 ≤ x + y,\n    { exact @aux2 x y h2 },\n  have h3 : x + y ≤ 0,\n    by exact le_of_not_ge h2,\n  have h4: -x + -y = -(x + y),\n    by rw neg_add,\n  have h5 : 0 ≤ -(x + y),\n    from neg_nonneg_of_nonpos h3,\n  have h6 : 0 ≤ -x + -y,\n    { rw [← h4] at h5,\n      exact h5 },\n  calc\n     abs (x + y) = abs (-x + -y)       : by rw [← abs_neg, neg_add]\n             ... ≤ abs (-x) + abs (-y) : aux2 h6\n             ... = abs x + abs y       : by rw [abs_neg, abs_neg],\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : ℝ\n⊢ abs (x + y) ≤ abs x + abs y\n  >> by_cases h2 : 0 ≤ x + y,\n| h2 : 0 ≤ x + y\n| ⊢ abs (x + y) ≤ abs x + abs y\n|   >>   { exact @aux2 x y h2 },\nh2 : ¬0 ≤ x + y\n⊢ abs (x + y) ≤ abs x + abs y\n  >> have h3 : x + y ≤ 0,\n  >>   by exact le_of_not_ge h2,\nx y : ℝ,\nh2 : ¬0 ≤ x + y,\nh3 : x + y ≤ 0\n⊢ abs (x + y) ≤ abs x + abs y\n  >> have h4: -x + -y = -(x + y),\n  >>   by rw neg_add,\nx y : ℝ,\nh2 : ¬0 ≤ x + y,\nh3 : x + y ≤ 0,\nh4 : -x + -y = -(x + y)\n⊢ abs (x + y) ≤ abs x + abs y\n  >> have h5 : 0 ≤ -(x + y),\n  >>   from neg_nonneg_of_nonpos h3,\nx y : ℝ,\nh2 : ¬0 ≤ x + y,\nh3 : x + y ≤ 0,\nh4 : -x + -y = -(x + y),\nh5 : 0 ≤ -(x + y)\n⊢ abs (x + y) ≤ abs x + abs y\n  >> have h6 : 0 ≤ -x + -y,\n  >>   { rw [← h4] at h5,\nx y : ℝ,\nh2 : ¬0 ≤ x + y,\nh3 : x + y ≤ 0,\nh4 : -x + -y = -(x + y),\nh5 : 0 ≤ -x + -y\n⊢ 0 ≤ -x + -y\n  >>     exact h5 },\nx y : ℝ,\nh2 : ¬0 ≤ x + y,\nh3 : x + y ≤ 0,\nh4 : -x + -y = -(x + y),\nh5 : 0 ≤ -(x + y),\nh6 : 0 ≤ -x + -y\n⊢ abs (x + y) ≤ abs x + abs y\n  >> calc\n  >>    abs (x + y) = abs (-x + -y)       : by rw [← abs_neg, neg_add]\n  >>            ... ≤ abs (-x) + abs (-y) : aux2 h6\n  >>            ... = abs x + abs y       : by rw [abs_neg, abs_neg],\n-/\n\n-- Comentario: Se han usado los lemas\n-- + le_of_not_ge : ¬x ≥ y → x ≤ y\n-- + neg_add x y : -(x + y) = -x + -y\n-- + neg_nonneg_of_nonpos : x ≤ 0 → 0 ≤ -x\n\n-- Comprobación:\n-- #check (@le_of_not_ge ℝ _ x y)\n-- #check (@neg_add ℝ _ x y)\n-- #check (@neg_nonneg_of_nonpos ℝ _ x)\n\nend my_abs\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/Desigualdad_triangular_para_valor_absoluto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7621636483763468}}
{"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önne, 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ 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 ℂ sin :=\nλx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin {x : ℂ} : differentiable_at ℂ sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ λ 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ 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 ℂ cos :=\nλx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos {x : ℂ} : differentiable_at ℂ cos x :=\ndifferentiable_cos x\n\nlemma deriv_cos {x : ℂ} : deriv cos x = -sin x :=\n(has_deriv_at_cos x).deriv\n\n@[simp] lemma deriv_cos' : deriv cos = (λ x, -sin x) :=\nfunext $ λ 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ n sinh :=\n(times_cont_diff_exp.sub times_cont_diff_neg.cexp).div_const\n\nlemma differentiable_sinh : differentiable ℂ sinh :=\nλx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh {x : ℂ} : differentiable_at ℂ sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ λ 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 : ℂ) : 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:ℂ)⁻¹,\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 : ℂ) : 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 ℂ n cosh :=\n(times_cont_diff_exp.add times_cont_diff_neg.cexp).div_const\n\nlemma differentiable_cosh : differentiable ℂ cosh :=\nλx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh {x : ℂ} : differentiable_at ℂ cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ λ x, (has_deriv_at_cosh x).deriv\n\nend complex\n\nsection\n/-! ### Simp lemmas for derivatives of `λ x, complex.cos (f x)` etc., `f : ℂ → ℂ` -/\n\nvariables {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}\n\n/-! #### `complex.cos` -/\n\nlemma has_strict_deriv_at.ccos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  deriv_within (λx, 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 ℂ f x) :\n  deriv (λx, 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 `λ x, complex.cos (f x)` etc., `f : E → ℂ` -/\n\nvariables {E : Type*} [normed_group E] [normed_space ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ}\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 (λ x, complex.cos (f x)) (- complex.sin (f x) • 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 (λ x, complex.cos (f x)) (- complex.sin (f x) • 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 (λ x, complex.cos (f x)) (- complex.sin (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.cos (f x)) x :=\nhc.has_fderiv_at.ccos.differentiable_at\n\nlemma differentiable_on.ccos (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.cos (f x)) s :=\nλx h, (hc x h).ccos\n\n@[simp] lemma differentiable.ccos (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.cos (f x)) :=\nλx, (hc x).ccos\n\nlemma fderiv_within_ccos (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.cos (f x)) s x = - complex.sin (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.ccos.fderiv_within hxs\n\n@[simp] lemma fderiv_ccos (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.cos (f x)) x = - complex.sin (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.ccos.fderiv\n\nlemma times_cont_diff.ccos {n} (h : times_cont_diff ℂ n f) :\n  times_cont_diff ℂ n (λ 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 ℂ n f x) :\n  times_cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  times_cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  times_cont_diff_within_at ℂ n (λ 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 (λ x, complex.sin (f x)) (complex.cos (f x) • 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 (λ x, complex.sin (f x)) (complex.cos (f x) • 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 (λ x, complex.sin (f x)) (complex.cos (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.sin (f x)) x :=\nhc.has_fderiv_at.csin.differentiable_at\n\nlemma differentiable_on.csin (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.sin (f x)) s :=\nλx h, (hc x h).csin\n\n@[simp] lemma differentiable.csin (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.sin (f x)) :=\nλx, (hc x).csin\n\nlemma fderiv_within_csin (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.sin (f x)) s x = complex.cos (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.csin.fderiv_within hxs\n\n@[simp] lemma fderiv_csin (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.sin (f x)) x = complex.cos (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.csin.fderiv\n\nlemma times_cont_diff.csin {n} (h : times_cont_diff ℂ n f) :\n  times_cont_diff ℂ n (λ 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 ℂ n f x) :\n  times_cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  times_cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  times_cont_diff_within_at ℂ n (λ 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 (λ x, complex.cosh (f x)) (complex.sinh (f x) • 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 (λ x, complex.cosh (f x)) (complex.sinh (f x) • 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 (λ x, complex.cosh (f x)) (complex.sinh (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.cosh (f x)) x :=\nhc.has_fderiv_at.ccosh.differentiable_at\n\nlemma differentiable_on.ccosh (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.cosh (f x)) s :=\nλx h, (hc x h).ccosh\n\n@[simp] lemma differentiable.ccosh (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.cosh (f x)) :=\nλx, (hc x).ccosh\n\nlemma fderiv_within_ccosh (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.cosh (f x)) s x = complex.sinh (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.ccosh.fderiv_within hxs\n\n@[simp] lemma fderiv_ccosh (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.cosh (f x)) x = complex.sinh (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.ccosh.fderiv\n\nlemma times_cont_diff.ccosh {n} (h : times_cont_diff ℂ n f) :\n  times_cont_diff ℂ n (λ 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 ℂ n f x) :\n  times_cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  times_cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  times_cont_diff_within_at ℂ n (λ 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 (λ x, complex.sinh (f x)) (complex.cosh (f x) • 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 (λ x, complex.sinh (f x)) (complex.cosh (f x) • 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 (λ x, complex.sinh (f x)) (complex.cosh (f x) • 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 ℂ f s x) :\n  differentiable_within_at ℂ (λ 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 ℂ f x) :\n  differentiable_at ℂ (λx, complex.sinh (f x)) x :=\nhc.has_fderiv_at.csinh.differentiable_at\n\nlemma differentiable_on.csinh (hc : differentiable_on ℂ f s) :\n  differentiable_on ℂ (λx, complex.sinh (f x)) s :=\nλx h, (hc x h).csinh\n\n@[simp] lemma differentiable.csinh (hc : differentiable ℂ f) :\n  differentiable ℂ (λx, complex.sinh (f x)) :=\nλx, (hc x).csinh\n\nlemma fderiv_within_csinh (hf : differentiable_within_at ℂ f s x)\n  (hxs : unique_diff_within_at ℂ s x) :\n  fderiv_within ℂ (λx, complex.sinh (f x)) s x = complex.cosh (f x) • (fderiv_within ℂ f s x) :=\nhf.has_fderiv_within_at.csinh.fderiv_within hxs\n\n@[simp] lemma fderiv_csinh (hc : differentiable_at ℂ f x) :\n  fderiv ℂ (λx, complex.sinh (f x)) x = complex.cosh (f x) • (fderiv ℂ f x) :=\nhc.has_fderiv_at.csinh.fderiv\n\nlemma times_cont_diff.csinh {n} (h : times_cont_diff ℂ n f) :\n  times_cont_diff ℂ n (λ 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 ℂ n f x) :\n  times_cont_diff_at ℂ n (λ 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 ℂ n f s) :\n  times_cont_diff_on ℂ n (λ 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 ℂ n f s x) :\n  times_cont_diff_within_at ℂ n (λ 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 : ℝ}\n\nlemma has_strict_deriv_at_sin (x : ℝ) : 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 : ℝ) : 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 ℝ n sin :=\ncomplex.times_cont_diff_sin.real_of_complex\n\nlemma differentiable_sin : differentiable ℝ sin :=\nλx, (has_deriv_at_sin x).differentiable_at\n\nlemma differentiable_at_sin : differentiable_at ℝ sin x :=\ndifferentiable_sin x\n\n@[simp] lemma deriv_sin : deriv sin = cos :=\nfunext $ λ x, (has_deriv_at_sin x).deriv\n\nlemma has_strict_deriv_at_cos (x : ℝ) : 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 : ℝ) : 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 ℝ n cos :=\ncomplex.times_cont_diff_cos.real_of_complex\n\nlemma differentiable_cos : differentiable ℝ cos :=\nλx, (has_deriv_at_cos x).differentiable_at\n\nlemma differentiable_at_cos : differentiable_at ℝ 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 = (λ x, - sin x) :=\nfunext $ λ _, deriv_cos\n\nlemma has_strict_deriv_at_sinh (x : ℝ) : 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 : ℝ) : 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 ℝ n sinh :=\ncomplex.times_cont_diff_sinh.real_of_complex\n\nlemma differentiable_sinh : differentiable ℝ sinh :=\nλx, (has_deriv_at_sinh x).differentiable_at\n\nlemma differentiable_at_sinh : differentiable_at ℝ sinh x :=\ndifferentiable_sinh x\n\n@[simp] lemma deriv_sinh : deriv sinh = cosh :=\nfunext $ λ x, (has_deriv_at_sinh x).deriv\n\nlemma has_strict_deriv_at_cosh (x : ℝ) : 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 : ℝ) : 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 ℝ n cosh :=\ncomplex.times_cont_diff_cosh.real_of_complex\n\nlemma differentiable_cosh : differentiable ℝ cosh :=\nλx, (has_deriv_at_cosh x).differentiable_at\n\nlemma differentiable_at_cosh : differentiable_at ℝ cosh x :=\ndifferentiable_cosh x\n\n@[simp] lemma deriv_cosh : deriv cosh = sinh :=\nfunext $ λ 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 `λ x, real.cos (f x)` etc., `f : ℝ → ℝ` -/\n\nvariables {f : ℝ → ℝ} {f' x : ℝ} {s : set ℝ}\n\n/-! #### `real.cos` -/\n\nlemma has_strict_deriv_at.cos (hf : has_strict_deriv_at f f' x) :\n  has_strict_deriv_at (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 (λ 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 (λ 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 (λ 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 ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  deriv_within (λx, 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 ℝ f x) :\n  deriv (λx, 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 `λ x, real.cos (f x)` etc., `f : E → ℝ` -/\n\nvariables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ}\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 (λ x, real.cos (f x)) (- real.sin (f x) • 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 (λ x, real.cos (f x)) (- real.sin (f x) • 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 (λ x, real.cos (f x)) (- real.sin (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.cos (f x)) x :=\nhc.has_fderiv_at.cos.differentiable_at\n\nlemma differentiable_on.cos (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.cos (f x)) s :=\nλx h, (hc x h).cos\n\n@[simp] lemma differentiable.cos (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.cos (f x)) :=\nλx, (hc x).cos\n\nlemma fderiv_within_cos (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.cos (f x)) s x = - real.sin (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.cos.fderiv_within hxs\n\n@[simp] lemma fderiv_cos (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.cos (f x)) x = - real.sin (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.cos.fderiv\n\nlemma times_cont_diff.cos {n} (h : times_cont_diff ℝ n f) :\n  times_cont_diff ℝ n (λ 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 ℝ n f x) :\n  times_cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  times_cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  times_cont_diff_within_at ℝ n (λ 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 (λ x, real.sin (f x)) (real.cos (f x) • 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 (λ x, real.sin (f x)) (real.cos (f x) • 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 (λ x, real.sin (f x)) (real.cos (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.sin (f x)) x :=\nhc.has_fderiv_at.sin.differentiable_at\n\nlemma differentiable_on.sin (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.sin (f x)) s :=\nλx h, (hc x h).sin\n\n@[simp] lemma differentiable.sin (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.sin (f x)) :=\nλx, (hc x).sin\n\nlemma fderiv_within_sin (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.sin (f x)) s x = real.cos (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.sin.fderiv_within hxs\n\n@[simp] lemma fderiv_sin (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.sin (f x)) x = real.cos (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.sin.fderiv\n\nlemma times_cont_diff.sin {n} (h : times_cont_diff ℝ n f) :\n  times_cont_diff ℝ n (λ 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 ℝ n f x) :\n  times_cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  times_cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  times_cont_diff_within_at ℝ n (λ 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 (λ x, real.cosh (f x)) (real.sinh (f x) • 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 (λ x, real.cosh (f x)) (real.sinh (f x) • 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 (λ x, real.cosh (f x)) (real.sinh (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.cosh (f x)) x :=\nhc.has_fderiv_at.cosh.differentiable_at\n\nlemma differentiable_on.cosh (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.cosh (f x)) s :=\nλx h, (hc x h).cosh\n\n@[simp] lemma differentiable.cosh (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.cosh (f x)) :=\nλx, (hc x).cosh\n\nlemma fderiv_within_cosh (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.cosh (f x)) s x = real.sinh (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.cosh.fderiv_within hxs\n\n@[simp] lemma fderiv_cosh (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.cosh (f x)) x = real.sinh (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.cosh.fderiv\n\nlemma times_cont_diff.cosh {n} (h : times_cont_diff ℝ n f) :\n  times_cont_diff ℝ n (λ 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 ℝ n f x) :\n  times_cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  times_cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  times_cont_diff_within_at ℝ n (λ 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 (λ x, real.sinh (f x)) (real.cosh (f x) • 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 (λ x, real.sinh (f x)) (real.cosh (f x) • 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 (λ x, real.sinh (f x)) (real.cosh (f x) • 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 ℝ f s x) :\n  differentiable_within_at ℝ (λ 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 ℝ f x) :\n  differentiable_at ℝ (λx, real.sinh (f x)) x :=\nhc.has_fderiv_at.sinh.differentiable_at\n\nlemma differentiable_on.sinh (hc : differentiable_on ℝ f s) :\n  differentiable_on ℝ (λx, real.sinh (f x)) s :=\nλx h, (hc x h).sinh\n\n@[simp] lemma differentiable.sinh (hc : differentiable ℝ f) :\n  differentiable ℝ (λx, real.sinh (f x)) :=\nλx, (hc x).sinh\n\nlemma fderiv_within_sinh (hf : differentiable_within_at ℝ f s x)\n  (hxs : unique_diff_within_at ℝ s x) :\n  fderiv_within ℝ (λx, real.sinh (f x)) s x = real.cosh (f x) • (fderiv_within ℝ f s x) :=\nhf.has_fderiv_within_at.sinh.fderiv_within hxs\n\n@[simp] lemma fderiv_sinh (hc : differentiable_at ℝ f x) :\n  fderiv ℝ (λx, real.sinh (f x)) x = real.cosh (f x) • (fderiv ℝ f x) :=\nhc.has_fderiv_at.sinh.fderiv\n\nlemma times_cont_diff.sinh {n} (h : times_cont_diff ℝ n f) :\n  times_cont_diff ℝ n (λ 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 ℝ n f x) :\n  times_cont_diff_at ℝ n (λ 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 ℝ n f s) :\n  times_cont_diff_on ℝ n (λ 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 ℝ n f s x) :\n  times_cont_diff_within_at ℝ n (λ 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", "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/trigonometric/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7621562750806675}}
{"text": "import data.list\nimport data.nat.prime\nimport tactic\nimport tactic.gptf\n\n\nlemma sieve_aux_wf (pred: ℕ -> Prop) [decidable_pred pred] (xs: list ℕ) :\n  (xs.filter pred).length < xs.length + 1 := \n  by simp only [nat.lt_succ_of_le, list.length_le_of_sublist, list.filter_sublist]\n  \ndef sieve_aux : list ℕ -> list ℕ\n| [] := []\n| (x :: xs) := \n  have (xs.filter $ λ n, ¬(x ∣ n)).length < xs.length + 1,\n    from sieve_aux_wf _ _,\n  x :: sieve_aux (xs.filter $ λ n, ¬(x ∣ n))\nusing_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf list.length⟩]}\n\ndef sieve (m: ℕ) : list ℕ := sieve_aux $ (list.range m).drop 2\n\n\nlemma sieve_aux_sublist (l: list ℕ) :\n  sieve_aux l <+ l :=\nbegin\n  apply well_founded.induction (measure_wf list.length) l,\n  intros x h₁,\n\n  cases x,\n  simp only [sieve_aux],\n  \n  simp only [sieve_aux],\n  apply list.sublist.cons2,\n    \n  simp only [measure, inv_image, list.length] at h₁,\n  generalize h₂ : list.filter (λ (n : ℕ), ¬x_hd ∣ n) x_tl = li',\n\n  have h₃ : li' <+ x_tl := by simp only [←h₂, list.filter_sublist],\n  have h₄ := h₁ li' (nat.lt_succ_iff.mpr (list.length_le_of_sublist h₃)),\n  exact list.sublist.trans h₄ h₃,\nend\n\nlemma sieve_aux_mem {n: ℕ} {l: list ℕ} :\n  n ∈ sieve_aux l -> n ∈ l := \n  by solve_by_elim [sieve_aux_sublist, list.sublist.subset]\n\ntheorem sieve_keeps_primes₁ (n: ℕ) (li: list ℕ):\n  nat.prime n -> 1 ∉ li -> n ∈ li -> n ∈ (sieve_aux li) :=\nbegin\n  intro h₁,\n  apply well_founded.induction (measure_wf list.length) li,\n  intro x,\n\n  cases x,\n  simp only [list.not_mem_nil, forall_prop_of_false, not_false_iff, forall_true_iff],\n  \n  replace h₁ := h₁.right x_hd,\n  by_cases n = x_hd,\n  finish [sieve_aux],\n\n  intros h₂ h₃ h₄,\n  right,\n\n  apply h₂,\n  all_goals { clear li h₂ },\n\n  simp only [measure, inv_image, list.length, sieve_aux_wf],\n  finish [list.mem_filter],\n  finish [list.mem_filter],\nend\n\nlemma nth_le_drop_range (m n i: ℕ) (h: i < n):\n  (list.drop m (list.range (m + n))).nth_le i (by simpa) = m + i :=\nbegin\n  rw ← list.nth_le_drop (list.range (m + n)),\n  rw list.nth_le_range,\n  simpa only [list.length_range, add_lt_add_iff_left],\nend\n\nlemma range_drop_mem₁ (m n k: ℕ) :\n  (k < n) -> k ∉ (list.range m).drop n :=\nbegin\n  intro h₁,\n  by_cases n ≤ m,\n\n  cases nat.le.dest h with m' h₂,\n  rw [←h₂] at *,\n  clear h₂ m h,\n\n  simp only [list.mem_iff_nth_le, not_exists, add_lt_add_iff_left],\n  intros i h₂,\n  rw nth_le_drop_range,\n  linarith,\n  simp only [*, list.length_drop, nat.add_sub_cancel_left, list.length_range] at *,\n\n  set li := (list.range m).drop n with h₂,  \n  have h₃: li.length = 0 := \n    by simp only [list.length_drop, list.length_range, le_of_not_ge h, nat.sub_eq_zero_of_le],\n\n  simp only [list.length_eq_zero.mp h₃, list.not_mem_nil, not_false_iff],  \nend\n\nlemma range_drop_mem₂ (m n k: ℕ) :\n  (k ≥ n) -> (k < m) -> k ∈ (list.range m).drop n :=\nbegin\n  intros h₁ h₂,\n\n  have h₄ : n ≤ m := by linarith,  \n  cases nat.le.dest h₁ with k' h₃,  \n  cases nat.le.dest h₄ with m' h₅,\n  simp only [←h₃, ←h₅, add_lt_add_iff_left] at *,\n  clear h₁ h₃ h₄ h₅ m k,\n\n  simp only [list.mem_iff_nth_le],\n  use k',\n\n  fconstructor,\n  simp only [*, list.length_drop, nat.add_sub_cancel_left, list.length_range],  \n\n  rwa [nth_le_drop_range],\nend\n\nlemma range_drop_mem₃ (m n k: ℕ) :\n  (k ≥ m) -> k ∉ (list.range m).drop n :=\nbegin\n  intros h₁ h₂,\n  have h₃ : k ∉ list.range m := by finish,\n  have h₄ : k ∈ list.range m := list.mem_of_mem_drop h₂,\n  contradiction,\nend\n\ntheorem sieve_keeps_primes₂ (m n: ℕ) :\n  n < m -> nat.prime n -> n ∈ sieve m :=\nbegin  \n  intros h₁ h₂,\n  refine sieve_keeps_primes₁ _ _ h₂ _ _,\n  simp only [range_drop_mem₁, nat.one_lt_bit0_iff, not_false_iff],\n  finish [nat.prime, range_drop_mem₂],\nend\n\nlemma sieve_filters₁ (n k: ℕ) (li: list ℕ) :\n  (n ≠ k) -> (n ∣ k) -> k ∉ sieve_aux (n :: li) :=\nbegin\n  intros h₁ h₂ h₃,\n  safe [sieve_aux],\n  replace h₃ := sieve_aux_mem h₃,\n  finish,\nend\n\nlemma sieve_sublist₁ (x: ℕ) (li: list ℕ) :\n  sieve_aux (li ++ [x]) <+ sieve_aux li ++ [x] :=\nbegin\n  apply well_founded.induction (measure_wf list.length) li,\n  clear li,\n\n  intros li h₁,\n\n  cases li,\n  simp only [sieve_aux, list.filter_nil, list.nil_append],\n\n  simp only [sieve_aux, list.filter_append, list.cons_append],\n  apply list.sublist.cons2,\n\n  by_cases li_hd ∣ x,\n\n  have h₂ : list.filter (λ (n : ℕ), ¬li_hd ∣ n) [x] = list.nil := by finish,\n  rw h₂,\n  simp only [list.sublist_append_left, list.append_nil],\n\n  have h₂ : list.filter (λ (n : ℕ), ¬li_hd ∣ n) [x] = [x] := by finish,\n  rw h₂,\n  apply h₁,\n  \n  simp only [measure, inv_image, list.length, sieve_aux_wf],\nend\n\nlemma sieve_filters₂ (n k: ℕ) (li: list ℕ) :\n  (nat.prime n) -> (n ≠ k) -> (n ∣ k) -> \n  (1 ∉ li) -> (k ∉ li) -> (n ∈ li) -> (k ∉ sieve_aux (li ++ [k])) :=\nbegin\n  intros h₀ h₁ h₂,\n  apply well_founded.induction (measure_wf list.length) li,\n  intros li' h₆ h₃ h₄ h₅,\n  clear li,\n\n  cases li',\n  solve_by_elim,\n\n  simp only [list.cons_append, sieve_aux, list.filter_append, list.mem_cons_iff, ne.def] at *,\n  push_neg,\n  split,\n  tauto,\n\n  by_cases li'_hd ∣ k,\n  \n  clear h₆,\n  simp only [*, list.filter_cons_of_neg, list.filter_nil,\n    list.append_nil, not_true, not_false_iff] at *,\n  intro h₆,\n  replace h₆ := sieve_aux_mem h₆,\n  simp only [*, list.mem_filter, not_true] at *,\n  \n  simp only [*, list.filter_nil, not_false_iff, list.filter_cons_of_pos] at *,\n  apply h₆,\n  all_goals { clear h₆ },\n\n  simp only [*, measure, inv_image, list.length, sieve_aux_wf],\n\n  simp only [*, and_true, list.mem_filter, not_false_iff],\n  tauto,\n\n  simp only [*, list.mem_filter, and_true, not_false_iff],\n  tauto,\n\n  finish [list.mem_filter, nat.prime],\nend\n\nlemma range_drop_append (n k: ℕ):\n  (k ≤ n) -> list.drop k (list.range (n + 1)) = list.drop k (list.range n) ++ [n] :=\nbegin\n  intro h₁,\n  cases nat.le.dest h₁ with n' h₂,\n  rw [←h₂] at *,\n  clear h₂ h₁ n,\n\n  apply list.ext_le,\n  simp only [list.length_append, list.length_drop, nat.add_sub_cancel_left,\n    list.length_singleton, list.length_range],\n  omega,\n  \n  intros i h₂ h₃,\n  set li₂ := list.drop k (list.range (k + n')) ++ [k + n'],\n  ring,\n  rw nth_le_drop_range,\n\n  by_cases i = n',\n  \n  have h₄ : i = li₂.length - 1,\n  simpa only [nat.add_succ_sub_one, add_zero, list.length_append, list.length_drop, \n    nat.add_sub_cancel_left, list.length_singleton, list.length_range],\n\n  simp only [h₄],\n  rw ←list.last_eq_nth_le,\n  simp only [nat.add_succ_sub_one, add_zero, list.length_append, list.length_drop,\n    nat.add_sub_cancel_left, list.length_singleton, list.length_range, list.last_append],\n  simp only [list.append_eq_nil, ne.def, not_false_iff, and_false],\n\n  have h₄ : i < li₂.length - 1,\n  simp only [*, nat.add_succ_sub_one, add_zero, list.length_append, list.length_drop, \n    nat.add_sub_cancel_left, list.length_singleton, list.length_range] at *,\n  omega,\n\n  rw [list.nth_le_append, nth_le_drop_range],\n\n  finish,\n  finish,\nend\n\nlemma sieve_filters₃ (n: ℕ) :\n  ¬nat.prime n -> n ∉ sieve (n + 1) := \nbegin\n  intro h₁,\n  rw sieve,\n  \n  cases n,\n  exact dec_trivial,\n  cases n,\n  exact dec_trivial,\n\n  rw nat.not_prime_iff_min_fac_lt at h₁,\n  swap,\n  exact dec_trivial,\n\n  rw range_drop_append,\n  swap,\n  exact dec_trivial,\n\n  set n' := n.succ.succ,\n  set k := n'.min_fac,\n  have h₂ := nat.min_fac_prime (dec_trivial : n' ≠ 1),\n  refine sieve_filters₂ k n' _ _ _ _ _ _ _,\n\n  exact h₂,\n  linarith,\n  exact nat.min_fac_dvd n',\n  \n  apply range_drop_mem₁,\n  exact dec_trivial,\n\n  apply range_drop_mem₃,\n  simp only [ge_iff_le],\n\n  apply range_drop_mem₂,\n  exact h₂.left,\n  exact h₁,\nend\n\nlemma sieve_filters_nonprimes (m n: ℕ) :\n  n < m -> ¬nat.prime n -> n ∉ sieve m :=\nbegin\n  intros h₁ h₂,\n\n  induction m,\n  exact dec_trivial,\n  \n  by_cases n = m_n,\n  rw ←h,\n  apply sieve_filters₃,\n  exact h₂,\n\n  have h₃ : n < m_n := by omega,\n  specialize m_ih h₃,\n  clear h h₁,\n\n  by_cases 2 ≤ m_n,\n  swap,\n  \n  cases m_n,\n  exact dec_trivial,\n  cases m_n,\n  exact dec_trivial,\n  simp only [nat.succ_eq_add_one, not_le] at *,\n  linarith,\n\n  rw [sieve, nat.succ_eq_add_one, range_drop_append],\n  swap,\n  exact h,\n\n  intro h₁,\n  have h₃ := sieve_sublist₁ m_n (list.drop 2 (list.range m_n)),\n  rw [sieve] at m_ih,\n  replace h₃ := (list.sublist.subset h₃) h₁,\n\n  finish,\nend\n\ntheorem prime_sieve (m n: ℕ) :\n  n < m -> (nat.prime n ↔ n ∈ (sieve m)) :=\nbegin \n  intro h₁,\n  split,\n  exact sieve_keeps_primes₂ _ _ h₁,\n  \n  intro h₂,\n  have h₃ := sieve_filters_nonprimes _ _ h₁,\n  cc,\nend\n", "meta": {"author": "technosentience", "repo": "lean-algorithms", "sha": "1a2d8ada915da276313ec4c2fd1ce98c7aaf0055", "save_path": "github-repos/lean/technosentience-lean-algorithms", "path": "github-repos/lean/technosentience-lean-algorithms/lean-algorithms-1a2d8ada915da276313ec4c2fd1ce98c7aaf0055/src/primesieve.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.762156267501836}}
{"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 data.fin.tuple.bubble_sort_induction\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.Data.Fin.Tuple.Sort\nimport Mathlib.Data.Fintype.Perm\nimport Mathlib.Order.WellFounded\n\n/-!\n# \"Bubble sort\" induction\n\nWe implement the following induction principle `Tuple.bubble_sort_induction`\non tuples with values in a linear order `α`.\n\nLet `f : Fin n → α` and let `P` be a predicate on `Fin n → α`. Then we can show that\n`f ∘ sort f` satisfies `P` if `f` satisfies `P`, and whenever some `g : Fin n → α`\nsatisfies `P` and `g i > g j` for some `i < j`, then `g ∘ swap i j` also satisfies `P`.\n\nWe deduce it from a stronger variant `Tuple.bubble_sort_induction'`, which\nrequires the assumption only for `g` that are permutations of `f`.\n\nThe latter is proved by well-founded induction via `WellFounded.induction_bot'`\nwith respect to the lexicographic ordering on the finite set of all permutations of `f`.\n-/\n\n\nnamespace Tuple\n\n/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`\nif `f` satsifies `P` and `P` is preserved on permutations of `f` when swapping two\nantitone values. -/\ntheorem bubble_sort_induction' {n : ℕ} {α : Type _} [LinearOrder α] {f : Fin n → α}\n    {P : (Fin n → α) → Prop} (hf : P f)\n    (h :\n      ∀ (σ : Equiv.Perm (Fin n)) (i j : Fin n),\n        i < j → (f ∘ σ) j < (f ∘ σ) i → P (f ∘ σ) → P (f ∘ σ ∘ Equiv.swap i j)) :\n    P (f ∘ sort f) := by\n  letI := @Preorder.lift _ (Lex (Fin n → α)) _ fun σ : Equiv.Perm (Fin n) => toLex (f ∘ σ)\n  refine'\n    @WellFounded.induction_bot' _ _ _ (@Finite.Preorder.wellFounded_lt (Equiv.Perm (Fin n)) _ _)\n      (Equiv.refl _) (sort f) P (fun σ => f ∘ σ) (fun σ hσ hfσ => _) hf\n  obtain ⟨i, j, hij₁, hij₂⟩ := antitone_pair_of_not_sorted' hσ\n  exact ⟨σ * Equiv.swap i j, Pi.lex_desc hij₁ hij₂, h σ i j hij₁ hij₂ hfσ⟩\n#align tuple.bubble_sort_induction' Tuple.bubble_sort_induction'\n\n/-- *Bubble sort induction*: Prove that the sorted version of `f` has some property `P`\nif `f` satsifies `P` and `P` is preserved when swapping two antitone values. -/\ntheorem bubble_sort_induction {n : ℕ} {α : Type _} [LinearOrder α] {f : Fin n → α}\n    {P : (Fin n → α) → Prop} (hf : P f)\n    (h : ∀ (g : Fin n → α) (i j : Fin n), i < j → g j < g i → P g → P (g ∘ Equiv.swap i j)) :\n    P (f ∘ sort f) :=\n  bubble_sort_induction' hf fun _ => h _\n#align tuple.bubble_sort_induction Tuple.bubble_sort_induction\n\nend Tuple\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/BubbleSortInduction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7621562656576837}}
{"text": "namespace hidden\nuniverse u\n\n-------------------------------------------------------------------------------\ninductive list (A:Type) : Type\n| Nil {} : list -- Brez {} moramo konstruktorju Nil vedno podati tip A\n| Cons : A -> list -> list -- Cons tip A ugotovi iz tipa prvega elementa\n\nnamespace list\n-- Dopolnite definicije in dokažitve trditve za sezname iz vaj 3. Uporabljate -- lahko notacijo x :: xs, [] in ++ (namesto @), vendar bodite pozorni na\n-- oklepaje.\n\nnotation x `::` xs := Cons x xs\nnotation `[]` := Nil\n\ndef join {A} : list A -> list A -> list A\n| [] ys := ys\n| (x :: xs) ys := x :: (join xs ys)\n\nnotation xs `++` ys := join xs ys\n\ntheorem join_nil {A} (xs: list A) :\n  xs ++ [] = xs \n:=\nbegin\n  induction xs,\n  { unfold join, },\n  unfold join, rewrite xs_ih,\nend\n\ndef reverse {A} : list A -> list A\n| [] := []\n| (x::xs) := (reverse xs) ++ (x::[])\n\n\ntheorem join_assoc {A} (xs ys zs : list A) :\n  xs ++ (ys ++ zs) = (xs ++ ys) ++ zs\n:=\nbegin\n  induction xs,\n  unfold join,\n  unfold join, rewrite xs_ih,\nend\n\n\ntheorem reverse_join {A} (xs ys : list A):\n  reverse (xs ++ ys) = (reverse ys) ++ (reverse xs)\n:=\nbegin\n  induction xs,\n  { unfold join, unfold reverse, rewrite join_nil, },\n  unfold join, unfold reverse, rewrite xs_ih,\n  rewrite join_assoc,\nend\n\n\n\n\n\nend list\n-------------------------------------------------------------------------------\n\n-- Podobno kot za sezname, napišite tip za drevesa in dokažite trditve iz \n-- vaj 3. Če po definiciji tipa `tree` odprete `namespace tree` lahko\n-- uporabljate konstruktorje brez predpone, torej `Empty` namesto\n-- `tree.Empty`.\n\ninductive tree (A:Type) : Type\n| Empty {} : tree \n| Node : tree -> A -> tree -> tree \n\nnamespace tree\n\ndef mirror {A} : tree A -> tree A\n| Empty := Empty\n| (Node lt x rt) := Node (mirror rt) x (mirror lt)   \ntheorem mirror_mirror {A} (t : tree A) :\n  mirror (mirror t) = t\n:=\nbegin\ninduction t,\n{ unfold mirror, },\nunfold mirror, rewrite [t_ih_a, t_ih_a_1],\nend\n\ndef tree_map {A B : Type} (f : A -> B) : tree A -> tree B\n| Empty := Empty\n| (Node lt x rt) := Node (tree_map lt) (f x) (tree_map rt)\n\ntheorem mirror_map_comm {A B} (t : tree A) (f : A -> B) :\n  tree_map f (mirror t) = mirror (tree_map f t) \n:=\nbegin\n  induction t,\n  { unfold mirror, unfold tree_map, unfold mirror, },\n  unfold mirror, unfold tree_map,\n  rewrite [t_ih_a, t_ih_a_1],\n  unfold mirror,\nend\n\nend tree\n\nend hidden", "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_delno_resene.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.7620868429068274}}
{"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 linear_algebra.quotient\nimport 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\nuniverses v u\n\nopen category_theory\nopen Module\nopen_locale Module\n\nnamespace Module\n\nvariables {R : Type u} [ring R] {X Y : Module.{v} R} (f : X ⟶ Y)\nvariables {M : Type v} [add_comm_group M] [module R M]\n\nlemma ker_eq_bot_of_mono [mono f] : f.ker = ⊥ :=\nlinear_map.ker_eq_bot_of_cancel $ λ u v, (@cancel_mono _ _ _ _ _ f _ ↟u ↟v).1\n\nlemma range_eq_top_of_epi [epi f] : f.range = ⊤ :=\nlinear_map.range_eq_top_of_cancel $ λ u v, (@cancel_epi _ _ _ _ _ f _ ↟u ↟v).1\n\nlemma mono_iff_ker_eq_bot : mono f ↔ f.ker = ⊥ :=\n⟨λ hf, by exactI ker_eq_bot_of_mono _,\n λ hf, concrete_category.mono_of_injective _ $ linear_map.ker_eq_bot.1 hf⟩\n\nlemma mono_iff_injective : mono f ↔ function.injective f :=\nby rw [mono_iff_ker_eq_bot, linear_map.ker_eq_bot]\n\nlemma epi_iff_range_eq_top : epi f ↔ f.range = ⊤ :=\n⟨λ hf, by exactI range_eq_top_of_epi _,\n λ hf, concrete_category.epi_of_surjective _ $ linear_map.range_eq_top.1 hf⟩\n\nlemma epi_iff_surjective : epi f ↔ function.surjective f :=\nby rw [epi_iff_range_eq_top, linear_map.range_eq_top]\n\n/-- If the zero morphism is an epi then the codomain is trivial. -/\ndef unique_of_epi_zero (X) [h : epi (0 : X ⟶ of R M)] : unique M :=\nunique_of_surjective_zero X ((Module.epi_iff_surjective _).mp h)\n\ninstance mono_as_hom'_subtype (U : submodule R X) : mono ↾U.subtype :=\n(mono_iff_ker_eq_bot _).mpr (submodule.ker_subtype U)\n\ninstance epi_as_hom''_mkq (U : submodule R X) : epi ↿U.mkq :=\n(epi_iff_range_eq_top _).mpr $ submodule.range_mkq _\n\ninstance forget_preserves_epimorphisms : (forget (Module.{v} R)).preserves_epimorphisms :=\n{ preserves := λ X Y f hf, by rwa [forget_map_eq_coe, category_theory.epi_iff_surjective,\n    ← epi_iff_surjective] }\n\ninstance forget_preserves_monomorphisms : (forget (Module.{v} R)).preserves_monomorphisms :=\n{ preserves := λ X Y f hf, by rwa [forget_map_eq_coe, category_theory.mono_iff_injective,\n    ← mono_iff_injective] }\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/epi_mono.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.76195934531187}}
{"text": "import tactic.finish\n\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 → N → Prop := sorry\n\n-- functions mapping N to nat and back\ndef nto : N → nat := sorry\ndef nof : nat → N := sorry\n\n-- axioms needed for transfer:\n-- the nto and nof are inverses\naxiom ax1 : ∀ n : nat, nto(nof(n)) = n\naxiom ax2 : ∀ x : N, nof(nto(x)) = x\n-- ordering is preserved by the mapping\naxiom ax3 : ∀ x y : N, ordern x y → nto x <= nto y \naxiom ax4 : ∀ m n : nat, m <= n → ordern (nof m) (nof 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 : ∀ x y z : nat, x <= y → y <= z → x <= z := sorry\n\ntheorem transitiveorder_N : ∀ x y z : N, ordern x y → ordern y z → ordern x z :=\nbegin\n  intros,\n  rw← ax2 x,\n  rw← ax2 z,\n  apply ax4,\n  apply transitiveorder_nat _ (nto y) _;\n  finish using [ax3]\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' : ∀ x y z : nat, x <= y → y <= z → x <= z := \nbegin \n  intros,\n  rw← ax1 x,\n  rw← ax1 z,\n  apply ax3,\n  apply transitiveorder_N _ (nof y) _;\n  finish using [ax4]\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 → Z2 → Z2\n| zero y := y\n| one zero := one \n| one one := zero\n\ninductive Z2.even : Z2 → Prop\n| zeroiseven : Z2.even zero\n\n-- mapping from int to Z2 (no inverse mapping)\ndef ztoz2 : int → Z2 := λ n, if n % 2 = 0 then zero else one\n\n-- axioms needed for transfer:\n-- mapping is surjective\naxiom surjectivemap : function.surjective ztoz2\n-- mapping respects add and even (there must be transfer axioms for every operation and predicate in the theorem)\naxiom transfer_add : ∀ m n : int, (ztoz2 m).add (ztoz2 n) = ztoz2(m + n)\naxiom eventoz2 : ∀ n : int, even n → Z2.even (ztoz2 n)\naxiom evenfromz2 : ∀ n : int, Z2.even (ztoz2 n) → 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 : ∀ m n : int, ¬ even m → ¬ even n → even (m + n) := sorry\n\ntheorem thetheoremforZ2 : ∀ x y : Z2, ¬ Z2.even x → ¬ Z2.even y → Z2.even (Z2.add x y) := \nbegin\n  intros,\n  rw [← classical.some_spec (surjectivemap x)] at *,\n  rw [← classical.some_spec (surjectivemap y)] at *,\n  rw transfer_add,\n  apply eventoz2,\n  apply thetheoremforint;\n  finish using [eventoz2]\nend\n\n-- the other direction can also be shown\ntheorem thetheoremforint' : ∀ x y : int, ¬ even x → ¬ even y → even (x + y) := \nbegin\n  intros,\n  apply evenfromz2,\n  rw← transfer_add,\n  apply thetheoremforZ2;\n  finish using [evenfromz2]\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 → int := int.of_nat --in all example cases the implementations are optional and not necessary for the proofs (nice to have for computation later?)\ndef nofi : int → nat := int.nat_abs\n\n-- axioms needed for transfer:\naxiom inverse1way : ∀ n : nat, nofi(ntoi n) = n\n-- respect add\naxiom transfer_add : ∀ x y : int, nofi x + nofi y = nofi (x + y)\n-- respect even\naxiom eventoint: ∀ x : int, even (nofi x) → evenint x\naxiom evenfromint : ∀ x : int, evenint x → even (nofi x)\n\ntheorem thetheoremfornat : ∀ m n : nat, ¬ even m → ¬ even n → even (m + n) := sorry\n\ntheorem thetheoremforint : ∀ x y : int, ¬ evenint x → ¬ evenint y → evenint (x + y) :=\nbegin\n  intros,\n  apply eventoint,\n  rw← transfer_add,\n  apply thetheoremfornat;\n  finish using [eventoint]\nend\n\ntheorem thetheoremfornat' : ∀ m n : nat, ¬ even m → ¬ even n → even (m + n) :=\nbegin\n  intros,\n  rw← inverse1way m at *,\n  rw← inverse1way n at *,\n  rw transfer_add,\n  apply evenfromint,\n  apply thetheoremforint;\n  finish using [evenfromint]\nend\n\nend example3\n\n\n-- EXAMPLE 4: the ordering theorem but with int and nat\nnamespace example4\n\n-- mapping between nat and int\ndef ntoi : nat → int := int.of_nat\ndef nofi : int → nat := int.nat_abs\n\n-- axioms needed for transfer:\n-- 1 direction is invertible\naxiom inverse1way : ∀ n : nat, nofi(ntoi n) = n\n\n-- ordering is not really preserved by the mapping, which poses a problem\n-- ∀ x y : int, x <= y → nofi x <= nofi y     does not hold\n-- ∀ x y : int, nofi x <= nofi y → x <= y     does not hold\n-- axiom order_ntoi : ∀ m n : nat, m <= n → ntoi m <= ntoi n      not useful\naxiom order_nofi : ∀ x y : int, x <= y → nofi x <= nofi y ∨ nofi y <= nofi x    -- doesn't go anywhere\n\n-- transfer approach does not seem to work for this problem\n-- idea: smaller axioms ie x<=y and x>0 → nofi x <= nofi y\n--                         x<=y and x<0 and y>0 → either is larger\n--                         x<=y and x<0 and y<0 → nofi x >= nofi y\n--   and split on cases <0 >0\n-- doesn't seem too useful either \n\ntheorem transitiveorder_nat : ∀ a b c : nat, a <= b → b <= c → a <= c := sorry\n\ntheorem transitiveorder_int : ∀ x y z : int, x <= y → y <= z → x <= z :=\nbegin\n  intros,\n  have hnxy : nofi x <= nofi y ∨ nofi y <= nofi x := by apply order_nofi _ _ a,\n  have hnyz : nofi y <= nofi z ∨ nofi z <= nofi y := by apply order_nofi _ _ a_1,\n  cases hnxy; cases hnyz,\n\n  have hnxz : nofi x <= nofi z := begin apply transitiveorder_nat _ _ _ hnxy hnyz end,\n  repeat {sorry},\nend\n\ntheorem transitiveorder_nat' : ∀ a b c : nat, a <= b → b <= c → a <= c :=\nbegin\n  intros,\n  rw← inverse1way a at *,\n  rw← inverse1way b at *,\n  rw← inverse1way c at *,\n  sorry\nend\n\nend example4", "meta": {"author": "KoenKahlman", "repo": "transfer", "sha": "b7de7b23ed00764dd02b5c6fd715a70c6e0b8374", "save_path": "github-repos/lean/KoenKahlman-transfer", "path": "github-repos/lean/KoenKahlman-transfer/transfer-b7de7b23ed00764dd02b5c6fd715a70c6e0b8374/examples.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7619593312191125}}
{"text": "import data.list data.subtype data.sigma\nopen subtype list prod prod.ops sigma.ops\n\ndefinition edge (V : Type) := V × V\ndefinition graph (V : Type) := edge V → Prop\n\ndefinition undirected {V : Type} (g : graph V) := ∀ (u v : V), g (u,v) → g (v,u)\n\nnamespace path\n\nvariables {V : Type} [V_decidable_eq : decidable_eq V]\ninclude V_decidable_eq\n\ndefinition path : graph V → V → V → Prop := sorry\ndefinition repeated_edges {g : graph V} {u v : V} (p : path g u v) : Prop := sorry\n\ndefinition simple_path (g : graph V) (u v : V) := { p : path g u v | ¬ repeated_edges p }\n\ndefinition path_contains_edge {g : graph V} {u v : V} : path g u v → edge V → Prop := sorry\n\nlemma simple_path_nonempty (g : graph V) (u v : V) (spath : simple_path g u v) : ∃ e, g e ∧ path_contains_edge (spath.1) e\n\ndefinition cycle (g : graph V) (u : V) := path g u u\n\ndefinition simple_cycle (g : graph V) := Σ (u : V) (p : cycle g u), ¬ repeated_edges p\n\nvariables {g : graph V}\n\ntheorem path_refl (g : graph V) : ∀ (v : V), path g v v := sorry\ntheorem path_symm (g : graph V) : ∀ {u v : V}, path g u v → path g v u := sorry\ntheorem path_trans (g : graph V) : ∀ {u v w : V}, path g u v → path g v w → path g u w := sorry\n\ndefinition graph_connected (g : graph V) := ∀ (u v : V), path g u v\n\ndefinition remove_edge (g : graph V) (e : edge V) : graph V := λ (f : edge V), if f.1 = e.1 ∧ f.2 = e.2 ∨ f.1 = e.2 ∧ f.2 = e.1 then false else g f\n\n-- An undirected graph G is called k-edge-connected iff G is connected, and there is no set of k – 1 edges that can be removed from G that disconnects it\ndefinition two_edge_connected (g : graph V) := graph_connected g ∧ ¬ ∃ (e1 e2 : edge V), g e1 ∧ g e2 ∧ ¬ graph_connected (remove_edge (remove_edge g e1) e2)\n\n-- A bridge in a connected, undirected graph G is an edge in G that, if removed, disconnects G.\ndefinition has_bridge (g : graph V) : Prop := graph_connected g ∧ ∃ (e : edge V), g e ∧ ¬ graph_connected (remove_edge g e)\n\n-- Theorem: An undirected graph G is 2-edge-connected iff it is connected and has no bridges.\ntheorem two_edge_connected_iff (g : graph V) : two_edge_connected g ↔ graph_connected g ∧ ¬ has_bridge g := sorry\n\n/- [KS]\nTheorem: Let G = (V, E) be any graph containing a simple cycle C. Let u, v ∈ V be nodes in G. If\nu ↔ v, then after deleting any single edge in C from graph G, it is still the case that u ↔ v.\n\nProof: Consider any graph G = (V, E) with a simple cycle C = (x1, x2, …, xn, x1). Consider any u, v ∈\nV such that u ↔ v. This means that there must be some simple path (u, y1, y2, …, ym, v) from u to v.\n\nNow, suppose that we remove the edge {xi, xi+1} from G.  We need to show that u ↔ v in this modified\ngraph. We consider two cases. First, it might be the case that the edge {xi, xi+1} does not appear\non the path (u, y1, …, ym, v). In that case, the path (u, y1, …, ym, v) is a valid path from u to v in the\nnew graph, so u ↔ v still holds.\n\nSecond, it might be the case that the edge {xi, xi+1} appears somewhere in our original path (u, y1, …,\nym, v). Since the graph is undirected, the edge might appear as {xi, xi+1} or as {xi+1, xi} when it occurs\nin the path. Assume without loss of generality that it appears as {xi, xi+1} (otherwise, we can just reverse\nthe ordering of the nodes in the original cycle so as to relabel the edges). This means that we\ncan split the original path into three smaller paths – a path from u to xi, then the edge {xi, xi+1}, and finally\na path from xi+1 to v. Thus u ↔ xi and xi+1 ↔ v. Now, since the edge {xi, xi+1} lies on the cycle\nC, after deleting the edge from the cycle, there is still a path from xi to xi+1. Specifically, we can follow\nthe edges of the cycle in reverse from xi until we reach xi+1. In other words, in this new graph, we\nmust have that xi ↔ xi+1.\n\nSince in this new graph u ↔ xi, xi ↔ xi+1, and xi+1 ↔ v, we thus have that u ↔ v in the new graph, as\nrequired. \n-/\n\nlemma path_imp_simple_path (g : graph V) : ∀ (u v : V), path g u v → simple_path g u v := sorry\n\ntheorem remove_edge_from_simple_cycle (g : graph V) (scycle : simple_cycle g) : ∀ (u v : V), path g u v → ∀ (e : edge V), g e → path (remove_edge g e) u v :=\n  -- Proof: Consider any graph G = (V, E) with a simple cycle C = (x1, x2, …, xn, x1). \n  -- Consider any u, v ∈ V such that u ↔ v. \n  take (u v : V) (u_conn_v : path g u v),\n  -- This means that there must be some simple path (u, y1, y2, …, ym, v) from u to v.\n  have u_sconn_v : simple_path g u v, from path_imp_simple_path u_conn_v,\n  -- Now, suppose that we remove the edge {xi, xi+1} from G.  \n  let G' := remove_edge g in\n  \n\n/-We need to show that u ↔ v in this modified\ngraph. We consider two cases. First, it might be the case that the edge {xi, xi+1} does not appear\non the path (u, y1, …, ym, v). In that case, the path (u, y1, …, ym, v) is a valid path from u to v in the\nnew graph, so u ↔ v still holds.\n-/\n\n\nend path\n\n\n\n", "meta": {"author": "dselsam", "repo": "cs103", "sha": "31ab9784a6f65f226efb702a0da52f907c616a71", "save_path": "github-repos/lean/dselsam-cs103", "path": "github-repos/lean/dselsam-cs103/cs103-31ab9784a6f65f226efb702a0da52f907c616a71/path.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7619197379843358}}
{"text": "import data.real.basic\nimport data.real.sqrt\n\nopen set real\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    sqrt '' { x | x ≥ 0 } = {y | y ≥ 0}\n-- ----------------------------------------------------------------------\n\nexample : sqrt '' { x | x ≥ 0 } = {y | y ≥ 0} :=\nbegin\n  ext,\n  split,\n  { intro h,\n    rcases h with ⟨y,hy,eq⟩,\n    simp at *,\n    rw ← eq,\n    exact sqrt_nonneg y },\n  { intro h,\n    use x ^ 2,\n    simp at *,\n    split,\n    { exact pow_nonneg h 2 },\n    { finish }},\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ sqrt '' {x : ℝ | x ≥ 0} = {y : ℝ | y ≥ 0}\n  >> ext,\nx : ℝ\n⊢ x ∈ sqrt '' {x : ℝ | x ≥ 0} ↔ x ∈ {y : ℝ | y ≥ 0}\n  >> split,\n| x : ℝ\n| ⊢ x ∈ sqrt '' {x : ℝ | x ≥ 0} → x ∈ {y : ℝ | y ≥ 0}\n|   >> { intro h,\n| h : x ∈ sqrt '' {x : ℝ | x ≥ 0}\n| ⊢ x ∈ {y : ℝ | y ≥ 0}\n|   >>   rcases h with ⟨y,hy,eq⟩,\n| x y : ℝ,\n| hy : y ∈ {x : ℝ | x ≥ 0},\n| eq : y.sqrt = x\n| ⊢ x ∈ {y : ℝ | y ≥ 0}\n|   >>   simp at *,\n| hy : 0 ≤ y\n| ⊢ 0 ≤ x\n|   >>   rw ← eq,\n| ⊢ 0 ≤ y.sqrt\n|   >>   exact sqrt_nonneg y },\nx : ℝ\n⊢ x ∈ {y : ℝ | y ≥ 0} → x ∈ sqrt '' {x : ℝ | x ≥ 0}\n  >> { intro h,\nh : x ∈ {y : ℝ | y ≥ 0}\n⊢ x ∈ sqrt '' {x : ℝ | x ≥ 0}\n  >>   use x ^ 2,\n⊢ x ^ 2 ∈ {x : ℝ | x ≥ 0} ∧ (x ^ 2).sqrt = x\n  >>   simp at *,\nh : 0 ≤ x\n⊢ 0 ≤ x ^ 2 ∧ (x ^ 2).sqrt = x\n  >>   split,\n| ⊢ 0 ≤ x ^ 2\n|   >>   { exact pow_nonneg h 2 },\n⊢ (x ^ 2).sqrt = x\n  >>   { exact sqrt_sqr h }},\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + x.sqrt_nonneg : 0 ≤ x.sqrt\n-- + pow_nonneg : 0 ≤ x → ∀ (n : ℕ), 0 ≤ x ^ n\n\n-- Comprobación:\n-- variable (x : ℝ)\n-- #check @sqrt_nonneg x\n-- #check @pow_nonneg _ _ x\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que\n--    range (λ (x : ℝ), x^2) = {y | y ≥ 0} :=\n-- ----------------------------------------------------------------------\n\nexample : range (λ (x : ℝ), x^2) = {y | y ≥ 0} :=\nbegin\n  ext,\n  split,\n  { intro h,\n    simp at *,\n    rcases h with ⟨y,hy⟩,\n    rw ← hy,\n    exact pow_two_nonneg y },\n  { intro h,\n    use sqrt x,\n    simp at *,\n    by finish, },\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ range (λ (x : ℝ), x ^ 2) = {y : ℝ | y ≥ 0}\n  >> ext,\nx : ℝ\n⊢ x ∈ range (λ (x : ℝ), x ^ 2) ↔ x ∈ {y : ℝ | y ≥ 0}\n  >> split,\n| ⊢ x ∈ range (λ (x : ℝ), x ^ 2) → x ∈ {y : ℝ | y ≥ 0}\n|   >> { intro h,\n| h : x ∈ range (λ (x : ℝ), x ^ 2)\n| ⊢ x ∈ {y : ℝ | y ≥ 0}\n|   >>   simp at *,\n| h : ∃ (y : ℝ), y ^ 2 = x\n| ⊢ 0 ≤ x\n|   >>   rcases h with ⟨y,hy⟩,\n| x y : ℝ,\n| hy : y ^ 2 = x\n| ⊢ 0 ≤ x\n|   >>   rw ← hy,\n| ⊢ 0 ≤ y ^ 2\n|   >>   exact pow_two_nonneg y },\nx : ℝ\n⊢ x ∈ {y : ℝ | y ≥ 0} → x ∈ range (λ (x : ℝ), x ^ 2)\n  >> { intro h,\nh : x ∈ {y : ℝ | y ≥ 0}\n⊢ x ∈ range (λ (x : ℝ), x ^ 2)\n  >>   use sqrt x,\n⊢ (λ (x : ℝ), x ^ 2) x.sqrt = x\n  >>   simp at *,\nh : 0 ≤ x\n⊢ x.sqrt ^ 2 = x\n  >>   exact sqr_sqrt h },\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + pow_two_nonneg x : 0 ≤ x ^ 2\n-- + sqr_sqrt : 0 ≤ x → (sqrt x) ^ 2 = x\n\n-- Comprobación:\n-- #check @pow_two_nonneg _ _ x\n-- #check @sqr_sqrt 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/Rango_del_cuadrado.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7619008957698842}}
{"text": "-- propositions\n-- proofs\n-- predicates\n    -- sets\n    -- relations\n    -- equality\n-- connectives\n    -- not\n    -- and\n    -- or\n\n\n-- proposition\ninductive nifty_was_a_cat : Prop\n-- proofs\n| there_are_pictures_of_nifty\n| we_remember_nifty_fondly\nopen nifty_was_a_cat \n\ntheorem nwac : nifty_was_a_cat := there_are_pictures_of_nifty\ntheorem there_is_a_natural_number : ℕ := 1\n\n/-\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 → Prop\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)\n#check (was_a_cat fido)\n#check (was_a_cat cheese)\n#check (was_a_cat tom)\n\ntheorem nwac' : was_a_cat nifty := \n    nifty_proof\n\n#check nifty_proof\n#check tom_proof\n\ntheorem cwac : was_a_cat cheese := _\n\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.\n\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 → Prop → Prop. This is just a\nProp parameterized by two Props, \nwhich we might call α and β. We\nneed a polymorphic type. \n\nnifty YES\nfido NO\ncheese NO\ntom YES\n-/\n\n#print and\n\nnamespace our_logic\n\n/-\nINTRODUCTION\nSuppose α and β are propositions.\nGiven proofs, (a : α) and (b : β), we \ncan build a proof, (and.intro a b), of \nα ∧ β.\n\nHere are three ways to write exactly\nthe same inductive definition.\n-/\n\ninductive and'' (α β : Prop) : Prop\n| intro : α → β → and''\n\n-- Here we build a big prop out of two small ones\ndef nwac_and_cwac : Prop := \n    and'' (was_a_cat nifty) (was_a_cat cheese)\n\n-- Here we try to construct a proof of the big prop\ndef pf : nwac_and_cwac := \n    and''.intro nifty_proof _\n\n-- Here we succeed in constructing a proof of it\ndef pf2 : \n    and'' (was_a_cat nifty) (was_a_cat tom) :=\n        and''.intro nifty_proof tom_proof\n\n-- The proposition is a (logical) type (of type Prop)\n#check and'' (was_a_cat nifty) (was_a_cat tom)\n-- The proof of it is a *value* of its logical type\n#check  and''.intro nifty_proof tom_proof\n-- Be sure you see exactly what's going on here!\n-- It's analogous to the following\n#check nat -- nat is a computational (of type, Type)\n#check 5 -- 5 is a value of type nat\n-- The proposition is analogous to ℕ: it's a type\n-- The proof is analogous to 5: a value of this type\n\n\n/- \nWe formalize the and left elimination rule\n(P ∧ Q) → P, as a function that takes a proof\nof (P ∧ Q) and that returns a proof of P. The\nkey ideas are that a proof of (P ∧ Q) is of\nthe form (and.intro p q), where (p : P) is a\nproof of P and (q : Q) is a proof of Q. We\nuse destructuring/pattern-matching to \"get\nour hands on\" the component proof, p, that\nis one part of a larger proof of P ∧ Q. \n-/\ndef and''_elim_left { α β : Prop} : (and'' α β) →  α \n| (and''.intro a _) := a\n\n#reduce and''_elim_left pf2\n\n/-\nWe put two tick marks on the name and''_elim_left\nbecause we're going to present exactly the same\nfunction using some slightly varying approaches\nto syntax. The last of our three versions is the\none we'd prefer to see. And please be aware that\nLean already provides the left and right elim\nfunctions through its libraries. They are called\nand.elim_left and and.elim_right. What you are\nseeing here is exactly how these functions work.\n-/\n\n-- The corresponding right elim rule, (P ∧ Q → P)\ndef and''_elim_right { α β : Prop} : (and'' α β) →  β \n| (and''.intro _ b) := b\n\n#reduce and''_elim_right pf2\n\n\n/-\nWe define a polymorphic \"and proposition builder\"\nwith explicitly named arguments. \n-/\n\ninductive and' (α β : Prop) : Prop\n| intro (left : α) (right : β) : and'\n\n/-\nAnd now, for the first time, you see the use\nof \"structure\" in Lean to (1) define a type with\none constructor, again called intro here, and with\ntwo arguments, with names left and right, of types\na and b. The benefit of using \"structure\" is that\ngiven a value, p, of this type, the names of the\nfields (left and right) can be used to obtain the\nfield values without having to write explicit\n\"projection functions\", such as elim_left and\nelim_right.\n-/\nstructure and (a b : Prop) : Prop :=\nintro :: (left : a) (right : b)\n\n\nopen and \n\nlemma cats : and (was_a_cat nifty) (was_a_cat tom) :=\n    and.intro nifty_proof tom_proof\n\n#reduce cats.left\n#reduce cats.right\n\n\n/-\nThe Lean libraries define ∧ as an infix notation\nfor (and _ _). We illustrate how this is done by\n\"overloading\" the similar looking ^ (caret) operator.\nWe don't try to overload ∧ here because it leads to\nan ambiguous interpretation of ∧, as ∧ is already\ndefined by Lean. \n-/\nnotation P ^ Q := and P Q   -- we don't overload ∧\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/-\nFor our nicely written \"and\" type (without ticks)\nwe rewrite the elimination rules. If we have a \nproof of P ^ Q, we can obtain individual proofs\nof P and Q, respectively. We define them in the\n\"and\" namespace. This is basically just as it is \nthe Lean libraries.\n-/\n\ndef and.elim_left {α β : Prop} : and α β → α\n| (and.intro a b) := a\n\ndef and.elim_right {α β : Prop} : and α β → β\n| (and.intro a b) := b\n\nend our_logic\n\n/-\nNow we're using Lean's libraries!\n-/\n\n-- PROPOSITIONS!!!\n#check and\ndef P1 : Prop := 0 = 0\ndef P2 : Prop := 1 = 1\ndef P12' : Prop := eq 1 1\n#check and P1 P2\n\n-- PROOFS!!!\n#check 0 = 0\n#check eq 0 0\n\ndef p1 : P1 := eq.refl 0\ndef p2 : P2 := eq.refl 1\n\nexample : 1 = 1 + 0 := eq.refl 1\n\n/-\nProve 0 = 0. \n\nProof: Equality is reflexive. This means that\nfor any value, a, of any type α, a = a.\n\n∀ {T : Type}, ∀ (t : T), t = t.\n\nWe apply this axiom to (ℕ and) 0, in \nparticular, to obtain a proof that 0 = 0.\n-/\n\ndef P1_and_P2' : Prop := and P1 P2\ndef P1_and_P2 : Prop := P1 ∧ P2     -- infix notation for and\n\ndef p1_and_p2' : P1_and_P2 := and.intro \n    p1 \n    p2\n\ndef p1_and_p2 : P1_and_P2 :=\nbegin\n    unfold P1_and_P2,\n    exact and.intro p1 p2,\nend\n\n#reduce p1_and_p2\n#reduce p1_and_p2'\n\n#check @and.elim_left\n\n#check and.elim_left p1_and_p2\n#check p1_and_p2.left\n\n#check and.elim_right p1_and_p2\n#check p1_and_p2.right\n\n#check @and.elim_left\n\ntheorem my_elim_left : ∀ (P1 P2 : Prop), P1 ∧ P2 → P1 :=\nλ P1 P2 h, \n    match h with\n    | and.intro a b := a\n    end\n\n/-\nEnglish language.\n\nWe are to prove P1 ∧ P2. The and introduction rule of\nnatural deduction tells us that it will suffice to\napply this rule to a proof of P1 and a proof of P2.\nSo what remains to be proved are P1 and P2. To prove\nP1, that 0 = 0, the reflexive property of equality\ntells us that *every* object is equal to itself. By\napplying this rule to the particular value, 0, we \nobtain a proof that 0 = 0. Now all that remains to be\nproved is 1 = 1. This is easily proved in the same way.\nWe apply the and introduction rule to the proofs of\nthese two lemmas, and thereby obtain a proof that \n0 = 0 ∧ 1 = 1. \n-/\n\n#check and.intro\n#check @and.intro\n\n/-\nUniversal generalizations (∀ propositions)\n-/\n\ntheorem th_and : ∀ {a b : Prop}, a → b → a ∧ b :=\nλ a b, \n    λ pf_a pf_b,\n        and.intro pf_a pf_b\n\n#check th_and p1 p2     -- P1 and P2 are implicit args\n\n/-\nIn English!\n-/\n\n/-\nIMPLICATION -- 2019.11.07.Lean\n-/\n\n/-\nIf we have a proof that nifty was a cat ∧\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 → \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\n/-\nLean provides exactly such this polymorphic\nlogical and connective. It's called \"and\" has\n∧ 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 ∧ 0 = 0 := \n    and.intro tom_proof (eq.refl 0)\n\n\nexample : was_a_cat tom ∧ 0 = 0 := \nbegin\n    apply and.intro tom_proof (eq.refl 0),\nend\n\nexample : was_a_cat tom ∧ 0 = 0 := \nbegin\n    apply and.intro tom_proof, -- arg as subgoal\n    exact (eq.refl 0)\nend\n\nexample : was_a_cat tom ∧ 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.\n\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 ∧ Q,\nfor example, then by applying one of the two\n\"and elimination\" axioms (rules of natural\ndeduction) to the proof of P ∧ Q, one can\nobtain either a proof of P, or a proof of Q. \n\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.\n\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.\n\nTheorem: For all propositions, P and Q,\n(P ∧ Q) → P. \n\nProof. Suppose that P and Q are arbitrary\nbut specific propositions. What remains to\nprove is that (P ∧ Q) → P. To prove this,\nassume we have a proof of P ∧ Q. Applying\nthe natural deduction principle of and \nelimination (left) yields of proof of P.\nQED. \n\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 : ∀ (P Q : Prop), P ∧ Q → P :=\n    λ P Q,\n        λ h, \n            and.elim_left h\n\ndef pf1' : ∀ (P Q : Prop), P ∧ Q → P :=\n    λ X Y,\n        λ 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 ∀ (P Q : Prop), P ∧ Q → P. \n\nWe use ∀ (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 ∧ Q → P. \n\nWe thus have the overall proposition: for \n*any* propositions, P and Q, if P ∧ Q (is\ntrue, has a proof) then P (is true, has a\nproof), i.e., P ∧ Q → P. In curt English: \n\"If P ∧ Q then P.\"\n\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 ∧ Q. \n\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.\n\nWe wrote the formal proof of ∀ (P Q : Prop), \nP ∧ Q → 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.\n\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 ∧ 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 : ∀ (P Q : Prop), P ∧ Q → P :=\nbegin\n    assume (X Y : Prop),    \n    assume (h : X ∧ Y),\n    exact and.elim_left h,\nend\n\n-- proof script, args already assumed\ndef pf4 (P Q : Prop) (h : P ∧ Q) : P :=\nbegin -- look: arguments are assumptions\n    exact and.elim_left h,\nend\n\n-- using cases notation\ndef pf5 : ∀ (P Q : Prop), P ∧ Q → P\n| P Q h := and.elim_left h\n\n/-\nFalse Elimination: ∀ (P : Prop), false → 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. \n\nA clear example involves the proof that\n\"false implies (the truth of) anything\".\nFormally: ∀ (P : Prop), false → 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 → 0 = 1)\neven though one can never produce a proof\nof false. The truth of (false → 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 → 0 = 1 :=\n    λ h, false.elim h\n\ntheorem false_elim_example' (h : false) : 0 = 1 :=\n    false.elim h\n\nexample : false → 0 = 1 := λ h, false.elim h", "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.11.05.Prop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7619008949146633}}
{"text": "/-\nCopyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alexander Bentkamp, Sébastien Gouëzel, Eric Wieser\n-/\nimport algebra.order.smul\nimport data.complex.basic\nimport data.fin.vec_notation\nimport field_theory.tower\n\n/-!\n# Complex number as a vector space over `ℝ`\n\nThis file contains the following instances:\n* Any `•`-structure (`has_scalar`, `mul_action`, `distrib_mul_action`, `module`, `algebra`) on\n  `ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ`\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 `ℝ`-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 `ℝ` in `ℂ`, and the complex conjugate):\n\n* `complex.re_lm` (`ℝ`-linear map);\n* `complex.im_lm` (`ℝ`-linear map);\n* `complex.of_real_am` (`ℝ`-algebra (homo)morphism);\n* `complex.conj_ae` (`ℝ`-algebra equivalence).\n\nIt also provides a universal property of the complex numbers `complex.lift`, which constructs a\n`ℂ →ₐ[ℝ] A` into any `ℝ`-algebra `A` given a square root of `-1`.\n\n-/\n\nnamespace complex\n\nopen_locale complex_conjugate\n\nvariables {R : Type*} {S : Type*}\n\nsection\n\nvariables [has_scalar R ℝ]\n\n/- The useless `0` multiplication in `smul` is to make sure that\n`restrict_scalars.module ℝ ℂ ℂ = complex.module` definitionally. -/\ninstance : has_scalar R ℂ :=\n{ smul := λ r x, ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩ }\n\nlemma smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(•)]\nlemma smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(•)]\n\n@[simp] lemma real_smul {x : ℝ} {z : ℂ} : x • z = x * z := rfl\n\nend\n\ninstance [has_scalar R ℝ] [has_scalar S ℝ] [smul_comm_class R S ℝ] : smul_comm_class R S ℂ :=\n{ smul_comm := λ r s x, by ext; simp [smul_re, smul_im, smul_comm] }\n\ninstance [has_scalar R S] [has_scalar R ℝ] [has_scalar S ℝ] [is_scalar_tower R S ℝ] :\n  is_scalar_tower R S ℂ :=\n{ smul_assoc := λ r s x, by ext; simp [smul_re, smul_im, smul_assoc] }\n\ninstance [monoid R] [mul_action R ℝ] : mul_action R ℂ :=\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 [semiring R] [distrib_mul_action R ℝ] : distrib_mul_action R ℂ :=\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] [module R ℝ] : module R ℂ :=\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 [comm_semiring R] [algebra R ℝ] : algebra R ℂ :=\n{ smul := (•),\n  smul_def' := λ r x, by ext; simp [smul_re, smul_im, algebra.smul_def],\n  commutes' := λ r ⟨xr, xi⟩, by ext; simp [smul_re, smul_im, algebra.commutes],\n  ..complex.of_real.comp (algebra_map R ℝ) }\n\n@[simp] lemma coe_algebra_map : (algebra_map ℝ ℂ : ℝ → ℂ) = coe := rfl\n\nsection\nvariables {A : Type*} [semiring A] [algebra ℝ 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] lemma _root_.alg_hom.map_coe_real_complex (f : ℂ →ₐ[ℝ] A) (x : ℝ) :\n  f x = algebra_map ℝ A x :=\nf.commutes x\n\n/-- Two `ℝ`-algebra homomorphisms from ℂ are equal if they agree on `complex.I`. -/\n@[ext]\nlemma alg_hom_ext ⦃f g : ℂ →ₐ[ℝ] A⦄ (h : f I = g I) : f = g :=\nbegin\n  ext ⟨x, y⟩,\n  simp only [mk_eq_add_mul_I, alg_hom.map_add, alg_hom.map_coe_real_complex, alg_hom.map_mul, h]\nend\n\nend\n\nsection\nopen_locale complex_order\n\nprotected lemma ordered_smul : ordered_smul ℝ ℂ :=\nordered_smul.mk' $ λ a b r hab hr, ⟨by simp [hr, hab.1.le], by simp [hab.2]⟩\n\nlocalized \"attribute [instance] complex.ordered_smul\" in complex_order\n\nend\n\nopen submodule finite_dimensional\n\n/-- `ℂ` has a basis over `ℝ` given by `1` and `I`. -/\nnoncomputable def basis_one_I : basis (fin 2) ℝ ℂ :=\nbasis.of_equiv_fun\n{ to_fun := λ z, ![z.re, z.im],\n  inv_fun := λ c, c 0 + c 1 • I,\n  left_inv := λ z, by simp,\n  right_inv := λ c, by { ext i, fin_cases i; simp },\n  map_add' := λ z z', by simp,\n  map_smul' := λ c z, by simp }\n\n@[simp] lemma coe_basis_one_I_repr (z : ℂ) : ⇑(basis_one_I.repr z) = ![z.re, z.im] := rfl\n\n@[simp] lemma coe_basis_one_I : ⇑basis_one_I = ![1, I] :=\nfunext $ λ i, basis.apply_eq_iff.mpr $ finsupp.ext $ λ j,\nby fin_cases i; fin_cases j;\n    simp only [coe_basis_one_I_repr, finsupp.single_eq_same, finsupp.single_eq_of_ne,\n              matrix.cons_val_zero, matrix.cons_val_one, matrix.head_cons,\n              nat.one_ne_zero, fin.one_eq_zero_iff, fin.zero_eq_one_iff, ne.def, not_false_iff,\n              one_re, one_im, I_re, I_im]\n\ninstance : finite_dimensional ℝ ℂ := of_fintype_basis basis_one_I\n\n@[simp] lemma finrank_real_complex : finite_dimensional.finrank ℝ ℂ = 2 :=\nby rw [finrank_eq_card_basis basis_one_I, fintype.card_fin]\n\n@[simp] lemma dim_real_complex : module.rank ℝ ℂ = 2 :=\nby simp [← finrank_eq_dim, finrank_real_complex]\n\nlemma {u} dim_real_complex' : cardinal.lift.{u} (module.rank ℝ ℂ) = 2 :=\nby simp [← finrank_eq_dim, finrank_real_complex, bit0]\n\n/-- `fact` version of the dimension of `ℂ` over `ℝ`, locally useful in the definition of the\ncircle. -/\nlemma finrank_real_complex_fact : fact (finrank ℝ ℂ = 2) := ⟨finrank_real_complex⟩\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 ℂ E] : module ℝ E :=\nrestrict_scalars.module ℝ ℂ E\n\ninstance module.real_complex_tower (E : Type*) [add_comm_group E] [module ℂ E] :\n  is_scalar_tower ℝ ℂ E :=\nrestrict_scalars.is_scalar_tower ℝ ℂ E\n\n@[simp, norm_cast] lemma complex.coe_smul {E : Type*} [add_comm_group E] [module ℂ E]\n  (x : ℝ) (y : E) :\n  (x : ℂ) • y = x • y :=\nrfl\n\n@[priority 100]\ninstance finite_dimensional.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E]\n  [finite_dimensional ℂ E] : finite_dimensional ℝ E :=\nfinite_dimensional.trans ℝ ℂ E\n\nlemma dim_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] :\n  module.rank ℝ E = 2 * module.rank ℂ E :=\ncardinal.lift_inj.1 $\n  by { rw [← dim_mul_dim' ℝ ℂ E, complex.dim_real_complex], simp [bit0] }\n\nlemma finrank_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] :\n  finite_dimensional.finrank ℝ E = 2 * finite_dimensional.finrank ℂ E :=\nby rw [← finite_dimensional.finrank_mul_finrank ℝ ℂ E, complex.finrank_real_complex]\n\nnamespace complex\n\nopen_locale complex_conjugate\n\n/-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/\ndef re_lm : ℂ →ₗ[ℝ] ℝ :=\n{ to_fun := λx, x.re,\n  map_add' := add_re,\n  map_smul' := by simp, }\n\n@[simp] lemma re_lm_coe : ⇑re_lm = re := rfl\n\n/-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/\ndef im_lm : ℂ →ₗ[ℝ] ℝ :=\n{ to_fun := λx, x.im,\n  map_add' := add_im,\n  map_smul' := by simp, }\n\n@[simp] lemma im_lm_coe : ⇑im_lm = im := rfl\n\n/-- `ℝ`-algebra morphism version of the canonical embedding of `ℝ` in `ℂ`. -/\ndef of_real_am : ℝ →ₐ[ℝ] ℂ := algebra.of_id ℝ ℂ\n\n@[simp] lemma of_real_am_coe : ⇑of_real_am = coe := rfl\n\n/-- `ℝ`-algebra isomorphism version of the complex conjugation function from `ℂ` to `ℂ` -/\ndef conj_ae : ℂ ≃ₐ[ℝ] ℂ :=\n{ inv_fun := conj,\n  left_inv := star_star,\n  right_inv := star_star,\n  commutes' := conj_of_real,\n  .. conj }\n\n@[simp] lemma conj_ae_coe : ⇑conj_ae = conj := rfl\n\nsection lift\n\nvariables {A : Type*} [ring A] [algebra ℝ A]\n\n/-- There is an alg_hom from `ℂ` to any `ℝ`-algebra with an element that squares to `-1`.\n\nSee `complex.lift` for this as an equiv. -/\ndef lift_aux (I' : A) (hf : I' * I' = -1) : ℂ →ₐ[ℝ] A :=\nalg_hom.of_linear_map\n  ((algebra.of_id ℝ A).to_linear_map.comp re_lm + (linear_map.to_span_singleton _ _ I').comp im_lm)\n  (show algebra_map ℝ A 1 + (0 : ℝ) • I' = 1,\n    by rw [ring_hom.map_one, zero_smul, add_zero])\n  (λ ⟨x₁, y₁⟩ ⟨x₂, y₂⟩, show algebra_map ℝ A (x₁ * x₂ - y₁ * y₂) + (x₁ * y₂ + y₁ * x₂) • I'\n                          = (algebra_map ℝ A x₁ + y₁ • I') * (algebra_map ℝ A x₂ + y₂ • I'),\n    begin\n      rw [add_mul, mul_add, mul_add, add_comm _ (y₁ • I' * y₂ • I'), add_add_add_comm],\n      congr' 1, -- equate \"real\" and \"imaginary\" parts\n      { rw [smul_mul_smul, hf, smul_neg, ←algebra.algebra_map_eq_smul_one, ←sub_eq_add_neg,\n          ←ring_hom.map_mul, ←ring_hom.map_sub], },\n      { rw [algebra.smul_def, algebra.smul_def, algebra.smul_def, ←algebra.right_comm _ x₂,\n          ←mul_assoc, ←add_mul, ←ring_hom.map_mul, ←ring_hom.map_mul, ←ring_hom.map_add] }\n    end)\n\n@[simp]\nlemma lift_aux_apply (I' : A) (hI') (z : ℂ) :\n lift_aux I' hI' z = algebra_map ℝ A z.re + z.im • I' := rfl\n\nlemma lift_aux_apply_I (I' : A) (hI') : lift_aux I' hI' I = I' := by simp\n\n/-- A universal property of the complex numbers, providing a unique `ℂ →ₐ[ℝ] 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 {simp_rhs := tt}]\ndef lift : {I' : A // I' * I' = -1} ≃ (ℂ →ₐ[ℝ] A) :=\n{ to_fun := λ I', lift_aux I' I'.prop,\n  inv_fun := λ F, ⟨F I, by rw [←F.map_mul, I_mul_I, alg_hom.map_neg, alg_hom.map_one]⟩,\n  left_inv := λ I', subtype.ext $ lift_aux_apply_I I' I'.prop,\n  right_inv := λ F, alg_hom_ext $ lift_aux_apply_I _ _, }\n\n/- When applied to `complex.I` itself, `lift` is the identity. -/\n@[simp]\nlemma lift_aux_I : lift_aux I I_mul_I = alg_hom.id ℝ ℂ :=\nalg_hom_ext $ lift_aux_apply_I _ _\n\n/- When applied to `-complex.I`, `lift` is conjugation, `conj`. -/\n@[simp]\n\n\nend lift\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/data/complex/module.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7619008779687133}}
{"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\n! This file was ported from Lean 3 source module combinatorics.derangements.exponential\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.Exponential\nimport Mathbin.Combinatorics.Derangements.Finite\nimport Mathbin.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-/\n\n\nopen Filter\n\nopen BigOperators\n\nopen Topology\n\ntheorem numDerangements_tendsto_inv_e :\n    Tendsto (fun n => (numDerangements n : ℝ) / n.factorial) atTop (𝓝 (Real.exp (-1))) :=\n  by\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 ≤ n always\n  let s : ℕ → ℝ := fun n => ∑ k in Finset.range n, (-1 : ℝ) ^ k / k.factorial\n  suffices ∀ n : ℕ, (numDerangements n : ℝ) / n.factorial = s (n + 1)\n    by\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 HasSum.tendsto_sum_nat\n    -- there's no specific lemma for ℝ that ∑ 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_ℝ]\n    exact exp_series_div_hasSum_exp ℝ (-1 : ℝ)\n  intro n\n  rw [← Int.cast_ofNat, numDerangements_sum]\n  push_cast\n  rw [Finset.sum_div]\n  -- get down to individual terms\n  refine' Finset.sum_congr (refl _) _\n  intro k hk\n  have h_le : k ≤ n := finset.mem_range_succ_iff.mp hk\n  rw [Nat.ascFactorial_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\n#align num_derangements_tendsto_inv_e numDerangements_tendsto_inv_e\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/Derangements/Exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.7618808151852026}}
{"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-/\nimport algebra.module.pid\nimport data.zmod.quotient\n\n/-!\n# Structure of finite(ly generated) abelian groups\n\n* `add_comm_group.equiv_free_prod_direct_sum_zmod` : Any finitely generated abelian group is the\n  product of a power of `ℤ` and a direct sum of some `zmod (p i ^ e i)` for some prime powers\n  `p i ^ e i`.\n* `add_comm_group.equiv_direct_sum_zmod_of_fintype` : Any finite abelian group is a direct sum of\n  some `zmod (p i ^ e i)` for some prime powers `p i ^ e i`.\n\n-/\n\nopen_locale direct_sum\n\nuniverse u\n\nnamespace module\n\nvariables (M : Type u)\n\nlemma finite_of_fg_torsion [add_comm_group M] [module ℤ M] [module.finite ℤ M]\n  (hM : module.is_torsion ℤ M) : _root_.finite M :=\nbegin\n  rcases module.equiv_direct_sum_of_is_torsion hM with ⟨ι, _, p, h, e, ⟨l⟩⟩,\n  haveI : ∀ i : ι, ne_zero (p i ^ e i).nat_abs :=\n  λ i, ⟨int.nat_abs_ne_zero_of_ne_zero $ pow_ne_zero (e i) (h i).ne_zero⟩,\n  haveI : ∀ i : ι, _root_.finite $ ℤ ⧸ submodule.span ℤ {p i ^ e i} :=\n  λ i, finite.of_equiv _ (p i ^ e i).quotient_span_equiv_zmod.symm.to_equiv,\n  haveI : _root_.finite ⨁ i, ℤ ⧸ (submodule.span ℤ {p i ^ e i} : submodule ℤ ℤ) :=\n  finite.of_equiv _ dfinsupp.equiv_fun_on_fintype.symm,\n  exact finite.of_equiv _ l.symm.to_equiv\nend\n\nend module\n\nvariables (G : Type u)\n\nnamespace add_comm_group\n\nvariable [add_comm_group G]\n\n/-- **Structure theorem of finitely generated abelian groups** : Any finitely generated abelian\ngroup is the product of a power of `ℤ` and a direct sum of some `zmod (p i ^ e i)` for some\nprime powers `p i ^ e i`. -/\ntheorem equiv_free_prod_direct_sum_zmod [hG : add_group.fg G] :\n  ∃ (n : ℕ) (ι : Type) [fintype ι] (p : ι → ℕ) [∀ i, nat.prime $ p i] (e : ι → ℕ),\n  nonempty $ G ≃+ (fin n →₀ ℤ) × ⨁ (i : ι), zmod (p i ^ e i) :=\nbegin\n  obtain ⟨n, ι, fι, p, hp, e, ⟨f⟩⟩ :=\n    @module.equiv_free_prod_direct_sum _ _ _ _ _ _ _ (module.finite.iff_add_group_fg.mpr hG),\n  refine ⟨n, ι, fι, λ i, (p i).nat_abs, λ i, _, e, ⟨_⟩⟩,\n  { rw [← int.prime_iff_nat_abs_prime, ← gcd_monoid.irreducible_iff_prime], exact hp i },\n  exact f.to_add_equiv.trans ((add_equiv.refl _).prod_congr $ dfinsupp.map_range.add_equiv $\n    λ i, ((int.quotient_span_equiv_zmod _).trans $\n      zmod.ring_equiv_congr $ (p i).nat_abs_pow _).to_add_equiv)\nend\n\n/-- **Structure theorem of finite abelian groups** : Any finite abelian group is a direct sum of\nsome `zmod (p i ^ e i)` for some prime powers `p i ^ e i`. -/\ntheorem equiv_direct_sum_zmod_of_fintype [finite G] :\n  ∃ (ι : Type) [fintype ι] (p : ι → ℕ) [∀ i, nat.prime $ p i] (e : ι → ℕ),\n  nonempty $ G ≃+ ⨁ (i : ι), zmod (p i ^ e i) :=\nbegin\n  casesI nonempty_fintype G,\n  obtain ⟨n, ι, fι, p, hp, e, ⟨f⟩⟩ := equiv_free_prod_direct_sum_zmod G,\n  cases n,\n  { exact ⟨ι, fι, p, hp, e, ⟨f.trans add_equiv.unique_prod⟩⟩ },\n  { haveI := @fintype.prod_left _ _ _ (fintype.of_equiv G f.to_equiv) _,\n    exact (fintype.of_surjective (λ f : fin n.succ →₀ ℤ, f 0) $\n      λ a, ⟨finsupp.single 0 a, finsupp.single_eq_same⟩).false.elim }\nend\n\nlemma finite_of_fg_torsion [hG' : add_group.fg G] (hG : add_monoid.is_torsion G) : finite G :=\n@module.finite_of_fg_torsion _ _ _ (module.finite.iff_add_group_fg.mpr hG') $\n  add_monoid.is_torsion_iff_is_torsion_int.mp hG\n\nend add_comm_group\n\nnamespace comm_group\n\nlemma finite_of_fg_torsion [comm_group G] [group.fg G] (hG : monoid.is_torsion G) : finite G :=\n@finite.of_equiv _ _ (add_comm_group.finite_of_fg_torsion (additive G) hG) multiplicative.of_add\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/finite_abelian.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.761796371170694}}
{"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.cyclotomic.primitive_roots\nimport field_theory.finite.trace\n\n/-!\n# Additive characters of finite rings and fields\n\nLet `R` be a finite commutative ring. An *additive character* of `R` with values\nin another commutative ring `R'` is simply a morphism from the additive group\nof `R` into the multiplicative monoid of `R'`.\n\nThe additive characters on `R` with values in `R'` form a commutative group.\n\nWe use the namespace `add_char`.\n\n## Main definitions and results\n\nWe define `mul_shift ψ a`, where `ψ : add_char R R'` and `a : R`, to be the\ncharacter defined by `x ↦ ψ (a * x)`. An additive character `ψ` is *primitive*\nif `mul_shift ψ a` is trivial only when `a = 0`.\n\nWe show that when `ψ` is primitive, then the map `a ↦ mul_shift ψ a` is injective\n(`add_char.to_mul_shift_inj_of_is_primitive`) and that `ψ` is primitive when `R` is a field\nand `ψ` is nontrivial (`add_char.is_nontrivial.is_primitive`).\n\nWe also show that there are primitive additive characters on `R` (with suitable\ntarget `R'`) when `R` is a field or `R = zmod n` (`add_char.primitive_char_finite_field`\nand `add_char.primitive_zmod_char`).\n\nFinally, we show that the sum of all character values is zero when the character\nis nontrivial (and the target is a domain); see `add_char.sum_eq_zero_of_is_nontrivial`.\n\n## Tags\n\nadditive character\n-/\n\nuniverses u v\n\n/-!\n### Definitions related to and results on additive characters\n-/\n\nsection add_char_def\n\n-- The domain of our additive characters\nvariables (R : Type u) [add_monoid R]\n-- The target\nvariables (R' : Type v) [comm_monoid R']\n\n/-- Define `add_char R R'` as `(multiplicative R) →* R'`.\nThe definition works for an additive monoid `R` and a monoid `R'`,\nbut we will restrict to the case that both are commutative rings below.\nWe assume right away that `R'` is commutative, so that `add_char R R'` carries\na structure of commutative monoid.\nThe trivial additive character (sending everything to `1`) is `(1 : add_char R R').` -/\n@[derive [comm_monoid, inhabited]]\ndef add_char : Type (max u v) := (multiplicative R) →* R'\n\nend add_char_def\n\nnamespace add_char\n\nsection coe_to_fun\n\nvariables {R : Type u} [add_monoid R] {R' : Type v} [comm_monoid R']\n\n/-- Interpret an additive character as a monoid homomorphism. -/\ndef to_monoid_hom : (add_char R R') → (multiplicative R →* R') := id\n\nopen multiplicative\n\n/-- Define coercion to a function so that it includes the move from `R` to `multiplicative R`.\nAfter we have proved the API lemmas below, we don't need to worry about writing `of_add a`\nwhen we want to apply an additive character. -/\ninstance has_coe_to_fun : has_coe_to_fun (add_char R R') (λ x, R → R') :=\n{ coe := λ ψ x, ψ.to_monoid_hom (of_add x) }\n\nlemma coe_to_fun_apply (ψ : add_char R R') (a : R) : ψ a = ψ.to_monoid_hom (of_add a) := rfl\n\ninstance monoid_hom_class : monoid_hom_class (add_char R R') (multiplicative R) R' :=\nmonoid_hom.monoid_hom_class\n\n/-- An additive character maps `0` to `1`. -/\n@[simp]\nlemma map_zero_one (ψ : add_char R R') : ψ 0 = 1 :=\nby rw [coe_to_fun_apply, of_add_zero, map_one]\n\n/-- An additive character maps sums to products. -/\n@[simp]\nlemma map_add_mul (ψ : add_char R R') (x y : R) : ψ (x + y) = ψ x * ψ y :=\nby rw [coe_to_fun_apply, coe_to_fun_apply _ x, coe_to_fun_apply _ y, of_add_add, map_mul]\n\n/-- An additive character maps multiples by natural numbers to powers. -/\n@[simp]\nlemma map_nsmul_pow (ψ : add_char R R') (n : ℕ) (x : R) : ψ (n • x) = (ψ x) ^ n :=\nby rw [coe_to_fun_apply, coe_to_fun_apply _ x, of_add_nsmul, map_pow]\n\nend coe_to_fun\n\nsection group_structure\n\nopen multiplicative\n\nvariables {R : Type u} [add_comm_group R] {R' : Type v} [comm_monoid R']\n\n/-- An additive character on a commutative additive group has an inverse.\n\nNote that this is a different inverse to the one provided by `monoid_hom.has_inv`,\nas it acts on the domain instead of the codomain. -/\ninstance has_inv : has_inv (add_char R R') := ⟨λ ψ, ψ.comp inv_monoid_hom⟩\n\nlemma inv_apply (ψ : add_char R R') (x : R) : ψ⁻¹ x = ψ (-x) := rfl\n\n/-- An additive character maps multiples by integers to powers. -/\n@[simp]\nlemma map_zsmul_zpow {R' : Type v} [comm_group R'] (ψ : add_char R R') (n : ℤ) (x : R) :\n  ψ (n • x) = (ψ x) ^ n :=\nby rw [coe_to_fun_apply, coe_to_fun_apply _ x, of_add_zsmul, map_zpow]\n\n/-- The additive characters on a commutative additive group form a commutative group. -/\ninstance comm_group : comm_group (add_char R R') :=\n{ inv := has_inv.inv,\n  mul_left_inv :=\n  λ ψ, by { ext, rw [monoid_hom.mul_apply, monoid_hom.one_apply, inv_apply, ← map_add_mul,\n                     add_left_neg, map_zero_one], },\n  ..monoid_hom.comm_monoid }\n\nend group_structure\n\nsection additive\n\n-- The domain and target of our additive characters. Now we restrict to rings on both sides.\nvariables {R : Type u} [comm_ring R] {R' : Type v} [comm_ring R']\n\n/-- An additive character is *nontrivial* if it takes a value `≠ 1`. -/\ndef is_nontrivial (ψ : add_char R R') : Prop := ∃ (a : R), ψ a ≠ 1\n\n/-- An additive character is nontrivial iff it is not the trivial character. -/\nlemma is_nontrivial_iff_ne_trivial (ψ : add_char R R') : is_nontrivial ψ ↔ ψ ≠ 1 :=\nbegin\n  refine not_forall.symm.trans (iff.not _),\n  rw fun_like.ext_iff,\n  refl,\nend\n\n/-- Define the multiplicative shift of an additive character.\nThis satisfies `mul_shift ψ a x = ψ (a * x)`. -/\ndef mul_shift (ψ : add_char R R') (a : R) : add_char R R' :=\nψ.comp (add_monoid_hom.mul_left a).to_multiplicative\n\n@[simp] lemma mul_shift_apply {ψ : add_char R R'} {a : R} {x : R} : mul_shift ψ a x = ψ (a * x) :=\nrfl\n\n/-- `ψ⁻¹ = mul_shift ψ (-1))`. -/\nlemma inv_mul_shift (ψ : add_char R R') : ψ⁻¹ = mul_shift ψ (-1) :=\nbegin\n  ext,\n  rw [inv_apply, mul_shift_apply, neg_mul, one_mul],\nend\n\n/-- If `n` is a natural number, then `mul_shift ψ n x = (ψ x) ^ n`. -/\nlemma mul_shift_spec' (ψ : add_char R R') (n : ℕ) (x : R) : mul_shift ψ n x = (ψ x) ^ n :=\nby rw [mul_shift_apply, ← nsmul_eq_mul, map_nsmul_pow]\n\n/-- If `n` is a natural number, then `ψ ^ n = mul_shift ψ n`. -/\nlemma pow_mul_shift (ψ : add_char R R') (n : ℕ) : ψ ^ n = mul_shift ψ n :=\nbegin\n  ext x,\n  rw [show (ψ ^ n) x = (ψ x) ^ n, from rfl, ← mul_shift_spec'],\nend\n\n/-- The product of `mul_shift ψ a` and `mul_shift ψ b` is `mul_shift ψ (a + b)`. -/\nlemma mul_shift_mul (ψ : add_char R R') (a b : R) :\n  mul_shift ψ a * mul_shift ψ b = mul_shift ψ (a + b) :=\nbegin\n  ext,\n  simp only [right_distrib, monoid_hom.mul_apply, mul_shift_apply, map_add_mul],\nend\n\n/-- `mul_shift ψ 0` is the trivial character. -/\n@[simp]\nlemma mul_shift_zero (ψ : add_char R R') : mul_shift ψ 0 = 1 :=\nbegin\n  ext,\n  simp only [mul_shift_apply, zero_mul, map_zero_one, monoid_hom.one_apply],\nend\n\n/-- An additive character is *primitive* iff all its multiplicative shifts by nonzero\nelements are nontrivial. -/\ndef is_primitive (ψ : add_char R R') : Prop :=\n∀ (a : R), a ≠ 0 → is_nontrivial (mul_shift ψ a)\n\n/-- The map associating to `a : R` the multiplicative shift of `ψ` by `a`\nis injective when `ψ` is primitive. -/\nlemma to_mul_shift_inj_of_is_primitive {ψ : add_char R R'} (hψ : is_primitive ψ) :\n  function.injective ψ.mul_shift :=\nbegin\n  intros a b h,\n  apply_fun (λ x, x * mul_shift ψ (-b)) at h,\n  simp only [mul_shift_mul, mul_shift_zero, add_right_neg] at h,\n  have h₂ := hψ (a + (-b)),\n  rw [h, is_nontrivial_iff_ne_trivial, ← sub_eq_add_neg, sub_ne_zero] at h₂,\n  exact not_not.mp (λ h, h₂ h rfl),\nend\n\n-- `add_comm_group.equiv_direct_sum_zmod_of_fintype`\n-- gives the structure theorem for finite abelian groups.\n-- This could be used to show that the map above is a bijection.\n-- We leave this for a later occasion.\n\n/-- When `R` is a field `F`, then a nontrivial additive character is primitive -/\nlemma is_nontrivial.is_primitive {F : Type u} [field F] {ψ : add_char F R'}\n  (hψ : is_nontrivial ψ) :\n  is_primitive ψ :=\nbegin\n  intros a ha,\n  cases hψ with x h,\n  use (a⁻¹ * x),\n  rwa [mul_shift_apply, mul_inv_cancel_left₀ ha],\nend\n\n/-- Structure for a primitive additive character on a finite ring `R` into a cyclotomic extension\nof a field `R'`. It records which cyclotomic extension it is, the character, and the\nfact that the character is primitive. -/\n@[nolint has_nonempty_instance] -- can't prove that they always exist\nstructure primitive_add_char (R : Type u) [comm_ring R] [fintype R] (R' : Type v) [field R'] :=\n(n : ℕ+)\n(char : add_char R (cyclotomic_field n R'))\n(prim : is_primitive char)\n\n/-!\n### Additive characters on `zmod n`\n-/\n\nvariables {C : Type v} [comm_ring C]\n\nsection zmod_char_def\n\nopen multiplicative -- so we can write simply `to_add`, which we need here again\n\n/-- We can define an additive character on `zmod n` when we have an `n`th root of unity `ζ : C`. -/\ndef zmod_char (n : ℕ+) {ζ : C} (hζ : ζ ^ ↑n = 1) : add_char (zmod n) C :=\n{ to_fun := λ (a : multiplicative (zmod n)), ζ ^ a.to_add.val,\n  map_one' := by simp only [to_add_one, zmod.val_zero, pow_zero],\n  map_mul' := λ x y, by rw [to_add_mul, ← pow_add, zmod.val_add (to_add x) (to_add y),\n                            ← pow_eq_pow_mod _ hζ] }\n\n/-- The additive character on `zmod n` defined using `ζ` sends `a` to `ζ^a`. -/\nlemma zmod_char_apply {n : ℕ+} {ζ : C} (hζ : ζ ^ ↑n = 1) (a : zmod n) :\n  zmod_char n hζ a = ζ ^ a.val := rfl\n\nlemma zmod_char_apply' {n : ℕ+} {ζ : C} (hζ : ζ ^ ↑n = 1) (a : ℕ) : zmod_char n hζ a = ζ ^ a :=\nby rw [pow_eq_pow_mod a hζ, zmod_char_apply, zmod.val_nat_cast a]\n\nend zmod_char_def\n\n/-- An additive character on `zmod n` is nontrivial iff it takes a value `≠ 1` on `1`. -/\nlemma zmod_char_is_nontrivial_iff (n : ℕ+) (ψ : add_char (zmod n) C) : is_nontrivial ψ ↔ ψ 1 ≠ 1 :=\nbegin\n  refine ⟨_, λ h, ⟨1, h⟩⟩,\n  contrapose!,\n  rintros h₁ ⟨a, ha⟩,\n  have ha₁ : a = a.val • 1,\n  { rw [nsmul_eq_mul, mul_one], exact (zmod.nat_cast_zmod_val a).symm },\n  rw [ha₁, map_nsmul_pow, h₁, one_pow] at ha,\n  exact ha rfl,\nend\n\n/-- A primitive additive character on `zmod n` takes the value `1` only at `0`. -/\nlemma is_primitive.zmod_char_eq_one_iff (n : ℕ+) {ψ : add_char (zmod n) C} (hψ : is_primitive ψ)\n  (a : zmod n) :\n  ψ a = 1 ↔ a = 0 :=\nbegin\n  refine ⟨λ h, not_imp_comm.mp (hψ a) _, λ ha, (by rw [ha, map_zero_one])⟩,\n  rw [zmod_char_is_nontrivial_iff n (mul_shift ψ a), mul_shift_apply, mul_one, h, not_not],\nend\n\n/-- The converse: if the additive character takes the value `1` only at `0`,\nthen it is primitive. -/\nlemma zmod_char_primitive_of_eq_one_only_at_zero (n : ℕ) (ψ : add_char (zmod n) C)\n  (hψ : ∀ a, ψ a = 1 → a = 0) :\n  is_primitive ψ :=\nbegin\n  refine λ a ha, (is_nontrivial_iff_ne_trivial _).mpr (λ hf, _),\n  have h : mul_shift ψ a 1 = (1 : add_char (zmod n) C) (1 : zmod n) :=\n    congr_fun (congr_arg coe_fn hf) 1,\n  rw [mul_shift_apply, mul_one, monoid_hom.one_apply] at h,\n  exact ha (hψ a h),\nend\n\n/-- The additive character on `zmod n` associated to a primitive `n`th root of unity\nis primitive -/\nlemma zmod_char_primitive_of_primitive_root (n : ℕ+) {ζ : C} (h : is_primitive_root ζ n) :\n  is_primitive (zmod_char n ((is_primitive_root.iff_def ζ n).mp h).left) :=\nbegin\n  apply zmod_char_primitive_of_eq_one_only_at_zero,\n  intros a ha,\n  rw [zmod_char_apply, ← pow_zero ζ] at ha,\n  exact (zmod.val_eq_zero a).mp (is_primitive_root.pow_inj h (zmod.val_lt a) n.pos ha),\nend\n\n/-- There is a primitive additive character on `zmod n` if the characteristic of the target\ndoes not divide `n` -/\nnoncomputable\ndef primitive_zmod_char (n : ℕ+) (F' : Type v) [field F'] (h : (n : F') ≠ 0) :\n  primitive_add_char (zmod n) F' :=\nbegin\n  haveI : ne_zero ((n : ℕ) : F') := ⟨h⟩,\n  exact\n{ n := n,\n  char := zmod_char n (is_cyclotomic_extension.zeta_pow n F' _),\n  prim := zmod_char_primitive_of_primitive_root n (is_cyclotomic_extension.zeta_spec n F' _) }\nend\n\n/-!\n### Existence of a primitive additive character on a finite field\n-/\n\n/-- There is a primitive additive character on the finite field `F` if the characteristic\nof the target is different from that of `F`.\nWe obtain it as the composition of the trace from `F` to `zmod p` with a primitive\nadditive character on `zmod p`, where `p` is the characteristic of `F`. -/\nnoncomputable\ndef primitive_char_finite_field (F F': Type*) [field F] [fintype F] [field F']\n  (h : ring_char F' ≠ ring_char F) :\n  primitive_add_char F F' :=\nbegin\n  let p := ring_char F,\n  haveI hp : fact p.prime := ⟨char_p.char_is_prime F _⟩,\n  let pp := p.to_pnat hp.1.pos,\n  have hp₂ : ¬ ring_char F' ∣ p :=\n  begin\n    cases char_p.char_is_prime_or_zero F' (ring_char F') with hq hq,\n    { exact mt (nat.prime.dvd_iff_eq hp.1 (nat.prime.ne_one hq)).mp h.symm, },\n    { rw [hq],\n      exact λ hf, nat.prime.ne_zero hp.1 (zero_dvd_iff.mp hf), },\n  end,\n  let ψ := primitive_zmod_char pp F' (ne_zero_iff.mp (ne_zero.of_not_dvd F' hp₂)),\n  let ψ' := ψ.char.comp (algebra.trace (zmod p) F).to_add_monoid_hom.to_multiplicative,\n  have hψ' : is_nontrivial ψ' :=\n  begin\n    obtain ⟨a, ha⟩ := finite_field.trace_to_zmod_nondegenerate F one_ne_zero,\n    rw one_mul at ha,\n    exact ⟨a, λ hf, ha $ (ψ.prim.zmod_char_eq_one_iff pp $ algebra.trace (zmod p) F a).mp hf⟩,\n  end,\n  exact\n{ n := ψ.n,\n  char := ψ',\n  prim := hψ'.is_primitive },\nend\n\n/-!\n### The sum of all character values\n-/\n\nopen_locale big_operators\n\nvariables [fintype R]\n\n/-- The sum over the values of a nontrivial additive character vanishes if the target ring\nis a domain. -/\nlemma sum_eq_zero_of_is_nontrivial [is_domain R'] {ψ : add_char R R'} (hψ : is_nontrivial ψ) :\n  ∑ a, ψ a = 0 :=\nbegin\n  rcases hψ with ⟨b, hb⟩,\n  have h₁ : ∑ (a : R), ψ (b + a) = ∑ (a : R), ψ a :=\n    fintype.sum_bijective _ (add_group.add_left_bijective b) _ _ (λ x, rfl),\n  simp_rw [map_add_mul] at h₁,\n  have h₂ : ∑ (a : R), ψ a = finset.univ.sum ⇑ψ := rfl,\n  rw [← finset.mul_sum, h₂] at h₁,\n  exact eq_zero_of_mul_eq_self_left hb h₁,\nend\n\n/-- The sum over the values of the trivial additive character is the cardinality of the source. -/\nlemma sum_eq_card_of_is_trivial {ψ : add_char R R'} (hψ : ¬ is_nontrivial ψ) :\n  ∑ a, ψ a = fintype.card R :=\nbegin\n  simp only [is_nontrivial] at hψ,\n  push_neg at hψ,\n  simp only [hψ, finset.sum_const, nat.smul_one_eq_coe],\n  refl,\nend\n\n/-- The sum over the values of `mul_shift ψ b` for `ψ` primitive is zero when `b ≠ 0`\nand `#R` otherwise. -/\nlemma sum_mul_shift [decidable_eq R] [is_domain R'] {ψ : add_char R R'} (b : R)\n  (hψ : is_primitive ψ) :\n  ∑ (x : R), ψ (x * b) = if b = 0 then fintype.card R else 0 :=\nbegin\n  split_ifs with h,\n  { -- case `b = 0`\n    simp only [h, mul_zero, map_zero_one, finset.sum_const, nat.smul_one_eq_coe],\n    refl, },\n  { -- case `b ≠ 0`\n    simp_rw mul_comm,\n    exact sum_eq_zero_of_is_nontrivial (hψ b h), },\nend\n\nend additive\n\nend add_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/number_theory/legendre_symbol/add_character.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7617878373655647}}
{"text": "namespace hidden        -- you can ignore this\n\n/-\n1a. Define a polymorphic tree type. A tree of objects of type α \nis either empty or it is a value of type α along with two \nsmaller trees of the same kind. You can call them left and right\nrespectively.\n-/\n\n/-\n1b. \nDefine a polymorphic function, is_empty, that takes a value of\ntype, tree α, and that returns Boolean tt if it is empty and ff \notherwise.\n-/\n\n/-\n1b. Define a polymorphic function, num_nodes, that takes a value \nof type, tree α, and that returns the number of nodes in the \ntree.\n-/\n\n\n/-\n2. A bit has one of two values. Imagine a type, let's call it \ntrit, with three values (e.g., true, false, and dont-know). How \nmany binary functions are there, taking two values of tihs type \nand returning a value of the same type?\n-/\n\n/-\n3. Define a function, sum_squares, that takes a natural number, \nn, as an argument, and that returns the sum of the squaress of \nall of the natural numbers from 0 to n, inclusive.\n-/\n\n/-\n4a. We represent a binary relation, R, on a set of  values of \nsome  type, α, as a predicate with two arguments. In Lean such a \npredicate is of type α → α → Prop. A property of such a relation \nis a predicate on a relation, and so is of type (α → α → Prop) → \nProp.\n\nHere is the definition of a property of binary relations called \nasymmetry. A relation is said to be asymmetric if whenever (x, y)\nis in the relation, (y, x) is not. For example, the less-than \nrelation on natural numbers is asymmetric.\n-/  \n\ndef asymmetric {α : Type} (R : α → α → Prop) : Prop :=\n    ∀ (x y : α), R x y → ¬ R y x\n\n/-\nSimilarly, a relation is said to be irreflexive if for all x,\n(x, x) is not in the relation. For example, an \"is-unequal-to\"\nrelation on the natural numbers would include (3, 4) because\n3 is unequal to 4, but it would not include (3, 3) because\n3 is not unqual to 3. Write a formal definition of irreflexive\nin the style of the definition of asymmetric above. Start the\nactual definition (after the :=) with ∀ (x : α).\n-/\n\ndef irreflexive {α : Type} (R : α → α → Prop) : Prop :=\n    ∀ (x : α), ¬ R x x\n\n/-\n4b. Prove that if a relation is asymmetric then it is \nirreflexive by completing the following proof.\n-/\n\ntheorem asy_imp_irr : \n    ∀ (α : Type) (F : α → α → Prop),\n        asymmetric F → irreflexive F :=\nbegin\nunfold asymmetric irreflexive,  -- expand defs\n_             \nend\n\n/-\n5. Prove the following. You may use a tactic script,\nas indicated here, or switch to another format for your\nproof. Whatever you are most comfortable with is fine.\n-/\n\nexample : \n    ∀ (P Q R : Prop), \n        (∀ (p : P), Q) → (∀ (q :Q), R) → (P ∨ Q) → R :=\nbegin\n_\nend \n\n/-\n6. Prove that every natural number, n, has a successor. \nFormalize this statement using universal and existential\nquantifiers: for every natural number n there exists a\nnatural number m such that m is the successor of n. Then\ncomplete the proof. Finish what we've started for you.\n-/\n\nexample : ∀ (n : ℕ), _ := _\n\n/-\n7. Consider a binary relation, squares, on the natural\nnumbers. A pair, (x, y), is in this relation if and only\nif y=x^2. Formalize this relation in Lean as a predicate,\nsquares, with two natural number arguments and one proof \nconstructor called intro. Then state and prove the simple\nproposition that the pair, (7, 49), is in this relation.\n-/\n\n-- Answer here\n\n\n/-\n8. This question asks you to model a little world.\nThe world has people in it (a type) and there is a\nbinary relation, parent_of, on people. What is means\nfor a pair (x, y) to be in this relation is that x \nis a parent of y.\n-/\n\naxiom Person : Type\naxiom ParentOf : Person → Person → Prop\n\n/-\nDefine a GrandParentOf relation, such that (x, y) is\nin this relation if and only if x is a grand parent of\ny. What this means, of course, is that there is some z\nsuch that x is the parent of z and z is the parent of y.\nDefine the GrandParentOf relation using an inductive \ntype definition in the usual way. It needs only one\nconstructor, which must enforce the condition that\ndefines what it means \"to be a grandparent of\".\n-/\n\n/-\n9. In simple English explain what it means for a binary\nrelation on a set to be\n\n* reflexive:\n* transitive: \n* symmetric:\n\nGive an example of an everyday mathematical relation \nother than equality that is transitive.\n\nIs the greater-than relation reflexive? Explain.\n\nIs it symmetric? Explain.\n-/\n\n\n/-\n10. Give a natural language proof, in your own words,\nshowing that the square root of two is irrational. You\nmay find the details of this proof easily by searching\nonline.\n-/\n\n/-\n11. Prove formally that 0 ≠ 1, then translate your\nformal proof, step by step, into an English language\nproof, citing the reasoning principles that you use.\nWhat fundamental proof strategy is centrally involved\nin this proof?\n-/\n\n/-\n12. Lean includes the law of the excluded middle in a\nclosed namespace called classical. The axiom goes\nby the name, classical.em. You may apply it to any\nproposition, P, to obtain a proof of P ∨ ¬ P. Use\nthe law of the excluded middle to show that proof\nby contradiction is valid, as long as you accept\nem as an axiom. Hint: We covered this in class.\n-/\n\n/-\n13. Let's define a natural number to be cool if it's\neither 2 or 5 or the sum or the product of two \ncool numbers. Formalize this definition in Lean\nand then state and prove the proposition that 35\nis cool.\n-/\n\nend hidden", "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/hw9_extra_credit_exam_prep.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711794579723, "lm_q2_score": 0.8962513627417532, "lm_q1q2_score": 0.761787827880423}}
{"text": "namespace hidden\n\nconstant and: Prop -> Prop -> Prop\nconstant or: Prop -> Prop -> Prop\nconstant not: Prop -> Prop\nconstant implies: Prop -> Prop -> Prop \n\nconstant Proof: Prop -> Type\n\nvariables p q r: Prop\n\nconstant and_comm: ∀ p q: Prop,\n  Proof (implies (and p q) (and q p))\n#check and_comm p q\n\nconstant modus_ponens: ∀ p q: Prop, Proof (implies p q) -> Proof p -> Proof q\nconstant implies_intro: ∀ p q: Prop, (Proof p -> Proof q) -> Proof (implies p q)\n\nend hidden\n\nnamespace hidden\nconstants p q: Prop \n\ntheorem t1: p -> q -> p := λ (hp: p) (hq: q), hp\n\ntheorem t1': p -> q -> p :=\n  assume hp: p,\n  assume hq: q,\n  hp\n\ntheorem t1'': p -> q -> p :=\n  assume hp: p,\n  assume hq: q,\n  show p, from hp\n\naxiom ap : p \n\ntheorem t2: q -> p := t1 ap\n\ntheorem t1''': ∀ {p q: Prop}, p -> q -> p :=\n  assume p q,\n  assume hp: p,\n  assume hq: q,\n  hp\nend hidden\n\ntheorem t1: ∀ (p q: Prop), p -> q -> p :=\n  assume p q,\n  assume hp: p,\n  assume hq: q,\n  hp\n\nvariables p q r s: Prop \n#check t1\n#check t1 p q\n#check t1 r s\n#check t1 (r -> s) (s -> r)\n\ntheorem t2 (h₁: q -> r) (h₂: p -> q): p -> r :=\n  assume h₃: p,\n  show r, from h₁ (h₂ h₃)\n\n#check t2\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/3-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7617492971019284}}
{"text": "import algebra.group\nimport group_theory.subgroup\n\nvariables {G: Type*} {H: set G} {a: G}\n\ntheorem Q_04a [hG: group G] [hH: is_subgroup H]:\n  is_subgroup ((λ h, a * h * a⁻¹) '' H) := {\n\n  inv_mem := λ g ⟨h, ⟨hH, ha⟩⟩, begin\n\n    -- inverse of aha⁻¹ is ah⁻¹a⁻¹ ...\n    have inv_g: g⁻¹ = a * h⁻¹ * a⁻¹,\n    from ha ▸ calc (a * h * a⁻¹)⁻¹\n    = (a⁻¹)⁻¹ * h⁻¹ * a⁻¹ : by rw [mul_inv_rev, mul_inv_rev, ←mul_assoc]\n... = a * h⁻¹ * a⁻¹       : by rw inv_inv,\n\n    -- ... and ah⁻¹a⁻¹ is in aHa⁻¹.\n    have t: a * h⁻¹ * a⁻¹ ∈ ((λ h, a * h * a⁻¹) '' H),\n    from ⟨h⁻¹, ⟨is_subgroup.inv_mem hH, rfl⟩⟩,\n\n    exact inv_g.symm ▸ t,\n  end,\n\n  -- the identity is in aHa⁻¹: 1 = a1a⁻¹.\n  one_mem := ⟨1, ⟨\n    hH.one_mem,\n    calc a * 1 * a⁻¹ = 1: by rw [mul_one, mul_right_inv a] ⟩⟩,\n\n  -- multiplication in aHa⁻¹ is closed because ah₁a⁻¹ * ah₂a⁻¹ = ah₁h₂a⁻¹.\n  mul_mem := λ g₁ g₂ ⟨h₁, ⟨hh₁, hg₁⟩⟩ ⟨h₂, ⟨hh₂, hg₂⟩⟩, ⟨h₁ * h₂, ⟨\n\n  is_submonoid.mul_mem hh₁ hh₂,\n\n  hg₁ ▸ hg₂ ▸ calc a * (h₁ * h₂) * a⁻¹\n    = a * h₁ * 1 * (h₂ * a⁻¹)         : by rw [←mul_assoc, mul_assoc, mul_one]\n... = a * h₁ * (a⁻¹ * a) * (h₂ * a⁻¹) : by rw mul_left_inv\n... = (a * h₁ * a⁻¹) * a * (h₂ * a⁻¹) : by rw ←(mul_assoc (a * h₁) a⁻¹ a)\n... = (a * h₁ * a⁻¹) * (a * h₂ * a⁻¹) : by rw [mul_assoc, mul_assoc a h₂ a⁻¹],\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_5/Q_04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.761749295004642}}
{"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 : ℕ) := 2 * n + 1\n\n#check @finset.sum\n\n-- finset.range n is the finite set {0,1,2,...,n-1}\ntheorem challenge05 (n : ℕ) : (finset.range n).sum (odd) = n ^ 2 :=\nbegin\n  induction n with n ih,\n  { refl },\n  { rw finset.sum_range_succ\n  , rw ih\n  , unfold odd\n  , rw nat.succ_eq_add_one\n  , ring }\nend\n\nend maths_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/challenge05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7616087817010263}}
{"text": "import data.nat.basic tactic.induction\n\n\n/-!\n# Sheet 1: Primes and induction.\n-/\n\n/-!\n## Question 1.\n\nIn each of the following cases, determine which integers `n` satisfy the stated\ncondition. Justify your answers.\n-/\n\nsection question_1\n\nvariables m n a : ℕ\n\nopen nat\n\n/-\nWe'll use the following results:\n`le_antisymm`,\n`le_of_dvd`,\n`pos_of_dvd_of_pos`.\n-/\n\nexample (h₁ : m ≤ n) (h₂ : n ≤ m) : m = n := le_antisymm h₁ h₂\n\nexample (h₁ : 0 < n) (h₂ : m ∣ n) : m ≤ n := le_of_dvd h₁ h₂\n\nexample (h₁ : m ∣ n) (h₂ : 0 < n) : 0 < m := pos_of_dvd_of_pos h₁ h₂\n\nlemma q1_i : n ∣ 1 ↔ n = 1 :=\nbegin\n  split, -- Split into proving `n ∣ 1 → n = 1` and `n = 1 → n ∣ 1`.\n  -- First task it to prove `n ∣ 1 → n = 1`.\n  { intro h, -- Assume `h : n ∣  1`. It suffices to prove `n = 1`.\n    apply le_antisymm, -- It suffices to prove `n ≤ 1` and `1 ≤ n`.\n    { -- Start by proving `n ≤ 1`.\n      apply le_of_dvd, -- it suffices to prove `0 < 1` and `n ∣ 1`.\n      { simp, },\n      { exact h }, },\n    { -- Now prove `1 ≤ n`.\n      apply pos_of_dvd_of_pos h,\n      simp, }, },\n  -- Second task is to prove `n = 1 → n ∣ 1`.\n  { intro h, rw h, },\nend\n\n/-\nThe `use` and `simp` and `trivial` tactics may help here.\nIt's more typical to write the following result as `1 ∣ n` rather than `1 ∣ n ↔ true`.\nWe've written the result this way so that we can `sorry` similar results in this question.\n-/\nlemma q1_ii : 1 ∣ n ↔ true :=\nbegin\n  split,\n  { intro h, sorry, },\n  { intro h,\n    dsimp [nat.has_dvd], -- By definition, we must show `∃ c, n = 1 * c`.\n    sorry, },\nend\n\n-- `simp at ...` might be helpful below (replacing `...` with an appropriate hypothesis).\nlemma q1_iii : 0 ∣ n ↔ n = 0 :=\nbegin\n  split,\n  { intro h, dsimp [nat.has_dvd] at h, -- By definition `h : ∃ c, n = 0 * c`.\n    cases h with c h, -- Destructing, we have `c : ℕ` and `h : n = 0 * c`.\n    sorry, },\n  { sorry, },\nend\n\nlemma q1_iv : n ∣ 0 ↔ sorry :=\nbegin\n  sorry,\nend\n\nlemma q1_v : n ∣ n ↔ sorry :=\nbegin\n  sorry\nend\n\n-- The `specialize` tactic may be helpful here.\nlemma q1_vi : (∀ a, a ∣ n) ↔ sorry :=\nbegin\n  sorry\nend\n\nend question_1\n\n-- add another comment", "meta": {"author": "gihanmarasingha", "repo": "mth1001_summer_2021", "sha": "fd168488a238c2e01800ebeeff2809adb3fa88b5", "save_path": "github-repos/lean/gihanmarasingha-mth1001_summer_2021", "path": "github-repos/lean/gihanmarasingha-mth1001_summer_2021/mth1001_summer_2021-fd168488a238c2e01800ebeeff2809adb3fa88b5/src/problem_sheets/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836382, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7615580309040655}}
{"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.group_action.basic\nimport tactic.group\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 : α` and a subset `s ⊆ α`, 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 : α` and a subset `s ⊆ α`, 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 `α` to `α/s` for a subgroup `s` of `α`, 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 ⧸ 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 {α : Type*}\n\n/-- The left coset `a * s` for an element `a : α` and a subset `s : set α` -/\n@[to_additive left_add_coset \"The left coset `a+s` for an element `a : α`\nand a subset `s : set α`\"]\ndef left_coset [has_mul α] (a : α) (s : set α) : set α := (λ x, a * x) '' s\n\n/-- The right coset `s * a` for an element `a : α` and a subset `s : set α` -/\n@[to_additive right_add_coset \"The right coset `s+a` for an element `a : α`\nand a subset `s : set α`\"]\ndef right_coset [has_mul α] (s : set α) (a : α) : set α := (λ 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 α]\n\n@[to_additive mem_left_add_coset]\nlemma mem_left_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a *l s :=\nmem_image_of_mem (λ b : α, a * b) hxS\n\n@[to_additive mem_right_add_coset]\nlemma mem_right_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ s *r a :=\nmem_image_of_mem (λ b : α, 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 α) (a b : α) := a *l s = b *l s\n\n@[to_additive left_add_coset_equivalence_rel]\nlemma left_coset_equivalence_rel (s : set α) : equivalence (left_coset_equivalence s) :=\nmk_equivalence (left_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ 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 α) (a b : α) := s *r a = s *r b\n\n@[to_additive right_add_coset_equivalence_rel]\nlemma right_coset_equivalence_rel (s : set α) : equivalence (right_coset_equivalence s) :=\nmk_equivalence (right_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans)\n\nend coset_mul\n\nsection coset_semigroup\nvariable [semigroup α]\n\n@[simp, to_additive left_add_coset_assoc] lemma left_coset_assoc (s : set α) (a b : α) :\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 α) (a b : α) :\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 α) (a b : α) : 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 α] (s : set α)\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 α] (s : submonoid α)\n\n@[to_additive mem_own_left_add_coset]\nlemma mem_own_left_coset (a : α) : a ∈ a *l s :=\nsuffices a * 1 ∈ a *l s, by simpa,\nmem_left_coset a (one_mem s : 1 ∈ s)\n\n@[to_additive mem_own_right_add_coset]\nlemma mem_own_right_coset (a : α) : a ∈ (s : set α) *r a :=\nsuffices 1 * a ∈ (s : set α) *r a, by simpa,\nmem_right_coset a (one_mem s : 1 ∈ s)\n\n@[to_additive mem_left_add_coset_left_add_coset]\nlemma mem_left_coset_left_coset {a : α} (ha : a *l s = s) : a ∈ s :=\nby rw [←set_like.mem_coe, ←ha]; 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 : α} (ha : (s : set α) *r a = s) : a ∈ s :=\nby rw [←set_like.mem_coe, ←ha]; exact mem_own_right_coset s a\n\nend coset_submonoid\n\nsection coset_group\nvariables [group α] {s : set α} {x : α}\n\n@[to_additive mem_left_add_coset_iff]\nlemma mem_left_coset_iff (a : α) : x ∈ a *l s ↔ a⁻¹ * x ∈ s :=\niff.intro\n  (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb])\n  (assume h, ⟨a⁻¹ * x, h, by simp⟩)\n\n@[to_additive mem_right_add_coset_iff]\nlemma mem_right_coset_iff (a : α) : x ∈ s *r a ↔ x * a⁻¹ ∈ s :=\niff.intro\n  (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb])\n  (assume h, ⟨x * a⁻¹, h, by simp⟩)\n\nend coset_group\n\nsection coset_subgroup\nopen subgroup\n\nvariables [group α] (s : subgroup α)\n\n@[to_additive left_add_coset_mem_left_add_coset]\nlemma left_coset_mem_left_coset {a : α} (ha : a ∈ s) : a *l s = s :=\nset.ext $ by simp [mem_left_coset_iff, mul_mem_cancel_left (s.inv_mem ha)]\n\n@[to_additive right_add_coset_mem_right_add_coset]\nlemma right_coset_mem_right_coset {a : α} (ha : a ∈ s) : (s : set α) *r a = s :=\nset.ext $ assume b, by simp [mem_right_coset_iff, mul_mem_cancel_right (s.inv_mem ha)]\n\n@[to_additive eq_add_cosets_of_normal]\ntheorem eq_cosets_of_normal (N : s.normal) (g : α) : 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 : ∀ g : α, g *l s = s *r g) : s.normal :=\n⟨assume a ha g, show g * a * g⁻¹ ∈ (s : set α),\n  by rw [← mem_right_coset_iff, ← h]; exact mem_left_coset g ha⟩\n\n@[to_additive normal_iff_eq_add_cosets]\ntheorem normal_iff_eq_cosets : s.normal ↔ ∀ g : α, g *l s = s *r g :=\n⟨@eq_cosets_of_normal _ _ s, normal_of_eq_cosets s⟩\n\n@[to_additive left_add_coset_eq_iff]\nlemma left_coset_eq_iff {x y : α} : left_coset x s = left_coset y s ↔ x⁻¹ * y ∈ 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 ←mul_inv_cancel_right x⁻¹ 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 : α} : right_coset ↑s x = right_coset s y ↔ y * x⁻¹ ∈ 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 ←inv_mul_cancel_left y x⁻¹, rw ←mul_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 α] (s : subgroup α)\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 α := mul_action.orbit_rel s.opposite α\n\nvariables {s}\n\n@[to_additive]\nlemma left_rel_apply {x y : α} : @setoid.r _ (left_rel s) x y ↔ (x⁻¹ * y ∈ s) :=\ncalc (∃ a : s.opposite, y * mul_opposite.unop a = x)\n    ↔ ∃ a : s, y * a = x : s.opposite_equiv.symm.exists_congr_left\n... ↔ ∃ a : s, x⁻¹ * y = a⁻¹ : by simp only [inv_mul_eq_iff_eq_mul, eq_mul_inv_iff_mul_eq]\n... ↔ x⁻¹ * y ∈ s : by simp [set_like.exists]\n\nvariables (s)\n\n@[to_additive]\nlemma left_rel_eq : @setoid.r _ (left_rel s) = λ x y, x⁻¹ * y ∈ s :=\nfunext₂ $ by { simp only [eq_iff_iff], apply left_rel_apply }\n\nlemma left_rel_r_eq_left_coset_equivalence :\n  @setoid.r _ (quotient_group.left_rel s) = left_coset_equivalence s :=\nby { ext, rw left_rel_eq, exact (left_coset_eq_iff s).symm }\n\n@[to_additive]\ninstance left_rel_decidable [decidable_pred (∈ s)] :\n  decidable_rel (left_rel s).r :=\nλ x y, by { rw left_rel_eq, exact ‹decidable_pred (∈ s)› _ }\n\n/-- `α ⧸ s` is the quotient type representing the left cosets of `s`.\n  If `s` is a normal subgroup, `α ⧸ s` is a group -/\n@[to_additive \"`α ⧸ s` is the quotient type representing the left cosets of `s`.  If `s` is a\nnormal subgroup, `α ⧸ s` is a group\"]\ninstance : has_quotient α (subgroup α) := ⟨λ s, quotient (left_rel s)⟩\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 α := mul_action.orbit_rel s α\n\nvariables {s}\n\n@[to_additive]\nlemma right_rel_apply {x y : α} : @setoid.r _ (right_rel s) x y ↔ (y * x⁻¹ ∈ s) :=\ncalc (∃ a : s, (a:α) * y = x)\n    ↔ ∃ a : s, y * x⁻¹ = a⁻¹ : by simp only [mul_inv_eq_iff_eq_mul, eq_inv_mul_iff_mul_eq]\n... ↔ y * x⁻¹ ∈ s : by simp [set_like.exists]\n\nvariables (s)\n\n@[to_additive]\nlemma right_rel_eq : @setoid.r _ (right_rel s) = λ x y, y * x⁻¹ ∈ s :=\nfunext₂ $ by { simp only [eq_iff_iff], apply right_rel_apply }\n\nlemma right_rel_r_eq_right_coset_equivalence :\n  @setoid.r _ (quotient_group.right_rel s) = right_coset_equivalence s :=\nby { ext, rw right_rel_eq, exact (right_coset_eq_iff s).symm }\n\n@[to_additive]\ninstance right_rel_decidable [decidable_pred (∈ s)] :\n  decidable_rel (right_rel s).r :=\nλ x y, by { rw right_rel_eq, exact ‹decidable_pred (∈ s)› _ }\n\n/-- Right cosets are in bijection with left cosets. -/\n@[to_additive \"Right cosets are in bijection with left cosets.\"]\ndef quotient_right_rel_equiv_quotient_left_rel : quotient (quotient_group.right_rel s) ≃ α ⧸ s :=\n{ to_fun := quotient.map' (λ g, g⁻¹) (λ a b, by { rw [left_rel_apply, right_rel_apply],\n      exact λ h, (congr_arg (∈ s) (by group)).mp (s.inv_mem h) }),\n  inv_fun := quotient.map' (λ g, g⁻¹) (λ a b, by { rw [left_rel_apply, right_rel_apply],\n      exact λ h, (congr_arg (∈ s) (by group)).mp (s.inv_mem h) }),\n  left_inv := λ g, quotient.induction_on' g (λ g, quotient.sound' (by\n  { simp only [inv_inv],\n    exact quotient.exact' rfl })),\n  right_inv := λ g, quotient.induction_on' g (λ g, quotient.sound' (by\n  { simp only [inv_inv],\n    exact quotient.exact' rfl })) }\n\n@[to_additive] instance fintype_quotient_right_rel [fintype (α ⧸ s)] :\n  fintype (quotient (quotient_group.right_rel s)) :=\nfintype.of_equiv (α ⧸ s) (quotient_group.quotient_right_rel_equiv_quotient_left_rel s).symm\n\n@[to_additive] lemma card_quotient_right_rel [fintype (α ⧸ s)] :\n  fintype.card (quotient (quotient_group.right_rel s)) = fintype.card (α ⧸ s) :=\nfintype.of_equiv_card (quotient_group.quotient_right_rel_equiv_quotient_left_rel s).symm\n\nend quotient_group\n\nnamespace quotient_group\n\nvariables [group α] {s : subgroup α}\n\n@[to_additive]\ninstance fintype [fintype α] (s : subgroup α) [decidable_rel (left_rel s).r] :\n  fintype (α ⧸ s) :=\nquotient.fintype (left_rel s)\n\n/-- The canonical map from a group `α` to the quotient `α ⧸ s`. -/\n@[to_additive \"The canonical map from an `add_group` `α` to the quotient `α ⧸ s`.\"]\nabbreviation mk (a : α) : α ⧸ s :=\nquotient.mk' a\n\n@[to_additive]\nlemma mk_surjective : function.surjective $ @mk _ _ s := quotient.surjective_quotient_mk'\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on {C : α ⧸ s → Prop} (x : α ⧸ s)\n  (H : ∀ z, C (quotient_group.mk z)) : C x :=\nquotient.induction_on' x H\n\n@[to_additive]\ninstance : has_coe_t α (α ⧸ s) := ⟨mk⟩ -- note [use has_coe_t]\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on' {C : α ⧸ s → Prop} (x : α ⧸ s)\n  (H : ∀ z : α, C z) : C x :=\nquotient.induction_on' x H\n\n@[simp, to_additive]\nlemma quotient_lift_on_coe {β} (f : α → β) (h) (x : α) :\n  quotient.lift_on' (x : α ⧸ s) f h = f x := rfl\n\n@[to_additive]\nlemma forall_coe {C : α ⧸ s → Prop} :\n  (∀ x : α ⧸ s, C x) ↔ ∀ x : α, C x :=\n⟨λ hx x, hx _, quot.ind⟩\n\n@[to_additive]\ninstance (s : subgroup α) : inhabited (α ⧸ s) :=\n⟨((1 : α) : α ⧸ s)⟩\n\n@[to_additive quotient_add_group.eq]\nprotected lemma eq {a b : α} : (a : α ⧸ s) = b ↔ a⁻¹ * b ∈ s :=\ncalc _ ↔ @setoid.r _ (left_rel s) a b : quotient.eq'\n... ↔ _ : by rw left_rel_apply\n\n@[to_additive quotient_add_group.eq']\nlemma eq' {a b : α} : (mk a : α ⧸ s) = mk b ↔ a⁻¹ * b ∈ s :=\nquotient_group.eq\n\n@[to_additive quotient_add_group.out_eq']\nlemma out_eq' (a : α ⧸ s) : mk a.out' = a :=\nquotient.out_eq' a\n\nvariables (s)\n\n/- It can be useful to write `obtain ⟨h, H⟩ := 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⁻¹ * (mk g).out'`. -/\n@[to_additive quotient_add_group.mk_out'_eq_mul]\nlemma mk_out'_eq_mul (g : α) : ∃ h : s, (mk g : α ⧸ s).out' = g * h :=\n⟨⟨g⁻¹ * (mk g).out', eq'.mp (mk g).out_eq'.symm⟩, by rw [set_like.coe_mk, mul_inv_cancel_left]⟩\n\nvariables {s}\n\n@[to_additive quotient_add_group.mk_mul_of_mem]\nlemma mk_mul_of_mem (g₁ g₂ : α) (hg₂ : g₂ ∈ s) : (mk (g₁ * g₂) : α ⧸ s) = mk g₁ :=\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 α) (g : α) :\n  {x : α | (x : α ⧸ s) = g} = left_coset g s :=\nset.ext $ λ 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 α) (s : set α) :\n  coe ⁻¹' ((coe : α → α ⧸ N) '' s) = ⋃ x : N, (λ y : α, y * x) ⁻¹' 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, set_like.coe_mk, ← eq_inv_mul_iff_mul_eq],\n  exact ⟨λ ⟨y, hs, hN⟩, ⟨_, N.inv_mem hN, by simpa using hs⟩,\n         λ ⟨z, hz, hxz⟩, ⟨x*z, hxz, by simpa using hz⟩⟩,\nend\n\nend quotient_group\n\nnamespace subgroup\nopen quotient_group\nvariables [group α] {s : subgroup α}\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 : α) : left_coset g s ≃ s :=\n⟨λ x, ⟨g⁻¹ * x.1, (mem_left_coset_iff _).1 x.2⟩,\n λ x, ⟨g * x.1, x.1, x.2, rfl⟩,\n λ ⟨x, hx⟩, subtype.eq $ by simp,\n λ ⟨g, hg⟩, subtype.eq $ by simp⟩\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 : α) : right_coset ↑s g ≃ s :=\n⟨λ x, ⟨x.1 * g⁻¹, (mem_right_coset_iff _).1 x.2⟩,\n λ x, ⟨x.1 * g, x.1, x.2, rfl⟩,\n λ ⟨x, hx⟩, subtype.eq $ by simp,\n λ ⟨g, hg⟩, subtype.eq $ by simp⟩\n\n/-- A (non-canonical) bijection between a group `α` and the product `(α/s) × s` -/\n@[to_additive \"A (non-canonical) bijection between an add_group `α` and the product `(α/s) × s`\"]\nnoncomputable def group_equiv_quotient_times_subgroup :\n  α ≃ (α ⧸ s) × s :=\ncalc α ≃ Σ L : α ⧸ s, {x : α // (x : α ⧸ s) = L} :\n  (equiv.sigma_fiber_equiv quotient_group.mk).symm\n    ... ≃ Σ L : α ⧸ s, left_coset (quotient.out' L) s :\n  equiv.sigma_congr_right (λ L,\n    begin\n      rw ← eq_class_eq_left_coset,\n      show _root_.subtype (λ x : α, quotient.mk' x = L) ≃\n        _root_.subtype (λ x : α, quotient.mk' x = quotient.mk' _),\n      simp [-quotient.eq'],\n    end)\n    ... ≃ Σ L : α ⧸ s, s :\n  equiv.sigma_congr_right (λ L, left_coset_equiv_subgroup _)\n    ... ≃ (α ⧸ s) × s :\n  equiv.sigma_equiv_prod _ _\n\nvariables {t : subgroup α}\n\n/-- If `H ≤ K`, then `G/H ≃ G/K × K/H` constructively, using the provided right inverse\nof the quotient map `G → G/K`. The classical version is `quotient_equiv_prod_of_le`. -/\n@[to_additive \"If `H ≤ K`, then `G/H ≃ G/K × K/H` constructively, using the provided right inverse\nof the quotient map `G → G/K`. The classical version is `quotient_equiv_prod_of_le`.\", simps]\ndef quotient_equiv_prod_of_le' (h_le : s ≤ t)\n  (f : α ⧸ t → α) (hf : function.right_inverse f quotient_group.mk) :\n  α ⧸ s ≃ (α ⧸ t) × (t ⧸ s.subgroup_of t) :=\n{ to_fun := λ a, ⟨a.map' id (λ b c h, left_rel_apply.mpr (h_le (left_rel_apply.mp h))),\n    a.map' (λ g : α, ⟨(f (quotient.mk' g))⁻¹ * g, left_rel_apply.mp (quotient.exact' (hf g))⟩)\n    (λ b c h, by\n    { rw left_rel_apply,\n      change ((f b)⁻¹ * b)⁻¹ * ((f c)⁻¹ * c) ∈ s,\n      have key : f b = f c :=\n        congr_arg f (quotient.sound' (left_rel_apply.mpr (h_le (left_rel_apply.mp h)))),\n      rwa [key, mul_inv_rev, inv_inv, mul_assoc, mul_inv_cancel_left, ← left_rel_apply] })⟩,\n  inv_fun := λ a, a.2.map' (λ b, f a.1 * b) (λ b c h, by\n  { rw left_rel_apply at ⊢ h,\n    change (f a.1 * b)⁻¹ * (f a.1 * c) ∈ s,\n    rwa [mul_inv_rev, mul_assoc, inv_mul_cancel_left] }),\n  left_inv := by\n  { refine quotient.ind' (λ a, _),\n    simp_rw [quotient.map'_mk', id.def, set_like.coe_mk, mul_inv_cancel_left] },\n  right_inv := by\n  { refine prod.rec _,\n    refine quotient.ind' (λ a, _),\n    refine quotient.ind' (λ b, _),\n    have key : quotient.mk' (f (quotient.mk' a) * b) = quotient.mk' a :=\n      (quotient_group.mk_mul_of_mem (f a) ↑b 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 ≤ K`, then `G/H ≃ G/K × K/H` nonconstructively.\nThe constructive version is `quotient_equiv_prod_of_le'`. -/\n@[to_additive \"If `H ≤ K`, then `G/H ≃ G/K × K/H` nonconstructively.\nThe constructive version is `quotient_equiv_prod_of_le'`.\", simps]\nnoncomputable def quotient_equiv_prod_of_le (h_le : s ≤ t) :\n  α ⧸ s ≃ (α ⧸ t) × (t ⧸ s.subgroup_of t) :=\nquotient_equiv_prod_of_le' h_le quotient.out' quotient.out_eq'\n\n/-- If `K ≤ L`, then there is an embedding `K ⧸ (H.subgroup_of K) ↪ L ⧸ (H.subgroup_of L)`. -/\n@[to_additive \"If `K ≤ L`, then there is an embedding\n  `K ⧸ (H.add_subgroup_of K) ↪ L ⧸ (H.add_subgroup_of L)`.\"]\ndef quotient_subgroup_of_embedding_of_le (H : subgroup α) {K L : subgroup α} (h : K ≤ L) :\n  K ⧸ (H.subgroup_of K) ↪ L ⧸ (H.subgroup_of L) :=\n{ to_fun := quotient.map' (set.inclusion h) (λ a b, by { simp [left_rel_apply], exact id }),\n  inj' := begin\n    refine quotient.ind₂' (λ a b, _),\n    refine λ h, (quotient.eq'.mpr ∘ left_rel_apply.mpr) _,\n    have := left_rel_apply.mp (quotient.eq'.mp h),\n    exact this,\n  end }\n\n@[to_additive] lemma card_eq_card_quotient_mul_card_subgroup\n  [fintype α] (s : subgroup α) [fintype s] [decidable_pred (λ a, a ∈ s)] :\n  fintype.card α = fintype.card (α ⧸ s) * fintype.card s :=\nby rw ← fintype.card_prod;\n  exact fintype.card_congr (subgroup.group_equiv_quotient_times_subgroup)\n\n/-- **Lagrange's Theorem**: The order of a subgroup divides the order of its ambient group. -/\n@[to_additive] lemma card_subgroup_dvd_card [fintype α] (s : subgroup α) [fintype s] :\n  fintype.card s ∣ fintype.card α :=\nby classical; simp [card_eq_card_quotient_mul_card_subgroup s, @dvd_mul_left ℕ]\n\n@[to_additive] lemma card_quotient_dvd_card [fintype α] (s : subgroup α)\n  [decidable_pred (λ a, a ∈ s)] [fintype s] : fintype.card (α ⧸ s) ∣ fintype.card α :=\nby simp [card_eq_card_quotient_mul_card_subgroup s, @dvd_mul_right ℕ]\n\nopen fintype\n\nvariables {H : Type*} [group H]\n\n@[to_additive] lemma card_dvd_of_injective [fintype α] [fintype H] (f : α →* H)\n  (hf : function.injective f) : card α ∣ card H :=\nby classical;\ncalc card α = card (f.range : subgroup H) : card_congr (equiv.of_injective f hf)\n...∣ card H : card_subgroup_dvd_card _\n\n@[to_additive] lemma card_dvd_of_le {H K : subgroup α} [fintype H] [fintype K] (hHK : H ≤ K) :\n  card H ∣ 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 : α →* H) [fintype (K.comap f)] (hf : function.injective f) :\n  fintype.card (K.comap f) ∣ 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... ∣ fintype.card K : card_dvd_of_le (map_comap_le _ _)\n\nend subgroup\n\nnamespace quotient_group\n\nvariables [group α]\n\n-- FIXME -- why is there no `to_additive`?\n\n/-- If `s` is a subgroup of the group `α`, and `t` is a subset of `α/s`, then\nthere is a (typically non-canonical) bijection between the preimage of `t` in\n`α` and the product `s × t`. -/\nnoncomputable def preimage_mk_equiv_subgroup_times_set\n  (s : subgroup α) (t : set (α ⧸ s)) : quotient_group.mk ⁻¹' t ≃ s × t :=\nhave h : ∀ {x : α ⧸ s} {a : α}, x ∈ t → a ∈ s →\n  (quotient.mk' (quotient.out' x * a) : α ⧸ s) = quotient.mk' (quotient.out' x) :=\n    λ x a hx ha, quotient.sound' $ by rwa [left_rel_apply, ← s.inv_mem_iff, mul_inv_rev, inv_inv,\n        ← mul_assoc, inv_mul_self, one_mul],\n{ to_fun := λ ⟨a, ha⟩, ⟨⟨(quotient.out' (quotient.mk' a))⁻¹ * a,\n    left_rel_apply.mp (@quotient.exact' _ (left_rel s) _ _ $ (quotient.out_eq' _))⟩,\n      ⟨quotient.mk' a, ha⟩⟩,\n  inv_fun := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, ⟨quotient.out' x * a, show quotient.mk' _ ∈ t,\n    by simp [h hx ha, hx]⟩,\n  left_inv := λ ⟨a, ha⟩, subtype.eq $ show _ * _ = a, by simp,\n  right_inv := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, 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": "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/coset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7615580236736708}}
{"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 `ε`, `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-/\n\n/-\n\n## lambda (λ) 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 : ℕ → ℝ := λ n, n^2+3\n\n/-\n\nMathematicians might write `n ↦ n^2+3` for this functions; indeed `λ` is\njust prefix notation for the infix notation `↦` (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₀, x₁, x₂, …` of reals on this sheet will\nbe encoded as a function `f : ℕ → ℝ` sending `0` to `x₀`, `1` to `x₁`\nand so on.\n \n## Limit of a sequence.\n\nHere's the definition of the limit of a sequence.\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 → ∞` is `t`. -/\ndef tendsto (a : ℕ → ℝ) (t : ℝ) : Prop :=\n∀ ε > 0, ∃ B : ℕ, ∀ n, B ≤ n → |a n - t| < ε\n\n-- the basic API for `tendsto`\n\n/-- If your goal is `tendsto a t` and you want to replace it with\n`∀ ε > 0, ∃ B, …` then you can do this with `rw tendsto_def`. -/\ntheorem tendsto_def {a : ℕ → ℝ} {t : ℝ} :\n  tendsto a t ↔ ∀ ε, 0 < ε → ∃ B : ℕ, ∀ n, B ≤ n → |a n - t| < ε :=\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 : ℝ) : tendsto (λ n, 37) 37 :=\nbegin\n  rw tendsto_def, -- you can just comment this out and the pf still works\n  intros ε hε,\n  use 1234567, -- any natural will do, but we have to choose one\n  intros n hn,\n  simp, -- because the goal mentions `|37 - 37|` which can\n  -- be solved by \"simplifying rewrites\" like `c - c = 0`\n  exact hε, -- you can combine the last two tactics with `simp [hε]`\nend\n\n/-- The limit of the constant sequence with value `c` is `c`. -/\ntheorem tendsto_const (c : ℝ) : tendsto (λ n, c) c :=\nbegin\n  rw tendsto_def,\n  intros ε hε,\n  use 42,\n  intros, -- something I promise I will never use just got a weird name\n  -- because I couldn't be bothered to name it \n  simp [hε],\nend\n\n/-- If `a(n)` tends to `t` then `a(n) + c` tends to `t + c` -/\ntheorem tendsto_add_const {a : ℕ → ℝ} {t : ℝ} (c : ℝ)\n  (h : tendsto a t) :\n  tendsto (λ n, a n + c) (t + c) :=\nbegin\n  rw tendsto_def at *,\n  intros ε hε,\n  specialize h ε hε,\n  cases h with B hB,\n  use B,\n  intros n hn,\n  specialize hB n hn,\n  convert hB using 2, -- could have done `convert hB n hn using 2` and saved a line,\n  ring,\nend\n\n-- alternative proof\ntheorem tendsto_add_const' {a : ℕ → ℝ} {t : ℝ} (c : ℝ)\n  (h : tendsto a t) :\n  tendsto (λ n, a n + c) (t + c) :=\nbegin\n  rw tendsto_def at *,\n  simpa using h, -- if you have a hypothesis `h` and\n  -- a goal `⊢ P`, and if after running the simplifier on\n  -- both `h` and `P` the terms become definitionally equal,\n  -- then `simpa using h` closes the goal. Try `simp *`\n  -- before the `simpa` to see what happens. `simp, assumption`\n  -- also closes the goal.\nend\n\n/-- If `a(n)` tends to `t` then `-a(n)` tends to `-t`.  -/\ntheorem tendsto_neg {a : ℕ → ℝ} {t : ℝ} (ha : tendsto a t) :\n  tendsto (λ n, - a n) (-t) :=\nbegin\n  rw tendsto_def at *,\n  simpa [abs_sub_comm] using ha,\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 : ℕ → ℝ} {t u : ℝ}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (λ n, a n + b n) (t + u) :=\nbegin\n  intros ε hε,\n  specialize ha (ε/2) (by linarith),\n  specialize hb (ε/2) (by linarith),\n  cases ha with B₁ hB₁,\n  cases hb with B₂ hB₂,\n  use max B₁ B₂, -- Application of the `use` tactic often indicates an \"idea\" in a proof. \n  intros n hn,\n  rw max_le_iff at hn,\n  cases hn with hn₁ hn₂,\n  dsimp only, -- git rid of stupid lambda\n  specialize hB₁ n hn₁,\n  specialize hB₂ n hn₂,\n  rw abs_lt at *,\n  cases hB₁,\n  cases hB₂,\n  split; -- semicolon means \"do both goals with next tactic\"\n  linarith,\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 : ℕ → ℝ} {t u : ℝ}\n  (ha : tendsto a t) (hb : tendsto b u) :\n  tendsto (λ n, a n - b n) (t - u) :=\ntendsto_add ha (tendsto_neg hb) -- you could put `begin exact tendsto_add ... end` but this is quicker\n-- note also we are using the fact that `t - u` is *defined* to mean `t + -u`.\n\n/-- If `a(n)` tends to `t` then `37 * a(n)` tends to `37 * t`-/\ntheorem tendsto_thirtyseven_mul (a : ℕ → ℝ) (t : ℝ) (h : tendsto a t) :\n  tendsto (λ n, 37 * a n) (37 * t) :=\nbegin\n  intros ε hε,\n  specialize h (ε/37) (by linarith),\n  cases h with B hB,\n  use B,\n  intros n hn,\n  specialize hB n hn,\n  -- now we have a tricky little inequality problem\n  rw [← mul_sub, abs_mul, abs_of_nonneg (show (0 : ℝ) ≤ 37, by norm_num)], -- now can treat |a n - t| as a constant\n  -- I found a lot of those rewrites by experimenting with `library_search`.\n  linarith,\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 : ℕ → ℝ} {t : ℝ} (h : tendsto a t)\n  {c : ℝ} (hc : 0 < c) : tendsto (λ n, c * a n) (c * t) :=\nbegin\n  intros ε hε,\n  specialize h (ε/c) (div_pos hε hc),\n  cases h with B hB,\n  use B,\n  intros n hn,\n  specialize hB n hn,\n  rw [← mul_sub, abs_mul, abs_of_nonneg (show c ≥ 0, by linarith)],\n  exact (lt_div_iff' hc).mp hB, -- thanks library_search\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 : ℕ → ℝ} {t : ℝ} (h : tendsto a t)\n  {c : ℝ} (hc : c < 0) : tendsto (λ n, c * a n) (c * t) :=\nbegin\n  -- handy hypothesis \n  have hc' : 0 < -c := neg_pos.mpr hc, -- thanks `library_search`\n  intros ε hε,\n  specialize h ((ε/(-c))) (div_pos hε hc'),\n  cases h with B hB,\n  use B,\n  intros n hn,\n  specialize hB n hn,\n  dsimp only, -- get rid of λ\n  rw [← mul_sub, abs_mul, abs_of_neg hc],\n  exact (lt_div_iff' hc').mp hB,\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 : ℕ → ℝ} {t : ℝ} (c : ℝ) (h : tendsto a t) :\n  tendsto (λ n, c * a n) (c * t) :=\nbegin\n  -- split into 3 cases 0 < c, c = 0 and c < 0\n  rcases lt_trichotomy 0 c with (hc | rfl | hc),\n  -- c > 0\n  { apply tendsto_pos_const_mul h hc },\n  -- c = 0 easy\n  { convert tendsto_const 0,\n    { ext,\n      simp },\n    { simp } },\n  -- c < 0\n  { apply tendsto_neg_const_mul h hc },\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 : ℕ → ℝ} {t : ℝ} (c : ℝ) (h : tendsto a t) :\n  tendsto (λ n, a n * c) (t * c) :=\nby simpa [mul_comm t, mul_comm _ c] using tendsto_const_mul c h\n-- `by tac` is the same as `begin tac end`, i.e. tactic blocks of length 1\n\n-- another proof of this\ntheorem tendsto_neg' {a : ℕ → ℝ} {t : ℝ} (ha : tendsto a t) :\n  tendsto (λ n, - a n) (-t) :=\nbegin\n  convert tendsto_const_mul (-1) ha, -- nearly right but not *exactly* right; new goals are the differences\n  { ext, simp },\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 tendsto_of_tendsto_sub {a b : ℕ → ℝ} {t u : ℝ}\n  (h1 : tendsto (λ n, a n - b n) t) (h2 : tendsto b u) :\n  tendsto a (t+u) :=\nbegin\n  convert tendsto_add h1 h2, -- reduces to an equality of functions\n  ext, -- apply functional extensionality\n  simp, -- `ring` would work too\nend\n\n/-- If `a(n)` tends to `t` then `a(n)-t` tends to `0`. -/\ntheorem tendsto_sub_lim {a : ℕ → ℝ} {t : ℝ}\n  (h : tendsto a t) : tendsto (λ n, a n - t) 0 :=\nbegin\n  convert tendsto_add_const (-t) h, -- nearly right\n  simp, -- last bit easy from simplifying rewrites.\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 : ℕ → ℝ} (ha : tendsto a 0) (hb : tendsto b 0) :\n  tendsto (λ n, a n * b n) 0 :=\nbegin\n  intros ε hε,\n  specialize ha ε hε,\n  specialize hb 1 (by linarith),\n  cases ha with Ba hBa,\n  cases hb with Bb hBb,\n  use (max Ba Bb),\n  intros n hn,\n  rw max_le_iff at hn,\n  cases hn with ha hb,\n  specialize hBa n ha,\n  specialize hBb n hb,\n  simp only [gt_iff_lt, sub_zero] at *, -- non-terminal simp was removed via `squeeze_simp`.\n  rw abs_mul,\n  have h0 : 0 ≤ |a n| := abs_nonneg (a n),\n  have h1 : 0 ≤ |b n| := abs_nonneg (b n),\n  nlinarith, -- general purpose non-linear inequality solver. \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 : ℕ → ℝ) (t u : ℝ) (ha : tendsto a t)\n  (hb : tendsto b u) : tendsto (λ n, a n * b n) (t * u) :=\nbegin\n  -- this method was harder than I thought because the algebra\n  -- under the binders was fiddly. I abstracted out random lemmas.\n  -- maybe if you went a different way you would have needed other\n  -- random lemmas instead of `tendsto_of_tendsto_sub`\n  have h1 : tendsto (λ n, a n - t) 0 := tendsto_sub_lim ha,\n  have h2 : tendsto (λ n, b n - u) 0 := tendsto_sub_lim hb,\n  have h3 := tendsto_zero_mul_tendsto_zero h1 h2,\n  clear h1 h2, -- these are no longer needed\n  simp only [sub_mul, mul_sub] at h3,\n  replace ha := tendsto_mul_const u ha,\n  replace ha := tendsto_sub_lim ha,\n  simp only at ha,\n  replace hb := tendsto_const_mul t hb,\n  have h6 := tendsto_of_tendsto_sub h3 ha,\n  clear h3 ha,\n  simp only [zero_add] at h6,\n  have h8 := tendsto_of_tendsto_sub h6 hb,\n  clear h6 hb, -- tidying up after ourselves for no apparent reason\n  simpa [zero_add] using h8,\nend\n\n-- something we never used!\n/-- A sequence has at most one limit. -/\ntheorem tendsto_unique (a : ℕ → ℝ) (s t : ℝ)\n  (hs : tendsto a s) (ht : tendsto a t) : s = t :=\nbegin\n  by_contra hne,\n  wlog h : s < t, \n  { rcases lt_trichotomy s t with (hst | rfl | hts),\n    { left, assumption },\n    { exact false.elim (hne rfl) },\n    { right, assumption } },\n  clear hne, -- have h now\n  let ε := (t - s) / 2,\n  have hεts : ε * 2 = t - s := by simp,\n  have hε : 0 < ε := div_pos (by linarith) zero_lt_two,\n  rcases hs ε hε with ⟨Bs, hs⟩,\n  rcases ht ε hε with ⟨Bt, ht⟩,\n  specialize hs (max Bs Bt) (le_max_left _ _),\n  specialize ht (max Bs Bt) (le_max_right _ _),\n  rw abs_lt at hs ht,\n  cases ht, cases hs, linarith,\nend", "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/solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.761558016493758}}
{"text": "import Lean4Axiomatic.AbstractAlgebra\n\n/-!\n# Fundamental definitions and properties of natural numbers\n\nClosely follows the [Peano axioms](https://en.wikipedia.org/wiki/Peano_axioms).\n-/\n\nnamespace Lean4Axiomatic.Natural\n\n/-!\n## Axioms\n-/\n\n/--\nDefines the primitive building blocks of all natural numbers.\n\nProvides the first two Peano axioms; see `Axioms.Base` for the rest.\n-/\nclass Constructors (ℕ : outParam Type) :=\n  /--\n  **Peano axiom 1**: `zero` is a natural number.\n\n  We start at zero instead of one because it gives nicer algebraic properties;\n  zero being the identity element for addition, for example.\n  -/\n  zero : ℕ\n\n  /--\n  **Peano axiom 2**: `step n` is a natural number for every natural number `n`.\n\n  The intuition is that `step zero` represents the number one,\n  `step (step zero)` represents two, `step (step (step zero))` is three, and in\n  general `step n` is the next number after `n` when counting up.\n\n  Other sources call this the _successor_ function, often abbreviated `S`,\n  `suc`, or `succ`. Using `step` is just as short, and conveys a similar\n  meaning, while not sounding like a word with negative connotations.\n  -/\n  step : ℕ → ℕ\n\nexport Constructors (zero step)\n\n/-- Definitions pertaining to equality of natural number values. -/\nclass Equality (ℕ : Type) :=\n  /-- Natural numbers have a decidable equality relation. -/\n  eqvOp? : Relation.Equivalence.EqvOp? ℕ\n\nattribute [instance] Equality.eqvOp?\n\nexport Equality (eqvOp?)\n\n/-- Definitions pertaining to numeric literal support for natural numbers. -/\nclass Literals (ℕ : outParam Type) [outParam (Constructors ℕ)] [outParam (Equality ℕ)] :=\n  /--\n  Enables representation of natural numbers by numeric literals.\n\n  Lean uses this instance to automatically replace literal values `n : Nat`\n  with `OfNat.ofNat ℕ n` in expressions where `ℕ` is expected. For example, the\n  raw literal `2` is represented as `succ (succ zero) : Nat`. In a context\n  where `2` is expected to have type `ℕ`, Lean would use this instance to\n  replace it with the term `OfNat.ofNat ℕ (succ (succ zero))`.\n\n  The interpretation of this representation must be equivalent to the\n  corresponding `Nat` values. The `literal_zero` and `literal_step` properties\n  enforce this requirement.\n  -/\n  literal {n : Nat} : OfNat ℕ n\n\n  /-- The numeric literal `0` represents the natural number `zero`. -/\n  literal_zero : OfNat.ofNat (α := ℕ) Nat.zero ≃ zero\n\n  /--\n  If the numeric literal `ℓ : Nat` represents the natural number `k`, then the\n  literal `Nat.succ ℓ` represents the natural number `step k`.\n  -/\n  literal_step {n : Nat}\n    : OfNat.ofNat (α := ℕ) (Nat.succ n) ≃ step (OfNat.ofNat n)\n\nattribute [instance default+1] Literals.literal\n\nexport Literals (literal literal_step literal_zero)\n\n/--\nPackages together the basic properties of natural numbers, to reduce the amount\nof class references needed for more advanced properties.\n-/\nclass Core (ℕ : Type) extends Constructors ℕ, Equality ℕ, Literals ℕ :=\n  /--\n  The `step` function preserves equality of natural numbers; if two natural\n  numbers are equal, they are still equal after `step` is applied to both.\n   -/\n  step_substitutive : AA.Substitutive₁ (α := ℕ) step (· ≃ ·) (· ≃ ·)\n\nattribute [instance] Core.step_substitutive\n\nexport Core (step_substitutive)\n\n/--\nProvides the remaining Peano axioms for natural numbers (see `Constructors`\nfor the first two).\n-/\nclass Axioms (ℕ : outParam Type) [outParam (Core ℕ)] :=\n  /-- **Peano axiom 3**: zero is not the successor of any natural number. -/\n  step_neqv_zero {n : ℕ} : step n ≄ 0\n\n  /--\n  **Peano axiom 4**: two natural numbers are equal if their successors are.\n  -/\n  step_injective : AA.Injective (α := ℕ) step (· ≃ ·) (· ≃ ·)\n\n  /--\n  **Peano axiom 5**: the principle of mathematical induction.\n\n  Given a predicate on natural numbers (here named `motive`), assert that it\n  holds of all natural numbers if the following criteria are met:\n  1. (base case) `motive 0` holds;\n  1. (inductive case) `motive (step n)` holds whenever `motive n` holds, for\n     all `n : ℕ`.\n  -/\n  ind {motive : ℕ → Prop}\n    : motive 0 → (∀ n, motive n → motive (step n)) → ∀ n, motive n\n\nattribute [instance] Axioms.step_injective\n\nexport Axioms (ind step_injective step_neqv_zero)\n\n/-!\n## Derived properties\n-/\n\nvariable {ℕ : Type}\nvariable [Core ℕ]\nvariable [Axioms ℕ]\n\n/--\nEquivalent to `Axioms.ind` but with a more convenient argument order when using\nthe `apply` tactic.\n-/\ndef ind_on\n    {motive : ℕ → Prop} (n : ℕ)\n    (zero : motive 0) (step : ∀ m, motive m → motive (step m)) : motive n\n    :=\n  Axioms.ind zero step n\n\n/--\nSimilar to `ind_on`, but doesn't provide an inductive hypothesis. Useful for\nproofs that need a case split but not the full power of induction.\n-/\ndef cases_on\n    {motive : ℕ → Prop} (n : ℕ)\n    (zero : motive 0) (step : ∀ n, motive (step n)) : motive n\n    :=\n  ind_on n zero (λ n _ => step n)\n\n/-- A natural number is never equal to its successor. -/\ntheorem step_neqv {n : ℕ} : step n ≄ n := by\n  apply ind_on (motive := λ n => step n ≄ n) n\n  case zero =>\n    show step 0 ≄ 0\n    exact step_neqv_zero\n  case step =>\n    intro n (ih : step n ≄ n)\n    show step (step n) ≄ step n\n    intro (_ : step (step n) ≃ step n)\n    show False\n    apply ih\n    show step n ≃ n\n    exact AA.inject ‹step (step n) ≃ step n›\n\nend Lean4Axiomatic.Natural\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/Natural/Core.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.761539969158255}}
{"text": "import .lovelib\n\n\n/-! # LoVe Exercise 3: Forward Proofs -/\n\n\nset_option pp.beta true\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 → a :=\nassume ha : a,\nshow a, from\n  ha\n\nlemma K (a b : Prop) :\n  a → b → b :=\nassume ha: a,\nassume hb: b,\nshow b, from\n  hb\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nassume habc: (a → b → c),\nassume hb: b,\nassume ha: a,\nshow c, from \n  habc ha hb\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nassume ha1,\nassume ha2: a,\nshow a, from\n  ha1\n\n/-! Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nassume ha1: a,\nassume ha2: a,\nshow a, from\n  ha2\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nassume habc: (a → b → c),\nassume ha: a,\nassume hac: (a → c),\nassume hb: b,\nshow c, from \n  habc ha hb\n\n/-! 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nassume hab: a → b,\nassume nb: ¬ b,\nshow ¬ a, from\nbegin\n  apply not.intro,\n  intro,\n  apply nb,\n  apply hab,\n  apply a_1,\nend\n\n/-! 1.3. Supply a structured proof of the distributivity of `∀` over `∧`. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\niff.intro\n  (assume pq: ∀ (x : α), p x ∧ q x,\n    have px : (∀x, p x) := \n      fix x: α,\n      and.elim_left (pq x),\n    have qx :(∀x, q x) :=\n      fix x: α,\n      and.elim_right (pq x),\n    show (∀x, p x) ∧ (∀x, q x), from\n      and.intro px qx\n  )\n  (assume pq: (∀x, p x) ∧ (∀x, q x),\n    fix x: α,\n    have px: p x := \n      and.elim_left pq x,\n    have qx: q x := \n      and.elim_right pq x,\n    show (p x) ∧ (q x), from\n      and.intro px qx\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 {α : Type} (r s : α → α → Prop) :\n  (∀x, r x x ∧ s x x) ↔ (∀x, r x x) ∧ (∀x, s x x) :=\nforall_and _ _\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 : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\ncalc (a + b) * (a + b)\n    = a * (a + b) + b * (a + b): by rewrite add_mul\n... = a * a + a * b + b * (a + b): by rewrite <- mul_add\n... = a * a + a * b + (b * a + b * b): by simp [mul_add b a b]\n... = a * a + (a * b + a * b) + b * b: by cc\n... = a * a + 2 * (a * b) + b * b: by rewrite two_mul (a * b)\n... = a * a + 2 * a * b + b * b: by cc\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₂ (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nhave h1: (a + b) * (a + b) = a * (a + b) + b * (a + b), by rewrite add_mul,\nhave h2: a * (a + b) + b * (a + b) = a * a + a * b + b * (a + b), by rewrite <- mul_add,\nhave h3: a * a + a * b + b * (a + b) = a * a + a * b + (b * a + b * b), by simp [mul_add b a b],\nhave h4: (a + b) * (a + b) = a * a + (a * b + a * b) + b * b, by cc,\nhave h5: a * a + (a * b + a * b) + b * b = a * a + 2 * (a * b) + b * b, by rewrite two_mul (a * b),\nshow (a + b) * (a + b) = a * a + 2 * a * b + b * b, from\nbegin\n  cc,\nend\n\n/-! 2.3. Prove the same lemma again, this time using tactics. -/\n\nlemma binomial_square₃ (a b : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nbegin\n  simp [add_mul, mul_add, two_mul],\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 `∀` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {α : Type} {t : α} {p : α → Prop} :\n  (∀x : α, x = t ∧ p x) ↔ 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 `∃` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {α : Type} {t : α} {p : α → Prop} :\n  (∃x : α, x = t → p x) ↔ p t\n\nlemma proof_of_false₂ :\n  false :=\nsorry\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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8539127455162774, "lm_q1q2_score": 0.7615288133808765}}
{"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.polynomial.degree.definitions\n\n/-!\n# Cancel the leading terms of two polynomials\n\n## Definition\n\n* `cancel_leads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting.\n\n## Main Results\nThe degree of `cancel_leads` is less than that of the larger of the two polynomials being cancelled.\nThus it is useful for induction or minimal-degree arguments.\n-/\nnamespace polynomial\nnoncomputable theory\n\nvariables {R : Type*}\n\nsection comm_ring\nvariables [comm_ring R] (p q : polynomial R)\n\n/-- `cancel_leads p q` is formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting. -/\ndef cancel_leads : polynomial R :=\nC p.leading_coeff * X ^ (p.nat_degree - q.nat_degree) * q -\nC q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p\n\nvariables {p q}\n\n@[simp] lemma neg_cancel_leads : - p.cancel_leads q = q.cancel_leads p := neg_sub _ _\n\nlemma dvd_cancel_leads_of_dvd_of_dvd {r : polynomial R} (pq : p ∣ q) (pr : p ∣ r) :\n  p ∣ q.cancel_leads r :=\ndvd_sub (dvd.trans pr (dvd.intro_left _ rfl)) (dvd.trans pq (dvd.intro_left _ rfl))\n\nend comm_ring\n\nlemma nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree [integral_domain R]\n  {p q : polynomial R} (h : p.nat_degree ≤ q.nat_degree) (hq : 0 < q.nat_degree) :\n  (p.cancel_leads q).nat_degree < q.nat_degree :=\nbegin\n  by_cases hp : p = 0,\n  { convert hq,\n    simp [hp, cancel_leads], },\n  rw [cancel_leads, sub_eq_add_neg, nat.sub_eq_zero_of_le h, pow_zero, mul_one],\n  by_cases h0 :\n      C p.leading_coeff * q + -(C q.leading_coeff * X ^ (q.nat_degree - p.nat_degree) * p) = 0,\n  { convert hq,\n    simp only [h0, nat_degree_zero], },\n  have hq0 : ¬ q = 0,\n  { contrapose! hq,\n    simp [hq] },\n  apply lt_of_le_of_ne,\n  { rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree h0, ← degree_eq_nat_degree hq0],\n    apply le_trans (degree_add_le _ _),\n    rw ← leading_coeff_eq_zero at hp hq0,\n    simp only [max_le_iff, degree_C hp, degree_C hq0, le_refl q.degree, true_and, nat.cast_with_bot,\n      nsmul_one, degree_neg, degree_mul, zero_add, degree_X, degree_pow],\n    rw leading_coeff_eq_zero at hp hq0,\n    rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq0, ← with_bot.coe_add, with_bot.coe_le_coe,\n      nat.sub_add_cancel h], },\n  { contrapose! h0,\n    rw [← leading_coeff_eq_zero, leading_coeff, h0, mul_assoc, mul_comm _ p,\n      ← nat.sub_add_cancel h, add_comm _ p.nat_degree],\n    simp only [coeff_mul_X_pow, coeff_neg, coeff_C_mul, nat.add_sub_cancel_left, coeff_add],\n    rw [add_comm p.nat_degree, nat.sub_add_cancel h, ← leading_coeff, ← leading_coeff,\n      mul_comm _ q.leading_coeff, ← sub_eq_add_neg, ← mul_sub, sub_self, mul_zero] }\nend\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/cancel_leads.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7614181344707412}}
{"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\nThis file provides two equivalences for linearly ordered fintypes:\n* `mono_equiv_of_fin`: Order isomorphism between `α` and `fin (card α)`.\n* `fin_sum_equiv_of_finset`: Equivalence between `α` and `fin m ⊕ fin n` where `m` and `n` are\n  respectively the cardinalities of some `finset α` and its complement.\n-/\n\nopen finset\n\n/-- Given a linearly ordered fintype `α` of cardinal `k`, the order isomorphism\n`mono_equiv_of_fin α h` is the increasing bijection between `fin k` and `α`. Here, `h` is a proof\nthat the cardinality of `α` is `k`. We use this instead of an isomorphism `fin (card α) ≃o α` to\navoid casting issues in further uses of this function. -/\ndef mono_equiv_of_fin (α : Type*) [fintype α] [linear_order α] {k : ℕ} (h : fintype.card α = k) :\n  fin k ≃o α :=\n(univ.order_iso_of_fin h).trans $ (order_iso.set_congr _ _ coe_univ).trans order_iso.set.univ\n\nvariables {α : Type*} [decidable_eq α] [fintype α] [linear_order α] {m n : ℕ} {s : finset α}\n\n/-- If `α` is a linearly ordered fintype, `s : finset α` has cardinality `m` and its complement has\ncardinality `n`, then `fin m ⊕ fin n ≃ α`. The equivalence sends elements of `fin m` to\nelements of `s` and elements of `fin n` to elements of `sᶜ` while preserving order on each\n\"half\" of `fin m ⊕ fin n` (using `set.order_iso_of_fin`). -/\ndef fin_sum_equiv_of_finset (hm : s.card = m) (hn : sᶜ.card = n) : fin m ⊕ fin n ≃ α :=\ncalc fin m ⊕ fin n ≃ (s : set α) ⊕ (sᶜ : set α) :\n  equiv.sum_congr (s.order_iso_of_fin hm).to_equiv $\n    (sᶜ.order_iso_of_fin hn).to_equiv.trans $ equiv.set.of_eq s.coe_compl\n... ≃ α : equiv.set.sum_compl _\n\n@[simp] lemma fin_sum_equiv_of_finset_inl (hm : s.card = m) (hn : sᶜ.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ᶜ.card = n) (i : fin n) :\n  fin_sum_equiv_of_finset hm hn (sum.inr i) = sᶜ.order_emb_of_fin hn i :=\nrfl\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/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7613891133112528}}
{"text": "/-\nhow to use only exact to prove 0 + n = n:\n-/\ninductive mynat : Type\n| zero : mynat\n| succ : mynat → mynat\n\n#print nat.add\n\nopen mynat\n-- def add' : mynat → mynat → mynat\n-- | a  zero     := a\n-- | a  (succ b) := succ (add' a b)\nconstant add' : mynat → mynat → mynat\n\nnotation 0 := mynat.zero\n-- notation a` + `b := add' a b\n\naxiom add_zero' (a : mynat) : add' a 0 = a\naxiom add_succ' (a b : mynat) : add' a (succ b) = succ(add' a b)\n\nlemma zero_add'(n : mynat) : add' 0 n = n :=\nbegin\n  induction n with d hd,\n  rw add_zero',\n  /-\n  λ (n : mynat),\n  mynat.rec ((id ((eq.refl (add' 0 0 = 0)).rec (add_zero' 0))).mpr (eq.refl 0))\n    (λ (d : mynat) (hd : add' 0 d = d), sorry) n\n  -/\n  rw [add_succ', hd],\n  /-\n  λ (n : mynat),\n  mynat.rec ((id ((eq.refl (add' 0 0 = 0)).rec (add_zero' 0))).mpr (eq.refl 0))\n    (λ (d : mynat) (hd : add' 0 d = d),\n       (id ((eq.refl (add' 0 d.succ = d.succ)).rec (add_succ' 0 d))).mpr\n         ((id ((eq.refl ((add' 0 d).succ = d.succ)).rec hd)).mpr (eq.refl d.succ)))\n    n  \n  -/\nend\n#print zero_add'\n\nnotation a ++ b := add' a b\n\nlemma add_assoc' (a b c : mynat) : (a ++ b) ++ c = a ++ (b ++ c) :=\nbegin\ninduction c with c hc,\nrw add_zero',\nrw add_zero',\nrw add_succ',\nrw add_succ',\nrw add_succ',\nrw hc,\nend\n\nlemma add_right_comm (a b c : mynat) : a + b + c = a + c + b :=\nbegin\n  -- a + b + c\n  rw add_assoc, \n  rw add_comm,\n  -- <=> rotate permutation (231)\n  -- b + c + a\n  rw add_assoc,\n  rw add_comm,\n  -- c + a + b\n  rw add_assoc,\n  rw add_comm,\n  -- a + b + c\nend\n\n/-\n\nlemma succ_add (a b : mynat) : succ a + b = succ (a + b) :=\nbegin\n  induction b with b hb,\n  repeat {rw add_zero, },\n  rw add_succ,\n  rw add_succ,\n  rw hb,\n  refl,\n\n-- n the set of natural numbers, addition is commutative. \n-- In other words, for all natural numbers a and b, we have a + b = b + a\nlemma add_comm (a b : mynat) : a + b = b + a :=\nbegin\n  induction a with a ha,\n  rw [zero_add, add_zero],\n  refl,\n  rw add_succ,\n  rw succ_add,\n  rw ha,\n  refl,\nend\n\ntheorem succ_eq_add_one (n : mynat) : succ n = n + 1 :=\nbegin\n  induction n with n hn,\n  rw one_eq_succ_zero,\n  rw zero_add, refl,\n  rw succ_add,\nend\n\nlemma add_right_comm (a b c : mynat) : a + b + c = a + c + b :=\nbegin\n  rw add_assoc,\n  rw add_comm,\n  apply eq.symm,\n  rw add_comm,\n  rw add_assoc,\n  have : a + c = c + a, from add_comm a c,\n  rw this, refl,\nend\n\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/question.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7613639246802454}}
{"text": "import .src_07_existential_quantification\n\nvariables p q r : Prop \n\nnamespace mth1001\n\nsection or_elimination\n\n/-\nWe've seen how to introduce a statement of the form `p ∨ q`. In this section, we'll see\nhow to _use_ a premise `h : p ∨ q`.\n\nSuppose you have `h : p ∨ q` and you know both\n1. `r` follows from `p` and\n2. `r` follows from `q`,\nthen you may derive `r`. This is known as or elimination.\n-/\n\n/-\nHere's a template for a tactic-mode application of or elimination. The line\n  `cases h with hp hq`\ndecomposes `h` and creates two subgoals:\n1. a goal of deriving `r`, where `h` has been replaced with `hp : p` in the context and\n2. a goal of deriving `r`, where `h` has been replaced with `hq : q` in the context.\n\nThese goals are closed through implication elimination.\n-/\nexample (h : p ∨ q) (k₁ : p → r) (k₂ : q → r) : r :=\nbegin \n  cases h with hp hq,\n  { exact k₁ hp },\n  { exact k₂ hq },\nend\n\n/-\nFor a term-style proof, we use the theorem `or.elim`.\n-/\n#check @or.elim\n/-\nWe see that `or.elim` (ignore the `@` for now) has type\n  `∀ {a b c : Prop}, a ∨ b → (a → c) → (b → c) → c`\nThis means that `or.elim` takes three arguments, one of type `a ∨ b`, one of type `a → c`,\nand one of type `b → c`. It returns a proof of `c`.\n\nRecall that the braces in `∀ {a b c : Prop}` tell Lean that the arguments `a`, `b`, and `c` \nare implicit - you need not supply them explicity.\n-/\n\n/-\nWe now use `or.elim` to give a term-style proof of the above result.\n-/\nexample (h : p ∨ q) (k₁ : p → r) (k₂ : q → r) : r :=\nor.elim h k₁ k₂\n\n/-\nHINT: when constructing a proof term, you can replace arguments with `_`. Even when Lean\ncannot infer the argument, it will give you information about the goal and the context.\n\nFor instance, replacing `k₂` above with `_` gives the following information:\n```\ndon't know how to synthesize placeholder\ncontext:\np q r : Prop,\nh : p ∨ q,\nk₁ : p → r,\nk₂ : q → r\n⊢ q → r\n```\n\nThe goal is presented as `⊢ q → r`. It's clear that this goal matches exactly the premise `k₂`.\n-/\n\n-- Exercise 050:\n/-\nWe can mimic the tactic-mode proof by replacing `k₁` and `k₂` in the proof term\n  `or.elim h k₁ k₂`\nwith more complicated terms. Though inefficient in this case, it provides a useful template\nfor more sophisticated examples.\n-/\nexample (h : p ∨ q) (k₁ : p → r) (k₂ : q → r) : r :=\nor.elim h\n( assume hp, k₁ hp )\nsorry \n\n-- Exercise 051:\nexample (h : (p ∧ q) ∨ (q ∧ r)) : q :=\nbegin\n  cases h with h₁ h₂,\n  sorry,\n  sorry,\nend\n\n-- Exercise 052:\nexample (h : (p ∧ q) ∨ (q ∧ r)) : q :=\nor.elim h\nsorry \nsorry \n/-\nThe combination of the following two results is called right distributivity of `∧` over `∨`\n(you don't need to remember this name!)\n-/\n\n-- Exercise 053:\ntheorem or_and_distrib_right1 : (p ∧ r) ∨ (q ∧ r) → (p ∨ q) ∧ r :=\nbegin \n  intro h,\n  cases h with hpr hqr,\n  { split,\n    { left, exact hpr.left },\n    { sorry, } }, \n  { sorry, },\nend\n\n-- Exercise 054:\n-- See the next example for a hint.\ntheorem or_and_distrib_right2 : (p ∨ q) ∧ r → (p ∧ r) ∨ (q ∧ r) :=\nbegin\n  sorry  \nend\n\n-- If you're stuck with the exercise above, here's a hint:\nexample : (p ∨ q) ∧ r → (p ∧ r) ∨ (q ∧ r) :=\nbegin\n  intro h,\n  cases h with hpq hr,\n  cases hpq with hp hq,\n  { sorry, },\n  { sorry, },\nend\n\n/-\nWe'll present some more examples using `odd` and `even` numbers. You don't need to understand\nall the details of the theorem, but it's worth nothing two points\n\n(1) Suppose `h` is an equation or if and only if expression, for example `h : a = b`.\nThe tactic `rw h` looks for `a` in the goal and replaces it with `b`. However, `rw ←h` looks\nfor `b` in the goals and replaces it with `a`.\n\n(2) The `linarith` tactic automatically uses any relevant premises in the context to solve linear\nequations and inequalities. \n\n(3) The `ring` tactic simplies algebraic expressions, whether linear or not.\n-/\nopen int \n\ntheorem even_or_odd (m : ℤ) : even m ∨ odd m :=\nbegin \n  cases (mod_two_eq_zero_or_one m) with h,\n  { left,\n    use (m/2),\n    rw [←(mod_add_div m 2), h],\n    ring,\n    rw int.mul_div_cancel_left,\n    linarith, },\n  { right,\n    use (m/2),\n    rw [←(mod_add_div m 2), h, add_comm],\n    congr' 2,\n    rw [add_comm, int.add_mul_div_left],\n    norm_num,\n    linarith, },\nend\n\n-- Exercise 055:\n-- We use the theorem above in proving the following.\nexample (b : ℤ) : even b ∨ odd (b + 8) :=\nbegin \n  cases even_or_odd b with h,\n  { sorry, }, \n  { sorry, },  \nend \n\n\n-- Exercise 056:\ntheorem even_mul_add_one (a : ℤ) : even (a * (a + 1)) :=\nbegin\n  sorry  \nend\n\nend or_elimination\n\n/-\nSUMMARY:\n\n* Or elimination.\n* Tactic-style elimination using `cases`.\n* Term-sytle elimination using `or.elim`.\n\n* Using the `_` placeholder.\n\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_09_or_elimination.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7613639152496456}}
{"text": "import .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 {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nbegin\n  intros a₁ a₂ 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 {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nbegin\n  intros a₁ a₂ 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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing : regex\n| empty   : regex\n| atom    : α → regex\n| concat  : regex → regex → regex\n| alt     : regex → regex → regex\n| star    : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n| (regex.concat r₁ r₂) := rel_of_regex r₁ ◯ rel_of_regex r₂\n| (regex.alt r₁ r₂)    := rel_of_regex r₁ ∪ rel_of_regex r₂\n| (regex.star r)       := lfp (λX, (rel_of_regex r ◯ X) ∪ Id)\n\n/-! 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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": "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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.761275652954088}}
{"text": "-- Imagen_inversa_de_la_imagen.lean\n-- Imagen inversa de la imagen\n-- José A. Alonso Jiménez\n-- Sevilla, 7 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si s es un subconjunto del dominio de la función f,\n-- entonces s está contenido en la [imagen inversa](https://bit.ly/3ckseBL)\n-- de la [imagen de s por f](https://bit.ly/3x2Jxij); es decir,\n--    s ⊆ f⁻¹[f[s]]\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\n\nopen set\n\nvariables {α : Type*} {β : Type*}\nvariable  f : α → β\nvariable  s : set α\n\n-- 1ª demostración\n-- ===============\n\nexample : s ⊆ f ⁻¹' (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ª demostración\n-- ===============\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nbegin\n  intros x xs,\n  apply mem_image_of_mem,\n  exact xs,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nλ x, mem_image_of_mem f\n\n-- 4ª demostración\n-- ===============\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nbegin\n  intros x xs,\n  show f x ∈ f '' s,\n  use [x, xs],\nend\n\n-- 5ª demostración\n-- ===============\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nbegin\n  intros x xs,\n  use [x, xs],\nend\n\n-- 6ª demostración\n-- ===============\n\nexample : s ⊆ f ⁻¹' (f '' s) :=\nsubset_preimage_image f s\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_imagen.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7612756526563308}}
{"text": "import algebra.ring.basic\nimport algebra.algebra.subalgebra\nimport algebra.group.defs\nimport analysis.special_functions.pow\nimport data.nat.parity\nimport data.nat.prime\nimport data.pnat.basic\nimport data.int.parity\nimport data.zmod.basic\nimport data.rat.basic\nimport data.real.basic\nimport data.real.irrational\nimport data.zsqrtd.basic\nimport ring_theory.subring\nimport tactic\nimport tactic.slim_check\nimport data.equiv.ring\nimport algebra.punit_instances\nopen rat\nopen nat\nopen tactic\nopen real\n\n-- Garrett Birkhoff and Saunders Mac Lane: A survey of modern algebra, 4th ed\n\nnamespace ch1A\n\n-- 1.1 Commutative Rings\n\n-- Integral domain\n\n#check integral_domain\n\n-- An integral domain of interest for number theory consists of all a + b √ 2, a and b ∈ ℤ \n\n#check ℤ√2\n\n-- 1.2. Elementary Properties of Commutative Rings\n\nuniverse u\n\nvariables {α : Type u} [comm_ring α] {a b c d z x₁ x₂ :  α}\n\nlemma rule_1 : (a+b)*c=a*c+b*c := add_mul _ _ _\nlemma rule_2_plus : (0 + a = a) := zero_add _\nlemma rule_2_times : (1 * a = a) := one_mul _\n\nlemma rule_3 : (∀ (a : α), a + z = a) → z = 0 := \nbegin\n  intro h1,\n  have h2 := h1 0,\n  exact add_left_eq_self.mp (congr_arg (has_add.add z) (congr_arg (has_add.add z) (h1 z))),\nend\n\nlemma rule_4 : a + b = a + c → b = c := (add_right_inj a).mp\n\nlemma rule_5 : a + x₁ = 0 → a + x₂ = 0 → x₁ = x₂ :=\nbegin\n  intro h1,\n  intro h2,\n  exact neg_unique h1 h2,\nend\n\nlemma rule_6 : a + x₁ = b → a + x₂ = b → x₁ = x₂ :=\nbegin\n  intro h1,\n  intro h2,\n  rw ← h1 at h2,\n  exact rule_4 (eq.symm h2),\nend\n\nlemma rule_7a : a * 0 = 0 := mul_zero a\nlemma rule_7b  : 0 * a = 0 := zero_mul a\n\nlemma rule_8 : (∀ (a : α), a*z = a) → z = 1 :=\nbegin\n  intro h1,\n  exact (eq_one_iff_eq_one_of_mul_eq_one (h1 1)).mp rfl,\nend\n\nlemma rule_9 : (-a)*(-b) = a*b := neg_mul_neg _ _\n\n/- Theorem 1. The cancellation law of multiplication for integral domains\nis equivalent in a commutative ring to the assertion that \na product of nonzero factors is not 0. -/\n\ntheorem theorem_1 :\n  (∀ a b c : α, c ≠ 0 → c*a = c*b → a = b) ↔\n  (∀ a b : α, a ≠ 0 → b ≠ 0 → a * b ≠ 0) :=\nbegin\n  split,\n  { intros H a b ha hb ab,\n    refine hb (H _ _ _ ha _),\n    have hc := mul_zero a,\n    rw hc,\n    rw ab, \n  },\n  { intros H a b c hc e,\n    rw ← sub_eq_zero at e ⊢,\n    refine by_contra (λ h, _),\n    refine H c (a - b) hc h _,\n    have hd := left_distrib c a (-b),\n    have he := sub_eq_add_neg a b,\n    rw ← he at hd,\n    have hf := norm_num.mul_pos_neg c b (c * b) rfl,\n    rw hf at hd,\n    have hg := sub_eq_add_neg (c*a) (c*b),\n    rw ← hg at hd,\n    rw hd,\n    exact e,\n  },\nend\n\n#check left_distrib c a (-b)\n/- A subdomain of an integral domain D is a subset of D\nwhich is also an integral domain, for the same operations of addition and\nmultiplication. -/\n\nvariables {R : Type*} [integral_domain R] {D : subring R}\nexample : integral_domain D := subring.subring.domain D\n\n-- Exercises for section 1.2\n\nlemma ex1a : (a+b)*(c+d) = (a*c+b*c) + (a*d + b*d) := \nbegin\n  ring,\nend\n\nlemma ex1b1 : a+(b+(c+d))=(a+b)+(c+d) := \nbegin\n  ring,\nend\n\nlemma ex1b2 : (a+b)+(c+d)=((a+b)+c)+d := \nbegin\n  ring,\nend\n\nlemma ex1c : a+(b+c) = (c+a)+b:= \nbegin\n  ring,\nend\n\nlemma ex1d : a*(b*c)=c*(a*b) := \nbegin\n  ring,\nend\n\nlemma ex1e : a*(b+(c+d))=(a*b+a*c)+a*d := \nbegin\n  ring,\nend\n\nlemma ex1f : (a+b)*(c+d) = (a*c+b*c) + (a*d + b*d) := \nbegin\n  ring,\nend\n\n#check rule_8\n\nlemma ex2b : 1*1=1 :=\nbegin\n  ring,\nend\n\n/- Exercise 2c.  The only idempotents of an integral domain are 0 and 1. -/\nvariables {β : Type u} [integral_domain β] {x : β}\nlemma ex2c : ∀ (x : β), x*x = x → (x = 0 ∨ x = 1) :=\nbegin\n  intro x,\n  intro h1,\n  conv_rhs at h1 { rw ← mul_one x, },\n  have h2 := sub_eq_zero.mpr h1,\n  rw (mul_sub x x 1).symm at h2,\n  have h3 := mul_eq_zero.mp h2,\n  by_cases h4 : x = 0,\n  by_cases h5 : x-1 = 0,\n  exact or.inl h4,\n  exact or.inl h4,\n  refine or.inr _,\n  exact (mul_right_inj' h4).mp h1,\nend\n\nlemma ex2c_JC (h1 : x * x = x) : x = 0 ∨ x = 1 := -- Johan Commelin\nby simp [← @sub_eq_zero β _ _ 1, ← mul_eq_zero, mul_sub, h1]\n\nlemma ex2c_KL {x : β} (h1 : x * x = x) : x = 0 ∨ x = 1 := -- Kenny Lau\nor_iff_not_imp_left.2 $ λ hx, mul_left_cancel' hx $ h1.trans (mul_one x).symm\n\nlemma ex3a : -(-a) = a :=\nbegin\n  ring,\nend\n\nlemma ex3b : -(0 : α ) = 0 := \nbegin\n  ring,\nend\n\nlemma ex3c : -(a+b) = (-a) + (-b) := \nbegin\n  ring,\nend\n\nlemma ex3d : -a = (-1)*a := \nbegin\n  ring,\nend\n\nlemma ex3e1 : (-a)*b=a*(-b) := \nbegin\n  ring,\nend\n\nlemma ex3e2 : a*(-b)=-(a*b) := \nbegin\n  ring,\nend\n\n#check rule_9\n\nlemma ex4 : (-1)*(-1) = (1:α) :=\nbegin\n  ring,\nend\n\nend ch1A\n\nnamespace ch1B\n\nuniverse u\nvariables {α : Type u} [integral_domain α] {a b c d : α}\n\nlemma ex5a: (a-b) + (c-d) = (a+c)-(b+d) :=\nbegin\n  ring,\nend\n\nlemma ex5b : (a-b)-(c-d) = (a+d)-(b+c) :=\nbegin\n  ring,\nend\n\nlemma ex5c : (a-b)*(c-d) = (a*c + b*d)-(a*d+b*c)  :=\nbegin\n  ring,\nend\n\nlemma ex5d : a-b=c-d ↔ a+d=b+c :=\nbegin\n  split,\n  {\n    intro h,\n    apply_fun (λ t, t+b+d) at h,\n    conv at h \n    begin\n      to_lhs,\n      rw sub_add_cancel,\n    end,\n    conv at h\n    begin\n      to_rhs,\n      rw sub_add_eq_add_sub,\n      rw sub_add,\n      rw sub_self,\n      rw sub_zero,\n    end,\n    have swap := add_comm c b,\n    rw swap at h,\n    assumption,   \n  },\n  {\n    intro h,\n    apply_fun (λ t, t-b-d) at h,\n    conv at h\n    begin\n      to_lhs,\n      rw ← sub_add_eq_add_sub,\n      rw ← add_sub,\n      rw sub_self,\n      rw add_zero,\n    end,\n    conv at h\n    begin\n      to_rhs,\n      rw ← sub_add_eq_add_sub,\n      rw sub_self,\n      rw zero_add,\n    end,\n    assumption,\n  },\nend\n\nlemma ex5e : (a-b)*c = a*c - b*c :=\nbegin\n  ring,\nend\n\ninstance (x : ℤ) : decidable (even x) :=  \n  decidable_of_iff' _ even_iff_two_dvd\n\ntheorem ex6a :  ¬ ∃ s : subring ℤ, ∀ x, x ∈ s ↔ even x := -- Mario Carneiro\nλ ⟨S, h⟩, absurd ((h 1).1 S.one_mem) dec_trivial\n\ntheorem ex6b :  ¬ ∃ s : subring ℤ, ∀ x, x ∈ s ↔ odd x :=\nbegin\n  intro h1,\n  cases h1 with S h,\n  have h2 := h 0,\n  have h3 := h2.1,\n  have h4 := S.zero_mem,\n  have h5 := h3 h4,\n  have h6 := (@int.odd_iff_not_even 0).1,\n  have h7 := h6 h5,\n  have h8 := absurd h7 dec_trivial,\n  exact h8,\nend\n\ntheorem ex6c :  ¬ ∃ s : subring ℤ, ∀ x, x ∈ s ↔ (0:ℤ) < x := \nbegin\n  intro h1,\n  cases h1 with S h,\n  have h2 := h (0:ℤ),\n  have h3 := subring.zero_mem S,\n  have h4 := h2.1,\n  have h5 := h4 h3,\n  have h6 := lt_irrefl (0:ℤ),\n  exact h6 h5,\nend\n\n\n-- Mario Carneiro\ntheorem ex6d : ¬ ∃ s : subring ℝ, ∀ x : ℝ, x ∈ s ↔ ∃ a b : ℤ, x = a + b * 5 ^ (1/4:ℝ) :=\nbegin\n  rintro ⟨S, h⟩,\n  simp only [one_div] at h,\n  have hY : (5 ^ (2⁻¹:ℝ) : ℝ) = (5 ^ (4⁻¹:ℝ) : ℝ) * (5 ^ (4⁻¹:ℝ) : ℝ),\n    by rw ← real.rpow_add; norm_num,\n  have hX : (5 : ℝ) = (5 ^ (2⁻¹:ℝ) : ℝ) * (5 ^ (2⁻¹:ℝ) : ℝ),\n    by rw ← real.rpow_add; norm_num,\n  set X := (5 ^ (2⁻¹:ℝ):ℝ) with eX,\n  have : X ∈ S,\n  { have : (5 ^ (4⁻¹:ℝ) : ℝ) ∈ S := (h _).2 ⟨0, 1, by simp⟩,\n    have := S.mul_mem this this,\n    rwa hY },\n  rcases (h _).1 this with ⟨a, b, e⟩, clear this,\n  rw ← sub_eq_iff_eq_add' at e,\n  have := congr (congr_arg (*) e) e,\n  rw [mul_mul_mul_comm, ← hY, sub_mul, mul_sub, ← hX, ← sub_eq_zero] at this,\n  have : X * (2 * a + b * b : ℤ) = (5 + a * a : ℤ),\n  { symmetry, simp [← sub_eq_zero], refine eq.trans (by ring) this },\n  by_cases h0 : ((2 * a + b * b : ℤ) : ℝ) = 0,\n  { simp [h0] at this, linarith only [mul_self_nonneg ((a:ℤ):ℝ), this] },\n  rw ← eq_div_iff h0 at this,\n  refine (irrational_iff_ne_rational _).1 _ _ _ this,\n  rw ← show real.sqrt 5 = X, by rw [eX, real.sqrt_eq_rpow, one_div],\n  exact_mod_cast nat.prime.irrational_sqrt (by norm_num : nat.prime 5),\nend\n\n/- Set s is closed under addition and multiplication, so if\n\na b c d : ℤ\nx = a + b * 9 ^ (1/4:ℝ)\ny = c + d * 9 ^ (1/4:ℝ)\n\nthen\n\nx + y = (a+c) + (b +d)* 9 ^ (1/4:ℝ)\n(a+c): ℤ\n(b+d): ℤ\nhence\n\n(x+y)∈ s\nand\n\n9 ^ (1/4:ℝ) *9 ^ (1/4:ℝ) =(3:ℤ)\nand\n\nx *y=(a*c+b*d*3)+(a*d+b*c)* 9 ^ (1/4:ℝ)\n(a*c+b*d*3): ℤ\n(a*d+b*c): ℤ\nhence\n\n(x*y)∈ s\nand hence\n\ns : subring ℝ -/\n-- Eric Wieser\n/-- The image of `zsqrtd` in `ℝ`.  -/\n@[simps]\nnoncomputable def zsqrtd.to_real {d : ℤ } (h : 0 ≤ d) : ℤ√d →+* ℝ := {\n  to_fun := λ a, a.1 + a.2*real.sqrt d,\n  map_zero' := by simp,\n  map_add' := λ a b, by { simp, ring, },\n  map_one' := by simp,\n  map_mul' := λ a b, by {\n    have : (↑a.re + ↑a.im * real.sqrt d) * (↑b.re + ↑b.im * real.sqrt d) =\n             ↑a.re * ↑b.re + (↑a.re * ↑b.im + ↑a.im * ↑b.re) * real.sqrt d\n                           + ↑a.im * ↑b.im * (real.sqrt d * real.sqrt d) := by ring,\n    simp [this, real.mul_self_sqrt (int.cast_nonneg.mpr h)],\n    ring, } }\n\n-- Eric Wieser\nabbreviation is_an_integral_domain {α : Type*} [ring α] (s : set α) := ∃ (sr : subring α) [integral_domain sr], s = sr\n\nlemma nine_equals_3_times_3 : (9:ℝ)=(3:ℝ)*(3:ℝ) :=\nbegin\n  linarith,\nend\n\nlemma three_is_gt_0 : (0:ℝ) < (3:ℝ) :=\nbegin\n  linarith,\nend\n\nlemma three_is_gte_0 : (0:ℝ) ≤ (3:ℝ) :=\nbegin\n  linarith,\nend\n\nlemma sqrt_of_9_is_3 : (3:ℝ) = (real.sqrt (9:ℝ)) :=\nbegin\n  have h1 := nine_equals_3_times_3,\n  rw h1,\n  have h2 := three_is_gte_0,\n  have h3 := real.sqrt_mul_self h2,\n  rw ← h1 at h3,\n  rw ← h1,\n  exact eq.symm h3,\nend\n\nlemma half_plus_half_equals_1: (1/2:ℝ)+(1/2:ℝ)=1 :=\nbegin\n  linarith,\nend\n\nlemma x_equals_sqrtx_times_sqrtx (x:ℝ): 0 < x → x = x^(1/2:ℝ) * x^(1/2:ℝ) :=\nbegin\n  intro h1,\n  have h2 := real.rpow_add h1,\n  have h3 := h2 (1/2) (1/2),\n  have h4 := half_plus_half_equals_1,\n  rw h4 at h3,\n  have h5 := real.rpow_one x,\n  rw h5 at h3,\n  exact h3,\nend\n\nlemma x_is_0 (x:ℝ) : x ≥ 0 → ¬(0 < x) → x = 0 :=\nbegin\n  intro h1,\n  intro h2,\n  linarith,\nend\n\nlemma half_ne_0 : (1/2:ℝ)  ≠ (0:ℝ) :=\nbegin\n  linarith,\nend\n\nlemma zero_le_0 : (0:ℝ) ≤ (0:ℝ) :=\nbegin\n  linarith,\nend\n\nlemma sqrt_0_equals_0 : real.sqrt 0 = 0 :=\nbegin\n  have h1 := zero_le_0,\n  exact real.sqrt_eq_zero_of_nonpos h1,\nend\n\nlemma x_gt_0_implies_sqrt_x_gt_0 (x:ℝ): x ≥ 0 → x^(1/2:ℝ) ≥ 0 :=\nbegin\n  intro h1,\n  exact real.rpow_nonneg_of_nonneg h1 (1 / 2),\nend\n\nlemma sqrt_x_equals_sqrt_x (x:ℝ) : x ≥ 0 → x^(1/2:ℝ) = real.sqrt x :=\nbegin\n  intro h,\n  have h1 := x_equals_sqrtx_times_sqrtx x,\n  by_cases h2 : 0 < x,\n  {\n    have h3 := h1 h2,\n    conv\n    begin\n      to_rhs,\n      rw h3,\n    end,\n    have h5 := x_gt_0_implies_sqrt_x_gt_0 x,\n    have h6 := h5 h,\n    have h4 := real.sqrt_mul_self h6,\n    exact eq.symm h4, \n  },\n  {\n    have h3 := x_is_0 x,\n    have h4 := h3 h,\n    have h5 := h4 h2,\n    rw h5,\n    have h6 := @real.zero_rpow (1/2:ℝ),\n    have h7 := half_ne_0,\n    have h8 := h6 h7,\n    rw h8,\n    have h9 := sqrt_0_equals_0,\n    exact eq.symm h9,\n  }\nend\n\nlemma x_mul_x_pow_y_equals_x_pow_y_plus_y (x y : ℝ) : 0 < x → (x * x)^y = x^(y+y) :=\nbegin\n  intro h,\n  have h1 := le_of_lt h,\n  have h2 := @real.mul_rpow x x y h1 h1,\n  rw h2,\n  have h3 := real.rpow_add h y y,\n  exact eq.symm h3,  \nend\n\nlemma fourth_root_of_9_equals_sqrt_sqrt : (9:ℝ) ^ (1/4:ℝ) = real.sqrt (real.sqrt (9:ℝ)) :=\nbegin\n  have h1 := nine_equals_3_times_3,\n  have h2 := three_is_gt_0,\n  have h7 := three_is_gte_0,\n  have h3 := sqrt_of_9_is_3,\n  rw ← h3,\n  rw h1,\n  have h4 := sqrt_x_equals_sqrt_x (3:ℝ),\n  have h5 := h4 h7,\n  rw ← h5,\n  have h6 := x_mul_x_pow_y_equals_x_pow_y_plus_y 3 (1/4),\n  have h8 := h6 h2,\n  rw h8,\n  ring,\nend\n\nlemma fourth_root_of_nine_equals_sqrt_3 : (9:ℝ) ^ (1/4:ℝ) = real.sqrt 3 := \nbegin \n  have h1 := fourth_root_of_9_equals_sqrt_sqrt,\n  rw h1,\n  have h2 := sqrt_of_9_is_3,\n  rw h2,\nend\n\ntheorem ex6e : is_an_integral_domain {x : ℝ | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)} :=\nbegin\n  refine ⟨(zsqrtd.to_real (show 0 ≤ (3 : ℤ), by norm_num)).range, _, _⟩,\n  apply_instance,\n  ext,\n  rw [fourth_root_of_nine_equals_sqrt_3],\n  simp [zsqrtd.to_real],\n  split,\n  {\n    intro h1,\n    cases h1 with a ha,\n    cases ha with b hb,\n    use {re := a, im := b},\n    rw hb,\n  },\n  {\n    intro h1,\n    cases h1 with y hy,\n    rw ← hy,\n    use [y.re, y.im],\n  }\nend\n\nlemma useful : ((9 : ℝ) ^ (4⁻¹ : ℝ)) * (9 ^ (4⁻¹ : ℝ)) = 3 :=\nbegin\n  rw ← mul_rpow,\n  convert pow_nat_rpow_nat_inv (show (0 : ℝ) ≤ 3, by norm_num) (show 0 < 4, by norm_num) using 2,\n  all_goals {norm_num}\nend\n\ndef A : subring ℝ :=\n{ carrier := {x | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)},\n  one_mem' := ⟨1, 0, by simp⟩,\n  mul_mem' := begin\n    rintro _ _ ⟨a1, b1, rfl⟩ ⟨a2, b2, rfl⟩,\n    use [a1 * a2 + 3 * b1 * b2, a1 * b2 + a2 * b1],\n    simp [mul_add, add_mul, mul_assoc, mul_left_comm, useful],\n    ring,\n  end,\n  zero_mem' := ⟨0, 0, by simp⟩,\n  add_mem' := by { rintro _ _ ⟨a1, b1, rfl⟩ ⟨a2, b2, rfl⟩,\n                   use [a1 + a2, b1 + b2],\n                   simp, ring },\n  neg_mem' := by { rintro _ ⟨a, b, rfl⟩,\n                   use [-a, -b],\n                   simp, ring },\n   }\n\ntheorem ex6e_kevin_buzzard : is_an_integral_domain {x : ℝ | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)} :=\n⟨A, infer_instance, rfl⟩\n\ntheorem ex6e_mario_carneiro : is_an_integral_domain {x : ℝ | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)} :=\nbegin\n  refine ⟨(zsqrtd.to_real (show 0 ≤ (3 : ℤ), by norm_num)).range, _, _⟩,\n  apply_instance,\n  ext,\n  rw calc (9:ℝ) ^ (1/4:ℝ) = (9:ℝ)^((2:ℕ)⁻¹ * (1/2) : ℝ) : by norm_num\n    ... = ((3^2:ℝ)^((2:ℕ)⁻¹:ℝ)) ^ (1/2:ℝ) : by rw real.rpow_mul; norm_num\n    ... = real.sqrt 3 : by rw [real.pow_nat_rpow_nat_inv, real.sqrt_eq_rpow]; norm_num,\n  simp [zsqrtd.to_real],\n  exact ⟨λ ⟨x,y,h⟩, ⟨⟨x,y⟩, h.symm⟩, λ ⟨⟨x,y⟩,h⟩, ⟨x,y, h.symm⟩⟩,\nend\n\n-- Exercise 6F\n\n-- Mario Carneiro, Hanting Zhang\nlemma eq_two_pow_of_dvd_two_pow {a n : ℕ} : a ∣ 2 ^ n → ∃ m : ℕ, a = 2 ^ m := \nbegin\n  intro h1,\n  have h2 := (@dvd_prime_pow 2 nat.prime_two n a).1 h1,\n  cases h2 with m hm,\n  cases hm with H hH,\n  finish,\nend\n\nlemma succ_def (m: ℕ) : m.succ = m + 1 := rfl\n\nlemma pow_two_ne_zero (n : ℕ): 2^n ≠ 0 :=\nbegin\n  induction n with d hd,\n  simp,\n  rw (succ_def d),\n  rw (pow_succ 2 d),\n  simp,\n  intro h,\n  finish,\nend \n\n-- Mario Carneiro\nlemma plus_injective {a b : ℚ} {n m : ℕ} (ha : a.denom = 2 ^ n) (hb : b.denom = 2 ^ m) :\n  ∃ k : ℕ, (a + b).denom = 2 ^ k :=\nbegin\n  apply @eq_two_pow_of_dvd_two_pow _ (n + m),\n  rw [rat.add_num_denom, ← int.coe_nat_mul, ha, hb, ← pow_add, ← int.coe_nat_dvd],\n  apply rat.denom_dvd,\nend \n\n-- Mario Carneiro\nlemma mul_injective {a b : ℚ} {n m : ℕ} (ha : a.denom = 2 ^ n) (hb : b.denom = 2 ^ m) :\n  ∃ k : ℕ, (a * b).denom = 2 ^ k :=\nbegin\n  apply @eq_two_pow_of_dvd_two_pow _ (n + m),\n  rw [rat.mul_num_denom, ha, hb, ← pow_add, ← int.coe_nat_dvd],\n  apply rat.denom_dvd,\nend\n\nnoncomputable def B : subring ℚ :=\n{ \n  carrier := {x : ℚ | ∃ n : ℕ, x.denom = 2 ^ n },\n  one_mem' /- (1 : M) ∈ carrier) -/ := \n  begin\n    rw set.mem_set_of_eq,\n    use 0,\n    simp,\n  end,\n  mul_mem' /- {a b} : a ∈ carrier → b ∈ carrier → a * b ∈ carrier) -/ := \n  begin\n    intros a b h1 h2,\n    rw set.mem_set_of_eq at h1,\n    rw set.mem_set_of_eq at h2,\n    cases h1 with n hn,\n    cases h2 with m hm,\n    rw set.mem_set_of_eq,\n    exact (mul_injective hn hm),\n  end,\n  zero_mem' /- (0 : M) ∈ carrier -/ := \n  begin\n    rw set.mem_set_of_eq,\n    use 0,\n    simp,\n    exact rfl,\n  end,\n  add_mem' /- {a b} : a ∈ carrier → b ∈ carrier → a + b ∈ carrier -/:= \n  begin\n    intro a,\n    intro b,\n    intro h1,\n    intro h2,\n    rw set.mem_set_of_eq at h1,\n    rw set.mem_set_of_eq at h2,\n    cases h1 with n hn,\n    cases h2 with m hm,\n    rw set.mem_set_of_eq,\n    exact (plus_injective hn hm),\n  end,\n  neg_mem' /- {x} : x ∈ carrier →d -x ∈ carrier -/:= \n  begin\n    intro x,\n    intro h1,\n    rw set.mem_set_of_eq at h1,\n    cases h1 with n hn,\n    rw set.mem_set_of_eq,\n    use n,\n    simp,\n    exact hn,\n  end,\n }\n\ntheorem ex6f : is_an_integral_domain {x : ℚ | ∃ n : ℕ, x.denom = 2 ^ n }  :=\n⟨B, infer_instance, rfl⟩\n\nnamespace ex7A\n\ninductive R\n| zero\n| one\n\nopen R\n\ndef R.add : R → R → R\n| zero zero := zero\n| zero one := one\n| one zero := one\n| one one := zero\n\ndef R.mul : R → R → R\n| zero zero := zero\n| zero one := zero\n| one zero := zero\n| one one := one\n\ndef R.neg : R → R\n| zero := zero\n| one := one\n\ninstance : has_add R := ⟨R.add⟩\ninstance : has_mul R := ⟨R.mul⟩\ninstance : has_zero R := ⟨zero⟩\ninstance : has_one R := ⟨one⟩\ninstance : has_neg R := ⟨R.neg⟩\n\ntheorem R.exists_pair_ne : ∃ (x y : R), x ≠ y :=\nbegin\n   use [R.zero, R.one],\nend\n\ntheorem R.zero_add (a : R): 0 + a = a := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.add_zero (a : R): a + 0 = a := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.one_mul (a : R): 1 * a = a := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.mul_one (a : R): a * 1 = a := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.add_assoc (a b c : R): a + b + c = a + (b + c) := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\nend\n\ntheorem R.add_left_neg (a : R): -a + a = 0 := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.add_comm (a b : R): a + b = b + a := \nbegin\n   cases a,\n   cases b,\n   repeat { exact rfl },\n   cases b,\n   repeat { exact rfl },\nend\n\ntheorem R.mul_assoc (a b c : R): a * b * c = a * (b * c) := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\nend\n\n\ntheorem R.left_distrib (a b c : R): a * (b + c) = a * b + a * c := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\nend\n\ntheorem R.right_distrib (a b c : R): (a + b) * c = a * c + b * c := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\n   cases b,\n   cases c,\n   repeat { exact rfl },\n   cases c,\n   repeat { exact rfl },\nend\n\ntheorem R.mul_comm (a b : R): a * b = b * a := \nbegin\n   cases a,\n   cases b,\n   repeat { exact rfl },\n   cases b,\n   repeat { exact rfl },\nend\n\ntheorem R.eq_zero_or_eq_zero_of_mul_eq_zero (a b : R) (h: a * b = 0): a = 0 ∨ b = 0:=\nbegin\n   cases a,\n   cases b,\n   left,\n   exact rfl,\n   left,\n   exact rfl,\n   cases b,\n   right,\n   exact rfl,\n   exfalso,\n   finish,   \nend\n\ninstance ex7a_kyle_miller : integral_domain R :=\n{\n  zero := R.zero,\n  one := R.one,\n  add := R.add,\n  mul := R.mul,\n  add_assoc := R.add_assoc,\n  zero_add := R.zero_add,\n  add_zero := R.add_zero,\n  neg := R.neg,\n  add_left_neg := R.add_left_neg,\n  add_comm := R.add_comm,\n  one_mul := R.one_mul,\n  mul_assoc := R.mul_assoc,\n  mul_one := R.mul_one ,\n  left_distrib := R.left_distrib,\n  right_distrib := R.right_distrib,\n  mul_comm := R.mul_comm,\n  exists_pair_ne := R.exists_pair_ne,\n  eq_zero_or_eq_zero_of_mul_eq_zero := R.eq_zero_or_eq_zero_of_mul_eq_zero,\n}\n\ninstance : fact (nat.prime 2) := nat.prime_two\n\n-- this is `@field.to_integral_domain _ (zmod.field 2)` under the hood\ninstance ex7a_eric_wieser : integral_domain (zmod 2) := by apply_instance\n\nend ex7A\n\nnamespace ex7b\n\ninductive R\n| zero\n\nopen R\n\ndef R.add : R → R → R\n| zero zero := zero\n\ndef R.mul : R → R → R\n| zero zero := zero\n\ndef R.neg : R → R\n| zero := zero\n\ninstance : has_add R := ⟨R.add⟩\ninstance : has_mul R := ⟨R.mul⟩\ninstance : has_zero R := ⟨zero⟩\ninstance : has_neg R := ⟨R.neg⟩\n\ntheorem R.zero_add (a : R): 0 + a = a := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.add_zero (a : R): a + 0 = a := \nbegin\n   cases a,\n   repeat { exact rfl },\nend\n\ntheorem R.add_assoc (a b c : R): a + b + c = a + (b + c) := \nbegin\n  cases a,\n  cases b,\n  cases c,\n  refl,\nend\n\ntheorem R.add_left_neg (a : R): -a + a = 0 := \nbegin\n   cases a,\n   refl,\nend\n\ntheorem R.add_comm (a b : R): a + b = b + a := \nbegin\n   cases a,\n   cases b,\n   refl,\nend\n\ntheorem R.mul_assoc (a b c : R): a * b * c = a * (b * c) := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   refl,\nend\n\n\ntheorem R.left_distrib (a b c : R): a * (b + c) = a * b + a * c := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   refl,\nend\n\ntheorem R.right_distrib (a b c : R): (a + b) * c = a * c + b * c := \nbegin\n   cases a,\n   cases b,\n   cases c,\n   refl,\nend\n\ntheorem R.mul_comm (a b : R): a * b = b * a := \nbegin\n   cases a,\n   cases b,\n   refl,\nend\n\ntheorem R.eq_zero_or_eq_zero_of_mul_eq_zero (a b : R) (h: a * b = 0): a = 0 ∨ b = 0:=\nbegin\n  cases a,\n  cases b,\n  left,\n  refl,\nend\n\nend ex7b\n\nlemma ex8a_eric_wieser {S: Type*} [CR: comm_ring S] \n        [NZD: no_zero_divisors S] (h : (0 : S) = 1) : S ≃+* unit :=\nbegin\n  refine ring_equiv.symm _,\n  refine {to_fun := _, inv_fun := _, left_inv := _, right_inv := _, map_mul' := _, map_add' := _},\n  intro h,\n  exact ring.one,\n  intro h1,\n  exact (),\n  rw function.left_inverse,\n  intro x,\n  exact unit.ext,\n  rw function.right_inverse,\n  rw function.left_inverse,\n  intro x,\n  exact eq_of_zero_eq_one h ring.one x,\n  intro u1,\n  intro u2,\n  ring,\n  exact eq_of_zero_eq_one h ring.one (ring.one * ring.one),\n  intro u1,\n  intro u2,\n  exact eq_of_zero_eq_one h ring.one (ring.one + ring.one),\nend\n\ndef is_zero_ring (α : Type u) [ring α] : Prop := ∀ (x : α), x = 0\n\nlemma ex8a_kyle_miller (S : Type u) [comm_ring S] [no_zero_divisors S] :\n  is_integral_domain S ∨ is_zero_ring S :=\nbegin\n  by_cases h: (1:S) ≠ (0:S),\n  fconstructor,\n  refine {exists_pair_ne := _, mul_comm := _, eq_zero_or_eq_zero_of_mul_eq_zero := _},\n  use [0,1],\n  refine ne_comm.mp _,\n  assumption,\n  exact mul_comm,\n  exact λ {a b : S}, mul_eq_zero.mp,\n  refine or.inr _,\n  rw is_zero_ring,\n  refine eq_zero_of_zero_eq_one _,\n  finish,\nend\n \n--exercise 8b: No\n\n-- exercise 9:\n\nnamespace ex9\n\nstructure M := Mk :: (x : ℤ)\n\nopen M \n\ndef M.add (a b : M) := Mk (a.x + b.x)\ndef M.mul (a b : M) := Mk 0\ndef M.neg (a : M) := Mk (-a.x)\ndef M.zero : M := Mk 0\ndef M.one : M := Mk 1\n\ninstance : has_add M := ⟨M.add⟩\ninstance : has_mul M := ⟨M.mul⟩\ninstance : has_zero M := ⟨M.zero⟩\ninstance : has_one M := ⟨M.one⟩\ninstance : has_neg M := ⟨M.neg⟩\n\n@[ext] lemma ext (a b : M) : a.x = b.x → a = b := -- Yakov Pechersky\nby cases a; cases b; simp\n\ntheorem M.zero_add (a : M): (0:M) + a = a := \nbegin\n  ext,\n  unfold has_zero.zero,\n  rw M.zero,\n  unfold has_add.add,\n  rw M.add,\n  simp [int.zero_add],\nend\n\ntheorem M.exists_pair_ne : ∃ (x y : M), x ≠ y :=\nbegin\n   use [M.zero, M.one],\n   rw [M.zero, M.one],\n   simp,\nend\n\ntheorem M.add_zero (a : M): a + 0 = a := \nbegin\n  ext,\n  unfold has_zero.zero,\n  rw M.zero,\n  unfold has_add.add,\n  rw M.add,\n  simp [int.zero_add],\nend\n\ntheorem M.add_assoc (a b c : M): a + b + c = a + (b + c) := \nbegin\n  ext,\n  unfold has_add.add,\n  repeat { rw M.add },\n  finish,\nend\n\ntheorem M.add_left_neg (a : M): -a + a = 0 := \nbegin\n  ext,\n  unfold has_neg.neg,\n  unfold has_add.add,\n  rw M.neg,\n  rw M.add,\n  finish,\nend\n\ntheorem M.add_comm (a b : M): a + b = b + a := \nbegin\n  ext,\n  unfold has_add.add,\n  repeat { rw M.add },\n  finish,\nend\n\ntheorem M.mul_assoc (a b c : M): a * b * c = a * (b * c) := \nbegin\n  ext,\n  unfold has_mul.mul,\n  repeat { rw M.mul },\nend\n\n\ntheorem M.left_distrib (a b c : M): a * (b + c) = a * b + a * c := \nbegin\n  ext,\n  unfold has_mul.mul,\n  unfold has_add.add,\n  repeat { rw M.add },\n  repeat { rw M.mul },\n  finish,\nend\n\ntheorem M.right_distrib (a b c : M): (a + b) * c = a * c + b * c := \nbegin\n  ext,\n  unfold has_mul.mul,\n  unfold has_add.add,\n  repeat { rw M.add },\n  repeat { rw M.mul },\n  finish,\nend\n\ntheorem M.mul_comm (a b : M): a * b = b * a := \nbegin\n  ext,\n  unfold has_mul.mul,\n  repeat { rw M.mul },\nend\n\n  \nlemma M.not_one_mul_or_mul_one: (1:M) * (1:M) ≠ (1:M):=\nbegin\n  unfold has_one.one,\n  unfold has_mul.mul,\n  rw M.one,\n  rw M.mul,\n  finish,\nend\n\nlemma M.not_eq_zero_or_eq_zero_of_mul_eq_zero : ¬∀ (a b : M), a * b = (0:M) → (a = (0:M) ∨ b = (0:M)) :=\nbegin\n  unfold has_mul.mul,\n  unfold has_zero.zero,\n  rw M.zero,\n  simp at *,\n  use (1:M),\n  use (1:M),\n  rw M.mul,\n  split,\n  simp,\n  intro h,\n  simp at *,\n  unfold has_one.one at h,\n  rw M.one at h,\n  simp at h,\n  assumption,\nend \n\nend ex9\n\nnamespace ex10\n\n\ndef g (x: ℤ ) := x / x\ndef f (x: ℤ ) := x - 1\n\nlemma two_minus_one_eq_1 : (2:ℤ)-(1:ℤ) = (1:ℤ) :=\nbegin\n  ring,\nend\n\ntheorem f_ne_zero : ∃ x : ℤ, f x ≠ 0 :=\nbegin\n  use (2:ℤ),\n  rw f,\n  rw two_minus_one_eq_1,\n  finish,\nend\n\ntheorem g_ne_zero : ∃ x : ℤ, g x ≠ 0 :=\nbegin\n  use 1,\n  rw g,\n  simp,\nend\n\ntheorem fg_zero (x : ℕ ) (h: x ≠ 0): (f ∘ g) x = 0 :=\nbegin\n  rw function.comp,\n  simp,\n  rw g,\n  rw f,\n  finish,  \nend\n\nend ex10\n\nend ch1B\n\n-- 1.3. Properties of Ordered Domains\n\n-- Exercises for section 1.3\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 ℤn\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.1_to_1.2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7612756447446676}}
{"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\n! This file was ported from Lean 3 source module analysis.complex.polynomial\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.Complex.Liouville\nimport Mathbin.FieldTheory.IsAlgClosed.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\n\nopen Polynomial\n\nopen Polynomial\n\nnamespace Complex\n\n/-- **Fundamental theorem of algebra**: every non constant complex polynomial\n  has a root -/\ntheorem exists_root {f : ℂ[X]} (hf : 0 < degree f) : ∃ z : ℂ, IsRoot f z :=\n  by\n  contrapose! hf\n  obtain ⟨c, hc⟩ := (f.differentiable.inv hf).exists_const_forall_eq_of_bounded _\n  · obtain rfl : f = C c⁻¹ := Polynomial.funext fun z => by rw [eval_C, ← hc z, inv_inv]\n    exact degree_C_le\n  · obtain ⟨z₀, h₀⟩ := f.exists_forall_norm_le\n    simp only [bounded_iff_forall_norm_le, Set.forall_range_iff, norm_inv]\n    exact ⟨‖eval z₀ f‖⁻¹, fun z => inv_le_inv_of_le (norm_pos_iff.2 <| hf z₀) (h₀ z)⟩\n#align complex.exists_root Complex.exists_root\n\ninstance isAlgClosed : IsAlgClosed ℂ :=\n  IsAlgClosed.of_exists_root _ fun p _ hp => Complex.exists_root <| degree_pos_of_irreducible hp\n#align complex.is_alg_closed Complex.isAlgClosed\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/Polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879432, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7612756430272896}}
{"text": "import tactic\n\n/-\nMaking group theory in a theorem prover\n-/\n\nnamespace mygroup\n\n-- A group needs multiplication, inverse, identity\nclass group (G : Type) extends has_mul G, has_inv G, has_one G :=\n-- axioms go here\n(mul_assoc : ∀ (a b c : G), (a * b) * c = a * (b * c))\n(one_mul : ∀ (a : G), 1 * a = a)\n(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)\n\n\n/-\nnon-example of a group: G is any non-empty set, 1 is any element,\nand define g * h = h, g⁻¹ = 1 for all g\n\nNOT A GROUP because mul_left_inv fails\n-/\n\nnamespace group\n\nattribute [simp] mul_left_inv one_mul\n\nvariables {G : Type} [group G]\n\n-- Students at my uni also learn that mul_one : a * 1 = a and mul_right_inv are axioms\n-- let's prove them!\n\n-- let's start by showing you can cancel on the left\n\n\nlemma mul_left_cancel (a b c : G) (H : a * b = a * c) : b = c :=\ncalc b = 1 * b         : by rw one_mul\n...    = (a⁻¹ * a) * b : by rw mul_left_inv\n...    = a⁻¹ * (a * b) : by rw mul_assoc\n...    = a⁻¹ * (a * c) : by rw H\n...    = (a⁻¹ * a) * c : by rw mul_assoc\n...    = 1 * c         : by rw mul_left_inv\n...    = c             : by rw one_mul\n\n-- that proof is nice to look at\n\nlemma mul_left_cancel' (a b c : G) (H : a * b = a * c) : b = c :=\nby rw [←one_mul b, ←mul_left_inv a, mul_assoc, H, ←mul_assoc, mul_left_inv, one_mul]\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  rw ←mul_assoc,\n  -- ⊢ (a⁻¹ * a) * x = a⁻¹ * y\n  -- know : x = a⁻¹ * y\n  -- simplifier can now do the rest\n  simp [h],\nend\n\n@[simp] lemma mul_one (a : G) : a * 1 = a :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  simp,\nend\n\n-- term mode proof\nlemma mul_one' (a : G) : a * 1 = a :=\nmul_eq_of_eq_inv_mul $ by simp\n\n@[simp] lemma mul_right_inv (a : G) : a * a⁻¹ = 1 :=\nbegin\n  apply mul_eq_of_eq_inv_mul,\n  simp,\nend\n\n@[simp] lemma inv_mul_right_cancel (a b : G) : (b * a⁻¹) * a = b := by simp [mul_assoc]\n@[simp] lemma mul_inv_right_cancel (a b : G) : (b * a) * a⁻¹ = b := by simp [mul_assoc]\n@[simp] lemma inv_mul_left_cancel (a b : G) : a⁻¹ * (a * b) = b := by simp [←mul_assoc]\n\nexample (a b c : G) : a * a⁻¹ * a⁻¹ * a = 1 := by simp\nexample (a b c : G) : a * a⁻¹ * b * a * a⁻¹ = b := by simp\nexample (a b c : G) : a * a⁻¹ * b * c * c⁻¹ * b⁻¹ = 1 := by simp\nexample (a b c : G) : b * c * c⁻¹ * b⁻¹ * a * a⁻¹ = 1 := by simp\n\n\n@[simp] lemma mul_eq_iff_eq_inv_mul {a x y : G} : x = a⁻¹ * y ↔ a * x = y :=\nbegin\n  split,\n  { apply mul_eq_of_eq_inv_mul},\n  { intro h,\n    simp [h.symm]}\nend\n\n@[simp] lemma mul_eq_iff_eq_inv_mul' {a x y : G} : a⁻¹ * y = x ↔ y = a * x :=\nby simp [eq_comm]\n\n@[simp] lemma mul_left_cancel_iff (a b c : G) : a * b = a * c ↔ b = c :=\nbegin\n  split,\n  { apply mul_left_cancel},\n  { rintro rfl, refl}\nend\n\nexample (a b c : G) : a * b * c * (c⁻¹ * a * a⁻¹) = a * c * c⁻¹ * b := by simp\n\n-- this is exactly what the simplifier is good at\n\nend group\n\nstructure subgroup (G : Type) [group G] :=\n-- carrier is the name of the subset\n(carrier : set G)\n(one_mem' : (1 : G) ∈ carrier)\n(inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier)\n(mul_mem' {x y} : x ∈ carrier → y ∈ carrier → x * y ∈ carrier)\n\nnamespace subgroup\n\nvariables {G : Type} [group G] (H J K : subgroup G) (a b c : G)\n\n-- want to be able to say a ∈ H\n\ninstance : has_mem G (subgroup G) := ⟨λ g H, g ∈ H.carrier⟩\n\n-- want to talk about H₁ ≤ H₂ (meanning H₁ ⊆ H₂)\n\n-- \"subgroups of a group form a lattice\"\n\ninstance : has_le (subgroup G) := ⟨λ S T, S.carrier ⊆ T.carrier⟩\n\nlemma le_def (H J : subgroup G) : H.carrier ≤ J.carrier ↔ H ≤ J := iff.rfl\n\n@[ext] theorem ext {H J : subgroup G} (h : ∀ (x : G), x ∈ H ↔ x ∈ J) : H = J :=\nbegin\n  cases H,\n  cases J,\n  suffices : H_carrier = J_carrier,\n    simpa,\n  ext x,\n  exact h x,\nend\n\nlemma mem_coe {g : G} : g ∈ H.carrier ↔ g ∈ H := iff.rfl\n\ntheorem one_mem : (1 : G) ∈ H := H.one_mem'\ntheorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := subgroup.mul_mem' H\ntheorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := subgroup.inv_mem' H\n\n-- definition in Lean because `subgroup` contains data\n/-- \"Theorem\" : intersection of two subgroups is a subgroup -/\ndef inf (H K : subgroup G) : subgroup G :=\n{ carrier := H.carrier ∩ K.carrier,\n  one_mem' := ⟨H.one_mem', K.one_mem'⟩,\n  inv_mem' := λ x ⟨hH, hK⟩, ⟨H.inv_mem' hH, K.inv_mem' hK⟩,\n  mul_mem' := λ x y ⟨hxH, hxK⟩ ⟨hyH, hyK⟩, ⟨H.mul_mem' hxH hyH, K.mul_mem' hxK hyK⟩ }\n\nopen set\n\n-- intersection of any number of subgroups is a subgroup\ndef Infi (ι : Type) (H : ι → subgroup G) : subgroup G :=\n{ carrier := ⋂(i : ι), (H i).carrier,\n  one_mem' := begin\n    rw mem_Inter,\n    intro i,\n    apply subgroup.one_mem',\n  end,\n  inv_mem' := begin\n    intro x,\n    intro hx,\n    rw mem_Inter at hx ⊢,\n    intro i,\n    apply subgroup.inv_mem',\n    tauto!,\n  end,\n  mul_mem' := begin\n    intros x y hx hy,\n    rw mem_Inter at *,\n    intro i,\n    apply subgroup.mul_mem';\n    tauto!,\n  end }\n\n-- why is H bug not fixed?\n\ndef Inf (S : set (subgroup G)) : subgroup G :=\n{ carrier := -- ⋂₀ {H.carrier | H ∈ S},\n             -- ⋂₀ {T : set G | ∃ J ∈ S, T = subgroup.carrier J},\n             Inf (subgroup.carrier '' S),\n  one_mem' := begin\n    rw mem_sInter,\n    rintro t ⟨⟨H_w_carrier, H_w_one_mem', H_w_inv_mem', H_w_mul_mem'⟩, H_h_w, rfl⟩,\n    apply subgroup.one_mem',\n  end,\n  inv_mem' := begin\n    intros x hx,\n    rw mem_sInter at hx ⊢,\n    rintro t ⟨H, H_h_w, rfl⟩,\n    apply H.inv_mem',\n    apply hx,\n    use H,\n    tauto!,\n  end,\n  mul_mem' :=  begin\n    intros x y hx hy,\n    rw mem_sInter at hx hy ⊢,\n    rintro t ⟨H, hH, rfl⟩,\n    apply H.mul_mem',\n    apply hx, use H, tauto,\n    apply hy, use H, tauto,\n  end }\n\ninstance : has_Inf (subgroup G) := ⟨Inf⟩\n\n-- goal -- make subgroups of a group into a complete lattice\n/-\ncomplete_lattice_of_Inf :\n  Π (α : Type u_1) [H1 : partial_order α] [H2 : has_Inf α],\n    (∀ (s : set α), is_glb s (Inf s)) → complete_lattice α\n-/\n\ninstance : partial_order (subgroup G) :=\n{ le := (≤),\n  le_refl := by tidy,\n  le_trans := by tidy,\n  le_antisymm := by tidy }\n\ninstance : complete_lattice (subgroup G) := complete_lattice_of_Inf _ begin\n  intro S,\n    apply @is_glb.of_image _ _ _ _ subgroup.carrier,\n  intros, refl,\n  apply is_glb_Inf,\nend\n\n-- adjoint functor to carrier functor is the span functor\n-- from subsets to subgroups\ndef span (S : set G) : subgroup G := Inf {H : subgroup G | S ⊆ H.carrier}\n\nlemma monotone_carrier : monotone (subgroup.carrier : subgroup G → set G) :=\nλ H J, id\n\nlemma monotone_span : monotone (span : set G → subgroup G) :=\nλ S T h, Inf_le_Inf $ λ H hH x hx, hH $ h hx\n\nlemma subset_span (S : set G) : S ≤ (span S).carrier :=\nbegin\n  rintro x hx _ ⟨H, hH, rfl⟩,\n  exact hH hx,\nend\n\nlemma span_subgroup (H : subgroup G) : span H.carrier = H :=\nbegin\n  ext,\n  split,\n  { intro hx,\n    unfold span at hx,\n    replace hx := mem_sInter.1 hx,\n    apply hx,\n    use H,\n    simp,\n    tauto! },\n  { intro h,\n    apply subset_span,\n    exact h},\nend\n\n-- the functors are adjoint\ndef gi_subgroup : galois_insertion span (@subgroup.carrier G _) :=\ngalois_insertion.monotone_intro monotone_carrier monotone_span subset_span span_subgroup\n\n-- claim : if g ∈ G then the map ℤ → G, n ↦ g^n is a group hom. Duh.\n\n/-- definition of map sending g, n to gⁿ , n ∈ ℕ -/\ndef pow (g : G) : ℕ → G\n| 0 := 1\n| (n+1) := pow n * g -- $6,000,000 : do I do that or g * pow n ??\n\n-- #check nat.iterate\n\n--example {α : Type} (h : α ≃ α) : ℤ → α ≃ α := by hint\n\ndef pow' (g : G) (n : ℕ) := ((*) g)^[n] 1\n\nopen int\n\ndef int.iterate {α : Type} (h : α ≃ α) : ℤ → α → α\n| (of_nat n) := h^[n]\n| (neg_succ_of_nat n) := h.symm^[n+1]\n\nnotation f`^⦃`:91 n`⦄`:91 := int.iterate f n\n\nnamespace int.iterate\n\nvariables {α : Type} (h : α ≃ α)\n\n--example (a b : ℕ) : h^[a+b] = (h^[a]) ∘ (h^[b]) := sorry -- brackets needed\n\n@[simp] lemma zero : h^⦃0⦄ = id := rfl\n@[simp] lemma one : h^⦃1⦄ = h := by funext; refl  --rfl --funext $ λ x, rfl\n@[simp] lemma neg_one : h^⦃-1⦄ = h.symm := funext $ λ x, rfl -- :-)\n\nlemma neg (a : ℤ) : h^⦃-a⦄ = h.symm^⦃a⦄ :=\nbegin\n  cases a,\n  cases a,\n  ext, refl,\n  ext, refl,\n  ext, refl,\nend\n\nexample (i : ℕ) : -[1+ i] = -((i : ℤ) + 1) := by exact neg_succ_of_nat_eq i\n\nlemma add_one (a : ℤ) : h^⦃a+1⦄ = h^⦃a⦄ ∘ h :=\nbegin\n  cases a with i i,\n  { refl},\n  { suffices :  h^⦃(-↑i)⦄ = h^⦃-(i + 1)⦄ ∘ h,\n      convert this, rw neg_succ_of_nat_eq, ring,\n    rw neg,\n    rw neg,\n    ext,\n    norm_cast,\n    have : h.symm^⦃↑i⦄ ∘ h.symm = h.symm^⦃↑(i + 1)⦄,\n      refl,\n    rw ←this,\n    simp},\nend\n\nlemma sub_one (a : ℤ) : h^⦃a-1⦄ = h^⦃a⦄ ∘ h.symm :=\nbegin\n  rw ←neg_one,\n  rw ←h.symm_symm,\n  rw ←neg,\n  rw (show -(a-1)=-a+1, by ring),\n  rw add_one,\n  simp [neg],\nend\n\n\nlemma add (a b : ℤ) : h^⦃a + b⦄ = h^⦃a⦄ ∘ h^⦃b⦄ :=\nbegin\n  apply int.induction_on b,\n  {simp},\n  { intro i,\n    intro useful,\n    rw ←add_assoc,\n    rw add_one,\n    rw useful,\n    rw add_one,\n  },\n  { intro i,\n    intro useful,\n    rw ←add_sub_assoc,\n    rw sub_one,\n    rw useful,\n    rw sub_one,\n  },\nend\n\nend int.iterate\n\n-- def pow_hom (g : G) (a b : ℕ) : pow g a * pow g b = pow g (a + b) :=\n-- begin\n\n--   sorry\n-- end\n\n-- /-- definition of map sending g, n to gⁿ , n ∈ ℤ -/\n-- def zpow (g : G) : ℤ → G\n-- | (of_nat n) := pow g n\n-- | (neg_succ_of_nat n) := pow g⁻¹ (n+1)\n\n--example (g : G) : G ≃ G := by suggest\n\ndef thing (g : G) : G ≃ G :=\n{ to_fun := (* g),\n  inv_fun := (* g⁻¹),\n  left_inv := by intro x; simp,\n  right_inv := by intro x; simp }\n\n  open int.iterate\n\nlemma foo (g j : G) (a : ℤ) : j * (thing g^⦃a⦄ 1) = thing g^⦃a⦄ j :=\nbegin\n  revert j,\n  apply int.induction_on a,\n  { simp},\n  { intro i,\n    intro hi,\n    intro j,\n    rw int.iterate.add_one,\n    unfold function.comp,\n    rw ←hi (thing _ j),\n    rw ←hi,\n    unfold thing, simp [mygroup.group.mul_assoc],\n  },\n  { intro i,\n    intro hi,\n    intro j,\n    rw int.iterate.sub_one,\n    unfold function.comp,\n    conv_rhs begin\n      rw ←hi,\n    end,\n    rw ←hi,\n    unfold thing, simp [mygroup.group.mul_assoc],\n  }\nend\n\ndef zpow' (g : G) : ℤ → G := λ z, (thing g)^⦃z⦄ 1\n\ninstance : has_pow G ℤ := ⟨zpow'⟩\n\nlemma zpow_hom (g : G) (a b : ℤ) : g^a * g^b = g^(a + b) :=\nbegin\n  unfold has_pow.pow,\n  unfold zpow',\n  rw add_comm,\n  rw int.iterate.add,\n  unfold function.comp,\n  rw foo,\nend\n\n\n\n/-- The subgroup generated by an element of a group equals the set of integer number powers of\n    the element. -/\nlemma mem_span_singleton {x y : G} : y ∈ span ({x} : set G) ↔ ∃ n : ℤ, x ^ n = y :=\nbegin\n  sorry\nend\n\n\n\nend subgroup\n\nend mygroup\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/group/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.7612756355622621}}
{"text": "-- El tipo de los números naturales\n-- ================================\n\nimport tactic\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir el tipo Nat de los números\n-- naturales con los constructores Cero (para el número\n-- 0) y Suc (para la función sucesor).\n-- ----------------------------------------------------\n\ninductive Nat : Type\n| Cero : Nat\n| Suc  : Nat → Nat\n\n-- #print prefix Nat\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Abrir el espacio de nimbre de Nat\n-- ----------------------------------------------------\n\nnamespace Nat\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Definir la función\n--    repr : Nat → string\n-- tal que (repr n) es la cadena que representa al\n-- número natural. Por ejemplo,\n--     repr (Suc (Cero)) = \"Suc (Cero)\"\n-- ----------------------------------------------------\n\ndef repr : Nat → string\n| Cero    := \"Cero\"\n| (Suc n) := \"Suc (\" ++ repr n ++ \")\"\n\n-- #eval repr (Suc (Cero)) -- = \"Suc (Cero)\"\n\n-- ----------------------------------------------------\n-- Ejercicio 4. Declarar repr la función para\n-- representar números naturales. Por ejemplo,\n--    #eval Suc (Cero) = Suc (Cero)\n-- ----------------------------------------------------\n\ninstance : has_repr Nat := ⟨repr⟩\n\n-- #eval Suc (Cero) -- = Suc (Cero)\n\n-- ----------------------------------------------------\n-- Ejercicio 5. Definir la función\n--    nat2int : Nat → ℕ\n-- tal que (nat2int n) es el número entero\n-- correspondiente al número natural n. Por ejemplo,\n--    nat2int (Suc (Suc (Suc Cero))) =  3\n-- ----------------------------------------------------\n\ndef nat2int : Nat → ℕ\n| Cero    := 0\n| (Suc n) := 1 + nat2int n\n\n-- #eval nat2int (Suc (Suc (Suc Cero)))\n\n-- ----------------------------------------------------\n-- Ejercicio 6. Definir la función\n--    int2nat : ℕ -> Nat\n-- tal que (int2nat n) es el número natural\n-- correspondiente al número entero n. Por ejemplo,\n--    int2nat 3 = Suc (Suc (Suc (Cero)))\n-- ----------------------------------------------------\n\ndef int2nat : ℕ -> Nat\n| 0     := Cero\n| (n+1) := Suc (int2nat n)\n\n-- #eval int2nat 3 -- ==  Suc (Suc (Suc (Cero)))\n\n-- ----------------------------------------------------\n-- Ejercicio 7. Definir la función\n--    suma : Nat → Nat → Nat\n-- tal que (suma m n) es la suma de los número\n-- naturales m y n. Por ejemplo,\n--    #eval suma (Suc (Suc Cero)) (Suc Cero)\n--    Da: Suc (Suc (Suc (Cero)))\n-- ----------------------------------------------------\n\ndef suma : Nat → Nat → Nat\n| Cero    n := n\n| (Suc m) n := Suc (suma m n)\n\n-- #eval suma (Suc (Suc Cero)) (Suc Cero)\n-- Da: Suc (Suc (Suc (Cero)))\n\n-- ----------------------------------------------------\n-- Ejercicio 8. Declarar lar variables m y n sobre Nat.\n-- ----------------------------------------------------\n\nvariables (m n : Nat)\n\n-- ----------------------------------------------------\n-- Ejercicio 9. Demostrar los siguientes lemas:\n-- + suma_1 :\n--      suma Cero n = n :=\n-- + suma_2 :\n--      suma (Suc m) n = Suc (suma m n) :=\n-- ----------------------------------------------------\n\n@[simp]\nlemma suma_1 :\n  suma Cero n = n :=\nrfl\n\n@[simp]\nlemma suma_2 :\n  suma (Suc m) n = Suc (suma m n) :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 10. Demostrar que\n--    suma n Cero = n\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  suma n Cero = n :=\nbegin\n  induction n with m HI,\n  { rw suma_1, },\n  { rw suma_2,\n    rw HI, },\nend\n\n-- 2ª demostración\nexample :\n  suma n Cero = n :=\nbegin\n  induction n with m HI,\n  { show suma Cero Cero = Cero,\n      by rw suma_1, },\n  { calc suma (Suc m) Cero\n         = Suc (suma m Cero) :by rw suma_2\n     ... = Suc m             :by rw congr_arg Suc HI, },\nend\n\n-- 3ª demostración\nexample :\n  suma n Cero = n :=\nbegin\n  induction n with m HI,\n  { show suma Cero Cero = Cero,\n      by simp, },\n  { calc suma (Suc m) Cero\n         = Suc (suma m Cero) :by simp\n     ... = Suc m             :by simp [HI], },\nend\n\n-- 4ª demostración\nexample :\n  suma n Cero = n :=\nbegin\n  induction n with m HI,\n  { simp, },\n  { simp [HI], },\nend\n\n-- 5ª demostración\nexample :\n  suma n Cero = n :=\nby induction n ; simp [*]\n\n-- 6ª demostración\nexample :\n  suma n Cero = n :=\nNat.rec_on n\n  ( show suma Cero Cero = Cero,\n      by rw suma_1)\n  ( assume m,\n    assume HI: suma m Cero = m,\n    show suma (Suc m) Cero = Suc m, from\n      calc suma (Suc m) Cero\n           = Suc (suma m Cero) :by rw suma_2\n       ... = Suc m             :by rw congr_arg Suc HI)\n\n\n-- 7ª demostración\nexample :\n  suma n Cero = n :=\nNat.rec_on n\n  ( show suma Cero Cero = Cero,\n      by simp)\n  ( assume m,\n    assume HI: suma m Cero = m,\n    show suma (Suc m) Cero = Suc m, from\n      calc suma (Suc m) Cero\n           = Suc (suma m Cero) :by simp\n       ... = Suc m             :by simp [HI])\n\n-- 8ª demostración\nexample :\n  suma n Cero = n :=\nNat.rec_on n\n  ( by simp)\n  ( assume m,\n    assume HI: suma m Cero = m,\n    by simp [HI])\n\n-- 9ª demostración\nexample :\n  suma n Cero = n :=\nNat.rec_on n\n  (by simp)\n  (λ m HI, by simp [HI])\n\n-- 10ª demostración\nlemma suma_Cero :\n  ∀ n, suma n Cero = n\n| Cero    := by simp\n| (Suc m) := by simp [suma_Cero m]\n\n-- ----------------------------------------------------\n-- Ejercicio 11. Cerrar el espacio de nombre Nat.\n-- ----------------------------------------------------\n\nend Nat\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/El_tipo_de_los_numeros_naturales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119663, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.761227692274201}}
{"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`λ + X i` is equal to a linear combination of the symmetric polynomials `esymm σ 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 σ R)`, which enables us to talk about linear combinations of\n`esymm σ 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 polynomial\n\nopen finset polynomial fintype\n\nnamespace mv_polynomial\n\nvariables {R : Type u} [comm_semiring R]\nvariables (σ : Type u) [fintype σ]\n\n/-- A sum version of Vieta's formula. Viewing `X i` as variables,\nthe product of linear terms `λ + X i` is equal to a linear combination of\nthe symmetric polynomials `esymm σ R j`. -/\nlemma prod_X_add_C_eq_sum_esymm :\n  (∏ i : σ, (polynomial.C (X i) + polynomial.X) : polynomial (mv_polynomial σ R) )=\n  ∑ j in range (card σ + 1),\n    (polynomial.C (esymm σ R j) * polynomial.X ^ (card σ - j)) :=\nbegin\n  classical,\n  rw [prod_add, sum_powerset],\n  refine sum_congr begin congr end (λ j hj, _),\n  rw [esymm, map_sum, sum_mul],\n  refine sum_congr rfl (λ t ht, _),\n  have h : (univ \\ t).card = card σ - j :=\n  by { rw card_sdiff (mem_powerset_len.mp ht).1, congr, exact (mem_powerset_len.mp ht).2 },\n  rw [map_prod, prod_const, ← 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 `∑ 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 : σ → R) : ∏ i : σ, (polynomial.C (r i) + polynomial.X) =\n  ∑ i in range (card σ + 1), (∑ t in powerset_len i (univ : finset σ),\n    ∏ i in t, polynomial.C (r i)) * polynomial.X ^ (card σ - i) :=\nbegin\n  classical,\n  have h := @prod_X_add_C_eq_sum_esymm _ _ σ _,\n  apply_fun (polynomial.map (eval r)) at h,\n  rw [polynomial.map_prod, polynomial.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, polynomial.map_sum, map_sum,\n    polynomial.map_C, polynomial.map_pow, polynomial.map_X, polynomial.map_mul],\n  congr,\n  funext,\n  simp only [eval_prod, eval_X, map_prod],\nend\n\nlemma esymm_to_sum (r : σ → R) (j : ℕ) : polynomial.C (eval r (esymm σ R j)) =\n  ∑ t in powerset_len j (univ : finset σ), ∏ i in t, polynomial.C (r i) :=\nby simp only [esymm, eval_sum, eval_prod, eval_X, map_sum, map_prod]\n\n/-- Vieta's formula for the coefficients of the product of linear terms `X + r i`,\nThe `k`th coefficient is `∑ t in powerset_len (card σ - k) (univ : finset σ), ∏ i in t, r i`,\ni.e. the symmetric polynomial `esymm σ R (card σ - k)` of the constant terms `r i`. -/\n\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/vieta.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7612276865459302}}
{"text": "-- Imagen_de_la_diferencia_de_conjuntos.lean\n-- Imagen de la diferencia de conjuntos\n-- José A. Alonso Jiménez\n-- Sevilla, 17 de junio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que\n--    f '' s \\ f '' t ⊆ f '' (s \\ t)\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {α : Type*} {β : Type*}\nvariable  f : α → β\nvariables s t : set α\n\n-- 1ª demostración\n-- ===============\n\nexample : f '' s \\ f '' t ⊆ 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    { intro xt,\n      apply ynft,\n      rw ← fxy,\n      apply mem_image_of_mem,\n      exact xt, }},\n  { exact fxy, },\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : f '' s \\ f '' t ⊆ f '' (s \\ t) :=\nbegin\n  rintros y ⟨⟨x, xs, fxy⟩, ynft⟩,\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ª demostración\n-- ===============\n\nexample : f '' s \\ f '' t ⊆ f '' (s \\ t) :=\nbegin\n  rintros y ⟨⟨x, xs, fxy⟩, ynft⟩,\n  use x,\n  finish,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample : f '' s \\ f '' t ⊆ f '' (s \\ t) :=\nsubset_image_diff f s t\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_diferencia_de_conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7612166697927518}}
{"text": "import data.real.basic\n\n/-!\n\n# Q3 \n\nTake bounded, nonempty `S, T ⊆ ℝ`.\nDefine `S + T := { s + t : s ∈ S, t ∈ T}`.\nProve `sup(S + T) = sup(S) + sup(T)`\n\n-/\n\n-- useful for rewriting\ntheorem is_lub_def {S : set ℝ} {a : ℝ} :\n  is_lub S a ↔ a ∈ upper_bounds S ∧ ∀ x, x ∈ upper_bounds S → a ≤ x :=\nbegin\n  refl\nend\n\n#check mem_upper_bounds -- a ∈ upper_bounds S ↔ ∀ x, x ∈ S → x ≤ a\n\n/-\nUseful tactics for this one: push_neg, specialize, have\n-/\ntheorem useful_lemma {S : set ℝ} {a : ℝ} (haS : is_lub S a) (t : ℝ)\n  (ht : t < a) : ∃ s, s ∈ S ∧ t < s :=\nbegin\n  by_contradiction,\n  push_neg at h,\n  rw is_lub_def at haS,\n  rw ← mem_upper_bounds at h,\n  cases haS with h1 h2,\n  specialize h2 t h,\n  linarith,\nend\n\n/-\nUseful tactics for this one:\n`rcases h with ⟨s, t, hsS, htT, rfl⟩` if h : x ∈ S + T\n`linarith`\n`by_contra`\n`set ε := a + b - x with hε`\n-/\ntheorem Q3 (S T : set ℝ) (a b : ℝ) :\n  is_lub S a → is_lub T b → is_lub (S + T) (a + b) :=\nbegin\n  intros h1 h2,\n  have h1':=h1,\n  have h2':=h2,\n  cases h1 with h3 h4,\n  cases h2 with h5 h6,\n  rw is_lub_def,\n  rw mem_lower_bounds at *,\n  rw mem_upper_bounds at *,\n  split;\n  intros x h8,\n  rcases h8 with ⟨ s,t,hsS,htT,rfl⟩,\n  specialize h5 t,\n  specialize h3 s,\n  have htb:= h5 htT,\n  have hsa:= h3 hsS,\n  linarith,\n\n  rw mem_upper_bounds at *,\n  by_contradiction,\n  push_neg at h,\n  set ε := a + b - x with hε,\n  have h9: a - ε / 100 <a,\n  linarith,\n  have hb: b - ε / 100<b,\n  linarith,\n  have h10:= useful_lemma h1' (a-ε/100) _,\n  rcases h10 with ⟨s, hs1, hs2⟩,\n  have h11:= useful_lemma h2' (b-ε/100) _,\n  rcases h11 with ⟨t, ht1, ht2⟩,\n  specialize h5 t,\n  specialize h3 s,\n  have htb:= h5 ht1,\n  have hsa:= h3 hs1,\n  specialize h8 (s+t),\n  have hst: s + t ∈ S + T,\n  split,\n  use t,\n  split,\n  assumption,\n  split,\n  assumption,\n  refl,\n  have h11:= h8 hst,\n  linarith,\n  linarith,\n  linarith,\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\n/-\nUseful for this one: `unfold`, `split_ifs` if you want to prove\nfrom first principles, or guessing the name of the library function\nif you want to use the library.\n-/\ntheorem Q6a (x y : ℝ) : | x + y | ≤ | x | + | y | :=\nbegin\n  exact abs_add x y,\nend\n\n-- all the rest you're supposed to do using Q6a somehow:\n-- `simp` and `linarith` are useful.\n\ntheorem Q6b (x y : ℝ) : |x + y| ≥ |x| - |y| :=\nbegin\n  have h:= Q6a,\n  rw ge_iff_le,\n  specialize h (x+y) (-y),\n  simp at h,\n  linarith,\nend\n\ntheorem Q6c (x y : ℝ) : |x + y| ≥ |y| - |x| :=\nbegin\n  have h:= Q6a,\n  rw ge_iff_le,\n  specialize h (-x) (x+y),\n  simp at h,\n  linarith,\nend\n\ntheorem Q6d (x y : ℝ) : |x - y| ≥ | |x| - |y| | :=\nbegin\n  rw ge_iff_le,\n  have h: |x| -|y|<0 ∨ 0≤ |x| - |y|,\n  exact lt_or_ge _ 0,\n  cases h,\n  rw abs_of_neg h,\n  simp,\n  have h2:= Q6c,\n  specialize h2 x (-y),\n  simp at h2,\n  have h3: x+-y = x-y,\n  ring,\n  rwa h3 at h2,\n  rw abs_of_nonneg h,\n  have h2:= Q6c,\n  specialize h2 y (-x),\n  simp at h2,\n  ring at h2,\n  exact abs_sub_abs_le_abs_sub x y,\nend\n\ntheorem Q6e (x y : ℝ) : |x| ≤ |y| + |x - y| :=\nbegin\n  have h2:= Q6a,\n  specialize h2 (x-y) (y),\n  ring at h2,\n  linarith,\nend\n\ntheorem Q6f (x y : ℝ) : |x| ≥ |y| - |x - y| :=\nbegin\n  have h2:= Q6a,\n  rw ge_iff_le,\n  specialize h2 x (y-x),\n  ring at h2,\n  have h3: abs(x-y) = abs(y-x),\n  apply abs_sub x y,\n  rw h3,\n  linarith,\nend\n\ntheorem Q6g (x y z : ℝ) : |x - y| ≤ |x - z| + |y - z| :=\nbegin\n  have h2:=Q6a,\n  specialize h2 (x-z) (z-y),\n  ring at h2,\n  have h3: abs(y-z) = abs(z-y),\n  apply abs_sub y z,\n  rwa h3,\nend\n\n\n\n/-!\n\n# Q4\n\nNOTE: I have not done this one myself -- some lemmas could be wrong!\nI just copied directly from the problem sheet and you know how\nsloppy mathematicians are...\n\n\nFix `a ∈ (0,∞)` and `n : ℕ`. We will prove\n`∃ x : ℝ, x^n = a`. \n\n-/\n\nsection Q4\n\nnoncomputable theory\n\nparameters {a : ℝ} (ha : 0 < a) {n : ℕ} (hn : 0 < n)\n\n/-\n1) Set `Sₐ := {s ∈ [0,∞) : s^n < a}` and show `Sₐ` is nonempty and\nbounded above, so we may define `x := sup Sₐ`.\n-/\n\ndef S := {s : ℝ | 0 ≤ s ∧ s ^ n < a}\n\ninclude ha hn\n\ntheorem part1 : (∃ s : ℝ, s ∈ S) ∧ (∃ B : ℝ, ∀ s ∈ S, s ≤ B ) :=\nsorry\n\ndef x := Sup S\n\n-- the sup is the least upper bound\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 `ε ∈ (0,1)` show `(x+ε)ⁿ ≤ x^n + ε[(x + 1)ⁿ − xⁿ].`\n(Hint: multiply out.)\n-/\n\n-- I'm pretty sure this is needed\nlemma x_nonneg : 0 ≤ x :=\nbegin\n  rcases is_lub_x with ⟨h, -⟩,\n  apply h,\n  split, refl,\n  convert ha,\n  simp [hn],\nend\n\ntheorem part2 (ε : ℝ) (hε0 : 0 < ε) (hε1 : ε < 1) : (x + ε)^n ≤ x^n + ε*((x+1)^n - x^n) :=\nbegin\n  sorry\nend\n\n/-\n3) Hence show that if `xⁿ < a` then\n`∃ ε ∈ (0,1)` such that `(x+ε)ⁿ < a.` (*)\n-/\n\ntheorem part3 (h : x ^ n < a) : ∃ ε : ℝ, 0 < ε ∧ ε < 1 ∧ (x+ε)^n < a :=\nbegin\n  sorry\nend\n\n/-\n4) If `xⁿ > a`, deduce from (∗) that\n`∃ ε ∈ (0,1)` such that `(1/x+ε)ⁿ < 1/a`. (∗∗)\n-/\n\n-- part 4 doesn't quite make sense because we didn't show x ≠ 0 yet\n\nlemma easy (h : a < x^n) : x ≠ 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) : ∃ ε : ℝ, 0 < ε ∧ ε < 1 ∧ (1/x + ε)^n < 1/a :=\nbegin\n  sorry\nend\n\n/-\n5) Deduce contradictions from (∗) and (∗∗) to show that `xⁿ = a`.\n-/\n\ntheorem part5 : x^n = a :=\nbegin\n  sorry\nend\n\nend Q4", "meta": {"author": "DeeproChoudhury", "repo": "Analysis", "sha": "1cfb1c9dd66e1ef316db5d3409262c6448e7e7e5", "save_path": "github-repos/lean/DeeproChoudhury-Analysis", "path": "github-repos/lean/DeeproChoudhury-Analysis/Analysis-1cfb1c9dd66e1ef316db5d3409262c6448e7e7e5/src/problem_sheet_two.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813454, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7612166691963687}}
{"text": "import .list\nimport algebra.geom_sum\nimport analysis.specific_limits\n\nlemma geom_sum_of_sum_of_range_map {α} [semiring α] (x: α) (n: ℕ):\n  list.sum (list.map (pow x) (list.range n)) = geom_sum x n :=\nbegin\n  induction n with d hd,\n  { simp only [list.sum_nil, geom_sum_zero, list.range_zero, list.map] },\n  { simp [geom_sum, finset.range, list.range_succ, add_comm, hd] },\nend\n\nlemma geom_sum_of_sum_of_map_with_index {α} [semiring α] (x: α) (l: list α):\n  list.sum (l.map_with_index (λ i a, x ^ i)) = geom_sum x (l.length) :=\nby simp [← geom_sum_of_sum_of_range_map x (l.length), list.map_with_index_eq_range_map (λ i a, x ^ i) (λ i, x ^ i)]\n\nlemma real.finite_geom_sum_le_infinite_geom_sum_of_abs_lt_1\n  {x: ℝ} (n: ℕ) (x_nonneg: 0 ≤ x) (h: abs x < 1):\n  geom_sum x n ≤ ∑' k: ℕ, x ^ k :=\nbegin\n  apply sum_le_tsum,\n  simp,\n  intros m hm,\n  exact pow_nonneg x_nonneg m,\n  exact summable_geometric_of_abs_lt_1 h,\nend\n\nlemma real.finite_geom_sum_le_infinite_geom_sum_of_lt_1\n  {x: ℝ} (n: ℕ) (x_nonneg: 0 ≤ x) (h: x < 1):\n  geom_sum x n ≤ ∑' k: ℕ, x ^ k :=\nbegin\n  rw ← abs_eq_self.2 x_nonneg at h,\n  exact real.finite_geom_sum_le_infinite_geom_sum_of_abs_lt_1 n x_nonneg h,\nend\n\n-- can be generalized to 'semifield', but we do not have them.\nlemma geom_sum_eq_factor_inv_geom_sum\n  {α} [field α]\n  {x: α} (n: ℕ) (hx_ne_0: x ≠ 0) (hx_ne_1: x ≠ 1):\n  geom_sum x (n + 1) = (x ^ n) * geom_sum (x⁻¹) (n + 1) :=\nbegin\n  rw [geom_sum_eq hx_ne_1, geom_sum_inv hx_ne_1 hx_ne_0],\n  rw [← mul_assoc, div_eq_mul_inv],\n  exact calc (x ^ (n + 1) - 1) * (x - 1)⁻¹ = (x - 1)⁻¹ * (x ^ (n + 1) - 1) : mul_comm _ _\n  ... = (x - 1)⁻¹ * (x ^ n * x - 1) : by rw pow_succ' x n\n  ... = (x - 1)⁻¹ * (x ^ n * x - x ^ (-n: ℤ) * x ^ (n: ℤ)) : by rw [fpow_neg_mul_fpow_self n hx_ne_0]\n  ... = (x - 1)⁻¹ * (x ^ n * x - x ^ n * x ^ (-n: ℤ)) : by norm_cast; ring_nf\n  ... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ n) : by rw [← mul_sub_left_distrib _ _ _, ← mul_assoc]; simp [inv_fpow]\n  ... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ n * 1) : by rw mul_one (x⁻¹ ^ n)\n  ... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ n * (x⁻¹ * x)) : by rw inv_mul_cancel hx_ne_0\n  ... = (x - 1)⁻¹ * x ^ n * (x - x⁻¹ ^ (n + 1) * x)  : by rw [← mul_assoc, pow_succ' x⁻¹ n]\n  ... = x ^ n * (x - 1)⁻¹ * (x - x⁻¹ ^ (n + 1) * x) : by ac_refl,\nend", "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/geom_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7612166524184222}}
{"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 𝕜 be a field equipped with a non-trivial norm (e.g. ℝ)\nvariables (𝕜 : Type) [nontrivially_normed_field 𝕜] \n\n-- Let `E` be a 𝕜-vector space with a norm (e.g. ℝ or ℝ²)\nvariables (E : Type) [normed_add_comm_group E] [normed_space 𝕜 E]\n\n-- and let `F` be another one\nvariables (F : Type) [normed_add_comm_group F] [normed_space 𝕜 F]\n\n-- Then it makes sense to say that a function `f : E → F` is differentiable\nvariable (f : E → F)\n\n-- This is the true-false statement that `f` is differentiable.\nexample : Prop := differentiable 𝕜 f\n\n-- You can also ask that `f` is differentiable at `e : E`\n\nexample (e : E) : Prop := differentiable_at 𝕜 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 𝕜 37 f\n\n-- Here's how you say \"`f` is smooth, i.e. infinitely differentiable\"\n\nexample : Prop := cont_diff 𝕜 ⊤ f\n\n-- That's `⊤` as in \"the top element of a lattice\" as in `+∞`, not `T` as in \"the letter T\".\n-- Indeed, `cont_diff 𝕜` takes an element of `ℕ∞`.\n\nend differentiability_in_general\n\n-- Let's now just assume `𝕜 = ℝ`; then `E` and `F` can be `ℝ` or `ℂ` or `ℝ × ℝ` or `fin n → ℝ` (the\n-- way we say `ℝⁿ` 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\"\n-- Hint: the theorems are called theorems like `differentiable.mul` etc.\n-- Try proving it by hand.\n\nexample : differentiable ℝ (λ x, cos (sin x) * exp x) :=\nbegin\n  sorry,\nend\n\n-- Now see what `hint` has to say!\nexample : differentiable ℝ (λ x, cos (sin x) * exp x) :=\nbegin\n  sorry,\nend\n\n-- The simplifier can even do this sort of thing:\nexample (x : ℝ) : deriv (λ 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 : ℝ) (x : ℝ) : differentiable_at ℝ (λ (y : ℝ), exp (-(a * y ^ 2))) x :=\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/section17curves_and_surfaces/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.761196196750479}}
{"text": "-- 4.6\n\nnamespace section_4_6_1\n    variables (α : Type) (p q : α → Prop)\n\n    example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := \n    iff.intro\n        (assume h : ∀ x, p x ∧ q x,\n        have r1 : (∀ x, p x), from (λ x, and.elim_left (h x)),\n        have r2 : (∀ x, q x), from (λ x, and.elim_right (h x)),\n        show (∀ x, p x) ∧ (∀ x, q x), from ⟨ r1, r2 ⟩\n        )\n        (assume h : (∀ x, p x) ∧ (∀ x, q x),\n        have h1 : (∀ x, p x), from and.elim_left h,\n        have h2 : (∀ x, q x), from and.elim_right h,\n        λ x, and.intro (h1 x) (h2 x)\n        )\n    example : \n    (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := \n    begin\n        assume h,\n        assume pu,\n        assume x,\n        from h x (pu x)\n    end\n    example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := \n    begin\n        assume h,\n        assume x,\n        from (or.elim h\n        (assume pu, or.intro_left _ (pu x))\n        (assume qu, or.intro_right _ (qu x))\n        )\n    end\nend section_4_6_1\n\nnamespace section_4_6_2\n    variables (α : Type) (p q : α → Prop)\n    variable r : Prop\n\n    example : α → ((∀ x : α, r) ↔ r) := \n      assume x,\n      iff.intro\n        (λ rp, rp x)\n        (λ r x, r)\n    example : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r := \n      iff.intro\n        (λ h, classical.by_contradiction \n          (assume nh2,\n          nh2 (or.intro_left _ \n          (assume x,\n          or.elim (h x)\n            (λ x, x)\n            (λ r, false.elim (nh2 (or.intro_right _ r)))\n          ))\n          ))\n        (λ h,\n        or.elim h\n          (λ pu x, or.intro_left _ (pu x))\n          (λ r x, or.intro_right _ r))\n    example : (∀ x, r → p x) ↔ (r → ∀ x, p x) := \n        iff.intro\n            (λ h r x, h x r)\n            (λ h r x, h x r)\nend section_4_6_2\n\nnamespace section_4_6_3\n    variables (men : Type) (barber : men)\n    variable  (shaves : men → men → Prop)\n\n    example (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) :\n    false := (\n        let weird := h barber in\n        let A := shaves barber barber in\n        let o : ¬ A := (λ s, weird.mp s s) in\n        o (weird.mpr o)\n    )\nend section_4_6_3\n\n\nnamespace section_4_6_4\n    namespace hidden\n\n    def divides (m n : ℕ) : Prop := ∃ k, m * k = n\n\n    instance : has_dvd nat := ⟨divides⟩\n\n    def even (n : ℕ) : Prop := 2 ∣ n\n\n    section\n    variables m n : ℕ\n\n    #check m ∣ n\n    #check m^n\n    #check even (m^n +3)\n    end\n\n    end hidden\n\n    def prime (n : ℕ) : Prop := \n        (¬ n = 1) ∧ (∀ d, d ∣ n → d = 1 ∨ d = n)\n\n    def infinitely_many_primes : Prop := \n        ∀ t, ∃ n, n > t ∧ prime n\n\n    def Fermat_prime (n : ℕ) : Prop :=\n        (∃ (k : ℕ), n = 2 ^ (2 ^ k)) ∧ prime n\n\n    def infinitely_many_Fermat_primes : Prop :=\n        ∀ t, ∃ n, n > t ∧ Fermat_prime n\n\n    def goldbach_conjecture : Prop := \n        ∀ x, x > 2 → ∃ a b, prime a ∧ prime b ∧ x = a + b\n\n    def Goldbach's_weak_conjecture : Prop :=\n        ∀ x, x > 5 → (¬ hidden.even x)\n        → ∃ a b c, prime a ∧ prime b ∧ prime c ∧ x = a + b + c\n\n    def Fermat's_last_theorem : Prop := \n        ¬ ∃ (a b c n : ℕ), n > 2 ∧ a ^ n + b ^ n = c ^ n\n\nend section_4_6_4\n\nnamespace section_4_6_5\n    variables (α : Type) (p q : α → Prop)\n    variable a : α\n    variable r : Prop\n\n    example : (∃ x : α, r) → r :=\n        λ ex, exists.elim ex (λ _ r, r)\n    example : r → (∃ x : α, r) :=\n        λ r, exists.intro a r\n    example : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r :=\n        iff.intro\n            (λ ex, exists.elim ex (λ x ⟨ px, r ⟩, \n                and.intro \n                    (exists.intro x px)\n                    r\n            ))\n            (λ ⟨ px, r ⟩, \n                exists.elim px (λ x px,\n                    exists.intro x ⟨ px, r ⟩\n                )\n            )\n    example : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=\n        iff.intro\n            (assume ⟨ x, pqx ⟩,\n                or.elim pqx \n                    (λ px,\n                        or.intro_left _\n                            (exists.intro _ px))\n                    (λ qx, \n                        or.intro_right _\n                            (exists.intro _ qx))\n                    )\n            (λ x, or.elim x\n                (λ ⟨ x , px ⟩, ⟨ x, or.intro_left _ px ⟩)\n                (λ ⟨ x , qx ⟩, ⟨ x, or.intro_right _ qx ⟩)\n            )\n\n    example : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := iff.intro \n        (λ pu enp, \n            exists.elim enp\n                (λ x npx, npx (pu x)))\n        (λ nenp x, \n            classical.by_contradiction\n                (λ npx, \n                    nenp ⟨ x, npx ⟩)\n        )\n        \n    example : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := iff.intro\n        (λ ⟨ x , px ⟩ unpx, unpx x px)\n        (λ nunp, \n            classical.by_contradiction (λ nep, \n                nunp (λ x px, nep ⟨ x, px ⟩)))\n    example : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := iff.intro\n        (λ nep x px, nep ⟨ x, px ⟩)\n        (λ unp ⟨ x , px ⟩, unp x px)\n    example : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := iff.intro\n        (λ nup, \n            classical.by_contradiction (λ nenp, \n                nup (λ x, \n                    classical.by_contradiction (\n                        λ np, \n                            nenp ⟨ x , np ⟩\n                    )\n                )\n            ))\n         (λ ⟨ x , npx ⟩ pu, npx (pu x))\n\n    example : (∀ x, p x → r) ↔ (∃ x, p x) → r := \n        iff.intro\n            (λ upxr ⟨ x, px ⟩, upxr x px)\n            (λ epxr x px, epxr ⟨ x, px ⟩)\n\n    lemma univ_or_counterexample : (∀ x, p x) ∨ (∃ x, ¬ p x) :=\n        or.elim (classical.em (∃ x, ¬ p x))\n            (λ ex, or.intro_right _ ex)\n            (λ nex, or.intro_left _ (λ x, \n                classical.by_contradiction (λ np, nex ⟨ _ , np ⟩)))\n\n    example : (∃ x, p x → r) ↔ (∀ x, p x) → r := \n        iff.intro\n            (λ ⟨ x , pxr ⟩ pu, pxr (pu x))\n            (λ pur, \n                or.elim\n                    (univ_or_counterexample _ p)\n                    (λ univ, ⟨ a, λ _, pur univ ⟩)\n                    (λ ⟨ x , np ⟩, ⟨ x, λ px, false.elim (np px) ⟩)\n                )\n    example : (∃ x, r → p x) ↔ (r → ∃ x, p x) := \n        iff.intro\n            (λ ⟨ x, rpx ⟩ r, ⟨ x , rpx r ⟩)\n            (λ rex, \n                or.elim (classical.em r)\n                    (λ r, \n                        let ⟨ x, px ⟩ := rex r in\n                        ⟨ x, λ _, px ⟩\n                        )\n                    (λ nr,\n                        ⟨ a, λ r, false.elim (nr r) ⟩\n                    )\n                )\nend section_4_6_5\n\nnamespace section_4_6_6\n    variables (real : Type) [ordered_ring real]\n    variables (log exp : real → real)\n    variable  log_exp_eq : ∀ x, log (exp x) = x\n    variable  exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x\n    variable  exp_pos    : ∀ x, exp x > 0\n    variable  exp_add    : ∀ 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    calc\n        log (x * y) = log (x * y) : rfl\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 : log_exp_eq _\n    \nend section_4_6_6\n\n\nnamespace section_4_6_7\n    #check sub_self\n\n    example (x : ℤ) : x * 0 = 0 :=\n    calc\n        x * 0\n            = x * (0 - 0) : eq.refl _\n        ... = x * 0 - x * 0 : by rewrite mul_sub\n        ... = 0 : by rewrite sub_self\n\nend section_4_6_7\n\nnamespace section_5_8\n  example (p q : Prop) (hp : p) (hq : q) : p ∧ q :=\n  begin\n    split;\n    assumption\n  end\n  example (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=\n  begin\n    split;\n    try { split };\n    assumption\n  end\n\n  meta def search : tactic unit :=\n    (tactic.assumption <|> (tactic.left >> search) <|> (tactic.right >> search))\n\n  example (p q r : Prop) (hp : p) :\n    (p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) :=\n    begin\n      repeat { split }; search\n    end\nend section_5_8\n\nnamespace section_6\nsection\n  variables x y : ℕ\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]\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\nend section_6\n\nsection\n\n  def t : Type := nat\n  def nat.dvd (m n : ℕ) : Prop := ∃ k, n = m * k\n\n  def has_dvd_t : has_dvd t := ⟨nat.dvd⟩\n\n  def f : t := (5 : nat)\n\nend\n\nset_option pp.beta true\n", "meta": {"author": "Rotsor", "repo": "brainfuck", "sha": "3e6f30f298b8ba76d0bc71b8b5a47cedaf2f0b97", "save_path": "github-repos/lean/Rotsor-brainfuck", "path": "github-repos/lean/Rotsor-brainfuck/brainfuck-3e6f30f298b8ba76d0bc71b8b5a47cedaf2f0b97/lean/src/tutorial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7611961792020471}}
{"text": "-- begin header\nimport tactic.linarith\nimport data.real.basic\n\nnoncomputable theory\nlocal attribute [instance, priority 0] classical.prop_decidable\n\nlocal notation `|` x `|` := abs x\n-- end header\n\n/- Section\nSequences, subsequences, and monotonic subsequences.\n-/\n\n/- Sub-section\nDefinitions\n-/\n\n/-\nWe model a sequence $a₀, a₁, a₂, \\dots$ of real numbers as a function\nfrom $ℕ := \\{0,1,2,\\dots\\}$ to $ℝ$, sending $n$ to $a_n$. We sometimes write such\na sequence as $(a_n)_{n≥0}$ or just $(a_n)$.\n-/\n\n/- Definition\nA sequence $(a_n)$ is *increasing* if forall $n∈ℕ$ we have $a_n≤a_{n+1}$. Note that equality\nis allowed here -- so for example the sequence $3, 3, 3, 3, …$ is increasing. A sequence is\n*strictly increasing* if for all $n∈ℕ$ we have $a_n<a_{n+1}$; constant sequences\nare not strictly increasing. \n-/\ndef is_increasing {X : Type*} [has_le X] (a : ℕ → X) : Prop :=\n∀ n : ℕ, a n ≤ a (n + 1)\ndef is_strictly_increasing {X : Type*} [has_lt X] (a : ℕ → X) : Prop :=\n∀ n : ℕ, a n < a (n + 1)\n/- Definition\nSimilarly a sequence $(a_n)$ is *decreasing* if $∀ n∈ℕ, a_{n+1}≤ a_n$ and is\n*strictly decreasing* if $∀ n∈ℕ, a_{n+1}<a_n$.\n-/\ndef is_decreasing {X : Type*} [has_le X] (a : ℕ → X) : Prop :=\n∀ n : ℕ, a (n + 1) ≤ a n\ndef is_strictly_decreasing {X : Type*} [has_lt X] (a : ℕ → X) : Prop :=\n∀ n : ℕ, a (n + 1) < a n\n/-\nA *subsequence* of a sequence $(a_n)$ is a sequence $(b_m)$ of the form\n$a_{k_0}$, $a_{k_1}$, $a_{k_2}$, where the indices $0≤ k_0<k_1<k_2<…$ are strictly increasing.\n-/\ndef is_subsequence {X : Type*} (a : ℕ → X) (b : ℕ → X) :=\n∃ k : ℕ → ℕ, is_strictly_increasing k ∧ ∀ n, a (k n) = b n\n/-\nWe are going to show that any sequence contains either a strictly increasing subsequence,\nor a decreasing sequence [Does this have a name?]. The strategy of the proof is to\nconsider so-called peaks of the sequence. A *peak* of a sequence $(a_n)$ is an index\n$i∈ℕ$ such that $a_i$ is at least as large as subsequent members of the sequence.\n-/\n/- Definition\nA *peak* of a sequence $(a_n)$ is $i∈ℕ$ such that $∀ j≥ i, $a_j≤ a_i$.\n-/\ndef is_peak (a : ℕ → ℝ) (i : ℕ) : Prop :=\n∀ j, i ≤ j → a j ≤ a i\n/-\nFor any sequence, consider the set of peaks. It is clearly either finite or infinite.\nLet us formally state this in a more convenient form.\n-/\n/- Lemma\nIf $(a_n)$ is a sequence, then either there exists $N∈ℕ$ such that all peak $i$\nof $(a_n)$ satisfy $i≤N$, or for all $N∈ℕ$ there exists a peak $i$ of $(a_n)$ with $i>N$.\n-/\nlemma finite_or_infinite_peaks (a : ℕ → ℝ) :\n(∃ N, ∀ i, is_peak a i → i ≤ N) ∨ (∀ N, ∃ i, is_peak a i ∧ i > N) :=\nby simpa [not_forall] using classical.em (∃ N, ∀ i, is_peak a i → i ≤ N)\n\n/- Lemma\nIf there are infinitely many peaks for a sequence $(a_n)$, then the peaks\nform a decreasing subsequence.\n-/\nlemma decreasing_subsequence_of_infinite_peaks (a : ℕ → ℝ) \n(h : ∀ N, ∃ i, is_peak a i ∧ i > N) :\n∃ b : ℕ → ℝ, is_subsequence a b ∧ is_strictly_decreasing b :=\nbegin\n  choose f hf using h,\n  let k : ℕ → ℕ := λ n, nat.rec_on n (f 0) (λ n kn, f kn),\n  use (λ n, a (k n)),  \n  split,\n  { use k,\n    split,swap,intro,refl,\n    sorry },\n  { \n    sorry },\nend\n\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/monotone_formatted.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7611264413616823}}
{"text": "/-\nCopyright (c) 2022 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel\n\n! This file was ported from Lean 3 source module measure_theory.covering.one_dim\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.Covering.DensityTheorem\nimport Mathbin.MeasureTheory.Measure.HaarLebesgue\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\n\nopen Set MeasureTheory IsDoublingMeasure Filter\n\nopen Topology\n\nnamespace Real\n\ntheorem Icc_mem_vitaliFamily_at_right {x y : ℝ} (hxy : x < y) :\n    Icc x y ∈ (VitaliFamily (volume : Measure ℝ) 1).setsAt x :=\n  by\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] <;> linarith\n#align real.Icc_mem_vitali_family_at_right Real.Icc_mem_vitaliFamily_at_right\n\ntheorem tendsto_Icc_vitaliFamily_right (x : ℝ) :\n    Tendsto (fun y => Icc x y) (𝓝[>] x) ((VitaliFamily (volume : Measure ℝ) 1).filterAt x) :=\n  by\n  refine' (VitaliFamily.tendsto_filterAt_iff _).2 ⟨_, _⟩\n  · filter_upwards [self_mem_nhdsWithin]with y hy using Icc_mem_vitali_family_at_right hy\n  · intro ε εpos\n    have : x ∈ Ico x (x + ε) := ⟨le_refl _, by linarith⟩\n    filter_upwards [Icc_mem_nhdsWithin_Ioi this]with y hy\n    rw [closed_ball_eq_Icc]\n    exact Icc_subset_Icc (by linarith) hy.2\n#align real.tendsto_Icc_vitali_family_right Real.tendsto_Icc_vitaliFamily_right\n\ntheorem Icc_mem_vitaliFamily_at_left {x y : ℝ} (hxy : x < y) :\n    Icc x y ∈ (VitaliFamily (volume : Measure ℝ) 1).setsAt y :=\n  by\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] <;> linarith\n#align real.Icc_mem_vitali_family_at_left Real.Icc_mem_vitaliFamily_at_left\n\ntheorem tendsto_Icc_vitaliFamily_left (x : ℝ) :\n    Tendsto (fun y => Icc y x) (𝓝[<] x) ((VitaliFamily (volume : Measure ℝ) 1).filterAt x) :=\n  by\n  refine' (VitaliFamily.tendsto_filterAt_iff _).2 ⟨_, _⟩\n  · filter_upwards [self_mem_nhdsWithin]with y hy using Icc_mem_vitali_family_at_left hy\n  · intro ε εpos\n    have : x ∈ Ioc (x - ε) x := ⟨by linarith, le_refl _⟩\n    filter_upwards [Icc_mem_nhdsWithin_Iio this]with y hy\n    rw [closed_ball_eq_Icc]\n    exact Icc_subset_Icc hy.1 (by linarith)\n#align real.tendsto_Icc_vitali_family_left Real.tendsto_Icc_vitaliFamily_left\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/MeasureTheory/Covering/OneDim.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7610574483518411}}
{"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-/\nimport number_theory.legendre_symbol.gauss_eisenstein_lemmas\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\nopen_locale nat\n\nnamespace nat\nvariable {n : ℕ}\n\n/-- For `n > 1`, `(n-1)!` is congruent to `-1` modulo `n` only if n is prime. --/\nlemma prime_of_fac_equiv_neg_one\n  (h : ((n - 1)! : zmod n) = -1) (h1 : 1 < n) : prime n :=\nbegin\n  by_contradiction h2,\n  obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2,\n  have hm : m ∣ (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 [←zmod.nat_coe_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg],\nend\n\n/-- **Wilson's Theorem**: For `n > 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. --/\ntheorem prime_iff_fac_equiv_neg_one (h : 1 < n) :\n  prime n ↔ ((n - 1)! : zmod n) = -1 :=\nbegin\n  refine ⟨λ h1, _, λ h2, prime_of_fac_equiv_neg_one h2 h⟩,\n  haveI := fact.mk h1,\n  exact zmod.wilsons_lemma n,\nend\n\nend nat\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/number_theory/wilson.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7610158053717705}}
{"text": "/-\nToday we cover three issues. (1) We start \nby completing our discussion of negation. \nWe compare its behavior in Boolean algebra\nand classical predicate logic with its \nbehavior in constructive logic. To get at\nthis difference we prove one of DeMorgan's\nlaws, first in Boolean algebra by (nested)\ncase analysis, then in Boolean algebra by\napplying the induction axiom for the bool\ndata type, then in the constructive logic\nof Lean, where we find we get stuck unless\nwe're willing to accept the axiom of the\nexcluded middle, which enables us to do a\nnested case analysis on non-constructive\nproofs of two arbitrary propositions. We\nwill also see that only one direction of\nthis proof (of a bi-implication) requires\nclassical reasoning.\n\nSecond, we will introduce and see a few \nexamples of applications of the introduction\nand elimination rules for ∃ (existential\nquantification).\n\nFinally, we will start to look at induction\nin a little more depth and generality. \n-/\n\n\n/-\nFirst, a proof of one of the DeMorgan laws, \nfor Boolean algebra. What we'll see is that\ncase analysis is all we really need to do to\nconstruct a proof.\n-/\n-- proof by case analysis\ntheorem demorgan_1 : \n  ∀ (b1 b2 : bool), \n    bnot (b1  &&  b2) = \n    (bnot b1) || (bnot b2) :=\n  begin \n    intros,\n    cases b1,\n\n    -- case 1 for b1\n    cases b2,\n      -- case 1 for b2\n      exact rfl,\n      -- case 2 for b2\n      exact rfl,\n\n    -- case 2 for b1\n    cases b2,\n      -- case 1 for b2\n      exact rfl,\n      -- case 2 for b2\n      exact rfl, \n  end\n\n\n/-\nNow let's look at doing a proof of the\nsame proposition \"by induction,\" which is\nto say by application of the induction\naxiom for the bool data type. What we'll\nsee is that this principle is equivalent\nto case analysis.\n-/\n\n#check @bool.rec_on\n\n/-\nbool.rec_on : \nΠ {motive : bool → Sort u_1} \n  (n : bool), \n  motive ff → \n  motive tt → \n  motive n\n\nIn English: If we want to show \"motive n\" \n(that an arbitrary bool n has some \"motive\"\nproperty, which is to say that *all* bool\nvalues have this property), it suffices to\nshow that tt has this property and that ff\nhas it too. \n-/\n\nexample : \n  ∀ (b1 b2 : bool), \n    bnot (b1 && b2) = \n    (bnot b1) || (bnot b2) :=\nbegin\n  intros,\n  \n  apply bool.rec_on b1, -- induction/recursion on b1\n    -- b1 = ff\n    apply bool.rec_on b2, \n      -- b2 = ff\n      exact rfl,\n      -- b2 = tt\n      exact rfl,\n    -- b1 = tt\n    apply bool.rec_on b2,\n      -- b2 = ff\n      exact rfl,\n      -- b2 = tt\n      exact rfl,\nend\n\n\n/-\nrec.on is the induction principle for \nany value of a given data type. So, as\nwe've seen here, bool.rec_on is the (or\none of the forms of induction principle)\nfor the bool type in Lean. What you now\nsee is that a \"proof by induction\" is\nreally just a proof step involvin the\napplication of an induction principle,\nusually leaving the arguments (a base\nvalue/proof and an inductive step value/\nproof) to be provided as solutions to\nsubgoals. \n-/\n\nexample : \n  ∀ (b1 b2 : bool), \n    bnot (b1 && b2) = \n    (bnot b1) || (bnot b2) :=\nbegin\n  intros,\n  induction b1,\n  induction b2,\n  exact rfl,\n  exact rfl,\n  induction b2,\n  exact rfl,\n  exact rfl,\nend\n\n/-\nOk, so we've seen that this DeMorgan's \nlaw is a theorem in Boolean algebra, or,\nequivalently in *propositional* logic.\nBut what about in predicate logic, where\nwe're dealing not with Boolean truth \nvalues and compositions of Boolean\nfunctions, but with truth judgments\nfor propositions in predicate logic.\nLet's state the theorem in predicate\nlogic and see if it's valid.\n-/\nexample : ∀ (P Q : Prop), ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\nbegin\nintros,\nsplit,\n-- forward direction \nassume h,\n-- without classical reasoning we are *stuck*\n-- em lets us do case analysis on any *proposition* \nhave pnp := classical.em P,\nhave qnq := classical.em Q,\ncases pnp,\ncases qnq,\nhave pq := and.intro pnp qnq,\nhave f := h pq,\ncontradiction,\nexact or.inr qnq,\nexact or.inl pnp,\n-- reverse direction -- is constructively valid\nassume h,\ncases h,\nassume k,\ncases k,\ncontradiction,\nassume k,\ncases k,\ncontradiction,\nend\n\n/-\nA takeaway message here is that one of the\ndirections of this DeMorgan law is not valid\n(it is not a theorem) in constructive logic,\neven though it is in classical predicate logic.\n-/\n\n/-\nNext, we introduce the axioms for reasoning\nabout existentials: for proving propositions\nof the form, ∃ (t : T), P (exists.intro) and\nfor using proofs of this form (exists.elim).\n-/\n\n/-\nOur examples will use natural numbers, and\nhere, again is our favorite simple definition\nof \"property\" of natural numbers: evenness.\n-/\ndef ev (n : ℕ) := n%2 = 0\n\n/-\nAs a first example, we claim then prove that\nthere exists *some* even number. To do this\nwe have to apply exists.intro to two arguments:\na specific natural number, n, along with a \nproof that that specific n has the property \nin question. \n-/\nexample : ∃ (n : ℕ), ev n :=\nbegin\n  apply exists.intro 0, -- apply it to first argument (your witness)\n  unfold ev,            -- construct second argument interactively \n  exact rfl,\nend \n\n/-\nThere's nothing special about 0 beyond the\nfact that it's even. We could give a different\nproof of the same proposition using a different\nwitness. Any witness for which a proof of its\nevenness can be given will do.\n-/\nexample : ∃ (n : ℕ), ev n :=\nbegin\n  apply exists.intro 2,\n  exact rfl,\nend \n\n/-\nHere's a not great example, but it works.\nThe idea we illustrate here is that if we\n*have* a proof of an exists, we can obtain\na witness and proof for that witness, and\nwe can then use those elements in building\na proof of another existentially quantified\nproposition.\n-/\nexample : (∃ (n : ℕ), ev n) → (exists l, ev (l + 2)) :=\nbegin\n  assume h,\n  cases h with w k,\n  apply exists.intro (w),\n  unfold ev at k,\n  unfold ev,\n  simp,\n  assumption,\nend\n\n/-\nIn this proof we really do have to use\n(by exists.elim, as applied by the cases\ntactic) the assumed proof of the premise\nin order to obtain the witness and proof\nthat are required to prove the conclusion.\n-/\nexample (h k : ℕ → Prop) : \n  (∃ (n : ℕ), (h n) ∧ (k n)) →\n  (∃ (n : ℕ), (h n)) :=\nbegin\n  assume a,\n  cases a with w p,\n  cases p with wh wk,\n  exact exists.intro w wh,\nend\n\n/-\nThat concludes our introduction to the existential\nquantifer and its rules of reasoning in predicate\nlogic, whether classical first-order predicate logic\nor the higher-order constructive logic of Lean.\n-/\n\n/-\nNow we just broad the subject of \"proofs by induction\"\nas a much more general idea. We've seen the induction \nprinciple for bool. Check out the corresponding rules\nfor unit and the empty type. For the rest of this file\nwe'll focus on induction on a natural number value.\n-/\n\n#check @nat.rec_on\n\n/-\nΠ {motive : ℕ → Sort u_1} \n  (n : ℕ), \n  motive 0 → \n  (Π (n : ℕ), motive n → motive n.succ) → \n  motive n\n\n  Read it like this: for any property,\n  \"motive,\" of natural numbers, to show\n  that *any* (arbitrary) natural number,\n  n, has this property, it suffices to\n  show two things: (1) there is a proof\n  that 0 has the property; (2) there is\n  a proof that *if* you have any n and a\n  proof for n (that n has the property)\n  then you can construct a proof for n+1.\n-/\n\n/-\nTo be continued next time!\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/S_02_PredicateLogic/L_04_exists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.760907190269953}}
{"text": "/-\nFirst steps towards proving the second isomorphism theorem for groups.\nWe relate the join of two subgroups with the closure of their pointwise product.\nAuthor: Adrián Doña Mateo\n\nThese were contributed to mathlib in\n[#6165](https://github.com/leanprover-community/mathlib/pull/6165/).\n\nAn apostrophe was added at the end of the names to avoid clashes.\n-/\n\nimport algebra.pointwise\nimport group_theory.subgroup\n\n-- These lemmas were added to src/algebra/pointwise.lean.\nnamespace submonoid\n\nvariables {M : Type*} [monoid M]\n\n@[to_additive]\nlemma closure_mul_le' (S T : set M) : closure (S * T) ≤ closure S ⊔ closure T :=\nInf_le $ λ x ⟨s, t, hs, ht, hx⟩, hx ▸ (closure S ⊔ 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 ⊔ K = closure (H * K) :=\nle_antisymm\n  (sup_le\n    (λ h hh, subset_closure ⟨h, 1, hh, K.one_mem, mul_one h⟩)\n    (λ k hk, subset_closure ⟨1, k, H.one_mem, hk, one_mul k⟩))\n  (by conv_rhs { rw [← closure_eq H, ← closure_eq K] }; apply closure_mul_le)\n\nend submonoid\n\n-- These lemmas were added to src/group_theory/subgroup.lean.\nsection pointwise\n\nnamespace subgroup\n\nvariables {G : Type*} [group G]\n\n@[to_additive]\nlemma closure_mul_le' (S T : set G) : closure (S * T) ≤ closure S ⊔ closure T :=\nInf_le $ λ x ⟨s, t, hs, ht, hx⟩, hx ▸ (closure S ⊔ 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 : subgroup G) : H ⊔ K = closure (H * K) :=\nle_antisymm\n  (sup_le\n    (λ h hh, subset_closure ⟨h, 1, hh, K.one_mem, mul_one h⟩)\n    (λ k hk, subset_closure ⟨1, k, H.one_mem, hk, one_mul k⟩))\n  (by conv_rhs { rw [← closure_eq H, ← closure_eq K] }; apply closure_mul_le)\n\n@[to_additive]\nprivate def mul_normal_aux (H N : subgroup G) [hN : N.normal] : subgroup G :=\n{ carrier := (H : set G) * N,\n  one_mem' := ⟨1, 1, H.one_mem, N.one_mem, by rw mul_one⟩,\n  mul_mem' := λ a b ⟨h, n, hh, hn, ha⟩ ⟨h', n', hh', hn', hb⟩,\n    ⟨h * h', h'⁻¹ * n * h' * n',\n    H.mul_mem hh hh', N.mul_mem (by simpa using hN.conj_mem _ hn h'⁻¹) hn',\n    by simp [← ha, ← hb, mul_assoc]⟩,\n  inv_mem' := λ x ⟨h, n, hh, hn, hx⟩,\n    ⟨h⁻¹, h * n⁻¹ * h⁻¹, H.inv_mem hh, hN.conj_mem _ (N.inv_mem hn) h,\n    by rw [mul_assoc h, inv_mul_cancel_left, ← hx, mul_inv_rev]⟩ }\n\n/-- The carrier of `H ⊔ N` is just `↑H * ↑N` (pointwise set product) when `N` is normal. -/\n@[to_additive \"The carrier of `H ⊔ N` is just `↑H + ↑N` (pointwise set addition)\nwhen `N` is normal.\"]\nlemma mul_normal' (H N : subgroup G) [N.normal] : (↑(H ⊔ N) : set G) = H * N :=\nset.subset.antisymm\n  (show H ⊔ N ≤ mul_normal_aux H N,\n    by { rw sup_eq_closure, apply Inf_le _, dsimp, refl })\n  ((sup_eq_closure H N).symm ▸ subset_closure)\n\n@[to_additive]\nprivate def normal_mul_aux (N H : subgroup G) [hN : N.normal] : subgroup G :=\n{ carrier := (N : set G) * H,\n  one_mem' := ⟨1, 1, N.one_mem, H.one_mem, by rw mul_one⟩,\n  mul_mem' := λ a b ⟨n, h, hn, hh, ha⟩ ⟨n', h', hn', hh', hb⟩,\n    ⟨n * (h * n' * h⁻¹), h * h',\n    N.mul_mem hn (hN.conj_mem _ hn' _), H.mul_mem hh hh',\n    by simp [← ha, ← hb, mul_assoc]⟩,\n  inv_mem' := λ x ⟨n, h, hn, hh, hx⟩,\n    ⟨h⁻¹ * n⁻¹ * h, h⁻¹,\n    by simpa using hN.conj_mem _ (N.inv_mem hn) h⁻¹, H.inv_mem hh,\n    by rw [mul_inv_cancel_right, ← mul_inv_rev, hx]⟩ }\n\n/-- The carrier of `N ⊔ H` is just `↑N * ↑H` (pointwise set product) when `N` is normal. -/\n@[to_additive \"The carrier of `N ⊔ H` is just `↑N + ↑H` (pointwise set addition)\nwhen `N` is normal.\"]\nlemma normal_mul' (N H : subgroup G) [N.normal] : (↑(N ⊔ H) : set G) = N * H :=\nset.subset.antisymm\n  (show N ⊔ H ≤ normal_mul_aux N H,\n    by { rw sup_eq_closure, apply Inf_le _, dsimp, refl })\n  ((sup_eq_closure N H).symm ▸ subset_closure)\n\nend subgroup\n\nend pointwise", "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/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.7608037516356888}}
{"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.int.order.basic\nimport data.nat.cast.basic\n\n/-!\n# Basic lemmas about the divisibility relation in `ℤ`.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nopen nat\n\nnamespace int\n\n@[norm_cast] theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n :=\n⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim\n  (λm0, by simp [m0] at ae; simp [ae, m0])\n  (λm0l, by\n  { cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_right ℤ _ m a\n      (by simp [ae.symm]) (by simpa using m0l)) with k e,\n    subst a, exact ⟨k, int.coe_nat_inj ae⟩ }),\n λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩\n\ntheorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ 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 : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n :=\nby rcases nat_abs_eq z with eq | eq; rw eq; simp [←coe_nat_dvd]\n\ntheorem le_of_dvd {a b : ℤ} (bpos : 0 < b) (H : a ∣ b) : a ≤ b :=\nmatch a, b, eq_succ_of_zero_lt bpos, H with\n| (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $\n  nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H\n| -[1+ m], ._, ⟨n, rfl⟩, _ :=\n  le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _)\nend\n\n\n\ntheorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : 0 ≤ a) (H' : a * b = 1) : a = 1 :=\neq_one_of_dvd_one H ⟨b, H'.symm⟩\n\ntheorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : 0 ≤ 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 : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z\n| (int.of_nat _) haz := int.coe_nat_dvd.2 haz\n| -[1+k] haz :=\n  begin\n    change ↑a ∣ -(k+1 : ℤ),\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 : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ 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' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz,\n  int.coe_nat_dvd.1 haz'\n\ntheorem dvd_antisymm {a b : ℤ} (H1 : 0 ≤ a) (H2 : 0 ≤ b) : a ∣ b → b ∣ a → a = b :=\nbegin\n  rw [← abs_of_nonneg H1, ← 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\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/dvd/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.7608037508385023}}
{"text": "import LeanUtils.Div\nimport Mathlib.Tactic.Ring\n\n/- Parity : functions and theorems related to parity -/\n\nnamespace Nat\n  def even (a : Nat) : Prop := a % 2 = 0\n  def odd (a : Nat) : Prop := a % 2 = 1\n\n  theorem even_rewrite {a : Nat} : even a ↔ ∃ (n : Nat), a = 2 * n := \n    Iff.intro\n      (by\n        intro h\n        rw [even, mod_rewrite] at h\n        simp_all)\n      (by \n        intro h\n        have ⟨n, hn⟩ := h\n        rw [hn, even, mod_rewrite]\n        exact ⟨_, by rfl⟩)\n  \n  theorem odd_rewrite {a : Nat} : odd a ↔ ∃ (n : Nat), a = 2 * n + 1 :=\n    Iff.intro\n      (by\n        intro h\n        rw [odd, mod_rewrite] at h\n        simp_all)\n      (by \n        intro h\n        have ⟨n, hn⟩ := h\n        rw [hn, odd, mod_rewrite]\n        exact ⟨_, by rfl⟩)\n\n  theorem even_plus_even {a b : Nat} : even a → even b → even (a + b) := by \n    intros h₁ h₂\n    rw [even_rewrite] at h₁ h₂\n    have ⟨n, hn⟩ := h₁\n    have ⟨m, hm⟩ := h₂\n    rw [hn, hm]\n    apply even_rewrite.mpr\n    exact ⟨n+m, by ring⟩\n\n  theorem even_plus_odd {a b : Nat} : even a → odd b → odd (a + b) := by\n    intros h₁ h₂\n    rw [even_rewrite] at h₁\n    rw [odd_rewrite] at h₂\n    have ⟨n, hn⟩ := h₁\n    have ⟨m, hm⟩ := h₂\n    rw [hn, hm]\n    apply odd_rewrite.mpr\n    exact ⟨n+m, by ring⟩\n\n  theorem odd_plus_odd {a b : Nat} : odd a → odd b → even (a + b) := by\n    intros h₁ h₂\n    rw [odd_rewrite] at h₁ h₂\n    have ⟨n, hn⟩ := h₁\n    have ⟨m, hm⟩ := h₂\n    rw [hn, hm]\n    apply even_rewrite.mpr\n    exact ⟨n+m+1, by ring⟩\n\n\nend Nat\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/LeanUtils/Parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7607904210905903}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que para tododos par de numero reales a y b, si \n-- a < b entonces no se tiene que b < a.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : ℝ\n\nexample \n  (h : a < b) \n  : ¬ b < a :=\nbegin\n  intro h',\n  have : a < a,\n    from lt_trans h h',\n  apply lt_irrefl a this,\nend\n\n-- La prueba es\n-- \n-- a b : ℝ,\n-- h : a < b\n-- ⊢ ¬b < a\n--    >>   intro h',\n-- h' : b < a\n-- ⊢ false\n--    >>   have : a < a,\n--    >>     from lt_trans h h',\n-- this : a < a\n-- ⊢ false\n--    >>   apply lt_irrefl a this,\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/Asimetrica_implica_irreflexiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8397339596505966, "lm_q1q2_score": 0.7607904192737086}}
{"text": "import tactic.norm_num\n-- if that line above doesn't work then you don't have mathlib\n-- so just comment it out and maybe some stuff won't work.\n\n-- If you think you do have mathlib, then try upgrading\n-- Lean (to nightly) and then try upgrading mathlib.\n\n-- If you have Lean running and want to get mathlib working\n-- then you could ask how to do it in the comments of this\n-- page on wordpress.com. When Kevin has the time he will\n-- try and help, and perhaps others will help sooner.\n\n-- all that should be on blog ^^^\n\n-- Ignore these lines if you son't understand them --\n-- they're just to get things up and running\n\nnamespace xena\n\nuniverses u v w\n/-\nvariables {α β γ : Type u}\nvariables a1 a2 a : α\nvariable b : β\nvariable X : Type u -- a set\nvariable Y : Type v\nvariables m n : ℕ\n-/\n\n-- This is where the maths starts\n\nopen function \n\ndefinition bijects_with (X : Type u) (Y : Type v) : Prop :=\n  ∃ f : X → Y, bijective f\n\n-- \"fin n\" means the finite set {0,1,...,n-1} of size n\ndefinition has_size (Y : Type u) (n) : Prop :=\n  bijects_with (fin n) Y\n\n-- if Kenny cares about constructive maths he can\n-- prove that this statement is decidable\n-- and give it a decidable instance.\n-- set_option pp.implicit true \n\ntheorem inv_of_bij {α : Type u} {β : Type v} (f : α → β) :\n  bijective f → exists g : β → α, bijective g :=\nbegin\nintros H_f_bijective,\nhave H_f_surjective := H_f_bijective.right,\nhave H_f_injective := H_f_bijective.left,\nhave surj_proof := λ b, classical.some_spec (H_f_surjective b),\nlet g := λ b, classical.some (H_f_surjective b),\nhave H_right_inverse : ∀ b : β, f (g b) = b,\n  intro b,\n  exact surj_proof b,\nclear surj_proof,\nexistsi g,\nsplit,\n  -- injectivity\n  intros b1 b2 H_g_b1_eq_g_b2,\n  rw [←H_right_inverse b1,H_g_b1_eq_g_b2,H_right_inverse b2],\n-- surjectivity\nintro a,\nexistsi (f a),\napply H_f_injective,\napply H_right_inverse,\nend\n\ntheorem only_one_size (X : Type u) {m n : ℕ} :\n  has_size X m ∧ has_size X n → m = n :=\nbegin\nassume X_size_m_and_n,\nhave X_size_m, from X_size_m_and_n.left,\nhave X_size_n, from X_size_m_and_n.right,\ncases X_size_m with f Hf,\ncases X_size_n with g Hg,\nhave ginv := inv_of_bij g Hg,\ncases ginv with h Hh,\nhave Hhf := bijective_comp Hh Hf,\nhave : bijects_with (fin m) (fin n) := ⟨_,Hhf⟩,\nadmit, \nend\n\ndefinition subset {α : Type u} (s : α → Prop) := { a : α // s a }\ndefinition complement {α : Type u} (s : α → Prop) := λ a, ¬ (s a)\n\nexample {α : Type u} (s : α → Prop) (m n : ℕ) :\n  has_size (subset s) m ∧ has_size (subset (complement s)) n\n  → has_size α (m+n) :=\nbegin\n  assume H : has_size (subset s) m ∧ has_size (subset (complement s)) n,\n  cases H with H_s_m H_nots_n,\n  cases H_s_m with f Hf,\n  cases H_nots_n with g Hg,\n  let h : fin (m+n) → α,\n    intro x,\n    cases x with val is_lt,\n    exact dite (val<m) \n      (λ h2,(f ⟨val,h2⟩).val)\n      -- next line : need a function ¬(val<m) -> α\n      (begin\n        intro H,\n        have H2 := le_of_not_gt H,\n        have H3 := (nat.sub_lt_left_iff_lt_add H2).2 is_lt,\n        exact (g ⟨val - m,H3⟩).val,\n      end),\n  exact ⟨h,begin\nsplit,\n  intros a1 a2,\n  cases lt_or_ge a1.val m with Ha1f Ha1g;cases lt_or_ge a2.val m with Ha2f Ha2g,\n        intro H,\n        have : h a1 = (f ⟨a1.val,Ha1f⟩).val,\n          --unfold fin.cases_on\n          --exact @dif_pos _ _ Ha1f _ (λ (h2 : a1.val < m), (f ⟨a1.val, h2⟩).val) (λ (H : ¬a1.val < m), (g ⟨a1.val - m, _⟩).val),\n\n  repeat {admit},\n  end⟩,\nend\n#check @dif_pos\n--dif_pos : ∀ {c : Prop} [h : decidable c] (hc : c) {α : Sort u_1} {t : c → α} {e : ¬c → α}, dite c t e = t hc\n\nend xena\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/random_projects_mostly_students/lagrange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7607140102436707}}
{"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.char_p.invertible\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.Invertible\nimport Mathlib.Algebra.CharP.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`invertibleOfNonzero` is a useful definition.\n-/\n\n\nvariable {K : Type _}\n\nsection Field\n\nvariable [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 invertibleOfRingCharNotDvd {t : ℕ} (not_dvd : ¬ringChar K ∣ t) : Invertible (t : K) :=\n  invertibleOfNonzero fun h => not_dvd ((ringChar.spec K t).mp h)\n#align invertible_of_ring_char_not_dvd invertibleOfRingCharNotDvd\n\ntheorem not_ringChar_dvd_of_invertible {t : ℕ} [Invertible (t : K)] : ¬ringChar K ∣ t := by\n  rw [← ringChar.spec, ← Ne.def]\n  exact nonzero_of_invertible (t : K)\n#align not_ring_char_dvd_of_invertible not_ringChar_dvd_of_invertible\n\n/-- A natural number `t` is invertible in a field `K` of charactistic `p` if `p` does not divide\n`t`. -/\ndef invertibleOfCharPNotDvd {p : ℕ} [CharP K p] {t : ℕ} (not_dvd : ¬p ∣ t) : Invertible (t : K) :=\n  invertibleOfNonzero fun h => not_dvd ((CharP.cast_eq_zero_iff K p t).mp h)\n#align invertible_of_char_p_not_dvd invertibleOfCharPNotDvd\n\n-- warning: this could potentially loop with `Invertible.ne_zero` - if there is weird type-class\n-- loops, watch out for that.\ninstance invertibleOfPos [CharZero K] (n : ℕ) [NeZero n] : Invertible (n : K) :=\n  invertibleOfNonzero <| NeZero.out\n#align invertible_of_pos invertibleOfPos\n\nend Field\n\nsection DivisionRing\n\nvariable [DivisionRing K] [CharZero K]\n\ninstance invertibleSucc (n : ℕ) : Invertible (n.succ : K) :=\n  invertibleOfNonzero (Nat.cast_ne_zero.mpr (Nat.succ_ne_zero _))\n#align invertible_succ invertibleSucc\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\n\ninstance invertibleTwo : Invertible (2 : K) :=\n  invertibleOfNonzero (by exact_mod_cast (by decide : 2 ≠ 0))\n#align invertible_two invertibleTwo\n\ninstance invertibleThree : Invertible (3 : K) :=\n  invertibleOfNonzero (by exact_mod_cast (by decide : 3 ≠ 0))\n#align invertible_three invertibleThree\n\nend DivisionRing\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/Invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7606589550533867}}
{"text": "example (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ 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\nexample (α : Type*) : α → α :=\nbegin\n  intro a,\n  exact a,\nend\n\nexample (α : Type*) : ∀ x : α, x = x :=\nbegin\n  intro x,\n  exact eq.refl x,\nend\n\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n  intros a b c h₁ h₂,\n  exact eq.trans (eq.symm h₂) h₁,\nend\n\nvariables x y z w : ℕ\n\nexample (h₁ : x = y) (h₂ : y = z) (h₃ : z = w) : x = w :=\nbegin \n  apply eq.trans h₁,\n  apply eq.trans h₂,\n  assumption,\nend\n\nexample (h₁ : x = y) (h₂ : y = z) (h₃ : z = w) : x = w :=\nbegin\n  apply eq.trans,\n  assumption,\n  apply eq.trans,\n  assumption,\n  assumption,\nend\n\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n  intros,\n  apply eq.trans,\n  apply eq.symm,\n  assumption,\n  assumption,\nend\n\nexample (y : ℕ) : (λ x : ℕ, 0) y = 0 :=\nbegin\n  refl,\nend\n\nexample (x : ℕ) : x ≤ x :=\nbegin\n  refl,\nend\n\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n  intros,\n  transitivity,\n  symmetry,\n  assumption,\n  assumption,\nend\n\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n  intros a b c h₁ h₂,\n  transitivity a,\n  symmetry,\n  assumption,\n  assumption,\nend\n\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n  intros,\n  transitivity,\n  symmetry,\n  repeat {assumption},\nend\n\nexample : ∃ a : ℕ, 5 = a :=\nbegin\n    apply exists.intro,\n    reflexivity,\nend\n\nexample : ∃ a : ℕ, a = a :=\nbegin\n    fapply exists.intro,\n    exact 0,\n    reflexivity,\nend\n\nexample (x : ℕ) : x = x :=\nbegin\n  revert x,\n  intro y,\n  reflexivity,\nend\n\nexample (x y : ℕ) (h : x = y) : y = x :=\nbegin\n  revert h,\n  intro h₁,\n  symmetry,\n  assumption,\nend\n\nexample (x y : ℕ) (h : x = y) : y = x :=\nbegin\n  revert x,\n  intros,\n  symmetry,\n  assumption,\nend\n\nexample (x y : ℕ) (h : x = y) : y = x :=\nbegin\n  revert x y,\n  intros,\n  symmetry,\n  assumption,\nend\n\nexample : 3 = 3 :=\nbegin\n  generalize : 3 = x,\n  revert x,\n  intro y,\n  reflexivity,\nend\n\nexample : 2 + 3 = 5 :=\nbegin\n  generalize : 3 = x,\n  sorry,\nend\n\nexample : 2 + 3 = 5 :=\nbegin\n  generalize h : 3 = x,\n  rw ←h,\nend", "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.2-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8652240773641087, "lm_q1q2_score": 0.7606589535257418}}
{"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 linear_algebra.affine_space.midpoint_zero\n! leanprover-community/mathlib commit 78261225eb5cedc61c5c74ecb44e5b385d13b733\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.Invertible\nimport Mathlib.LinearAlgebra.AffineSpace.Midpoint\n\n/-!\n# Midpoint of a segment for characteristic zero\n\nWe collect lemmas that require that the underlying ring has characteristic zero.\n\n## Tags\n\nmidpoint\n-/\n\n\nopen AffineMap AffineEquiv\n\ntheorem lineMap_inv_two {R : Type _} {V P : Type _} [DivisionRing R] [CharZero R] [AddCommGroup V]\n    [Module R V] [AddTorsor V P] (a b : P) : lineMap a b (2⁻¹ : R) = midpoint R a b :=\n  rfl\n#align line_map_inv_two lineMap_inv_two\n\ntheorem lineMap_one_half {R : Type _} {V P : Type _} [DivisionRing R] [CharZero R] [AddCommGroup V]\n    [Module R V] [AddTorsor V P] (a b : P) : lineMap a b (1 / 2 : R) = midpoint R a b := by\n  rw [one_div, lineMap_inv_two]\n#align line_map_one_half lineMap_one_half\n\ntheorem homothety_invOf_two {R : Type _} {V P : Type _} [CommRing R] [Invertible (2 : R)]\n    [AddCommGroup V] [Module R V] [AddTorsor V P] (a b : P) :\n    homothety a (⅟ 2 : R) b = midpoint R a b :=\n  rfl\n#align homothety_inv_of_two homothety_invOf_two\n\ntheorem homothety_inv_two {k : Type _} {V P : Type _} [Field k] [CharZero k] [AddCommGroup V]\n    [Module k V] [AddTorsor V P] (a b : P) : homothety a (2⁻¹ : k) b = midpoint k a b :=\n  rfl\n#align homothety_inv_two homothety_inv_two\n\ntheorem homothety_one_half {k : Type _} {V P : Type _} [Field k] [CharZero k] [AddCommGroup V]\n    [Module k V] [AddTorsor V P] (a b : P) : homothety a (1 / 2 : k) b = midpoint k a b := by\n  rw [one_div, homothety_inv_two]\n#align homothety_one_half homothety_one_half\n\n@[simp]\ntheorem pi_midpoint_apply {k ι : Type _} {V : ∀ _ : ι, Type _} {P : ∀ _ : ι, Type _} [Field k]\n    [Invertible (2 : k)] [∀ i, AddCommGroup (V i)] [∀ i, Module k (V i)]\n    [∀ i, AddTorsor (V i) (P i)] (f g : ∀ i, P i) (i : ι) :\n    midpoint k f g i = midpoint k (f i) (g i) :=\n  rfl\n#align pi_midpoint_apply pi_midpoint_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/LinearAlgebra/AffineSpace/MidpointZero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.855851154320682, "lm_q1q2_score": 0.7606452468883547}}
{"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-/\nimport analysis.complex.polynomial\nimport field_theory.galois\nimport group_theory.perm.cycle.type\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 ℚ-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 ≃ₐ[F] E) → 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 × 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 ≃ₐ[F] p.splitting_field\n\nnamespace gal\n\ninstance : has_coe_to_fun p.gal (λ _, p.splitting_field → p.splitting_field) :=\nalg_equiv.has_coe_to_fun\n\ninstance apply_mul_semiring_action : mul_semiring_action p.gal p.splitting_field :=\nalg_equiv.apply_mul_semiring_action\n\n@[ext] lemma ext {σ τ : p.gal} (h : ∀ x ∈ p.root_set p.splitting_field, σ x = τ x) : σ = τ :=\nbegin\n  refine alg_equiv.ext (λ x, (alg_hom.mem_equalizer σ.to_alg_hom τ.to_alg_hom x).mp\n      ((set_like.ext_iff.mp _ x).mpr algebra.mem_top)),\n  rwa [eq_top_iff, ←splitting_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 := λ f, alg_equiv.ext (λ x, by { obtain ⟨y, rfl⟩ := 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 : ℕ) : 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  (λ 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 ≃ₐ[F] E) →* 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 → root_set p E :=\nset.maps_to.restrict (is_scalar_tower.to_alg_hom F p.splitting_field E) _ _ $ root_set_maps_to _\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 λ _ _ 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 →+* 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 ⟨x, hx1, hx2⟩,\n    exact ⟨⟨x, multiset.mem_to_finset.mpr hx1⟩, subtype.ext hx2⟩ }\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) ≃ (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 := λ ϕ, set.maps_to.restrict ϕ _ _ $ root_set_maps_to ϕ.to_alg_hom,\n  one_smul := λ _, by { ext, refl },\n  mul_smul := λ _ _ _, 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 := λ ϕ x, roots_equiv_roots p E (ϕ • ((roots_equiv_roots p E).symm x)),\n  one_smul := λ _, by simp only [equiv.apply_symm_apply, one_smul],\n  mul_smul := λ _ _ _, 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  (ϕ : E ≃ₐ[F] E) (x : root_set p E) : ↑((restrict p E ϕ) • x) = ϕ x :=\nbegin\n  let ψ := alg_equiv.of_injective_field (is_scalar_tower.to_alg_hom F p.splitting_field E),\n  change ↑(ψ (ψ.symm _)) = ϕ x,\n  rw alg_equiv.apply_symm_apply ψ,\n  change ϕ (roots_equiv_roots p E ((roots_equiv_roots p E).symm x)) = ϕ 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 →* equiv.perm (root_set p E) :=\nmul_action.to_perm_hom _ _\n\nlemma gal_action_hom_restrict [fact (p.splits (algebra_map F E))]\n  (ϕ : E ≃ₐ[F] E) (x : root_set p E) : ↑(gal_action_hom p E (restrict p E ϕ) x) = ϕ x :=\nrestrict_smul ϕ 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 injective_iff_map_eq_one,\n  intros ϕ hϕ,\n  ext x hx,\n  have key := equiv.perm.ext_iff.mp hϕ (roots_equiv_roots p E ⟨x, hx⟩),\n  change roots_equiv_roots p E (ϕ • (roots_equiv_roots p E).symm\n    (roots_equiv_roots p E ⟨x, hx⟩)) = roots_equiv_roots p E ⟨x, hx⟩ 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 ∣ q) : q.gal →* p.gal :=\nif hq : q = 0 then 1 else @restrict F _ p _ _ _\n  ⟨splits_of_splits_of_dvd (algebra_map F q.splitting_field) hq (splitting_field.splits q) hpq⟩\n\nlemma restrict_dvd_surjective (hpq : p ∣ q) (hq : q ≠ 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 →* p.gal × 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 λ 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, polynomial.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      ⟨splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_right p q)⟩,\n    have key : x = algebra_map (p.splitting_field) (p * q).splitting_field\n      ((roots_equiv_roots p _).inv_fun ⟨x, multiset.mem_to_finset.mpr h⟩) :=\n      subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots p _) ⟨x, _⟩).symm,\n    rw [key, ←alg_equiv.restrict_normal_commutes, ←alg_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      ⟨splits_of_splits_of_dvd _ hpq (splitting_field.splits (p * q)) (dvd_mul_left q p)⟩,\n    have key : x = algebra_map (q.splitting_field) (p * q).splitting_field\n      ((roots_equiv_roots q _).inv_fun ⟨x, multiset.mem_to_finset.mpr h⟩) :=\n      subtype.ext_iff.mp (equiv.apply_symm_apply (roots_equiv_roots q _) ⟨x, _⟩).symm,\n    rw [key, ←alg_equiv.restrict_normal_commutes, ←alg_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, ←mul_eq_zero] }\nend\n\n\n\n/-- `p` splits in the splitting field of `p ∘ q`, for `q` non-constant. -/\nlemma splits_in_splitting_field_of_comp (hq : q.nat_degree ≠ 0) :\n  p.splits (algebra_map F (p.comp q).splitting_field) :=\nbegin\n  let P : F[X] → Prop := λ r, r.splits (algebra_map F (r.comp q).splitting_field),\n  have key1 : ∀ {r : F[X]}, irreducible r → 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 ⟨x, hx⟩ := exists_root_of_splits _ (splitting_field.splits (r.comp q))\n      (λ 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 [←aeval_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 : ∀ {p₁ p₂ : F[X]}, P p₁ → P p₂ → P (p₁ * p₂),\n  { intros p₁ p₂ hp₁ hp₂,\n    by_cases h₁ : p₁.comp q = 0,\n    { cases comp_eq_zero_iff.mp h₁ 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₂ : p₂.comp q = 0,\n    { cases comp_eq_zero_iff.mp h₂ 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₁ h₂ hp₁ hp₂,\n    rwa ← mul_comp at key },\n  exact wf_dvd_monoid.induction_on_irreducible p (splits_zero _)\n    (λ _, splits_of_is_unit _) (λ _ _ _ h, key2 (key1 h)),\nend\n\n/-- `polynomial.gal.restrict` for the composition of polynomials. -/\ndef restrict_comp (hq : q.nat_degree ≠ 0) : (p.comp q).gal →* p.gal :=\n@restrict F _ p _ _ _ ⟨splits_in_splitting_field_of_comp p q hq⟩\n\nlemma restrict_comp_surjective (hq : q.nat_degree ≠ 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 ∣ fintype.card p.gal :=\nbegin\n  rw gal.card_of_separable p_irr.separable,\n  have hp : p.degree ≠ 0 :=\n    λ h, nat.prime.ne_zero p_deg (nat_degree_eq_zero_iff_degree_le_zero.mpr (le_of_eq h)),\n  let α : p.splitting_field := root_of_splits (algebra_map F p.splitting_field)\n    (splitting_field.splits p) hp,\n  have hα : is_integral F α := algebra.is_integral_of_finite _ _ α,\n  use finite_dimensional.finrank F⟮α⟯ p.splitting_field,\n  suffices : (minpoly F α).nat_degree = p.nat_degree,\n  { rw [←finite_dimensional.finrank_mul_finrank F F⟮α⟯ p.splitting_field,\n        intermediate_field.adjoin.finrank hα, this] },\n  suffices : minpoly F α ∣ p,\n  { have key := (minpoly.irreducible hα).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α) } },\n  apply minpoly.dvd F α,\n  rw [aeval_def, map_root_of_splits _ (splitting_field.splits p) hp],\nend\n\nsection rationals\n\nlemma splits_ℚ_ℂ {p : ℚ[X]} : fact (p.splits (algebra_map ℚ ℂ)) :=\n⟨is_alg_closed.splits_codomain p⟩\n\nlocal attribute [instance] splits_ℚ_ℂ\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 : ℚ[X]) :\n  (p.root_set ℂ).to_finset.card = (p.root_set ℝ).to_finset.card +\n  (gal_action_hom p ℂ (restrict p ℂ (complex.conj_ae.restrict_scalars ℚ))).support.card :=\nbegin\n  by_cases hp : p = 0,\n  { haveI : is_empty (p.root_set ℂ) := by { rw [hp, root_set_zero], apply_instance },\n    simp_rw [(gal_action_hom p ℂ _).support.eq_empty_of_is_empty, hp, root_set_zero,\n      set.to_finset_empty, finset.card_empty] },\n  have inj : function.injective (is_scalar_tower.to_alg_hom ℚ ℝ ℂ) := (algebra_map ℝ ℂ).injective,\n  rw [←finset.card_image_of_injective _ subtype.coe_injective,\n      ←finset.card_image_of_injective _ inj],\n  let a : finset ℂ := _,\n  let b : finset ℂ := _,\n  let c : finset ℂ := _,\n  change a.card = b.card + c.card,\n  have ha : ∀ z : ℂ, z ∈ a ↔ aeval z p = 0,\n  { intro z, rw [set.mem_to_finset, mem_root_set_of_ne hp], apply_instance },\n  have hb : ∀ z : ℂ, z ∈ b ↔ aeval z p = 0 ∧ z.im = 0,\n  { intro z,\n    simp_rw [finset.mem_image, exists_prop, set.mem_to_finset, mem_root_set_of_ne hp],\n    split,\n    { rintros ⟨w, hw, rfl⟩,\n      exact ⟨by rw [aeval_alg_hom_apply, hw, alg_hom.map_zero], rfl⟩ },\n    { rintros ⟨hz1, hz2⟩,\n      have key : is_scalar_tower.to_alg_hom ℚ ℝ ℂ z.re = z := by { ext, refl, rw hz2, refl },\n      exact ⟨z.re, inj (by rwa [←aeval_alg_hom_apply, key, alg_hom.map_zero]), key⟩ } },\n  have hc0 : ∀ w : p.root_set ℂ, gal_action_hom p ℂ\n    (restrict p ℂ (complex.conj_ae.restrict_scalars ℚ)) w = w ↔ 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 : ∀ z : ℂ, z ∈ c ↔ aeval z p = 0 ∧ z.im ≠ 0,\n  { intro z,\n    simp_rw [finset.mem_image, exists_prop],\n    split,\n    { rintros ⟨w, hw, rfl⟩,\n      exact ⟨(mem_root_set.mp w.2).2, mt (hc0 w).mpr (equiv.perm.mem_support.mp hw)⟩ },\n    { rintros ⟨hz1, hz2⟩,\n      exact ⟨⟨z, mem_root_set.mpr ⟨hp, hz1⟩⟩,\n        equiv.perm.mem_support.mpr (mt (hc0 _).mp hz2), rfl⟩ } },\n  rw ← 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  { rw finset.disjoint_left,\n    intros z,\n    rw [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 : ℚ[X]} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)\n  (p_roots : fintype.card (p.root_set ℂ) = fintype.card (p.root_set ℝ) + 2) :\n  function.bijective (gal_action_hom p ℂ) :=\nbegin\n  have h1 : fintype.card (p.root_set ℂ) = p.nat_degree,\n  { simp_rw [root_set_def, finset.coe_sort_coe, fintype.card_coe],\n    rw [multiset.to_finset_card_of_nodup, ←nat_degree_eq_card_roots],\n    { exact is_alg_closed.splits_codomain p },\n    { exact nodup_roots ((separable_map (algebra_map ℚ ℂ)).mpr p_irr.separable) } },\n  have h2 : fintype.card p.gal = fintype.card (gal_action_hom p ℂ).range :=\n  fintype.card_congr (monoid_hom.of_injective (gal_action_hom_injective p ℂ)).to_equiv,\n  let conj := restrict p ℂ (complex.conj_ae.restrict_scalars ℚ),\n  refine ⟨gal_action_hom_injective p ℂ, λ x, (congr_arg (has_mem.mem x)\n    (show (gal_action_hom p ℂ).range = ⊤, from _)).mpr (subgroup.mem_top x)⟩,\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 ⟨conj, rfl⟩ },\n  { rw ← equiv.perm.card_support_eq_two,\n    apply nat.add_left_cancel,\n    rw [←p_roots, ←set.to_finset_card (root_set p ℝ), ←set.to_finset_card (root_set p ℂ)],\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 : ℚ[X]} (p_irr : irreducible p) (p_deg : p.nat_degree.prime)\n  (p_roots1 : fintype.card (p.root_set ℝ) + 1 ≤ fintype.card (p.root_set ℂ))\n  (p_roots2 : fintype.card (p.root_set ℂ) ≤ fintype.card (p.root_set ℝ) + 3) :\n  function.bijective (gal_action_hom p ℂ) :=\nbegin\n  apply gal_action_hom_bijective_of_prime_degree p_irr p_deg,\n  let n := (gal_action_hom p ℂ (restrict p ℂ\n    (complex.conj_ae.restrict_scalars ℚ))).support.card,\n  have hn : 2 ∣ n :=\n  equiv.perm.two_dvd_card_support (by rw [←monoid_hom.map_pow, ←monoid_hom.map_pow,\n    show alg_equiv.restrict_scalars ℚ 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 : ∀ m : ℕ, 2 ∣ m → 1 ≤ m → m ≤ 3 → m = 2,\n  { exact this n hn p_roots1 p_roots2 },\n  rintros m ⟨k, rfl⟩ h2 h3,\n  exact le_antisymm (nat.lt_succ_iff.mp (lt_of_le_of_ne h3 (show 2 * k ≠ 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 ≠ 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": "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/polynomial_galois_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7606049212583879}}
{"text": "import tactic\n\n/- Tactics you may consider\n-intro\n-cases\n-exact\n-apply\n-change\n-by_cases \n-by_contra\n-assumption\n-contradition\n-/\n\nopen_locale classical\n\nvariables (P Q : Prop)\n\n#check classical.em \n#check classical.em Q\n\n-- BEGIN\nexample (h : ¬ ¬ Q) : Q :=\nbegin\n  by_contra h', \n  /- assume that the negation of Q is true:\n    \"h' : ¬ Q\" and prove it false -/\n  exact h h',\n  /- A contradiction is found in h and h' -/\nend\n\nexample (h : Q) : ¬ ¬ Q :=\nbegin\n  by_contra h',\n  contradiction,\nend\n-- END\n\n/- Tactic Proof 1: Double negation -/\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro hnnp,\n  /- introduce the proof of ¬¬P, denoted as hnnp -/\n  by_contra h,\n  /- 'by_contra h' creates the negation of what is to \n     be proved, namely h: ¬P, and tells Lean to prove\n     false by finding a contradiction -/\n  exact hnnp h,\n  /- A contradiction is found in hnnp (¬¬P) and h (¬P):  \n     they cannot be true at the same time -/\nend\n\n/- Tactic Proof 2: Double negation -/\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro hnnp,\n  /- introduce the proof of ¬¬P, denoted as hnnp. -/\n  by_contra h, \n  /- 'by_contra h' creates the negation of what is to \n     be proved, namely h: ¬P, and tells Lean to prove\n     false by finding a contradiction. -/\n  apply hnnp,\n  /- ¬¬P is equivalent to ¬P → false. The apply tactic \n     transforms the current goal to sufficient conditions. \n     'apply hnnp' (hnnp: ¬¬P) matches the goal ⊢ false \n     and leaves the hypothesis ¬P as a new goal. As a \n     result, the goal changes from ⊢ false to ⊢ ¬P. -/\n  exact h,\n  /- use the proof of ¬P (h) to prove ¬P. -/\nend\n\n/- Tactic Proof 3: Double negation -/\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro h,\n  by_cases h' : P,\n  { assumption },\n  contradiction,\nend\n\n/- Tactic Proof 4: Double negation -/\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro h,\n  change ¬P → false at h,\n  by_contra hP,\n  apply h,\n  exact hP,\nend\n\n/- Tactic Proof 5: Double negation -/\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro h,\n  cases classical.em P,\n  { assumption },\n  contradiction\nend\n\n/- Term Proof 1: Double negation -/\nexample (P : Prop) (h : ¬ ¬ P) : P :=\nby_contradiction\n  (assume h1 : ¬ P,\n    show false, from h h1)\n\nopen classical\n/- Term Proof 2: Double negation -/\nexample (P : Prop) (h : ¬ ¬ P) : P :=\nby_cases\n  (assume h1 : P, h1)\n  (assume h1 : ¬ P, absurd h1 h)", "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/ex1_double_neg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7606049177662427}}
{"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-/\nimport data.nat.pow\nimport data.nat.bits\n\n/-!\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n Lemmas about `size`. -/\n\nnamespace nat\n\n/-! ### `shiftl` and `shiftr` -/\n\nlemma shiftl_eq_mul_pow (m) : ∀ n, shiftl m n = m * 2 ^ n\n| 0     := (nat.mul_one _).symm\n| (k+1) := show bit0 (shiftl m k) = m * (2 * 2 ^ k),\n  by rw [bit0_val, shiftl_eq_mul_pow, mul_left_comm, mul_comm 2]\n\nlemma shiftl'_tt_eq_mul_pow (m) : ∀ n, shiftl' tt m n + 1 = (m + 1) * 2 ^ n\n| 0     := by simp [shiftl, shiftl', pow_zero, nat.one_mul]\n| (k+1) :=\nbegin\n  change bit1 (shiftl' tt m k) + 1 = (m + 1) * (2 * 2 ^ k),\n  rw bit1_val,\n  change 2 * (shiftl' tt m k + 1) = _,\n  rw [shiftl'_tt_eq_mul_pow, mul_left_comm, mul_comm 2],\nend\n\nlemma one_shiftl (n) : shiftl 1 n = 2 ^ n :=\n(shiftl_eq_mul_pow _ _).trans (nat.one_mul _)\n\n@[simp] lemma zero_shiftl (n) : shiftl 0 n = 0 :=\n(shiftl_eq_mul_pow _ _).trans (nat.zero_mul _)\n\nlemma shiftr_eq_div_pow (m) : ∀ n, shiftr m n = m / 2 ^ n\n| 0     := (nat.div_one _).symm\n| (k+1) := (congr_arg div2 (shiftr_eq_div_pow k)).trans $\n           by rw [div2_val, nat.div_div_eq_div_mul, mul_comm]; refl\n\n@[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 :=\n(shiftr_eq_div_pow _ _).trans (nat.zero_div _)\n\ntheorem shiftl'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftl' b m n ≠ 0 :=\nby induction n; simp [bit_ne_zero, shiftl', *]\n\ntheorem shiftl'_tt_ne_zero (m) : ∀ {n} (h : n ≠ 0), shiftl' tt m n ≠ 0\n| 0        h := absurd rfl h\n| (succ n) _ := nat.bit1_ne_zero _\n\n/-! ### `size` -/\n\n@[simp] theorem size_zero : size 0 = 0 := by simp [size]\n\n@[simp] theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) :=\nbegin\n  rw size,\n  conv { to_lhs, rw [binary_rec], simp [h] },\n  rw div2_bit,\nend\n\n@[simp] theorem size_bit0 {n} (h : n ≠ 0) : size (bit0 n) = succ (size n) :=\n@size_bit ff n (nat.bit0_ne_zero h)\n\n@[simp] theorem size_bit1 (n) : size (bit1 n) = succ (size n) :=\n@size_bit tt n (nat.bit1_ne_zero n)\n\n@[simp] theorem size_one : size 1 = 1 :=\nshow size (bit1 0) = 1, by rw [size_bit1, size_zero]\n\n@[simp] theorem size_shiftl' {b m n} (h : shiftl' b m n ≠ 0) :\n  size (shiftl' b m n) = size m + n :=\nbegin\n  induction n with n IH; simp [shiftl'] at h ⊢,\n  rw [size_bit h, nat.add_succ],\n  by_cases s0 : shiftl' b m n = 0; [skip, rw [IH s0]],\n  rw s0 at h ⊢,\n  cases b, {exact absurd rfl h},\n  have : shiftl' tt m n + 1 = 1 := congr_arg (+1) s0,\n  rw [shiftl'_tt_eq_mul_pow] at this,\n  obtain rfl := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩),\n  rw one_mul at this,\n  obtain rfl : n = 0 := nat.eq_zero_of_le_zero (le_of_not_gt $ λ hn,\n    ne_of_gt (pow_lt_pow_of_lt_right dec_trivial hn) this),\n  refl\nend\n\n@[simp] theorem size_shiftl {m} (h : m ≠ 0) (n) :\n  size (shiftl m n) = size m + n :=\nsize_shiftl' (shiftl'_ne_zero_left _ h _)\n\ntheorem lt_size_self (n : ℕ) : n < 2^size n :=\nbegin\n  rw [← one_shiftl],\n  have : ∀ {n}, n = 0 → n < shiftl 1 (size n), { simp },\n  apply binary_rec _ _ n, {apply this rfl},\n  intros b n IH,\n  by_cases bit b n = 0, {apply this h},\n  rw [size_bit h, shiftl_succ],\n  exact bit_lt_bit0 _ IH\nend\n\ntheorem size_le {m n : ℕ} : size m ≤ n ↔ m < 2^n :=\n⟨λ h, lt_of_lt_of_le (lt_size_self _) (pow_le_pow_of_le_right dec_trivial h),\nbegin\n  rw [← one_shiftl], revert n,\n  apply binary_rec _ _ m,\n  { intros n h, simp },\n  { intros b m IH n h,\n    by_cases e : bit b m = 0, { simp [e] },\n    rw [size_bit e],\n    cases n with n,\n    { exact e.elim (nat.eq_zero_of_le_zero (le_of_lt_succ h)) },\n    { apply succ_le_succ (IH _),\n      apply lt_imp_lt_of_le_imp_le (λ h', bit0_le_bit _ h') h } }\nend⟩\n\ntheorem lt_size {m n : ℕ} : m < size n ↔ 2^m ≤ n :=\nby rw [← not_lt, decidable.iff_not_comm, not_lt, size_le]\n\ntheorem size_pos {n : ℕ} : 0 < size n ↔ 0 < n :=\nby rw lt_size; refl\n\ntheorem size_eq_zero {n : ℕ} : size n = 0 ↔ n = 0 :=\nby have := @size_pos n; simp [pos_iff_ne_zero] at this;\n   exact decidable.not_iff_not.1 this\n\ntheorem size_pow {n : ℕ} : size (2^n) = n+1 :=\nle_antisymm\n  (size_le.2 $ pow_lt_pow_of_lt_right dec_trivial (lt_succ_self _))\n  (lt_size.2 $ le_rfl)\n\ntheorem size_le_size {m n : ℕ} (h : m ≤ n) : size m ≤ size n :=\nsize_le.2 $ lt_of_le_of_lt h (lt_size_self _)\n\nlemma size_eq_bits_len (n : ℕ) : n.bits.length = n.size :=\nbegin\n  induction n using nat.binary_rec' with b n h ih, { simp, },\n  rw [size_bit, bits_append_bit _ _ h],\n  { simp [ih], },\n  { simpa [bit_eq_zero_iff], }\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/size.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7605452541161919}}
{"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.list.range\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\nnamespace list\n\n\nnamespace nat\n\n\n/-- The antidiagonal of a natural number `n` is the list of pairs `(i,j)` such that `i+j = n`. -/\ndef antidiagonal (n : ℕ) : List (ℕ × ℕ) :=\n  map (fun (i : ℕ) => (i, n - i)) (range (n + 1))\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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ prod.fst x + prod.snd x = n := sorry\n\n/-- The length of the antidiagonal of `n` is `n+1`. -/\n@[simp] theorem length_antidiagonal (n : ℕ) : length (antidiagonal n) = n + 1 := sorry\n\n/-- The antidiagonal of `0` is the list `[(0,0)]` -/\n@[simp] theorem antidiagonal_zero : antidiagonal 0 = [(0, 0)] :=\n  rfl\n\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\ntheorem nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) :=\n  nodup_map (function.left_inverse.injective fun (i : ℕ) => rfl) (nodup_range (n + 1))\n\n@[simp] theorem antidiagonal_succ {n : ℕ} : antidiagonal (n + 1) = (0, n + 1) :: map (prod.map Nat.succ id) (antidiagonal 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/data/list/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.760545253784766}}
{"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 ℝ^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 : ℝ) (im : ℝ)\n\nnotation `ℂ` := complex\n\nnamespace complex\n\nopen_locale complex_conjugate\n\nnoncomputable instance : decidable_eq ℂ := classical.dec_eq _\n\n/-- The equivalence between the complex numbers and `ℝ × ℝ`. -/\ndef equiv_real_prod : ℂ ≃ (ℝ × ℝ) :=\n{ to_fun := λ z, ⟨z.re, z.im⟩,\n  inv_fun := λ p, ⟨p.1, p.2⟩,\n  left_inv := λ ⟨x, y⟩, rfl,\n  right_inv := λ ⟨x, y⟩, rfl }\n\n@[simp] theorem equiv_real_prod_apply (z : ℂ) : equiv_real_prod z = (z.re, z.im) := rfl\ntheorem equiv_real_prod_symm_re (x y : ℝ) : (equiv_real_prod.symm (x, y)).re = x := rfl\ntheorem equiv_real_prod_symm_im (x y : ℝ) : (equiv_real_prod.symm (x, y)).im = y := rfl\n\n@[simp] theorem eta : ∀ z : ℂ, complex.mk z.re z.im = z\n| ⟨a, b⟩ := rfl\n\n@[ext]\ntheorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w\n| ⟨zr, zi⟩ ⟨_, _⟩ rfl rfl := rfl\n\ntheorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=\n⟨λ H, by simp [H], and.rec ext⟩\n\ninstance : has_coe ℝ ℂ := ⟨λ r, ⟨r, 0⟩⟩\n\n@[simp, norm_cast] lemma of_real_re (r : ℝ) : (r : ℂ).re = r := rfl\n@[simp, norm_cast] lemma of_real_im (r : ℝ) : (r : ℂ).im = 0 := rfl\nlemma of_real_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl\n\n@[simp, norm_cast] theorem of_real_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w :=\n⟨congr_arg re, congr_arg _⟩\n\ntheorem of_real_injective : function.injective (coe : ℝ → ℂ) :=\nλ z w, congr_arg re\n\ninstance : can_lift ℂ ℝ :=\n{ cond := λ z, z.im = 0,\n  coe := coe,\n  prf := λ z hz, ⟨z.re, ext rfl hz.symm⟩ }\n\ninstance : has_zero ℂ := ⟨(0 : ℝ)⟩\ninstance : inhabited ℂ := ⟨0⟩\n\n@[simp] lemma zero_re : (0 : ℂ).re = 0 := rfl\n@[simp] lemma zero_im : (0 : ℂ).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_zero : ((0 : ℝ) : ℂ) = 0 := rfl\n\n@[simp] theorem of_real_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := of_real_inj\ntheorem of_real_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr of_real_eq_zero\n\ninstance : has_one ℂ := ⟨(1 : ℝ)⟩\n\n@[simp] lemma one_re : (1 : ℂ).re = 1 := rfl\n@[simp] lemma one_im : (1 : ℂ).im = 0 := rfl\n@[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 1 := rfl\n\ninstance : has_add ℂ := ⟨λ z w, ⟨z.re + w.re, z.im + w.im⟩⟩\n\n@[simp] lemma add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl\n@[simp] lemma add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl\n\n@[simp] lemma bit0_re (z : ℂ) : (bit0 z).re = bit0 z.re := rfl\n@[simp] lemma bit1_re (z : ℂ) : (bit1 z).re = bit1 z.re := rfl\n@[simp] lemma bit0_im (z : ℂ) : (bit0 z).im = bit0 z.im := eq.refl _\n@[simp] lemma bit1_im (z : ℂ) : (bit1 z).im = bit0 z.im := add_zero _\n\n@[simp, norm_cast] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s :=\next_iff.2 $ by simp\n\n@[simp, norm_cast] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r :=\next_iff.2 $ by simp [bit0]\n\n@[simp, norm_cast] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r :=\next_iff.2 $ by simp [bit1]\n\ninstance : has_neg ℂ := ⟨λ z, ⟨-z.re, -z.im⟩⟩\n\n@[simp] lemma neg_re (z : ℂ) : (-z).re = -z.re := rfl\n@[simp] lemma neg_im (z : ℂ) : (-z).im = -z.im := rfl\n@[simp, norm_cast] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 $ by simp\n\ninstance : has_sub ℂ := ⟨λ z w, ⟨z.re - w.re, z.im - w.im⟩⟩\n\ninstance : has_mul ℂ := ⟨λ z w, ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩\n\n@[simp] lemma mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl\n@[simp] lemma mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl\n@[simp, norm_cast] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := ext_iff.2 $ by simp\n\nlemma of_real_mul_re (r : ℝ) (z : ℂ) : (↑r * z).re = r * z.re := by simp\nlemma of_real_mul_im (r : ℝ) (z : ℂ) : (↑r * z).im = r * z.im := by simp\nlemma of_real_mul' (r : ℝ) (z : ℂ) : (↑r * z) = ⟨r * z.re, r * z.im⟩ :=\next (of_real_mul_re _ _) (of_real_mul_im _ _)\n\n/-! ### The imaginary unit, `I` -/\n\n/-- The imaginary unit. -/\ndef I : ℂ := ⟨0, 1⟩\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 : ℂ) : I * z = ⟨-z.im, z.re⟩ :=\next_iff.2 $ by simp\n\nlemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm\n\nlemma mk_eq_add_mul_I (a b : ℝ) : complex.mk a b = a + b * I :=\next_iff.2 $ by simp\n\n@[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + 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 `ℕ` and `ℤ` actions to make sure there is no\ndiamond from the other actions they inherit through the `ℝ`-action on `ℂ` and action transitivity\ndefined in `data.complex.module.lean`. -/\ninstance : comm_ring ℂ :=\nby refine_struct\n  { zero := (0 : ℂ),\n    add := (+),\n    neg := has_neg.neg,\n    sub := has_sub.sub,\n    one := 1,\n    mul := (*),\n    zero_add := λ z, by { apply ext_iff.2, simp },\n    add_zero := λ z, by { apply ext_iff.2, simp },\n    nsmul := λ n z, ⟨n • z.re - 0 * z.im, n • z.im + 0 * z.re⟩,\n    npow := @npow_rec _ ⟨(1 : ℂ)⟩ ⟨(*)⟩,\n    zsmul := λ n z, ⟨n • z.re - 0 * z.im, n • z.im + 0 * z.re⟩ };\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 ℂ := by apply_instance\n\n/-- The \"real part\" map, considered as an additive group homomorphism. -/\ndef re_add_group_hom : ℂ →+ ℝ :=\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 : ℂ → ℝ) = re := rfl\n\n/-- The \"imaginary part\" map, considered as an additive group homomorphism. -/\ndef im_add_group_hom : ℂ →+ ℝ :=\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 : ℂ → ℝ) = im := rfl\n\n@[simp] lemma I_pow_bit0 (n : ℕ) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [pow_bit0', I_mul_I]\n\n@[simp] lemma I_pow_bit1 (n : ℕ) : 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 ℂ`. It\nis recommended to use the ring automorphism version `star_ring_aut`, available under the\nnotation `conj` in the locale `complex_conjugate`. -/\ninstance : star_ring ℂ :=\n{ star := λ z, ⟨z.re, -z.im⟩,\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] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl\n@[simp] lemma conj_im (z : ℂ) : (conj z).im = -z.im := rfl\n\nlemma conj_of_real (r : ℝ) : conj (r : ℂ) = 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 : ℂ) : conj (bit0 z) = bit0 (conj z) := ext_iff.2 $ by simp [bit0]\nlemma conj_bit1 (z : ℂ) : 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 : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=\n⟨λ h, ⟨z.re, ext rfl $ eq_zero_of_neg_eq (congr_arg im h)⟩,\n λ ⟨h, e⟩, by rw [e, conj_of_real]⟩\n\nlemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=\neq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩\n\nlemma eq_conj_iff_im {z : ℂ} : conj z = z ↔ z.im = 0 :=\n⟨λ h, add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)),\n  λ h, ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩\n\n@[simp] lemma star_def : (has_star.star : ℂ → ℂ) = conj := rfl\n\n/-! ### Norm squared -/\n\n/-- The norm squared function. -/\n@[pp_nodot] def norm_sq : monoid_with_zero_hom ℂ ℝ :=\n{ to_fun := λ 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 { dsimp, ring } }\n\nlemma norm_sq_apply (z : ℂ) : norm_sq z = z.re * z.re + z.im * z.im := rfl\n\n@[simp] lemma norm_sq_of_real (r : ℝ) : norm_sq r = r * r :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_mk (x y : ℝ) : norm_sq ⟨x, y⟩ = x * x + y * y := rfl\n\nlemma norm_sq_add_mul_I (x y : ℝ) : norm_sq (x + y * I) = x ^ 2 + y ^ 2 :=\nby rw [← mk_eq_add_mul_I, norm_sq_mk, sq, sq]\n\nlemma norm_sq_eq_conj_mul_self {z : ℂ} : (norm_sq z : ℂ) = 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 : ℂ) : 0 ≤ norm_sq z :=\nadd_nonneg (mul_self_nonneg _) (mul_self_nonneg _)\n\nlemma norm_sq_eq_zero {z : ℂ} : norm_sq z = 0 ↔ z = 0 :=\n⟨λ 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 λ h, h.symm ▸ norm_sq_zero⟩\n\n@[simp] lemma norm_sq_pos {z : ℂ} : 0 < norm_sq z ↔ z ≠ 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 : ℂ) : norm_sq (-z) = norm_sq z :=\nby simp [norm_sq]\n\n@[simp] lemma norm_sq_conj (z : ℂ) : norm_sq (conj z) = norm_sq z :=\nby simp [norm_sq]\n\nlemma norm_sq_mul (z w : ℂ) : norm_sq (z * w) = norm_sq z * norm_sq w :=\nnorm_sq.map_mul z w\n\nlemma norm_sq_add (z w : ℂ) : 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 : ℂ) : z.re * z.re ≤ norm_sq z :=\nle_add_of_nonneg_right (mul_self_nonneg _)\n\nlemma im_sq_le_norm_sq (z : ℂ) : z.im * z.im ≤ norm_sq z :=\nle_add_of_nonneg_left (mul_self_nonneg _)\n\ntheorem mul_conj (z : ℂ) : 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 : ℂ) : z + conj z = (2 * z.re : ℝ) :=\next_iff.2 $ by simp [two_mul]\n\n/-- The coercion `ℝ → ℂ` as a `ring_hom`. -/\ndef of_real : ℝ →+* ℂ := ⟨coe, of_real_one, of_real_mul, of_real_zero, of_real_add⟩\n\n@[simp] lemma of_real_eq_coe (r : ℝ) : 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 : ℂ) : (z - w).re = z.re - w.re := rfl\n@[simp] lemma sub_im (z w : ℂ) : (z - w).im = z.im - w.im := rfl\n@[simp, norm_cast] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := ext_iff.2 $ by simp\n@[simp, norm_cast] lemma of_real_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = r ^ n :=\nby induction n; simp [*, of_real_mul, pow_succ]\n\ntheorem sub_conj (z : ℂ) : z - conj z = (2 * z.im : ℝ) * I :=\next_iff.2 $ by simp [two_mul, sub_eq_add_neg]\n\nlemma norm_sq_sub (z w : ℂ) : 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_equiv.map_neg, mul_neg_eq_neg_mul_symm, neg_re,\n                tactic.ring.add_neg_eq_sub, norm_sq_neg] }\n\n/-! ### Inversion -/\n\nnoncomputable instance : has_inv ℂ := ⟨λ z, conj z * ((norm_sq z)⁻¹:ℝ)⟩\n\ntheorem inv_def (z : ℂ) : z⁻¹ = conj z * ((norm_sq z)⁻¹:ℝ) := rfl\n@[simp] lemma inv_re (z : ℂ) : (z⁻¹).re = z.re / norm_sq z := by simp [inv_def, division_def]\n@[simp] lemma inv_im (z : ℂ) : (z⁻¹).im = -z.im / norm_sq z := by simp [inv_def, division_def]\n\n@[simp, norm_cast] lemma of_real_inv (r : ℝ) : ((r⁻¹ : ℝ) : ℂ) = r⁻¹ :=\next_iff.2 $ by simp\n\nprotected \n\nprotected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 :=\nby rw [inv_def, ← mul_assoc, mul_conj, ← 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 ℂ :=\n{ inv := has_inv.inv,\n  exists_pair_ne := ⟨0, 1, mt (congr_arg re) zero_ne_one⟩,\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 : ℤ) : I ^ (bit0 n) = (-1) ^ n :=\nby rw [zpow_bit0', I_mul_I]\n\n@[simp] lemma I_zpow_bit1 (n : ℤ) : I ^ (bit1 n) = (-1) ^ n * I :=\nby rw [zpow_bit1', I_mul_I]\n\nlemma div_re (z w : ℂ) : (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 : ℂ) : (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 : ℝ) : ((r / s : ℝ) : ℂ) = r / s :=\nof_real.map_div r s\n\n@[simp, norm_cast] lemma of_real_zpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n :=\nof_real.map_zpow r n\n\n@[simp] lemma div_I (z : ℂ) : 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⁻¹ = -I :=\nby simp [inv_eq_one_div]\n\n@[simp] lemma norm_sq_inv (z : ℂ) : norm_sq z⁻¹ = (norm_sq z)⁻¹ :=\nnorm_sq.map_inv z\n\n@[simp] lemma norm_sq_div (z w : ℂ) : 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 : ℕ) : ((n : ℝ) : ℂ) = n :=\nof_real.map_nat_cast n\n\n@[simp, norm_cast] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n :=\nby rw [← of_real_nat_cast, of_real_re]\n\n@[simp, norm_cast] lemma nat_cast_im (n : ℕ) : (n : ℂ).im = 0 :=\nby rw [← of_real_nat_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_int_cast (n : ℤ) : ((n : ℝ) : ℂ) = n :=\nof_real.map_int_cast n\n\n@[simp, norm_cast] lemma int_cast_re (n : ℤ) : (n : ℂ).re = n :=\nby rw [← of_real_int_cast, of_real_re]\n\n@[simp, norm_cast] lemma int_cast_im (n : ℤ) : (n : ℂ).im = 0 :=\nby rw [← of_real_int_cast, of_real_im]\n\n@[simp, norm_cast] theorem of_real_rat_cast (n : ℚ) : ((n : ℝ) : ℂ) = n :=\nof_real.map_rat_cast n\n\n@[simp, norm_cast] lemma rat_cast_re (q : ℚ) : (q : ℂ).re = q :=\nby rw [← of_real_rat_cast, of_real_re]\n\n@[simp, norm_cast] lemma rat_cast_im (q : ℚ) : (q : ℂ).im = 0 :=\nby rw [← of_real_rat_cast, of_real_im]\n\n/-! ### Characteristic zero -/\n\ninstance char_zero_complex : char_zero ℂ :=\nchar_zero_of_inj_zero $ λ n h,\nby rwa [← 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 : ℂ) : (z.re : ℂ) = (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:ℂ) 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 : ℂ) : (z.im : ℂ) = (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 ≠ 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 : ℂ) : ℝ := (norm_sq z).sqrt\n\nlocal notation `abs'` := has_abs.abs\n\n@[simp, norm_cast] lemma abs_of_real (r : ℝ) : abs r = |r| :=\nby simp [abs, norm_sq_of_real, real.sqrt_mul_self_eq_abs]\n\nlemma abs_of_nonneg {r : ℝ} (h : 0 ≤ r) : abs r = r :=\n(abs_of_real _).trans (abs_of_nonneg h)\n\nlemma abs_of_nat (n : ℕ) : complex.abs n = n :=\ncalc complex.abs n = complex.abs (n:ℝ) : by rw [of_real_nat_cast]\n  ... = _ : abs_of_nonneg (nat.cast_nonneg n)\n\nlemma mul_self_abs (z : ℂ) : abs z * abs z = norm_sq z :=\nreal.mul_self_sqrt (norm_sq_nonneg _)\n\nlemma sq_abs (z : ℂ) : abs z ^ 2 = norm_sq z :=\nreal.sq_sqrt (norm_sq_nonneg _)\n\n@[simp] lemma sq_abs_sub_sq_re (z : ℂ) : abs z ^ 2 - z.re ^ 2 = z.im ^ 2 :=\nby rw [sq_abs, norm_sq_apply, ← sq, ← sq, add_sub_cancel']\n\n@[simp] lemma sq_abs_sub_sq_im (z : ℂ) : abs z ^ 2 - z.im ^ 2 = z.re ^ 2 :=\nby rw [← 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 : ℝ) : by rw [of_real_bit0, of_real_one]\n... = (2 : ℝ) : abs_of_nonneg (by norm_num)\n\nlemma abs_nonneg (z : ℂ) : 0 ≤ abs z :=\nreal.sqrt_nonneg _\n\n@[simp] lemma abs_eq_zero {z : ℂ} : abs z = 0 ↔ z = 0 :=\n(real.sqrt_eq_zero $ norm_sq_nonneg _).trans norm_sq_eq_zero\n\nlemma abs_ne_zero {z : ℂ} : abs z ≠ 0 ↔ z ≠ 0 :=\nnot_congr abs_eq_zero\n\n@[simp] lemma abs_conj (z : ℂ) : abs (conj z) = abs z :=\nby simp [abs]\n\n@[simp] lemma abs_mul (z w : ℂ) : abs (z * w) = abs z * abs w :=\nby rw [abs, norm_sq_mul, real.sqrt_mul (norm_sq_nonneg _)]; refl\n\n@[simp] lemma abs_pow (z : ℂ) (n : ℕ) : abs (z ^ n) = abs z ^ n :=\nmonoid_hom.map_pow ⟨abs, abs_one, abs_mul⟩ z n\n\n@[simp] lemma abs_zpow (z : ℂ) (n : ℤ) : abs (z ^ n) = abs z ^ n :=\nmonoid_with_zero_hom.map_zpow ⟨abs, abs_zero, abs_one, abs_mul⟩ z n\n\nlemma abs_re_le_abs (z : ℂ) : |z.re| ≤ 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 : ℂ) : |z.im| ≤ 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 : ℂ) : z.re ≤ abs z :=\n(abs_le.1 (abs_re_le_abs _)).2\n\nlemma im_le_abs (z : ℂ) : z.im ≤ 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 : ℂ) : abs (z + w) ≤ 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 ℝ _ _)],\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 := λ _, abs_eq_zero,\n  abv_add     := abs_add,\n  abv_mul     := abs_mul }\nopen is_absolute_value\n\n@[simp] lemma abs_abs (z : ℂ) : |(abs z)| = abs z :=\n_root_.abs_of_nonneg (abs_nonneg _)\n\n@[simp] lemma abs_pos {z : ℂ} : 0 < abs z ↔ z ≠ 0 := abv_pos abs\n@[simp] lemma abs_neg : ∀ z, abs (-z) = abs z := abv_neg abs\nlemma abs_sub_comm : ∀ z w, abs (z - w) = abs (w - z) := abv_sub abs\nlemma abs_sub_le : ∀ a b c, abs (a - c) ≤ abs (a - b) + abs (b - c) := abv_sub_le abs\n@[simp] theorem abs_inv : ∀ z, abs z⁻¹ = (abs z)⁻¹ := abv_inv abs\n@[simp] theorem abs_div : ∀ z w, abs (z / w) = abs z / abs w := abv_div abs\n\nlemma abs_abs_sub_le_abs_sub : ∀ z w, |abs z - abs w| ≤ abs (z - w) :=\nabs_abv_sub_le_abv_sub abs\n\nlemma abs_le_abs_re_add_abs_im (z : ℂ) : abs z ≤ |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 : ℂ) : |z.re / z.abs| ≤ 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 : ℂ) : |z.im / z.abs| ≤ 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 : ℕ) : abs (n : ℂ) = n :=\nby rw [← of_real_nat_cast, abs_of_nonneg (nat.cast_nonneg n)]\n\n@[simp, norm_cast] lemma int_cast_abs (n : ℤ) : ↑|n| = abs n :=\nby rw [← of_real_int_cast, abs_of_real, int.cast_abs]\n\nlemma norm_sq_eq_abs (x : ℂ) : 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 ℂ so that `z ≤ w` exactly if `w - z` is real and nonnegative.\nComplex numbers with different imaginary parts are incomparable.\n-/\nprotected def partial_order : partial_order ℂ :=\n{ le := λ z w, z.re ≤ w.re ∧ z.im = w.im,\n  lt := λ z w, z.re < w.re ∧ z.im = w.im,\n  lt_iff_le_not_le := λ z w, by { dsimp, rw lt_iff_le_not_le, tauto },\n  le_refl := λ x, ⟨le_rfl, rfl⟩,\n  le_trans := λ x y z h₁ h₂, ⟨h₁.1.trans h₂.1, h₁.2.trans h₂.2⟩,\n  le_antisymm := λ z w h₁ h₂, ext (h₁.1.antisymm h₂.1) h₁.2 }\n\nsection complex_order\n\nlocalized \"attribute [instance] complex.partial_order\" in complex_order\n\nlemma le_def {z w : ℂ} : z ≤ w ↔ z.re ≤ w.re ∧ z.im = w.im := iff.rfl\nlemma lt_def {z w : ℂ} : z < w ↔ z.re < w.re ∧ z.im = w.im := iff.rfl\n\n@[simp, norm_cast] lemma real_le_real {x y : ℝ} : (x : ℂ) ≤ (y : ℂ) ↔ x ≤ y := by simp [le_def]\n\n@[simp, norm_cast] lemma real_lt_real {x y : ℝ} : (x : ℂ) < (y : ℂ) ↔ x < y := by simp [lt_def]\n\n@[simp, norm_cast] lemma zero_le_real {x : ℝ} : (0 : ℂ) ≤ (x : ℂ) ↔ 0 ≤ x := real_le_real\n@[simp, norm_cast] lemma zero_lt_real {x : ℝ} : (0 : ℂ) < (x : ℂ) ↔ 0 < x := real_lt_real\n\nlemma not_le_iff {z w : ℂ} : ¬(z ≤ w) ↔ w.re < z.re ∨ z.im ≠ w.im :=\nby rw [le_def, not_and_distrib, not_le]\n\nlemma not_le_zero_iff {z : ℂ} : ¬z ≤ 0 ↔ 0 < z.re ∨ z.im ≠ 0 := not_le_iff\n\n/--\nWith `z ≤ w` iff `w - z` is real and nonnegative, `ℂ` is an ordered ring.\n-/\nprotected def ordered_comm_ring : ordered_comm_ring ℂ :=\n{ zero_le_one := ⟨zero_le_one, rfl⟩,\n  add_le_add_left := λ w z h y, ⟨add_le_add_left h.1 _, congr_arg2 (+) rfl h.2⟩,\n  mul_pos := λ z w hz hw,\n    by simp [lt_def, mul_re, mul_im, ← hz.2, ← 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 ≤ w` iff `w - z` is real and nonnegative, `ℂ` 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. `ℂ`,\nbut we don't yet have `C^*`-algebras in mathlib.\n-/\nprotected def star_ordered_ring : star_ordered_ring ℂ :=\n{ star_mul_self_nonneg := λ z, ⟨by simp [add_nonneg, mul_self_nonneg], by simp [mul_comm]⟩ }\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 ℂ abs) : is_cau_seq abs' (λ n, (f n).re) :=\nλ ε ε0, (f.cauchy ε0).imp $ λ 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 ℂ abs) : is_cau_seq abs' (λ n, (f n).im) :=\nλ ε ε0, (f.cauchy ε0).imp $ λ 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 ℂ abs) : cau_seq ℝ abs' :=\n⟨_, is_cau_seq_re f⟩\n\n/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/\nnoncomputable def cau_seq_im (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=\n⟨_, is_cau_seq_im f⟩\n\nlemma is_cau_seq_abs {f : ℕ → ℂ} (hf : is_cau_seq abs f) :\n  is_cau_seq abs' (abs ∘ f) :=\nλ ε ε0, let ⟨i, hi⟩ := hf ε ε0 in\n⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩\n\n/-- The limit of a Cauchy sequence of complex numbers. -/\nnoncomputable def lim_aux (f : cau_seq ℂ abs) : ℂ :=\n⟨cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)⟩\n\ntheorem equiv_lim_aux (f : cau_seq ℂ abs) : f ≈ cau_seq.const abs (lim_aux f) :=\nλ ε ε0, (exists_forall_ge_and\n  (cau_seq.equiv_lim ⟨_, is_cau_seq_re f⟩ _ (half_pos ε0))\n  (cau_seq.equiv_lim ⟨_, is_cau_seq_im f⟩ _ (half_pos ε0))).imp $\nλ i H j ij, begin\n  cases H _ ij with H₁ H₂,\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₁ H₂,\n  rwa add_halves at this,\nend\n\nnoncomputable instance : cau_seq.is_complete ℂ abs :=\n⟨λ f, ⟨lim_aux f, equiv_lim_aux f⟩⟩\n\nopen cau_seq\n\nlemma lim_eq_lim_im_add_lim_re (f : cau_seq ℂ abs) : lim f =\n  ↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I :=\nlim_eq_of_equiv_const $\ncalc f ≈ _ : equiv_lim_aux f\n... = cau_seq.const abs (↑(lim (cau_seq_re f)) + ↑(lim (cau_seq_im f)) * I) :\n  cau_seq.ext (λ _, complex.ext (by simp [lim_aux, cau_seq_re]) (by simp [lim_aux, cau_seq_im]))\n\nlemma lim_re (f : cau_seq ℂ 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 ℂ 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 ℂ abs) : is_cau_seq abs (λ n, conj (f n)) :=\nλ ε ε0, let ⟨i, hi⟩ := f.2 ε ε0 in\n⟨i, λ j hj, by rw [← ring_equiv.map_sub, abs_conj]; exact hi j hj⟩\n\n/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/\nnoncomputable def cau_seq_conj (f : cau_seq ℂ abs) : cau_seq ℂ abs :=\n⟨_, is_cau_seq_conj f⟩\n\nlemma lim_conj (f : cau_seq ℂ 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 ℂ abs) : cau_seq ℝ abs' :=\n⟨_, is_cau_seq_abs f.2⟩\n\nlemma lim_abs (f : cau_seq ℂ abs) : lim (cau_seq_abs f) = abs (lim f) :=\nlim_eq_of_equiv_const (λ ε ε0,\nlet ⟨i, hi⟩ := equiv_lim f ε ε0 in\n⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩)\n\n@[simp, norm_cast] lemma of_real_prod {α : Type*} (s : finset α) (f : α → ℝ) :\n  ((∏ i in s, f i : ℝ) : ℂ) = ∏ i in s, (f i : ℂ) :=\nring_hom.map_prod of_real _ _\n\n@[simp, norm_cast] lemma of_real_sum {α : Type*} (s : finset α) (f : α → ℝ) :\n  ((∑ i in s, f i : ℝ) : ℂ) = ∑ i in s, (f i : ℂ) :=\nring_hom.map_sum of_real _ _\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/data/complex/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7604728045139276}}
{"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\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\nopen list set\nopen_locale computability\n\nuniverse u\n\nvariables {α β γ : Type*} [dec : decidable_eq α]\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 (α : Type u) : Type u\n| zero : regular_expression\n| epsilon : regular_expression\n| char : α → regular_expression\n| plus : regular_expression → regular_expression → regular_expression\n| comp : regular_expression → regular_expression → regular_expression\n| star : regular_expression → regular_expression\n\nnamespace regular_expression\nvariables {a b : α}\n\ninstance : inhabited (regular_expression α) := ⟨zero⟩\n\ninstance : has_add (regular_expression α) := ⟨plus⟩\ninstance : has_mul (regular_expression α) := ⟨comp⟩\ninstance : has_one (regular_expression α) := ⟨epsilon⟩\ninstance : has_zero (regular_expression α) := ⟨zero⟩\ninstance : has_pow (regular_expression α) ℕ := ⟨λ n r, npow_rec r n⟩\n\nattribute [pattern] has_mul.mul\n\n@[simp] lemma zero_def : (zero : regular_expression α) = 0 := rfl\n@[simp] lemma one_def : (epsilon : regular_expression α) = 1 := rfl\n\n@[simp] lemma plus_def (P Q : regular_expression α) : plus P Q = P + Q := rfl\n@[simp] lemma comp_def (P Q : regular_expression α) : comp P Q = P * Q := rfl\n\n/-- `matches P` provides a language which contains all strings that `P` matches -/\n@[simp] def matches : regular_expression α → language α\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∗\n\n@[simp] lemma matches_zero : (0 : regular_expression α).matches = 0 := rfl\n@[simp] lemma matches_epsilon : (1 : regular_expression α).matches = 1 := rfl\n@[simp] lemma matches_char (a : α) : (char a).matches = {[a]} := rfl\n@[simp] lemma matches_add (P Q : regular_expression α) :\n  (P + Q).matches = P.matches + Q.matches := rfl\n@[simp] lemma matches_mul (P Q : regular_expression α) :\n  (P * Q).matches = P.matches * Q.matches := rfl\n@[simp] lemma matches_pow (P : regular_expression α) :\n  ∀ n : ℕ, (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@[simp] lemma matches_star (P : regular_expression α) : P.star.matches = P.matches∗ := rfl\n\n/-- `match_epsilon P` is true if and only if `P` matches the empty string -/\ndef match_epsilon : regular_expression α → 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 α → α → regular_expression α\n| 0 _ := 0\n| 1 _ := 0\n| (char a₁) a₂ := if a₁ = a₂ 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@[simp] lemma deriv_zero (a : α) : deriv 0 a = 0 := rfl\n@[simp] lemma deriv_one (a : α) : deriv 1 a = 0 := rfl\n@[simp] lemma deriv_char_self (a : α) : deriv (char a) a = 1 := if_pos rfl\n@[simp] lemma deriv_char_of_ne (h : a ≠ b) : deriv (char a) b = 0 := if_neg h\n@[simp] lemma deriv_add (P Q : regular_expression α) (a : α) :\n  deriv (P + Q) a = deriv P a + deriv Q a := rfl\n@[simp] lemma deriv_star (P : regular_expression α) (a : α) :\n  deriv (P.star) a = deriv P a * star P := rfl\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 α → list α → bool\n| P [] := match_epsilon P\n| P (a::as) := rmatch (P.deriv a) as\n\n@[simp] lemma zero_rmatch (x : list α) : rmatch 0 x = ff :=\nby induction x; simp [rmatch, match_epsilon, *]\n\n\n\nlemma char_rmatch_iff (a : α) (x : list α) : rmatch (char a) x ↔ 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 α) (x : list α) :\n  (P + Q).rmatch x ↔ P.rmatch x ∨ Q.rmatch x :=\nbegin\n  induction x with _ _ ih generalizing P Q,\n  { simp only [rmatch, match_epsilon, bor_coe_iff] },\n  { repeat {rw rmatch},\n    rw deriv,\n    exact ih _ _ }\nend\n\nlemma mul_rmatch_iff (P Q : regular_expression α) (x : list α) :\n  (P * Q).rmatch x ↔ ∃ t u : list α, x = t ++ u ∧ P.rmatch t ∧ 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 ⟨ [], [], rfl, _ ⟩,\n      rw [rmatch, rmatch],\n      rwa band_coe_iff at h },\n    { rintro ⟨ t, u, h₁, h₂ ⟩,\n      cases list.append_eq_nil.1 h₁.symm with ht hu,\n      subst ht,\n      subst hu,\n      repeat {rw rmatch at h₂},\n      simp [h₂] } },\n  { rw [rmatch, deriv],\n    split_ifs with hepsilon,\n    { rw [add_rmatch_iff, ih],\n      split,\n      { rintro (⟨ t, u, _ ⟩ | h),\n        { exact ⟨ a :: t, u, by tauto ⟩ },\n        { exact ⟨ [], a :: x, rfl, hepsilon, h ⟩ } },\n      { rintro ⟨ t, u, h, hP, hQ ⟩,\n        cases t with b t,\n        { right,\n          rw list.nil_append at h,\n          rw ←h at hQ,\n          exact hQ },\n        { left,\n          simp only [list.cons_append] at h,\n          refine ⟨ t, u, h.2, _, hQ ⟩,\n          rw rmatch at hP,\n          convert hP,\n          exact h.1 } } },\n    { rw ih,\n      split;\n      rintro ⟨ t, u, h, hP, hQ ⟩,\n      { exact ⟨ a :: t, u, by tauto ⟩ },\n      { cases t with b t,\n        { contradiction },\n        { simp only [list.cons_append] at h,\n          refine ⟨ t, u, h.2, _, hQ ⟩,\n          rw rmatch at hP,\n          convert hP,\n          exact h.1 } } } }\nend\n\nlemma star_rmatch_iff (P : regular_expression α) : ∀ (x : list α),\n  (star P).rmatch x ↔ ∃ S : list (list α), x = S.join ∧ ∀ t ∈ S, t ≠ [] ∧ P.rmatch t\n| x :=\nbegin\n  have A : ∀ (m n : ℕ), 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 := λ 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 ⟨ t, u, hs, ht, hu ⟩,\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 ⟨ S', hsum, helem ⟩,\n      use (a :: t) :: S',\n      split,\n      { simp [hs, hsum] },\n      { intros t' ht',\n        cases ht' with ht' ht',\n        { rw ht',\n          exact ⟨ dec_trivial, ht ⟩ },\n        { exact helem _ ht' } } } },\n  { rintro ⟨ S, hsum, helem ⟩,\n    cases x with a x,\n    { dec_trivial },\n    { rw [rmatch, deriv, mul_rmatch_iff],\n      cases S with t' U,\n      { exact ⟨ [], [], by tauto ⟩ },\n      { cases t' with b t,\n        { simp only [forall_eq_or_imp, list.mem_cons_iff] at helem,\n          simp only [eq_self_iff_true, not_true, ne.def, false_and] at helem,\n          cases helem },\n        simp only [list.join, list.cons_append] at hsum,\n        refine ⟨ t, U.join, hsum.2, _, _ ⟩,\n        { specialize helem (b :: t) (by simp),\n          rw rmatch at helem,\n          convert helem.2,\n          exact hsum.1 },\n        { have hwf : U.join.length < (list.cons a x).length,\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 ⟨ U, rfl, λ t h, helem t _ ⟩,\n          right,\n          assumption } } } }\nend\nusing_well_founded\n{ rel_tac := λ _ _, `[exact ⟨(λ L₁ L₂ : list _, L₁.length < L₂.length), inv_image.wf _ nat.lt_wf⟩] }\n\n@[simp] lemma rmatch_iff_matches (P : regular_expression α) :\n  ∀ x : list α, P.rmatch x ↔ x ∈ 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₁ ih₂\n  { rw [add_rmatch_iff, ih₁, ih₂],\n    refl },\n  case comp : P Q ih₁ ih₂\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 ⟨ x, y, hsum, hmatch₁, hmatch₂ ⟩,\n      rw ih₁ at hmatch₁,\n      rw ih₂ at hmatch₂,\n      exact ⟨ x, hmatch₁, y, hmatch₂, hsum.symm ⟩ },\n    { rintro ⟨ x, hmatch₁, y, hmatch₂, hsum ⟩,\n      rw ←ih₁ at hmatch₁,\n      rw ←ih₂ at hmatch₂,\n      exact ⟨ x, y, hsum.symm, hmatch₁, hmatch₂ ⟩ } },\n  case star : _ ih\n  { rw [star_rmatch_iff, language.kstar_def_nonempty],\n    split,\n    all_goals\n    { rintro ⟨ S, hx, hS ⟩,\n      refine ⟨ S, hx, _ ⟩,\n      intro y,\n      specialize hS y },\n    { rw ←ih y,\n      tauto },\n    { rw ih y,\n      tauto } }\nend\n\ninstance (P : regular_expression α) : decidable_pred P.matches :=\nbegin\n  intro x,\n  change decidable (x ∈ P.matches),\n  rw ←rmatch_iff_matches,\n  exact eq.decidable _ _\nend\n\nomit dec\n\n/-- Map the alphabet of a regular expression. -/\n@[simp] def map (f : α → β) : regular_expression α → regular_expression β\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\n@[simp] protected lemma map_pow (f : α → β) (P : regular_expression α) :\n  ∀ n : ℕ, map f (P ^ n) = map f P ^ n\n| 0 := rfl\n| (n + 1) := (congr_arg ((*) (map f P)) (map_pow n) : _)\n\n@[simp] lemma map_id : ∀ (P : regular_expression α), 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\n@[simp] lemma map_map (g : β → γ) (f : α → β) :\n  ∀ (P : regular_expression α), (P.map f).map g = P.map (g ∘ 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\n/-- The language of the map is the map of the language. -/\n@[simp] lemma matches_map (f : α → β) :\n  ∀ P : regular_expression α, (P.map f).matches = language.map f P.matches\n| 0 := (map_zero _).symm\n| 1 := (map_one _).symm\n| (char a) := by { rw eq_comm, 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) := begin\n    simp_rw [map, matches, matches_map],\n    rw [language.kstar_eq_supr_pow, language.kstar_eq_supr_pow],\n    simp_rw ←map_pow,\n    exact image_Union.symm,\n  end\n\nend regular_expression\n", "meta": {"author": "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/regular_expressions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942171172603, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7604162389833363}}
{"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önne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.basic\nimport topology.algebra.order.proj_Icc\n\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\nnoncomputable theory\nopen_locale classical topology filter\nopen set filter\n\nopen_locale real\n\nnamespace real\n\n/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.\nIt defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/\n@[pp_nodot] noncomputable def arcsin : ℝ → ℝ :=\ncoe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm\n\nlemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _\n\n@[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) :=\nby { rw [arcsin, range_comp coe], simp [Icc] }\n\nlemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2\n\nlemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1\n\nlemma arcsin_proj_Icc (x : ℝ) :\n  arcsin (proj_Icc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x :=\nby rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]\n\nlemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 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 ⟨x, hx⟩)\n\nlemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=\nsin_arcsin' ⟨hx₁, hx₂⟩\n\nlemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 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 : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=\narcsin_sin' ⟨hx₁, hx₂⟩\n\nlemma strict_mono_on_arcsin : strict_mono_on arcsin (Icc (-1) 1) :=\n(subtype.strict_mono_coe _).comp_strict_mono_on $\n  sin_order_iso.symm.strict_mono.strict_mono_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_on_arcsin.inj_on\n\nlemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :\n  arcsin x = arcsin y ↔ x = y :=\ninj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩\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 : ℝ} : continuous_at arcsin x :=\ncontinuous_arcsin.continuous_at\n\nlemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin y = x :=\nbegin\n  subst y,\n  exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))\nend\n\n@[simp] lemma arcsin_zero : arcsin 0 = 0 :=\narcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩\n\n@[simp] lemma arcsin_one : arcsin 1 = π / 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 : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 :=\nby rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]\n\nlemma arcsin_neg_one : arcsin (-1) = -(π / 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 : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) :=\nby rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]\n\n@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=\nbegin\n  cases le_total x (-1) with hx₁ hx₁,\n  { rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] },\n  cases le_total 1 x with hx₂ hx₂,\n  { rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] },\n  refine arcsin_eq_of_sin_eq _ _,\n  { rw [sin_neg, sin_arcsin hx₁ hx₂] },\n  { exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ }\nend\n\nlemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin x ≤ y ↔ x ≤ sin y :=\nby rw [← arcsin_sin' hy, strict_mono_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]\n\nlemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :\n  arcsin x ≤ y ↔ x ≤ sin y :=\nbegin\n  cases le_total x (-1) with hx₁ hx₁,\n  { simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] },\n  cases lt_or_le 1 x with hx₂ hx₂,\n  { simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] },\n  exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)\nend\n\nlemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :\n  x ≤ arcsin y ↔ sin x ≤ y :=\nby rw [← neg_le_neg_iff, ← arcsin_neg,\n  arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩,\n  sin_neg, neg_le_neg_iff]\n\nlemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :\n  x ≤ arcsin y ↔ sin x ≤ y :=\nby rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,\n  sin_neg, neg_le_neg_iff]\n\nlemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin x < y ↔ 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 : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :\n  arcsin x < y ↔ 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 : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :\n  x < arcsin y ↔ 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 : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :\n  x < arcsin y ↔ 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 : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :\n  arcsin x = y ↔ 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 : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=\n(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero]\n\n@[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=\nneg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg\n\n@[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 :=\nby simp [le_antisymm_iff]\n\n@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=\neq_comm.trans arcsin_eq_zero_iff\n\n@[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=\nlt_iff_lt_of_le_iff_le arcsin_nonpos\n\n@[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=\nlt_iff_lt_of_le_iff_le arcsin_nonneg\n\n@[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ 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 : ℝ} : -(π / 2) < arcsin x ↔ -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 : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=\n⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩\n\n@[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=\neq_comm.trans arcsin_eq_pi_div_two\n\n@[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ 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 : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=\n⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩\n\n@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=\neq_comm.trans arcsin_eq_neg_pi_div_two\n\n@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=\n(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two\n\n@[simp] \n\nlemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) :=\nλ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin,\n  arcsin_sin h.1.le h.2.le]\n\n/-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/\n@[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ :=\n{ to_fun := sin,\n  inv_fun := arcsin,\n  source := Ioo (-(π / 2)) (π / 2),\n  target := Ioo (-1) 1,\n  map_source' := maps_to_sin_Ioo,\n  map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩,\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 := 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 : ℝ) : 0 ≤ cos (arcsin x) :=\ncos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩\n\n-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.\nlemma cos_arcsin (x : ℝ) : cos (arcsin x) = sqrt (1 - x ^ 2) :=\nbegin\n  by_cases hx₁ : -1 ≤ x, swap,\n  { rw not_le at hx₁,\n    rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos],\n    nlinarith },\n  by_cases hx₂ : x ≤ 1, swap,\n  { rw not_le at hx₂,\n    rw [arcsin_of_one_le hx₂.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 [← eq_sub_iff_add_eq', ← 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₁ hx₂],\nend\n\n-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.\nlemma tan_arcsin (x : ℝ) : tan (arcsin x) = x / sqrt (1 - x ^ 2) :=\nbegin\n  rw [tan_eq_sin_div_cos, cos_arcsin],\n  by_cases hx₁ : -1 ≤ x, swap,\n  { have h : sqrt (1 - x ^ 2) = 0, { exact sqrt_eq_zero_of_nonpos (by nlinarith) }, rw h, simp },\n  by_cases hx₂ : x ≤ 1, swap,\n  { have h : sqrt (1 - x ^ 2) = 0, { exact sqrt_eq_zero_of_nonpos (by nlinarith) }, rw h, simp },\n  rw sin_arcsin hx₁ hx₂\nend\n\n/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.\n  It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/\n@[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ :=\nπ / 2 - arcsin x\n\nlemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl\n\nlemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=\nby simp [arccos]\n\nlemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=\nby unfold arccos; linarith [neg_pi_div_two_le_arcsin x]\n\nlemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=\nby unfold arccos; linarith [arcsin_le_pi_div_two x]\n\n@[simp] lemma arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 :=\nby simp [arccos]\n\nlemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=\nby rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]\n\nlemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=\nby rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith\n\nlemma strict_anti_on_arccos : strict_anti_on arccos (Icc (-1) 1) :=\nλ x hx y hy h, sub_lt_sub_left (strict_mono_on_arcsin hx hy h) _\n\nlemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_anti_on_arccos.inj_on\n\nlemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :\n  arccos x = arccos y ↔ x = y :=\narccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩\n\n@[simp] lemma arccos_zero : arccos 0 = π / 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) = π := by simp [arccos, add_halves]\n\n@[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x :=\nby simp [arccos, sub_eq_zero]\n\n@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 :=\nby simp [arccos]\n\n@[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 :=\nby rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]\n\nlemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=\nby rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]\n\nlemma arccos_of_one_le {x : ℝ} (hx : 1 ≤ x) : arccos x = 0 :=\nby rw [arccos, arcsin_of_one_le hx, sub_self]\n\nlemma arccos_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arccos x = π :=\nby rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves']\n\n-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.\nlemma sin_arccos (x : ℝ) : sin (arccos x) = sqrt (1 - x ^ 2) :=\nbegin\n  by_cases hx₁ : -1 ≤ x, swap,\n  { rw not_le at hx₁,\n    rw [arccos_of_le_neg_one hx₁.le, sin_pi, sqrt_eq_zero_of_nonpos],\n    nlinarith },\n  by_cases hx₂ : x ≤ 1, swap,\n  { rw not_le at hx₂,\n    rw [arccos_of_one_le hx₂.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]\nend\n\n@[simp] lemma arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos]\n\n@[simp] lemma arccos_lt_pi_div_two {x : ℝ} : arccos x < π / 2 ↔ 0 < x := by simp [arccos]\n\n@[simp] lemma arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ sqrt 2 / 2 ≤ x :=\nby { rw [arccos, ← pi_div_four_le_arcsin], split; { intro, linarith } }\n\n@[continuity]\nlemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin\n\n-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.\nlemma tan_arccos (x : ℝ) : tan (arccos x) = sqrt (1 - x ^ 2) / x :=\nby rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div]\n\n-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.\nlemma arccos_eq_arcsin {x : ℝ} (h : 0 ≤ x) :\n  arccos x = arcsin (sqrt (1 - x ^ 2)) :=\n(arcsin_eq_of_sin_eq (sin_arccos _)\n  ⟨(left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by norm_num))).trans (arccos_nonneg _),\n   arccos_le_pi_div_two.2 h⟩).symm\n\n-- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`.\nlemma arcsin_eq_arccos {x : ℝ} (h : 0 ≤ x) :\n  arcsin x = arccos (sqrt (1 - x ^ 2)) :=\nbegin\n  rw [eq_comm, ← cos_arcsin],\n  exact arccos_cos (arcsin_nonneg.2 h)\n    ((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two))\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/inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7604162258339582}}
{"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.basic\nimport analysis.special_functions.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\nassert_not_exists has_fderiv_at\nassert_not_exists conformal_at\n\nnoncomputable theory\nopen real set\nopen_locale big_operators\nopen_locale real\nopen_locale real_inner_product_space\n\nnamespace inner_product_geometry\n\nvariables {V : Type*} [normed_add_comm_group V] [inner_product_space ℝ V] {x y : V}\n\n/-- The undirected angle between two vectors. If either vector is 0,\nthis is π/2. See `orientation.oangle` for the corresponding oriented angle\ndefinition. -/\ndef angle (x y : V) : ℝ := real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖))\n\nlemma continuous_at_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :\n  continuous_at (λ y : V × V, angle y.1 y.2) x :=\nreal.continuous_arccos.continuous_at.comp $ continuous_inner.continuous_at.div\n  ((continuous_norm.comp continuous_fst).mul (continuous_norm.comp continuous_snd)).continuous_at\n  (by simp [hx1, hx2])\n\nlemma angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) :\n  angle (c • x) (c • y) = angle x y :=\nhave c * c ≠ 0, from mul_ne_zero hc hc,\nby rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, real.norm_eq_abs,\n  mul_mul_mul_comm _ (‖x‖), abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this]\n\n@[simp] lemma _root_.linear_isometry.angle_map {E F : Type*}\n  [normed_add_comm_group E] [normed_add_comm_group F]\n  [inner_product_space ℝ E] [inner_product_space ℝ F] (f : E →ₗᵢ[ℝ] F) (u v : E) :\n  angle (f u) (f v) = angle u v :=\nby rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map]\n\n@[simp, norm_cast] lemma _root_.submodule.angle_coe {s : submodule ℝ V} (x y : s) :\n  angle (x : V) (y : V) = angle x y :=\ns.subtypeₗᵢ.angle_map x y\n\n/-- The cosine of the angle between two vectors. -/\nlemma cos_angle (x y : V) : real.cos (angle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) :=\nreal.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\n/-- The angle between two vectors does not depend on their order. -/\nlemma angle_comm (x y : V) : angle x y = angle y x :=\nbegin\n  unfold angle,\n  rw [real_inner_comm, mul_comm]\nend\n\n/-- The angle between the negation of two vectors. -/\n@[simp] lemma angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y :=\nbegin\n  unfold angle,\n  rw [inner_neg_neg, norm_neg, norm_neg]\nend\n\n/-- The angle between two vectors is nonnegative. -/\nlemma angle_nonneg (x y : V) : 0 ≤ angle x y :=\nreal.arccos_nonneg _\n\n/-- The angle between two vectors is at most π. -/\nlemma angle_le_pi (x y : V) : angle x y ≤ π :=\nreal.arccos_le_pi _\n\n/-- The angle between a vector and the negation of another vector. -/\nlemma angle_neg_right (x y : V) : angle x (-y) = π - angle x y :=\nbegin\n  unfold angle,\n  rw [←real.arccos_neg, norm_neg, inner_neg_right, neg_div]\nend\n\n/-- The angle between the negation of a vector and another vector. -/\nlemma angle_neg_left (x y : V) : angle (-x) y = π - angle x y :=\nby rw [←angle_neg_neg, neg_neg, angle_neg_right]\n\n/-- The angle between the zero vector and a vector. -/\n@[simp] lemma angle_zero_left (x : V) : angle 0 x = π / 2 :=\nbegin\n  unfold angle,\n  rw [inner_zero_left, zero_div, real.arccos_zero]\nend\n\n/-- The angle between a vector and the zero vector. -/\n@[simp] lemma angle_zero_right (x : V) : angle x 0 = π / 2 :=\nbegin\n  unfold angle,\n  rw [inner_zero_right, zero_div, real.arccos_zero]\nend\n\n/-- The angle between a nonzero vector and itself. -/\n@[simp] lemma angle_self {x : V} (hx : x ≠ 0) : angle x x = 0 :=\nbegin\n  unfold angle,\n  rw [←real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : ⟪x, x⟫ ≠ 0),\n    real.arccos_one]\nend\n\n/-- The angle between a nonzero vector and its negation. -/\n@[simp] lemma angle_self_neg_of_nonzero {x : V} (hx : x ≠ 0) : angle x (-x) = π :=\nby rw [angle_neg_right, angle_self hx, sub_zero]\n\n/-- The angle between the negation of a nonzero vector and that\nvector. -/\n@[simp] lemma angle_neg_self_of_nonzero {x : V} (hx : x ≠ 0) : angle (-x) x = π :=\nby rw [angle_comm, angle_self_neg_of_nonzero hx]\n\n/-- The angle between a vector and a positive multiple of a vector. -/\n@[simp] lemma angle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :\n  angle x (r • y) = angle x y :=\nbegin\n  unfold angle,\n  rw [inner_smul_right, norm_smul, real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), ←mul_assoc,\n      mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)]\nend\n\n/-- The angle between a positive multiple of a vector and a vector. -/\n@[simp] lemma angle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :\n  angle (r • x) y = angle x y :=\nby rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm]\n\n/-- The angle between a vector and a negative multiple of a vector. -/\n@[simp] lemma angle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) :\n  angle x (r • y) = angle x (-y) :=\nby rw [←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\n/-- The angle between a negative multiple of a vector and a vector. -/\n@[simp] lemma angle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) :\n  angle (r • x) y = angle (-x) y :=\nby rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm]\n\n/-- The cosine of the angle between two vectors, multiplied by the\nproduct of their norms. -/\nlemma cos_angle_mul_norm_mul_norm (x y : V) : real.cos (angle x y) * (‖x‖ * ‖y‖) = ⟪x, y⟫ :=\nbegin\n  rw [cos_angle, div_mul_cancel_of_imp],\n  simp [or_imp_distrib] { contextual := tt },\nend\n\n/-- The sine of the angle between two vectors, multiplied by the\nproduct of their norms. -/\nlemma sin_angle_mul_norm_mul_norm (x y : V) : real.sin (angle x y) * (‖x‖ * ‖y‖) =\n    real.sqrt (⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫) :=\nbegin\n  unfold angle,\n  rw [real.sin_arccos,\n      ←real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),\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,\n      real_inner_self_eq_norm_mul_norm],\n  by_cases h : (‖x‖ * ‖y‖) = 0,\n  { rw [(show ‖x‖ * ‖x‖ * (‖y‖ * ‖y‖) = (‖x‖ * ‖y‖) * (‖x‖ * ‖y‖), by ring), h, mul_zero, mul_zero,\n        zero_sub],\n    cases eq_zero_or_eq_zero_of_mul_eq_zero h with hx hy,\n    { rw norm_eq_zero at hx,\n      rw [hx, inner_zero_left, zero_mul, neg_zero] },\n    { rw norm_eq_zero at hy,\n      rw [hy, inner_zero_right, zero_mul, neg_zero] } },\n  { field_simp [h], ring_nf }\nend\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. -/\nlemma angle_eq_zero_iff {x y : V} : angle x y = 0 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), 0 < r ∧ y = r • x) :=\nbegin\n  rw [angle, ← real_inner_div_norm_mul_norm_eq_one_iff, real.arccos_eq_zero, has_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\nend\n\n/-- The angle between two vectors is π if and only if they are nonzero\nand one is a negative multiple of the other. -/\nlemma angle_eq_pi_iff {x y : V} : angle x y = π ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r < 0 ∧ y = r • x) :=\nbegin\n  rw [angle, ← real_inner_div_norm_mul_norm_eq_neg_one_iff, real.arccos_eq_pi, has_le.le.le_iff_eq],\n  exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1\nend\n\n/-- If the angle between two vectors is π, the angles between those\nvectors and a third vector add to π. -/\nlemma angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = π) :\n  angle x z + angle y z = π :=\nbegin\n  rcases angle_eq_pi_iff.1 h with ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩,\n  rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel'_right]\nend\n\n/-- Two vectors have inner product 0 if and only if the angle between\nthem is π/2. -/\nlemma inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : ⟪x, y⟫ = 0 ↔ angle x y = π / 2 :=\niff.symm $ by simp [angle, or_imp_distrib] { contextual := tt }\n\n/-- If the angle between two vectors is π, the inner product equals the negative product\nof the norms. -/\nlemma inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ⟪x, y⟫ = - (‖x‖ * ‖y‖) :=\nby simp [← cos_angle_mul_norm_mul_norm, h]\n\n/-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/\nlemma inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ⟪x, y⟫ = ‖x‖ * ‖y‖ :=\nby simp [← cos_angle_mul_norm_mul_norm, h]\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 π. -/\nlemma inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ⟪x, y⟫ = - (‖x‖ * ‖y‖) ↔ angle x y = π :=\nbegin\n  refine ⟨λ h, _, inner_eq_neg_mul_norm_of_angle_eq_pi⟩,\n  have h₁ : (‖x‖ * ‖y‖) ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne',\n  rw [angle, h, neg_div, div_self h₁, real.arccos_neg_one],\nend\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. -/\nlemma inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ⟪x, y⟫ = ‖x‖ * ‖y‖ ↔ angle x y = 0 :=\nbegin\n  refine ⟨λ h, _, inner_eq_mul_norm_of_angle_eq_zero⟩,\n  have h₁ : (‖x‖ * ‖y‖) ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne',\n  rw [angle, h, div_self h₁, real.arccos_one],\nend\n\n/-- If the angle between two vectors is π, the norm of their difference equals\nthe sum of their norms. -/\nlemma norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ‖x - y‖ = ‖x‖ + ‖y‖ :=\nbegin\n  rw ← 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,\nend\n\n/-- If the angle between two vectors is 0, the norm of their sum equals\nthe sum of their norms. -/\nlemma norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ‖x + y‖ = ‖x‖ + ‖y‖ :=\nbegin\n  rw ← 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,\nend\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. -/\nlemma norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :\n  ‖x - y‖ = |‖x‖ - ‖y‖| :=\nbegin\n  rw [← sq_eq_sq (norm_nonneg (x - y)) (abs_nonneg (‖x‖ - ‖y‖)),\n      norm_sub_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (‖x‖ - ‖y‖)],\n  ring,\nend\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 π. -/\nlemma norm_sub_eq_add_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ‖x - y‖ = ‖x‖ + ‖y‖ ↔ angle x y = π :=\nbegin\n  refine ⟨λ h, _, norm_sub_eq_add_norm_of_angle_eq_pi⟩,\n  rw ← inner_eq_neg_mul_norm_iff_angle_eq_pi hx hy,\n  obtain ⟨hxy₁, hxy₂⟩ := ⟨norm_nonneg (x - y), add_nonneg (norm_nonneg x) (norm_nonneg y)⟩,\n  rw [← sq_eq_sq hxy₁ hxy₂, norm_sub_pow_two_real] at h,\n  calc ⟪x, y⟫ = (‖x‖ ^ 2 + ‖y‖ ^ 2 - (‖x‖ + ‖y‖) ^ 2) / 2 : by linarith\n  ...         = -(‖x‖ * ‖y‖) : by ring,\nend\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. -/\nlemma norm_add_eq_add_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ‖x + y‖ = ‖x‖ + ‖y‖ ↔ angle x y = 0 :=\nbegin\n  refine ⟨λ h, _, norm_add_eq_add_norm_of_angle_eq_zero⟩,\n  rw ← inner_eq_mul_norm_iff_angle_eq_zero hx hy,\n  obtain ⟨hxy₁, hxy₂⟩ := ⟨norm_nonneg (x + y), add_nonneg (norm_nonneg x) (norm_nonneg y)⟩,\n  rw [← sq_eq_sq hxy₁ hxy₂, norm_add_pow_two_real] at h,\n  calc ⟪x, y⟫ = ((‖x‖ + ‖y‖) ^ 2 - ‖x‖ ^ 2 - ‖y‖ ^ 2)/ 2 : by linarith\n  ...         = ‖x‖ * ‖y‖ : by ring,\nend\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. -/\nlemma norm_sub_eq_abs_sub_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :\n  ‖x - y‖ = |‖x‖ - ‖y‖| ↔ angle x y = 0 :=\nbegin\n  refine ⟨λ h, _, norm_sub_eq_abs_sub_norm_of_angle_eq_zero⟩,\n  rw ← inner_eq_mul_norm_iff_angle_eq_zero hx hy,\n  have h1 : ‖x - y‖ ^ 2 = (‖x‖ - ‖y‖) ^ 2, { rw h, exact sq_abs (‖x‖ - ‖y‖) },\n  rw norm_sub_pow_two_real at h1,\n  calc ⟪x, y⟫ = ((‖x‖ + ‖y‖) ^ 2 - ‖x‖ ^ 2 - ‖y‖ ^ 2)/ 2 : by linarith\n  ...         = ‖x‖ * ‖y‖ : by ring,\nend\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 π/2. -/\nlemma norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (x y : V) :\n  ‖x + y‖ = ‖x - y‖ ↔ angle x y = π / 2 :=\nbegin\n  rw [← sq_eq_sq (norm_nonneg (x + y)) (norm_nonneg (x - y)),\n      ← inner_eq_zero_iff_angle_eq_pi_div_two x y, norm_add_pow_two_real, norm_sub_pow_two_real],\n  split; intro h; linarith,\nend\n\n/-- The cosine of the angle between two vectors is 1 if and only if the angle is 0. -/\nlemma cos_eq_one_iff_angle_eq_zero : cos (angle x y) = 1 ↔ angle x y = 0 :=\nbegin\n  rw ← cos_zero,\n  exact inj_on_cos.eq_iff ⟨angle_nonneg x y, angle_le_pi x y⟩ (left_mem_Icc.2 pi_pos.le),\nend\n\n/-- The cosine of the angle between two vectors is 0 if and only if the angle is π / 2. -/\nlemma cos_eq_zero_iff_angle_eq_pi_div_two : cos (angle x y) = 0 ↔ angle x y = π / 2 :=\nbegin\n  rw ← cos_pi_div_two,\n  apply inj_on_cos.eq_iff ⟨angle_nonneg x y, angle_le_pi x y⟩,\n  split; linarith [pi_pos],\nend\n\n/-- The cosine of the angle between two vectors is -1 if and only if the angle is π. -/\nlemma cos_eq_neg_one_iff_angle_eq_pi : cos (angle x y) = -1 ↔ angle x y = π :=\nbegin\n  rw ← cos_pi,\n  exact inj_on_cos.eq_iff ⟨angle_nonneg x y, angle_le_pi x y⟩ (right_mem_Icc.2 pi_pos.le),\nend\n\n/-- The sine of the angle between two vectors is 0 if and only if the angle is 0 or π. -/\nlemma sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi :\n  sin (angle x y) = 0 ↔ angle x y = 0 ∨ angle x y = π :=\nby rw [sin_eq_zero_iff_cos_eq, cos_eq_one_iff_angle_eq_zero, cos_eq_neg_one_iff_angle_eq_pi]\n\n/-- The sine of the angle between two vectors is 1 if and only if the angle is π / 2. -/\nlemma sin_eq_one_iff_angle_eq_pi_div_two : sin (angle x y) = 1 ↔ angle x y = π / 2 :=\nbegin\n  refine ⟨λ h, _, λ h, by rw [h, sin_pi_div_two]⟩,\n  rw [←cos_eq_zero_iff_angle_eq_pi_div_two, ←abs_eq_zero, abs_cos_eq_sqrt_one_sub_sin_sq, h],\n  simp,\nend\n\nend inner_product_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/unoriented/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7604135740069164}}
{"text": "import data.vector .list \n\nvariables {α : Type} {k m n : nat}\n\nopen tactic\n\nnamespace vector\n\ndef zero [has_zero α] (m) : vector α m := \nvector.repeat 0 m\n\ninstance has_zero [has_zero α] : has_zero (vector α m) := ⟨zero m⟩ \n\nlemma zero_succ [has_zero α] {m} : \n  (0 : vector α (m+1)) = (0 : α)::(0 : vector α m) := rfl\n\ndef neg [has_neg α] (v : vector α m) : vector α m := \n⟨v.val.neg, eq.trans (list.length_neg _) v.property⟩ \n\ninstance has_neg [has_neg α]: has_neg (vector α m) := ⟨neg⟩  \n\nlemma val_neg [has_neg α] (v : vector α k) :\n  (-v).val = list.neg v.val := rfl\n\ndef add [has_add α] (v w : vector α k) : vector α k :=\n⟨ list.add v.val w.val, \n  calc (list.add (v.val) (w.val)).length \n      = max (list.length (v.val)) (list.length (w.val)) : list.length_add\n  ... = v.val.length : \n        begin\n          apply max_eq_left (le_of_eq _),\n          apply eq.trans w.property v.property.symm\n        end\n  ... = k : v.property ⟩ \n\ninstance has_add [has_add α] : has_add (vector α k) := ⟨add⟩ \n\nlemma val_add [has_add α] (v w : vector α k) :\n  (v + w).val = list.add v.val w.val := rfl\n\nlemma add_assoc [add_group α] (a b c : vector α m) :\n  a + b + c = a + (b + c) :=\nbegin apply subtype.eq, simp only [val_add], apply list.add_assoc end\n\nlemma val_zero_equiv_nil [has_zero α] {m} :\n  (@zero α _ m).val ≃ [] := \nbegin\n  intro k, simp only [zero, repeat, list.get_nil],\n  cases list.mem_get_or_get_eq_zero k (list.repeat (0 : α) m),\n  apply list.eq_of_mem_repeat h, exact h\nend\n\nlemma zero_add [add_group α] (a : vector α m) : 0 + a = a :=\nbegin\n  apply subtype.eq, simp only [val_add], apply list.eq_of_equiv,\n  { apply list.length_add_eq_length_right \n    (zero m).property a.property },\n  { apply list.equiv_trans \n    (list.add_equiv_add val_zero_equiv_nil list.equiv_refl) \n    (list.equiv_of_eq list.nil_add) }\nend\n\nlemma add_zero [add_group α] (a : vector α m) : a + 0 = a :=\nbegin\n  apply subtype.eq, simp only [val_add], apply list.eq_of_equiv,\n  { apply list.length_add_eq_length_left \n    a.property (zero m).property },\n  { apply list.equiv_trans \n    (list.add_equiv_add list.equiv_refl val_zero_equiv_nil) \n    (list.equiv_of_eq list.add_nil) }\nend\n\nlemma add_left_neg [add_group α] (a : vector α m) : -a + a = 0 := \nbegin\n  apply subtype.eq, simp only [val_neg, val_add],\n  apply list.eq_of_equiv,\n  { rw list.length_add_eq_length_left _ a.property,\n    rw list.length_neg,\n    apply eq.trans a.property (zero m).property.symm,\n    rw list.length_neg, apply a.property },\n  { apply list.equiv_trans list.add_left_neg \n    (list.equiv_symm val_zero_equiv_nil) }\nend\n\ninstance add_group [add_group α] : add_group (vector α m) :=\n{ add := add,\n  add_assoc := add_assoc,\n  zero := zero m,\n  zero_add := zero_add,\n  add_zero := add_zero,\n  neg := neg,\n  add_left_neg := add_left_neg }\n\ndef dot_prod [ring α] (v w : vector α k) : α :=\nlist.dot_prod v.val w.val \n\ninfix `⬝` := dot_prod\n\n--def zero_dot_prod [ring α] (v : vector α k) : 0 ⬝ v = 0 := sorry\n--def dot_prod_zero [ring α] (v : vector α k) : v ⬝ 0 = 0 := sorry\n\ndef sum [add_monoid α] : ∀ {k}, vector α k → α \n| 0     _ := 0\n| (k+1) v := v.head + @sum k v.tail\n\nend vector\n\n/- (mk_meta_vector k) returns the expr of a vector of length k,\n   where the expr of each entry is a metavariable. -/ \nmeta def mk_meta_vector (αx : expr) : nat → tactic expr \n| 0     := to_expr ``(@vector.nil %%αx)\n| (k+1) := \n  do x ← mk_meta_var αx,\n     vx ← mk_meta_vector k,\n     to_expr ``(@vector.cons %%αx %%`(k) %%x %%vx)\n\n/- (vector₂.mk_meta m n) returns the expr of an m × n vector₂,\n   where the expr of each entry is a metavariable. -/ \nmeta def mk_meta_vector₂ (αx : expr) : nat → nat → tactic expr \n| 0     n := to_expr ``(@vector.nil (vector %%αx %%`(n)))\n| (m+1) n :=  \n  do v₁x ← mk_meta_vector αx n,\n     v₂x ← mk_meta_vector₂ m n,\n     to_expr ``(@vector.cons (vector %%αx %%`(n)) %%`(m) %%v₁x %%v₂x)\n\ndef vector₂ (α : Type) (m n : nat) : Type := vector (vector α n) m", "meta": {"author": "skbaek", "repo": "cvx", "sha": "c50c790c9116f9fac8dfe742903a62bdd7292c15", "save_path": "github-repos/lean/skbaek-cvx", "path": "github-repos/lean/skbaek-cvx/cvx-c50c790c9116f9fac8dfe742903a62bdd7292c15/src/vector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7604135701802649}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, 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 `∪`, `∩`, `insert`, and provide\nformulas for `∅`, `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 {α : Type u} [preorder α] (s : set α) : set α :=\n  set_of fun (x : α) => ∀ {a : α}, a ∈ s → a ≤ x\n\ndef lower_bounds {α : Type u} [preorder α] (s : set α) : set α :=\n  set_of fun (x : α) => ∀ {a : α}, a ∈ s → x ≤ 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 {α : Type u} [preorder α] (s : set α) :=\n  set.nonempty (upper_bounds s)\n\ndef bdd_below {α : Type u} [preorder α] (s : set α) :=\n  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 {α : Type u} [preorder α] (s : set α) (a : α) :=\n  a ∈ s ∧ a ∈ lower_bounds s\n\ndef is_greatest {α : Type u} [preorder α] (s : set α) (a : α) :=\n  a ∈ s ∧ a ∈ 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 {α : Type u} [preorder α] (s : set α) : α → Prop :=\n  is_least (upper_bounds s)\n\ndef is_glb {α : Type u} [preorder α] (s : set α) : α → Prop :=\n  is_greatest (lower_bounds s)\n\ntheorem mem_upper_bounds {α : Type u} [preorder α] {s : set α} {a : α} : a ∈ upper_bounds s ↔ ∀ (x : α), x ∈ s → x ≤ a :=\n  iff.rfl\n\ntheorem mem_lower_bounds {α : Type u} [preorder α] {s : set α} {a : α} : a ∈ lower_bounds s ↔ ∀ (x : α), x ∈ s → a ≤ x :=\n  iff.rfl\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`¬(y ≤ x)`. A version for linear orders is called `not_bdd_above_iff`. -/\ntheorem not_bdd_above_iff' {α : Type u} [preorder α] {s : set α} : ¬bdd_above s ↔ ∀ (x : α), ∃ (y : α), ∃ (H : y ∈ s), ¬y ≤ x := sorry\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`¬(x ≤ y)`. A version for linear orders is called `not_bdd_below_iff`. -/\ntheorem not_bdd_below_iff' {α : Type u} [preorder α] {s : set α} : ¬bdd_below s ↔ ∀ (x : α), ∃ (y : α), ∃ (H : y ∈ s), ¬x ≤ 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 ∈ s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\ntheorem not_bdd_above_iff {α : Type u_1} [linear_order α] {s : set α} : ¬bdd_above s ↔ ∀ (x : α), ∃ (y : α), ∃ (H : y ∈ s), x < y := sorry\n\n/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\ntheorem not_bdd_below_iff {α : Type u_1} [linear_order α] {s : set α} : ¬bdd_below s ↔ ∀ (x : α), ∃ (y : α), ∃ (H : y ∈ s), y < x :=\n  not_bdd_above_iff\n\n/-!\n### Monotonicity\n-/\n\ntheorem upper_bounds_mono_set {α : Type u} [preorder α] {s : set α} {t : set α} (hst : s ⊆ t) : upper_bounds t ⊆ upper_bounds s :=\n  fun (b : α) (hb : b ∈ upper_bounds t) (x : α) (h : x ∈ s) => hb (hst h)\n\ntheorem lower_bounds_mono_set {α : Type u} [preorder α] {s : set α} {t : set α} (hst : s ⊆ t) : lower_bounds t ⊆ lower_bounds s :=\n  fun (b : α) (hb : b ∈ lower_bounds t) (x : α) (h : x ∈ s) => hb (hst h)\n\ntheorem upper_bounds_mono_mem {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (hab : a ≤ b) : a ∈ upper_bounds s → b ∈ upper_bounds s :=\n  fun (ha : a ∈ upper_bounds s) (x : α) (h : x ∈ s) => le_trans (ha h) hab\n\ntheorem lower_bounds_mono_mem {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (hab : a ≤ b) : b ∈ lower_bounds s → a ∈ lower_bounds s :=\n  fun (hb : b ∈ lower_bounds s) (x : α) (h : x ∈ s) => le_trans hab (hb h)\n\ntheorem upper_bounds_mono {α : Type u} [preorder α] {s : set α} {t : set α} (hst : s ⊆ t) {a : α} {b : α} (hab : a ≤ b) : a ∈ upper_bounds t → b ∈ upper_bounds s :=\n  fun (ha : a ∈ upper_bounds t) => upper_bounds_mono_set hst (upper_bounds_mono_mem hab ha)\n\ntheorem lower_bounds_mono {α : Type u} [preorder α] {s : set α} {t : set α} (hst : s ⊆ t) {a : α} {b : α} (hab : a ≤ b) : b ∈ lower_bounds t → a ∈ lower_bounds s :=\n  fun (hb : b ∈ lower_bounds t) => lower_bounds_mono_set hst (lower_bounds_mono_mem hab hb)\n\n/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/\ntheorem bdd_above.mono {α : Type u} [preorder α] {s : set α} {t : set α} (h : s ⊆ t) : bdd_above t → bdd_above s :=\n  set.nonempty.mono (upper_bounds_mono_set h)\n\n/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/\ntheorem bdd_below.mono {α : Type u} [preorder α] {s : set α} {t : set α} (h : s ⊆ t) : bdd_below t → 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 ⊆ t ⊆ p`. -/\ntheorem is_lub.of_subset_of_superset {α : Type u} [preorder α] {a : α} {s : set α} {t : set α} {p : set α} (hs : is_lub s a) (hp : is_lub p a) (hst : s ⊆ t) (htp : t ⊆ 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 ⊆ t ⊆ p`. -/\ntheorem is_glb.of_subset_of_superset {α : Type u} [preorder α] {a : α} {s : set α} {t : set α} {p : set α} (hs : is_glb s a) (hp : is_glb p a) (hst : s ⊆ t) (htp : t ⊆ p) : is_glb t a :=\n  is_lub.of_subset_of_superset hs hp hst htp\n\ntheorem is_least.mono {α : Type u} [preorder α] {s : set α} {t : set α} {a : α} {b : α} (ha : is_least s a) (hb : is_least t b) (hst : s ⊆ t) : b ≤ a :=\n  and.right hb a (hst (and.left ha))\n\ntheorem is_greatest.mono {α : Type u} [preorder α] {s : set α} {t : set α} {a : α} {b : α} (ha : is_greatest s a) (hb : is_greatest t b) (hst : s ⊆ t) : a ≤ b :=\n  and.right hb a (hst (and.left ha))\n\ntheorem is_lub.mono {α : Type u} [preorder α] {s : set α} {t : set α} {a : α} {b : α} (ha : is_lub s a) (hb : is_lub t b) (hst : s ⊆ t) : a ≤ b :=\n  is_least.mono hb ha (upper_bounds_mono_set hst)\n\ntheorem is_glb.mono {α : Type u} [preorder α] {s : set α} {t : set α} {a : α} {b : α} (ha : is_glb s a) (hb : is_glb t b) (hst : s ⊆ t) : b ≤ a :=\n  is_greatest.mono hb ha (lower_bounds_mono_set hst)\n\n/-!\n### Conversions\n-/\n\ntheorem is_least.is_glb {α : Type u} [preorder α] {s : set α} {a : α} (h : is_least s a) : is_glb s a :=\n  { left := and.right h, right := fun (b : α) (hb : b ∈ lower_bounds s) => hb (and.left h) }\n\ntheorem is_greatest.is_lub {α : Type u} [preorder α] {s : set α} {a : α} (h : is_greatest s a) : is_lub s a :=\n  { left := and.right h, right := fun (b : α) (hb : b ∈ upper_bounds s) => hb (and.left h) }\n\ntheorem is_lub.upper_bounds_eq {α : Type u} [preorder α] {s : set α} {a : α} (h : is_lub s a) : upper_bounds s = set.Ici a := sorry\n\ntheorem is_glb.lower_bounds_eq {α : Type u} [preorder α] {s : set α} {a : α} (h : is_glb s a) : lower_bounds s = set.Iic a :=\n  is_lub.upper_bounds_eq h\n\ntheorem is_least.lower_bounds_eq {α : Type u} [preorder α] {s : set α} {a : α} (h : is_least s a) : lower_bounds s = set.Iic a :=\n  is_glb.lower_bounds_eq (is_least.is_glb h)\n\ntheorem is_greatest.upper_bounds_eq {α : Type u} [preorder α] {s : set α} {a : α} (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 {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (h : is_lub s a) : a ≤ b ↔ b ∈ upper_bounds s :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (a ≤ b ↔ b ∈ upper_bounds s)) (is_lub.upper_bounds_eq h))) (iff.refl (a ≤ b))\n\ntheorem le_is_glb_iff {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (h : is_glb s a) : b ≤ a ↔ b ∈ lower_bounds s :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (b ≤ a ↔ b ∈ lower_bounds s)) (is_glb.lower_bounds_eq h))) (iff.refl (b ≤ a))\n\n/-- If `s` has a least upper bound, then it is bounded above. -/\ntheorem is_lub.bdd_above {α : Type u} [preorder α] {s : set α} {a : α} (h : is_lub s a) : 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 {α : Type u} [preorder α] {s : set α} {a : α} (h : is_glb s a) : 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 {α : Type u} [preorder α] {s : set α} {a : α} (h : is_greatest s a) : 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 {α : Type u} [preorder α] {s : set α} {a : α} (h : is_least s a) : bdd_below s :=\n  Exists.intro a (and.right h)\n\ntheorem is_least.nonempty {α : Type u} [preorder α] {s : set α} {a : α} (h : is_least s a) : set.nonempty s :=\n  Exists.intro a (and.left h)\n\ntheorem is_greatest.nonempty {α : Type u} [preorder α] {s : set α} {a : α} (h : is_greatest s a) : set.nonempty s :=\n  Exists.intro a (and.left h)\n\n/-!\n### Union and intersection\n-/\n\n@[simp] theorem upper_bounds_union {α : Type u} [preorder α] {s : set α} {t : set α} : upper_bounds (s ∪ t) = upper_bounds s ∩ upper_bounds t := sorry\n\n@[simp] theorem lower_bounds_union {α : Type u} [preorder α] {s : set α} {t : set α} : lower_bounds (s ∪ t) = lower_bounds s ∩ lower_bounds t :=\n  upper_bounds_union\n\ntheorem union_upper_bounds_subset_upper_bounds_inter {α : Type u} [preorder α] {s : set α} {t : set α} : upper_bounds s ∪ upper_bounds t ⊆ upper_bounds (s ∩ 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 {α : Type u} [preorder α] {s : set α} {t : set α} : lower_bounds s ∪ lower_bounds t ⊆ lower_bounds (s ∩ t) :=\n  union_upper_bounds_subset_upper_bounds_inter\n\ntheorem is_least_union_iff {α : Type u} [preorder α] {a : α} {s : set α} {t : set α} : is_least (s ∪ t) a ↔ is_least s a ∧ a ∈ lower_bounds t ∨ a ∈ lower_bounds s ∧ is_least t a := sorry\n\ntheorem is_greatest_union_iff {α : Type u} [preorder α] {s : set α} {t : set α} {a : α} : is_greatest (s ∪ t) a ↔ is_greatest s a ∧ a ∈ upper_bounds t ∨ a ∈ upper_bounds s ∧ is_greatest t a :=\n  is_least_union_iff\n\n/-- If `s` is bounded, then so is `s ∩ t` -/\ntheorem bdd_above.inter_of_left {α : Type u} [preorder α] {s : set α} {t : set α} (h : bdd_above s) : bdd_above (s ∩ t) :=\n  bdd_above.mono (set.inter_subset_left s t) h\n\n/-- If `t` is bounded, then so is `s ∩ t` -/\ntheorem bdd_above.inter_of_right {α : Type u} [preorder α] {s : set α} {t : set α} (h : bdd_above t) : bdd_above (s ∩ t) :=\n  bdd_above.mono (set.inter_subset_right s t) h\n\n/-- If `s` is bounded, then so is `s ∩ t` -/\ntheorem bdd_below.inter_of_left {α : Type u} [preorder α] {s : set α} {t : set α} (h : bdd_below s) : bdd_below (s ∩ t) :=\n  bdd_below.mono (set.inter_subset_left s t) h\n\n/-- If `t` is bounded, then so is `s ∩ t` -/\ntheorem bdd_below.inter_of_right {α : Type u} [preorder α] {s : set α} {t : set α} (h : bdd_below t) : bdd_below (s ∩ 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 ∪ t`. -/\ntheorem bdd_above.union {γ : Type w} [semilattice_sup γ] {s : set γ} {t : set γ} : bdd_above s → bdd_above t → bdd_above (s ∪ t) := sorry\n\n/-- The union of two sets is bounded above if and only if each of the sets is. -/\ntheorem bdd_above_union {γ : Type w} [semilattice_sup γ] {s : set γ} {t : set γ} : bdd_above (s ∪ t) ↔ bdd_above s ∧ bdd_above t := sorry\n\ntheorem bdd_below.union {γ : Type w} [semilattice_inf γ] {s : set γ} {t : set γ} : bdd_below s → bdd_below t → bdd_below (s ∪ 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 {γ : Type w} [semilattice_inf γ] {s : set γ} {t : set γ} : bdd_below (s ∪ t) ↔ bdd_below s ∧ 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 ⊔ b` is the least upper bound of `s ∪ t`. -/\ntheorem is_lub.union {γ : Type w} [semilattice_sup γ] {a : γ} {b : γ} {s : set γ} {t : set γ} (hs : is_lub s a) (ht : is_lub t b) : is_lub (s ∪ t) (a ⊔ b) := sorry\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/\ntheorem is_glb.union {γ : Type w} [semilattice_inf γ] {a₁ : γ} {a₂ : γ} {s : set γ} {t : set γ} (hs : is_glb s a₁) (ht : is_glb t a₂) : is_glb (s ∪ t) (a₁ ⊓ a₂) :=\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 ∪ t`. -/\ntheorem is_least.union {γ : Type w} [linear_order γ] {a : γ} {b : γ} {s : set γ} {t : set γ} (ha : is_least s a) (hb : is_least t b) : is_least (s ∪ t) (min a b) := 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 ∪ t`. -/\ntheorem is_greatest.union {γ : Type w} [linear_order γ] {a : γ} {b : γ} {s : set γ} {t : set γ} (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s ∪ t) (max a b) := sorry\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\ntheorem is_least_Ici {α : Type u} [preorder α] {a : α} : is_least (set.Ici a) a :=\n  { left := set.left_mem_Ici, right := fun (x : α) => id }\n\ntheorem is_greatest_Iic {α : Type u} [preorder α] {a : α} : is_greatest (set.Iic a) a :=\n  { left := set.right_mem_Iic, right := fun (x : α) => id }\n\ntheorem is_lub_Iic {α : Type u} [preorder α] {a : α} : is_lub (set.Iic a) a :=\n  is_greatest.is_lub is_greatest_Iic\n\ntheorem is_glb_Ici {α : Type u} [preorder α] {a : α} : is_glb (set.Ici a) a :=\n  is_least.is_glb is_least_Ici\n\ntheorem upper_bounds_Iic {α : Type u} [preorder α] {a : α} : upper_bounds (set.Iic a) = set.Ici a :=\n  is_lub.upper_bounds_eq is_lub_Iic\n\ntheorem lower_bounds_Ici {α : Type u} [preorder α] {a : α} : lower_bounds (set.Ici a) = set.Iic a :=\n  is_glb.lower_bounds_eq is_glb_Ici\n\ntheorem bdd_above_Iic {α : Type u} [preorder α] {a : α} : bdd_above (set.Iic a) :=\n  is_lub.bdd_above is_lub_Iic\n\ntheorem bdd_below_Ici {α : Type u} [preorder α] {a : α} : bdd_below (set.Ici a) :=\n  is_glb.bdd_below is_glb_Ici\n\ntheorem bdd_above_Iio {α : Type u} [preorder α] {a : α} : bdd_above (set.Iio a) :=\n  Exists.intro a fun (x : α) (hx : x ∈ set.Iio a) => le_of_lt hx\n\ntheorem bdd_below_Ioi {α : Type u} [preorder α] {a : α} : bdd_below (set.Ioi a) :=\n  Exists.intro a fun (x : α) (hx : x ∈ set.Ioi a) => le_of_lt hx\n\ntheorem is_lub_Iio {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} : is_lub (set.Iio a) a :=\n  { left := fun (x : γ) (hx : x ∈ set.Iio a) => le_of_lt hx,\n    right := fun (y : γ) (hy : y ∈ upper_bounds (set.Iio a)) => le_of_forall_ge_of_dense hy }\n\ntheorem is_glb_Ioi {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} : is_glb (set.Ioi a) a :=\n  is_lub_Iio\n\ntheorem upper_bounds_Iio {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} : upper_bounds (set.Iio a) = set.Ici a :=\n  is_lub.upper_bounds_eq is_lub_Iio\n\ntheorem lower_bounds_Ioi {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} : 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 {α : Type u} [preorder α] {a : α} : is_greatest (singleton a) a :=\n  { left := set.mem_singleton a, right := fun (x : α) (hx : x ∈ singleton a) => le_of_eq (set.eq_of_mem_singleton hx) }\n\ntheorem is_least_singleton {α : Type u} [preorder α] {a : α} : is_least (singleton a) a :=\n  is_greatest_singleton\n\ntheorem is_lub_singleton {α : Type u} [preorder α] {a : α} : is_lub (singleton a) a :=\n  is_greatest.is_lub is_greatest_singleton\n\ntheorem is_glb_singleton {α : Type u} [preorder α] {a : α} : is_glb (singleton a) a :=\n  is_least.is_glb is_least_singleton\n\ntheorem bdd_above_singleton {α : Type u} [preorder α] {a : α} : bdd_above (singleton a) :=\n  is_lub.bdd_above is_lub_singleton\n\ntheorem bdd_below_singleton {α : Type u} [preorder α] {a : α} : bdd_below (singleton a) :=\n  is_glb.bdd_below is_glb_singleton\n\n@[simp] theorem upper_bounds_singleton {α : Type u} [preorder α] {a : α} : upper_bounds (singleton a) = set.Ici a :=\n  is_lub.upper_bounds_eq is_lub_singleton\n\n@[simp] theorem lower_bounds_singleton {α : Type u} [preorder α] {a : α} : 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 {α : Type u} [preorder α] {a : α} {b : α} : bdd_above (set.Icc a b) :=\n  Exists.intro b fun (_x : α) => and.right\n\ntheorem bdd_below_Icc {α : Type u} [preorder α] {a : α} {b : α} : bdd_below (set.Icc a b) :=\n  Exists.intro a fun (_x : α) => and.left\n\ntheorem bdd_above_Ico {α : Type u} [preorder α] {a : α} {b : α} : bdd_above (set.Ico a b) :=\n  bdd_above.mono set.Ico_subset_Icc_self bdd_above_Icc\n\ntheorem bdd_below_Ico {α : Type u} [preorder α] {a : α} {b : α} : bdd_below (set.Ico a b) :=\n  bdd_below.mono set.Ico_subset_Icc_self bdd_below_Icc\n\ntheorem bdd_above_Ioc {α : Type u} [preorder α] {a : α} {b : α} : bdd_above (set.Ioc a b) :=\n  bdd_above.mono set.Ioc_subset_Icc_self bdd_above_Icc\n\ntheorem bdd_below_Ioc {α : Type u} [preorder α] {a : α} {b : α} : bdd_below (set.Ioc a b) :=\n  bdd_below.mono set.Ioc_subset_Icc_self bdd_below_Icc\n\ntheorem bdd_above_Ioo {α : Type u} [preorder α] {a : α} {b : α} : bdd_above (set.Ioo a b) :=\n  bdd_above.mono set.Ioo_subset_Icc_self bdd_above_Icc\n\ntheorem bdd_below_Ioo {α : Type u} [preorder α] {a : α} {b : α} : bdd_below (set.Ioo a b) :=\n  bdd_below.mono set.Ioo_subset_Icc_self bdd_below_Icc\n\ntheorem is_greatest_Icc {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : is_greatest (set.Icc a b) b :=\n  { left := iff.mpr set.right_mem_Icc h, right := fun (x : α) => and.right }\n\ntheorem is_lub_Icc {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : is_lub (set.Icc a b) b :=\n  is_greatest.is_lub (is_greatest_Icc h)\n\ntheorem upper_bounds_Icc {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : upper_bounds (set.Icc a b) = set.Ici b :=\n  is_lub.upper_bounds_eq (is_lub_Icc h)\n\ntheorem is_least_Icc {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : is_least (set.Icc a b) a :=\n  { left := iff.mpr set.left_mem_Icc h, right := fun (x : α) => and.left }\n\ntheorem is_glb_Icc {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : is_glb (set.Icc a b) a :=\n  is_least.is_glb (is_least_Icc h)\n\ntheorem lower_bounds_Icc {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : lower_bounds (set.Icc a b) = set.Iic a :=\n  is_glb.lower_bounds_eq (is_glb_Icc h)\n\ntheorem is_greatest_Ioc {α : Type u} [preorder α] {a : α} {b : α} (h : a < b) : is_greatest (set.Ioc a b) b :=\n  { left := iff.mpr set.right_mem_Ioc h, right := fun (x : α) => and.right }\n\ntheorem is_lub_Ioc {α : Type u} [preorder α] {a : α} {b : α} (h : a < b) : is_lub (set.Ioc a b) b :=\n  is_greatest.is_lub (is_greatest_Ioc h)\n\ntheorem upper_bounds_Ioc {α : Type u} [preorder α] {a : α} {b : α} (h : a < b) : upper_bounds (set.Ioc a b) = set.Ici b :=\n  is_lub.upper_bounds_eq (is_lub_Ioc h)\n\ntheorem is_least_Ico {α : Type u} [preorder α] {a : α} {b : α} (h : a < b) : is_least (set.Ico a b) a :=\n  { left := iff.mpr set.left_mem_Ico h, right := fun (x : α) => and.left }\n\ntheorem is_glb_Ico {α : Type u} [preorder α] {a : α} {b : α} (h : a < b) : is_glb (set.Ico a b) a :=\n  is_least.is_glb (is_least_Ico h)\n\ntheorem lower_bounds_Ico {α : Type u} [preorder α] {a : α} {b : α} (h : a < b) : lower_bounds (set.Ico a b) = set.Iic a :=\n  is_glb.lower_bounds_eq (is_glb_Ico h)\n\ntheorem is_glb_Ioo {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (hab : a < b) : is_glb (set.Ioo a b) a := sorry\n\ntheorem lower_bounds_Ioo {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (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 {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (hab : a < b) : 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 {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (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 {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (hab : a < b) : is_lub (set.Ioo a b) b := sorry\n\ntheorem upper_bounds_Ioo {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (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 {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (hab : a < b) : is_lub (set.Ico a b) b := sorry\n\ntheorem upper_bounds_Ico {γ : Type w} [linear_order γ] [densely_ordered γ] {a : γ} {b : γ} (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 {α : Type u} [preorder α] {s : set α} : bdd_below s ↔ ∃ (a : α), s ⊆ set.Ici a :=\n  iff.rfl\n\ntheorem bdd_above_iff_subset_Iic {α : Type u} [preorder α] {s : set α} : bdd_above s ↔ ∃ (a : α), s ⊆ set.Iic a :=\n  iff.rfl\n\ntheorem bdd_below_bdd_above_iff_subset_Icc {α : Type u} [preorder α] {s : set α} : bdd_below s ∧ bdd_above s ↔ ∃ (a : α), ∃ (b : α), s ⊆ set.Icc a b := sorry\n\n/-!\n### Univ\n-/\n\ntheorem order_top.upper_bounds_univ {γ : Type w} [order_top γ] : upper_bounds set.univ = singleton ⊤ := sorry\n\ntheorem is_greatest_univ {γ : Type w} [order_top γ] : is_greatest set.univ ⊤ := sorry\n\ntheorem is_lub_univ {γ : Type w} [order_top γ] : is_lub set.univ ⊤ :=\n  is_greatest.is_lub is_greatest_univ\n\ntheorem order_bot.lower_bounds_univ {γ : Type w} [order_bot γ] : lower_bounds set.univ = singleton ⊥ :=\n  order_top.upper_bounds_univ\n\ntheorem is_least_univ {γ : Type w} [order_bot γ] : is_least set.univ ⊥ :=\n  is_greatest_univ\n\ntheorem is_glb_univ {γ : Type w} [order_bot γ] : is_glb set.univ ⊥ :=\n  is_least.is_glb is_least_univ\n\ntheorem no_top_order.upper_bounds_univ {α : Type u} [preorder α] [no_top_order α] : upper_bounds set.univ = ∅ := sorry\n\ntheorem no_bot_order.lower_bounds_univ {α : Type u} [preorder α] [no_bot_order α] : lower_bounds set.univ = ∅ :=\n  no_top_order.upper_bounds_univ\n\n/-!\n### Empty set\n-/\n\n@[simp] theorem upper_bounds_empty {α : Type u} [preorder α] : upper_bounds ∅ = set.univ := sorry\n\n@[simp] theorem lower_bounds_empty {α : Type u} [preorder α] : lower_bounds ∅ = set.univ :=\n  upper_bounds_empty\n\n@[simp] theorem bdd_above_empty {α : Type u} [preorder α] [Nonempty α] : bdd_above ∅ := sorry\n\n@[simp] theorem bdd_below_empty {α : Type u} [preorder α] [Nonempty α] : bdd_below ∅ := sorry\n\ntheorem is_glb_empty {γ : Type w} [order_top γ] : is_glb ∅ ⊤ := sorry\n\ntheorem is_lub_empty {γ : Type w} [order_bot γ] : is_lub ∅ ⊥ :=\n  is_glb_empty\n\ntheorem is_lub.nonempty {α : Type u} [preorder α] {s : set α} {a : α} [no_bot_order α] (hs : is_lub s a) : set.nonempty s := sorry\n\ntheorem is_glb.nonempty {α : Type u} [preorder α] {s : set α} {a : α} [no_top_order α] (hs : is_glb s a) : set.nonempty s :=\n  is_lub.nonempty hs\n\ntheorem nonempty_of_not_bdd_above {α : Type u} [preorder α] {s : set α} [ha : Nonempty α] (h : ¬bdd_above s) : set.nonempty s :=\n  nonempty.elim ha\n    fun (x : α) => Exists.imp (fun (a : α) (ha : ∃ (H : a ∈ s), ¬a ≤ x) => Exists.fst ha) (iff.mp not_bdd_above_iff' h x)\n\ntheorem nonempty_of_not_bdd_below {α : Type u} [preorder α] {s : set α} [ha : Nonempty α] (h : ¬bdd_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 {γ : Type w} [semilattice_sup γ] (a : γ) {s : set γ} : bdd_above (insert a s) ↔ bdd_above s := sorry\n\ntheorem bdd_above.insert {γ : Type w} [semilattice_sup γ] (a : γ) {s : set γ} (hs : bdd_above s) : 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 {γ : Type w} [semilattice_inf γ] (a : γ) {s : set γ} : bdd_below (insert a s) ↔ bdd_below s := sorry\n\ntheorem bdd_below.insert {γ : Type w} [semilattice_inf γ] (a : γ) {s : set γ} (hs : bdd_below s) : bdd_below (insert a s) :=\n  iff.mpr (bdd_below_insert a) hs\n\ntheorem is_lub.insert {γ : Type w} [semilattice_sup γ] (a : γ) {b : γ} {s : set γ} (hs : is_lub s b) : is_lub (insert a s) (a ⊔ b) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_lub (insert a s) (a ⊔ b))) (set.insert_eq a s))) (is_lub.union is_lub_singleton hs)\n\ntheorem is_glb.insert {γ : Type w} [semilattice_inf γ] (a : γ) {b : γ} {s : set γ} (hs : is_glb s b) : is_glb (insert a s) (a ⊓ b) :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (is_glb (insert a s) (a ⊓ b))) (set.insert_eq a s))) (is_glb.union is_glb_singleton hs)\n\ntheorem is_greatest.insert {γ : Type w} [linear_order γ] (a : γ) {b : γ} {s : set γ} (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 {γ : Type w} [linear_order γ] (a : γ) {b : γ} {s : set γ} (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 {α : Type u} [preorder α] (a : α) (s : set α) : upper_bounds (insert a s) = set.Ici a ∩ upper_bounds s := sorry\n\n@[simp] theorem lower_bounds_insert {α : Type u} [preorder α] (a : α) (s : set α) : lower_bounds (insert a s) = set.Iic a ∩ lower_bounds s := sorry\n\n/-- When there is a global maximum, every set is bounded above. -/\n@[simp] protected theorem order_top.bdd_above {γ : Type w} [order_top γ] (s : set γ) : bdd_above s :=\n  Exists.intro ⊤ fun (a : γ) (ha : a ∈ 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 {γ : Type w} [order_bot γ] (s : set γ) : bdd_below s :=\n  Exists.intro ⊥ fun (a : γ) (ha : a ∈ s) => order_bot.bot_le a\n\n/-!\n### Pair\n-/\n\ntheorem is_lub_pair {γ : Type w} [semilattice_sup γ] {a : γ} {b : γ} : is_lub (insert a (singleton b)) (a ⊔ b) :=\n  is_lub.insert a is_lub_singleton\n\ntheorem is_glb_pair {γ : Type w} [semilattice_inf γ] {a : γ} {b : γ} : is_glb (insert a (singleton b)) (a ⊓ b) :=\n  is_glb.insert a is_glb_singleton\n\ntheorem is_least_pair {γ : Type w} [linear_order γ] {a : γ} {b : γ} : is_least (insert a (singleton b)) (min a b) :=\n  is_least.insert a is_least_singleton\n\ntheorem is_greatest_pair {γ : Type w} [linear_order γ] {a : γ} {b : γ} : 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 {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds s) : set.nonempty s → a ≤ b :=\n  fun (ᾰ : set.nonempty s) =>\n    Exists.dcases_on ᾰ fun (ᾰ_w : α) (ᾰ_h : ᾰ_w ∈ s) => idRhs (a ≤ b) (le_trans (ha ᾰ_h) (hb ᾰ_h))\n\ntheorem is_glb_le_is_lub {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (ha : is_glb s a) (hb : is_lub s b) (hs : set.nonempty s) : a ≤ b :=\n  lower_bounds_le_upper_bounds (and.left ha) (and.left hb) hs\n\ntheorem is_lub_lt_iff {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (ha : is_lub s a) : a < b ↔ ∃ (c : α), ∃ (H : c ∈ upper_bounds s), c < b := sorry\n\ntheorem lt_is_glb_iff {α : Type u} [preorder α] {s : set α} {a : α} {b : α} (ha : is_glb s a) : b < a ↔ ∃ (c : α), ∃ (H : c ∈ lower_bounds s), b < c :=\n  is_lub_lt_iff ha\n\ntheorem is_least.unique {α : Type u} [partial_order α] {s : set α} {a : α} {b : α} (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 {α : Type u} [partial_order α] {s : set α} {a : α} {b : α} (Ha : is_least s a) : is_least s b ↔ a = b :=\n  { mp := is_least.unique Ha, mpr := fun (h : a = b) => h ▸ Ha }\n\ntheorem is_greatest.unique {α : Type u} [partial_order α] {s : set α} {a : α} {b : α} (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 {α : Type u} [partial_order α] {s : set α} {a : α} {b : α} (Ha : is_greatest s a) : is_greatest s b ↔ a = b :=\n  { mp := is_greatest.unique Ha, mpr := fun (h : a = b) => h ▸ Ha }\n\ntheorem is_lub.unique {α : Type u} [partial_order α] {s : set α} {a : α} {b : α} (Ha : is_lub s a) (Hb : is_lub s b) : a = b :=\n  is_least.unique Ha Hb\n\ntheorem is_glb.unique {α : Type u} [partial_order α] {s : set α} {a : α} {b : α} (Ha : is_glb s a) (Hb : is_glb s b) : a = b :=\n  is_greatest.unique Ha Hb\n\ntheorem lt_is_lub_iff {α : Type u} [linear_order α] {s : set α} {a : α} {b : α} (h : is_lub s a) : b < a ↔ ∃ (c : α), ∃ (H : c ∈ s), b < c := sorry\n\ntheorem is_glb_lt_iff {α : Type u} [linear_order α] {s : set α} {a : α} {b : α} (h : is_glb s a) : a < b ↔ ∃ (c : α), ∃ (H : c ∈ s), c < b :=\n  lt_is_lub_iff h\n\ntheorem is_lub.exists_between {α : Type u} [linear_order α] {s : set α} {a : α} {b : α} (h : is_lub s a) (hb : b < a) : ∃ (c : α), ∃ (H : c ∈ s), b < c ∧ c ≤ a := sorry\n\ntheorem is_lub.exists_between' {α : Type u} [linear_order α] {s : set α} {a : α} {b : α} (h : is_lub s a) (h' : ¬a ∈ s) (hb : b < a) : ∃ (c : α), ∃ (H : c ∈ s), b < c ∧ c < a := sorry\n\ntheorem is_glb.exists_between {α : Type u} [linear_order α] {s : set α} {a : α} {b : α} (h : is_glb s a) (hb : a < b) : ∃ (c : α), ∃ (H : c ∈ s), a ≤ c ∧ c < b := sorry\n\ntheorem is_glb.exists_between' {α : Type u} [linear_order α] {s : set α} {a : α} {b : α} (h : is_glb s a) (h' : ¬a ∈ s) (hb : a < b) : ∃ (c : α), ∃ (H : c ∈ s), a < c ∧ c < b := 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 {α : Type u} [linear_ordered_add_comm_group α] {s : set α} {a : α} {ε : α} (h : is_glb s a) (hε : 0 < ε) : ∃ (b : α), ∃ (H : b ∈ s), a ≤ b ∧ b < a + ε :=\n  is_glb.exists_between h (lt_add_of_pos_right a hε)\n\ntheorem is_glb.exists_between_self_add' {α : Type u} [linear_ordered_add_comm_group α] {s : set α} {a : α} {ε : α} (h : is_glb s a) (h₂ : ¬a ∈ s) (hε : 0 < ε) : ∃ (b : α), ∃ (H : b ∈ s), a < b ∧ b < a + ε :=\n  is_glb.exists_between' h h₂ (lt_add_of_pos_right a hε)\n\ntheorem is_lub.exists_between_sub_self {α : Type u} [linear_ordered_add_comm_group α] {s : set α} {a : α} {ε : α} (h : is_lub s a) (hε : 0 < ε) : ∃ (b : α), ∃ (H : b ∈ s), a - ε < b ∧ b ≤ a :=\n  is_lub.exists_between h (sub_lt_self a hε)\n\ntheorem is_lub.exists_between_sub_self' {α : Type u} [linear_ordered_add_comm_group α] {s : set α} {a : α} {ε : α} (h : is_lub s a) (h₂ : ¬a ∈ s) (hε : 0 < ε) : ∃ (b : α), ∃ (H : b ∈ s), a - ε < b ∧ b < a :=\n  is_lub.exists_between' h h₂ (sub_lt_self a hε)\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\nnamespace monotone\n\n\ntheorem mem_upper_bounds_image {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α} (Ha : a ∈ upper_bounds s) : f a ∈ upper_bounds (f '' s) :=\n  set.ball_image_of_ball fun (x : α) (H : x ∈ s) => Hf (Ha H)\n\ntheorem mem_lower_bounds_image {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α} (Ha : a ∈ lower_bounds s) : f a ∈ lower_bounds (f '' s) :=\n  set.ball_image_of_ball fun (x : α) (H : x ∈ 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 {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} {s : set α} (hf : monotone f) : bdd_above s → bdd_above (f '' s) := sorry\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. -/\ntheorem map_bdd_below {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} {s : set α} (hf : monotone f) : bdd_below s → bdd_below (f '' s) := sorry\n\n/-- A monotone map sends a least element of a set to a least element of its image. -/\ntheorem map_is_least {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α} (Ha : is_least s a) : is_least (f '' s) (f a) :=\n  { left := set.mem_image_of_mem f (and.left Ha), 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 {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α} (Ha : is_greatest s a) : is_greatest (f '' s) (f a) :=\n  { left := set.mem_image_of_mem f (and.left Ha), right := mem_upper_bounds_image Hf (and.right Ha) }\n\ntheorem is_lub_image_le {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α} (Ha : is_lub s a) {b : β} (Hb : is_lub (f '' s) b) : b ≤ f a :=\n  and.right Hb (f a) (mem_upper_bounds_image Hf (and.left Ha))\n\ntheorem le_is_glb_image {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α} (Ha : is_glb s a) {b : β} (Hb : is_glb (f '' s) b) : f a ≤ 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 {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (hf : ∀ {x y : α}, f x ≤ f y ↔ x ≤ y) {s : set α} {x : α} (hx : is_glb (f '' s) (f x)) : is_glb s x := sorry\n\ntheorem is_lub.of_image {α : Type u} {β : Type v} [preorder α] [preorder β] {f : α → β} (hf : ∀ {x y : α}, f x ≤ f y ↔ x ≤ y) {s : set α} {x : α} (hx : is_lub (f '' s) (f x)) : is_lub s x :=\n  is_glb.of_image (fun (x y : order_dual α) => hf) hx\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/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7604135663232205}}
{"text": "import .lovelib\n\n\n/-! # LoVe Homework 6: Monads\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): `map` for Monads\n\nWe will define a `map` function for monads and derive its so-called functorial\nproperties from the three laws.\n\nWe use Lean's definition of monads. In combination, `monad` and `is_lawful_monad`\nprovide the same constants, laws, and syntactic sugar as the `lawful_monad` type\nclass from the lecture: -/\n\n#check monad\n#check is_lawful_monad\n\n/-! 1.1 (1 point). Define `map` on `m`. This function should not be confused\nwith `mmap` from the lecture's demo.\n\nHint: The challenge is to find a way to create a value of type `m β`. Follow the\ntypes. Inventory all the arguments and operations available (e.g., `pure`,\n`>>=`) with their types and see if you can plug them together like Lego\nbricks. -/\n\ndef map {m : Type → Type} [monad m] {α β : Type} (f : α → β) (ma : m α) :\n  m β := :=\nsorry\n\n/-! 1.2 (1 point). Prove the identity law for `map`.\n\nHint: You will need `bind_pure`. -/\n\nlemma map_id {m : Type → Type} [monad m] [is_lawful_monad m] {α : Type}\n    (ma : m α) :\n  map id ma = ma :=\nsorry\n\n/-! 1.3 (1 point). Prove the composition law for `map`. -/\n\nlemma map_map {m : Type → Type} [monad m] [is_lawful_monad m] {α β γ : Type}\n    (f : α → β) (g : β → γ) (ma : m α) :\n  map g (map f ma) = map (g ∘ f) ma :=\nsorry\n\n\n/-! ## Question 2 (6 points): Monadic Structure on Lists\n\n`list` can be seen as a monad, similar to `option` but with several possible\noutcomes. It is also similar to `set`, but the results are ordered and finite.\nThe code below sets `list` up as a monad. -/\n\nnamespace list\n\ndef bind {α β : Type} : list α → (α → list β) → list β\n| []        f := []\n| (a :: as) f := f a ++ bind as f\n\ndef pure {α : Type} (a : α) : list α :=\n[a]\n\nlemma pure_eq_singleton {α : Type} (a : α) :\n  pure a = [a] :=\nby refl\n\ninstance : monad list :=\n{ pure := @list.pure,\n  bind := @list.bind }\n\n/-! 2.1 (2 points). Prove the following properties of `bind` under the list\nconstructors and the append operation.\n\nHint: Use `simp [(>>=)]` if you want to unfold the definition of the bind\noperator. -/\n\nlemma bind_nil {α β : Type} (f : α → list β) :\n  ([] >>= f) = [] :=\nsorry\n\nlemma bind_cons {α β : Type} (f : α → list β) (a : α) (as : list α) :\n  (list.cons a as >>= f) = f a ++ (as >>= f) :=\nsorry\n\nlemma bind_append {α β : Type} (f : α → list β) :\n  ∀as as' : list α, ((as ++ as') >>= f) = (as >>= f) ++ (as' >>= f) :=\nsorry\n\n/-! 2.2 (3 points). Prove the three laws for `list`.\n\nHint: The simplifier cannot see through the type class definition of `pure`. You\ncan use `pure_eq_singleton` to unfold the definition or `show` to state the\nlemma statement using `bind` and `[…]`. -/\n\nlemma pure_bind {α β : Type} (a : α) (f : α → list β) :\n  (pure a >>= f) = f a :=\nsorry\n\nlemma bind_pure {α : Type} :\n  ∀as : list α, (as >>= pure) = as :=\nsorry\n\nlemma bind_assoc {α β γ : Type} (f : α → list β) (g : β → list γ) :\n  ∀as : list α, ((as >>= f) >>= g) = (as >>= (λa, f a >>= g)) :=\nsorry\n\n/-! 2.3 (1 point). Prove the following `list`-specific law. -/\n\nlemma bind_pure_comp_eq_map {α β : Type} {f : α → β} :\n  ∀as : list α, (as >>= (pure ∘ f)) = list.map f as :=\nsorry\n\nend list\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_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7603877736354626}}
{"text": "import tactic\nimport data.nat.digits\nimport logic.basic\nimport data.list\n\nnamespace happynumber\n\nsection definitions\n\n-- Perfect digital invariant (a.k.a. happy function)\n-- the sum of the pth (p > 0) power of digits of a natural number n in a base b > 1\ndef happyfunction (p : ℕ) (b : ℕ) : ℕ → ℕ\n| n := ((digits b n).map (λ d, d^p)).sum\n\n-- gets the ith iteration of the happy function w/base b, power p on natural number n\ndef happyfunction' (p : ℕ) (b : ℕ) (n : ℕ) : ℕ → ℕ\n| 0 := n\n| (i+1) := happyfunction p b (happyfunction' (i))\n\n-- Happy number\n-- a number n is b-happy iff the happy function on n w/base b, power 2 eventually equals 1\ndef happy (b : ℕ) (n : ℕ) : Prop := ∃ (j : ℕ), happyfunction' 2 b n j = 1\n\n-- height of a b-happy number n is the number of iterations of the happy function to reach 1\ndef happyheight (b n i : ℕ) (H : happyfunction' 2 b n i ≠ 1 ∧ happyfunction' 2 b n i.succ = 1) : ℕ := i.succ\n\n--Sad number\n-- a number n is b-sad iff all iterations of the happy function on n w/base b, power 2 are not equal to 1\ndef sad (b : ℕ) (n : ℕ): Prop := ∀ (j : ℕ), happyfunction' 2 b n j ≠ 1\n\nend definitions\n\n-- one iteration of happy function\n@[simp]\nlemma happyfunction'_one_eq_happyfunction (p b n : ℕ) : happyfunction' p b n 1 = happyfunction p b n :=\nbegin\n  unfold happyfunction',\nend\n\n-- commutative composition but not really bc it's technically the same function\nlemma happyfunction'_comm (p b n i : ℕ) : happyfunction p b (happyfunction' p b n i) = happyfunction' p b (happyfunction p b n) i :=\nbegin\n  rw <- happyfunction',\n  induction i with k nk,\n  unfold happyfunction',\n  unfold happyfunction' at *,\n  rw nk,\nend\n\n-- happy = not sad\nlemma happy_not_sad (b n : ℕ) : happy b n ↔ ¬(sad b n) :=\nbegin\n  split,\n  intros H S,\n  cases H with k Hk,\n  specialize S k,\n  contradiction,\n  intros S,\n  unfold sad at S,\n  --rw <- not_exists at S,\n  simp at S,\n  cases S with k Sk,\n  use k,\n  exact Sk,\nend\n\n-- every natural number n is either happy or sad (but not both)\nlemma happy_or_sad (b: ℕ) : ∀ (n : ℕ), happy b n ∨ sad b n :=\nbegin\n  intros n,\n  rw happy_not_sad,\n  finish,\nend\n\n-- happy function on 1 equals 1 for any p > 0 and b > 1\nlemma happyfunction_one (p : ℕ) (b : ℕ) : (b > 1) → happyfunction p b 1 = 1 :=\nbegin\n  intros h,\n  unfold happyfunction,\n  have H : digits b 1 = [1],\n  apply digits_of_lt,\n  linarith,\n  exact h,\n  rw H,\n  simp,\nend\n\n-- junk input. b = 0\nlemma junk_zero_one (p : ℕ) : happyfunction p 0 1 = 1 :=\nbegin\n  unfold happyfunction,\n  have H : digits 0 1 = [1],\n  refl,\n  rw H,\n  simp,\nend\n\n-- junk input. b = 1\nlemma junk_one_one (p : ℕ) : happyfunction p 1 1 = 1 :=\nbegin\n  unfold happyfunction,\n  have H : digits 1 1 = [1],\n  refl,\n  rw H,\n  simp,\nend\n\n-- just to not deal with b > 1 hypothesis\n@[simp]\nlemma happyfunction_one' (p : ℕ) (b : ℕ) : happyfunction p b 1 = 1 :=\nbegin\n  have H : (b = 0) ∨ (1 = b) ∨ (1 < b),\n  cases b,\n  left,\n  refl,\n  right,\n  have H := nat.succ_pos b,\n  have H' : 1 ≤ b.succ,\n  linarith,\n  rw le_iff_eq_or_lt at H',\n  exact H',\n  cases H,\n  rw H,\n  exact junk_zero_one p,\n  cases H,\n  rw <- H,\n  exact junk_one_one p,\n  exact happyfunction_one p b H,\nend\n\n-- any iteration of the happy function on 1 equals 1\n@[simp]\nlemma happyfunction'_one (p : ℕ) (b : ℕ) : ∀ (i : ℕ), happyfunction' p b 1 i = 1 :=\nbegin\n  intros i,\n  induction i with k ik,\n  unfold happyfunction',\n  unfold happyfunction',\n  rw ik,\n  exact happyfunction_one' p b,\nend\n\n-- for base 10, after reaching 1, will stay 1\nlemma ten_happily_ever_after (n : ℕ) (j: ℕ) : happyfunction' 2 10 n j = 1 → ∀ (i : ℕ), (j ≤ i) → happyfunction' 2 10 n i = 1 :=\nbegin\n  intros H i hi,\n  rw le_iff_exists_add at hi,\n  cases hi with c hc,\n  induction c with k ck generalizing i,\n  { simp at hc,\n    rw hc,\n    exact H,\n  },\n  { rw nat.add_succ at hc,\n    rw hc,\n    unfold happyfunction',\n    specialize ck (j+k),\n    simp at ck,\n    rw ck,\n    --unfold happyfunction,\n    simp,\n  },\nend\n\n-- for base b, after reaching 1, will stay 1\nlemma happily_ever_after (b : ℕ) (n : ℕ) (j: ℕ) : happyfunction' 2 b n j = 1 → ∀ i, (j ≤ i) → happyfunction' 2 b n i = 1 :=\nbegin\n  intros H i hi,\n  rw le_iff_exists_add at hi,\n  cases hi with c hc,\n  induction c with k ck generalizing i,\n   { simp at hc,\n     rw hc,\n     exact H,\n  }, \n  { rw nat.add_succ at hc,\n    rw hc,\n    unfold happyfunction',\n    specialize ck (j+k),\n    simp at ck,\n    rw ck,\n    --exact happyfunction_one' 2 b,\n    simp,\n  },\nend\n\n-- 1 is 10-happy\nlemma ten_happy_one : happy 10 1 :=\nbegin\n  use 0,\n  unfold happyfunction',\nend\n\n-- 7 is 10-happy\nlemma ten_happy_seven : happy 10 7 :=\nbegin\n  use 5,\n  unfold happyfunction',\n  unfold happyfunction,\n  norm_num,\nend\n\n-- happy function on 0 equals 0\n@[simp]\nlemma happyfunction_zero  (p : ℕ) (b : ℕ) : happyfunction p b 0 = 0 :=\nbegin\n  unfold happyfunction,\n  simp,\nend\n\n-- any iteration of the happy function on 0 equals 0\n@[simp]\nlemma happyfunction'_zero (p : ℕ) (b : ℕ) : ∀ (i : ℕ), happyfunction' p b 0 i = 0 :=\nbegin\n  intros i,\n  induction i with k ik,\n  unfold happyfunction',\n  unfold happyfunction',\n  rw ik,\n  --unfold happyfunction,\n  simp,\nend\n\n -- 0 is 10-sad\nlemma ten_sad_zero : sad 10 0 :=\nbegin\n  intros i hi,\n  --rw happyfunction'_zero 2 10 i at hi,\n  --linarith,\n  simp at hi,\n  exact hi,\nend\n\n-- for b=10, multiplying by 10 (adding a zero) won't make a difference\nlemma ten_happyfunction_eq_times_ten (n : ℕ) : happyfunction 2 10 n = happyfunction 2 10 (10*n) :=\nbegin\n  cases n,\n  norm_num,\n  have H : digits 10 (10*n.succ) = 0 :: digits 10 n.succ,\n  have h₁ : 10*n.succ = 0 + 10*n.succ,\n  simp,\n  rw h₁,\n  apply digits_add,\n  linarith,\n  linarith,\n  right,\n  exact nat.succ_pos n,\n  unfold happyfunction,\n  rw H,\n  norm_num,\nend\n\nlemma ten_happyfunction'_eq_times_ten (n : ℕ) : ∀ (i : ℕ), (0 < i) → happyfunction' 2 10 n i = happyfunction' 2 10 (10*n) i :=\nbegin\n  intros i i_pos,\n  cases i,\n  exfalso,\n  linarith,\n  unfold happyfunction',\n  rw happyfunction'_comm,\n  rw happyfunction'_comm 2 10 (10*n),\n  rw ten_happyfunction_eq_times_ten,\nend\n\n-- if n is 10-happy, then n*10 is 10-happy\nlemma ten_happy_times_ten (n : ℕ) : happy 10 n → happy 10 (10*n) :=\nbegin\n  intros H,\n  cases H with j Hj,\n  cases j,\n  use 1,\n  rw happyfunction'_one_eq_happyfunction,\n  unfold happyfunction' at Hj,\n  rw Hj,\n  rw <- ten_happyfunction_eq_times_ten,\n  simp,\n  use j.succ,\n  rw <- ten_happyfunction'_eq_times_ten n j.succ (nat.succ_pos'),\n  exact Hj,\nend\n\n-- 10^m is always a 10-happy number\nlemma ten_happy_pow_ten (m : ℕ) : happy 10 (10^m) :=\nbegin\n  use 1,\n  unfold happyfunction',\n  induction m with k mk,\n  rw nat.pow_zero 10,\n  exact happyfunction_one' 2 10,\n  rw nat.pow_succ,\n  rw mul_comm,\n  rw <- ten_happyfunction_eq_times_ten (10^k),\n  exact mk,\nend\n\n-- for b=10, permuting the digits won't make a difference\nlemma ten_happyfunction_eq_permute_digits (p : ℕ) (n n' : ℕ) (P : (digits 10 n) ~ (digits 10 n')) : happyfunction p 10 n = happyfunction p 10 n' :=\nbegin\n  unfold happyfunction,\n  have h := list.perm.map (λ (d : ℕ), d^p) P,\n  have h' := list.perm.sum_eq h,\n  exact h',\nend\n\nlemma ten_happyfunction'_eq_permute_digits (p i : ℕ) (n n' : ℕ) (P : (digits 10 n) ~ (digits 10 n')) : happyfunction' p 10 n i = happyfunction' p 10 n' i :=\nbegin\n  sorry\nend\n\n-- permuting a 10-happy number's digits will result in another happy number\nlemma ten_happy_permute_ten_happy (n : ℕ) (H : happy 10 n) (n' : ℕ) (P : (digits 10 n) ~ (digits 10 n')) : happy 10 n' :=\nbegin\n  sorry\nend\n\n\n-- references \"A Set of Eight Numbers\" - Arthur Porges\n-- https://oeis.org/A003621/a003621.pdf\nsection mainTheorem\n\n-- the base 10 digits of a number are all at most 9\n-- Thanks Kevin Buzzard for digits_lt_base :)\nlemma ten_digits_le_9 (n : ℕ) : ∀ (d ∈ (digits 10 n)), d ≤ 9 :=\nbegin\n  intros d H,\n  have H' := digits_lt_base (by linarith) H,\n  linarith,\nend\n\nlemma sum_list_le_len_mul_ge (l : list ℕ) (m : ℕ) : (∀ n ∈ l, n ≤ m) → l.sum ≤ m*l.length :=\nbegin\n  intros h,\n  induction l,\n  refl,\n  rw [list.sum_cons, list.length_cons, mul_add, mul_one, add_comm],\n  apply add_le_add,\n  apply l_ih,\n  intros n in_t_tl,\n  specialize h n,\n  apply h,\n  right,\n  exact in_t_tl,\n  exact h l_hd (list.mem_cons_self l_hd l_tl),\nend\n\nlemma ne_zero_iff_digits_ne_nil (b n : ℕ) : n ≠ 0 ↔ digits b n ≠ list.nil :=\nbegin\n  split,\n  { intros hn hd,\n    cases n,\n    { contradiction },\n    { have h := of_digits_digits b n.succ,\n      rw hd at h,\n      contradiction,\n    },\n  },\n  { contrapose!,\n    intros h,\n    rw h,\n    exact digits_zero b,\n  },\nend\n\nlemma ne_zero_iff_digits_len_ne_zero (b n : ℕ) : n ≠ 0 ↔ (digits b n).length ≠ 0 :=\nbegin\n  rw [ne_zero_iff_digits_ne_nil b n, not_iff_not],\n  symmetry',\n  exact list.length_eq_zero,\nend\n\nlemma digits_ge_base_pow_len (b m : ℕ) : m ≠ 0 → m ≥ (b + 2) ^ ((digits (b + 2) m).length - 1) :=\nbegin\n  apply nat.strong_induction_on m,\n  clear m,\n  intros n IH npos,\n  unfold digits at IH ⊢,\n  cases n,\n  { contradiction, },\n  { rw [digits_aux_def (b+2) (by linarith) (n.succ), list.length_cons],\n    specialize IH ((n.succ)/(b+2)) (nat.div_lt_self' n b),\n    cases nat.lt_or_ge n.succ (b+2),\n    { rw [nat.div_eq_of_lt h, digits_aux_zero, list.length],\n      exact nat.succ_pos n },\n    { have geb : (n.succ / (b + 2)) ≥ 1 := nat.div_pos h (by linarith),\n      specialize IH (by linarith [geb]),\n      rw nat.succ_sub_one,\n      have IH' := nat.mul_le_mul_left (b+2) IH,\n      rw [nat.mul_comm, <- nat.pow_succ, nat.succ_eq_add_one] at IH',\n      rw nat.add_comm ((digits_aux (b + 2) _ (n.succ / (b + 2))).length - 1) at IH',\n      rw <- nat.add_sub_assoc at IH',\n      { rw nat.add_sub_cancel_left 1 (digits_aux (b + 2) _ (n.succ / (b + 2))).length at IH',\n        have IH'' := nat.div_mul_le_self n.succ (b+2),\n        rw mul_comm at IH',\n        exact le_trans IH' IH'' },\n      { change 0 < (digits_aux (b + 2) _ (n.succ / (b + 2))).length,\n        rw nat.pos_iff_ne_zero,\n        rw [<- digits, <- ne_zero_iff_digits_len_ne_zero],\n        linarith [geb] } },\n    rwa nat.pos_iff_ne_zero }\nend\n\nlemma ten_digits_ge_base_pow_len (n : ℕ) : n ≠ 0 → n ≥ 10 ^ ((digits 10 n).length - 1) :=\nbegin\n  exact digits_ge_base_pow_len 8 n,\nend\n\nlemma digits_one_less (b m : ℕ) : m > 0 → (digits (b+2) m).length = (digits (b+2) (m/(b+2))).length + 1 :=\nbegin\n  intros hm,\n  unfold digits,\n  conv_lhs { rw digits_aux_def (b+2) (by linarith) m hm },\n  rw list.length_cons,\nend\n\n-- happyfunction n is less than 81*(number of digits in n)\nlemma ten_happyfunction_le (n : ℕ) : happyfunction 2 10 n ≤ 81*(digits 10 n).length :=\nbegin\n  unfold happyfunction,\n  have hdsq : ∀ dsq ∈ (list.map (λ (d : ℕ), d ^ 2) (digits 10 n)), dsq ≤ 81,\n  intros dsq dsqin,\n  rw list.mem_map at dsqin,\n  cases dsqin with d' hd',\n  cases hd' with dh sqh,\n  have dle := ten_digits_le_9 n d' dh,\n  rw <- sqh,\n  exact nat.pow_le_pow_of_le_left dle 2,\n  have hle := sum_list_le_len_mul_ge (list.map (λ (d : ℕ), d ^ 2) (digits 10 n)) 81 hdsq,\n  rw list.length_map (λ (d : ℕ), d ^ 2) (digits 10 n) at hle,\n  exact hle,\nend\n\nlemma helper_lt (a : ℕ) : 81*(a + 4) < 10^(a + 3) :=\nbegin\n  induction a with k ak,\n  { norm_num },\n  { repeat { rw nat.succ_add },\n    rw nat.mul_succ,\n    rw nat.pow_succ,\n    linarith,\n  },\nend\n\n-- happy function on a 4 or more digit number will result in a smaller number\nlemma ge_four_digits_dec (n : ℕ) : 4 ≤ (digits 10 n).length → happyfunction 2 10 n < n :=\nbegin\n  intros hdig,\n  have npos : n ≠ 0,\n  rw ne_zero_iff_digits_len_ne_zero 10,\n  linarith,\n  have hge := digits_ge_base_pow_len 8 n npos,\n  norm_num at hge,\n  have hle := ten_happyfunction_le n,\n  set R := (digits 10 n).length with ←h,\n  suffices : 81*R < 10^(R-1),\n  { linarith },\n  rw le_iff_exists_add at hdig,\n  cases hdig with c hc,\n  rw hc,\n  norm_num,\n  rw [add_comm 4 c, add_comm 3 c],\n  exact helper_lt c,\nend\n\n-- happy function on a 4 or more digit number will never increase the number of digits\nlemma ge_four_digits_le_digits_len (n : ℕ) : 4 ≤ (digits 10 n).length → (digits 10 (happyfunction 2 10 n)).length ≤ (digits 10 n).length :=\nbegin\n  intros h,\n  have dec := ge_four_digits_dec n h,\n  exact le_digits_len_le 10 (happyfunction 2 10 n) n (by linarith [dec]),\nend\n\n-- eventually, happyfunction on n is less than 4 digits long\nlemma eventually_lt_four_digits (n : ℕ) : ∃ (a : ℕ), (digits 10 (happyfunction' 2 10 n a)).length < 4 :=\nbegin\n  sorry\nend\n\n-- eventually, happyfunction on n is less than or equal to 162\nlemma eventually_le (n : ℕ) : ∃ (a : ℕ), happyfunction' 2 10 n a ≤ 162 :=\nbegin\n  sorry\nend\n\ndef K : set ℕ := {4, 16, 37, 58, 89, 145, 42, 20}\n\nlemma K_closed_under_happyfunction (n : ℕ) (H : n ∈ K) : happyfunction 2 10 n ∈ K :=\nbegin\n  iterate 7 {\n    cases H,\n    rw H,\n    unfold happyfunction,\n    norm_num,\n    right,\n    simp },\n  have H' := set.eq_of_mem_singleton H,\n  rw H',\n  unfold happyfunction,\n  norm_num,\n  left,\n  refl,\nend\n\nlemma K_closed_under_happyfunction' (n : ℕ) (H : n ∈ K) : ∀ (i : ℕ), happyfunction' 2 10 n i ∈ K :=\nbegin\n  intros i,\n  induction i with k ik,\n  unfold happyfunction',\n  exact H,\n  unfold happyfunction',\n  exact K_closed_under_happyfunction (happyfunction' 2 10 n k) ik,\nend\n\n-- 10-Sad numbers > 0 always end in the 8 number cycle {4, 16, 37, 58, 89, 145, 42, 20}\nlemma ten_sad_eightnumcycle (n : ℕ) (H : sad 10 n) : ∃ (j : ℕ), ∀ (i : ℕ), (j ≤ i) → (happyfunction' 2 10 n i) ∈ K :=\nbegin\n  sorry\nend\n\ntheorem ten_happyfunction_convergence (A : ℕ) : ∃ (n > 0),  ∀ (r ≥ n), (happyfunction' 2 10 A r = 1 ∨ happyfunction' 2 10 A r ∈ K) :=\nbegin\n  have H := happy_or_sad 10 A,\n  cases H,\n  cases H with n Hn,\n  use n,\n  split,\n  sorry\nend\n\nend mainTheorem\n\n#print happyfunction\n#eval happyfunction 2 10 999\n\n#print happyfunction'\n#eval happyfunction' 2 10 7 5\n\n#print happy\n#reduce happy 10 7\n\n#print sad\n#reduce sad 10 4\n\nend happynumber\n", "meta": {"author": "SnobbyDragon", "repo": "happynumbers", "sha": "e71d1c05d461a27db7dfbaa34561ad7c1e141836", "save_path": "github-repos/lean/SnobbyDragon-happynumbers", "path": "github-repos/lean/SnobbyDragon-happynumbers/happynumbers-e71d1c05d461a27db7dfbaa34561ad7c1e141836/src/happy_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7603877734428469}}
{"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 linear_algebra.free_module.finite.rank\nimport linear_algebra.matrix.to_lin\n\n/-!\n# Rank of matrices\n\nThe rank of a matrix `A` is defined to be the rank of range of the linear map corresponding to `A`.\nThis definition does not depend on the choice of basis, see `matrix.rank_eq_finrank_range_to_lin`.\n\n## Main declarations\n\n* `matrix.rank`: the rank of a matrix\n\n## TODO\n\n* Show that `matrix.rank` is equal to the row-rank and column-rank\n* Generalize away from fields\n\n-/\n\nopen_locale matrix\n\nnamespace matrix\n\nopen finite_dimensional\n\nvariables {m n o K : Type*} [m_fin : fintype m] [fintype n] [fintype o]\nvariables [decidable_eq n] [decidable_eq o] [field K]\nvariables (A : matrix m n K)\n\n/-- The rank of a matrix is the rank of its image. -/\nnoncomputable def rank : ℕ := finrank K A.to_lin'.range\n\n@[simp] lemma rank_one : rank (1 : matrix n n K) = fintype.card n :=\nby rw [rank, to_lin'_one, linear_map.range_id, finrank_top, module.free.finrank_pi]\n\n@[simp] lemma rank_zero : rank (0 : matrix n n K) = 0 :=\nby rw [rank, linear_equiv.map_zero, linear_map.range_zero, finrank_bot]\n\nlemma rank_le_card_width : A.rank ≤ fintype.card n :=\nbegin\n  convert le_of_add_le_left (A.to_lin'.finrank_range_add_finrank_ker).le,\n  exact (module.free.finrank_pi K).symm,\nend\n\nlemma rank_le_width {m n : ℕ} (A : matrix (fin m) (fin n) K) : A.rank ≤ n :=\nA.rank_le_card_width.trans $ (fintype.card_fin n).le\n\nlemma rank_mul_le (B : matrix n o K) : (A ⬝ B).rank ≤ A.rank :=\nbegin\n  refine linear_map.finrank_le_finrank_of_injective (submodule.of_le_injective _),\n  rw [to_lin'_mul],\n  exact linear_map.range_comp_le_range _ _,\nend\n\nlemma rank_unit (A : (matrix n n K)ˣ) :\n  (A : matrix n n K).rank = fintype.card n :=\nbegin\n  refine le_antisymm (rank_le_card_width A) _,\n  have := rank_mul_le (A : matrix n n K) (↑A⁻¹ : matrix n n K),\n  rwa [← mul_eq_mul, ← units.coe_mul, mul_inv_self, units.coe_one, rank_one] at this,\nend\n\nlemma rank_of_is_unit (A : matrix n n K) (h : is_unit A) :\n  A.rank = fintype.card n :=\nby { obtain ⟨A, rfl⟩ := h, exact rank_unit A }\n\ninclude m_fin\n\nlemma rank_eq_finrank_range_to_lin\n  {M₁ M₂ : Type*} [add_comm_group M₁] [add_comm_group M₂]\n  [module K M₁] [module K M₂] (v₁ : basis m K M₁) (v₂ : basis n K M₂) :\n  A.rank = finrank K (to_lin v₂ v₁ A).range :=\nbegin\n  let e₁ := (pi.basis_fun K m).equiv v₁ (equiv.refl _),\n  let e₂ := (pi.basis_fun K n).equiv v₂ (equiv.refl _),\n  have range_e₂ : (e₂ : (n → K) →ₗ[K] M₂).range = ⊤,\n  { rw linear_map.range_eq_top, exact e₂.surjective },\n  refine linear_equiv.finrank_eq (e₁.of_submodules _ _ _),\n  rw [← linear_map.range_comp, ← linear_map.range_comp_of_range_eq_top (to_lin v₂ v₁ A) range_e₂],\n  congr' 1,\n  apply linear_map.pi_ext', rintro i, apply linear_map.ext_ring,\n  have aux₁ := to_lin_self (pi.basis_fun K n) (pi.basis_fun K m) A i,\n  have aux₂ := basis.equiv_apply (pi.basis_fun K n) i v₂,\n  rw [to_lin_eq_to_lin'] at aux₁,\n  rw [pi.basis_fun_apply, linear_map.coe_std_basis] at aux₁ aux₂,\n  simp only [linear_map.comp_apply, e₁, e₂, linear_equiv.coe_coe, equiv.refl_apply, aux₁, aux₂,\n    linear_map.coe_single, to_lin_self, linear_equiv.map_sum, linear_equiv.map_smul,\n    basis.equiv_apply],\nend\n\nlemma rank_le_card_height : A.rank ≤ fintype.card m :=\n(submodule.finrank_le _).trans (module.free.finrank_pi K).le\n\nomit m_fin\n\nlemma rank_le_height {m n : ℕ} (A : matrix (fin m) (fin n) K) : A.rank ≤ m :=\nA.rank_le_card_height.trans $ (fintype.card_fin m).le\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/data/matrix/rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819236, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7603877699516053}}
{"text": "import logic.basic\n\nlemma or_iff_or {p p' q q' : Prop} :\n  (p ↔ p') → (q ↔ q') → ((p ∨ q) ↔ (p' ∨ q')) := \nbegin\n  intros hp hq, rewrite hp, rewrite hq\nend\n\nlemma and_iff_and {p p' q q' : Prop} :\n  (p ↔ p') → (q ↔ q') → ((p ∧ q) ↔ (p' ∧ q')) := \nbegin intros hp hq, rewrite hp, rewrite hq end\n\nlemma iff_of_left_of_right {p q : Prop} :\n  p → q → (p ↔ q) := \nbegin intros hp hq, constructor; intro h; assumption end\n\nlemma iff_iff_and_or_not_and_not {p q : Prop} :\n  (p ↔ q) ↔ ((p ∧ q) ∨ (¬p ∧ ¬q)) := \nbegin\n  constructor; intro h1,\n  { apply @classical.by_cases p; intro h2,\n    { left, rw ← h1, constructor; assumption }, \n    { right, rw ← h1, constructor; assumption } }, \n  { cases h1; cases h1 with hp hq, \n    { constructor; intro _; assumption }, \n    { constructor; intro _; contradiction } }\nend\n\nlemma exists_iff_exists {α : Type} {p q : α → Prop} :\n  (∀ a, p a ↔ q a) → ((∃ a, p a) ↔ ∃ a, q a) :=\nbegin\n  intro h, constructor; intro h; \n  cases h with a ha; existsi a; \n  [{rw (h a).symm}, {rw h}]; assumption\nend\n\nlemma forall_iff_not_exists_not {α : Type} {p : α → Prop} :\n  (∀ a, p a) ↔ (¬ ∃ a, ¬ p a) :=\nbegin\n  rw [@not_exists_not α p (λ x, _)], \n  apply classical.dec\nend\n\nlemma forall_iff_forall {α : Type} {p q : α → Prop} :\n  (∀ a, p a ↔ q a) → ((∀ a, p a) ↔ ∀ a, q a) :=\nbegin\n  intro h1, constructor; intros h2 a;\n  [{rw (h1 a).symm}, {rw h1}]; apply h2\nend \n\nlemma not_not_iff {φ : Prop} : ¬¬φ ↔ φ :=\niff.intro (classical.by_contradiction) (not_not_intro)\n\nlemma or_of_not_imp_right {p q} : (¬ q → p) → p ∨ q :=\nbegin\n  intro h, cases (classical.em q) with hq hq,\n  apply or.inr hq, apply or.inl (h hq)\nend\n\nvariable {α : Type}\n\nlemma exists_eq_and_iff {p : α → Prop} {a : α} :\n  (∃ x, (x = a ∧ p x)) ↔ p a :=\nbegin\n  constructor; intro h, cases h with a' ha',\n  cases ha' with ha1' ha2', subst ha1', assumption,\n  existsi a, constructor, refl, assumption\nend\n\nlemma exists_and_comm {p q : α → Prop} :\n  (∃ x, p x ∧ q x) ↔ (∃ x, q x ∧ p x) :=\nbegin apply exists_iff_exists, intro a, apply and.comm end\n\nlemma ite.rec {p} [hd : decidable p] {q : α → Prop} {f g : α} \n  (hf : p → q f) (hg : ¬ p → q g) : q (@ite p hd α f g) := \nbegin\n  unfold ite, tactic.unfreeze_local_instances, \n  cases hd with h h, simp, apply hg h, simp, apply hf h\nend\n\ndef as_true' (c : Prop) (h : decidable c) : Prop :=\n@ite _ h Prop true false\n\ndef of_as_true' {c : Prop} (h₁ : decidable c) (h₂ : as_true' c h₁) : c :=\nmatch h₁, h₂ with\n| (is_true h_c),  h₂ := h_c\n| (is_false h_c), h₂ := false.elim h₂\nend\n\nlemma eq.symm' {a1 a2 : α} :\n  a1 = a2 ↔ a2 = a1 :=\niff.intro eq.symm eq.symm\n  \n\nlemma eq_iff_eq_of_eq_of_eq {a1 a2 a3 a4 : α} :\n  a1 = a3 → a2 = a4 → (a1 = a2 ↔ a3 = a4) :=\nbegin intros h1 h2, rw [h1, h2] end\n\nlemma lt_iff_lt_of_eq_of_eq [has_lt α] {a1 a2 a3 a4 : α} :\n  a1 = a3 → a2 = a4 → (a1 < a2 ↔ a3 < a4) :=\nbegin intros h1 h2, rw [h1, h2] end", "meta": {"author": "skbaek", "repo": "cooper", "sha": "812afc6b158821f2e7dac9c91d3b6123c7a19faf", "save_path": "github-repos/lean/skbaek-cooper", "path": "github-repos/lean/skbaek-cooper/cooper-812afc6b158821f2e7dac9c91d3b6123c7a19faf/logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7603555020186499}}
{"text": "/-\nGive a natural deduction proof of ¬(𝐴∧𝐵) from ¬𝐴∨¬𝐵.\n(You do not need to use proof by contradiction.)\n-/\n\nopen classical\n\nvariables (A B : Prop)\n\nexample (h: ¬ A ∨ ¬ B) : ¬ (A ∧ B) :=\n  show ¬ (A ∧ B), from or.elim(h)(\n    assume hnA: ¬ A,\n    -- it says you don't *have* to use proof by contradiction,\n    -- but it doesn't say you *can't* ...\n    by_contradiction(\n      assume hnnAB: ¬¬(A ∧ B),\n      have hAB: A ∧ B, -- is there an easier way to get A from ¬¬A?\n      from by_contradiction(\n        assume hnAB: ¬(A ∧ B),\n        show false, from hnnAB(hnAB)\n      ),\n      have hA: A,\n      from and.left hAB,\n      show false, from hnA(hA)\n    )\n  ) (\n    assume hnB: ¬ B,\n    -- this is almost identical to the proof of the first branch\n    -- is there a way to consolidate this somehow?\n    by_contradiction(\n      assume hnnAB: ¬¬(A ∧ B),\n      have hAB: A ∧ B,\n      from by_contradiction(\n        assume hnAB: ¬(A ∧ B),\n        show false, from hnnAB(hnAB)\n      ),\n      have hB: B,\n      from and.right hAB,\n      show false, from hnB(hB)\n    )\n  )\n  \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/ex2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164656, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7603297180422489}}
{"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 linear_algebra.matrix.spectrum\nimport linear_algebra.quadratic_form.basic\n\n/-! # Positive Definite Matrices\nThis file defines positive (semi)definite matrices and connects the notion to positive definiteness\nof quadratic forms.\n## Main definition\n * `matrix.pos_def` : a matrix `M : matrix n n 𝕜` is positive definite if it is hermitian and `xᴴMx`\n   is greater than zero for all nonzero `x`.\n * `matrix.pos_semidef` : a matrix `M : matrix n n 𝕜` is positive semidefinite if it is hermitian\n   and `xᴴMx` is nonnegative for all `x`.\n-/\n\nnamespace matrix\n\nvariables {𝕜 : Type*} [is_R_or_C 𝕜] {m n : Type*} [fintype m] [fintype n]\n\nopen_locale matrix\n\n/-- A matrix `M : matrix n n 𝕜` is positive definite if it is hermitian\n   and `xᴴMx` is greater than zero for all nonzero `x`. -/\ndef pos_def (M : matrix n n 𝕜) :=\nM.is_hermitian ∧ ∀ x : n → 𝕜, x ≠ 0 → 0 < is_R_or_C.re (dot_product (star x) (M.mul_vec x))\n\nlemma pos_def.is_hermitian {M : matrix n n 𝕜} (hM : M.pos_def) : M.is_hermitian := hM.1\n\n/-- A matrix `M : matrix n n 𝕜` is positive semidefinite if it is hermitian\n   and `xᴴMx` is nonnegative for all `x`. -/\ndef pos_semidef (M : matrix n n 𝕜) :=\nM.is_hermitian ∧ ∀ x : n → 𝕜, 0 ≤ is_R_or_C.re (dot_product (star x) (M.mul_vec x))\n\nlemma pos_def.pos_semidef {M : matrix n n 𝕜} (hM : M.pos_def) : M.pos_semidef :=\nbegin\n  refine ⟨hM.1, _⟩,\n  intros x,\n  by_cases hx : x = 0,\n  { simp only [hx, zero_dot_product, star_zero, is_R_or_C.zero_re'] },\n  { exact le_of_lt (hM.2 x hx) }\nend\n\n\n\n@[simp] lemma pos_semidef_submatrix_equiv {M : matrix n n 𝕜} (e : m ≃ n) :\n  (M.submatrix e e).pos_semidef ↔ M.pos_semidef :=\n⟨λ h, by simpa using h.submatrix e.symm, λ h, h.submatrix _⟩\n\nlemma pos_def.transpose {M : matrix n n 𝕜} (hM : M.pos_def) : Mᵀ.pos_def :=\nbegin\n  refine ⟨is_hermitian.transpose hM.1, λ x hx, _⟩,\n  convert hM.2 (star x) (star_ne_zero.2 hx) using 2,\n  rw [mul_vec_transpose, matrix.dot_product_mul_vec, star_star, dot_product_comm]\nend\n\nlemma pos_def_of_to_quadratic_form' [decidable_eq n] {M : matrix n n ℝ}\n  (hM : M.is_symm) (hMq : M.to_quadratic_form'.pos_def) :\n  M.pos_def :=\nbegin\n  refine ⟨hM, λ x hx, _⟩,\n  simp only [to_quadratic_form', quadratic_form.pos_def, bilin_form.to_quadratic_form_apply,\n    matrix.to_bilin'_apply'] at hMq,\n  apply hMq x hx,\nend\n\nlemma pos_def_to_quadratic_form' [decidable_eq n] {M : matrix n n ℝ} (hM : M.pos_def) :\n  M.to_quadratic_form'.pos_def :=\nbegin\n  intros x hx,\n  simp only [to_quadratic_form', bilin_form.to_quadratic_form_apply, matrix.to_bilin'_apply'],\n  apply hM.2 x hx,\nend\n\nnamespace pos_def\n\nvariables {M : matrix n n ℝ} (hM : M.pos_def)\ninclude hM\n\nlemma det_pos [decidable_eq n] : 0 < det M :=\nbegin\n  rw hM.is_hermitian.det_eq_prod_eigenvalues,\n  apply finset.prod_pos,\n  intros i _,\n  rw hM.is_hermitian.eigenvalues_eq,\n  apply hM.2 _ (λ h, _),\n  have h_det : (hM.is_hermitian.eigenvector_matrix)ᵀ.det = 0,\n    from matrix.det_eq_zero_of_row_eq_zero i (λ j, congr_fun h j),\n  simpa only [h_det, not_is_unit_zero] using\n    is_unit_det_of_invertible hM.is_hermitian.eigenvector_matrixᵀ,\nend\n\nend pos_def\n\nend matrix\n\nnamespace quadratic_form\n\nvariables {n : Type*} [fintype n]\n\nlemma pos_def_of_to_matrix'\n  [decidable_eq n] {Q : quadratic_form ℝ (n → ℝ)} (hQ : Q.to_matrix'.pos_def) :\n  Q.pos_def :=\nbegin\n  rw [←to_quadratic_form_associated ℝ Q,\n      ←bilin_form.to_matrix'.left_inv ((associated_hom _) Q)],\n  apply matrix.pos_def_to_quadratic_form' hQ\nend\n\nlemma pos_def_to_matrix' [decidable_eq n] {Q : quadratic_form ℝ (n → ℝ)} (hQ : Q.pos_def) :\n  Q.to_matrix'.pos_def :=\nbegin\n  rw [←to_quadratic_form_associated ℝ Q,\n    ←bilin_form.to_matrix'.left_inv ((associated_hom _) Q)] at hQ,\n  apply matrix.pos_def_of_to_quadratic_form' (is_symm_to_matrix' Q) hQ,\nend\n\nend quadratic_form\n\nnamespace matrix\n\nvariables {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n]\n\n/-- A positive definite matrix `M` induces a norm `‖x‖ = sqrt (re xᴴMx)`. -/\n@[reducible]\nnoncomputable def normed_add_comm_group.of_matrix {M : matrix n n 𝕜} (hM : M.pos_def) :\n  normed_add_comm_group (n → 𝕜) :=\n@inner_product_space.of_core.to_normed_add_comm_group _ _ _ _ _\n{ inner := λ x y, dot_product (star x) (M.mul_vec y),\n  conj_symm := λ x y, by\n    rw [star_dot_product, star_ring_end_apply, star_star, star_mul_vec,\n      dot_product_mul_vec, hM.is_hermitian.eq],\n  nonneg_re := λ x,\n    begin\n      by_cases h : x = 0,\n      { simp [h] },\n      { exact le_of_lt (hM.2 x h) }\n    end,\n  definite := λ x hx,\n    begin\n      by_contra' h,\n      simpa [hx, lt_self_iff_false] using hM.2 x h,\n    end,\n  add_left := by simp only [star_add, add_dot_product, eq_self_iff_true, forall_const],\n  smul_left := λ x y r, by rw [← smul_eq_mul, ←smul_dot_product, star_ring_end_apply, ← star_smul] }\n\n/-- A positive definite matrix `M` induces an inner product `⟪x, y⟫ = xᴴMy`. -/\ndef inner_product_space.of_matrix {M : matrix n n 𝕜} (hM : M.pos_def) :\n  @inner_product_space 𝕜 (n → 𝕜) _ (normed_add_comm_group.of_matrix hM) :=\ninner_product_space.of_core _\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/pos_def.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465134460243, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7603126116335956}}
{"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 algebra.big_operators.intervals\nimport algebra.geom_sum\nimport data.nat.bitwise\nimport data.nat.log\nimport data.nat.parity\nimport data.nat.prime\nimport ring_theory.multiplicity\n\n/-!\n# Natural number multiplicity\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 the multiplicity function (the maximum prime power dividing a\nnumber) when applied to naturals, in particular calculating it for factorials and binomial\ncoefficients.\n\n## Multiplicity calculations\n\n* `nat.multiplicity_factorial`: Legendre's Theorem. The multiplicity of `p` in `n!` is\n  `n/p + ... + n/p^b` for any `b` such that `n/p^(b + 1) = 0`.\n* `nat.multiplicity_factorial_mul`: The multiplicity of `p` in `(p * n)!` is `n` more than that of\n  `n!`.\n* `nat.multiplicity_choose`: The multiplicity of `p` in `n.choose k` is the number of carries when\n  `k` and`n - k` are added in base `p`.\n\n## Other declarations\n\n* `nat.multiplicity_eq_card_pow_dvd`: The multiplicity of `m` in `n` is the number of positive\n  natural numbers `i` such that `m ^ i` divides `n`.\n* `nat.multiplicity_two_factorial_lt`: The multiplicity of `2` in `n!` is strictly less than `n`.\n* `nat.prime.multiplicity_something`: Specialization of `multiplicity.something` to a prime in the\n  naturals. Avoids having to provide `p ≠ 1` and other trivialities, along with translating between\n  `prime` and `nat.prime`.\n\n## Tags\n\nLegendre, p-adic\n-/\n\nopen finset nat multiplicity\nopen_locale big_operators nat\n\nnamespace nat\n\n/-- The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i`\ndivides `n`. This set is expressed by filtering `Ico 1 b` where `b` is any bound greater than\n`log m n`. -/\nlemma multiplicity_eq_card_pow_dvd {m n b : ℕ} (hm : m ≠ 1) (hn : 0 < n) (hb : log m n < b):\n  multiplicity m n = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card :=\ncalc\n  multiplicity m n = ↑(Ico 1 $ ((multiplicity m n).get (finite_nat_iff.2 ⟨hm, hn⟩) + 1)).card\n    : by simp\n... = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card\n    : congr_arg coe $ congr_arg card $ finset.ext $ λ i,\n      begin\n        rw [mem_filter, mem_Ico, mem_Ico, lt_succ_iff, ←@part_enat.coe_le_coe i, part_enat.coe_get,\n          ←pow_dvd_iff_le_multiplicity, and.right_comm],\n        refine (and_iff_left_of_imp (λ h, lt_of_le_of_lt _ hb)).symm,\n        cases m,\n        { rw [zero_pow, zero_dvd_iff] at h,\n          exacts [(hn.ne' h.2).elim, h.1] },\n        exact le_log_of_pow_le (one_lt_iff_ne_zero_and_ne_one.2 ⟨m.succ_ne_zero, hm⟩)\n          (le_of_dvd hn h.2)\n      end\n\nnamespace prime\n\n\n\nlemma multiplicity_mul {p m n : ℕ} (hp : p.prime) :\n  multiplicity p (m * n) = multiplicity p m + multiplicity p n :=\nmultiplicity.mul hp.prime\n\nlemma multiplicity_pow {p m n : ℕ} (hp : p.prime) :\n  multiplicity p (m ^ n) = n • (multiplicity p m) :=\nmultiplicity.pow hp.prime\n\nlemma multiplicity_self {p : ℕ} (hp : p.prime) : multiplicity p p = 1 :=\nmultiplicity_self hp.prime.not_unit hp.ne_zero\n\nlemma multiplicity_pow_self {p n : ℕ} (hp : p.prime) : multiplicity p (p ^ n) = n :=\nmultiplicity_pow_self hp.ne_zero hp.prime.not_unit n\n\n/-- **Legendre's Theorem**\n\nThe multiplicity of a prime in `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed\nover the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/\nlemma multiplicity_factorial {p : ℕ} (hp : p.prime) :\n  ∀ {n b : ℕ}, log p n < b → multiplicity p n! = (∑ i in Ico 1 b, n / p ^ i : ℕ)\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  ... = (∑ i in Ico 1 b, n / p ^ i : ℕ) + ((finset.Ico 1 b).filter (λ i, p ^ i ∣ n+1)).card :\n    by rw [multiplicity_factorial ((log_mono_right $ le_succ _).trans_lt hb),\n      ← multiplicity_eq_card_pow_dvd hp.ne_one (succ_pos _) hb]\n  ... = (∑ i in Ico 1 b, (n / p ^ i + if p^i ∣ n+1 then 1 else 0) : ℕ) :\n    by { rw [sum_add_distrib, sum_boole], simp }\n  ... = (∑ i in Ico 1 b, (n + 1) / p ^ i : ℕ) :\n    congr_arg coe $ finset.sum_congr rfl $ λ _ _, (succ_div _ _).symm\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 : ℕ} (hp : p.prime) :\n  multiplicity p (p * (n + 1))! = multiplicity p (p * n)! + multiplicity p (n + 1) + 1 :=\nbegin\n  have hp' := hp.prime,\n  have h0 : 2 ≤ p := hp.two_le,\n  have h1 : 1 ≤ p * n + 1 := nat.le_add_left _ _,\n  have h2 : p * n + 1 ≤ p * (n + 1), linarith,\n  have h3 : p * n + 1 ≤ p * (n + 1) + 1, linarith,\n  have hm : multiplicity p (p * n)! ≠ ⊤,\n  { rw [ne.def, eq_top_iff_not_finite, not_not, finite_nat_iff],\n    exact ⟨hp.ne_one, factorial_pos _⟩ },\n  revert hm,\n  have h4 : ∀ m ∈ Ico (p * n + 1) (p * (n + 1)), multiplicity p m = 0,\n  { intros m hm,\n    rw [multiplicity_eq_zero, ← not_dvd_iff_between_consec_multiples _ hp.pos],\n    rw [mem_Ico] at hm,\n    exact ⟨n, lt_of_succ_le hm.1, hm.2⟩ },\n  simp_rw [← prod_Ico_id_eq_factorial, multiplicity.finset.prod hp', ← sum_Ico_consecutive _ h1 h3,\n    add_assoc], intro h,\n  rw [part_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 : part_enat)]\nend\n\n/-- The multiplicity of `p` in `(p * n)!` is `n` more than that of `n!`. -/\nlemma multiplicity_factorial_mul {n p : ℕ} (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, hp.prime, ih,\n      multiplicity_factorial_mul_succ, ←add_assoc, nat.cast_one, nat.cast_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 : ℕ} {n r b : ℕ} (hp : p.prime) (hbn : log p n < b) :\n   p ^ r ∣ n! ↔ r ≤ ∑ i in Ico 1 b, n / p ^ i :=\nby rw [← part_enat.coe_le_coe, ← hp.multiplicity_factorial hbn, ← pow_dvd_iff_le_multiplicity]\n\nlemma multiplicity_factorial_le_div_pred {p : ℕ} (hp : p.prime) (n : ℕ) :\n  multiplicity p n! ≤ (n/(p - 1) : ℕ) :=\nbegin\n  rw [hp.multiplicity_factorial (lt_succ_self _), part_enat.coe_le_coe],\n  exact nat.geom_sum_Ico_le hp.two_le _ _,\nend\n\nlemma multiplicity_choose_aux {p n b k : ℕ} (hp : p.prime) (hkn : k ≤ n) :\n  ∑ i in finset.Ico 1 b, n / p ^ i =\n  ∑ i in finset.Ico 1 b, k / p ^ i + ∑ i in finset.Ico 1 b, (n - k) / p ^ i +\n  ((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card :=\ncalc ∑ i in finset.Ico 1 b, n / p ^ i\n    = ∑ i in finset.Ico 1 b, (k + (n - k)) / p ^ i :\n    by simp only [add_tsub_cancel_of_le hkn]\n... = ∑ i in finset.Ico 1 b, (k / p ^ i + (n - k) / p ^ i +\n      if p ^ i ≤ 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 multiplicity 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 : ℕ} (hp : p.prime) (hkn : k ≤ n) (hnb : log p n < b) :\n  multiplicity p (choose n k) =\n  ((Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card :=\nhave h₁ : multiplicity p (choose n k) + multiplicity p (k! * (n - k)!) =\n    ((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card +\n    multiplicity p (k! * (n - k)!),\n  begin\n    rw [← hp.multiplicity_mul, ← mul_assoc, choose_mul_factorial_mul_factorial hkn,\n        hp.multiplicity_factorial hnb, hp.multiplicity_mul,\n        hp.multiplicity_factorial ((log_mono_right hkn).trans_lt hnb),\n        hp.multiplicity_factorial (lt_of_le_of_lt (log_mono_right tsub_le_self) hnb),\n        multiplicity_choose_aux hp hkn],\n    simp [add_comm],\n  end,\n(part_enat.add_right_cancel_iff\n  (part_enat.ne_top_iff_dom.2 $\n    by exact finite_nat_iff.2\n      ⟨ne_of_gt hp.one_lt, mul_pos (factorial_pos k) (factorial_pos (n - k))⟩)).1\n  h₁\n\n/-- A lower bound on the multiplicity of `p` in `choose n k`. -/\nlemma multiplicity_le_multiplicity_choose_add {p : ℕ} (hp : p.prime) : ∀ (n k : ℕ),\n  multiplicity p n ≤ multiplicity p (choose n k) + multiplicity p k\n| _     0     := by simp\n| 0     (_+1) := by simp\n| (n+1) (k+1) :=\nbegin\n  rw ← hp.multiplicity_mul,\n  refine multiplicity_le_multiplicity_of_dvd_right _,\n  rw [← succ_mul_choose_eq],\n  exact dvd_mul_right _ _\nend\n\nvariables {p n k : ℕ}\n\nlemma multiplicity_choose_prime_pow_add_multiplicity (hp : p.prime) (hkn : k ≤ p ^ n)\n  (hk0 : k ≠ 0) :\n  multiplicity p (choose (p ^ n) k) + multiplicity p k = n :=\nle_antisymm\n  (have hdisj : disjoint\n      ((Ico 1 n.succ).filter (λ i, p ^ i ≤ k % p ^ i + (p ^ n - k) % p ^ i))\n      ((Ico 1 n.succ).filter (λ i, p ^ i ∣ 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.bot_lt\n        (lt_succ_of_le (log_mono_right hkn)),\n      ← nat.cast_add, part_enat.coe_le_coe, log_pow hp.one_lt,\n      ← card_disjoint_union hdisj, filter_union_right],\n    have filter_le_Ico := (Ico 1 n.succ).card_filter_le _,\n    rwa card_Ico 1 n.succ at filter_le_Ico,\n  end)\n  (by rw [← hp.multiplicity_pow_self];\n    exact multiplicity_le_multiplicity_choose_add hp _ _)\n\nlemma multiplicity_choose_prime_pow {p n k : ℕ} (hp : p.prime) (hkn : k ≤ p ^ n) (hk0 : k ≠ 0) :\n  multiplicity p (choose (p ^ n) k) =\n    ↑(n - (multiplicity p k).get (finite_nat_iff.2 ⟨hp.ne_one, hk0.bot_lt⟩)) :=\npart_enat.eq_coe_sub_of_add_eq_coe $ multiplicity_choose_prime_pow_add_multiplicity hp hkn hk0\n\nlemma dvd_choose_pow (hp : prime p) (hk : k ≠ 0) (hkp : k ≠ p ^ n) : p ∣ (p ^ n).choose k :=\nbegin\n  obtain hkp | hkp := hkp.symm.lt_or_lt,\n  { simp [choose_eq_zero_of_lt hkp] },\n  refine multiplicity_ne_zero.1 (λ h, hkp.not_le $ nat.le_of_dvd hk.bot_lt _),\n  have H := hp.multiplicity_choose_prime_pow_add_multiplicity hkp.le hk,\n  rw [h, zero_add, eq_coe_iff] at H,\n  exact H.1,\nend\n\nlemma dvd_choose_pow_iff (hp : prime p) : p ∣ (p ^ n).choose k ↔ k ≠ 0 ∧ k ≠ p ^ n :=\nby refine ⟨λ h, ⟨_, _⟩, λ h, dvd_choose_pow hp h.1 h.2⟩; rintro rfl; simpa [hp.ne_one] using h\n\nend prime\n\nlemma multiplicity_two_factorial_lt : ∀ {n : ℕ} (h : n ≠ 0), multiplicity 2 n! < n :=\nbegin\n  have h2 := prime_two.prime,\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] },\n    have : multiplicity 2 (2 * n)! < (2 * n : ℕ),\n    { rw [prime_two.multiplicity_factorial_mul],\n      refine (part_enat.add_lt_add_right (ih hn) (part_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)! < ↑(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.2 (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": "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/multiplicity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.946596665680527, "lm_q2_score": 0.8031738034238807, "lm_q1q2_score": 0.7602816442829925}}
{"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édéric Dupuis\n-/\nimport analysis.inner_product_space.projection\n\n/-!\n# Convex cones\n\nIn a `𝕜`-module `E`, we define a convex cone as a set `s` such that `a • x + b • y ∈ s` whenever\n`x, y ∈ 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 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 ≤ ⟪ x, y ⟫`.\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 → ℝ` which is\n  nonnegative on `p ∩ s`, then there exists a globally defined linear function\n  `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`.\n* `exists_extension_of_le_sublinear`:\n  Hahn-Banach theorem: if `N : E → ℝ` is a sublinear map, `f` is a linear map\n  defined on a subspace of `E`, and `f x ≤ 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 ≤ N x`\n  for all `x`\n\nWe prove the following theorems:\n* `convex_cone.hyperplane_separation_of_nonempty_of_is_closed_of_nmem`:\n  This variant of the\n  [hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem)\n  states that given a nonempty, closed, convex cone `K` in a complete, real inner product space `H`\n  and a point `b` disjoint from it, there is a vector `y` which separates `b` from `K` in the sense\n  that for all points `x` in `K`, `0 ≤ ⟪x, y⟫_ℝ` and `⟪y, b⟫_ℝ < 0`. This is also a geometric\n  interpretation of the\n  [Farkas lemma](https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation).\n* `convex_cone.inner_dual_cone_of_inner_dual_cone_eq_self`:\n  The `inner_dual_cone` of the `inner_dual_cone` of a nonempty, closed, convex cone is itself.\n\n## Implementation notes\n\nWhile `convex 𝕜` is a predicate on sets, `convex_cone 𝕜 E` is a bundled convex cone.\n\n## References\n\n* https://en.wikipedia.org/wiki/Convex_cone\n* [Stephen P. Boyd and Lieven Vandenberghe, *Convex Optimization*][boydVandenberghe2004]\n* [Emo Welzl and Bernd Gärtner, *Cone Programming*][welzl_garter]\n-/\n\n\nopen set linear_map\nopen_locale classical pointwise\n\nvariables {𝕜 E F G : Type*}\n\n/-! ### Definition of `convex_cone` and basic properties -/\n\nsection definitions\nvariables (𝕜 E) [ordered_semiring 𝕜]\n\n/-- A convex cone is a subset `s` of a `𝕜`-module such that `a • x + b • y ∈ s` whenever `a, b > 0`\nand `x, y ∈ s`. -/\nstructure convex_cone [add_comm_monoid E] [has_smul 𝕜 E] :=\n(carrier : set E)\n(smul_mem' : ∀ ⦃c : 𝕜⦄, 0 < c → ∀ ⦃x : E⦄, x ∈ carrier → c • x ∈ carrier)\n(add_mem' : ∀ ⦃x⦄ (hx : x ∈ carrier) ⦃y⦄ (hy : y ∈ carrier), x + y ∈ carrier)\n\nend definitions\n\nvariables {𝕜 E}\n\nnamespace convex_cone\nsection ordered_semiring\nvariables [ordered_semiring 𝕜] [add_comm_monoid E]\n\nsection has_smul\nvariables [has_smul 𝕜 E] (S T : convex_cone 𝕜 E)\n\ninstance : set_like (convex_cone 𝕜 E) E :=\n{ coe := carrier,\n  coe_injective' := λ S T h, by cases S; cases T; congr' }\n\n@[simp] lemma coe_mk {s : set E} {h₁ h₂} : ↑(@mk 𝕜 _ _ _ _ s h₁ h₂) = s := rfl\n\n@[simp] lemma mem_mk {s : set E} {h₁ h₂ x} : x ∈ @mk 𝕜 _ _ _ _ s h₁ h₂ ↔ x ∈ s := iff.rfl\n\n/-- Two `convex_cone`s are equal if they have the same elements. -/\n@[ext] theorem ext {S T : convex_cone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := set_like.ext h\n\nlemma smul_mem {c : 𝕜} {x : E} (hc : 0 < c) (hx : x ∈ S) : c • x ∈ S := S.smul_mem' hc hx\n\nlemma add_mem ⦃x⦄ (hx : x ∈ S) ⦃y⦄ (hy : y ∈ S) : x + y ∈ S := S.add_mem' hx hy\n\ninstance : add_mem_class (convex_cone 𝕜 E) E :=\n{ add_mem := λ c a b ha hb, add_mem c ha hb }\n\ninstance : has_inf (convex_cone 𝕜 E) :=\n⟨λ S T, ⟨S ∩ T, λ c hc x hx, ⟨S.smul_mem hc hx.1, T.smul_mem hc hx.2⟩,\n  λ x hx y hy, ⟨S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2⟩⟩⟩\n\n@[simp] lemma coe_inf : ((S ⊓ T : convex_cone 𝕜 E) : set E) = ↑S ∩ ↑T := rfl\n\nlemma mem_inf {x} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := iff.rfl\n\ninstance : has_Inf (convex_cone 𝕜 E) :=\n⟨λ S, ⟨⋂ s ∈ S, ↑s,\n  λ c hc x hx, mem_bInter $ λ s hs, s.smul_mem hc $ mem_Inter₂.1 hx s hs,\n  λ x hx y hy, mem_bInter $ λ s hs, s.add_mem (mem_Inter₂.1 hx s hs) (mem_Inter₂.1 hy s hs)⟩⟩\n\n@[simp] lemma coe_Inf (S : set (convex_cone 𝕜 E)) : ↑(Inf S) = ⋂ s ∈ S, (s : set E) := rfl\n\nlemma mem_Inf {x : E} {S : set (convex_cone 𝕜 E)} : x ∈ Inf S ↔ ∀ s ∈ S, x ∈ s := mem_Inter₂\n\n@[simp] lemma coe_infi {ι : Sort*} (f : ι → convex_cone 𝕜 E) : ↑(infi f) = ⋂ i, (f i : set E) :=\nby simp [infi]\n\nlemma mem_infi {ι : Sort*} {x : E} {f : ι → convex_cone 𝕜 E} : x ∈ infi f ↔ ∀ i, x ∈ f i :=\nmem_Inter₂.trans $ by simp\n\nvariables (𝕜)\n\ninstance : has_bot (convex_cone 𝕜 E) := ⟨⟨∅, λ c hc x, false.elim, λ x, false.elim⟩⟩\n\nlemma mem_bot (x : E) : x ∈ (⊥ : convex_cone 𝕜 E) = false := rfl\n\n@[simp] lemma coe_bot : ↑(⊥ : convex_cone 𝕜 E) = (∅ : set E) := rfl\n\ninstance : has_top (convex_cone 𝕜 E) := ⟨⟨univ, λ c hc x hx, mem_univ _, λ x hx y hy, mem_univ _⟩⟩\n\nlemma mem_top (x : E) : x ∈ (⊤ : convex_cone 𝕜 E) := mem_univ x\n\n@[simp] lemma coe_top : ↑(⊤ : convex_cone 𝕜 E) = (univ : set E) := rfl\n\ninstance : complete_lattice (convex_cone 𝕜 E) :=\n{ le           := (≤),\n  lt           := (<),\n  bot          := (⊥),\n  bot_le       := λ S x, false.elim,\n  top          := (⊤),\n  le_top       := λ S x hx, mem_top 𝕜 x,\n  inf          := (⊓),\n  Inf          := has_Inf.Inf,\n  sup          := λ a b, Inf {x | a ≤ x ∧ b ≤ x},\n  Sup          := λ s, Inf {T | ∀ S ∈ s, S ≤ T},\n  le_sup_left  := λ a b, λ x hx, mem_Inf.2 $ λ s hs, hs.1 hx,\n  le_sup_right := λ a b, λ x hx, mem_Inf.2 $ λ s hs, hs.2 hx,\n  sup_le       := λ a b c ha hb x hx, mem_Inf.1 hx c ⟨ha, hb⟩,\n  le_inf       := λ a b c ha hb x hx, ⟨ha hx, hb hx⟩,\n  inf_le_left  := λ a b x, and.left,\n  inf_le_right := λ a b x, and.right,\n  le_Sup       := λ s p hs x hx, mem_Inf.2 $ λ t ht, ht p hs hx,\n  Sup_le       := λ s p hs x hx, mem_Inf.1 hx p hs,\n  le_Inf       := λ s a ha x hx, mem_Inf.2 $ λ t ht, ha t ht hx,\n  Inf_le       := λ s a ha x hx, mem_Inf.1 hx _ ha,\n  .. set_like.partial_order }\n\ninstance : inhabited (convex_cone 𝕜 E) := ⟨⊥⟩\n\nend has_smul\n\nsection module\nvariables [module 𝕜 E] (S : convex_cone 𝕜 E)\n\nprotected lemma convex : convex 𝕜 (S : set E) :=\nconvex_iff_forall_pos.2 $ λ x hx y hy a b ha hb _, 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 𝕜]\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 𝕜 E] (S : convex_cone 𝕜 E)\n\nlemma smul_mem_iff {c : 𝕜} (hc : 0 < c) {x : E} :\n  c • x ∈ S ↔ x ∈ S :=\n⟨λ h, inv_smul_smul₀ hc.ne' x ▸ S.smul_mem (inv_pos.2 hc) h, S.smul_mem hc⟩\n\nend mul_action\n\nsection module\nvariables [module 𝕜 E] [module 𝕜 F] [module 𝕜 G]\n\n/-- The image of a convex cone under a `𝕜`-linear map is a convex cone. -/\ndef map (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 E) : convex_cone 𝕜 F :=\n{ carrier := f '' S,\n  smul_mem' := λ c hc y ⟨x, hx, hy⟩, hy ▸ f.map_smul c x ▸ mem_image_of_mem f (S.smul_mem hc hx),\n  add_mem' := λ y₁ ⟨x₁, hx₁, hy₁⟩ y₂ ⟨x₂, hx₂, hy₂⟩, hy₁ ▸ hy₂ ▸ f.map_add x₁ x₂ ▸\n    mem_image_of_mem f (S.add_mem hx₁ hx₂) }\n\n@[simp] lemma mem_map {f : E →ₗ[𝕜] F} {S : convex_cone 𝕜 E} {y : F} :\n  y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=\nmem_image_iff_bex\n\nlemma map_map (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 E) :\n  (S.map f).map g = S.map (g.comp f) :=\nset_like.coe_injective $ image_image g f S\n\n@[simp] lemma map_id (S : convex_cone 𝕜 E) : S.map linear_map.id = S :=\nset_like.coe_injective $ image_id _\n\n/-- The preimage of a convex cone under a `𝕜`-linear map is a convex cone. -/\ndef comap (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 F) : convex_cone 𝕜 E :=\n{ carrier := f ⁻¹' S,\n  smul_mem' := λ c hc x hx, by { rw [mem_preimage, f.map_smul c], exact S.smul_mem hc hx },\n  add_mem' := λ x hx y hy, by { rw [mem_preimage, f.map_add], exact S.add_mem hx hy } }\n\n@[simp] lemma coe_comap (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 F) : (S.comap f : set E) = f ⁻¹' S := rfl\n\n@[simp] lemma comap_id (S : convex_cone 𝕜 E) : S.comap linear_map.id = S :=\nset_like.coe_injective preimage_id\n\nlemma comap_comap (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : convex_cone 𝕜 G) :\n  (S.comap g).comap f = S.comap (g.comp f) :=\nset_like.coe_injective $ preimage_comp.symm\n\n@[simp] lemma mem_comap {f : E →ₗ[𝕜] F} {S : convex_cone 𝕜 F} {x : E} : x ∈ S.comap f ↔ f x ∈ S :=\niff.rfl\n\nend module\nend add_comm_monoid\n\nsection ordered_add_comm_group\nvariables [ordered_add_comm_group E] [module 𝕜 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 𝕜 E) (h : ∀ x y : E, x ≤ y ↔ y - x ∈ S) :\n  ordered_smul 𝕜 E :=\nordered_smul.mk'\nbegin\n  intros x y z xy hz,\n  rw [h (z • x) (z • y), ←smul_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 𝕜]\n\nsection add_comm_monoid\nvariables [add_comm_monoid E] [has_smul 𝕜 E] (S : convex_cone 𝕜 E)\n\n/-- A convex cone is pointed if it includes `0`. -/\ndef pointed (S : convex_cone 𝕜 E) : Prop := (0 : E) ∈ S\n\n/-- A convex cone is blunt if it doesn't include `0`. -/\ndef blunt (S : convex_cone 𝕜 E) : Prop := (0 : E) ∉ S\n\nlemma pointed_iff_not_blunt (S : convex_cone 𝕜 E) : S.pointed ↔ ¬S.blunt :=\n⟨λ h₁ h₂, h₂ h₁, not_not.mp⟩\n\nlemma blunt_iff_not_pointed (S : convex_cone 𝕜 E) : S.blunt ↔ ¬S.pointed :=\nby rw [pointed_iff_not_blunt, not_not]\n\nlemma pointed.mono {S T : convex_cone 𝕜 E} (h : S ≤ T) : S.pointed → T.pointed := @h _\n\nlemma blunt.anti {S T : convex_cone 𝕜 E} (h : T ≤ S) : S.blunt → T.blunt := (∘ @@h)\n\nend add_comm_monoid\n\nsection add_comm_group\nvariables [add_comm_group E] [has_smul 𝕜 E] (S : convex_cone 𝕜 E)\n\n/-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/\ndef flat : Prop := ∃ x ∈ S, x ≠ (0 : E) ∧ -x ∈ S\n\n/-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/\ndef salient : Prop := ∀ x ∈ S, x ≠ (0 : E) → -x ∉ S\n\nlemma salient_iff_not_flat (S : convex_cone 𝕜 E) : S.salient ↔ ¬S.flat :=\nbegin\n  split,\n  { rintros h₁ ⟨x, xs, H₁, H₂⟩,\n    exact h₁ x xs H₁ H₂ },\n  { intro h,\n    unfold flat at h,\n    push_neg at h,\n    exact h }\nend\n\nlemma flat.mono {S T : convex_cone 𝕜 E} (h : S ≤ T) : S.flat → T.flat\n| ⟨x, hxS, hx, hnxS⟩ := ⟨x, h hxS, hx, h hnxS⟩\n\nlemma salient.anti {S T : convex_cone 𝕜 E} (h : T ≤ S) : S.salient → T.salient :=\nλ hS x hxT hx hnT, hS x (h hxT) hx (h hnT)\n\n/-- A flat cone is always pointed (contains `0`). -/\nlemma flat.pointed {S : convex_cone 𝕜 E} (hS : S.flat) : S.pointed :=\nbegin\n  obtain ⟨x, hx, _, hxneg⟩ := hS,\n  rw [pointed, ←add_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 𝕜 E} : S.blunt → 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₁ : S.pointed) : preorder E :=\n{ le := λ x y, y - x ∈ S,\n  le_refl := λ x, by change x - x ∈ S; rw [sub_self x]; exact h₁,\n  le_trans := λ 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₁ : S.pointed) (h₂ : 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 ≠ 0 := λ h'', h (eq_of_sub_eq_zero h'').symm,\n      have H := h₂ (b-a) ab h',\n      rw neg_sub b a at H,\n      exact H ba,\n    end,\n  ..to_preorder S h₁ }\n\n/-- A pointed and salient cone defines an `ordered_add_comm_group`. -/\ndef to_ordered_add_comm_group (h₁ : S.pointed) (h₂ : 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) ∈ S,\n      rw add_sub_add_left_eq_sub,\n      exact hab,\n    end,\n  ..to_partial_order S h₁ h₂,\n  ..show add_comm_group E, by apply_instance }\n\nend add_comm_group\n\nsection module\nvariables [add_comm_monoid E] [module 𝕜 E]\n\ninstance : has_zero (convex_cone 𝕜 E) := ⟨⟨0, λ _ _, by simp, λ _, by simp⟩⟩\n\n@[simp] lemma mem_zero (x : E) : x ∈ (0 : convex_cone 𝕜 E) ↔ x = 0 := iff.rfl\n@[simp] lemma coe_zero : ((0 : convex_cone 𝕜 E) : set E) = 0 := rfl\n\nlemma pointed_zero : (0 : convex_cone 𝕜 E).pointed := by rw [pointed, mem_zero]\n\ninstance : has_add (convex_cone 𝕜 E) := ⟨ λ K₁ K₂,\n{ carrier := {z | ∃ (x y : E), x ∈ K₁ ∧ y ∈ K₂ ∧ x + y = z},\n  smul_mem' :=\n  begin\n    rintro c hc _ ⟨x, y, hx, hy, rfl⟩,\n    rw smul_add,\n    use [c • x, c • y, K₁.smul_mem hc hx, K₂.smul_mem hc hy],\n  end,\n  add_mem' :=\n  begin\n    rintro _ ⟨x₁, x₂, hx₁, hx₂, rfl⟩ y ⟨y₁, y₂, hy₁, hy₂, rfl⟩,\n    use [x₁ + y₁, x₂ + y₂, K₁.add_mem hx₁ hy₁, K₂.add_mem hx₂ hy₂],\n    abel,\n  end } ⟩\n\n@[simp] lemma mem_add {K₁ K₂ : convex_cone 𝕜 E} {a : E} :\n  a ∈ K₁ + K₂ ↔ ∃ (x y : E), x ∈ K₁ ∧ y ∈ K₂ ∧ x + y = a := iff.rfl\n\ninstance : add_zero_class (convex_cone 𝕜 E) :=\n⟨0, has_add.add, λ _, by {ext, simp}, λ _, by {ext, simp}⟩\n\ninstance : add_comm_semigroup (convex_cone 𝕜 E) :=\n{ add := has_add.add,\n  add_assoc := λ _ _ _, set_like.coe_injective $ set.add_comm_semigroup.add_assoc _ _ _,\n  add_comm := λ _ _, set_like.coe_injective $ set.add_comm_semigroup.add_comm _ _ }\n\nend module\nend ordered_semiring\n\nend convex_cone\n\nnamespace submodule\n\n/-! ### Submodules are cones -/\n\nsection ordered_semiring\nvariables [ordered_semiring 𝕜]\n\nsection add_comm_monoid\nvariables [add_comm_monoid E] [module 𝕜 E]\n\n/-- Every submodule is trivially a convex cone. -/\ndef to_convex_cone (S : submodule 𝕜 E) : convex_cone 𝕜 E :=\n{ carrier := S,\n  smul_mem' := λ c hc x hx, S.smul_mem c hx,\n  add_mem' := λ x hx y hy, S.add_mem hx hy }\n\n@[simp] lemma coe_to_convex_cone (S : submodule 𝕜 E) : ↑S.to_convex_cone = (S : set E) := rfl\n\n@[simp] lemma mem_to_convex_cone {x : E} {S : submodule 𝕜 E} : x ∈ S.to_convex_cone ↔ x ∈ S :=\niff.rfl\n\n@[simp] lemma to_convex_cone_le_iff {S T : submodule 𝕜 E} :\n  S.to_convex_cone ≤ T.to_convex_cone ↔ S ≤ T :=\niff.rfl\n\n@[simp] lemma to_convex_cone_bot : (⊥ : submodule 𝕜 E).to_convex_cone = 0 := rfl\n@[simp] lemma to_convex_cone_top : (⊤ : submodule 𝕜 E).to_convex_cone = ⊤ := rfl\n\n@[simp] lemma to_convex_cone_inf (S T : submodule 𝕜 E) :\n  (S ⊓ T).to_convex_cone = S.to_convex_cone ⊓ T.to_convex_cone :=\nrfl\n\n@[simp] lemma pointed_to_convex_cone (S : submodule 𝕜 E) : S.to_convex_cone.pointed := S.zero_mem\n\nend add_comm_monoid\nend ordered_semiring\n\nend submodule\n\nnamespace convex_cone\n\n/-! ### Positive cone of an ordered module -/\n\nsection positive_cone\nvariables (𝕜 E) [ordered_semiring 𝕜] [ordered_add_comm_group E] [module 𝕜 E] [ordered_smul 𝕜 E]\n\n/--\nThe positive cone is the convex cone formed by the set of nonnegative elements in an ordered\nmodule.\n-/\ndef positive : convex_cone 𝕜 E :=\n{ carrier := set.Ici 0,\n  smul_mem' := λ c hc x (hx : _ ≤ _), smul_nonneg hc.le hx,\n  add_mem' := λ x (hx : _ ≤ _) y (hy : _ ≤ _), add_nonneg hx hy }\n\n@[simp] lemma mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := iff.rfl\n@[simp] lemma coe_positive : ↑(positive 𝕜 E) = set.Ici (0 : E) := rfl\n\n/-- The positive cone of an ordered module is always salient. -/\nlemma salient_positive : salient (positive 𝕜 E) :=\nλ x xs hx hx', lt_irrefl (0 : E)\n  (calc\n    0   < x         : lt_of_le_of_ne xs hx.symm\n    ... ≤ 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 : pointed (positive 𝕜 E) := le_refl 0\n\n/-- The cone of strictly positive elements.\n\nNote that this naming diverges from the mathlib convention of `pos` and `nonneg` due to \"positive\ncone\" (`convex_cone.positive`) being established terminology for the non-negative elements. -/\ndef strictly_positive : convex_cone 𝕜 E :=\n{ carrier := set.Ioi 0,\n  smul_mem' := λ c hc x (hx : _ < _), smul_pos hc hx,\n  add_mem' := λ x hx y hy, add_pos hx hy }\n\n@[simp] \n\nlemma positive_le_strictly_positive : strictly_positive 𝕜 E ≤ positive 𝕜 E := λ x, le_of_lt\n\n/-- The strictly positive cone of an ordered module is always salient. -/\nlemma salient_strictly_positive : salient (strictly_positive 𝕜 E) :=\n(salient_positive 𝕜 E).anti $ positive_le_strictly_positive 𝕜 E\n\n/-- The strictly positive cone of an ordered module is always blunt. -/\nlemma blunt_strictly_positive : blunt (strictly_positive 𝕜 E) := lt_irrefl 0\n\nend positive_cone\nend convex_cone\n\n/-! ### Cone over a convex set -/\n\nsection cone_from_convex\nvariables [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 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 𝕜 s) : convex_cone 𝕜 E :=\nbegin\n  apply convex_cone.mk (⋃ (c : 𝕜) (H : 0 < c), c • s);\n    simp only [mem_Union, mem_smul_set],\n  { rintros c c_pos _ ⟨c', c'_pos, x, hx, rfl⟩,\n    exact ⟨c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm⟩ },\n  { rintros _ ⟨cx, cx_pos, x, hx, rfl⟩ _ ⟨cy, cy_pos, y, hy, rfl⟩,\n    have : 0 < cx + cy, from add_pos cx_pos cy_pos,\n    refine ⟨_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, _⟩,\n    simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left _ this.ne'] }\nend\n\nvariables {s : set E} (hs : convex 𝕜 s) {x : E}\n\nlemma mem_to_cone : x ∈ hs.to_cone s ↔ ∃ (c : 𝕜), 0 < c ∧ ∃ y ∈ s, c • 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 ∈ hs.to_cone s ↔ ∃ (c : 𝕜), 0 < c ∧ c • x ∈ s :=\nbegin\n  refine hs.mem_to_cone.trans ⟨_, _⟩,\n  { rintros ⟨c, hc, y, hy, rfl⟩,\n    exact ⟨c⁻¹, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ },\n  { rintros ⟨c, hc, hcx⟩,\n    exact ⟨c⁻¹, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ }\nend\n\nlemma subset_to_cone : s ⊆ hs.to_cone s :=\nλ x hx, hs.mem_to_cone'.2 ⟨1, zero_lt_one, by rwa one_smul⟩\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 ⊆ t } (hs.to_cone s) :=\nbegin\n  refine ⟨hs.subset_to_cone, λ t ht x hx, _⟩,\n  rcases hs.mem_to_cone.1 hx with ⟨c, hc, y, hy, rfl⟩,\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 ⊆ 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 ⊆ t} ((convex_convex_hull 𝕜 s).to_cone _) :=\nbegin\n  convert (convex_convex_hull 𝕜 s).to_cone_is_least,\n  ext t,\n  exact ⟨λ h, convex_hull_min h t.convex, (subset_convex_hull 𝕜 s).trans⟩,\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 ⊆ t} :=\neq.symm $ is_glb.Inf_eq $ is_least.is_glb $ convex_hull_to_cone_is_least s\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 → ℝ`, assume\nthat `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear\nfunction `g : E → ℝ` 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 ⊔ span ℝ {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 `⊤ : submodule E`. Mathematically this is the same as a linear map on `E`\nbut in Lean `⊤ : 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 ℝ E]\n\nnamespace riesz_extension\nopen submodule\nvariables (s : convex_cone ℝ E) (f : E →ₗ.[ℝ] ℝ)\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 → ℝ`, assume that `f` is nonnegative on `f.domain ∩ 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 : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x)\n  (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) (hdom : f.domain ≠ ⊤) :\n  ∃ g, f < g ∧ ∀ x : g.domain, (x : E) ∈ s → 0 ≤ g x :=\nbegin\n  obtain ⟨y, -, hy⟩ : ∃ (y : E) (h : y ∈ ⊤), y ∉ f.domain,\n    { exact @set_like.exists_of_lt (submodule ℝ E) _ _ _ _ (lt_top_iff_ne_top.2 hdom) },\n  obtain ⟨c, le_c, c_le⟩ :\n    ∃ c, (∀ x : f.domain, -(x:E) - y ∈ s → f x ≤ c) ∧ (∀ x : f.domain, (x:E) + y ∈ s → c ≤ f x),\n  { set Sp := f '' {x : f.domain | (x:E) + y ∈ s},\n    set Sn := f '' {x : f.domain | -(x:E) - y ∈ s},\n    suffices : (upper_bounds Sn ∩ 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 ⟨x, hx⟩,\n      rw [← neg_neg x, add_subgroup_class.coe_neg, ← sub_eq_add_neg] at hx,\n      exact ⟨_, hx⟩ },\n    rintros a ⟨xn, hxn, rfl⟩ b ⟨xp, hxp, rfl⟩,\n    have := s.add_mem hxp hxn,\n    rw [add_assoc, add_sub_cancel'_right, ← sub_eq_add_neg, ← add_subgroup_class.coe_sub] at this,\n    replace := nonneg _ this,\n    rwa [f.map_sub, sub_nonneg] at this },\n  have hy' : y ≠ 0, from λ hy₀, hy (hy₀.symm ▸ zero_mem _),\n  refine ⟨f.sup_span_singleton y (-c) hy, _, _⟩,\n  { refine lt_iff_le_not_le.2 ⟨f.left_le_sup _ _, λ H, _⟩,\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 ⟨z, hz⟩ hzs,\n    rcases mem_sup.1 hz with ⟨x, hx, y', hy', rfl⟩,\n    rcases mem_span_singleton.1 hy' with ⟨r, rfl⟩,\n    simp only [subtype.coe_mk] at hzs,\n    erw [linear_pmap.sup_span_singleton_apply_mk _ _ _ _ _ hx, smul_neg,\n      ← sub_eq_add_neg, sub_nonneg],\n    rcases lt_trichotomy r 0 with hr|hr|hr,\n    { have : -(r⁻¹ • x) - y ∈ s,\n        by rwa [← 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⁻¹ • ⟨x, hx⟩) this,\n      rwa [← mul_le_mul_left (neg_pos.2 hr), neg_mul, neg_mul,\n        neg_le_neg_iff, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne,\n        one_mul] at this },\n    { subst r,\n      simp only [zero_smul, add_zero] at hzs ⊢,\n      apply nonneg,\n      exact hzs },\n    { have : r⁻¹ • x + y ∈ s,\n        by rwa [← s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel hr.ne', one_smul],\n      replace := c_le (r⁻¹ • ⟨x, hx⟩) this,\n      rwa [← mul_le_mul_left hr, f.map_smul, smul_eq_mul, ← mul_assoc,\n        mul_inv_cancel hr.ne', one_mul] at this } }\nend\n\ntheorem exists_top (p : E →ₗ.[ℝ] ℝ)\n  (hp_nonneg : ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x)\n  (hp_dense : ∀ y, ∃ x : p.domain, (x : E) + y ∈ s) :\n  ∃ q ≥ p, q.domain = ⊤ ∧ ∀ x : q.domain, (x : E) ∈ s → 0 ≤ q x :=\nbegin\n  replace hp_nonneg : p ∈ { p | _ }, by { rw mem_set_of_eq, exact hp_nonneg },\n  obtain ⟨q, hqs, hpq, hq⟩ := zorn_nonempty_partial_order₀ _ _ _ hp_nonneg,\n  { refine ⟨q, hpq, _, hqs⟩,\n    contrapose! hq,\n    rcases step s q hqs _ hq with ⟨r, hqr, hr⟩,\n    { exact ⟨r, hr, hqr.le, hqr.ne'⟩ },\n    { exact λ y, let ⟨x, hx⟩ := hp_dense y in ⟨of_le hpq.left x, hx⟩ } },\n  { intros c hcs c_chain y hy,\n    clear hp_nonneg hp_dense p,\n    have cne : c.nonempty := ⟨y, hy⟩,\n    refine ⟨linear_pmap.Sup c c_chain.directed_on, _, λ _, linear_pmap.le_Sup c_chain.directed_on⟩,\n    rintros ⟨x, hx⟩ hxs,\n    have hdir : directed_on (≤) (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 ⟨_, ⟨f, hfc, rfl⟩, hfx⟩,\n    have : f ≤ linear_pmap.Sup c c_chain.directed_on, from linear_pmap.le_Sup _ hfc,\n    convert ← hcs hfc ⟨x, hfx⟩ 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 → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then\nthere exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`,\nand is nonnegative on `s`. -/\ntheorem riesz_extension (s : convex_cone ℝ E) (f : E →ₗ.[ℝ] ℝ)\n  (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) :\n  ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ (∀ x ∈ s, 0 ≤ g x) :=\nbegin\n  rcases riesz_extension.exists_top s f nonneg dense with ⟨⟨g_dom, g⟩, ⟨hpg, hfg⟩, htop, hgs⟩,\n  clear hpg,\n  refine ⟨g ∘ₗ ↑(linear_equiv.of_top _ htop).symm, _, _⟩;\n    simp only [comp_apply, linear_equiv.coe_coe, linear_equiv.of_top_symm_apply],\n  { exact λ x, (hfg (submodule.coe_mk _ _).symm).symm },\n  { exact λ x hx, hgs ⟨x, _⟩ hx }\nend\n\n/-- **Hahn-Banach theorem**: if `N : E → ℝ` is a sublinear map, `f` is a linear map\ndefined on a subspace of `E`, and `f x ≤ 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 ≤ N x`\nfor all `x`. -/\ntheorem exists_extension_of_le_sublinear (f : E →ₗ.[ℝ] ℝ) (N : E → ℝ)\n  (N_hom : ∀ (c : ℝ), 0 < c → ∀ x, N (c • x) = c * N x)\n  (N_add : ∀ x y, N (x + y) ≤ N x + N y)\n  (hf : ∀ x : f.domain, f x ≤ N x) :\n  ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ (∀ x, g x ≤ N x) :=\nbegin\n  let s : convex_cone ℝ (E × ℝ) :=\n  { carrier := {p : E × ℝ | N p.1 ≤ p.2 },\n    smul_mem' := λ c hc p hp,\n      calc N (c • p.1) = c * N p.1 : N_hom c hc p.1\n      ... ≤ c * p.2 : mul_le_mul_of_nonneg_left hp hc.le,\n    add_mem' := λ x hx y hy, (N_add _ _).trans (add_le_add hx hy) },\n  obtain ⟨g, g_eq, g_nonneg⟩ :=\n    riesz_extension s ((-f).coprod (linear_map.id.to_pmap ⊤)) _ _;\n    try { simp only [linear_pmap.coprod_apply, to_pmap_apply, id_apply,\n            linear_pmap.neg_apply, ← sub_eq_neg_add, sub_nonneg, subtype.coe_mk] at * },\n  replace g_eq : ∀ (x : f.domain) (y : ℝ), g (x, y) = y - f x,\n  { intros x y,\n    simpa only [subtype.coe_mk, subtype.coe_eta] using g_eq ⟨(x, y), ⟨x.2, trivial⟩⟩ },\n  { refine ⟨-g.comp (inl ℝ E ℝ), _, _⟩; 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 ⟨x, N x⟩ (le_refl (N x)),\n      rw [A, map_add, ← 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 ← C } },\n  { exact λ x hx, le_trans (hf _) hx },\n  { rintros ⟨x, y⟩,\n    refine ⟨⟨(0, N x - y), ⟨f.domain.zero_mem, trivial⟩⟩, _⟩,\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*} [normed_add_comm_group H] [inner_product_space ℝ 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 ≤ ⟪ x, y ⟫`. -/\ndef set.inner_dual_cone (s : set H) : convex_cone ℝ H :=\n{ carrier := { y | ∀ x ∈ s, 0 ≤ ⟪ x, y ⟫ },\n  smul_mem' := λ 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' := λ 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\n@[simp] lemma mem_inner_dual_cone (y : H) (s : set H) :\n  y ∈ s.inner_dual_cone ↔ ∀ x ∈ s, 0 ≤ ⟪ x, y ⟫ := iff.rfl\n\n@[simp] lemma inner_dual_cone_empty : (∅ : set H).inner_dual_cone = ⊤ :=\neq_top_iff.mpr $ λ x hy y, false.elim\n\n/-- Dual cone of the convex cone {0} is the total space. -/\n@[simp] lemma inner_dual_cone_zero : (0 : set H).inner_dual_cone = ⊤ :=\neq_top_iff.mpr $ λ x hy y (hy : y = 0), hy.symm ▸ (inner_zero_left _).ge\n\n/-- Dual cone of the total space is the convex cone {0}. -/\n@[simp] lemma inner_dual_cone_univ : (univ : set H).inner_dual_cone = 0 :=\nbegin\n  suffices : ∀ x : H, x ∈ (univ : set H).inner_dual_cone → x = 0,\n  { apply set_like.coe_injective,\n    exact eq_singleton_iff_unique_mem.mpr ⟨λ x hx, (inner_zero_right _).ge, this⟩ },\n  exact λ x hx, by simpa [←real_inner_self_nonpos] using hx (-x) (mem_univ _),\nend\n\nlemma inner_dual_cone_le_inner_dual_cone (h : t ⊆ s) :\n  s.inner_dual_cone ≤ t.inner_dual_cone :=\nλ y hy x hx, hy x (h hx)\n\nlemma pointed_inner_dual_cone : s.inner_dual_cone.pointed :=\nλ x hx, by rw inner_zero_right\n\n/-- The inner dual cone of a singleton is given by the preimage of the positive cone under the\nlinear map `λ y, ⟪x, y⟫`. -/\nlemma inner_dual_cone_singleton (x : H) :\n  ({x} : set H).inner_dual_cone = (convex_cone.positive ℝ ℝ).comap (innerₛₗ ℝ x) :=\nconvex_cone.ext $ λ i, forall_eq\n\nlemma inner_dual_cone_union (s t : set H) :\n  (s ∪ t).inner_dual_cone = s.inner_dual_cone ⊓ t.inner_dual_cone :=\nle_antisymm\n  (le_inf (λ x hx y hy, hx _ $ or.inl hy) (λ x hx y hy, hx _ $ or.inr hy))\n  (λ x hx y, or.rec (hx.1 _) (hx.2 _))\n\nlemma inner_dual_cone_insert (x : H) (s : set H) :\n  (insert x s).inner_dual_cone = set.inner_dual_cone {x} ⊓ s.inner_dual_cone :=\nby rw [insert_eq, inner_dual_cone_union]\n\nlemma inner_dual_cone_Union {ι : Sort*} (f : ι → set H) :\n  (⋃ i, f i).inner_dual_cone = ⨅ i, (f i).inner_dual_cone :=\nbegin\n  refine le_antisymm (le_infi $ λ i x hx y hy, hx _ $ mem_Union_of_mem _ hy) _,\n  intros x hx y hy,\n  rw [convex_cone.mem_infi] at hx,\n  obtain ⟨j, hj⟩ := mem_Union.mp hy,\n  exact hx _ _ hj,\nend\n\nlemma inner_dual_cone_sUnion (S : set (set H)) :\n  (⋃₀ S).inner_dual_cone = Inf (set.inner_dual_cone '' S) :=\nby simp_rw [Inf_image, sUnion_eq_bUnion, inner_dual_cone_Union]\n\n/-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/\nlemma inner_dual_cone_eq_Inter_inner_dual_cone_singleton :\n  (s.inner_dual_cone : set H) = ⋂ i : s, (({i} : set H).inner_dual_cone : set H) :=\nby rw [←convex_cone.coe_infi, ←inner_dual_cone_Union, Union_of_singleton_coe]\n\nlemma is_closed_inner_dual_cone : is_closed (s.inner_dual_cone : set H) :=\nbegin\n  -- reduce the problem to showing that dual cone of a singleton `{x}` is closed\n  rw inner_dual_cone_eq_Inter_inner_dual_cone_singleton,\n  apply is_closed_Inter,\n  intros x,\n\n  -- the dual cone of a singleton `{x}` is the preimage of `[0, ∞)` under `inner x`\n  have h : ↑({x} : set H).inner_dual_cone = (inner x : H → ℝ) ⁻¹' set.Ici 0,\n  { rw [inner_dual_cone_singleton, convex_cone.coe_comap, convex_cone.coe_positive,\n      innerₛₗ_apply_coe] },\n\n  -- the preimage is closed as `inner x` is continuous and `[0, ∞)` is closed\n  rw h,\n  exact is_closed_Ici.preimage (by continuity),\nend\n\nlemma convex_cone.pointed_of_nonempty_of_is_closed (K : convex_cone ℝ H)\n  (ne : (K : set H).nonempty) (hc : is_closed (K : set H)) : K.pointed :=\nbegin\n  obtain ⟨x, hx⟩ := ne,\n  let f : ℝ → H := (• x),\n\n  -- f (0, ∞) is a subset of K\n  have fI : f '' set.Ioi 0 ⊆ (K : set H),\n  { rintro _ ⟨_, h, rfl⟩,\n    exact K.smul_mem (set.mem_Ioi.1 h) hx },\n\n  -- closure of f (0, ∞) is a subset of K\n  have clf : closure (f '' set.Ioi 0) ⊆ (K : set H) := hc.closure_subset_iff.2 fI,\n\n  -- f is continuous at 0 from the right\n  have fc : continuous_within_at f (set.Ioi (0 : ℝ)) 0 :=\n    (continuous_id.smul continuous_const).continuous_within_at,\n\n  -- 0 belongs to the closure of the f (0, ∞)\n  have mem₀ := fc.mem_closure_image (by rw [closure_Ioi (0 : ℝ), mem_Ici]),\n\n  -- as 0 ∈ closure f (0, ∞) and closure f (0, ∞) ⊆ K, 0 ∈ K.\n  have f₀ : f 0 = 0 := zero_smul ℝ x,\n  simpa only [f₀, convex_cone.pointed, ← set_like.mem_coe] using mem_of_subset_of_mem clf mem₀,\nend\n\nsection complete_space\nvariables [complete_space H]\n\n/-- This is a stronger version of the Hahn-Banach separation theorem for closed convex cones. This\nis also the geometric interpretation of Farkas' lemma. -/\ntheorem convex_cone.hyperplane_separation_of_nonempty_of_is_closed_of_nmem (K : convex_cone ℝ H)\n  (ne : (K : set H).nonempty) (hc : is_closed (K : set H)) {b : H} (disj : b ∉ K) :\n  ∃ (y : H), (∀ x : H, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ) ∧ ⟪y, b⟫_ℝ < 0 :=\nbegin\n  -- let `z` be the point in `K` closest to `b`\n  obtain ⟨z, hzK, infi⟩ := exists_norm_eq_infi_of_complete_convex ne hc.is_complete K.convex b,\n\n  -- for any `w` in `K`, we have `⟪b - z, w - z⟫_ℝ ≤ 0`\n  have hinner := (norm_eq_infi_iff_real_inner_le_zero K.convex hzK).1 infi,\n\n  -- set `y := z - b`\n  use z - b,\n\n  split,\n  { -- the rest of the proof is a straightforward calculation\n    rintros x hxK,\n    specialize hinner _ (K.add_mem hxK hzK),\n    rwa [add_sub_cancel, real_inner_comm, ← neg_nonneg, neg_eq_neg_one_mul,\n         ← real_inner_smul_right, neg_smul, one_smul, neg_sub] at hinner },\n  { -- as `K` is closed and non-empty, it is pointed\n    have hinner₀ := hinner 0 (K.pointed_of_nonempty_of_is_closed ne hc),\n\n    -- the rest of the proof is a straightforward calculation\n    rw [zero_sub, inner_neg_right, right.neg_nonpos_iff] at hinner₀,\n    have hbz : b - z ≠ 0 := by { rw sub_ne_zero, contrapose! hzK, rwa ← hzK },\n    rw [← neg_zero, lt_neg, ← neg_one_mul, ← real_inner_smul_left, smul_sub, neg_smul, one_smul,\n      neg_smul, neg_sub_neg, one_smul],\n    calc 0 < ⟪b - z, b - z⟫_ℝ : lt_of_not_le ((iff.not real_inner_self_nonpos).2 hbz)\n    ... = ⟪b - z, b - z⟫_ℝ + 0 : (add_zero _).symm\n    ... ≤ ⟪b - z, b - z⟫_ℝ + ⟪b - z, z⟫_ℝ : add_le_add rfl.ge hinner₀\n    ... = ⟪b - z, b - z + z⟫_ℝ : (inner_add_right _ _ _).symm\n    ... = ⟪b - z, b⟫_ℝ : by rw sub_add_cancel },\nend\n\n/-- The inner dual of inner dual of a non-empty, closed convex cone is itself.  -/\ntheorem convex_cone.inner_dual_cone_of_inner_dual_cone_eq_self (K : convex_cone ℝ H)\n  (ne : (K : set H).nonempty) (hc : is_closed (K : set H)) :\n  ((K : set H).inner_dual_cone : set H).inner_dual_cone = K :=\nbegin\n  ext x,\n  split,\n  { rw [mem_inner_dual_cone, ← set_like.mem_coe],\n    contrapose!,\n    exact K.hyperplane_separation_of_nonempty_of_is_closed_of_nmem ne hc },\n  { rintro hxK y h,\n    specialize h x hxK,\n    rwa real_inner_comm },\nend\n\nend complete_space\nend 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/convex/cone/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682085, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7602793254602705}}
{"text": "/-\nCopyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Antoine Chambert-Loir, María Inés de Frutos-Fernández\n-- Copy of PR #17855\n-/\n\nimport algebra.graded_monoid\nimport data.mv_polynomial.variables\nimport algebra.direct_sum.decomposition\nimport .graded_algebra\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 : σ → M`,\nwhere `σ` are the indeterminates.\n\nA multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials\noccuring in `φ` have the same weighted degree `m`.\n\n## Main definitions/lemmas\n\n* `weighted_total_degree' w φ` : 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 φ` : When `M` has a `⊥` 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 φ m`: a predicate that asserts that `φ` 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\nnoncomputable theory\n\nopen_locale big_operators\n\nopen set function finset finsupp add_monoid_algebra\n\nvariables {R M : Type*} [comm_semiring R]\n\nnamespace mv_polynomial\nvariables {σ : Type*}\n\nsection add_comm_monoid\nvariables [add_comm_monoid M]\n\n/-! ### `weighted_degree'` -/\n\n/-- The `weighted degree'` of the finitely supported function `s : σ →₀ ℕ` is the sum\n  `∑(s i)•(w i)`. -/\n\n/- def weighted_degree' (w : σ → M) : (σ →₀ ℕ) →+ M :=\n(finsupp.total σ M ℕ w).to_add_monoid_hom\n-/\n\ndef weighted_degree' (w : σ → M) : (σ →₀ ℕ) →ₗ[ℕ] M := (finsupp.total σ M ℕ w)\n\nsection semilattice_sup\nvariable [semilattice_sup M]\n\n/-- The weighted total degree of a multivariate polynomial, taking values in `with_bot M`. -/\ndef weighted_total_degree' (w : σ → M) (p : mv_polynomial σ R) : with_bot M :=\np.support.sup (λ s, weighted_degree' w s)\n\n/-- The `weighted_total_degree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/\nlemma weighted_total_degree'_eq_bot_iff (w : σ → M) (p : mv_polynomial σ R) :\n  weighted_total_degree' w p = ⊥ ↔ p = 0 :=\nbegin\n  simp only [weighted_total_degree',finset.sup_eq_bot_iff, mem_support_iff, with_bot.coe_ne_bot,\n    mv_polynomial.eq_zero_iff ],\n  exact forall_congr (λ _, not_not)\nend\n\n/-- The `weighted_total_degree'` of the zero polynomial is `⊥`. -/\nlemma weighted_total_degree'_zero (w : σ → M) :\n  weighted_total_degree' w (0 : mv_polynomial σ R) = ⊥ :=\nby simp only [weighted_total_degree', support_zero, finset.sup_empty]\n\nsection order_bot\nvariable [order_bot M]\n\n/-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate\n  polynomial as a function taking values in `M`. -/\ndef weighted_total_degree (w : σ → M) (p : mv_polynomial σ R) : M :=\np.support.sup (λ s, weighted_degree' w s)\n\n/-- This lemma relates `weighted_total_degree` and `weighted_total_degree'`. -/\nlemma weighted_total_degree_coe (w : σ → M) (p : mv_polynomial σ R) (hp : p ≠ 0):\n  weighted_total_degree' w p = ↑(weighted_total_degree w p) :=\nbegin\n  rw [ne.def, ← weighted_total_degree'_eq_bot_iff w p, ← ne.def, with_bot.ne_bot_iff_exists] at hp,\n  obtain ⟨m, hm⟩ := hp,\n  apply le_antisymm,\n  { simp only [weighted_total_degree, weighted_total_degree', finset.sup_le_iff,\n      with_bot.coe_le_coe],\n    intro b,\n    exact finset.le_sup },\n  { simp only [weighted_total_degree],\n    have hm' : weighted_total_degree' w p ≤ m := le_of_eq hm.symm,\n    rw ← hm,\n    simpa [weighted_total_degree'] using hm' }\nend\n\n/-- The `weighted_total_degree` of the zero polynomial is `⊥`. -/\nlemma weighted_total_degree_zero (w : σ → M) :\n  weighted_total_degree w (0 : mv_polynomial σ R) = ⊥ :=\nby simp only [weighted_total_degree, support_zero, finset.sup_empty]\n\nlemma le_weighted_total_degree (w : σ → M) {φ : mv_polynomial σ R} {d : σ →₀ ℕ}\n  (hd : d ∈ φ.support) : weighted_degree' w d ≤ φ.weighted_total_degree w :=\nle_sup hd\n\nend order_bot\nend semilattice_sup\n\n/-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials\n  occuring in `φ` have weighted degree `m`. -/\ndef is_weighted_homogeneous (w : σ → M) (φ : mv_polynomial σ R) (m : M) : Prop :=\n∀ ⦃d⦄, coeff d φ ≠ 0 → weighted_degree' w d = m\n\nvariable (R)\n\n/-- The submodule of homogeneous `mv_polynomial`s of degree `n`. -/\ndef weighted_homogeneous_submodule (w : σ → M) (m : M) :\n  submodule R (mv_polynomial σ R) :=\n{ carrier := { x | x.is_weighted_homogeneous w m },\n  smul_mem' := λ r a ha c hc, begin\n    rw coeff_smul at hc,\n    exact ha (right_ne_zero_of_mul hc),\n  end,\n  zero_mem' := λ d hd, false.elim (hd $ coeff_zero _),\n  add_mem' := λ a b ha hb c hc, begin\n    rw coeff_add at hc,\n    obtain h|h : coeff c a ≠ 0 ∨ coeff c b ≠ 0,\n    { contrapose! hc, simp only [hc, add_zero] },\n    { exact ha h },\n    { exact hb h },\n  end }\n\n@[simp] lemma mem_weighted_homogeneous_submodule (w : σ → M) (m : M) (p : mv_polynomial σ R) :\n  p ∈ weighted_homogeneous_submodule R w m ↔ p.is_weighted_homogeneous w m := iff.rfl\n\nvariables (R)\n\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 : (σ →₀ ℕ) →₀ R` such that\n  `p.support ⊆ {d | weighted_degree' w d = m}`. While equal, the former has a\n  convenient definitional reduction. -/\nlemma weighted_homogeneous_submodule_eq_finsupp_supported (w : σ → M) (m : M) :\n  weighted_homogeneous_submodule R w m =\n  finsupp.supported _ R {d | weighted_degree' w d = m} :=\nbegin\n  ext,\n  simp only [mem_supported, set.subset_def, finsupp.mem_support_iff, mem_coe],\n  refl,\nend\n\nvariables {R}\n\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`. -/\nlemma weighted_homogeneous_submodule_mul (w : σ → M) (m n : M) :\n  weighted_homogeneous_submodule R w m * weighted_homogeneous_submodule R w n ≤\n    weighted_homogeneous_submodule R w (m + n) :=\nbegin\n  rw submodule.mul_le,\n  intros φ hφ ψ hψ c hc,\n  rw [coeff_mul] at hc,\n  obtain ⟨⟨d, e⟩, hde, H⟩ := finset.exists_ne_zero_of_sum_ne_zero hc,\n  have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0,\n  { contrapose! H,\n    by_cases h : coeff d φ = 0;\n    simp only [*, ne.def, not_false_iff, zero_mul, mul_zero] at * },\n  rw [← (finsupp.mem_antidiagonal.mp hde), ← hφ aux.1, ← hψ aux.2, map_add],\nend\n\n/-- Monomials are weighted homogeneous. -/\nlemma is_weighted_homogeneous_monomial [decidable_eq σ] (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M}\n  (hm : weighted_degree' w d = m) : is_weighted_homogeneous w (monomial d r) m :=\nbegin\n  intros c hc,\n  rw coeff_monomial at hc,\n  split_ifs at hc with h,\n  { subst c, exact hm },\n  { contradiction }\nend\n\n/-- A polynomial of weighted_total_degree `⊥` is weighted_homogeneous of degree `⊥`. -/\nlemma is_weighted_homogeneous_of_total_degree_zero [semilattice_sup M] [order_bot M]\n  (w : σ → M) {p : mv_polynomial σ R} (hp : weighted_total_degree w p = (⊥ : M)) :\n  is_weighted_homogeneous w p (⊥ : M) :=\nbegin\n  intros d hd,\n  have h := weighted_total_degree_coe w p (mv_polynomial.ne_zero_iff.mpr ⟨d, hd⟩),\n  simp only [weighted_total_degree', hp] at h,\n  rw [eq_bot_iff, ← with_bot.coe_le_coe, ← h],\n  exact finset.le_sup (mem_support_iff.mpr hd),\nend\n\n/-- Constant polynomials are weighted homogeneous of degree 0. -/\nlemma is_weighted_homogeneous_C [decidable_eq σ] (w : σ → M) (r : R) :\n  is_weighted_homogeneous w (C r : mv_polynomial σ R) 0 :=\nis_weighted_homogeneous_monomial _ _ _ (map_zero _)\n\nvariables (R)\n\n/-- 0 is weighted homogeneous of any degree. -/\nlemma is_weighted_homogeneous_zero [decidable_eq σ] (w : σ → M) (m : M) :\n  is_weighted_homogeneous w (0 : mv_polynomial σ R) m :=\n(weighted_homogeneous_submodule R w m).zero_mem\n\n/-- 1 is weighted homogeneous of degree 0. -/\nlemma is_weighted_homogeneous_one [decidable_eq σ] (w : σ → M) :\n  is_weighted_homogeneous w (1 : mv_polynomial σ R) 0 :=\nis_weighted_homogeneous_C _ _\n\n/-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/\nlemma is_weighted_homogeneous_X [decidable_eq σ] (w : σ → M) (i : σ) :\n  is_weighted_homogeneous w (X i : mv_polynomial σ R) (w i) :=\nbegin\n  apply is_weighted_homogeneous_monomial,\n  simp only [weighted_degree', add_monoid_hom.coe_coe, total_single, one_nsmul],\nend\n\nnamespace is_weighted_homogeneous\nvariables {R} {φ ψ : mv_polynomial σ R} {m n : M}\n\n/-- The weighted degree of a weighted homogeneous polynomial controls its support. -/\nlemma coeff_eq_zero {w : σ → M} (hφ : is_weighted_homogeneous w φ n) (d : σ →₀ ℕ)\n  (hd : weighted_degree' w d ≠ n) : coeff d φ = 0 :=\nby { have aux := mt (@hφ d) hd, rwa not_not at aux }\n\n/-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/\nlemma inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : is_weighted_homogeneous w φ m)\n  (hn : is_weighted_homogeneous w φ n) : m = n :=\nbegin\n  obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ,\n  rw [← hm hd, ← hn hd]\nend\n\n/-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\nlemma add {w : σ → M} (hφ : is_weighted_homogeneous w φ n) (hψ : is_weighted_homogeneous w ψ n) :\n  is_weighted_homogeneous w (φ + ψ) n :=\n(weighted_homogeneous_submodule R w n).add_mem hφ hψ\n\n/-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of\n  weighted degree `n`. -/\nlemma sum  {ι : Type*} (s : finset ι)  (φ : ι → mv_polynomial σ R) (n : M) {w : σ → M}\n  (h : ∀ i ∈ s, is_weighted_homogeneous w (φ i) n) :\n  is_weighted_homogeneous w (∑ i in s, φ i) n :=\n(weighted_homogeneous_submodule R w n).sum_mem h\n\n/-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted\n  homogeneous of weighted degree `m + n`. -/\nlemma mul {w : σ → M} (hφ : is_weighted_homogeneous w φ m) (hψ : is_weighted_homogeneous w ψ n) :\n  is_weighted_homogeneous w (φ * ψ) (m + n) :=\nweighted_homogeneous_submodule_mul w m n $ submodule.mul_mem_mul hφ hψ\n\n/-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree\n  equal to the sum of the weighted degrees. -/\nlemma prod [decidable_eq σ] {ι : Type*} [decidable_eq ι] (s : finset ι) (φ : ι → mv_polynomial σ R) (n : ι → M) {w : σ → M} :\n  (∀ i ∈ s, is_weighted_homogeneous w (φ i) (n i)) →\n  is_weighted_homogeneous w (∏ i in s, φ i) (∑ i in s, n i) :=\nbegin\n  apply finset.induction_on s,\n  { intro, \n    rw [finset.sum_empty, finset.prod_empty],\n    exact is_weighted_homogeneous_one R w, },\n  { intros 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    intros j hjs,\n    exact h j (finset.mem_insert_of_mem hjs) }\nend\n\n/-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree\n  `n`. -/\nlemma weighted_total_degree [semilattice_sup M] {w : σ → M} (hφ : is_weighted_homogeneous w φ n)\n  (h : φ ≠ 0) : weighted_total_degree' w φ = n :=\nbegin\n  simp only [weighted_total_degree'],\n  apply le_antisymm,\n  { simp only [finset.sup_le_iff, mem_support_iff, with_bot.coe_le_coe],\n    exact λ d hd, le_of_eq (hφ hd), },\n  { obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h,\n    simp only [← hφ hd, finsupp.sum],\n    replace hd := finsupp.mem_support_iff.mpr hd,\n    exact finset.le_sup hd, }\nend\n\n/-- The weighted homogeneous submodules form a graded monoid. -/\ninstance weighted_homogeneous_submodule.gcomm_monoid [decidable_eq σ] {w : σ → M} :\n  set_like.graded_monoid (weighted_homogeneous_submodule R w) :=\n{ one_mem := is_weighted_homogeneous_one R w,\n  mul_mem := λ i j xi xj, is_weighted_homogeneous.mul }\n\nend is_weighted_homogeneous\n\n/-- `weighted_homogeneous_component w n φ` is the part of `φ` 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 `φ` is equal to the sum\n  of all its weighted homogeneous components. -/\ndef weighted_homogeneous_component (w : σ → M) (n : M) :\n  mv_polynomial σ R →ₗ[R] mv_polynomial σ R :=\n(submodule.subtype _).comp $ finsupp.restrict_dom _ _ {d | weighted_degree' w d = n}\n\nsection weighted_homogeneous_component\n\nvariables {w : σ → M} (n : M) (φ ψ : mv_polynomial σ R)\n\nvariables {R}\n\nlemma coeff_weighted_homogeneous_component [decidable_eq M] (d : σ →₀ ℕ) :\n  coeff d (weighted_homogeneous_component R w n φ) =\n    if weighted_degree' w d = n then coeff d φ else 0 :=\nfinsupp.filter_apply (λ d : σ →₀ ℕ, weighted_degree' w d = n) φ d\n\nlemma weighted_homogeneous_component_apply [decidable_eq M] :\n  weighted_homogeneous_component R w n φ =\n  ∑ d in φ.support.filter (λ d, weighted_degree' w d = n), monomial d (coeff d φ) :=\nfinsupp.filter_eq_sum (λ d : σ →₀ ℕ, weighted_degree' w d = n) φ\n\n/-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of\nweighted degree `n`. -/\nlemma weighted_homogeneous_component_is_weighted_homogeneous [decidable_eq M] :\n  (weighted_homogeneous_component R w n φ).is_weighted_homogeneous w n :=\nbegin\n  intros d hd,\n  contrapose! hd,\n  rw [coeff_weighted_homogeneous_component, if_neg hd]\nend\n\nlemma weighted_homogeneous_component_mem [decidable_eq M]\n  (w : σ → M) (φ : mv_polynomial σ R) (m : M) :\n  weighted_homogeneous_component R w m φ ∈ weighted_homogeneous_submodule R w m :=\nbegin\n  rw mem_weighted_homogeneous_submodule, \n  exact weighted_homogeneous_component_is_weighted_homogeneous m φ, \nend\n\n@[simp] lemma weighted_homogeneous_component_C_mul (n : M) (r : R) :\n  weighted_homogeneous_component R w n (C r * φ) \n  = C r * weighted_homogeneous_component R w n φ :=\nby simp only [C_mul', linear_map.map_smul]\n\nlemma weighted_homogeneous_component_eq_zero' [decidable_eq M] \n  (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → weighted_degree' w d ≠ n) : weighted_homogeneous_component R w n φ = 0 :=\nbegin\n  rw [weighted_homogeneous_component_apply, sum_eq_zero],\n  intros d hd, rw mem_filter at hd,\n  exfalso, exact h _ hd.1 hd.2\nend\n\nlemma weighted_homogeneous_component_eq_zero \n  [semilattice_sup M] [order_bot M] [decidable_eq M]\n  (h : weighted_total_degree w φ < n) : \n  weighted_homogeneous_component R w n φ = 0 :=\nbegin\n  rw [weighted_homogeneous_component_apply, sum_eq_zero],\n  intros d hd, rw mem_filter at hd,\n  exfalso,\n  apply lt_irrefl n,\n  nth_rewrite 0 ← hd.2,\n  exact lt_of_le_of_lt (le_weighted_total_degree w hd.1) h,\nend\n\nvariable (w)\nlemma weighted_homogeneous_component_finsupp [decidable_eq M] :\n  (function.support (λ m, weighted_homogeneous_component R w m φ)).finite :=\nbegin\n  suffices : function.support (λ m, weighted_homogeneous_component R w m φ) ⊆\n    (λ d, weighted_degree' w d) '' φ.support,\n  { exact finite.subset ((λ (d : σ →₀ ℕ), (weighted_degree' w) d) '' ↑(support φ)).to_finite this },\n  intros m hm,\n  by_contradiction hm', 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 φ hm',\nend\n\nvariable (w)\n\n/-- Every polynomial is the sum of its weighted homogeneous components. -/\nlemma sum_weighted_homogeneous_component [decidable_eq M] :\n  (weighted_homogeneous_component_finsupp w φ).to_finset.sum (λ m, weighted_homogeneous_component R w m φ) = φ :=\nbegin\n   ext1 d,\n  simp only [coeff_sum, coeff_weighted_homogeneous_component],\n  rw finset.sum_eq_single (weighted_degree' w d),\n  { rw if_pos rfl, },\n  { intros m hm hm', rw if_neg hm'.symm, },\n  { intro hm, rw if_pos rfl,\n    simp only [finite.mem_to_finset, mem_support, ne.def, not_not] at hm,\n    have := coeff_weighted_homogeneous_component (_ :M) φ d,\n    rw [hm, if_pos rfl, coeff_zero] at this,\n    exact this.symm, },\nend\n\nlemma finsum_weighted_homogeneous_component [decidable_eq M] :\n finsum (λ m, weighted_homogeneous_component R w m φ) = φ :=\nby rw [finsum_eq_sum _ (weighted_homogeneous_component_finsupp w φ), sum_weighted_homogeneous_component]\n \nvariable {w}\n\nlemma weighted_homogeneous_component_of_weighted_homogeneous_polynomial_same \n  [decidable_eq M] (m : M) (p : mv_polynomial σ R) (hp : is_weighted_homogeneous w p m) :\n  weighted_homogeneous_component R w m p = p :=\nbegin\n  ext x, \n  rw coeff_weighted_homogeneous_component,\n  by_cases zero_coeff : coeff x p = 0,\n  { split_ifs,\n    refl, rw zero_coeff, },\n  { rw [hp zero_coeff, if_pos], refl, }\nend\n\nlemma weighted_homogeneous_component_of_weighted_homogeneous_polynomial_other \n  [decidable_eq M] \n  (m n : M) (p : mv_polynomial σ R) (hp : is_weighted_homogeneous w p m) :\n  n ≠ m → weighted_homogeneous_component R w n p = 0 :=\nbegin\n  intro hn,\n  ext x, \n  rw coeff_weighted_homogeneous_component,\n  by_cases zero_coeff : coeff x p = 0,\n  { split_ifs,\n    rw zero_coeff, rw coeff_zero, rw coeff_zero, },\n  { rw if_neg, rw coeff_zero, rw hp zero_coeff, exact ne.symm hn, }\nend\n\n/-- The weighted homogeneous components of a weighted homogeneous polynomial. -/\nlemma weighted_homogeneous_component_weighted_homogeneous_polynomial [decidable_eq M]\n  (m n : M) (p : mv_polynomial σ R) (hp : p ∈ weighted_homogeneous_submodule R w n) :\n  weighted_homogeneous_component R w m p = if m = n then p else 0 :=\nbegin\n  rw mem_weighted_homogeneous_submodule at hp,\n  split_ifs,\n  rw [h],\n  exact weighted_homogeneous_component_of_weighted_homogeneous_polynomial_same n p hp,\n  exact weighted_homogeneous_component_of_weighted_homogeneous_polynomial_other n m p hp h,\nend\n\nvariables (R w)\n-- Rewrite direct_sum.coe_linear_map\nlemma direct_sum.coe_linear_map_eq_support_sum \n  [decidable_eq σ] [decidable_eq R] [decidable_eq M]\n  (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) :\n  ((direct_sum.coe_linear_map (λ (i : M), weighted_homogeneous_submodule R w i)) x) = \n  dfinsupp.sum x  (λ m, coe) := \nby rw direct_sum.coe_linear_map_eq_dfinsupp_sum\n\n-- Rewrite direct_sum.coe_add_monoid_hom\nlemma direct_sum.coe_add_monoid_hom_eq_support_sum \n  [decidable_eq σ] [decidable_eq R] [decidable_eq M]\n  (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) :\n  ((direct_sum.coe_add_monoid_hom (λ (i : M), weighted_homogeneous_submodule R w i)) x) = \n  dfinsupp.sum x  (λ m, coe) :=\n  direct_sum.coe_linear_map_eq_support_sum R w x\n\n-- Variants for finsum\nlemma direct_sum.coe_linear_map_eq_finsum \n  [decidable_eq σ] [decidable_eq R] [decidable_eq M]\n  (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) : \n  ((direct_sum.coe_linear_map (λ (i : M), weighted_homogeneous_submodule R w i)) x) = \n  finsum (λ m, x m) :=\nbegin\n  rw [direct_sum.coe_linear_map_eq_support_sum, dfinsupp.sum],\n  rw finsum_eq_sum_of_support_subset, \n  apply direct_sum.support_subset_submodule, \nend\n\nlemma direct_sum.coe_add_monoid_hom_eq_finsum \n  [decidable_eq σ] [decidable_eq R] [decidable_eq M]\n  (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i))) :\n  ((direct_sum.coe_add_monoid_hom \n    (λ (i : M), weighted_homogeneous_submodule R w i)) x)\n  = finsum (λ m, x m) := direct_sum.coe_linear_map_eq_finsum R w x\n\nlemma weighted_homogeneous_component_weighted_homogeneous_polynomial' \n  [decidable_eq M] \n  (m : M) (x : weighted_homogeneous_submodule R w m) :\n  (weighted_homogeneous_component  R w m) ↑x = x :=\nby rw [weighted_homogeneous_component_weighted_homogeneous_polynomial m m _ x.prop, if_pos rfl]\n \nlemma weighted_homogeneous_component_direct_sum \n  [decidable_eq σ] [decidable_eq R] [decidable_eq M]\n  (x : direct_sum M (λ (i : M), ↥(weighted_homogeneous_submodule R w i)))\n  (m : M) : \n  (weighted_homogeneous_component R w m) \n    ((direct_sum.coe_linear_map (λ (i : M), weighted_homogeneous_submodule R w i)) x) = x m :=\nbegin\n  rw [direct_sum.coe_linear_map_eq_dfinsupp_sum],\n  rw dfinsupp.sum, \n  rw map_sum, \n  rw finset.sum_eq_single m, \n  { rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_same,\n    rw ← mem_weighted_homogeneous_submodule, \n    exact (x m).prop, },\n  { intros n hn hmn, \n    rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_other,\n    rw ← mem_weighted_homogeneous_submodule, \n    exact (x n).prop, exact ne.symm hmn, },\n  { rw dfinsupp.not_mem_support_iff, \n    intro hm, rw [hm, submodule.coe_zero, map_zero], },\nend\n\n\nend weighted_homogeneous_component\n\nend add_comm_monoid\n\nsection canonically_ordered_add_monoid\n\nvariables [canonically_ordered_add_monoid M] {w : σ → M} (φ : mv_polynomial σ R)\n\ndef non_trivial_weight (w : σ → M) := ∀ n x, n • (w x) = 0 → n = 0\n\nlemma non_trivial_weight_of [no_zero_smul_divisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) :\n  non_trivial_weight w :=\nbegin\n  intros n x, rw smul_eq_zero, \n  intro hnx, \n  cases hnx with hn hx, \n  exact hn,\n  exfalso, exact hw x hx,\nend\n\n/-- If `M` is a `canonically_ordered_add_monoid`, \n  then the `weighted_homogeneous_component` of weighted degree `0` \n  of a polynomial is its constant coefficient. -/\n@[simp] lemma weighted_homogeneous_component_zero \n  [decidable_eq σ] [decidable_eq M] (hw : non_trivial_weight w) : \n  weighted_homogeneous_component R w 0 φ = C (coeff 0 φ) :=\nbegin\n  ext1 d,\n  rcases em (d = 0) with (rfl|hd),\n  { simp only [coeff_weighted_homogeneous_component, if_pos, map_zero, coeff_zero_C] },\n  { rw [coeff_weighted_homogeneous_component, if_neg, coeff_C, if_neg (ne.symm hd)],\n    rw [weighted_degree', finsupp.total_apply, finsupp.sum, sum_eq_zero_iff],\n    intro h,\n    apply hd, \n    ext x, simp only [finsupp.coe_zero, pi.zero_apply], \n    specialize h x, \n    by_contradiction hx, \n    rw finsupp.mem_support_iff at h,\n    exact hx (hw (d x) x (h hx)), }\nend\n\nend canonically_ordered_add_monoid\n\nsection canonically_linear_ordered_monoid\n\nvariables [canonically_linear_ordered_add_monoid M] \n  {w : σ → M} (φ : mv_polynomial σ R)\n\nlemma weighted_degree'_eq_zero_iff (hw : non_trivial_weight w) (m : σ →₀ ℕ) : \n  weighted_degree' w m = 0 ↔ ∀ (x : σ), m x = 0 :=\nbegin\n  rw [weighted_degree', finsupp.total],\n  simp only [coe_lsum, linear_map.coe_smul_right, linear_map.id_coe, id.def, bot_eq_zero'], \n  rw [finsupp.sum, finset.sum_eq_zero_iff],\n  apply forall_congr, intro x,\n  rw finsupp.mem_support_iff, \n  split, \n  intro hx, \n  by_contradiction hx', apply hx', \n  exact hw _ _ (hx hx'), \n  intros hax hax', simp only [hax, zero_smul],\nend\n\nlemma is_weighted_homogeneous_of_total_weighted_degree_zero_iff {p : mv_polynomial σ R} : \n  p.weighted_total_degree w = 0 ↔ is_weighted_homogeneous w p 0 :=\nbegin\n  rw [weighted_total_degree, ← bot_eq_zero, finset.sup_eq_bot_iff, bot_eq_zero], \n  rw [is_weighted_homogeneous],\n  apply forall_congr, intro m,\n  rw mem_support_iff, \nend\n\nlemma weighted_total_degree_eq_zero_iff \n  (hw : non_trivial_weight w)\n  (p : mv_polynomial σ R) :\n  p.weighted_total_degree w = 0\n  ↔ ∀ (m : σ →₀ ℕ) (hm : m ∈ p.support) (x : σ), m x = ⊥ :=\nbegin\n  rw is_weighted_homogeneous_of_total_weighted_degree_zero_iff, \n  rw is_weighted_homogeneous,\n  apply forall_congr, intro m,\n  rw [mem_support_iff, bot_eq_zero],\n  apply forall_congr, intro hm, \n  exact weighted_degree'_eq_zero_iff hw m, \nend\n\nend canonically_linear_ordered_monoid\n\n\nsection graded_algebra\n\n/- Here, given a weight `w : σ → M`, where `M` is an additive and commutative monoid, we endow the\n  ring of multivariate polynomials `mv_polynomial σ R` with the structure of a graded algebra -/\n\nvariables [add_comm_monoid M] [decidable_eq M] \nvariable (w : σ → M)\n\nprivate lemma decompose'_aux (φ : mv_polynomial σ R) (i : M) \n  (hi : i ∉ finset.image (weighted_degree' w) φ.support) : \n  weighted_homogeneous_component R w i φ = 0 :=\nbegin\n  apply weighted_homogeneous_component_eq_zero', \n  simp only [finset.mem_image, mem_support_iff, ne.def, exists_prop, not_exists, not_and] at hi, \n  intros m hm, \n  apply hi m, \n  rw mem_support_iff at hm, \n  exact hm, \nend\n\nvariable (R)\nprivate def decompose'_fun := λ (φ : mv_polynomial σ R), direct_sum.mk \n  (λ (i : M), ↥(weighted_homogeneous_submodule R w i))\n  (finset.image (weighted_degree' w) φ.support)\n  (λ m, ⟨weighted_homogeneous_component R w m φ, weighted_homogeneous_component_mem w φ m⟩)\n\nprivate lemma decompose'_fun_apply (φ : mv_polynomial σ R) (m : M):\n  (decompose'_fun R w φ m : mv_polynomial σ R) = \n  weighted_homogeneous_component R w m φ := \nbegin\n  rw decompose'_fun,\n  by_cases hm :  m ∈ finset.image (weighted_degree' w) φ.support,\n  simp only [direct_sum.mk_apply_of_mem hm, subtype.coe_mk], \n  rw [direct_sum.mk_apply_of_not_mem hm, submodule.coe_zero, decompose'_aux w φ m hm],\nend\n\ninstance [decidable_eq σ] [decidable_eq R] :\n  Π (i : M) (x : ↥(weighted_homogeneous_submodule R w i)), decidable (x ≠ 0) :=\nbegin\n  intros m x,\n  rw [ne.def, ← set_like.coe_eq_coe], \n  apply_instance,\nend\n\n/-- Given a weight w, the decomposition of mv_polynomial σ R into weighted homogeneous submodules -/\ndef weighted_decomposition [decidable_eq σ] [decidable_eq R] : \n  direct_sum.decomposition (weighted_homogeneous_submodule R w) := \n{ decompose'  := decompose'_fun R w,\n  left_inv    := λ φ,\n  begin\n    conv_rhs { rw [← sum_weighted_homogeneous_component w φ], },\n    rw ← direct_sum.sum_support_of (λ m, ↥(weighted_homogeneous_submodule R w m))\n      (decompose'_fun R w φ),\n    simp only [direct_sum.coe_add_monoid_hom_of, mv_polynomial.coeff_sum, map_sum],\n    apply congr_arg2,\n    { ext m,\n      simp only [dfinsupp.mem_support_to_fun, ne.def, set.finite.mem_to_finset,\n        function.mem_support, not_iff_not],\n      conv_lhs { rw ← subtype.coe_inj },\n      rw [decompose'_fun_apply, submodule.coe_zero], },\n    { apply funext, intro m, rw decompose'_fun_apply, },\n  end,\n  right_inv   := λ x,\n  begin\n    apply dfinsupp.ext, intro m, \n    rw ← subtype.coe_inj, \n    rw decompose'_fun_apply, \n    change (weighted_homogeneous_component R w m) ((direct_sum.coe_linear_map (weighted_homogeneous_submodule R w)) x) = ↑(x m), \n    rw direct_sum.coe_linear_map_eq_dfinsupp_sum, \n    rw dfinsupp.sum,\n    rw map_sum, \n    rw finset.sum_eq_single m,\n    { rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_same,\n      exact (x m).prop,  },\n    { intros n hn hmn, \n      rw weighted_homogeneous_component_of_weighted_homogeneous_polynomial_other,\n      exact (x n).prop,\n      exact ne.symm hmn, },\n    { intro hm, rw dfinsupp.not_mem_support_iff at hm, \n      simp only [hm, submodule.coe_zero, map_zero], },\n  end }\n\n/-- Given a weight, mv_polynomial as a graded algebra -/\ndef weighted_graded_algebra \n  [decidable_eq σ] [decidable_eq R] : \n  graded_algebra (weighted_homogeneous_submodule R w) :=\n{ to_decomposition  := weighted_decomposition R w,\n  to_graded_monoid  := infer_instance, }\n\nlemma weighted_decomposition.decompose'_eq [decidable_eq σ] [decidable_eq R] : (weighted_decomposition R w).decompose' = \nλ (φ : mv_polynomial σ R), direct_sum.mk \n  (λ (i : M), ↥(weighted_homogeneous_submodule R w i))\n  (finset.image (weighted_degree' w) φ.support)\n  (λ m, ⟨weighted_homogeneous_component R w m φ, weighted_homogeneous_component_mem w φ m⟩) := rfl \n\nlemma weighted_decomposition.decompose'_apply [decidable_eq σ] [decidable_eq R] (φ : mv_polynomial σ R) (m : M) : ((weighted_decomposition R w).decompose' φ m : mv_polynomial σ R) = weighted_homogeneous_component R w m φ := \ndecompose'_fun_apply R w φ m \n \nend graded_algebra\n\nend mv_polynomial\n", "meta": {"author": "AntoineChambert-Loir", "repo": "divided_powers", "sha": "86b6f8716590d38e63ed11d34c0140de8ae2af7d", "save_path": "github-repos/lean/AntoineChambert-Loir-divided_powers", "path": "github-repos/lean/AntoineChambert-Loir-divided_powers/divided_powers-86b6f8716590d38e63ed11d34c0140de8ae2af7d/src/weighted_homogeneous.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.8267117983401362, "lm_q1q2_score": 0.7602793253178276}}
{"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 data.set.pointwise.iterate\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.Set.Pointwise.SMul\nimport Mathlib.Algebra.Hom.Iterate\nimport Mathlib.Dynamics.FixedPoints.Basic\n\n/-!\n# Results about pointwise operations on sets with iteration.\n-/\n\n\nopen Pointwise\n\nopen Set Function\n\n/-- Let `n : ℤ` and `s` a subset of a commutative group `G` that is invariant under preimage for\nthe map `x ↦ x^n`. Then `s` is invariant under the pointwise action of the subgroup of elements\n`g : G` such that `g^(n^j) = 1` for some `j : ℕ`. (This subgroup is called the Prüfer subgroup when\n `G` is the `Circle` and `n` is prime.) -/\n@[to_additive\n      \"Let `n : ℤ` and `s` a subset of an additive commutative group `G` that is invariant\n      under preimage for the map `x ↦ n • x`. Then `s` is invariant under the pointwise action of\n      the additive subgroup of elements `g : G` such that `(n^j) • g = 0` for some `j : ℕ`.\n      (This additive subgroup is called the Prüfer subgroup when `G` is the `AddCircle` and `n` is\n      prime.)\"]\ntheorem smul_eq_self_of_preimage_zpow_eq_self {G : Type _} [CommGroup G] {n : ℤ} {s : Set G}\n    (hs : (fun x => x ^ n) ⁻¹' s = s) {g : G} {j : ℕ} (hg : g ^ n ^ j = 1) : g • s = s := by\n  suffices ∀ {g' : G} (_ : g' ^ n ^ j = 1), g' • s ⊆ s by\n    refine' le_antisymm (this hg) _\n    conv_lhs => rw [← smul_inv_smul g s]\n    replace hg : g⁻¹ ^ n ^ j = 1\n    · rw [inv_zpow, hg, inv_one]\n    simpa only [le_eq_subset, set_smul_subset_set_smul_iff] using this hg\n  rw [(IsFixedPt.preimage_iterate hs j : zpowGroupHom n^[j] ⁻¹' s = s).symm]\n  rintro g' hg' - ⟨y, hy, rfl⟩\n  change (zpowGroupHom n^[j]) (g' * y) ∈ s\n  replace hg' : (zpowGroupHom n^[j]) g' = 1\n  · simpa [zpowGroupHom]\n  rwa [MonoidHom.iterate_map_mul, hg', one_mul]\n#align smul_eq_self_of_preimage_zpow_eq_self smul_eq_self_of_preimage_zpow_eq_self\n#align vadd_eq_self_of_preimage_zsmul_eq_self vadd_eq_self_of_preimage_zsmul_eq_self\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/Iterate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642526773001, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7602793232121949}}
{"text": "/-\nCopyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël Dillies, Sara Rousta\n-/\nimport data.set.lattice\nimport data.set_like.basic\n\n/-!\n# Up-sets and down-sets\n\nThis file defines upper and lower sets in an order.\n\n## Main declarations\n\n* `is_upper_set`: Predicate for a set to be an upper set. This means every element greater than a\n  member of the set is in the set itself.\n* `is_lower_set`: Predicate for a set to be a lower set. This means every element less than a member\n  of the set is in the set itself.\n* `upper_set`: The type of upper sets.\n* `lower_set`: The type of lower sets.\n\n## TODO\n\nLattice structure on antichains. Order equivalence between upper/lower sets and antichains.\n-/\n\nopen order_dual set\n\nvariables {ι : Sort*} {κ : ι → Sort*} {α : Type*}\n\n/-! ### Unbundled upper/lower sets -/\n\nsection unbundled\nvariables [has_le α] {s t : set α}\n\n/-- An upper set in an order `α` is a set such that any element greater than one of its members is\nalso a member. Also called up-set, upward-closed set. -/\ndef is_upper_set (s : set α) : Prop := ∀ ⦃a b : α⦄, a ≤ b → a ∈ s → b ∈ s\n\n/-- A lower set in an order `α` is a set such that any element less than one of its members is also\na member. Also called down-set, downward-closed set. -/\ndef is_lower_set (s : set α) : Prop := ∀ ⦃a b : α⦄, b ≤ a → a ∈ s → b ∈ s\n\nlemma is_upper_set_empty : is_upper_set (∅ : set α) := λ _ _ _, id\nlemma is_lower_set_empty : is_lower_set (∅ : set α) := λ _ _ _, id\nlemma is_upper_set_univ : is_upper_set (univ : set α) := λ _ _ _, id\nlemma is_lower_set_univ : is_lower_set (univ : set α) := λ _ _ _, id\nlemma is_upper_set.compl (hs : is_upper_set s) : is_lower_set sᶜ := λ a b h hb ha, hb $ hs h ha\nlemma is_lower_set.compl (hs : is_lower_set s) : is_upper_set sᶜ := λ a b h hb ha, hb $ hs h ha\n\nlemma is_upper_set.union (hs : is_upper_set s) (ht : is_upper_set t) : is_upper_set (s ∪ t) :=\nλ a b h, or.imp (hs h) (ht h)\n\nlemma is_lower_set.union (hs : is_lower_set s) (ht : is_lower_set t) : is_lower_set (s ∪ t) :=\nλ a b h, or.imp (hs h) (ht h)\n\nlemma is_upper_set.inter (hs : is_upper_set s) (ht : is_upper_set t) : is_upper_set (s ∩ t) :=\nλ a b h, and.imp (hs h) (ht h)\n\nlemma is_lower_set.inter (hs : is_lower_set s) (ht : is_lower_set t) : is_lower_set (s ∩ t) :=\nλ a b h, and.imp (hs h) (ht h)\n\nlemma is_upper_set_Union {f : ι → set α} (hf : ∀ i, is_upper_set (f i)) : is_upper_set (⋃ i, f i) :=\nλ a b h, Exists₂.imp $ forall_range_iff.2 $ λ i, hf i h\n\nlemma is_lower_set_Union {f : ι → set α} (hf : ∀ i, is_lower_set (f i)) : is_lower_set (⋃ i, f i) :=\nλ a b h, Exists₂.imp $ forall_range_iff.2 $ λ i, hf i h\n\nlemma is_upper_set_Union₂ {f : Π i, κ i → set α} (hf : ∀ i j, is_upper_set (f i j)) :\n  is_upper_set (⋃ i j, f i j) :=\nis_upper_set_Union $ λ i, is_upper_set_Union $ hf i\n\nlemma is_lower_set_Union₂ {f : Π i, κ i → set α} (hf : ∀ i j, is_lower_set (f i j)) :\n  is_lower_set (⋃ i j, f i j) :=\nis_lower_set_Union $ λ i, is_lower_set_Union $ hf i\n\nlemma is_upper_set_sUnion {S : set (set α)} (hf : ∀ s ∈ S, is_upper_set s) : is_upper_set (⋃₀ S) :=\nλ a b h, Exists₂.imp $ λ s hs, hf s hs h\n\nlemma is_lower_set_sUnion {S : set (set α)} (hf : ∀ s ∈ S, is_lower_set s) : is_lower_set (⋃₀ S) :=\nλ a b h, Exists₂.imp $ λ s hs, hf s hs h\n\nlemma is_upper_set_Inter {f : ι → set α} (hf : ∀ i, is_upper_set (f i)) : is_upper_set (⋂ i, f i) :=\nλ a b h, forall₂_imp $ forall_range_iff.2 $ λ i, hf i h\n\nlemma is_lower_set_Inter {f : ι → set α} (hf : ∀ i, is_lower_set (f i)) : is_lower_set (⋂ i, f i) :=\nλ a b h, forall₂_imp $ forall_range_iff.2 $ λ i, hf i h\n\nlemma is_upper_set_Inter₂ {f : Π i, κ i → set α} (hf : ∀ i j, is_upper_set (f i j)) :\n  is_upper_set (⋂ i j, f i j) :=\nis_upper_set_Inter $ λ i, is_upper_set_Inter $ hf i\n\nlemma is_lower_set_Inter₂ {f : Π i, κ i → set α} (hf : ∀ i j, is_lower_set (f i j)) :\n  is_lower_set (⋂ i j, f i j) :=\nis_lower_set_Inter $ λ i, is_lower_set_Inter $ hf i\n\nlemma is_upper_set_sInter {S : set (set α)} (hf : ∀ s ∈ S, is_upper_set s) : is_upper_set (⋂₀ S) :=\nλ a b h, forall₂_imp $ λ s hs, hf s hs h\n\nlemma is_lower_set_sInter {S : set (set α)} (hf : ∀ s ∈ S, is_lower_set s) : is_lower_set (⋂₀ S) :=\nλ a b h, forall₂_imp $ λ s hs, hf s hs h\n\n@[simp] lemma is_lower_set_preimage_of_dual_iff : is_lower_set (of_dual ⁻¹' s) ↔ is_upper_set s :=\niff.rfl\n@[simp] lemma is_upper_set_preimage_of_dual_iff : is_upper_set (of_dual ⁻¹' s) ↔ is_lower_set s :=\niff.rfl\n@[simp] lemma is_lower_set_preimage_to_dual_iff {s : set (order_dual α)} :\n  is_lower_set (to_dual ⁻¹' s) ↔ is_upper_set s := iff.rfl\n@[simp] lemma is_upper_set_preimage_to_dual_iff {s : set (order_dual α)} :\n  is_upper_set (to_dual ⁻¹' s) ↔ is_lower_set s := iff.rfl\n\nalias is_lower_set_preimage_of_dual_iff ↔ _ is_upper_set.of_dual\nalias is_upper_set_preimage_of_dual_iff ↔ _ is_lower_set.of_dual\nalias is_lower_set_preimage_to_dual_iff ↔ _ is_upper_set.to_dual\nalias is_upper_set_preimage_to_dual_iff ↔ _ is_lower_set.to_dual\n\nend unbundled\n\n/-! ### Bundled upper/lower sets -/\n\nsection has_le\nvariables [has_le α]\n\n/-- The type of upper sets of an order. -/\nstructure upper_set (α : Type*) [has_le α] :=\n(carrier : set α)\n(upper' : is_upper_set carrier)\n\n/-- The type of lower sets of an order. -/\nstructure lower_set (α : Type*) [has_le α] :=\n(carrier : set α)\n(lower' : is_lower_set carrier)\n\nnamespace upper_set\n\ninstance : set_like (upper_set α) α :=\n{ coe := upper_set.carrier,\n  coe_injective' := λ s t h, by { cases s, cases t, congr' } }\n\n@[ext] lemma ext {s t : upper_set α} : (s : set α) = t → s = t := set_like.ext'\n\n@[simp] lemma carrier_eq_coe (s : upper_set α) : s.carrier = s := rfl\n\nprotected lemma upper (s : upper_set α) : is_upper_set (s : set α) := s.upper'\n\nend upper_set\n\nnamespace lower_set\n\ninstance : set_like (lower_set α) α :=\n{ coe := lower_set.carrier,\n  coe_injective' := λ s t h, by { cases s, cases t, congr' } }\n\n@[ext] lemma ext {s t : lower_set α} : (s : set α) = t → s = t := set_like.ext'\n\n@[simp] lemma carrier_eq_coe (s : lower_set α) : s.carrier = s := rfl\n\nprotected lemma lower (s : lower_set α) : is_lower_set (s : set α) := s.lower'\n\nend lower_set\n\n/-! #### Order -/\n\nnamespace upper_set\nvariables {S : set (upper_set α)} {s t : upper_set α} {a : α}\n\ninstance : has_sup (upper_set α) := ⟨λ s t, ⟨s ∪ t, s.upper.union t.upper⟩⟩\ninstance : has_inf (upper_set α) := ⟨λ s t, ⟨s ∩ t, s.upper.inter t.upper⟩⟩\ninstance : has_top (upper_set α) := ⟨⟨univ, is_upper_set_univ⟩⟩\ninstance : has_bot (upper_set α) := ⟨⟨∅, is_upper_set_empty⟩⟩\ninstance : has_Sup (upper_set α) :=\n⟨λ S, ⟨⋃ s ∈ S, ↑s, is_upper_set_Union₂ $ λ s _, s.upper⟩⟩\ninstance : has_Inf (upper_set α) :=\n⟨λ S, ⟨⋂ s ∈ S, ↑s, is_upper_set_Inter₂ $ λ s _, s.upper⟩⟩\n\ninstance : complete_distrib_lattice (upper_set α) :=\nset_like.coe_injective.complete_distrib_lattice _\n  (λ _ _, rfl) (λ _ _, rfl) (λ _, rfl) (λ _, rfl) rfl rfl\n\ninstance : inhabited (upper_set α) := ⟨⊥⟩\n\n@[simp] lemma coe_top : ((⊤ : upper_set α) : set α) = univ := rfl\n@[simp] lemma coe_bot : ((⊥ : upper_set α) : set α) = ∅ := rfl\n@[simp] lemma coe_sup (s t : upper_set α) : (↑(s ⊔ t) : set α) = s ∪ t := rfl\n@[simp] lemma coe_inf (s t : upper_set α) : (↑(s ⊓ t) : set α) = s ∩ t := rfl\n@[simp] lemma coe_Sup (S : set (upper_set α)) : (↑(Sup S) : set α) = ⋃ s ∈ S, ↑s := rfl\n@[simp] lemma coe_Inf (S : set (upper_set α)) : (↑(Inf S) : set α) = ⋂ s ∈ S, ↑s := rfl\n@[simp] lemma coe_supr (f : ι → upper_set α) : (↑(⨆ i, f i) : set α) = ⋃ i, f i := by simp [supr]\n@[simp] lemma coe_infi (f : ι → upper_set α) : (↑(⨅ i, f i) : set α) = ⋂ i, f i := by simp [infi]\n@[simp] lemma coe_supr₂ (f : Π i, κ i → upper_set α) : (↑(⨆ i j, f i j) : set α) = ⋃ i j, f i j :=\nby simp_rw coe_supr\n@[simp] lemma coe_infi₂ (f : Π i, κ i → upper_set α) : (↑(⨅ i j, f i j) : set α) = ⋂ i j, f i j :=\nby simp_rw coe_infi\n\nend upper_set\n\nnamespace lower_set\nvariables {S : set (lower_set α)} {s t : lower_set α} {a : α}\n\ninstance : has_sup (lower_set α) := ⟨λ s t, ⟨s ∪ t, λ a b h, or.imp (s.lower h) (t.lower h)⟩⟩\ninstance : has_inf (lower_set α) := ⟨λ s t, ⟨s ∩ t, λ a b h, and.imp (s.lower h) (t.lower h)⟩⟩\ninstance : has_top (lower_set α) := ⟨⟨univ, λ a b h, id⟩⟩\ninstance : has_bot (lower_set α) := ⟨⟨∅, λ a b h, id⟩⟩\ninstance : has_Sup (lower_set α) := ⟨λ S, ⟨⋃ s ∈ S, ↑s, is_lower_set_Union₂ $ λ s _, s.lower⟩⟩\ninstance : has_Inf (lower_set α) := ⟨λ S, ⟨⋂ s ∈ S, ↑s, is_lower_set_Inter₂ $ λ s _, s.lower⟩⟩\n\ninstance : complete_distrib_lattice (lower_set α) :=\nset_like.coe_injective.complete_distrib_lattice _\n  (λ _ _, rfl) (λ _ _, rfl) (λ _, rfl) (λ _, rfl) rfl rfl\n\ninstance : inhabited (lower_set α) := ⟨⊥⟩\n\n@[simp] lemma coe_top : ((⊤ : lower_set α) : set α) = univ := rfl\n@[simp] lemma coe_bot : ((⊥ : lower_set α) : set α) = ∅ := rfl\n@[simp] lemma coe_sup (s t : lower_set α) : (↑(s ⊔ t) : set α) = s ∪ t := rfl\n@[simp] lemma coe_inf (s t : lower_set α) : (↑(s ⊓ t) : set α) = s ∩ t := rfl\n@[simp] lemma coe_Sup (S : set (lower_set α)) : (↑(Sup S) : set α) = ⋃ s ∈ S, ↑s := rfl\n@[simp] lemma coe_Inf (S : set (lower_set α)) : (↑(Inf S) : set α) = ⋂ s ∈ S, ↑s := rfl\n@[simp] lemma coe_supr (f : ι → lower_set α) : (↑(⨆ i, f i) : set α) = ⋃ i, f i :=\nby simp_rw [supr, coe_Sup, mem_range, Union_exists, Union_Union_eq']\n@[simp] lemma coe_infi (f : ι → lower_set α) : (↑(⨅ i, f i) : set α) = ⋂ i, f i :=\nby simp_rw [infi, coe_Inf, mem_range, Inter_exists, Inter_Inter_eq']\n@[simp] lemma coe_supr₂ (f : Π i, κ i → lower_set α) : (↑(⨆ i j, f i j) : set α) = ⋃ i j, f i j :=\nby simp_rw coe_supr\n@[simp] lemma coe_infi₂ (f : Π i, κ i → lower_set α) : (↑(⨅ i j, f i j) : set α) = ⋂ i j, f i j :=\nby simp_rw coe_infi\n\nend lower_set\n\n/-! #### Complement -/\n\n/-- The complement of a lower set as an upper set. -/\ndef upper_set.compl (s : upper_set α) : lower_set α := ⟨sᶜ, s.upper.compl⟩\n\n/-- The complement of a lower set as an upper set. -/\ndef lower_set.compl (s : lower_set α) : upper_set α := ⟨sᶜ, s.lower.compl⟩\n\nnamespace upper_set\nvariables {s : upper_set α} {a : α}\n\n@[simp] lemma coe_compl (s : upper_set α) : (s.compl : set α) = sᶜ := rfl\n@[simp] lemma mem_compl_iff : a ∈ s.compl ↔ a ∉ s := iff.rfl\n@[simp] lemma compl_compl (s : upper_set α) : s.compl.compl = s := upper_set.ext $ compl_compl _\n\n@[simp] protected lemma compl_sup (s t : upper_set α) : (s ⊔ t).compl = s.compl ⊓ t.compl :=\nlower_set.ext compl_sup\n@[simp] protected lemma compl_inf (s t : upper_set α) : (s ⊓ t).compl = s.compl ⊔ t.compl :=\nlower_set.ext compl_inf\n@[simp] protected lemma compl_top : (⊤ : upper_set α).compl = ⊥ := lower_set.ext compl_univ\n@[simp] protected lemma compl_bot : (⊥ : upper_set α).compl = ⊤ := lower_set.ext compl_empty\n@[simp] protected lemma compl_Sup (S : set (upper_set α)) :\n  (Sup S).compl = ⨅ s ∈ S, upper_set.compl s :=\nlower_set.ext $ by simp only [coe_compl, coe_Sup, compl_Union₂, lower_set.coe_infi₂]\n\n@[simp] protected lemma compl_Inf (S : set (upper_set α)) :\n  (Inf S).compl = ⨆ s ∈ S, upper_set.compl s :=\nlower_set.ext $ by simp only [coe_compl, coe_Inf, compl_Inter₂, lower_set.coe_supr₂]\n\n@[simp] protected lemma compl_supr (f : ι → upper_set α) : (⨆ i, f i).compl = ⨅ i, (f i).compl :=\nlower_set.ext $ by simp only [coe_compl, coe_supr, compl_Union, lower_set.coe_infi]\n\n@[simp] protected lemma compl_infi (f : ι → upper_set α) : (⨅ i, f i).compl = ⨆ i, (f i).compl :=\nlower_set.ext $ by simp only [coe_compl, coe_infi, compl_Inter, lower_set.coe_supr]\n\n@[simp] lemma compl_supr₂ (f : Π i, κ i → upper_set α) :\n  (⨆ i j, f i j).compl = ⨅ i j, (f i j).compl :=\nby simp_rw upper_set.compl_supr\n\n@[simp] lemma compl_infi₂ (f : Π i, κ i → upper_set α) :\n  (⨅ i j, f i j).compl =  ⨆ i j, (f i j).compl :=\nby simp_rw upper_set.compl_infi\n\nend upper_set\n\nnamespace lower_set\nvariables {s : lower_set α} {a : α}\n\n@[simp] lemma coe_compl (s : lower_set α) : (s.compl : set α) = sᶜ := rfl\n@[simp] lemma mem_compl_iff : a ∈ s.compl ↔ a ∉ s := iff.rfl\n@[simp] lemma compl_compl (s : lower_set α) : s.compl.compl = s := lower_set.ext $ compl_compl _\n\nprotected lemma compl_sup (s t : lower_set α) : (s ⊔ t).compl = s.compl ⊓ t.compl :=\nupper_set.ext compl_sup\nprotected lemma compl_inf (s t : lower_set α) : (s ⊓ t).compl = s.compl ⊔ t.compl :=\nupper_set.ext compl_inf\nprotected lemma compl_top : (⊤ : lower_set α).compl = ⊥ := upper_set.ext compl_univ\nprotected lemma compl_bot : (⊥ : lower_set α).compl = ⊤ := upper_set.ext compl_empty\nprotected lemma compl_Sup (S : set (lower_set α)) : (Sup S).compl = ⨅ s ∈ S, lower_set.compl s :=\nupper_set.ext $ by simp only [coe_compl, coe_Sup, compl_Union₂, upper_set.coe_infi₂]\n\nprotected lemma compl_Inf (S : set (lower_set α)) : (Inf S).compl = ⨆ s ∈ S, lower_set.compl s :=\nupper_set.ext $ by simp only [coe_compl, coe_Inf, compl_Inter₂, upper_set.coe_supr₂]\n\nprotected lemma compl_supr (f : ι → lower_set α) : (⨆ i, f i).compl = ⨅ i, (f i).compl :=\nupper_set.ext $ by simp only [coe_compl, coe_supr, compl_Union, upper_set.coe_infi]\n\nprotected lemma compl_infi (f : ι → lower_set α) : (⨅ i, f i).compl = ⨆ i, (f i).compl :=\nupper_set.ext $ by simp only [coe_compl, coe_infi, compl_Inter, upper_set.coe_supr]\n\n@[simp] lemma compl_supr₂ (f : Π i, κ i → lower_set α) :\n  (⨆ i j, f i j).compl = ⨅ i j, (f i j).compl :=\nby simp_rw lower_set.compl_supr\n\n@[simp] lemma compl_infi₂ (f : Π i, κ i → lower_set α) :\n  (⨅ i j, f i j).compl =  ⨆ i j, (f i j).compl :=\nby simp_rw lower_set.compl_infi\n\nend lower_set\nend has_le\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/upper_lower.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7602453149304573}}
{"text": "\ntheorem Ex010(a : Prop): a ∨ ¬false := \nhave A:false → false,from \n( \n  assume H1:false,\n  show false, from H1\n),\nhave ¬false, from not.intro A,\nshow a ∨ ¬false, from or.inr this\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/Ex010.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.7931059585194573, "lm_q1q2_score": 0.7602219829782796}}
{"text": "open nat\n\nnamespace hidden\n\ntheorem add_distrib (m n k: nat) : m * (n + k) = m * n + m * k :=\nnat.rec_on k\n  (show m * (n + 0) = m * n + m * 0, by rw [mul_zero , add_zero, add_zero])\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\ntheorem zero_mul (n : nat) : 0 * n = 0 :=\nnat.rec_on n\n  (show 0 * 0 = 0, from rfl)\n  (assume n,\n    assume ih : 0 * n = 0,\n    show 0 * succ n = 0, from calc\n      0 * succ n = 0 * n + 0 : by rw mul_succ\n      ... = 0 + 0 : by rw ih\n      ... = 0 : by rw zero_add)\n\ntheorem one_mul (n : nat) : 1 * n = n :=\nnat.rec_on n\n  (show 1 * 0 = 0, by rw mul_zero)\n  (assume n,\n    assume ih: 1 * n = n,\n    show 1 * succ n = succ n, from calc\n      1 * succ n = 1 * n + 1 : by rw mul_succ\n      ... = n + 1 : by rw ih\n      ... = succ n : rfl)\n\n\ntheorem mul_assoc (m n k : nat) : m * (n * k) = (m * n) * k :=\nnat.rec_on k\n  (show m * (n * 0) = (m * n) * 0, by rw [mul_zero, mul_zero, mul_zero])\n  (assume k,\n    assume ih : m * (n * k) = (m * n) * k,\n    show m * (n * succ k) = (m * n) * succ k, from calc\n      m * (n * succ k) = m * (n * k + n) : by rw mul_succ\n      ... = m * (n * k) + m * n : by rw add_distrib\n      ... = (m * n) * k + m * n : by rw ih\n      ... = (m * n) * succ k : by rw mul_succ)\n\ntheorem mul_comm (m n : nat) : m * n = n * m :=\nnat.rec_on n\n  (show m * 0 = 0 * m, by rw [zero_mul,mul_zero])\n  (assume n,\n    assume ih: m * n = n * m,\n    show m * succ n = succ n * m, from calc\n      m * succ n = m * n + m : by rw mul_succ\n      ... = n * m + m : by rw ih\n      ... = succ n * m : by rw succ_mul)\n\n-- END\nend hidden\n\n\nopen nat\n\nnamespace hidden\n\n\n-- BEGIN\ntheorem T1 : ∀ m n : nat, m > n → (m = n + 1) ∨ (m > n + 1) :=\nassume m n,\nassume h,\nhave h1: succ n ≤ m, from succ_le_of_lt h,\nhave h2 : n + 1 < m ∨ n + 1 = m, from iff.elim_left le_iff_lt_or_eq h1,\nor.elim h2\n  (assume : n + 1 < m,\n    show m = n + 1 ∨ m > n + 1, from or.inr this)\n  (assume : n + 1 = m,\n    have m = n + 1, from eq.symm this,\n    show m = n + 1 ∨ m > n + 1, from or.inl this)\n\n\ntheorem T2: ∀ n : nat, n = 0 ∨ n > 0 :=\nassume n,\nhave 0 = n ∨ 0 < n, from or.swap $ iff.elim_left le_iff_lt_or_eq $ zero_le n,\nor.elim this\n  (assume h1, or.inl (eq.symm h1))\n  (assume h1, or.inr h1)\n\n\ntheorem T3 (m n : nat) : n + m = 0 → n = 0 ∧ m = 0 :=\nassume h,\nhave h1: n ≥ 0, from zero_le n,\nhave h2: m ≥ 0, from zero_le m,\niff.elim_left (add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg h1 h2) h\n\ntheorem T4 (n m k : nat) : n * k < m * k → k > 0 ∧ n < m :=\nassume h,\nhave h1 : k ≥ 0, from zero_le k,\nhave h2 : n < m, from lt_of_mul_lt_mul_right h h1,\nhave h3: k ≠ 0, from\n  assume : k = 0,\n  have n * 0 < m * 0, from (this ▸ h),\n  lt_le_antisymm this (zero_le 0),\nhave h4: k > 0, from lt_of_le_of_ne h1 h3.symm,\n⟨ h4 , h2 ⟩\n\n-- END\nend hidden\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/ch18.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7602123251710011}}
{"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.group_action\nimport group_theory.group_action.defs\nimport group_theory.group_action.group\nimport data.setoid.basic\nimport data.fintype.card\n\n/-!\n# Basic properties of group actions\n\nThis file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of\nactions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation\nof `•` belong elsewhere.\n\n## Main definitions\n\n* `mul_action.orbit`\n* `mul_action.fixed_points`\n* `mul_action.fixed_by`\n* `mul_action.stabilizer`\n\n-/\n\nuniverses u v w\nvariables {α : Type u} {β : Type v} {γ : Type w}\n\nopen_locale big_operators pointwise\nopen function\n\nnamespace mul_action\n\nvariables (α) [monoid α] [mul_action α β]\n\n/-- The orbit of an element under an action. -/\n@[to_additive \"The orbit of an element under an action.\"]\ndef orbit (b : β) := set.range (λ x : α, x • b)\n\nvariable {α}\n\n@[to_additive] lemma mem_orbit_iff {b₁ b₂ : β} : b₂ ∈ orbit α b₁ ↔ ∃ x : α, x • b₁ = b₂ :=\niff.rfl\n\n@[simp, to_additive] lemma mem_orbit (b : β) (x : α) : x • b ∈ orbit α b :=\n⟨x, rfl⟩\n\n@[simp, to_additive] lemma mem_orbit_self (b : β) : b ∈ orbit α b :=\n⟨1, by simp [mul_action.one_smul]⟩\n\n@[to_additive] lemma orbit_nonempty (b : β) : set.nonempty (orbit α b) := set.range_nonempty _\n\n@[to_additive] lemma maps_to_smul_orbit (a : α) (b : β) :\n  set.maps_to ((•) a) (orbit α b) (orbit α b) :=\nset.range_subset_iff.2 $ λ a', ⟨a * a', mul_smul _ _ _⟩\n\n@[to_additive] lemma smul_orbit_subset (a : α) (b : β) : a • orbit α b ⊆ orbit α b :=\n(maps_to_smul_orbit a b).image_subset\n\n@[to_additive] lemma orbit_smul_subset (a : α) (b : β) : orbit α (a • b) ⊆ orbit α b :=\nset.range_subset_iff.2 $ λ a', mul_smul a' a b ▸ mem_orbit _ _\n\n@[to_additive] instance {b : β} : mul_action α (orbit α b) :=\n{ smul := λ a, (maps_to_smul_orbit a b).restrict _ _ _,\n  one_smul := λ a, subtype.ext (one_smul α a),\n  mul_smul := λ a a' b', subtype.ext (mul_smul a a' b') }\n\n@[simp, to_additive] lemma orbit.coe_smul {b : β} {a : α} {b' : orbit α b} :\n  ↑(a • b') = a • (b' : β) :=\nrfl\n\nvariables (α) (β)\n\n/-- The set of elements fixed under the whole action. -/\n@[to_additive \"The set of elements fixed under the whole action.\"]\ndef fixed_points : set β := {b : β | ∀ x : α, x • b = b}\n\n/-- `fixed_by g` is the subfield of elements fixed by `g`. -/\n@[to_additive \"`fixed_by g` is the subfield of elements fixed by `g`.\"]\ndef fixed_by (g : α) : set β :=\n{ x | g • x = x }\n\n@[to_additive] theorem fixed_eq_Inter_fixed_by : fixed_points α β = ⋂ g : α, fixed_by α β g :=\nset.ext $ λ x, ⟨λ hx, set.mem_Inter.2 $ λ g, hx g, λ hx g, by exact (set.mem_Inter.1 hx g : _)⟩\n\nvariables {α} (β)\n\n@[simp, to_additive] lemma mem_fixed_points {b : β} :\n  b ∈ fixed_points α β ↔ ∀ x : α, x • b = b := iff.rfl\n\n@[simp, to_additive] lemma mem_fixed_by {g : α} {b : β} :\n  b ∈ fixed_by α β g ↔ g • b = b := iff.rfl\n\n@[to_additive] lemma mem_fixed_points' {b : β} : b ∈ fixed_points α β ↔\n  (∀ b', b' ∈ orbit α b → b' = b) :=\n⟨λ h b h₁, let ⟨x, hx⟩ := mem_orbit_iff.1 h₁ in hx ▸ h x,\nλ h b, h _ (mem_orbit _ _)⟩\n\nvariables (α) {β}\n\n/-- The stabilizer of a point `b` as a submonoid of `α`. -/\n@[to_additive \"The stabilizer of a point `b` as an additive submonoid of `α`.\"]\ndef stabilizer.submonoid (b : β) : submonoid α :=\n{ carrier := { a | a • b = b },\n  one_mem' := one_smul _ b,\n  mul_mem' := λ a a' (ha : a • b = b) (hb : a' • b = b),\n    show (a * a') • b = b, by rw [←smul_smul, hb, ha] }\n\n@[simp, to_additive] lemma mem_stabilizer_submonoid_iff {b : β} {a : α} :\n  a ∈ stabilizer.submonoid α b ↔ a • b = b := iff.rfl\n\n@[to_additive] lemma orbit_eq_univ [is_pretransitive α β] (x : β) :\n  orbit α x = set.univ :=\n(surjective_smul α x).range_eq\n\nvariables {α} {β}\n\n@[to_additive] lemma mem_fixed_points_iff_card_orbit_eq_one {a : β}\n  [fintype (orbit α a)] : a ∈ fixed_points α β ↔ fintype.card (orbit α a) = 1 :=\nbegin\n  rw [fintype.card_eq_one_iff, mem_fixed_points],\n  split,\n  { exact λ h, ⟨⟨a, mem_orbit_self _⟩, λ ⟨b, ⟨x, hx⟩⟩, subtype.eq $ by simp [h x, hx.symm]⟩ },\n  { assume h x,\n    rcases h with ⟨⟨z, hz⟩, hz₁⟩,\n    calc x • a = z : subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩)\n      ... = a : (subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm }\nend\n\nend mul_action\n\nnamespace mul_action\nvariable (α)\nvariables [group α] [mul_action α β]\n\n/-- The stabilizer of an element under an action, i.e. what sends the element to itself.\nA subgroup. -/\n@[to_additive \"The stabilizer of an element under an action, i.e. what sends the element to itself.\nAn additive subgroup.\"]\ndef stabilizer (b : β) : subgroup α :=\n{ inv_mem' := λ a (ha : a • b = b), show a⁻¹ • b = b, by rw [inv_smul_eq_iff, ha]\n  ..stabilizer.submonoid α b }\n\nvariables {α} {β}\n\n@[simp, to_additive] lemma mem_stabilizer_iff {b : β} {a : α} :\n  a ∈ stabilizer α b ↔ a • b = b := iff.rfl\n\n@[simp, to_additive] lemma smul_orbit (a : α) (b : β) :\n  a • orbit α b = orbit α b :=\n(smul_orbit_subset a b).antisymm $\n  calc orbit α b = a • a⁻¹ • orbit α b : (smul_inv_smul _ _).symm\n             ... ⊆ a • orbit α b       : set.image_subset _ (smul_orbit_subset _ _)\n\n@[simp, to_additive] lemma orbit_smul (a : α) (b : β) : orbit α (a • b) = orbit α b :=\n(orbit_smul_subset a b).antisymm $\n  calc orbit α b = orbit α (a⁻¹ • a • b) : by rw inv_smul_smul\n             ... ⊆ orbit α (a • b)       : orbit_smul_subset _ _\n\n/-- The action of a group on an orbit is transitive. -/\n@[to_additive \"The action of an additive group on an orbit is transitive.\"]\ninstance (x : β) : is_pretransitive α (orbit α x) :=\n⟨by { rintro ⟨_, a, rfl⟩ ⟨_, b, rfl⟩, use b * a⁻¹, ext1, simp [mul_smul] }⟩\n\n@[to_additive] lemma orbit_eq_iff {a b : β} :\n   orbit α a = orbit α b ↔ a ∈ orbit α b:=\n⟨λ h, h ▸ mem_orbit_self _, λ ⟨c, hc⟩, hc ▸ orbit_smul _ _⟩\n\nvariables (α) {β}\n\n@[to_additive] lemma mem_orbit_smul (g : α) (a : β) : a ∈ orbit α (g • a) :=\nby simp only [orbit_smul, mem_orbit_self]\n\n@[to_additive] lemma smul_mem_orbit_smul (g h : α) (a : β) : g • a ∈ orbit α (h • a) :=\nby simp only [orbit_smul, mem_orbit]\n\nvariables (α) (β)\n/-- The relation 'in the same orbit'. -/\n@[to_additive \"The relation 'in the same orbit'.\"]\ndef orbit_rel : setoid β :=\n{ r := λ a b, a ∈ orbit α b,\n  iseqv := ⟨mem_orbit_self, λ a b, by simp [orbit_eq_iff.symm, eq_comm],\n    λ a b, by simp [orbit_eq_iff.symm, eq_comm] {contextual := tt}⟩ }\n\nlocal attribute [instance] orbit_rel\n\nvariables {α} {β}\n/-- When you take a set `U` in `β`, push it down to the quotient, and pull back, you get the union\nof the orbit of `U` under `α`.\n-/\n@[to_additive] lemma quotient_preimage_image_eq_union_mul (U : set β) :\n  quotient.mk ⁻¹' (quotient.mk '' U) = ⋃ a : α, ((•) a) '' U :=\nbegin\n  set f : β → quotient (mul_action.orbit_rel α β) := quotient.mk,\n  ext,\n  split,\n  { rintros ⟨y , hy, hxy⟩,\n    obtain ⟨a, rfl⟩ := quotient.exact hxy,\n    rw set.mem_Union,\n    exact ⟨a⁻¹, a • x, hy, inv_smul_smul a x⟩ },\n  { intros hx,\n    rw set.mem_Union at hx,\n    obtain ⟨a, u, hu₁, hu₂⟩ := hx,\n    rw [set.mem_preimage, set.mem_image_iff_bex],\n    refine ⟨a⁻¹ • x, _, by simp only [quotient.eq]; use a⁻¹⟩,\n    rw ← hu₂,\n    convert hu₁,\n    simp only [inv_smul_smul], },\nend\n\n@[to_additive] lemma disjoint_image_image_iff {U V : set β} :\n  disjoint (quotient.mk '' U) (quotient.mk '' V) ↔ ∀ x ∈ U, ∀ a : α, a • x ∉ V :=\nbegin\n  set f : β → quotient (mul_action.orbit_rel α β) := quotient.mk,\n  refine ⟨λ h x x_in_U a a_in_V, h ⟨⟨x, x_in_U, quotient.sound ⟨a⁻¹, _⟩⟩, ⟨a • x, a_in_V, rfl⟩⟩, _⟩,\n  { simp },\n  { rintro h x ⟨⟨y, hy₁, hy₂⟩, ⟨z, hz₁, hz₂⟩⟩,\n    obtain ⟨a, rfl⟩ := quotient.exact (hz₂.trans hy₂.symm),\n    exact h y hy₁ a hz₁ }\nend\n\n@[to_additive]\nlemma image_inter_image_iff (U V : set β) :\n  (quotient.mk '' U) ∩ (quotient.mk '' V) = ∅ ↔ ∀ x ∈ U, ∀ a : α, a • x ∉ V :=\nset.disjoint_iff_inter_eq_empty.symm.trans disjoint_image_image_iff\n\nvariables (α) (β)\nlocal notation `Ω` := (quotient $ orbit_rel α β)\n\n/-- Decomposition of a type `X` as a disjoint union of its orbits under a group action.\nThis version works with any right inverse to `quotient.mk'` in order to stay computable. In most\ncases you'll want to use `quotient.out'`, so we provide `mul_action.self_equiv_sigma_orbits` as\na special case. -/\n@[to_additive \"Decomposition of a type `X` as a disjoint union of its orbits under an additive group\naction. This version works with any right inverse to `quotient.mk'` in order to stay computable.\nIn most cases you'll want to use `quotient.out'`, so we provide `add_action.self_equiv_sigma_orbits`\nas a special case.\"]\ndef self_equiv_sigma_orbits' {φ : Ω → β} (hφ : right_inverse φ quotient.mk') :\n  β ≃ Σ (ω : Ω), orbit α (φ ω) :=\ncalc  β\n    ≃ Σ (ω : Ω), {b // quotient.mk' b = ω} : (equiv.sigma_fiber_equiv quotient.mk').symm\n... ≃ Σ (ω : Ω), orbit α (φ ω) :\n        equiv.sigma_congr_right (λ ω, equiv.subtype_equiv_right $\n          λ x, by {rw [← hφ ω, quotient.eq', hφ ω], refl })\n\n/-- Decomposition of a type `X` as a disjoint union of its orbits under a group action. -/\n@[to_additive \"Decomposition of a type `X` as a disjoint union of its orbits under an additive group\naction.\"]\nnoncomputable def self_equiv_sigma_orbits : β ≃ Σ (ω : Ω), orbit α ω.out' :=\nself_equiv_sigma_orbits' α β quotient.out_eq'\n\nvariables {α β}\n\n/-- If the stabilizer of `x` is `S`, then the stabilizer of `g • x` is `gSg⁻¹`. -/\nlemma stabilizer_smul_eq_stabilizer_map_conj (g : α) (x : β) :\n  (stabilizer α (g • x) = (stabilizer α x).map (mul_aut.conj g).to_monoid_hom) :=\nbegin\n  ext h,\n  rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul, mul_left_inv,\n      one_smul, ← mem_stabilizer_iff, subgroup.mem_map_equiv, mul_aut.conj_symm_apply]\nend\n\n/-- A bijection between the stabilizers of two elements in the same orbit. -/\nnoncomputable def stabilizer_equiv_stabilizer_of_orbit_rel {x y : β} (h : (orbit_rel α β).rel x y) :\n  stabilizer α x ≃* stabilizer α y :=\nlet g : α := classical.some h in\nhave hg : g • y = x := classical.some_spec h,\nhave this : stabilizer α x = (stabilizer α y).map (mul_aut.conj g).to_monoid_hom,\n  by rw [← hg, stabilizer_smul_eq_stabilizer_map_conj],\n(mul_equiv.subgroup_congr this).trans ((mul_aut.conj g).subgroup_map $ stabilizer α y).symm\n\nend mul_action\n\nnamespace add_action\n\nvariables [add_group α] [add_action α β]\n\n/-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/\nlemma stabilizer_vadd_eq_stabilizer_map_conj (g : α) (x : β) :\n  (stabilizer α (g +ᵥ x) = (stabilizer α x).map (add_aut.conj g).to_add_monoid_hom) :=\nbegin\n  ext h,\n  rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g) , vadd_vadd, vadd_vadd, vadd_vadd,\n      add_left_neg, zero_vadd, ← mem_stabilizer_iff, add_subgroup.mem_map_equiv,\n      add_aut.conj_symm_apply]\nend\n\n/-- A bijection between the stabilizers of two elements in the same orbit. -/\nnoncomputable def stabilizer_equiv_stabilizer_of_orbit_rel {x y : β}\n  (h : (orbit_rel α β).rel x y) :\n  stabilizer α x ≃+ stabilizer α y :=\nlet g : α := classical.some h in\nhave hg : g +ᵥ y = x := classical.some_spec h,\nhave this : stabilizer α x = (stabilizer α y).map (add_aut.conj g).to_add_monoid_hom,\n  by rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj],\n(add_equiv.add_subgroup_congr this).trans\n  ((add_aut.conj g).add_subgroup_map $ stabilizer α y).symm\n\nend add_action\n\n/-- `smul` by a `k : M` over a ring is injective, if `k` is not a zero divisor.\nThe general theory of such `k` is elaborated by `is_smul_regular`.\nThe typeclass that restricts all terms of `M` to have this property is `no_zero_smul_divisors`. -/\nlemma smul_cancel_of_non_zero_divisor {M R : Type*}\n  [monoid M] [non_unital_non_assoc_ring R] [distrib_mul_action M R]\n  (k : M) (h : ∀ (x : R), k • x = 0 → x = 0) {a b : R} (h' : k • a = k • b) :\n  a = b :=\nbegin\n  rw ←sub_eq_zero,\n  refine h _ _,\n  rw [smul_sub, h', sub_self]\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/group_theory/group_action/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.7602123251710011}}
{"text": "/-\nCopyright (c) 2022 Kalle Kytölä. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kytölä\n\n! This file was ported from Lean 3 source module measure_theory.integral.layercake\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.Analysis.SpecialFunctions.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 : ℝ≥0 → ℝ≥0` 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`∫ G ∘ 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   ∫ f(ω) ∂μ(ω) = ∫ μ {ω | f(ω) ≥ t} dt\n * a representation of the integral of the p:th power of a nonnegative function f:\n   ∫ f(ω)^p ∂μ(ω) = p * ∫ t^(p-1) * μ {ω | f(ω) ≥ t} dt .\n\nVariants of the formulas with measures of sets of the form {ω | f(ω) > t} instead of {ω | f(ω) ≥ 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 {ω | t ≤ f(ω)} and {ω | t < f(ω)}, 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 ∫ f(ω) ∂μ(ω) = ∫ μ {ω | f(ω) ≥ t} dt and\n   ∫ f(ω) ∂μ(ω) = ∫ μ {ω | f(ω) > 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 ∫ f(ω)^p ∂μ(ω) = p * ∫ μ {ω | f(ω) ≥ t} * t^(p-1) dt and\n   ∫ f(ω)^p ∂μ(ω) = p * ∫ μ {ω | f(ω) > t} * t^(p-1) dt, respectively.\n\n## Tags\n\nlayer cake representation, Cavalieri's principle, tail probability formula\n-/\n\n\nnoncomputable section\n\nopen ENNReal MeasureTheory\n\nopen Set MeasureTheory Filter\n\n/-! ### Layercake formula -/\n\n\nsection Layercake\n\nnamespace MeasureTheory\n\nvariable {α : Type _} [MeasurableSpace α] {f : α → ℝ} {g : ℝ → ℝ} {s : Set α}\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. -/\ntheorem lintegral_comp_eq_lintegral_meas_le_mul_of_measurable (μ : Measure α) [SigmaFinite μ]\n    (f_nn : 0 ≤ f) (f_mble : Measurable f) (g_intble : ∀ t > 0, IntervalIntegrable g volume 0 t)\n    (g_mble : Measurable g) (g_nn : ∀ t > 0, 0 ≤ g t) :\n    (∫⁻ ω, ENNReal.ofReal (∫ t in 0 ..f ω, g t) ∂μ) =\n      ∫⁻ t in Ioi 0, μ { a : α | t ≤ f a } * ENNReal.ofReal (g t) :=\n  by\n  have g_intble' : ∀ t : ℝ, 0 ≤ t → IntervalIntegrable g volume 0 t :=\n    by\n    intro t ht\n    cases eq_or_lt_of_le ht\n    · simp [← h]\n    · exact g_intble t h\n  have integrand_eq :\n    ∀ ω, ENNReal.ofReal (∫ t in 0 ..f ω, g t) = ∫⁻ t in Ioc 0 (f ω), ENNReal.ofReal (g t) :=\n    by\n    intro ω\n    have g_ae_nn : 0 ≤ᵐ[volume.restrict (Ioc 0 (f ω))] g := by\n      filter_upwards [self_mem_ae_restrict\n          (measurableSet_Ioc : MeasurableSet (Ioc 0 (f ω)))]with x hx using g_nn x hx.1\n    rw [← of_real_integral_eq_lintegral_of_real (g_intble' (f ω) (f_nn ω)).1 g_ae_nn]\n    congr\n    exact intervalIntegral.integral_of_le (f_nn ω)\n  simp_rw [integrand_eq, ← lintegral_indicator (fun t => ENNReal.ofReal (g t)) measurableSet_Ioc, ←\n    lintegral_indicator _ measurableSet_Ioi]\n  rw [lintegral_lintegral_swap]\n  · apply congr_arg\n    funext s\n    have aux₁ :\n      (fun x => (Ioc 0 (f x)).indicator (fun t : ℝ => ENNReal.ofReal (g t)) s) = fun x =>\n        ENNReal.ofReal (g s) * (Ioi (0 : ℝ)).indicator (fun _ => 1) s *\n          (Ici s).indicator (fun t : ℝ => (1 : ℝ≥0∞)) (f x) :=\n      by\n      funext a\n      by_cases s ∈ Ioc (0 : ℝ) (f a)\n      ·\n        simp only [h, show s ∈ Ioi (0 : ℝ) from h.1, show f a ∈ Ici s from h.2, indicator_of_mem,\n          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        ·\n          simp only [h_copy, h h', indicator_of_not_mem, not_false_iff, mem_Ici, not_le,\n            MulZeroClass.mul_zero]\n        · have : s ∉ Ioi (0 : ℝ) := h'\n          simp only [this, h', indicator_of_not_mem, not_false_iff, MulZeroClass.mul_zero,\n            MulZeroClass.zero_mul, mem_Ioc, false_and_iff]\n    simp_rw [aux₁]\n    rw [lintegral_const_mul']\n    swap\n    · apply ENNReal.mul_ne_top ENNReal.ofReal_ne_top\n      by_cases s ∈ Ioi (0 : ℝ) <;> · simp [h]\n    simp_rw [show\n        (fun a => (Ici s).indicator (fun t : ℝ => (1 : ℝ≥0∞)) (f a)) = fun a =>\n          { a : α | s ≤ f a }.indicator (fun _ => 1) a\n        by\n        funext a\n        by_cases s ≤ f a <;> simp [h]]\n    rw [lintegral_indicator]\n    swap\n    · exact f_mble measurableSet_Ici\n    rw [lintegral_one, measure.restrict_apply MeasurableSet.univ, univ_inter, indicator_mul_left,\n      mul_assoc,\n      show\n        (Ioi 0).indicator (fun _x : ℝ => (1 : ℝ≥0∞)) s * μ { a : α | s ≤ f a } =\n          (Ioi 0).indicator (fun _x : ℝ => 1 * μ { a : α | s ≤ f a }) s\n        by by_cases 0 < s <;> simp [h]]\n    simp_rw [mul_comm _ (ENNReal.ofReal _), one_mul]\n    rfl\n  have aux₂ :\n    (Function.uncurry fun (x : α) (y : ℝ) =>\n        (Ioc 0 (f x)).indicator (fun t : ℝ => ENNReal.ofReal (g t)) y) =\n      { p : α × ℝ | p.2 ∈ Ioc 0 (f p.1) }.indicator fun p => ENNReal.ofReal (g p.2) :=\n    by\n    funext p\n    cases p\n    rw [Function.uncurry_apply_pair]\n    by_cases p_snd ∈ Ioc 0 (f p_fst)\n    · have h' : (p_fst, p_snd) ∈ { p : α × ℝ | p.snd ∈ 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) ∉ { p : α × ℝ | p.snd ∈ Ioc 0 (f p.fst) } := h\n      rw [Set.indicator_of_not_mem h', Set.indicator_of_not_mem h]\n  rw [aux₂]\n  have mble := measurableSet_region_between_oc measurable_zero f_mble MeasurableSet.univ\n  simp_rw [mem_univ, Pi.zero_apply, true_and_iff] at mble\n  exact (ennreal.measurable_of_real.comp (g_mble.comp measurable_snd)).AeMeasurable.indicator mble\n#align measure_theory.lintegral_comp_eq_lintegral_meas_le_mul_of_measurable MeasureTheory.lintegral_comp_eq_lintegral_meas_le_mul_of_measurable\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 ∘ f` can be written as\nthe integral over the positive real line of the \"tail measures\" `μ {ω | f(ω) ≥ t}` of `f`\nweighted by `g`.\n\nRoughly speaking, the statement is: `∫⁻ (G ∘ f) ∂μ = ∫⁻ t in 0 .. ∞, g(t) * μ {ω | f(ω) ≥ t}`.\n\nSee `lintegral_comp_eq_lintegral_meas_lt_mul` for a version with sets of the form `{ω | f(ω) > t}`\ninstead. -/\ntheorem lintegral_comp_eq_lintegral_meas_le_mul (μ : Measure α) [SigmaFinite μ] (f_nn : 0 ≤ f)\n    (f_mble : Measurable f) (g_intble : ∀ t > 0, IntervalIntegrable g volume 0 t)\n    (g_nn : ∀ᵐ t ∂volume.restrict (Ioi 0), 0 ≤ g t) :\n    (∫⁻ ω, ENNReal.ofReal (∫ t in 0 ..f ω, g t) ∂μ) =\n      ∫⁻ t in Ioi 0, μ { a : α | t ≤ f a } * ENNReal.ofReal (g t) :=\n  by\n  have ex_G : ∃ G : ℝ → ℝ, Measurable G ∧ 0 ≤ G ∧ g =ᵐ[volume.restrict (Ioi 0)] G :=\n    by\n    refine' AeMeasurable.exists_measurable_nonneg _ g_nn\n    exact aeMeasurableIoiOfForallIoc fun t ht => (g_intble t ht).1.1.AeMeasurable\n  rcases ex_G with ⟨G, G_mble, G_nn, g_eq_G⟩\n  have g_eq_G_on : ∀ t, g =ᵐ[volume.restrict (Ioc 0 t)] G := fun t =>\n    ae_mono (measure.restrict_mono Ioc_subset_Ioi_self le_rfl) g_eq_G\n  have G_intble : ∀ t > 0, IntervalIntegrable G volume 0 t :=\n    by\n    refine' fun t t_pos => ⟨integrable_on.congr_fun' (g_intble t t_pos).1 (g_eq_G_on t), _⟩\n    rw [Ioc_eq_empty_of_le t_pos.lt.le]\n    exact integrable_on_empty\n  have eq₁ :\n    (∫⁻ t in Ioi 0, μ { a : α | t ≤ f a } * ENNReal.ofReal (g t)) =\n      ∫⁻ t in Ioi 0, μ { a : α | t ≤ f a } * ENNReal.ofReal (G t) :=\n    by\n    apply lintegral_congr_ae\n    filter_upwards [g_eq_G]with a ha\n    rw [ha]\n  have eq₂ : ∀ ω, (∫ t in 0 ..f ω, g t) = ∫ t in 0 ..f ω, G t :=\n    by\n    refine' fun ω => intervalIntegral.integral_congr_ae _\n    have fω_nn : 0 ≤ f ω := f_nn ω\n    rw [uIoc_of_le fω_nn, ←\n      ae_restrict_iff' (measurableSet_Ioc : MeasurableSet (Ioc (0 : ℝ) (f ω)))]\n    exact g_eq_G_on (f ω)\n  simp_rw [eq₁, eq₂]\n  exact\n    lintegral_comp_eq_lintegral_meas_le_mul_of_measurable μ f_nn f_mble G_intble G_mble\n      fun t t_pos => G_nn t\n#align measure_theory.lintegral_comp_eq_lintegral_meas_le_mul MeasureTheory.lintegral_comp_eq_lintegral_meas_le_mul\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: `∫⁻ f ∂μ = ∫⁻ t in 0 .. ∞, μ {ω | f(ω) ≥ t}`.\n\nSee `lintegral_eq_lintegral_meas_lt` for a version with sets of the form `{ω | f(ω) > t}`\ninstead. -/\ntheorem lintegral_eq_lintegral_meas_le (μ : Measure α) [SigmaFinite μ] (f_nn : 0 ≤ f)\n    (f_mble : Measurable f) :\n    (∫⁻ ω, ENNReal.ofReal (f ω) ∂μ) = ∫⁻ t in Ioi 0, μ { a : α | t ≤ f a } :=\n  by\n  set cst := fun t : ℝ => (1 : ℝ) with def_cst\n  have cst_intble : ∀ t > 0, IntervalIntegrable cst volume 0 t := fun _ _ => intervalIntegrableConst\n  have key :=\n    lintegral_comp_eq_lintegral_meas_le_mul μ f_nn f_mble cst_intble\n      (eventually_of_forall fun t => zero_le_one)\n  simp_rw [def_cst, ENNReal.ofReal_one, mul_one] at key\n  rw [← key]\n  congr with ω\n  simp only [intervalIntegral.integral_const, sub_zero, Algebra.id.smul_eq_mul, mul_one]\n#align measure_theory.lintegral_eq_lintegral_meas_le MeasureTheory.lintegral_eq_lintegral_meas_le\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: `∫⁻ f^p ∂μ = p * ∫⁻ t in 0 .. ∞, t^(p-1) * μ {ω | f(ω) ≥ t}`.\n\nSee `lintegral_rpow_eq_lintegral_meas_lt_mul` for a version with sets of the form `{ω | f(ω) > t}`\ninstead. -/\ntheorem lintegral_rpow_eq_lintegral_meas_le_mul (μ : Measure α) [SigmaFinite μ] (f_nn : 0 ≤ f)\n    (f_mble : Measurable f) {p : ℝ} (p_pos : 0 < p) :\n    (∫⁻ ω, ENNReal.ofReal (f ω ^ p) ∂μ) =\n      ENNReal.ofReal p * ∫⁻ t in Ioi 0, μ { a : α | t ≤ f a } * ENNReal.ofReal (t ^ (p - 1)) :=\n  by\n  have one_lt_p : -1 < p - 1 := by linarith\n  have obs : ∀ x : ℝ, (∫ t : ℝ in 0 ..x, t ^ (p - 1)) = x ^ p / p :=\n    by\n    intro x\n    rw [integral_rpow (Or.inl one_lt_p)]\n    simp [Real.zero_rpow p_pos.ne.symm]\n  set g := fun t : ℝ => t ^ (p - 1) with g_def\n  have g_nn : ∀ᵐ t ∂volume.restrict (Ioi (0 : ℝ)), 0 ≤ g t :=\n    by\n    filter_upwards [self_mem_ae_restrict (measurableSet_Ioi : MeasurableSet (Ioi (0 : ℝ)))]\n    intro 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 : ∀ t > 0, IntervalIntegrable g volume 0 t := fun _ _ =>\n    intervalIntegral.intervalIntegrableRpow' one_lt_p\n  have key := lintegral_comp_eq_lintegral_meas_le_mul μ f_nn f_mble g_intble g_nn\n  simp_rw [g_def] at key\n  rw [← key, ← lintegral_const_mul (ENNReal.ofReal p)] <;> simp_rw [obs]\n  · congr with ω\n    rw [← ENNReal.ofReal_mul p_pos.le, mul_div_cancel' (f ω ^ p) p_pos.ne.symm]\n  · exact ((f_mble.pow measurable_const).div_const p).eNNReal_ofReal\n#align measure_theory.lintegral_rpow_eq_lintegral_meas_le_mul MeasureTheory.lintegral_rpow_eq_lintegral_meas_le_mul\n\nend MeasureTheory\n\nend Layercake\n\nsection LayercakeLt\n\nopen MeasureTheory\n\nvariable {α : Type _} [MeasurableSpace α] (μ : Measure α)\n\nvariable {β : Type _} [MeasurableSpace β] [MeasurableSingletonClass β]\n\nnamespace Measure\n\ntheorem meas_le_ne_meas_lt_subset_meas_pos {R : Type _} [LinearOrder R] [MeasurableSpace R]\n    [MeasurableSingletonClass R] {g : α → R} (g_mble : Measurable g) {t : R}\n    (ht : μ { a : α | t ≤ g a } ≠ μ { a : α | t < g a }) : 0 < μ { a : α | g a = t } :=\n  by\n  have uni : { a : α | t ≤ g a } = { a : α | t < g a } ∪ { a : α | t = g a } :=\n    by\n    ext a\n    simp only [mem_set_of_eq, mem_union]\n    apply le_iff_lt_or_eq\n  rw [show { a : α | t = g a } = { a : α | g a = t } by simp_rw [eq_comm]] at uni\n  have disj : { a : α | t < g a } ∩ { a : α | g a = t } = ∅ :=\n    by\n    ext a\n    simp only [mem_inter_iff, mem_set_of_eq, mem_empty_iff_false, iff_false_iff, not_and]\n    exact ne_of_gt\n  have μ_add : μ { a : α | t ≤ g a } = μ { a : α | t < g a } + μ { a : α | g a = t } := by\n    rw [uni,\n      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 μ_add\n  exact ht μ_add\n#align measure.meas_le_ne_meas_lt_subset_meas_pos Measure.meas_le_ne_meas_lt_subset_meas_pos\n\ntheorem countable_meas_le_ne_meas_lt [SigmaFinite μ] {R : Type _} [LinearOrder R]\n    [MeasurableSpace R] [MeasurableSingletonClass R] {g : α → R} (g_mble : Measurable g) :\n    { t : R | μ { a : α | t ≤ g a } ≠ μ { a : α | t < g a } }.Countable :=\n  Countable.mono (show _ from fun t ht => meas_le_ne_meas_lt_subset_meas_pos μ g_mble ht)\n    (Measure.countable_meas_level_set_pos g_mble)\n#align measure.countable_meas_le_ne_meas_lt Measure.countable_meas_le_ne_meas_lt\n\ntheorem meas_le_ae_eq_meas_lt [SigmaFinite μ] {R : Type _} [LinearOrder R] [MeasurableSpace R]\n    [MeasurableSingletonClass R] (ν : Measure R) [HasNoAtoms ν] {g : α → R}\n    (g_mble : Measurable g) :\n    (fun t => μ { a : α | t ≤ g a }) =ᵐ[ν] fun t => μ { a : α | t < g a } :=\n  Set.Countable.measure_zero (Measure.countable_meas_le_ne_meas_lt μ g_mble) _\n#align measure.meas_le_ae_eq_meas_lt Measure.meas_le_ae_eq_meas_lt\n\nend Measure\n\nvariable {f : α → ℝ} {g : ℝ → ℝ} {s : Set α}\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 ∘ f` can be written as\nthe integral over the positive real line of the \"tail measures\" `μ {ω | f(ω) > t}` of `f`\nweighted by `g`.\n\nRoughly speaking, the statement is: `∫⁻ (G ∘ f) ∂μ = ∫⁻ t in 0 .. ∞, g(t) * μ {ω | f(ω) > t}`.\n\nSee `lintegral_comp_eq_lintegral_meas_le_mul` for a version with sets of the form `{ω | f(ω) ≥ t}`\ninstead. -/\ntheorem lintegral_comp_eq_lintegral_meas_lt_mul (μ : Measure α) [SigmaFinite μ] (f_nn : 0 ≤ f)\n    (f_mble : Measurable f) (g_intble : ∀ t > 0, IntervalIntegrable g volume 0 t)\n    (g_nn : ∀ᵐ t ∂volume.restrict (Ioi 0), 0 ≤ g t) :\n    (∫⁻ ω, ENNReal.ofReal (∫ t in 0 ..f ω, g t) ∂μ) =\n      ∫⁻ t in Ioi 0, μ { a : α | t < f a } * ENNReal.ofReal (g t) :=\n  by\n  rw [lintegral_comp_eq_lintegral_meas_le_mul μ f_nn f_mble g_intble g_nn]\n  apply lintegral_congr_ae\n  filter_upwards [Measure.meas_le_ae_eq_meas_lt μ (volume.restrict (Ioi 0)) f_mble]with t ht\n  rw [ht]\n#align lintegral_comp_eq_lintegral_meas_lt_mul lintegral_comp_eq_lintegral_meas_lt_mul\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: `∫⁻ f ∂μ = ∫⁻ t in 0 .. ∞, μ {ω | f(ω) > t}`.\n\nSee `lintegral_eq_lintegral_meas_le` for a version with sets of the form `{ω | f(ω) ≥ t}`\ninstead. -/\ntheorem lintegral_eq_lintegral_meas_lt (μ : Measure α) [SigmaFinite μ] (f_nn : 0 ≤ f)\n    (f_mble : Measurable f) :\n    (∫⁻ ω, ENNReal.ofReal (f ω) ∂μ) = ∫⁻ t in Ioi 0, μ { a : α | t < f a } :=\n  by\n  rw [lintegral_eq_lintegral_meas_le μ f_nn f_mble]\n  apply lintegral_congr_ae\n  filter_upwards [Measure.meas_le_ae_eq_meas_lt μ (volume.restrict (Ioi 0)) f_mble]with t ht\n  rw [ht]\n#align lintegral_eq_lintegral_meas_lt lintegral_eq_lintegral_meas_lt\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: `∫⁻ f^p ∂μ = p * ∫⁻ t in 0 .. ∞, t^(p-1) * μ {ω | f(ω) > t}`.\n\nSee `lintegral_rpow_eq_lintegral_meas_le_mul` for a version with sets of the form `{ω | f(ω) ≥ t}`\ninstead. -/\ntheorem lintegral_rpow_eq_lintegral_meas_lt_mul (μ : Measure α) [SigmaFinite μ] (f_nn : 0 ≤ f)\n    (f_mble : Measurable f) {p : ℝ} (p_pos : 0 < p) :\n    (∫⁻ ω, ENNReal.ofReal (f ω ^ p) ∂μ) =\n      ENNReal.ofReal p * ∫⁻ t in Ioi 0, μ { a : α | t < f a } * ENNReal.ofReal (t ^ (p - 1)) :=\n  by\n  rw [lintegral_rpow_eq_lintegral_meas_le_mul μ f_nn f_mble p_pos]\n  apply congr_arg fun z => ENNReal.ofReal p * z\n  apply lintegral_congr_ae\n  filter_upwards [Measure.meas_le_ae_eq_meas_lt μ (volume.restrict (Ioi 0)) f_mble]with t ht\n  rw [ht]\n#align lintegral_rpow_eq_lintegral_meas_lt_mul lintegral_rpow_eq_lintegral_meas_lt_mul\n\nend LayercakeLt\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/Layercake.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7602123238398667}}
{"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, Leonardo de Moura, Jeremy Avigad\n\nThe order relation on the natural numbers.\n-/\nimport .basic algebra.ordered_ring\nopen eq.ops\n\nnamespace nat\n\n/- lt and le -/\n\nprotected theorem le_of_lt_or_eq {m n : ℕ} (H : m < n ∨ m = n) : m ≤ n :=\nnat.le_of_eq_or_lt (or.swap H)\n\nprotected theorem lt_or_eq_of_le {m n : ℕ} (H : m ≤ n) : m < n ∨ m = n :=\nor.swap (nat.eq_or_lt_of_le H)\n\nprotected theorem le_iff_lt_or_eq (m n : ℕ) : m ≤ n ↔ m < n ∨ m = n :=\niff.intro nat.lt_or_eq_of_le nat.le_of_lt_or_eq\n\nprotected theorem lt_of_le_and_ne {m n : ℕ} (H1 : m ≤ n) : m ≠ n → m < n :=\nor_resolve_right (nat.eq_or_lt_of_le H1)\n\nprotected theorem lt_iff_le_and_ne (m n : ℕ) : m < n ↔ m ≤ n ∧ m ≠ n :=\niff.intro\n  (take H, and.intro (nat.le_of_lt H) (take H1, !nat.lt_irrefl (H1 ▸ H)))\n  (and.rec nat.lt_of_le_and_ne)\n\ntheorem le_add_right (n k : ℕ) : n ≤ n + k :=\nnat.rec !nat.le_refl (λ k, le_succ_of_le) k\n\ntheorem le_add_left (n m : ℕ): n ≤ m + n :=\n!add.comm ▸ !le_add_right\n\ntheorem le.intro {n m k : ℕ} (h : n + k = m) : n ≤ m :=\nh ▸ !le_add_right\n\ntheorem le.elim {n m : ℕ} : n ≤ m → ∃ k, n + k = m :=\nle.rec (exists.intro 0 rfl) (λm h, Exists.rec\n  (λ k H, exists.intro (succ k) (H ▸ rfl)))\n\nprotected theorem le_total {m n : ℕ} : m ≤ n ∨ n ≤ m :=\nor.imp_left nat.le_of_lt !nat.lt_or_ge\n\n/- addition -/\n\nprotected theorem add_le_add_left {n m : ℕ} (H : n ≤ m) (k : ℕ) : k + n ≤ k + m :=\nobtain l Hl, from le.elim H, le.intro (Hl ▸ !add.assoc)\n\nprotected theorem add_le_add_right {n m : ℕ} (H : n ≤ m) (k : ℕ) : n + k ≤ m + k :=\n!add.comm ▸ !add.comm ▸ nat.add_le_add_left H k\n\nprotected theorem le_of_add_le_add_left {k n m : ℕ} (H : k + n ≤ k + m) : n ≤ m :=\nobtain l Hl, from le.elim H, le.intro (nat.add_left_cancel (!add.assoc⁻¹ ⬝ Hl))\n\nprotected theorem lt_of_add_lt_add_left {k n m : ℕ} (H : k + n < k + m) : n < m :=\nlet H' := nat.le_of_lt H in\nnat.lt_of_le_and_ne (nat.le_of_add_le_add_left H') (assume Heq, !nat.lt_irrefl (Heq ▸ H))\n\nprotected theorem add_lt_add_left {n m : ℕ} (H : n < m) (k : ℕ) : k + n < k + m :=\nlt_of_succ_le (!add_succ ▸ nat.add_le_add_left (succ_le_of_lt H) k)\n\nprotected theorem add_lt_add_right {n m : ℕ} (H : n < m) (k : ℕ) : n + k < m + k :=\n!add.comm ▸ !add.comm ▸ nat.add_lt_add_left H k\n\nprotected theorem lt_add_of_pos_right {n k : ℕ} (H : k > 0) : n < n + k :=\n!add_zero ▸ nat.add_lt_add_left H n\n\n/- multiplication -/\n\ntheorem mul_le_mul_left {n m : ℕ} (k : ℕ) (H : n ≤ m) : k * n ≤ k * m :=\nobtain (l : ℕ) (Hl : n + l = m), from le.elim H,\nhave k * n + k * l = k * m, by rewrite [-left_distrib, Hl],\nle.intro this\n\ntheorem mul_le_mul_right {n m : ℕ} (k : ℕ) (H : n ≤ m) : n * k ≤ m * k :=\n!mul.comm ▸ !mul.comm ▸ !mul_le_mul_left H\n\nprotected theorem mul_le_mul {n m k l : ℕ} (H1 : n ≤ k) (H2 : m ≤ l) : n * m ≤ k * l :=\nnat.le_trans (!nat.mul_le_mul_right H1) (!nat.mul_le_mul_left H2)\n\nprotected theorem mul_lt_mul_of_pos_left {n m k : ℕ} (H : n < m) (Hk : k > 0) : k * n < k * m :=\nnat.lt_of_lt_of_le (nat.lt_add_of_pos_right Hk) (!mul_succ ▸ nat.mul_le_mul_left k (succ_le_of_lt H))\n\nprotected theorem mul_lt_mul_of_pos_right {n m k : ℕ} (H : n < m) (Hk : k > 0) : n * k < m * k :=\n!mul.comm ▸ !mul.comm ▸ nat.mul_lt_mul_of_pos_left H Hk\n\n/- nat is an instance of a linearly ordered semiring and a lattice -/\n\nprotected definition decidable_linear_ordered_semiring [trans_instance] :\ndecidable_linear_ordered_semiring nat :=\n⦃ decidable_linear_ordered_semiring, nat.comm_semiring,\n  add_left_cancel            := @nat.add_left_cancel,\n  add_right_cancel           := @nat.add_right_cancel,\n  lt                         := nat.lt,\n  le                         := nat.le,\n  le_refl                    := nat.le_refl,\n  le_trans                   := @nat.le_trans,\n  le_antisymm                := @nat.le_antisymm,\n  le_total                   := @nat.le_total,\n  le_iff_lt_or_eq            := @nat.le_iff_lt_or_eq,\n  le_of_lt                   := @nat.le_of_lt,\n  lt_irrefl                  := @nat.lt_irrefl,\n  lt_of_lt_of_le             := @nat.lt_of_lt_of_le,\n  lt_of_le_of_lt             := @nat.lt_of_le_of_lt,\n  lt_of_add_lt_add_left      := @nat.lt_of_add_lt_add_left,\n  add_lt_add_left            := @nat.add_lt_add_left,\n  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_lt_one                := zero_lt_succ 0,\n  mul_le_mul_of_nonneg_left  := (take a b c H1 H2, nat.mul_le_mul_left c H1),\n  mul_le_mul_of_nonneg_right := (take a b c H1 H2, nat.mul_le_mul_right c H1),\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  decidable_lt               := nat.decidable_lt ⦄\n\ndefinition nat_has_dvd [instance] [priority nat.prio] : has_dvd nat :=\nhas_dvd.mk has_dvd.dvd\n\ntheorem add_pos_left {a : ℕ} (H : 0 < a) (b : ℕ) : 0 < a + b :=\n@add_pos_of_pos_of_nonneg _ _ a b H !zero_le\n\ntheorem add_pos_right {a : ℕ} (H : 0 < a) (b : ℕ) : 0 < b + a :=\nby rewrite add.comm; apply add_pos_left H b\n\ntheorem add_eq_zero_iff_eq_zero_and_eq_zero {a b : ℕ} :\na + b = 0 ↔ a = 0 ∧ b = 0 :=\n@add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg _ _ a b !zero_le !zero_le\n\ntheorem le_add_of_le_left {a b c : ℕ} (H : b ≤ c) : b ≤ a + c :=\n@le_add_of_nonneg_of_le _ _ a b c !zero_le H\n\ntheorem le_add_of_le_right {a b c : ℕ} (H : b ≤ c) : b ≤ c + a :=\n@le_add_of_le_of_nonneg _ _ a b c H !zero_le\n\ntheorem lt_add_of_lt_left {b c : ℕ} (H : b < c) (a : ℕ) : b < a + c :=\n@lt_add_of_nonneg_of_lt _ _ a b c !zero_le H\n\ntheorem lt_add_of_lt_right {b c : ℕ} (H : b < c) (a : ℕ) : b < c + a :=\n@lt_add_of_lt_of_nonneg _ _ a b c H !zero_le\n\ntheorem lt_of_mul_lt_mul_left {a b c : ℕ} (H : c * a < c * b) : a < b :=\n@lt_of_mul_lt_mul_left _ _ a b c H !zero_le\n\ntheorem lt_of_mul_lt_mul_right {a b c : ℕ} (H : a * c < b * c) : a < b :=\n@lt_of_mul_lt_mul_right _ _ a b c H !zero_le\n\ntheorem pos_of_mul_pos_left {a b : ℕ} (H : 0 < a * b) : 0 < b :=\n@pos_of_mul_pos_left _ _ a b H !zero_le\n\ntheorem pos_of_mul_pos_right {a b : ℕ} (H : 0 < a * b) : 0 < a :=\n@pos_of_mul_pos_right _ _ a b H !zero_le\n\ntheorem zero_le_one : (0:nat) ≤ 1 :=\ndec_trivial\n\n/- properties specific to nat -/\n\ntheorem lt_intro {n m k : ℕ} (H : succ n + k = m) : n < m :=\nlt_of_succ_le (le.intro H)\n\ntheorem lt_elim {n m : ℕ} (H : n < m) : ∃k, succ n + k = m :=\nle.elim (succ_le_of_lt H)\n\ntheorem lt_add_succ (n m : ℕ) : n < n + succ m :=\nlt_intro !succ_add_eq_succ_add\n\ntheorem eq_zero_of_le_zero {n : ℕ} (H : n ≤ 0) : n = 0 :=\nobtain (k : ℕ) (Hk : n + k = 0), from le.elim H,\neq_zero_of_add_eq_zero_right Hk\n\n/- succ and pred -/\n\ntheorem le_of_lt_succ {m n : nat} : m < succ n → m ≤ n :=\nle_of_succ_le_succ\n\ntheorem lt_iff_succ_le (m n : nat) : m < n ↔ succ m ≤ n :=\niff.rfl\n\ntheorem lt_succ_iff_le (m n : nat) : m < succ n ↔ m ≤ n :=\niff.intro le_of_lt_succ lt_succ_of_le\n\ntheorem self_le_succ (n : ℕ) : n ≤ succ n :=\nle.intro !add_one\n\ntheorem succ_le_or_eq_of_le {n m : ℕ} : n ≤ m → succ n ≤ m ∨ n = m :=\nlt_or_eq_of_le\n\ntheorem pred_le_of_le_succ {n m : ℕ} : n ≤ succ m → pred n ≤ m :=\npred_le_pred\n\ntheorem succ_le_of_le_pred {n m : ℕ} : succ n ≤ m → n ≤ pred m :=\npred_le_pred\n\ntheorem pred_le_pred_of_le {n m : ℕ} : n ≤ m → pred n ≤ pred m :=\npred_le_pred\n\ntheorem pre_lt_of_lt {n m : ℕ} : n < m → pred n < m :=\nlt_of_le_of_lt !pred_le\n\ntheorem lt_of_pred_lt_pred {n m : ℕ} (H : pred n < pred m) : n < m :=\nlt_of_not_ge\n  (suppose m ≤ n,\n    not_lt_of_ge (pred_le_pred_of_le this) H)\n\ntheorem le_or_eq_succ_of_le_succ {n m : ℕ} (H : n ≤ succ m) : n ≤ m ∨ n = succ m :=\nor.imp_left le_of_succ_le_succ (succ_le_or_eq_of_le H)\n\ntheorem le_pred_self (n : ℕ) : pred n ≤ n :=\n!pred_le\n\ntheorem succ_pos (n : ℕ) : 0 < succ n :=\n!zero_lt_succ\n\ntheorem succ_pred_of_pos {n : ℕ} (H : n > 0) : succ (pred n) = n :=\n(or_resolve_right (eq_zero_or_eq_succ_pred n) (ne.symm (ne_of_lt H)))⁻¹\n\ntheorem exists_eq_succ_of_lt {n : ℕ} : Π {m : ℕ}, n < m → ∃k, m = succ k\n| 0        H := absurd H !not_lt_zero\n| (succ k) H := exists.intro k rfl\n\ntheorem lt_succ_self (n : ℕ) : n < succ n :=\nlt.base n\n\nlemma lt_succ_of_lt {i j : nat} : i < j → i < succ j :=\nassume Plt, lt.trans Plt (self_lt_succ j)\n\nlemma one_le_succ (n : ℕ) : 1 ≤ succ n :=\nnat.succ_le_succ !zero_le\n\nlemma two_le_succ_succ (n : ℕ) : 2 ≤ succ (succ n) :=\nnat.succ_le_succ !one_le_succ\n\n/- increasing and decreasing functions -/\n\nsection\n  variables {A : Type} [strict_order A] {f : ℕ → A}\n\n  theorem strictly_increasing_of_forall_lt_succ (H : ∀ i, f i < f (succ i)) : strictly_increasing f :=\n  take i j,\n  nat.induction_on j\n    (suppose i < 0, absurd this !not_lt_zero)\n    (take j', assume ih, suppose i < succ j',\n       or.elim (lt_or_eq_of_le (le_of_lt_succ this))\n         (suppose i < j', lt.trans (ih this) (H j'))\n         (suppose i = j', by rewrite this; apply H))\n\n  theorem strictly_decreasing_of_forall_gt_succ (H : ∀ i, f i > f (succ i)) : strictly_decreasing f :=\n  take i j,\n  nat.induction_on j\n    (suppose i < 0, absurd this !not_lt_zero)\n    (take j', assume ih, suppose i < succ j',\n       or.elim (lt_or_eq_of_le (le_of_lt_succ this))\n         (suppose i < j', lt.trans (H j') (ih this))\n         (suppose i = j', by rewrite this; apply H))\nend\n\nsection\n  variables {A : Type} [weak_order A] {f : ℕ → A}\n\n  theorem nondecreasing_of_forall_le_succ (H : ∀ i, f i ≤ f (succ i)) : nondecreasing f :=\n  take i j,\n  nat.induction_on j\n    (suppose i ≤ 0, have i = 0, from eq_zero_of_le_zero this, by rewrite this; apply le.refl)\n    (take j', assume ih, suppose i ≤ succ j',\n       or.elim (le_or_eq_succ_of_le_succ this)\n         (suppose i ≤ j', le.trans (ih this) (H j'))\n         (suppose i = succ j', by rewrite this; apply le.refl))\n\n  theorem nonincreasing_of_forall_ge_succ (H : ∀ i, f i ≥ f (succ i)) : nonincreasing f :=\n  take i j,\n  nat.induction_on j\n    (suppose i ≤ 0, have i = 0, from eq_zero_of_le_zero this, by rewrite this; apply le.refl)\n    (take j', assume ih, suppose i ≤ succ j',\n       or.elim (le_or_eq_succ_of_le_succ this)\n         (suppose i ≤ j', le.trans (H j') (ih this))\n         (suppose i = succ j', by rewrite this; apply le.refl))\nend\n\n/- other forms of induction -/\n\nprotected definition strong_rec_on {P : nat → Type} (n : ℕ) (H : ∀n, (∀m, m < n → P m) → P n) : P n :=\nnat.rec (λm h, absurd h !not_lt_zero)\n  (λn' (IH : ∀ {m : ℕ}, m < n' → P m) m l,\n     or.by_cases (lt_or_eq_of_le (le_of_lt_succ l))\n    IH (λ e, eq.rec (H n' @IH) e⁻¹)) (succ n) n !lt_succ_self\n\nprotected theorem strong_induction_on {P : nat → Prop} (n : ℕ) (H : ∀n, (∀m, m < n → P m) → P n) :\n    P n :=\nnat.strong_rec_on n H\n\nprotected theorem case_strong_induction_on {P : nat → Prop} (a : nat) (H0 : P 0)\n  (Hind : ∀(n : nat), (∀m, m ≤ n → P m) → P (succ n)) : P a :=\nnat.strong_induction_on a\n  (take n,\n   show (∀ m, m < n → P m) → P n, from\n     nat.cases_on n\n       (suppose (∀ m, m < 0 → P m), show P 0, from H0)\n       (take n,\n         suppose (∀ m, m < succ n → P m),\n         show P (succ n), from\n           Hind n (take m, assume H1 : m ≤ n, this _ (lt_succ_of_le H1))))\n\n/- pos -/\n\ntheorem by_cases_zero_pos {P : ℕ → Prop} (y : ℕ) (H0 : P 0) (H1 : ∀ {y : nat}, y > 0 → P y) :\n  P y :=\nnat.cases_on y H0 (take y, H1 !succ_pos)\n\ntheorem eq_zero_or_pos (n : ℕ) : n = 0 ∨ n > 0 :=\nor_of_or_of_imp_left\n  (or.swap (lt_or_eq_of_le !zero_le))\n  (suppose 0 = n, by subst n)\n\ntheorem pos_of_ne_zero {n : ℕ} (H : n ≠ 0) : n > 0 :=\nor.elim !eq_zero_or_pos (take H2 : n = 0, by contradiction) (take H2 : n > 0, H2)\n\ntheorem ne_zero_of_pos {n : ℕ} (H : n > 0) : n ≠ 0 :=\nne.symm (ne_of_lt H)\n\ntheorem exists_eq_succ_of_pos {n : ℕ} (H : n > 0) : ∃l, n = succ l :=\nexists_eq_succ_of_lt H\n\ntheorem pos_of_dvd_of_pos {m n : ℕ} (H1 : m ∣ n) (H2 : n > 0) : m > 0 :=\npos_of_ne_zero\n  (suppose m = 0,\n   have  n = 0, from eq_zero_of_zero_dvd (this ▸ H1),\n   ne_of_lt H2 (by subst n))\n\n/- multiplication -/\n\ntheorem mul_lt_mul_of_le_of_lt {n m k l : ℕ} (Hk : k > 0) (H1 : n ≤ k) (H2 : m < l) :\n  n * m < k * l :=\nlt_of_le_of_lt (mul_le_mul_right m H1) (mul_lt_mul_of_pos_left H2 Hk)\n\ntheorem mul_lt_mul_of_lt_of_le {n m k l : ℕ} (Hl : l > 0) (H1 : n < k) (H2 : m ≤ l) :\n  n * m < k * l :=\nlt_of_le_of_lt (mul_le_mul_left n H2) (mul_lt_mul_of_pos_right H1 Hl)\n\ntheorem mul_lt_mul_of_le_of_le {n m k l : ℕ} (H1 : n < k) (H2 : m < l) : n * m < k * l :=\nhave H3 : n * m ≤ k * m, from mul_le_mul_right m (le_of_lt H1),\nhave H4 : k * m < k * l, from mul_lt_mul_of_pos_left H2 (lt_of_le_of_lt !zero_le H1),\nlt_of_le_of_lt H3 H4\n\ntheorem eq_of_mul_eq_mul_left {m k n : ℕ} (Hn : n > 0) (H : n * m = n * k) : m = k :=\nhave n * m ≤ n * k, by rewrite H,\nhave m ≤ k,         from le_of_mul_le_mul_left this Hn,\nhave n * k ≤ n * m, by rewrite H,\nhave k ≤ m,         from le_of_mul_le_mul_left this Hn,\nle.antisymm `m ≤ k` this\n\ntheorem eq_of_mul_eq_mul_right {n m k : ℕ} (Hm : m > 0) (H : n * m = k * m) : n = k :=\neq_of_mul_eq_mul_left Hm (!mul.comm ▸ !mul.comm ▸ H)\n\ntheorem eq_zero_or_eq_of_mul_eq_mul_left {n m k : ℕ} (H : n * m = n * k) : n = 0 ∨ m = k :=\nor_of_or_of_imp_right !eq_zero_or_pos\n  (assume Hn : n > 0, eq_of_mul_eq_mul_left Hn H)\n\ntheorem eq_zero_or_eq_of_mul_eq_mul_right  {n m k : ℕ} (H : n * m = k * m) : m = 0 ∨ n = k :=\neq_zero_or_eq_of_mul_eq_mul_left (!mul.comm ▸ !mul.comm ▸ H)\n\ntheorem eq_one_of_mul_eq_one_right {n m : ℕ} (H : n * m = 1) : n = 1 :=\nhave H2 : n * m > 0, by rewrite H; apply succ_pos,\nor.elim (le_or_gt n 1)\n  (suppose n ≤ 1,\n    have n > 0, from pos_of_mul_pos_right H2,\n    show n = 1, from le.antisymm `n ≤ 1` (succ_le_of_lt this))\n  (suppose n > 1,\n    have m > 0, from pos_of_mul_pos_left H2,\n    have n * m ≥ 2 * 1, from nat.mul_le_mul (succ_le_of_lt `n > 1`) (succ_le_of_lt this),\n    have 1 ≥ 2, from !mul_one ▸ H ▸ this,\n    absurd !lt_succ_self (not_lt_of_ge this))\n\ntheorem eq_one_of_mul_eq_one_left {n m : ℕ} (H : n * m = 1) : m = 1 :=\neq_one_of_mul_eq_one_right (!mul.comm ▸ H)\n\ntheorem eq_one_of_mul_eq_self_left {n m : ℕ} (Hpos : n > 0) (H : m * n = n) : m = 1 :=\neq_of_mul_eq_mul_right Hpos (H ⬝ !one_mul⁻¹)\n\ntheorem eq_one_of_mul_eq_self_right {n m : ℕ} (Hpos : m > 0) (H : m * n = m) : n = 1 :=\neq_one_of_mul_eq_self_left Hpos (!mul.comm ▸ H)\n\ntheorem eq_one_of_dvd_one {n : ℕ} (H : n ∣ 1) : n = 1 :=\ndvd.elim H\n  (take m, suppose 1 = n * m,\n   eq_one_of_mul_eq_one_right this⁻¹)\n\n/- min and max -/\nopen decidable\n\ntheorem min_zero [simp] (a : ℕ) : min a 0 = 0 :=\nby rewrite [min_eq_right !zero_le]\n\ntheorem zero_min [simp] (a : ℕ) : min 0 a = 0 :=\nby rewrite [min_eq_left !zero_le]\n\ntheorem max_zero [simp] (a : ℕ) : max a 0 = a :=\nby rewrite [max_eq_left !zero_le]\n\ntheorem zero_max [simp] (a : ℕ) : max 0 a = a :=\nby rewrite [max_eq_right !zero_le]\n\ntheorem min_succ_succ [simp] (a b : ℕ) : min (succ a) (succ b) = succ (min a b) :=\nor.elim !lt_or_ge\n  (suppose a < b, by rewrite [min_eq_left_of_lt this, min_eq_left_of_lt (succ_lt_succ this)])\n  (suppose a ≥ b, by rewrite [min_eq_right this, min_eq_right (succ_le_succ this)])\n\ntheorem max_succ_succ [simp] (a b : ℕ) : max (succ a) (succ b) = succ (max a b) :=\nor.elim !lt_or_ge\n  (suppose a < b, by rewrite [max_eq_right_of_lt this, max_eq_right_of_lt (succ_lt_succ this)])\n  (suppose a ≥ b, by rewrite [max_eq_left this, max_eq_left (succ_le_succ this)])\n\n/- In algebra.ordered_group, these next four are only proved for additive groups, not additive\n   semigroups. -/\n\nprotected theorem min_add_add_left (a b c : ℕ) : min (a + b) (a + c) = a + min b c :=\ndecidable.by_cases\n  (suppose b ≤ c,\n   have a + b ≤ a + c, from add_le_add_left this _,\n   by rewrite [min_eq_left `b ≤ c`, min_eq_left this])\n  (suppose ¬ b ≤ c,\n   have c ≤ b,         from le_of_lt (lt_of_not_ge this),\n   have a + c ≤ a + b, from add_le_add_left this _,\n   by rewrite [min_eq_right `c ≤ b`, min_eq_right this])\n\nprotected theorem min_add_add_right (a b c : ℕ) : min (a + c) (b + c) = min a b + c :=\nby rewrite [add.comm a c, add.comm b c, add.comm _ c]; apply nat.min_add_add_left\n\nprotected theorem max_add_add_left (a b c : ℕ) : max (a + b) (a + c) = a + max b c :=\ndecidable.by_cases\n  (suppose b ≤ c,\n   have a + b ≤ a + c, from add_le_add_left this _,\n   by rewrite [max_eq_right `b ≤ c`, max_eq_right this])\n  (suppose ¬ b ≤ c,\n   have c ≤ b,         from le_of_lt (lt_of_not_ge this),\n   have a + c ≤ a + b, from add_le_add_left this _,\n   by rewrite [max_eq_left `c ≤ b`, max_eq_left this])\n\nprotected theorem max_add_add_right (a b c : ℕ) : max (a + c) (b + c) = max a b + c :=\nby rewrite [add.comm a c, add.comm b c, add.comm _ c]; apply nat.max_add_add_left\n\n/- least and greatest -/\n\nsection least_and_greatest\n  variable (P : ℕ → Prop)\n  variable [decP : ∀ n, decidable (P n)]\n  include decP\n\n  -- returns the least i < n satisfying P, or n if there is none\n  definition least : ℕ → ℕ\n    | 0        := 0\n    | (succ n) := if P (least n) then least n else succ n\n\n  theorem least_of_bound {n : ℕ} (H : P n) : P (least P n) :=\n    begin\n      induction n with [m, ih],\n      rewrite ↑least,\n      apply H,\n      rewrite ↑least,\n      cases decidable.em (P (least P m)) with [Hlp, Hlp],\n      rewrite [if_pos Hlp],\n      apply Hlp,\n      rewrite [if_neg Hlp],\n      apply H\n    end\n\n  theorem least_le (n : ℕ) : least P n ≤ n:=\n    begin\n      induction n with [m, ih],\n        {rewrite ↑least},\n      rewrite ↑least,\n      cases decidable.em (P (least P m)) with [Psm, Pnsm],\n      rewrite [if_pos Psm],\n      apply le.trans ih !le_succ,\n      rewrite [if_neg Pnsm]\n    end\n\n theorem least_of_lt {i n : ℕ} (ltin : i < n) (H : P i) : P (least P n) :=\n   begin\n     induction n with [m, ih],\n     exact absurd ltin !not_lt_zero,\n     rewrite ↑least,\n     cases decidable.em (P (least P m)) with [Psm, Pnsm],\n     rewrite [if_pos Psm],\n     apply Psm,\n     rewrite [if_neg Pnsm],\n     cases (lt_or_eq_of_le (le_of_lt_succ ltin)) with [Hlt, Heq],\n     exact absurd (ih Hlt) Pnsm,\n     rewrite Heq at H,\n     exact absurd (least_of_bound P H) Pnsm\n   end\n\n  theorem ge_least_of_lt {i n : ℕ} (ltin : i < n) (Hi : P i) : i ≥ least P n :=\n    begin\n      induction n with [m, ih],\n      exact absurd ltin !not_lt_zero,\n      rewrite ↑least,\n      cases decidable.em (P (least P m)) with [Psm, Pnsm],\n      rewrite [if_pos Psm],\n      cases (lt_or_eq_of_le (le_of_lt_succ ltin)) with [Hlt, Heq],\n      apply ih Hlt,\n      rewrite Heq,\n      apply least_le,\n      rewrite [if_neg Pnsm],\n      cases (lt_or_eq_of_le (le_of_lt_succ ltin)) with [Hlt, Heq],\n      apply absurd (least_of_lt P Hlt Hi) Pnsm,\n      rewrite Heq at Hi,\n      apply absurd (least_of_bound P Hi) Pnsm\n    end\n  theorem least_lt {n i : ℕ} (ltin : i < n) (Hi : P i) : least P n < n :=\n    lt_of_le_of_lt (ge_least_of_lt P ltin Hi) ltin\n\n  -- returns the largest i < n satisfying P, or n if there is none.\n  definition greatest : ℕ → ℕ\n  | 0        := 0\n  | (succ n) := if P n then n else greatest n\n\n  theorem greatest_of_lt {i n : ℕ} (ltin : i < n) (Hi : P i) : P (greatest P n) :=\n  begin\n    induction n with [m, ih],\n      {exact absurd ltin !not_lt_zero},\n      {cases (decidable.em (P m)) with [Psm, Pnsm],\n        {rewrite [↑greatest, if_pos Psm]; exact Psm},\n        {rewrite [↑greatest, if_neg Pnsm],\n          have neim : i ≠ m, from assume H : i = m, absurd (H ▸ Hi) Pnsm,\n          have ltim : i < m, from lt_of_le_of_ne (le_of_lt_succ ltin) neim,\n          apply ih ltim}}\n  end\n\n  theorem le_greatest_of_lt {i n : ℕ} (ltin : i < n) (Hi : P i) : i ≤ greatest P n :=\n  begin\n    induction n with [m, ih],\n      {exact absurd ltin !not_lt_zero},\n      {cases (decidable.em (P m)) with [Psm, Pnsm],\n        {rewrite [↑greatest, if_pos Psm], apply le_of_lt_succ ltin},\n        {rewrite [↑greatest, if_neg Pnsm],\n          have neim : i ≠ m, from assume H : i = m, absurd (H ▸ Hi) Pnsm,\n          have ltim : i < m, from lt_of_le_of_ne (le_of_lt_succ ltin) neim,\n          apply ih ltim}}\n  end\n\nend least_and_greatest\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/order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7602123199350613}}
{"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 algebra.order.invertible\n! leanprover-community/mathlib commit ee0c179cd3c8a45aa5bffbf1b41d8dbede452865\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.Defs\nimport Mathlib.Algebra.Invertible\nimport Mathlib.Data.Nat.Cast.Basic\n\n/-!\n# Lemmas about `invOf` in ordered (semi)rings.\n-/\n\nvariable [LinearOrderedSemiring α] {a : α}\n\n@[simp]\ntheorem invOf_pos [Invertible a] : 0 < ⅟ a ↔ 0 < a :=\n  haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one]\n  ⟨fun h => pos_of_mul_pos_left this h.le, fun h => pos_of_mul_pos_right this h.le⟩\n#align inv_of_pos invOf_pos\n\n@[simp]\ntheorem invOf_nonpos [Invertible a] : ⅟ a ≤ 0 ↔ a ≤ 0 := by simp only [← not_lt, invOf_pos]\n#align inv_of_nonpos invOf_nonpos\n\n@[simp]\ntheorem invOf_nonneg [Invertible a] : 0 ≤ ⅟ a ↔ 0 ≤ a :=\n  haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one]\n  ⟨fun h => (pos_of_mul_pos_left this h).le, fun h => (pos_of_mul_pos_right this h).le⟩\n#align inv_of_nonneg invOf_nonneg\n\n@[simp]\ntheorem invOf_lt_zero [Invertible a] : ⅟ a < 0 ↔ a < 0 := by simp only [← not_le, invOf_nonneg]\n#align inv_of_lt_zero invOf_lt_zero\n\n@[simp]\ntheorem invOf_le_one [Invertible a] (h : 1 ≤ a) : ⅟ a ≤ 1 :=\n  mul_invOf_self a ▸ le_mul_of_one_le_left (invOf_nonneg.2 <| zero_le_one.trans h) h\n#align inv_of_le_one invOf_le_one\n\ntheorem pos_invOf_of_invertible_cast [Nontrivial α] (n : ℕ)\n    [Invertible (n : α)] : 0 < ⅟(n : α) :=\n  invOf_pos.2 <| Nat.cast_pos.2 <| pos_of_invertible_cast (α := α) 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/Algebra/Order/Invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070011518829, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7602123141666057}}
{"text": "import .field_rename\nimport ...inClassNotes.typeclasses.functor\nimport ...inClassNotes.typeclasses.algebra\nimport data.real.basic\n\n/-\nCopy this file to where you want to work on \nit and then adjust the imports accordingly.\nWork through the file following directions\nas indicated. Turn in your completed file on\nCollab.\n-/\n\n/-\n1. We've imported our definitions from our\nclass on basic algebraic structures, such as\nmonoid and group. Go learn what an algebraic\n*ring* is, define a typeclass that expresses\nits definition, and define an instance that\nexpresses the claim that the integers (ℤ or\n*int* in Lean) is a ring. You may \"stub out\"\nthe required proofs with *sorry*. \n-/\n\nopen alg \n\nset_option old_structure_cmd true\n\nuniverse u\n\nclass has_ring (α : Type u) \n  extends alg.add_comm_group α, mul_monoid α :=\n(dist_left : ∀ (a b c : α), \n  mul_groupoid.mul a (add_groupoid.add b c) = \n  add_groupoid.add (mul_groupoid.mul a b) (mul_groupoid.mul a c))\n(dist_right : ∀ (a b c : α), \n  mul_groupoid.mul (add_groupoid.add b c) a = \n  add_groupoid.add (mul_groupoid.mul b a) (mul_groupoid.mul c a))\n\naxioms (T : Type) (t_add : T → T → T) (t_mul : T → T → T)\n\n\n/-\n2. Go learn what an algebraic *field* is, then\ndefine a typeclass to formalize its definition,\nand finally define two instances that express\nthe claims that the rational numbers (ℚ) and \nthe real numbers (ℝ) are both fields. Again you\nmay (and should) stub out the proof fields in\nyour instances using sorry.\n-/\n\nclass has_field (α : Type u) extends has_ring α, mul_monoid α :=\n(mul_comm : ∀ (a b : α), mul_groupoid.mul a b = mul_groupoid.mul b a )\n(mul_inv : ∀ (a : α), (a ≠ alg.has_zero.zero) → ∃ (ainv : α), mul_groupoid.mul a ainv = alg.has_one.one)\n\ninstance has_field_rat : has_field ℚ := _\n\n/-\n3. Graduate students required. Undergrads extra\ncredit. Go figure out what an algebraic module is\nand write a typeclass to specify it formally. \nCreate an instance to implement the typeclass for\nthe integers (ℤ not ℕ). Stub out the proofs. In\nlieu of a formal proof, present a *brief informal*\n(in English) argument to convince your instructor\nthat the integers really do form a module under\nthe usual arithmetic operators.\n-/\n\n\n/-\n4. The set of (our representations of) natural\nnumbers is defined inductively. Here's how they\nare defined, copied straight from Lean's library.\n\ninductive nat\n| zero : nat\n| succ (n : nat) : nat\n\nComplete the following function definitions \nfor natural number addition, multiplication,\nand exponentiation. Write your own functions\nhere without using Lean's implementations \n(i.e., don't use nat.mul, *, etc). You may\nnot use + except as a shorthand for using \nthe nat.succ constructor to add one. If you\nneed to do addition of something other than\none, use your own add function. Similarly, if\nyou need to multiply, using your mul function.\n-/\n\ndef add : nat → nat → nat\n| 0 m         := m\n| (n' + 1) m  := nat.succ (add n' m)\n\ndef mul : nat → nat → nat\n| 0 m         := _\n| (n' + 1) m  := _ \n\n-- first arg raised to second\ndef exp : nat → nat → nat \n| n 0 := _\n| n (m'+1) := _\n\n#eval exp 2 10    -- expect 1024\n\n\n/-\n5. Many computations can be expressed \nas compositions of map and fold (also \nsometimes called reduce). For example,\nyou can compute the length of a list\nby mapping each element to the number,\n1, and by the folding the list under\nnatural number addition. A slightly \nmore interesting function counts the\nnumber of elements in a list that \nsatisfy some predicate (specified by\na boolean-returning function). \n\nA. Write a function, mul_map_reduce, that \ntakes (1) a function, f : α → β, where β\nmust be a monoid; and (2) a list, l, of\nobjects of type α; and that then uses f\nto map l to a list of objects of a type, \nβ, and that then does a fold on the list \nto reduce it to a final value of type β. \n\nBe sure to use a typeclass instance in \nspecifying the type of your function to \nensure that the only types that can serve\nas values of β have monoid structures.\nUse both our mul_monoid_foldr and fmap\nfunctions to implement your solution.\n-/\n\n-- Your answer here\n\n\n\n/-\nB. Complete the given application of \nmul_map_reduce with a lambda expression \nto compute the product of the non-zero \nvalues in the list \n[1,0,2,0,3,0,4].\n-/\n\n#eval mul_map_reduce  _ [1,0,2,0,3,0,4]\n-- expect 24\n\n/-\n6. Here you practice with type families.\n\nA. Define a family of types, each of which\nis index by two natural numbers, such that \neach type is inhabited if and only if the \ntwo natural numbers are equal. You may call\nyour type family nat_eql. Use implicit args\nwhen it makes the use of your type family\neasier. \n-/\n\ninductive nat_eql: nat → nat → Type\n| zeros_equal : nat_eql 0 0\n| n_succ_m_succ_equal : Π {n m : nat}, \n    nat_eql n m → nat_eql (n+1) (m+1)\n\n/-\nB. Now either complete the following programs\nor argue informally (and briefly) why that\nwon't be possible.\n-/\n\nopen nat_eql\n\ndef eq_0_0 : nat_eql 0 0 := zeros_equal\ndef eq_0_1 : nat_eql 0 1 := _\ndef eq_1_1 : nat_eql 1 1 := n_succ_m_succ_equal eq_0_0\ndef eq_2_2 : nat_eql 2 2 := n_succ_m_succ_equal (n_succ_m_succ_equal eq_0_0)\n\n/-\nC. The apply tactic in Lean's tactic language\nlet's you build the term you need by applying\nan already defined function. Moreover, you can\nleave holes (underscores) for the arguments and\nthose holes then become subgoals. In this way,\nusing tactics allows you to build a solution \nusing interactive, top-down, type-guided, aka\nstructured, programming! Show that eq_2_2 is\ninhabited using Lean's tactic language. We get\nyou started. Hint: remember the \"exact\" tactic. \nHint: Think *top down*. Write a single, simple\nexpression that provides a complete solution\n*except* for the holes that remain to be filled.\nThen recursively \"fill the holes\". Continue \nuntil you're done. Voila! \n-/\n\ndef eq_10_10 : nat_eql 10 10 :=\nbegin\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  apply n_succ_m_succ_equal,\n  exact eq_0_0,\nend\n\n/-\nIn Lean, \"repeat\" is a tactic that takes\nanother tactic as an argument (enclosed in\ncurly braces), applies it repeatedly until\nit fails, and leaves you in the resulting \ntactic state. Use the repeat tactic to \nshow that \"nat_eql 500 500\" is inhabited.\nIf you get a deterministic timeout, pick\nsmaller numbers, such as 100 and 100. It's\nok with us.\n-/\n\ndef eq_500_500 : nat_eql 500 500 :=\nbegin\n  repeat {apply n_succ_m_succ_equal},\n  exact eq_0_0,\nend\n\n#reduce eq_500_500\n\n\n/-\n7. Typeclasses and instances are used in Lean\nto implement *coercions*, also known as type\ncasts. \n\nAs in Java, C++, and many other languages,\ncoercions are automatically applied conversions\nof values of one type, α, to values of another \ntype, β, so that that values of type α can be\nused where values of type β are needed.\n\nFor example, in many languages you may use an \ninteger wherever a Boolean value is expected. \nThe conversion is typically from zero to false\nand from any non-zero value to true. \n\nHere's the has_coe (has coercion) typeclass as\ndefined in Lean's libraries. As you can see, a\ncoercion is really just a function, coe, from \none type to another, associated with the pair \nof those two types.\n\nclass has_coe (a : Sort u) (b : Sort v) :=\n(coe : a → b)\n\nA. We provide a simple function, needs_bool, \nthat takes a bool value and just returns it. \nYour job is to allow this function to be \napplied to any nat value by defining a new\ncoercion from nat to bool. \n\nFirst define a function, say nat_to_bool, that\nconverts any nat, n, to a bool, by the rule that\nzero goes to false and any other nat goes to tt. \nThen define an instance of the has_coe typeclass\nto enable coercions from nat to bool. You should\ncall it nat_to_bool_coe. When you're done the\ntest cases below should work.\n-/\n\ndef nat_to_bool : nat → bool :=\n_\n\ninstance nat_to_bool_coe : has_coe nat bool := \n_\n\ndef needs_bool : bool → bool := λ b, b\n\n-- Test cases\n#eval needs_bool (1:nat)  -- expect tt\n#eval needs_bool (0:nat)  -- expect ff\n\n\n/-\nNot only are coercions, when available, applied\nautomatically, but, with certain limitations, \nLean can also chain them automatically. Define \na second coercion called string_to_nat_coe, \nfrom string to nat, that will coerce any string\nto its length as a nat (using the string.length\nfunction). When you're done, you should be able\nto apply the needs_bool function to any string, \nwhere the empty string returns ff and non-empty, \ntt. \n-/\n\ninstance string_to_nat_coe : _ := \n_\n\n-- Test cases\n#eval needs_bool \"Hello\"  -- expect tt\n#eval needs_bool \"\"  -- expect ff\n\n/-\nDo you see how the coercions are being chained,\naka, composed, automatically?\n-/\n\n--  Good job!\n\nexample : 1 = 1 := \nbegin\n  exact (eq.refl 1),\nend\n\nexample : 1 = 1 := \nbegin\n  apply eq.refl _,\nend\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_6/assignment_6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7601662306564982}}
{"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-/\nimport number_theory.number_field.class_number\nimport ring_theory.dedekind_domain.factorization\n\nimport tactic\n\n/-\n\n# Factorization of ideals into primes\n\nThe correct generality to set up a theory of factorization of nonzero ideals into prime\nideals is to assume that the ground ring is a Dedekind domain.\n\n-/\n\nopen_locale number_field -- for 𝓞 K notation\n\n-- Lean knows that the integers of a number field are a Dedekind domain\n\nexample (K : Type) [field K] [number_field K] : is_dedekind_domain (𝓞 K) := infer_instance\n\n-- here's how to say \"let R be a Dedekind domain\"\n\nvariables (R : Type) [comm_ring R] [is_domain R] [is_dedekind_domain R]\n\nopen is_dedekind_domain\n\n/- \nThere's an entire directory of files `ring_theory.dedekind_domain` containing\nresults about Dedekind domains. There are still a few \"TODO\"s though; for\nexample `ring_theory.dedekind_domain.dvr` contains a definition which is\nknown to be equivalent to Dedekind domain, but this is not yet proved in mathlib.\n\n## Nonzero prime ideals of a Dedekind domain.\n\nHere's the definition of `is_dedekind_domain.height_one_spectrum`:\n\n```\nstructure height_one_spectrum :=\n(as_ideal : ideal R)\n(is_prime : as_ideal.is_prime)\n(ne_bot : as_ideal ≠ ⊥)\n```\n\nIt's the nonzero prime ideals of `R`. Because Dedekind domains are either fields or\n1-dimensional, `height_one_spectrum R` is either empty (if `R` is a field) or\nthe set of maximal ideals of `R`.\n\nA key result is that in any Dedekind domain, any nonzero ideal is contained\nin only finitely many maximal ideals.\n\n-/\n\nexample {I : ideal R} (hI : I ≠ 0) :\n  {v : height_one_spectrum R | v.as_ideal ∣ I}.finite := \nbegin\n  exact ideal.finite_factors hI,\nend\n\n-- Hence it makes sense to take a product over these factors. \n-- The theorem `ideal.finprod_height_one_spectrum_factorization`\n-- says that every nonzero ideal factors into primes.\n\nopen_locale big_operators\n\nexample (I : ideal R) (hI : I ≠ 0) :\n  ∏ᶠ (v : height_one_spectrum R), v.max_pow_dividing I = I :=\nbegin\n  exact ideal.finprod_height_one_spectrum_factorization I hI,\nend\n\n-- Furthermore the factorization is unique\nexample : unique_factorization_monoid (ideal R) := infer_instance\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/section19algebraic_number_theory/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7600894554705367}}
{"text": "import plane_separation_world.level04 --hide\nopen IncidencePlane --hide\n\nnoncomputable theory --hide\nopen_locale classical --hide\n\n/-\n# Plane Separation World\n\n## Level 5: on the way to the final level (II).\n\nThis is the second 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 three non-collinear points A, B and C, then B is not incident with the line through A and C.\n\n**Proof:**\n\nBy the lemma `noncollinear_ne_points`, since A, B and C are non-collinear points, then `A ≠ C`.\n\nBy the lemma `collinear_iff_on_line_through`, since `A ≠ C`, then it suffices to prove that the points A, C, B are not collinear. \n\nBy the assumption of the lemma `hCol : ¬ collinear ({A, C, B} : set Ω))`, then we show that `B ∉ line_through A C`.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nIf you have a theorem statement called `theorem1`, which shows `x` by using the hypothesis `h : P`, then `have htheorem := theorem1 h` will\nadd the hypothesis `htheorem : x` to the local context. 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 {Ω : Type} [IncidencePlane Ω] --hide\nvariables {A B C P Q R : Ω} --hide\nvariables {ℓ r s t : Line Ω} --hide\n\n/- Lemma :\nGiven three non-collinear points A, B and C, then B is not incident with the line through A and C.\n-/\nlemma noncollinear_ne_line (hCol : ¬ collinear ({A, C, B} : set Ω)) : B ∉ line_through A C :=\nbegin\n  have hAC := noncollinear_ne_points hCol,\n  rw ← collinear_iff_on_line_through hAC,\n  exact hCol,\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/level05.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7600894534823547}}
{"text": "#print \"------------------------------------------------\"\n#print \"Section 2.10 Exercises\"\n/- 1. Define the function =Do_twice=, as described in Section 2.4.-/\ndef Do_Twice : ((ℕ → ℕ) → (ℕ → ℕ)) → (ℕ → ℕ) → (ℕ → ℕ) :=\n                 λ (f: (ℕ → ℕ) → (ℕ → ℕ)) (g: ℕ → ℕ), f (f g)\n\n/- 2. Define the functions =curry= and =uncurry=, as described in Section 2.4. -/\n  def curry (α β γ : Type) (f : α × β → γ) : α → β → γ := \n         λ (x : α) (y : β), f (x, y)\n\n  def uncurry (α β γ : Type) (f : α → β → γ) : α × β → γ :=\n         λ (p : α × β), f p.1 p.2\n\n\n/- 3. We used the example =vec α n= for vectors of elements of type =α= of length =n=. \n      Declare a constant =vec_add= that could represent a function that adds two vectors \n      of natural numbers of the same length, and a constant =vec_reverse= that can represent \n      a function that reverses its argument. Use implicit arguments for parameters that can \n      be inferred. Declare some variables and check some expressions involving the constants \n      that you have declared. -/\n\nnamespace exercise3\n  universe u\n  constant vec : Type u → ℕ → Type u\n\n  namespace vec\n    constant empty : Π {α : Type u}, vec α 0\n    constant cons : Π {α : Type u} {n : ℕ}, α → vec α n → vec α (n + 1)\n    constant append : Π {α : Type u} {n m : ℕ},\n                    vec α n → vec α m → vec α (n + m)\n    constant add : Π {α : Type u} {n : ℕ}, vec α n → vec α n → vec α n\n    constant reverse : Π {α : Type u} {n : ℕ}, vec α n → vec α n\n  end vec\n\n  variable α : Type u\n  variable v : vec α 10\n  variable w : vec α 5\n  variable z : vec α 5\n\n-- (partial application types)\n  #check @vec.append α 10 5 v         -- vec α 5 → vec α (10 + 5)\n  #check @vec.append α 10 _ v         -- vec α ?M_1 → vec α (10 + ?M_1)\n\n  #check vec.append v w               -- vec α (10 + 5)\n  #check vec.add w z                  -- vec α 5\n  #check vec.add v (vec.append w z)   -- vec α 10\n\nend exercise3\n\n/- 4. Similarly, declare a constant =matrix= so that =matrix α m n= could represent the type \n      of =m= by =n= matrices. Declare some constants to represent functions on this type, \n      such as matrix addition and multiplication, and (using =vec=) multiplication of a \n      matrix by a vector. Once again, declare some variables and check some expressions \n      involving the constants that you have declared.  -/\nnamespace exercise4\n  universe u\n  constant matrix : Type u → ℕ → ℕ → Type u\n\n  namespace matrix \n    constant empty : Π {α : Type u}, matrix α 0 0\n    constant plus : Π {α : Type u} {m n : ℕ}, matrix α m n → matrix α m n → matrix α m n\n    constant prod : Π {α : Type u} {i k j : ℕ}, matrix α i k → matrix α k j → matrix α i j\n  end matrix\n\n  variables α β : Type u\n  variables M1 M2 : matrix α 2 3\n  variable M3 : matrix α 3 4\n  variable N3 : matrix β 3 4\n\n  #check matrix.plus M1 M2        -- matrix α 2 3\n  #check matrix.prod M2 M3        -- matrix α 2 4\n\n  -- #check matrix.plus M1 M3      -- (dimensions not compatible with plus)\n  -- #check matrix.prod M1 M2      -- (dimensions not compatible with prod)\n  -- #check matrix.prod M2 N3      -- (expected `matrix α 3 ?` but `N3 : matrix β 3 4`)\n\nend exercise4\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/02-dependent_types_exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7599828395636443}}
{"text": "/-\nCopyright (c) 2020 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel, Yury Kudryashov\n\n! This file was ported from Lean 3 source module analysis.calculus.fderiv_measurable\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.Calculus.Deriv\nimport Mathbin.MeasureTheory.Constructions.BorelSpace\nimport Mathbin.MeasureTheory.Function.StronglyMeasurable.Basic\nimport Mathbin.Tactic.RingExp\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 𝕜 f x}` is measurable;\n* `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable;\n* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `λ x, fderiv 𝕜 f x y`\n  is measurable;\n* `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → 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, ε)` 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 `ε r`. It is an open set.\nLet also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: 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 = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`.\nIn other words, for any `ε > 0`, we require that there is a size `δ` 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 `⋃ L, B (L, r, s, ε)` 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 `ε, 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, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus\n`‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps\n`L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, 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₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as\n`x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s`\nw.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is\nclose to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (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`ε` 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 σ-algebra\n-/\n\n\nnoncomputable section\n\nopen Set Metric Asymptotics Filter ContinuousLinearMap\n\nopen TopologicalSpace (SecondCountableTopology)\n\nopen MeasureTheory\n\nopen Topology\n\nnamespace ContinuousLinearMap\n\nvariable {𝕜 E F : Type _} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E]\n  [NormedAddCommGroup F] [NormedSpace 𝕜 F]\n\ntheorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E] [SecondCountableTopology E]\n    [SecondCountableTopology (E →L[𝕜] F)] [MeasurableSpace F] [BorelSpace F] :\n    Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 :=\n  isBoundedBilinearMapApply.Continuous.Measurable\n#align continuous_linear_map.measurable_apply₂ ContinuousLinearMap.measurable_apply₂\n\nend ContinuousLinearMap\n\nsection fderiv\n\nvariable {𝕜 : Type _} [NontriviallyNormedField 𝕜]\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace 𝕜 E]\n\nvariable {F : Type _} [NormedAddCommGroup F] [NormedSpace 𝕜 F]\n\nvariable {f : E → F} (K : Set (E →L[𝕜] F))\n\nnamespace FderivMeasurableAux\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (y z «expr ∈ » ball[metric.ball] x r') -/\n/-- The set `A f L r ε` 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 `ε`. We tweak the definition to make sure that\nthis is an open set.-/\ndef a (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E :=\n  { x |\n    ∃ r' ∈ Ioc (r / 2) r,\n      ∀ (y) (_ : y ∈ ball x r') (z) (_ : z ∈ ball x r'), ‖f z - f y - L (z - y)‖ ≤ ε * r }\n#align fderiv_measurable_aux.A FderivMeasurableAux.a\n\n/-- The set `B f K r s ε` 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 `ε`), simultaneously at scales `r` and `s`. -/\ndef b (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E :=\n  ⋃ L ∈ K, a f L r ε ∩ a f L s ε\n#align fderiv_measurable_aux.B FderivMeasurableAux.b\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 → F) (K : Set (E →L[𝕜] F)) : Set E :=\n  ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), b f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)\n#align fderiv_measurable_aux.D FderivMeasurableAux.d\n\ntheorem isOpen_a (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (a f L r ε) :=\n  by\n  rw [Metric.isOpen_iff]\n  rintro x ⟨r', r'_mem, hr'⟩\n  obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1\n  have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩\n  refine' ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, _⟩⟩\n  have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx')\n  intro y hy z hz\n  exact hr' y (B hy) z (B hz)\n#align fderiv_measurable_aux.is_open_A FderivMeasurableAux.isOpen_a\n\ntheorem isOpen_b {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (b f K r s ε) := by\n  simp [B, isOpen_unionᵢ, IsOpen.inter, is_open_A]\n#align fderiv_measurable_aux.is_open_B FderivMeasurableAux.isOpen_b\n\ntheorem a_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : a f L r ε ⊆ a f L r δ :=\n  by\n  rintro x ⟨r', r'r, hr'⟩\n  refine' ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)⟩\n  linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x]\n#align fderiv_measurable_aux.A_mono FderivMeasurableAux.a_mono\n\ntheorem le_of_mem_a {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ a f L r ε) {y z : E}\n    (hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) :\n    ‖f z - f y - L (z - y)‖ ≤ ε * r :=\n  by\n  rcases hx with ⟨r', r'mem, hr'⟩\n  exact hr' _ ((mem_closed_ball.1 hy).trans_lt r'mem.1) _ ((mem_closed_ball.1 hz).trans_lt r'mem.1)\n#align fderiv_measurable_aux.le_of_mem_A FderivMeasurableAux.le_of_mem_a\n\ntheorem mem_a_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) :\n    ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ a f (fderiv 𝕜 f x) r ε :=\n  by\n  have := hx.has_fderiv_at\n  simp only [HasFderivAt, HasFderivAtFilter, is_o_iff] at this\n  rcases eventually_nhds_iff_ball.1 (this (half_pos hε)) with ⟨R, R_pos, hR⟩\n  refine' ⟨R, R_pos, fun r hr => _⟩\n  have : r ∈ Ioc (r / 2) r := ⟨half_lt_self hr.1, le_rfl⟩\n  refine' ⟨r, this, fun y hy z hz => _⟩\n  calc\n    ‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ =\n        ‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ :=\n      by\n      congr 1\n      simp only [ContinuousLinearMap.map_sub]\n      abel\n    _ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ :=\n      (norm_sub_le _ _)\n    _ ≤ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ :=\n      (add_le_add (hR _ (lt_trans (mem_ball.1 hz) hr.2)) (hR _ (lt_trans (mem_ball.1 hy) hr.2)))\n    _ ≤ ε / 2 * r + ε / 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ε)))\n        (mul_le_mul_of_nonneg_left (le_of_lt (mem_ball_iff_norm.1 hy)) (le_of_lt (half_pos hε))))\n    _ = ε * r := by ring\n    \n#align fderiv_measurable_aux.mem_A_of_differentiable FderivMeasurableAux.mem_a_of_differentiable\n\ntheorem norm_sub_le_of_mem_a {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E}\n    {L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ a f L₁ r ε) (h₂ : x ∈ a f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε :=\n  by\n  have : 0 ≤ 4 * ‖c‖ * ε :=\n    mul_nonneg (mul_nonneg (by norm_num : (0 : ℝ) ≤ 4) (norm_nonneg _)) hε.le\n  refine' op_norm_le_of_shell (half_pos hr) this hc _\n  intro y ley ylt\n  rw [div_div, div_le_iff' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley\n  calc\n    ‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by\n      simp\n    _ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := (norm_sub_le _ _)\n    _ ≤ ε * r + ε * r := by\n      apply add_le_add\n      · apply le_of_mem_A h₂\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₁\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    _ = 2 * ε * r := by ring\n    _ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := (mul_le_mul_of_nonneg_left ley (mul_nonneg (by norm_num) hε.le))\n    _ = 4 * ‖c‖ * ε * ‖y‖ := by ring\n    \n#align fderiv_measurable_aux.norm_sub_le_of_mem_A FderivMeasurableAux.norm_sub_le_of_mem_a\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\ntheorem differentiable_set_subset_d : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ d f K :=\n  by\n  intro x hx\n  rw [D, mem_Inter]\n  intro e\n  have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _\n  rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩\n  obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)\n  simp only [mem_Union, mem_Inter, B, mem_inter_iff]\n  refine' ⟨n, fun p hp q hq => ⟨fderiv 𝕜 f x, hx.2, ⟨_, _⟩⟩⟩ <;>\n    · refine' hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt _ hn⟩\n      exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption)\n#align fderiv_measurable_aux.differentiable_set_subset_D FderivMeasurableAux.differentiable_set_subset_d\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\ntheorem d_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :\n    d f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } :=\n  by\n  have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := pow_pos (by norm_num)\n  rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩\n  have cpos : 0 < ‖c‖ := lt_trans zero_lt_one hc\n  intro x hx\n  have :\n    ∀ e : ℕ,\n      ∃ n : ℕ,\n        ∀ p q,\n          n ≤ p →\n            n ≤ q →\n              ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) :=\n    by\n    intro e\n    have := mem_Inter.1 hx e\n    rcases mem_Union.1 this with ⟨n, hn⟩\n    refine' ⟨n, fun p q hp hq => _⟩\n    simp only [mem_Inter, ge_iff_le] at hn\n    rcases mem_Union.1 (hn p hp q hq) with ⟨L, hL⟩\n    exact ⟨L, mem_Union.1 hL⟩\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 ≥ 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 :\n    ∀ e p q e' p' q',\n      n e ≤ p →\n        n e ≤ q →\n          n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e :=\n    by\n    intro e p q e' p' q' hp hq hp' hq' he'\n    let r := max (n e) (n e')\n    have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e :=\n      pow_le_pow_of_le_one (by norm_num) (by norm_num) he'\n    have J1 : ‖L e p q - L e p r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e :=\n      by\n      have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1\n      have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (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 : ‖L e p r - L e' p' r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e :=\n      by\n      have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2\n      have I2 : x ∈ 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 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e :=\n      by\n      have I1 : x ∈ 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 ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (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\n      ‖L e p q - L e' p' q'‖ =\n          ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ :=\n        by\n        congr 1\n        abel\n      _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ :=\n        (le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _))\n      _ ≤ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by\n        apply_rules [add_le_add]\n      _ = 12 * ‖c‖ * (1 / 2) ^ e := by ring\n      \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 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e)\n  have : CauchySeq L0 := by\n    rw [Metric.cauchySeq_iff']\n    intro ε εpos\n    obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) :=\n      exists_pow_lt_of_lt_one (div_pos εpos (mul_pos (by norm_num) cpos)) (by norm_num)\n    refine' ⟨e, fun e' he' => _⟩\n    rw [dist_comm, dist_eq_norm]\n    calc\n      ‖L0 e - L0 e'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      _ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) :=\n        (mul_lt_mul' le_rfl he (le_of_lt P) (mul_pos (by norm_num) cpos))\n      _ = ε := by\n        field_simp [(by norm_num : (12 : ℝ) ≠ 0), ne_of_gt cpos]\n        ring\n      \n  -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.\n  obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, tendsto L0 at_top (𝓝 f') :=\n    cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this\n  have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e :=\n    by\n    intro e p hp\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm\n    rw [eventually_at_top]\n    exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩\n  -- Let us show that `f` has derivative `f'` at `x`.\n  have : HasFderivAt f f' x :=\n    by\n    simp only [hasFderivAt_iff_isOCat_nhds_zero, is_o_iff]\n    /- to get an approximation with a precision `ε`, 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    intro ε εpos\n    have pos : 0 < 4 + 12 * ‖c‖ :=\n      add_pos_of_pos_of_nonneg (by norm_num) (mul_nonneg (by norm_num) (norm_nonneg _))\n    obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) :=\n      exists_pow_lt_of_lt_one (div_pos εpos Pos) (by norm_num)\n    rw [eventually_nhds_iff_ball]\n    refine' ⟨(1 / 2) ^ (n e + 1), P, fun y hy => _⟩\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 `‖y‖ ∼ 2 ^ (-k)`.\n    by_cases y_pos : y = 0\n    · simp [y_pos]\n    have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos\n    have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy\n    have yone : ‖y‖ ≤ 1 := le_trans y_lt.le (pow_le_one _ (by norm_num) (by norm_num))\n    -- define the scale `k`.\n    obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≤ (1 / 2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2)\n        (by norm_num : (1 : ℝ) / 2 < 1)\n    -- the scale is large enough (as `y` is small enough)\n    have k_gt : n e < k :=\n      by\n      have : ((1 : ℝ) / 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 : ℝ) < 1 / 2) (by norm_num)] at this\n      linarith\n    set m := k - 1 with hl\n    have m_ge : n e ≤ 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 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m :=\n      by\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      ·\n        simpa only [dist_eq_norm, add_sub_cancel', mem_closed_ball, pow_succ', mul_one_div] using\n          h'k\n    have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≤ 4 * (1 / 2) ^ e * ‖y‖ :=\n      calc\n        ‖f (x + y) - f x - L e (n e) m y‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by\n          simpa only [add_sub_cancel'] using J1\n        _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) :=\n          by\n          field_simp\n          ring\n        _ ≤ 4 * (1 / 2) ^ e * ‖y‖ :=\n          mul_le_mul_of_nonneg_left (le_of_lt hk) (mul_nonneg (by norm_num) (le_of_lt P))\n        \n    -- use the previous estimates to see that `f (x + y) - f x - f' y` is small.\n    calc\n      ‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ :=\n        congr_arg _ (by simp)\n      _ ≤ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ :=\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 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring\n      _ ≤ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) :=\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      _ = ε * ‖y‖ := by\n        field_simp [ne_of_gt Pos]\n        ring\n      \n  rw [← this.fderiv] at f'K\n  exact ⟨this.differentiable_at, f'K⟩\n#align fderiv_measurable_aux.D_subset_differentiable_set FderivMeasurableAux.d_subset_differentiable_set\n\ntheorem differentiable_set_eq_d (hK : IsComplete K) :\n    { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = d f K :=\n  Subset.antisymm (differentiable_set_subset_d _) (d_subset_differentiable_set hK)\n#align fderiv_measurable_aux.differentiable_set_eq_D FderivMeasurableAux.differentiable_set_eq_d\n\nend FderivMeasurableAux\n\nopen FderivMeasurableAux\n\nvariable [MeasurableSpace E] [OpensMeasurableSpace E]\n\nvariable (𝕜 f)\n\n/-- The set of differentiability points of a function, with derivative in a given complete set,\nis Borel-measurable. -/\ntheorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :\n    MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by\n  simp [differentiable_set_eq_D K hK, D, is_open_B.measurable_set, MeasurableSet.interᵢ,\n    MeasurableSet.unionᵢ]\n#align measurable_set_of_differentiable_at_of_is_complete measurableSet_of_differentiableAt_of_isComplete\n\nvariable [CompleteSpace F]\n\n/-- The set of differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } :=\n  by\n  have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ\n  convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this\n  simp\n#align measurable_set_of_differentiable_at measurableSet_of_differentiableAt\n\n@[measurability]\ntheorem measurable_fderiv : Measurable (fderiv 𝕜 f) :=\n  by\n  refine' measurable_of_isClosed fun s hs => _\n  have :\n    fderiv 𝕜 f ⁻¹' s =\n      { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪\n        { x | ¬DifferentiableAt 𝕜 f x } ∩ { x | (0 : E →L[𝕜] F) ∈ s } :=\n    Set.ext fun x => mem_preimage.trans fderiv_mem_iff\n  rw [this]\n  exact\n    (measurableSet_of_differentiableAt_of_isComplete _ _ hs.is_complete).union\n      ((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _))\n#align measurable_fderiv measurable_fderiv\n\n@[measurability]\ntheorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) :\n    Measurable fun x => fderiv 𝕜 f x y :=\n  (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f)\n#align measurable_fderiv_apply_const measurable_fderiv_apply_const\n\nvariable {𝕜}\n\n@[measurability]\ntheorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F]\n    [BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by\n  simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1\n#align measurable_deriv measurable_deriv\n\ntheorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜]\n    [SecondCountableTopology F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) :=\n  by\n  borelize F\n  exact (measurable_deriv f).StronglyMeasurable\n#align strongly_measurable_deriv stronglyMeasurable_deriv\n\ntheorem aeMeasurableDeriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F]\n    [BorelSpace F] (f : 𝕜 → F) (μ : Measure 𝕜) : AeMeasurable (deriv f) μ :=\n  (measurable_deriv f).AeMeasurable\n#align ae_measurable_deriv aeMeasurableDeriv\n\ntheorem aeStronglyMeasurableDeriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜]\n    [SecondCountableTopology F] (f : 𝕜 → F) (μ : Measure 𝕜) : AeStronglyMeasurable (deriv f) μ :=\n  (stronglyMeasurable_deriv f).AeStronglyMeasurable\n#align ae_strongly_measurable_deriv aeStronglyMeasurableDeriv\n\nend fderiv\n\nsection RightDeriv\n\nvariable {F : Type _} [NormedAddCommGroup F] [NormedSpace ℝ F]\n\nvariable {f : ℝ → F} (K : Set F)\n\nnamespace RightDerivMeasurableAux\n\n/- ./././Mathport/Syntax/Translate/Basic.lean:635:2: warning: expanding binder collection (y z «expr ∈ » Icc[set.Icc] x «expr + »(x, r')) -/\n/-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated\nat scale `r` by the linear map `h ↦ h • L`, up to an error `ε`. We tweak the definition to\nmake sure that this is open on the right. -/\ndef a (f : ℝ → F) (L : F) (r ε : ℝ) : Set ℝ :=\n  { x |\n    ∃ r' ∈ Ioc (r / 2) r,\n      ∀ (y) (_ : y ∈ Icc x (x + r')) (z) (_ : z ∈ Icc x (x + r')),\n        ‖f z - f y - (z - y) • L‖ ≤ ε * r }\n#align right_deriv_measurable_aux.A RightDerivMeasurableAux.a\n\n/-- The set `B f K r s ε` 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 • L` approximates well `f (x + h)`\n(up to an error `ε`), simultaneously at scales `r` and `s`. -/\ndef b (f : ℝ → F) (K : Set F) (r s ε : ℝ) : Set ℝ :=\n  ⋃ L ∈ K, a f L r ε ∩ a f L s ε\n#align right_deriv_measurable_aux.B RightDerivMeasurableAux.b\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 : ℝ → F) (K : Set F) : Set ℝ :=\n  ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), b f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)\n#align right_deriv_measurable_aux.D RightDerivMeasurableAux.d\n\ntheorem a_mem_nhdsWithin_Ioi {L : F} {r ε x : ℝ} (hx : x ∈ a f L r ε) : a f L r ε ∈ 𝓝[>] x :=\n  by\n  rcases hx with ⟨r', rr', hr'⟩\n  rw [mem_nhdsWithin_Ioi_iff_exists_Ioo_subset]\n  obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between rr'.1\n  have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le rr'.2)⟩\n  refine'\n    ⟨x + r' - s, by\n      simp only [mem_Ioi]\n      linarith, fun x' hx' => ⟨s, this, _⟩⟩\n  have A : Icc x' (x' + s) ⊆ Icc x (x + r') :=\n    by\n    apply Icc_subset_Icc hx'.1.le\n    linarith [hx'.2]\n  intro y hy z hz\n  exact hr' y (A hy) z (A hz)\n#align right_deriv_measurable_aux.A_mem_nhds_within_Ioi RightDerivMeasurableAux.a_mem_nhdsWithin_Ioi\n\ntheorem b_mem_nhdsWithin_Ioi {K : Set F} {r s ε x : ℝ} (hx : x ∈ b f K r s ε) :\n    b f K r s ε ∈ 𝓝[>] x :=\n  by\n  obtain ⟨L, LK, hL₁, hL₂⟩ : ∃ L : F, L ∈ K ∧ x ∈ A f L r ε ∧ x ∈ A f L s ε := by\n    simpa only [B, mem_Union, mem_inter_iff, exists_prop] using hx\n  filter_upwards [A_mem_nhds_within_Ioi hL₁, A_mem_nhds_within_Ioi hL₂]with y hy₁ hy₂\n  simp only [B, mem_Union, mem_inter_iff, exists_prop]\n  exact ⟨L, LK, hy₁, hy₂⟩\n#align right_deriv_measurable_aux.B_mem_nhds_within_Ioi RightDerivMeasurableAux.b_mem_nhdsWithin_Ioi\n\ntheorem measurableSet_b {K : Set F} {r s ε : ℝ} : MeasurableSet (b f K r s ε) :=\n  measurableSet_of_mem_nhdsWithin_Ioi fun x hx => b_mem_nhdsWithin_Ioi hx\n#align right_deriv_measurable_aux.measurable_set_B RightDerivMeasurableAux.measurableSet_b\n\ntheorem a_mono (L : F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : a f L r ε ⊆ a f L r δ :=\n  by\n  rintro x ⟨r', r'r, hr'⟩\n  refine' ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h _)⟩\n  linarith [hy.1, hy.2, r'r.2]\n#align right_deriv_measurable_aux.A_mono RightDerivMeasurableAux.a_mono\n\ntheorem le_of_mem_a {r ε : ℝ} {L : F} {x : ℝ} (hx : x ∈ a f L r ε) {y z : ℝ}\n    (hy : y ∈ Icc x (x + r / 2)) (hz : z ∈ Icc x (x + r / 2)) : ‖f z - f y - (z - y) • L‖ ≤ ε * r :=\n  by\n  rcases hx with ⟨r', r'mem, hr'⟩\n  have A : x + r / 2 ≤ x + r' := by linarith [r'mem.1]\n  exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz)\n#align right_deriv_measurable_aux.le_of_mem_A RightDerivMeasurableAux.le_of_mem_a\n\ntheorem mem_a_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : ℝ}\n    (hx : DifferentiableWithinAt ℝ f (Ici x) x) :\n    ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ a f (derivWithin f (Ici x) x) r ε :=\n  by\n  have := hx.has_deriv_within_at\n  simp_rw [hasDerivWithinAt_iff_isOCat, is_o_iff] at this\n  rcases mem_nhdsWithin_Ici_iff_exists_Ico_subset.1 (this (half_pos hε)) with ⟨m, xm, hm⟩\n  refine' ⟨m - x, by linarith [show x < m from xm], fun r hr => _⟩\n  have : r ∈ Ioc (r / 2) r := ⟨half_lt_self hr.1, le_rfl⟩\n  refine' ⟨r, this, fun y hy z hz => _⟩\n  calc\n    ‖f z - f y - (z - y) • derivWithin f (Ici x) x‖ =\n        ‖f z - f x - (z - x) • derivWithin f (Ici x) x -\n            (f y - f x - (y - x) • derivWithin f (Ici x) x)‖ :=\n      by\n      congr 1\n      simp only [sub_smul]\n      abel\n    _ ≤\n        ‖f z - f x - (z - x) • derivWithin f (Ici x) x‖ +\n          ‖f y - f x - (y - x) • derivWithin f (Ici x) x‖ :=\n      (norm_sub_le _ _)\n    _ ≤ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ :=\n      (add_le_add (hm ⟨hz.1, hz.2.trans_lt (by linarith [hr.2])⟩)\n        (hm ⟨hy.1, hy.2.trans_lt (by linarith [hr.2])⟩))\n    _ ≤ ε / 2 * r + ε / 2 * r := by\n      apply add_le_add\n      · apply mul_le_mul_of_nonneg_left _ (le_of_lt (half_pos hε))\n        rw [Real.norm_of_nonneg] <;> linarith [hz.1, hz.2]\n      · apply mul_le_mul_of_nonneg_left _ (le_of_lt (half_pos hε))\n        rw [Real.norm_of_nonneg] <;> linarith [hy.1, hy.2]\n    _ = ε * r := by ring\n    \n#align right_deriv_measurable_aux.mem_A_of_differentiable RightDerivMeasurableAux.mem_a_of_differentiable\n\ntheorem norm_sub_le_of_mem_a {r x : ℝ} (hr : 0 < r) (ε : ℝ) {L₁ L₂ : F} (h₁ : x ∈ a f L₁ r ε)\n    (h₂ : x ∈ a f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ε :=\n  by\n  suffices H : ‖(r / 2) • (L₁ - L₂)‖ ≤ r / 2 * (4 * ε)\n  · rwa [norm_smul, Real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H\n  calc\n    ‖(r / 2) • (L₁ - L₂)‖ =\n        ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂ -\n            (f (x + r / 2) - f x - (x + r / 2 - x) • L₁)‖ :=\n      by simp [smul_sub]\n    _ ≤\n        ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂‖ +\n          ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₁‖ :=\n      (norm_sub_le _ _)\n    _ ≤ ε * r + ε * r := by\n      apply add_le_add\n      · apply le_of_mem_A h₂ <;> simp [(half_pos hr).le]\n      · apply le_of_mem_A h₁ <;> simp [(half_pos hr).le]\n    _ = r / 2 * (4 * ε) := by ring\n    \n#align right_deriv_measurable_aux.norm_sub_le_of_mem_A RightDerivMeasurableAux.norm_sub_le_of_mem_a\n\n/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/\ntheorem differentiable_set_subset_d :\n    { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } ⊆ d f K :=\n  by\n  intro x hx\n  rw [D, mem_Inter]\n  intro e\n  have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _\n  rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩\n  obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=\n    exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)\n  simp only [mem_Union, mem_Inter, B, mem_inter_iff]\n  refine' ⟨n, fun p hp q hq => ⟨derivWithin f (Ici x) x, hx.2, ⟨_, _⟩⟩⟩ <;>\n    · refine' hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt _ hn⟩\n      exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption)\n#align right_deriv_measurable_aux.differentiable_set_subset_D RightDerivMeasurableAux.differentiable_set_subset_d\n\n/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/\ntheorem d_subset_differentiable_set {K : Set F} (hK : IsComplete K) :\n    d f K ⊆ { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } :=\n  by\n  have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := pow_pos (by norm_num)\n  intro x hx\n  have :\n    ∀ e : ℕ,\n      ∃ n : ℕ,\n        ∀ p q,\n          n ≤ p →\n            n ≤ q →\n              ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) :=\n    by\n    intro e\n    have := mem_Inter.1 hx e\n    rcases mem_Union.1 this with ⟨n, hn⟩\n    refine' ⟨n, fun p q hp hq => _⟩\n    simp only [mem_Inter, ge_iff_le] at hn\n    rcases mem_Union.1 (hn p hp q hq) with ⟨L, hL⟩\n    exact ⟨L, mem_Union.1 hL⟩\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 ≥ 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 :\n    ∀ e p q e' p' q',\n      n e ≤ p →\n        n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * (1 / 2) ^ e :=\n    by\n    intro e p q e' p' q' hp hq hp' hq' he'\n    let r := max (n e) (n e')\n    have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e :=\n      pow_le_pow_of_le_one (by norm_num) (by norm_num) he'\n    have J1 : ‖L e p q - L e p r‖ ≤ 4 * (1 / 2) ^ e :=\n      by\n      have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1\n      have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1\n      exact norm_sub_le_of_mem_A P _ I1 I2\n    have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * (1 / 2) ^ e :=\n      by\n      have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2\n      have I2 : x ∈ 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 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * (1 / 2) ^ e :=\n      by\n      have I1 : x ∈ 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 ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (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\n      ‖L e p q - L e' p' q'‖ =\n          ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ :=\n        by\n        congr 1\n        abel\n      _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ :=\n        (le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _))\n      _ ≤ 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e := by apply_rules [add_le_add]\n      _ = 12 * (1 / 2) ^ e := by ring\n      \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 : ℕ → F := fun e => L e (n e) (n e)\n  have : CauchySeq L0 := by\n    rw [Metric.cauchySeq_iff']\n    intro ε εpos\n    obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 12 :=\n      exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num)\n    refine' ⟨e, fun e' he' => _⟩\n    rw [dist_comm, dist_eq_norm]\n    calc\n      ‖L0 e - L0 e'‖ ≤ 12 * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'\n      _ < 12 * (ε / 12) := (mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num))\n      _ = ε := by\n        field_simp [(by norm_num : (12 : ℝ) ≠ 0)]\n        ring\n      \n  -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.\n  obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, tendsto L0 at_top (𝓝 f') :=\n    cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this\n  have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * (1 / 2) ^ e :=\n    by\n    intro e p hp\n    apply le_of_tendsto (tendsto_const_nhds.sub hf').norm\n    rw [eventually_at_top]\n    exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩\n  -- Let us show that `f` has right derivative `f'` at `x`.\n  have : HasDerivWithinAt f f' (Ici x) x :=\n    by\n    simp only [hasDerivWithinAt_iff_isOCat, is_o_iff]\n    /- to get an approximation with a precision `ε`, 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    intro ε εpos\n    obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 16 :=\n      exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num)\n    have xmem : x ∈ Ico x (x + (1 / 2) ^ (n e + 1)) := by\n      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_nhdsWithin_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 `‖y - x‖ ∼ 2 ^ (-k)`.\n    rcases eq_or_lt_of_le hy.1 with (rfl | xy)\n    · simp only [sub_self, zero_smul, norm_zero, MulZeroClass.mul_zero]\n    have yzero : 0 < y - x := sub_pos.2 xy\n    have y_le : y - x ≤ (1 / 2) ^ (n e + 1) := by linarith [hy.2]\n    have yone : y - x ≤ 1 := le_trans y_le (pow_le_one _ (by norm_num) (by norm_num))\n    -- define the scale `k`.\n    obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < y - x ∧ y - x ≤ (1 / 2) ^ k :=\n      exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2)\n        (by norm_num : (1 : ℝ) / 2 < 1)\n    -- the scale is large enough (as `y - x` is small enough)\n    have k_gt : n e < k :=\n      by\n      have : ((1 : ℝ) / 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 : ℝ) < 1 / 2) (by norm_num)] at this\n      linarith\n    set m := k - 1 with hl\n    have m_ge : n e ≤ 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 : ‖f y - f x - (y - x) • L e (n e) m‖ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ :=\n      calc\n        ‖f y - f x - (y - x) • L e (n e) m‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m :=\n          by\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_iff, one_div, pow_one] using h'k\n        _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) :=\n          by\n          field_simp\n          ring\n        _ ≤ 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 * ‖y - x‖ := by rw [Real.norm_of_nonneg yzero.le]\n        \n    calc\n      ‖f y - f x - (y - x) • f'‖ =\n          ‖f y - f x - (y - x) • L e (n e) m + (y - x) • (L e (n e) m - f')‖ :=\n        by simp only [smul_sub, sub_add_sub_cancel]\n      _ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ + ‖y - x‖ * (12 * (1 / 2) ^ e) :=\n        (norm_add_le_of_le J\n          (by\n            rw [norm_smul]\n            exact mul_le_mul_of_nonneg_left (Lf' _ _ m_ge) (norm_nonneg _)))\n      _ = 16 * ‖y - x‖ * (1 / 2) ^ e := by ring\n      _ ≤ 16 * ‖y - x‖ * (ε / 16) :=\n        (mul_le_mul_of_nonneg_left he.le (mul_nonneg (by norm_num) (norm_nonneg _)))\n      _ = ε * ‖y - x‖ := by ring\n      \n  rw [← this.deriv_within (uniqueDiffOn_Ici x x le_rfl)] at f'K\n  exact ⟨this.differentiable_within_at, f'K⟩\n#align right_deriv_measurable_aux.D_subset_differentiable_set RightDerivMeasurableAux.d_subset_differentiable_set\n\ntheorem differentiable_set_eq_d (hK : IsComplete K) :\n    { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } = d f K :=\n  Subset.antisymm (differentiable_set_subset_d _) (d_subset_differentiable_set hK)\n#align right_deriv_measurable_aux.differentiable_set_eq_D RightDerivMeasurableAux.differentiable_set_eq_d\n\nend RightDerivMeasurableAux\n\nopen RightDerivMeasurableAux\n\nvariable (f)\n\n/-- The set of right differentiability points of a function, with derivative in a given complete\nset, is Borel-measurable. -/\ntheorem measurableSet_of_differentiableWithinAt_Ici_of_isComplete {K : Set F} (hK : IsComplete K) :\n    MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by\n  simp [differentiable_set_eq_D K hK, D, measurable_set_B, MeasurableSet.interᵢ,\n    MeasurableSet.unionᵢ]\n#align measurable_set_of_differentiable_within_at_Ici_of_is_complete measurableSet_of_differentiableWithinAt_Ici_of_isComplete\n\nvariable [CompleteSpace F]\n\n/-- The set of right differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurableSet_of_differentiableWithinAt_Ici :\n    MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x } :=\n  by\n  have : IsComplete (univ : Set F) := complete_univ\n  convert measurableSet_of_differentiableWithinAt_Ici_of_isComplete f this\n  simp\n#align measurable_set_of_differentiable_within_at_Ici measurableSet_of_differentiableWithinAt_Ici\n\n@[measurability]\ntheorem measurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] :\n    Measurable fun x => derivWithin f (Ici x) x :=\n  by\n  refine' measurable_of_isClosed fun s hs => _\n  have :\n    (fun x => derivWithin f (Ici x) x) ⁻¹' s =\n      { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ s } ∪\n        { x | ¬DifferentiableWithinAt ℝ f (Ici x) x } ∩ { x | (0 : F) ∈ s } :=\n    Set.ext fun x => mem_preimage.trans derivWithin_mem_iff\n  rw [this]\n  exact\n    (measurableSet_of_differentiableWithinAt_Ici_of_isComplete _ hs.is_complete).union\n      ((measurableSet_of_differentiableWithinAt_Ici _).compl.inter (MeasurableSet.const _))\n#align measurable_deriv_within_Ici measurable_derivWithin_Ici\n\ntheorem stronglyMeasurable_derivWithin_Ici [SecondCountableTopology F] :\n    StronglyMeasurable fun x => derivWithin f (Ici x) x :=\n  by\n  borelize F\n  exact (measurable_derivWithin_Ici f).StronglyMeasurable\n#align strongly_measurable_deriv_within_Ici stronglyMeasurable_derivWithin_Ici\n\ntheorem aeMeasurableDerivWithinIci [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) :\n    AeMeasurable (fun x => derivWithin f (Ici x) x) μ :=\n  (measurable_derivWithin_Ici f).AeMeasurable\n#align ae_measurable_deriv_within_Ici aeMeasurableDerivWithinIci\n\ntheorem aeStronglyMeasurableDerivWithinIci [SecondCountableTopology F] (μ : Measure ℝ) :\n    AeStronglyMeasurable (fun x => derivWithin f (Ici x) x) μ :=\n  (stronglyMeasurable_derivWithin_Ici f).AeStronglyMeasurable\n#align ae_strongly_measurable_deriv_within_Ici aeStronglyMeasurableDerivWithinIci\n\n/-- The set of right differentiability points of a function taking values in a complete space is\nBorel-measurable. -/\ntheorem measurableSet_of_differentiableWithinAt_Ioi :\n    MeasurableSet { x | DifferentiableWithinAt ℝ f (Ioi x) x } := by\n  simpa [differentiableWithinAt_Ioi_iff_Ici] using measurableSet_of_differentiableWithinAt_Ici f\n#align measurable_set_of_differentiable_within_at_Ioi measurableSet_of_differentiableWithinAt_Ioi\n\n@[measurability]\ntheorem measurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] :\n    Measurable fun x => derivWithin f (Ioi x) x := by\n  simpa [derivWithin_Ioi_eq_Ici] using measurable_derivWithin_Ici f\n#align measurable_deriv_within_Ioi measurable_derivWithin_Ioi\n\ntheorem stronglyMeasurable_derivWithin_Ioi [SecondCountableTopology F] :\n    StronglyMeasurable fun x => derivWithin f (Ioi x) x :=\n  by\n  borelize F\n  exact (measurable_derivWithin_Ioi f).StronglyMeasurable\n#align strongly_measurable_deriv_within_Ioi stronglyMeasurable_derivWithin_Ioi\n\ntheorem aeMeasurableDerivWithinIoi [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) :\n    AeMeasurable (fun x => derivWithin f (Ioi x) x) μ :=\n  (measurable_derivWithin_Ioi f).AeMeasurable\n#align ae_measurable_deriv_within_Ioi aeMeasurableDerivWithinIoi\n\ntheorem aeStronglyMeasurableDerivWithinIoi [SecondCountableTopology F] (μ : Measure ℝ) :\n    AeStronglyMeasurable (fun x => derivWithin f (Ioi x) x) μ :=\n  (stronglyMeasurable_derivWithin_Ioi f).AeStronglyMeasurable\n#align ae_strongly_measurable_deriv_within_Ioi aeStronglyMeasurableDerivWithinIoi\n\nend RightDeriv\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/FderivMeasurable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7599828327448859}}
{"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 types\n\nAs well as finite subsets of a (possibly infinite type), Lean has a theory\nof finite types. Just like finite subsets, there is a `Prop`-valued version\n(the true-false statement \"this type is finite\") and a `Type`-valued version \n(\"here is an explicit list of all the finitely many terms of this type\").\nIf you want to work constructively, then use the `Type` version, and if\nyou just care about theorems you can use the `Prop` version.\n\n## The Prop-valued version\n\nIf `(X : Type)` then `finite X` is the true-false statement saying\nthat `X` is finite. It's a class, which means it goes in square brackets.\n\n-/\n\nsection prop_version\n\n-- Let X be a finite type\nvariables (X : Type) [finite X]\n\n-- The typeclass inference system now knows that various other types are finite:\n\nvariables (Y : Type) [finite Y]\n\nexample : finite (X × Y) := infer_instance\nexample : finite (X → Y) := infer_instance\n\n-- The type `fin n` is a structure. To make a term of this structure\n-- you need to give a natural `a`, and a proof that `a < n`.\n\nexample : fin 37 := ⟨3, by linarith⟩\n\n-- The typeclass inference system also knows that these are finite\n\nexample : finite (fin 37) := infer_instance\n\nend prop_version\n\n/-\n\n## The Type-valued version\n\nThis is `[fintype X]`. It's (in my opinion) harder to use, but finite sums work\nfor it, and they don't appear to work for `finite`.\n\n-/\n\n-- Let X be a constructively finite type\nvariables (X : Type) [fintype X]\n\nexample : X = X :=\nbegin\n  -- _inst_1 : fintype X\n  unfreezingI {cases _inst_1 }, -- it's a finset under the hood, plus a proof\n  -- that everything is in it!\n  refl,\nend\n\n-- Lean knows that `fin n` is constructively finite\nexample (n : ℕ) : fintype (fin n) := infer_instance \n\nopen_locale big_operators\n\n-- the advantage of constructive finiteness is that the elements are internally stored\n-- as a list, so you can prove this with `refl`\nexample : ∑ x : fin 10, x = 45 :=\nbegin\n  refl,\nend\n\n-- Actually I just tricked you. Can you explain this?\nexample : ∑ x : fin 10, x = 25 :=\nbegin\n  refl,\nend\n\n-- Here's a better proof\nexample : ∑ x : fin 10, x.val = 45 :=\nbegin\n  refl\nend\n-- Take a look at the types of the 45 in those proof. Do you know how to? Do you know\n-- what's going on? Hint: ℤ/10ℤ.\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/section08finiteness/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7599828256497286}}
{"text": "import tutorial_world.level11_cases2_or --hide\nopen set IncidencePlane --hide\n\nvariables {Ω : Type} [IncidencePlane Ω] --hide\n\n/-\n# Tutorial World \n\n## Level 12: the `cases` tactic (III) (boss level).\n\nSuppose now that your hypothesis says there is some element `x` satisfying a certain\nproperty `P`. That is, you have `h : ∃ x, P x`. Then `cases h with z hz` will\nreplace `h` with `z : x` and `hz : P z`. That is, from the fact that you assume that\nsome `z` exists (`z : x`), it will give you another hypothesis in which `z` satisfies the \nproperty `P` (`hz : P z`).\n\nLet's try to understand this with a real life example! Say that we have the hypothesis \n`h: ∃ GALAXY, SOLAR_SYSTEM GALAXY`. That is, **there exists a GALAXY such that \"SOLAR_SYSTEM\" is an element of \"GALAXY\"**. \nThen, `cases h with MILKY_WAY hMILKY_WAY` will break `h` into two goals:\n`MILKY_WAY : GALAXY`, which is read as **the \"MILKY_WAY\" is a term of the type \"GALAXY\"**, and\n`hMILKY_WAY : SOLAR_SYSTEM MILKY_WAY, which is read as **the hypothesis hMILKY_WAY assumes that \"SOLAR_SYSTEM\"\nis an element of the \"MILKY_WAY\"**. Is it better for you now? [**Tip:** Whenever you don't\nunderstand an abstract concept, try to apply a real life example to it.]\n\nNow, let's try to solve this level! From now on, it will be better if we start by reading the lemma \nas many times as we need to understand it. Then, do a drawing of the situation. In this way, we can\nthink of a clearer path to close the goal. Once you feel ready, delete the `sorry` and take a look \nto the hypothesis h1 and h2. As you may be thinking, we can apply the `cases` tactic to them. Following\nthe guiding thread of the real life example, we need to think about a specific line for each of them. \nIn geometry, lines are usually represented by the letters `r` and `s`. Then, type `cases h1 with r hr,`, \nclick on enter, and write `cases h2 with s hs,`. If you look at the local context, you'll see that we've\nassumed that `r` and `s`are lines in the plane Ω. \n\nRight after, it comes the genius idea. After reading the lemmma and trying to do a draw that represents\nthe situation, you should be wondering if we could create a hypothesis to state that the lines we've just\nadded to the local context are the same (`r = s`). Do you remember how we could add a hypothesis? Exactly, \nthe `have` tactic will do it for us! Now, type `have H : r = s,` (don't forget the comma).  \n\nSubsequently, we will have to prove two goals. First, try to look for a theorem statement that might help us \nto close the `⊢ r = s` goal. Can you see that `equal_lines_of_contain_two_points` ends with exactly the `r = s`\nstatement? Then, try to look if we have all the previous implications of this statement in the local context of \nthis level. If so, why don't we use the `exact` tactic? [**Pro tip:** Whenever we have a hypothesis of the form\n`h : P ∧ Q ∧ R`, we write `h.1` to refer to `P` and we type `h.2` to refer to `Q ∧ 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`. With that being said, \nyou can solve the first goal! \n\nWhen it comes to the second goal, you should remember what tactic comes handy for solving goals of the form\n`⊢ ∃ x, P x`. Once you have it mind, try to use it with the hypotheses `r` or `s`. From there, some `split`'s, `exact`'s \nand a `rewrite` will close the goal.\n\n-/\n\n/- Hint : Click here for a hint, in case you get stuck.\nThe tactic that comes handy for solving goals of the form `⊢ ∃ x, P x` is the `use` tactic. Type `use r,` and note how the goal \nchanges. Now, `split` will break the proof into different goals. Try to close with the `exact` tactic. You may need to use `rw` before\nwriting the last `exact` that will take you home. Bewildered? Click on \"View source\" (located on the top right corner of the game screen) to see the solution. \n-/\n\n\n/- Lemma : no-side-bar\nGiven 4 distinct points that pass through a line, then that line passes through two different subsets of three points.\n-/\nlemma exists_line_example (P Q R S : Ω) (h : Q ≠ R) (h1 : ∃ ℓ : Line Ω, P ∈ ℓ ∧ Q ∈ ℓ ∧ R ∈ ℓ)\n(h2 : ∃ ℓ : Line Ω, Q ∈ ℓ ∧ R ∈ ℓ ∧ S ∈ ℓ) :\n∃ ℓ : Line Ω, P ∈ ℓ ∧ Q ∈ ℓ ∧ R ∈ ℓ ∧ S ∈ ℓ :=\nbegin\n\n  cases h1 with r hr,\n  cases h2 with s hs,\n  have H : r = s,\n  {\n    exact equal_lines_of_contain_two_points h hr.2.1 hs.1 hr.2.2 hs.2.1,\n  },\n  use r,\n  split,\n  exact hr.1,\n  split,\n  exact hr.2.1,\n  split,\n  exact hr.2.2,\n  rw H,\n  exact hs.2.2,\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/level12_cases3_exists.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7599765356015783}}
{"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\n! This file was ported from Lean 3 source module data.mv_polynomial.supported\n! leanprover-community/mathlib commit a26d17fcd679e43d380d0583b33c9eca5359d41e\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Data.MvPolynomial.Variables\n\n/-!\n# Polynomials supported by a set of variables\n\nThis file contains the definition and lemmas about `MvPolynomial.supported`.\n\n## Main definitions\n\n* `MvPolynomial.supported` : Given a set `s : Set σ`, `supported R s` is the subalgebra of\n  `MvPolynomial σ R` consisting of polynomials whose set of variables is contained in `s`.\n  This subalgebra is isomorphic to `MvPolynomial s R`.\n\n## Tags\nvariables, polynomial, vars\n-/\n\n\nuniverse u v w\n\nnamespace MvPolynomial\n\nvariable {σ τ : Type _} {R : Type u} {S : Type v} {r : R} {e : ℕ} {n m : σ}\n\nsection CommSemiring\n\nvariable [CommSemiring R] {p q : MvPolynomial σ R}\n\nvariable (R)\n\n/-- The set of polynomials whose variables are contained in `s` as a `Subalgebra` over `R`. -/\nnoncomputable def supported (s : Set σ) : Subalgebra R (MvPolynomial σ R) :=\n  Algebra.adjoin R (X '' s)\n#align mv_polynomial.supported MvPolynomial.supported\n\nvariable {R}\n\nopen Classical\n\nopen Algebra\n\ntheorem supported_eq_range_rename (s : Set σ) : supported R s = (rename ((↑) : s → σ)).range := by\n  rw [supported, Set.image_eq_range, adjoin_range_eq_range_aeval, rename]\n  congr\n#align mv_polynomial.supported_eq_range_rename MvPolynomial.supported_eq_range_rename\n\n/-- The isomorphism between the subalgebra of polynomials supported by `s` and `MvPolynomial s R`.-/\nnoncomputable def supportedEquivMvPolynomial (s : Set σ) : supported R s ≃ₐ[R] MvPolynomial s R :=\n  (Subalgebra.equivOfEq _ _ (supported_eq_range_rename s)).trans\n    (AlgEquiv.ofInjective (rename ((↑) : s → σ)) (rename_injective _ Subtype.val_injective)).symm\n#align mv_polynomial.supported_equiv_mv_polynomial MvPolynomial.supportedEquivMvPolynomial\n\n@[simp]\ntheorem supportedEquivMvPolynomial_symm_C (s : Set σ) (x : R) :\n    (supportedEquivMvPolynomial s).symm (C x) = algebraMap R (supported R s) x := by\n  ext1\n  simp [supportedEquivMvPolynomial, MvPolynomial.algebraMap_eq]\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.supported_equiv_mv_polynomial_symm_C MvPolynomial.supportedEquivMvPolynomial_symm_C\n\n@[simp]\ntheorem supportedEquivMvPolynomial_symm_X (s : Set σ) (i : s) :\n    (↑((supportedEquivMvPolynomial s).symm (X i : MvPolynomial s R)) : MvPolynomial σ R) = X ↑i :=\n  by simp [supportedEquivMvPolynomial]\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.supported_equiv_mv_polynomial_symm_X MvPolynomial.supportedEquivMvPolynomial_symm_X\n\nvariable {s t : Set σ}\n\ntheorem mem_supported : p ∈ supported R s ↔ ↑p.vars ⊆ s := by\n  rw [supported_eq_range_rename, AlgHom.mem_range]\n  constructor\n  · rintro ⟨p, rfl⟩\n    refine' _root_.trans (Finset.coe_subset.2 (vars_rename _ _)) _\n    simp\n  · intro hs\n    exact exists_rename_eq_of_vars_subset_range p ((↑) : s → σ) Subtype.val_injective (by simpa)\n#align mv_polynomial.mem_supported MvPolynomial.mem_supported\n\ntheorem supported_eq_vars_subset : (supported R s : Set (MvPolynomial σ R)) = { p | ↑p.vars ⊆ s } :=\n  Set.ext fun _ ↦ mem_supported\n#align mv_polynomial.supported_eq_vars_subset MvPolynomial.supported_eq_vars_subset\n\n@[simp]\ntheorem mem_supported_vars (p : MvPolynomial σ R) : p ∈ supported R (↑p.vars : Set σ) := by\n  rw [mem_supported]\n#align mv_polynomial.mem_supported_vars MvPolynomial.mem_supported_vars\n\nvariable (s)\n\ntheorem supported_eq_adjoin_X : supported R s = Algebra.adjoin R (X '' s) := rfl\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.supported_eq_adjoin_X MvPolynomial.supported_eq_adjoin_X\n\n@[simp]\ntheorem supported_univ : supported R (Set.univ : Set σ) = ⊤ := by\n  simp [Algebra.eq_top_iff, mem_supported]\n#align mv_polynomial.supported_univ MvPolynomial.supported_univ\n\n@[simp]\ntheorem supported_empty : supported R (∅ : Set σ) = ⊥ := by simp [supported_eq_adjoin_X]\n#align mv_polynomial.supported_empty MvPolynomial.supported_empty\n\nvariable {s}\n\ntheorem supported_mono (st : s ⊆ t) : supported R s ≤ supported R t :=\n  Algebra.adjoin_mono (Set.image_subset _ st)\n#align mv_polynomial.supported_mono MvPolynomial.supported_mono\n\n@[simp]\ntheorem X_mem_supported [Nontrivial R] {i : σ} : X i ∈ supported R s ↔ i ∈ s := by\n  simp [mem_supported]\nset_option linter.uppercaseLean3 false in\n#align mv_polynomial.X_mem_supported MvPolynomial.X_mem_supported\n\n@[simp]\ntheorem supported_le_supported_iff [Nontrivial R] : supported R s ≤ supported R t ↔ s ⊆ t := by\n  constructor\n  · intro h i\n    simpa using @h (X i)\n  · exact supported_mono\n#align mv_polynomial.supported_le_supported_iff MvPolynomial.supported_le_supported_iff\n\ntheorem supported_strictMono [Nontrivial R] :\n    StrictMono (supported R : Set σ → Subalgebra R (MvPolynomial σ R)) :=\n  strictMono_of_le_iff_le fun _ _ ↦ supported_le_supported_iff.symm\n#align mv_polynomial.supported_strict_mono MvPolynomial.supported_strictMono\n\ntheorem exists_restrict_to_vars (R : Type _) [CommRing R] {F : MvPolynomial σ ℤ}\n    (hF : ↑F.vars ⊆ s) : ∃ f : (s → R) → R, ∀ x : σ → R, f (x ∘ (↑) : s → R) = aeval x F := by\n  rw [← mem_supported, supported_eq_range_rename, AlgHom.mem_range] at hF\n  cases' hF with F' hF'\n  use fun z ↦ aeval z F'\n  intro x\n  simp only [← hF', aeval_rename]\n#align mv_polynomial.exists_restrict_to_vars MvPolynomial.exists_restrict_to_vars\n\nend CommSemiring\n\nend MvPolynomial\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/MvPolynomial/Supported.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7599765292446085}}
{"text": "import data.complex.basic \nimport data.fintype.basic \nimport data.matrix.basic\nimport linear_algebra.finite_dimensional\nimport .complex_transpose\nimport analysis.normed_space.basic\nimport tactic \n\nnoncomputable theory \nopen_locale big_operators \nopen_locale matrix\n\nuniverses u v\nvariables {n m : Type u} [fintype n] [fintype m]\n\nlocal notation `Euc` := (n → ℂ)\n\nnamespace vector\n/-- Complex conjugate of a vector.-/\n@[simp]\ndef conj (v : Euc) : Euc := \nλ i, complex.conj (v i)\n\n@[simp] \nlemma conj_val (v : Euc) (i : n) : conj v i = complex.conj (v i) := rfl\n\n@[simp] \nlemma smul_conj (x : ℂ) (v : Euc) : \n  conj (x • v) = x.conj • conj(v) :=\nby ext; simp\n\n@[simp]\ndef complex_dot_product (v : Euc) (w : Euc) : ℂ := \n-- ∑ i, complex.conj (v i) * w i \nmatrix.dot_product v (conj w)\n\n@[simp]\nlemma complex_dot_product_zero {v : Euc} : complex_dot_product v (0 : Euc) = 0 :=\nby {ext; simp}\n\nlemma complex_dot_product_symm {v w : Euc} : \n  (complex_dot_product v w) = (complex_dot_product w v).conj :=\nsorry\n\n@[simp]\nlemma zero_complex_dot_product {v : Euc} : complex_dot_product (0 : Euc) v = 0 :=\nby {ext;simp}\n\n@[simp]\nlemma add_complex_dot_product {v w u : Euc} : \n  complex_dot_product (v + w) u = complex_dot_product v u + complex_dot_product w u := \nby {ext;simp}\n\n@[simp]\nlemma complex_dot_product_add {v w u : Euc} : \n  complex_dot_product v (w + u) = complex_dot_product v w + complex_dot_product v u := \nby {rw [complex_dot_product_symm, @complex_dot_product_symm _ _ v w, @complex_dot_product_symm _ _ v u], \n  simp only [conj, ring_hom.map_add, eq_self_iff_true, add_complex_dot_product]}\n\n@[simp]\nlemma complex_dot_product_sub {v w u : Euc} : \n  complex_dot_product (v - w) u = complex_dot_product v u - complex_dot_product w u := \nbegin \nsuffices : complex_dot_product v u = complex_dot_product (v - w) u +  complex_dot_product w u,\nby exact eq_sub_of_add_eq (eq.symm this),\nset u' := v - w with hu,\nhave : v = u' + w, by {exact eq_add_of_sub_eq rfl},\nrw this, apply add_complex_dot_product,\nend \n\n@[simp] \nlemma diagonal_complex_dot_product [decidable_eq n] (v w : Euc) (i : n) :\n  complex_dot_product (matrix.diagonal v i) w = v i * w i :=\nhave ∀ j ≠ i, matrix.diagonal v i j * w j = 0 := λ j hij, \n  by simp [matrix.diagonal_val_ne' hij],\n  by convert finset.sum_eq_single i (λ j _, this j) _; sorry\n\n@[simp] \nlemma complex_dot_product_diagonal [decidable_eq n] (v w : Euc) (i : n) :\n  complex_dot_product v (matrix.diagonal w i) = v i * w i :=\nhave ∀ j ≠ i, v j * matrix.diagonal w i j = 0 := λ j hij, by simp [matrix.diagonal_val_ne' hij],\nby convert finset.sum_eq_single i (λ j _, this j) _; sorry\n\n@[simp] lemma complex_dot_product_diagonal' [decidable_eq n] (v w : Euc) (i : n) :\n  complex_dot_product v (λ j, matrix.diagonal w j i) = v i * w i :=\nhave ∀ j ≠ i, v j * matrix.diagonal w j i = 0 := λ j hij, by simp [matrix.diagonal_val_ne hij],\nby convert finset.sum_eq_single i (λ j _, this j) _; sorry\n\n@[simp] lemma neg_complex_dot_product (v w : Euc) : \n  complex_dot_product (-v) w = - complex_dot_product v w :=\nby simp [matrix.dot_product]\n\n@[simp] lemma complex_dot_product_neg (v w : Euc) : complex_dot_product v (-w) = - complex_dot_product v w :=\nby simp only [matrix.dot_product, conj, pi.neg_apply, mul_neg_eq_neg_mul_symm, ring_hom.map_neg, finset.sum_neg_distrib,\n complex_dot_product]\n\n@[simp] lemma smul_complex_dot_product (x : ℂ) (v w : Euc) :\n  complex_dot_product (x • v) w = x * complex_dot_product v w :=\nby simp only [complex_dot_product, matrix.smul_dot_product]\n\n@[simp] lemma complex_dot_product_smul (x : ℂ) (v w : Euc) :\n  complex_dot_product v (x • w) = x.conj * complex_dot_product v w :=\nby simp only [complex_dot_product, smul_conj, matrix.dot_product_smul]\n\n@[simp]\ndef orthogonal (v : Euc) (w : Euc) : Prop := \n(complex_dot_product v w = 0) \n\ndef complex_norm (v : Euc) := complex_dot_product v v\n\nend vector\n\nsection subspace \ndef is_orthogonal (S : set Euc) : subspace ℂ Euc → Prop := \n  λ W, ∀ w ∈ W, ∀ v ∈ S, (vector.complex_dot_product v w = 0)\n\ndef orthogonal_complement (S : set Euc) : subspace ℂ Euc := \nInf {W | is_orthogonal S W}\n\nend subspace", "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_dot_product.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7598193580249918}}
{"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 number_theory.liouville.basic\nimport topology.metric_space.baire\nimport topology.instances.irrational\n\n/-!\n# Density of Liouville numbers\n\nIn this file we prove that the set of Liouville numbers form a dense `Gδ` set. We also prove a\nsimilar statement about irrational numbers.\n-/\n\nopen_locale filter\nopen filter set metric\n\nlemma set_of_liouville_eq_Inter_Union :\n  {x | liouville x} =\n    ⋂ n : ℕ, ⋃ (a b : ℤ) (hb : 1 < b), ball (a / b) (1 / b ^ n) \\ {a / b} :=\nbegin\n  ext x,\n  simp only [mem_Inter, mem_Union, liouville, mem_set_of_eq, exists_prop, mem_diff,\n    mem_singleton_iff, mem_ball, real.dist_eq, and_comm]\nend\n\nlemma is_Gδ_set_of_liouville : is_Gδ {x | liouville x} :=\nbegin\n  rw set_of_liouville_eq_Inter_Union,\n  refine is_Gδ_Inter (λ n, is_open.is_Gδ _),\n  refine is_open_Union (λ a, is_open_Union $ λ b, is_open_Union $ λ hb, _),\n  exact is_open_ball.inter is_closed_singleton.is_open_compl\nend\n\nlemma set_of_liouville_eq_irrational_inter_Inter_Union :\n  {x | liouville x} =\n    {x | irrational x} ∩ ⋂ n : ℕ, ⋃ (a b : ℤ) (hb : 1 < b), ball (a / b) (1 / b ^ n) :=\nbegin\n  refine subset.antisymm _ _,\n  { refine subset_inter (λ x hx, hx.irrational) _,\n    rw set_of_liouville_eq_Inter_Union,\n    exact Inter_mono (λ n, Union₂_mono $ λ a b, Union_mono $ λ hb, diff_subset _ _) },\n  { simp only [inter_Inter, inter_Union, set_of_liouville_eq_Inter_Union],\n    refine Inter_mono (λ n, Union₂_mono $ λ a b, Union_mono $ λ hb, _),\n    rw [inter_comm],\n    refine diff_subset_diff subset.rfl (singleton_subset_iff.2 ⟨a / b, _⟩),\n    norm_cast }\nend\n\n/-- The set of Liouville numbers is a residual set. -/\nlemma eventually_residual_liouville : ∀ᶠ x in residual ℝ, liouville x :=\nbegin\n  rw [filter.eventually, set_of_liouville_eq_irrational_inter_Inter_Union],\n  refine eventually_residual_irrational.and _,\n  refine eventually_residual.2 ⟨_, _, rat.dense_embedding_coe_real.dense.mono _, subset.rfl⟩,\n  { exact is_Gδ_Inter (λ n, is_open.is_Gδ $ is_open_Union $ λ a, is_open_Union $\n      λ b, is_open_Union $ λ hb, is_open_ball) },\n  { rintro _ ⟨r, rfl⟩,\n    simp only [mem_Inter, mem_Union],\n    refine λ n, ⟨r.num * 2, r.denom * 2, _, _⟩,\n    { have := int.coe_nat_le.2 r.pos, rw int.coe_nat_one at this, linarith },\n    { convert mem_ball_self _ using 2,\n      { push_cast, norm_cast, norm_num },\n      { refine one_div_pos.2 (pow_pos (int.cast_pos.2 _) _),\n        exact mul_pos (int.coe_nat_pos.2 r.pos) zero_lt_two } } }\nend\n\n/-- The set of Liouville numbers in dense. -/\nlemma dense_liouville : dense {x | liouville x} :=\ndense_of_mem_residual eventually_residual_liouville\n", "meta": {"author": "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/liouville/residual.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7598193568432038}}
{"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 group_theory.quotient_group -- import Lean's quotient groups\n\n/-\n\n# Quotient groups\n\nmathlib has quotient groups. Here's how they work.\n\n-/\n\n-- let G be a group and let N be a normal subgroup\nvariables (G : Type) [group G] (N : subgroup G) [subgroup.normal N]\n\n-- The underlying type (or set) of the quotient group. Note that `⧸` is `\\quot`, not the slash\n-- character `/` in your keyboard.\n\nexample : Type := G ⧸ N\n\n-- Let's check that the typeclass inference system can find the group structure on the quotient\nexample : group (G ⧸ N) := infer_instance\n\n-- The group homomorphism from `G` to `G ⧸ N`\n\nexample : G →* G ⧸ N := quotient_group.mk' N\n\n-- Remarks:\n-- (1) Why `quotient_group.mk'` and not `quotient_group.mk`? Because the version without the `'`\n-- is just the function, the version with the `'` is the group homomorphism.\n-- (2) Why does `quotient_group.mk' N` want to have `N` as an input but not `G`? It's because\n-- the type of `N` is `subgroup G` so Lean can figure out `G` from `N`: if you like, `N` \"knows\n-- which group it's a subgroup of\".\n\n-- Here is the basic API you need for quotient groups.\n\n-- the map G → G ⧸ N is surjective\nexample : function.surjective (quotient_group.mk' N) := quotient_group.mk'_surjective N \n\n-- Two elements of G have the same image in `G ⧸ N` iff they differ by an element of `N`\nexample (x y : G) : quotient_group.mk' N x = quotient_group.mk' N y ↔ ∃ n ∈ N, x * n = y :=\nquotient_group.mk'_eq_mk' N\n\n-- There is of course much more API, but if you want to get some practice you can\n-- just develop some of it yourself from these two functions.\n\nexample : (quotient_group.mk' N).ker = N :=\nbegin\n  sorry,\nend\n\n-- The \"universal property\" of quotients says that if you have a group homomorphism `φ : G →* H`\n-- whose kernel contains `N` then it \"extends\" to a group homomorphism `ψ : G ⧸ N →* H`\n-- such that the composite map `ψ ∘ (quotient_group.mk' N)` equals `φ`. Given `φ`, the `ψ` with\n-- this property is called `quotient_group.lift N φ h`, where `h` is a proof of `∀ x, x ∈ N → φ x = 1`.\n\nvariables (H : Type) [group H] (φ : G →* H) (h : ∀ x, x ∈ N → φ x = 1)\n\nexample : G ⧸ N →* H := quotient_group.lift N φ h\n\n-- The proof that if `x : G` then `(quotient_group.lift N φ h) ((quotient_group.mk' N) x) = φ x`\n-- is, amazingly, `refl`. \n\nexample (x : G) : (quotient_group.lift N φ h) ((quotient_group.mk' N) x) = φ x :=\nbegin\n  refl,\nend\n\n-- Technical remark: this would not be the case if quotient groups were *defined* to \n-- be cosets. In Lean quotient groups are an *opaque definition*. What do I mean by this? \n-- You probably learnt in algebra that if G is a group and H is a normal subgroup then the \n-- quotient G⧸H has elements which are *equal* to cosets of H. In Lean this is not true.\n-- A term of the quotient type G⧸H cannot be taken apart with `cases` because it is not *equal* to\n-- a coset. But the universal property `quotient_group.lift` is all we need; we don't\n-- need to worry about the underlying definition of the quotient.\n\n-- Example. Let's use `quotient_group.lift` to define the following map. Say `φ : G →* H` is a \n-- group hom and we have normal subgroups `N : subgroup G` and `P : subgroup H` such that `φ N ≤ P`.\n-- Then the induced map `G →* H ⧸ P` has `N` in the kernel, so it \"lifts\" to a group hom\n-- `ρ : G ⧸ N →* H ⧸ P` with the property that for all `x : G`, \n-- `ρ (quotient_group.mk' N x) = quotient_group.mk' P (φ x)`. Let's define `ρ` and prove\n-- this equality.\n\nvariables {G H φ N} {P : subgroup H} \nvariable [P.normal]\n\ndef ρ (h : N.map φ ≤ P) : G ⧸ N →* H ⧸ P := \nquotient_group.lift N ((quotient_group.mk' P).comp φ) \nbegin\n  -- we are using `quotient_group.lift` so we need to supply the proof that `(mk' P).comp φ` kills `N`\n  sorry,\nend\n\n-- Now let's prove that `ρ ∘ mk' N = mk' P ∘ φ`\n\n/-\n    G ----φ----> H\n    |            |\n    |            |\n   mk'           mk' \n    |            |\n    \\/           \\/\n  G ⧸ N --ρ--> H ⧸ P\n\n-/\nopen quotient_group -- no idea why I didn't do this earlier\n\nexample (h : N.map φ ≤ P) (x : G) : ρ h (mk' N x) = mk' P (φ x) :=\nbegin\n  -- this proof does my head in\n  refl,\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/section07subgroups_and_homomorphisms/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172630429475, "lm_q2_score": 0.8006920116079209, "lm_q1q2_score": 0.7597904721953403}}
{"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# Figuring out how to use the reals\n\n## The `library_search` tactic\n\nWe saw in the previous sheet that we couldn't even prove something\nas simple as \"if `aₙ → L` then `-aₙ → -L`\" because when you write down\nthe proof carefully, it relies on the fact that `|x - y| = |y - x|`\nor, equivalently, that `|(-x)| = |x|`. I say \"equivalently\" because\n`ring` will prove that `-(x - y) = y - x`.\n\nYou don't want to be proving stuff like `|x - y| = |y - x|` from first\nprinciples. Someone else has already done all the hard work for you.\nAll you need to do is to learn how to find out the names of the lemmas.\nThe `library_search` tactic tells you the names of all these lemmas. \nSee where it says \"try this\" -- click there and Lean will replace\n`library_search` with the actual name of the lemma. Once you've done\nthat, hover over the lemma name to see in what generality it holds.\n\n## The `linarith` tactic\n\nSome of the results below are bare inequalities which are too complex\nto be in the library. The library contains \"natural\" or \"standard\"\nresults, but it doesn't contain a random inequality fact just because\nit happens to be true -- the library just contains \"beautiful\" facts.\n\nThe `linarith` tactic is a tactic which can solve some equalities and inequalities\nin ordered structures like the naturals or reals. Unlike `ring`, `linarith`\ndoes look at hypotheses in the tactic state. For example if you have\nhypotheses `h1 : a < b` and `h2 : b ≤ c` then `linarith` would prove\na goal of `⊢ a < c`.\n\nHowever `linarith` doesn't know about anything other than `=`, `≠`,\n`<` and `≤`, so don't expect it to prove any results about `|x|` or\n`max A B`.\n\nExperiment with the `library_search` and `linarith` tactics below.\nTry and learn something about the naming convention which Lean uses;\nsee if you can start beginning to guess what various lemmas should be called.\n\n-/\n\nexample (x : ℝ) : |(-x)| = |x| :=\nbegin\n  sorry\nend\n\nexample (x y : ℝ) : |x - y| = |y - x| :=\nbegin\n  sorry\nend \n\nexample (A B C : ℕ) : max A B ≤ C ↔ A ≤ C ∧ B ≤ C :=\nbegin\n  sorry\nend\n\nexample (x y : ℝ) : |x| < y ↔ -y < x ∧ x < y :=\nbegin\n  sorry\nend\n\nexample (ε : ℝ) (hε : 0 < ε) : 0 < ε / 2 :=\nbegin\n  sorry,\nend\n\nexample (a b x y : ℝ) (h1 : a < x) (h2 : b < y) : a + b < x + y :=\nbegin\n  sorry,\nend\n\nexample (ε : ℝ) (hε : 0 < ε) : 0 < ε / 3 :=\nbegin\n  sorry,\nend\n\nexample (a b c d x y : ℝ) (h1 : a + c < x) (h2 : b + d < y) :\n  a + b + c + d < x + y :=\nbegin\n  sorry\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/section02reals/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7597809354906593}}
{"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-/\nimport group_theory.free_group\nimport group_theory.quotient_group\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 `α`, this file constructs the group\ngiven by generators `x : α` and relations `r ∈ rels`.\n\n## Main definitions\n\n* `presented_group rels`: the quotient group of the free group on a type `α` by a subset `rels` of\n  relations of the free group on `α`.\n* `of`: The canonical map from `α` to a presented group with generators `α`.\n* `to_group f`: the canonical group homomorphism `presented_group rels → G`, given a function\n  `f : α → G` from a type `α` to a group `G` which satisfies the relations `rels`.\n\n## Tags\n\ngenerators, relations, group presentations\n-/\n\nvariables {α : Type}\n\n/-- Given a set of relations, rels, over a type `α`, presented_group constructs the group with\ngenerators `x : α` and relations `rels` as a quotient of free_group `α`.-/\ndef presented_group (rels : set (free_group α)) : Type :=\nfree_group α ⧸ subgroup.normal_closure rels\n\nnamespace presented_group\n\ninstance (rels : set (free_group α)) : group (presented_group (rels)) :=\nquotient_group.quotient.group _\n\n/-- `of` is the canonical map from `α` to a presented group with generators `x : α`. The term `x` is\nmapped to the equivalence class of the image of `x` in `free_group α`. -/\ndef of {rels : set (free_group α)} (x : α) : presented_group rels :=\nquotient_group.mk (free_group.of x)\n\nsection to_group\n\n/-\nPresented groups satisfy a universal property. If `G` is a group and `f : α → G` is a map such that\nthe images of `f` satisfy all the given relations, then `f` extends uniquely to a group homomorphism\nfrom `presented_group rels` to `G`.\n-/\n\nvariables {G : Type} [group G] {f : α → G} {rels : set (free_group α)}\n\nlocal notation `F` := free_group.lift f\n\nvariable (h : ∀ r ∈ rels, F r = 1)\n\nlemma closure_rels_subset_ker : subgroup.normal_closure rels ≤ monoid_hom.ker F :=\nsubgroup.normal_closure_le_normal (λ x w, (monoid_hom.mem_ker _).2 (h x w))\n\nlemma to_group_eq_one_of_mem_closure : ∀ x ∈ subgroup.normal_closure rels, F x = 1 :=\nλ x w, (monoid_hom.mem_ker _).1 $ closure_rels_subset_ker h w\n\n/-- The extension of a map `f : α → G` that satisfies the given relations to a group homomorphism\nfrom `presented_group rels → G`. -/\ndef to_group : presented_group rels →* G :=\nquotient_group.lift (subgroup.normal_closure rels) F (to_group_eq_one_of_mem_closure h)\n\n@[simp] lemma to_group.of {x : α} : to_group h (of x) = f x := free_group.lift.of\n\ntheorem to_group.unique (g : presented_group rels →* G)\n  (hg : ∀ x : α, g (of x) = f x) : ∀ {x}, g x = to_group h x :=\nλ x, quotient_group.induction_on x\n    (λ _, free_group.lift.unique (g.comp (quotient_group.mk' _)) hg)\n\nend to_group\n\ninstance (rels : set (free_group α)) : inhabited (presented_group rels) := ⟨1⟩\n\nend presented_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/group_theory/presented_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379296, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7597809240155338}}
{"text": "import .love01_definitions_and_statements_demo\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 (5 points): Arithmetic expressions\n\nRecall the type of arithmetic expressions from lecture 1 and its evaluation\nfunction: -/\n\n#check aexp\n#check eval\n\n/-! Let us introduce the following abbreviation for an environment that maps\nvariable names to values: -/\n\ndef envir : Type :=\nstring → ℤ\n\n/-! 1.1 (2 points). Complete the following Lean definition of a big-step-style\nsemantics for arithmetic expressions. The predicate `big_step` (`⟹`) relates\nan arithmetic expression, an environment, and the value to which it the\nexpression evaluates in the given environment: -/\n\ninductive big_step : aexp × envir → ℤ → Prop\n| num {i env} : big_step (aexp.num i, env) i\n\ninfix ` ⟹ ` : 110 := big_step\n\n/-! 1.2 (1 point). Prove the following lemma to validate your definition\nabove. -/\n\nlemma big_step_add_two_two (env : envir) :\n  (aexp.add (aexp.num 2) (aexp.num 2), env) ⟹ 4 :=\nsorry\n\n/-! 1.3 (2 points). Prove that the big-step semantics is sound with respect to\nthe `eval` function: -/\n\nlemma big_step_sound (env : envir) (a : aexp) (i : ℤ) :\n  (a, env) ⟹ i → eval env a = i :=\nsorry\n\n\n/-! ## Question 2 (4 points + 1 bonus points): 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 ::= ∅       — `nothing`: matches nothing\n        | ε       — `empty`: matches the empty string\n        | a       — `atom`: matches the atom `a`\n        | R ⬝ R    — `concat`: matches the concatenation of two regexes\n        | R + R   — `alt`: matches either of two regexes\n        | R*      — `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 (α : Type) : Type\n| nothing {} : regex\n| empty   {} : regex\n| atom       : α → regex\n| concat     : regex → regex → regex\n| alt        : regex → regex → regex\n| star       : regex → regex\n\n/-! The `matches r s` predicate indicates that the regular expression `r` matches\nthe string `s`. -/\n\ninductive matches {α : Type } : regex α → list α → Prop\n| empty :\n  matches regex.empty []\n| atom (a : α) :\n  matches (regex.atom a) [a]\n| concat {r₁ r₂ : regex α} (s₁ s₂ : list α) (h₁ : matches r₁ s₁)\n    (h₂ : matches r₂ s₂) :\n  matches (regex.concat r₁ r₂) (s₁ ++ s₂)\n| alt_left {r₁ r₂ : regex α} (s : list α) (h : matches r₁ s) :\n  matches (regex.alt r₁ r₂) s\n| alt_right {r₁ r₂ : regex α} (s : list α) (h : matches r₂ s) :\n  matches (regex.alt r₁ r₂) s\n| star_base {r : regex α} :\n  matches (regex.star r) []\n| star_step {r : regex α} (s s' : list α) (h₁ : matches r s)\n    (h₂ : 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\n2.1 (1 point). Explain why there is no rule for `nothing`. -/\n\n-- enter your answer here\n\n/-! 2.2 (3 points). Prove the following inversion rules. -/\n\n@[simp] lemma matches_atom {α : Type} {s : list α} {a : α} :\n  matches (regex.atom a) s ↔ s = [a] :=\nsorry\n\n@[simp] lemma matches_nothing {α : Type} {s : list α} :\n  ¬ matches regex.nothing s :=\nsorry\n\n@[simp] lemma matches_empty {α : Type} {s : list α} :\n  matches regex.empty s ↔ s = [] :=\nsorry\n\n@[simp] lemma matches_concat {α : Type} {s : list α} {r₁ r₂ : regex α} :\n  matches (regex.concat r₁ r₂) s\n  ↔ (∃s₁ s₂, matches r₁ s₁ ∧ matches r₂ s₂ ∧ s = s₁ ++ s₂) :=\nsorry\n\n@[simp] lemma matches_alt {α : Type} {s : list α} {r₁ r₂ : regex α} :\n  matches (regex.alt r₁ r₂) s ↔ (matches r₁ s ∨ matches r₂ s) :=\nsorry\n\n/-! 2.3 (1 bonus points). Prove the following inversion rule. -/\n\nlemma matches_star {α : Type} {s : list α} {r : regex α} :\n  matches (regex.star r) s ↔\n  (s = [] ∨ (∃s₁ s₂, matches r s₁ ∧ matches (regex.star r) s₂ ∧ s = s₁ ++ s₂)) :=\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/love08_operational_semantics_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8856314647623015, "lm_q1q2_score": 0.7596664361291886}}
{"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 analysis.inner_product_space.basic\nimport analysis.special_functions.complex.arg\n\n/-!\n# Rays in the complex numbers\n\nThis file links the definition `same_ray ℝ x y` with the equality of arguments of complex numbers,\nthe usual way this is considered.\n\n## Main statements\n\n* `complex.same_ray_iff` : Two complex numbers are on the same ray iff one of them is zero, or they\n  have the same argument.\n* `complex.abs_add_eq/complex.abs_sub_eq`: If two non zero complex numbers have different argument,\n  then the triangle inequality becomes strict.\n\n-/\n\nvariables {x y : ℂ}\n\nnamespace complex\n\nlemma same_ray_iff : same_ray ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\nbegin\n  rcases eq_or_ne x 0 with rfl | hx,\n  { simp },\n  rcases eq_or_ne y 0 with rfl | hy,\n  { simp },\n  simp only [hx, hy, false_or, same_ray_iff_norm_smul_eq, arg_eq_arg_iff hx hy],\n  field_simp [hx, hy],\n  rw [mul_comm, eq_comm]\nend\n\nlemma same_ray_iff_arg_div_eq_zero : same_ray ℝ x y ↔ arg (x / y) = 0 :=\nbegin\n  rw [←real.angle.to_real_zero, ←arg_coe_angle_eq_iff_eq_to_real, same_ray_iff],\n  by_cases hx : x = 0, { simp [hx] },\n  by_cases hy : y = 0, { simp [hy] },\n  simp [hx, hy, arg_div_coe_angle, sub_eq_zero]\nend\n\nlemma abs_add_eq_iff : (x + y).abs = x.abs + y.abs ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\nsame_ray_iff_norm_add.symm.trans same_ray_iff\n\nlemma abs_sub_eq_iff : (x - y).abs = |x.abs - y.abs| ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\nsame_ray_iff_norm_sub.symm.trans same_ray_iff\n\nlemma same_ray_of_arg_eq (h : x.arg = y.arg) : same_ray ℝ x y :=\nsame_ray_iff.mpr $ or.inr $ or.inr h\n\nlemma abs_add_eq (h : x.arg = y.arg) : (x + y).abs = x.abs + y.abs :=\n(same_ray_of_arg_eq h).norm_add\n\nlemma abs_sub_eq (h : x.arg = y.arg) : (x - y).abs = ‖x.abs - y.abs‖ :=\n(same_ray_of_arg_eq h).norm_sub\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/arg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.7596664300373884}}
{"text": "import neater_proof.ideal_algebra\n\nlocal infixr ` + ` : 80 := plus\nlocal infixr ` * ` : 80 := mult\nlocal infixr ` ⨁ ` : 80 := Ideal_plus\nlocal infixr ` ⨂ ` : 80 := Ideal_mult\n\n/-- See, e.g. here: https://en.wikipedia.org/wiki/Semiring -/\nstructure is_idempotent_semiring (X : Type _) :=\n(plus : X → X → X)\n(mult : X → X → X)\n(zero' : X)\n(one'  : X)\n(plus_assoc : ∀ x y z : X, plus x (plus y z) = plus (plus x y) z)\n(plus_comm  : ∀ x y   : X, plus x y = plus y x)\n(plus_iden  : ∀ x     : X, plus x zero' = x)\n(mult_assoc : ∀ x y z : X, mult x (mult y z) = mult (mult x y) z)\n(mult_liden : ∀ x     : X, mult one' x = x)\n(mult_riden : ∀ x     : X, mult x one' = x)\n(lm_distrib : ∀ x y z : X, mult x (plus y z) = plus (mult x y) (mult x z))\n(rm_distrib : ∀ x y z : X, mult (plus x y) z = plus (mult x z) (mult y z))\n(zero_lanni : ∀ x     : X, mult zero' x = zero')\n(zero_ranni : ∀ x     : X, mult x zero' = zero')\n(plus_idemp : ∀ x     : X, plus x x = x)\n\ntheorem ring_ideals_form_an_idempotent_semiring {R : Ring} :\nis_idempotent_semiring (Ideal R) :=\n{ plus  := Ideal_plus,\n  mult  := Ideal_mult,\n  zero' := Ideal_zero,\n  one'  := Ideal_one,\n  plus_assoc :=\n  begin -- addition of Ideals is associative!\n   intros w x y,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,  -- we now see that the two ideals are equal if, for an arbitrary element of the ring,\n           -- it is an element of one of the ideals iff it is an element of the other, we \n           -- split, to consider the two directions of the biconditional is turn\n   { intro hz,\n     cases hz with x' hz, \n     cases hz with y' hz,\n     cases hz with hx' hz,\n     cases hz with hy' hz,\n     cases hy' with x'' hy',\n     cases hy' with y'' hy',\n     cases hy' with hx'' hy',\n     cases hy' with hy'' hy',\n     rw hy' at hz,\n     -- we are required to show that z is an element of (w ⨁ x) ⨁ y, we know that:\n     -- z = x' + x'' + y', that x' is an element of w, that x'' is an element of x and that y' is\n     -- an element of y, by associativity z = (x' + x'') + y', and then there isn't much more work\n     -- to do.\n     existsi x' + x'',\n     existsi y'',\n     split,\n     { existsi x',\n       existsi x'',\n       split,\n       { exact hx', },\n       { split,\n         { exact hx'', },\n         { exact rfl, }, }, }, -- and we have succesfully shown that x' + x'' ∈ w ⨁ x\n     { split,\n       { exact hy'' }, -- and y' ∈ y\n       { calc\n          z     = x' + x'' + y'' : by exact hz\n            ... = (x' + x'') + y'' : by exact plus_assoc x' x'' y'', }, }, },\n          -- so, z = (x' + x'') + y'' ∈ (w ⨁ x) ⨁ y as required\n   { intro hz, \n     cases hz with x' hz, -- the second part of this proof proceeds in substantially the same way,\n     cases hz with y' hz, -- only the associativity runs in the other direction\n     cases hz with hx' hz,-- in a sense, the type of Ideals inherits its associativity from the\n     cases hz with hy' hz,-- associativity of the corresponding ring\n     cases hx' with x'' hx',\n     cases hx' with y'' hx',\n     cases hx' with hx'' hx',\n     cases hx' with hy'' hx',\n     rw hx' at hz,\n     existsi x'',\n     existsi y'' + y',\n     split,\n     { exact hx'', },\n     { split,\n       { existsi y'',\n         existsi y',\n         split,\n         { exact hy'' },\n         { split,\n           { exact hy', },\n           { exact rfl, }, }, },\n       { calc\n          z     = (x'' + y'') + y' : by exact hz\n            ... = x'' + y'' + y'   : by { symmetry, exact plus_assoc x'' y'' y' } }, }, },\n  end,\n  plus_comm  :=\n  begin -- addition of Ideals is commutative!\n   intros x y,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split, -- these few lines will appear in most sections of the proof of this theorem,\n          -- we demonstrate that the biconditional about membership of our Ideals is sufficient \n          -- for equality of those Ideals, and then we split and prove each direction in turn\n   { intro hz,\n     cases hz with x' hz,\n     cases hz with y' hz,\n     cases hz with hx' hz,\n     cases hz with hy' hz,\n     existsi y',\n     existsi x',\n     split,          -- we must show that z ∈ y ⨁ x, we know that z = x' + y', x' ∈ x, y' ∈ y\n     { exact hy', }, -- so we can use commutativity of addition in the ring   \n     { split,\n       { exact hx', },\n       { calc\n          z     = x' + y' : by exact hz\n            ... = y' + x' : by exact plus_comm x' y', }, }, },\n   { intro hz,\n     cases hz with x' hz,\n     cases hz with y' hz,\n     cases hz with hx' hz,\n     cases hz with hy' hz,\n     existsi y',\n     existsi x',\n     split,\n     { exact hy', },\n     { split,\n       { exact hx', },\n       { calc\n          z     = x' + y' : by exact hz\n            ... = y' + x' : by exact plus_comm x' y',  }, }, },\n  end,\n  plus_iden  :=\n  begin -- zero Ideal is additive identity!\n   intro x,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split, -- see, here it is again, same as in the last two sections\n   { intro hz,\n     cases hz with x' hz,\n     cases hz with y' hz,\n     cases hz with hx' hz,\n     cases hz with hy' hz,\n     -- now, we want to show that z ∈ x, we know that z = x' + y', that y' ∈ Ideal_zero and that\n     -- x' ∈ x, we now show that y' can only be zero, so x' must be equal to z, so z ∈ x.\n     have h : y' = zero,\n     { exact Ideal_zero_mems_are_zero y' hy', },\n     rw h at hz,\n     have h' : z = x',\n     { calc\n        z     = x' + zero : by exact hz\n          ... = x'        : by exact zero_plus_neutral x',  },\n     rw h',\n     exact hx', },\n   { intro hz,\n     -- we must show that z ∈ x ⨁ Ideal_zero, we know that z ∈ x, and showing that \n     -- zero ∈ Ideal_zero would be trivial, and z + zero = z, therefore z ∈ x ⨁ Ideal_zero\n     existsi z,\n     existsi zero,\n     split,\n     { exact hz, },\n     { split,\n       { exact zero_mem_Ideal Ideal_zero },\n       { calc\n          z     = z + zero : by { symmetry, exact zero_plus_neutral z, }, }, }, },\n  end,\n  mult_assoc :=\n  begin -- multiplication of Ideals is associative!\n   -- all of the material on finite sums really comes into play here\n   intros w y z,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hx,\n     -- we know that x ∈ w ⨂ y ⨂ z and we want to show that it is in (w ⨂ y) ⨂ z, from the\n     -- material on finite sums in the ideal_algebra file, we know that elements of the product\n     -- ideal are finite sums of multiples of products of elements of the component ideals of the\n     -- product, and then we can use what we know about the conditions for finite sums being\n     -- elements of ideals to proceed.\n     specialize hx (fin_sum_ideal (set_ideal_mult w (y ⨂ z)) (nonempty_set_ideal_mult w (y ⨂ z)))\n                   (set_ideal_mult_in_mult_set w (y ⨂ z)),\n     cases hx with nx hx,\n     cases hx with fx hx,\n     cases hx with eqx hx,\n     rw eqx, -- eqx is the premise telling us that x is a finite sum of elements of the ring\n     apply fin_sum_member_condition ((w ⨂ y) ⨂ z) fx nx,\n     intro n, -- we consider an arbitrary value of the function fx, to show that the finite sum\n     specialize hx n, -- membership condition holds for x.\n     intros I hI,\n     cases hx with x' hx,\n     cases hx with hx' hx,\n     cases hx' with y' hx',\n     cases hx' with hy' hx',\n     cases hx' with y'' hx',\n     cases hx' with hy'' hx',\n     specialize hy'' (fin_sum_ideal (set_ideal_mult y z) (nonempty_set_ideal_mult y z))\n                     (set_ideal_mult_in_mult_set y z),\n     cases hx with q hx,\n     cases hx with p hx,\n     rw hx, -- we know that each term of these finite sums is a multiple of products of terms in\n     apply (multiplication_conditions I).2, -- w and terms in (y ⨂ z), by definition of ideals\n     apply (multiplication_conditions I).1, -- we only need to show that those products are in\n                                            -- the set we are interested in.\n     cases hy'' with ny'' hy'', -- A term in y ⨂ z is a finite sum, so the product of such a term\n     cases hy'' with fy'' hy'', -- and a term in w is a multiple of a finite sum, and we know that\n     cases hy'' with eqy'' hy'',-- multiples of finite sums are finite sums, so after a little\n     have h : x' = fin_sum (mul_fun y' fy'') ny'', -- rewriting we can apply our membership \n     { calc                                        -- condition again.\n        x'     = y' * y'' : by exact hx'\n           ... = y' * (fin_sum fy'' ny'') : by rw eqy''\n           ... = fin_sum (mul_fun y' fy'') ny'' : by\n                                                  exact mul_fin_sum.mul_fin_sum y' fy'' ny'' },\n     rw h,\n     apply fin_sum_member_condition I (mul_fun y' fy'') ny'',\n     intro n',\n     specialize hy'' n',\n     cases hy'' with x'' hy'',\n     cases hy'' with hx'' hy'',\n     cases hy'' with y''' hy'',\n     cases hy'' with z'' hy'',\n     have h' : mul_fun y' fy'' n' = y' * (fy'' n'),\n     { exact rfl, },\n     have h'' : mul_fun y' fy'' n' = y' * y''' * x'' * z'',\n     { calc\n        mul_fun y' fy'' n'     = y' * fy'' n' : by exact h'\n                           ... = y' * y''' * x'' * z'' : by rw hy'', },\n     rw h'',\n     cases hx'' with x''' hx'',\n     cases hx'' with hx''' hx'',\n     cases hx'' with z''' hx'',\n     cases hx'' with hz''' hx'',\n     have h''' : (y' * y''') * x''' ∈ (w ⨂ y).I,\n     { intros I' hI',\n       specialize hI' (y' * y''') x''',\n       apply hI',\n       { apply (multiplication_conditions w).1,\n         exact hy', },\n       { exact hx''', }, },\n     have h'''' : y' * y''' * x'' * z''  -- we break up and rewrite our product so that its\n                = ((y' * y''') * x''') * (z''' * z''), -- membership in the mult-set can be proved\n     { calc                                            -- directly.\n        y' * y''' * x'' * z''     = y' * y''' * (x''' * z''') * z'' : by rw hx''\n                              ... = y' * y''' * x''' * z''' * z'' : by \n                                                                    rw ← mult_assoc x''' z''' z''\n                              ... = (y' * y''') * x''' * z''' * z'' : by rw mult_assoc\n                              ... = ((y' * y''') * x''') * z''' * z'' : by rw mult_assoc, },\n     rw h'''',\n     apply hI,\n     { exact h''', },\n     { apply (multiplication_conditions z).1,\n       exact hz''', }, }, -- so ends the first part of the proof of multiplication's associativity\n   {intro hx,\n    specialize hx (fin_sum_ideal (set_ideal_mult (w ⨂ y) z) (nonempty_set_ideal_mult (w ⨂ y) z))\n                  (set_ideal_mult_in_mult_set (w ⨂ y) z),\n    cases hx with nx hx,\n    cases hx with fx hx,\n    cases hx with eqx hx,\n    rw eqx,\n    apply fin_sum_member_condition (w ⨂ y ⨂ z) fx nx,\n    intro n,\n    specialize hx n,\n    intros I hI,\n    cases hx with x' hx,\n    cases hx with hx' hx,\n    cases hx' with y' hx',\n    cases hx' with hy' hx',\n    cases hx' with y'' hx',\n    cases hx' with hy'' hx',\n    specialize hy' (fin_sum_ideal (set_ideal_mult w y) (nonempty_set_ideal_mult w y))\n                    (set_ideal_mult_in_mult_set w y),\n    cases hx with q hx,\n    cases hx with p hx,\n    rw hx,\n    apply (multiplication_conditions I).2,\n    apply (multiplication_conditions I).1,\n    cases hy' with ny' hy',\n    cases hy' with fy' hy',\n    cases hy' with eqy' hy',\n    have h : x' = fin_sum (mul_fun' y'' fy') ny',\n    { calc\n       x'     = y' * y'' : by exact hx'\n          ... = (fin_sum fy' ny') * y'' : by rw eqy'\n          ... = fin_sum (mul_fun' y'' fy') ny' : by\n                                                 exact mul_fin_sum.mul_fin_sum' y'' fy' ny' },\n    rw h,\n    apply fin_sum_member_condition I (mul_fun' y'' fy') ny',\n    intro n',\n    specialize hy' n',\n    cases hy' with x'' hy',\n    cases hy' with hx'' hy',\n    cases hy' with y''' hy',\n    cases hy' with z'' hy',\n    have h' : mul_fun' y'' fy' n' = (fy' n') * y'',\n    { exact rfl, },\n    have h'' : mul_fun' y'' fy' n' = y''' * x'' * z'' * y'',\n    { calc\n       mul_fun' y'' fy' n'     = (fy' n') * y'' : by exact h'\n                           ... = (y''' * x'' * z'') * y'' : by rw hy'\n                           ... = y''' * (x'' * z'') * y'' : by rw ← mult_assoc\n                           ... = y''' * x'' * z'' * y''   : by rw ← mult_assoc x'' z'' y'', },\n    rw h'',\n    cases hx'' with x''' hx'',\n    cases hx'' with hx''' hx'',\n    cases hx'' with z''' hx'',\n    cases hx'' with hz''' hx'',\n    have h''' : z''' * z'' * y'' ∈ (y ⨂ z).I,\n    { intros I' hI',\n      specialize hI' z''' (z'' * y''),\n      apply hI',\n      { exact hz''', },\n      { apply (multiplication_conditions z).2,\n        exact hy'', }, },\n    have h'''' : y''' * x'' * z'' * y'' \n               = (y''' * x''') * (z''' * z'' * y''),\n    { calc\n       y''' * x'' * z'' * y''     = y''' * (x''' * z''') * z'' * y'' : by rw hx''\n                              ... = y''' * x''' * z''' * z'' * y'' : by \n                                                                     rw ← mult_assoc x''' z'''\n                                                                                    (z'' * y'')\n                              ... = (y''' * x''') * z''' * z'' * y'' : by rw mult_assoc, },\n    rw h'''',\n    apply hI,\n    { apply (multiplication_conditions w).2,\n      exact hx''', },\n    { exact h''', }, },\n  /- The proof of associativity is essentially the same is both directions, the basic idea is that\n     an element is contained in an Ideal product if it is contained in every Ideal which contains\n     all of the products of elements of the Ideals that make up the product, amongst those Ideals\n     (the Ideals containing the products of elements) is the Ideal which contains only finite sums\n     of multiples of products of elements of those Ideals, so each element of any ideal product is\n     expressable as a finite sum. A finite sum is contained in an Ideal if each one of its terms\n     is contained in that Ideal, and the terms of the finite sums expressing elements of our Ideal\n     product are long multiples of elements of our ring. We are considering Ideal products where\n     one of the terms is itself an Ideal product, so the terms of the finite sum contain,\n     themselves, a finite sum, in fact, each term is re-expressible as a finite sum itself, but \n     this is no problem, since we can then use the same machinery to show that the term is in the\n     Ideal product, by showing that each term of this new finite sum we have expressed it as is \n     so. We know that an element of the Ring is in our Ideal product if it's a product of elements\n     of the Ring whose terms are in the terms of our Ideal product, so we use associativity of \n     multiplication in the Ring to rewrite our term of our finite sum as such a product, then we\n     can complete the proof that the element is contained in the other Ideal product. -/\n  end,\n  mult_liden :=\n  begin -- one Ideal is multiplicative identity from the left!\n   intro w,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hx,\n     specialize hx w, -- x ∈ w if w contains all products of a term in w and a term in Ideal_one\n     apply hx,\n     exact mult_set_self_right w Ideal_one, /- and w does -/ },\n   { intros hx I hI,\n     specialize hI one x, -- x ∈ Ideal_one ⨂ w if, for arbitrary I, I contains all products of\n                          -- an element of Ideal_one and an element of w, implies I contains x,\n                          -- the antecedant implies that I contains one * x, and we're done.\n     rw ← one_mult_neutral_left x,\n     apply hI,\n     { have t : true,\n       { cc, },\n       exact t, }, -- silly trivial proof that one ∈ Ideal_one\n     { exact hx, }, },\n  end,\n  mult_riden :=\n  begin -- one Ideal is multiplicative identity from the right!\n   intro w,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split, -- the body of this proof is almost identical to that above\n   { intro hx,\n     exact hx w (mult_set_self_left w Ideal_one), },\n   { intros hx I hI,\n     rw ← one_mult_neutral_right x,\n     apply hI,\n     { exact hx, },\n     { have t : true,\n       { cc, },\n       exact t, }, },\n  end,\n  lm_distrib :=\n  begin -- Ideal multiplication is distributive from the left!\n   intros w y z,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hx,\n     specialize hx ((w ⨂ y) ⨁ (w ⨂ z)), -- we proceed by showing that, for all x' ∈ w, for all\n     apply hx,                             -- y' ∈ (y ⨁ z), x' * y' ∈ (w ⨂ y) ⨁ (w ⨂ z) \n     intros x' y' hx' hy',\n     cases hy' with x'' hy',\n     cases hy' with y'' hy',\n     cases hy' with hx'' hy', -- we have that, for some x'' ∈ y, for some y'' ∈ z, y' = x'' + y''\n     cases hy' with hy'' hy',\n     have h : x' * y' = (x' * x'') + (x' * y''),\n     { calc\n        x' * y'     = x' * x'' + y'' : by rw hy'\n                ... = (x' * x'') + x' * y'' : by exact left_distributivity x' x'' y'', },\n     rw h,\n     existsi x' * x'', -- to show that a sum is in a sum Ideal, we can show that its first term is\n     existsi x' * y'', -- in the first Ideal, and it's second in the second Ideal\n     split,\n     { intros I hI,\n       specialize hI x' x'',\n       apply hI,\n       { exact hx', },\n       { exact hx'', }, },\n     { split,\n       { intros I hI,\n         specialize hI x' y'',\n         apply hI,\n         { exact hx', },\n         { exact hy'', }, },\n       { exact rfl, }, }, },\n   { intro hx,\n     cases hx with x' hx,   -- because x is an element a sum Ideal, it itself can be written as a\n     cases hx with y' hx,   -- sum, and we can prove that a sum is an element of an Ideal by \n     cases hx with hx' hx,  -- proving that each one of its terms is an element of the Ideal\n     cases hx with hy' hx,\n     specialize hx' (w ⨂ y ⨁ z),\n     specialize hy' (w ⨂ y ⨁ z),\n     rw hx,\n     apply (subgroup_under_addition(w ⨂ y ⨁ z)).2.1 x' y',\n     { apply hx', -- all elements in the mult_set of w and y contain x'\n       intros x'' y'' hx'' hy'' I hI,\n       apply hI,\n       { exact hx'' },\n       { existsi y'',\n         existsi zero,\n         split,\n         { exact hy'' },\n         { split,\n           { exact zero_mem_Ideal z, },\n           { calc\n              y''     = y'' + zero : by { symmetry, exact zero_plus_neutral y'', }, }, }, }, },\n     { apply hy', -- similarly for y'\n       intros x'' y'' hx'' hy'' I hI,\n       apply hI,\n       { exact hx'', },\n       { existsi zero,\n         existsi y'',\n         split,\n         { exact zero_mem_Ideal y, },\n         { split,\n           { exact hy'', },\n           { calc\n              y''     = y'' + zero : by { symmetry, exact zero_plus_neutral y'' }\n                  ... = zero + y'' : by exact plus_comm y'' zero, }, }, }, }, },\n  end,\n  rm_distrib :=\n  begin -- Ideal multiplication is distributive from the right!\n   -- this proof is substantially the same as the one above\n   intros w y z,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hx,\n     specialize hx ((w ⨂ z) ⨁ (y ⨂ z)),\n     apply hx,\n     intros x' y' hx' hy',\n     cases hx' with x'' hx',\n     cases hx' with y'' hx',\n     cases hx' with hx'' hx',\n     cases hx' with hy'' hx',\n     have h : x' * y' = (x'' * y') + (y'' * y'),\n     { calc\n        x' * y'     = (x'' + y'') * y' : by rw hx'\n                ... = (x'' * y') + y'' * y' : by exact right_distributivity x'' y'' y' },\n     rw h,\n     existsi (x'' * y'),\n     existsi (y'' * y'),\n     split,\n     { intros I hI,\n       apply hI x'' y',\n       { exact hx'', },\n       { exact hy', }, },\n     { split,\n       { intros I hI,\n         apply hI y'' y',\n         { exact hy'', },\n         { exact hy', }, },\n       { exact rfl, }, }, },\n   { intro hx,\n     cases hx with x' hx,\n     cases hx with y' hx,\n     cases hx with hx' hx,\n     cases hx with hy' hx,\n     specialize hx' ((w ⨁ y) ⨂ z),\n     specialize hy' ((w ⨁ y) ⨂ z),\n     rw hx,\n     apply (subgroup_under_addition ((w ⨁ y) ⨂ z)).2.1,\n     { apply hx',\n       intros x'' y'' hx'' hy'' I hI,\n       apply hI,\n       { existsi x'',\n         existsi zero,\n         split,\n         { exact hx'', },\n         { split,\n           { exact zero_mem_Ideal y, },\n           { calc\n              x'' = x'' + zero : by { symmetry, exact zero_plus_neutral x'', }, }, }, },\n       { exact hy'' }, },\n     { apply hy',\n       intros x'' y'' hx'' hy'' I hI,\n       apply hI,\n       { existsi zero,\n         existsi x'',\n         split,\n         { exact zero_mem_Ideal w, },\n         { split,\n           { exact hx'', },\n           { calc\n              x''     = x'' + zero : by { symmetry, exact zero_plus_neutral x'' }\n                  ... = zero + x'' : by exact plus_comm x'' zero, }, }, },\n       { exact hy'', }, }, },\n  end,\n  zero_lanni :=\n  begin -- zero Ideal annihilates in multiplication from the left!\n   intro w,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hx, -- first we prove that if x ∈ Ideal_zero ⨂ w then x ∈ Ideal_zero, this is easy,\n     exact hx Ideal_zero (mult_set_self_left Ideal_zero w), }, -- since the antecedant implies \n                                                               -- that x is in all elements of the\n                                                               -- the mult_set of Ideal_zero and\n                                                               -- w, which includes Ideal_zero.\n   { intro hx, -- next we prove that if x ∈ Ideal_zero, then x ∈ Ideal_zero ⨂ w, again easy,\n     have h : x = zero, -- since the antecedant implies that x = zero, and all Ideals contain zero\n     { exact hx },\n     rw h,\n     exact zero_mem_Ideal (Ideal_zero ⨂ w), },\n  end,\n  zero_ranni :=\n  begin -- zero Ideal annihilates in multiplication from the right!\n   -- this proof is substantially the same as the above.\n   intro w,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hx,\n     exact hx Ideal_zero (mult_set_self_right Ideal_zero w), },\n   { intro hx,\n     have h : x = zero,\n     { exact hx, },\n     rw h,\n     exact zero_mem_Ideal (w ⨂ Ideal_zero), },\n  end,\n  plus_idemp :=\n  begin -- Ideal addition is idempotent!\n   intro x,\n   apply ideal_equality_condition,\n   funext,\n   apply propext,\n   split,\n   { intro hz, -- if z ∈  x ⨁ x, then there is an x' ∈ x and a y ∈ x st. z = x' + y', and then\n     cases hz with x' hz, -- we must have z ∈ x, since Ideals are closed under addition.\n     cases hz with y' hz,\n     cases hz with hx' hz,\n     cases hz with hy' hz,\n     rw hz,\n     exact (subgroup_under_addition x).2.1 x' y' hx' hy', },\n   { intro hz, -- conversely if z ∈ x then there exists an element of x and an element of x st.\n     existsi z, -- their sum is z, namely z itself, and zero.\n     existsi zero,\n     split,\n     { exact hz, },\n     { split,\n       { exact zero_mem_Ideal x, },\n       { calc\n          z = z + zero : by { symmetry, exact zero_plus_neutral z, }, }, }, },\n  end } -- Ring Ideals form an Idempotent Semiring.\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/ring_ideals_form_an_idempotent_semiring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7596657969299478}}
{"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.convex.topology\nimport analysis.normed.group.pointwise\nimport analysis.normed_space.ray\n\n/-!\n# Topological and metric properties of convex sets in normed spaces\n\nWe prove the following facts:\n\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 {ι : Type*} {E : Type*}\n\nopen metric set\nopen_locale pointwise convex\n\nvariables [seminormed_add_comm_group E] [normed_space ℝ 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 ℝ s) : convex_on ℝ s norm :=\n⟨hs, λ x hx y hy a b ha hb hab,\n  calc ‖a • x + b • y‖ ≤ ‖a • x‖ + ‖b • y‖ : norm_add_le _ _\n    ... = a * ‖x‖ + b * ‖y‖\n        : by rw [norm_smul, norm_smul, real.norm_of_nonneg ha, real.norm_of_nonneg hb]⟩\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 ℝ univ (norm : E → ℝ) := convex_on_norm convex_univ\n\nlemma convex_on_dist (z : E) (hs : convex ℝ s) : convex_on ℝ s (λ 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 ℝ E - affine_map.const ℝ E z)\n\nlemma convex_on_univ_dist (z : E) : convex_on ℝ univ (λz', dist z' z) :=\nconvex_on_dist z convex_univ\n\nlemma convex_ball (a : E) (r : ℝ) : convex ℝ (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 : ℝ) : convex ℝ (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 ℝ s) (δ : ℝ) : convex ℝ (thickening δ s) :=\nby { rw ←add_ball_zero, exact hs.add (convex_ball 0 _) }\n\nlemma convex.cthickening (hs : convex ℝ s) (δ : ℝ) : convex ℝ (cthickening δ s) :=\nbegin\n  obtain hδ | hδ := le_total 0 δ,\n  { rw cthickening_eq_Inter_thickening hδ,\n    exact convex_Inter₂ (λ _ _, hs.thickening _) },\n  { rw cthickening_of_nonpos hδ,\n    exact hs.closure }\nend\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 ∈ convex_hull ℝ s) (y : E) :\n  ∃ x' ∈ s, dist x y ≤ 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' ∈ s` and `y' ∈ t` at distance at least `dist x y`. -/\nlemma convex_hull_exists_dist_ge2 {s t : set E} {x y : E}\n  (hx : x ∈ convex_hull ℝ s) (hy : y ∈ convex_hull ℝ t) :\n  ∃ (x' ∈ s) (y' ∈ t), dist x y ≤ dist x' y' :=\nbegin\n  rcases convex_hull_exists_dist_ge hx y with ⟨x', hx', Hx'⟩,\n  rcases convex_hull_exists_dist_ge hy x' with ⟨y', hy', Hy'⟩,\n  use [x', hx', y', hy'],\n  exact le_trans Hx' (dist_comm y x' ▸ dist_comm y' x' ▸ 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 $ λ x hx y hy, _).antisymm (emetric.diam_mono $ subset_convex_hull ℝ s),\n  rcases convex_hull_exists_dist_ge2 hx hy with ⟨x', hx', y', hy', H⟩,\n  rw edist_dist,\n  apply le_trans (ennreal.of_real_le_of_real H),\n  rw ← 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) ↔ 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 (λ x, metric.nhds_basis_ball)\n  (λ 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 ∈ [x -[ℝ] 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\n/-- The set of vectors in the same ray as `x` is connected. -/\nlemma is_connected_set_of_same_ray (x : E) : is_connected {y | same_ray ℝ x y} :=\nbegin\n  by_cases hx : x = 0, { simpa [hx] using is_connected_univ },\n  simp_rw ←exists_nonneg_left_iff_same_ray hx,\n  exact is_connected_Ici.image _ ((continuous_id.smul continuous_const).continuous_on)\nend\n\n/-- The set of nonzero vectors in the same ray as the nonzero vector `x` is connected. -/\nlemma is_connected_set_of_same_ray_and_ne_zero {x : E} (hx : x ≠ 0) :\n  is_connected {y | same_ray ℝ x y ∧ y ≠ 0} :=\nbegin\n  simp_rw ←exists_pos_left_iff_same_ray_and_ne_zero hx,\n  exact is_connected_Ioi.image _ ((continuous_id.smul continuous_const).continuous_on)\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/normed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7596657878589688}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world8.level10 -- hide\nnamespace mynat -- hide\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 → b = 0`.\nHopefully `add_right_eq_zero` shouldn't be too hard now.\n-/\n\n/- Lemma\nIf $a$ and $b$ are natural numbers such that \n$$ a + b = 0, $$\nthen $a = 0$.\n-/\nlemma add_right_eq_zero {a b : mynat} : a + b = 0 → a = 0 :=\nbegin [nat_num_game]\n  intro H,\n  rw add_comm at H,\n  exact add_left_eq_zero H,\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/level11.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.945801267121407, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7596427987690402}}
{"text": "import data.set\nimport tactic\n\n-- dEAduction imports\nimport logics\nimport structures\nimport definitions\n\nlemma definition.iff {P Q : Prop} : ( P ↔ Q ) ↔ (P → Q) ∧ (Q → P) := \niff_def\n\nnamespace set_theory -- Course title\n/- dEAduction\nSection\n    Set theory\n-/\n\nvariables {X : Type} {Y : Type}\n\nlemma definition.inclusion (A B : set X) : A ⊆ B ↔ ∀ {{x:X}}, x ∈ A → x ∈ B :=\niff.rfl\n\nlemma definition.equality_two_sets {A A' : set X} : (A = A') ↔ ( ∀ x, x ∈ A ↔ x ∈ A' ) :=\n/- dEAduction\nPrettyName\n    Equality of two sets\n-/\nby exact set.ext_iff\n\nlemma theorem.double_inclusion {A A' : set X} : (A = A') ↔ (A ⊆ A' ∧ A' ⊆ A) :=\nbegin\n    exact le_antisymm_iff\nend\n\n\nnamespace unions_and_intersections -- Section 1\n\n\nlemma definition.intersection_two_sets (A B : set X) (x : X) :  x ∈ A ∩ B ↔ ( x ∈ A ∧ x ∈ B) :=\niff.rfl\n/- dEAduction\nPrettyName\n    Intersection of two sets\n-/\n\nlemma theorem.included_in_intersection_iff  (A B C : set X) : C ⊆ A ∩ B ↔ C ⊆ A ∧ C ⊆ B :=\nbegin\n    exact ball_and_distrib\nend\n\nlemma definition.intersection_arbitrary_sets (I : Type) (O : I → set X)  (x : X) : (x ∈ set.Inter O) ↔ (∀ i:I, x ∈ O i) :=\nset.mem_Inter\n/- dEAduction\nPrettyName\n    Intersection of an arbitrary family of sets\n-/\n\nlemma definition.union_two_sets  (A : set X) (B : set X) (x : X) :  x ∈ A ∪ B ↔ ( x ∈ A ∨ x ∈ B) :=\niff.rfl\n/- dEAduction\nPrettyName\n    Union of two sets\n-/\n\nlemma definition.union_arbitrary_sets (I : Type) (O : I → set X)  (x : X) : (x ∈ set.Union O) ↔ (∃ i:I, x ∈ O i) :=\nset.mem_Union\n/- dEAduction\nPrettyName\n    Union of an arbitrary family of sets\n-/\n\nlemma exercise.intersection_dist_over_union (X : Type) (A B C : set X) : A ∩ (B ∪ C)  = (A ∩ B) ∪ (A ∩ C) :=\n/- dEAduction\nPrettyName\n    Intersection distributes over union\nDescription\n    The intersection of sets distributes over the union of sets.\nTools->Logic\n    $ALL -implicate -negate\nTools->ProofTechniques\n    $ALL -contradiction\nTools->Definitions\n    $UNTIL_NOW\nTools->Theorems\n    double_inclusion\nExpectedVarsNumber\n    X=3, A=1, B=1\n-/\nbegin\n    defi set_theory.definition.equality_two_sets,\n    intro x,\n    defi definition.iff,\n    split,\n    intro H,\n    defi set_theory.unions_and_intersections.definition.intersection_two_sets at H,\n    ET H,\n    defi set_theory.unions_and_intersections.definition.union_two_sets at HB,\n    OU HB,\n    ET HA HA_1,\n    defi set_theory.unions_and_intersections.definition.intersection_two_sets at H,\n    defi set_theory.unions_and_intersections.definition.union_two_sets,\n    OU gauche,\n    assumption,\nend\n\nvariables {A B C : set X}\n\nlemma exercise.union_dist_over_union : A ∪ (B ∩ C)  = (A ∪ B) ∩ (A ∪ C) :=\n/- dEAduction\nPrettyName\n    Union distributes over intersection\nDescription\n    The union of sets distributes over the intersection of sets.\nTools->Logic\n    $ALL\nTools->ProofTechniques\n    $ALL -choice\nTools->Statements\n    $UNTIL_NOW\n-/\nbegin\n    sorry\nend\n\nend unions_and_intersections\n\n\nnamespace complements -- section 2\n/- dEAduction\nSection\n    Complements\n-/\n\n\nlemma definition.complement {A : set X} {x : X} : x ∈ set.univ \\ A ↔ x ∉ A :=\nby finish\n\nlemma definition.complement_1 {A : set X} {x : X} : x ∈ set.compl A ↔ x ∉ A :=\nby finish\n\nlemma definition.complement_2 {A B : set X} {x : X} : x ∈ B \\ A ↔ (x ∈ B ∧ x ∉ A) :=\niff.rfl\n\nlemma exercise.complement_of_complement {A : set X} : - - A = A :=\n/- dEAduction\nPrettyName\n    Complement of complement\nDescription\n    Every set equals the complement of its complement.\n-/\nbegin\n    sorry\nend\n\nend complements\nend set_theory\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/trash/exercises_test2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107984180245, "lm_q2_score": 0.8104789040926008, "lm_q1q2_score": 0.7595895808055919}}
{"text": "-- Suma_de_fila_del_triangulo_de_Pascal.lean\n-- Suma de fila del triángulo de Pascal\n-- José A. Alonso Jiménez\n-- Sevilla, 25 de julio de 2021\n-- ---------------------------------------------------------------------\n\nimport tactic\nimport data.finset.basic\nopen finset nat\nopen_locale big_operators\n\ntheorem sum_pascal_row (n : ℕ) :\n  ∑ (m : ℕ) in range (n + 1), (choose n m) = 2 ^ n :=\nbegin\n  induction n with d hd,\n  { refl },\n  { calc ∑ i in range (d + 2), choose (d + 1) i\n        = ∑ i in range (d + 1), choose (d + 1) (i + 1) + 1\n          : by simp [sum_range_succ']\n    ... = ∑ i in range (d + 1), (choose d i + choose d (i+1)) + 1\n          : rfl\n    ... = ∑ i in range (d + 1), choose d i +\n          ∑ i in range (d + 1), choose d (i+1) + 1\n          : by rw sum_add_distrib\n    ... = 2^d + ∑ i in range (d + 1), choose d (i+1) + 1\n          : by rw hd\n    ... = 2^d + ∑ i in range d, choose d (i+1) + 1\n          : by simp [sum_range_succ]\n    ... = 2^d + ∑ i in range (d + 1), choose d i\n          : by simp [sum_range_succ', add_assoc]\n    ... = 2^d + 2^d\n          : by rw hd\n    ... = 2*2^d\n          : by ring,\n  }\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/Suma_de_fila_del_triangulo_de_Pascal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107861416414, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7595895794364226}}
{"text": "open nat\n\ndef double : nat → nat := fun x, x + x\ndef do_twice : (nat → nat) → nat → nat := fun f x, f (f x)\n\n#eval do_twice double 2\n\n-- Define Do_Twice : ((ℕ → ℕ) → (ℕ → ℕ)) → (ℕ → ℕ) → (ℕ → ℕ) which applies\n-- its argument twice, so that Do_Twice do_twice is a function that applies its \n-- input four times.\ndef Do_Twice : ((nat → nat) -> (nat → nat)) → (nat → nat) → (nat → nat) :=\n  fun metaFun ordFun, metaFun (metaFun ordFun)\n\n#eval Do_Twice do_twice double 2\n\ndef curry (a b c : Type*) (f : a × b → c) : a → b → c := \n  fun a1 b1, f (a1,b1)\n\ndef uncurry (a b c : Type*) (f : a → b → c) : a × b → c := \n  fun pair, f pair.fst pair.snd\n\nuniverse u\nconstant vec : Type u -> nat -> Type u\n\nnamespace vec\nconstant empty : Π {α : Type u}, vec α 0\nconstant cons : Π {α : Type u} {n : ℕ}, α → vec α n → vec α (succ n)\nconstant append : Π (α : Type u) (n m : ℕ), vec α m -> vec α n -> vec α (m + n)\n-- Above, we used the example vec α n for vectors of elements of type α 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_add : Π {α : Type u}  {n : ℕ}, vec α n -> vec α n -> vec α n\nconstant vec_reverse : Π {α : Type u}  {n : ℕ}, vec α n -> vec α n\n#check vec_add empty empty\n\nend vec\n\nconstant matrix : Type u → ℕ → ℕ → Type u\n\nnamespace matrix\nconstant empty :  Π {α : Type u}, matrix α 0 0\nconstant matrix_add : Π {α : Type u} {n : ℕ} {m : ℕ}, \n  matrix α n m → matrix α n m → matrix α n m\nconstant matrix_mult : Π {α : Type u} {n : ℕ} {m : ℕ} {p : ℕ},\n  matrix α n m → matrix α m p → matrix α n p\nconstant vec_mult :  Π {α : Type u} {n : ℕ} {m : ℕ},\n  matrix α n m → vec α m → vec α n\n\n#check vec_mult\n#check vec_mult empty vec.empty\nend matrix", "meta": {"author": "nicklecompte", "repo": "LeanLearning", "sha": "cb1a51f159569194b951441bb1940650e09ccc34", "save_path": "github-repos/lean/nicklecompte-LeanLearning", "path": "github-repos/lean/nicklecompte-LeanLearning/LeanLearning-cb1a51f159569194b951441bb1940650e09ccc34/src/Chapter2Exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.8128673223709252, "lm_q1q2_score": 0.7595392967810585}}
{"text": "import data.nat.prime data.nat.parity\n\nopen nat\n\n-- BEGIN\nvariable (s : set ℕ)\n\nexample (h : ∃ x ∈ s, ¬ even x ∧ nat.prime x) :\n  ∃ x ∈ s, nat.prime x :=\nbegin\n  rcases h with ⟨x, xs, _, prime_x⟩,\n  use [x, xs, prime_x],\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/ex4_use_even_prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951661947455, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7595392925451165}}
{"text": "-- Stuff that's not there yet\n\nclass One (α : Type u) where\n  one : α\n\ninstance [One α] : OfNat α (natLit! 1) where\n  ofNat := One.one\n\nclass Inv (α : Type u) where\n  inv : α → α\n\npostfix:max \"⁻¹\" => Inv.inv\n\n-- where is `u` coming from?\ndef Function.injective {α : Sort u} {β : Sort v} (f : α → β) : Prop :=\n  ∀ a₁ a₂ : α, f a₁ = f a₂ → a₁ = a₂\n\ntheorem Function.injective.eqIff {α : Sort u} {β : Sort v} {f : α → β} (I : Function.injective f) {a b : α} :\n  f a = f b ↔ a = b :=\n⟨I a b, λ h => congrArg _ h⟩\n\n-- Actual File from mathlib\n\nuniverse u\n\nsection Mul\n\nvariables {G : Type u} [Mul G] \n\ndef leftMul : G → G → G := λ g : G => λ x : G => g * x \n\ndef rightMul : G → G → G := λ g : G => λ x : G => x * g\n\nend Mul\n\nclass Semigroup (G : Type u) extends Mul G where\n  mulAssoc : ∀ a b c : G, (a * b) * c = a * (b * c)\n\nsection Semigroup\n\nvariables {G : Type u} [Semigroup G]\n\ntheorem mulAssoc : ∀ a b c : G, (a * b) * c = a * (b * c) := Semigroup.mulAssoc\n\nend Semigroup\n\nclass CommSemigroup (G : Type u) extends Semigroup G where\n  mulComm : ∀ a b : G, a * b = b * a\n\nsection CommSemigroup\n\nvariables {G : Type u} [CommSemigroup G]\n\ntheorem mulComm : ∀ a b : G, a * b = b * a := CommSemigroup.mulComm\n\nend CommSemigroup\n\nclass LeftCancelSemigroup (G : Type u) extends Semigroup G where\n  mulLeftCancel : ∀ a b c : G, a * b = a * c → b = c\n\nsection LeftCancelSemigroup\n\nvariables {G : Type u} [LeftCancelSemigroup G] {a b c : G}\n\ntheorem mulLeftCancel : a * b = a * c → b = c := LeftCancelSemigroup.mulLeftCancel a b c\n\ntheorem mulLeftCancelIff : a * b = a * c ↔ b = c :=\n⟨mulLeftCancel, congrArg _⟩\n\n-- It's \\centerdot\ntheorem mulRightInjective (a : G) : Function.injective ((a * ·)) :=\nλ b c => mulLeftCancel\n\ntheorem mulRightInj (a : G) {b c : G} : a * b = a * c ↔ b = c :=\n(mulRightInjective a).eqIff\n\nend LeftCancelSemigroup\n\nclass RightCancelSemigroup (G : Type u) extends Semigroup G where\n  mulRightCancel : ∀ a b c : G, a * b = c * b → a = c\n\nsection RightCancelSemigroup\n\nvariables {G : Type u} [RightCancelSemigroup G] {a b c : G}\n\ntheorem mulRightCancel : a * b = c * b → a = c := RightCancelSemigroup.mulRightCancel a b c\n\ntheorem mulRightCancelIff : a * b = c * b ↔ a = c :=\n⟨mulRightCancel, congrArg (· * b)⟩ -- mathlib Lean 3 proof is ⟨mul_right_cancel, congr_arg _⟩\n\ntheorem mulLeftInjective (a : G) : Function.injective (· * a) :=\nλ b c => mulRightCancel\n\ntheorem mulLeftInj (a : G) {b c : G} : b * a = c * a ↔ b = c :=\n(mulLeftInjective a).eqIff\n\nend RightCancelSemigroup\n\nclass Monoid (M : Type u) extends Semigroup M, One M where\n  oneMul : ∀ a : M, 1 * a = a\n  mulOne : ∀ a : M, a * 1 = a\n\nsection Monoid\n\nvariables {M : Type u} [Monoid M]\n\ntheorem oneMul : ∀ a : M, 1 * a = a := Monoid.oneMul\n\ntheorem mulOne : ∀ a : M, a * 1 = a := Monoid.mulOne\n\ntheorem leftInvEqRightInv {a b c : M} (hba : b * a = 1) (hac : a * c = 1) : b = c := by\n  rw [←oneMul c, ←hba, mulAssoc, hac, mulOne]\n\nend Monoid\n\n-- This no longer `extends` `CommSemigroup`\nclass CommMonoid (M : Type u) extends Monoid M where\n  mulComm : ∀ a b : M, a * b = b * a\n\n-- Instead, we have an instance going from `CommMonoid` to `CommSemigroup`\ninstance {M : Type u} [CommMonoid M] : CommSemigroup M where\n  mulComm := CommMonoid.mulComm\n\nsection LeftCancelMonoid\n\n-- Again, we only extend one `class` and we provide an instance to the other\nclass LeftCancelMonoid (M : Type u) extends Monoid M where\n  mulLeftCancel : ∀ a b c : M, a * b = a * c → b = c\n\ninstance {M : Type u} [LeftCancelMonoid M] : LeftCancelSemigroup M where\n  mulLeftCancel := LeftCancelMonoid.mulLeftCancel\n\nclass LeftCancelCommMonoid (M : Type u) extends LeftCancelMonoid M where\n  mulComm : ∀ a b : M, a * b = b * a\n\ninstance {M : Type u} [LeftCancelCommMonoid M] : CommMonoid M where\n  mulComm := LeftCancelCommMonoid.mulComm\n\nend LeftCancelMonoid\n\nsection RightCancelMonoid \n\nclass RightCancelMonoid (M : Type u) extends Monoid M where\n  mulRightCancel : ∀ a b c : M, a * b = c * b → a = c\n\ninstance {M : Type u} [RightCancelMonoid M] : RightCancelSemigroup M where\n  mulRightCancel := RightCancelMonoid.mulRightCancel\n\nclass RightCancelCommMonoid (M : Type u) extends RightCancelMonoid M where\n  mulComm : ∀ a b : M, a * b = b * a\n\ninstance {M : Type u} [RightCancelCommMonoid M] : CommMonoid M where\n  mulComm := RightCancelCommMonoid.mulComm\n\nend RightCancelMonoid\n\nsection CancelMonoid\n\nclass CancelMonoid (M : Type u) extends LeftCancelMonoid M where\n  mulRightCancel : ∀ a b c : M, a * b = c * b → a = c\n\ninstance {M : Type u} [CancelMonoid M] : RightCancelMonoid M where\n  mulRightCancel := CancelMonoid.mulRightCancel\n\nclass CancelCommMonoid (M : Type u) extends LeftCancelCommMonoid M where\n  mulRightCancel : ∀ a b c : M, a * b = c * b → a = c\n\ninstance {M : Type u} [CancelCommMonoid M] : RightCancelCommMonoid M where\n  mulRightCancel := CancelCommMonoid.mulRightCancel\n  mulComm := λ a b => mulComm a b -- why is the λ necessary?\n\nend CancelMonoid\n\nclass DivInvMonoid (G : Type u) extends Monoid G, Inv G, Div G where\n  div := λ a b => a * b⁻¹\n  divEqMulInv : ∀ a b : G, a / b = a * b⁻¹\n\ntheorem divEqMulInv {G : Type u} [DivInvMonoid G] :\n  ∀ a b : G, a / b = a * b⁻¹ :=\nDivInvMonoid.divEqMulInv\n\nclass Group (G : Type u) extends DivInvMonoid G where\n  mulLeftInv : ∀ a : G, a⁻¹ * a = 1\n\ndef Group.toMonoid (G : Type u) [Group G] : Monoid G :=\n  (Group.toDivInvMonoid (G := G)).toMonoid -- no more underscores!\n\nsection Group\n\nvariables {G : Type u} [Group G] {a b c : G}\n\n@[simp]\ntheorem mulLeftInv : ∀ a : G, a⁻¹ * a = 1 := Group.mulLeftInv\n\n@[simp]\ntheorem invMulCancelLeft (a b : G) : a⁻¹ * (a * b) = b := by\n  rw [←mulAssoc, mulLeftInv, oneMul]\n\n@[simp]\ntheorem invEqOfMulEqOne (h : a * b = 1) : a⁻¹ = b :=\n  leftInvEqRightInv (mulLeftInv _) h\n\n@[simp]\ntheorem invInv (a : G) : a⁻¹⁻¹ = a :=\n  invEqOfMulEqOne (mulLeftInv _)\n\n@[simp]\ntheorem mulRightInv (a : G) : a * a⁻¹ = 1 :=\n  have a⁻¹⁻¹ * a⁻¹ = 1 := mulLeftInv a⁻¹\n  by rw invInv at this\n     assumption\n\ntheorem mulInv (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := by\n  apply invEqOfMulEqOne\n  rw [← mulAssoc, mulAssoc _ b, mulRightInv, mulOne, mulRightInv]\n\ntheorem invMulInvEqInvMul (a b : G) : (a⁻¹ * b)⁻¹ = b⁻¹ * a := by \n  rw [mulInv, invInv]\n\ntheorem mulInvSelf (a : G) : a * a⁻¹ = 1 := mulRightInv a\n\n@[simp]\ntheorem mulInvCancelRight (a b : G) : a * b * b⁻¹ = a := by\n  rw [mulAssoc, mulRightInv, mulOne]\n\ninstance : CancelMonoid G where \n  mulLeftCancel := λ a b c h => by rw [←invMulCancelLeft a b, h, invMulCancelLeft]\n  mulRightCancel := λ a b c h => by rw [←mulInvCancelRight a b, h, mulInvCancelRight]\n\nend Group\n\nclass CommGroup (G : Type u) extends Group G where\n  mulComm : ∀ a b : G, a * b = b * a\n\ninstance (G : Type u) [CommGroup G] : CommMonoid G where\n  mulComm := CommGroup.mulComm\n\ndef Set (α : Type u) := α → Prop\n\nnamespace Set\n\nvariables {α : Type u} {s : Set α}\n\ndef mem (a : α) (s : Set α) := s a\n\ninfix:50 \" ∈ \" => Set.mem\n\ninstance : CoeSort (Set α) (Type u) where \n  coe s := Subtype s\n\ntheorem ext {s t : Set α} (h : ∀ x, x ∈ s ↔ x ∈ t) : s = t := \n  funext <| λ x => propext <| h x\n\n-- instance : Coe (Set α) α := ⟨ λ a => a.1 ⟩ \n\nend Set\n\nstructure Subgroup (G : Type u) [Group G] :=\n(carrier : Set G)\n(oneMem' : 1 ∈ carrier)\n(mulMem' {x y} : x ∈ carrier → y ∈ carrier → (x * y) ∈ carrier)\n(invMem' {x} : x ∈ carrier → x⁻¹ ∈ carrier)\n\n-- We try out the suggestion about membership where we do not make a membership \n-- relation for subgroups\n\nnamespace Subgroup\n\nvariables {G : Type u} [Group G] {H : Subgroup G}\n\ntheorem oneMem : 1 ∈ H.carrier := H.oneMem'\n\ntheorem mulMem {x y : G} (hx : x ∈ H.carrier) (hy : y ∈ H.carrier.mem) : \n  H.carrier.mem (x * y) := H.mulMem' hx hy\n\ntheorem invMem {x : G} (hx : x ∈ H.carrier) : x⁻¹ ∈ H.carrier := \n  H.invMem' hx\n\ntheorem mkInj (s t : Set G) (hs₁ : 1 ∈ s) (ht₁ : 1 ∈ t) \n  (hs₂ : ∀ {x y}, x ∈ s → y ∈ s → (x * y) ∈ s) \n  (ht₂ : ∀ {x y}, x ∈ t → y ∈ t → (x * y) ∈ t) \n  (hs₃ : ∀ {x}, x ∈ s → x⁻¹ ∈ s)\n  (ht₃ : ∀ {x}, x ∈ t → x⁻¹ ∈ t) (hst : s = t) : \n  Subgroup.mk s hs₁ hs₂ hs₃ = Subgroup.mk t ht₁ ht₂ ht₃ := by subst hst; rfl\n\ntheorem ext' {H K : Subgroup G} (h : H.carrier = K.carrier) : H = K := by\n  cases H; cases K\n  apply mkInj; allGoals { assumption }\n\ntheorem invMemIff {x : G} : x⁻¹ ∈ H.carrier ↔ x ∈ H.carrier := by\n  apply Iff.intro\n  { intro hx; rw ← invInv x;\n    exact invMem hx }\n  { exact invMem }\n\ninstance : Coe (Subgroup G) (Set G) := ⟨ Subgroup.carrier ⟩\n\ninstance : CoeSort (Subgroup G) (Type u) where \n  coe s := Subtype s.carrier\n\ninstance ofSubgroup (H : Subgroup G) : Group (coeSort H) where\n  mul := λ x y => ⟨ x.1 * y.1, H.mulMem x.2 y.2 ⟩ \n  one := ⟨ 1, H.oneMem ⟩  \n  inv := λ x => ⟨ x.1⁻¹, H.invMem x.2 ⟩\n  oneMul := λ x => by { cases x; apply Subtype.eq; exact oneMul _ }\n  mulOne := λ x => by { cases x; apply Subtype.eq; exact mulOne _ }\n  mulAssoc := λ x y z => by \n    { cases x; cases y; cases z; apply Subtype.eq;\n      exact mulAssoc _ _ _ }\n  divEqMulInv := λ x y => rfl\n  mulLeftInv := λ x => by { cases x; apply Subtype.eq; exact mulLeftInv _ }\n\n@[simp] theorem coeMul (a b : G) (ha : a ∈ H.carrier) (hb : b ∈ H.carrier) :\n  (⟨a, ha⟩ * ⟨b, hb⟩ : H).1 = a * b := rfl\n\ndef LCoset (g : G) (H : Subgroup G) : Set G := \n  (λ s => ∃ k, ∃ (h : k ∈ H.carrier), s = g * k)\n\ninfix:70 \" ⋆ \" => LCoset\n\ntheorem selfMemLCoset (x : G) (H : Subgroup G): x ∈ x ⋆ H := \n  ⟨ 1, ⟨ H.oneMem, (mulOne x).symm ⟩ ⟩ \n\ntheorem LCosetEq {x y : G} : x ⋆ H = y ⋆ H ↔ x⁻¹ * y ∈ H := by \n  apply Iff.intro\n  { intro h;\n    have h' : x ∈ y ⋆ H := by \n    { rw ← h;\n      exact selfMemLCoset _ _ };\n    cases h' with | intro k hk => \n    cases hk with | intro hk hk' => \n    { rw [hk', mulInv, mulAssoc, mulLeftInv, mulOne];\n      exact invMem hk  } }\n  { intro h;\n    apply Set.ext;\n    intro t;\n    apply Iff.intro;\n    { intro ht;\n      cases ht with | intro g hg => \n      cases hg with | intro hg₀ hg₁ => \n      { rw hg₁;\n        apply Exists.intro (y⁻¹ * x * g);\n        apply Exists.intro <| H.mulMem _ hg₀;\n        rw [← mulAssoc, ← mulAssoc, mulRightInv, oneMul];\n        rw [← invMulInvEqInvMul];\n        exact H.invMem h } }\n    { intro ht;\n      cases ht with | intro g hg => \n      cases hg with | intro hg₀ hg₁ => \n      { rw hg₁;\n        apply Exists.intro (x⁻¹ * y * g);\n        apply Exists.intro <| H.mulMem h hg₀;\n        rw [← mulAssoc, ← mulAssoc, mulRightInv, oneMul] } } }\n\ntheorem oneLCosetEqSelf : 1 ⋆ H = H := by\n  apply Set.ext;\n  intro x; \n  apply Iff.intro;\n  { intro hx;\n    cases hx with | intro h hh => \n    cases hh with | intro hh₀ hh₁ => \n    { rw [hh₁, oneMul]; assumption } }\n  { intro hx;\n    apply Exists.intro x;\n    apply Exists.intro hx;\n    rw oneMul }\n\ntheorem memSubgroupIff (x : G) : x ∈ H.carrier ↔ x ∈ H := Iff.rfl\n\ntheorem lcoset_of_mem {a : G} :\n  a ⋆ H = H ↔ a ∈ H := by \n  rw [← oneLCosetEqSelf, LCosetEq, mulOne, oneLCosetEqSelf, \n      ← memSubgroupIff, invMemIff]; exact Iff.rfl\n  \ntheorem lcoset_digj {a b c : G} (ha : c ∈ a ⋆ H) (hb : c ∈ b ⋆ H) : \n  a ⋆ H = b ⋆ H := by\n  { let ⟨g₀, ⟨hg₀, hca⟩⟩ := ha; let ⟨g₁, ⟨hg₁, hcb⟩⟩ := hb;\n    rw [LCosetEq, show b = c * g₁⁻¹ by simp [hcb]];\n    rw (show a⁻¹ = g₀ * c⁻¹ by rw [(show a = c * g₀⁻¹ by \n      rw [hca, mulAssoc, mulRightInv, mulOne]), mulInv, invInv]);\n    rw [← mulAssoc, mulAssoc _ _ c, mulLeftInv, mulOne];\n    exact H.mulMem hg₀ (H.invMem hg₁) }\n\nend Subgroup\n\n", "meta": {"author": "JasonKYi", "repo": "funWithLean4", "sha": "c00cff02380e83253cc5c9f36e25b1a4e445ef09", "save_path": "github-repos/lean/JasonKYi-funWithLean4", "path": "github-repos/lean/JasonKYi-funWithLean4/funWithLean4-c00cff02380e83253cc5c9f36e25b1a4e445ef09/src/group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.8705972616934406, "lm_q1q2_score": 0.7594632471973501}}
{"text": "import game.sup_inf.level01\n\nnamespace xena -- hide\n-- World name : Sup and Inf\n\n/-\n# Chapter 6 : Sup and Inf\n\n## Level 4  \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 ℝ) (x : ℝ) := x ∈ upper_bounds S \n-- (Definition above deprecated? GT)\n\ndefinition is_lub (S : set ℝ) (x : ℝ) := is_upper_bound S x ∧ \n∀ y : ℝ, is_upper_bound S y → x ≤ y\n\ndefinition has_lub (S : set ℝ) := ∃ 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 ℝ) (H : has_lub S) : \n  (S ≠ ∅) ∧ (∃ x, is_upper_bound S x) :=\nbegin\n  cases H with b Hb,\n  split,\n  intro t,\n  have H1 : (b-1) ∈ upper_bounds S,\n  change ∀ x ∈ S, x ≤ (b-1),\n  by_contradiction hn,\n  push_neg at hn,\n  cases hn with d hd,\n  cases hd with y hy,\n  rw t at y,\n  exact y,\n  unfold is_lub at Hb,\n  have HH := Hb.2 (b-1) H1,\n  linarith,\n\n  existsi b,\n  exact Hb.1,\n\n\nend \n\nend xena -- hide\n\n\n\n\n\n\n\n/-\ncases 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) ∈ upper_bounds S,\n    change ∀ x ∈ S, x ≤ (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\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/Completeness/level04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.7594632356403109}}
{"text": "/-\nCopyright (c) 2020 Patrick Massot. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Patrick Massot, Scott Morrison\n-/\nimport topology.instances.real\nimport topology.algebra.field\n\n/-!\n# The unit interval, as a topological space\n\nUse `open_locale unit_interval` to turn on the notation `I := set.Icc (0 : ℝ) (1 : ℝ)`.\n\nWe provide basic instances, as well as a custom tactic for discharging\n`0 ≤ x`, `0 ≤ 1 - x`, `x ≤ 1`, and `1 - x ≤ 1` when `x : I`.\n\n-/\n\nnoncomputable theory\nopen_locale classical topological_space filter\nopen set\n\n/-! ### The unit interval -/\n\n/-- The unit interval `[0,1]` in ℝ. -/\nabbreviation unit_interval : set ℝ := set.Icc 0 1\n\nlocalized \"notation `I` := unit_interval\" in unit_interval\n\nnamespace unit_interval\n\nlemma mem_iff_one_sub_mem {t : ℝ} : t ∈ I ↔ 1 - t ∈ I :=\nbegin\n  rw [mem_Icc, mem_Icc],\n  split ; intro ; split ; linarith\nend\n\ninstance has_zero : has_zero I := ⟨⟨0, by split ; norm_num⟩⟩\n\n@[simp, norm_cast] lemma coe_zero : ((0 : I) : ℝ) = 0 := rfl\n\ninstance has_one : has_one I := ⟨⟨1, by split ; norm_num⟩⟩\n\n@[simp, norm_cast] lemma coe_one : ((1 : I) : ℝ) = 1 := rfl\n\ninstance : nonempty I := ⟨0⟩\n\n/-- Unit interval central symmetry. -/\ndef symm : I → I := λ t, ⟨1 - t.val, mem_iff_one_sub_mem.mp t.property⟩\n\nlocalized \"notation `σ` := unit_interval.symm\" in unit_interval\n\n@[simp] lemma symm_zero : σ 0 = 1 :=\nsubtype.ext $ by simp [symm]\n\n@[simp] lemma symm_one : σ 1 = 0 :=\nsubtype.ext $ by simp [symm]\n\n@[continuity]\nlemma continuous_symm : continuous σ :=\nby continuity!\n\ninstance : connected_space I :=\nsubtype.connected_space ⟨nonempty_Icc.mpr zero_le_one, is_preconnected_Icc⟩\n\n/-- Verify there is an instance for `compact_space I`. -/\nexample : compact_space I := by apply_instance\n\nlemma nonneg (x : I) : 0 ≤ (x : ℝ) := x.2.1\nlemma one_minus_nonneg (x : I) : 0 ≤ 1 - (x : ℝ) := by simpa using x.2.2\nlemma le_one (x : I) : (x : ℝ) ≤ 1 := x.2.2\nlemma one_minus_le_one (x : I) : 1 - (x : ℝ) ≤ 1 := by simpa using x.2.1\n\nend unit_interval\n\nnamespace tactic.interactive\n\n/-- A tactic that solves `0 ≤ x`, `0 ≤ 1 - x`, `x ≤ 1`, and `1 - x ≤ 1` for `x : I`. -/\nmeta def unit_interval : tactic unit :=\n`[apply unit_interval.nonneg] <|> `[apply unit_interval.one_minus_nonneg] <|>\n`[apply unit_interval.le_one] <|> `[apply unit_interval.one_minus_le_one]\n\nend tactic.interactive\n\nsection\nvariables {𝕜 : Type*} [linear_ordered_field 𝕜] [topological_space 𝕜] [topological_ring 𝕜]\n\n/--\nThe image of `[0,1]` under the homeomorphism `λ x, a * x + b` is `[b, a+b]`.\n-/\n-- We only need the ordering on `𝕜` here to avoid talking about flipping the interval over.\n-- At the end of the day I only care about `ℝ`, so I'm hesitant to put work into generalizing.\nlemma affine_homeomorph_image_I (a b : 𝕜) (h : 0 < a) :\n  affine_homeomorph a b h.ne.symm '' set.Icc 0 1 = set.Icc b (a + b) :=\nby simp [h]\n\n/--\nThe affine homeomorphism from a nontrivial interval `[a,b]` to `[0,1]`.\n-/\ndef Icc_homeo_I (a b : 𝕜) (h : a < b) : set.Icc a b ≃ₜ set.Icc (0 : 𝕜) (1 : 𝕜) :=\nbegin\n  let e := homeomorph.image (affine_homeomorph (b-a) a (sub_pos.mpr h).ne.symm) (set.Icc 0 1),\n  refine (e.trans _).symm,\n  apply homeomorph.set_congr,\n  simp [sub_pos.mpr h],\nend\n\n@[simp] lemma Icc_homeo_I_apply_coe (a b : 𝕜) (h : a < b) (x : set.Icc a b) :\n  ((Icc_homeo_I a b h) x : 𝕜) = (x - a) / (b - a) :=\nrfl\n\n@[simp] lemma Icc_homeo_I_symm_apply_coe (a b : 𝕜) (h : a < b) (x : set.Icc (0 : 𝕜) (1 : 𝕜)) :\n  ((Icc_homeo_I a b h).symm x : 𝕜) = (b - a) * x + a :=\nrfl\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/topology/unit_interval.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.7594632313262268}}
{"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.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 → Y`, one can define `x_1 ≈ 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 → Z` such that `x_1 ≈ 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 → Y) (x_1 x_2 : X) : Prop :=\nf x_1 = f x_2\n\nlemma function.to_rel_def {X Y : Type} (f : X → Y) (x_1 x_2 : X) :\n(function.to_rel f) x_1 x_2 ↔ f x_1 = f x_2 :=\nbegin\n  refl,\nend\n\nlemma function.to_rel_refl {X Y : Type} (f : X → Y) : reflexive (function.to_rel f) :=\nbegin\n  intro x,\n  rw function.to_rel_def,\nend\n\nlemma function.to_rel_symm {X Y : Type} (f : X → Y) : symmetric (function.to_rel f) :=\nbegin\n  intros x x' hxx',\n  rw function.to_rel_def at *,\n  symmetry,\n  exact hxx',\nend\n\nlemma function.to_rel_trans {X Y : Type} (f : X → Y) : transitive (function.to_rel f) :=\nbegin\n  intros x x' x'' hxx' hx'x'',\n  rw function.to_rel_def at *,\n  rw [hxx', hx'x''],\nend\n\nlemma function.to_rel_equiv {X Y : Type} (f : X → Y) : equivalence (function.to_rel f) :=\nbegin\n  exact ⟨function.to_rel_refl f, function.to_rel_symm f, function.to_rel_trans f⟩,\nend\n\ninstance function.to_setoid {X Y : Type} (f : X → 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 → Y) : ∃ (Z : Type) (g : X → Z), \nfunction.surjective g ∧ ∀ x x' : X, f x = f x' ↔ g x = g x' :=\nbegin\n  use set.range f, \n  use set.range_factorization f,\n  split,\n  { exact set.surjective_onto_range, },\n  { intros x x',\n    split,\n    { intro h,\n      exact subtype.coe_inj.mp h },\n    { intro h,\n      exact subtype.mk.inj h, } }\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 → 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 → Y → Prop) (f : X → Y) \n  (x1 x2 : X) : Prop :=\nS (f x1) (f x2)\n\nlemma fun_rel.to_rel_def {X Y : Type} (S : Y → Y → Prop) (f : X → Y) \n(x_1 x_2 : X) : (fun_rel.to_rel S f) x_1 x_2 ↔ S (f x_1) (f x_2) :=\nbegin\n  refl,\nend\n\nlemma fun_rel.to_rel_refl {X Y : Type} {S : Y → Y → Prop} (hS : reflexive S) (f : X → Y) : \n  reflexive (fun_rel.to_rel S f) :=\nbegin\n  intro x,\n  rw fun_rel.to_rel_def,\n  exact hS (f x),\nend\n\nlemma fun_rel.to_rel_symm {X Y : Type} {S : Y → Y → Prop} (hS : symmetric S) (f : X → Y) : \n  symmetric (fun_rel.to_rel S f) :=\nbegin\n  intros x x' hxx',\n  rw fun_rel.to_rel_def at *,\n  exact hS hxx',\nend\n\nlemma fun_rel.to_rel_trans {X Y : Type} {S : Y → Y → Prop} (hS : transitive S) (f : X → Y) : \n  transitive (fun_rel.to_rel S f) :=\nbegin\n  intros x x' x'' hxx' hx'x'',\n  rw fun_rel.to_rel_def at *,\n  exact hS hxx' hx'x'',\nend\n\nlemma fun_rel.to_rel_equiv {X Y : Type} {S : Y → Y → Prop} (hS : equivalence S) (f : X → Y) : \n  equivalence (fun_rel.to_rel S f) :=\nbegin\n  exact ⟨fun_rel.to_rel_refl hS.1 f, fun_rel.to_rel_symm hS.2.1 f, fun_rel.to_rel_trans hS.2.2 f⟩,\nend\n\ninstance fun_rel.to_setoid {X Y : Type} {S : Y → Y → Prop} (hS : equivalence S) (f : X → 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 × 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 → X → Prop) (S : Y → Y → Prop) \n  (u v : X × Y) : Prop :=\nR u.1 v.1 ∧ S u.2 v.2\n\nlemma prod_rel_def {X Y : Type} {R : X → X → Prop} {S : Y → Y → Prop} (u v : X × Y) :\n  prod_rel R S u v ↔ R u.1 v.1 ∧ S u.2 v.2 := by refl \n\nlemma prod_rel_refl {X Y : Type} {R : X → X → Prop} {S : Y → Y → Prop} (hR : reflexive R)\n  (hS : reflexive S) : reflexive (prod_rel R S) :=\nbegin \n  intro x,\n  rw prod_rel_def,\n  exact ⟨hR x.1, hS x.2⟩,\nend\n\nlemma prod_rel_symm {X Y : Type} {R : X → X → Prop} {S : Y → Y → Prop} (hR : symmetric R)\n  (hS : symmetric S) : symmetric (prod_rel R S) :=\nbegin\n  intros u v huv,\n  exact ⟨hR huv.1, hS huv.2⟩,\nend\n\nlemma prod_rel_trans {X Y : Type} {R : X → X → Prop} {S : Y → Y → Prop} (hR : transitive R)\n  (hS : transitive S) : transitive (prod_rel R S) :=\nbegin\n  intros u v w huv hvw,\n  exact ⟨hR huv.1 hvw.1, hS huv.2 hvw.2⟩,\nend\n\nlemma prod_rel_equiv {X Y : Type} {R : X → X → Prop} {S : Y → Y → Prop} (hR : equivalence R)\n  (hS : equivalence S) : equivalence (prod_rel R S) :=\nbegin\n  exact ⟨prod_rel_refl hR.1 hS.1, prod_rel_symm hR.2.1 hS.2.1, prod_rel_trans hR.2.2 hS.2.2⟩ \nend", "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/sheet08.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7594216988706907}}
{"text": "\ntheorem same{P: Prop}: (¬P) = (P → false) := rfl\n\ntheorem zneqo : 0 ≠ 1.\n#check zneqo\n\ntheorem zneqoeqzneqo : (0 ≠ 1) = ¬(0 = 1) := rfl\n\ntheorem zneqo' : 0 = 1 → false := \n    λ h : (0 = 1), \n        nat.no_confusion h\n\ntheorem zneqo'' : ¬ 0 = 1 := \nbegin\n    assume h : (0 = 1),\n    show false,\n    from nat.no_confusion h\nend\n\n#reduce nat.add_zero\n#check nat.zero\n#reduce nat.succ(nat.zero)\n#reduce nat.succ(nat.succ(nat.zero))\n#reduce nat.succ(4)\n\ntheorem ttneqff : ¬tt = ff := \nbegin\n    assume h : (tt = ff),\n    show false,\n    from bool.no_confusion h\nend\n\ntheorem ttneqff' : tt ≠ ff.\n\ntheorem ex2 : 2 ≠ 1.\n\ntheorem proof_by_negation : ∀(P : Prop),\n    (P → false) → ¬P :=\n        λ P p, p\n\ntheorem proof_by_negation' : ∀(P : Prop),\n    (P → false) → ¬P :=\nbegin\n  assume P,\n  assume pf_P_to_f,\n  assume pf_P,\n  exact pf_P_to_f pf_P,\nend\n\nlemma zneqo''': ¬(0 = 1) :=\nbegin\n    apply proof_by_negation,\n    assume h: (0 = 1),\n    show false,\n    from (nat.no_confusion h)\nend\n\ntheorem qAndNotQfalse{Q: Prop}\n  (pf: Q ∧ ¬Q): false := \n    pf.right pf.left\n\nexample: ∀(Q: Prop), Q ∧ ¬Q → false :=\nbegin\n  assume Q,\n  assume pf_Q_and_not_Q,\n  have pf_Q := pf_Q_and_not_Q.left,\n  have pf_not_Q := pf_Q_and_not_Q.right,\n  contradiction,\nend\n\ntheorem no_contra : \n∀(Q: Prop), ¬(Q ∧ ¬Q) :=\n    λ (Q : Prop) (pf : Q ∧ ¬Q), \n        pf.right pf.left\n\ntheorem ncab{a b: nat}: ¬((a = b) ∧ (a ≠ b)) :=\nbegin\n    apply no_contra,\nend\n\ntheorem ncab'{a b: nat}: ¬((a = b) ∧ (a ≠ b)) :=\nbegin\n  assume c : ((a = b) ∧ (a ≠ b)),\n  have pf_eq := c.left,\n  have pf_neq := c.right,\n  have f := pf_neq pf_eq,\n  assumption\nend\n\n-- classical logic\naxiom em: ∀(P: Prop), P ∨ ¬P\n\nexample: ¬¬true :=\nbegin\n  assume pf_not_true,\n  have pf_true := true.intro,\n  contradiction,\nend\n\ntheorem double_neg_elim: ∀{P: Prop}, ¬¬P → P := \nbegin\n  assume P : Prop,\n  assume pfNotNotP : ¬¬P,\n  cases (em P) with pf_P pf_not_P,\n    show P, from pf_P,\n\n    have f: false := pfNotNotP pf_not_P,\n    exact false.elim f\nend\n\ntheorem prove_P: ∀{P: Prop}, ¬¬P → P :=\n  λ(P)(pf_not_not_P),\n    double_neg_elim pf_not_not_P\n\ntheorem proof_by_contradiction : ∀(P : Prop),\n  (¬P → false) → P := \n    @double_neg_elim\n\ntheorem zeqz : 0 = 0 :=\nbegin\n  apply proof_by_contradiction,\n  assume pf: 0 = 0 → false,\n  show false,\n  from pf (eq.refl 0)\nend\n\nexample{P Q: Prop} \n  (pf: ¬P → (Q ∧ ¬ Q)): P :=\nbegin\n  apply proof_by_contradiction,\n  assume notP: ¬P,\n  have contra := (pf notP),\n  show false,\n  from no_contra Q contra\nend\n\ntheorem proof_by_contrapositive: \n  ∀(P Q : Prop), (¬Q → ¬P) → (P → Q) :=\nbegin\n  assume P Q: Prop,\n  assume pf_not_Q_to_not_P: (¬Q → ¬P),\n  assume pf_P : P,\n  have pf_not_Q_to_false: ¬Q → false :=\n    λ(pf_not_Q: ¬Q),\n      no_contra P (and.intro pf_P (pf_not_Q_to_not_P pf_not_Q)),\n  have pf_not_not_Q: ¬¬Q := pf_not_Q_to_false,\n  show Q,\n  from double_neg_elim pf_not_not_Q\nend\n\ntheorem proof_by_contrapositive': \n  ∀(P Q : Prop), (¬Q → ¬P) → (P → Q) :=\nbegin\n  assume P Q,\n  assume pf_not_Q_to_not_P: (¬Q → ¬P),\n  assume pf_P : P,\n  have pf_not_Q_to_false: ¬Q → false :=\n    begin\n      assume pf_not_Q,\n      have pf_not_P := pf_not_Q_to_not_P pf_not_Q,\n      exact pf_not_P pf_P\n    end,\n  have pf_not_not_Q: ¬¬Q := pf_not_Q_to_false,\n  show Q,\n  from double_neg_elim pf_not_not_Q\nend\n\ntheorem proof_by_contrapositive'': \n  ∀(P Q : Prop), (¬Q → ¬P) → (P → Q) :=\nbegin\n  assume P Q,\n  assume pf_not_Q_to_not_P: (¬Q → ¬P),\n  assume pf_P : P,\n  cases (em Q) with pf_Q pf_not_Q,\n    -- Q\n    assumption,\n    -- ¬Q\n    have pf_not_P := pf_not_Q_to_not_P pf_not_Q,\n    contradiction,\nend\n\ntheorem zeqz' : 0 = 0 → true :=\nbegin\n  apply proof_by_contrapositive,\n  assume nt : ¬true,\n  have pff := nt true.intro,\n  show ¬ 0 = 0,\n  from false.elim pff\nend\n\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/examples/negation_properties.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605947, "lm_q2_score": 0.8289388125473629, "lm_q1q2_score": 0.7593988209478207}}
{"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 data.nat.parity\nimport order.filter.at_top_bot\n\n/-!\n# Numbers are frequently modeq to fixed numbers\n\nIn this file we prove that `m ≡ d [MOD n]` frequently as `m → ∞`.\n-/\n\nopen filter\n\nnamespace nat\n\n/-- Infinitely many natural numbers are equal to `d` mod `n`. -/\nlemma frequently_modeq {n : ℕ} (h : n ≠ 0) (d : ℕ) : ∃ᶠ m in at_top, m ≡ d [MOD n] :=\n((tendsto_add_at_top_nat d).comp (tendsto_id.nsmul_at_top h.bot_lt)).frequently $\n  frequently_of_forall $ λ m, by { simp [nat.modeq_iff_dvd, ← sub_sub] }\n\nlemma frequently_mod_eq {d n : ℕ} (h : d < n) : ∃ᶠ m in at_top, m % n = d :=\nby simpa only [nat.modeq, mod_eq_of_lt h] using frequently_modeq h.ne_bot d\n\nlemma frequently_even : ∃ᶠ m : ℕ in at_top, even m :=\nby simpa only [even_iff] using frequently_mod_eq zero_lt_two\n\nlemma frequently_odd : ∃ᶠ m : ℕ in at_top, odd m :=\nby simpa only [odd_iff] using frequently_mod_eq one_lt_two\n\nend nat\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/filter/modeq.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096227509861, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7593988170392685}}
{"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\nuniverses u v\n\n/-- An NFA is a set of states (`σ`), 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 (α : Type u) (σ : Type v) :=\n(step : σ → α → set σ)\n(start : set σ)\n(accept : set σ)\n\nvariables {α : Type u} {σ σ' : Type v} (M : NFA α σ)\n\nnamespace NFA\n\ninstance : inhabited (NFA α σ) := ⟨ NFA.mk (λ _ _, ∅) ∅ ∅ ⟩\n\n/-- `M.step_set S a` is the union of `M.step s a` for all `s ∈ S`. -/\ndef step_set : set σ → α → set σ :=\nλ Ss a, Ss >>= (λ S, (M.step S a))\n\n\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 σ) : list α → set σ :=\nlist.foldl M.step_set start\n\n/-- `M.eval x` computes all possible paths though `M` with input `x` starting at an element of\n  `M.start`. -/\ndef eval := M.eval_from M.start\n\n/-- `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. -/\ndef accepts : language α :=\nλ x, ∃ S ∈ M.accept, S ∈ 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 α (set σ) :=\n{ step := M.step_set,\n  start := M.start,\n  accept := {S | ∃ s ∈ S, s ∈ 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 _ _ _ ∈ {S | _} ↔ _,\n  split; { exact λ ⟨w, h2, h3⟩, ⟨w, h3, h2⟩ },\nend\n\nlemma pumping_lemma [fintype σ] {x : list α} (hx : x ∈ M.accepts)\n  (hlen : fintype.card (set σ) ≤ list.length x) :\n  ∃ a b c, x = a ++ b ++ c ∧ a.length + b.length ≤ fintype.card (set σ) ∧ b ≠ [] ∧\n  {a} * language.star {b} * {c} ≤ M.accepts :=\nbegin\n  rw ←to_DFA_correct at hx ⊢,\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 α σ') : NFA α σ' :=\n{ step := λ 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 α σ) (start : σ) (s : list α) :\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 α σ) :\n  M.to_NFA.accepts = M.accepts :=\nbegin\n  ext x,\n  change (∃ S H, S ∈ M.to_NFA.eval_from {M.start} x) ↔ _,\n  rw to_NFA_eval_from_match,\n  split,\n  { rintro ⟨ S, hS₁, hS₂ ⟩,\n    rwa set.mem_singleton_iff.mp hS₂ at hS₁ },\n  { exact λ h, ⟨M.eval x, h, rfl⟩ }\nend\n\nend DFA\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/computability/NFA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7593988093335277}}
{"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 field_theory.finite.trace\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.RingTheory.Trace\nimport Mathbin.FieldTheory.Finite.GaloisField\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\n\nnamespace FiniteField\n\n/-- The trace map from a finite field to its prime field is nongedenerate. -/\ntheorem trace_to_zMod_nondegenerate (F : Type _) [Field F] [Finite F] {a : F} (ha : a ≠ 0) :\n    ∃ b : F, Algebra.trace (ZMod (ringChar F)) F (a * b) ≠ 0 :=\n  by\n  haveI : Fact (ringChar F).Prime := ⟨CharP.char_is_prime F _⟩\n  have htr := traceFormNondegenerate (ZMod (ringChar F)) F a\n  simp_rw [Algebra.traceForm_apply] at htr\n  by_contra' hf\n  exact ha (htr hf)\n#align finite_field.trace_to_zmod_nondegenerate FiniteField.trace_to_zMod_nondegenerate\n\nend FiniteField\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/Finite/Trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7593988075091754}}
{"text": "/-\nCopyright (c) 2022 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel\n\n! This file was ported from Lean 3 source module measure_theory.measure.haar_of_inner\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.Orientation\nimport Mathbin.MeasureTheory.Measure.HaarLebesgue\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\n\nopen FiniteDimensional MeasureTheory MeasureTheory.Measure Set\n\nvariable {ι F : Type _}\n\nvariable [Fintype ι] [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F]\n  [MeasurableSpace F] [BorelSpace F]\n\nsection\n\nvariable {m n : ℕ} [_i : Fact (finrank ℝ F = n)]\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. -/\ntheorem Orientation.measure_orthonormalBasis (o : Orientation ℝ F (Fin n))\n    (b : OrthonormalBasis ι ℝ F) : o.volumeForm.Measure (parallelepiped b) = 1 :=\n  by\n  have e : ι ≃ Fin n := by\n    refine' Fintype.equivFinOfCardEq _\n    rw [← _i.out, finrank_eq_card_basis b.to_basis]\n  have A : ⇑b = b.reindex e ∘ e := by\n    ext x\n    simp only [OrthonormalBasis.coe_reindex, Function.comp_apply, Equiv.symm_apply_apply]\n  rw [A, parallelepiped_comp_equiv, AlternatingMap.measure_parallelepiped,\n    o.abs_volume_form_apply_of_orthonormal, ENNReal.ofReal_one]\n#align orientation.measure_orthonormal_basis Orientation.measure_orthonormalBasis\n\n/-- In an oriented inner product space, the measure coming from the canonical volume form\nassociated to an orientation coincides with the volume. -/\ntheorem Orientation.measure_eq_volume (o : Orientation ℝ F (Fin n)) :\n    o.volumeForm.Measure = volume :=\n  by\n  have A : o.volume_form.measure (stdOrthonormalBasis ℝ F).toBasis.parallelepiped = 1 :=\n    Orientation.measure_orthonormalBasis o (stdOrthonormalBasis ℝ F)\n  rw [add_haar_measure_unique o.volume_form.measure\n      (stdOrthonormalBasis ℝ F).toBasis.parallelepiped,\n    A, one_smul]\n  simp only [volume, Basis.addHaar]\n#align orientation.measure_eq_volume Orientation.measure_eq_volume\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. -/\ntheorem OrthonormalBasis.volume_parallelepiped (b : OrthonormalBasis ι ℝ F) :\n    volume (parallelepiped b) = 1 :=\n  by\n  haveI : Fact (finrank ℝ F = finrank ℝ F) := ⟨rfl⟩\n  let o := (stdOrthonormalBasis ℝ F).toBasis.Orientation\n  rw [← o.measure_eq_volume]\n  exact o.measure_orthonormal_basis b\n#align orthonormal_basis.volume_parallelepiped OrthonormalBasis.volume_parallelepiped\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/HaarOfInner.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7593988056848227}}
{"text": "lemma {u} FOIL {R : Type u} [ring R] : ∀ a b c d : R, (a + b) * (c + d) = a*c + a*d + b*c + b*d :=\nby { intros, rw [left_distrib, right_distrib, right_distrib], ac_refl }\n\nlemma {u} FOIL_neg_square {R : Type u} [comm_ring R] : ∀ a b : R, (a - b) * (a - b) = a*a + (-(a*b)+ -(a*b)) + b*b :=\nby { intros, rw sub_eq_add_neg, rw FOIL,\n     rw neg_mul_neg, repeat { rw add_assoc }, congr,\n     rw neg_mul_eq_mul_neg, rw [mul_comm a b, neg_mul_eq_neg_mul] }\n\nlemma {u} FOIL_sub {R : Type u} [ring R] : ∀ a b c d : R, (a - b) * (c - d) = a*c - a*d - b*c + b*d :=\nby { intros, repeat { rw sub_eq_add_neg }, rw FOIL, rw neg_mul_eq_mul_neg, rw neg_mul_eq_neg_mul,\n     apply congr_arg, rw [← neg_mul_eq_mul_neg, ← neg_mul_eq_neg_mul, neg_neg] }\n\nlemma difference_of_squares {R} [comm_ring R] : ∀ x y : R, x * x - y*y = (x - y)*(x + y) :=\nbegin\n  intros, rw sub_eq_add_neg, rw sub_eq_add_neg,\n  rw FOIL, rw add_assoc (x*x), rw mul_comm (-y) x, \n  rw ← neg_mul_eq_mul_neg, rw ← sub_eq_add_neg (x*y),\n  rw sub_self, rw add_zero, congr, rw neg_mul_eq_mul_neg,\n  rw mul_comm\nend\n\nlemma div_of_div_eq_self {F} [field F] : ∀ x y : F, x ≠ 0 → y ≠ 0 → x/(x/y) = y :=\nbegin\n  intros, rw div_eq_mul_one_div x y,\n  rw field.div_mul_eq_div_mul_one_div _ a,\n  rw div_self a, rw one_mul,\n  rw [one_div_eq_inv, one_div_eq_inv],\n  rw division_ring.inv_inv a_1,\n  apply one_div_ne_zero a_1,\nend\n\nlemma square_neg_one {R} [ring R] : (-1)*(-1) = (1 : R) :=\nbegin\n  apply eq_of_sub_eq_zero, rw sub_eq_add_neg, \n  transitivity (-1)*(-1) + (-1)*(1:R), rw mul_one,\n  rw ← left_distrib, rw neg_add_self, rw mul_zero\nend\n\nlemma weird_analysis_trick {R} [ring R] \n  : ∀ a b c d : R, a * c = (a - b) * (c - d) + a * d + b * c - b * d :=\nbegin\n  intros, rw [sub_eq_add_neg a, sub_eq_add_neg c],\n  rw FOIL, rw [← neg_mul_eq_neg_mul b (-d), mul_neg_eq_neg_mul_symm b d, neg_neg],\n  rw add_right_comm _ (b*d), rw add_right_comm _ (b*d), rw add_sub_assoc,\n  rw [sub_self, add_zero], rw add_right_comm _ (-b*c),\n  rw [← neg_mul_eq_neg_mul, add_assoc, neg_add_self, add_zero],\n  rw [add_assoc, mul_neg_eq_neg_mul_symm, neg_add_self, add_zero]\nend\n\nlemma eq_zero_of_sqr_eq_zero {F} [division_ring F] [decidable_eq F]\n  : ∀ {x : F}, x * x = 0 → x = 0 :=\nbegin\n  intros x h, by_contra h', refine (_ : x * x ≠ 0) h,\n  apply division_ring.mul_ne_zero h' h'\nend\n\nlemma classical.l_or_r_eq_zero_of_mul_eq_zero {F} [division_ring F]\n  : ∀ {x y : F}, x * y = 0 → x = 0 ∨ y = 0 :=\nbegin\n  intros x y h, apply classical.by_contradiction,\n  rw @decidable.not_or_iff_and_not _ _ (classical.prop_decidable _) (classical.prop_decidable _),\n  intro h', apply division_ring.mul_ne_zero h'.left h'.right, assumption\nend\n\nlemma eq_sub_implies_sub_zero {G} [add_comm_group G]\n  : ∀ x y : G, x = x - y → y = 0 :=\nbegin\n  intros,\n  transitivity x - (x - y), { rw sub_sub_self x y },\n  rw ← a, apply sub_self\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/algebra.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7593985520550022}}
{"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.encodable\nopen nat encodable\n\n/-\nIn mathematics, the axiom of dependent choice is a weak form of the axiom of choice that is\nsufficient to develop most of real analysis. See http://en.wikipedia.org/wiki/Axiom_of_dependent_choice.\nWe can state it as follows:\n-/\ndefinition dependent_choice {A : Type} (R : A → A → Prop) :=\n(∀ a : A, ∃ b : A, R a b) → (∀ a : A, ∃ f : nat → A, f 0 = a ∧ ∀ n, R (f n) (f (n+1)))\n\n/-\nIf A is an encodable type, and R is a decidable relation, we can prove (dependent_choice R) using the\nconstructive choice function \"choose\"\n-/\nsection depchoice\n  parameters {A : Type} {R : A → A → Prop}\n  parameters [encA : encodable A] [decR : decidable_rel R]\n  include encA decR\n\n  local infix `~` := R\n\n  private definition f_aux (a : A) (H : ∀ a, ∃ b, a ~ b) : nat → A\n  | 0     := a\n  | (n+1) := choose (H (f_aux n))\n\n  theorem dependent_choice_of_encodable_of_decidable : dependent_choice R :=\n  assume H : ∀ a, ∃ b, a ~ b,\n  take   a : A,\n  let    f : nat → A := f_aux a H in\n  have   f_zero : f 0 = a,            from rfl,\n  have   R_seq  : ∀ n, f n ~ f (n+1), from\n    take n, show f n ~ choose (H (f n)), from !choose_spec,\n  exists.intro f (and.intro f_zero R_seq)\n\n  /-\n  The following slightly stronger version can be proved, where we also \"return\" the constructed function f.\n  We just have to use Σ instead of ∃, and use Σ-constructor instead of exists.intro.\n  Recall that ⟨f, H⟩ is notation for (sigma.mk f H)\n  -/\n  theorem stronger_dependent_choice_of_encodable_of_decidable\n          : (∀ a, ∃ b, R a b) → (∀ a, Σ f, f (0:nat) = a ∧ ∀ n, f n ~ f (n+1))  :=\n  assume H : ∀ a, ∃ b, a ~ b,\n  take   a : A,\n  let    f : nat → A := f_aux a H in\n  have   f_zero : f 0 = a,            from rfl,\n  have   R_seq  : ∀ n, f n ~ f (n+1), from\n    take n, show f n ~ choose (H (f n)), from !choose_spec,\n  ⟨f, and.intro f_zero R_seq⟩\n\nend depchoice\n\n/-\nIf we encode dependent_choice using Σ instead of ∃.\nThen, we can prove this version without using any extra hypothesis (e.g., A is encodable or R is decidable).\nThe function f can be constructed directly from the hypothesis: ∀ a : A, Σ b : A, R a b\nbecause Σ \"carries\" the witness 'b'. That is, we don't have to search for anything using \"choose\".\n-/\nopen sigma.ops\n\nsection sigma_depchoice\n  parameters {A : Type} {R : A → A → Prop}\n  local infix `~` := R\n\n  private definition f_aux (a : A) (H : ∀ a, Σ b, a ~ b) : nat → A\n  | 0     := a\n  | (n+1) := (H (f_aux n)).1\n\n  theorem sigma_dependent_choice : (∀ a, Σ b, R a b) → (∀ a, Σ f, f (0:nat) = a ∧ ∀ n, f n ~ f (n+1)) :=\n  assume H : ∀ a, Σ b, a ~ b,\n  take   a : A,\n  let    f : nat → A := f_aux a H in\n  have   f_zero : f 0 = a,            from rfl,\n  have   R_seq  : ∀ n, f n ~ f (n+1), from take n, (H (f n)).2,\n  ⟨f, and.intro f_zero R_seq⟩\nend sigma_depchoice\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/examples/depchoice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.759398549167618}}
{"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 linear_algebra.dual\n\n/-!\n# Contractions\n\nGiven modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps:\n$M^* \\otimes M \\to R$, $M \\otimes M^* \\to R$, and $M^* \\otimes N → Hom(M, N)$, as well as proving\nsome basic properties of these maps.\n\n## Tags\n\ncontraction, dual module, tensor product\n-/\n\nuniverses u v\n\n\nsection contraction\nopen tensor_product\nopen_locale tensor_product\n\nvariables (R : Type u) (M N : Type v)\nvariables [comm_ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N]\n\n/-- The natural left-handed pairing between a module and its dual. -/\ndef contract_left : (module.dual R M) ⊗ M →ₗ[R] R := (uncurry _ _ _ _).to_fun linear_map.id\n\n/-- The natural right-handed pairing between a module and its dual. -/\ndef contract_right : M ⊗ (module.dual R M) →ₗ[R] R :=\n(uncurry _ _ _ _).to_fun (linear_map.flip linear_map.id)\n\n/-- The natural map associating a linear map to the tensor product of two modules. -/\ndef dual_tensor_hom : (module.dual R M) ⊗ N →ₗ M →ₗ N :=\n  let M' := module.dual R M in\n  (uncurry R M' N (M →ₗ[R] N) : _ → M' ⊗ N →ₗ M →ₗ N) linear_map.smul_rightₗ\n\nvariables {R M N}\n\n@[simp] lemma contract_left_apply (f : module.dual R M) (m : M) :\n  contract_left R M (f ⊗ₜ m) = f m := by apply uncurry_apply\n\n@[simp] lemma contract_right_apply (f : module.dual R M) (m : M) :\n  contract_right R M (m ⊗ₜ f) = f m := by apply uncurry_apply\n\n@[simp] lemma dual_tensor_hom_apply (f : module.dual R M) (m : M) (n : N) :\n  dual_tensor_hom R M N (f ⊗ₜ n) m = (f m) • n :=\nby { dunfold dual_tensor_hom, rw uncurry_apply, refl, }\n\nend contraction\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/contraction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.7593985381357586}}
{"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.modeq\nimport algebra.parity\n\n/-!\n# Parity of 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 contains theorems about the `even` and `odd` predicates on the natural numbers.\n\n## Tags\n\neven, odd\n-/\n\nnamespace nat\n\nvariables {m n : ℕ}\n\n@[simp] theorem mod_two_ne_one : ¬ n % 2 = 1 ↔ n % 2 = 0 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\n@[simp] theorem mod_two_ne_zero : ¬ n % 2 = 0 ↔ n % 2 = 1 :=\nby cases mod_two_eq_zero_or_one n with h h; simp [h]\n\ntheorem even_iff : even n ↔ n % 2 = 0 :=\n⟨λ ⟨m, hm⟩, by simp [← two_mul, hm],\n  λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by simp [← two_mul, h])⟩⟩\n\ntheorem odd_iff : odd n ↔ n % 2 = 1 :=\n⟨λ ⟨m, hm⟩, by norm_num [hm, add_mod],\n λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by rw [h, add_comm])⟩⟩\n\nlemma not_even_iff : ¬ even n ↔ n % 2 = 1 :=\nby rw [even_iff, mod_two_ne_zero]\n\nlemma not_odd_iff : ¬ odd n ↔ n % 2 = 0 :=\nby rw [odd_iff, mod_two_ne_one]\n\nlemma even_iff_not_odd : even n ↔ ¬ odd n :=\nby rw [not_odd_iff, even_iff]\n\n@[simp] lemma odd_iff_not_even : odd n ↔ ¬ even n :=\nby rw [not_even_iff, odd_iff]\n\nlemma is_compl_even_odd : is_compl {n : ℕ | even n} {n | odd n} :=\nby simp only [←set.compl_set_of, is_compl_compl, odd_iff_not_even]\n\nlemma even_or_odd (n : ℕ) : even n ∨ odd n :=\nor.imp_right odd_iff_not_even.2 $ em $ even n\n\nlemma even_or_odd' (n : ℕ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 :=\nby simpa only [← two_mul, exists_or_distrib, ← odd, ← even] using even_or_odd n\n\nlemma even_xor_odd (n : ℕ) : xor (even n) (odd n) :=\nbegin\n  cases even_or_odd n with h,\n  { exact or.inl ⟨h, even_iff_not_odd.mp h⟩ },\n  { exact or.inr ⟨h, odd_iff_not_even.mp h⟩ },\nend\n\nlemma even_xor_odd' (n : ℕ) : ∃ k, xor (n = 2 * k) (n = 2 * k + 1) :=\nbegin\n  rcases even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩;\n  use k,\n  { simpa only [← 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 : ¬ 2 ∣ n ↔ n % 2 = 1 :=\neven_iff_two_dvd.symm.not.trans not_even_iff\n\ninstance : decidable_pred (even : ℕ → Prop) := λ n, decidable_of_iff _ even_iff.symm\ninstance : decidable_pred (odd : ℕ → Prop) := λ n, decidable_of_iff _ odd_iff_not_even.symm\n\ntheorem mod_two_add_add_odd_mod_two (m : ℕ) {n : ℕ} (hn : odd n) : m % 2 + (m + n) % 2 = 1 :=\n(even_or_odd m).elim (λ hm, by rw [even_iff.1 hm, odd_iff.1 (hm.add_odd hn)]) $\n  λ hm, by rw [odd_iff.1 hm, even_iff.1 (hm.add_odd hn)]\n\n@[simp] theorem mod_two_add_succ_mod_two (m : ℕ) : m % 2 + (m + 1) % 2 = 1 :=\nmod_two_add_add_odd_mod_two m odd_one\n\n@[simp] theorem succ_mod_two_add_mod_two (m : ℕ) : (m + 1) % 2 + m % 2 = 1 :=\nby rw [add_comm, mod_two_add_succ_mod_two]\n\nmk_simp_attribute parity_simps \"Simp attribute for lemmas about `even`\"\n\n@[simp] theorem not_even_one : ¬ even 1 :=\nby rw even_iff; norm_num\n\n@[parity_simps] theorem even_add : even (m + n) ↔ (even m ↔ even n) :=\nby cases mod_two_eq_zero_or_one m with h₁ h₁;\n   cases mod_two_eq_zero_or_one n with h₂ h₂;\n   simp [even_iff, h₁, h₂, nat.add_mod];\n   norm_num\n\ntheorem even_add' : even (m + n) ↔ (odd m ↔ odd n) :=\nby rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\n@[parity_simps] theorem even_add_one : even (n + 1) ↔ ¬ even n :=\nby simp [even_add]\n\n@[simp] theorem not_even_bit1 (n : ℕ) : ¬ even (bit1 n) :=\nby simp [bit1] with parity_simps\n\nlemma two_not_dvd_two_mul_add_one (n : ℕ) : ¬(2 ∣ 2 * n + 1) :=\nby simp [add_mod]\n\nlemma two_not_dvd_two_mul_sub_one : Π {n} (w : 0 < n), ¬(2 ∣ 2 * n - 1)\n| (n + 1) _ := two_not_dvd_two_mul_add_one n\n\n@[parity_simps] theorem even_sub (h : n ≤ m) : even (m - n) ↔ (even m ↔ even n) :=\nbegin\n  conv { to_rhs, rw [←tsub_add_cancel_of_le h, even_add] },\n  by_cases h : even n; simp [h]\nend\n\ntheorem even_sub' (h : n ≤ m) : even (m - n) ↔ (odd m ↔ odd n) :=\nby rw [even_sub h, even_iff_not_odd, even_iff_not_odd, not_iff_not]\n\ntheorem odd.sub_odd (hm : odd m) (hn : odd n) : even (m - n) :=\n(le_total n m).elim\n  (λ h, by simp only [even_sub' h, *])\n  (λ h, by simp only [tsub_eq_zero_iff_le.mpr h, even_zero])\n\n@[parity_simps] theorem even_mul : even (m * n) ↔ even m ∨ even n :=\nby cases mod_two_eq_zero_or_one m with h₁ h₁;\n   cases mod_two_eq_zero_or_one n with h₂ h₂;\n   simp [even_iff, h₁, h₂, nat.mul_mod];\n   norm_num\n\ntheorem odd_mul : odd (m * n) ↔ odd m ∧ 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/-- If `m` and `n` are natural numbers, then the natural number `m^n` is even\nif and only if `m` is even and `n` is positive. -/\n@[parity_simps] theorem even_pow : even (m ^ n) ↔ even m ∧ n ≠ 0 :=\nby { induction n with n ih; simp [*, pow_succ', even_mul], tauto }\n\ntheorem even_pow' (h : n ≠ 0) : even (m ^ n) ↔ even m :=\neven_pow.trans $ and_iff_left h\n\ntheorem even_div : even (m / n) ↔ m % (2 * n) / n = 0 :=\nby rw [even_iff_two_dvd, dvd_iff_mod_eq_zero, nat.div_mod_eq_mod_mul_div, mul_comm]\n\n@[parity_simps] theorem odd_add : odd (m + n) ↔ (odd m ↔ even n) :=\nby rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even]\n\ntheorem odd_add' : odd (m + n) ↔ (odd n ↔ even m) :=\nby rw [add_comm, odd_add]\n\nlemma ne_of_odd_add (h : odd (m + n)) : m ≠ n :=\nλ hnot, by simpa [hnot] with parity_simps using h\n\n@[parity_simps] theorem odd_sub (h : n ≤ m) : odd (m - n) ↔ (odd m ↔ even n) :=\nby rw [odd_iff_not_even, even_sub h, not_iff, odd_iff_not_even]\n\ntheorem odd.sub_even (h : n ≤ m) (hm : odd m) (hn : even n) : odd (m - n) :=\n(odd_sub h).mpr $ iff_of_true hm hn\n\ntheorem odd_sub' (h : n ≤ m) : odd (m - n) ↔ (odd n ↔ even m) :=\nby rw [odd_iff_not_even, even_sub h, not_iff, not_iff_comm, odd_iff_not_even]\n\ntheorem even.sub_odd (h : n ≤ m) (hm : even m) (hn : odd n) : odd (m - n) :=\n(odd_sub' h).mpr $ iff_of_true hn hm\n\nlemma even_mul_succ_self (n : ℕ) : even (n * (n + 1)) :=\nbegin\n  rw even_mul,\n  convert n.even_or_odd,\n  simp with parity_simps\nend\n\nlemma even_mul_self_pred (n : ℕ) : even (n * (n - 1)) :=\nbegin\n  cases n,\n  { exact even_zero },\n  { rw mul_comm,\n    apply even_mul_succ_self }\nend\n\nlemma two_mul_div_two_of_even : even n → 2 * (n / 2) = n :=\n λ h, nat.mul_div_cancel_left' (even_iff_two_dvd.mp h)\n\nlemma div_two_mul_two_of_even : even n → n / 2 * 2 = n :=\nλ h, nat.div_mul_cancel (even_iff_two_dvd.mp h)\n\nlemma two_mul_div_two_add_one_of_odd (h : odd n) : 2 * (n / 2) + 1 = n :=\nby { rw mul_comm, convert nat.div_add_mod' n 2, rw odd_iff.mp h }\n\nlemma div_two_mul_two_add_one_of_odd (h : odd n) : n / 2 * 2 + 1 = n :=\nby { convert nat.div_add_mod' n 2, rw odd_iff.mp h }\n\nlemma one_add_div_two_mul_two_of_odd (h : odd n) : 1 + n / 2 * 2 = n :=\nby { rw add_comm, convert nat.div_add_mod' n 2, rw odd_iff.mp h }\n\nlemma bit0_div_two : bit0 n / 2 = n :=\nby rw [←nat.bit0_eq_bit0, bit0_eq_two_mul, two_mul_div_two_of_even (even_bit0 n)]\n\n\n\n@[simp] lemma bit0_div_bit0 : bit0 n / bit0 m = n / m :=\nby rw [bit0_eq_two_mul m, ←nat.div_div_eq_div_mul, bit0_div_two]\n\n@[simp] lemma bit1_div_bit0 : bit1 n / bit0 m = n / m :=\nby rw [bit0_eq_two_mul, ←nat.div_div_eq_div_mul, bit1_div_two]\n\n@[simp] lemma bit0_mod_bit0 : bit0 n % bit0 m = bit0 (n % m) :=\nby rw [bit0_eq_two_mul n, bit0_eq_two_mul m, bit0_eq_two_mul (n % m), nat.mul_mod_mul_left]\n\n@[simp] lemma bit1_mod_bit0 : bit1 n % bit0 m = bit1 (n % m) :=\nbegin\n  have h₁ := congr_arg bit1 (nat.div_add_mod n m),\n  -- `∀ m n : ℕ, bit0 m * n = bit0 (m * n)` seems to be missing...\n  rw [bit1_add, bit0_eq_two_mul, ← mul_assoc, ← bit0_eq_two_mul] at h₁,\n  have h₂ := nat.div_add_mod (bit1 n) (bit0 m),\n  rw [bit1_div_bit0] at h₂,\n  exact add_left_cancel (h₂.trans h₁.symm),\nend\n\n-- Here are examples of how `parity_simps` can be used with `nat`.\n\nexample (m n : ℕ) (h : even m) : ¬ even (n + 3) ↔ even (m^2 + m + n) :=\nby simp [*, (dec_trivial : ¬ 2 = 0)] with parity_simps\n\nexample : ¬ even 25394535 :=\nby simp\n\nend nat\n\nopen nat\n\nnamespace function\nnamespace involutive\n\nvariables {α : Type*} {f : α → α} {n : ℕ}\n\ntheorem iterate_bit0 (hf : involutive f) (n : ℕ) : f^[bit0 n] = id :=\nby rw [bit0, ← two_mul, iterate_mul, involutive_iff_iter_2_eq_id.1 hf, iterate_id]\n\ntheorem iterate_bit1 (hf : involutive f) (n : ℕ) : f^[bit1 n] = f :=\nby rw [bit1, iterate_succ, hf.iterate_bit0, comp.left_id]\n\ntheorem iterate_even (hf : involutive f) (hn : even n) : f^[n] = id :=\nlet ⟨m, hm⟩ := hn in hm.symm ▸ hf.iterate_bit0 m\n\ntheorem iterate_odd (hf : involutive f) (hn : odd n) : f^[n] = f :=\nlet ⟨m, hm⟩ := odd_iff_exists_bit1.mp hn in hm.symm ▸ hf.iterate_bit1 m\n\ntheorem iterate_eq_self (hf : involutive f) (hne : f ≠ id) : f^[n] = f ↔ odd n :=\n⟨λ H, odd_iff_not_even.2 $ λ hn, hne $ by rwa [hf.iterate_even hn, eq_comm] at H, hf.iterate_odd⟩\n\ntheorem iterate_eq_id (hf : involutive f) (hne : f ≠ id) : f^[n] = id ↔ even n :=\n⟨λ H, even_iff_not_odd.2 $ λ hn, hne $ by rwa [hf.iterate_odd hn] at H, hf.iterate_even⟩\n\nend involutive\nend function\n\nvariables {R : Type*} [monoid R] [has_distrib_neg R] {n : ℕ}\n\nlemma neg_one_pow_eq_one_iff_even (h : (-1 : R) ≠ 1) : (-1 : R) ^ n = 1 ↔ even n :=\n⟨λ h', of_not_not $ λ hn, h $ (odd.neg_one_pow $ odd_iff_not_even.mpr hn).symm.trans h',\n  even.neg_one_pow⟩\n\n/-- If `a` is even, then `n` is odd iff `n % a` is odd. -/\nlemma odd.mod_even_iff {n a : ℕ} (ha : even a) : odd (n % a) ↔ odd n :=\n((even_sub' $ mod_le n a).mp $ even_iff_two_dvd.mpr $ (even_iff_two_dvd.mp ha).trans $\n   dvd_sub_mod n).symm\n\n/-- If `a` is even, then `n` is even iff `n % a` is even. -/\nlemma even.mod_even_iff {n a : ℕ} (ha : even a) : even (n % a) ↔ even n :=\n((even_sub $ mod_le n a).mp $ even_iff_two_dvd.mpr $ (even_iff_two_dvd.mp ha).trans $\n   dvd_sub_mod n).symm\n\n/-- If `n` is odd and `a` is even, then `n % a` is odd. -/\nlemma odd.mod_even {n a : ℕ} (hn : odd n) (ha : even a) : odd (n % a) :=\n(odd.mod_even_iff ha).mpr hn\n\n/-- If `n` is even and `a` is even, then `n % a` is even. -/\nlemma even.mod_even {n a : ℕ} (hn : even n) (ha : even a) : even (n % a) :=\n(even.mod_even_iff ha).mpr hn\n\ntheorem odd.of_dvd_nat {m n : ℕ} (hn : odd n) (hm : m ∣ n) : odd m :=\nodd_iff_not_even.2 $ mt hm.even (odd_iff_not_even.1 hn)\n\n/-- `2` is not a factor of an odd natural number. -/\ntheorem odd.ne_two_of_dvd_nat {m n : ℕ} (hn : odd n) (hm : m ∣ n) : m ≠ 2 :=\nbegin\n  rintro rfl,\n  exact absurd (hn.of_dvd_nat hm) dec_trivial\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/parity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7593985375637181}}
{"text": "import .list data.int.basic .logic\n\nnamespace int\n\nlemma add_div {a b c : int} : \nc ∣ a → c ∣ b → (a + b) / c = a / c + b / c :=\nbegin\n  intros h1 h2, \n  by_cases h3 : c = 0,\n  { rw [h3, zero_dvd_iff] at *, \n    rw [h1, h2, h3], refl },\n  { apply eq_of_mul_eq_mul_right h3,\n    rw add_mul, repeat {rw [int.div_mul_cancel]};\n    try {apply dvd_add}; assumption }\nend\n\nend int\n\ndef ints.gcd : list int → nat\n| []      := 0\n| (i::is) := nat.gcd i.nat_abs (ints.gcd is)\n\nlemma forall_mem_nil_eq_zero : ∀ x : int, x ∈ ([] : list int) → x = (0 : int) :=\nbegin intros x h1, cases h1 end\n\nlemma forall_mem_cons_eq_zero (i : int) (is : list int) :\n  (i = (0 : int)) → \n  (∀ x : int, x ∈ is → x = (0 : int)) → \n  (∀ x : int, x ∈ (i::is) → x = (0 : int)) := \nbegin\n  intros h1 h2, rw list.forall_mem_cons,\n  constructor; assumption\nend\n\nmeta instance int.has_reflect : has_reflect int := by tactic.mk_has_reflect_instance\n\ndef symdiv (i j : int) : int := \nif (2 * (i % j)) < j\nthen i / j\nelse (i / j) + 1\n\ndef symmod (i j : int) : int := \nif (2 * (i % j)) < j\nthen i % j\nelse (i % j) - j\n\nlemma symmod_add_one {i} : \n  0 < i → symmod i (i+1) = -1 := \nbegin\n  intro h1, \n  simp only [symmod],\n  rw int.mod_eq_of_lt (le_of_lt h1) (lt_add_one _),\n  rw if_neg, simp,\n  have h2 : 2 * i = (1 + 1) * i := rfl,\n  simp [h2, add_mul], apply h1 \nend\n\nlemma mul_symdiv_eq {i j} :\nj * (symdiv i j) = i - (symmod i j) := \nbegin\n  simp only [symdiv, symmod],\n  by_cases h1 : (2 * (i % j)) < j,\n  { repeat {rw if_pos h1}, \n    rw [int.mod_def, sub_sub_cancel] },\n  { repeat {rw if_neg h1},\n    rw [int.mod_def, sub_sub, sub_sub_cancel,\n      mul_add, mul_one] }\nend\n\nlemma symmod_eq {i j} :\n  symmod i j = i - j * (symdiv i j) := \nby rw [mul_symdiv_eq, sub_sub_cancel]", "meta": {"author": "skbaek", "repo": "omega", "sha": "715e384ed14e8eb177a326700066e7c98269e078", "save_path": "github-repos/lean/skbaek-omega", "path": "github-repos/lean/skbaek-omega/omega-715e384ed14e8eb177a326700066e7c98269e078/int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765304654121, "lm_q2_score": 0.8311430520409023, "lm_q1q2_score": 0.7593959001091651}}
{"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# 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 ∈ R` is `M`-regular if the smultiplication map\n`M → M`, defined by `m ↦ a • 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 → M`. -/\ndef is_smul_regular [has_scalar R M] (c : R) := function.injective ((•) c : M → 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 ↔ 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ᵐᵒᵖ`-regularity of `R` itself. -/\nlemma is_right_regular_iff [has_mul R] {a : R} :\n  is_right_regular a ↔ is_smul_regular R (mul_opposite.op a) := iff.rfl\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 • s) :=\nλ 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 • s)) :\n  is_smul_regular M s :=\n@function.injective.of_comp _ _ _ (λ m : M, a • m) _ (λ 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 • b) ↔ is_smul_regular M b :=\n⟨of_smul _, ha.smul⟩\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\nend has_scalar\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λ 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 ← 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) ↔ is_smul_regular M b :=\n⟨of_mul, ha.mul⟩\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) ∧ is_smul_regular M (b * a) ↔\n  is_smul_regular M a ∧ is_smul_regular M b :=\nbegin\n  refine ⟨_, _⟩,\n  { rintros ⟨ab, ba⟩,\n    refine ⟨ba.of_mul, ab.of_mul⟩ },\n  { rintros ⟨ha, hb⟩,\n    exact ⟨ha.mul hb, hb.mul ha⟩ }\nend\n\n/-- Any power of an `M`-regular element is `M`-regular. -/\nlemma pow (n : ℕ) (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 : ℕ} (n0 : 0 < n) :\n  is_smul_regular M (a ^ n) ↔ is_smul_regular M a :=\nbegin\n  refine ⟨_, pow n⟩,\n  rw [← nat.succ_pred_eq_of_pos n0, pow_succ', ← 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⟨λ a b, h (by repeat { rw mul_action_with_zero.zero_smul })⟩\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) ↔ subsingleton M :=\n⟨λ h, h.subsingleton, λ H a b h, @subsingleton.elim _ H a b⟩\n\n/-- The `0` element is not `M`-regular, on a non-trivial module. -/\nlemma not_zero_iff : ¬ is_smul_regular M (0 : R) ↔ 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\n/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/\nlemma of_smul_eq_one (h : a • 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) ↔\n  is_smul_regular M a ∧ is_smul_regular M b :=\nbegin\n  rw ← mul_and_mul_iff,\n  exact ⟨λ ab, ⟨ab, by rwa mul_comm⟩, λ rab, rab.1⟩\nend\n\nend comm_monoid\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 ((•) g⁻¹) h using 1;\n  simp [←smul_assoc]\nend\n\nend group\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) :=\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 ⟨a, rfl⟩,\n  exact a.is_smul_regular M\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/algebra/regular/smul.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7593958885159129}}
{"text": "section basics\nvariable Sigma : Type\n\ndef word : Type := list Sigma\n\ndef lang : Type := word Sigma → Prop\n\nend basics \n\n\nsection dfa\nvariable {Sigma : Type}\n\nstructure dfa(Sigma : Type)  : Type 1 :=\n  (Q : Type)\n  (init : Q)\n  (final : Q → Prop)\n  (δ : Q → Sigma → Q)\n\nopen dfa\n\ndef dfa_δ_star (A : dfa Sigma) : A.Q → word Sigma → A.Q\n| q [] := q\n| q (x :: w) := dfa_δ_star (A.δ q x) w\n\ndef dfa_lang (A : dfa Sigma) : lang Sigma\n:= λ w , A.final (dfa_δ_star A A.init w)\n\nend dfa\n\n\nsection nfa\nvariables {Sigma : Type}\n\nstructure nfa(Sigma : Type) : Type 1 := \n  (Q : Type)\n  (inits : Q → Prop)\n  (final : Q → Prop)\n  (δ : Q → Sigma → Q → Prop)\n\nopen nfa\n\n/--/\ninductive nfa_δ_star (A : nfa Sigma) : A.Q → word Sigma → A.Q → Prop \n| empty : ∀ q : A.Q , nfa_δ_star q [] q\n| step : ∀ q0 q1 q2 : A.Q, ∀ x : Sigma, ∀ w : word Sigma, \n            A.δ q0 x q1 → nfa_δ_star q1 w q2 → nfa_δ_star q1 (x :: w) q2 \n-/\n\ndef nfa_δ_star : Π A : nfa Sigma , A.Q → word Sigma → A.Q → Prop \n| A q0 [] q1 := q0 = q1\n| A q0 (x :: w) q1 := ∃ q2 : A.Q, A.δ q0 x q2 ∧ nfa_δ_star A q2 w q1\n\ndef nfa_lang (A : nfa Sigma) : lang Sigma\n:= λ w , ∃ q0 q1 : A.Q, A.inits q0 ∧ nfa_δ_star A q0 w q1 ∧ A.final q1\n\nend nfa\n\n\nsection dfa2nfa \nvariables {Sigma : Type}\n\ndef dfa2nfa(A : dfa Sigma) : nfa Sigma :=\n  {\n    Q := A.Q,\n    inits := λ q , q = A.init,\n    final := A.final,\n    δ := λ q0 x q1 , q1 = A.δ q0 x\n  }\n\nlemma nfaδ2dfaδ : ∀ A : dfa Sigma, ∀ w : word Sigma,\n  ∀ q0 q1 : A.Q, dfa_δ_star A q0 w = q1 ↔ nfa_δ_star (dfa2nfa A) q0 w q1 :=\nbegin\n  assume A w,\n  induction w,\n  {\n    assume q0 q1,\n    constructor,\n    dsimp [dfa_δ_star, nfa_δ_star],\n    assume h,\n    exact h,\n    dsimp [dfa_δ_star, nfa_δ_star],\n    assume h,\n    exact h,\n  },\n  {\n    assume q0 q1,\n    constructor,\n    {\n      assume h,\n      dsimp [nfa_δ_star],\n      existsi A.δ q0 w_hd,\n      constructor,\n      dsimp [dfa2nfa],\n      reflexivity,\n      apply (iff.mp (w_ih (A.δ q0 w_hd) q1)),\n      exact h,\n    },\n    {\n      dsimp [dfa_δ_star, nfa_δ_star],\n      assume g,\n      apply (iff.mpr (w_ih (A.δ q0 w_hd) q1)),\n      cases g with q00 gg,\n      have eq: A.δ q0 w_hd = q00,\n      dsimp [dfa2nfa] at gg,\n      exact (eq.symm (and.elim_left gg)),\n      rewrite eq,\n      exact (and.elim_right gg),\n    }\n  }\nend\n\nlemma emb11 : ∀ A : dfa Sigma, ∀ w : word Sigma, \n    dfa_lang A w → nfa_lang (dfa2nfa A) w :=\nbegin\n  assume A w,\n  dsimp [dfa_lang, nfa_lang],\n  induction w,\n  {\n    dsimp [dfa_δ_star],\n    assume h,\n    existsi A.init,\n    existsi A.init,\n    constructor,\n    dsimp [dfa2nfa],\n    reflexivity,\n    constructor,\n    dsimp [nfa_δ_star],\n    reflexivity,\n    dsimp [dfa2nfa],\n    exact h,\n  },\n  {\n    assume h,\n    existsi A.init,\n    existsi (dfa_δ_star A A.init (w_hd :: w_tl)),\n    constructor,\n    dsimp [dfa2nfa],\n    reflexivity,\n    constructor,\n    dsimp [nfa_δ_star],\n    existsi A.δ A.init w_hd,\n    constructor,\n    dsimp [dfa2nfa],\n    reflexivity,\n    dsimp [dfa_δ_star],\n    apply iff.mp (nfaδ2dfaδ A w_tl (A.δ A.init w_hd) (dfa_δ_star A (A.δ A.init w_hd) w_tl)),\n    reflexivity,\n    dsimp [dfa2nfa],\n    exact h,\n  }\nend\n\nlemma emb12 : ∀ A : dfa Sigma, ∀ w : word Sigma, \n    nfa_lang (dfa2nfa A) w → dfa_lang A w :=\nbegin\n  assume A w,\n  dsimp [nfa_lang, dfa_lang],\n  assume h,\n  induction w,\n  {\n    dsimp [dfa_δ_star] at *,\n    cases h with q0 h2,\n    cases h2 with q1 h3,\n    dsimp [nfa_δ_star, dfa2nfa] at h3,\n    rewrite← (and.elim_left h3),\n    rewrite (and.elim_left (and.elim_right h3)),\n    exact (and.elim_right (and.elim_right h3)),\n  },\n  {\n    dsimp [dfa_δ_star] at *,\n    cases h with q0 h2,\n    cases h2 with q1 h3,\n    have eq: q0 = A.init,\n    dsimp [dfa2nfa] at h3,\n    exact and.elim_left h3,\n    have g: dfa_δ_star A (A.δ A.init w_hd) w_tl = q1,\n    rewrite← eq,\n    change dfa_δ_star A q0 (w_hd :: w_tl) = q1,\n    apply (iff.mpr (nfaδ2dfaδ A (w_hd :: w_tl) q0 q1)),  \n    exact and.elim_left (and.elim_right h3),\n    rewrite g,\n    exact and.elim_right (and.elim_right h3),\n  }\nend\n\nlemma emb1 : ∀ A : dfa Sigma, ∀ w : word Sigma, \n    dfa_lang A w ↔ nfa_lang (dfa2nfa A) w :=\nbegin\n  assume A w,\n  constructor,\n  exact (emb11 A w),\n  exact (emb12 A w),\nend\n\nend dfa2nfa\n\n\nsection nfa2dfa\nvariables {Sigma : Type}\n\ndef nfa2dfa(A : nfa Sigma) : dfa Sigma :=\n  {\n    Q := A.Q → Prop,\n    init := A.inits,\n    final := λ p , ∃ q : A.Q, p q ∧ A.final q,\n    δ := λ p x q1 , ∃ q0 : A.Q, p q0 ∧ A.δ q0 x q1, \n  }\n\nlemma dfaδ2nfaδ : ∀ A : nfa Sigma, ∀ w : word Sigma, \n  ∀ q1 : A.Q, ∀ p : (nfa2dfa A).Q,\n  (∃ q0 : A.Q, p q0 ∧ nfa_δ_star A q0 w q1) ↔ dfa_δ_star (nfa2dfa A) p w q1\n  :=\nbegin\n  assume A w,\n  induction w,\n  {\n    assume q1 p,\n    dsimp [nfa_δ_star, dfa_δ_star],\n    constructor,\n    {\n      assume h,\n      cases h with q0 h2,\n      rewrite← (and.elim_right h2),\n      exact (and.elim_left h2),\n    },\n    {\n      assume h,\n      existsi q1,\n      exact (and.intro h rfl),\n    },\n  },\n  {\n    assume q1 p,\n    dsimp [nfa_δ_star, dfa_δ_star],\n    constructor,\n    {\n      assume h,\n      cases h with q0 h2,\n      cases (and.elim_right h2) with q2 h3,\n      have g: ((nfa2dfa A).δ p w_hd) q2,\n      {\n        dsimp [nfa2dfa],\n        existsi q0,\n        exact (and.intro (and.elim_left h2) (and.elim_left h3)),\n      },\n      apply (iff.mp (w_ih q1 ((nfa2dfa A).δ p w_hd))),\n      existsi q2,\n      exact (and.intro g (and.elim_right h3)),\n    },\n    { \n      assume h,\n      cases iff.mpr (w_ih q1 ((nfa2dfa A).δ p w_hd)) h with q2 h2,\n      dsimp [nfa2dfa] at h2,\n      cases (and.elim_left h2) with q0 h3,\n      existsi q0,\n      constructor,\n      exact (and.elim_left h3),\n      existsi q2,\n      exact (and.intro (and.elim_right h3) (and.elim_right h2)),\n    },\n  }\nend\n\nlemma emb21 : ∀ A : nfa Sigma, ∀ w : word Sigma,\n  nfa_lang A w → dfa_lang (nfa2dfa A) w :=\nbegin\n  assume A w,\n  dsimp [nfa_lang, dfa_lang],\n  induction w,\n  {\n    dsimp [nfa_δ_star, dfa_δ_star],\n    assume h,\n    dsimp [nfa2dfa],\n    cases h with q0 h2,\n    cases h2 with q1 h3,\n    existsi q0,\n    constructor,\n    exact (and.elim_left h3),\n    rewrite (and.elim_left (and.elim_right h3)),\n    exact (and.elim_right (and.elim_right h3)),\n  },\n  {\n    dsimp [nfa_δ_star, dfa_δ_star],\n    assume h,\n    cases h with q0 h2,\n    cases h2 with q1 h3,\n    have g: dfa_δ_star (nfa2dfa A) ((nfa2dfa A).δ (nfa2dfa A).init w_hd) w_tl q1,\n    {\n      apply iff.mp (dfaδ2nfaδ A w_tl q1 ((nfa2dfa A).δ (nfa2dfa A).init w_hd)),\n      cases (and.elim_left (and.elim_right h3)) with q2 h4,\n      existsi q2,\n      dsimp [nfa2dfa],\n      constructor,\n      existsi q0,\n      exact (and.intro (and.elim_left h3) (and.elim_left h4)),\n      exact (and.elim_right h4),\n    },\n    existsi q1,\n    exact (and.intro g (and.elim_right (and.elim_right h3))),\n  }\nend\n\nlemma emb22 : ∀ A : nfa Sigma, ∀ w : word Sigma,\n  dfa_lang (nfa2dfa A) w → nfa_lang A w :=\nbegin\n  assume A w,\n  dsimp [nfa_lang, dfa_lang],\n  induction w,\n  {\n    dsimp [nfa_δ_star, dfa_δ_star, nfa2dfa],\n    assume h,\n    cases h with q0 h2,\n    existsi q0,\n    existsi q0,\n    simp,\n    exact h2,\n  },\n  {\n    assume h,\n    cases h with q1 h2,\n    have g: ∃ q0 : A.Q, (nfa2dfa A).init q0 ∧ nfa_δ_star A q0 (w_hd :: w_tl) q1,\n    {\n      apply iff.mpr (dfaδ2nfaδ A (w_hd :: w_tl) q1 (nfa2dfa A).init),\n      exact (and.elim_left h2),\n    },\n    cases g with q0 gg,\n    existsi q0,\n    existsi q1,\n    constructor,\n    exact (and.elim_left gg),\n    exact (and.intro (and.elim_right gg) (and.elim_right h2)),\n  }\nend\n\nlemma emb2 : ∀ A : nfa Sigma, ∀ w : word Sigma,\n  nfa_lang A w ↔ dfa_lang (nfa2dfa A) w :=\nbegin\n  assume A w,\n  constructor,\n  exact emb21 A w,\n  exact emb22 A w,\nend\n\nend nfa2dfa\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/automata.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7593958846514957}}
{"text": "namespace homework5\n\nopen nat\n\n-- 1\ntheorem mul_add (m n k : nat) : m * (n + k) = (m * n) + (m * 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    (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))       : rfl\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-- 2\ntheorem zero_mul (n : nat) : 0 * n = 0 :=\nnat.rec_on n\n    (show 0 * 0 = 0, from mul_zero 0)\n    (assume n,\n        assume ih : 0 * n = 0,\n        show 0 * succ n = 0, from calc\n            0 * succ n = 0 * n + 0 : by rw mul_succ\n                   ... = 0 + 0     : by rw ih\n                   ... = 0         : by rw add_zero)\n\n\n\n-- 3\ntheorem one_mul (n : nat) : 1 * n = n :=\nnat.rec_on n\n    (show 1 * 0 = 0, from mul_zero 1)\n    (assume n,\n        assume ih : 1 * n = n,\n        show 1 * succ n = succ n, from calc\n            1 * succ n = 1 * n + 1 : by rw mul_succ\n                   ... = n + 1     : by rw ih\n                   ... = succ n    : rfl)\n\n-- 4\ntheorem mul_assoc (m n k : nat) : (m * n) * k = m * (n * k) :=\nnat.rec_on k\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                \n    (assume k,\n        assume ih : (m * n) * k = m * (n * k),\n        show (m * n) * succ k = m * (n * succ k), from calc\n            (m * n) * succ k = (m * n) * k + (m * n) : by rw mul_succ\n                           ... = m * (n * k) + (m * n) : by rw ih\n                           ... = m * (n * k + n)       : by rw mul_add\n                           ... = m * (n * succ k)    : by rw mul_succ)\n\n-- 5\ntheorem mul_comm (m n : nat) : m * n = n * m :=\nnat.rec_on n\n    (show m * 0 = 0 * m, from calc\n        m * 0 = 0     : by rw mul_zero\n          ... = 0 * m : by rw zero_mul)\n    (assume n,\n        assume ih : m * n = n * m,\n        show m * succ n = succ n * m, from calc\n            m * succ n = m * n + m : by rw mul_succ\n                     ... = n * m + m : by rw ih\n                     ... = succ n * m : by rw succ_mul)\nend homework5\n", "meta": {"author": "bsemeraro1", "repo": "discretestructures", "sha": "0c2857830c03efcef04d1eef9f11d52f24fee336", "save_path": "github-repos/lean/bsemeraro1-discretestructures", "path": "github-repos/lean/bsemeraro1-discretestructures/discretestructures-0c2857830c03efcef04d1eef9f11d52f24fee336/discrete5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8152324983301567, "lm_q1q2_score": 0.7593585113095448}}
{"text": "\nimport tactic\nimport data.real.basic\nimport data.real.irrational\n\n-- Q1) what's the biggest element of {x ∈ ℝ | x < 1}?\n\ntheorem soln1 : ∀ a ∈ {x : ℝ | x < 1}, ∃ b ∈ {x : ℝ | x < 1}, a < b :=\nbegin\n  intro a,\n  rintro (ha : a < 1),\n  use (a + 1) / 2,\n  split,\n  { simp,\n    linarith },\n  linarith,\nend\n\nopen real\n\n-- Q2) Prove that for every positive intger n ≠ 3, √n - √3 is irrational\ntheorem soln2 : ∀ n : ℕ, 0 < n ∧ n ≠ 3 → irrational (sqrt (n : ℝ) - sqrt 3) :=\nbegin\n  rintros n ⟨hn0, hn3⟩ hq,\n  rw set.mem_range at hq,\n  cases hq with q hq,\n  have hq1 := add_eq_of_eq_sub hq,\n  apply_fun (λ x, x * x) at hq1,\n  have h3 : (0 : ℝ) ≤ 3 := by norm_num,\n  simp [mul_add, add_mul, h3] at hq1,\n  have hq2 : (2 : ℝ) * q * sqrt 3 = n - q * q - 3,\n    rw ← hq1, ring,\n  let r : ℚ := n - q * q - 3,\n  have hq3 : (2 : ℝ) * q * sqrt 3 = r,\n    convert hq2,\n    norm_cast,\n  clear hq1,\n  clear hq2,\n  have s3 : irrational (sqrt ((3 : ℕ) : ℝ)),\n    apply nat.prime.irrational_sqrt,\n    norm_num,\n  simp at s3,\n  have temp : (2 : ℝ) * q * sqrt 3 = sqrt 3 * ((2 : ℚ) * q : ℚ),\n    rw mul_comm ((2 : ℝ) * _),\n    norm_cast,\n  rw temp at hq3,\n  apply irrational.mul_rat s3,\n  swap,\n  use r,\n  exact hq3.symm,\n  clear hq3 r s3 temp,\n  intro h,\n  rw mul_eq_zero at h,\n  cases h, linarith,\n  rw h at hq,\n  simp at hq,\n  symmetry' at hq,\n  rw sub_eq_zero at hq,\n  apply hn3,\n  apply_fun (λ x, x * x) at hq,\n  simp [h3] at hq,\n  norm_cast at hq,\nend\n\n\n", "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_one.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602594, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7593584873683292}}
{"text": "/-\nCopyright (c) 2022 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel, Yury Kudryashov\n-/\nimport order.conditionally_complete_lattice.basic\n\n/-!\n# Extension of a monotone function from a set to the whole space\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 if a function is monotone and is bounded on a set `s`, then it admits a\nmonotone extension to the whole space.\n-/\n\nopen set\n\nvariables {α β : Type*} [linear_order α] [conditionally_complete_linear_order β]\n  {f : α → β} {s : set α} {a b : α}\n\n/-- If a function is monotone and is bounded on a set `s`, then it admits a monotone extension to\nthe whole space. -/\nlemma monotone_on.exists_monotone_extension (h : monotone_on f s) (hl : bdd_below (f '' s))\n  (hu : bdd_above (f '' s)) :\n  ∃ g : α → β, monotone g ∧ eq_on f g s :=\nbegin\n  /- The extension is defined by `f x = f a` for `x ≤ a`, and `f x` is the supremum of the values\n  of `f`  to the left of `x` for `x ≥ a`. -/\n  classical,\n  rcases hl with ⟨a, ha⟩,\n  have hu' : ∀ x, bdd_above (f '' (Iic x ∩ s)),\n    from λ x, hu.mono (image_subset _ (inter_subset_right _ _)),\n  set g : α → β := λ x, if disjoint (Iic x) s then a else Sup (f '' (Iic x ∩ s)),\n  have hgs : eq_on f g s,\n  { intros x hx,\n    simp only [g],\n    have : is_greatest (Iic x ∩ s) x, from ⟨⟨right_mem_Iic, hx⟩, λ y hy, hy.1⟩,\n    rw [if_neg this.nonempty.not_disjoint,\n      ((h.mono $ inter_subset_right _ _).map_is_greatest this).cSup_eq] },\n  refine ⟨g, λ x y hxy, _, hgs⟩,\n  by_cases hx : disjoint (Iic x) s; by_cases hy : disjoint (Iic y) s;\n    simp only [g, if_pos, if_neg, not_false_iff, *],\n  { rcases not_disjoint_iff_nonempty_inter.1 hy with ⟨z, hz⟩,\n    exact le_cSup_of_le (hu' _) (mem_image_of_mem _ hz) (ha $ mem_image_of_mem _ hz.2) },\n  { exact (hx $ hy.mono_left $ Iic_subset_Iic.2 hxy).elim },\n  { rw [not_disjoint_iff_nonempty_inter] at hx hy,\n    refine cSup_le_cSup (hu' _) (hx.image _) (image_subset _ _),\n    exact inter_subset_inter_left _ (Iic_subset_Iic.2 hxy) },\nend\n\n/-- If a function is antitone and is bounded on a set `s`, then it admits an antitone extension to\nthe whole space. -/\nlemma antitone_on.exists_antitone_extension (h : antitone_on f s) (hl : bdd_below (f '' s))\n  (hu : bdd_above (f '' s)) :\n  ∃ g : α → β, antitone g ∧ eq_on f g s :=\nh.dual_right.exists_monotone_extension hu hl\n", "meta": {"author": "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/extension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8757870046160257, "lm_q1q2_score": 0.7593386419451584}}
{"text": "import data.real.basic\nimport tactic\n\nopen function real\n\nnamespace vilnius\n\n\nexample (X Y Z : Type) (f : X → Y) (g : Y → Z) \n  (hf : surjective f) (hg : surjective g) : surjective (g ∘ f) :=\nbegin\n  intro z,\n  have h1 : exists (y:Y), g y = z,\n  apply hg,\n  cases h1 with y hy,\n  have h2 : exists (a:X), f a = y,\n  apply hf,\n  cases h2 with a ha,\n  --use a,\n  split,\n  rw <- hy,\n  rw <- ha,\nend\n\n/- ### The λ notation:\nIn Lean (or in Type Theory, rather) the way to define a function is to use λ expressions: here, you\nshould think that `λ = ∀`: so, the function\n`λ x, 3*x ^ 2 + 1`\nis nothing else that the function\n`f(x)=3*x ^ 2 + 1` or `f : x ↦ 3*x ^ 2 + 1`.\n\nAs for usual functions, the name of the variable does not matter, so\n`λ x, 3*x ^ 2 + 1` is the same as `λ w, 3*w ^ 2 + 1` \n\nThe tactic to get rid of a `λ` term is\n* `simp only` (possibly: at h)\nbecause it \"evaluates a λ-term\", transforming, for instance\n`(λ x, 2 * x + 1) 3` into `2 * 3 + 1`.\n-/\n\n\ndefinition A : ℕ → ℕ := λ n, n + 1 \n\nexample : injective A :=\nbegin\n  intros x1 x2 hx,\n  rewrite <- add_left_inj 1,\n  assumption,\nend\n\nexample : ¬ surjective A := \nbegin\n  intro h,\n  rewrite A at h,\n  rewrite surjective at h,\n  specialize h 0,\n  cases h with a h,\n  --contrapose h,\n  rewrite <- nat.succ_eq_add_one at h,\n  apply nat.succ_ne_zero a h,\nend\n\n-- Recall the-\ndefinition is_linear (f : ℝ → ℝ) : Prop := ∀ c x y, f (c * x + y) = c * f (x) + f(y) \n\n--as well as\ntheorem linear_at_0 (f : ℝ → ℝ) (H : is_linear f) : f 0 = 0 :=\nbegin\n  rewrite <- add_left_inj (f 0),\n  rewrite zero_add,\n  nth_rewrite_lhs 0 <- one_mul (f 0),\n  rw <- H,\n  rw one_mul,\n  rw add_zero,\nend\n\n-- And now a new\n\ndefinition is_linear' (f : ℝ → ℝ) : Prop :=\n(∀ x y, f ( x + y) = f (x) + f (y)) ∧ (∀ c x, f (c * x) = c * f (x))\n\ntheorem linear_eq (f : ℝ → ℝ) : is_linear f ↔ is_linear' f :=\nbegin\n  split,\n    intros hl,\n    split,\n      intros x1 x2,\n      nth_rewrite_lhs 0 <- one_mul x1,\n      rw hl,\n      rw one_mul,\n\n      intros c x,\n      rw <- add_zero (c*x:real),\n      rw hl,\n      rw linear_at_0 f,\n      rw add_zero,\n      assumption,\n    \n    intro hl,\n    cases hl with hs hp,\n    intros c x y,\n    rw hs,\n    rw hp,\nend\n\n--Recall the\ndefinition is_affine (f : ℝ → ℝ) : Prop := ∃ a, ∀ x y, f (y) - f(x) = a * (y - x)\n\n-- together with the\ntheorem linear_add_cnst_of_affine (f : ℝ → ℝ) : is_affine f → (∃ a : ℝ, ∃ g : ℝ → ℝ,\n  (f = g + (λ x, a)) ∧ is_linear g) :=\n  begin\n    intro haf,\n    cases haf with a haf,\n    use (f 0),\n    use (λ (x : ℝ), a*x),\n    split,\n    swap,\n      intros c x y,\n      simp only,\n      rewrite mul_add a (c*x) y,\n      rewrite <- mul_assoc,\n      rewrite <- mul_assoc,\n      rewrite mul_comm a c,\n\n      ext,\n      simp,\n      rw <- sub_eq_iff_eq_add,\n      nth_rewrite_rhs 0 <- sub_zero x,\n      specialize haf (0:ℝ) x,\n      assumption,\n  end\n\n\n-- as well as\n\ntheorem affine_of_linear_add_cnst (f : ℝ → ℝ) : (∃ b : ℝ, ∃ g : ℝ → ℝ,\n  (f = g + (λ x, b)) ∧ is_linear g) → is_affine f :=\n  begin\n    intros ht,\n    cases ht with b ht,\n    cases ht with g ht,\n    cases ht with ha hl,\n      rw linear_eq at hl,\n      cases hl with hs hp,\n    use (g 1),\n    intros x y,\n    rewrite ha,\n    simp,\n    rw mul_sub,\n    rewrite mul_comm,\n    nth_rewrite_rhs 1 mul_comm,\n    rw <- hp,\n    rw mul_one,\n    rw <- hp,\n    rw mul_one,\n  end\n\n-- that we proved in the lesson.\n\nexample (f : ℝ → ℝ) : is_affine f ↔ ∃ a : ℝ, ∃ g : ℝ → ℝ, (f = g + (λ x, a)) ∧ is_linear g := -- iff.intro (linear_add_cnst_of_affine _) (affine_of_linear_add_cnst _)\nbegin\n  split,\n  apply linear_add_cnst_of_affine f,\n  apply affine_of_linear_add_cnst f,\nend\n\nend vilnius\n", "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/Exercices/B.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8670357632379241, "lm_q1q2_score": 0.7593386371154283}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen\n\n! This file was ported from Lean 3 source module linear_algebra.matrix.dot_product\n! leanprover-community/mathlib commit 738c19f572805cff525a93aa4ffbdf232df05aa8\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.StdBasis\n\n/-!\n# Dot product of two vectors\n\nThis file contains some results on the map `matrix.dot_product`, which maps two\nvectors `v w : n → R` to the sum of the entrywise products `v i * w i`.\n\n## Main results\n\n* `matrix.dot_product_std_basis_one`: the dot product of `v` with the `i`th\n  standard basis vector is `v i`\n* `matrix.dot_product_eq_zero_iff`: if `v`'s' dot product with all `w` is zero,\n  then `v` is zero\n\n## Tags\n\nmatrix, reindex\n\n-/\n\n\nuniverse v w\n\nnamespace Matrix\n\nvariable {R : Type v} [Semiring R] {n : Type w} [Fintype n]\n\n@[simp]\ntheorem dotProduct_stdBasis_eq_mul [DecidableEq n] (v : n → R) (c : R) (i : n) :\n    dotProduct v (LinearMap.stdBasis R (fun _ => R) i c) = v i * c :=\n  by\n  rw [dot_product, Finset.sum_eq_single i, LinearMap.stdBasis_same]\n  exact fun _ _ hb => by rw [LinearMap.stdBasis_ne _ _ _ _ hb, MulZeroClass.mul_zero]\n  exact fun hi => False.elim (hi <| Finset.mem_univ _)\n#align matrix.dot_product_std_basis_eq_mul Matrix.dotProduct_stdBasis_eq_mul\n\n@[simp]\ntheorem dotProduct_stdBasis_one [DecidableEq n] (v : n → R) (i : n) :\n    dotProduct v (LinearMap.stdBasis R (fun _ => R) i 1) = v i := by\n  rw [dot_product_std_basis_eq_mul, mul_one]\n#align matrix.dot_product_std_basis_one Matrix.dotProduct_stdBasis_one\n\ntheorem dotProduct_eq (v w : n → R) (h : ∀ u, dotProduct v u = dotProduct w u) : v = w :=\n  by\n  funext x\n  classical rw [← dot_product_std_basis_one v x, ← dot_product_std_basis_one w x, h]\n#align matrix.dot_product_eq Matrix.dotProduct_eq\n\ntheorem dotProduct_eq_iff {v w : n → R} : (∀ u, dotProduct v u = dotProduct w u) ↔ v = w :=\n  ⟨fun h => dotProduct_eq v w h, fun h _ => h ▸ rfl⟩\n#align matrix.dot_product_eq_iff Matrix.dotProduct_eq_iff\n\ntheorem dotProduct_eq_zero (v : n → R) (h : ∀ w, dotProduct v w = 0) : v = 0 :=\n  dotProduct_eq _ _ fun u => (h u).symm ▸ (zero_dotProduct u).symm\n#align matrix.dot_product_eq_zero Matrix.dotProduct_eq_zero\n\ntheorem dotProduct_eq_zero_iff {v : n → R} : (∀ w, dotProduct v w = 0) ↔ v = 0 :=\n  ⟨fun h => dotProduct_eq_zero v h, fun h w => h.symm ▸ zero_dotProduct w⟩\n#align matrix.dot_product_eq_zero_iff Matrix.dotProduct_eq_zero_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/DotProduct.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.867035752930664, "lm_q1q2_score": 0.7593386308994114}}
{"text": "import algebra.group_power tactic.norm_num algebra.big_operators\n\n\ntheorem Q3a (n : ℕ) : ∃ 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 ▸ @eq.refl ℕ ((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 : ∀ a b: ℕ, 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 : ∀ (e : ℕ), 11^e ≥ 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... ≥ 3*11^d : nat.mul_le_mul_right (11^d) (dec_trivial)\n... ≥ 3*3^d : nat.mul_le_mul_left 3 Hd\n... = 3^(nat.succ d) : rfl\nend \n\ntheorem Q3helpful_lemma2 : ∀ (e : ℕ ), (((11^e-3^e):ℕ):ℤ) = (11:ℤ)^e-(3:ℤ)^e :=\nbegin\nintro e,\nshow int.of_nat (11^e - 3^e) = (11:ℤ)^e - (3:ℤ)^e,\nrw [int.of_nat_sub (Q3helpful_lemma e)],\nrw [of_nat_pow,of_nat_pow],\nrefl,\nend\n\ntheorem Q3b (n : ℕ) : 8 ∣ 11^n - 3^n :=\nbegin\nhave H : ∀ (e : ℕ), 11^e ≥ 3^e := Q3helpful_lemma,\n\nhave H311 : @Zmod.of_int 8 3 = Zmod.of_int 11,\napply quot.sound,\nexistsi (1:ℤ),\nexact dec_trivial,\n\ninduction n with d Hd,\n  exact ⟨0,rfl⟩,\n\ncases Hd with k Hk,\nrw [←int.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:ℤ)^d) = Zmod.of_int ((11:ℤ)^d),\napply quot.sound,\nexistsi (k:ℤ),\nrw [mul_comm],\nexact eq.symm Hk,\nhave H1 : @Zmod.of_int 8 ((3:ℤ)^(nat.succ d)) = Zmod.of_int (11^(nat.succ d)) := calc\nZmod.of_int ((3:ℤ)^(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 ℤ (@Z_setoid 8) _ _ H1,\ncases H2 with k2 Hk2,\n--show (8:ℤ) ∣ 11^nat.succ d - 3^nat.succ d,\nhave H3 : k2 * ↑8 = (int.of_nat 11) ^ nat.succ d - (int.of_nat 3) ^ nat.succ d,\nexact Hk2,\nrw [←of_nat_pow,←of_nat_pow] at H3,\nrw [←int.of_nat_sub (H (nat.succ d))] at H3,\nhave Hpos : k2 * ↑8 ≥ 0,\nrw [H3], exact int.of_nat_nonneg (11^nat.succ d - 3^nat.succ d),\nhave Hpos2 : k2 ≥ 0 := nonneg_of_mul_nonneg_right Hpos (dec_trivial),\nlet k3 : ℕ := int.nat_abs k2,\nhave H4 : ↑k3 = k2 := int.nat_abs_of_nonneg Hpos2,\nexistsi k3,\napply int.of_nat_inj,\nrw [eq.symm H3],\nrw [←H4,int.of_nat_mul,mul_comm],\nrw int.of_nat_eq_coe,\nrw int.of_nat_eq_coe,\nend\n\ntheorem Q3ca (n : ℕ) : ∃ 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 : ℕ) (a b : ℤ) := finset.sum (finset.range (d+1)) (λ n, a^n*b^(d-n))\n\n--finset.sum_image :\n--  ∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β} [_inst_1 : add_comm_monoid β]\n--  [_inst_2 : decidable_eq α] [_inst_3 : decidable_eq γ] {s : finset γ} {g : γ → α},\n--    (∀ (x : γ), x ∈ s → ∀ (y : γ), y ∈ s → g x = g y → x = y) →\n--    finset.sum (finset.image g s) f = finset.sum s (λ (x : γ), f (g x))\n\n\nlemma lt_of_in_finset {x y: ℕ} : x ∈ finset.range y → x < y := by simp\n\nlemma H8 (d : ℕ) : list.map (λ (i : ℕ), d - i) (list.range (d + 1)) \n    = list.reverse (list.range (d + 1)) :=\nbegin\nadmit, -- and ask Mario\nend\n\nlemma H7 : ∀ d : ℕ, (finset.range (d+1)).image (λ 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 (λ (i : ℕ), 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 (λ (i : ℕ), 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 (λ (i : ℕ), 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 (λ (i : ℕ), d - i) (multiset.range (d + 1)) \n    = ↑(list.range (d + 1)),\nrw ←multiset.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 : ℕ) (a b : ℤ) : Q3sum d a b = Q3sum d b a :=\nbegin\nunfold Q3sum,\nhave : (finset.range (d+1)).image (λ i,d-i) = finset.range (d+1),\n  exact H7 d,\n/-\n  unfold finset.range,\n  unfold multiset.range,\n  rw ←multiset.coe_reverse,\n-/\nrw ←this, -- aargh, rewrites both!\nhave H53 : ∀ (x : ℕ), \n    x ∈ finset.range(d+1) → ∀ (y : ℕ), y ∈ finset.range (d+1) → d-x = d-y → 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 ←nat.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 ℕ ℤ ℕ (λ (n : ℕ), a ^ n * b ^ (d - n)) _ _ _ \n     (finset.range (d+1)) (λ i : ℕ, 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 : ℕ) : finset.range (nat.succ e) = insert e (finset.range e) :=\nbegin\nexact finset.range_succ,\nend\n\n\nlemma H1 (d : ℕ) (aa b : ℤ) : 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 : ∀ x : ℕ, x<(d+1) → 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 : ℕ) : 11 * Q3sum d 3 11 = Q3sum (d+1) 3 11 - 3^(d+1) := H1 d 3 11\nlemma H2 (d : ℕ) : 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 : ∀ d : ℕ, 8*Q3sum d 3 11 = 11^(d+1)-3^(d+1) :=\nbegin\nintro d,\nchange (8:ℤ) with (11:ℤ)-3,\nrw [sub_mul,H3,H2],\nsimp,\nend\n\ntheorem Q3cbint (n : ℕ) : 8 ∣ (11:ℤ)^n - 3^n :=\nbegin\ncases n with d,\n  simp,\nshow 8 ∣ (11:ℤ)^(d+1) - 3^(d+1),\nrw [←Q3cb_helper d],\nexistsi Q3sum d 3 11,\nrefl,\nend\n\ntheorem Q3cb (n : ℕ) : 8 ∣ 11^n - 3^n := -- non-inductive proof\nbegin\nrw ←int.coe_nat_dvd,\nrw [Q3helpful_lemma2],\napply Q3cbint,\nend\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/0503/S0503.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.759315065865412}}
{"text": "/-\nCopyright (c) 2022 Alex Kontorovich. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Alex Kontorovich\n\n! This file was ported from Lean 3 source module group_theory.subgroup.mul_opposite\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.Actions\n\n/-!\n# Mul-opposite subgroups\n\n## Tags\nsubgroup, subgroups\n\n-/\n\n\nvariable {G : Type _} [Group G]\n\nnamespace Subgroup\n\n/-- A subgroup `H` of `G` determines a subgroup `H.opposite` of the opposite group `Gᵐᵒᵖ`. -/\n@[to_additive \"An additive subgroup `H` of `G` determines an additive subgroup `H.opposite` of the\n opposite additive group `Gᵃᵒᵖ`.\"]\ndef opposite : Subgroup G ≃ Subgroup Gᵐᵒᵖ\n    where\n  toFun H :=\n    { carrier := MulOpposite.unop ⁻¹' (H : Set G)\n      one_mem' := H.one_mem\n      mul_mem' := fun ha hb => H.mul_mem hb ha\n      inv_mem' := H.inv_mem }\n  invFun H :=\n    { carrier := MulOpposite.op ⁻¹' (H : Set Gᵐᵒᵖ)\n      one_mem' := H.one_mem\n      mul_mem' := fun ha hb => H.mul_mem hb ha\n      inv_mem' := H.inv_mem }\n  left_inv _ := SetLike.coe_injective rfl\n  right_inv _ := SetLike.coe_injective rfl\n#align subgroup.opposite Subgroup.opposite\n#align add_subgroup.opposite AddSubgroup.opposite\n\n/-- Bijection between a subgroup `H` and its opposite. -/\n@[to_additive (attr := simps!) \"Bijection between an additive subgroup `H` and its opposite.\"]\ndef oppositeEquiv (H : Subgroup G) : H ≃ opposite H :=\n  MulOpposite.opEquiv.subtypeEquiv fun _ => Iff.rfl\n#align subgroup.opposite_equiv Subgroup.oppositeEquiv\n#align add_subgroup.opposite_equiv AddSubgroup.oppositeEquiv\n#align subgroup.opposite_equiv_symm_apply_coe Subgroup.oppositeEquiv_symm_apply_coe\n\n@[to_additive]\ninstance (H : Subgroup G) [Encodable H] : Encodable (opposite H) :=\n  Encodable.ofEquiv H H.oppositeEquiv.symm\n\n@[to_additive]\ninstance (H : Subgroup G) [Countable H] : Countable (opposite H) :=\n  Countable.of_equiv H H.oppositeEquiv\n\n@[to_additive]\ntheorem smul_opposite_mul {H : Subgroup G} (x g : G) (h : opposite H) :\n    h • (g * x) = g * h • x :=\n  mul_assoc _ _ _\n#align subgroup.smul_opposite_mul Subgroup.smul_opposite_mul\n#align add_subgroup.vadd_opposite_add AddSubgroup.vadd_opposite_add\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/MulOpposite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875224, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7593150589174588}}
{"text": "/-\nCopyright (c) 2022 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Yaël Dillies\n-/\nimport linear_algebra.ray\nimport analysis.normed_space.basic\n\n/-!\n# Rays in a real normed vector space\n\nIn this file we prove some lemmas about the `same_ray` predicate in case of a real normed space. In\nthis case, for two vectors `x y` in the same ray, the norm of their sum is equal to the sum of their\nnorms and `‖y‖ • x = ‖x‖ • y`.\n-/\n\nopen real\n\nvariables {E : Type*} [seminormed_add_comm_group E] [normed_space ℝ E]\n  {F : Type*} [normed_add_comm_group F] [normed_space ℝ F]\n\nnamespace same_ray\n\nvariables {x y : E}\n\n/-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm\nof `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex\nspace. -/\nlemma norm_add (h : same_ray ℝ x y) : ‖x + y‖ = ‖x‖ + ‖y‖ :=\nbegin\n  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩,\n  rw [← add_smul, norm_smul_of_nonneg (add_nonneg ha hb), norm_smul_of_nonneg ha,\n    norm_smul_of_nonneg hb, add_mul]\nend\n\nlemma norm_sub (h : same_ray ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| :=\nbegin\n  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩,\n  wlog hab : b ≤ a,\n  { rw same_ray_comm at h, rw [norm_sub_rev, abs_sub_comm],\n    exact this u b a hb ha h (le_of_not_le hab), },\n  rw ← sub_nonneg at hab,\n  rw [← sub_smul, norm_smul_of_nonneg hab, norm_smul_of_nonneg ha,\n    norm_smul_of_nonneg hb, ← sub_mul, abs_of_nonneg (mul_nonneg hab (norm_nonneg _))]\nend\n\nlemma norm_smul_eq (h : same_ray ℝ x y) : ‖x‖ • y = ‖y‖ • x :=\nbegin\n  rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩,\n  simp only [norm_smul_of_nonneg, *, mul_smul, smul_comm (‖u‖)],\n  apply smul_comm\nend\n\nend same_ray\n\nvariables {x y : F}\n\nlemma norm_inj_on_ray_left (hx : x ≠ 0) : {y | same_ray ℝ x y}.inj_on norm :=\nbegin\n  rintro y hy z hz h,\n  rcases hy.exists_nonneg_left hx with ⟨r, hr, rfl⟩,\n  rcases hz.exists_nonneg_left hx with ⟨s, hs, rfl⟩,\n  rw [norm_smul, norm_smul, mul_left_inj' (norm_ne_zero_iff.2 hx), norm_of_nonneg hr,\n    norm_of_nonneg hs] at h,\n  rw h\nend\n\nlemma norm_inj_on_ray_right (hy : y ≠ 0) : {x | same_ray ℝ x y}.inj_on norm :=\nby simpa only [same_ray_comm] using norm_inj_on_ray_left hy\n\nlemma same_ray_iff_norm_smul_eq : same_ray ℝ x y ↔ ‖x‖ • y = ‖y‖ • x :=\n⟨same_ray.norm_smul_eq, λ h, or_iff_not_imp_left.2 $ λ hx, or_iff_not_imp_left.2 $ λ hy,\n  ⟨‖y‖, ‖x‖, norm_pos_iff.2 hy, norm_pos_iff.2 hx, h.symm⟩⟩\n\n/-- Two nonzero vectors `x y` in a real normed space are on the same ray if and only if the unit\nvectors `‖x‖⁻¹ • x` and `‖y‖⁻¹ • y` are equal. -/\nlemma same_ray_iff_inv_norm_smul_eq_of_ne (hx : x ≠ 0) (hy : y ≠ 0) :\n  same_ray ℝ x y ↔ ‖x‖⁻¹ • x = ‖y‖⁻¹ • y :=\nby rw [inv_smul_eq_iff₀, smul_comm, eq_comm, inv_smul_eq_iff₀, same_ray_iff_norm_smul_eq];\n    rwa norm_ne_zero_iff\n\nalias same_ray_iff_inv_norm_smul_eq_of_ne ↔ same_ray.inv_norm_smul_eq _\n\n/-- Two vectors `x y` in a real normed space are on the ray if and only if one of them is zero or\nthe unit vectors `‖x‖⁻¹ • x` and `‖y‖⁻¹ • y` are equal. -/\nlemma same_ray_iff_inv_norm_smul_eq : same_ray ℝ x y ↔ x = 0 ∨ y = 0 ∨ ‖x‖⁻¹ • x = ‖y‖⁻¹ • y :=\nbegin\n  rcases eq_or_ne x 0 with rfl|hx, { simp [same_ray.zero_left] },\n  rcases eq_or_ne y 0 with rfl|hy, { simp [same_ray.zero_right] },\n  simp only [same_ray_iff_inv_norm_smul_eq_of_ne hx hy, *, false_or]\nend\n\n/-- Two vectors of the same norm are on the same ray if and only if they are equal. -/\nlemma same_ray_iff_of_norm_eq (h : ‖x‖ = ‖y‖) : same_ray ℝ x y ↔ x = y :=\nbegin\n  obtain rfl | hy := eq_or_ne y 0,\n  { rw [norm_zero, norm_eq_zero] at h,\n    exact iff_of_true (same_ray.zero_right _) h },\n  { exact ⟨λ hxy, norm_inj_on_ray_right hy hxy same_ray.rfl h, λ hxy, hxy ▸ same_ray.rfl⟩ }\nend\n\nlemma not_same_ray_iff_of_norm_eq (h : ‖x‖ = ‖y‖) : ¬ same_ray ℝ x y ↔ x ≠ y :=\n(same_ray_iff_of_norm_eq h).not\n\n/-- If two points on the same ray have the same norm, then they are equal. -/\nlemma same_ray.eq_of_norm_eq (h : same_ray ℝ x y) (hn : ‖x‖ = ‖y‖) : x = y :=\n(same_ray_iff_of_norm_eq hn).mp h\n\n/-- The norms of two vectors on the same ray are equal if and only if they are equal. -/\nlemma same_ray.norm_eq_iff (h : same_ray ℝ x y) : ‖x‖ = ‖y‖ ↔ x = y :=\n⟨h.eq_of_norm_eq, λ h, h ▸ 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_space/ray.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7593084571964096}}
{"text": "-- La composición de funciones suprayectivas es suprayectiva\n-- =========================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar que la composición de dos funciones\n-- suprayectivas es una función suprayectiva.\n-- ----------------------------------------------------\n\nimport tactic\n\nopen function\n\nvariables {X Y Z : Type}\nvariable  {f : X → Y}\nvariable  {g : Y → Z} \n\n-- 1ª demostración\nexample \n  (hf : surjective f) \n  (hg : surjective g) \n  : surjective (g ∘ f) :=\nbegin\n  intro z,\n  cases hg z with y hy,\n  cases hf y with x hx,\n  use x,\n  simp,\n  rw hx,\n  exact hy,\nend\n\n-- 2ª demostración\nexample \n  (hf : surjective f) \n  (hg : surjective g) \n  : surjective (g ∘ f) :=\nbegin\n  intro z,\n  cases hg z with y hy,\n  cases hf y with x hx,\n  use x,\n  calc (g ∘ f) x = g (f x) : by rw comp_app\n             ... = g y     : congr_arg g hx\n             ... = z       : hy,\nend\n\n-- 3ª demostración\nexample \n  (hf : surjective f) \n  (hg : surjective g) \n  : surjective (g ∘ f) :=\nassume z,\nexists.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 ∃ x, g (f x) = z, from exists.intro x this))\n\n-- 4ª demostración\nexample \n  (hf : surjective f) \n  (hg : surjective g) \n  : surjective (g ∘ f) :=\n-- by library_search\nsurjective.comp hg hf\n\n-- 5ª demostración\nexample \n  (hf : surjective f) \n  (hg : surjective g) \n  : surjective (g ∘ f) :=\nλ z, exists.elim (hg z) \n  (λ y hy, exists.elim (hf y) \n     (λ x hx, exists.intro x \n        (show g (f x) = z, \n           from (eq.trans (congr_arg g hx) hy))))\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/5_Funciones/La_composicion_de_funciones_suprayectivas_es_suprayectiva.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139577, "lm_q2_score": 0.8499711794579722, "lm_q1q2_score": 0.7592872470706649}}
{"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 {α : Type uu} {r : α → α → Prop}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `≤`-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 : α) : sorted r [a] := pairwise_singleton _ _\n\ntheorem sorted_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) → sorted r l :=\npairwise_of_pairwise_cons\n\ntheorem rel_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) →\n  ∀ b ∈ l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : α} {l : list α} :\n  sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ sorted r l :=\npairwise_cons\n\ntheorem eq_of_sorted_of_perm [is_antisymm α r]\n  {l₁ l₂ : list α} (p : l₁ ~ l₂) (s₁ : sorted r l₁) (s₂ : sorted r l₂) : l₁ = l₂ :=\nbegin\n  induction s₁ with a l₁ h₁ s₁ IH generalizing l₂,\n  { rw eq_nil_of_perm_nil p },\n  { have : a ∈ l₂ := perm_subset p (mem_cons_self _ _),\n    rcases mem_split this with ⟨u₂, v₂, rfl⟩,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    have := IH p' (pairwise_of_sublist (by simp) s₂), subst l₁,\n    change a::u₂ ++ v₂ = u₂ ++ ([a] ++ v₂), rw ← append_assoc, congr,\n    have : ∀ (x : α) (h : x ∈ u₂), x = a := λ x m,\n      antisymm ((pairwise_append.1 s₂).2.2 _ m a (mem_cons_self _ _))\n        (h₁ _ (by simp [m])),\n    rw [(@eq_repeat _ a (length u₂ + 1) (a::u₂)).2,\n        (@eq_repeat _ a (length u₂ + 1) (u₂++[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 {α : Type uu} (r : α → α → Prop) [decidable_rel r]\nlocal infix `≼` : 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 : α) : list α → list α\n| []       := [a]\n| (b :: l) := if a ≼ 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 α → list α\n| []       := []\n| (b :: l) := ordered_insert b (insertion_sort l)\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : ∀ l : list α, ordered_insert a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a ≼ 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 : ∀ l : list α, 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 α r] [is_trans α r]\n\ntheorem sorted_ordered_insert (a : α) : ∀ l, sorted r l → sorted r (ordered_insert a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a ≼ b,\n  { simpa [ordered_insert, h', h] using λ b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : ∀ (b' : α), b' ∈ ordered_insert r a l → 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 ∨ b' ∈ 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 : ∀ 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 α → list α × list α\n| []       := ([], [])\n| (a :: l) := let (l₁, l₂) := split l in (a :: l₂, l₁)\n\ntheorem split_cons_of_eq (a : α) {l l₁ l₂ : list α} (h : split l = (l₁, l₂)) :\n  split (a :: l) = (a :: l₂, l₁) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : ∀ {l l₁ l₂ : list α},\n  split l = (l₁, l₂) → length l₁ ≤ length l ∧ length l₂ ≤ length l\n| []     ._  ._  rfl := ⟨nat.le_refl 0, nat.le_refl 0⟩\n| (a::l) l₁' l₂' h   := begin\n  cases e : split l with l₁ l₂,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂',\n  cases length_split_le e with h₁ h₂,\n  exact ⟨nat.succ_le_succ h₂, nat.le_succ_of_le h₁⟩\nend\n\ntheorem length_split_lt {a b} {l l₁ l₂ : list α} (h : split (a::b::l) = (l₁, l₂)) :\n  length l₁ < length (a::b::l) ∧ length l₂ < length (a::b::l) :=\nbegin\n  cases e : split l with l₁' l₂',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l₁ l₂,\n  cases length_split_le e with h₁ h₂,\n  exact ⟨nat.succ_le_succ (nat.succ_le_succ h₁), nat.succ_le_succ (nat.succ_le_succ h₂)⟩\nend\n\ntheorem perm_split : ∀ {l l₁ l₂ : list α}, split l = (l₁, l₂) → l ~ l₁ ++ l₂\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l₁' l₂' h   := begin\n  cases e : split l with l₁ l₂,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂',\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 α → list α → list α\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a ≼ 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 α → list α\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  exact merge r (merge_sort l₁) (merge_sort l₂)\nend\nusing_well_founded {\n  rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l₁ l₂ : list α}\n  (h : split (a::b::l) = (l₁, l₂)) :\n  merge_sort (a::b::l) = merge (merge_sort l₁) (merge_sort l₂) :=\nbegin\n  suffices : ∀ (L : list α) h1, @@and.rec\n    (λ a a (_ : length l₁ < length l + 1 + 1 ∧\n      length l₂ < 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 : ∀ (l l' : list α), 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 ≼ 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 : ∀ l : list α, 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₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact (perm_app (perm_merge_sort l₁) (perm_merge_sort l₂)).trans (perm_split e).symm\nend\nusing_well_founded {\n  rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\nsection total_and_transitive\nvariables [is_total α r] [is_trans α r]\n\ntheorem sorted_merge : ∀ {l l' : list α}, sorted r l → sorted r l' → sorted r (merge l l')\n| []       []        h₁ h₂ := sorted_nil\n| []       (b :: l') h₁ h₂ := by simpa [merge] using h₂\n| (a :: l) []        h₁ h₂ := by simpa [merge] using h₁\n| (a :: l) (b :: l') h₁ h₂ := begin\n  by_cases a ≼ b,\n  { suffices : ∀ (b' : α) (_ : b' ∈ merge r l (b :: l')), r a b',\n    { simpa [merge, h, sorted_merge (sorted_of_sorted_cons h₁) h₂] },\n    intros b' bm,\n    rcases (show b' = b ∨ b' ∈ l ∨ b' ∈ 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₁ _ bl },\n    { exact trans h (rel_of_sorted_cons h₂ _ bl') } },\n  { suffices : ∀ (b' : α) (_ : b' ∈ merge r (a :: l) l'), r b b',\n    { simpa [merge, h, sorted_merge h₁ (sorted_of_sorted_cons h₂)] },\n    intros b' bm,\n    have ba : b ≼ a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a ∨ b' ∈ l ∨ b' ∈ 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₁ _ bl) },\n    { exact rel_of_sorted_cons h₂ _ bl' } }\nend\n\ntheorem sorted_merge_sort : ∀ l : list α, 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₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  rw [merge_sort_cons_cons r e],\n  exact sorted_merge r (sorted_merge_sort l₁) (sorted_merge_sort l₂)\nend\nusing_well_founded {\n  rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm α r] {l : list α} : sorted r l → 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 (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\nend list\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/list/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.8933094046341532, "lm_q1q2_score": 0.7592872313031359}}
{"text": "variables p q: Prop\n\n#check p -> ¬ p\n#check p -> q -> p ∧ q\n\nexample (hp: p) (hq: q): p ∧ q := and.intro hp hq\nexample (h: p ∧ q): p := and.elim_left h\nexample (h: p ∧ q): q := and.elim_right h\n#check assume (h: p ∧ q), and.elim_left h\n\nexample (h: p ∧ q): q ∧ p := and.intro (and.right h) (and.left h)\n\n#check assume (hp: p) (hq: q), (⟨hp, hq⟩: p ∧ q)\n\nexample (h: p ∧ q): q ∧ p := ⟨h.right, h.left⟩\n\nexample (h: p ∧ q): q ∧ p ∧ q := ⟨h.right, h.left, h.right⟩\n\nexample (hp: p): p ∨ q := or.intro_left q hp\n\n#print or.elim\n\nexample (h: p ∨ q) : q ∨ p := \n  or.elim h\n    (assume hp: p, or.inr hp)\n    (assume hq: q, or.inl hq)\n\nexample (hpq: p -> q) (hnq: ¬ q) : ¬ p :=\n  assume hp: p,\n  show false, from hnq (hpq hp)\n\n#print absurd\nexample (hp: p) (hnp: ¬ p) : q := absurd hp hnp\n\ntheorem and_swap: p ∧ q ↔ q ∧ p := ⟨ λ h, ⟨h.right, h.left⟩, λ h, ⟨h.right, h.left⟩ ⟩ \n\nexample (h: p ∧ q) : q ∧ p := (and_swap p q).mp h\n\nexample (h: p ∧ q): q ∧ p :=\n  have hp: p, from h.left,\n  have hq: q, from h.right,\n  ⟨hq, hp⟩\n \nexample (h: p ∧ q): q ∧ p :=\n  have hp: p, from h.left,\n  suffices hq: q, from ⟨hq, hp⟩,\n  show q, from h.right\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/3-3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843131, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7592599519909332}}
{"text": "/-\nCopyright (c) 2020 Bolton Bailey. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Bolton Bailey\n\n! This file was ported from Lean 3 source module number_theory.lucas_primality\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.Fintype.Basic\nimport Mathlib.GroupTheory.OrderOfElement\nimport Mathlib.Tactic.Zify\nimport Mathlib.Data.Nat.Totient\n\n/-!\n# The Lucas test for primes.\n\nThis file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for\nMersenne primes). A number `a` witnesses that `n` is prime if `a` has order `n-1` in the\nmultiplicative group of integers mod `n`. This is checked by verifying that `a^(n-1) = 1 (mod n)`\nand `a^d ≠ 1 (mod n)` for any divisor `d | n - 1`. This test is the basis of the Pratt primality\ncertificate.\n\n## TODO\n\n- Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness.\n  Use `Units.IsCyclic` from `RingTheory/IntegralDomain` to show the group is cyclic.\n- Write a tactic that uses this theorem to generate Pratt primality certificates\n- Integrate Pratt primality certificates into the norm_num primality verifier\n\n## Implementation notes\n\nNote that the proof for `lucas_primality` relies on analyzing the multiplicative group\nmodulo `p`. Despite this, the theorem still holds vacuously for `p = 0` and `p = 1`: In these\ncases, we can take `q` to be any prime and see that `hd` does not hold, since `a^((p-1)/q)` reduces\nto `1`.\n-/\n\n\n/-- If `a^(p-1) = 1 mod p`, but `a^((p-1)/q) ≠ 1 mod p` for all prime factors `q` of `p-1`, then `p`\nis prime. This is true because `a` has order `p-1` in the multiplicative group mod `p`, so this\ngroup must itself have order `p-1`, which only happens when `p` is prime.\n-/\ntheorem lucas_primality (p : ℕ) (a : ZMod p) (ha : a ^ (p - 1) = 1)\n    (hd : ∀ q : ℕ, q.Prime → q ∣ p - 1 → a ^ ((p - 1) / q) ≠ 1) : p.Prime := by\n  have h0 : p ≠ 0 := by\n    rintro ⟨⟩\n    exact hd 2 Nat.prime_two (dvd_zero _) (pow_zero _)\n  have h1 : p ≠ 1 := by\n    rintro ⟨⟩\n    exact hd 2 Nat.prime_two (dvd_zero _) (pow_zero _)\n  have hp1 : 1 < p := lt_of_le_of_ne h0.bot_lt h1.symm\n  have order_of_a : orderOf a = p - 1 := by\n    apply orderOf_eq_of_pow_and_pow_div_prime _ ha hd\n    exact tsub_pos_of_lt hp1\n  haveI : NeZero p := ⟨h0⟩\n  rw [Nat.prime_iff_card_units]\n  -- Prove cardinality of `Units` of `ZMod p` is both `≤ p-1` and `≥ p-1`\n  refine' le_antisymm (Nat.card_units_zMod_lt_sub_one hp1) _\n  have hp' : p - 2 + 1 = p - 1 := tsub_add_eq_add_tsub hp1\n  let a' : (ZMod p)ˣ := Units.mkOfMulEqOne a (a ^ (p - 2)) (by rw [← pow_succ, hp', ha])\n  calc\n    p - 1 = orderOf a := order_of_a.symm\n    _ = orderOf a' := (orderOf_injective (Units.coeHom (ZMod p)) Units.ext a')\n    _ ≤ Fintype.card (ZMod p)ˣ := orderOf_le_card_univ\n\n#align lucas_primality lucas_primality\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/LucasPrimality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7591560395141591}}
{"text": "\nvariable (p q r : Prop)\n\n\n-- commutativity of ∧ and ∨\n\n\nexample : p ∧ q ↔ q ∧ p :=\n  Iff.intro\n    (\n      λ hpq : p ∧ q =>\n        have hp : p := hpq.left\n        have hq : q := hpq.right\n        show q ∧ p\n          from And.intro hq hp\n    )\n    (\n      λ hqp : q ∧ p =>\n        have hq : q := hqp.left\n        have hp : p := hqp.right\n        show p ∧ q\n          from And.intro hp hq\n    )\n\n\nexample : p ∨ q ↔ q ∨ p :=\n  Iff.intro\n    (\n      λ hpq : p ∨ q =>\n        Or.elim hpq\n          (\n            λ hp : p =>\n              show q ∨ p\n                from Or.inr hp\n          )\n          (\n            λ hq : q =>\n              show q ∨ p\n                from Or.inl hq\n          )\n    )\n    (\n      λ hpq : q ∨ p =>\n        Or.elim hpq\n          (\n            λ hq : q =>\n              show p ∨ q\n                from Or.inr hq\n          )\n          (\n            λ hp : p =>\n              show p ∨ q\n                from Or.inl hp\n          )\n    )\n    \n\n-- associativity of ∧ and ∨\n\n\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  Iff.intro\n    (\n      λ h : (p ∧ q) ∧ r =>\n        have hp : p := h.left.left\n        have hq : q := h.left.right\n        have hr : r := h.right\n        show p ∧ (q ∧ r)\n          from And.intro hp (And.intro hq hr)\n    )\n    (\n      λ h : p ∧ (q ∧ r) =>\n        let hp : p := h.left\n        let hq : q := h.right.left\n        let hr : r := h.right.right\n        ⟨⟨hp, hq⟩, hr⟩\n    )\n\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\n  Iff.intro\n    (\n      λ h : (p ∨ q) ∨ r =>\n        Or.elim h\n          (\n            λ h' : p ∨ q =>\n              Or.elim h'\n                (λ hp : p => Or.inl hp)\n                (λ hq : q => Or.inr (Or.inl hq))\n          )\n          (λ hr : r => Or.inr (Or.inr hr))\n    )\n    (\n      λ h : p ∨ (q ∨ r) =>\n        Or.elim h\n          (λ hp : p => Or.inl (Or.inl hp))\n          (\n            λ h' : q ∨ r =>\n              Or.elim h'\n                (λ hq : q => Or.inl (Or.inr hq))\n                (λ hr : r => Or.inr hr)\n          )\n    )\n\n\n-- distributivity\n\n\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\n  Iff.intro\n    (\n      λ h : p ∧ (q ∨ r) =>\n        have hp : p := h.left\n        Or.elim h.right\n          (λ hq : q => Or.inl ⟨hp, hq⟩)\n          (λ hr : r => Or.inr ⟨hp, hr⟩)\n    )\n    (\n      λ h : (p ∧ q) ∨ (p ∧ r) =>\n        Or.elim h\n          (λ h' : p ∧ q => ⟨h'.left, Or.inl h'.right⟩)\n          (λ h' : p ∧ r => ⟨h'.left, Or.inr h'.right⟩)\n    )\n\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\n  Iff.intro\n    (\n      λ h : p ∨ (q ∧ r) =>\n        Or.elim h\n          (λ hp : p => ⟨Or.inl hp, Or.inl hp⟩)\n          (λ h' : q ∧ r => ⟨Or.inr h'.left, Or.inr h'.right⟩)\n    )\n    (\n      λ h : (p ∨ q) ∧ (p ∨ r) =>\n        Or.elim h.left\n          (λ hp : p => Or.inl hp)\n          (\n            λ hq : q =>\n              Or.elim h.right\n                (λ hp : p => Or.inl hp)\n                (λ hr : r => Or.inr ⟨hq, hr⟩)\n          )\n    )\n\n\n-- other properties\n\n\nexample : (p → (q → r)) ↔ (p ∧ q → r) :=\n  Iff.intro\n    (\n      λ h : p → (q → r) =>\n        λ h' : p ∧ q =>\n          (h h'.left) h'.right\n    )\n    (\n      λ h : p ∧ q → r =>\n        λ hp : p =>\n          λ hq : q =>\n            h ⟨hp, hq⟩\n    )\n\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\n  Iff.intro\n    (\n      λ h : (p ∨ q) → r =>\n        ⟨\n          λ hp : p => h (Or.inl hp)\n        , λ hq : q => h (Or.inr hq)\n        ⟩\n    )\n    (\n      λ h : (p → r) ∧ (q → r) =>\n        λ h' : p ∨ q =>\n          Or.elim h'\n            (λ hp : p => h.left hp)\n            (λ hq : q => h.right hq)\n    )\n\n\nexample : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  Iff.intro\n    (\n      λ h : ¬(p ∨ q) =>\n        ⟨\n          λ hp : p => show False from h (Or.inl hp)\n        , λ hq : q => show False from h (Or.inr hq)\n        ⟩\n    )\n    (\n      λ h : ¬p ∧ ¬q =>\n        λ h' : p ∨ q =>\n          Or.elim h'\n            (λ hp : p => h.left hp)\n            (λ hq : q => h.right hq)\n    )\n\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\n  λ h : ¬p ∨ ¬q =>\n    λ h' : p ∧ q =>\n      Or.elim h\n        (λ hnp : ¬p => hnp h'.left)\n        (λ hnq : ¬q => hnq h'.right)\n\n\nexample : ¬(p ∧ ¬p) :=\n  λ h : p ∧ ¬p => h.right h.left\n\n\nexample : p ∧ ¬q → ¬(p → q) :=\n  λ h : p ∧ ¬q =>\n    λ h' : p → q =>\n      have hnq : ¬q := h.right\n      have hq : q := h' h.left\n      show False\n        from hnq hq\n\n\nexample : ¬p → (p → q) :=\n  λ hnp : ¬p =>\n    λ hp : p => absurd hp hnp\n\n\nexample : (¬p ∨ q) → (p → q) :=\n  λ h : ¬p ∨ q =>\n    λ hp : p =>\n      Or.elim h\n        (λ hnp : ¬p => False.elim (hnp hp))\n        (λ hq : q => hq)\n\n\nexample : p ∨ False ↔ p :=\n  Iff.intro\n    (\n      λ h : p ∨ False =>\n        Or.elim h\n          (λ hp : p => hp)\n          False.elim\n    )\n      Or.inl\n\n\nexample : p ∧ False ↔ False :=\n  Iff.intro\n    (\n      λ h : p ∧ False =>\n        h.right\n    )\n    False.elim\n\n\nexample : (p → q) → (¬q → ¬p) :=\n  λ h : p → q =>\n    λ hnq : ¬q =>\n      λ hp : p =>\n        absurd (h hp) hnq\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-3/Exercises-3-1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896758909757, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7591560240155105}}
{"text": "import Math.CategoryTheory.Basic\nimport Math.CategoryTheory.Functor\n\nopen CategoryTheory\n\nvariable {C : Category} {X Y Z : C.obj}\n\n-- # Exercise\n-- Prove that, for any object `X : C`, the identity morphism is the only morphism\n-- such that `C.comp g f = g` for all morphisms `g : C.hom Y X`.\nexample (f : C.hom X X) (hf : ∀ {Y : C.obj} (g : C.hom X Y), C.comp g f = g) : f = C.id X := by {\n  specialize hf (C.id X);\n  rw [C.id_comp] at hf;\n  exact hf;\n}\n\n-- # Exercise\n-- Prove that the identity morphism on `X` is mono.\ntheorem id_mono : mono (C.id X) := by {\n  constructor;\n  intros Z g h;  \n  rw [C.id_comp, C.id_comp];\n  exact λ f => f;\n}\n\n-- # Exercise\n-- Prove that the identity morphism on `X` is epi.\ntheorem id_epi : epi (C.id X) := by {\n  constructor;\n  intros Z g h;\n  rw [C.comp_id, C.comp_id];\n  exact λ f => f;\n}\n\n-- # Exercise\n-- Prove that the composition of two monos is mono.\ntheorem comp_mono (hf : mono f) (hg : mono g) : mono (C.comp g f) := by {\n  constructor;\n  intros Z s t hgf;\n  apply hf.cancel;\n  apply hg.cancel;\n  rw [C.assoc, C.assoc] at hgf;\n  exact hgf;\n}\n\n-- # Exercise\n-- Prove that the composition of two epis is epi.\ntheorem comp_epi (hf : epi f) (hg : epi g) : epi (C.comp g f) := by {\n  constructor;\n  intros Z s t hgf;\n  apply hg.cancel;\n  apply hf.cancel;\n  rw [← C.assoc, ← C.assoc] at hgf;\n  exact hgf;\n}\n\n-- # Exercise\n-- Prove that the composition of two isomorphisms is an isomorphism.\ntheorem comp_iso (hf : iso f) (hg : iso g) : iso (C.comp g f) := by {\n  cases hf.is_iso with | intro k hk =>\n  cases hg.is_iso with | intro l hl =>\n  constructor;\n  apply Exists.intro (C.comp k l);\n  constructor;\n  rw [C.assoc, ← C.assoc l g f, hl.1, C.id_comp, hk.1];\n  rw [C.assoc, ← C.assoc f k l, hk.2, C.id_comp, hl.2];\n}\n\n-- # Exercise\n-- Prove that initial objects are unique up to isomorphism.\ntheorem initial_unique (X Y : C.obj) [hx : initial X] [hy : initial Y] : ∃ (f : C.hom X Y), iso f := by {\n  -- sorry,\n  cases hx.is_initial Y with | intro f hf =>\n  cases hy.is_initial X with | intro g hg =>\n  cases hx.is_initial X with | intro k hk =>\n  cases hy.is_initial Y with | intro l hl =>\n  apply Exists.intro f;\n  constructor;\n  apply Exists.intro g;\n  constructor;\n  rw [← hk (C.id X), ← hk (C.comp g f)];\n  rw [← hl (C.id Y), ← hl (C.comp f g)];\n}\n\n-- # Exercise\n-- Prove that terminal objects are unique up to isomorphism.\ntheorem terminal_unique (X Y : C.obj) [hx : terminal X] [hy : terminal Y] : ∃ (f : C.hom X Y), iso f := by {\n  -- sorry,\n  cases hx.is_terminal Y with | intro f hf =>\n  cases hy.is_terminal X with | intro g hg =>\n  cases hx.is_terminal X with | intro k hk =>\n  cases hy.is_terminal Y with | intro l hl =>\n  apply Exists.intro g;\n  constructor;\n  apply Exists.intro f;\n  constructor;\n  rw [← hk (C.id X), ← hk (C.comp f g)];\n  rw [← hl (C.id Y), ← hl (C.comp g f)];\n}\n\nsection\n\nstructure poset :=\n  (α : Sort u)\n  (R : α → α → Prop)\n  (refl  : ∀ x, R x x)\n  (asymm : ∀ {x y}, R x y → R y x → x = y)\n  (trans : ∀ {x y z}, R y z → R x y → R x z)\n\n-- # Exercise\n-- Show that the type `Prop` has the structure of a partially ordered set,\n-- where the relation `R` is given by implication, that is, `R P Q := P → Q`\ndef poset_Prop : poset := {\n  α := Prop,\n  R := λ P Q => P → Q,\n  refl := λ P p => p, --sorry,\n  asymm := λ pq qp => by dsimp; apply Eq.propIntro pq qp, --by ext; exact ⟨pq, qp⟩, -- sorry,\n  trans := λ qr pq p => qr (pq p), -- sorry,\n}\n\n-- # Exercise\n-- Show that every partially ordered set is naturally a category, where `hom x y`\n-- is given by the proposition `x ≤ y`\ndef category_of_poset (P : poset) : Category := {\n  obj := P.α,\n  hom := λ x y => P.R x y,\n  id := P.refl, -- sorry,\n  comp := P.trans, -- sorry,\n  comp_id := λ _ => by dsimp, -- sorry,\n  id_comp := λ _ => by dsimp, -- sorry,\n  assoc := λ _ _ _ => by dsimp, -- sorry,\n}\n\nend\n\n-- # Exercise\n-- Prove that a full and faithful functor reflects initial objects.\nexample (F : Functor C D) {Ffull : F.full} {Ffaith : F.faithful} {X : C.obj} [hFx : initial (F.obj X)] : initial X := by {\n  constructor;\n  intro Y;\n  cases hFx.is_initial (F.obj Y) with | intro Ff hFf =>\n  cases Ffull.intro Ff with | intro f hf =>\n  apply Exists.intro f;\n  intro g;\n  specialize hFf (F.hom g);\n  apply Ffaith.cancel;\n  rw [← hFf, hf];\n}\n\n-- # Exercise\n-- Prove that a full and faithful functor reflects terminal objects.\nexample (F : Functor C D) [Ffull : F.full] [Ffaith : F.faithful] {X : C.obj} [hFx : terminal (F.obj X)] : terminal X := by {\n  constructor;\n  intro Y;\n  cases hFx.is_terminal (F.obj Y) with | intro Ff hFf =>\n  cases Ffull.intro Ff with | intro f hf =>\n  apply Exists.intro f;\n  intro g;\n  specialize hFf (F.hom g);\n  apply Ffaith.cancel;\n  rw [← hFf, hf];\n}\n\n-- # Exercise\n-- Prove that a faithful functor reflects monos.\nexample (F : Functor C D) [Ffaith : F.faithful] {X Y : C.obj} {f : C.hom X Y} [hf : mono (F.hom f)] : mono f := by {\n  constructor;\n  intros Z g h hfgh;\n  apply Ffaith.cancel;\n  apply hf.cancel;\n  rw [← F.map_comp, ← F.map_comp, hfgh];\n}\n\n-- # Exercise\n-- Prove that a faithful functor reflects epis.\nexample (F : Functor C D) [Ffaith : F.faithful] {X Y : C.obj} {f : C.hom X Y} [hf : epi (F.hom f)] : epi f := by {\n  constructor;\n  intros Z g h hfgh;\n  apply Ffaith.cancel;\n  apply hf.cancel;\n  rw [← F.map_comp, ← F.map_comp, hfgh];\n}\n\n-- # Exercise\n-- Prove that if `F` is full and faithful, and `F X` is isomorphic to `F Y`, then `X` is isomorphic to `Y`\nexample (F : Functor C D) [Ffull : F.full] [Ffaith: F.faithful] {X Y : C.obj} {f : D.hom (F.obj X) (F.obj Y)} (hf : iso f) : ∃ (g : C.hom X Y), iso g := by {\n  cases hf.is_iso with | intro g hg =>\n  cases Ffull.intro f with | intro k hk =>\n  cases Ffull.intro g with | intro l hl =>\n  apply Exists.intro k;\n  constructor;\n  apply Exists.intro l;\n  constructor;\n  apply Ffaith.cancel;\n  rw [F.map_comp, hk, hl, hg.1, F.map_id];\n  apply Ffaith.cancel;\n  rw [F.map_comp, hk, hl, hg.2, F.map_id];\n}\n", "meta": {"author": "jessetvogel", "repo": "Math4", "sha": "1d6a30589c7b3b3c70e968985d0c1f6f9f242938", "save_path": "github-repos/lean/jessetvogel-Math4", "path": "github-repos/lean/jessetvogel-Math4/Math4-1d6a30589c7b3b3c70e968985d0c1f6f9f242938/Math/CategoryTheory/Exercises/Exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7591353063966578}}
{"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.units\n! leanprover-community/mathlib commit 641b6a82006416ec431b2987b354af9311fed4f2\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.Units\nimport Mathlib.Data.Int.Basic\nimport Mathlib.Algebra.Ring.Units\nimport Mathlib.Tactic.Tauto\n\n/-!\n# Lemmas about units in `ℤ`.\n-/\n\n\nnamespace Int\n\n/-! ### units -/\n\n@[simp]\ntheorem units_natAbs (u : ℤˣ) : natAbs u = 1 :=\n  Units.ext_iff.1 <|\n    Nat.units_eq_one\n      ⟨natAbs u, natAbs ↑u⁻¹, by rw [← natAbs_mul, Units.mul_inv]; rfl, by\n        rw [← natAbs_mul, Units.inv_mul]; rfl⟩\n#align int.units_nat_abs Int.units_natAbs\n\ntheorem units_eq_one_or (u : ℤˣ) : u = 1 ∨ u = -1 := by\n  simpa only [Units.ext_iff, units_natAbs] using natAbs_eq u\n#align int.units_eq_one_or Int.units_eq_one_or\n\ntheorem isUnit_eq_one_or {a : ℤ} : IsUnit a → a = 1 ∨ a = -1\n  | ⟨_, hx⟩ => hx ▸ (units_eq_one_or _).imp (congr_arg Units.val) (congr_arg Units.val)\n#align int.is_unit_eq_one_or Int.isUnit_eq_one_or\n\ntheorem isUnit_iff {a : ℤ} : IsUnit a ↔ a = 1 ∨ a = -1 := by\n  refine' ⟨fun h => isUnit_eq_one_or h, fun h => _⟩\n  rcases h with (rfl | rfl)\n  · exact isUnit_one\n  · exact isUnit_one.neg\n#align int.is_unit_iff Int.isUnit_iff\n\ntheorem isUnit_eq_or_eq_neg {a b : ℤ} (ha : IsUnit a) (hb : IsUnit b) : a = b ∨ a = -b := by\n  rcases isUnit_eq_one_or hb with (rfl | rfl)\n  · exact isUnit_eq_one_or ha\n  · rwa [or_comm, neg_neg, ← isUnit_iff]\n#align int.is_unit_eq_or_eq_neg Int.isUnit_eq_or_eq_neg\n\ntheorem eq_one_or_neg_one_of_mul_eq_one {z w : ℤ} (h : z * w = 1) : z = 1 ∨ z = -1 :=\n  isUnit_iff.mp (isUnit_of_mul_eq_one z w h)\n#align int.eq_one_or_neg_one_of_mul_eq_one Int.eq_one_or_neg_one_of_mul_eq_one\n\ntheorem eq_one_or_neg_one_of_mul_eq_one' {z w : ℤ} (h : z * w = 1) :\n    z = 1 ∧ w = 1 ∨ z = -1 ∧ w = -1 := by\n  have h' : w * z = 1 := mul_comm z w ▸ 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) <;> tauto\n#align int.eq_one_or_neg_one_of_mul_eq_one' Int.eq_one_or_neg_one_of_mul_eq_one'\n\ntheorem eq_of_mul_eq_one {z w : ℤ} (h : z * w = 1) : z = w :=\n  (eq_one_or_neg_one_of_mul_eq_one' h).elim\n    (and_imp.2 (·.trans ·.symm)) (and_imp.2 (·.trans ·.symm))\n#align int.eq_of_mul_eq_one Int.eq_of_mul_eq_one\n\ntheorem mul_eq_one_iff_eq_one_or_neg_one {z w : ℤ} :\n    z * w = 1 ↔ z = 1 ∧ w = 1 ∨ z = -1 ∧ w = -1 := by\n  refine' ⟨eq_one_or_neg_one_of_mul_eq_one', fun h => Or.elim h (fun H => _) fun H => _⟩ <;>\n      rcases H with ⟨rfl, rfl⟩ <;>\n    rfl\n#align int.mul_eq_one_iff_eq_one_or_neg_one Int.mul_eq_one_iff_eq_one_or_neg_one\n\ntheorem eq_one_or_neg_one_of_mul_eq_neg_one' {z w : ℤ} (h : z * w = -1) :\n    z = 1 ∧ w = -1 ∨ z = -1 ∧ w = 1 := by\n  rcases isUnit_eq_one_or (IsUnit.mul_iff.mp (Int.isUnit_iff.mpr (Or.inr h))).1 with (rfl | rfl)\n  · exact Or.inl ⟨rfl, one_mul w ▸ h⟩\n  · exact Or.inr ⟨rfl, neg_inj.mp (neg_one_mul w ▸ h)⟩\n#align int.eq_one_or_neg_one_of_mul_eq_neg_one' Int.eq_one_or_neg_one_of_mul_eq_neg_one'\n\ntheorem mul_eq_neg_one_iff_eq_one_or_neg_one {z w : ℤ} :\n    z * w = -1 ↔ z = 1 ∧ w = -1 ∨ z = -1 ∧ w = 1 := by\n  refine' ⟨eq_one_or_neg_one_of_mul_eq_neg_one', fun h => Or.elim h (fun H => _) fun H => _⟩ <;>\n      rcases H with ⟨rfl, rfl⟩ <;>\n    rfl\n#align int.mul_eq_neg_one_iff_eq_one_or_neg_one Int.mul_eq_neg_one_iff_eq_one_or_neg_one\n\ntheorem isUnit_iff_natAbs_eq {n : ℤ} : IsUnit n ↔ n.natAbs = 1 := by\n  simp [natAbs_eq_iff, isUnit_iff, Nat.cast_zero]\n#align int.is_unit_iff_nat_abs_eq Int.isUnit_iff_natAbs_eq\n\nalias isUnit_iff_natAbs_eq ↔ IsUnit.natAbs_eq _\n#align int.is_unit.nat_abs_eq Int.IsUnit.natAbs_eq\n\n-- Porting note: `rw` didn't work on `natAbs_ofNat`, so had to change to `simp`,\n-- presumably because `(n : ℤ)` is `Nat.cast` and not just `ofNat`\n@[norm_cast]\ntheorem ofNat_isUnit {n : ℕ} : IsUnit (n : ℤ) ↔ IsUnit n := by\n  simp [isUnit_iff_natAbs_eq]\n#align int.of_nat_is_unit Int.ofNat_isUnit\n\ntheorem isUnit_mul_self {a : ℤ} (ha : IsUnit a) : a * a = 1 :=\n  (isUnit_eq_one_or ha).elim (fun h => h.symm ▸ rfl) fun h => h.symm ▸ rfl\n#align int.is_unit_mul_self Int.isUnit_mul_self\n\n-- Porting note: this was proven in mathlib3 with `tidy` which hasn't been ported yet\ntheorem isUnit_add_isUnit_eq_isUnit_add_isUnit {a b c d : ℤ} (ha : IsUnit a) (hb : IsUnit b)\n    (hc : IsUnit c) (hd : IsUnit d) : a + b = c + d ↔ a = c ∧ b = d ∨ a = d ∧ b = c := by\n  rw [isUnit_iff] at ha hb hc hd\n  cases ha <;> cases hb <;> cases hc <;> cases hd <;>\n      subst a <;> subst b <;> subst c <;> subst d <;>\n    simp\n#align int.is_unit_add_is_unit_eq_is_unit_add_is_unit Int.isUnit_add_isUnit_eq_isUnit_add_isUnit\n\ntheorem eq_one_or_neg_one_of_mul_eq_neg_one {z w : ℤ} (h : z * w = -1) : z = 1 ∨ z = -1 :=\n  Or.elim (eq_one_or_neg_one_of_mul_eq_neg_one' h) (fun H => Or.inl H.1) fun H => Or.inr H.1\n#align int.eq_one_or_neg_one_of_mul_eq_neg_one Int.eq_one_or_neg_one_of_mul_eq_neg_one\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/Units.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.7591353020553833}}
{"text": "/-\nCopyright (c) 2017 Galois Inc.  All rights reserved.\nAuthor: Joe Hendrix\n\nThis module defines operations for simplifying comparisons between\nnatural numbers.\n-/\nimport data.nat.basic\nimport .simplify_eq\n\nnamespace nat\n\n-- Reduce x < y to theorem with addition\nprotected theorem lt_is_succ_le (x y : ℕ) : x < y ↔ x + 1 ≤ y := by trivial\n\n------------------------------------------------------------------------\n-- le theorems\n\nprotected lemma le_zero_iff_eq_zero (n : nat) : n ≤ 0 ↔ n = 0 :=\nbegin\n  cases n,\n  simp,\n  { apply iff.intro,\n    { intro h,\n      have pr := not_succ_le_zero _ h,\n      contradiction,\n    },\n    { contradiction, },\n  },\nend\n\n-- Reduce proof that product is greater than one to constraints\n-- on variables.\nlemma one_le_mul (m n : ℕ) : 1 ≤ m * n ↔ 1 ≤ m ∧ 1 ≤ n :=\nbegin\n  cases n,\n  case zero {\n    simp [nat.le_zero_iff_eq_zero],\n   },\n  case succ n {\n    simp [nat.mul_succ],\n    cases (nat.eq_zero_or_pos m) with h h,\n    {\n      simp [h, le_zero_iff],\n    },\n    {\n      have g : 1 ≤ m := h,\n      simp [g, succ_le_succ_iff, nat.zero_le],\n      transitivity,\n      exact g,\n      apply nat.le_add_right,\n    },\n  },\nend\n\n-- Reduce proof that power is greater than one to constraints\n-- on variables.\nlemma one_le_pow (m n : ℕ) : 1 ≤ m^n ↔ n = 0 ∨ 1 ≤ m :=\nbegin\n  induction n,\n  case zero { simp, },\n  case succ n ind {\n    simp [nat.pow, one_le_mul, ind],\n    by_cases (1 ≤ m) with h,\n    all_goals {\n      simp [nat.lt_is_succ_le] at h,\n      simp [h, not_succ_eq_zero],\n    },\n  },\nend\n\n-- This rewrites a subtraction on left-hand-side of inequality into an\n-- addition, and one of two additional checks.\nprotected lemma sub_le_iff' (a m n : ℕ) : a - n ≤ m ↔ a ≤ m + n :=\nbegin\n  revert a m,\n  induction n,\n  case nat.zero {\n    simp,\n  },\n  case nat.succ n ind {\n    intros a m,\n    cases a,\n    case nat.zero {\n      simp [zero_le],\n    },\n    case nat.succ {\n      simp [add_succ, nat.succ_le_succ_iff, ind],\n    },\n  },\nend\n\n------------------------------------------------------------------------\n-- lt theorems\n\n-- Reduce succ x < succ y\nprotected lemma succ_lt_succ_iff : ∀{m n : ℕ}, succ n < succ m ↔ n < m :=\nbegin\n  intros m n,\n  simp [nat.lt_is_succ_le, nat.succ_le_succ_iff],\nend\n\n-- This rewrites a subtraction on left-hand-side of inequality into an\n-- addition, and one of two additional checks.\nprotected lemma sub_lt_iff' (a m n : ℕ) : a - n < m ↔ (a < m + n ∧ (n ≤ a ∨ 0 < m)) :=\nbegin\n  revert a m,\n  induction n,\n  case nat.zero {\n    intros a m,\n    simp [zero_le],\n  },\n  case nat.succ n ind {\n    intros a m,\n    cases a,\n    case nat.zero {\n      simp [nat.zero_sub, zero_lt_succ, not_succ_le_zero],\n    },\n    case nat.succ {\n      simp [add_succ, nat.succ_lt_succ_iff, nat.succ_le_succ_iff, ind],\n    },\n  },\nend\n\n\n-- This rewrites a subtraction on right-hand side of inequality into an addition.\nprotected lemma lt_sub_iff (a m n : ℕ) : a < m - n ↔ a + n < m :=\nbegin\n  revert n,\n  induction m with m ind,\n  { simp [nat.lt_is_succ_le, add_succ, nat.not_succ_le_zero, nat.zero_sub],\n  },\n  { intro n,\n    cases n with n,\n    { simp, },\n    { simp [nat.succ_lt_succ_iff, ind],\n    },\n  },\nend\n\n------------------------------------------------------------------------\n-- Specialized lemmas\n\nprotected lemma sub_add_iff : ∀(m n p : ℕ),\n   (m - n) + p = if n ≤ m then (m + p) - n else p :=\nbegin\n  intros m n p,\n  revert n,\n  induction m,\n  case zero {\n    intro n,\n    simp,\n    cases n,\n    case zero { simp, },\n    case succ { simp [nat.not_succ_le_zero], },\n  },\n  case succ m ind {\n    intro n,\n    cases n,\n    case zero {\n      simp [nat.zero_le],\n    },\n    case succ n {\n      simp only [nat.succ_sub_succ],\n      by_cases (n ≤ m) with h,\n      {\n        simp only [succ_le_succ_iff, h, ind, if_pos, succ_add, succ_sub_succ],\n      },\n      {\n        simp [ind, if_neg, succ_le_succ_iff, h],\n      }\n    }\n  }\n end\n\nlemma le_add (a b : ℕ) : a ≤ a + b :=\nbegin\n  induction b,\n  case zero {\n    exact less_than_or_equal.refl a,\n  },\n  case succ b ind {\n    exact less_than_or_equal.step ind,\n  },\nend\n\nend nat\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/nat/simplify_le.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178870347122, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7591352861352124}}
{"text": "import algebra.comm_rings.basic\nimport algebra.comm_rings.ideals.basic\n\nnamespace comm_ring\n\nuniverses u v\n\nopen set\nopen classical\n\ndef univ_as_ideal {R : Type u} [comm_ring R] : ideal R :=\n{\n  body := univ,\n  contains_zero := trivial,\n  minus_closure := λ _ _, trivial,\n  add_closure := λ _ _ _ _, trivial,\n  mul_absorb := λ _ _ _, trivial,\n}\n\ndef ideal_generated_by_set_set {R : Type u} [comm_ring R] (S : set R) : set R := λ x, linear_combination univ S x\n\nlemma ideal_gen_set_contains_zero {R : Type u} [l:comm_ring R] (S : set R) : l.zero ∈ ideal_generated_by_set_set S :=\nbegin\n  exact linear_combination.empty_sum,\nend\n\nlemma ideal_gen_set_add_closure {R : Type u} [comm_ring R] (S : set R) :\n   ∀ (a b : R), (a ∈ ideal_generated_by_set_set S) → (b ∈ ideal_generated_by_set_set S) \n   → (a + b ∈ ideal_generated_by_set_set S) :=\nbegin\n  intros a b ha hb,\n  induction ha with x r s l hx hs hl sum hlb,\n  rw add_comm,\n  rw add_zero,\n  exact hb,\n  rw sum,\n  rw ← add_assoc,\n  apply linear_combination.add_term,\n  exact hx,\n  exact hs,\n  exact hlb,\n  refl,\nend\n\nlemma ideal_gen_set_minus_closure {R : Type u} [comm_ring R] (S : set R) \n  : ∀ r : R, r ∈ ideal_generated_by_set_set S → -r ∈ ideal_generated_by_set_set S :=\nbegin\n  intros r hr,\n  induction hr with r a b l hainuniv hbinS hl hr hminusl,\n  rw minus_zero_zero,\n  exact ideal_gen_set_contains_zero S,\n  rw [hr,minus_dis,minus_mul],\n  apply linear_combination.add_term,\n  trivial,\n  exact hbinS,\n  exact hminusl,\n  refl,\nend\n\nlemma ideal_gen_set_mul_absorb {R : Type u} [comm_ring R] (S : set R) \n  : ∀ r : R, ∀ {i : R}, i ∈ ideal_generated_by_set_set S → (r * i) ∈ ideal_generated_by_set_set S :=\nbegin\n  intros r i hi,\n  induction hi with  i y s l hy hs hl sum hlb,\n  rw mul_zero,\n  exact linear_combination.empty_sum,\n  rw sum,\n  rw [mul_dis,mul_assoc],\n  apply linear_combination.add_term,\n  trivial,\n  exact hs,\n  exact hlb,\n  refl,\nend\n\ndef ideal_generated_by_set {R : Type u} [comm_ring R] (S : set R) : ideal R :=\n{\n  body := ideal_generated_by_set_set S,\n  contains_zero := ideal_gen_set_contains_zero S,\n  minus_closure := ideal_gen_set_minus_closure S,\n  mul_absorb := ideal_gen_set_mul_absorb S,\n  add_closure := ideal_gen_set_add_closure S,\n}\n\ndef zero_ideal (R : Type u) [comm_ring R] : ideal R := ideal_generated_by_set (λ x, x = 0)\n\ntheorem zero_ideal_is_just_zero {R : Type u} [comm_ring R] : ∀ {x : R} , x ∈ (zero_ideal R).body → x = 0 :=\nbegin\n  intros x hx,\n  induction hx with y s₁ s₂ l hs₁ hs₂ hl sum hsum,\n  refl,\n  rw sum,\n  have zs₂ : s₂ = 0 := hs₂,\n  rw [zs₂,mul_zero,hsum,add_zero],\nend\n\ntheorem zero_ideal_proper {R : Type u} [comm_ring R] (not_zero : ∃ x : R , x ≠ 0) : ↑(zero_ideal R) ≠ @univ R :=\nbegin\n  intro ab,\n  let x := some not_zero,\n  have hx : x ≠ 0 := some_spec not_zero,\n  apply hx,\n  have hxuniv : x ∈ @univ R := trivial,\n  rw ← ab at hxuniv,\n  apply zero_ideal_is_just_zero,\n  exact hxuniv,  \nend\n\ndef product_of_ideals_set {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) : set R :=\n  λ x, linear_combination ↑I₁ ↑I₂ x\n\nlemma product_of_ideals_contains_zero {R : Type u} [l:comm_ring R] (I₁ : ideal R) (I₂ : ideal R) : l.zero ∈ product_of_ideals_set I₁ I₂ :=\n  linear_combination.empty_sum\n\nlemma product_of_ideals_add_closure {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ∀ i₁ i₂ : R, i₁ ∈ product_of_ideals_set I₁ I₂ → i₂ ∈ product_of_ideals_set I₁ I₂\n    → i₁ + i₂ ∈ product_of_ideals_set I₁ I₂ :=\nbegin\n  intros i₁ i₂ hi₁ hi₂,\n  induction hi₂ with i₂ s₁ s₂ l hs₁ hs₂ hl hi₂  hsum,\n  rw add_zero,\n  exact hi₁,\n  rw hi₂,\n  have sub : i₁ + (s₁ * s₂ + l) = s₁ * s₂ + (i₁ + l),\n    simp [add_assoc,add_comm],\n  rw sub,\n  apply linear_combination.add_term,\n  exact hs₁,\n  exact hs₂,\n  exact hsum,\n  refl,\nend\n\nlemma product_of_ideals_mul_absorb {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ∀ r : R, ∀ {i : R}, i ∈ product_of_ideals_set I₁ I₂ → (r * i) ∈ product_of_ideals_set I₁ I₂ :=\nbegin\n  intros r i hi,\n  induction hi with i i₁ i₂ l hi₁ hi₂ hl hi hprod,\n  rw mul_zero,\n  exact linear_combination.empty_sum,\n  rw hi,\n  rw mul_dis,\n  rw mul_assoc,\n  apply linear_combination.add_term,\n  apply I₁.mul_absorb,\n  exact r,\n  exact hi₁,\n  exact hi₂,\n  exact hprod,\n  refl,\nend\n\nlemma product_of_ideals_minus_closure {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ∀ a, a ∈ product_of_ideals_set I₁ I₂ → -a ∈ product_of_ideals_set I₁ I₂ :=\nbegin\n  intros a ha,\n  induction ha with a i₁ i₂ l hi₁ hi₂ hl ha hlminus,\n  rw minus_zero_zero,\n  exact product_of_ideals_contains_zero I₁ I₂,\n  rw [ha, minus_dis,minus_mul],\n  apply linear_combination.add_term,\n  apply I₁.minus_closure,\n  exact hi₁,\n  exact hi₂,\n  exact hlminus,\n  refl,\nend\n\ndef product_of_ideals {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) : ideal R := \n  {\n    body          := product_of_ideals_set I₁ I₂,\n    contains_zero := product_of_ideals_contains_zero I₁ I₂,\n    minus_closure := product_of_ideals_minus_closure I₁ I₂,\n    add_closure   := product_of_ideals_add_closure I₁ I₂,\n    mul_absorb    := product_of_ideals_mul_absorb I₁ I₂\n  }\n\ninstance mul_ideals {R : Type u} [comm_ring R] : has_mul (ideal R) := ⟨ λ I₁ I₂, product_of_ideals I₁ I₂⟩ \n\ndef sum_of_ideals_set {R : Type u} [l:comm_ring R] (I₁ : ideal R) (I₂ : ideal R) : set R := λ r : R, ∃ i₁ i₂ : R, i₁ ∈ I₁.body ∧ i₂ ∈ I₂.body ∧ r = i₁ + i₂\n\nlemma half_sum_of_pairs_set_commuative {R :Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : sum_of_ideals_set I₁ I₂ ⊆ sum_of_ideals_set I₂ I₁ :=\nbegin\n  intros x hx,\n  cases hx with x₁ hx₁,\n  cases hx₁ with x₂ hx₁x₂,\n  cases hx₁x₂ with hx₁inI₁ the_rest,\n  cases the_rest with hx₂inI₂ hx,\n  existsi x₂,\n  existsi x₁,\n  split,\n  exact hx₂inI₂,\n  split,\n  exact hx₁inI₁,\n  rw add_comm,\n  exact hx,\nend\n\nlemma sum_of_pair_of_ideals_upper_bound {R :Type u} [l:comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ↑I₁ ⊆ sum_of_ideals_set I₁ I₂ :=\nbegin\n  intros i hi,\n  existsi i,\n  existsi l.zero,\n  split,\n  exact hi,\n  split,\n  exact I₂.contains_zero,\n  rw add_zero,\nend\n\nlemma sum_of_ideals_contains_zero {R : Type u} [l:comm_ring R] (I₁ : ideal R) (I₂ : ideal R) : l.zero ∈ sum_of_ideals_set I₁ I₂ :=\nbegin\n  existsi l.zero,\n  existsi l.zero,\n  split,\n  exact I₁.contains_zero,\n  split,\n  exact I₂.contains_zero,\n  rw add_zero l.zero,\nend\n\nlemma sum_of_ideals_add_closure {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ∀ a b, a ∈ sum_of_ideals_set I₁ I₂ → b ∈ sum_of_ideals_set I₁ I₂ → a + b ∈ sum_of_ideals_set I₁ I₂ :=\nbegin\n  intros a b ha hb,\n  cases ha with a₁ ha₁,\n  cases ha₁ with a₂ ha₁a₂,\n  cases ha₁a₂ with ha₁inI₁ the_rest,\n  cases the_rest with ha₂inI₂ ha,\n  cases hb with b₁ hb₁,\n  cases hb₁ with b₂ hb₁b₂,\n  cases hb₁b₂ with hb₁inI₁ the_rest,\n  cases the_rest with hb₂inI₂ hb,\n  existsi a₁ + b₁,\n  existsi a₂ + b₂,\n  split,\n  apply I₁.add_closure,\n  exact ha₁inI₁,\n  exact hb₁inI₁,\n  split,\n  apply I₂.add_closure,\n  exact ha₂inI₂,\n  exact hb₂inI₂,\n  rw [ha,hb],\n  exact calc (a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + b₁) + b₂   : by simp [add_assoc]\n                               ... = (a₁ + b₁) + (a₂ + b₂) : by {rw add_comm a₂ b₁,simp [add_assoc]},\nend \n\nlemma sum_of_ideals_mul_absorb {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ∀ r : R, ∀ {i}, i ∈ sum_of_ideals_set I₁ I₂ → r * i ∈ sum_of_ideals_set I₁ I₂ :=\nbegin\n  intros r i hi,\n  cases hi with i₁ hi₁,\n  cases hi₁ with i₂ hi₁i₂,\n  cases hi₁i₂ with hi₁inI₁ the_rest,\n  cases the_rest with hi₂inI₂ hi,\n  rw hi,\n  rw mul_dis,\n  apply sum_of_ideals_add_closure,\n  apply sum_of_pair_of_ideals_upper_bound,\n  apply I₁.mul_absorb,\n  exact hi₁inI₁,\n  apply half_sum_of_pairs_set_commuative,\n  apply sum_of_pair_of_ideals_upper_bound,\n  apply I₂.mul_absorb,\n  exact hi₂inI₂,\nend\n\nlemma sum_of_ideals_minus_closure {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) \n  : ∀ i : R, i ∈ sum_of_ideals_set I₁ I₂ → -i ∈ sum_of_ideals_set I₁ I₂ :=\nbegin\n  intros i hi,\n  cases hi with i₁ hi₁,\n  cases hi₁ with i₂ hi₁i₂,\n  cases hi₁i₂ with hi₁inI₁ the_rest,\n  cases the_rest with hi₂inI₂ hi,\n  existsi -i₁,\n  existsi -i₂,\n  split,\n  apply I₁.minus_closure,\n  exact hi₁inI₁,\n  split,\n  apply I₂.minus_closure,\n  exact hi₂inI₂,\n  rw [hi,minus_dis],\nend\n\ndef sum_of_ideals {R : Type u} [comm_ring R] (I₁ : ideal R) (I₂ : ideal R) : ideal R :=\n  {\n    body := sum_of_ideals_set I₁ I₂,\n    contains_zero := sum_of_ideals_contains_zero I₁ I₂,\n    minus_closure := sum_of_ideals_minus_closure I₁ I₂,\n    add_closure := sum_of_ideals_add_closure I₁ I₂,\n    mul_absorb := sum_of_ideals_mul_absorb I₁ I₂,\n  }\n\ninstance add_ideals {R : Type u} [comm_ring R]  : has_add (ideal R) := ⟨λ I₁ I₂, sum_of_ideals I₁ I₂⟩ \n\ndef princple_ideal {R : Type u} [comm_ring R] (r : R) : ideal R := ideal_generated_by_set (λ x, x = r)\n\nlemma elements_of_princple_ideal {R : Type u} [comm_ring R] {x : R} {r : R} : r ∈ (princple_ideal x).body → ∃ a : R, r = a * x :=\nbegin\n  intro h,\n  induction h with r a₁ s l trv hs trv hr hl,\n  existsi (0:R),\n  rw [mul_comm, mul_zero],\n  let a₂ := some hl,\n  have ha₂ : l = a₂ * x := some_spec hl,\n  existsi (a₁ + a₂),\n  have hsx : s = x := hs,\n  rw [mul_comm,mul_dis,mul_comm,hr,ha₂,hsx],\n  simp [mul_comm],\nend\n\nlemma princple_ideal_membership {R : Type u} [comm_ring R] {x : R} {r : R} : (∃ a : R, r = a * x) → r ∈ (princple_ideal x).body :=\nbegin\n  intro h,\n  cases h with a ha,\n  rw ha,\n  apply linear_combination.add_term,\n  trivial,\n  exact rfl,\n  apply linear_combination.empty_sum,\n  rw add_zero,\nend\n\ntheorem intersection_of_ideals_add_closure {R : Type u} [comm_ring R] (C : set (ideal R)) \n  : ∀ a b : R, (a ∈ ⋂₀ (image (λ I : ideal R, I.body) C)) → (b ∈ ⋂₀ (image (λ I : ideal R, I.body) C))\n    → (a + b) ∈ ⋂₀ (image (λ I : ideal R, I.body) C) :=\nbegin\n  intros a b ha hb,\n  intros A hA,\n  have hainA := ha A hA,\n  have hbinA := hb A hA,\n  cases hA with I hI,\n  cases hI with hIinC hrw,\n  simp at hrw,\n  rw ← hrw at hainA,\n  rw ← hrw at hbinA,\n  rw ← hrw,\n  apply I.add_closure,\n  exact hainA,\n  exact hbinA,\nend\n\ntheorem intersection_of_ideals_contains_zero {R : Type u} [comm_ring R] (C : set (ideal R)) \n  : (0: R) ∈ ⋂₀ (image (λ I : ideal R, I.body) C) :=\nbegin\n  intros A hA,\n  cases hA with I hI,\n  cases hI with hIinC hrw,\n  simp at hrw,\n  rw ← hrw,\n  apply I.contains_zero,\nend\n\ntheorem intersection_of_ideals_mul_absorb {R : Type u} [comm_ring R] (C : set (ideal R)) \n  : ∀ (r : R) {i}, i ∈ ⋂₀ (image (λ I : ideal R, I.body) C) → (r * i) ∈ ⋂₀ (image (λ I : ideal R, I.body) C) :=\nbegin\n  intros r i hi A hA,\n  have hiinA := hi A hA,\n  cases hA with I hI,\n  cases hI with hIinC hrw,\n  simp at hrw,\n  rw ← hrw,\n  apply I.mul_absorb,\n  rw hrw,\n  exact hiinA,\nend\n\ntheorem intersection_of_ideals_minus_closure {R : Type u} [comm_ring R] (C : set (ideal R))\n  : ∀ i, i ∈  ⋂₀ (image (λ I : ideal R, I.body) C) → -i ∈  ⋂₀ (image (λ I : ideal R, I.body) C) :=\nbegin\n  intros i hi A hA,\n  have hiinA := hi A hA,\n  cases hA with I hI,\n  cases hI with hIinC hrw,\n  simp at hrw,\n  rw ← hrw,\n  apply I.minus_closure,\n  rw hrw,\n  exact hiinA,\nend\n\n\ndef intersection_of_ideals {R : Type u} [comm_ring R] (C : set (ideal R)) : ideal R :=\nbegin\n  split,\n  exact intersection_of_ideals_contains_zero C,\n  exact intersection_of_ideals_minus_closure C,\n  exact intersection_of_ideals_add_closure C,\n  exact intersection_of_ideals_mul_absorb C,\nend\n\nprefix `⋂₀`:110 := intersection_of_ideals\n\ninstance ideals_have_inter {R : Type u} [comm_ring R] : has_inter (ideal R) := ⟨ λ I₁ I₂, ⋂₀ (list_to_set [I₁,I₂])⟩  \n\ntheorem ideal_pairwise_inter_set {R : Type u} [comm_ring R] (I₁ I₂ : ideal R) \n  : (↑(I₁ ∩ I₂) : set R) = ↑I₁ ∩ ↑I₂ :=\nbegin\n  cases list_to_set_pair_mem ↑I₁ ↑I₂ with hI₁ hI₂,\n  have trv₁ : I₁ ∩ I₂ = ⋂₀ (list_to_set [I₁,I₂]) := rfl,\n  rw trv₁,\n  have trv₂ : ↑I₁ = I₁.body := rfl,\n  have trv₃ : ↑I₂ = I₂.body := rfl,\n  have trv₄ : list.map (λ I :ideal R, I.body) [I₁,I₂] = [↑I₁,↑I₂],\n    rw [trv₂,trv₃],\n    refl,\n  apply subset_antisymmetric,\n  split,\n  intros x hx,\n  split,\n  apply hx,\n  rw image_of_list_to_set,\n  rw trv₄,\n  exact hI₁,\n  apply hx,\n  rw image_of_list_to_set,\n  rw trv₄,\n  exact hI₂,\n  intros x hx,\n  intros A hA,\n  rw image_of_list_to_set at hA,\n  rw trv₄ at hA,\n  cases hA,\n  rw hA,\n  apply intersection_in_set,\n  assumption,\n  cases hA,\n  rw hA,\n  apply intersection_in_set,\n  rw intersection_commuative,\n  assumption,\n  apply false.elim,\n  exact hA, \nend \n\ndef preimage_set {R₁ : Type u} [comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) (I : ideal R₂) : set R₁ :=\n  λ r : R₁, φ r ∈ I.body \n\ntheorem preimage_add_closure {R₁ : Type u} [comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) (I : ideal R₂) \n  : ∀ r₁ r₂ : R₁, r₁ ∈ (preimage_set φ I) → r₂ ∈ (preimage_set φ I) → (r₁ + r₂) ∈ (preimage_set φ I) :=\nbegin\n  intros r₁ r₂ hr₁ hr₂,\n  have h: φ.map (r₁ + r₂) ∈ ↑I,\n    rw φ.prevs_add,\n    apply I.add_closure,\n    exact hr₁,\n    exact hr₂,\n  exact h,  \nend\n\ntheorem preimage_mul_absorb {R₁ : Type u} [comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) (I : ideal R₂)\n  : ∀ r : R₁, ∀ {i : R₁}, i ∈ preimage_set φ I → (r * i) ∈ preimage_set φ I :=\nbegin\n  intros r i hi,\n  have h : φ.map (r * i) ∈ ↑I,\n    rw φ.prevs_mul,\n    apply I.mul_absorb,\n    exact hi,\n  exact h,\nend\n\ntheorem preimage_contains_zero {R₁ : Type u} [l:comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) (I : ideal R₂) \n  : l.zero ∈ preimage_set φ I :=\nbegin\n  have trv : φ.map = ⇑φ := rfl,\n  have h : φ.map 0 ∈ ↑I,\n    rw trv,\n    rw ring_hom_preserves_zero φ,\n    exact I.contains_zero,\n  exact h,\nend\n\ntheorem preimage_of_ideal_minus_closure {R₁ : Type u} [comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) (I : ideal R₂)\n  : ∀ x : R₁, x ∈ preimage_set φ I → -x ∈ preimage_set φ I :=\nbegin\n  intros x hx,\n  have h : φ (-x) ∈ ↑I,\n    rw minus_commutes_with_hom,\n    apply I.minus_closure,\n    exact hx,\n  exact h,\nend\n\ndef preimage_of_ideal {R₁ : Type u} [l:comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) (I : ideal R₂) : ideal R₁ :=\n  {\n    body := preimage_set φ I,\n    contains_zero := preimage_contains_zero φ I,\n    minus_closure := preimage_of_ideal_minus_closure φ I,\n    add_closure := preimage_add_closure φ I,\n    mul_absorb := preimage_mul_absorb φ I,\n  }\n\ndef ker {R₁ : Type u} [l:comm_ring R₁] {R₂ : Type v} [comm_ring R₂] (φ : R₁ →ᵣ R₂) : ideal R₁ := preimage_of_ideal φ (zero_ideal R₂) \n\n\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/instances.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8175744850834648, "lm_q1q2_score": 0.7590433454415944}}
{"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ébastien Gouëzel\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.analysis.calculus.fderiv\nimport Mathlib.data.polynomial.derivative\nimport Mathlib.PostPort\n\nuniverses u v u_1 w \n\nnamespace Mathlib\n\n/-!\n\n# One-dimensional derivatives\n\nThis file defines the derivative of a function `f : 𝕜 → F` where `𝕜` 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échet\nderivatives](./fderiv.lean). We first introduce predicates defined in terms\nof the corresponding predicates for Fréchet 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) • f' + o (y - z)` as `y, z → 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échet 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 → x⁻¹`\n  - multiplication of two functions in `𝕜 → 𝕜`\n  - multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E`\n  - composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜`\n  - composition of a function in `F → E` with a function in `𝕜 → 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 : ℝ) : deriv (λ 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échet 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/--\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) • f' + o(x' - x)` where `x'` converges along the filter `L`.\n-/\ndef has_deriv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : filter 𝕜) :=\n  has_fderiv_at_filter f (continuous_linear_map.smul_right 1 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) • f' + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (f : 𝕜 → F) (f' : F) (s : set 𝕜) (x : 𝕜) :=\n  has_deriv_at_filter f f' x (nhds_within x s)\n\n/--\n`f` has the derivative `f'` at the point `x`.\n\nThat is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x`.\n-/\ndef has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (f : 𝕜 → F) (f' : F) (x : 𝕜) :=\n  has_deriv_at_filter f f' x (nhds 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) • f' + o(y - z)` as `y, z → x`. -/\ndef has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (f : 𝕜 → F) (f' : F) (x : 𝕜) :=\n  has_strict_fderiv_at f (continuous_linear_map.smul_right 1 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., `∃ f', has_deriv_within_at f f' s x`), then\n`f x' = f x + (x' - x) • deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.\n-/\ndef deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (f : 𝕜 → F) (s : set 𝕜) (x : 𝕜) : F :=\n  coe_fn (fderiv_within 𝕜 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., `∃ f', has_deriv_at f f' x`), then\n`f x' = f x + (x' - x) • deriv f x + o(x' - x)` where `x'` converges to `x`.\n-/\ndef deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (f : 𝕜 → F) (x : 𝕜) : F :=\n  coe_fn (fderiv 𝕜 f x) 1\n\n/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/\ntheorem has_fderiv_at_filter_iff_has_deriv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {L : filter 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_fderiv_at_filter f f' x L ↔ has_deriv_at_filter f (coe_fn f' 1) x L := sorry\n\ntheorem has_fderiv_at_filter.has_deriv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {L : filter 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_fderiv_at_filter f f' x L → has_deriv_at_filter f (coe_fn f' 1) x L :=\n  iff.mp has_fderiv_at_filter_iff_has_deriv_at_filter\n\n/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/\ntheorem has_fderiv_within_at_iff_has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_fderiv_within_at f f' s x ↔ has_deriv_within_at f (coe_fn f' 1) s x :=\n  has_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` -/\ntheorem has_deriv_within_at_iff_has_fderiv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {f' : F} : has_deriv_within_at f f' s x ↔ has_fderiv_within_at f (continuous_linear_map.smul_right 1 f') s x :=\n  iff.rfl\n\ntheorem has_fderiv_within_at.has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_fderiv_within_at f f' s x → has_deriv_within_at f (coe_fn f' 1) s x :=\n  iff.mp has_fderiv_within_at_iff_has_deriv_within_at\n\ntheorem has_deriv_within_at.has_fderiv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {f' : F} : has_deriv_within_at f f' s x → has_fderiv_within_at f (continuous_linear_map.smul_right 1 f') s x :=\n  iff.mp has_deriv_within_at_iff_has_fderiv_within_at\n\n/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/\ntheorem has_fderiv_at_iff_has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_fderiv_at f f' x ↔ has_deriv_at f (coe_fn f' 1) x :=\n  has_fderiv_at_filter_iff_has_deriv_at_filter\n\ntheorem has_fderiv_at.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_fderiv_at f f' x → has_deriv_at f (coe_fn f' 1) x :=\n  iff.mp has_fderiv_at_iff_has_deriv_at\n\ntheorem has_strict_fderiv_at_iff_has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_strict_fderiv_at f f' x ↔ has_strict_deriv_at f (coe_fn f' 1) x := sorry\n\nprotected theorem has_strict_fderiv_at.has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {f' : continuous_linear_map 𝕜 𝕜 F} : has_strict_fderiv_at f f' x → has_strict_deriv_at f (coe_fn f' 1) x :=\n  iff.mp has_strict_fderiv_at_iff_has_strict_deriv_at\n\n/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/\ntheorem has_deriv_at_iff_has_fderiv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {f' : F} : has_deriv_at f f' x ↔ has_fderiv_at f (continuous_linear_map.smul_right 1 f') x :=\n  iff.rfl\n\ntheorem deriv_within_zero_of_not_differentiable_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (h : ¬differentiable_within_at 𝕜 f s x) : deriv_within f s x = 0 := sorry\n\ntheorem deriv_zero_of_not_differentiable_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (h : ¬differentiable_at 𝕜 f x) : deriv f x = 0 := sorry\n\ntheorem unique_diff_within_at.eq_deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {f₁' : F} {x : 𝕜} (s : set 𝕜) (H : unique_diff_within_at 𝕜 s x) (h : has_deriv_within_at f f' s x) (h₁ : has_deriv_within_at f f₁' s x) : f' = f₁' :=\n  iff.mp continuous_linear_map.smul_right_one_eq_iff (unique_diff_within_at.eq H h h₁)\n\ntheorem has_deriv_at_filter_iff_tendsto {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} : has_deriv_at_filter f f' x L ↔\n  filter.tendsto (fun (x' : 𝕜) => norm (x' - x)⁻¹ * norm (f x' - f x - (x' - x) • f')) L (nhds 0) :=\n  has_fderiv_at_filter_iff_tendsto\n\ntheorem has_deriv_within_at_iff_tendsto {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} : has_deriv_within_at f f' s x ↔\n  filter.tendsto (fun (x' : 𝕜) => norm (x' - x)⁻¹ * norm (f x' - f x - (x' - x) • f')) (nhds_within x s) (nhds 0) :=\n  has_fderiv_at_filter_iff_tendsto\n\ntheorem has_deriv_at_iff_tendsto {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} : has_deriv_at f f' x ↔\n  filter.tendsto (fun (x' : 𝕜) => norm (x' - x)⁻¹ * norm (f x' - f x - (x' - x) • f')) (nhds x) (nhds 0) :=\n  has_fderiv_at_filter_iff_tendsto\n\ntheorem has_strict_deriv_at.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_strict_deriv_at f f' x) : has_deriv_at f f' x :=\n  has_strict_fderiv_at.has_fderiv_at h\n\n/-- If the domain has dimension one, then Fréchet 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⁻¹=0`. -/\ntheorem has_deriv_at_filter_iff_tendsto_slope {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} : has_deriv_at_filter f f' x L ↔\n  filter.tendsto (fun (y : 𝕜) => y - x⁻¹ • (f y - f x)) (L ⊓ filter.principal (singleton xᶜ)) (nhds f') := sorry\n\ntheorem has_deriv_within_at_iff_tendsto_slope {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} : has_deriv_within_at f f' s x ↔\n  filter.tendsto (fun (y : 𝕜) => y - x⁻¹ • (f y - f x)) (nhds_within x (s \\ singleton x)) (nhds f') := sorry\n\ntheorem has_deriv_within_at_iff_tendsto_slope' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (hs : ¬x ∈ s) : has_deriv_within_at f f' s x ↔ filter.tendsto (fun (y : 𝕜) => y - x⁻¹ • (f y - f x)) (nhds_within x s) (nhds f') := sorry\n\ntheorem has_deriv_at_iff_tendsto_slope {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} : has_deriv_at f f' x ↔ filter.tendsto (fun (y : 𝕜) => y - x⁻¹ • (f y - f x)) (nhds_within x (singleton xᶜ)) (nhds f') :=\n  has_deriv_at_filter_iff_tendsto_slope\n\n@[simp] theorem has_deriv_within_at_diff_singleton {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} : has_deriv_within_at f f' (s \\ singleton x) x ↔ has_deriv_within_at f f' s x := sorry\n\n@[simp] theorem has_deriv_within_at_Ioi_iff_Ici {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} [partial_order 𝕜] : has_deriv_within_at f f' (set.Ioi x) x ↔ has_deriv_within_at f f' (set.Ici x) x := sorry\n\ntheorem has_deriv_within_at.Ioi_of_Ici {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} [partial_order 𝕜] : has_deriv_within_at f f' (set.Ici x) x → has_deriv_within_at f f' (set.Ioi x) x :=\n  iff.mpr has_deriv_within_at_Ioi_iff_Ici\n\n@[simp] theorem has_deriv_within_at_Iio_iff_Iic {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} [partial_order 𝕜] : has_deriv_within_at f f' (set.Iio x) x ↔ has_deriv_within_at f f' (set.Iic x) x := sorry\n\ntheorem has_deriv_within_at.Iio_of_Iic {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} [partial_order 𝕜] : has_deriv_within_at f f' (set.Iic x) x → has_deriv_within_at f f' (set.Iio x) x :=\n  iff.mpr has_deriv_within_at_Iio_iff_Iic\n\ntheorem has_deriv_at_iff_is_o_nhds_zero {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} : has_deriv_at f f' x ↔ asymptotics.is_o (fun (h : 𝕜) => f (x + h) - f x - h • f') (fun (h : 𝕜) => h) (nhds 0) :=\n  has_fderiv_at_iff_is_o_nhds_zero\n\ntheorem has_deriv_at_filter.mono {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L₁ : filter 𝕜} {L₂ : filter 𝕜} (h : has_deriv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) : has_deriv_at_filter f f' x L₁ :=\n  has_fderiv_at_filter.mono h hst\n\ntheorem has_deriv_within_at.mono {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (h : has_deriv_within_at f f' t x) (hst : s ⊆ t) : has_deriv_within_at f f' s x :=\n  has_fderiv_within_at.mono h hst\n\ntheorem has_deriv_at.has_deriv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (h : has_deriv_at f f' x) (hL : L ≤ nhds x) : has_deriv_at_filter f f' x L :=\n  has_fderiv_at.has_fderiv_at_filter h hL\n\ntheorem has_deriv_at.has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=\n  has_fderiv_at.has_fderiv_within_at h\n\ntheorem has_deriv_within_at.differentiable_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) : differentiable_within_at 𝕜 f s x :=\n  has_fderiv_within_at.differentiable_within_at h\n\ntheorem has_deriv_at.differentiable_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_deriv_at f f' x) : differentiable_at 𝕜 f x :=\n  has_fderiv_at.differentiable_at h\n\n@[simp] theorem has_deriv_within_at_univ {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} : has_deriv_within_at f f' set.univ x ↔ has_deriv_at f f' x :=\n  has_fderiv_within_at_univ\n\ntheorem has_deriv_at_unique {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₀' : F} {f₁' : F} {x : 𝕜} (h₀ : has_deriv_at f f₀' x) (h₁ : has_deriv_at f f₁' x) : f₀' = f₁' :=\n  iff.mp continuous_linear_map.smul_right_one_eq_iff (has_fderiv_at_unique h₀ h₁)\n\ntheorem has_deriv_within_at_inter' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (h : t ∈ nhds_within x s) : has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=\n  has_fderiv_within_at_inter' h\n\ntheorem has_deriv_within_at_inter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (h : t ∈ nhds x) : has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=\n  has_fderiv_within_at_inter h\n\ntheorem has_deriv_within_at.union {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (hs : has_deriv_within_at f f' s x) (ht : has_deriv_within_at f f' t x) : has_deriv_within_at f f' (s ∪ t) x := sorry\n\ntheorem has_deriv_within_at.nhds_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (h : has_deriv_within_at f f' s x) (ht : s ∈ nhds_within x t) : has_deriv_within_at f f' t x :=\n  iff.mp (has_deriv_within_at_inter' ht) (has_deriv_within_at.mono h (set.inter_subset_right t s))\n\ntheorem has_deriv_within_at.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) (hs : s ∈ nhds x) : has_deriv_at f f' x :=\n  has_fderiv_within_at.has_fderiv_at h hs\n\ntheorem differentiable_within_at.has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (h : differentiable_within_at 𝕜 f s x) : has_deriv_within_at f (deriv_within f s x) s x := sorry\n\ntheorem differentiable_at.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (h : differentiable_at 𝕜 f x) : has_deriv_at f (deriv f x) x := sorry\n\ntheorem has_deriv_at.deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_deriv_at f f' x) : deriv f x = f' :=\n  has_deriv_at_unique (differentiable_at.has_deriv_at (has_deriv_at.differentiable_at h)) h\n\ntheorem has_deriv_within_at.deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within f s x = f' :=\n  unique_diff_within_at.eq_deriv s hxs\n    (differentiable_within_at.has_deriv_within_at (has_deriv_within_at.differentiable_within_at h)) h\n\ntheorem fderiv_within_deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} : coe_fn (fderiv_within 𝕜 f s x) 1 = deriv_within f s x :=\n  rfl\n\ntheorem deriv_within_fderiv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} : continuous_linear_map.smul_right 1 (deriv_within f s x) = fderiv_within 𝕜 f s x := sorry\n\ntheorem fderiv_deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} : coe_fn (fderiv 𝕜 f x) 1 = deriv f x :=\n  rfl\n\ntheorem deriv_fderiv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} : continuous_linear_map.smul_right 1 (deriv f x) = fderiv 𝕜 f x := sorry\n\ntheorem differentiable_at.deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within f s x = deriv f x := sorry\n\ntheorem deriv_within_subset {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f t x) : deriv_within f s x = deriv_within f t x :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.mono (differentiable_within_at.has_deriv_within_at h) st) ht\n\n@[simp] theorem deriv_within_univ {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} : deriv_within f set.univ = deriv f := sorry\n\ntheorem deriv_within_inter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (ht : t ∈ nhds x) (hs : unique_diff_within_at 𝕜 s x) : deriv_within f (s ∩ t) x = deriv_within f s x := sorry\n\ntheorem deriv_within_of_open {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hs : is_open s) (hx : x ∈ s) : deriv_within f s x = deriv f x := sorry\n\n/-! ### Congruence properties of derivatives -/\n\ntheorem filter.eventually_eq.has_deriv_at_filter_iff {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f₀ : 𝕜 → F} {f₁ : 𝕜 → F} {f₀' : F} {f₁' : F} {x : 𝕜} {L : filter 𝕜} (h₀ : filter.eventually_eq L f₀ f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') : has_deriv_at_filter f₀ f₀' x L ↔ has_deriv_at_filter f₁ f₁' x L := sorry\n\ntheorem has_deriv_at_filter.congr_of_eventually_eq {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (h : has_deriv_at_filter f f' x L) (hL : filter.eventually_eq L f₁ f) (hx : f₁ x = f x) : has_deriv_at_filter f₁ f' x L := sorry\n\ntheorem has_deriv_within_at.congr_mono {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {t : set 𝕜} (h : has_deriv_within_at f f' s x) (ht : ∀ (x : 𝕜), x ∈ t → f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : has_deriv_within_at f₁ f' t x :=\n  has_fderiv_within_at.congr_mono h ht hx h₁\n\ntheorem has_deriv_within_at.congr {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) (hs : ∀ (x : 𝕜), x ∈ s → f₁ x = f x) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=\n  has_deriv_within_at.congr_mono h hs hx (set.subset.refl s)\n\ntheorem has_deriv_within_at.congr_of_eventually_eq {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) (h₁ : filter.eventually_eq (nhds_within x s) f₁ f) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=\n  has_deriv_at_filter.congr_of_eventually_eq h h₁ hx\n\ntheorem has_deriv_within_at.congr_of_eventually_eq_of_mem {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) (h₁ : filter.eventually_eq (nhds_within x s) f₁ f) (hx : x ∈ s) : has_deriv_within_at f₁ f' s x :=\n  has_deriv_within_at.congr_of_eventually_eq h h₁ (filter.eventually_eq.eq_of_nhds_within h₁ hx)\n\ntheorem has_deriv_at.congr_of_eventually_eq {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_deriv_at f f' x) (h₁ : filter.eventually_eq (nhds x) f₁ f) : has_deriv_at f₁ f' x :=\n  has_deriv_at_filter.congr_of_eventually_eq h h₁ (mem_of_nhds h₁)\n\ntheorem filter.eventually_eq.deriv_within_eq {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hs : unique_diff_within_at 𝕜 s x) (hL : filter.eventually_eq (nhds_within x s) f₁ f) (hx : f₁ x = f x) : deriv_within f₁ s x = deriv_within f s x := sorry\n\ntheorem deriv_within_congr {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hs : unique_diff_within_at 𝕜 s x) (hL : ∀ (y : 𝕜), y ∈ s → f₁ y = f y) (hx : f₁ x = f x) : deriv_within f₁ s x = deriv_within f s x := sorry\n\ntheorem filter.eventually_eq.deriv_eq {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f₁ : 𝕜 → F} {x : 𝕜} (hL : filter.eventually_eq (nhds x) f₁ f) : deriv f₁ x = deriv f x := sorry\n\n/-! ### Derivative of the identity -/\n\ntheorem has_deriv_at_filter_id {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) (L : filter 𝕜) : has_deriv_at_filter id 1 x L :=\n  has_fderiv_at_filter.has_deriv_at_filter (has_fderiv_at_filter_id x L)\n\ntheorem has_deriv_within_at_id {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) (s : set 𝕜) : has_deriv_within_at id 1 s x :=\n  has_deriv_at_filter_id x (nhds_within x s)\n\ntheorem has_deriv_at_id {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : has_deriv_at id 1 x :=\n  has_deriv_at_filter_id x (nhds x)\n\ntheorem has_deriv_at_id' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : has_deriv_at (fun (x : 𝕜) => x) 1 x :=\n  has_deriv_at_filter_id x (nhds x)\n\ntheorem has_strict_deriv_at_id {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : has_strict_deriv_at id 1 x :=\n  has_strict_fderiv_at.has_strict_deriv_at (has_strict_fderiv_at_id x)\n\ntheorem deriv_id {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : deriv id x = 1 :=\n  has_deriv_at.deriv (has_deriv_at_id x)\n\n@[simp] theorem deriv_id' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] : deriv id = fun (_x : 𝕜) => 1 :=\n  funext deriv_id\n\n@[simp] theorem deriv_id'' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : deriv (fun (x : 𝕜) => x) x = 1 :=\n  deriv_id x\n\ntheorem deriv_within_id {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) (s : set 𝕜) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within id s x = 1 :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at_id x s) hxs\n\n/-! ### Derivative of constant functions -/\n\ntheorem has_deriv_at_filter_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (x : 𝕜) (L : filter 𝕜) (c : F) : has_deriv_at_filter (fun (x : 𝕜) => c) 0 x L :=\n  has_fderiv_at_filter.has_deriv_at_filter (has_fderiv_at_filter_const c x L)\n\ntheorem has_strict_deriv_at_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (x : 𝕜) (c : F) : has_strict_deriv_at (fun (x : 𝕜) => c) 0 x :=\n  has_strict_fderiv_at.has_strict_deriv_at (has_strict_fderiv_at_const c x)\n\ntheorem has_deriv_within_at_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (x : 𝕜) (s : set 𝕜) (c : F) : has_deriv_within_at (fun (x : 𝕜) => c) 0 s x :=\n  has_deriv_at_filter_const x (nhds_within x s) c\n\ntheorem has_deriv_at_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (x : 𝕜) (c : F) : has_deriv_at (fun (x : 𝕜) => c) 0 x :=\n  has_deriv_at_filter_const x (nhds x) c\n\ntheorem deriv_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (x : 𝕜) (c : F) : deriv (fun (x : 𝕜) => c) x = 0 :=\n  has_deriv_at.deriv (has_deriv_at_const x c)\n\n@[simp] theorem deriv_const' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (c : F) : (deriv fun (x : 𝕜) => c) = fun (x : 𝕜) => 0 :=\n  funext fun (x : 𝕜) => deriv_const x c\n\ntheorem deriv_within_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] (x : 𝕜) (s : set 𝕜) (c : F) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => c) s x = 0 :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at_const x s c) hxs\n\n/-! ### Derivative of continuous linear maps -/\n\ntheorem continuous_linear_map.has_deriv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {L : filter 𝕜} (e : continuous_linear_map 𝕜 𝕜 F) : has_deriv_at_filter (⇑e) (coe_fn e 1) x L :=\n  has_fderiv_at_filter.has_deriv_at_filter (continuous_linear_map.has_fderiv_at_filter e)\n\ntheorem continuous_linear_map.has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} (e : continuous_linear_map 𝕜 𝕜 F) : has_strict_deriv_at (⇑e) (coe_fn e 1) x :=\n  has_strict_fderiv_at.has_strict_deriv_at (continuous_linear_map.has_strict_fderiv_at e)\n\ntheorem continuous_linear_map.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} (e : continuous_linear_map 𝕜 𝕜 F) : has_deriv_at (⇑e) (coe_fn e 1) x :=\n  continuous_linear_map.has_deriv_at_filter e\n\ntheorem continuous_linear_map.has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} (e : continuous_linear_map 𝕜 𝕜 F) : has_deriv_within_at (⇑e) (coe_fn e 1) s x :=\n  continuous_linear_map.has_deriv_at_filter e\n\n@[simp] theorem continuous_linear_map.deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} (e : continuous_linear_map 𝕜 𝕜 F) : deriv (⇑e) x = coe_fn e 1 :=\n  has_deriv_at.deriv (continuous_linear_map.has_deriv_at e)\n\ntheorem continuous_linear_map.deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} (e : continuous_linear_map 𝕜 𝕜 F) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (⇑e) s x = coe_fn e 1 :=\n  has_deriv_within_at.deriv_within (continuous_linear_map.has_deriv_within_at e) hxs\n\n/-! ### Derivative of bundled linear maps -/\n\ntheorem linear_map.has_deriv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {L : filter 𝕜} (e : linear_map 𝕜 𝕜 F) : has_deriv_at_filter (⇑e) (coe_fn e 1) x L :=\n  continuous_linear_map.has_deriv_at_filter (linear_map.to_continuous_linear_map₁ e)\n\ntheorem linear_map.has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} (e : linear_map 𝕜 𝕜 F) : has_strict_deriv_at (⇑e) (coe_fn e 1) x :=\n  continuous_linear_map.has_strict_deriv_at (linear_map.to_continuous_linear_map₁ e)\n\ntheorem linear_map.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} (e : linear_map 𝕜 𝕜 F) : has_deriv_at (⇑e) (coe_fn e 1) x :=\n  linear_map.has_deriv_at_filter e\n\ntheorem linear_map.has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} (e : linear_map 𝕜 𝕜 F) : has_deriv_within_at (⇑e) (coe_fn e 1) s x :=\n  linear_map.has_deriv_at_filter e\n\n@[simp] theorem linear_map.deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} (e : linear_map 𝕜 𝕜 F) : deriv (⇑e) x = coe_fn e 1 :=\n  has_deriv_at.deriv (linear_map.has_deriv_at e)\n\ntheorem linear_map.deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} (e : linear_map 𝕜 𝕜 F) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (⇑e) s x = coe_fn e 1 :=\n  has_deriv_within_at.deriv_within (linear_map.has_deriv_within_at e) hxs\n\ntheorem has_fpower_series_at.has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {p : formal_multilinear_series 𝕜 𝕜 F} (h : has_fpower_series_at f p x) : has_strict_deriv_at f (coe_fn (p 1) fun (_x : fin 1) => 1) x :=\n  has_strict_fderiv_at.has_strict_deriv_at (has_fpower_series_at.has_strict_fderiv_at h)\n\ntheorem has_fpower_series_at.has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {p : formal_multilinear_series 𝕜 𝕜 F} (h : has_fpower_series_at f p x) : has_deriv_at f (coe_fn (p 1) fun (_x : fin 1) => 1) x :=\n  has_strict_deriv_at.has_deriv_at (has_fpower_series_at.has_strict_deriv_at h)\n\ntheorem has_fpower_series_at.deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {p : formal_multilinear_series 𝕜 𝕜 F} (h : has_fpower_series_at f p x) : deriv f x = coe_fn (p 1) fun (_x : fin 1) => 1 :=\n  has_deriv_at.deriv (has_fpower_series_at.has_deriv_at h)\n\n/-! ### Derivative of the sum of two functions -/\n\ntheorem has_deriv_at_filter.add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} {L : filter 𝕜} (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) : has_deriv_at_filter (fun (y : 𝕜) => f y + g y) (f' + g') x L := sorry\n\ntheorem has_strict_deriv_at.add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) : has_strict_deriv_at (fun (y : 𝕜) => f y + g y) (f' + g') x := sorry\n\ntheorem has_deriv_within_at.add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} {s : set 𝕜} (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (fun (y : 𝕜) => f y + g y) (f' + g') s x :=\n  has_deriv_at_filter.add hf hg\n\ntheorem has_deriv_at.add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) : has_deriv_at (fun (x : 𝕜) => f x + g x) (f' + g') x :=\n  has_deriv_at_filter.add hf hg\n\ntheorem deriv_within_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : deriv_within (fun (y : 𝕜) => f y + g y) s x = deriv_within f s x + deriv_within g s x := sorry\n\n@[simp] theorem deriv_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {x : 𝕜} (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : deriv (fun (y : 𝕜) => f y + g y) x = deriv f x + deriv g x :=\n  has_deriv_at.deriv (has_deriv_at.add (differentiable_at.has_deriv_at hf) (differentiable_at.has_deriv_at hg))\n\ntheorem has_deriv_at_filter.add_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (hf : has_deriv_at_filter f f' x L) (c : F) : has_deriv_at_filter (fun (y : 𝕜) => f y + c) f' x L :=\n  add_zero f' ▸ has_deriv_at_filter.add hf (has_deriv_at_filter_const x L c)\n\ntheorem has_deriv_within_at.add_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (hf : has_deriv_within_at f f' s x) (c : F) : has_deriv_within_at (fun (y : 𝕜) => f y + c) f' s x :=\n  has_deriv_at_filter.add_const hf c\n\ntheorem has_deriv_at.add_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (hf : has_deriv_at f f' x) (c : F) : has_deriv_at (fun (x : 𝕜) => f x + c) f' x :=\n  has_deriv_at_filter.add_const hf c\n\ntheorem deriv_within_add_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (c : F) : deriv_within (fun (y : 𝕜) => f y + c) s x = deriv_within f s x := sorry\n\ntheorem deriv_add_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (c : F) : deriv (fun (y : 𝕜) => f y + c) x = deriv f x := sorry\n\ntheorem has_deriv_at_filter.const_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (c : F) (hf : has_deriv_at_filter f f' x L) : has_deriv_at_filter (fun (y : 𝕜) => c + f y) f' x L :=\n  zero_add f' ▸ has_deriv_at_filter.add (has_deriv_at_filter_const x L c) hf\n\ntheorem has_deriv_within_at.const_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (c : F) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (y : 𝕜) => c + f y) f' s x :=\n  has_deriv_at_filter.const_add c hf\n\ntheorem has_deriv_at.const_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (c : F) (hf : has_deriv_at f f' x) : has_deriv_at (fun (x : 𝕜) => c + f x) f' x :=\n  has_deriv_at_filter.const_add c hf\n\ntheorem deriv_within_const_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (c : F) : deriv_within (fun (y : 𝕜) => c + f y) s x = deriv_within f s x := sorry\n\ntheorem deriv_const_add {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (c : F) : deriv (fun (y : 𝕜) => c + f y) x = deriv f x := sorry\n\n/-! ### Derivative of a finite sum of functions -/\n\ntheorem has_deriv_at_filter.sum {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {L : filter 𝕜} {ι : Type u_1} {u : finset ι} {A : ι → 𝕜 → F} {A' : ι → F} (h : ∀ (i : ι), i ∈ u → has_deriv_at_filter (A i) (A' i) x L) : has_deriv_at_filter (fun (y : 𝕜) => finset.sum u fun (i : ι) => A i y) (finset.sum u fun (i : ι) => A' i) x L := sorry\n\ntheorem has_strict_deriv_at.sum {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {ι : Type u_1} {u : finset ι} {A : ι → 𝕜 → F} {A' : ι → F} (h : ∀ (i : ι), i ∈ u → has_strict_deriv_at (A i) (A' i) x) : has_strict_deriv_at (fun (y : 𝕜) => finset.sum u fun (i : ι) => A i y) (finset.sum u fun (i : ι) => A' i) x := sorry\n\ntheorem has_deriv_within_at.sum {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} {ι : Type u_1} {u : finset ι} {A : ι → 𝕜 → F} {A' : ι → F} (h : ∀ (i : ι), i ∈ u → has_deriv_within_at (A i) (A' i) s x) : has_deriv_within_at (fun (y : 𝕜) => finset.sum u fun (i : ι) => A i y) (finset.sum u fun (i : ι) => A' i) s x :=\n  has_deriv_at_filter.sum h\n\ntheorem has_deriv_at.sum {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {ι : Type u_1} {u : finset ι} {A : ι → 𝕜 → F} {A' : ι → F} (h : ∀ (i : ι), i ∈ u → has_deriv_at (A i) (A' i) x) : has_deriv_at (fun (y : 𝕜) => finset.sum u fun (i : ι) => A i y) (finset.sum u fun (i : ι) => A' i) x :=\n  has_deriv_at_filter.sum h\n\ntheorem deriv_within_sum {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} {ι : Type u_1} {u : finset ι} {A : ι → 𝕜 → F} (hxs : unique_diff_within_at 𝕜 s x) (h : ∀ (i : ι), i ∈ u → differentiable_within_at 𝕜 (A i) s x) : deriv_within (fun (y : 𝕜) => finset.sum u fun (i : ι) => A i y) s x = finset.sum u fun (i : ι) => deriv_within (A i) s x :=\n  has_deriv_within_at.deriv_within\n    (has_deriv_within_at.sum fun (i : ι) (hi : i ∈ u) => differentiable_within_at.has_deriv_within_at (h i hi)) hxs\n\n@[simp] theorem deriv_sum {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {ι : Type u_1} {u : finset ι} {A : ι → 𝕜 → F} (h : ∀ (i : ι), i ∈ u → differentiable_at 𝕜 (A i) x) : deriv (fun (y : 𝕜) => finset.sum u fun (i : ι) => A i y) x = finset.sum u fun (i : ι) => deriv (A i) x :=\n  has_deriv_at.deriv (has_deriv_at.sum fun (i : ι) (hi : i ∈ u) => differentiable_at.has_deriv_at (h i hi))\n\n/-! ### Derivative of the multiplication of a scalar function and a vector function -/\n\ntheorem has_deriv_within_at.smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (y : 𝕜) => c y • f y) (c x • f' + c' • f x) s x := sorry\n\ntheorem has_deriv_at.smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) : has_deriv_at (fun (y : 𝕜) => c y • f y) (c x • f' + c' • f x) x := sorry\n\ntheorem has_strict_deriv_at.smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) : has_strict_deriv_at (fun (y : 𝕜) => c y • f y) (c x • f' + c' • f x) x := sorry\n\ntheorem deriv_within_smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : deriv_within (fun (y : 𝕜) => c y • f y) s x = c x • deriv_within f s x + deriv_within c s x • f x := sorry\n\ntheorem deriv_smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : deriv (fun (y : 𝕜) => c y • f y) x = c x • deriv f x + deriv c x • f x :=\n  has_deriv_at.deriv (has_deriv_at.smul (differentiable_at.has_deriv_at hc) (differentiable_at.has_deriv_at hf))\n\ntheorem has_deriv_within_at.smul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_within_at c c' s x) (f : F) : has_deriv_within_at (fun (y : 𝕜) => c y • f) (c' • f) s x := sorry\n\ntheorem has_deriv_at.smul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_at c c' x) (f : F) : has_deriv_at (fun (y : 𝕜) => c y • f) (c' • f) x := sorry\n\ntheorem deriv_within_smul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (f : F) : deriv_within (fun (y : 𝕜) => c y • f) s x = deriv_within c s x • f :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.smul_const (differentiable_within_at.has_deriv_within_at hc) f)\n    hxs\n\ntheorem deriv_smul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (f : F) : deriv (fun (y : 𝕜) => c y • f) x = deriv c x • f :=\n  has_deriv_at.deriv (has_deriv_at.smul_const (differentiable_at.has_deriv_at hc) f)\n\ntheorem has_deriv_within_at.const_smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (c : 𝕜) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (y : 𝕜) => c • f y) (c • f') s x := sorry\n\ntheorem has_deriv_at.const_smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (c : 𝕜) (hf : has_deriv_at f f' x) : has_deriv_at (fun (y : 𝕜) => c • f y) (c • f') x := sorry\n\ntheorem deriv_within_const_smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (c : 𝕜) (hf : differentiable_within_at 𝕜 f s x) : deriv_within (fun (y : 𝕜) => c • f y) s x = c • deriv_within f s x :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.const_smul c (differentiable_within_at.has_deriv_within_at hf))\n    hxs\n\ntheorem deriv_const_smul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (c : 𝕜) (hf : differentiable_at 𝕜 f x) : deriv (fun (y : 𝕜) => c • f y) x = c • deriv f x :=\n  has_deriv_at.deriv (has_deriv_at.const_smul c (differentiable_at.has_deriv_at hf))\n\n/-! ### Derivative of the negative of a function -/\n\ntheorem has_deriv_at_filter.neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (h : has_deriv_at_filter f f' x L) : has_deriv_at_filter (fun (x : 𝕜) => -f x) (-f') x L := sorry\n\ntheorem has_deriv_within_at.neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (x : 𝕜) => -f x) (-f') s x :=\n  has_deriv_at_filter.neg h\n\ntheorem has_deriv_at.neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_deriv_at f f' x) : has_deriv_at (fun (x : 𝕜) => -f x) (-f') x :=\n  has_deriv_at_filter.neg h\n\ntheorem has_strict_deriv_at.neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_strict_deriv_at f f' x) : has_strict_deriv_at (fun (x : 𝕜) => -f x) (-f') x := sorry\n\ntheorem deriv_within.neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (y : 𝕜) => -f y) s x = -deriv_within f s x := sorry\n\ntheorem deriv.neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} : deriv (fun (y : 𝕜) => -f y) x = -deriv f x := sorry\n\n@[simp] theorem deriv.neg' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} : (deriv fun (y : 𝕜) => -f y) = fun (x : 𝕜) => -deriv f x :=\n  funext fun (x : 𝕜) => deriv.neg\n\n/-! ### Derivative of the negation function (i.e `has_neg.neg`) -/\n\ntheorem has_deriv_at_filter_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) (L : filter 𝕜) : has_deriv_at_filter Neg.neg (-1) x L :=\n  has_deriv_at_filter.neg (has_deriv_at_filter_id x L)\n\ntheorem has_deriv_within_at_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) (s : set 𝕜) : has_deriv_within_at Neg.neg (-1) s x :=\n  has_deriv_at_filter_neg x (nhds_within x s)\n\ntheorem has_deriv_at_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : has_deriv_at Neg.neg (-1) x :=\n  has_deriv_at_filter_neg x (nhds x)\n\ntheorem has_deriv_at_neg' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : has_deriv_at (fun (x : 𝕜) => -x) (-1) x :=\n  has_deriv_at_filter_neg x (nhds x)\n\ntheorem has_strict_deriv_at_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : has_strict_deriv_at Neg.neg (-1) x :=\n  has_strict_deriv_at.neg (has_strict_deriv_at_id x)\n\ntheorem deriv_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : deriv Neg.neg x = -1 :=\n  has_deriv_at.deriv (has_deriv_at_neg x)\n\n@[simp] theorem deriv_neg' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] : deriv Neg.neg = fun (_x : 𝕜) => -1 :=\n  funext deriv_neg\n\n@[simp] theorem deriv_neg'' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) : deriv (fun (x : 𝕜) => -x) x = -1 :=\n  deriv_neg x\n\ntheorem deriv_within_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) (s : set 𝕜) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within Neg.neg s x = -1 :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at_neg x s) hxs\n\ntheorem differentiable_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] : differentiable 𝕜 Neg.neg :=\n  differentiable.neg differentiable_id\n\ntheorem differentiable_on_neg {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (s : set 𝕜) : differentiable_on 𝕜 Neg.neg s :=\n  differentiable_on.neg differentiable_on_id\n\n/-! ### Derivative of the difference of two functions -/\n\ntheorem has_deriv_at_filter.sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} {L : filter 𝕜} (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) : has_deriv_at_filter (fun (x : 𝕜) => f x - g x) (f' - g') x L := sorry\n\ntheorem has_deriv_within_at.sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} {s : set 𝕜} (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (fun (x : 𝕜) => f x - g x) (f' - g') s x :=\n  has_deriv_at_filter.sub hf hg\n\ntheorem has_deriv_at.sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) : has_deriv_at (fun (x : 𝕜) => f x - g x) (f' - g') x :=\n  has_deriv_at_filter.sub hf hg\n\ntheorem has_strict_deriv_at.sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {f' : F} {g' : F} {x : 𝕜} (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) : has_strict_deriv_at (fun (x : 𝕜) => f x - g x) (f' - g') x := sorry\n\ntheorem deriv_within_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : deriv_within (fun (y : 𝕜) => f y - g y) s x = deriv_within f s x - deriv_within g s x := sorry\n\n@[simp] theorem deriv_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {g : 𝕜 → F} {x : 𝕜} (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : deriv (fun (y : 𝕜) => f y - g y) x = deriv f x - deriv g x :=\n  has_deriv_at.deriv (has_deriv_at.sub (differentiable_at.has_deriv_at hf) (differentiable_at.has_deriv_at hg))\n\ntheorem has_deriv_at_filter.is_O_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (h : has_deriv_at_filter f f' x L) : asymptotics.is_O (fun (x' : 𝕜) => f x' - f x) (fun (x' : 𝕜) => x' - x) L :=\n  has_fderiv_at_filter.is_O_sub h\n\ntheorem has_deriv_at_filter.sub_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (hf : has_deriv_at_filter f f' x L) (c : F) : has_deriv_at_filter (fun (x : 𝕜) => f x - c) f' x L := sorry\n\ntheorem has_deriv_within_at.sub_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (hf : has_deriv_within_at f f' s x) (c : F) : has_deriv_within_at (fun (x : 𝕜) => f x - c) f' s x :=\n  has_deriv_at_filter.sub_const hf c\n\ntheorem has_deriv_at.sub_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (hf : has_deriv_at f f' x) (c : F) : has_deriv_at (fun (x : 𝕜) => f x - c) f' x :=\n  has_deriv_at_filter.sub_const hf c\n\ntheorem deriv_within_sub_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (c : F) : deriv_within (fun (y : 𝕜) => f y - c) s x = deriv_within f s x := sorry\n\ntheorem deriv_sub_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (c : F) : deriv (fun (y : 𝕜) => f y - c) x = deriv f x := sorry\n\ntheorem has_deriv_at_filter.const_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (c : F) (hf : has_deriv_at_filter f f' x L) : has_deriv_at_filter (fun (x : 𝕜) => c - f x) (-f') x L := sorry\n\ntheorem has_deriv_within_at.const_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (c : F) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (fun (x : 𝕜) => c - f x) (-f') s x :=\n  has_deriv_at_filter.const_sub c hf\n\ntheorem has_deriv_at.const_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (c : F) (hf : has_deriv_at f f' x) : has_deriv_at (fun (x : 𝕜) => c - f x) (-f') x :=\n  has_deriv_at_filter.const_sub c hf\n\ntheorem deriv_within_const_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} {s : set 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (c : F) : deriv_within (fun (y : 𝕜) => c - f y) s x = -deriv_within f s x := sorry\n\ntheorem deriv_const_sub {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {x : 𝕜} (c : F) : deriv (fun (y : 𝕜) => c - f y) x = -deriv f x := sorry\n\n/-! ### Continuity of a function admitting a derivative -/\n\ntheorem has_deriv_at_filter.tendsto_nhds {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {L : filter 𝕜} (hL : L ≤ nhds x) (h : has_deriv_at_filter f f' x L) : filter.tendsto f L (nhds (f x)) :=\n  has_fderiv_at_filter.tendsto_nhds hL h\n\ntheorem has_deriv_within_at.continuous_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} {s : set 𝕜} (h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=\n  has_deriv_at_filter.tendsto_nhds inf_le_left h\n\ntheorem has_deriv_at.continuous_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_deriv_at f f' x) : continuous_at f x :=\n  has_deriv_at_filter.tendsto_nhds (le_refl (nhds x)) h\n\n/-! ### Derivative of the cartesian product of two functions -/\n\ntheorem has_deriv_at_filter.prod {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f₁ : 𝕜 → F} {f₁' : F} {x : 𝕜} {L : filter 𝕜} {G : Type w} [normed_group G] [normed_space 𝕜 G] {f₂ : 𝕜 → G} {f₂' : G} (hf₁ : has_deriv_at_filter f₁ f₁' x L) (hf₂ : has_deriv_at_filter f₂ f₂' x L) : has_deriv_at_filter (fun (x : 𝕜) => (f₁ x, f₂ x)) (f₁', f₂') x L := sorry\n\ntheorem has_deriv_within_at.prod {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f₁ : 𝕜 → F} {f₁' : F} {x : 𝕜} {s : set 𝕜} {G : Type w} [normed_group G] [normed_space 𝕜 G] {f₂ : 𝕜 → G} {f₂' : G} (hf₁ : has_deriv_within_at f₁ f₁' s x) (hf₂ : has_deriv_within_at f₂ f₂' s x) : has_deriv_within_at (fun (x : 𝕜) => (f₁ x, f₂ x)) (f₁', f₂') s x :=\n  has_deriv_at_filter.prod hf₁ hf₂\n\ntheorem has_deriv_at.prod {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f₁ : 𝕜 → F} {f₁' : F} {x : 𝕜} {G : Type w} [normed_group G] [normed_space 𝕜 G] {f₂ : 𝕜 → G} {f₂' : G} (hf₁ : has_deriv_at f₁ f₁' x) (hf₂ : has_deriv_at f₂ f₂' x) : has_deriv_at (fun (x : 𝕜) => (f₁ x, f₂ x)) (f₁', f₂') x :=\n  has_deriv_at_filter.prod hf₁ hf₂\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/- 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 -/\n\ntheorem has_deriv_at_filter.scomp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} {g' : F} (x : 𝕜) {L : filter 𝕜} {h : 𝕜 → 𝕜} {h' : 𝕜} (hg : has_deriv_at_filter g g' (h x) (filter.map h L)) (hh : has_deriv_at_filter h h' x L) : has_deriv_at_filter (g ∘ h) (h' • g') x L := sorry\n\ntheorem has_deriv_within_at.scomp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} {g' : F} (x : 𝕜) {s : set 𝕜} {h : 𝕜 → 𝕜} {h' : 𝕜} {t : set 𝕜} (hg : has_deriv_within_at g g' t (h x)) (hh : has_deriv_within_at h h' s x) (hst : s ⊆ h ⁻¹' t) : has_deriv_within_at (g ∘ h) (h' • g') s x := sorry\n\n/-- The chain rule. -/\ntheorem has_deriv_at.scomp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} {g' : F} (x : 𝕜) {h : 𝕜 → 𝕜} {h' : 𝕜} (hg : has_deriv_at g g' (h x)) (hh : has_deriv_at h h' x) : has_deriv_at (g ∘ h) (h' • g') x :=\n  has_deriv_at_filter.scomp x (has_deriv_at_filter.mono hg (has_deriv_at.continuous_at hh)) hh\n\ntheorem has_strict_deriv_at.scomp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} {g' : F} (x : 𝕜) {h : 𝕜 → 𝕜} {h' : 𝕜} (hg : has_strict_deriv_at g g' (h x)) (hh : has_strict_deriv_at h h' x) : has_strict_deriv_at (g ∘ h) (h' • g') x := sorry\n\ntheorem has_deriv_at.scomp_has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} {g' : F} (x : 𝕜) {s : set 𝕜} {h : 𝕜 → 𝕜} {h' : 𝕜} (hg : has_deriv_at g g' (h x)) (hh : has_deriv_within_at h h' s x) : has_deriv_within_at (g ∘ h) (h' • g') s x :=\n  has_deriv_within_at.scomp x\n    (eq.mp (Eq._oldrec (Eq.refl (has_deriv_at g g' (h x))) (Eq.symm (propext has_deriv_within_at_univ))) hg) hh\n    set.subset_preimage_univ\n\ntheorem deriv_within.scomp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} (x : 𝕜) {s : set 𝕜} {t : set 𝕜} {h : 𝕜 → 𝕜} (hg : differentiable_within_at 𝕜 g t (h x)) (hh : differentiable_within_at 𝕜 h s x) (hs : s ⊆ h ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (g ∘ h) s x = deriv_within h s x • deriv_within g t (h x) := sorry\n\ntheorem deriv.scomp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {g : 𝕜 → F} (x : 𝕜) {h : 𝕜 → 𝕜} (hg : differentiable_at 𝕜 g (h x)) (hh : differentiable_at 𝕜 h x) : deriv (g ∘ h) x = deriv h x • deriv g (h x) :=\n  has_deriv_at.deriv (has_deriv_at.scomp x (differentiable_at.has_deriv_at hg) (differentiable_at.has_deriv_at hh))\n\n/-! ### Derivative of the composition of a scalar and vector functions -/\n\ntheorem has_deriv_at_filter.comp_has_fderiv_at_filter {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {E : Type w} [normed_group E] [normed_space 𝕜 E] {h₁ : 𝕜 → 𝕜} {h₁' : 𝕜} {f : E → 𝕜} {f' : continuous_linear_map 𝕜 E 𝕜} (x : E) {L : filter E} (hh₁ : has_deriv_at_filter h₁ h₁' (f x) (filter.map f L)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (h₁ ∘ f) (h₁' • f') x L := sorry\n\ntheorem has_deriv_at.comp_has_fderiv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {E : Type w} [normed_group E] [normed_space 𝕜 E] {h₁ : 𝕜 → 𝕜} {h₁' : 𝕜} {f : E → 𝕜} {f' : continuous_linear_map 𝕜 E 𝕜} (x : E) (hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_at f f' x) : has_fderiv_at (h₁ ∘ f) (h₁' • f') x :=\n  has_deriv_at_filter.comp_has_fderiv_at_filter x (has_deriv_at_filter.mono hh₁ (has_fderiv_at.continuous_at hf)) hf\n\ntheorem has_deriv_at.comp_has_fderiv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {E : Type w} [normed_group E] [normed_space 𝕜 E] {h₁ : 𝕜 → 𝕜} {h₁' : 𝕜} {f : E → 𝕜} {f' : continuous_linear_map 𝕜 E 𝕜} {s : set E} (x : E) (hh₁ : has_deriv_at h₁ h₁' (f x)) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x :=\n  has_deriv_at_filter.comp_has_fderiv_at_filter x\n    (has_deriv_at_filter.mono hh₁ (has_fderiv_within_at.continuous_within_at hf)) hf\n\ntheorem has_deriv_within_at.comp_has_fderiv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {E : Type w} [normed_group E] [normed_space 𝕜 E] {h₁ : 𝕜 → 𝕜} {h₁' : 𝕜} {f : E → 𝕜} {f' : continuous_linear_map 𝕜 E 𝕜} {s : set E} {t : set 𝕜} (x : E) (hh₁ : has_deriv_within_at h₁ h₁' t (f x)) (hf : has_fderiv_within_at f f' s x) (hst : set.maps_to f s t) : has_fderiv_within_at (h₁ ∘ f) (h₁' • f') s x := sorry\n\n/-! ### Derivative of the composition of two scalar functions -/\n\ntheorem has_deriv_at_filter.comp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {L : filter 𝕜} {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} {h₁' : 𝕜} {h₂' : 𝕜} (hh₁ : has_deriv_at_filter h₁ h₁' (h₂ x) (filter.map h₂ L)) (hh₂ : has_deriv_at_filter h₂ h₂' x L) : has_deriv_at_filter (h₁ ∘ h₂) (h₁' * h₂') x L :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (has_deriv_at_filter (h₁ ∘ h₂) (h₁' * h₂') x L)) (mul_comm h₁' h₂')))\n    (has_deriv_at_filter.scomp x hh₁ hh₂)\n\ntheorem has_deriv_within_at.comp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {s : set 𝕜} {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} {h₁' : 𝕜} {h₂' : 𝕜} {t : set 𝕜} (hh₁ : has_deriv_within_at h₁ h₁' t (h₂ x)) (hh₂ : has_deriv_within_at h₂ h₂' s x) (hst : s ⊆ h₂ ⁻¹' t) : has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x)) (mul_comm h₁' h₂')))\n    (has_deriv_within_at.scomp x hh₁ hh₂ hst)\n\n/-- The chain rule. -/\ntheorem has_deriv_at.comp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} {h₁' : 𝕜} {h₂' : 𝕜} (hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_at h₂ h₂' x) : has_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=\n  has_deriv_at_filter.comp x (has_deriv_at_filter.mono hh₁ (has_deriv_at.continuous_at hh₂)) hh₂\n\ntheorem has_strict_deriv_at.comp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} {h₁' : 𝕜} {h₂' : 𝕜} (hh₁ : has_strict_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_strict_deriv_at h₂ h₂' x) : has_strict_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (has_strict_deriv_at (h₁ ∘ h₂) (h₁' * h₂') x)) (mul_comm h₁' h₂')))\n    (has_strict_deriv_at.scomp x hh₁ hh₂)\n\ntheorem has_deriv_at.comp_has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {s : set 𝕜} {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} {h₁' : 𝕜} {h₂' : 𝕜} (hh₁ : has_deriv_at h₁ h₁' (h₂ x)) (hh₂ : has_deriv_within_at h₂ h₂' s x) : has_deriv_within_at (h₁ ∘ h₂) (h₁' * h₂') s x :=\n  has_deriv_within_at.comp x\n    (eq.mp (Eq._oldrec (Eq.refl (has_deriv_at h₁ h₁' (h₂ x))) (Eq.symm (propext has_deriv_within_at_univ))) hh₁) hh₂\n    set.subset_preimage_univ\n\ntheorem deriv_within.comp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {s : set 𝕜} {t : set 𝕜} {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} (hh₁ : differentiable_within_at 𝕜 h₁ t (h₂ x)) (hh₂ : differentiable_within_at 𝕜 h₂ s x) (hs : s ⊆ h₂ ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (h₁ ∘ h₂) s x = deriv_within h₁ t (h₂ x) * deriv_within h₂ s x := sorry\n\ntheorem deriv.comp {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜 → 𝕜} (hh₁ : differentiable_at 𝕜 h₁ (h₂ x)) (hh₂ : differentiable_at 𝕜 h₂ x) : deriv (h₁ ∘ h₂) x = deriv h₁ (h₂ x) * deriv h₂ x :=\n  has_deriv_at.deriv (has_deriv_at.comp x (differentiable_at.has_deriv_at hh₁) (differentiable_at.has_deriv_at hh₂))\n\nprotected theorem has_deriv_at_filter.iterate {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {L : filter 𝕜} {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : has_deriv_at_filter f f' x L) (hL : filter.tendsto f L L) (hx : f x = x) (n : ℕ) : has_deriv_at_filter (nat.iterate f n) (f' ^ n) x L := sorry\n\nprotected theorem has_deriv_at.iterate {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : has_deriv_at f f' x) (hx : f x = x) (n : ℕ) : has_deriv_at (nat.iterate f n) (f' ^ n) x := sorry\n\nprotected theorem has_deriv_within_at.iterate {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {s : set 𝕜} {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : set.maps_to f s s) (n : ℕ) : has_deriv_within_at (nat.iterate f n) (f' ^ n) s x := sorry\n\nprotected theorem has_strict_deriv_at.iterate {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (x : 𝕜) {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : ℕ) : has_strict_deriv_at (nat.iterate f n) (f' ^ n) x := sorry\n\n/-! ### Derivative of the composition of a function between vector spaces and of a function defined on `𝕜` -/\n\n/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set\nequal to the Fréchet derivative of `l` applied to the derivative of `f`. -/\ntheorem has_fderiv_within_at.comp_has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {E : Type w} [normed_group E] [normed_space 𝕜 E] {f : 𝕜 → F} {f' : F} (x : 𝕜) {s : set 𝕜} {l : F → E} {l' : continuous_linear_map 𝕜 F E} {t : set F} (hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x) (hst : s ⊆ f ⁻¹' t) : has_deriv_within_at (l ∘ f) (coe_fn l' f') s x := sorry\n\n/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the\nFréchet derivative of `l` applied to the derivative of `f`. -/\ntheorem has_fderiv_at.comp_has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {E : Type w} [normed_group E] [normed_space 𝕜 E] {f : 𝕜 → F} {f' : F} (x : 𝕜) {l : F → E} {l' : continuous_linear_map 𝕜 F E} (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) : has_deriv_at (l ∘ f) (coe_fn l' f') x := sorry\n\ntheorem has_fderiv_at.comp_has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {E : Type w} [normed_group E] [normed_space 𝕜 E] {f : 𝕜 → F} {f' : F} (x : 𝕜) {s : set 𝕜} {l : F → E} {l' : continuous_linear_map 𝕜 F E} (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (l ∘ f) (coe_fn l' f') s x :=\n  has_fderiv_within_at.comp_has_deriv_within_at x\n    (eq.mp (Eq._oldrec (Eq.refl (has_fderiv_at l l' (f x))) (Eq.symm (propext has_fderiv_within_at_univ))) hl) hf\n    set.subset_preimage_univ\n\ntheorem fderiv_within.comp_deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {E : Type w} [normed_group E] [normed_space 𝕜 E] {f : 𝕜 → F} (x : 𝕜) {s : set 𝕜} {l : F → E} {t : set F} (hl : differentiable_within_at 𝕜 l t (f x)) (hf : differentiable_within_at 𝕜 f s x) (hs : s ⊆ f ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (l ∘ f) s x = coe_fn (fderiv_within 𝕜 l t (f x)) (deriv_within f s x) := sorry\n\ntheorem fderiv.comp_deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {E : Type w} [normed_group E] [normed_space 𝕜 E] {f : 𝕜 → F} (x : 𝕜) {l : F → E} (hl : differentiable_at 𝕜 l (f x)) (hf : differentiable_at 𝕜 f x) : deriv (l ∘ f) x = coe_fn (fderiv 𝕜 l (f x)) (deriv f x) :=\n  has_deriv_at.deriv\n    (has_fderiv_at.comp_has_deriv_at x (differentiable_at.has_fderiv_at hl) (differentiable_at.has_deriv_at hf))\n\n/-! ### Derivative of the multiplication of two scalar functions -/\n\ntheorem has_deriv_within_at.mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} {c' : 𝕜} {d' : 𝕜} (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) : has_deriv_within_at (fun (y : 𝕜) => c y * d y) (c' * d x + c x * d') s x := sorry\n\ntheorem has_deriv_at.mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} {c' : 𝕜} {d' : 𝕜} (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) : has_deriv_at (fun (y : 𝕜) => c y * d y) (c' * d x + c x * d') x := sorry\n\ntheorem has_strict_deriv_at.mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} {c' : 𝕜} {d' : 𝕜} (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) : has_strict_deriv_at (fun (y : 𝕜) => c y * d y) (c' * d x + c x * d') x := sorry\n\ntheorem deriv_within_mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : deriv_within (fun (y : 𝕜) => c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x := sorry\n\n@[simp] theorem deriv_mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : deriv (fun (y : 𝕜) => c y * d y) x = deriv c x * d x + c x * deriv d x :=\n  has_deriv_at.deriv (has_deriv_at.mul (differentiable_at.has_deriv_at hc) (differentiable_at.has_deriv_at hd))\n\ntheorem has_deriv_within_at.mul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_within_at c c' s x) (d : 𝕜) : has_deriv_within_at (fun (y : 𝕜) => c y * d) (c' * d) s x := sorry\n\ntheorem has_deriv_at.mul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_at c c' x) (d : 𝕜) : has_deriv_at (fun (y : 𝕜) => c y * d) (c' * d) x := sorry\n\ntheorem deriv_within_mul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (d : 𝕜) : deriv_within (fun (y : 𝕜) => c y * d) s x = deriv_within c s x * d :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.mul_const (differentiable_within_at.has_deriv_within_at hc) d) hxs\n\ntheorem deriv_mul_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (d : 𝕜) : deriv (fun (y : 𝕜) => c y * d) x = deriv c x * d :=\n  has_deriv_at.deriv (has_deriv_at.mul_const (differentiable_at.has_deriv_at hc) d)\n\ntheorem has_deriv_within_at.const_mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {d : 𝕜 → 𝕜} {d' : 𝕜} (c : 𝕜) (hd : has_deriv_within_at d d' s x) : has_deriv_within_at (fun (y : 𝕜) => c * d y) (c * d') s x := sorry\n\ntheorem has_deriv_at.const_mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {d : 𝕜 → 𝕜} {d' : 𝕜} (c : 𝕜) (hd : has_deriv_at d d' x) : has_deriv_at (fun (y : 𝕜) => c * d y) (c * d') x := sorry\n\ntheorem deriv_within_const_mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {d : 𝕜 → 𝕜} (hxs : unique_diff_within_at 𝕜 s x) (c : 𝕜) (hd : differentiable_within_at 𝕜 d s x) : deriv_within (fun (y : 𝕜) => c * d y) s x = c * deriv_within d s x :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.const_mul c (differentiable_within_at.has_deriv_within_at hd)) hxs\n\ntheorem deriv_const_mul {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {d : 𝕜 → 𝕜} (c : 𝕜) (hd : differentiable_at 𝕜 d x) : deriv (fun (y : 𝕜) => c * d y) x = c * deriv d x :=\n  has_deriv_at.deriv (has_deriv_at.const_mul c (differentiable_at.has_deriv_at hd))\n\n/-! ### Derivative of `x ↦ x⁻¹` -/\n\ntheorem has_strict_deriv_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (hx : x ≠ 0) : has_strict_deriv_at has_inv.inv (-(x ^ bit0 1⁻¹)) x := sorry\n\ntheorem has_deriv_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (x_ne_zero : x ≠ 0) : has_deriv_at (fun (y : 𝕜) => y⁻¹) (-(x ^ bit0 1⁻¹)) x :=\n  has_strict_deriv_at.has_deriv_at (has_strict_deriv_at_inv x_ne_zero)\n\ntheorem has_deriv_within_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (x_ne_zero : x ≠ 0) (s : set 𝕜) : has_deriv_within_at (fun (x : 𝕜) => x⁻¹) (-(x ^ bit0 1⁻¹)) s x :=\n  has_deriv_at.has_deriv_within_at (has_deriv_at_inv x_ne_zero)\n\ntheorem differentiable_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (x_ne_zero : x ≠ 0) : differentiable_at 𝕜 (fun (x : 𝕜) => x⁻¹) x :=\n  has_deriv_at.differentiable_at (has_deriv_at_inv x_ne_zero)\n\ntheorem differentiable_within_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (x_ne_zero : x ≠ 0) : differentiable_within_at 𝕜 (fun (x : 𝕜) => x⁻¹) s x :=\n  differentiable_at.differentiable_within_at (differentiable_at_inv x_ne_zero)\n\ntheorem differentiable_on_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] : differentiable_on 𝕜 (fun (x : 𝕜) => x⁻¹) (set_of fun (x : 𝕜) => x ≠ 0) :=\n  fun (x : 𝕜) (hx : x ∈ set_of fun (x : 𝕜) => x ≠ 0) => differentiable_within_at_inv hx\n\ntheorem deriv_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (x_ne_zero : x ≠ 0) : deriv (fun (x : 𝕜) => x⁻¹) x = -(x ^ bit0 1⁻¹) :=\n  has_deriv_at.deriv (has_deriv_at_inv x_ne_zero)\n\ntheorem deriv_within_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => x⁻¹) s x = -(x ^ bit0 1⁻¹) := sorry\n\ntheorem has_fderiv_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (x_ne_zero : x ≠ 0) : has_fderiv_at (fun (x : 𝕜) => x⁻¹) (continuous_linear_map.smul_right 1 (-(x ^ bit0 1⁻¹))) x :=\n  has_deriv_at_inv x_ne_zero\n\ntheorem has_fderiv_within_at_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (x_ne_zero : x ≠ 0) : has_fderiv_within_at (fun (x : 𝕜) => x⁻¹) (continuous_linear_map.smul_right 1 (-(x ^ bit0 1⁻¹))) s x :=\n  has_fderiv_at.has_fderiv_within_at (has_fderiv_at_inv x_ne_zero)\n\ntheorem fderiv_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (x_ne_zero : x ≠ 0) : fderiv 𝕜 (fun (x : 𝕜) => x⁻¹) x = continuous_linear_map.smul_right 1 (-(x ^ bit0 1⁻¹)) :=\n  has_fderiv_at.fderiv (has_fderiv_at_inv x_ne_zero)\n\ntheorem fderiv_within_inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (fun (x : 𝕜) => x⁻¹) s x = continuous_linear_map.smul_right 1 (-(x ^ bit0 1⁻¹)) := sorry\n\ntheorem has_deriv_within_at.inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_within_at c c' s x) (hx : c x ≠ 0) : has_deriv_within_at (fun (y : 𝕜) => c y⁻¹) (-c' / c x ^ bit0 1) s x := sorry\n\ntheorem has_deriv_at.inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} (hc : has_deriv_at c c' x) (hx : c x ≠ 0) : has_deriv_at (fun (y : 𝕜) => c y⁻¹) (-c' / c x ^ bit0 1) x := sorry\n\ntheorem differentiable_within_at.inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0) : differentiable_within_at 𝕜 (fun (x : 𝕜) => c x⁻¹) s x :=\n  has_deriv_within_at.differentiable_within_at\n    (has_deriv_within_at.inv (differentiable_within_at.has_deriv_within_at hc) hx)\n\n@[simp] theorem differentiable_at.inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) : differentiable_at 𝕜 (fun (x : 𝕜) => c x⁻¹) x :=\n  has_deriv_at.differentiable_at (has_deriv_at.inv (differentiable_at.has_deriv_at hc) hx)\n\ntheorem differentiable_on.inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_on 𝕜 c s) (hx : ∀ (x : 𝕜), x ∈ s → c x ≠ 0) : differentiable_on 𝕜 (fun (x : 𝕜) => c x⁻¹) s :=\n  fun (x : 𝕜) (h : x ∈ s) => differentiable_within_at.inv (hc x h) (hx x h)\n\n@[simp] theorem differentiable.inv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {c : 𝕜 → 𝕜} (hc : differentiable 𝕜 c) (hx : ∀ (x : 𝕜), c x ≠ 0) : differentiable 𝕜 fun (x : 𝕜) => c x⁻¹ :=\n  fun (x : 𝕜) => differentiable_at.inv (hc x) (hx x)\n\ntheorem deriv_within_inv' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_within_at 𝕜 c s x) (hx : c x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => c x⁻¹) s x = -deriv_within c s x / c x ^ bit0 1 :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.inv (differentiable_within_at.has_deriv_within_at hc) hx) hxs\n\n@[simp] theorem deriv_inv' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (hx : c x ≠ 0) : deriv (fun (x : 𝕜) => c x⁻¹) x = -deriv c x / c x ^ bit0 1 :=\n  has_deriv_at.deriv (has_deriv_at.inv (differentiable_at.has_deriv_at hc) hx)\n\n/-! ### Derivative of `x ↦ c x / d x` -/\n\ntheorem has_deriv_within_at.div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} {c' : 𝕜} {d' : 𝕜} (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x ≠ 0) : has_deriv_within_at (fun (y : 𝕜) => c y / d y) ((c' * d x - c x * d') / d x ^ bit0 1) s x := sorry\n\ntheorem has_deriv_at.div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} {c' : 𝕜} {d' : 𝕜} (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x ≠ 0) : has_deriv_at (fun (y : 𝕜) => c y / d y) ((c' * d x - c x * d') / d x ^ bit0 1) x := sorry\n\ntheorem differentiable_within_at.div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0) : differentiable_within_at 𝕜 (fun (x : 𝕜) => c x / d x) s x :=\n  has_deriv_within_at.differentiable_within_at\n    (has_deriv_within_at.div (differentiable_within_at.has_deriv_within_at hc)\n      (differentiable_within_at.has_deriv_within_at hd) hx)\n\n@[simp] theorem differentiable_at.div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) : differentiable_at 𝕜 (fun (x : 𝕜) => c x / d x) x :=\n  has_deriv_at.differentiable_at\n    (has_deriv_at.div (differentiable_at.has_deriv_at hc) (differentiable_at.has_deriv_at hd) hx)\n\ntheorem differentiable_on.div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) (hx : ∀ (x : 𝕜), x ∈ s → d x ≠ 0) : differentiable_on 𝕜 (fun (x : 𝕜) => c x / d x) s :=\n  fun (x : 𝕜) (h : x ∈ s) => differentiable_within_at.div (hc x h) (hd x h) (hx x h)\n\n@[simp] theorem differentiable.div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) (hx : ∀ (x : 𝕜), d x ≠ 0) : differentiable 𝕜 fun (x : 𝕜) => c x / d x :=\n  fun (x : 𝕜) => differentiable_at.div (hc x) (hd x) (hx x)\n\ntheorem deriv_within_div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => c x / d x) s x = (deriv_within c s x * d x - c x * deriv_within d s x) / d x ^ bit0 1 := sorry\n\n@[simp] theorem deriv_div {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {d : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) : deriv (fun (x : 𝕜) => c x / d x) x = (deriv c x * d x - c x * deriv d x) / d x ^ bit0 1 :=\n  has_deriv_at.deriv (has_deriv_at.div (differentiable_at.has_deriv_at hc) (differentiable_at.has_deriv_at hd) hx)\n\ntheorem differentiable_within_at.div_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜} : differentiable_within_at 𝕜 (fun (x : 𝕜) => c x / d) s x := sorry\n\n@[simp] theorem differentiable_at.div_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) {d : 𝕜} : differentiable_at 𝕜 (fun (x : 𝕜) => c x / d) x :=\n  has_deriv_at.differentiable_at (has_deriv_at.mul_const (differentiable_at.has_deriv_at hc) (d⁻¹))\n\ntheorem differentiable_on.div_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_on 𝕜 c s) {d : 𝕜} : differentiable_on 𝕜 (fun (x : 𝕜) => c x / d) s := sorry\n\n@[simp] theorem differentiable.div_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {c : 𝕜 → 𝕜} (hc : differentiable 𝕜 c) {d : 𝕜} : differentiable 𝕜 fun (x : 𝕜) => c x / d := sorry\n\ntheorem deriv_within_div_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_within_at 𝕜 c s x) {d : 𝕜} (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => c x / d) s x = deriv_within c s x / d := sorry\n\n@[simp] theorem deriv_div_const {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} (hc : differentiable_at 𝕜 c x) {d : 𝕜} : deriv (fun (x : 𝕜) => c x / d) x = deriv c x / d := sorry\n\ntheorem has_strict_deriv_at.has_strict_fderiv_at_equiv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {f : 𝕜 → 𝕜} {f' : 𝕜} {x : 𝕜} (hf : has_strict_deriv_at f f' x) (hf' : f' ≠ 0) : has_strict_fderiv_at f (↑(coe_fn (continuous_linear_equiv.units_equiv_aut 𝕜) (units.mk0 f' hf'))) x :=\n  hf\n\ntheorem has_deriv_at.has_fderiv_at_equiv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {f : 𝕜 → 𝕜} {f' : 𝕜} {x : 𝕜} (hf : has_deriv_at f f' x) (hf' : f' ≠ 0) : has_fderiv_at f (↑(coe_fn (continuous_linear_equiv.units_equiv_aut 𝕜) (units.mk0 f' hf'))) x :=\n  hf\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'⁻¹` 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 {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {f : 𝕜 → 𝕜} {g : 𝕜 → 𝕜} {f' : 𝕜} {a : 𝕜} (hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' ≠ 0) (hfg : filter.eventually (fun (y : 𝕜) => f (g y) = y) (nhds a)) : has_strict_deriv_at g (f'⁻¹) a :=\n  has_strict_fderiv_at.of_local_left_inverse hg (has_strict_deriv_at.has_strict_fderiv_at_equiv hf hf') hfg\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'⁻¹` 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 {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {f : 𝕜 → 𝕜} {g : 𝕜 → 𝕜} {f' : 𝕜} {a : 𝕜} (hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' ≠ 0) (hfg : filter.eventually (fun (y : 𝕜) => f (g y) = y) (nhds a)) : has_deriv_at g (f'⁻¹) a :=\n  has_fderiv_at.of_local_left_inverse hg (has_deriv_at.has_fderiv_at_equiv hf hf') 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'⁻¹` 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 local_homeomorph.has_deriv_at_symm {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (f : local_homeomorph 𝕜 𝕜) {a : 𝕜} {f' : 𝕜} (ha : a ∈ local_equiv.target (local_homeomorph.to_local_equiv f)) (hf' : f' ≠ 0) (htff' : has_deriv_at (⇑f) f' (coe_fn (local_homeomorph.symm f) a)) : has_deriv_at (⇑(local_homeomorph.symm f)) (f'⁻¹) a :=\n  has_deriv_at.of_local_left_inverse (local_homeomorph.continuous_at (local_homeomorph.symm f) ha) htff' hf'\n    (local_homeomorph.eventually_right_inverse f ha)\n\ntheorem has_deriv_at.eventually_ne {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {F : Type v} [normed_group F] [normed_space 𝕜 F] {f : 𝕜 → F} {f' : F} {x : 𝕜} (h : has_deriv_at f f' x) (hf' : f' ≠ 0) : filter.eventually (fun (z : 𝕜) => f z ≠ f x) (nhds_within x (singleton xᶜ)) := sorry\n\ntheorem not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {f : 𝕜 → 𝕜} {g : 𝕜 → 𝕜} {a : 𝕜} {s : set 𝕜} {t : set 𝕜} (ha : a ∈ s) (hsu : unique_diff_within_at 𝕜 s a) (hf : has_deriv_within_at f 0 t (g a)) (hst : set.maps_to g s t) (hfg : filter.eventually_eq (nhds_within a s) (f ∘ g) id) : ¬differentiable_within_at 𝕜 g s a := sorry\n\ntheorem not_differentiable_at_of_local_left_inverse_has_deriv_at_zero {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {f : 𝕜 → 𝕜} {g : 𝕜 → 𝕜} {a : 𝕜} (hf : has_deriv_at f 0 (g a)) (hfg : filter.eventually_eq (nhds a) (f ∘ g) id) : ¬differentiable_at 𝕜 g a := sorry\n\nnamespace polynomial\n\n\n/-! ### Derivative of a polynomial -/\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected theorem has_strict_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (p : polynomial 𝕜) (x : 𝕜) : has_strict_deriv_at (fun (x : 𝕜) => eval x p) (eval x (coe_fn derivative p)) x := sorry\n\n/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/\nprotected theorem has_deriv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (p : polynomial 𝕜) (x : 𝕜) : has_deriv_at (fun (x : 𝕜) => eval x p) (eval x (coe_fn derivative p)) x :=\n  has_strict_deriv_at.has_deriv_at (polynomial.has_strict_deriv_at p x)\n\nprotected theorem has_deriv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (p : polynomial 𝕜) (x : 𝕜) (s : set 𝕜) : has_deriv_within_at (fun (x : 𝕜) => eval x p) (eval x (coe_fn derivative p)) s x :=\n  has_deriv_at.has_deriv_within_at (polynomial.has_deriv_at p x)\n\nprotected theorem differentiable_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (p : polynomial 𝕜) : differentiable_at 𝕜 (fun (x : 𝕜) => eval x p) x :=\n  has_deriv_at.differentiable_at (polynomial.has_deriv_at p x)\n\nprotected theorem differentiable_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (p : polynomial 𝕜) : differentiable_within_at 𝕜 (fun (x : 𝕜) => eval x p) s x :=\n  differentiable_at.differentiable_within_at (polynomial.differentiable_at p)\n\nprotected theorem differentiable {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (p : polynomial 𝕜) : differentiable 𝕜 fun (x : 𝕜) => eval x p :=\n  fun (x : 𝕜) => polynomial.differentiable_at p\n\nprotected theorem differentiable_on {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} (p : polynomial 𝕜) : differentiable_on 𝕜 (fun (x : 𝕜) => eval x p) s :=\n  differentiable.differentiable_on (polynomial.differentiable p)\n\n@[simp] protected theorem deriv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (p : polynomial 𝕜) : deriv (fun (x : 𝕜) => eval x p) x = eval x (coe_fn derivative p) :=\n  has_deriv_at.deriv (polynomial.has_deriv_at p x)\n\nprotected theorem deriv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (p : polynomial 𝕜) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => eval x p) s x = eval x (coe_fn derivative p) := sorry\n\nprotected theorem has_fderiv_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (p : polynomial 𝕜) (x : 𝕜) : has_fderiv_at (fun (x : 𝕜) => eval x p) (continuous_linear_map.smul_right 1 (eval x (coe_fn derivative p))) x := sorry\n\nprotected theorem has_fderiv_within_at {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} (p : polynomial 𝕜) (x : 𝕜) : has_fderiv_within_at (fun (x : 𝕜) => eval x p) (continuous_linear_map.smul_right 1 (eval x (coe_fn derivative p))) s x :=\n  has_fderiv_at.has_fderiv_within_at (polynomial.has_fderiv_at p x)\n\n@[simp] protected theorem fderiv {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (p : polynomial 𝕜) : fderiv 𝕜 (fun (x : 𝕜) => eval x p) x = continuous_linear_map.smul_right 1 (eval x (coe_fn derivative p)) :=\n  has_fderiv_at.fderiv (polynomial.has_fderiv_at p x)\n\nprotected theorem fderiv_within {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} (p : polynomial 𝕜) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (fun (x : 𝕜) => eval x p) s x = continuous_linear_map.smul_right 1 (eval x (coe_fn derivative p)) := sorry\n\nend polynomial\n\n\n/-! ### Derivative of `x ↦ x^n` for `n : ℕ` -/\n\ntheorem has_strict_deriv_at_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (n : ℕ) (x : 𝕜) : has_strict_deriv_at (fun (x : 𝕜) => x ^ n) (↑n * x ^ (n - 1)) x := sorry\n\ntheorem has_deriv_at_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (n : ℕ) (x : 𝕜) : has_deriv_at (fun (x : 𝕜) => x ^ n) (↑n * x ^ (n - 1)) x :=\n  has_strict_deriv_at.has_deriv_at (has_strict_deriv_at_pow n x)\n\ntheorem has_deriv_within_at_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] (n : ℕ) (x : 𝕜) (s : set 𝕜) : has_deriv_within_at (fun (x : 𝕜) => x ^ n) (↑n * x ^ (n - 1)) s x :=\n  has_deriv_at.has_deriv_within_at (has_deriv_at_pow n x)\n\ntheorem differentiable_at_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {n : ℕ} : differentiable_at 𝕜 (fun (x : 𝕜) => x ^ n) x :=\n  has_deriv_at.differentiable_at (has_deriv_at_pow n x)\n\ntheorem differentiable_within_at_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {n : ℕ} : differentiable_within_at 𝕜 (fun (x : 𝕜) => x ^ n) s x :=\n  differentiable_at.differentiable_within_at differentiable_at_pow\n\ntheorem differentiable_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {n : ℕ} : differentiable 𝕜 fun (x : 𝕜) => x ^ n :=\n  fun (x : 𝕜) => differentiable_at_pow\n\ntheorem differentiable_on_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} {n : ℕ} : differentiable_on 𝕜 (fun (x : 𝕜) => x ^ n) s :=\n  differentiable.differentiable_on differentiable_pow\n\ntheorem deriv_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {n : ℕ} : deriv (fun (x : 𝕜) => x ^ n) x = ↑n * x ^ (n - 1) :=\n  has_deriv_at.deriv (has_deriv_at_pow n x)\n\n@[simp] theorem deriv_pow' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {n : ℕ} : (deriv fun (x : 𝕜) => x ^ n) = fun (x : 𝕜) => ↑n * x ^ (n - 1) :=\n  funext fun (x : 𝕜) => deriv_pow\n\ntheorem deriv_within_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {n : ℕ} (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => x ^ n) s x = ↑n * x ^ (n - 1) :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at_pow n x s) hxs\n\ntheorem iter_deriv_pow' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {n : ℕ} {k : ℕ} : (nat.iterate deriv k fun (x : 𝕜) => x ^ n) =\n  fun (x : 𝕜) => ↑(finset.prod (finset.range k) fun (i : ℕ) => n - i) * x ^ (n - k) := sorry\n\ntheorem iter_deriv_pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {n : ℕ} {k : ℕ} : nat.iterate deriv k (fun (x : 𝕜) => x ^ n) x = ↑(finset.prod (finset.range k) fun (i : ℕ) => n - i) * x ^ (n - k) :=\n  congr_fun iter_deriv_pow' x\n\ntheorem has_deriv_within_at.pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} {n : ℕ} (hc : has_deriv_within_at c c' s x) : has_deriv_within_at (fun (y : 𝕜) => c y ^ n) (↑n * c x ^ (n - 1) * c') s x :=\n  has_deriv_at.comp_has_deriv_within_at x (has_deriv_at_pow n (c x)) hc\n\ntheorem has_deriv_at.pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {c' : 𝕜} {n : ℕ} (hc : has_deriv_at c c' x) : has_deriv_at (fun (y : 𝕜) => c y ^ n) (↑n * c x ^ (n - 1) * c') x := sorry\n\ntheorem differentiable_within_at.pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {n : ℕ} (hc : differentiable_within_at 𝕜 c s x) : differentiable_within_at 𝕜 (fun (x : 𝕜) => c x ^ n) s x :=\n  has_deriv_within_at.differentiable_within_at (has_deriv_within_at.pow (differentiable_within_at.has_deriv_within_at hc))\n\n@[simp] theorem differentiable_at.pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {n : ℕ} (hc : differentiable_at 𝕜 c x) : differentiable_at 𝕜 (fun (x : 𝕜) => c x ^ n) x :=\n  has_deriv_at.differentiable_at (has_deriv_at.pow (differentiable_at.has_deriv_at hc))\n\ntheorem differentiable_on.pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} {c : 𝕜 → 𝕜} {n : ℕ} (hc : differentiable_on 𝕜 c s) : differentiable_on 𝕜 (fun (x : 𝕜) => c x ^ n) s :=\n  fun (x : 𝕜) (h : x ∈ s) => differentiable_within_at.pow (hc x h)\n\n@[simp] theorem differentiable.pow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {c : 𝕜 → 𝕜} {n : ℕ} (hc : differentiable 𝕜 c) : differentiable 𝕜 fun (x : 𝕜) => c x ^ n :=\n  fun (x : 𝕜) => differentiable_at.pow (hc x)\n\ntheorem deriv_within_pow' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {c : 𝕜 → 𝕜} {n : ℕ} (hc : differentiable_within_at 𝕜 c s x) (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (fun (x : 𝕜) => c x ^ n) s x = ↑n * c x ^ (n - 1) * deriv_within c s x :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at.pow (differentiable_within_at.has_deriv_within_at hc)) hxs\n\n@[simp] theorem deriv_pow'' {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {c : 𝕜 → 𝕜} {n : ℕ} (hc : differentiable_at 𝕜 c x) : deriv (fun (x : 𝕜) => c x ^ n) x = ↑n * c x ^ (n - 1) * deriv c x :=\n  has_deriv_at.deriv (has_deriv_at.pow (differentiable_at.has_deriv_at hc))\n\n/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/\n\ntheorem has_strict_deriv_at_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (m : ℤ) (hx : x ≠ 0) : has_strict_deriv_at (fun (x : 𝕜) => x ^ m) (↑m * x ^ (m - 1)) x := sorry\n\ntheorem has_deriv_at_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (m : ℤ) (hx : x ≠ 0) : has_deriv_at (fun (x : 𝕜) => x ^ m) (↑m * x ^ (m - 1)) x :=\n  has_strict_deriv_at.has_deriv_at (has_strict_deriv_at_fpow m hx)\n\ntheorem has_deriv_within_at_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} (m : ℤ) (hx : x ≠ 0) (s : set 𝕜) : has_deriv_within_at (fun (x : 𝕜) => x ^ m) (↑m * x ^ (m - 1)) s x :=\n  has_deriv_at.has_deriv_within_at (has_deriv_at_fpow m hx)\n\ntheorem differentiable_at_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {m : ℤ} (hx : x ≠ 0) : differentiable_at 𝕜 (fun (x : 𝕜) => x ^ m) x :=\n  has_deriv_at.differentiable_at (has_deriv_at_fpow m hx)\n\ntheorem differentiable_within_at_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {m : ℤ} (hx : x ≠ 0) : differentiable_within_at 𝕜 (fun (x : 𝕜) => x ^ m) s x :=\n  differentiable_at.differentiable_within_at (differentiable_at_fpow hx)\n\ntheorem differentiable_on_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {s : set 𝕜} {m : ℤ} (hs : ¬0 ∈ s) : differentiable_on 𝕜 (fun (x : 𝕜) => x ^ m) s :=\n  fun (x : 𝕜) (hxs : x ∈ s) => differentiable_within_at_fpow fun (hx : x = 0) => hs (hx ▸ hxs)\n\n-- TODO : this is true at `x=0` as well\n\ntheorem deriv_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {m : ℤ} (hx : x ≠ 0) : deriv (fun (x : 𝕜) => x ^ m) x = ↑m * x ^ (m - 1) :=\n  has_deriv_at.deriv (has_deriv_at_fpow m hx)\n\ntheorem deriv_within_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {s : set 𝕜} {m : ℤ} (hxs : unique_diff_within_at 𝕜 s x) (hx : x ≠ 0) : deriv_within (fun (x : 𝕜) => x ^ m) s x = ↑m * x ^ (m - 1) :=\n  has_deriv_within_at.deriv_within (has_deriv_within_at_fpow m hx s) hxs\n\ntheorem iter_deriv_fpow {𝕜 : Type u} [nondiscrete_normed_field 𝕜] {x : 𝕜} {m : ℤ} {k : ℕ} (hx : x ≠ 0) : nat.iterate deriv k (fun (x : 𝕜) => x ^ m) x = ↑(finset.prod (finset.range k) fun (i : ℕ) => m - ↑i) * x ^ (m - ↑k) := sorry\n\n/-! ### Upper estimates on liminf and limsup -/\n\ntheorem has_deriv_within_at.limsup_slope_le {f : ℝ → ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' s x) (hr : f' < r) : filter.eventually (fun (z : ℝ) => z - x⁻¹ * (f z - f x) < r) (nhds_within x (s \\ singleton x)) :=\n  iff.mp has_deriv_within_at_iff_tendsto_slope hf (set.Iio r) (mem_nhds_sets is_open_Iio hr)\n\ntheorem has_deriv_within_at.limsup_slope_le' {f : ℝ → ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' s x) (hs : ¬x ∈ s) (hr : f' < r) : filter.eventually (fun (z : ℝ) => z - x⁻¹ * (f z - f x) < r) (nhds_within x s) :=\n  iff.mp (has_deriv_within_at_iff_tendsto_slope' hs) hf (set.Iio r) (mem_nhds_sets is_open_Iio hr)\n\ntheorem has_deriv_within_at.liminf_right_slope_le {f : ℝ → ℝ} {f' : ℝ} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' (set.Ici x) x) (hr : f' < r) : filter.frequently (fun (z : ℝ) => z - x⁻¹ * (f z - f x) < r) (nhds_within x (set.Ioi x)) :=\n  filter.eventually.frequently (has_deriv_within_at.limsup_slope_le' (has_deriv_within_at.Ioi_of_Ici hf) (lt_irrefl x) hr)\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio\n`∥f z - f x∥ / ∥z - x∥` 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 `∥f'∥`. -/\ntheorem has_deriv_within_at.limsup_norm_slope_le {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {s : set ℝ} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' s x) (hr : norm f' < r) : filter.eventually (fun (z : ℝ) => norm (z - x)⁻¹ * norm (f z - f x) < r) (nhds_within x s) := sorry\n\n/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio\n`(∥f z∥ - ∥f x∥) / ∥z - x∥` 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 `∥f'∥`.\n\nThis lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`\nwhere `∥f z∥ - ∥f x∥` is replaced by `∥f z - f x∥`. -/\ntheorem has_deriv_within_at.limsup_slope_norm_le {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {s : set ℝ} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' s x) (hr : norm f' < r) : filter.eventually (fun (z : ℝ) => norm (z - x)⁻¹ * (norm (f z) - norm (f x)) < r) (nhds_within x s) := sorry\n\n/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio\n`∥f z - f x∥ / ∥z - x∥` is frequently less than `r` as `z → x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `∥f'∥`. See also `has_deriv_within_at.limsup_norm_slope_le`\nfor a stronger version using limit superior and any set `s`. -/\ntheorem has_deriv_within_at.liminf_right_norm_slope_le {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' (set.Ici x) x) (hr : norm f' < r) : filter.frequently (fun (z : ℝ) => norm (z - x)⁻¹ * norm (f z - f x) < r) (nhds_within x (set.Ioi x)) :=\n  filter.eventually.frequently (has_deriv_within_at.limsup_norm_slope_le (has_deriv_within_at.Ioi_of_Ici hf) hr)\n\n/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio\n`(∥f z∥ - ∥f x∥) / (z - x)` is frequently less than `r` as `z → x+0`.\nIn other words, the limit inferior of this ratio as `z` tends to `x+0`\nis less than or equal to `∥f'∥`.\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  `∥f z - f x∥` instead of `∥f z∥ - ∥f x∥`. -/\ntheorem has_deriv_within_at.liminf_right_slope_norm_le {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {x : ℝ} {r : ℝ} (hf : has_deriv_within_at f f' (set.Ici x) x) (hr : norm f' < r) : filter.frequently (fun (z : ℝ) => z - x⁻¹ * (norm (f z) - norm (f x)) < r) (nhds_within x (set.Ioi 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/analysis/calculus/deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8175744806385543, "lm_q1q2_score": 0.7590433364564518}}
{"text": "/-\n*** MATHEMATICAL LOGIC ***\n\n/- *** Overview *** -/\n\nIn this unit you will learned the following concepts, among others:\n\n* mathematical logics as formal systems\n* propositions, including their syntax and semantics\n* truth judgments \n* inference rules, their meaning and notation\n* axioms\n* proofs as evidence that justify truth judgments\n* propositions about equality\n* automating propositions and proofs in Lean\n* an axiom defining equality in general\n* type judgments\n* proof trees (derivations)\n* set theory and type theory as axiomatic foundations for mathematics\n-/\n\n/- *** Formal systems *** -/\n\n/-\nModern mathematics, and discrete mathematics in particular,\nare formal (mathematical) logical systems. \n\nLogical systems in turn are rooted in the concepts of \npropositions, truth judgments, inference rules, and \nproofs, or derivations, as evidence supporting truth\njudgments.\n\nThis is pretty abstract. Let's see what it really means.\n-/\n\n/- ** 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: ¬ (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 intution, 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 ¬ (0 = 1) is true.\n\nPropositions, then, are claims that certain states\nof affairs hold, and logic provides us with rules\nfor determing 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\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/- * semantics *-/\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-/\n\n/- ** Inference rules ** -/\n\n/-\nSo how do we decide whether a given proposition\ncan be judged to be true or not? Here is where \nthe semantics of a logic come into play.\n\nThe semantics of a logic comprises a set of rules,\ncalled inference rules, that define the conditions \nunder which a given proposition can be judged to \nbe true.\n\nOversimplying a bit, if you can apply one or more \ninference rules to propositions you already know \nto be true, and if by doing this you \"deduce\" some\nnew proposition, then you can conclude that that\nnew proposition must also be true. Such a \"chain\"\nof inference rules, linking things already known\nto be true to propositions that you want to prove\nto be true because they follow logically is called\na proof. A valid proof is incontrovertible evidence\nthat the final proposition is true.\n\nAn inference rule is like a little program: it says,\nif you can give me evidence (i.e., proofs) showing\nthat certain \"input\" propositions can be judged to\nbe true, then I will hand you back evidence (i.e.,\na proof) that shows that some new proposition can \nalso be judged to be true. We would say that from \nthe  proofs of the premises (the input propositions\nalready known to be true), the rule derives or deduces\na proof of the conclusion.\n\nLogicians often write inference rules like this:\n\n  list of input truth judgments \n  ----------------------------- (name-of-rule)\n  truth judgment for conclusion\n\nThe required input judgments, called premises (or\nantecedents), are listed above the line. The name \nof the rule is given to the right of the line. And\nthe proposition (or consequent) that can thereby\nbe judged to be true (the conclusion of the rule)\nis written below the line.\n\nFor example, if we already have the truth judgment,\n(0 = 0 : true), and another, (1 = 1: true), then the \ninference rule that logicians call \"and introduction\"\n(or \"conjunction introduction\") can be used to derive\na truth judgment for the new proposition, \"0 = 0 and\n1 = 1\", typically written as 0 = 0 ∧ 1 = 1. (Hover\nyour mouse over special symbols in this editor to\nlearn how to use them in your work.)\n\nPredicate logic will thus (in effect) include this \nrule as an inference rule:\n\n0 = 0 : true, 1 = 1 : true\n-------------------------- and-introduction-*\n      0 = 0 ∧ 1 = 1\n\nThis can be pronounced as, \"If you already have \nevidence (a proof) supporting the judgment that \n0 = 0 is true, and if you also have evidence (a\nproof) supporting the judgment that 1 = 1 is true, \nthen by applying the and-introduction-* rule, \nyou can deduce (obtain a proof justifying a truth\njudgment for) the proposition, 0 = 0 ∧  1 = 1\". \n\nWe've put a * on the name of this rule to indicate\nthat it's really just a special case of a far more\ngeneral inference rule for reasoning about equality. \n\nInference rules are usually written not in terms of \nvery specific propositions, such as 0 = 0, but in \nterms of variables that can refer to any arbitrary \npropositions. They are often called meta-variables.\n\n\nIn this way, inference rules become program-like, in\nthat they can take arbitrary inputs (of the correct \ntypes), and whenever they are given such inputs, they\nproduce result of a promised type.\n\nHere's a simple example of such a parameterized and\nthereby generalized rule. If P is *any* proposition \n(e.g., it could be 0 = 0 but might be some other\nproposition), and Q is another proposition (e.g.,\n1 = 1), and if both propositions are already known\nto be true, then you can always conclude that the \nproposition \"P and Q\", written P ∧ Q, must also be\ntrue, for whatever propositions P and Q happen to \nbe.\n\nHere is how the general form of this inference rule \nwould typically be written in a book on logic.\n\nP : true, Q : true\n------------------ (and-introduction)\n   P ∧ Q : true\n\nNow here we're going to pull a little trick. \nIt's based on the idea that a \"proof\", whatever\nthat is (!), serves as \"evidence\" that justifies\na truth judgment about a proposition. So we are\nnow technically distinguishing between a proof\nof a proposition and the truth judgment that it\njustifies. Nevertheless, we will assume that a\ntruth judgment for some proposition, P, is in\nfact justified if and only if we have a proof\nof P.\n\nTo denote the fact that we have a proof, \nlet's call it, p, of some proposition, P, \nwe will write p : P. Now, the idea is that \nif we have p : P then we also have P : true, \nand the only way we can get P : true is if \nwe have some evidence, p, (a proof) for P. \n\nIn other words, P is true if and only if we \nhave evidence (a proof), p, for P. We can \nwrite this statement in the language of logic\nlike this: \"p : P ↔ P : true\".  The evidence, \np, for P, justifies the judgement, P : true,\nand the only way to justify such a judgement\nis with such a piece of evidence. The bottom\nline: having a proof of P is equivalent to P \nbeing true.\n\nWe can thus write an equivalent inference \nrule like this (compare with the previous):\n\np : P, q : Q\n------------ (and-introduction)\n r : P ∧ Q\n\nThis then says, \"If you give me a proof, p, of\nsome proposition, P, and if you also given me a\nproof, q, of some proposition Q, then I promise\nto give you back a proof, r, of the proposition,\nP ∧ Q.\" \n\nAs a shorthand, logicians usually leave off the\n\": true\" bits and/or the \"p :\" bits, and so you'd \nusually see this rule written simply like this:\n\n   P, Q\n   ----- and-introduction\n   P ∧ Q\n\nAbove the line, then, is a list of propositions \nthat must be true (i.e., for which there must\nalready be proofs) for the rule to be applied. Below \nthe line is a new proposition, the conclusion, \nwhich typically involves some premise propositions.\nAn inference rule allows you to conlude that the\nconclusion is true whenever you already know that\nthe premises are true. \n\nA nice way to think about such a rule is as a \nlittle program. Let's call it \"and-introduction!\" \nIt takes two arguments: namely a proof, p, of P, \nand a proof, q, of Q. When these are provided as\narguments, the program constructs and returns a \nproof, r, of P ∧ Q. How it might do this and what \nsuch a proof might look like are details that we \nwill get to shortly. \n-/\n\n/- \nEXERCISE: What is returned when the and-introduction\ninference rule, viewed as a program, is applied to two\nproofs: one of the proposition, 0 = 0, and one of the\nproposition, \"Hello\" = \"Hello\"?\n\nEXERCISE: Why could this rule never be applied (in\nany reasonable logic) to produce a proof (thus a\ntruth judgement) for the proposition, 0 = 0 ∧ 0 = 1?\n-/\n\n/- *** Axioms *** -/\n\n/-\nIn a mathematical or logical system, some propositions \nare taken to be true unconditionally: without the need \nfor any prior \"input\" judgements or proofs.\n\nAn inference rule that requires no proof or truth\njudgement inputs, and that nevertheless lets you \njudge some proposition to be true unconditionally,\n(e.g., by simply handing you a proof of or a truth\njudgment for that proposition), is called an axiom. \n\nWe also use the term, axiom, to refer to the \nproposition that is the conclusion of the rule, \nand that is thereby judged true unconditionally. \n\nAn axiom viewed as an inference rule with no\nproofs/judgements as inputs would be written\nwith no proof/judgment premises/arguments above\nthe line.\n\nFor example, if we were to take the proposition, \n0 = 0, as an axiom, we could write it like this: \n\n           <---- note the absence of premises\n-----\n0 = 0\n\nWhat this says then is that without having proved \nor judged any other propositions to be true you can\nnevertheless assume that 0 = 0 is true. Equivalently,\nwithout providing any proofs of other propositions\nas arguments, this rule will still hand you back a\nproof of 0 = 0, thereby justifying the judgment that\n0 = 0 is true. In this case, you could say that the\nlogic includes 0 = 0 as an axiom.\n-/\n\n/- ** An inference rule for equality in general ** -/\n\n/-\nIntuitively you would suppose that the proposition,\n0 = 0, should be true in any reasonable logical system. \n\nThere are two ways a logic could make this happen. \nThe first is that the logic could provide 0 = 0 as \nan axiom, as we just discussed. \n\nThat'd be ok, but then we'd need similar axioms for \nevery other number. We'd also need similar axioms\nfor every object of every other type: person, car, \nplant, atom, book, idea, etc. We end up with a pretty\nunweildy (and infinite) set of axioms. Moreover, if\nwe were ever to define a new type of objects (e.g.,\ndigital pets), we'd have to extend the logic with \nsimilar inference rules for every value of the new\ntype. (Fido = Fido, Spot = Spot, Kitty = Kitty, etc).\n\nWhat would be much better would be to have just one\ninference rule that basically allow us to conclude\nthat *any* object, or value, of any type whatsoever \nis always equal to itself (and that nothing else\nis ever equal to that object).\n\nIt'd go something like this: if T is any \"type\" \n(such as natural number, car, person), and t is any \nobject or value of that type, T (e.g., 0 is a value\nof type \"natural number\", or \"nat\"), then you can \nunconditionally conclude that t = t is true.  \n\n/- * Type judgments * -/\n\nWe meet a new kind of judgment here: a type judgment.\nIf X is some type, and x is a value of that type, X, \nwe can denote this fact by writing x : X. We read this\nas \"x is of type X.\"\n\n\n\n/- * The types of types * -/\n\nThe Lean tool that you're using here is based on a\nfoundational theory called type theory. In type\ntheory, every object (or value) has a single type.\nEvery parameter, such as an argument to a function.\nhas a type. Every expression has a type. \n\nIn Lean you can check the type of an expression\nby using the #check command. Note that ℕ is math\nshorthand for the type of natural numbers, i.e.,\nnon-negative integers (thus zero on up). Hover\nyour mouse over the #check commands to see what\nare the types of 0, \"Hi!\", and tt in Lean.\n-/\n\n#check 0\n#check \"Hi!\"\n#check tt\n\n/-\nHere's the key idea: types are values, too! It\nthus follows that a type must have a type. So \nwhat is the type of a type? \n\nAnswer: If T is a type, then it's type is called \n\"Type\".\n-/\n\n/-\nEXERCISE: Use the #check command the see what is \nthe type of nat, bool, and string.\n-/\n\n/-\nSo, if T is some type, then we'd write the type \njudgment, \"T : Type\". And if T is a type, and t \na value of type, T, then we'd also write t : T. \n-/\n\n\n/-\nSo now, with all that out of the way, we can write\nthe inference rule for equality that we really want. \n\nT: Type, t : T\n-------------- (eq)\n    t = t\n\nThose are now type judgments above the line. You can \nunderstand this inference rule as saying this: \"if you \ngive me a T that is a type (e.g., bool, nat, string), \nand if you also give me a value, t, of type, T, (e.g.,\n0 or true), then I will give you back a proof that \nt = t. This single inference rule thus defines a very \nsensible notion of equality for all values of all types \nthat exist or might ever be defined. \n\n(Detail: This notion of equality is called Leibniz\nequality.)\n\nEXERCISE: Why exactly can this rule never be used to \nderive a proof of the proposition that 0 = 1?\n\nSo now, rather than a separate axiom for 0 = 0,\nanother one for 1 = 1, another for true = true, and\nyet another for Fido = Fido, so forth, we now have \na single inference rule, which we take as an axiom\n(no prior proofs are required, but the types of T\nand t do have to be right) that covers every possible \ncase, forever forward.  \n\n/- * Formalizing Leibniz equality * -/\n\nNow we move the ball forward yet another yard or two. \nIn predicate logic, we could also write the inference \nrule for eq like this: ∀ T: Type, ∀ t: T, t = t. \n\nThe upside-down A is called the universal quantifier \nof predicate logic. You can pronounce it as \"for all\" \nor \"for any\" or \"if you give me any value of the given\ntype ...\" Thus we have, \"for any T of type, Type, ...\"\nand what then follows is a proposition in which T is\nused. That following proposition also uses ∀. And the\nproposition after that, t = t, is interpreted in a way\nthat assumes T and t have been given specific meanings\nby the preceding quantifiers. We say that T and t are\n\"bound\" in the expression, t = t. The scope of that\nbinding is limited to the current proposition.\n\nYou could thus pronounce the rule like this: \"If you\ngive me any value, T, of type, Type (which is to say\nthat if T is any type), and if you give me any value,\nt, of that type, T, then I promise to give you back \na value of type t = t.\n\nWait! We expected to get back a proof of t = t.\n\nYeah! In the logic of Lean, propositions are types\nand proofs are values of these types. To read the\nrule again, we could say, if you given me any type,\nT, and any value, t, of that type, I promise to give\nyou back a value of type, t = t. But t = t is clearly\na proposition, so a value of this type is ... wait for\nit ... a proof: a proof of the proposition, t = t.\" \n-/\n\n/-\nNow, given this more general inference rule, we could\n\"apply\" it to the case where T = nat (Lean's name for\nthe type of natural numbers), and where t = 0 (a value\nof this type) to produce a proof of 0 = 0. We could \napply the same  rule to derive truth judgements for \n1 = 1, 2 = 2, true = true, \"Bob\" = \"Bob\", and so on.\n-/\n\n/-\nIn Lean, this inference rule is built in (actually \ndefined in a library that is automatically loaded \nwhen you start Lean). Moreover, there's a shorthand \nin Lean for applying this rule to a value, t, of \nsome particular type, T, to produce a proof of \nt = t. The shorthand is called \"rfl\". It can be \napplied whenever you want to produce a proof that \ntwo terms are equal.\n\nHere's an example for the proposition, 0 = 0. Note:\nmathematicians will often use the term \"theorem\" for a\nproposition for which there is a proof of its truth.\n-/\n\ntheorem zeqz: 0 = 0 := rfl\n\n/-\nLet's decode that. First, it says we're about\nto establish a theorem by stating a proposition\nand by giving a proof. The name that we give to\nour proposition is zeqz (any variable name not \nalready in use would do). The proposition for\nwhich we seek a truth judgment (proof) is 0 = 0. \nThe := separates the proposition from code that\nis intended to produce such a proof. The proof \ncode here is simply rfl. This rfl \"thing\" in\nturn looks at the value on the left side of the\nequal sign. It finds 0. That's \"t\". rfl can then \ninfer that that the type of t is nat. That's T.\nGiven T = nat and t = 0, rfl returns a proof of\n(a truth judgment for) the proposition, t = t,\nwhere t = 0, which is to say, a proof of 0 = 0.\nLean then checks that this is a valid proof for\nthe proposition to be proved (also 0 = 0), which\nit is, so so Lean accepts the proof as valid,\nand assigns the proof as the value of zeqz.\nFrom this point forward, zeqz can be used as \na proof -- justifying a truth judgment -- for \nthe proposition, 0 = 0. \n-/\n\n/-\nEXERCISE: Try to use the same approach to prove\na \"theorem\" (call it zeqo) that 0 = 1. What goes \nwrong? Hover over the red squiggles to see the \nerror messages say. They're cryptic, but we can \npuzzle out what it's saying more or less. First,\nthe one over the rfl says rfl is expected to be\na proof that something (here denoted as m_2) is\nequal to itself, but it is given as a putative \nproof of 0 = 1, and that doesn't work because in\nfact it's not the case that 0 = 1. In a funny way\nLean treats the proposition as a type and expects\nthe proof to be a value of that type. Here, rfl \ngenerates a proof of \"type\" 0 = 0, but the \"type\"\nof this proof object doesn't work for the type\nof the proposition to be proved, \"0 = 1\", so Lean\nrejects the proof. The red line over the zeqo\nthen explains that you've promised to provide a\nproof, but you haven't, and so the thing you said\nwould be a theorem hasn't actually been proven to\nbe one!\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 somewhat less \nimportant proposition that has been proved, often as\npart of a larger proof of a more important theorem.\nMathematicians also use the word corrolary 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/-\nFor use in a few minutes, here's a similar \ntheorem (proposition with a proof) for the\nproposition that one equals one.\n-/\n\ntheorem oeqo : 1 = 1 := rfl\n\n/-\nEXERCISE: Use the same approach to prove that\n\"hello\" = \"hello\".\nEXERCISE: Does this approach work to prove that\n2 = 1 + 1? You'd think it should, but those are\ntwo different expressions on each side of =. Try\nit to see if rfl can be used to generate a proof\nthat 2 = 1 + 1. Call your proof teqopo (for two\nequals one plus one).\n-/\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 of what two expressions\nmean: equality of the values to which they \"reduce\"\nwhen you \"evaluate\" them. We can prove 2 = 1 + 1\nusing rfl because the \"literal expression\", 2, \nreduces  to the value 2, and the function \napplication expression, 1 + 1 (wherein the plus \nfunction is applied to the two arguments, 1 and 1) \nalso reduces to (evaluates to) 2. Now you've got \nthe same value on each side of the =, and rfl \nwill generate a valid proof of that proposition.  \nThe Lean type checker then confirms that this proof\nis of type 2 = 1 + 1, and Lean takes that proof to\nbe the value of teqopo.\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++ \"Logic! is equal to \"Hello Logic!\" (these values \nare of type string in Lean and the ++ operator here \nrefers to the string concatenation function in Lean.)\n-/\n\n/- *** Applying Inference Rules *** -/\n\n/-\nAs a cherry on top, let's return to the idea of\ninference rules that require prior proof judgments\nof other propositions as inputs. What inference\nrules do in general is to build bigger proofs\nfrom smaller ones!\n\nFor example, we now have a proof, zeqz, for the \nproposition that 0 = 0, and we also have one, oeqo, \nfor the proposition, 1 = 1. You'd think we might \ntherefore be able to produce a new proof for the \nproposition that 0 = 0 ∧ 1 = 1.\n-/\n\n/-\nEXERCISE: What inference rule might we try to apply\nto generate such a proof? \n-/\n\n/-\nIn Lean the and-introduction inference rule goes by\nthe name and.intro. It takes two arguments: a proof \nfor any proposition, P, and a proof for another\nproposition, Q. It then returns a proof for the \nproposition P ∧ Q. Here's the code!\n-/\n\ntheorem zeqz_and_oeqo: 0 = 0 ∧ 1 = 1 := \n    and.intro zeqz oeqo -- study this carefully!\n\n/-\nOk, let's decode that. We're proposing a theorem.\nThe proposition we aim to prove is 0 = 0 ∧ 1 = 1.\nIf we can generate a proof that Lean accepts, it\nwill become the value bound to zeqz_and_oeqo. \nFinally, we propose to generate this proof by \napplying the and introduction inference rule, which, \nagain, in Lean, is called and.intro.\n\nThis rule, and.intro, is really just a function!\nIn Lean you apply a function to its arguments by \nfirst writing the function name and then writing \neach of the arguments following that name. You do\nnot write the arguments to a function as a list \nof values within parentheses as in Python or Java. \n\nVoilà! We apply an inference rule \"program\" to\ntwo smaller proofs to get a larger one and then\nLean checks automatically to make sure it's a\nvalid proof for the proposition that was asserted.\nIt actually does this by checking to see if the\ntype of the proof is consistent with the type of\nthe proposition.\n-/\n\n/-\nEXERCISE: What happens if the proofs you pass to \nand.intro aren't quite right? For example, try to \ngive zeqz as the value for both arguments. Does the\nresulting proof \"type check\"?\n-/\n\n/-\nSuppose we wanted to prove a similar theorem for\nthe proposition that 2 = 2 ∧ \"Hi\" = \"Hi\". We can\nof course write two smaller theorems for 2 = 2 \nand \"Hi\" = \"Hi\". Each of these would in turn be\nproved by the application of the rfl rule. Then \nwe could use the named proofs as inputs to the\nand.intro \"rule\" and we'd be done. But there's \na shorter way to go: just write the proofs of \nthe individual propositions directly inline.\nThe and.intro rule needs a proof of 2 = 2, and\nrfl will do. Similarly it needs a proof of \"Hi\"\n= \"Hi\", and once again, rfl will so.\n-/\n\ntheorem teqt_and_heqh: 2 = 2 ∧ \"Hi\" = \"Hi\" :=\n  and.intro rfl rfl \n\n\n/- ** Formal Systems ** -/\n/-\nA mathematical, or formal, system starts with a set \nof inference rules including axioms (with the condition \nthat this starting point not be self-contradictory; so, \nfor example, you would never want 0 = 1 as an axiom). \nIt extends to include the typically infinite set of \nall of theorems that can be possibly \"proved\" by any\nnumber of applications of available inference rules \nto already available truth judgments (or equivalently\nto proofs, which in Lean are taken to be tantamount\nto truth judgments).  \n-/\n\n/-\nEXERCISE: What are some other theorems that you could\nprove using only the concepts we've discussed so far?\nFormulate and prove several new theorems. Note that \nLean has a Boolean type, called bool, with the values\ntt and ff (short for Boolean true and Boolean false).\nProve at least one theorem involving Boolean values.\n-/\n\n/- ** What mathematicians and some computer scientists do -/\n\n/-\nWorking mathematicians and computer scientists don't sit\naround all day mechanically generating theorems by applying\ninference rules to already proved theorems to come up with\nnew theorems. That would be like typing randomly and hoping\nto produce a new Shakespeare-quality play. \n\nRather, mathematicians and computer scientists, come up\nwith propositions that they believe, and hope, are true\n(e.g., a proposition that asserts that some program gives\nthe right answer for any possible combination of inputs);\nand they then have the task of producing proofs to show\nthat such propositions are true.\n\nWe call this the problem of \"proving\" that a proposition\nis true. If there is already a truth judgment for (proof \nof) the given proposition, it's easy: you just hand over\nthe existing proof. If there are proofs to which an\ninference rule can be applied directly to produce a\nproof for the given proposition, then you just apply the\ninference rule to those proofs and you hand over the new\nproof that results. In the typical case, you won't have\nproofs of propositions that you need as inputs to the\ninference rule that you'll ultimately want to generate\nthe desired proof, so you need to go off and produce\nproofs of those intermediate propositions first. In this \nway the task of producing the desired proof is broken\ndown into one or more smaller problems of producing the\nproofs that are needed to feed the inference rule that\nwill be used to produce the final proof. \n\nMathematicians typically label the proposition that is\nultimately to be proved as a theorem (once there really\nis a proof), and the smaller propositions to be proved\nas lemmas. In Lean you can use theorem and lemma (and\na few other keywords, such as def) interchangeably.\n\nSuch a process is said to be \"recursive\". Axioms give\nyou starting points. You then apply inference rules to\nproduces proofs of larger and larger lemmas. Finally \nyou apply some inference rule to proofs of key lemmas\nto produce a proof of the desired theorem. \n\nThe chain of \"derivations\" that thus results is what\nlogicians and mathematicians sometimes call a proof tree.\nSuch trees can be written using inference rule notation.\n\nHere's the entire proof tree for 0 = 0 ∧ 1 = 1. \n\n rfl     rfl\n-----   -----\n0 = 0   1 = 1\n------------- \n0 = 0 ∧ 1 = 1\n\nRead it from bottom to the top: to prove the desired\nproposition, we need proofs of 0 = 0 and 1 = 1 \nrespectively. Each of these in turn can be produced \nby the rfl \"axiom\". These axioms requires no prior \nproofs (truth judgments) as inputs, so you are done. \n(We've left off the rule names to make the proof \ntree easier to read. Typically they'd be included.)\n\nSo, coming up with a proof of a proposition that hasn't \nyet been proved often feels like a \"backwards chaining\"\nactivity. When asked to prove a proposition, P, we often\ntry to find other propositions, such as Q and R, such that\nif we had proofs of Q and R, we could then apply a valid \ninference rule to prove P. One thus reduces the problem \nof proving P to the sub-problems of proving Q and R. One \nthen backward-chains this way until one finally reaches \n... axioms! Axioms are the \"base cases\" in the recursive\ndecomposition of the overall problem: there is no need\nto recurse any further once you've reach the bottom!\n-/\n\n/-\nEXERCISE: What \"smaller\" propositions might you want to\nprove if your aim is ultimately to prove the proposition\nthat 5 = 1 + 4 ∧ \"Strike\" = \"S\" ++ \"trike\". Go ahead and\nprove those smaller propositions. You can use whatever\nnames you want for these little \"theorems\", then write\nthe theorem that proves the final result using the lemmas\nas inputs.\n-/\n\n/- ** Logical Foundations of Mathematics ** -/\n\n/-\nModern mathematics is axiomatic. It's logical. It is\n\"founded\" on mutually consistent axioms and inference\nrules. \n\nThere is however more than one way to establish the \nlogical foundations of mathematics.\n\nThe most widely used axiomatic foundation comprises a\nset of axioms that describes what it means to be a set,\nand everything else then builds on the concept of sets.\nThe resulting theory is called \"set theory.\" Set theory\nis the most widely accepted and used logical foundation\nfor everyday mathematics.\n\nThe natural numbers for example can be \"formalized\" as\nsets. Zero is represented by the empty set; one by the\nset that contains only the empty set; two by the set\nthat contains that set; and so forth. \n\nThe specific set theory foundation for ordinary\nmathematics is known as Zermelo-Frankl Set Theory \nwith the Axiom of Choice (often abbreviated as ZFC). \nThe axioms of ZFC capture our \"naïve\" view of sets \nas collections of elements. It took much time and\ngreat care, however, to craft a set of axioms that\nare not self-contradicting. The original formulation\nof set theory turned out to be inconsistent! \n\n(Does the set of all sets that do not contain \nthemselves contain itself? If it does, then it \ndoesn't, and if it doesn't then it does: a real \ninconsistency! In fact it was this problem that\nled mathematicians to a much more careful notion\nof what it means to be a set, as captured by the\naxioms of ZFC.\n\nAs another example of an inconsistency, there's \na word in the English language to describe words \nthat describe themselves: autological. The antonym \nof autological is heterological. \"Polysyllabic\" is \nautological, but  \"palindrome\" is heterological. \nIs the word \"heterological\" heterological? If the \nword doesn't describe itself, then it is, but then \nthe word would describe itself. So, yeah, English\nis inconsistent in this sense.)\n\nThe axioms of ZFC are somewhat technical; we will \nnot explore them in this class. What you might want\nto remember is that if you want to prove even simple\nmathematical proposition in a precise, fully formal \nway using ZFC, it is a complex and messy affair. \n\nIn fact, it's so messy that most mathematicians trade\nin rigorous but informal proofs. By informal \nproofs we mean mathematical arguments written in a \nstylized form of a natural language, such as English.\nFor example, a proof of 0 = 0 and 1 = 1 might read\nlike this: \"To prove the proposition, which is a\nconjunction, we need proofs of the two parts. The\nfirst, 0 = 0, is proved by noting that equality is\na reflexive relation, and 1 = 1 is proved similarly.\nGiven that both conjuncts are so, then so is the\noverall conjunction. So it is shown (QED in latin).\"\n\nBecause machines aren't much good at figuring out what\nnatural language text means with mathematical precision, \nit's nearly impossible today for computers to check that\npurported informal proofs are correct. Proof checking \nremains a demanding, mostly human, and social process. \n\nWhen a mathematician claims to have produced a proof\nof a theorem of potential significance, other experts\ncome together (often as reviewers for journals to which\nmathematical purported proofs are generally submitted \nfor review and publication) to see if they can find \nany errors in reasoning. They often do! \n\nSuch human proof checking has in some cases proved to \nbe nearly intractable. For example, in 2012, Shinichi \nMochizuki, a reclusive Japanse mathematician, quietly \nposted to the web a 500-page \"putative\" proof of a \nmajor mathematical conjecture (proposition for which\nthere is not yet a proof) in number theory and geometry.\nIf correct, it could revolutionize mathematics. Yet the \nwork is so complex and unusual that the mathematical \ncommunity even to this day has still been unable even \nto comprehend the overall concept, not to mention \nchecking every last detail for subtle errors. \n-/\n\n/- \nHOMEWORK: Read this article. https://www.sciencealert.com/nightmarish-500-page-math-proof-even-experts-can-t-understand-about-published-shinichi-mochizuki\n-/\n\n/-\nAn alternative foundation for mathematics (in particular\nfor what is called \"constructive\" mathematics) is available\nin what is called \"type theory.\" It's basically a different\n(from ZFC) set of axioms and inference rules on which math \ncan be based. Not surprisingly, types, rather than sets, are\na fundamental building block of mathematics in type theory.\nSets can be modeled, but they are not built in. \n\nFrom your high school math background, you probably \nalready have a reasonable intuition for sets as collections\nof values. A type also defines a set of values, and each\nvalue in that set has that type. But whereas a value can be\nin many sets, in type theory a value has exactly one type.\nWhenever you see a value, or an expression that reduces to\na value, in type theory, it thus makes sense to ask the\nquestion, what is its type? Every well formed expression\nand value in a type theory has exactly one type. \n\nIn Lean, we can ask the type of an expression (including\nof a literal expression that directly denotes a value) by\nusing the check command. Hover your mouse over the #check\ncommand. Note that ℕ is mathematical notation for \"natural\nnumber\", the type of non-negative integers.\n-/\n\n-- The types of some literal expressions \n#check 0\n#check \"Hello\"\n#check tt\n\n-- defining a binding of an identifier to a value\ndef foo := 0\n\n-- The type of a variable expression\n#check foo\n\n-- The types of some more complex expressions\n#check 1 + foo\n#check \"Hello \" ++ \"Logic!\"\n#check tt && ff\n\n/-\nWithout getting into complicated details, it will suffice \nfor now to say that proofs are much more tractable objects \nin type theory than in set theory. Type theory has thus \nemerged as an important framework for *automating* the \nhandling of logic in both mathematics and computer science. \n\nFor computer scientists, it is also the main foundation for\nfunctional programming, the theory of programming languages, \nand for formal verification of software correctness, which\nis vitally important when ultra-high levels of confidence \nin the correctness of code is required (e.g., for security). \n\nThis very tool and language that you're using now, the Lean\nprover, is based on type theory. It's am example of what's \nknown in the business as a proof assistant. But you can just \nthink of it for now as a really cool tool in which you can \nwrite both programs and logic, and that can help you to \nconstruct \"manageable\" proofs. Through the magic of type \nchecking it then *automatically* determines whether a proof \nis valid for a given proposition.\n\nThis technology holds the promise of eventually changing\nthe way that code is written and verified, and even the way \nthat mathematics work.\n-/\n\n/-\nIn this unit you've learned the following concepts:\n\n* formal system\n* proposition\n* axiom\n* inference rule\n* truth judgment \n* proof\n* equality\n* type judgment\n* set theory and type theory foundations of mathematics\n* type theory for automating mathematical logic and proof checking\n-/", "meta": {"author": "Mnormansell", "repo": "Discrete-Notes", "sha": "61f13b98be590269fc4822be7b47924a6ddc1261", "save_path": "github-repos/lean/Mnormansell-Discrete-Notes", "path": "github-repos/lean/Mnormansell-Discrete-Notes/Discrete-Notes-61f13b98be590269fc4822be7b47924a6ddc1261/00_Foundations/00_intro.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7589224714411337}}
{"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 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 α` is \"symmetric\" if `Aᵀ = A`.\n\n## Tags\n\nsymm, symmetric, matrix\n-/\n\nvariables {α β n m R : Type*}\n\nnamespace matrix\n\nopen_locale matrix\n\n/-- A matrix `A : matrix n n α` is \"symmetric\" if `Aᵀ = A`. -/\ndef is_symm (A : matrix n n α) : Prop := Aᵀ = A\n\nlemma is_symm.eq {A : matrix n n α} (h : A.is_symm) : Aᵀ = A := h\n\n/-- A version of `matrix.ext_iff` that unfolds the `matrix.transpose`. -/\nlemma is_symm.ext_iff {A : matrix n n α} : A.is_symm ↔ ∀ i j, A j i = A i j :=\nmatrix.ext_iff.symm\n\n/-- A version of `matrix.ext` that unfolds the `matrix.transpose`. -/\n@[ext]\nlemma is_symm.ext {A : matrix n n α} : (∀ i j, A j i = A i j) → A.is_symm :=\nmatrix.ext\n\nlemma is_symm.apply {A : matrix n n α} (h : A.is_symm) (i j : n) : A j i = A i j :=\nis_symm.ext_iff.1 h i j\n\nlemma is_symm_mul_transpose_self [fintype n] [comm_semiring α] (A : matrix n n α) :\n  (A ⬝ Aᵀ).is_symm :=\ntranspose_mul _ _\n\nlemma is_symm_transpose_mul_self [fintype n] [comm_semiring α] (A : matrix n n α) :\n  (Aᵀ ⬝ A).is_symm :=\ntranspose_mul _ _\n\nlemma is_symm_add_transpose_self [add_comm_semigroup α] (A : matrix n n α) :\n  (A + Aᵀ).is_symm :=\nadd_comm _ _\n\nlemma is_symm_transpose_add_self [add_comm_semigroup α] (A : matrix n n α) :\n  (Aᵀ + A).is_symm :=\nadd_comm _ _\n\n@[simp] lemma is_symm_zero [has_zero α] :\n  (0 : matrix n n α).is_symm :=\ntranspose_zero\n\n@[simp] lemma is_symm_one [decidable_eq n] [has_zero α] [has_one α] :\n  (1 : matrix n n α).is_symm :=\ntranspose_one\n\n@[simp] lemma is_symm.map {A : matrix n n α} (h : A.is_symm) (f : α → β) :\n  (A.map f).is_symm :=\ntranspose_map.symm.trans (h.symm ▸ rfl)\n\n@[simp] lemma is_symm.transpose {A : matrix n n α} (h : A.is_symm) :\n  Aᵀ.is_symm :=\ncongr_arg _ h\n\n@[simp] lemma is_symm.conj_transpose [has_star α] {A : matrix n n α} (h : A.is_symm) :\n  Aᴴ.is_symm :=\nh.transpose.map _\n\n@[simp] lemma is_symm.neg [has_neg α] {A : matrix n n α} (h : A.is_symm) :\n  (-A).is_symm :=\n(transpose_neg _).trans (congr_arg _ h)\n\n@[simp] lemma is_symm.add {A B : matrix n n α} [has_add α] (hA : A.is_symm) (hB : B.is_symm) :\n  (A + B).is_symm :=\n(transpose_add _ _).trans (hA.symm ▸ hB.symm ▸ rfl)\n\n@[simp] lemma is_symm.sub {A B : matrix n n α} [has_sub α] (hA : A.is_symm) (hB : B.is_symm) :\n  (A - B).is_symm :=\n(transpose_sub _ _).trans (hA.symm ▸ hB.symm ▸ rfl)\n\n@[simp] lemma is_symm.smul [has_smul R α] {A : matrix n n α} (h : A.is_symm) (k : R) :\n  (k • A).is_symm :=\n(transpose_smul _ _).trans (congr_arg _ h)\n\n@[simp] lemma is_symm.submatrix {A : matrix n n α} (h : A.is_symm) (f : m → n) :\n  (A.submatrix f f).is_symm :=\n(transpose_submatrix _ _ _).trans (h.symm ▸ rfl)\n\n/-- The diagonal matrix `diagonal v` is symmetric. -/\n@[simp] lemma is_symm_diagonal [decidable_eq n] [has_zero α] (v : n → α) :\n  (diagonal v).is_symm :=\ndiagonal_transpose _\n\n/-- A block matrix `A.from_blocks B C D` is symmetric,\n    if `A` and `D` are symmetric and `Bᵀ = C`. -/\nlemma is_symm.from_blocks\n  {A : matrix m m α} {B : matrix m n α} {C : matrix n m α} {D : matrix n n α}\n  (hA : A.is_symm) (hBC : Bᵀ = C) (hD : D.is_symm) :\n  (A.from_blocks B C D).is_symm :=\nbegin\n  have hCB : Cᵀ = B, {rw ← hBC, simp},\n  unfold matrix.is_symm,\n  rw from_blocks_transpose,\n  congr;\n  assumption\nend\n\n/-- This is the `iff` version of `matrix.is_symm.from_blocks`. -/\nlemma is_symm_from_blocks_iff\n  {A : matrix m m α} {B : matrix m n α} {C : matrix n m α} {D : matrix n n α} :\n  (A.from_blocks B C D).is_symm ↔ A.is_symm ∧ Bᵀ = C ∧ Cᵀ = B ∧ D.is_symm :=\n⟨λ h, ⟨(congr_arg to_blocks₁₁ h : _), (congr_arg to_blocks₂₁ h : _),\n       (congr_arg to_blocks₁₂ h : _), (congr_arg to_blocks₂₂ h : _)⟩,\n λ ⟨hA, hBC, hCB, hD⟩, is_symm.from_blocks hA hBC hD⟩\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/symmetric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8539127566694177, "lm_q1q2_score": 0.7589224613012695}}
{"text": "/-\nCopyright (c) 2021 Heather Macbeth. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Heather Macbeth, David Loeffler\n\n! This file was ported from Lean 3 source module analysis.fourier.add_circle\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.SpecialFunctions.Complex.Circle\nimport Mathbin.Topology.Instances.AddCircle\nimport Mathbin.Analysis.InnerProductSpace.L2Space\nimport Mathbin.MeasureTheory.Function.ContinuousMapDense\nimport Mathbin.MeasureTheory.Function.L2Space\nimport Mathbin.MeasureTheory.Group.Integration\nimport Mathbin.MeasureTheory.Integral.Periodic\nimport Mathbin.Topology.ContinuousFunction.StoneWeierstrass\n\n/-!\n\n# Fourier analysis on the additive circle\n\nThis file contains basic results on Fourier series for functions on the additive circle\n`add_circle T = ℝ / ℤ • T`.\n\n## Main definitions\n\n* `haar_add_circle`, Haar measure on `add_circle T`, normalized to have total measure `1`. (Note\n  that this is not the same normalisation as the standard measure defined in `integral.periodic`,\n  so we do not declare it as a `measure_space` instance, to avoid confusion.)\n* for `n : ℤ`, `fourier n` is the monomial `λ x, exp (2 π i n x / T)`, bundled as a continuous map\n  from `add_circle T` to `ℂ`.\n* `fourier_basis` is the Hilbert basis of `Lp ℂ 2 haar_add_circle` given by the images of the\n  monomials `fourier n`.\n* `fourier_coeff f n`, for `f : add_circle T → E` (with `E` a complete normed `ℂ`-vector space), is\n  the `n`-th Fourier coefficient of `f`, defined as an integral over `add_circle T`. The lemma\n  `fourier_coeff_eq_interval_integral` expresses this as an integral over `[a, a + T]` for any real\n  `a`.\n* `fourier_coeff_on`, for `f : ℝ → E` and `a < b` reals, is the `n`-th Fourier\n  coefficient of the unique periodic function of period `b - a` which agrees with `f` on `(a, b]`.\n  The lemma `fourier_coeff_on_eq_integral` expresses this as an integral over `[a, b]`.\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(add_circle T, ℂ)`, i.e. that its `submodule.topological_closure` is `⊤`.  This follows\nfrom the Stone-Weierstrass theorem after checking that the span is a subalgebra, is closed under\nconjugation, and separates points.\n\nUsing this and general theory on approximation of Lᵖ functions by continuous functions, we deduce\n(`span_fourier_Lp_closure_eq_top`) that for any `1 ≤ p < ∞`, the span of the Fourier monomials is\ndense in the Lᵖ space of `add_circle T`. For `p = 2` we show (`orthonormal_fourier`) that the\nmonomials are also orthonormal, so they form a Hilbert basis for L², which is named as\n`fourier_basis`; in particular, for `L²` functions `f`, the Fourier series of `f` converges to `f`\nin the `L²` topology (`has_sum_fourier_series_L2`). Parseval's identity, `tsum_sq_fourier_coeff`, is\na direct consequence.\n\nFor continuous maps `f : add_circle T → ℂ`, the theorem\n`continuous_map.has_sum_fourier_series_of_summable` states that if the sequence of Fourier\ncoefficients of `f` is summable, then the Fourier series `∑ (i:ℤ), f.fourier_coeff i * fourier i`\nconverges to `f` in the uniform-convergence topology of `C(add_circle T, ℂ)`.\n-/\n\n\nnoncomputable section\n\nopen ENNReal ComplexConjugate Real\n\nopen TopologicalSpace ContinuousMap MeasureTheory MeasureTheory.Measure Algebra Submodule Set\n\nvariable {T : ℝ}\n\nnamespace AddCircle\n\n/-! ### Map from `add_circle` to `circle` -/\n\n\ntheorem scaled_exp_map_periodic : Function.Periodic (fun x => expMapCircle (2 * π / T * x)) T :=\n  by\n  -- The case T = 0 is not interesting, but it is true, so we prove it to save hypotheses\n  rcases eq_or_ne T 0 with (rfl | hT)\n  · intro x\n    simp\n  · intro x\n    simp_rw [mul_add]\n    rw [div_mul_cancel _ hT, periodic_expMapCircle]\n#align add_circle.scaled_exp_map_periodic AddCircle.scaled_exp_map_periodic\n\n/-- The canonical map `λ x, exp (2 π i x / T)` from `ℝ / ℤ • T` to the unit circle in `ℂ`.\nIf `T = 0` we understand this as the constant function 1. -/\ndef toCircle : AddCircle T → circle :=\n  (@scaled_exp_map_periodic T).lift\n#align add_circle.to_circle AddCircle.toCircle\n\ntheorem toCircle_add (x : AddCircle T) (y : AddCircle T) :\n    toCircle (x + y) = toCircle x * toCircle y :=\n  by\n  induction x using QuotientAddGroup.induction_on'\n  induction y using QuotientAddGroup.induction_on'\n  simp_rw [← QuotientAddGroup.mk_add, to_circle, Function.Periodic.lift_coe, mul_add,\n    expMapCircle_add]\n#align add_circle.to_circle_add AddCircle.toCircle_add\n\ntheorem continuous_toCircle : Continuous (@toCircle T) :=\n  continuous_coinduced_dom.mpr (expMapCircle.Continuous.comp <| continuous_const.mul continuous_id')\n#align add_circle.continuous_to_circle AddCircle.continuous_toCircle\n\ntheorem injective_toCircle (hT : T ≠ 0) : Function.Injective (@toCircle T) :=\n  by\n  intro a b h\n  induction a using QuotientAddGroup.induction_on'\n  induction b using QuotientAddGroup.induction_on'\n  simp_rw [to_circle, Function.Periodic.lift_coe] at h\n  obtain ⟨m, hm⟩ := exp_map_circle_eq_exp_map_circle.mp h.symm\n  simp_rw [QuotientAddGroup.eq, AddSubgroup.mem_zmultiples_iff, zsmul_eq_mul]\n  use m\n  field_simp [real.two_pi_pos.ne']  at hm\n  rw [← mul_right_inj' real.two_pi_pos.ne']\n  linarith\n#align add_circle.injective_to_circle AddCircle.injective_toCircle\n\n/-! ### Measure on `add_circle T`\n\nIn this file we use the Haar measure on `add_circle T` normalised to have total measure 1 (which is\n**not** the same as the standard measure defined in `topology.instances.add_circle`). -/\n\n\nvariable [hT : Fact (0 < T)]\n\ninclude hT\n\n/-- Haar measure on the additive circle, normalised to have total measure 1. -/\ndef haarAddCircle : Measure (AddCircle T) :=\n  add_haar_measure ⊤deriving IsAddHaarMeasure\n#align add_circle.haar_add_circle AddCircle.haarAddCircle\n\ninstance : IsProbabilityMeasure (@haarAddCircle T _) :=\n  IsProbabilityMeasure.mk add_haar_measure_self\n\ntheorem volume_eq_smul_haarAddCircle :\n    (volume : Measure (AddCircle T)) = ENNReal.ofReal T • haarAddCircle :=\n  rfl\n#align add_circle.volume_eq_smul_haar_add_circle AddCircle.volume_eq_smul_haarAddCircle\n\nend AddCircle\n\nopen AddCircle\n\nsection Monomials\n\n/-- The family of exponential monomials `λ x, exp (2 π i n x / T)`, parametrized by `n : ℤ` and\nconsidered as bundled continuous maps from `ℝ / ℤ • T` to `ℂ`. -/\ndef fourier (n : ℤ) : C(AddCircle T, ℂ)\n    where\n  toFun x := toCircle (n • x)\n  continuous_toFun := continuous_induced_dom.comp <| continuous_toCircle.comp <| continuous_zsmul _\n#align fourier fourier\n\n@[simp]\ntheorem fourier_apply {n : ℤ} {x : AddCircle T} : fourier n x = toCircle (n • x) :=\n  rfl\n#align fourier_apply fourier_apply\n\n@[simp]\ntheorem fourier_coe_apply {n : ℤ} {x : ℝ} :\n    fourier n (x : AddCircle T) = Complex.exp (2 * π * Complex.I * n * x / T) :=\n  by\n  rw [fourier_apply, ← QuotientAddGroup.mk_zsmul, to_circle, Function.Periodic.lift_coe,\n    expMapCircle_apply, Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_mul, zsmul_eq_mul,\n    Complex.ofReal_mul, Complex.ofReal_int_cast, Complex.ofReal_bit0, Complex.ofReal_one]\n  congr 1; ring\n#align fourier_coe_apply fourier_coe_apply\n\n@[simp]\ntheorem fourier_zero {x : AddCircle T} : fourier 0 x = 1 :=\n  by\n  induction x using QuotientAddGroup.induction_on'\n  simp only [fourier_coe_apply, algebraMap.coe_zero, MulZeroClass.mul_zero, MulZeroClass.zero_mul,\n    zero_div, Complex.exp_zero]\n#align fourier_zero fourier_zero\n\n@[simp]\ntheorem fourier_eval_zero (n : ℤ) : fourier n (0 : AddCircle T) = 1 := by\n  rw [← QuotientAddGroup.mk_zero, fourier_coe_apply, Complex.ofReal_zero, MulZeroClass.mul_zero,\n    zero_div, Complex.exp_zero]\n#align fourier_eval_zero fourier_eval_zero\n\n@[simp]\ntheorem fourier_one {x : AddCircle T} : fourier 1 x = toCircle x := by rw [fourier_apply, one_zsmul]\n#align fourier_one fourier_one\n\n@[simp]\ntheorem fourier_neg {n : ℤ} {x : AddCircle T} : fourier (-n) x = conj (fourier n x) :=\n  by\n  induction x using QuotientAddGroup.induction_on'\n  simp_rw [fourier_apply, to_circle, ← QuotientAddGroup.mk_zsmul, Function.Periodic.lift_coe, ←\n    coe_inv_circle_eq_conj, ← expMapCircle_neg, neg_smul, mul_neg]\n#align fourier_neg fourier_neg\n\n@[simp]\ntheorem fourier_add {m n : ℤ} {x : AddCircle T} : fourier (m + n) x = fourier m x * fourier n x :=\n  by simp_rw [fourier_apply, add_zsmul, to_circle_add, coe_mul_unitSphere]\n#align fourier_add fourier_add\n\ntheorem fourier_norm [Fact (0 < T)] (n : ℤ) : ‖@fourier T n‖ = 1 :=\n  by\n  rw [ContinuousMap.norm_eq_supᵢ_norm]\n  have : ∀ x : AddCircle T, ‖fourier n x‖ = 1 := fun x => abs_coe_circle _\n  simp_rw [this]\n  exact @csupᵢ_const _ _ _ Zero.nonempty _\n#align fourier_norm fourier_norm\n\n/-- For `n ≠ 0`, a translation by `T / 2 / n` negates the function `fourier n`. -/\ntheorem fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (hT : 0 < T) (x : AddCircle T) :\n    fourier n (x + (T / 2 / n : ℝ)) = -fourier n x :=\n  by\n  rw [fourier_apply, zsmul_add, ← QuotientAddGroup.mk_zsmul, to_circle_add, coe_mul_unitSphere]\n  have : (n : ℂ) ≠ 0 := by simpa using hn\n  have : (@to_circle T (n • (T / 2 / n) : ℝ) : ℂ) = -1 :=\n    by\n    rw [zsmul_eq_mul, to_circle, Function.Periodic.lift_coe, expMapCircle_apply]\n    replace hT := complex.of_real_ne_zero.mpr hT.ne'\n    convert Complex.exp_pi_mul_i using 3\n    field_simp\n    ring\n  rw [this]\n  simp\n#align fourier_add_half_inv_index fourier_add_half_inv_index\n\n/-- The subalgebra of `C(add_circle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` . -/\ndef fourierSubalgebra : Subalgebra ℂ C(AddCircle T, ℂ) :=\n  Algebra.adjoin ℂ (range fourier)\n#align fourier_subalgebra fourierSubalgebra\n\n/-- The subalgebra of `C(add_circle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is in fact the\nlinear span of these functions. -/\ntheorem fourierSubalgebra_coe : (@fourierSubalgebra T).toSubmodule = span ℂ (range fourier) :=\n  by\n  apply adjoin_eq_span_of_subset\n  refine' subset.trans _ Submodule.subset_span\n  intro x hx\n  apply Submonoid.closure_induction hx (fun _ => id) ⟨0, _⟩\n  · rintro _ _ ⟨m, rfl⟩ ⟨n, rfl⟩\n    refine' ⟨m + n, _⟩\n    ext1 z\n    exact fourier_add\n  · ext1 z\n    exact fourier_zero\n#align fourier_subalgebra_coe fourierSubalgebra_coe\n\n/-- The subalgebra of `C(add_circle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is invariant under\ncomplex conjugation. -/\ntheorem fourierSubalgebra_conj_invariant :\n    ConjInvariantSubalgebra ((@fourierSubalgebra T).restrictScalars ℝ) :=\n  by\n  apply subalgebra_conj_invariant\n  rintro _ ⟨n, rfl⟩\n  exact ⟨-n, ext fun _ => fourier_neg⟩\n#align fourier_subalgebra_conj_invariant fourierSubalgebra_conj_invariant\n\nvariable [hT : Fact (0 < T)]\n\ninclude hT\n\n/-- The subalgebra of `C(add_circle T, ℂ)` generated by `fourier n` for `n ∈ ℤ`\nseparates points. -/\ntheorem fourierSubalgebra_separatesPoints : (@fourierSubalgebra T).SeparatesPoints :=\n  by\n  intro x y hxy\n  refine' ⟨_, ⟨fourier 1, subset_adjoin ⟨1, rfl⟩, rfl⟩, _⟩\n  dsimp only; rw [fourier_one, fourier_one]\n  contrapose! hxy\n  rw [Subtype.coe_inj] at hxy\n  exact injective_to_circle hT.elim.ne' hxy\n#align fourier_subalgebra_separates_points fourierSubalgebra_separatesPoints\n\n/-- The subalgebra of `C(add_circle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is dense. -/\ntheorem fourierSubalgebra_closure_eq_top : (@fourierSubalgebra T).topologicalClosure = ⊤ :=\n  ContinuousMap.subalgebra_isROrC_topologicalClosure_eq_top_of_separatesPoints fourierSubalgebra\n    fourierSubalgebra_separatesPoints fourierSubalgebra_conj_invariant\n#align fourier_subalgebra_closure_eq_top fourierSubalgebra_closure_eq_top\n\n/-- The linear span of the monomials `fourier n` is dense in `C(add_circle T, ℂ)`. -/\ntheorem span_fourier_closure_eq_top : (span ℂ (range <| @fourier T)).topologicalClosure = ⊤ :=\n  by\n  rw [← fourierSubalgebra_coe]\n  exact congr_arg Subalgebra.toSubmodule fourierSubalgebra_closure_eq_top\n#align span_fourier_closure_eq_top span_fourier_closure_eq_top\n\n/-- The family of monomials `fourier n`, parametrized by `n : ℤ` and considered as\nelements of the `Lp` space of functions `add_circle T → ℂ`. -/\nabbrev fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : lp ℂ p (@haarAddCircle T hT) :=\n  toLp p haarAddCircle ℂ (fourier n)\n#align fourier_Lp fourierLp\n\ntheorem coeFn_fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) :\n    @fourierLp T hT p _ n =ᵐ[haarAddCircle] fourier n :=\n  coeFn_toLp haarAddCircle (fourier n)\n#align coe_fn_fourier_Lp coeFn_fourierLp\n\n/-- For each `1 ≤ p < ∞`, the linear span of the monomials `fourier n` is dense in\n`Lp ℂ p haar_circle`. -/\ntheorem span_fourierLp_closure_eq_top {p : ℝ≥0∞} [Fact (1 ≤ p)] (hp : p ≠ ∞) :\n    (span ℂ (range (@fourierLp T _ p _))).topologicalClosure = ⊤ :=\n  by\n  convert(ContinuousMap.toLp_denseRange ℂ hp (@haar_add_circle T hT)\n          ℂ).topologicalClosure_map_submodule\n      span_fourier_closure_eq_top\n  rw [map_span, range_comp]\n  simp only [ContinuousLinearMap.coe_coe]\n#align span_fourier_Lp_closure_eq_top span_fourierLp_closure_eq_top\n\n/-- The monomials `fourier n` are an orthonormal set with respect to normalised Haar measure. -/\ntheorem orthonormal_fourier : Orthonormal ℂ (@fourierLp T _ 2 _) :=\n  by\n  rw [orthonormal_iff_ite]\n  intro i j\n  rw [continuous_map.inner_to_Lp (@haar_add_circle T hT) (fourier i) (fourier j)]\n  simp_rw [← fourier_neg, ← fourier_add]\n  split_ifs\n  · simp_rw [h, neg_add_self]\n    have : ⇑(@fourier T 0) = (fun x => 1 : AddCircle T → ℂ) :=\n      by\n      ext1\n      exact fourier_zero\n    rw [this, integral_const, measure_univ, ENNReal.one_toReal, Complex.real_smul,\n      Complex.ofReal_one, mul_one]\n  have hij : -i + j ≠ 0 := by\n    rw [add_comm]\n    exact sub_ne_zero.mpr (Ne.symm h)\n  convert integral_eq_zero_of_add_right_eq_neg (fourier_add_half_inv_index hij hT.elim)\n  exact IsAddLeftInvariant.is_add_right_invariant\n#align orthonormal_fourier orthonormal_fourier\n\nend Monomials\n\nsection ScopeHT\n\n-- everything from here on needs `0 < T`\nvariable [hT : Fact (0 < T)]\n\ninclude hT\n\nsection fourierCoeff\n\nvariable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E]\n\n/-- The `n`-th Fourier coefficient of a function `add_circle T → E`, for `E` a complete normed\n`ℂ`-vector space, defined as the integral over `add_circle T` of `fourier (-n) t • f t`. -/\ndef fourierCoeff (f : AddCircle T → E) (n : ℤ) : E :=\n  ∫ t : AddCircle T, fourier (-n) t • f t ∂haarAddCircle\n#align fourier_coeff fourierCoeff\n\n/-- The Fourier coefficients of a function on `add_circle T` can be computed as an integral\nover `[a, a + T]`, for any real `a`. -/\ntheorem fourierCoeff_eq_intervalIntegral (f : AddCircle T → E) (n : ℤ) (a : ℝ) :\n    fourierCoeff f n = (1 / T) • ∫ x in a..a + T, @fourier T (-n) x • f x :=\n  by\n  have : ∀ x : ℝ, @fourier T (-n) x • f x = (fun z : AddCircle T => @fourier T (-n) z • f z) x :=\n    by\n    intro x\n    rfl\n  simp_rw [this]\n  rw [fourierCoeff, AddCircle.intervalIntegral_preimage T a, volume_eq_smul_haar_add_circle,\n    integral_smul_measure, ENNReal.toReal_ofReal hT.out.le, ← smul_assoc, smul_eq_mul,\n    one_div_mul_cancel hT.out.ne', one_smul]\n#align fourier_coeff_eq_interval_integral fourierCoeff_eq_intervalIntegral\n\ntheorem fourierCoeff.const_smul (f : AddCircle T → E) (c : ℂ) (n : ℤ) :\n    fourierCoeff (c • f) n = c • fourierCoeff f n := by\n  simp_rw [fourierCoeff, Pi.smul_apply, ← smul_assoc, smul_eq_mul, mul_comm, ← smul_eq_mul,\n    smul_assoc, integral_smul]\n#align fourier_coeff.const_smul fourierCoeff.const_smul\n\ntheorem fourierCoeff.const_mul (f : AddCircle T → ℂ) (c : ℂ) (n : ℤ) :\n    fourierCoeff (fun x => c * f x) n = c * fourierCoeff f n :=\n  fourierCoeff.const_smul f c n\n#align fourier_coeff.const_mul fourierCoeff.const_mul\n\nomit hT\n\n/-- For a function on `ℝ`, the Fourier coefficients of `f` on `[a, b]` are defined as the\nFourier coefficients of the unique periodic function agreeing with `f` on `Ioc a b`. -/\ndef fourierCoeffOn {a b : ℝ} (hab : a < b) (f : ℝ → E) (n : ℤ) : E :=\n  haveI := Fact.mk (by linarith : 0 < b - a)\n  fourierCoeff (AddCircle.liftIoc (b - a) a f) n\n#align fourier_coeff_on fourierCoeffOn\n\ntheorem fourierCoeffOn_eq_integral {a b : ℝ} (f : ℝ → E) (n : ℤ) (hab : a < b) :\n    fourierCoeffOn hab f n =\n      (1 / (b - a)) • ∫ x in a..b, fourier (-n) (x : AddCircle (b - a)) • f x :=\n  by\n  rw [fourierCoeffOn, fourierCoeff_eq_intervalIntegral _ _ a]\n  congr 1\n  rw [add_sub, add_sub_cancel']\n  simp_rw [intervalIntegral.integral_of_le hab.le]\n  refine' set_integral_congr measurableSet_Ioc fun x hx => _\n  dsimp only\n  rwa [lift_Ioc_coe_apply]\n  rwa [add_sub, add_sub_cancel']\n#align fourier_coeff_on_eq_integral fourierCoeffOn_eq_integral\n\ntheorem fourierCoeffOn.const_smul {a b : ℝ} (f : ℝ → E) (c : ℂ) (n : ℤ) (hab : a < b) :\n    fourierCoeffOn hab (c • f) n = c • fourierCoeffOn hab f n := by apply fourierCoeff.const_smul\n#align fourier_coeff_on.const_smul fourierCoeffOn.const_smul\n\ntheorem fourierCoeffOn.const_mul {a b : ℝ} (f : ℝ → ℂ) (c : ℂ) (n : ℤ) (hab : a < b) :\n    fourierCoeffOn hab (fun x => c * f x) n = c * fourierCoeffOn hab f n :=\n  fourierCoeffOn.const_smul _ _ _ _\n#align fourier_coeff_on.const_mul fourierCoeffOn.const_mul\n\ninclude hT\n\ntheorem fourierCoeff_liftIoc_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) :\n    fourierCoeff (AddCircle.liftIoc T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n :=\n  by\n  rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral, add_sub_cancel' a T]\n  congr 1\n  refine' intervalIntegral.integral_congr_ae (ae_of_all _ fun x hx => _)\n  rw [lift_Ioc_coe_apply]\n  rwa [uIoc_of_le (lt_add_of_pos_right a hT.out).le] at hx\n#align fourier_coeff_lift_Ioc_eq fourierCoeff_liftIoc_eq\n\ntheorem fourierCoeff_liftIco_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) :\n    fourierCoeff (AddCircle.liftIco T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n :=\n  by\n  rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral _ _ a, add_sub_cancel' a T]\n  congr 1\n  simp_rw [intervalIntegral.integral_of_le (lt_add_of_pos_right a hT.out).le,\n    integral_Ioc_eq_integral_Ioo]\n  refine' set_integral_congr measurableSet_Ioo fun x hx => _\n  dsimp only\n  rw [lift_Ico_coe_apply (Ioo_subset_Ico_self hx)]\n#align fourier_coeff_lift_Ico_eq fourierCoeff_liftIco_eq\n\nend fourierCoeff\n\nsection FourierL2\n\n/-- We define `fourier_basis` to be a `ℤ`-indexed Hilbert basis for `Lp ℂ 2 haar_add_circle`,\nwhich by definition is an isometric isomorphism from `Lp ℂ 2 haar_add_circle` to `ℓ²(ℤ, ℂ)`. -/\ndef fourierBasis : HilbertBasis ℤ ℂ (lp ℂ 2 <| @haarAddCircle T hT) :=\n  HilbertBasis.mk orthonormal_fourier (span_fourierLp_closure_eq_top (by norm_num)).ge\n#align fourier_basis fourierBasis\n\n/-- The elements of the Hilbert basis `fourier_basis` are the functions `fourier_Lp 2`, i.e. the\nmonomials `fourier n` on the circle considered as elements of `L²`. -/\n@[simp]\ntheorem coe_fourierBasis : ⇑(@fourierBasis _ hT) = fourierLp 2 :=\n  HilbertBasis.coe_mk _ _\n#align coe_fourier_basis coe_fourierBasis\n\n/-- Under the isometric isomorphism `fourier_basis` from `Lp ℂ 2 haar_circle` to `ℓ²(ℤ, ℂ)`, the\n`i`-th coefficient is `fourier_coeff f i`, i.e., the integral over `add_circle T` of\n`λ t, fourier (-i) t * f t` with respect to the Haar measure of total mass 1. -/\ntheorem fourierBasis_repr (f : lp ℂ 2 <| @haarAddCircle T hT) (i : ℤ) :\n    fourierBasis.repr f i = fourierCoeff f i :=\n  by\n  trans ∫ t : AddCircle T, conj ((@fourierLp T hT 2 _ i : AddCircle T → ℂ) t) * f t ∂haar_add_circle\n  · simp [fourier_basis.repr_apply_apply f i, MeasureTheory.L2.inner_def]\n  · apply integral_congr_ae\n    filter_upwards [coeFn_fourierLp 2 i]with _ ht\n    rw [ht, ← fourier_neg, smul_eq_mul]\n#align fourier_basis_repr fourierBasis_repr\n\n/-- The Fourier series of an `L2` function `f` sums to `f`, in the `L²` space of `add_circle T`. -/\ntheorem hasSum_fourier_series_L2 (f : lp ℂ 2 <| @haarAddCircle T hT) :\n    HasSum (fun i => fourierCoeff f i • fourierLp 2 i) f :=\n  by\n  simp_rw [← fourierBasis_repr]\n  simpa using HilbertBasis.hasSum_repr fourierBasis f\n#align has_sum_fourier_series_L2 hasSum_fourier_series_L2\n\n/-- **Parseval's identity**: for an `L²` function `f` on `add_circle T`, the sum of the squared\nnorms of the Fourier coefficients equals the `L²` norm of `f`. -/\ntheorem tsum_sq_fourierCoeff (f : lp ℂ 2 <| @haarAddCircle T hT) :\n    (∑' i : ℤ, ‖fourierCoeff f i‖ ^ 2) = ∫ t : AddCircle T, ‖f t‖ ^ 2 ∂haarAddCircle :=\n  by\n  simp_rw [← fourierBasis_repr]\n  have H₁ : ‖fourier_basis.repr f‖ ^ 2 = ∑' i, ‖fourier_basis.repr f i‖ ^ 2 :=\n    by\n    exact_mod_cast lp.norm_rpow_eq_tsum _ (fourier_basis.repr f)\n    norm_num\n  have H₂ : ‖fourier_basis.repr f‖ ^ 2 = ‖f‖ ^ 2 := by simp\n  have H₃ := congr_arg IsROrC.re (@L2.inner_def (AddCircle T) ℂ ℂ _ _ _ _ _ f f)\n  rw [← integral_re] at H₃\n  · simp only [← norm_sq_eq_inner] at H₃\n    rw [← H₁, H₂, H₃]\n  · exact L2.integrable_inner f f\n#align tsum_sq_fourier_coeff tsum_sq_fourierCoeff\n\nend FourierL2\n\nsection Convergence\n\nvariable (f : C(AddCircle T, ℂ))\n\ntheorem fourierCoeff_toLp (n : ℤ) : fourierCoeff (toLp 2 haarAddCircle ℂ f) n = fourierCoeff f n :=\n  integral_congr_ae\n    (Filter.EventuallyEq.mul (Filter.eventually_of_forall (by tauto))\n      (ContinuousMap.coeFn_toAeEqFun haarAddCircle f))\n#align fourier_coeff_to_Lp fourierCoeff_toLp\n\nvariable {f}\n\n/-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series converges\nuniformly to `f`. -/\ntheorem hasSum_fourier_series_of_summable (h : Summable (fourierCoeff f)) :\n    HasSum (fun i => fourierCoeff f i • fourier i) f :=\n  by\n  have sum_L2 := hasSum_fourier_series_L2 (to_Lp 2 haar_add_circle ℂ f)\n  simp_rw [fourierCoeff_toLp] at sum_L2\n  refine' ContinuousMap.hasSum_of_hasSum_lp (summable_of_summable_norm _) sum_L2\n  simp_rw [norm_smul, fourier_norm, mul_one, summable_norm_iff]\n  exact h\n#align has_sum_fourier_series_of_summable hasSum_fourier_series_of_summable\n\n/-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series of `f`\nconverges everywhere pointwise to `f`. -/\ntheorem has_pointwise_sum_fourier_series_of_summable (h : Summable (fourierCoeff f))\n    (x : AddCircle T) : HasSum (fun i => fourierCoeff f i • fourier i x) (f x) :=\n  (ContinuousMap.evalClm ℂ x).HasSum (hasSum_fourier_series_of_summable h)\n#align has_pointwise_sum_fourier_series_of_summable has_pointwise_sum_fourier_series_of_summable\n\nend Convergence\n\nend ScopeHT\n\nsection deriv\n\nopen Complex intervalIntegral\n\nopen Interval\n\nvariable (T)\n\ntheorem hasDerivAt_fourier (n : ℤ) (x : ℝ) :\n    HasDerivAt (fun y : ℝ => fourier n (y : AddCircle T))\n      (2 * π * I * n / T * fourier n (x : AddCircle T)) x :=\n  by\n  simp_rw [fourier_coe_apply]\n  refine' (_ : HasDerivAt (fun y => exp (2 * π * I * n * y / T)) _ _).comp_of_real\n  rw [(fun α β => by ring : ∀ α β : ℂ, α * exp β = exp β * α)]\n  refine' (has_deriv_at_exp _).comp x _\n  convert hasDerivAt_mul_const (2 * ↑π * I * ↑n / T)\n  ext1 y; ring\n#align has_deriv_at_fourier hasDerivAt_fourier\n\ntheorem hasDerivAt_fourier_neg (n : ℤ) (x : ℝ) :\n    HasDerivAt (fun y : ℝ => fourier (-n) (y : AddCircle T))\n      (-2 * π * I * n / T * fourier (-n) (x : AddCircle T)) x :=\n  by simpa using hasDerivAt_fourier T (-n) x\n#align has_deriv_at_fourier_neg hasDerivAt_fourier_neg\n\nvariable {T}\n\ntheorem has_antideriv_at_fourier_neg (hT : Fact (0 < T)) {n : ℤ} (hn : n ≠ 0) (x : ℝ) :\n    HasDerivAt (fun y : ℝ => (T : ℂ) / (-2 * π * I * n) * fourier (-n) (y : AddCircle T))\n      (fourier (-n) (x : AddCircle T)) x :=\n  by\n  convert(hasDerivAt_fourier_neg T n x).div_const (-2 * π * I * n / T) using 1\n  · ext1 y\n    rw [div_div_eq_mul_div]\n    ring\n  · rw [mul_div_cancel_left]\n    simp only [Ne.def, div_eq_zero_iff, neg_eq_zero, mul_eq_zero, bit0_eq_zero, one_ne_zero,\n      of_real_eq_zero, false_or_iff, Int.cast_eq_zero, not_or]\n    exact ⟨⟨⟨Real.pi_ne_zero, I_ne_zero⟩, hn⟩, hT.out.ne'⟩\n#align has_antideriv_at_fourier_neg has_antideriv_at_fourier_neg\n\n/-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/\ntheorem fourierCoeffOn_of_hasDerivAt {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ} {n : ℤ} (hn : n ≠ 0)\n    (hf : ∀ x, x ∈ [a, b] → HasDerivAt f (f' x) x) (hf' : IntervalIntegrable f' volume a b) :\n    fourierCoeffOn hab f n =\n      1 / (-2 * π * I * n) *\n        (fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) :=\n  by\n  rw [← of_real_sub]\n  have hT : Fact (0 < b - a) := ⟨by linarith⟩\n  simp_rw [fourierCoeffOn_eq_integral, smul_eq_mul, real_smul, of_real_div, of_real_one]\n  conv => pattern (occs := 1 2 3) fourier _ _ * _ <;> (rw [mul_comm])\n  rw [integral_mul_deriv_eq_deriv_mul hf (fun x hx => has_antideriv_at_fourier_neg hT hn x) hf'\n      (((map_continuous (fourier (-n))).comp (AddCircle.continuous_mk' _)).IntervalIntegrable _ _)]\n  dsimp only\n  have : ∀ u v w : ℂ, u * ((b - a : ℝ) / v * w) = (b - a : ℝ) / v * (u * w) :=\n    by\n    intros\n    ring\n  conv in intervalIntegral _ _ _ _ =>\n    congr\n    ext\n    rw [this]\n  rw [(by ring : ((b - a : ℝ) : ℂ) / (-2 * π * I * n) = ((b - a : ℝ) : ℂ) * (1 / (-2 * π * I * n)))]\n  have s2 : (b : AddCircle (b - a)) = (a : AddCircle (b - a)) := by\n    simpa using coe_add_period (b - a) a\n  rw [s2, integral_const_mul, ← sub_mul, mul_sub, mul_sub]\n  congr 1\n  · conv_lhs => rw [mul_comm, mul_div, mul_one]\n    rw [div_eq_iff (of_real_ne_zero.mpr hT.out.ne')]\n    ring\n  · ring\n#align fourier_coeff_on_of_has_deriv_at fourierCoeffOn_of_hasDerivAt\n\nend deriv\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/Fourier/AddCircle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7589127687472577}}
{"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.matrix.basic\nimport linear_algebra.matrix.determinant\nimport linear_algebra.matrix.adjugate\n\n/-!\n# Matrices associated with non-degenerate bilinear forms\n\n## Main definitions\n\n* `matrix.nondegenerate A`: the proposition that when interpreted as a bilinear form, the matrix `A`\n  is nondegenerate.\n\n-/\n\nnamespace matrix\n\nvariables {m R A : Type*} [fintype m] [comm_ring R]\n\n/-- A matrix `M` is nondegenerate if for all `v ≠ 0`, there is a `w ≠ 0` with `w ⬝ M ⬝ v ≠ 0`. -/\ndef nondegenerate (M : matrix m m R) :=\n∀ v, (∀ w, matrix.dot_product v (mul_vec M w) = 0) → v = 0\n\n/-- If `M` is nondegenerate and `w ⬝ M ⬝ v = 0` for all `w`, then `v = 0`. -/\nlemma nondegenerate.eq_zero_of_ortho {M : matrix m m R} (hM : nondegenerate M)\n  {v : m → R} (hv : ∀ w, matrix.dot_product v (mul_vec M w) = 0) : v = 0 :=\nhM v hv\n\n/-- If `M` is nondegenerate and `v ≠ 0`, then there is some `w` such that `w ⬝ M ⬝ v ≠ 0`. -/\nlemma nondegenerate.exists_not_ortho_of_ne_zero {M : matrix m m R} (hM : nondegenerate M)\n  {v : m → R} (hv : v ≠ 0) : ∃ w, matrix.dot_product v (mul_vec M w) ≠ 0 :=\nnot_forall.mp (mt hM.eq_zero_of_ortho hv)\n\nvariables [comm_ring A] [is_domain A]\n\n/-- If `M` has a nonzero determinant, then `M` as a bilinear form on `n → A` is nondegenerate.\n\nSee also `bilin_form.nondegenerate_of_det_ne_zero'` and `bilin_form.nondegenerate_of_det_ne_zero`.\n-/\ntheorem nondegenerate_of_det_ne_zero [decidable_eq m] {M : matrix m m A} (hM : M.det ≠ 0) :\n  nondegenerate M :=\nbegin\n  intros v hv,\n  ext i,\n  specialize hv (M.cramer (pi.single i 1)),\n  refine (mul_eq_zero.mp _).resolve_right hM,\n  convert hv,\n  simp only [mul_vec_cramer M (pi.single i 1), dot_product, pi.smul_apply, smul_eq_mul],\n  rw [finset.sum_eq_single i, pi.single_eq_same, mul_one],\n  { intros j _ hj, simp [hj] },\n  { intros, have := finset.mem_univ i, contradiction }\nend\n\ntheorem eq_zero_of_vec_mul_eq_zero [decidable_eq m] {M : matrix m m A} (hM : M.det ≠ 0) {v : m → A}\n  (hv : M.vec_mul v = 0) : v = 0 :=\n(nondegenerate_of_det_ne_zero hM).eq_zero_of_ortho\n  (λ w, by rw [dot_product_mul_vec, hv, zero_dot_product])\n\ntheorem eq_zero_of_mul_vec_eq_zero [decidable_eq m] {M : matrix m m A} (hM : M.det ≠ 0) {v : m → A}\n  (hv : M.mul_vec v = 0) :\n  v = 0 :=\neq_zero_of_vec_mul_eq_zero (by rwa det_transpose) ((vec_mul_transpose M v).trans hv)\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/nondegenerate.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.758912761634217}}
{"text": "import catalan\n\nopen finset catalan\n\n@[derive decidable_eq]\ninductive binary_tree\n| empty : binary_tree\n| branch : binary_tree → binary_tree → binary_tree\n\nnamespace binary_tree\n\ndef vertices : binary_tree → ℕ\n| empty := 0\n| (branch l r) := (vertices l) + (vertices r) + 1\n\n@[simp] def vertices_Empty : empty.vertices = 0 := rfl\n@[simp] def vertices_Branch (l r : binary_tree) : (branch l r).vertices = l.vertices + r.vertices + 1 := rfl\n\nlemma eq_Empty_of_vertices_zero {t : binary_tree} (h : t.vertices = 0) : t = empty := \nbegin\n  cases t with l r,\n  { refl },\n  { rw [vertices_Branch] at h, simpa only using h },\nend\n\nlemma eq_Branch_of_vertices_succ {n : ℕ} {t : binary_tree} (h : t.vertices = n.succ) : \n  ∃ l r, t = branch l r := \nbegin\n  cases t with l r,\n  { rw [vertices_Empty] at h, simpa only using h},\n  { use [l, r] },\nend\n\ndef all_trees : Π (n : ℕ), finset binary_tree\n| 0 := ({ empty } : finset binary_tree)\n| (n + 1) := \n  finset.bUnion (finset.nat.antidiagonal n) $\n  λ p, if h : p.1 + p.2 = n then\n    let h₁ : p.1 < n + 1 := nat.lt_succ_of_add_right_eq h in\n    let h₂ : p.2 < n + 1 := nat.lt_succ_of_add_left_eq h in\n      finset.image \n      (λ i : binary_tree × binary_tree, branch i.1 i.2)\n      (finset.product (all_trees p.1) (all_trees p.2))\n    else ∅\n\n\n@[simp] lemma all_trees_zero : all_trees 0 = ({ empty } : finset binary_tree) := by rw all_trees\n@[simp] lemma all_trees_succ {n : ℕ} : all_trees n.succ = \n  (nat.antidiagonal n).bUnion\n    (λ p, finset.image (λ i : binary_tree × binary_tree, branch i.1 i.2) $ finset.product (all_trees p.1) (all_trees p.2)) := \nbegin\n  -- TODO: extract as bUnion_congr or something\n  rw [all_trees],\n  ext t, \n  simp only [mem_bUnion, mem_image, dite_eq_ite, exists_prop, nat.mem_antidiagonal, prod.exists, mem_product],\n  split,\n  {\n    rintro ⟨a, b, rfl, h⟩,\n    use [a, b, rfl],\n    simpa only [mem_image, exists_prop, if_pos rfl, prod.exists, mem_product] using h,\n  }, {\n    rintro ⟨a, b, rfl, h⟩,\n    use [a, b, rfl],\n    rw if_pos rfl,\n    simpa only [mem_image, exists_prop, prod.exists, mem_product] using h,\n  }\nend\n\ndef mem_all_trees {t : binary_tree} : t ∈ all_trees t.vertices :=\nbegin\n  induction t with a b iha ihb, {\n    simp only [vertices_Empty, mem_singleton, all_trees_zero],    \n  }, {\n    simp only [mem_bUnion, mem_image, exists_prop, vertices_Branch, exists_eq_right_right, exists_eq_right, all_trees_succ,\n  nat.mem_antidiagonal, prod.exists, mem_product],\n    use [a.vertices, b.vertices, rfl],\n    exact ⟨iha, ihb⟩,\n  }\nend\n\ndef vertices_eq_of_mem_all_trees {t : binary_tree} {n : ℕ} (h : t ∈ all_trees n) : t.vertices = n :=\nbegin\n  induction t with a b iha ihb generalizing n, {\n    cases n, {\n      exact vertices_Empty,\n    }, {\n      simp [all_trees] at h,\n      rcases h with ⟨a, b, rfl, h⟩, \n      simpa only [if_pos rfl, mem_image, if_true, exists_false] using h,\n    }\n  }, {\n    cases n, {\n      simpa using h,\n    }, {\n      simp [all_trees] at h,\n      rcases h with ⟨x, y, rfl, h⟩,\n      simp only [mem_image, exists_prop, if_true, exists_eq_right_right, eq_self_iff_true, exists_eq_right, prod.exists, mem_product] at h,\n      rw [←iha h.1, ←ihb h.2],\n      exact vertices_Branch _ _,\n    }\n  }\nend\nend binary_tree\n\nopen binary_tree\n\nlemma all_trees_card_eq_catalan {n} : (all_trees n).card = catalan n :=\nbegin\n  apply nat.strong_induction_on n,\n  clear n,\n  rintro n ih,\n  cases n, {\n    rw [catalan_zero, all_trees_zero, card_singleton],\n  }, {\n    simp only [catalan_succ, all_trees_succ],\n    rw [card_bUnion], {\n      apply sum_congr rfl,\n      rintro ⟨a, b⟩ h,\n      rw nat.mem_antidiagonal at h,\n      rw [card_image_of_injective, card_product],\n      {\n        rw [ih _ $ nat.lt_succ_of_add_right_eq h],\n        rw [ih _ $ nat.lt_succ_of_add_left_eq h],\n      }, {\n        rintro a b,\n        simp only [and_imp],\n        exact prod.ext, \n      },\n    }, {\n      rintro x - y - hneq k hk,\n      simp only [mem_image, exists_prop, inf_eq_inter, mem_inter, prod.exists, mem_product] at hk,\n      rcases hk with ⟨⟨a1, b1, ha1, hc1⟩, ⟨a2, b2, ha2, rfl⟩⟩,\n      rcases branch.inj hc1 with ⟨rfl, rfl⟩,\n      apply hneq,\n      ext, {\n        rw [←vertices_eq_of_mem_all_trees ha1.1, ←vertices_eq_of_mem_all_trees ha2.1],\n      }, {\n        rw [←vertices_eq_of_mem_all_trees ha1.2, ←vertices_eq_of_mem_all_trees ha2.2],\n      },        \n    }\n  }\nend\n\ndef sized_binary_tree (n : ℕ) := {t : binary_tree // vertices t = n}\n@[simp] lemma sized_binary_tree_def {n : ℕ} : (sized_binary_tree n) = {t : binary_tree // vertices t = n} := rfl\n\ninstance {n : ℕ} : fintype (sized_binary_tree n) :=\n  ⟨(all_trees n).subtype (λ t, t.vertices = n), \n  begin\n    rintro ⟨t, rfl⟩,\n    rw mem_subtype,\n    exact mem_all_trees,\n  end⟩\n\nlemma catalan_eq_TreeN_card {n : ℕ} : fintype.card (sized_binary_tree n) = catalan n :=\nbegin\n  rw [←all_trees_card_eq_catalan],\n  apply fintype.card_of_subtype,\n  intro x,\n  split, {\n    exact vertices_eq_of_mem_all_trees,\n  }, {\n    rintro rfl,\n    exact mem_all_trees,\n  }\nend", "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/binary_tree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.758875169890853}}
{"text": "-- División de una suma\n-- ====================\n\nimport tactic\nimport data.nat.modeq\n\n-- 1ª demostración\nexample\n  (a b c : ℕ)\n  (hca : c ∣ a)\n  (hba : c ∣ b)\n  : (a+b)/c=a/c+b/c :=\nbegin\n  cases le_or_gt c 0 with hc hc,\n  { rw nat.le_zero_iff at hc,\n    rw hc,\n    simp only [nat.div_zero] },\n  { rw [nat.add_div hc, if_neg, add_zero],\n    rw [nat.mod_eq_zero_of_dvd hca, nat.mod_eq_zero_of_dvd hba, add_zero],\n    exact hc.lt.not_le, },\nend\n\n-- 2ª demostración\nexample\n  (a b c : ℕ)\n  (hca : c ∣ a)\n  (hba : c ∣ b)\n  : (a+b)/c=a/c+b/c :=\nif h : c = 0\nthen by simp [h]\nelse nat.add_div_eq_of_add_mod_lt\nbegin\n  rw [nat.mod_eq_zero_of_dvd hca,\n      nat.mod_eq_zero_of_dvd hba,\n      zero_add],\n  exact nat.pos_of_ne_zero h,\nend\n\n-- ---------------------------------------------------------------------\n\nlemma add_div_of_dvd_right\n  {a b c : ℤ}\n  (H : c ∣ 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 ≠ 0 at h1,\n    rw [mul_comm c k,\n        int.add_mul_div_right _ _ h1,\n        ← zero_add (k * c),\n        int.add_mul_div_right _ _ h1,\n        int.zero_div,\n        zero_add]},\nend\n\n-- ------------------------------------------------------------------------\n\nexample\n  {a b c : ℤ}\n  (H : c ∣ a) :\n  (a + b) / c = a / c + b / c :=\nby rw [add_comm,\n       add_div_of_dvd_right H,\n       add_comm]\n\n-- ---------------------------------------------------------------------\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/Division_de_una_suma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7588403351728977}}
{"text": "-- Cuadrado_del_binomio.lean\n-- Cuadrado del binomio.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 24-agosto-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si a y b son números reales, entonces\n--    (a + b) * (a + b) = a * a + 2 * (a * b) + b * b\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b : ℝ\n\n-- 1ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\ncalc\n  (a + b) * (a + b)\n      = (a + b) * a + (a + b) * b       : by rw mul_add\n  ... = a * a + b * a + (a + b) * b     : by rw add_mul\n  ... = a * a + b * a + (a * b + b * b) : by rw add_mul\n  ... = a * a + b * a + a * b + b * b   : by rw ← add_assoc\n  ... = a * a + (b * a + a * b) + b * b : by rw add_assoc (a * a)\n  ... = a * a + (a * b + a * b) + b * b : by rw mul_comm b a\n  ... = a * a + 2 * (a * b) + b * b     : by rw ← two_mul\n\n-- 2ª demostración\n-- ===============\n\nexample :\n  (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) : by rw [mul_add, add_mul, add_mul]\n  ... = a * a + (b * a + a * b) + b * b : by rw [←add_assoc, add_assoc (a * a)]\n  ... = a * a + 2 * (a * b) + b * b     : by rw [mul_comm b a, ←two_mul]\n\n-- 3ª demostración\n-- ===============\n\nexample :\n  (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) : by ring\n  ... = a * a + (b * a + a * b) + b * b : by ring\n  ... = a * a + 2 * (a * b) + b * b     : by ring\n\n-- 4ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nby ring\n\n-- 5ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw mul_add,\n  rw add_mul,\n  rw add_mul,\n  rw ← add_assoc,\n  rw add_assoc (a * a),\n  rw mul_comm b a,\n  rw ← two_mul,\nend\n\n-- 6ª demostración\n-- ===============\n\nexample :\n  (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=\nbegin\n  rw [mul_add, add_mul, add_mul],\n  rw [←add_assoc, add_assoc (a * a)],\n  rw [mul_comm b a, ←two_mul],\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/Cuadrado_del_binomio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7587951674727627}}
{"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 {α β γ : Type*}\n\nnamespace finset\nopen multiset\n\nvariables [cancel_comm_monoid_with_zero α] [normalized_gcd_monoid α]\n\n/-! ### lcm -/\nsection lcm\n\n/-- Least common multiple of a finite set -/\ndef lcm (s : finset β) (f : β → α) : α := s.fold gcd_monoid.lcm 1 f\n\nvariables {s s₁ s₂ : finset β} {f : β → α}\n\nlemma lcm_def : s.lcm f = (s.1.map f).lcm := rfl\n\n@[simp] lemma lcm_empty : (∅ : finset β).lcm f = 1 :=\nfold_empty\n\n@[simp] lemma lcm_dvd_iff {a : α} : s.lcm f ∣ a ↔ (∀b ∈ s, f b ∣ a) :=\nbegin\n  apply iff.trans multiset.lcm_dvd,\n  simp only [multiset.mem_map, and_imp, exists_imp_distrib],\n  exact ⟨λ k b hb, k _ _ hb rfl, λ k a' b hb h, h ▸ k _ hb⟩,\nend\n\nlemma lcm_dvd {a : α} : (∀b ∈ s, f b ∣ a) → s.lcm f ∣ a :=\nlcm_dvd_iff.2\n\nlemma dvd_lcm {b : β} (hb : b ∈ s) : f b ∣ s.lcm f :=\nlcm_dvd_iff.1 dvd_rfl _ hb\n\n@[simp] lemma lcm_insert [decidable_eq β] {b : β} :\n  (insert b s : finset β).lcm f = gcd_monoid.lcm (f b) (s.lcm f) :=\nbegin\n  by_cases h : b ∈ 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 : β} : ({b} : finset β).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 β] : (s₁ ∪ s₂).lcm f = gcd_monoid.lcm (s₁.lcm f) (s₂.lcm f) :=\nfinset.induction_on s₁ (by rw [empty_union, lcm_empty, lcm_one_left, normalize_lcm]) $ λ a s has ih,\n  by rw [insert_union, lcm_insert, lcm_insert, ih, lcm_assoc]\n\ntheorem lcm_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a ∈ s₂, f a = g a) :\n  s₁.lcm f = s₂.lcm g :=\nby { subst hs, exact finset.fold_congr hfg }\n\nlemma lcm_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.lcm f ∣ s.lcm g :=\nlcm_dvd (λ b hb, (h b hb).trans (dvd_lcm hb))\n\nlemma lcm_mono (h : s₁ ⊆ s₂) : s₁.lcm f ∣ s₂.lcm f :=\nlcm_dvd $ assume b hb, dvd_lcm (h hb)\n\ntheorem lcm_eq_zero_iff [nontrivial α] : s.lcm f = 0 ↔ 0 ∈ f '' s :=\nby simp only [multiset.mem_map, lcm_def, multiset.lcm_eq_zero_iff, set.mem_image, mem_coe,\n  ← finset.mem_def]\n\nend lcm\n\n/-! ### gcd -/\nsection gcd\n\n/-- Greatest common divisor of a finite set -/\ndef gcd (s : finset β) (f : β → α) : α := s.fold gcd_monoid.gcd 0 f\n\nvariables {s s₁ s₂ : finset β} {f : β → α}\n\nlemma gcd_def : s.gcd f = (s.1.map f).gcd := rfl\n\n@[simp] lemma gcd_empty : (∅ : finset β).gcd f = 0 :=\nfold_empty\n\nlemma dvd_gcd_iff {a : α} : a ∣ s.gcd f ↔ ∀b ∈ s, a ∣ f b :=\nbegin\n  apply iff.trans multiset.dvd_gcd,\n  simp only [multiset.mem_map, and_imp, exists_imp_distrib],\n  exact ⟨λ k b hb, k _ _ hb rfl, λ k a' b hb h, h ▸ k _ hb⟩,\nend\n\nlemma gcd_dvd {b : β} (hb : b ∈ s) : s.gcd f ∣ f b :=\ndvd_gcd_iff.1 dvd_rfl _ hb\n\nlemma dvd_gcd {a : α} : (∀b ∈ s, a ∣ f b) → a ∣ s.gcd f :=\ndvd_gcd_iff.2\n\n@[simp] lemma gcd_insert [decidable_eq β] {b : β} :\n  (insert b s : finset β).gcd f = gcd_monoid.gcd (f b) (s.gcd f) :=\nbegin\n  by_cases h : b ∈ 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 : β} : ({b} : finset β).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 β] : (s₁ ∪ s₂).gcd f = gcd_monoid.gcd (s₁.gcd f) (s₂.gcd f) :=\nfinset.induction_on s₁ (by rw [empty_union, gcd_empty, gcd_zero_left, normalize_gcd]) $\n  λ a s has ih, by rw [insert_union, gcd_insert, gcd_insert, ih, gcd_assoc]\n\ntheorem gcd_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a ∈ s₂, f a = g a) :\n  s₁.gcd f = s₂.gcd g :=\nby { subst hs, exact finset.fold_congr hfg }\n\nlemma gcd_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ∣ g b) : s.gcd f ∣ s.gcd g :=\ndvd_gcd (λ b hb, (gcd_dvd hb).trans (h b hb))\n\nlemma gcd_mono (h : s₁ ⊆ s₂) : s₂.gcd f ∣ s₁.gcd f :=\ndvd_gcd $ assume b hb, gcd_dvd (h hb)\n\ntheorem gcd_image {g : γ → β} (s: finset γ) [decidable_eq β] [is_idempotent α gcd_monoid.gcd] :\n  (s.image g).gcd f = s.gcd (f ∘ g) := by simp [gcd, fold_image_idem]\n\ntheorem gcd_eq_gcd_image [decidable_eq α] [is_idempotent α 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 ↔ ∀ (x : β), x ∈ s → 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 ⟨b, ⟨bs, rfl⟩⟩,\n    apply h b (mem_def.1 bs) }\nend\n\nlemma gcd_eq_gcd_filter_ne_zero [decidable_pred (λ (x : β), f x = 0)] :\n  s.gcd f = (s.filter (λ x, f x ≠ 0)).gcd f :=\nbegin\n  classical,\n  transitivity ((s.filter (λ x, f x = 0)) ∪ (s.filter (λ x, f x ≠ 0))).gcd f,\n  { rw filter_union_filter_neg_eq },\n  rw gcd_union,\n  transitivity gcd_monoid.gcd (0 : α) _,\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 : α} : s.gcd (λ 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, ← gcd_mul_left],\n  apply ((normalize_associated a).mul_right _).gcd_eq_right\nend\n\nlemma gcd_mul_right {a : α} : s.gcd (λ 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, ← 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 α] [is_domain α] [normalized_gcd_monoid α]\n\nlemma gcd_eq_of_dvd_sub {s : finset β} {f g : β → α} {a : α}\n  (h : ∀ x : β, x ∈ s → a ∣ 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), ← gcd_assoc, hi (λ 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": "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/gcd_monoid/finset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7587641286451953}}
{"text": "/-\nIn this file, we'll start to build a certified abstract\ndata type for the natural numbers. What we want is for\nour implementations to faithfully present the properties\nof natural numbers that we're familar with from highschool\nalgebra. For example, zero is a left identify for addition;\nzero is also a right identity; addition is associative and\ncommutative; the distributive law holds; etc. We'll get\nyou started, and you will then finish off development of\na certified abstract data type for natural numbers.\n-/\n\nnamespace hidden\n\n/-\nDATA TYPE\n-/\ninductive nt \n| zero\n| succ (n' : nt)\n\nopen nt \n\n/-\nSome example values of this type, with nice names.\n-/\ndef one := succ zero\ndef two := succ (succ zero)\ndef three := succ (succ (succ zero))\ndef four := succ three  -- works just fine\ndef five := succ four\ndef six := succ five\n\n-- tests\n#reduce four\n#reduce five\n#reduce six\n\n\n/-\nOPERATIONS\n-/\n\n-- COMPUTATIONAL\n\n/-\nThis implementation of the identity function can\nbe read as saying that id is a function from nt \nto nt, and in particular when applied to any\nargument, n, it returns n. Importantly, we don't\nneed to \"analyze/destructure\" n to decide what \nto return: we just return whatever we got. \n-/\ndef id : nt → nt \n| n := n\n\n-- we can compute results of evaluating applications\n#reduce (id two)\n\n/-\nWe can also write test cases as equality propositions\nthat assert that actual outputs are equal to expected\noutputs, with simple equality proofs. The failure of\nrfl here indicates that either the computation or the\ntest case is wrong.\n-/\nexample : id two = two := rfl\nexample : id three = two := rfl -- oops, bad test case\n\n/-\nA similar approaches works for defining increment.\n-/\ndef inc : nt → nt \n| n := succ n\n\n\n/-\nNext we'll look at the decrement function, defined\nmathemtically as mapping 0 to 0 and and any positive\nnatural number, n = n'+1, to n', i.e., to n-1. Make\nsure you understand what we just said! To implement\nthis function, we need to *analyze/destructure* the \nargument in order to determine if it's zero or some\nnon-zero number (which is to say, the successor of \nsome one-smaller natural number, n').\n-/\ndef dec : nt → nt \n| zero := zero \n| (succ n') := n'   -- you must understand this!\n\n-- tests\n#reduce dec two     -- expect one\n#reduce dec one     -- expect zero\n#reduce dec zero    -- expect zero\n\n/-\nTest cases as equality propositions for \nindividual inputs.\n-/\n\nexample : dec two = one := rfl\nexample : dec one = zero := rfl\nexample : dec zero = zero := rfl\n\n\n/-\nThe key to this definition is in the pattern match\nthat occurs in the second case. Take, for example,\nthe expression (dec two). To evaluate this we first\nevaluate the identifier expression, two, which then\nunfolds to (succ (succ zero)), then we do pattern\nmatching. This term does not match the term, zero,\nso Lean moves on to match it with (succ n'). \n\nThe essential technical concept at this point what\nwe call unification. Lean sees that the pattern, \n(succ n'), can be unified with (succ (succ zero)),\nwhere the \"succ\" in (succ n') matches the first\n\"succ\" in (succ (succ zero)), and where n' matches\nthe rest, namely (succ zero); and that n' is what\ngets returned. \n\nThe big idea is that you can use pattern matching\nto \"analyze\" a term (argument in this case), to pull \nit apart into subterms pieces, giving subterms names\n(here n') that we can then use to express the return\nresult to the right of the colon-equals separator.\n-/\n\n/-\nNext, we define an isZero \"predicate function\", a\nfunction that returns true if an argument has a\nparticular property (here that of being zero), or\nfalse if it doesn't. We again have to analyze the\nargument (doing a kind of case analysis). The one\nnew concept introduced here is that sometimes you\nwill want to match on any value of a given argument \nwithout giving it a name. This function matches on\nits argument to determine if it's zero, in which\ncase the function returns true, otherwise it just\nreturns false without further naming or analysis \nof the argument value.\n-/\ndef isZero : nt → bool\n| zero := tt \n| _ := ff\n\n/-\nAnother example of a function where there's no \nneed to analyze the argument: this function takes\na natural number and returns zero no matter what\nit is.\n-/\ndef const_zero : nt → nt \n| _ := zero\n\n/-\nAs an aside, it would be preferable for readability\nto use simpler syntax to define this function. Here\nis an alternative.\n-/\n\ndef const_zero' (n : nt) := zero\n\n-- some simple tests\n#check const_zero'\n#reduce const_zero' six -- expect zero\n\n\n-- binary operations\n\n/-\nAddition is defined as iterated application of the\nincrement (inc) function to the second argument the\nfirst argument number of times. For example, 3 + 2\nreduces to 1 + 1 + 1 + 2. That's three applications\nof inc to two. \n-/\ndef add : nt → nt → nt\n| zero m := m\n| (succ n') m := succ (add n' m)\n\n-- tests\n#reduce add two three                 -- check by eye\nexample : add two three = five := rfl -- prove it\n\n/-\nMultiplication implemented as iteration of \naddition of the second argument the first\nargument number of times. Note that iterating\nmultiplication 0 times is defined to be one,\nwhile iterating addition zero times is defined\nto be zero.\n-/\ndef mul : nt → nt → nt\n| zero m := zero\n| (succ n') m := add (mul n' m) m \n\n-- test\nexample : mul two three = six := rfl\n\n/-\nProblem: represent the square function\non natural numbers declaratively.\n-/\n\n/-\nExponentiation is defined to be iteration\nof multiplication of the first argument the\nsecond argument number of times. Take some\ntime to really study the similarities and\ndifferences in the definitions of add, mul,\nand exp.\n-/\ndef exp : nt → nt → nt\n| n zero := one\n| n (succ m') := mul n (exp n m')\n\n-- tests \nexample : exp two three = succ (succ six) := rfl\nexample : exp zero three = zero := rfl\nexample : exp three zero = one := rfl\n\n/-\nPROOFS OF PROPERTIES\n\nThere are many properties we can try to prove. As\na starter, let's try to prove that zero is a left\nidentity for addition.\n\ndef add : nt → nt → nt\n| zero m := m\n| (succ n') m := succ (add n' m)\n-/\nexample : ∀ (m : nt), add zero m = m := by simp [add] \n\n/-\nThe crucial point in this case is that we already\nknow that, ∀ (m : nt), add zero m = m, *from the \ndefinition of add*. In other words, add zero m is\n*definitionally* equal to m.\n\n  def add : nt → nt → nt\n  | zero m := m\n  | (succ n') m := succ (add n' m)\n\nThe first rule serves as an axiom that allows us\ninstantly to conclude that: ∀ m, add zero m = m. \nThe proof is by simply invoking this axiom, which\nwe do by using the simplify (simp) tactic in Lean,\npointing it to the definition whose rules we want\nit to employ.\n\nNote that \"by\" is a way of introducing a proof \nwritten using tactics without having the write \na complete \"begin ... end\" block.\n-/\n\n/-\nPerhaps somewhat surprisingly, we hit a roadblock when\nwe try to prove that zero is a *right* identity. We don't\nhave an axiom for that! Rather we'll need to prove it \nas a theorem.\n-/\nexample : ∀ (m : nt), add m zero = m := by simp [add] --fail\n/-\ndef add : nt → nt → nt\n| zero m := m\n| (succ n') m := succ (add n' m)\n-/\n\n-- Prove it!\ntheorem zero_is_right_zero : ∀ (m : nt), add m zero = m :=\nbegin\n  assume m,\n  induction m with m' h,  -- by induction!\n  simp [add],\n  simp [add],\n  exact h,\nend\n\n-- NOTATION\n\n/-\nA complete, beautiful, and highly usable \"module\"\nthat implements an algebraic structure, such as \nBoolean algebra or Peano arithmetic, often needs\nto introduce convenient *notations* for applying\noperations to arguments. We'd rather write (2 + 3)\nthan (nat.add zero.succ.succ zero.succ.succ.succ),\nfor example, even though we understand that they\nmean the same thing. \n\nIn Lean, we can overload operators, such as +, \nthat are already defined in Lean's libraries, \nand we will thereby inherit both precedence and\nassociativity properties that were carefully\ncrafted by the library designers. \n-/\n\nnotation x + y := add x y\nnotation x * y := mul x y\n\n#reduce five + six        -- expect 11 .succs of zero\n#reduce five * six + two  -- expect 32 .succs of zero\n\n-- Now we can use these notations in writing expressions\nexample : five + six = zero.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ.succ := rfl\n\n\n-- HOMEWORK\ntheorem add_commutes : ∀ (m n : nt), m + n = n + m :=\nbegin\n  assume m n,\n  induction m with m' h,\n  -- base case\n  -- exact rfl,   does NOT work\n  simp [add],\n  rw zero_is_right_zero,\n  -- inductive case\n  simp [add],\n  rw h,\n\n  -- \n  induction n with n' k,\n  --base case\n  rw <-h,\n  simp [add],\n  rw zero_is_right_zero,\n  --inductive case\n\nend\n\nend hidden", "meta": {"author": "kevinsullivan", "repo": "cs6501s22", "sha": "c55d342145b127e7b7bf396c660966034e80a944", "save_path": "github-repos/lean/kevinsullivan-cs6501s22", "path": "github-repos/lean/kevinsullivan-cs6501s22/cs6501s22-c55d342145b127e7b7bf396c660966034e80a944/src/content/project_1/nat.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7587641279125339}}
{"text": "import data.real.basic \nimport chris_hughes_various.exponential.exponential\n\ndefinition is_deriv (f : ℝ → ℝ) (x : ℝ) (d : ℝ) : Prop :=\n-- d = derivative of f at x\n-- limit of f(x+h)-f(x) / h = d as h tends to zero \n∀ ε > 0, ∃ δ > 0, ∀ h, abs h < δ ∧ h ≠ 0 → abs ((f (x + h) - f x) / h - d) < ε  \n--#print group\n\ndefinition is_differentiable_at (f : ℝ → ℝ) (x : ℝ) : Prop :=\n∃ d, is_deriv f x d\n\ndefinition is_differentiable_on (f : ℝ → ℝ) (X : set ℝ) : Prop :=\n∀ x ∈ X, is_differentiable_at f x\n\ndefinition is_differentiable (f : ℝ → ℝ) : Prop :=\n∀ x, is_differentiable_at f x\n\ntheorem deriv_is_unique (f : ℝ → ℝ) (x : ℝ) (d e : ℝ) :\nis_deriv f x d → is_deriv f x e → d = e := sorry\n\ntheorem deriv_is_linear1 (f : ℝ → ℝ) (g : ℝ → ℝ) (x : ℝ) (d e : ℝ) :\nis_deriv f x d → is_deriv g x e → is_deriv (λ t, f t + g t) x (d + e) := sorry \n\ntheorem deriv_is_linear2 (f : ℝ → ℝ) (x : ℝ) (d : ℝ) (μ : ℝ) :\nis_deriv f x d → is_deriv (λ t, μ * f t) x (μ * d) := sorry \n\n-- sorry Patrick\ntheorem product_rule (f g : ℝ → ℝ) (x : ℝ) (d e : ℝ) :\nis_deriv f x d → is_deriv g x e → is_deriv (λ t, f t * g t) x (d * g x + f x * e) := sorry\n\ntheorem chain_rule (f g : ℝ → ℝ) (x : ℝ) (d e : ℝ) :\nis_deriv f x d → is_deriv g (f x) e → is_deriv (g ∘ f) x (e * d) := sorry\n\ntheorem exp_deriv (x : ℝ) : is_deriv (λ t : ℝ, (exp t).re) x (exp x).re := 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/xenalib/M1P1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620619801094, "lm_q2_score": 0.7905303087996143, "lm_q1q2_score": 0.7587209992312904}}
{"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.section06quotients.sheet2zmod37\n\n/-!\n\n# Z/37 is a ring\n\n(or an additive abelian group if you only get half way through the sheet)\n\n-/\n\nnamespace Zmod\n\n-- We already defined negation but right now it's called `neg`. \n-- Let's set up notation for it so we can call it `-`.\n\ninstance : has_neg Zmod37 :=\n{ neg := neg }\n\n-- Now we can talk about `-⟦a⟧` and Lean will interpret it as `neg ⟦a⟧`.\n\n-- Let's train the simplifier to push everything into\n-- the brackets\n@[simp] lemma neg_def (a : ℤ) : -⟦a⟧ = ⟦-a⟧ :=\nbegin\n  refl\nend\n\n-- Let's also define notation for zero\ninstance : has_zero Zmod37 :=\n{ zero := ⟦0⟧ }\n\n@[simp] lemma zero_def : (0 : Zmod37) = ⟦0⟧ :=\nbegin\n  refl\nend\n\n/-\n\n## Maps X → X → X\n\nWe're trying to make `Zmod37` into an additive group; we've defined\nthe additive unit `0` and additive inverse `-`; we still need to \ndefine the group law `+` though. The type of `+` will be\n`Zmod37 → Zmod37 → Zmod37` and this might look a bit weird, so let\nme just spell it out. We usually think of addition as a function\nwhich eats two elements of an additive group `G` and returns another\nelement. But here what we're going to do is to think of addition\nas a function `g + _` which eats *one* element `g` and returns a\nfunction `G → G`, namely the function which adds `g` to its input.\nWith this way of thinking about it, addition is a function\nfrom `Zmod37` to the type of functions from `Zmod37` to `Zmod37`,\nand this latter type is called `Zmod37 → Zmod37`. So, putting\nit all together, addition has type `Zmod37 → (Zmod37 → Zmod37)`,\nand because `→` is right associative in Lean we can write this\nas `Zmod37 → Zmod37 → Zmod37` (indeed, that's what \"right associative\" means).\n\n-/\n\n-- We define addition using a function in the library called `quotient.map₂`\n-- which will descend a term of type `ℤ → ℤ → ℤ` to a term of type\n-- `Zmod37 → Zmod37 → Zmod37`. We descend addition on the integers.\n-- To make this work (to check it's a \"well-defined definition\") we need to prove\n-- a theorem, hence this starts as a definition and ends up as a proof of a theorem.\n\ndef add : Zmod37 → Zmod37 → Zmod37 :=\nquotient.map₂ (λ a b, a + b) begin\n  -- keep intro-ing, and dsimp the lambdas away\n  sorry\nend\n\ninstance : has_add Zmod37 :=\n{ add := add }\n\n@[simp] lemma add_def (a b : ℤ) : ⟦a⟧ + ⟦b⟧ = ⟦a + b⟧ :=\nbegin\n  refl\nend\n\n/-\n\n## `quotient.induction_on`\n\nThe one thing I've not told you about is a really nice way of \nreducing questions about `Zmod37` to equations about integers.\nSure you can use `surjective_quotient_mk` but there's a much\nnicer way; you can do \"induction on the terms of the quotient\".\nLet me do this first one for you, to give you the idea of\nhow to do these simply.\n\n-/\nlemma add_zero (z : Zmod37) : z + 0 = z :=\nbegin\n  -- A question about Zmod37, a type we're in the middle of building\n  -- an API for.\n  apply quotient.induction_on z, clear z,\n  -- Still a question about Zmod37, but now all our variables\n  -- are integers,\n  intro a,\n  -- There are now two approaches. You can either `apply quotient.sound`\n  -- to turn it into a question about integers, where we can use\n  -- all the usual tactics like `ring`, or you can see how far\n  -- the simplifier gets, because we've been training it to\n  -- do questions like these.\n  -- We told it `0 = ⟦0⟧` and `⟦a⟧ + ⟦b⟧ = ⟦a + b⟧`.\n  -- In this case, the simplifier can do it.\n  simp,\n  -- If it can't do it, try applying `quotient.sound` and\n  -- then perhaps `dsimp` to get rid of the lambdas.\nend\n\n-- I'll give you the first line for this one.\nlemma add_comm (y z : Zmod37) : y + z = z + y :=\nbegin\n  apply quotient.induction_on₂ y z, clear y z,\n  sorry\nend\n\n-- See if you can prove the remaining axioms for an additive abelian group yourself.\n-- We name this instance `Zmod.add_comm_group` and we'll use it later on.\ninstance add_comm_group : add_comm_group Zmod37 :=\n{ add := (+),\n  zero := 0,\n  neg := has_neg.neg,\n  add_assoc := begin\n    sorry\n  end,\n  zero_add := begin\n    sorry\n  end,\n  add_zero := add_zero,\n  add_left_neg := begin\n    sorry\n  end,\n  add_comm := add_comm }\n\n-- Bonus points: see if you can make it a ring!\n-- The rest of this file introduces no new techniques; all it offers\n-- you is the satisfaction of proving that ℤ/37ℤ is a ring by yourself.\n\ninstance : has_one Zmod37 :=\n{ one := ⟦1⟧ }\n\n@[simp] lemma one_def : (1 : Zmod37) = ⟦1⟧ :=\nbegin\n  refl\nend\n\ndef mul : Zmod37 → Zmod37 → Zmod37 :=\nquotient.map₂ (λ x y, x * y) begin\n  -- tricky!\n  sorry,\nend\n\ninstance : has_mul Zmod37 :=\n{ mul := mul }\n\n@[simp] lemma mul_def (a b : ℤ) : ⟦a⟧ * ⟦b⟧ = ⟦a * b⟧ :=\nbegin\n  refl\nend\n\ninstance : comm_ring Zmod37 :=\n{ \n  mul := (*),\n  add := (+),\n  mul_assoc := begin\n    sorry\n  end,\n  one := 1,\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,\nend,\n  -- the rest of the ring axioms are the axioms for an additive abelian group,\n  -- and we did those already.\n  ..Zmod.add_comm_group }\nend Zmod\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/sheet3ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541577509315, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.758626893780536}}
{"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 data.list.basic\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 α`, the smallest element of `l` for nonempty lists, and `⊤` for\n`[]`\n-/\nnamespace list\nvariables {α : Type*} {β : Type*} [linear_order β]\n\n/-- Auxiliary definition to define `argmax` -/\ndef argmax₂ (f : α → β) (a : option α) (b : α) : option α :=\noption.cases_on a (some b) (λ c, if f b ≤ f c then some c else 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 (f : α → β) (l : list α) : option α :=\nl.foldl (argmax₂ f) none\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 (f : α → β) (l : list α) :=\n@argmax _ (order_dual β) _ f l\n\n@[simp] lemma argmax_two_self (f : α → β) (a : α) : argmax₂ f (some a) a = a :=\nif_pos le_rfl\n\n@[simp] lemma argmax_nil (f : α → β) : argmax f [] = none := rfl\n\n@[simp] lemma argmin_nil (f : α → β) : argmin f [] = none := rfl\n\n@[simp] lemma argmax_singleton {f : α → β} {a : α} : argmax f [a] = some a := rfl\n\n@[simp] lemma argmin_singleton {f : α → β} {a : α} : argmin f [a] = a := rfl\n\n@[simp] lemma foldl_argmax₂_eq_none {f : α → β} {l : list α} {o : option α} :\n  l.foldl (argmax₂ f) o = none ↔ l = [] ∧ o = none :=\nlist.reverse_rec_on l (by simp) $\n  (assume tl hd, by simp [argmax₂];\n    cases foldl (argmax₂ f) o tl; simp; try {split_ifs}; simp)\n\nprivate theorem le_of_foldl_argmax₂ {f : α → β} {l} : Π {a m : α} {o : option α}, a ∈ l →\n  m ∈ foldl (argmax₂ f) o l → f a ≤ f m :=\nlist.reverse_rec_on l\n  (λ _ _ _ h, absurd h $ not_mem_nil _)\n  begin\n    intros tl _ ih _ _ _ h ho,\n    rw [foldl_append, foldl_cons, foldl_nil, argmax₂] at ho,\n    cases hf : foldl (argmax₂ f) o tl,\n    { rw [hf] at ho,\n      rw [foldl_argmax₂_eq_none] at hf,\n      simp [hf.1, hf.2, *] at * },\n    rw [hf, option.mem_def] at ho,\n    dsimp only at ho,\n    cases mem_append.1 h with h h,\n    { refine le_trans (ih h hf) _,\n      have := @le_of_lt _ _ (f val) (f m),\n      split_ifs at ho;\n      simp * at * },\n    { split_ifs at ho;\n      simp * at * }\n  end\n\nprivate theorem foldl_argmax₂_mem (f : α → β) (l) : Π (a m : α),\n  m ∈ foldl (argmax₂ f) (some a) l → m ∈ a :: l :=\nlist.reverse_rec_on l (by simp [eq_comm])\n  begin\n    assume tl hd ih a m,\n    simp only [foldl_append, foldl_cons, foldl_nil, argmax₂],\n    cases hf : foldl (argmax₂ f) (some a) tl,\n    { simp {contextual := tt} },\n    { dsimp only, split_ifs,\n      { -- `finish [ih _ _ hf]` closes this goal\n        rcases ih _ _ hf with rfl | H,\n        { simp only [mem_cons_iff, mem_append, mem_singleton, option.mem_def], tauto },\n        { apply λ hm, or.inr (list.mem_append.mpr $ or.inl _),\n          exact (option.mem_some_iff.mp hm ▸ H)} },\n      { simp {contextual := tt} } }\n  end\n\ntheorem argmax_mem {f : α → β} : Π {l : list α} {m : α}, m ∈ argmax f l → m ∈ l\n| [] m       := by simp\n| (hd::tl) m := by simpa [argmax, argmax₂] using foldl_argmax₂_mem f tl hd m\n\ntheorem argmin_mem {f : α → β} : Π {l : list α} {m : α}, m ∈ argmin f l → m ∈ l :=\n@argmax_mem _ (order_dual β) _ _\n\n@[simp] theorem argmax_eq_none {f : α → β} {l : list α} : l.argmax f = none ↔ l = [] :=\nby simp [argmax]\n\n@[simp] theorem argmin_eq_none {f : α → β} {l : list α} : l.argmin f = none ↔ l = [] :=\n@argmax_eq_none _ (order_dual β) _ _ _\n\ntheorem le_argmax_of_mem {f : α → β} {a m : α} {l : list α} : a ∈ l → m ∈ argmax f l → f a ≤ f m :=\nle_of_foldl_argmax₂\n\ntheorem argmin_le_of_mem {f : α → β} {a m : α} {l : list α} : a ∈ l → m ∈ argmin f l → f m ≤ f a:=\n@le_argmax_of_mem _ (order_dual β) _ _ _ _ _\n\ntheorem argmax_concat (f : α → β) (a : α) (l : list α) : argmax f (l ++ [a]) =\n  option.cases_on (argmax f l) (some a) (λ c, if f a ≤ f c then some c else some a) :=\nby rw [argmax, argmax]; simp [argmax₂]\n\ntheorem argmin_concat (f : α → β) (a : α) (l : list α) : argmin f (l ++ [a]) =\n  option.cases_on (argmin f l) (some a) (λ c, if f c ≤ f a then some c else some a) :=\n@argmax_concat _ (order_dual β) _ _ _ _\n\ntheorem argmax_cons (f : α → β) (a : α) (l : list α) : argmax f (a :: l) =\n  option.cases_on (argmax f l) (some a) (λ c, if f c ≤ f a then some a else some c) :=\nlist.reverse_rec_on l rfl $\n  assume hd tl ih,  begin\n    rw [← cons_append, argmax_concat, ih, argmax_concat],\n    cases h : argmax f hd with m,\n    { simp [h] },\n    { simp [h], dsimp,\n      by_cases ham : f m ≤ f a,\n      { rw if_pos ham, dsimp,\n        by_cases htlm : f tl ≤ f m,\n        { rw if_pos htlm, dsimp,\n          rw [if_pos (le_trans htlm ham), if_pos ham] },\n        { rw if_neg htlm } },\n      { rw if_neg ham, dsimp,\n        by_cases htlm : f tl ≤ f m,\n        { rw if_pos htlm, dsimp,\n          rw if_neg ham },\n        { rw if_neg htlm, dsimp,\n          rw [if_neg (not_le_of_gt (lt_trans (lt_of_not_ge ham) (lt_of_not_ge htlm)))] } } }\n  end\n\ntheorem argmin_cons (f : α → β) (a : α) (l : list α) : argmin f (a :: l) =\n  option.cases_on (argmin f l) (some a) (λ c, if f a ≤ f c then some a else some c) :=\n@argmax_cons _ (order_dual β) _ _ _ _\n\ntheorem index_of_argmax [decidable_eq α] {f : α → β} : Π {l : list α} {m : α}, m ∈ argmax f l →\n  ∀ {a}, a ∈ l → f m ≤ f a → l.index_of m ≤ l.index_of a\n| []       m _  _ _  _   := by simp\n| (hd::tl) m hm a ha ham := begin\n  simp only [index_of_cons, argmax_cons, option.mem_def] at ⊢ hm,\n  cases h : argmax f tl,\n  { rw h at hm,\n    simp * at * },\n  { rw h at hm,\n    dsimp only at hm,\n    cases ha with hahd hatl,\n    { clear index_of_argmax,\n      subst hahd,\n      split_ifs at hm,\n      { subst hm },\n      { subst hm, contradiction } },\n    { have := index_of_argmax h hatl, clear index_of_argmax,\n      split_ifs at *;\n      refl <|> exact nat.zero_le _ <|> simp [*, nat.succ_le_succ_iff, -not_le] at * } }\nend\n\ntheorem index_of_argmin [decidable_eq α] {f : α → β} : Π {l : list α} {m : α}, m ∈ argmin f l →\n  ∀ {a}, a ∈ l → f a ≤ f m → l.index_of m ≤ l.index_of a :=\n@index_of_argmax _ (order_dual β) _ _ _\n\ntheorem mem_argmax_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :\n  m ∈ argmax f l ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧\n    (∀ a ∈ l, f m ≤ f a → l.index_of m ≤ l.index_of a) :=\n⟨λ hm, ⟨argmax_mem hm, λ a ha, le_argmax_of_mem ha hm, λ _, index_of_argmax hm⟩,\n  begin\n    rintros ⟨hml, ham, hma⟩,\n    cases harg : argmax f l with n,\n    { simp * at * },\n    { have := le_antisymm (hma n (argmax_mem harg) (le_argmax_of_mem hml harg))\n        (index_of_argmax harg hml (ham _ (argmax_mem harg))),\n      rw [(index_of_inj hml (argmax_mem harg)).1 this, option.mem_def] }\n  end⟩\n\ntheorem argmax_eq_some_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :\n  argmax f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧\n    (∀ a ∈ l, f m ≤ f a → l.index_of m ≤ l.index_of a) := mem_argmax_iff\n\ntheorem mem_argmin_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :\n  m ∈ argmin f l ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧\n    (∀ a ∈ l, f a ≤ f m → l.index_of m ≤ l.index_of a) :=\n@mem_argmax_iff _ (order_dual β) _ _ _ _ _\n\ntheorem argmin_eq_some_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :\n  argmin f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧\n    (∀ a ∈ l, f a ≤ f m → l.index_of m ≤ l.index_of a) := mem_argmin_iff\n\nvariable [linear_order α]\n\n/-- `maximum l` returns an `with_bot α`, the largest element of `l` for nonempty lists, and `⊥` for\n`[]`  -/\ndef maximum (l : list α) : with_bot α := argmax id l\n\n/-- `minimum l` returns an `with_top α`, the smallest element of `l` for nonempty lists, and `⊤` for\n`[]`  -/\ndef minimum (l : list α) : with_top α := argmin id l\n\n@[simp] lemma maximum_nil : maximum ([] : list α) = ⊥ := rfl\n\n@[simp] lemma minimum_nil : minimum ([] : list α) = ⊤ := rfl\n\n@[simp] lemma maximum_singleton (a : α) : maximum [a] = a := rfl\n\n@[simp] lemma minimum_singleton (a : α) : minimum [a] = a := rfl\n\ntheorem maximum_mem {l : list α} {m : α} : (maximum l : with_top α) = m → m ∈ l := argmax_mem\n\ntheorem minimum_mem {l : list α} {m : α} : (minimum l : with_bot α) = m → m ∈ l := argmin_mem\n\n@[simp] theorem maximum_eq_none {l : list α} : l.maximum = none ↔ l = [] := argmax_eq_none\n\n@[simp] theorem minimum_eq_none {l : list α} : l.minimum = none ↔ l = [] := argmin_eq_none\n\n\n\ntheorem minimum_le_of_mem {a m : α} {l : list α} : a ∈ l → (minimum l : with_top α) = m → m ≤ a :=\nargmin_le_of_mem\n\ntheorem le_maximum_of_mem' {a : α} {l : list α} (ha : a ∈ l) : (a : with_bot α) ≤ maximum l :=\noption.cases_on (maximum l) (λ _ h, absurd ha ((h rfl).symm ▸ not_mem_nil _))\n  (λ m hm _, with_bot.coe_le_coe.2 $ hm _ rfl)\n  (λ m, @le_maximum_of_mem _ _ _ m _ ha)\n  (@maximum_eq_none _ _ l).1\n\ntheorem le_minimum_of_mem' {a : α} {l : list α} (ha : a ∈ l) : minimum l ≤ (a : with_top α) :=\n@le_maximum_of_mem' (order_dual α) _ _ _ ha\n\ntheorem maximum_concat (a : α) (l : list α) : maximum (l ++ [a]) = max (maximum l) a :=\nbegin\n  rw max_comm,\n  simp only [maximum, argmax_concat, id],\n  cases h : argmax id l,\n  { rw [max_eq_left], refl, exact bot_le },\n  change (coe : α → with_bot α) with some,\n  rw [max_comm],\n  simp [max_def]\nend\n\ntheorem minimum_concat (a : α) (l : list α) : minimum (l ++ [a]) = min (minimum l) a :=\n@maximum_concat (order_dual α) _ _ _\n\ntheorem maximum_cons (a : α) (l : list α) : maximum (a :: l) = max a (maximum l) :=\nlist.reverse_rec_on l (by simp [@max_eq_left (with_bot α) _ _ _ bot_le])\n  (λ tl hd ih, by rw [← cons_append, maximum_concat, ih, maximum_concat, max_assoc])\n\ntheorem minimum_cons (a : α) (l : list α) : minimum (a :: l) = min a (minimum l) :=\n@maximum_cons (order_dual α) _ _ _\n\ntheorem maximum_eq_coe_iff {m : α} {l : list α} :\n  maximum l = m ↔ m ∈ l ∧ (∀ a ∈ l, a ≤ m) :=\nbegin\n  unfold_coes,\n  simp only [maximum, argmax_eq_some_iff, id],\n  split,\n  { simp only [true_and, forall_true_iff] {contextual := tt} },\n  { simp only [true_and, forall_true_iff] {contextual := tt},\n    intros h a hal hma,\n    rw [le_antisymm hma (h.2 a hal)] }\nend\n\ntheorem minimum_eq_coe_iff {m : α} {l : list α} :\n  minimum l = m ↔ m ∈ l ∧ (∀ a ∈ l, m ≤ a) :=\n@maximum_eq_coe_iff (order_dual α) _ _ _\n\nsection fold\n\nvariables {M : Type*} [canonically_linear_ordered_add_monoid M]\n\n/-! Note: since there is no typeclass typeclass dual\nto `canonically_linear_ordered_add_monoid α` we cannot express these lemmas generally for\n`minimum`; instead we are limited to doing so on `order_dual α`. -/\n\nlemma maximum_eq_coe_foldr_max_of_ne_nil (l : list M) (h : l ≠ []) :\n  l.maximum = (l.foldr max ⊥ : M) :=\nbegin\n  induction l with hd tl IH,\n  { contradiction },\n  { rw [maximum_cons, foldr, with_bot.coe_max],\n    by_cases h : tl = [],\n    { simp [h, -with_top.coe_zero] },\n    { simp [IH h] } }\nend\n\nlemma minimum_eq_coe_foldr_min_of_ne_nil (l : list (order_dual M)) (h : l ≠ []) :\n  l.minimum = (l.foldr min ⊤ : order_dual M) :=\nmaximum_eq_coe_foldr_max_of_ne_nil l h\n\nlemma maximum_nat_eq_coe_foldr_max_of_ne_nil (l : list ℕ) (h : l ≠ []) :\n  l.maximum = (l.foldr max 0 : ℕ) :=\nmaximum_eq_coe_foldr_max_of_ne_nil l h\n\nlemma max_le_of_forall_le (l : list M) (n : M) (h : ∀ (x ∈ l), x ≤ n) :\n  l.foldr max ⊥ ≤ n :=\nbegin\n  induction l with y l IH,\n  { simp },\n  { specialize IH (λ x hx, h x (mem_cons_of_mem _ hx)),\n    have hy : y ≤ n := h y (mem_cons_self _ _),\n    simpa [hy] using IH }\nend\n\nlemma le_min_of_le_forall (l : list (order_dual M)) (n : (order_dual M))\n  (h : ∀ (x ∈ l), n ≤ x) :\n  n ≤ l.foldr min ⊤ :=\nmax_le_of_forall_le l n h\n\nlemma max_nat_le_of_forall_le (l : list ℕ) (n : ℕ) (h : ∀ (x ∈ l), x ≤ n) :\n  l.foldr max 0 ≤ n :=\nmax_le_of_forall_le l n h\n\nend fold\n\nend list\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/list/min_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.7585912462729559}}
{"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 : ℕ) : multiset (ℕ × ℕ) :=\n  ↑(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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ prod.fst x + prod.snd x = n := sorry\n\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp] theorem card_antidiagonal (n : ℕ) : 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) :=\n  rfl\n\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\n@[simp] theorem nodup_antidiagonal (n : ℕ) : nodup (antidiagonal n) :=\n  iff.mpr coe_nodup (list.nat.nodup_antidiagonal n)\n\n@[simp] theorem antidiagonal_succ {n : ℕ} : antidiagonal (n + 1) = (0, n + 1) ::ₘ map (prod.map Nat.succ id) (antidiagonal 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/data/multiset/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7585898851502789}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nnamespace MyNat\nopen MyNat\n\n/-!\n\n## Level 1: `zero_mul`\n\n## Lemma\n\nFor all natural numbers `m`, we have ` 0 * m = 0. `\n-/\nlemma zero_mul (m : MyNat) : 0 * m = 0 := by\n  induction m with\n  | zero =>\n    rw [zero_is_0]\n    rw [mul_zero]\n  | succ m ih =>\n    rw [mul_succ]\n    rw [ih]\n    rw [add_zero]\n\n/-!\nNext up is [Multiplication 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/MultiplicationWorld/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948928, "lm_q2_score": 0.800692004473946, "lm_q1q2_score": 0.7585604340028416}}
{"text": "section\n  variable (p q r : Prop)\n\n  -- commutativity of ∧ and ∨\n  example : p ∧ q ↔ q ∧ p := by \n    apply Iff.intro\n    . intro h\n      apply And.intro\n      . exact h.right\n      . exact h.left\n    . intro h \n      apply And.intro \n      . exact h.right\n      . exact h.left\n\n  example : p ∨ q ↔ q ∨ p := by\n    apply Iff.intro\n    . intro hpq\n      apply Or.elim hpq\n      . intro hp\n        apply Or.inr\n        exact hp\n      . intro hq \n        apply Or.inl\n        exact hq\n    . intro hqp \n      cases hqp with\n      | inl hq => \n        apply Or.inr\n        exact hq\n      | inr hp =>\n        apply Or.inl\n        exact hp\n\n  -- associativity of ∧ and ∨\n  example : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := by \n    apply Iff.intro \n    . intro hpqr\n      apply And.intro\n      . exact hpqr.left.left\n      . apply And.intro\n        . exact hpqr.left.right\n        . exact hpqr.right\n    . intro hpqr\n      apply And.intro\n      . apply And.intro\n        . exact hpqr.left\n        . exact hpqr.right.left\n      . exact hpqr.right.right\n\n  example : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := by\n    apply Iff.intro \n    . intro hpqr\n      cases hpqr with\n      | inl hpq => \n          cases hpq with\n          | inl hp => \n              exact Or.inl hp\n          | inr hq => \n              exact Or.inr $ Or.inl hq\n      | inr hr => \n          exact Or.inr $ Or.inr hr\n    . intro hpqr\n      cases hpqr with\n      | inl hp => \n          exact Or.inl $ Or.inl hp\n      | inr hqr => \n          cases hqr with\n          | inl hq => \n              exact Or.inl $ Or.inr hq\n          | inr hr =>\n              exact Or.inr hr\n\n  -- distributivity\n  example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := by\n    apply Iff.intro\n    . intro h   \n      have hp := h.left\n      have hqr := h.right\n      cases hqr with\n      | inl hq => \n        have hpq := And.intro hp hq\n        exact Or.inl hpq\n      | inr hr =>\n        have hpr := And.intro hp hr \n        exact Or.inr hpr\n    . intro h\n      apply And.intro \n      . cases h with\n        | inl hpq => \n          exact hpq.left\n        | inr hpr => \n          exact hpr.left\n      . cases h with\n        | inl hpq =>\n          have hq := hpq.right\n          exact Or.inl hq\n        | inr hpr =>\n          have hr := hpr.right\n          exact Or.inr hr\n\n  example : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := by\n    apply Iff.intro\n    . intro h\n      apply And.intro\n      . cases h with\n        | inl hp =>\n          exact Or.inl hp\n        | inr hqr =>\n          have hq := hqr.left \n          exact Or.inr hq\n      . cases h with\n        | inl hp => \n          exact Or.inl hp\n        | inr hqr => \n          have hr := hqr.right\n          exact Or.inr hr\n    . intro h \n      have hpq := h.left\n      have hpr := h.right\n      cases hpq with\n      | inl hp => \n        exact Or.inl hp\n      | inr hq => \n        cases hpr with\n        | inl hp => \n          apply Or.inl\n          exact hp\n        | inr hr => \n          have hqr := And.intro hq hr\n          apply Or.inr\n          exact hqr\n\n  -- other properties\n  example : (p → (q → r)) ↔ (p ∧ q → r) := by\n    apply Iff.intro\n    . intros hpqr hpq\n      have hp := hpq.left\n      have hq := hpq.right\n      have hqr := hpqr hp\n      have hr := hqr hq\n      exact hr\n    . intros hpqr hp hq\n      have hpq := And.intro hp hq\n      have hr := hpqr hpq\n      exact hr\n\n  example : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := by\n    apply Iff.intro\n    case mp => \n      intro hpqr\n      apply And.intro\n      case left => \n        intro hp\n        have hpq := Or.intro_left q hp \n        have hr := hpqr hpq\n        assumption\n      case right => \n        intro hq\n        have hpq := Or.intro_right p hq\n        have hr := hpqr hpq\n        assumption\n    case mpr => \n      intros hprqr hpq\n      have hpr := hprqr.left \n      have hqr := hprqr.right\n      cases hpq with\n      | inl hp => \n        have hr := hpr hp\n        assumption\n      | inr hq => \n        have hr := hqr hq\n        assumption \n\n  example : ¬(p ∨ q) ↔ ¬p ∧ ¬q := by\n    apply Iff.intro\n    . intro hnpq\n      apply And.intro\n      . intro hp \n        have hpq := Or.intro_left q hp\n        exact absurd hpq hnpq\n      . intro hq \n        have hpq := Or.intro_right p hq \n        exact absurd hpq hnpq\n    . intro hnpnq hpq\n      cases hpq with\n      | inl hp =>\n        exact hnpnq.left hp \n      | inr hq =>\n        exact hnpnq.right hq\n\n\n  example : ¬p ∨ ¬q → ¬(p ∧ q) := by\n    intro hnpnq hpq\n    cases hnpnq with\n    | inl hnp =>\n      exact hnp hpq.left\n    | inr hnq =>\n      exact hnq hpq.right\n\n  example : ¬(p ∧ ¬p) := by\n    intro hpnp\n    have hnp := hpnp.right \n    have hp := hpnp.left \n    exact hnp hp\n\n  example : p ∧ ¬q → ¬(p → q) := by\n    intro hpnq hpq\n    have hp := hpnq.left\n    have hnq := hpnq.right\n    have hq := hpq hp \n    exact hnq hq\n\n  example : ¬p → (p → q) := by\n    intro hnp hp \n    exact absurd hp hnp\n\n  example : (¬p ∨ q) → (p → q) := by\n    intro hnpq hp \n    cases hnpq with\n    | inl hnp => \n      exact absurd hp hnp\n    | inr hq => \n      exact hq\n\n  example : p ∨ False ↔ p := by\n    apply Iff.intro\n    . intro hpf\n      cases hpf with\n      | inl hp =>\n        exact hp\n      | inr hf =>\n        exact False.elim hf\n    . intro hp\n      apply Or.inl\n      exact hp\n\n  example : p ∧ False ↔ False := by\n    apply Iff.intro\n    . intro hpf\n      exact hpf.right\n    . intro hf\n      apply And.intro\n      . exact False.elim hf\n      . exact hf \n\n  example : (p → q) → (¬q → ¬p) := by\n    intro hpq hnq hp \n    have hq := hpq hp \n    exact hnq hq\n\nend\n\n\nsection\n  open Classical\n\n  variable (p q r : Prop)\n\n  example : (p → q ∨ r) → ((p → q) ∨ (p → r)) := by\n    intro hpqr\n    apply Or.elim (em q)\n    . intro hq\n      apply Or.inl\n      intro \n      exact hq\n    . intro hnq\n      apply Or.inr\n      intro hp \n      have hqr := hpqr hp\n      cases hqr with\n      | inl hq => contradiction\n      | inr hr => assumption\n\n  example : ¬(p ∧ q) → ¬p ∨ ¬q := by\n    intro hnpq \n    apply Or.elim (em p)\n    . intro hp\n      apply Or.inr\n      intro hq\n      have hpq := And.intro hp hq\n      contradiction      \n    . intro hnp\n      apply Or.inl\n      assumption\n\n  example : ¬(p → q) → p ∧ ¬q := by\n    intro hnpq\n    apply Or.elim (em p) \n    . intro hp \n      apply Or.elim (em q)\n      . intro hq\n        apply And.intro\n        . assumption\n        . have hpq : p → q := fun _ => hq\n          contradiction\n      . intro hnq\n        apply And.intro  <;> assumption\n    . intro hnp\n      apply Or.elim (em q)\n      . intro hq \n        have hpq : p → q := fun _ => hq \n        contradiction\n      . intro \n        have hpq : p → q := fun hp => absurd hp hnp\n        contradiction\n  \n\n  example : (p → q) → (¬p ∨ q) := by\n    intro hpq\n    cases (em p) with\n    | inl hp =>\n      have hq := hpq hp \n      apply Or.inr\n      assumption\n    | inr hq => \n      apply Or.inl \n      assumption\n\n  example : (¬q → ¬p) → (p → q) := by\n    intro hnqnp hp \n    cases (em q) with\n    | inl hq => \n      assumption\n    | inr hnq =>\n      have hnp := hnqnp hnq\n      contradiction\n       \n  example : p ∨ ¬p := by\n    cases (em p) with\n    | inl hp => \n      apply Or.inl\n      assumption\n    | inr hp =>\n      apply Or.inr\n      assumption\n\n  example : (((p → q) → p) → p) := by\n    intro hpqp\n    cases (em p) with\n    | inl hp  => \n      assumption\n    | inr hnp => \n      have hpq : p → q := fun hp : p => absurd hp hnp\n      have hp : p := hpqp hpq\n      assumption\n\n\nend\n\n\nsection\n  variable (α : Type) (p q : α → Prop)\n\n  example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := by\n    apply Iff.intro \n    . intros hAxpxqx\n      apply And.intro\n      . intro x\n        have hpxqx := hAxpxqx x\n        exact hpxqx.left\n      . intro x\n        have hpxqx := hAxpxqx x\n        exact hpxqx.right\n    . intro h \n      have hAxpx := h.left \n      have hAxqx := h.right \n      intro x\n      have px := hAxpx x \n      have qx := hAxqx x \n      apply And.intro\n      . exact px\n      . exact qx\n\n  example : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := by\n    intros hAxpxqx hAxpx x\n    have hpx := hAxpx x\n    have hpxqx := hAxpxqx x \n    have hqx := hpxqx hpx\n    exact hqx\n\n  example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := by\n    intros hAxpxAxqx x\n    cases hAxpxAxqx with\n    | inl hAxpx => \n      have hpx := hAxpx x\n      apply Or.inl\n      assumption\n    | inr hAxqx => \n      have hqx := hAxqx x\n      apply Or.inr\n      assumption\n\nend\n\nsection\n  open Classical\n\n  variable (α : Type) (p q : α → Prop)\n  variable (r : Prop)\n\n  example : α → ((∀ _ : α, r) ↔ r) := by \n    intro hα\n    apply Iff.intro\n    . intro hαr\n      exact hαr hα\n    . intro hr\n      intro\n      assumption\nend\n\nsection\n  variable (men : Type) (barber : men)\n  variable (shaves : men → men → Prop)\n\n  example (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : False := by \n    have h1 := h barber\n    have h2 := fun hbb => h1.mp hbb hbb\n    have h3 := h1.mpr h2\n    contradiction\n\nend\n\n\nsection ex2\n\nexample (p q r : Prop) (hp :  p) \n  : (p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) := by\n  repeat (constructor; repeat (first | apply Or.inl; assumption | apply Or.inr | assumption ))\n\nend ex2", "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/sec05_ex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7585268271086035}}
{"text": "import .lovelib\n\n\n/-! # LoVe Demo 13: Rational and Real Numbers\n\nWe review the construction of `ℚ` and `ℝ` as quotient types.\n\nOur procedure to construct types with specific properties:\n\n1. Create a new type that can represent all elements, but not necessarily in a\n   unique manner.\n\n2. Quotient this representation, equating elements that should be equal.\n\n3. Define operators on the quotient type by lifting functions from the base\n   type and prove that they are compatible with the quotient relation.\n\nWe used this approach in lecture 11 to construct `ℤ`. It can be used for `ℚ` and\n`ℝ` as well. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Rational Numbers\n\n**Step 1:** A rational number is a number that can be expressed as a fraction\n`n / d` of integers `n` and `d ≠ 0`: -/\n\nstructure fraction :=\n(num           : ℤ)\n(denom         : ℤ)\n(denom_ne_zero : denom ≠ 0)\n\n/-! The number `n` is called the numerator, and the number `d` is called the\ndenominator.\n\nThe representation of a rational number as a fraction is not unique—e.g.,\n`1 / 2 = 2 / 4 = -1 / -2`.\n\n**Step 2:** Two fractions `n₁ / d₁` and `n₂ / d₂` represent the same rational\nnumber if the ratio between numerator and denominator are the same—i.e.,\n`n₁ * d₂ = n₂ * d₁`. This will be our equivalence relation `≈` on fractions. -/\n\nnamespace fraction\n\n@[instance] def setoid : setoid fraction :=\n{ r     := λa b : fraction, num a * denom b = num b * denom a,\n  iseqv :=\n    begin\n      repeat { apply and.intro },\n      { intros a; refl },\n      { intros a b h; cc },\n      { intros a b c eq_ab eq_bc,\n        apply int.eq_of_mul_eq_mul_right (denom_ne_zero b),\n        cc }\n    end }\n\nlemma setoid_iff (a b : fraction) :\n  a ≈ b ↔ num a * denom b = num b * denom a :=\nby refl\n\n/-! **Step 3:** Define `0 := 0 / 1`, `1 := 1 / 1`, addition, multiplication, etc.\n\n    `n₁ / d₁ + n₂ / d₂`     := `(n₁ * d₂ + n₂ * d₁) / (d₁ * d₂)`\n    `(n₁ / d₁) * (n₂ / d₂)` := `(n₁ * n₂) / (d₁ * d₂)`\n\nThen show that they are compatible with `≈`. -/\n\ndef of_int (i : ℤ) : fraction :=\n{ num           := i,\n  denom         := 1,\n  denom_ne_zero := by simp }\n\n@[instance] def has_zero : has_zero fraction :=\n{ zero := of_int 0 }\n\n@[instance] def has_one : has_one fraction :=\n{ one := of_int 1 }\n\n@[instance] def has_add : has_add fraction :=\n{ add := λa b : fraction,\n    { num           := num a * denom b + num b * denom a,\n      denom         := denom a * denom b,\n      denom_ne_zero :=\n        by apply mul_ne_zero; exact denom_ne_zero _ } }\n\n@[simp] lemma add_num (a b : fraction) :\n  num (a + b) = num a * denom b + num b * denom a :=\nby refl\n\n@[simp] lemma add_denom (a b : fraction) :\n  denom (a + b) = denom a * denom b :=\nby refl\n\nlemma add_equiv_add {a a' b b' : fraction} (ha : a ≈ a')\n    (hb : b ≈ b') :\n  a + b ≈ a' + b' :=\nbegin\n  simp [setoid_iff, add_denom, add_num] at *,\n  calc  (num a * denom b + num b * denom a)\n          * (denom a' * denom b')\n      = num a * denom a' * denom b * denom b'\n          + num b * denom b' * denom a * denom a' :\n    by simp [add_mul, mul_add]; ac_refl\n  ... = num a' * denom a * denom b * denom b'\n          + num b' * denom b * denom a * denom a' :\n    by simp [*]\n  ... = (num a' * denom b' + num b' * denom a')\n          * (denom a * denom b) :\n    by simp [add_mul, mul_add]; ac_refl\nend\n\n@[instance] def has_neg : has_neg fraction :=\n{ neg := λa : fraction,\n    { num := - num a,\n      ..a } }\n\n@[simp] lemma neg_num (a : fraction) :\n  num (- a) = - num a :=\nby refl\n\n@[simp] lemma neg_denom (a : fraction) :\n  denom (- a) = denom a :=\nby refl\n\nlemma setoid_neg {a a' : fraction} (hab : a ≈ a') :\n  - a ≈ - a' :=\nby simp [setoid_iff] at hab ⊢; exact hab\n\n@[instance] def has_mul : has_mul fraction :=\n{ mul := λa b : fraction,\n    { num           := num a * num b,\n      denom         := denom a * denom b,\n      denom_ne_zero :=\n        mul_ne_zero (denom_ne_zero a) (denom_ne_zero b) } }\n\n@[simp] lemma mul_num (a b : fraction) :\n  num (a * b) = num a * num b :=\nby refl\n\n@[simp] lemma mul_denom (a b : fraction) :\n  denom (a * b) = denom a * denom b :=\nby refl\n\nlemma setoid_mul {a a' b b' : fraction} (ha : a ≈ a')\n    (hb : b ≈ b') :\n  a * b ≈ a' * b' :=\nby simp [setoid_iff] at ha hb ⊢; cc\n\n@[instance] def has_inv : has_inv fraction :=\n{ inv := λa : fraction,\n    if ha : num a = 0 then\n      0\n    else\n      { num           := denom a,\n        denom         := num a,\n        denom_ne_zero := ha } }\n\nlemma inv_def (a : fraction) (ha : num a ≠ 0) :\n  a⁻¹ =\n  { num           := denom a,\n    denom         := num a,\n    denom_ne_zero := ha } :=\ndif_neg ha\n\nlemma inv_zero (a : fraction) (ha : num a = 0) :\n  a⁻¹ = 0 :=\ndif_pos ha\n\n@[simp] lemma inv_num (a : fraction) (ha : num a ≠ 0) :\n  num (a⁻¹) = denom a :=\nby rw inv_def a ha\n\n@[simp] lemma inv_denom (a : fraction) (ha : num a ≠ 0) :\n  denom (a⁻¹) = num a :=\nby rw inv_def a ha\n\nlemma setoid_inv {a a' : fraction} (ha : a ≈ a') :\n  a⁻¹ ≈ a'⁻¹ :=\nbegin\n  cases' classical.em (num a = 0),\n  case inl : ha0 {\n    cases' classical.em (num a' = 0),\n    case inl : ha'0 {\n      simp [ha0, ha'0, inv_zero] },\n    case inr : ha'0 {\n      simp [ha0, ha'0, setoid_iff, denom_ne_zero] at ha,\n      cc } },\n  case inr : ha0 {\n    cases' classical.em (num a' = 0),\n    case inl : ha'0 {\n      simp [setoid_iff, ha'0, denom_ne_zero] at ha,\n      cc },\n    case inr : ha'0 {\n      simp [setoid_iff, ha0, ha'0] at ha ⊢,\n      cc } }\nend\n\nend fraction\n\ndef rat : Type :=\nquotient fraction.setoid\n\nnamespace rat\n\n@[instance] def has_zero : has_zero rat :=\n{ zero := ⟦0⟧ }\n\n@[instance] def has_one : has_one rat :=\n{ one := ⟦1⟧ }\n\n@[instance] def has_add : has_add rat :=\n{ add := quotient.lift₂ (λa b : fraction, ⟦a + b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact fraction.add_equiv_add ha hb\n    end }\n\n@[instance] def has_neg : has_neg rat :=\n{ neg := quotient.lift (λa : fraction, ⟦- a⟧)\n    begin\n      intros a a' ha,\n      apply quotient.sound,\n      exact fraction.setoid_neg ha\n    end }\n\n@[instance] def has_mul : has_mul rat :=\n{ mul := quotient.lift₂ (λa b : fraction, ⟦a * b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact fraction.setoid_mul ha hb\n    end }\n\n@[instance] def has_inv : has_inv rat :=\n{ inv := quotient.lift (λa : fraction, ⟦a⁻¹⟧)\n    begin\n      intros a a' ha,\n      apply quotient.sound,\n      exact fraction.setoid_inv ha\n    end }\n\nend rat\n\n\n/-! ### Alternative Definitions of `ℚ`\n\n**Alternative 1:** Define `ℚ` as a subtype of `fraction`, with the requirement\nthat the denominator is positive and that the numerator and the denominator have\nno common divisors except `1` and `-1`: -/\n\nnamespace alternative\n\ndef rat.is_canonical (a : fraction) : Prop :=\nfraction.denom a > 0\n∧ nat.coprime (int.nat_abs (fraction.num a))\n  (int.nat_abs (fraction.denom a))\n\ndef rat : Type :=\n{a : fraction // rat.is_canonical a}\n\nend alternative\n\n/-! This is more or less the `mathlib` definition.\n\nAdvantages:\n\n* no quotient required;\n* more efficient computation;\n* more properties are syntactic equalities up to computation.\n\nDisadvantage:\n\n* more complicated function definitions.\n\n\n### Real Numbers\n\nSome sequences of rational numbers seem to converge because the numbers in the\nsequence get closer and closer to each other, and yet do not converge to a\nrational number.\n\nExample:\n\n    `a₀ = 1`\n    `a₁ = 1.4`\n    `a₂ = 1.41`\n    `a₃ = 1.414`\n    `a₄ = 1.4142`\n    `a₅ = 1.41421`\n    `a₆ = 1.414213`\n    `a₇ = 1.4142135`\n       ⋮\n\nThis sequence seems to converge because each `a_n` is at most `10^-n` away from\nany of the following numbers. But the limit is `√2`, which is not a rational\nnumber.\n\nThe rational numbers are incomplete, and the reals are their  __completion__.\n\nTo construct the reals, we need to fill in the gaps that are revealed by these\nsequences that seem to converge, but do not.\n\nMathematically, a sequence `a₀, a₁, …` of rational numbers is __Cauchy__ if for\nany `ε > 0`, there exists an `N ∈ ℕ` such that for all `m ≥ N`, we have\n`|a_N - a_m| < ε`.\n\nIn other words, no matter how small we choose `ε`, we can always find a point in\nthe sequence from which all following numbers deviate less than by `ε`. -/\n\ndef is_cau_seq (f : ℕ → ℚ) : Prop :=\n∀ε > 0, ∃N, ∀m ≥ N, abs (f N - f m) < ε\n\n/-! Not every sequence is a Cauchy sequence: -/\n\nlemma id_not_cau_seq :\n  ¬ is_cau_seq (λn : ℕ, (n : ℚ)) :=\nbegin\n  rw is_cau_seq,\n  intro h,\n  cases' h 1 zero_lt_one with i hi,\n  have hi_succi :=\n    hi (i + 1) (by simp),\n  simp [←sub_sub] at hi_succi,\n  assumption\nend\n\n/-! We define a type of Cauchy sequences as a subtype: -/\n\ndef cau_seq : Type :=\n{f : ℕ → ℚ // is_cau_seq f}\n\ndef seq_of (f : cau_seq) : ℕ → ℚ :=\nsubtype.val f\n\n/-! Cauchy sequences represent real numbers:\n\n* `a_n = 1 / n` represents the real number `0`;\n* `1, 1.4, 1.41, …` represents the real number `√2`;\n* `a_n = 0` also represents the real number `0`.\n\nSince different Cauchy sequences can represent the same real number, we need to\ntake the quotient. Formally, two sequences represent the same real number when\ntheir difference converges to zero: -/\n\nnamespace cau_seq\n\n@[instance] def setoid : setoid cau_seq :=\n{ r     := λf g : cau_seq,\n    ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε,\n  iseqv :=\n    begin\n      apply and.intro,\n      { intros f ε hε,\n        apply exists.intro 0,\n        finish },\n      apply and.intro,\n      { intros f g hfg ε hε,\n        cases' hfg ε hε with N hN,\n        apply exists.intro N,\n        intros m hm,\n        rw abs_sub,\n        apply hN m hm },\n      { intros f g h hfg hgh ε hε,\n        cases' hfg (ε / 2) (half_pos hε) with N₁ hN₁,\n        cases' hgh (ε / 2) (half_pos hε) with N₂ hN₂,\n        apply exists.intro (max N₁ N₂),\n        intros m hm,\n        calc  abs (seq_of f m - seq_of h m)\n            ≤ abs (seq_of f m - seq_of g m)\n              + abs (seq_of g m - seq_of h m) :\n          by apply abs_sub_le\n        ... < ε / 2 + ε / 2 :\n          add_lt_add (hN₁ m (le_of_max_le_left hm))\n            (hN₂ m (le_of_max_le_right hm))\n        ... = ε :\n          by simp }\n    end }\n\nlemma setoid_iff (f g : cau_seq) :\n  f ≈ g ↔\n  ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε :=\nby refl\n\n/-! We can define constants such as `0` and `1` as a constant sequence. Any\nconstant sequence is a Cauchy sequence: -/\n\ndef const (q : ℚ) : cau_seq :=\nsubtype.mk (λ_ : ℕ, q) (by rw is_cau_seq; intros ε hε; finish)\n\n/-! Defining addition of real numbers requires a little more effort. We define\naddition on Cauchy sequences as pairwise addition: -/\n\n@[instance] def has_add : has_add cau_seq :=\n{ add := λf g : cau_seq,\n    subtype.mk (λn : ℕ, seq_of f n + seq_of g n) sorry }\n\n/-! Above, we omit the proof that the addition of two Cauchy sequences is again\na Cauchy sequence.\n\nNext, we need to show that this addition is compatible with `≈`: -/\n\nlemma add_equiv_add {f f' g g' : cau_seq} (hf : f ≈ f')\n    (hg : g ≈ g') :\n  f + g ≈ f' + g' :=\nbegin\n  intros ε₀ hε₀,\n  simp [setoid_iff],\n  cases' hf (ε₀ / 2) (half_pos hε₀) with Nf hNf,\n  cases' hg (ε₀ / 2) (half_pos hε₀) with Ng hNg,\n  apply exists.intro (max Nf Ng),\n  intros m hm,\n  calc  abs (seq_of (f + g) m - seq_of (f' + g') m)\n      = abs ((seq_of f m + seq_of g m)\n           - (seq_of f' m + seq_of g' m)) :\n    by refl\n  ... = abs ((seq_of f m - seq_of f' m)\n           + (seq_of g m - seq_of g' m)) :\n    begin\n      have arg_eq :\n        seq_of f m + seq_of g m - (seq_of f' m + seq_of g' m) =\n        seq_of f m - seq_of f' m + (seq_of g m - seq_of g' m),\n        by linarith,\n      rw arg_eq\n    end\n  ... ≤ abs (seq_of f m - seq_of f' m)\n      + abs (seq_of g m - seq_of g' m) :\n    by apply abs_add\n  ... < ε₀ / 2 + ε₀ / 2 :\n    add_lt_add (hNf m (le_of_max_le_left hm))\n      (hNg m (le_of_max_le_right hm))\n  ... = ε₀ :\n    by simp\nend\n\nend cau_seq\n\n/-! The real numbers are the quotient: -/\n\ndef real : Type :=\nquotient cau_seq.setoid\n\nnamespace real\n\n@[instance] def has_zero : has_zero real :=\n{ zero := ⟦cau_seq.const 0⟧ }\n\n@[instance] def has_one : has_one real :=\n{ one := ⟦cau_seq.const 1⟧ }\n\n@[instance] def has_add : has_add real :=\n{ add := quotient.lift₂ (λa b : cau_seq, ⟦a + b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact cau_seq.add_equiv_add ha hb,\n    end }\n\nend real\n\n\n/-! ### Alternative Definitions of `ℝ`\n\n* Dedekind cuts: `r : ℝ` is represented essentially as `{x : ℚ | x < r}`.\n\n* Binary sequences `ℕ → bool` can represent the interval `[0, 1]`. This can be\n  used to build `ℝ`. -/\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/love13_rational_and_real_numbers_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7585268252353938}}
{"text": "\nimport .myRing\nimport .axiom_set\n-- import tactic\nopen myRing\nvariables {R : Type} [myRing R]\nvariables {O : Type} [ordered_ring O ]\n\n\ntheorem div_self : ∀ (a  :R), a  ∣ a :=\nbegin\n intros a,\n rw divs,\n have : a*1=a := begin\n  exact mul_one a,\n end,\n split,\n  exact this ,\n\nend\ntheorem div_one: ∀ (a :R), 1 ∣ a := begin\nintro a,\nrw divs,\nuse a,\nrw one_mul,\nend \n\ntheorem div_mul : ∀ (a b c :R), a ∣ b → a ∣  b*c := begin\nintros a b c d,\nrw divs at d,\ncases d,\nrw divs,\nsplit, {\n  have  :  a * d_w *c = b *c := begin\n  exact mul_right c d_h,\n  end,\n  rw mul_assoc at this,\nexact this,\n},\nend\n\ntheorem divs_add: ∀ ( a b k :R ),  k ∣ a → k ∣ b → k ∣ (a+b) := begin\nintros a b c d e,\nrw divs at d,\nrw divs at e,\ncases d,\ncases e,\nrw divs,\nsplit, {\n have :  c* d_w  + c*e_w = a +b := begin\n rw d_h,\n rw e_h,\n end,\n rw ← mul_add at this,\n exact this,\n},\nend\n\ntheorem divs_linear_combination: ∀{a b c: R}, ∀(d e:R ), a ∣ b → a ∣ c → a ∣ (b*d+c*e) := begin\nintros a b c d e f g,\n  have o := div_mul a b d f,\n  have t := div_mul a c e g,\n  have w := divs_add  (b * d) (c*e) a o t ,\n  exact w, \nend\n\ntheorem divs_trans : ∀ (a b c : R), a ∣ b → b ∣ c → a ∣ c := begin\nintros a b c d e,\nrw divs at d,\nrw divs at e,\ncases d,\ncases e,\nrw divs,\nsplit, {\nrw ← d_h at e_h,\nrw mul_assoc at e_h,\nexact e_h,\n},\nend\n\n-- theorem divs_le: ∀ (a b : O), is_positive (a) → is_positive (b) → a ∣ b → a ≤ b := begin\n-- intros a b c d e,\n-- rw divs at e,\n-- cases e,\n-- rw less_eq,\n-- end\n\ntheorem neg_one_mul_neg_one: (-1:R) * (-1:R) = 1 := begin\n simp,\n--  rw mul_one,\nend\n", "meta": {"author": "AtticusKuhn", "repo": "axioms", "sha": "671c3f0e4b32207b556b17652719255336a88a37", "save_path": "github-repos/lean/AtticusKuhn-axioms", "path": "github-repos/lean/AtticusKuhn-axioms/axioms-671c3f0e4b32207b556b17652719255336a88a37/src/set_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7585268219870843}}
{"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.order.basic\n\n/-!\n#  Distance function on ℕ\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\nnamespace nat\n\n/-- Distance (absolute value of difference) between natural numbers. -/\ndef dist (n m : ℕ) := (n - m) + (m - n)\n\ntheorem dist.def (n m : ℕ) : dist n m = (n - m) + (m - n) := rfl\n\ntheorem dist_comm (n m : ℕ) : dist n m = dist m n :=\nby simp [dist.def, add_comm]\n\n@[simp] theorem dist_self (n : ℕ) : dist n n = 0 :=\nby simp [dist.def, tsub_self]\n\ntheorem eq_of_dist_eq_zero {n m : ℕ} (h : dist n m = 0) : n = m :=\nhave n - m = 0, from nat.eq_zero_of_add_eq_zero_right h,\nhave n ≤ 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 ≤ n, from tsub_eq_zero_iff_le.mp this,\nle_antisymm ‹n ≤ m› ‹m ≤ n›\n\ntheorem dist_eq_zero {n m : ℕ} (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 : ℕ} (h : m ≤ 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 : ℕ) : m ≤ dist n m + n :=\nle_trans le_tsub_add (add_le_add_right (nat.le_add_left _ _) _)\n\ntheorem dist_tri_right (n m : ℕ) : m ≤ n + dist n m :=\nby rw add_comm; apply dist_tri_left\n\ntheorem dist_tri_left' (n m : ℕ) : n ≤ dist n m + m :=\nby rw dist_comm; apply dist_tri_left\n\ntheorem dist_tri_right' (n m : ℕ) : n ≤ m + dist n m :=\nby rw dist_comm; apply dist_tri_right\n\ntheorem dist_zero_right (n : ℕ) : dist n 0 = n :=\neq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n)\n\ntheorem dist_zero_left (n : ℕ) : 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 : ℕ) : 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 : ℕ) : 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 : ℕ} (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 : ℕ) : dist n k ≤ 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 : ℕ) : 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 : ℕ) : 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 ≥ 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 ≠ j → 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": "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/dist.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652496, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7584886721136287}}
{"text": "/-\n  Dependent types\n\n  In class, I presented \"vector α n\" and \"matrix α m n\" as examples of\n  dependent types. Make up some operations on these types -- like\n  \"vector_add\" or \"vector_reverse\" -- and declare constants of the\n  right type to describe them. Use implicit arguments for parameters\n  that can be inferred. Then use \"check\" to make sure they work.\n\n  You can make up other dependent types if you would like. Don't\n  worry about the definitions; just declare constants with the right\n  types.\n-/\n\nuniverse variable u\n\nconstant vector : Type u → ℕ → Type u\nconstant matrix : Type u → ℕ → ℕ → Type u\n\nsection\n  variable α : Type u\n  variables m n : ℕ\n\n  check vector α n\n  check matrix α m n\n\n  variables v₁ v₂ : vector α n\n  variables v₃ v₄ : vector α m\nend\n\n/-\n  Propositional logic\n\n  Do at least five of these, and satisfy the following constraints:\n  - make sure you use introduction and elimination rules for all the\n    connectives\n  - do at least one that requires classical logic\n  - prove ¬(p ↔ ¬p) without using classical logic\n-/\n\nsection\n  open classical\n\n  variables p q r s : Prop\n\n  -- commutativity of ∧ and ∨\n  example : p ∧ q ↔ q ∧ p := sorry\n  example : p ∨ q ↔ q ∨ p := sorry\n\n  -- associativity of ∧ and ∨\n  example : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) := sorry\n  example : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := sorry\n\n  -- distributivity\n  -- this next one is in *Theorem Proving in Lean*\n  -- example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := sorry\n  example : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := sorry\n\n  -- other properties\n  example : (p → (q → r)) ↔ (p ∧ q → r) := sorry\n  example : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := sorry\n  example : ¬(p ∨ q) ↔ ¬p ∧ ¬q := sorry\n  example : ¬p ∨ ¬q → ¬(p ∧ q) := sorry\n  example : ¬(p ∧ ¬ p) := sorry\n  example : p ∧ ¬q → ¬(p → q) := sorry\n  example : ¬p → (p → q) := sorry\n  example : (¬p ∨ q) → (p → q) := sorry\n  example : p ∨ false ↔ p := sorry\n  example : p ∧ false ↔ false := sorry\n  example : ¬(p ↔ ¬p) := sorry\n  example : (p → q) → (¬q → ¬p) := sorry\n\n  -- these require classical reasoning\n  example : (p → r ∨ s) → ((p → r) ∨ (p → s)) := sorry\n  example : ¬(p ∧ q) → ¬p ∨ ¬q := sorry\n  example : ¬(p → q) → p ∧ ¬q := sorry\n  example : (p → q) → (¬p ∨ q) := sorry\n  example : (¬q → ¬p) → (p → q) := sorry\n  example : p ∨ ¬p := sorry\n  example : (((p → q) → p) → p) := sorry\nend\n\n/-\n  Writing mathematical assertions\n\n  I put the definitions of \"divides\" and \"pow\" in a funny namespace\n  here, to avoid conflicts with similarly-named definitions elsewhere\n  in the library (though at the moment though would not pose any such\n  conflicts). Don't worry about the recursive definition of pow or the\n  \"instance\" declaration -- we will discuss those later.\n\n  Fill in the definitions and statements indicated; you can use\n  Wikipedia to look them up.\n-/\n\nnamespace experiment\n\ndef divides (m n : ℕ) : Prop := ∃ k, m * k = n\n\ninstance : has_dvd nat := ⟨divides⟩\n\ndef pow (m : ℕ) : ℕ → ℕ\n| 0     := 1\n| (n+1) := m * pow n\n\ninfix `^` := pow\n\nsection\n  variables m n : ℕ\n\n  check m ∣ n     -- use \\| to type the divides symbol\n  check dvd m n   -- this is equivalent\n  check m^n\n  check pow m n\n\n  vm_eval 2^10\n  vm_eval 2^100\n  vm_eval 10^2\nend\n\ndef even (n : ℕ) : Prop := 2 ∣ n\n\ndef prime (n : ℕ) : Prop := sorry\n\n-- Without any parameters, an expression of type Prop is an\n-- assertion. The next one should be the statement that there are\n-- infinitely many primes. You can say this by asserting that for\n-- every natural number n, there is a prime number bigger than n.\ndef infinitely_many_primes : Prop := sorry\n\ndef Fermat_prime (n : ℕ) : Prop := sorry\n\ndef infinitely_many_Fermat_primes : Prop := sorry\n\ndef goldbach_conjecture : Prop := sorry\n\n-- This is the statement that every odd number greater than 5 is the\n-- sum of three primes.\ndef Goldbach's_weak_conjecture : Prop := sorry\n\ndef Fermat's_last_theorem : Prop := sorry\n\nend experiment\n\n/-\n  Reasoning with quantifiers:\n\n  Do at least three of these, including\n  - at least one involving the universal quantifier\n  - at least one involving the existential quantifier\n  - at least one that requires classical logic\n-/\n\nsection\n\nvariable  α : Type\nvariables (p q : α → Prop) (r : Prop)\nvariable  a : α\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := sorry\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) := sorry\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x := sorry\n\nexample : (∃ x : α, r) → r := sorry\nexample : r → (∃ x : α, r) := sorry\nexample : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r := sorry\n-- in *Theorem Proving in Lean*\n-- example : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := sorry\n\nexample : (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) := sorry\nexample : (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) := sorry\nexample : (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) := sorry\nexample : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := sorry\n\nexample : (∀ x, p x → r) ↔ (∃ x, p x) → r := sorry\n-- in *Theorem Proving in Lean*\n-- example : (∃ x, p x → r) ↔ (∀ x, p x) → r := sorry\nexample : (∃ x, r → p x) ↔ (r → ∃ x, p x) := sorry\n\nend\n", "meta": {"author": "leanclassroom", "repo": "homework-template", "sha": "cc7c213add87a9b13474842c0f5420cf566d8868", "save_path": "github-repos/lean/leanclassroom-homework-template", "path": "github-repos/lean/leanclassroom-homework-template/homework-template-cc7c213add87a9b13474842c0f5420cf566d8868/homework1/homework1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528132451417, "lm_q2_score": 0.8902942217558212, "lm_q1q2_score": 0.7584886668407659}}
{"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 set_theory.cardinal.basic\n\n/-!\n# Finite Cardinality Functions\n\n## Main Definitions\n\n* `nat.card α` is the cardinality of `α` as a natural number.\n  If `α` is infinite, `nat.card α = 0`.\n* `enat.card α` is the cardinality of `α` as an extended natural number.\n  If `α` is infinite, `enat.card α = ⊤`.\n\n-/\n\nopen cardinal\nnoncomputable theory\n\nvariables {α β : Type*}\n\nnamespace nat\n\n/-- `nat.card α` is the cardinality of `α` as a natural number.\n  If `α` is infinite, `nat.card α = 0`. -/\nprotected def card (α : Type*) : ℕ := (mk α).to_nat\n\n@[simp]\nlemma card_eq_fintype_card [fintype α] : nat.card α = fintype.card α := mk_to_nat_eq_card\n\n@[simp]\nlemma card_eq_zero_of_infinite [infinite α] : nat.card α = 0 := mk_to_nat_of_infinite\n\nlemma card_congr (f : α ≃ β) : nat.card α = nat.card β :=\ncardinal.to_nat_congr f\n\nlemma card_eq_of_bijective (f : α → β) (hf : function.bijective f) : nat.card α = nat.card β :=\ncard_congr (equiv.of_bijective f hf)\n\nlemma card_eq_of_equiv_fin {α : Type*} {n : ℕ}\n  (f : α ≃ fin n) : nat.card α = 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 `α` and `fin (nat.card α)`. See also `finite.equiv_fin`. -/\ndef equiv_fin_of_card_pos {α : Type*} (h : nat.card α ≠ 0) :\n  α ≃ fin (nat.card α) :=\nbegin\n  casesI fintype_or_infinite α,\n  { simpa using fintype.equiv_fin α },\n  { simpa using h },\nend\n\nlemma card_of_subsingleton (a : α) [subsingleton α] : nat.card α = 1 :=\nbegin\n  rw [card_eq_fintype_card],\n  convert fintype.card_of_subsingleton a,\nend\n\n@[simp] lemma card_unique [unique α] : nat.card α = 1 :=\ncard_of_subsingleton default\n\nlemma card_eq_one_iff_unique : nat.card α = 1 ↔ subsingleton α ∧ nonempty α :=\ncardinal.to_nat_eq_one_iff_unique\n\ntheorem card_of_is_empty [is_empty α] : nat.card α = 0 := by simp\n\n@[simp] lemma card_prod (α β : Type*) : nat.card (α × β) = nat.card α * nat.card β :=\nby simp only [nat.card, mk_prod, to_nat_mul, to_nat_lift]\n\n@[simp] lemma card_ulift (α : Type*) : nat.card (ulift α) = nat.card α :=\ncard_congr equiv.ulift\n\n@[simp] lemma card_plift (α : Type*) : nat.card (plift α) = nat.card α :=\ncard_congr equiv.plift\n\nend nat\n\nnamespace enat\n\n/-- `enat.card α` is the cardinality of `α` as an extended natural number.\n  If `α` is infinite, `enat.card α = ⊤`. -/\ndef card (α : Type*) : enat := (mk α).to_enat\n\n@[simp]\nlemma card_eq_coe_fintype_card [fintype α] : card α = fintype.card α := mk_to_enat_eq_coe_card\n\n@[simp]\nlemma card_eq_top_of_infinite [infinite α] : card α = ⊤ := mk_to_enat_of_infinite\n\nend enat\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/finite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7584886654806087}}
{"text": "set_option trace.simplify.rewrite true\n\nopen list(nil)\n\nconstant α : Type\nconstants reverse reverse2 : list α → list α\nconstant append : list α → α → list α\n\naxiom append.base (x : α) : append nil x = [x]\naxiom append.step (x y : α) (xs : list α) :\n  append (x :: xs) y = x :: append xs y\n\naxiom reverse.base : reverse nil = nil\naxiom reverse.step (x : α) (xs : list α) :\n  reverse (x :: xs) = append (reverse xs) x\n\nattribute [simp] append.base append.step reverse.base reverse.step\n\nexample (x y z : α) : append [x, y] z = [x, y, z] :=\nbegin\n  rw append.step,\n  rw append.step,\n  rw append.base,\nend\n\nlemma reverse.single (x : α) : reverse [x] = [x] :=\nbegin\n  -- simp, give the same steps for proof\n  rw reverse.step,\n  rw reverse.base,\n  rw append.base,\nend\n\nlemma reverse_twice.single (x : α) : reverse (reverse [x]) = [x] :=\nbegin\n  rw reverse.step,\n  rw reverse.base,\n  rw append.base,\n  rw reverse.step,\n  rw reverse.base,\n  rw append.base,\nend\n\nlemma reverse_twice.two (x y : α) : reverse (reverse [x, y]) = [x, y] :=\nbegin\n  rw reverse.step,\n  rw reverse.step,\n  rw reverse.base,\n  rw append.base,\n  -- ⊢ reverse (append [y] x) = [x, y] ~\n  -- reverse (append xs x) = x :: reverse xs\n  rw append.step,\n  rw reverse.step,\n  rw append.base,\n  rw reverse.step,\n  rw reverse.base,\n  rw append.base,\n  rw append.step,\n  rw append.base,\nend\n\n-- reverse (y :: xs) = append (reverse xs) y\nexample (x y : α) (xs : list α) :\n  reverse (x :: y :: xs) = append (append (reverse xs) y) x :=\nbegin\n  rw reverse.step,\n  rw reverse.step,\n  -- rw ←reverse.step,\n  -- rw ←reverse.step,\nend\n\nlemma reverse_right (x : α) (xs : list α) :\n  reverse (append xs x) = x :: reverse xs :=\nbegin\n  induction xs with head tail ih,\n  case nil {\n    -- simp,\n    rw append.base,\n    rw reverse.step,\n    rw reverse.base,\n    rw append.base,\n  },\n  case cons {\n    -- simp [ih],\n    -- 1st way:\n  -- [append.step]: append (head :: tail) x ==> head :: append tail x\n  -- [reverse.step]: reverse (head :: append tail x) ==> append (reverse (append tail x)) head\n  -- [ih]: reverse (append tail x) ==> x :: reverse tail\n  -- [append.step]: append (x :: reverse tail) head ==> x :: append (reverse tail) head\n  -- [reverse.step]: reverse (head :: tail) ==> append (reverse tail) head\n    rw append.step,\n    rw reverse.step,\n    rw ih,\n    rw append.step,\n    rw reverse.step, -- rw ←reverse.step, also works because equality\n\n    -- 2nd way:\n    -- rw reverse.step,\n    -- rw append.step,\n    -- rw reverse.step,\n    -- rw ←append.step,\n    -- congr,\n    -- exact ih,\n  },\nend\n\nlemma reverse_twice.induction_step (x : α) (xs : list α) :\n  reverse (reverse xs) = xs →  reverse (reverse (x :: xs)) = x :: xs :=\nbegin\n  intros h,\n  rw reverse.step,\n  rw reverse_right,\n  congr,\n  exact h,\nend\n\ntheorem reverse_twice (xs : list α) : reverse (reverse xs) = xs :=\nbegin\n  induction xs with head tail ih,\n  repeat { rw reverse.base, },\n  simp [ih, reverse_right],\n  -------------------------\n  -- rw reverse.step,\n  -- rw reverse_right,\n  -- rw ih,\n  -------------------------\n  -- rw reverse.step,\n  -- have h : ∃ (y : α) (ys : list α), y :: ys = tail, sorry,\n  -- rw ←h,\n\n  -- rw ←reverse.step at ih,\n  -- rw reverse.step,\n  -- have h : ∀ (l1 l2 : list α) (x : α), l1 = l2 → x :: l1 = x :: l2, sorry,\n  -- have H := h (reverse (reverse tail)) tail head,\n  -- have ih2 := H ih,\n  -- apply eq.trans _ ih2,\n  -- rw append.step,\nend\n\n#print reverse_twice\n-- #eval cons 1 nil -- [1]\n\n-- how to prove without lemma reverse_right:\ntheorem reverse_twice₂ (xs : list α) : reverse (reverse xs) = xs :=\nbegin\n  induction xs with y ys ih,\n  repeat { rw reverse.base },\n  -- rw reverse.step,\n  induction ys with z zs ih2, -- I think two induction steps need to prove without lemma reverse_right, because we have one in reverse_twice proof and have another in reverse_right proof.\n  case nil {\n    simp [reverse.base, append.base, reverse.step],\n  }, \n  case cons {\n    rw reverse.step,\n    -- rw reverse_right,\n    -- have rev_right := reverse_right y (reverse (z :: zs)),\n    have rev_right : reverse (append (reverse (z :: zs)) y) =\n                       y :: reverse (reverse (z :: zs)),\n      {\n        induction (reverse (z :: zs)) with head tail ih3,\n        {\n          rw append.base,\n          rw reverse.base,\n          exact reverse.single y,\n        },\n        {\n          rw append.step,\n          rw reverse.step,\n          rw ih3,\n          rw append.step,\n          congr,\n          rw reverse.step,\n        },\n      },\n    rw rev_right,\n    rw ih,\n  },\nend\n\nexample (β : Type) [decidable_eq β] (x : β) (xs : list β) :\n  (x :: xs) ∩ xs = xs :=\nbegin\n  change (list.inter (x :: xs) xs = xs),\n  simp [list.inter],\n  induction xs with head tail ih,\n  simp,\n  simp,\n  sorry,\nend\n\nexample (xs : list α) : list.append xs nil = xs :=\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/functional_equations/reverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7584886621340426}}
{"text": "/-\nCopyright (c) 2022 Damiano Testa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Damiano Testa, Eric Wieser\n-/\nimport algebra.char_p.basic\n\n/-! # `char_p R 0` and `char_zero R` need not coincide for semirings\n\nFor rings, the two notions coincide.\n\nIn fact, `char_p.of_char_zero` shows that `char_zero R` implies `char_p R 0` for any `char_zero`\n`add_monoid R` with `1`.\nThe reverse implication holds for any `add_left_cancel_monoid R` with `1`, by `char_p_to_char_zero`.\n\nThis file shows that there are semiring `R` for which `char_p R 0` holds and `char_zero R` does not.\n\nThe example is `{0, 1}` with saturating addition.\n-/\n\n@[simp] lemma add_one_eq_one (x : with_zero unit) : x + 1 = 1 :=\nwith_zero.cases_on x (by refl) (λ h, by refl)\n\nlemma with_zero_unit_char_p_zero : char_p (with_zero unit) 0 :=\n⟨λ x, by cases x; simp⟩\n\nlemma with_zero_unit_not_char_zero : ¬ char_zero (with_zero unit) :=\nλ ⟨h⟩, h.ne (by simp : 1 + 1 ≠ 0 + 1) (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/counterexamples/char_p_zero_ne_char_zero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7584886547545482}}
{"text": "\ntheorem Ex005(a b : Prop): (a ∧ (a → ¬a)) → (a ∧ ¬a) :=\nassume H:(a ∧ (a → ¬a)),\n  have A:a, from and.elim_left H,\n  have B:(a → ¬a), from and.elim_right H,\n  have C:¬a,from B A,\n  show a ∧ ¬a, from and.intro A C\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/Ex005.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9532750373915658, "lm_q2_score": 0.7956581073313275, "lm_q1q2_score": 0.7584810120171737}}
{"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 → zfc → zfc\n\ninstance : has_emptyc zfc := ⟨zfc.empty⟩\ninstance : has_insert zfc zfc := ⟨zfc.insert⟩\n\ninstance : has_zero zfc := ⟨{}⟩\ninstance : has_one zfc := ⟨{0}⟩\n\ndef succ (a : zfc) : zfc := has_insert.insert a a\n\ndef zfc_add : zfc → zfc → zfc\n| m 0 := m\n| m (zfc.insert n p) := succ (zfc_add m n)\n\ninstance : has_add zfc := ⟨zfc_add⟩\n\ninductive member : zfc → zfc → Prop\n| left {a b c : zfc} : member a c → 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 := ⟨member⟩\ninstance : has_subset zfc := ⟨(λ a b:zfc, (∀ z:zfc, z ∈ a → z ∈ b))⟩\ninfix `⊈`:50 := (λ a b, ¬(a ⊆ b))\ninfix `⊉`:50 := (λ a b, ¬(b ⊆ a))\n\naxiom member.ext (a b : zfc) : (∀ x, x ∈ a ↔ x ∈ b) ↔ a=b\n\nexport zfc\nexport member\n\n-- start here\n\n/-\n\nUSAGE:\n1. ¬P is shorthand of (P → false).\n2. A ∉ B is shorthand of ¬(A ∈ B), which is shorthand of (A ∈ B → false) per 1.\n3. A ⊆ B is shorthand of (∀ z, z ∈ A → z ∈ B).\n4. A ⊈ B is shorthand of ¬(A ⊆ B), and then use 1 and 3.\n5. A ⊇ B is shorthand of B ⊆ A.\n6. If the current goal is x ∈ {a,b,c,d,e}, then using \"left\" or \"apply left\"\n   will make the goal x ∈ {a,b,c,d}.\n7. If the current goal is x ∈ {a,b,c,d,x}, then using \"right\" or \"apply right\"\n   or \"exact right\" will prove the goal.\n8. If one wishes to disprove (i.e. derive false from) one of the current hypotheses\n   of the form h : x ∈ {a,b,c,d,e}, using \"cases h\" will replace the current hypothesis\n   with a_1 : x ∈ {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 → P\", use \"exact id\". \n\nRECAP:\n1. To prove a statement of the form \"∀ z, P z\", type \"intro x\" and then prove \"P x\".\n2. To prove a statement of the form \"P → Q\", type \"intro HP\" and then prove \"Q\".\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,3,4,5}\n\n-- prove one and delete the other for each part.\n\ntheorem M1F_Sheet01_Q05a_is_true : (1:zfc) ∈ A := sorry\ntheorem M1F_Sheet01_Q05a_is_false : (1:zfc) ∈ A := sorry\n\ntheorem M1F_Sheet01_Q05b_is_true: ({1}:zfc) ∈ A := sorry\ntheorem M1F_Sheet01_Q05b_is_false: ({1}:zfc) ∉ A := sorry\n\ntheorem M1F_Sheet01_Q05c_is_true: ({1}:zfc) ⊆ A := sorry\ntheorem M1F_Sheet01_Q05c_is_false: ({1}:zfc) ⊈ A := sorry\n\n-- The goal generator gets messy in (d) and (e).\n\ntheorem M1F_Sheet01_Q05d_is_true: ({1,2}:zfc) ⊆ A := sorry\ntheorem M1F_Sheet01_Q05d_is_false: ({1,2}:zfc) ⊆ A := sorry\n\ntheorem M1F_Sheet01_Q05e_is_true: ({1,2,1}:zfc) ⊆ A := sorry\ntheorem M1F_Sheet01_Q05e_is_false: ({1,2,1}:zfc) ⊈ A := sorry\n\ntheorem M1F_Sheet01_Q05f_is_true: ({1,1}:zfc) ∈ A := sorry\ntheorem M1F_Sheet01_Q05f_is_false: ({1,1}:zfc) ∉ A := sorry\n\ntheorem M1F_Sheet01_Q05g_is_true: A ∈ A := sorry\ntheorem M1F_Sheet01_Q05g_is_false: A ∉ A := sorry\n\ntheorem M1F_Sheet01_Q05h_is_true: A ⊇ A := sorry\ntheorem M1F_Sheet01_Q05h_is_false: A ⊉ 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/0105/Q0105.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7583969112108211}}
{"text": "import game.limits.L01defs\nimport game.limits.seq_limitLinear\n\nopen real\n\nnamespace xena -- hide\n\nnotation `|` x `|` := abs x -- hide\n\n/-\nUse previous results to obtain the limit of a product if individual limits\nfor the factors are both zero.\n-/\n\n\n/- Lemma\nIf $\\lim_{n \\to \\infty} a_n = 0$ and $\\lim_{n \\to \\infty} b_n = 0$,\nthen \n$\\lim_{n \\to \\infty} ( a_n * b_n) = 0$\n-/\nlemma lim_zero_prod (a : ℕ → ℝ) (b : ℕ → ℝ)\n    (ha : is_limit a 0) (hb : is_limit b 0) : \n    is_limit ( λ n, (a n) * (b n) ) 0 :=\nbegin\n    unfold is_limit,\n    intros ε hε,\n    set sε := sqrt ε with hsε, \n    have h1 : 0 < sε, from  real.sqrt_pos.mpr hε,\n    have Ha := ha sε h1,\n    have Hb := hb sε h1,\n    cases Ha with Na hNa,\n    cases Hb with Nb hNb,\n    set N := max Na Nb with hN,\n    use N,\n    intros n hn,\n    have Ha := hNa n (le_of_max_le_left hn),\n    have Hb := hNb n (le_of_max_le_right hn),\n    rw sub_zero at *, rw abs_mul, \n    have g1 := mul_lt_mul_of_pos_right Hb h1,\n    have g2 : sε ^ 2 = ε, exact sqr_sqrt( le_of_lt hε),\n    have g3 : sε * sε = sε ^2, ring,\n    rw g3 at g1, rw g2 at g1, rw mul_comm at g1,\n    have hbn : 0 ≤ |b n|, exact is_absolute_value.abv_nonneg abs (b n),\n    have G := mul_le_mul_of_nonneg_right (le_of_lt Ha) hbn,\n    exact lt_of_le_of_lt G g1, -- linarith fails!\n    done\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/limits/seq_limitZeroProd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7583969092776595}}
{"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\nimport lemmas2\nnoncomputable theory\n\nopen nat nat.modeq zmod euclidean_domain lemmas2\nnamespace defs_lemmas\n\n\n/- DEFINITIONS -/\n\n\n/--\nA structure for a congruence x ≡ a [MOD n] \n-/\ndef cong := (Σ (n : ℕ), zmod n)\n\n/--\nA list of congruence relations \n-/\ndef congruences := list cong\n\n/-Examples of above definitions \n def x : cong := ⟨5, ↑2⟩\n def y : congruences := [⟨5, ↑2⟩ , ⟨3, ↑2⟩]\n-/\n\n\n/- LIST PROPERTIES -/\n\n\n/--\nAll moduli for the congruences in the list are pairwise coprime \n-/\ndef pairwise_coprime  (l : congruences) : Prop := \n            list.pairwise (λ (x y : cong), nat.coprime x.1 y.1) l\n\n/--\nAll moduli for the congruences in the list are nonzero \n-/\ndef nonzero_cong ( l : congruences) : Prop :=\n            list.all l (λ (c : cong), 0 < c.1)  \n\n/--\nDefines when x is a solution to the list of congruences in l \n-/\ndef solution (x : ℕ) (l : congruences) : Prop := \n            list.all l (λ (c : cong), modeq c.1 x c.2.val)\n\n/--\nTakes the product of the defining moduli of all congruences in the list \n-/\ndef cong_prod : congruences → ℕ\n    | list.nil := 1\n    | (h :: t) := h.1 * cong_prod t\n--\n\n\n/- LEMMAS ABOUT LIST PROPERTIES -/\n\n\n/-- \nIf a list satisfies nonzero_cong, so does the tail and the head has nonzero moduli\n-/\nlemma subset_nonzero (c : cong) (l : list cong) (H : nonzero_cong (c :: l)) :\n                                 0 < c.1 ∧ nonzero_cong l :=\nbegin\n    unfold nonzero_cong at H, \n    rw list.all_iff_forall_prop at H, \n    split, \n    { exact H c (by exact list.mem_cons_self c l), },\n    {   unfold nonzero_cong, \n        rw list.all_iff_forall_prop,\n        rintros a ha, \n        exact H a (by exact list.mem_cons_of_mem _ ha), }\nend \n\n/--\nIf a list satisfies pairwise_coprime the head is coprime to all \nmoduli in the tail and the tail satisfies pairwise_coprime \n-/\nlemma subset_coprime (c : cong) (l : list cong) (H : pairwise_coprime (c :: l)) :\n                (∀ (a : cong), a ∈ l → coprime c.1 a.1) ∧ pairwise_coprime l :=\nbegin\n    unfold pairwise_coprime at H,\n    rw list.pairwise_cons at H, \n    exact H,\nend\n\n/--\nThe modulus for an element of list of congruences will divide the \ncong_prod of the list, the product of all moduli in the list \n-/\nlemma mem_div_prod (l : list cong) (a : cong) (H : a ∈ l) : a.1 ∣ cong_prod l :=\nbegin\n    induction l with head tail ihtail,\n     --nil case\n    exfalso,\n    exact H,\n    --induction case\n    dsimp[cong_prod],\n    cases H,\n    rw H,\n    simp only [nat.dvd_mul_right],\n    specialize ihtail H,\n    cases ihtail with c hc,\n    rw hc,\n    rw mul_comm,\n    use c * head.fst,\n    ring,\nend\n \n\n/-  LEMMAS ABOUT CONG_PROD OUTPUTS -/ \n\n\n/--\n Given a list of congruences with nonzero (i.e. positive) \n   moduli, the product of those moduli will be positive \n-/\nlemma pos_prod (l : congruences) (H : nonzero_cong l) : 0 < cong_prod l :=\nbegin\n    induction l with head tail ihtail,\n    {   dsimp [cong_prod],\n        linarith, },\n    {   have nonzero_parts := subset_nonzero head tail H,\n        specialize ihtail nonzero_parts.right,\n        dsimp [cong_prod],\n        exact mul_pos nonzero_parts.left ihtail,}\nend\n\n/--\nThe modulus of the first congruence is coprime to the product of the moduli of \nthe tail of the list assuming that the entire list satisfies pairwise_coprime\n-/\nlemma coprime_prod (c : cong) (l : list cong) (H : pairwise_coprime (c :: l)) :\n                             coprime c.1 (cong_prod l) :=\nbegin\n    induction l with head tail ihtail,\n    {   dsimp[cong_prod],\n        by exact c.fst.coprime_one_right, },\n    {   dsimp[cong_prod],\n        apply nat.coprime.mul_right,\n        exact (subset_coprime c (head :: tail) H).left head (by exact list.mem_cons_self head tail),\n        apply ihtail,\n        unfold pairwise_coprime at *, \n        rw list.pairwise_cons at *, \n        split, \n        intros a ha, \n        refine H.left a (by exact list.mem_cons_of_mem head ha), \n        exact list.pairwise_of_pairwise_cons H.right, },\nend \n\nend defs_lemmas\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/defs_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7583968996703746}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\n\n\n# Advanced proposition world.\n\n## Level 2: the `cases` tactic.\n\nIf `P ∧ Q` is in the goal, then we can make progress with `constructor`. But what if `P ∧ Q` is a\nhypothesis?\n\nThe lemma below asks us to prove `P ∧ Q → Q ∧ P`, that is, symmetry of the \"and\" relation. The\nobvious first move is\n\n`intro h`\n\nbecause the goal is an implication and this tactic is guaranteed to make progress. Now `h : P ∧ Q`\nis a hypothesis, and we can extract the parts of this `And.intro` using the [`cases` tactic](../Tactics/cases.lean.md)\n\n`cases h with`\n\nThis will give us two hypotheses `p` and `q` proving `P` and `Q` respectively.  So we hold onto\nthese, the goal is now `⊢ Q ∧ P` which we can split using the `constructor` tactic, then we can\neasily pick off the two sub-goals `⊢ Q` and  `⊢ P` using `q` and `p` respectively.\n\n## Lemma\nIf `P` and `Q` are true/false statements, then `P ∧ Q ⟹ Q ∧ P`.\n-/\nlemma and_symm (P Q : Prop) : P ∧ Q → Q ∧ P := by\n  intro h\n  cases h with\n  | intro p q =>\n    constructor\n    exact q\n    exact p\n\n/-!\n\n\nNext up [Level 3](./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/AdvancedPropositionWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7583968977177054}}
{"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\n! This file was ported from Lean 3 source module algebra.add_torsor\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.Set.Pointwise.SMul\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 `+ᵥ` for adding a group element to a point and\n`-ᵥ` 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 +ᵥ p` is a notation for `VAdd.vadd`, the left action of an additive monoid;\n\n* `p₁ -ᵥ p₂` is a notation for `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\n/-- An `AddTorsor G P` gives a structure to the nonempty type `P`,\nacted on by an `AddGroup G` with a transitive and free action given\nby the `+ᵥ` operation and a corresponding subtraction given by the\n`-ᵥ` operation. In the case of a vector space, it is an affine\nspace. -/\nclass AddTorsor (G : outParam (Type _)) (P : Type _) [outParam <| AddGroup G] extends AddAction G P,\n  VSub G P where\n  [Nonempty : Nonempty P]\n  /-- Torsor subtraction and addition with the same element cancels out. -/\n  vsub_vadd' : ∀ p1 p2 : P, (p1 -ᵥ p2 : G) +ᵥ p2 = p1\n  /-- Torsor addition and subtraction with the same element cancels out. -/\n  vadd_vsub' : ∀ (g : G) (p : P), g +ᵥ p -ᵥ p = g\n#align add_torsor AddTorsor\n\nattribute [instance] AddTorsor.Nonempty -- porting note: removers `nolint instance_priority`\n\n--Porting note: removed\n--attribute [nolint dangerous_instance] AddTorsor.toVSub\n\n/-- An `AddGroup G` is a torsor for itself. -/\n--@[nolint instance_priority] Porting note: linter does not exist\ninstance addGroupIsAddTorsor (G : Type _) [AddGroup G] : AddTorsor G G\n    where\n  vsub := Sub.sub\n  vsub_vadd' := sub_add_cancel\n  vadd_vsub' := add_sub_cancel\n#align add_group_is_add_torsor addGroupIsAddTorsor\n\n/-- Simplify subtraction for a torsor for an `AddGroup G` over\nitself. -/\n@[simp]\ntheorem vsub_eq_sub {G : Type _} [AddGroup G] (g1 g2 : G) : g1 -ᵥ g2 = g1 - g2 :=\n  rfl\n#align vsub_eq_sub vsub_eq_sub\n\nsection General\n\nvariable {G : Type _} {P : Type _} [AddGroup G] [T : AddTorsor G P]\n\n/-- Adding the result of subtracting from another point produces that\npoint. -/\n@[simp]\ntheorem vsub_vadd (p1 p2 : P) : p1 -ᵥ p2 +ᵥ p2 = p1 :=\n  AddTorsor.vsub_vadd' p1 p2\n#align vsub_vadd vsub_vadd\n\n/-- Adding a group element then subtracting the original point\nproduces that group element. -/\n@[simp]\ntheorem vadd_vsub (g : G) (p : P) : g +ᵥ p -ᵥ p = g :=\n  AddTorsor.vadd_vsub' g p\n#align vadd_vsub vadd_vsub\n\n/-- If the same point added to two group elements produces equal\nresults, those group elements are equal. -/\ntheorem vadd_right_cancel {g1 g2 : G} (p : P) (h : g1 +ᵥ p = g2 +ᵥ p) : g1 = g2 := by\n-- Porting note: vadd_vsub g₁ → vadd_vsub g₁ p\n  rw [← vadd_vsub g1 p, h, vadd_vsub]\n#align vadd_right_cancel vadd_right_cancel\n\n@[simp]\ntheorem vadd_right_cancel_iff {g1 g2 : G} (p : P) : g1 +ᵥ p = g2 +ᵥ p ↔ g1 = g2 :=\n  ⟨vadd_right_cancel p, fun h => h ▸ rfl⟩\n#align vadd_right_cancel_iff vadd_right_cancel_iff\n\n/-- Adding a group element to the point `p` is an injective\nfunction. -/\ntheorem vadd_right_injective (p : P) : Function.Injective ((· +ᵥ p) : G → P) := fun _ _ =>\n  vadd_right_cancel p\n#align vadd_right_injective vadd_right_injective\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. -/\ntheorem vadd_vsub_assoc (g : G) (p1 p2 : P) : g +ᵥ p1 -ᵥ p2 = g + (p1 -ᵥ p2) :=\n  by\n  apply vadd_right_cancel p2\n  rw [vsub_vadd, add_vadd, vsub_vadd]\n#align vadd_vsub_assoc vadd_vsub_assoc\n\n/-- Subtracting a point from itself produces 0. -/\n@[simp]\ntheorem vsub_self (p : P) : p -ᵥ p = (0 : G) := by\n  rw [← zero_add (p -ᵥ p), ← vadd_vsub_assoc, vadd_vsub]\n#align vsub_self vsub_self\n\n/-- If subtracting two points produces 0, they are equal. -/\ntheorem eq_of_vsub_eq_zero {p1 p2 : P} (h : p1 -ᵥ p2 = (0 : G)) : p1 = p2 := by\n  rw [← vsub_vadd p1 p2, h, zero_vadd]\n#align eq_of_vsub_eq_zero eq_of_vsub_eq_zero\n\n/-- Subtracting two points produces 0 if and only if they are\nequal. -/\n@[simp]\ntheorem vsub_eq_zero_iff_eq {p1 p2 : P} : p1 -ᵥ p2 = (0 : G) ↔ p1 = p2 :=\n  Iff.intro eq_of_vsub_eq_zero fun h => h ▸ vsub_self _\n#align vsub_eq_zero_iff_eq vsub_eq_zero_iff_eq\n\ntheorem vsub_ne_zero {p q : P} : p -ᵥ q ≠ (0 : G) ↔ p ≠ q :=\n  not_congr vsub_eq_zero_iff_eq\n#align vsub_ne_zero vsub_ne_zero\n\n/-- Cancellation adding the results of two subtractions. -/\n@[simp]\ntheorem vsub_add_vsub_cancel (p1 p2 p3 : P) : p1 -ᵥ p2 + (p2 -ᵥ p3) = p1 -ᵥ p3 :=\n  by\n  apply vadd_right_cancel p3\n  rw [add_vadd, vsub_vadd, vsub_vadd, vsub_vadd]\n#align vsub_add_vsub_cancel vsub_add_vsub_cancel\n\n/-- Subtracting two points in the reverse order produces the negation\nof subtracting them. -/\n@[simp]\ntheorem neg_vsub_eq_vsub_rev (p1 p2 : P) : -(p1 -ᵥ p2) = p2 -ᵥ p1 :=\n  by\n  refine' neg_eq_of_add_eq_zero_right (vadd_right_cancel p1 _)\n  rw [vsub_add_vsub_cancel, vsub_self]\n#align neg_vsub_eq_vsub_rev neg_vsub_eq_vsub_rev\n\ntheorem vadd_vsub_eq_sub_vsub (g : G) (p q : P) : g +ᵥ p -ᵥ q = g - (q -ᵥ p) := by\n  rw [vadd_vsub_assoc, sub_eq_add_neg, neg_vsub_eq_vsub_rev]\n#align vadd_vsub_eq_sub_vsub vadd_vsub_eq_sub_vsub\n\n/-- Subtracting the result of adding a group element produces the same result\nas subtracting the points and subtracting that group element. -/\ntheorem vsub_vadd_eq_vsub_sub (p1 p2 : P) (g : G) : p1 -ᵥ (g +ᵥ p2) = p1 -ᵥ p2 - g := by\n  rw [← add_right_inj (p2 -ᵥ p1 : G), vsub_add_vsub_cancel, ← neg_vsub_eq_vsub_rev, vadd_vsub, ←\n    add_sub_assoc, ← neg_vsub_eq_vsub_rev, neg_add_self, zero_sub]\n#align vsub_vadd_eq_vsub_sub vsub_vadd_eq_vsub_sub\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp]\ntheorem vsub_sub_vsub_cancel_right (p1 p2 p3 : P) : p1 -ᵥ p3 - (p2 -ᵥ p3) = p1 -ᵥ p2 := by\n  rw [← vsub_vadd_eq_vsub_sub, vsub_vadd]\n#align vsub_sub_vsub_cancel_right vsub_sub_vsub_cancel_right\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. -/\ntheorem eq_vadd_iff_vsub_eq (p1 : P) (g : G) (p2 : P) : p1 = g +ᵥ p2 ↔ p1 -ᵥ p2 = g :=\n  ⟨fun h => h.symm ▸ vadd_vsub _ _, fun h => h ▸ (vsub_vadd _ _).symm⟩\n#align eq_vadd_iff_vsub_eq eq_vadd_iff_vsub_eq\n\ntheorem vadd_eq_vadd_iff_neg_add_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} :\n    v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ -v₁ + v₂ = p₁ -ᵥ p₂ := by\n  rw [eq_vadd_iff_vsub_eq, vadd_vsub_assoc, ← add_right_inj (-v₁), neg_add_cancel_left, eq_comm]\n#align vadd_eq_vadd_iff_neg_add_eq_vsub vadd_eq_vadd_iff_neg_add_eq_vsub\n\nnamespace Set\n\nopen Pointwise\n\n-- Porting note: simp can prove this\n--@[simp]\ntheorem singleton_vsub_self (p : P) : ({p} : Set P) -ᵥ {p} = {(0 : G)} := by\n  rw [Set.singleton_vsub_singleton, vsub_self]\n#align set.singleton_vsub_self Set.singleton_vsub_self\n\nend Set\n\n@[simp]\ntheorem vadd_vsub_vadd_cancel_right (v₁ v₂ : G) (p : P) : v₁ +ᵥ p -ᵥ (v₂ +ᵥ p) = v₁ - v₂ := by\n  rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, vsub_self, add_zero]\n#align vadd_vsub_vadd_cancel_right vadd_vsub_vadd_cancel_right\n\n/-- If the same point subtracted from two points produces equal\nresults, those points are equal. -/\ntheorem vsub_left_cancel {p1 p2 p : P} (h : p1 -ᵥ p = p2 -ᵥ p) : p1 = p2 := by\n  rwa [← sub_eq_zero, vsub_sub_vsub_cancel_right, vsub_eq_zero_iff_eq] at h\n#align vsub_left_cancel vsub_left_cancel\n\n/-- The same point subtracted from two points produces equal results\nif and only if those points are equal. -/\n@[simp]\ntheorem vsub_left_cancel_iff {p1 p2 p : P} : p1 -ᵥ p = p2 -ᵥ p ↔ p1 = p2 :=\n  ⟨vsub_left_cancel, fun h => h ▸ rfl⟩\n#align vsub_left_cancel_iff vsub_left_cancel_iff\n\n/-- Subtracting the point `p` is an injective function. -/\ntheorem vsub_left_injective (p : P) : Function.Injective ((· -ᵥ p) : P → G) := fun _ _ =>\n  vsub_left_cancel\n#align vsub_left_injective vsub_left_injective\n\n/-- If subtracting two points from the same point produces equal\nresults, those points are equal. -/\ntheorem vsub_right_cancel {p1 p2 p : P} (h : p -ᵥ p1 = p -ᵥ p2) : p1 = p2 :=\n  by\n  refine' vadd_left_cancel (p -ᵥ p2) _\n  rw [vsub_vadd, ← h, vsub_vadd]\n#align vsub_right_cancel vsub_right_cancel\n\n/-- Subtracting two points from the same point produces equal results\nif and only if those points are equal. -/\n@[simp]\ntheorem vsub_right_cancel_iff {p1 p2 p : P} : p -ᵥ p1 = p -ᵥ p2 ↔ p1 = p2 :=\n  ⟨vsub_right_cancel, fun h => h ▸ rfl⟩\n#align vsub_right_cancel_iff vsub_right_cancel_iff\n\n/-- Subtracting a point from the point `p` is an injective\nfunction. -/\ntheorem vsub_right_injective (p : P) : Function.Injective ((p -ᵥ ·) : P → G) := fun _ _ =>\n  vsub_right_cancel\n#align vsub_right_injective vsub_right_injective\n\nend General\n\nsection comm\n\nvariable {G : Type _} {P : Type _} [AddCommGroup G] [AddTorsor G P]\n\n-- Porting note: Removed:\n-- include G\n\n/-- Cancellation subtracting the results of two subtractions. -/\n@[simp]\ntheorem vsub_sub_vsub_cancel_left (p1 p2 p3 : P) : p3 -ᵥ p2 - (p3 -ᵥ p1) = p1 -ᵥ p2 := by\n  rw [sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm, vsub_add_vsub_cancel]\n#align vsub_sub_vsub_cancel_left vsub_sub_vsub_cancel_left\n\n@[simp]\ntheorem vadd_vsub_vadd_cancel_left (v : G) (p1 p2 : P) : v +ᵥ p1 -ᵥ (v +ᵥ p2) = p1 -ᵥ p2 := by\n  rw [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub_cancel']\n#align vadd_vsub_vadd_cancel_left vadd_vsub_vadd_cancel_left\n\ntheorem vsub_vadd_comm (p1 p2 p3 : P) : (p1 -ᵥ p2 : G) +ᵥ p3 = p3 -ᵥ p2 +ᵥ p1 := by\n  rw [← @vsub_eq_zero_iff_eq G, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub]\n  simp\n#align vsub_vadd_comm vsub_vadd_comm\n\ntheorem vadd_eq_vadd_iff_sub_eq_vsub {v₁ v₂ : G} {p₁ p₂ : P} :\n    v₁ +ᵥ p₁ = v₂ +ᵥ p₂ ↔ v₂ - v₁ = p₁ -ᵥ p₂ := by\n  rw [vadd_eq_vadd_iff_neg_add_eq_vsub, neg_add_eq_sub]\n#align vadd_eq_vadd_iff_sub_eq_vsub vadd_eq_vadd_iff_sub_eq_vsub\n\ntheorem vsub_sub_vsub_comm (p₁ p₂ p₃ p₄ : P) : p₁ -ᵥ p₂ - (p₃ -ᵥ p₄) = p₁ -ᵥ p₃ - (p₂ -ᵥ p₄) := by\n  rw [← vsub_vadd_eq_vsub_sub, vsub_vadd_comm, vsub_vadd_eq_vsub_sub]\n#align vsub_sub_vsub_comm vsub_sub_vsub_comm\n\nend comm\n\nnamespace Prod\n\nvariable {G : Type _} {P : Type _} {G' : Type _} {P' : Type _} [AddGroup G] [AddGroup G']\n  [AddTorsor G P] [AddTorsor G' P']\n\n-- Porting note: the `{_ : ...}` instance terms make this instance not dangerous\ninstance {G : Type _} {P : Type _} {G' : Type _} {P' : Type _} {_ : AddGroup G} {_ : AddGroup G'}\n    [AddTorsor G P] [AddTorsor G' P'] : AddTorsor (G × G') (P × P') where\n  vadd v p := (v.1 +ᵥ p.1, v.2 +ᵥ p.2)\n  zero_vadd _ := Prod.ext (zero_vadd _ _) (zero_vadd _ _)\n  add_vadd _ _ _ := Prod.ext (add_vadd _ _ _) (add_vadd _ _ _)\n  vsub p₁ p₂ := (p₁.1 -ᵥ p₂.1, p₁.2 -ᵥ p₂.2)\n  Nonempty := Prod.Nonempty\n  vsub_vadd' _ _ := Prod.ext (vsub_vadd _ _) (vsub_vadd _ _)\n  vadd_vsub' _ _ := Prod.ext (vadd_vsub _ _) (vadd_vsub _ _)\n\n-- Porting note: The proofs above used to be shorter:\n-- zero_vadd p := by simp ⊢ 0 +ᵥ p = p\n-- add_vadd := by simp [add_vadd] ⊢ ∀ (a : G) (b : G') (a_1 : G) (b_1 : G') (a_2 : P) (b_2 : P'),\n--  (a + a_1, b + b_1) +ᵥ (a_2, b_2) = (a, b) +ᵥ ((a_1, b_1) +ᵥ (a_2, b_2))\n-- vsub_vadd' p₁ p₂ := show (p₁.1 -ᵥ p₂.1 +ᵥ p₂.1, _) = p₁ by simp\n--   ⊢ (p₁.fst -ᵥ p₂.fst +ᵥ p₂.fst, ((p₁.fst -ᵥ p₂.fst, p₁.snd -ᵥ p₂.snd) +ᵥ p₂).snd) = p₁\n-- vadd_vsub' v p := show (v.1 +ᵥ p.1 -ᵥ p.1, v.2 +ᵥ p.2 -ᵥ p.2) = v by simp\n--   ⊢ (v.fst +ᵥ p.fst -ᵥ p.fst, v.snd) = v\n\n@[simp]\ntheorem fst_vadd (v : G × G') (p : P × P') : (v +ᵥ p).1 = v.1 +ᵥ p.1 :=\n  rfl\n#align prod.fst_vadd Prod.fst_vadd\n\n@[simp]\ntheorem snd_vadd (v : G × G') (p : P × P') : (v +ᵥ p).2 = v.2 +ᵥ p.2 :=\n  rfl\n#align prod.snd_vadd Prod.snd_vadd\n\n@[simp]\ntheorem mk_vadd_mk (v : G) (v' : G') (p : P) (p' : P') : (v, v') +ᵥ (p, p') = (v +ᵥ p, v' +ᵥ p') :=\n  rfl\n#align prod.mk_vadd_mk Prod.mk_vadd_mk\n\n@[simp]\ntheorem fst_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').1 = p₁.1 -ᵥ p₂.1 :=\n  rfl\n#align prod.fst_vsub Prod.fst_vsub\n\n@[simp]\ntheorem snd_vsub (p₁ p₂ : P × P') : (p₁ -ᵥ p₂ : G × G').2 = p₁.2 -ᵥ p₂.2 :=\n  rfl\n#align prod.snd_vsub Prod.snd_vsub\n\n@[simp]\ntheorem mk_vsub_mk (p₁ p₂ : P) (p₁' p₂' : P') :\n    ((p₁, p₁') -ᵥ (p₂, p₂') : G × G') = (p₁ -ᵥ p₂, p₁' -ᵥ p₂') :=\n  rfl\n#align prod.mk_vsub_mk Prod.mk_vsub_mk\n\nend Prod\n\nnamespace Pi\n\nuniverse u v w\n\nvariable {I : Type u} {fg : I → Type v} [∀ i, AddGroup (fg i)] {fp : I → Type w}\n\nopen AddAction AddTorsor\n\n/-- A product of `AddTorsor`s is an `AddTorsor`. -/\ninstance [T : ∀ i, AddTorsor (fg i) (fp i)] : AddTorsor (∀ i, fg i) (∀ i, fp i) where\n  vadd g p i := g i +ᵥ p i\n  zero_vadd p := funext fun i => zero_vadd (fg i) (p i)\n  add_vadd g₁ g₂ p := funext fun i => add_vadd (g₁ i) (g₂ i) (p i)\n  vsub p₁ p₂ i := p₁ i -ᵥ p₂ i\n  Nonempty := ⟨fun i => Classical.choice (T i).Nonempty⟩\n  vsub_vadd' p₁ p₂ := funext fun i => vsub_vadd (p₁ i) (p₂ i)\n  vadd_vsub' g p := funext fun i => vadd_vsub (g i) (p i)\n\nend Pi\n\nnamespace Equiv\n\nvariable {G : Type _} {P : Type _} [AddGroup G] [AddTorsor G P]\n\n-- Porting note: Removed:\n-- include G\n\n/-- `v ↦ v +ᵥ p` as an equivalence. -/\ndef vaddConst (p : P) : G ≃ P where\n  toFun v := v +ᵥ p\n  invFun p' := p' -ᵥ p\n  left_inv _ := vadd_vsub _ _\n  right_inv _ := vsub_vadd _ _\n#align equiv.vadd_const Equiv.vaddConst\n\n@[simp]\ntheorem coe_vaddConst (p : P) : ⇑(vaddConst p) = fun v => v +ᵥ p :=\n  rfl\n#align equiv.coe_vadd_const Equiv.coe_vaddConst\n\n@[simp]\n\n\n/-- `p' ↦ p -ᵥ p'` as an equivalence. -/\ndef constVSub (p : P) : P ≃ G where\n  toFun := (· -ᵥ ·) p\n  invFun v := -v +ᵥ p\n  left_inv p' := by simp\n  right_inv v := by simp [vsub_vadd_eq_vsub_sub]\n#align equiv.const_vsub Equiv.constVSub\n\n@[simp]\ntheorem coe_constVSub (p : P) : ⇑(constVSub p) = (· -ᵥ ·) p :=\n  rfl\n#align equiv.coe_const_vsub Equiv.coe_constVSub\n\n@[simp]\ntheorem coe_constVSub_symm (p : P) : ⇑(constVSub p).symm = fun (v : G) => -v +ᵥ p :=\n  rfl\n#align equiv.coe_const_vsub_symm Equiv.coe_constVSub_symm\n\nvariable (P)\n\n/-- The permutation given by `p ↦ v +ᵥ p`. -/\ndef constVAdd (v : G) : Equiv.Perm P where\n  toFun := (· +ᵥ ·) v\n  invFun := (· +ᵥ ·) (-v)\n  left_inv p := by simp [vadd_vadd]\n  right_inv p := by simp [vadd_vadd]\n#align equiv.const_vadd Equiv.constVAdd\n\n@[simp]\ntheorem coe_constVAdd (v : G) : ⇑(constVAdd P v) = (· +ᵥ ·) v :=\n  rfl\n#align equiv.coe_const_vadd Equiv.coe_constVAdd\n\nvariable (G)\n\n@[simp]\ntheorem constVAdd_zero : constVAdd P (0 : G) = 1 :=\n  ext <| zero_vadd G\n#align equiv.const_vadd_zero Equiv.constVAdd_zero\n\nvariable {G}\n\n@[simp]\ntheorem constVAdd_add (v₁ v₂ : G) : constVAdd P (v₁ + v₂) = constVAdd P v₁ * constVAdd P v₂ :=\n  ext <| add_vadd v₁ v₂\n#align equiv.const_vadd_add Equiv.constVAdd_add\n\n/-- `Equiv.constVAdd` as a homomorphism from `Multiplicative G` to `Equiv.perm P` -/\ndef constVAddHom : Multiplicative G →* Equiv.Perm P where\n  toFun v := constVAdd P (Multiplicative.toAdd v)\n  map_one' := constVAdd_zero G P\n  map_mul' := constVAdd_add P\n#align equiv.const_vadd_hom Equiv.constVAddHom\n\nvariable {P}\n\n-- Porting note: Previous code was:\n-- open _Root_.Function\nopen Function\n\n/-- Point reflection in `x` as a permutation. -/\ndef pointReflection (x : P) : Perm P :=\n  (constVSub x).trans (vaddConst x)\n#align equiv.point_reflection Equiv.pointReflection\n\ntheorem pointReflection_apply (x y : P) : pointReflection x y = x -ᵥ y +ᵥ x :=\n  rfl\n#align equiv.point_reflection_apply Equiv.pointReflection_apply\n\n@[simp]\ntheorem pointReflection_symm (x : P) : (pointReflection x).symm = pointReflection x :=\n  ext <| by simp [pointReflection]\n#align equiv.point_reflection_symm Equiv.pointReflection_symm\n\n@[simp]\ntheorem pointReflection_self (x : P) : pointReflection x x = x :=\n  vsub_vadd _ _\n#align equiv.point_reflection_self Equiv.pointReflection_self\n\ntheorem pointReflection_involutive (x : P) : Involutive (pointReflection x : P → P) := fun y =>\n  (Equiv.apply_eq_iff_eq_symm_apply _).2 <| by rw [pointReflection_symm]\n#align equiv.point_reflection_involutive Equiv.pointReflection_involutive\n\nset_option linter.deprecated false\n/-- `x` is the only fixed point of `pointReflection x`. This lemma requires\n`x + x = y + y ↔ x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/\ntheorem pointReflection_fixed_iff_of_injective_bit0 {x y : P} (h : Injective (bit0 : G → G)) :\n    pointReflection x y = y ↔ y = x := by\n  rw [pointReflection_apply, eq_comm, eq_vadd_iff_vsub_eq, ← neg_vsub_eq_vsub_rev,\n    neg_eq_iff_add_eq_zero, ← bit0, ← bit0_zero, h.eq_iff, vsub_eq_zero_iff_eq, eq_comm]\n#align\n  equiv.point_reflection_fixed_iff_of_injective_bit0\n  Equiv.pointReflection_fixed_iff_of_injective_bit0\n\n-- Porting note: Removed:\n-- omit G\n\n-- Porting note: need this to calm down CI\ntheorem injective_pointReflection_left_of_injective_bit0 {G P : Type _} [AddCommGroup G]\n    [AddTorsor G P] (h : Injective (bit0 : G → G)) (y : P) :\n    Injective fun x : P => pointReflection x y :=\n  fun x₁ x₂ (hy : pointReflection x₁ y = pointReflection x₂ y) => by\n  rwa [pointReflection_apply, pointReflection_apply, vadd_eq_vadd_iff_sub_eq_vsub,\n    vsub_sub_vsub_cancel_right, ← neg_vsub_eq_vsub_rev, neg_eq_iff_add_eq_zero, ← bit0, ← bit0_zero,\n    h.eq_iff, vsub_eq_zero_iff_eq] at hy\n#align\n  equiv.injective_point_reflection_left_of_injective_bit0\n  Equiv.injective_pointReflection_left_of_injective_bit0\n\nend Equiv\n\ntheorem AddTorsor.subsingleton_iff (G P : Type _) [AddGroup G] [AddTorsor G P] :\n    Subsingleton G ↔ Subsingleton P := by\n  inhabit P\n  exact (Equiv.vaddConst default).subsingleton_congr\n#align add_torsor.subsingleton_iff AddTorsor.subsingleton_iff\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/AddTorsor.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.758364975140425}}
{"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 `ℤ`,\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 ε` sets, such that the remainders\nin each set are close together. -/\nlemma exists_partition_int (n : ℕ) {ε : ℝ} (hε : 0 < ε) {b : ℤ} (hb : b ≠ 0) (A : fin n → ℤ) :\n  ∃ (t : fin n → fin ⌈1 / ε⌉₊),\n  ∀ i₀ i₁, t i₀ = t i₁ → ↑(abs (A i₁ % b - A i₀ % b)) < abs b • ε :=\nbegin\n  have hb' : (0 : ℝ) < ↑(abs b) := int.cast_pos.mpr (abs_pos.mpr hb),\n  have hbε : 0 < abs b • ε,\n  { rw algebra.smul_def,\n    exact mul_pos hb' hε },\n  have hfloor : ∀ i, 0 ≤ floor ((A i % b : ℤ) / (abs b • ε) : ℝ),\n  { intro i,\n    exact floor_nonneg.mpr (div_nonneg (cast_nonneg.mpr (mod_nonneg _ hb)) hbε.le) },\n  refine ⟨λ i, ⟨nat_abs (floor ((A i % b : ℤ) / (abs b • ε) : ℝ)), _⟩, _⟩,\n  { rw [← 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, ← div_div_eq_div_mul, div_lt_div_right hε,\n        div_lt_iff hb', one_mul, cast_lt],\n    exact int.mod_lt _ hb },\n  intros i₀ i₁ hi,\n  have hi : (⌊↑(A i₀ % b) / abs b • ε⌋.nat_abs : ℤ) = ⌊↑(A i₁ % b) / abs b • ε⌋.nat_abs :=\n    congr_arg (coe : ℕ → ℤ) (subtype.mk_eq_mk.mp hi),\n  rw [nat_abs_of_nonneg (hfloor i₀), nat_abs_of_nonneg (hfloor i₁)] at hi,\n  have hi := abs_sub_lt_one_of_floor_eq_floor hi,\n  rw [abs_sub_comm, ← sub_div, abs_div, abs_of_nonneg hbε.le, div_lt_iff hbε, one_mul] at hi,\n  rwa [int.cast_abs, int.cast_sub]\nend\n\n/-- `abs : ℤ → ℤ` is an admissible absolute value -/\nnoncomputable def abs_is_admissible : is_admissible absolute_value.abs :=\n{ card := λ ε, ⌈1 / ε⌉₊,\n  exists_partition' := λ n ε hε b hb, exists_partition_int n hε hb,\n  .. absolute_value.abs_is_euclidean }\n\nnoncomputable instance : inhabited (is_admissible absolute_value.abs) :=\n⟨abs_is_admissible⟩\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/number_theory/class_number/admissible_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.8311430541321951, "lm_q1q2_score": 0.7583649711823577}}
{"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 \"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 ↔ commute b a :=\n⟨commute.symm, commute.symm⟩\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 [← 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₁ u₂ : Mˣ}\n\n@[simp, to_additive]\ntheorem pow_right (h : commute a b) (n : ℕ) : commute a (b ^ n) := h.pow_right n\n@[simp, to_additive]\ntheorem pow_left (h : commute a b) (n : ℕ) : commute (a ^ n) b := (h.symm.pow_right n).symm\n@[simp, to_additive]\ntheorem pow_pow (h : commute a b) (m n : ℕ) : commute (a ^ m) (b ^ n) :=\n(h.pow_left m).pow_right n\n\n@[simp, to_additive]\ntheorem self_pow (a : M) (n : ℕ) : commute a (a ^ n) := (commute.refl a).pow_right n\n@[simp, to_additive]\ntheorem pow_self (a : M) (n : ℕ) : commute (a ^ n) a := (commute.refl a).pow_left n\n@[simp, to_additive]\ntheorem pow_pow_self (a : M) (m n : ℕ) : 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 : ℕ) : 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 → commute a ↑u⁻¹ :=\nsemiconj_by.units_inv_right\n\n@[simp, to_additive] theorem units_inv_right_iff :\n  commute a ↑u⁻¹ ↔ commute a u :=\nsemiconj_by.units_inv_right_iff\n\n@[to_additive] theorem units_inv_left : commute ↑u a → commute ↑u⁻¹ a :=\nsemiconj_by.units_inv_symm_left\n\n@[simp, to_additive]\ntheorem units_inv_left_iff: commute ↑u⁻¹ a ↔ commute ↑u a :=\nsemiconj_by.units_inv_symm_left_iff\n\n@[to_additive]\ntheorem units_coe : commute u₁ u₂ → commute (u₁ : M) u₂ := semiconj_by.units_coe\n@[to_additive]\ntheorem units_of_coe : commute (u₁ : M) u₂ → commute u₁ u₂ := semiconj_by.units_of_coe\n@[simp, to_additive]\ntheorem units_coe_iff : commute (u₁ : M) u₂ ↔ commute u₁ u₂ := semiconj_by.units_coe_iff\n\n@[to_additive] lemma is_unit_mul_iff (h : commute a b) :\n  is_unit (a * b) ↔ is_unit a ∧ is_unit b :=\nbegin\n  refine ⟨_, λ H, H.1.mul H.2⟩,\n  rintro ⟨u, hu⟩,\n  have : b * ↑u⁻¹ * a = 1,\n  { have : commute a u := hu.symm ▸ (commute.refl _).mul_right h,\n    rw [← this.units_inv_right.right_comm, ← h.eq, ← hu, u.mul_inv] },\n  split,\n  { refine ⟨⟨a, b * ↑u⁻¹, _, this⟩, rfl⟩,\n    rw [← mul_assoc, ← hu, u.mul_inv] },\n  { rw mul_assoc at this,\n    refine ⟨⟨b, ↑u⁻¹ * a, this, _⟩, rfl⟩,\n    rw [mul_assoc, ← hu, u.inv_mul] }\nend\n\n@[simp, to_additive] lemma _root_.is_unit_mul_self_iff :\n  is_unit (a * a) ↔ 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 → commute a b⁻¹ := semiconj_by.inv_right\n@[simp, to_additive]\ntheorem inv_right_iff : commute a b⁻¹ ↔ commute a b := semiconj_by.inv_right_iff\n\n@[to_additive] theorem inv_left :  commute a b → commute a⁻¹ b := semiconj_by.inv_symm_left\n@[simp, to_additive]\ntheorem inv_left_iff : commute a⁻¹ b ↔ commute a b := semiconj_by.inv_symm_left_iff\n\n@[to_additive]\ntheorem inv_inv : commute a b → commute a⁻¹ b⁻¹ := semiconj_by.inv_inv_symm\n@[simp, to_additive]\ntheorem inv_inv_iff : commute a⁻¹ b⁻¹ ↔ commute a b := semiconj_by.inv_inv_symm_iff\n\n@[to_additive]\nprotected theorem inv_mul_cancel (h : commute a b) : a⁻¹ * 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⁻¹ * (b * a) = b :=\nby rw [← mul_assoc, h.inv_mul_cancel]\n\n@[to_additive]\nprotected theorem mul_inv_cancel (h : commute a b) : a * b * a⁻¹ = 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⁻¹) = b :=\nby rw [← 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⁻¹ = b :=\n(commute.all a b).mul_inv_cancel\n\n@[simp, to_additive] lemma mul_inv_cancel_comm_assoc : a * (b * a⁻¹) = b :=\n(commute.all a b).mul_inv_cancel_assoc\n\n@[simp, to_additive] lemma inv_mul_cancel_comm : a⁻¹ * b * a = b :=\n(commute.all a b).inv_mul_cancel\n\n@[simp, to_additive] lemma inv_mul_cancel_comm_assoc : a⁻¹ * (b * a) = b :=\n(commute.all a b).inv_mul_cancel_assoc\n\nend comm_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/algebra/group/commute.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91243616285804, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7583649657412942}}
{"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 order.zorn_atoms\n! leanprover-community/mathlib commit 9aba7801eeecebb61f58a5763c2b6dd1b47dc6ef\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.Order.Zorn\nimport Mathlib.Order.Atoms\n\n/-!\n# Zorn lemma for (co)atoms\n\nIn this file we use Zorn's lemma to prove that a partial order is atomic if every nonempty chain\n`c`, `⊥ ∉ c`, has a lower bound not equal to `⊥`. We also prove the order dual version of this\nstatement.\n-/\n\n\nopen Set\n\n/-- **Zorn's lemma**: A partial order is coatomic if every nonempty chain `c`, `⊤ ∉ c`, has an upper\nbound not equal to `⊤`. -/\ntheorem IsCoatomic.of_isChain_bounded {α : Type _} [PartialOrder α] [OrderTop α]\n    (h :\n      ∀ c : Set α,\n        IsChain (· ≤ ·) c → c.Nonempty → ⊤ ∉ c → ∃ (x : _)(_ : x ≠ ⊤), x ∈ upperBounds c) :\n    IsCoatomic α := by\n  refine ⟨fun x => le_top.eq_or_lt.imp_right fun hx => ?_⟩\n  have : ∃ y ∈ Ico x ⊤, x ≤ y ∧ ∀ z ∈ Ico x ⊤, y ≤ z → z = y := by\n    refine zorn_nonempty_partialOrder₀ (Ico x ⊤) (fun c hxc hc y hy => ?_) x (left_mem_Ico.2 hx)\n    rcases h c hc ⟨y, hy⟩ fun h => (hxc h).2.ne rfl with ⟨z, hz, hcz⟩\n    exact ⟨z, ⟨le_trans (hxc hy).1 (hcz hy), hz.lt_top⟩, hcz⟩\n  rcases this with ⟨y, ⟨hxy, hy⟩, -, hy'⟩\n  refine ⟨y, ⟨hy.ne, fun z hyz => le_top.eq_or_lt.resolve_right fun hz => ?_⟩, hxy⟩\n  exact hyz.ne' (hy' z ⟨hxy.trans hyz.le, hz⟩ hyz.le)\n#align is_coatomic.of_is_chain_bounded IsCoatomic.of_isChain_bounded\n\n/-- **Zorn's lemma**: A partial order is atomic if every nonempty chain `c`, `⊥ ∉ c`, has an lower\nbound not equal to `⊥`. -/\ntheorem IsAtomic.of_isChain_bounded {α : Type _} [PartialOrder α] [OrderBot α]\n    (h :\n      ∀ c : Set α,\n        IsChain (· ≤ ·) c → c.Nonempty → ⊥ ∉ c → ∃ (x : _)(_ : x ≠ ⊥), x ∈ lowerBounds c) :\n    IsAtomic α :=\n  isCoatomic_dual_iff_isAtomic.mp <| IsCoatomic.of_isChain_bounded fun c hc => h c hc.symm\n#align is_atomic.of_is_chain_bounded IsAtomic.of_isChain_bounded\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/ZornAtoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7583649597333308}}
{"text": "import tactic\nimport algebra.ring.equiv -- ring isomorphisms\n\n/-\n\n# Isomorphisms (of groups, rings, etc)\n\nIf `X` and `Y` are types, we have a type `X ≃ Y` of bijections\nfrom `X` to `Y`. If `X` and `Y` additionally have the structure\nof groups, or rings, or orders, or topological spaces, or...\nthen we can furthermore ask that the bijections preserves this\nstructure. \n\nJust like in the homomorphism case, we don't do this by making\nnew predicates like `is_group_isomorphism : G ≃ H → Prop`, we do this\nby making totally new types called things like `G ≃* H` (group\nisomorphisms), `A ≃+* B` (ring isomorphisms) and so on.\n \n-/\n\n-- let A and B be rings\nvariables (A B : Type) [ring A] [ring B]\n\n-- Here's the set of all ring isomorphisms from A to B\nexample : Type := A ≃+* B\n-- `A ≃+* B` is notation for `ring_equiv A B`. \n\n-- A ring isomorphism is magically a function\n\nexample (φ : A ≃+* B) (a : A) : B := φ a -- if you use this in a proof it will say ⇑φ a\n\n-- A ring isomorphism is magically a ring homomorphism\n\nexample (φ : A ≃+* B) (x y : A) : φ (x + y) = φ x + φ y := map_add φ x y\n\n-- You can compose two ring isomorphisms using ring_equiv.trans\n\n-- let C be another ring\nvariables (C : Type) [ring C]\n\n-- here using the power of dot notation\nexample (φ : A ≃+* B) (ψ : B ≃+* C) : A ≃+* C := φ.trans ψ\n\n-- How do you make a ring isomorphism from two invertible ring homomorphisms?\nexample (φ : A →+* B) (ψ : B →+* A) (h1 : ∀ a, ψ (φ a) = a) (h2 : ∀ b, φ (ψ b) = b) : A ≃+* B :=\n{ to_fun := φ,\n  inv_fun := ψ,\n  left_inv := h1,\n  right_inv := h2,\n  map_add' := φ.map_add,\n  map_mul' := φ.map_mul }\n\n-- Notice that `ring_equiv` *extends* `equiv`, so you need to fill in the `equiv` fields and then\n-- add in the proofs that `φ(a+b)=φ(a)+φ(b)` and `φ(ab)=φ(a)φ(b)`.\n\n-- Note that we never used that ψ was a ring homomorphism! It follows from the fact that ψ is a bijection\n-- whose inverse is a ring homomorphism. But of course Lean knows that the inverse of a ring\n-- isomorphism is a ring homomorphism -- it's just a theorem, rather than an axiom. \n\nexample (φ : A ≃+* B) (x y : B) : φ.symm (x * y) = φ.symm x * φ.symm y := map_mul φ.symm x y", "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/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7583449311499035}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Yury Kudryashov\n-/\nimport data.set.intervals.basic\nimport algebra.ordered_group\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 `∪`, `∩`, `insert`, and provide\nformulas for `∅`, `univ`, and intervals.\n-/\nopen set\n\nuniverses u v w x\nvariables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}\n\nsection\nvariables [preorder α] [preorder β] {s t : set α} {a b : α}\n\n/-!\n### Definitions\n-/\n\n/-- The set of upper bounds of a set. -/\ndef upper_bounds (s : set α) : set α := { x | ∀ ⦃a⦄, a ∈ s →  a ≤ x }\n/-- The set of lower bounds of a set. -/\ndef lower_bounds (s : set α) : set α := { x | ∀ ⦃a⦄, a ∈ s → x ≤ a }\n\n/-- A set is bounded above if there exists an upper bound. -/\ndef bdd_above (s : set α) := (upper_bounds s).nonempty\n/-- A set is bounded below if there exists a lower bound. -/\ndef bdd_below (s : set α) := (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 α) (a : α) : Prop := a ∈ s ∧ a ∈ 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 α) (a : α) : Prop := a ∈ s ∧ a ∈ 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 α) : α → 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 α) : α → Prop := is_greatest (lower_bounds s)\n\nlemma mem_upper_bounds : a ∈ upper_bounds s ↔ ∀ x ∈ s, x ≤ a := iff.rfl\n\nlemma mem_lower_bounds : a ∈ lower_bounds s ↔ ∀ x ∈ s, a ≤ x := iff.rfl\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`\nis not greater than or equal to `y`. This version only assumes `preorder` structure and uses\n`¬(y ≤ x)`. A version for linear orders is called `not_bdd_above_iff`. -/\nlemma not_bdd_above_iff' : ¬bdd_above s ↔ ∀ x, ∃ y ∈ s, ¬(y ≤ 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 ∈ s` such that `x`\nis not less than or equal to `y`. This version only assumes `preorder` structure and uses\n`¬(x ≤ y)`. A version for linear orders is called `not_bdd_below_iff`. -/\nlemma not_bdd_below_iff' : ¬bdd_below s ↔ ∀ x, ∃ y ∈ s, ¬(x ≤ y) :=\n@not_bdd_above_iff' (order_dual α) _ _\n\n/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater\nthan `x`. A version for preorders is called `not_bdd_above_iff'`. -/\nlemma not_bdd_above_iff {α : Type*} [linear_order α] {s : set α} :\n  ¬bdd_above s ↔ ∀ x, ∃ y ∈ 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 ∈ s` that is less\nthan `x`. A version for preorders is called `not_bdd_below_iff'`. -/\nlemma not_bdd_below_iff {α : Type*} [linear_order α] {s : set α} :\n  ¬bdd_below s ↔ ∀ x, ∃ y ∈ s, y < x :=\n@not_bdd_above_iff (order_dual α) _ _\n\n/-!\n### Monotonicity\n-/\n\nlemma upper_bounds_mono_set ⦃s t : set α⦄ (hst : s ⊆ t) :\n  upper_bounds t ⊆ upper_bounds s :=\nλ b hb x h, hb $ hst h\n\nlemma lower_bounds_mono_set ⦃s t : set α⦄ (hst : s ⊆ t) :\n  lower_bounds t ⊆ lower_bounds s :=\nλ b hb x h, hb $ hst h\n\nlemma upper_bounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upper_bounds s → b ∈ upper_bounds s :=\nλ ha x h, le_trans (ha h) hab\n\nlemma lower_bounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lower_bounds s → a ∈ lower_bounds s :=\nλ hb x h, le_trans hab (hb h)\n\nlemma upper_bounds_mono ⦃s t : set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :\n  a ∈ upper_bounds t → b ∈ upper_bounds s :=\nλ ha, upper_bounds_mono_set hst $ upper_bounds_mono_mem hab ha\n\nlemma lower_bounds_mono ⦃s t : set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :\n  b ∈ lower_bounds t → a ∈ lower_bounds s :=\nλ hb, lower_bounds_mono_set hst $ lower_bounds_mono_mem hab hb\n\n/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/\nlemma bdd_above.mono ⦃s t : set α⦄ (h : s ⊆ t) : bdd_above t → bdd_above s :=\nnonempty.mono $ upper_bounds_mono_set h\n\n/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/\nlemma bdd_below.mono ⦃s t : set α⦄ (h : s ⊆ t) : bdd_below t → 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 ⊆ t ⊆ p`. -/\nlemma is_lub.of_subset_of_superset {s t p : set α} (hs : is_lub s a) (hp : is_lub p a)\n  (hst : s ⊆ t) (htp : t ⊆ p) : is_lub t a :=\n⟨upper_bounds_mono_set htp hp.1, lower_bounds_mono_set (upper_bounds_mono_set hst) hs.2⟩\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 ⊆ t ⊆ p`. -/\nlemma is_glb.of_subset_of_superset {s t p : set α} (hs : is_glb s a) (hp : is_glb p a)\n  (hst : s ⊆ t) (htp : t ⊆ p) : is_glb t a :=\n@is_lub.of_subset_of_superset (order_dual α) _ a s t p hs hp hst htp\n\nlemma is_least.mono (ha : is_least s a) (hb : is_least t b) (hst : s ⊆ t) : b ≤ a :=\nhb.2 (hst ha.1)\n\nlemma is_greatest.mono (ha : is_greatest s a) (hb : is_greatest t b) (hst : s ⊆ t) : a ≤ b :=\nhb.2 (hst ha.1)\n\nlemma is_lub.mono (ha : is_lub s a) (hb : is_lub t b) (hst : s ⊆ t) : a ≤ 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 ⊆ t) : b ≤ a :=\nhb.mono ha $ lower_bounds_mono_set hst\n\n/-!\n### Conversions\n-/\n\nlemma is_least.is_glb (h : is_least s a) : is_glb s a := ⟨h.2, λ b hb, hb h.1⟩\n\nlemma is_greatest.is_lub (h : is_greatest s a) : is_lub s a := ⟨h.2, λ b hb, hb h.1⟩\n\nlemma is_lub.upper_bounds_eq (h : is_lub s a) : upper_bounds s = Ici a :=\nset.ext $ λ b, ⟨λ hb, h.2 hb, λ hb, upper_bounds_mono_mem hb h.1⟩\n\nlemma is_glb.lower_bounds_eq (h : is_glb s a) : lower_bounds s = Iic a :=\n@is_lub.upper_bounds_eq (order_dual α) _ _ _ h\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 ≤ b ↔ b ∈ upper_bounds s :=\nby { rw h.upper_bounds_eq, refl }\n\nlemma le_is_glb_iff (h : is_glb s a) : b ≤ a ↔ b ∈ lower_bounds s :=\nby { rw h.lower_bounds_eq, refl }\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 := ⟨a, h.1⟩\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 := ⟨a, h.1⟩\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 := ⟨a, h.2⟩\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 := ⟨a, h.2⟩\n\nlemma is_least.nonempty (h : is_least s a) : s.nonempty := ⟨a, h.1⟩\n\nlemma is_greatest.nonempty (h : is_greatest s a) : s.nonempty := ⟨a, h.1⟩\n\n/-!\n### Union and intersection\n-/\n\n@[simp] lemma upper_bounds_union : upper_bounds (s ∪ t) = upper_bounds s ∩ upper_bounds t :=\nsubset.antisymm\n  (λ b hb, ⟨λ x hx, hb (or.inl hx), λ x hx, hb (or.inr hx)⟩)\n  (λ b hb x hx, hx.elim (λ hs, hb.1 hs) (λ ht, hb.2 ht))\n\n@[simp] lemma lower_bounds_union : lower_bounds (s ∪ t) = lower_bounds s ∩ lower_bounds t :=\n@upper_bounds_union (order_dual α) _ s t\n\nlemma union_upper_bounds_subset_upper_bounds_inter :\n  upper_bounds s ∪ upper_bounds t ⊆ upper_bounds (s ∩ 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 ∪ lower_bounds t ⊆ lower_bounds (s ∩ t) :=\n@union_upper_bounds_subset_upper_bounds_inter (order_dual α) _ s t\n\nlemma is_least_union_iff {a : α} {s t : set α} :\n  is_least (s ∪ t) a ↔ (is_least s a ∧ a ∈ lower_bounds t ∨ a ∈ lower_bounds s ∧ is_least t a) :=\nby simp [is_least, lower_bounds_union, or_and_distrib_right, and_comm (a ∈ t), and_assoc]\n\nlemma is_greatest_union_iff :\n  is_greatest (s ∪ t) a ↔ (is_greatest s a ∧ a ∈ upper_bounds t ∨\n    a ∈ upper_bounds s ∧ is_greatest t a) :=\n@is_least_union_iff (order_dual α) _ a s t\n\n/-- If `s` is bounded, then so is `s ∩ t` -/\nlemma bdd_above.inter_of_left (h : bdd_above s) : bdd_above (s ∩ t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s ∩ t` -/\nlemma bdd_above.inter_of_right (h : bdd_above t) : bdd_above (s ∩ t) :=\nh.mono $ inter_subset_right s t\n\n/-- If `s` is bounded, then so is `s ∩ t` -/\nlemma bdd_below.inter_of_left (h : bdd_below s) : bdd_below (s ∩ t) :=\nh.mono $ inter_subset_left s t\n\n/-- If `t` is bounded, then so is `s ∩ t` -/\nlemma bdd_below.inter_of_right (h : bdd_below t) : bdd_below (s ∩ 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 ∪ t`. -/\nlemma bdd_above.union [semilattice_sup γ] {s t : set γ} :\n  bdd_above s → bdd_above t → bdd_above (s ∪ t) :=\nbegin\n  rintros ⟨bs, hs⟩ ⟨bt, ht⟩,\n  use bs ⊔ bt,\n  rw upper_bounds_union,\n  exact ⟨upper_bounds_mono_mem le_sup_left hs,\n    upper_bounds_mono_mem le_sup_right ht⟩\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 γ] {s t : set γ} :\n  bdd_above (s ∪ t) ↔ bdd_above s ∧ bdd_above t :=\n⟨λ h, ⟨h.mono $ subset_union_left s t, h.mono $ subset_union_right s t⟩,\n  λ h, h.1.union h.2⟩\n\nlemma bdd_below.union [semilattice_inf γ] {s t : set γ} :\n  bdd_below s → bdd_below t → bdd_below (s ∪ t) :=\n@bdd_above.union (order_dual γ) _ 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 γ] {s t : set γ} :\n  bdd_below (s ∪ t) ↔ bdd_below s ∧ bdd_below t :=\n@bdd_above_union (order_dual γ) _ s t\n\n/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,\nthen `a ⊔ b` is the least upper bound of `s ∪ t`. -/\nlemma is_lub.union [semilattice_sup γ] {a b : γ} {s t : set γ}\n  (hs : is_lub s a) (ht : is_lub t b) :\n  is_lub (s ∪ t) (a ⊔ b) :=\n⟨assume c h, h.cases_on (λ h, le_sup_left_of_le $ hs.left h) (λ h, le_sup_right_of_le $ ht.left h),\n  assume c hc, sup_le\n    (hs.right $ assume d hd, hc $ or.inl hd) (ht.right $ assume d hd, hc $ or.inr hd)⟩\n\n/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,\nthen `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/\nlemma is_glb.union [semilattice_inf γ] {a₁ a₂ : γ} {s t : set γ}\n  (hs : is_glb s a₁) (ht : is_glb t a₂) :\n  is_glb (s ∪ t) (a₁ ⊓ a₂) :=\n@is_lub.union (order_dual γ) _ _ _ _ _ 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 ∪ t`. -/\nlemma is_least.union [linear_order γ] {a b : γ} {s t : set γ}\n  (ha : is_least s a) (hb : is_least t b) : is_least (s ∪ t) (min a b) :=\n⟨by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_glb.union hb.is_glb).1⟩\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 ∪ t`. -/\nlemma is_greatest.union [linear_order γ] {a b : γ} {s t : set γ}\n  (ha : is_greatest s a) (hb : is_greatest t b) : is_greatest (s ∪ t) (max a b) :=\n⟨by cases (le_total a b) with h h; simp [h, ha.1, hb.1],\n  (ha.is_lub.union hb.is_lub).1⟩\n\nlemma is_lub.inter_Ici_of_mem [linear_order γ] {s : set γ} {a b : γ} (ha : is_lub s a)\n  (hb : b ∈ s) : is_lub (s ∩ Ici b) a :=\n⟨λ x hx, ha.1 hx.1, λ c hc, have hbc : b ≤ c, from hc ⟨hb, le_rfl⟩,\n  ha.2 $ λ x hx, (le_total x b).elim (λ hxb, hxb.trans hbc) $ λ hbx, hc ⟨hx, hbx⟩⟩\n\nlemma is_glb.inter_Iic_of_mem [linear_order γ] {s : set γ} {a b : γ} (ha : is_glb s a)\n  (hb : b ∈ s) : is_glb (s ∩ Iic b) a :=\n@is_lub.inter_Ici_of_mem (order_dual γ) _ _ _ _ ha hb\n\n/-!\n### Specific sets\n\n#### Unbounded intervals\n-/\n\nlemma is_least_Ici : is_least (Ici a) a := ⟨left_mem_Ici, λ x, id⟩\n\nlemma is_greatest_Iic : is_greatest (Iic a) a := ⟨right_mem_Iic, λ x, id⟩\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) := ⟨a, λ x hx, le_of_lt hx⟩\n\nlemma bdd_below_Ioi : bdd_below (Ioi a) := ⟨a, λ x hx, le_of_lt hx⟩\n\nsection\n\nvariables [linear_order γ] [densely_ordered γ]\n\nlemma is_lub_Iio {a : γ} : is_lub (Iio a) a :=\n⟨λ x hx, le_of_lt hx, λ y hy, le_of_forall_ge_of_dense hy⟩\n\nlemma is_glb_Ioi {a : γ} : is_glb (Ioi a) a := @is_lub_Iio (order_dual γ) _ _ a\n\nlemma upper_bounds_Iio {a : γ} : upper_bounds (Iio a) = Ici a := is_lub_Iio.upper_bounds_eq\n\nlemma lower_bounds_Ioi {a : γ} : 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⟨mem_singleton a, λ x hx, le_of_eq $ eq_of_mem_singleton hx⟩\n\nlemma is_least_singleton : is_least {a} a :=\n@is_greatest_singleton (order_dual α) _ 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 α) := is_lub_singleton.bdd_above\n\nlemma bdd_below_singleton : bdd_below ({a} : set α) := 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) := ⟨b, λ _, and.right⟩\n\nlemma bdd_below_Icc : bdd_below (Icc a b) := ⟨a, λ _, and.left⟩\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 ≤ b) : is_greatest (Icc a b) b :=\n⟨right_mem_Icc.2 h, λ x, and.right⟩\n\nlemma is_lub_Icc (h : a ≤ b) : is_lub (Icc a b) b := (is_greatest_Icc h).is_lub\n\nlemma upper_bounds_Icc (h : a ≤ b) : upper_bounds (Icc a b) = Ici b :=\n(is_lub_Icc h).upper_bounds_eq\n\nlemma is_least_Icc (h : a ≤ b) : is_least (Icc a b) a :=\n⟨left_mem_Icc.2 h, λ x, and.left⟩\n\nlemma is_glb_Icc (h : a ≤ b) : is_glb (Icc a b) a := (is_least_Icc h).is_glb\n\nlemma lower_bounds_Icc (h : a ≤ 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⟨right_mem_Ioc.2 h, λ x, and.right⟩\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⟨left_mem_Ico.2 h, λ x, and.left⟩\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 γ] [densely_ordered γ]\n\nlemma is_glb_Ioo {a b : γ} (h : a < b) :\n  is_glb (Ioo a b) a :=\n⟨λ x hx, hx.1.le, λ x hx,\nbegin\n  cases eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ h₂,\n  { exact h₁.symm ▸ le_sup_left },\n  obtain ⟨y, lty, ylt⟩ := exists_between h₂,\n  apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim,\n  obtain ⟨u, au, ub⟩ := exists_between h,\n  apply (hx ⟨au, ub⟩).trans ub.le,\nend⟩\n\nlemma lower_bounds_Ioo {a b : γ} (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 : γ} (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 : γ} (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 γ] [densely_ordered γ]\n\nlemma is_lub_Ioo {a b : γ} (hab : a < b) : is_lub (Ioo a b) b :=\nby simpa only [dual_Ioo] using @is_glb_Ioo (order_dual γ) _ _ b a hab\n\nlemma upper_bounds_Ioo {a b : γ} (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 : γ} (hab : a < b) : is_lub (Ico a b) b :=\nby simpa only [dual_Ioc] using @is_glb_Ioc (order_dual γ) _ _ b a hab\n\nlemma upper_bounds_Ico {a b : γ} (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 ↔ ∃ a, s ⊆ Ici a := iff.rfl\n\nlemma bdd_above_iff_subset_Iic : bdd_above s ↔ ∃ a, s ⊆ Iic a := iff.rfl\n\nlemma bdd_below_bdd_above_iff_subset_Icc : bdd_below s ∧ bdd_above s ↔ ∃ a b, s ⊆ 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 order_top.upper_bounds_univ [order_top γ] : upper_bounds (univ : set γ) = {⊤} :=\nset.ext $ λ b, iff.trans ⟨λ hb, top_unique $ hb trivial, λ hb x hx, hb.symm ▸ le_top⟩\n  mem_singleton_iff.symm\n\nlemma is_greatest_univ [order_top γ] : is_greatest (univ : set γ) ⊤ :=\nby simp only [is_greatest, order_top.upper_bounds_univ, mem_univ, mem_singleton, true_and]\n\nlemma is_lub_univ [order_top γ] : is_lub (univ : set γ) ⊤ :=\nis_greatest_univ.is_lub\n\nlemma order_bot.lower_bounds_univ [order_bot γ] : lower_bounds (univ : set γ) = {⊥} :=\n@order_top.upper_bounds_univ (order_dual γ) _\n\nlemma is_least_univ [order_bot γ] : is_least (univ : set γ) ⊥ :=\n@is_greatest_univ (order_dual γ) _\n\nlemma is_glb_univ [order_bot γ] : is_glb (univ : set γ) ⊥ :=\nis_least_univ.is_glb\n\nlemma no_top_order.upper_bounds_univ [no_top_order α] : upper_bounds (univ : set α) = ∅ :=\neq_empty_of_subset_empty $ λ b hb, let ⟨x, hx⟩ := no_top b in\nnot_le_of_lt hx (hb trivial)\n\nlemma no_bot_order.lower_bounds_univ [no_bot_order α] : lower_bounds (univ : set α) = ∅ :=\n@no_top_order.upper_bounds_univ (order_dual α) _ _\n\n/-!\n### Empty set\n-/\n\n@[simp] lemma upper_bounds_empty : upper_bounds (∅ : set α) = 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 (∅ : set α) = univ :=\n@upper_bounds_empty (order_dual α) _\n\n@[simp] lemma bdd_above_empty [nonempty α] : bdd_above (∅ : set α) :=\nby simp only [bdd_above, upper_bounds_empty, univ_nonempty]\n\n@[simp] lemma bdd_below_empty [nonempty α] : bdd_below (∅ : set α) :=\nby simp only [bdd_below, lower_bounds_empty, univ_nonempty]\n\nlemma is_glb_empty [order_top γ] : is_glb ∅ (⊤:γ) :=\nby simp only [is_glb, lower_bounds_empty, is_greatest_univ]\n\nlemma is_lub_empty [order_bot γ] : is_lub ∅ (⊥:γ) :=\n@is_glb_empty (order_dual γ) _\n\nlemma is_lub.nonempty [no_bot_order α] (hs : is_lub s a) : s.nonempty :=\nlet ⟨a', ha'⟩ := no_bot a in\nne_empty_iff_nonempty.1 $ assume h,\nhave a ≤ a', from hs.right $ by simp only [h, upper_bounds_empty],\nnot_le_of_lt ha' this\n\nlemma is_glb.nonempty [no_top_order α] (hs : is_glb s a) : s.nonempty :=\n@is_lub.nonempty (order_dual α) _ _ _ _ hs\n\nlemma nonempty_of_not_bdd_above [ha : nonempty α] (h : ¬bdd_above s) : s.nonempty :=\nnonempty.elim ha $ λ x, (not_bdd_above_iff'.1 h x).imp $ λ a ha, ha.fst\n\nlemma nonempty_of_not_bdd_below [ha : nonempty α] (h : ¬bdd_below s) : s.nonempty :=\n@nonempty_of_not_bdd_above (order_dual α) _ _ _ 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 γ] (a : γ) {s : set γ} :\n  bdd_above (insert a s) ↔ bdd_above s :=\nby simp only [insert_eq, bdd_above_union, bdd_above_singleton, true_and]\n\nlemma bdd_above.insert [semilattice_sup γ] (a : γ) {s : set γ} (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 γ] (a : γ) {s : set γ} :\n  bdd_below (insert a s) ↔ bdd_below s :=\nby simp only [insert_eq, bdd_below_union, bdd_below_singleton, true_and]\n\nlemma bdd_below.insert [semilattice_inf γ] (a : γ) {s : set γ} (hs : bdd_below s) :\n  bdd_below (insert a s) :=\n(bdd_below_insert a).2 hs\n\nlemma is_lub.insert [semilattice_sup γ] (a) {b} {s : set γ} (hs : is_lub s b) :\n  is_lub (insert a s) (a ⊔ b) :=\nby { rw insert_eq, exact is_lub_singleton.union hs }\n\nlemma is_glb.insert [semilattice_inf γ] (a) {b} {s : set γ} (hs : is_glb s b) :\n  is_glb (insert a s) (a ⊓ b) :=\nby { rw insert_eq, exact is_glb_singleton.union hs }\n\nlemma is_greatest.insert [linear_order γ] (a) {b} {s : set γ} (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 γ] (a) {b} {s : set γ} (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 : α) (s : set α) :\n  upper_bounds (insert a s) = Ici a ∩ upper_bounds s :=\nby rw [insert_eq, upper_bounds_union, upper_bounds_singleton]\n\n@[simp] lemma lower_bounds_insert (a : α) (s : set α) :\n  lower_bounds (insert a s) = Iic a ∩ 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 γ] (s : set γ) : bdd_above s :=\n⟨⊤, assume a ha, order_top.le_top a⟩\n\n/-- When there is a global minimum, every set is bounded below. -/\n@[simp] protected lemma order_bot.bdd_below [order_bot γ] (s : set γ) : bdd_below s :=\n⟨⊥, assume a ha, order_bot.bot_le a⟩\n\n/-!\n### Pair\n-/\n\nlemma is_lub_pair [semilattice_sup γ] {a b : γ} : is_lub {a, b} (a ⊔ b) :=\nis_lub_singleton.insert _\n\nlemma is_glb_pair [semilattice_inf γ] {a b : γ} : is_glb {a, b} (a ⊓ b) :=\nis_glb_singleton.insert _\n\nlemma is_least_pair [linear_order γ] {a b : γ} : is_least {a, b} (min a b) :=\nis_least_singleton.insert _\n\nlemma is_greatest_pair [linear_order γ] {a b : γ} : is_greatest {a, b} (max a b) :=\nis_greatest_singleton.insert _\n\nend\n\n/-!\n### (In)equalities with the least upper bound and the greatest lower bound\n-/\n\nsection preorder\nvariables [preorder α] {s : set α} {a b : α}\n\nlemma lower_bounds_le_upper_bounds (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds s) :\n  s.nonempty → a ≤ b\n| ⟨c, hc⟩ := 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 ≤ b :=\nlower_bounds_le_upper_bounds ha.1 hb.1 hs\n\nlemma is_lub_lt_iff (ha : is_lub s a) : a < b ↔ ∃ c ∈ upper_bounds s, c < b :=\n⟨λ hb, ⟨a, ha.1, hb⟩, λ ⟨c, hcs, hcb⟩, lt_of_le_of_lt (ha.2 hcs) hcb⟩\n\nlemma lt_is_glb_iff (ha : is_glb s a) : b < a ↔ ∃ c ∈ lower_bounds s, b < c :=\n@is_lub_lt_iff (order_dual α) _ s _ _ ha\n\nlemma le_of_is_lub_le_is_glb {x y} (ha : is_glb s a) (hb : is_lub s b) (hab : b ≤ a)\n  (hx : x ∈ s) (hy : y ∈ s) : x ≤ y :=\ncalc x ≤ b : hb.1 hx\n   ... ≤ a : hab\n   ... ≤ y : ha.1 hy\n\nend preorder\n\nsection partial_order\nvariables [partial_order α] {s : set α} {a b : α}\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 ↔ a = b :=\niff.intro Ha.unique (assume h, h ▸ 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 ↔ a = b :=\niff.intro Ha.unique (assume h, h ▸ 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 ≤ a) :\n  s.subsingleton :=\nλ 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 ∈ s) (Hy : y ∈ s) (Hxy : x ≠ y) :\n  a < b :=\nlt_iff_le_not_le.2\n  ⟨lower_bounds_le_upper_bounds Ha.1 Hb.1 ⟨x, Hx⟩,\n    λ hab, Hxy $ set.subsingleton_of_is_lub_le_is_glb Ha Hb hab Hx Hy⟩\n\nend partial_order\n\nsection linear_order\nvariables [linear_order α] {s : set α} {a b : α}\n\nlemma lt_is_lub_iff (h : is_lub s a) : b < a ↔ ∃ c ∈ s, b < c :=\nby simp only [← 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 ↔ ∃ c ∈ s, c < b :=\n@lt_is_lub_iff (order_dual α) _ _ _ _ h\n\nlemma is_lub.exists_between (h : is_lub s a) (hb : b < a) :\n  ∃ c ∈ s, b < c ∧ c ≤ a :=\nlet ⟨c, hcs, hbc⟩ := (lt_is_lub_iff h).1 hb in ⟨c, hcs, hbc, h.1 hcs⟩\n\nlemma is_lub.exists_between' (h : is_lub s a) (h' : a ∉ s) (hb : b < a) :\n  ∃ c ∈ s, b < c ∧ c < a :=\nlet ⟨c, hcs, hbc, hca⟩ := h.exists_between hb\nin ⟨c, hcs, hbc, hca.lt_of_ne $ λ hac, h' $ hac ▸ hcs⟩\n\nlemma is_glb.exists_between (h : is_glb s a) (hb : a < b) :\n  ∃ c ∈ s, a ≤ c ∧ c < b :=\nlet ⟨c, hcs, hbc⟩ := (is_glb_lt_iff h).1 hb in ⟨c, hcs, h.1 hcs, hbc⟩\n\nlemma is_glb.exists_between' (h : is_glb s a) (h' : a ∉ s) (hb : a < b) :\n  ∃ c ∈ s, a < c ∧ c < b :=\nlet ⟨c, hcs, hac, hcb⟩ := h.exists_between hb\nin ⟨c, hcs, hac.lt_of_ne $ λ hac, h' $ hac.symm ▸ hcs, hcb⟩\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 α] {s : set α} {a ε : α}\n\nlemma is_glb.exists_between_self_add (h : is_glb s a) (hε : 0 < ε) :\n  ∃ b ∈ s, a ≤ b ∧ b < a + ε :=\nh.exists_between $ lt_add_of_pos_right _ hε\n\nlemma is_glb.exists_between_self_add' (h : is_glb s a) (h₂ : a ∉ s) (hε : 0 < ε) :\n  ∃ b ∈ s, a < b ∧ b < a + ε :=\nh.exists_between' h₂ $ lt_add_of_pos_right _ hε\n\nlemma is_lub.exists_between_sub_self  (h : is_lub s a) (hε : 0 < ε) : ∃ b ∈ s, a - ε < b ∧ b ≤ a :=\nh.exists_between $ sub_lt_self _ hε\n\nlemma is_lub.exists_between_sub_self' (h : is_lub s a) (h₂ : a ∉ s) (hε : 0 < ε) :\n  ∃ b ∈ s, a - ε < b ∧ b < a :=\nh.exists_between' h₂ $ sub_lt_self _ hε\n\nend linear_ordered_add_comm_group\n\n/-!\n### Images of upper/lower bounds under monotone functions\n-/\n\nnamespace monotone\n\nvariables [preorder α] [preorder β] {f : α → β} (Hf : monotone f) {a : α} {s : set α}\n\nlemma mem_upper_bounds_image (Ha : a ∈ upper_bounds s) :\n  f a ∈ upper_bounds (f '' s) :=\nball_image_of_ball (assume x H, Hf (Ha ‹x ∈ s›))\n\nlemma mem_lower_bounds_image (Ha : a ∈ lower_bounds s) :\n  f a ∈ lower_bounds (f '' s) :=\nball_image_of_ball (assume x H, Hf (Ha ‹x ∈ s›))\n\n/-- The image under a monotone function of a set which is bounded above is bounded above. -/\nlemma map_bdd_above (hf : monotone f) : bdd_above s → bdd_above (f '' s)\n| ⟨C, hC⟩ := ⟨f C, hf.mem_upper_bounds_image hC⟩\n\n/-- The image under a monotone function of a set which is bounded below is bounded below. -/\nlemma map_bdd_below (hf : monotone f) : bdd_below s → bdd_below (f '' s)\n| ⟨C, hC⟩ := ⟨f C, hf.mem_lower_bounds_image hC⟩\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⟨mem_image_of_mem _ Ha.1, Hf.mem_lower_bounds_image Ha.2⟩\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⟨mem_image_of_mem _ Ha.1, Hf.mem_upper_bounds_image Ha.2⟩\n\nlemma is_lub_image_le (Ha : is_lub s a) {b : β} (Hb : is_lub (f '' s) b) :\n  b ≤ f a :=\nHb.2 (Hf.mem_upper_bounds_image Ha.1)\n\nlemma le_is_glb_image (Ha : is_glb s a) {b : β} (Hb : is_glb (f '' s) b) :\n  f a ≤ b :=\nHb.2 (Hf.mem_lower_bounds_image Ha.1)\n\nend monotone\n\nlemma is_glb.of_image [preorder α] [preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y)\n  {s : set α} {x : α} (hx : is_glb (f '' s) (f x)) :\n  is_glb s x :=\n⟨λ y hy, hf.1 $ hx.1 $ mem_image_of_mem _ hy,\n  λ y hy, hf.1 $ hx.2 $ monotone.mem_lower_bounds_image (λ x y, hf.2) hy⟩\n\nlemma is_lub.of_image [preorder α] [preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y)\n  {s : set α} {x : α} (hx : is_lub (f '' s) (f x)) :\n  is_lub s x :=\n@is_glb.of_image (order_dual α) (order_dual β) _ _ f (λ x y, hf) _ _ hx\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/bounds.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7583006947925918}}
{"text": "import data.nat.prime\nimport tactic.norm_num\nimport data.list.basic\nimport data.int.basic\nopen nat\nopen list\n\ntheorem  prime_factors_unique: ∀ A B:list ℕ,prod A=prod B→(∀p:ℕ, p∈A→prime p)→(∀ p:ℕ,p∈ B→ prime p)→A~B:=begin\n    intro A,induction A with pA A1 Hi,\n    norm_num,intros,cases B with p B1,exact perm.refl nil,exfalso,revert a,norm_num,\n    have H:=a_1 p (list.mem_cons_self _ _),have H1:=dvd_mul_right p (prod B1),intro,rw ←a at H1,exact prime.not_dvd_one H H1,\n    intros,simp at a,have H:pA ∣ prod B, have:=dvd_mul_right pA (prod A1),rwa a at this,\n    have H1: ∀ (B:list ℕ)(p:ℕ),prime p→(∀pB, pB ∈ B → prime pB)→p ∣ prod B → p ∈ B:=begin\n        assume B,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:=iff.elim_left (prime.dvd_mul 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:¬p2=1:=begin unfold prime at Hp2,intro,rw a_3 at Hp2,simp at Hp2,revert Hp2,exact dec_trivial,end,\n        simp [H6] at H5,assumption,right,\n        have H3:(∀ (pB : ℕ), pB ∈ B1 → prime pB):=begin revert H, norm_num,end,have H2:= Hi p2 Hp2 H3 A,assumption,\n    end,\n    have HppA: prime pA:=begin apply a_1,norm_num,  end,\n    have H9:=H1 B pA HppA a_2 H,\n    have H11:=prod_eq_of_perm (perm_erase H9),rw [H11,prod_cons] at a,\n    rw nat.mul_left_inj (gt_of_ge_of_gt (and.left HppA) (dec_trivial:2>0)) at a,\n    have HA1:∀ (p : ℕ), p ∈ A1 → prime p:=begin revert a_1,norm_num,end,\n    have HB1:∀ (p : ℕ), p ∈(list.erase B pA) → prime p:=λ p Hp,a_2 p (mem_of_mem_erase Hp),\n    have Hi2:= iff.elim_right (perm_cons pA) (Hi (list.erase B pA) a HA1 HB1),\n    exact perm.trans Hi2 (perm.symm (perm_erase H9)),\nend\n", "meta": {"author": "ChrisHughes24", "repo": "leanstuff", "sha": "9efa85f72efaccd1d540385952a6acc18fce8687", "save_path": "github-repos/lean/ChrisHughes24-leanstuff", "path": "github-repos/lean/ChrisHughes24-leanstuff/leanstuff-9efa85f72efaccd1d540385952a6acc18fce8687/primesaf.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242132, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7582478935332205}}
{"text": "import tactic -- hide\nopen function nat -- hide\n\n/-\n## The `rw` tactic\n\nThe next tactic to learn is the `rw` tactic (short for `rewrite`). If we have a proof $h$ of an equality\n$a=b$, then `rw h` will replace all occurrences of $a$ in the goal with $b$. It also works with `↔` instead of `=`.\nThat is, if we have two equivalent statements, it will replace one with the other.\n\nIn the example at hand, we have a proof $h$ of the fact that $a=3$. We want to prove that $a+5=8$,\nwhich we could do by substituting in the value of $a$. Try to erase the `sorry` and replace it with\n`rw h,` and see if it works.\n-/\n\n/- Lemma : no-side-bar\nIf $a = 3$, then $a + 5 = 8$.\n-/\nlemma l1 (a : ℕ) (h : a = 3) : a + 5 = 8 :=\nbegin\n  rw h,\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/tutorial_world/01_rw.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7582102544809851}}
{"text": "import data.real.basic data.real.sqrt\n\nnamespace MAS114\nnamespace exercises_1\nnamespace Q38\n\nnoncomputable def r3 : ℝ := real.sqrt 3\nnoncomputable def r5 : ℝ := real.sqrt 5\nnoncomputable def r7 : ℝ := real.sqrt 7\n\nlemma p3 : (3 : ℝ) ≥ 0 := by { norm_cast, exact dec_trivial }\nlemma p5 : (5 : ℝ) ≥ 0 := by { norm_cast, exact dec_trivial }\nlemma p7 : (7 : ℝ) ≥ 0 := by { norm_cast, exact dec_trivial }\n\nlemma h3 : r3 * r3 = 3 := real.mul_self_sqrt p3\nlemma h5 : r5 * r5 = 5 := real.mul_self_sqrt p5\nlemma h7 : r7 * r7 = 7 := real.mul_self_sqrt p7\n\nnoncomputable def u := r3 + r5 + r7 \n\nnoncomputable def v := (u ^ 7 - 60 * u^5 + 841 * u ^ 3 - 4950 * u) / 472\n\nlemma u2 : u ^ 2 = 15 + 2 * r3 * r5 + 2 * r3 * r7 + 2 * r5 * r7 := \ncalc \n u ^ 2 = r3 * r3 + r5 * r5 + r7 * r7 + 2 * r3 * r5 + 2 * r3 * r7 + 2 * r5 * r7 : \n          by { dsimp[u], ring}\n ... = 3 + 5 + 7 + 2 * r3 * r5 + 2 * r3 * r7 + 2 * r5 * r7 : \n          by { rw[h3, h5, h7] }\n ... = 15 + 2 * r3 * r5 + 2 * r3 * r7 + 2 * r5 * r7 : by { ring }\n\nlemma v_sq : v * v = 3 * 5 * 7 := sorry\n\nlemma v_irrational : ¬ ∃ v_Q : ℚ, v = v_Q := sorry\n\nlemma u_irrational : ¬ ∃ u_Q : ℚ, u = u_Q := sorry\n\nend Q38\nend exercises_1\nend MAS114", "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/undergraduate/MAS114/Semester 1/Q38.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7582102524977186}}
{"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\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 → p → 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 → p → 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 → p → 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 ∧ q ∧ r) → (p ∧ r) := by \n  sorry\n\n\n\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 → ¬ q` and `¬ (p ∧ 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 → ¬ q) → ¬ (p ∧ q) := by \n  sorry\n\n\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 ∨ q) ∧ (p → r) ∧ (q → s))`,\nthen we know `r ∨ s`. \nSo suppose that we know `((p ∨ q) ∧ (p → r) ∧ (q → s))`.\nOur goal is to show that `r ∨ s` follows.\n\nFrom that long statement, we know three facts: `p ∨ q`, `p → r`, and `q → s`. \nWe'll reason by cases on `p ∨ q`.\n\nFirst, if we know `p`, then we know `r`, because `p → r`. \nAnd if we know `r` then we know `r ∨ s`. \n\nSecond, if we know `q`, then we know `s`, because `q → s`. \nAnd if we know `s` then we know `r ∨ s`.\n\nThat completes our proof!\n\nYour task: translate this argument to Lean.\n\n-/\n\n/- 4 points -/\ntheorem problem_3 : ((p ∨ q) ∧ (p → r) ∧ (q → s)) → (r ∨ s) := by \n  sorry", "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/Hw1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84594244507642, "lm_q2_score": 0.8962513835254865, "lm_q1q2_score": 0.7581770867826744}}
{"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 order.well_founded_set\nimport algebra.big_operators.finprod\nimport ring_theory.valuation.basic\nimport algebra.module.pi\nimport ring_theory.power_series.basic\n\n/-!\n# Hahn Series\n\n## Main Definitions\n  * If `Γ` is ordered and `R` has zero, then `hahn_series Γ R` consists of\n  formal series over `Γ` with coefficients in `R`, whose supports are partially well-ordered.\n  * If `R` is a (commutative) additive monoid or group, then so is `hahn_series Γ R`.\n  * If `R` is a (comm_)(semi)ring, then so is `hahn_series Γ R`.\n  * `hahn_series.add_val Γ R` defines an `add_valuation` on `hahn_series Γ R` when `Γ` is linearly\n    ordered.\n  * A `hahn_series.summable_family` is a family of Hahn series such that the union of their supports\n  is well-founded and only finitely many are nonzero at any given coefficient. They have a formal\n  sum, `hahn_series.summable_family.hsum`, which can be bundled as a `linear_map` as\n  `hahn_series.summable_family.lsum`. Note that this is different from `summable` in the valuation\n  topology, because there are topologically summable families that do not satisfy the axioms of\n  `hahn_series.summable_family`, and formally summable families whose sums do not converge\n  topologically.\n\n## TODO\n  * Given `[linear_ordered_add_comm_group Γ]` and `[field R]`, define `field (hahn_series Γ R)`.\n  * Build an API for the variable `X`\n  * Define Laurent series\n\n-/\n\nopen finset\nopen_locale big_operators classical\nnoncomputable theory\n\n/-- If `Γ` is linearly ordered and `R` has zero, then `hahn_series Γ R` consists of\n  formal series over `Γ` with coefficients in `R`, whose supports are well-founded. -/\n@[ext]\nstructure hahn_series (Γ : Type*) (R : Type*) [partial_order Γ] [has_zero R] :=\n(coeff : Γ → R)\n(is_pwo_support' : (function.support coeff).is_pwo)\n\nvariables {Γ : Type*} {R : Type*}\n\nnamespace hahn_series\n\nsection zero\nvariables [partial_order Γ] [has_zero R]\n\n/-- The support of a Hahn series is just the set of indices whose coefficients are nonzero.\n  Notably, it is well-founded. -/\ndef support (x : hahn_series Γ R) : set Γ := function.support x.coeff\n\n@[simp]\nlemma is_pwo_support (x : hahn_series Γ R) : x.support.is_pwo := x.is_pwo_support'\n\n@[simp]\nlemma is_wf_support (x : hahn_series Γ R) : x.support.is_wf := x.is_pwo_support.is_wf\n\n@[simp]\nlemma mem_support (x : hahn_series Γ R) (a : Γ) : a ∈ x.support ↔ x.coeff a ≠ 0 := iff.refl _\n\ninstance : has_zero (hahn_series Γ R) :=\n⟨{ coeff := 0,\n   is_pwo_support' := by simp }⟩\n\ninstance : inhabited (hahn_series Γ R) := ⟨0⟩\n\ninstance [subsingleton R] : subsingleton (hahn_series Γ R) :=\n⟨λ a b, a.ext b (subsingleton.elim _ _)⟩\n\n@[simp]\nlemma zero_coeff {a : Γ} : (0 : hahn_series Γ R).coeff a = 0 := rfl\n\n@[simp]\nlemma support_zero : support (0 : hahn_series Γ R) = ∅ := function.support_zero\n\n@[simp]\nlemma support_nonempty_iff {x : hahn_series Γ R} :\n  x.support.nonempty ↔ x ≠ 0 :=\nbegin\n  split,\n  { rintro ⟨a, ha⟩ rfl,\n    apply ha zero_coeff },\n  { contrapose!,\n    rw set.not_nonempty_iff_eq_empty,\n    intro h,\n    ext a,\n    have ha := set.not_mem_empty a,\n    rw [← h, mem_support, not_not] at ha,\n    rw [ha, zero_coeff] }\nend\n\n/-- `single a r` is the Hahn series which has coefficient `r` at `a` and zero otherwise. -/\ndef single (a : Γ) : zero_hom R (hahn_series Γ R) :=\n{ to_fun := λ r, { coeff := pi.single a r,\n    is_pwo_support' := (set.is_pwo_singleton a).mono pi.support_single_subset },\n  map_zero' := ext _ _ (pi.single_zero _) }\n\nvariables {a b : Γ} {r : R}\n\n@[simp]\ntheorem single_coeff_same (a : Γ) (r : R) : (single a r).coeff a = r := pi.single_eq_same a r\n\n@[simp]\ntheorem single_coeff_of_ne (h : b ≠ a) : (single a r).coeff b = 0 := pi.single_eq_of_ne h r\n\ntheorem single_coeff : (single a r).coeff b = if (b = a) then r else 0 :=\nby { split_ifs with h; simp [h] }\n\n@[simp]\nlemma support_single_of_ne (h : r ≠ 0) : support (single a r) = {a} :=\npi.support_single_of_ne h\n\nlemma support_single_subset : support (single a r) ⊆ {a} :=\npi.support_single_subset\n\nlemma eq_of_mem_support_single {b : Γ} (h : b ∈ support (single a r)) : b = a :=\nsupport_single_subset h\n\n@[simp]\nlemma single_eq_zero : (single a (0 : R)) = 0 := (single a).map_zero\n\ninstance [nonempty Γ] [nontrivial R] : nontrivial (hahn_series Γ R) :=\n⟨begin\n  obtain ⟨r, s, rs⟩ := exists_pair_ne R,\n  inhabit Γ,\n  refine ⟨single (arbitrary Γ) r, single (arbitrary Γ) s, λ con, rs _⟩,\n  rw [← single_coeff_same (arbitrary Γ) r, con, single_coeff_same],\nend⟩\n\nlemma coeff_min_ne_zero {x : hahn_series Γ R} (hx : x ≠ 0) :\n  x.coeff (x.is_wf_support.min (support_nonempty_iff.2 hx)) ≠ 0 :=\nx.is_wf_support.min_mem (support_nonempty_iff.2 hx)\n\nend zero\n\nsection addition\n\nvariable [partial_order Γ]\n\nsection add_monoid\nvariable [add_monoid R]\n\ninstance : has_add (hahn_series Γ R) :=\n{ add := λ x y, { coeff := x.coeff + y.coeff,\n                  is_pwo_support' := (x.is_pwo_support.union y.is_pwo_support).mono\n                    (function.support_add _ _) } }\n\ninstance : add_monoid (hahn_series Γ R) :=\n{ zero := 0,\n  add := (+),\n  add_assoc := λ x y z, by { ext, apply add_assoc },\n  zero_add := λ x, by { ext, apply zero_add },\n  add_zero := λ x, by { ext, apply add_zero } }\n\n@[simp]\nlemma add_coeff' {x y : hahn_series Γ R} :\n  (x + y).coeff = x.coeff + y.coeff := rfl\n\nlemma add_coeff {x y : hahn_series Γ R} {a : Γ} :\n  (x + y).coeff a = x.coeff a + y.coeff a := rfl\n\nlemma support_add_subset {x y : hahn_series Γ R} :\n  support (x + y) ⊆ support x ∪ support y :=\nλ a ha, begin\n  rw [mem_support, add_coeff] at ha,\n  rw [set.mem_union, mem_support, mem_support],\n  contrapose! ha,\n  rw [ha.1, ha.2, add_zero],\nend\n\n/-- `single` as an additive monoid/group homomorphism -/\n@[simps] def single.add_monoid_hom (a : Γ) : R →+ (hahn_series Γ R) :=\n{ map_add' := λ x y, by { ext b, by_cases h : b = a; simp [h] },\n  ..single a }\n\n/-- `coeff g` as an additive monoid/group homomorphism -/\n@[simps] def coeff.add_monoid_hom (g : Γ) : (hahn_series Γ R) →+ R :=\n{ to_fun := λ f, f.coeff g,\n  map_zero' := zero_coeff,\n  map_add' := λ x y, add_coeff }\n\nend add_monoid\n\ninstance [add_comm_monoid R] : add_comm_monoid (hahn_series Γ R) :=\n{ add_comm := λ x y, by { ext, apply add_comm }\n  .. hahn_series.add_monoid }\n\nsection add_group\nvariable [add_group R]\n\ninstance : add_group (hahn_series Γ R) :=\n{ neg := λ x, { coeff := λ a, - x.coeff a,\n                is_pwo_support' := by { rw function.support_neg,\n                  exact x.is_pwo_support }, },\n  add_left_neg := λ x, by { ext, apply add_left_neg },\n  .. hahn_series.add_monoid }\n\n@[simp]\nlemma neg_coeff' {x : hahn_series Γ R} : (- x).coeff = - x.coeff := rfl\n\nlemma neg_coeff {x : hahn_series Γ R} {a : Γ} : (- x).coeff a = - x.coeff a := rfl\n\n@[simp]\nlemma support_neg {x : hahn_series Γ R} : (- x).support = x.support :=\nby { ext, simp }\n\n@[simp]\nlemma sub_coeff' {x y : hahn_series Γ R} :\n  (x - y).coeff = x.coeff - y.coeff := by { ext, simp [sub_eq_add_neg] }\n\nlemma sub_coeff {x y : hahn_series Γ R} {a : Γ} :\n  (x - y).coeff a = x.coeff a - y.coeff a := by simp\n\nend add_group\n\ninstance [add_comm_group R] : add_comm_group (hahn_series Γ R) :=\n{ .. hahn_series.add_comm_monoid,\n  .. hahn_series.add_group }\n\nend addition\n\nsection distrib_mul_action\nvariables [partial_order Γ] {V : Type*} [monoid R] [add_monoid V] [distrib_mul_action R V]\n\ninstance : has_scalar R (hahn_series Γ V) :=\n⟨λ r x, { coeff := r • x.coeff,\n          is_pwo_support' := x.is_pwo_support.mono (function.support_smul_subset_right r x.coeff) }⟩\n\n@[simp]\nlemma smul_coeff {r : R} {x : hahn_series Γ V} {a : Γ} : (r • x).coeff a = r • (x.coeff a) := rfl\n\ninstance : distrib_mul_action R (hahn_series Γ V) :=\n{ smul := (•),\n  one_smul := λ _, by { ext, simp },\n  smul_zero := λ _, by { ext, simp },\n  smul_add := λ _ _ _, by { ext, simp [smul_add] },\n  mul_smul := λ _ _ _, by { ext, simp [mul_smul] } }\n\nvariables {S : Type*} [monoid S] [distrib_mul_action S V]\n\ninstance [has_scalar R S] [is_scalar_tower R S V] :\n  is_scalar_tower R S (hahn_series Γ V) :=\n⟨λ r s a, by { ext, simp }⟩\n\ninstance [smul_comm_class R S V] :\n  smul_comm_class R S (hahn_series Γ V) :=\n⟨λ r s a, by { ext, simp [smul_comm] }⟩\n\nend distrib_mul_action\n\nsection module\nvariables [partial_order Γ] [semiring R] {V : Type*} [add_comm_monoid V] [module R V]\n\ninstance : module R (hahn_series Γ V) :=\n{ zero_smul := λ _, by { ext, simp },\n  add_smul := λ _ _ _, by { ext, simp [add_smul] },\n  .. hahn_series.distrib_mul_action }\n\n/-- `single` as a linear map -/\n@[simps] def single.linear_map (a : Γ) : R →ₗ[R] (hahn_series Γ R) :=\n{ map_smul' := λ r s, by { ext b, by_cases h : b = a; simp [h] },\n  ..single.add_monoid_hom a }\n\n/-- `coeff g` as a linear map -/\n@[simps] def coeff.linear_map (g : Γ) : (hahn_series Γ R) →ₗ[R] R :=\n{ map_smul' := λ r s, rfl,\n  ..coeff.add_monoid_hom g }\n\nend module\n\nsection multiplication\n\nvariable [ordered_cancel_add_comm_monoid Γ]\n\ninstance [has_zero R] [has_one R] : has_one (hahn_series Γ R) :=\n⟨single 0 1⟩\n\n@[simp]\nlemma one_coeff [has_zero R] [has_one R] {a : Γ} :\n  (1 : hahn_series Γ R).coeff a = if a = 0 then 1 else 0 := single_coeff\n\n@[simp]\nlemma single_zero_one [has_zero R] [has_one R] : (single 0 (1 : R)) = 1 := rfl\n\n@[simp]\nlemma support_one [semiring R] [nontrivial R] :\n  support (1 : hahn_series Γ R) = {0} :=\nsupport_single_of_ne one_ne_zero\n\ninstance [semiring R] : has_mul (hahn_series Γ R) :=\n{ mul := λ x y, { coeff := λ a,\n    ∑ ij in (add_antidiagonal x.is_pwo_support y.is_pwo_support a),\n    x.coeff ij.fst * y.coeff ij.snd,\n    is_pwo_support' := begin\n      have h : {a : Γ | ∑ (ij : Γ × Γ) in add_antidiagonal x.is_pwo_support\n        y.is_pwo_support a, x.coeff ij.fst * y.coeff ij.snd ≠ 0} ⊆\n        {a : Γ | (add_antidiagonal x.is_pwo_support y.is_pwo_support a).nonempty},\n      { intros a ha,\n        contrapose! ha,\n        simp [not_nonempty_iff_eq_empty.1 ha] },\n      exact is_pwo_support_add_antidiagonal.mono h,\n    end, }, }\n\n@[simp]\nlemma mul_coeff [semiring R] {x y : hahn_series Γ R} {a : Γ} :\n  (x * y).coeff a = ∑ ij in (add_antidiagonal x.is_pwo_support y.is_pwo_support a),\n    x.coeff ij.fst * y.coeff ij.snd := rfl\n\nlemma mul_coeff_right' [semiring R] {x y : hahn_series Γ R} {a : Γ} {s : set Γ} (hs : s.is_pwo)\n  (hys : y.support ⊆ s) :\n  (x * y).coeff a = ∑ ij in (add_antidiagonal x.is_pwo_support hs a),\n    x.coeff ij.fst * y.coeff ij.snd :=\nbegin\n  rw mul_coeff,\n  apply sum_subset_zero_on_sdiff (add_antidiagonal_mono_right hys) _ (λ _ _, rfl),\n  intros b hb,\n  simp only [not_and, not_not, mem_sdiff, mem_add_antidiagonal,\n      ne.def, set.mem_set_of_eq, mem_support] at hb,\n  rw [(hb.2 hb.1.1 hb.1.2.1), mul_zero]\nend\n\nlemma mul_coeff_left' [semiring R] {x y : hahn_series Γ R} {a : Γ} {s : set Γ} (hs : s.is_pwo)\n  (hxs : x.support ⊆ s) :\n  (x * y).coeff a = ∑ ij in (add_antidiagonal hs y.is_pwo_support a),\n    x.coeff ij.fst * y.coeff ij.snd :=\nbegin\n  rw mul_coeff,\n  apply sum_subset_zero_on_sdiff (add_antidiagonal_mono_left hxs) _ (λ _ _, rfl),\n  intros b hb,\n  simp only [not_and, not_not, mem_sdiff, mem_add_antidiagonal,\n      ne.def, set.mem_set_of_eq, mem_support] at hb,\n  rw [not_not.1 (λ con, hb.1.2.2 (hb.2 hb.1.1 con)), zero_mul],\nend\n\ninstance [semiring R] : distrib (hahn_series Γ R) :=\n{ left_distrib := λ x y z, begin\n    ext a,\n    have hwf := (y.is_pwo_support.union z.is_pwo_support),\n    rw [mul_coeff_right' hwf, add_coeff, mul_coeff_right' hwf (set.subset_union_right _ _),\n      mul_coeff_right' hwf (set.subset_union_left _ _)],\n    { simp only [add_coeff, mul_add, sum_add_distrib] },\n    { intro b,\n      simp only [add_coeff, ne.def, set.mem_union_eq, set.mem_set_of_eq, mem_support],\n      contrapose!,\n      intro h,\n      rw [h.1, h.2, add_zero], }\n  end,\n  right_distrib := λ x y z, begin\n    ext a,\n    have hwf := (x.is_pwo_support.union y.is_pwo_support),\n    rw [mul_coeff_left' hwf, add_coeff, mul_coeff_left' hwf (set.subset_union_right _ _),\n      mul_coeff_left' hwf (set.subset_union_left _ _)],\n    { simp only [add_coeff, add_mul, sum_add_distrib] },\n    { intro b,\n      simp only [add_coeff, ne.def, set.mem_union_eq, set.mem_set_of_eq, mem_support],\n      contrapose!,\n      intro h,\n      rw [h.1, h.2, add_zero], },\n  end,\n  .. hahn_series.has_mul,\n  .. hahn_series.has_add }\n\nlemma single_mul_coeff_add [semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} {b : Γ} :\n  ((single b r) * x).coeff (a + b) = r * x.coeff a :=\nbegin\n  by_cases hr : r = 0,\n  { simp [hr] },\n  simp only [hr, smul_coeff, mul_coeff, support_single_of_ne, ne.def, not_false_iff, smul_eq_mul],\n  by_cases hx : x.coeff a = 0,\n  { simp only [hx, mul_zero],\n    rw [sum_congr _ (λ _ _, rfl), sum_empty],\n    ext ⟨a1, a2⟩,\n    simp only [not_mem_empty, not_and, set.mem_singleton_iff, not_not,\n      mem_add_antidiagonal, set.mem_set_of_eq, iff_false],\n    rintro h1 rfl h2,\n    rw add_comm at h1,\n    rw ← add_right_cancel h1 at hx,\n    exact h2 hx, },\n  transitivity ∑ (ij : Γ × Γ) in {(b, a)}, (single b r).coeff ij.fst * x.coeff ij.snd,\n  { apply sum_congr _ (λ _ _, rfl),\n    ext ⟨a1, a2⟩,\n    simp only [set.mem_singleton_iff, prod.mk.inj_iff, mem_add_antidiagonal,\n      mem_singleton, set.mem_set_of_eq],\n    split,\n    { rintro ⟨h1, rfl, h2⟩,\n      rw add_comm at h1,\n      refine ⟨rfl, add_right_cancel h1⟩ },\n    { rintro ⟨rfl, rfl⟩,\n      refine ⟨add_comm _ _, _⟩,\n      simp [hx] } },\n  { simp }\nend\n\nlemma mul_single_coeff_add [semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} {b : Γ} :\n  (x * (single b r)).coeff (a + b) = x.coeff a * r :=\nbegin\n  by_cases hr : r = 0,\n  { simp [hr] },\n  simp only [hr, smul_coeff, mul_coeff, support_single_of_ne, ne.def, not_false_iff, smul_eq_mul],\n  by_cases hx : x.coeff a = 0,\n  { simp only [hx, zero_mul],\n    rw [sum_congr _ (λ _ _, rfl), sum_empty],\n    ext ⟨a1, a2⟩,\n    simp only [not_mem_empty, not_and, set.mem_singleton_iff, not_not,\n      mem_add_antidiagonal, set.mem_set_of_eq, iff_false],\n    rintro h1 h2 rfl,\n    rw ← add_right_cancel h1 at hx,\n    exact h2 hx, },\n  transitivity ∑ (ij : Γ × Γ) in {(a,b)}, x.coeff ij.fst * (single b r).coeff ij.snd,\n  { apply sum_congr _ (λ _ _, rfl),\n    ext ⟨a1, a2⟩,\n    simp only [set.mem_singleton_iff, prod.mk.inj_iff, mem_add_antidiagonal,\n      mem_singleton, set.mem_set_of_eq],\n    split,\n    { rintro ⟨h1, h2, rfl⟩,\n      refine ⟨add_right_cancel h1, rfl⟩ },\n    { rintro ⟨rfl, rfl⟩,\n      simp [hx] } },\n  { simp }\nend\n\n@[simp]\nlemma mul_single_zero_coeff [semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} :\n  (x * (single 0 r)).coeff a = x.coeff a * r  :=\nby rw [← add_zero a, mul_single_coeff_add, add_zero]\n\nlemma single_zero_mul_coeff [semiring R] {r : R} {x : hahn_series Γ R} {a : Γ} :\n  ((single 0 r) * x).coeff a = r * x.coeff a :=\nby rw [← add_zero a, single_mul_coeff_add, add_zero]\n\n@[simp]\nlemma single_zero_mul_eq_smul [semiring R] {r : R} {x : hahn_series Γ R} :\n  (single 0 r) * x = r • x :=\nby { ext, exact single_zero_mul_coeff }\n\ntheorem support_mul_subset_add_support [semiring R] {x y : hahn_series Γ R} :\n  support (x * y) ⊆ support x + support y :=\nbegin\n  apply set.subset.trans (λ x hx, _) support_add_antidiagonal_subset_add,\n  { exact x.is_pwo_support },\n  { exact y.is_pwo_support },\n  contrapose! hx,\n  simp only [not_nonempty_iff_eq_empty, ne.def, set.mem_set_of_eq] at hx,\n  simp [hx],\nend\n\n@[simp]\nlemma mul_coeff_min_add_min {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [semiring R]\n  {x y : hahn_series Γ R} (hx : x ≠ 0) (hy : y ≠ 0) :\n  (x * y).coeff (x.is_wf_support.min (support_nonempty_iff.2 hx) +\n    y.is_wf_support.min (support_nonempty_iff.2 hy)) =\n    (x.coeff (x.is_wf_support.min (support_nonempty_iff.2 hx))) *\n    y.coeff (y.is_wf_support.min (support_nonempty_iff.2 hy)) :=\nby rw [mul_coeff, finset.add_antidiagonal_min_add_min, finset.sum_singleton]\n\nprivate lemma mul_assoc' [semiring R] (x y z : hahn_series Γ R) :\n  x * y * z = x * (y * z) :=\nbegin\n  ext b,\n  rw [mul_coeff_left' (x.is_pwo_support.add y.is_pwo_support) support_mul_subset_add_support,\n      mul_coeff_right' (y.is_pwo_support.add z.is_pwo_support) support_mul_subset_add_support],\n  simp only [mul_coeff, add_coeff, sum_mul, mul_sum, sum_sigma'],\n  refine sum_bij_ne_zero (λ a has ha0, ⟨⟨a.2.1, a.2.2 + a.1.2⟩, ⟨a.2.2, a.1.2⟩⟩) _ _ _ _,\n  { rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H1 H2,\n    simp only [true_and, set.image2_add, eq_self_iff_true, mem_add_antidiagonal, ne.def,\n      set.image_prod, mem_sigma, set.mem_set_of_eq] at H1 H2 ⊢,\n    obtain ⟨⟨rfl, ⟨H3, nz⟩⟩, ⟨rfl, nx, ny⟩⟩ := H1,\n    refine ⟨⟨(add_assoc _ _ _).symm, nx, set.add_mem_add ny nz⟩, ny, nz⟩ },\n  { rintros ⟨⟨i1,j1⟩, ⟨k1,l1⟩⟩ ⟨⟨i2,j2⟩, ⟨k2,l2⟩⟩ H1 H2 H3 H4 H5,\n    simp only [set.image2_add, prod.mk.inj_iff, mem_add_antidiagonal, ne.def,\n      set.image_prod, mem_sigma, set.mem_set_of_eq, heq_iff_eq] at H1 H3 H5,\n    obtain ⟨⟨rfl, H⟩, rfl, rfl⟩ := H5,\n    simp only [and_true, prod.mk.inj_iff, eq_self_iff_true, heq_iff_eq],\n    exact add_right_cancel (H1.1.1.trans H3.1.1.symm) },\n  { rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H1 H2,\n    simp only [exists_prop, set.image2_add, prod.mk.inj_iff, mem_add_antidiagonal,\n      sigma.exists, ne.def, set.image_prod, mem_sigma, set.mem_set_of_eq, heq_iff_eq,\n      prod.exists] at H1 H2 ⊢,\n    obtain ⟨⟨rfl, nx, H⟩, rfl, ny, nz⟩ := H1,\n    exact ⟨i + k, l, i, k, ⟨⟨add_assoc _ _ _, set.add_mem_add nx ny, nz⟩, rfl, nx, ny⟩,\n      λ con, H2 ((mul_assoc _ _ _).symm.trans con), ⟨rfl, rfl⟩, rfl, rfl⟩ },\n  { rintros ⟨⟨i,j⟩, ⟨k,l⟩⟩ H1 H2,\n    simp [mul_assoc], }\nend\n\ninstance [semiring R] : semiring (hahn_series Γ R) :=\n{ zero := 0,\n  one := 1,\n  add := (+),\n  mul := (*),\n  zero_mul := λ _, by { ext, simp },\n  mul_zero := λ _, by { ext, simp },\n  one_mul := λ x, single_zero_mul_eq_smul.trans (one_smul _ _),\n  mul_one := λ x, by { ext, exact mul_single_zero_coeff.trans (mul_one _) },\n  mul_assoc := mul_assoc',\n  .. hahn_series.add_comm_monoid,\n  .. hahn_series.distrib }\n\ninstance [comm_semiring R] : comm_semiring (hahn_series Γ R) :=\n{ mul_comm := λ x y, begin\n    ext,\n    simp_rw [mul_coeff, mul_comm],\n    refine sum_bij (λ a ha, ⟨a.2, a.1⟩) _ (λ a ha, by simp) _ _,\n    { intros a ha,\n      simp only [mem_add_antidiagonal, ne.def, set.mem_set_of_eq] at ha ⊢,\n      obtain ⟨h1, h2, h3⟩ := ha,\n      refine ⟨_, h3, h2⟩,\n      rw [add_comm, h1], },\n    { rintros ⟨a1, a2⟩ ⟨b1, b2⟩ ha hb hab,\n      rw prod.ext_iff at *,\n      refine ⟨hab.2, hab.1⟩, },\n    { intros a ha,\n      refine ⟨a.swap, _, by simp⟩,\n      simp only [prod.fst_swap, mem_add_antidiagonal, prod.snd_swap,\n        ne.def, set.mem_set_of_eq] at ha ⊢,\n      exact ⟨(add_comm _ _).trans ha.1, ha.2.2, ha.2.1⟩ }\n  end,\n  .. hahn_series.semiring }\n\ninstance [ring R] : ring (hahn_series Γ R) :=\n{ .. hahn_series.semiring,\n  .. hahn_series.add_comm_group }\n\ninstance [comm_ring R] : comm_ring (hahn_series Γ R) :=\n{ .. hahn_series.comm_semiring,\n  .. hahn_series.ring }\n\ninstance {Γ} [linear_ordered_cancel_add_comm_monoid Γ] [integral_domain R] :\n  integral_domain (hahn_series Γ R) :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := λ x y xy, begin\n    by_cases hx : x = 0,\n    { left, exact hx },\n    right,\n    contrapose! xy,\n    rw [hahn_series.ext_iff, function.funext_iff, not_forall],\n    refine ⟨x.is_wf_support.min (support_nonempty_iff.2 hx) +\n      y.is_wf_support.min (support_nonempty_iff.2 xy), _⟩,\n    rw [mul_coeff_min_add_min, zero_coeff, mul_eq_zero],\n    simp [coeff_min_ne_zero, hx, xy],\n  end,\n  .. hahn_series.nontrivial,\n  .. hahn_series.comm_ring }\n\nsection semiring\nvariables [semiring R]\n\n@[simp]\nlemma single_mul_single {a b : Γ} {r s : R} :\n  single a r * single b s = single (a + b) (r * s) :=\nbegin\n  ext x,\n  by_cases h : x = a + b,\n  { rw [h, mul_single_coeff_add],\n    simp },\n  { rw [single_coeff_of_ne h, mul_coeff, sum_eq_zero],\n    rintros ⟨y1, y2⟩ hy,\n    obtain ⟨rfl, hy1, hy2⟩ := mem_add_antidiagonal.1 hy,\n    rw [eq_of_mem_support_single hy1, eq_of_mem_support_single hy2] at h,\n    exact (h rfl).elim }\nend\n\n/-- `C a` is the constant Hahn Series `a`. `C` is provided as a ring homomorphism. -/\n@[simps] def C : R →+* (hahn_series Γ R) :=\n{ to_fun := single 0,\n  map_zero' := single_eq_zero,\n  map_one' := rfl,\n  map_add' := λ x y, by { ext a, by_cases h : a = 0; simp [h] },\n  map_mul' := λ x y, by rw [single_mul_single, zero_add] }\n\n@[simp]\nlemma C_zero : C (0 : R) = (0 : hahn_series Γ R) := C.map_zero\n\n@[simp]\nlemma C_one : C (1 : R) = (1 : hahn_series Γ R) := C.map_one\n\nlemma C_mul_eq_smul {r : R} {x : hahn_series Γ R} : C r * x = r • x :=\nsingle_zero_mul_eq_smul\n\nend semiring\n\nsection algebra\nvariables [comm_semiring R] {A : Type*} [semiring A] [algebra R A]\n\ninstance : algebra R (hahn_series Γ A) :=\n{ to_ring_hom := C.comp (algebra_map R A),\n  smul_def' := λ r x, by { ext, simp },\n  commutes' := λ r x, by { ext, simp only [smul_coeff, single_zero_mul_eq_smul, ring_hom.coe_comp,\n    ring_hom.to_fun_eq_coe, C_apply, function.comp_app, algebra_map_smul, mul_single_zero_coeff],\n    rw [← algebra.commutes, algebra.smul_def], }, }\n\ntheorem C_eq_algebra_map : C = (algebra_map R (hahn_series Γ R)) := rfl\n\ntheorem algebra_map_apply {r : R} :\n  algebra_map R (hahn_series Γ A) r = C (algebra_map R A r) := rfl\n\ninstance [nontrivial Γ] [nontrivial R] : nontrivial (subalgebra R (hahn_series Γ R)) :=\n⟨⟨⊥, ⊤, begin\n  rw [ne.def, set_like.ext_iff, not_forall],\n  obtain ⟨a, ha⟩ := exists_ne (0 : Γ),\n  refine ⟨single a 1, _⟩,\n  simp only [algebra.mem_bot, not_exists, set.mem_range, iff_true, algebra.mem_top],\n  intros x,\n  rw [ext_iff, function.funext_iff, not_forall],\n  refine ⟨a, _⟩,\n  rw [single_coeff_same, algebra_map_apply, C_apply, single_coeff_of_ne ha],\n  exact zero_ne_one\nend⟩⟩\n\nend algebra\n\nend multiplication\n\nsection semiring\nvariables [semiring R]\n\n/-- The ring `hahn_series ℕ R` is isomorphic to `power_series R`. -/\n@[simps] def to_power_series : (hahn_series ℕ R) ≃+* power_series R :=\n{ to_fun := λ f, power_series.mk f.coeff,\n  inv_fun := λ f, ⟨λ n, power_series.coeff R n f, (nat.lt_wf.is_wf _).is_pwo⟩,\n  left_inv := λ f, by { ext, simp },\n  right_inv := λ f, by { ext, simp },\n  map_add' := λ f g, by { ext, simp },\n  map_mul' := λ f g, begin\n    ext n,\n    simp only [power_series.coeff_mul, power_series.coeff_mk, mul_coeff, is_pwo_support],\n    classical,\n    refine sum_filter_ne_zero.symm.trans\n      ((sum_congr _ (λ _ _, rfl)).trans sum_filter_ne_zero),\n    ext m,\n    simp only [nat.mem_antidiagonal, and.congr_left_iff, mem_add_antidiagonal, ne.def,\n      and_iff_left_iff_imp, mem_filter, mem_support],\n    intros h1 h2,\n    contrapose h1,\n    rw ← decidable.or_iff_not_and_not at h1,\n    cases h1; simp [h1]\n  end }\n\nlemma coeff_to_power_series {f : hahn_series ℕ R} {n : ℕ} :\n  power_series.coeff R n f.to_power_series = f.coeff n :=\npower_series.coeff_mk _ _\n\nlemma coeff_to_power_series_symm {f : power_series R} {n : ℕ} :\n  (hahn_series.to_power_series.symm f).coeff n = power_series.coeff R n f := rfl\n\nend semiring\n\nsection algebra\nvariables (R) [comm_semiring R] {A : Type*} [semiring A] [algebra R A]\n\n/-- The `R`-algebra `hahn_series ℕ A` is isomorphic to `power_series A`. -/\n@[simps] def to_power_series_alg : (hahn_series ℕ A) ≃ₐ[R] power_series A :=\n{ commutes' := λ r, begin\n    ext n,\n    simp only [algebra_map_apply, power_series.algebra_map_apply, ring_equiv.to_fun_eq_coe, C_apply,\n      coeff_to_power_series],\n    cases n,\n    { simp only [power_series.coeff_zero_eq_constant_coeff, single_coeff_same],\n      refl },\n    { simp only [n.succ_ne_zero, ne.def, not_false_iff, single_coeff_of_ne],\n      rw [power_series.coeff_C, if_neg n.succ_ne_zero] }\n  end,\n  .. to_power_series }\n\nend algebra\n\nsection valuation\n\nvariables [linear_ordered_add_comm_group Γ] [integral_domain R] [nontrivial R]\n\ninstance : linear_ordered_comm_group (multiplicative Γ) :=\n{ .. (infer_instance : linear_order (multiplicative Γ)),\n  .. (infer_instance : ordered_comm_group (multiplicative Γ)) }\n\ninstance : linear_ordered_comm_group_with_zero (with_zero (multiplicative Γ)) :=\n{ zero_le_one := with_zero.zero_le 1,\n  .. (with_zero.ordered_comm_monoid),\n  .. (infer_instance : linear_order (with_zero (multiplicative Γ))),\n  .. (infer_instance : comm_group_with_zero (with_zero (multiplicative Γ))) }\n\nvariables (Γ) (R)\n\n/-- The additive valuation on `hahn_series Γ R`, returning the smallest index at which\n  a Hahn Series has a nonzero coefficient, or `⊤` for the 0 series.  -/\ndef add_val : add_valuation (hahn_series Γ R) (with_top Γ) :=\nadd_valuation.of (λ x, if h : x = (0 : hahn_series Γ R) then (⊤ : with_top Γ)\n    else x.is_wf_support.min (support_nonempty_iff.2 h))\n  (dif_pos rfl)\n  ((dif_neg one_ne_zero).trans (by simp))\n  (λ x y, begin\n    by_cases hx : x = 0,\n    { by_cases hy : y = 0; { simp [hx, hy] } },\n    { by_cases hy : y = 0,\n      { simp [hx, hy] },\n      { simp only [hx, hy, support_nonempty_iff, dif_neg, not_false_iff, is_wf_support, min_le_iff],\n        by_cases hxy : x + y = 0,\n        { simp [hxy] },\n        rw [dif_neg hxy, with_top.coe_le_coe, with_top.coe_le_coe, ← min_le_iff,\n          ← set.is_wf.min_union],\n        exact set.is_wf.min_le_min_of_subset support_add_subset, } },\n  end)\n  (λ x y, begin\n    by_cases hx : x = 0,\n    { simp [hx] },\n    by_cases hy : y = 0,\n    { simp [hy] },\n    rw [dif_neg hx, dif_neg hy, dif_neg (mul_ne_zero hx hy),\n      ← with_top.coe_add, with_top.coe_eq_coe],\n    apply le_antisymm,\n    { apply set.is_wf.min_le,\n      rw [mem_support, mul_coeff_min_add_min],\n      exact mul_ne_zero (coeff_min_ne_zero hx) (coeff_min_ne_zero hy) },\n    { rw ← set.is_wf.min_add,\n      exact set.is_wf.min_le_min_of_subset (support_mul_subset_add_support) },\n  end)\n\nvariables {Γ} {R}\n\nlemma add_val_apply {x : hahn_series Γ R} :\n  add_val Γ R x = if h : x = (0 : hahn_series Γ R) then (⊤ : with_top Γ)\n    else x.is_wf_support.min (support_nonempty_iff.2 h) :=\nadd_valuation.of_apply _\n\n@[simp]\nlemma add_val_apply_of_ne {x : hahn_series Γ R} (hx : x ≠ 0) :\n  add_val Γ R x = x.is_wf_support.min (support_nonempty_iff.2 hx) :=\ndif_neg hx\n\nend valuation\n\nsection\nvariables (Γ) (R) [partial_order Γ] [add_comm_monoid R]\n\n/-- An infinite family of Hahn series which has a formal coefficient-wise sum.\n  The requirements for this are that the union of the supports of the series is well-founded,\n  and that only finitely many series are nonzero at any given coefficient. -/\nstructure summable_family (α : Type*) :=\n(to_fun : α → hahn_series Γ R)\n(is_pwo_Union_support' : set.is_pwo (⋃ (a : α), (to_fun a).support))\n(finite_co_support' : ∀ (g : Γ), ({a | (to_fun a).coeff g ≠ 0}).finite)\n\nend\n\nnamespace summable_family\nsection add_comm_monoid\n\nvariables [partial_order Γ] [add_comm_monoid R] {α : Type*}\n\ninstance : has_coe_to_fun (summable_family Γ R α) :=\n⟨λ _, (α → hahn_series Γ R), to_fun⟩\n\nlemma is_pwo_Union_support (s : summable_family Γ R α) : set.is_pwo (⋃ (a : α), (s a).support) :=\ns.is_pwo_Union_support'\n\nlemma finite_co_support (s : summable_family Γ R α) (g : Γ) :\n  (function.support (λ a, (s a).coeff g)).finite :=\ns.finite_co_support' g\n\nlemma coe_injective : @function.injective (summable_family Γ R α) (α → hahn_series Γ R) coe_fn\n| ⟨f1, hU1, hf1⟩ ⟨f2, hU2, hf2⟩ h :=\nbegin\n  change f1 = f2 at h,\n  subst h,\nend\n\n@[ext]\nlemma ext {s t : summable_family Γ R α} (h : ∀ (a : α), s a = t a) : s = t :=\ncoe_injective $ funext h\n\ninstance : has_add (summable_family Γ R α) :=\n⟨λ x y, { to_fun := x + y,\n    is_pwo_Union_support' := (x.is_pwo_Union_support.union y.is_pwo_Union_support).mono (begin\n      rw ← set.Union_union_distrib,\n      exact set.Union_subset_Union (λ a, support_add_subset)\n    end),\n    finite_co_support' := λ g, ((x.finite_co_support g).union (y.finite_co_support g)).subset begin\n      intros a ha,\n      change (x a).coeff g + (y a).coeff g ≠ 0 at ha,\n      rw [set.mem_union, function.mem_support, function.mem_support],\n      contrapose! ha,\n      rw [ha.1, ha.2, add_zero]\n    end }⟩\n\ninstance : has_zero (summable_family Γ R α) :=\n⟨⟨0, by simp, by simp⟩⟩\n\ninstance : inhabited (summable_family Γ R α) := ⟨0⟩\n\n@[simp]\nlemma coe_add {s t : summable_family Γ R α} : ⇑(s + t) = s + t := rfl\n\nlemma add_apply {s t : summable_family Γ R α} {a : α} : (s + t) a = s a + t a := rfl\n\n@[simp]\nlemma coe_zero : ((0 : summable_family Γ R α) : α → hahn_series Γ R) = 0 := rfl\n\nlemma zero_apply {a : α} : (0 : summable_family Γ R α) a = 0 := rfl\n\ninstance : add_comm_monoid (summable_family Γ R α) :=\n{ add := (+),\n  zero := 0,\n  zero_add := λ s, by { ext, apply zero_add },\n  add_zero := λ s, by { ext, apply add_zero },\n  add_comm := λ s t, by { ext, apply add_comm },\n  add_assoc := λ r s t, by { ext, apply add_assoc } }\n\n/-- The infinite sum of a `summable_family` of Hahn series. -/\ndef hsum (s : summable_family Γ R α) :\n  hahn_series Γ R :=\n{ coeff := λ g, ∑ᶠ i, (s i).coeff g,\n  is_pwo_support' := s.is_pwo_Union_support.mono (λ g, begin\n    contrapose,\n    rw [set.mem_Union, not_exists, function.mem_support, not_not],\n    simp_rw [mem_support, not_not],\n    intro h,\n    rw [finsum_congr h, finsum_zero],\n  end) }\n\n@[simp]\nlemma hsum_coeff {s : summable_family Γ R α} {g : Γ} :\n  s.hsum.coeff g = ∑ᶠ i, (s i).coeff g := rfl\n\nlemma support_hsum_subset {s : summable_family Γ R α} :\n  s.hsum.support ⊆ ⋃ (a : α), (s a).support :=\nλ g hg, begin\n  rw [mem_support, hsum_coeff, finsum_eq_sum _ (s.finite_co_support _)] at hg,\n  obtain ⟨a, h1, h2⟩ := exists_ne_zero_of_sum_ne_zero hg,\n  rw [set.mem_Union],\n  exact ⟨a, h2⟩,\nend\n\n@[simp]\nlemma hsum_add {s t : summable_family Γ R α} : (s + t).hsum = s.hsum + t.hsum :=\nbegin\n  ext g,\n  simp only [hsum_coeff, add_coeff, add_apply],\n  exact finsum_add_distrib (s.finite_co_support _) (t.finite_co_support _)\nend\n\nend add_comm_monoid\n\nsection add_comm_group\nvariables [partial_order Γ] [add_comm_group R] {α : Type*} {s t : summable_family Γ R α} {a : α}\n\ninstance : add_comm_group (summable_family Γ R α) :=\n{ neg := λ s, { to_fun := λ a, - s a,\n    is_pwo_Union_support' := by { simp_rw [support_neg], exact s.is_pwo_Union_support' },\n    finite_co_support' := λ g, by { simp only [neg_coeff', pi.neg_apply, ne.def, neg_eq_zero],\n      exact s.finite_co_support g } },\n  add_left_neg := λ a, by { ext, apply add_left_neg },\n  .. summable_family.add_comm_monoid }\n\n@[simp]\nlemma coe_neg : ⇑(-s) = - s := rfl\n\nlemma neg_apply : (-s) a = - (s a) := rfl\n\nlemma coe_sub : ⇑(s - t) = s - t := rfl\n\nlemma sub_apply : (s - t) a = s a - t a := rfl\n\nend add_comm_group\n\nsection semiring\n\nvariables [ordered_cancel_add_comm_monoid Γ] [semiring R] {α : Type*}\n\ninstance : has_scalar (hahn_series Γ R) (summable_family Γ R α) :=\n{ smul := λ x s, { to_fun := λ a, x * (s a),\n    is_pwo_Union_support' := begin\n      apply (x.is_pwo_support.add s.is_pwo_Union_support).mono,\n      refine set.subset.trans (set.Union_subset_Union (λ a, support_mul_subset_add_support)) _,\n      intro g,\n      simp only [set.mem_Union, exists_imp_distrib],\n      exact λ a ha, (set.add_subset_add (set.subset.refl _) (set.subset_Union _ a)) ha,\n    end,\n    finite_co_support' := λ g, begin\n      refine ((add_antidiagonal x.is_pwo_support s.is_pwo_Union_support g).finite_to_set.bUnion\n        (λ ij hij, _)).subset (λ a ha, _),\n      { exact λ ij hij, function.support (λ a, (s a).coeff ij.2) },\n      { apply s.finite_co_support },\n      { obtain ⟨i, j, hi, hj, rfl⟩ := support_mul_subset_add_support ha,\n        simp only [exists_prop, set.mem_Union, mem_add_antidiagonal,\n          mul_coeff, ne.def, mem_support, is_pwo_support, prod.exists],\n        refine ⟨i, j, mem_coe.2 (mem_add_antidiagonal.2 ⟨rfl, hi, set.mem_Union.2 ⟨a, hj⟩⟩), hj⟩, }\n    end } }\n\n@[simp]\nlemma smul_apply {x : hahn_series Γ R} {s : summable_family Γ R α} {a : α} :\n  (x • s) a = x * (s a) := rfl\n\ninstance : module (hahn_series Γ R) (summable_family Γ R α) :=\n{ smul := (•),\n  smul_zero := λ x, ext (λ a, mul_zero _),\n  zero_smul := λ x, ext (λ a, zero_mul _),\n  one_smul := λ x, ext (λ a, one_mul _),\n  add_smul := λ x y s, ext (λ a, add_mul _ _ _),\n  smul_add := λ x s t, ext (λ a, mul_add _ _ _),\n  mul_smul := λ x y s, ext (λ a, mul_assoc _ _ _) }\n\n@[simp]\nlemma hsum_smul {x : hahn_series Γ R} {s : summable_family Γ R α} :\n  (x • s).hsum = x * s.hsum :=\nbegin\n  ext g,\n  simp only [mul_coeff, hsum_coeff, smul_apply],\n  have h : ∀ i, (s i).support ⊆ ⋃ j, (s j).support := set.subset_Union _,\n  refine (eq.trans (finsum_congr (λ a, _))\n    (finsum_sum_comm (add_antidiagonal x.is_pwo_support s.is_pwo_Union_support g)\n    (λ i ij, x.coeff (prod.fst ij) * (s i).coeff ij.snd) _)).trans _,\n  { refine sum_subset (add_antidiagonal_mono_right (set.subset_Union _ a)) _,\n    rintro ⟨i, j⟩ hU ha,\n    rw mem_add_antidiagonal at *,\n    rw [not_not.1 (λ con, ha ⟨hU.1, hU.2.1, con⟩), mul_zero] },\n  { rintro ⟨i, j⟩ hij,\n    refine (s.finite_co_support j).subset _,\n    simp_rw [function.support_subset_iff', function.mem_support, not_not],\n    intros a ha,\n    rw [ha, mul_zero] },\n  { refine (sum_congr rfl _).trans (sum_subset (add_antidiagonal_mono_right _) _).symm,\n    { rintro ⟨i, j⟩ hij,\n      rw mul_finsum,\n      apply s.finite_co_support, },\n    { intros x hx,\n      simp only [set.mem_Union, ne.def, mem_support],\n      contrapose! hx,\n      simp [hx] },\n    { rintro ⟨i, j⟩ hU ha,\n      rw mem_add_antidiagonal at *,\n      rw [← hsum_coeff, not_not.1 (λ con, ha ⟨hU.1, hU.2.1, con⟩), mul_zero] } }\nend\n\n/-- The summation of a `summable_family` as a `linear_map`. -/\n@[simps] def lsum : (summable_family Γ R α) →ₗ[hahn_series Γ R] (hahn_series Γ R) :=\n⟨hsum, λ _ _, hsum_add, λ _ _, hsum_smul⟩\n\nend semiring\n\nsection of_finsupp\nvariables [partial_order Γ] [add_comm_monoid R] {α : Type*}\n\n/-- A family with only finitely many nonzero elements is summable. -/\ndef of_finsupp (f : α →₀ (hahn_series Γ R)) :\n  summable_family Γ R α :=\n{ to_fun := f,\n  is_pwo_Union_support' := begin\n      apply (f.support.is_pwo_sup (λ a, (f a).support) (λ a ha, (f a).is_pwo_support)).mono,\n      intros g hg,\n      obtain ⟨a, ha⟩ := set.mem_Union.1 hg,\n      have haf : a ∈ f.support,\n      { rw finsupp.mem_support_iff,\n        contrapose! ha,\n        rw [ha, support_zero],\n        exact set.not_mem_empty _ },\n      have h : (λ i, (f i).support) a ≤ _ := le_sup haf,\n      exact h ha,\n    end,\n  finite_co_support' := λ g, begin\n    refine f.support.finite_to_set.subset (λ a ha, _),\n    simp only [coeff.add_monoid_hom_apply, mem_coe, finsupp.mem_support_iff,\n    ne.def, function.mem_support],\n    contrapose! ha,\n    simp [ha]\n  end }\n\n@[simp]\nlemma coe_of_finsupp {f : α →₀ (hahn_series Γ R)} : ⇑(summable_family.of_finsupp f) = f := rfl\n\n@[simp]\nlemma hsum_of_finsupp {f : α →₀ (hahn_series Γ R)} :\n  (of_finsupp f).hsum = f.sum (λ a, id) :=\nbegin\n  ext g,\n  simp only [hsum_coeff, coe_of_finsupp, finsupp.sum, ne.def],\n  simp_rw [← coeff.add_monoid_hom_apply, id.def],\n  rw [add_monoid_hom.map_sum, finsum_eq_sum_of_support_subset],\n  intros x h,\n  simp only [coeff.add_monoid_hom_apply, mem_coe, finsupp.mem_support_iff, ne.def],\n  contrapose! h,\n  simp [h]\nend\n\nend of_finsupp\n\nend summable_family\n\nend hahn_series\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/hahn_series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7581770710297577}}
{"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ölzl\n\n! This file was ported from Lean 3 source module algebra.order.monoid.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.Algebra.Order.Monoid.Lemmas\nimport Mathlib.Order.BoundedOrder\n\n/-!\n# Ordered monoids\n\nThis file provides the definitions of ordered monoids.\n\n-/\n\n\nopen Function\n\nuniverse u\n\nvariable {α : Type u} {β : Type _}\n\n/-- An ordered commutative monoid is a commutative monoid\nwith a partial order such that `a ≤ b → c * a ≤ c * b` (multiplication is monotone)\n-/\nclass OrderedCommMonoid (α : Type _) extends CommMonoid α, PartialOrder α where\n  /-- Multiplication is monotone in an `OrderedCommMonoid`. -/\n  protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b\n#align ordered_comm_monoid OrderedCommMonoid\n\n/-- An ordered (additive) commutative monoid is a commutative monoid\n  with a partial order such that `a ≤ b → c + a ≤ c + b` (addition is monotone)\n-/\nclass OrderedAddCommMonoid (α : Type _) extends AddCommMonoid α, PartialOrder α where\n  /-- Addition is monotone in an `OrderedAddCommMonoid`. -/\n  protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b\n#align ordered_add_comm_monoid OrderedAddCommMonoid\n\nattribute [to_additive] OrderedCommMonoid\n\nsection OrderedInstances\n\n@[to_additive]\ninstance OrderedCommMonoid.to_covariantClass_left (M : Type _) [OrderedCommMonoid M] :\n    CovariantClass M M (· * ·) (· ≤ ·) where\n  elim := fun a _ _ 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/- This instance can be proven with `by apply_instance`.  However, `WithBot ℕ` does not\npick up a `CovariantClass M M (function.swap (*)) (≤)` instance without it (see PR mathlib#7940). -/\n@[to_additive]\ninstance OrderedCommMonoid.to_covariantClass_right (M : Type _) [OrderedCommMonoid M] :\n    CovariantClass M M (swap (· * ·)) (· ≤ ·) :=\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/- This is not an instance, to avoid creating a loop in the type-class system: in a\n`LeftCancelSemigroup` with a `PartialOrder`, assuming `CovariantClass M M (*) (≤)` implies\n`CovariantClass M M (*) (<)`, see `LeftCancelSemigroup.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 (· * ·) (· < ·)] :\n    CovariantClass M M (· * ·) (· ≤ ·) :=\n  ⟨covariant_le_of_covariant_lt _ _ _ CovariantClass.elim⟩\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/- This is not an instance, to avoid creating a loop in the type-class system: in a\n`RightCancelSemigroup` with a `PartialOrder`, assuming `CovariantClass M M (swap (*)) (<)`\nimplies `CovariantClass M M (swap (*)) (≤)`, see\n`RightCancelSemigroup.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 (· * ·)) (· < ·)] :\n    CovariantClass M M (swap (· * ·)) (· ≤ ·) :=\n  ⟨covariant_le_of_covariant_lt _ _ _ CovariantClass.elim⟩\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\nend OrderedInstances\n\nset_option linter.deprecated false in\n@[deprecated] theorem bit0_pos [OrderedAddCommMonoid α] {a : α} (h : 0 < a) : 0 < bit0 a :=\n  add_pos' h h\n#align bit0_pos bit0_pos\n\n/-- A linearly ordered additive commutative monoid. -/\nclass LinearOrderedAddCommMonoid (α : Type _) extends LinearOrder α, OrderedAddCommMonoid α\n#align linear_ordered_add_comm_monoid LinearOrderedAddCommMonoid\n\n/-- A linearly ordered commutative monoid. -/\n@[to_additive]\nclass LinearOrderedCommMonoid (α : Type _) extends LinearOrder α, OrderedCommMonoid α\n#align linear_ordered_comm_monoid LinearOrderedCommMonoid\n\nattribute [to_additive existing] LinearOrderedCommMonoid.toOrderedCommMonoid\n\n/-- A linearly ordered commutative monoid with an additively absorbing `⊤` element.\n  Instances should include number systems with an infinite element adjoined.` -/\nclass LinearOrderedAddCommMonoidWithTop (α : Type _) extends LinearOrderedAddCommMonoid α,\n    Top α where\n  /-- In a `LinearOrderedAddCommMonoidWithTop`, the `⊤` element is larger than any other element.-/\n  protected le_top : ∀ x : α, x ≤ ⊤\n  /-- In a `LinearOrderedAddCommMonoidWithTop`, the `⊤` element is invariant under addition. -/\n  protected top_add' : ∀ x : α, ⊤ + x = ⊤\n#align linear_ordered_add_comm_monoid_with_top LinearOrderedAddCommMonoidWithTop\n\n-- see Note [lower instance priority]\ninstance (priority := 100) LinearOrderedAddCommMonoidWithTop.toOrderTop (α : Type u)\n    [h : LinearOrderedAddCommMonoidWithTop α] : OrderTop α :=\n  { h with }\n#align linear_ordered_add_comm_monoid_with_top.to_order_top LinearOrderedAddCommMonoidWithTop.toOrderTop\n\nsection LinearOrderedAddCommMonoidWithTop\n\nvariable [LinearOrderedAddCommMonoidWithTop α] {a b : α}\n\n@[simp]\ntheorem top_add (a : α) : ⊤ + a = ⊤ :=\n  LinearOrderedAddCommMonoidWithTop.top_add' a\n#align top_add top_add\n\n@[simp]\ntheorem add_top (a : α) : a + ⊤ = ⊤ :=\n  Trans.trans (add_comm _ _) (top_add _)\n#align add_top add_top\n\nend LinearOrderedAddCommMonoidWithTop\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/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7581770628602683}}
{"text": "-- Suma_de_los_primeros_n_numeros_naturales.lean\n-- Suma de los primeros n números naturales\n-- José A. Alonso Jiménez\n-- Sevilla, 18 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que la suma de los números naturales\n--    0 + 1 + 2 + 3 + ··· + n\n-- es n × (n + 1)/2\n-- ---------------------------------------------------------------------\n\nimport data.nat.basic\nimport tactic\nopen nat\n\nvariable (n : ℕ)\n\nset_option pp.structure_projections false\n\n@[simp]\ndef suma : ℕ → ℕ\n| 0     := 0\n| (n+1) := suma n + (n+1)\n\n-- 1ª demostración\nexample :\n  2 * suma n = n * (n + 1) :=\nbegin\n  induction n with n HI,\n  { calc 2 * suma 0\n         = 2 * 0       : congr_arg ((*) 2) suma.equations._eqn_1\n     ... = 0           : mul_zero 2\n     ... = 0 * (0 + 1) : zero_mul (0 + 1), },\n  { calc 2 * suma (n + 1)\n         = 2 * (suma n + (n + 1))    : congr_arg ((*) 2) (suma.equations._eqn_2 n)\n     ... = 2 * suma n + 2 * (n + 1)  : mul_add 2 (suma n) (n + 1)\n     ... = n * (n + 1) + 2 * (n + 1) : congr_arg2 (+) HI rfl\n     ... = (n + 2) * (n + 1)         : (add_mul n 2 (n + 1)).symm\n     ... = (n + 1) * (n + 2)         : mul_comm (n + 2) (n + 1) },\nend\n\n-- 2ª demostración\nexample :\n  2 * suma n = n * (n + 1) :=\nbegin\n  induction n with n HI,\n  { calc 2 * suma 0\n         = 2 * 0       : rfl\n     ... = 0           : rfl\n     ... = 0 * (0 + 1) : rfl, },\n  { calc 2 * suma (n + 1)\n         = 2 * (suma n + (n + 1))    : rfl\n     ... = 2 * suma n + 2 * (n + 1)  : by ring\n     ... = n * (n + 1) + 2 * (n + 1) : by simp [HI]\n     ... = (n + 2) * (n + 1)         : by ring\n     ... = (n + 1) * (n + 2)         : by ring, },\nend\n\n-- 3ª demostración\nexample :\n  2 * suma n = n * (n + 1) :=\nbegin\n  induction n with n HI,\n  { simp, },\n  { calc 2 * suma (n + 1)\n         = 2 * (suma n + (n + 1))    : rfl\n     ... = 2 * suma n + 2 * (n + 1)  : by ring\n     ... = n * (n + 1) + 2 * (n + 1) : by simp [HI]\n     ... = (n + 1) * (n + 2)         : by ring, },\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_los_primeros_n_numeros_naturales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7581770599122758}}
{"text": "/- LoVe Homework 10: Denotational Semantics -/\n\nimport .love10_denotational_semantics_demo\n\nnamespace LoVe\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\n/- The `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 by\n`fail`, and nondeterministic choice between two alternatives (identified by the\n`bool` values `tt` and `ff`) is represented by `choice`. -/\n\ninductive nondet (α : Type) : Type\n| pure    : α → nondet\n| fail {} : nondet\n| choice  : (bool → nondet) → nondet\n\nnamespace nondet\n\n\n/- Question 1: The `nondet` Monad -/\n\ndef bind {α β : Type} : nondet α → (α → nondet β) → nondet β\n| (pure x)   f := f x\n| fail       f := fail\n| (choice k) f := choice (λb, bind (k b) f)\n\ninstance : has_pure nondet := { pure := @pure }\ninstance : has_bind nondet := { bind := @bind }\n\ndef starts_with : list ℕ → list ℕ → bool\n| (x :: xs) []        := ff\n| []        ys        := tt\n| (x :: xs) (y :: ys) := (x = y) && starts_with xs ys\n\n/- 1.2 (**optional**). Translate the `portmanteau` program from the `list` monad\nto the `nondet` monad. -/\n\ndef nondet_portmanteau : list ℕ → list ℕ → nondet (list ℕ)\n| []        ys := fail\n| (x :: xs) ys :=\n  choice (λb, if b then (if starts_with (x :: xs) ys then pure ys else fail)\n    else nondet_portmanteau xs ys >>= λzs, pure (list.cons x zs))\n    -- this line could also be `else (list.cons x <$> nondet_portmanteau xs ys)`\n\n\n/- Question 2: Nondeterminism, Denotationally -/\n\ndef list_sem {α : Type} : nondet α → list α\n| (pure x)   := [x]\n| fail       := []\n| (choice k) := list_sem (k ff) ++ list_sem (k tt)\n\n\n/- Question 3 (**optional**). Nondeterminism, Operationally -/\n\n/- We can define the following big-step operational semantics for `nondet`: -/\n\ninductive big_step {α : Type} : nondet α → α → Prop\n| pure {x : α} :\n  big_step (pure x) x\n| choice_l {k : bool → nondet α} {x : α} :\n  big_step (k ff) x → big_step (choice k) x\n| choice_r {k : bool → nondet α} {x : α} :\n  big_step (k tt) x → big_step (choice k) x\n-- there is no case for `fail`\n\nnotation mx `⟹` x := big_step mx x\n\n/- 3.1 (**optional**). Prove the following lemma.\n\nThe lemma states that `choice` has the semantics of \"angelic nondeterminism\": If\nthere is a computational path that leads to some `x`, the `choice` operator will\nproduce this `x`. -/\n\nlemma choice_existential {α : Type} (x : α) (k : bool → nondet α) :\n  nondet.choice k ⟹ x ↔ ∃b, k b ⟹ x :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases h,\n    { use ff,\n      assumption },\n    { use tt,\n      assumption } },\n  { intro h,\n    cases h,\n    cases h_w,\n    { apply big_step.choice_l,\n      assumption },\n    { apply big_step.choice_r,\n      assumption } }\nend\n\n/- 3.2 (**optional**). Prove the compatibility between denotational and\noperational semantics. -/\n\ntheorem den_op_compat {α : Type} :\n  ∀(x : α) (mx : nondet α), x ∈ list_sem mx ↔ mx ⟹ x\n| x (pure x')  :=\n  begin\n    apply iff.intro,\n    { intro h,\n      cases h;\n        cases h,\n      exact big_step.pure },\n    { intro h,\n      cases h,\n      apply iff.elim_right list.mem_singleton,\n      refl }\n  end\n| x fail       :=\n  begin\n    apply iff.intro;\n      intro h;\n      cases h\n  end\n| x (choice k) :=\n  begin\n    apply iff.intro,\n    { intro h,\n      cases iff.elim_left list.mem_append h,\n      { apply big_step.choice_l,\n        apply iff.elim_left (den_op_compat x (k ff)),\n        assumption },\n      { apply big_step.choice_r,\n        apply iff.elim_left (den_op_compat x (k tt)),\n        assumption } },\n    { intro h,\n      cases h;\n        apply iff.elim_right list.mem_append,\n      { apply or.intro_left,\n        apply iff.elim_right (den_op_compat x (k ff)),\n        assumption },\n      { apply or.intro_right,\n        apply iff.elim_right (den_op_compat x (k tt)),\n        assumption } }\n  end\n\nend nondet\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_homework_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7580890772152191}}
{"text": "\ntheorem Ex015 (a b : Prop):(a → b) → a → a ∧ b :=\n  assume H : (a → b),\n  assume H1 : a,\n  have A : b , from H H1,\n  show a ∧ b, from and.intro H1 A\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/Ex015.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9353465134460244, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7580786235872029}}
{"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.enat.basic\nimport 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\nnoncomputable theory\n\nopen function polynomial finsupp finset\nopen_locale big_operators classical polynomial\n\nnamespace polynomial\nuniverses u v\nvariables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}\n\nsection semiring\nvariables [semiring R] {p q r : R[X]}\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 ≠ 0` and `n` is the smallest power of `X` that appears\nin `p`, otherwise\n`trailing_degree 0 = ⊤`. -/\ndef trailing_degree (p : R[X]) : ℕ∞ := p.support.min\n\nlemma trailing_degree_lt_wf : well_founded\n(λp q : R[X], 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 `ℕ`, by defining\n`nat_trailing_degree ⊤ = 0`. -/\ndef nat_trailing_degree (p : R[X]) : ℕ := (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 : R[X]) : R := coeff p (nat_trailing_degree p)\n\n/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/\ndef trailing_monic (p : R[X]) := trailing_coeff p = (1 : R)\n\nlemma trailing_monic.def : trailing_monic p ↔ 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 : R[X]} (hp : p.trailing_monic) :\n  trailing_coeff p = 1 := hp\n\n@[simp] lemma trailing_degree_zero : trailing_degree (0 : R[X]) = ⊤ := rfl\n\n@[simp] lemma trailing_coeff_zero : trailing_coeff (0 : R[X]) = 0 := rfl\n\n@[simp] lemma nat_trailing_degree_zero : nat_trailing_degree (0 : R[X]) = 0 := rfl\n\nlemma trailing_degree_eq_top : trailing_degree p = ⊤ ↔ p = 0 :=\n⟨λ h, support_eq_empty.1 (finset.min_eq_top.1 h), λ h, by simp [h]⟩\n\nlemma trailing_degree_eq_nat_trailing_degree (hp : p ≠ 0) :\n  trailing_degree p = (nat_trailing_degree p : ℕ∞) :=\nlet ⟨n, hn⟩ :=\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 = n := not_not.1 hn,\nby rw [nat_trailing_degree, hn]; refl\n\nlemma trailing_degree_eq_iff_nat_trailing_degree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :\n  p.trailing_degree = n ↔ 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 : R[X]} {n : ℕ} (hn : 0 < n) :\n  p.trailing_degree = n ↔ p.nat_trailing_degree = n :=\nbegin\n  split,\n  { intro H, rwa ← 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 : R[X]} {n : ℕ}\n  (h : trailing_degree p = n) : nat_trailing_degree p = n :=\nhave hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,\noption.some_inj.1 $ show (nat_trailing_degree p : ℕ∞) = n,\n  by rwa [← trailing_degree_eq_nat_trailing_degree hp0]\n\n@[simp] lemma nat_trailing_degree_le_trailing_degree :\n  ↑(nat_trailing_degree p) ≤ trailing_degree p :=\nbegin\n  by_cases hp : p = 0, { rw [hp, trailing_degree_zero], exact le_top },\n  rw [trailing_degree_eq_nat_trailing_degree hp],\n  exact le_rfl\nend\n\nlemma nat_trailing_degree_eq_of_trailing_degree_eq [semiring S] {q : S[X]}\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 ≠ 0) : trailing_degree p ≤ n :=\nshow @has_le.le ℕ∞ _ p.support.min n,\nfrom min_le (mem_support_iff.2 h)\n\nlemma nat_trailing_degree_le_of_ne_zero (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n :=\nbegin\n  rw [← with_top.coe_le_coe, ← 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) ≠ 0) :\n  trailing_degree q ≤ 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 : ℕ} :\n  p.nat_trailing_degree ≠ n → trailing_degree p ≠ n :=\nmt $ λ h, by rw [nat_trailing_degree, h, option.get_or_else_coe]\n\ntheorem nat_trailing_degree_le_of_trailing_degree_le {n : ℕ} {hp : p ≠ 0}\n  (H : (n : ℕ∞) ≤ trailing_degree p) : n ≤ 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 ≠ 0) : trailing_degree (monomial n a) = n :=\nby rw [trailing_degree, support_monomial n ha, min_singleton]\n\nlemma nat_trailing_degree_monomial (ha : a ≠ 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) ≤ n :=\nif ha : a = 0 then by simp [ha] else (nat_trailing_degree_monomial ha).le\n\nlemma le_trailing_degree_monomial : ↑n ≤ 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 ≠ 0) : trailing_degree (C a) = (0 : ℕ∞) :=\ntrailing_degree_monomial ha\n\nlemma le_trailing_degree_C : (0 : ℕ∞) ≤ trailing_degree (C a) :=\nle_trailing_degree_monomial\n\nlemma trailing_degree_one_le : (0 : ℕ∞) ≤ trailing_degree (1 : R[X]) :=\nby rw [← 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 : R[X]) = 0 :=\nnat_trailing_degree_C 1\n\n@[simp] lemma nat_trailing_degree_nat_cast (n : ℕ) : nat_trailing_degree (n : R[X]) = 0 :=\nby simp only [←C_eq_nat_cast, nat_trailing_degree_C]\n\n@[simp] lemma trailing_degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 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 : ℕ) (a : R) :\n  (n : ℕ∞) ≤ 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 : ℕ∞) < 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 : R[X]} {n : ℕ}\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  { rw [hp, trailing_degree_zero], 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 : R[X]}\n  {hp : (0 : ℕ∞) < 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 : ℕ) :\n  (n : ℕ∞) ≤ trailing_degree (X^n : R[X]) :=\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 : ℕ∞) ≤ trailing_degree (X : R[X]) :=\nle_trailing_degree_monomial\n\nlemma nat_trailing_degree_X_le : (X : R[X]).nat_trailing_degree ≤ 1 :=\nnat_trailing_degree_monomial_le\n\n@[simp] lemma trailing_coeff_eq_zero : trailing_coeff p = 0 ↔ p = 0 :=\n⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1\n  (not_not.2 h) (mem_of_min (trailing_degree_eq_nat_trailing_degree hp)),\nλ h, h.symm ▸ leading_coeff_zero⟩\n\nlemma trailing_coeff_nonzero_iff_nonzero : trailing_coeff p ≠ 0 ↔ p ≠ 0 :=\nnot_congr trailing_coeff_eq_zero\n\nlemma nat_trailing_degree_mem_support_of_nonzero : p ≠ 0 → nat_trailing_degree p ∈ p.support :=\n(mem_support_iff.mpr ∘ trailing_coeff_nonzero_iff_nonzero.mpr)\n\nlemma nat_trailing_degree_le_of_mem_supp (a : ℕ) :\n  a ∈ p.support → nat_trailing_degree p ≤ a:=\nnat_trailing_degree_le_of_ne_zero ∘ mem_support_iff.mp\n\nlemma nat_trailing_degree_eq_support_min' (h : p ≠ 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 le_nat_trailing_degree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) :\n  n ≤ p.nat_trailing_degree :=\nbegin\n  rw nat_trailing_degree_eq_support_min' hp,\n  exact finset.le_min' _ _ _ (λ m hm, not_lt.1 $ λ hmn, mem_support_iff.1 hm $ hn _ hmn),\nend\n\nlemma nat_trailing_degree_le_nat_degree (p : R[X]) :\n  p.nat_trailing_degree ≤ 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 : R[X]} (hp : p ≠ 0) (n : ℕ) :\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 (λ h, mt trailing_coeff_eq_zero.mp hp _),\n    rwa [trailing_coeff, ←coeff_mul_X_pow] },\n  { rw [nat_trailing_degree_eq_support_min' (λ h, hp (mul_X_pow_eq_zero h)), finset.le_min'_iff],\n    intros y hy,\n    have key : n ≤ y,\n    { rw [mem_support_iff, coeff_mul_X_pow'] at hy,\n      exact by_contra (λ 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) },\nend\n\nlemma le_trailing_degree_mul : p.trailing_degree + q.trailing_degree ≤ (p * q).trailing_degree :=\nbegin\n  refine finset.le_min (λ n hn, _),\n  rw [mem_support_iff, coeff_mul] at hn,\n  obtain ⟨⟨i, j⟩, hij, hpq⟩ := exists_ne_zero_of_sum_ne_zero hn,\n  refine (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 (le_of_eq _),\n  rwa [← with_top.coe_add, with_top.coe_eq_coe, ←nat.mem_antidiagonal],\nend\n\nlemma le_nat_trailing_degree_mul (h : p * q ≠ 0) :\n  p.nat_trailing_degree + q.nat_trailing_degree ≤ (p * q).nat_trailing_degree :=\nbegin\n  have hp : p ≠ 0 := λ hp, h (by rw [hp, zero_mul]),\n  have hq : q ≠ 0 := λ hq, h (by rw [hq, mul_zero]),\n  rw [←with_top.coe_le_coe, with_top.coe_add, ←trailing_degree_eq_nat_trailing_degree hp,\n      ←trailing_degree_eq_nat_trailing_degree hq, ←trailing_degree_eq_nat_trailing_degree h],\n  exact le_trailing_degree_mul,\nend\n\nlemma coeff_mul_nat_trailing_degree_add_nat_trailing_degree :\n  (p * q).coeff (p.nat_trailing_degree + q.nat_trailing_degree) =\n    p.trailing_coeff * q.trailing_coeff :=\nbegin\n  rw coeff_mul,\n  refine finset.sum_eq_single (p.nat_trailing_degree, q.nat_trailing_degree) _\n    (λ h, (h (nat.mem_antidiagonal.mpr rfl)).elim),\n  rintro ⟨i, j⟩ h₁ h₂,\n  rw nat.mem_antidiagonal at h₁,\n  by_cases hi : i < p.nat_trailing_degree,\n  { rw [coeff_eq_zero_of_lt_nat_trailing_degree hi, zero_mul] },\n  by_cases hj : j < q.nat_trailing_degree,\n  { rw [coeff_eq_zero_of_lt_nat_trailing_degree hj, mul_zero] },\n  rw not_lt at hi hj,\n  refine (h₂ (prod.ext_iff.mpr _).symm).elim,\n  exact (add_eq_add_iff_eq_and_eq hi hj).mp h₁.symm,\nend\n\nlemma trailing_degree_mul' (h : p.trailing_coeff * q.trailing_coeff ≠ 0) :\n  (p * q).trailing_degree = p.trailing_degree + q.trailing_degree :=\nbegin\n  have hp : p ≠ 0 := λ hp, h (by rw [hp, trailing_coeff_zero, zero_mul]),\n  have hq : q ≠ 0 := λ hq, h (by rw [hq, trailing_coeff_zero, 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,\n    ← enat.coe_add],\n  apply le_trailing_degree_of_ne_zero,\n  rwa coeff_mul_nat_trailing_degree_add_nat_trailing_degree,\nend\n\nlemma nat_trailing_degree_mul' (h : p.trailing_coeff * q.trailing_coeff ≠ 0) :\n  (p * q).nat_trailing_degree = p.nat_trailing_degree + q.nat_trailing_degree :=\nbegin\n  have hp : p ≠ 0 := λ hp, h (by rw [hp, trailing_coeff_zero, zero_mul]),\n  have hq : q ≠ 0 := λ hq, h (by rw [hq, trailing_coeff_zero, mul_zero]),\n  apply nat_trailing_degree_eq_of_trailing_degree_eq_some,\n  rw [trailing_degree_mul' h, with_top.coe_add,\n      ←trailing_degree_eq_nat_trailing_degree hp, ←trailing_degree_eq_nat_trailing_degree hq],\nend\n\nlemma nat_trailing_degree_mul [no_zero_divisors R] (hp : p ≠ 0) (hq : q ≠ 0) :\n  (p * q).nat_trailing_degree = p.nat_trailing_degree + q.nat_trailing_degree :=\nnat_trailing_degree_mul' (mul_ne_zero (mt trailing_coeff_eq_zero.mp hp)\n  (mt trailing_coeff_eq_zero.mp hq))\n\nend semiring\n\nsection nonzero_semiring\nvariables [semiring R] [nontrivial R] {p q : R[X]}\n\n@[simp] lemma trailing_degree_one : trailing_degree (1 : R[X]) = (0 : ℕ∞) :=\ntrailing_degree_C one_ne_zero\n\n@[simp] lemma trailing_degree_X : trailing_degree (X : R[X]) = 1 :=\ntrailing_degree_monomial one_ne_zero\n\n@[simp] lemma nat_trailing_degree_X : (X : R[X]).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 : R[X]) : trailing_degree (-p) = trailing_degree p :=\nby unfold trailing_degree; rw support_neg\n\n@[simp] lemma nat_trailing_degree_neg (p : R[X]) :\n  nat_trailing_degree (-p) = nat_trailing_degree p :=\nby simp [nat_trailing_degree]\n\n@[simp] lemma nat_trailing_degree_int_cast (n : ℤ) : nat_trailing_degree (n : R[X]) = 0 :=\nby simp only [←C_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 : R[X]) : 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 : R[X]) (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 : R[X]} {ι : 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 : ℕ∞} (h : trailing_degree p < n) : p ≠ 0 :=\nλ h₀, h.not_le (by simp [h₀])\n\nend semiring\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/trailing_degree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465062370313, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7580786156035881}}
{"text": "/- \n\n# Advanced proposition world. \n\nIn this world we will learn five key tactics needed to solve all the\nlevels of the Natural Number Game, namely `split`, `cases`, `left`, `right`, and `exfalso`.\nThese, and `use` (which we'll get to in Inequality World) are all the\ntactics you will need to beat all the levels of the game.\n\n## Level 1: the `split` tactic.\n\nThe logical symbol `∧` means \"and\". If $P$ and $Q$ are propositions, then\n$P\\land Q$ is the proposition \"$P$ and $Q$\". If your *goal* is `P ∧ Q` then\nyou can make progress with the `split` tactic, which turns one goal `⊢ P ∧ Q`\ninto two goals, namely `⊢ P` and `⊢ Q`. In the level below, after a `split`,\nyou will be able to finish off the goals with the `exact` tactic.\n-/\n\n/- Lemma : no-side-bar\nIf $P$ and $Q$ are true, then $P\\land Q$ is true.\n-/\nexample (P Q : Prop) (p : P) (q : Q) : P ∧ Q :=\nbegin\n  split,\n  exact p,\n  exact q,\n\n\nend \n\n/- Tactic : split\n\n## Summary:\n\nIf the goal is `P ∧ Q` or `P ↔ Q` then `split` will break it into two goals.\n\n## Details\n\nIf `P Q : Prop` and the goal is `⊢ P ∧ Q`, then `split` will change it into\ntwo goals, namely `⊢ P` and `⊢ Q`. \n\nIf `P Q : Prop` and the goal is `⊢ P ↔ Q`, then `split` will change it into\ntwo goals, namely `⊢ P → Q` and `⊢ Q → P`.  \n\n## Example:\n\nIf your local context (the top right window) looks like this\n```\na b : mynat,\n⊢ a = b ↔ a + 3 = b + 3\n```\n\nthen after\n\n`split,`\n\nit will look like this:\n\n```\n2 goals\na b : mynat\n⊢ a = b → a + 3 = b + 3\n\na b : mynat\n⊢ a + 3 = b + 3 → a = b\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/level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8080672227971211, "lm_q1q2_score": 0.75806727104932}}
{"text": "import tactic\n\n/- see the document doc/categorya.pdf -/\n\n/- 1 Definition Section -/\n\ndef div (a:ℕ)(b:ℕ) := ∃c:ℕ, b=a*c\ninfix ` | `:55 := div\n\ndef is_even (a:ℕ) := 2|a \n\ndef is_prime (a:ℕ) := a≠1 ∧ \n(∀b:ℕ, b|a → (b=1 ∨ b=a))\n\ndef is_gcd (a:ℕ)(b:ℕ)(d:ℕ) := d|a ∧ d|b \n∧ (∀c:ℕ, (c|a ∧ c|b) → c|d)\n\ndef is_coprime (a:ℕ)(b:ℕ) := is_gcd a b 1\n\n/- 2 Lemma Section -/\n\n/- 2.1 Divison Part -/\n\nlemma one_div_nat (a:ℕ) : 1|a := -- Lemma 6\nbegin\n  use a,\n  simp,\nend\n\nlemma nat_div_zero (a:ℕ) : a|0 := -- Lemma 7\nbegin\n  use 0,\n  simp,\nend\n\nlemma div_refl (a:ℕ): a|a := -- Lemma 8\nbegin\n  use 1,\n  simp,\nend\n\nlemma div_trans (a:ℕ)(b:ℕ)(c:ℕ): \na|b → b|c → a|c := -- Lemma 9\nbegin\n  intros f g,\n  rw div at f g ⊢,\n  cases f with c1,\n  cases g with c2,\n  use c1*c2,\n  rw f_h at g_h,\n  rw g_h,\n  rw mul_assoc,\nend\n\n/- Divison Algorithm/ Quotient Remainder Theorem -/\n\nlemma div_alg_exist (a:ℕ)(b:ℕ):\nb≠0 → (∃q:ℕ, ∃r:ℕ, r<b ∧ a=b*q+r) := --Lemma 34\nbegin\n  intro f,\n\n  /- prove by induction on a -/\n  induction a with d hd,\n\n  /- the case for a=0 -/\n  use 0,\n  use 0,\n  split,\n  cases b,\n  exfalso,\n  apply f,\n  refl,\n  exact nat.succ_pos',\n  simp,\n\n  /- the inductive case:\n  assume that a=bq+r and r < b \n  we want to find q' and r' \n  such that a+1=bq'+r'\n  -/\n  cases hd with q hq,\n  cases hq with r hr,\n\n  /- there are two subcases -/\n  /- Subcase I: r+1 < b -/\n  by_cases r+1<b,\n  /- Let q'=q and r'=r+1 -/\n  use q,\n  use r+1,\n  cases hr with hrp hrq,\n  split,\n  exact h,\n  rw ← nat.one_add,\n  rw hrq,\n  rw add_comm,\n  rw add_assoc,\n\n  /- Subcase II: r+1 ≥ b -/\n  simp at h,\n  /- Since r+1 ≥ b, r+1=b+k for some k -/\n  have t:=nat.exists_eq_add_of_le h,\n  cases t with k tk,\n  /- Then we prove that k must be 0 -/\n  cases hr with hrp hrq,\n  have u: 0<1 := zero_lt_one,\n  have v: r+0+1<b+1 := nat.add_succ_lt_add hrp u,\n  rw add_assoc at v,\n  rw zero_add at v,\n  rw tk at v,\n  simp at v,\n  rw nat.lt_iff_add_one_le at v,\n  simp at v,\n  /- Let r'=0 and q'=q+1 -/\n  use q+1,\n  use 0,\n  rw v at tk,\n  simp at tk,\n  split,\n  cases b,\n  exfalso,\n  apply f,\n  refl,\n  apply nat.succ_pos',\n  simp,\n  rw ←  nat.one_add,\n  rw hrq,\n  rw ← tk,\n  ring,\nend  \n\nlemma div_alg_unique (a:ℕ)(b:ℕ):\n∀ q1 :ℕ, ∀ r1:ℕ, ∀ q2:ℕ, ∀ r2:ℕ, \n(r1<b ∧ r2<b ∧ a=b*q1+r1 ∧ a=b*q2+r2)→ \n(q1=q2 ∧ r1=r2):= -- Lemma 34\nbegin\n  sorry,\nend\n\n/- 2.2 Prime Part-/\n\nlemma zero_is_not_prime: \nis_prime(0)→false := -- Lemma 19\nbegin\n  intro h,\n  cases h with p q,\n  have t:=q(2),\n  have u:=nat_div_zero(2),\n  have v:=t(u),\n  cases v with s t,\n  simp at s,\n  exact s,\n  simp at t,\n  exact t,\nend\n\nlemma one_is_not_prime:\nis_prime(1)→false := -- Lemma 20\nbegin\n  intro f,\n  have t:=f.1,\n  apply t,\n  refl,\nend\n\n/- 2.3 GCD Part-/\n\nlemma gcd_of_a_div_b (a:ℕ)(b:ℕ):\na|b → is_gcd a b a := -- Lemma 27\nbegin\n  intro f,\n  split,\n  apply div_refl,\n  split,\n  exact f,\n  intro c,\n  intro g,\n  cases g with p q,\n  exact p,\nend\n\nlemma gcd_of_nat_zero (a:ℕ): \nis_gcd a 0 a := -- Lemma 28\nbegin\n  have t: a|0 := nat_div_zero a, \n  apply gcd_of_a_div_b a 0 t,\nend \n\nlemma gcd_of_one_nat (b:ℕ):\nis_gcd 1 b 1 := -- Lemma 29\nbegin\n  have t: 1|b := one_div_nat b, \n  apply gcd_of_a_div_b 1 b t,\nend\n\nlemma prime_coprime (a:ℕ)(p:ℕ):\n(¬p|a) → is_prime p → is_coprime a p \n:= -- Lemma 33\nbegin\n  intros f g,\n  cases g with gp gq,\n  split,\n  exact one_div_nat a,\n  split,\n  exact one_div_nat p,\n  intro c,\n  intro g,\n  cases g with g1 g2,\n  have gqc:=gq c,\n  have h:= gqc g2,\n  cases h with hp hq,\n  rw hp,\n  exact one_div_nat 1,\n  rw hq at g1,\n  exfalso,\n  cc,\nend ", "meta": {"author": "ourlean", "repo": "project", "sha": "9872a0d69caa780cbe409a09210b370649d3f341", "save_path": "github-repos/lean/ourlean-project", "path": "github-repos/lean/ourlean-project/project-9872a0d69caa780cbe409a09210b370649d3f341/categorya.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7580672623769659}}
{"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ébastien Gouëzel, Frédéric Dupuis\n-/\nimport algebra.direct_sum.module\nimport analysis.complex.basic\nimport analysis.convex.uniform\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 `ℝ^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 → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `euclidean_space` in\n`analysis.inner_product_space.pi_L2`.\n\n## Main results\n\n- We define the class `inner_product_space 𝕜 E` extending `normed_space 𝕜 E` with a number of basic\n  properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ`\n  or `ℂ`, 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ₛₗ` for the non-continuous version).\n- We define `orthonormal`, a predicate on a function `v : ι → 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 `⟪v i, x⟫` 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 `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively.\nWe also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,\nwhich respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product.\n\nThe orthogonal complement of a submodule `K` is denoted by `Kᗮ`.\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ément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]\n*  [Clément & Martin, *A Coq formal proof of the Lax–Milgram 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 {𝕜 E F : Type*} [is_R_or_C 𝕜]\n\n/-- Syntactic typeclass for types endowed with an inner product -/\nclass has_inner (𝕜 E : Type*) := (inner : E → E → 𝕜)\n\nexport has_inner (inner)\n\nnotation `⟪`x`, `y`⟫_ℝ` := @inner ℝ _ _ x y\nnotation `⟪`x`, `y`⟫_ℂ` := @inner ℂ _ _ x y\n\nsection notations\n\nlocalized \"notation `⟪`x`, `y`⟫` := @inner ℝ _ _ x y\" in real_inner_product_space\nlocalized \"notation `⟪`x`, `y`⟫` := @inner ℂ _ _ 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 `∥x∥^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product\nspaces.\n\nTo construct a norm from an inner product, see `inner_product_space.of_core`.\n-/\nclass inner_product_space (𝕜 : Type*) (E : Type*) [is_R_or_C 𝕜]\n  extends normed_group E, normed_space 𝕜 E, has_inner 𝕜 E :=\n(norm_sq_eq_inner : ∀ (x : E), ∥x∥^2 = re (inner x x))\n(conj_sym  : ∀ x y, conj (inner y x) = inner x y)\n(add_left  : ∀ x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : ∀ x y r, inner (r • 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 `ℝ`), 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  (𝕜 : Type*) (F : Type*)\n  [is_R_or_C 𝕜] [add_comm_group F] [module 𝕜 F] :=\n(inner     : F → F → 𝕜)\n(conj_sym  : ∀ x y, conj (inner y x) = inner x y)\n(nonneg_re : ∀ x, 0 ≤ re (inner x x))\n(definite  : ∀ x, inner x x = 0 → x = 0)\n(add_left  : ∀ x y z, inner (x + y) z = inner x z + inner y z)\n(smul_left : ∀ x y r, inner (r • 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 𝕜 F] [c : inner_product_space.core 𝕜 F]\ninclude c\n\nlocal notation `⟪`x`, `y`⟫` := @inner 𝕜 F _ x y\nlocal notation `norm_sqK` := @is_R_or_C.norm_sq 𝕜 _\nlocal notation `reK` := @is_R_or_C.re 𝕜 _\nlocal notation `absK` := @is_R_or_C.abs 𝕜 _\nlocal notation `ext_iff` := @is_R_or_C.ext_iff 𝕜 _\nlocal postfix `†`:90 := star_ring_end _\n\n/-- Inner product defined by the `inner_product_space.core` structure. -/\ndef to_has_inner : has_inner 𝕜 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 ⟪x, x⟫\n\nlocal notation `norm_sqF` := @norm_sq 𝕜 F _ _ _ _\n\nlemma inner_conj_sym (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_sym x y\n\nlemma inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _\n\nlemma inner_self_nonneg_im {x : F} : im ⟪x, x⟫ = 0 :=\nby rw [← @of_real_inj 𝕜, im_eq_conj_sub]; simp [inner_conj_sym]\n\nlemma inner_self_im_zero {x : F} : im ⟪x, x⟫ = 0 :=\ninner_self_nonneg_im\n\nlemma inner_add_left {x y z : F} : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=\nc.add_left _ _ _\n\nlemma inner_add_right {x y z : F} : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ :=\nby rw [←inner_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 : 𝕜) = ⟪x, x⟫ :=\nbegin\n  rw ext_iff,\n  exact ⟨by simp only [of_real_re]; refl, by simp only [inner_self_nonneg_im, of_real_im]⟩\nend\n\nlemma inner_re_symm {x y : F} : re ⟪x, y⟫ = re ⟪y, x⟫ :=\nby rw [←inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : F} : im ⟪x, y⟫ = -im ⟪y, x⟫ :=\nby rw [←inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : F} {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=\nc.smul_left _ _ _\n\nlemma inner_smul_right {x y : F} {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=\nby rw [←inner_conj_sym, inner_smul_left]; simp only [conj_conj, inner_conj_sym, ring_hom.map_mul]\n\nlemma inner_zero_left {x : F} : ⟪0, x⟫ = 0 :=\nby rw [←zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, ring_hom.map_zero]\n\nlemma inner_zero_right {x : F} : ⟪x, 0⟫ = 0 :=\nby rw [←inner_conj_sym, inner_zero_left]; simp only [ring_hom.map_zero]\n\nlemma inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 :=\niff.intro (c.definite _) (by { rintro rfl, exact inner_zero_left })\n\nlemma inner_self_re_to_K {x : F} : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=\nby norm_num [ext_iff, inner_self_nonneg_im]\n\nlemma inner_abs_conj_sym {x y : F} : abs ⟪x, y⟫ = abs ⟪y, x⟫ :=\n  by rw [←inner_conj_sym, abs_conj]\n\nlemma inner_neg_left {x y : F} : ⟪-x, y⟫ = -⟪x, y⟫ :=\nby { rw [← neg_one_smul 𝕜 x, inner_smul_left], simp }\n\nlemma inner_neg_right {x y : F} : ⟪x, -y⟫ = -⟪x, y⟫ :=\nby rw [←inner_conj_sym, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_sym]\n\nlemma inner_sub_left {x y z : F} : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ :=\nby { simp [sub_eq_add_neg, inner_add_left, inner_neg_left] }\n\nlemma inner_sub_right {x y z : F} : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ :=\nby { simp [sub_eq_add_neg, inner_add_right, inner_neg_right] }\n\nlemma inner_mul_conj_re_abs {x y : F} : re (⟪x, y⟫ * ⟪y, x⟫) = abs (⟪x, y⟫ * ⟪y, x⟫) :=\nby { rw [←inner_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} : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ :=\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} : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/--\n**Cauchy–Schwarz 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 ⟪x, y⟫ * abs ⟪y, x⟫ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=\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 ≠ 0 at hy,\n    have hy' : ⟪y, y⟫ ≠ 0 := λ h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := ⟪y, x⟫ / ⟪y, y⟫ with hT,\n    have h₁ : re ⟪y, x⟫ = re ⟪x, y⟫ := inner_re_symm,\n    have h₂ : im ⟪y, x⟫ = -im ⟪x, y⟫ := inner_im_symm,\n    have h₃ : ⟪y, x⟫ * ⟪x, y⟫ * ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = ⟪y, x⟫ * ⟪x, y⟫ / ⟪y, y⟫,\n    { rw [mul_div_assoc],\n      have : ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = 1 / ⟪y, y⟫ :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, ←div_eq_mul_inv] },\n    have h₄ : ⟪y, y⟫ = re ⟪y, y⟫ := by simp only [inner_self_re_to_K],\n    have h₅ : re ⟪y, y⟫ > 0,\n    { refine lt_of_le_of_ne inner_self_nonneg _,\n      intro H,\n      apply hy',\n      rw ext_iff,\n      exact ⟨by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]⟩ },\n    have h₆ : re ⟪y, y⟫ ≠ 0 := ne_of_gt h₅,\n    have hmain := calc\n      0   ≤ re ⟪x - T • y, x - T • y⟫\n                  : inner_self_nonneg\n      ... = re ⟪x, x⟫ - re ⟪T • y, x⟫ - re ⟪x, T • y⟫ + re ⟪T • y, T • y⟫\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h₁, h₂,\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 ⟪x, x⟫ - re (T† * ⟪y, x⟫) - re (T * ⟪x, y⟫) + re (T * T† * ⟪y, y⟫)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ / ⟪y, y⟫ * ⟪y, x⟫)\n                  : by field_simp [-mul_re, inner_conj_sym, hT, ring_hom.map_div, h₁, h₃]\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / ⟪y, y⟫)\n                  : by rw ←mul_div_right_comm\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / re ⟪y, y⟫)\n                  : by conv_lhs { rw [h₄] }\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫\n                  : by rw [div_re_of_real]\n      ... = re ⟪x, x⟫ - abs (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re ⟪x, x⟫ - abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫ ≤ re ⟪x, x⟫ := by linarith,\n    have := (mul_le_mul_right h₅).mpr hmain',\n    rwa [div_mul_cancel (abs ⟪x, y⟫ * abs ⟪y, x⟫) h₆] 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 := λ x, sqrt (re ⟪x, x⟫) }\n\nlocal attribute [instance] to_has_norm\n\nlemma norm_eq_sqrt_inner (x : F) : ∥x∥ = sqrt (re ⟪x, x⟫) := rfl\n\nlemma inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ∥x∥ * ∥x∥ :=\nby rw [norm_eq_sqrt_inner, ←sqrt_mul inner_self_nonneg (re ⟪x, x⟫),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma sqrt_norm_sq_eq_norm {x : F} : sqrt (norm_sqF x) = ∥x∥ := rfl\n\n/-- Cauchy–Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : F) : abs ⟪x, y⟫ ≤ ∥x∥ * ∥y∥ :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _))\nbegin\n  have H : ∥x∥ * ∥y∥ * (∥x∥ * ∥y∥) = re ⟪y, y⟫ * re ⟪x, x⟫,\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 ⟪x, x⟫) = 0 at H,\n      rw [sqrt_eq_zero inner_self_nonneg] at H,\n      apply (inner_self_eq_zero : ⟪x, x⟫ = 0 ↔ x = 0).mp,\n      rw ext_iff,\n      exact ⟨by simp [H], by simp [inner_self_im_zero]⟩ },\n    { rintro rfl,\n      change sqrt (re ⟪0, 0⟫) = 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₁ : abs ⟪x, y⟫ ≤ ∥x∥ * ∥y∥ := abs_inner_le_norm _ _,\n    have h₂ : re ⟪x, y⟫ ≤ abs ⟪x, y⟫ := re_le_abs _,\n    have h₃ : re ⟪x, y⟫ ≤ ∥x∥ * ∥y∥ := by linarith,\n    have h₄ : re ⟪y, x⟫ ≤ ∥x∥ * ∥y∥ := by rwa [←inner_conj_sym, conj_re],\n    have : ∥x + y∥ * ∥x + y∥ ≤ (∥x∥ + ∥y∥) * (∥x∥ + ∥y∥),\n    { simp [←inner_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 := λ 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 𝕜 F :=\n{ norm_smul_le := assume r x,\n  begin\n    rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ←mul_assoc],\n    rw [conj_mul_eq_norm_sq_left, of_real_mul_re, sqrt_mul, ←inner_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 𝕜 F]\n  (c : inner_product_space.core 𝕜 F) : inner_product_space 𝕜 F :=\nbegin\n  letI : normed_group F := @inner_product_space.of_core.to_normed_group 𝕜 F _ _ _ c,\n  letI : normed_space 𝕜 F := @inner_product_space.of_core.to_normed_space 𝕜 F _ _ _ c,\n  exact { norm_sq_eq_inner := λ x,\n    begin\n      have h₁ : ∥x∥^2 = (sqrt (re (c.inner x x))) ^ 2 := rfl,\n      have h₂ : 0 ≤ re (c.inner x x) := inner_product_space.of_core.inner_self_nonneg,\n      simp [h₁, sq_sqrt, h₂],\n    end,\n    ..c }\nend\n\n/-! ### Properties of inner product spaces -/\n\nvariables [inner_product_space 𝕜 E] [inner_product_space ℝ F]\nvariables [dec_E : decidable_eq E]\nlocal notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y\nlocal notation `IK` := @is_R_or_C.I 𝕜 _\nlocal notation `absR` := has_abs.abs\nlocal notation `absK` := @is_R_or_C.abs 𝕜 _\nlocal postfix `†`: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) : ⟪y, x⟫† = ⟪x, y⟫ := inner_product_space.conj_sym _ _\nlemma real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := @inner_conj_sym ℝ _ _ _ x y\n\nlemma inner_eq_zero_sym {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 :=\n⟨λ h, by simp [←inner_conj_sym, h], λ h, by simp [←inner_conj_sym, h]⟩\n\n@[simp] lemma inner_self_nonneg_im {x : E} : im ⟪x, x⟫ = 0 :=\nby rw [← @of_real_inj 𝕜, im_eq_conj_sub]; simp\n\nlemma inner_self_im_zero {x : E} : im ⟪x, x⟫ = 0 := inner_self_nonneg_im\n\nlemma inner_add_left {x y z : E} : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=\ninner_product_space.add_left _ _ _\n\nlemma inner_add_right {x y z : E} : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ :=\nby { rw [←inner_conj_sym, inner_add_left, ring_hom.map_add], simp only [inner_conj_sym] }\n\nlemma inner_re_symm {x y : E} : re ⟪x, y⟫ = re ⟪y, x⟫ :=\nby rw [←inner_conj_sym, conj_re]\n\nlemma inner_im_symm {x y : E} : im ⟪x, y⟫ = -im ⟪y, x⟫ :=\nby rw [←inner_conj_sym, conj_im]\n\nlemma inner_smul_left {x y : E} {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=\ninner_product_space.smul_left _ _ _\nlemma real_inner_smul_left {x y : F} {r : ℝ} : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_left\n\nlemma inner_smul_real_left {x y : E} {r : ℝ} : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ :=\nby { rw [inner_smul_left, conj_of_real, algebra.smul_def], refl }\n\nlemma inner_smul_right {x y : E} {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=\nby rw [←inner_conj_sym, inner_smul_left, ring_hom.map_mul, conj_conj, inner_conj_sym]\nlemma real_inner_smul_right {x y : F} {r : ℝ} : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_right\n\nlemma inner_smul_real_right {x y : E} {r : ℝ} : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ :=\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 →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=\nlinear_map.mk₂'ₛₗ (ring_hom.id 𝕜) (star_ring_end _)\n  (λ x y, ⟪y, x⟫)\n  (λ x y z, inner_add_right)\n  (λ r x y, inner_smul_right)\n  (λ x y z, inner_add_left)\n  (λ 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 ℝ F :=\n{ bilin := inner,\n  bilin_add_left := λ x y z, inner_add_left,\n  bilin_smul_left := λ a x y, inner_smul_left,\n  bilin_add_right := λ x y z, inner_add_right,\n  bilin_smul_right := λ a x y, inner_smul_right }\n\n/-- An inner product with a sum on the left. -/\nlemma sum_inner {ι : Type*} (s : finset ι) (f : ι → E) (x : E) :\n  ⟪∑ i in s, f i, x⟫ = ∑ i in s, ⟪f i, x⟫ := (sesq_form_of_inner x).map_sum\n\n/-- An inner product with a sum on the right. -/\nlemma inner_sum {ι : Type*} (s : finset ι) (f : ι → E) (x : E) :\n  ⟪x, ∑ i in s, f i⟫ = ∑ i in s, ⟪x, f i⟫ := (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 {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :\n  ⟪l.sum (λ (i : ι) (a : 𝕜), a • v i), x⟫\n  = l.sum (λ (i : ι) (a : 𝕜), (conj a) • ⟪v i, x⟫) :=\nby { convert sum_inner l.support (λ a, l a • 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 {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :\n  ⟪x, l.sum (λ (i : ι) (a : 𝕜), a • v i)⟫ = l.sum (λ (i : ι) (a : 𝕜), a • ⟪x, v i⟫) :=\nby { convert inner_sum l.support (λ a, l a • v a) x, simp [inner_smul_right, finsupp.sum] }\n\nlemma dfinsupp.sum_inner {ι : Type*} [dec : decidable_eq ι] {α : ι → Type*}\n  [Π i, add_zero_class (α i)] [Π i (x : α i), decidable (x ≠ 0)]\n  (f : Π i, α i → E) (l : Π₀ i, α i) (x : E) :\n  ⟪l.sum f, x⟫ = l.sum (λ i a, ⟪f i a, x⟫) :=\nby simp [dfinsupp.sum, sum_inner] {contextual := tt}\n\nlemma dfinsupp.inner_sum {ι : Type*} [dec : decidable_eq ι] {α : ι → Type*}\n  [Π i, add_zero_class (α i)] [Π i (x : α i), decidable (x ≠ 0)]\n  (f : Π i, α i → E) (l : Π₀ i, α i) (x : E) :\n  ⟪x, l.sum f⟫ = l.sum (λ i a, ⟪x, f i a⟫) :=\nby simp [dfinsupp.sum, inner_sum] {contextual := tt}\n\n@[simp] lemma inner_zero_left {x : E} : ⟪0, x⟫ = 0 :=\nby rw [← zero_smul 𝕜 (0:E), inner_smul_left, ring_hom.map_zero, zero_mul]\n\nlemma inner_re_zero_left {x : E} : re ⟪0, x⟫ = 0 :=\nby simp only [inner_zero_left, add_monoid_hom.map_zero]\n\n@[simp] lemma inner_zero_right {x : E} : ⟪x, 0⟫ = 0 :=\nby rw [←inner_conj_sym, inner_zero_left, ring_hom.map_zero]\n\nlemma inner_re_zero_right {x : E} : re ⟪x, 0⟫ = 0 :=\nby simp only [inner_zero_right, add_monoid_hom.map_zero]\n\nlemma inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=\nby rw [←norm_sq_eq_inner]; exact pow_nonneg (norm_nonneg x) 2\nlemma real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ x\n\n@[simp] lemma inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 :=\nbegin\n  split,\n  { intro h,\n    have h₁ : re ⟪x, x⟫ = 0 := by rw is_R_or_C.ext_iff at h; simp [h.1],\n    rw [←norm_sq_eq_inner x] at h₁,\n    rw [←norm_eq_zero],\n    exact pow_eq_zero h₁ },\n  { rintro rfl,\n    exact inner_zero_left }\nend\n\n@[simp] lemma inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 :=\nbegin\n  split,\n  { intro h,\n    rw ←inner_self_eq_zero,\n    have H₁ : re ⟪x, x⟫ ≥ 0, exact inner_self_nonneg,\n    have H₂ : re ⟪x, x⟫ = 0, exact le_antisymm h H₁,\n    rw is_R_or_C.ext_iff,\n    exact ⟨by simp [H₂], by simp [inner_self_nonneg_im]⟩ },\n  { rintro rfl,\n    simp only [inner_zero_left, add_monoid_hom.map_zero] }\nend\n\nlemma real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 :=\nby { have h := @inner_self_nonpos ℝ F _ _ x, simpa using h }\n\n@[simp] lemma inner_self_re_to_K {x : E} : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=\nby rw is_R_or_C.ext_iff; exact ⟨by simp, by simp [inner_self_nonneg_im]⟩\n\nlemma inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (∥x∥ ^ 2 : 𝕜) :=\nbegin\n  suffices : (is_R_or_C.re ⟪x, x⟫ : 𝕜) = ∥x∥ ^ 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 ⟪x, x⟫ = abs ⟪x, x⟫ :=\nbegin\n  conv_rhs { rw [←inner_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 ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=\nby { rw [←inner_self_re_abs], exact inner_self_re_to_K }\n\nlemma real_inner_self_abs {x : F} : absR ⟪x, x⟫_ℝ = ⟪x, x⟫_ℝ :=\nby { have h := @inner_self_abs_to_K ℝ F _ _ x, simpa using h }\n\nlemma inner_abs_conj_sym {x y : E} : abs ⟪x, y⟫ = abs ⟪y, x⟫ :=\nby rw [←inner_conj_sym, abs_conj]\n\n@[simp] lemma inner_neg_left {x y : E} : ⟪-x, y⟫ = -⟪x, y⟫ :=\nby { rw [← neg_one_smul 𝕜 x, inner_smul_left], simp }\n\n@[simp] lemma inner_neg_right {x y : E} : ⟪x, -y⟫ = -⟪x, y⟫ :=\nby rw [←inner_conj_sym, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_sym]\n\nlemma inner_neg_neg {x y : E} : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp\n\n@[simp] lemma inner_self_conj {x : E} : ⟪x, x⟫† = ⟪x, x⟫ :=\nby rw [is_R_or_C.ext_iff]; exact ⟨by rw [conj_re], by rw [conj_im, inner_self_im_zero, neg_zero]⟩\n\nlemma inner_sub_left {x y z : E} : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ :=\nby { simp [sub_eq_add_neg, inner_add_left] }\n\nlemma inner_sub_right {x y z : E} : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ :=\nby { simp [sub_eq_add_neg, inner_add_right] }\n\nlemma inner_mul_conj_re_abs {x y : E} : re (⟪x, y⟫ * ⟪y, x⟫) = abs (⟪x, y⟫ * ⟪y, x⟫) :=\nby { rw [←inner_conj_sym, mul_comm], exact re_eq_abs_of_mul_conj (inner y x), }\n\n/-- Expand `⟪x + y, x + y⟫` -/\nlemma inner_add_add_self {x y : E} : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ :=\nby simp only [inner_add_left, inner_add_right]; ring\n\n/-- Expand `⟪x + y, x + y⟫_ℝ` -/\nlemma real_inner_add_add_self {x y : F} : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ :=\nbegin\n  have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [←inner_conj_sym]; refl,\n  simp [inner_add_add_self, this],\n  ring,\nend\n\n/- Expand `⟪x - y, x - y⟫` -/\nlemma inner_sub_sub_self {x y : E} : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ :=\nby simp only [inner_sub_left, inner_sub_right]; ring\n\n/-- Expand `⟪x - y, x - y⟫_ℝ` -/\nlemma real_inner_sub_sub_self {x y : F} : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ :=\nbegin\n  have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [←inner_conj_sym]; refl,\n  simp [inner_sub_sub_self, this],\n  ring,\nend\n\n/-- Parallelogram law -/\nlemma parallelogram_law {x y : E} :\n  ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) :=\nby simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]\n\n/-- Cauchy–Schwarz inequality. This proof follows \"Proof 2\" on Wikipedia. -/\nlemma inner_mul_inner_self_le (x y : E) : abs ⟪x, y⟫ * abs ⟪y, x⟫ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=\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 ≠ 0 at hy,\n    have hy' : ⟪y, y⟫ ≠ 0 := λ h, by rw [inner_self_eq_zero] at h; exact hy h,\n    set T := ⟪y, x⟫ / ⟪y, y⟫ with hT,\n    have h₁ : re ⟪y, x⟫ = re ⟪x, y⟫ := inner_re_symm,\n    have h₂ : im ⟪y, x⟫ = -im ⟪x, y⟫ := inner_im_symm,\n    have h₃ : ⟪y, x⟫ * ⟪x, y⟫ * ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = ⟪y, x⟫ * ⟪x, y⟫ / ⟪y, y⟫,\n    { rw [mul_div_assoc],\n      have : ⟪y, y⟫ / (⟪y, y⟫ * ⟪y, y⟫) = 1 / ⟪y, y⟫ :=\n        by rw [div_mul_eq_div_mul_one_div, div_self hy', one_mul],\n      rw [this, div_eq_mul_inv, one_mul, ←div_eq_mul_inv] },\n    have h₄ : ⟪y, y⟫ = re ⟪y, y⟫ := by simp,\n    have h₅ : re ⟪y, y⟫ > 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 ⟨by simp only [H, zero_re'],\n             by simp only [inner_self_nonneg_im, add_monoid_hom.map_zero]⟩ },\n    have h₆ : re ⟪y, y⟫ ≠ 0 := ne_of_gt h₅,\n    have hmain := calc\n      0   ≤ re ⟪x - T • y, x - T • y⟫\n                  : inner_self_nonneg\n      ... = re ⟪x, x⟫ - re ⟪T • y, x⟫ - re ⟪x, T • y⟫ + re ⟪T • y, T • y⟫\n                  : by simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, h₁, h₂,\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 ⟪x, x⟫ - re (T† * ⟪y, x⟫) - re (T * ⟪x, y⟫) + re (T * T† * ⟪y, y⟫)\n                  : by simp only [inner_smul_left, inner_smul_right, mul_assoc]\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ / ⟪y, y⟫ * ⟪y, x⟫)\n                  : by field_simp [-mul_re, hT, ring_hom.map_div, h₁, h₃, inner_conj_sym]\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / ⟪y, y⟫)\n                  : by rw ←mul_div_right_comm\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫ / re ⟪y, y⟫)\n                  : by conv_lhs { rw [h₄] }\n      ... = re ⟪x, x⟫ - re (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫\n                  : by rw [div_re_of_real]\n      ... = re ⟪x, x⟫ - abs (⟪x, y⟫ * ⟪y, x⟫) / re ⟪y, y⟫\n                  : by rw [inner_mul_conj_re_abs]\n      ... = re ⟪x, x⟫ - abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫\n                  : by rw is_R_or_C.abs_mul,\n    have hmain' : abs ⟪x, y⟫ * abs ⟪y, x⟫ / re ⟪y, y⟫ ≤ re ⟪x, x⟫ := by linarith,\n    have := (mul_le_mul_right h₅).mpr hmain',\n    rwa [div_mul_cancel (abs ⟪x, y⟫ * abs ⟪y, x⟫) h₆] at this }\nend\n\n/-- Cauchy–Schwarz inequality for real inner products. -/\nlemma real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=\nbegin\n  have h₁ : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [←inner_conj_sym]; refl,\n  have h₂ := @inner_mul_inner_self_le ℝ F _ _ x y,\n  dsimp at h₂,\n  have h₃ := abs_mul_abs_self ⟪x, y⟫_ℝ,\n  rw [h₁] at h₂,\n  simpa [h₃] using h₂,\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 {ι : Type*} {v : ι → E}\n  (hz : ∀ i, v i ≠ 0) (ho : ∀ i j, i ≠ j → ⟪v i, v j⟫ = 0) : linear_independent 𝕜 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) (∑ j in s, g j • 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 λ h, false.elim (h hi) } },\n  simpa [hg, hz] using h'\nend\n\nend basic_properties\n\nsection orthonormal_sets\nvariables {ι : Type*} [dec_ι : decidable_eq ι] (𝕜)\n\ninclude 𝕜\n\n/-- An orthonormal set of vectors in an `inner_product_space` -/\ndef orthonormal (v : ι → E) : Prop :=\n(∀ i, ∥v i∥ = 1) ∧ (∀ {i j}, i ≠ j → ⟪v i, v j⟫ = 0)\n\nomit 𝕜\n\nvariables {𝕜}\n\ninclude dec_ι\n/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal.  (Inner\nproduct equals Kronecker delta.) -/\nlemma orthonormal_iff_ite {v : ι → E} :\n  orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1:𝕜) else (0:𝕜) :=\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' : ∥v i∥ ^ 2 = 1 ^ 2 := by simp [norm_sq_eq_inner, h i i],\n      have h₁ : 0 ≤ ∥v i∥ := norm_nonneg _,\n      have h₂ : (0:ℝ) ≤ 1 := zero_le_one,\n      rwa sq_eq_sq h₁ h₂ at h' },\n    { intros i j hij,\n      simpa [hij] using h i j } }\nend\nomit dec_ι\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 𝕜 (coe : s → E) ↔\n  (∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = 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 ⟨v, hv⟩ ⟨w, hw⟩ using 1,\n    simp },\n  { rintros h ⟨v, hv⟩ ⟨w, hw⟩,\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 : ι → E} (hv : orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) :\n  ⟪v i, finsupp.total ι E 𝕜 v l⟫ = 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 : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) {s : finset ι} {i : ι} (hi : i ∈ s) :\n  ⟪v i, ∑ i in s, (l i) • (v i)⟫ = 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 ι]\n  {v : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) :\n  ⟪v i, ∑ i : ι, (l i) • (v i)⟫ = 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 : ι → E} (hv : orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) :\n  ⟪finsupp.total ι E 𝕜 v l, v i⟫ = conj (l i) :=\nby rw [← 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 : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) {s : finset ι} {i : ι} (hi : i ∈ s) :\n  ⟪∑ i in s, (l i) • (v i), v i⟫ = 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 ι]\n  {v : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) :\n  ⟪∑ i : ι, (l i) • (v i), v i⟫ = 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 : ι → E} (hv : orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) :\n  ⟪finsupp.total ι E 𝕜 v l₁, finsupp.total ι E 𝕜 v l₂⟫ = l₁.sum (λ i y, conj y * l₂ i) :=\nby simp [finsupp.total_apply _ l₁, 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 : ι → E} (hv : orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) :\n  ⟪finsupp.total ι E 𝕜 v l₁, finsupp.total ι E 𝕜 v l₂⟫ = l₂.sum (λ i y, conj (l₁ i) * y) :=\nby simp [finsupp.total_apply _ l₂, 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 : ι → E} (hv : orthonormal 𝕜 v) (l₁ l₂ : ι → 𝕜) (s : finset ι) :\n  ⟪∑ i in s, l₁ i • v i, ∑ i in s, l₂ i • v i⟫ = ∑ i in s, conj (l₁ i) * l₂ i :=\nbegin\n  simp_rw [sum_inner, inner_smul_left],\n  refine finset.sum_congr rfl (λ i hi, _),\n  rw hv.inner_right_sum l₂ 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 ι}  {v : ι → E} (hv : orthonormal 𝕜 v)\n  {a : ι → ι → 𝕜} : ∑ i in s, ∑ j in s, (a i j) • ⟪v j, v i⟫ = ∑ 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 : ι → E} (hv : orthonormal 𝕜 v) :\n  linear_independent 𝕜 v :=\nbegin\n  rw linear_independent_iff,\n  intros l hl,\n  ext i,\n  have key : ⟪v i, finsupp.total ι E 𝕜 v l⟫ = ⟪v i, 0⟫ := 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  {ι' : Type*} {v : ι → E} (hv : orthonormal 𝕜 v) (f : ι' → ι) (hf : function.injective f) :\n  orthonormal 𝕜 (v ∘ f) :=\nbegin\n  classical,\n  rw orthonormal_iff_ite at ⊢ 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 : ι → E} (hv : orthonormal 𝕜 v) {s : set ι} {i : ι} (hi : i ∉ s) {l : ι →₀ 𝕜}\n  (hl : l ∈ finsupp.supported 𝕜 𝕜 s) :\n  ⟪finsupp.total ι E 𝕜 v l, v i⟫ = 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 : ι → E} (hv : orthonormal 𝕜 v)\n  (hw : ∀ i, w i = v i ∨ w i = -(v i)) : orthonormal 𝕜 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 (𝕜 E)\nlemma orthonormal_empty : orthonormal 𝕜 (λ x, x : (∅ : set E) → E) :=\nby classical; simp [orthonormal_subtype_iff_ite]\nvariables {𝕜 E}\n\nlemma orthonormal_Union_of_directed\n  {η : Type*} {s : η → set E} (hs : directed (⊆) s) (h : ∀ i, orthonormal 𝕜 (λ x, x : s i → E)) :\n  orthonormal 𝕜 (λ x, x : (⋃ i, s i) → E) :=\nbegin\n  classical,\n  rw orthonormal_subtype_iff_ite,\n  rintros x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩,\n  obtain ⟨k, hik, hjk⟩ := hs i j,\n  have h_orth : orthonormal 𝕜 (λ x, x : (s k) → 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 (⊆) s)\n  (h : ∀ a ∈ s, orthonormal 𝕜 (λ x, x : (a : set E) → E)) :\n  orthonormal 𝕜 (λ x, x : (⋃₀ s) → 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 𝕜 (coe : s → E)) :\n  ∃ w ⊇ s, orthonormal 𝕜 (coe : w → E) ∧ ∀ u ⊇ w, orthonormal 𝕜 (coe : u → E) → u = w :=\nbegin\n  obtain ⟨b, bi, sb, h⟩ := zorn_subset_nonempty {b | orthonormal 𝕜 (coe : b → E)} _ _ hs,\n  { refine ⟨b, sb, bi, _⟩,\n    exact λ u hus hu, h u hu hus },\n  { refine λ c hc cc c0, ⟨⋃₀ c, _, _⟩,\n    { exact orthonormal_sUnion_of_directed cc.directed_on (λ x xc, hc xc) },\n    { exact λ _, set.subset_sUnion_of_mem } }\nend\n\nlemma orthonormal.ne_zero {v : ι → E} (hv : orthonormal 𝕜 v) (i : ι) : v i ≠ 0 :=\nbegin\n  have : ∥v i∥ ≠ 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 ι] [nonempty ι] {v : ι → E}\n  (hv : orthonormal 𝕜 v) (card_eq : fintype.card ι = finrank 𝕜 E) :\n  basis ι 𝕜 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 ι] [nonempty ι] {v : ι → E}\n  (hv : orthonormal 𝕜 v) (card_eq : fintype.card ι = finrank 𝕜 E) :\n  (basis_of_orthonormal_of_card_eq_finrank hv card_eq : ι → 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) : ∥x∥ = sqrt (re ⟪x, x⟫) :=\nbegin\n  have h₁ : ∥x∥^2 = re ⟪x, x⟫ := norm_sq_eq_inner x,\n  have h₂ := congr_arg sqrt h₁,\n  simpa using h₂,\nend\n\nlemma norm_eq_sqrt_real_inner (x : F) : ∥x∥ = sqrt ⟪x, x⟫_ℝ :=\nby { have h := @norm_eq_sqrt_inner ℝ F _ _ x, simpa using h }\n\nlemma inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ∥x∥ * ∥x∥ :=\nby rw [norm_eq_sqrt_inner, ←sqrt_mul inner_self_nonneg (re ⟪x, x⟫),\n  sqrt_mul_self inner_self_nonneg]\n\nlemma inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ∥x∥^2 :=\nby rw [pow_two, inner_self_eq_norm_mul_norm]\n\nlemma real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ∥x∥ * ∥x∥ :=\nby { have h := @inner_self_eq_norm_mul_norm ℝ F _ _ x, simpa using h }\n\nlemma real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ∥x∥^2 :=\nby rw [pow_two, real_inner_self_eq_norm_mul_norm]\n\n/-- Expand the square -/\nlemma norm_add_sq {x y : E} : ∥x + y∥^2 = ∥x∥^2 + 2 * (re ⟪x, y⟫) + ∥y∥^2 :=\nbegin\n  repeat {rw [sq, ←inner_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 [←inner_conj_sym, conj_re],\nend\n\nalias norm_add_sq ← norm_add_pow_two\n\n/-- Expand the square -/\nlemma norm_add_sq_real {x y : F} : ∥x + y∥^2 = ∥x∥^2 + 2 * ⟪x, y⟫_ℝ + ∥y∥^2 :=\nby { have h := @norm_add_sq ℝ F _ _, simpa using h }\n\nalias norm_add_sq_real ← norm_add_pow_two_real\n\n/-- Expand the square -/\nlemma norm_add_mul_self {x y : E} : ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + 2 * (re ⟪x, y⟫) + ∥y∥ * ∥y∥ :=\nby { repeat {rw [← sq]}, exact norm_add_sq }\n\n/-- Expand the square -/\nlemma norm_add_mul_self_real {x y : F} : ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + 2 * ⟪x, y⟫_ℝ + ∥y∥ * ∥y∥ :=\nby { have h := @norm_add_mul_self ℝ F _ _, simpa using h }\n\n/-- Expand the square -/\nlemma norm_sub_sq {x y : E} : ∥x - y∥^2 = ∥x∥^2 - 2 * (re ⟪x, y⟫) + ∥y∥^2 :=\nbegin\n  repeat {rw [sq, ←inner_self_eq_norm_mul_norm]},\n  rw [inner_sub_sub_self],\n  calc\n    re (⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫)\n        = re ⟪x, x⟫ - re ⟪x, y⟫ - re ⟪y, x⟫ + re ⟪y, y⟫  : by simp\n    ... = -re ⟪y, x⟫ - re ⟪x, y⟫ + re ⟪x, x⟫ + re ⟪y, y⟫  : by ring\n    ... = -re (⟪x, y⟫†) - re ⟪x, y⟫ + re ⟪x, x⟫ + re ⟪y, y⟫ : by rw [inner_conj_sym]\n    ... = -re ⟪x, y⟫ - re ⟪x, y⟫ + re ⟪x, x⟫ + re ⟪y, y⟫ : by rw [conj_re]\n    ... = re ⟪x, x⟫ - 2*re ⟪x, y⟫ + re ⟪y, y⟫ : by ring\nend\n\nalias norm_sub_sq ← norm_sub_pow_two\n\n/-- Expand the square -/\nlemma norm_sub_sq_real {x y : F} : ∥x - y∥^2 = ∥x∥^2 - 2 * ⟪x, y⟫_ℝ + ∥y∥^2 :=\nnorm_sub_sq\n\nalias norm_sub_sq_real ← norm_sub_pow_two_real\n\n/-- Expand the square -/\nlemma norm_sub_mul_self {x y : E} : ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ - 2 * re ⟪x, y⟫ + ∥y∥ * ∥y∥ :=\nby { repeat {rw [← sq]}, exact norm_sub_sq }\n\n/-- Expand the square -/\nlemma norm_sub_mul_self_real {x y : F} : ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ - 2 * ⟪x, y⟫_ℝ + ∥y∥ * ∥y∥ :=\nby { have h := @norm_sub_mul_self ℝ F _ _, simpa using h }\n\n/-- Cauchy–Schwarz inequality with norm -/\nlemma abs_inner_le_norm (x y : E) : abs ⟪x, y⟫ ≤ ∥x∥ * ∥y∥ :=\nnonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _))\nbegin\n  have : ∥x∥ * ∥y∥ * (∥x∥ * ∥y∥) = (re ⟪x, x⟫) * (re ⟪y, y⟫),\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) : ∥⟪x, y⟫∥ ≤ ∥x∥ * ∥y∥ :=\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) : ∥⟪x, y⟫∥₊ ≤ ∥x∥₊ * ∥y∥₊ :=\nnorm_inner_le_norm x y\n\nlemma re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ∥x∥ * ∥y∥ :=\nle_trans (re_le_abs (inner x y)) (abs_inner_le_norm x y)\n\n/-- Cauchy–Schwarz inequality with norm -/\nlemma abs_real_inner_le_norm (x y : F) : absR ⟪x, y⟫_ℝ ≤ ∥x∥ * ∥y∥ :=\nby { have h := @abs_inner_le_norm ℝ F _ _ x y, simpa using h }\n\n/-- Cauchy–Schwarz inequality with norm -/\nlemma real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ∥x∥ * ∥y∥ :=\nle_trans (le_abs_self _) (abs_real_inner_le_norm _ _)\n\ninclude 𝕜\nlemma parallelogram_law_with_norm (x y : E) :\n  ∥x + y∥ * ∥x + y∥ + ∥x - y∥ * ∥x - y∥ = 2 * (∥x∥ * ∥x∥ + ∥y∥ * ∥y∥) :=\nbegin\n  simp only [← inner_self_eq_norm_mul_norm],\n  rw [← 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  ∥x + y∥₊ * ∥x + y∥₊ + ∥x - y∥₊ * ∥x - y∥₊ = 2 * (∥x∥₊ * ∥x∥₊ + ∥y∥₊ * ∥y∥₊) :=\nsubtype.ext $ parallelogram_law_with_norm x y\n\nomit 𝕜\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 ⟪x, y⟫ = (∥x + y∥ * ∥x + y∥ - ∥x∥ * ∥x∥ - ∥y∥ * ∥y∥) / 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 ⟪x, y⟫ = (∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ - ∥x - y∥ * ∥x - y∥) / 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 ⟪x, y⟫ = (∥x + y∥ * ∥x + y∥ - ∥x - y∥ * ∥x - y∥) / 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 ⟪x, y⟫ = (∥x - IK • y∥ * ∥x - IK • y∥ - ∥x + IK • y∥ * ∥x + IK • y∥) / 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  ⟪x, y⟫ = (∥x + y∥ ^ 2 - ∥x - y∥ ^ 2 + (∥x - IK • y∥ ^ 2 - ∥x + IK • y∥ ^ 2) * IK) / 4 :=\nbegin\n  rw [← re_add_im ⟪x, y⟫, 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, ← mul_div_right_comm, ← 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 ≠ 0) (hy : y ≠ 0) (R : ℝ) :\n  dist ((R / ∥x∥) ^ 2 • x) ((R / ∥y∥) ^ 2 • y) = (R ^ 2 / (∥x∥ * ∥y∥)) * dist x y :=\nhave hx' : ∥x∥ ≠ 0, from norm_ne_zero_iff.2 hx,\nhave hy' : ∥y∥ ≠ 0, from norm_ne_zero_iff.2 hy,\ncalc dist ((R / ∥x∥) ^ 2 • x) ((R / ∥y∥) ^ 2 • y)\n    = sqrt (∥(R / ∥x∥) ^ 2 • x - (R / ∥y∥) ^ 2 • y∥^2) :\n  by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]\n... = sqrt ((R ^ 2 / (∥x∥ * ∥y∥)) ^ 2 * ∥x - y∥ ^ 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 / (∥x∥ * ∥y∥)) * 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⟨λ ε hε, begin\n  refine ⟨2 - sqrt (4 - ε^2), sub_pos_of_lt $ (sqrt_lt' zero_lt_two).2 _, λ x hx y hy hxy, _⟩,\n  { norm_num,\n    exact pow_pos hε _ },\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 x y), ←sq (∥x - y∥), hx, hy],\n  norm_num,\n  exact pow_le_pow_of_le_left hε.le hxy _,\nend⟩\n\nsection complex\n\nvariables {V : Type*}\n[inner_product_space ℂ V]\n\n/--\nA complex polarization identity, with a linear map\n-/\nlemma inner_map_polarization (T : V →ₗ[ℂ] V) (x y : V):\n  ⟪ T y, x ⟫_ℂ = (⟪T (x + y) , x + y⟫_ℂ - ⟪T (x - y) , x - y⟫_ℂ +\n    complex.I * ⟪T (x + complex.I • y) , x + complex.I • y⟫_ℂ -\n    complex.I * ⟪T (x - complex.I • y), x - complex.I • y ⟫_ℂ) / 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, ←pow_two, complex.I_sq,\n             inner_sub_left, inner_sub_right, mul_add, ←mul_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 →ₗ[ℂ] V) (x y : V):\n  ⟪ T x, y ⟫_ℂ = (⟪T (x + y) , x + y⟫_ℂ - ⟪T (x - y) , x - y⟫_ℂ -\n    complex.I * ⟪T (x + complex.I • y) , x + complex.I • y⟫_ℂ +\n    complex.I * ⟪T (x - complex.I • y), x - complex.I • y ⟫_ℂ) / 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, ←pow_two, complex.I_sq,\n             inner_sub_left, inner_sub_right, mul_add, ←mul_assoc, mul_neg, neg_neg,\n             sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub],\n  ring,\nend\n\n/--\nIf `⟪T x, x⟫_ℂ = 0` for all x, then T = 0.\n-/\nlemma inner_map_self_eq_zero (T : V →ₗ[ℂ] V) :\n  (∀ (x : V), ⟪T x, x⟫_ℂ = 0) ↔ T = 0 :=\nbegin\n  split,\n  { intro hT,\n    ext x,\n    simp only [linear_map.zero_apply, ← inner_self_eq_zero, inner_map_polarization, hT],\n    norm_num },\n  { rintro rfl x,\n    simp only [linear_map.zero_apply, inner_zero_left] }\nend\n\nend complex\n\nsection\n\nvariables {ι : Type*} {ι' : Type*} {ι'' : Type*}\nvariables {E' : Type*} [inner_product_space 𝕜 E']\nvariables {E'' : Type*} [inner_product_space 𝕜 E'']\n\n/-- A linear isometry preserves the inner product. -/\n@[simp] lemma linear_isometry.inner_map_map (f : E →ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ :=\nby simp [inner_eq_sum_norm_sq_div_four, ← f.norm_map]\n\n/-- A linear isometric equivalence preserves the inner product. -/\n@[simp] lemma linear_isometry_equiv.inner_map_map (f : E ≃ₗᵢ[𝕜] E') (x y : E) :\n  ⟪f x, f y⟫ = ⟪x, y⟫ :=\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 →ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E →ₗᵢ[𝕜] E' :=\n⟨f, λ x, by simp only [norm_eq_sqrt_inner, h]⟩\n\n@[simp] lemma linear_map.coe_isometry_of_inner (f : E →ₗ[𝕜] E') (h) :\n  ⇑(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_map.isometry_of_inner_to_linear_map (f : E →ₗ[𝕜] 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 ≃ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) :\n  E ≃ₗᵢ[𝕜] E' :=\n⟨f, ((f : E →ₗ[𝕜] E').isometry_of_inner h).norm_map⟩\n\n@[simp] lemma linear_equiv.coe_isometry_of_inner (f : E ≃ₗ[𝕜] E') (h) :\n  ⇑(f.isometry_of_inner h) = f := rfl\n\n@[simp] lemma linear_equiv.isometry_of_inner_to_linear_equiv (f : E ≃ₗ[𝕜] 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 : ι → E} (hv : orthonormal 𝕜 v) (f : E →ₗᵢ[𝕜] E') :\n  orthonormal 𝕜 (f ∘ v) :=\nbegin\n  classical,\n  simp_rw [orthonormal_iff_ite, linear_isometry.inner_map_map, ←orthonormal_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 : ι → E} (hv : orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') :\n  orthonormal 𝕜 (f ∘ 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 ι 𝕜 E} (hv : orthonormal 𝕜 v)\n  (f : E ≃ₗᵢ[𝕜] E') : orthonormal 𝕜 (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 →ₗ[𝕜] E') {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)\n  (hf : orthonormal 𝕜 (f ∘ v)) : E →ₗᵢ[𝕜] E' :=\nf.isometry_of_inner $ λ x y, by rw [←v.total_repr x, ←v.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 →ₗ[𝕜] E') {v : basis ι 𝕜 E}\n  (hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ v)) :\n  ⇑(f.isometry_of_orthonormal hv hf) = f :=\nrfl\n\n@[simp] lemma linear_map.isometry_of_orthonormal_to_linear_map (f : E →ₗ[𝕜] E') {v : basis ι 𝕜 E}\n  (hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ 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 ≃ₗ[𝕜] E') {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)\n  (hf : orthonormal 𝕜 (f ∘ v)) : E ≃ₗᵢ[𝕜] E' :=\nf.isometry_of_inner $ λ x y, begin\n  rw ←linear_equiv.coe_coe at hf,\n  rw [←v.total_repr x, ←v.total_repr y, ←linear_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 ≃ₗ[𝕜] E') {v : basis ι 𝕜 E}\n  (hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ v)) :\n  ⇑(f.isometry_of_orthonormal hv hf) = f :=\nrfl\n\n@[simp] lemma linear_equiv.isometry_of_orthonormal_to_linear_equiv (f : E ≃ₗ[𝕜] E')\n  {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ 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 ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}\n  (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') : E ≃ₗᵢ[𝕜] E' :=\n(v.equiv v' e).isometry_of_orthonormal hv begin\n  have h : (v.equiv v' e) ∘ v = v' ∘ 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 ι 𝕜 E} (hv : orthonormal 𝕜 v)\n  {v' : basis ι' 𝕜 E'} (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') :\n  (hv.equiv hv' e).to_linear_equiv = v.equiv v' e :=\nrfl\n\n@[simp] lemma orthonormal.equiv_apply {ι' : Type*} {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)\n  {v' : basis ι' 𝕜 E'} (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') (i : ι) :\n  hv.equiv hv' e (v i) = v' (e i) :=\nbasis.equiv_apply _ _ _ _\n\n@[simp] lemma orthonormal.equiv_refl {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) :\n  hv.equiv hv (equiv.refl ι) = linear_isometry_equiv.refl 𝕜 E :=\nv.ext_linear_isometry_equiv $ λ i, by simp\n\n@[simp] lemma orthonormal.equiv_symm {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}\n  (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.equiv hv' e).symm = hv'.equiv hv e.symm :=\nv'.ext_linear_isometry_equiv $ λ i, (hv.equiv hv' e).injective (by simp)\n\n@[simp] lemma orthonormal.equiv_trans {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}\n  (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') {v'' : basis ι'' 𝕜 E''} (hv'' : orthonormal 𝕜 v'')\n  (e' : ι' ≃ ι'') : (hv.equiv hv' e).trans (hv'.equiv hv'' e') = hv.equiv hv'' (e.trans e') :=\nv.ext_linear_isometry_equiv $ λ i, by simp\n\nlemma orthonormal.map_equiv {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}\n  (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') :\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  ⟪x, y⟫_ℝ = (∥x + y∥ * ∥x + y∥ - ∥x∥ * ∥x∥ - ∥y∥ * ∥y∥) / 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  ⟪x, y⟫_ℝ = (∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ - ∥x - y∥ * ∥x - y∥) / 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  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ ⟪x, y⟫_ℝ = 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 : ⟪x, y⟫ = 0) :\n  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\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 : ⟪x, y⟫_ℝ = 0) :\n  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\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  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ ⟪x, y⟫_ℝ = 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 : ⟪x, y⟫_ℝ = 0) :\n  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\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) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ∥x∥ = ∥y∥ :=\nbegin\n  conv_rhs { rw ←mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _) },\n  simp only [←inner_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 : ⟪v, w⟫ = 0) : ∥w - v∥ = ∥w + v∥ :=\nbegin\n  rw ←mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _),\n  simp [h, ←inner_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 (⟪x, y⟫_ℝ / (∥x∥ * ∥y∥)) ≤ 1 :=\nbegin\n  rw _root_.abs_div,\n  by_cases h : 0 = absR (∥x∥ * ∥y∥),\n  { rw [←h, div_zero],\n    norm_num },\n  { change 0 ≠ absR (∥x∥ * ∥y∥) at h,\n    rw div_le_iff' (lt_of_le_of_ne (ge_iff_le.mp (_root_.abs_nonneg (∥x∥ * ∥y∥))) 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 : ℝ) : ⟪r • x, x⟫_ℝ = r * (∥x∥ * ∥x∥) :=\nby rw [real_inner_smul_left, ←real_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 : ℝ) : ⟪x, r • x⟫_ℝ = r * (∥x∥ * ∥x∥) :=\nby rw [inner_smul_right, ←real_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 : 𝕜} (hx : x ≠ 0) (hr : r ≠ 0) : abs ⟪x, r • x⟫ / (∥x∥ * ∥r • x∥) = 1 :=\nbegin\n  have hx' : ∥x∥ ≠ 0 := by simp [norm_eq_zero, hx],\n  have hr' : abs r ≠ 0 := by simp [is_R_or_C.abs_eq_zero, hr],\n  rw [inner_smul_right, is_R_or_C.abs_mul, ←inner_self_re_abs, inner_self_eq_norm_mul_norm,\n      norm_smul],\n  rw [is_R_or_C.norm_eq_abs, ←mul_assoc, ←div_div, mul_div_cancel _ hx',\n     ←div_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 : ℝ} (hx : x ≠ 0) (hr : r ≠ 0) : absR ⟪x, r • x⟫_ℝ / (∥x∥ * ∥r • x∥) = 1 :=\nbegin\n  rw ← 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 : ℝ} (hx : x ≠ 0) (hr : 0 < r) : ⟪x, r • x⟫_ℝ / (∥x∥ * ∥r • x∥) = 1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ∥x∥, 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    (λ 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 : ℝ} (hx : x ≠ 0) (hr : r < 0) : ⟪x, r • x⟫_ℝ / (∥x∥ * ∥r • x∥) = -1 :=\nbegin\n  rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ∥x∥, 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    (λ 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 (⟪x, y⟫ / (∥x∥ * ∥y∥)) = 1 ↔ (x ≠ 0 ∧ ∃ (r : 𝕜), r ≠ 0 ∧ y = r • x) :=\nbegin\n  split,\n  { intro h,\n    have hx0 : x ≠ 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 := ⟪x, y⟫ / (∥x∥ * ∥x∥) with hr,\n    use r,\n    set t := y - r • x with ht,\n    have ht0 : ⟪x, t⟫ = 0,\n    { rw [ht, inner_sub_right, inner_smul_right, hr],\n      norm_cast,\n      rw [←inner_self_eq_norm_mul_norm, inner_self_re_to_K,\n          div_mul_cancel _ (λ h, hx0 (inner_self_eq_zero.1 h)), sub_self] },\n    replace h : ∥r • x∥ / ∥t + r • x∥ = 1,\n    { rw [←sub_add_cancel y (r • x), ←ht, inner_add_right, ht0, zero_add, inner_smul_right,\n        is_R_or_C.abs_div, is_R_or_C.abs_mul, ←inner_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, ←mul_assoc, mul_comm,\n        mul_div_mul_left _ _ (λ h, hx0 (norm_eq_zero.1 h)), ←is_R_or_C.norm_eq_abs,\n        ←norm_smul] at h },\n    have hr0 : r ≠ 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 : ∥r • x∥ ^ 2 = ∥t + r • x∥ ^ 2,\n    { rw [eq_of_div_eq_one h] },\n    replace h2 : ⟪r • x, r • x⟫ = ⟪t, t⟫ + ⟪t, r • x⟫ + ⟪r • x, t⟫ + ⟪r • x, r • x⟫,\n    { rw [sq, sq, ←inner_self_eq_norm_mul_norm, ←inner_self_eq_norm_mul_norm ] at h2,\n      have h2' := congr_arg (λ z : ℝ, (z : 𝕜)) h2,\n      simp_rw [inner_self_re_to_K, inner_add_add_self] at h2',\n      exact h2' },\n    conv at h2 in ⟪r • x, t⟫ { rw [inner_smul_left, ht0, mul_zero] },\n    symmetry' at h2,\n    have h₁ : ⟪t, r • x⟫ = 0 := by { rw [inner_smul_right, ←inner_conj_sym, ht0], simp },\n    rw [add_zero, h₁, 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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,\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 (⟪x, y⟫_ℝ / (∥x∥ * ∥y∥)) = 1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r ≠ 0 ∧ y = r • x) :=\nbegin\n  have := @abs_inner_div_norm_mul_norm_eq_one_iff ℝ 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 `⟪x, y⟫ = ∥x∥ * ∥y∥`. -/\nlemma abs_inner_eq_norm_iff (x y : E) (hx0 : x ≠ 0) (hy0 : y ≠ 0):\n  abs ⟪x, y⟫ = ∥x∥ * ∥y∥ ↔ ∃ (r : 𝕜), r ≠ 0 ∧ y = r • x :=\nbegin\n  have hx0' : ∥x∥ ≠ 0 := by simp [norm_eq_zero, hx0],\n  have hy0' : ∥y∥ ≠ 0 := by simp [norm_eq_zero, hy0],\n  have hxy0 : ∥x∥ * ∥y∥ ≠ 0 := by simp [hx0', hy0'],\n  have h₁ : abs ⟪x, y⟫ = ∥x∥ * ∥y∥ ↔ abs (⟪x, y⟫ / (∥x∥ * ∥y∥)) = 1,\n  { refine ⟨_ ,_⟩,\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₁, abs_inner_div_norm_mul_norm_eq_one_iff x y],\n  simp [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  ⟪x, y⟫_ℝ / (∥x∥ * ∥y∥) = 1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), 0 < r ∧ y = r • 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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,\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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,\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  ⟪x, y⟫_ℝ / (∥x∥ * ∥y∥) = -1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r < 0 ∧ y = r • 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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,\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 ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,\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`⟪x, y⟫ = ∥x∥ * ∥y∥`), 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 ⟪x, y⟫ = ∥x∥ * ∥y∥`. -/\nlemma inner_eq_norm_mul_iff {x y : E} :\n  ⟪x, y⟫ = (∥x∥ : 𝕜) * ∥y∥ ↔ (∥y∥ : 𝕜) • x = (∥x∥ : 𝕜) • y :=\nbegin\n  by_cases h : (x = 0 ∨ y = 0), -- WLOG `x` and `y` are nonzero\n  { cases h; simp [h] },\n  calc ⟪x, y⟫ = (∥x∥ : 𝕜) * ∥y∥ ↔ ∥x∥ * ∥y∥ = re ⟪x, y⟫ :\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 ⊢ cauchy_schwarz,\n      rwa re_eq_self_of_le }\n  end\n  ... ↔ 2 * ∥x∥ * ∥y∥ * (∥x∥ * ∥y∥ - re ⟪x, y⟫) = 0 :\n    by simp [h, show (2:ℝ) ≠ 0, by norm_num, sub_eq_zero]\n  ... ↔ ∥(∥y∥:𝕜) • x - (∥x∥:𝕜) • y∥ * ∥(∥y∥:𝕜) • x - (∥x∥:𝕜) • y∥ = 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  ... ↔ (∥y∥ : 𝕜) • x = (∥x∥ : 𝕜) • 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`⟪x, y⟫ = ∥x∥ * ∥y∥`), 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 ⟪x, y⟫ = ∥x∥ * ∥y∥`. -/\nlemma inner_eq_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ = ∥x∥ * ∥y∥ ↔ ∥y∥ • x = ∥x∥ • 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 : ∥x∥ = 1) (hy : ∥y∥ = 1) :\n  ⟪x, y⟫ = 1 ↔ 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  ⟪x, y⟫_ℝ < ∥x∥ * ∥y∥ ↔ ∥y∥ • x ≠ ∥x∥ • y :=\ncalc ⟪x, y⟫_ℝ < ∥x∥ * ∥y∥\n    ↔ ⟪x, y⟫_ℝ ≠ ∥x∥ * ∥y∥ : ⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩\n... ↔ ∥y∥ • x ≠ ∥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. -/\nlemma inner_lt_one_iff_real_of_norm_one {x y : F} (hx : ∥x∥ = 1) (hy : ∥y∥ = 1) :\n  ⟪x, y⟫_ℝ < 1 ↔ x ≠ 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 {ι₁ : Type*} {s₁ : finset ι₁} {w₁ : ι₁ → ℝ}\n    (v₁ : ι₁ → F) (h₁ : ∑ i in s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : finset ι₂} {w₂ : ι₂ → ℝ}\n    (v₂ : ι₂ → F) (h₂ : ∑ i in s₂, w₂ i = 0) :\n  ⟪(∑ i₁ in s₁, w₁ i₁ • v₁ i₁), (∑ i₂ in s₂, w₂ i₂ • v₂ i₂)⟫_ℝ =\n    (-∑ i₁ in s₁, ∑ i₂ in s₂, w₁ i₁ * w₂ i₂ * (∥v₁ i₁ - v₂ i₂∥ * ∥v₁ i₁ - v₂ i₂∥)) / 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            ←div_sub_div_same, ←div_add_div_same, mul_sub_left_distrib, left_distrib,\n            finset.sum_sub_distrib, finset.sum_add_distrib, ←finset.mul_sum, ←finset.sum_mul,\n            h₁, h₂, 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ₛₗ : E →ₗ⋆[𝕜] E →ₗ[𝕜] 𝕜 :=\nlinear_map.mk₂'ₛₗ _ _ (λ v w, ⟪v, w⟫) (λ _ _ _, inner_add_left) (λ _ _ _, inner_smul_left)\n(λ _ _ _, inner_add_right) (λ _ _ _, inner_smul_right)\n\n@[simp] lemma innerₛₗ_apply_coe (v : E) : (innerₛₗ v : E → 𝕜) = λ w, ⟪v, w⟫ := rfl\n\n@[simp] lemma innerₛₗ_apply (v w : E) : innerₛₗ v w = ⟪v, w⟫ := 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 →L⋆[𝕜] E →L[𝕜] 𝕜 :=\nlinear_map.mk_continuous₂ innerₛₗ 1\n(λ x y, by simp only [norm_inner_le_norm, one_mul, innerₛₗ_apply])\n\n@[simp] lemma innerSL_apply_coe (v : E) : (innerSL v : E → 𝕜) = λ w, ⟪v, w⟫ := rfl\n\n@[simp] lemma innerSL_apply (v w : E) : innerSL v w = ⟪v, w⟫ := 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} : ∥(innerSL x : E →L[𝕜] 𝕜)∥ = ∥x∥ :=\nbegin\n  refine le_antisymm ((innerSL x).op_norm_le_bound (norm_nonneg _) (λ 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 ∥x∥ * ∥x∥ = ∥x∥ ^ 2 : by ring\n    ... = re ⟪x, x⟫ : norm_sq_eq_inner _\n    ... ≤ abs ⟪x, x⟫ : re_le_abs _\n    ... = ∥innerSL x x∥ : by { rw [←is_R_or_C.norm_eq_abs], refl }\n    ... ≤ ∥innerSL x∥ * ∥x∥ : (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 →L[𝕜] E →L⋆[𝕜] 𝕜 :=\n@continuous_linear_map.flipₗᵢ' 𝕜 𝕜 𝕜 E E 𝕜 _ _ _ _ _ _ _ _ _ (ring_hom.id 𝕜) (star_ring_end 𝕜) _ _\n  innerSL\n\n@[simp] lemma innerSL_flip_apply {x y : E} : innerSL_flip x y = ⟪y, x⟫ := rfl\n\nnamespace continuous_linear_map\n\nvariables  {E' : Type*} [inner_product_space 𝕜 E']\n\n/-- Given `f : E →L[𝕜] E'`, construct the continuous sesquilinear form `λ x y, ⟪x, A y⟫`, given\nas a continuous linear map. -/\ndef to_sesq_form : (E →L[𝕜] E') →L[𝕜] E' →L⋆[𝕜] E →L[𝕜] 𝕜 :=\n↑((continuous_linear_map.flipₗᵢ' E E' 𝕜\n  (star_ring_end 𝕜) (ring_hom.id 𝕜)).to_continuous_linear_equiv) ∘L\n(continuous_linear_map.compSL E E' (E' →L⋆[𝕜] 𝕜) (ring_hom.id 𝕜) (ring_hom.id 𝕜) innerSL_flip)\n\n@[simp] lemma to_sesq_form_apply_coe (f : E →L[𝕜] E') (x : E') :\n  to_sesq_form f x = (innerSL x).comp f := rfl\n\nlemma to_sesq_form_apply_norm_le {f : E →L[𝕜] E'} {v : E'} : ∥to_sesq_form f v∥ ≤ ∥f∥ * ∥v∥ :=\nbegin\n  refine op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,\n  intro x,\n  have h₁ : ∥f x∥ ≤ ∥f∥ * ∥x∥ := le_op_norm _ _,\n  have h₂ := @norm_inner_le_norm 𝕜 E' _ _ v (f x),\n  calc ∥⟪v, f x⟫∥ ≤ ∥v∥ * ∥f x∥       :  h₂\n              ... ≤ ∥v∥ * (∥f∥ * ∥x∥)  : mul_le_mul_of_nonneg_left h₁ (norm_nonneg v)\n              ... = ∥f∥ * ∥v∥ * ∥x∥    : by ring,\nend\n\nend continuous_linear_map\n\n/-- When an inner product space `E` over `𝕜` 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 ℝ E` instance. We will later establish\nsuch an instance by restriction-of-scalars, `inner_product_space.is_R_or_C_to_real 𝕜 E`, but this\ninstance may be not definitionally equal to some other “natural” instance. So, we assume\n`[normed_space ℝ E]`.\n-/\nlemma is_bounded_bilinear_map_inner [normed_space ℝ E] :\n  is_bounded_bilinear_map ℝ (λ p : E × E, ⟪p.1, p.2⟫) :=\n{ add_left := λ _ _ _, inner_add_left,\n  smul_left := λ r x y,\n    by simp only [← algebra_map_smul 𝕜 r x, algebra_map_eq_of_real, inner_smul_real_left],\n  add_right := λ _ _ _, inner_add_right,\n  smul_right := λ r x y,\n    by simp only [← algebra_map_smul 𝕜 r y, algebra_map_eq_of_real, inner_smul_real_right],\n  bound := ⟨1, zero_lt_one, λ x y,\n    by { rw [one_mul], exact norm_inner_le_norm x y, }⟩ }\n\nend norm\n\nsection bessels_inequality\n\nvariables {ι: Type*} (x : E) {v : ι → E}\n\n/-- Bessel's inequality for finite sums. -/\nlemma orthonormal.sum_inner_products_le {s : finset ι} (hv : orthonormal 𝕜 v) :\n  ∑ i in s, ∥⟪v i, x⟫∥ ^ 2 ≤ ∥x∥ ^ 2 :=\nbegin\n  have h₂ : ∑ i in s, ∑ j in s, ⟪v i, x⟫ * ⟪x, v j⟫ * ⟪v j, v i⟫\n    = (∑ k in s, (⟪v k, x⟫ * ⟪x, v k⟫) : 𝕜),\n  { exact hv.inner_left_right_finset },\n  have h₃ : ∀ z : 𝕜, re (z * conj (z)) = ∥z∥ ^ 2,\n  { intro z,\n    simp only [mul_conj, norm_sq_eq_def'],\n    norm_cast, },\n  suffices hbf: ∥x -  ∑ i in s, ⟪v i, x⟫ • (v i)∥ ^ 2 = ∥x∥ ^ 2 - ∑ i in s, ∥⟪v i, x⟫∥ ^ 2,\n  { rw [←sub_nonneg, ←hbf],\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, ←mul_assoc, h₂, ←h₃,\n  inner_conj_sym, add_monoid_hom.map_sum, finset.mul_sum, ←finset.sum_sub_distrib, inner_smul_left,\n  add_sub_cancel'],\nend\n\n/-- Bessel's inequality. -/\nlemma orthonormal.tsum_inner_products_le (hv : orthonormal 𝕜 v) :\n  ∑' i, ∥⟪v i, x⟫∥ ^ 2 ≤ ∥x∥ ^ 2 :=\nbegin\n  refine tsum_le_of_sum_le' _ (λ 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 𝕜 v) : summable (λ i, ∥⟪v i, x⟫∥ ^ 2) :=\nbegin\n  use ⨆ s : finset ι, ∑ i in s, ∥⟪v i, x⟫∥ ^ 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 ∥x∥ ^ 2,\n    rintro y ⟨s, rfl⟩,\n    exact hv.sum_inner_products_le x }\nend\n\nend bessels_inequality\n\n/-- A field `𝕜` satisfying `is_R_or_C` is itself a `𝕜`-inner product space. -/\ninstance is_R_or_C.inner_product_space : inner_product_space 𝕜 𝕜 :=\n{ inner := (λ x y, (conj x) * y),\n  norm_sq_eq_inner := λ x,\n    by { unfold inner, rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def'] },\n  conj_sym := λ x y, by simp [mul_comm],\n  add_left := λ x y z, by simp [inner, add_mul],\n  smul_left := λ x y z, by simp [inner, mul_assoc] }\n\n@[simp] lemma is_R_or_C.inner_apply (x y : 𝕜) : ⟪x, y⟫ = (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 𝕜 E) : inner_product_space 𝕜 W :=\n{ inner             := λ x y, ⟪(x:E), (y:E)⟫,\n  conj_sym          := λ _ _, inner_conj_sym _ _ ,\n  norm_sq_eq_inner  := λ _, norm_sq_eq_inner _,\n  add_left          := λ _ _ _ , inner_add_left,\n  smul_left         := λ _ _ _, 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 𝕜 E) (x y : W) : ⟪x, y⟫ = ⟪(x:E), ↑y⟫ := rfl\n\n/-! ### Families of mutually-orthogonal subspaces of an inner product space -/\n\nsection orthogonal_family\nvariables {ι : Type*} [dec_ι : decidable_eq ι] (𝕜)\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 : ι → submodule 𝕜 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 : ι → E`,\nwe have an associated orthogonal family of one-dimensional subspaces of `E`, which it is convenient\nto be able to discuss using `ι → 𝕜` rather than `Π i : ι, span 𝕜 (v i)`. -/\ndef orthogonal_family {G : ι → Type*} [Π i, inner_product_space 𝕜 (G i)] (V : Π i, G i →ₗᵢ[𝕜] E) :\n  Prop :=\n∀ ⦃i j⦄, i ≠ j → ∀ v : G i, ∀ w : G j, ⟪V i v, V j w⟫ = 0\n\nvariables {𝕜} {G : ι → Type*} [Π i, inner_product_space 𝕜 (G i)] {V : Π i, G i →ₗᵢ[𝕜] E}\n  (hV : orthogonal_family 𝕜 V) [dec_V : Π i (x : G i), decidable (x ≠ 0)]\n\nlemma orthonormal.orthogonal_family {v : ι → E} (hv : orthonormal 𝕜 v) :\n  @orthogonal_family 𝕜 _ _ _ _ (λ i : ι, 𝕜) _\n    (λ i, linear_isometry.to_span_singleton 𝕜 E (hv.1 i)) :=\nλ i j hij a b, by simp [inner_smul_left, inner_smul_right, hv.2 hij]\n\ninclude hV dec_ι\nlemma orthogonal_family.eq_ite {i j : ι} (v : G i) (w : G j) :\n  ⟪V i v, V j w⟫ = ite (i = j) ⟪V i v, V j w⟫ 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 : ⨁ i, G i) (i : ι) (v : G i) :\n  ⟪V i v, l.sum (λ j, V j)⟫ = ⟪v, l i⟫ :=\ncalc ⟪V i v, l.sum (λ j, V j)⟫\n    = l.sum (λ j, λ w, ⟪V i v, V j w⟫) : dfinsupp.inner_sum (λ j, V j) l (V i v)\n... = l.sum (λ j, λ w, ite (i=j) ⟪V i v, V j w⟫ 0) :\n  congr_arg l.sum $ funext $ λ j, funext $ hV.eq_ite v\n... = ⟪v, l i⟫ :\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_ι dec_V\n\nlemma orthogonal_family.inner_right_fintype [fintype ι] (l : Π i, G i) (i : ι) (v : G i) :\n  ⟪V i v, ∑ j : ι, V j (l j)⟫ = ⟪v, l i⟫ :=\nby classical;\ncalc ⟪V i v, ∑ j : ι, V j (l j)⟫\n    = ∑ j : ι, ⟪V i v, V j (l j)⟫: by rw inner_sum\n... = ∑ j, ite (i = j) ⟪V i v, V j (l j)⟫ 0 :\n  congr_arg (finset.sum finset.univ) $ funext $ λ j, (hV.eq_ite v (l j))\n... = ⟪v, l i⟫ : by simp\n\nlemma orthogonal_family.inner_sum (l₁ l₂ : Π i, G i) (s : finset ι) :\n  ⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫ = ∑ i in s, ⟪l₁ i, l₂ i⟫ :=\nby classical;\ncalc ⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫\n    = ∑ j in s, ∑ i in s, ⟪V i (l₁ i), V j (l₂ j)⟫ : by simp [sum_inner, inner_sum]\n... = ∑ j in s, ∑ i in s, ite (i = j) ⟪V i (l₁ i), V j (l₂ j)⟫ 0 :\nbegin\n  congr' with i,\n  congr' with j,\n  apply hV.eq_ite,\nend\n... = ∑ i in s, ⟪l₁ i, l₂ i⟫ : by simp [finset.sum_ite_of_true]\n\nlemma orthogonal_family.norm_sum (l : Π i, G i) (s : finset ι) :\n  ∥∑ i in s, V i (l i)∥ ^ 2 = ∑ i in s, ∥l i∥ ^ 2 :=\nbegin\n  have : (∥∑ i in s, V i (l i)∥ ^ 2 : 𝕜) = ∑ i in s, ∥l i∥ ^ 2,\n  { simp [← 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 {γ : Type*} {f : γ → ι} (hf : function.injective f) :\n  orthogonal_family 𝕜 (λ g : γ, (V (f g) : G (f g) →ₗᵢ[𝕜] E)) :=\nλ i j hij v w, hV (hf.ne hij) v w\n\nlemma orthogonal_family.orthonormal_sigma_orthonormal {α : ι → Type*} {v_family : Π i, (α i) → G i}\n  (hv_family : ∀ i, orthonormal 𝕜 (v_family i)) :\n  orthonormal 𝕜 (λ a : Σ i, α i, V a.1 (v_family a.1 a.2)) :=\nbegin\n  split,\n  { rintros ⟨i, v⟩,\n    simpa using (hv_family i).1 v },\n  rintros ⟨i, v⟩ ⟨j, w⟩ hvw,\n  by_cases hij : i = j,\n  { subst hij,\n    have : v ≠ 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_ι\nlemma orthogonal_family.norm_sq_diff_sum (f : Π i, G i) (s₁ s₂ : finset ι) :\n  ∥∑ i in s₁, V i (f i) - ∑ i in s₂, V i (f i)∥ ^ 2\n  = ∑ i in s₁ \\ s₂, ∥f i∥ ^ 2 + ∑ i in s₂ \\ s₁, ∥f i∥ ^ 2 :=\nbegin\n  rw [← finset.sum_sdiff_sub_sum_sdiff, sub_eq_add_neg, ← finset.sum_neg_distrib],\n  let F : Π i, G i := λ i, if i ∈ s₁ then f i else - (f i),\n  have hF₁ : ∀ i ∈ s₁ \\ s₂, F i = f i := λ i hi, if_pos (finset.sdiff_subset _ _ hi),\n  have hF₂ : ∀ i ∈ s₂ \\ s₁, F i = - f i := λ i hi, if_neg (finset.mem_sdiff.mp hi).2,\n  have hF : ∀ i, ∥F i∥ = ∥f i∥,\n  { intros i,\n    dsimp [F],\n    split_ifs;\n    simp, },\n  have : ∥∑ i in s₁ \\ s₂, V i (F i) + ∑ i in s₂ \\ s₁, V i (F i)∥ ^ 2 =\n    ∑ i in s₁ \\ s₂, ∥F i∥ ^ 2 + ∑ i in s₂ \\ s₁, ∥F i∥ ^ 2,\n  { have hs : disjoint (s₁ \\ s₂) (s₂ \\ s₁) := disjoint_sdiff_sdiff,\n    simpa only [finset.sum_union hs] using hV.norm_sum F (s₁ \\ s₂ ∪ s₂ \\ s₁) },\n  convert this using 4,\n  { refine finset.sum_congr rfl (λ i hi, _),\n    simp [hF₁ i hi] },\n  { refine finset.sum_congr rfl (λ i hi, _),\n    simp [hF₂ i hi] },\n  { simp [hF] },\n  { simp [hF] },\nend\n\nomit dec_ι\n\n/-- A family `f` of mutually-orthogonal elements of `E` is summable, if and only if\n`(λ i, ∥f i∥ ^ 2)` is summable. -/\nlemma orthogonal_family.summable_iff_norm_sq_summable [complete_space E] (f : Π i, G i) :\n  summable (λ i, V i (f i)) ↔ summable (λ i, ∥f i∥ ^ 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 ε hε,\n    obtain ⟨a, H⟩ := hf _ (sqrt_pos.mpr hε),\n    use a,\n    intros s₁ hs₁ s₂ hs₂,\n    rw ← finset.sum_sdiff_sub_sum_sdiff,\n    refine (_root_.abs_sub _ _).trans_lt _,\n    have : ∀ i, 0 ≤ ∥f i∥ ^ 2 := λ i : ι, sq_nonneg _,\n    simp only [finset.abs_sum_of_nonneg' this],\n    have : ∑ i in s₁ \\ s₂, ∥f i∥ ^ 2 + ∑ i in s₂ \\ s₁, ∥f i∥ ^ 2 < (sqrt ε) ^ 2,\n    { rw [← 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₁ hs₁ s₂ hs₂ },\n    have hη := sq_sqrt (le_of_lt hε),\n    linarith },\n  { intros hf ε hε,\n    have hε' : 0 < ε ^ 2 / 2 := half_pos (sq_pos_of_pos hε),\n    obtain ⟨a, H⟩ := hf _ hε',\n    use a,\n    intros s₁ hs₁ s₂ hs₂,\n    refine (abs_lt_of_sq_lt_sq' _ (le_of_lt hε)).2,\n    have has : a ≤ s₁ ⊓ s₂ := le_inf hs₁ hs₂,\n    rw hV.norm_sq_diff_sum,\n    have Hs₁ : ∑ (x : ι) in s₁ \\ s₂, ∥f x∥ ^ 2 < ε ^ 2 / 2,\n    { convert H _ hs₁ _ has,\n      have : s₁ ⊓ s₂ ⊆ s₁ := finset.inter_subset_left _ _,\n      rw [← finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],\n      { simp },\n      { exact λ i, sq_nonneg _ } },\n    have Hs₂ : ∑ (x : ι) in s₂ \\ s₁, ∥f x∥ ^ 2 < ε ^ 2 /2,\n    { convert H _ hs₂ _ has,\n      have : s₁ ⊓ s₂ ⊆ s₂ := finset.inter_subset_right _ _,\n      rw [← finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],\n      { simp },\n      { exact λ 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 : ι → submodule 𝕜 E}\n  (hV : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) :\n  complete_lattice.independent V :=\nbegin\n  classical,\n  apply complete_lattice.independent_of_dfinsupp_lsum_injective,\n  rw [← @linear_map.ker_eq_bot _ _ _ _ _ _ (direct_sum.add_comm_group (λ 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 : ⟪(v i : E), v i⟫ = 0,\n  { simpa using this },\n  calc ⟪(v i : E), v i⟫ = ⟪(v i : E), dfinsupp.lsum ℕ (λ i, (V i).subtype) v⟫ :\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_ι\nlemma direct_sum.is_internal.collected_basis_orthonormal {V : ι → submodule 𝕜 E}\n  (hV : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ))\n  (hV_sum : direct_sum.is_internal (λ i, V i))\n  {α : ι → Type*}\n  {v_family : Π i, basis (α i) 𝕜 (V i)} (hv_family : ∀ i, orthonormal 𝕜 (v_family i)) :\n  orthonormal 𝕜 (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 (𝕜 E)\ninclude 𝕜\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 `𝕜 = ℝ`. -/\ndef has_inner.is_R_or_C_to_real : has_inner ℝ E :=\n{ inner := λ x y, re ⟪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 `𝕜 = ℝ`, but in can be used in a\nproof to obtain a real inner product space structure from a given `𝕜`-inner product space\nstructure. -/\ndef inner_product_space.is_R_or_C_to_real : inner_product_space ℝ E :=\n{ norm_sq_eq_inner := norm_sq_eq_inner,\n  conj_sym := λ x y, inner_re_symm,\n  add_left := λ x y z, by\n  { change re ⟪x + y, z⟫ = re ⟪x, z⟫ + re ⟪y, z⟫,\n    simp [inner_add_left] },\n  smul_left := λ x y r, by\n  { change re ⟪(r : 𝕜) • x, y⟫ = r * re ⟪x, y⟫,\n    simp [inner_smul_left] },\n  ..has_inner.is_R_or_C_to_real 𝕜 E,\n  ..normed_space.restrict_scalars ℝ 𝕜 E }\n\nvariable {E}\n\nlemma real_inner_eq_re_inner (x y : E) :\n  @has_inner.inner ℝ E (has_inner.is_R_or_C_to_real 𝕜 E) x y = re ⟪x, y⟫ := rfl\n\nlemma real_inner_I_smul_self (x : E) :\n  @has_inner.inner ℝ E (has_inner.is_R_or_C_to_real 𝕜 E) x ((I : 𝕜) • x) = 0 :=\nby simp [real_inner_eq_re_inner, inner_smul_right]\n\nomit 𝕜\n\n/-- A complex inner product implies a real inner product -/\ninstance inner_product_space.complex_to_real [inner_product_space ℂ G] : inner_product_space ℝ G :=\ninner_product_space.is_R_or_C_to_real ℂ 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 (λ p : E × E, ⟪p.1, p.2⟫) :=\nbegin\n  letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E,\n  exact is_bounded_bilinear_map_inner.continuous\nend\n\nvariables {α : Type*}\n\nlemma filter.tendsto.inner {f g : α → E} {l : filter α} {x y : E} (hf : tendsto f l (𝓝 x))\n  (hg : tendsto g l (𝓝 y)) :\n  tendsto (λ t, ⟪f t, g t⟫) l (𝓝 ⟪x, y⟫) :=\n(continuous_inner.tendsto _).comp (hf.prod_mk_nhds hg)\n\nvariables [topological_space α] {f g : α → E} {x : α} {s : set α}\n\ninclude 𝕜\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 (λ t, ⟪f t, g t⟫) s x :=\nhf.inner hg\n\nlemma continuous_at.inner (hf : continuous_at f x) (hg : continuous_at g x) :\n  continuous_at (λ t, ⟪f t, g t⟫) x :=\nhf.inner hg\n\nlemma continuous_on.inner (hf : continuous_on f s) (hg : continuous_on g s) :\n  continuous_on (λ t, ⟪f t, g t⟫) s :=\nλ x hx, (hf x hx).inner (hg x hx)\n\nlemma continuous.inner (hf : continuous f) (hg : continuous g) : continuous (λ t, ⟪f t, g t⟫) :=\ncontinuous_iff_continuous_at.2 $ λ 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 `λ x, re ⟪T x, x⟫`. -/\ndef continuous_linear_map.re_apply_inner_self (T : E →L[𝕜] E) (x : E) : ℝ := re ⟪T x, x⟫\n\nlemma continuous_linear_map.re_apply_inner_self_apply (T : E →L[𝕜] E) (x : E) :\n  T.re_apply_inner_self x = re ⟪T x, x⟫ :=\nrfl\n\nlemma continuous_linear_map.re_apply_inner_self_continuous (T : E →L[𝕜] 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 →L[𝕜] E) (x : E) {c : 𝕜} :\n  T.re_apply_inner_self (c • x) = ∥c∥ ^ 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, ← mul_assoc, mul_conj, norm_sq_eq_def', ← smul_re,\n  algebra.smul_def (∥c∥ ^ 2) ⟪T x, x⟫, algebra_map_eq_of_real]\n\nend re_apply_inner_self\n\n/-! ### The orthogonal complement -/\n\nsection orthogonal\nvariables (K : submodule 𝕜 E)\n\n/-- The subspace of vectors orthogonal to a given subspace. -/\ndef submodule.orthogonal : submodule 𝕜 E :=\n{ carrier := {v | ∀ u ∈ K, ⟪u, v⟫ = 0},\n  zero_mem' := λ _ _, inner_zero_right,\n  add_mem' := λ x y hx hy u hu, by rw [inner_add_right, hx u hu, hy u hu, add_zero],\n  smul_mem' := λ c x hx u hu, by rw [inner_smul_right, hx u hu, mul_zero] }\n\nnotation K`ᗮ`:1200 := submodule.orthogonal K\n\n/-- When a vector is in `Kᗮ`. -/\nlemma submodule.mem_orthogonal (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪u, v⟫ = 0 := iff.rfl\n\n/-- When a vector is in `Kᗮ`, with the inner product the\nother way round. -/\nlemma submodule.mem_orthogonal' (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪v, u⟫ = 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ᗮ`. -/\nlemma submodule.inner_right_of_mem_orthogonal {u v : E} (hu : u ∈ K) (hv : v ∈ Kᗮ) : ⟪u, v⟫ = 0 :=\n(K.mem_orthogonal v).1 hv u hu\n\n/-- A vector in `Kᗮ` is orthogonal to one in `K`. -/\nlemma submodule.inner_left_of_mem_orthogonal {u v : E} (hu : u ∈ K) (hv : v ∈ Kᗮ) : ⟪v, u⟫ = 0 :=\nby rw [inner_eq_zero_sym]; exact submodule.inner_right_of_mem_orthogonal hu hv\n\n/-- A vector in `(𝕜 ∙ u)ᗮ` is orthogonal to `u`. -/\nlemma inner_right_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v ∈ (𝕜 ∙ u)ᗮ) : ⟪u, v⟫ = 0 :=\nsubmodule.inner_right_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector in `(𝕜 ∙ u)ᗮ` is orthogonal to `u`. -/\nlemma inner_left_of_mem_orthogonal_singleton (u : E) {v : E} (hv : v ∈ (𝕜 ∙ u)ᗮ) : ⟪v, u⟫ = 0 :=\nsubmodule.inner_left_of_mem_orthogonal (submodule.mem_span_singleton_self u) hv\n\n/-- A vector orthogonal to `u` lies in `(𝕜 ∙ u)ᗮ`. -/\nlemma mem_orthogonal_singleton_of_inner_right (u : E) {v : E} (hv : ⟪u, v⟫ = 0) : v ∈ (𝕜 ∙ u)ᗮ :=\nbegin\n  intros w hw,\n  rw submodule.mem_span_singleton at hw,\n  obtain ⟨c, rfl⟩ := hw,\n  simp [inner_smul_left, hv],\nend\n\n/-- A vector orthogonal to `u` lies in `(𝕜 ∙ u)ᗮ`. -/\nlemma mem_orthogonal_singleton_of_inner_left (u : E) {v : E} (hv : ⟪v, u⟫ = 0) : v ∈ (𝕜 ∙ u)ᗮ :=\nmem_orthogonal_singleton_of_inner_right u $ inner_eq_zero_sym.2 hv\n\nvariables (K)\n\n/-- `K` and `Kᗮ` have trivial intersection. -/\nlemma submodule.inf_orthogonal_eq_bot : K ⊓ Kᗮ = ⊥ :=\nbegin\n  rw submodule.eq_bot_iff,\n  intros x,\n  rw submodule.mem_inf,\n  exact λ ⟨hx, ho⟩, inner_self_eq_zero.1 (ho x hx)\nend\n\n/-- `K` and `Kᗮ` have trivial intersection. -/\nlemma submodule.orthogonal_disjoint : disjoint K Kᗮ :=\nby simp [disjoint_iff, K.inf_orthogonal_eq_bot]\n\n/-- `Kᗮ` 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ᗮ = ⨅ v : K, (innerSL (v:E)).ker :=\nbegin\n  apply le_antisymm,\n  { rw le_infi_iff,\n    rintros ⟨v, hv⟩ w hw,\n    simpa using hw _ hv },\n  { intros v hv w hw,\n    simp only [submodule.mem_infi] at hv,\n    exact hv ⟨w, hw⟩ }\nend\n\n/-- The orthogonal complement of any submodule `K` is closed. -/\nlemma submodule.is_closed_orthogonal : is_closed (Kᗮ : set E) :=\nbegin\n  rw orthogonal_eq_inter K,\n  convert is_closed_Inter (λ 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ᗮ := K.is_closed_orthogonal.complete_space_coe\n\nvariables (𝕜 E)\n\n/-- `submodule.orthogonal` gives a `galois_connection` between\n`submodule 𝕜 E` and its `order_dual`. -/\nlemma submodule.orthogonal_gc :\n  @galois_connection (submodule 𝕜 E) (submodule 𝕜 E)ᵒᵈ _ _\n    submodule.orthogonal submodule.orthogonal :=\nλ K₁ K₂, ⟨λ h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu),\n          λ h v hv u hu, submodule.inner_left_of_mem_orthogonal hv (h hu)⟩\n\nvariables {𝕜 E}\n\n/-- `submodule.orthogonal` reverses the `≤` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_le {K₁ K₂ : submodule 𝕜 E} (h : K₁ ≤ K₂) : K₂ᗮ ≤ K₁ᗮ :=\n(submodule.orthogonal_gc 𝕜 E).monotone_l h\n\n/-- `submodule.orthogonal.orthogonal` preserves the `≤` ordering of two\nsubspaces. -/\nlemma submodule.orthogonal_orthogonal_monotone {K₁ K₂ : submodule 𝕜 E} (h : K₁ ≤ K₂) :\n  K₁ᗮᗮ ≤ K₂ᗮᗮ :=\nsubmodule.orthogonal_le (submodule.orthogonal_le h)\n\n/-- `K` is contained in `Kᗮᗮ`. -/\nlemma submodule.le_orthogonal_orthogonal : K ≤ Kᗮᗮ := (submodule.orthogonal_gc 𝕜 E).le_u_l _\n\n/-- The inf of two orthogonal subspaces equals the subspace orthogonal\nto the sup. -/\nlemma submodule.inf_orthogonal (K₁ K₂ : submodule 𝕜 E) : K₁ᗮ ⊓ K₂ᗮ = (K₁ ⊔ K₂)ᗮ :=\n(submodule.orthogonal_gc 𝕜 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 {ι : Type*} (K : ι → submodule 𝕜 E) : (⨅ i, (K i)ᗮ) = (supr K)ᗮ :=\n(submodule.orthogonal_gc 𝕜 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 𝕜 E) : (⨅ K ∈ s, Kᗮ) = (Sup s)ᗮ :=\n(submodule.orthogonal_gc 𝕜 E).l_Sup.symm\n\n@[simp] lemma submodule.top_orthogonal_eq_bot : (⊤ : submodule 𝕜 E)ᗮ = ⊥ :=\nbegin\n  ext,\n  rw [submodule.mem_bot, submodule.mem_orthogonal],\n  exact ⟨λ h, inner_self_eq_zero.mp (h x submodule.mem_top), by { rintro rfl, simp }⟩\nend\n\n@[simp] lemma submodule.bot_orthogonal_eq_top : (⊥ : submodule 𝕜 E)ᗮ = ⊤ :=\nbegin\n  rw [← submodule.top_orthogonal_eq_bot, eq_top_iff],\n  exact submodule.le_orthogonal_orthogonal ⊤\nend\n\n@[simp] lemma submodule.orthogonal_eq_top_iff : Kᗮ = ⊤ ↔ K = ⊥ :=\nbegin\n  refine ⟨_, by { rintro rfl, exact submodule.bot_orthogonal_eq_top }⟩,\n  intro h,\n  have : K ⊓ Kᗮ = ⊥ := 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 `⟪T x, y⟫ = ⟪x, T y⟫`. -/\ndef is_self_adjoint (T : E →ₗ[𝕜] E) : Prop := ∀ x y, ⟪T x, y⟫ = ⟪x, T y⟫\n\n/-- An operator `T` on a `ℝ`-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 →ₗ[ℝ] F) :\n  is_self_adjoint T ↔ 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 →ₗ[𝕜] E} (hT : is_self_adjoint T) (x y : E) :\n  conj ⟪T x, y⟫ = ⟪T y, x⟫ :=\nby rw [hT x y, inner_conj_sym]\n\n@[simp] lemma is_self_adjoint.apply_clm {T : E →L[𝕜] E} (hT : is_self_adjoint (T : E →ₗ[𝕜] E))\n  (x y : E) :\n  ⟪T x, y⟫ = ⟪x, T y⟫ :=\nhT x y\n\n/-- For a self-adjoint operator `T`, the function `λ x, ⟪T x, x⟫` is real-valued. -/\n@[simp] lemma is_self_adjoint.coe_re_apply_inner_self_apply\n  {T : E →L[𝕜] E} (hT : is_self_adjoint (T : E →ₗ[𝕜] E)) (x : E) :\n  (T.re_apply_inner_self x : 𝕜) = ⟪T x, x⟫ :=\nbegin\n  suffices : ∃ r : ℝ, ⟪T x, x⟫ = r,\n  { obtain ⟨r, hr⟩ := this,\n    simp [hr, T.re_apply_inner_self_apply] },\n  rw ← 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 →ₗ[𝕜] E} (hT : is_self_adjoint T)\n  {V : submodule 𝕜 E} (hV : ∀ v ∈ V, T v ∈ V) :\n  is_self_adjoint (T.restrict hV) :=\nλ v w, hT v w\n\nsection complex\n\nvariables {V : Type*}\n  [inner_product_space ℂ V]\n\n/-- A linear operator on a complex inner product space is self-adjoint precisely when\n`⟪T v, v⟫_ℂ` is real for all v.-/\nlemma is_self_adjoint_iff_inner_map_self_real (T : V →ₗ[ℂ] V):\n  is_self_adjoint T ↔ ∀ (v : V), conj ⟪T v, v⟫_ℂ = ⟪T v, v⟫_ℂ :=\nbegin\n  split,\n  { intros hT v,\n    apply is_self_adjoint.conj_inner_sym hT },\n  { intros h x y,\n    nth_rewrite 1 ← inner_conj_sym,\n    nth_rewrite 1 inner_map_polarization,\n    simp only [star_ring_end_apply, star_div', star_sub, star_add, star_mul],\n    simp only [← star_ring_end_apply],\n    rw [h (x + y), h (x - y), h (x + complex.I • y), h (x - complex.I • y)],\n    simp only [complex.conj_I],\n    rw inner_map_polarization',\n    norm_num,\n    ring },\nend\n\nend complex\n\nend inner_product_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/inner_product_space/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240108164657, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7580672488831379}}
{"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 linear_algebra.dual\n\n/-!\n# Contractions\n\nGiven modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps:\n$M^* \\otimes M \\to R$, $M \\otimes M^* \\to R$, and $M^* \\otimes N → Hom(M, N)$, as well as proving\nsome basic properties of these maps.\n\n## Tags\n\ncontraction, dual module, tensor product\n-/\n\nuniverses u v\n\n\nsection contraction\nopen tensor_product\nopen_locale tensor_product\n\nvariables (R : Type u) (M N : Type v)\nvariables [comm_ring R] [add_comm_group M] [add_comm_group N] [module R M] [module R N]\n\n/-- The natural left-handed pairing between a module and its dual. -/\ndef contract_left : (module.dual R M) ⊗ M →ₗ[R] R := (uncurry _ _ _ _).to_fun linear_map.id\n\n/-- The natural right-handed pairing between a module and its dual. -/\ndef contract_right : M ⊗ (module.dual R M) →ₗ[R] R :=\n(uncurry _ _ _ _).to_fun (linear_map.flip linear_map.id)\n\n/-- The natural map associating a linear map to the tensor product of two modules. -/\ndef dual_tensor_hom : (module.dual R M) ⊗ N →ₗ[R] M →ₗ[R] N :=\n  let M' := module.dual R M in\n  (uncurry R M' N (M →ₗ[R] N) : _ → M' ⊗ N →ₗ[R] M →ₗ[R] N) linear_map.smul_rightₗ\n\nvariables {R M N}\n\n@[simp] lemma contract_left_apply (f : module.dual R M) (m : M) :\n  contract_left R M (f ⊗ₜ m) = f m := by apply uncurry_apply\n\n@[simp] lemma contract_right_apply (f : module.dual R M) (m : M) :\n  contract_right R M (m ⊗ₜ f) = f m := by apply uncurry_apply\n\n@[simp] lemma dual_tensor_hom_apply (f : module.dual R M) (m : M) (n : N) :\n  dual_tensor_hom R M N (f ⊗ₜ n) m = (f m) • n :=\nby { dunfold dual_tensor_hom, rw uncurry_apply, refl, }\n\nend contraction\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/contraction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.758044430005795}}
{"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 ℕ × ℕ as 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 the antidiagonals of ℕ × ℕ 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 : ℕ) : finset (ℕ × ℕ) :=\n⟨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] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :\n  x ∈ antidiagonal n ↔ 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 : ℕ) : (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 : ℕ) :\n  antidiagonal (n + 1) = cons (0, n + 1) ((antidiagonal n).map\n  (function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ (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 : ℕ) :\n  antidiagonal (n + 1) = cons (n + 1, 0) ((antidiagonal n).map\n  (function.embedding.prod_map (function.embedding.refl _) ⟨nat.succ, nat.succ_injective⟩))\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 : ℕ} :\n  antidiagonal (n + 2) =\n    cons (0, n + 2)\n      (cons (n + 2, 0) ((antidiagonal n).map\n        (function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ ⟨nat.succ, nat.succ_injective⟩))\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 : ℕ} :\n  (antidiagonal n).map ⟨prod.swap, prod.swap_right_inverse.injective⟩ = 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 : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)\n  (hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=\nbegin\n  refine ⟨congr_arg prod.fst, (λ h, prod.ext h ((add_right_inj q.fst).mp _))⟩,\n  rw mem_antidiagonal at hp hq,\n  rw [hq, ← h, hp],\nend\n\nlemma antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.1 ≤ 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 : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :\n  kl.2 ≤ 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 : ℕ) :\n  filter (λ x : ℕ × ℕ, x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ :=\nbegin\n  ext ⟨x, y⟩,\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 λ 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 : ℕ) :\n  filter (λ x : ℕ × ℕ, x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ :=\nbegin\n  have : (λ (x : ℕ × ℕ), x.snd = m) ∘ prod.swap = (λ (x : ℕ × ℕ), x.fst = m),\n  { ext, simp },\n  rw ←map_swap_antidiagonal,\n  simp [filter_map, this, filter_fst_eq_antidiagonal, apply_ite (finset.map _)]\nend\n\nsection equiv_prod\n\n/-- The disjoint union of antidiagonals `Σ (n : ℕ), antidiagonal n` is equivalent to the product\n    `ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps] def sigma_antidiagonal_equiv_prod : (Σ (n : ℕ), antidiagonal n) ≃ ℕ × ℕ :=\n{ to_fun := λ x, x.2,\n  inv_fun := λ x, ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩,\n  left_inv :=\n    begin\n      rintros ⟨n, ⟨k, l⟩, h⟩,\n      rw mem_antidiagonal at h,\n      exact sigma.subtype_ext h rfl,\n    end,\n  right_inv := λ x, rfl }\n\nend equiv_prod\n\nend nat\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/finset/nat_antidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.758013693476674}}
{"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.partition_of_unity\nimport analysis.convex.combination\n\n/-!\n# Partition of unity and convex sets\n\nIn this file we prove the following lemma, see `exists_continuous_forall_mem_convex_of_local`. Let\n`X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a\ntopological real vector space. Let `t : X → set E` be a family of convex sets. Suppose that for each\npoint `x : X`, there exists a neighborhood `U ∈ 𝓝 X` and a function `g : X → E` that is continuous\non `U` and sends each `y ∈ U` to a point of `t y`. Then there exists a continuous map `g : C(X, E)`\nsuch that `g x ∈ t x` for all `x`.\n\nWe also formulate a useful corollary, see `exists_continuous_forall_mem_convex_of_local_const`, that\nassumes that local functions `g` are constants.\n\n## Tags\n\npartition of unity\n-/\n\nopen set function\nopen_locale big_operators topology\n\nvariables {ι X E : Type*} [topological_space X] [add_comm_group E] [module ℝ E]\n\nlemma partition_of_unity.finsum_smul_mem_convex {s : set X} (f : partition_of_unity ι X s)\n  {g : ι → X → E} {t : set E} {x : X} (hx : x ∈ s) (hg : ∀ i, f i x ≠ 0 → g i x ∈ t)\n  (ht : convex ℝ t) :\n  ∑ᶠ i, f i x • g i x ∈ t :=\nht.finsum_mem (λ i, f.nonneg _ _) (f.sum_eq_one hx) hg\n\nvariables [normal_space X] [paracompact_space X] [topological_space E] [has_continuous_add E]\n  [has_continuous_smul ℝ E] {t : X → set E}\n\n/-- Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be\na topological real vector space. Let `t : X → set E` be a family of convex sets. Suppose that for\neach point `x : X`, there exists a neighborhood `U ∈ 𝓝 X` and a function `g : X → E` that is\ncontinuous on `U` and sends each `y ∈ U` to a point of `t y`. Then there exists a continuous map\n`g : C(X, E)` such that `g x ∈ t x` for all `x`. See also\n`exists_continuous_forall_mem_convex_of_local_const`. -/\nlemma exists_continuous_forall_mem_convex_of_local (ht : ∀ x, convex ℝ (t x))\n  (H : ∀ x : X, ∃ (U ∈ 𝓝 x) (g : X → E), continuous_on g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃\n  g : C(X, E), ∀ x, g x ∈ t x :=\nbegin\n  choose U hU g hgc hgt using H,\n  obtain ⟨f, hf⟩ := partition_of_unity.exists_is_subordinate is_closed_univ (λ x, interior (U x))\n    (λ x, is_open_interior) (λ x hx, mem_Union.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩),\n  refine ⟨⟨λ x, ∑ᶠ i, f i x • g i x,\n    hf.continuous_finsum_smul (λ i, is_open_interior) $ λ i, (hgc i).mono interior_subset⟩,\n    λ x, f.finsum_smul_mem_convex (mem_univ x) (λ i hi, hgt _ _ _) (ht _)⟩,\n  exact interior_subset (hf _ $ subset_closure hi)\nend\n\n/-- Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be\na topological real vector space. Let `t : X → set E` be a family of convex sets. Suppose that for\neach point `x : X`, there exists a vector `c : E` that belongs to `t y` for all `y` in a\nneighborhood of `x`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all\n`x`. See also `exists_continuous_forall_mem_convex_of_local`. -/\nlemma exists_continuous_forall_mem_convex_of_local_const (ht : ∀ x, convex ℝ (t x))\n  (H : ∀ x : X, ∃ c : E, ∀ᶠ y in 𝓝 x, c ∈ t y) :\n  ∃ g : C(X, E), ∀ x, g x ∈ t x :=\nexists_continuous_forall_mem_convex_of_local ht $ λ x,\n  let ⟨c, hc⟩ := H x in ⟨_, hc, λ _, c, continuous_on_const, λ y, 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/analysis/convex/partition_of_unity.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193595, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7579941125424372}}
{"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 ∩ is symmetric\nlemma question1 (α : Type) (X Y : set α) : X ∩ Y = Y ∩ X :=\nbegin\n  \nend\n\n-- question 2 defs\ndef A := {x : ℝ | x ^ 2 < 3}\ndef B := {x : ℝ | ∃ n : ℤ, x = n ∧ x ^ 2 < 3}\ndef C := {x : ℝ | x ^ 3 < 3}\n\n-- Change _true to _false and put a ¬ 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 : ¬ (A ⊆ C) := ...\n\n-- Some of these are tricky for Lean beginners.\n\nlemma question2a_true : (1 : ℝ)/2 ∈ A ∩ B :=\nbegin\n  sorry\nend\n\nlemma question2b_true : (1 : ℝ)/2 ∈ A ∪ B :=\nbegin\n  sorry\nend\n\nlemma question2c_true : A ⊆ C :=\nbegin\n  sorry\nend\n\nlemma question2d_true : B ⊆ C :=\nbegin\n  sorry\nend\n\nlemma question2e_true : C ⊆ A ∪ B :=\nbegin\n  sorry\nend\n\nlemma question2f_true : (A ∩ B) ∪ C = (A ∪ B) ∩ C :=\nbegin\n  sorry\nend\n\n-- Q3 set-up\nvariables (X Y : Type)\nvariable (P : X → Prop)\nvariable (Q : X → Prop)\nvariable (R : X → Y → Prop)\n\n-- for Q3 you're going to have to change the right hand\n-- side of the ↔ in the statement\n-- of the lemma to the answer you think is correct.\n\nlemma question3a : ¬ (∀ x : X, P x ∧ ¬ Q x) ↔ true := -- change `true`!\nbegin\n  sorry\nend\n\nlemma question3b : ¬ (∃ x : X, (¬ P x) ∧ Q x) ↔ true := -- change `true`!\nbegin\n  sorry\nend\n\nlemma question3c : ¬ (∀ x : X, ∃ y : Y, R x y) ↔ true := -- change `true`!\nbegin\n  sorry\nend\n\nexample (f : ℝ → ℝ) (x : ℝ) :\n  ¬ (∀ ε : ℝ, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ y : ℝ, abs (y - x) < δ → abs (f y -f x) < ε )\n↔ -- 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 `¬` in front of it\nlemma question4a_true : ∀ x : ℝ, ∃ y : ℝ, x + y = 2 :=\nbegin\n  sorry\nend\n\nlemma question4b_true : ∃ y : ℝ, ∀ x : ℝ, 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 : ∃ x ∈ (∅ : set ℕ), 2 + 2 = 5 :=\nbegin\n  sorry\nend\n\nlemma question5b_true : ∀ x ∈ (∅ : set ℕ), 2 + 2 = 5 :=\nbegin\n  sorry\nend \n", "meta": {"author": "SzymonKubica", "repo": "Lean", "sha": "627bff2f001ba3f009c112c9332093e8de84863c", "save_path": "github-repos/lean/SzymonKubica-Lean", "path": "github-repos/lean/SzymonKubica-Lean/Lean-627bff2f001ba3f009c112c9332093e8de84863c/ProblemSheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7579687016508985}}
{"text": "/-\nFill in the sorry.\n\nsection\n  variable A : Type\n  variable f : A → A\n  variable P : A → Prop\n  variable  h : ∀ x, P x → P (f x)\n\n  -- Show the following:\n  example : ∀ y, P y → P (f (f y)) :=\n  sorry\nend\n-/\n\nsection\n  variable A : Type\n  variable f : A → A\n  variable P : A → Prop\n  variable  h : ∀ x, P x → P (f x)\n\n  -- Show the following:\n  example : ∀ y, P y → P (f (f y)) :=\n  assume y: A,\n  assume Py: P y,\n  have Pfy_to_Pffy: P(f(y)) → P(f(f(y))), from h(f(y)),\n  have Pfy: P(f(y)), from h(y)(Py),\n  show P(f(f(y))), from Pfy_to_Pffy(Pfy)\nend\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/chapter9/ex1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9324533051062238, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7579608234711848}}
{"text": "import Mathlib.Init.Data.Nat.Basic\nimport Mathlib.Tactic.Ring\nimport Mathlib.Init.Data.Nat.Lemmas\n\n\n/- Div : functions and theorems relative to the division and modulo operations -/\n\nnamespace Nat\n  def divisible (b a : Nat) : Prop := a % b = 0\n\n  -- TODO : more general version of this will be easy to implement with access to dec_trivial (currently not yet in mathlib4) -> https://github.com/leanprover-community/mathlib/blob/master/src/tactic/dec_trivial.lean\n  theorem mod_2_poss (a : Nat) : a % 2 = 0 ∨ a % 2 = 1 :=\n    mod_two_eq_zero_or_one a\n\n  theorem mod_3_poss (a : Nat) : a % 3 = 0 ∨ a % 3 = 1 ∨ a % 3 = 2 :=\n    -- copied from Mathlib.Init.Data.Nat.Lemmas (and modified from mod_two_eq_zero_or_one)\n    match a % 3, @Nat.mod_lt a 3 (by simp) with\n    | 0,   _ => Or.inl rfl\n    | 1,   _ => Or.inr (Or.inl rfl)\n    | 2,   _ => Or.inr (Or.inr rfl)\n  \n  theorem mod_4_poss (a : Nat) : a % 4 = 0 ∨ a % 4 = 1 ∨ a % 4 = 2 ∨ a % 4 = 3 :=\n    -- copied from Mathlib.Init.Data.Nat.Lemmas (and modified from mod_two_eq_zero_or_one)\n    match a % 4, @Nat.mod_lt a 4 (by simp) with\n    | 0,   _ => Or.inl rfl\n    | 1,   _ => Or.inr (Or.inl rfl)\n    | 2,   _ => Or.inr (Or.inr (Or.inl rfl))\n    | 3,   _ => Or.inr (Or.inr (Or.inr rfl))\n\n  theorem mod_5_poss (a : Nat) : a % 5 = 0 ∨ a % 5 = 1 ∨ a % 5 = 2 ∨ a % 5 = 3 ∨ a % 5 = 4 :=\n    -- copied from Mathlib.Init.Data.Nat.Lemmas (and modified from mod_two_eq_zero_or_one)\n    match a % 5, @Nat.mod_lt a 5 (by simp) with\n    | 0,   _ => Or.inl rfl\n    | 1,   _ => Or.inr (Or.inl rfl)\n    | 2,   _ => Or.inr (Or.inr (Or.inl rfl))\n    | 3,   _ => Or.inr (Or.inr (Or.inr (Or.inl rfl)))\n    | 4,   _ => Or.inr (Or.inr (Or.inr (Or.inr rfl)))\n\n  -- TODO : find equivalent in mathlib / prove it\n  axiom mod_rewrite {a b m : Nat} : a % b = m ↔ ∃ k, a = b * k + m\n\n  \n  theorem div_plus_div {a b c : Nat} : divisible c a → divisible c b → divisible c (a + b) := by\n    intros h₁ h₂\n    rw [divisible, mod_rewrite] at h₁ h₂\n    have ⟨n, hn⟩ := h₁\n    have ⟨m, hm⟩ := h₂\n    rw [hn, hm]\n    apply mod_rewrite.mpr\n    exact ⟨n+m, by ring⟩\n\nend Nat\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/LeanUtils/Div.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533013520765, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7579608056245754}}
{"text": "import .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 {α : Type} : list α → list α → list α\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 {α : Type} :\n  ∀as xs : list α, accurev as xs = reverse xs ++ as\n| as []        := by refl\n| as (x :: xs) := by simp [reverse, accurev, accurev_eq_reverse_append _ xs]\n\n/- 1.2. Derive the desired equation. -/\n\nlemma accurev_eq_reverse {α : Type} (xs : list α) :\n  accurev [] xs = reverse xs :=\nby simp [accurev_eq_reverse_append]\n\n/- 1.3. Prove the following property.\n\nHint: A one-line inductionless proof is possible. -/\n\nlemma accurev_accurev {α : Type} (xs : list α) :\n  accurev [] (accurev [] xs) = xs :=\nby simp [accurev_eq_reverse, reverse_reverse]\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 {α : Type} :\n      ∀as xs : list α, 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/- We perform the proof by structural induction on `xs`, generalizing `as`.\n\nCase `[]`: The goal is `accurev as [] = reverse [] ++ as`. The left-hand side\nis `as` by definition of `accurev`. The right-hand side is `as` by definition\nof `reverse` and `++`.\n\nCase `x :: xs`: The goal is `accurev as (x :: xs) = reverse (x :: xs) ++ as`.\nThe induction hypothesis is `∀as, accurev as xs = reverse xs ++ as`.\n\nLet us simplify the goal's left-hand side:\n\n      accurev as (x :: xs)\n    = accurev (x :: as) xs        -- by definition of `accurev`\n    = reverse xs ++ (x :: as)     -- by the induction hypothesis\n\nNow let us massage the right-hand side so that it matches the simplified\nleft-hand side:\n\n      reverse (x :: xs) ++ as\n    = (reverse xs ++ [x]) ++ as   -- by definition of `reverse`\n    = reverse xs ++ ([x] ++ as)   -- by associativity of `++`\n    = reverse xs ++ (x :: as)     -- by definition of `++`\n\nThe two sides are equal. QED -/\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 {α : Type} : ℕ → list α → list α\n| 0       xs        := xs\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := drop m xs\n\n/- Its relative `take` returns a list consisting of the the first `n` elements\nat the front of a list.\n\n2.1. Define `take`.\n\nTo avoid unpleasant surprises in the proofs, we recommend that you follow the\nsame recursion pattern as for `drop` above. -/\n\ndef take {α : Type} : ℕ → list α → list α\n| 0       _         := []\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := x :: take m xs\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 {α : Type} :\n  ∀n : ℕ, drop n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\n\n@[simp] lemma take_nil {α : Type} :\n  ∀n : ℕ, take n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\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\nThe first case is shown for `drop_drop`. Beware of the fact that there are three\nvariables in the `drop_drop` lemma (but only two arguments to `drop`).\n\nHint: The `refl` tactic might be useful in the third case of `drop_drop`. -/\n\nlemma drop_drop {α : Type} :\n  ∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) _ []        := by simp [drop]\n| (m + 1) n (x :: xs) :=\n  begin\n    simp [drop, drop_drop m n xs],\n    refl\n  end\n\nlemma take_take {α : Type} :\n  ∀(m : ℕ) (xs : list α), 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 {α : Type} :\n  ∀(n : ℕ) (xs : list α), 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/- ## Question 3: A Type of λ-Terms\n\n3.1. Define an inductive type corresponding to the untyped λ-terms, as given\nby the following context-free grammar:\n\n    term ::= 'var' string        -- variable (e.g., `x`)\n           | 'lam' string term   -- λ-expression (e.g., `λx, t`)\n           | 'app' term term     -- application (e.g., `t u`) -/\n\ninductive term : Type\n| var : string → term\n| lam : string → term → term\n| app : term → term → term\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 → string\n| (term.var s)   := s\n| (term.lam s t) := \"(λ\" ++ s ++ \", \" ++ term.repr t ++ \")\"\n| (term.app t u) := \"(\" ++ term.repr t ++ \" \" ++ term.repr u ++ \")\"\n\n@[instance] def term.has_repr : has_repr term :=\n{ repr := term.repr }\n\n/- 3.3. Test your textual representation: -/\n\n#eval (term.lam \"x\" (term.app (term.app (term.var \"y\") (term.var \"x\"))\n    (term.var \"x\")))\n  -- should print something like `(λx, ((y x) x))`\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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8705972633721708, "lm_q1q2_score": 0.7579396081445926}}
{"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 ℝ) (x : ℝ) := x ∈ upper_bounds S \n-- (Definition above deprecated? GT)\n\ndefinition is_lub (S : set ℝ) (x : ℝ) := is_upper_bound S x ∧ \n∀ y : ℝ, is_upper_bound S y → x ≤ y\n\ndefinition has_lub (S : set ℝ) := ∃ 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 ℝ) (H : has_lub S) : \n  (S ≠ ∅) ∧ (∃ x, is_upper_bound S x) :=\nbegin\n  cases H with b Hb,\n  split,\n  intro t,\n  have H1 : (b-1) ∈ upper_bounds S,\n  change ∀ x ∈ S, x ≤ (b-1),\n  by_contradiction hn,\n  push_neg at hn,\n  cases hn with d hd,\n  cases hd with y hy,\n  rw t at y,\n  exact y,\n  unfold is_lub at Hb,\n  have HH := Hb.2 (b-1) H1,\n  linarith,\n\n  existsi b,\n  exact Hb.1,\n\n\nend \n\nend xena -- hide\n\n\n\n\n\n\n\n/-\ncases 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) ∈ upper_bounds S,\n    change ∀ x ∈ S, x ≤ (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\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/level02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7579395949911129}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar el límite de la suma de dos sucesiones\n-- convergentes es la suma de los límites.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_convergencia\n\nvariables {s t : ℕ → ℝ} {a b c : ℝ}\n\nlemma converges_to_add\n  (cs : converges_to s a)\n  (ct : converges_to t b)\n  : converges_to (λ n, s n + t n) (a + b) :=\nbegin\n  intros ε εpos,\n  dsimp,\n  have ε2pos : 0 < ε / 2,\n    { linarith },\n  cases cs (ε / 2) ε2pos with Ns hs,\n  cases ct (ε / 2) ε2pos with Nt ht,\n  clear cs ct ε2pos εpos,\n  use max Ns Nt,\n  intros n hn,\n  have nNs : n ≥ Ns,\n    { exact le_of_max_le_left hn },\n  specialize hs n nNs,\n  have nNt : n ≥ Nt,\n    { exact le_of_max_le_right hn },\n  specialize ht n nNt,\n  clear hn nNs nNt Ns Nt,\n  calc abs (s n + t n - (a + b))\n           = abs ((s n - a) + (t n -  b))   : by { congr, ring }\n       ... ≤ abs (s n - a) + abs (t n -  b) : by apply abs_add\n       ... < ε / 2 + ε / 2                  : by linarith [hs, ht]\n       ... = ε                              : by apply add_halves,\nend\n\n-- Prueba\n-- ======\n\n/-\ns t : ℕ → ℝ,\na b : ℝ,\ncs : converges_to s a,\nct : converges_to t b\n⊢ converges_to (λ (n : ℕ), s n + t n) (a + b)\n  >> intros ε εpos,\nε : ℝ,\nεpos : ε > 0\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs ((λ (n : ℕ), s n + t n) n - (a + b)) < ε\n  >> dsimp,\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs (s n + t n - (a + b)) < ε\n  >> have ε2pos : 0 < ε / 2,\n| 2 goals\n| s t : ℕ → ℝ,\n| a b : ℝ,\n| cs : converges_to s a,\n| ct : converges_to t b,\n| ε : ℝ,\n| εpos : ε > 0\n| ⊢ 0 < ε / 2\n|   >>   { linarith },\ns t : ℕ → ℝ,\na b : ℝ,\ncs : converges_to s a,\nct : converges_to t b,\nε : ℝ,\nεpos : ε > 0,\nε2pos : 0 < ε / 2\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs (s n + t n - (a + b)) < ε\n  >> cases cs (ε / 2) ε2pos with Ns hs,\nε2pos : 0 < ε / 2,\nNs : ℕ,\nhs : ∀ (n : ℕ), n ≥ Ns → abs (s n - a) < ε / 2\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs (s n + t n - (a + b)) < ε\n  >> cases ct (ε / 2) ε2pos with Nt ht,\nNt : ℕ,\nht : ∀ (n : ℕ), n ≥ Nt → abs (t n - b) < ε / 2\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs (s n + t n - (a + b)) < ε\n  >> clear cs ct ε2pos εpos,\ns t : ℕ → ℝ,\na b ε : ℝ,\nNs : ℕ,\nhs : ∀ (n : ℕ), n ≥ Ns → abs (s n - a) < ε / 2,\nNt : ℕ,\nht : ∀ (n : ℕ), n ≥ Nt → abs (t n - b) < ε / 2\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs (s n + t n - (a + b)) < ε\n  >> use max Ns Nt,\n⊢ ∀ (n : ℕ), n ≥ max Ns Nt → abs (s n + t n - (a + b)) < ε\n  >> intros n hn,\nn : ℕ,\nhn : n ≥ max Ns Nt\n⊢ abs (s n + t n - (a + b)) < ε\n  >> have nNs : n ≥ Ns,\n| 2 goals\n| s t : ℕ → ℝ,\n| a b ε : ℝ,\n| Ns : ℕ,\n| hs : ∀ (n : ℕ), n ≥ Ns → abs (s n - a) < ε / 2,\n| Nt : ℕ,\n| ht : ∀ (n : ℕ), n ≥ Nt → abs (t n - b) < ε / 2,\n| n : ℕ,\n| hn : n ≥ max Ns Nt\n| ⊢ n ≥ Ns\n|   >>   { exact le_of_max_le_left hn },\nnNs : n ≥ Ns\n⊢ abs (s n + t n - (a + b)) < ε\n  >> specialize hs n nNs,\nhs : abs (s n - a) < ε / 2\n⊢ abs (s n + t n - (a + b)) < ε\n  >> have nNt : n ≥ Nt,\n| 2 goals\n| s t : ℕ → ℝ,\n| a b ε : ℝ,\n| Ns Nt : ℕ,\n| ht : ∀ (n : ℕ), n ≥ Nt → abs (t n - b) < ε / 2,\n| n : ℕ,\n| hn : n ≥ max Ns Nt,\n| nNs : n ≥ Ns,\n| hs : abs (s n - a) < ε / 2\n| ⊢ n ≥ Nt\n|   >>   { exact le_of_max_le_right hn },\ns t : ℕ → ℝ,\na b ε : ℝ,\nNs Nt : ℕ,\nht : ∀ (n : ℕ), n ≥ Nt → abs (t n - b) < ε / 2,\nn : ℕ,\nhn : n ≥ max Ns Nt,\nnNs : n ≥ Ns,\nhs : abs (s n - a) < ε / 2,\nnNt : n ≥ Nt\n⊢ abs (s n + t n - (a + b)) < ε\n  >> specialize ht n nNt,\nht : abs (t n - b) < ε / 2\n⊢ abs (s n + t n - (a + b)) < ε\n  >> clear hn nNs nNt Ns Nt,\ns t : ℕ → ℝ,\na b ε : ℝ,\nn : ℕ,\nhs : abs (s n - a) < ε / 2,\nht : abs (t n - b) < ε / 2\n⊢ abs (s n + t n - (a + b)) < ε\n  >> calc abs (s n + t n - (a + b))\n  >>          = abs ((s n - a) + (t n -  b))   : by { congr, ring }\n  >>      ... ≤ abs (s n - a) + abs (t n -  b) : by apply abs_add\n  >>      ... < ε / 2 + ε / 2                  : by linarith [hs, ht]\n  >>      ... = ε                              : by apply add_halves,\nno goals\n-/\n\n-- Comentario. Se han usado los lemas:\n-- + le_of_max_le_left : max a b ≤ c → a ≤ c\n-- + le_of_max_le_right : max a b ≤ c → b ≤ c\n-- + abs_add a b : abs (a + b) ≤ abs a + abs b\n-- + add_halves a : a / 2 + a / 2 = a\n\n-- Comprobación\n-- #check @le_of_max_le_left _ _ a b c\n-- #check @le_of_max_le_right _ _ a b c\n-- #check @abs_add _ _ a b\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/Convergencia_de_la_suma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.757856213869762}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen\n-/\nimport data.matrix.basic\n\n/-!\n# Trace of a matrix\n\nThis file defines the trace of a matrix, the map sending a matrix to the sum of its diagonal\nentries.\n\nSee also `linear_algebra.trace` for the trace of an endomorphism.\n\n## Tags\n\nmatrix, trace, diagonal\n\n-/\n\nopen_locale big_operators matrix\n\nnamespace matrix\n\nvariables {ι m n p : Type*} {α R S : Type*}\nvariables [fintype m] [fintype n] [fintype p]\n\nsection add_comm_monoid\nvariables [add_comm_monoid R]\n\n/-- The trace of a square matrix. For more bundled versions, see:\n* `matrix.trace_add_monoid_hom`\n* `matrix.trace_linear_map`\n-/\ndef trace (A : matrix n n R) : R := ∑ i, diag A i\n\nvariables (n R)\n@[simp] lemma trace_zero : trace (0 : matrix n n R) = 0 :=\n(finset.sum_const (0 : R)).trans $ smul_zero _\nvariables {n R}\n\n@[simp] lemma trace_add (A B : matrix n n R) : trace (A + B) = trace A + trace B :=\nfinset.sum_add_distrib\n\n@[simp] lemma trace_smul [monoid α] [distrib_mul_action α R] (r : α) (A : matrix n n R) :\n  trace (r • A) = r • trace A :=\nfinset.smul_sum.symm\n\n@[simp] lemma trace_transpose (A : matrix n n R) : trace Aᵀ = trace A := rfl\n\n@[simp] lemma trace_conj_transpose [star_add_monoid R] (A : matrix n n R) :\n  trace Aᴴ = star (trace A) :=\n(star_sum _ _).symm\n\nvariables (n α R)\n/-- `matrix.trace` as an `add_monoid_hom` -/\n@[simps]\ndef trace_add_monoid_hom : matrix n n R →+ R :=\n{ to_fun := trace, map_zero' := trace_zero n R, map_add' := trace_add }\n\n/-- `matrix.trace` as a `linear_map` -/\n@[simps]\ndef trace_linear_map [semiring α] [module α R] : matrix n n R →ₗ[α] R :=\n{ to_fun := trace, map_add' := trace_add, map_smul' := trace_smul }\nvariables {n α R}\n\n@[simp] lemma trace_list_sum (l : list (matrix n n R)) : trace l.sum = (l.map trace).sum :=\nmap_list_sum (trace_add_monoid_hom n R) l\n\n@[simp] lemma trace_multiset_sum (s : multiset (matrix n n R)) : trace s.sum = (s.map trace).sum :=\nmap_multiset_sum (trace_add_monoid_hom n R) s\n\n@[simp] lemma trace_sum (s : finset ι) (f : ι → matrix n n R) :\n  trace (∑ i in s, f i) = ∑ i in s, trace (f i) :=\nmap_sum (trace_add_monoid_hom n R) f s\n\nend add_comm_monoid\n\nsection add_comm_group\nvariables [add_comm_group R]\n\n@[simp] lemma trace_sub (A B : matrix n n R) : trace (A - B) = trace A - trace B :=\nfinset.sum_sub_distrib\n\n@[simp] lemma trace_neg (A : matrix n n R) : trace (-A) = -trace A :=\nfinset.sum_neg_distrib\n\nend add_comm_group\n\nsection one\nvariables [decidable_eq n] [add_comm_monoid_with_one R]\n\n@[simp] lemma trace_one : trace (1 : matrix n n R) = fintype.card n :=\nby simp_rw [trace, diag_one, pi.one_def, finset.sum_const, nsmul_one, finset.card_univ]\n\nend one\n\nsection mul\n\n@[simp] lemma trace_transpose_mul [add_comm_monoid R] [has_mul R]\n  (A : matrix m n R) (B : matrix n m R) : trace (Aᵀ ⬝ Bᵀ) = trace (A ⬝ B) := finset.sum_comm\n\nlemma trace_mul_comm [add_comm_monoid R] [comm_semigroup R] (A : matrix m n R) (B : matrix n m R) :\n  trace (A ⬝ B) = trace (B ⬝ A) :=\nby rw [←trace_transpose, ←trace_transpose_mul, transpose_mul]\n\nlemma trace_mul_cycle [non_unital_comm_semiring R]\n  (A : matrix m n R) (B : matrix n p R) (C : matrix p m R) :\n  trace (A ⬝ B ⬝ C) = trace (C ⬝ A ⬝ B) :=\nby rw [trace_mul_comm, matrix.mul_assoc]\n\nlemma trace_mul_cycle' [non_unital_comm_semiring R]\n  (A : matrix m n R) (B : matrix n p R) (C : matrix p m R) :\n  trace (A ⬝ (B ⬝ C)) = trace (C ⬝ (A ⬝ B)) :=\nby rw [←matrix.mul_assoc, trace_mul_comm]\n\n@[simp] lemma trace_col_mul_row [non_unital_non_assoc_semiring R] (a b : n → R) :\n  trace (col a ⬝ row b) = dot_product a b :=\nby simp [dot_product, trace]\n\nend mul\n\nsection fin\nvariables [add_comm_monoid R]\n\n/-! ### Special cases for `fin n`\n\nWhile `simp [fin.sum_univ_succ]` can prove these, we include them for convenience and consistency\nwith `matrix.det_fin_two` etc.\n-/\n\n@[simp] lemma trace_fin_zero (A : matrix (fin 0) (fin 0) R) : trace A = 0 :=\nrfl\n\nlemma trace_fin_one (A : matrix (fin 1) (fin 1) R) : trace A = A 0 0 :=\nadd_zero _\n\nlemma trace_fin_two (A : matrix (fin 2) (fin 2) R) : trace A = A 0 0 + A 1 1 :=\ncongr_arg ((+) _) (add_zero (A 1 1))\n\nlemma trace_fin_three (A : matrix (fin 3) (fin 3) R) : trace A = A 0 0 + A 1 1 + A 2 2 :=\nby { rw [← add_zero (A 2 2), add_assoc], refl }\n\nend fin\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/trace.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129513, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7577533618344192}}
{"text": "/-\n\n(X) We agree with sharing this code with the classmates.\n\nAlunos:\n - Lucas Emanuel Resck Domingues\n - Lucas Machado Moschen\n\nConsidere uma fonte de água inesgotável e duas garrafas, uma de 5 e\noutra de 7 litros, as quais não possuem quaisquer marcações que\npossibilitem medidas de volumes intermediários às suas respectivas\ncapacidades. O formato das mesmas também impede o uso de aparelhos de\nmedição indireta, assim como não há uma balança disponível. \n\nConsiderando essas condições, pergunta-se se é possível armazenar o\nvolume exato de 6 litros de água.\n\nÉ possível que você já conheça a solução deste problema ou mesmo saiba\nque, no caso geral de duas garrafas com capacidade que representem\nnúmeros primos entre si, pode-se medir qualquer volume inteiro até a\ncapacidade da maior garrafa. De qq forma, pretende-se construir\nprimeiro um conjunto de sentenças que representem o problema e somente\ndepois, via o uso do conceito de consequência lógica, verificar se é\npossível medir 6 litros nas condições estipuladas. Neste exercício,\npede-se apenas a formalização em FOL.\n\n-/\n\n/- How to represent something that changes in time? Now the bottles\nare filled up, byt later they can be empty. We can represent time in\nthe domain, through states, that change in time. Let's represent first\nstate as z (\"zero\") in the domain. Each element of the domain will\nhave a \"sucessor\". This is analogous to the Piano axioms.-/\n\nconstant T : Type\nconstant z : T\nconstant s : T → T\n\n/- Let's use G predicate to infer: G(t, x, y) means that exists a\npossibility that, in state t, the big bottle (the one with 7L) will\nhave x liters and the little bottle (5L) will have y liters. That is,\nthere is a sequence of steps where we can reach x and y liters at step\nt. For example (and for formalization), at step 0, we can state that\nboth bottles are empty: -/\n\nconstant G : T → ℕ → ℕ → Prop\nconstant start : G z 0 0\n\n/- Given a step, which bottle can be filled up in next step,\nindependently of how many liters it has and which step it is. -/\n\nconstant fill1 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) → (G (s t) 7 y)\nconstant fill2 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) → (G (s t) x 5)\n\n-- In the same way, they can be empty:\n\nconstant empty1 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) → (G (s t) 0 y)\nconstant empty2 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) → (G (s t) x 0)\n\n/- But how to tranfer water between these bottles? We have to\ncondition in the volume of the bottles at step t, because one may be\nfilled up or the other may become empty: -/\n\nconstant transfer1 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) ∧ (y ≥ 7 - x) → (G (s t) 7 (y - (7 - x)))\nconstant transfer2 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) ∧ (y < 7 - x) → (G (s t) (x + y) 0)\n\nconstant transfer3 : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) ∧ (x ≥ 5 - y) → (G (s t) (x - (5 - y)) 5)\nconstant transfer4x : ∀ t : T, ∀ x : ℕ, ∀ y : ℕ, (G t x y) ∧ (x < 5 - y) → (G (s t) 0 (x + y))\n\n/- What was asked to prove is if it's possible to reach 6L with this\nprocess. -/\n\ntheorem sixLiters : ∃ t : T, (G t 6 0) := sorry\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 4/garrafas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240860523328, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7577520092428742}}
{"text": "-- Inverso_del_inverso_en_grupos.lean\n-- Inverso del inverso en grupos\n-- José A. Alonso Jiménez\n-- Sevilla, 7 de julio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Sea G un grupo y a ∈ G. Demostrar que\n--    (a⁻¹)⁻¹ = a\n-- ---------------------------------------------------------------------\n\nimport algebra.group.basic\n\nuniverse  u\nvariables {G : Type u} [group G]\nvariables {a b : G}\n\n-- 1ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a :=\ncalc (a⁻¹)⁻¹\n     = (a⁻¹)⁻¹ * 1         : (mul_one (a⁻¹)⁻¹).symm\n ... = (a⁻¹)⁻¹ * (a⁻¹ * a) : congr_arg ((*) (a⁻¹)⁻¹) (inv_mul_self a).symm\n ... = ((a⁻¹)⁻¹ * a⁻¹) * a : (mul_assoc _ _ _).symm\n ... = 1 * a               : congr_arg (* a) (inv_mul_self a⁻¹)\n ... = a                   : one_mul a\n\n-- 2ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a :=\ncalc (a⁻¹)⁻¹\n     = (a⁻¹)⁻¹ * 1         : by simp only [mul_one]\n ... = (a⁻¹)⁻¹ * (a⁻¹ * a) : by simp only [inv_mul_self]\n ... = ((a⁻¹)⁻¹ * a⁻¹) * a : by simp only [mul_assoc]\n ... = 1 * a               : by simp only [inv_mul_self]\n ... = a                   : by simp only [one_mul]\n\n-- 3ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a :=\ncalc (a⁻¹)⁻¹\n     = (a⁻¹)⁻¹ * 1         : by simp\n ... = (a⁻¹)⁻¹ * (a⁻¹ * a) : by simp\n ... = ((a⁻¹)⁻¹ * a⁻¹) * a : by simp\n ... = 1 * a               : by simp\n ... = a                   : by simp\n\n-- 4ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a :=\nbegin\n  apply mul_eq_one_iff_inv_eq.mp,\n  exact mul_left_inv a,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a :=\nmul_eq_one_iff_inv_eq.mp (mul_left_inv a)\n\n-- 6ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a:=\ninv_inv a\n\n-- 7ª demostración\n-- ===============\n\nexample : (a⁻¹)⁻¹ = a:=\nby simp\n\n\n-- Referencia\n-- ==========\n\n-- Propiedad 3.20 del libro \"Abstract algebra: Theory and applications\"\n-- de Thomas W. Judson.\n-- http://abstract.ups.edu/download/aata-20200730.pdf#page=49\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_inverso_en_grupos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7577520007083836}}
{"text": "-- Formula_de_Gauss_de_la_suma.lean\n-- Fórmula de Gauss de la suma\n-- José A. Alonso Jiménez\n-- Sevilla, 24 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- La fórmula de Gauss para la suma de los primeros números naturales es\n--    0 + 1 + 2 + ... + (n-1) = n(n-1)/2\n--\n-- En un ejercicio anterior https://bit.ly/2Xu3IKh se ha demostrado\n-- dicha fórmula por inducción. Otra forma de demostrarla, sin usar\n-- inducción, es la siguiente: La suma se puede escribir de dos maneras\n--    S = 0     + 1     + 2     + ... + (n-3) + (n-2) + (n-1)\n--    S = (n-1) + (n-2) + (n-3) + ... + 2     + 1     + 0\n-- Al sumar, se observa que cada par de números de la misma columna da\n-- como suma (n-1), y puesto que hay n columnas en total, se sigue\n--    2S = n(n-1)\n-- lo que prueba la fórmula.\n--\n-- Demostrar la fórmula de Gauss siguiendo el procedimiento anterior.\n-- ---------------------------------------------------------------------\n\nimport algebra.big_operators.basic\nimport algebra.big_operators.intervals\n\nopen_locale big_operators\nopen finset nat\n\nvariables (n i : ℕ)\n\n-- Lema auxiliar\n-- =============\n\n-- Se usará el siguiente lema auxiliar del que se presentan distintas\n-- demostraciones.\n\n-- 1ª demostración del lema auxiliar\nexample : ∀ x, x ∈ range n → x + (n - 1 - x) = n - 1 :=\nbegin\n  intros x hx,\n  replace hx : x < n := mem_range.1 hx,\n  replace hx : x ≤ n - 1 := le_pred_of_lt hx,\n  exact nat.add_sub_of_le hx,\nend\n\n-- 2ª demostración del lema auxiliar\nexample : ∀ x, x ∈ range n → x + (n - 1 - x) = n - 1 :=\nbegin\n  intros x hx,\n  exact nat.add_sub_of_le (le_pred_of_lt (mem_range.1 hx)),\nend\n\n-- 3ª demostración del lema auxiliar\nlemma auxiliar : ∀ x, x ∈ range n → x + (n - 1 - x) = n - 1 :=\nλ x hx, nat.add_sub_of_le (le_pred_of_lt (mem_range.1 hx))\n\n-- Lema principal\n-- ==============\n\n-- 1ª demostración\nexample :\n  (∑ i in range n, i) * 2 = n * (n - 1) :=\ncalc (∑ i in range n, i) * 2\n     = (∑ i in range n, i) + (∑ i in range n, i)\n         : mul_two _\n ... = (∑ i in range n, i) + (∑ i in range n, (n - 1 - i))\n         : congr_arg2 (+) rfl (sum_range_reflect id n).symm\n ... = ∑ i in range n, (i + (n - 1 - i))\n         : sum_add_distrib.symm\n ... = ∑ i in range n, (n - 1)\n         : sum_congr rfl (auxiliar n)\n ... = card (range n) • (n - 1)\n         : sum_const (n - 1)\n ... = card (range n) * (n - 1)\n         : nat.nsmul_eq_mul _ _\n ... = n * (n - 1)\n         : congr_arg2 (*) (card_range n) rfl\n\n-- 2ª demostración\nexample :\n  (∑ i in range n, i) * 2 = n * (n - 1) :=\ncalc (∑ i in range n, i) * 2\n     = (∑ i in range n, i) + (∑ i in range n, (n - 1 - i))\n         : by rw [sum_range_reflect (λ i, i) n, mul_two]\n ... = ∑ i in range n, (i + (n - 1 - i))\n         : sum_add_distrib.symm\n ... = ∑ i in range n, (n - 1)\n         : sum_congr rfl (auxiliar n)\n ... = n * (n - 1)\n         : by rw [sum_const, card_range, nat.nsmul_eq_mul]\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Formula_de_Gauss_de_la_suma.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264638, "lm_q2_score": 0.875787001374006, "lm_q1q2_score": 0.7577519987094968}}
{"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\nFor the convolution product on `finsupp` when the domain has a binary operation,\nsee the type synonyms `add_monoid_algebra`\n(which is in turn used to define `polynomial` and `mv_polynomial`)\nand `monoid_algebra`.\n-/\n\nnoncomputable theory\nopen_locale classical\n\nopen finset\n\nuniverses u₁ u₂ u₃ u₄ u₅\nvariables {α : Type u₁} {β : Type u₂} {γ : Type u₃} {δ : Type u₄} {ι : Type u₅}\n\nnamespace finsupp\n\n/-! ### Declarations about the pointwise product on `finsupp`s -/\n\nsection\nvariables [mul_zero_class β]\n\n/-- The product of `f g : α →₀ β` is the finitely supported function\n  whose value at `a` is `f a * g a`. -/\ninstance : has_mul (α →₀ β) := ⟨zip_with (*) (mul_zero 0)⟩\n\n@[simp] lemma mul_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ * g₂) a = g₁ a * g₂ a :=\nrfl\n\nlemma support_mul {g₁ g₂ : α →₀ β} : (g₁ * g₂).support ⊆ g₁.support ∩ g₂.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 ←not_or_distrib,\n  intro w,\n  apply h,\n  cases w; { rw w, simp },\nend\n\ninstance : mul_zero_class (α →₀ β) :=\n{ zero      := 0,\n  mul       := (*),\n  mul_zero  := λ f, by { ext, simp only [mul_apply, zero_apply, mul_zero], },\n  zero_mul  := λ f, by { ext, simp only [mul_apply, zero_apply, zero_mul], }, }\n\nend\n\ninstance [semigroup_with_zero β] : semigroup_with_zero (α →₀ β) :=\n{ mul       := (*),\n  mul_assoc := λ f g h, by { ext, simp only [mul_apply, mul_assoc], },\n  ..(infer_instance : mul_zero_class (α →₀ β)) }\n\ninstance [non_unital_non_assoc_semiring β] : non_unital_non_assoc_semiring (α →₀ β) :=\n{ left_distrib := λ f g h, by { ext, simp only [mul_apply, add_apply, left_distrib] {proj := ff} },\n  right_distrib := λ f g h,\n    by { ext, simp only [mul_apply, add_apply, right_distrib] {proj := ff} },\n  ..(infer_instance : mul_zero_class (α →₀ β)),\n  ..(infer_instance : add_comm_monoid (α →₀ β)) }\n\ninstance [non_unital_semiring β] : non_unital_semiring (α →₀ β) :=\n{ ..(infer_instance : semigroup (α →₀ β)),\n  ..(infer_instance : non_unital_non_assoc_semiring (α →₀ β)) }\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/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7577100203630576}}
{"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 ∧ 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 ∨ 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 ∧ (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\nnamespace hidden \n\n-- review -- prod abstract data type!\n\n\n-- be sure you fully understand this type definition\ninductive prod (α β : Type) : Type\n| mk (a : α) (b : β) : 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 {α β : Type} : prod α β → α \n| (prod.mk a b) := a \n\n-- the second, or right, projection function\ndef snd {α β : Type} : prod α β → β  \n| (prod.mk a b) := b \n\n-- and a function that from one pair derives its swap\ndef swap  {α β : Type} : prod α β → prod β α\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 ∧ Q\ndef and_elim_left := P ∧ Q >> P\ndef and_elim_right := P ∧ 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 ∧ 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, ⟨p, q⟩, of P ∧ Q.\nThat's the and introduction rule. Similarly, if we have \na proof (pair!), ⟨p, q⟩, 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\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 → 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 → 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 ∧ 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 ∧ 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\n-- We now see that pf1 is basically a pair of proofs\n#reduce pf1\n\n\n\n/- OR\n\nWe also formalize the logical connective, ∨, as an \ninductive type with two (logical) type arguments,\nP and Q (two propositions). The both ∧ and ∨ 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 ∧ Q, we need proofs of both\nP and of Q. To build a proof of P ∨ 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 ∨ Q\ndef or_intro_right := Q >> P ∨ Q\ndef or_elim := P ∨ 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| inr {} (q : Q) : or   -- P is implicit\n\n\n-- example, proof of 0=0 ∨ 1=0\nexample : or (eq 0 0) (eq 1 0) :=\nor.inl (eq.refl 0)\n\n#check @or.elim\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.\nQ: What rule of reasoning apply?\nA: The \"and\" introduction and elimination rules.\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.\nQ: So what remains to be done? \nA: It will now suffice to produce a proof of 1=1 and one of 2=2.\nQ: How to prove 1=1? \nA: By the reflexive property of equality. \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 ∨ 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 : ℕ := 1\nexample : ℕ := 1\n\n\n\n\n/-\nNEXT UP: ∀, → \n-/\n\n/-\n************************************************************\nUniversal generalizations. Propositions starting with forall.\n************************************************************\n-/\n\n\n/-\nIntroduction rule: To prove \"∀ (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 ∀ introduction rule of natural deduction.\n-/\nexample : ∀ (n : ℕ), or (n = 0) (n ≠ 0) :=\n  λ (n : ℕ),\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 ≠ 0.\n-/\n\n\n/-\nProve that for any propositions, P and Q, P ∧ Q → P ∨ Q\n-/\n\ndef aProp := ∀ (P Q : Prop), and P Q → 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 → or P Q. To prove this is\nto prove an implication. We do this in the same way we prove\na ∀: 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  λ (P Q : Prop),\n    λ (pq : and P Q),\n      or.inl (and.elim_left pq)\n\nlemma and_imp_or_2  : aProp := \n  λ (P Q : Prop),\n    λ (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\n\n/-\nProve that the \"and\" connective is commutative.\n-/\n\ntheorem and_commutes : ∀ {P Q : Prop}, and P Q → and Q P :=\nλ (P Q : Prop), \n  λ (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 ∧ Q → Q ∧ P. Suppose we have a proof,\npq, of P ∧ 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 our proof, pq, of P ∧ Q.\n-/\n\n/-\nIf a proof of a ∀ or → 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 ∀ and →. If you're given a \nproof, pf, of either ∀ (p : P), Q, or of P → 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/-\nWe now use the elimination rule for ∀/→ 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 ∀ 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 → 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 → 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 : ∀ {P Q : Prop}, (P → Q) → P → Q :=\nλ (P Q : Prop),\n  λ (p2q : P → Q),\n    λ (p : P),\n      p2q p       ---<<< apply proof of P→Q to proof of P!\n\n\n/--- TODAY ---/\n\n/-\nPropositions that use ¬\n-/\n\n/-\nSuppose you want to prove ¬P. 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¬ P ==== P → false\n-/\n\nexample : 0 ≠ 1 := \n/- ¬ (0 = 1) -/\n/- (0 = 1) → false -/\nλ (h : 0 = 1), \n  match h with /- NO CASES! -/ end\n\ntheorem mt : ∀ {P Q}, (P → Q) → (¬Q → ¬P) :=\nλ P Q,\n  λ (h : P → Q),\n    λ (nq : ¬Q),\n      λ (p : P),\n       nq (h p)\n\ntheorem non_contradiction: ∀ (P : Prop), ¬ (P ∧ ¬ P) := \n  λ P,                    -- forall introduction \n    λ (h : P ∧ ¬P),       -- 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 : ∀ (n : ℕ), or (n = 0) (n ≠ 0) :=\nλ (n : ℕ),\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 ∃ \n-/\n\nexample : ∃ n, n = 0 := exists.intro 0 (eq.refl 0)\n\nexample : ∃ n, n^2 = 25 := exists.intro 5 rfl\n\nexample : ∃ x : nat, ∃ y: nat, ∃ z : ℕ, x^2 +y^2 = z^2 := \nexists.intro 3 \n  (exists.intro 4 \n    (exists.intro 5 (rfl)))\n\n/-\nPropositions that use both ∃ and ∀  \n-/\n\n\n\n/- Still to do:\n\ndef iff_intro := (P >> Q) >> (Q >> P) >> (P ↔ Q)\ndef iff_intro' := (P >> Q) ∧ (Q >> P) >> (P ↔ Q)\ndef iff_elim_left := (P ↔ Q) >> (P >> Q)\ndef iff_elim_right := (P ↔ Q) >> (Q >> P)\ndef syllogism := (P >> Q) >> (Q >> R) >> (P >> R)\ndef modus_tollens := (P >> Q) >> (¬ Q >> ¬ P)\ndef neg_elim := (¬ ¬ P) >> P         -- not a constructive rule\ndef excluded_middle := P ∨ (¬ P)     -- not a constructive rule\ndef neg_intro := (P >> pFalse) >> (¬ P)\ndef true_intro : pExp := pTrue\ndef false_elim := pFalse >> P\n-/\n\n\nend hidden", "meta": {"author": "kevinsullivan", "repo": "dm.s20", "sha": "6f90ecb3881c602cdd1e3f12aad458bcdabd250a", "save_path": "github-repos/lean/kevinsullivan-dm.s20", "path": "github-repos/lean/kevinsullivan-dm.s20/dm.s20-6f90ecb3881c602cdd1e3f12aad458bcdabd250a/instructor/predicate_logic/rules_of_reasoning.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8152324960856177, "lm_q1q2_score": 0.7577100187697148}}
{"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.normal\n\n/-\n\n# Normal extensions\n\nNormal extensions are splitting fields. They play a role in Galois theory\nbecause they correspond to normal subgroups via the fundamental theorem.\nIn Lean, normal implies algebraic.\n\nSay F/E is an extension of fields\n\n-/\n\nvariables (E F : Type) [field E] [field F] [algebra E F]\n\nsection is_normal\n\n-- Say furthermore F/E is normal\n\nvariable [normal E F]\n\n-- Then F/E is algebraic\n\nexample (f : F) : is_algebraic E f := normal.is_algebraic infer_instance f\n\n-- and all min polys split\n\nopen polynomial\n\nexample (f : F) : splits (algebra_map E F) (minpoly E f) := normal.splits infer_instance f\n\nend is_normal\n\n-- A finite extension is normal iff it's the splitting field of a polynomial\n\nopen_locale polynomial\nopen polynomial\n\nexample [finite_dimensional E F] : normal E F ↔ ∃ p : E[X], is_splitting_field E F p :=\n⟨λ h, by exactI normal.exists_is_splitting_field E F, λ ⟨p, hp⟩, by exactI normal.of_is_splitting_field p⟩\n\n/- \n\nNote that in that proof I had to use `by exactI` which jumps into tactic mode, resets the instance\ncache (because I've just `intro`ed something which should be in it but isn't), and jumps back\ninto term mode.\n\nPS the proof of `normal.of_is_splitting_field` is a 60 line monster.\n\n## Normal closures\n\nSay E ⊆ F ⊆ Ω is a tower of field extensions. The normal closure of F/E in Ω is naturally a subfield of\nΩ containing `F`, and there's a special structure for this: `intermediate_field F Ω`, which we'll\nsee in the fundamental theorem. \n\n-/\n\nnoncomputable theory\n\n-- Say E ⊆ F ⊆ Ω\nvariables (Ω : Type) [field Ω] [algebra E Ω] [algebra F Ω] [is_scalar_tower E F Ω] \n\nexample : intermediate_field F Ω := normal_closure E F Ω\n\n-- Note that `normal_closure E F Ω` is a term (of type `intermediate_field F Ω`) but it has a coercion\n-- to a type, and that type has a field structure and is normal over `E` if `Ω/E` is normal\n\nexample [normal E Ω] : normal E (normal_closure E F Ω) := normal_closure.normal E F Ω\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/sheet4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404038127071, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7577100141045613}}
{"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 linear_algebra.matrix.spectrum\nimport linear_algebra.quadratic_form.basic\n\n/-! # Positive Definite Matrices\n\nThis file defines positive definite matrices and connects this notion to positive definiteness of\nquadratic forms.\n\n## Main definition\n\n * `matrix.pos_def` : a matrix `M : matrix n n R` is positive definite if it is hermitian\n   and `xᴴMx` is greater than zero for all nonzero `x`.\n\n-/\n\nnamespace matrix\n\nvariables {R : Type*} [ordered_semiring R] [star_ring R] {n : Type*} [fintype n]\n\nopen_locale matrix\n\n/-- A matrix `M : matrix n n R` is positive definite if it is hermitian\n   and `xᴴMx` is greater than zero for all nonzero `x`. -/\ndef pos_def (M : matrix n n R) :=\nM.is_hermitian ∧ ∀ x : n → R, x ≠ 0 → 0 < dot_product (star x) (M.mul_vec x)\n\nlemma pos_def_of_to_quadratic_form' [decidable_eq n] {M : matrix n n ℝ}\n  (hM : M.is_symm) (hMq : M.to_quadratic_form'.pos_def) :\n  M.pos_def :=\nbegin\n  refine ⟨hM, λ x hx, _⟩,\n  simp only [to_quadratic_form', quadratic_form.pos_def, bilin_form.to_quadratic_form_apply,\n    matrix.to_bilin'_apply'] at hMq,\n  apply hMq x hx,\nend\n\nlemma pos_def_to_quadratic_form' [decidable_eq n] {M : matrix n n ℝ} (hM : M.pos_def) :\n  M.to_quadratic_form'.pos_def :=\nbegin\n  intros x hx,\n  simp only [to_quadratic_form', bilin_form.to_quadratic_form_apply, matrix.to_bilin'_apply'],\n  apply hM.2 x hx,\nend\n\nend matrix\n\nnamespace quadratic_form\n\nvariables {n : Type*} [fintype n]\n\nlemma pos_def_of_to_matrix'\n  [decidable_eq n] {Q : quadratic_form ℝ (n → ℝ)} (hQ : Q.to_matrix'.pos_def) :\n  Q.pos_def :=\nbegin\n  rw [←to_quadratic_form_associated ℝ Q,\n      ←bilin_form.to_matrix'.left_inv ((associated_hom _) Q)],\n  apply matrix.pos_def_to_quadratic_form' hQ\nend\n\nlemma pos_def_to_matrix' [decidable_eq n] {Q : quadratic_form ℝ (n → ℝ)} (hQ : Q.pos_def) :\n  Q.to_matrix'.pos_def :=\nbegin\n  rw [←to_quadratic_form_associated ℝ Q,\n    ←bilin_form.to_matrix'.left_inv ((associated_hom _) Q)] at hQ,\n  apply matrix.pos_def_of_to_quadratic_form' (is_symm_to_matrix' Q) hQ,\nend\n\nend quadratic_form\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/pos_def.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.929440403812707, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7577100141045612}}
{"text": "/-\nIn this module, we define a numerical expression type and a parser for this type.\n-/\n\nimport .parsing\n\nnamespace exlean\n\ninductive nexpr\n| num : ℕ → nexpr\n| nadd : nexpr → nexpr → nexpr\n| nmul : nexpr → nexpr → nexpr\n\nopen nexpr\n\nexample : nexpr := num 10\n\nexample : nexpr := nmul (num 10) (num 20)\n\ndef nexpr_to_string : nexpr → string\n  | (num n) := to_string n\n  | (nadd a b) := \"(\" ++ (nexpr_to_string a) ++ \" + \" ++ (nexpr_to_string b) ++ \")\"\n  | (nmul a b) := \"(\" ++ (nexpr_to_string a) ++ \" × \" ++ (nexpr_to_string b) ++ \")\"\n\ninstance : has_repr nexpr := ⟨nexpr_to_string⟩\n\n#eval nadd (num 5) (nmul (num 10) (num 20))\n\n-- `eval_nexpr' t` evaluates the term `t : nexpr` to an integer.\ndef eval_nexpr' : nexpr → ℕ\n  | (num n) := n\n  | (nadd a b) := (eval_nexpr' a) + (eval_nexpr' b)\n  | (nmul a b) := (eval_nexpr' a) * (eval_nexpr' b)\n\nexample : eval_nexpr' (nmul (num 10) (num 20)) = 200 := rfl\n\n\n/-\nLet's parse this type\n-/\nopen parser\n\n/-\n`eval_nexpr p inp` parses the string `inp` using the parser `p` and returns either some natural\nnumber representing the parsed value or none if the parsing of `inp` failed.\n-/\ndef eval_nexpr : Parser nexpr → string → option ℕ\n  | (Parser.P p) inp := match p inp with\n                          | none := none\n                          | some (v,out) := eval_nexpr' v\n                        end\n\n-- `nump` parses natural number expressions.\nmeta def nump : Parser nexpr :=\n  do  n ← natural,\n      return (num n)\n\n#eval eval_nexpr nump \"123\" -- some 123\n\n#eval parse nump \"123 + 5\" -- some (123, \"+ 5\")\n\n#eval parse nump \"+ 5\" -- fail\n\n/-\nThe `old_school` parser has no support for order-of-precedence or parentheses.\n-/\nmeta def old_school : Parser nexpr :=\n  (do a ← nump,\n      symbol \"+\",\n      b ← old_school,\n      return (nadd a b)) <|>\n  (do a ← nump,\n      symbol \"*\",\n      b ← old_school,\n      return (nmul a b) ) <|> nump\n\n#eval parse old_school \"2 * 3 * 5\" -- some ((2 × (3 × 5)), \"\")\n\n#eval eval_nexpr old_school \"2 * 3 * 5\" -- some 30\n\n#eval parse old_school \"1 + 2 + 3 * 7 + 10\" -- some ((1 + (2 + (3 × (7 + 10)))), \"\")\n\n#eval eval_nexpr old_school \"1 + 2 + 3 * 7 + 10\" -- some 54\n\n#eval parse old_school \"7 * 8 + 2 + 3 * 7 + 10\"  -- some ((7 × (8 + (2 + (3 × (7 + 10))))), \"\")\n\n#eval eval_nexpr old_school \"7 * 8 + 2 + 3 * 7 + 10\" -- some 427\n\n/-\n`brackets_parser` improves `old_school` by introducing parentheses.\n-/\nmeta def brackets_parser : Parser nexpr :=\n  (do symbol \"(\",\n      xs ← brackets_parser,\n      symbol \")\",\n      (do symbol \"*\", ys ← brackets_parser, return (nmul xs ys)) <|>\n      (do symbol \"+\", ys ← brackets_parser, return (nadd xs ys)) <|>\n      return xs) <|> \n  (do a ← nump,\n      symbol \"+\",\n      b ← old_school,\n      return (nadd a b)) <|>\n  (do a ← nump,\n      symbol \"*\",\n      b ← old_school,\n      return (nmul a b) ) <|> nump\n\n#eval parse brackets_parser \"(1 + 2) + (3 * (7 + 5)) + 10\" -- some (((1 + 2) + ((3 × (7 + 5)) + 10)), \"\")\n\n#eval eval_nexpr brackets_parser \"(1 + 2) + (3 * (7 + 5)) + 10\" -- some 24\n\ninductive nexpr_index : Type\n  | nexpr_type : nexpr_index\n  | nterm_type : nexpr_index\n  | nfactor_type : nexpr_index\n\nopen nexpr_index\n\nmeta def nexpr_parser_aux : nexpr_index → Parser nexpr\n| nexpr_type := do  t ← nexpr_parser_aux nterm_type,\n                    (do symbol \"+\",\n                        e ← nexpr_parser_aux nexpr_type,\n                        return (nadd t e)) <|> return t\n| nterm_type := do  f ← nexpr_parser_aux nfactor_type,\n                    (do symbol \"*\",\n                        t ← nexpr_parser_aux nterm_type,\n                        return (nmul f t)) <|> return f\n| nfactor_type := (do symbol \"(\",\n                      e ← nexpr_parser_aux nexpr_type,\n                      symbol \")\",\n                      return e) <|> nump\n\nmeta def nexpr_parser : Parser nexpr := nexpr_parser_aux nexpr_type\n\n#eval eval_nexpr nexpr_parser  \"1 + 2 + 3 * 7 + 5 + 10\" -- 39\n\n#eval eval_nexpr nexpr_parser  \"1 + 2 + 3 * (7 + 5) + 10\" -- 49  \n\nend exlean", "meta": {"author": "gihanmarasingha", "repo": "exleanblog", "sha": "aa6dc06cb64376dc87ba680815b9d14a904ad2ff", "save_path": "github-repos/lean/gihanmarasingha-exleanblog", "path": "github-repos/lean/gihanmarasingha-exleanblog/exleanblog-aa6dc06cb64376dc87ba680815b9d14a904ad2ff/src/2021/06/nexpr.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7577100110327503}}
{"text": "import tactic \n\n/- \nTactics you may consider \n-intro\n-cases\n-exact\n-have\n-clear\n-/\n\nvariables P Q R :  Prop\n\ntheorem basic_logic : (P → Q) ∧ (Q → R) → (P → R) :=\nbegin\n    intros h,\n    have hpq : P → Q,\n    exact h.left,\n    have hqr : Q → 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 → Q) ∧ (Q → R) → (P → R) :=\nbegin\n    intros h,\n    cases h with hpq hqr,\n    intro hp,\n    exact (hqr (hpq (hp))),\nend\n\n\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/3_apply_exact/3.2_exact/ex5_exact_imp_trans.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7576977210320113}}
{"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 data.finsupp.basic\n\n/-!\n# Isomorphism between `free_abelian_group X` and `X →₀ ℤ`\n\nIn this file we construct the canonical isomorphism between `free_abelian_group X` and `X →₀ ℤ`.\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 →₀ ℤ`\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 →+ (X →₀ ℤ)`. -/\ndef free_abelian_group.to_finsupp : free_abelian_group X →+ (X →₀ ℤ) :=\nfree_abelian_group.lift $ λ x, finsupp.single x (1 : ℤ)\n\n/-- The group homomorphism `(X →₀ ℤ) →+ free_abelian_group X`. -/\ndef finsupp.to_free_abelian_group : (X →₀ ℤ) →+ free_abelian_group X :=\nfinsupp.lift_add_hom $ λ x, (smul_add_hom ℤ (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 ℤ (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 →₀ ℤ) :=\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 [← 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 →₀ ℤ) :\n  f.to_free_abelian_group.to_finsupp = f :=\nby rw [← 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 →₀ ℤ)`. -/\n@[simps]\ndef equiv_finsupp : free_abelian_group X ≃+ (X →₀ ℤ) :=\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\nvariable {X}\n\n/-- `coeff x` is the additive group homomorphism `free_abelian_group X →+ ℤ`\nthat sends `a` to the multiplicity of `x : X` in `a`. -/\ndef coeff (x : X) : free_abelian_group X →+ ℤ :=\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 ∈ a.support ↔ coeff x a ≠ 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 ∉ a.support ↔ 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) = ∅ :=\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 : ℤ) (h : k ≠ 0) (a : free_abelian_group X) :\n  support (k • 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 : ℕ) (h : k ≠ 0) (a : free_abelian_group X) :\n  support (k • 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)) ⊆ a.support ∪ 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": "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/free_abelian_group_finsupp.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7576977165342017}}
{"text": "-- Opuesto_de_cero.lean\n-- Si R es un anillo, entonces -0 = 0.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 8-septiembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si R es un anillo, entonces\n--    -0 = 0\n-- ----------------------------------------------------------------------\n\nimport algebra.ring\n\nvariables {R : Type*} [ring R]\n\n-- 1ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nbegin\n  have h : 0 - 0 = (-0 : R) := zero_sub 0,\n  calc (-0 : R)\n       = 0 - 0    : h.symm\n   ... = -(0 - 0) : (neg_sub (0 : R) 0).symm\n   ... = -(-0)    : congr_arg (λ x, -x) h\n   ... = 0        : neg_neg 0\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nbegin\n  have h : 0 - 0 = (-0 : R) := by rw zero_sub,\n  calc (-0 : R)\n       = 0 - 0    : by rw h\n   ... = -(0 - 0) : by rw neg_sub\n   ... = -(-0)    : by {congr; rw h}\n   ... = 0        : by rw neg_neg\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nby simpa only [zero_sub, neg_neg] using (neg_sub (0 : R) 0).symm\n\n-- 4ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nneg_zero\n\n-- 5ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nby simp\n\n-- 6ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nbegin\n  apply neg_eq_of_add_eq_zero_right,\n  rw add_zero,\nend\n\n-- 7ª demostración\n-- ===============\n\nexample : (-0 : R) = 0 :=\nneg_eq_of_add_eq_zero_right (add_zero 0)\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Opuesto_de_cero.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940975, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7576060999311065}}
{"text": "-- Conmutatividad_del_infimo.lean\n-- Si R es un retículo y x, y ∈ R, entonces x ⊓ y = y ⊓ x.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 12-octubre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Sea R un retículo. Demostrar que si x, y ∈ R, entonces\n--     x ⊓ y = y ⊓ x\n-- ----------------------------------------------------------------------\n\nimport order.lattice\n\nvariables {R : Type*} [lattice R]\nvariables x y z : R\n\n-- 1ª demostración\n-- ===============\n\nlemma aux1 : x ⊓ y ≤ y ⊓ x :=\nbegin\n  have h1 : x ⊓ y ≤ y,\n    by exact inf_le_right,\n  have h2 : x ⊓ y ≤ x,\n    by exact inf_le_left,\n  show x ⊓ y ≤ y ⊓ x,\n    by exact le_inf h1 h2,\nend\n\nexample : x ⊓ y = y ⊓ x :=\nbegin\n  have h1 : x ⊓ y ≤ y ⊓ x,\n    by exact aux1 x y,\n  have h2 : y ⊓ x ≤ x ⊓ y,\n    by exact aux1 y x,\n  show x ⊓ y = y ⊓ x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma aux2 : x ⊓ y ≤ y ⊓ x :=\nle_inf inf_le_right inf_le_left\n\nexample : x ⊓ y = y ⊓ x :=\nle_antisymm (aux2 x y) (aux2 y x)\n\n-- 3ª demostración\n-- ===============\n\nlemma aux3 : x ⊓ y ≤ y ⊓ x :=\nbegin\n  apply le_inf,\n  apply inf_le_right,\n  apply inf_le_left,\nend\n\nexample : x ⊓ y = y ⊓ x :=\nbegin\n  apply le_antisymm,\n  apply aux3,\n  apply aux3,\nend\n\n-- 4ª demostración\n-- ===============\n\nexample : x ⊓ y = y ⊓ x :=\nby apply le_antisymm; simp\n\n-- 5ª demostración\n-- ===============\n\nexample : x ⊓ y = y ⊓ x :=\ninf_comm\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_infimo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.757606090407785}}
{"text": "import tactic.basic\nimport tactic.linarith\nimport tactic.omega\nimport .ch06_logic\n\nopen nat (add_succ succ_add)\nopen list (\n  filter nil_append append_nil foldr cons_append\n  append_assoc length_append ne_nil_of_length_pos\n)\n\nopen basics (leb)\nopen induction (double double_add)\nopen logic (In in_app_iff eqb_eq eqb_neq)\n\nnamespace indprop\n\nvariables {α β γ : Type}\nvariables {P Q : Prop}\nvariables {a : α}\nvariables {n m o p : ℕ}\n\n/-\nInductive even : nat → Prop :=\n| ev_0 : even 0\n| ev_SS (n : nat) (H : even n) : even (S (S n)).\n-/\n\ninductive even : ℕ → Prop\n| ev_0 : even 0\n| ev_ss {n} (h : even n) : even (n + 2)\n\nopen even\n\n/-\nFail Inductive wrong_ev (n : nat) : Prop :=\n| wrong_ev_0 : wrong_ev 0\n| wrong_ev_SS : wrong_ev n → wrong_ev (S (S n)).\n(* ===> Error: Last occurrence of \"wrong_ev\" must have \"n\"\n        as 1st argument in \"wrong_ev 0\". *)\n-/\n\n-- inductive wrong_ev (n : ℕ) : Prop\n-- | wrong_ev_0 : wrong_ev 0\n-- | wrong_ev_ss : wrong_ev n → wrong_ev (succ (succ n))\n\n/-\n  Inductive even : nat → Prop :=\n  | ev_0 : even 0\n  | ev_SS : ∀n, even n → even (S (S n)).\n-/\n\ninductive even'' : ℕ → Prop\n| ev_0 : even'' 0\n| ev_ss : ∀n, even'' n → even'' (n + 2)\n\n/-\nTheorem ev_4 : even 4.\nProof. apply ev_SS. apply ev_SS. apply ev_0. Qed.\n-/\n\ntheorem even_four : even 4 :=\nbegin\n  apply ev_ss,\n  apply ev_ss,\n  exact ev_0,\nend\n\n/-\nTheorem ev_4' : even 4.\nProof. apply (ev_SS 2 (ev_SS 0 ev_0)). Qed.\n-/\n\ntheorem even_four' : even 4 := ev_ss $ ev_ss ev_0\n\n/-\nTheorem ev_plus4 : ∀n, even n → even (4 + n).\nProof.\n  intros n. simpl. intros Hn.\n  apply ev_SS. apply ev_SS. apply Hn.\nQed.\n-/\n\ntheorem even_add_four (h : even n) : even (n + 4) :=\nbegin\n  apply ev_ss,\n  apply ev_ss,\n  exact h,\nend\n\n/-\nTheorem ev_double : ∀n,\n  even (double n).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem even_double : even (double n) :=\nbegin\n  induction n with n ih,\n    apply ev_0,\n  apply ev_ss,\n  exact ih,\nend\n\n/-\nTheorem ev_inversion :\n  ∀(n : nat), even n →\n    (n = 0) ∨ (∃n', n = S (S n') ∧ even n').\nProof.\n  intros n E.\n  destruct E as [ | n' E'].\n  - (* E = ev_0 : even 0 *)\n    left. reflexivity.\n  - (* E = ev_SS n' E' : even (S (S n')) *)\n    right. ∃n'. split. reflexivity. apply E'.\nQed.\n-/\n\ntheorem even_inv (e : even n) : (n = 0) ∨ (∃n', n = n' + 2 ∧ even n') :=\nbegin\n  cases e with n' e',\n    left,\n    refl,\n  right,\n  use n',\n  split,\n    refl,\n  apply e',\nend\n\n/-\nTheorem ev_minus2 : ∀n,\n  even n → even (pred (pred n)).\nProof.\n  intros n E.\n  destruct E as [| n' E'].\n  - (* E = ev_0 *) simpl. apply ev_0.\n  - (* E = ev_SS n' E' *) simpl. apply E'.\nQed.\n-/\n\ntheorem even_sub_two (e : even n) : even (n - 2) :=\nbegin\n  cases e with n' e',\n    exact e,\n  exact e',\nend\n\n/-\nTheorem evSS_ev : ∀n,\n  even (S (S n)) → even n.\nProof.\n  intros n E.\n  destruct E as [| n' E'].\n  - (* E = ev_0. *)\n    (* We must prove that n is even from no assumptions! *)\nAbort.\n-/\n\n-- theorem evss_ev (h : even (n + 2)) : even n :=\n-- begin\n--   destruct h,\n--   sorry,\n-- end\n\n/-\nTheorem evSS_ev : ∀n, even (S (S n)) → even n.\nProof. intros n H. apply ev_inversion in H. destruct H.\n - discriminate H.\n - destruct H as [n' [Hnm Hev]]. injection Hnm.\n   intro Heq. rewrite Heq. apply Hev.\nQed.\n-/\n\ntheorem add_two_even (e : even (n + 2)) : even n :=\nbegin\n  replace e, exact even_inv e,\n  rcases e with ⟨⟨⟩⟩ | ⟨n', hn, he⟩,\n  injections with hn' heq,\n  rwa heq,\nend\n\n/-\nTheorem evSS_ev' : ∀n,\n  even (S (S n)) → even n.\nProof.\n  intros n E.\n  inversion E as [| n' E'].\n  (* We are in the E = ev_SS n' E' case now. *)\n  apply E'.\nQed.\n-/\n\ntheorem add_two_even' (e : even (n + 2)) : even n :=\nbegin\n  cases e with _ e',\n  exact e',\nend\n\n/-\nTheorem one_not_even : ¬even 1.\nProof.\n  intros H. apply ev_inversion in H.\n  destruct H as [ | [m [Hm _]]].\n  - discriminate H.\n  - discriminate Hm.\nQed.\n\nTheorem one_not_even' : ¬even 1.\n  intros H. inversion H. Qed.\n-/\n\n/-\nTODO: see if this is the right time to introduce by_contra\nas a slightly more readable version of intro for negated statements\n-/\ntheorem one_not_even : ¬even 1 :=\nbegin\n  by_contra h,\n  replace h, exact even_inv h,\n  rcases h with ⟨⟨⟩⟩ | ⟨_, ⟨⟩, _⟩,\nend\n\ntheorem one_not_even' : ¬even 1 := by rintro ⟨⟩\n\n/-\nTheorem SSSSev__even : ∀n,\n  even (S (S (S (S n)))) → even n.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem add_four_even (h : even (n + 4)) : even n :=\nbegin\n  apply add_two_even,\n  apply add_two_even,\n  exact h,\nend\n\n/-\nTheorem even5_nonsense :\n  even 5 → 2 + 2 = 9.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem even5_nonsense (h : even 5) : 2 + 2 = 9 :=\nbegin\n  replace h, exact add_four_even h,\n  cases h,\nend\n\n/-\nTODO: go back to tactics and use destruct?\n-/\n\n/-\nTheorem inversion_ex1 : ∀(n m o : nat),\n  [n; m] = [o; o] →\n  [n] = [m].\nProof.\n  intros n m o H. inversion H. reflexivity. Qed.\n\nTheorem inversion_ex2 : ∀(n : nat),\n  S n = O →\n  2 + 2 = 5.\nProof.\n  intros n contra. inversion contra. Qed.\n-/\n\n/- cases does not do injection in lean -/\n\ntheorem inversion_ex₁ (h : [n, m] = [o, o]) : [n] = [m] :=\nbegin\n  cases h,\n  injection h,\nend\n\ntheorem inversion_ex₂ (h : n + 1 = 0) : 2 + 2 = 5 := by cases h\n\n/- Lemma ev_even_firsttry : ∀n,\n  even n → ∃k, n = double k.\nProof.\n(* WORKED IN CLASS *)\n intros n E. inversion E as [| n' E'].\n  - (* E = ev_0 *)\n    ∃0. reflexivity.\n  - (* E = ev_SS n' E' *) simpl.\n    assert (I : (∃k', n' = double k') →\n                (∃k, S (S n') = double k)).\n    { intros [k' Hk']. rewrite Hk'. ∃(S k'). reflexivity. }\n    apply I. (* reduce the original goal to the new one *)\nAbort.\n-/\n\n-- lemma ev_even_firstry (e : even n): ∃k, n = double k :=\n-- begin\n--   cases e with n' e',\n--     exact ⟨0, rfl⟩,\n--   have i : (∃k', n' = double k') → (∃k, n' + 2 = double k),\n--     rintro ⟨k', hk'⟩,\n--     rw hk',\n--     exact ⟨k' + 1, rfl⟩,\n--   sorry,\n-- end\n\n/-\nLemma ev_even : ∀n,\n  even n → ∃k, n = double k.\nProof.\n  intros n E.\n  induction E as [|n' E' IH].\n  - (* E = ev_0 *)\n    ∃0. reflexivity.\n  - (* E = ev_SS n' E'\n       with IH : exists k', n' = double k' *)\n    destruct IH as [k' Hk'].\n    rewrite Hk'. ∃(S k'). reflexivity.\nQed.\n-/\n\nlemma even_even (e : even n) : ∃k, n = double k :=\nbegin\n  induction e with n' e' ih,\n    exact ⟨0, rfl⟩,\n  cases ih with k' hk',\n  rw hk',\n  exact ⟨k' + 1, rfl⟩,\nend\n\n/-\nTheorem ev_even_iff : ∀n,\n  even n ↔ ∃k, n = double k.\nProof.\n  intros n. split.\n  - (* -> *) apply ev_even.\n  - (* <- *) intros [k Hk]. rewrite Hk. apply ev_double.\nQed.\n-/\n\ntheorem even_iff_even : even n ↔ ∃k, n = double k :=\nbegin\n  split,\n    apply even_even,\n  rintro ⟨k, hk⟩,\n  rw hk,\n  apply even_double,\nend\n\n/-\nTheorem ev_sum : ∀n m, even n → even m → even (n + m).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem even_sum (hn : even n) (hm : even m) : even (n + m) :=\nbegin\n  induction hn with n' hn' ih,\n    rw add_comm,\n    exact hm,\n  rw [succ_add, succ_add],\n  exact ev_ss ih,\nend\n\n/-\nInductive even' : nat → Prop :=\n| even'_0 : even' 0\n| even'_2 : even' 2\n| even'_sum n m (Hn : even' n) (Hm : even' m) : even' (n + m).\n-/\n\ninductive even' : ℕ → Prop\n| even'_0 : even' 0\n| even'_2 : even' 2\n| even'_sum {n m} (hn : even' n) (hm : even' m) : even' (n + m)\n\nopen even'\n\n/-\nTheorem even'_ev : ∀n, even' n ↔ even n.\nProof.\n (* FILL IN HERE *) Admitted.\n-/\n\ntheorem even'_ev : even' n ↔ even n :=\nbegin\n  split,\n    intro h,\n    induction h with n' m' hn' hm' ihn ihm,\n        exact ev_0,\n      exact ev_ss ev_0,\n    exact even_sum ihn ihm,\n  intro h,\n  induction h with n' hn' ih,\n    exact even'_0,\n  exact even'_sum ih even'_2,\nend\n\n/-\nTheorem ev_ev__ev : ∀n m,\n  even (n+m) → even n → even m.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem even_add_even (hnm : even (n + m)) (hn : even n) : even m :=\nbegin\n  induction hn with n' hn' ih,\n    rwa zero_add at hnm,\n  rw [succ_add, succ_add] at hnm,\n  exact ih (add_two_even hnm),\nend\n\n/-\nTheorem ev_plus_plus : ∀n m p,\n  even (n+m) → even (n+p) → even (m+p).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/-\nTODO: is this a good spot to introduce ac_refl?\n-/\n\ntheorem even_add_add (hnm : even (n + m)) (hnp : even (n + p)) : even (m + p) :=\nbegin\n  have h₁, exact even_sum hnm hnp,\n  have : ((n + m) + (n + p)) = ((n + n) + (m + p)), ac_refl,\n  rw this at h₁,\n  have h₂ : even (n + n),\n    rw ←double_add,\n    apply even_double,\n  exact even_add_even h₁ h₂,\nend\n\n/-\nInductive le : nat → nat → Prop :=\n  | le_n n : le n n\n  | le_S n m (H : le n m) : le n (S m).\n\nNotation \"m ≤ n\" := (le m n).\n-/\n\ninductive le (n : ℕ) : ℕ → Prop\n| refl : le n\n| step {m} (h : le m) : le (m + 1)\n\nopen le\n\nlocal infix ≤ := le\n\n/-\nTheorem test_le1 :\n  3 ≤ 3.\nProof.\n  (* WORKED IN CLASS *)\n  apply le_n. Qed.\n\nTheorem test_le2 :\n  3 ≤ 6.\nProof.\n  (* WORKED IN CLASS *)\n  apply le_S. apply le_S. apply le_S. apply le_n. Qed.\n\nTheorem test_le3 :\n  (2 ≤ 1) → 2 + 2 = 5.\nProof.\n  (* WORKED IN CLASS *)\n  intros H. inversion H. inversion H2. Qed.\n-/\n\ntheorem test_le₁ : 3 ≤ 3 := refl\n\ntheorem test_le₂ : 3 ≤ 6 :=\nbegin\n  apply step,\n  apply step,\n  apply step,\n  exact refl,\nend\n\ntheorem test_le₃ (h : 2 ≤ 1) : 2 + 2 = 5 :=\nby rcases h with _ | ⟨_, _, ⟨⟩⟩\n\n/-\nDefinition lt (n m:nat) := le (S n) m.\n\nNotation \"m < n\" := (lt m n).\n-/\n\ndef lt (n m) := le (n + 1) m\n\nlocal infix < := lt\n\n/-\nInductive square_of : nat → nat → Prop :=\n  | sq n : square_of n (n * n).\n\nInductive next_nat : nat → nat → Prop :=\n  | nn n : next_nat n (S n).\n\nInductive next_even : nat → nat → Prop :=\n  | ne_1 n : even (S n) → next_even n (S n)\n  | ne_2 n (H : even (S (S n))) : next_even n (S (S n)).\n-/\n\ninductive square_of : ℕ → ℕ → Prop\n| sq (n : ℕ) : square_of n (n * n)\n\ninductive next_nat : ℕ → ℕ → Prop\n| nn (n : ℕ) : next_nat n (n + 1)\n\ninductive next_even : ℕ → ℕ → Prop\n| ne_1 {n} : even (n + 1) → next_even n (n + 1)\n| ne_2 {n} (h : even (n + 2)) : next_even n (n + 2)\n\ninductive total_relation : ℕ → ℕ → Prop\n| intro (n₁ n₂) : total_relation n₁ n₂\n\ninductive empty_relation : ℕ → ℕ → Prop\n\n/-\nLemma le_trans : ∀m n o, m ≤ n → n ≤ o → m ≤ o.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem O_le_n : ∀n,\n  0 ≤ n.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem n_le_m__Sn_le_Sm : ∀n m,\n  n ≤ m → S n ≤ S m.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem Sn_le_Sm__n_le_m : ∀n m,\n  S n ≤ S m → n ≤ m.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem le_plus_l : ∀a b,\n  a ≤ a + b.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem plus_lt : ∀n1 n2 m,\n  n1 + n2 < m →\n  n1 < m ∧ n2 < m.\nProof.\n unfold lt.\n (* FILL IN HERE *) Admitted.\n\nTheorem lt_S : ∀n m,\n  n < m →\n  n < S m.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem leb_complete : ∀n m,\n  n <=? m = true → n ≤ m.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma le_trans (hmn : m ≤ n) (hno : n ≤ o) : m ≤ o :=\nbegin\n  induction hno with o' hno' ih,\n    exact hmn,\n  exact step ih,\nend\n\ntheorem zero_le : 0 ≤ n :=\nbegin\n  induction n with n' ih,\n    exact refl,\n  exact step ih,\nend\n\n/-\nTODO: i used this earlier\n-/\ntheorem nat.succ_le_succ (h : n ≤ m) : n + 1 ≤ m + 1 :=\nbegin\n  induction h with m' h' ih,\n    exact refl,\n  exact step ih,\nend\n\n/-\nTODO: i used this earlier\n-/\ntheorem nat.le_of_succ_le_succ (h : n + 1 ≤ m + 1) : n ≤ m :=\nbegin\n  rcases h with _ | ⟨m, h⟩,\n    exact refl,\n  exact le_trans (step refl) h,\nend\n\ntheorem nat.le_add_right : n ≤ n + m :=\nbegin\n  induction m with m ih,\n    rw add_zero,\n    exact refl,\n  exact step ih,\nend\n\ntheorem add_lt (h : n + m < o) : n < o ∧ m < o :=\nbegin\n  have : ∀n m, n + 1 ≤ n + m + 1,\n    intros n m,\n    rw add_assoc,\n    rw add_comm m,\n    rw ←add_assoc,\n    exact nat.le_add_right,\n  split,\n    exact le_trans (this n m) h,\n  rw add_comm at h,\n  exact le_trans (this m n) h,\nend\n\ntheorem lt_lt_succ (h : n < m) : n < m + 1 := step h\n\ntheorem leb_complete (h : n ≤? m = tt) : n ≤ m :=\nbegin\n  induction n with n ih generalizing m,\n    exact zero_le,\n  cases m with m,\n    cases h,\n  exact nat.succ_le_succ (ih h),\nend\n\n/-\nTheorem leb_correct : ∀n m,\n  n ≤ m →\n  n <=? m = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem leb_correct (h : n ≤ m) : n ≤? m = tt :=\nbegin\n  induction m with m ih generalizing n,\n  cases h,\n    refl,\n  cases n,\n    refl,\n  exact ih (nat.le_of_succ_le_succ h),\nend\n\n/-\nTheorem leb_true_trans : ∀n m o,\n  n <=? m = true → m <=? o = true → n <=? o = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem leb_tt_trans (hnm : n ≤? m = tt) (hmo : m ≤? o = tt)\n  : n ≤? o = tt := leb_correct (le_trans (leb_complete hnm) (leb_complete hmo))\n\n/-\nTheorem leb_iff : ∀n m,\n  n <=? m = true ↔ n ≤ m.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/- if you didn't do the last section -/\n/- you're gonna have a bad time -/\n\ntheorem leb_iff : n ≤? m = tt ↔ n ≤ m := ⟨leb_complete, leb_correct⟩\n\n/-\nInductive R : nat → nat → nat → Prop :=\n   | c1 : R 0 0 0\n   | c2 m n o (H : R m n o) : R (S m) n (S o)\n   | c3 m n o (H : R m n o) : R m (S n) (S o)\n   | c4 m n o (H : R (S m) (S n) (S (S o))) : R m n o\n   | c5 m n o (H : R m n o) : R n m o.\n-/\n\ninductive R : ℕ → ℕ → ℕ → Prop\n| c₁ : R 0 0 0\n| c₂ {m n o} (h : R m n o) : R (m + 1) n (o + 1)\n| c₃ {m n o} (h : R m n o) : R m (n + 1) (o + 1)\n| c₄ {m n o} (h : R (m + 1) (n + 1) (o + 2)) : R m n o\n| c₅ {m n o} (h : R m n o) : R n m o\n\nopen R\n\n/-\nDefinition fR : nat → nat → nat\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n\nTheorem R_equiv_fR : ∀m n o, R m n o ↔ fR m n = o.\nProof.\n(* FILL IN HERE *) Admitted.\n-/\n\ndef fR := λ(m n : ℕ), m + n\n\n/-\nrecommended - tricky induction\nmake fun of coq destruction naming (for once)\n-/\n\nlemma add_eq_zero : ∀{m n}, m + n = 0 → m = 0 ∧ n = 0\n| 0 0 h := ⟨rfl, rfl⟩\n| (m + 1) n h :=\nbegin\n  rw succ_add at h,\n  cases h,\nend\n\n\ntheorem R_equiv_fR {m n o : ℕ} : R m n o ↔ fR m n = o :=\nbegin\n  split,\n    intro h,\n    induction h,\n    case c₁ : { refl },\n    case c₂ : m' n' o' h ih {\n      unfold fR at ih ⊢,\n      rw succ_add,\n      rw ih,\n    },\n    case c₃ : m' n' o' h ih {\n      unfold fR at ih ⊢,\n      have : m' + (n' + 1) = m' + n' + 1, refl,\n      rw this,\n      rw ih,\n    },\n    case c₄ : m' n' o' h ih {\n      unfold fR at ih ⊢,\n      have : m' + 1 + (n' + 1) = m' + n' + 1 + 1, ac_refl,\n      rw this at ih,\n      injections,\n    },\n    case c₅ : m' n' o' h ih {\n      unfold fR at ih ⊢,\n      rwa add_comm,\n    },\n  intro h,\n  unfold fR at h,\n  induction o with o ih generalizing m n,\n    have h, exact add_eq_zero h,\n    rw [h.left, h.right],\n    exact c₁,\n  cases m,\n    cases n,\n      cases h,\n    injection h with h,\n    exact c₃ (ih h),\n  rw succ_add at h,\n  injection h with h,\n  exact c₂ (ih h),\nend\n\n/-\nInductive subseq : list nat → list nat → Prop :=\n(* FILL IN HERE *)\n.\nTheorem subseq_refl : ∀(l : list nat), subseq l l.\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem subseq_app : ∀(l1 l2 l3 : list nat),\n  subseq l1 l2 →\n  subseq l1 (l2 ++ l3).\nProof.\n  (* FILL IN HERE *) Admitted.\n\nTheorem subseq_trans : ∀(l1 l2 l3 : list nat),\n  subseq l1 l2 →\n  subseq l2 l3 →\n  subseq l1 l3.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/-\nstarting generic since it's useful later\n-/\n\ninductive subseq : list α → list α → Prop\n| em : subseq [] []\n| cr {l₁ l₂} (a) (h : subseq l₁ l₂) : subseq l₁ (a::l₂)\n| cl {l₁ l₂} (a) (h : subseq l₁ l₂) : subseq (a::l₁) (a::l₂)\n\nopen subseq\n\ntheorem subseq_refl (l : list α) : subseq l l :=\nbegin\n  induction l with h t ih,\n    exact em,\n  exact cl h ih,\nend\n\ntheorem subseq_app (l₁ l₂ l₃ : list α) (h : subseq l₁ l₂)\n  : subseq l₁ (l₂ ++ l₃) :=\nbegin\n  induction h,\n  case em : {\n    rw nil_append,\n    induction l₃ with h t ih,\n      exact em,\n    exact cr h ih,\n  },\n  case cr : l₁' l₂' n h' ih { exact cr n ih },\n  case cl : l₁' l₂' n h' ih { exact cl n ih },\nend\n\ntheorem subseq_trans {l₁ l₂ l₃ : list α}\n  (h₁₂ : subseq l₁ l₂) (h₂₃ : subseq l₂ l₃) : subseq l₁ l₃ :=\nbegin\n  induction h₂₃ generalizing l₁,\n  case em : {\n    cases h₁₂,\n    exact em,\n  },\n  case cr : l₂' l₃' n h ih { exact cr n (ih h₁₂) },\n  case cl : l₂' l₃' n h ih {\n    cases h₁₂,\n    case cr : l₁' l₂' n h₁₂' { exact cr n (ih h₁₂') },\n    case cl : l₁' l₂' n h₁₂' { exact cl n (ih h₁₂') },\n  },\nend\n\n/-\nInductive R : nat → list nat → Prop :=\n  | c1 : R 0 []\n  | c2 : ∀n l, R n l → R (S n) (n :: l)\n  | c3 : ∀n l, R (S n) l → R n l.\n-/\n\ninductive R' : ℕ → list ℕ → Prop\n| c₁' : R' 0 []\n| c₂' : ∀{n l}, R' n l → R' (n + 1) (n :: l)\n| c₃' : ∀{n l}, R' (n + 1) l → R' n l\n\nopen R'\n\nexample : R' 2 [1, 0] :=\nbegin\n  apply c₂',\n  apply c₂',\n  exact c₁',\nend\n\nexample : R' 1 [1, 2, 1, 0] :=\nbegin\n  apply c₃',\n  apply c₂',\n  apply c₃',\n  apply c₃',\n  apply c₂',\n  apply c₂',\n  apply c₂',\n  apply c₁',\nend\n\n/-\nInductive reg_exp {T : Type} : Type :=\n  | EmptySet\n  | EmptyStr\n  | Char (t : T)\n  | App (r1 r2 : reg_exp)\n  | Union (r1 r2 : reg_exp)\n  | Star (r : reg_exp).\n-/\n\ninductive reg_exp : Type\n| EmptySet : reg_exp\n| EmptyStr : reg_exp\n| Char (a : α) : reg_exp\n| App (r₁ r₂ : reg_exp) : reg_exp\n| Union (r₁ r₂ : reg_exp) : reg_exp\n| Star (r : reg_exp) : reg_exp\n\nopen reg_exp\n\n/-\nInductive exp_match {T} : list T → reg_exp → Prop :=\n  | MEmpty : exp_match [] EmptyStr\n  | MChar x : exp_match [x] (Char x)\n  | MApp s1 re1 s2 re2\n             (H1 : exp_match s1 re1)\n             (H2 : exp_match s2 re2) :\n             exp_match (s1 ++ s2) (App re1 re2)\n  | MUnionL s1 re1 re2\n                (H1 : exp_match s1 re1) :\n                exp_match s1 (Union re1 re2)\n  | MUnionR re1 s2 re2\n                (H2 : exp_match s2 re2) :\n                exp_match s2 (Union re1 re2)\n  | MStar0 re : exp_match [] (Star re)\n  | MStarApp s1 s2 re\n                 (H1 : exp_match s1 re)\n                 (H2 : exp_match s2 (Star re)) :\n                 exp_match (s1 ++ s2) (Star re).\n-/\n\ninductive exp_match : list α → @reg_exp α → Prop\n| MEmpty : exp_match [] EmptyStr\n| MChar (a : α) : exp_match [a] (Char a)\n| MApp {s₁ re₁ s₂ re₂} (h₁ : exp_match s₁ re₁) (h₂ : exp_match s₂ re₂)\n  : exp_match (s₁ ++ s₂) (App re₁ re₂)\n| MUnionL {s₁ re₁} re₂ (h : exp_match s₁ re₁) : exp_match s₁ (Union re₁ re₂)\n| MUnionR re₁ {s₂ re₂} (h : exp_match s₂ re₂) : exp_match s₂ (Union re₁ re₂)\n| MStar0 (re : reg_exp) : exp_match [] (Star re)\n| MStarApp {s₁ s₂ re}\n  (h₁ : exp_match s₁ re)\n  (h₂ : exp_match s₂ (Star re))\n  : exp_match (s₁ ++ s₂) (Star re)\n\nopen exp_match\n\nvariables {s s₁ s₂ : list α}\nvariables {re re₀ re₁ re₂ : @reg_exp α}\n\n/-\nNotation \"s =~ re\" := (exp_match s re) (at level 80).\n-/\n\ninfix ` =~ `:35 := exp_match\n\n/-\nExample reg_exp_ex1 : [1] =~ Char 1.\nProof.\n  apply MChar.\nQed.\n\nExample reg_exp_ex2 : [1; 2] =~ App (Char 1) (Char 2).\nProof.\n  apply (MApp [1] _ [2]).\n  - apply MChar.\n  - apply MChar.\nQed.\n-/\n\nexample : [1] =~ Char 1 := MChar 1\n\nexample : [1, 2] =~ App (Char 1) (Char 2) := MApp (MChar 1) (MChar 2)\n\n/-\nExample reg_exp_ex3 : ¬([1; 2] =~ Char 1).\nProof.\n  intros H. inversion H.\nQed.\n-/\n\n/-\nTODO: lean can't make it to the remember section\nbefore needing generalize\n-/\n\nexample : ¬([1, 2] =~ Char 1) :=\nbegin\n  generalize heq : [1, 2] = s,\n  with_cases { rintro ⟨_⟩ },\n  rintro ⟨⟩,\nend\n\n/-\nFixpoint reg_exp_of_list {T} (l : list T) :=\n  match l with\n  | [] ⇒ EmptyStr\n  | x :: l' ⇒ App (Char x) (reg_exp_of_list l')\n  end.\n\nExample reg_exp_ex4 : [1; 2; 3] =~ reg_exp_of_list [1; 2; 3].\nProof.\n  simpl. apply (MApp [1]).\n  { apply MChar. }\n  apply (MApp [2]).\n  { apply MChar. }\n  apply (MApp [3]).\n  { apply MChar. }\n  apply MEmpty.\nQed.\n-/\n\ndef reg_exp_of_list : list α → @reg_exp α\n| [] := EmptyStr\n| (a::l) := App (Char a) (reg_exp_of_list l)\n\nexample : [1, 2, 3] =~ reg_exp_of_list [1, 2, 3] :=\nbegin\n  apply @MApp _ [1],\n    apply MChar,\n  apply @MApp _ [2],\n    apply MChar,\n  apply @MApp _ [3],\n    apply MChar,\n  apply MEmpty,\nend\n\n/-\nLemma MStar1 :\n  ∀T s (re : @reg_exp T) ,\n    s =~ re →\n    s =~ Star re.\nProof.\n  intros T s re H.\n  rewrite <- (app_nil_r _ s).\n  apply (MStarApp s [] re).\n  - apply H.\n  - apply MStar0.\nQed.\n-/\n\nlemma MStar₁ (h : s =~ re) : s =~ Star re :=\nbegin\n  rw ←append_nil s,\n  exact MStarApp h (MStar0 re),\nend\n\n/-\nLemma empty_is_empty : ∀T (s : list T),\n  ¬(s =~ EmptySet).\nProof.\n  (* FILL IN HERE *) Admitted.\n\nLemma MUnion' : ∀T (s : list T) (re1 re2 : @reg_exp T),\n  s =~ re1 ∨ s =~ re2 →\n  s =~ Union re1 re2.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma empty_is_empty : ¬(s =~ EmptySet) := by rintro ⟨⟩\n\nlemma MUnion' (h : s =~ re₁ ∨ s =~ re₂) : s =~ Union re₁ re₂ :=\nbegin\n  cases h,\n    exact MUnionL re₂ h,\n  exact MUnionR re₁ h,\nend\n\n/-\nLemma MStar' : ∀T (ss : list (list T)) (re : reg_exp),\n  (∀s, In s ss → s =~ re) →\n  fold app ss [] =~ Star re.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma MStar' (ss) (h : ∀{s : list α}, In s ss → s =~ re)\n  : ss.foldr append [] =~ Star re :=\nbegin\n  induction ss with s' ss ih,\n    exact MStar0 re,\n  apply MStarApp,\n    exact h (or.inl rfl),\n  apply ih,\n  intros s h',\n  exact h (or.inr h'),\nend\n\n/-\nLemma reg_exp_of_list_spec : ∀T (s1 s2 : list T),\n  s1 =~ reg_exp_of_list s2 ↔ s1 = s2.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma reg_exp_of_list_spec : s₁ =~ reg_exp_of_list s₂ ↔ s₁ = s₂ :=\nbegin\n  split,\n    intro h,\n    induction s₂ with a₂ s₂ ih₂ generalizing s₁,\n      cases h,\n      refl,\n    generalize heq : reg_exp_of_list (a₂::s₂) = re',\n    rw heq at h,\n    cases h,\n    case MEmpty { cases heq, },\n    case MChar : a { cases heq, },\n    case MApp : s₁ re₁ s₂' re₂ h₁ h₂ {\n      injection heq with h₁' h₂',\n      rw ←h₁' at h₁,\n      rw ←h₂' at h₂,\n      cases h₁,\n      unfold list.append,\n      congr,\n      exact ih₂ h₂,\n    },\n    case MUnionL : s₁ re₁ re₂ h { cases heq, },\n    case MUnionR : re₁ s₂' re₂ h { cases heq, },\n    case MStar0 : re { cases heq, },\n    case MStarApp : s₁ s₂' re { cases heq, },\n  intro h,\n  induction s₂ with a₂ s₂ ih₂ generalizing s₁,\n    rw h,\n    exact MEmpty,\n  rw h,\n  unfold reg_exp_of_list,\n  exact MApp (MChar a₂) (ih₂ rfl),\nend\n\n/-\nFixpoint re_chars {T} (re : reg_exp) : list T :=\n  match re with\n  | EmptySet ⇒ []\n  | EmptyStr ⇒ []\n  | Char x ⇒ [x]\n  | App re1 re2 ⇒ re_chars re1 ++ re_chars re2\n  | Union re1 re2 ⇒ re_chars re1 ++ re_chars re2\n  | Star re ⇒ re_chars re\n  end.\n-/\n\ndef re_chars : reg_exp → list α\n| EmptySet := []\n| EmptyStr := []\n| (Char a) := [a]\n| (App re₁ re₂) := re_chars re₁ ++ re_chars re₂\n| (Union re₁ re₂) := re_chars re₁ ++ re_chars re₂\n| (Star re) := re_chars re\n\n/-\nTheorem in_re_match : ∀T (s : list T) (re : reg_exp) (x : T),\n  s =~ re →\n  In x s →\n  In x (re_chars re).\nProof.\n  intros T s re x Hmatch Hin.\n  induction Hmatch\n    as [| x'\n        | s1 re1 s2 re2 Hmatch1 IH1 Hmatch2 IH2\n        | s1 re1 re2 Hmatch IH | re1 s2 re2 Hmatch IH\n        | re | s1 s2 re Hmatch1 IH1 Hmatch2 IH2].\n  (* WORKED IN CLASS *)\n  - (* MEmpty *)\n    apply Hin.\n  - (* MChar *)\n    apply Hin.\n  - simpl. rewrite In_app_iff in *.\n    destruct Hin as [Hin | Hin].\n    + (* In x s1 *)\n      left. apply (IH1 Hin).\n    + (* In x s2 *)\n      right. apply (IH2 Hin).\n  - (* MUnionL *)\n    simpl. rewrite In_app_iff.\n    left. apply (IH Hin).\n  - (* MUnionR *)\n    simpl. rewrite In_app_iff.\n    right. apply (IH Hin).\n  - (* MStar0 *)\n    destruct Hin.\n  - (* MStarApp *)\n    simpl. rewrite In_app_iff in Hin.\n    destruct Hin as [Hin | Hin].\n    + (* In x s1 *)\n      apply (IH1 Hin).\n    + (* In x s2 *)\n      apply (IH2 Hin).\nQed.\n-/\n\ntheorem in_re_match (hm : s =~ re) (hi : In a s) : In a (re_chars re) :=\nbegin\n  induction hm,\n  case MEmpty { apply hi, },\n  case MChar { apply hi, },\n  case MApp : s₁ re₁ s₂ re₂ h₁ h₂ ih₁ ih₂ {\n    unfold re_chars,\n    rw in_app_iff at *,\n    exact or.imp ih₁ ih₂ hi,\n  },\n  case MUnionL : s₁ re₁ re₂ h ih {\n    unfold re_chars,\n    rw in_app_iff,\n    exact or.inl (ih hi),\n  },\n  case MUnionR : s₁ re₁ re₂ h ih {\n    unfold re_chars,\n    rw in_app_iff,\n    exact or.inr (ih hi),\n  },\n  case MStar0 { cases hi, },\n  case MStarApp : s₁ s₂ re h₁ h₂ ih₁ ih₂ {\n    rw in_app_iff at hi,\n    cases hi,\n      exact ih₁ hi,\n    exact ih₂ hi,\n  }\nend\n\n/-\nFixpoint re_not_empty {T : Type} (re : @reg_exp T) : bool\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n\nLemma re_not_empty_correct : ∀T (re : @reg_exp T),\n  (∃s, s =~ re) ↔ re_not_empty re = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/- yep, the lemma found errors in my first two attempts -/\n\ndef re_not_empty : @reg_exp α → bool\n| EmptySet := ff\n| EmptyStr := tt\n| (Char _) := tt\n| (App re₁ re₂) := re_not_empty re₁ && re_not_empty re₂\n| (Union re₁ re₂) := re_not_empty re₁ || re_not_empty re₂\n| (Star _) := tt\n\n/-\nTODO: file issues for dsimp and unfold breaking tags\n-/\nlemma re_not_empty_correct : (∃s, s =~ re) ↔ re_not_empty re = tt :=\nbegin\n  split,\n    /- braces so all_goals doesn't affect other direction -/\n    rintro ⟨w, h⟩, {\n    induction h,\n      case MEmpty { rw re_not_empty, },\n      case MChar : a { rw re_not_empty, },\n      case MApp : s₁ re₁ s₂ re₂ h₁ h₂ ih₁ ih₂ {\n        rw re_not_empty,\n        rw band_eq_true_eq_eq_tt_and_eq_tt,\n        exact ⟨ih₁, ih₂⟩,\n      },\n      case MUnionL : s₁ re₁ re₂ h ih {\n        rw re_not_empty,\n        rw bor_eq_true_eq_eq_tt_or_eq_tt,\n        exact or.inl ih,\n      },\n      case MUnionR : re₁ s₂ re₂ h ih {\n        rw re_not_empty,\n        rw bor_eq_true_eq_eq_tt_or_eq_tt,\n        exact or.inr ih,\n      },\n      case MStar0 : re { rw re_not_empty, },\n      case MStarApp : s₁ s₂ re h₁ h₂ ih₁ ih₂ { rw re_not_empty, },\n    },\n  intro h,\n  induction re,\n  case EmptySet { cases h, },\n  case EmptyStr { exact ⟨[], MEmpty⟩, },\n  case Char { exact ⟨[re], MChar re⟩, },\n  case App : re₁ re₂ ih₁ ih₂ {\n    rw re_not_empty at h,\n    rw band_eq_true_eq_eq_tt_and_eq_tt at h,\n    cases (ih₁ h.left) with w₁ ih₁,\n    cases (ih₂ h.right) with w₂ ih₂,\n    exact ⟨w₁ ++ w₂, MApp ih₁ ih₂⟩,\n  },\n  case Union : re₁ re₂ ih₁ ih₂ {\n    rw re_not_empty at h,\n    rw bor_eq_true_eq_eq_tt_or_eq_tt at h,\n    cases h,\n      cases ih₁ h with w ih₁,\n      exact ⟨w, MUnionL re₂ ih₁⟩,\n    cases ih₂ h with w ih₂,\n    exact ⟨w, MUnionR re₁ ih₂⟩,\n  },\n  case Star : re ih { exact ⟨[], MStar0 re⟩, },\nend\n\n/-\nLemma star_app: ∀T (s1 s2 : list T) (re : @reg_exp T),\n  s1 =~ Star re →\n  s2 =~ Star re →\n  s1 ++ s2 =~ Star re.\nProof.\n  intros T s1 s2 re H1.\n  induction H1\n    as [|x'|s1 re1 s2' re2 Hmatch1 IH1 Hmatch2 IH2\n        |s1 re1 re2 Hmatch IH|re1 s2' re2 Hmatch IH\n        |re''|s1 s2' re'' Hmatch1 IH1 Hmatch2 IH2].\n  - (* MEmpty *)\n    simpl. intros H. apply H.\n  - (* MChar. Stuck... *)\nAbort.\n-/\n\n-- lemma star_app (h₁ : s₁ =~ Star re) (h₂ : s₂ =~ Star re)\n--   : s₁ ++ s₂ =~ Star re :=\n-- begin\n--   induction h₁,\n--   case MEmpty { exact h₂, },\n--   case MChar { },\n-- end\n\n/-\nLemma star_app: ∀T (s1 s2 : list T) (re re' : reg_exp),\n  re' = Star re →\n  s1 =~ re' →\n  s2 =~ Star re →\n  s1 ++ s2 =~ Star re\nAbort.\n-/\n\n-- lemma star_app {re'}\n--   {heq : Star re = re'}\n--   (h₁ : s₁ =~ Star re)\n--   (h₂ : s₂ =~ Star re)\n--   : s₁ ++ s₂ =~ Star re := sorry\n\n/-\nLemma star_app: ∀T (s1 s2 : list T) (re : reg_exp),\n  s1 =~ Star re →\n  s2 =~ Star re →\n  s1 ++ s2 =~ Star re.\nProof.\n  intros T s1 s2 re H1.\n  remember (Star re) as re'.\n  generalize dependent s2.\n  induction H1\n    as [|x'|s1 re1 s2' re2 Hmatch1 IH1 Hmatch2 IH2\n        |s1 re1 re2 Hmatch IH|re1 s2' re2 Hmatch IH\n        |re''|s1 s2' re'' Hmatch1 IH1 Hmatch2 IH2].\n  - (* MEmpty *) discriminate.\n  - (* MChar *) discriminate.\n  - (* MApp *) discriminate.\n  - (* MUnionL *) discriminate.\n  - (* MUnionR *) discriminate.\n  - (* MStar0 *)\n    injection Heqre'. intros Heqre'' s H. apply H.\n  - (* MStarApp *)\n    injection Heqre'. intros H0.\n    intros s2 H1. rewrite <- app_assoc.\n    apply MStarApp.\n    + apply Hmatch1.\n    + apply IH2.\n      * rewrite H0. reflexivity.\n      * apply H1.\nQed.\n-/\n\n/-\nex uses discriminate with no hypothesis, so it's fair to\nintroduce contradiction here\n-/\nlemma star_app (h₁ : s₁ =~ Star re) (h₂ : s₂ =~ Star re)\n  : s₁ ++ s₂ =~ Star re :=\nbegin\n  /- generalize performs rewrites at the goal-/\n  revert re,\n  intro,\n  generalize heq : Star re = re',\n  intros,\n  induction h₁ generalizing h₂,\n  case MEmpty { contradiction, },\n  case MChar : a { contradiction, },\n  case MApp : s₁ re₁ s₂ re₂ h₁' h₂' ih₁ ih₂ { contradiction, },\n  case MUnionL : s₁ re₁ re₂ h ih { contradiction},\n  case MUnionR : re₁ s₂ re₂ h ih { contradiction, },\n  case MStar0 : re'' { exact h₂, },\n  case MStarApp : s₁ s₂ re'' h₁' h₂' ih₁ ih₂ {\n    rw append_assoc,\n    exact MStarApp h₁' (ih₂ heq h₂),\n  },\nend\n\n/-\nLemma MStar'' : ∀T (s : list T) (re : reg_exp),\n  s =~ Star re →\n  ∃ss : list (list T),\n    s = fold app ss []\n    ∧ ∀s', In s' ss → s' =~ re.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/- use permits a list, so using [] would be an empty use -/\n/- use continues working on arbitrary inductive types\nso can be used to eat the left side of the and in the goal\n-/\nlemma MStar'' (h : s =~ Star re)\n  : ∃ss, s = foldr append [] ss ∧ ∀{s'}, In s' ss → s' =~ re :=\nbegin\n  revert h,\n  generalize heq : Star re = re',\n  intro,\n  induction h,\n  case MEmpty { contradiction, },\n  case MChar { contradiction, },\n  case MApp { contradiction, },\n  case MUnionL { contradiction, },\n  case MUnionR { contradiction, },\n  case MStar0 : re'' {\n    use [[], rfl],\n    rintro s' ⟨⟩,\n  },\n  case MStarApp : s₁ s₂ re' h₁ h₂ ih₁ ih₂ {\n    cases ih₂ heq with w h,\n    use s₁::w,\n    rw h.left,\n    simp,\n    rintro s' (h' | h'),\n      injection heq with heq',\n      rw heq',\n      rwa ←h',\n    exact h.right h',\n  },\nend\n\n/-\nFixpoint pumping_constant {T} (re : @reg_exp T) : nat :=\n  match re with\n  | EmptySet ⇒ 0\n  | EmptyStr ⇒ 1\n  | Char _ ⇒ 2\n  | App re1 re2 ⇒\n      pumping_constant re1 + pumping_constant re2\n  | Union re1 re2 ⇒\n      pumping_constant re1 + pumping_constant re2\n  | Star _ ⇒ 1\n  end\n-/\n\ndef pumping_constant : @reg_exp α → ℕ\n| EmptySet := 0\n| EmptyStr := 1\n| (Char _) := 2\n| (App re₁ re₂) := pumping_constant re₁ + pumping_constant re₂\n| (Union re₁ re₂) := pumping_constant re₁ + pumping_constant re₂\n| (Star _) := 1\n\n/-\nFixpoint napp {T} (n : nat) (l : list T) : list T :=\n  match n with\n  | 0 ⇒ []\n  | S n' ⇒ l ++ napp n' l\n  end.\n\nLemma napp_plus: ∀T (n m : nat) (l : list T),\n  napp (n + m) l = napp n l ++ napp m l.\nProof.\n  intros T n m l.\n  induction n as [|n IHn].\n  - reflexivity.\n  - simpl. rewrite IHn, app_assoc. reflexivity.\nQed.\n-/\n\ndef napp : ℕ → list α → list α\n| 0 _ := []\n| (n + 1) l := l ++ napp n l\n\nlemma napp_plus : napp (n + m) s = napp n s ++ napp m s :=\nbegin\n  induction n with n ih,\n    unfold napp,\n    rw [zero_add, nil_append],\n  rw succ_add,\n  unfold napp,\n  rw append_assoc,\n  rw ih,\nend\n\n/-\nImport Coq.omega.Omega.\nLemma pumping : ∀T (re : @reg_exp T) s,\n  s =~ re →\n  pumping_constant re ≤ length s →\n  ∃s1 s2 s3,\n    s = s1 ++ s2 ++ s3 ∧\n    s2 ≠ [] ∧\n    ∀m, s1 ++ napp m s2 ++ s3 =~ re.\nProof.\n  intros T re s Hmatch.\n  induction Hmatch\n    as [ | x | s1 re1 s2 re2 Hmatch1 IH1 Hmatch2 IH2\n       | s1 re1 re2 Hmatch IH | re1 s2 re2 Hmatch IH\n       | re | s1 s2 re Hmatch1 IH1 Hmatch2 IH2 ].\n  - (* MEmpty *)\n    simpl. omega.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/- going back to default as finishing tactics can't handle our def -/\n\n/- omega is less useful, but solves a couple lemmas -/\n\nlemma le_add (h : n + m <= o) : n <= o ∧ m <= o := by omega\n\nlemma add_le_add' (h: n + m <= o + p) : n <= o ∨ m <= p := by omega\n\nlemma one_le (h : 1 <= n + m) : 1 <= n ∨ 1 <= m := by omega\n\nlemma napp_star (h₁ : s₁ =~ re) (h₂ : s₂ =~ Star re)\n  : napp n s₁ ++ s₂ =~ Star re :=\nbegin\n  induction n with n ih,\n    unfold napp,\n    rwa nil_append,\n  unfold napp,\n  rw append_assoc,\n  exact MStarApp h₁ ih,\nend\n\nlemma pumping (hm : s =~ re) (hp : pumping_constant re <= s.length)\n  : ∃{s₁ s₂ s₃},\n  s = s₁ ++ s₂ ++ s₃ ∧ s₂ ≠ [] ∧ ∀{m}, s₁ ++ napp m s₂ ++ s₃ =~ re :=\nbegin\n  induction hm,\n  case MEmpty { cases hp, },\n  case MChar : a { rcases hp with _ | ⟨_, _, ⟨⟩⟩, },\n  case MApp : s₁ re₁ s₂ re₂ h₁ h₂ ih₁ ih₂ {\n    unfold pumping_constant at hp,\n    rw length_append at hp,\n    cases add_le_add' hp,\n      rcases ih₁ h with ⟨s₁', s₂', s₃, rfl, h₂', h₃⟩,\n      use [s₁', s₂', s₃ ++ s₂],\n      rw append_assoc,\n      use [rfl, h₂'],\n      intro m,\n      rw ←append_assoc,\n      exact MApp h₃ h₂,\n    rcases ih₂ h with ⟨s₁', s₂', s₃, rfl, h₂', h₃⟩,\n    use [s₁ ++ s₁', s₂', s₃],\n    rw [←append_assoc, ←append_assoc],\n    use [rfl, h₂'],\n    intro m,\n    rw [append_assoc, append_assoc],\n    apply MApp h₁,\n    rw ←append_assoc,\n    exact h₃,\n  },\n  case MUnionL : s₁ re₁ re₂ h ih {\n    unfold pumping_constant at hp,\n    rcases ih (le_add hp).left with ⟨s₁', s₂, s₃, rfl, h₂, h₃⟩,\n    use [s₁', s₂, s₃, rfl, h₂],\n    intro m,\n    apply MUnionL,\n    exact h₃,\n  },\n  case MUnionR : re₁ s₂ re₂ h ih {\n    unfold pumping_constant at hp,\n    rcases ih (le_add hp).right with ⟨s₁, s₂', s₃, rfl, h₂, h₃⟩,\n    use [s₁, s₂', s₃, rfl, h₂],\n    intro m,\n    apply MUnionR,\n    exact h₃,\n  },\n  case MStar0 : re { cases hp, },\n  case MStarApp : s₁ s₂ re h₁ h₂ ih₁ ih₂ {\n    rw length_append at hp,\n    cases one_le hp,\n      use [[], s₁, s₂, rfl, ne_nil_of_length_pos h],\n      intro m,\n      rw nil_append,\n      exact napp_star h₁ h₂,\n    rcases ih₂ h with ⟨s₁', s₂', s₃, rfl, h₂, h₃⟩,\n    use [s₁ ++ s₁', s₂', s₃],\n    rw [←append_assoc, ←append_assoc],\n    use [rfl, h₂],\n    intro m,\n    rw [append_assoc, append_assoc],\n    apply MStarApp h₁,\n    rw ←append_assoc,\n    exact h₃,\n  },\nend\n\n/-\nTheorem filter_not_empty_In : ∀n l,\n  filter (fun x ⇒ n =? x) l ≠ [] →\n  In n l.\nProof.\n  intros n l. induction l as [|m l' IHl'].\n  - (* l =  *)\n    simpl. intros H. apply H. reflexivity.\n  - (* l = m :: l' *)\n    simpl. destruct (n =? m) eqn:H.\n    + (* n =? m = true *)\n      intros _. rewrite eqb_eq in H. rewrite H.\n      left. reflexivity.\n    + (* n =? m = false *)\n      intros H'. right. apply IHl'. apply H'.\nQed.\n-/\n\ntheorem filter_not_empty_In {l} (h : filter (λx, n =? x) l ≠ []) : In n l :=\nbegin\n  induction l with m l ih,\n    apply h,\n    refl,\n  cases heq : n =? m,\n    right,\n    apply ih,\n    unfold filter at h,\n    rwa heq at h,\n  left,\n  rw eqb_eq at heq,\n  rw heq,\nend\n\n/-\nInductive reflect (P : Prop) : bool → Prop :=\n| ReflectT (H : P) : reflect P true\n| ReflectF (H : ¬P) : reflect P false.\n-/\n\ninductive reflect (P : Prop) : bool → Prop\n| ReflectT (h : P) : reflect tt\n| ReflectF (h : ¬P) : reflect ff\n\nopen reflect\n\n/-\nTheorem iff_reflect : ∀P b, (P ↔ b = true) → reflect P b.\nProof.\n  (* WORKED IN CLASS *)\n  intros P b H. destruct b.\n  - apply ReflectT. rewrite H. reflexivity.\n  - apply ReflectF. rewrite H. intros H'. discriminate.\nQed.\n-/\n\ntheorem iff_reflect {b} (h : P ↔ b = tt) : reflect P b :=\nbegin\n  cases b,\n    apply ReflectF,\n    rw h,\n    simp,\n  apply ReflectT,\n  rw h,\nend\n\n/-\nTheorem reflect_iff : ∀P b, reflect P b → (P ↔ b = true).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem reflect_iff {b} (h : reflect P b) : (P ↔ b = tt) :=\nbegin\n  cases h with h' h',\n    rw eq_self_iff_true,\n    rwa iff_true,\n  simp only [iff_false],\n  exact h',\nend\n\n/-\nLemma eqbP : ∀n m, reflect (n = m) (n =? m).\nProof.\n  intros n m. apply iff_reflect. rewrite eqb_eq. reflexivity.\nQed.\n-/\n\nlemma eqbP : reflect (n = m) (n =? m) :=\nbegin\n  apply iff_reflect,\n  rw eqb_eq,\nend\n\n/-\nTheorem filter_not_empty_In' : ∀n l,\n  filter (fun x ⇒ n =? x) l ≠ [] →\n  In n l.\nProof.\n  intros n l. induction l as [|m l' IHl'].\n  - (* l =  *)\n    simpl. intros H. apply H. reflexivity.\n  - (* l = m :: l' *)\n    simpl. destruct (eqbP n m) as [H | H].\n    + (* n = m *)\n      intros _. rewrite H. left. reflexivity.\n    + (* n <> m *)\n      intros H'. right. apply IHl'. apply H'.\nQed.\n-/\n\ntheorem filter_not_empty_In' {l} (h : filter (λ x, n =? x) l ≠ []) : In n l :=\nbegin\n  induction l with m l ih,\n    apply h,\n    refl,\n  have, exact @eqbP n m,\n  generalize heq : n =? m = eq,\n  generalize heq' : n = m = eq',\n  rw [heq, heq'] at this,\n  cases this,\n  case ReflectT : this' {\n    rw ←heq' at this',\n    rw this',\n    exact or.inl rfl,\n  },\n  case ReflectF : this' {\n    unfold filter at h,\n    rw heq at h,\n    exact or.inr (ih h),\n  },\nend\n\n/-\nFixpoint count n l :=\n  match l with\n  | [] ⇒ 0\n  | m :: l' ⇒ (if n =? m then 1 else 0) + count n l'\n  end.\n\nTheorem eqbP_practice : ∀n l,\n  count n l = 0 → ~(In n l).\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ndef count (n) : list ℕ → ℕ\n| [] := 0\n| (m::l) := (if n =? m then 1 else 0) + count l\n\n/-\nTODO: introduced revert_after for hypothesis management to make\ngeneralize work nicer\n-/\n\ntheorem eqbP_practice' {l} (h : count n l = 0) : ¬In n l :=\nbegin\n  induction l with m l ih,\n    rintro ⟨⟨⟩⟩,\n  unfold count at h,\n  have, exact @eqbP n m,\n  revert_after ih,\n  generalize heq : n = m = eq,\n  generalize heq' : n =? m = eq',\n  intros h h',\n  cases h',\n  case ReflectT : h' {\n    simp only [if_true, bool.coe_sort_tt] at h,\n    rw add_comm at h,\n    contradiction,\n  },\n  case ReflectF : h' {\n    simp only [bool.coe_sort_ff, if_false] at h,\n    rintro (c | c),\n      rw c at heq,\n      simp only [true_iff, eq_self_iff_true, eq_iff_iff] at heq,\n      contradiction,\n    rw zero_add at h,\n    exact absurd c (ih h),\n  },\nend\n\n/-\nInductive nostutter {X:Type} : list X → Prop :=\n (* FILL IN HERE *)\n.\n-/\n\ninductive nostutter : list α → Prop\n| no₀ : nostutter []\n| no₁ (a) : nostutter [a]\n| no₂ (a) {h t} (n : nostutter (h::t)) (hne : a ≠ h)\n  : nostutter (a::h::t)\n\nopen nostutter\n\n/-\nExample test_nostutter_1: nostutter [3;1;4;1;5;6].\n(* FILL IN HERE *) Admitted.\n(*\n  Proof. repeat constructor; apply eqb_neq; auto.\n  Qed.\n*)\n\nExample test_nostutter_2: nostutter (@nil nat).\n(* FILL IN HERE *) Admitted.\n(*\n  Proof. repeat constructor; apply eqb_neq; auto.\n  Qed.\n*)\n\nExample test_nostutter_3: nostutter [5].\n(* FILL IN HERE *) Admitted.\n(*\n  Proof. repeat constructor; apply eqb_false; auto. Qed.\n*)\n\nExample test_nostutter_4: not (nostutter [3;1;1;4]).\n(* FILL IN HERE *) Admitted.\n(*\n  Proof. intro.\n  repeat match goal with\n    h: nostutter _ ⊢ _ => inversion h; clear h; subst\n  end.\n  contradiction Hneq0; auto. Qed.\n*)\n-/\n\nexample : nostutter [3, 1, 4, 1, 5, 6] :=\nby repeat { constructor, }; omega\n\nexample : @nostutter ℕ [] :=\nby repeat { constructor, }; omega\n\nexample : nostutter [5] :=\nby repeat { constructor, }; omega\n\n/- not converting ltac for this -/\nexample : ¬nostutter [3, 1, 1, 4] :=\nbegin\n  by_contra c,\n  repeat { contradiction <|> cases c with _ _ _ _ c h },\nend\n\ninductive merge : list α → list α → list α → Prop\n| m₀ : merge [] [] []\n| ml (h) {t r m} (hm : merge t r m) : merge (h::t) r (h::m)\n| mr {l} (h) {t m} (hm : merge l t m) : merge l (h::t) (h::m)\n\nopen merge\n\nexample : merge [1, 2, 3] [4, 5, 6] [1, 2, 3, 4, 5, 6] :=\nby repeat { constructor, }\n\nexample : merge [1, 2, 3] [4, 5, 6] [4, 5, 6, 1, 2, 3] :=\nby repeat { constructor, }\n\nexample : merge [1, 2, 3] [4, 5, 6] [1, 4, 2, 5, 3, 6] :=\nby repeat { constructor, }\n\n/-\nneed λ for coe from bool to Prop\nTODO : maybe change p to return a decidable prop\n-/\n\nlemma filter_merge {l r m} {p : α → bool}\n  (hm : merge l r m)\n  (hf : ∀a, In a l → p a = ff)\n  (ht : ∀a, In a r → p a = tt)\n  : m.filter (λa, p a) = r :=\nbegin\n  induction hm,\n  case m₀ { refl, },\n  case ml : h t r m hm ih {\n    have : p h = ff,\n      apply hf,\n      use rfl,\n    unfold filter,\n    rw this,\n    simp only [bool.coe_sort_ff, if_false],\n    apply ih,\n      intros a hin,\n      unfold In at hf,\n      exact hf a (or.inr hin),\n    intros a hin,\n    exact ht a hin,\n  },\n  case mr : l h t m hm ih {\n    have : p h = tt,\n      apply ht,\n      use rfl,\n    unfold filter,\n    rw this,\n    simp only [if_true, bool.coe_sort_tt],\n    use rfl,\n    apply ih,\n      intros a hin,\n      exact hf a hin,\n    intros a hin,\n    unfold In at ht,\n    exact ht a (or.inr hin),\n  },\nend\n\n/- filter challenge 2 -/\n\ntheorem filter_longest_matching_subseq\n  {l₁ l₂ : list α} {p : α → bool}\n  (hs : subseq l₁ l₂)\n  (ht : l₁.all p)\n  : l₁.length ≤ (l₂.filter (λa, p a)).length :=\nbegin\n  induction hs,\n  case em { exact refl, },\n  case cr : l₁' l₂' a h ih {\n    apply le_trans (ih ht),\n    unfold filter,\n    cases p a,\n      exact refl,\n    exact step refl,\n  },\n  case cl : l₁' l₂' a h ih {\n    unfold filter,\n    unfold list.all foldr at ht,\n    simp only [band_coe_iff] at ht,\n    simp only [ht.left, if_true],\n    unfold list.length,\n    apply nat.succ_le_succ,\n    exact ih ht.right,\n  },\nend\n\nsection palindrome\n\nopen poly (\n  append_assoc nil_append reverse_append\n  reverse_involutive\n)\nopen poly.list\n\nlocal infix :: := cons\nlocal infix ++ := append\nlocal notation `[]` := nil\nlocal notation `[` l:(foldr `, ` (h t, cons h t) nil `]`) := l\n\nvariable {l : poly.list α}\n\ninductive pal : poly.list α → Prop\n| pal₀ : pal []\n| pal₁ (a) : pal [a]\n| pal₂ (a) {l} (h : pal l) : pal (a::l ++ [a])\n\nopen pal\n\nexample : pal [1, 2, 1] := pal₂ 1 (pal₁ 2)\n\nlemma pal_app_rev : pal (l ++ l.reverse) :=\nbegin\n  induction l with a l ih,\n    exact pal₀,\n  rw poly.cons_append,\n  rw reverse,\n  rw poly.append_assoc,\n  exact pal₂ a ih,\nend\n\nlemma pal_rev (p : pal l) : l = l.reverse :=\nbegin\n  induction p,\n  case pal₀ { refl, },\n  case pal₁ { refl, },\n  case pal₂ : h t hp ih {\n    rw poly.cons_append,\n    unfold reverse,\n    rw reverse_append,\n    unfold reverse,\n    unfold poly.list.append,\n    rw ←ih,\n  },\nend\n\n/-\npalindrome converse\n-/\n\ntheorem nat.le_of_succ_le (h : n + 1 ≤ m) : n ≤ m := le_trans (step refl) h\n\ntheorem nat.le_add_left : n ≤ m + n :=\nbegin\n  induction m with m ih,\n    rw zero_add,\n    exact refl,\n  rw succ_add,\n  exact step ih,\nend\n\nlemma one_le_cons_length (a : α) (l : poly.list α) : 1 ≤ (a::l).length :=\nby apply nat.le_add_left\n\nlemma has_snoc {l : poly.list α} (h : 1 ≤ l.length) : ∃ll ar, l = ll ++ [ar] :=\nbegin\n  induction l with a l ih,\n    cases h,\n  cases l with a' l,\n    use [[], a],\n    rw poly.nil_append,\n  rcases ih (one_le_cons_length a' l) with ⟨ll, ar, ih⟩,\n  use [a::ll, ar],\n  rw ih,\n  rw poly.cons_append,\nend\n\nlemma length_append_cons (a l') (h : l = l' ++ [a])\n  : l.length = l'.length + 1 :=\nbegin\n  induction l' with a' l' ih generalizing l,\n    cases l with a'' l,\n      cases h,\n    cases h,\n    refl,\n  cases l with a'' l,\n    cases h,\n  cases h,\n  unfold length,\n  simp only [add_left_inj],\n  exact ih rfl,\nend\n\nlemma append_cons_eq_length {l₁ l₂ : poly.list α} {a₁ a₂}\n  (h : l₁ ++ [a₁] = l₂ ++ [a₂]) : l₁.length = l₂.length :=\nbegin\n  replace h, exact congr_arg length h,\n  rw length_append_cons a₁ l₁ rfl at h,\n  rw length_append_cons a₂ l₂ rfl at h,\n  rwa add_left_inj at h,\nend\n\nlemma append_cons_eq {l₁ l₂ : poly.list α} {a₁ a₂}\n  (h : l₁ ++ [a₁] = l₂ ++ [a₂]) : l₁ = l₂ ∧ a₁ = a₂ :=\nbegin\n  have hl, exact append_cons_eq_length h,\n  induction l₁ with a₁' l₁ ih generalizing l₂,\n    cases l₂ with a₂' l₂,\n      cases h,\n      use [rfl, rfl],\n    cases hl,\n  cases l₂ with a₂' l₂,\n    cases hl,\n  injections with h₁ h₂ h₃,\n  rw h₁,\n  simp only [true_and, eq_self_iff_true],\n  exact ih h₂ h₃,\nend\n\nlemma rev_cons_snoc {al ar : α} {lm : poly.list α}\n  (h : al::lm ++ [ar] = (al::lm ++ [ar]).reverse) : al = ar ∧ lm = lm.reverse :=\nbegin\n  rw poly.cons_append at h,\n  unfold reverse at h,\n  rw reverse_append at h,\n  injections with h₁ h₂,\n  rw poly.nil_append at h₂,\n  use [h₁, (append_cons_eq h₂).left],\nend\n\nlemma rev_pal_aux (hr : l = l.reverse) (n) (hl : l.length ≤ n) : pal l :=\nbegin\n  induction n with n ih generalizing l,\n    cases l with a l,\n      exact pal₀,\n    cases hl,\n  cases l with a l,\n    exact pal₀,\n  cases l with a' l,\n    exact pal₁ a,\n  rcases has_snoc (one_le_cons_length a' l) with ⟨ll, ar', h⟩,\n  rw h at hl hr ⊢,\n  rcases rev_cons_snoc hr with ⟨rfl, hr'⟩,\n  have hl' : ll.length ≤ n,\n    unfold length at hl,\n    rw length_append_cons a ll rfl at hl,\n    exact nat.le_of_succ_le (nat.le_of_succ_le_succ hl),\n  exact pal₂ a (ih hr' hl'),\nend\n\nlemma rev_pal (h : l = l.reverse) : pal l :=\nby exact rev_pal_aux h l.length refl\n\nend palindrome\n\n/- very different from builtin -/\n\ninductive disjoint : list α → list α → Prop\n| dis₀ : disjoint [] []\n| disl (h) {t r} (d : disjoint t r) (hn : ¬In h r) : disjoint (h::t) r\n| disr (h) {l t} (d : disjoint l t) (hn : ¬In h l) : disjoint l (h::t)\n\nopen indprop.disjoint\n\ninductive nodup : list α → Prop\n| nodup₀ : nodup []\n| nodup₁ (h) {l} (n : nodup l) (hn : ¬In h l) : nodup (h::l)\n\nopen nodup\n\nexample : nodup [1, 2, 3, 4] :=\nbegin\n  repeat {constructor},\n  repeat {unfold In <|> simp only [not_false_iff, or_false] <|> omega },\nend\n\nexample : @nodup bool [] := nodup₀\n\nexample : ¬nodup [1, 2, 1] :=\nbegin\n  by_contra c,\n  cases c with _ _ h hn,\n  unfold In at hn,\n  simp only [eq_self_iff_true, not_true, or_false, or_true] at hn,\n  exact hn,\nend\n\nexample : ¬nodup [tt, tt] :=\nbegin\n  by_contra c,\n  cases c with _ _ n hn,\n  unfold In at hn,\n  simp only [eq_self_iff_true, not_true, or_false] at hn,\n  exact hn,\nend\n\nlemma nil_dis (l : list α) : disjoint l [] :=\nbegin\n  induction l with h t ih,\n    exact dis₀,\n  apply disl h ih,\n  exact not_false,\nend\n\nlemma dis_nil (r : list α) : disjoint [] r :=\nbegin\n  induction r with h t ih,\n    exact dis₀,\n  apply disr h ih,\n  exact not_false,\nend\n\nlemma dis_iso {l r : list α}\n  : disjoint l r ↔ (∀a, In a l → ¬In a r) ∧ (∀a, In a r → ¬In a l) :=\nbegin\n  split,\n    intro h,\n    induction h,\n    case dis₀ {\n      rw and_self,\n      rintro a ⟨⟩,\n    },\n    case disl : h' t r' d hn ih {\n      split,\n        cases ih with ihl ihr,\n        rintro a (rfl | h'') c,\n          exact absurd c hn,\n        exact absurd h'' (ihr a c),\n      cases ih with ihl ihr,\n      rintros a h'' (rfl | c),\n        exact absurd h'' hn,\n      exact absurd h'' (ihl a c),\n    },\n    case disr : h' l' t d hn ih {\n      split,\n        cases ih with ihl ihr,\n        rintros a h'' (rfl | c),\n          exact absurd h'' hn,\n        exact absurd h'' (ihr a c),\n      cases ih with ihl ihr,\n      rintros a (rfl | h'') c,\n        exact absurd c hn,\n      exact absurd h'' (ihl a c),\n    },\n  rintro ⟨hl, hr⟩,\n  induction l with a l ih generalizing r,\n    exact dis_nil r,\n  have : disjoint l r,\n    apply ih,\n      intros a h',\n      exact hl a (or.inr h'),\n    intros a h',\n    have, exact hr a h',\n    rw In at this,\n    exact (not_or_distrib.mp this).right,\n  refine disl a this _,\n  apply hl,\n  exact or.inl rfl,\nend\n\nlemma dis_cons {l r} (d : disjoint (a :: l) r) : ¬In a r ∧ disjoint l r :=\nbegin\n  rcases dis_iso.mp d with ⟨dl, dr⟩,\n  split,\n    by_contra c,\n    have, exact dr a c,\n    rw [In, not_or_distrib] at this,\n    exact this.left rfl,\n  rw dis_iso,\n  split,\n    intros a h',\n    apply dl,\n    exact or.inr h',\n  intros a h',\n  have, exact dr a h',\n  rw [In, not_or_distrib] at this,\n  exact this.right,\nend\n\nlemma nodup_cons {l} (hn : nodup (a::l)) : nodup l :=\nbegin\n  cases hn with _ _ n hn,\n  exact n,\nend\n\nlemma nodup_app {l r : list α} (hn : nodup (l ++ r)) : nodup l ∧ nodup r :=\nbegin\n  induction l,\n  case nil {\n    simp at hn,\n    exact ⟨nodup₀, hn⟩,\n  },\n  case cons : hd tl ih {\n    cases hn with _ _ n hn,\n    have, exact ih n,\n    refine ⟨nodup₁ hd this.left _, this.right⟩,\n    change ¬In hd (tl ++ r) at hn,\n    rw in_app_iff at hn,\n    rw not_or_distrib at hn,\n    exact hn.left,\n  }\nend\n\nlemma app_disjoint {l r : list α}\n  (hl : nodup l) (hr : nodup r) (hd : disjoint l r) : nodup (l ++ r) :=\nbegin\n  rw dis_iso at hd,\n  cases hd with hdl hdr,\n  induction hl generalizing r,\n  case nodup₀ {\n    simp,\n    exact hr,\n  },\n  case nodup₁ : h t n hn ih {\n    rw cons_append,\n    have : nodup (t ++ r),\n      apply ih hr,\n        intros a h',\n        exact hdl a (or.inr h'),\n      intros a h' c,\n      have, exact hdr a h',\n      rw [In, not_or_distrib] at this,\n      exact absurd c this.right,\n    refine nodup₁ h this _,\n    by_contra c,\n    rcases in_app_iff.mp c with c | c,\n      exact absurd c hn,\n    have : ¬In h r,\n      apply hdl h,\n      exact or.inl rfl,\n    exact absurd c this,\n  },\nend\n\n/-\nLemma in_split : ∀(X:Type) (x:X) (l:list X),\n  In x l →\n  ∃l1 l2, l = l1 ++ x :: l2.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma in_split {l} (hin : In a l) : ∃l₁ l₂, l = l₁ ++ a :: l₂ :=\nbegin\n  induction l with a' l ih,\n    cases hin,\n  rcases hin with rfl | hin,\n    use [[], l],\n    rw nil_append,\n  have, exact ih hin,\n  rcases (ih hin) with ⟨w₁, w₂, rfl⟩,\n  use [a'::w₁, w₂],\n  rw cons_append,\nend\n\n/-\nInductive repeats {X:Type} : list X → Prop :=\n  (* FILL IN HERE *)\n.\n-/\n\ninductive repeats : list α → Prop\n| r₀ {a} {l} (hin : In a l) : repeats (a::l)\n| r₁ (a) {l} (r : repeats l) : repeats (a::l)\n\nopen repeats\n\n/-\nTheorem pigeonhole_principle: ∀(X:Type) (l1 l2:list X),\n   excluded_middle →\n   (∀x, In x l1 → In x l2) →\n   length l2 < length l1 →\n   repeats l1.\nProof.\n   intros X l1. induction l1 as [|x l1' IHl1'].\n  (* FILL IN HERE *) Admitted.\n-/\n\nsection pigeon\n\n/-\nTODO - don't use classical\n-/\nopen classical\n\ntheorem pigeonhole_principle {l₁ l₂ : list α}\n  (h : ∀a, In a l₁ → In a l₂) (hl : l₂.length < l₁.length) : repeats l₁ :=\nbegin\n  induction l₁ with a₁ l₁ ih generalizing l₂,\n    cases hl,\n  cases l₂ with a₂ l₂,\n    cases h a₁ (or.inl rfl),\n  cases (em (In a₁ l₁)) with hi₁ hni₁,\n    exact r₀ hi₁,\n  apply r₁,\n  rcases @in_split α a₁ (a₂::l₂) (h a₁ (or.inl rfl)) with ⟨l₂', l₃, heq⟩,\n  apply @ih (l₂' ++ l₃),\n    intros a hi₁,\n    rcases h a (or.inr hi₁) with rfl | hi₂,\n      cases l₂' with a₂' l₂',\n        cases heq,\n        exact absurd hi₁ hni₁,\n      cases heq,\n      exact or.inl rfl,\n    cases l₂' with a₂' l₂',\n      cases heq,\n      exact hi₂,\n    cases heq,\n    rw in_app_iff,\n    rcases in_app_iff.mp hi₂ with hi₂' | rfl | hi₃,\n        exact or.inl (or.inr hi₂'),\n      exact absurd hi₁ hni₁,\n    exact or.inr hi₃,\n  replace heq, exact congr_arg list.length heq,\n  rw length_append at heq ⊢,\n  unfold list.length at hl heq ⊢,\n  rw heq at hl,\n  rw ←add_assoc at hl,\n  unfold lt at hl ⊢,\n  exact nat.le_of_succ_le_succ hl,\nend\n\nend pigeon\n\n/-\nRequire Export Coq.Strings.Ascii.\nDefinition string := list ascii.\n-/\n\n/-\nTODO: explain this\n-/\ndef str := list char\ninstance : has_append str := ⟨list.append⟩\n\n/-\nLemma provable_equiv_true : ∀(P : Prop), P → (P ↔ True).\nProof.\n  intros.\n  split.\n  - intros. constructor.\n  - intros _. apply H.\nQed.\n-/\n\nlemma iff_true_intro (p : P) : P ↔ true :=\nbegin\n  split,\n    intro,\n    constructor,\n  intro,\n  exact p,\nend\n\n/-\nLemma not_equiv_false : ∀(P : Prop), ¬P → (P ↔ False).\nProof.\n  intros.\n  split.\n  - apply H.\n  - intros. destruct H0.\nQed.\n-/\n\nlemma iff_false_intro (np : ¬P) : (P ↔ false) :=\nbegin\n  split,\n    apply np,\n  intro h,\n  cases h,\nend\n\n/-\nLemma null_matches_none : ∀(s : string), (s =~ EmptySet) ↔ False.\nProof.\n  intros.\n  apply not_equiv_false.\n  unfold not. intros. inversion H.\nQed.\n-/\n\nlemma null_matches_none : s =~ EmptySet ↔ false :=\nbegin\n  apply iff_false_intro,\n  by_contra c,\n  cases c,\nend\n\n/-\nLemma empty_matches_eps : ∀(s : string), s =~ EmptyStr ↔ s = [ ].\nProof.\n  split.\n  - intros. inversion H. reflexivity.\n  - intros. rewrite H. apply MEmpty.\nQed.\n-/\n\nlemma empty_matches_eps : s =~ EmptyStr ↔ s = [] :=\nbegin\n  split,\n    intro h,\n    cases h,\n    refl,\n  intro h,\n  rw h,\n  exact MEmpty,\nend\n\n/-\nLemma empty_nomatch_ne : ∀(a : ascii) s, (a :: s =~ EmptyStr) ↔ False.\nProof.\n  intros.\n  apply not_equiv_false.\n  unfold not. intros. inversion H.\nQed.\n-/\n\nlemma empty_nomatch_ne : a::s =~ EmptyStr ↔ false :=\nbegin\n  apply iff_false_intro,\n  generalize heq : a::s = re,\n  by_contra c,\n  cases c,\n  cases heq,\nend\n\n/-\nLemma char_nomatch_char :\n  ∀(a b : ascii) s, b ≠ a → (b :: s =~ Char a ↔ False).\nProof.\n  intros.\n  apply not_equiv_false.\n  unfold not.\n  intros.\n  apply H.\n  inversion H0.\n  reflexivity.\nQed.\n-/\n\nlemma char_nomatch_char {b} (hne : b ≠ a) : b::s =~ Char a ↔ false :=\nbegin\n  apply iff_false_intro,\n  generalize heq : b::s = re,\n  by_contra c,\n  apply hne,\n  cases c,\n  cases heq,\n  refl,\nend\n\n/-\nLemma char_eps_suffix : ∀(a : ascii) s, a :: s =~ Char a ↔ s = [ ].\nProof.\n  split.\n  - intros. inversion H. reflexivity.\n  - intros. rewrite H. apply MChar.\nQed.\n-/\n\nlemma char_eps_suffix : a::s =~ Char a ↔ s = [] :=\nbegin\n  split,\n    generalize heq : a::s = re,\n    intro h,\n    cases h,\n    cases heq,\n    refl,\n  intro h,\n  rw h,\n  apply MChar,\nend\n\n/-\nLemma app_exists : ∀(s : string) re0 re1,\n    s =~ App re0 re1 ↔\n    ∃s0 s1, s = s0 ++ s1 ∧ s0 =~ re0 ∧ s1 =~ re1.\nProof.\n  intros.\n  split.\n  - intros. inversion H. ∃s1, s2. split.\n    * reflexivity.\n    * split. apply H3. apply H4.\n  - intros [ s0 [ s1 [ Happ [ Hmat0 Hmat1 ] ] ] ].\n    rewrite Happ. apply (MApp s0 _ s1 _ Hmat0 Hmat1).\nQed.\n-/\n\nlemma app_exists\n  : s =~ App re₀ re₁ ↔\n    ∃s₀ s₁, s = s₀ ++ s₁ ∧ s₀ =~ re₀ ∧ s₁ =~ re₁ :=\nbegin\n  split,\n    rintro (_ | _ | ⟨s₁, re₁, s₂, re₂, h₁, h₂⟩),\n    exact ⟨s₁, s₂, rfl, h₁, h₂⟩,\n  rintro ⟨w₁, w₂, rfl, hl, hr⟩,\n  exact MApp hl hr,\nend\n\n/-\nLemma app_ne : ∀(a : ascii) s re0 re1,\n    a :: s =~ (App re0 re1) ↔\n    ([ ] =~ re0 ∧ a :: s =~ re1) ∨\n    ∃s0 s1, s = s0 ++ s1 ∧ a :: s0 =~ re0 ∧ s1 =~ re1.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nlemma app_ne\n  : a::s =~ App re₀ re₁ ↔\n    [] =~ re₀ ∧ a::s =~ re₁ ∨\n    ∃s₀ s₁, s = s₀ ++ s₁ ∧ a::s₀ =~ re₀ ∧ s₁ =~ re₁ :=\nbegin\n  split,\n    intro h,\n    rw app_exists at h,\n    rcases h with ⟨_ | ⟨h₀, t₀⟩, w₁, hl, hr⟩,\n      rw nil_append at hl,\n      rw ←hl at hr,\n      exact or.inl hr,\n    injection hl with hll hlr,\n    cases hr with hrl hrr,\n    rw ←hll at hrl,\n    exact or.inr ⟨t₀, w₁, hlr, hrl, hrr⟩,\n  rw app_exists,\n  rintro (⟨hl, hr⟩ | ⟨w₀, w₁, rfl, hl, hr⟩),\n    exact ⟨[], a::s, rfl, hl, hr⟩,\n  use [a::w₀, w₁, rfl, hl, hr],\nend\n\n/-\nLemma union_disj : ∀(s : string) re0 re1,\n    s =~ Union re0 re1 ↔ s =~ re0 ∨ s =~ re1.\nProof.\n  intros. split.\n  - intros. inversion H.\n    + left. apply H2.\n    + right. apply H1.\n  - intros [ H | H ].\n    + apply MUnionL. apply H.\n    + apply MUnionR. apply H.\nQed.\n-/\n\nlemma union_disj : s =~ Union re₀ re₁ ↔ s =~ re₀ ∨ s =~ re₁ :=\nbegin\n  split,\n    intro h,\n    cases h,\n    case MUnionL : _ _ _ h { exact or.inl h, },\n    case MUnionR : _ _ _ h { exact or.inr h, },\n  intro h,\n  cases h,\n    exact MUnionL re₁ h,\n  exact MUnionR re₀ h,\nend\n\n/-\nLemma star_ne : ∀(a : ascii) s re,\n    a :: s =~ Star re ↔\n    ∃s0 s1, s = s0 ++ s1 ∧ a :: s0 =~ re ∧ s1 =~ Star re.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/-\nTODO: examine whether it's reasonable to use\nall_goals { try { contradiction } } here\n-/\n\nlemma star_ne\n  : a::s =~ Star re ↔\n    ∃s₀ s₁, s = s₀ ++ s₁ ∧ a::s₀ =~ re ∧ s₁ =~ Star re :=\nbegin\n  split,\n    generalize heq : a::s = s',\n    generalize heq' : Star re = re',\n    intro h,\n    induction h,\n    case MStarApp : s₁ s₂ re'' h₁ h₂ ih₁ ih₂ {\n      rw ←heq' at *,\n      cases s₁,\n      case nil {\n        simp at heq,\n        exact ih₂ heq (refl _),\n      },\n      case cons : hd tl {\n        injection heq' with heq'',\n        rw ←heq'' at *,\n        injection heq with heq₁ heq₂,\n        rw ← heq₁ at *,\n        exact ⟨tl, s₂, heq₂, h₁, h₂⟩,\n      },\n    },\n    case MEmpty { cases heq, },\n    case MChar { cases heq', },\n    case MApp { cases heq', },\n    case MUnionL { cases heq', },\n    case MUnionR { cases heq', },\n    case MStar0 { cases heq, },\n  rintro ⟨w₀, w₁, rfl, hl, hr⟩,\n  rw ←cons_append,\n  exact MStarApp hl hr,\nend\n\n/-\nDefinition refl_matches_eps m :=\n  ∀re : @reg_exp ascii, reflect ([ ] =~ re) (m re).\n-/\n\ndef refl_matches_eps (m : @reg_exp α → bool) := ∀re, reflect ([] =~ re) (m re)\n\n/-\nFixpoint match_eps (re: @reg_exp ascii) : bool\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n-/\n\ndef match_eps : @reg_exp α → bool\n| EmptyStr := tt\n| (Union re₁ re₂) := match_eps re₁ || match_eps re₂\n| (Star _) := tt\n| (App re₁ re₂) := match_eps re₁ && match_eps re₂\n| _ := ff\n\n/-\nLemma match_eps_refl : refl_matches_eps match_eps.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n\nlemma append_eq_nil {ll lr : list α} (h : [] = ll ++ lr): ll = [] ∧ lr = [] :=\nbegin\n  cases ll with a ll,\n    rw nil_append at h,\n    rw h,\n    use [rfl, rfl],\n  cases h,\nend\n\n/- yeah, lean does not do well here -/\nlemma match_eps_refl : @refl_matches_eps α match_eps :=\nbegin\n  unfold refl_matches_eps,\n  intro re,\n  induction re,\n  case EmptySet {\n    unfold match_eps,\n    apply ReflectF,\n    rw null_matches_none,\n    exact not_false,\n  },\n  case EmptyStr {\n    unfold match_eps,\n    apply ReflectT,\n    exact MEmpty,\n  },\n  case Char : a {\n    unfold match_eps,\n    apply ReflectF,\n    generalize heq : [] = s,\n    by_contra c,\n    cases c,\n    cases heq,\n  },\n  case App : re₁ re₂ ih₁ ih₂ {\n    revert_after re₂,\n    generalize heq₁ : ([] =~ re₁) = re₁',\n    generalize hmeq₁ : match_eps re₁ = m₁',\n    generalize heq₂ : ([] =~ re₂) = re₂',\n    generalize hmeq₂ : match_eps re₂ = m₂',\n    unfold match_eps,\n    intros,\n    cases ih₁,\n    case ReflectT : ih₁' {\n      rw ←heq₁ at ih₁',\n      cases ih₂,\n      case ReflectT : ih₂' {\n        rw [hmeq₁, hmeq₂],\n        apply ReflectT,\n        rw ←heq₂ at ih₂',\n        exact MApp ih₁' ih₂',\n      },\n      case ReflectF : ih₂' {\n        rw [hmeq₁, hmeq₂],\n        apply ReflectF,\n        rw ←heq₂ at ih₂',\n        generalize heq : [] = s,\n        rintro (_ | _ | ⟨s₁, re₁, s₂, re₂, h₁, h₂⟩),\n        rcases append_eq_nil heq with ⟨rfl, rfl⟩,\n        exact absurd h₂ ih₂',\n      },\n    },\n    case ReflectF : ih₁' {\n      rw ←heq₁ at ih₁',\n      rw [hmeq₁, hmeq₂],\n      apply ReflectF,\n      generalize heq : [] = s,\n      rintro (_ | _ | ⟨s₁, re₁, s₂, re₂, h₁, h₂⟩),\n      rcases append_eq_nil heq with ⟨rfl, rfl⟩,\n      exact absurd h₁ ih₁',\n    },\n  },\n  case Union : re₁ re₂ ih₁ ih₂ {\n    revert_after re₂,\n    generalize heq₁ : ([] =~ re₁) = re₁',\n    generalize hmeq₁ : match_eps re₁ = m₁',\n    generalize heq₂ : ([] =~ re₂) = re₂',\n    generalize hmeq₂ : match_eps re₂ = m₂',\n    unfold match_eps,\n    intros,\n    cases ih₁,\n    case ReflectT : ih₁' {\n      rw [hmeq₁, hmeq₂],\n      rw ←heq₁ at ih₁',\n      exact ReflectT (MUnionL re₂ ih₁'),\n    },\n    case ReflectF : ih₁' {\n      rw ←heq₁ at ih₁',\n      cases ih₂,\n      case ReflectT : ih₂' {\n        rw [hmeq₁, hmeq₂],\n        rw ←heq₂ at ih₂',\n        exact ReflectT (MUnionR re₁ ih₂'),\n      },\n      case ReflectF : ih₂' {\n        rw [hmeq₁, hmeq₂],\n        rw ←heq₂ at ih₂',\n        apply ReflectF,\n        rw union_disj,\n        rintro (c | c),\n          exact absurd c ih₁',\n        exact absurd c ih₂',\n      },\n    },\n  },\n  case Star : r ih {\n    unfold match_eps,\n    exact ReflectT (MStar0 r),\n  },\nend\n\n/-\nDefinition is_der re (a : ascii) re' :=\n  ∀s, a :: s =~ re ↔ s =~ re'.\n-/\n\ndef is_der (a : α) (re₀ re₁) := ∀s, a::s =~ re₀ ↔ s =~ re₁\n\n/-\nDefinition derives d := ∀a re, is_der re a (d a re).\n-/\n\ndef derives (d : α → @reg_exp α → @reg_exp α) := ∀a re, is_der a re (d a re)\n\n/-\nFixpoint derive (a : ascii) (re : @reg_exp ascii) : @reg_exp ascii\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n-/\n\n/-\nTODO: look into deciable eq\n-/\ndef derive (a : char) : @reg_exp char → @reg_exp char\n| EmptySet := EmptySet\n| EmptyStr := EmptySet\n| (Char a') := if a = a' then EmptyStr else EmptySet\n| (App re₁ re₂) := if match_eps re₁\n                   then Union (App (derive re₁) re₂) (derive re₂)\n                   else App (derive re₁) re₂\n| (Union re₁ re₂) := Union (derive re₁) (derive re₂)\n| (Star re) := App (derive re) (Star re)\n\n/-\nExample c := ascii_of_nat 99.\nExample d := ascii_of_nat 100.\n-/\n\ndef c := 'c'\ndef d := 'd'\n\n/-\nExample test_der0 : match_eps (derive c (EmptySet)) = false.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive c (EmptySet)) = ff := rfl\n\n/-\nExample test_der1 : match_eps (derive c (Char c)) = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive c (Char c)) = tt := rfl\n\n/-\nExample test_der2 : match_eps (derive c (Char d)) = false.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive c (Char d)) = ff := rfl\n\n/-\nExample test_der3 : match_eps (derive c (App (Char c) EmptyStr)) = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive c (App (Char c) EmptyStr)) = tt := rfl\n\n/-\nExample test_der4 : match_eps (derive c (App EmptyStr (Char c))) = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive c (App EmptyStr (Char c))) = tt := rfl\n\n/-\nExample test_der5 : match_eps (derive c (Star (Char c))) = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive c (Star (Char c))) = tt := rfl\n\n/-\nExample test_der6 :\n  match_eps (derive d (derive c (App (Char c) (Char d)))) = true.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive d (derive c (App (Char c) (Char d)))) = tt := rfl\n\n/-\nExample test_der7 :\n  match_eps (derive d (derive c (App (Char d) (Char c)))) = false.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\nexample : match_eps (derive d (derive c (App (Char d) (Char c)))) = ff := rfl\n\n/-\nLemma derive_corr : derives derive.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\n/-\nTODO: is this a good spot to introduce refine?\n-/\nlemma derive_corr : derives derive :=\nbegin\n  unfold derives,\n  unfold is_der,\n  intros,\n  split,\n    generalize heq : a::s = s',\n    intro h,\n    induction re generalizing s s',\n    case EmptySet { cases h, },\n    case EmptyStr {\n      cases h,\n      cases heq,\n    },\n    case Char {\n      cases h,\n      cases heq,\n      unfold derive,\n      simp only [if_true, eq_self_iff_true],\n      exact MEmpty,\n    },\n    case App : re₁ re₂ ih₁ ih₂ {\n      unfold derive,\n      rw [←heq, app_ne] at h,\n      have, exact match_eps_refl re₁,\n      revert this,\n      generalize heq' : ([] =~ re₁) = re₁',\n      generalize heq'' : match_eps re₁ = me',\n      intro,\n      rcases h with ⟨h₁, h₂⟩ | ⟨s₀, s₁, rfl, h₁, h₂⟩,\n        cases this,\n        case ReflectT : this {\n          simp only [if_true, bool.coe_sort_tt],\n          apply MUnionR,\n          exact ih₂ s (a::s) rfl h₂,\n        },\n        case ReflectF : this {\n          rw ←heq' at this,\n          cases this with hl hr,\n          exact absurd h₁ hr,\n        },\n      cases this,\n      case ReflectT : this {\n        apply MUnionL,\n        rw app_exists,\n        refine ⟨s₀, s₁, rfl, _, h₂⟩,\n        exact ih₁ s₀ (a::s₀) rfl h₁,\n      },\n      case ReflectF : this {\n        simp only [bool.coe_sort_ff, if_false],\n        rw app_exists,\n        refine ⟨s₀, s₁, rfl, _, h₂⟩,\n        exact ih₁ s₀ (a::s₀) rfl h₁,\n      },\n    },\n    case Union : re₁ re₂ ih₁ ih₂ {\n      unfold derive,\n      rcases union_disj.mp h with h | h,\n        apply MUnionL,\n        exact ih₁ s s' heq h,\n      apply MUnionR,\n      exact ih₂ s s' heq h,\n    },\n    case Star : re ih {\n      unfold derive,\n      rw [←heq, star_ne] at h,\n      rcases h with ⟨s₀, s₁, rfl, h₁, h₂⟩,\n      rw app_exists,\n      refine ⟨s₀, s₁, rfl, _, h₂⟩,\n      exact ih s₀ (a::s₀) rfl h₁,\n    },\n  intro h,\n  induction re generalizing s,\n  case EmptySet { cases h, },\n  case EmptyStr { cases h, },\n  case Char {\n    unfold derive at h,\n    /- can't just use a = re -/\n    cases (char.decidable_eq a re) with h' h',\n      unfold ite at h,\n      cases h,\n    unfold ite at h,\n    cases h,\n    rw h',\n    exact MChar re,\n  },\n  case App : re₁ re₂ ih₁ ih₂ {\n    unfold derive at h,\n    rw app_ne,\n    cases hm : match_eps re₁,\n      rw hm at h,\n      simp only [bool.coe_sort_ff, if_false] at h,\n      rcases app_exists.mp h with ⟨s₀, s₁, rfl, h₁, h₂⟩,\n      exact or.inr ⟨s₀, s₁, rfl, ih₁ s₀ h₁, h₂⟩,\n    rw hm at h,\n    simp only [if_true, bool.coe_sort_tt] at h,\n    rw union_disj at h,\n    cases h,\n      rcases app_exists.mp h with ⟨s₀, s₁, rfl, h₁, h₂⟩,\n      exact or.inr ⟨s₀, s₁, rfl, ih₁ s₀ h₁, h₂⟩,\n    have, exact match_eps_refl re₁,\n    rw hm at this,\n    cases this with this,\n    exact or.inl ⟨this, ih₂ s h⟩,\n  },\n  case Union : re₁ re₂ ih₁ ih₂ {\n    unfold derive at h,\n    rw union_disj at h ⊢,\n    cases h,\n      exact or.inl (ih₁ s h),\n    exact or.inr (ih₂ s h),\n  },\n  case Star : re ih {\n    unfold derive at h,\n    rcases app_exists.mp h with ⟨s₀, s₁, rfl, h₁, h₂⟩,\n    rw star_ne,\n    exact ⟨s₀, s₁, rfl, ih s₀ h₁, h₂⟩,\n  },\nend\n\n/-\nDefinition matches_regex m : Prop :=\n  ∀(s : string) re, reflect (s =~ re) (m s re).\n-/\n\ndef matches_regex (m : list α → @reg_exp α → bool) :=\n  ∀s re, reflect (s =~ re) (m s re)\n\n/-\nFixpoint regex_match (s : string) (re : @reg_exp ascii) : bool\n  (* REPLACE THIS LINE WITH \":= _your_definition_ .\" *). Admitted.\n-/\n\ndef regex_match : str → @reg_exp char → bool\n| [] r := match_eps r\n| (c::s) r := regex_match s (derive c r)\n\n/-\nTheorem regex_refl : matches_regex regex_match.\nProof.\n  (* FILL IN HERE *) Admitted.\n-/\n\ntheorem regex_refl : matches_regex regex_match :=\nbegin\n  unfold matches_regex,\n  intros,\n  induction s with a s ih generalizing re,\n    exact match_eps_refl re,\n  rw derive_corr,\n  unfold regex_match,\n  exact ih (derive a re),\nend\n\nend indprop", "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/ch07_indprop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7576060848750233}}
{"text": "import ..prooflab\nimport lectures.lec7_predicate\n\n\n/-! # Homework 6: ...\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 -/\n\n\nnamespace PROOFS\n\n\nvariables {X Y Z : Type}\n\n\n\n/-! ## Question 1 (20 points): \nThe following question has five lemmas each worth 4 points. Refer to the lecture file for a review of concepts of __binary relation__ and __equivalence relation__.\n-/\n\n-- let X be a type, and let R be a binary relation on R.\nvariable {R : X → X → Prop}\n\n\nnamespace equivalence_alt\n\nlemma refl_ext_left {ρ : reflexive R} (x y : X) (H : ∀ a : X,  R a x → R a y) : \n  R x y :=\nbegin\n  sorry, \nend \n\n\nlemma refl_ext {ρ : reflexive R} (x y : X) (H : ∀ a: X,  R x a ↔ R y a) : \n  R x y :=\nbegin\n  sorry, \nend \n\n\nlemma refl_symm_ext_left {ρ : reflexive R} {σ : symmetric R} (x y : X) (H : ∀ a : X,  R x a → R y a) : \n  R x y :=\nbegin\n  sorry, \nend    \n\n\nlemma eqv_rel_ext {eqv : equivalence R} (x y : X) (H : ∀ a : X,  R x a → R y a) : R x y :=\nbegin \nobtain ⟨ρ, σ, τ⟩ := eqv, \n  sorry, \nend \n\n\nlemma trans_ext {tr : transitive R} (x y : X) (H : ∃ a : X, R x a ∧ R a y) : R x y := \nbegin \nsorry, \nend \n\nend equivalence_alt -- end of namespace\n\n\n\n\n\n\n\n/-! ## Question 2 (10 points): -/\n\nlemma injection_respect_distinction_alt {X Y : Type} {f : X → Y} (inj : is_injective f) : \n  ∀ ⦃x₁ x₂⦄, (x₁ ≠ x₂)  → (f x₁ ≠ f x₂) := \nbegin\n  sorry, \nend \n\n\n\n\n\n\n\n/-! ## Question 3 (20 points): \n\nWe Define a predicate which states whether a function of the form `ℤ × ℤ → ℤ` is symmetric. Recall that a function `f : ℤ × ℤ → ℤ` is said to be __symmetric__ if swapping the coordinates does not change the value of the function, i.e `f (x , y) = f(y , x)` for all integers `x` and `y`. \n-/\n\ndef is_symm_fun (f : ℤ × ℤ → ℤ) := ∀ x y : ℤ, f (x , y) = f (y , x)\n\n#check is_symm_fun\n\n\n/-\n**Part I**: Consider the functions `shift_fun` and `diff_fun_zero` defined in below. The function `cross_effect` is constructed from these functions. Lemma `cross_effect_defn` in below describes the effect of fucntion `cross_effect` on each pair `(x,y) : ℤ × ℤ`. \n-/\n\ndef shift_fun (x : ℤ) (f : ℤ → ℤ) := \nλ y : ℤ, f (x + y)\n\n#check shift_fun \n\n\ndef diff_fun_zero (f : ℤ → ℤ) (y : ℤ) := \nf y - f 0 \n\n\n#check diff_fun_zero\n\ndef cross_effect (f : ℤ → ℤ) (p : ℤ × ℤ) := (diff_fun_zero (shift_fun p.1 f) p.2) - (diff_fun_zero f p.2)\n\n\n#eval cross_effect (λ x, x^2) (2, 3)\n\n\n\nlemma cross_effect_defn {x y : ℤ} {f : ℤ → ℤ} :\ncross_effect f (x,y) = f (x + y) - f (x) - f (y) + f(0) := \nbegin \n  sorry,   \nend \n\n/-\n**Part II**: Show that for any function `f : ℤ × ℤ → ℤ`, the cross-effect of `f` is symmetric by completing the following proof. You can use the lemma `cross_effect_defn`.  \n-/\n\ntheorem is_symm_cross_effect : \n  ∀ f : ℤ → ℤ, is_symm_fun (cross_effect f) := \nbegin\n  sorry, \nend   \n\n\n\n\n\n\n/- ## Question 4 (20 points): -/\n\n#check bool_of_nat \n-- This function was defined in `lec3_function` as follows: \n-- def bool_of_nat (n : ℕ) := if n = 0 then ff else tt\n\n\n\nlemma not_inj_bool_of_nat : \n  ¬ is_injective (bool_of_nat) := \nbegin\n  sorry,\nend    \n\n\n\n\n\n\n\n/- ## Question 5 (30 points): \n\n**Part I**:\nProve that for every function `f : X → Y` and `g : Y → Z`, if the composition `g ∘ f : X → Z` is injective then `f` is injective.  \n-/\n\nlemma inj_right_of_inj_comp_alt (f : X → Y) (g : Y → Z) (h : is_injective (g ∘ f)) :\n  is_injective f := \nbegin\n  sorry, \nend \n\n\n\n/- **Part II**-/\n\nlemma id_of_bool_nat_comp_nat_bool : \n  bool_of_nat ∘ nat_of_bool = id := \nbegin\n  sorry, \nend  \n\n\n\n/- **Part III**: \nUse lemma `id_of_bool_nat_comp_nat_bool` and `not_inj_bool_of_nat` to prove the following statement. \n-/\n\nexample : \n∃ X Y Z : Type, ∃ f : X → Y, ∃ g : Y → Z,  is_injective (g ∘ f) ∧  ¬ is_injective g := \nbegin\n  sorry, \nend \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/hw6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7575953019179901}}
{"text": "import data.real.basic\n\n--begin hide\nnamespace xena\ndef neighborhood1 (a : ℝ) (ε : ℝ) (h : ε > 0) := { x : ℝ | abs(a - x) < ε}\n\n/-\n To be technically correct, the definition below should include \n the hypothesis that ε > 0, see the one above.\n But that does raise some issues which I don't know how to handle\n when using it in the main result lemma.\n-/\n-- end hide\n\ndef neighborhood (a : ℝ) (ε : ℝ) := { x : ℝ | abs(a - x) < ε} \nlocal attribute [instance] classical.prop_decidable --hide\n\n/- Lemma\nHausdorff property for the reals.\n-/\nlemma hausdorff_reals (a b : ℝ) (hne : a ≠ b) : \n  ∃ (ε:ℝ), ε > 0 ∧ (neighborhood a ε ∩ neighborhood b ε = ∅) :=\nbegin\n  set d := abs(b-a) with hd,\n  have h1 : 0 < d, \n    rw hd, by_contradiction hf, push_neg at hf, \n    have h11 := abs_nonneg (b-a),\n    have h12 : abs(b-a) = 0, linarith,\n    have h13 : (b-a) = 0, exact abs_eq_zero.1 h12,\n    have h14 : a = b, linarith, \n    exact hne h14,\n  set e := d / 3 with he,\n  use e, split, linarith,\n  by_contradiction H,\n  -- the stuff below can probably be made much shorter\n  have G := set.ne_empty_iff_nonempty.mp H,\n  cases G with x hab, cases hab with ha hb,\n  have ha1 : abs(a-x) < e, exact ha,  -- linarith below won't work\n  have hb1 : abs(b-x) < e, exact hb,  -- without these\n  have hb2 : abs(b-x) = abs(x-b), exact abs_sub _ _,\n  rw hb2 at hb1,\n  have hab := abs_add (a-x) (x-b), \n  have hab1 : a - x + (x - b) = a - b, ring,\n  rw hab1 at hab,\n  have hab2 : abs(a-b) <  e + e, linarith,\n  have hdd : d = 3 * e, rw he, linarith,\n  rw hdd at hd, \n  have hde := eq.symm hd, \n  have hdf : abs(b-a) > 2 * e,\n    linarith,\n  have hdg : e + e = 2 * e, linarith,\n  rw hdg at hab2, \n  have hb2 : abs(b-a) = abs(a-b), exact abs_sub _ _,\n  rw hb2 at hdf, linarith, 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/topology/hausdorff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952838963489, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7575606607152198}}
{"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-/\nimport linear_algebra.matrix.charpoly.coeff\nimport field_theory.finite.basic\nimport data.matrix.char_p\n\n\n/-!\n# Results on characteristic polynomials and traces over finite fields.\n-/\n\nnoncomputable theory\n\nopen polynomial matrix\nopen_locale polynomial\n\nvariables {n : Type*} [decidable_eq n] [fintype n]\n\n@[simp] lemma finite_field.matrix.charpoly_pow_card {K : Type*} [field K] [fintype K]\n  (M : matrix n n K) : (M ^ (fintype.card K)).charpoly = M.charpoly :=\nbegin\n  casesI (is_empty_or_nonempty n).symm,\n  { cases char_p.exists K with p hp, letI := hp,\n    rcases finite_field.card K p with ⟨⟨k, kpos⟩, ⟨hp, hk⟩⟩,\n    haveI : fact p.prime := ⟨hp⟩,\n    dsimp at hk, rw hk at *,\n    apply (frobenius_inj K[X] p).iterate k,\n    repeat { rw iterate_frobenius, rw ← hk },\n    rw ← finite_field.expand_card,\n    unfold charpoly, rw [alg_hom.map_det, ← coe_det_monoid_hom,\n      ← (det_monoid_hom : matrix n n K[X] →* K[X]).map_pow],\n    apply congr_arg det,\n    refine mat_poly_equiv.injective _,\n    rw [alg_equiv.map_pow, mat_poly_equiv_charmatrix, hk, sub_pow_char_pow_of_commute, ← C_pow],\n    { exact (id (mat_poly_equiv_eq_X_pow_sub_C (p ^ k) M) : _) },\n    { exact (C M).commute_X } },\n  { -- TODO[gh-6025]: remove this `haveI` once `subsingleton_of_empty_right` is a global instance\n    haveI : subsingleton (matrix n n K) := subsingleton_of_empty_right,\n    exact congr_arg _ (subsingleton.elim _ _), },\nend\n\n@[simp] lemma zmod.charpoly_pow_card {p : ℕ} [fact p.prime] (M : matrix n n (zmod p)) :\n  (M ^ p).charpoly = M.charpoly :=\nby { have h := finite_field.matrix.charpoly_pow_card M, rwa zmod.card at h, }\n\nlemma finite_field.trace_pow_card {K : Type*} [field K] [fintype K]\n  (M : matrix n n K) : trace (M ^ (fintype.card K)) = trace M ^ (fintype.card K) :=\nbegin\n  casesI is_empty_or_nonempty n,\n  { simp [zero_pow fintype.card_pos, matrix.trace], },\n  rw [matrix.trace_eq_neg_charpoly_coeff, matrix.trace_eq_neg_charpoly_coeff,\n       finite_field.matrix.charpoly_pow_card, finite_field.pow_card]\nend\n\nlemma zmod.trace_pow_card {p : ℕ} [fact p.prime] (M : matrix n n (zmod p)) :\n  trace (M ^ p) = (trace M)^p :=\nby { have h := finite_field.trace_pow_card M, rwa zmod.card at h, }\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/charpoly/finite_field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7575606582859193}}
{"text": "\nopen nat\n\nnamespace existential\n\ntheorem bob : ∃x : ℕ, x > 0 :=\nhave h : 1 > 0, from zero_lt_succ 0,\nexists.intro _ h\n#check bob\n\nexample (x : ℕ) (h : x > 0) : ∃y, y < x :=\nexists.intro 0 h\n\nexample (x y z : ℕ) (hxy : x < y) (hyz : y < z) :\n    ∃w, x < w ∧ w < z :=\n-- exists.intro y (and.intro hxy hyz)\n-- exists.intro y ⟨hxy, hyz⟩\n-- ⟨y, ⟨hxy, hyz⟩⟩\n⟨y, hxy, hyz⟩\n\n#check @exists.intro\n\nexample : ∃x : ℕ, x > 0 :=\n⟨1, zero_lt_succ 0⟩\n\nexample (x : ℕ) (h : x > 0) : ∃y, y < x :=\n⟨0, h⟩\n\nexample (x y z : ℕ) (hxy : x < y) (hyz : y < z) :\n    ∃w, x < w ∧ w < z :=\n⟨y, hxy, hyz⟩ \n\nvariable g : ℕ → ℕ → ℕ\nvariable hg : g 0 0 = 0\n\ntheorem gex1 : ∃ x, g x x = x := ⟨0, hg⟩\ntheorem gex2 : ∃ x, g x 0 = x := ⟨0, hg⟩\ntheorem gex3 : ∃ x, g 0 0 = x := ⟨0, hg⟩\ntheorem gex4 : ∃ x, g x x = 0 := ⟨0, hg⟩\n\nset_option pp.implicit true\n\n#print gex1\n#print gex2\n#print gex3\n#print gex4\n\n\nvariables (α : Type) (p q : α → Prop)\n\nexample (h : ∃ r, p r ∧ q r) : ∃ x, q x ∧ p x :=\nexists.elim h\n    (assume w,\n        assume hw : p w ∧ q w,\n        show ∃ x, q x ∧ p x, from ⟨w, hw.right, hw.left⟩)\n\n\n\n\nend existential\n\nnamespace matchh\n\nvariables (α : Type) (p q : α → Prop)\n\nexample (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x :=\n-- match h with ⟨(w : α),(hw : p w ∧ q w)⟩ :=\n-- match h with ⟨w, hw⟩ :=\n--     ⟨w, hw.right, hw.left⟩\nmatch h with ⟨w, hpw, hqw⟩ :=\n    ⟨w, hqw, hpw⟩\nend\n\nexample (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x :=\nlet ⟨w, hpw, hqw⟩ := h in ⟨w, hqw, hpw⟩\n\nexample : (∃ x, p x ∧ q x) → ∃ x, q x ∧ p x :=\nassume ⟨w, hpw, hqw⟩, ⟨w, hqw, hpw⟩\n\ndef is_even (a : nat) := ∃ b, a = 2 * b\n\n\ntheorem even_plus_even {a b : nat}\n    (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\nmatch h1, h2 with\n    ⟨w1, hw1⟩, ⟨w2, hw2⟩ := ⟨w1 + w2, by rw [hw1, hw2, mul_add]⟩\nend\n#check even_plus_even\n\nend matchh\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/Chapter4/4-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703476, "lm_q2_score": 0.8438950966654772, "lm_q1q2_score": 0.7575606529993331}}
{"text": "-- Chapter 3 Exercises\n-- Question 1\n-- Commutativity of ∧ \nexample (p q : Prop) : p ∧ q <-> q ∧ p :=\nbegin\n  apply iff.intro,\n  intro h,\n  have hp : p, from and.left h,\n  have hq : q, from and.right h,\n  show q ∧ p, from and.intro hq hp,\n  intro g,\n  have hq' : q, from and.left g,\n  have hp' : p, from and.right g,\n  show p ∧ q, from and.intro hp' hq'\nend\n-- Question 2\n-- Commutativity of ∨  \nexample (p q : Prop) : p ∨ q <-> q ∨ p :=\nbegin\n apply iff.intro,\n intro h,\n apply or.elim h,\n intro h1,\n apply or.inr,\n exact h1,\n intro h2,\n apply or.inl,\n exact h2,\n intro h',\n apply or.elim h',\n intro h1,\n apply or.inr,\n exact h1,\n intro h2,\n apply or.inl,\n exact h2, \nend\n--Question 3\n-- Associativity of ∧ \nexample (p q r : Prop) :\n (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n begin\n  apply iff.intro,\n  intro h,\n  apply and.intro,\n  have hp : (p ∧ q), from and.left h,\n  have hp' : p, from and.left hp,\n  show p, from hp',\n  apply and.intro,\n  have hp : (p ∧ q), from and.left h,\n  have hp' : p, from and.left hp,\n  have hq : q, from and.right hp,\n  show q, from hq,\n  have hr : r, from and.right h,\n  show r, from hr,\n  intro h',\n  apply and.intro,\n  apply and.elim h',\n  intro h1,\n  intro h2,\n  apply and.intro,\n  exact h1,\n  apply and.left h2,\n  apply and.elim h',\n  intro h1,\n  intro h2,\n  apply and.right h2\nend\n-- Question 4\n-- Associativity of ∨ \nexample (p q r : Prop) : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\nbegin \n apply iff.intro,\n intro h,\n apply or.elim h,\n intro h1,\n apply or.elim h1,\n intro h2,\n apply or.inl,\n apply h2,\n intro h3,\n apply or.inr,\n apply or.inl,\n exact h3,\n intro h4,\n apply or.inr,\n apply or.inr,\n exact h4,\n intro,\n apply or.inl,\n apply or.elim a,\n intro,\n apply or.inl,\n assumption,\n intro,\n apply or.inr,\n apply or.elim a_1,\n intro,\n assumption,\n intro,\n exfalso,\n admit\nend \n-- Question 5\n-- Distributivity of ∧ \nexample (p q r : Prop) :\np ∧ (q ∨ r) <-> (p ∧ q) ∨ (p ∧ 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 apply and.left h,\n exact hq,\n intro hr,\n apply or.inr,\n apply and.intro,\n apply and.left h,\n exact hr,\n intro h',\n apply or.elim h',\n intro h1,\n apply and.intro,\n apply and.left h1,\n apply or.inl,\n apply and.right h1,\n intro h'',\n apply and.intro,\n apply and.left h'',\n apply or.inr,\n apply and.right h'',\nend\n-- Question 6\n-- Distributivity  of ∨ \nexample (p q r : Prop) :\np ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\nbegin \n apply iff.intro,\n intro h,\n apply and.intro,\n apply or.elim h,\n intro h1,\n apply or.inl,\n exact h1,\n intro h2,\n apply or.inr,\n apply and.left h2,\n apply or.elim h,\n intro h3,\n apply or.inl,\n exact h3,\n intro h4,\n apply or.inr,\n apply and.right h4,\n intro h',\n apply or.elim (and.left h'),\n intro h1,\n apply or.inl,\n exact h1,\n intro h2,\n apply or.inr,\n apply and.intro,\n exact h2,\n admit\nend\n--Question 7\nexample (p q : Prop) : p ∧ ¬q → ¬(p → q) := \nbegin \n intro h,\n intro h',\n apply and.right h,\n apply h',\n apply and.left h\nend\n--Question 8\nexample (p : Prop) : ¬(p ∧ ¬p) := \nbegin \n intro h,\n apply and.right h,\n apply and.left h\nend \n--Question 9\nexample (p q : Prop) : ¬p ∨ ¬q → ¬(p ∧ q) := \nbegin\n intro h,\n intro h',\n apply or.elim h,\n intro h'',\n apply h'',\n apply and.left h',\n intro h1,\n apply h1,\n apply and.right h'\nend \n--Question 10\nexample (p q r : Prop) : (p → (q → r)) ↔ (p ∧ q → r) := \nbegin \n apply iff.intro,\n intros,\n apply a,\n apply a_1.left,\n apply a_1.right,\n intros,\n apply a,\n apply and.intro,\n assumption,\n assumption\nend \n--Question 11\nexample (p q: Prop) : (p → q) → (¬q → ¬p) := \nbegin \nintros,\nintro,\napply a_1,\napply a,\napply a_2\nend\n--Question 12\nexample (p : Prop) : ¬(p ↔ ¬p) := \nbegin \n intro,\n apply iff.elim_left a,\n apply iff.elim_right a,\n intro,\n apply iff.elim_left a,\n assumption,\n assumption,\n apply iff.elim_right a,\n intro,\n apply iff.elim_left a,\n assumption,\n assumption\nend\n--Question 13\nexample (p : Prop) : p ∧ false ↔ false := \nbegin \n apply iff.intro,\n intro,\n apply and.right a,\n intro,\n apply and.intro,\n exfalso,\n assumption,\n assumption\nend \n--Question 14\nexample (p : Prop) : p ∨ false ↔ p := \nbegin\n apply iff.intro,\n intro,\n apply or.elim a,\n intro,\n assumption,\n intro,\n exfalso,\n assumption,\n intro,\n apply or.inl,\n assumption\nend\n--Question 15\nexample (p q : Prop) : (¬p ∨ q) → (p → q) := \nbegin\n intro,\n intro,\n apply or.elim a,\n intro,\n exfalso,\n apply a_2,\n assumption,\n intro,\n apply a_2 \nend\n--Question 16\nexample (p q : Prop) : ¬p → (p → q) := \nbegin\nintro,\nintro,\nexfalso,\napply a,\nassumption \nend \n--Question 17\nexample (p : Prop) : p ∨ ¬p := \nbegin\n apply or.inr,\n admit\nend \n--Question 18\nexample (p q : Prop) : (¬q → ¬p) → (p → q) := \nbegin\n intro,\n intro,\n admit\nend \n--Question 19\nexample (p q : Prop) : (p → q) → (¬p ∨ q) := \nbegin\n intro,\n apply or.inr,\n apply a,\n admit\nend \n--Question 20\nexample (p q : Prop) : (((p → q) → p) → p) := \nbegin \n intro,\n apply a,\n intro,\n admit\nend\n--Question 21\nexample (p q : Prop) : ¬(p → q) → p ∧ ¬q := \nbegin\n intro,\n apply and.intro,\n exfalso,\n admit\nend\n--Question 22\nexample (p q : Prop) : ¬(p ∧ q) → ¬p ∨ ¬q := \nbegin\n intro,\n apply or.inl, \n intro,\n apply a,\n apply and.intro,\n assumption,\n exfalso,\n apply a,\n admit\nend\n--Question 23\nexample (p r s : Prop) : (p → r ∨ s) → ((p → r) ∨ (p → s)) := \nbegin\n intro,\n apply or.inr,\n intro,\n admit \nend\n--Question 24\nexample (p q r : Prop) : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := \nbegin\n apply iff.intro,\n intro,\n apply and.intro,\n intro,\n apply a,\n apply or.inl,\n assumption,\n intro,\n apply a,\n apply or.inr,\n assumption,\n intro,\n intro,\n apply and.left a,\n admit\nend\n--Question 25\nexample (p q : Prop) : ¬(p ∨ q) ↔ ¬p ∧ ¬q := \nbegin\n apply iff.intro,\n intro,\n apply and.intro,\n intro,\n apply a,\n apply or.inl,\n assumption,\n intro,\n apply a,\n right,\n assumption,\n intro,\n intro,\n apply and.left a,\n apply or.elim a_1,\n intro,\n assumption,\n intro,\n exfalso,\n apply and.right a,\n assumption \nend\n--Question 26\nexample (p : Prop) : ¬(p ↔ ¬ p) :=\nbegin\n intro,\n apply iff.elim_left a,\n admit \nend \n\n--Chapter 4 Exercises\nvariables (α : Type) (p q : α → Prop)\nvariable a : α\nvariable r : Prop\n--Question 1\nexample : (∃ x : α, r) → r := \nbegin \n intro h,\n cases h with x r,\n assumption \nend \n--Question 2\nexample  : r → (∃ x : α, r) := \nbegin\n intro h,\n admit\nend\n--Question 3\nexample: (∃x: α, true) → (∀x, p x ∧ r) → (∀x, p x) ∧ r :=\nbegin\nintro h,\n\nassume H1 : (∃x: α, true),\nassume H2 : (∀x, p x ∧ r),\nobtain x0 T0, from H₁,\nhave H₃ : p x₀ ∧ r, from H₂ x₀,\nhave Hpx : p x₀, from and.left H₃,\nhave Hr : r, from and.right H₃,\nhave Hapx : (∀x, p x), from \n    (take x, and.left (H₂ x)),\nshow (∀x, p x) ∧ r, from and.intro Hapx Hr\n\n\nexample : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=\nbegin \napply iff.intro,\nintro h,\napply or.inl,\napply or.elim h,\napply iff.intro\n (assume ⟨a, (h1 : p a ∨ q a)⟩,\n  or.elim h1\n      (assume hpa : p a, or.inl ⟨a, hpa⟩)\n      (assume hqa : q a, or.inr ⟨a, hqa⟩))\n  (assume h : (∃ x, p x) ∨ (∃ x, q x),\n    or.elim h\n      (assume ⟨a, hpa⟩, ⟨a, (or.inl hpa)⟩)\n      (assume ⟨a, hqa⟩, ⟨a, (or.inr hqa)⟩)) \n\n", "meta": {"author": "swarnpriya", "repo": "Lean", "sha": "a0a9978fd058041eb1a09aec0e2dd7d19a7436a7", "save_path": "github-repos/lean/swarnpriya-Lean", "path": "github-repos/lean/swarnpriya-Lean/Lean-a0a9978fd058041eb1a09aec0e2dd7d19a7436a7/practice_questions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7575606495945029}}
{"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 analysis.inner_product_space.basic\nimport analysis.special_functions.complex.arg\n\n/-!\n# Rays in the complex numbers\n\nThis file links the definition `same_ray ℝ x y` with the equality of arguments of complex numbers,\nthe usual way this is considered.\n\n## Main statements\n\n* `complex.same_ray_iff` : Two complex numbers are on the same ray iff one of them is zero, or they\n  have the same argument.\n* `complex.abs_add_eq/complex.abs_sub_eq`: If two non zero complex numbers have different argument,\n  then the triangle inequality becomes strict.\n\n-/\n\nvariables {x y : ℂ}\n\nnamespace complex\n\nlemma same_ray_iff : same_ray ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\nbegin\n  rcases eq_or_ne x 0 with rfl | hx,\n  { simp },\n  rcases eq_or_ne y 0 with rfl | hy,\n  { simp },\n  simp only [hx, hy, false_or, same_ray_iff_norm_smul_eq, arg_eq_arg_iff hx hy],\n  field_simp [hx, hy],\n  rw [mul_comm, eq_comm]\nend\n\nlemma abs_add_eq_iff : (x + y).abs = x.abs + y.abs ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\nsame_ray_iff_norm_add.symm.trans same_ray_iff\n\nlemma abs_sub_eq_iff : (x - y).abs = |x.abs - y.abs| ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg :=\nsame_ray_iff_norm_sub.symm.trans same_ray_iff\n\nlemma same_ray_of_arg_eq (h : x.arg = y.arg) : same_ray ℝ x y :=\nsame_ray_iff.mpr $ or.inr $ or.inr h\n\nlemma abs_add_eq (h : x.arg = y.arg) : (x + y).abs = x.abs + y.abs :=\n(same_ray_of_arg_eq h).norm_add\n\nlemma abs_sub_eq (h : x.arg = y.arg) : (x - y).abs = ∥x.abs - y.abs∥ :=\n(same_ray_of_arg_eq h).norm_sub\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/analysis/complex/arg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.757418537363242}}
{"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- A `dart` is a directed edge, consisting of an ordered pair of adjacent vertices,\n  thought of as being a directed edge.\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\n/-- A dart is a directed edge, consisting of an ordered pair of adjacent vertices. -/\n@[ext, derive decidable_eq]\nstructure dart :=\n(fst snd : V)\n(is_adj : G.adj fst snd)\n\ninstance dart.fintype [fintype V] [decidable_rel G.adj] : fintype G.dart :=\nfintype.of_equiv (Σ v, G.neighbor_set v)\n{ to_fun := λ s, ⟨s.fst, s.snd, s.snd.property⟩,\n  inv_fun := λ d, ⟨d.fst, d.snd, d.is_adj⟩,\n  left_inv := λ s, by ext; simp,\n  right_inv := λ d, by ext; simp }\n\nvariables {G}\n\n/-- The edge associated to the dart. -/\ndef dart.edge (d : G.dart) : sym2 V := ⟦(d.fst, d.snd)⟧\n\n@[simp] lemma dart.edge_mem (d : G.dart) : d.edge ∈ G.edge_set :=\nd.is_adj\n\n/-- The dart with reversed orientation from a given dart. -/\ndef dart.rev (d : G.dart) : G.dart :=\n⟨d.snd, d.fst, G.sym d.is_adj⟩\n\n@[simp] lemma dart.rev_edge (d : G.dart) : d.rev.edge = d.edge :=\nsym2.eq_swap\n\n@[simp] lemma dart.rev_rev (d : G.dart) : d.rev.rev = d :=\ndart.ext _ _ rfl rfl\n\n@[simp] lemma dart.rev_involutive : function.involutive (dart.rev : G.dart → G.dart) :=\ndart.rev_rev\n\nlemma dart.rev_ne (d : G.dart) : d.rev ≠ d :=\nbegin\n  cases d with f s h,\n  simp only [dart.rev, not_and, ne.def],\n  rintro rfl,\n  exact false.elim (G.loopless _ h),\nend\n\nlemma dart_edge_eq_iff (d₁ d₂ : G.dart) :\n  d₁.edge = d₂.edge ↔ d₁ = d₂ ∨ d₁ = d₂.rev :=\nbegin\n  cases d₁ with s₁ t₁ h₁,\n  cases d₂ with s₂ t₂ h₂,\n  simp only [dart.edge, dart.rev_edge, dart.rev],\n  rw sym2.eq_iff,\nend\n\nvariables (G)\n\n/-- For a given vertex `v`, this is the bijective map from the neighbor set at `v`\nto the darts `d` with `d.fst = v`. --/\ndef dart_of_neighbor_set (v : V) (w : G.neighbor_set v) : G.dart :=\n⟨v, w, w.property⟩\n\nlemma dart_of_neighbor_set_injective (v : V) : function.injective (G.dart_of_neighbor_set v) :=\nλ e₁ e₂ h, by { injection h with h₁ h₂, exact subtype.ext h₂ }\n\ninstance dart.inhabited [inhabited V] [inhabited (G.neighbor_set (default _))] :\n  inhabited G.dart := ⟨G.dart_of_neighbor_set (default _) (default _)⟩\n\nsection degree_sum\nvariables [fintype V] [decidable_rel G.adj]\n\nlemma dart_fst_fiber [decidable_eq V] (v : V) :\n  univ.filter (λ 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 ⟨_, d.is_adj, dart.ext _ _ rfl rfl⟩, },\n  { rintro ⟨e, he, rfl⟩,\n    refl, },\nend\n\nlemma dart_fst_fiber_card_eq_degree [decidable_eq V] (v : V) :\n  (univ.filter (λ d : G.dart, d.fst = v)).card = G.degree v :=\nbegin\n  have hh := card_image_of_injective univ (G.dart_of_neighbor_set_injective v),\n  rw [finset.card_univ, card_neighbor_set_eq_degree] at hh,\n  rwa dart_fst_fiber,\nend\n\nlemma dart_card_eq_sum_degrees : fintype.card G.dart = ∑ v, G.degree v :=\nbegin\n  haveI h : decidable_eq V := by { classical, apply_instance },\n  simp only [←card_univ, ←dart_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 (λ (d' : G.dart), d'.edge = d.edge)) = {d, d.rev} :=\nfinset.ext (λ d', by simpa using dart_edge_eq_iff d' d)\n\nvariables (G)\n\nlemma dart_edge_fiber_card (e : sym2 V) (h : e ∈ G.edge_set) :\n  (univ.filter (λ (d : G.dart), d.edge = e)).card = 2 :=\nbegin\n  refine quotient.ind (λ p h, _) e h,\n  cases p with v w,\n  let d : G.dart := ⟨v, w, h⟩,\n  convert congr_arg card d.edge_fiber,\n  rw [card_insert_of_not_mem, card_singleton],\n  rw [mem_singleton],\n  exact d.rev_ne.symm,\nend\n\nlemma dart_card_eq_twice_card_edges : fintype.card G.dart = 2 * G.edge_finset.card :=\nbegin\n  rw ←card_univ,\n  rw @card_eq_sum_card_fiberwise _ _ _ dart.edge _ G.edge_finset\n    (λ d h, by { rw mem_edge_finset, apply dart.edge_mem }),\n  rw [←mul_comm, sum_const_nat],\n  intros e h,\n  apply G.dart_edge_fiber_card e,\n  rwa ←mem_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 : ∑ 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 (λ v, odd (G.degree v))).card :=\nbegin\n  classical,\n  have h := congr_arg ((λ n, ↑n) : ℕ → 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 [sum_nat_cast, ←sum_filter_ne_zero] at h,\n  rw @sum_congr _ (zmod 2) _ _ (λ v, (G.degree v : zmod 2)) (λ 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 ←zmod.eq_zero_iff_even,\n    convert h,\n    ext v,\n    rw ←zmod.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 (λ w, w ≠ v ∧ odd (G.degree w))).card :=\nbegin\n  rcases G.even_card_odd_degree_vertices with ⟨k, hg⟩,\n  have hk : 0 < k,\n  { have hh : (filter (λ (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 [←card_pos, hg, zero_lt_mul_left] at hh,\n    exact zero_lt_two, },\n  have hc : (λ (w : V), w ≠ v ∧ odd (G.degree w)) = (λ (w : V), odd (G.degree w) ∧ w ≠ v),\n  { ext w,\n    rw and_comm, },\n  simp only [hc, filter_congr_decidable],\n  rw [←filter_filter, filter_ne', card_erase_of_mem],\n  { use k - 1,\n    rw [nat.pred_eq_succ_iff, hg, nat.mul_sub_left_distrib, ← nat.sub_add_comm, eq_comm,\n      ← (nat.sub_eq_iff_eq_add _).symm],\n    { ring },\n    { exact add_le_add_right (zero_le (2 * k)) 2 },\n    { exact nat.mul_le_mul_left _ hk } },\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  ∃ (w : V), w ≠ v ∧ odd (G.degree w) :=\nbegin\n  haveI : decidable_eq V := by { classical, apply_instance },\n  rcases G.odd_card_odd_degree_vertices_ne v h with ⟨k, hg⟩,\n  have hg' : (filter (λ (w : V), w ≠ v ∧ odd (G.degree w)) univ).card > 0,\n  { rw hg,\n    apply nat.succ_pos, },\n  rcases card_pos.mp hg' with ⟨w, hw⟩,\n  simp only [true_and, mem_filter, mem_univ, ne.def] at hw,\n  exact ⟨w, hw⟩,\nend\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/degree_sum.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7574185323047178}}
{"text": "/-\nCopyright (c) 2022 Violeta Hernández Palacios. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Violeta Hernández Palacios\n-/\nimport computability.primrec\nimport tactic.linarith\n\n/-!\n# Ackermann function\n\nIn this file, we define the two-argument Ackermann function `ack`. Despite having a recursive\ndefinition, we show that this isn't a primitive recursive function.\n\n## Main results\n\n- `exists_lt_ack_of_primrec`: any primitive recursive function is pointwise bounded above by `ack m`\n  for some `m`.\n- `not_primrec₂_ack`: the two-argument Ackermann function is not primitive recursive.\n\n## Proof approach\n\nWe very broadly adapt the proof idea from\nhttps://www.planetmath.org/ackermannfunctionisnotprimitiverecursive. Namely, we prove that for any\nprimitive recursive `f : ℕ → ℕ`, there exists `m` such that `f n < ack m n` for all `n`. This then\nimplies that `λ n, ack n n` can't be primitive recursive, and so neither can `ack`. We aren't able\nto use the same bounds as in that proof though, since our approach of using pairing functions\ndiffers from their approach of using multivariate functions.\n\nThe important bounds we show during the main inductive proof (`exists_lt_ack_of_primrec`) are the\nfollowing. Assuming `∀ n, f n < ack a n` and `∀ n, g n < ack b n`, we have:\n\n- `∀ n, nat.mkpair (f n) (g n) < ack (max a b + 3) n`.\n- `∀ n, g (f n) < ack (max a b + 2) n`.\n- `∀ n, nat.elim (f n.unpair.1) (λ (y IH : ℕ), g (nat.mkpair n.unpair.1 (nat.mkpair y IH)))\n  n.unpair.2 < ack (max a b + 9) n`.\n\nThe last one is evidently the hardest. Using `nat.unpair_add_le`, we reduce it to the more\nmanageable\n\n- `∀ m n, elim (f m) (λ (y IH : ℕ), g (nat.mkpair m (nat.mkpair y IH))) n <\n  ack (max a b + 9) (m + n)`.\n\nWe then prove this by induction on `n`. Our proof crucially depends on `ack_mkpair_lt`, which is\napplied twice, giving us a constant of `4 + 4`. The rest of the proof consists of simpler bounds\nwhich bump up our constant to `9`.\n-/\n\nopen nat\n\n/-- The two-argument Ackermann function, defined so that\n\n- `ack 0 n = n + 1`\n- `ack (m + 1) 0 = ack m 1`\n- `ack (m + 1) (n + 1) = ack m (ack (m + 1) n)`.\n\nThis is of interest as both a fast-growing function, and as an example of a recursive function that\nisn't primitive recursive. -/\ndef ack : ℕ → ℕ → ℕ\n| 0       n       := n + 1\n| (m + 1) 0       := ack m 1\n| (m + 1) (n + 1) := ack m (ack (m + 1) n)\n\n@[simp] theorem ack_zero (n : ℕ) : ack 0 n = n + 1 := by rw ack\n@[simp] theorem ack_succ_zero (m : ℕ) : ack (m + 1) 0 = ack m 1 := by rw ack\n@[simp] theorem ack_succ_succ (m n : ℕ) : ack (m + 1) (n + 1) = ack m (ack (m + 1) n) := by rw ack\n\n@[simp] theorem ack_one (n : ℕ) : ack 1 n = n + 2 :=\nbegin\n  induction n with n IH,\n  { simp },\n  { simp [IH] }\nend\n\n@[simp] theorem ack_two (n : ℕ) : ack 2 n = 2 * n + 3 :=\nbegin\n  induction n with n IH,\n  { simp },\n  { simp [IH, mul_succ] }\nend\n\nprivate theorem ack_three_aux (n : ℕ) : (ack 3 n : ℤ) = 2 ^ (n + 3) - 3 :=\nbegin\n  induction n with n IH,\n  { simp, norm_num },\n  { simp [IH, pow_succ],\n    rw [mul_sub, sub_add],\n    norm_num }\nend\n\n@[simp] theorem ack_three (n : ℕ) : ack 3 n = 2 ^ (n + 3) - 3 :=\nbegin\n  zify,\n  rw cast_sub,\n  { exact_mod_cast ack_three_aux n },\n  { have H : 3 ≤ 2 ^ 3 := by norm_num,\n    exact H.trans (pow_mono one_le_two $ le_add_left le_rfl) }\nend\n\ntheorem ack_pos : ∀ m n, 0 < ack m n\n| 0       n       := by simp\n| (m + 1) 0       := by { rw ack_succ_zero, apply ack_pos }\n| (m + 1) (n + 1) := by { rw ack_succ_succ, apply ack_pos }\n\ntheorem one_lt_ack_succ_left : ∀ m n, 1 < ack (m + 1) n\n| 0       n       := by simp\n| (m + 1) 0       := by { rw ack_succ_zero, apply one_lt_ack_succ_left }\n| (m + 1) (n + 1) := by { rw ack_succ_succ, apply one_lt_ack_succ_left }\n\ntheorem one_lt_ack_succ_right : ∀ m n, 1 < ack m (n + 1)\n| 0       n := by simp\n| (m + 1) n := begin\n  rw ack_succ_succ,\n  cases exists_eq_succ_of_ne_zero (ack_pos (m + 1) n).ne',\n  rw h,\n  apply one_lt_ack_succ_right\nend\n\ntheorem ack_strict_mono_right : ∀ m, strict_mono (ack m)\n| 0 n₁ n₂ h := by simpa using h\n| (m + 1) 0 (n + 1) h := begin\n  rw [ack_succ_zero, ack_succ_succ],\n  exact ack_strict_mono_right _ (one_lt_ack_succ_left m n)\nend\n| (m + 1) (n₁ + 1) (n₂ + 1) h := begin\n  rw [ack_succ_succ, ack_succ_succ],\n  apply ack_strict_mono_right _ (ack_strict_mono_right _ _),\n  rwa add_lt_add_iff_right at h\nend\n\ntheorem ack_mono_right (m : ℕ) : monotone (ack m) := (ack_strict_mono_right m).monotone\n\ntheorem ack_injective_right (m : ℕ) : function.injective (ack m) :=\n(ack_strict_mono_right m).injective\n\n@[simp] theorem ack_lt_iff_right {m n₁ n₂ : ℕ} : ack m n₁ < ack m n₂ ↔ n₁ < n₂ :=\n(ack_strict_mono_right m).lt_iff_lt\n\n@[simp] theorem ack_le_iff_right {m n₁ n₂ : ℕ} : ack m n₁ ≤ ack m n₂ ↔ n₁ ≤ n₂ :=\n(ack_strict_mono_right m).le_iff_le\n\n@[simp] theorem ack_inj_right {m n₁ n₂ : ℕ} : ack m n₁ = ack m n₂ ↔ n₁ = n₂ :=\n(ack_injective_right m).eq_iff\n\ntheorem max_ack_right (m n₁ n₂ : ℕ) : ack m (max n₁ n₂) = max (ack m n₁) (ack m n₂) :=\n(ack_mono_right m).map_max\n\ntheorem add_lt_ack : ∀ m n, m + n < ack m n\n| 0       n       := by simp\n| (m + 1) 0       := by simpa using add_lt_ack m 1\n| (m + 1) (n + 1) :=\ncalc (m + 1) + n + 1\n      ≤ m + (m + n + 2) : by linarith\n  ... < ack m (m + n + 2) : add_lt_ack _ _\n  ... ≤ ack m (ack (m + 1) n) : ack_mono_right m $\n          le_of_eq_of_le (by ring_nf) $ succ_le_of_lt $ add_lt_ack (m + 1) n\n  ... = ack (m + 1) (n + 1) : (ack_succ_succ m n).symm\n\ntheorem add_add_one_le_ack (m n : ℕ) : m + n + 1 ≤ ack m n := succ_le_of_lt (add_lt_ack m n)\n\ntheorem lt_ack_left (m n : ℕ) : m < ack m n := (self_le_add_right m n).trans_lt $ add_lt_ack m n\ntheorem lt_ack_right (m n : ℕ) : n < ack m n := (self_le_add_left n m).trans_lt $ add_lt_ack m n\n\n-- we reorder the arguments to appease the equation compiler\nprivate theorem ack_strict_mono_left' : ∀ {m₁ m₂} n, m₁ < m₂ → ack m₁ n < ack m₂ n\n| m 0 n := λ h, (nat.not_lt_zero m h).elim\n| 0 (m + 1) 0 := λ h, by simpa using one_lt_ack_succ_right m 0\n| 0 (m + 1) (n + 1) := λ h, begin\n  rw [ack_zero, ack_succ_succ],\n  apply lt_of_le_of_lt (le_trans _ $ add_le_add_left (add_add_one_le_ack _ _) m) (add_lt_ack _ _),\n  linarith\nend\n| (m₁ + 1) (m₂ + 1) 0 := λ h, by simpa using ack_strict_mono_left' 1 ((add_lt_add_iff_right 1).1 h)\n| (m₁ + 1) (m₂ + 1) (n + 1) := λ h, begin\n  rw [ack_succ_succ, ack_succ_succ],\n  exact (ack_strict_mono_left' _ $ (add_lt_add_iff_right 1).1 h).trans\n    (ack_strict_mono_right _ $ ack_strict_mono_left' n h)\nend\n\ntheorem ack_strict_mono_left (n : ℕ) : strict_mono (λ m, ack m n) :=\nλ m₁ m₂, ack_strict_mono_left' n\n\ntheorem ack_mono_left (n : ℕ) : monotone (λ m, ack m n) := (ack_strict_mono_left n).monotone\n\ntheorem ack_injective_left (n : ℕ) : function.injective (λ m, ack m n) :=\n(ack_strict_mono_left n).injective\n\n@[simp] theorem ack_lt_iff_left {m₁ m₂ n : ℕ} : ack m₁ n < ack m₂ n ↔ m₁ < m₂ :=\n(ack_strict_mono_left n).lt_iff_lt\n\n@[simp] theorem ack_le_iff_left {m₁ m₂ n : ℕ} : ack m₁ n ≤ ack m₂ n ↔ m₁ ≤ m₂ :=\n(ack_strict_mono_left n).le_iff_le\n\n@[simp] theorem ack_inj_left {m₁ m₂ n : ℕ} : ack m₁ n = ack m₂ n ↔ m₁ = m₂ :=\n(ack_injective_left n).eq_iff\n\ntheorem max_ack_left (m₁ m₂ n : ℕ) : ack (max m₁ m₂) n = max (ack m₁ n) (ack m₂ n) :=\n(ack_mono_left n).map_max\n\ntheorem ack_le_ack {m₁ m₂ n₁ n₂ : ℕ} (hm : m₁ ≤ m₂) (hn : n₁ ≤ n₂) : ack m₁ n₁ ≤ ack m₂ n₂ :=\n(ack_mono_left n₁ hm).trans $ ack_mono_right m₂ hn\n\ntheorem ack_succ_right_le_ack_succ_left (m n : ℕ) : ack m (n + 1) ≤ ack (m + 1) n :=\nbegin\n  cases n,\n  { simp },\n  { rw [ack_succ_succ, succ_eq_add_one],\n    apply ack_mono_right m (le_trans _ $ add_add_one_le_ack _ n),\n    linarith }\nend\n\n-- All the inequalities from this point onwards are specific to the main proof.\n\nprivate theorem sq_le_two_pow_add_one_minus_three (n : ℕ) : n ^ 2 ≤ 2 ^ (n + 1) - 3 :=\nbegin\n  induction n with k hk,\n  { norm_num },\n  { cases k,\n    { norm_num },\n    { rw [succ_eq_add_one, add_sq, pow_succ 2, two_mul (2 ^ _), add_tsub_assoc_of_le,\n        add_comm (2 ^ _), add_assoc],\n      { apply add_le_add hk,\n        norm_num,\n        apply succ_le_of_lt,\n        rw [pow_succ, mul_lt_mul_left (zero_lt_two' ℕ)],\n        apply lt_two_pow },\n      { rw [pow_succ, pow_succ],\n        linarith [one_le_pow k 2 zero_lt_two] } } }\nend\n\ntheorem ack_add_one_sq_lt_ack_add_three : ∀ m n, (ack m n + 1) ^ 2 ≤ ack (m + 3) n\n| 0       n       := by simpa using sq_le_two_pow_add_one_minus_three (n + 2)\n| (m + 1) 0       := by { rw [ack_succ_zero, ack_succ_zero], apply ack_add_one_sq_lt_ack_add_three }\n| (m + 1) (n + 1) := begin\n  rw [ack_succ_succ, ack_succ_succ],\n  apply (ack_add_one_sq_lt_ack_add_three _ _).trans (ack_mono_right _ $ ack_mono_left _ _),\n  linarith\nend\n\ntheorem ack_ack_lt_ack_max_add_two (m n k : ℕ) : ack m (ack n k) < ack (max m n + 2) k :=\ncalc ack m (ack n k)\n      ≤ ack (max m n) (ack n k) : ack_mono_left _ (le_max_left _ _)\n  ... < ack (max m n) (ack (max m n + 1) k) : ack_strict_mono_right _ $ ack_strict_mono_left k $\n          lt_succ_of_le $ le_max_right m n\n  ... = ack (max m n + 1) (k + 1) : (ack_succ_succ _ _).symm\n  ... ≤ ack (max m n + 2) k : ack_succ_right_le_ack_succ_left _ _\n\ntheorem ack_add_one_sq_lt_ack_add_four (m n : ℕ) : ack m ((n + 1) ^ 2) < ack (m + 4) n :=\ncalc ack m ((n + 1) ^ 2)\n      < ack m ((ack m n + 1) ^ 2) : ack_strict_mono_right m $\n          pow_lt_pow_of_lt_left (succ_lt_succ $ lt_ack_right m n) zero_lt_two\n  ... ≤ ack m (ack (m + 3) n) : ack_mono_right m $ ack_add_one_sq_lt_ack_add_three m n\n  ... ≤ ack (m + 2) (ack (m + 3) n) : ack_mono_left _ $ by linarith\n  ... = ack (m + 3) (n + 1) : (ack_succ_succ _ n).symm\n  ... ≤ ack (m + 4) n : ack_succ_right_le_ack_succ_left _ n\n\ntheorem ack_mkpair_lt (m n k : ℕ) : ack m (mkpair n k) < ack (m + 4) (max n k) :=\n(ack_strict_mono_right m $ mkpair_lt_max_add_one_sq n k).trans $ ack_add_one_sq_lt_ack_add_four _ _\n\n/-- If `f` is primitive recursive, there exists `m` such that `f n < ack m n` for all `n`. -/\ntheorem exists_lt_ack_of_nat_primrec {f : ℕ → ℕ} (hf : nat.primrec f) : ∃ m, ∀ n, f n < ack m n :=\nbegin\n  induction hf with f g hf hg IHf IHg f g hf hg IHf IHg f g hf hg IHf IHg,\n  -- Zero function:\n  { exact ⟨0, ack_pos 0⟩ },\n  -- Successor function:\n  { refine ⟨1, λ n, _⟩,\n    rw succ_eq_one_add,\n    apply add_lt_ack },\n  -- Left projection:\n  { refine ⟨0, λ n, _⟩,\n    rw [ack_zero, lt_succ_iff],\n    exact unpair_left_le n },\n  -- Right projection:\n  { refine ⟨0, λ n, _⟩,\n    rw [ack_zero, lt_succ_iff],\n    exact unpair_right_le n },\n  all_goals { cases IHf with a ha, cases IHg with b hb },\n  -- Pairing:\n  { refine ⟨max a b + 3, λ n, (mkpair_lt_max_add_one_sq _ _).trans_le $\n      (nat.pow_le_pow_of_le_left (add_le_add_right _ _) 2).trans $\n        ack_add_one_sq_lt_ack_add_three _ _⟩,\n    rw max_ack_left,\n    exact max_le_max (ha n).le (hb n).le },\n  -- Composition:\n  { exact ⟨max a b + 2, λ n,\n      (ha _).trans $ (ack_strict_mono_right a $ hb n).trans $ ack_ack_lt_ack_max_add_two a b n⟩ },\n  -- Primitive recursion operator:\n  { -- We prove this simpler inequality first.\n    have : ∀ {m n}, elim (f m) (λ y IH, g $ mkpair m $ mkpair y IH) n < ack (max a b + 9) (m + n),\n    { intros m n,\n      -- We induct on n.\n      induction n with n IH,\n      -- The base case is easy.\n      { apply (ha m).trans (ack_strict_mono_left m $ (le_max_left a b).trans_lt _),\n        linarith },\n      { -- We get rid of the first `mkpair`.\n        rw elim_succ,\n        apply (hb _).trans ((ack_mkpair_lt _ _ _).trans_le _),\n        -- If m is the maximum, we get a very weak inequality.\n        cases lt_or_le _ m with h₁ h₁,\n        { rw max_eq_left h₁.le,\n          exact ack_le_ack (add_le_add (le_max_right a b) $ by norm_num) (self_le_add_right m _) },\n        rw max_eq_right h₁,\n        -- We get rid of the second `mkpair`.\n        apply (ack_mkpair_lt _ _ _).le.trans,\n        -- If n is the maximum, we get a very weak inequality.\n        cases lt_or_le _ n with h₂ h₂,\n        { rw [max_eq_left h₂.le, add_assoc],\n          exact ack_le_ack (add_le_add (le_max_right a b) $ by norm_num)\n            ((le_succ n).trans $ self_le_add_left _ _) },\n        rw max_eq_right h₂,\n        -- We now use the inductive hypothesis, and some simple algebraic manipulation.\n        apply (ack_strict_mono_right _ IH).le.trans,\n        rw [add_succ m, add_succ _ 8, ack_succ_succ (_ + 8), add_assoc],\n        exact ack_mono_left _ (add_le_add (le_max_right a b) le_rfl) } },\n    -- The proof is now simple.\n    exact ⟨max a b + 9, λ n, this.trans_le $ ack_mono_right _ $ unpair_add_le n⟩ }\nend\n\ntheorem not_nat_primrec_ack_self : ¬ nat.primrec (λ n, ack n n) :=\nλ h, by { cases exists_lt_ack_of_nat_primrec h with m hm, exact (hm m).false }\n\ntheorem not_primrec_ack_self : ¬ _root_.primrec (λ n, ack n n) :=\nby { rw primrec.nat_iff, exact not_nat_primrec_ack_self }\n\n/-- The Ackermann function is not primitive recursive. -/\ntheorem not_primrec₂_ack : ¬ primrec₂ ack :=\nλ h, not_primrec_ack_self $ h.comp primrec.id primrec.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/computability/ackermann.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8615382076534743, "lm_q1q2_score": 0.7574185221605064}}
{"text": "/-\n© 2021 by the Rector and Visitors of the University of Virginia\n-/\n\nimport algebra.module.basic\nimport linear_algebra.affine_space.affine_equiv\n\n-- Let K be a non-empty field\nuniverses u \nvariables (K : Type u) [field K] [inhabited K]\n\n\nlemma add_smul_l2 : ∀ (r s : K) (x : K × K), (r + s) • x = r • x + s • x := \nbegin\n  intros,\n  ext,\n  simp *,\n  exact right_distrib r s _,\n  simp *,\n  exact right_distrib r s _,\nend\nlemma zero_smul_l2 : ∀ (x : K × K), (0 : K) • x = 0 := \nbegin\n  intros,\n  ext,\n  simp *,\n  simp *,\nend\n\ninstance module_K_KxK : module K (K × K) := \n⟨ add_smul_l2 K, zero_smul_l2 K ⟩ \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/lin2Kcoord/lin2kcoord.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9489172673767973, "lm_q2_score": 0.7981867825403176, "lm_q1q2_score": 0.757413220544436}}
{"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.set.intervals.ord_connected\nimport tactic.wlog\n\n/-!\n# Order connected components 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 define `set.ord_connected_component s x` to be the set of `y` such that\n`set.uIcc x y ⊆ 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₅ space,\nso we only add API needed for this lemma.\n-/\n\nopen function order_dual\nopen_locale interval\n\nnamespace set\n\nvariables {α : Type*} [linear_order α] {s t : set α} {x y z : α}\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 ⊆ s`. Note that it is empty if and only if `x ∉ s`. -/\ndef ord_connected_component (s : set α) (x : α) : set α := {y | [x, y] ⊆ s}\n\nlemma mem_ord_connected_component : y ∈ ord_connected_component s x ↔ [x, y] ⊆ s := iff.rfl\n\nlemma dual_ord_connected_component :\n  ord_connected_component (of_dual ⁻¹' s) (to_dual x) = of_dual ⁻¹' (ord_connected_component s x) :=\next $ to_dual.surjective.forall.2 $ λ x,\n  by { rw [mem_ord_connected_component, dual_uIcc], refl }\n\nlemma ord_connected_component_subset : ord_connected_component s x ⊆ s := λ y hy, hy right_mem_uIcc\n\nlemma subset_ord_connected_component {t} [h : ord_connected s] (hs : x ∈ s) (ht : s ⊆ t) :\n  s ⊆ ord_connected_component t x :=\nλ y hy, (h.uIcc_subset hs hy).trans ht\n\n@[simp] lemma self_mem_ord_connected_component : x ∈ ord_connected_component s x ↔ x ∈ s :=\nby rw [mem_ord_connected_component, uIcc_self, singleton_subset_iff]\n\n@[simp] lemma nonempty_ord_connected_component : (ord_connected_component s x).nonempty ↔ x ∈ s :=\n⟨λ ⟨y, hy⟩, hy $ left_mem_uIcc, λ h, ⟨x, self_mem_ord_connected_component.2 h⟩⟩\n\n@[simp] lemma ord_connected_component_eq_empty : ord_connected_component s x = ∅ ↔ x ∉ s :=\nby rw [← not_nonempty_iff_eq_empty, nonempty_ord_connected_component]\n\n@[simp] lemma ord_connected_component_empty : ord_connected_component ∅ x = ∅ :=\nord_connected_component_eq_empty.2 (not_mem_empty x)\n\n@[simp] lemma ord_connected_component_univ : ord_connected_component univ x = univ :=\nby simp [ord_connected_component]\n\nlemma ord_connected_component_inter (s t : set α) (x : α) :\n  ord_connected_component (s ∩ t) x = ord_connected_component s x ∩ ord_connected_component t x :=\nby simp [ord_connected_component, set_of_and]\n\nlemma mem_ord_connected_component_comm :\n  y ∈ ord_connected_component s x ↔ x ∈ ord_connected_component s y :=\nby rw [mem_ord_connected_component, mem_ord_connected_component, uIcc_comm]\n\nlemma mem_ord_connected_component_trans (hxy : y ∈ ord_connected_component s x)\n  (hyz : z ∈ ord_connected_component s y) : z ∈ ord_connected_component s x :=\ncalc [x, z] ⊆ [x, y] ∪ [y, z] : uIcc_subset_uIcc_union_uIcc\n... ⊆ s : union_subset hxy hyz\n\nlemma ord_connected_component_eq (h : [x, y] ⊆ s) :\n  ord_connected_component s x = ord_connected_component s y :=\next $ λ z, ⟨mem_ord_connected_component_trans (mem_ord_connected_component_comm.2 h),\n  mem_ord_connected_component_trans h⟩\n\ninstance : ord_connected (ord_connected_component s x) :=\nord_connected_of_uIcc_subset_left $ λ y hy z hz, (uIcc_subset_uIcc_left hz).trans hy\n\n/-- Projection from `s : set α` to `α` sending each order connected component of `s` to a single\npoint of this component. -/\nnoncomputable def ord_connected_proj (s : set α) : s → α :=\nλ x : s, (nonempty_ord_connected_component.2 x.prop).some\n\nlemma ord_connected_proj_mem_ord_connected_component (s : set α) (x : s) :\n  ord_connected_proj s x ∈ ord_connected_component s x :=\nnonempty.some_mem _\n\nlemma mem_ord_connected_component_ord_connected_proj (s : set α) (x : s) :\n  ↑x ∈ ord_connected_component s (ord_connected_proj s x) :=\nmem_ord_connected_component_comm.2 $ ord_connected_proj_mem_ord_connected_component s x\n\n@[simp] lemma ord_connected_component_ord_connected_proj (s : set α) (x : s) :\n  ord_connected_component s (ord_connected_proj s x) = ord_connected_component s x :=\nord_connected_component_eq $ mem_ord_connected_component_ord_connected_proj _ _\n\n@[simp] lemma ord_connected_proj_eq {x y : s} :\n  ord_connected_proj s x = ord_connected_proj s y ↔ [(x : α), y] ⊆ s :=\nbegin\n  split; intro h,\n  { rw [← mem_ord_connected_component, ← ord_connected_component_ord_connected_proj, h,\n      ord_connected_component_ord_connected_proj, self_mem_ord_connected_component],\n    exact y.2 },\n  { simp only [ord_connected_proj],\n    congr' 1,\n    exact ord_connected_component_eq h }\nend\n\n/-- A set that intersects each order connected component of a set by a single point. Defined as the\nrange of `set.ord_connected_proj s`. -/\ndef ord_connected_section (s : set α) : set α := range $ ord_connected_proj s\n\nlemma dual_ord_connected_section (s : set α) :\n  ord_connected_section (of_dual ⁻¹' s) = of_dual ⁻¹' (ord_connected_section s) :=\nbegin\n  simp only [ord_connected_section, ord_connected_proj],\n  congr' 1 with x, simp only, congr' 1,\n  exact dual_ord_connected_component\nend\n\nlemma ord_connected_section_subset : ord_connected_section s ⊆ s :=\nrange_subset_iff.2 $ λ x, ord_connected_component_subset $ nonempty.some_mem _\n\nlemma eq_of_mem_ord_connected_section_of_uIcc_subset (hx : x ∈ ord_connected_section s)\n  (hy : y ∈ ord_connected_section s) (h : [x, y] ⊆ s) : x = y :=\nbegin\n  rcases hx with ⟨x, rfl⟩, rcases hy with ⟨y, rfl⟩,\n  exact ord_connected_proj_eq.2 (mem_ord_connected_component_trans\n    (mem_ord_connected_component_trans (ord_connected_proj_mem_ord_connected_component _ _) h)\n    (mem_ord_connected_component_ord_connected_proj _ _))\nend\n\n/-- Given two sets `s t : set α`, the set `set.order_separating_set s t` is the set of points that\nbelong both to some `set.ord_connected_component tᶜ x`, `x ∈ s`, and to some\n`set.ord_connected_component sᶜ x`, `x ∈ 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 ord_separating_set (s t : set α) : set α :=\n(⋃ x ∈ s, ord_connected_component tᶜ x) ∩ (⋃ x ∈ t, ord_connected_component sᶜ x)\n\nlemma ord_separating_set_comm (s t : set α) :\n  ord_separating_set s t = ord_separating_set t s :=\ninter_comm _ _\n\nlemma disjoint_left_ord_separating_set : disjoint s (ord_separating_set s t) :=\ndisjoint.inter_right' _ $ disjoint_Union₂_right.2 $ λ x hx, disjoint_compl_right.mono_right $\n  ord_connected_component_subset\n\nlemma disjoint_right_ord_separating_set : disjoint t (ord_separating_set s t) :=\nord_separating_set_comm t s ▸ disjoint_left_ord_separating_set\n\nlemma dual_ord_separating_set :\n  ord_separating_set (of_dual ⁻¹' s) (of_dual ⁻¹' t) = of_dual ⁻¹' (ord_separating_set s t) :=\nby simp only [ord_separating_set, mem_preimage, ← to_dual.surjective.Union_comp, of_dual_to_dual,\n  dual_ord_connected_component, ← preimage_compl, preimage_inter, preimage_Union]\n\n/-- An auxiliary neighborhood that will be used in the proof of `order_topology.t5_space`. -/\ndef ord_t5_nhd (s t : set α) : set α :=\n⋃ x ∈ s, ord_connected_component (tᶜ ∩ (ord_connected_section $ ord_separating_set s t)ᶜ) x\n\nlemma disjoint_ord_t5_nhd : disjoint (ord_t5_nhd s t) (ord_t5_nhd t s) :=\nbegin\n  rw disjoint_iff_inf_le,\n  rintro x ⟨hx₁, hx₂⟩,\n  rcases mem_Union₂.1 hx₁ with ⟨a, has, ha⟩, clear hx₁,\n  rcases mem_Union₂.1 hx₂ with ⟨b, hbt, hb⟩, clear hx₂,\n  rw [mem_ord_connected_component, subset_inter_iff] at ha hb,\n  wlog hab : a ≤ b,\n  { exact this b hbt a has ha hb (le_of_not_le hab) },\n  cases ha with ha ha', cases hb with hb hb',\n  have hsub : [a, b] ⊆ (ord_separating_set s t).ord_connected_sectionᶜ,\n  { rw [ord_separating_set_comm, uIcc_comm] at hb',\n    calc [a, b] ⊆ [a, x] ∪ [x, b] : uIcc_subset_uIcc_union_uIcc\n    ... ⊆ (ord_separating_set s t).ord_connected_sectionᶜ : union_subset ha' hb' },\n  clear ha' hb',\n  cases le_total x a with hxa hax,\n  { exact hb (Icc_subset_uIcc' ⟨hxa, hab⟩) has },\n  cases le_total b x with hbx hxb,\n  { exact ha (Icc_subset_uIcc ⟨hab, hbx⟩) hbt },\n  have : x ∈ ord_separating_set s t,\n  { exact ⟨mem_Union₂.2 ⟨a, has, ha⟩, mem_Union₂.2 ⟨b, hbt, hb⟩⟩ },\n  lift x to ord_separating_set s t using this,\n  suffices : ord_connected_component (ord_separating_set s t) x ⊆ [a, b],\n    from hsub (this $ ord_connected_proj_mem_ord_connected_component _ _) (mem_range_self _),\n  rintros y (hy : [↑x, y] ⊆ ord_separating_set s t),\n  rw [uIcc_of_le hab, mem_Icc, ← not_lt, ← not_lt],\n  exact ⟨λ hya, disjoint_left.1 disjoint_left_ord_separating_set has\n    (hy $ Icc_subset_uIcc' ⟨hya.le, hax⟩),\n    λ hyb, disjoint_left.1 disjoint_right_ord_separating_set hbt\n      (hy $ Icc_subset_uIcc ⟨hxb, hyb.le⟩)⟩\nend\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/ord_connected_component.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7573819207159463}}
{"text": "import tactic --hide\n\n\n/-\n`split` can also be used for if and only if statements. For example, if you have `⊢ P ↔ Q` and apply\n`split`, then your goal will change from \n\n```\n⊢ P ↔ Q\n```\nto two goals, `⊢ P → Q` and `⊢ Q → P`.\n-/\n\n/- Lemma\nLet $P$ be a logical statement, then $P$ is true if and only if $P$ is true.\n-/\nlemma split_examle_two (P : Prop) : P ↔ P :=\nbegin\n  split,\n  intro p,\n  exact p,\n  intro p,\n  exact p,\nend\n\n/- Tactic : split\n\nIf your lemma has the goal: \n\n```\n⊢ P ∧ Q\n```\n\nthen the  `split` tactic will turn it into *two* goals `⊢ P` and `⊢ Q`.\n\nMoreover, if you have an iff `P ↔ Q` then splitting it will give you two goals, `P → Q` \n(i.e \"`P` only if `Q`\") and `P ← Q ` (i.e \"`P` if `Q`\") to prove.\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/splittac2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8289388083214155, "lm_q1q2_score": 0.7573819207159462}}
{"text": "import .term\n\n@[reducible] def clause := (list term) × (list term)\n\nnamespace clause\n\ndef weaker : clause → clause → Prop \n| ⟨eqs1,les1⟩ ⟨eqs2,les2⟩ := eqs1 ⊆ eqs2 ∧ les1 ⊆ les2 \n\ndef holds (v) : clause → Prop \n| (eqs,les) :=\n  ( (∀ t : term, t ∈ eqs → 0 = term.val v t) \n    ∧ (∀ t : term, t ∈ les → 0 ≤ term.val v t) )\n\nlemma holds_of_weaker {v c1 c2} : \n  weaker c1 c2 → holds v c2 → holds v c1 :=\nbegin\n  intros h1 h2, \n  cases c1 with eqs1 les1, \n  cases c2 with eqs2 les2, \n  constructor, \n  { apply list.forall_mem_of_subset h1.left h2.left }, \n  { apply list.forall_mem_of_subset h1.right h2.right }, \nend\n\ndef sat (c : clause) : Prop :=\n  ∃ v : nat → int, holds v c\n\nlemma sat_of_weaker { c1 c2} : \n  weaker c1 c2 → sat c2 → sat c1 :=\nbegin\n  intros h1 h2, cases h2 with v h2,\n  refine ⟨v,holds_of_weaker h1 h2⟩,\nend\n\ndef unsat (c : clause) : Prop := ¬ c.sat \n\ndef append (c1 c2 : clause) : clause :=\n(c1.fst ++ c2.fst, c1.snd ++ c2.snd)\n\ndef holds_append {v c1 c2} : \nholds v c1 → holds v c2 → holds v (append c1 c2) := \nbegin\n  intros h1 h2, \n  cases c1 with eqs1 les1,\n  cases c2 with eqs2 les2,\n  cases h1, cases h2,\n  constructor; rw list.forall_mem_append; \n  constructor; assumption,\nend\n\nend clause\n\ndef clauses.sat (ps : list clause) : Prop := \n∃ c ∈ ps, clause.sat c  \n\ndef clauses.unsat (ps) : Prop := ¬ clauses.sat ps\n\nlemma clauses.unsat_nil : clauses.unsat [] := \nbegin intro h1, rcases h1 with ⟨c,h1,h2⟩, cases h1 end\n\nlemma clauses.unsat_cons (p ps) : \n  clause.unsat p → clauses.unsat ps → \n  clauses.unsat (p::ps) | h1 h2 h3 := \nbegin\n  simp only [clauses.sat] at h3,\n  rw list.exists_mem_cons_iff at h3, \n  cases h3; contradiction,\nend\n", "meta": {"author": "skbaek", "repo": "omega", "sha": "715e384ed14e8eb177a326700066e7c98269e078", "save_path": "github-repos/lean/skbaek-omega", "path": "github-repos/lean/skbaek-omega/omega-715e384ed14e8eb177a326700066e7c98269e078/clause.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7573734322502984}}
{"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ölzl\n\n! This file was ported from Lean 3 source module dynamics.fixed_points.topology\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 Mathbin.Dynamics.FixedPoints.Basic\nimport Mathbin.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) → 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\n\nvariable {α : Type _} [TopologicalSpace α] [T2Space α] {f : α → α}\n\nopen Function Filter\n\nopen Topology\n\n#print isFixedPt_of_tendsto_iterate /-\n/-- If the iterates `f^[n] x` converge to `y` and `f` is continuous at `y`,\nthen `y` is a fixed point for `f`. -/\ntheorem isFixedPt_of_tendsto_iterate {x y : α} (hy : Tendsto (fun n => (f^[n]) x) atTop (𝓝 y))\n    (hf : ContinuousAt f y) : IsFixedPt f y :=\n  by\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\n#align is_fixed_pt_of_tendsto_iterate isFixedPt_of_tendsto_iterate\n-/\n\n#print isClosed_fixedPoints /-\n/-- The set of fixed points of a continuous map is a closed set. -/\ntheorem isClosed_fixedPoints (hf : Continuous f) : IsClosed (fixedPoints f) :=\n  isClosed_eq hf continuous_id\n#align is_closed_fixed_points isClosed_fixedPoints\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/Dynamics/FixedPoints/Topology.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7573734242052633}}
{"text": "import tactic\nimport group_theory.subgroup.basic\n\nopen subgroup\n\nvariables {G : Type} [group G]\n\nnamespace pullback\n\nvariables {H K : Type} [group H] [group K] \n  (i : H →* G) (j : K →* G) \n\ndef pullback : subgroup (H × K) :=\n{ carrier := {x | i x.1 = j x.2},\n  one_mem' := by simp,\n  mul_mem' := by simp {contextual := tt},\n  inv_mem' := by simp {contextual := tt} }\n\ndef fst : pullback i j →* H := \n{ to_fun := λ x, x.1.1,\n  map_one' := rfl,\n  map_mul' := λ _ _, rfl }\n\ndef snd : pullback i j →* K := \n{ to_fun := λ x, x.1.2,\n  map_one' := rfl,\n  map_mul' := λ _ _, rfl }\n\nlemma comp_fst_eq_comp_snd : i.comp (fst i j) = j.comp (snd i j) :=\nmonoid_hom.ext $ λ x, x.2 \n\ndef restrict {L : Type} [group L] (f : L →* H) (g : L →* K)\n  (hfg : i.comp f = j.comp g) : L →* pullback i j :=\n{ to_fun := λ x, ⟨⟨f x, g x⟩, monoid_hom.congr_fun hfg x⟩,\n  map_one' := subtype.ext (prod.ext (map_one f) (map_one g)),\n  map_mul' := λ a b, subtype.ext (prod.ext (map_mul f _ _) (map_mul g _ _)) }\n\n@[simp] lemma fst_comp_restrict {L : Type} [group L] (f : L →* H) (g : L →* K)\n  (hfg : i.comp f = j.comp g) : \n  (fst i j).comp (restrict i j f g hfg) = f :=\nmonoid_hom.ext (λ _, rfl)\n\n@[simp] lemma snd_comp_restrict {L : Type} [group L] (f : L →* H) (g : L →* K)\n  (hfg : i.comp f = j.comp g) : \n  (snd i j).comp (restrict i j f g hfg) = g :=\nmonoid_hom.ext (λ _, rfl)\n\n@[simp] lemma fst_restrict {L : Type} [group L] (f : L →* H) (g : L →* K)\n  (hfg : i.comp f = j.comp g) (x : L) : \n  fst i j (restrict i j f g hfg x) = f x :=\nrfl\n\n@[simp] lemma snd_restrict {L : Type} [group L] (f : L →* H) (g : L →* K)\n  (hfg : i.comp f = j.comp g) (x : L) : \n  snd i j (restrict i j f g hfg x) = g x :=\nrfl\n\n@[ext] lemma hom_ext {L : Type} [group L] {f g : L →* pullback i j}\n  (h1 : (fst i j).comp f = (fst i j).comp g)\n  (h2 : (snd i j).comp f = (snd i j).comp g) :\n  f = g :=\nmonoid_hom.ext (λ x, subtype.ext (prod.ext \n  (monoid_hom.congr_fun h1 x) \n  (monoid_hom.congr_fun h2 x)))\n\nend pullback\n", "meta": {"author": "ChrisHughes24", "repo": "coq-and-lean-playground", "sha": "7da672891e29c0434909abad315ca6efefcbb989", "save_path": "github-repos/lean/ChrisHughes24-coq-and-lean-playground", "path": "github-repos/lean/ChrisHughes24-coq-and-lean-playground/coq-and-lean-playground-7da672891e29c0434909abad315ca6efefcbb989/lean/representable_functor/examples/rubbish/second_isomorphism_theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.757373422396542}}
{"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\nimport 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 β`: a type synonym for `Π i, β i` with `dist` and `norm` provided by the above.\n* `hamming.to_hamming`, `hamming.of_hamming`: functions for casting between `hamming β` and\n`Π i, β i`.\n* `hamming.normed_add_comm_group`: the Hamming norm forms a normed group on `hamming β`.\n-/\nsection hamming_dist_norm\n\nopen finset function\n\nvariables {α ι : Type*} {β : ι → Type*} [fintype ι] [Π i, decidable_eq (β i)]\nvariables {γ : ι → Type*} [Π i, decidable_eq (γ i)]\n\n/-- The Hamming distance function to the naturals. -/\ndef hamming_dist (x y : Π i, β i) : ℕ := (univ.filter (λ i, x i ≠ y i)).card\n\n/-- Corresponds to `dist_self`. -/\n@[simp] lemma hamming_dist_self (x : Π i, β i) : hamming_dist x x = 0 :=\nby { rw [hamming_dist, card_eq_zero, filter_eq_empty_iff], exact λ _ _ H, H rfl }\n\n/-- Corresponds to `dist_nonneg`. -/\nlemma hamming_dist_nonneg {x y : Π i, β i} : 0 ≤ hamming_dist x y := zero_le _\n\n/-- Corresponds to `dist_comm`. -/\nlemma hamming_dist_comm (x y : Π i, β i) : hamming_dist x y = hamming_dist y x :=\nby simp_rw [hamming_dist, ne_comm]\n\n/-- Corresponds to `dist_triangle`. -/\nlemma hamming_dist_triangle (x y z : Π i, β i) :\n  hamming_dist x z ≤ hamming_dist x y + hamming_dist y z :=\nbegin\n  classical, simp_rw hamming_dist, refine le_trans (card_mono _) (card_union_le _ _),\n  rw ← filter_or, refine monotone_filter_right _ _, intros i h,\n  by_contra' H, exact h (eq.trans H.1 H.2)\nend\n\n/-- Corresponds to `dist_triangle_left`. -/\nlemma hamming_dist_triangle_left (x y z : Π i, β i) :\n  hamming_dist x y ≤ hamming_dist z x + hamming_dist z y :=\nby { rw hamming_dist_comm z, exact hamming_dist_triangle _ _ _ }\n\n/-- Corresponds to `dist_triangle_right`. -/\nlemma hamming_dist_triangle_right (x y z : Π i, β i) :\n  hamming_dist x y ≤ hamming_dist x z + hamming_dist y z :=\nby { rw hamming_dist_comm y, exact hamming_dist_triangle _ _ _ }\n\n/-- Corresponds to `swap_dist`. -/\ntheorem swap_hamming_dist : swap (@hamming_dist _ β _ _) = hamming_dist :=\nby { funext x y, exact hamming_dist_comm _ _ }\n\n/-- Corresponds to `eq_of_dist_eq_zero`. -/\nlemma eq_of_hamming_dist_eq_zero {x y : Π i, β i} : hamming_dist x y = 0 → x = y :=\nby simp_rw [hamming_dist, card_eq_zero, filter_eq_empty_iff, not_not,\n            funext_iff,  mem_univ, forall_true_left, imp_self]\n\n/-- Corresponds to `dist_eq_zero`. -/\n@[simp] lemma hamming_dist_eq_zero {x y : Π i, β i} : hamming_dist x y = 0 ↔ x = y :=\n⟨eq_of_hamming_dist_eq_zero, (λ H, by {rw H, exact hamming_dist_self _})⟩\n\n/-- Corresponds to `zero_eq_dist`. -/\n@[simp] lemma hamming_zero_eq_dist {x y : Π i, β i} : 0 = hamming_dist x y ↔ x = y :=\nby rw [eq_comm, hamming_dist_eq_zero]\n\n/-- Corresponds to `dist_ne_zero`. -/\nlemma hamming_dist_ne_zero {x y : Π i, β i} : hamming_dist x y ≠ 0 ↔ x ≠ y :=\nhamming_dist_eq_zero.not\n\n/-- Corresponds to `dist_pos`. -/\n@[simp] lemma hamming_dist_pos {x y : Π i, β i} : 0 < hamming_dist x y ↔ x ≠ y :=\nby rw [←hamming_dist_ne_zero, iff_not_comm, not_lt, le_zero_iff]\n\n@[simp] lemma hamming_dist_lt_one {x y : Π i, β i} : hamming_dist x y < 1 ↔ x = y :=\nby rw [nat.lt_one_iff, hamming_dist_eq_zero]\n\nlemma hamming_dist_le_card_fintype {x y : Π i, β i} :\n  hamming_dist x y ≤ fintype.card ι := card_le_univ _\n\nlemma hamming_dist_comp_le_hamming_dist (f : Π i, γ i → β i) {x y : Π i, γ i} :\n  hamming_dist (λ i, f i (x i)) (λ i, f i (y i)) ≤ hamming_dist x y :=\ncard_mono (monotone_filter_right _ $ λ i H1 H2, H1 $ congr_arg (f i) H2)\n\nlemma hamming_dist_comp (f : Π i, γ i → β i) {x y : Π i, γ i} (hf : Π i, injective (f i)) :\n  hamming_dist (λ i, f i (x i)) (λ i, f i (y i)) = hamming_dist x y :=\nbegin\n  refine le_antisymm (hamming_dist_comp_le_hamming_dist _) _,\n  exact card_mono (monotone_filter_right _ $ λ i H1 H2, H1 $ hf i H2)\nend\n\nlemma hamming_dist_smul_le_hamming_dist [Π i, has_smul α (β i)] {k : α} {x y : Π i, β i} :\n  hamming_dist (k • x) (k • y) ≤ hamming_dist x y :=\nhamming_dist_comp_le_hamming_dist $ λ i, (•) k\n\n/-- Corresponds to `dist_smul` with the discrete norm on `α`. -/\nlemma hamming_dist_smul [Π i, has_smul α (β i)] {k : α} {x y : Π i, β i}\n  (hk : Π i, is_smul_regular (β i) k) : hamming_dist (k • x) (k • y) = hamming_dist x y :=\nhamming_dist_comp (λ i, (•) k) hk\n\nsection has_zero\n\nvariables [Π i, has_zero (β i)] [Π i, has_zero (γ i)]\n\n/-- The Hamming weight function to the naturals. -/\ndef hamming_norm (x : Π i, β i) : ℕ := (univ.filter (λ i, x i ≠ 0)).card\n\n/-- Corresponds to `dist_zero_right`. -/\n@[simp] lemma hamming_dist_zero_right (x : Π i, β i) : hamming_dist x 0 = hamming_norm x := rfl\n\n/-- Corresponds to `dist_zero_left`. -/\n@[simp] lemma hamming_dist_zero_left : hamming_dist (0 : Π i, β i) = hamming_norm :=\nfunext $ λ x, by rw [hamming_dist_comm, hamming_dist_zero_right]\n\n/-- Corresponds to `norm_nonneg`. -/\n@[simp] lemma hamming_norm_nonneg {x : Π i, β i} : 0 ≤ hamming_norm x := zero_le _\n\n/-- Corresponds to `norm_zero`. -/\n@[simp] lemma hamming_norm_zero : hamming_norm (0 : Π i, β i) = 0 := hamming_dist_self _\n\n/-- Corresponds to `norm_eq_zero`. -/\n@[simp] lemma hamming_norm_eq_zero {x : Π i, β i} : hamming_norm x = 0 ↔ x = 0 :=\nhamming_dist_eq_zero\n\n/-- Corresponds to `norm_ne_zero_iff`. -/\nlemma hamming_norm_ne_zero_iff {x : Π i, β i} : hamming_norm x ≠ 0 ↔ x ≠ 0 :=\nhamming_norm_eq_zero.not\n\n/-- Corresponds to `norm_pos_iff`. -/\n@[simp] lemma hamming_norm_pos_iff {x : Π i, β i} : 0 < hamming_norm x ↔ x ≠ 0 := hamming_dist_pos\n\n@[simp] lemma hamming_norm_lt_one {x : Π i, β i} : hamming_norm x < 1 ↔ x = 0 := hamming_dist_lt_one\n\nlemma hamming_norm_le_card_fintype {x : Π i, β i} : hamming_norm x ≤ fintype.card ι :=\nhamming_dist_le_card_fintype\n\nlemma hamming_norm_comp_le_hamming_norm (f : Π i, γ i → β i) {x : Π i, γ i} (hf : Π i, f i 0 = 0) :\n  hamming_norm (λ i, f i (x i)) ≤ hamming_norm x :=\nby {convert hamming_dist_comp_le_hamming_dist f, simp_rw hf, refl}\n\nlemma hamming_norm_comp (f : Π i, γ i → β i) {x : Π i, γ i} (hf₁ : Π i, injective (f i))\n  (hf₂ : Π i, f i 0 = 0) : hamming_norm (λ i, f i (x i)) = hamming_norm x :=\nby {convert hamming_dist_comp f hf₁, simp_rw hf₂, refl}\n\nlemma hamming_norm_smul_le_hamming_norm [has_zero α] [Π i, smul_with_zero α (β i)] {k : α}\n  {x : Π i, β i} : hamming_norm (k • x) ≤ hamming_norm x :=\nhamming_norm_comp_le_hamming_norm (λ i (c : β i), k • c) (λ i, by simp_rw smul_zero)\n\nlemma hamming_norm_smul [has_zero α] [Π i, smul_with_zero α (β i)] {k : α}\n  (hk : ∀ i, is_smul_regular (β i) k) (x : Π i, β i) : hamming_norm (k • x) = hamming_norm x :=\nhamming_norm_comp (λ i (c : β i), k • c) hk (λ i, by simp_rw smul_zero)\n\nend has_zero\n\n/-- Corresponds to `dist_eq_norm`. -/\nlemma hamming_dist_eq_hamming_norm [Π i, add_group (β i)] (x y : Π i, β i) :\n  hamming_dist x y = hamming_norm (x - y) :=\nby simp_rw [hamming_norm, hamming_dist, pi.sub_apply, sub_ne_zero]\n\nend hamming_dist_norm\n\n/-! ### The `hamming` type synonym -/\n\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 {ι : Type*} (β : ι → Type*) : Type* := Π i, β i\n\nnamespace hamming\n\nvariables {α ι : Type*} {β : ι → Type*}\n\n/-! Instances inherited from normal Pi types. -/\n\ninstance [Π i, inhabited (β i)] : inhabited (hamming β) := ⟨λ i, default⟩\ninstance [decidable_eq ι] [fintype ι] [Π i, fintype (β i)] : fintype (hamming β) := pi.fintype\ninstance [inhabited ι] [∀ i, nonempty (β i)] [nontrivial (β default)] :\n  nontrivial (hamming β) := pi.nontrivial\ninstance [fintype ι] [Π i, decidable_eq (β i)] : decidable_eq (hamming β) :=\nfintype.decidable_pi_fintype\n\ninstance [Π i, has_zero (β i)]    : has_zero (hamming β) := pi.has_zero\ninstance [Π i, has_neg (β i)]     : has_neg (hamming β) := pi.has_neg\ninstance [Π i, has_add (β i)]     : has_add (hamming β) := pi.has_add\ninstance [Π i, has_sub (β i)]     : has_sub (hamming β) := pi.has_sub\ninstance [Π i, has_smul α (β i)]  : has_smul α (hamming β) := pi.has_smul\n\ninstance [has_zero α] [Π i, has_zero (β i)] [Π i, smul_with_zero α (β i)] :\n  smul_with_zero α (hamming β) := pi.smul_with_zero _\ninstance [Π i, add_monoid (β i)] : add_monoid (hamming β) := pi.add_monoid\ninstance [Π i, add_comm_monoid (β i)] : add_comm_monoid (hamming β) := pi.add_comm_monoid\ninstance [Π i, add_comm_group (β i)] : add_comm_group (hamming β) := pi.add_comm_group\ninstance (α) [semiring α] (β : ι → Type*) [Π i, add_comm_monoid (β i)]\n  [Π i, module α (β i)] : module α (hamming β) := pi.module _ _ _\n\n/-! API to/from the type synonym. -/\n\n/-- `to_hamming` is the identity function to the `hamming` of a type.  -/\n@[pattern] def to_hamming : (Π i, β i) ≃ hamming β := equiv.refl _\n\n/-- `of_hamming` is the identity function from the `hamming` of a type.  -/\n@[pattern] def of_hamming : hamming β ≃ Π i, β i := equiv.refl _\n\n@[simp] lemma to_hamming_symm_eq : (@to_hamming _ β).symm = of_hamming := rfl\n@[simp] lemma of_hamming_symm_eq : (@of_hamming _ β).symm = to_hamming := rfl\n@[simp] lemma to_hamming_of_hamming (x : hamming β) : to_hamming (of_hamming x) = x := rfl\n@[simp] lemma of_hamming_to_hamming (x : Π i, β i) : of_hamming (to_hamming x) = x := rfl\n@[simp] lemma to_hamming_inj {x y : Π i, β i} : to_hamming x = to_hamming y ↔ x = y := iff.rfl\n@[simp] lemma of_hamming_inj {x y : hamming β} : of_hamming x = of_hamming y ↔ x = y := iff.rfl\n\n@[simp] lemma to_hamming_zero [Π i, has_zero (β i)] : to_hamming (0 : Π i, β i) = 0 := rfl\n@[simp] lemma of_hamming_zero [Π i, has_zero (β i)] : of_hamming (0 : hamming β) = 0 := rfl\n@[simp] lemma to_hamming_neg [Π i, has_neg (β i)] {x : Π i, β i} :\n  to_hamming (-x) = - to_hamming x := rfl\n@[simp] lemma of_hamming_neg [Π i, has_neg (β i)] {x : hamming β} :\n  of_hamming (-x)  = - of_hamming x := rfl\n@[simp] lemma to_hamming_add [Π i, has_add (β i)] {x y : Π i, β i} :\n  to_hamming (x + y) = to_hamming x + to_hamming y := rfl\n@[simp] lemma of_hamming_add [Π i, has_add (β i)] {x y : hamming β} :\n  of_hamming (x + y) = of_hamming x + of_hamming y := rfl\n@[simp] lemma to_hamming_sub [Π i, has_sub (β i)] {x y : Π i, β i} :\n  to_hamming (x - y) = to_hamming x - to_hamming y := rfl\n@[simp] lemma of_hamming_sub [Π i, has_sub (β i)] {x y : hamming β} :\n  of_hamming (x - y) = of_hamming x - of_hamming y := rfl\n@[simp] lemma to_hamming_smul [Π i, has_smul α (β i)] {r : α} {x : Π i, β i} :\n  to_hamming (r • x) = r • to_hamming x := rfl\n@[simp] lemma of_hamming_smul [Π i, has_smul α (β i)] {r : α} {x : hamming β} :\n  of_hamming (r • x) = r • of_hamming x := rfl\n\nsection\n\n/-! Instances equipping `hamming` with `hamming_norm` and `hamming_dist`. -/\n\nvariables [fintype ι] [Π i, decidable_eq (β i)]\n\ninstance : has_dist (hamming β) := ⟨λ x y, hamming_dist (of_hamming x) (of_hamming y)⟩\n\n@[simp, push_cast] \n\ninstance : pseudo_metric_space (hamming β) :=\n{ dist_self        := by { push_cast, exact_mod_cast hamming_dist_self },\n  dist_comm        := by { push_cast, exact_mod_cast hamming_dist_comm },\n  dist_triangle    := by { push_cast, exact_mod_cast hamming_dist_triangle },\n  to_uniform_space := ⊥,\n  uniformity_dist  := uniformity_dist_of_mem_uniformity _ _ $ λ s, begin\n    push_cast,\n    split,\n    { refine λ hs, ⟨1, zero_lt_one, λ _ _ hab, _⟩,\n      rw_mod_cast [hamming_dist_lt_one] at hab,\n      rw [of_hamming_inj, ← mem_id_rel] at hab,\n      exact hs hab },\n    { rintros ⟨_, hε, hs⟩ ⟨_, _⟩ hab,\n      rw mem_id_rel at hab,\n      rw hab,\n      refine hs (lt_of_eq_of_lt _ hε),\n      exact_mod_cast hamming_dist_self _ }\n  end,\n  to_bornology     := ⟨⊥, bot_le⟩,\n  cobounded_sets   := begin\n    ext,\n    push_cast,\n    refine iff_of_true (filter.mem_sets.mpr filter.mem_bot) ⟨fintype.card ι, λ _ _ _ _, _⟩,\n    exact_mod_cast hamming_dist_le_card_fintype\n  end,\n  ..hamming.has_dist }\n\n@[simp, push_cast] lemma nndist_eq_hamming_dist (x y : hamming β) :\n  nndist x y = hamming_dist (of_hamming x) (of_hamming y) := rfl\n\ninstance : metric_space (hamming β) :=\n{ eq_of_dist_eq_zero  :=\n  by { push_cast, exact_mod_cast @eq_of_hamming_dist_eq_zero _ _ _ _ },\n  ..hamming.pseudo_metric_space }\n\ninstance [Π i, has_zero (β i)] : has_norm (hamming β) := ⟨λ x, hamming_norm (of_hamming x)⟩\n\n@[simp, push_cast] lemma norm_eq_hamming_norm [Π i, has_zero (β i)] (x : hamming β) :\n  ‖x‖ = hamming_norm (of_hamming x) := rfl\n\ninstance [Π i, add_comm_group (β i)] : seminormed_add_comm_group (hamming β) :=\n{ dist_eq := by { push_cast, exact_mod_cast hamming_dist_eq_hamming_norm }, ..pi.add_comm_group }\n\n@[simp, push_cast] lemma nnnorm_eq_hamming_norm [Π i, add_comm_group (β i)] (x : hamming β) :\n  ‖x‖₊ = hamming_norm (of_hamming x) := rfl\n\ninstance [Π i, add_comm_group (β i)] : normed_add_comm_group (hamming β) :=\n{ ..hamming.seminormed_add_comm_group }\n\nend\n\nend hamming\n", "meta": {"author": "leanprover-community", "repo": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/information_theory/hamming.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7573734219914671}}
{"text": "/-\nCopyright (c) 2022 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 combinatorics.catalan\n! leanprover-community/mathlib commit 26b40791e4a5772a4e53d0e28e4df092119dc7da\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.Fin\nimport Mathlib.Algebra.BigOperators.NatAntidiagonal\nimport Mathlib.Algebra.CharZero.Lemmas\nimport Mathlib.Data.Finset.NatAntidiagonal\nimport Mathlib.Data.Nat.Choose.Central\nimport Mathlib.Data.Tree\nimport Mathlib.Tactic.FieldSimp\n\n/-!\n# Catalan numbers\n\nThe Catalan numbers (http://oeis.org/A000108) are probably the most ubiquitous sequence of integers\nin mathematics. They enumerate several important objects like binary trees, Dyck paths, and\ntriangulations of convex polygons.\n\n## Main definitions\n\n* `catalan n`: the `n`th Catalan number, defined recursively as\n  `catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)`.\n\n## Main results\n\n* `catalan_eq_centralBinom_div `: The explicit formula for the Catalan number using the central\n  binomial coefficient, `catalan n = Nat.centralBinom n / (n + 1)`.\n\n* `treesOfNodesEq_card_eq_catalan`: The number of binary trees with `n` internal nodes\n  is `catalan n`\n\n## Implementation details\n\nThe proof of `catalan_eq_centralBinom_div` follows https://math.stackexchange.com/questions/3304415\n\n## TODO\n\n* Prove that the Catalan numbers enumerate many interesting objects.\n* Provide the many variants of Catalan numbers, e.g. associated to complex reflection groups,\n  Fuss-Catalan, etc.\n\n-/\n\n\nopen BigOperators\n\nopen Finset\n\nopen Finset.Nat.antidiagonal (fst_le snd_le)\n\n/-- The recursive definition of the sequence of Catalan numbers:\n`catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)` -/\ndef catalan : ℕ → ℕ\n  | 0 => 1\n  | n + 1 =>\n    ∑ i : Fin n.succ,\n      catalan i * catalan (n - i)\n#align catalan catalan\n\n@[simp]\ntheorem catalan_zero : catalan 0 = 1 := by rw [catalan]\n#align catalan_zero catalan_zero\n\ntheorem catalan_succ (n : ℕ) : catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i) := by\n  rw [catalan]\n#align catalan_succ catalan_succ\n\ntheorem catalan_succ' (n : ℕ) :\n    catalan (n + 1) = ∑ ij in Nat.antidiagonal n, catalan ij.1 * catalan ij.2 := by\n  rw [catalan_succ, Nat.sum_antidiagonal_eq_sum_range_succ (fun x y => catalan x * catalan y) n,\n    sum_range]\n#align catalan_succ' catalan_succ'\n\n@[simp]\ntheorem catalan_one : catalan 1 = 1 := by simp [catalan_succ]\n#align catalan_one catalan_one\n\n/-- A helper sequence that can be used to prove the equality of the recursive and the explicit\ndefinition using a telescoping sum argument. -/\nprivate def gosperCatalan (n j : ℕ) : ℚ :=\n  Nat.centralBinom j * Nat.centralBinom (n - j) * (2 * j - n) / (2 * n * (n + 1))\n\nprivate theorem gosper_trick {n i : ℕ} (h : i ≤ n) :\n    gosperCatalan (n + 1) (i + 1) - gosperCatalan (n + 1) i =\n      Nat.centralBinom i / (i + 1) * Nat.centralBinom (n - i) / (n - i + 1) := by\n  have l₁ : (n : ℚ) + 1 ≠ 0 := by norm_cast; exact n.succ_ne_zero\n  have l₂ : (n : ℚ) + 1 + 1 ≠ 0 := by norm_cast; exact (n + 1).succ_ne_zero\n  have l₃ : (i : ℚ) + 1 ≠ 0 := by norm_cast; exact i.succ_ne_zero\n  have l₄ : (n : ℚ) - i + 1 ≠ 0 := by norm_cast; exact (n - i).succ_ne_zero\n  have h₁ := (mul_div_cancel_left (↑(Nat.centralBinom (i + 1))) l₃).symm\n  have h₂ := (mul_div_cancel_left (↑(Nat.centralBinom (n - i + 1))) l₄).symm\n  have h₃ : ((i : ℚ) + 1) * (i + 1).centralBinom = 2 * (2 * i + 1) * i.centralBinom := by\n    exact_mod_cast Nat.succ_mul_centralBinom_succ i\n  have h₄ :\n    ((n : ℚ) - i + 1) * (n - i + 1).centralBinom = 2 * (2 * (n - i) + 1) * (n - i).centralBinom :=\n    by exact_mod_cast Nat.succ_mul_centralBinom_succ (n - i)\n  simp only [gosperCatalan]\n  push_cast\n  rw [show n + 1 - i = n - i + 1 by rw [Nat.add_comm (n - i) 1, ←(Nat.add_sub_assoc h 1), add_comm]]\n  rw [h₁, h₂, h₃, h₄]\n  field_simp\n  ring_nf\n\nprivate theorem gosper_catalan_sub_eq_central_binom_div (n : ℕ) :\n    gosperCatalan (n + 1) (n + 1) - gosperCatalan (n + 1) 0 = Nat.centralBinom (n + 1) / (n + 2) :=\n  by\n  have : (n : ℚ) + 1 ≠ 0 := by norm_cast; exact n.succ_ne_zero\n  have : (n : ℚ) + 1 + 1 ≠ 0 := by norm_cast; exact (n + 1).succ_ne_zero\n  have h : (n : ℚ) + 2 ≠ 0 := by norm_cast; exact (n + 1).succ_ne_zero\n  simp only [gosperCatalan, Nat.sub_zero, Nat.centralBinom_zero, Nat.sub_self]\n  field_simp\n  ring_nf\n\ntheorem catalan_eq_centralBinom_div (n : ℕ) : catalan n = n.centralBinom / (n + 1) := by\n  suffices (catalan n : ℚ) = Nat.centralBinom n / (n + 1) by\n    have h := Nat.succ_dvd_centralBinom n\n    exact_mod_cast this\n  induction' n using Nat.case_strong_induction_on with d hd\n  · simp\n  · simp_rw [catalan_succ, Nat.cast_sum, Nat.cast_mul]\n    trans (∑ i : Fin d.succ, Nat.centralBinom i / (i + 1) *\n                             (Nat.centralBinom (d - i) / (d - i + 1)) : ℚ)\n    · congr\n      ext1 x\n      have m_le_d : x.val ≤ d := by apply Nat.le_of_lt_succ; apply x.2\n      have d_minus_x_le_d : (d - x.val) ≤ d := tsub_le_self\n      rw [hd _ m_le_d, hd _ d_minus_x_le_d]\n      norm_cast\n    · trans (∑ i : Fin d.succ, (gosperCatalan (d + 1) (i + 1) - gosperCatalan (d + 1) i))\n      · refine' sum_congr rfl fun i _ => _\n        rw [gosper_trick i.is_le, mul_div]\n      · rw [← sum_range fun i => gosperCatalan (d + 1) (i + 1) - gosperCatalan (d + 1) i,\n            sum_range_sub, Nat.succ_eq_add_one]\n        rw [gosper_catalan_sub_eq_central_binom_div d]\n        norm_cast\n#align catalan_eq_central_binom_div catalan_eq_centralBinom_div\n\ntheorem succ_mul_catalan_eq_centralBinom (n : ℕ) : (n + 1) * catalan n = n.centralBinom :=\n  (Nat.eq_mul_of_div_eq_right n.succ_dvd_centralBinom (catalan_eq_centralBinom_div n).symm).symm\n#align succ_mul_catalan_eq_central_binom succ_mul_catalan_eq_centralBinom\n\ntheorem catalan_two : catalan 2 = 2 := by unfold catalan; rfl\n#align catalan_two catalan_two\n\ntheorem catalan_three : catalan 3 = 5 := by unfold catalan; rfl\n#align catalan_three catalan_three\n\nnamespace Tree\n\nopen Tree\n\n/-- Given two finsets, find all trees that can be formed with\n  left child in `a` and right child in `b` -/\n@[reducible]\ndef pairwiseNode (a b : Finset (Tree Unit)) : Finset (Tree Unit) :=\n  (a ×ᶠ b).map ⟨fun x => x.1 △ x.2, fun ⟨x₁, x₂⟩ ⟨y₁, y₂⟩ => fun h => by simpa using h⟩\n#align tree.pairwise_node Tree.pairwiseNode\n\n/-- A Finset of all trees with `n` nodes. See `mem_treesOfNodesEq` -/\ndef treesOfNumNodesEq : ℕ → Finset (Tree Unit)\n  | 0 => {nil}\n  | n + 1 =>\n    (Finset.Nat.antidiagonal n).attach.bunionᵢ fun ijh =>\n      -- Porting note: `unusedHavesSuffices` linter is not happy with this. Commented out.\n      -- have := Nat.lt_succ_of_le (fst_le ijh.2)\n      -- have := Nat.lt_succ_of_le (snd_le ijh.2)\n      pairwiseNode (treesOfNumNodesEq ijh.1.1) (treesOfNumNodesEq ijh.1.2)\n  -- Porting note: Add this to satisfy the linter.\n  decreasing_by\n      simp_wf\n      try exact Nat.lt_succ_of_le (fst_le ijh.2)\n      try exact Nat.lt_succ_of_le (snd_le ijh.2)\n#align tree.trees_of_num_nodes_eq Tree.treesOfNumNodesEq\n\n@[simp]\ntheorem treesOfNumNodesEq_zero : treesOfNumNodesEq 0 = {nil} := by rw [treesOfNumNodesEq]\n#align tree.trees_of_nodes_eq_zero Tree.treesOfNumNodesEq_zero\n\ntheorem treesOfNumNodesEq_succ (n : ℕ) :\n    treesOfNumNodesEq (n + 1) =\n      (Nat.antidiagonal n).bunionᵢ fun ij =>\n        pairwiseNode (treesOfNumNodesEq ij.1) (treesOfNumNodesEq ij.2) := by\n  rw [treesOfNumNodesEq]\n  ext\n  simp\n#align tree.trees_of_nodes_eq_succ Tree.treesOfNumNodesEq_succ\n\n@[simp]\ntheorem mem_treesOfNumNodesEq {x : Tree Unit} {n : ℕ} : x ∈ treesOfNumNodesEq n ↔ x.numNodes = n :=\n  by\n  induction x using Tree.unitRecOn generalizing n <;> cases n <;>\n    simp [treesOfNumNodesEq_succ, Nat.succ_eq_add_one, *]\n  exact (Nat.succ_ne_zero _).symm\n#align tree.mem_trees_of_nodes_eq Tree.mem_treesOfNumNodesEq\n\ntheorem mem_treesOfNumNodesEq_numNodes (x : Tree Unit) : x ∈ treesOfNumNodesEq x.numNodes :=\n  mem_treesOfNumNodesEq.mpr rfl\n#align tree.mem_trees_of_nodes_eq_num_nodes Tree.mem_treesOfNumNodesEq_numNodes\n\n@[simp, norm_cast]\ntheorem coe_treesOfNumNodesEq (n : ℕ) :\n    ↑(treesOfNumNodesEq n) = { x : Tree Unit | x.numNodes = n } :=\n  Set.ext (by simp)\n#align tree.coe_trees_of_nodes_eq Tree.coe_treesOfNumNodesEq\n\ntheorem treesOfNumNodesEq_card_eq_catalan (n : ℕ) : (treesOfNumNodesEq n).card = catalan n := by\n  induction' n using Nat.case_strong_induction_on with n ih\n  · simp\n  rw [treesOfNumNodesEq_succ, card_bunionᵢ, catalan_succ']\n  · apply sum_congr rfl\n    rintro ⟨i, j⟩ H\n    rw [card_map, card_product, ih _ (fst_le H), ih _ (snd_le H)]\n  · simp_rw [disjoint_left]\n    rintro ⟨i, j⟩ _ ⟨i', j'⟩ _\n    -- Porting note: was clear * -; tidy\n    intros h a\n    cases' a with a l r\n    · intro h; simp at h\n    · intro h1 h2\n      apply h\n      trans (numNodes l, numNodes r)\n      · simp at h1; simp [h1]\n      · simp at h2; simp [h2]\n#align tree.trees_of_nodes_eq_card_eq_catalan Tree.treesOfNumNodesEq_card_eq_catalan\n\nend Tree\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/Catalan.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7573586203224071}}
{"text": "namespace calcc\nvariables (a b c d e : ℕ)\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 : add_comm d (1 : ℕ)\n    ... = e : h4.symm\nend calcc\n\nnamespace tactics\nvariables (a b c d e : ℕ)\nvariable h1 : a = b\nvariable h2 : b = c + 1\nvariable h3 : c = d\nvariable h4 : e = 1 + d\n\ninclude h1 h2 h3 h4\ntheorem T : 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 add_comm\n    ... = e     : by rw h4\n\ntheorem T₁ : a = e :=\ncalc\n  a     = d + 1 : by rw [h1, h2, h3]\n    ... = 1 + d : by rw add_comm\n    ... = e     : by rw h4\n\ntheorem T₂ : a = e :=\nby rw [h1, h2, h3, add_comm, h4]\n#print T₂\n#check T₂\n\ntheorem T₃ : a = e :=\nby simp [h1, h2, h3, h4]\n\nexample (x y : ℕ) :\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 left_distrib\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 ← add_assoc\n\nexample (x y : ℕ) :\n  (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\nby rw [mul_add, add_mul, add_mul, ← add_assoc]\n\nexample (x y : ℕ) :\n  (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\nby simp [left_distrib, right_distrib]\n\nend tactics\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/Chapter4/4-3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.91610961358942, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7573586202602527}}
{"text": "theorem ex1 : (fun y => y + 0) = (fun x => 0 + x) := by\n  funext x\n  simp\n\ntheorem ex2 : (fun y x => y + x + 0) = (fun x y => y + x) := by\n  funext x y\n  rw [Nat.add_zero, Nat.add_comm]\n\ntheorem ex3 : (fun (x : Nat × Nat) => x.1 + x.2) = (fun (x : Nat × Nat) => x.2 + x.1) := by\n  funext (a, b)\n  show a + b = b + a\n  rw [Nat.add_comm]\n\ntheorem ex4 : (fun (x : Nat × Nat) (y : Nat × Nat) => x.1 + y.2) = (fun (x : Nat × Nat) (z : Nat × Nat) => z.2 + x.1) := by\n  funext (a, b) (c, d)\n  show a + d = d + a\n  rw [Nat.add_comm]\n\ntheorem ex5 : (fun (x : Id Nat) => x.succ + 0) = (fun (x : Id Nat) => 0 + x.succ) := by\n  funext (x : Nat)\n  have y := x + 1 -- if `(x : Nat)` is not used at `funext`, then `x+1` would fail to be elaborated since we don't have the instance `Add (Id Nat)`\n  rw [Nat.add_comm]\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/funext.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7573586181802959}}
{"text": "/-\nGive a natural deduction proof of 𝐴→((𝐴∧𝐵)∨(𝐴∧¬𝐵)).\nYou may use the law of the excluded middle.\n-/\n\nopen classical\n\nexample (A B: Prop):  A → ((A ∧ B)∨(A ∧ ¬B)) :=\n  λ hA: A,\n  or.elim(em(B))(\n    λ hB: B,\n    have hAB: A ∧ B, from ⟨hA, hB⟩,\n    show (A ∧ B)∨(A ∧ ¬B), from  or.inl hAB\n  )(\n    λ hnB: ¬ B,\n    have hAnB: A ∧ ¬B, from ⟨hA, hnB⟩,\n    show (A ∧ B)∨(A ∧ ¬B), from  or.inr hAnB\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/ex6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632247867715, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7573576780355226}}
{"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 3 : not in (`∉`)\n\nThe definition in Lean of `x ∉ A` is `¬ (x ∈ A)`. In other words,\n`x ∉ A`, `¬ (x ∈ A)` and `(x ∈ A) → false` are all equal *by definition*\nin Lean. This means that they are all interchangeable, and you can\nchange between them using the `change` tactic, or you can just keep this\nin mind. For example, if you have a hypothesis `h : x ∉ A` and your goal\nis `false`, then `apply h` will work and will change the goal to `x ∈ A`.\n\n## Tactics\n\nYou can do all these levels just with `intros`, `apply` and `exact`!\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 : x ∉ A → (x ∈ A → false) :=\nbegin\n  intro h,\n  exact h,\nend\n\nexample : x ∈ A → (x ∉ A → false) :=     /-attention!-/\nbegin\n  intro h,\n  intro h1,\n  apply h1,\n  exact h,\nend\n\nexample : (∀ t, t ∈ A → t ∈ B) → x ∉ B → x ∉ A :=\nbegin\n  intros h2 h1,\n  specialize h2 x,\n  by_cases (x ∈ A),\n  have h3: x ∈ B, by exact h2 h,\n  trivial,\n  exact h,\nend\n\nexample : x ∉ (∅ : set X) :=\nbegin\n  change x ∈ ∅ → false,\n  intro h,\n  exact h,\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/sets/Sets3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.8080672227971212, "lm_q1q2_score": 0.757329322801636}}
{"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 : ℕ) : polynomial R :=\n  nat.iterate (⇑derivative) n f\n\n@[simp] theorem iterated_deriv_zero_right {R : Type u} [semiring R] (f : polynomial R) : iterated_deriv f 0 = f :=\n  rfl\n\ntheorem iterated_deriv_succ {R : Type u} [semiring R] (f : polynomial R) (n : ℕ) : iterated_deriv f (n + 1) = coe_fn derivative (iterated_deriv f n) := sorry\n\n@[simp] theorem iterated_deriv_zero_left {R : Type u} [semiring R] (n : ℕ) : iterated_deriv 0 n = 0 := sorry\n\n@[simp] theorem iterated_deriv_add {R : Type u} [semiring R] (p : polynomial R) (q : polynomial R) (n : ℕ) : iterated_deriv (p + q) n = iterated_deriv p n + iterated_deriv q n := sorry\n\n@[simp] theorem iterated_deriv_smul {R : Type u} [semiring R] (r : R) (p : polynomial R) (n : ℕ) : iterated_deriv (r • p) n = r • iterated_deriv p 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 : ℕ) (h : 1 < n) : iterated_deriv X n = 0 := sorry\n\n@[simp] theorem iterated_deriv_C_zero {R : Type u} [semiring R] (r : R) : iterated_deriv (coe_fn C r) 0 = coe_fn C r := sorry\n\n@[simp] theorem iterated_deriv_C {R : Type u} [semiring R] (r : R) (n : ℕ) (h : 0 < n) : iterated_deriv (coe_fn C r) n = 0 := 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 : ℕ) : 0 < n → iterated_deriv 1 n = 0 := sorry\n\n@[simp] theorem iterated_deriv_neg {R : Type u} [ring R] (p : polynomial R) (n : ℕ) : iterated_deriv (-p) n = -iterated_deriv p n := sorry\n\n@[simp] theorem iterated_deriv_sub {R : Type u} [ring R] (p : polynomial R) (q : polynomial R) (n : ℕ) : iterated_deriv (p - q) n = iterated_deriv p n - iterated_deriv q n := sorry\n\ntheorem coeff_iterated_deriv_as_prod_Ico {R : Type u} [comm_semiring R] (f : polynomial R) (k : ℕ) (m : ℕ) : coeff (iterated_deriv f k) m =\n  (finset.prod (finset.Ico (Nat.succ m) (m + Nat.succ k)) fun (i : ℕ) => ↑i) * coeff f (m + k) := sorry\n\ntheorem coeff_iterated_deriv_as_prod_range {R : Type u} [comm_semiring R] (f : polynomial R) (k : ℕ) (m : ℕ) : coeff (iterated_deriv f k) m = coeff f (m + k) * finset.prod (finset.range k) fun (i : ℕ) => ↑(m + k - i) := sorry\n\ntheorem iterated_deriv_eq_zero_of_nat_degree_lt {R : Type u} [comm_semiring R] (f : polynomial R) (n : ℕ) (h : nat_degree f < n) : iterated_deriv f n = 0 := sorry\n\ntheorem iterated_deriv_mul {R : Type u} [comm_semiring R] (p : polynomial R) (q : polynomial R) (n : ℕ) : iterated_deriv (p * q) n =\n  finset.sum (finset.range (Nat.succ n))\n    fun (k : ℕ) => coe_fn C ↑(nat.choose n k) * iterated_deriv p (n - k) * iterated_deriv q k := 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/iterated_deriv.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104866, "lm_q2_score": 0.8080672204860317, "lm_q1q2_score": 0.7573293220528213}}
{"text": "/-\nProve the following in Lean:\n\nvariables A B C D : Prop\n\nexample : A ∧ (A → B) → B :=\nsorry\n\nexample : A → ¬ (¬ A ∧ B) :=\nsorry\n\nexample : ¬ (A ∧ B) → (A → ¬ B) :=\nsorry\n\nexample (h₁ : A ∨ B) (h₂ : A → C) (h₃ : B → D) : C ∨ D :=\nsorry\n\nexample (h : ¬ A ∧ ¬ B) : ¬ (A ∨ B) :=\nsorry\n\nexample : ¬ (A ↔ ¬ A) :=\nsorry\n-/\n\nvariables A B C D : Prop\n\nexample : A ∧ (A → B) → B :=\nλ h: A ∧ (A → B),\nhave hA: A, from and.elim_left h,\nhave A → B, from and.elim_right h,\nshow B, from this hA\n\nexample : A → ¬ (¬ A ∧ B) :=\nassume hA: A,\nassume hnAB: ¬ A ∧ B,\nshow false, from (\n  have hnA: ¬ A, from and.elim_left hnAB,\n  hnA(hA)\n)\n\nexample : ¬ (A ∧ B) → (A → ¬ B) :=\n  assume h:  ¬ (A ∧ B),\n  assume hA: A,\n  assume hB: B,\n  show false, from (\n    have hAB: A ∧ B, from ⟨ hA, hB ⟩,\n    h(hAB)\n  )\n\nexample (h₁ : A ∨ B) (h₂ : A → C) (h₃ : B → D) : C ∨ D :=\nor.elim(h₁)(\n  assume hA, or.inl(h₂(hA))\n)(\n  assume hB, or.inr(h₃(hB))\n)\n\nexample (h : ¬ A ∧ ¬ B) : ¬ (A ∨ B) :=\nhave hnA: ¬ A, from and.elim_left(h),\nhave hnB: ¬ B, from and.elim_right(h),\nassume hAoB: A ∨ B,\nshow false, from (\n  or.elim(hAoB)(\n    assume hA, hnA(hA)\n  )(\n    assume hB, hnB(hB)\n  )\n)\n\nexample : ¬ (A ↔ ¬ A) :=\nassume h: A ↔ ¬ A,\nshow false, from (\n  have hAtnA: A → ¬ A, from  iff.mp(h),\n  have hnAtA: ¬ A → A, from  iff.mpr(h),\n  have hnA: ¬ A, from (\n    assume hA: A,\n    show false, from hAtnA(hA)(hA)\n  )\n  have hA: A, from hnAtA(hnA),\n  hnA(hA)\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/chapter4/exercises.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7573222783793383}}
{"text": "import MyNat.Power\nimport MyNat.Addition -- add_zero\nimport MultiplicationWorld.Level2 -- mul_one\nimport MultiplicationWorld.Level5 -- mul_assoc\nnamespace MyNat\nopen MyNat\n\n/-!\n# Power World\n\n## Level 5: `pow_add`\n\n## Lemma\nFor all naturals `a`, `m`, `n`, we have `a^(m + n) = a ^ m  a ^ n`.\n-/\nlemma pow_add (a m n : MyNat) : a ^ (m + n) = a ^ m * a ^ n := by\n  induction n with\n  | zero =>\n    rw [zero_is_0]\n    rw [add_zero]\n    rw [pow_zero]\n    rw [mul_one]\n  | succ n ih =>\n    rw [add_succ]\n    rw [pow_succ]\n    rw [pow_succ]\n    rw [ih]\n    rw [mul_assoc]\n\n/-!\nRemember you can combine all the `rw` rules into one with\n`rw [add_succ, pow_succ, pow_succ, ih, mul_assoc]` but we have\nbroken it out here so you can more easily see all the intermediate\ngoal states.\n\nNext up [Level 6](./Level6.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/Level5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9579122756889437, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7572587060126258}}
{"text": "-- La función duplicadora no es par\n-- ================================\n\nimport data.real.basic\n\nvariable (f : ℝ → ℝ)\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la función\n--    par : (ℝ → ℝ) → Prop\n-- tal que (par f) expresa que f es par.\n-- ----------------------------------------------------\n\ndef par : (ℝ → ℝ) → Prop\n| f := ∀ x, f (-x) = f x\n\n-- ----------------------------------------------------\n-- Ejercicio 2. Demostrar que la función que a cada x\n-- le asigna 2*x no es par.\n-- ----------------------------------------------------\n\nexample :\n  ¬par (λ x, 2*x) :=\nbegin\n  unfold par,\n  push_neg,\n  use 42,\n  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/La_funcion_duplicadora_no_es_par.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802395624259, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7572519876484517}}
{"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.monoid_algebra.support\n\n/-!\n# Variations on non-zero divisors in `add_monoid_algebra`s\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis file studies the interaction between typeclass assumptions on two Types `R` and `A` and\nwhether `add_monoid_algebra R A` has non-zero zero-divisors.  For some background on related\nquestions, see [Kaplansky's Conjectures](https://en.wikipedia.org/wiki/Kaplansky%27s_conjectures),\nespecially the *zero divisor conjecture*.\n\n_Conjecture._\nLet `K` be a field, and `G` a torsion-free group. The group ring `K[G]` does not contain\nnontrivial zero divisors, that is, it is a domain.\n\nWe formalize in this file the well-known result that if `R` is a field and `A` is a left-ordered\ngroup, then `R[A]` contains no non-zero zero-divisors.  Some of these assumptions can be trivially\nweakened: below we mention what assumptions are sufficient for the proofs in this file.\n\n##  Main results\n\n* `no_zero_divisors.of_left_ordered` shows that if `R` is a semiring with no non-zero\n  zero-divisors, `A` is a linearly ordered, add right cancel semigroup with strictly monotone\n  left addition, then `add_monoid_algebra R A` has no non-zero zero-divisors.\n* `no_zero_divisors.of_right_ordered` shows that if `R` is a semiring with no non-zero\n  zero-divisors, `A` is a linearly ordered, add left cancel semigroup with strictly monotone\n  right addition, then `add_monoid_algebra R A` has no non-zero zero-divisors.\n\nThe conditions on `A` imposed in `no_zero_divisors.of_left_ordered` are sometimes referred to as\n`left-ordered`.\nThe conditions on `A` imposed in `no_zero_divisors.of_right_ordered` are sometimes referred to as\n`right-ordered`.\n\nThese conditions are sufficient, but not necessary.  As mentioned above, *Kaplansky's Conjecture*\nasserts that `A` being torsion-free may be enough.\n-/\n\nnamespace add_monoid_algebra\nopen finsupp\n\nvariables {R A : Type*} [semiring R]\n\n/--  The coefficient of a monomial in a product `f * g` that can be reached in at most one way\nas a product of monomials in the supports of `f` and `g` is a product. -/\nlemma mul_apply_add_eq_mul_of_forall_ne [has_add A] {f g : add_monoid_algebra R A} {a0 b0 : A}\n  (h : ∀ {a b : A}, a ∈ f.support → b ∈ g.support → (a ≠ a0 ∨ b ≠ b0) → a + b ≠ a0 + b0) :\n  (f * g) (a0 + b0) = f a0 * g b0 :=\nbegin\n  classical,\n  rw mul_apply,\n  refine (finset.sum_eq_single a0 _ _).trans _,\n  { exact λ b H hb, finset.sum_eq_zero (λ x H1, if_neg (h H H1 (or.inl hb))) },\n  { exact λ af0, by simp [not_mem_support_iff.mp af0] },\n  { refine (finset.sum_eq_single b0 (λ b bg b0, _) _).trans (if_pos rfl),\n    { by_cases af : a0 ∈ f.support,\n      { exact if_neg (h af bg (or.inr b0)) },\n      { simp only [not_mem_support_iff.mp af, zero_mul, if_t_t] } },\n    { exact λ bf0, by simp [not_mem_support_iff.mp bf0] } },\nend\n\nsection left_or_right_orderability\n\nlemma left.exists_add_of_mem_support_single_mul [add_left_cancel_semigroup A]\n  {g : add_monoid_algebra R A} (a x : A)\n  (hx : x ∈ (single a 1 * g : add_monoid_algebra R A).support) :\n  ∃ b ∈ g.support, a + b = x :=\nby rwa [support_single_mul _ _ (λ y, by rw one_mul : ∀ y : R, 1 * y = 0 ↔ _), finset.mem_map] at hx\n\nlemma right.exists_add_of_mem_support_single_mul [add_right_cancel_semigroup A]\n  {f : add_monoid_algebra R A} (b x : A)\n  (hx : x ∈ (f * single b 1 : add_monoid_algebra R A).support) :\n  ∃ a ∈ f.support, a + b = x :=\nby rwa [support_mul_single _ _ (λ y, by rw mul_one : ∀ y : R, y * 1 = 0 ↔ _), finset.mem_map] at hx\n\n/--  If `R` is a semiring with no non-trivial zero-divisors and `A` is a left-ordered add right\ncancel semigroup, then `add_monoid_algebra R A` also contains no non-zero zero-divisors. -/\nlemma no_zero_divisors.of_left_ordered [no_zero_divisors R]\n  [add_right_cancel_semigroup A] [linear_order A] [covariant_class A A (+) (<)] :\n  no_zero_divisors (add_monoid_algebra R A) :=\n⟨λ f g fg, begin\n  contrapose! fg,\n  let gmin : A := g.support.min' (support_nonempty_iff.mpr fg.2),\n  refine support_nonempty_iff.mp _,\n  obtain ⟨a, ha, H⟩ := right.exists_add_of_mem_support_single_mul gmin\n    ((f * single gmin 1 : add_monoid_algebra R A).support.min'\n      (by rw support_mul_single; simp [support_nonempty_iff.mpr fg.1])) (finset.min'_mem _ _),\n  refine ⟨a + gmin, mem_support_iff.mpr _⟩,\n  rw mul_apply_add_eq_mul_of_forall_ne _,\n  { refine mul_ne_zero _ _,\n    exacts [mem_support_iff.mp ha, mem_support_iff.mp (finset.min'_mem _ _)] },\n  { rw H,\n    rintro b c bf cg (hb | hc); refine ne_of_gt _,\n    { refine lt_of_lt_of_le (_ : _ < b + gmin ) _,\n      { apply finset.min'_lt_of_mem_erase_min',\n        rw ← H,\n        apply finset.mem_erase_of_ne_of_mem,\n        { simpa only [ne.def, add_left_inj] },\n        { rw support_mul_single _ _ (λ y, by rw mul_one : ∀ y : R, y * 1 = 0 ↔ _),\n          simpa only [finset.mem_map, add_right_embedding_apply, add_left_inj, exists_prop,\n            exists_eq_right] } },\n      { haveI : covariant_class A A (+) (≤) := has_add.to_covariant_class_left A,\n        exact add_le_add_left (finset.min'_le _ _ cg) _ } },\n    { refine lt_of_le_of_lt (_ : _ ≤ b + gmin) _,\n      { apply finset.min'_le,\n        rw support_mul_single _ _ (λ y, by rw mul_one : ∀ y : R, y * 1 = 0 ↔ _),\n        simp only [bf, finset.mem_map, add_right_embedding_apply, add_left_inj, exists_prop,\n          exists_eq_right] },\n      { refine add_lt_add_left _ _,\n        exact finset.min'_lt_of_mem_erase_min' _ _ (finset.mem_erase.mpr ⟨hc, cg⟩) } } }\nend⟩\n\n/--  If `R` is a semiring with no non-trivial zero-divisors and `A` is a right-ordered add left\ncancel semigroup, then `add_monoid_algebra R A` also contains no non-zero zero-divisors. -/\nlemma no_zero_divisors.of_right_ordered [no_zero_divisors R]\n  [add_left_cancel_semigroup A] [linear_order A] [covariant_class A A (function.swap (+)) (<)] :\n  no_zero_divisors (add_monoid_algebra R A) :=\n⟨λ f g fg, begin\n  contrapose! fg,\n  let fmin : A := f.support.min' (support_nonempty_iff.mpr fg.1),\n  refine support_nonempty_iff.mp _,\n  obtain ⟨a, ha, H⟩ := left.exists_add_of_mem_support_single_mul fmin\n    ((single fmin 1 * g : add_monoid_algebra R A).support.min'\n      (by rw support_single_mul; simp [support_nonempty_iff.mpr fg.2])) (finset.min'_mem _ _),\n  refine ⟨fmin + a, mem_support_iff.mpr _⟩,\n  rw mul_apply_add_eq_mul_of_forall_ne _,\n  { refine mul_ne_zero _ _,\n    exacts [mem_support_iff.mp (finset.min'_mem _ _), mem_support_iff.mp ha] },\n  { rw H,\n    rintro b c bf cg (hb | hc); refine ne_of_gt _,\n    { refine lt_of_le_of_lt (_ : _ ≤ fmin + c) _,\n      { apply finset.min'_le,\n        rw support_single_mul _ _ (λ y, by rw one_mul : ∀ y : R, 1 * y = 0 ↔ _),\n        simp only [cg, finset.mem_map, add_left_embedding_apply, add_right_inj, exists_prop,\n          exists_eq_right] },\n      { refine add_lt_add_right _ _,\n        exact finset.min'_lt_of_mem_erase_min' _ _ (finset.mem_erase.mpr ⟨hb, bf⟩) } },\n    { refine lt_of_lt_of_le (_ : _ < fmin + c) _,\n      { apply finset.min'_lt_of_mem_erase_min',\n        rw ← H,\n        apply finset.mem_erase_of_ne_of_mem,\n        { simpa only [ne.def, add_right_inj] },\n        { rw support_single_mul _ _ (λ y, by rw one_mul : ∀ y : R, 1 * y = 0 ↔ _),\n          simpa only [finset.mem_map, add_left_embedding_apply, add_right_inj, exists_prop,\n            exists_eq_right]} },\n      { haveI : covariant_class A A (function.swap (+)) (≤) := has_add.to_covariant_class_right A,\n        exact add_le_add_right (finset.min'_le _ _ bf) _ } } }\nend⟩\n\nend left_or_right_orderability\n\nend add_monoid_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/monoid_algebra/no_zero_divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7572519852445926}}
{"text": "import data.list.basic tactic.linarith\nimport tactic.omega tactic.apply\n\nopen list\n\n\n/- cons -/\n\n/-- (a::L) is the same as [a] ++ L-/\nlemma cons_eq_sing_append {α : Type*} {L : list α } (a : α ):\n(a::L) = [a] ++ L := by refl -- true by definition of append\n\n\n/- bind -/\n\n/--list.bind of two lists is the second appended to the first-/\ntheorem list.bind_fin2 {α : Type*} (f : fin 2 → list α) : \n  list.bind [0, 1] f = f 0 ++ f 1 :=\nbegin\n  show f 0 ++ (f 1 ++ nil) = f 0 ++ f 1, -- by definition of list.bind\n  rw append_nil,\nend\n\n/- tail -/\n\n/--the tail of a list with the first m elements dropped is that\nlist with the first m+1 elements dropped-/\nlemma tail_drop (α : Type*) {A:list α} {m : ℕ} :\ntail (drop m A) = drop (nat.succ m) A :=\nby rw [← drop_one, drop_drop, add_comm]\n/-\nbegin\nrw ← drop_one, -- drop 1 L = tail L (here L is drop m A)\nrw drop_drop,  -- drop 1 (drop m) A = drop (1 + m) A\nrw add_comm,   -- commutativity of + (nat.succ n is defined as n + 1)\nend \n-/\n\n\n/- drop -/\n\n/-- dropping no elements from a list gives the list-/\nlemma drop_zero {α : Type*} {L : list α}: drop 0 L = L := by refl --by def of drop\n\n\n/--If one drops the first n elements of two lists appended to each other and\n   the fist list has length l no longer than n, then this is the same as \n   dropping the first n-l elements from the second list-/\nlemma drop_append_of_length_le {α : Type*} {l₁ l₂ : list α} {n : ℕ} :\n  length l₁ ≤ n → drop n (l₁ ++ l₂) = drop (n - l₁.length) l₂ :=\nbegin\n  revert n, -- revert n so the inductive hyothesis holds for any value of n\n  induction l₁ with c L H,\n  -- base case: l₁ = nil \n  { intros n h,\n    rw nil_append, -- nil ++ l₂ = l₂\n    rw length, -- length nil = nil\n    rw nat.sub_zero}, -- n-0 = n\n  -- inductive step: l_1 = (c :: L), c of type α and L of type list α   \n  { intros n h,\n    rw length_cons, -- length (c :: L) = length L + 1\n    rw cons_append, -- (c :: L) ++ l₂ = (c :: (L ++ l₂))\n    cases n,\n      -- n = 0,  contradicts length (c :: L) ≤ n (hypothesis h)\n      exfalso,\n      rw length_cons at h,\n      exact nat.not_succ_le_zero (length L) h,\n    -- nat.succ n \n    rw drop, -- drop (nat.succ n) (c :: (L ++ l₂)) = drop n (L ++ l₂) by def of drop\n    rw nat.succ_eq_add_one,\n    rw [length_cons, nat.succ_eq_add_one] at h, \n    rw ← nat.sub_le_right_iff_le_add at h, -- (length L + 1) - 1 ≤ n ↔ (length L + 1) ≤ n + 1\n    rw nat.add_sub_cancel (length L) 1 at h,\n    rw H h, -- use inductive hypothesis\n    rw nat.succ_sub_succ n (length L)} /- nat.succ n - nat.succ (length L) = n - (length L)\n                                          nat.succ x defined as x + 1 -/\nend \n\n\n/--summary of drop_append_of_le_length and drop_append_of_length_le-/\nlemma drop_append {α : Type*} {l₁ l₂ : list α} {n : ℕ} :\n  drop n (l₁ ++ l₂) = if n ≤ l₁.length then drop n l₁ ++ l₂ else drop (n - l₁.length) l₂ :=\nbegin\n  split_ifs with ite, -- split if-then-else-condition into cases true or not)\n    /- if-case (named ite) : n ≤ length l₁-/\n    exact drop_append_of_le_length ite, -- existing lemma in mathlib\n  /- else-case (named ite) : ¬ (n ≤ length l₁)-/\n  apply drop_append_of_length_le, -- lemma above\n  --goal : length l₁ ≤ n    necessary hypothesis for drop_append_of_length_le\n  linarith, -- lean can do this much by itself\nend\n\n\n/- take -/\n\n/--If one takes the first n elements of two lists appended to each other and\n   the fist list has length l no longer than n, then this is the same as \n   taking all of the first list and appending the first n-l elements from \n   the second list-/\nlemma take_append_of_length_le {α : Type*} {l₁ l₂ : list α} {n : ℕ} :\n length l₁ ≤ n →\n  take n (l₁ ++ l₂) = l₁ ++ take (n - l₁.length) l₂ :=\nbegin\n  revert n, -- revert n so the inductive hyothesis holds for any value of n\n  induction l₁ with c L H,\n  -- base case: l₁ = nil\n  { intros n h, \n    rw nil_append, -- nil ++ l₂ = l₂\n    rw nil_append, -- nil ++ take (n - length nil) l₂ = take (n - length nil) l₂\n    refl, -- n - length nil = n - 0 = n\n  },\n  -- inductive step: l₁ = (c :: L), with c of type α and L of type list α \n  intros n h,\n  cases n with m,\n    cases h, -- kill n = 0 case (h is ength (c :: L) ≤ 0)\n  -- nat.succ n\n  rw cons_append, -- ((c :: L) ++ l₂) = (c :: (L ++ l₂))\n  rw take_cons, -- take (nat.succ m) (c :: (L ++ l₂)) =  c :: take m (L ++ l₂)\n  rw cons_append, /- c :: L ++ take (nat.succ m - length (c :: L)) l₂ = \n                     c :: (L ++ take (nat.succ m - length (c :: L)) l₂)-/\n  congr', -- eliminates the c at the start on both sides\n  rw H, -- use inductive hypothesis\n  { congr' 2, -- focused goal becomes : m - length L = nat.succ m - length (c :: L)\n    rw length_cons, -- length (c :: L) = ength L + 1\n    generalize : length L = d, -- replaces length L by d\n    simp, -- Lean can solve the goal by itself now\n  },\n  -- necessary hypothesis for inductive hypothesis: length L ≤ m\n  rw length_cons at h,\n  revert h,\n  exact nat.pred_le_iff.mpr -- solves goal : length L + 1 ≤ nat.succ m → length L ≤ m\nend\n\n\n/--summary of  take_append_of_le_length and take_append_of_length_le-/\nlemma take_append {α : Type*} {l₁ l₂ : list α} {n : ℕ} :\n  take n (l₁ ++ l₂) = \n  if ( n ≤ length l₁) then take n l₁ else l₁ ++ take (n - l₁.length) l₂ :=\nbegin\n    split_ifs with ite, -- split if-then-else-condition into cases true or not)\n    /- if-case (named ite) : n ≤ length l₁-/\n    exact take_append_of_le_length ite, -- existing lemma in mathlib\n  /- else-case (named ite) : ¬ (n ≤ length l₁)-/\n  apply take_append_of_length_le, -- lemma above\n  --goal : length l₁ ≤ n    necessary hypothesis for drop_append_of_length_le\n  linarith, -- lean can do this much by itself\nend\n\n\n/- remove_nth -/\n\n/--removing only the 0th element gives the tail-/\nlemma remove_nth_zero {α : Type*} (L : list α) : remove_nth L 0 = tail L :=\n--proof in term mode\nby cases L; refl\n\n/--removing the (n+1)th element gives the 'tail' of the list with \n   the nth element removed, concatenated to the first element   -/\nlemma remove_nth_succ {α : Type*}  {n : ℕ} ( L : list α) ( l : α ): \nremove_nth (l::L) (nat.succ n) = l :: remove_nth L n:=  \nbegin\ncases L with a L1, \n-- L = nil\nrefl, -- by def of remove_nth\n-- L = (a :: L1)\nrefl, -- by def of remove_nth\nend\n\n\n/--If we try to remove an entry outside of the list, we get the unchanged list-/\nlemma remove_nth_large_n {α : Type*} {n : ℕ} (L : list α) (h : length L ≤ n): \nremove_nth L n = L :=\nbegin\nrevert L, -- so the inductive hypothesis holds for any list of length ≤ n\ninduction n with d hd,\n-- base case : n = 0\n  {intros L h,\n  have p : L = nil, -- because of h, as the only list of length 0 is nil\n    {rw ←  length_eq_zero, -- length L = 0 ↔ L = nil\n    exact le_zero_iff_eq.mp h},\n  rw p, \n  refl}, -- by def of remove_nth\n-- inductive step : n = nat.succ d\n{intros L h,\ncases L with l Lt,\n  -- L = nil\n  {refl}, -- by def of remove_nth\n-- L = (l :: Lt), with l of type α and Lt of type list α\n{rw remove_nth_succ Lt l, \nrw length_cons at h,\nrw hd Lt (nat.le_of_succ_le_succ h)},}, -- use inductive hypothesis\nend\n\n\n/- nth_le -/\n\n/--the zeroth element of the list is its head-/\nlemma nth_le_zero {α : Type*} [inhabited α] (l : list α) (h : _) :\n  nth_le l 0 h = head l :=\nbegin\n  cases l with m M,\n    -- l = nil     contradicts (h : 0 < length l)\n    {exfalso,\n    revert h, \n    exact dec_trivial},\n  -- L = (m :: M), with m of type α and M of type list α  \n  refl, -- by def of nth_le\nend\n\n\n/-- the ith element of the reverted list is the (length l - 1 - i)th element of the list-/\n@[simp] theorem nth_le_reverse' {α : Type*} (l : list α) (i : nat) (h1 h2) :\n  nth_le (reverse l) i h1 = nth_le l (length l - 1 - i) h2 :=\nbegin\n  /- this lemma is just a slightly different version of nth_le_reverse, which says\n     for any ist l , natural number i\n     nth_le (reverse l) (length l - 1 - i) h1 = nth_le l i h2\n     where h1,h2 are the respective proofs that the lists have an element \n     of the index asked for-/\n\n  convert nth_le_reverse l _ _ _, -- convert the goal using nth_le_reverse\n\n  -- first goal : i = length l - 1 - (length l - 1 - i)\n  rw length_reverse at h1, -- length (reverse l) = length l\n  { generalize hL : length l = x, -- create hyothesis length l = x for some x ∈ ℕ \n    rw hL at h1,\n    clear hL h2 l α, -- working around bugs in old mathlib\n    omega -- let Lean solve this by itself (using linear integer and natural number arithmetic)\n  },\n\n  /- other goal : length l - 1 - (length l - 1 - i) < length (reverse l)  \n     (needed as argument for nth_le) -/\n  { generalize hL : length l = x, -- create hyothesis length l = x for some x ∈ ℕ  \n    rw  length_reverse  at *, -- rewrite using length_reverse everywhere\n    rw hL at *,\n\n    -- now the goal is equivalent to h1 after getting rid of cancelling terms\n    \n    clear hL l α, -- working around bugs in old mathlib\n    omega, -- let Lean solve this by itself (using linear integer and natural number arithmetic)\n  }\nend\n\n/--the nth element of the first m elements is the nth element if n < m-/\nlemma nth_le_take {α : Type*} (l : list α) (n m : ℕ) (h1) (h2) :\nnth_le (take m l) n h1 = nth_le l n h2 :=\nbegin\n  rw length_take at h1, /- length (take m l) = min m length l \n                           creates duplicate of h1, as h1 in its exact old form\n                           is needed as an argument for nth_le-/\n  rename h1 h3, -- this line renames the new version of h1\n  rw lt_min_iff at h3, -- n < min m (length l) ↔ n < m ∧ n < length l\n  cases h3 with H1 H2, -- now H1 : n < m , and H2 : n < length l\n\n  revert m n, -- so the inductive hypothesis holds for any choices of m and n\n  induction l with k Lk IH,\n\n    -- base case : l = nil\n    { intros m n h1 h2 H1 H2, -- now l = nil contradicts H2, saying n < length l\n      exfalso, \n      rw length at H2, -- length nil = 0 by def of length\n      cases H2}, -- both cases killed immediately\n\n    -- inductive step : l = (k :: kL) \n    intros m n h1 h2 H1 H2,\n    cases m with m',\n\n      -- m = 0\n      { simp only [take_zero], -- take 0 (k :: Lk) = nil    (simp only because of nth_le)\n          cases H1}, -- both cases killed immediately\n\n      -- m = nat.succ m'  for some natural number m'    \n      { simp only [take], /- take (nat.succ m') (k :: Lk) = (k :: take m' Lk)\n                             (simp only because of nth_le) -/                    \n        cases n with n',\n\n          -- n = 0 \n          {refl}, -- by def of nth_le\n\n          -- n = nat.succ n'  for some natural number n'\n          {rw nth_le, /- nth_le (k :: take m' Lk) (nat.succ n') _ = nth_le (take m' Lk) n' _\n                         by def of nth_le-/\n          rw nth_le,  /- nth_le (k :: Lk) (nat.succ n') h2 = nth_le Lk n' _\n                         by def of nth_le-/\n          apply IH, -- apply inductive hypothesis\n\n          /- IH was ∀ (m n : ℕ) (h1 : n < length (take m Lk)) (h2 : n < length Lk),\n             n < m → n < length Lk → nth_le (take m Lk) n h1 = nth_le Lk n h2,\n             \n             we used it for m' and n'\n             h1 and h2 Lean can infer itself, so only need to prove n' < m' and n' < length Lk-/\n            {apply nat.lt_of_succ_lt_succ, \n            assumption}, -- true by some assumption (here h1)\n\n            apply nat.lt_of_succ_lt_succ, \n            assumption}, -- true by h2\n      }\nend\n\n\n\n/--the ith element of of_fn f (if it is in the list) is f(i)-/\n@[simp] theorem nth_le_of_fn' {α : Type*} {n : ℕ} (f : fin n → α)\n  (i : ℕ) (hi : i < n) :\n  nth_le (of_fn f) i ((length_of_fn f).symm ▸ hi) = f ⟨i, hi⟩ :=\n  -- the following proof is in term mode\noption.some.inj $ by rw [← nth_le_nth];\n  simp only [list.nth_of_fn, of_fn_nth_val, fin.eta, dif_pos hi]\n\n\n\n/- head -/\n\n/--if two lists are equal, their heads are equal-/\nlemma head_eq_of_list_eq {α : Type*} [inhabited α] {L1 L2 : list α}:\nL1 = L2 → list.head L1 = list.head L2:= \nbegin\nintro h, -- h is L1 = L2\nrw h,\nend\n\n\n/--The head of a list with its first m element dropped is\n   its (m+1)th element-/\nlemma head_drop (α : Type*) [inhabited α] (L : list α) (m : ℕ) (hm : m < L.length):\n  head (drop m L) = nth_le L m hm :=\nbegin\n  revert L, -- so the inductive hyothesis holds for any list of lenght greater m\n  induction m with d hd,\n    -- base case :  m = 0\n    { intros L hL,\n      rw drop_zero, -- drop 0 L = L\n      rw nth_le_zero,\n    },\n    -- inductive step : n = nat.succ d\n    intros L hm,\n    cases L with a M,\n        -- L = nil\n        {cases hm}, -- does it as hm is equivalent to nat.succ d < 0\n      --  L = (a :: M)\n      exact hd M _, /- true by inductive hypothesis\n                       that d < length M can be inferred from hm -/\n  end\n\n\n/- sum -/\n\n/--the sum of a two-element list is the sum of its two elements-/\ntheorem sum_list2 (α : Type*) [add_monoid α] (x y : α) : list.sum [x, y] = x + y :=\nbegin\n  -- [x,y] is interpreted as (x :: (y :: nil))\n  rw list.sum_cons, -- sum (x :: [y]) = x + sum [y] \n  rw list.sum_cons, -- sum (y :: nil) = y + sum nil \n  rw list.sum_nil, -- sum nil = 0\n  rw add_zero, -- y + 0 = 0\nend\n\n", "meta": {"author": "ImperialCollegeLondon", "repo": "dots_and_boxes", "sha": "f7bd0b1603674a657170c5395adb717c4f670220", "save_path": "github-repos/lean/ImperialCollegeLondon-dots_and_boxes", "path": "github-repos/lean/ImperialCollegeLondon-dots_and_boxes/dots_and_boxes-f7bd0b1603674a657170c5395adb717c4f670220/src/list/lemmas/simple.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7572519835458986}}
{"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\nimport combinatorics.composition\nimport data.nat.parity\nimport tactic.apply_fun\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\nvariables {α : Type*}\n\nopen multiset nat\nopen_locale big_operators\n\n/-- A partition of `n` is a multiset of positive integers summing to `n`. -/\n@[ext, derive decidable_eq] structure partition (n : ℕ) :=\n(parts : multiset ℕ)\n(parts_pos : ∀ {i}, i ∈ parts → 0 < i)\n(parts_sum : parts.sum = n)\n\nnamespace partition\n\n/-- A composition induces a partition (just convert the list to a multiset). -/\ndef of_composition (n : ℕ) (c : composition n) : partition n :=\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\nlemma of_composition_surj {n : ℕ} : function.surjective (of_composition n) :=\nbegin\n  rintro ⟨b, hb₁, hb₂⟩,\n  rcases quotient.exists_rep b with ⟨b, rfl⟩,\n  refine ⟨⟨b, λ i hi, hb₁ hi, _⟩, partition.ext _ _ rfl⟩,\n  simpa using hb₂\nend\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-- proof obligation `l.sum = n`.\ndef of_sums (n : ℕ) (l : multiset ℕ) (hl : l.sum = n) : partition n :=\n{ parts := l.filter (≠ 0),\n  parts_pos := λ i hi, nat.pos_of_ne_zero $ by apply of_mem_filter hi,\n  parts_sum :=\n  begin\n    have lt : l.filter (= 0) + l.filter (≠ 0) = l := filter_add_not _ l,\n    apply_fun multiset.sum at lt,\n    have lz : (l.filter (= 0)).sum = 0,\n    { rw multiset.sum_eq_zero_iff,\n      simp },\n    simpa [lz, hl] using lt,\n  end }\n\n/-- A `multiset ℕ` induces a partition on its sum. -/\ndef of_multiset (l : multiset ℕ) : partition l.sum :=\nof_sums _ l rfl\n\n/-- The partition of exactly one part. -/\ndef indiscrete_partition (n : ℕ) : partition n :=\nof_sums n {n} rfl\n\ninstance {n : ℕ} : inhabited (partition n) := ⟨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-/\nlemma count_of_sums_of_ne_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) {i : ℕ} (hi : i ≠ 0) :\n  (of_sums n l hl).parts.count i = l.count i :=\ncount_filter_of_pos hi\n\nlemma count_of_sums_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) :\n  (of_sums n l hl).parts.count 0 = 0 :=\ncount_filter_of_neg (λ h, h rfl)\n\n/--\nShow there are finitely many partitions by considering the surjection from compositions to\npartitions.\n-/\ninstance (n : ℕ) : fintype (partition n) :=\nfintype.of_surjective (of_composition n) of_composition_surj\n\n/-- The finset of those partitions in which every part is odd. -/\ndef odds (n : ℕ) : finset (partition n) :=\nfinset.univ.filter (λ c, ∀ i ∈ c.parts, ¬ even i)\n\n/-- The finset of those partitions in which each part is used at most once. -/\ndef distincts (n : ℕ) : finset (partition n) :=\nfinset.univ.filter (λ c, c.parts.nodup)\n\n/-- The finset of those partitions in which every part is odd and used at most once. -/\ndef odd_distincts (n : ℕ) : finset (partition n) := odds n ∩ distincts n\n\nend partition\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/partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.757189332312683}}
{"text": "import data.nat.gcd data.nat.prime \nimport tactic.tauto tactic.squeeze tactic.find\n\n/- --------------------------------------------------------------- -/\n-- Section 2.1.1\n\n#check 3 = 3\n#check (ff && tt = ff)\n#check (false ∧ true = false)\n\n#print notation `=`\n#print eq\n\n-- #check (3 = [3]) -- ERROR\n#check 3 = 4\n\nlemma my_first_lemma : 3 = 3 := rfl\n#check my_first_lemma\n\n/- --------------------------------------------------------------- -/\n-- Section 2.1.2\n\nlemma my_add_assoc (n m k : ℕ) : m + (n + k) = (m + n) + k :=\n (nat.add_assoc _ _ _).symm\n\nlemma my_bor_tt (b : bool) : b || tt = tt :=\n by { cases b; refl }\n\nlemma my_bor_assoc (b1 b2 b3) : b1 || (b2 || b3) = (b1 || b2) || b3 := \n by { cases b1; cases b2; cases b3; refl, }\n\n-- Next example skipped because bool implication is not predefined in Lean\n\nlemma my_bnot_and (a b : bool) : bnot (a && b) = (bnot a) || (bnot b) :=\n by { cases a; cases b; refl }\n\n/- --------------------------------------------------------------- -/\n-- Section 2.1.3\n\nlemma my_zero_le (n : ℕ) :  0 ≤ n :=\nbegin\n induction n with n ih,\n exact nat.less_than_or_equal.refl,\n exact nat.less_than_or_equal.step ih,\nend\n\ndef odd' (n : ℕ) : Prop := (n % 2 = 1)\n\nlemma eq_leq (m n : ℕ) : m = n ↔ ((m ≤ n) ∧ (n ≤ m)) := sorry\nlemma ne_lt (m n : ℕ) : m ≠ n ↔ ((m < n) ∨ (n < m)) := sorry\nlemma le_zero (n : ℕ) : n ≤ 0 ↔ n = 0 := sorry\nlemma dvd_one (d : ℕ) : (d ∣ 1) ↔ (d = 1) := sorry \nlemma odd_mul (m n : ℕ) : odd' (m * n) ↔ (odd' n) ∧ (odd' m) := sorry\n\n\n/- --------------------------------------------------------------- -/\n-- Section 2.1.4\n\nlemma leq_pmull (m n : ℕ) : (n > 0) → m ≤ n * m := sorry\nlemma odd_gt_zero (n : ℕ) : odd' n → n > 0 := sorry\n\nlemma dvd_mul (d1 d2 m1 m2 : ℕ) : (d1 ∣ m1) → (d2 ∣ m2) → d1 * d2 ∣ m1 * m2 := sorry\n\n/- --------------------------------------------------------------- -/\n-- Section 2.2.1\n\nlemma my_first_lemma' : 3 = 3 := by refl\n\nlemma my_second_lemma : 2 + 1 = 3 := rfl\n\nlemma add_succ (m n : ℕ) : m + (nat.succ n) = nat.succ (m + n) := rfl\n\nlemma my_bnot_bnot (b : bool) : bnot (bnot b) = b := by {cases b; refl,}\n\nlemma le_zero' (n : ℕ) : n ≤ 0 ↔ n = 0 := \nby { cases n with k; simp, }\n\nlemma my_mul_eq_zero (m n : ℕ) : (m * n = 0) ↔ (m = 0) ∨ (n = 0) := \nbegin\n cases n; cases m;\n try {simp [-nat.mul_eq_zero]}\nend\n\n/- --------------------------------------------------------------- -/\n-- Section 2.3.1\n\ndef is_zero : ℕ → bool \n| 0 := tt\n| _ := ff\n\ndef my_le (n m : ℕ) : bool := is_zero (n - m)\n\nlemma le_zero'' (n m : ℕ) : (my_le n 0) = is_zero n := \nbegin\n cases n; dsimp[my_le]; refl,\nend\n\nlemma list_ext (s₁ s₂ : list ℕ) : \n s₁.length = s₂.length → ∀ i, s₁.nth i = s₂.nth i → s₁ = s₂ := sorry\n\nlemma map_length {α β : Type} (f : α → β) (s : list α) : \n list.length (list.map f s) = list.length s := sorry\n\ndef my_commutative {α β : Type} (op : α → α → β) := \n ∀ a₁ a₂ : α, op a₁ a₂ = op a₂ a₁ \n\nlemma my_add_comm : my_commutative nat.add := nat.add_comm\n\n#print associative\n#print right_distrib\n#print left_distrib\n#print left_identity\n#print function.injective\n#print function.left_inverse\n\n/- --------------------------------------------------------------- -/\n-- Section 2.3.2\n\nsection chinese\n\nvariables m₁ m₂ : ℕ \nvariable co_n12 : nat.coprime m₁ m₂  \n\nlemma chinese_remainder (x y : ℕ) : \n x % (m₁ * m₂) = y % (m₁ * m₂) ↔ x % m₁ = y % m₁ ∧ x % m₂ = y % m₂ := sorry\n\nend chinese\n\n/- --------------------------------------------------------------- -/\n-- Section 2.3.3\n\nlemma my_le_refl (n : ℕ) : n ≤ n := le_refl n\n\nexample (a b : ℕ) : a + b ≤ a + b := my_le_refl (a + b)\n\nexample (a b : ℕ) : a + (nat.succ b) ≤ nat.succ (a + b) := \nbegin\n apply my_le_refl,\nend\n\nattribute [simp] my_le_refl \n\nexample (a b : ℕ) : a + (nat.succ b) ≤ nat.succ (a + b) := sorry\n\nlemma contra (c b : Prop) : (¬ c → ¬ b) → (b → c) := \nbegin\n intros h hb,\n cases classical.em c with hc hnc,\n {exact hc},\n {exact false.elim (h hnc hb)}\nend\n\nexample (m p : ℕ) : nat.prime p → p ∣ ((nat.factorial m) + 1) → m < p := \nbegin\n intro prime_p,\n apply contra,\n intro h0,\n have leq_p_m : p ≤ m := le_of_not_gt h0,\n rw[← (@nat.dvd_add_iff_right p (nat.factorial m) 1)],\n {exact nat.prime.not_dvd_one prime_p},\n {exact nat.dvd_factorial (nat.prime.pos prime_p) leq_p_m}\nend\n\nexample (m p : ℕ) : nat.prime p → p ∣ ((nat.factorial m) + 1) → m < p := \nbegin\n intros prime_p d1,\n cases lt_or_ge m p, assumption, exfalso,\n rw[← (@nat.dvd_add_iff_right p (nat.factorial m) 1)] at d1,\n exact nat.prime.not_dvd_one prime_p d1,\n exact nat.dvd_factorial (nat.prime.pos prime_p) h,\nend\n\n/- --------------------------------------------------------------- -/\n-- Section 2.3.4\n\n#check @nat.rec\n#check @list.rec\n\nlemma my_add_zero (m : ℕ) : m + 0 = m := rfl\nlemma my_zero_add (m : ℕ) : 0 + m = m := \nbegin\n induction m with m ih,refl,exact congr_arg nat.succ ih,\nend\n\nlemma last_ind (α : Type) (P : list α → Prop) :\n (P list.nil) → (∀ s x, P s → P (s.concat x)) → ∀ s, P s := \nbegin\n intros P_nil P_step,\n let C : (list α) → Prop := λ s,\n  (∀ (Q : list α → Prop) (Q_nil : Q list.nil)\n   (Q_step : ∀ t x, Q t → Q (t.concat x)), Q s),\n have h : ∀ s : list α, C s,\n {intro s,\n  induction s with w s ih,\n  {intros Q Q_nil Q_step,exact Q_nil},\n  {intros Q Q_nil Q_step,\n   let R := λ t, Q (w :: t),\n   let R_nil : R list.nil := Q_step list.nil w Q_nil,\n   let R_step : ∀ t x, R t → R (t.concat x) := \n    λ t x R_t, Q_step (w :: t) x R_t,\n   exact ih R R_nil R_step,\n  }\n },\n intro s,\n exact h s P P_nil P_step,\nend\n\nlemma foldl_rev (α β : Type) (f : α → β → α) (z : α) (s : list β) :\n list.foldl f z s.reverse = list.foldr (λ x z, f z x) z s := \nbegin\n revert z,\n refine last_ind β _ _ _ s,\n {intro z,simp,},\n {intros t x h0 z,\n  have h1 : list.reverse (list.concat t x) = x :: (list.reverse t) := by simp,\n  have h2 : t.concat x = t ++ [x] := by simp,\n  rw[h1,h2,list.foldl,h0 (f z x),list.foldr_append,list.foldr,list.foldr],\n }\nend\n\n/- --------------------------------------------------------------- -/\n-- Section 2.4\n\nexample (m p : ℕ) : nat.prime p → p ∣ ((nat.factorial m) + 1) → m < p := \nbegin\n intros prime_p,apply contra,intros h0 d1,\n exact nat.prime.not_dvd_one prime_p\n  ((@nat.dvd_add_iff_right p (nat.factorial m) 1 (nat.dvd_factorial (nat.prime.pos prime_p) (le_of_not_gt h0))).mpr d1), \nend\n\n/- --------------------------------------------------------------- -/\n-- Section 2.5\n\n-- #find nat.bodd\n-- #find (_ ∣ nat.fact _)\n-- #find nat.coprime\n-- #find (_ * _ = _ * _)\n\n/- --------------------------------------------------------------- -/\n-- Exercises for Chapter 2\n\nexample (b1 b2 b3 : bool) : b1 || (b2 || b3) = (b1 || b2) || b3 := \n by {cases b1; cases b2; cases b3; refl,}\n\n-- Next example skipped as boolean implication is not predefined in Lean\n\nexample (a b : bool) : bnot (a && b) = (bnot a) || (bnot b) := \n by {cases a; cases b; refl,}\n\nlemma nat.sub_add : ∀ (n m k : ℕ), n - (m + k) = (n - m) - k \n| n m 0 := by {rw[add_zero,nat.sub_zero],}\n| n m (nat.succ k) := by {rw[nat.add_succ,nat.sub_succ,nat.sub_add,nat.sub_succ]}\n\nlemma nat.mul_pred (n m : ℕ) : n * (nat.pred m) = n * m - n :=\nbegin\n cases m,\n {rw[nat.pred_zero,mul_zero,nat.zero_sub],},\n {rw[nat.pred_succ,nat.mul_succ,nat.add_sub_cancel],}\nend\n\nlemma nat.pred_mul (n m : ℕ) : (nat.pred n) * m = n * m - m := \n by { rw[nat.mul_comm,nat.mul_pred,nat.mul_comm], }\n\nlemma nat.mul_sub : ∀ (n m k : ℕ), n * (m - k) = n * m - n * k\n| n m 0 := by { rw[mul_zero,nat.sub_zero,nat.sub_zero],}\n| n m (k + 1) := \n   by {rw[nat.sub_succ,nat.mul_pred,nat.mul_sub,nat.mul_succ,nat.sub_add],} \n\nlemma nat.sub_mul (n m k : ℕ) : (n - m) * k = n * k - m * k := \n by {rw[nat.mul_comm,nat.mul_sub],congr' 1;apply nat.mul_comm}\n\nexample (n m : ℕ) : m ^ 2 - n ^ 2 = (m - n) * (m + n) := \n begin\n  rw[pow_two,pow_two,nat.sub_mul,mul_add,mul_add,nat.mul_comm m n],\n  rw[nat.sub_add,nat.add_sub_cancel],\n end\n\nlemma bodd_exp (m n : ℕ) : nat.bodd (m ^ n) = (n = 0) || nat.bodd m := \nbegin\n induction n with n ih,\n {refl,},\n {rw[to_bool_ff (nat.succ_ne_zero n),ff_bor,pow_succ,nat.bodd_mul,ih],\n  cases (nat.bodd m); cases (to_bool (n = 0)); refl\n }\nend\n\ndef flatten {α : Type} (l : list (list α)) : list α := \n list.foldr list.append list.nil l\n\nlemma flatten_length {α : Type} : ∀ (l : list (list α)),\n (flatten l).length = list.sum (l.map list.length)\n| list.nil := rfl\n| (list.cons u l) := by {\n   erw[list.length_append,flatten_length l,list.map_cons,list.sum_cons],\n   }\n\ndef all_words {α : Type} : ∀ (n : ℕ) (alphabet : list α), list (list α)\n| 0 _ := [list.nil]\n| (nat.succ n) alphabet := \n   flatten (list.map (λ a,list.map (list.cons a) (all_words n alphabet)) alphabet)\n\nlemma all_words_length {α : Type} (n : ℕ) (alphabet : list α) :\n (all_words n alphabet).length = alphabet.length ^ n := \nbegin\n induction n with n ih,\n {refl,},\n {erw[all_words,flatten_length],\n  rw[pow_succ,mul_comm],\n  let f : α → list (list α) :=\n   λ a, list.map (list.cons a) (all_words n alphabet),\n  let g : α → ℕ := λ a, (f a).length,\n  let l := alphabet.map f,\n  let m := l.map list.length,\n  have h0 : ∀ a : α, g a = alphabet.length ^ n :=\n    λ a, (list.length_map _ _).trans ih,\n  have h1 : m.length = alphabet.length := \n    (list.length_map list.length l).trans (list.length_map f alphabet),\n  have h2 : ∀ i : ℕ, i ∈ m → i = alphabet.length ^ n := \n   begin\n    intros i i_in_m,\n    rcases list.mem_map.mp i_in_m with ⟨l0,⟨l0_in_l,l0_length⟩⟩,\n    rcases list.mem_map.mp l0_in_l with ⟨a,⟨a_in_alphabet,fa_eq_l0⟩⟩,\n    exact ((h0 a).symm.trans\n              ((congr_arg list.length fa_eq_l0).trans l0_length)).symm,\n   end,\n  let h3 := (@list.eq_repeat ℕ (alphabet.length ^ n) alphabet.length\n   (l.map list.length)).mpr ⟨h1,h2⟩,\n  exact ((congr_arg list.sum h3).trans \n   (list.sum_const_nat (alphabet.length ^ n) alphabet.length)),\n }\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/chapter_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7571893217056803}}
{"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 `decicdable_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) ≡ (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 ≡ 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 ≥ c` and that `count I w ≡ 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_repeat (n : ℕ) : derivable (M::(repeat I (2^n))) :=\nbegin\n  induction n with k hk,\n  { constructor, }, -- base case\n  { rw [succ_eq_add_one, nat.pow_add, nat.pow_one 2, mul_two,repeat_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 ≡ 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 ≥ c` and\nwhere `d ≡ 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 ≡ 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_repeat_U_even {z : miustr} {m : ℕ} (h : derivable (z ++ repeat U (m*2)))\n  : derivable z :=\nbegin\n  induction m with k hk,\n  { revert h,\n    simp only [list.repeat, zero_mul, append_nil, imp_self], },\n  { apply hk,\n    simp only [succ_mul, repeat_add] at h,\n    change repeat U 2 with [U,U] at h,\n    rw ←(append_nil (z ++ repeat U (k*2) )),\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_repeat_I_repeat_U_append_of_der_cons_repeat_I_append (c k : ℕ)\n  (hc : c % 3 = 1 ∨ c % 3 = 2) (xs : miustr) (hder : derivable (M ::(repeat I (c+3*k)) ++ xs)) :\n    derivable (M::(repeat I c ++ repeat U k) ++ xs) :=\nbegin\n  revert xs,\n  induction k with a ha,\n  { simp only [list.repeat, mul_zero, add_zero, append_nil, forall_true_iff, imp_self],},\n  { intro xs,\n    specialize ha (U::xs),\n    intro h₂,\n    simp only [succ_eq_add_one, repeat_add], -- We massage the goal\n    rw [←append_assoc, ←cons_append],        -- into a form amenable\n    change repeat U 1 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 repeat I 3,\n    simp only [cons_append, ←repeat_add],\n    convert h₂, },\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 : ℕ) : ∃ 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, ←two_mul, mul_mod_right],\nend\n\nprivate lemma le_pow2_and_pow2_eq_mod3' (c : ℕ) (x : ℕ) (h : c = 1 ∨ c = 2) :\n  ∃ m : ℕ, c + 3*x ≤ 2^m ∧ 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 ⟨g, hkg, hgmod⟩,\n    by_cases hp : (c + 3*(k+1) ≤ 2 ^g),\n    { use g, exact ⟨hp,hgmod⟩ },\n    use (g+2),\n    { split,\n      { rw [mul_succ, ←add_assoc,nat.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 [nat.pow_add,←mul_one c],\n        exact modeq.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 ≤ k` and `a ≡ k [MOD 3]`.\n-/\nlemma le_pow2_and_pow2_eq_mod3 (a : ℕ) (h : a % 3 = 1 ∨ a % 3 = 2) :\n  ∃ m : ℕ, a ≤ 2^m ∧ 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 repeat_pow_minus_append  {m : ℕ} : M :: repeat I (2^m - 1) ++ [I] = M::(repeat I (2^m)) :=\nbegin\n  change [I] with repeat I 1,\n  rw [cons_append, ←repeat_add, nat.sub_add_cancel (one_le_pow' m 1)],\nend\n\n/--\n`der_repeat_I_of_mod3` states that `M::y` is `derivable` if `y` is any `miustr` consisiting just of\n`I`s, where `count I y` is 1 or 2 modulo 3.\n-/\nlemma der_repeat_I_of_mod3 (c : ℕ) (h : c % 3 = 1 ∨ c % 3 = 2):\n  derivable (M::(repeat I c)) :=\nbegin\n  -- From `der_cons_repeat`, 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₂ : derivable (M::(repeat I (2^m)) ++ repeat U ((2^m -c)/3 % 2)),\n  { cases mod_two_eq_zero_or_one ((2^m -c)/3) with h_zero h_one,\n    { simp only [der_cons_repeat m, append_nil,list.repeat, h_zero], }, -- `(2^m - c)/3 ≡ 0 [MOD 2]`\n    { rw [h_one, ←repeat_pow_minus_append, append_assoc], -- case `(2^m - c)/3 ≡ 1 [MOD 2]`\n      apply derivable.r1,\n      rw repeat_pow_minus_append,\n      exact (der_cons_repeat m), }, },\n  have hw₃ : derivable (M::(repeat I c) ++ repeat U ((2^m-c)/3) ++ repeat U ((2^m-c)/3 % 2)),\n  { apply der_cons_repeat_I_repeat_U_append_of_der_cons_repeat_I_append c ((2^m-c)/3) h,\n    convert hw₂, -- now we must show `c + 3 * ((2 ^ m - c) / 3) = 2 ^ m`\n    rw nat.mul_div_cancel',\n    { exact add_sub_of_le hm.1, },\n    { exact (modeq.modeq_iff_dvd' hm.1).mp hm.2.symm, }, },\n  rw [append_assoc, ←repeat_add _ _] at hw₃,\n  cases add_mod2 ((2^m-c)/3) with t ht,\n  rw ht at hw₃,\n  exact der_of_der_append_repeat_U_even hw₃,\nend\n\nexample (c : ℕ) (h : c % 3 = 1 ∨ c % 3 = 2):\n  derivable (M::(repeat I c)) :=\nbegin\n  -- From `der_cons_repeat`, 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₂ : derivable (M::(repeat I (2^m)) ++ repeat U ((2^m -c)/3 % 2)),\n  { cases mod_two_eq_zero_or_one ((2^m -c)/3) with h_zero h_one,\n    { simp only [der_cons_repeat m, append_nil, list.repeat,h_zero], }, -- `(2^m - c)/3 ≡ 0 [MOD 2]`\n    { rw [h_one, ←repeat_pow_minus_append, append_assoc], -- case `(2^m - c)/3 ≡ 1 [MOD 2]`\n      apply derivable.r1,\n      rw repeat_pow_minus_append,\n      exact (der_cons_repeat m), }, },\n  have hw₃ : derivable (M::(repeat I c) ++ repeat U ((2^m-c)/3) ++ repeat U ((2^m-c)/3 % 2)),\n  { apply der_cons_repeat_I_repeat_U_append_of_der_cons_repeat_I_append c ((2^m-c)/3) h,\n    convert hw₂, -- now we must show `c + 3 * ((2 ^ m - c) / 3) = 2 ^ m`\n    rw nat.mul_div_cancel',\n    { exact add_sub_of_le hm.1, },\n    { exact (modeq.modeq_iff_dvd' hm.1).mp hm.2.symm, }, },\n  rw [append_assoc, ←repeat_add _ _] at hw₃,\n  cases add_mod2 ((2^m-c)/3) with t ht,\n  rw ht at hw₃,\n  exact der_of_der_append_repeat_U_even hw₃,\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 ∉ 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 ⟨⟨mhead, nmtail⟩, hi ⟩,\n  have : en ≠ 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 ⟨y,ys,rfl⟩,\n  rw head at mhead,\n  rw mhead at *,\n  suffices  : ∃ c, repeat I c = ys ∧ (c % 3 = 1 ∨ c % 3 = 2),\n  { rcases this with ⟨c, hysr, hc⟩,\n    rw ←hysr,\n    exact der_repeat_I_of_mod3 c hc, },\n  { simp only [count] at *,\n    use (count I ys),\n    refine and.intro _ hi,\n    apply repeat_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 : ℕ} (h : count U xs = succ k) : U ∈ 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 ←h, refl, },\n    { left, refl, }, }, -- case `z = U`\nend\n\nlemma eq_append_cons_U_of_count_U_pos {k : ℕ} {zs : miustr} (h : count U zs = succ k) :\n∃ (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 : ℕ) (ys : miustr) (hu : count U ys = succ k) (hdec : decstr ys) :\n∃ (as bs : miustr), (ys = M::as ++ U:: bs) ∧ (count U (M::as ++ [I,I,I] ++ bs) = k) ∧\n  decstr (M::as ++ [I,I,I] ++ bs) :=\nbegin\n  rcases hdec with ⟨⟨mhead,nmtail⟩, hic⟩,\n  have : ys ≠ 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 ⟨z,zs,rfl⟩,\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 ⟨as,bs,hab⟩,\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 : ∃ 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 ⟨as, bs, hyab, habuc, hdecab⟩,\n    have h₂ : derivable (M::as ++ [I,I,I] ++ bs) := hk hdecab habuc,\n    rw hyab,\n    exact derivable.r3 h₂, },\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λ en, decidable_of_iff _ ⟨der_of_decstr, decstr_of_der⟩\n\n/-!\nBy decidability, we can automatically determine whether any given `miustr` is `derivable`.\n-/\n\nexample : ¬(derivable \"MU\") :=\ndec_trivial\n\nexample : derivable \"MUIUIUIIIIIUUUIUII\" :=\ndec_trivial\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_suf.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7571805385388393}}
{"text": "import data.real.basic\n\nopen_locale classical\n\n/-\nTheoretical negations.\n\nThis file is for people interested in logic who want to fully understand\nnegations.\n\nHere we don't use `contrapose` or `push_neg`. The goal is to prove lemmas\nthat are used by those tactics. Of course we can use\n`exfalso`, `by_contradiction` and `by_cases`.\n\nIf this doesn't sound like fun then skip ahead to the next file.\n-/\n\nsection negation_prop\n\nvariables P Q : Prop\n\n-- 0055\nexample : (P → Q) ↔ (¬ Q → ¬ P) :=\nbegin\n  -- sorry\n  split,\n  { intros h hnQ hP,\n    exact hnQ (h hP) },\n  { intros h hP,\n    by_contradiction hnQ,\n    exact h hnQ hP },\n  -- sorry\nend\n\n-- 0056\nlemma non_imp (P Q : Prop) : ¬ (P → Q) ↔ P ∧ ¬ Q :=\nbegin\n  -- sorry\n  split,\n  { intro h,\n    by_contradiction H,\n    apply h,\n    intro hP,\n    by_contradiction H',\n    apply H,\n    exact ⟨hP, H'⟩ },\n  { intros h h',\n    cases h with hP hnQ,\n    exact hnQ (h' hP) },\n  -- sorry\nend\n\n-- In the next one, let's use the axiom\n-- propext {P Q : Prop} : (P ↔ Q) → P = Q\n\n-- 0057\nexample (P : Prop) : ¬ P ↔ P = false :=\nbegin\n  -- sorry\n  split,\n  { intro h,\n    apply propext,\n    split,\n    { intro h',\n      exact h h' },\n    { intro h,\n      exfalso,\n      exact h } },\n  { intro h,\n    rw h,\n    exact id },\n  -- sorry\nend\n\nend negation_prop\n\nsection negation_quantifiers\nvariables (X : Type) (P : X → Prop)\n\n-- 0058\nexample : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x :=\nbegin\n  -- sorry\n  split,\n  { intro h,\n    by_contradiction H,\n    apply h,\n    intros x,\n    by_contradiction H',\n    apply H,\n    use [x, H'] },\n  { rintros ⟨x, hx⟩ h',\n    exact hx (h' x) },\n  -- sorry\nend\n\n-- 0059\nexample : ¬ (∃ x, P x) ↔ ∀ x, ¬ P x :=\nbegin\n  -- sorry\n  split,\n  { intros h x h',\n    apply h,\n    use [x, h'] },\n  { rintros h ⟨x, hx⟩,\n    exact h x hx },\n  -- sorry\nend\n\n-- 0060\nexample (P : ℝ → Prop) : ¬ (∃ ε > 0, P ε) ↔ ∀ ε > 0, ¬ P ε :=\nbegin\n  -- sorry\n  split,\n  { intros h ε ε_pos hP,\n    apply h,\n    use [ε, ε_pos, hP] },\n  { rintros h ⟨ε, ε_pos, hP⟩,\n    exact h ε ε_pos hP },\n  -- sorry\nend\n\n-- 0061\nexample (P : ℝ → Prop) : ¬ (∀ x > 0, P x) ↔ ∃ x > 0, ¬ P x :=\nbegin\n  -- sorry\n  split,\n  { intros h,\n    by_contradiction H,\n    apply h,\n    intros x x_pos,\n    by_contradiction HP,\n    apply H,\n    use [x, x_pos, HP] },\n  { rintros ⟨x, xpos, hx⟩ h',\n    exact hx (h' x xpos) },\n  -- sorry\nend\n\nend negation_quantifiers\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/07bis_abstract_negations.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8333246035907932, "lm_q1q2_score": 0.7571736529012213}}
{"text": "namespace hidden\n\nset_option trace.simplify true\n\n@[class] structure group (α : Type) : Type :=\n(mul : α → α → α)\n(one : α)\n(inv : α → α)\n(mul_assoc : ∀ a b c, mul (mul a b) c = mul a (mul b c))\n(one_mul : ∀ a, mul one a = a)\n(mul_left_inv : ∀ a, mul (inv a) a = one)\n\n-- potential instance of group class\ninductive ℤ₂ : Type\n| zero\n| one\n\ndef ℤ₂.add : ℤ₂ → ℤ₂ → ℤ₂\n| ℤ₂.zero a       := a\n| a       ℤ₂.zero := a\n| ℤ₂.one  ℤ₂.one  := ℤ₂.zero\n\n-- def ℤ₂.neg (a : ℤ₂) := a\n\nnotation `z0` := ℤ₂.zero\nnotation `z1` := ℤ₂.one\n\n-- #reduce ℤ₂.neg z0 -- z0\n-- #reduce ℤ₂.neg z1 -- z1\n\n#print add_group\n\n-- proof of fact that ℤ₂ structure is group\n@[instance] def ℤ₂.add_group : add_group ℤ₂ :=\n{\n  add := ℤ₂.add,\n  add_assoc := by intros a b c; cases a; cases b; cases c; simp only [(+), ℤ₂.add],\n  zero := ℤ₂.zero,\n  zero_add := by intro a; cases a; simp only [(+), ℤ₂.add],\n  add_zero := by intro a; cases a; simp only [(+), ℤ₂.add],\n  neg      := (λ x, x),\n  add_left_neg := begin\n    intro a,\n    -- have h : Z₂.add_group.neg a = a,\n    simp only [],\n    cases a,\n    trivial, -- or refl\n    refl,\n  end,\n}\n\n-- With this instance declaration, \n-- we can now use the notations 0, +, and -:\n#reduce ℤ₂.one + 0 - 0 - ℤ₂.one -- ℤ₂.zero\n#reduce ℤ₂.one + 0 + ℤ₂.one -- ℤ₂.zero\n\n#reduce z0 + z0 -- z0\n#reduce z0 + z1 -- z1\n#reduce z1 + z0 -- z1\n#reduce z1 + z1 -- z0\n-- #reduce (3 : ℤ₂)\n\nexample (a : ℤ₂) : \n  a + a = z0 :=\nbegin\n-- simp [ℤ₂.add], -- fails\n  cases a; refl,  \nend\n\nlemma ex1 (a : ℤ₂) (b : ℤ₂) : \n  a ≠ b → a + b = z1 :=\nbegin\n  intro h,\n  cases a; cases b,\n    exfalso, simp at h, exact h,\n    refl,\n    refl,\n    exfalso, simp at h, exact h,\nend\n\nlemma ex2 (a : ℤ₂) (b : ℤ₂) : \n  a ≠ b → a + b = z1 :=\nbegin\n  intro h,\n  cases a; cases b,\n  repeat {\n    refl <|> { exfalso, simp at h, exact h },\n  },\nend\n#print ex1\n#print ex2\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/foundations_of_mathematics/basic_mathematical_structures.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7571736352500797}}
{"text": "import tactic \nimport algebra.field \nimport analysis.complex.polynomial\nimport data.multiset.basic\nimport field_theory.splitting_field\n\nnoncomputable theory\nopen_locale classical\n\nopen complex polynomial\n\nuniverses u \nvariables {k : Type u}  [field k]\n\nclass algebraically_closed (k : Type u) extends field k :=\n(exists_root (f : polynomial k) (hf : 0 < degree f) : ∃ z : k, is_root f z)\n\n\n-- need a better name\nlemma linear_factor_poly [algebraically_closed k] {f : polynomial ℂ} (hge0 : 0 < f.degree) : \n  splits (ring_hom.id ℂ) f :=\nbegin \nsorry,\nend \n\ninstance : algebraically_closed ℂ := \nsorry\n\n#check splits\n#check ring_hom.id ℂ\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/algebraically_closed.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7571554306871201}}
{"text": "import game.world10.level16 -- hide\nnamespace mynat -- hide\n/- \n\n# Inequality world. \n\n## Level 17: definition of `<`\n\nOK so we are going to *define* `a < b` by `a ≤ b ∧ ¬ (b ≤ 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 ↔ succ(a) ≤ b`. \n\n-/\n\ndefinition lt (a b : mynat) := a ≤ b ∧ ¬ (b ≤ a)\n\n-- incantation so that we can use `<` notation: \ninstance : has_lt mynat := ⟨lt⟩\n\n/- Lemma : \nFor all naturals $a$ and $b$,\n$$a<b\\iff\\operatorname{succ}(a)\\le b.$$\n-/\nlemma lt_iff_succ_le (a b : mynat) : a < b ↔ succ a ≤ b :=\nbegin [nat_num_game]\n  split,\n    exact lt_aux_one a b,\n  exact lt_aux_two a b,\n\n\nend\n/-\nFor now -- that's it. In the next version of the natural number game we will go on and make\nthe natural numbers into an `ordered_cancel_comm_monoid`, which is the most\nexotic of all the structures defined on the natural numbers in Lean 3.4.2.\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\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/level17.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625126757596, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.757155425899697}}
{"text": "import number_theory.basic\nimport data.nat.totient\nimport data.nat.pow\nimport field_theory.finite.basic\n\nopen nat\n\ndef encrypt (e n m : ℕ) := m ^ e % n\ndef decrypt (d n m : ℕ) := m ^ d % n\n\ntheorem RSA_correct (n d e m : ℕ) (h₁ : ∃ k : ℕ, e * d = n.totient * k + 1) \n        (h₂ : m.coprime n) :\n        decrypt d n (encrypt e n m) ≡ m [MOD n] :=\nbegin\n  rw [encrypt, decrypt],\n  rw ← pow_mod,\n  rw ← pow_mul,\n  apply modeq.trans (mod_modeq _ _),\n  cases h₁ with k h,\n  rw h,\n  rw [pow_add, pow_mul, pow_one],\n  suffices h' : (m ^ n.totient) ^ k ≡ 1 [MOD n],\n  { nth_rewrite_rhs 0 ← one_mul m,\n    exact modeq.mul_right m h', },\n  { rw ← one_pow k,\n    apply modeq.pow,\n    exact modeq.pow_totient h₂, }\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/proofs introduced in CSC110/correctness_of_RSA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.970687766704745, "lm_q2_score": 0.7799929053683038, "lm_q1q2_score": 0.7571295713575044}}
{"text": "import data.int.basic\n\nsection\n  variable A : Type\n  variable f : A → A\n  variable P : A → Prop\n  variable h : ∀ x, P x → P (f x)\n\n  -- Show the following:\n  example : ∀ y, P y → P (f (f y)) :=\n    assume y,\n    assume Py: P y,\n    have Py_imp_Pfy: P y → P (f y), from h y,\n    have Pfy: P (f y), from Py_imp_Pfy Py,\n    have Pfy_imp_Pffy: P (f y) → P (f(f y)), from h (f y),\n    show P (f (f y)), from Pfy_imp_Pffy Pfy\nend\n\nsection\n  variable U : Type\n  variables A B : U → Prop\n\n  example : (∀ x, A x ∧ B x) → ∀ x, A x :=\n    assume h,\n    assume x,\n    have Ax_and_Bx: A x ∧ B x, from h x,\n    show A x, from and.left Ax_and_Bx\nend\n\nsection\n  variable U : Type\n  variables A B C : U → Prop\n\n  variable h1 : ∀ x, A x ∨ B x\n  variable h2 : ∀ x, A x → C x\n  variable h3 : ∀ x, B x → C x\n\n  example : ∀ x, C x :=\n    assume x,\n    have Ax_or_Bx: A x ∨ B x, from h1 x,\n    have Ax_imp_Cx: A x → C x, from h2 x,\n    have Bx_imp_Cx: B x → C x, from h3 x,\n    show C x, from or.elim Ax_or_Bx Ax_imp_Cx Bx_imp_Cx\nend\n\nsection\n  variable Person : Type\n  variable shaves : Person → Person → Prop\n  variable barber : Person\n  variable h : ∀ x, shaves barber x ↔ ¬ shaves x x\n\n  example : false :=\n    have h_barber: shaves barber barber ↔ ¬ shaves barber barber, from h barber,\n    have h1: ¬shaves barber barber,\n      from assume h_shaves,\n      show false, from (h_barber.elim_left h_shaves) h_shaves,\n    show false, from h1 (h_barber.elim_right h1)\nend\n\nsection\n  variable U : Type\n  variables A B : U → Prop\n\n  example : (∃ x, A x) → ∃ x, A x ∨ B x :=\n    assume h,\n    exists.elim h $\n      assume x (h1: A x),\n      have A x ∨ B x, from or.inl h1,\n      exists.intro x this\nend\n\nsection\n  variable U : Type\n  variables A B : U → Prop\n\n  variable h1 : ∀ x, A x → B x\n  variable h2 : ∃ x, A x\n\n  example : ∃ x, B x :=\n   exists.elim h2 $\n    assume x (Ax : A x),\n    have Ax_imp_Bx: A x → B x, from h1 x,\n    have B x, from Ax_imp_Bx Ax,\n    exists.intro x this\nend\n\nsection\n  variable  U : Type\n  variables A B C : U → Prop\n\n  example (h1 : ∃ x, A x ∧ B x) (h2 : ∀ x, B x → C x) :\n  ∃ x, A x ∧ C x :=\n    exists.elim h1 $\n      assume x (Ax_and_Bx: A x ∧ B x),\n      have Bx_imp_Cx: B x → C x, from h2 x,\n      have Ax: A x, from and.left Ax_and_Bx,\n      have Bx: B x, from and.right Ax_and_Bx,\n      have Cx: C x, from Bx_imp_Cx Bx,\n      have Ax_and_Cx: A x ∧ C x, from and.intro Ax Cx,\n      exists.intro x Ax_and_Cx\nend\n\nsection\n  variable  U : Type\n  variables A B C : U → Prop\n\n  example : (¬ ∃ x, A x) → ∀ x, ¬ A x :=\n    assume h,\n    assume x,\n    assume Ax,\n    have exists_Ax: ∃x, A x, from exists.intro x Ax,\n    show false, from h exists_Ax\n\n  example : (∀ x, ¬ A x) → ¬ ∃ x, A x :=\n    assume h,\n    assume exists_Ax,\n    exists.elim exists_Ax $\n      assume x (Ax: A x),\n      have ¬A x, from h x,\n      show false, from this Ax\nend\n\nsection\n  variable  U : Type\n  variables R : U → U → Prop\n\n  example : (∃ x, ∀ y, R x y) → ∀ y, ∃ x, R x y :=\n    assume h,\n    exists.elim h $\n      assume x (h₁: ∀ y, R x y),\n      assume y,\n      have Rxy: R x y, from h₁ y,\n      exists.intro x Rxy\nend\n\nsection\n  variable {A : Type}\n  variables {a b c : A}\n\n  theorem foo {A : Type} {a b c : A} : a = b → c = b → a = c :=\n  sorry\n\n  theorem my_symm (h : b = a) : a = b :=\n    have a = a, from rfl,\n    show a = b, from foo ‹a = a› h\n\n  theorem my_trans (h1 : a = b) (h2 : b = c) : a = c :=\n    have c = b, from my_symm h2,\n    show a = c, from foo h1 ‹c = b›\nend\n\nsection\n  variables x y z : ℤ\n\n  theorem t1 : x - x = 0 :=\n  calc\n  x - x = x + -x : by rw sub_eq_add_neg\n      ... = 0      : by rw add_right_neg\n\n  theorem t2 (h : x + y = x + z) : y = z :=\n  calc\n  y     = 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\n  theorem t3 (h : x + y = z + y) : x = z :=\n  calc\n  x     = x + 0        : by rw add_zero\n      ... = x + (y + -y) : by rw 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\n  theorem t4 (h : x + y = 0) : x = -y :=\n  calc\n  x     = 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\n  theorem t5 : x * 0 = 0 :=\n  have h1 : x * 0 + x * 0 = x * 0 + 0, from\n  calc\n      x * 0 + x * 0 = x * (0 + 0) : by rw left_distrib\n              ... = x * 0       : by rw add_zero\n              ... = x * 0 + 0   : by rw add_zero,\n  show x * 0 = 0, from t2 _ _ _ h1\n\n  theorem t6 : x * (-y) = -(x * y) :=\n  have h1 : x * (-y) + x * y = 0, from\n  calc\n      x * (-y) + x * y = x * (-y + y) : by rw left_distrib\n                  ... = x * 0        : by rw add_left_neg\n                  ... = 0            : by rw t5 x,\n  show x * (-y) = -(x * y), from t4 _ _ h1\n\n  theorem t7 : x + x = 2 * x :=\n  calc\n  x + x = 1 * x + 1 * x : by rw one_mul\n      ... = (1 + 1) * x   : by rw right_distrib\n      ... = 2 * x         : rfl\nend", "meta": {"author": "TateKennington", "repo": "logic-and-proof-exercises", "sha": "acca8882026e7b643453eb096d3021cd043005bd", "save_path": "github-repos/lean/TateKennington-logic-and-proof-exercises", "path": "github-repos/lean/TateKennington-logic-and-proof-exercises/logic-and-proof-exercises-acca8882026e7b643453eb096d3021cd043005bd/chapter9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7569403725087285}}
{"text": "import data.real.basic\nimport data.nat.gcd\n\nopen nat\n\n#check add_lt_add_of_lt_of_le\n#check add_lt_add_of_le_of_lt\n#check int.sub_lt_sub_of_lt_of_le\n\n-- BEGIN\n\n/- In the follwoing example,we use dvd_gcd_iff to replace an expression of \nthe form m ∣ gcd n k by the equivalent expression m ∣ n ∧ m ∣ k -/\nexample : 3 ∣ gcd 6 15 :=\nbegin\n  rw dvd_gcd_iff,\n  split,\n  { use 2, norm_num,},\n  { use 5, norm_num,}\nend\n\nexample (x y z : ℝ) (h : x + y > z) : x > z - y :=\nsub_lt_iff_lt_add.mpr h\n\nexample (x y z : ℝ) (h : x + y < z) : x < z - y :=\nlt_sub_iff_add_lt.mpr h\n\n/- It is often convenient to rewrite a statement to an equivalent one\n In the following example, we use abs_lt to replace an expression of \n the form abs x < y by the equivalent expression - y < x ∧ x < y -/\nexample (x y : ℝ) : abs (x + 3) < 5 → -8 < x ∧ x < 2 :=\nbegin\n  rw abs_lt,\n  intro h,\n  cases h with h1 h2,\n  split,\n  rw ← sub_lt_iff_lt_add at h1,\n  norm_num at h1,\n  exact h1,\n  rw ← lt_sub_iff_add_lt at h2,\n  norm_num at h2,\n  exact h2,\nend\n\n\nexample (x y : ℝ) : abs (x + 3) < 5 → -8 < x ∧ x < 2 :=\nbegin\n  rw abs_lt,\n  intro h,\n  cases h with h1 h2,\n  split;\n  linarith,\nend\n\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/5_split/5.1_conjunc/ex4_split_dvd_abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7569395836900146}}
{"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\nimport data.polynomial.degree.trailing_degree\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\nnoncomputable theory\nopen_locale classical\n\nopen polynomial finsupp finset\n\nnamespace polynomial\n\nvariables {R : Type*} [semiring R] {f : polynomial R}\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 (f : polynomial R) : polynomial R :=\nfinsupp.erase f.nat_degree f\n\nsection erase_lead\n\nlemma erase_lead_support (f : polynomial R) :\n  f.erase_lead.support = f.support.erase f.nat_degree :=\n-- `rfl` fails because LHS uses `nat.decidable_eq` but RHS is classical.\nby convert rfl\n\nlemma erase_lead_coeff (i : ℕ) :\n  f.erase_lead.coeff i = if i = f.nat_degree then 0 else f.coeff i :=\n-- `rfl` fails because LHS uses `nat.decidable_eq` but RHS is classical.\nby convert rfl\n\n@[simp] lemma erase_lead_coeff_nat_degree : f.erase_lead.coeff f.nat_degree = 0 :=\nfinsupp.erase_same\n\nlemma erase_lead_coeff_of_ne (i : ℕ) (hi : i ≠ f.nat_degree) :\n  f.erase_lead.coeff i = f.coeff i :=\nfinsupp.erase_ne hi\n\n@[simp] lemma erase_lead_zero : erase_lead (0 : polynomial R) = 0 :=\nfinsupp.erase_zero _\n\n@[simp] lemma erase_lead_add_monomial_nat_degree_leading_coeff (f : polynomial R) :\n  f.erase_lead + monomial f.nat_degree f.leading_coeff = f :=\nbegin\n  ext i,\n  simp only [erase_lead_coeff, coeff_monomial, coeff_add, @eq_comm _ _ i],\n  split_ifs with h,\n  { subst i, simp only [leading_coeff, zero_add] },\n  { exact add_zero _ }\nend\n\n@[simp] lemma erase_lead_add_C_mul_X_pow (f : polynomial R) :\n  f.erase_lead + (C f.leading_coeff) * X ^ f.nat_degree = f :=\nby rw [C_mul_X_pow_eq_monomial, erase_lead_add_monomial_nat_degree_leading_coeff]\n\n@[simp] lemma self_sub_monomial_nat_degree_leading_coeff {R : Type*} [ring R] (f : polynomial R) :\n  f - monomial f.nat_degree f.leading_coeff = f.erase_lead :=\n(eq_sub_iff_add_eq.mpr (erase_lead_add_monomial_nat_degree_leading_coeff f)).symm\n\n@[simp] lemma self_sub_C_mul_X_pow {R : Type*} [ring R] (f : polynomial R) :\n  f - (C f.leading_coeff) * X ^ f.nat_degree = f.erase_lead :=\nby rw [C_mul_X_pow_eq_monomial, self_sub_monomial_nat_degree_leading_coeff]\n\nlemma erase_lead_ne_zero (f0 : 2 ≤ f.support.card) : erase_lead f ≠ 0 :=\nbegin\n  rw [ne.def, ← card_support_eq_zero, erase_lead_support],\n  exact (zero_lt_one.trans_le $ (nat.sub_le_sub_right f0 1).trans\n    finset.pred_card_le_card_erase).ne.symm\nend\n\n@[simp] lemma nat_degree_not_mem_erase_lead_support : f.nat_degree ∉ (erase_lead f).support :=\nby convert not_mem_erase _ _\n\nlemma ne_nat_degree_of_mem_erase_lead_support {a : ℕ} (h : a ∈ (erase_lead f).support) :\n  a ≠ f.nat_degree :=\nby { rintro rfl, exact nat_degree_not_mem_erase_lead_support h }\n\nlemma erase_lead_support_card_lt (h : f ≠ 0) : (erase_lead f).support.card < f.support.card :=\nbegin\n  rw erase_lead_support,\n  exact card_lt_card (erase_ssubset $ nat_degree_mem_support_of_nonzero h)\nend\n\n\n\nlemma erase_lead_card_support' {c : ℕ} (fc : f.support.card = c + 1) :\n  f.erase_lead.support.card = c :=\nerase_lead_card_support fc\n\n@[simp] lemma erase_lead_monomial (i : ℕ) (r : R) :\n  erase_lead (monomial i r) = 0 :=\nbegin\n  by_cases hr : r = 0,\n  { subst r, simp only [monomial_zero_right, erase_lead_zero] },\n  { rw [erase_lead, nat_degree_monomial _ _ hr], exact erase_single }\nend\n\n@[simp] lemma erase_lead_C (r : R) : erase_lead (C r) = 0 :=\nerase_lead_monomial _ _\n\n@[simp] lemma erase_lead_X : erase_lead (X : polynomial R) = 0 :=\nerase_lead_monomial _ _\n\n@[simp] lemma erase_lead_X_pow (n : ℕ) : erase_lead (X ^ n : polynomial R) = 0 :=\nby rw [X_pow_eq_monomial, erase_lead_monomial]\n\n@[simp] lemma erase_lead_C_mul_X_pow (r : R) (n : ℕ) : erase_lead (C r * X ^ n) = 0 :=\nby rw [C_mul_X_pow_eq_monomial, erase_lead_monomial]\n\nlemma erase_lead_degree_le : (erase_lead f).degree ≤ f.degree :=\nbegin\n  rw degree_le_iff_coeff_zero,\n  intros i hi,\n  rw erase_lead_coeff,\n  split_ifs with h, { refl },\n  apply coeff_eq_zero_of_degree_lt hi\nend\n\nlemma erase_lead_nat_degree_le : (erase_lead f).nat_degree ≤ f.nat_degree :=\nnat_degree_le_nat_degree erase_lead_degree_le\n\nlemma erase_lead_nat_degree_lt (f0 : 2 ≤ f.support.card) :\n  (erase_lead f).nat_degree < f.nat_degree :=\nlt_of_le_of_ne erase_lead_nat_degree_le $ ne_nat_degree_of_mem_erase_lead_support $\n  nat_degree_mem_support_of_nonzero $ erase_lead_ne_zero f0\n\nlemma erase_lead_nat_degree_lt_or_erase_lead_eq_zero (f : polynomial R) :\n  (erase_lead f).nat_degree < f.nat_degree ∨ f.erase_lead = 0 :=\nbegin\n  by_cases h : f.support.card ≤ 1,\n  { right,\n    rw ← C_mul_X_pow_eq_self h,\n    simp },\n  { left,\n    apply erase_lead_nat_degree_lt (lt_of_not_ge h) }\nend\n\nend erase_lead\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. -/\nlemma induction_with_nat_degree_le {R : Type*} [semiring R] {P : polynomial R → Prop} (N : ℕ)\n  (P_0 : P 0)\n  (P_C_mul_pow : ∀ n : ℕ, ∀ r : R, r ≠ 0 → n ≤ N → P (C r * X ^ n))\n  (P_C_add : ∀ f g : polynomial R, f.nat_degree ≤ N → g.nat_degree ≤ N → P f → P g → P (f + g)) :\n  ∀ f : polynomial R, f.nat_degree ≤ N → P f :=\nbegin\n  intros f df,\n  generalize' hd : card f.support = c,\n  revert f,\n  induction c with c hc,\n  { exact λ f df f0, by rwa (finsupp.support_eq_empty.mp (card_eq_zero.mp f0)) },\n  { intros f df f0,\n    rw ← erase_lead_add_C_mul_X_pow f,\n    refine P_C_add f.erase_lead _ (erase_lead_nat_degree_le.trans df) _ _ _,\n    { exact (nat_degree_C_mul_X_pow_le f.leading_coeff f.nat_degree).trans df },\n    { exact hc _ (erase_lead_nat_degree_le.trans df) (erase_lead_card_support f0) },\n    { refine P_C_mul_pow _ _ _ df,\n      rw [ne.def, leading_coeff_eq_zero],\n      rintro rfl,\n      exact not_le.mpr c.succ_pos f0.ge } }\nend\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/erase_lead.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7569395794485466}}
{"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 1 : \"forall\" (`∀`)\n\nA lot of questions about sets can be reduced to questions about logic.\nWe explain how to do this in Lean.\n\nAll the sets we consider on this and the next few sheets will all be\nsubsets of an underlying set `X`, which is our \"universe\" where all\nthe maths we do will take place. This underlying set `X` is called a \"type\" in\nLean. It plays the role of a \"universe\" -- every element we consider will\nalways be an element of `X`, and every subset we consider will\nbe a subset of `X`.\n\nNotation: elements of `X` are called *terms* of the type `X` and the\nnotation is `x : X`. All the variables `x`, `y` and `z` which appear in this\nsheet will always be terms of type `X`, i.e. elements of the set `X`\nif you want to think set-theoretically.\n\nAll the sets `A`, `B`, `C` etc we consider will be subsets of `X`. \nIf `x : X` then `x` may or may not be an element of `A`, `B`, `C`,\nbut it will always be an element of `X`.\n\n## Tactics\n\nTactics you will need to know for this sheet:\n\n* `intro` (it works for `∀` goals as well as for `P → Q`)\n* `specialize`\n\n### The `intro` tactic\n\nIf the goal is `∀ x, P(x)` then `intro a,` lets `a` be an arbitrary\nelement of `X` (or, more precisely, an arbitrary term of type `X`)\nand changes the goal to `P(a)`.\n\n### The `specialize` tactic\n\nIf we have a hypothesis `h : ∀ x, P(x)` and we have a term `a : X`\nthen `specialize h a,` changes `h` to `h : P(a)`.\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-- You can start this one with `intro x`\nexample : ∀ x : X, x ∈ A → x ∈ A :=\nbegin\n  sorry,\nend\n\nexample : ∀ x : X, (x ∈ A ∧ x ∈ B) → x ∈ A :=\nbegin\n  sorry\nend\n\n-- for this one if you start with `intros h x` then you might well\n-- need `specialize h x` later on. This is how to use hypotheses with `∀` in.\nexample : (∀ x, x ∈ A ∧ x ∈ B) → (∀ x, x ∈ A) :=\nbegin\n  sorry\nend\n\nexample : (∀ x, x ∈ A ∧ x ∈ B) → (∀ y, y ∈ B ∧ y ∈ A) :=\nbegin\n  sorry\nend\n\nexample : (∀ x, x ∈ A → x ∈ B) → (∀ y, y ∈ B → y ∈ C) →\n  (∀ z, z ∈ A → z ∈ C) :=\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/sets/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.756939567519463}}
{"text": "/-\nCopyright (c) 2023 Maxwell Thum. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE. **TODO**: get this license\nAuthor: Maxwell Thum.\n-/\n--import data.finset.powerset\nimport data.set.finite\n--import data.set.default\n\n/-!\n# IMPORTANT\nI am getting hung up on little details here and there and I don't think I can make some of these decisions\nuntil I have a bigger picture of what all these definitions are supposed to serve. For now I will just try\nto build the blueprint and move on with lots of `sorry`s.\n\n# Abstract simplicial complexes (should this file be renamed? split up?)\nA *(finite) abstract simplicial complex* `K` is a pair `(V, S)`, where \n`V` is a finite set, \n`S ⊆ 𝒫(V)` is a set of subsets of `V`,\nevery `σ ∈ S` is finite, \nand for all `σ ∈ S`, \n`σ' ⊆ σ` implies `σ' ∈ S`. \n`V` is called the set of *vertices* and elements of `S` are called *simplices*.\n\n\n## Notation\n\n`σ ∈ K` means that `σ` is a simplex of `K`.\n\n`K' ⊆ K` means that the simplices of `K'` are simplices of `K`.\n\n-/\n\nuniverses u v\n\nnamespace hidden -- temporary because of the new file\n\n/-- Based off of `analysis.convex.simplicial_complex.basic`,\n`https://ncatlab.org/nlab/show/simplicial+complex`, and Keenan Crane's DDG textbook.\nI am (currently?) allowing the empty set to be a simplex. -/\n--@[ext]\nclass abstract_simplicial_complex (A : Type*) := -- making this a class again?\n(simplices : set (finset A))\n(down_closed : ∀ σ ∈ simplices, ∀ τ ⊆ σ, τ ∈ simplices)\n\nnamespace abstract_simplicial_complex\nvariables {A : Type*} [K : abstract_simplicial_complex A]\n\n/-- A `finset` belongs to an `abstract_simplicial_complex` if it's a simplex of it. -/\ninstance : has_mem (finset A) (abstract_simplicial_complex A) := ⟨λ σ K, σ ∈ K.simplices⟩\n\n/-- The degree (or dimension) of a simplex is its cardinality minus one. -/ --\ndef degree (σ : finset A) : ℤ := σ.card - 1\n\n/-- The set of `k`-simplices in `K`, the simplices in `K` with degree `k`. -/\ndef k_simplices (K : abstract_simplicial_complex A) (k : ℤ) : set (finset A) := \n  { σ ∈ K.simplices | degree σ = k }\n\n-- **TODO**: make this more in line with `analysis.convex.simplicial_complex.basic`\n/-- The set of vertices of an ASC, corresponding to its 0-simplices. -/\ndef vertices (K : abstract_simplicial_complex A) : set A := ⋃ σ ∈ K.simplices, (σ : set A)\n\n/-- A pure (abstract) `k`-simplicial complex is such that every simplex is contained in \nsome `k`-simplex. -/\ndef is_pure_k_asc (K : abstract_simplicial_complex A) (k : ℕ) : Prop :=\n  ∀ σ ∈ K.simplices, ∃ σ' ∈ K.k_simplices k, σ ⊆ σ'\n\n/-- An ASC `K'` is a subcomplex of the ASC `K` if all of `K'`'s simplices belong to `K`. -/\n--instance subcomplex : has_subset (abstract_simplicial_complex A) := ⟨λ K' K, K'.simplices ⊆ K.simplices⟩\ndef subcomplex (K' K : abstract_simplicial_complex A) : Prop := K'.simplices ⊆ K.simplices\n\n-- -- ~~Is this unnecessary now that we have an instance of `has_subset`?~~\n/-- Every ASC is a subcomplex of itself. -/\n@[simp]\nlemma asc_subcomplex_self (K : abstract_simplicial_complex A) : K.subcomplex K := rfl.subset\n\n/-\n/- I think I might prefer to just use `S ⊆ K.simplices`. Being able to just write `S ⊆ K` might be nice,\nbut `⊆` seems to be reserved for terms of the same type. -/\n/-- Proposition that a set (not necessarily itself an ASC) is a subset of an ASC. -/\ndef subset_asc (S : set (finset A)) (K : abstract_simplicial_complex A) := S ⊆ K.simplices\n\n/-- The set of simplices of a subcomplex of an ASC `K` form a subset of `K`. -/\n@[simp]\nlemma subcomplex_simplices_is_subset_asc (K' K : abstract_simplicial_complex A) \n    (K'_subc_K : K'.subcomplex K) : subset_asc K'.simplices K := K'_subc_K\n\n-- (is this lemma unnecessary?)\n/-- In particular, the simplices of an ASC are a subset of themselves. -/\n@[simp]\nlemma asc_simplices_is_subset_asc (K : abstract_simplicial_complex A) : \n    subset_asc K.simplices K := rfl.subset\n-/\n\n/-- The proposition that a subset of an ASC is closed downward\n--, which is equivalent to it forming an ASC / \n--subset by the previous lemma `of_subcomplex_is_subcomplex`. \n--Note: I understand that logically this feels a bit... circular. I don't have a good way ...\nNote 2: Both here and in `degree`, it seems weird that the definition doesn't (explicitly) \ndepend on the ASC stuff, but it's still important that we only want to talk about degree or\ndown-closedness in the context of an ASC. Right? -/\ndef is_down_closed (S : set (finset A)) (hS : S ⊆ K.simplices) : Prop := \n  ∀ σ ∈ S, ∀ τ ⊆ σ, τ ∈ S\n\n/-\n/-- Construct an ASC from a downward-closed subset of a given ASC. -/\n--@[simps]\ninstance to_asc (K : abstract_simplicial_complex A)\n  (S : set (finset A))\n  (hS : S ⊆ K.simplices)\n  (down_closed : is_down_closed S hS) :\n  abstract_simplicial_complex A :=\n{ simplices := S,\n  down_closed := down_closed, }\n\n/- The ASC constructed from a downward-closed subset of an ASC `K` is a subcomplex of `K`. -/\n@[simp]\nlemma to_asc_is_subcomplex (K : abstract_simplicial_complex A) (S : set (finset A))\n    (hS : S ⊆ K.simplices) (down_closed : is_down_closed S hS) : \n    (abstract_simplicial_complex.to_asc K S hS down_closed).subcomplex K := \n  hS\n-/\n\n/-- The star of a subset `S` of an ASC `K` is the set of simplices in `K` which contain a \nsimplex in `S`. -/\ndef star (S : set (finset A)) {hS : S ⊆ K.simplices} : set (finset A) :=\n  { σ ∈ K.simplices | ∃ σ' ∈ S, σ' ⊆ σ }\n\n/- trying to get blueprint working\n/-- The star of a subset `S` of an ASC `K` indeed forms a subset of `K`. -/\n@[simp]\nlemma star_is_subset_asc (S : set (finset A)) \n    {hS : S ⊆ K.simplices} : (@star A K S hS) ⊆ K.simplices := \n  by sorry --simp only [subset_asc, star, set.sep_subset]\n-/\n\n/-- (Downward?) closure of a single simplex. -/\ndef simplex_closure (σ : finset A) \n    (hσ : σ ∈ K.simplices) : set (finset A) :=\n  { σ' ∈ K.simplices | σ' ⊆ σ }\n\n/- **TODO**: Define union and intersection of complexes. Make these instances of `has_union`\nand `has_int` or whatever they're called. This may be a good reason to let ∅ be a simplex.\nOn a related note, do we want `subcomplex` to be an instance of `has_sub`? -/\n/-- The closure of a subset `S` of an ASC `K` is the union of the closures of its simplices.\n--Book definition: \"The closure Cl(S) is the smallest (i.e., fewest elements) subcomplex of \n--K  that contains S.\" This is a rough definition in an arbitrary type `A` / possibly infinite \n--set `K.simplices` as it is not necessarily clear that there even *exists* such a minimal set. \n--Perhaps we need a nicer definition.  -/\ndef closure (S : set (finset A)) [hS : S ⊆ K.simplices] : \n    set (finset A) := \n  ⋃ (σ ∈ S), simplex_closure σ (hS H)\n\n/- for now \n/-- The closure of a subset `S` of an ASC `K` indeed forms a subset of `K`. -/\n@[simp]\nlemma closure_is_subset_asc (S : set (finset A))\n    (hS : S ⊆ K.simplices) : (closure S hS) ⊆ K.simplices := by\n{ unfold subset_asc closure,\n  simp at *,\n  sorry\n  }\n\n@[simp]\nlemma closure_is_down_closed (S : set (finset A)) \n    (hS : subset_asc S K) : is_down_closed (closure S hS) (closure_is_subset_asc S hS) := \n  sorry\n\n/- The link of a subset of an ASC is -/\ndef link (S : set (finset A)) (hS : subset_asc S K) : set (finset A) := \n  S.star.closure.simplices \\ S.closure.star.simplices\n\n\n/--  -/\ndef boundary (K' : abstract_simplicial_complex A) [K'.subcomplex K] \n    {k : ℕ} [is_pure_k_asc K' k] : \n    abstract_simplicial_complex A := by sorry\n--{ refine (closure _)}  \n\n-/\nend abstract_simplicial_complex\n\nend hidden", "meta": {"author": "maxwell-thum", "repo": "DDG_Lean3", "sha": "8c919a75b41f21f7ea5819cbd6df6992dbb17b87", "save_path": "github-repos/lean/maxwell-thum-DDG_Lean3", "path": "github-repos/lean/maxwell-thum-DDG_Lean3/DDG_Lean3-8c919a75b41f21f7ea5819cbd6df6992dbb17b87/src/combinatorial_surface/OLD_abstract_simplicial_complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7569184873119535}}
{"text": "-- single line comment\nuniverse u\n\ndef m: Nat := 1\n\n#check m\n#check m\n\n#check (m + m)\n#eval (m + m)\n\n#check Nat × Nat\n\ndef Γ := 2 + m\n \n\ndef double (a: Nat) := a + a\n\n#eval double (double 3)\n\nsection composition\n  variable (α β γ: Type)\n\n  def compose (f: α → β) (g: β → γ): (α -> γ) := fun x: α => g (f x)\nend composition\n\ndef quadruble := compose _ _ _ double double\n\n#print compose\n\nsection composition'\n  variable (α β γ : Type)\n  variable (g : β → γ) (f : α → β) (h : α → α)\n  variable (x : α)\n\n  def compose' := g (f x)\n  def doTwice := h (h x)\n  def doThrice := h (h (h x))\nend composition'\n\ndef a: Nat := 3\n\n#eval double a\n#print compose'\n#check (Nat : Sort 1)\n#check (Prop : Sort 1)\n#check (Prop : Type)\n\n\nsection proofs \n  theorem hmm (α: Prop) (β: Prop): Prop := α\n  theorem hmm2 : Prop -> Prop -> Prop := \n    fun α β => show Prop from α\n\n  theorem hmm3 (hm: α): α := hm\n\n  axiom myProof: Prop\n\n  #check hmm\n  #check hmm2\n  #check hmm3 myProof\n  #check @hmm3\n  #check @hmm3 myProof\nend proofs\n\nsection logic\n  variable {α β π: Prop}\n  variable (ha: α) (hb: β)\n\n  theorem pair: α -> β -> α ∧ β := fun a b => And.intro a b\n  theorem unpair: (α → β → π) → α ∧ β → π := fun f a => \n    show π from f (And.left a) (And.right a)\n\n  theorem pairsCommute: (α ∧ β) → (β ∧ α) := fun p => \n    show (β ∧ α) from And.intro (And.right p) (And.left p)\n\n  example (h: α ∧ β): β ∧ α := ⟨h.right, h.left⟩\n\n  theorem thrice: (f: α) -> α ∧ α ∧ α := fun f => ⟨ f, f, f ⟩\n\n  theorem negateFunc: (β → α) → ¬α → ¬β := \n    fun f notₐ b => \n      show False from notₐ (f b)\n\n  #print pairsCommute \n  #check (⟨ha, hb⟩: α ∧ β)\n\n  theorem exFalso: (α ∧ ¬ α) → β :=\n    fun contradiction => \n      show β from (contradiction.right contradiction.left).elim\n\n  theorem pairIso: α ∧ β ↔ β ∧ α := ⟨ pairsCommute, pairsCommute ⟩\nend logic\n\nsection classical\n  open Classical \n\n  variable (α : Prop)\n\n  def dneT: Prop := ¬¬α → α\n\n  theorem doubleNegation: α ↔ ¬¬α :=\n    suffices l: α → ¬¬α from \n    suffices r: ¬¬α → α from ⟨ l, r ⟩\n    show dneT α from fun doubleNegA => (em α).elim\n      (fun p: α => p)\n      (fun p: ¬α => absurd p doubleNegA)\n    show α → ¬¬α from (fun a f => f a)\n\n  #print byCases\n\n  theorem dne: dneT α := fun nnₚ =>\n    byCases id\n      (fun nₚ => (nnₚ nₚ).elim)\n\n  #print byContradiction\n\n  theorem dne': dneT α := fun nnₚ =>\n    byContradiction fun nₚ => nnₚ nₚ \nend classical\n\nsection exercises\n  variable (p q r : Prop)\n    \n  theorem noContradictions : ¬(p ↔ ¬p) := \n    fun contradiction => \n      suffices someP: p from contradiction.mp someP someP\n      suffices someNotP: ¬p from show p from contradiction.mpr someNotP\n      show ¬p from fun p => contradiction.mp p p\nend exercises\n\nsection quantifiers\n  variable (α: Type) (r: α → α → Prop)\n  variable (transitivity: ∀x y z, r x y → r y z → r x z)\n  variable (n: Nat)\n\n  variable (trans2: ∀x y z, r x y → r y z → r x z)\n  variable (trans3: ∀τ β ω, r τ β → r β ω → r τ ω)\n\n  axiom someA: α \n\n  #print someA\n  #check transitivity\n\n  #print Eq.subst\n\n  theorem substTest: (a b c: Nat) → (myProp: Nat -> Prop) → \n    (a + b = c) → myProp c → myProp (a + b) :=\n    fun a b c myProp p₁ l  => @Eq.subst Nat (fun a => myProp a) c (a + b) p₁.symm l\n  theorem substTest': {a b c: Nat} → {myProp: Nat -> Prop} → \n    (a + b = c) → myProp c → myProp (a + b) :=\n    fun p₁ l  => p₁ ▸ l\n\n  #check @congr\n  #print congrArg\n  #print congrFun\n\n  theorem congrArgTest: {a b: Nat} → (c: Nat) → (a = b) → (a + c = b + c) :=\n    fun c p₁ => congrArg (fun a => a + c) p₁\n\nend quantifiers\n\nsection calc_\n  variable (a b c d e : Nat)\n  variable (h1 : a = b)\n  variable (h2 : b = c + 1)\n  variable (h3 : c = d)\n  variable (h4 : e = 1 + d)\n\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 T₂ : a = e :=\n    calc\n      a = b := h1\n      _ = c + 1 := h2\n      _ = d + 1 := by rw [h3]\n      _ = 1 + d := by rw [Nat.add_comm]\n      _ = e     := by rw [h4]\n\n  theorem T₃ : a = e :=\n    by rw [h1, h2, h3, Nat.add_comm, h4]\n\n  theorem T₄ : a = e := \n    by simp [h1, h2, h3, Nat.add_comm, h4]\n\n  example (a b c d : Nat) (h1 : a = b) (h2 : b ≤ c) (h3 : c + 1 < d) : a < d :=\n    calc\n      a = b     := h1\n      _ < b + 1 := Nat.lt_succ_self b\n      _ ≤ c + 1 := Nat.succ_le_succ h2\n      _ < d     := h3\n\n  variable (x y: Nat)\n\n  theorem A₁: (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 * y)        := by simp [Nat.add_mul]\n          _ = x * x + y * x + x * y + y * y          := by rw [←Nat.add_assoc]\n\n  theorem A₂: (x + y) * (x + y) = x * x + y * x + x * y + y * y :=\n    by simp [Nat.add_mul, Nat.mul_add, Nat.add_assoc]\n\n  axiom forallTest: ¬(∀a: Nat, a + a = a + 1)\n\n  theorem existsOne: ∃a: Nat, a + a = a + 1 := ⟨ 1, rfl ⟩\n  theorem existsBiggerThanOne: ∃a: Nat, a > 1 := \n    have r: 1 < 2 := Nat.succ_lt_succ (Nat.zero_lt_succ 0)\n    ⟨ 2, r ⟩\n\n  example (x : Nat) (h : x > 0) : ∃ y, y < x :=\n    ⟨ 0, h ⟩\nend calc_\n\nsection exists_print\n  variable (g : Nat → Nat → Nat)\n  variable (hg : g 0 0 = 0)\n\n  theorem gex1 : ∃ x, g x x = x := ⟨0, hg⟩\n  theorem gex2 : ∃ x, g x 0 = x := ⟨0, hg⟩\n  theorem gex3 : ∃ x, g 0 0 = x := ⟨0, hg⟩\n  theorem gex4 : ∃ x, g x x = 0 := ⟨0, hg⟩\n\n  theorem gex5 : ∃ x, g x x = 0 := ⟨0, hg⟩\n  theorem gex6 : ∃ x, g x x = 0 := ⟨0, hg⟩ \n  theorem gex7 : ∃ x, g x x = 0 := ⟨0, hg⟩\n\n  set_option pp.explicit true  -- display implicit arguments\n  #print gex1\n  #print gex2\n  #print gex3\n  #print gex4\nend exists_print\n\nsection existentials \n  variable (α : Type) (p q : α → Prop)\n\n  example (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x :=\n    match h with\n    | ⟨w, hw⟩ => ⟨w, hw.right, hw.left⟩\n\n  theorem _matches : (n: Nat) → n + 1 = 1 + n := fun n =>\n    match n with\n    | Nat.succ w => calc\n        Nat.succ w + 1 = Nat.succ (w + 1) := rfl\n        _              = Nat.succ (1 + w) := by rw [_matches w]\n        _              = 1 + Nat.succ w := rfl\n    | Nat.zero => rfl\nend existentials\n\nsection tactics\n  theorem test (p q : Prop) (hp: p) (hq: q): p ∧ q ∧ p := by\n    apply And.intro\n    case left => \n      exact hp\n    case right =>\n      apply And.intro hq hp\n\n  #print test\n\n  theorem test₂ (p q r : Prop) : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := by\n    apply Iff.intro\n    . intro h\n      apply Or.elim h.right\n      . intro hq\n        apply Or.inl\n        exact ⟨h.left, hq⟩\n      . intro hr \n        apply Or.inr\n        exact ⟨h.left, hr⟩\n    . intro h\n      apply Or.elim h\n      . intro pq \n        apply And.intro \n        . exact pq.left\n        . exact Or.inl pq.right\n      . intro pr \n        apply And.intro\n        . exact pr.left\n        . exact Or.inr pr.right\n\n  #print test₂\nend tactics\n", "meta": {"author": "Mateiadrielrafael", "repo": "lean-sandbox", "sha": "e32eafd06ef48cd9fe2c599ce08d0dabcfbb6c9e", "save_path": "github-repos/lean/Mateiadrielrafael-lean-sandbox", "path": "github-repos/lean/Mateiadrielrafael-lean-sandbox/lean-sandbox-e32eafd06ef48cd9fe2c599ce08d0dabcfbb6c9e/LeanSandbox/Noob.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.8577681031721324, "lm_q1q2_score": 0.7569184745427168}}
{"text": "/-\n   lemma o theorem si se quiere dar un nombre al resultado, sino example\n   Tipeo de → ∧ ∨ ¬ ↔ \n   Múltiples premisas\n   Introducción del implica [intro(s)] y de la conjunción [apply and.intro]\n-/ \nlemma Ejemplo1 (a b : Prop) : a → b → a ∧ b :=\nbegin\n    intro ha, \n    intro hb,         -- can be replaced by [intros ha hb],\n    apply and.intro,  -- can be replaced by [apply (and.intro ha hb)]\n        apply ha,\n        apply hb   \nend\n\n\n-- Eliminación de la conjunción [apply and.left, apply and.right]\nlemma Ejemplo2 (a b : Prop) : a ∧ ¬b → ¬b ∧ a :=\nbegin\n    intro h,\n    apply and.intro,           -- can be replaced by [apply (and.intro (and.right h) (and.left h))]\n        apply (and.right h),\n        apply (and.left h)\nend\n\n\n-- Eliminación de la disyunción [apply or.elim]\nlemma Ejemplo3 (a b c : Prop) : a ∨ b -> (a → c) -> (b → c) → c :=\nbegin\n    intros hab hac hbc,\n    apply (or.elim hab),   -- can be replaced by [apply (or.elim hab hac hbc)]\n        apply hac,\n        apply hbc\nend\n\n\n-- Eliminación del implica [apply premisa] e introducción de la disyunción [apply or.inl/inr]\nlemma Ejemplo4 (a b c : Prop) : a -> (a ∨ b → c) → c :=\nbegin\n    intros ha habc,\n    apply habc,          -- can be replaced with [apply (habc (or.inl ha))]\n        apply or.inl,\n            apply ha\nend\n\n\n-- Introducción del iff [apply iff.intro]\nlemma Ejemplo5 (a b : Prop) : a ∧ b ↔ b ∧ a :=\nbegin\n    apply iff.intro,\n        intro hab; apply (and.intro (and.right hab) (and.left hab)),\n        intro hba; apply (and.intro (and.right hba) (and.left hba))        \nend\n\n\n-- Eliminación de la negación: ¬a se define como  a → false,\n-- por lo que para eliminar ¬a debo eliminar el implica [aplicación]\n-- Eliminación de false [false.elim]\nlemma Ejemplo6 (a b : Prop) : a -> ¬a -> b :=\nbegin\n    intros ha hna,\n    apply false.elim,   -- can be replaced with [apply (false.elim (hna ha))]\n    apply (hna ha)\nend \n\n\nopen classical\nlocal attribute [instance] classical.prop_decidable\n\n-- Logica clásica: prueba por reducción al absurdo.\n-- Hay que agregar los dos comandos de arriba\n-- Para probar una proposición, [by_contradiction] pide que\n-- derivemos false a partir de la negación de la proposición. \nlemma Ejemplo7 (a : Prop) : ¬¬a → a :=\nbegin\n    intro hnna,\n    by_contradiction,\n    apply (hnna a_1)\nend\n\n\n", "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/Clases/Clase2/demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8824278664544911, "lm_q1q2_score": 0.756918469173758}}
{"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.defs\nimport algebra.invertible\n\n/-!\n# Lemmas about `inv_of` in ordered (semi)rings.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariables {α : Type*} [linear_ordered_semiring α] {a : α}\n\n@[simp] lemma inv_of_pos [invertible a] : 0 < ⅟a ↔ 0 < a :=\nbegin\n  have : 0 < a * ⅟a, by simp only [mul_inv_of_self, zero_lt_one],\n  exact ⟨λ h, pos_of_mul_pos_left this h.le, λ h, pos_of_mul_pos_right this h.le⟩\nend\n\n@[simp] lemma inv_of_nonpos [invertible a] : ⅟a ≤ 0 ↔ a ≤ 0 :=\nby simp only [← not_lt, inv_of_pos]\n\n@[simp] lemma inv_of_nonneg [invertible a] : 0 ≤ ⅟a ↔ 0 ≤ a :=\nbegin\n  have : 0 < a * ⅟a, by simp only [mul_inv_of_self, zero_lt_one],\n  exact ⟨λ h, (pos_of_mul_pos_left this h).le, λ h, (pos_of_mul_pos_right this h).le⟩\nend\n\n@[simp] lemma inv_of_lt_zero [invertible a] : ⅟a < 0 ↔ a < 0 :=\nby simp only [← not_le, inv_of_nonneg]\n\n@[simp] lemma inv_of_le_one [invertible a] (h : 1 ≤ a) : ⅟a ≤ 1 :=\nby haveI := @linear_order.decidable_le α _; exact\nmul_inv_of_self a ▸ le_mul_of_one_le_left (inv_of_nonneg.2 $ zero_le_one.trans h) 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/algebra/order/invertible.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7569034430055814}}
{"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\nUniversal and existential quantifiers. See also init.logic.\n-/\nimport .connectives\nopen inhabited nonempty\n\ntheorem exists_imp_distrib {A : Type} {B : Prop} {P : A → Prop} : ((∃ a : A, P a) → B) ↔ (∀ a : A, P a → B) :=\niff.intro (λ e x H, e (exists.intro x H)) Exists.rec\n\ntheorem forall_iff_not_exists {A : Type} {P : A → Prop} : (¬ ∃ a : A, P a) ↔ ∀ a : A, ¬ P a :=\nexists_imp_distrib\n\ntheorem not_forall_not_of_exists {A : Type} {p : A → Prop} (H : ∃ x, p x) : ¬ ∀ x, ¬ p x :=\nassume H1 : ∀ x, ¬ p x,\n  obtain (w : A) (Hw : p w), from H,\n  absurd Hw (H1 w)\n\ntheorem not_exists_not_of_forall {A : Type} {p : A → Prop} (H2 : ∀ x, p x) : ¬ ∃ x, ¬p x :=\nassume H1 : ∃ x, ¬ p x,\n  obtain (w : A) (Hw : ¬ p w), from H1,\n  absurd (H2 w) Hw\n\ntheorem not_forall_of_exists_not {A : Type} {P : A → Prop} (H : ∃ a : A, ¬ P a) : ¬ ∀ a : A, P a :=\nassume H', not_exists_not_of_forall H' H\n\ntheorem forall_true_iff_true (A : Type) : (∀ x : A, true) ↔ true :=\niff_true_intro (λH, trivial)\n\ntheorem forall_p_iff_p (A : Type) [H : inhabited A] (p : Prop) : (∀ x : A, p) ↔ p :=\niff.intro (inhabited.destruct H) (λ Hr x, Hr)\n\ntheorem exists_p_iff_p (A : Type) [H : inhabited A] (p : Prop) : (∃ x : A, p) ↔ p :=\niff.intro (Exists.rec (λ x Hp, Hp)) (inhabited.destruct H exists.intro)\n\ntheorem forall_and_distribute {A : Type} (φ ψ : A → Prop) :\n  (∀ x, φ x ∧ ψ x) ↔ (∀ x, φ x) ∧ (∀ x, ψ x) :=\niff.intro\n  (assume H, and.intro (take x, and.left (H x)) (take x, and.right (H x)))\n  (assume H x, and.intro (and.left H x) (and.right H x))\n\ntheorem exists_or_distribute {A : Type} (φ ψ : A → Prop) :\n  (∃ x, φ x ∨ ψ x) ↔ (∃ x, φ x) ∨ (∃ x, ψ x) :=\niff.intro\n  (Exists.rec (λ x, or.imp !exists.intro !exists.intro))\n  (or.rec (exists_imp_exists (λ x, or.inl))\n          (exists_imp_exists (λ x, or.inr)))\n\nsection\n  open decidable eq.ops\n\n  variables {A : Type} (P : A → Prop) (a : A) [H : decidable (P a)]\n  include H\n\n  definition decidable_forall_eq [instance] : decidable (∀ x, x = a → P x) :=\n  if pa : P a then inl (λ x heq, eq.substr heq pa)\n  else inr (not.mto (λH, H a rfl) pa)\n\n  definition decidable_exists_eq [instance] : decidable (∃ x, x = a ∧ P x) :=\n  if pa : P a then inl (exists.intro a (and.intro rfl pa))\n  else inr (Exists.rec (λh, and.rec (λheq, eq.substr heq pa)))\nend\n\n/- definite description -/\n\nsection\n  open classical\n\n  noncomputable definition the {A : Type} {p : A → Prop} (H : ∃! x, p x) : A :=\n  some (exists_of_exists_unique H)\n\n  theorem the_spec {A : Type} {p : A → Prop} (H : ∃! x, p x) : p (the H) :=\n  some_spec (exists_of_exists_unique H)\n\n  theorem eq_the {A : Type} {p : A → Prop} (H : ∃! x, p x) {y : A} (Hy : p y) :\n    y = the H :=\n  unique_of_exists_unique H Hy (the_spec H)\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/logic/quantifiers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7569034340855444}}
{"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\nimport analysis.inner_product_space.pi_L2\nimport linear_algebra.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\nopen_locale big_operators\nopen finset submodule finite_dimensional\n\nvariables (𝕜 : Type*) {E : Type*} [is_R_or_C 𝕜] [normed_add_comm_group E] [inner_product_space 𝕜 E]\nvariables {ι : Type*} [linear_order ι] [locally_finite_order_bot ι] [is_well_order ι (<)]\n\nlocal attribute [instance] is_well_order.to_has_well_founded\n\nlocal notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ 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 gram_schmidt (f : ι → E) : ι → E\n| n := f n - ∑ i : Iio n, orthogonal_projection (𝕜 ∙ gram_schmidt i) (f n)\nusing_well_founded { dec_tac := `[exact mem_Iio.1 i.2] }\n\n/-- This lemma uses `∑ i in` instead of `∑ i :`.-/\nlemma gram_schmidt_def (f : ι → E) (n : ι):\n  gram_schmidt 𝕜 f n = f n - ∑ i in Iio n,\n    orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=\nby { rw [←sum_attach, attach_eq_univ, gram_schmidt], refl }\n\nlemma gram_schmidt_def' (f : ι → E) (n : ι):\n  f n = gram_schmidt 𝕜 f n + ∑ i in Iio n,\n    orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=\nby rw [gram_schmidt_def, sub_add_cancel]\n\nlemma gram_schmidt_def'' (f : ι → E) (n : ι):\n  f n = gram_schmidt 𝕜 f n\n  + ∑ i in Iio n, (⟪gram_schmidt 𝕜 f i, f n⟫ / ‖gram_schmidt 𝕜 f i‖ ^ 2) • gram_schmidt 𝕜 f i :=\nbegin\n  convert gram_schmidt_def' 𝕜 f n,\n  ext i,\n  rw orthogonal_projection_singleton,\nend\n\n@[simp] lemma gram_schmidt_zero {ι : Type*} [linear_order ι] [locally_finite_order ι]\n  [order_bot ι] [is_well_order ι (<)] (f : ι → E) : gram_schmidt 𝕜 f ⊥ = f ⊥ :=\nby rw [gram_schmidt_def, Iio_eq_Ico, finset.Ico_self, finset.sum_empty, sub_zero]\n\n/-- **Gram-Schmidt Orthogonalisation**:\n`gram_schmidt` produces an orthogonal system of vectors. -/\ntheorem gram_schmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) :\n  ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0 :=\nbegin\n  suffices : ∀ a b : ι, a < b → ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0,\n  { cases h₀.lt_or_lt with ha hb,\n    { exact this _ _ ha, },\n    { rw inner_eq_zero_symm,\n      exact this _ _ hb, }, },\n  clear h₀ a b,\n  intros a b h₀,\n  revert a,\n  apply well_founded.induction (@is_well_founded.wf ι (<) _) b,\n  intros b ih a h₀,\n  simp only [gram_schmidt_def 𝕜 f b, inner_sub_right, inner_sum,\n    orthogonal_projection_singleton, inner_smul_right],\n  rw finset.sum_eq_single_of_mem a (finset.mem_Iio.mpr h₀),\n  { by_cases h : gram_schmidt 𝕜 f a = 0,\n    { simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero], },\n    { rw [← inner_self_eq_norm_sq_to_K, div_mul_cancel, sub_self],\n      rwa [inner_self_ne_zero], }, },\n  simp_intros 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₁ hia₂,\n  { rw inner_eq_zero_symm,\n    exact ih a h₀ i hia₁ },\n  { exact ih i (mem_Iio.1 hi) a hia₂ }\nend\n\n/-- This is another version of `gram_schmidt_orthogonal` using `pairwise` instead. -/\ntheorem gram_schmidt_pairwise_orthogonal (f : ι → E) :\n  pairwise (λ a b, ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0) :=\nλ a b, gram_schmidt_orthogonal 𝕜 f\n\nlemma gram_schmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) :\n  ⟪gram_schmidt 𝕜 v j, v i⟫ = 0 :=\nbegin\n  rw gram_schmidt_def'' 𝕜 v,\n  simp only [inner_add_right, inner_sum, inner_smul_right],\n  set b : ι → E := gram_schmidt 𝕜 v,\n  convert zero_add (0:𝕜),\n  { exact gram_schmidt_orthogonal 𝕜 v hij.ne' },\n  apply finset.sum_eq_zero,\n  rintros k hki',\n  have hki : k < i := by simpa using hki',\n  have : ⟪b j, b k⟫ = 0 := gram_schmidt_orthogonal 𝕜 v (hki.trans hij).ne',\n  simp [this],\nend\n\nopen submodule set order\n\nlemma mem_span_gram_schmidt (f : ι → E) {i j : ι} (hij : i ≤ j) :\n  f i ∈ span 𝕜 (gram_schmidt 𝕜 f '' Iic j) :=\nbegin\n  rw [gram_schmidt_def' 𝕜 f i],\n  simp_rw orthogonal_projection_singleton,\n  exact submodule.add_mem _ (subset_span $ mem_image_of_mem _ hij)\n    (submodule.sum_mem _ $ λ k hk, smul_mem (span 𝕜 (gram_schmidt 𝕜 f '' Iic j)) _ $\n    subset_span $ mem_image_of_mem (gram_schmidt 𝕜 f) $ (finset.mem_Iio.1 hk).le.trans hij),\nend\n\nlemma gram_schmidt_mem_span (f : ι → E) :\n  ∀ {j i}, i ≤ j → gram_schmidt 𝕜 f i ∈ span 𝕜 (f '' Iic j)\n| j := λ i hij,\nbegin\n  rw [gram_schmidt_def 𝕜 f i],\n  simp_rw orthogonal_projection_singleton,\n  refine submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij))\n    (submodule.sum_mem _ $ λ k hk, _),\n  let hkj : k < j := (finset.mem_Iio.1 hk).trans_le hij,\n  exact smul_mem _ _ (span_mono (image_subset f $ Iic_subset_Iic.2 hkj.le) $\n    gram_schmidt_mem_span le_rfl),\nend\nusing_well_founded { dec_tac := `[assumption] }\n\nlemma span_gram_schmidt_Iic (f : ι → E) (c : ι) :\n  span 𝕜 (gram_schmidt 𝕜 f '' Iic c) = span 𝕜 (f '' Iic c) :=\nspan_eq_span (set.image_subset_iff.2 $ λ i, gram_schmidt_mem_span _ _) $\n  set.image_subset_iff.2 $ λ i, mem_span_gram_schmidt _ _\n\nlemma span_gram_schmidt_Iio (f : ι → E) (c : ι) :\n  span 𝕜 (gram_schmidt 𝕜 f '' Iio c) = span 𝕜 (f '' Iio c) :=\nspan_eq_span\n  (set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $\n    gram_schmidt_mem_span _ _ le_rfl) $\n  set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $\n    mem_span_gram_schmidt _ _ le_rfl\n\n/-- `gram_schmidt` preserves span of vectors. -/\nlemma span_gram_schmidt (f : ι → E) : span 𝕜 (range (gram_schmidt 𝕜 f)) = span 𝕜 (range f) :=\nspan_eq_span (range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $\n  gram_schmidt_mem_span _ _ le_rfl) $\n  range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $ mem_span_gram_schmidt _ _ le_rfl\n\nlemma gram_schmidt_of_orthogonal {f : ι → E} (hf : pairwise (λ i j, ⟪f i, f j⟫ = 0)) :\n  gram_schmidt 𝕜 f = f :=\nbegin\n  ext i,\n  rw gram_schmidt_def,\n  transitivity f i - 0,\n  { congr,\n    apply finset.sum_eq_zero,\n    intros j hj,\n    rw coe_eq_zero,\n    suffices : span 𝕜 (f '' set.Iic j) ≤ (𝕜 ∙ f i)ᗮ,\n    { apply orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,\n      rw mem_orthogonal_singleton_iff_inner_left,\n      rw ←mem_orthogonal_singleton_iff_inner_right,\n      exact this (gram_schmidt_mem_span 𝕜 f (le_refl j)) },\n    rw span_le,\n    rintros - ⟨k, hk, rfl⟩,\n    rw [set_like.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  { simp },\nend\n\nvariables {𝕜}\n\nlemma gram_schmidt_ne_zero_coe\n    {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :\n  gram_schmidt 𝕜 f n ≠ 0 :=\nbegin\n  by_contra h,\n  have h₁ : f n ∈ span 𝕜 (f '' Iio n),\n  { rw [← span_gram_schmidt_Iio 𝕜 f n, gram_schmidt_def' _ f, h, zero_add],\n    apply submodule.sum_mem _ _,\n    simp_intros a ha only [finset.mem_Ico],\n    simp only [set.mem_image, set.mem_Iio, orthogonal_projection_singleton],\n    apply submodule.smul_mem _ _ _,\n    rw finset.mem_Iio at ha,\n    refine subset_span ⟨a, ha, by refl⟩ },\n  have h₂ : (f ∘ (coe : set.Iic n → ι)) ⟨n, le_refl n⟩\n    ∈ span 𝕜 (f ∘ (coe : set.Iic n → ι) '' Iio ⟨n, le_refl n⟩),\n  { rw [image_comp],\n    convert h₁ using 3,\n    ext i,\n    simpa using @le_of_lt _ _ i n },\n  apply linear_independent.not_mem_span_image h₀ _ h₂,\n  simp only [set.mem_Iio, lt_self_iff_false, not_false_iff]\nend\n\n/-- If the input vectors of `gram_schmidt` are linearly independent,\nthen the output vectors are non-zero. -/\nlemma gram_schmidt_ne_zero {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 f) :\n  gram_schmidt 𝕜 f n ≠ 0 :=\ngram_schmidt_ne_zero_coe _ (linear_independent.comp h₀ _ subtype.coe_injective)\n\n/-- `gram_schmidt` produces a triangular matrix of vectors when given a basis. -/\nlemma gram_schmidt_triangular {i j : ι} (hij : i < j) (b : basis ι 𝕜 E) :\n  b.repr (gram_schmidt 𝕜 b i) j = 0 :=\nbegin\n  have : gram_schmidt 𝕜 b i ∈ span 𝕜 (gram_schmidt 𝕜 b '' set.Iio j),\n    from subset_span ((set.mem_image _ _ _).2 ⟨i, hij, rfl⟩),\n  have : gram_schmidt 𝕜 b i ∈ span 𝕜 (b '' set.Iio j),\n    by rwa [← span_gram_schmidt_Iio 𝕜 b j],\n  have : ↑(((b.repr) (gram_schmidt 𝕜 b i)).support) ⊆ set.Iio j,\n    from basis.repr_support_subset_of_mem_span b (set.Iio j) this,\n  exact (finsupp.mem_supported' _ _).1\n    ((finsupp.mem_supported 𝕜 _).2 this) j set.not_mem_Iio_self,\nend\n\n/-- `gram_schmidt` produces linearly independent vectors when given linearly independent vectors. -/\nlemma gram_schmidt_linear_independent {f : ι → E} (h₀ : linear_independent 𝕜 f) :\n  linear_independent 𝕜 (gram_schmidt 𝕜 f) :=\nlinear_independent_of_ne_zero_of_inner_eq_zero\n    (λ i, gram_schmidt_ne_zero _ h₀) (λ i j, gram_schmidt_orthogonal 𝕜 f)\n\n/-- When given a basis, `gram_schmidt` produces a basis. -/\nnoncomputable def gram_schmidt_basis (b : basis ι 𝕜 E) : basis ι 𝕜 E :=\nbasis.mk\n  (gram_schmidt_linear_independent b.linear_independent)\n  ((span_gram_schmidt 𝕜 b).trans b.span_eq).ge\n\nlemma coe_gram_schmidt_basis (b : basis ι 𝕜 E) :\n  (gram_schmidt_basis b : ι → E) = gram_schmidt 𝕜 b := basis.coe_mk _ _\n\nvariables (𝕜)\n\n/-- the normalized `gram_schmidt`\n(i.e each vector in `gram_schmidt_normed` has unit length.) -/\nnoncomputable def gram_schmidt_normed (f : ι → E) (n : ι) : E :=\n(‖gram_schmidt 𝕜 f n‖ : 𝕜)⁻¹ • (gram_schmidt 𝕜 f n)\n\nvariables {𝕜}\n\nlemma gram_schmidt_normed_unit_length_coe\n    {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :\n  ‖gram_schmidt_normed 𝕜 f n‖ = 1 :=\nby simp only [gram_schmidt_ne_zero_coe n h₀,\n  gram_schmidt_normed, norm_smul_inv_norm, ne.def, not_false_iff]\n\nlemma gram_schmidt_normed_unit_length {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 f) :\n  ‖gram_schmidt_normed 𝕜 f n‖ = 1 :=\ngram_schmidt_normed_unit_length_coe _ (linear_independent.comp h₀ _ subtype.coe_injective)\n\nlemma gram_schmidt_normed_unit_length' {f : ι → E} {n : ι} (hn : gram_schmidt_normed 𝕜 f n ≠ 0) :\n  ‖gram_schmidt_normed 𝕜 f n‖ = 1 :=\nbegin\n  rw gram_schmidt_normed at *,\n  rw [norm_smul_inv_norm],\n  simpa using hn,\nend\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 : ι → E} (h₀ : linear_independent 𝕜 f) :\n  orthonormal 𝕜 (gram_schmidt_normed 𝕜 f) :=\nbegin\n  unfold orthonormal,\n  split,\n  { simp only [gram_schmidt_normed_unit_length, h₀, eq_self_iff_true, implies_true_iff], },\n  { intros i j hij,\n    simp only [gram_schmidt_normed, inner_smul_left, inner_smul_right, is_R_or_C.conj_inv,\n      is_R_or_C.conj_of_real, mul_eq_zero, inv_eq_zero, is_R_or_C.of_real_eq_zero, norm_eq_zero],\n    repeat { right },\n    exact gram_schmidt_orthogonal 𝕜 f hij }\nend\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. -/\nlemma gram_schmidt_orthonormal' (f : ι → E) :\n  orthonormal 𝕜 (λ i : {i | gram_schmidt_normed 𝕜 f i ≠ 0}, gram_schmidt_normed 𝕜 f i) :=\nbegin\n  refine ⟨λ i, gram_schmidt_normed_unit_length' i.prop, _⟩,\n  rintros i j (hij : ¬ _),\n  rw subtype.ext_iff at hij,\n  simp [gram_schmidt_normed, inner_smul_left, inner_smul_right, gram_schmidt_orthogonal 𝕜 f hij],\nend\n\nlemma span_gram_schmidt_normed (f : ι → E) (s : set ι) :\n  span 𝕜 (gram_schmidt_normed 𝕜 f '' s) = span 𝕜 (gram_schmidt 𝕜 f '' s) :=\nbegin\n  refine span_eq_span (set.image_subset_iff.2 $ λ i hi, smul_mem _ _ $ subset_span $\n    mem_image_of_mem _ hi)\n    (set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ singleton_subset_set_iff.2 hi) _),\n  simp only [coe_singleton, set.image_singleton],\n  by_cases h : gram_schmidt 𝕜 f i = 0,\n  { simp [h] },\n  { refine mem_span_singleton.2 ⟨‖gram_schmidt 𝕜 f i‖, smul_inv_smul₀ _ _⟩,\n    exact_mod_cast (norm_ne_zero_iff.2 h) }\nend\n\nlemma span_gram_schmidt_normed_range (f : ι → E) :\n  span 𝕜 (range (gram_schmidt_normed 𝕜 f)) = span 𝕜 (range (gram_schmidt 𝕜 f)) :=\nby simpa only [image_univ.symm] using span_gram_schmidt_normed f univ\n\nsection orthonormal_basis\nvariables [fintype ι] [finite_dimensional 𝕜 E] (h : finrank 𝕜 E = fintype.card ι) (f : ι → E)\ninclude h\n\n/-- Given an indexed family `f : ι → 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`ι` for which this process gives a nonzero number. -/\nnoncomputable def gram_schmidt_orthonormal_basis : orthonormal_basis ι 𝕜 E :=\n((gram_schmidt_orthonormal' f).exists_orthonormal_basis_extension_of_card_eq h).some\n\nlemma gram_schmidt_orthonormal_basis_apply {f : ι → E} {i : ι}\n  (hi : gram_schmidt_normed 𝕜 f i ≠ 0) :\n  gram_schmidt_orthonormal_basis h f i = gram_schmidt_normed 𝕜 f i :=\n((gram_schmidt_orthonormal' f).exists_orthonormal_basis_extension_of_card_eq h).some_spec i hi\n\nlemma gram_schmidt_orthonormal_basis_apply_of_orthogonal {f : ι → E}\n  (hf : pairwise (λ i j, ⟪f i, f j⟫ = 0)) {i : ι} (hi : f i ≠ 0) :\n  gram_schmidt_orthonormal_basis h f i = (‖f i‖⁻¹ : 𝕜) • f i :=\nbegin\n  have H : gram_schmidt_normed 𝕜 f i = (‖f i‖⁻¹ : 𝕜) • f i,\n  { rw [gram_schmidt_normed, gram_schmidt_of_orthogonal 𝕜 hf] },\n  rw [gram_schmidt_orthonormal_basis_apply h, H],\n  simpa [H] using hi,\nend\n\nlemma inner_gram_schmidt_orthonormal_basis_eq_zero {f : ι → E} {i : ι}\n  (hi : gram_schmidt_normed 𝕜 f i = 0) (j : ι) :\n  ⟪gram_schmidt_orthonormal_basis h f i, f j⟫ = 0 :=\nbegin\n  rw ←mem_orthogonal_singleton_iff_inner_right,\n  suffices : span 𝕜 (gram_schmidt_normed 𝕜 f '' Iic j)\n    ≤ (𝕜 ∙ gram_schmidt_orthonormal_basis h f i)ᗮ,\n  { apply this,\n    rw span_gram_schmidt_normed,\n    simpa using mem_span_gram_schmidt 𝕜 f (le_refl j) },\n  rw span_le,\n  rintros - ⟨k, -, rfl⟩,\n  rw [set_like.mem_coe, mem_orthogonal_singleton_iff_inner_left],\n  by_cases hk : gram_schmidt_normed 𝕜 f k = 0,\n  { simp [hk] },\n  rw ← gram_schmidt_orthonormal_basis_apply h hk,\n  have : k ≠ i,\n  { rintros rfl,\n    exact hk hi },\n  exact (gram_schmidt_orthonormal_basis h f).orthonormal.2 this,\nend\n\nlemma gram_schmidt_orthonormal_basis_inv_triangular {i j : ι} (hij : i < j) :\n  ⟪gram_schmidt_orthonormal_basis h f j, f i⟫ = 0 :=\nbegin\n  by_cases hi : gram_schmidt_normed 𝕜 f j = 0,\n  { rw inner_gram_schmidt_orthonormal_basis_eq_zero h hi },\n  { simp [gram_schmidt_orthonormal_basis_apply h hi, gram_schmidt_normed, inner_smul_left,\n      gram_schmidt_inv_triangular 𝕜 f hij] }\nend\n\nlemma gram_schmidt_orthonormal_basis_inv_triangular' {i j : ι} (hij : i < j) :\n  (gram_schmidt_orthonormal_basis h f).repr (f i) j = 0 :=\nby simpa [orthonormal_basis.repr_apply_apply]\n  using gram_schmidt_orthonormal_basis_inv_triangular h f hij\n\n/-- Given an indexed family `f : ι → 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. -/\nlemma gram_schmidt_orthonormal_basis_inv_block_triangular :\n  ((gram_schmidt_orthonormal_basis h f).to_basis.to_matrix f).block_triangular id :=\nλ i j, gram_schmidt_orthonormal_basis_inv_triangular' h f\n\nlemma gram_schmidt_orthonormal_basis_det :\n  (gram_schmidt_orthonormal_basis h f).to_basis.det f =\n    ∏ i, ⟪gram_schmidt_orthonormal_basis h f i, f i⟫ :=\nbegin\n  convert matrix.det_of_upper_triangular (gram_schmidt_orthonormal_basis_inv_block_triangular h f),\n  ext i,\n  exact ((gram_schmidt_orthonormal_basis h f).repr_apply_apply (f i) i).symm,\nend\n\nend orthonormal_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/analysis/inner_product_space/gram_schmidt_ortho.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605412, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.756903433903311}}
{"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-/\nimport analysis.inner_product_space.projection\nimport analysis.normed_space.lp_space\n\n/-!\n# Hilbert sum of a family of inner product spaces\n\nGiven a family `(G : ι → Type*) [Π i, inner_product_space 𝕜 (G i)]` of inner product spaces, this\nfile equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those\ndependent functions `f : Π i, G i` for which `∑' i, ∥f i∥ ^ 2`, the sum of the norms-squared, is\nsummable.  This construction is sometimes called the *Hilbert sum* of the family `G`.  By choosing\n`G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction.\n\n## Main definitions\n\n* `orthogonal_family.linear_isometry`: Given a Hilbert space `E`, a family `G` of inner product\n  spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with\n  mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G`\n  into `E`.\n\n* `orthogonal_family.linear_isometry_equiv`: Given a Hilbert space `E`, a family `G` of inner\n  product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`\n  with mutually-orthogonal images whose span is dense in `E`, there is an induced isometric\n  isomorphism of the Hilbert sum of `G` with `E`.\n\n* `hilbert_basis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single\n  field `hilbert_basis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert\n  sum of `ι` copies of `𝕜`).  This parallels the definition of `basis`, in `linear_algebra.basis`,\n  as an isomorphism of an `R`-module with `ι →₀ R`.\n\n* `hilbert_basis.has_coe_to_fun`: More conventionally a Hilbert basis is thought of as a family\n  `ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness).  We obtain\n  this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image\n  under `b.repr` of `lp.single 2 i (1:𝕜)`.  This parallels the definition `basis.has_coe_to_fun` in\n  `linear_algebra.basis`.\n\n* `hilbert_basis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors\n  in `E` whose span is dense.  This parallels the definition `basis.mk` in `linear_algebra.basis`.\n\n* `hilbert_basis.mk_of_orthogonal_eq_bot`: Make a Hilbert basis of `E` from an orthonormal family\n  `v : ι → E` of vectors in `E` whose span has trivial orthogonal complement.\n\n## Main results\n\n* `lp.inner_product_space`: Construction of the inner product space instance on the Hilbert sum\n  `lp G 2`.  Note that from the file `analysis.normed_space.lp_space`, the space `lp G 2` already\n  held a normed space instance (`lp.normed_space`), and if each `G i` is a Hilbert space (i.e.,\n  complete), then `lp G 2` was already known to be complete (`lp.complete_space`).  So the work\n  here is to define the inner product and show it is compatible.\n\n* `orthogonal_family.range_linear_isometry`: Given a family `G` of inner product spaces and a family\n  `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal\n  images, the image of the embedding `orthogonal_family.linear_isometry` of the Hilbert sum of `G`\n  into `E` is the closure of the span of the images of the `G i`.\n\n* `hilbert_basis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of\n  `x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`.\n\n* `hilbert_basis.has_sum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be\n  expressed as the \"infinite linear combination\" `∑' i, b.repr x i • b i` of the basis vectors\n  `b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`.\n\n* `exists_hilbert_basis`: A Hilbert space admits a Hilbert basis.\n\n## Keywords\n\nHilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism\n-/\n\nopen is_R_or_C submodule filter\nopen_locale big_operators nnreal ennreal classical complex_conjugate\n\nnoncomputable theory\n\nvariables {ι : Type*}\nvariables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*} [inner_product_space 𝕜 E] [cplt : complete_space E]\nvariables {G : ι → Type*} [Π i, inner_product_space 𝕜 (G i)]\nlocal notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y\n\nnotation `ℓ²(` ι `,` 𝕜 `)` := lp (λ i : ι, 𝕜) 2\n\n/-! ### Inner product space structure on `lp G 2` -/\n\nnamespace lp\n\nlemma summable_inner (f g : lp G 2) : summable (λ i, ⟪f i, g i⟫) :=\nbegin\n  -- Apply the Direct Comparison Test, comparing with ∑' i, ∥f i∥ * ∥g i∥ (summable by Hölder)\n  refine summable_of_norm_bounded (λ i, ∥f i∥ * ∥g i∥) (lp.summable_mul _ f g) _,\n  { rw real.is_conjugate_exponent_iff; norm_num },\n  intros i,\n  -- Then apply Cauchy-Schwarz pointwise\n  exact norm_inner_le_norm _ _,\nend\n\ninstance : inner_product_space 𝕜 (lp G 2) :=\n{ inner := λ f g, ∑' i, ⟪f i, g i⟫,\n  norm_sq_eq_inner := λ f, begin\n    calc ∥f∥ ^ 2 = ∥f∥ ^ (2:ℝ≥0∞).to_real : by norm_cast\n    ... = ∑' i, ∥f i∥ ^ (2:ℝ≥0∞).to_real : lp.norm_rpow_eq_tsum _ f\n    ... = ∑' i, ∥f i∥ ^ 2 : by norm_cast\n    ... = ∑' i, re ⟪f i, f i⟫ : by simp only [norm_sq_eq_inner]\n    ... = re (∑' i, ⟪f i, f i⟫) : (is_R_or_C.re_clm.map_tsum _).symm\n    ... = _ : by congr,\n    { norm_num },\n    { exact summable_inner f f },\n  end,\n  conj_sym := λ f g, begin\n    calc conj _ = conj ∑' i, ⟪g i, f i⟫ : by congr\n    ... = ∑' i, conj ⟪g i, f i⟫ : is_R_or_C.conj_cle.map_tsum\n    ... = ∑' i, ⟪f i, g i⟫ : by simp only [inner_conj_sym]\n    ... = _ : by congr,\n  end,\n  add_left := λ f₁ f₂ g, begin\n    calc _ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ : _\n    ... = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) :\n          by simp only [inner_add_left, pi.add_apply, coe_fn_add]\n    ... = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ : tsum_add _ _\n    ... = _ : by congr,\n    { congr, },\n    { exact summable_inner f₁ g },\n    { exact summable_inner f₂ g }\n  end,\n  smul_left := λ f g c, begin\n    calc _ = ∑' i, ⟪c • f i, g i⟫ : _\n    ... = ∑' i, conj c * ⟪f i, g i⟫ : by simp only [inner_smul_left]\n    ... = conj c * ∑' i, ⟪f i, g i⟫ : tsum_mul_left\n    ... = _ : _,\n    { simp only [coe_fn_smul, pi.smul_apply] },\n    { congr },\n  end,\n  .. lp.normed_space }\n\nlemma inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ := rfl\n\nlemma has_sum_inner (f g : lp G 2) : has_sum (λ i, ⟪f i, g i⟫) ⟪f, g⟫ :=\n(summable_inner f g).has_sum\n\nlemma inner_single_left (i : ι) (a : G i) (f : lp G 2) : ⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ :=\nbegin\n  refine (has_sum_inner (lp.single 2 i a) f).unique _,\n  convert has_sum_ite_eq i ⟪a, f i⟫,\n  ext j,\n  rw lp.single_apply,\n  split_ifs,\n  { subst h },\n  { simp }\nend\n\nlemma inner_single_right (i : ι) (a : G i) (f : lp G 2) : ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ :=\nby simpa [inner_conj_sym] using congr_arg conj (inner_single_left i a f)\n\nend lp\n\n/-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/\n\nnamespace orthogonal_family\nvariables {V : Π i, G i →ₗᵢ[𝕜] E} (hV : orthogonal_family 𝕜 V)\n\ninclude cplt hV\n\nprotected lemma summable_of_lp (f : lp G 2) : summable (λ i, V i (f i)) :=\nbegin\n  rw hV.summable_iff_norm_sq_summable,\n  convert (lp.mem_ℓp f).summable _,\n  { norm_cast },\n  { norm_num }\nend\n\n/-- A mutually orthogonal family of subspaces of `E` induce a linear isometry from `lp 2` of the\nsubspaces into `E`. -/\nprotected def linear_isometry : lp G 2 →ₗᵢ[𝕜] E :=\n{ to_fun := λ f, ∑' i, V i (f i),\n  map_add' := λ f g, by simp only [tsum_add (hV.summable_of_lp f) (hV.summable_of_lp g),\n    lp.coe_fn_add, pi.add_apply, linear_isometry.map_add],\n  map_smul' := λ c f, by simpa only [linear_isometry.map_smul, pi.smul_apply, lp.coe_fn_smul]\n    using tsum_const_smul (hV.summable_of_lp f),\n  norm_map' := λ f, begin\n    classical, -- needed for lattice instance on `finset ι`, for `filter.at_top_ne_bot`\n    have H : 0 < (2:ℝ≥0∞).to_real := by norm_num,\n    suffices : ∥∑' (i : ι), V i (f i)∥ ^ ((2:ℝ≥0∞).to_real) = ∥f∥ ^ ((2:ℝ≥0∞).to_real),\n    { exact real.rpow_left_inj_on H.ne' (norm_nonneg _) (norm_nonneg _) this },\n    refine tendsto_nhds_unique  _ (lp.has_sum_norm H f),\n    convert (hV.summable_of_lp f).has_sum.norm.rpow_const (or.inr H.le),\n    ext s,\n    exact_mod_cast (hV.norm_sum f s).symm,\n  end }\n\nprotected lemma linear_isometry_apply (f : lp G 2) :\n  hV.linear_isometry f = ∑' i, V i (f i) :=\nrfl\n\nprotected lemma has_sum_linear_isometry (f : lp G 2) :\n  has_sum (λ i, V i (f i)) (hV.linear_isometry f) :=\n(hV.summable_of_lp f).has_sum\n\n@[simp] protected lemma linear_isometry_apply_single {i : ι} (x : G i) :\n  hV.linear_isometry (lp.single 2 i x) = V i x :=\nbegin\n  rw [hV.linear_isometry_apply, ← tsum_ite_eq i (V i x)],\n  congr,\n  ext j,\n  rw [lp.single_apply],\n  split_ifs,\n  { subst h },\n  { simp }\nend\n\n@[simp] protected \n\n/-- The canonical linear isometry from the `lp 2` of a mutually orthogonal family of subspaces of\n`E` into E, has range the closure of the span of the subspaces. -/\nprotected lemma range_linear_isometry [Π i, complete_space (G i)] :\n  hV.linear_isometry.to_linear_map.range = (⨆ i, (V i).to_linear_map.range).topological_closure :=\nbegin\n  classical,\n  refine le_antisymm _ _,\n  { rintros x ⟨f, rfl⟩,\n    refine mem_closure_of_tendsto (hV.has_sum_linear_isometry f) (eventually_of_forall _),\n    intros s,\n    refine sum_mem (supr (λ i, (V i).to_linear_map.range)) _,\n    intros i hi,\n    refine mem_supr_of_mem i _,\n    exact linear_map.mem_range_self _ (f i) },\n  { apply topological_closure_minimal,\n    { refine supr_le _,\n      rintros i x ⟨x, rfl⟩,\n      use lp.single 2 i x,\n      convert hV.linear_isometry_apply_single _ },\n    exact hV.linear_isometry.isometry.uniform_inducing.is_complete_range.is_closed }\nend\n\n/-- A mutually orthogonal family of complete subspaces of `E`, whose range is dense in `E`, induces\na isometric isomorphism from E to `lp 2` of the subspaces.\n\nNote that this goes in the opposite direction from `orthogonal_family.linear_isometry`. -/\nnoncomputable def linear_isometry_equiv [Π i, complete_space (G i)]\n  (hV' : (⨆ i, (V i).to_linear_map.range).topological_closure = ⊤) :\n  E ≃ₗᵢ[𝕜] lp G 2 :=\nlinear_isometry_equiv.symm $\nlinear_isometry_equiv.of_surjective\nhV.linear_isometry\nbegin\n  refine linear_map.range_eq_top.mp _,\n  rw ← hV',\n  rw hV.range_linear_isometry,\nend\n\n/-- In the canonical isometric isomorphism `E ≃ₗᵢ[𝕜] lp G 2` induced by an orthogonal family `G`,\na vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`. -/\nprotected lemma linear_isometry_equiv_symm_apply [Π i, complete_space (G i)]\n  (hV' : (⨆ i, (V i).to_linear_map.range).topological_closure = ⊤) (w : lp G 2) :\n  (hV.linear_isometry_equiv hV').symm w = ∑' i, V i (w i) :=\nby simp [orthogonal_family.linear_isometry_equiv, orthogonal_family.linear_isometry_apply]\n\n/-- In the canonical isometric isomorphism `E ≃ₗᵢ[𝕜] lp G 2` induced by an orthogonal family `G`,\na vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`, and this\nsum indeed converges. -/\nprotected lemma has_sum_linear_isometry_equiv_symm [Π i, complete_space (G i)]\n  (hV' : (⨆ i, (V i).to_linear_map.range).topological_closure = ⊤) (w : lp G 2) :\n  has_sum (λ i, V i (w i)) ((hV.linear_isometry_equiv hV').symm w) :=\nby simp [orthogonal_family.linear_isometry_equiv, orthogonal_family.has_sum_linear_isometry]\n\n/-- In the canonical isometric isomorphism `E ≃ₗᵢ[𝕜] lp G 2` induced by an `ι`-indexed orthogonal\nfamily `G`, an \"elementary basis vector\" in `lp G 2` supported at `i : ι` is the image of the\nassociated element in `E`. -/\n@[simp] protected lemma linear_isometry_equiv_symm_apply_single [Π i, complete_space (G i)]\n  (hV' : (⨆ i, (V i).to_linear_map.range).topological_closure = ⊤) {i : ι} (x : G i) :\n  (hV.linear_isometry_equiv hV').symm (lp.single 2 i x) = V i x :=\nby simp [orthogonal_family.linear_isometry_equiv, orthogonal_family.linear_isometry_apply_single]\n\n/-- In the canonical isometric isomorphism `E ≃ₗᵢ[𝕜] lp G 2` induced by an `ι`-indexed orthogonal\nfamily `G`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of\nelements of `E`. -/\n@[simp] protected lemma linear_isometry_equiv_symm_apply_dfinsupp_sum_single\n  [Π i, complete_space (G i)]\n  (hV' : (⨆ i, (V i).to_linear_map.range).topological_closure = ⊤) (W₀ : Π₀ (i : ι), G i) :\n  (hV.linear_isometry_equiv hV').symm (W₀.sum (lp.single 2)) = (W₀.sum (λ i, V i)) :=\nby simp [orthogonal_family.linear_isometry_equiv,\n  orthogonal_family.linear_isometry_apply_dfinsupp_sum_single]\n\n/-- In the canonical isometric isomorphism `E ≃ₗᵢ[𝕜] lp G 2` induced by an `ι`-indexed orthogonal\nfamily `G`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of\nelements of `E`. -/\n@[simp] protected lemma linear_isometry_equiv_apply_dfinsupp_sum_single\n  [Π i, complete_space (G i)]\n  (hV' : (⨆ i, (V i).to_linear_map.range).topological_closure = ⊤) (W₀ : Π₀ (i : ι), G i) :\n  (hV.linear_isometry_equiv hV' (W₀.sum (λ i, V i)) : Π i, G i) = W₀ :=\nbegin\n  rw ← hV.linear_isometry_equiv_symm_apply_dfinsupp_sum_single hV',\n  rw linear_isometry_equiv.apply_symm_apply,\n  ext i,\n  simp [dfinsupp.sum, lp.single_apply] {contextual := tt},\nend\n\nend orthogonal_family\n\n/-! ### Hilbert bases -/\n\nsection\nvariables (ι) (𝕜) (E)\n\n/-- A Hilbert basis on `ι` for an inner product space `E` is an identification of `E` with the `lp`\nspace `ℓ²(ι, 𝕜)`. -/\nstructure hilbert_basis := of_repr :: (repr : E ≃ₗᵢ[𝕜] ℓ²(ι, 𝕜))\n\nend\n\nnamespace hilbert_basis\n\ninstance {ι : Type*} : inhabited (hilbert_basis ι 𝕜 ℓ²(ι, 𝕜)) :=\n⟨of_repr (linear_isometry_equiv.refl 𝕜 _)⟩\n\n/-- `b i` is the `i`th basis vector. -/\ninstance : has_coe_to_fun (hilbert_basis ι 𝕜 E) (λ _, ι → E) :=\n{ coe := λ b i, b.repr.symm (lp.single 2 i (1:𝕜)) }\n\n@[simp] protected lemma repr_symm_single (b : hilbert_basis ι 𝕜 E) (i : ι) :\n  b.repr.symm (lp.single 2 i (1:𝕜)) = b i :=\nrfl\n\n@[simp] protected lemma repr_self (b : hilbert_basis ι 𝕜 E) (i : ι) :\n  b.repr (b i) = lp.single 2 i (1:𝕜) :=\nby rw [← b.repr_symm_single, linear_isometry_equiv.apply_symm_apply]\n\nprotected lemma repr_apply_apply (b : hilbert_basis ι 𝕜 E) (v : E) (i : ι) :\n  b.repr v i = ⟪b i, v⟫ :=\nbegin\n  rw [← b.repr.inner_map_map (b i) v, b.repr_self, lp.inner_single_left],\n  simp,\nend\n\n@[simp] protected lemma orthonormal (b : hilbert_basis ι 𝕜 E) : orthonormal 𝕜 b :=\nbegin\n  rw orthonormal_iff_ite,\n  intros i j,\n  rw [← b.repr.inner_map_map (b i) (b j), b.repr_self, b.repr_self, lp.inner_single_left,\n    lp.single_apply],\n  simp,\nend\n\nprotected lemma has_sum_repr_symm (b : hilbert_basis ι 𝕜 E) (f : ℓ²(ι, 𝕜)) :\n  has_sum (λ i, f i • b i) (b.repr.symm f) :=\nbegin\n  suffices H : (λ (i : ι), f i • b i) =\n    (λ (b_1 : ι), (b.repr.symm.to_continuous_linear_equiv) ((λ (i : ι), lp.single 2 i (f i)) b_1)),\n  { rw H,\n    have : has_sum (λ (i : ι), lp.single 2 i (f i)) f := lp.has_sum_single ennreal.two_ne_top f,\n    exact (↑(b.repr.symm.to_continuous_linear_equiv) : ℓ²(ι, 𝕜) →L[𝕜] E).has_sum this },\n  ext i,\n  apply b.repr.injective,\n  have : lp.single 2 i (f i * 1) = f i • lp.single 2 i 1 := lp.single_smul 2 i (1:𝕜) (f i),\n  rw mul_one at this,\n  rw [linear_isometry_equiv.map_smul, b.repr_self, ← this,\n    linear_isometry_equiv.coe_to_continuous_linear_equiv],\n  exact (b.repr.apply_symm_apply (lp.single 2 i (f i))).symm,\nend\n\nprotected lemma has_sum_repr (b : hilbert_basis ι 𝕜 E) (x : E) :\n  has_sum (λ i, b.repr x i • b i) x :=\nby simpa using b.has_sum_repr_symm (b.repr x)\n\n@[simp] protected lemma dense_span (b : hilbert_basis ι 𝕜 E) :\n  (span 𝕜 (set.range b)).topological_closure = ⊤ :=\nbegin\n  classical,\n  rw eq_top_iff,\n  rintros x -,\n  refine mem_closure_of_tendsto (b.has_sum_repr x) (eventually_of_forall _),\n  intros s,\n  simp only [set_like.mem_coe],\n  refine sum_mem _ _,\n  rintros i -,\n  refine smul_mem _ _ _,\n  exact subset_span ⟨i, rfl⟩\nend\n\nvariables {v : ι → E} (hv : orthonormal 𝕜 v)\ninclude hv cplt\n\n/-- An orthonormal family of vectors whose span is dense in the whole module is a Hilbert basis. -/\nprotected def mk (hsp : (span 𝕜 (set.range v)).topological_closure = ⊤) :\n  hilbert_basis ι 𝕜 E :=\nhilbert_basis.of_repr $\nhv.orthogonal_family.linear_isometry_equiv\nbegin\n  convert hsp,\n  simp [← linear_map.span_singleton_eq_range, ← submodule.span_Union],\nend\n\n@[simp] protected lemma coe_mk (hsp : (span 𝕜 (set.range v)).topological_closure = ⊤) :\n  ⇑(hilbert_basis.mk hv hsp) = v :=\nbegin\n  ext i,\n  show (hilbert_basis.mk hv hsp).repr.symm _ = v i,\n  simp [hilbert_basis.mk]\nend\n\n/-- An orthonormal family of vectors whose span has trivial orthogonal complement is a Hilbert\nbasis. -/\nprotected def mk_of_orthogonal_eq_bot (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) : hilbert_basis ι 𝕜 E :=\nhilbert_basis.mk hv\n(by rw [← orthogonal_orthogonal_eq_closure, orthogonal_eq_top_iff, hsp])\n\n@[simp] protected lemma coe_of_orthogonal_eq_bot_mk (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) :\n  ⇑(hilbert_basis.mk_of_orthogonal_eq_bot hv hsp) = v :=\nhilbert_basis.coe_mk hv _\n\nomit hv\n\n/-- A Hilbert space admits a Hilbert basis extending a given orthonormal subset. -/\nlemma _root_.orthonormal.exists_hilbert_basis_extension\n  {s : set E} (hs : orthonormal 𝕜 (coe : s → E)) :\n  ∃ (w : set E) (b : hilbert_basis w 𝕜 E), s ⊆ w ∧ ⇑b = (coe : w → E) :=\nlet ⟨w, hws, hw_ortho, hw_max⟩ := exists_maximal_orthonormal hs in\n⟨ w,\n  hilbert_basis.mk_of_orthogonal_eq_bot hw_ortho\n    (by simpa [maximal_orthonormal_iff_orthogonal_complement_eq_bot hw_ortho] using hw_max),\n  hws,\n  hilbert_basis.coe_of_orthogonal_eq_bot_mk _ _ ⟩\n\nvariables (𝕜 E)\n\n/-- A Hilbert space admits a Hilbert basis. -/\nlemma _root_.exists_hilbert_basis :\n  ∃ (w : set E) (b : hilbert_basis w 𝕜 E), ⇑b = (coe : w → E) :=\nlet ⟨w, hw, hw', hw''⟩ := (orthonormal_empty 𝕜 E).exists_hilbert_basis_extension in ⟨w, hw, hw''⟩\n\nend hilbert_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/analysis/inner_product_space/l2_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937712, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7568690206349844}}
{"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 data.nat.squarefree\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.Algebra.Squarefree\nimport Mathbin.Data.Nat.Factorization.PrimePow\nimport Mathbin.Data.Nat.PrimeNormNum\nimport Mathbin.RingTheory.Int.Basic\n\n/-!\n# Lemmas about squarefreeness of natural numbers\nA number is squarefree when it is not divisible by any squares except the squares of units.\n\n## Main Results\n - `nat.squarefree_iff_nodup_factors`: A positive natural number `x` is squarefree iff\n  the list `factors x` has no duplicate factors.\n\n## Tags\nsquarefree, multiplicity\n\n-/\n\n\nnamespace Nat\n\ntheorem squarefree_iff_nodup_factors {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔ n.factors.Nodup :=\n  by\n  rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0, Nat.factors_eq]\n  simp\n#align nat.squarefree_iff_nodup_factors Nat.squarefree_iff_nodup_factors\n\ntheorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n :=\n  squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩\n#align nat.squarefree_iff_prime_squarefree Nat.squarefree_iff_prime_squarefree\n\ntheorem Squarefree.factorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :\n    n.factorization p ≤ 1 := by\n  rcases eq_or_ne n 0 with (rfl | hn')\n  · simp\n  rw [multiplicity.squarefree_iff_multiplicity_le_one] at hn\n  by_cases hp : p.prime\n  · have := hn p\n    simp only [multiplicity_eq_factorization hp hn', Nat.isUnit_iff, hp.ne_one, or_false_iff] at\n      this\n    exact_mod_cast this\n  · rw [factorization_eq_zero_of_non_prime _ hp]\n    exact zero_le_one\n#align nat.squarefree.factorization_le_one Nat.Squarefree.factorization_le_one\n\ntheorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) :\n    Squarefree n :=\n  by\n  rw [squarefree_iff_nodup_factors hn, List.nodup_iff_count_le_one]\n  intro a\n  rw [factors_count_eq]\n  apply hn'\n#align nat.squarefree_of_factorization_le_one Nat.squarefree_of_factorization_le_one\n\ntheorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :\n    Squarefree n ↔ ∀ p, n.factorization p ≤ 1 :=\n  ⟨fun p hn => Squarefree.factorization_le_one hn p, squarefree_of_factorization_le_one hn⟩\n#align nat.squarefree_iff_factorization_le_one Nat.squarefree_iff_factorization_le_one\n\ntheorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :\n    n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) :=\n  by\n  refine'\n    ⟨by\n      rintro rfl\n      simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => _⟩\n  by_cases hp : p.prime\n  · have h₁ := h _ hp\n    rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,\n      hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁\n    have h₂ := squarefree.factorization_le_one p hn\n    have h₃ := squarefree.factorization_le_one p hm\n    rw [Nat.le_add_one_iff, le_zero_iff] at h₂ h₃\n    cases h₂\n    · rwa [h₂, eq_comm, ← h₁]\n    · rw [h₂, h₃.resolve_left]\n      rw [← h₁, h₂]\n      simp only [Nat.one_ne_zero, not_false_iff]\n  rw [factorization_eq_zero_of_non_prime _ hp, factorization_eq_zero_of_non_prime _ hp]\n#align nat.squarefree.ext_iff Nat.Squarefree.ext_iff\n\ntheorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :\n    Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 :=\n  by\n  refine'\n    ⟨fun h => _, by\n      rintro ⟨hn, rfl⟩\n      simpa⟩\n  rcases eq_or_ne n 0 with (rfl | hn₀)\n  · simpa [zero_pow hk.bot_lt] using h\n  refine' ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => _⟩\n  have : 2 ≤ k := k.two_le_iff.mpr ⟨hk, h₁⟩\n  apply hn (Nat.isUnit_iff.1 (h _ _))\n  rw [← sq]\n  exact pow_dvd_pow _ this\n#align nat.squarefree_pow_iff Nat.squarefree_pow_iff\n\ntheorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n :=\n  by\n  refine' Iff.symm ⟨fun hn => ⟨hn.Squarefree, hn.IsPrimePow⟩, _⟩\n  rw [isPrimePow_nat_iff]\n  rintro ⟨h, p, k, hp, hk, rfl⟩\n  rw [squarefree_pow_iff hp.ne_one hk.ne'] at h\n  rwa [h.2, pow_one]\n#align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime\n\n/-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that\n  `p^2 ∣ n`. -/\ndef minSqFacAux : ℕ → ℕ → Option ℕ\n  | n, k =>\n    if h : n < k * k then none\n    else\n      have : Nat.sqrt n + 2 - (k + 2) < Nat.sqrt n + 2 - k :=\n        by\n        rw [Nat.add_sub_add_right]\n        exact Nat.minFac_lemma n k h\n      if k ∣ n then\n        let n' := n / k\n        have : Nat.sqrt n' + 2 - (k + 2) < Nat.sqrt n + 2 - k :=\n          lt_of_le_of_lt\n            (Nat.sub_le_sub_right (Nat.add_le_add_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) _)\n              _)\n            this\n        if k ∣ n' then some k else min_sq_fac_aux n' (k + 2)\n      else min_sq_fac_aux n (k + 2)termination_by'\n  ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩\n#align nat.min_sq_fac_aux Nat.minSqFacAux\n\n/-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no\n  such `p` (that is, `n` is squarefree). See also `squarefree_iff_min_sq_fac`. -/\ndef minSqFac (n : ℕ) : Option ℕ :=\n  if 2 ∣ n then\n    let n' := n / 2\n    if 2 ∣ n' then some 2 else minSqFacAux n' 3\n  else minSqFacAux n 3\n#align nat.min_sq_fac Nat.minSqFac\n\n/-- The correctness property of the return value of `min_sq_fac`.\n  * If `none`, then `n` is squarefree;\n  * If `some d`, then `d` is a minimal square factor of `n` -/\ndef MinSqFacProp (n : ℕ) : Option ℕ → Prop\n  | none => Squarefree n\n  | some d => Prime d ∧ d * d ∣ n ∧ ∀ p, Prime p → p * p ∣ n → d ≤ p\n#align nat.min_sq_fac_prop Nat.MinSqFacProp\n\ntheorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k ∣ n) {o}\n    (H : MinSqFacProp (n / k) o) : MinSqFacProp n o :=\n  by\n  have : ∀ p, Prime p → p * p ∣ n → k * (p * p) ∣ n := fun p pp dp =>\n    have :=\n      (coprime_primes pk pp).2 fun e => by\n        subst e\n        contradiction\n    (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp\n  cases' o with d\n  · rw [min_sq_fac_prop, squarefree_iff_prime_squarefree] at H⊢\n    exact fun p pp dp => H p pp ((dvd_div_iff dk).2 (this _ pp dp))\n  · obtain ⟨H1, H2, H3⟩ := H\n    simp only [dvd_div_iff dk] at H2 H3\n    exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩\n#align nat.min_sq_fac_prop_div Nat.minSqFacProp_div\n\ntheorem minSqFacAux_has_prop :\n    ∀ {n : ℕ} (k),\n      0 < n → ∀ i, k = 2 * i + 3 → (∀ m, Prime m → m ∣ n → k ≤ m) → MinSqFacProp n (minSqFacAux n k)\n  | n, k => fun n0 i e ih => by\n    rw [min_sq_fac_aux]\n    by_cases h : n < k * k <;> simp [h]\n    · refine' squarefree_iff_prime_squarefree.2 fun p pp d => _\n      have := ih p pp (dvd_trans ⟨_, rfl⟩ d)\n      have := Nat.mul_le_mul this this\n      exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))\n    have k2 : 2 ≤ k := by\n      subst e\n      exact by decide\n    have k0 : 0 < k := lt_of_lt_of_le (by decide) k2\n    have IH : ∀ n', n' ∣ n → ¬k ∣ n' → min_sq_fac_prop n' (n'.minSqFacAux (k + 2)) :=\n      by\n      intro n' nd' nk\n      have hn' := le_of_dvd n0 nd'\n      refine'\n        have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k :=\n          lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h)\n        @min_sq_fac_aux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)\n          (by simp [e, left_distrib]) fun m m2 d => _\n      cases' Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me ml\n      · subst me\n        contradiction\n      apply (Nat.eq_or_lt_of_le ml).resolve_left\n      intro me\n      rw [← me, e] at d\n      change 2 * (i + 2) ∣ n' at d\n      have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')\n      rw [e] at this\n      exact absurd this (by decide)\n    have pk : k ∣ n → Prime k :=\n      by\n      refine' fun dk => prime_def_min_fac.2 ⟨k2, le_antisymm (min_fac_le k0) _⟩\n      exact ih _ (min_fac_prime (ne_of_gt k2)) (dvd_trans (min_fac_dvd _) dk)\n    split_ifs with dk dkk\n    · exact ⟨pk dk, (Nat.dvd_div_iff dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩\n    · specialize IH (n / k) (div_dvd_of_dvd dk) dkk\n      exact min_sq_fac_prop_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH\n    · exact IH n (dvd_refl _) dk termination_by' ⟨_, measure_wf fun ⟨n, k⟩ => Nat.sqrt n + 2 - k⟩\n#align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop\n\ntheorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) :=\n  by\n  dsimp only [min_sq_fac]; split_ifs with d2 d4\n  · exact ⟨prime_two, (dvd_div_iff d2).1 d4, fun p pp _ => pp.two_le⟩\n  · cases' Nat.eq_zero_or_pos n with n0 n0\n    · subst n0\n      cases d4 (by decide)\n    refine' min_sq_fac_prop_div _ prime_two d2 (mt (dvd_div_iff d2).2 d4) _\n    refine' min_sq_fac_aux_has_prop 3 (Nat.div_pos (le_of_dvd n0 d2) (by decide)) 0 rfl _\n    refine' fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le _)\n    rintro rfl\n    contradiction\n  · cases' Nat.eq_zero_or_pos n with n0 n0\n    · subst n0\n      cases d2 (by decide)\n    refine' min_sq_fac_aux_has_prop _ n0 0 rfl _\n    refine' fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le _)\n    rintro rfl\n    contradiction\n#align nat.min_sq_fac_has_prop Nat.minSqFac_has_prop\n\ntheorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d :=\n  by\n  have := min_sq_fac_has_prop n\n  rw [h] at this\n  exact this.1\n#align nat.min_sq_fac_prime Nat.minSqFac_prime\n\ntheorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n :=\n  by\n  have := min_sq_fac_has_prop n\n  rw [h] at this\n  exact this.2.1\n#align nat.min_sq_fac_dvd Nat.minSqFac_dvd\n\ntheorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) :\n    d ≤ m := by\n  have := min_sq_fac_has_prop n; rw [h] at this\n  have fd := min_fac_dvd m\n  exact\n    le_trans (this.2.2 _ (min_fac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md))\n      (min_fac_le <| lt_of_lt_of_le (by decide) m2)\n#align nat.min_sq_fac_le_of_dvd Nat.minSqFac_le_of_dvd\n\ntheorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none :=\n  by\n  have := min_sq_fac_has_prop n\n  constructor <;> intro H\n  · cases' n.min_sq_fac with d\n    · rfl\n    cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1\n  · rwa [H] at this\n#align nat.squarefree_iff_min_sq_fac Nat.squarefree_iff_minSqFac\n\ninstance : DecidablePred (Squarefree : ℕ → Prop) := fun n =>\n  decidable_of_iff' _ squarefree_iff_minSqFac\n\ntheorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_factors] <;> norm_num\n#align nat.squarefree_two Nat.squarefree_two\n\nopen UniqueFactorizationMonoid\n\ntheorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) :\n    (n.divisors.filterₓ Squarefree).val =\n      (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x =>\n        x.val.Prod :=\n  by\n  rw [(Finset.nodup _).ext ((Finset.nodup _).map_onₓ _)]\n  · intro a\n    simp only [Multiset.mem_filter, id.def, Multiset.mem_map, Finset.filter_val, ← Finset.mem_def,\n      mem_divisors]\n    constructor\n    · rintro ⟨⟨an, h0⟩, hsq⟩\n      use (UniqueFactorizationMonoid.normalizedFactors a).toFinset\n      simp only [id.def, Finset.mem_powerset]\n      rcases an with ⟨b, rfl⟩\n      rw [mul_ne_zero_iff] at h0\n      rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq\n      rw [Multiset.toFinset_subset, Multiset.toFinset_val, hsq.dedup, ← associated_iff_eq,\n        normalized_factors_mul h0.1 h0.2]\n      exact ⟨Multiset.subset_of_le (Multiset.le_add_right _ _), normalized_factors_prod h0.1⟩\n    · rintro ⟨s, hs, rfl⟩\n      rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs\n      have hs0 : s.val.prod ≠ 0 :=\n        by\n        rw [Ne.def, Multiset.prod_eq_zero_iff]\n        simp only [exists_prop, id.def, exists_eq_right]\n        intro con\n        apply\n          not_irreducible_zero\n            (irreducible_of_normalized_factor 0 (Multiset.mem_dedup.1 (Multiset.mem_of_le hs Con)))\n      rw [(normalized_factors_prod h0).symm.dvd_iff_dvd_right]\n      refine' ⟨⟨Multiset.prod_dvd_prod_of_le (le_trans hs (Multiset.dedup_le _)), h0⟩, _⟩\n      have h :=\n        UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor\n          (fun x hx =>\n            irreducible_of_normalized_factor x\n              (Multiset.mem_of_le (le_trans hs (Multiset.dedup_le _)) hx))\n          (normalized_factors_prod hs0)\n      rw [associated_eq_eq, Multiset.rel_eq] at h\n      rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors hs0, h]\n      apply s.nodup\n  · intro x hx y hy h\n    rw [← Finset.val_inj, ← Multiset.rel_eq, ← associated_eq_eq]\n    rw [← Finset.mem_def, Finset.mem_powerset] at hx hy\n    apply UniqueFactorizationMonoid.factors_unique _ _ (associated_iff_eq.2 h)\n    · intro z hz\n      apply irreducible_of_normalized_factor z\n      rw [← Multiset.mem_toFinset]\n      apply hx hz\n    · intro z hz\n      apply irreducible_of_normalized_factor z\n      rw [← Multiset.mem_toFinset]\n      apply hy hz\n#align nat.divisors_filter_squarefree Nat.divisors_filter_squarefree\n\nopen BigOperators\n\ntheorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type _} [AddCommMonoid α]\n    {f : ℕ → α} :\n    (∑ i in n.divisors.filterₓ Squarefree, f i) =\n      ∑ i in (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset, f i.val.Prod :=\n  by\n  rw [Finset.sum_eq_multiset_sum, divisors_filter_squarefree h0, Multiset.map_map,\n    Finset.sum_eq_multiset_sum]\n#align nat.sum_divisors_filter_squarefree Nat.sum_divisors_filter_squarefree\n\ntheorem sq_mul_squarefree_of_pos {n : ℕ} (hn : 0 < n) :\n    ∃ a b : ℕ, 0 < a ∧ 0 < b ∧ b ^ 2 * a = n ∧ Squarefree a :=\n  by\n  let S := { s ∈ Finset.range (n + 1) | s ∣ n ∧ ∃ x, s = x ^ 2 }\n  have hSne : S.nonempty := by\n    use 1\n    have h1 : 0 < n ∧ ∃ x : ℕ, 1 = x ^ 2 := ⟨hn, ⟨1, (one_pow 2).symm⟩⟩\n    simpa [S]\n  let s := Finset.max' S hSne\n  have hs : s ∈ S := Finset.max'_mem S hSne\n  simp only [Finset.sep_def, S, Finset.mem_filter, Finset.mem_range] at hs\n  obtain ⟨hsn1, ⟨a, hsa⟩, ⟨b, hsb⟩⟩ := hs\n  rw [hsa] at hn\n  obtain ⟨hlts, hlta⟩ := canonically_ordered_comm_semiring.mul_pos.mp hn\n  rw [hsb] at hsa hn hlts\n  refine' ⟨a, b, hlta, (pow_pos_iff zero_lt_two).mp hlts, hsa.symm, _⟩\n  rintro x ⟨y, hy⟩\n  rw [Nat.isUnit_iff]\n  by_contra hx\n  refine' lt_le_antisymm _ (Finset.le_max' S ((b * x) ^ 2) _)\n  · simp_rw [S, hsa, Finset.sep_def, Finset.mem_filter, Finset.mem_range]\n    refine' ⟨lt_succ_iff.mpr (le_of_dvd hn _), _, ⟨b * x, rfl⟩⟩ <;> use y <;> rw [hy] <;> ring\n  · convert lt_mul_of_one_lt_right hlts\n        (one_lt_pow 2 x zero_lt_two (one_lt_iff_ne_zero_and_ne_one.mpr ⟨fun h => by simp_all, hx⟩))\n    rw [mul_pow]\n#align nat.sq_mul_squarefree_of_pos Nat.sq_mul_squarefree_of_pos\n\ntheorem sq_mul_squarefree_of_pos' {n : ℕ} (h : 0 < n) :\n    ∃ a b : ℕ, (b + 1) ^ 2 * (a + 1) = n ∧ Squarefree (a + 1) :=\n  by\n  obtain ⟨a₁, b₁, ha₁, hb₁, hab₁, hab₂⟩ := sq_mul_squarefree_of_pos h\n  refine' ⟨a₁.pred, b₁.pred, _, _⟩ <;> simpa only [add_one, succ_pred_eq_of_pos, ha₁, hb₁]\n#align nat.sq_mul_squarefree_of_pos' Nat.sq_mul_squarefree_of_pos'\n\ntheorem sq_mul_squarefree (n : ℕ) : ∃ a b : ℕ, b ^ 2 * a = n ∧ Squarefree a :=\n  by\n  cases n\n  · exact ⟨1, 0, by simp, squarefree_one⟩\n  · obtain ⟨a, b, -, -, h₁, h₂⟩ := sq_mul_squarefree_of_pos (succ_pos n)\n    exact ⟨a, b, h₁, h₂⟩\n#align nat.sq_mul_squarefree Nat.sq_mul_squarefree\n\n/-- `squarefree` is multiplicative. Note that the → direction does not require `hmn`\nand generalizes to arbitrary commutative monoids. See `squarefree.of_mul_left` and\n`squarefree.of_mul_right` above for auxiliary lemmas. -/\ntheorem squarefree_mul {m n : ℕ} (hmn : m.coprime n) :\n    Squarefree (m * n) ↔ Squarefree m ∧ Squarefree n :=\n  by\n  simp only [squarefree_iff_prime_squarefree, ← sq, ← forall_and]\n  refine' ball_congr fun p hp => _\n  simp only [hmn.is_prime_pow_dvd_mul (hp.is_prime_pow.pow two_ne_zero), not_or]\n#align nat.squarefree_mul Nat.squarefree_mul\n\nend Nat\n\n/-! ### Square-free prover -/\n\n\nopen NormNum\n\nnamespace Tactic\n\nnamespace NormNum\n\n/-- A predicate representing partial progress in a proof of `squarefree`. -/\ndef SquarefreeHelper (n k : ℕ) : Prop :=\n  0 < k → (∀ m, Nat.Prime m → m ∣ bit1 n → bit1 k ≤ m) → Squarefree (bit1 n)\n#align tactic.norm_num.squarefree_helper Tactic.NormNum.SquarefreeHelper\n\ntheorem squarefree_bit10 (n : ℕ) (h : SquarefreeHelper n 1) : Squarefree (bit0 (bit1 n)) :=\n  by\n  refine' @Nat.minSqFacProp_div _ _ Nat.prime_two two_dvd_bit0 _ none _\n  · rw [bit0_eq_two_mul (bit1 n), mul_dvd_mul_iff_left (two_ne_zero' ℕ)]\n    exact Nat.not_two_dvd_bit1 _\n  · rw [bit0_eq_two_mul, Nat.mul_div_right _ (by decide : 0 < 2)]\n    refine' h (by decide) fun p pp dp => Nat.succ_le_of_lt (lt_of_le_of_ne pp.two_le _)\n    rintro rfl\n    exact Nat.not_two_dvd_bit1 _ dp\n#align tactic.norm_num.squarefree_bit10 Tactic.NormNum.squarefree_bit10\n\ntheorem squarefree_bit1 (n : ℕ) (h : SquarefreeHelper n 1) : Squarefree (bit1 n) :=\n  by\n  refine' h (by decide) fun p pp dp => Nat.succ_le_of_lt (lt_of_le_of_ne pp.two_le _)\n  rintro rfl; exact Nat.not_two_dvd_bit1 _ dp\n#align tactic.norm_num.squarefree_bit1 Tactic.NormNum.squarefree_bit1\n\ntheorem squarefree_helper_0 {k} (k0 : 0 < k) {p : ℕ} (pp : Nat.Prime p) (h : bit1 k ≤ p) :\n    bit1 (k + 1) ≤ p ∨ bit1 k = p :=\n  by\n  rcases lt_or_eq_of_le h with ((hp : _ + 1 ≤ _) | hp)\n  · rw [bit1, bit0_eq_two_mul] at hp\n    change 2 * (_ + 1) ≤ _ at hp\n    rw [bit1, bit0_eq_two_mul]\n    refine' Or.inl (lt_of_le_of_ne hp _)\n    rintro rfl\n    exact Nat.not_prime_mul (by decide) (lt_add_of_pos_left _ k0) pp\n  · exact Or.inr hp\n#align tactic.norm_num.squarefree_helper_0 Tactic.NormNum.squarefree_helper_0\n\ntheorem squarefreeHelper_1 (n k k' : ℕ) (e : k + 1 = k')\n    (hk : Nat.Prime (bit1 k) → ¬bit1 k ∣ bit1 n) (H : SquarefreeHelper n k') :\n    SquarefreeHelper n k := fun k0 ih => by\n  subst e\n  refine' H (Nat.succ_pos _) fun p pp dp => _\n  refine' (squarefree_helper_0 k0 pp (ih p pp dp)).resolve_right fun hp => _\n  subst hp; cases hk pp dp\n#align tactic.norm_num.squarefree_helper_1 Tactic.NormNum.squarefreeHelper_1\n\ntheorem squarefreeHelper_2 (n k k' c : ℕ) (e : k + 1 = k') (hc : bit1 n % bit1 k = c) (c0 : 0 < c)\n    (h : SquarefreeHelper n k') : SquarefreeHelper n k :=\n  by\n  refine' squarefree_helper_1 _ _ _ e (fun _ => _) h\n  refine' mt _ (ne_of_gt c0); intro e₁\n  rwa [← hc, ← Nat.dvd_iff_mod_eq_zero]\n#align tactic.norm_num.squarefree_helper_2 Tactic.NormNum.squarefreeHelper_2\n\ntheorem squarefreeHelper_3 (n n' k k' c : ℕ) (e : k + 1 = k') (hn' : bit1 n' * bit1 k = bit1 n)\n    (hc : bit1 n' % bit1 k = c) (c0 : 0 < c) (H : SquarefreeHelper n' k') : SquarefreeHelper n k :=\n  fun k0 ih => by\n  subst e\n  have k0' : 0 < bit1 k := bit1_pos (Nat.zero_le _)\n  have dn' : bit1 n' ∣ bit1 n := ⟨_, hn'.symm⟩\n  have dk : bit1 k ∣ bit1 n := ⟨_, ((mul_comm _ _).trans hn').symm⟩\n  have : bit1 n / bit1 k = bit1 n' := by rw [← hn', Nat.mul_div_cancel _ k0']\n  have k2 : 2 ≤ bit1 k := Nat.succ_le_succ (bit0_pos k0)\n  have pk : (bit1 k).Prime :=\n    by\n    refine' Nat.prime_def_minFac.2 ⟨k2, le_antisymm (Nat.minFac_le k0') _⟩\n    exact ih _ (Nat.minFac_prime (ne_of_gt k2)) (dvd_trans (Nat.minFac_dvd _) dk)\n  have dkk' : ¬bit1 k ∣ bit1 n' :=\n    by\n    rw [Nat.dvd_iff_mod_eq_zero, hc]\n    exact ne_of_gt c0\n  have dkk : ¬bit1 k * bit1 k ∣ bit1 n := by rwa [← Nat.dvd_div_iff dk, this]\n  refine' @Nat.minSqFacProp_div _ _ pk dk dkk none _\n  rw [this]\n  refine' H (Nat.succ_pos _) fun p pp dp => _\n  refine' (squarefree_helper_0 k0 pp (ih p pp <| dvd_trans dp dn')).resolve_right fun e => _\n  subst e\n  contradiction\n#align tactic.norm_num.squarefree_helper_3 Tactic.NormNum.squarefreeHelper_3\n\ntheorem squarefreeHelper_4 (n k k' : ℕ) (e : bit1 k * bit1 k = k') (hd : bit1 n < k') :\n    SquarefreeHelper n k := by\n  cases' Nat.eq_zero_or_pos n with h h\n  · subst n\n    exact fun _ _ => squarefree_one\n  subst e\n  refine' fun k0 ih => Irreducible.squarefree (Nat.prime_def_le_sqrt.2 ⟨bit1_lt_bit1.2 h, _⟩)\n  intro m m2 hm md\n  obtain ⟨p, pp, hp⟩ := Nat.exists_prime_and_dvd (ne_of_gt m2)\n  have :=\n    (ih p pp (dvd_trans hp md)).trans\n      (le_trans (Nat.le_of_dvd (lt_of_lt_of_le (by decide) m2) hp) hm)\n  rw [Nat.le_sqrt] at this\n  exact not_le_of_lt hd this\n#align tactic.norm_num.squarefree_helper_4 Tactic.NormNum.squarefreeHelper_4\n\ntheorem not_squarefree_mul (a aa b n : ℕ) (ha : a * a = aa) (hb : aa * b = n) (h₁ : 1 < a) :\n    ¬Squarefree n := by\n  rw [← hb, ← ha]\n  exact fun H => ne_of_gt h₁ (Nat.isUnit_iff.1 <| H _ ⟨_, rfl⟩)\n#align tactic.norm_num.not_squarefree_mul Tactic.NormNum.not_squarefree_mul\n\n/-- Given `e` a natural numeral and `a : nat` with `a^2 ∣ n`, return `⊢ ¬ squarefree e`. -/\nunsafe def prove_non_squarefree (e : expr) (n a : ℕ) : tactic expr := do\n  let ea := reflect a\n  let eaa := reflect (a * a)\n  let c ← mk_instance_cache q(Nat)\n  let (c, p₁) ← prove_lt_nat c q(1) ea\n  let b := n / (a * a)\n  let eb := reflect b\n  let (c, eaa, pa) ← prove_mul_nat c ea ea\n  let (c, e', pb) ← prove_mul_nat c eaa eb\n  guard (e' == e)\n  return <| q(@not_squarefree_mul).mk_app [ea, eaa, eb, e, pa, pb, p₁]\n#align tactic.norm_num.prove_non_squarefree tactic.norm_num.prove_non_squarefree\n\n/-- Given `en`,`en1 := bit1 en`, `n1` the value of `en1`, `ek`,\n  returns `⊢ squarefree_helper en ek`. -/\nunsafe def prove_squarefree_aux :\n    ∀ (ic : instance_cache) (en en1 : expr) (n1 : ℕ) (ek : expr) (k : ℕ), tactic expr\n  | ic, en, en1, n1, ek, k => do\n    let k1 := bit1 k\n    let ek1 := q((bit1 : ℕ → ℕ)).mk_app [ek]\n    if n1 < k1 * k1 then do\n        let (ic, ek', p₁) ← prove_mul_nat ic ek1 ek1\n        let (ic, p₂) ← prove_lt_nat ic en1 ek'\n        pure <| q(squarefreeHelper_4).mk_app [en, ek, ek', p₁, p₂]\n      else do\n        let c := n1 % k1\n        let k' := k + 1\n        let ek' := reflect k'\n        let (ic, p₁) ← prove_succ ic ek ek'\n        if c = 0 then do\n            let n1' := n1 / k1\n            let n' := n1' / 2\n            let en' := reflect n'\n            let en1' := q((bit1 : ℕ → ℕ)).mk_app [en']\n            let (ic, _, pn') ← prove_mul_nat ic en1' ek1\n            let c := n1' % k1\n            guard (c ≠ 0)\n            let (ic, ec, pc) ← prove_div_mod ic en1' ek1 tt\n            let (ic, p₀) ← prove_pos ic ec\n            let p₂ ← prove_squarefree_aux ic en' en1' n1' ek' k'\n            pure <| q(squarefreeHelper_3).mk_app [en, en', ek, ek', ec, p₁, pn', pc, p₀, p₂]\n          else do\n            let (ic, ec, pc) ← prove_div_mod ic en1 ek1 tt\n            let (ic, p₀) ← prove_pos ic ec\n            let p₂ ← prove_squarefree_aux ic en en1 n1 ek' k'\n            pure <| q(squarefreeHelper_2).mk_app [en, ek, ek', ec, p₁, pc, p₀, p₂]\n#align tactic.norm_num.prove_squarefree_aux tactic.norm_num.prove_squarefree_aux\n\n/-- Given `n > 0` a squarefree natural numeral, returns `⊢ squarefree n`. -/\nunsafe def prove_squarefree (en : expr) (n : ℕ) : tactic expr :=\n  match match_numeral en with\n  | match_numeral_result.one => pure q(@squarefree_one ℕ _)\n  | match_numeral_result.bit0 en1 =>\n    match match_numeral en1 with\n    | match_numeral_result.one => pure q(Nat.squarefree_two)\n    | match_numeral_result.bit1 en => do\n      let ic ← mk_instance_cache q(ℕ)\n      let p ← prove_squarefree_aux ic en en1 (n / 2) q((1 : ℕ)) 1\n      pure <| q(squarefree_bit10).mk_app [en, p]\n    | _ => failed\n  | match_numeral_result.bit1 en' => do\n    let ic ← mk_instance_cache q(ℕ)\n    let p ← prove_squarefree_aux ic en' en n q((1 : ℕ)) 1\n    pure <| q(squarefree_bit1).mk_app [en', p]\n  | _ => failed\n#align tactic.norm_num.prove_squarefree tactic.norm_num.prove_squarefree\n\n/-- Evaluates the `squarefree` predicate on naturals. -/\n@[norm_num]\nunsafe def eval_squarefree : expr → tactic (expr × expr)\n  | q(Squarefree ($(e) : ℕ)) => do\n    let n ← e.toNat\n    match n with\n      | 0 => false_intro q(@not_squarefree_zero ℕ _ _)\n      | 1 => true_intro q(@squarefree_one ℕ _)\n      | _ =>\n        match n with\n        | some d => prove_non_squarefree e n d >>= false_intro\n        | none => prove_squarefree e n >>= true_intro\n  | _ => failed\n#align tactic.norm_num.eval_squarefree tactic.norm_num.eval_squarefree\n\nend NormNum\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/Nat/Squarefree.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.756869017613122}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que 3 divide al máximo xomún divisor de 6 y 15.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\nimport data.nat.gcd\n\nopen nat\n\n-- 1ª demostración\n-- ===============\n\nexample : 3 ∣ gcd 6 15 :=\nbegin\n  rw dvd_gcd_iff,\n  split; norm_num,\nend\n\n-- Prueba\n-- ======\n\n/-\n⊢ 3 ∣ 6.gcd 15\n  rw dvd_gcd_iff,\n⊢ 3 ∣ 6 ∧ 3 ∣ 15\n  split; norm_num,\nno goals\n-/\n\n-- Comentario: Se ha usado el lema\n-- + dvd_gcd_iff: k | gcd m n ↔ k | m ∧ k | b\n\n-- 2ª demostración\n-- ===============\n\nexample : 3 ∣ gcd 6 15 :=\nbegin\n  convert dvd_refl _,\n  by norm_num,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : 3 ∣ gcd 6 15 :=\nby norm_num\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/Divisor_del_mcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.756869015529272}}
{"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\" (`¬`) \n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# Important : the definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → false`. So `¬ P` and `P → 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 : ¬ true → false :=\nbegin\n  intro q, change true->false at q,apply q,triv,\nend\n\nexample : false → ¬ true :=\nbegin\n  intro q, by_contra, triv,\nend\n\nexample : ¬ false → true :=\nbegin\n  intro q,triv,\nend\n\nexample : true → ¬ false :=\nbegin\n  intros q w,triv,\nend\n\nexample : false → ¬ P :=\nbegin\n  intro q,change P->false,intro w,triv,\nend\n\nexample : P → ¬ P → false :=\nbegin\n  intro q, triv,\nend\n\nexample : P → ¬ (¬ P) :=\nbegin\n  intro q,change ¬ P ->false,triv,\nend\n\nexample : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  intros q w e, apply w,apply q,assumption,\nend\n\nexample : ¬ ¬ false → false :=\nbegin\n  intro q, apply q,intro w,triv,\nend\n\nexample : ¬ ¬ P → P :=\nbegin\n  intro q,by_contra,apply q,triv,\nend\n\nexample : (¬ Q → ¬ P) → (P → Q) :=\nbegin\n  intro q,intro w,by_cases Q,{assumption},{by_contra, apply q,{assumption},{assumption}}\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/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.756869013445422}}
{"text": "import data.real.basic\n\nvariables (u : ℕ → ℝ)\nvariables (a b x y : ℝ)\n\nnotation `|`x`|` := abs x\n\ndef limite : (ℕ → ℝ) → ℝ → Prop :=\nλ u c, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - c| ≤ ε\n\nlemma eq_of_abs_sub_le_all\n  : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h,\n  apply eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\nexample\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  apply eq_of_abs_sub_le_all,\n  intros eps eps_pos,\n  cases ha (eps/2) (by linarith) with N1 hN1,\n  cases hb (eps/2) (by linarith) with N2 hN2,\n  let N0:=max N1 N2,\n  calc  |a-b|\n      = |(a-u N0)+(u N0-b)| : by ring_nf\n  ... ≤ |a-u N0| + |u N0-b| : by apply abs_add\n  ... = |u N0-a| + |u N0-b| : by rw abs_sub\n  ... ≤ eps                 : by linarith [hN1 N0 (le_max_left N1 N2),\n                                           hN2 N0 (le_max_right N1 N2)],\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/Unicidad_del_limite.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7568690049021971}}
{"text": "-- -- * On propositions ----------------------------------------------------------\n-- * Int [#64]\n-- we can build a small logical system directly in lean\nnamespace ml\nconstant and : Prop → Prop → Prop\nconstant or : Prop → Prop → Prop\nconstant not : Prop → Prop\nconstant implies : Prop → Prop → Prop\n\nvariables 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\nconstant Proof : Prop → Type\n\nconstant and_comm : Π 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\nend ml\n\n-- How do we go from a Proof object to the usual proof using the objects\n-- themselves? By conflating Proof p with p! instantiating p is thus tantamount\n-- to proving p!\n\n\n-- Some simplifications are possible, however. To start with, we can avoid\n-- writing the term Proof repeatedly by conflating Proof p with p itself. In\n-- other words, whenever we have p : Prop, we can interpret p as a type, namely,\n-- the type of its proofs. We can then read t : p as the assertion that t is a\n-- proof of p. Moreover, once we make this identification, the rules for\n-- implication show that we can pass back and forth between implies p q and p →\n-- q. In other words, implication between propositions p and q corresponds to\n-- having a function that takes any element of p to an element of q. As a\n-- result, the introduction of the connective implies is entirely redundant: we\n-- can use the usual function space constructor p → q from dependent type theory\n-- as our notion of implication.This is the approach followed in the Calculus of\n-- Constructions, and hence in Lean as well. The fact that the rules for\n-- implication in a proof system for natural deduction correspond exactly to the\n-- rules governing abstraction and application for functions is an instance of\n-- the Curry-Howard isomorphism, sometimes known as the propositions-as-types\n-- paradigm. In fact, the type Prop is syntactic sugar for Sort 0, the very\n-- bottom of the type hierarchy described in the last chapter. Moreover, Type u\n-- is also just syntactic sugar for Sort (u+1). Prop has some special features,\n-- but like the other type universes, it is closed under the arrow constructor:\n-- if we have p q : Prop, then p → q : Prop.\n\n-- There are at least two ways of thinking about propositions as types. To some\n-- who take a constructive view of logic and mathematics, this is a faithful\n-- rendering of what it means to be a proposition: a proposition p represents a\n-- sort of data type, namely, a specification of the type of data that\n-- constitutes a proof. A proof of p is then simply an object t : p of the right\n-- type.\n\n\n-- They talk about interpretations and so on what matters is the bottom line\n\n-- To formally express a mathematical assertion in the language of dependent\n-- type theory, we need to exhibit a term p : Prop. To prove that assertion, we\n-- need to exhibit a term t : p. Lean’s task, as a proof assistant, is to help\n-- us to construct such a term, t, and to verify that it is well-formed and has\n-- the correct type.\n\n\n-- ** What differs theorem from def? [#85]\n-- It gives a hint to the compiler!\n\n\n-- Note that the theorem command is really a version of the definition command:\n-- under the propositions and types correspondence, proving the theorem p → q →\n-- p is really the same as defining an element of the associated type. To the\n-- kernel type checker, there is no difference between the two.\n\n-- There are a few pragmatic differences between definitions and theorems,\n-- however. In normal circumstances, it is never necessary to unfold the\n-- “definition” of a theorem; by proof irrelevance, any two proofs of that\n-- theorem are definitionally equal. Once the proof of a theorem is complete,\n-- typically we only need to know that the proof exists; it doesn’t matter what\n-- the proof is. In light of that fact, Lean tags proofs as irreducible, which\n-- serves as a hint to the parser (more precisely, the elaborator) that there is\n-- generally no need to unfold it when processing a file. In fact, Lean is\n-- generally able to process and check proofs in parallel, since assessing the\n-- correctness of one proof does not require knowing the details of another.\n\n\n-- The three ways below are equivalent, but some are clearer to read\n\n\nconstants p q : Prop\n\ntheorem t1 : p → q → p := λ hp : p, λ hq : q, hp\n\n#print t1\n\n\ntheorem t2 : p → q → p :=\nassume hp : p,\nassume hq : q,\nhp\n\n#print t2\n\ntheorem t3 : p → q → p :=\nassume hp : p,\nassume hq : q,\nshow p, from hp\n\n-- assume here looks like the intro tactic\ntheorem t4 (hp : p) (hq : q) : p := hp\n#check t4    -- p → q → p\n\n\n-- the axiom kw is like constant for Prop\naxiom hp : p\ntheorem t5 : q → p := t4 hp\n\n\n-- Notice, by the way, that the original theorem t1 is true for any propositions\n-- p and q, not just the particular constants declared. So it would be more\n-- natural to define the theorem so that it quantifies over those, too:\n\ntheorem t6 (p q : Prop) (hp : p) (hq : q) : p := hp\n#check t6 -- ∀ (p q : Prop), p → q → p\n\n-- The type of t1 is now ∀ p q : Prop, p → q → p. We can read this as the\n-- assertion “for every pair of propositions p q, we have p → q → p.” The symbol\n-- ∀ is alternate syntax for Π, and later we will see how Pi types let us model\n-- universal quantifiers more generally.\n\n-- If p and q have been declared as variables, Lean will generalize them for us automatically:\nvariables p q : Prop\n\ntheorem t7 : p → q → p := λ (hp : p) (hq : q), hp\n#check t7\n-- note it is the same damn thing as t6!\nvariables r s : Prop\n\n#check t7 p q                -- p → q → p\n#check t7 r s                -- r → s → r\n#check t7 (r → s) (s → r)    -- (r → s) → (s → r) → r → s\n\nvariable h : r → s\n\n#check t7 (r → s) (s → r) h  -- (s → r) → r → s\n\n\ntheorem t8 (h₁ : q → r) (h₂ : p → q) : p → r :=\nassume h₃ : p,\nshow r, from h₁ (h₂ h₃)\n\n-- * Having fun with connectives [#15]\n#check p → q → p ∧ q\n#check ¬p → p ↔ false\n#check p ∨ q → q ∨ p\n\n\n-- The order of operations is as follows: unary negation ¬ binds most strongly,\n-- then ∧, then ∨, then →, and finally ↔. For example, a ∧ b → c ∨ d ∧ e means\n-- (a ∧ b) → (c ∨ (d ∧ e)).\n\n--In the last chapter we observed that lambda abstraction can be viewed as an\n--“introduction rule” for →. In the current setting, it shows how to “introduce”\n--or establish an implication. Application can be viewed as an “elimination\n--rule,” showing how to “eliminate” or use an implication in a proof.\n\n\n-- ** Conjunction [#10]\n\n-- The expression and.intro h1 h2 builds a proof of p ∧ q using\n-- proofs h1 : p and h2 : q. It is common to describe and.intro as the\n-- and-introduction rule. In the next example we use and.intro to create a proof\n-- of p → q → p ∧ q.\n\n\n\n\n\n-- *** example command [#12]\n\n\n-- The example command states a theorem without naming it or storing it in the\n-- permanent context. Essentially, it just checks that the given term has the\n-- indicated type\nexample (hp : p) (hq : q) : p ∧ q := and.intro hp hq\n\n#check assume (hp : p) (hq : q), and.intro hp hq\n\n\n\n\n-- *** and.intro command [#33]\n\n\n-- The expression and.intro h1 h2 builds a proof of p ∧ q using proofs h1 : p\n-- and h2 : q. It is common to describe and.intro as the and-introduction rule.\n-- In the next example we use and.intro to create a proof of p → q → p ∧ q. try\n-- it!\n\nexample (hp : p) (hq : q) : p ∧ q := and.intro hp hq\n\n#check assume (hp : p) (hq : q), and.intro hp hq\n\n--- *** and.elim_left, and.elim_right, and abbreviations: and.left, and.right\n\n-- The expression and.elim_left h creates a proof of p from a proof h : p ∧ q.\n-- Similarly, and.elim_right h is a proof of q. They are commonly known as the\n-- right and left and-elimination rules. Because they are so commonly used, the\n-- standard library provides the abbreviations and.left and and.right for\n-- and.elim_left and and.elim_right, respectively.\n\n\n\n\n-- COOL FACT\n\n-- Notice that and-introduction and and-elimination are similar to the pairing\n-- and projection operations for the cartesian product. The difference is that\n-- given hp : p and hq : q, and.intro hp hq has type p ∧ q : Prop, while pair hp\n-- hq has type p × q : Type. The similarity between ∧ and × is another instance\n-- of the Curry-Howard isomorphism, but in contrast to implication and the\n-- function space constructor, ∧ and × are treated separately in Lean. With the\n-- analogy, however, the proof we have just constructed is similar to a function\n-- that swaps the elements of a pair.\n\n-- *** EXPLAINING THE WEIRD ⟨ ⟩ notation [#34]\n\n-- We will see in Chapter 9 that certain types in Lean are structures, which is\n-- to say, the type is defined with a single canonical constructor which builds\n-- an element of the type from a sequence of suitable arguments. For every p q :\n-- Prop, p ∧ q is an example: the canonical way to construct an element is to\n-- apply and.intro to suitable arguments hp : p and hq : q. Lean allows us to\n-- use anonymous constructor notation ⟨arg1, arg2, ...⟩ in situations like\n-- these, when the relevant type is an inductive type and can be inferred from\n-- the context. In particular, we can often write ⟨hp, hq⟩ instead of and.intro\n-- hp hq:\nvariables  (hp : p) (hq : q)\n\n#check (⟨hp, hq⟩ : p ∧ q)\n\n--- *** another syntatic sugar: h.left = and.left h\n-- Lean provides another useful syntactic gadget. Given an expression e of an\n-- inductive type foo (possibly applied to some arguments), the notation e.bar\n-- is shorthand for foo.bar e. This provides a convenient way of accessing\n-- functions without opening a namespace. For example, the following two\n-- expressions mean the same thing:\n\nvariable l : list ℕ\n\n#check list.head l\n#check l.head\n\nexample (h : p ∧ q) : q ∧ p := ⟨h.right, h.left⟩\n\n--- *** flattening right-associative constructors\nexample (h : p ∧ q) : q ∧ p ∧ q:= ⟨h.right, ⟨h.left, h.right⟩⟩\n-- is equiv to\nexample (h : p ∧ q) : q ∧ p ∧ q:= ⟨h.right, h.left, h.right⟩\n\n\n-- ** Disjunction [#1]\n\n-- * or-introduction rules\n\n-- The expression or.intro_left q hp creates a proof of p ∨ q from a proof hp :\n-- p. Similarly, or.intro_right p hq creates a proof for p ∨ q using a proof hq\n-- : q. These are the left and right or-introduction rules.\nexample (hp : p) : p ∨ q := or.intro_left q hp\nexample (hq : q) : p ∨ q := or.intro_right p hq\n\n-- *** or-elimination rules [#15]\n\n-- The or-elimination rule is slightly more complicated. The idea is that we can\n-- prove r from p ∨ q, by showing that r follows from p and that r follows from\n-- q. In other words, it is a proof by cases. In the expression or.elim hpq hpr\n-- hqr, or.elim takes three arguments, hpq : p ∨ q, hpr : p → r and hqr : q → r,\n-- and produces a proof of r. In the following example, we use or.elim to prove\n-- p ∨ q → q ∨ p.\nexample (h : p ∨ q) : q ∨ p :=\nor.elim h\n  (assume hp : p,\n    show q ∨ p, from or.intro_right q hp)\n  (assume hq : q,\n    show q ∨ p, from or.intro_left p hq)\n\n\n-- *** abbreviation of or.intro left q hp = or.inl q (gotta assume hp !) [#15]\n\n-- In most cases, the first argument of or.intro_right and or.intro_left can be\n-- inferred automatically by Lean. Lean therefore provides or.inr and or.inl as\n-- shorthand for or.intro_right _ and or.intro_left _. Thus the proof term above\n-- could be written more concisely\n-- This one sucks to read\nexample (h : p ∨ q) : q ∨ p := or.elim h (λ hp, or.inr hp) (λ hq, or.inl hq)\n\n\n-- Because or has two constructors, we cannot use anonymous constructor\n-- notation. But we can still write h.elim instead of or.elim h:\nexample (h : p ∨ q) : q ∨ p :=\nh.elim\n  (assume hp : p, or.inr hp)\n  (assume hq : q, or.inl hq)\n-- * Falsity [#6]\n\n-- The connective false has a single elimination rule, false.elim, which\n-- expresses the fact that anything follows from a contradiction. This rule is\n-- sometimes called ex falso (short for ex falso sequitur quodlibet), or the\n-- principle of explosion.\n\n-- ** elimination rule: false.elim [#15]\n\n\n\n-- They explain wwtf is ex falso\n\n-- REVIEW THAT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n-- The connective false has a single elimination rule, false.elim, which\n-- expresses the fact that anything follows from a contradiction. This rule is\n-- sometimes called ex falso (short for ex falso sequitur quodlibet), or the\n-- principle of explosion.\n\nexample (hp : p) (hnp : ¬p) : q := false.elim (hnp hp)\n\n-- ** absurd [#10]\n-- The arbitrary fact, q, that follows from falsity is an implicit argument in\n-- false.elim and is inferred automatically. This pattern, deriving an arbitrary\n-- fact from contradictory hypotheses, is quite common, and is represented by\n-- absurd.\n\nexample (hp : p) (hnp : ¬p) : q := absurd hp hnp\n\nexample (hnp : ¬p) (hq : q) (hqp : q → p) : r := absurd (hqp hq) hnp\n\n\n-- ** introduction rule: true.intro [#6]\n\n-- Incidentally, just as false has only an elimination rule, true has only an\n-- introduction rule, true.intro : true, sometimes abbreviated trivial : true.\n-- In other words, true is simply true, and has a canonical proof, trivial.\n\n\n-- * Logical equivalence [#1]\n\n-- ** iff.intro h₁ h₂, iff.elim_left, iff.elim_right [#15]\n\n-- The expression iff.intro h1 h2 produces a proof of p ↔ q from h1 : p → q and\n-- h2 : q → p. The expression iff.elim_left h produces a proof of p → q from h :\n-- p ↔ q. Similarly, iff.elim_right h produces a proof of q → p from h : p ↔ q.\n-- Here is a proof of p ∧ q ↔ q ∧ p:The expression iff.intro h1 h2 produces a\n-- proof of p ↔ q from h1 : p → q and h2 : q → p. The expression iff.elim_left h\n-- produces a proof of p → q from h : p ↔ q. Similarly, iff.elim_right h\n-- produces a proof of q → p from h : p ↔ q. Here is a proof of p ∧ q ↔ q ∧ p:\ntheorem and_swap : p ∧ q ↔ q ∧ p :=\n  iff.intro\n  (assume h : p ∧ q,\n    show q ∧ p, from and.intro (and.right h) (and.left h))\n  (assume h : q ∧ p,\n    show p ∧ q, from and.intro (and.right h) (and.left h))\n\n-- ** abreviating iff.elim_ : iff.mp and iff.mpr [#22]\n#check and_swap p q\n\n-- p ∧ q ↔ q ∧ p Because they represent a form of modus\n-- ponens, iff.elim_left and iff.elim_right can be abbreviated iff.mp and\n-- iff.mpr, respectively. In the next example, we use that theorem to derive q ∧\n-- p from p ∧ q:\nvariable h2 : p ∧ q\n\nexample : q ∧ p := iff.mp (and_swap p q) h2\n\n-- THIS NOTATION IS HARD AFF\n\n-- We can use the anonymous constructor notation to construct a proof of p ↔ q\n-- from proofs of the forward and backward directions, and we can also use .\n-- notation with mp and mpr. The previous examples can therefore be written\n-- concisely as follows:\n\ntheorem and_swap_again : p ∧ q ↔ q ∧ p :=\n⟨ λ h, ⟨h.right, h.left⟩, λ h, ⟨h.right, h.left⟩ ⟩\n\nexample (h : p ∧ q) : q ∧ p := (and_swap_again p q).mp h\n\n-- DIGEST THAT ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑\n\n-- * Auxiliary Subgoals: have and suffices [#9]\n\n-- NOW THIS IS FUN\nexample (h : p ∧ q) : q ∧ p :=\n\nhave hp : p, from and.left h, --- DIGEST THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nhave hq : q, from and.right h, --- DIGEST THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\nshow q ∧ p, from and.intro hq hp\n\n\n-- * Classical Logic: the em constructor [#62]\n-- We basically need the excluded middle for lots of normal math. Constructively,\n-- it is not in our toolset. For that we open the classical logic namespace\n\n\n-- I USE THIS SHIT A LOT. WTF VELLEMAN\n\n\n-- The introduction and elimination rules we have seen so far are all\n-- constructive, which is to say, they reflect a computational understanding of\n-- the logical connectives based on the propositions-as-types correspondence.\n-- Ordinary classical logic adds to this the law of the excluded middle, p ∨ ¬p.\n-- To use this principle, you have to open the classical namespace.\n\n\nopen classical\n\n#check em p\n\n-- One consequence of the law of the excluded middle is the principle of\n-- double-negation elimination:\n\ntheorem dne {p : Prop} (h : ¬¬p) : p :=\nor.elim (em p)\n  (assume hp : p, hp)\n  (assume hnp : ¬p, absurd hnp h)\n\n-- Double-negation elimination allows one to prove any proposition, p, by\n-- assuming ¬p and deriving false, because that amounts to proving ¬¬p. In other\n-- words, double-negation elimination allows one to carry out a proof by\n-- contradiction, something which is not generally possible in constructive\n-- logic.\n\n\n-- TRICKy AS FUCK ⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡⇡\n\n-- The classical axioms also give you access to additional patterns of proof\n-- that can be justified by appeal to em. For example, one can carry out a proof\n-- by cases or by contradiction.\n\nexample (h : ¬¬p) : p :=\nby_cases\n  (assume h1 : p, h1)\n  (assume h1 : ¬p, absurd h1 h)\n\nexample (h : ¬¬p) : p :=\nby_contradiction\n  (assume h1 : ¬p,\n    show false, from h h1)\n\n\nexample (h : ¬(p ∧ q)) : ¬p ∨ ¬q :=\nor.elim (em p)\n  (assume hp : p,\n    or.inr\n      (show ¬q, from\n        assume hq : q,\n        h ⟨hp, hq⟩))\n  (assume hp : ¬p,\n    or.inl hp)\n\n\n\n-- * EXERCISES\n-- in the supplemental file\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.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7568690049021971}}
{"text": "/-\nCopyright (c) 2022 Hans Parshall. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hans Parshall\n\n! This file was ported from Lean 3 source module analysis.normed_space.star.matrix\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.Matrix\nimport Mathbin.Analysis.NormedSpace.Basic\nimport Mathbin.Data.IsROrC.Basic\nimport Mathbin.LinearAlgebra.UnitaryGroup\n\n/-!\n# Unitary matrices\n\nThis file collects facts about the unitary matrices over `𝕜` (either `ℝ` or `ℂ`).\n-/\n\n\nopen BigOperators Matrix\n\nvariable {𝕜 m n E : Type _}\n\nsection EntrywiseSupNorm\n\nvariable [IsROrC 𝕜] [Fintype n] [DecidableEq n]\n\ntheorem entry_norm_bound_of_unitary {U : Matrix n n 𝕜} (hU : U ∈ Matrix.unitaryGroup n 𝕜)\n    (i j : n) : ‖U i j‖ ≤ 1 :=\n  by\n  -- The norm squared of an entry is at most the L2 norm of its row.\n  have norm_sum : ‖U i j‖ ^ 2 ≤ ∑ x, ‖U i x‖ ^ 2 :=\n    by\n    apply Multiset.single_le_sum\n    · intro x h_x\n      rw [Multiset.mem_map] at h_x\n      cases' h_x with a h_a\n      rw [← h_a.2]\n      apply sq_nonneg\n    · rw [Multiset.mem_map]\n      use j\n      simp only [eq_self_iff_true, Finset.mem_univ_val, and_self_iff, sq_eq_sq]\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ\n  have diag_eq_norm_sum : (U ⬝ Uᴴ) i i = ∑ x : n, ‖U i x‖ ^ 2 := by\n    simp only [Matrix.mul_apply, Matrix.conjTranspose_apply, ← starRingEnd_apply, IsROrC.mul_conj,\n      IsROrC.normSq_eq_def', IsROrC.of_real_pow]\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ, real part\n  have re_diag_eq_norm_sum : IsROrC.re ((U ⬝ Uᴴ) i i) = ∑ x : n, ‖U i x‖ ^ 2 :=\n    by\n    rw [IsROrC.ext_iff] at diag_eq_norm_sum\n    rw [diag_eq_norm_sum.1]\n    norm_cast\n  -- Since U is unitary, the diagonal entries of U ⬝ Uᴴ are all 1\n  have mul_eq_one : U ⬝ Uᴴ = 1 := unitary.mul_star_self_of_mem hU\n  have diag_eq_one : IsROrC.re ((U ⬝ Uᴴ) i i) = 1 := by\n    simp only [mul_eq_one, eq_self_iff_true, Matrix.one_apply_eq, IsROrC.one_re]\n  -- Putting it all together\n  rw [← sq_le_one_iff (norm_nonneg (U i j)), ← diag_eq_one, re_diag_eq_norm_sum]\n  exact norm_sum\n#align entry_norm_bound_of_unitary entry_norm_bound_of_unitary\n\nattribute [local instance] Matrix.normedAddCommGroup\n\n/-- The entrywise sup norm of a unitary matrix is at most 1. -/\ntheorem entrywise_sup_norm_bound_of_unitary {U : Matrix n n 𝕜} (hU : U ∈ Matrix.unitaryGroup n 𝕜) :\n    ‖U‖ ≤ 1 := by\n  simp_rw [pi_norm_le_iff_of_nonneg zero_le_one]\n  intro i j\n  exact entry_norm_bound_of_unitary hU _ _\n#align entrywise_sup_norm_bound_of_unitary entrywise_sup_norm_bound_of_unitary\n\nend EntrywiseSupNorm\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/Matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.756793667724354}}
{"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ölzl\n-/\nimport algebra.order.group.abs\nimport algebra.order.monoid.min_max\n\n/-!\n# `min` and `max` in 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\nsection\nvariables {α : Type*} [group α] [linear_order α] [covariant_class α α (*) (≤)]\n\n@[simp, to_additive] lemma max_one_div_max_inv_one_eq_self (a : α) :\n  max a 1 / max a⁻¹ 1 = a :=\nby { rcases le_total a 1 with h|h; simp [h] }\n\nalias max_zero_sub_max_neg_zero_eq_self ← max_zero_sub_eq_self\n\nend\n\nsection linear_ordered_comm_group\nvariables {α : Type*} [linear_ordered_comm_group α] {a b c : α}\n\n@[to_additive min_neg_neg]\nlemma min_inv_inv' (a b : α) : min (a⁻¹) (b⁻¹) = (max a b)⁻¹ :=\neq.symm $ @monotone.map_max α αᵒᵈ _ _ has_inv.inv a b $ λ a b, inv_le_inv_iff.mpr\n\n@[to_additive max_neg_neg]\nlemma max_inv_inv' (a b : α) : max (a⁻¹) (b⁻¹) = (min a b)⁻¹ :=\neq.symm $ @monotone.map_min α αᵒᵈ _ _ has_inv.inv a b $ λ a b, inv_le_inv_iff.mpr\n\n@[to_additive min_sub_sub_right]\nlemma min_div_div_right' (a b c : α) : min (a / c) (b / c) = min a b / c :=\nby simpa only [div_eq_mul_inv] using min_mul_mul_right a b (c⁻¹)\n\n@[to_additive max_sub_sub_right]\nlemma max_div_div_right' (a b c : α) : max (a / c) (b / c) = max a b / c :=\nby simpa only [div_eq_mul_inv] using max_mul_mul_right a b (c⁻¹)\n\n@[to_additive min_sub_sub_left]\nlemma min_div_div_left' (a b c : α) : 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 : α) : max (a / b) (a / c) = a / min b c :=\nby simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']\n\nend linear_ordered_comm_group\n\nsection linear_ordered_add_comm_group\nvariables {α : Type*} [linear_ordered_add_comm_group α] {a b c : α}\n\nlemma max_sub_max_le_max (a b c d : α) : max a b - max c d ≤ 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  ... ≤ 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  ... ≤ 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 : α) : |max a b - max c d| ≤ max (|a - c|) (|b - d|) :=\nbegin\n  refine abs_sub_le_iff.2 ⟨_, _⟩,\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 : α) : |min a b - min c d| ≤ 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 : α) : |max a c - max b c| ≤ |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\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/min_max.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7567936625169815}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl\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 σ R m`: the subspace of multivariate polynomials indexed by `σ` over the\n  commutative ring `R` of total degree at most `m`.\n* `restrict_degree σ R m`: the subspace of multivariate polynomials indexed by `σ` 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 (σ : Type u) (R : Type v) [comm_ring R] (p m : ℕ)\n\nnamespace mv_polynomial\n\nsection char_p\n\ninstance [char_p R p] : char_p (mv_polynomial σ R) p :=\n{ cast_eq_zero_iff := λ n, by rw [← C_eq_coe_nat, ← 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 σ R)\n  (f : R →+* S) :\n  finsupp.map_range f f.map_zero p = map f p :=\nbegin\n  -- `finsupp.map_range_finset_sum` expects `f : R →+ S`\n  change finsupp.map_range (f : R →+ S) (f : R →+ 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, ← 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 σ R) :=\nfinsupp.supported _ _ {n | n.sum (λn e, e) ≤ 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 : ℕ) : submodule R (mv_polynomial σ R) :=\nfinsupp.supported _ _ {n | ∀i, n i ≤ m }\n\nvariable {R}\n\nlemma mem_restrict_total_degree (p : mv_polynomial σ R) :\n  p ∈ restrict_total_degree σ R m ↔ p.total_degree ≤ m :=\nbegin\n  rw [total_degree, finset.sup_le_iff],\n  refl\nend\n\nlemma mem_restrict_degree (p : mv_polynomial σ R) (n : ℕ) :\n  p ∈ restrict_degree σ R n ↔ (∀s ∈ p.support, ∀i, (s : σ →₀ ℕ) i ≤ n) :=\nbegin\n  rw [restrict_degree, finsupp.mem_supported],\n  refl\nend\n\nlemma mem_restrict_degree_iff_sup (p : mv_polynomial σ R) (n : ℕ) :\n  p ∈ restrict_degree σ R n ↔ ∀i, p.degrees.count i ≤ n :=\nbegin\n  simp only [mem_restrict_degree, degrees, multiset.count_finset_sup, finsupp.count_to_multiset,\n    finset.sup_le_iff],\n  exact ⟨assume h n s hs, h s hs n, assume h s hs n, h n s hs⟩\nend\n\nvariables (σ R)\n\n/-- The monomials form a basis on `mv_polynomial σ R`. -/\ndef basis_monomials : basis (σ →₀ ℕ) R (mv_polynomial σ R) := finsupp.basis_single_one\n\n@[simp] lemma coe_basis_monomials :\n  (basis_monomials σ R : (σ →₀ ℕ) → mv_polynomial σ R) = λ s, monomial s 1 :=\nrfl\n\nlemma linear_independent_X : linear_independent R (X : σ → mv_polynomial σ R) :=\n(basis_monomials σ R).linear_independent.comp\n  (λ s : σ, 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 ℕ R R[X] :=\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 : ℕ → R[X]) = λ s, monomial s 1 :=\n_root_.funext $ λ n, of_finsupp_single _ _\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/ring_theory/mv_polynomial/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7567936604859}}
{"text": "import data.real.basic\n\nvariables (f : ℝ → ℝ) (a b : ℝ)\n\n#check @lt_of_not_ge\n#check @not_lt_of_gt\n\n-- BEGIN\nexample (h : monotone f) (h' : f a < f b) : a < b :=\nbegin\n  apply lt_of_not_ge,\n  intro hab,\n  have : f a ≥ f b,\n    from h hab, \n  apply not_lt_of_ge this,\n  exact h', \nend\n\nexample (h : a ≤ b) (h' : f b < f a) : ¬ monotone f :=\nbegin\n  intro fmono,\n  have : f a ≤ f b,\n   from fmono h,\n  apply not_lt_of_ge this,\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.1_apply/ex14_apply_monof.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.756793657568946}}
{"text": "import MyNat.Addition\nimport MyNat.Multiplication\nimport MultiplicationWorld.Level5\nimport MultiplicationWorld.Level8\nnamespace MyNat\nopen MyNat\n\n/-!\n# Multiplication World\n\n## Level 9: `mul_left_comm`\n\nYou are equipped with\n\n* `mul_assoc (a b c : MyNat) : (a * b) * c = a * (b * c)`\n* `mul_comm (a b : MyNat) : a * b = b * a`\n\nRe-read the docs for `rw` so you know all the tricks.\nYou can see them in the [Tactics section](../Tactics.lean.md) on the left.\n\n## Lemma\nFor all natural numbers `a` `b` and `c`, we have `a(bc) = b(ac)`\n-/\nlemma mul_left_comm (a b c : MyNat) : a * (b * c) = b * (a * c) := by\n  rw [←mul_assoc]\n  rw [mul_comm a]\n  rw [mul_assoc]\n\n\n/-!\nAnd now you can teach the `simp` tactic these new tricks:\n-/\nattribute [simp] mul_assoc mul_comm mul_left_comm\n/-!\nand all of a sudden Lean can automatically do levels which are\nvery boring for a human, for example:\n-/\nexample (a b c d e : MyNat) :\n  (((a*b)*c)*d)*e=(c*((b*e)*a))*d := by\n  simp\n\n/-!\nIf you feel like attempting Advanced Multiplication world\nyou'll have to do [Function World](../FunctionWorld.lean.md) and the Proposition Worlds first.\nThese worlds assume a certain amount of mathematical maturity\n(perhaps 1st year undergraduate level).\n\nYour other possibility is [Power World](../PowerWorld.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/MultiplicationWorld/Level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9572777987970316, "lm_q2_score": 0.7905303162021596, "lm_q1q2_score": 0.7567571209763247}}
{"text": "/-\nCopyright (c) 2022 Frédéric Dupuis. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Frédéric Dupuis\n-/\n\nimport analysis.normed_space.star.basic\nimport algebra.star.module\nimport analysis.complex.basic\n\n/-!\n# Complex normed star modules and algebras\n\nFacts about star modules and star algebras over the complex numbers.\n\n## Main definitions\n\n* `star_module.mul_neg_I_lin`: multiplication by -I as a real-linear equivalence between the\n  skew-adjoint and self-adjoint elements of a star module.\n* `star_module.im`: the imaginary part of an element of a star module, defined via\n  `skew_adjoint_part`.\n\n-/\n\nvariables {E : Type*}\n\nnamespace star_module\nopen_locale complex_conjugate\nopen complex\n\nvariables [add_comm_group E] [star_add_monoid E] [module ℂ E] [star_module ℂ E]\n\n/-- Multiplication by -I as a real-linear equivalence between the skew-adjoint and self-adjoint\nelements of a star module. -/\n@[simps] def mul_neg_I_lin : skew_adjoint E ≃ₗ[ℝ] self_adjoint E :=\n{ to_fun := λ x, ⟨-I • x, by simp [self_adjoint.mem_iff]⟩,\n  inv_fun := λ x, ⟨I • x, by simp [skew_adjoint.mem_iff]⟩,\n  map_add' := λ x y, by { ext, simp only [add_subgroup.coe_add, smul_add, add_subgroup.coe_mk] },\n  map_smul' := λ r x, by { ext, simp only [neg_smul, neg_inj, skew_adjoint.coe_smul,\n    add_subgroup.coe_mk, ring_hom.id_apply, self_adjoint.coe_smul, smul_neg, smul_comm I], },\n  left_inv := λ x, by simp only [neg_smul, add_subgroup.coe_mk, smul_neg, ←mul_smul, I_mul_I,\n                                 neg_neg, one_smul, set_like.eta],\n  right_inv := λ x, by simp only [←mul_smul, I_mul_I, add_subgroup.coe_mk, neg_mul, neg_neg,\n                                  one_smul, set_like.eta] }\n\n/-- The imaginary part of an element of a star module, as a real-linear map.  -/\n@[simps] noncomputable def im : E →ₗ[ℝ] self_adjoint E :=\n  mul_neg_I_lin.to_linear_map.comp (skew_adjoint_part ℝ)\n\n/-- The real part of an element of a star module, as a real-linear map. This is simply an\nabbreviation for `self_adjoint_part ℝ`. -/\n@[simps] noncomputable abbreviation re : E →ₗ[ℝ] self_adjoint E := self_adjoint_part ℝ\n\n/-- An element of a complex star module can be decomposed into self-adjoint \"real\" and\n\"imaginary\" parts -/\nlemma re_add_im (x : E) : (re x : E) + I • im x = x :=\nby simp [←mul_smul, I_mul_I, ←smul_add, ←two_smul ℝ]\n\nend star_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/analysis/normed_space/star/complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652497, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7567244467214375}}
{"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.sheet02noetherian\n\n/-!\n\n# An auxiliary construction\n\nI haven't talked about which proof of the Hilbert Basis Theorem we'll\nbe formalising, so let me say a bit about this here. The theorem\nstates that if `R` is a Noetherian (commutative) ring then so is\nthe polynomial ring `R[X]`. So, given an ideal `I` of `R[X]` we need\nto come up with a finite set of generators, and the only tool we have\nis that any ideal of `R` has a finite set of generators. So, however\nthis proof goes, we are going to probably be wanting to construct\nideals of `R` given an ideal of `R[X]`. \n\nThe `aux_ideal` construction is of this nature. An ideal of `R[X]`\nis by definition an `R[X]`-submodule of `R[X]` so it's also\nan `R`-submodule of `R[X]` (this is a bit like saying that a complex\nvector space is obviously also a real vector space). The `lcoeff`\nmaps, taking a polynomial to its coefficient of `X^n`,  are `R`-linear\nmaps from `R[X]` to `R`, so we can push `R`-submodules of `R[X]` along\nthese maps (i.e. look at their images) to get `R`-submodules of `R`,\nwhich is the same thing as ideals of `R`. The submodules we will push\nforward are the following: given an ideal `I` of `R[X]`, and a natural\nnumber `n`, we will consider `I` as an `R`-submodule of `R[X]`, we will\nintersect it with `M R n` (the `R`-submodule of polynomials of degree\nat most `n`), and we will then look at its image under `lcoeff R n`.\nBy definition then, the elements of `aux_ideal I n` will be the\ncoeficients of `X^n` of the polynomials in `I` which have degree\nat most `n`, and this abstract way of describing this set shows that\nit is an ideal of `R`.\n\nAgain, more briefly: if `I` is an ideal of `R[X]` and `n` is a natural,\nthen `aux_ideal I n` is the ideal of `R` consisting of the coefficients\nof `X^n` of the elements of `I` with `nat_degree` at most `n`. \n\nThe first result we are aiming for in this file is that\n`aux_ideal I n` is monotone as a function of `n`, that is, if `n ≤ m`\nthen `aux_ideal I n ≤ aux_ideal I m`.\n\n-/\n\nvariables {R : Type} [comm_ring R] (I : ideal (polynomial R))\n\nopen polynomial\n\n/-\n\n`I.restrict_scalars R` means the ideal `I`, regarded as an `R`-submodule\nof `R[X]`. The `⊓` is just intersection of submodules. The `map`\nis `submodule.map` which is the function which eats a linear map\n(in this case `lcoeff R n`) and outputs a function sending submodules\nof the domain of the map to submodules of the codomain; the function\nitself is just \"image of the submodule under the linear map\".\n\n-/\n\n/-- If `I` is an ideal of `polynomial R` then `aux_ideal I n` is the ideal of `R`\nobtained by pushing forward `I ∩ {polynomials of degree ≤ n}` along the linear map `lcoeff n`\nsending a polynomial to its coefficient of `X^n`. \n\nOne can imagine `aux_ideal I n` as the ideal consisting of `0` and the coefficient of `X^n`\nin all of the degree `n` polynomials in `I`, but this case split definition is harder\nto work with in practice. -/\nnoncomputable def aux_ideal (n : ℕ) :=\n(I.restrict_scalars R ⊓ M R n).map (lcoeff R n)\n\nnamespace aux_ideal\n\n/-\n\nWe're going to prove that `aux_ideal I n` is monotone for fixed `I`, i.e. it gets \nbigger as `n` gets bigger. \n\nMake sure you know a maths proof before embarking on this.\n\nUseful API: \n\n`I.mul_mem_right r : p ∈ I → p * r ∈ I`\n`polynomial.nat_degree_mul_le : (p * q).nat_degree ≤ p.nat_degree + q.nat_degree`\n`p.coeff_mul_X : (n : ℕ), (p * X).coeff (n + 1) = p.coeff n`\n\nand note that `lcoeff R n f` is definitionally `f.coeff n`.\n\n-/\n\nlemma mono_aux (n : ℕ) :\n  aux_ideal I n ≤ aux_ideal I (n + 1) :=\nbegin\n  rintro r ⟨p, ⟨(hp1 : p ∈ I), (hp2 : p.nat_degree ≤ n)⟩, rfl⟩,\n  refine ⟨p * X, ⟨I.mul_mem_right X hp1, _⟩, _⟩,\n  { -- change (p * X).nat_degree ≤ _,\n    refine le_trans (nat_degree_mul_le) _,\n    refine add_le_add hp2 _,\n    exact nat_degree_X_le }, \n  { apply p.coeff_mul_X },\nend\n\n-- this is now a one-liner\nlemma mono : monotone (aux_ideal I) := monotone_nat_of_le_succ (mono_aux _)\n\n/- Given an ideal `I` and a natural number `n`, we have been\nconsidering the map from `I ∩ {degree ≤ n}` to `R` defined by\n\"take coefficient of `X^n`\". The `lift` function below is\na one-sided inverse to this map. Given an element of `R`,\nif it's in the image then we send it to a random preimage\nin `I ∩ (degree ≤ n)` and if it's not then we just send it to 0.\nNote the use of `exists.some`; the statement \"I am in the image\"\nis definitionally equal to \"there exists something in the domain\nwhich maps to me\", and `exists.some` chooses a random thing in the\nimage with this property.\n\n-/\n\nnoncomputable def lift (n : ℕ) (r : R) [decidable (r ∈ aux_ideal I n)] : polynomial R :=\nif hr : r ∈ aux_ideal I n then (submodule.mem_map.1 hr).some else 0\n\nvariables {n : ℕ} {r : R} [decidable (r ∈ aux_ideal I n)]\n\nlemma lift_def (n : ℕ) (r : R) [decidable (r ∈ aux_ideal I n)] : \nlift I n r = if hr : r ∈ aux_ideal I n then (submodule.mem_map.1 hr).some else 0 :=\nbegin\n  refl,\nend\n\nvariable {I}\n\n-- you can use `dif_neg` to prove this lemma.\nlemma lift_eq_zero_of_ne (hr : ¬ r ∈ aux_ideal I n) : lift I n r = 0 :=\nbegin\n--  rw lift_def,\n  exact dif_neg hr,\nend\n\n-- you need to do a case split for this one. The definition of `lift`\n-- used ` (submodule.mem_map.1 hr).some` so this proof will need\n-- ` (submodule.mem_map.1 hr).some_spec` somewhere. Note also `dif_pos` :-)\nlemma lift_mem :\n  (lift I n r) ∈ submodule.restrict_scalars R I ⊓ M R n :=\nbegin\n  rw lift_def,\n  split_ifs with hr,\n  { have := (submodule.mem_map.1 hr).some_spec, -- never used `⇑(lcoeff R n) _.some = r`\n    exact this.1 },\n  { apply submodule.zero_mem },\nend\n\n-- this is a one-liner\nlemma lift_mem_I : lift I n r ∈ I :=\nbegin\n  exact lift_mem.1,\nend\n\n-- this is a one-liner too (thanks to definitional equality abuse)\nlemma lift_nat_degree_le :\n  (lift I n r).nat_degree ≤ n :=\nbegin\n  exact lift_mem.2,\nend\n\nlemma lift_spec (hr : r ∈ aux_ideal I n) :\n  lcoeff R n (lift I n r) = r :=\nbegin\n  rw lift_def,\n  rw dif_pos hr,\n  have := (submodule.mem_map.1 hr).some_spec, -- used it now\n  exact this.2,\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/sheet03aux_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.756724420034683}}
{"text": "import Aesop\n\n/-!\nSource: https://github.com/IPDSnelting/tba-2022/blob/master/TBA/AesopSort.lean\n-/\n\n\nvariable [LE α] [DecidableRel ((· ≤ ·) : α → α → Prop)]\n\n@[aesop safe constructors]\ninductive Sorted : List α → Prop where\n  | nil : Sorted []\n  | single : Sorted [x]\n  | cons_cons : x ≤ x' → Sorted (x' :: xs) → Sorted (x :: x' :: xs)\n\n@[simp] def insertInOrder (a : α) : List α → List α\n  | [] => [a]\n  | x :: xs =>\n    if a ≤ x then\n      a :: x :: xs\n    else\n      x :: insertInOrder a xs\n\n@[simp] def insertionSort : List α → List α\n  | []      => []\n  | x :: xs => insertInOrder x (insertionSort xs)\n\nvariable (antisymm : ∀ {x y : α}, ¬ (x ≤ y) → y ≤ x)\n\ntheorem sorted_insertInOrder {xs : List α} (h : Sorted xs) : Sorted (insertInOrder x xs) := by\n  induction h <;> aesop\n\ntheorem sorted_insertionSort {xs : List α} : Sorted (insertionSort xs) := by\n  induction xs <;> aesop (add safe sorted_insertInOrder)\n\ninductive Perm : List α → List α → Prop where\n  | nil : Perm [] []\n  | cons : Perm xs xs' → Perm (x :: xs) (x :: xs')\n  | swap : Perm (x :: y :: xs) (y :: x :: xs)\n  | trans : Perm xs ys → Perm ys zs → 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 → Perm ys xs := by\n  intro h\n  induction h <;> aesop\n\n@[aesop safe]\ntheorem perm_insertInOrder {xs : List α} : Perm (x :: xs) (insertInOrder x xs) := by\n  induction xs <;> aesop\n\ntheorem perm_insertionSort {xs : List α} : 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      · exact Perm.cons perm_insertInOrder\n      · apply Perm.trans (ys := x :: insertionSort (x' :: xs))\n        · aesop (add safe Perm.cons, unsafe [cases List, Perm.symm])\n        · aesop\n\ndef IsSortingAlgorithm (f : List α → List α) := ∀ xs, Perm xs (f xs) ∧ Sorted (f xs)\n\ntheorem isSortingAlgorithm_insertionSort : IsSortingAlgorithm (insertionSort (α := α)) :=\n  fun _xs => ⟨perm_insertionSort, sorted_insertionSort @antisymm⟩\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/notes/AesopDemo/AesopSort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.84997116805678, "lm_q1q2_score": 0.756724418342947}}
{"text": "import algebra.parity\n\ntheorem even_times_self_is_even {n : ℕ} : -- n is a natural number\n  (even n) → even (n ^ 2) := -- if n is even, then n ^ 2 is even\nbegin\n  intro p, \n  -- assume that n is even\n\n\n  rw even at *,\n  -- rewrite the definition of \"even\"\n\n\n  cases p with r h,\n  -- since p is a hypothesis,\n  --assume such a number r exists\n\n\n\n  use (r ^ 2 + r ^ 2),\n  -- we need to find a number m\n  -- such that n ^ 2 = m + m\n  -- (definition of \"even\")\n  -- let's use 2 r ^ 2\n\n\n\n  rw h,\n  -- replace n by r + r\n\n\n\n  ring, -- simplify algebra\nend\n\n\n\n", "meta": {"author": "mikesha2", "repo": "identitylib", "sha": "6fb9c7913b0b85fafb14f1f34bca0f7af47fa190", "save_path": "github-repos/lean/mikesha2-identitylib", "path": "github-repos/lean/mikesha2-identitylib/identitylib-6fb9c7913b0b85fafb14f1f34bca0f7af47fa190/src/square_root_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947101574298, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7566497019516594}}
{"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.quaternion\nimport analysis.normed_space.inner_product\n\n/-!\n# Quaternions as a normed algebra\n\nIn this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions:\n\n* inner product space;\n* normed ring;\n* normed space over `ℝ`.\n\n## Notation\n\nThe following notation is available with `open_locale quaternion`:\n\n* `ℍ` : quaternions\n\n## Tags\n\nquaternion, normed ring, normed space, normed algebra\n-/\n\nlocalized \"notation `ℍ` := quaternion ℝ\" in quaternion\nopen_locale real_inner_product_space\n\nnoncomputable theory\n\nnamespace quaternion\n\ninstance : has_inner ℝ ℍ := ⟨λ a b, (a * b.conj).re⟩\n\nlemma inner_self (a : ℍ) : ⟪a, a⟫ = norm_sq a := rfl\n\nlemma inner_def (a b : ℍ) : ⟪a, b⟫ = (a * b.conj).re := rfl\n\ninstance : inner_product_space ℝ ℍ :=\ninner_product_space.of_core\n{ inner := has_inner.inner,\n  conj_sym := λ x y, by simp [inner_def, mul_comm],\n  nonneg_re := λ x, norm_sq_nonneg,\n  definite := λ x, norm_sq_eq_zero.1,\n  add_left := λ x y z, by simp only [inner_def, add_mul, add_re],\n  smul_left := λ x y r, by simp [inner_def] }\n\nlemma norm_sq_eq_norm_sq (a : ℍ) : norm_sq a = ∥a∥ * ∥a∥ :=\nby rw [← inner_self, real_inner_self_eq_norm_sq]\n\ninstance : norm_one_class ℍ :=\n⟨by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]⟩\n\n@[simp] lemma norm_mul (a b : ℍ) : ∥a * b∥ = ∥a∥ * ∥b∥ :=\nbegin\n  simp only [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_mul],\n  exact real.sqrt_mul norm_sq_nonneg _\nend\n\n@[simp, norm_cast] lemma norm_coe (a : ℝ) : ∥(a : ℍ)∥ = ∥a∥ :=\nby rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_coe, real.sqrt_sq_eq_abs, real.norm_eq_abs]\n\nnoncomputable instance : normed_ring ℍ :=\n{ dist_eq := λ _ _, rfl,\n  norm_mul := λ a b, (norm_mul a b).le }\n\nnoncomputable instance : normed_algebra ℝ ℍ :=\n{ norm_algebra_map_eq := norm_coe,\n  to_algebra := quaternion.algebra }\n\ninstance : has_coe ℂ ℍ := ⟨λ z, ⟨z.re, z.im, 0, 0⟩⟩\n\n@[simp, norm_cast] \n\n@[simp, norm_cast] lemma coe_complex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_zero : ((0 : ℂ) : ℍ) = 0 := rfl\n@[simp, norm_cast] lemma coe_complex_one : ((1 : ℂ) : ℍ) = 1 := rfl\n@[simp, norm_cast] lemma coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z :=\nby ext; simp\n@[simp, norm_cast] lemma coe_complex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl\n\n/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/\ndef of_complex : ℂ →ₐ[ℝ] ℍ :=\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' := λ x, rfl }\n\n@[simp] lemma coe_of_complex : ⇑of_complex = coe := rfl\n\nend quaternion\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/quaternion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7566172719827026}}
{"text": "/- LoVe Exercise 4: Functional Programming -/\n\nimport .love04_functional_programming_demo\n\nnamespace LoVe\n\n\n/- Question 1: Reverse of a List -/\n\n/- We define a new accumulator-based version of `reverse`. The first argument\nserves as the accumulator. This definition is _tail-recursive_, meaning that\ncompilers and interpreters can easily optimize the recursion away, resulting in\nmore efficient code. -/\n\ndef areverse {α : Type} : list α → list α → list α\n| ys []        := ys\n| ys (x :: xs) := areverse (x :: ys) xs\n\n/- 1.1. Our intention is that `areverse [] 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 pattern\nmatching or the `induction` tactic): -/\n\nlemma areverse_eq_reverse_append {α : Type} :\n  ∀ys xs : list α, areverse ys xs = reverse xs ++ ys\n| ys []        := by refl\n| ys (x :: xs) := by simp [reverse, areverse, areverse_eq_reverse_append _ xs]\n\n/- 1.2. Derive the desired equation. -/\n\nlemma areverse_eq_reverse {α : Type} (xs : list α) :\n  areverse [] xs = reverse xs :=\nby simp [areverse_eq_reverse_append]\n\n/- 1.3. Prove the following property. Hint: A one-line inductionless proof is\n possible. -/\n\nlemma areverse_areverse {α : Type} (xs : list α) :\n  areverse [] (areverse [] xs) = xs :=\nby simp [areverse_eq_reverse, reverse_reverse]\n\n\n/- Question 2: Drop and Take -/\n\n/- The `drop` function removes the first `n` elements from the front of a\nlist. -/\n\ndef drop {α : Type} : ℕ → list α → list α\n| 0       xs        := xs\n| (_ + 1) []        := []\n| (m + 1) (x :: xs) := drop m xs\n\n/- Its relative `take` returns a list consisting of the the first `n` elements\nat the front of a list. -/\n\n/- 2.1. Define `take`. -/\n\n/- To avoid unpleasant surprises in the proofs, we recommend that you follow the\nsame recursion pattern as for `drop` above. -/\n\ndef take {α : Type} : ℕ → list α → list α\n| 0       _         := []\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-- when `#reduce` fails for some obscure reason, try `#eval`:\n#eval take 2 [\"a\", \"b\", \"c\"]   -- expected: [\"a\", \"b\"]\n\n/- 2.2. Prove the following lemmas. Notice that they are registered as\nsimplification rules thanks to the `@[simp]` attribute. -/\n\n@[simp] lemma drop_nil {α : Type} :\n  ∀n : ℕ, drop n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\n\n@[simp] lemma take_nil {α : Type} :\n  ∀n : ℕ, take n ([] : list α) = []\n| 0       := by refl\n| (_ + 1) := by refl\n\n/- 2.3. Follow the recursion pattern of `drop` and `take` to prove the following\nlemmas. In other words, for each lemma, there should be three cases, and the\nthird case will need to invoke the induction hypothesis.\n\nThe first case is shown for `drop_drop`. Beware of the fact that there are three\nvariables in the `drop_drop` lemma (but only two arguments to `drop`).\n\nHint: The `refl` tactic might be useful in the third case of `drop_drop`. -/\n\nlemma drop_drop {α : Type} :\n  ∀(m n : ℕ) (xs : list α), drop n (drop m xs) = drop (n + m) xs\n| 0       n xs        := by refl\n| (_ + 1) _ []        := by simp [drop]\n| (m + 1) n (x :: xs) :=\n  begin\n    simp [drop, drop_drop m n xs],\n    refl\n  end\n\nlemma take_take {α : Type} :\n  ∀(m : ℕ) (xs : list α), 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 {α : Type} :\n  ∀(n : ℕ) (xs : list α), 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/- Question 3: λ-Terms -/\n\n/- 3.1. Define an inductive type corresponding to the untyled λ-terms, as given\nby the following context-free grammar:\n\n<lam> ::= 'var' <string>\n        | 'abs' <string> <lam>\n        | 'app' <lam> <lam> -/\n\ninductive lam : Type\n| var : string → lam\n| abs : string → lam → lam\n| app : lam → lam → lam\n\nexport lam (var abs app)\n\n/- 3.2. Register a textual representation of the type `lam`. Make sure to supply\nenough parentheses to guarantee that the output is unambiguous. -/\n\ndef lam.repr : lam → string\n| (var s)   := s\n| (abs s t) := \"(λ\" ++ s ++ \", \" ++ lam.repr t ++ \")\"\n| (app t u) := \"(\" ++ lam.repr t ++ \" \" ++ lam.repr u ++ \")\"\n\ninstance : has_repr lam :=\n⟨lam.repr⟩\n\n\n/- Question 4 (**optional**): Concatenation -/\n\n/- Consider the following Lean definition of 2–3 trees as an inductive type: -/\n\ninductive tttree (α : Type) : Type\n| empty {} : tttree\n| bin      : α → tttree → tttree → tttree\n| ter      : α → tttree → tttree → tttree → tttree\n\nexport tttree (empty bin ter)\n\n/- 4.1 (**optional**). Complete the following Lean definition. The `map_tree`\nfunction should apply its argument `f` to all values of type α stored in the\ntree and otherwise preserve the tree's structure. -/\n\ndef map_tttree {α β : Type} (f : α → β) : tttree α → tttree β\n| empty         := empty\n| (bin a l r)   := bin (f a) (map_tttree l) (map_tttree r)\n| (ter a l m r) := ter (f a) (map_tttree l) (map_tttree m) (map_tttree r)\n\n/- 4.2 (**optional**). Prove the following lemma about your definition of\n`map_tree`. -/\n\nlemma map_tttree_id {α : Type} :\n  ∀t : tttree α, map_tttree (λx : α, x) t = t\n| empty         := by refl\n| (bin a l r)   := by simp [map_tttree, map_tttree_id l, map_tttree_id r]\n| (ter a l m r) :=\n  by simp [map_tttree, map_tttree_id l, map_tttree_id m, map_tttree_id r]\n\n/- 4.3 (**optional**). Complete the following Lean definition. The `set_tree`\nfunction should return the set of all values of type α stored in the tree. In\nyour answer, you may use traditional set notations regardless of whether they\nare actually supported by Lean. -/\n\ndef set_tttree {α : Type} : tttree α → set α\n| empty         := ∅\n| (bin a l r)   := insert a (set_tttree l ∪ set_tttree r)\n| (ter a l m r) := insert a (set_tttree l ∪ set_tttree m ∪ set_tttree r)\n\n/- A _congruence rule_ is a lemma that can be used to lift an equivalence\nrelation between terms to the same terms occurring under a common context.\nCongruence rules for equality are built into Lean's logic. In the following\nexample, the equivalence relation is `=`, the terms are `f` and `g`, and the\ncontext is `map_tree … t`: -/\n\nlemma map_tttree_congr_weak {α β : Type} (f g : α → β) (f = g) (t : tttree α) :\n  map_tttree f t = map_tttree g t :=\nby simp *\n\n/- 4.4 (**optional**). The above rule is not as flexible as it could be,\nbecause it requires `f = g`. As long as `f` and `g` are equal for all values\n`x : α` stored in `t`, we have `map_tree f t = map_tree g t`, even if `f` and\n`g` disagree on other `α` values. Inspired by this observation, prove the\nfollowing stronger congruence rule. -/\n\nlemma map_tttree_congr_strong {α β : Type} (f g : α → β) :\n  ∀t : tttree α, (∀x, x ∈ set_tttree t → f x = g x) →\n  map_tttree f t = map_tttree g t\n| empty         := by intros; refl\n| (bin a l r)   :=\n  begin\n    intros,\n    simp [map_tttree],\n    apply and.intro,\n    { apply a_1,\n      simp [set_tttree] },\n    apply and.intro,\n    { apply map_tttree_congr_strong,\n      intros,\n      apply a_1,\n      simp [set_tttree],\n      cc },\n    { apply map_tttree_congr_strong,\n      intros,\n      apply a_1,\n      simp [set_tttree],\n      cc },\n  end\n| (ter a l m r)   :=\n  begin\n    intros,\n    simp [map_tttree],\n    apply and.intro,\n    { apply a_1,\n      simp [set_tttree] },\n    apply and.intro,\n    { apply map_tttree_congr_strong,\n      intros,\n      apply a_1,\n      simp [set_tttree],\n      cc },\n    apply and.intro,\n    { apply map_tttree_congr_strong,\n      intros,\n      apply a_1,\n      simp [set_tttree],\n      cc },\n    { apply map_tttree_congr_strong,\n      intros,\n      apply a_1,\n      simp [set_tttree],\n      cc }\n  end\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/love04_functional_programming_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7566172668403177}}
{"text": "-- finset ℕ machinery for use in sums and products\n\nimport data.complex.basic\nimport data.finset.basic\nimport data.stream.defs\nimport order.filter.at_top_bot\nopen filter (at_top)\nopen_locale topological_space\n\n-- Insert 0, adding 1 to existing elements\ndef push (N : finset ℕ) := insert 0 (finset.image (λ n, n + 1) N)\n\n-- Subtract 1 from everything, discarding zero (left inverse of push)\ndef pop (N : finset ℕ) := finset.image (λ n, n - 1) (finset.erase N 0)\n\n-- push almost cancels pop\nlemma push_pop {N : finset ℕ} : push (pop N) = insert 0 N := begin\n  rw [push, pop], apply finset.ext, simp,\n  intro n, by_cases n0 : n = 0, { rw n0, simp },\n  simp_rw or_iff_right n0,\n  constructor, {\n    intro h, rcases h with ⟨x,hx⟩,\n    have c := nat.sub_add_cancel (nat.one_le_iff_ne_zero.mpr hx.left.left),\n    rw c at hx, finish\n  }, {\n    intro h, existsi n,\n    rw nat.sub_add_cancel (nat.one_le_iff_ne_zero.mpr n0),\n    finish\n  }\nend\n\n-- push is monotone\nlemma push_le_push {A B : finset ℕ} : push A ≤ push B ↔ A ≤ B := begin\n  simp, rw push, rw push, \n  constructor, {\n    intro AB, rw finset.subset_iff at ⊢ AB, intros x xA,\n    have h : x+1 ∈ insert 0 (finset.image (λ (n : ℕ), n + 1) A) := by simpa,\n    specialize AB h, simp at AB, assumption\n  }, {\n    intro AB, apply finset.insert_subset_insert, apply finset.image_mono, assumption\n  }\nend\n\n-- push and products interact nicely\nlemma push_prod {a : ℂ} {f : ℕ → ℂ} {N : finset ℕ} : a * N.prod f = (push N).prod (a::f) :=\n  by { rw push, simp, refl }\n\n-- The range of push is finsets containing 0\nlemma push_range : set.range push = {N : finset ℕ | 0 ∈ N} := begin\n  rw set.range, apply set.ext, simp, intro N, constructor, {\n    intro h, rcases h with ⟨M,H⟩, rw push at H, rw ←H, exact finset.mem_insert_self 0 _\n  }, {\n    intro N0, existsi pop N, rw push_pop, exact finset.insert_eq_of_mem N0\n  }\nend\n\nlemma push_comap_at_top : filter.comap push at_top = at_top := begin\n  apply filter.comap_embedding_at_top,\n  exact @push_le_push,\n  intro N, existsi pop N, rw push_pop, simp, exact finset.subset_insert _ _\nend\n\n-- f ∘ push converges at_top iff f does\nlemma tendsto_comp_push {A : Type} {f : finset ℕ → A} {l : filter A}\n    : filter.tendsto (f ∘ push) at_top l ↔ filter.tendsto f at_top l := begin\n  nth_rewrite 0 ←push_comap_at_top, apply filter.tendsto_comap'_iff,\n  rw push_range,\n  have h : {N : finset ℕ | 0 ∈ N} = {N : finset ℕ | {0} ≤ N} := by simp,\n  rw h, exact filter.mem_at_top _\nend", "meta": {"author": "girving", "repo": "ray", "sha": "e0c501756e067711e2d3667d4b1d18045d83a313", "save_path": "github-repos/lean/girving-ray", "path": "github-repos/lean/girving-ray/ray-e0c501756e067711e2d3667d4b1d18045d83a313/src/finset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7566172610796311}}
{"text": "open tactic\n\nvariables {α : Type*}\n\n-- TODO: write a tactic to unfold specific instances of generic notation?\ntheorem subset_def {s t : set α} : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl\ntheorem union_def {s₁ s₂ : set α} : s₁ ∪ s₂ = {a | a ∈ s₁ ∨ a ∈ s₂} := rfl\ntheorem inter_def {s₁ s₂ : set α} : s₁ ∩ s₂ = {a | a ∈ s₁ ∧ a ∈ s₂} := rfl\n\ntheorem union_subset {s t r : set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r :=\nbegin\n  dsimp [subset_def, union_def] at *,\n  intros x h,\n  cases h; back_chaining_using_hs\nend\n\ntheorem subset_inter {s t r : set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t :=\nbegin\n  dsimp [subset_def, inter_def] at *,\n  intros x h,\n  split; back_chaining_using_hs\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/back_chaining.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8376199572530449, "lm_q1q2_score": 0.7566172526256116}}
{"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 ⊆ ℘(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 ∈ X with S1 ≠ S2, we have that S1 ∩ S2 = Ø (S1 and S2 are disjoint)\n3. Ø ∉ X.\n-/\n\ndefinition pairwise_disjoint (Xs : set (set T)) := ∀ ⦃ X1 X2 : set T ⦄, X1 ∈ Xs → X2 ∈ Xs → X1 ≠ X2 → X1 ∩ X2 = ∅\n\nstructure partition (Xs : set (set T)) :=\n  mk :: (cover : T → set T)\n        (cover_legal : ∀ x, cover x ∈ Xs)\n        (cover_spans : ∀ x, x ∈ cover x)\n        (pdisjoint : pairwise_disjoint Xs)\n        (ncempty : ¬ ∅ ∈ Xs)\n\nopen partition\n\n\n\n/- [KS]\nLemma: Let S be a set and X a partition of S. Then every element u ∈ S belongs to exactly one set\nY ∈ X.\nProof: Let S be a set and X a partition of S. We will show that every element u ∈ S belongs to at least\none set Y ∈ X and to at most one set Y ∈ X.\nTo see that every element u ∈ S belongs to at least one set Y ∈ 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 ∈ X\nsuch that u ∈ Y, since otherwise the union of all sets contained in X would not be equal to S.\nTo see that every element u ∈ S belongs to at most one set Y ∈ X, suppose for the sake of contradiction\nthat u belongs to two sets Y1, Y2 ∈ X with Y1 ≠ Y2. But then x ∈ Y1 ∩ Y2, meaning that\nY1 ∩ Y2 ≠ Ø, a contradiction. We have reached a contradiction, so our assumption must have been\nwrong.\nThus every element u ∈ S belongs to at most one set Y ∈ X. ■\n-/\n\n/-\ndefinition exists_unique {A : Type} (p : A → Prop) :=\n∃x, p x ∧ ∀y, p y → y = x\n\nnotation `∃!` binders `,` r:(scoped P, exists_unique P) := r\n\ntheorem exists_unique.intro {A : Type} {p : A → Prop} (w : A) (H1 : p w) (H2 : ∀y, p y → y = w) :\n  ∃!x, p x :=\nexists.intro w (and.intro H1 H2)\n\ntheorem exists_unique.elim {A : Type} {p : A → Prop} {b : Prop}\n    (H2 : ∃!x, p x) (H1 : ∀x, p x → (∀y, p y → y = x) → b) : b :=\nobtain w Hw, from H2,\nH1 w (and.elim_left Hw) (and.elim_right Hw)\n-/\n\nlemma unique_set : ∀ {Xs : set (set T)}, partition Xs → ∀ (u : T), ∃! (X : set T), X ∈ Xs ∧ u ∈ X :=\n  assume (Xs : set (set T)) (pXs : partition Xs) (u : T),\n  show ∃! (X : set T), X ∈ Xs ∧ u ∈ X, from\n  show ∃ (X : set T), (X ∈ Xs ∧ u ∈ X) ∧ (∀ Y, Y ∈ Xs ∧ u ∈ Y → Y = X), from\n  let X := cover pXs u in \n  have X_unique : (∀ Y, Y ∈ Xs ∧ u ∈ Y → Y = X), from\n    assume (Y : set T) (Y_in_Xs_and_u_in_Y : Y ∈ Xs ∧ u ∈ Y),\n    have Y_in_Xs : Y ∈ Xs, from and.left Y_in_Xs_and_u_in_Y,\n    have u_in_Y : u ∈ Y, from and.right Y_in_Xs_and_u_in_Y,\n    by_contradiction \n      (assume (Y_neq_X : Y ≠ X),\n       show false, from\n       -- But then x ∈ Y1 ∩ Y2, \n       have u_in_Y_cap_X : u ∈ Y ∩ X, from and.intro u_in_Y (cover_spans pXs u),\n       -- meaning that Y1 ∩ Y2 ≠ Ø, \n       have Y_cap_X_neq_empty : Y ∩ X ≠ ∅, from \n         assume (cap_empty : Y ∩ X = ∅), \n         have u_in_empty : u ∈ ∅, from cap_empty ▸ u_in_Y_cap_X,\n         show false, from u_in_empty,\n       -- a contradiction. We have reached a contradiction, so our assumption must have been wrong.\n       absurd (pdisjoint pXs Y_in_Xs (cover_legal pXs u) Y_neq_X) Y_cap_X_neq_empty),\n  -- Thus every element u ∈ S belongs to at most one set Y ∈ X. ■\n  exists_unique.intro X (and.intro (cover_legal pXs u) (cover_spans pXs u)) X_unique\n\ndefinition P_equiv {Xs : set (set T)} (pXs : partition Xs) (x y : T) := cover pXs x = cover pXs y\n\n/-\nTo see that ~X is reflexive, we need to prove that for any u ∈ S, that u ~X u. By definition, this means\nthat we need to show that [u]X = [u]X, which is true because = is reflexive.\nTo see that ~X is symmetric, we need to show that if u ~X v, then v ~X u. By definition, this means\nthat we need to show that if [u]X = [v]X, then [v]X = [u]X. This is true because = is symmetric.\nTo see that ~X is transitive, we need to show that if u ~X v and v ~X w, then u ~X w. By definition, this\nmeans that we need to show that if [u]X = [v]X and [v]X = [w]X, then [u]X = [w]X. This is true because\n= is transitive.\n-/\n\nprint definition reflexive\ncheck reflexive\n-- TODO why won't this work??\nset_option formatter.hide_full_terms false\n\n\nlemma P_equiv_refl : ∀ {Xs : set (set T)} (pXs : partition Xs), reflexive (P_equiv pXs) := \n  assume (Xs : set (set T)) (pXs : partition Xs), \n  show reflexive (P_equiv pXs), from\n  assume (u : T),\n  show P_equiv pXs u u, from\n  show cover pXs u = cover pXs u, from rfl\n\nlemma P_equiv_symm : ∀ {Xs : set (set T)} (pXs : partition Xs), symmetric (P_equiv pXs) := \n  assume (Xs : set (set T)) (pXs : partition Xs), \n  show symmetric (P_equiv pXs), from\n  assume (u v : T),\n  show P_equiv pXs u v → P_equiv pXs v u, from\n  assume (uRv : cover pXs u = cover pXs v),\n  show cover pXs v = cover pXs u, from uRv⁻¹\n\nlemma P_equiv_trans : ∀ {Xs : set (set T)} (pXs : partition Xs), transitive (P_equiv pXs) := \n  assume (Xs : set (set T)) (pXs : partition Xs), \n  show transitive (P_equiv pXs), from\n  assume (u v w: T) (uRv : cover pXs u = cover pXs v) (vRw : cover pXs v = cover pXs w),\n  show cover pXs u = cover pXs w, from vRw ▸ uRv\n\n\n/- [KS]\nLemma: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. Then ∪X = A.\nProof: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. We will prove that ∪X ⊆ A\nand A ⊆ ∪X, from which we can conclude that ∪X = A.\nTo show that ∪X ⊆ A, consider any x ∈ X. By definition of ∪X, since x ∈ X, this means that there is\nsome [y]R ∈ X such that x ∈ [y]R. By definition of [y]R, since x ∈ [y]R, this means that yRx. Since R is\na binary relation over A, this means that x ∈ A. Since our choice of x was arbitrary, this shows that if\nx ∈ ∪X, then x ∈ A. Thus ∪X ⊆ A.\nTo show that A ⊆ ∪X, consider any x ∈ A. We will prove that x ∈ [x]R. If we can show this, then note\nthat since x ∈ [x]R and [x]R ∈ X, we have x ∈ X. Since our choice of x is arbitrary, this would mean\nthat any x ∈ A satisfies x ∈ ∪X, so A ⊆ ∪X.\nSo let's now prove that x ∈ [x]R. By definition, [x]R = { y ∈ A | xRy }. Since R is an equivalence relation,\nR is reflexive, so xRx. Consequently, x ∈ [x]R, as required. ■ \n-/\nprint definition equivalence\n\ndefinition set_of_sets (f : T → set T) : set (set T) := λ (s : set T), ∃ (u : T), s = f u\ndefinition bigcup (Xs : set (set T)) : set T := λ (v: T), ∃ (X : set T), X ∈ Xs ∧ v ∈ X\n\nlemma equiv_spans : ∀ {R : T → T → Prop}, equivalence R → ∀ v, v ∈ bigcup (set_of_sets R) :=\n  assume (R : T → T → Prop) (R_equiv : equivalence R) (v : T),\n  show ∃ (X : set T), X ∈ (set_of_sets R) ∧ v ∈ X, from\n  let X := R v in\n  have X_in_ssR : X ∈ set_of_sets R, from exists.intro v rfl,\n  have v_in_X : v ∈ X, from and.left R_equiv v,\n  exists.intro X (and.intro X_in_ssR v_in_X)\n\n/- [KS]\nLemma: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. Then Ø ∉ X.\nProof: Using the logic of our previous proof, we have that for any x ∈ A, that x ∈ [x]R. Consequently,\nfor any x ∈ A, we know [x]R ≠ Ø. Thus Ø ∉ X. ■\n-/\n\nlemma equiv_nonempty : ∀ {R : T → T → Prop}, equivalence R → ¬ ∅ ∈ set_of_sets R := \n  assume (R : T → T → Prop) (R_equiv : equivalence R) (equiv_empty : ∅ ∈ set_of_sets R),\n  show false, from \n  have exists_u : ∃ (u : T), ∅ = R u, from equiv_empty,\n  obtain (u : T) (u_empty : ∅ = R u), from exists_u,\n  have Ruu : R u u, from and.left R_equiv u,\n  show false, from (congr_fun u_empty⁻¹ u) ▸ Ruu\n\n\n/- [KS]\nLemma: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. Then for any two sets [x]R,\n[y]R ∈ X, if [x]R ≠ [y]R, then [x]R ∩ [y]R = Ø.\nProof: Let R be an equivalence relation over A, and X = { [x]R | x ∈ A }. We proceed by contrapositive\nand show that for any [x]R, [y]R ∈ X, that if [x]R ∩ [y]R ≠ Ø, then [x]R = [y]R.\nConsider any [x]R, [y]R ∈ X such that [x]R ∩ [y]R ≠ Ø. Then there must be some element w such that\nw ∈ [x]R and w ∈ [y]R. By definition, this means w ∈ { z ∈ A | xRz } and w ∈ { z ∈ A | yRz }. Consequently,\nxRw and yRw. Since R is symmetric, this means that xRw and wRy. Since R is transitive,\nthis means that xRy. By symmetry, we also have that yRx.\nWe will now use this fact to show that [x]R ⊆ [y]R. Without loss of generality, we can use this same\nargument to show that [y]R ⊆ [x]R, from which we can conclude that [x]R = [y]R, as required.\nTo show that [x]R ⊆ [y]R, consider any z ∈ [x]R. This means that xRz. Since yRx and xRz, by transitivity\nwe have that yRz. Consequently, z ∈ [y]R. Since our choice of z was arbitrary, we have that any\nz ∈ [x]R satisfies z ∈ [y]R. Thus [x]R ⊆ [y]R, as required. ■\n-/\n\n-- proved elsewhere\naxiom by_contrapositive : ∀ {P Q : Prop}, (¬ Q → ¬ P) → (P → Q)\nlemma nonempty_choice : ∀ ⦃X : set T⦄, X ≠ ∅ → ∃ x, x ∈ X := sorry\nlemma subset_eq : ∀ ⦃ X Y : set T ⦄, X ⊆ Y → Y ⊆ X → X = Y := sorry\nlemma double_negation : ∀ {P : Prop}, ¬ ¬ P → P := sorry\nlemma intro_double_negation : ∀ {P : Prop}, P → ¬¬ P := sorry\n\nprint definition equivalence\n\ndefinition equiv_refl ⦃R : T → T → Prop⦄ (R_equiv : equivalence R) : reflexive R := and.left R_equiv\ndefinition equiv_symm ⦃R : T → T → Prop⦄ (R_equiv : equivalence R) : symmetric R := and.left (and.right R_equiv)\ndefinition equiv_trans ⦃R : T → T → Prop⦄ (R_equiv : equivalence R) : transitive R := and.right (and.right R_equiv)\nprint definition transitive\n\nlemma equiv_pdisjoint : ∀ {R : T → T → Prop}, equivalence R → pairwise_disjoint (set_of_sets R) :=\n  assume (R : T → T → Prop) (R_equiv : equivalence R),\n  show pairwise_disjoint (set_of_sets R), from\n  let Xs := set_of_sets R in\n  show ∀ (X1 X2 : set T), X1 ∈ Xs → X2 ∈ Xs → X1 ≠ X2 → X1 ∩ X2 = ∅, from\n  assume (X1 X2 : set T) (X1_in_Xs : X1 ∈ Xs) (X2_in_Xs : X2 ∈ Xs),\n  show X1 ≠ X2 → X1 ∩ X2 = ∅, from\n  by_contrapositive (\n    assume (X1_meets_X2 : X1 ∩ X2 ≠ ∅),\n    show ¬ X1 ≠ X2, from -- annoying double negation (how to apply and change the show?)\n    have X1_eq_X2 : X1 = X2, from \n    obtain (x : T) (X1_x : X1 = R x), from X1_in_Xs,\n    obtain (y : T) (X2_y : X2 = R y), from X2_in_Xs,\n    have exists_w_in_both : ∃ w, w ∈ X1 ∧ w ∈ X2, from nonempty_choice X1_meets_X2,\n    obtain (w : T) (w_in_both : w ∈ X1 ∧ w ∈ X2), from exists_w_in_both,\n    have Rxw : R x w, from congr_fun X1_x w ▸ (and.left w_in_both),\n    have Ryw : R y w, from congr_fun X2_y w ▸ (and.right w_in_both),\n    have Rxy : R x y, from equiv_trans R_equiv Rxw (equiv_symm R_equiv Ryw),\n    have X1_ss_X2 : X1 ⊆ X2, from\n      assume (z : T) (z_in_X1 : z ∈ X1),\n      show z ∈ X2, from\n      have Rxz : R x z, from congr_fun X1_x z ▸ z_in_X1,\n      have Ryz : R y z, from equiv_trans R_equiv (equiv_symm R_equiv Rxy) Rxz,\n      congr_fun X2_y⁻¹ z ▸ Ryz,\n    have X2_ss_X1 : X2 ⊆ X1, from\n      assume (z : T) (z_in_X2 : z ∈ X2),\n      show z ∈ X1, from\n      have Ryz : R y z, from congr_fun X2_y z ▸ z_in_X2,\n      have Rxz : R x z, from equiv_trans R_equiv Rxy Ryz,\n      congr_fun X1_x⁻¹ z ▸ Rxz,\n    subset_eq X1_ss_X2 X2_ss_X1,\n    intro_double_negation X1_eq_X2\n  )\n\n/- [KS]\nTheorem: Let R be an equivalence relation over A, and let X = { [x]R | x ∈ A }. Then X is a partition\nof A.\n-/\n\ntheorem equiv_partition : ∀ (R : T → T → Prop), equivalence R → partition (set_of_sets R) := \n  assume (R : T → T → Prop) (R_equiv : equivalence R),\n  show partition (set_of_sets R), from\n  have R_legal : ∀ x, R x ∈ set_of_sets R, from assume x, exists.intro x rfl,\n  have R_spans : ∀ x, x ∈ R x, from assume x, equiv_refl R_equiv x,\n  have R_pdisjoint : pairwise_disjoint (set_of_sets R), from equiv_pdisjoint R_equiv,\n  have R_ncempty : ¬ ∅ ∈ set_of_sets R, from equiv_nonempty R_equiv,\n  partition.mk R R_legal R_spans R_pdisjoint R_ncempty\n  \n\n\ndefinition asymmetric (R : T → T → Prop) := ∀ x y, R x y → ¬ R y x\ndefinition antisymmetric (R : T → T → Prop) := ∀ x y, R x y → R y x → x = y\n\n/- [KS]\nA binary relation R over a set A is called a strict order iff R is irreflexive, asymmetric, and transitive.\n-/\n\nstructure strict_order (R : T → T → Prop) :=\n  mk :: (irrefl : irreflexive R)\n        (asym : asymmetric R)\n        (trans : transitive R)\n\n/- [KS]\nTheorem: The relation ⊂ over ℘(ℕ) is a strict order.\nProof: We show that ⊂ is irreflexive, asymmetric, and transitive.\nTo show that ⊂ is irreflexive, we must show that for any A ∈ ℘(ℕ) that A ⊂ A does not hold. To see\nthis, assume for the sake of contradiction that this is false and that there exists some A ∈ ℘(ℕ) such\nthat A ⊂ A. By definition of ⊂, this means that A ⊆ A and A ≠ A. But A ≠ A is impossible, since = is\nreflexive. We have reached a contradiction, so our assumption must have been wrong. Thus ⊂ is irreflexive.\nTo show that ⊂ is asymmetric, we must show that for any A, B ∈ ℘(ℕ) that if A ⊂ B, then it is not the\ncase that B ⊂ A. We proceed by contradiction; assume that this statement is false and that there exist\nsome sets A, B ∈ ℘(ℕ) such that A ⊂ B and B ⊂ A. By definition of ⊂, this means that A ⊆ B, B ⊆ A,\nbut A ≠ B. Since A ⊆ B and B ⊆ A, we know that A = B, contradicting the fact that A ≠ B. We have\nreached a contradiction, so our assumption must have been wrong. Thus ⊂ is asymmetric.\nTo show that ⊂ is transitive, we need to show that for any A, B, C ∈ ℘(ℕ), that if A ⊂ B and B ⊂ C,\nthen A ⊂ C. Consider any A, B, C ∈ ℘(ℕ) where A ⊂ B and B ⊂ C. By definition of ⊂, this means\nthat A ⊆ B, B ⊆ C, A ≠ B, and B ≠ C. We will show that A ⊂ C, meaning that A ⊆ C and A ≠ C.\nSince A ⊆ B and B ⊆ C, we know that A ⊆ C. To show that A ≠ C, assume for the sake of contradiction\nthat A = C. Since B ⊂ C and C = A, this means that B ⊂ A. But this is impossible, because we\nalso know that A ⊂ B, and ⊂ is asymmetric. We have reached a contradiction, so our assumption\nmust have been wrong. Thus A ≠ C. Since A ⊆ C and A ≠ C, this means that A ⊂ C as required.\nSince ⊂ is irreflexive, asymmetric, and transitive, it is a strict order over ℘(ℕ). ■\n-/\n\n\ndefinition strict_subset (X Y : set T) : Prop := X ⊆ Y ∧ X ≠ Y\ninfix `⊂`:50 := strict_subset\n\ncheck strict_order\ncheck strict_subset\ntheorem strict_subset_string_order : (@strict_order (set T)) (@strict_subset T) := \n  have ss_irrefl : irreflexive strict_subset, from \n    assume (X : set T) (X_lt_X : X ⊆ X ∧ X ≠ X),\n    absurd rfl (and.right X_lt_X),\n  have ss_asym : asymmetric strict_subset, from \n    assume (X Y : set T) (X_lt_Y : X ⊂ Y) (Y_lt_X : Y ⊂ X),\n    have X_eq_Y : X = Y, from subset_eq (and.left X_lt_Y) (and.left Y_lt_X),\n    absurd X_eq_Y (and.right X_lt_Y),\n  have ss_trans : transitive strict_subset, from \n    assume (X Y Z : set T) (X_lt_Y : X ⊂ Y) (Y_lt_Z : Y ⊂ Z),\n    show X ⊂ Z, from\n      have X_ss_Z : X ⊆ Z, from assume (x : T) (x_in_X : x ∈ X), and.left Y_lt_Z x (and.left X_lt_Y x x_in_X),\n      have X_neq_Z : X ≠ Z, from \n        assume (X_eq_Z : X = Z), \n        have Y_ss_X : Y ⊆ X, from X_eq_Z⁻¹ ▸ (and.left Y_lt_Z),\n        have X_eq_Y : X = Y, from subset_eq (and.left X_lt_Y) Y_ss_X,\n        absurd X_eq_Y (and.right X_lt_Y),\n    and.intro X_ss_Z X_neq_Z,\n  strict_order.mk ss_irrefl ss_asym ss_trans\n  \nopen nat\n\nstructure partial_order (R : T → T → Prop) :=\n  mk :: (refl : reflexive R)\n        (antisym : antisymmetric R)\n        (trans : transitive R)\n\ndefinition divides (m n : nat) := ∃ q, n = m * q\ninfix `∣` := divides\ncheck 2 ∣ 8\n/- [KS]\nTheorem: | is a partial order over ℕ.\nProof: We will show that | is reflexive, antisymmetric, and transitive. To see that | is reflexive, we will\nprove that for any n ∈ ℕ, that n | n (that there exists some q ∈ ℕ such that n = nq). So let n be any\nnatural number, and take q = 1. Then nq = n · 1 = n, so n | n.\nTo see that | is antisymmetric, we will prove that for any m, n ∈ ℕ, that if m | n and n | m, that m = n.\nConsider any m, n ∈ ℕ where m | n and n | m. This means that there exists q, r ∈ ℕ such that n = mq\nand m = nr. Consequently:\nm = nr = (mq)r = mqr\nn = mq = (nr)q = nqr\nWe now consider two cases. First, if m = n = 0, then we are done, since m = n. Otherwise, at least\none of m or n is nonzero; without loss of generality, assume m ≠ 0. Then since m = mqr, we know\nthat 1 = qr. Since q, r ∈ ℕ, this is only possible if q = r = 1. Consequently, m = nr = n · 1 = n, so\nm = n, as required.\nTo see that | is transitive, we will prove that for any m, n, p ∈ ℕ, that if m | n and n | p, then m | p.\nConsider any m, n, p ∈ ℕ where m | n and n | p; then there must exist q, r ∈ ℕ such that n = qm and\np = rn. Consequently, p = rn = r(qm) = qrm = (qr)m. Since qr ∈ ℕ, this means that there is some\nk ∈ ℕ (namely, qr) such that p = km. Thus m | p, as required.\nSince | is reflexive, antisymmetric, and transitive over ℕ, | is a partial order over ℕ.\n-/\n\nprint definition mul\n\nlemma mul_cancel : ∀ ⦃m n : nat⦄, m ≠ 0 → m = m * n → n = 1 := sorry\nlemma mul_cancel_one_right : ∀ ⦃ m n : nat ⦄, m * n = 1 → n = 1 := sorry\n\ntheorem divides_partial_order : partial_order divides := \n  have div_refl : reflexive divides, from \n    assume (n : ℕ),\n    show n ∣ n, from exists.intro 1 (mul_one n)⁻¹,\n  have div_antisym : antisymmetric divides, from \n    assume (m n : ℕ) (m_div_n : m ∣ n) (n_div_m : n ∣ m),\n    show m = n, from \n      have m_neq_0 : m ≠ 0, from sorry, -- #FALSE need case analysis\n      obtain (q1 : ℕ) (n_eq_mq1 : n = m * q1), from m_div_n,\n      obtain (q2 : ℕ) (m_eq_nq2 : m = n * q2), from n_div_m,\n      have m_eq_m_q12 : m = m * (q1 * q2), from (mul.assoc m q1 q2) ▸ n_eq_mq1 ▸ m_eq_nq2,\n      have q1q2_eq_1 : q1 * q2 = 1, from mul_cancel m_neq_0 m_eq_m_q12,\n      have q2_eq_1 : q2 = 1, from mul_cancel_one_right q1q2_eq_1,\n      have m_eq_n1 : m = n * 1, from q2_eq_1 ▸ m_eq_nq2,\n      (mul_one n) ▸ m_eq_n1,\n  have div_trans : transitive divides, from \n    assume (m n p : ℕ) (m_div_n : m ∣ n) (n_div_p : n ∣ p),\n    show m ∣ p, from \n      obtain (q1 : ℕ) (n_eq_mq1 : n = m * q1), from m_div_n,\n      obtain (q2 : ℕ) (p_eq_nq2 : p = n * q2), from n_div_p,\n      exists.intro (q1 * q2) (mul.assoc m q1 q2 ▸ n_eq_mq1 ▸ p_eq_nq2),\n  partial_order.mk div_refl div_antisym div_trans\n \n  \n  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\nend relations\n", "meta": {"author": "dselsam", "repo": "cs103", "sha": "31ab9784a6f65f226efb702a0da52f907c616a71", "save_path": "github-repos/lean/dselsam-cs103", "path": "github-repos/lean/dselsam-cs103/cs103-31ab9784a6f65f226efb702a0da52f907c616a71/rel.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666336, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7566060404551123}}
{"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.preadditive.hom_orthogonal\n! leanprover-community/mathlib commit 829895f162a1f29d0133f4b3538f4cd1fb5bffd3\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.CategoryTheory.Linear.Basic\nimport Mathbin.CategoryTheory.Preadditive.Biproducts\nimport Mathbin.LinearAlgebra.Matrix.InvariantBasisNumber\n\n/-!\n# Hom orthogonal families.\n\nA family of objects in a category with zero morphisms is \"hom orthogonal\" if the only\nmorphism between distinct objects is the zero morphism.\n\nWe show that in any category with zero morphisms and finite biproducts,\na morphism between biproducts drawn from a hom orthogonal family `s : ι → C`\ncan be decomposed into a block diagonal matrix with entries in the endomorphism rings of the `s i`.\n\nWhen the category is preadditive, this decomposition is an additive equivalence,\nand intertwines composition and matrix multiplication.\nWhen the category is `R`-linear, the decomposition is an `R`-linear equivalence.\n\nIf every object in the hom orthogonal family has an endomorphism ring with invariant basis number\n(e.g. if each object in the family is simple, so its endomorphism ring is a division ring,\nor otherwise if each endomorphism ring is commutative),\nthen decompositions of an object as a biproduct of the family have uniquely defined multiplicities.\nWe state this as:\n```\nlemma hom_orthogonal.equiv_of_iso (o : hom_orthogonal s) {f : α → ι} {g : β → ι}\n  (i : ⨁ (λ a, s (f a)) ≅ ⨁ (λ b, s (g b))) : ∃ e : α ≃ β, ∀ a, g (e a) = f a\n```\n\nThis is preliminary to defining semisimple categories.\n-/\n\n\nopen Classical Matrix\n\nopen CategoryTheory.Limits\n\nuniverse v u\n\nnamespace CategoryTheory\n\nvariable {C : Type u} [Category.{v} C]\n\n/-- A family of objects is \"hom orthogonal\" if\nthere is at most one morphism between distinct objects.\n\n(In a category with zero morphisms, that must be the zero morphism.) -/\ndef HomOrthogonal {ι : Type _} (s : ι → C) : Prop :=\n  ∀ i j, i ≠ j → Subsingleton (s i ⟶ s j)\n#align category_theory.hom_orthogonal CategoryTheory.HomOrthogonal\n\nnamespace HomOrthogonal\n\nvariable {ι : Type _} {s : ι → C}\n\ntheorem eq_zero [HasZeroMorphisms C] (o : HomOrthogonal s) {i j : ι} (w : i ≠ j) (f : s i ⟶ s j) :\n    f = 0 := by\n  haveI := o i j w\n  apply Subsingleton.elim\n#align category_theory.hom_orthogonal.eq_zero CategoryTheory.HomOrthogonal.eq_zero\n\nsection\n\nvariable [HasZeroMorphisms C] [HasFiniteBiproducts C]\n\n/-- Morphisms between two direct sums over a hom orthogonal family `s : ι → C`\nare equivalent to block diagonal matrices,\nwith blocks indexed by `ι`,\nand matrix entries in `i`-th block living in the endomorphisms of `s i`. -/\n@[simps]\nnoncomputable def matrixDecomposition (o : HomOrthogonal s) {α β : Type} [Fintype α] [Fintype β]\n    {f : α → ι} {g : β → ι} :\n    ((⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b)) ≃\n      ∀ i : ι, Matrix (g ⁻¹' {i}) (f ⁻¹' {i}) (End (s i))\n    where\n  toFun z i j k :=\n    eqToHom\n        (by\n          rcases k with ⟨k, ⟨⟩⟩\n          simp) ≫\n      biproduct.components z k j ≫\n        eqToHom\n          (by\n            rcases j with ⟨j, ⟨⟩⟩\n            simp)\n  invFun z :=\n    biproduct.matrix fun j k =>\n      if h : f j = g k then z (f j) ⟨k, by simp [h]⟩ ⟨j, by simp⟩ ≫ eqToHom (by simp [h]) else 0\n  left_inv z := by\n    ext (j k)\n    simp only [category.assoc, biproduct.lift_π, biproduct.ι_matrix]\n    split_ifs\n    · simp\n      rfl\n    · symm\n      apply o.eq_zero h\n  right_inv z := by\n    ext (i⟨j, w⟩⟨k, ⟨⟩⟩)\n    simp only [Set.mem_preimage, Set.mem_singleton_iff]\n    simp [w.symm]; rfl\n#align category_theory.hom_orthogonal.matrix_decomposition CategoryTheory.HomOrthogonal.matrixDecomposition\n\nend\n\nsection\n\nvariable [Preadditive C] [HasFiniteBiproducts C]\n\n/-- `hom_orthogonal.matrix_decomposition` as an additive equivalence. -/\n@[simps]\nnoncomputable def matrixDecompositionAddEquiv (o : HomOrthogonal s) {α β : Type} [Fintype α]\n    [Fintype β] {f : α → ι} {g : β → ι} :\n    ((⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b)) ≃+\n      ∀ i : ι, Matrix (g ⁻¹' {i}) (f ⁻¹' {i}) (End (s i)) :=\n  { o.matrixDecomposition with\n    map_add' := fun w z => by\n      ext\n      dsimp [biproduct.components]\n      simp }\n#align category_theory.hom_orthogonal.matrix_decomposition_add_equiv CategoryTheory.HomOrthogonal.matrixDecompositionAddEquiv\n\n@[simp]\ntheorem matrixDecomposition_id (o : HomOrthogonal s) {α : Type} [Fintype α] {f : α → ι} (i : ι) :\n    o.matrixDecomposition (𝟙 (⨁ fun a => s (f a))) i = 1 :=\n  by\n  ext (⟨b, ⟨⟩⟩⟨a⟩)\n  simp only [Set.mem_preimage, Set.mem_singleton_iff] at j_property\n  simp only [category.comp_id, category.id_comp, category.assoc, End.one_def, eq_to_hom_refl,\n    Matrix.one_apply, hom_orthogonal.matrix_decomposition_apply, biproduct.components]\n  split_ifs with h\n  · cases h\n    simp\n  · convert comp_zero\n    simpa using biproduct.ι_π_ne _ (Ne.symm h)\n#align category_theory.hom_orthogonal.matrix_decomposition_id CategoryTheory.HomOrthogonal.matrixDecomposition_id\n\ntheorem matrixDecomposition_comp (o : HomOrthogonal s) {α β γ : Type} [Fintype α] [Fintype β]\n    [Fintype γ] {f : α → ι} {g : β → ι} {h : γ → ι} (z : (⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b))\n    (w : (⨁ fun b => s (g b)) ⟶ ⨁ fun c => s (h c)) (i : ι) :\n    o.matrixDecomposition (z ≫ w) i = o.matrixDecomposition w i ⬝ o.matrixDecomposition z i :=\n  by\n  ext (⟨c, ⟨⟩⟩⟨a⟩)\n  simp only [Set.mem_preimage, Set.mem_singleton_iff] at j_property\n  simp only [Matrix.mul_apply, limits.biproduct.components,\n    hom_orthogonal.matrix_decomposition_apply, category.comp_id, category.id_comp, category.assoc,\n    End.mul_def, eq_to_hom_refl, eq_to_hom_trans_assoc, Finset.sum_congr]\n  conv_lhs => rw [← category.id_comp w, ← biproduct.total]\n  simp only [preadditive.sum_comp, preadditive.comp_sum]\n  apply Finset.sum_congr_set\n  · intros\n    simp\n    rfl\n  · intro b nm\n    simp only [Set.mem_preimage, Set.mem_singleton_iff] at nm\n    simp only [category.assoc]\n    convert comp_zero\n    convert comp_zero\n    convert comp_zero\n    convert comp_zero\n    apply o.eq_zero nm\n#align category_theory.hom_orthogonal.matrix_decomposition_comp CategoryTheory.HomOrthogonal.matrixDecomposition_comp\n\nsection\n\nvariable {R : Type _} [Semiring R] [Linear R C]\n\n/-- `hom_orthogonal.matrix_decomposition` as an `R`-linear equivalence. -/\n@[simps]\nnoncomputable def matrixDecompositionLinearEquiv (o : HomOrthogonal s) {α β : Type} [Fintype α]\n    [Fintype β] {f : α → ι} {g : β → ι} :\n    ((⨁ fun a => s (f a)) ⟶ ⨁ fun b => s (g b)) ≃ₗ[R]\n      ∀ i : ι, Matrix (g ⁻¹' {i}) (f ⁻¹' {i}) (End (s i)) :=\n  { o.matrixDecompositionAddEquiv with\n    map_smul' := fun w z => by\n      ext\n      dsimp [biproduct.components]\n      simp }\n#align category_theory.hom_orthogonal.matrix_decomposition_linear_equiv CategoryTheory.HomOrthogonal.matrixDecompositionLinearEquiv\n\nend\n\n/-!\nThe hypothesis that `End (s i)` has invariant basis number is automatically satisfied\nif `s i` is simple (as then `End (s i)` is a division ring).\n-/\n\n\nvariable [∀ i, InvariantBasisNumber (End (s i))]\n\n/-- Given a hom orthogonal family `s : ι → C`\nfor which each `End (s i)` is a ring with invariant basis number (e.g. if each `s i` is simple),\nif two direct sums over `s` are isomorphic, then they have the same multiplicities.\n-/\ntheorem equiv_of_iso (o : HomOrthogonal s) {α β : Type} [Fintype α] [Fintype β] {f : α → ι}\n    {g : β → ι} (i : (⨁ fun a => s (f a)) ≅ ⨁ fun b => s (g b)) : ∃ e : α ≃ β, ∀ a, g (e a) = f a :=\n  by\n  refine' ⟨Equiv.ofPreimageEquiv _, fun a => Equiv.ofPreimageEquiv_map _ _⟩\n  intro c\n  apply Nonempty.some\n  apply Cardinal.eq.1\n  simp only [Cardinal.mk_fintype, Nat.cast_inj]\n  exact\n    Matrix.square_of_invertible (o.matrix_decomposition i.inv c) (o.matrix_decomposition i.hom c)\n      (by\n        rw [← o.matrix_decomposition_comp]\n        simp)\n      (by\n        rw [← o.matrix_decomposition_comp]\n        simp)\n#align category_theory.hom_orthogonal.equiv_of_iso CategoryTheory.HomOrthogonal.equiv_of_iso\n\nend\n\nend HomOrthogonal\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/Preadditive/HomOrthogonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460333, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7566060299960975}}
{"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.modular_lattice\nimport order.well_founded\n\n/-!\n# Atoms, Coatoms, and Simple Lattices\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nThis module defines atoms, which are minimal non-`⊥` 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 `⊥`.\n  * `is_coatom a` indicates that the only element above `a` is `⊤`.\n\n### Atomic and Atomistic Lattices\n  * `is_atomic` indicates that every element other than `⊥` is above an atom.\n  * `is_coatomic` indicates that every element other than `⊤` 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, `⊥` and `⊤`.\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\nvariables {α β : Type*}\n\nsection atoms\n\nsection is_atom\n\nsection preorder\n\nvariables [preorder α] [order_bot α] {a b x : α}\n\n/-- An atom of an `order_bot` is an element with no other element between it and `⊥`,\n  which is not `⊥`. -/\ndef is_atom (a : α) : Prop := a ≠ ⊥ ∧ (∀ b, b < a → b = ⊥)\n\nlemma is_atom.Iic (ha : is_atom a) (hax : a ≤ x) : is_atom (⟨a, hax⟩ : set.Iic x) :=\n⟨λ con, ha.1 (subtype.mk_eq_mk.1 con), λ ⟨b, hb⟩ hba, subtype.mk_eq_mk.2 (ha.2 b hba)⟩\n\nlemma is_atom.of_is_atom_coe_Iic {a : set.Iic x} (ha : is_atom a) : is_atom (a : α) :=\n⟨λ con, ha.1 (subtype.ext con), λ b hba, subtype.mk_eq_mk.1 (ha.2 ⟨b, hba.le.trans a.prop⟩ hba)⟩\n\nlemma is_atom_iff {a : α} : is_atom a ↔ a ≠ ⊥ ∧ ∀ b ≠ ⊥, b ≤ a → a ≤ b :=\nand_congr iff.rfl $ forall_congr $\n  λ b, by simp only [ne.def, @not_imp_comm (b = ⊥), not_imp, lt_iff_le_not_le]\n\nend preorder\n\nvariables [partial_order α] [order_bot α] {a b x : α}\n\nlemma is_atom.lt_iff (h : is_atom a) : x < a ↔ x = ⊥ := ⟨h.2 x, λ hx, hx.symm ▸ h.1.bot_lt⟩\n\nlemma is_atom.le_iff (h : is_atom a) : x ≤ a ↔ x = ⊥ ∨ x = a :=\nby rw [le_iff_lt_or_eq, h.lt_iff]\n\nlemma is_atom.Iic_eq (h : is_atom a) : set.Iic a = {⊥, a} := set.ext $ λ x, h.le_iff\n\n@[simp] lemma bot_covby_iff : ⊥ ⋖ a ↔ is_atom a :=\nby simp only [covby, bot_lt_iff_ne_bot, is_atom, not_imp_not]\n\nalias bot_covby_iff ↔ covby.is_atom is_atom.bot_covby\n\nend is_atom\n\nsection is_coatom\n\nsection preorder\n\nvariables [preorder α]\n\n/-- A coatom of an `order_top` is an element with no other element between it and `⊤`,\n  which is not `⊤`. -/\ndef is_coatom [order_top α] (a : α) : Prop := a ≠ ⊤ ∧ (∀ b, a < b → b = ⊤)\n\n@[simp] lemma is_coatom_dual_iff_is_atom [order_bot α] {a : α}:\n  is_coatom (order_dual.to_dual a) ↔ is_atom a :=\niff.rfl\n\n@[simp] lemma is_atom_dual_iff_is_coatom [order_top α] {a : α} :\n  is_atom (order_dual.to_dual a) ↔ is_coatom a :=\niff.rfl\n\nalias is_coatom_dual_iff_is_atom ↔ _ is_atom.dual\nalias is_atom_dual_iff_is_coatom ↔ _ is_coatom.dual\n\nvariables [order_top α] {a x : α}\n\nlemma is_coatom.Ici (ha : is_coatom a) (hax : x ≤ a) : is_coatom (⟨a, hax⟩ : set.Ici x) :=\nha.dual.Iic hax\n\nlemma is_coatom.of_is_coatom_coe_Ici {a : set.Ici x} (ha : is_coatom a) :\n  is_coatom (a : α) :=\n@is_atom.of_is_atom_coe_Iic αᵒᵈ _ _ x a ha\n\nlemma is_coatom_iff {a : α} : is_coatom a ↔ a ≠ ⊤ ∧ ∀ b ≠ ⊤, a ≤ b → b ≤ a := @is_atom_iff αᵒᵈ _ _ _\n\nend preorder\n\nvariables [partial_order α] [order_top α] {a b x : α}\n\nlemma is_coatom.lt_iff (h : is_coatom a) : a < x ↔ x = ⊤ := h.dual.lt_iff\nlemma is_coatom.le_iff (h : is_coatom a) : a ≤ x ↔ x = ⊤ ∨ x = a := h.dual.le_iff\nlemma is_coatom.Ici_eq (h : is_coatom a) : set.Ici a = {⊤, a} := h.dual.Iic_eq\n\n@[simp] lemma covby_top_iff : a ⋖ ⊤ ↔ is_coatom a :=\nto_dual_covby_to_dual_iff.symm.trans bot_covby_iff\n\nalias covby_top_iff ↔ covby.is_coatom is_coatom.covby_top\n\nend is_coatom\n\nsection partial_order\nvariables [partial_order α] {a b : α}\n\n@[simp] lemma set.Ici.is_atom_iff {b : set.Ici a} : is_atom b ↔ a ⋖ b :=\nbegin\n  rw ←bot_covby_iff,\n  refine (set.ord_connected.apply_covby_apply_iff (order_embedding.subtype $ λ c, a ≤ c) _).symm,\n  simpa only [order_embedding.subtype_apply, subtype.range_coe_subtype] using set.ord_connected_Ici,\nend\n\n@[simp] lemma set.Iic.is_coatom_iff {a : set.Iic b} : is_coatom a ↔ ↑a ⋖ b :=\nbegin\n  rw ←covby_top_iff,\n  refine (set.ord_connected.apply_covby_apply_iff (order_embedding.subtype $ λ c, c ≤ b) _).symm,\n  simpa only [order_embedding.subtype_apply, subtype.range_coe_subtype] using set.ord_connected_Iic,\nend\n\nlemma covby_iff_atom_Ici (h : a ≤ b) : a ⋖ b ↔ is_atom (⟨b, h⟩ : set.Ici a) := by simp\nlemma covby_iff_coatom_Iic (h : a ≤ b) : a ⋖ b ↔ is_coatom (⟨a, h⟩ : set.Iic b) := by simp\n\nend partial_order\n\nsection pairwise\n\nlemma is_atom.inf_eq_bot_of_ne [semilattice_inf α] [order_bot α] {a b : α}\n  (ha : is_atom a) (hb : is_atom b) (hab : a ≠ b) : a ⊓ b = ⊥ :=\nhab.not_le_or_not_le.elim (ha.lt_iff.1 ∘ inf_lt_left.2) (hb.lt_iff.1 ∘ inf_lt_right.2)\n\nlemma is_atom.disjoint_of_ne [semilattice_inf α] [order_bot α] {a b : α}\n  (ha : is_atom a) (hb : is_atom b) (hab : a ≠ 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 α] [order_top α] {a b : α}\n  (ha : is_coatom a) (hb : is_coatom b) (hab : a ≠ b) : a ⊔ b = ⊤ :=\nha.dual.inf_eq_bot_of_ne hb.dual hab\n\nend pairwise\n\nend atoms\n\nsection atomic\n\nvariables [partial_order α] (α)\n\n/-- A lattice is atomic iff every element other than `⊥` has an atom below it. -/\n@[mk_iff] class is_atomic [order_bot α] : Prop :=\n(eq_bot_or_exists_atom_le : ∀ (b : α), b = ⊥ ∨ ∃ (a : α), is_atom a ∧ a ≤ b)\n\n/-- A lattice is coatomic iff every element other than `⊤` has a coatom above it. -/\n@[mk_iff] class is_coatomic [order_top α] : Prop :=\n(eq_top_or_exists_le_coatom : ∀ (b : α), b = ⊤ ∨ ∃ (a : α), is_coatom a ∧ b ≤ a)\n\nexport is_atomic (eq_bot_or_exists_atom_le) is_coatomic (eq_top_or_exists_le_coatom)\n\nvariable {α}\n\n@[simp] lemma is_coatomic_dual_iff_is_atomic [order_bot α] : is_coatomic αᵒᵈ ↔ is_atomic α :=\n⟨λ h, ⟨λ b, by apply h.eq_top_or_exists_le_coatom⟩, λ h, ⟨λ b, by apply h.eq_bot_or_exists_atom_le⟩⟩\n\n@[simp] lemma is_atomic_dual_iff_is_coatomic [order_top α] : is_atomic αᵒᵈ ↔ is_coatomic α :=\n⟨λ h, ⟨λ b, by apply h.eq_bot_or_exists_atom_le⟩, λ h, ⟨λ b, by apply h.eq_top_or_exists_le_coatom⟩⟩\n\nnamespace is_atomic\n\nvariables [order_bot α] [is_atomic α]\n\ninstance is_coatomic_dual : is_coatomic αᵒᵈ := is_coatomic_dual_iff_is_atomic.2 ‹is_atomic α›\n\ninstance {x : α} : is_atomic (set.Iic x) :=\n⟨λ ⟨y, hy⟩, (eq_bot_or_exists_atom_le y).imp subtype.mk_eq_mk.2\n  (λ ⟨a, ha, hay⟩, ⟨⟨a, hay.trans hy⟩, ha.Iic (hay.trans hy), hay⟩)⟩\n\nend is_atomic\n\nnamespace is_coatomic\n\nvariables [order_top α] [is_coatomic α]\n\ninstance is_coatomic : is_atomic αᵒᵈ := is_atomic_dual_iff_is_coatomic.2 ‹is_coatomic α›\n\ninstance {x : α} : is_coatomic (set.Ici x) :=\n⟨λ ⟨y, hy⟩, (eq_top_or_exists_le_coatom y).imp subtype.mk_eq_mk.2\n  (λ ⟨a, ha, hay⟩, ⟨⟨a, le_trans hy hay⟩, ha.Ici (le_trans hy hay), hay⟩)⟩\n\nend is_coatomic\n\ntheorem is_atomic_iff_forall_is_atomic_Iic [order_bot α] :\n  is_atomic α ↔ ∀ (x : α), is_atomic (set.Iic x) :=\n⟨@is_atomic.set.Iic.is_atomic _ _ _, λ h, ⟨λ x, ((@eq_bot_or_exists_atom_le _ _ _ (h x))\n  (⊤ : set.Iic x)).imp subtype.mk_eq_mk.1 (exists_imp_exists' coe\n  (λ ⟨a, ha⟩, and.imp_left (is_atom.of_is_atom_coe_Iic)))⟩⟩\n\ntheorem is_coatomic_iff_forall_is_coatomic_Ici [order_top α] :\n  is_coatomic α ↔ ∀ (x : α), is_coatomic (set.Ici x) :=\nis_atomic_dual_iff_is_coatomic.symm.trans $ is_atomic_iff_forall_is_atomic_Iic.trans $ forall_congr\n  (λ x, is_coatomic_dual_iff_is_atomic.symm.trans iff.rfl)\n\nsection well_founded\n\nlemma is_atomic_of_order_bot_well_founded_lt [order_bot α]\n  (h : well_founded ((<) : α → α → Prop)) : is_atomic α :=\n⟨λ a, or_iff_not_imp_left.2 $\n  λ ha, let ⟨b, hb, hm⟩ := h.has_min { b | b ≠ ⊥ ∧ b ≤ a } ⟨a, ha, le_rfl⟩ in\n  ⟨b, ⟨hb.1, λ c, not_imp_not.1 $ λ hc hl, hm c ⟨hc, hl.le.trans hb.2⟩ hl⟩, hb.2⟩⟩\n\nlemma is_coatomic_of_order_top_gt_well_founded [order_top α]\n  (h : well_founded ((>) : α → α → Prop)) : is_coatomic α :=\nis_atomic_dual_iff_is_coatomic.1 (@is_atomic_of_order_bot_well_founded_lt αᵒᵈ _ _ h)\n\nend well_founded\n\nend atomic\n\nsection atomistic\n\nvariables (α) [complete_lattice α]\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 : ∀ (b : α), ∃ (s : set α), b = Sup s ∧ ∀ a, a ∈ s → 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 : ∀ (b : α), ∃ (s : set α), b = Inf s ∧ ∀ a, a ∈ s → is_coatom a)\n\nexport is_atomistic (eq_Sup_atoms) is_coatomistic (eq_Inf_coatoms)\n\nvariable {α}\n\n@[simp]\ntheorem is_coatomistic_dual_iff_is_atomistic : is_coatomistic αᵒᵈ ↔ is_atomistic α :=\n⟨λ h, ⟨λ b, by apply h.eq_Inf_coatoms⟩, λ h, ⟨λ b, by apply h.eq_Sup_atoms⟩⟩\n\n@[simp]\ntheorem is_atomistic_dual_iff_is_coatomistic : is_atomistic αᵒᵈ ↔ is_coatomistic α :=\n⟨λ h, ⟨λ b, by apply h.eq_Sup_atoms⟩, λ h, ⟨λ b, by apply h.eq_Inf_coatoms⟩⟩\n\nnamespace is_atomistic\n\ninstance is_coatomistic_dual [h : is_atomistic α] : is_coatomistic αᵒᵈ :=\nis_coatomistic_dual_iff_is_atomistic.2 h\n\nvariable [is_atomistic α]\n\n@[priority 100]\ninstance : is_atomic α :=\n⟨λ b, by { rcases eq_Sup_atoms b with ⟨s, rfl, hs⟩,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ ⟨h.some, hs _ h.some_spec, le_Sup h.some_spec⟩ } } ⟩\n\nend is_atomistic\n\nsection is_atomistic\nvariables [is_atomistic α]\n\n@[simp]\ntheorem Sup_atoms_le_eq (b : α) : Sup {a : α | is_atom a ∧ a ≤ b} = b :=\nbegin\n  rcases eq_Sup_atoms b with ⟨s, rfl, hs⟩,\n  exact le_antisymm (Sup_le (λ _, and.right)) (Sup_le_Sup (λ a ha, ⟨hs a ha, le_Sup ha⟩)),\nend\n\n@[simp]\ntheorem Sup_atoms_eq_top : Sup {a : α | is_atom a} = ⊤ :=\nbegin\n  refine eq.trans (congr rfl (set.ext (λ x, _))) (Sup_atoms_le_eq ⊤),\n  exact (and_iff_left le_top).symm,\nend\n\ntheorem le_iff_atom_le_imp {a b : α} :\n  a ≤ b ↔ ∀ c : α, is_atom c → c ≤ a → c ≤ b :=\n⟨λ ab c hc ca, le_trans ca ab, λ h, begin\n  rw [← Sup_atoms_le_eq a, ← Sup_atoms_le_eq b],\n  exact Sup_le_Sup (λ c hc, ⟨hc.1, h c hc.1 hc.2⟩),\nend⟩\n\nend is_atomistic\n\nnamespace is_coatomistic\n\ninstance is_atomistic_dual [h : is_coatomistic α] : is_atomistic αᵒᵈ :=\nis_atomistic_dual_iff_is_coatomistic.2 h\n\nvariable [is_coatomistic α]\n\n@[priority 100]\ninstance : is_coatomic α :=\n⟨λ b, by { rcases eq_Inf_coatoms b with ⟨s, rfl, hs⟩,\n  cases s.eq_empty_or_nonempty with h h,\n  { simp [h] },\n  { exact or.intro_right _ ⟨h.some, hs _ h.some_spec, Inf_le h.some_spec⟩ } } ⟩\n\nend is_coatomistic\nend atomistic\n\n/-- An order is simple iff it has exactly two elements, `⊥` and `⊤`. -/\nclass is_simple_order (α : Type*) [has_le α] [bounded_order α] extends nontrivial α : Prop :=\n(eq_bot_or_eq_top : ∀ (a : α), a = ⊥ ∨ a = ⊤)\n\nexport is_simple_order (eq_bot_or_eq_top)\n\ntheorem is_simple_order_iff_is_simple_order_order_dual [has_le α] [bounded_order α] :\n  is_simple_order α ↔ is_simple_order αᵒᵈ :=\nbegin\n  split; intro i; haveI := i,\n  { exact { exists_pair_ne := @exists_pair_ne α _,\n      eq_bot_or_eq_top := λ a, or.symm (eq_bot_or_eq_top ((order_dual.of_dual a)) : _ ∨ _) } },\n  { exact { exists_pair_ne := @exists_pair_ne αᵒᵈ _,\n      eq_bot_or_eq_top := λ a, or.symm (eq_bot_or_eq_top (order_dual.to_dual a)) } }\nend\n\nlemma is_simple_order.bot_ne_top [has_le α] [bounded_order α] [is_simple_order α] :\n  (⊥ : α) ≠ (⊤ : α) :=\nbegin\n  obtain ⟨a, b, h⟩ := exists_pair_ne α,\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 α] [bounded_order α] [is_simple_order α]\n\ninstance {α} [has_le α] [bounded_order α] [is_simple_order α] : is_simple_order αᵒᵈ :=\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 {α} [has_le α] [bounded_order α] [is_simple_order α] :\n  preorder α :=\n{ le := (≤),\n  le_refl := λ a, by rcases eq_bot_or_eq_top a with rfl|rfl; simp,\n  le_trans := λ 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 α] : linear_order α :=\n{ le_total := λ a b, by rcases eq_bot_or_eq_top a with rfl|rfl; simp,\n  decidable_le := λ a b, if ha : a = ⊥ then is_true (ha.le.trans bot_le) else\n    if hb : b = ⊤ then is_true (le_top.trans hb.ge) else\n      is_false (λ 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 α) }\n\n@[simp] lemma is_atom_top : is_atom (⊤ : α) :=\n⟨top_ne_bot, λ a ha, or.resolve_right (eq_bot_or_eq_top a) (ne_of_lt ha)⟩\n\n@[simp] lemma is_coatom_bot : is_coatom (⊥ : α) := is_atom_dual_iff_is_coatom.1 is_atom_top\n\nlemma bot_covby_top : (⊥ : α) ⋖ ⊤ := is_atom_top.bot_covby\n\nend is_simple_order\n\nnamespace is_simple_order\nsection preorder\nvariables [preorder α] [bounded_order α] [is_simple_order α] {a b : α} (h : a < b)\n\nlemma eq_bot_of_lt : a = ⊥ := (is_simple_order.eq_bot_or_eq_top _).resolve_right h.ne_top\nlemma eq_top_of_lt : b = ⊤ := (is_simple_order.eq_bot_or_eq_top _).resolve_left h.ne_bot\n\nalias eq_bot_of_lt ← has_lt.lt.eq_bot\nalias eq_top_of_lt ← has_lt.lt.eq_top\n\nend preorder\n\nsection bounded_order\n\nvariables [lattice α] [bounded_order α] [is_simple_order α]\n\n/-- A simple partial ordered `bounded_order` induces a lattice.\nThis is not an instance to prevent loops -/\nprotected def lattice {α} [decidable_eq α] [partial_order α] [bounded_order α]\n  [is_simple_order α] : lattice α :=\n@linear_order.to_lattice α (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 α :=\n{ le_sup_inf := λ x y z, by { rcases eq_bot_or_eq_top x with rfl | rfl; simp },\n  .. (infer_instance : lattice α) }\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : is_atomic α :=\n⟨λ b, (eq_bot_or_eq_top b).imp_right (λ h, ⟨⊤, ⟨is_atom_top, ge_of_eq h⟩⟩)⟩\n\n@[priority 100] -- see Note [lower instance priority]\ninstance : is_coatomic α := 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 α] [partial_order α] [bounded_order α] [is_simple_order α]\n\n/-- Every simple lattice is isomorphic to `bool`, regardless of order. -/\n@[simps] def equiv_bool {α} [decidable_eq α] [has_le α] [bounded_order α] [is_simple_order α] :\n  α ≃ bool :=\n{ to_fun := λ x, x = ⊤,\n  inv_fun := λ x, cond x ⊤ ⊥,\n  left_inv := λ x, by { rcases (eq_bot_or_eq_top x) with rfl | rfl; simp [bot_ne_top] },\n  right_inv := λ 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 : α ≃o bool :=\n{ map_rel_iff' := λ 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/-- A simple `bounded_order` is also a `boolean_algebra`. -/\nprotected def boolean_algebra {α} [decidable_eq α] [lattice α] [bounded_order α]\n  [is_simple_order α] : boolean_algebra α :=\n{ compl := λ x, if x = ⊥ then ⊤ else ⊥,\n  sdiff := λ x y, if x = ⊤ ∧ y = ⊥ then ⊤ else ⊥,\n  sdiff_eq := λ 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 := λ 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 := λ x, by rcases eq_bot_or_eq_top x with rfl | rfl; simp,\n  .. (show bounded_order α, by apply_instance),\n  .. is_simple_order.distrib_lattice }\n\nend decidable_eq\n\nvariables [lattice α] [bounded_order α] [is_simple_order α]\nopen_locale classical\n\n/-- A simple `bounded_order` is also complete. -/\nprotected noncomputable def complete_lattice : complete_lattice α :=\n{ Sup := λ s, if ⊤ ∈ s then ⊤ else ⊥,\n  Inf := λ s, if ⊥ ∈ s then ⊥ else ⊤,\n  le_Sup := λ 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 := λ 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 ⊤ con)) },\n    { exact le_top } },\n  Inf_le := λ 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 := λ 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 ⊥ con)) } },\n  .. (infer_instance : lattice α),\n  .. (infer_instance : bounded_order α) }\n\n/-- A simple `bounded_order` is also a `complete_boolean_algebra`. -/\nprotected noncomputable def complete_boolean_algebra : complete_boolean_algebra α :=\n{ infi_sup_le_sup_Inf := λ x s, by { rcases eq_bot_or_eq_top x with rfl | rfl,\n    { simp only [bot_sup_eq, ← Inf_eq_infi], exact le_rfl },\n    { simp only [top_sup_eq, le_top] }, },\n  inf_Sup_le_supr_inf := λ 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, ← 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 α] [is_simple_order α]\nset_option default_priority 100\n\ninstance : is_atomistic α :=\n⟨λ b, (eq_bot_or_eq_top b).elim\n  (λ h, ⟨∅, ⟨h.trans Sup_empty.symm, λ a ha, false.elim (set.not_mem_empty _ ha)⟩⟩)\n  (λ h, ⟨{⊤}, h.trans Sup_singleton.symm, λ a ha, (set.mem_singleton_iff.1 ha).symm ▸ is_atom_top⟩)⟩\n\ninstance : is_coatomistic α := is_atomistic_dual_iff_is_coatomistic.1 is_simple_order.is_atomistic\n\nend is_simple_order\n\ntheorem is_simple_order_iff_is_atom_top [partial_order α] [bounded_order α] :\n  is_simple_order α ↔ is_atom (⊤ : α) :=\n⟨λ h, @is_atom_top _ _ _ h, λ h,\n  { exists_pair_ne := ⟨⊤, ⊥, h.1⟩,\n    eq_bot_or_eq_top := λ a, ((eq_or_lt_of_le le_top).imp_right (h.2 a)).symm }⟩\n\ntheorem is_simple_order_iff_is_coatom_bot [partial_order α] [bounded_order α] :\n  is_simple_order α ↔ is_coatom (⊥ : α) :=\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 α] [order_bot α] {a : α} :\n  is_simple_order (Iic a) ↔ is_atom a :=\nis_simple_order_iff_is_atom_top.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  ⟨λ h b ab, subtype.mk_eq_mk.1 (h ⟨b, le_of_lt ab⟩ ab),\n    λ h ⟨b, hab⟩ hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))⟩\n\ntheorem is_simple_order_Ici_iff_is_coatom [partial_order α] [order_top α] {a : α} :\n  is_simple_order (Ici a) ↔ is_coatom a :=\nis_simple_order_iff_is_coatom_bot.trans $ and_congr (not_congr subtype.mk_eq_mk)\n  ⟨λ h b ab, subtype.mk_eq_mk.1 (h ⟨b, le_of_lt ab⟩ ab),\n    λ h ⟨b, hab⟩ hbotb, subtype.mk_eq_mk.2 (h b (subtype.mk_lt_mk.1 hbotb))⟩\n\nend set\n\nnamespace order_embedding\n\nvariables [partial_order α] [partial_order β]\n\nlemma is_atom_of_map_bot_of_image [order_bot α] [order_bot β] (f : β ↪o α) (hbot : f ⊥ = ⊥) {b : β}\n  (hb : is_atom (f b)) : is_atom b :=\nby { simp only [←bot_covby_iff] at hb ⊢, exact covby.of_image f (hbot.symm ▸ hb) }\n\nlemma is_coatom_of_map_top_of_image [order_top α] [order_top β] (f : β ↪o α) (htop : f ⊤ = ⊤)\n  {b : β} (hb : is_coatom (f b)) : is_coatom b :=\nf.dual.is_atom_of_map_bot_of_image htop hb\n\nend order_embedding\n\nnamespace galois_insertion\n\nvariables [partial_order α] [partial_order β]\n\nlemma is_atom_of_u_bot [order_bot α] [order_bot β] {l : α → β} {u : β → α}\n  (gi : galois_insertion l u) (hbot : u ⊥ = ⊥) {b : β} (hb : is_atom (u b)) : is_atom b :=\norder_embedding.is_atom_of_map_bot_of_image\n  ⟨⟨u, gi.u_injective⟩, @galois_insertion.u_le_u_iff _ _ _ _ _ _ gi⟩ hbot hb\n\nlemma is_atom_iff [order_bot α] [is_atomic α] [order_bot β] {l : α → β} {u : β → α}\n  (gi : galois_insertion l u) (hbot : u ⊥ = ⊥) (h_atom : ∀ a, is_atom a → u (l a) = a) (a : α) :\n  is_atom (l a) ↔ is_atom a :=\nbegin\n  refine ⟨λ hla, _, λ ha, gi.is_atom_of_u_bot hbot ((h_atom a ha).symm ▸ ha)⟩,\n  obtain ⟨a', ha', hab'⟩ := (eq_bot_or_exists_atom_le (u (l a))).resolve_left\n    (hbot ▸ λ h, hla.1 (gi.u_injective h)),\n  have := (hla.le_iff.mp $ (gi.l_u_eq (l a) ▸ gi.gc.monotone_l hab' : l a' ≤ l a)).resolve_left\n    (λ h, ha'.1 (hbot ▸ (h_atom a' ha') ▸ congr_arg u h)),\n  have haa' : a = a' := (ha'.le_iff.mp $\n    (gi.gc.le_u_l a).trans_eq (h_atom a' ha' ▸ congr_arg u this.symm)).resolve_left\n    (mt (congr_arg l) (gi.gc.l_bot.symm ▸ hla.1)),\n  exact haa'.symm ▸ ha'\nend\n\nlemma is_atom_iff' [order_bot α] [is_atomic α] [order_bot β] {l : α → β} {u : β → α}\n  (gi : galois_insertion l u) (hbot : u ⊥ = ⊥) (h_atom : ∀ a, is_atom a → u (l a) = a) (b : β) :\n  is_atom (u b) ↔ is_atom b :=\nby rw [←gi.is_atom_iff hbot h_atom, gi.l_u_eq]\n\n\n\nlemma is_coatom_iff [order_top α] [is_coatomic α] [order_top β] {l : α → β} {u : β → α}\n  (gi : galois_insertion l u) (h_coatom : ∀ a : α, is_coatom a → u (l a) = a) (b : β) :\n  is_coatom (u b) ↔ is_coatom b :=\nbegin\n  refine ⟨λ hb, gi.is_coatom_of_image hb, λ hb, _⟩,\n  obtain ⟨a, ha, hab⟩ := (eq_top_or_exists_le_coatom (u b)).resolve_left\n    (λ h, hb.1 $ (gi.gc.u_top ▸ gi.l_u_eq ⊤ : l ⊤ = ⊤) ▸ gi.l_u_eq b ▸ congr_arg l h),\n  have : l a = b := (hb.le_iff.mp ((gi.l_u_eq b ▸ gi.gc.monotone_l hab) : b ≤ l a)).resolve_left\n    (λ hla, ha.1 (gi.gc.u_top ▸ h_coatom a ha ▸ congr_arg u hla)),\n  exact this ▸ (h_coatom a ha).symm ▸ ha,\nend\n\nend galois_insertion\n\nnamespace galois_coinsertion\n\nvariables [partial_order α] [partial_order β]\n\nlemma is_coatom_of_l_top [order_top α] [order_top β] {l : α → β} {u : β → α}\n  (gi : galois_coinsertion l u) (hbot : l ⊤ = ⊤) {a : α} (hb : is_coatom (l a)) : is_coatom a :=\ngi.dual.is_atom_of_u_bot hbot hb.dual\n\nlemma is_coatom_iff [order_top α] [order_top β] [is_coatomic β] {l : α → β} {u : β → α}\n  (gi : galois_coinsertion l u) (htop : l ⊤ = ⊤) (h_coatom : ∀ b, is_coatom b → l (u b) = b)\n  (b : β) : is_coatom (u b) ↔ is_coatom b :=\ngi.dual.is_atom_iff htop h_coatom b\n\nlemma is_coatom_iff' [order_top α] [order_top β] [is_coatomic β] {l : α → β} {u : β → α}\n  (gi : galois_coinsertion l u) (htop : l ⊤ = ⊤) (h_coatom : ∀ b, is_coatom b → l (u b) = b)\n  (a : α) : is_coatom (l a) ↔ is_coatom a :=\ngi.dual.is_atom_iff' htop h_coatom a\n\nlemma is_atom_of_image [order_bot α] [order_bot β] {l : α → β} {u : β → α}\n  (gi : galois_coinsertion l u) {a : α} (hb : is_atom (l a)) : is_atom a :=\ngi.dual.is_coatom_of_image hb.dual\n\nlemma is_atom_iff [order_bot α] [order_bot β] [is_atomic β] {l : α → β} {u : β → α}\n  (gi : galois_coinsertion l u) (h_atom : ∀ b, is_atom b → l (u b) = b) (a : α) :\n  is_atom (l a) ↔ is_atom a :=\ngi.dual.is_coatom_iff h_atom a\n\nend galois_coinsertion\n\nnamespace order_iso\n\nvariables [partial_order α] [partial_order β]\n\n@[simp] lemma is_atom_iff [order_bot α] [order_bot β] (f : α ≃o β) (a : α) :\n  is_atom (f a) ↔ is_atom a :=\n⟨f.to_galois_coinsertion.is_atom_of_image,\n λ ha, f.to_galois_insertion.is_atom_of_u_bot (map_bot f.symm) $ (f.symm_apply_apply a).symm ▸ ha⟩\n\n@[simp] lemma is_coatom_iff [order_top α] [order_top β] (f : α ≃o β) (a : α) :\n  is_coatom (f a) ↔ is_coatom a :=\nf.dual.is_atom_iff a\n\nlemma is_simple_order_iff [bounded_order α] [bounded_order β] (f : α ≃o β) :\n  is_simple_order α ↔ is_simple_order β :=\nby rw [is_simple_order_iff_is_atom_top, is_simple_order_iff_is_atom_top,\n  ← f.is_atom_iff ⊤, f.map_top]\n\nlemma is_simple_order [bounded_order α] [bounded_order β] [h : is_simple_order β] (f : α ≃o β) :\n  is_simple_order α :=\nf.is_simple_order_iff.mpr h\n\nprotected lemma is_atomic_iff [order_bot α] [order_bot β] (f : α ≃o β) :\n  is_atomic α ↔ is_atomic β :=\nby simp only [is_atomic_iff, f.surjective.forall, f.surjective.exists, ← map_bot f, f.eq_iff_eq,\n  f.le_iff_le, f.is_atom_iff]\n\nprotected lemma is_coatomic_iff [order_top α] [order_top β] (f : α ≃o β) :\n  is_coatomic α ↔ is_coatomic β :=\nby simp only [← is_atomic_dual_iff_is_coatomic, f.dual.is_atomic_iff]\n\nend order_iso\n\nsection is_modular_lattice\nvariables [lattice α] [bounded_order α] [is_modular_lattice α]\n\nnamespace is_compl\nvariables {a b : α} (hc : is_compl a b)\ninclude hc\n\nlemma is_atom_iff_is_coatom : is_atom a ↔ 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 ↔ is_atom b := hc.symm.is_atom_iff_is_coatom.symm\n\nend is_compl\n\nvariables [complemented_lattice α]\n\nlemma is_coatomic_of_is_atomic_of_complemented_lattice_of_is_modular [is_atomic α] :\n  is_coatomic α :=\n⟨λ x, begin\n  rcases exists_is_compl x with ⟨y, xy⟩,\n  apply (eq_bot_or_exists_atom_le y).imp _ _,\n  { rintro rfl,\n    exact eq_top_of_is_compl_bot xy },\n  { rintro ⟨a, ha, ay⟩,\n    rcases exists_is_compl (xy.symm.Iic_order_iso_Ici ⟨a, ay⟩) with ⟨⟨b, xb⟩, hb⟩,\n    refine ⟨↑(⟨b, xb⟩ : set.Ici x), is_coatom.of_is_coatom_coe_Ici _, xb⟩,\n    rw [← hb.is_atom_iff_is_coatom, order_iso.is_atom_iff],\n    apply ha.Iic }\nend⟩\n\nlemma is_atomic_of_is_coatomic_of_complemented_lattice_of_is_modular [is_coatomic α] :\n  is_atomic α :=\nis_coatomic_dual_iff_is_atomic.1 is_coatomic_of_is_atomic_of_complemented_lattice_of_is_modular\n\ntheorem is_atomic_iff_is_coatomic : is_atomic α ↔ is_coatomic α :=\n⟨λ h, @is_coatomic_of_is_atomic_of_complemented_lattice_of_is_modular _ _ _ _ _ h,\n  λ h, @is_atomic_of_is_coatomic_of_complemented_lattice_of_is_modular _ _ _ _ _ h⟩\n\nend is_modular_lattice\n\nnamespace set\n\nlemma is_atom_singleton (x : α) : is_atom ({x} : set α) :=\n⟨singleton_ne_empty _, λ s hs, ssubset_singleton_iff.mp hs⟩\n\nlemma is_atom_iff (s : set α) : is_atom s ↔ ∃ x, s = {x} :=\nbegin\n  refine ⟨_, by { rintro ⟨x, rfl⟩, exact is_atom_singleton x }⟩,\n  rw [is_atom_iff, bot_eq_empty, ←nonempty_iff_ne_empty],\n  rintro ⟨⟨x, hx⟩, hs⟩,\n  exact ⟨x, eq_singleton_iff_unique_mem.2 ⟨hx, λ y hy,\n    (hs {y} (singleton_ne_empty _) (singleton_subset_iff.2 hy) hx).symm⟩⟩,\nend\n\nlemma is_coatom_iff (s : set α) : is_coatom s ↔ ∃ x, s = {x}ᶜ :=\nby simp_rw [is_compl_compl.is_coatom_iff_is_atom, is_atom_iff, @eq_comm _ s, compl_eq_comm]\n\nlemma is_coatom_singleton_compl (x : α) : is_coatom ({x}ᶜ : set α) :=\n(is_coatom_iff {x}ᶜ).mpr ⟨x, rfl⟩\n\ninstance : is_atomistic (set α) :=\n{ eq_Sup_atoms := λ s, ⟨(λ x, {x}) '' s,\n    by rw [Sup_eq_sUnion, sUnion_image, bUnion_of_singleton],\n    by { rintro - ⟨x, hx, rfl⟩, exact is_atom_singleton x }⟩ }\n\ninstance : is_coatomistic (set α) :=\n{ eq_Inf_coatoms := λ s, ⟨(λ x, {x}ᶜ) '' sᶜ,\n    by rw [Inf_eq_sInter, sInter_image, ←compl_Union₂, bUnion_of_singleton, compl_compl],\n    by { rintro - ⟨x, hx, rfl⟩, exact is_coatom_singleton_compl x }⟩ }\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/atoms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7566060221518357}}
{"text": "/- Spatial Reasoning Problem 01 -/\n/- It can be found at: SpatialQs.txt -/\n\n/- (1) A is on the right of B. C is on the left of B. Hence, A is on the right of C -/\n\nconstant U : Type\n\nconstants A B C : U\nconstants Left Right : U\nconstant orientation : U → U → U → Prop\n\naxiom a1 : orientation A B Right\naxiom a2 : orientation C B Left\n\n/- axioms to be added to SUMO -/\naxiom a3 : ∀ X Y Z R, (orientation X Y R) ∧ (orientation Y Z R) → (orientation X Z R)\naxiom a4 : ∀ OBJ1 OBJ2, (orientation OBJ1 OBJ2 Right) ↔ (orientation OBJ2 OBJ1 Left)\n\n/- Demonstration Start -/\ntheorem A_is_on_the_right_of_C : orientation A C Right :=\nbegin\n    have h, from (a4 _ _).elim_right a2,\n    apply a3 _ _ _ _,\n    apply and.intro a1 h\nend\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-01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248157222395, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7565086090337055}}
{"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.cardinal.finite\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 ∣ fintype.card G`\n- `index_eq_mul_of_le` : If `H ≤ K`, then `H.index = K.index * (H.subgroup_of K).index`\n- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ 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 : ℕ :=\nnat.card (G ⧸ 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 : ℕ :=\n(H.subgroup_of K).index\n\n@[to_additive] lemma index_comap_of_surjective {G' : Type*} [group G'] {f : G' →* 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 : ∀ x y : G', setoid.r x y ↔ setoid.r (f x) (f y),\n  { simp only [quotient_group.left_rel_apply],\n    exact λ x y, iff_of_eq (congr_arg (∈ H) (by rw [f.map_mul, f.map_inv])) },\n  refine cardinal.to_nat_congr (equiv.of_bijective (quotient.map' f (λ x y, (key x y).mp)) ⟨_, _⟩),\n  { simp_rw [←quotient.eq'] at key,\n    refine quotient.ind' (λ x, _),\n    refine quotient.ind' (λ y, _),\n    exact (key x y).mpr },\n  { refine quotient.ind' (λ x, _),\n    obtain ⟨y, hy⟩ := hf x,\n    exact ⟨y, (quotient.map'_mk' f _ y).trans (congr_arg quotient.mk' hy)⟩ },\nend\n\n@[to_additive] lemma index_comap {G' : Type*} [group G'] (f : G' →* 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 relindex_mul_index] lemma relindex_mul_index (h : H ≤ K) :\n  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 ≤ K) : K.index ∣ H.index :=\ndvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)\n\n@[to_additive] lemma relindex_dvd_index_of_le (h : H ≤ K) : H.relindex K ∣ H.index :=\ndvd_of_mul_right_eq K.index (relindex_mul_index h)\n\n@[to_additive] lemma relindex_subgroup_of (hKL : K ≤ 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\nvariables (H K L)\n\n@[to_additive relindex_mul_relindex] lemma relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) :\n  H.relindex K * K.relindex L = H.relindex L :=\nbegin\n  rw [←relindex_subgroup_of hKL],\n  exact relindex_mul_index (λ x hx, hHK hx),\nend\n\n@[to_additive] lemma inf_relindex_right : (H ⊓ K).relindex K = H.relindex K :=\nbegin\n  rw [←subgroup_of_map_subtype, relindex, relindex, subgroup_of, comap_map_eq_self_of_injective],\n  exact subtype.coe_injective,\nend\n\n@[to_additive] lemma inf_relindex_left : (H ⊓ K).relindex H = K.relindex H :=\nby rw [inf_comm, inf_relindex_right]\n\n@[to_additive relindex_inf_mul_relindex]\nlemma relindex_inf_mul_relindex : H.relindex (K ⊓ L) * K.relindex L = (H ⊓ K).relindex L :=\nby rw [←inf_relindex_right H (K ⊓ L), ←inf_relindex_right K L, ←inf_relindex_right (H ⊓ K) L,\n  inf_assoc, relindex_mul_relindex (H ⊓ (K ⊓ L)) (K ⊓ L) L inf_le_right inf_le_right]\n\n@[to_additive]\nlemma inf_relindex_eq_relindex_sup [K.normal] : (H ⊓ K).relindex H = K.relindex (H ⊔ K) :=\ncardinal.to_nat_congr (quotient_group.quotient_inf_equiv_prod_normal_quotient H K).to_equiv\n\n@[to_additive] lemma relindex_eq_relindex_sup [K.normal] : K.relindex H = K.relindex (H ⊔ K) :=\nby rw [←inf_relindex_left, inf_relindex_eq_relindex_sup]\n\n@[to_additive] lemma relindex_dvd_index_of_normal [H.normal] : H.relindex K ∣ H.index :=\n(relindex_eq_relindex_sup K H).symm ▸ relindex_dvd_index_of_le le_sup_right\n\nvariables {H K}\n\n@[to_additive] lemma relindex_dvd_of_le_left (hHK : H ≤ K) : K.relindex L ∣ H.relindex L :=\nbegin\n  apply dvd_of_mul_left_eq ((H ⊓ L).relindex (K ⊓ L)),\n  rw [←inf_relindex_right H L, ←inf_relindex_right K L],\n  exact relindex_mul_relindex (H ⊓ L) (K ⊓ L) L (inf_le_inf_right L hHK) inf_le_right,\nend\n\nvariables (H K)\n\n@[simp, to_additive] lemma index_top : (⊤ : subgroup G).index = 1 :=\ncardinal.to_nat_eq_one_iff_unique.mpr ⟨quotient_group.subsingleton_quotient_top, ⟨1⟩⟩\n\n@[simp, to_additive] lemma index_bot : (⊥ : 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] : (⊥ : subgroup G).index = fintype.card G :=\nindex_bot.trans nat.card_eq_fintype_card\n\n@[simp, to_additive] lemma relindex_top_left : (⊤ : subgroup G).relindex H = 1 :=\nindex_top\n\n@[simp, to_additive] lemma relindex_top_right : H.relindex ⊤ = H.index :=\nby rw [←relindex_mul_index (show H ≤ ⊤, from le_top), index_top, mul_one]\n\n@[simp, to_additive] lemma relindex_bot_left : (⊥ : 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  (⊥ : 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 ⊥ = 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 [←relindex_bot_left, ←index_bot], exact relindex_mul_index bot_le }\n\n@[to_additive] lemma index_map {G' : Type*} [group G'] (f : G →* G') :\n  (H.map f).index = (H ⊔ f.ker).index * f.range.index :=\nby rw [←comap_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 →* G'}\n  (hf : function.surjective f) : (H.map f).index ∣ 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 →* G'}\n  (hf : f.ker ≤ H) : H.index ∣ (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 →* G'}\n  (hf1 : function.surjective f) (hf2 : f.ker ≤ 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 ⧸ H)] :\n  H.index = fintype.card (G ⧸ 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 [←relindex_bot_left_eq_card, ←index_bot_eq_card, mul_comm]; exact relindex_mul_index bot_le\n\n@[to_additive] lemma index_dvd_card [fintype G] : H.index ∣ fintype.card G :=\nbegin\n  classical,\n  exact ⟨fintype.card H, H.index_mul_card.symm⟩,\nend\n\nvariables {H K L}\n\n@[to_additive]\nlemma relindex_eq_zero_of_le_left (hHK : H ≤ K) (hKL : K.relindex L = 0) : H.relindex L = 0 :=\neq_zero_of_zero_dvd (hKL ▸ (relindex_dvd_of_le_left L hHK))\n\n@[to_additive]\nlemma relindex_eq_zero_of_le_right (hKL : K ≤ L) (hHK : H.relindex K = 0) : H.relindex L = 0 :=\ncardinal.to_nat_apply_of_aleph_0_le (le_trans (le_of_not_lt (λ h, cardinal.mk_ne_zero _\n  ((cardinal.cast_to_nat_of_lt_aleph_0 h).symm.trans (cardinal.nat_cast_inj.mpr hHK))))\n    (quotient_subgroup_of_embedding_of_le H hKL).cardinal_le)\n\n@[to_additive] lemma relindex_le_of_le_left (hHK : H ≤ K) (hHL : H.relindex L ≠ 0) :\n  K.relindex L ≤ H.relindex L :=\nnat.le_of_dvd (nat.pos_of_ne_zero hHL) (relindex_dvd_of_le_left L hHK)\n\n@[to_additive] lemma relindex_le_of_le_right (hKL : K ≤ L) (hHL : H.relindex L ≠ 0) :\n  H.relindex K ≤ H.relindex L :=\ncardinal.to_nat_le_of_le_of_lt_aleph_0 (lt_of_not_ge (mt cardinal.to_nat_apply_of_aleph_0_le hHL))\n  (cardinal.mk_le_of_injective (quotient_subgroup_of_embedding_of_le H hKL).2)\n\n@[to_additive] lemma relindex_ne_zero_trans (hHK : H.relindex K ≠ 0) (hKL : K.relindex L ≠ 0) :\n  H.relindex L ≠ 0 :=\nλ h, mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K ⊓ L ≤ 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\n@[to_additive] lemma relindex_inf_ne_zero (hH : H.relindex L ≠ 0) (hK : K.relindex L ≠ 0) :\n  (H ⊓ K).relindex L ≠ 0 :=\nbegin\n  replace hH : H.relindex (K ⊓ L) ≠ 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH,\n  rw ← inf_relindex_right at hH hK ⊢,\n  rw inf_assoc,\n  exact relindex_ne_zero_trans hH hK,\nend\n\n@[to_additive] lemma index_inf_ne_zero (hH : H.index ≠ 0) (hK : K.index ≠ 0) : (H ⊓ K).index ≠ 0 :=\nbegin\n  rw ← relindex_top_right at hH hK ⊢,\n  exact relindex_inf_ne_zero hH hK,\nend\n\n@[to_additive] lemma relindex_inf_le : (H ⊓ K).relindex L ≤ H.relindex L * K.relindex L :=\nbegin\n  by_cases h : H.relindex L = 0,\n  { exact (le_of_eq (relindex_eq_zero_of_le_left (by exact inf_le_left) h)).trans (zero_le _) },\n  rw [←inf_relindex_right, inf_assoc, ←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),\nend\n\n@[to_additive] lemma index_inf_le : (H ⊓ K).index ≤ H.index * K.index :=\nby simp_rw [←relindex_top_right, relindex_inf_le]\n\n@[simp, to_additive index_eq_one] lemma index_eq_one : H.index = 1 ↔ H = ⊤ :=\n⟨λ h, quotient_group.subgroup_eq_top_of_subsingleton H (cardinal.to_nat_eq_one_iff_unique.mp h).1,\n  λ h, (congr_arg index h).trans index_top⟩\n\n@[to_additive] lemma index_ne_zero_of_fintype [hH : fintype (G ⧸ H)] : H.index ≠ 0 :=\nby { rw index_eq_card, exact fintype.card_ne_zero }\n\n/-- Finite index implies finite quotient. -/\n@[to_additive \"Finite index implies finite quotient.\"]\nnoncomputable def fintype_of_index_ne_zero (hH : H.index ≠ 0) : fintype (G ⧸ H) :=\n(cardinal.lt_aleph_0_iff_fintype.mp (lt_of_not_ge (mt cardinal.to_nat_apply_of_aleph_0_le hH))).some\n\n@[to_additive one_lt_index_of_ne_top]\nlemma one_lt_index_of_ne_top [fintype (G ⧸ H)] (hH : H ≠ ⊤) : 1 < H.index :=\nnat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨index_ne_zero_of_fintype, mt index_eq_one.mp hH⟩\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/index.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7563594021566024}}
{"text": "universe u\n\nnamespace one\n  /-\n  As an exercise, we encourage you to use do_twice and double to \n  define functions that quadruple their input, \n  and multiply the input by 8. \n  As a further exercise, we encourage you to try defining a \n  function Do_Twice : ((ℕ → ℕ) → (ℕ → ℕ)) → (ℕ → ℕ) → (ℕ → ℕ) \n  which applies its argument twice, so that Do_Twice do_twice \n  is a function that applies its input four times. \n  Then evaluate Do_Twice do_twice double 2.\n  -/\n\n  -- reference code from section 2.4\n  def double : ℕ → ℕ := λ x, x + x\n  def square : ℕ → ℕ := λ x, x * x\n  def do_twice : (ℕ → ℕ) → ℕ → ℕ := λ f x, f (f x)\n  def compose (α β γ : Type) (g : β → γ) (f : α → β) (x : α) : γ := g (f x)\n\n  -- solution\n  def Do_Twice {α :Type} (f: (α → α) → (α → α)) (g: α → α) (x: α) := f g x\n  #reduce @Do_Twice ℕ do_twice double 2\n  #reduce Do_Twice do_twice double 2\nend one\n\nnamespace two\n  /- \n  Above, we discussed the process of “currying” a function, \n  that is, taking a function f (a, b) that takes an ordered \n  pair as an argument, and recasting it as a function f' a b \n  that takes two arguments successively. \n  As another exercise, we encourage you to complete the \n  following definitions, which “curry” and “uncurry” a function.\n  -/\n  def curry (α β γ : Type) (f : α × β → γ) : α → β → γ \n  := λ (a: α), (λ (b: β), f (a, b) )\n  def uncurry (α β γ : Type) (f : α → β → γ) : α × β → γ \n  := λ (x : α × β), f x.1 x.2\nend two\n\nnamespace three\n  /-\n  Above, we used the example vec α n for vectors of elements of \n  type α of length n. \n  Declare a constant vec_add that could represent a \n  function that adds two vectors of natural numbers of \n  the same length, and a constant vec_reverse that can \n  represent a function that reverses its argument. \n  Use implicit arguments for parameters that can be inferred. \n  Declare some variables and check some expressions \n  involving the constants that you have declared.\n  -/\n\n  -- dependant types reference code from section 2.9\n\n  constant cons   : Π {α : Type u}, α → list α → list α\n  constant nil    : Π {α : Type u}, list α\n  constant append : Π {α : Type u}, list α → list α → list α\n\n  variable  α : Type\n  variable  a : α\n  variables l1 l2 : list α\n\n  #check cons a nil\n  #check append (cons a nil) l1\n  #check append (append (cons a nil) l1) l2\n\n  -- vector reference code from section 2.8\n\n  constant vec : Type u → ℕ → Type u\n\n  constant vec_empty : Π α : Type u, vec α 0\n  constant vec_cons : Π (α : Type u) (n : ℕ), α → vec α n → vec α (n + 1)\n  constant vec_append : Π (α : Type u) (n m : ℕ),  vec α m → vec α n → vec α (n + m)\n\n  #check vec_empty ℕ\n  #check (vec_cons ℕ 0) 9 (vec_empty ℕ) -- vec of len 1\n  #check (vec_cons ℕ 1) 9 ((vec_cons ℕ 0) 9 (vec_empty ℕ)) -- vec of len 2\n  #check vec_append ℕ 2 2 ((vec_cons ℕ 1) 9 ((vec_cons ℕ 0) 9 (vec_empty ℕ))) ((vec_cons ℕ 1) 9 ((vec_cons ℕ 0) 9 (vec_empty ℕ))) -- vec of len 4\n\n  -- solution\n\n  constant Vec_empty : Π {α : Type u}, vec α 0\n  constant Vec_cons : Π {α : Type u} {n: ℕ}, α → vec α n → vec α (n + 1)\n  constant Vec_append : Π {α : Type u} {n m: ℕ},  vec α m → vec α n → vec α (n + m)\n\n  constant Vec_add : Π {α : Type u} {n m: ℕ}, vec α n → vec α m → vec α (n + m)\n  constant Vec_reverses : Π {α : Type u} {n: ℕ}, vec α n → vec α n\n\n  #check @Vec_empty\n  #check Vec_cons 9 Vec_empty -- vec of len 1\n  #check Vec_cons 9 (Vec_cons 9 Vec_empty) -- vec of len 2\n  #check Vec_append (Vec_cons 9 (Vec_cons 9 Vec_empty)) (Vec_cons 9 (Vec_cons 9 Vec_empty)) -- vec of len 4\n\n  #check Vec_add (Vec_append (Vec_cons 9 (Vec_cons 9 Vec_empty)) (Vec_cons 9 (Vec_cons 9 Vec_empty))) (Vec_cons 9 (Vec_cons 9 Vec_empty))  -- vec of len 6\n  #check Vec_reverses (Vec_cons 9 (Vec_cons 9 Vec_empty))\nend three\n\nnamespace four\n  /-\n  Similarly, declare a constant matrix so that matrix α m n could represent the \n  type of m by n matrices. \n  Declare some constants to represent functions on this type, \n  such as matrix addition and multiplication, and (using vec) \n  multiplication of a matrix by a vector. \n  Once again, declare some variables and check some expressions\n  involving the constants that you have declared.\n  -/\n\n  -- solution\n  open three\n\n  constant mat : Type u → ℕ → ℕ → Type u\n\n  constant mat_empty : Π {α : Type u}, mat α 0 0\n  constant mat_concat_vecs_as_rows : Π {α : Type u} {n: ℕ}, vec α n → vec α n → mat α 2 n\n  constant mat_concat_vecs_as_cols : Π {α : Type u} {n: ℕ}, vec α n → vec α n → mat α n 2\n\n  #check mat_concat_vecs_as_rows Vec_empty Vec_empty  -- 2x0 matrix\n  #check mat_concat_vecs_as_rows (Vec_cons 9 (Vec_cons 9 Vec_empty)) (Vec_cons 9 (Vec_cons 9 Vec_empty))  -- 2x2 matrix\n\n  constant mat_add : Π {α : Type u} {n m: ℕ},  mat α n m → mat α n m → mat α n m\n  constant mat_mul : Π {α : Type u} {n m t: ℕ},  mat α n m → mat α m t → mat α n t\n  constant mat_mul_by_vec : Π {α : Type u} {n m: ℕ},  mat α n m → vec α m → vec α n\nend four", "meta": {"author": "mbrg", "repo": "lean-tutorial-reference", "sha": "46cb983e8547fc39e43480c37e6cf4dd3e085485", "save_path": "github-repos/lean/mbrg-lean-tutorial-reference", "path": "github-repos/lean/mbrg-lean-tutorial-reference/lean-tutorial-reference-46cb983e8547fc39e43480c37e6cf4dd3e085485/Theorem Proving in Lean/2.dependent_type_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8723473647220786, "lm_q1q2_score": 0.7563563601832288}}
{"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 : ℕ) (s : string) := s\n\n/-\na. What is it's return type? Answer:\n-/\n\n/-\nb. What is the type of (f 5)? Answer:\n-/\n\n/-\nc. What is the value of (f 0 \"yay\")\n-/\n\n/-\nd. What is the type of this function?\n-/\n\n\n/- 2.\nDefine three functions called square,\nsquare', and square'', each of type\nℕ → ℕ. 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-/\n\n\ndef square (n : ℕ) : ℕ := n^2\n\ndef square' (n : ℕ) : ℕ := \nbegin\nexact n^2\nend\n\ndef square'' : ℕ → ℕ :=\nλ 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-/\n\nlemma square_3_9 : eq (square 3) 9 := 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-/\n\n\ndef lastFirst (s1 s2 : string) : string :=\n    s2 ++ \", \" ++ s1\n\nexample : \n    lastFirst \"Orson\" \"Welles\" = \"Welles, Orson\" := rfl\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 ℕ → ℕ. It must return a function,\nalso of type ℕ to ℕ, 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 : (ℕ → ℕ) → (ℕ → ℕ) :=\n    λ f : ℕ → ℕ, \n        λ n, f(f(f(n)))\n\n#reduce apply3 (λ n : ℕ, n^2) 2\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-/\n\ndef len2 (s1 s2 : string) : ℕ :=\n    string.length (s1 ++ s2)\n\n/- 7.\nUse \"example\" to prove that there is a\nfunction of the following type:\n\n((ℕ → ℕ) → (ℕ → ℕ)) →\n    ((ℕ → ℕ) → ℕ) →\n        ((ℕ → ℕ) → ℕ)\n-/\n\nexample : ((ℕ → ℕ) → (ℕ → ℕ)) →\n          ((ℕ → ℕ) → ℕ) →\n          ((ℕ → ℕ) → ℕ) :=\nλ f, \n    λ g, \n        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:\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 ∧ in answering.\nYou might also want to use = or ≠.\n\nAnswer:\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:\n\nThe set of all values appearing as the second\nelement of any pair in P.\n\nAnswer:\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:\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:\n\nThe property of being one-to-one and onto.\n\nAnswer:\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 ≠ 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 → 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 t1eqt2 :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-/\n\naxiom P : T → Prop\naxiom pf : P t1\n\nexample : P t2 := eq.subst t1eqt2 pf\n\n/- 12 c.\n\nNow use \"example\" to assert, and then\nprove, that t2 also has property P.\n-/\n\n\n/- 13 a.\nDefine eq_1_0 to be the proposition, 1 = 0.\n-/\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-/\n\n\n/- 13 c.\nWrite a function, w, that takes three\nvalues, a, b, and c of type ℕ, and that\nalso takes proofs, cb : c = b, and\nba : b = a, and that returns a proof\nthat a = c.\n-/\n\n\n\n/- 13d.\n\nWhat is the type of this function?\n\nAnswer:\n\nWhat is the form of this proposition?\n\nAnswer:\n\nWhat's the form the proposition after the\ncomma?\n\nAnswer:\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 : ∀ (s : string), s = s :=\n_\n\n\n-- lambda expresion\nexample : ∀ (n : ℕ), ∀ (m : ℕ), true :=\n_\n\n\n-- tactic script\nexample : ∀ (T : Type), ∀ (t : T), eq t t :=\n_\n\n\n-- tactic script\nexample :\n    ∀ (T : Type),\n    ∀ (P : T → Prop),\n    ∀ t1 t2 : T,\n    ∀ Pt1 : P t1,\n    ∀ t2t1 : t2 = t1,\n    P t2 :=\n_\n\n/-\nThe following problems involve implications.\nFor example, false → 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 : ∀ (P : Prop), false → P :=\n_\n\n\n-- tactic script\nexample : ∀ (P : Prop), false → P :=\n_\n\n\n-- lambda expression\nexample : ∀ (P Q : Prop), P ∧ Q → Q ∧ P :=\n_\n\n-- tactic script\nexample : ∀ (P Q : Prop), P ∧ Q → Q ∧ P :=\n_\n\n\n\n-- tactic script\nexample :\n    ∀ T : Type,\n    ∀ (t1 t2 t3 : T),\n    t1 = t2 ∧ t2 = t3 → 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\n\n/-\nAnother\n\nProve:  ∀(A B C: Prop), A ∧ (B ∧ C) →  (A ∧ B) ∧ C \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/hw5-exam1-practice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8670357477770336, "lm_q1q2_score": 0.7563563583254533}}
{"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.order.field.basic\nimport analysis.specific_limits.basic\nimport ring_theory.polynomial.bernstein\nimport topology.continuous_function.polynomial\nimport topology.continuous_function.compact\n\n/-!\n# Bernstein approximations and Weierstrass' theorem\n\nWe prove that the Bernstein approximations\n```\n∑ k : fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity.\n\nOur proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], §7D.\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 `δ`,\n  obtaining a bound of `(4 * n * δ^2)⁻¹`, 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], ℝ)`,\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 ν : ℕ) : C(I, ℝ) :=\n(bernstein_polynomial ℝ n ν).to_continuous_map_on I\n\n@[simp] lemma bernstein_apply (n ν : ℕ) (x : I) :\n  bernstein n ν x = n.choose ν * x^ν * (1-x)^(n-ν) :=\nbegin\n  dsimp [bernstein, polynomial.to_continuous_map_on, polynomial.to_continuous_map,\n    bernstein_polynomial],\n  simp,\nend\n\nlemma bernstein_nonneg {n ν : ℕ} {x : I} :\n  0 ≤ bernstein n ν 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 : ℕ} (k : fin (n+1)) : I :=\n⟨(k : ℝ) / n,\n  begin\n    cases n,\n    { norm_num },\n    { have h₁ : 0 < (n.succ : ℝ) := by exact_mod_cast (nat.succ_pos _),\n      have h₂ : ↑k ≤ n.succ := by exact_mod_cast (fin.le_last k),\n      rw [set.mem_Icc, le_div_iff h₁, div_le_iff h₁],\n      norm_cast,\n      simp [h₂], },\n  end⟩\n\nlocal postfix `/ₙ`:90 := z\n\nlemma probability (n : ℕ) (x : I) :\n  ∑ k : fin (n+1), bernstein n k x = 1 :=\nbegin\n  have := bernstein_polynomial.sum ℝ n,\n  apply_fun (λ p, polynomial.aeval (x : ℝ) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range] at this,\n  exact this,\nend\n\nlemma variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :\n  ∑ k : fin (n+1), (x - k/ₙ : ℝ)^2 * bernstein n k x = x * (1-x) / n :=\nbegin\n  have h' : (n : ℝ) ≠ 0 := ne_of_gt h,\n  apply_fun (λ x : ℝ, x * n) using group_with_zero.mul_right_injective h',\n  apply_fun (λ x : ℝ, 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 ℝ n,\n  apply_fun (λ p, polynomial.aeval (x : ℝ) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range, ←polynomial.nat_cast_mul] at this,\n  convert this using 1,\n  { congr' 1, funext k,\n    rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ←mul_assoc, ←mul_assoc],\n    congr' 1,\n    field_simp [h],\n    ring, },\n  { ring, },\nend\n\nend bernstein\n\nopen bernstein\n\nlocal postfix `/ₙ`:2000 := z\n\n/--\nThe `n`-th approximation of a continuous function on `[0,1]` by Bernstein polynomials,\ngiven by `∑ k, f (k/n) * bernstein n k x`.\n-/\ndef bernstein_approximation (n : ℕ) (f : C(I, ℝ)) : C(I, ℝ) :=\n∑ k : fin (n+1), f k/ₙ • 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 ε h n x`,\nfor some function `f : C(I, ℝ)`, `h : 0 < ε`, `n : ℕ` and `x : I`.\n\nThis is the set of points `k` in `fin (n+1)` such that\n`k/n` is within `δ` of `x`, where `δ` is the modulus of uniform continuity for `f`,\nchosen so `|f x - f y| < ε/2` when `|x - y| < δ`.\n\nWe show that if `k ∉ S`, then `1 ≤ δ^-2 * (x - k/n)^2`.\n-/\n\nnamespace bernstein_approximation\n\n@[simp] lemma apply (n : ℕ) (f : C(I, ℝ)) (x : I) :\n  bernstein_approximation n f x = ∑ k : fin (n+1), f k/ₙ * bernstein n k x :=\nby simp [bernstein_approximation]\n\n/--\nThe modulus of (uniform) continuity for `f`, chosen so `|f x - f y| < ε/2` when `|x - y| < δ`.\n-/\ndef δ (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) : ℝ := f.modulus (ε/2) (half_pos h)\n\nlemma δ_pos {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} : 0 < δ f ε h := f.modulus_pos\n\n/--\nThe set of points `k` so `k/n` is within `δ` of `x`.\n-/\ndef S (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) (n : ℕ) (x : I) : finset (fin (n+1)) :=\n{ k : fin (n+1) | dist k/ₙ x < δ f ε h }.to_finset\n\n/--\nIf `k ∈ S`, then `f(k/n)` is close to `f x`.\n-/\nlemma lt_of_mem_S\n  {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : fin (n+1)} (m : k ∈ S f ε h n x) :\n  |f k/ₙ - f x| < ε/2 :=\nbegin\n  apply f.dist_lt_of_dist_lt_modulus (ε/2) (half_pos h),\n  simpa [S] using m,\nend\n\n/--\nIf `k ∉ S`, then as `δ ≤ |x - k/n|`, we have the inequality `1 ≤ δ^-2 * (x - k/n)^2`.\nThis particular formulation will be helpful later.\n-/\nlemma le_of_mem_S_compl\n  {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : fin (n+1)} (m : k ∈ (S f ε h n x)ᶜ) :\n  (1 : ℝ) ≤ (δ f ε h)^(-2 : ℤ) * (x - k/ₙ) ^ 2 :=\nbegin\n  simp only [finset.mem_compl, not_lt, set.mem_to_finset, set.mem_set_of_eq, S] at m,\n  rw [zpow_neg, ← div_eq_inv_mul, zpow_two, ←pow_two, one_le_div (pow_pos δ_pos 2), sq_le_sq,\n    abs_of_pos δ_pos],\n  rwa [dist_comm] at m\nend\n\nend bernstein_approximation\n\nopen bernstein_approximation\nopen bounded_continuous_function\nopen filter\n\nopen_locale topology\n\n/--\nThe Bernstein approximations\n```\n∑ k : fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity.\n\nThis is the proof given in [Richard Beals' *Analysis, an introduction*][beals-analysis], §7D,\nand reproduced on wikipedia.\n-/\ntheorem bernstein_approximation_uniform (f : C(I, ℝ)) :\n  tendsto (λ n : ℕ, bernstein_approximation n f) at_top (𝓝 f) :=\nbegin\n  simp only [metric.nhds_basis_ball.tendsto_right_iff, metric.mem_ball, dist_eq_norm],\n  intros ε h,\n  let δ := δ f ε h,\n  have nhds_zero := tendsto_const_div_at_top_nhds_0_nat (2 * ‖f‖ * δ ^ (-2 : ℤ)),\n  filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_at_top 0]\n    with n nh npos',\n  have npos : 0 < (n:ℝ) := by exact_mod_cast npos',\n  -- Two easy inequalities we'll need later:\n  have w₁ : 0 ≤ 2 * ‖f‖ := mul_nonneg (by norm_num) (norm_nonneg f),\n  have w₂ : 0 ≤ 2 * ‖f‖ * δ^(-2 : ℤ) := mul_nonneg w₁ (zpow_neg_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 < δ`, and its complement.\n  let S := S f ε 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 * (∑ k : fin (n+1), bernstein n k x)|\n                              : by rw bernstein.probability\n    ... = |∑ k : fin (n+1), (f k/ₙ - f x) * bernstein n k x|\n                              : by simp [bernstein_approximation, finset.mul_sum, sub_mul]\n    ... ≤ ∑ k : fin (n+1), |(f k/ₙ - f x) * bernstein n k x|\n                              : finset.abs_sum_le_sum_abs _ _\n    ... = ∑ k : fin (n+1), |f k/ₙ - f x| * bernstein n k x\n                              : by simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]\n    ... = ∑ k in S, |f k/ₙ - f x| * bernstein n k x +\n          ∑ k in Sᶜ, |f k/ₙ - 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ᶜ` in separate calc blocks.\n    ... < ε/2 + ε/2 : add_lt_add_of_le_of_lt _ _\n    ... = ε : add_halves ε,\n    { -- We now work on the terms in `S`: uniform continuity and `bernstein.probability`\n      -- quickly give us a bound.\n      calc ∑ k in S, |f k/ₙ - f x| * bernstein n k x\n          ≤ ∑ k in S, ε/2 * bernstein n k x\n                                :  finset.sum_le_sum\n                                    (λ k m, (mul_le_mul_of_nonneg_right (le_of_lt (lt_of_mem_S m))\n                                      bernstein_nonneg))\n      ... = ε/2 * ∑ 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      ... ≤ ε/2 * ∑ k : fin (n+1), bernstein n k x\n                                : mul_le_mul_of_nonneg_left\n                                    (finset.sum_le_univ_sum_of_nonneg (λ k, bernstein_nonneg))\n                                    (le_of_lt (half_pos h))\n      ... = ε/2 : by rw [bernstein.probability, mul_one] },\n      { -- We now turn to working on `Sᶜ`: we control the difference term just using `‖f‖`,\n        -- and then insert a `δ^(-2) * (x - k/n)^2` factor\n        -- (which is at least one because we are not in `S`).\n        calc ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x\n            ≤ ∑ k in Sᶜ, (2 * ‖f‖) * bernstein n k x\n                                  : finset.sum_le_sum\n                                      (λ k m, mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _)\n                                        bernstein_nonneg)\n        ... = (2 * ‖f‖) * ∑ k in Sᶜ, bernstein n k x\n                                  : by rw finset.mul_sum\n        ... ≤ (2 * ‖f‖) * ∑ k in Sᶜ, δ^(-2 : ℤ) * (x - k/ₙ)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_sum (λ k m, begin\n                                        conv_lhs { rw ←one_mul (bernstein _ _ _), },\n                                        exact mul_le_mul_of_nonneg_right\n                                          (le_of_mem_S_compl m) bernstein_nonneg,\n                                      end)) w₁\n        -- Again enlarging the sum from `Sᶜ` to all of `fin (n+1)`\n        ... ≤ (2 * ‖f‖) * ∑ k : fin (n+1), δ^(-2 : ℤ) * (x - k/ₙ)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_univ_sum_of_nonneg\n                                        (λ k, mul_nonneg\n                                          (mul_nonneg (zpow_neg_two_nonneg _) (sq_nonneg _))\n                                          bernstein_nonneg)) w₁\n        ... = (2 * ‖f‖) * δ^(-2 : ℤ) * ∑ k : fin (n+1), (x - k/ₙ)^2 * bernstein n k x\n                                  : by conv_rhs\n                                    { rw [mul_assoc, finset.mul_sum], simp only [←mul_assoc], }\n        -- `bernstein.variance` and `x ∈ [0,1]` gives the uniform bound\n        ... = (2 * ‖f‖) * δ^(-2 : ℤ) * x * (1-x) / n\n                                  : by { rw variance npos, ring, }\n        ... ≤ (2 * ‖f‖) * δ^(-2 : ℤ) / n\n                                  : (div_le_div_right npos).mpr $\n              by refine mul_le_of_le_of_le_one' (mul_le_of_le_one_right w₂ _) _ _ w₂; unit_interval\n        ... < ε/2 : nh, }\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/bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7563421502808122}}
{"text": "import data.rat.basic\n\nimport summation\n\nopen summation\n\n/-The limit as `f` goes to ±∞ is 0 -/\ndef vanishes (f : ℤ → ℚ) := ∀ (ε : ℚ), ε > (0 : ℚ) → ∃ (K : ℕ), ∀ (k : ℤ), (k > K ∨ k < -K) → (f k > - ε ∧ f k < ε)\n\n/-\nThe functions `F` and `G` form a WZ pair\n\nThat is, Δₙ F = Δₖ G\n-/\ndef WZ_pair (F : ℤ → ℤ → ℚ) (G : ℤ → ℤ → ℚ) := (∀ (n k : ℤ), F (n+1) k - F n k = G n (k+1) - G n k)\n\n/-\nThis lemma demonstrates that if functions `F` and `G` form a WZ pair, then a finite summation of `F` with the variable `k` can be converted to a telescoping sum of the funtion `G`.\n-/\nlemma creative_telescoping {F G : ℤ → ℤ → ℚ} (wz : WZ_pair F G) (n : ℤ) : ∀ (m : ℕ), summation (λ (k : ℤ), F (n+1) k - F n k) m = G n (m+1) - G n (-m) :=\nbegin\n  intro m,\n  induction m with d hd,\n  {\n    rw [summation, wz n 0],\n    refl,\n  },\n  {\n    rw [summation, hd, wz, wz],\n    simp,\n  }\nend\n\n/-This is the main WZ theorem.\n\nSketch of the proof:\n\nAny identity of the form ∑ₖ f n k = S n can be rewritten as\n∑ₖ F n k = c, where\n`c` is a constant and\nF n k = (f n k) / (S n)\n\nTo show that ∑ₖ F n k = c, it suffices to show that (∑ₖ F (n+1) k) - (∑ₖ F n k) = ∑ₖ (F (n+1) k - F n k) = 0.\n\nUsing the WZ mate of `F`, namely `G`, this summation can be converted into a telescoping sum which is easily evaluated:\n\n∑ₖ G n (k+1) - G n k = lim_{m → ∞} G n (m+1) - G n (-m)\n\nSince the function G n is assumed to vanish at infinity, the above sum is just zero.\n\nThis shows that ∑ₖ F n k is a constant function of `n`, and therefore the identity must hold.\n\n-/\ntheorem WZ \n  (F G : ℤ → ℤ → ℚ)\n  (wz : WZ_pair F G) \n  (Gvanishes : ∀ (n : ℤ), vanishes (G n)) \n  (c : ℚ)\n  (base_case : equals_indefinite_sum (F 0) c)\n\n  : ∀ (n : ℤ), equals_indefinite_sum (F n) c :=\nbegin\n\n  -- this is the crux of the theorem - the fact that ∑ₖ (F (n+1) k - F n k) = 0\n  have consecutive_difference_vanishes : ∀ (n : ℤ), equals_indefinite_sum (λ (k : ℤ), F (n+1) k - F n k) 0 :=\n  begin\n    intro n,\n    rw equals_indefinite_sum,\n    intros ε hε_pos,\n    have hεby2_pos : ε/2 > 0 := half_pos hε_pos,\n    cases (Gvanishes n (ε/2) hεby2_pos) with K hK,\n    use K,\n    intro m,\n    intro hmgtK,\n    rw creative_telescoping wz n,\n\n    cases hK (-m) _ with Gnm_neg Gnm_pos,\n    cases hK (m+1) (or.inl (int.coe_nat_lt.mpr (nat.lt.step hmgtK))) with Gnms_neg Gnms_pos,\n\n    split,\n    {\n      linarith,\n    },\n    {\n      linarith,\n    },\n    right,\n    linarith,\n  end,\n\n  have inductive_case : _ := zero_diff_iff_equal F consecutive_difference_vanishes c,\n\n  intro n,\n  cases n,\n  {\n    induction n with d hd,\n    exact base_case,\n    exact (inductive_case d).1 hd,\n  },\n  {\n    induction n with d hd,\n    {\n      exact (inductive_case (-1)).2 base_case,\n    },\n    {\n      exact (inductive_case (-(d+2))).2 hd,\n    }\n  }\nend", "meta": {"author": "0art0", "repo": "WZ", "sha": "134e872d8071107d8348f38cafd21c66ab4d04de", "save_path": "github-repos/lean/0art0-WZ", "path": "github-repos/lean/0art0-WZ/WZ-134e872d8071107d8348f38cafd21c66ab4d04de/WZtheorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7562811274548757}}
{"text": "-- ----------------------------------------------------\n-- Ejercicio . Demostrar\n--    ¬¬p ⊢ p\n-- ----------------------------------------------------\n\nimport tactic\nvariable (p : Prop)\n\nopen_locale classical\n\n-- 1ª demostración\nexample\n  (h1 : ¬¬p)\n  : p :=\nby_contra\n  ( assume h2 : ¬p,\n    show false,\n      from h1 h2 )\n\n-- 2ª demostración\nexample\n  (h1 : ¬¬p)\n  : p :=\nby_contra\n  ( assume h2 : ¬p,\n    h1 h2 )\n\n-- 3ª demostración\nexample\n  (h1 : ¬¬p)\n  : p :=\nby_contra (λ h2, h1 h2)\n\n-- 4ª demostración\nexample\n  (h1 : ¬¬p)\n  : p :=\n-- by library_search\nnot_not.mp h1\n\n-- 5ª demostración\nexample\n  (h1 : ¬¬p)\n  : p :=\nbegin\n  by_contradiction h2,\n  exact h1 h2,\nend\n\n-- 6ª demostración\nexample\n  (h1 : ¬¬p)\n  : p :=\n-- by hint\nby tauto\n\n-- 7ª demostración\nlemma aux\n  (h1 : ¬¬p)\n  : 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/¬¬p⊢p.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7562811084728447}}
{"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 f1a2caaf51ef593799107fe9a8d5e411599f3996\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.Basic\nimport Mathlib.Algebra.Divisibility.Units\n\n/-!\n# Divisibility in groups with zero.\n\nLemmas about divisibility in groups and monoids with zero.\n\n-/\n\n\nvariable {α : Type _}\n\nsection SemigroupWithZero\n\nvariable [SemigroupWithZero α] {a : α}\n\ntheorem eq_zero_of_zero_dvd (h : 0 ∣ a) : a = 0 :=\n  Dvd.elim h fun c H' => H'.trans (zero_mul c)\n#align eq_zero_of_zero_dvd eq_zero_of_zero_dvd\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]\ntheorem zero_dvd_iff : 0 ∣ a ↔ a = 0 :=\n  ⟨eq_zero_of_zero_dvd, fun h => by\n    rw [h]\n    exact ⟨0, by simp⟩⟩\n#align zero_dvd_iff zero_dvd_iff\n\n@[simp]\ntheorem dvd_zero (a : α) : a ∣ 0 :=\n  Dvd.intro 0 (by simp)\n#align dvd_zero dvd_zero\n\nend SemigroupWithZero\n\n/-- Given two elements `b`, `c` of a `CancelMonoidWithZero` and a nonzero element `a`,\n `a*b` divides `a*c` iff `b` divides `c`. -/\ntheorem mul_dvd_mul_iff_left [CancelMonoidWithZero α] {a b c : α} (ha : a ≠ 0) :\n    a * b ∣ a * c ↔ b ∣ 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/-- Given two elements `a`, `b` of a commutative `CancelMonoidWithZero` and a nonzero\n  element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/\ntheorem mul_dvd_mul_iff_right [CancelCommMonoidWithZero α] {a b c : α} (hc : c ≠ 0) :\n    a * c ∣ b * c ↔ a ∣ 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 α]\n\n/-- `DvdNotUnit a b` expresses that `a` divides `b` \"strictly\", i.e. that `b` divided by `a`\nis not a unit. -/\ndef DvdNotUnit (a b : α) : Prop :=\n  a ≠ 0 ∧ ∃ x, ¬IsUnit x ∧ b = a * x\n#align dvd_not_unit DvdNotUnit\n\ntheorem dvdNotUnit_of_dvd_of_not_dvd {a b : α} (hd : a ∣ b) (hnd : ¬b ∣ a) : DvdNotUnit a b := by\n  constructor\n  · rintro rfl\n    exact hnd (dvd_zero _)\n  · rcases hd with ⟨c, rfl⟩\n    refine' ⟨c, _, rfl⟩\n    rintro ⟨u, rfl⟩\n    simp at hnd\n#align dvd_not_unit_of_dvd_of_not_dvd dvdNotUnit_of_dvd_of_not_dvd\n\nend CommMonoidWithZero\n\ntheorem dvd_and_not_dvd_iff [CancelCommMonoidWithZero α] {x y : α} :\n    x ∣ y ∧ ¬y ∣ x ↔ DvdNotUnit x y :=\n  ⟨fun ⟨⟨d, hd⟩, hyx⟩ =>\n    ⟨fun hx0 => by simp [hx0] at hyx,\n      ⟨d, mt isUnit_iff_dvd_one.1 fun ⟨e, he⟩ => hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩,\n        hd⟩⟩,\n    fun ⟨hx0, d, hdu, hdx⟩ =>\n    ⟨⟨d, hdx⟩, fun ⟨e, he⟩ =>\n      hdu\n        (isUnit_of_dvd_one\n          ⟨e, mul_left_cancel₀ hx0 <| by conv =>\n            lhs\n            rw [he, hdx]\n            simp [mul_assoc]⟩)⟩⟩\n#align dvd_and_not_dvd_iff dvd_and_not_dvd_iff\n\nsection MonoidWithZero\n\nvariable [MonoidWithZero α]\n\ntheorem ne_zero_of_dvd_ne_zero {p q : α} (h₁ : q ≠ 0) (h₂ : p ∣ q) : p ≠ 0 := by\n  rcases h₂ with ⟨u, rfl⟩\n  exact left_ne_zero_of_mul h₁\n#align ne_zero_of_dvd_ne_zero ne_zero_of_dvd_ne_zero\n\nend MonoidWithZero\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/Divisibility.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8652240825770433, "lm_q1q2_score": 0.7562726795732674}}
{"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-/\nimport analysis.asymptotics.asymptotic_equivalent\nimport analysis.asymptotics.specific_asymptotics\nimport data.polynomial.ring_division\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 +∞.\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\nopen filter finset asymptotics\nopen_locale asymptotics polynomial topology\n\nnamespace polynomial\n\nvariables {𝕜 : Type*} [normed_linear_ordered_field 𝕜] (P Q : 𝕜[X])\n\nlemma eventually_no_roots (hP : P ≠ 0) : ∀ᶠ x in at_top, ¬ P.is_root x :=\nat_top_le_cofinite $ (finite_set_of_is_root hP).compl_mem_cofinite\n\nvariables [order_topology 𝕜]\n\nsection polynomial_at_top\n\nlemma is_equivalent_at_top_lead :\n  (λ x, eval x P) ~[at_top] (λ x, P.leading_coeff * x ^ P.nat_degree) :=\nbegin\n  by_cases h : P = 0,\n  { simp [h] },\n  { simp only [polynomial.eval_eq_sum_range, sum_range_succ],\n    exact is_o.add_is_equivalent (is_o.sum $ λ i hi, is_o.const_mul_left\n      (is_o.const_mul_right (λ hz, h $ leading_coeff_eq_zero.mp hz) $\n        is_o_pow_pow_at_top_of_lt (mem_range.mp hi)) _) is_equivalent.refl }\nend\n\nlemma tendsto_at_top_of_leading_coeff_nonneg (hdeg : 0 < P.degree) (hnng : 0 ≤ P.leading_coeff) :\n  tendsto (λ x, eval x P) at_top at_top :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_top $\n  tendsto_const_mul_pow_at_top (nat_degree_pos_iff_degree_pos.2 hdeg).ne' $\n    hnng.lt_of_ne' $ leading_coeff_ne_zero.mpr $ ne_zero_of_degree_gt hdeg\n\nlemma tendsto_at_top_iff_leading_coeff_nonneg :\n  tendsto (λ x, eval x P) at_top at_top ↔ 0 < P.degree ∧ 0 ≤ P.leading_coeff :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_at_top_of_leading_coeff_nonneg P h.1 h.2⟩,\n  have : tendsto (λ x, P.leading_coeff * x ^ P.nat_degree) at_top at_top :=\n    (is_equivalent_at_top_lead P).tendsto_at_top h,\n  rw [tendsto_const_mul_pow_at_top_iff, ← pos_iff_ne_zero, nat_degree_pos_iff_degree_pos] at this,\n  exact ⟨this.1, this.2.le⟩\nend\n\nlemma tendsto_at_bot_iff_leading_coeff_nonpos :\n  tendsto (λ x, eval x P) at_top at_bot ↔ 0 < P.degree ∧ P.leading_coeff ≤ 0 :=\nby simp only [← tendsto_neg_at_top_iff, ← eval_neg, tendsto_at_top_iff_leading_coeff_nonneg,\n  degree_neg, leading_coeff_neg, neg_nonneg]\n\nlemma tendsto_at_bot_of_leading_coeff_nonpos (hdeg : 0 < P.degree) (hnps : P.leading_coeff ≤ 0) :\n  tendsto (λ x, eval x P) at_top at_bot :=\nP.tendsto_at_bot_iff_leading_coeff_nonpos.2 ⟨hdeg, hnps⟩\n\nlemma abs_tendsto_at_top (hdeg : 0 < P.degree) :\n  tendsto (λ x, abs $ eval x P) at_top at_top :=\nbegin\n  cases le_total 0 P.leading_coeff with hP hP,\n  { exact tendsto_abs_at_top_at_top.comp (P.tendsto_at_top_of_leading_coeff_nonneg hdeg hP) },\n  { exact tendsto_abs_at_bot_at_top.comp (P.tendsto_at_bot_of_leading_coeff_nonpos hdeg hP) }\nend\n\nlemma abs_is_bounded_under_iff :\n  is_bounded_under (≤) at_top (λ x, |eval x P|) ↔ P.degree ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, ⟨|P.coeff 0|, eventually_map.mpr (eventually_of_forall\n    (forall_imp (λ _, le_of_eq) (λ x, congr_arg abs $ trans (congr_arg (eval x)\n    (eq_C_of_degree_le_zero h)) (eval_C))))⟩⟩,\n  contrapose! h,\n  exact not_is_bounded_under_of_tendsto_at_top (abs_tendsto_at_top P h)\nend\n\nlemma abs_tendsto_at_top_iff :\n  tendsto (λ x, abs $ eval x P) at_top at_top ↔ 0 < P.degree :=\n⟨λ h, not_le.mp (mt (abs_is_bounded_under_iff P).mpr (not_is_bounded_under_of_tendsto_at_top h)),\n  abs_tendsto_at_top P⟩\n\nlemma tendsto_nhds_iff {c : 𝕜} :\n  tendsto (λ x, eval x P) at_top (𝓝 c) ↔ P.leading_coeff = c ∧ P.degree ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { have := P.is_equivalent_at_top_lead.tendsto_nhds h,\n    by_cases hP : P.leading_coeff = 0,\n    { simp only [hP, zero_mul, tendsto_const_nhds_iff] at this,\n      refine ⟨trans hP this, by simp [leading_coeff_eq_zero.1 hP]⟩ },\n    { rw [tendsto_const_mul_pow_nhds_iff hP, nat_degree_eq_zero_iff_degree_le_zero] at this,\n      exact this.symm } },\n  { 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 }\nend\n\nend polynomial_at_top\n\nsection polynomial_div_at_top\n\nlemma is_equivalent_at_top_div :\n  (λ x, (eval x P)/(eval x Q)) ~[at_top]\n    λ x, P.leading_coeff/Q.leading_coeff * x^(P.nat_degree - Q.nat_degree : ℤ) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP] },\n  by_cases hQ : Q = 0,\n  { simp [hQ] },\n  refine (P.is_equivalent_at_top_lead.symm.div\n          Q.is_equivalent_at_top_lead.symm).symm.trans\n         (eventually_eq.is_equivalent ((eventually_gt_at_top 0).mono $ λ x hx, _)),\n  simp [← div_mul_div_comm, hP, hQ, zpow_sub₀ hx.ne.symm]\nend\n\nlemma div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP, tendsto_const_nhds] },\n  rw ←  nat_degree_lt_nat_degree_iff hP at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw ← mul_zero,\n  refine (tendsto_zpow_at_top_zero _).const_mul _,\n  linarith\nend\n\nlemma div_tendsto_zero_iff_degree_lt (hQ : Q ≠ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) ↔ P.degree < Q.degree :=\nbegin\n  refine ⟨λ h, _, div_tendsto_zero_of_degree_lt P Q⟩,\n  by_cases hPQ : P.leading_coeff / Q.leading_coeff = 0,\n  { simp only [div_eq_mul_inv, inv_eq_zero, mul_eq_zero] at hPQ,\n    cases hPQ with hP0 hQ0,\n    { rw [leading_coeff_eq_zero.1 hP0, degree_zero],\n      exact bot_lt_iff_ne_bot.2 (λ hQ', hQ (degree_eq_bot.1 hQ')) },\n    { exact absurd (leading_coeff_eq_zero.1 hQ0) hQ } },\n  { have := (is_equivalent_at_top_div P Q).tendsto_nhds h,\n    rw tendsto_const_mul_zpow_at_top_nhds_iff hPQ at this,\n    cases this with h h,\n    { exact absurd h.2 hPQ },\n    { rw [sub_lt_iff_lt_add, zero_add, int.coe_nat_lt] at h,\n      exact degree_lt_degree h.1 } }\nend\n\nlemma div_tendsto_leading_coeff_div_of_degree_eq (hdeg : P.degree = Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 $ P.leading_coeff / Q.leading_coeff) :=\nbegin\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw show (P.nat_degree : ℤ) = Q.nat_degree, by simp [hdeg, nat_degree],\n  simp [tendsto_const_nhds]\nend\n\nlemma div_tendsto_at_top_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hpos : 0 < P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hpos, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_top _,\n  apply tendsto.const_mul_at_top hpos,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnng : 0 ≤ P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nhave ratio_pos : 0 < P.leading_coeff/Q.leading_coeff,\n  from lt_of_le_of_ne hnng\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)).symm,\ndiv_tendsto_at_top_of_degree_gt' P Q hdeg ratio_pos\n\nlemma div_tendsto_at_bot_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hneg : P.leading_coeff/Q.leading_coeff < 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hneg, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_bot _,\n  apply tendsto.neg_const_mul_at_top hneg,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_bot_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnps : P.leading_coeff/Q.leading_coeff ≤ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nhave ratio_neg : P.leading_coeff/Q.leading_coeff < 0,\n  from lt_of_le_of_ne hnps\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)),\ndiv_tendsto_at_bot_of_degree_gt' P Q hdeg ratio_neg\n\nlemma abs_div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) :\n  tendsto (λ x, |(eval x P)/(eval x Q)|) at_top at_top :=\nbegin\n  by_cases h : 0 ≤ P.leading_coeff/Q.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.div_tendsto_at_top_of_degree_gt Q hdeg hQ h) },\n  { 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) }\nend\n\nend polynomial_div_at_top\n\ntheorem is_O_of_degree_le (h : P.degree ≤ Q.degree) :\n  (λ x, eval x P) =O[at_top] (λ x, eval x Q) :=\nbegin\n  by_cases hp : P = 0,\n  { simpa [hp] using is_O_zero (λ x, eval x Q) at_top },\n  { have hq : Q ≠ 0 := ne_zero_of_degree_ge_degree h hp,\n    have hPQ : ∀ᶠ (x : 𝕜) in at_top, eval x Q = 0 → eval x P = 0 :=\n      filter.mem_of_superset (polynomial.eventually_no_roots Q hq) (λ x h h', absurd h' h),\n    cases le_iff_lt_or_eq.mp h with h h,\n    { exact is_O_of_div_tendsto_nhds hPQ 0 (div_tendsto_zero_of_degree_lt P Q h) },\n    { exact is_O_of_div_tendsto_nhds hPQ _ (div_tendsto_leading_coeff_div_of_degree_eq P Q h) } }\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/analysis/special_functions/polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672955, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7562628864548703}}
{"text": "import data.real.basic\nimport tactic\n-- import C_Limits.fae_solutions.Course\n-- open vilnius\n\nnamespace vilnius\n\n--local notation `|` x `|` := abs x\n\n\n-- Recall the\ndefinition is_limit (a : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε\n\nexample {a : ℕ → ℝ} {l : ℝ} (c : ℝ) (ha : is_limit a l) :\n  is_limit (λ i, a i + c) (l + c) :=\nbegin\n  intros e se,\n  specialize ha e se,\n  cases ha with N ha,\n  use N,\n  intros n sn,\n  simp,\n  specialize ha n sn,\n  exact ha,\nend\n\n\nexample (a : ℕ → ℝ) (l : ℝ) :\n  is_limit a l ↔ is_limit (λ i, a i - l) 0 :=\nbegin\n  split,\n  intros ha e se,\n  specialize ha e se,\n  cases ha with N ha,\n  use N,\n  intros n sn,\n  simp,\n  specialize ha n sn,\n  exact ha,\n\n  intros ha e se,\n  specialize ha e se,\n  cases ha with N ha,\n  use N,\n  intros n sn,\n  specialize ha n sn,\n  simp only [tsub_zero] at ha,\n  exact ha,\nend\n\n\n/- Helpful things:\n'squeeze_simp' décrit ce que simp fait\n`abs_pos : 0 < |a| ↔ a ≠ 0`\n`div_pos : 0 < a → 0 < b → 0 < a / b`\n`abs_mul x y : |x * y| = |x| * |y|`\n`lt_div_iff' : 0 < c → (a < b / c ↔ 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-/\ntheorem is_limit_add {a b : ℕ → ℝ} {l m : ℝ}\n  (h1 : is_limit a l) (h2 : is_limit b m) :\n  is_limit (a + b) (l + m) :=\n  begin\n    intros e se,\n    specialize h1 (e/2),\n    specialize h2 (e/2),\n    have h: e/2 > 0,\n    apply div_pos,\n    exact se,\n    exact two_pos,\n    specialize h1 h,\n    specialize h2 h,\n\n    cases h1 with N1 h1,\n    cases h2 with N2 h2,\n    use max N1 N2,\n    intros n sn,\n    simp,\n    rewrite <- sub_sub,\n    rw ← add_sub,\n    rw sub_eq_add_neg _ l,\n    rw add_comm _ (-l),\n    rw ← add_assoc,\n    rw ← sub_eq_add_neg,\n    rw sub_eq_add_neg _ m,\n    rw add_assoc (a n - l) (b n) (- m),\n    rw ← sub_eq_add_neg _ m,\n    apply lt_of_le_of_lt,\n    apply abs_add (a n -l) (b n -m) ,\n    rw ← add_halves e,\n    apply add_lt_add (h1 n _) (h2 n _),\n    apply le_of_max_le_left,\n    exact sn, \n    apply le_of_max_le_left,\n    rw max_comm,\n    exact sn, \n  end\n\n\n-- And now, over to you!\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 : ℕ → ℝ} {l c : ℝ} (h : is_limit a l) :\n  is_limit (λ n, c * (a n)) (c * l) :=\nbegin\n  by_cases hc : c=0,\n  intros e se,\n  rewrite hc,\n  simp only [ge_iff_le, zero_mul, tsub_zero, abs_zero],\n  use 0,\n  intros n sn,\n  exact se,\n\n  intros e se,\n  specialize h (e/|c|),\n  have hec : e/|c| > 0,\n    apply div_pos,\n    exact se,\n    rw abs_pos,\n    exact hc,\n  specialize h hec,\n  cases h with N h,\n  use N,\n  intros n sn,\n  simp only,\n  rewrite <- mul_sub,\n  rewrite abs_mul,\n  have hc' : 0 < |c|,\n    rewrite abs_pos,\n    exact hc,\n  rewrite mul_comm,\n  rewrite ← lt_div_iff hc',\n  exact h n sn,\nend\n\ntheorem sandwich (a b c : ℕ → ℝ)\n  (l : ℝ) (ha : is_limit a l) (hc : is_limit c l) \n  (hab : ∀ n, a n ≤ b n) (hbc : ∀ n, b n ≤ c n) : is_limit b l :=\nbegin\n  intros e se,\n  specialize ha e se,\n  specialize hc e se,\n  cases ha with na ha,\n  cases hc with nc hc,\n  use max na nc,\n  intros n sn,\n  specialize hab n,\n  specialize hbc n,\n  specialize ha n,\n  specialize hc n,\n  specialize ha (le_of_max_le_left sn),\n  specialize hc (le_of_max_le_right sn),\n  rewrite abs_sub_lt_iff,\n  split,\n\n  rewrite sub_lt_iff_lt_add,\n  apply lt_of_lt_of_le',\n  rewrite ← sub_lt_iff_lt_add,\n  apply lt_of_abs_lt,\n  use hc,\n  exact hbc,\n\n  rewrite sub_lt,\n  apply lt_of_lt_of_le,\n  swap,\n  use hab,\n  rewrite ← sub_lt,\n  apply lt_of_abs_lt,\n  rewrite abs_sub_comm,\n  exact ha,\nend\n\nexample (a : ℕ → ℝ) (b : ℕ → ℝ) (α β c d : ℝ) \n    (ha : is_limit a α) (hb : is_limit b β) : \n    is_limit ( λ n, c * (a n) + d * (b n) ) (c * α + d * β) :=\nbegin\n  -- intros ε hε,**BAD IDEA**, you can do this much faster using the above theorems!\n  apply is_limit_add,\n  apply is_limit_mul_const_left,\n  exact ha,\n\n  apply is_limit_mul_const_left,\n  exact hb,\nend\n\nexample (a : ℕ → ℝ) (b : ℕ → ℝ)\n  (l : ℝ) (m : ℝ) (hl : is_limit a l) (hm : is_limit b m) \n  (hle : ∀ n, a n ≤ b n) : l ≤ m :=\nbegin\n  sorry,\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/Exercices/C.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7562270213995643}}
{"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.order.field\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∑ k : fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity.\n\nOur proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], §7D.\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 `δ`,\n  obtaining a bound of `(4 * n * δ^2)⁻¹`, 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], ℝ)`,\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 ν : ℕ) : C(I, ℝ) :=\n(bernstein_polynomial ℝ n ν).to_continuous_map_on I\n\n@[simp] lemma bernstein_apply (n ν : ℕ) (x : I) :\n  bernstein n ν x = n.choose ν * x^ν * (1-x)^(n-ν) :=\nbegin\n  dsimp [bernstein, polynomial.to_continuous_map_on, polynomial.to_continuous_map,\n    bernstein_polynomial],\n  simp,\nend\n\nlemma bernstein_nonneg {n ν : ℕ} {x : I} :\n  0 ≤ bernstein n ν 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 : ℕ} (k : fin (n+1)) : I :=\n⟨(k : ℝ) / n,\n  begin\n    cases n,\n    { norm_num },\n    { have h₁ : 0 < (n.succ : ℝ) := by exact_mod_cast (nat.succ_pos _),\n      have h₂ : ↑k ≤ n.succ := by exact_mod_cast (fin.le_last k),\n      rw [set.mem_Icc, le_div_iff h₁, div_le_iff h₁],\n      norm_cast,\n      simp [h₂], },\n  end⟩\n\nlocal postfix `/ₙ`:90 := z\n\nlemma probability (n : ℕ) (x : I) :\n  ∑ k : fin (n+1), bernstein n k x = 1 :=\nbegin\n  have := bernstein_polynomial.sum ℝ n,\n  apply_fun (λ p, polynomial.aeval (x : ℝ) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range] at this,\n  exact this,\nend\n\nlemma variance {n : ℕ} (h : 0 < (n : ℝ)) (x : I) :\n  ∑ k : fin (n+1), (x - k/ₙ : ℝ)^2 * bernstein n k x = x * (1-x) / n :=\nbegin\n  have h' : (n : ℝ) ≠ 0 := ne_of_gt h,\n  apply_fun (λ x : ℝ, x * n) using group_with_zero.mul_right_injective h',\n  apply_fun (λ x : ℝ, 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 ℝ n,\n  apply_fun (λ p, polynomial.aeval (x : ℝ) p) at this,\n  simp [alg_hom.map_sum, finset.sum_range, ←polynomial.nat_cast_mul] at this,\n  convert this using 1,\n  { congr' 1, funext k,\n    rw [mul_comm _ (n : ℝ), mul_comm _ (n : ℝ), ←mul_assoc, ←mul_assoc],\n    congr' 1,\n    field_simp [h],\n    ring, },\n  { ring, },\nend\n\nend bernstein\n\nopen bernstein\n\nlocal postfix `/ₙ`:2000 := z\n\n/--\nThe `n`-th approximation of a continuous function on `[0,1]` by Bernstein polynomials,\ngiven by `∑ k, f (k/n) * bernstein n k x`.\n-/\ndef bernstein_approximation (n : ℕ) (f : C(I, ℝ)) : C(I, ℝ) :=\n∑ k : fin (n+1), f k/ₙ • 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 ε h n x`,\nfor some function `f : C(I, ℝ)`, `h : 0 < ε`, `n : ℕ` and `x : I`.\n\nThis is the set of points `k` in `fin (n+1)` such that\n`k/n` is within `δ` of `x`, where `δ` is the modulus of uniform continuity for `f`,\nchosen so `|f x - f y| < ε/2` when `|x - y| < δ`.\n\nWe show that if `k ∉ S`, then `1 ≤ δ^-2 * (x - k/n)^2`.\n-/\n\nnamespace bernstein_approximation\n\n@[simp] lemma apply (n : ℕ) (f : C(I, ℝ)) (x : I) :\n  bernstein_approximation n f x = ∑ k : fin (n+1), f k/ₙ * bernstein n k x :=\nby simp [bernstein_approximation]\n\n/--\nThe modulus of (uniform) continuity for `f`, chosen so `|f x - f y| < ε/2` when `|x - y| < δ`.\n-/\ndef δ (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) : ℝ := f.modulus (ε/2) (half_pos h)\n\nlemma δ_pos {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} : 0 < δ f ε h := f.modulus_pos\n\n/--\nThe set of points `k` so `k/n` is within `δ` of `x`.\n-/\ndef S (f : C(I, ℝ)) (ε : ℝ) (h : 0 < ε) (n : ℕ) (x : I) : finset (fin (n+1)) :=\n{ k : fin (n+1) | dist k/ₙ x < δ f ε h }.to_finset\n\n/--\nIf `k ∈ S`, then `f(k/n)` is close to `f x`.\n-/\nlemma lt_of_mem_S\n  {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : fin (n+1)} (m : k ∈ S f ε h n x) :\n  |f k/ₙ - f x| < ε/2 :=\nbegin\n  apply f.dist_lt_of_dist_lt_modulus (ε/2) (half_pos h),\n  simpa [S] using m,\nend\n\n/--\nIf `k ∉ S`, then as `δ ≤ |x - k/n|`, we have the inequality `1 ≤ δ^-2 * (x - k/n)^2`.\nThis particular formulation will be helpful later.\n-/\nlemma le_of_mem_S_compl\n  {f : C(I, ℝ)} {ε : ℝ} {h : 0 < ε} {n : ℕ} {x : I} {k : fin (n+1)} (m : k ∈ (S f ε h n x)ᶜ) :\n  (1 : ℝ) ≤ (δ f ε h)^(-2 : ℤ) * (x - k/ₙ) ^ 2 :=\nbegin\n  simp only [finset.mem_compl, not_lt, set.mem_to_finset, set.mem_set_of_eq, S] at m,\n  erw [zpow_neg, ← div_eq_inv_mul, one_le_div (pow_pos δ_pos 2), sq_le_sq, abs_of_pos δ_pos],\n  rwa [dist_comm] at 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∑ k : fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k)\n```\nfor a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity.\n\nThis is the proof given in [Richard Beals' *Analysis, an introduction*][beals-analysis], §7D,\nand reproduced on wikipedia.\n-/\ntheorem bernstein_approximation_uniform (f : C(I, ℝ)) :\n  tendsto (λ n : ℕ, bernstein_approximation n f) at_top (𝓝 f) :=\nbegin\n  simp only [metric.nhds_basis_ball.tendsto_right_iff, metric.mem_ball, dist_eq_norm],\n  intros ε h,\n  let δ := δ f ε h,\n  have nhds_zero := tendsto_const_div_at_top_nhds_0_nat (2 * ∥f∥ * δ ^ (-2 : ℤ)),\n  filter_upwards [nhds_zero.eventually (gt_mem_nhds (half_pos h)), eventually_gt_at_top 0]\n    with n nh npos',\n  have npos : 0 < (n:ℝ) := by exact_mod_cast npos',\n  -- Two easy inequalities we'll need later:\n  have w₁ : 0 ≤ 2 * ∥f∥ := mul_nonneg (by norm_num) (norm_nonneg f),\n  have w₂ : 0 ≤ 2 * ∥f∥ * δ^(-2 : ℤ) := mul_nonneg w₁ 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 < δ`, and its complement.\n  let S := S f ε 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 * (∑ k : fin (n+1), bernstein n k x)|\n                              : by rw bernstein.probability\n    ... = |∑ k : fin (n+1), (f k/ₙ - f x) * bernstein n k x|\n                              : by simp [bernstein_approximation, finset.mul_sum, sub_mul]\n    ... ≤ ∑ k : fin (n+1), |(f k/ₙ - f x) * bernstein n k x|\n                              : finset.abs_sum_le_sum_abs _ _\n    ... = ∑ k : fin (n+1), |f k/ₙ - f x| * bernstein n k x\n                              : by simp_rw [abs_mul, abs_eq_self.mpr bernstein_nonneg]\n    ... = ∑ k in S, |f k/ₙ - f x| * bernstein n k x +\n          ∑ k in Sᶜ, |f k/ₙ - 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ᶜ` in separate calc blocks.\n    ... < ε/2 + ε/2 : add_lt_add_of_le_of_lt _ _\n    ... = ε : add_halves ε,\n    { -- We now work on the terms in `S`: uniform continuity and `bernstein.probability`\n      -- quickly give us a bound.\n      calc ∑ k in S, |f k/ₙ - f x| * bernstein n k x\n          ≤ ∑ k in S, ε/2 * bernstein n k x\n                                :  finset.sum_le_sum\n                                    (λ k m, (mul_le_mul_of_nonneg_right (le_of_lt (lt_of_mem_S m))\n                                      bernstein_nonneg))\n      ... = ε/2 * ∑ 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      ... ≤ ε/2 * ∑ k : fin (n+1), bernstein n k x\n                                : mul_le_mul_of_nonneg_left\n                                    (finset.sum_le_univ_sum_of_nonneg (λ k, bernstein_nonneg))\n                                    (le_of_lt (half_pos h))\n      ... = ε/2 : by rw [bernstein.probability, mul_one] },\n      { -- We now turn to working on `Sᶜ`: we control the difference term just using `∥f∥`,\n        -- and then insert a `δ^(-2) * (x - k/n)^2` factor\n        -- (which is at least one because we are not in `S`).\n        calc ∑ k in Sᶜ, |f k/ₙ - f x| * bernstein n k x\n            ≤ ∑ k in Sᶜ, (2 * ∥f∥) * bernstein n k x\n                                  : finset.sum_le_sum\n                                      (λ k m, mul_le_mul_of_nonneg_right (f.dist_le_two_norm _ _)\n                                        bernstein_nonneg)\n        ... = (2 * ∥f∥) * ∑ k in Sᶜ, bernstein n k x\n                                  : by rw finset.mul_sum\n        ... ≤ (2 * ∥f∥) * ∑ k in Sᶜ, δ^(-2 : ℤ) * (x - k/ₙ)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_sum (λ k m, begin\n                                        conv_lhs { rw ←one_mul (bernstein _ _ _), },\n                                        exact mul_le_mul_of_nonneg_right\n                                          (le_of_mem_S_compl m) bernstein_nonneg,\n                                      end)) w₁\n        -- Again enlarging the sum from `Sᶜ` to all of `fin (n+1)`\n        ... ≤ (2 * ∥f∥) * ∑ k : fin (n+1), δ^(-2 : ℤ) * (x - k/ₙ)^2 * bernstein n k x\n                                  : mul_le_mul_of_nonneg_left\n                                      (finset.sum_le_univ_sum_of_nonneg\n                                        (λ k, mul_nonneg\n                                          (mul_nonneg pow_minus_two_nonneg (sq_nonneg _))\n                                          bernstein_nonneg)) w₁\n        ... = (2 * ∥f∥) * δ^(-2 : ℤ) * ∑ k : fin (n+1), (x - k/ₙ)^2 * bernstein n k x\n                                  : by conv_rhs\n                                    { rw [mul_assoc, finset.mul_sum], simp only [←mul_assoc], }\n        -- `bernstein.variance` and `x ∈ [0,1]` gives the uniform bound\n        ... = (2 * ∥f∥) * δ^(-2 : ℤ) * x * (1-x) / n\n                                  : by { rw variance npos, ring, }\n        ... ≤ (2 * ∥f∥) * δ^(-2 : ℤ) / n\n                                  : (div_le_div_right npos).mpr\n                                    begin\n                                      apply mul_nonneg_le_one_le w₂,\n                                      apply mul_nonneg_le_one_le w₂ le_rfl,\n                                      all_goals { unit_interval, },\n                                    end\n        ... < ε/2 : nh, }\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/special_functions/bernstein.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7562270179731648}}
{"text": "import ..lectures.love02_backward_proofs_demo\n\n\n/-! # LoVe Exercise 2: Backward Proofs -/\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: Connectives and Quantifiers\n\n1.1. Carry out the following proofs using basic tactics.\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 I (a : Prop) :\n  a → a :=\nbegin\n  intro ha,\n  exact ha\nend\n\nlemma K (a b : Prop) :\n  a → b → b :=\nbegin\n  intros ha hb,\n  exact hb\nend\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nbegin\n  intros hg hb ha,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha\nend\n\n/-! Please give a different answer than for `proj_1st`: -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nbegin\n  intros ha ha',\n  exact ha'\nend\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nbegin\n  intros hg ha hf hb,\n  apply hg,\n  exact ha,\n  exact hb\nend\n\n/-! 1.2. Prove the contraposition rule using basic tactics. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nbegin\n  intros hab hnb ha,\n  apply hnb,\n  apply hab,\n  apply ha\nend\n\n/-! 1.3. Prove the distributivity of `∀` over `∧` using basic tactics.\n\nHint: This exercise is tricky, especially the right-to-left direction. Some\nforward reasoning, like in the proof of `and_swap₂` in the lecture, might be\nnecessary. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nbegin\n  apply iff.intro,\n  { intro h,\n    apply and.intro,\n    { intro x,\n      apply and.elim_left,\n      apply h },\n    { intro x,\n      apply and.elim_right,\n      apply h } },\n  { intros h x,\n    apply and.intro,\n    { apply and.elim_left h },\n    { apply and.elim_right h } }\nend\n\nend backward_proofs\n\nnamespace existentials\n\n/-! ## Question 2: Existentials\n\nIn this section, you'll practice using `exists.intro` and `exists.elim`.\n-/\n\n#check @exists.intro\n#check @exists.elim\n\n/-! 2.1. Prove that we can \"flip\" the existential and universal quantifiers.\n(Note that this only works in one direction!)\n-/\n\nlemma website_icon {α β : Sort _} {p : α → β → Prop} :\n  (∃ a, ∀ b, p a b) → (∀ b, ∃ a, p a b) :=\nbegin\n  intros h b,\n  apply exists.elim h,\n  intros w hw,\n  apply exists.intro w,\n  apply hw,\nend\n\n/-! 2.2 Prove, using the definition of `isEven` below, that adding two to an\neven number gives another even number.\n-/\n\n-- Here is a definition and helper lemma for exercise 2.2\ndef isEven (n : ℕ) := ∃ k, n = 2 * k\nlemma add_two_eq (m n : ℕ) : m = n → m + 2 = n + 2 :=\ncongr_arg (λ x, x + 2)\n\n-- You may also find the following lemmas helpful:\n#check mul_add\n#check mul_one\n\nlemma even_add_two : ∀ n : ℕ, isEven n → isEven (n + 2) :=\nbegin\n  intros n hn,\n  apply exists.elim hn,\n  intros w hw,\n  apply exists.intro (w + 1),\n  rw [mul_add, mul_one],\n  apply add_two_eq,\n  apply hw,\nend\n\n/- 2.3. Prove that two consecutive natural numbers cannot be even.\n\nHints:\n* You can use `and.elim` to extract the two sides of a conjunction.\n* `eq.symm` reverses the sides of an equality.\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 ←h` (note the `←`).\n-/\naxiom no_odd_doubles : ∀ (n : ℕ), ¬ ∃ (m : ℕ), 2 * n = m + 1\n\nlemma t (n : ℕ) : ¬(isEven n ∧ isEven (n + 1)) :=\nbegin\n  intros hneg,\n  apply and.elim hneg,\n  intros hright hleft,\n  apply exists.elim hright,\n  intros w hw,\n  apply exists.elim hleft,\n  intros v hv,\n  apply no_odd_doubles v,\n  apply exists.intro (2*w),\n  rw ←hw,\n  apply eq.symm,\n  apply hv,\nend\n\nend existentials\n\nnamespace backward_proofs\n\n/-! ## Question 3: Natural Numbers\n\n3.1. Prove the following recursive equations on the first argument of the\n`mul` operator defined in lecture 1. -/\n\n#check mul\n\nlemma mul_zero (n : ℕ) :\n  mul 0 n = 0 :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, mul, ih] }\nend\n\nlemma mul_succ (m n : ℕ) :\n  mul (nat.succ m) n = add (mul m n) n :=\nbegin\n  induction' n,\n  { refl },\n  { simp [add, add_succ, add_assoc, mul, ih] }\nend\n\n/-! 3.2. Prove commutativity and associativity of multiplication using the\n`induction'` tactic. Choose the induction variable carefully. -/\n\nlemma mul_comm (m n : ℕ) :\n  mul m n = mul n m :=\nbegin\n  induction' m,\n  { simp [mul, mul_zero] },\n  { simp [mul, mul_succ, ih],\n    cc }\nend\n\nlemma mul_assoc (l m n : ℕ) :\n  mul (mul l m) n = mul l (mul m n) :=\nbegin\n  induction' n,\n  { refl },\n  { simp [mul, mul_add, ih] }\nend\n\n/-! 3.3. Prove the symmetric variant of `mul_add` using `rw`. To apply\ncommutativity at a specific position, instantiate the rule by passing some\narguments (e.g., `mul_comm _ l`). -/\n\nlemma add_mul (l m n : ℕ) :\n  mul (add l m) n = add (mul n l) (mul n m) :=\nbegin\n  rw mul_comm _ n,\n  rw mul_add\nend\n\n\n/-! ## Question 4 (**optional**): Intuitionistic Logic\n\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle : Prop :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce : Prop :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation : Prop :=\n∀a : Prop, (¬¬ a) → a\n\n/-! For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, as this would defeat the purpose of the exercise.\n\n4.1 (**optional**). Prove the following implication using tactics.\n\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nbegin\n  rw excluded_middle,\n  rw peirce,\n  intro hem,\n  intros a b haba,\n  apply or.elim (hem a),\n  { intro,\n    assumption },\n  { intro hna,\n    apply haba,\n    intro ha,\n    apply false.elim,\n    apply hna,\n    assumption }\nend\n\n/-! 4.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nbegin\n  rw peirce,\n  rw double_negation,\n  intros hpeirce a hnna,\n  apply hpeirce a false,\n  intro hna,\n  apply false.elim,\n  apply hnna,\n  exact hna\nend\n\n/-! We leave the remaining implication for the homework: -/\n\nnamespace sorry_lemmas\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nsorry\n\nend sorry_lemmas\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/exercises/love02_backward_proofs_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7562270089450974}}
{"text": "/-\nCopyright (c) 2021 Yaël Dillies. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël Dillies\n\n! This file was ported from Lean 3 source module data.nat.succ_pred\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.Fin.Basic\nimport Mathlib.Order.SuccPred.Basic\n\n/-!\n# Successors and predecessors of naturals\n\nIn this file, we show that `ℕ` is both an archimedean `succOrder` and an archimedean `predOrder`.\n-/\n\n\nopen Function Order\n\nnamespace Nat\n\n-- so that Lean reads `Nat.succ` through `succ_order.succ`\n@[reducible]\ninstance : SuccOrder ℕ :=\n  SuccOrder.ofSuccLeIff succ Nat.succ_le\n\n-- so that Lean reads `Nat.pred` through `pred_order.pred`\n@[reducible]\ninstance : PredOrder ℕ where\n  pred := pred\n  pred_le := pred_le\n  min_of_le_pred {a} ha := by\n    cases a\n    · exact isMin_bot\n    · exact (not_succ_le_self _ ha).elim\n  le_pred_of_lt {a} {b} h := by\n    cases b\n    · exact (a.not_lt_zero h).elim\n    · exact le_of_succ_le_succ h\n  le_of_pred_lt {a} {b} h := by\n    cases a\n    · exact b.zero_le\n    · exact h\n\n@[simp]\ntheorem succ_eq_succ : Order.succ = succ :=\n  rfl\n#align nat.succ_eq_succ Nat.succ_eq_succ\n\n@[simp]\ntheorem pred_eq_pred : Order.pred = pred :=\n  rfl\n#align nat.pred_eq_pred Nat.pred_eq_pred\n\ntheorem succ_iterate (a : ℕ) : ∀ n, (succ^[n]) a = a + n\n  | 0 => rfl\n  | n + 1 => by\n    rw [Function.iterate_succ', add_succ]\n    exact congr_arg _ (succ_iterate a n)\n#align nat.succ_iterate Nat.succ_iterate\n\ntheorem pred_iterate (a : ℕ) : ∀ n, (pred^[n]) a = a - n\n  | 0 => rfl\n  | n + 1 => by\n    rw [Function.iterate_succ', sub_succ]\n    exact congr_arg _ (pred_iterate a n)\n#align nat.pred_iterate Nat.pred_iterate\n\ninstance : IsSuccArchimedean ℕ :=\n  ⟨fun {a} {b} h => ⟨b - a, by rw [succ_eq_succ, succ_iterate, add_tsub_cancel_of_le h]⟩⟩\n\ninstance : IsPredArchimedean ℕ :=\n  ⟨fun {a} {b} h => ⟨b - a, by rw [pred_eq_pred, pred_iterate, tsub_tsub_cancel_of_le h]⟩⟩\n\n/-! ### Covering relation -/\n\n\nprotected theorem covby_iff_succ_eq {m n : ℕ} : m ⋖ n ↔ m + 1 = n :=\n  succ_eq_iff_covby.symm\n#align nat.covby_iff_succ_eq Nat.covby_iff_succ_eq\n\nend Nat\n\n@[simp, norm_cast]\ntheorem Fin.coe_covby_iff {n : ℕ} {a b : Fin n} : (a : ℕ) ⋖ b ↔ a ⋖ b :=\n  and_congr_right' ⟨fun h _c hc => h hc, fun h c ha hb => @h ⟨c, hb.trans b.prop⟩ ha hb⟩\n#align fin.coe_covby_iff Fin.coe_covby_iff\n\nalias Fin.coe_covby_iff ↔ _ Covby.coe_fin\n#align covby.coe_fin Covby.coe_fin\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/Nat/SuccPred.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7562054602050636}}
{"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 data.polynomial.cancel_leads\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.Degree.Definitions\nimport Mathlib.Data.Polynomial.Degree.Lemmas\n\n/-!\n# Cancel the leading terms of two polynomials\n\n## Definition\n\n* `cancelLeads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting.\n\n## Main Results\nThe degree of `cancelLeads` is less than that of the larger of the two polynomials being cancelled.\nThus it is useful for induction or minimal-degree arguments.\n-/\n\n\nnamespace Polynomial\n\nnoncomputable section\n\nopen Polynomial\n\nvariable {R : Type _}\n\nsection Ring\n\nvariable [Ring R] (p q : R[X])\n\n/-- `cancelLeads p q` is formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting. -/\ndef cancelLeads : R[X] :=\n  C p.leadingCoeff * X ^ (p.natDegree - q.natDegree) * q -\n    C q.leadingCoeff * X ^ (q.natDegree - p.natDegree) * p\n#align polynomial.cancel_leads Polynomial.cancelLeads\n\nvariable {p q}\n\n@[simp]\ntheorem neg_cancelLeads : -p.cancelLeads q = q.cancelLeads p :=\n  neg_sub _ _\n#align polynomial.neg_cancel_leads Polynomial.neg_cancelLeads\n\ntheorem natDegree_cancelLeads_lt_of_natDegree_le_natDegree_of_comm\n    (comm : p.leadingCoeff * q.leadingCoeff = q.leadingCoeff * p.leadingCoeff)\n    (h : p.natDegree ≤ q.natDegree) (hq : 0 < q.natDegree) :\n    (p.cancelLeads q).natDegree < q.natDegree := by\n  by_cases hp : p = 0\n  · convert hq\n    simp [hp, cancelLeads]\n  rw [cancelLeads, sub_eq_add_neg, tsub_eq_zero_iff_le.mpr h, pow_zero, mul_one]\n  by_cases h0 :\n    C p.leadingCoeff * q + -(C q.leadingCoeff * X ^ (q.natDegree - p.natDegree) * p) = 0\n  · exact (le_of_eq (by simp only [h0, natDegree_zero])).trans_lt hq\n  apply lt_of_le_of_ne\n  · -- porting note: was compute_degree_le; repeat' rwa [Nat.sub_add_cancel]\n    rw [natDegree_add_le_iff_left]\n    · apply natDegree_C_mul_le\n    refine (natDegree_neg (C q.leadingCoeff * X ^ (q.natDegree - p.natDegree) * p)).le.trans ?_\n    exact natDegree_mul_le.trans <| Nat.add_le_of_le_sub h <| natDegree_C_mul_X_pow_le _ _\n  · contrapose! h0\n    rw [← leadingCoeff_eq_zero, leadingCoeff, h0, mul_assoc, X_pow_mul, ← tsub_add_cancel_of_le h,\n      add_comm _ p.natDegree]\n    simp only [coeff_mul_X_pow, coeff_neg, coeff_C_mul, add_tsub_cancel_left, coeff_add]\n    rw [add_comm p.natDegree, tsub_add_cancel_of_le h, ← leadingCoeff, ← leadingCoeff, comm,\n      add_right_neg]\n#align polynomial.nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree_of_comm Polynomial.natDegree_cancelLeads_lt_of_natDegree_le_natDegree_of_comm\n\nend Ring\n\nsection CommRing\n\nvariable [CommRing R] {p q : R[X]}\n\ntheorem dvd_cancelLeads_of_dvd_of_dvd {r : R[X]} (pq : p ∣ q) (pr : p ∣ r) : p ∣ q.cancelLeads r :=\n  dvd_sub (pr.trans (Dvd.intro_left _ rfl)) (pq.trans (Dvd.intro_left _ rfl))\n#align polynomial.dvd_cancel_leads_of_dvd_of_dvd Polynomial.dvd_cancelLeads_of_dvd_of_dvd\n\n\n\nend CommRing\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/Polynomial/CancelLeads.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7562054440144227}}
{"text": "import data.nat.prime\nimport polyfill.factorial\nimport polyfill.mod\nimport logic.basic\nimport custom.util\n\n/- \n    The following code contains a theorem that proves that\n    there are infinitely many prime numbers. Specifically,\n    the statement of the theorem is that:\n\n    If `n` is a natural number greater than or equal to\n    `2`, there exists some prime number `p` that is\n    greater than `n`.\n\n    Given that `2` is a natural number, we can iteratively\n    apply the above theorem to show that there are\n    infinitely many primes.\n\n    The proof of infinitely many primes will be explained\n    in detail. However, before the theorem statement, there\n    are also several lemmas presented here that are used in\n    the proof of the theorem, in addition to those that are\n    imported from the Lean standard library `mathlib`.\n-/\n\nnamespace nat\n\n/- Lemma: Given naturals `n` and `m` where `n` divides `m`\n   and `m > 0`, we have that `n > 0`. -/\nlemma dvd_gt_zero (n m : ℕ) (h : 0 < m) : n ∣ m → 0 < n :=\nbegin\n    intro h2,\n    rw dvd_iff_mod_eq_zero at h2,\n    by_contra h3,\n    rw ← ne_zero_iff_gt_zero at h3,\n    rw ne.def at h3,\n    rw not_not at h3,\n    rw h3 at h2,\n    have h4 := mod_zero m,\n    rw h4 at h2,\n    rw ← ne_zero_iff_gt_zero at h,\n    rw h2 at h,\n    apply ne_self_imp_false 0,\n    exact h,\nend\n\n/- Lemma: `2` is a prime number, where prime is defined as\n   being `≥ 2` and having exactly `1` and itself as\n   factors. -/\nlemma two_is_prime : prime 2 :=\nbegin\n    split,\n    {\n        apply le_of_eq,\n        refl,\n    },\n    {\n        intro m,\n        intro h,\n        apply one_or_two,\n        split,\n        {\n            apply dvd_gt_zero m 2,\n            apply zero_lt_one_add,\n            exact h,\n        },\n        {\n            apply le_of_dvd,\n            apply zero_lt_one_add,\n            exact h,\n        },\n    }\nend\n\n/- Lemma: Given a factor of a natural number `≥ 2`, if that\n   factor is not `1`, it must be also `≥ 2` -/\nlemma ge_two_of_factor_not_one (a b : ℕ) (h : a ≠ 1) (h2 : 2 ≤ b) : b % a = 0 → 2 ≤ a :=\nbegin\n    intro hd,\n    apply le_of_not_gt,\n    rw gt_from_lt,\n    rw ← zero_or_one,\n    apply not_or,\n    {\n        by_contra haz,\n        have hmz := mod_zero b,\n        rw haz at hd,\n        rw hmz at hd,\n        have hzo := @or.inl (b = 0) (b = 1) hd,\n        rw zero_or_one at hzo,\n        have h2n := not_le_of_gt hzo,\n        apply absurd h2 h2n,\n    },\n    {\n        rw ← ne.def,\n        exact h,\n    },\nend\n\n/- Lemma: Given a natural number `≥ 2`, that number has at\n   least one factor that is prime. -/\nlemma exists_prime_factor : ∀ (n : ℕ), 2 ≤ n → ∃ (p : ℕ), prime p ∧ n % p = 0 :=\nbegin\n    intro n,\n    intro h,\n    have hnge2 := le.dest h,\n    cases hnge2 with m hm,\n    rw ← hm,\n    clear hm,\n    induction m using nat.case_strong_induction_on with d hd,\n    {\n        use 2,\n        split,\n        {\n            exact two_is_prime,\n        },\n        {\n            rw add_zero,\n            exact mod_self 2,\n        }\n    },\n    {\n        have h2 := @classical.or_not (prime (2 + succ d)),\n        cases h2,\n        {\n            use (2 + succ d),\n            split,\n            {\n                exact h2,\n            },\n            {\n                apply mod_self,\n            }\n        },\n        {\n            rw prime_def_lt at h2,\n            rw not_and at h2,\n            have h2lsd := @le_add_right 2 (succ d),\n            have h3 := h2 h2lsd,\n            have hnf1 := classical.not_forall.1,\n            have h4 := hnf1 h3,\n            cases h4 with x hx,\n            have h5 := not_imp.1 hx,\n            have h6 := not_imp.1 (h5.right),\n            have hxne1 := h6.right,\n            rw ← ne.def at hxne1,\n            have hxdvd := h6.left,\n            have hmodx := mod_eq_zero_of_dvd hxdvd,\n            have hxge2 := ge_two_of_factor_not_one x (2 + succ d) hxne1 h2lsd hmodx,\n            cases (le.dest hxge2) with y hy,\n            have hlt := h5.left,\n            rw ← hy at hlt,\n            have hyltsd := lt_of_add_lt_add_left hlt,\n            have hyled := le_of_lt_succ hyltsd,\n            have hdy := hd y hyled,\n            cases hdy with p hp,\n            use p,\n            split,\n            {\n                apply hp.left,\n            },\n            {\n                apply mod_eq_zero_of_dvd,\n                apply dvd_trans,\n                {\n                    rw dvd_iff_mod_eq_zero,\n                    apply hp.right,\n                },\n                {\n                    rw hy,\n                    exact hxdvd,\n                },\n            },\n        },\n    },\nend\n\n/- Lemma: Given a natural number `n`, every natural number\n   between `1` and `n` inclusive divides `n` factorial. -/\nlemma factorial_mod_zero (n d : ℕ) (h : d ≤ n) (h2 : 1 ≤ d) : (factorial n) % d = 0 :=\nbegin\n    apply mod_eq_zero_of_dvd,\n    apply dvd_factorial,\n    {\n        exact h2,\n    },\n    {\n        exact h,\n    },\nend\n\n/- Lemma: Given `d ≥ 2` and `n`, where `n mod d` is `0`,\n   `(n + 1) mod d` is `1`. -/\nlemma mod_zero_add_one_is_one (n d : ℕ) (h: 2 ≤ d) : n % d = 0 → (n + 1) % d = 1 :=\nbegin\n    intro hmz,\n    rw add_comm,\n    rw ← @add_mod_mod 1 n d,\n    rw hmz,\n    rw add_zero,\n    have hle := le.dest h,\n    cases hle with c hc,\n    rw ← hc,\n    rw add_comm,\n    apply one_mod,\nend\n\n/-\n    Theorem: Given a natural number `n ≥ 2`, there exists a\n    prime `p` where `p > n`.\n\n    This proof is inspired by Euclid's proof of existence\n    of infinitely many primes. The proof will be written\n    inline accompanying the corresponding Lean code.\n-/   \n-- Let `n` be a natural number such that `n ≥ 2`.\ntheorem infinite_primes (n : ℕ) (h : 2 ≤ n) : ∃ (p : ℕ), prime p ∧ p > n :=\nbegin\n    -- We have that `n! ≥ n` as a property of factorials.\n    have hnlnf := self_le_factorial n,\n    -- Since `n ≥ 2`, it must be the case that `n! ≥ 2`.\n    have hfng2 := le_trans h hnlnf,\n    -- Thus, `n! + 1 ≥ 2`.\n    have hfnp1g2 := le_trans hfng2 (le_add_right (factorial n) 1),\n    -- From an above lemma, we have shown that any `x ≥ 2`\n    -- has a prime factor.\n    -- Therefore, `n! + 1` has a prime factor.\n    have h1 := exists_prime_factor (factorial n + 1) hfnp1g2,\n    -- Let `p` be a prime factor of `n! + 1`.\n    cases h1 with p hp,\n    -- We want to show that `p` is a prime greater than `n`.\n    use p,\n    -- `p` is prime because it is a prime factor of\n    -- `n! + 1`.\n    have hprime := hp.left,\n    split,\n    -- We will start by showing that `p` is prime.\n    {\n        -- We have already shown just now that `p` is\n        -- prime, so we are done.\n        exact hprime,\n    },\n    -- Now we have to show that `p > n`.\n    {\n        -- By contradiction, assume that it is not the case\n        -- that `p > n`.\n        by_contra hnpgn,\n        -- At this point, we will work backwards to show\n        -- that a contradiction occurs. This backwards\n        -- solving style may be a bit unintuitive for\n        -- reading a regular proof in, but it is the style\n        -- that is preferred by Lean.\n        -- Since we have shown that `n! + 1` has `p` as a\n        -- factor, we can create a contradiction by showing\n        -- that `n! + 1` does not have `p` has a factor.\n        apply absurd hp.right,\n        -- To do this, we want to show that\n        -- `(n! + 1) mod p ≠ 0`.\n        rw ← ne_from_not_eq ((factorial n + 1) % p) 0,\n        -- This can be achieved by showing that\n        -- `(n! + 1) mod p > 0`.\n        apply ne_of_gt,\n        -- This can be achieved by showing that\n        -- `(n! + 1) mod p = 1`.\n        apply gt_zero_of_eq_one,\n        -- If we know that `n! mod p = 0`, along with\n        -- `p ≥ 2`, we can use one\n        -- of our above lemmas to show that\n        -- `(n! + 1) mod p = 1`.\n        apply mod_zero_add_one_is_one,\n        -- First we need to show that `p ≥ 2`.\n        {\n            -- We know that all primes `p` satisfy `p ≥ 2`,\n            -- so we just need to show that `p` is prime.\n            apply prime.two_le,\n            -- However, we have already shown that `p` is\n            -- prime, so we can conclude `p ≥ 2`.\n            apply hprime,\n        },\n        -- Now we need to show that `n! mod p = 0`.\n        {\n            -- We can rewrite this as `p divides n!`.\n            rw ← dvd_iff_mod_eq_zero,\n            -- We can use the basic property of factorials\n            -- where for all `0 < p ≤ n`, `p divides n!`.\n            apply dvd_factorial,\n            -- First we need to show that `p > 0`.\n            {\n                -- This is equivalent to `p ≥ 1`.\n                apply lt_of_succ_le,\n                -- We know that `p ≥ 1` when `p ≥ 2`.\n                apply le_of_succ_le,\n                -- Which is true if `p` is a prime.\n                apply prime.two_le,\n                -- And we already know that `p` is a prime,\n                -- so we can conclude that `p > 0`.\n                apply hprime,\n            },\n            -- Lastly, we need to show that `p ≤ n`.\n            {\n                -- This is equivalent to showing the\n                -- inverse of `p > n`.\n                apply le_of_not_gt,\n                -- We assumed in our contradiction that it\n                -- is not the case that `p > n`. Thus,\n                -- `p ≤ n`.\n                exact hnpgn,\n            },\n            -- We are now done with the proof!\n            -- As a recap of the backwards logic,\n            -- by contradiction, we assumed that `p ≤ n`.\n            -- Therefore, since `p ≥ 0`, we have that\n            -- `p divides n!`.\n        },\n        -- Therefore, `n! mod p = 0`.\n        -- Therefore, since `p ≥ 2`, `(n! + 1) mod p = 1`.\n        -- However, we defined `p` as being a prime factor\n        -- of `(n! + 1)`, so `(n! + 1) mod p = 0`.\n        -- This is a contradiction, so it must be the case\n        -- that `p > n`.\n        -- Since we have already shown that `p` is prime,\n        -- we can conclude that for all natural numbers\n        -- `n`, there exists a prime `p` such that `p > n`.\n    },\nend\n\nend nat", "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/prime.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810525948927, "lm_q2_score": 0.798186787341014, "lm_q1q2_score": 0.7561870387584656}}
{"text": "import tactic data.rat data.nat.prime data.real.irrational\nimport analysis.special_functions.pow\n\nopen real\n\n/-\nWe show there exist irrational numbers `a` and `b` such that `a ^ b` is rational.\n-/\n\nlemma ss_nat : sqrt 2 ^ 2 = 2 := sq_sqrt zero_le_two\n\nlemma sq_sqrt2 : (sqrt 2)^(2 : ℝ) = 2 := by { conv_rhs { rw ←ss_nat}, simp [←rpow_nat_cast] }\n\n-- A proof using `convert`.\nexample : ∃ a b : ℝ, irrational a ∧ irrational b ∧ ¬(irrational (a ^ b)) :=\nbegin\n  have irrs2 := irrational_sqrt_two,\n  by_cases h : irrational ((sqrt 2)^(sqrt 2)),\n  { use [(sqrt 2)^(sqrt 2), sqrt 2],\n    split, { exact h }, clear h,  split, { exact irrs2 },\n    rw [←rpow_mul (sqrt_nonneg 2), ←pow_two, ss_nat, sq_sqrt2],\n    have := rat.not_irrational 2, simpa, },\n  { use [sqrt 2, sqrt 2], tauto, }\nend", "meta": {"author": "gihanmarasingha", "repo": "exleanblog", "sha": "aa6dc06cb64376dc87ba680815b9d14a904ad2ff", "save_path": "github-repos/lean/gihanmarasingha-exleanblog", "path": "github-repos/lean/gihanmarasingha-exleanblog/exleanblog-aa6dc06cb64376dc87ba680815b9d14a904ad2ff/src/2021/06/pow_irrational_irrational.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.7981867801399695, "lm_q1q2_score": 0.7561870224497121}}
{"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-/\nimport order.succ_pred.basic\n/-!\n# Relations on types with a `succ_order`\n\nThis file contains properties about relations on types with a `succ_order`\nand their closure operations (like the transitive closure).\n-/\n\nopen function order relation set\n\nsection partial_succ\nvariables {α : Type*} [partial_order α] [succ_order α] [is_succ_archimedean α]\n\n/-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_succ_of_le (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n ≤ m) : refl_trans_gen r n m :=\nbegin\n  revert h, refine succ.rec _ _ hnm,\n  { intros h, exact refl_trans_gen.refl },\n  { intros m hnm ih h,\n    have : refl_trans_gen r n m := ih (λ i hi, h i ⟨hi.1, hi.2.trans_le $ le_succ m⟩),\n    cases (le_succ m).eq_or_lt with hm hm, { rwa [← hm] },\n    exact this.tail (h m ⟨hnm, hm⟩) }\nend\n\n/-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `succ i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_succ_of_ge (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m ≤ n) : refl_trans_gen r n m :=\nby { rw [← refl_trans_gen_swap], exact refl_trans_gen_of_succ_of_le (swap r) h hmn }\n\n/-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_lt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n < m) : trans_gen r n m :=\n(refl_trans_gen_iff_eq_or_trans_gen.mp $ refl_trans_gen_of_succ_of_le r h hnm.le).resolve_left\n  hnm.ne'\n\n/-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` if `succ i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_gt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m < n) : trans_gen r n m :=\n(refl_trans_gen_iff_eq_or_trans_gen.mp $ refl_trans_gen_of_succ_of_ge r h hmn.le).resolve_left\n  hmn.ne\n\nend partial_succ\n\nsection linear_succ\nvariables {α : Type*} [linear_order α] [succ_order α] [is_succ_archimedean α]\n\n/-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i` and `succ i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_succ (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : refl_trans_gen r n m :=\n(le_total n m).elim (refl_trans_gen_of_succ_of_le r h1) $ refl_trans_gen_of_succ_of_ge r h2\n\n/-- For `n ≠ m`,`(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i` and\n  `succ i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_ne (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i)\n  (hnm : n ≠ m) : trans_gen r n m :=\n(refl_trans_gen_iff_eq_or_trans_gen.mp (refl_trans_gen_of_succ r h1 h2)).resolve_left hnm.symm\n\n\n/-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ succ i` and\n  `succ i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_reflexive (r : α → α → Prop) {n m : α} (hr : reflexive r)\n  (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : trans_gen r n m :=\nbegin\n  rcases eq_or_ne m n with rfl|hmn, { exact trans_gen.single (hr m) },\n  exact trans_gen_of_succ_of_ne r h1 h2 hmn.symm\nend\n\nend linear_succ\n\nsection partial_pred\nvariables {α : Type*} [partial_order α] [pred_order α] [is_pred_archimedean α]\n\n/-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_pred_of_ge (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m ≤ n) : refl_trans_gen r n m :=\n@refl_trans_gen_of_succ_of_le (order_dual α) _ _ _ r n m (λ x hx, h x ⟨hx.2, hx.1⟩) hnm\n\n/-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `pred i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_pred_of_le (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n ≤ m) : refl_trans_gen r n m :=\n@refl_trans_gen_of_succ_of_ge (order_dual α) _ _ _ r n m (λ x hx, h x ⟨hx.2, hx.1⟩) hmn\n\n/-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `i ~ pred i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_gt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m < n) : trans_gen r n m :=\n@trans_gen_of_succ_of_lt (order_dual α) _ _ _ r _ _ (λ x hx, h x ⟨hx.2, hx.1⟩) hnm\n\n/-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `pred i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_lt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n < m) : trans_gen r n m :=\n@trans_gen_of_succ_of_gt (order_dual α) _ _ _ r _ _ (λ x hx, h x ⟨hx.2, hx.1⟩) hmn\n\nend partial_pred\n\nsection linear_pred\nvariables {α : Type*} [linear_order α] [pred_order α] [is_pred_archimedean α]\n\n/-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i` and `pred i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_pred (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : refl_trans_gen r n m :=\n@refl_trans_gen_of_succ (order_dual α) _ _ _ r n m (λ x hx, h1 x ⟨hx.2, hx.1⟩)\n  (λ x hx, h2 x ⟨hx.2, hx.1⟩)\n\n/-- For `n ≠ m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ pred i` and\n  `pred i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_ne (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i)\n  (hnm : n ≠ m) : trans_gen r n m :=\n@trans_gen_of_succ_of_ne (order_dual α) _ _ _ r n m (λ x hx, h1 x ⟨hx.2, hx.1⟩)\n  (λ x hx, h2 x ⟨hx.2, hx.1⟩) hnm\n\n/-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ pred i` and\n  `pred i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_reflexive (r : α → α → Prop) {n m : α} (hr : reflexive r)\n  (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : trans_gen r n m :=\n@trans_gen_of_succ_of_reflexive (order_dual α) _ _ _ r n m hr (λ x hx, h1 x ⟨hx.2, hx.1⟩)\n  (λ x hx, h2 x ⟨hx.2, hx.1⟩)\n\nend linear_pred\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/succ_pred/relation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.756147149389742}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Mario Carneiro\n\nTheory of topological spaces.\n\nParts of the formalization is based on the books:\n  N. Bourbaki: General Topology\n  I. M. James: Topologies and Uniformities\nA major difference is that this formalization is heavily based on the filter library.\n-/\nimport order.filter data.set.countable tactic\n\nopen set filter lattice classical\nlocal attribute [instance] prop_decidable\n\nuniverses u v w\n\nstructure topological_space (α : Type u) :=\n(is_open       : set α → Prop)\n(is_open_univ   : is_open univ)\n(is_open_inter  : ∀s t, is_open s → is_open t → is_open (s ∩ t))\n(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))\n\nattribute [class] topological_space\n\nsection topological_space\n\nvariables {α : Type u} {β : Type v} {ι : Sort w} {a : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop}\n\n@[extensionality]\nlemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g\n| ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl\n\nsection\nvariables [t : topological_space α]\ninclude t\n\n/-- `is_open s` means that `s` is open in the ambient topological space on `α` -/\ndef is_open (s : set α) : Prop := topological_space.is_open t s\n\n@[simp]\nlemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t\n\nlemma is_open_inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) :=\ntopological_space.is_open_inter t s₁ s₂ h₁ h₂\n\nlemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) :=\ntopological_space.is_open_sUnion t s h\n\nend\n\nlemma is_open_fold {s : set α} {t : topological_space α} : t.is_open s = @is_open α t s :=\nrfl\n\nvariables [topological_space α]\n\nlemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=\nis_open_sUnion $ by rintro _ ⟨i, rfl⟩; exact h i\n\nlemma is_open_bUnion {s : set β} {f : β → set α} (h : ∀i∈s, is_open (f i)) :\n  is_open (⋃i∈s, f i) :=\nis_open_Union $ assume i, is_open_Union $ assume hi, h i hi\n\nlemma is_open_union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) :=\nby rw union_eq_Union; exact is_open_Union (bool.forall_bool.2 ⟨h₂, h₁⟩)\n\n@[simp] lemma is_open_empty : is_open (∅ : set α) :=\nby rw ← sUnion_empty; exact is_open_sUnion (assume a, false.elim)\n\nlemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) :=\nfinite.induction_on hs (λ _, by rw sInter_empty; exact is_open_univ) $\nλ a s has hs ih h, by rw sInter_insert; exact\nis_open_inter (h _ $ mem_insert _ _) (ih $ λ t, h t ∘ mem_insert_of_mem _)\n\nlemma is_open_bInter {s : set β} {f : β → set α} (hs : finite s) :\n  (∀i∈s, is_open (f i)) → is_open (⋂i∈s, f i) :=\nfinite.induction_on hs\n  (λ _, by rw bInter_empty; exact is_open_univ)\n  (λ a s has hs ih h, by rw bInter_insert; exact\n    is_open_inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))\n\nlemma is_open_const {p : Prop} : is_open {a : α | p} :=\nby_cases\n  (assume : p, begin simp only [this]; exact is_open_univ end)\n  (assume : ¬ p, begin simp only [this]; exact is_open_empty end)\n\nlemma is_open_and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} :=\nis_open_inter\n\n/-- A set is closed if its complement is open -/\ndef is_closed (s : set α) : Prop := is_open (-s)\n\n@[simp] lemma is_closed_empty : is_closed (∅ : set α) :=\nby unfold is_closed; rw compl_empty; exact is_open_univ\n\n@[simp] lemma is_closed_univ : is_closed (univ : set α) :=\nby unfold is_closed; rw compl_univ; exact is_open_empty\n\nlemma is_closed_union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) :=\nλ h₁ h₂, by unfold is_closed; rw compl_union; exact is_open_inter h₁ h₂\n\nlemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) :=\nby simp only [is_closed, compl_sInter, sUnion_image]; exact assume h, is_open_Union $ assume t, is_open_Union $ assume ht, h t ht\n\nlemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) :=\nis_closed_sInter $ assume t ⟨i, (heq : f i = t)⟩, heq ▸ h i\n\n@[simp] lemma is_open_compl_iff {s : set α} : is_open (-s) ↔ is_closed s := iff.rfl\n\n@[simp] lemma is_closed_compl_iff {s : set α} : is_closed (-s) ↔ is_open s :=\nby rw [←is_open_compl_iff, compl_compl]\n\nlemma is_open_diff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s \\ t) :=\nis_open_inter h₁ $ is_open_compl_iff.mpr h₂\n\nlemma is_closed_inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) :=\nby rw [is_closed, compl_inter]; exact is_open_union h₁ h₂\n\nlemma is_closed_Union {s : set β} {f : β → set α} (hs : finite s) :\n  (∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) :=\nfinite.induction_on hs\n  (λ _, by rw bUnion_empty; exact is_closed_empty)\n  (λ a s has hs ih h, by rw bUnion_insert; exact\n    is_closed_union (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))\n\nlemma is_closed_imp {p q : α → Prop} (hp : is_open {x | p x})\n  (hq : is_closed {x | q x}) : is_closed {x | p x → q x} :=\nhave {x | p x → q x} = (- {x | p x}) ∪ {x | q x}, from set.ext $ λ x, imp_iff_not_or,\nby rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq\n\nlemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} :=\nis_open_compl_iff.mpr\n\n/-- The interior of a set `s` is the largest open subset of `s`. -/\ndef interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s}\n\nlemma mem_interior {s : set α} {x : α} :\n  x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t :=\nby simp only [interior, mem_set_of_eq, exists_prop, and_assoc, and.left_comm]\n\n@[simp] lemma is_open_interior {s : set α} : is_open (interior s) :=\nis_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁\n\nlemma interior_subset {s : set α} : interior s ⊆ s :=\nsUnion_subset $ assume t ⟨h₁, h₂⟩, h₂\n\nlemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s :=\nsubset_sUnion_of_mem ⟨h₂, h₁⟩\n\nlemma interior_eq_of_open {s : set α} (h : is_open s) : interior s = s :=\nsubset.antisymm interior_subset (interior_maximal (subset.refl s) h)\n\nlemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s :=\n⟨assume h, h ▸ is_open_interior, interior_eq_of_open⟩\n\nlemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s :=\nby simp only [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset, true_and]\n\nlemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) :\n  s ⊆ interior t ↔ s ⊆ t :=\n⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩\n\nlemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t :=\ninterior_maximal (subset.trans interior_subset h) is_open_interior\n\n@[simp] lemma interior_empty : interior (∅ : set α) = ∅ :=\ninterior_eq_of_open is_open_empty\n\n@[simp] lemma interior_univ : interior (univ : set α) = univ :=\ninterior_eq_of_open is_open_univ\n\n@[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s :=\ninterior_eq_of_open is_open_interior\n\n@[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t :=\nsubset.antisymm\n  (subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t))\n  (interior_maximal (inter_subset_inter interior_subset interior_subset) $ is_open_inter is_open_interior is_open_interior)\n\nlemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s) (h₂ : interior t = ∅) :\n  interior (s ∪ t) = interior s :=\nhave interior (s ∪ t) ⊆ s, from\n  assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩,\n  classical.by_contradiction $ assume hx₂ : x ∉ s,\n    have u \\ s ⊆ t,\n      from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂,\n    have u \\ s ⊆ interior t,\n      by rwa subset_interior_iff_subset_of_open (is_open_diff hu₁ h₁),\n    have u \\ s ⊆ ∅,\n      by rwa h₂ at this,\n    this ⟨hx₁, hx₂⟩,\nsubset.antisymm\n  (interior_maximal this is_open_interior)\n  (interior_mono $ subset_union_left _ _)\n\nlemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t :=\nby rw ← subset_interior_iff_open; simp only [subset_def, mem_interior]\n\n/-- The closure of `s` is the smallest closed set containing `s`. -/\ndef closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t}\n\n@[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) :=\nis_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁\n\nlemma subset_closure {s : set α} : s ⊆ closure s :=\nsubset_sInter $ assume t ⟨h₁, h₂⟩, h₂\n\nlemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t :=\nsInter_subset_of_mem ⟨h₂, h₁⟩\n\nlemma closure_eq_of_is_closed {s : set α} (h : is_closed s) : closure s = s :=\nsubset.antisymm (closure_minimal (subset.refl s) h) subset_closure\n\nlemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s :=\n⟨assume h, h ▸ is_closed_closure, closure_eq_of_is_closed⟩\n\nlemma closure_subset_iff_subset_of_is_closed {s t : set α} (h₁ : is_closed t) :\n  closure s ⊆ t ↔ s ⊆ t :=\n⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩\n\nlemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t :=\nclosure_minimal (subset.trans h subset_closure) is_closed_closure\n\nlemma is_closed_of_closure_subset {s : set α} (h : closure s ⊆ s) : is_closed s :=\nby rw subset.antisymm subset_closure h; exact is_closed_closure\n\n@[simp] lemma closure_empty : closure (∅ : set α) = ∅ :=\nclosure_eq_of_is_closed is_closed_empty\n\nlemma closure_empty_iff (s : set α) : closure s = ∅ ↔ s = ∅ :=\nbegin\n  split; intro h,\n  { rw set.eq_empty_iff_forall_not_mem,\n    intros x H,\n    simpa only [h] using subset_closure H },\n  { exact (eq.symm h) ▸ closure_empty },\nend\n\n@[simp] lemma closure_univ : closure (univ : set α) = univ :=\nclosure_eq_of_is_closed is_closed_univ\n\n@[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s :=\nclosure_eq_of_is_closed is_closed_closure\n\n@[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t :=\nsubset.antisymm\n  (closure_minimal (union_subset_union subset_closure subset_closure) $ is_closed_union is_closed_closure is_closed_closure)\n  (union_subset (closure_mono $ subset_union_left _ _) (closure_mono $ subset_union_right _ _))\n\nlemma interior_subset_closure {s : set α} : interior s ⊆ closure s :=\nsubset.trans interior_subset subset_closure\n\nlemma closure_eq_compl_interior_compl {s : set α} : closure s = - interior (- s) :=\nbegin\n  unfold interior closure is_closed,\n  rw [compl_sUnion, compl_image_set_of],\n  simp only [compl_subset_compl]\nend\n\n@[simp] lemma interior_compl {s : set α} : interior (- s) = - closure s :=\nby simp [closure_eq_compl_interior_compl]\n\n@[simp] lemma closure_compl {s : set α} : closure (- s) = - interior s :=\nby simp [closure_eq_compl_interior_compl]\n\ntheorem mem_closure_iff {s : set α} {a : α} : a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → o ∩ s ≠ ∅ :=\n⟨λ h o oo ao os,\n  have s ⊆ -o, from λ x xs xo, @ne_empty_of_mem α (o∩s) x ⟨xo, xs⟩ os,\n  closure_minimal this (is_closed_compl_iff.2 oo) h ao,\nλ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc,\n  let ⟨x, hc, hs⟩ := exists_mem_of_ne_empty (H _ h₁ nc) in hc (h₂ hs)⟩\n\nlemma dense_iff_inter_open {s : set α} : closure s = univ ↔ ∀ U, is_open U → U ≠ ∅ → U ∩ s ≠ ∅ :=\nbegin\n  split ; intro h,\n  { intros U U_op U_ne,\n    cases exists_mem_of_ne_empty U_ne with x x_in,\n    exact mem_closure_iff.1 (by simp only [h]) U U_op x_in },\n  { apply eq_univ_of_forall, intro x,\n    rw mem_closure_iff,\n    intros U U_op x_in,\n    exact h U U_op (ne_empty_of_mem x_in) },\nend\n\n/-- The frontier of a set is the set of points between the closure and interior. -/\ndef frontier (s : set α) : set α := closure s \\ interior s\n\nlemma frontier_eq_closure_inter_closure {s : set α} :\n  frontier s = closure s ∩ closure (- s) :=\nby rw [closure_compl, frontier, diff_eq]\n\n@[simp] lemma frontier_compl (s : set α) : frontier (-s) = frontier s :=\nby simp only [frontier_eq_closure_inter_closure, lattice.neg_neg, inter_comm]\n\nlemma is_closed_frontier {s : set α} : is_closed (frontier s) :=\nby rw frontier_eq_closure_inter_closure; exact is_closed_inter is_closed_closure is_closed_closure\n\nlemma interior_frontier {s : set α} (h : is_closed s) : interior (frontier s) = ∅ :=\nbegin\n  have A : frontier s = s \\ interior s, by rw [frontier, closure_eq_of_is_closed h],\n  have B : interior (frontier s) ⊆ interior s, by rw A; exact interior_mono (diff_subset _ _),\n  have C : interior (frontier s) ⊆ frontier s := interior_subset,\n  have : interior (frontier s) ⊆ (interior s) ∩ (s \\ interior s) :=\n    subset_inter B (by simpa [A] using C),\n  rwa [inter_diff_self, subset_empty_iff] at this,\nend\n\n/-- neighbourhood filter -/\ndef nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s)\n\nlemma nhds_sets {a : α} : (nhds a).sets = {s | ∃t⊆s, is_open t ∧ a ∈ t} :=\ncalc (nhds a).sets = (⋃s∈{s : set α| a ∈ s ∧ is_open s}, (principal s).sets) : infi_sets_eq'\n  (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,\n    ⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩,\n      le_principal_iff.2 (inter_subset_left _ _),\n      le_principal_iff.2 (inter_subset_right _ _)⟩)\n  ⟨univ, mem_univ _, is_open_univ⟩\n  ... = {s | ∃t⊆s, is_open t ∧ a ∈ t} :\n    le_antisymm\n      (supr_le $ assume i, supr_le $ assume ⟨hi₁, hi₂⟩ t ht, ⟨i, ht, hi₂, hi₁⟩)\n      (assume t ⟨i, hi₁, hi₂, hi₃⟩, mem_Union.2 ⟨i, mem_Union.2 ⟨⟨hi₃, hi₂⟩, hi₁⟩⟩)\n\nlemma map_nhds {a : α} {f : α → β} :\n  map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal (image f s)) :=\ncalc map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, map f (principal s)) :\n    map_binfi_eq\n    (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,\n      ⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩,\n      le_principal_iff.2 (inter_subset_left _ _),\n      le_principal_iff.2 (inter_subset_right _ _)⟩)\n    ⟨univ, mem_univ _, is_open_univ⟩\n  ... = _ : by simp only [map_principal]\n\nlemma mem_nhds_sets_iff {a : α} {s : set α} :\n s ∈ nhds a ↔ ∃t⊆s, is_open t ∧ a ∈ t :=\nby simp only [nhds_sets, mem_set_of_eq, exists_prop]\n\nlemma mem_of_nhds {a : α} {s : set α} : s ∈ nhds a → a ∈ s :=\nλ H, let ⟨t, ht, _, hs⟩ := mem_nhds_sets_iff.1 H in ht hs\n\nlemma mem_nhds_sets {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :\n s ∈ nhds a :=\nmem_nhds_sets_iff.2 ⟨s, subset.refl _, hs, ha⟩\n\ntheorem all_mem_nhds (x : α) (P : set α → Prop) (hP : ∀ s t, s ⊆ t → P s → P t) :\n  (∀ s ∈ nhds x, P s) ↔ (∀ s, is_open s → x ∈ s → P s) :=\niff.intro\n  (λ h s os xs, h s (mem_nhds_sets os xs))\n  (λ h t,\n    begin\n      change t ∈ (nhds x).sets → P t,\n      rw nhds_sets,\n      rintros ⟨s, hs, opens, xs⟩,\n      exact hP _ _ hs (h s opens xs),\n    end)\n\ntheorem all_mem_nhds_filter (x : α) (f : set α → set β) (hf : ∀ s t, s ⊆ t → f s ⊆ f t)\n    (l : filter β) :\n  (∀ s ∈ nhds x, f s ∈ l) ↔ (∀ s, is_open s → x ∈ s → f s ∈ l) :=\nall_mem_nhds _ _ (λ s t ssubt h, mem_sets_of_superset h (hf s t ssubt))\n\ntheorem rtendsto_nhds {r : rel β α} {l : filter β} {a : α} :\n  rtendsto r l (nhds a) ↔ (∀ s, is_open s → a ∈ s → r.core s ∈ l) :=\nall_mem_nhds_filter _ _ (λ s t h, λ x hx, λ y hy, h (hx y hy)) _\n\ntheorem rtendsto'_nhds {r : rel β α} {l : filter β} {a : α} :\n  rtendsto' r l (nhds a) ↔ (∀ s, is_open s → a ∈ s → r.preimage s ∈ l) :=\nby { rw [rtendsto'_def], apply all_mem_nhds_filter, apply rel.preimage_mono }\n\ntheorem ptendsto_nhds {f : β →. α} {l : filter β} {a : α} :\n  ptendsto f l (nhds a) ↔ (∀ s, is_open s → a ∈ s → f.core s ∈ l) :=\nrtendsto_nhds\n\ntheorem ptendsto'_nhds {f : β →. α} {l : filter β} {a : α} :\n  ptendsto' f l (nhds a) ↔ (∀ s, is_open s → a ∈ s → f.preimage s ∈ l) :=\nrtendsto'_nhds\n\ntheorem tendsto_nhds {f : β → α} {l : filter β} {a : α} :\n  tendsto f l (nhds a) ↔ (∀ s, is_open s → a ∈ s → f ⁻¹' s ∈ l) :=\nall_mem_nhds_filter _ _ (λ s t h, preimage_mono h) _\n\nlemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (nhds a) :=\ntendsto_nhds.mpr $ assume s hs ha, univ_mem_sets' $ assume _, ha\n\n\nlemma pure_le_nhds : pure ≤ (nhds : α → filter α) :=\nassume a, le_infi $ assume s, le_infi $ assume ⟨h₁, _⟩, principal_mono.mpr $\n  singleton_subset_iff.2 h₁\n\nlemma tendsto_pure_nhds [topological_space β] (f : α → β) (a : α) :\n  tendsto f (pure a) (nhds (f a)) :=\nbegin\n  rw [tendsto, filter.map_pure],\n  exact pure_le_nhds (f a)\nend\n\n@[simp] lemma nhds_neq_bot {a : α} : nhds a ≠ ⊥ :=\nassume : nhds a = ⊥,\nhave pure a = (⊥ : filter α),\n  from lattice.bot_unique $ this ▸ pure_le_nhds a,\npure_neq_bot this\n\nlemma interior_eq_nhds {s : set α} : interior s = {a | nhds a ≤ principal s} :=\nset.ext $ λ x, by simp only [mem_interior, le_principal_iff, mem_nhds_sets_iff]; refl\n\nlemma mem_interior_iff_mem_nhds {s : set α} {a : α} :\n  a ∈ interior s ↔ s ∈ nhds a :=\nby simp only [interior_eq_nhds, le_principal_iff]; refl\n\nlemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, nhds a ≤ principal s :=\ncalc is_open s ↔ s ⊆ interior s : subset_interior_iff_open.symm\n  ... ↔ (∀a∈s, nhds a ≤ principal s) : by rw [interior_eq_nhds]; refl\n\nlemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ nhds a :=\nis_open_iff_nhds.trans $ forall_congr $ λ _, imp_congr_right $ λ _, le_principal_iff\n\nlemma closure_eq_nhds {s : set α} : closure s = {a | nhds a ⊓ principal s ≠ ⊥} :=\ncalc closure s = - interior (- s) : closure_eq_compl_interior_compl\n  ... = {a | ¬ nhds a ≤ principal (-s)} : by rw [interior_eq_nhds]; refl\n  ... = {a | nhds a ⊓ principal s ≠ ⊥} : set.ext $ assume a, not_congr\n    (inf_eq_bot_iff_le_compl\n      (show principal s ⊔ principal (-s) = ⊤, by simp only [sup_principal, union_compl_self, principal_univ])\n      (by simp only [inf_principal, inter_compl_self, principal_empty])).symm\n\ntheorem mem_closure_iff_nhds {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ nhds a, t ∩ s ≠ ∅ :=\nmem_closure_iff.trans\n⟨λ H t ht, subset_ne_empty\n  (inter_subset_inter_left _ interior_subset)\n  (H _ is_open_interior (mem_interior_iff_mem_nhds.2 ht)),\n λ H o oo ao, H _ (mem_nhds_sets oo ao)⟩\n\n/-- `x` belongs to the closure of `s` if and only if some ultrafilter\n  supported on `s` converges to `x`. -/\nlemma mem_closure_iff_ultrafilter {s : set α} {x : α} :\n  x ∈ closure s ↔ ∃ (u : ultrafilter α), s ∈ u.val ∧ u.val ≤ nhds x :=\nbegin\n  rw closure_eq_nhds, change nhds x ⊓ principal s ≠ ⊥ ↔ _, symmetry,\n  convert exists_ultrafilter_iff _, ext u,\n  rw [←le_principal_iff, inf_comm, le_inf_iff]\nend\n\nlemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s :=\ncalc is_closed s ↔ closure s = s : by rw [closure_eq_iff_is_closed]\n  ... ↔ closure s ⊆ s : ⟨assume h, by rw h, assume h, subset.antisymm h subset_closure⟩\n  ... ↔ (∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s) : by rw [closure_eq_nhds]; refl\n\nlemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) :=\nassume a ⟨hs, ht⟩,\nhave s ∈ nhds a, from mem_nhds_sets h hs,\nhave nhds a ⊓ principal s = nhds a, from inf_of_le_left $ by rwa le_principal_iff,\nhave nhds a ⊓ principal (s ∩ t) ≠ ⊥,\n  from calc nhds a ⊓ principal (s ∩ t) = nhds a ⊓ (principal s ⊓ principal t) : by rw inf_principal\n    ... = nhds a ⊓ principal t : by rw [←inf_assoc, this]\n    ... ≠ ⊥ : by rw [closure_eq_nhds] at ht; assumption,\nby rw [closure_eq_nhds]; assumption\n\nlemma closure_diff {s t : set α} : closure s - closure t ⊆ closure (s - t) :=\ncalc closure s \\ closure t = (- closure t) ∩ closure s : by simp only [diff_eq, inter_comm]\n  ... ⊆ closure (- closure t ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure\n  ... = closure (s \\ closure t) : by simp only [diff_eq, inter_comm]\n  ... ⊆ closure (s \\ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure\n\nlemma mem_of_closed_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}\n  (hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (hs : is_closed s) (h : f ⁻¹' s ∈ b) : a ∈ s :=\nhave b.map f ≤ nhds a ⊓ principal s,\n  from le_trans (le_inf (le_refl _) (le_principal_iff.mpr h)) (inf_le_inf hf (le_refl _)),\nis_closed_iff_nhds.mp hs a $ neq_bot_of_le_neq_bot (map_ne_bot hb) this\n\nlemma mem_of_closed_of_tendsto' {f : β → α} {x : filter β} {a : α} {s : set α}\n  (hf : tendsto f x (nhds a)) (hs : is_closed s) (h : x ⊓ principal (f ⁻¹' s) ≠ ⊥) : a ∈ s :=\nis_closed_iff_nhds.mp hs _ $ neq_bot_of_le_neq_bot (@map_ne_bot _ _ _ f h) $\n  le_inf (le_trans (map_mono $ inf_le_left) hf) $\n    le_trans (map_mono $ inf_le_right_of_le $ by simp only [comap_principal, le_principal_iff]; exact subset.refl _) (@map_comap_le _ _ _ f)\n\nlemma mem_closure_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}\n  (hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (h : f ⁻¹' s ∈ b) : a ∈ closure s :=\nmem_of_closed_of_tendsto hb hf (is_closed_closure) $\n  filter.mem_sets_of_superset h (preimage_mono subset_closure)\n\n\nsection lim\nvariables [inhabited α]\n\n/-- If `f` is a filter, then `lim f` is a limit of the filter, if it exists. -/\nnoncomputable def lim (f : filter α) : α := epsilon $ λa, f ≤ nhds a\n\nlemma lim_spec {f : filter α} (h : ∃a, f ≤ nhds a) : f ≤ nhds (lim f) := epsilon_spec h\nend lim\n\n/-\nThe nhds_within filter.\n-/\n\ndef nhds_within (a : α) (s : set α) : filter α := nhds a ⊓ principal s\n\ntheorem nhds_within_eq (a : α) (s : set α) :\n  nhds_within a s = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, principal (t ∩ s) :=\nhave set.univ ∈ {s : set α | a ∈ s ∧ is_open s}, from ⟨set.mem_univ _, is_open_univ⟩,\nbegin\n  rw [nhds_within, nhds, lattice.binfi_inf]; try { exact this },\n  simp only [inf_principal]\nend\n\ntheorem nhds_within_univ (a : α) : nhds_within a set.univ = nhds a :=\nby rw [nhds_within, principal_univ, lattice.inf_top_eq]\n\ntheorem mem_nhds_within (t : set α) (a : α) (s : set α) :\n  t ∈ nhds_within a s ↔ ∃ u, is_open u ∧ a ∈ u ∧ u ∩ s ⊆ t  :=\nbegin\n  rw [nhds_within, mem_inf_principal, mem_nhds_sets_iff], split,\n  { rintros ⟨u, hu, openu, au⟩,\n    exact ⟨u, openu, au, λ x ⟨xu, xs⟩, hu xu xs⟩ },\n  rintros ⟨u, openu, au, hu⟩,\n  exact ⟨u, λ x xu xs, hu ⟨xu, xs⟩, openu, au⟩\nend\n\ntheorem nhds_within_mono (a : α) {s t : set α} (h : s ⊆ t) : nhds_within a s ≤ nhds_within a t :=\nlattice.inf_le_inf (le_refl _) (principal_mono.mpr h)\n\ntheorem nhds_within_restrict {a : α} (s : set α) {t : set α} (h₀ : a ∈ t) (h₁ : is_open t) :\n  nhds_within a s = nhds_within a (s ∩ t) :=\nhave s ∩ t ∈ nhds_within a s,\n  from inter_mem_sets (mem_inf_sets_of_right (mem_principal_self s))\n         (mem_inf_sets_of_left (mem_nhds_sets h₁ h₀)),\nle_antisymm\n  (lattice.le_inf lattice.inf_le_left (le_principal_iff.mpr this))\n  (lattice.inf_le_inf (le_refl _) (principal_mono.mpr (set.inter_subset_left _ _)))\n\ntheorem nhds_within_eq_nhds_within {a : α} {s t u : set α}\n    (h₀ : a ∈ s) (h₁ : is_open s) (h₂ : t ∩ s = u ∩ s) :\n  nhds_within a t = nhds_within a u :=\nby rw [nhds_within_restrict t h₀ h₁, nhds_within_restrict u h₀ h₁, h₂]\n\ntheorem nhs_within_eq_of_open {a : α} {s : set α} (h₀ : a ∈ s) (h₁ : is_open s) :\n  nhds_within a s = nhds a :=\nby rw [←nhds_within_univ]; apply nhds_within_eq_nhds_within h₀ h₁;\n     rw [set.univ_inter, set.inter_self]\n\n@[simp] theorem nhds_within_empty (a : α) : nhds_within a {} = ⊥ :=\nby rw [nhds_within, principal_empty, lattice.inf_bot_eq]\n\ntheorem nhds_within_union (a : α) (s t : set α) :\n  nhds_within a (s ∪ t) = nhds_within a s ⊔ nhds_within a t :=\nby unfold nhds_within; rw [←lattice.inf_sup_left, sup_principal]\n\ntheorem nhds_within_inter (a : α) (s t : set α) :\n  nhds_within a (s ∩ t) = nhds_within a s ⊓ nhds_within a t :=\nby unfold nhds_within; rw [lattice.inf_left_comm, lattice.inf_assoc, inf_principal,\n                             ←lattice.inf_assoc, lattice.inf_idem]\n\ntheorem nhds_within_inter' (a : α) (s t : set α) :\n  nhds_within a (s ∩ t) = (nhds_within a s) ⊓ principal t :=\nby { unfold nhds_within, rw [←inf_principal, lattice.inf_assoc] }\n\ntheorem tendsto_if_nhds_within {f g : α → β} {p : α → Prop} [decidable_pred p]\n    {a : α} {s : set α} {l : filter β}\n    (h₀ : tendsto f (nhds_within a (s ∩ p)) l)\n    (h₁ : tendsto g (nhds_within a (s ∩ {x | ¬ p x})) l) :\n  tendsto (λ x, if p x then f x else g x) (nhds_within a s) l :=\nby apply tendsto_if; rw [←nhds_within_inter']; assumption\n\nlemma map_nhds_within (f : α → β) (a : α) (s : set α) :\n  map f (nhds_within a s) =\n    ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, principal (set.image f (t ∩ s)) :=\nhave h₀ : directed_on ((λ (i : set α), principal (i ∩ s)) ⁻¹'o ge)\n        {x : set α | x ∈ {t : set α | a ∈ t ∧ is_open t}}, from\n  assume x ⟨ax, openx⟩ y ⟨ay, openy⟩,\n  ⟨x ∩ y, ⟨⟨ax, ay⟩, is_open_inter openx openy⟩,\n    le_principal_iff.mpr (set.inter_subset_inter_left _ (set.inter_subset_left _ _)),\n    le_principal_iff.mpr (set.inter_subset_inter_left _ (set.inter_subset_right _ _))⟩,\nhave h₁ : ∃ (i : set α), i ∈ {t : set α | a ∈ t ∧ is_open t},\n  from ⟨set.univ, set.mem_univ _, is_open_univ⟩,\nby { rw [nhds_within_eq, map_binfi_eq h₀ h₁], simp only [map_principal] }\n\ntheorem tendsto_nhds_within_mono_left {f : α → β} {a : α}\n    {s t : set α} {l : filter β} (hst : s ⊆ t) (h : tendsto f (nhds_within a t) l) :\n  tendsto f (nhds_within a s) l :=\ntendsto_le_left (nhds_within_mono a hst) h\n\ntheorem tendsto_nhds_within_mono_right {f : β → α} {l : filter β}\n    {a : α} {s t : set α} (hst : s ⊆ t) (h : tendsto f l (nhds_within a s)) :\n  tendsto f l (nhds_within a t) :=\ntendsto_le_right (nhds_within_mono a hst) h\n\ntheorem tendsto_nhds_within_of_tendsto_nhds {f : α → β} {a : α}\n    {s : set α} {l : filter β} (h : tendsto f (nhds a) l) :\n  tendsto f (nhds_within a s) l :=\nby rw [←nhds_within_univ] at h; exact tendsto_nhds_within_mono_left (set.subset_univ _) h\n\n\n/- locally finite family [General Topology (Bourbaki, 1995)] -/\nsection locally_finite\n\n/-- A family of sets in `set α` is locally finite if at every point `x:α`,\n  there is a neighborhood of `x` which meets only finitely many sets in the family -/\ndef locally_finite (f : β → set α) :=\n∀x:α, ∃t ∈ nhds x, finite {i | f i ∩ t ≠ ∅ }\n\nlemma locally_finite_of_finite {f : β → set α} (h : finite (univ : set β)) : locally_finite f :=\nassume x, ⟨univ, univ_mem_sets, finite_subset h $ subset_univ _⟩\n\nlemma locally_finite_subset\n  {f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ :=\nassume a,\nlet ⟨t, ht₁, ht₂⟩ := hf₂ a in\n⟨t, ht₁, finite_subset ht₂ $ assume i hi,\n  neq_bot_of_le_neq_bot hi $ inter_subset_inter (hf i) $ subset.refl _⟩\n\nlemma is_closed_Union_of_locally_finite {f : β → set α}\n  (h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) :=\nis_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i),\n  have ∀i, a ∈ -f i,\n    from assume i hi, h $ mem_Union.2 ⟨i, hi⟩,\n  have ∀i, - f i ∈ (nhds a).sets,\n    by rw [nhds_sets]; exact assume i, ⟨- f i, subset.refl _, h₂ i, this i⟩,\n  let ⟨t, h_sets, (h_fin : finite {i | f i ∩ t ≠ ∅ })⟩ := h₁ a in\n\n  calc nhds a ≤ principal (t ∩ (⋂ i∈{i | f i ∩ t ≠ ∅ }, - f i)) :\n  begin\n    rw [le_principal_iff],\n    apply @filter.inter_mem_sets _ (nhds a) _ _ h_sets,\n    apply @filter.Inter_mem_sets _ (nhds a) _ _ _ h_fin,\n    exact assume i h, this i\n  end\n  ... ≤ principal (- ⋃i, f i) :\n  begin\n    simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq,\n      mem_Inter, mem_set_of_eq, mem_Union, and_imp, not_exists,\n      not_eq_empty_iff_exists, exists_imp_distrib, (≠)],\n    exact assume x xt ht i xfi, ht i x xfi xt xfi\n  end\n\nend locally_finite\n\nend topological_space\n\nsection continuous\nvariables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}\nvariables [topological_space α] [topological_space β] [topological_space γ]\n\n/-- A function between topological spaces is continuous if the preimage\n  of every open set is open. -/\ndef continuous (f : α → β) := ∀s, is_open s → is_open (f ⁻¹' s)\n\ndef continuous_at (f : α → β) (x : α) := tendsto f (nhds x) (nhds (f x))\n\ndef continuous_at_within (f : α → β) (x : α) (s : set α) : Prop :=\ntendsto f (nhds_within x s) (nhds (f x))\n\ndef continuous_on (f : α → β) (s : set α) : Prop := ∀ x ∈ s, continuous_at_within f x s\n\nlemma continuous_id : continuous (id : α → α) :=\nassume s h, h\n\nlemma continuous.comp {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g):\n  continuous (g ∘ f) :=\nassume s h, hf _ (hg s h)\n\nlemma continuous.tendsto {f : α → β} (hf : continuous f) (x) :\n  tendsto f (nhds x) (nhds (f x)) | s :=\nshow s ∈ nhds (f x) → s ∈ map f (nhds x),\nby simp [nhds_sets]; exact\nassume t t_subset t_open fx_in_t,\n  ⟨f ⁻¹' t, preimage_mono t_subset, hf t t_open, fx_in_t⟩\n\nlemma continuous_iff_continuous_at {f : α → β} : continuous f ↔ ∀ x, continuous_at f x :=\n⟨continuous.tendsto,\n  assume hf : ∀x, tendsto f (nhds x) (nhds (f x)),\n  assume s, assume hs : is_open s,\n  have ∀a, f a ∈ s → s ∈ nhds (f a),\n    by simp [nhds_sets]; exact assume a ha, ⟨s, subset.refl s, hs, ha⟩,\n  show is_open (f ⁻¹' s),\n    by simp [is_open_iff_nhds]; exact assume a ha, hf a (this a ha)⟩\n\nlemma continuous_const {b : β} : continuous (λa:α, b) :=\ncontinuous_iff_continuous_at.mpr $ assume a, tendsto_const_nhds\n\nlemma continuous_iff_is_closed {f : α → β} :\n  continuous f ↔ (∀s, is_closed s → is_closed (f ⁻¹' s)) :=\n⟨assume hf s hs, hf (-s) hs,\n  assume hf s, by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩\n\nlemma continuous_at_iff_ultrafilter {f : α → β} (x) : continuous_at f x ↔\n  ∀ g, is_ultrafilter g → g ≤ nhds x → g.map f ≤ nhds (f x) :=\ntendsto_iff_ultrafilter f (nhds x) (nhds (f x))\n\nlemma continuous_iff_ultrafilter {f : α → β} :\n  continuous f ↔ ∀ x g, is_ultrafilter g → g ≤ nhds x → g.map f ≤ nhds (f x) :=\nby simp only [continuous_iff_continuous_at, continuous_at_iff_ultrafilter]\n\nlemma continuous_if {p : α → Prop} {f g : α → β} {h : ∀a, decidable (p a)}\n  (hp : ∀a∈frontier {a | p a}, f a = g a) (hf : continuous f) (hg : continuous g) :\n  continuous (λa, @ite (p a) (h a) β (f a) (g a)) :=\ncontinuous_iff_is_closed.mpr $\nassume s hs,\nhave (λa, ite (p a) (f a) (g a)) ⁻¹' s =\n    (closure {a | p a} ∩  f ⁻¹' s) ∪ (closure {a | ¬ p a} ∩ g ⁻¹' s),\n  from set.ext $ assume a,\n  classical.by_cases\n    (assume : a ∈ frontier {a | p a},\n      have hac : a ∈ closure {a | p a}, from this.left,\n      have hai : a ∈ closure {a | ¬ p a},\n        from have a ∈ - interior {a | p a}, from this.right, by rwa [←closure_compl] at this,\n      by by_cases p a; simp [h, hp a this, hac, hai, iff_def] {contextual := tt})\n    (assume hf : a ∈ - frontier {a | p a},\n      classical.by_cases\n        (assume : p a,\n          have hc : a ∈ closure {a | p a}, from subset_closure this,\n          have hnc : a ∉ closure {a | ¬ p a},\n            by show a ∉ closure (- {a | p a}); rw [closure_compl]; simpa [frontier, hc] using hf,\n          by simp [this, hc, hnc])\n        (assume : ¬ p a,\n          have hc : a ∈ closure {a | ¬ p a}, from subset_closure this,\n          have hnc : a ∉ closure {a | p a},\n            begin\n              have hc : a ∈ closure (- {a | p a}), from hc,\n              simp [closure_compl] at hc,\n              simpa [frontier, hc] using hf\n            end,\n          by simp [this, hc, hnc])),\nby rw [this]; exact is_closed_union\n  (is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hf s hs)\n  (is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hg s hs)\n\n\n/- Continuity and partial functions -/\n\ndef pcontinuous (f : α →. β) := ∀ s, is_open s → is_open (f.preimage s)\n\nlemma open_dom_of_pcontinuous {f : α →. β} (h : pcontinuous f) : is_open f.dom :=\nby rw [←pfun.preimage_univ]; exact h _ is_open_univ\n\nlemma pcontinuous_iff' {f : α →. β} :\n  pcontinuous f ↔ ∀ {x y} (h : y ∈ f x), ptendsto' f (nhds x) (nhds y) :=\nbegin\n  split,\n  { intros h x y h',\n    rw [ptendsto'_def],\n    change ∀ (s : set β), s ∈ (nhds y).sets → pfun.preimage f s ∈ (nhds x).sets,\n    rw [nhds_sets, nhds_sets],\n    rintros s ⟨t, tsubs, opent, yt⟩,\n    exact ⟨f.preimage t, pfun.preimage_mono _ tsubs, h _ opent, ⟨y, yt, h'⟩⟩\n  },\n  intros hf s os,\n  rw is_open_iff_nhds,\n  rintros x ⟨y, ys, fxy⟩ t,\n  rw [mem_principal_sets],\n  assume h : f.preimage s ⊆ t,\n  change t ∈ nhds x,\n  apply mem_sets_of_superset _ h,\n  have h' : ∀ s ∈ nhds y, f.preimage s ∈ nhds x,\n  { intros s hs,\n     have : ptendsto' f (nhds x) (nhds y) := hf fxy,\n     rw ptendsto'_def at this,\n     exact this s hs },\n  show f.preimage s ∈ nhds x,\n  apply h', rw mem_nhds_sets_iff, exact ⟨s, set.subset.refl _, os, ys⟩\nend\n\n\nlemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) :\n  f '' closure s ⊆ closure (f '' s) :=\nhave ∀ (a : α), nhds a ⊓ principal s ≠ ⊥ → nhds (f a) ⊓ principal (f '' s) ≠ ⊥,\n  from assume a ha,\n  have h₁ : ¬ map f (nhds a ⊓ principal s) = ⊥,\n    by rwa[map_eq_bot_iff],\n  have h₂ : map f (nhds a ⊓ principal s) ≤ nhds (f a) ⊓ principal (f '' s),\n    from le_inf\n      (le_trans (map_mono inf_le_left) $ by rw [continuous_iff_continuous_at] at h; exact h a)\n      (le_trans (map_mono inf_le_right) $ by simp; exact subset.refl _),\n  neq_bot_of_le_neq_bot h₁ h₂,\nby simp [image_subset_iff, closure_eq_nhds]; assumption\n\nlemma mem_closure [topological_space α] [topological_space β]\n  {s : set α} {t : set β} {f : α → β} {a : α}\n  (hf : continuous f) (ha : a ∈ closure s) (ht : ∀a∈s, f a ∈ t) : f a ∈ closure t :=\nsubset.trans (image_closure_subset_closure_image hf) (closure_mono $ image_subset_iff.2 ht) $\n  (mem_image_of_mem f ha)\nend continuous\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7561471437914765}}
{"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.submonoid.center\n! leanprover-community/mathlib commit 6cb77a8eaff0ddd100e87b1591c6d3ad319514ff\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathlib.GroupTheory.Submonoid.Operations\nimport Mathlib.GroupTheory.Subsemigroup.Center\n\n/-!\n# Centers of monoids\n\n## Main definitions\n\n* `Submonoid.center`: the center of a monoid\n* `AddSubmonoid.center`: the center of an additive monoid\n\nWe provide `Subgroup.center`, `AddSubgroup.center`, `Subsemiring.center`, and `Subring.center` in\nother files.\n-/\n\n\nnamespace Submonoid\n\nsection\n\nvariable (M : Type _) [Monoid M]\n\n/-- The center of a monoid `M` is the set of elements that commute with everything in `M` -/\n@[to_additive\n      \"The center of a monoid `M` is the set of elements that commute with everything in `M`\"]\ndef center : Submonoid M where\n  carrier := Set.center M\n  one_mem' := Set.one_mem_center M\n  mul_mem' := Set.mul_mem_center\n#align submonoid.center Submonoid.center\n#align add_submonoid.center AddSubmonoid.center\n\n@[to_additive]\ntheorem coe_center : ↑(center M) = Set.center M :=\n  rfl\n#align submonoid.coe_center Submonoid.coe_center\n#align add_submonoid.coe_center AddSubmonoid.coe_center\n\n@[to_additive (attr := simp) AddSubmonoid.center_toAddSubsemigroup]\n\n\nvariable {M}\n\n@[to_additive]\ntheorem mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g :=\n  Iff.rfl\n#align submonoid.mem_center_iff Submonoid.mem_center_iff\n#align add_submonoid.mem_center_iff AddSubmonoid.mem_center_iff\n\n@[to_additive]\ninstance decidableMemCenter (a) [Decidable <| ∀ b : M, b * a = a * b] : Decidable (a ∈ center M) :=\n  decidable_of_iff' _ mem_center_iff\n#align submonoid.decidable_mem_center Submonoid.decidableMemCenter\n#align add_submonoid.decidable_mem_center AddSubmonoid.decidableMemCenter\n\n/-- The center of a monoid is commutative. -/\ninstance center.commMonoid : CommMonoid (center M) :=\n  { (center M).toMonoid with\n    mul_comm := fun _ b => Subtype.ext <| b.prop _ }\n\n/-- The center of a monoid acts commutatively on that monoid. -/\ninstance center.smulCommClass_left : SMulCommClass (center M) M M\n    where smul_comm m x y := (Commute.left_comm (m.prop x) y).symm\n#align submonoid.center.smul_comm_class_left Submonoid.center.smulCommClass_left\n\n/-- The center of a monoid acts commutatively on that monoid. -/\ninstance center.smulCommClass_right : SMulCommClass M (center M) M :=\n  SMulCommClass.symm _ _ _\n#align submonoid.center.smul_comm_class_right Submonoid.center.smulCommClass_right\n\n/-! Note that `smulCommClass (center M) (center M) M` is already implied by\n`Submonoid.smulCommClass_right` -/\n\nexample : SMulCommClass (center M) (center M) M := by infer_instance\n\nend\n\nsection\n\nvariable (M : Type _) [CommMonoid M]\n\n@[simp]\ntheorem center_eq_top : center M = ⊤ :=\n  SetLike.coe_injective (Set.center_eq_univ M)\n#align submonoid.center_eq_top Submonoid.center_eq_top\n\nend\n\nend Submonoid\n\n-- Porting note: `assert_not_exists` is not ported 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/Center.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.7561471401543558}}
{"text": "import tactic\nimport data.real.basic\nimport data.set\n\n------------\n-- ESSAIS --\n------------\nopen set\n\n-----------\n-- DEBUT --\n-----------\n\n/-- Une structure d'espace métrique sur un type X -/\nclass espace_metrique (X : Type) :=\n(dist : X → X → ℝ)\n(dist_pos : ∀ x y, dist x y ≥ 0)\n(sep : ∀ x y, dist x y = 0 ↔ x = y)\n(sym : ∀ x y, dist x y = dist y x)\n(triangle : ∀ x y z, dist x z ≤ dist x y + dist y z)\n\n\nopen espace_metrique\n\n/-- Fonction distance avec le type en argument explicite -/\ndef dist' (X : Type) [espace_metrique X] : X → X → ℝ := λ x y, dist x y\n\nnotation `d` := dist\nnotation `d_[` X `]` := dist' X\n\n\n----------------------------------------------------\nsection fondements\n----------------------------------------------------\n\nvariables {X : Type} [espace_metrique X]\n\n@[simp]\nlemma dist_sym (x:X) (y:X) : d x y = d y x := sym x y\n\n@[simp]\nlemma dist_x_x_eq_zero  (x:X) : d x x = 0 := \n (sep x x).2 rfl \n\nlemma dist_str_pos  {x:X} {y:X} : x ≠ y → d x y > 0 := \nbegin\ncontrapose!,\nintro d_neg,\nhave d_pos : d x y ≥ 0, from dist_pos x y,\nhave d_zero : d x y = 0, from antisymm d_neg d_pos,\nexact iff.mp (sep x y) d_zero\nend\n\n\n/-- `boule x r` est la boule ouverte de centre `x` et de rayon `r` -/\ndef boule (x : X) (r : ℝ)  := {y | dist x y < r}\n\n/-- appartenir à une boule équivaut à une inégalité -/\n@[simp]\nlemma mem_boule (x : X) (r : ℝ) (y : X) : y ∈ boule x r ↔ dist x y < r := \niff.rfl\n\n/-- Une boule de rayon >0 contient son centre --/\nlemma centre_mem_boule (x : X) (r : ℝ) : r > 0 → x ∈ boule x r :=\nbegin\nintro r_pos,\nsimpa [boule] -- simplifie et utilise l'hypothèse\nend\n\n\n/-- Une partie d'un espace métrique `X` est ouverte si elle contient une boule ouverte de rayon \nstrictement positif autour de chacun de ses points. -/\ndef ouvert (A : set X) := ∀ x ∈ A, ∃ r > 0, boule x r ⊆ A\n\n/-- Les boules sont ouvertes -/\nlemma boule_est_ouverte : ∀ x : X, ∀ r > 0, ouvert (boule x r) :=\nbegin\n  intros x r r_pos y y_in, -- on déroule les définitions,\n  -- on se retrouve avec un point y dans la boule\n  -- de centre x et de rayon r, et on cherche une boule autour de y qui soit incluse\n  -- dans boule x r\n  set ε := r - d x y with hε,\n  use  ε, -- le rayon candidat\n  -- OBSOLETE rw exists_prop,\n  split,\n  { -- La ligne suivante peut être remplacée par n'importe laquelle des trois lignes qui la suivent\n    simp [boule] at y_in,\n    --change d x y < r at y_in,\n    --rw mem_boule at y_in,\n    --unfold boule at y_in, rw set.mem_set_of_eq at y_in,\n    linarith only [hε, y_in]}, -- le rayon est bien strictement positif\n  { -- La ligne suivante est optionnelle, elle sert  à expliciter le but\n    -- change ∀ z, z ∈ boule y (r - d x y) → z ∈ boule x r,\n    intros z z_in,\n    rw mem_boule at *,\n    have clef : d x z ≤ d x y + d y z, from triangle x y z,\n    linarith only [clef, z_in, y_in, hε]} -- et l'inégalité triangulaire permet de montrer l'inclusion des boules\nend\n\n\n-- Lemme de théorie des ensembles - finalement non utilisé\nlemma inclusion_transitive {Y : Type} {A B C : set Y} : A ⊆ B → B ⊆ C → A ⊆ C :=\nbegin\n  intros AB BC a a_app_A,\n  exact BC (AB a_app_A),  \nend\n\n/-- Une union d'ouverts d'un espace métrique est un ouvert -/\nlemma union_ouverts_est_ouvert (I : set (set X)) : (∀ O ∈ I, ouvert O) → ouvert (⋃₀ I) :=\nbegin\n  -- Supposons que tous les O dans I sont ouverts.\n  intro O_ouverts,\n  -- Soit x un point d'un des O dans I\n  rintro x ⟨O, O_app_I, x_app_O⟩,\n  -- Comme O est ouvert, il existe r > 0 tel que B(x, r) ⊆ O\n  obtain ⟨r, r_positif, boule_dans_O⟩ : ∃ r > 0, boule x r ⊆ O,\n    from (O_ouverts O) O_app_I x x_app_O,\n  -- Montrons que ce r convient \n  use [r, r_positif],\n  -- Puisque  B(x, r) ⊆ O, il suffit de montrer que O ⊆ ⋃₀ I\n  transitivity O, assumption,\n  -- Or O est dans I.\n  exact subset_sUnion_of_mem O_app_I\nend\n\n-- ** variante en λ-calcul - non utilisé\nlemma union_ouverts_est_ouvert' (I : set (set X)) : (∀ O ∈ I, ouvert O) → ouvert (⋃₀ I) :=\nassume O_ouverts x ⟨O, O_app_I, x_app_O⟩,\nlet ⟨r, r_positif, boule_dans_O⟩ := O_ouverts O O_app_I x x_app_O in\n⟨r, r_positif, subset.trans boule_dans_O (subset_sUnion_of_mem O_app_I)⟩\n\n\n/-- L'intersection de deux ouverts est un ouvert -/\nlemma intersection_deux_ouverts_est_ouvert : ∀ O₁ O₂ : set X, ouvert O₁ →  ouvert O₂ → ouvert (O₁ ∩ O₂) :=\nbegin\n  -- Soit x un point dans l'intersection,\n  rintro O₁ O₂ ouvert_O₁ ouvert_O₂ x ⟨x_app_O₁,x_app_O₂⟩,\n  -- le fait que O₁ et O₂ soient ouverts fournis deux nombres positifs\n  obtain ⟨r₁,r₁_pos,boule_dans_O₁⟩ : ∃ r₁>0, boule x r₁ ⊆ O₁, from ouvert_O₁ x x_app_O₁,\n  obtain ⟨r₂,r₂_pos,boule_dans_O₂⟩ : ∃ r₂>0, boule x r₂ ⊆ O₂, from ouvert_O₂ x x_app_O₂,\n  -- Montrons que le minimum r des deux convient\n  use min r₁ r₂, \n  -- OBSOLETE rw exists_prop,\n  -- Il est bien positif\n  split, \n    by exact lt_min r₁_pos r₂_pos,\n  -- les quatre lignes qui précèdent peuvent être remplacées par :\n  -- use [min r₁ r₂,lt_min r₁_pos r₂_pos]\n\n  -- Prenons un y dans la boule de rayon r\n  intros y y_app_boule, \n  -- vu le choix de r, on a d x y < r₁ et d x y < r₂\n  simp [boule] at y_app_boule,\n  -- donc c'est bon\n  split  ; tautology\n  -- FIN plus compliquée : \n  -- simp [boule] at y_app_boule,\n  -- rcases y_app_boule with ⟨ineg_1,ineg_2⟩,\n  -- -- il est dans O₁ et dans O₂ \n  -- have y_O₁ : y ∈ O₁, from boule_dans_O₁ ineg_1,\n  -- have y_O₂ : y ∈ O₂, from boule_dans_O₂ ineg_2,\n  -- -- donc dans l'intersection, comme voulu.\n  -- exact and.intro y_O₁ y_O₂,\nend\n\n\n/-- L'espace total est ouvert -/\nlemma total_ouvert : ouvert (univ : set X) :=\nbegin\n  intros x hx,  \n  use 1,\n  -- OBSOLETE rw exists_prop,\n  split,\n    exact zero_lt_one,\n    exact subset_univ (boule x 1),\nend\n\n/-- L'intersection d'un nombre fini d'ouverts est un ouvert -/\n--lemma intersection_ouverts_est_ouvert'  \n--(I : set (set X)) : (finite I) (∀ O ∈ I, ouvert O) → ouvert (⋂₀ I) :=\n--begin\n  --tactic.unfreeze_local_instances,\n  --rcases _inst_2 with ⟨Liste, Liste_exhaustive⟩,\n  --sorry\n--end\n\n--{s : set β} {f : β → set α} (hs : finite s) :\n--variables (β : Type) \n--lemma intersection_ouverts_est_ouvert  {s: set β} {O : β → set X} (hs: finite s) :\n--  (∀ i, ouvert (O i)) → ouvert (⋂ i, O i) :=\n--begin\n--  set.finite.induction_on hs (sorry) (sorry)\n  -- (λ _, by rw bInter_empty; exact total_ouvert)\n  -- (λ a s has hs ih h, by rw bInter_insert; exact\n    -- is_open_inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))\n--end\n\n\n--lemma is_open_sInter {s : set (set X)} (hs : finite s) : (∀t ∈ s, ouvert t) → ouvert (⋂₀ s) :=\n\n\n\n\nlemma vide_ouvert : ouvert (∅ : set X) :=\nbegin\n  intros x x_in,\n  exfalso,\n  exact x_in,\nend\n\nlemma vide_ouvert' : ouvert (∅ : set X) :=\nassume x x_in, false.elim x_in\n\n\n/-- L'intérieur d'une partie de X est la réunion des ouverts qu'elle contient -/\ndef Int (E : set X) := ⋃₀ {O : set X | ouvert O ∧ O ⊆ E}\n\n/-- Caractérisation métrique de l'intérieur -/\n@[simp]\nlemma interieur_metrique {E : set X} {x : X} : x ∈ Int E ↔  ∃ r>0, boule x r ⊆ E  :=\nbegin\nsplit,\n  -- Pour le sens direct, supposons que x est dans l'intérieur de E\n  intro x_dans_Int, \n    -- Par définition de l'intérieur, il existe un ouvert O inclus dans E et contenant x\n  rcases x_dans_Int with ⟨O, ⟨ouvert_O,O_sub_E⟩ , x_app_O⟩,\n  -- L'ouvert O contient une boule autour de x\n  obtain ⟨r,r_pos,boule_dans_O⟩ : ∃ r>0, boule x r ⊆ O, from ouvert_O x x_app_O,\n  -- Cette boule convient \n  use [r, r_pos],\n  -- puisqu'elle est incluse dans O qui est inclus dans E\n  transitivity O, assumption, assumption,\n  -- VARIANTE : exact subset.trans boule_dans_O O_sub_E, -- On peut aussi écrire : tauto,\n  -- Pour l'autre sens, soit x le centre d'une boule incluse dans E.\nrintros ⟨ r,r_pos, boule_dans_E⟩,\n  -- Cette boule est un ouvert\n  have ouvert_boule, from boule_est_ouverte x r r_pos,\n  -- et elle contient x\n  have x_mem_boule, from centre_mem_boule x r r_pos,\n  -- donc x est dans l'intérieur de E\n  use boule x r,\n  repeat { split }, assumption, assumption, assumption,\n  -- VARIANTE FIN PLUS COMPLIQUEE : -- la boule est donc incluse dans l'intérieur de E\n  -- let I := {O : set X | ouvert O ∧ O ⊆ E},\n  -- have boule_mem_I : (boule x r) ∈ I,\n  --   exact and.intro ouvert_boule boule_dans_E,\n  -- have boule_inc_Int : boule x r ⊆ Int E, from subset_sUnion_of_mem boule_mem_I,\n  -- -- qui contient donc x, centre d'une boule incluse dans Int E\n  -- exact boule_inc_Int (centre_mem_boule x r r_pos),\nend\n\n-- Variante moins pratique (?)\nlemma interieur_metrique' {E : set X} : Int E = { x : X | ∃ r>0, boule x r ⊆ E } :=\nbegin\n  -- Nous raisonnons par double inclusion\n  apply subset.antisymm,\n  -- Soit x dans l'intérieur de E\n  intros x x_dans_Int, simp,\n  -- Par définition de l'intérieur, il existe un ouvert O inclus dans E et contenant x\n  rcases x_dans_Int with ⟨O, ⟨ouvert_O,O_sub_E⟩ , x_app_O⟩,\n  -- L'ouvert O contient une boule autour de x\n  obtain ⟨r,r_pos,boule_dans_O⟩ : ∃ r>0, boule x r ⊆ O, from ouvert_O x x_app_O,\n  -- Cette boule convient \n  use [r, r_pos],\n  -- puisqu'elle est incluse dans O qui est inclus dans E\n  transitivity O, assumption, assumption,\n  -- VARIANTE : exact subset.trans boule_dans_O O_sub_E, -- On peut aussi écrire : tauto,\n  -- Pour l'autre sens, soit x le centre d'une boule incluse dans E.\n  rintros x ⟨ r,r_pos, boule_dans_E⟩,\n  -- Cette boule est un ouvert\n  have ouvert_boule, from boule_est_ouverte x r r_pos,\n  -- et elle contient x\n  have x_mem_boule, from centre_mem_boule x r r_pos,\n  -- donc x est dans l'intérieur de E\n  use boule x r,\n  repeat { split }, assumption, assumption, assumption,\n  -- VARIANTE FIN PLUS COMPLIQUEE : -- la boule est donc incluse dans l'intérieur de E\n  -- let I := {O : set X | ouvert O ∧ O ⊆ E},\n  -- have boule_mem_I : (boule x r) ∈ I,\n  --   exact and.intro ouvert_boule boule_dans_E,\n  -- have boule_inc_Int : boule x r ⊆ Int E, from subset_sUnion_of_mem boule_mem_I,\n  -- -- qui contient donc x, centre d'une boule incluse dans Int E\n  -- exact boule_inc_Int (centre_mem_boule x r r_pos),\nend\n\n\n\ndef est_voisinage (V : set X) (x : X) := x ∈ Int V\n\n-- caractérisation d'un voisinage en termes d'ouverts ?\n-- caractérisation en terme de boules ?\n\n\nend fondements\n\n\n\n----------------------------------------------------\nsection continuite\n----------------------------------------------------\nvariables {X Y : Type} [espace_metrique X] [espace_metrique Y]\n\n-- dans la définition suivante les `d_[X]` et `d_[Y]` sont cosmétiques, `d` seul marche aussi bien\n\ndef continue_en (f : X → Y) (x₀ : X) :=\n  ∀ ε > 0, ∃ δ > 0, ∀ x, d_[X] x₀ x < δ → d_[Y] (f x₀) (f x) < ε   \n\ndef continue (f:X → Y) := \n∀ x : X, continue_en f x\n\n-- Notations f continue, f continue_au_point x\n\n-- caractérisation topologique (ponctuelle, globale)\nlemma continuite_ouverts (f:X → Y): continue f ↔ ( ∀O, ouvert O → ouvert (f ⁻¹' O) ) :=\nbegin\n  -- On raisonne par double implication\n  split,\n  { -- Supposons donc que f vérifie la définition métrique de la continuité\n    -- Soit O un ouvert à l'arrivé, il s'agit de voir que son image réciproque est ouverte\n    --  SOit x un point de l'image réciproque, on cherche un rayon\n    intros cont O O_ouvert x x_dans_reciproque,\n    -- c'est-à-dire tel que f(x) ∈ O\n    change f x ∈ O at x_dans_reciproque, -- Cette ligne est purement psychologique, on peut la retirer\n    -- Puisque O est ouvert, il contient une boule de rayon ε autour de f(x)\n    obtain ⟨ε, ε_positif, boule_dans_O⟩ : ∃ ε > 0, boule (f x) ε ⊆ O,\n    from O_ouvert (f x) x_dans_reciproque,\n    -- L'hypothèse de continuité fournit un δ >0\n    rcases (cont x) ε ε_positif with ⟨δ , δ_positif, H⟩,\n    -- Montrons que la boule de rayon δ est dans l'image réciproque\n    use [δ, δ_positif],\n    -- pour ceci on prend un point x' dans la boule\n    intros x' hx',\n    -- il s'agit de voir que son image est dans O\n    change f x' ∈ O, -- encore une ligne purement psychologique, Lean n'en a pas besoin\n    -- Pour cela il suffit de voir que f(x') est dans la boule de centre f(x) et de rayon ε, \n    -- puisqu'elle est incluse dans O\n    suffices hh : f x' ∈ boule (f x) ε, from boule_dans_O hh,\n    -- ce qui est donné par la propriété de δ issue de la continuité\n    exact H x' hx'\n     },\n  { -- Pour l'autre direction, on suppose que l'image réciproque de tout ouvert est un ouvert,\n    -- on prend un point x et un ε > 0\n    rintros H x ε ε_positif,\n    -- La boule de centre x et de rayon epsilon est un ouvert de Y,\n    have boule_ouverte, from boule_est_ouverte (f x) ε ε_positif,\n    -- donc par hypothèse son image réciproque est un ouvert de X\n    have reciproque_ouvert, from H (boule (f x) ε) boule_ouverte,\n      -- or x appartient à cette image réciproque\n    have x_dans_reciproque: x ∈ f ⁻¹' boule (f x) ε,\n      simpa [boule],\n    -- Il existe donc une boule autour de x incluse dans l'image réciproque de la première boule\n    obtain ⟨δ, δ_positif, H⟩: ∃ δ >0, boule x δ ⊆ f ⁻¹' boule (f x) ε ,  from reciproque_ouvert x x_dans_reciproque,\n    -- montrons que le rayon de cette boule satisfait la définition métrique de la continuité\n    use [δ , δ_positif],\n    -- On considère donc un point x' tel que d(x,x') < δ\n    intros x' hx',\n    -- Autrement dit, x' est dans la boule B(x,δ),\n    change x' ∈ boule x δ at hx', -- encore une ligne pour rien    \n    -- donc son image est dans la première boule\n    exact H hx' }\nend\n\nvariables {Z : Type} [espace_metrique Z]\n\n/-- La composée de deux applications continues est continue-/\nlemma composition_continue (f : X → Y) (g : Y → Z) : (continue f) →  (continue g) →  continue (g ∘ f) :=\nbegin\n-- Supposons que f et g sont continues\nintros f_cont g_cont, \n-- Nous allons utiliser la caractérisation topologique pour montrer la continuité de g ∘ f :\nrw continuite_ouverts,\n-- On considère un ouvert O de Z\nintros O O_ouvert,\n-- La caractérisation topologique de la continuité de g nous dit que g ⁻¹' O est un ouvert de Y,\nhave ouvert1 : ouvert (g ⁻¹' O), \n  from (((iff.elim_left (continuite_ouverts g)) g_cont) O) O_ouvert,\n-- La caractérisation topologique de la continuité de f nous dit que f ⁻¹' (g ⁻¹' O) est un ouvert de X,\nexact (((iff.elim_left (continuite_ouverts f)) f_cont) (g ⁻¹' O)) ouvert1,\n-- et il est égal à (g ∘ f)  ⁻¹' O, CQFD\nend\n\n-- A FAIRE : caractérisation topologique de la continuité ponctuelle par les voisinages, \n-- et composition ponctuelle\n\ndef lipschitzienne (k:ℝ) (f: X → Y) := \n∀ x₀  x₁ , d_[Y] (f x₀) (f x₁) ≤ ( k * d_[X] x₀  x₁ )\n\n-- A FAIRE : lipschitzien implique continu\n\nend continuite\n\n\n----------------------------------------------------\nsection fermes\n----------------------------------------------------\nvariables {X:Type} [espace_metrique X]\n\ndef ferme (F : set X) := ouvert (- F) \n\n-- A FAIRE : intersection, union\n\n/-- L'adhérence d'une partie de X est l'intersection des fermés qui la contienne -/\ndef Adh (E : set X) := sInter {F : set X | ferme F ∧ E ⊆ F}\n\n\n\n-- adhérence et intérieur par passage au complémentaire\n\n/-- Caractérisation métrique de l'adhérence -/\n\n@[simp]\nlemma adherence_metrique {E : set X} {x : X} : x ∈ Adh E  ↔ ∀ r>0, boule x r ∩ E ≠ ∅ :=\nbegin\n  sorry\nend\n\n\n\nend fermes\n\n\n----------------------------------------------------\nsection suites\n----------------------------------------------------\nvariables {X:Type} [espace_metrique X]\n-- variable E : set X\n-- variable x : E \n-- #print x\n\ndef limite_suite (x: ℕ → X) (l : X) := ∀ ε > 0, ∃ N, ∀ n ≥ N, ((d l (x n))  < ε)\n\n\n\n-- On va voir besoin de \"0<2\" dans ℝ \nlemma zero_pp_2 :  (0:real) < 2 := \nbegin\nlinarith only [zero_lt_one]\nend\n\n#print zero_pp_2 -- Waou !\n\nopen classical\nlocal attribute [instance] prop_decidable\nlemma unicite_limite {x: ℕ → X} {l₁ : X} {l₂ : X} : \n  (limite_suite x l₁) → (limite_suite x l₂) → l₁ = l₂ :=\nbegin\n-- Supposons que la suite (x_n) converge à la fois vers l₁ et l₂ \nintros H₁ H₂,\n-- Raisonnons par l'absurde, en supposant l₁ ≠ l₂ \nby_contradiction lim_non_eg,\n-- Alors d(l₁, l₂) >0\nhave dist_limites_pos : 0 < d l₁ l₂, from dist_str_pos lim_non_eg,\n-- Appelons ε la moitié de cette distance, qui est donc aussi un nombre positif\nlet ε := (d l₁ l₂)/2,\nhave ε_pos : 0 < ε, from  div_pos dist_limites_pos zero_pp_2,\n-- et appliquons la définition de convergence à nos deux limites\nrcases H₁ ε ε_pos with ⟨ N₁ , HN₁ ⟩,\nrcases H₂ ε ε_pos with ⟨ N₂ , HN₂ ⟩,\n-- On obtient deux rangs N₁, N₂, dont on prend le maximum\nlet N := max N₁ N₂,\n-- La définition de convergence nous donne les deux inégalités d(l₁,x_N )< ε et  d(l₂,x_N) < ε\nhave I₁ : d l₁ (x N) < ε, from  HN₁ N (le_max_left N₁ N₂),\nhave I₂ : d l₂ (x N) < ε, from  HN₂ N (le_max_right N₁ N₂),\n-- En les combinant à l'inégalité triangulaire entre les trois points impliqué, \n-- on obtient d(l₁,l₂) <  d(l₁,l₂), \nhave egal : d l₁ l₂  = 2 * ε , from eq.symm (@mul_div_cancel' ℝ real.field (d l₁ l₂) 2 two_ne_zero),\nhave Ineg : d l₁ l₂ < d l₁ l₂, from\ncalc \n   d l₁ l₂ ≤ d l₁ (x N) + d (x N) l₂  : (triangle l₁ (x N) l₂)\n    ...    ≤ d l₁ (x N) + d l₂ (x N)  : by simp\n    -- Linarith se débrouille sans les 3 lignes suivante :\n    -- ...    < ε + ε                    : by linarith\n    -- ...    = 2 * ε                    : eq.symm (two_mul ε)\n    -- ...    = d l₁ l₂                  : by rw egal, \n      ...   < d l₁ l₂                  : by linarith,\n-- ce qui donne la contradiction recherchée.\nlinarith only [Ineg]\nend\n\n-- nom des lemmes trouvés avec la tactique library_search\nexample (ε : ℝ) : 2*ε = ε + ε := two_mul ε \nexample (a : ℝ) (b : ℝ) (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a/b := div_pos h₁ h₂\nexample (a : ℝ) (b : ℝ) (H : a ≠ 0) : a * (b/a) = b := mul_div_cancel' b H\nexample (a : ℝ) (b : ℝ) (h₁ : a = b) : b = a := eq.symm h₁\nexample (a : ℝ) (h₁ : a < a) : false := by linarith\nexample : @has_lt.lt real real.has_lt 0 1 := zero_lt_one\n\n-- Variante utilisant le lemme suivant :\nlemma pp_que_tout_pos (l : real) : (∀ ε>0, l ≤ ε)  → l ≤ 0 :=\nbegin\n  contrapose!,\n  intro H,\n  use l/2,\n  split,\n  linarith,\n  linarith\nend\n\nlemma unicite_limite' {x: ℕ → X} {l₁ : X} {l₂ : X} : \n  (limite_suite x l₁) → (limite_suite x l₂) → l₁ = l₂ :=\nbegin\n  intros H1 H2,\n  have H : (∀ ε>0, d l₁ l₂ ≤ ε),\n      intros ε ε_pos,\n      have εs2_pos : ε/2>0, by linarith,\n      have H1', from H1 _ εs2_pos,\n      cases H1' with N₁ PN₁ ,\n      have H2', from H2 _ εs2_pos,\n      cases H2' with N₂ PN₂,\n      have HN₁  : max N₁ N₂ ≥ N₁ , by exact le_max_left N₁ N₂, -- library_search\n      have HN₂  : max N₁ N₂ ≥ N₂ , by exact le_max_right N₁ N₂, -- library_search\n      specialize PN₁  _ HN₁ ,\n      specialize PN₂  _ HN₂ ,\n      have T, from triangle l₁ (x (max N₁ N₂)) l₂,\n      have Dsym, from sym l₂ (x (max N₁ N₂)),\n      exact calc \n        d l₁ l₂ ≤ d l₁ (x (max N₁ N₂)) + d (x (max N₁ N₂)) l₂ : T\n          ...   ≤ ε : by linarith,\n  have D , from  pp_que_tout_pos (d l₁ l₂) H,   -- : (d l₁ l₂) ≤ 0\n  have D' , from dist_pos l₁ l₂,\n  have D'' , by exact le_antisymm D D', -- d l₁ l₂ =0\n  exact (sep l₁ l₂).1 D''\nend\n\n\nlemma nonvide_ssi_existe_element (A : set X) : A ≠ ∅ ↔ ∃ a : X, a ∈ A :=\nne_empty_iff_nonempty\n\nlemma essai (a : ℝ) (b : ℝ) (c : ℝ) (H1 : a > b) (H2 : b > c) : a > c := \nbegin \n  transitivity b, exact H1, exact H2,\nend\n\nlemma inv_inv2 {ε : ℝ} (ε_nz : ε ≠ 0) : ε = 1 / (1 / ε) :=\nbegin\n  have inv_ε_nz : (1/ε) ≠ 0, from one_div_ne_zero ε_nz,\n  have H : ε * (1/ε) = 1, from mul_div_cancel' 1 ε_nz,\n  exact (eq_div_iff_mul_eq ε 1 inv_ε_nz).2 H,\nend\n\n-- critère séquentiel d'adhérence (construire une suite)\nlemma critere_sequentiel_adherence (E : set X) (l : X) : \n          l ∈ Adh E ↔ ∃ x : ℕ → X, (∀ n, x n ∈ E) ∧ (limite_suite x l) :=\nbegin\nsplit,\n  -- Pour le sens direct, on prend l dans l'adhérence de E\n  -- et on cherche à construire une suite d'éléments de E qui converge vers l\n  intros Hl,\n    -- Comment éviter d'avoir à introduire cette grosse propriété intermédiaire ?\n  have H1 : ∀ n : ℕ, ∃ x : X, d l x < 1/(n+1) ∧ x ∈ E, \n    intro n,\n    -- have H2, from H 1/(n+1),\n    -- exact adherence_metrique.mpr l Hl,\n    sorry,\n  -- H1 permet de définir une suite (x_n) qui va convenir  \n  choose x H using H1,\n  use x,\n  split,\n    -- La suite est bien à valeur dans E,\n    exact λ n, ((H n).2),\n  -- Reste à montrer qu'elle converge vers l\n    intros ε ε_pos,\n    have HN, from exists_nat_gt (1 / ε),\n    cases HN with N HN,\n    use N, intros n Hn,\n    specialize H n,\n    cases H with Hutile Hinutile,\n    have Ineg : N < n+1, by linarith,\n    have Ineg2 : ↑n+(1:ℝ)  > ↑N, by exact_mod_cast Ineg,\n    have Ineg3 : ↑n+1 > 1/ε,\n      begin \n        transitivity ↑N,\n        exact Ineg2,\n        exact HN,\n      end,\n    have inv_ε_pos : (1/ε)>0, from one_div_pos_of_pos ε_pos,\n    have Ineg4, by exact one_div_lt_one_div_of_lt inv_ε_pos Ineg3,\n    transitivity 1 / (↑n + 1:ℝ),\n      exact Hutile,\n    have NZ : ε ≠ 0, by linarith,\n    -- have inv_inv_ε : ε = 1/(1/ε), by inv_inv2 NZ,\n    \n      \n\n    sorry,\n  -- Pour l'autre direction, on suppose l'existence d'une suite \n  -- d'éléments de E convergeant vers l\nrintro ⟨x,H1,H2⟩,\n-- On utilise la caractérisation métrique de l'adhérence\nrw adherence_metrique,\nrintro r Hr, \nrw limite_suite at H2,\nhave H, from (H2 r) Hr,\n-- obtain ⟨N, H3N⟩ : ℕ  ,(∀ (n : ℕ), n ≥ N → d l (x n) < r) , from (H2 r) Hr,\ncases H with N HN,\nhave HNN: N ≥ N, by linarith,\nspecialize HN N HNN,\nrw← mem_boule at HN,\nspecialize H1 N,\nrw ne_empty_iff_nonempty,\nuse x N,\nexact and.intro HN H1\nend\n\nexample  (a : ℝ) (b : ℝ) (a_pos : a>0) (a_inf_b : a <b) : 1/a > 1/b := \nbegin\n  exact one_div_lt_one_div_of_lt a_pos a_inf_b\nend\n \nexample (x : ℝ) (H : x ≠ 0) : x * (1/x) = 1 := mul_div_cancel' 1 H\nexample (x : ℝ) (y : ℝ) (H : x ≠ 0) : ( y = 1/x ) ↔ ( y * x = 1 ) := \n        eq_div_iff_mul_eq y 1 H\n\n\n\n-- critère séquentiel de fermeture\n\n\n-- critère séquentiel de continuité\n\n\n\n\n\nend suites\n\n\n----------------------------------------------------\nsection sous_espaces_metriques\n----------------------------------------------------\n\n\n----------------------------------------------------\nsection distances_equivalentes\n----------------------------------------------------\n\n\n\n----------------------------------------------------\nsection espaces_metriques_produits\n----------------------------------------------------\n\n----------------------------------------------------\nsection espaces_de_fonctions\n----------------------------------------------------\n", "meta": {"author": "FredericLeRoux", "repo": "LEAN_ESPACES_METRIQUES", "sha": "ebab6c37d88988a87b4310b0347db98c2245b902", "save_path": "github-repos/lean/FredericLeRoux-LEAN_ESPACES_METRIQUES", "path": "github-repos/lean/FredericLeRoux-LEAN_ESPACES_METRIQUES/LEAN_ESPACES_METRIQUES-ebab6c37d88988a87b4310b0347db98c2245b902/esp_metrique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7561471384725397}}
{"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.admissible_abs\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.Algebra.Algebra.Basic\nimport Mathlib.NumberTheory.ClassNumber.AdmissibleAbsoluteValue\n\n/-!\n# Admissible absolute value on the integers\nThis file defines an admissible absolute value `AbsoluteValue.absIsAdmissible`\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 * `AbsoluteValue.absIsAdmissible` shows the \"standard\" absolute value on `ℤ`,\n   mapping negative `x` to `-x`, is admissible.\n-/\n\n\nnamespace AbsoluteValue\n\nopen Int\n\n/-- We can partition a finite family into `partition_card ε` sets, such that the remainders\nin each set are close together. -/\ntheorem exists_partition_int (n : ℕ) {ε : ℝ} (hε : 0 < ε) {b : ℤ} (hb : b ≠ 0) (A : Fin n → ℤ) :\n    ∃ t : Fin n → Fin ⌈1 / ε⌉₊, ∀ i₀ i₁, t i₀ = t i₁ → ↑(abs (A i₁ % b - A i₀ % b)) < abs b • ε :=\n  by\n  have hb' : (0 : ℝ) < ↑(abs b) := Int.cast_pos.mpr (abs_pos.mpr hb)\n  have hbε : 0 < abs b • ε := by\n    rw [Algebra.smul_def]\n    exact mul_pos hb' hε\n  have hfloor : ∀ i, 0 ≤ floor ((A i % b : ℤ) / abs b • ε : ℝ) :=\n    fun _ ↦ floor_nonneg.mpr (div_nonneg (cast_nonneg.mpr (emod_nonneg _ hb)) hbε.le)\n  refine' ⟨fun i ↦ ⟨natAbs (floor ((A i % b : ℤ) / abs b • ε : ℝ)), _⟩, _⟩\n  · rw [← ofNat_lt, natAbs_of_nonneg (hfloor i), floor_lt]\n    apply lt_of_lt_of_le _ (Nat.le_ceil _)\n    rw [Algebra.smul_def, eq_intCast, ← div_div, div_lt_div_right hε, div_lt_iff hb', one_mul,\n      cast_lt]\n    exact Int.emod_lt _ hb\n  intro i₀ i₁ hi\n  have hi : (⌊↑(A i₀ % b) / abs b • ε⌋.natAbs : ℤ) = ⌊↑(A i₁ % b) / abs b • ε⌋.natAbs :=\n    congr_arg ((↑) : ℕ → ℤ) (Fin.mk_eq_mk.mp hi)\n  rw [natAbs_of_nonneg (hfloor i₀), natAbs_of_nonneg (hfloor i₁)] at hi\n  have hi := abs_sub_lt_one_of_floor_eq_floor hi\n  rw [abs_sub_comm, ← sub_div, abs_div, abs_of_nonneg hbε.le, div_lt_iff hbε, one_mul] at hi\n  rwa [Int.cast_abs, Int.cast_sub]\n#align absolute_value.exists_partition_int AbsoluteValue.exists_partition_int\n\n/-- `abs : ℤ → ℤ` is an admissible absolute value. -/\nnoncomputable def absIsAdmissible : IsAdmissible AbsoluteValue.abs :=\n  { AbsoluteValue.abs_isEuclidean with\n    card := fun ε ↦ ⌈1 / ε⌉₊\n    exists_partition' := fun n _ hε _ hb ↦ exists_partition_int n hε hb }\n#align absolute_value.abs_is_admissible AbsoluteValue.absIsAdmissible\n\nnoncomputable instance : Inhabited (IsAdmissible AbsoluteValue.abs) :=\n  ⟨absIsAdmissible⟩\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/NumberTheory/ClassNumber/AdmissibleAbs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7561200894785031}}
{"text": "import data.real.basic\n\ntheorem SW_15_induction (x:ℝ) (k:ℕ) (h0: 0 ≤ x) (h1: x ≤ 1):\n  1 - (k:ℝ) * x ≤ (1 - x)^k := nat.rec_on k ( -- Base for induction\n    calc 1 - ↑0 * x = 1 - 0*x: by rw nat.cast_zero\n                ... = 1 - 0: by rw zero_mul\n                ... = 1: by ring\n                ... ≤ 1: le_refl 1\n                ... = (1-x)^0: pow_zero (1-x)\n  ) ( -- Inductive step 1 - ↑(nat.succ n) * x ≤ (1 - x) ^ nat.succ n\n    λ n, λ h,\n    have H:   0 ≤ 1-x, from le_sub.mp (calc\n              x ≤ 1: h1\n            ... = 1-0: by ring),\n    have hkk:(1-x)≤ 1, from by {simp,exact h0,},\n    have hn: (1-x)^n ≤ 1, from calc\n             (1-x)^n ≤ 1^n : pow_le_pow_of_le_left H hkk n\n                 ... = 1   : one_pow n,\n    have hm: -(1*x) ≤ (-(1-x)^n)*x, from calc\n             -(1*x) ≤ -((1-x)^n*x): neg_le_neg (mul_le_mul_of_nonneg_right hn h0)\n                ... = (-(1-x)^n)*x: by ring,\n    calc  1 - ↑(nat.succ n) * x\n        = 1 - ↑ (n+1) * x  : by rw nat.succ_eq_add_one\n    ... = 1 - (↑n + ↑1) * x         : by norm_cast\n    ... = 1 - (↑n * x + ↑1*x)       : by rw right_distrib (↑ n) (↑ 1) x\n    ... = 1 - (↑n * x + 1*x)        : by norm_cast\n    ... = 1 - ↑n * x - 1*x          : by ring\n    ... ≤ (1-x)^n    - 1*x          : sub_le_sub h (le_refl (1*x))\n    ... ≤ (1-x)^n   + (- (1*x))     : by ring_nf\n    ... ≤ (1-x)^n   + (- (1-x)^n)*x : add_le_add (le_refl _) hm\n    ... = (1-x) * (1-x)^n           : by ring\n  )\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/page-2-acamoi.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706048, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.756120087667717}}
{"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.basic\nimport algebra.hom.aut\nimport data.zmod.defs\nimport 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 → (R ≃ R)` is the self-action,\nthen the self-distributivity is, equivalently, that\n```\nact (act x y) = act x * act y * (act x)⁻¹\n```\nwhere multiplication is composition in `R ≃ 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 ◃ y` is `shelf.act x y`\n* `x ◃⁻¹ y` is `rack.inv_act x y`\n* `S →◃ 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 ◃ 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 ◃ b = t * b + (1 - t) * b`, with `a` and `b` elements\n  of a module over `Z[t,t⁻¹]`.\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 ◃ xH = yzy⁻¹xH`.  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 (α : Type u) :=\n(act : α → α → α)\n(self_distrib : ∀ {x y z : α}, act x (act y z) = act (act x y) (act x z))\n\n/--\nA *unital shelf* is a shelf equipped with an element `1` such that, for all elements `x`,\nwe have both `x ◃ 1` and `1 ◃ x` equal `x`.\n-/\nclass unital_shelf (α : Type u) extends shelf α, has_one α :=\n(one_act : ∀ a : α, act 1 a = a)\n(act_one : ∀ a : α, act a 1 = a)\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₁ : Type*) (S₂ : Type*) [shelf S₁] [shelf S₂] :=\n(to_fun : S₁ → S₂)\n(map_act' : ∀ {x y : S₁}, 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 ◃ y` and `x ◃⁻¹ y` denote the action and the\ninverse action, respectively, and they are right associative.\n-/\nclass rack (α : Type u) extends shelf α :=\n(inv_act : α → α → α)\n(left_inv : ∀ x, function.left_inverse (inv_act x) (act x))\n(right_inv : ∀ x, function.right_inverse (inv_act x) (act x))\n\nlocalized \"infixr (name := shelf.act) ` ◃ `:65 := shelf.act\" in quandles\nlocalized \"infixr (name := rack.inv_act) ` ◃⁻¹ `:65 := rack.inv_act\" in quandles\nlocalized \"infixr (name := shelf_hom) ` →◃ `:25 := shelf_hom\" in quandles\n\nopen_locale quandles\n\nnamespace unital_shelf\nopen shelf\n\nvariables {S : Type*} [unital_shelf S]\n\n/--\nA 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-/\nlemma act_act_self_eq (x y : S) : (x ◃ y) ◃ x = x ◃ y :=\nbegin\n  have h : (x ◃ y) ◃ x = (x ◃ y) ◃ (x ◃ 1) := by rw act_one,\n  rw [h, ←shelf.self_distrib, act_one],\nend\n\nlemma act_idem (x : S) : (x ◃ x) = x := by rw [←act_one x, ←shelf.self_distrib, act_one, act_one]\n\nlemma act_self_act_eq (x y : S) : x ◃ (x ◃ y) = x ◃ y :=\nbegin\n  have h : x ◃ (x ◃ y) = (x ◃ 1) ◃ (x ◃ y) := by rw act_one,\n  rw [h, ←shelf.self_distrib, one_act],\nend\n\n/--\nThe associativity of a unital shelf comes for free.\n-/\nlemma assoc (x y z : S) : (x ◃ y) ◃ z = x ◃ y ◃ z :=\nby rw [self_distrib, self_distrib, act_act_self_eq, act_self_act_eq]\n\nend unital_shelf\n\nnamespace rack\nvariables {R : Type*} [rack R]\n\nlemma self_distrib {x y z : R} : x ◃ (y ◃ z) = (x ◃ y) ◃ (x ◃ z) :=\nshelf.self_distrib\n\n/--\nA rack acts on itself by equivalences.\n-/\ndef act (x : R) : R ≃ 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 ◃ y := rfl\n@[simp] lemma act_symm_apply (x y : R) : (act x).symm y = x ◃⁻¹ y := rfl\n@[simp] lemma inv_act_apply (x y : R) : (act x)⁻¹ y = x ◃⁻¹ y := rfl\n\n@[simp] lemma inv_act_act_eq (x y : R) : x ◃⁻¹ x ◃ y = y := left_inv x y\n@[simp] lemma act_inv_act_eq (x y : R) : x ◃ x ◃⁻¹ y = y := right_inv x y\n\nlemma left_cancel (x : R) {y y' : R} : x ◃ y = x ◃ y' ↔ y = y' :=\nby { split, apply (act x).injective, rintro rfl, refl }\n\nlemma left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' :=\nby { split, apply (act x).symm.injective, rintro rfl, refl }\n\nlemma self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ (x ◃⁻¹ z) :=\nbegin\n  rw [←left_cancel (x ◃⁻¹ y), right_inv, ←left_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 ◃ 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 ≃ R)` defined by `op'`.\n-/\nlemma ad_conj {R : Type*} [rack R] (x y : R) :\n  act (x ◃ y) = act x * act y * (act x)⁻¹ :=\nbegin\n  rw [eq_mul_inv_iff_mul_eq], ext z,\n  apply self_distrib.symm,\nend\n\n/--\nThe opposite rack, swapping the roles of `◃` and `◃⁻¹`.\n-/\ninstance opposite_rack : rack Rᵐᵒᵖ :=\n{ act := λ x y, op (inv_act (unop x) (unop y)),\n  self_distrib := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, mul_opposite.rec $ λ z, begin\n    simp only [unop_op, op_inj],\n    exact self_distrib_inv,\n  end,\n  inv_act := λ x y, op (shelf.act (unop x) (unop y)),\n  left_inv := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, by simp,\n  right_inv := mul_opposite.rec $ λ x, mul_opposite.rec $ λ y, by simp }\n\n@[simp] lemma op_act_op_eq {x y : R} : (op x) ◃ (op y) = op (x ◃⁻¹ y) := rfl\n@[simp] lemma op_inv_act_op_eq {x y : R} : (op x) ◃⁻¹ (op y) = op (x ◃ y) := rfl\n\n@[simp]\nlemma self_act_act_eq {x y : R} : (x ◃ x) ◃ y = x ◃ y :=\nby { rw [←right_inv x y, ←self_distrib] }\n\n@[simp]\nlemma self_inv_act_inv_act_eq {x y : R} : (x ◃⁻¹ x) ◃⁻¹ y = x ◃⁻¹ 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 ◃ x) ◃⁻¹ y = x ◃⁻¹ y :=\nby { rw ←left_cancel (x ◃ 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 ◃⁻¹ x) ◃ y = x ◃ 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 ◃ x = y ◃ y ↔ x = y :=\nbegin\n  split, swap, rintro rfl, refl,\n  intro h,\n  transitivity (x ◃ x) ◃⁻¹ (x ◃ x),\n  rw [←left_cancel (x ◃ x), right_inv, self_act_act_eq],\n  rw [h, ←left_cancel (y ◃ y), right_inv, self_act_act_eq],\nend\n\nlemma self_inv_act_eq_iff_eq {x y : R} : x ◃⁻¹ x = y ◃⁻¹ y ↔ x = y :=\nby { have h := @self_act_eq_iff_eq _ _ (op x) (op y), simpa using h }\n\n/--\nThe map `x ↦ x ◃ 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 ≃ R :=\n{ to_fun := λ x, x ◃ x,\n  inv_fun := λ x, x ◃⁻¹ x,\n  left_inv := λ x, by simp,\n  right_inv := λ 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 := ∀ 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 ◃⁻¹ y = x ◃ y :=\nbegin\n  rw [←left_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∀ (x y z w : R), (x ◃ y) ◃ (z ◃ w) = (x ◃ z) ◃ (y ◃ w)\n\n/--\nAssociative racks are uninteresting.\n-/\nlemma assoc_iff_id {R : Type*} [rack R] {x y z : R} :\n  x ◃ y ◃ z = (x ◃ y) ◃ z ↔ x ◃ z = z :=\nby { rw self_distrib, rw left_cancel }\n\nend rack\n\nnamespace shelf_hom\nvariables {S₁ : Type*} {S₂ : Type*} {S₃ : Type*} [shelf S₁] [shelf S₂] [shelf S₃]\n\ninstance : has_coe_to_fun (S₁ →◃ S₂) (λ _, S₁ → S₂) := ⟨shelf_hom.to_fun⟩\n\n@[simp] lemma to_fun_eq_coe (f : S₁ →◃ S₂) : f.to_fun = f := rfl\n\n@[simp] lemma map_act (f : S₁ →◃ S₂) {x y : S₁} : f (x ◃ y) = f x ◃ f y := map_act' f\n\n/-- The identity homomorphism -/\ndef id (S : Type*) [shelf S] : S →◃ S :=\n{ to_fun := id,\n  map_act' := by simp }\n\ninstance inhabited (S : Type*) [shelf S] : inhabited (S →◃ S) :=\n⟨id S⟩\n\n/-- The composition of shelf homomorphisms -/\ndef comp (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) : S₁ →◃ S₃ :=\n{ to_fun := g.to_fun ∘ f.to_fun,\n  map_act' := by simp }\n\n@[simp]\nlemma comp_apply (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) (x : S₁) :\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 (α : Type*) extends rack α :=\n(fix : ∀ {x : α}, 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 ◃⁻¹ x = x :=\nby { rw ←left_cancel x, simp }\n\ninstance opposite_quandle : quandle Qᵐᵒᵖ :=\n{ fix := λ 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_nonempty_instance]\ndef conj (G : Type*) := G\n\ninstance conj.quandle (G : Type*) [group G] : quandle (conj G) :=\n{ act := (λ x, @mul_aut.conj G _ x),\n  self_distrib := λ x y z, begin\n    dsimp only [mul_equiv.coe_to_equiv, mul_aut.conj_apply, conj],\n    group,\n  end,\n  inv_act := (λ x, (@mul_aut.conj G _ x).symm),\n  left_inv := λ x y, by { dsimp [act, conj], group },\n  right_inv := λ x y, by { dsimp [act, conj], group },\n  fix := λ x, by simp }\n\n@[simp]\nlemma conj_act_eq_conj {G : Type*} [group G] (x y : conj G) :\n  x ◃ y = ((x : G) * (y : G) * (x : G)⁻¹ : G) := rfl\n\nlemma conj_swap {G : Type*} [group G] (x y : conj G) :\n  x ◃ y = y ↔ y ◃ 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 →* H) : conj G →◃ conj H :=\n{ to_fun := f,\n  map_act' := by simp }\n\ninstance {G : Type*} {H : Type*} [group G] [group H] : has_lift (G →* H) (conj G →◃ 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_nonempty_instance]\ndef dihedral (n : ℕ) := 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 : ℕ) (a : zmod n) : zmod n → zmod n :=\nλ b, 2 * a - b\n\nlemma dihedral_act.inv (n : ℕ) (a : zmod n) : function.involutive (dihedral_act n a) :=\nby { intro b, dsimp [dihedral_act], ring }\n\ninstance (n : ℕ) : quandle (dihedral n) :=\n{ act := dihedral_act n,\n  self_distrib := λ x y z, begin\n    dsimp [dihedral_act], ring,\n  end,\n  inv_act := dihedral_act n,\n  left_inv := λ x, (dihedral_act.inv n x).left_inverse,\n  right_inv := λ x, (dihedral_act.inv n x).right_inverse,\n  fix := λ 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 ≃ R`\nthat acts on the rack.\n-/\ndef to_conj (R : Type*) [rack R] : R →◃ quandle.conj (R ≃ 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 →◃ conj G` is\ninduced by a unique group homomorphism `envel_group R →* 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 →* 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 →◃ conj G`, how does\n`envel_group.map f : envel_group R →* 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 →* 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⟨pre_envel_group.unit⟩\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 → pre_envel_group R → 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 ◃ y))\n\ninstance pre_envel_group_rel'.inhabited (R : Type u) [rack R] :\n  inhabited (pre_envel_group_rel' R unit unit) :=\n⟨pre_envel_group_rel'.refl⟩\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 → pre_envel_group R → 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 → 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 → pre_envel_group_rel R b a\n| ⟨r⟩ := 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 → pre_envel_group_rel R b c → pre_envel_group_rel R a c\n| ⟨rab⟩ ⟨rbc⟩ := (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 := λ a b, quotient.lift_on₂ a b\n                  (λ a b, ⟦pre_envel_group.mul a b⟧)\n                  (λ a b a' b' ⟨ha⟩ ⟨hb⟩,\n                    quotient.sound (pre_envel_group_rel'.congr_mul ha hb).rel),\n  one := ⟦unit⟧,\n  inv := λ a, quotient.lift_on a\n                (λ a, ⟦pre_envel_group.inv a⟧)\n                (λ a a' ⟨ha⟩,\n                  quotient.sound (pre_envel_group_rel'.congr_inv ha).rel),\n  mul_assoc := λ a b c,\n    quotient.induction_on₃ a b c (λ a b c, quotient.sound (pre_envel_group_rel'.assoc a b c).rel),\n  one_mul := λ a,\n    quotient.induction_on a (λ a, quotient.sound (pre_envel_group_rel'.one_mul a).rel),\n  mul_one := λ a,\n    quotient.induction_on a (λ 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 := λ a,\n    quotient.induction_on a (λ 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) := ⟨1⟩\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 →◃ quandle.conj (envel_group R) :=\n{ to_fun := λ x, ⟦incl x⟧,\n  map_act' := λ 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 →◃ quandle.conj G) : pre_envel_group R → 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)⁻¹\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 →◃ quandle.conj G) :\n  Π {a b : pre_envel_group R}, pre_envel_group_rel' R a b →\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 →◃ quandle.conj G) ≃ (envel_group R →* G) :=\n{ to_fun := λ f,\n  { to_fun := λ x, quotient.lift_on x (to_envel_group.map_aux f)\n                    (λ a b ⟨hab⟩, to_envel_group.map_aux.well_def f hab),\n    map_one' := begin\n      change quotient.lift_on ⟦rack.pre_envel_group.unit⟧ (to_envel_group.map_aux f) _ = 1,\n      simp [to_envel_group.map_aux],\n    end,\n    map_mul' := λ x y, quotient.induction_on₂ x y (λ x y, begin\n      change quotient.lift_on ⟦mul x y⟧ (to_envel_group.map_aux f) _ = _,\n      simp [to_envel_group.map_aux],\n    end) },\n  inv_fun := λ F, (quandle.conj.map F).comp (to_envel_group R),\n  left_inv := λ f, by { ext, refl },\n  right_inv := λ F, monoid_hom.ext $ λ x, quotient.induction_on x $ λ x, begin\n    induction x,\n    { exact F.map_one.symm, },\n    { refl, },\n    { have hm : ⟦x_a.mul x_b⟧ = @has_mul.mul (envel_group R) _ ⟦x_a⟧ ⟦x_b⟧ := rfl,\n      rw [hm, F.map_mul, monoid_hom.map_mul, ←x_ih_a, ←x_ih_b] },\n    { have hm : ⟦x_a.inv⟧ = @has_inv.inv (envel_group R) _ ⟦x_a⟧ := 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 →◃ 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 →◃ quandle.conj G)\n  (g : envel_group R →* G) (h : f = (quandle.conj.map g).comp (to_envel_group R)) :\n  g = to_envel_group.map f :=\nh.symm ▸ (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 →* (R ≃ R) :=\nto_envel_group.map (to_conj R)\n\n@[simp]\n\n\nend envel_group\n\nend rack\n", "meta": {"author": "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/quandle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7560855999190262}}
{"text": "/- Copyright (c) 2022 Sina Hazratpour. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n----------------\n\n# Inductive Types : Natural Numbers\nSina Hazratpour\nIntroduction to Proof  \nMATH 301, Johns Hopkins University, Fall 2022   \n-/\n\nimport ..prooflab\nimport lectures.lec12_gaussian_integers\nimport lectures.lec13_structures_on_gaussian_int\n\n\n/-\nOverview of this code:\n1. Natural Numbers\n2. Predicates on Natural Numbers\n3. Induction  \n-/\n\n\nnamespace PROOFS\n\nvariables {X Y : Type}\n\n------------------------------\n--------Natural Numbers----\n------------------------------\n\n/- \n1.  Every natural number is either `zero` or `succ n`, for a previously defined natural number `n`. \n2. The type `nat` of natural numbers, which is defined in the Lean mathlib library, is the archetypal exmaple of an __inductive__ type.  \n3. However, for the sole purpose of pedagogy we are going to define our own adhoc inductive type of natural numbers. It is defined in the same way as in the mathlib, but we give it a different name so that we can prove our own theorem without any previous knowledge. So far, we have taken the knowledge of natural numbers for granted, and we have relied on mathlib. Now, for the first time we will understand what statements like `∀ m n : mat, m + n = n + m` are true in virute of the construction of natural numbers. \n-/\n\n\n/- mat short for  mynat -/\n\ninductive mat : Type\n| zero : mat -- pattern 1 (constructor `zero`)\n| succ : mat → mat -- pattern 2 (constructor `succ`)\n-- there are two cases; either a natural number is zero or is the successor of a previously defined natural number. \n\n/- 3 = succ 2 = succ (succ 1) = succ (succ (succ 0)) -/\n\n\n/- There are two __constructors__. We start with `zero : nat`; it takes no arguments, so we have it from the start. In contrast, the constructor `succ` can only be applied to a previously constructed nat. Applying it to zero yields `succ zero : mat`. Applying it again yields `succ (succ zero) : mat`, and so on. \n-/\n\n\n\n#check mat\n\n\n#check mat.zero -- zero constructor \n#check mat.succ -- succ constructor \n\n\n\n\n\n\nnamespace mat\n\ninstance : has_zero mat := ⟨mat.zero⟩ --zero here is mat.zero since we are inside in the namespace `mat`. \n\n@[simp]\nlemma zero_def : \n  mat.zero = 0 := \nbegin\n  refl, \nend \n\n\ndef one := succ 0 -- this works because 0 := zero in the type class has_zero \n\n\ninstance : has_one mat := ⟨one⟩ \n\n\ndef two := succ 1  \n\n\ndef three := succ two \n\ndef four := succ three\n\ndef five := succ (succ three)\n\n\n\nexample : \n  five = succ (four) := \nbegin\n  refl, \nend \n\n\n\nexample : \n  five = succ (succ (succ (two))) := \nbegin\n  refl, \nend \n\n\n#reduce three\n#reduce four\n\n\nexample (m : mat) (h : succ m = two) : \n  succ(succ(m)) = three :=\nbegin\n  rw h, \n  refl, \nend \n\n\ntheorem no_conf : -- short for no_confusion\n  ∀ m : mat, 0 ≠ succ (m) := \nbegin \n  intro m, \n  intro h, \n  contradiction, -- the free generation of mat under the constructors `zero` and `succ` means there cannot be any non-rfl equations between terms of `mat` \nend   \n\n\ntheorem succ_inj (m n : mat) : \n  m.succ = n.succ → m = n := \nbegin\n  intro h, \n  simp at h, \n  exact h, \nend \n\n\n/- \nWhat does it mean that `mat` is indutively defined? Intuitively, `mat` is the “smallest” type with these two constructors, meaning that it is __exhaustively__ and __freely__ generated by starting with `zero` and applying `succ` repeatedly. \nAs a consequence to define a function, say `f`, out of `mat` all we need to do is to specify the value of `f` at `zero` and the value of `f` at `succ n` for `n : mat`. \n\nThis is the idea behind __recursion__. \n-/\n\n@[simp]\ndef pred : mat → mat -- predecessor function \n| 0 := 0 \n| (succ n) := n \n\n#check pred\n\n\n@[simp]\nlemma pred_succ : \n   pred ∘ succ = id := \nbegin\n  funext n,\n  dsimp, \n  cases n,\n  {\n    refl, \n  }, \n  {\n    refl,\n  }\nend    \n\n\n@[simp]\nlemma succ_pred (k : mat) (h : ∃ m : mat, k = succ m): \n  succ (pred k) = k := \nbegin \n  cases h with n hn,\n  rw hn, \n  refl,  \nend   \n\n\n\n/-\nAnother example of recursion: For instance the constant function `mat → bool` at `ff`: \n-/\n\ndef constant_ff_of_mat : mat → bool \n| 0 := ff \n| (succ n) := constant_ff_of_mat n -- this definition is recursive since the value of `constant_ff_of_mat` at `succ n` is expressed in term of the value of  `constant_ff_of_mat` at `n` (one lower). This process halts at `zero`. \n\n\n\ndef constant_ff_of_mat_alt : mat → bool  := λ b, ff -- what is the difference between this function and the one above\n\n\n#reduce bool_of_nat \n\n-- define it by pattern matching  \ndef bool_of_mat : mat → bool \n| 0 := ff  \n| (succ n) := tt \n\n\n\ndef bad : mat → mat\n| zero := zero\n| (succ n) := succ (bad (succ n))\n\n\n\n#check one + two \n\n\n-- note what just happened:\ndef thirty_seven_error : mat := 37 -- what is 37?\n\n\n-- define it recursively \ndef two_add : mat → mat \n-- define two_add to be a function which takes a natural number n and returns 2 + n\n| 0 := two \n| (succ n) := succ (two_add (n))\n\n\n/- `two_add 1 = two_add (succ 0)  by pattern matching \n              = succ (two_add 0) by definition of two_add; second pattern \n              = succ (two)  by definition of two_add; first pattern \n              = three by definition of three\n-/\n\n\nexample : \n  two_add two = four := \nbegin \n  refl, \nend \n\n\ndef add : mat → mat → mat\n-- λ m, (add m : mat → mat)\n| m 0 := m\n| m (succ n) := succ (add m n)\n\n\n\nexample : \n  add two two = four := \nbegin \n  refl, \nend \n\ninstance : has_add mat := ⟨add⟩\n\n\n#check one + two \n\ndef thirty_seven : mat := 37\n\n-- another example of recursive function \ndef double : mat → mat  \n| 0 := 0 \n| (succ n) := double n + 2 \n\n\nexample : \n  double 1 = 2 := \nbegin \n  refl, \nend \n\n@[simp]\nlemma add_zero (m : mat) : \n  m + 0 = m :=\nbegin\n  refl, -- works because of the defn of addition \nend\n\n\n@[simp]\nlemma add_one (m : mat) : \n  m + 1 = succ (m) :=\nbegin\n  refl,  \nend \n\n\n@[simp]\nlemma add_succ (m n : mat) : \n  m + succ n = succ (m + n) := \nbegin\n  refl,\nend \n\n\n\n\nlemma zero_add' (m : mat) :\n  0 + m = m := \nbegin\n  cases m, \n  {\n    refl,  \n  },\n  {\n    rw add_succ,\n    -- we cannot do this because this is our original problem -- to do this we need some more tools (induction).\n  }\nend   \n\n\n/-\n__The Principle of Induction for Natural Numbers__: \nLet `P` be any property of natural numbers, i.e. P : ℕ → Prop (e.g. `P m = (0 + m =m)` ). Suppose `P` holds of zero (i.e. `P 0` holds), and whenever `P` holds of a natural number `n`, then it holds of its successor, `succ n` (i.e. we have a proof of `P n → P succ(n)` ). Then `P` holds of every natural number `n` (i.e. `∀ n : ℕ, P n` ).\n\n`P 0 ∧ ( ∀ n, P n → P succ(n) ) →  ∀ n, P n`. \n\n                          ---------\n                          `P n` (the induction hypothesis) \n                          .\n                          .\n                          .\n`P 0` (the base case)     `P (succ n)`\n------------------------------------\n          ∀ n, P n \n\nInduction  works very similar to `cases`  but it gives us an extra assumption when proving the successor case, which we usually label `ih` (or something similar) for the induction hypothesis. \n-/\n\n@[simp]\nlemma zero_add  :\n  ∀ m : mat, 0 + m = m :=  -- has the form of `∀ m : mat, P m` \nbegin\n  intro m, \n  induction m with n ihn, -- the important difference between tactic `induction` is that we now have an extra assumption `ihn` in the context which will be crucial\n  {\n    -- proving base case `P 0`\n    refl,\n  },\n  {-- the inductive step: assuming `P n` and proving  `P succ(n)`\n    rw add_succ,    \n    rw ihn,\n  },\nend   \n\n@[simp]\nlemma one_add (n : mat) : 1 + n = succ n :=\nbegin\n  induction n with d ihd, -- ihd stands for \"inductive hypothesis\"\n  {\n    refl,\n  },\n  {\n    rw add_succ, -- changes lhs `1 + d.succ` to `(1 + d).succ`\n    rw ihd,\n  },\nend\n\n\n-- We isolate some useful facts and prove them first\n@[simp]\nlemma succ_add (a b : mat) : succ a + b = succ (a + b) :=\nbegin\n  induction b with d ihd,\n  { -- base case when b = 0\n    refl,\n  }, \n  { -- supposing `succ a + i = succ (a + i)` we want to prove `a.succ + i.succ = (a + i.succ).succ`. \n    rw add_succ, -- bring `i` into the addition. \n    rw ihd,\n    refl,\n  }\nend\n\n\n\nlemma add_comm (m n : mat) : m + n = n + m :=\nbegin\n  induction m with d ihd,\n  {\n    show 0 + n = n + 0,\n    rw add_zero, -- simplified `n + 0` to `n`\n    rw zero_add, \n  },\n  {\n    rw add_succ, --changed `n + d.succ` to `(n + d).succ`\n    rw ← ihd, \n    --rw ← add_succ,\n    rw succ_add, \n  },\nend   \n\n\n\nlemma add_assoc (a b c : mat) : (a + b) + c = a + (b + c) :=\nbegin\n  induction c with d ihd,\n  {\n    -- (a + b) + zero = a + (b + zero)\n    show (a + b) + 0 = a + (b + 0), \n    repeat {rw add_zero}, \n  },\n  {\n    rw add_succ, \n    rw add_succ, \n    rw add_succ, \n    rw ihd, \n  },\nend \n\n\n\nnamespace STR\nopen PROOFS.STR\n\ninstance : comm_additive_monoid_str mat := \n{ \n  add := mat.add,\n  add_assoc := mat.add_assoc,\n  zero := 0,\n  add_zero := mat.add_zero,\n  zero_add := mat.zero_add, \n  add_comm := mat.add_comm, \n}\n\nend STR\n\n\n\n\nlemma succ_inj' : \n  is_injective succ := \nbegin\n  unfold is_injective,\n  intros a b, -- introduced these to prove ∀   \n  intro h, -- introduce `h` to prove → \n  induction a with d ihd, \n  {\n    show 0 = b, \n    induction b with c ihc, \n    {\n      refl,\n    },\n    {\n      sorry, -- maybe this is a deadend approach, we have to reevaluate our strategy. \n    },\n  },\n  {\n    sorry,\n  },\nend \n\n\n\n\n\n\n\n\n\n\ndef mul : mat → mat → mat\n-- λ m, (add m : mat → mat)\n| m 0 := 0  \n| m (succ n) :=  (mul m n) + m -- m * (n + 1) should return m * n + m\n\n\nlemma mul_zero' (m : mat) : \n  mul m 0 =  0 := \nbegin\n  refl, -- definitional equality based on the first line of the defn of mul \nend   \n\n\ninstance : has_mul mat := ⟨mul⟩ \n\n@[simp]\nlemma mul_zero (m : mat) : \n   m * 0 =  0 :=  \nbegin\n  refl, -- definitional equality based on the first line of the defn of mul \nend   \n\n\n@[simp]\nlemma mul_succ (m n : mat) : \n   m * (succ n) =  m * n + m :=  \nbegin\n  refl, -- definitional equality based on the second line of defn of mul \nend   \n\n\n@[simp]\nlemma mul_one (m : mat) : \n  m * 1 = m := \nbegin\n  suffices h : m * 1 = 0 + m, from zero_add m, \n  refl, \nend   \n\n\n@[simp]\nlemma zero_mul (m : mat) : \n   0 * m =  0 :=  \nbegin\n  induction m with d ihd, \n  {\n    refl, \n  }, \n  {\n    rw mul_succ, \n    rw add_zero, \n    rw ihd, \n  }\nend   \n\n#check mat.mul_zero\n\n\n@[simp]\nlemma one_mul (m : mat) : \n  1 * m = m := \nbegin\n  induction m with d ihd, \n  {\n    show (1 : mat) * 0 = 0, from (mat.mul_zero 1),\n  },\n  {\n    rw mul_succ, \n    rw ihd, \n    rw add_one, \n  },\nend \n\n\n\n/- We define recursively a function `sum_up_to : mat → mat` which assigns to `m : mat` the sum of natural numbers up to (and including) `m`, i.e. the value `sum_up n` is the sum of `1, ..., n`. -/\n\ndef sum_up_to : mat → mat\n-- \n-- therefore, \n| 0 := 0\n| (succ n) := sum_up_to n + succ n \n\n-- testing\nexample : \n  sum_up_to 5 = 15 := \nbegin\n  refl,   \nend \n\n\n\nend mat \nend PROOFS\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/lec14_inductive_naturals.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542185, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7560166917618316}}
{"text": "import tactic\n\n#check mul_add\n#check dvd_mul_right\n#check add_sub_cancel\n#check add_sub_cancel'\n\nvariables {x d f g : ℤ}\nvariables {a b c e m n t : ℕ}\n\n-- BEGIN\n/- Prove that for x, d ∈ ℤ, if x divides x + d, \n   then x also divides d. -/\nexample (divxd : x ∣ x + d) : x ∣ d :=\nbegin\n  cases divxd with f beq,\n  use f - 1,\n  rw mul_sub,\n  rw ← beq,\n  rw [mul_one, add_sub_cancel' x d], -- or, ring\nend\n\n/- A similar proof: prove that for a, b, c ∈ ℕ, if a ∣ b and a ∣ c, \n   then a ∣ (b + c). -/\nexample (divab : a ∣ b) (divac : a ∣ c) : a ∣ (b + c) :=\nbegin \n  cases divab with d beq,\n  cases divac with e ceq,\n  rw [beq, ceq],\n  rw ← mul_add,\n  exact dvd_mul_right a (d + e),\nend\n\nexample (divab : a ∣ b) (divac : a ∣ c) : a ∣ (b + c) :=\nbegin \n  cases divab with d beq,\n  cases divac with e ceq,\n  rw [beq, ceq],\n  rw ← mul_add,\n  use (d + e),\nend\n\nexample (h : t ∣ m) (h' : t ∣ n) : t ∣ a * m + b * n := \nbegin \n  cases h with c hc,\n  cases h' with e he,\n  rw [hc, he],\n  rw [mul_comm, mul_assoc, mul_comm b, mul_assoc t],\n  rw ← mul_add,\n  use (c * a + e * b),\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/0_Introduction/proofs introduced in CSC110/dvd_a(b+c).lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.944176857294597, "lm_q2_score": 0.8006920068519376, "lm_q1q2_score": 0.7559948626903664}}
{"text": "-- Monotonía de la suma por la izquierda en Lean\n-- =============================================\n\n-- Demostrar que si a, b y c son números reales \n-- tales que a ≤ b, entonces c + a ≤ c + b.\n\nimport data.real.basic\n\nvariables {a b c : ℝ}\n\n-- 1ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  have h : (c + b) - (c + a) = b - a, \n  { ring, },  \n  { rw h, \n    rw sub_nonneg,\n    exact hab, },\nend\n\n-- 2ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  calc \n    0   ≤ b - a           \n            : by exact sub_nonneg.mpr hab\n    ... = c + b - (c + a) \n            : by exact (add_sub_add_left_eq_sub b a c).symm, \nend\n\n-- 3ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  calc \n  0   ≤ b - a           \n          : sub_nonneg.mpr hab\n  ... = c + b - (c + a) \n          : (add_sub_add_left_eq_sub b a c).symm,\nend\n\n-- 4ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  calc 0   ≤ b - a           : sub_nonneg.mpr hab\n       ... = c + b - (c + a) : by ring\nend\n\n-- 5ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  simp,\n  exact hab,\nend\n\n-- 6ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  rw ← sub_nonneg,\n  simp [hab],\nend\n\n-- 7ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nbegin\n  simp [hab],\nend\n\n-- 8ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nby simp [hab]\n\n-- 9ª demostración\nexample \n  (d : ℝ)\n  (hab : a ≤ b) \n  : d + a ≤ d + b :=\nadd_le_add_left hab d\n\n-- 10ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\nby linarith\n\n-- 11ª demostración\nexample \n  (hab : a ≤ b) \n  : c + a ≤ c + b :=\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_izquierda_SC.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7559797882266333}}
{"text": "import Katydid.Std.Algebra\n\ninstance : Repr Ordering where\n  reprPrec\n    | Ordering.lt, _ => \"<\"\n    | Ordering.gt, _ => \">\"\n    | Ordering.eq, _ => \"=\"\n\nnamespace Ordering\n\n-- lexicographical ordering\ndef lex (x: Ordering) (y: Ordering): Ordering :=\n  match x with\n  | Ordering.eq => y\n  | _ => x\n\ntheorem lex_assoc:\n  ∀ a b c, lex (lex a b) c = lex a (lex b c) := by\n  intros a b c\n  cases a <;> simp [lex]\n\ntheorem lex_assoc' (a b c: Ordering):\n  lex (lex a b) c = lex a (lex b c) := by\n  cases a\n  {\n    case lt => rfl\n  }\n  case eq => rfl\n  case gt => rfl\n\ntheorem lex_assoc'' (a b c: Ordering):\n  lex (lex a b) c = lex a (lex b c) :=\n  by cases a with\n  | eq => rfl\n  | lt => rfl\n  | gt => rfl\n\ntheorem lex_assoc''' (a b c: Ordering):\n  lex (lex a b) c = lex a (lex b c) :=\n  match a with\n  | Ordering.eq => rfl\n  | Ordering.lt => by rfl\n  | Ordering.gt => by rfl\n\ntheorem lex_left_identity (a: Ordering):\n  lex Ordering.eq a = a := by\n  cases a <;> rfl\n\ntheorem lex_right_identity (a: Ordering):\n  lex a Ordering.eq = a := by\n  cases a <;> rfl\n\ntheorem lex_right_identity':\n  ∀ x, lex x Ordering.eq = x := by\n  intro x\n  cases x\n  · rfl\n  · rfl\n  · rfl\n\ntheorem lex_right_identity'':\n  ∀ x, lex x Ordering.eq = x := by\n  intro x\n  cases x\n  { rfl }\n  { rfl }\n  { rfl }\n\nend Ordering\n\ninstance : Magma Ordering where\n  op a b := Ordering.lex a b\n\ninstance : Semigroup Ordering where\n  is_assoc := Ordering.lex_assoc\n\ninstance : Monoid Ordering where\n  empty := Ordering.eq\n  left_identity := Ordering.lex_left_identity\n  right_identity := Ordering.lex_right_identity\n\nsection instances_using_structure'\n\n  open algebra_using_structure'\n\n  def instanceMagmaLex := Magma'Struct.mk Ordering Ordering.lex\n  def instanceMagmaLex': Magma'Struct := {\n    carrier := Ordering,\n    op := Ordering.lex\n  }\n\n  def instanceSemigroupLex : Semigroup'Struct := {\n    toMagma'Struct := instanceMagmaLex,\n    is_assoc := Ordering.lex_assoc\n  }\n  def instanceSemigroupLex' : Semigroup'Struct := {\n    carrier := Ordering,\n    op := Ordering.lex,\n    is_assoc := Ordering.lex_assoc\n  }\n\n  def instanceMonoidLex : Monoid'Struct := {\n    carrier := Ordering,\n    op := Ordering.lex,\n    is_assoc := Ordering.lex_assoc,\n    e := Ordering.eq,\n    left_identity := Ordering.lex_left_identity,\n    right_identity := Ordering.lex_right_identity,\n  }\n  def instanceMonoidLex' : Monoid'Struct := {\n    toSemigroup'Struct := instanceSemigroupLex,\n    e := Ordering.eq,\n    left_identity := Ordering.lex_left_identity,\n    right_identity := Ordering.lex_right_identity,\n  }\n\nend instances_using_structure'", "meta": {"author": "katydid", "repo": "proofs", "sha": "f13ca817190069a392eba69b6db9d5add4fd8ce5", "save_path": "github-repos/lean/katydid-proofs", "path": "github-repos/lean/katydid-proofs/proofs-f13ca817190069a392eba69b6db9d5add4fd8ce5/Katydid/Std/Ordering.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7559797818641714}}
{"text": "import tactic           -- import all the tactics\nimport data.nat.prime_norm_num   -- import ℕ natural numbers \nimport data.real.basic  -- import ℝ real numbers\nimport data.real.irrational  -- allows us to talk about irrational numbers\n\nvariables (α β: Type)        \nvariables (A B C D: set α)\nvariables (a x y: α)\nopen set nat\n\n/- \nA set in Lean can only contain elements of the same type.\n\nSo for any type `α : Type` there is a type of `set α : Type`\n\nThe terms of this type are sets containing elements of type α\n\nSo if `S : set ℕ` then `S` is a set containing only natural numbers.\n\nSuppose we also have a set `T : set ℝ`, containing only real numbers. \n\nAs mathematicians we could happily form their intersection `S ∩ T` \nbut this doesn't work in Lean! -/\n\nvariable (S : set ℕ)\nvariable (T : set ℝ) \n\n--#check S ∩ T    -- type mismatch at application `S ∩ T` term `T` has\n                  /- type `set ℝ` but is expected to have type `set ℕ` \n\nAnother obvious difference between sets in Lean and in maths is that \nwe would usually call S a subset of ℕ and write `S ⊆ ℕ`\n\nUnfortunately this also doesn't work in Lean: `ℕ` is a Type not a set. -/\n\n--#check S ⊆ ℕ -- type mismatch at application S ⊆ ℕ term ℕ has type Type : Type 1\n                /- but is expected to have type set ℕ : Type\n\nA `predicate` on a type α is a function `α → Prop`\n\nFor example `nat.prime: ℕ → Prop` is the predicate telling us whether \nor not `n : ℕ` is `prime`.\n\nGiven any set A whose elements all have type α there is a predicate on α\ngiven by `x ∈ A`.\n\nIn Lean `A : set α`  is defined to be this predicate.\n\nSets can be written in standard set-builder notation\n\nFor example `{p : ℕ | nat.prime p}` is the set of primes\n\nHere are some more examples:\n\n`{n : ℕ | n ≤ 10}`  the set ℕ containing all nats ≤ 10\n`{x : ℝ | irrational x}`  the set ℝ containing all irrational numbers\n\nNote that in each case the elements of each set are of `a fixed type`. -/\n\n--#check {p : ℕ | nat.prime p} -- : set ℕ\n--#check {n : ℕ | n ≤ 10}      -- : set ℕ  \n--#check {x : ℝ | irrational x} -- : set ℝ\n\nvariable (Pr : α → Prop)  -- a predicate on α\n-- The set defined by a predicate equals the predicate\n\n-- 01\nexample : {a : α | Pr a} = Pr :=\nbegin\n  refl,\nend\n\n-- 02\nexample : {p : ℕ | nat.prime p} = nat.prime :=\nbegin\n  sorry,\nend\n\n/-  \nThe way we refer to membership of a set is with `∈` (type `\\in`)\nFor any  `x : α`  we have  `x ∈ A` iff `Pr x` -/\n-- 03\nexample : x ∈ { a | Pr a} ↔ Pr x:=\nbegin\n   sorry, \nend\n\n-- Asking Lean whether a term of type `β` belongs to a `set α` is problematic\nvariable (b : β) -- UNCOMMENT next line to see full error\n--#check (b ∈ A) -- failed to synthesize type class instance for... ⊢ has_mem β (set α)\n\n/- This error message can be read as saying:\n\"I don't know how to make sense of the question of whether a term of type β\nis a member of a set α\"  \n  \n(Trying to make sense of Infoview output is all part of learning Lean.) -/\n\n/- \n# New tactic: `change` \n\nWhen we have a goal `⊢ H1` and we know that it is definitionally equal to `H2`\nthen we can do `change H2` and our goal changes to `⊢ H2`\n\nIt can also be used on local hypotheses: eg if we had \nif `h : H1` then we could do `change H2 at h` to get `h : H2` -/\n \nsection mem\n-- 04\nexample : 2 ∈ {n : ℕ | even n}:=\nbegin\n  dsimp,    -- simplifies our goal to `⊢ even 2` which is definitionally the same.\n  change ∃x, 2 = x + x, --if you check `even k` is defined to be `∃ x, k = x + x`\n  use 1, -- provides the required `x` and then closes the remaining goal `2 = 1 + 1`\nend\n\n/-\nYou can check that both `dsimp` and `change` are not needed in our previous proof\n(comment out the 1st two lines). They are still useful as we write the proof since they\nhelp to clarify the goal. -/\n-- 05\nexample : 2 ∈ ({1,2,3}: set ℕ):=\nbegin\n  dsimp, -- goal becomes  `⊢ 3 = 1 ∨ 3 = 2 ∨ 3 = 3` \n  right,left,refl,\nend\n\n-- 06\nexample : 3 ∈ {n:ℕ | n ≤ 10}  :=\nbegin\n  sorry,\nend\n\n-- 07\nexample : 1 ∈ { x : ℕ | ∀ (k:ℕ), 1 ≤ k+1} :=\nbegin\n  sorry,\nend\n\n--Not in `∉` is `\\nin`\n-- 08\nexample : x ∉ A ↔ ¬ (x ∈ A):=\nbegin\n  refl,\nend\n\n-- 09\nexample : 4 ∉ {n : ℕ| 5 < n} ∧ 6 ∉ {n : ℕ | nat.prime n}:=\nbegin\n  sorry,\nend\n\nend mem\n\nsection subsets\n\n/-  `Subsets`: `⊆` (type \\ss) \nIf `A B : set α` then `A ⊆ B` iff every element of A is also an element of B -/\n-- 10\nexample : (A ⊆ B) ↔ (∀x, x ∈ A → x ∈ B):=\nbegin\n  refl,\nend\n\n--the next proof is easy, but can you explain why `refl` works in this case?\n-- 11\nexample (A : set α) : A ⊆ A:=\nbegin\n  sorry,\nend\n\n/- If we have `(h : A ⊆ B)` and `(hx : x ∈ A)` then `h hx` is a proof that `x ∈ B`\nSo `h` takes a proof that `x ∈ A` and returns a proof that `x ∈ B`-/\n-- 12\nexample (hx: x ∈ A)  (h: A ⊆ B) :  x ∈ B:=\nbegin\n  apply h, -- Goal `⊢ x ∈ B` changes to `⊢ x ∈ A`\n  exact hx,\nend\n\n-- Since `A ⊆ C` is `∀x, x ∈ A → x ∈ C` you can start with `intro x`,\n-- 13\nexample  (hAB: A ⊆ B) (hBC: B ⊆ C) : A ⊆ C:=\nbegin\n  sorry,\nend\n\n-- `dsimp at *` will simplify definitions in local context and in the goal.\n-- 14\nexample : ({1,3} : set ℕ) ⊆ {n | n ≤ 5} :=\nbegin\n  sorry,\nend\n\n\nend subsets\n\nsection ops\n\n/- `Operations on sets`\n\nWe have all the usual methods of building new sets from old.\n\nThey are defined exactly as you would imagine.\n\nMost of the next examples can be proved using `refl`\n\ne.g. intersection `∩` (type \\cap ) is `and` -/\n-- 15\nexample : x ∈ A ∩ B ↔ (x ∈ A) ∧ (x ∈ B):=\nbegin\n  refl,\nend\n\n-- union `∪` (type \\un) is `or`\n-- 16\nexample : x ∈ A ∪ B ↔ (x ∈ A) ∨ (x ∈ B):=\nbegin\n  sorry,\nend\n\n-- Set `diff`erence `\\` (type \\\\) is `(in A)  and (not in B)` (for `∉` type `\\nin`)\n-- 17\nexample : x ∈ A \\ B ↔   x ∈ A ∧ x ∉ B :=\nbegin\n  sorry,\nend\n\n-- Complement `ᶜ` (type \\^c) is `not in`\n-- 18\nexample : x ∈ Aᶜ ↔ ¬ (x ∈ A):=\nbegin\n  sorry,\nend\n\n-- Complement and ∉ are the same\n-- 19\nexample : x ∈ Aᶜ ↔ x ∉ A :=\nbegin\n  sorry,\nend\n\n-- 20\nexample : A ∩ B ⊆ B:=\nbegin\n  sorry,\nend\n\n-- 21\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  sorry,\nend\n\n-- 22\nexample  : A ∩ B ⊆ A ∪ B:=\nbegin\n  sorry,\nend\n\n-- 23\nexample (hAB : A ⊆ B) (hCD: C ⊆ D) : A ∩ C ⊆ B ∩ D :=\nbegin\n  sorry,\nend\n\n-- 24\nexample (hAB : A ∪ B ⊆ C) : A ⊆ C ∧ B ⊆ C:=\nbegin\n  sorry,\nend\nend ops\n\n\nsection univ_empty\n/-There are two special sets for any type α\n\n     `univ = {a:α | true}`\n\n     `∅ = {a:α | false}`\n\nNote that `(univ : set α)` and `(∅ : set α)` so each type has\nits own universal set and empty set. -/\n\n-- open the namespace `set` to use univ otherwise we would have to use `set.univ`  \nopen set \n-- 25\nexample : x ∈ (univ : set α) ↔ true:=\nbegin\n  refl,\nend\n\n--26\nexample  (A : set α) : A ⊆ A ∩ univ  :=\nbegin\n  sorry,\nend\n\n/- Although `(univ : set α)` is the set containing every element of type `α`\n   it is not equal to `α`, and Lean won't let you consider this -/\n\n-- #check (univ : set α) = α\n-- 27\nexample : x ∈ (∅ : set α) ↔ false:=\nbegin\n  refl,\nend\n\n-- Note: if you have `h : x ∈ ∅` then `cases h` will let you consider all the cases..\n-- 28\nexample (A : set α) : ∅ ∪  A ⊆ A   :=\nbegin\n  sorry,\nend\nend univ_empty", "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/3_sets/basics.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859265, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7559797783855382}}
{"text": "def is_even (a : ℕ) := ∃ b, a = 2 * b\n\ntheorem even_plus_even {a b : ℕ} (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n  match h1, h2 with\n    ⟨w1, hw1⟩, ⟨w2, hw2⟩ := ⟨w1 + w2, by rw [hw1, hw2, mul_add]⟩\n  end\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/ex0410.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9658995713428385, "lm_q2_score": 0.7826624789529375, "lm_q1q2_score": 0.7559733529267657}}
{"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.basic\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/Pythagorean_theorem\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*} [inner_product_space ℝ V]\n\n/-- Pythagorean theorem, if-and-only-if vector angle form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :\n  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ angle x y = π / 2 :=\nbegin\n  rw norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero,\n  exact inner_eq_zero_iff_angle_eq_pi_div_two x y\nend\n\n/-- Pythagorean theorem, vector angle form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :\n  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\n(norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :\n  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ angle x y = π / 2 :=\nbegin\n  rw norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero,\n  exact inner_eq_zero_iff_angle_eq_pi_div_two x y\nend\n\n/-- Pythagorean theorem, subtracting vectors, vector angle form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :\n  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\n(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h\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  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ - 2 * ∥x∥ * ∥y∥ * real.cos (angle x y) :=\nby rw [(show 2 * ∥x∥ * ∥y∥ * real.cos (angle x y) =\n             2 * (real.cos (angle x y) * (∥x∥ * ∥y∥)), by ring),\n       cos_angle_mul_norm_mul_norm, ←real_inner_self_eq_norm_sq,\n       ←real_inner_self_eq_norm_sq, ←real_inner_self_eq_norm_sq, real_inner_sub_sub_self,\n       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 : ∥x∥ = ∥y∥) :\n  angle x (x - y) = angle y (y - x) :=\nbegin\n  refine real.inj_on_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ _,\n  rw [cos_angle, cos_angle, h, ←neg_sub, norm_neg, neg_sub,\n    inner_sub_right, inner_sub_right, real_inner_self_eq_norm_sq,\n    real_inner_self_eq_norm_sq, 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 ≠ π) : ∥x∥ = ∥y∥ :=\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 [←norm_neg (y - x), neg_sub, mul_comm, mul_comm ∥y∥, div_eq_mul_inv, div_eq_mul_inv,\n        mul_inv_rev', mul_inv_rev', ←mul_assoc, ←mul_assoc] at h,\n    replace h :=\n      mul_right_cancel' (inv_ne_zero (λ 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_sq,\n        real_inner_self_eq_norm_sq, 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        ←mul_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 (λ hz, hx0 (norm_eq_zero.1 hz)) (λ hz, hy0 (norm_eq_zero.1 hz)),\n            ←neg_sub, ←mul_div_assoc, mul_comm, mul_div_assoc, ←mul_neg_one] at h,\n        symmetry,\n        by_contradiction hyx,\n        replace h := (mul_left_cancel' (sub_ne_zero_of_ne hyx) h).symm,\n        rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ←angle_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 ≠ 0) (hy : y ≠ 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 : ∥x∥ ≠ 0 := (λ h, hx (norm_eq_zero.1 h)),\n    have hyn : ∥y∥ ≠ 0 := (λ h, hy (norm_eq_zero.1 h)),\n    have hxyn : ∥x - y∥ ≠ 0 := (λ h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),\n    apply mul_right_cancel' hxn,\n    apply mul_right_cancel' hyn,\n    apply mul_right_cancel' hxyn,\n    apply mul_right_cancel' hxyn,\n    have H1 : real.sin (angle x (x - y)) * real.sin (angle y (y - x)) *\n                ∥x∥ * ∥y∥ * ∥x - y∥ * ∥x - y∥ =\n              (real.sin (angle x (x - y)) * (∥x∥ * ∥x - y∥)) *\n                (real.sin (angle y (y - x)) * (∥y∥ * ∥x - y∥)), { ring },\n    have H2 : ⟪x, x⟫ * (inner x x - inner x y - (inner x y - inner y y)) -\n                (inner x x - inner x y) * (inner x x - inner x y) =\n              inner x x * inner y y - inner x y * inner x y, { ring },\n    have H3 : ⟪y, y⟫ * (inner y y - inner x y - (inner x y - inner x x)) -\n                (inner y y - inner x y) * (inner y y - inner x y) =\n              inner x x * inner y y - inner x y * inner x y, { 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_sq, real_inner_self_eq_norm_sq,\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 ≠ 0) (hy : y ≠ 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 : ∥x∥ ≠ 0 := (λ h, hx (norm_eq_zero.1 h)),\n    have hyn : ∥y∥ ≠ 0 := (λ h, hy (norm_eq_zero.1 h)),\n    have hxyn : ∥x - y∥ ≠ 0 := (λ h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),\n    apply mul_right_cancel' hxn,\n    apply mul_right_cancel' hyn,\n    apply mul_right_cancel' hxyn,\n    apply mul_right_cancel' hxyn,\n    have H1 : real.sin (angle x (x - y)) * (⟪y, y - x⟫ / (∥y∥ * ∥y - x∥)) * ∥x∥ * ∥y∥ * ∥x - y∥ =\n                real.sin (angle x (x - y)) * (∥x∥ * ∥x - y∥) *\n                  (⟪y, y - x⟫ / (∥y∥ * ∥y - x∥)) * ∥y∥, { ring },\n    have H2 : ⟪x, x - y⟫ / (∥x∥ * ∥y - x∥) * real.sin (angle y (y - x)) * ∥x∥ * ∥y∥ * ∥y - x∥ =\n                ⟪x, x - y⟫ / (∥x∥ * ∥y - x∥) *\n                  (real.sin (angle y (y - x)) * (∥y∥ * ∥y - x∥)) * ∥x∥, { ring },\n    have H3 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) -\n                (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) =\n              ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫, { ring },\n    have H4 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) -\n                (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) =\n              ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫  * ⟪x, y⟫, { 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_sq,\n        real_inner_self_eq_norm_sq,\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 ≠ 0) (hy : y ≠ 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, ←neg_mul_eq_mul_neg, ←neg_add',\n       add_comm, ←sq, ←sq, 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 ≠ 0) (hy : y ≠ 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 ≠ 0) (hy : y ≠ 0) :\n  angle x y + angle x (x - y) + angle y (y - x) = π :=\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 ≤ 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) ≤ π + π + π :=\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) < π + π + π,\n  { by_contradiction hnlt,\n    have hxy : angle x y = π,\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 ⟨hx, ⟨r, ⟨hr, hxr⟩⟩⟩,\n    rw [hxr, ←one_smul ℝ x, ←mul_smul, mul_one, ←sub_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 π real.pi_pos)) _ },\n  have hn0 : 0 ≤ n,\n  { rw [hn, mul_nonneg_iff_right_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 π + π + π = 3 * π, 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*} [inner_product_space ℝ V] [metric_space P]\n    [normed_add_torsor V P]\ninclude V\n\n/-- Pythagorean theorem, if-and-only-if angle-at-point form. -/\nlemma dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two (p1 p2 p3 : P) :\n  dist p1 p3 * dist p1 p3 = dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 ↔\n    ∠ p1 p2 p3 = π / 2 :=\nby erw [pseudo_metric_space.dist_comm p3 p2, dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2,\n        dist_eq_norm_vsub V p2 p3,\n        ←norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two,\n        vsub_sub_vsub_cancel_right p1, ←neg_vsub_eq_vsub_rev p2 p3, norm_neg]\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 (∠ 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 -ᵥ p2 : V) (p3 -ᵥ 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\n/-- 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  ∠ p1 p2 p3 = ∠ 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 : ∠ p1 p2 p3 = ∠ p1 p3 p2)\n    (hpi : ∠ p2 p1 p3 ≠ π) : 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 [←angle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hpi,\n  rw [←vsub_sub_vsub_cancel_left p3 p2 p1, ←vsub_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 possibly degenerate triangle (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 ≠ p1) (h3 : p3 ≠ p1) :\n  ∠ p1 p2 p3 + ∠ p2 p3 p1 + ∠ p3 p1 p2 = π :=\nbegin\n  rw [add_assoc, add_comm, add_comm (∠ p2 p3 p1), angle_comm p2 p3 p1],\n  unfold angle,\n  rw [←angle_neg_neg (p1 -ᵥ p3), ←angle_neg_neg (p1 -ᵥ p2), neg_vsub_eq_vsub_rev,\n      neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev,\n      ←vsub_sub_vsub_cancel_right p3 p2 p1, ←vsub_sub_vsub_cancel_right p2 p3 p1],\n  exact angle_add_angle_sub_add_angle_sub_eq_pi (λ he, h3 (vsub_eq_zero_iff_eq.1 he))\n                                                (λ he, h2 (vsub_eq_zero_iff_eq.1 he))\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/triangle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.755877561055869}}
{"text": "import data.polynomial\nimport data.real.basic\nimport algebra.big_operators\n\nnoncomputable theory\nopen_locale big_operators\n\nopen polynomial\n\n-- The basic building block in the Lagrange polynomial\n-- this is (x - b)/(a - b)\ndef scaled_binomial (a b : ℝ) : polynomial ℝ :=\n((1 : ℝ) / (a - b)) • (X - C b)\n\n@[simp] lemma scaled_binomial.def (a b : ℝ) :\n  scaled_binomial a b = ((1 : ℝ) / (a - b)) • (X - C b) := rfl\n\nlemma bin_zero (a b : ℝ) : eval b (scaled_binomial a b) = 0 :=\nby rw [scaled_binomial.def, eval_smul, eval_sub, eval_X, eval_C, sub_self, smul_eq_mul, mul_zero]\n\nlemma bin_one (a b : ℝ) (h : a ≠ b) : eval a (scaled_binomial a b) = 1 :=\nby rw [scaled_binomial.def, eval_smul, eval_sub, eval_X, eval_C, smul_eq_mul,\n      div_mul_cancel 1 (sub_ne_zero_of_ne h)]\n\n-- This version, using scalar multiplication (`smul`) seems simplest.\n-- Must add hypothesis that data points are distinct\ndef lagrange_interpolant (n : ℕ) (i : ℕ) (xData : ℕ → ℝ) : polynomial ℝ :=\n∏ j in (finset.range (n+1)).erase i, scaled_binomial (xData i) (xData j)\n\n-- This has been PR'd into mathlib as `eval_prod`\nlemma eval_finset.prod {ι : Type*} (s : finset ι) (p : ι → polynomial ℝ) (x : ℝ) :\n  eval x (∏ j in s, p j) = ∏ j in s, eval x (p j) :=\n(finset.prod_hom _ _).symm\n\n\n-- The equivalent of the above for sums\nlemma eval_finset.sum {ι : Type*} (s : finset ι) (p : ι → polynomial ℝ) (x : ℝ) :\n  eval x (∑ j in s, p j) = ∑ j in s, eval x (p j) :=\n(finset.sum_hom _ _).symm\n\n-- The Lagrange interpolant `Lᵢ x` is one for `x = xData i`\n@[simp]\nlemma lagrange_interpolant_one (n : ℕ) (xData : ℕ → ℝ) (i : ℕ)\n  (hinj : function.injective xData) :\n  eval (xData i) (lagrange_interpolant n i xData) = (1:ℝ) :=\nbegin\n  unfold lagrange_interpolant,\n  rw eval_finset.prod,\n  --simp only [bin_one], -- simp fails because the simplifier can't derive `a ≠ b`\n  exact finset.prod_eq_one (λ j hj, bin_one (xData i) (xData j)\n    (mt (@hinj i j) (finset.ne_of_mem_erase hj).symm))\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/Interpolation/lagrange_v1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098192, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7558775587574823}}
{"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` (= `ℕ`): -/\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` (= `ℕ`):\n\n* \"No junk\" means that there are no special values, say, `–1` or `ε`, that\n  cannot be expressed using a finite combination of `zero` and `succ`.\n\n* \"No confusion\" is what ensures that `zero` ≠ `succ x`.\n\nIn addition, inductive types are always finite. `succ (succ (succ …))` 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    `∀k, P[k] → P[k + 1]`\n\nFor lists, the base case is\n\n    `P[[]]`\n\nand the induction step is\n\n    `∀y ys, P[ys] → 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 : ℕ) :\n  nat.succ n ≠ 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₂ (n : ℕ) :\n  nat.succ n ≠ 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 : ℕ → ℕ\n| 0       := 1\n| (n + 1) := (n + 1) * fact n\n\ndef fact₂ : ℕ → ℕ\n| 0       := 1\n| 1       := 1\n| (n + 1) := (n + 1) * fact₂ 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 : ℕ → ℕ\n| n := illegal n + 1\n\nconstant immoral : ℕ → ℕ\n\naxiom immoral_eq (n : ℕ) :\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₁_, …, _termM_ `with`\n    | _pattern₁₁_, …, _pattern₁M_ := _result₁_\n        ⋮\n    | _patternN₁_, …, _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 {α : Type} (p : α → bool) : list α → ℕ\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 : ℕ) : ℕ :=\nif a ≤ 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 : ℕ)\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 : ℕ → ℕ → ℕ → rgb\n\ndef rgb.red : rgb → ℕ\n| (rgb.mk r _ _) := r\n\ndef rgb.green : rgb → ℕ\n| (rgb.mk _ g _) := g\n\ndef rgb.blue : rgb → ℕ\n| (rgb.mk _ _ b) := b\n\nend rgb_as_inductive\n\nstructure rgba extends rgb :=\n(alpha : ℕ)\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₂ (c : rgb) :\n  shuffle (shuffle (shuffle c)) = c :=\nmatch c with\n| rgb.mk _ _ _ := 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 ℕ :=\n{ default := 0 }\n\n@[instance] def list.inhabited {α : Type} :\n  inhabited (list α) :=\n{ default := [] }\n\n#eval inhabited.default ℕ          -- result: 0\n#eval inhabited.default (list ℤ)   -- result: []\n\ndef head {α : Type} [inhabited α] : list α → α\n| []       := inhabited.default α\n| (x :: _) := x\n\nlemma head_head {α : Type} [inhabited α] (xs : list α) :\n  head [head xs] = head xs :=\nbegin\n  cases' xs,\n  { refl },\n  { refl }\nend\n\n#eval head ([] : list ℕ)   -- result: 0\n\n#check list.head\n\n@[instance] def fun.inhabited {α β : Type} [inhabited β] :\n  inhabited (α → β) :=\n{ default := λa : α, inhabited.default β }\n\ninductive empty : Type\n\n@[instance] def fun_empty.inhabited {β : Type} :\n  inhabited (empty → β) :=\n{ default := λa : empty, match a with end }\n\n@[instance] def prod.inhabited {α β : Type}\n    [inhabited α] [inhabited β] :\n  inhabited (α × β) :=\n{ default := (inhabited.default α, inhabited.default β) }\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 : ℕ)\n#check (1 : ℤ)\n#check (1 : ℝ)\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 {α : Type} (x y : α) (xs ys : list α)\n    (h : list.cons x xs = list.cons y ys) :\n  x = y ∧ 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 {α : Type} (y : α) (ys : list α)\n    (h : [] = y :: ys) :\n  false :=\nby cases' h\n\ndef map {α β : Type} (f : α → β) : list α → list β\n| []        := []\n| (x :: xs) := f x :: map xs\n\ndef map₂ {α β : Type} : (α → β) → list α → list β\n| _ []        := []\n| f (x :: xs) := f x :: map₂ f xs\n\n#check list.map\n\nlemma map_ident {α : Type} (xs : list α) :\n  map (λx, 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 {α β γ : Type} (f : α → β) (g : β → γ)\n    (xs : list α) :\n  map g (map f xs) = map (λx, 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 {α β : Type} (f : α → β) (xs ys : list α) :\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 {α : Type} : list α → list α\n| []        := []\n| (_ :: xs) := xs\n\n#check list.tail\n\ndef head_opt {α : Type} : list α → option α\n| []       := option.none\n| (x :: _) := option.some x\n\ndef head_pre {α : Type} : ∀xs : list α, xs ≠ [] → α\n| []       hxs := by cc\n| (x :: _) _   := x\n\n#eval head_opt [3, 1, 4]\n#eval head_pre [3, 1, 4] (by simp)\n-- fails\n#eval head_pre ([] : list ℕ) sorry\n\ndef zip {α β : Type} : list α → list β → list (α × β)\n| (x :: xs) (y :: ys) := (x, y) :: zip xs ys\n| []        _         := []\n| (_ :: _)  []        := []\n\n#check list.zip\n\ndef length {α : Type} : list α → ℕ\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 : ℕ) :\n  min (m + l) (n + l) = min m n + l :=\nbegin\n  cases' classical.em (m ≤ n),\n  case inl {\n    simp [min, h] },\n  case inr {\n    simp [min, h] }\nend\n\nlemma min_add_add₂ (l m n : ℕ) :\n  min (m + l) (n + l) = min m n + l :=\nmatch classical.em (m ≤ n) with\n| or.inl h := by simp [min, h]\n| or.inr h := by simp [min, h]\nend\n\nlemma min_add_add₃ (l m n : ℕ) :\n  min (m + l) (n + l) = min m n + l :=\nif h : m ≤ n then\n  by simp [min, h]\nelse\n  by simp [min, h]\n\nlemma length_zip {α β : Type} (xs : list α) (ys : list β) :\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 {α α' β β' : Type} (f : α → α') (g : β → β') :\n  ∀xs ys,\n    map (λab : α × β, (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 (α : Type) : Type\n| empty {} : btree\n| node     : α → btree → btree → 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 {α : Type} : btree α → btree α\n| btree.empty        := btree.empty\n| (btree.node a l r) := btree.node a (mirror r) (mirror l)\n\nlemma mirror_mirror {α : Type} (t : btree α) :\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₂ {α : Type} :\n  ∀t : btree α, 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₂ l\n  ... = btree.node a l r :\n    by rw mirror_mirror₂ r\n\nlemma mirror_eq_empty_iff {α : Type} :\n  ∀t : btree α, mirror t = btree.empty ↔ 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 (α : Type) : ℕ → Type\n| nil {}                           : vec 0\n| cons (a : α) {n : ℕ} (v : vec n) : vec (n + 1)\n\n#check vec.nil\n#check vec.cons\n\ndef list_of_vec {α : Type} : ∀{n : ℕ}, vec α n → list α\n| _ vec.nil        := []\n| _ (vec.cons a v) := a :: list_of_vec v\n\ndef vec_of_list {α : Type} :\n  ∀xs : list α, vec α (list.length xs)\n| []        := vec.nil\n| (x :: xs) := vec.cons x (vec_of_list xs)\n\nlemma length_list_of_vec {α : Type} :\n  ∀{n : ℕ} (v : vec α 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_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/love04_functional_programming_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045817875225, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7558564227030984}}
{"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\nPorted by: Scott Morrison\n\n! This file was ported from Lean 3 source module algebra.order.ring.canonical\n! leanprover-community/mathlib commit 824f9ae93a4f5174d2ea948e2d75843dd83447bb\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.Defs\nimport Mathlib.Algebra.Order.Sub.Canonical\nimport Mathlib.GroupTheory.GroupAction.Defs\n\n/-!\n# Canoncially ordered rings and semirings.\n\n* `CanonicallyOrderedCommSemiring`\n  - `CanonicallyOrderedAddMonoid` & multiplication & `*` respects `≤` & no zero divisors\n  - `CommSemiring` & `a ≤ b ↔ ∃ c, b = a + c` & no zero divisors\n\n## TODO\n\nWe're still missing some typeclasses, like\n* `CanonicallyOrderedSemiring`\nThey have yet to come up in practice.\n-/\n\n\nopen Function\n\nuniverse u\n\nvariable {α : Type u} {β : Type _}\n\n/-- A canonically ordered commutative semiring is an ordered, commutative semiring in which `a ≤ 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. -/\nclass CanonicallyOrderedCommSemiring (α : Type _) extends CanonicallyOrderedAddMonoid α,\n    CommSemiring α where\n  /-- No zero divisors. -/\n  protected eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : α}, a * b = 0 → a = 0 ∨ b = 0\n#align canonically_ordered_comm_semiring CanonicallyOrderedCommSemiring\n\nsection StrictOrderedSemiring\n\nvariable [StrictOrderedSemiring α] {a b c d : α}\n\nsection ExistsAddOfLE\n\nvariable [ExistsAddOfLE α]\n\n/-- Binary **rearrangement inequality**. -/\ntheorem mul_add_mul_le_mul_add_mul (hab : a ≤ b) (hcd : c ≤ d) : a * d + b * c ≤ a * c + b * d := by\n  obtain ⟨b, rfl⟩ := exists_add_of_le hab\n  obtain ⟨d, rfl⟩ := exists_add_of_le hcd\n  rw [mul_add, add_right_comm, mul_add, ← add_assoc]\n  exact add_le_add_left (mul_le_mul_of_nonneg_right hab <| (le_add_iff_nonneg_right _).1 hcd) _\n#align mul_add_mul_le_mul_add_mul mul_add_mul_le_mul_add_mul\n\n/-- Binary **rearrangement inequality**. -/\ntheorem mul_add_mul_le_mul_add_mul' (hba : b ≤ a) (hdc : d ≤ c) :\n    a • d + b • c ≤ a • c + b • d := by\n  rw [add_comm (a • d), add_comm (a • c)]\n  exact mul_add_mul_le_mul_add_mul hba hdc\n#align mul_add_mul_le_mul_add_mul' mul_add_mul_le_mul_add_mul'\n\n/-- Binary strict **rearrangement inequality**. -/\ntheorem mul_add_mul_lt_mul_add_mul (hab : a < b) (hcd : c < d) : a * d + b * c < a * c + b * d := by\n  obtain ⟨b, rfl⟩ := exists_add_of_le hab.le\n  obtain ⟨d, rfl⟩ := exists_add_of_le hcd.le\n  rw [mul_add, add_right_comm, mul_add, ← add_assoc]\n  exact add_lt_add_left (mul_lt_mul_of_pos_right hab <| (lt_add_iff_pos_right _).1 hcd) _\n#align mul_add_mul_lt_mul_add_mul mul_add_mul_lt_mul_add_mul\n\n/-- Binary **rearrangement inequality**. -/\ntheorem mul_add_mul_lt_mul_add_mul' (hba : b < a) (hdc : d < c) :\n    a • d + b • c < a • c + b • d := by\n  rw [add_comm (a • d), add_comm (a • c)]\n  exact mul_add_mul_lt_mul_add_mul hba hdc\n#align mul_add_mul_lt_mul_add_mul' mul_add_mul_lt_mul_add_mul'\n\nend ExistsAddOfLE\n\nend StrictOrderedSemiring\n\nnamespace CanonicallyOrderedCommSemiring\n\nvariable [CanonicallyOrderedCommSemiring α] {a b : α}\n\n-- see Note [lower instance priority]\ninstance (priority := 100) toNoZeroDivisors : NoZeroDivisors α :=\n  ⟨CanonicallyOrderedCommSemiring.eq_zero_or_eq_zero_of_mul_eq_zero⟩\n#align canonically_ordered_comm_semiring.to_no_zero_divisors CanonicallyOrderedCommSemiring.toNoZeroDivisors\n\n-- see Note [lower instance priority]\ninstance (priority := 100) toCovariantClassMulLE : CovariantClass α α (· * ·) (· ≤ ·) := by\n  refine' ⟨fun a b c h => _⟩\n  rcases exists_add_of_le h with ⟨c, rfl⟩\n  rw [mul_add]\n  apply self_le_add_right\n#align canonically_ordered_comm_semiring.to_covariant_mul_le CanonicallyOrderedCommSemiring.toCovariantClassMulLE\n\n-- see Note [lower instance priority]\ninstance (priority := 100) toOrderedCommMonoid : OrderedCommMonoid α where\n  mul_le_mul_left := fun _ _ => mul_le_mul_left'\n#align canonically_ordered_comm_semiring.to_ordered_comm_monoid CanonicallyOrderedCommSemiring.toOrderedCommMonoid\n\n-- see Note [lower instance priority]\ninstance (priority := 100) toOrderedCommSemiring : OrderedCommSemiring α :=\n  { ‹CanonicallyOrderedCommSemiring α› with\n    zero_le_one := zero_le _,\n    mul_le_mul_of_nonneg_left := fun a b c h _ => mul_le_mul_left' h _,\n    mul_le_mul_of_nonneg_right := fun a b c h _ => mul_le_mul_right' h _ }\n#align canonically_ordered_comm_semiring.to_ordered_comm_semiring CanonicallyOrderedCommSemiring.toOrderedCommSemiring\n\n@[simp]\ntheorem mul_pos : 0 < a * b ↔ 0 < a ∧ 0 < b := by\n  simp only [pos_iff_ne_zero, ne_eq, mul_eq_zero, not_or]\n#align canonically_ordered_comm_semiring.mul_pos CanonicallyOrderedCommSemiring.mul_pos\n\nend CanonicallyOrderedCommSemiring\n\nsection Sub\n\nvariable [CanonicallyOrderedCommSemiring α] {a b c : α}\n\nvariable [Sub α] [OrderedSub α]\n\nvariable [IsTotal α (· ≤ ·)]\n\nnamespace AddLECancellable\n\nprotected theorem mul_tsub (h : AddLECancellable (a * c)) : a * (b - c) = a * b - a * c := by\n  cases' total_of (· ≤ ·) 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\n    rw [← mul_add, tsub_add_cancel_of_le hcb]\n#align add_le_cancellable.mul_tsub AddLECancellable.mul_tsub\n\nprotected theorem tsub_mul (h : AddLECancellable (b * c)) : (a - b) * c = a * c - b * c := by\n  simp only [mul_comm _ c] at *\n  exact h.mul_tsub\n#align add_le_cancellable.tsub_mul AddLECancellable.tsub_mul\n\nend AddLECancellable\n\nvariable [ContravariantClass α α (· + ·) (· ≤ ·)]\n\ntheorem mul_tsub (a b c : α) : a * (b - c) = a * b - a * c :=\n  Contravariant.AddLECancellable.mul_tsub\n#align mul_tsub mul_tsub\n\ntheorem tsub_mul (a b c : α) : (a - b) * c = a * c - b * c :=\n  Contravariant.AddLECancellable.tsub_mul\n#align tsub_mul tsub_mul\n\nend Sub\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/Ring/Canonical.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181417, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7558206203175415}}
{"text": "import MyNat.Addition -- imports addition.\nnamespace MyNat\nopen MyNat\n/-!\n# Addition world\n\n## Level 2: `add_assoc` -- associativity of addition.\n\nIt's well-known that (1 + 2) + 3 = 1 + (2 + 3) -- if you have three numbers\nto add up, it doesn't matter which of the additions you 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\nTo prove associativity of addition it is handy to recall that addition was defined\nby recursion on the right-most variable. This means you can 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 explicitly.\n\nReminder: you are done when you see \"Goals accomplished 🎉\" in the InfoView, and no\nerrors in the VS Code Problems list.\n\n**Lemma**\n\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-/\n\nlemma add_assoc (a b c : MyNat) : (a + b) + c = a + (b + c) := by\n  induction c with\n  | zero =>\n    -- ⊢ a + b + 0 = a + (b + 0)\n    rw [zero_is_0]\n    rw [add_zero]\n    rw [add_zero]\n  | succ c ih =>\n    -- ⊢ (a + b) + succ d = a + (b + succ d)\n    rw [add_succ]\n    rw [add_succ]\n    rw [add_succ]\n    rw [ih]\n\n/-!\nOn to [Level 3](./Level3.lean.md).\n-/\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/AdditionWorld/Level2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062238, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7557337435112947}}
{"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.p_series\nimport number_theory.arithmetic_function\nimport topology.algebra.infinite_sum\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 `ζ`\n  (whose analytic continuation is the Riemann ζ) 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 ℂ) (z : ℂ) : ℂ := ∑'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 ℂ) (z : ℂ) : Prop := summable (λ n, (f n) / (n ^ z))\n\nlemma l_series_eq_zero_of_not_l_series_summable (f : arithmetic_function ℂ) (z : ℂ) :\n  ¬ f.l_series_summable z → f.l_series z = 0 :=\ntsum_eq_zero_of_not_summable\n\n@[simp]\nlemma l_series_summable_zero {z : ℂ} : 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 ℂ} {m : ℝ}\n  (h : ∀ (n : ℕ), complex.abs (f n) ≤ m) {z : ℝ} (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 (λ n, complex.abs_eq_zero.1\n        (le_antisymm (h n) (complex.abs_nonneg _))),\n    simp [hf] },\n  refine summable_of_norm_bounded (λ (n : ℕ), m / (n ^ z)) _ _,\n  { simp_rw [div_eq_mul_inv],\n    exact (summable_mul_left_iff h0).1 (real.summable_nat_rpow_inv.2 hz) },\n  { intro n,\n    have hm : 0 ≤ 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 [complex.abs_div, 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 ℂ} {m : ℝ}\n  (h : ∀ (n : ℕ), complex.abs (f n) ≤ m) {z : ℂ} (hz : 1 < z.re) :\n  f.l_series_summable z :=\nbegin\n  rw ← 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 : ℂ} :\n  l_series_summable ζ z ↔ 1 < z.re :=\nbegin\n  rw [← l_series_summable_iff_of_re_eq_re (complex.of_real_re z.re), l_series_summable,\n    ← summable_norm_iff, ← real.summable_one_div_nat_rpow, iff_iff_eq],\n  by_cases h0 : z.re = 0,\n  { rw [h0, ← 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 n,\n    cases n, { simp [h0] },\n    simp only [n.succ_ne_zero, one_div, cast_one, nat_coe_apply, complex.abs_cpow_real, inv_inj₀,\n      complex.abs_inv, if_false, zeta_apply, complex.norm_eq_abs, complex.abs_of_nat] }\nend\n\n@[simp] theorem l_series_add {f g : arithmetic_function ℂ} {z : ℂ}\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 ← tsum_add hf hg,\n  apply congr rfl (funext (λ n, _)),\n  apply _root_.add_div,\nend\n\nend arithmetic_function\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/l_series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7557029149694194}}
{"text": "import Mathlib\nimport PnP2023.Lec_02_03.InductiveTypes\n\n/-!\nVectors, i.e., lists of a fixed length, can be defined in (at least) two ways. One way is as an indexed inductive type `Vec`, as we saw in lecture and is in the file `InductiveTypes.lean`. \n\nA different definition is as a subtype `Vector` of lists consisting of those of a fixed length. This is the definition used in `mathlib` and is recalled below.\n\n```lean\n/-- `Vector α n` is the type of lists of length `n` with elements of type `α`. -/\ndef Vector (α : Type u) (n : ℕ) :=\n  { l : List α // l.length = n }\n```\n\nIn this lab, you will relate the two definitions by constructing functions that convert between the two definitions and prove that these functions are inverses of each other.\n-/\nuniverse u\n\n/-- Convert a `Vector` to a `Vec` -/\ndef Vec.ofVector {α : Type u}: (n : ℕ) →  Vector α n → Vec α n \n| 0, _ => Vec.nil\n| k + 1, Vector.cons head tail => by\n  \n\n/-- Convert a `Vec` to a `Vector` \ndef Vec.toVector {α : Type u}: (n : ℕ) →  Vec α n → Vector α n\n| _, _ => sorry --/\n\ndef vector1 : Vector ℕ 1 := ⟨ [2] , rfl ⟩\ndef vector0 : Vector ℕ 0 := ⟨ [], rfl ⟩ \n\n#eval vector1\n\n\n\n\n/-- Convert a `Vec` to a `Vector` -/\ndef Vec.toVector {α : Type u}: (n : ℕ) →  Vec α n → Vector α n\n| 0, _ => ⟨ [], rfl ⟩\n| k + 1, Vec.cons head tail => by\n  let vectorTail : Vector α k := Vec.toVector k tail\n  let ⟨a, b⟩ := vectorTail\n  have lem5 : (head :: a).length = k + 1 := by\n    simp [List.length, b]\n  let vec3 : Vector α (k+1) := ⟨head :: a, lem5⟩\n  assumption\n\n\n\n\n\n/--  Vec.to_list {α : Type u} {n : ℕ} : Vec α n → List α\n| Vec.nil => []\n| Vec.cons head tail => head :: tail.to_list\n-/\n\n\n\n\n-- Mapping a `Vec` to a `Vector` and back gives the original `Vec` -/\ntheorem Vec.ofVector.toVector {α : Type u} (n : ℕ) (v : Vec α n) :\n  Vec.ofVector n (Vec.toVector n v) = v := sorry\n\n/-- Mapping a `Vector` to a `Vec` and back gives the original `Vector` -/\ntheorem Vec.toVector.ofVector {α : Type u} (n : ℕ) (v : Vector α n) :\n  Vec.toVector n (Vec.ofVector n v) = v := sorry", "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/VecVector.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7557029139236228}}
{"text": "import mynat.definition -- hide\nimport mynat.add -- hide\nimport game.world8.level8 -- hide\nnamespace mynat -- hide\n\n/- Axiom : zero_ne_succ (a : mynat) :\n0 ≠ succ(a)\n-/\n\n/- Tactic : symmetry\n\n## Summary\n\n`symmetry` turns goals of the form `⊢ A = B` to `⊢ B = A`.\nAlso works with `≠`. Also works on hypotheses: if `h : a ≠ b`\nthen `symmetry at h` gives `h : b ≠ a`.\n\n## Details\n\n`symmetry` works on both goals and hypotheses. By default it\nworks on the goal. It will turn a goal of the form `⊢ A = B`\nto `⊢ B = A`. More generally it will work with any symmetric\nbinary relation (for example `≠`, or more generally any\nbinary relation whose proof of symmetry has been tagged\nwith the `symm` attribute).\n\nTo get `symmetry` working on a hypothesis, use `symmetry at h`.\n\n## Examples\n\nIf the tactic state is\n```\nh : a = b\n⊢ c ≠ d\n```\n\nthen `symmetry` changes the goal to `⊢ d ≠ c` and\n`symmetry at h` changes `h` to `h : b = a`.\n-/\n\n/-\n\n# Advanced Addition World\n\n## Level 9: `succ_ne_zero`\n\nLevels 9 to 13 introduce the last axiom of Peano, namely\nthat $0\\not=\\operatorname{succ}(a)$. The proof of this is called `zero_ne_succ a`. \n\n`zero_ne_succ (a : mynat) : 0 ≠ succ(a)`\n\nThe `symmetry` tactic will turn any goal of the form `R x y` into `R y x`,\nif `R` is a symmetric binary relation (for example `=` or `≠`).\nIn particular, you can prove `succ_ne_zero` below by first using\n`symmetry` and then `exact zero_ne_succ a`. \n-/\n\n/- Theorem\nZero is not the successor of any natural number.\n-/\ntheorem succ_ne_zero (a : mynat) : succ a ≠ 0 := \nbegin [nat_num_game]\n  symmetry,\n  exact zero_ne_succ a,\n\n\nend\n\nend mynat\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/level9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695283896349, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7557029080571909}}
{"text": "/-\nCopyright (c) 2018 Luca Gerolla. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Luca Gerolla, Kevin Buzzard\nProve basic results of real continuous functions and closed intervals\n-/\nimport analysis.topology.continuity\nimport analysis.topology.topological_space\nimport analysis.topology.infinite_sum\nimport analysis.topology.topological_structures\nimport analysis.topology.uniform_space\nimport analysis.real\nimport data.real.basic tactic.norm_num\nimport data.set.basic\n\nuniverse u\n\nopen set filter lattice classical\n\nnoncomputable theory \n\n\n-- Useful continuity results for functions ℝ → ℝ\n\ntheorem real.continuous_add_const (r : ℝ) : continuous (λ x : ℝ, x + r) :=\nbegin\n  have H₁ : continuous (λ x, (x,r) : ℝ → ℝ × ℝ),\n    exact continuous.prod_mk continuous_id continuous_const,\n  exact continuous.comp H₁ continuous_add', \nend \n\ntheorem real.continuous_sub_const (r : ℝ) : continuous (λ x : ℝ, x - r) := \ncontinuous_sub continuous_id continuous_const \n\n\ntheorem real.continuous_mul_const (r : ℝ) : continuous (λ x : ℝ, r*x) :=\nbegin \n  have H₁ : continuous (λ x, (r,x) : ℝ → ℝ × ℝ),\n    exact continuous.prod_mk continuous_const continuous_id,\n  show continuous ( (λ p : ℝ × ℝ , p.1 * p.2)  ∘  (λ (x : ℝ), (r,x))), \n  refine continuous.comp H₁  continuous_mul' , \nend \n\ntheorem real.continuous_mul_const_right (r : ℝ) : continuous (λ x : ℝ, x*r) :=\nbegin \n  have H₁ : continuous (λ x, (x,r) : ℝ → ℝ × ℝ),\n    exact continuous.prod_mk continuous_id continuous_const,\n  refine continuous.comp H₁ continuous_mul' , \nend\n\n\ntheorem real.continuous_div_const (r : ℝ) : continuous (λ x : ℝ, x / r) :=\nbegin\n  conv in (_ / r) begin\n    rw div_eq_mul_inv,\n  end,\n  have H₁ : continuous (λ x, (x,r⁻¹) : ℝ → ℝ × ℝ),\n    exact continuous.prod_mk continuous_id continuous_const,\n  exact continuous.comp H₁ continuous_mul', \nend \n\n\ntheorem real.continuous_scale (a b : ℝ) : continuous (λ x : ℝ, (x + a) / b) := \n  continuous.comp (real.continuous_add_const a) (real.continuous_div_const b)\n\n\ntheorem real.continuous_linear (m q : ℝ) : continuous (λ x : ℝ, m * x + q) :=\n  continuous.comp (real.continuous_mul_const m) (real.continuous_add_const q)\n\n\n\n--- Definition of closed intervals in ℝ \n                                                                                                 \ndef int_clos { r s : ℝ } ( Hrs : r < s ) : set ℝ := {x : ℝ  | r ≤ x ∧ x ≤ s}\n\n\ntheorem is_closed_int_clos { r s : ℝ } ( Hrs : r < s ) : is_closed (int_clos Hrs) := \n  is_closed_inter (is_closed_ge' r) (is_closed_le' s) \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/real_results.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7556883386310446}}
{"text": "def is_even (x: ℕ) : bool := x % 2 = 0\ndef positive (n: ℕ) : bool := n > 0\ndef uint32 (n: ℕ) : bool := n >= 0 ∧ n < 2^32\n\ndef positive' : ℕ → bool := λ n, n > 0 \n#check positive'\n#check λ n : ℕ, n > 0 \n#reduce is_even 1\n#reduce positive 0\n\ntheorem ttt {a b : ℕ}: a=b→ b=a := λ f, eq.symm f\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/lessons/lesson4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966747198241, "lm_q2_score": 0.7981867777396212, "lm_q1q2_score": 0.7555609496136567}}
{"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\n-- import tactic -- imports all the Lean tactics\nimport Std.Tactic.Basic -- imports by_contra\nimport Mathlib.Tactic.Basic -- imports change, by_cases\n\n/-!\n\n# Logic in Lean, example sheet 3 : \"not\" (`¬`)\n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# Important : the definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → False`. So `¬ P` and `P → 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\nvariable (P Q R : Prop)\n\nexample : ¬ True → False := by\n  sorry \n\nexample : False → ¬ True := by\n  sorry\n\nexample : ¬ False → True := by\n  sorry\n\nexample : True → ¬ False := by\n  sorry\n\nexample : False → ¬ P := by\n  sorry\n\nexample : P → ¬ P → False := by\n  sorry\n\nexample : P → ¬ (¬ P) := by\n  sorry\n\nexample : (P → Q) → (¬ Q → ¬ P) := by\n  sorry\n\nexample : ¬ ¬ False → False := by\n  sorry\n\nexample : ¬ ¬ P → P := by\n  sorry\n\nexample : (¬ Q → ¬ P) → (P → Q) := by\n  sorry\n\n", "meta": {"author": "UofSC-Spring-2023-Math-768-001", "repo": "formalizing-mathematics-lean4", "sha": "38783ca5d1c81db4cc59c04474aefb18c181bff6", "save_path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalizing-mathematics-lean4", "path": "github-repos/lean/UofSC-Spring-2023-Math-768-001-formalizing-mathematics-lean4/formalizing-mathematics-lean4-38783ca5d1c81db4cc59c04474aefb18c181bff6/Fm4/Sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.924141826246517, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7555547674682694}}
{"text": "-- based on Lean Tutorial / 05_sequence_limits.lean\nimport resources\n\n/- \nUseful lemmata:\n\n`le_max_left  p q` says `p ≤ max p q`\n`le_max_right p q` says `q ≤ max p q`\n\n`eq_of_abs_sub_le_all_pos x y` says `(∀ ε > 0, |x - y| ≤ ε) → x = y`\n-/\n\n-- This is the definition of limit we will work with in all exercises here.\ndef seq_limit (s : ℕ → ℝ) (a : ℝ) : Prop :=\n∀ ε : ℝ, ε > 0 → ∃ n₀ : ℕ, ∀ n : ℕ, n ≥ n₀ → |s n - a| ≤ ε\n\n\n-- Arithmetic of limits ... the sum law:\n-- If [`u` approaches `a`] and [`v` approaches `b`],\n-- then [`u + v` approaches `a + b`].\nexample (u v : ℕ → ℝ) (a b : ℝ) (hu : seq_limit u a) (hv : seq_limit v b) :\n  seq_limit (u + v) (a + b) :=\nbegin\n  sorry,\nend\n\n-- Squeeze theorem (a.k.a. \"Sandwich rule\" or \"Two policemen and a drunk\"):\n-- If [`u` approaches `z`] and [`v` approaches `z`],\n-- then [`w` such that `u ≤ w ≤ v` approaches `z` as well].\nexample (u v w : ℕ → ℝ) (z : ℝ) (hu : seq_limit u z) (hv : seq_limit v z)\n        (below : ∀ n, u n ≤ w n) (above : ∀ n, w n ≤ v n) :\n  seq_limit w z :=\nbegin\n  sorry,\nend\n\n-- A sequence admits at most one limit.\nexample (w : ℕ → ℝ) (a b : ℝ) (ha : seq_limit w a) (hb : seq_limit w b) :\n  a = b :=\nbegin\n  sorry,\nend\n", "meta": {"author": "madvorak", "repo": "lean-showcase", "sha": "d405796deef7a7903befa438d5d7ac2873960a98", "save_path": "github-repos/lean/madvorak-lean-showcase", "path": "github-repos/lean/madvorak-lean-showcase/lean-showcase-d405796deef7a7903befa438d5d7ac2873960a98/src/sequence_limits.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7555547544741962}}
{"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 section14polynomials.sheet02noetherian\n\n/-!\n\n# An auxiliary construction\n\nI haven't talked about which proof of the Hilbert Basis Theorem we'll\nbe formalising, so let me say a bit about this here. The theorem\nstates that if `R` is a Noetherian (commutative) ring then so is\nthe polynomial ring `R[X]`. So, given an ideal `I` of `R[X]` we need\nto come up with a finite set of generators, and the only tool we have\nis that any ideal of `R` has a finite set of generators. So, however\nthis proof goes, we are going to probably be wanting to construct\nideals of `R` given an ideal of `R[X]`. \n\nThe `aux_ideal` construction is of this nature. An ideal of `R[X]`\nis by definition an `R[X]`-submodule of `R[X]` so it's also\nan `R`-submodule of `R[X]` (this is a bit like saying that a complex\nvector space is obviously also a real vector space). The `lcoeff`\nmaps, taking a polynomial to its coefficient of `X^n`,  are `R`-linear\nmaps from `R[X]` to `R`, so we can push `R`-submodules of `R[X]` along\nthese maps (i.e. look at their images) to get `R`-submodules of `R`,\nwhich is the same thing as ideals of `R`. The submodules we will push\nforward are the following: given an ideal `I` of `R[X]`, and a natural\nnumber `n`, we will consider `I` as an `R`-submodule of `R[X]`, we will\nintersect it with `M R n` (the `R`-submodule of polynomials of degree\nat most `n`), and we will then look at its image under `lcoeff R n`.\nBy definition then, the elements of `aux_ideal I n` will be the\ncoeficients of `X^n` of the polynomials in `I` which have degree\nat most `n`, and this abstract way of describing this set shows that\nit is an ideal of `R`.\n\nAgain, more briefly: if `I` is an ideal of `R[X]` and `n` is a natural,\nthen `aux_ideal I n` is the ideal of `R` consisting of the coefficients\nof `X^n` of the elements of `I` with `nat_degree` at most `n`. \n\nThe first result we are aiming for in this file is that\n`aux_ideal I n` is monotone as a function of `n`, that is, if `n ≤ m`\nthen `aux_ideal I n ≤ aux_ideal I m`.\n\n-/\n\nvariables {R : Type} [comm_ring R] (I : ideal (polynomial R))\n\nopen polynomial\n\n/-\n\n`I.restrict_scalars R` means the ideal `I`, regarded as an `R`-submodule\nof `R[X]`. The `⊓` is just intersection of submodules. The `map`\nis `submodule.map` which is the function which eats a linear map\n(in this case `lcoeff R n`) and outputs a function sending submodules\nof the domain of the map to submodules of the codomain; the function\nitself is just \"image of the submodule under the linear map\".\n\n-/\n\n/-- If `I` is an ideal of `polynomial R` then `aux_ideal I n` is the ideal of `R`\nobtained by pushing forward `I ∩ {polynomials of degree ≤ n}` along the linear map `lcoeff n`\nsending a polynomial to its coefficient of `X^n`. \n\nOne can imagine `aux_ideal I n` as the ideal consisting of `0` and the coefficient of `X^n`\nin all of the degree `n` polynomials in `I`, but this case split definition is harder\nto work with in practice. -/\nnoncomputable def aux_ideal (n : ℕ) :=\n(I.restrict_scalars R ⊓ M R n).map (lcoeff R n)\n\nnamespace aux_ideal\n\n/-\n\nWe're going to prove that `aux_ideal I n` is monotone for fixed `I`, i.e. it gets \nbigger as `n` gets bigger. \n\nMake sure you know a maths proof before embarking on this.\n\nUseful API: \n\n`I.mul_mem_right r : p ∈ I → p * r ∈ I`\n`polynomial.nat_degree_mul_le : (p * q).nat_degree ≤ p.nat_degree + q.nat_degree`\n`p.coeff_mul_X : (n : ℕ), (p * X).coeff (n + 1) = p.coeff n`\n\nand note that `lcoeff R n f` is definitionally `f.coeff n`.\n\n-/\n\nlemma mono_aux (n : ℕ) :\n  aux_ideal I n ≤ aux_ideal I (n + 1) :=\nbegin\n  sorry,\nend\n\n-- this is now a one-liner\nlemma mono : monotone (aux_ideal I) :=\nbegin\n  sorry\nend\n\n/- Given an ideal `I` and a natural number `n`, we have been\nconsidering the map from `I ∩ {degree ≤ n}` to `R` defined by\n\"take coefficient of `X^n`\". The `lift` function below is\na one-sided inverse to this map. Given an element of `R`,\nif it's in the image then we send it to a random preimage\nin `I ∩ (degree ≤ n)` and if it's not then we just send it to 0.\nNote the use of `exists.some`; the statement \"I am in the image\"\nis definitionally equal to \"there exists something in the domain\nwhich maps to me\", and `exists.some` chooses a random thing in the\nimage with this property.\n\n-/\n\nnoncomputable def lift (n : ℕ) (r : R) [decidable (r ∈ aux_ideal I n)] : polynomial R :=\nif hr : r ∈ aux_ideal I n then (submodule.mem_map.1 hr).some else 0\n\nvariables {n : ℕ} {r : R} [decidable (r ∈ aux_ideal I n)]\n\nlemma lift_def (n : ℕ) (r : R) [decidable (r ∈ aux_ideal I n)] : \nlift I n r = if hr : r ∈ aux_ideal I n then (submodule.mem_map.1 hr).some else 0 :=\nbegin\n  sorry,\nend\n\nvariable {I}\n\n-- you can use `dif_neg` to prove this lemma.\nlemma lift_eq_zero_of_ne (hr : ¬ r ∈ aux_ideal I n) : lift I n r = 0 :=\nbegin\n  sorry,\nend\n\n-- you need to do a case split for this one. The definition of `lift`\n-- used ` (submodule.mem_map.1 hr).some` so this proof will need\n-- ` (submodule.mem_map.1 hr).some_spec` somewhere. Note also `dif_pos` :-)\nlemma lift_mem :\n  (lift I n r) ∈ submodule.restrict_scalars R I ⊓ M R n :=\nbegin\n  sorry,\nend\n\n-- this is a one-liner\nlemma lift_mem_I : lift I n r ∈ I :=\nbegin\n  sorry,\nend\n\n-- this is a one-liner too (thanks to definitional equality abuse)\nlemma lift_nat_degree_le :\n  (lift I n r).nat_degree ≤ n :=\nbegin\n  sorry,\nend\n\nlemma lift_spec (hr : r ∈ aux_ideal I n) :\n  lcoeff R n (lift I n r) = r :=\nbegin\n  sorry,\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/section14polynomials/sheet03aux_ideal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7555196517124407}}
{"text": "/-\n\nIn lean we represent: (1) propositions as\n\ntypes and (2) predicates as parameterized\n\npropositions.\n\n \n\nA parameterized type gives rise to a whole\n\nfamily of proposition, once for each value\n\nof each parameter.\n\n \n\nWe can think of one-parameter predicates \n\nas specifying *properties* of objects. As\n\nan example, as defined, is_even : ℕ → Prop\n\nexpresses the property of a natural number\n\n(an argument value) \"being even\". We define\n\nthe constructors to ensure that there is a\n\nproof of (is_even n) if and only if (n : ℕ)\n\nis (a term that represents) an even number.\n\n \n\nOne-parameter predicates thus also specify \n\n*sets* of objects: namely all and only those\n\nvalues of a given argument type that have the \n\nspecified property as shown by the existence\n\nof a proof that such a value \"satisfies the \n\npredicate\" (makes the resulting proposition\n\ntrue).\n\n \n\nThe is_even predicate thus specifies the\n\nset of all even natural numbers, which we\n\ncan write as {0, 2, 4, 6, ...} or, better,\n\nas { n : ℕ | is_even n }.\n\n \n\nWe can think of two-parameter predicates as \n\nspecifying binary relations, that is, sets of\n\n*pairs* of argument values that make a given\n\nproposition true.\n\n \n\nThe most commonplace example of a two-argument\n\npredicate is equals. We can write (_ = _) to \n\nmake it clear that equals takes two values and\n\nyields a proposition that the first equals the\n\nsecond. For example, if a and b are of type ℕ, \n\nthen (a = b) is a proposition that has a proof\n\nif and only if the two terms really are equal\n\n(when reduced). So, for example, 4 = 2 + 2 is\n\ntrue, there is a proof of it, because reducing\n\n2 + 2 to 4 reduces the whole proposition to \n\n4 = 4, and there is a proof of this proposition.\n\n \n\nThe proposition, a = b, in Lean is just a nice\n\nshorthand notation for (eq a b). The two-place\n\npredicate, eq, implements the equality relation. \n\nIt's polymorphic: it takes a *type parameter*, α,\n\nimplicitly. It then explicitly takes two values,\n\na and b, of type α, and yields the proposition, \n\na = b (which is of course itself a type).\n\n \n\nThe eq \"type builder\" (taking α and two values,\n\na and b of type α) and yielding the proposition\n\n(a type), a = b, provides a single constructor\n\nwith which to build proofs. It's called refl,\n\nand it establishes the \"reflexive\" property of\n\nthe eq relation, by taking *any* value, a : α,\n\nfor any type, α, and by returning a proof of\n\n(eq a a), that is, of a = a. So, by applying\n\neq.refl to any value, a, of any type, we get\n\na proof of (a = a), and those are the *only*\n\nproofs of equality that can be constructed.\n\nThere's thus no way to prove that 0 = 1, for\n\nexample, because those terms don't reduce to\n\nthe same values, and we can only use eq.refl\n\nto construct proofs that two terms are equal\n\nif they really do reduce to exactly the same\n\nvalue.\n\n \n\nFinally, we will represent some, but no all,\n\nof the logical connetives, including \"and\",\n\n\"or\", and \"iff\", as polymorphic propositions.\n\nWhereas a predicate, such as eq, will take\n\nvalues of arbitrary types as arguments (e.g.,\n\neq can take values of type ℕ), connectives\n\nare like polymorphic types: they take types\n\nas arguments, but in this case the types are\n\nof type Prop.\n\n \n\nConsider \"and\" for example. If P and Q are\n\nany two pre-existing propositions (types of\n\ntype Prop), then we can form the proposition,\n\nP ∧ Q, and it, too, will be a proposition (a\n\ntype of type, Prop). The type of \"and\" is thus\n\nProp → Prop → Prop: it takes two propositions\n\n(types of type Prop) as arguments and yields\n\na new proposition (a new type of type Prop).\n\n \n\nTo enforce the logical meaning of \"and\", we\n\ndefine the \"and\" type builder to have just\n\none constructor, which we call \"intro\", that\n\nif applied to a proof, p, of P and to a proof,\n\nq, of Q yields a term, (and.intro p q), that\n\nis axiomatically accepted as being a \"proof\"\n\nof (and P Q), which we write using an infix\n\nnotation as (P ∧ Q). \n\n \n\nFinally, we note that if we're given a term,\n\n(and.intro p q), of type (P ∧ Q), that is, if\n\nwe're given a proof of (P ∧ Q), we can get a\n\nproof of P from it, by \"destructuring\" the\n\nterm using pattern matching. For example, we\n\ncan obtain \"p\" (the proof of P \"contained \n\ninside\" the proof of P ∧ Q) with the following\n\nrule: | (and.intro p _) := p. This is how we\n\nimplement the two \"elimination rules\" for and.\n\n-/\n\n \n\n/-\n\nHere's a statement of the proposition that\n\n2 + 2 = 4 and a proof of it. \n\n-/\n\n \n\nlemma proof_of_two_plus_two_eq_four : 2 + 2 = 4 :=\n\n    eq.refl 4\n\n \n\n/-\n\n1. State and prove the proposition that the\n\nstring,\"Lean!\", appended to the string, \"Hello, \"\n\nis equal to the string, \"Hello, Lean!\". You may\n\nand should use the Lean library-provided string \n\nappend operator, ++, as an infix notation for \n\nappend.\n\n-/\n\n \n\n-- string append example\n\n#eval \"Hi \" ++ \"There!\"\n\n \n\n-- fill in the blanks\n\nlemma proof1 : ((\"Hi \"++ \"There!\") = \"Hi There!\") := eq.refl \"Hi There!\"\n\n/-\n\n2.  Sometimes we want to state and prove a \n\nproposition without binding a name to the proof.\n\nFor that, instead of using def, theorem, or\n\nlemma, we can use \"example.\" Here's an example. \n\n-/\n\n \n\nexample : 1 = 1 := eq.refl _    -- Fill blank with proof.\n\n \n\n/-\n\nNote that we can use example for ordinary types\n\nas well.\n\n-/\n\n \n\nexample : ℕ := 5\n\n \n\n/-\n\n2. State and prove the proposition that 3 * 4 = 12,\n\nusing \"example.\"\n\n-/\n\n \n\n-- Answer Here\nexample : 3*4 = 12 := eq.refl _\n\n \n\n/-\n\n3. Use example to formally state and prove the\n\nproposition that 1 = 1 ∧ 0 = 0. \n\n-/\n\n \n\n-- Here\nexample : 1 = 1 ∧ 0 = 0 :=\nbegin\n    apply and.intro,\n    apply eq.refl,\n    apply eq.refl\nend\n\n\n \n\n/-\n\n4. Complete the following program to show that\n\nif P and Q are arbitrary propositions, and *if* \n\nyou're given a proof of P and Q, then you can \n\nobtain and return a proof of P.\n\n \n\nHint: In Lean, and.intro is the one introduction\n\n(proof creating) rule for and, and and.elim_left\n\nand and.elim_right are the two elimination rules.\n\nThey are functions. Use one of them!\n\n-/\n\n \n\ntheorem P_and_Q_imp_P {P Q : Prop} (pq : P ∧ Q) : P :=\nbegin\n    apply and.elim_left pq,\nend", "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/quiz1_prep.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8577681068080748, "lm_q1q2_score": 0.7555196420591724}}
{"text": "import subgroup.basic\n\n/-\nLet G be a group. The type of subgroups of G is `subgroup G`. \nIn other words, if `H : subgroup G` then H is a subgroup of G. \nThe three basic facts you need to know about H are:\n\nH.one_mem : (1 : G) ∈ H\nH.mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H\nH.inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H\n\nSubgroups of a group form what is known as a *lattice*. \nThis is a partially ordered set with a sensible notion of\nmax and min (and even sup and inf). \n\nWe will prove this here.\n-/\n\nopen_locale classical\n\nnamespace mygroup\n\nopen group set\n\nvariables {G : Type} [group G]\nvariables {H K : subgroup G}\n\nnamespace subgroup\n\n-- The intersect of two subgroups is also a subgroup\ndef inf (H K : subgroup G) : subgroup G :=\n{ carrier := H.carrier ∩ K.carrier,\n  one_mem' := ⟨H.one_mem, K.one_mem⟩,\n  mul_mem' := λ _ _ ⟨hhx, hkx⟩ ⟨hhy, hky⟩, \n  ⟨H.mul_mem hhx hhy, K.mul_mem hkx hky⟩,\n  inv_mem' := λ x ⟨hhx, hhy⟩,\n  ⟨H.inv_mem hhx, K.inv_mem hhy⟩}\n\nlemma inf_def (H K : subgroup G) : (inf H K : set G) = (H : set G) ∩ K := rfl \n\n/- \nWe will consider the closure of a set as the intersect of all subgroups\ncontaining the set\n-/\ninstance : has_Inf (subgroup G) :=\n⟨λ s, {\n  carrier := ⋂ t ∈ s, (t : set G),\n  one_mem' := mem_bInter $ λ i h, i.one_mem,\n  mul_mem' := λ x y hx hy, mem_bInter $ λ i h,\n    i.mul_mem (by apply mem_bInter_iff.1 hx i h) \n    (by apply mem_bInter_iff.1 hy i h),\n  inv_mem' := λ x hx, mem_bInter $ λ i h,\n    i.inv_mem (by apply mem_bInter_iff.1 hx i h) }⟩\n\nvariable {ι : Type*}\n\n-- The intersect of a set of subgroups is a subgroup\ndef infi (H : ι → subgroup G) : subgroup G := \n{ carrier := ⋂ i, H i,\n  one_mem' := mem_Inter.mpr $ λ i, (H i).one_mem,\n  mul_mem' := λ _ _ hx hy, mem_Inter.mpr $ λ i, \n  by {rw mem_Inter at *, from mul_mem (H i) (hx i) (hy i)},\n  inv_mem' := λ x hx, mem_Inter.mpr $ λ i, (H i).inv_mem $ by apply mem_Inter.mp hx }\n\ndef closure (S : set G) : subgroup G := Inf {H | S ⊆ H}\n\nlemma mem_closure_iff {S : set G} {x : G} : \n  x ∈ closure S ↔ ∀ H : subgroup G, S ⊆ H → x ∈ H := mem_bInter_iff\n\n/- We will now prove some lemmas that are helpful in proving subgroups \nform a galois_insertion with the coercion to set-/\n\nlemma le_closure (S : set G) : S ≤ closure S :=\nλ s hs H ⟨y, hy⟩, by rw ←hy; simp; exact λ hS, hS hs\n\nlemma closure_le (S : set G) (H : subgroup G) : closure S ≤ H ↔ S ≤ H :=\nbegin\n  split,\n    { intro h, refine subset.trans (le_closure _) h },\n    { intros h y,\n      unfold closure, unfold Inf, \n      rw mem_bInter_iff, intro hy,\n      exact hy H h }\nend\n\nlemma closure_le' (S : set G) (H : subgroup G) : \n  (closure S : set G) ⊆ H ↔ S ⊆ H := closure_le S H\n\nlemma closure_le'' (S : set G) (H : subgroup G) : \n  (∀ x, x ∈ closure S → x ∈ H) ↔ (∀ x, x ∈ S → x ∈ H) := closure_le S H\n\nlemma closure_self {H : subgroup G} : closure (H : set G) = H :=\nbegin\n  rw ←subgroup.ext'_iff, ext,\n  split; intro hx,\n    { apply subset.trans _ ((closure_le (H : set G) H).2 (subset.refl H)), \n      exact hx, exact subset.refl _ },\n    { apply subset.trans (le_closure (H : set G)), \n      intros g hg, assumption, assumption }\nend\n\nlemma closure_induction {p : G → Prop} {x} {k : set G} (h : x ∈ closure k)\n  (Hk : ∀ x ∈ k, p x) (H1 : p 1)\n  (Hmul : ∀ x y, p x → p y → p (x * y))\n  (Hinv : ∀ x, p x → p x⁻¹) : p x :=\n(@closure_le _ _ _ ⟨p, H1, Hmul, Hinv⟩).2 Hk h\n\n/-\nNow, by considering the coercion between subgroup G → set G, we cheat a bit\nby transfering the partial order on set to the partial order on subgroups.\n\nWe do this because galois_insertion requires preorders and partial orders\nextends preoders.\n-/\ninstance : partial_order (subgroup G) := \n{.. partial_order.lift (coe : subgroup G → set G) (λ x y, subgroup.ext')}\n\n/-\nFinially we prove that subgroups form a galois_insertion with the coercion \nto set.\n-/\ndef gi : @galois_insertion (set G) (subgroup G) _ _ closure (λ H, H.carrier) :=\n{ choice := λ S _, closure S,\n  gc := λ H K,\n    begin\n      split; intro h,\n        { exact subset.trans (le_closure H) h },\n        { exact (closure_le _ _).2 h },\n    end,\n  le_l_u := λ H, le_closure (H : set G),\n  choice_eq := λ _ _, rfl }\n\n/-\nWith that it follows that subgroups form a complete lattice!\n-/\ninstance : complete_lattice (subgroup G) :=\n{.. galois_insertion.lift_complete_lattice gi}\n\ndef trivial : subgroup G := \n  ⟨{(1 : G)}, set.mem_singleton 1, \n    λ _ _ hx hy, by rw set.mem_singleton_iff at *; simp [hx, hy],\n    λ _ hx, by rw set.mem_singleton_iff at *; rw hx; exact group.one_inv⟩\n\nlemma mem_trivial_iff (g : G) : g ∈ (trivial : subgroup G) ↔ g = 1 := iff.rfl\n\nlemma mem_trivial_carrier_iff (g : G) : g ∈ (trivial : subgroup G).carrier ↔ g = 1 := iff.rfl\n\nlemma bot_eq_trivial : (⊥ : subgroup G) = trivial :=\nbegin\n  apply le_antisymm,\n    { change closure (∅ : set G) ≤ _,\n      rw closure_le, finish },\n    { intros x hx,\n      change x ∈ {(1 : G)} at hx, \n      rw set.mem_singleton_iff at hx,\n      subst hx, unfold_coes, rw mem_coe,\n      exact one_mem ⊥ }\nend \n\nlemma bot_eq_singleton_one : ((⊥ : subgroup G) : set G) = {1} :=\nby rw bot_eq_trivial; refl\n\nlemma mem_bot_iff {x : G} : x ∈ (⊥ : subgroup G) ↔ x = 1 :=\nbegin \n  split; intro h,\n    rw [← mem_singleton_iff, ← bot_eq_singleton_one], exact h,\n    rw [bot_eq_trivial], exact h\nend\n\nlemma fincard_bot : fincard (⊥ : subgroup G) = 1 :=\nby rw [← @fincard.card_singleton_eq_one _ (1 : G), ← bot_eq_singleton_one]; refl\n\nlemma eq_top_iff' (H : subgroup G) : H = ⊤ ↔ ∀ g, g ∈ H :=\nbegin\n  split,\n  { rintro rfl,\n    intro g,\n    show g ∈ ((⊤ : subgroup G) : set G),\n    rw ←singleton_subset_iff,\n    show ({g} : set G) ≤ _,\n    rw ←closure_le, simp },\n  { intro h,\n    rw eq_top_iff,\n    intros g hg,\n    apply h  }\nend\n\n-- scary example!\n-- SL₂(ℝ) acts on the upper half plane {z : ℂ | Im(z) > 0}\n-- (a b; c d) sends z to (az+b)/(cz+d)\n-- check this is an action\n-- so SL₂(ℤ) acts on the upper half plane\n-- and H, the stabilizer of i ,is cyclic order 4\n-- generated by (0 -1; 1 0)\n-- and K, the stabilizer of e^{2 pi i/6}, is cyclic order 6\n-- generated by something like (1 1; -1 0) maybe\n-- Turns out that the smallest subgroup of SL₂(ℤ)\n-- containing H and K is all of SL₂(ℤ)!\n-- In particular if H and K are finite, but neither of\n-- them are normal, then H ⊔ K can be huge\n\nexample (H K : subgroup G) : subgroup G := H ⊔ K\n\n-- theorem: if K is normal in G then H ⊔ K is just \n-- literally {hk : h ∈ H, k ∈ K}\n\nvariables {H K}\n\nopen normal\n\n/-- The supremum of two subgroups induced by the Galois insertion is the closure \n  of the union of their carriers -/\nlemma sup_def : H ⊔ K = closure (H.carrier ⊔ K.carrier) := rfl\n\n/-- The supremum of two subgroups is larger then their union -/\nlemma mem_sup_of_mem {x} (hx : x ∈ H ∨ x ∈ K) : x ∈ H ⊔ K :=\nbegin\n  rw sup_def,\n  change x ∈ ⋂ (t : subgroup G) (H : H.carrier ∪ K.carrier ⊆ t), ↑t,\n  refine mem_bInter (λ S hS, hS hx)\nend\n\nlemma mem_sup_of_mem_left {x} (hx : x ∈ H) : x ∈ H ⊔ K :=\nby { apply mem_sup_of_mem, left, assumption }\n\nlemma mem_sup_of_mem_right {x} (hx : x ∈ K) : x ∈ H ⊔ K :=\nby { apply mem_sup_of_mem, right, assumption }\n\nlemma mem_inf {H K : subgroup G} {g : G} : \n  g ∈ H ⊓ K ↔ g ∈ H ∧ g ∈ K := \nbegin\n  change g ∈ closure ((H : set G) ∩ K) ↔ _,\n  rw [←inf_def H K, closure_self], refl\nend\n\nnamespace product\n\n/-- The product of a subgroup and a normal subgroup forms a subgroup -/\ndef prod (H : subgroup G) (K : normal G) : subgroup G := \n{ carrier := { g | ∃ h ∈ H, ∃ k ∈ K, g = h * k },\n  one_mem' := ⟨1, one_mem H, 1, one_mem K, (group.one_mul _).symm⟩,\n  mul_mem' := λ x y ⟨h₀, hh₀, k₀, hk₀, hx⟩ ⟨h₁, hh₁, k₁, hk₁, hy⟩,\n    begin\n      rw [hx, hy],\n      refine ⟨h₀ * h₁, mul_mem H hh₀ hh₁, h₁⁻¹ * k₀ * h₁ * k₁, _, _⟩,\n        { refine mul_mem K (mem_normal'.2 ⟨h₁, k₀, hk₀, rfl⟩) hk₁ },\n        { simp [group.mul_assoc] }\n    end,\n  inv_mem' := λ x ⟨h, hh, k, hk, hx⟩,\n    begin\n      rw [hx, group.inv_mul],\n      rw (show k⁻¹ * h⁻¹ = h⁻¹ * (h * k⁻¹ * h⁻¹), by simp [group.mul_assoc]),\n      refine ⟨h⁻¹, inv_mem H hh, h * k⁻¹ * h⁻¹, \n        mem_normal.2 ⟨h, k⁻¹, inv_mem K hk, rfl⟩, by simp [group.mul_assoc]⟩      \n    end } \n\ninfix ` ⨯ `:70 := prod\n\nlemma mem_product {H : subgroup G} {K : normal G} {x} : \n  x ∈ H ⨯ K ↔ ∃ (h ∈ H) (k ∈ K), x = h * k := iff.rfl\n\ntheorem product_eq_sup (H : subgroup G) (K : normal G) : H ⨯ K = H ⊔ K :=\nbegin\n  ext, split,\n    { intro hx, rcases mem_product.1 hx with ⟨h, hh, k, hk, rfl⟩,\n      exact mul_mem _ (mem_sup_of_mem_left hh) (mem_sup_of_mem_right hk) },\n    { revert x, \n      simp_rw [sup_def, closure_le'', mem_product],\n      intros x hx, cases hx, \n        exact ⟨x, hx, 1, one_mem K, (group.mul_one x).symm⟩,\n        exact ⟨1, one_mem H, x, hx, (group.one_mul x).symm⟩ }\nend \n\nend product\n\n-- We make a inductive type `subgroup_ge G H` which is the the type whose terms \n-- are subgroups of `G` greater than `H : subgroup G` (this makes sense since we \n-- created a lattice structure on subgroups). \n\n/-- `subgroup_ge G H` is the inductive type of subgroups of `G` thats greater \n  than `H`-/\ninductive subgroup_ge (G : Type) [group G] (K : subgroup G) \n| mk (H : subgroup G) : (K ≤ H) → subgroup_ge\n\nnamespace ge\n\nopen subgroup_ge\n\n-- We will show that the set of subgroups greater than some subgroup form a \n-- complete lattice. To do this we will use the fact that the subgroups forms \n-- a complete lattice and we will create a Galois insertion from subgroups \n-- inducing a complete lattice\n\n@[simp] lemma subgroup_ge_eq (A B : subgroup G) {hA : H ≤ A} {hB : H ≤ B} : \n  subgroup_ge.mk A hA = subgroup_ge.mk B hB ↔ A = B := ⟨subgroup_ge.mk.inj, by cc⟩\n\ninstance : has_coe (subgroup_ge G H) (set G) := ⟨λ ⟨K, _⟩, (K : set G)⟩\n\n@[simp] lemma ext' {A B : subgroup_ge G H} : \n  A = B ↔ (A : set G) = B :=\nbegin\n  cases A, cases B,\n  rw subgroup_ge_eq,\n  exact ⟨by cc, λ h, ext' h⟩,\nend\n\ninstance : has_mem G (subgroup_ge G H) := ⟨λ g K, g ∈ (K : set G)⟩\n\n@[ext] theorem ext {A B : subgroup_ge G H}\n  (h : ∀ x, x ∈ A ↔ x ∈ B) : A = B := ext'.2 $ set.ext h\n\ninstance has_coe_to_subgroup : has_coe (subgroup_ge G H) (subgroup G) := \n  ⟨λ ⟨K, _⟩, K⟩\n\n@[simp] lemma subgroup_ge_eq' (A B : subgroup_ge G H) : \n  A = B ↔ (A : subgroup G) = B := by { cases A, cases B, exact subgroup_ge_eq _ _ }\n\n-- We borrow the partital order structure from subgroups\ninstance : partial_order (subgroup_ge G H) := \n{ .. partial_order.lift (coe : subgroup_ge G H → subgroup G) $ λ x y hxy, by simp [hxy] }\n\ninstance : has_bot (subgroup_ge G H) := ⟨⟨H, le_refl _⟩⟩\n\ninstance : has_Inf (subgroup_ge G H) := \n⟨ λ s, subgroup_ge.mk (Inf { A | ∃ t ∈ s, (t : subgroup G) = A }) $ λ h hh,\n  begin\n    suffices : ∀ (i : subgroup G) (x : subgroup_ge G H), x ∈ s → ↑x = i → h ∈ ↑i,\n      simpa [Inf],\n    rintros _ ⟨t, ht⟩ _ rfl,\n    exact ht hh\n  end ⟩\n\nlemma le_Inf (s : set (subgroup_ge G H)) : ∀ t ∈ s, Inf s ≤ t :=\nbegin\n  rintros ⟨t, ht⟩ hst a ha,\n  change a ∈ ⋂ t _, ↑t at ha,\n  rw mem_bInter_iff at ha,\n  exact ha t ⟨⟨t, ht⟩, hst, rfl⟩,\nend  \n\ndef closure (A : subgroup G) : subgroup_ge G H := Inf { B | A ≤ B }\n\nlemma closure_le (A : subgroup G) (B : subgroup_ge G H) : \n  closure A ≤ B ↔ A ≤ B :=\nbegin\n  split,\n    { intro h, cases B with B hB,\n      exact le_trans \n        (show A ≤ _, by exact (λ _ ha, mem_bInter (λ _ ⟨⟨_, _⟩, ht', rfl⟩, ht' ha))) h },\n    { intro h, exact le_Inf _ _ h }\nend\n\nlemma le_closure (A : subgroup_ge G H) : A = closure A :=\nbegin\n  cases A with A hA,\n  ext, split,\n  { intro hx,\n    refine mem_bInter (λ B hB, _),\n    rcases hB with ⟨t, ht, rfl⟩,\n    exact ht hx },\n  { suffices : closure A ≤ ⟨A, hA⟩,\n      intro hx, exact this hx,\n    apply le_Inf,\n    rw mem_set_of_eq,\n    exact le_of_eq rfl }  \nend\n\ndef gi : @galois_insertion (subgroup G) (subgroup_ge G H) _ _ closure (coe) := \n{ choice := λ x _, closure x,\n  gc := λ A B, closure_le _ _,\n  le_l_u := λ x, le_of_eq $ le_closure x,\n  choice_eq := λ _ _, rfl }\n\ninstance : complete_lattice (subgroup_ge G H) := \n{.. @galois_insertion.lift_complete_lattice (subgroup G) (subgroup_ge G H) _ _ _ _ gi }\n\n-- We can see easily that subgroup G is the same as subgroup_ge G ⊥\n\ndef subgroup_ge_bot_equiv : subgroup G ≃ subgroup_ge G ⊥ := \n{ to_fun := λ H, ⟨H, bot_le⟩,\n  inv_fun := λ ⟨H, _⟩, H,\n  left_inv := λ _, rfl,\n  right_inv := λ ⟨_, _⟩, rfl }\n\ndef subgroup_ge_bot_order_iso : \n  let A := subgroup G in let B := subgroup_ge G ⊥ in \n  ((≤) : A → A → Prop) ≃o ((≤) : B → B → Prop) :=\n{ ord' := λ _ _, iff.rfl, \n  .. subgroup_ge_bot_equiv }\n\nend ge\n\nend subgroup\n\nnamespace lattice\n\n/-- Given an equivalence `e` on preorders `A` and `B`, and a Galois connection \n  using `e`, there is an induced `order_iso` between `A` and `B`  -/\ndef order_iso_of_equiv_gi {A B : Type} [preorder A] [preorder B]\n   (e : A ≃ B) (g : galois_connection e.to_fun e.inv_fun) : \n  ((≤) : A → A → Prop) ≃o ((≤) : B → B → Prop) := \n{ ord' := λ a b, let h := g a (e.to_fun b) in\n    by { rw e.left_inv at h, rw ←h, refl}, .. e }\n\nopen order_iso\n\n/-- Given a `lattice`, `A`, there is an induced `lattice` on the `partial_order`, \n  `B` given that they are order isomorphic -/\ndef lattice_of_order_iso {A B : Type} [lattice A] [partial_order B] \n  (e : ((≤) : A → A → Prop) ≃o ((≤) : B → B → Prop)) : lattice B := \n{ .. galois_insertion.lift_lattice e.to_galois_insertion }\n\n/-- Given a `lattice`, `B` and an `order_iso` to the `distrib_lattice`, `A`, \n  there is an induced `distrib_lattice` on `B` -/\ndef distrib_lattice_of_order_iso {A B : Type} [hA : distrib_lattice A] [lattice B]\n  (e : ((≤) : B → B → Prop) ≃o ((≤) : A → A → Prop)) : distrib_lattice B := \n{ le_sup_inf := \n    begin\n      intros x y z, rw e.ord',\n      change e ((x ⊔ y) ⊓ (x ⊔ z)) ≤ e (x ⊔ y ⊓ z),\n      rw [map_inf, map_sup, map_sup, map_sup, map_inf],\n      apply hA.le_sup_inf\n    end\n  .. show lattice B, by apply_instance }\n\ndef distrib_lattice_of_order_iso' {A B : Type} [distrib_lattice A] [lattice B]\n  (e : ((≤) : A → A → Prop) ≃o ((≤) : B → B → Prop)) : distrib_lattice B := \ndistrib_lattice_of_order_iso $ order_iso.symm e\n\n/-- Given a `distrib_lattice`, `A`, there is an induced `distrib_lattice` on the \n  `partial_order`, `B` given that they are order isomorphic -/\ndef distrib_lattice_of_order_iso'' {A B : Type} [distrib_lattice A] [partial_order B]\n  (e : ((≤) : A → A → Prop) ≃o ((≤) : B → B → Prop)) : distrib_lattice B :=\n@distrib_lattice_of_order_iso' _ _ _ \n  (@lattice_of_order_iso _ _ (distrib_lattice.to_lattice A) _ e) e\n\nend lattice \n\nnamespace normal \n\ninstance : partial_order (normal G) := \n{.. partial_order.lift (normal.to_subgroup) (λ x y, normal.ext')}\n\ninstance : has_Inf (normal G) :=\n⟨λ s, {\n  carrier := ⋂ t ∈ s, (t : set G),\n  one_mem' := mem_bInter $ λ i h, i.one_mem',\n  mul_mem' := λ x y hx hy, mem_bInter $ λ i h,\n    i.mul_mem' (by apply mem_bInter_iff.1 hx i h) \n    (by apply mem_bInter_iff.1 hy i h),\n  inv_mem' := λ x hx, mem_bInter $ λ i h,\n    i.inv_mem' (by apply mem_bInter_iff.1 hx i h),\n  conj_mem' := \n    begin\n      simp_rw mem_bInter_iff,\n      intros n hn g N hNs,\n      exact N.conj_mem _ (hn N hNs) _, \n    end }⟩\n\n@[simp] lemma mem_Inf (x : G) (s : set (normal G)) : \n  x ∈ Inf s ↔ x ∈ ⋂ t ∈ s, (t : set G) := iff.rfl\n\ndef closure (S : set G) : normal G := Inf {H | S ⊆ H}\n\nlemma mem_closure_iff {S : set G} {x : G} : \n  x ∈ closure S ↔ ∀ H : normal G, S ⊆ H → x ∈ H := mem_bInter_iff\n\nlemma le_closure (S : set G) : S ≤ closure S :=\nλ s hs H ⟨y, hy⟩, by rw ←hy; simp; exact λ hS, hS hs\n\nlemma closure_le (S : set G) (H : normal G) : closure S ≤ H ↔ S ≤ H :=\nbegin\n  split,\n    { intro h, refine subset.trans (le_closure _) h },\n    { intros h y hy,\n      change y ∈ (_ : normal G) at hy,\n      unfold closure at hy,\n      rw [mem_Inf, mem_bInter_iff] at hy,\n      exact hy H h }\nend\n\nlemma closure_le' (S : set G) (H : normal G) : \n  (closure S : set G) ⊆ H ↔ S ⊆ H := closure_le S H\n\nlemma closure_le'' (S : set G) (H : normal G) : \n  (∀ x, x ∈ closure S → x ∈ H) ↔ (∀ x, x ∈ S → x ∈ H) := closure_le S H\n\nlemma closure_self {H : normal G} : closure (H : set G) = H :=\nbegin\n  ext, split; intro hx,\n    { apply subset.trans _ ((closure_le (H : set G) H).2 (subset.refl H)), \n      exact hx, exact subset.refl _ },\n    { rw ← mem_carrier,\n      apply subset.trans (le_closure (H : set G)), \n      intros g hg, assumption, assumption }\nend\n\n-- lemma closure_induction {p : G → Prop} {x} {k : set G} (h : x ∈ closure k)\n--   (Hk : ∀ x ∈ k, p x) (H1 : p 1)\n--   (Hmul : ∀ x y, p x → p y → p (x * y))\n--   (Hinv : ∀ x, p x → p x⁻¹) : p x :=\n-- (@closure_le _ _ _ ⟨p, H1, Hmul, Hinv⟩).2 Hk h\n\ndef gi : @galois_insertion (set G) (normal G) _ _ closure (λ H, H.carrier) :=\n{ choice := λ S _, closure S,\n  gc := λ H K,\n    begin\n      split; intro h,\n        { exact subset.trans (le_closure H) h },\n        { exact (closure_le _ _).2 h },\n    end,\n  le_l_u := λ H, le_closure (H : set G),\n  choice_eq := λ _ _, rfl }\n\ninstance : complete_lattice (normal G) :=\n{.. galois_insertion.lift_complete_lattice gi}\n\nend normal\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/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.85776809953619, "lm_q1q2_score": 0.7555196276021127}}
{"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(ζₙ)` and `(zmod n)ˣ`;\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 `ℚ` and certain `𝔽ₚ`).\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\nvariables {n : ℕ+} (K : Type*) [field K] {L : Type*} {μ : L}\n\nopen polynomial is_cyclotomic_extension\n\nopen_locale cyclotomic\n\nnamespace is_primitive_root\n\nvariables [comm_ring L] [is_domain L] (hμ : is_primitive_root μ n) [algebra K L]\n          [is_cyclotomic_extension {n} K L]\n\n/-- `is_primitive_root.aut_to_pow` is injective in the case that it's considered over a cyclotomic\nfield extension. -/\nlemma aut_to_pow_injective : function.injective $ hμ.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ζ at hf hg,\n  suffices : f hμ.to_roots_of_unity = g hμ.to_roots_of_unity,\n  { apply alg_equiv.coe_alg_hom_injective,\n    apply (hμ.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 [←roots_of_unity.coe_pow _ hf'.some, ←roots_of_unity.coe_pow _ hg'.some],\n  congr' 1,\n  rw [pow_eq_pow_iff_modeq],\n  convert hfg,\n  rw [hμ.eq_order_of],\n  rw [←hμ.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\nvariables [comm_ring L] [is_domain L] (hμ : is_primitive_root μ n) [algebra K L]\n          [is_cyclotomic_extension {n} K L]\n\n/-- Cyclotomic extensions are abelian. -/\nnoncomputable def aut.comm_group : comm_group (L ≃ₐ[K] L) :=\n((zeta_spec 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)ˣ` such that\n  `f μ = μ ^ k` for any root of unity `μ`. A  strengthening of `is_primitive_root.aut_to_pow`. -/\n@[simps] noncomputable def aut_equiv_pow : (L ≃ₐ[K] L) ≃* (zmod n)ˣ :=\nlet hζ := zeta_spec n K L,\n    hμ := λ t, hζ.pow_of_coprime _ (zmod.val_coe_unit_coprime t) in\n{ inv_fun := λ t, (hζ.power_basis K).equiv_of_minpoly ((hμ t).power_basis K)\n  begin\n    haveI := is_cyclotomic_extension.ne_zero' n K L,\n    simp only [is_primitive_root.power_basis_gen],\n    have hr := is_primitive_root.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  end,\n  left_inv := λ f, begin\n    simp only [monoid_hom.to_fun_eq_coe],\n    apply alg_equiv.coe_alg_hom_injective,\n    apply (hζ.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 := λ x, begin\n    simp only [monoid_hom.to_fun_eq_coe],\n    generalize_proofs _ h,\n    have key := hζ.aut_to_pow_spec K ((hζ.power_basis K).equiv_of_minpoly ((hμ x).power_basis K) h),\n    have := (hζ.power_basis K).equiv_of_minpoly_gen ((hμ x).power_basis K) h,\n    rw hζ.power_basis_gen K at this,\n    rw [this, is_primitive_root.power_basis_gen] at key,\n    rw ← hζ.coe_to_roots_of_unity_coe at key {occs := occurrences.pos [1, 5]},\n    simp only [←coe_coe, ←roots_of_unity.coe_pow] at key,\n    replace key := roots_of_unity.coe_injective key,\n    rw [pow_eq_pow_iff_modeq, ←order_of_subgroup, ←order_of_units, hζ.coe_to_roots_of_unity_coe,\n        ←(zeta_spec n K L).eq_order_of, ←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  end,\n  .. (zeta_spec n K L).aut_to_pow K }\n\ninclude hμ\n\nvariables {L}\n\n/-- Maps `μ` to the `alg_equiv` that sends `is_cyclotomic_extension.zeta` to `μ`. -/\nnoncomputable def from_zeta_aut : L ≃ₐ[K] L :=\nlet hζ := (zeta_spec n K L).eq_pow_of_pow_eq_one hμ.pow_eq_one n.pos in\n(aut_equiv_pow L h).symm $ zmod.unit_of_coprime hζ.some $\n((zeta_spec n K L).pow_iff_coprime n.pos hζ.some).mp $ hζ.some_spec.some_spec.symm ▸ hμ\n\nlemma from_zeta_aut_spec : from_zeta_aut hμ h (zeta n K L) = μ :=\nbegin\n  simp_rw [from_zeta_aut, aut_equiv_pow_symm_apply],\n  generalize_proofs hζ h _ hμ _,\n  rw [←hζ.power_basis_gen K] {occs := occurrences.pos [4]},\n  rw [power_basis.equiv_of_minpoly_gen, hμ.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 [field L] (hμ : is_primitive_root μ n) [algebra K L]\n          [is_cyclotomic_extension {n} K L] (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)ˣ`\nif `cyclotomic n K` is irreducible in the base field. -/\nnoncomputable def gal_cyclotomic_equiv_units_zmod :\n  (cyclotomic n K).gal ≃* (zmod n)ˣ :=\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`.\nAsserts that the Galois group of `X ^ n - 1` is equivalent to `(zmod n)ˣ`\nif `cyclotomic n K` is irreducible in the base field. -/\nnoncomputable def gal_X_pow_equiv_units_zmod :\n  (X ^ (n : ℕ) - 1).gal ≃* (zmod n)ˣ :=\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": "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/cyclotomic/gal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7555117228529258}}
{"text": "import data.real.basic\n\nvariables (a b : ℝ)\n\ninclude a b\nexample : (a + b) ^ 3 = a ^ 3 + 3 * (a ^ 2) * b + 3 * a * b ^ 2 + b ^ 3 := \nby calc\n    (a + b) ^ 3 = (a + b) ^ (2 + 1) : rfl\n    ... = (a + b) ^ 2 * (a + b) : by rw pow_succ'\n    ... = (a + b) * (a + b) * (a + b) : by rw pow_two\n    ... = ((a + b) * a + (a + b) * b) * (a + b) : by rw mul_add (a + b) a b\n    ... = ((a * a + b * a) + (a * b + b * b)) * (a + b) : \n    by rw [add_mul a b a, add_mul a b b]\n    ... = (a * a + b * a + a * b + b * b) * (a + b) : \n    by rw [add_assoc (a * a + b * a) (a * b) (b * b)]\n    ... = (a ^ 2 + a * b + a * b + b ^ 2) * (a + b) : \n    by rw [mul_comm b a, pow_two, pow_two]\n    ... = (a ^ 2 + 1 * a * b + 1 * a * b + b ^ 2) * (a + b) : by rw one_mul\n    ... = (a ^ 2 + (1 * a * b + 1 * a * b) + b ^ 2) * (a + b) : \n    by rw add_assoc (a ^ 2) (1 * a * b) (1 * a * b)\n    ... = (a ^ 2 + (1 * (a * b) + 1 * (a * b)) + b ^ 2) * (a + b) : \n    by rw mul_assoc\n    ... = (a ^ 2 + (1 + 1) * (a * b) + b ^ 2) * (a + b) : by rw add_mul 1 1 (a * b)\n    ... = (a ^ 2 + 2 * (a * b) + b ^ 2) * (a + b) : rfl\n    ... = (a ^ 2 + 2 * a * b + b ^ 2) * (a + b) : by rw mul_assoc\n    ... = (a ^ 2 + 2 * a * b + b ^ 2) * a + (a ^ 2 + 2 * a * b + b ^ 2) * b : \n    by rw mul_add    \n    ... = (a ^ 2 + 2 * a * b) * a + b ^ 2 * a + \n    ((a ^ 2 + 2 * a * b) * b + b ^ 2 * b) : \n    by rw [add_mul (a ^ 2 + 2 * a * b) (b ^ 2) a, \n    add_mul (a ^ 2 + 2 * a * b) (b ^ 2) b]\n    ... = a ^ 2 * a + 2 * a * b * a + a * b ^ 2 + \n    (a ^ 2 * b + 2 * a * b * b + b ^ 3) : \n    by rw [add_mul, add_mul, mul_comm (b ^ 2) a, pow_succ' b 2]\n    ... = a ^ 3 + 2 * a * (b * a) + a * b ^ 2 + \n    (a ^ 2 * b + 2 * a * (b * b) + b ^ 3) : \n    by rw [pow_succ' a 2, mul_assoc, mul_assoc (2 * a) b b]\n    ... = a ^ 3 + 2 * a * (a * b) + a * b ^ 2 + \n    (a ^ 2 * b + 2 * a * b ^ 2 + b ^ 3) : \n    by rw [mul_comm b a, pow_two]\n    ... = a ^ 3 + 2 * a * a * b + a * b ^ 2 + \n    (a ^ 2 * b + 2 * a * b ^ 2 + b ^ 3) : \n    by rw [mul_assoc (2 * a) a b]\n    ... = a ^ 3 + 2 * (a * a) * b + 1 * a * b ^ 2 + \n    (1 * a ^ 2 * b + 2 * a * b ^ 2 + b ^ 3) : \n    by rw [mul_assoc 2 a a, one_mul, one_mul]\n    ... = a ^ 3 + 2 * a ^ 2 * b + 1 * a * b ^ 2 + \n    (1 * a ^ 2 * b + 2 * a * b ^ 2 + b ^ 3) : \n    by rw [pow_two a]\n    ... = a ^ 3 + 2 * a ^ 2 * b + 1 * a * b ^ 2 + \n    (1 * a ^ 2 * b + 2 * a * b ^ 2) + b ^ 3 : \n    by rw [add_assoc (a ^ 3 + 2 * a ^ 2 * b + 1 * a * b ^ 2) \n    (1 * a ^ 2 * b + 2 * a * b ^ 2) (b ^ 3)]\n    ... = a ^ 3 + 2 * a ^ 2 * b + 1 * a * b ^ 2 + \n    1 * a ^ 2 * b + 2 * a * b ^ 2 + b ^ 3 : \n    by rw [add_assoc (a ^ 3 + 2 * a ^ 2 * b + 1 * a * b ^ 2) (1 * a ^ 2 * b)\n    (2 * a * b ^ 2)]\n    ... = a ^ 3 + 2 * a ^ 2 * b + (1 * a * b ^ 2 + \n    1 * a ^ 2 * b) + 2 * a * b ^ 2 + b ^ 3 : \n    by rw [add_assoc (a ^ 3 + 2 * a ^ 2 * b) (1 * a * b ^ 2) (1 * a ^ 2 * b)]\n    ... = a ^ 3 + 2 * a ^ 2 * b + (1 * a ^ 2 * b + 1 * a * b ^ 2) +\n    2 * a * b ^ 2 + b ^ 3 : \n    by rw [add_comm (1 * a ^ 2 * b) (1 * a * b ^ 2)]\n    ... = a ^ 3 + 2 * a ^ 2 * b + 1 * a ^ 2 * b + 1 * a * b ^ 2 +\n    2 * a * b ^ 2 + b ^ 3 : \n    by rw [add_assoc (a ^ 3 + 2 * a ^ 2 * b) (1 * a ^ 2 * b) (1 * a * b ^ 2)]\n    ... = a ^ 3 + (2 * a ^ 2 * b + 1 * a ^ 2 * b) + (1 * a * b ^ 2 +\n    2 * a * b ^ 2) + b ^ 3 : \n    by rw [add_assoc (a ^ 3) (2 * a ^ 2 * b) (1 * a ^ 2 * b), \n    add_assoc (a ^ 3 + (2 * a ^ 2 * b + 1 * a ^ 2 * b)) (1 * a * b ^ 2) \n    (2 * a * b ^ 2)]\n    ... = a ^ 3 + (2 + 1) * (a ^ 2 * b) + (1 + 2) * (a * b ^ 2) + b ^ 3 : \n    by rw [mul_assoc 2 (a ^ 2) b, mul_assoc 1 (a ^ 2) b, mul_assoc 1 a (b ^ 2),\n    mul_assoc 2 a (b ^ 2), add_mul 2 1 (a ^ 2 * b), add_mul 1 2 (a * b ^ 2)]\n    ... = a ^ 3 + 3 * (a ^ 2 * b) + 3 * (a * b ^ 2) + b ^ 3 : rfl\n    ... = a ^ 3 + 3 * a ^ 2 * b + 3 * a * b ^ 2 + b ^ 3 : \n    by rw [mul_assoc 3 (a ^ 2) b, mul_assoc 3 a (b ^ 2)]", "meta": {"author": "AlexandruBosinta", "repo": "MyLeanPlayground", "sha": "5dc50a590d784bfc27e7fb37b6361a6dcc1b2790", "save_path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground", "path": "github-repos/lean/AlexandruBosinta-MyLeanPlayground/MyLeanPlayground-5dc50a590d784bfc27e7fb37b6361a6dcc1b2790/(a + b)^3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741254760638, "lm_q2_score": 0.7931059487389968, "lm_q1q2_score": 0.7554922055299137}}
{"text": "import .love05_inductive_predicates_demo\nimport .love13_rational_and_real_numbers_demo\n\n/-! # LoVe Exercise 13: Rational and Real Numbers -/\n\n\nset_option pp.beta true\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\n\n-- lemma rat_test : ℚ \n-- #eval  0 0   -- expected: 0\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/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.901920681802153, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7554667684206545}}
{"text": "import data.list\nimport tactic.norm_num\nimport .common .tree_sort .list\n\nlocal attribute [simp, reducible] nat.factors\n\n@[simp, reducible]\ndef list.zip_with_count {α: Type*} [decidable_eq α] (l: list α): list (α × ℕ) :=\n  list.map (λ x, (x, list.count x l)) l\n\n@[simp, reducible]\ndef factorize (n: ℕ) : list (ℕ × ℕ) := \n  list.erase_dup (nat.factors n).zip_with_count\n\n#eval factorize (2*2*3*5*5)\nexample: (factorize (2*2*3)) ~ [(2, 2), (3, 1)] := by norm_num; reflexivity\n\ntheorem factors_ge_2 {n p m: ℕ}: (p, m) ∈ (factorize n) -> p ≥ 2 := begin\nintro h,\nsimp at h,\ncases h with a w,\n  rw w.right.left.symm,\n  have: nat.prime a, by apply nat.mem_factors w.left,\n  apply nat.prime.two_le,\n  assumption,\nend\n\ntheorem factors_are_nat_factors {n p m: ℕ}: (p, m) ∈ (factorize n) -> p ∈ (nat.factors n) := begin\nintro h,\nsimp at h,\ncases h with a w,\n  rw w.right.left.symm,\n  apply w.left,\nend\n\ntheorem factors_are_prime {n p m: ℕ}: (p, m) ∈ (factorize n) -> nat.prime p := begin\nintro h,\nsimp at h,\ncases h with a w,\n  rw w.right.left.symm,\n  apply nat.mem_factors w.left,\nend\n\n@[simp, reducible]\ndef Prod: list ℕ -> ℕ := list.prod\ntheorem prod_singleton_id {x}: Prod [x] = x := by simp\ntheorem prod_singleton_of_lift_id {x}: (Prod ∘ (λ x, [x])) x = x := by simp\n\n@[simp, reducible]\ndef divisors_aux: list (ℕ × ℕ) -> list ℕ\n| [] := [1]\n| (p::ps) := (<| p |>) <*> (divisors_aux ps)\n\n#eval divisors_aux (factorize (2*2*3*5*5))\n\n@[simp, reducible]\ndef divisors (n: ℕ) := divisors_aux (factorize n)\n\n#eval divisors (2*2*3*5*5)\n#eval divisors (2*2*3)\nexample: tree_sort.sort (λ a b, to_bool (a < b)) (divisors (2*2*3)) = [1, 2, 3, 4, 6, 12] := by norm_num; reflexivity\n", "meta": {"author": "ntabee", "repo": "lean-mathgirls", "sha": "95b64a33ffb34f3c45e212c4adff3cc988dcbc60", "save_path": "github-repos/lean/ntabee-lean-mathgirls", "path": "github-repos/lean/ntabee-lean-mathgirls/lean-mathgirls-95b64a33ffb34f3c45e212c4adff3cc988dcbc60/src/factorize.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7554667636239516}}
{"text": "import affine_algebraic_set.Zariski -- Zariski topology\nimport affine_algebraic_set.V_and_I -- 𝕍 and 𝕀 basics\nimport for_mathlib.topological_space -- silly fact about closed sets I couldn't find\n\nopen affine_algebraic_set\n\nopen_locale classical -- classical logic\n\nvariables (σ : Type*) (k : Type*) [integral_domain k]\n\nlocal notation `𝔸ⁿ` := σ → k\n\n-- Question: Let A be any subset of 𝔸ⁿ.\n-- Prove that 𝕍(𝕀(A)) is the Zariski closure of A.\n\nlemma sheet_1.question_1 (A : set 𝔸ⁿ) : 𝕍 (𝕀 A) = closure A :=\nbegin\n  -- we prove both inclusions separately.\n  apply set.subset.antisymm,\n  { -- Here we prove 𝕍 (𝕀 A) ⊆ closure A\n    -- say x ∈ 𝕍 (𝕀 A)\n    intros x hx,\n    change 𝔸ⁿ at x,\n    -- it suffices to prove that x is in every closed set containing A,\n    rw mem_closure_iff',\n    -- so let C be a closed set containing A\n    intros C hC hAC,\n    -- Because C is closed, it's 𝕍(S) for some S\n    rw is_closed_iff at hC,\n    cases hC with S hS,\n    rw hS at hAC ⊢, clear hS C,\n    -- Our goal is to prove x ∈ 𝕍 S,\n    -- or in other words that f(x) = 0 for all f ∈ S\n    rw mem_𝕍_iff,\n    -- so say g ∈ S\n    intros g hg,\n    -- now x ∈ 𝕍 (𝕀 A) by assumption, so f(x) = 0 forall f ∈ 𝕀 A,\n    rw mem_𝕍_iff at hx,\n    -- so it suffices to prove g ∈ 𝕀 A\n    apply hx, clear hx,\n    -- i.e. that f(y) = 0 for all y ∈ A\n    rw mem_𝕀_iff,\n    -- so say y ∈ A\n    intros y hy,\n    -- then y ∈ 𝕍 S,\n    replace hy := hAC hy,\n    -- so f(y) = 0 for all f ∈ S\n    rw mem_𝕍_iff at hy,\n    -- and this is what we needed\n    apply hy,\n    assumption},\n  { -- to prove the closure of A is a subset of 𝕍 (𝕀 A), it suffices\n    -- to prove that 𝕍 (𝕀 A) is closed and contains A\n    rw closure_subset_iff_subset_of_is_closed,\n    { -- The fact that A ⊆ 𝕍 (𝕀 A) is straightforward\n      intros x hx, rw mem_𝕍_iff, intros f hf, rw mem_𝕀_iff at hf, \n      apply hf, assumption\n    },\n    { -- and the fact that 𝕍 (𝕀 A) is closed follows straight from\n      -- the definition, because it's in the image of 𝕍.\n      rw is_closed_iff, use 𝕀 A}\n  }\nend\n\n-- computer science version:\nlemma sheet_1.question_1' (A : set 𝔸ⁿ) : 𝕍 (𝕀 A) = closure A :=\nset.subset.antisymm\n  (λ x hx, mem_closure_iff'.2 $ λ C hC hAC, begin\n    cases (is_closed_iff _).1 hC with S hS,\n    rw hS at hAC ⊢,\n    exact λ g hg, hx _ (λ y hy, hAC hy _ hg), \n  end)\n  ((closure_subset_iff_subset_of_is_closed $ (is_closed_iff _).2 ⟨_, rfl⟩).2 \n  (λ x hx f hf, hf _ hx))\n", "meta": {"author": "ImperialCollegeLondon", "repo": "M4P33", "sha": "1a179372db71ad6802d11eacbc1f02f327d55f8f", "save_path": "github-repos/lean/ImperialCollegeLondon-M4P33", "path": "github-repos/lean/ImperialCollegeLondon-M4P33/M4P33-1a179372db71ad6802d11eacbc1f02f327d55f8f/problem_sheets/sheet_1/question_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7554667625564996}}
{"text": "import tactic\n\nnamespace hidden\n\n\nlemma not_not_1 {P : Prop} : ¬ ¬ P → P :=\nassume a1 :  ¬ ¬ P,\nby_contradiction (\n  assume a2 : ¬ P,\n  show false, from a1 a2\n)\n\nlemma not_not_2 {P : Prop} : P → ¬ ¬ P :=\nassume a1 : P,\nassume a2 : ¬ P,\nshow false, from a2 a1\n\nlemma not_not {P : Prop} : ¬ ¬ P ↔ P :=\niff.intro not_not_1 not_not_2\n\n--------------------------------------------------------------------------------\n\nlemma contrapose_1 {P Q : Prop} : (P → Q) → (¬ Q → ¬ P) :=\nassume a1 : P → Q,\nassume a2: ¬ Q,\nby_contradiction (\n  assume a3 : ¬ ¬ P,\n  have s1 : P := not_not_1 a3,\n  have s2 : Q := a1 s1,\n  show false, from a2 s2\n)\n\nlemma contrapose_2 {P Q : Prop} : (P → ¬ Q) → (Q → ¬ P) :=\nassume a1 : P → ¬ Q,\nassume a2 : Q,\nby_contradiction (\n  assume a3 : ¬ ¬ P,\n  have s1 : P := not_not_1 a3,\n  have s2 : ¬ Q := a1 s1,\n  show false, from s2 a2\n)\n\nlemma contrapose_3 {P Q : Prop} : (¬ P → Q) → (¬ Q → P) :=\nassume a1 : ¬ P → Q,\nassume a2 : ¬ Q,\nby_contradiction (\n  assume a3 : ¬ P,\n  have s1 : Q := a1 a3,\n  show false, from a2 s1\n)\n\nlemma contrapose_4 {P Q : Prop} : (¬ P → ¬ Q) → (Q → P) :=\nassume a1 : ¬ P → ¬ Q,\nassume a2 : Q,\nby_contradiction (\n  assume a3 : ¬ P,\n  have s1 : ¬ Q := a1 a3,\n  show false, from s1 a2\n)\n\n--------------------------------------------------------------------------------\n\nlemma dm_1_a {P Q : Prop} : ¬ (P ∧ Q) → (¬ P ∨ ¬ Q) :=\nassume a1 : ¬ (P ∧ Q),\nby_contradiction (\n  assume a2 : ¬ (¬ P ∨ ¬ Q),\n  have s1 : P := (\n    by_contradiction (\n      assume a3 : ¬ P,\n      have s2 : ¬ P ∨ ¬ Q := or.intro_left (¬ Q) a3,\n      show false, from a2 s2\n    )\n  ),\n  have s3 : Q := (\n    by_contradiction (\n      assume a4 : ¬ Q,\n      have s4 : ¬ P ∨ ¬ Q := or.intro_right (¬ P) a4,\n      show false, from a2 s4\n    )\n  ),\n  have s5 : P ∧ Q := and.intro s1 s3,\n  show false, from a1 s5\n)\n\nlemma dm_1_b {P Q : Prop} : ¬ (P ∧ ¬ Q) → (¬ P ∨ Q) :=\nassume a1 : ¬ (P ∧ ¬ Q),\nby_contradiction (\n  assume a2 : ¬ (¬ P ∨ Q),\n  have s1 : P := (\n    by_contradiction (\n      assume a3 : ¬ P,\n      have s2 : ¬ P ∨ Q := or.intro_left Q a3,\n      show false, from a2 s2\n    )\n  ),\n  have s3 : ¬ Q := (\n    by_contradiction (\n      assume a4 : ¬ ¬ Q,\n      have s4 : Q := not_not_1 a4,\n      have s5 : ¬ P ∨ Q := or.intro_right (¬ P) s4,\n      show false, from a2 s5\n    )\n  ),\n  have s6 : P ∧ ¬ Q := and.intro s1 s3,\n  show false, from a1 s6\n)\n\nlemma dm_1_c {P Q : Prop} : ¬ (¬ P ∧ Q) → (P ∨ ¬ Q) :=\nassume a1 : ¬ (¬ P ∧ Q),\nby_contradiction (\n  assume a2 : ¬ (P ∨ ¬ Q),\n  have s1 : ¬ P := (\n    by_contradiction (\n      assume a3 : ¬ ¬ P,\n      have s2 : P := not_not_1 a3,\n      have s3 : P ∨ ¬ Q := or.intro_left (¬ Q) s2,\n      show false, from a2 s3\n    )\n  ),\n  have s4 : Q := (\n    by_contradiction (\n      assume a4 : ¬ Q,\n      have s5 : P ∨ ¬ Q := or.intro_right P a4,\n      show false, from a2 s5\n    )\n  ),\n  have s6 : ¬ P ∧ Q := and.intro s1 s4,\n  show false, from a1 s6\n)\n\nlemma dm_1_d {P Q : Prop} : ¬ (¬ P ∧ ¬ Q) → (P ∨ Q) :=\nassume a1 : ¬ (¬ P ∧ ¬ Q),\nby_contradiction (\n  assume a2 : ¬ (P ∨ Q),\n  have s1 : ¬ P := (\n    by_contradiction (\n      assume a3 : ¬ ¬ P,\n      have s2 : P := not_not_1 a3,\n      have s3 : P ∨ Q := or.intro_left Q s2,\n      show false, from a2 s3\n    )\n  ),\n  have s4 : ¬ Q := (\n    by_contradiction (\n      assume a4 : ¬ ¬ Q,\n      have s5 : Q := not_not_1 a4,\n      have s6 : P ∨ Q := or.intro_right P s5,\n      show false, from a2 s6\n    )\n  ),\n  have s7 : ¬ P ∧ ¬ Q := and.intro s1 s4,\n  show false, from a1 s7\n)\n\n\nlemma dm_2_a {P Q : Prop} : (¬ P ∨ ¬ Q) → ¬ (P ∧ Q) :=\nassume a1 : ¬ P ∨ ¬ Q,\nassume a2 : P ∧ Q,\nor.elim a1\n(\n  assume a3 : ¬ P,\n  have s1 : P := and.left a2,\n  show false, from a3 s1\n)\n(\n  assume a4 : ¬ Q,\n  have s2 : Q := and.right a2,\n  show false, from a4 s2\n)\n\nlemma dm_2_b {P Q : Prop} : (¬ P ∨ Q) → ¬ (P ∧ ¬ Q) :=\nassume a1 : ¬ P ∨ Q,\nassume a2 : P ∧ ¬ Q,\nor.elim a1\n(\n  assume a3 : ¬ P,\n  have s1 : P := and.left a2,\n  show false, from a3 s1\n)\n(\n  assume a4 : Q,\n  have s2 : ¬ Q := and.right a2,\n  show false, from s2 a4\n)\n\nlemma dm_2_c {P Q : Prop} : (P ∨ ¬ Q) → ¬ (¬ P ∧ Q) :=\nassume a1 : P ∨ ¬ Q,\nassume a2 : ¬ P ∧ Q,\nor.elim a1\n(\n  assume a3 : P,\n  have s1 : ¬ P := and.left a2,\n  show false, from s1 a3\n)\n(\n  assume a4 : ¬ Q,\n  have s2 : Q := and.right a2,\n  show false, from a4 s2\n)\n\nlemma dm_2_d {P Q : Prop} : (P ∨ Q) → ¬ (¬ P ∧ ¬ Q) :=\nassume a1 : P ∨ Q,\nassume a2 : ¬ P ∧ ¬ Q,\nor.elim a1\n(\n  assume a3 : P,\n  have s1 : ¬ P := and.left a2,\n  show false, from s1 a3\n)\n(\n  assume a4 : Q,\n  have s2 : ¬ Q := and.right a2,\n  show false, from s2 a4\n)\n\nlemma dm_a {P Q : Prop} : ¬ (P ∧ Q) ↔ (¬ P ∨ ¬ Q) :=\niff.intro dm_1_a dm_2_a\n\n\nlemma dm_3_a {P Q : Prop} : ¬ (P ∨ Q) → (¬ P ∧ ¬ Q) :=\nassume a1 : ¬ (P ∨ Q),\nhave s1 : ¬ P := (\n  by_contradiction (\n    assume a2 : ¬ ¬ P,\n    have s2 : P := not_not_1 a2,\n    have s3 : P ∨ Q := or.intro_left Q s2,\n    show false, from a1 s3\n  )\n),\nhave s4 : ¬ Q := (\n  by_contradiction (\n    assume a3 : ¬ ¬ Q,\n    have s5 : Q := not_not_1 a3,\n    have s6 : P ∨ Q := or.intro_right P s5,\n    show false, from a1 s6\n  )\n),\nand.intro s1 s4\n\nlemma dm_3_b {P Q : Prop} : ¬ (P ∨ ¬ Q) → (¬ P ∧ Q) :=\nassume a1 : ¬ (P ∨ ¬ Q),\nhave s1 : ¬ P := (\n  by_contradiction (\n    assume a2 : ¬ ¬ P,\n    have s2 : P := not_not_1 a2,\n    have s3 : P ∨ ¬ Q := or.intro_left (¬ Q) s2,\n    show false, from a1 s3\n  )\n),\nhave s4 : Q := (\n  by_contradiction (\n    assume a3 : ¬ Q,\n    have s5 : P ∨ ¬ Q := or.intro_right P a3,\n    show false, from a1 s5\n  )\n),\nand.intro s1 s4\n\nlemma dm_3_c {P Q : Prop} : ¬ (¬ P ∨ Q) → (P ∧ ¬ Q) :=\nassume a1 : ¬ (¬ P ∨ Q),\nhave s1 : P := (\n  by_contradiction (\n    assume a2 : ¬ P,\n    have s2 : ¬ P ∨ Q := or.intro_left Q a2,\n    show false, from a1 s2\n  )\n),\nhave s3 : ¬ Q := (\n  by_contradiction (\n    assume a3 : ¬ ¬ Q,\n    have s4 : Q := not_not_1 a3,\n    have s5 : ¬ P ∨ Q := or.intro_right (¬ P) s4,\n    show false, from a1 s5\n  )\n),\nand.intro s1 s3\n\nlemma dm_3_d {P Q : Prop} : ¬ (¬ P ∨ ¬ Q) → (P ∧ Q) :=\nassume a1 : ¬ (¬ P ∨ ¬ Q),\nhave s1 : P := (\n  by_contradiction (\n    assume a2 : ¬ P,\n    have s2 : ¬ P ∨ ¬ Q := or.intro_left (¬ Q) a2,\n    show false, from a1 s2\n  )\n),\nhave s3 : Q := (\n  by_contradiction (\n    assume a3 : ¬ Q,\n    have s4 : ¬ P ∨ ¬ Q := or.intro_right (¬ P) a3,\n    show false, from a1 s4\n  )\n),\nand.intro s1 s3\n\n\nlemma dm_4_a {P Q : Prop} : (¬ P ∧ ¬ Q) → ¬ (P ∨ Q) :=\nassume a1 : ¬ P ∧ ¬ Q,\nassume a2 : P ∨ Q,\nor.elim a2\n(\n  assume a3 : P,\n  have s1 : ¬ P := and.left a1,\n  show false, from s1 a3\n)\n(\n  assume a4 : Q,\n  have s2 : ¬ Q := and.right a1,\n  show false, from s2 a4\n)\n\nlemma dm_4_b {P Q : Prop} : (¬ P ∧ Q) → ¬ (P ∨ ¬ Q) :=\nassume a1 : ¬ P ∧ Q,\nassume a2 : P ∨ ¬ Q,\nor.elim a2\n(\n  assume a3 : P,\n  have s1 : ¬ P := and.left a1,\n  show false, from s1 a3\n)\n(\n  assume a4 : ¬ Q,\n  have s2 : Q := and.right a1,\n  show false, from a4 s2\n)\n\nlemma dm_4_c {P Q : Prop} : (P ∧ ¬ Q) → ¬ (¬ P ∨ Q) :=\nassume a1 : P ∧ ¬ Q,\nassume a2 : ¬ P ∨ Q,\nor.elim a2\n(\n  assume a3 : ¬ P,\n  have s1 : P := and.left a1,\n  show false, from a3 s1\n)\n(\n  assume a4 : Q,\n  have s2 : ¬ Q := and.right a1,\n  show false, from s2 a4\n)\n\nlemma dm_4_d {P Q : Prop} : (P ∧ Q) → ¬ (¬ P ∨ ¬ Q) :=\nassume a1 : P ∧ Q,\nassume a2 : ¬ P ∨ ¬ Q,\nor.elim a2\n(\n  assume a3 : ¬ P,\n  have s1 : P := and.left a1,\n  show false, from a3 s1\n)\n(\n  assume a4 : ¬ Q,\n  have s2 : Q := and.right a1,\n  show false, from a4 s2\n)\n\nlemma dm_b {P Q : Prop} : ¬ (P ∨ Q) ↔ (¬ P ∧ ¬ Q) :=\niff.intro dm_3_a dm_4_a\n\n--------------------------------------------------------------------------------\n\nlemma dm_quant_cp_1 {α : Type} {P : α → Prop} : ¬ (∃ x : α, ¬ P x) → (∀ x : α, P x) :=\nassume a1 : ¬ (∃ x : α, ¬ P x),\nassume x' : α,\nby_contradiction (\n  assume a2 : ¬ P x',\n  have s1 : ∃ x : α, ¬ P x := exists.intro x' a2,\n  show false, from a1 s1\n)\n\nlemma dm_quant_1 {α : Type} {P : α → Prop} : ¬ (∀ x : α, P x) → (∃ x : α, ¬ P x) :=\ncontrapose_3 dm_quant_cp_1\n\nlemma dm_quant_2 {α : Type} {P : α → Prop} : (∃ x : α, ¬ P x) → ¬ (∀ x : α, P x) :=\nassume a1 : ∃ x : α, ¬ P x,\nexists.elim a1 (\n  assume x' : α,\n  assume a2 : ¬ P x',\n  assume a3 : ∀ x : α, P x,\n  have s1 : P x' := a3 x',\n  show false, from a2 s1\n)\n\nlemma dm_quant_a {α : Type} {P : α → Prop} : ¬ (∀ x : α, P x) ↔ (∃ x : α, ¬ P x) :=\niff.intro dm_quant_1 dm_quant_2\n\n\nlemma dm_quant_3 {α : Type} {P : α → Prop} : ¬ (∃ x : α, P x) → (∀ x : α, ¬ P x) :=\nassume a1 : ¬ (∃ x : α, P x),\nassume x' : α,\nby_contradiction (\n  assume a2 : ¬ ¬ P x',\n  have s1 : P x' := not_not_1 a2,\n  have s2 : ∃ x : α, P x := exists.intro x' s1,\n  show false, from a1 s2\n)\n\nlemma dm_quant_4 {α : Type} {P : α → Prop} : (∀ x : α, ¬ P x) → ¬ (∃ x : α, P x) :=\nassume a1 : ∀ x : α, ¬ P x,\nassume a2 : ∃ x : α, P x,\nexists.elim a2 (\n  assume x' : α,\n  assume a3 : P x',\n  have s1 : ¬ P x' := a1 x',\n  show false, from s1 a3\n)\n\nlemma dm_quant_b {α : Type} {P : α → Prop} : ¬ (∃ x : α, P x) ↔ (∀ x : α, ¬ P x) :=\niff.intro dm_quant_3 dm_quant_4\n\n--------------------------------------------------------------------------------\n\nlemma dm_quant_set_cp_1 {α : Type} {S : set α} {P : α → Prop} : ¬ (∃ x ∈ S, ¬ P x) → (∀ x ∈ S, P x) :=\nassume a1 : ¬ (∃ x ∈ S, ¬ P x),\nassume x' : α,\nassume a2 : x' ∈ S,\nby_contradiction (\n  assume a3 : ¬ P x',\n  have s1 : ∃ x ∈ S, ¬ P x := exists.intro x' (exists.intro a2 a3),\n  show false, from a1 s1\n)\n\nlemma dm_quant_set_1 {α : Type} {S : set α} {P : α → Prop} : ¬ (∀ x ∈ S, P x) → (∃ x ∈ S, ¬ P x) :=\ncontrapose_3 dm_quant_set_cp_1\n\nlemma dm_quant_set_2 {α : Type} {S : set α} {P : α → Prop} : (∃ x ∈ S, ¬ P x) → ¬ (∀ x ∈ S, P x) :=\nassume a1 : ∃ x ∈ S, ¬ P x,\nexists.elim a1 (\n  assume x' : α,\n  assume a2 : ∃ (H : x' ∈ S), ¬ P x',\n  exists.elim a2 (\n    assume H0 : x' ∈ S,\n    assume a3 : ¬ P x',\n    assume a4 : ∀ x ∈ S, P x,\n    have s1 : P x' := a4 x' H0,\n    show false, from a3 s1\n  )\n)\n\nlemma dm_quant_set_a {α : Type} {S : set α} {P : α → Prop} : ¬ (∀ x ∈ S, P x) ↔ (∃ x ∈ S, ¬ P x) :=\niff.intro dm_quant_set_1 dm_quant_set_2\n\n\nlemma dm_quant_set_3 {α : Type} {S : set α} {P : α → Prop} : ¬ (∃ x ∈ S, P x) → (∀ x ∈ S, ¬ P x) :=\nassume a1 : ¬ (∃ x ∈ S, P x),\nassume x' : α,\nassume a2 : x' ∈ S,\nby_contradiction (\n  assume a3 : ¬ ¬ P x',\n  have s1 : P x' := not_not_1 a3,\n  have s2 : ∃ x ∈ S, P x := exists.intro x' (exists.intro a2 s1),\n  show false, from a1 s2\n)\n\nlemma dm_quant_set_4 {α : Type} {S : set α} {P : α → Prop} : (∀ x ∈ S, ¬ P x) → ¬ (∃ x ∈ S, P x) :=\nassume a1 : ∀ x ∈ S, ¬ P x,\nassume a2 : ∃ x ∈ S, P x,\nexists.elim a2 (\n  assume x' : α,\n  assume a3 : ∃ (H : x' ∈ S), P x',\n  exists.elim a3 (\n    assume H0 : x' ∈ S,\n    assume a4 : P x',\n    have s1 : ¬ P x' := a1 x' H0,\n    show false, from s1 a4\n  )\n)\n\nlemma dm_quant_set_b {α : Type} {S : set α} {P : α → Prop} : ¬ (∃ x ∈ S, P x) ↔ (∀ x ∈ S, ¬ P x) :=\niff.intro dm_quant_set_3 dm_quant_set_4\n\n--------------------------------------------------------------------------------\n\nexample {α : Type} {P Q : α → Prop} (h : ∀ x : α, P x → Q x) : (∀ x : α, P x) → (∀ x : α, Q x) :=\nassume a1 : ∀ x : α, P x,\nassume x' : α,\nhave s1 : P x' := a1 x',\nhave s2 : P x' → Q x' := h x',\ns2 s1\n\nexample {α : Type} {S : set α} {P Q : α → Prop} (h : ∀ x ∈ S, P x → Q x) : (∀ x ∈ S, P x) → (∀ x ∈ S, Q x) :=\nassume a1 : ∀ x ∈ S, P x,\nassume x' : α,\nassume a2 : x' ∈ S,\nhave s1 : P x' := a1 x' a2,\nhave s2 : P x' → Q x' := h x' a2,\ns2 s1\n\n\nexample {α : Type} {P Q : α → Prop} (h : ∀ x : α, P x → Q x) : (∃ x : α, P x) → (∃ x : α, Q x) :=\nassume a1 : ∃ x : α, P x,\nexists.elim a1 (\n  assume x' : α,\n  assume a2 : P x',\n  have s1 : P x' → Q x' := h x',\n  have s2 : Q x' := s1 a2,\n  exists.intro x' s2\n)\n\nexample {α : Type} {S : set α} {P Q : α → Prop} (h : ∀ x ∈ S, P x → Q x) : (∃ x ∈ S, P x) → (∃ x ∈ S, Q x) :=\nassume a1 : ∃ x ∈ S, P x,\nexists.elim a1 (\n  assume x' : α,\n  assume a2 : ∃ (H : x' ∈ S), P x',\n  exists.elim a2 (\n    assume H0 : x' ∈ S,\n    assume a3 : P x',\n    have s1 : P x' → Q x' := h x' H0,\n    have s2 : Q x' := s1 a3,\n    exists.intro x' (exists.intro H0 s2)\n  )\n)\n\n--------------------------------------------------------------------------------\n\nlemma or_comm {P Q : Prop} : (P ∨ Q) → (Q ∨ P) :=\nassume a1 : P ∨ Q,\nor.elim a1\n(\n  assume a2 : P,\n  or.intro_right Q a2\n)\n(\n  assume a3 : Q,\n  or.intro_left P a3\n)\n\n\nlemma or_implies_1 {P Q : Prop} : (P ∨ Q) → ¬ P → Q :=\nassume a1 : P ∨ Q,\nassume a2 : ¬ P,\nor.elim a1\n(\n  assume a3 : P,\n  false.elim (a2 a3)\n)\n(\n  assume a4 : Q,\n  a4\n)\n\nlemma or_implies_2 {P Q : Prop} : (P ∨ ¬ Q) → ¬ P → ¬ Q :=\nassume a1 : P ∨ ¬ Q,\nassume a2 : ¬ P,\nor.elim a1\n(\n  assume a3 : P,\n  false.elim (a2 a3)\n)\n(\n  assume a4 : ¬ Q,\n  a4\n)\n\nlemma or_implies_3 {P Q : Prop} : (¬ P ∨ Q) → P → Q :=\nassume a1 : ¬ P ∨ Q,\nassume a2 : P,\nor.elim a1\n(\n  assume a3 : ¬ P,\n  false.elim (a3 a2)\n)\n(\n  assume a4 : Q,\n  a4\n)\n\nlemma or_implies_4 {P Q : Prop} : (¬ P ∨ ¬ Q) → P → ¬ Q :=\nassume a1 : ¬ P ∨ ¬ Q,\nassume a2 : P,\nor.elim a1\n(\n  assume a3 : ¬ P,\n  false.elim (a3 a2)\n)\n(\n  assume a4 : ¬ Q,\n  a4\n)\n\n--------------------------------------------------------------------------------\n\nlemma not_and_implies_1 {P Q : Prop} : ¬ (P ∧ Q) → P → ¬ Q :=\nassume a1 : ¬ (P ∧ Q),\nor_implies_4 (dm_1_a a1)\n\nlemma not_and_implies_2 {P Q : Prop} : ¬ (P ∧ Q) → Q → ¬ P :=\nassume a1 : ¬ (P ∧ Q),\nor_implies_4 (or_comm (dm_1_a a1))\n\n\nlemma not_and_implies_3 {P Q : Prop} : ¬ (P ∧ ¬ Q) → P → Q :=\nassume a1 : ¬ (P ∧ ¬ Q),\nor_implies_3 (dm_1_b a1)\n\nlemma not_and_implies_4 {P Q : Prop} : ¬ (P ∧ ¬ Q) → ¬ Q → ¬ P :=\nassume a1 : ¬ (P ∧ ¬ Q),\nor_implies_2 (or_comm (dm_1_b a1))\n\n\nlemma not_and_implies_5 {P Q : Prop} : ¬ (¬ P ∧ Q) → ¬ P → ¬ Q :=\nassume a1 : ¬ (¬ P ∧ Q),\nor_implies_2 (dm_1_c a1)\n\nlemma not_and_implies_6 {P Q : Prop} : ¬ (¬ P ∧ Q) → Q → P :=\nassume a1 : ¬ (¬ P ∧ Q),\nor_implies_3 (or_comm (dm_1_c a1))\n\n\nlemma not_and_implies_7 {P Q : Prop} : ¬ (¬ P ∧ ¬ Q) → ¬ P → Q :=\nassume a1 : ¬ (¬ P ∧ ¬ Q),\nor_implies_1 (dm_1_d a1)\n\nlemma not_and_implies_8 {P Q : Prop} : ¬ (¬ P ∧ ¬ Q) → ¬ Q → P :=\nassume a1 : ¬ (¬ P ∧ ¬ Q),\nor_implies_1 (or_comm (dm_1_d a1))\n\n--------------------------------------------------------------------------------\n\ndef set (α : Type) := α → Prop\n\n-- a is an element of the set s.\ndef mem {α : Type} (a : α) (s : set α) : Prop := s a\n\nnotation x `∈` S := mem x S\nnotation x `∉` S := ¬ mem x S\n\n\n-- The set containing only a.\ndef singleton {α : Type} (a : α) : set α := fun x, x = a\n\nnotation `{` x `}` := singleton x\n\nexample {α : Type} {a b : α} : mem a (singleton b) = (a = b) := by refl\n\n\n-- The union of the sets s and t.\ndef union {α : Type} (s t : set α) : set α :=\nfun x, (mem x s) ∨ (mem x t)\n\nnotation s `∪`  t := union s t\n\nexample {α : Type} {s t : set α} {x : α} : mem x (union s t) = ((mem x s) ∨ (mem x t)) := by refl\n\n\n-- The intersection of the sets s and t.\ndef inter {α : Type} (s t : set α) : set α :=\nfun x, (mem x s) ∧ (mem x t)\n\nnotation s `∩` t := inter s t\n\nexample {α : Type} {s t : set α} {x : α} : mem x (inter s t) = ((mem x s) ∧ (mem x t)) := by refl\n\n\n-- The difference of the sets s and t.\ndef diff {α : Type} (s t : set α) : set α :=\nfun x, (mem x s) ∧ ¬ (mem x t)\n\nnotation s `\\` t := diff s t\n\nexample {α : Type} {s t : set α} {x : α} : mem x (diff s t) = ((mem x s) ∧ ¬ (mem x t)) := by refl\n\n\n-- The complement of the set s.\ndef compl {α : Type} (s : set α) : set α :=\nfun x, ¬ mem x s\n\nexample {α : Type} {s t : set α} {x : α} : mem x (compl s) = ¬ mem x s := by refl\n\n--------------------------------------------------------------------------------\n\ndef var := ℕ\n\ninductive pre_term : Type\n| var : var → pre_term\n| app : pre_term → pre_term → pre_term\n| abs : var → pre_term → pre_term\n\nnotation `λ` y `.` P := pre_term.abs y P\n\n\ndef FV : pre_term → set var\n| (pre_term.var x) := {x}\n| (pre_term.app P Q) := (FV P) ∪ (FV Q)\n| (pre_term.abs x P) := (FV P) \\ {x}\n\n\n-- sub_is_def M x N means M [ x := N ] is defined\ninductive sub_is_def : pre_term → var → pre_term → Prop\n\n-- y [ x := N ] is defined\n| var (y : var) (x : var) (N : pre_term) :\n  sub_is_def (pre_term.var y) x N\n\n-- P [ x := N ] is defined → Q [ x := N ] is defined → (P Q) [ x := N ] is defined\n| app (P : pre_term) (Q : pre_term) (x : var) (N : pre_term) :\n  sub_is_def P x N → sub_is_def Q x N → sub_is_def (pre_term.app P Q) x N\n\n-- x = y → ( λ y . P ) [ x := N ] is defined\n| abs_same (y : var) (P : pre_term) (x : var) (N : pre_term) :\n  x = y → sub_is_def (pre_term.abs y P) x N\n\n-- x ≠ y → x ∉ FV ( λ y . P ) → ( λ y . P ) [ x := N ] is defined\n| abs_diff_nel (y : var) (P : pre_term) (x : var) (N : pre_term) :\n  x ≠ y → x ∉ FV (pre_term.abs y P) → sub_is_def (pre_term.abs y P) x N\n\n-- x ≠ y → y ∉ FV ( N ) → P [ x := N ] is defined → ( λ y . P ) [ x := N ] is defined\n| abs_diff (y : var) (P : pre_term) (x : var) (N : pre_term) :\n  x ≠ y → y ∉ FV N → sub_is_def P x N → sub_is_def (pre_term.abs y P) x N\n\nnotation M `[` x `:=` N `]` `is_def` := sub_is_def M x N\n\n\n-- M [ x := N ]\ndef sub : pre_term → var → pre_term → pre_term\n-- if x = y then y [ x := N ] = N else y [ x := N ] = y\n| (pre_term.var y) x N := if (x = y) then N else (pre_term.var y)\n\n-- (P Q) [ x := N ] = (P [ x := N ] Q [ x := N ])\n| (pre_term.app P Q) x N := pre_term.app (sub P x N) (sub Q x N)\n\n-- if x = y then ( λ y . P ) [ x := N ] = ( λ y . P ) else ( λ y . P ) [ x := N ] = ( λ y . P [ x := N ] )\n| (pre_term.abs y P) x N := if x = y then (pre_term.abs y P) else (pre_term.abs y (sub P x N))\n\nnotation M `[` x `:=` N `]` := sub M x N\n\n\nlemma lemma_1_2_5_i_a (M : pre_term) (x : var) (N : pre_term) : x ∉ FV M → M [ x := N ] is_def :=\nbegin\nassume a1 : x ∉ FV M,\ninduction M,\ncase pre_term.var : y\n{\n  -- M = pre_term.var y\n  show (pre_term.var y) [ x := N ] is_def, by exact sub_is_def.var y x N\n},\ncase pre_term.app : P Q IH_1 IH_2\n{\n  -- M = pre_term.app P Q\n  have s1 : x ∉ FV (pre_term.app P Q), by exact a1,\n  have s2 : x ∉ FV P → P [ x := N ] is_def, by exact IH_1,\n  have s3 : x ∉ FV Q → Q [ x := N ] is_def, by exact IH_2,\n  have s4 : (x ∉ FV P) ∧ (x ∉ FV Q), by exact dm_3_a s1,\n  have s5 : P [ x := N ] is_def, by exact s2 (and.left s4),\n  have s6 : Q [ x := N ] is_def, by exact s3 (and.right s4),\n  show (pre_term.app P Q) [ x := N ] is_def, by exact sub_is_def.app P Q x N s5 s6\n},\ncase pre_term.abs : y P\n{\n  -- M = pre_term.abs y P\n  by_cases x = y,\n  {\n    have s7: x = y, by exact h,\n    show (pre_term.abs y P) [ x := N ] is_def, by exact (sub_is_def.abs_same y P x N) s7\n  },\n  {\n    have s8 : x ≠ y, by exact h,\n    have s9 : x ∉ FV (pre_term.abs y P), by exact a1,\n    show (pre_term.abs y P) [ x := N ] is_def, by exact (sub_is_def.abs_diff_nel y P x N) s8 s9\n  }\n}\nend\n\n\nlemma lemma_1_2_5_i_b (M : pre_term) (x : var) (N : pre_term) : x ∉ FV M → M [ x := N ] = M :=\nbegin\nassume a1 : x ∉ FV M,\ninduction M,\ncase pre_term.var : y\n{\n  -- M = pre_term.var y\n  have s1 : x ≠ y, by exact a1,\n  show (pre_term.var y) [ x := N ] = (pre_term.var y), by exact if_neg s1\n},\ncase pre_term.app : P Q IH_1 IH_2\n{\n  -- M = pre_term.app P Q\n  have s2 : x ∉ FV (pre_term.app P Q), by exact a1,\n  have s3 : x ∉ FV P → P [ x := N ] = P, by exact IH_1,\n  have s4 : x ∉ FV Q → Q [ x := N ] = Q, by exact IH_2,\n  have s5 : (x ∉ FV P) ∧ (x ∉ FV Q), by exact dm_3_a s2,\n  have s6 : P [ x := N ] = P, by exact s3 (and.left s5),\n  have s7 : Q [ x := N ] = Q, by exact s4 (and.right s5),\n  have s8 : (pre_term.app P Q) [ x := N ] = pre_term.app (P [ x := N ]) (Q [ x := N ]), by refl,\n  have s9 : pre_term.app (P [ x := N ]) (Q [ x := N ]) = pre_term.app P (Q [ x := N ]), by rw s6,\n  have s10 : pre_term.app P (Q [ x := N ]) = pre_term.app P Q, by rw s7,\n  show (pre_term.app P Q) [ x := N ] = pre_term.app P Q, by exact eq.trans (eq.trans s8 s9) s10\n},\ncase pre_term.abs : y P IH\n{\n  -- M = pre_term.abs y P\n  by_cases (x = y),\n  {\n    have s11 : x = y, by exact h,\n    show (pre_term.abs y P) [ x := N ] = pre_term.abs y P, by exact if_pos s11\n  },\n  {\n    have s12 : x ≠ y, by exact h,\n    have s13 : x ∉ FV (pre_term.abs y P), by exact a1,\n    have s14 : x ∉ FV P → P [ x := N ] = P, by exact IH,\n    have s15 : x ∉ FV P, by exact not_and_implies_4 s13 s12,\n    have s16 : P [ x := N ] = P, by exact s14 s15,\n    have s17 : (pre_term.abs y P) [ x := N ] = pre_term.abs y (P [ x := N ]), by exact if_neg s12,\n    have s18 : pre_term.abs y (P [ x := N ]) = pre_term.abs y P, by rw s16,\n    show (pre_term.abs y P) [ x := N ] = pre_term.abs y P, by exact eq.trans s17 s18\n  }\n}\nend\n\n--------------------------------------------------------------------------------\n\nclass total_order (T : Type*) :=\n(le : T → T → Prop)\n(le_asymm : ∀ {x y : T}, le x y → le y x → x = y)\n(le_trans : ∀ {x y z : T}, le x y → le y z → le x z)\n(le_conn : ∀ {x y : T}, le x y ∨ le y x)\n\nopen total_order\n\n\n-- x < y\ndef lt {T : Type*} [total_order T] (x y : T) : Prop := le x y ∧ ¬ x = y\n\n-- x ≥ y\ndef ge {T : Type*} [total_order T] (x y : T) : Prop := le y x\n\n-- x > y\ndef gt {T : Type*} [total_order T] (x y : T) : Prop := ge x y ∧ ¬ x = y\n\n\nlemma ne_symm {α : Type*} {x y : α} : ¬ x = y → ¬ y = x :=\nassume a1 : ¬ x = y,\nassume a2 : y = x,\nhave s1 : x = y := eq.symm a2,\nshow false, from a1 s1\n\n\nlemma lt_to_gt {T : Type*} [total_order T] {x y : T} : lt x y → gt y x :=\nassume a1 : lt x y,\nhave s1 : le x y := and.left a1,\nhave s2 : ge y x := s1,\nhave s3 : ¬ x = y := and.right a1,\nhave s4 : ¬ y = x := ne_symm s3,\nand.intro s1 s4\n\nlemma gt_to_lt {T : Type*} [total_order T] {x y : T} : gt x y → lt y x :=\nassume a1 : gt x y,\nhave s1 : ge x y := and.left a1,\nhave s2 : le y x := s1,\nhave s3 : ¬ x = y := and.right a1,\nhave s4 : ¬ y = x := ne_symm s3,\nand.intro s1 s4\n\n\nlemma ge_asymm {T : Type*} [total_order T] {x y : T} : ge x y → ge y x → x = y :=\nassume a1 : ge x y,\nassume a2 : ge y x,\nhave s1 : le y x := a1,\nhave s2 : le x y := a2,\nle_asymm s2 s1\n\n\nlemma ge_trans {T : Type*} [total_order T] {x y z : T} : ge x y → ge y z → ge x z :=\nassume a1 : ge x y,\nassume a2 : ge y z,\nhave s1 : le y x := a1,\nhave s2 : le z y := a2,\nle_trans s2 s1\n\n\nlemma ge_conn {T : Type*} [total_order T] {x y : T} : ge x y ∨ ge y x :=\nhave s1 : le x y ∨ le y x := le_conn,\nor.elim s1\n(\n  assume a1 : le x y,\n  have s2 : ge y x := a1,\n  or.intro_right (ge x y) s2\n)\n(\n  assume a2 : le y x,\n  have s3 : ge x y := a2,\n  or.intro_left (ge y x) s3\n)\n\n\nlemma le_refl {T : Type*} [total_order T] {x : T} : le x x :=\nhave s1 : le x x ∨ le x x := le_conn,\nor.elim s1\n(\n  assume a1 : le x x,\n  a1\n)\n(\n  assume a2 : le x x,\n  a2\n)\n\nlemma ge_refl {T : Type*} [total_order T] {x : T} : ge x x :=\nhave s1 : ge x x ∨ ge x x := ge_conn,\nor.elim s1\n(\n  assume a1 : ge x x,\n  a1\n)\n(\n  assume a2 : ge x x,\n  a2\n)\n\n\nlemma not_lt_refl {T : Type*} [total_order T] {x : T} : ¬ lt x x :=\nassume a1 : lt x x,\nhave s1 : ¬ x = x := and.right a1,\nhave s2 : x = x := eq.refl x,\nshow false, from s1 s2\n\nlemma not_gt_refl {T : Type*} [total_order T] {x : T} : ¬ gt x x :=\nassume a1 : gt x x,\nhave s1 : ¬ x = x := and.right a1,\nhave s2 : x = x := eq.refl x,\nshow false, from s1 s2\n\n\nlemma le_lt_trans {T : Type*} [total_order T] {x y z : T} : le x y → lt y z → lt x z :=\nassume a1 : le x y,\nassume a2 : lt y z,\nhave s1 : le y z := and.left a2,\nhave s2 : ¬ y = z := and.right a2,\nhave s3 : le x z := le_trans a1 s1,\nhave s4 : ¬ x = z :=\nby_contradiction (\n  assume a3: ¬ ¬ x = z,\n  have s5 : x = z := not_not_1 a3,\n  have s6 : le z y := eq.subst s5 a1,\n  have s7 : y = z := le_asymm s1 s6,\n  show false, from s2 s7\n),\nand.intro s3 s4\n\nlemma lt_le_trans {T : Type*} [total_order T] {x y z : T} : lt x y → le y z → lt x z :=\nassume a1 : lt x y,\nassume a2 : le y z,\nhave s1 : le x y := and.left a1,\nhave s2 : ¬ x = y := and.right a1,\nhave s3 : le x z := le_trans s1 a2,\nhave s4 : ¬ x = z :=\nby_contradiction (\n  assume a3 : ¬ ¬ x = z,\n  have s5 : x = z := not_not_1 a3,\n  have s6 : le y x := eq.subst (eq.symm s5) a2,\n  have s7 : x = y := le_asymm s1 s6,\n  show false, from s2 s7\n),\nand.intro s3 s4\n\nlemma lt_lt_trans {T : Type*} [total_order T] {x y z : T} : lt x y → lt y z → lt x z :=\nassume a1 : lt x y,\nassume a2 : lt y z,\nhave s1 : le x y := and.left a1,\nle_lt_trans s1 a2\n\n\nlemma ge_gt_trans {T : Type*} [total_order T] {x y z : T} : ge x y → gt y z → gt x z :=\nassume a1 : ge x y,\nassume a2 : gt y z,\nhave s1 : ge y z := and.left a2,\nhave s2 : ¬ y = z := and.right a2,\nhave s3 : ge x z := ge_trans a1 s1,\nhave s4 : ¬ x = z :=\nby_contradiction (\n  assume a3: ¬ ¬ x = z,\n  have s5 : x = z := not_not_1 a3,\n  have s6 : ge z y := eq.subst s5 a1,\n  have s7 : y = z := ge_asymm s1 s6,\n  show false, from s2 s7\n),\nand.intro s3 s4\n\nlemma gt_ge_trans {T : Type*} [total_order T] {x y z : T} : gt x y → ge y z → gt x z :=\nassume a1 : gt x y,\nassume a2 : ge y z,\nhave s1 : ge x y := and.left a1,\nhave s2 : ¬ x = y := and.right a1,\nhave s3 : ge x z := ge_trans s1 a2,\nhave s4 : ¬ x = z :=\nby_contradiction (\n  assume a3 : ¬ ¬ x = z,\n  have s5 : x = z := not_not_1 a3,\n  have s6 : ge y x := eq.subst (eq.symm s5) a2,\n  have s7 : x = y := ge_asymm s1 s6,\n  show false, from s2 s7\n),\nand.intro s3 s4\n\nlemma gt_gt_trans {T : Type*} [total_order T] {x y z : T} : gt x y → gt y z → gt x z :=\nassume a1 : gt x y,\nassume a2 : gt y z,\nhave s1 : ge x y := and.left a1,\nge_gt_trans s1 a2\n\n\nlemma le_to_or {T : Type*} [total_order T] {x y : T} : le x y → (lt x y ∨ x = y) :=\nassume a1 : le x y,\nby_contradiction (\n  assume a2 : ¬ (lt x y ∨ x = y),\n  have s1 : ¬ lt x y ∧ ¬ x = y := dm_3_a a2,\n  have s2 : ¬ (le x y ∧ ¬ x = y) := and.left s1,\n  have s3 : ¬ x = y := and.right s1,\n  have s4 : ¬ le x y ∨ x = y := dm_1_b s2,\n  or.elim s4\n  (\n    assume a3 : ¬ le x y,\n    show false, from a3 a1\n  )\n  (\n    assume a4 : x = y,\n    show false, from s3 a4\n  )\n)\n\n\nlemma or_to_le {T : Type*} [total_order T] {x y : T} : (lt x y ∨ x = y) → le x y :=\nassume a1 : lt x y ∨ x = y,\nor.elim a1\n(\n  assume a2 : lt x y,\n  have s1 : le x y ∧ ¬ x = y := a2,\n  and.left s1\n)\n(\n  assume a3 : x = y,\n  have s2 : le x x := le_refl,\n  eq.subst a3 s2\n)\n\n\nlemma ge_to_or {T : Type*} [total_order T] {x y : T} : ge x y → (gt x y ∨ x = y) :=\nassume a1 : ge x y,\nby_contradiction (\n  assume a2 : ¬ (gt x y ∨ x = y),\n  have s1 : ¬ gt x y ∧ ¬ x = y := dm_3_a a2,\n  have s2 : ¬ (ge x y ∧ ¬ x = y) := and.left s1,\n  have s3 : ¬ x = y := and.right s1,\n  have s4 : ¬ ge x y ∨ x = y := dm_1_b s2,\n  or.elim s4\n  (\n    assume a3 : ¬ ge x y,\n    show false, from a3 a1\n  )\n  (\n    assume a4 : x = y,\n    show false, from s3 a4\n  )\n)\n\nlemma or_to_ge {T : Type*} [total_order T] {x y : T} : (gt x y ∨ x = y) → ge x y :=\nassume a1 : gt x y ∨ x = y,\nor.elim a1\n(\n  assume a2 : gt x y,\n  have s1 : ge x y ∧ ¬ x = y := a2,\n  and.left s1\n)\n(\n  assume a3 : x = y,\n  have s2 : ge x x := ge_refl,\n  eq.subst a3 s2\n)\n\n\nexample {T : Type*} [total_order T] {x y : T} : lt x y → ¬ ge x y :=\nassume a1 : lt x y,\nassume a2 : ge x y,\nhave s1 : le x y := and.left a1,\nhave s2 : ¬ x = y := and.right a1,\nhave s3 : le y x := a2,\nhave s4 : x = y := le_asymm s1 s3,\nshow false, from s2 s4\n\n\nexample {T : Type*} [total_order T] {x y : T} : ¬ ge x y → ¬ x = y :=\nassume a1 : ¬ ge x y,\nassume a2 : x = y,\nhave s1 : ge x x := ge_refl,\nhave s2 : ge x y := eq.subst a2 s1,\nshow false, from a1 s2\n\n\nexample {T : Type*} [total_order T] {x y : T} : ¬ ge x y → le x y :=\nassume a1 : ¬ ge x y,\nhave s1 : ¬ le y x := a1,\nhave s2 : le x y ∨ le y x := le_conn,\nor.elim s2\n(\n  assume a2 : le x y,\n  a2\n)\n(\n  assume a3 : le y x,\n  false.elim (s1 a3)\n)\n\n\nexample {T : Type*} [total_order T] {x y : T} : gt x y → ¬ le x y :=\nassume a1 : gt x y,\nassume a2 : le x y,\nhave s1 : ge x y := and.left a1,\nhave s2 : ¬ x = y := and.right a1,\nhave s3 : ge y x := a2,\nhave s4 : x = y := ge_asymm s1 s3,\nshow false, from s2 s4\n\n\nexample {T : Type*} [total_order T] {x y : T} : ¬ le x y → ¬ x = y :=\nassume a1 : ¬ le x y,\nassume a2 : x = y,\nhave s1 : le x x := le_refl,\nhave s2 : le x y := eq.subst a2 s1,\nshow false, from a1 s2\n\n\nexample {T : Type*} [total_order T] {x y : T} : ¬ le x y → ge x y :=\nassume a1 : ¬ le x y,\nhave s1 : ¬ ge y x := a1,\nhave s2 : ge x y ∨ ge y x := ge_conn,\nor.elim s2\n(\n  assume a2 : ge x y,\n  a2\n)\n(\n  assume a3 : ge y x,\n  false.elim (s1 a3)\n)\n\n--------------------------------------------------------------------------------\n\nclass field (F : Type) extends has_add F, has_neg F, has_zero F, has_mul F, has_inv F, has_one F :=\n(add_assoc : ∀ x y z : F, x + (y + z) = (x + y) + z)\n(add_comm : ∀ x y : F, x + y = y + x)\n(add_neg_left : ∀ x : F, -x + x = 0)\n(add_zero_left : ∀ x : F, 0 + x = x)\n(mul_assoc : ∀ x y z : F, x * (y * z) = (x * y) * z)\n(mul_comm : ∀ x y : F, x * y = y * x)\n(mul_inv_left : ∀ x : F, ¬ x = 0 → x⁻¹ * x = 1)\n(mul_one_left : ∀ x : F, 1 * x = x)\n(dist_left : ∀ x y z : F, x * (y + z) = (x * y) + (x * z))\n(zero_inv : (0 : F)⁻¹ = 0)\n\nopen hidden.field\n\n\nlemma add_idempotent {F : Type} [field F] : ∀ x : F, x + x = x → x = 0 :=\nassume x : F,\nassume a1 : x + x = x,\ncalc\nx   = 0 + x        : eq.symm (add_zero_left x)\n... = (-x + x) + x : by rw (add_neg_left x)\n... = -x + (x + x) : eq.symm (add_assoc (-x) x x)\n... = -x + x       : by rw a1\n... = 0            : add_neg_left x\n\n\nlemma add_neg_right {F : Type} [field F] : ∀ x : F, x + -x = 0 :=\nassume x : F,\nhave s1 : (x + -x) + (x + -x) = x + -x := (\ncalc\n(x + -x) + (x + -x) = x + (-x + (x + -x)) : eq.symm (add_assoc x (-x) (x + -x))\n                ... = x + ((-x + x) + -x) : by rw (add_assoc (-x) x (-x))\n                ... = x + (0 + -x)        : by rw (add_neg_left x)\n                ... = x + -x              : by rw (add_zero_left (-x))\n),\nadd_idempotent (x + -x) s1\n\n\nlemma add_zero_right {F : Type} [field F] : ∀ x : F, x + 0 = x :=\nassume x : F,\ncalc\nx + 0 = x + (-x + x) : by rw (add_neg_left x)\n  ... = (x + -x) + x : add_assoc x (-x) x\n  ... = 0 + x        : by rw add_neg_right\n  ... = x            : add_zero_left x\n\n\nexample (F : Type) [field F] (neg' : F → F) (add_neg_left' : ∀ x : F, (neg' x) + x = 0) : ∀ x : F, neg' x = -x :=\nassume x : F,\ncalc\nneg' x = neg' x + 0        : eq.symm (add_zero_right (neg' x))\n   ... = neg' x + (x + -x) : by rw (add_neg_right x)\n   ... = (neg' x + x) + -x : add_assoc (neg' x) x (-x)\n   ... = 0 + -x            : by rw (add_neg_left' x)\n   ... = -x                : add_zero_left (-x)\n\n\nexample (F : Type) [field F] (zero' : F) (add_zero_left' : ∀ x : F, zero' + x = x) : zero' = 0 :=\nhave s1 : zero' + zero' = zero' := add_zero_left' zero',\nadd_idempotent zero' s1\n\n\nlemma add_left_cancel {F : Type} [field F] : ∀ x y z : F, x + y = x + z → y = z :=\nassume x y z : F,\nassume a1 : x + y = x + z,\ncalc\ny   = 0 + y        : eq.symm (add_zero_left y)\n... = (-x + x) + y : by rw (add_neg_left x)\n... = -x + (x + y) : eq.symm (add_assoc (-x) x y)\n... = -x + (x + z) : by rw a1\n... = (-x + x) + z : add_assoc (-x) x z\n... = 0 + z        : by rw (add_neg_left x)\n... = z            : add_zero_left z\n\n\nlemma add_right_cancel {F : Type} [field F] : ∀ x y z : F, y + x = z + x → y = z :=\nassume x y z : F,\nassume a1 : y + x = z + x,\ncalc\ny   = y + 0        : eq.symm (add_zero_right y)\n... = y + (x + -x) : by rw (add_neg_right x)\n... = (y + x) + -x : add_assoc y x (-x)\n... = (z + x) + -x : by rw a1\n... = z + (x + -x) : eq.symm (add_assoc z x (-x))\n... = z + 0        : by rw (add_neg_right x)\n... = z            : add_zero_right z\n\n\nlemma add_1 {F : Type} [field F] : ∀ x y : F, x + y = x → y = 0 :=\nassume x y : F,\nassume a1 : x + y = x,\nhave s1 : x = x + 0 := eq.symm (add_zero_right x),\nhave s2 : x + y = x + 0 := eq.trans a1 s1,\nadd_left_cancel x y 0 s2\n\n\nlemma add_2 {F : Type} [field F] : ∀ x y : F, x + y = 0 → y = -x :=\nassume x y : F,\nassume a1 : x + y = 0,\nhave s1 : 0 = x + -x := eq.symm (add_neg_right x),\nhave s2 : x + y = x + -x := eq.trans a1 s1,\nadd_left_cancel x y (-x) s2\n\n\nlemma neg_neg {F : Type} [field F] : ∀ x : F, x = -(-x) :=\nassume x : F,\nhave s1 : -x + x = 0 := add_neg_left x,\nadd_2 (-x) x s1\n\n\nlemma mul_idempotent {F : Type} [field F] : ∀ x : F, ¬ x = 0 → x * x = x → x = 1 :=\nassume x : F,\nassume a1 : ¬ x = 0,\nassume a2 : x * x = x,\ncalc\nx   = 1 * x         : eq.symm (mul_one_left x)\n... = (x⁻¹ * x) * x : by rw (mul_inv_left x a1)\n... = x⁻¹ * (x * x) : eq.symm (mul_assoc x⁻¹ x x)\n... = x⁻¹ * x       : by rw a2\n... = 1             : mul_inv_left x a1\n\n\nlemma mul_zero_right {F : Type} [field F] : ∀ x : F, x * 0 = 0 :=\nassume x : F,\ncalc\nx * 0 = 0 + (x * 0)                    : eq.symm (add_zero_left (x * 0))\n  ... = (-(x * 0) + (x * 0)) + (x * 0) : by rw (add_neg_left (x * 0))\n  ... = -(x * 0) + ((x * 0) + (x * 0)) : eq.symm (add_assoc (-(x * 0)) (x * 0) (x * 0))\n  ... = -(x * 0) + (x * (0 + 0))       : by rw (dist_left x 0 0)\n  ... = -(x * 0) + (x * 0)             : by rw (add_zero_left (0 : F))\n  ... = 0                              : add_neg_left (x * 0)\n\n\nend hidden\n\n", "meta": {"author": "pthomas505", "repo": "lean3", "sha": "eb449be2b9a92becda4be38aac76e080194e3f7c", "save_path": "github-repos/lean/pthomas505-lean3", "path": "github-repos/lean/pthomas505-lean3/lean3-eb449be2b9a92becda4be38aac76e080194e3f7c/src/all.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7554193532608072}}
{"text": "import tactic\nimport data.nat.prime\n-- the next two lines let us use the by_cases tactic without trouble\n-- noncomputable theory\n-- open_locale classical\n\n\n-- 2.1.2. Proofs as functions\n\n-- Every time you successfully construct a proof of a theorem say\ntheorem tautology (P : Prop) : P → P :=\nbegin\n  intro hp,\n  exact hp,\nend\n\n-- Lean constructs a proof term tautology : ∀ P : Prop, P → P (you can see this by typing #check tautology).\n#check tautology\n\n\n-- Once constructed, any term can be used in a later proof. For example,\nexample (P Q : Prop) : (P → Q) → (P → Q) :=\nbegin\n  exact tautology (P → Q),\nend\n\n-- This is how Lean simulates mathematics.\n-- Every time you prove a theorem using tactics a proof term gets created.\n-- Because of proof irrelevance, Lean forgets the exact content of the proof and only remembers its type.\n-- All the proof terms can then be used in later proofs.\n-- All of this falls under the giant umbrella of the Curry–Howard correspondence.\n\n-- 2.2 And / Or\n\n/--------------------------------------------------------------------------\n\n``cases``\n\n  ``cases`` is a general tactic that breaks up complicated terms.\n  If ``hpq`` is a term of type ``P ∧ Q`` or ``P ∨ Q`` or ``P ↔ Q``, then use\n  ``cases hpq with hp hq,``.\n\n``split``\n\n  If the target of the current goal is ``P ∧ Q`` or ``P ↔ Q``, then use\n  ``split,``.\n\n``left``/``right``\n\n  If the target of the current goal is ``P ∨ Q``, then use\n  either ``left,`` or ``right,`` (choose wisely).\n\n``exfalso``\n\n  Changes the target of the current goal to ``false``.\n\nDelete the ``sorry,`` below and replace them with a legitimate proof.\n\n--------------------------------------------------------------------------/\n\nexample (P Q : Prop) : P ∧ Q → Q ∧ P :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  split,\n  exact hq,\n  exact hp,\nend\n\nexample (P Q : Prop) : P ∨ Q → Q ∨ P :=\nbegin\n  intro hpq,\n  cases hpq with hp hq,\n  {\n    right,\n    exact hp,\n  }, {\n    left,\n    exact hq,\n  }\nend\n\nexample (P Q R : Prop) : P ∧ false ↔ false :=\nbegin\n  split,\n  {\n    -- here we need to prove P ∧ false → false\n    intro hPnFalse,\n    cases hPnFalse with hp hfalse,\n    exact hfalse,\n  },\n  {\n      -- here we need to prove false → P ∧ false\n      intro h,\n      exfalso,\n      exact h,\n  }\nend\n\ntheorem principle_of_explosion (P Q : Prop) : P ∧ ¬ P → Q :=\nbegin\n  intro hPnP,\n  cases hPnP with hP hnP,\n  exfalso,\n  apply hnP,\n  exact hP,\nend\n\n-- 2.3. Quantifiers\n\n-- 2.3.1. Barber paradox\n\n/--------------------------------------------------------------------------\n\n``by_cases``\n\n  If ``P`` is a proposition, then ``by_cases P,`` creates two goals,\n    the first with a hypothesis ``hp: P`` and\n    second with a hypothesis ``hp: ¬ P``.\n\nDelete the ``sorry,`` below and replace them with a legitimate proof.\n\n--------------------------------------------------------------------------/\n\n-- men is type.\n-- x : men means x is a man in the town\n-- shaves x y is inhabited if x shaves y\n\nvariables (men : Type) (barber : men)\nvariable  (shaves : men → men → Prop)\n\n/--------------------------------------------------------------------------\nThe claim is that in a certain town there is a (male) barber that shaves all\nthe men who do not shave themselves. (Why is this a paradox?) Prove that this\nis a contradiction.\n\nI found this complicated - the outline of the proof is as follows:\n\nUse proof by contradiction, so first assume\n  shaves barber x ↔ ¬ shaves x x\nI.e. we are assuming both\n  p1: shaves barber x → ¬ shaves x x\nand\n  p2: ¬ shaves x x → shaves barber x\n\nassume shaves barber x\nthen by p1, we also have ¬ shaves x x\nbut barber is a man and this means ¬ shaves barber x\nwhich is a contradiction.\nThis contradiction means the assumption above is invalid and so ¬ assume shaves barber x\n\nNow assuming\n¬ shaves barber x\nthen by p2 we must have shaves barber x\nthis is also a contraction.\n\nThis second contraction, means the initial assumption was wrong and so\nthis completes the proof.\n---------------------------------------------------------------------------/\n\nexample : ¬ (∀ x : men, shaves barber x ↔ ¬ shaves x x) :=\nbegin\n  -- we prove by contradiction, so assume it's true\n  by_contradiction,\n  -- x is a barber\n  have x := barber,\n  -- h is currently (x : men), shaves barber x ↔ ¬shaves x x\n  -- so lets specialize to just get\n  -- h : h: shaves barber barber ↔ ¬shaves barber barber\n  specialize h barber,\n  -- since h is a ↔ hypothesis, we do cases on it.\n  cases h with p1 p2,\n  by_cases shaves barber barber,\n  {\n    -- goal here is false, and have h : shaves barber barber\n    -- show false, from p1 h h, -- this is one line that will solve the goal\n    -- apply p1 h h, -- this line also on it's own solves the goal\n    apply p1 h,\n    exact h,\n    -- remember, goal was false and\n    -- ¬ shaves barber barber is the same as shaves barber barber → false\n    -- so applying p1: shaves barber barber → ¬shaves barber barber\n    -- gives shaves barber barber and this is exactly h\n  },\n  {\n    -- goal here is false and have h : ¬ shaves barber barber\n    -- show false, from h (p2 h), -- solves this is onle line\n    -- apply h (p2 h), -- this also solves the goal in one line\n    apply h,\n    apply p2,\n    exact h,\n    -- again goal was false, and h is\n    -- ¬shaves barber barber which is the same as shaves barber barber → false\n    -- so we can apply h on false to give goal of\n    -- shaves barber barber\n    -- now p2 is  ¬shaves barber barber → shaves barber barber\n    -- so after applying this, we get goal of ¬ shaves barber barber\n    -- and this is exactly h.\n\n  }\nend\n\n\n--- temp, the following are various proofs found on the internet that I used to help me to write the proof above.\n\n-- standalone\n-- See https://github.com/hyponymous/theorem-proving-in-lean-solutions/blob/a95320ae81c90c1b15da04574602cd378794400d/4.6.3.lean\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\nhave hparadox : shaves barber barber ↔ ¬shaves barber barber, from\n    (h barber),\nhave hn_self_shave : ¬shaves barber barber, from\n    (show shaves barber barber → 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\nexample (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\nbegin\n  -- goal is false\n  have hparadox : shaves barber barber ↔ ¬shaves barber barber, from\n      (h barber),\n  -- now have hypothesis : shaves barber barber ↔ ¬shaves barber barber\n  have hn_self_shave : ¬shaves barber barber, from\n      (show shaves barber barber → false, from\n          assume h_self_shave : shaves barber barber,\n          absurd h_self_shave (hparadox.mp h_self_shave)),\n  -- now also have hypotheisis :  ¬shaves barber barber\n  -- this line comes from suggest, but what is it doing ?\n  exact (not_congr hparadox).mp hn_self_shave hn_self_shave,\n  --absurd (hparadox.mpr hn_self_shave) hn_self_shave\nend\n\n-- another proof from zulip chat\nvariables (Man : Type) (tshaves : Man → Man → Prop)\ntheorem NoSuchBarber ( h : ∃ x : Man,  ∀ y : Man, tshaves x y ↔ ¬ tshaves y y )\n: false :=\n    exists.elim h\n  ( assume barber,\n    begin\n        intro h,\n        have hbarbermpr : ¬tshaves barber barber → tshaves barber barber,\n            from iff.mpr (h barber),\n        have hbarbermp  : tshaves barber barber → ¬tshaves barber barber,\n            from iff.mp (h barber),\n        have nsbb : ¬tshaves barber barber, from\n            assume sbb : tshaves barber barber,\n            show false, from hbarbermp sbb sbb,\n        show false, from nsbb (hbarbermpr nsbb)\n    end\n)\n#print NoSuchBarber\n\n\n-- from Kevin Buzzard\n--variables (Man : Type) (shaves : Man → Man → Prop)\ntheorem NoSuchBarber2 ( h : ∃ x : Man,  ∀ y : Man, tshaves x y ↔ ¬ tshaves y y )\n: false :=\n    exists.elim h\n  ( assume barber,\n    begin\n        intro h2, -- I don't want two hypotheses called h\n        have hbarber := h2 barber, -- human-generated good idea\n        tauto!, -- computer can finish it off\n    end\n)\n\n\n-- trying to rewrite this\n-- theorem NoSuchBarber ( h : ∃ x : Man,  ∀ y : Man, tshaves x y ↔ ¬ tshaves y y )\nexample : ¬ (∀ x : men, shaves barber x ↔ ¬ shaves x x) :=\nbegin\n  by_contradiction,\n  have x := barber,\n  specialize h barber,\n  cases h with p1 p2,\n  by_cases shaves barber barber,\n  {\n    show false, from p1 h h,\n  },\n  {\n    show false, from h (p2 h),\n  }\nend\n\n-- 2.3.2. Mathcampers singing paradox\n\n-- Assume that the main lounge is non-empty. At a fixed moment in time,\n-- there is someone in the lounge such that, if they are singing, then\n-- everyone in the lounge is singing.\n\n-- Note: This paradox is a rewording of the Drinker paradox.\n-- See https://en.wikipedia.org/wiki/Drinker_paradox\n-- \"There is someone in the pub such that, if he is drinking, then everyone in the pub is drinking.\"\n\n-- The outline of the proof from wikipedia.\n-- The proof begins by recognizing it is true that either:\n--  [1] everyone in the pub is drinking, or\n--  [2] at least one person in the pub is not drinking.\n-- Consequently, there are two cases to consider:\n-- [1] Suppose everyone is drinking.\n--     For any particular person, it cannot be wrong to say that if that particular person is drinking,\n--     then everyone in the pub is drinking—because everyone is drinking.\n--     Because everyone is drinking, then that one person must drink because when that person drinks everybody drinks\n--     everybody includes that person.\n-- [2] Otherwise at least one person is not drinking.\n--     For any nondrinking person, the statement if that particular person is drinking,\n--     then everyone in the pub is drinking is formally true:\n--     its antecedent (\"that particular person is drinking\") is false, therefore the statement is true due to the\n--     nature of material implication in formal logic, which states that\n--     \"If P, then Q\" is always true if P is false.\n\n/--------------------------------------------------------------------------\n\n``by_cases``\n\n  If ``P`` is a proposition, then ``by_cases P,`` creates two goals,\n    the first with a hypothesis ``hp: P`` and\n    second with a hypothesis ``hp: ¬ P``.\n\nDelete the ``sorry,`` below and replace them with a legitimate proof.\n\n--------------------------------------------------------------------------/\n\n-- camper is a type.\n-- If x : camper then x is a camper in the main lounge.\n-- singing(x) is inhabited if x is singing\n\ntheorem math_campers_singing_paradox\n  (camper : Type)\n  (singing : camper → Prop)\n  (alice : camper) -- making sure that there is at least one camper in the lounge\n  : ∃ x : camper, (singing x → (∀ y : camper, singing y)) :=\nbegin\n  -- Following the proof structure above we first create two goals,\n  -- in which either everyone sings, or someone is not singing\n  by_cases (∃ bob : camper, ¬ singing bob),\n  {\n    -- Here we have the case:\n    -- h: ∃ (bob : camper), ¬singing bob\n    -- So this is case [2] above, the one where not everyone is singing.\n    -- h says there exists a bob such that bob is not singing. The line\n    cases h with bob h_bob_not_singing,\n    -- gives us the hypotheiss that bob isn't singing\n    use bob, -- vacuously proving the goal.\n  },\n  {\n    -- Here we have the case where everyone sings, but it is written with a negative\n    -- h: ¬∃ (bob : camper), ¬singing bob\n    -- push_neg will sort this out\n    push_neg at h,\n    -- we now have\n    -- h: ∀ (bob : camper), singing bob\n    -- Our goal is a \"there exists\", we only know alice is in the lounge so lets use alice.\n    use alice,\n    -- goal is now singing alice → ∀ (y : camper), singing y\n    -- Which is an implication, so lets use intro.\n    intro h2, -- gives h2: singing alice\n    -- goal is now : camper), singing y\n    -- which is exactly h\n    exact h,\n  }\nend\n\n-- 2.3.3. Relationship conundrum\n\n/--------------------------------------------------------------------------\n  A relation r on a type X is a map r : X → X → Prop. We say that x is related to y if r x y is inhabited.\n\n  r is reflexive if ∀ x : X, x is related to itself.\n  r is symmetric if ∀ x y : X, x is related to y implies y is related to x.\n  r is transitive if ∀ x y z : X, x is related to y and y is related to x implies z is related to z.\n  r is connected if for all x : X there is a y : Y such that x is related to y.\n---------------------------------------------------------------------------/\n\n-- Show that if a relation is symmetric, transitive, and connected, then it is also reflexive.\n\nvariable X : Type\n\ntheorem reflexive_of_symmetric_transitive_and_connected\n  (r : X → X → Prop)\n  (h_symm : ∀ x y : X, r x y → r y x)\n  (h_trans : ∀ x y z : X, r x y → r y z → r x z)\n  (h_connected : ∀ x, ∃ y, r x y)\n: (∀ x : X, r x x) :=\nbegin\n  -- out goal is ∀ x : X, so lets introduce an arbitary x : X\n  intro x,\n  -- Either r x x is true, or it is false\n  by_cases (r x x), {\n    -- it's true, we are done as this is simpley h\n    exact h,\n  }, {\n    -- we now need to prove r x x when we know ¬ r x x, which we do by contradiction\n    by_contradiction,\n    -- from h_connected we know there exists a y such that r x y\n    -- by h_conneced is written as ∀ first, so we specialise on the x we have\n    specialize h_connected x,\n    -- we can now use cases on this to introduce the y : X such that we have h_rxy\n    cases h_connected with y h_rxy,\n    -- we now have h_rxy : r x y\n    -- we have also h_ryx y x := by applying h_symm,\n    have h_ryx : r y x := begin\n      apply h_symm,\n      assumption,\n    end,\n    -- and h_rxy and h_ryx and h_trans we have h_rxx\n    have h_rxx : r x x := begin\n      -- first specialize h_trans with the variables we want\n      specialize h_trans x y x,\n      -- our goal of r x x is now the result of applying this\n      exact h_trans h_rxy h_ryx,\n    end,\n    -- we now have h : ¬ r x x and h_rxx : r x x which is the contradtion we need to prove the goal of false.\n    show false, from h h_rxx,\n  }\nend\n\n-- note: a similar proof from the course notes solutions\ntheorem reflexive_of_symmetric_and_transitive' (r : ℕ → ℕ → Prop)\n  (h_symm : symmetric r)\n  (h_trans : transitive r)\n  (h_connected : ∀ x, ∃ y, r x y) :\n  reflexive r :=\nbegin\n  intro x,\n  have hxy := h_connected x,\n  cases hxy with y hy,\n  apply h_trans hy,\n  apply h_symm hy,\nend\n\n-- 2.4. Proving “trivial” statements\n\n/--\n   In mathlib, divisibility for natural numbers is defined as the following proposition.\n\n   a ∣ b := (∃ k : ℕ, a = b * k)\n\n  For example, 2 | 4 will be a proposition ∃ k : ℕ, 4 = 2 * k.\n  Very important. The statement 2 | 4 is not saying that “2 divides 4 is true”.\n  It is simply a proposition that requires a proof.\n\n  Similarly, the mathlib library also contains the following definition of prime.\n\ndef nat.prime (p : ℕ) : Prop :=\n  2 ≤ p                                       -- p is at least 2\n  ∧                                           -- and\n  ∀ (m : ℕ), m ∣ p → m = 1 ∨ m = p            -- if m divides p, then m = 1 or m = p.\n\n--/\n\n/--------------------------------------------------------------------------\n\n  These tactics in Lean are useful for proving trivial proofs such as these.\n\n``norm_num``\n\n  Useful for arithmetic.\n\n``ring``\n\n  Useful for basic algebra.\n\n``linarith``\n\n  Useful for inequalities.\n\n``simp``\n\n  Complex simplifier. Use only to close goals.\n\nDelete the ``sorry,`` below and replace them with a legitimate proof.\n\n--------------------------------------------------------------------------/\n\nexample : 1 > 0 :=\nbegin\n  norm_num,\nend\n\nexample (m a b : ℕ) :  m^2 + (a + b) * m + a * b = (m + a) * (m + b) :=\nbegin\n  ring,\nend\n\nexample : 101 ∣ 2020 :=\nbegin\n  norm_num,\nend\n\nexample : nat.prime 3 :=\nbegin\n  norm_num,\nend\n\nexample : nat.prime 101 :=\nbegin\n  -- note you need to have\n  --    import data.nat.prime\n  -- for this one line proof to work.\n  -- I spent quite a bit of time trying to prove it without this line.\n  norm_num,\n end\n\n-- you will need the definition\n-- a ∣ b := (∃ k : ℕ, a = b * k)\nexample (m a b : ℕ) :  m + a ∣ m^2 + (a + b) * m + a * b :=\nbegin\n  -- Our proof of this is to first observe that the rhs factorises\n  -- m^2 (a + b)m + ab = (m + a)(m + b)\n  -- from the definition of a | b we have a ∃ k, so in this case\n  -- our k is m + b\n  use m + b,\n  -- we are just left to prove that\n  -- m ^ 2 + (a + b) * m + a * b = (m + a) * (m + b)\n  ring, -- and now this is easily solved with ring!\nend\n\n-- try ``unfold nat.prime at hp,`` to get started\nexample (p : ℕ) (hp : nat.prime p) : ¬ (p = 1) :=\nbegin\n  unfold nat.prime at hp,\n  -- after unfolding hp is\n  -- hp: 2 ≤ p ∧ ∀ (m : ℕ), m ∣ p → m = 1 ∨ m = p\n  -- this is two hypotheses via an and which we can split with\n  -- cases hp,\n  -- but in fact this isn't necessary as the linarith tatic clears the goal\n  linarith,\nend\n\n-- if none of the simplifiers work, try doing ``contrapose!``\n-- sometimes the simplifiers need a little help\nexample (n : ℕ) : 0 < n ↔ n ≠ 0 :=\nbegin\n  -- Since we have ↔, split to → and ← .\n  split,\n  {\n    -- this is where the hint is needed, contrapose before simp\n    contrapose,\n    simp,\n  },\n  {\n    contrapose,\n    simp,\n  }\nend\n\n-- extra note, since the two split proofs above are the same, this above\n-- proof can be reduced to\n\nexample (n : ℕ) : 0 < n ↔ n ≠ 0 :=\nbegin\n  split;  -- here the ; means apply the following to both goals.\n  {\n    contrapose,\n    simp,\n  }\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/exercises/lean_at_mc2020/chapter_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137296, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7553471539707121}}
{"text": "import Math.Algebra.Basic\n\nnamespace Algebra\n\nclass Monoid (α : Type u) extends Mul α, One α, MulOne α where\n  mul_assoc : ∀ (x y z : α), x * (y * z) = (x * y) * z\n\nattribute [simp] Monoid.mul_assoc Monoid.mul_one Monoid.one_mul\n\nnamespace Monoid\n\nvariable [Monoid α]\n\ndef npow (x : α) (n : Nat) : α := match n with\n| Nat.zero => 1\n| Nat.succ n => x * (npow x n)\n\ninstance : Pow α Nat where pow := npow\n\n@[simp] theorem npow_zero (x : α) : x ^ (0 : Nat) = 1 := by rfl;\n@[simp] theorem npow_succ (x : α) (n : Nat) : x ^ n.succ = x * x ^ n := by rfl;\n@[simp] theorem npow_one (x : α) : x ^ (1 : Nat) = x := by have q := npow_succ x 0; rw [npow_zero, mul_one] at q; exact q;\n@[simp] theorem npow_mul (x : α) (m n : Nat) : x ^ (n + m) = x ^ n * x ^ m := by {\n  induction n with\n  | zero => simp\n  | succ n hn => simp [Nat.succ_add, hn];\n}\n\ntheorem left_inv_eq_right_inv {x y z : α} (h₁ : x * y = 1) (h₂ : y * z = 1) : x = z :=\n  by rw [← mul_one x, ← h₂, mul_assoc, h₁, one_mul]\n\nend Monoid\n\nclass abbrev MonoidHom (f : α → β) [Monoid α] [Monoid β] : Prop := MulHom f, OneHom f\n\n-- Very good!\n-- variable (g : β → γ) (f : α → β) [Monoid α] [Monoid β] [Monoid γ] [MonoidHom f] [MonoidHom g]\n-- #check (inferInstance : MonoidHom (id : α → α))\n-- #check (inferInstance :  MonoidHom (g ∘ f))\n\nend Algebra\n", "meta": {"author": "jessetvogel", "repo": "Math4", "sha": "1d6a30589c7b3b3c70e968985d0c1f6f9f242938", "save_path": "github-repos/lean/jessetvogel-Math4", "path": "github-repos/lean/jessetvogel-Math4/Math4-1d6a30589c7b3b3c70e968985d0c1f6f9f242938/Math/Algebra/Monoid/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.913676518712608, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7553471520346934}}
{"text": "import data.real.basic\n\nvariables {x y : ℝ}\n\nexample (h : y > x^2) : y > 0 ∨ y < -1 :=\nby { left, linarith [pow_two_nonneg x] }\n\nexample (h : -y > x^2 + 1) : y > 0 ∨ y < -1 :=\nby { right, linarith [pow_two_nonneg x] }\n\n\nexample : x < abs y → x < y ∨ x < -y :=\nbegin\n  cases le_or_gt 0 y with h h,\n  { rw abs_of_nonneg h,\n    intro h,\n    from or.inl h,\n  },\n  { rw abs_of_neg h,\n    intro h,\n    from or.inr h,\n  },\nend\n\nnamespace my_abs\n\ntheorem le_abs_self (x : ℝ) : x ≤ |x| :=\nbegin \n  cases le_or_gt 0 x with h h,\n  { rw abs_of_nonneg h,\n  },\n  { rw abs_of_neg h,\n    apply le_of_lt,\n    apply lt_trans h,\n    rw neg_pos,\n    from h,\n  }\nend\n\ntheorem neg_le_abs_self (x : ℝ) : -x ≤ |x| :=\nbegin \n  cases le_or_gt 0 x with h h,\n  { rw abs_of_nonneg h,\n    apply le_trans,\n    rw neg_nonpos,\n    repeat {from h},\n  },\n  { rw abs_of_neg h,\n  },\nend\n\ntheorem abs_add (x y : ℝ) : |x + y| ≤ |x| + |y| :=\nbegin \n  cases le_or_gt 0 (x + y) with h h,\n  { rw abs_of_nonneg h,\n    apply add_le_add; apply le_abs_self,\n  },\n  {\n    rw abs_of_neg h,\n    rw neg_add,\n    apply add_le_add; apply neg_le_abs_self,\n  },\nend\n\ntheorem lt_abs : x < |y| ↔ x < y ∨ x < -y :=\nbegin \n  split,\n  { intro h,\n    cases le_or_gt 0 y with h' h',\n    { rw abs_of_nonneg h' at h,\n      left, from h,\n    },\n    { rw abs_of_neg h' at h,\n      right, from h,\n    },\n  },\n  { intro h,\n    cases h with hy hny,\n    { apply lt_of_lt_of_le,\n      from hy,\n      apply le_abs_self,\n    },\n    { apply lt_of_lt_of_le,\n      from hny,\n      apply neg_le_abs_self,\n    },\n  },\nend\n\ntheorem abs_lt : |x| < y ↔ - y < x ∧ x < y :=\nbegin \n  split,\n  { intro h,\n    cases le_or_gt 0 x with h' h',\n    { rw abs_of_nonneg h' at h,\n      split; linarith,\n    },\n    { rw abs_of_neg h' at h,\n      split; linarith,\n    }\n  },\n  { intro h,\n    cases le_or_gt 0 x with h' h',\n    { rw abs_of_nonneg h',\n      from h.right,\n    },\n    { rw abs_of_neg h',\n      linarith,\n    }\n  }\n\nend\n\nend my_abs\n\n\n\nexample {x : ℝ} (h : x ≠ 0) : x < 0 ∨ x > 0 :=\nbegin\n  rcases lt_trichotomy x 0 with xlt | xeq | xgt,\n  { left, exact xlt },\n  { contradiction },\n  right, exact xgt\nend\n\n\nexample {m n k : ℕ} (h : m ∣ n ∨ m ∣ k) : m ∣ n * k :=\nbegin\n  rcases h with ⟨a, rfl⟩ | ⟨b, rfl⟩,\n  { rw [mul_assoc],\n    apply dvd_mul_right,\n  },\n  { rw [mul_comm, mul_assoc],\n    apply dvd_mul_right,\n  }\nend\n\n\nexample {z : ℝ} (h : ∃ x y, z = x^2 + y^2 ∨ z = x^2 + y^2 + 1) :\n  z ≥ 0 :=\nby {rcases h with ⟨x, y, rfl | rfl⟩; linarith [sq_nonneg x, sq_nonneg y],}\n\n\nexample {x : ℝ} (h : x^2 = 1) : x = 1 ∨ x = -1 :=\nbegin \n  have : (x - 1) * (x + 1) = 0 := by linarith,\n  have : x - 1 = 0 ∨ x + 1 = 0 := eq_zero_or_eq_zero_of_mul_eq_zero this,\n  cases this,\n    left, linarith,\n    right, linarith,\nend\n\nexample {x y : ℝ} (h : x^2 = y^2) : x = y ∨ x = -y :=\nbegin \n  have : (x - y) * (x + y) = 0 := by linarith,\n  have : x - y = 0 ∨ x + y = 0 := eq_zero_or_eq_zero_of_mul_eq_zero this,\n  cases this,\n    left, linarith,\n    right, linarith,\nend\n\n\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro h,\n  cases classical.em P,\n  { assumption },\n  contradiction\nend\n\n\nexample (P Q : Prop) : (P → Q) ↔ ¬ P ∨ Q :=\nbegin \n  split,\n  { intro hp,\n    by_cases P,\n    { right,\n      from hp h,\n    },\n    { left,\n      assumption,\n    },\n  },\n  { rintros (hnp | hq) hp,\n    { contradiction,\n    },\n    { from hq\n    }\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/05_Disjunction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7553122268344497}}
{"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) : (∀ x₁, x₁ < x → Nat → Nat) → Nat → 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 lt_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 <;> simp [gcd_succ]\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": "subfish-zhou", "repo": "leanprover-zh_CN.github.io", "sha": "8b2985d4a3d458ceda9361ac454c28168d920d3f", "save_path": "github-repos/lean/subfish-zhou-leanprover-zh_CN.github.io", "path": "github-repos/lean/subfish-zhou-leanprover-zh_CN.github.io/leanprover-zh_CN.github.io-8b2985d4a3d458ceda9361ac454c28168d920d3f/stage0/src/Init/Data/Nat/Gcd.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.755312215208606}}
{"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 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.GroupPower.Basic\nimport Mathlib.Algebra.Order.Group.Abs\nimport Mathlib.Tactic.NthRewrite\n/-!\n# Lattice ordered groups\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⁺-a⁻` 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⁺ = a ⊔ 0`: The *positive component* of an element `a` of a lattice ordered commutative group\n- `a⁻ = (-a) ⊔ 0`: The *negative component* of an element `a` of a lattice ordered commutative group\n- `|a| = a⊔(-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 `α` satisfying:\n\n* `[Lattice α]`\n* `[CommGroup α]`\n* `[CovariantClass α α (*) (≤)]`\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-- 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 (α : Type u)\n    [LinearOrderedCommGroup α] :\n    CovariantClass α α (· * ·)\n      (· ≤ ·) where elim a _ _ bc := OrderedCommGroup.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 {α : Type u} [Lattice α] [CommGroup α]\n\n-- Special case of Bourbaki A.VI.9 (1)\n-- c + (a ⊔ b) = (c + a) ⊔ (c + b)\n@[to_additive]\ntheorem mul_sup [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : c * (a ⊔ b) = c * a ⊔ c * b := by\n  refine' le_antisymm _ _\n  rw [← mul_le_mul_iff_left (c⁻¹), ← mul_assoc, inv_mul_self, one_mul]\n  apply sup_le\n  rw [le_inv_mul_iff_mul_le]\n  exact le_sup_left'\n  rw [le_inv_mul_iff_mul_le]\n  exact le_sup_right\n  rw [sup_le_iff, mul_le_mul_iff_left, mul_le_mul_iff_left, and_iff_left le_sup_right]\n  exact le_sup_left\n#align mul_sup mul_sup\n#align add_sup add_sup\n\n@[to_additive]\ntheorem mul_inf [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : c * (a ⊓ b) = c * a ⊓ c * b := by\n  refine' le_antisymm _ _\n  rw [le_inf_iff, mul_le_mul_iff_left, mul_le_mul_iff_left, and_iff_left inf_le_right]\n  exact inf_le_left\n  rw [← mul_le_mul_iff_left (c⁻¹), ← mul_assoc, inv_mul_self, one_mul]\n  apply le_inf\n  rw [inv_mul_le_iff_le_mul]\n  exact inf_le_left\n  rw [inv_mul_le_iff_le_mul]\n  exact inf_le_right\n#align mul_inf mul_inf\n#align add_inf add_inf\n\n-- Special case of Bourbaki A.VI.9 (2)\n-- -(a ⊔ b)=(-a) ⊓ (-b)\n@[to_additive]\ntheorem inv_sup_eq_inv_inf_inv [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) :\n    (a ⊔ b)⁻¹ = a⁻¹ ⊓ b⁻¹ := by\n  apply le_antisymm\n  · refine' le_inf _ _\n    · rw [inv_le_inv_iff]\n      exact le_sup_left\n    · rw [inv_le_inv_iff]\n      exact le_sup_right\n  · rw [← inv_le_inv_iff, inv_inv]\n    refine' sup_le _ _\n    · rw [← inv_le_inv_iff]\n      simp\n    · rw [← 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-- -(a ⊓ b) = -a ⊔ -b\n@[to_additive]\ntheorem inv_inf_eq_sup_inv [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) : (a ⊓ b)⁻¹ = a⁻¹ ⊔ b⁻¹ :=\n  by rw [← inv_inv (a⁻¹ ⊔ b⁻¹), inv_sup_eq_inv_inf_inv a⁻¹ b⁻¹, 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-- Bourbaki A.VI.10 Prop 7\n-- a ⊓ b + (a ⊔ b) = a + b\n@[to_additive]\ntheorem inf_mul_sup [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) : (a ⊓ b) * (a ⊔ b) = a * b :=\n  calc\n    (a ⊓ b) * (a ⊔ b) = (a ⊓ b) * (a * b * (b⁻¹ ⊔ a⁻¹)) :=\n    by\n      rw [mul_sup b⁻¹ a⁻¹ (a * b)]\n      simp\n    _ = (a ⊓ b) * (a * b * (a ⊓ b)⁻¹) := 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-- see Note [lower instance priority]\n/--\nLet `α` be a lattice ordered commutative group with identity `1`. For an element `a` of type `α`,\nthe element `a ⊔ 1` is said to be the *positive component* of `a`, denoted `a⁺`.\n-/\n@[to_additive\n      \"Let `α` be a lattice ordered commutative group with identity `0`. For an element `a` of type\n      `α`,the element `a ⊔ 0` is said to be the *positive component* of `a`, denoted `a⁺`.\"]\ninstance (priority := 100) hasOneLatticeHasPosPart : PosPart α :=\n  ⟨fun a => a ⊔ 1⟩\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@[to_additive pos_part_def]\ntheorem m_pos_part_def (a : α) : a⁺ = a ⊔ 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-- see Note [lower instance priority]\n/--\nLet `α` be a lattice ordered commutative group with identity `1`. For an element `a` of type `α`,\nthe element `(-a) ⊔ 1` is said to be the *negative component* of `a`, denoted `a⁻`.\n-/\n@[to_additive\n      \"Let `α` be a lattice ordered commutative group with identity `0`. For an element `a` of type\n      `α`, the element `(-a) ⊔ 0` is said to be the *negative component* of `a`, denoted `a⁻`.\"]\ninstance (priority := 100) hasOneLatticeHasNegPart : NegPart α :=\n  ⟨fun a => a⁻¹ ⊔ 1⟩\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@[to_additive neg_part_def]\ntheorem m_neg_part_def (a : α) : a⁻ = a⁻¹ ⊔ 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@[to_additive (attr := simp)]\ntheorem pos_one : (1 : α)⁺ = 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@[to_additive (attr := simp)]\ntheorem neg_one : (1 : α)⁻ = 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-- a⁻ = -(a ⊓ 0)\n@[to_additive]\ntheorem neg_eq_inv_inf_one [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : a⁻ = (a ⊓ 1)⁻¹ := by\n  rw [m_neg_part_def, ← 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@[to_additive le_abs]\ntheorem le_mabs (a : α) : a ≤ |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-- -a ≤ |a|\n@[to_additive]\ntheorem inv_le_abs (a : α) : a⁻¹ ≤ |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-- 0 ≤ a⁺\n@[to_additive pos_nonneg]\ntheorem one_le_pos (a : α) : 1 ≤ a⁺ :=\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-- 0 ≤ a⁻\n@[to_additive neg_nonneg]\ntheorem one_le_neg (a : α) : 1 ≤ a⁻ :=\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-- pos_nonpos_iff\n@[to_additive]\ntheorem pos_le_one_iff {a : α} : a⁺ ≤ 1 ↔ a ≤ 1 := 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-- neg_nonpos_iff\n@[to_additive]\ntheorem neg_le_one_iff {a : α} : a⁻ ≤ 1 ↔ a⁻¹ ≤ 1 := 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@[to_additive]\ntheorem pos_eq_one_iff {a : α} : a⁺ = 1 ↔ a ≤ 1 := 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@[to_additive]\ntheorem neg_eq_one_iff' {a : α} : a⁻ = 1 ↔ a⁻¹ ≤ 1 := 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@[to_additive]\ntheorem neg_eq_one_iff [CovariantClass α α Mul.mul LE.le] {a : α} : a⁻ = 1 ↔ 1 ≤ a := 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@[to_additive le_pos]\ntheorem m_le_pos (a : α) : a ≤ a⁺ :=\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-- -a ≤ a⁻\n@[to_additive]\ntheorem inv_le_neg (a : α) : a⁻¹ ≤ a⁻ :=\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-- Bourbaki A.VI.12\n--  a⁻ = (-a)⁺\n@[to_additive]\ntheorem neg_eq_pos_inv (a : α) : a⁻ = a⁻¹⁺ :=\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-- a⁺ = (-a)⁻\n@[to_additive]\ntheorem pos_eq_neg_inv (a : α) : a⁺ = a⁻¹⁻ := 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-- We use this in Bourbaki A.VI.12  Prop 9 a)\n-- c + (a ⊓ b) = (c + a) ⊓ (c + b)\n@[to_additive]\ntheorem mul_inf_eq_mul_inf_mul [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :\n    c * (a ⊓ b) = c * a ⊓ c * b := by\n  refine' le_antisymm _ _\n  rw [le_inf_iff, mul_le_mul_iff_left, mul_le_mul_iff_left]\n  simp\n  rw [← mul_le_mul_iff_left c⁻¹, ← mul_assoc, inv_mul_self, one_mul, le_inf_iff,\n    inv_mul_le_iff_le_mul, inv_mul_le_iff_le_mul]\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-- Bourbaki A.VI.12  Prop 9 a)\n-- a = a⁺ - a⁻\n@[to_additive (attr := simp)]\ntheorem pos_div_neg [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : a⁺ / a⁻ = a := 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-- Bourbaki A.VI.12  Prop 9 a)\n-- a⁺ ⊓ a⁻ = 0 (`a⁺` and `a⁻` are co-prime, and, since they are positive, disjoint)\n@[to_additive]\ntheorem pos_inf_neg_eq_one [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : a⁺ ⊓ a⁻ = 1 := by\n  rw [← mul_right_inj (a⁻)⁻¹, mul_inf_eq_mul_inf_mul, mul_one, mul_left_inv, mul_comm, ←\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-- Bourbaki A.VI.12 (with a and b swapped)\n-- a⊔b = b + (a - b)⁺\n@[to_additive]\ntheorem sup_eq_mul_pos_div [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) : a ⊔ b = b * (a / b)⁺ :=\n  calc\n    a ⊔ b = b * (a / b) ⊔ b * 1 :=\n      by rw [mul_one b, div_eq_mul_inv, mul_comm a, mul_inv_cancel_left]\n    _ = b * (a / b ⊔ 1) := by rw [← 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-- Bourbaki A.VI.12 (with a and b swapped)\n-- a⊓b = a - (a - b)⁺\n@[to_additive]\ntheorem inf_eq_div_pos_div [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) : a ⊓ b = a / (a / b)⁺ :=\n  calc\n    a ⊓ b = a * 1 ⊓ a * (b / a) :=\n      by rw [mul_one a, div_eq_mul_inv, mul_comm b, mul_inv_cancel_left]\n    _ = a * (1 ⊓ b / a) := by rw [← mul_inf_eq_mul_inf_mul 1 (b / a) a]\n    _ = a * (b / a ⊓ 1) := by rw [inf_comm]\n    _ = a * ((a / b)⁻¹ ⊓ 1) :=\n      by\n        rw [div_eq_mul_inv]\n        nth_rw 1 [← inv_inv b]\n        rw [← mul_inv, mul_comm b⁻¹, ← div_eq_mul_inv]\n    _ = a * ((a / b)⁻¹ ⊓ 1⁻¹) := by rw [inv_one]\n    _ = a / (a / b ⊔ 1) := by rw [← inv_sup_eq_inv_inf_inv, ← 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-- 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 α α (· * ·) (· ≤ ·)] (a b : α) :\n    a ≤ b ↔ a⁺ ≤ b⁺ ∧ b⁻ ≤ a⁻ := by\n  constructor <;> intro h\n  · constructor\n    · exact sup_le (h.trans (m_le_pos b)) (one_le_pos b)\n    · rw [← inv_le_inv_iff] at h\n      exact sup_le (h.trans (inv_le_neg a)) (one_le_neg a)\n  · rw [← pos_div_neg a, ← 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@[to_additive neg_abs]\ntheorem m_neg_abs [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : |a|⁻ = 1 := by\n  refine' le_antisymm _ _\n  · rw [← pos_inf_neg_eq_one a]\n    apply le_inf\n    · rw [pos_eq_neg_inv]\n      exact ((m_le_iff_pos_le_neg_ge _ _).mp (inv_le_abs a)).right\n    · exact And.right (Iff.mp (m_le_iff_pos_le_neg_ge _ _) (le_mabs a))\n  · 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@[to_additive pos_abs]\ntheorem m_pos_abs [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : |a|⁺ = |a| := by\n  nth_rw 2 [← 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@[to_additive abs_nonneg]\ntheorem one_le_abs [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : 1 ≤ |a| := by\n  rw [← 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-- The proof from Bourbaki A.VI.12 Prop 9 d)\n-- |a| = a⁺ - a⁻\n@[to_additive]\ntheorem pos_mul_neg [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : |a| = a⁺ * a⁻ := by\n  refine' le_antisymm _ _\n  · refine' sup_le _ _\n    · nth_rw 1 [← mul_one a]\n      exact mul_le_mul' (m_le_pos a) (one_le_neg a)\n    · nth_rw 1 [← one_mul a⁻¹]\n      exact mul_le_mul' (one_le_pos a) (inv_le_neg a)\n  · rw [← inf_mul_sup, pos_inf_neg_eq_one, one_mul, ← m_pos_abs a]\n    apply sup_le\n    · exact ((m_le_iff_pos_le_neg_ge _ _).mp (le_mabs a)).left\n    · 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-- a ⊔ b - (a ⊓ b) = |b - a|\n@[to_additive]\ntheorem sup_div_inf_eq_abs_div [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) :\n    (a ⊔ b) / (a ⊓ b) = |b / a| := by\n  rw [sup_eq_mul_pos_div, inf_comm, inf_eq_div_pos_div, div_eq_mul_inv, div_eq_mul_inv b ((b / a)⁺),\n    mul_inv_rev, inv_inv, mul_comm, ← mul_assoc, inv_mul_cancel_right, pos_eq_neg_inv (a / b),\n    div_eq_mul_inv a b, mul_inv_rev, ← div_eq_mul_inv, inv_inv, ← 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-- 2•(a ⊔ b) = a + b + |b - a|\n@[to_additive two_sup_eq_add_add_abs_sub]\ntheorem sup_sq_eq_mul_mul_abs_div [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) :\n    (a ⊔ b) ^ 2 = a * b * |b / a| := by\n  rw [← inf_mul_sup a b, ← sup_div_inf_eq_abs_div, div_eq_mul_inv, ← mul_assoc, mul_comm, mul_assoc,\n    ← 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-- 2•(a ⊓ b) = a + b - |b - a|\n@[to_additive two_inf_eq_add_sub_abs_sub]\ntheorem inf_sq_eq_mul_div_abs_div [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) :\n    (a ⊓ b) ^ 2 = a * b / |b / a| := by\n  rw [← inf_mul_sup a b, ← 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, ← 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/-- 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 (α : Type u) [s : Lattice α] [CommGroup α]\n    [CovariantClass α α (· * ·) (· ≤ ·)] : DistribLattice α :=\n  { s with\n    le_sup_inf := by\n      intros x y z\n      rw [← mul_le_mul_iff_left (x ⊓ (y ⊓ z)), inf_mul_sup x (y ⊓ z), ← inv_mul_le_iff_le_mul,\n        le_inf_iff]\n      constructor\n      · rw [inv_mul_le_iff_le_mul, ← inf_mul_sup x y]\n        apply mul_le_mul'\n        · apply inf_le_inf_left\n          apply inf_le_left\n        · apply inf_le_left\n      · rw [inv_mul_le_iff_le_mul, ← inf_mul_sup x z]\n        apply mul_le_mul'\n        · apply inf_le_inf_left\n          apply inf_le_right\n        · 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-- See, e.g. Zaanen, Lectures on Riesz Spaces\n-- 3rd lecture\n-- |a ⊔ c - (b ⊔ c)| + |a ⊓ c-b ⊓ c| = |a - b|\n@[to_additive]\ntheorem abs_div_sup_mul_abs_div_inf [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :\n    |(a ⊔ c) / (b ⊔ c)| * |(a ⊓ c) / (b ⊓ c)| = |a / b| := by\n  letI : DistribLattice α := LatticeOrderedCommGroup.latticeOrderedCommGroupToDistribLattice α\n  calc\n    |(a ⊔ c) / (b ⊔ c)| * |(a ⊓ c) / (b ⊓ c)| =\n        (b ⊔ c ⊔ (a ⊔ c)) / ((b ⊔ c) ⊓ (a ⊔ c)) * |(a ⊓ c) / (b ⊓ c)| :=\n      by rw [sup_div_inf_eq_abs_div]\n    _ = (b ⊔ c ⊔ (a ⊔ c)) / ((b ⊔ c) ⊓ (a ⊔ c)) * ((b ⊓ c ⊔ a ⊓ c) / (b ⊓ c ⊓ (a ⊓ c))) :=\n      by rw [sup_div_inf_eq_abs_div (b ⊓ c) (a ⊓ c)]\n    _ = (b ⊔ a ⊔ c) / (b ⊓ a ⊔ c) * (((b ⊔ a) ⊓ c) / (b ⊓ a ⊓ c)) :=\n      by\n        rw [← sup_inf_right, ← inf_sup_right, sup_assoc, @sup_comm _ _ c (a⊔c), sup_right_idem,\n          sup_assoc, inf_assoc, @inf_comm _ _ c (a⊓c), inf_right_idem, inf_assoc]\n    _ = (b ⊔ a ⊔ c) * ((b ⊔ a) ⊓ c) / ((b ⊓ a ⊔ c) * (b ⊓ a ⊓ c)) := by rw [div_mul_div_comm]\n    _ = (b ⊔ a) * c / ((b ⊓ a) * c) :=\n      by rw [mul_comm, inf_mul_sup, mul_comm (b ⊓ a ⊔ c), inf_mul_sup]\n    _ = (b ⊔ a) / (b ⊓ a) :=\n      by rw [div_eq_mul_inv, mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← 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-- pos_of_nonneg\n/-- If `a` is positive, then it is equal to its positive component `a⁺`. -/\n@[to_additive \"If `a` is positive, then it is equal to its positive component `a⁺`.\"]\ntheorem pos_of_one_le (a : α) (h : 1 ≤ a) : a⁺ = a := 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-- pos_eq_self_of_pos_pos\n@[to_additive]\ntheorem pos_eq_self_of_one_lt_pos {α} [LinearOrder α] [CommGroup α] {x : α} (hx : 1 < x⁺) :\n    x⁺ = 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-- 0 ≤ a implies a⁺ = a\n-- pos_of_nonpos\n@[to_additive]\ntheorem pos_of_le_one (a : α) (h : a ≤ 1) : a⁺ = 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@[to_additive neg_of_inv_nonneg]\ntheorem neg_of_one_le_inv (a : α) (h : 1 ≤ a⁻¹) : a⁻ = a⁻¹ := 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-- neg_of_neg_nonpos\n@[to_additive]\ntheorem neg_of_inv_le_one (a : α) (h : a⁻¹ ≤ 1) : a⁻ = 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-- neg_of_nonpos\n@[to_additive]\ntheorem neg_of_le_one [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) (h : a ≤ 1) : a⁻ = a⁻¹ := 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-- neg_of_nonneg'\n@[to_additive]\ntheorem neg_of_one_le [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) (h : 1 ≤ a) : a⁻ = 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-- 0 ≤ a implies |a| = a\n@[to_additive abs_of_nonneg]\ntheorem mabs_of_one_le [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) (h : 1 ≤ a) : |a| = a := by\n  rw [abs_eq_sup_inv, sup_eq_mul_pos_div, div_eq_mul_inv, inv_inv, ← pow_two, inv_mul_eq_iff_eq_mul,\n    ← pow_two, 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/-- The unary operation of taking the absolute value is idempotent. -/\n@[to_additive (attr := simp) abs_abs\n  \"The unary operation of taking the absolute value is idempotent.\"]\ntheorem mabs_mabs [CovariantClass α α (· * ·) (· ≤ ·)] (a : α) : |(|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@[to_additive abs_sup_sub_sup_le_abs]\ntheorem mabs_sup_div_sup_le_mabs [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :\n    |(a ⊔ c) / (b ⊔ c)| ≤ |a / b| := by\n  apply le_of_mul_le_of_one_le_left\n  · rw [abs_div_sup_mul_abs_div_inf]\n  · 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@[to_additive abs_inf_sub_inf_le_abs]\ntheorem mabs_inf_div_inf_le_mabs [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :\n    |(a ⊓ c) / (b ⊓ c)| ≤ |a / b| := by\n  apply le_of_mul_le_of_one_le_right\n  · rw [abs_div_sup_mul_abs_div_inf]\n  · 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-- Commutative case, Zaanen, 3rd lecture\n-- For the non-commutative case, see Birkhoff Theorem 19 (27)\n-- |(a ⊔ c) - (b ⊔ c)| ⊔ |(a ⊓ c) - (b ⊓ c)| ≤ |a - b|\n@[to_additive Birkhoff_inequalities]\ntheorem m_Birkhoff_inequalities [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :\n    |(a ⊔ c) / (b ⊔ c)| ⊔ |(a ⊓ c) / (b ⊓ c)| ≤ |a / b| :=\n  sup_le (mabs_sup_div_sup_le_mabs a b c) (mabs_inf_div_inf_le_mabs a b c)\nset_option linter.uppercaseLean3 false in\n#align lattice_ordered_comm_group.m_Birkhoff_inequalities LatticeOrderedCommGroup.m_Birkhoff_inequalities\nset_option linter.uppercaseLean3 false in\n#align lattice_ordered_comm_group.Birkhoff_inequalities LatticeOrderedCommGroup.Birkhoff_inequalities\n\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 α α (· * ·) (· ≤ ·)] (a b : α) : |a * b| ≤ |a| * |b| := by\n  apply sup_le\n  · exact mul_le_mul' (le_mabs a) (le_mabs b)\n  · 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-- |a - b| = |b - a|\n@[to_additive]\ntheorem abs_inv_comm (a b : α) : |a / b| = |b / a| := by\n  dsimp only [Abs.abs]\n  rw [inv_div a b, ← 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-- | |a| - |b| | ≤ |a - b|\n@[to_additive]\ntheorem abs_abs_div_abs_le [CovariantClass α α (· * ·) (· ≤ ·)] (a b : α) :\n|(|a| / |b|)| ≤ |a / b| := by\n  rw [abs_eq_sup_inv, sup_le_iff]\n  constructor\n  · apply div_le_iff_le_mul.2\n    convert mabs_mul_le (a / b) b\n    · rw [div_mul_cancel']\n  · rw [div_eq_mul_inv, mul_inv_rev, inv_inv, mul_inv_le_iff_le_mul,\n      abs_inv_comm]\n    convert mabs_mul_le (b / a) a\n    · 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", "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/LatticeGroup.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7552974970539496}}
{"text": "import data.nat.basic\n\n-- First definition of prime (quite \"prim(e)itive\")\ndef prime (p : ℕ) := p ≥ 2 ∧ ∀ (m < p), m ∣ p → m = 1\n\nopen nat\n\n-- A lemma to prove that 4 is not prime\nlemma two_divides_four : 2 ∣ 4 :=\nbegin\n    dsimp [(∣)],\n    use 2,\n    refl,\nend\n\n-- Question 1a\ntheorem four_is_not_prime : ¬ (prime 4) :=\nbegin\n    unfold prime,\n    simp [not_and_distrib],\n    right,\n    intros h,\n    have h₁ : 2 ∣ 4, by exact two_divides_four,\n    have h₂ : 2 < 4, by exact dec_trivial,\n    have w := h 2 h₂ h₁,\n    have w' : 2 ≠ 1, by exact dec_trivial,\n    contradiction,\nend\n\n-- A lemma to prove that 5 is prime; dec_trivial was not used because we can't use tactics in MathLib\nlemma five_ge_two : 5 ≥ 2 :=\nbegin\n    dsimp [(≥)],\n    rw [le_iff_lt_or_eq],\n    left,\n    have h₁ : 3 ≠ 0, begin\n        intros h,\n        contradiction,\n    end,\n    have h₂ : 3 > 0, by exact nat.pos_of_ne_zero h₁,\n    dsimp [(>)] at h₂,\n    have h₃ : 1 < 4, by exact succ_lt_succ h₂,\n    have h₄ : 2 < 5, by exact succ_lt_succ h₃,\n    exact h₄,\nend\n\n-- This tactic gives a contradiction proof that a non-factor does not divide a number\n-- I couldn't work out how to make the name n be given as an input\nmeta def case_bash : tactic unit :=\n`[intros h, repeat {cases n, cases h, try {cases h}}]\n\nlemma two_not_div_five (n : ℕ) : 5 ≠ 2 * n := by case_bash\n\nlemma three_not_div_five (n : ℕ) : 5 ≠ 3 * n := by case_bash\n\nlemma four_not_div_five (n : ℕ) : 5 ≠ 4 * n := by case_bash\n\n-- Question 1a\ntheorem five_is_prime : prime 5 :=\nbegin\n    unfold prime,\n    split,\n    exact five_ge_two,\n    intros m h w,\n    cases m,\n    dsimp [(∣)] at w,\n    cases w with c w,\n    simp only [zero_mul] at w,\n    contradiction,\n    cases m,\n    trivial,\n    cases m,\n    cases w with c w,\n    have w' : 5 ≠ 2 * c, by apply two_not_div_five,\n    contradiction,\n    cases m,\n    cases w with c w,\n    have w' : 5 ≠ 3 * c, by apply three_not_div_five,\n    contradiction,\n    cases m,\n    cases w with c w,\n    have w' : 5 ≠ 4 * c, by apply four_not_div_five,\n    contradiction,\n    cases m,\n    repeat {cases h with h h},\nend\n\n-- It is decidable that one natural number is greater than or equal to another\ninstance decidable_ge {a b : ℕ} : decidable (a ≥ b) :=\nbegin\n    dsimp [(≥)],\n    apply nat.decidable_le b a,\nend\n\n-- Builds up in stages that the right-hand side of the and statement in the definition of prime\n-- is decidable. It begins by saying that it is decidable if a number equals 1.\n-- Then it is decidable if one number divides another. Finally, a lemma from MathLib is used\n-- which says that it is decidable that, if you have an upper bound for a predicate and that\n-- predicate is decidable for any specific natural number then it is decidable for all natural \n-- numbers.\ninstance decidable_divisors {p : ℕ} : decidable (∀ (m : ℕ), m < p → m ∣ p → m = 1) :=\nbegin\n    apply nat.decidable_ball_lt p (λ (m : ℕ) (a : m < p), m ∣ p → m = 1),    \nend\n\n-- First instance of decidability about primes. Uses and.decidable and the previous two\n-- lemmas to say that the whole statement is decidable.\n-- Note that haveI is used to update the instance cache after the instances are declared.\ninstance decidable_prime : decidable_pred prime :=\nbegin\n    intros p,\n    unfold prime,\n    haveI h₁ : decidable (p ≥ 2) := decidable_ge,\n    haveI h₂ : decidable (∀ (m : ℕ), m < p → m ∣ p → m = 1) := decidable_divisors,\n    apply and.decidable,\nend\n\n-- A second definition of primality. We will prove that this is equivalent to the\n-- first definition.\ndef prime' (p : ℕ) := p ≥ 2 ∧ ∀ (m ≤ p/2), m ∣ p → m = 1\n\n-- If a natural number a is less than or equal to b/2 then it is less than b\n-- Used as a lemma in prime_im_prime'\nlemma lt_half_lt {a b : ℕ} : (b > 0) → a ≤ b/2 → a < b :=\nbegin\n    intros h w,\n    have h₁ : 2 > 1, by exact dec_trivial,\n    have h₂ : b/2 < b, by apply div_lt_self h h₁,\n    have h₃ : a < b, by apply lt_of_le_of_lt w h₂,\n    exact h₃,\nend\n\n-- Essentially used to say that if p is prime then p > 0\nlemma ge_two_gt_zero {p : ℕ} : p ≥ 2 → p > 0 :=\nbegin\n    intros h,\n    dsimp [(≥)] at h,\n    have w₁ : 1 < p, by apply lt_of_succ_le h,\n    have w₂ : 0 < 1, by exact dec_trivial,\n    have w₃ : 0 < p, by apply lt_trans w₂ w₁,\n    dsimp [(>)],\n    exact w₃,\nend\n\n-- Non-zero factors of a number respect multiplication\nlemma div_gt_zero_eq {m p k: ℕ} : m ∣ p → m > 0 → p / m = k → p = m * k :=\nbegin\n    intros h₁ h₂ h₃,\n    have h₄ : m * p / m = p := nat.mul_div_cancel_left p h₂,\n    subst h₃,\n    have h₅ : m * p / m = m * (p / m) := nat.mul_div_assoc m h₁,\n    rw h₅ at h₄,\n    exact h₄.symm,\nend\n\n-- The reciprocals of positive natural numbers behave as you would\n-- expect them to under ≤\nlemma dvd_pos_lt {a b c : ℕ} : c ≤ b → 0 < c → a / b ≤ a / c :=\nbegin\n    intros h₁ h₂,\n    apply (le_div_iff_mul_le (a/b) a h₂).2,\n    have h₃ : a * c ≤ a * b := mul_le_mul_left a h₁,\n    apply le_trans,\n    swap,\n    apply div_mul_le_self',\n    exact b,\n    apply nat.mul_le_mul_left (a/b),\n    exact h₁,\nend\n\n-- The first definition prime → the second definition prime'\ntheorem prime_im_prime' {p : ℕ} : prime p → prime' p :=\nbegin\n    intro h,\n    unfold prime at h,\n    unfold prime',\n    split,\n    exact h.1,\n    have ge := h.1,\n    have h₁ := h.2,\n    intros m w₁ w₂,\n    have w₃ : p > 0, by apply ge_two_gt_zero ge,\n    have w₄ : m < p, by apply lt_half_lt w₃ w₁,\n    have w₅ : m = 1, by apply h₁ m w₄ w₂,\n    exact w₅,\nend\n\n-- The second definition prime' → the first definition prime\ntheorem prime'_im_prime {p : ℕ} : prime' p → prime p :=\nbegin\n    intros w,\n    unfold prime' at w,\n    unfold prime,\n    split,\n    exact w.1,\n    have ge := w.1,\n    intros m w₁ w₂,\n    by_cases (m ≤ p/2),\n    exact w.2 m h w₂,\n    simp at h,\n    have two_gt_zero : 2 > 0, by exact dec_trivial,\n    -- Wasn't written as a lemma because I felt it would be unwieldy to pass\n    -- hypotheses around\n    have one_lt_half : p / 2 ≥ 1, begin\n        have le : 2 ≤ p := ge,\n        have z : 2/2 ≤ p / 2 := nat.div_le_div_right le,\n        have h₁ : 2 / 2 = 1 := nat.div_self two_gt_zero,\n        rw [h₁] at z,\n        exact z,\n    end,\n    -- Same as above. Relies on hypotheses.\n    have h₄ : m > 0, begin\n        have zero_lt_one : 0 < 1, by exact dec_trivial,\n        have h₂ : 0 < p / 2, by apply lt_of_lt_of_le zero_lt_one one_lt_half,\n        exact (lt_trans h₂ h),\n    end,\n    have m_gt_one : m > 1, by apply lt_of_le_of_lt one_lt_half h,\n    have m_ge_two : m ≥ 2, by apply succ_le_of_lt m_gt_one,\n    have h₁ : p / m ≤ p / 2 := dvd_pos_lt m_ge_two two_gt_zero,\n    have h₂ : p / m ∣ p, by apply div_dvd_of_dvd w₂,\n    have h₃ : p / m = 1, by apply w.2 (p/m) h₁ h₂,\n    have h₅ : p = m * 1 := div_gt_zero_eq w₂ h₄ h₃,\n    simp at h₅,\n    subst h₅,\n    have h₆ : p ≥ p, by exact le_refl p,\n    have h₇ : ¬ (p < p), by simp,\n    exact (absurd w₁ h₇),\nend\n\n-- Uses the constructor for ↔ and the above implications to give an equivalence statement\ntheorem prime_equiv_statement {p : ℕ} : prime p ↔ prime' p :=\n⟨prime_im_prime', prime'_im_prime⟩\n\n-- See explanation above decidable_divisors. Construction is the same but upper bound used is p/2\n-- instead of p\ninstance decidable_divisors' {p : ℕ}: decidable (∀ (m : ℕ), m < p / 2 → m ∣ p → m = 1) :=\nnat.decidable_ball_lt (p / 2) (λ (m : ℕ) (a : m < p / 2), m ∣ p → m = 1)\n\n-- Says that it is possible to decide if a natural number is prime under prime'\ninstance decidable_prime' : decidable_pred prime' :=\nbegin\n    intros p,\n    unfold prime',\n    haveI h₁ : decidable (p ≥ 2) := decidable_ge,\n    haveI h₂ : decidable (∀ (m : ℕ), m < p / 2 → m ∣ p → m = 1) := decidable_divisors',\n    apply and.decidable,\nend\n\n-- Gives a \"better\" instance for decidable_prime by applying the equivalence of\n-- prime and prime'. It is better because you only need to check half as many natural numbers.\ninstance decidable_prime_v2 : decidable_pred prime :=\nbegin\n    intros p,\n    apply decidable_of_iff' (prime' p) (@prime_equiv_statement p),\nend\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 2/Q1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990283, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7552974968793359}}
{"text": "import data.int.gcd\nimport data.int.modeq\nimport tactic\n\nnamespace int\n\ntheorem dvd_one {n : ℤ} (h : n ∣ 1) : n = 1 ∨ n = -1 :=\nbegin\n\tby_cases hn : 0 ≤ n,\n\t{\tleft, exact eq_one_of_dvd_one hn h },\n\tright, \n\trw ← neg_dvd at h,\n\trw eq_neg_iff_eq_neg, symmetry,\n\texact eq_one_of_dvd_one (neg_nonneg.mpr $ le_of_not_ge hn) h,\nend\n\nsection gcd\n\ntheorem exists_mul_eq_gcd (a b : ℤ) : ∃ x y, a * x + b * y = gcd a b :=\nbegin\n\thave : ∃ x y : ℤ, ↑(nat_abs a) * x + ↑(nat_abs b) * y = gcd a b,\n\t{\tuse [nat.gcd_a (nat_abs a) (nat_abs b), nat.gcd_b (nat_abs a) (nat_abs b)],\n\t\trw ← nat.gcd_eq_gcd_ab, congr },\n\trcases this with ⟨x, y, hxy⟩,\n\tcases nat_abs_eq a with ha ha,\n\t{\trw ← ha at hxy,\n\t\tcases nat_abs_eq b with hb hb,\n\t\t{\trwa ← hb at hxy, use [x, y, hxy] },\n\t\tuse [x, -y], conv_lhs { rw hb }, simpa },\n\tcases nat_abs_eq b with hb hb,\n\t{\tuse [-x, y], conv_lhs { rw [ha, hb] }, simpa },\n\tuse [-x, -y], conv_lhs { rw [ha, hb] }, simpa,\nend\n\ntheorem mul_of_coprime_mul {a b c d : ℤ} (hab : gcd a b = 1) (h : a * c = b * d) :\n\t∃ n, c = n * b ∧ d = n * a  :=\nbegin\n\trcases exists_mul_eq_gcd a b with ⟨x, y, hxy⟩,\n\tsimp [hab] at hxy,\n\tuse d * x + c * y, split,\n\t{ calc c\n\t      = c * (a * x + b * y)   : by rw [hxy, mul_one]\n\t\t... = a * c * x + c * b * y : by ring\n\t\t... = b * d * x + c * b * y : by rw h\n\t\t... = (d * x + c * y) * b   : by ring },\n\t{ calc d\n\t\t    = d * (a * x + b * y)   : by rw [hxy, mul_one]\n\t\t... = d * a * x + b * d * y : by ring\n\t\t... = d * a * x + a * c * y : by rw ← h\n\t\t... = (d * x + c * y) * a   : by ring },\nend\n\nend gcd\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/int.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7552974931026544}}
{"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.basic\nimport data.fin_extra\nopen list \n\nvariables {α : 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 ≥ n.  \n\n The standard library defines (l.nth i) to be of type (option α),\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 ≥ 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 ⟨i,h⟩ gives a term of type\n (fin n), and we define l.fin_nth ⟨i,h⟩ to be x again. \n-/\ndef fin_nth (l : list α) (i : fin l.length) : α := \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 : α) (l : list α) (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 α 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 ≠ 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₀ (R : α → α → Prop) (l : list α) := \n ∀ (i j : fin l.length), i < j → R (l.fin_nth i) (l.fin_nth j)\n\ndef pairwise_nth (R : α → α → Prop) (l : list α) := \n ∀ {i j : ℕ} (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 : α → α → Prop} {l : list α} \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    cases 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 : α → α → Prop} {l : list α} \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 : ∀ (b ∈ l), (R a b) :=\n    begin\n      intros b b_in_l,\n      rcases nth_le_of_mem b_in_l with ⟨j,⟨hj,eq_b⟩⟩,\n      rw [← 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 : α → α → Prop} {l : list α} :\n (pairwise R l) ↔ (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 α] [decidable_rel (@has_le.le α _)]\n\ndef strongly_sorted (l : list α) : Prop := \n list.pairwise has_lt.lt l\n\nlemma strongly_sorted_of_sorted_nodup (l : list α) :\n l.sorted has_le.le → l.nodup → 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 : ∀ (x : α) (x_in_l0 : x ∈ 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 α) : \n l.strongly_sorted → 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 : ∀ x ∈ l0, a ≤ x := \n   λ 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 α) : \n l.strongly_sorted → 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 : ∀ x ∈ l0, a ≠ x := \n   λ 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 α} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l)\n {i j : ℕ} (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 ≠ y := pairwise_nth_mp l_nodup hi hj,\n  have x_le_y : x ≤ 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 α} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l)\n {i j : ℕ} (hi : i ≤ j) (hj : j < l.length) :\n (l.nth_le i (lt_of_le_of_lt hi hj) ≤ 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 α} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l) \n { i j : ℕ } (hi : i < l.length) (hj : j < l.length) :\n  (i < j) ↔ (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 α} \n (l_nodup : list.nodup l)\n (l_sorted : list.sorted has_le.le l) \n { i j : ℕ } (hi : i < l.length) (hj : j < l.length) :\n  (i ≤ j) ↔ (l.nth_le i hi ≤ 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 α] [decidable_rel (@has_le.le α _)]\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' (α : Type*) : equivalence (@perm α) :=\nmk_equivalence (@perm α) (@perm.refl α) (@perm.symm α) (@perm.trans α)\n\ninstance list.is_setoid' (α : Type*) : setoid (list α) :=\nsetoid.mk (@perm α) (list.perm.eqv' α)\n\nlemma sort_spec (s : finset α) (l : list α) \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_perm_of_sorted (@quotient.exact (list α) (list.is_setoid' α) _ _ h0) (sort_sorted has_le.le s) l_sorted,\n let ll : multiset α := quot.mk _ l,\n have ll_nodup : ll.nodup := multiset.coe_nodup.mpr l_nodup,\n have ll_eq : (⟨ll,ll_nodup⟩ : finset α) = 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 α := quot.mk _ m,\n have mm_nodup : mm.nodup := multiset.coe_nodup.mpr m_nodup,\n have mm_eq : (⟨mm,mm_nodup⟩ : finset α) = 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_perm_of_sorted 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 α) (l : list α) \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_perm_of_sorted\n     (@quotient.exact \n      (list α)\n      (list.is_setoid' α) \n      _ \n      _ \n      (@congr_arg \n       (finset α)\n       (multiset α) \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 α has\n a decidable linear order and s is a finite subset of α that need not contain \n all elements of α.  In order to talk about an order-equivalence we need to \n convert s into a separate type by considering {a // a ∈ 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 α} {n : ℕ} (s_card : s.card = n)\ninclude s_card\n\n#check list.mem_to_finset\ndef rank_equiv : { a // a ∈ s } ≃ 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 α) (λ 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 : ∀ a : α, a ∈ s ↔ a ∈ l :=\n  λ a, @eq.subst (finset α) (λ t, a ∈ t ↔ a ∈ l) _ _ l_eq_s\n         list.mem_to_finset,\n let to_fun : { a // a ∈ s } → fin n := \n begin\n  intro a,\n  have a_in_l : a.val ∈ l := (mem_equiv a.val).mp a.property,\n  let i : ℕ := 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 ⟨i,i_lt_n⟩ \n end,\n let inv_fun : fin n → { a // a ∈ s } := \n begin\n  intro i,\n  have i_is_lt : i.val < l.length := @eq.subst ℕ (λ 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 ∈ s := (mem_equiv a).mpr (l.nth_le_mem i.val i_is_lt),\n  exact ⟨a,a_in_s⟩ \n end,\n have left_inv : ∀ a, inv_fun (to_fun a) = a := \n begin\n  intro a,\n  rcases a with ⟨a_val,a_in_s⟩,\n  have a_in_l : a_val ∈ 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 : ∀ i, to_fun (inv_fun i) = i := \n begin\n  intro i,\n  rcases i with ⟨i_val,i_lt_n⟩,\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[subtype.val],\n  exact list.nth_le_index_of l_nodup i_val i_lt_len,\n end,\n exact ⟨to_fun,inv_fun,left_inv,right_inv⟩, \nend\n\nlemma seq_le (i1 i2 : fin n) :\n i1 ≤ i2 ↔ (((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 α) (λ 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 ↔ (((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 α) (λ 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 ∈ s }) :\n a1.val ≤ a2.val ↔ (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_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[← e1,← 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 ∈ s }) :\n a1.val < a2.val ↔ ((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[← e1,← 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 ∈ s}) :\n ((rank_equiv s_card).to_fun a).val = card (s.filter (λ x, x < a.val)) := \nbegin\n let f := rank_equiv s_card,\n let u := s.filter (λ x, x < a.val),\n let ut := {x // x ∈ 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 → fin k.val := \n begin\n  intro x,\n  let x0 : { x // x ∈ s } := ⟨x.val,(mem_filter.mp x.property).left⟩,\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 ⟨i.val,i_lt_k_val⟩,\n end,\n let g_inv_fun : fin k.val → ut := \n begin\n  intro i,\n  let i0 : fin n := ⟨i.val,lt_trans i.is_lt k.is_lt⟩,\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 ∈ u := \n  begin\n   apply mem_filter.mpr,\n   exact ⟨x0.property,x_lt_a⟩,\n  end,\n  exact ⟨x0.val,x_in_u⟩, \n end,\n have g_left_inv : ∀ 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 end,\n have g_right_inv : ∀ 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[subtype.val]\n end,\n let g : ut ≃ fin k.val := ⟨g_to_fun,g_inv_fun,g_left_inv,g_right_inv⟩,\n let h0 := fintype.card_congr g, \n let h1 := @finset.card_attach α 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 α] [decidable_rel (@has_le.le α _)]\nvariables [fintype α] {n : ℕ} (α_card : card α = n)\ninclude α_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 α), which is essentially a proof that the whole type \n α is finite. From this we build an equivalence from α to (fin n), and again \n we prove the order properties as separate lemmas.\n-/\n\ndef rank_equiv : α ≃ fin n := \nbegin\n have h0 : finset.card (@elems α _) = n := α_card,\n let f := finset.rank_equiv h0,\n let to_fun : α → fin n := λ a, f.to_fun ⟨a,mem_univ a⟩,\n let inv_fun : fin n → α := λ i, (f.inv_fun i).val,\n have left_inv : ∀ a : α, inv_fun (to_fun a) = a := \n  λ a, congr_arg subtype.val (f.left_inv ⟨a,mem_univ a⟩),\n have right_inv : ∀ i : fin n, to_fun (inv_fun i) = i := \n begin\n  intro i,\n  have e : f.inv_fun i = ⟨inv_fun i,mem_univ _⟩ := \n   by {apply subtype.eq,simp[inv_fun]},\n  dsimp[inv_fun,to_fun],simp[e]\n end,\n exact ⟨to_fun,inv_fun,left_inv,right_inv⟩,\nend\n\nlemma seq_le (i1 i2 : fin n) : \n i1 ≤ i2 ↔ (rank_equiv α_card).inv_fun i1 ≤ (rank_equiv α_card).inv_fun i2 := \n  (seq_le α_card) i1 i2\n\nlemma seq_lt (i1 i2 : fin n) : \n i1 < i2 ↔ (rank_equiv α_card).inv_fun i1 < (rank_equiv α_card).inv_fun i2 := \n  (seq_lt α_card) i1 i2\n\nlemma rank_le (a1 a2 : α) : \n a1 ≤ a2 ↔ (rank_equiv α_card).to_fun a1 ≤ (rank_equiv α_card).to_fun a2 := \n  (rank_le α_card) ⟨a1,mem_univ a1⟩ ⟨a2,mem_univ a2⟩\n\nlemma rank_lt (a1 a2 : α) : \n a1 < a2 ↔ (rank_equiv α_card).to_fun a1 < (rank_equiv α_card).to_fun a2 := \n  (rank_lt α_card) ⟨a1,mem_univ a1⟩ ⟨a2,mem_univ a2⟩\n\nend fintype\n\nnamespace fin \n/-\n The only strictly increasing self-map of (fin n) is the identity\n-/\nlemma rigid {n : ℕ} {f : fin n → fin n} \n (f_mono : ∀ {i1 i2 : fin n}, i1 < i2 → (f i1) < (f i2)) :\n  ∀ (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 → 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 : ∀ (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 : ∀ {i1 i2 : fin n0}, i1 < i2 → (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[← (succ_f0 i1)] at h0,\n   rw[← (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 : ∀ (j : fin n0.succ), f 0 = j → j = 0 := \n  begin\n   intros j e, cases j with j_val j_is_lt, 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 := ⟨j0_val,j0_is_lt⟩,\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) (λ 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 with i_val i_is_lt, 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 ⟨i0_val,i0_is_lt⟩),\n   let h1 := succ_f0 ⟨i0_val,i0_is_lt⟩,\n   let h2 := h1.symm.trans h0,\n   exact h2,\n  }\n }\nend\n\nend fin", "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/order/sort_rank.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8558511469672595, "lm_q1q2_score": 0.7552269069134612}}
{"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-/\nimport order.succ_pred.basic\n/-!\n# Relations on types with a `succ_order`\n\nThis file contains properties about relations on types with a `succ_order`\nand their closure operations (like the transitive closure).\n-/\n\nopen set relation succ_order pred_order function\n\nsection partial_succ\nvariables {α : Type*} [partial_order α] [succ_order α] [is_succ_archimedean α]\n\n/-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_succ_of_le (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n ≤ m) : refl_trans_gen r n m :=\nbegin\n  revert h, refine succ.rec _ _ hnm,\n  { intros h, exact refl_trans_gen.refl },\n  { intros m hnm ih h,\n    have : refl_trans_gen r n m := ih (λ i hi, h i ⟨hi.1, hi.2.trans_le $ le_succ m⟩),\n    cases (le_succ m).eq_or_lt with hm hm, { rwa [← hm] },\n    exact this.tail (h m ⟨hnm, hm⟩) }\nend\n\n/-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `succ i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_succ_of_ge (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m ≤ n) : refl_trans_gen r n m :=\nby { rw [← refl_trans_gen_swap], exact refl_trans_gen_of_succ_of_le (swap r) h hmn }\n\n/-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_lt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico n m, r i (succ i)) (hnm : n < m) : trans_gen r n m :=\n(refl_trans_gen_iff_eq_or_trans_gen.mp $ refl_trans_gen_of_succ_of_le r h hnm.le).resolve_left\n  hnm.ne'\n\n/-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` if `succ i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_gt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ico m n, r (succ i) i) (hmn : m < n) : trans_gen r n m :=\n(refl_trans_gen_iff_eq_or_trans_gen.mp $ refl_trans_gen_of_succ_of_ge r h hmn.le).resolve_left\n  hmn.ne\n\nend partial_succ\n\nsection linear_succ\nvariables {α : Type*} [linear_order α] [succ_order α] [is_succ_archimedean α]\n\n/-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ succ i` and `succ i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_succ (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : refl_trans_gen r n m :=\n(le_total n m).elim (refl_trans_gen_of_succ_of_le r h1) $ refl_trans_gen_of_succ_of_ge r h2\n\n/-- For `n ≠ m`,`(n, m)` is in the transitive closure of a relation `~` if `i ~ succ i` and\n  `succ i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_ne (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i)\n  (hnm : n ≠ m) : trans_gen r n m :=\n(refl_trans_gen_iff_eq_or_trans_gen.mp (refl_trans_gen_of_succ r h1 h2)).resolve_left hnm.symm\n\n\n/-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ succ i` and\n  `succ i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_succ_of_reflexive (r : α → α → Prop) {n m : α} (hr : reflexive r)\n  (h1 : ∀ i ∈ Ico n m, r i (succ i)) (h2 : ∀ i ∈ Ico m n, r (succ i) i) : trans_gen r n m :=\nbegin\n  rcases eq_or_ne m n with rfl|hmn, { exact trans_gen.single (hr m) },\n  exact trans_gen_of_succ_of_ne r h1 h2 hmn.symm\nend\n\nend linear_succ\n\nsection partial_pred\nvariables {α : Type*} [partial_order α] [pred_order α] [is_pred_archimedean α]\n\n/-- For `m ≤ n`, `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_pred_of_ge (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m ≤ n) : refl_trans_gen r n m :=\n@refl_trans_gen_of_succ_of_le (order_dual α) _ _ _ r n m (λ x hx, h x ⟨hx.2, hx.1⟩) hnm\n\n/-- For `n ≤ m`, `(n, m)` is in the reflexive-transitive closure of `~` if `pred i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_pred_of_le (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n ≤ m) : refl_trans_gen r n m :=\n@refl_trans_gen_of_succ_of_ge (order_dual α) _ _ _ r n m (λ x hx, h x ⟨hx.2, hx.1⟩) hmn\n\n/-- For `m < n`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `i ~ pred i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_gt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc m n, r i (pred i)) (hnm : m < n) : trans_gen r n m :=\n@trans_gen_of_succ_of_lt (order_dual α) _ _ _ r _ _ (λ x hx, h x ⟨hx.2, hx.1⟩) hnm\n\n/-- For `n < m`, `(n, m)` is in the transitive closure of a relation `~` for `n ≠ m` if `pred i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_lt (r : α → α → Prop) {n m : α}\n  (h : ∀ i ∈ Ioc n m, r (pred i) i) (hmn : n < m) : trans_gen r n m :=\n@trans_gen_of_succ_of_gt (order_dual α) _ _ _ r _ _ (λ x hx, h x ⟨hx.2, hx.1⟩) hmn\n\nend partial_pred\n\nsection linear_pred\nvariables {α : Type*} [linear_order α] [pred_order α] [is_pred_archimedean α]\n\n/-- `(n, m)` is in the reflexive-transitive closure of `~` if `i ~ pred i` and `pred i ~ i`\n  for all `i` between `n` and `m`. -/\nlemma refl_trans_gen_of_pred (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : refl_trans_gen r n m :=\n@refl_trans_gen_of_succ (order_dual α) _ _ _ r n m (λ x hx, h1 x ⟨hx.2, hx.1⟩)\n  (λ x hx, h2 x ⟨hx.2, hx.1⟩)\n\n/-- For `n ≠ m`, `(n, m)` is in the transitive closure of a relation `~` if `i ~ pred i` and\n  `pred i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_ne (r : α → α → Prop) {n m : α}\n  (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i)\n  (hnm : n ≠ m) : trans_gen r n m :=\n@trans_gen_of_succ_of_ne (order_dual α) _ _ _ r n m (λ x hx, h1 x ⟨hx.2, hx.1⟩)\n  (λ x hx, h2 x ⟨hx.2, hx.1⟩) hnm\n\n/-- `(n, m)` is in the transitive closure of a reflexive relation `~` if `i ~ pred i` and\n  `pred i ~ i` for all `i` between `n` and `m`. -/\nlemma trans_gen_of_pred_of_reflexive (r : α → α → Prop) {n m : α} (hr : reflexive r)\n  (h1 : ∀ i ∈ Ioc m n, r i (pred i)) (h2 : ∀ i ∈ Ioc n m, r (pred i) i) : trans_gen r n m :=\n@trans_gen_of_succ_of_reflexive (order_dual α) _ _ _ r n m hr (λ x hx, h1 x ⟨hx.2, hx.1⟩)\n  (λ x hx, h2 x ⟨hx.2, hx.1⟩)\n\nend linear_pred\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/succ_pred/relation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.855851154320682, "lm_q1q2_score": 0.7552269054635563}}
{"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\nimport combinatorics.composition\nimport data.nat.parity\nimport tactic.apply_fun\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\nvariables {α : Type*}\n\nopen multiset\nopen_locale big_operators\n\nnamespace nat\n\n/-- A partition of `n` is a multiset of positive integers summing to `n`. -/\n@[ext, derive decidable_eq] structure partition (n : ℕ) :=\n(parts : multiset ℕ)\n(parts_pos : ∀ {i}, i ∈ parts → 0 < i)\n(parts_sum : parts.sum = n)\n\nnamespace partition\n\n/-- A composition induces a partition (just convert the list to a multiset). -/\ndef of_composition (n : ℕ) (c : composition n) : partition n :=\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\nlemma of_composition_surj {n : ℕ} : function.surjective (of_composition n) :=\nbegin\n  rintro ⟨b, hb₁, hb₂⟩,\n  rcases quotient.exists_rep b with ⟨b, rfl⟩,\n  refine ⟨⟨b, λ i hi, hb₁ hi, _⟩, partition.ext _ _ rfl⟩,\n  simpa using hb₂\nend\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-- proof obligation `l.sum = n`.\ndef of_sums (n : ℕ) (l : multiset ℕ) (hl : l.sum = n) : partition n :=\n{ parts := l.filter (≠ 0),\n  parts_pos := λ i hi, nat.pos_of_ne_zero $ by apply of_mem_filter hi,\n  parts_sum :=\n  begin\n    have lt : l.filter (= 0) + l.filter (≠ 0) = l := filter_add_not _ l,\n    apply_fun multiset.sum at lt,\n    have lz : (l.filter (= 0)).sum = 0,\n    { rw multiset.sum_eq_zero_iff,\n      simp },\n    simpa [lz, hl] using lt,\n  end }\n\n/-- A `multiset ℕ` induces a partition on its sum. -/\ndef of_multiset (l : multiset ℕ) : partition l.sum :=\nof_sums _ l rfl\n\n/-- The partition of exactly one part. -/\ndef indiscrete_partition (n : ℕ) : partition n :=\nof_sums n {n} rfl\n\ninstance {n : ℕ} : inhabited (partition n) := ⟨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-/\nlemma count_of_sums_of_ne_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) {i : ℕ} (hi : i ≠ 0) :\n  (of_sums n l hl).parts.count i = l.count i :=\ncount_filter_of_pos hi\n\nlemma count_of_sums_zero {n : ℕ} {l : multiset ℕ} (hl : l.sum = n) :\n  (of_sums n l hl).parts.count 0 = 0 :=\ncount_filter_of_neg (λ h, h rfl)\n\n/--\nShow there are finitely many partitions by considering the surjection from compositions to\npartitions.\n-/\ninstance (n : ℕ) : fintype (partition n) :=\nfintype.of_surjective (of_composition n) of_composition_surj\n\n/-- The finset of those partitions in which every part is odd. -/\ndef odds (n : ℕ) : finset (partition n) :=\nfinset.univ.filter (λ c, ∀ i ∈ c.parts, ¬ even i)\n\n/-- The finset of those partitions in which each part is used at most once. -/\ndef distincts (n : ℕ) : finset (partition n) :=\nfinset.univ.filter (λ c, c.parts.nodup)\n\n/-- The finset of those partitions in which every part is odd and used at most once. -/\ndef odd_distincts (n : ℕ) : finset (partition n) := odds n ∩ distincts n\n\nend partition\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/partition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7552269036690283}}
{"text": "/- Homework 2.2: Functional Programming — Trees -/\n\n/- Question 1: Huffman's algorithm -/\n\n/- Recall the following definition from the lecture. -/\n\ninductive tree (α : Type)\n| leaf : ℕ → α → tree\n| inner : ℕ → tree → tree → tree\n\nexport tree (leaf inner)\n\n/- To make our lives easy, we will fix a type α of symbols equipped with decidable equality\nthroughout this question. -/\n\nsection\n\nparameter (α : Type)\nparameter [decidable_eq α]\n\n/- We start by defining the alphabet of a tree: the set of its labels. We use lists to represent\nsets to get executability for free. The cost is that we must ignore the order or number of\noccurrences of elements in a list when comparing alphabets. -/\n\ndef alphabet : tree α → list α\n| (leaf _ a)    := [a]\n| (inner _ l r) := alphabet l ++ alphabet r\n\n/- 1.1. Define the following function, so that we can obtain the alphabet of an entire forest\n(i.e. list of trees).\n\nHint: Through this exercise, try to keep your definitions as simple as possible, because this will\naffect proving ease further down. -/\n\ndef alphabet_list : list (tree α) → list α\n| [] := []\n| (x :: xs) := alphabet_list xs ++ alphabet x\n\n\n/- A tree is consistent if it contains no duplicate labels. This can be defined as an inductive\npredicate. -/\n\ninductive consistent : tree α → Prop\n| consistent_leaf (w : ℕ) (a : α) : consistent (leaf w a)\n| consistent_inner (w : ℕ) (l : tree α) (r : tree α) :\n  consistent l → consistent r → (∀a, a ∈ alphabet l → a ∈ alphabet r → false) →\n  consistent (inner w l r)\n\n/- 1.2. A forest is consistent if it contains no duplicate labels (even in different trees). Define\nan inductive predicate `consistent_list` that captures this property. -/\n\ninductive consistent_trees : list (tree α) → Prop\n| consistent_nil (w: ℕ) (a: α) : consistent_trees[]\n| consistent_cons (w: ℕ) (t: tree α) (ts: list (tree α) : consistent t → consistent_trees ts → (∀a, a ∈ alphabet t → a ∈ alphabet_list ts → false) → \nconsistent_trees ts\n/- 1.3. The height of a tree is the length of the longest path from its root node to a leaf. A tree\nconsisting of a single node has height 0 by convention. Define a recursive function `height` that\ncomputes this.\n\nHint: You may use the built-in `max` function. -/\n\ndef height {α: Type} : tree α → ℕ\n| (leaf _ a) := 1\n| (inner _ l r) := 1 + max (height l) (height r)\n\n\n/- 1.4. Now define the same function on forests, where the height of a forest is defined as the\nheight of its tallest tree. -/\n\ndef height_forest {α: Type}: list(tree α) → ℕ \n| [] := 0\n| (x :: xs) :=  1 + max (height x) (height_forest xs)\n\n\n/- 1.5. Define a function that returns the depth of a symbol in a tree. For example, if the symbol\nis stored in a leaf node immediately below the root, it would be at depth 1. Symbols that do not\noccur in the tree are conventionally put at depth 0. For symbols that occur several times as labels,\nyou can arbitrarily choose which occurrence to consider (e.g. the leftmost one). -/\n\ndef depth : tree α → α → ℕ\n| (leaf _ a) x := 1\n| (inner _ l r) x := depth l x + depth r x \n\n\n/- 1.6. State and prove that the depth of a symbol in a tree is less than or equal to the height of\nthe tree.\n\nHint: You might find the lemmas `le_max_left`, `add_le_add_left`, and similarly named ones useful.\nUse Visual Studio Code's Command Palette to explore Lean's library (e.g. `#le_max`). -/\nlemma depthlessequal :∀t : tree α, consistent t → ∀a ∈ alphabet t, depth t a <= height t\n| (leaf _ a)      ct := begin repeat {apply exists.intro}, simp[alphabet], simp[depth, height], intro s, simp[le_of_eq] end\n| (inner _ l r)   ct := \nbegin \n repeat{apply exists.intro},\n simp[alphabet],\n simp[depth, height],\n intro s,\n intro a,\n simp[le_max],\n \n  end\n\n/- 1.7. A tree's height is not only an upper bound on the depth of symbols stored in the tree. It is\nalso a tight bound. Complete the following proof. -/\n\nlemma exists_at_height : ∀t : tree α, consistent t → ∃a ∈ alphabet t, depth t a = height t\n| (leaf _ a)      ct :=\n  begin\n    repeat {apply exists.intro},\n    simp[alphabet],\n    simp[depth, height]\n  end\n| t@(inner _ l r) ct :=  -- `t@` introduces the alias `t` for `inner _ l r`\n  have cl : consistent l :=\n   begin\n    have bla: ∀ (t : tree α), consistent t → (∃ (a : α) (H : a ∈ alphabet t), depth t a = height t) ,\n    intro a,\n    intro b,\n    apply exists_at_height,\n    assumption,\n    \n\n   end\n  have cr : consistent r :=\n   sorry,\n  let ⟨b, b_in_alpha_l, depth_l_b_eq_height_l⟩ := exists_at_height l cl in\n  let ⟨c, c_in_alpha_r, depth_r_c_eq_height_r⟩ := exists_at_height r cr in\n  let b_or_c := if height r ≤ height l then b else c in\n  have borc_in_alpha_t : b_or_c ∈ alphabet t :=\n   begin\n    repeat {apply exists.intro},\n    simp[alphabet],\n    apply or.inr,\n    simp [b_or_c],\n    by_cases (ite (height r ≤ height l) b c ∈ alphabet r),\n    \n  \n\n\n    \n    \n   end\n  have depth_t_borc_eq_height_t : depth t b_or_c = height t :=\n   sorry,  -- **optional**\n  ⟨b_or_c, borc_in_alpha_t, depth_t_borc_eq_height_t⟩\n\nend\n\n\n/- Question 2: Enter your question here. -/\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 5/22_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.908617906830944, "lm_q2_score": 0.8311430541321951, "lm_q1q2_score": 0.7551914621226732}}
{"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.fintype.basic\nimport data.finset.basic\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 {α : Type u} [dec : decidable_eq α]\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 (α : Type u) : Type u\n| zero : regular_expression\n| epsilon : regular_expression\n| char : α → regular_expression\n| plus : regular_expression → regular_expression → regular_expression\n| comp : regular_expression → regular_expression → regular_expression\n| star : regular_expression → regular_expression\n\nnamespace regular_expression\n\ninstance : inhabited (regular_expression α) := ⟨zero⟩\n\ninstance : has_add (regular_expression α) := ⟨plus⟩\ninstance : has_mul (regular_expression α) := ⟨comp⟩\ninstance : has_one (regular_expression α) := ⟨epsilon⟩\ninstance : has_zero (regular_expression α) := ⟨zero⟩\n\nattribute [pattern] has_mul.mul\n\n@[simp] lemma zero_def : (zero : regular_expression α) = 0 := rfl\n@[simp] lemma one_def : (epsilon : regular_expression α) = 1 := rfl\n\n@[simp] lemma plus_def (P Q : regular_expression α) : plus P Q = P + Q := rfl\n@[simp] lemma comp_def (P Q : regular_expression α) : comp P Q = P * Q := rfl\n\n/-- `matches P` provides a language which contains all strings that `P` matches -/\ndef matches : regular_expression α → language α\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 α).matches = 0 := rfl\n@[simp] lemma matches_epsilon_def : (1 : regular_expression α).matches = 1 := rfl\n@[simp] lemma matches_add_def (P Q : regular_expression α) :\n  (P + Q).matches = P.matches + Q.matches := rfl\n@[simp] lemma matches_mul_def (P Q : regular_expression α) :\n  (P * Q).matches = P.matches * Q.matches := rfl\n@[simp] lemma matches_star_def (P : regular_expression α) : 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 α → 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 α → α → regular_expression α\n| 0 _ := 0\n| 1 _ := 0\n| (char a₁) a₂ := if a₁ = a₂ 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 α → list α → bool\n| P [] := match_epsilon P\n| P (a::as) := rmatch (P.deriv a) as\n\n@[simp] lemma zero_rmatch (x : list α) : rmatch 0 x = ff :=\nby induction x; simp [rmatch, match_epsilon, deriv, *]\n\n\n\nlemma char_rmatch_iff (a : α) (x : list α) : rmatch (char a) x ↔ 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 α) (x : list α) :\n  (P + Q).rmatch x ↔ P.rmatch x ∨ 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 α) (x : list α) :\n  (P * Q).rmatch x ↔ ∃ t u : list α, x = t ++ u ∧ P.rmatch t ∧ 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 ⟨ [], [], rfl, _ ⟩,\n      rw [rmatch, rmatch],\n      rwa band_coe_iff at h },\n    { rintro ⟨ t, u, h₁, h₂ ⟩,\n      cases list.append_eq_nil.1 h₁.symm with ht hu,\n      subst ht,\n      subst hu,\n      repeat {rw rmatch at h₂},\n      finish } },\n  { rw [rmatch, deriv],\n    split_ifs with hepsilon,\n    { rw [add_rmatch_iff, ih],\n      split,\n      { rintro (⟨ t, u, _ ⟩ | h),\n        { exact ⟨ a :: t, u, by tauto ⟩ },\n        { exact ⟨ [], a :: x, rfl, hepsilon, h ⟩ } },\n      { rintro ⟨ t, u, h, hP, hQ ⟩,\n        cases t with b t,\n        { right,\n          rw list.nil_append at h,\n          rw ←h at hQ,\n          exact hQ },\n        { left,\n          refine ⟨ t, u, by finish, _, hQ ⟩,\n          rw rmatch at hP,\n          convert hP,\n          finish } } },\n    { rw ih,\n      split;\n      rintro ⟨ t, u, h, hP, hQ ⟩,\n      { exact ⟨ a :: t, u, by tauto ⟩ },\n      { cases t with b t,\n        { contradiction },\n        { refine ⟨ t, u, by finish, _, hQ ⟩,\n          rw rmatch at hP,\n          convert hP,\n          finish } } } }\nend\n\nlemma star_rmatch_iff (P : regular_expression α) : ∀ (x : list α),\n  (star P).rmatch x ↔ ∃ S : list (list α), x = S.join ∧ ∀ t ∈ S, t ≠ [] ∧ P.rmatch t\n| x :=\nbegin\n  have A : ∀ (m n : ℕ), 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 := λ 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 ⟨ t, u, hs, ht, hu ⟩,\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 ⟨ S', hsum, helem ⟩,\n      use (a :: t) :: S',\n      split,\n      { finish },\n      { intros t' ht',\n        cases ht' with ht' ht',\n        { rw ht',\n          exact ⟨ dec_trivial, ht ⟩ },\n        { exact helem _ ht' } } } },\n  { rintro ⟨ S, hsum, helem ⟩,\n    cases x with a x,\n    { dec_trivial },\n    { rw [rmatch, deriv, mul_rmatch_iff],\n      cases S with t' U,\n      { exact ⟨ [], [], by tauto ⟩ },\n      { cases t' with b t,\n        { finish },\n        refine ⟨ t, U.join, by finish, _, _ ⟩,\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 ⟨ U, rfl, λ t h, helem t _ ⟩,\n          right,\n          assumption } } } }\nend\nusing_well_founded {\n  rel_tac := λ _ _, `[exact ⟨(λ L₁ L₂ : list _, L₁.length < L₂.length), inv_image.wf _ nat.lt_wf⟩]\n}\n\n@[simp] lemma rmatch_iff_matches (P : regular_expression α) :\n  ∀ x : list α, P.rmatch x ↔ x ∈ 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₁ ih₂ {\n    rw [add_rmatch_iff, ih₁, ih₂],\n    refl },\n  case comp : P Q ih₁ ih₂ {\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 ⟨ x, y, hsum, hmatch₁, hmatch₂ ⟩,\n      rw ih₁ at hmatch₁,\n      rw ih₂ at hmatch₂,\n      exact ⟨ x, hmatch₁, y, hmatch₂, hsum.symm ⟩ },\n    { rintro ⟨ x, hmatch₁, y, hmatch₂, hsum ⟩,\n      rw ←ih₁ at hmatch₁,\n      rw ←ih₂ at hmatch₂,\n      exact ⟨ x, y, hsum.symm, hmatch₁, hmatch₂ ⟩ } },\n  case star : _ ih {\n    rw [star_rmatch_iff, language.star_def_nonempty],\n    split,\n    all_goals\n    { rintro ⟨ S, hx, hS ⟩,\n      refine ⟨ S, hx, _ ⟩,\n      intro y,\n      specialize hS y },\n    { rw ←ih y,\n      tauto },\n    { rw ih y,\n      tauto } }\nend\n\ninstance (P : regular_expression α) : decidable_pred P.matches :=\nbegin\n  intro x,\n  change decidable (x ∈ P.matches),\n  rw ←rmatch_iff_matches,\n  exact eq.decidable _ _\nend\n\nend regular_expression\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/regular_expressions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7551914497825479}}
{"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.finset.nat_antidiagonal\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.Data.Multiset.NatAntidiagonal\n\n/-!\n# Antidiagonals in ℕ × ℕ as finsets\n\nThis file defines the antidiagonals of ℕ × ℕ 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.NatAntidiagonal` and `Data.Multiset.NatAntidiagonal`.\n-/\n\n\nnamespace Finset\n\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 : ℕ) : Finset (ℕ × ℕ) :=\n  ⟨Multiset.Nat.antidiagonal n, Multiset.Nat.nodup_antidiagonal n⟩\n#align finset.nat.antidiagonal Finset.Nat.antidiagonal\n\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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := by\n  rw [antidiagonal, mem_def, Multiset.Nat.mem_antidiagonal]\n#align finset.nat.mem_antidiagonal Finset.Nat.mem_antidiagonal\n\n/-- The cardinality of the antidiagonal of `n` is `n + 1`. -/\n@[simp]\ntheorem card_antidiagonal (n : ℕ) : (antidiagonal n).card = n + 1 := by simp [antidiagonal]\n#align finset.nat.card_antidiagonal Finset.Nat.card_antidiagonal\n\n/-- The antidiagonal of `0` is the list `[(0, 0)]` -/\n@[simp]\ntheorem antidiagonal_zero : antidiagonal 0 = {(0, 0)} := rfl\n#align finset.nat.antidiagonal_zero Finset.Nat.antidiagonal_zero\n\ntheorem antidiagonal_succ (n : ℕ) :\n    antidiagonal (n + 1) =\n      cons (0, n + 1)\n        ((antidiagonal n).map\n          (Function.Embedding.prodMap ⟨Nat.succ, Nat.succ_injective⟩ (Function.Embedding.refl _)))\n        (by simp) := by\n  apply eq_of_veq\n  rw [cons_val, map_val]\n  · apply Multiset.Nat.antidiagonal_succ\n#align finset.nat.antidiagonal_succ Finset.Nat.antidiagonal_succ\n\ntheorem antidiagonal_succ' (n : ℕ) :\n    antidiagonal (n + 1) =\n      cons (n + 1, 0)\n        ((antidiagonal n).map\n          (Function.Embedding.prodMap (Function.Embedding.refl _) ⟨Nat.succ, Nat.succ_injective⟩))\n        (by simp) := by\n  apply eq_of_veq\n  rw [cons_val, map_val]\n  exact Multiset.Nat.antidiagonal_succ'\n#align finset.nat.antidiagonal_succ' Finset.Nat.antidiagonal_succ'\n\ntheorem antidiagonal_succ_succ' {n : ℕ} :\n    antidiagonal (n + 2) =\n      cons (0, n + 2)\n        (cons (n + 2, 0)\n            ((antidiagonal n).map\n              (Function.Embedding.prodMap ⟨Nat.succ, Nat.succ_injective⟩\n                ⟨Nat.succ, Nat.succ_injective⟩)) <|\n          by simp)\n        (by simp) := by\n  simp_rw [antidiagonal_succ (n + 1), antidiagonal_succ', Finset.map_cons, map_map]\n  rfl\n#align finset.nat.antidiagonal_succ_succ' Finset.Nat.antidiagonal_succ_succ'\n\ntheorem map_swap_antidiagonal {n : ℕ} :\n    (antidiagonal n).map ⟨Prod.swap, Prod.swap_injective⟩ = antidiagonal n :=\n  eq_of_veq <| by simp [antidiagonal, Multiset.Nat.map_swap_antidiagonal]\n#align finset.nat.map_swap_antidiagonal Finset.Nat.map_swap_antidiagonal\n\n/-- A point in the antidiagonal is determined by its first co-ordinate. -/\ntheorem antidiagonal_congr {n : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)\n    (hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst := by\n  refine' ⟨congr_arg Prod.fst, fun h ↦ Prod.ext h ((add_right_inj q.fst).mp _)⟩\n  rw [mem_antidiagonal] at hp hq\n  rw [hq, ← h, hp]\n#align finset.nat.antidiagonal_congr Finset.Nat.antidiagonal_congr\n\ntheorem antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) : kl.1 ≤ n := by\n  rw [le_iff_exists_add]\n  use kl.2\n  rwa [mem_antidiagonal, eq_comm] at hlk\n#align finset.nat.antidiagonal.fst_le Finset.Nat.antidiagonal.fst_le\n\ntheorem antidiagonal.snd_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) : kl.2 ≤ n := by\n  rw [le_iff_exists_add]\n  use kl.1\n  rwa [mem_antidiagonal, eq_comm, add_comm] at hlk\n#align finset.nat.antidiagonal.snd_le Finset.Nat.antidiagonal.snd_le\n\ntheorem filter_fst_eq_antidiagonal (n m : ℕ) :\n    filter (fun x : ℕ × ℕ ↦ x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ := by\n  ext ⟨x, y⟩\n  simp only [mem_filter, Nat.mem_antidiagonal]\n  split_ifs with h\n  · simp (config := { contextual := true }) [and_comm, eq_tsub_iff_add_eq_of_le h, add_comm]\n  · rw [not_le] at h\n    simp only [not_mem_empty, iff_false_iff, not_and, decide_eq_true_eq]\n    exact fun hn => ne_of_lt (lt_of_le_of_lt (le_self_add.trans hn.le) h)\n#align finset.nat.filter_fst_eq_antidiagonal Finset.Nat.filter_fst_eq_antidiagonal\n\ntheorem filter_snd_eq_antidiagonal (n m : ℕ) :\n    filter (fun x : ℕ × ℕ ↦ x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ := by\n  have : (fun x : ℕ × ℕ ↦ (x.snd = m)) ∘ Prod.swap = fun x : ℕ × ℕ ↦ x.fst = m := by\n    ext ; simp\n  rw [← map_swap_antidiagonal]\n  simp [filter_map, this, filter_fst_eq_antidiagonal, apply_ite (Finset.map _)]\n#align finset.nat.filter_snd_eq_antidiagonal Finset.Nat.filter_snd_eq_antidiagonal\n\nsection EquivProd\n\n/-- The disjoint union of antidiagonals `Σ (n : ℕ), antidiagonal n` is equivalent to the product\n    `ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/\n@[simps]\ndef sigmaAntidiagonalEquivProd : (Σn : ℕ, antidiagonal n) ≃ ℕ × ℕ where\n  toFun x := x.2\n  invFun x := ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩\n  left_inv := by\n    rintro ⟨n, ⟨k, l⟩, h⟩\n    rw [mem_antidiagonal] at h\n    exact Sigma.subtype_ext h rfl\n  right_inv x := rfl\n#align finset.nat.sigma_antidiagonal_equiv_prod Finset.Nat.sigmaAntidiagonalEquivProd\n#align finset.nat.sigma_antidiagonal_equiv_prod_symm_apply_fst Finset.Nat.sigmaAntidiagonalEquivProd_symm_apply_fst\n#align finset.nat.sigma_antidiagonal_equiv_prod_symm_apply_snd_coe Finset.Nat.sigmaAntidiagonalEquivProd_symm_apply_snd_coe\n#align finset.nat.sigma_antidiagonal_equiv_prod_apply Finset.Nat.sigmaAntidiagonalEquivProd_apply\n\nend EquivProd\n\nend Nat\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/NatAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7551644712358596}}
{"text": "import Lean4Axiomatic.Function\nimport Lean4Axiomatic.Operators\n\n/-!\n# Equivalence relations\n\n## Fundamental definitions and properties\n-/\n\nnamespace Lean4Axiomatic\nnamespace Relation\n\n/--\nClass for\n[reflexive relations](https://en.wikipedia.org/wiki/Reflexive_relation).\n\nParaphrasing Wikipedia, a homogeneous binary relation `R` on a sort `α` is\n**reflexive** iff it relates every inhabitant of `α` to itself.\n\nThis property is provided by the single field `Reflexive.refl`; see its\ndocumentation for more details.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The homogeneous binary relation obeying the reflexive property.\n-/\nclass Reflexive {α : Sort u} (R : α → α → Prop) :=\n  /--\n  The reflexive property of a homogeneous binary relation `R` on a sort `α`.\n\n  Equality, or equivalence, are the archetypes of reflexive relations: if a\n  sort `α` has an equivalence relation (see `Eqv` and `EqvOp`), then any\n  inhabitant `x : α` is equivalent to itself (i.e., `x ≃ x`).\n\n  Another reflexive relation is _divisibility_, from number theory. We say an\n  integer `a` divides an integer `b` iff `b ≃ c * a` for some integer `c`. We\n  can show that all integers divide themselves by taking `c ≃ 1`.\n\n  An example of a relation that is _not_ reflexive is \"`n * m` is even\" for\n  natural numbers `n`, `m`. While \"`n * n` is even\" holds for even numbers `n`,\n  it fails for odd numbers and thus is not reflexive on the natural numbers.\n  Credit goes to Wikipedia for this example.\n\n  **Named parameters**\n  - See `Reflexive` for the parameters provided by the class.\n  - `x`: `R`'s first and second argument.\n  -/\n  refl : {x : α} → R x x\n\nexport Reflexive (refl)\n\n/--\nThe type of logical implication (i.e., the arrow type or exponential) is\nreflexive: there are inhabitants of the type `α → α` for all `α : Prop`.\n\n**Intuition**: The identity function (i.e, the function that simply returns its\nsingle argument) meets this requirement.\n-/\ninstance implication_reflexive : Reflexive (· → ·) := {\n  refl := id\n}\n\n/--\nClass for\n[symmetric relations](https://en.wikipedia.org/wiki/Symmetric_relation).\n\nA homogeneous binary relation `R` on a sort `α` is **symmetric** iff its truth\nvalue remains the same when its arguments are exchanged.\n\nThis property is provided by the single field `Symmetric.symm`; see its\ndocumentation for more details.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The homogeneous binary relation obeying the symmetric property.\n-/\nclass Symmetric {α : Sort u} (R : α → α → Prop) :=\n  /--\n  The symmetric property of a homogeneous binary relation `R` on a sort `α`.\n\n  Equality, or equivalence, are the archetypes of symmetric relations: if a\n  sort `α` has an equivalence relation (see `Eqv` and `EqvOp`), and for some\n  inhabitants `x y : α` we know that `x` is equivalent to `y` (i.e., `x ≃ y`),\n  then we also know that `y` is equivalent to `x` (i.e., `y ≃ x`).\n\n  Another example is actually the non-example from `Reflexive.refl`,\n  \"`n * m` is even\" for natural numbers `n` and `m`. In this case it's because\n  multiplication of natural numbers is commutative.\n\n  A relation that fails to be symmetric is \"X likes Y\" where X and Y are\n  people. While there are many specific Xs and Ys that like each other, this\n  unfortunately doesn't hold in general.\n\n  **Named parameters**\n  - See `Symmetric` for the parameters provided by the class.\n  - `x`, `y`: The arguments to `R`.\n  -/\n  symm : {x y : α} → R x y → R y x\n\nexport Symmetric (symm)\n\n/--\n`Symmetric` relations are special cases of `Fn.Swappable` functions.\n\n**Intuition**: Just going by syntax, a relation `R` that satisfies\n`Symmetric.symm` also satisfies `Fn.swap` as the swappable function `f`, with\nlogical implication (i.e., the function type or arrow type) as the relation\nbetween swapped invocations.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The symmetric relation.\n\n**Class parameters**\n- `Symmetric R`: Evidence that `R` is symmetric.\n-/\ninstance swappable_over_implication_from_symmetric\n    {α : Sort u} {R : α → α → Prop} [Symmetric R] : Fn.Swappable R (· → ·)\n    := {\n  swap := symm\n}\n\n/--\nThe negation of a symmetric relation is also symmetric.\n\n**Intuition**: Consider the set of all input pairs to the relation. It can be\ndivided into two disjoint subsets: the pairs that satisfy the relation, and\nthe pairs that don't. Both subsets must be closed under the operation of\nswapping the components of the pairs, otherwise the relation wouldn't be\nsymmetric.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The symmetric relation.\n\n**Class parameters**\n- `Symmetric R`: Evidence that `R` is symmetric.\n-/\ninstance negation_preserves_symmetry\n    {α : Sort u} {R : α → α → Prop} [Symmetric R] : Symmetric (¬ R · ·)\n    := {\n  symm := mt symm\n}\n\n/--\nConjunction (i.e. logical _and_) is symmetric.\n\n**Intuition**: The order of a conjunction's arguments doesn't affect its truth\nvalue.\n-/\ninstance and_symmetric : Symmetric (· ∧ ·) := by\n  apply Symmetric.mk\n  intro p q (And.intro (_ : p) (_ : q))\n  show q ∧ p\n  exact And.intro ‹q› ‹p›\n\n/--\nClass for\n[transitive relations](https://en.wikipedia.org/wiki/Transitive_relation).\n\nA homogeneous binary relation `R` on a sort `α` is **transitive** iff when `R`\nrelates `x` to `y`, and `y` to `z`, then it also relates `x` to `z`, for all\n`x`, `y`, and `z` inhabiting `α`. Transitive relations are useful because new\npairs of values can be shown to be related by chaining already known pairs\ntogether.\n\nThis property is provided by the single field `Transitive.trans`; see its\ndocumentation for more details.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The homogeneous binary relation obeying the transitive property.\n-/\nclass Transitive {α : Sort u} (R : α → α → Prop) :=\n  /--\n  The transitive property of a homogeneous binary relation `R` on a sort `α`.\n\n  Equality, or equivalence, are the archetypes of transitive relations: if a\n  sort `α` has an equivalence relation (see `Eqv` and `EqvOp`), and for some\n  inhabitants `x y z : α` we know that `x` is equivalent to `y` (i.e. `x ≃ y`)\n  and `y` is equivalent to `z` (i.e. `y ≃ z`), then we also know that `x` is\n  equivalent to `z` (i.e. `x ≃ z`).\n\n  Another transitive relation is _divisibility_, from number theory. We say an\n  integer `a` divides an integer `b` iff `b ≃ c * a` for some integer `c`. If\n  we know that `x` divides `y` (into, say, `p` copies of `x`), and `y` divides\n  `z` (into `q` copies of `y`), then `z` must consist of `p * q` copies of `x`,\n  and therefore `x` divides `z`.\n\n  A relation that fails to be transitive is \"X likes Y\" where X and Y are\n  people. If Alice likes Bob, and Bob likes Carol, then Alice might be a bit\n  jealous of Carol, and definitely not inclined to like her!\n\n  **Named parameters**\n  - See `Transitive` for the parameters provided by the class.\n  - `x`, `y`, `z`: The arguments to `R`.\n  -/\n  trans : {x y z : α} → R x y → R y z → R x z\n\nexport Transitive (trans)\n\n/--\n`Transitive` is a special case of the `Trans` class from Lean's Prelude.\n\n**Intuition**: The Prelude's `Trans` allows the three values involved in the\nproperty to be of different sorts. Which means it must support three\nheterogeneous relations to pair up the values. Our `Transitive` is the special\ncase where all values are of the same sort, and only one homogeneous relation\nis needed.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The transitive relation.\n\n**Class parameters**\n- `Transitive R`: Evidence that `R` is transitive.\n-/\ninstance prelude_trans_from_transitive\n    {α : Sort u} {R : α → α → Prop} [Transitive R] : Trans R R R\n    := {\n  trans := trans\n}\n\n/--\nLogical implication (i.e. the function type or the arrow type) is transitive.\n\n**Intuition**: This is essentially why implications are so useful in logic,\nbecause intermediate deductions can be combined into a larger, more significant\nresult. Alternatively, this is just function composition.\n-/\ntheorem implication_trans {p q r : Prop} : (p → q) → (q → r) → (p → r) :=\n  flip Function.comp\n\ninstance implication_transitive : Transitive (· → ·) := {\n  trans := implication_trans\n}\n\n/--\nLogical equivalence (i.e. the biconditional or \"if and only if\") is transitive.\n\n**Property intuition**: This relation holds when two propositions have the same\ntruth value, so we would expect it to be transitive.\n\n**Proof intuition**: Expand the definitions and use transitivity of implication\nin both directions to show the result.\n-/\ntheorem iff_trans {p q r : Prop} : (p ↔ q) → (q ↔ r) → (p ↔ r) := by\n  intro (_ : p ↔ q) (_ : q ↔ r)\n  show p ↔ r\n  apply Iff.intro\n  case mp =>\n    show p → r\n    exact implication_trans ‹p ↔ q›.mp ‹q ↔ r›.mp\n  case mpr =>\n    show r → p\n    exact implication_trans ‹q ↔ r›.mpr ‹p ↔ q›.mpr\n\ninstance iff_transitive : Transitive (· ↔ ·) := {\n  trans := iff_trans\n}\n\n/--\nTransitivity fails if the left operand's relation does not hold.\n\n**Property intuition**: This must be the case, otherwise transitivity would not\nbe a useful property.\n\n**Proof intuition**: Use transitivity on the right and output relations to\ncontradict the failed left relation.\n-/\ntheorem trans_failL\n    {α : Sort u} {R : α → α → Prop} [Symmetric R] [Transitive R] {x y z : α}\n    : ¬ R x y → R y z → ¬ R x z\n    := by\n  intro (_ : ¬ R x y) (_ : R y z) (_ : R x z)\n  show False\n  have : R x y := trans ‹R x z› (symm ‹R y z›)\n  exact ‹¬ R x y› ‹R x y›\n\n/--\nTransitivity fails if the right operand's relation does not hold.\n\n**Property intuition**: This must be the case, otherwise transitivity would not\nbe a useful property.\n\n**Proof intuition**: Use transitivity on the left and output relations to\ncontradict the failed right relation.\n-/\ntheorem trans_failR\n    {α : Sort u} {R : α → α → Prop} [Symmetric R] [Transitive R] {x y z : α}\n    : R x y → ¬ R y z → ¬ R x z\n    := by\n  intro (_ : R x y) (_ : ¬ R y z) (_ : R x z)\n  show False\n  have : R y z := trans (symm ‹R x y›) ‹R x z›\n  exact ‹¬ R y z› ‹R y z›\n\nnamespace Equivalence\n\n/--\nClass for\n[equivalence relations](https://en.wikipedia.org/wiki/Equivalence_relation).\n\nA homogeneous binary relation `R` on a sort `α` is an **equivalence relation**\niff it is reflexive, symmetric, and transitive.\n\nEquality is the simplest example of an equivalence relation, where each\ninhabitant of `α` is equivalent only to itself. A less trivial example is the\nrelation where two integers are equivalent iff they have the same sign.\n\n**Named parameters**\n- `α`: The `Sort` of `R`'s parameters.\n- `R`: The equivalence relation.\n-/\nclass Eqv {α : Sort u} (R : α → α → Prop)\n    extends Reflexive R, Symmetric R, Transitive R\n\n/--\nProvides an equivalence relation over `α` with the operator `· ≃ ·`.\n\n**Named parameters**\n- `α`: The `Sort` of the elements in the relation.\n-/\nclass EqvOp (α : Sort u) extends Operators.TildeDash α, Eqv tildeDash\n\n/--\nExtends `EqvOp` with `· ≃? ·`, a decision procedure for equivalence.\n\n**Named parameters**\n- `α`: The `Sort` of the elements in the relation.\n-/\nclass EqvOp? (α : Sort u)\n    extends EqvOp α, Operators.TildeDashQuestion tildeDash\n\nend Equivalence\nend Relation\n\nnamespace Rel\nexport Relation (refl symm trans trans_failL trans_failR)\nend Rel\n\nend Lean4Axiomatic\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/Relation/Equivalence/Core.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7551644709034203}}
{"text": "import game.sup_inf.infSumConst\n\nnamespace xena -- hide\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 8\n\nAgain a classical result.\n-/\n\n-- supremum of constant × set\ndef const_times_set (c: ℝ) (A : set ℝ) := { x : ℝ | ∃ y ∈ A, x = c * y }\n\n/- Lemma\nIf $A$ is a set of reals and $c > 0$, then\n$$ \\textrm{sup} (cA) = c \\cdot \\textrm{sup} (A)$$\n-/\nlemma sup_const_times_set (c : ℝ) (hc: 0 < c) (A : set ℝ) (h1A : A.nonempty)\n  (h2A : bdd_above A) (a : ℝ) : \n  (is_lub A a) → is_lub (const_times_set c A) (c * a) :=\nbegin\n  intro h,\n  cases h with hA1 hA2,\n  split,\n  { -- prove that (c*a) is an upper bound\n    intros x h0,\n    cases h0 with y h1, cases h1 with yA h2,\n    have H13A := hA1 y yA, rw h2, \n    exact (mul_le_mul_left hc).mpr H13A,\n  },\n  -- now prove that (c*a) is the least upper bound\n  intros S hS,\n  set y1 := S / c with hys,\n  have H : y1 ∈ upper_bounds A,\n    intros x hx,\n    have G := hA1 x hx, \n    set xc := c * x with hxc,\n    have G1 : xc ∈ const_times_set c A, \n        use x, existsi hx, exact hxc,\n    have G2 := hS xc G1, rw hxc at G2,  \n    rw hys, exact (le_div_iff' hc).mpr G2,\n  have F := hA2 y1 H, rw hys at F, \n  have E := (mul_le_mul_left hc).mpr F,\n  exact (le_div_iff' hc).mp F, 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/supProdConst.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037262250327, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7551528905473418}}
{"text": "import helpers\n\ndef in_cube {d : ℕ} (corner p : point d) : Prop :=\n  ∀ coord : fin d, vector.nth corner coord ≤ vector.nth p coord ∧\n                   vector.nth p coord < vector.nth corner coord + 1\n\n--Defines the cube (set of d dimensional points) corner + [0, 1)^d\ndef cube {d : ℕ} (corner : point d) : set (point d) :=\n  { p : point d | in_cube corner p }\n\nlemma cube_intersection_lemma_left_implication : \n  ∀ d : ℕ, ∀ corner1 : point d, ∀ corner2 : point d,\n  (cube corner1 ∩ cube corner2 = ∅) →\n  (∃ coord : fin d, vector.nth corner1 coord - vector.nth corner2 coord ≥ 1 ∨ \n                    vector.nth corner2 coord - vector.nth corner1 coord ≥ 1) :=\nbegin\n  intros _ _ _ h,\n  have cube1_not_in_cube2 : ∀ p : point d, p ∈ cube corner1 → p ∉ cube corner2 :=\n    begin\n      rw [cube, cube, set.inter_def] at h,\n      simp at h,\n      rw set.eq_empty_iff_forall_not_mem at h,\n      simp at h,\n      rw [cube, cube],\n      simp,\n      exact h,\n    end,\n  rw [cube, cube] at cube1_not_in_cube2,\n  simp at cube1_not_in_cube2,\n  conv at cube1_not_in_cube2\n  begin\n    find (in_cube corner1 _) { rw in_cube },\n    find (in_cube corner2 _) { rw in_cube },\n  end,\n  simp at cube1_not_in_cube2,\n  contrapose cube1_not_in_cube2,\n  rename cube1_not_in_cube2 no_far_coord,\n  simp,\n  simp at no_far_coord,\n  let get_first_intersecting_point : fin d → ℝ :=\n    λ coord : fin d, max (vector.nth corner1 coord) (vector.nth corner2 coord),\n  let p : point d := vector.of_fn get_first_intersecting_point,\n  use p,\n  split,\n  { intro coord,\n    split, simp only [vector.nth_of_fn, le_max_iff, le_refl, true_or],\n    simp only [vector.nth_of_fn, max_lt_iff, lt_add_iff_pos_right, zero_lt_one, true_and],\n    replace no_far_coord := no_far_coord coord,\n    contrapose no_far_coord,\n    rw not_not,\n    right,\n    linarith,\n  },\n  intro coord,\n  split, simp only [vector.nth_of_fn, le_max_iff, le_refl, or_true],\n  simp only [vector.nth_of_fn, max_lt_iff, lt_add_iff_pos_right, zero_lt_one, and_true],\n  replace no_far_coord := no_far_coord coord,\n  contrapose no_far_coord,\n  rw not_not,\n  left,\n  linarith,\nend\n\nlemma cube_intersection_lemma_right_implication :\n  ∀ d : ℕ, ∀ corner1 : point d, ∀ corner2 : point d,\n  (∃ coord : fin d, vector.nth corner1 coord - vector.nth corner2 coord ≥ 1 ∨ \n                    vector.nth corner2 coord - vector.nth corner1 coord ≥ 1\n  ) → (cube corner1 ∩ cube corner2 = ∅)\n  :=\nbegin\n  intros _ _ _ exists_far_coord,\n  cases exists_far_coord with x x_far_coord,\n  rw set.inter_def,\n  rw set.eq_empty_iff_forall_not_mem,\n  intro p,\n  simp,\n  rw [cube, cube],\n  simp,\n  rw [in_cube, in_cube],\n  simp,\n  intro p_in_cube1,\n  have p_in_cube1_x_coord := p_in_cube1 x,\n  use x,\n  intro corner2_le_p,\n  cases x_far_coord, linarith,\n  linarith,\nend\n\nlemma cube_intersection_lemma :\n  ∀ d : ℕ, ∀ corner1 : point d, ∀ corner2 : point d,\n  (∃ coord : fin d, vector.nth corner1 coord - vector.nth corner2 coord ≥ 1 ∨ \n                    vector.nth corner2 coord - vector.nth corner1 coord ≥ 1\n  ) ↔ (cube corner1 ∩ cube corner2 = ∅) :=\nbegin\n  repeat{intro},\n  split,\n  apply cube_intersection_lemma_right_implication,\n  apply cube_intersection_lemma_left_implication,\nend\n\n--States whether two d dimensional cubes (as defined by their corners) are distinct and share a face\ndef is_facesharing {d : ℕ} (c1 c2 : point d) : Prop :=\n  ∃ x : fin d, (vector.nth c1 x - vector.nth c2 x = 1 ∨\n                vector.nth c2 x - vector.nth c1 x = 1) ∧\n  ∀ y : fin d, x = y ∨ vector.nth c1 y = vector.nth c2 y\n\nlemma is_facesharing_comm {d : ℕ} {corner1 : point d} {corner2 : point d} (h : is_facesharing corner1 corner2) :\n  is_facesharing corner2 corner1 :=\nbegin\n  rw is_facesharing at h,\n  cases h with coord h,\n  cases h,\n  rw or_comm at h_left,\n  rw is_facesharing,\n  use coord,\n  split, exact h_left,\n  intro y,\n  replace h_right := h_right y,\n  cases h_right, {left, exact h_right,},\n  right,\n  symmetry,\n  exact h_right,\nend\n\n--States whether a tiling contains any two distinct corners whose cubes share a face\ndef tiling_faceshare_free {d : ℕ} (T : set (point d)) : Prop :=\n  ∀ c1 c2 ∈ T, ¬(is_facesharing c1 c2)\n\n--States whether a set of d dimensional cubes (as defined by their corners) is a tiling in ℝ^d\ndef is_tiling {d : ℕ} (T : set (point d)) : Prop := \n  ∀ p : point d, ∃ corner ∈ T, p ∈ cube corner ∧ \n  (∀ alt_corner ∈ T, p ∈ cube alt_corner → alt_corner = corner)\n\n/-\nTakes a point p and a tiling T and returns the unique corner in T such that p\nis in the cube defined by that corner. This function, when given an int_point x,\nis denoted t(x) ∈ T in Brakensiek et al.'s paper\n\nAlso want to return a proof that the result is the unique corner in T such that\np is in the cube defined by that corner. For this, rather than simply return a point d,\nI return a subtype of point d that for which all elements have exactly the desired property\n(i.e. the only element of the type is the corner corresponding to the given point)\n-/\nnoncomputable def point_to_corner {d : ℕ} {T : set (point d)} (h : is_tiling T) (p : point d) :\n  { corner : point d // \n      corner ∈ T ∧ p ∈ cube corner ∧\n      (∀ alt_corner ∈ T, p ∈ cube alt_corner → alt_corner = corner)\n  } :=\nbegin\n  rw is_tiling at h,\n  have h' := h p,\n  let corner := classical.some h',\n  have h' := classical.some_spec h',\n  change \n    ∃ (H : corner ∈ T), p ∈ cube corner ∧ \n    (∀ (alt_corner : point d), alt_corner ∈ T → p ∈ cube alt_corner → alt_corner = corner)\n    at h',\n  rename h'_1 h'',\n  simp at h'',\n  cases h'' with res_in_T h'',\n  use corner,\n  have goal : \n    corner ∈ T ∧ p ∈ cube corner ∧\n    (∀ alt_corner ∈ T, p ∈ cube alt_corner → alt_corner = corner),\n  split, exact res_in_T,\n  { cases h'',\n    split, exact h''_left,\n    exact h''_right,\n  },\n  exact goal,\nend\n\nnoncomputable def int_point_to_corner {d : ℕ} {T : set (point d)} (h : is_tiling T) (x : int_point d) :\n  { corner : point d // \n      corner ∈ T ∧ int_point_to_point x ∈ cube corner ∧\n      (∀ alt_corner ∈ T, int_point_to_point x ∈ cube alt_corner → alt_corner = corner)\n  } := point_to_corner h (int_point_to_point x)\n\n--Return type of try_point_to_corner\ninductive try_point_to_corner_res {d : ℕ} (T : set (point d)) (p : point d)\n  | no_corner : (∀ t ∈ T, p ∉ cube t) → try_point_to_corner_res\n  | unique_corner : \n      { corner : point d // \n          corner ∈ T ∧ p ∈ cube corner ∧\n          (∀ alt_corner ∈ T, p ∈ cube alt_corner → alt_corner = corner)\n      } → try_point_to_corner_res\n  | multiple_corners :\n      { corners : point d × point d // \n          prod.fst corners ∈ T ∧ p ∈ cube (prod.fst corners) ∧\n          prod.snd corners ∈ T ∧ p ∈ cube (prod.snd corners) ∧\n          prod.fst corners ≠ prod.snd corners\n      } → try_point_to_corner_res\n\n/-\nThis function takes a set of cube corners T and an arbitrary point p, and tries to return a unique\ncube corner in T that contains p. Unlike point_to_corner, this function does not require that T\nis a tiling.\n\nWhen we try to get the corner of a point p in a set of cube corners T, we can either find that there\nis no corner in T that contains p, exactly one corner in T that contains p, or multiple corners in T\nthat contain p. In the first case, we return a proof that no corner in T contains p. In the second case,\nwe return the unique corner in T that contains p, and through the type assert that no other corner in T\ncontains p. In the final case, we find two distinct corners in T that contain p, and return them while\nasserting through the type that the two corners are distinct, both in T, and both contain p.\n-/\nnoncomputable def try_point_to_corner {d : ℕ} (T : set (point d)) (p : point d) : \n  try_point_to_corner_res T p :=\n  begin\n    let corners_containing_p_in_T := { corner ∈ T | p ∈ cube corner },\n    by_cases corners_containing_p_in_T = ∅,\n    { have goal : ∀ t ∈ T, p ∉ cube t :=\n        begin\n          intros _ t_in_T,\n          change {corner ∈ T | p ∈ cube corner} = ∅ at h,\n          have h' : ∀ corner ∈ T, p ∉ cube corner :=\n            begin\n              have empty_h := set.eq_empty_iff_forall_not_mem,\n              cases empty_h with empty_h rev_empty_h,\n              replace h := empty_h h,\n              simp at h,\n              exact h,\n            end,\n          exact h' t t_in_T,\n        end,\n      exact try_point_to_corner_res.no_corner goal,\n    },\n    by_cases multiple_corners_contain_p : ∃ corner1 ∈ T, ∃ corner2 ∈ T, \n      corner1 ∈ T ∧ corner2 ∈ T ∧ p ∈ cube corner1 ∧ p ∈ cube corner2 ∧ corner1 ≠ corner2,\n    { let corner1 := classical.some multiple_corners_contain_p,\n      have multiple_corners_contain_p_2 := classical.some_spec multiple_corners_contain_p,\n      change ∃ (H : corner1 ∈ T) (corner2 : point d) (H : corner2 ∈ T), \n        corner1 ∈ T ∧ corner2 ∈ T ∧ p ∈ cube corner1 ∧ p ∈ cube corner2 ∧ corner1 ≠ corner2\n        at multiple_corners_contain_p_2,\n      let corner1_in_T := classical.some multiple_corners_contain_p_2,\n      have multiple_corners_contain_p_3 := classical.some_spec multiple_corners_contain_p_2,\n      let corner2 := classical.some multiple_corners_contain_p_3,\n      have multiple_corners_contain_p_4 := classical.some_spec multiple_corners_contain_p_3,\n      change ∃ (H : corner2 ∈ T),\n        corner1 ∈ T ∧ corner2 ∈ T ∧ p ∈ cube corner1 ∧ p ∈ cube corner2 ∧ corner1 ≠ corner2\n        at multiple_corners_contain_p_4,\n      let corner2_in_T := classical.some multiple_corners_contain_p_4,\n      have multiple_corners_contain_p_5 := classical.some_spec multiple_corners_contain_p_4,\n      let corners : point d × point d := ⟨corner1, corner2⟩,\n      have goal : \n        prod.fst corners ∈ T ∧ p ∈ cube (prod.fst corners) ∧\n        prod.snd corners ∈ T ∧ p ∈ cube (prod.snd corners) ∧\n        prod.fst corners ≠ prod.snd corners :=\n        begin\n          cases multiple_corners_contain_p_5 with corner1_in_T multiple_corners_contain_p_5,\n          cases multiple_corners_contain_p_5 with corner2_in_T multiple_corners_contain_p_5,\n          cases multiple_corners_contain_p_5 with p_in_cube_corner1 multiple_corners_contain_p_5,\n          cases multiple_corners_contain_p_5 with p_in_cube_corner2 corner1_neq_corner2,\n          split, simp, exact corner1_in_T,\n          split, simp, exact p_in_cube_corner1,\n          split, simp, exact corner2_in_T,\n          split, simp, exact p_in_cube_corner2,\n          exact corner1_neq_corner2,\n        end,\n      let corners' : \n        { corners : point d × point d // \n            prod.fst corners ∈ T ∧ p ∈ cube (prod.fst corners) ∧\n            prod.snd corners ∈ T ∧ p ∈ cube (prod.snd corners) ∧\n            prod.fst corners ≠ prod.snd corners\n        } := ⟨corners, goal⟩,\n      exact try_point_to_corner_res.multiple_corners corners',\n    },\n    rename multiple_corners_contain_p unique_corner_contains_p,\n    simp at unique_corner_contains_p,\n    change ∀ (t1 : point d), t1 ∈ T → ∀ (t2 : point d), t2 ∈ T → t1 ∈ T → t2 ∈ T → \n      p ∈ cube t1 → p ∈ cube t2 → t1 = t2 at unique_corner_contains_p,\n    change corners_containing_p_in_T ≠ ∅ at h,\n    rw [set.ne_empty_iff_nonempty, set.nonempty_def] at h,\n    let corner_with_p := classical.some h,\n    have h' := classical.some_spec h,\n    change corner_with_p ∈ corners_containing_p_in_T at h',\n    have goal : \n      corner_with_p ∈ T ∧ p ∈ cube corner_with_p ∧\n      (∀ alt_corner ∈ T, p ∈ cube alt_corner → alt_corner = corner_with_p) :=\n      begin\n        change corner_with_p ∈ {corner ∈ T | p ∈ cube corner} at h',\n        simp at h',\n        cases h' with corner_with_p_in_T p_in_cube_corner_with_p,\n        split, exact corner_with_p_in_T,\n        split, exact p_in_cube_corner_with_p, \n        intros _ alt_corner_in_T p_in_alt_corner,\n        symmetry,\n        exact unique_corner_contains_p corner_with_p corner_with_p_in_T alt_corner alt_corner_in_T \n          corner_with_p_in_T alt_corner_in_T p_in_cube_corner_with_p p_in_alt_corner,\n      end,\n    let corner_with_p' : \n      { corner : point d // \n          corner ∈ T ∧ p ∈ cube corner ∧\n          (∀ alt_corner ∈ T, p ∈ cube alt_corner → alt_corner = corner)\n      } := ⟨corner_with_p, goal⟩,\n    exact try_point_to_corner_res.unique_corner corner_with_p',\n  end", "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/src/cube_tilings.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037282594921, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7551528901267742}}
{"text": "-- import the definitions of uniform space via entourages\nimport uniform_structure.entourages\n\n\n\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 collection of entourages for X \n\n-- This is a question about pseudometrics so let's put it\n-- in the pseudometric namespace\nopen_locale classical\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 → X → ℝ) [is_pseudometric d]\n\n-- Define U ⊆ X × X to be an entourage if there exists ε > 0 such\n-- that d(x,y)≤ε → (x,y) ∈ U\n\ndef entourages :=\n  {U : set (X × X) | ∃ ε > 0, ∀ x y : X, d x y ≤ ε → (x,y) ∈ U}\n\n-- this lemma is true by definition\nlemma mem_entourages (U : set (X × X)) :\n  U ∈ entourages d ↔ ∃ ε > 0, ∀ x y : X, d x y ≤ ε → (x,y) ∈ U := iff.rfl \n\n-- The exerise is to show that the 5 axioms of a uniform space are\n-- satisfied.\n\n-- Hint: You can `rw mem_entourages` to change from `U ∈ entourages d` to the\n-- explicit epsilon definition.\n\n-- Hint: if `hU : U ∈ entourages d` then `obtain ⟨ε, hε, hεU⟩ := hU` will\n-- get you the ε which is a witness to U being an entourage for d.\n\n-- Axiom 1: the diagonal is in U\nlemma refl (U : set (X × X)) (hU : U ∈ entourages d) :\n  ∀ (x : X), (x, x) ∈ U :=\nbegin\n  intro x,\n  have hx : d x x = 0,\n    exact d_self d x,\n  obtain ⟨ε, hε, hεU⟩ := hU,\n  apply hεU,\n  rw hx,\n  linarith,\n  \n  \nend\n\n-- Axiom 2: anything bigger than an entourage is an entourage\nlemma bigger (U V : set (X × X)) (hU : U ∈ entourages d) (hUV : U ⊆ V) :\n  V ∈ entourages d :=\nbegin\n  rw mem_entourages,\n  obtain ⟨ε, hε, hεU⟩ := hU,\n  use ε,\n  split,\n  apply hε,\n  tauto,\n\nend\n\n-- Axiom 3: Intersection of two entourages is an entourage\nlemma inter (U V : set (X × X)) (hU : U ∈ entourages d) (hV : V ∈ entourages d) :\n  U ∩ V ∈ entourages d :=\nbegin\n  rw mem_entourages,\n  obtain ⟨ε1, hε1, hε1U⟩ := hU,\n  obtain ⟨ε2, hε2, hε2V⟩ := hV,\n  set e := min ε1 ε2 with he,\n  use e,\n  split,\n  have h: e>0,\n  simp,\n  split,\n  apply hε1,\n  apply hε2,\n  simp,\n  split,\n  apply hε1,\n  apply hε2,\n  simp,\n  tauto,\n\nend\n\n/-\n\n-/\n-- Axiom 4: the \"square root\" axiom. \n-- You'll need `mem_comp_ent` here (defined in the entourages file)\nlemma comp (U : set (X × X)) (hU : U ∈ entourages d) :\n ∃ (V : set (X × X)) (H : V ∈ entourages d), V ∘ V ⊆ U :=\nbegin\n  obtain ⟨ε, hε, hεU⟩ := hU,\n  use {z : X × X | d z.1 z.2 ≤ ε/2},\n  split,\n  rw mem_entourages,\n  use ε/2,\n  split,\n  linarith,\n  tauto,\n  intro x,\n  intro h,\n  have q: d x.1 x.2 ≤ ε,\n  have s: ∃ z, (x.1, z) ∈ {z : X × X | d z.1 z.2 ≤ ε/2} ∧ (z, x.2) ∈ {z : X × X | d z.1 z.2 ≤ ε/2},\n  rw ← mem_comp_ent,\n  apply h,\n  obtain ⟨z, hz1, hz2⟩ := s,\n  have p1: d x.1 z ≤ ε/2,\n  apply hz1,\n  have p2: d z x.2 ≤ ε/2,\n  apply hz2,\n  have p3 : d x.1 x.2 ≤ d x.1 z + d z x.2,\n  apply d_triangle d,\n  linarith,\n  have p4: (x.1, x.2) ∈ U,\n  apply hεU,\n  apply q,\n  cases x,\n  apply p4,\nend\n\n-- Axiom 5: the \"transpose\" axiom.\nlemma symm (U : set (X × X)) (hU : U ∈ entourages d) :\n  {z : X × X | (z.snd, z.fst) ∈ U} ∈ entourages d :=\nbegin\n  rw mem_entourages,\n  obtain ⟨ε, hε, hεU⟩ := hU,\n  use ε,\n  split,\n  apply hε,\n  intros x y,\n  have hx : d x y = d y x,\n    exact d_comm d x y,\n  intro h,\n  apply hεU,\n  have q:  d x y = d (x, y).snd (x, y).fst,\n    apply hx,\n  linarith,\nend\n \ndefinition to_entourages : uniform_space_entourage X :=\n{ entourages := entourages d,\n  refl := refl d,\n  bigger := bigger d,\n  inter := inter d,\n  comp := comp d,\n  symm := symm d }\n\nend pseudometric\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/solutions/entourages_from_pseudometric.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7551084435260167}}
{"text": "------------------------------------------------------------------------\n-- Teoría elemental de conjuntos\n------------------------------------------------------------------------\n\nimport tactic\n\nvariables (Ω : Type)\nvariables (X Y Z W : set Ω)\nvariables (a b c x y z : Ω)\n\n------------------------------------------------------------------------\n-- § Subconjuntos                                                     --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Demostrar que\n--    X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y :=\nbegin\n  refl,\nend\n\n-- 2ª demostración\nexample :\n  X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y :=\nby refl\n\n-- 3ª demostración\nexample :\n  X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y :=\n-- by suggest\niff.rfl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Demostrar que\n--    X ⊆ X\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ⊆ X :=\nbegin\n  rw set.subset_def,\n  intros a ha,\n  exact ha,\nend\n\n-- 2ª demostración\nexample :\n  X ⊆ X :=\nbegin\n  intros a ha,\n  exact ha,\nend\n\n-- 3ª demostración\nexample :\n  X ⊆ X :=\nby exact λ a ha, ha\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Demostrar que\n--      X ⊆ Y, Y ⊆ Z ⊢ X ⊆ Z\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hXY : X ⊆ Y)\n  (hYZ : Y ⊆ Z)\n  : X ⊆ Z :=\nbegin\n  rw set.subset_def at *,\n  intros a ha,\n  apply hYZ,\n  apply hXY,\n  exact ha,\nend\n\n-- 2ª demostración\nexample\n  (hXY : X ⊆ Y)\n  (hYZ : Y ⊆ Z)\n  : X ⊆ Z :=\nbegin\n  intros a ha,\n  apply hYZ,\n  apply hXY,\n  exact ha,\nend\n\n-- 3ª demostración\nexample\n  (hXY : X ⊆ Y)\n  (hYZ : Y ⊆ Z)\n  : X ⊆ Z :=\nbegin\n  intros a ha,\n  apply hYZ (hXY ha),\nend\n\n-- 4ª demostración\nexample\n  (hXY : X ⊆ Y)\n  (hYZ : Y ⊆ Z)\n  : X ⊆ Z :=\nλ a ha, hYZ (hXY ha)\n\n------------------------------------------------------------------------\n-- § Igualdad de conjuntos                                            --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Demostrar que\n--    X = Y ↔ (∀ a, a ∈ X ↔ a ∈ Y)\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X = Y ↔ (∀ a, a ∈ X ↔ a ∈ Y) :=\nbegin\n  exact set.ext_iff\nend\n\n-- 2ª demostración\nexample :\n  X = Y ↔ (∀ a, a ∈ X ↔ a ∈ Y) :=\nset.ext_iff\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Demostrar que\n--      X ⊆ Y, Y ⊆ X ⊢ X = Y\n-- ----------------------------------------------------------------------\n\nexample\n  (hXY : X ⊆ Y)\n  (hYX : Y ⊆ X)\n  : X = Y :=\nbegin\n  ext a,\n  split,\n  { apply hXY },\n  { apply hYX },\nend\n\n------------------------------------------------------------------------\n-- § Uniones e intersecciones                                         --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Demostrar que\n--    a ∈ X ∪ Y ↔ a ∈ X ∨ a ∈ Y\n-- ----------------------------------------------------------------------\n\nexample :\n  a ∈ X ∪ Y ↔ a ∈ X ∨ a ∈ Y :=\nby refl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Demostrar que\n--    a ∈ X ∩ Y ↔ a ∈ X ∧ a ∈ Y\n-- ----------------------------------------------------------------------\n\nexample :\n  a ∈ X ∩ Y ↔ a ∈ X ∧ a ∈ Y :=\nby refl\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 8. Demostrar que\n--    X ∪ X = X\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ∪ X = X :=\nbegin\n  ext a,\n  rw set.mem_union,\n  split,\n  { intro h,\n    cases h with ha ha;\n    exact ha },\n  { intro ha,\n    left,\n    exact ha }\nend\n\n-- 2ª demostración\nexample :\n  X ∪ X = X :=\nbegin\n  ext a,\n  split,\n  { intro h,\n    dsimp at h,\n    tauto, },\n  { intro ha,\n    dsimp,\n    tauto, }\nend\n\n-- 3ª demostración\nexample :\n  X ∪ X = X :=\nbegin\n  ext a,\n  dsimp;\n  tauto,\nend\n\n-- 4ª demostración\nexample :\n  X ∪ X = X :=\nset.union_self X\n\n-- 5ª demostración\nexample :\n  X ∪ X = X :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 9. Demostrar que\n--    X ⊆ X ∪ Y\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ⊆ X ∪ Y :=\nbegin\n  rw set.subset_def,\n  intros a haX,\n  rw set.mem_union,\n  left,\n  assumption,\nend\n\n-- 2ª demostración\nexample :\n  X ⊆ X ∪ Y :=\nbegin\n  intros a haX,\n  apply or.inl,\n  exact haX,\nend\n\n-- 3ª demostración\nexample :\n  X ⊆ X ∪ Y :=\nbegin\n  intros a haX,\n  exact or.inl haX,\nend\n\n-- 4ª demostración\nexample :\n  X ⊆ X ∪ Y :=\nset.subset_union_left X Y\n\n-- 5ª demostración\nexample :\n  X ⊆ X ∪ Y :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 10. Demostrar que\n--    Y ⊆ X ∪ Y\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  Y ⊆ X ∪ Y :=\nbegin\n  intros a haY,\n  right,\n  assumption,\nend\n\n-- 2ª demostración\nexample :\n  Y ⊆ X ∪ Y :=\nbegin\n  intros a haY,\n  exact or.inr haY,\nend\n\n-- 3ª demostración\nexample :\n  Y ⊆ X ∪ Y :=\n-- by library_search\nset.subset_union_right X Y\n\n-- 4ª demostración\nexample :\n  Y ⊆ X ∪ Y :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 11. Demostrar que\n--    X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nbegin\n  split,\n  { intro h,\n    split,\n    { intros a haX,\n      apply h,\n      left,\n      assumption },\n    { intros a haY,\n      apply h,\n      right,\n      assumption }},\n  { rintros ⟨hXZ, hYZ⟩ a (haX | haY),\n    { exact hXZ haX },\n    { exact hYZ haY } }\nend\n\n-- 2ª demostración\nexample :\n  X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nbegin\n  split,\n  { intro h,\n    split,\n    { intros a haX,\n      exact h (or.inl haX), },\n    { intros a haY,\n      exact h (or.inr haY)}},\n  { rintros ⟨hXZ, hYZ⟩ a (haX | haY),\n    { exact hXZ haX },\n    { exact hYZ haY } }\nend\n\n-- 3ª demostración\nexample :\n  X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nbegin\n  split,\n  { intro h,\n    split,\n    { exact λ a haX, h (or.inl haX), },\n    { exact λ a haY, h (or.inr haY)}},\n  { rintros ⟨hXZ, hYZ⟩ a (haX | haY),\n    { exact hXZ haX },\n    { exact hYZ haY } }\nend\n\n-- 3ª demostración\nexample :\n  X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nby finish [iff_def, set.subset_def]\n\n-- 4ª demostración\nexample :\n  X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\n-- by library_search\nset.union_subset_iff\n\n-- 5ª demostración\nexample :\n  X ∪ Y ⊆ Z ↔ X ⊆ Z ∧ Y ⊆ Z :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 12. Demostrar que\n--    W ⊆ X, Y ⊆ Z ⊢ W ∪ Y ⊆ X ∪ Z\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hWX : W ⊆ X)\n  (hYZ : Y ⊆ Z)\n  : W ∪ Y ⊆ X ∪ Z :=\nbegin\n  rintros a (haW | haY),\n  { left,\n    exact hWX haW },\n  { right,\n    exact hYZ haY }\nend\n\n-- 2ª demostración\nexample\n  (hWX : W ⊆ X)\n  (hYZ : Y ⊆ Z)\n  : W ∪ Y ⊆ X ∪ Z :=\nbegin\n  rintros a (haW | haY),\n  { exact or.inl (hWX haW), },\n  { exact or.inr (hYZ haY), }\nend\n\n-- 3ª demostración\nexample\n  (hWX : W ⊆ X)\n  (hYZ : Y ⊆ Z)\n  : W ∪ Y ⊆ X ∪ Z :=\nby finish [set.subset_def]\n\n-- 4ª demostración\nexample\n  (hWX : W ⊆ X)\n  (hYZ : Y ⊆ Z)\n  : W ∪ Y ⊆ X ∪ Z :=\n-- by library_search\nset.union_subset_union hWX hYZ\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 13. Demostrar que\n--    X ⊆ Y ⊢ X ∪ Z ⊆ Y ∪ Z\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample\n  (hXY : X ⊆ Y)\n  : X ∪ Z ⊆ Y ∪ Z :=\nbegin\n  rintros a (haX | haZ),\n  { left,\n    exact hXY haX },\n  { right,\n    exact haZ, }\nend\n\n-- 2ª demostración\nexample\n  (hXY : X ⊆ Y)\n  : X ∪ Z ⊆ Y ∪ Z :=\nbegin\n  rintros a (haX | haZ),\n  { exact or.inl (hXY haX), },\n  { exact or.inr haZ, }\nend\n\n-- 3ª demostración\nexample\n  (hXY : X ⊆ Y)\n  : X ∪ Z ⊆ Y ∪ Z :=\nby finish [set.subset_def]\n\n-- 4ª demostración\nexample\n  (hXY : X ⊆ Y)\n  : X ∪ Z ⊆ Y ∪ Z :=\n-- by library_search\nset.union_subset_union_left Z hXY\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 14. Demostrar que\n--    X ∩ Y ⊆ X\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ∩ Y ⊆ X :=\nbegin\n  rintro a ⟨haX, haY⟩,\n  assumption,\nend\n\n-- 2ª demostración\nexample :\n  X ∩ Y ⊆ X :=\nbegin\n  rintro a ⟨haX, -⟩,\n  exact haX,\nend\n\n-- 3ª demostración\nexample :\n  X ∩ Y ⊆ X :=\n-- by library_search\nset.inter_subset_left X Y\n\n-- 4ª demostración\nexample :\n  X ∩ Y ⊆ X :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 15. Demostrar que\n--    X ∩ X = X\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ∩ X = X :=\nbegin\n  ext a,\n  split,\n  { rintro ⟨haX, -⟩,\n    exact haX, },\n  { intro haX,\n    exact ⟨haX, haX⟩ }\nend\n\n-- 2ª demostración\nexample :\n  X ∩ X = X :=\nset.ext (assume x, and_self _)\n\n-- 3ª demostración\nexample :\n  X ∩ X = X :=\n-- by library_search\nset.inter_self X\n\n-- 4ª demostración\nexample :\n  X ∩ X = X :=\nby simp\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 16. Demostrar que\n--    X ∩ Y = Y ∩ X\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ∩ Y = Y ∩ X :=\nbegin\n  ext a,\n  split,\n  { rintro ⟨haX, haY⟩,\n    exact ⟨haY, haX⟩ },\n  { rintro ⟨haY, haX⟩,\n    exact ⟨haX, haY⟩ }\nend\n\n-- 2ª demostración\nexample :\n  X ∩ Y = Y ∩ X :=\nbegin\n  ext a,\n  split;\n  { rintro ⟨h1, h2⟩,\n    exact ⟨h2, h1⟩ }\nend\n\n-- 2ª demostración\nexample :\n  X ∩ Y = Y ∩ X :=\nbegin\n  ext a,\n  exact and.comm,\nend\n\n-- 3ª demostración\nexample :\n  X ∩ Y = Y ∩ X :=\nset.ext (λ x, and.comm)\n\n-- 4ª demostración\nexample :\n  X ∩ Y = Y ∩ X :=\n-- by library_search\nset.inter_comm X Y\n\n-- 5ª demostración\nexample :\n  X ∩ Y = Y ∩ X :=\n-- by hint\nby finish\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 17. Demostrar que\n--    X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z :=\nbegin\n  ext a,\n  split,\n  { rintro ⟨hx, hy, hz⟩,\n    exact ⟨⟨hx, hy⟩, hz⟩ },\n  { rintro ⟨⟨hx, hy⟩, hz⟩,\n    exact ⟨hx, hy, hz⟩ },\nend\n\n-- 2ª demostración\nexample :\n  X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z :=\nbegin\n  ext a,\n  dsimp,\n  exact and.assoc.symm,\nend\n\n-- 3ª demostración\nexample :\n  X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z :=\nset.ext (λ x, and.assoc.symm)\n\n-- 4ª demostración\nexample :\n  X ∩ (Y ∩ Z) = (X ∩ Y) ∩ Z :=\n-- by library_search\n(set.inter_assoc X Y Z).symm\n\n------------------------------------------------------------------------\n-- § Cuantificadores                                                  --\n------------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 18. Demostrar que\n--    ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X)\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X) :=\nbegin\n  split,\n  { intros h b hb,\n    apply h,\n    use b,\n    exact hb, },\n  { rintro h ⟨a, ha⟩,\n    exact (h a) ha, },\nend\n\n-- 2ª demostración\nexample :\n  ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X) :=\nbegin\n  push_neg,\n  simp,\nend\n\n-- 3ª demostración\nexample :\n  ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X) :=\nby {push_neg, simp}\n\n-- 3ª demostración\nexample :\n  ¬ (∃ a, a ∈ X) ↔ ∀ b, ¬ (b ∈ X) :=\n-- by library_search\nnot_exists\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 19. Demostrar que\n--    ¬ (∀ a, a ∈ X) ↔ ∃ b, ¬ (b ∈ X)\n-- ----------------------------------------------------------------------\n\n-- 1ª demostración\nexample :\n  ¬ (∀ a, a ∈ X) ↔ ∃ b, ¬ (b ∈ X) :=\nbegin\n  split,\n  { intro h,\n    by_contra hnX,\n    apply h,\n    intro a,\n    by_contra hXa,\n    apply hnX,\n    use a, },\n  { intro h,\n    cases h with b hb,\n    intro h,\n    apply hb,\n    apply h }\nend\n\n-- 2ª demostración\nexample :\n  ¬ (∀ a, a ∈ X) ↔ ∃ b, ¬ (b ∈ X) :=\n-- by library_search\nnot_forall\n\n-- 3ª demostración\nexample :\n  ¬ (∀ a, a ∈ X) ↔ ∃ b, ¬ (b ∈ X) :=\nby simp\n\n-- =====================================================================\n-- § Referencias                                                      --\n-- =====================================================================\n\n-- + Kevin Buzzard. \"Formalising mathematics : workshop 1 — logic, sets,\n--   functions, relations\" https://bit.ly/3kJo231\n-- + Kevin Buzzard. formalising-mathematics: Part_B_sets.lean\n--   https://bit.ly/2Wiv1Xe\n-- + Kevin Buzzard. formalising-mathematics: Part_B_sets_solutions.lean\n--   https://bit.ly/3zQyv0Y\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/2_Conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7551084387907037}}
{"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 group_theory.submonoid.operations\nimport group_theory.subsemigroup.center\n\n/-!\n# Centers of monoids\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* `submonoid.center`: the center of a monoid\n* `add_submonoid.center`: the center of an additive monoid\n\nWe provide `subgroup.center`, `add_subgroup.center`, `subsemiring.center`, and `subring.center` in\nother files.\n-/\n\nnamespace submonoid\nsection\nvariables (M : Type*) [monoid M]\n\n/-- The center of a monoid `M` is the set of elements that commute with everything in `M` -/\n@[to_additive \"The center of a monoid `M` is the set of elements that commute with everything in\n`M`\"]\ndef center : submonoid M :=\n{ carrier := set.center M,\n  one_mem' := set.one_mem_center M,\n  mul_mem' := λ a b, set.mul_mem_center }\n\n@[to_additive] lemma coe_center : ↑(center M) = set.center M := rfl\n\n@[simp]\nlemma center_to_subsemigroup : (center M).to_subsemigroup = subsemigroup.center M := rfl\n\nlemma _root_.add_submonoid.center_to_add_subsemigroup (M) [add_monoid M] :\n  (add_submonoid.center M).to_add_subsemigroup = add_subsemigroup.center M := rfl\n\nattribute [to_additive add_submonoid.center_to_add_subsemigroup] submonoid.center_to_subsemigroup\n\nvariables {M}\n\n@[to_additive] lemma mem_center_iff {z : M} : z ∈ center M ↔ ∀ g, g * z = z * g := iff.rfl\n\n@[to_additive] instance decidable_mem_center (a) [decidable $ ∀ b : M, b * a = a * b] :\n  decidable (a ∈ center M) :=\ndecidable_of_iff' _ mem_center_iff\n\n/-- The center of a monoid is commutative. -/\ninstance : comm_monoid (center M) :=\n{ mul_comm := λ a b, subtype.ext $ b.prop _,\n  .. (center M).to_monoid }\n\n/-- The center of a monoid acts commutatively on that monoid. -/\ninstance center.smul_comm_class_left : smul_comm_class (center M) M M :=\n{ smul_comm := λ m x y, (commute.left_comm (m.prop x) y).symm }\n\n/-- The center of a monoid acts commutatively on that monoid. -/\ninstance center.smul_comm_class_right : smul_comm_class M (center M) M :=\nsmul_comm_class.symm _ _ _\n\n/-! Note that `smul_comm_class (center M) (center M) M` is already implied by\n`submonoid.smul_comm_class_right` -/\nexample : smul_comm_class (center M) (center M) M := by apply_instance\n\nend\n\nsection\nvariables (M : Type*) [comm_monoid M]\n\n@[simp] lemma center_eq_top : center M = ⊤ :=\nset_like.coe_injective (set.center_eq_univ M)\n\nend\n\nend submonoid\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/submonoid/center.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7550227778459017}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov\n\n! This file was ported from Lean 3 source module linear_algebra.quotient\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.QuotientGroup\nimport Mathlib.LinearAlgebra.Span\n\n/-!\n# Quotients by submodules\n\n* If `p` is a submodule of `M`, `M ⧸ 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\nsection deinstance_nonassocring\n-- porting note: because we're missing lean4#2074 we need this, see:\n-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/LinearAlgebra.2ESpan.20!4.232248\nattribute [-instance] Ring.toNonAssocRing\n\n-- For most of this file we work over a noncommutative ring\nsection Ring\n\nnamespace Submodule\n\nvariable {R M : Type _} {r : R} {x y : M} [Ring R] [AddCommGroup M] [Module R M]\n\nvariable (p p' : Submodule R M)\n\nopen LinearMap QuotientAddGroup\n\n/-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `-x + y ∈ p`.\n\nNote this is equivalent to `y - x ∈ p`, but defined this way to be be defeq to the `add_subgroup`\nversion, where commutativity can't be assumed. -/\ndef quotientRel : Setoid M :=\n  QuotientAddGroup.leftRel p.toAddSubgroup\n#align submodule.quotient_rel Submodule.quotientRel\n\ntheorem quotientRel_r_def {x y : M} : @Setoid.r _ p.quotientRel x y ↔ x - y ∈ p :=\n  Iff.trans\n    (by\n      rw [leftRel_apply, sub_eq_add_neg, neg_add, neg_neg]\n      rfl)\n    neg_mem_iff\n#align submodule.quotient_rel_r_def Submodule.quotientRel_r_def\n\n/-- The quotient of a module `M` by a submodule `p ⊆ M`. -/\ninstance hasQuotient : HasQuotient M (Submodule R M) :=\n  ⟨fun p => Quotient (quotientRel p)⟩\n#align submodule.has_quotient Submodule.hasQuotient\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 → M ⧸ p :=\n  Quotient.mk''\n#align submodule.quotient.mk Submodule.Quotient.mk\n\n/- porting note: here and throughout elaboration is sped up *tremendously* (in some cases even\navoiding timeouts) by providing type ascriptions to `mk` (or `mk x`) and its variants. Lean 3\ndidn't need this help. -/\n@[simp]\ntheorem mk'_eq_mk' {p : Submodule R M} (x : M) :\n    @Quotient.mk' _ (quotientRel p) x = (mk : M → M ⧸ p) x :=\n  rfl\n#align submodule.quotient.mk_eq_mk Submodule.Quotient.mk'_eq_mk'\n\n@[simp]\ntheorem mk''_eq_mk {p : Submodule R M} (x : M) : (Quotient.mk'' x : M ⧸ p) = (mk : M → M ⧸ p) x :=\n  rfl\n#align submodule.quotient.mk'_eq_mk Submodule.Quotient.mk''_eq_mk\n\n@[simp]\ntheorem quot_mk_eq_mk {p : Submodule R M} (x : M) : (Quot.mk _ x : M ⧸ p) = (mk : M → M ⧸ p) x :=\n  rfl\n#align submodule.quotient.quot_mk_eq_mk Submodule.Quotient.quot_mk_eq_mk\n\nprotected theorem eq' {x y : M} : (mk x : M ⧸ p) = (mk : M → M ⧸ p) y ↔ -x + y ∈ p :=\n  QuotientAddGroup.eq\n#align submodule.quotient.eq' Submodule.Quotient.eq'\n\nprotected theorem eq {x y : M} : (mk x : M ⧸ p) = (mk y : M ⧸ p) ↔ x - y ∈ p :=\n  (Submodule.Quotient.eq' p).trans (leftRel_apply.symm.trans p.quotientRel_r_def)\n#align submodule.quotient.eq Submodule.Quotient.eq\n\ninstance : Zero (M ⧸ p) :=\n  ⟨mk 0⟩\n\ninstance : Inhabited (M ⧸ p) :=\n  ⟨0⟩\n\n@[simp]\ntheorem mk_zero : mk 0 = (0 : M ⧸ p) :=\n  rfl\n#align submodule.quotient.mk_zero Submodule.Quotient.mk_zero\n\n@[simp]\ntheorem mk_eq_zero : (mk x : M ⧸ p) = 0 ↔ x ∈ p := by simpa using (Quotient.eq' p : mk x = 0 ↔ _)\n#align submodule.quotient.mk_eq_zero Submodule.Quotient.mk_eq_zero\n\ninstance addCommGroup : AddCommGroup (M ⧸ p) :=\n  QuotientAddGroup.Quotient.addCommGroup p.toAddSubgroup\n#align submodule.quotient.add_comm_group Submodule.Quotient.addCommGroup\n\n@[simp]\ntheorem mk_add : (mk (x + y) : M ⧸ p) = (mk x : M ⧸ p) + (mk y : M ⧸ p) :=\n  rfl\n#align submodule.quotient.mk_add Submodule.Quotient.mk_add\n\n@[simp]\ntheorem mk_neg : (mk (-x) : M ⧸ p) = -(mk x : M ⧸ p) :=\n  rfl\n#align submodule.quotient.mk_neg Submodule.Quotient.mk_neg\n\n@[simp]\ntheorem mk_sub : (mk (x - y) : M ⧸ p) = (mk x : M ⧸ p) - (mk y : M ⧸ p) :=\n  rfl\n#align submodule.quotient.mk_sub Submodule.Quotient.mk_sub\n\nsection SMul\n\nvariable {S : Type _} [SMul S R] [SMul S M] [IsScalarTower S R M] (P : Submodule R M)\n\ninstance hasSmul' : SMul S (M ⧸ P) :=\n  ⟨fun a =>\n    Quotient.map' ((· • ·) a) fun x y h =>\n      leftRel_apply.mpr <| by simpa using Submodule.smul_mem P (a • (1 : R)) (leftRel_apply.mp h)⟩\n#align submodule.quotient.has_smul' Submodule.Quotient.hasSmul'\n\n-- porting note: should this be marked as a `@[default_instance]`?\n/-- Shortcut to help the elaborator in the common case. -/\ninstance hasSmul : SMul R (M ⧸ P) :=\n  Quotient.hasSmul' P\n#align submodule.quotient.has_smul Submodule.Quotient.hasSmul\n\n@[simp]\ntheorem mk_smul (r : S) (x : M) : (mk (r • x) : M ⧸ p) = r • mk x :=\n  rfl\n#align submodule.quotient.mk_smul Submodule.Quotient.mk_smul\n\ninstance smulCommClass (T : Type _) [SMul T R] [SMul T M] [IsScalarTower T R M]\n    [SMulCommClass S T M] : SMulCommClass S T (M ⧸ P)\n    where smul_comm _x _y := Quotient.ind' fun _z => congr_arg mk (smul_comm _ _ _)\n#align submodule.quotient.smul_comm_class Submodule.Quotient.smulCommClass\n\ninstance isScalarTower (T : Type _) [SMul T R] [SMul T M] [IsScalarTower T R M] [SMul S T]\n    [IsScalarTower S T M] : IsScalarTower S T (M ⧸ P)\n    where smul_assoc _x _y := Quotient.ind' fun _z => congr_arg mk (smul_assoc _ _ _)\n#align submodule.quotient.is_scalar_tower Submodule.Quotient.isScalarTower\n\ninstance isCentralScalar [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M]\n    [IsCentralScalar S M] : IsCentralScalar S (M ⧸ P)\n    where op_smul_eq_smul _x := Quotient.ind' fun _z => congr_arg mk <| op_smul_eq_smul _ _\n#align submodule.quotient.is_central_scalar Submodule.Quotient.isCentralScalar\n\nend SMul\n\nsection Module\n\nvariable {S : Type _}\n\ninstance mulAction' [Monoid S] [SMul S R] [MulAction S M] [IsScalarTower S R M]\n    (P : Submodule R M) : MulAction S (M ⧸ P) :=\n  Function.Surjective.mulAction mk (surjective_quot_mk _) <| Submodule.Quotient.mk_smul P\n#align submodule.quotient.mul_action' Submodule.Quotient.mulAction'\n\n-- porting note: should this be marked as a `@[default_instance]`?\ninstance mulAction (P : Submodule R M) : MulAction R (M ⧸ P) :=\n  Quotient.mulAction' P\n#align submodule.quotient.mul_action Submodule.Quotient.mulAction\n\ninstance smulZeroClass' [SMul S R] [SMulZeroClass S M] [IsScalarTower S R M] (P : Submodule R M) :\n    SMulZeroClass S (M ⧸ P) :=\n  ZeroHom.smulZeroClass ⟨mk, mk_zero _⟩ <| Submodule.Quotient.mk_smul P\n#align submodule.quotient.smul_zero_class' Submodule.Quotient.smulZeroClass'\n\n-- porting note: should this be marked as a `@[default_instance]`?\ninstance smulZeroClass (P : Submodule R M) : SMulZeroClass R (M ⧸ P) :=\n  Quotient.smulZeroClass' P\n#align submodule.quotient.smul_zero_class Submodule.Quotient.smulZeroClass\n\ninstance distribSmul' [SMul S R] [DistribSMul S M] [IsScalarTower S R M] (P : Submodule R M) :\n    DistribSMul S (M ⧸ P) :=\n  Function.Surjective.distribSMul {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}\n    (surjective_quot_mk _) (Submodule.Quotient.mk_smul P)\n#align submodule.quotient.distrib_smul' Submodule.Quotient.distribSmul'\n\n-- porting note: should this be marked as a `@[default_instance]`?\ninstance distribSmul (P : Submodule R M) : DistribSMul R (M ⧸ P) :=\n  Quotient.distribSmul' P\n#align submodule.quotient.distrib_smul Submodule.Quotient.distribSmul\n\ninstance distribMulAction' [Monoid S] [SMul S R] [DistribMulAction S M] [IsScalarTower S R M]\n    (P : Submodule R M) : DistribMulAction S (M ⧸ P) :=\n  Function.Surjective.distribMulAction {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}\n    (surjective_quot_mk _) (Submodule.Quotient.mk_smul P)\n#align submodule.quotient.distrib_mul_action' Submodule.Quotient.distribMulAction'\n\n-- porting note: should this be marked as a `@[default_instance]`?\ninstance distribMulAction (P : Submodule R M) : DistribMulAction R (M ⧸ P) :=\n  Quotient.distribMulAction' P\n#align submodule.quotient.distrib_mul_action Submodule.Quotient.distribMulAction\n\ninstance module' [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) :\n    Module S (M ⧸ P) :=\n  Function.Surjective.module _ {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}\n    (surjective_quot_mk _) (Submodule.Quotient.mk_smul P)\n#align submodule.quotient.module' Submodule.Quotient.module'\n\n-- porting note: should this be marked as a `@[default_instance]`?\ninstance module (P : Submodule R M) : Module R (M ⧸ P) :=\n  Quotient.module' P\n#align submodule.quotient.module Submodule.Quotient.module\n\nvariable (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 restrictScalarsEquiv [Ring S] [SMul S R] [Module S M] [IsScalarTower S R M]\n    (P : Submodule R M) : (M ⧸ P.restrictScalars S) ≃ₗ[S] M ⧸ P :=\n  {\n    Quotient.congrRight fun _ _ =>\n      Iff.rfl with\n    map_add' := fun x y => Quotient.inductionOn₂' x y fun _x' _y' => rfl\n    map_smul' := fun _c x => Quotient.inductionOn' x fun _x' => rfl }\n#align submodule.quotient.restrict_scalars_equiv Submodule.Quotient.restrictScalarsEquiv\n\n@[simp]\ntheorem restrictScalarsEquiv_mk [Ring S] [SMul S R] [Module S M] [IsScalarTower S R M]\n    (P : Submodule R M) (x : M) :\n    restrictScalarsEquiv S P (mk x : M ⧸ P) = (mk x : M ⧸ P) :=\n  rfl\n#align submodule.quotient.restrict_scalars_equiv_mk Submodule.Quotient.restrictScalarsEquiv_mk\n\n@[simp]\ntheorem restrictScalarsEquiv_symm_mk [Ring S] [SMul S R] [Module S M] [IsScalarTower S R M]\n    (P : Submodule R M) (x : M) :\n    (restrictScalarsEquiv S P).symm ((mk : M → M ⧸ P) x) = (mk : M → M ⧸ P) x :=\n  rfl\n#align submodule.quotient.restrict_scalars_equiv_symm_mk Submodule.Quotient.restrictScalarsEquiv_symm_mk\n\nend Module\n\ntheorem mk_surjective : Function.Surjective (@mk _ _ _ _ _ p) := by\n  rintro ⟨x⟩\n  exact ⟨x, rfl⟩\n#align submodule.quotient.mk_surjective Submodule.Quotient.mk_surjective\n\ntheorem nontrivial_of_lt_top (h : p < ⊤) : Nontrivial (M ⧸ p) := by\n  obtain ⟨x, _, not_mem_s⟩ := SetLike.exists_of_lt h\n  refine' ⟨⟨mk x, 0, _⟩⟩\n  simpa using not_mem_s\n#align submodule.quotient.nontrivial_of_lt_top Submodule.Quotient.nontrivial_of_lt_top\n\nend Quotient\n\ninstance QuotientBot.infinite [Infinite M] : Infinite (M ⧸ (⊥ : Submodule R M)) :=\n  Infinite.of_injective Submodule.Quotient.mk fun _x _y h =>\n    sub_eq_zero.mp <| (Submodule.Quotient.eq ⊥).mp h\n#align submodule.quotient_bot.infinite Submodule.QuotientBot.infinite\n\ninstance QuotientTop.unique : Unique (M ⧸ (⊤ : Submodule R M))\n    where\n  default := 0\n  uniq x := Quotient.inductionOn' x fun _x => (Submodule.Quotient.eq ⊤).mpr Submodule.mem_top\n#align submodule.quotient_top.unique Submodule.QuotientTop.unique\n\ninstance QuotientTop.fintype : Fintype (M ⧸ (⊤ : Submodule R M)) :=\n  Fintype.ofSubsingleton 0\n#align submodule.quotient_top.fintype Submodule.QuotientTop.fintype\n\nvariable {p}\n\ntheorem subsingleton_quotient_iff_eq_top : Subsingleton (M ⧸ p) ↔ p = ⊤ := by\n  constructor\n  · rintro h\n    refine' eq_top_iff.mpr fun x _ => _\n    have : x - 0 ∈ p := (Submodule.Quotient.eq p).mp (Subsingleton.elim _ _)\n    rwa [sub_zero] at this\n  · rintro rfl\n    infer_instance\n#align submodule.subsingleton_quotient_iff_eq_top Submodule.subsingleton_quotient_iff_eq_top\n\ntheorem unique_quotient_iff_eq_top : Nonempty (Unique (M ⧸ p)) ↔ p = ⊤ :=\n  ⟨fun ⟨h⟩ => subsingleton_quotient_iff_eq_top.mp (@Unique.instSubsingleton _ h),\n   by\n    rintro rfl\n    exact ⟨QuotientTop.unique⟩⟩\n#align submodule.unique_quotient_iff_eq_top Submodule.unique_quotient_iff_eq_top\n\nvariable (p)\n\nnoncomputable instance Quotient.fintype [Fintype M] (S : Submodule R M) : Fintype (M ⧸ S) :=\n  @_root_.Quotient.fintype _ _ _ fun _ _ => Classical.dec _\n#align submodule.quotient.fintype Submodule.Quotient.fintype\n\ntheorem card_eq_card_quotient_mul_card [Fintype M] (S : Submodule R M) [DecidablePred (· ∈ S)] :\n    Fintype.card M = Fintype.card S * Fintype.card (M ⧸ S) := by\n  rw [mul_comm, ← Fintype.card_prod]\n  exact Fintype.card_congr AddSubgroup.addGroupEquivQuotientProdAddSubgroup\n#align submodule.card_eq_card_quotient_mul_card Submodule.card_eq_card_quotient_mul_card\n\nsection\n\nvariable {M₂ : Type _} [AddCommGroup M₂] [Module R M₂]\n\ntheorem quot_hom_ext (f g : (M ⧸ p) →ₗ[R] M₂) (h : ∀ x : M, f (Quotient.mk x) = g (Quotient.mk x)) :\n    f = g :=\n  LinearMap.ext fun x => Quotient.inductionOn' x h\n#align submodule.quot_hom_ext Submodule.quot_hom_ext\n\n/-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/\ndef mkQ : M →ₗ[R] M ⧸ p where\n  toFun := Quotient.mk\n  map_add' := by simp\n  map_smul' := by simp\n#align submodule.mkq Submodule.mkQ\n\n@[simp]\ntheorem mkQ_apply (x : M) : p.mkQ x = (Quotient.mk x : M ⧸ p) :=\n  rfl\n#align submodule.mkq_apply Submodule.mkQ_apply\n\ntheorem mkQ_surjective (A : Submodule R M) : Function.Surjective A.mkQ := by\n  rintro ⟨x⟩; exact ⟨x, rfl⟩\n#align submodule.mkq_surjective Submodule.mkQ_surjective\n\nend\n\nvariable {R₂ M₂ : Type _} [Ring R₂] [AddCommGroup M₂] [Module R₂ M₂] {τ₁₂ : R →+* R₂}\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 1100] -- porting note: increase priority so this applies before `LinearMap.ext`\ntheorem linearMap_qext ⦃f g : M ⧸ p →ₛₗ[τ₁₂] M₂⦄ (h : f.comp p.mkQ = g.comp p.mkQ) : f = g :=\n  LinearMap.ext fun x => Quotient.inductionOn' x <| (LinearMap.congr_fun h : _)\n#align submodule.linear_map_qext Submodule.linearMap_qext\n\n/-- The map from the quotient of `M` by a submodule `p` to `M₂` induced by a linear map `f : M → M₂`\nvanishing on `p`, as a linear map. -/\ndef liftQ (f : M →ₛₗ[τ₁₂] M₂) (h : p ≤ ker f) : M ⧸ p →ₛₗ[τ₁₂] M₂ :=\n  { QuotientAddGroup.lift p.toAddSubgroup f.toAddMonoidHom h with\n    map_smul' := by rintro a ⟨x⟩; exact f.map_smulₛₗ a x }\n#align submodule.liftq Submodule.liftQ\n\n@[simp]\ntheorem liftQ_apply (f : M →ₛₗ[τ₁₂] M₂) {h} (x : M) : p.liftQ f h (Quotient.mk x) = f x :=\n  rfl\n#align submodule.liftq_apply Submodule.liftQ_apply\n\n@[simp]\ntheorem liftQ_mkQ (f : M →ₛₗ[τ₁₂] M₂) (h) : (p.liftQ f h).comp p.mkQ = f := by ext; rfl\n#align submodule.liftq_mkq Submodule.liftQ_mkQ\n\n/-- Special case of `submodule.liftQ` when `p` is the span of `x`. In this case, the condition on\n`f` simply becomes vanishing at `x`.-/\ndef liftQSpanSingleton (x : M) (f : M →ₛₗ[τ₁₂] M₂) (h : f x = 0) : (M ⧸ R ∙ x) →ₛₗ[τ₁₂] M₂ :=\n  (R ∙ x).liftQ f <| by rw [span_singleton_le_iff_mem, LinearMap.mem_ker, h]\n#align submodule.liftq_span_singleton Submodule.liftQSpanSingleton\n\n@[simp]\ntheorem liftQSpanSingleton_apply (x : M) (f : M →ₛₗ[τ₁₂] M₂) (h : f x = 0) (y : M) :\n    liftQSpanSingleton x f h (Quotient.mk y) = f y :=\n  rfl\n#align submodule.liftq_span_singleton_apply Submodule.liftQSpanSingleton_apply\n\n@[simp]\ntheorem range_mkQ : range p.mkQ = ⊤ :=\n  eq_top_iff'.2 <| by rintro ⟨x⟩; exact ⟨x, rfl⟩\n#align submodule.range_mkq Submodule.range_mkQ\n\n@[simp]\ntheorem ker_mkQ : ker p.mkQ = p := by ext; simp\n#align submodule.ker_mkq Submodule.ker_mkQ\n\ntheorem le_comap_mkQ (p' : Submodule R (M ⧸ p)) : p ≤ comap p.mkQ p' := by\n  simpa using (comap_mono bot_le : ker p.mkQ ≤ comap p.mkQ p')\n#align submodule.le_comap_mkq Submodule.le_comap_mkQ\n\n@[simp]\ntheorem mkQ_map_self : map p.mkQ p = ⊥ := by\n  rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkQ]\n#align submodule.mkq_map_self Submodule.mkQ_map_self\n\n@[simp]\ntheorem comap_map_mkQ : comap p.mkQ (map p.mkQ p') = p ⊔ p' := by simp [comap_map_eq, sup_comm]\n#align submodule.comap_map_mkq Submodule.comap_map_mkQ\n\n@[simp]\ntheorem map_mkQ_eq_top : map p.mkQ p' = ⊤ ↔ p ⊔ p' = ⊤ := by\n  simp only [map_eq_top_iff p.range_mkQ, sup_comm, ker_mkQ]\n#align submodule.map_mkq_eq_top Submodule.map_mkQ_eq_top\n\nvariable (q : Submodule R₂ M₂)\n\n/-- The map from the quotient of `M` by submodule `p` to the quotient of `M₂` by submodule `q` along\n`f : M → M₂` is linear. -/\ndef mapQ (f : M →ₛₗ[τ₁₂] M₂) (h : p ≤ comap f q) : M ⧸ p →ₛₗ[τ₁₂] M₂ ⧸ q :=\n  p.liftQ (q.mkQ.comp f) <| by simpa [ker_comp] using h\n#align submodule.mapq Submodule.mapQ\n\n@[simp]\ntheorem mapQ_apply (f : M →ₛₗ[τ₁₂] M₂) {h} (x : M) :\n    mapQ p q f h (Quotient.mk x : M ⧸ p) = (Quotient.mk (f x) : M₂ ⧸ q) :=\n  rfl\n#align submodule.mapq_apply Submodule.mapQ_apply\n\ntheorem mapQ_mkQ (f : M →ₛₗ[τ₁₂] M₂) {h} : (mapQ p q f h).comp p.mkQ = q.mkQ.comp f := by\n  ext x; rfl\n#align submodule.mapq_mkq Submodule.mapQ_mkQ\n\n@[simp]\ntheorem mapQ_zero (h : p ≤ q.comap (0 : M →ₛₗ[τ₁₂] M₂) := (by simp)) :\n    p.mapQ q (0 : M →ₛₗ[τ₁₂] M₂) h = 0 := by\n  ext\n  simp\n#align submodule.mapq_zero Submodule.mapQ_zero\n\n/-- Given submodules `p ⊆ M`, `p₂ ⊆ M₂`, `p₃ ⊆ M₃` and maps `f : M → M₂`, `g : M₂ → M₃` inducing\n`mapQ f : M ⧸ p → M₂ ⧸ p₂` and `mapQ g : M₂ ⧸ p₂ → M₃ ⧸ p₃` then\n`mapQ (g ∘ f) = (mapQ g) ∘ (mapQ f)`. -/\ntheorem mapQ_comp {R₃ M₃ : Type _} [Ring R₃] [AddCommGroup M₃] [Module R₃ M₃] (p₂ : Submodule R₂ M₂)\n    (p₃ : Submodule R₃ M₃) {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]\n    (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : p ≤ p₂.comap f) (hg : p₂ ≤ p₃.comap g)\n    (h := hf.trans (comap_mono hg)) :\n    p.mapQ p₃ (g.comp f) h = (p₂.mapQ p₃ g hg).comp (p.mapQ p₂ f hf) := by\n  ext\n  simp\n#align submodule.mapq_comp Submodule.mapQ_comp\n\n@[simp]\ntheorem mapQ_id (h : p ≤ p.comap LinearMap.id := (by rw [comap_id])) :\n    p.mapQ p LinearMap.id h = LinearMap.id := by\n  ext\n  simp\n#align submodule.mapq_id Submodule.mapQ_id\n\ntheorem mapQ_pow {f : M →ₗ[R] M} (h : p ≤ p.comap f) (k : ℕ)\n    (h' : p ≤ 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 := by\n  induction' k with k ih\n  · simp [LinearMap.one_eq_id]\n  · simp only [LinearMap.iterate_succ]\n    -- porting note: why does any of these `optParams` need to be applied? Why didn't `simp` handle\n    -- all of this for us?\n    convert mapQ_comp p p p f (f ^ k) h (p.le_comap_pow_of_le_comap h k)\n      (h.trans (comap_mono <| p.le_comap_pow_of_le_comap h k))\n    exact (ih _).symm\n#align submodule.mapq_pow Submodule.mapQ_pow\n\ntheorem comap_liftQ (f : M →ₛₗ[τ₁₂] M₂) (h) : q.comap (p.liftQ f h) = (q.comap f).map (mkQ p) :=\n  le_antisymm (by rintro ⟨x⟩ hx; exact ⟨_, hx, rfl⟩)\n    (by rw [map_le_iff_le_comap, ← comap_comp, liftQ_mkQ])\n#align submodule.comap_liftq Submodule.comap_liftQ\n\ntheorem map_liftQ [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (h) (q : Submodule R (M ⧸ p)) :\n    q.map (p.liftQ f h) = (q.comap p.mkQ).map f :=\n  le_antisymm (by rintro _ ⟨⟨x⟩, hxq, rfl⟩; exact ⟨x, hxq, rfl⟩)\n    (by rintro _ ⟨x, hxq, rfl⟩; exact ⟨Quotient.mk x, hxq, rfl⟩)\n#align submodule.map_liftq Submodule.map_liftQ\n\ntheorem ker_liftQ (f : M →ₛₗ[τ₁₂] M₂) (h) : ker (p.liftQ f h) = (ker f).map (mkQ p) :=\n  comap_liftQ _ _ _ _\n#align submodule.ker_liftq Submodule.ker_liftQ\n\ntheorem range_liftQ [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (h) :\n    range (p.liftQ f h) = range f := by simpa only [range_eq_map] using map_liftQ _ _ _ _\n#align submodule.range_liftq Submodule.range_liftQ\n\ntheorem ker_liftQ_eq_bot (f : M →ₛₗ[τ₁₂] M₂) (h) (h' : ker f ≤ p) : ker (p.liftQ f h) = ⊥ := by\n  rw [ker_liftQ, le_antisymm h h', mkQ_map_self]\n#align submodule.ker_liftq_eq_bot Submodule.ker_liftQ_eq_bot\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 comapMkQRelIso : Submodule R (M ⧸ p) ≃o { p' : Submodule R M // p ≤ p' }\n    where\n  toFun p' := ⟨comap p.mkQ p', le_comap_mkQ p _⟩\n  invFun q := map p.mkQ q\n  left_inv p' := map_comap_eq_self <| by simp\n  right_inv := fun ⟨q, hq⟩ => Subtype.ext_val <| by simpa [comap_map_mkQ p]\n  map_rel_iff' := comap_le_comap_iff <| range_mkQ _\n#align submodule.comap_mkq.rel_iso Submodule.comapMkQRelIso\n\n/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules\nof `M`. -/\ndef comapMkQOrderEmbedding : Submodule R (M ⧸ p) ↪o Submodule R M :=\n  (RelIso.toRelEmbedding <| comapMkQRelIso p).trans (Subtype.relEmbedding (· ≤ ·) _)\n\n#align submodule.comap_mkq.order_embedding Submodule.comapMkQOrderEmbedding\n\n@[simp]\ntheorem comapMkQOrderEmbedding_eq (p' : Submodule R (M ⧸ p)) :\n    comapMkQOrderEmbedding p p' = comap p.mkQ p' :=\n  rfl\n#align submodule.comap_mkq_embedding_eq Submodule.comapMkQOrderEmbedding_eq\n\ntheorem span_preimage_eq [RingHomSurjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {s : Set M₂} (h₀ : s.Nonempty)\n    (h₁ : s ⊆ range f) : span R (f ⁻¹' s) = (span R₂ s).comap f := by\n  suffices (span R₂ s).comap f ≤ span R (f ⁻¹' s) by exact le_antisymm (span_preimage_le f s) this\n  have hk : ker f ≤ span R (f ⁻¹' s) :=\n    by\n    let y := Classical.choose h₀\n    have hy : y ∈ s := Classical.choose_spec h₀\n    rw [ker_le_iff]\n    use y, h₁ hy\n    rw [← Set.singleton_subset_iff] at hy\n    exact Set.Subset.trans subset_span (span_mono (Set.preimage_mono hy))\n  rw [← left_eq_sup] at hk\n  rw [range_coe f] at h₁\n  rw [hk, ← LinearMap.map_le_map_iff, map_span, map_comap_eq, Set.image_preimage_eq_of_subset h₁]\n  exact inf_le_right\n#align submodule.span_preimage_eq Submodule.span_preimage_eq\n\n/-- If `P` is a submodule of `M` and `Q` a submodule of `N`,\nand `f : M ≃ₗ N` maps `P` to `Q`, then `M ⧸ P` is equivalent to `N ⧸ Q`. -/\n@[simps]\ndef Quotient.equiv {N : Type _} [AddCommGroup N] [Module R N] (P : Submodule R M)\n    (Q : Submodule R N) (f : M ≃ₗ[R] N) (hf : P.map f = Q) : (M ⧸ P) ≃ₗ[R] N ⧸ Q :=\n  {\n    P.mapQ Q (f : M →ₗ[R] N) fun x hx =>\n      hf ▸\n        Submodule.mem_map_of_mem\n          hx with\n    toFun := P.mapQ Q (f : M →ₗ[R] N) fun x hx => hf ▸ Submodule.mem_map_of_mem hx\n    invFun :=\n      Q.mapQ P (f.symm : N →ₗ[R] M) fun x hx =>\n        by\n        rw [← hf, Submodule.mem_map] at hx\n        obtain ⟨y, hy, rfl⟩ := hx\n        simpa\n    left_inv := fun x => Quotient.inductionOn' x (by simp)\n    right_inv := fun x => Quotient.inductionOn' x (by simp) }\n#align submodule.quotient.equiv Submodule.Quotient.equiv\n#align submodule.quotient.equiv_apply Submodule.Quotient.equiv_apply\n\n@[simp]\ntheorem Quotient.equiv_symm {R M N : Type _} [CommRing R] [AddCommGroup M] [Module R M]\n    [AddCommGroup N] [Module R N] (P : Submodule R M) (Q : Submodule R N) (f : M ≃ₗ[R] N)\n    (hf : P.map f = Q) :\n    (Quotient.equiv P Q f hf).symm =\n      Quotient.equiv Q P f.symm ((Submodule.map_symm_eq_iff f).mpr hf) :=\n  rfl\n#align submodule.quotient.equiv_symm Submodule.Quotient.equiv_symm\n\n@[simp]\ntheorem Quotient.equiv_trans {N O : Type _} [AddCommGroup N] [Module R N] [AddCommGroup O]\n    [Module R O] (P : Submodule R M) (Q : Submodule R N) (S : Submodule R O) (e : M ≃ₗ[R] N)\n    (f : N ≃ₗ[R] O) (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 =\n      (Quotient.equiv P Q e he).trans (Quotient.equiv Q S f hf) := by\n  ext\n  -- `simp` can deal with `hef` depending on `e` and `f`\n  simp only [Quotient.equiv_apply, LinearEquiv.trans_apply, LinearEquiv.coe_trans]\n  -- `rw` can deal with `mapQ_comp` needing extra hypotheses coming from the RHS\n  rw [mapQ_comp, LinearMap.comp_apply]\n#align submodule.quotient.equiv_trans Submodule.Quotient.equiv_trans\n\nend Submodule\n\nopen Submodule\n\nnamespace LinearMap\n\nsection Ring\n\nvariable {R M R₂ M₂ R₃ M₃ : Type _}\n\nvariable [Ring R] [Ring R₂] [Ring R₃]\n\nvariable [AddCommMonoid M] [AddCommGroup M₂] [AddCommMonoid M₃]\n\nvariable [Module R M] [Module R₂ M₂] [Module R₃ M₃]\n\nvariable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}\n\nvariable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] [RingHomSurjective τ₁₂]\n\ntheorem range_mkQ_comp (f : M →ₛₗ[τ₁₂] M₂) : f.range.mkQ.comp f = 0 :=\n  LinearMap.ext fun x => by simp\n#align linear_map.range_mkq_comp LinearMap.range_mkQ_comp\n\n\n\n/-- An epimorphism is surjective. -/\ntheorem range_eq_top_of_cancel {f : M →ₛₗ[τ₁₂] M₂}\n    (h : ∀ u v : M₂ →ₗ[R₂] M₂ ⧸ (range f), u.comp f = v.comp f → u = v) : range f = ⊤ := by\n  have h₁ : (0 : M₂ →ₗ[R₂] M₂ ⧸ (range f)).comp f = 0 := zero_comp _\n  rw [← Submodule.ker_mkQ (range f), ← h 0 f.range.mkQ (Eq.trans h₁ (range_mkQ_comp _).symm)]\n  exact ker_zero\n#align linear_map.range_eq_top_of_cancel LinearMap.range_eq_top_of_cancel\n\nend Ring\n\nend LinearMap\n\nopen LinearMap\n\nnamespace Submodule\n\nvariable {R M : Type _} {r : R} {x y : M} [Ring R] [AddCommGroup M] [Module R M]\n\nvariable (p p' : Submodule R M)\n\n/-- If `p = ⊥`, then `M / p ≃ₗ[R] M`. -/\ndef quotEquivOfEqBot (hp : p = ⊥) : (M ⧸ p) ≃ₗ[R] M :=\n  LinearEquiv.ofLinear (p.liftQ id <| hp.symm ▸ bot_le) p.mkQ (liftQ_mkQ _ _ _) <|\n    p.quot_hom_ext _ LinearMap.id fun _ => rfl\n#align submodule.quot_equiv_of_eq_bot Submodule.quotEquivOfEqBot\n\n@[simp]\ntheorem quotEquivOfEqBot_apply_mk (hp : p = ⊥) (x : M) :\n    p.quotEquivOfEqBot hp (Quotient.mk x : M ⧸ p) = x :=\n  rfl\n#align submodule.quot_equiv_of_eq_bot_apply_mk Submodule.quotEquivOfEqBot_apply_mk\n\n@[simp]\ntheorem quotEquivOfEqBot_symm_apply (hp : p = ⊥) (x : M) :\n    (p.quotEquivOfEqBot hp).symm x = (Quotient.mk x : M ⧸ p) :=\n  rfl\n#align submodule.quot_equiv_of_eq_bot_symm_apply Submodule.quotEquivOfEqBot_symm_apply\n\n@[simp]\ntheorem coe_quotEquivOfEqBot_symm (hp : p = ⊥) :\n    ((p.quotEquivOfEqBot hp).symm : M →ₗ[R] M ⧸ p) = p.mkQ :=\n  rfl\n#align submodule.coe_quot_equiv_of_eq_bot_symm Submodule.coe_quotEquivOfEqBot_symm\n\n/-- Quotienting by equal submodules gives linearly equivalent quotients. -/\ndef quotEquivOfEq (h : p = p') : (M ⧸ p) ≃ₗ[R] M ⧸ p' :=\n  {\n    @Quotient.congr _ _ (quotientRel p) (quotientRel p') (Equiv.refl _) fun a b =>\n      by\n      subst h\n      rfl with\n    map_add' := by\n      rintro ⟨x⟩ ⟨y⟩\n      rfl\n    map_smul' := by\n      rintro x ⟨y⟩\n      rfl }\n#align submodule.quot_equiv_of_eq Submodule.quotEquivOfEq\n\n@[simp]\ntheorem quotEquivOfEq_mk (h : p = p') (x : M) :\n    Submodule.quotEquivOfEq p p' h (Submodule.Quotient.mk x : M ⧸ p) =\n      (Submodule.Quotient.mk x : M ⧸ p') :=\n  rfl\n#align submodule.quot_equiv_of_eq_mk Submodule.quotEquivOfEq_mk\n\n@[simp]\ntheorem Quotient.equiv_refl (P : Submodule R M) (Q : Submodule R M)\n    (hf : P.map (LinearEquiv.refl R M : M →ₗ[R] M) = Q) :\n    Quotient.equiv P Q (LinearEquiv.refl R M) hf = quotEquivOfEq _ _ (by simpa using hf) :=\n  rfl\n#align submodule.quotient.equiv_refl Submodule.Quotient.equiv_refl\n\nend Submodule\n\nend Ring\n\nsection CommRing\n\nvariable {R M M₂ : Type _} {r : R} {x y : M} [CommRing R] [AddCommGroup M] [Module R M]\n  [AddCommGroup M₂] [Module R M₂] (p : Submodule R M) (q : Submodule R M₂)\n\nnamespace Submodule\n\n/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,\nthe natural map $\\{f ∈ Hom(M, M₂) | f(p) ⊆ q \\} \\to Hom(M/p, M₂/q)$ is linear. -/\ndef mapQLinear : compatibleMaps p q →ₗ[R] M ⧸ p →ₗ[R] M₂ ⧸ q\n    where\n  toFun f := mapQ _ _ f.val f.property\n  map_add' x y := by\n    ext\n    rfl\n  map_smul' c f := by\n    ext\n    rfl\n#align submodule.mapq_linear Submodule.mapQLinear\n\nend Submodule\n\nend CommRing\n\nend deinstance_nonassocring\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/Quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7549835990329791}}
{"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 6 : 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 `⊢ 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 ∈ A ↔ x ∈ 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 ⊆ B → B ⊆ A → A = B :=\nbegin\n  sorry\nend\n\nexample : A ∪ A = A :=\nbegin\n  sorry\nend\n\nexample : A ∩ A = A :=\nbegin\n  sorry\nend\n\nexample : A ∩ B = B ∩ A :=\nbegin\n  sorry\nend\n\nexample : A ∩ (B ∩ C) = (A ∩ B) ∩ C :=\nbegin\n  sorry\nend\n\nexample : A ∪ (B ∪ C) = (A ∪ B) ∪ C :=\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/sets/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.754949315476651}}
{"text": "import tactic\n\n-- Основано на https://github.com/ImperialCollegeLondon/formalising-mathematics/tree/master/src/week_7\n-- Я убрал довольно много материала оттуда, посмотрите по возможности оригинал, в котором Kevin уходит гораздо глубже в концепцию `quotient`\n-- Больше в книге Theorem Proving in Lean: https://leanprover.github.io/theorem_proving_in_lean/axioms_and_computation.html#quotients\n\n-- В этом файле мы изучим конструкцию `quotient`\n-- И построим целые числа как классы эквивалентности пар натуральных чисел (a, b)\n-- Где (a, b) ≈ (c, d) ↔ a + d = b + c\n-- В первом приближении `quotient` можно описать как \"тип классов эквивалентности по бинарному отношению\"\n-- Пусть у нас есть тип `α` и отношение эквивалентности `r : α → α → Prop`\n\n-- `abbreviation` это просто синтаксический синоним\nabbreviation N2 := ℕ × ℕ\n\nnamespace N2\n\nsection product\n\ndef foo : ℕ × ℕ := (3, 4)\n\n#reduce (foo.fst, foo.snd)\n-- Аналогично можно писать `foo.1` или `foo.2`\n\n-- Чтобы доказать равенство двух пар, можно использовать `ext` \nexample (X Y : Type) (s t : X × 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-- Чтобы разбить пару `x` на два натуральных числа, можно использовать `cases x with a b`\nexample (A B : Type) (x : A × B) : x = (x.1, x.2) :=\nbegin\n  cases x with a b,\n  -- ⊢ (a, b) = ((a, b).fst, (a, b).snd)\n  dsimp only, -- упрощает `(a, b).fst` до `a`.\n  -- ⊢ (a, b) = (a, b)\n  refl,\nend\n\nend product\n\n-- Как построить целые числа на основе натуральных? \n-- Стандартная конструкция: целое число либо `n : ℕ`, либо `-n-1`\n#check ℤ\n\n-- Иначе целые числа можно представить, как разность двух натуральных чисел, например, -1 = 3 - 4\n-- Такое представление неоднозначно, 3 - 4 = 5 - 6 = ...\n-- В каком случае две пары задают одно число? a - b = c - d ↔ a + d = c + b\n-- Определим отношение `r : N2 → N2 → Prop`: r (a, b) (c, d) = a + d = c + b\n\ndef r (ab cd : N2) : Prop :=\nab.1 + cd.2 = cd.1 + ab.2\n\nlemma r_def (ab cd : N2) : r ab cd ↔ ab.1 + cd.2 = cd.1 + ab.2 := iff.rfl\n\nlemma r_def' (a b c d : ℕ) : r (a,b) (c,d) ↔ a + d = c + b := iff.rfl\n\ndef r_refl : reflexive r :=\nbegin\n  -- `unfold reflexive` раскроет определение и покажет, как оно определено\n  -- не забывайте, что N2 = ℕ × ℕ, поэтому можно делать `rintro ⟨a, b⟩`\n  sorry,\nend\n \ndef r_symm : symmetric r :=\nbegin\n  sorry,\nend\n\ndef r_trans : transitive r :=\nbegin\n  sorry,\nend\n\n-- Определим инстанс класса `setoid`: это просто отношение эквивалентности на `N2`\ninstance setoid : setoid N2 := ⟨r, r_refl, r_symm, r_trans⟩\n\n-- Теперь можно использовать `≈` (\\~~ или \\approx) \n\nexample (x y : N2) : x ≈ y ↔ r x y := iff.rfl\n\n-- Добавим simp-леммы для упрощения жизни в будущем\n@[simp] lemma equiv_def (ab cd : N2) : ab ≈ cd ↔ ab.1 + cd.2 = cd.1 + ab.2 :=\nbegin\n  refl\nend\n\n@[simp] lemma equiv_def' (a b c d : ℕ) : (a,b) ≈ (c,d) ↔ a + d = c + b := iff.rfl \n\nend N2\n\nopen N2\n\n-- Определим Z как `quotient` по определенному отношению эквивалентности\ndef Z := quotient N2.setoid\n\nnamespace Z\n\n-- По заданной паре типа N2 можно легко получить элемент типа Z как `quotient.mk x`\n-- Или же `⟦x⟧`\n\ndef bar : Z := quotient.mk foo -- соответствует целому числу -1.\n\nexample : bar = ⟦foo⟧ := rfl\n\n-- Посмотрим на API `quotient`\n\nexample (x y : N2) : x ≈ y → ⟦x⟧ = ⟦y⟧ := quotient.sound\n\nexample (x y : N2) : ⟦x⟧ = ⟦y⟧ → x ≈ y := quotient.exact\n\nexample (x y : N2) : ⟦x⟧ = ⟦y⟧ ↔ x ≈ y := quotient.eq\n\n-- Определим и докажем все операции над Z, дойдя до коммутативного кольца\n\n-- Определим 0 и 1:\n\ndef zero : Z := ⟦(0, 0)⟧\n\ndef one : Z := ⟦(1, 0)⟧\n\ninstance : has_zero Z := ⟨zero⟩\ninstance : has_one Z := ⟨one⟩\n\n@[simp] lemma zero_def : (0 : Z) = ⟦(0, 0)⟧ := rfl  \n@[simp] lemma one_def : (1 : Z) = ⟦(1, 0)⟧ := rfl\n\n/-\nОпределим обратное по сложению число. Как определить функцию для `quotient`?\n\n1) Определим вспомогательное отображение `N2 → Z`: по `(a,b)` выдаем `⟦(b,a)⟧`\n2) Докажем, что эта функция константна на классах эквивалентности:\n  `(a, b) ≈ (c, d) → ⟦(b, a)⟧ = ⟦(d, c)⟧`\n3) Используем `quotient.lift`, чтобы получить функцию `Z → Z`.\n\n-/\n\ndef neg_aux (ab : N2) : Z := ⟦(ab.2, ab.1)⟧\n\n@[simp] lemma neg_aux_def (ab : N2) : neg_aux ab = ⟦(ab.2, ab.1)⟧ := rfl\n\ndef neg : Z → Z := quotient.lift neg_aux \nbegin\n  -- ⊢ ∀ (a b : N2), a ≈ b → neg_aux a = neg_aux b\n  intros a b rab,\n  sorry,\nend\n\n-- нотация `-z`\ninstance : has_neg Z := ⟨neg⟩\n\n@[simp] lemma neg_def (a b : ℕ) : (-⟦(a, b)⟧ : Z) = ⟦(b, a)⟧ := rfl\n\n/-\nОпределим сложение. Если бы мы определяли сложение так же, как отрицание, то пришлось бы использовать\n`lift` дважды: сначала показать, что функция независима по первому аргументу, потом по второму.\nЕсть функция `quotient.lift₂`, которая позволяет взять функцию `f : A → B → C`,\nи доказательство, что она не меняет значение, если заменить первые два аргумента на эквивалентные, и выдает функцию `A/~ → B/~ → C`.\n-/\n\n-- Вспомогательное определение сложения (note `(a-b)+(c-d)=(a+c)-(b+d)` )\ndef add_aux (ab cd : N2) : Z := ⟦(ab.1 + cd.1, ab.2 + cd.2)⟧\n\n-- И simp-лемма для него\n@[simp] lemma add_aux_def (ab cd : N2) : add_aux ab cd = ⟦(ab.1 + cd.1, ab.2 + cd.2)⟧ := rfl \n\ndef add : Z → Z → Z := quotient.lift₂ add_aux \nbegin\n  rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨c₁, d₁⟩ ⟨c₂, d₂⟩ rab rcd,\n  sorry,\nend\n\ninstance : has_add Z := ⟨add⟩\n\n@[simp] lemma add_def (a b c d : ℕ) :\n  (⟦(a, b)⟧ + ⟦(c, d)⟧ : Z) = ⟦(a+c, b+d)⟧ := \nrfl\n\n-- И определим вычитание целых чисел\ndef sub (x y : Z) : Z := x + -y\n\ninstance : has_sub Z := ⟨sub⟩\n\n-- Покажем, что Z - коммутативная группа по сложению\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  -- Используйте `quotient.induction_on` для доказательства лемм про свойства операций над `quotient`\n  -- \"Если для всех `x : N2` верно `p ⟦x⟧`, то для всех `y : Z` верно p y\"\n  zero_add := begin\n    intro x,\n    apply quotient.induction_on x, clear x,\n    rintro ⟨a, b⟩,\n    simp,\n  end,\n  add_zero := begin\n    sorry,\n  end,    \n  -- Для версий с 2 и 3 аргументами есть `quotient.induction_on₂` и `quotient.induction_on₃`\n  -- Не забывайте про `linarith` и `ring`\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-- Умножение: `(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 : ℕ) :\n  mul_aux (a,b) (c,d) = (a*c+b*d,a*d+b*c) := rfl\n\n-- Для разнообразия определим умножение слегка иначе.\n-- Вместо использования `quotient.lift₂` (который превращает `N2 → N2 → Z` в `Z → Z → Z`),\n-- используем `quotient.map₂`, который превращает `N2 → N2 → N2` в `Z → Z → Z`.\n-- `nlinarith` умеет доказывать некоторые цели, содержащие нелинейные [не]равенства\ndef mul : Z → Z → Z := quotient.map₂ mul_aux \nbegin\n  sorry,\nend\n\ninstance : has_mul Z := ⟨mul⟩\n\n@[simp] lemma mul_def (a b c d : ℕ) :\n  (⟦(a, b)⟧ * ⟦(c, d)⟧ : Z) = ⟦(a*c+b*d, a*d+b*c)⟧ := rfl\n\n-- И наконец, докажем, что Z - коммутативное кольцо\ndef comm_ring : comm_ring Z :=\n{ one := 1,\n  add := (+),\n  mul := (*),\n  mul_assoc := begin\n    sorry,\n  end,\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": "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/week06/e01_Z.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7549408014953672}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Sea x un número real. Demostrar que si \n--    x ≠ 0\n-- entonces\n--    x < 0 ∨ x > 0\n -- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nexample \n  {x : ℝ} \n  (h : x ≠ 0) \n  : x < 0 ∨ x > 0 :=\nbegin\n  rcases lt_trichotomy x 0 with xlt | xeq | xgt,\n  { left, \n    exact xlt },\n  { contradiction },\n  { right, \n    exact xgt },\nend\n\n-- Prueba\n-- ======\n\n/-\nx : ℝ,\nh : x ≠ 0\n⊢ x < 0 ∨ x > 0\n  >> rcases lt_trichotomy x 0 with xlt | xeq | xgt,\n| | xlt : x < 0\n| | ⊢ x < 0 ∨ x > 0\n| |   >> { left,\n| | ⊢ x < 0 \n| |   >>  exact xlt },\n| h : x ≠ 0,\n| xeq : x = 0\n| ⊢ x < 0 ∨ x > 0\n  >> { contradiction },\nh : x ≠ 0,\nxgt : 0 < x\n⊢ x < 0 ∨ x > 0\n  >> { right, \n⊢ x > 0\n  >>  exact xgt },\nno goals\n-/\n\n-- Comentarios:\n-- 1. La táctica (rcases h with h1 | h2 | h3) si el objetivo es (P ∨ Q ∨ R)\n--    crea tres casos añadiéndole al primero la hipótesis (h1 : P), al\n--    segundo (h2 : Q) y al tercero (h3 : R). \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/Eliminacion_de_la_disyuncion_con_rcases.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7549407990270984}}
{"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\nimport tactic.linarith.verification\nimport 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₁x₁ + a₂x₂ + ... + aₙxₙ R b₁x₁ + b₂x₂ + ... + bₙxₙ}`,\nwhere `R ∈ {<, ≤, =, ≥, >}`.\nOur goal is to determine if the inequalities in `S` are jointly satisfiable, that is, if there is\nan assignment of values to `x₁, ..., xₙ` 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 `ℤ` that are not dense orders, but it will fail to prove `false` on some unsatisfiable\nproblems. It will run over concrete types like `ℕ`, `ℚ`, and `ℝ`, 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ᵢ Rᵢ 0`, where\n`Rᵢ ∈ {<, ≤, =}` and each `tᵢ` is of the form `∑ cⱼxⱼ`.\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ᵢ` such that `∑ kᵢtᵢ = 0`, where for\nat least one `i`, `kᵢ > 0` and `Rᵢ = <`.\n\nGiven a list of such coefficients, `linarith` verifies that `∑ kᵢtᵢ = 0` using a normalization\ntactic such as `ring`. It proves that `∑ kᵢtᵢ < 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₀`.\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 ≠ 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 → ℕ → tactic (rb_map ℕ ℕ)`,\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\nopen tactic native\n\nnamespace linarith\n\n/-! ### Control -/\n\n/--\nIf `e` is a comparison `a R b` or the negation of a comparison `¬ 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 : ℕ) < b`, returns ``(`lt_of_not_ge, ℕ)``.\n-/\nmeta def get_contr_lemma_name_and_type : expr → option (name × expr)\n| `(@has_lt.lt %%tp %%_ _ _) := return (`lt_of_not_ge, tp)\n| `(@has_le.le %%tp %%_ _ _) := return (`le_of_not_gt, tp)\n| `(@eq %%tp _ _) := return (``eq_of_not_lt_of_not_gt, tp)\n| `(@ne %%tp _ _) := return (`not.intro, tp)\n| `(@ge %%tp %%_ _ _) := return (`le_of_not_gt, tp)\n| `(@gt %%tp %%_ _ _) := return (`lt_of_not_ge, tp)\n| `(¬ @has_lt.lt %%tp %%_ _ _) := return (`not.intro, tp)\n| `(¬ @has_le.le %%tp %%_ _ _) := return (`not.intro, tp)\n| `(¬ @eq %%tp _ _) := return (``not.intro, tp)\n| `(¬ @ge %%tp %%_ _ _) := return (`not.intro, tp)\n| `(¬ @gt %%tp %%_ _ _) := return (`not.intro, tp)\n| _ := none\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 `⊢ a ≤ b` can become `a > b ⊢ 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-/\nmeta def apply_contr_lemma : tactic (option (expr × expr)) :=\ndo t ← target,\n   match get_contr_lemma_name_and_type t with\n   | some (nm, tp) :=\n     do refine ((expr.const nm []) pexpr.mk_placeholder), v ← intro1, return $ some (tp, v)\n   | none := return none\n   end\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 : ℚ) < 1` and `(b : ℤ) > c` will be separated.\nReturns a map from a type to a list of comparisons over that type.\n-/\nmeta def partition_by_type (l : list expr) : tactic (rb_lmap expr expr) :=\nl.mfoldl (λ m h, do tp ← ineq_prf_tp h, return $ m.insert tp h) mk_rb_map\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-/\nmeta def try_linarith_on_lists (cfg : linarith_config) (ls : list (list expr)) : tactic expr :=\n(first $ ls.map $ prove_false_by_linarith cfg) <|> fail \"linarith failed to find a contradiction\"\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-/\nmeta def run_linarith_on_pfs (cfg : linarith_config) (hyps : list expr) (pref_type : option expr) :\n  tactic unit :=\nlet single_process := λ hyps : list expr, do\n   linarith_trace_proofs\n     (\"after preprocessing, linarith has \" ++ to_string hyps.length ++ \" facts:\") hyps,\n   hyp_set ← partition_by_type hyps,\n   linarith_trace format!\"hypotheses appear in {hyp_set.size} different types\",\n   match pref_type with\n   | some t := prove_false_by_linarith cfg (hyp_set.ifind t) <|>\n               try_linarith_on_lists cfg (rb_map.values (hyp_set.erase t))\n   | none := try_linarith_on_lists cfg (rb_map.values hyp_set)\n   end in\nlet preprocessors := cfg.preprocessors.get_or_else default_preprocessors,\n    preprocessors := if cfg.split_ne then linarith.remove_ne::preprocessors else preprocessors in\ndo hyps ← preprocess preprocessors hyps,\nhyps.mmap' $ λ hs, do set_goals [hs.1], single_process hs.2 >>= exact\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-/\nmeta def filter_hyps_to_type (restr_type : expr) (hyps : list expr) : tactic (list expr) :=\nhyps.mfilter $ λ h, do\n  ht ← infer_type h,\n  match get_contr_lemma_name_and_type ht with\n  | some (_, htype) := succeeds $ unify htype restr_type\n  | none := return ff\n  end\n\n/-- A hack to allow users to write `{restr_type := ℚ}` in configuration structures. -/\nmeta def get_restrict_type (e : expr) : tactic expr :=\ndo m ← mk_mvar,\n   unify `(some %%m : option Type) e,\n   instantiate_mvars m\n\nend linarith\n\n/-! ### User facing functions -/\n\nopen linarith\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-/\nmeta def tactic.linarith (reduce_semi : bool) (only_on : bool) (hyps : list pexpr)\n  (cfg : linarith_config := {}) : tactic unit :=\nfocus1 $\ndo t ← target,\n-- if the target is an equality, we run `linarith` twice, to prove ≤ and ≥.\nif t.is_eq.is_some then\n  linarith_trace \"target is an equality: splitting\" >>\n    seq' (applyc ``eq_of_not_lt_of_not_gt) tactic.linarith else\ndo hyps ← hyps.mmap $ λ e, i_to_expr e >>= note_anon none,\n   when cfg.split_hypotheses (linarith_trace \"trying to split hypotheses\" >> try auto.split_hyps),\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   pref_type_and_new_var_from_tgt ← apply_contr_lemma,\n   when pref_type_and_new_var_from_tgt.is_none $\n     if cfg.exfalso then linarith_trace \"using exfalso\" >> exfalso\n     else fail \"linarith failed: target is not a valid comparison\",\n   let cfg := cfg.update_reducibility reduce_semi,\n   let (pref_type, new_var) :=\n     pref_type_and_new_var_from_tgt.elim (none, none) (prod.map some some),\n   -- set up the list of hypotheses, considering the `only_on` and `restrict_type` options\n   hyps ← if only_on then return (new_var.elim [] singleton ++ hyps)\n          else (++ hyps) <$> local_context,\n   hyps ← (do t ← get_restrict_type cfg.restrict_type_reflect, filter_hyps_to_type t hyps) <|>\n     return hyps,\n   linarith_trace_proofs \"linarith is running on the following hypotheses:\" hyps,\n   run_linarith_on_pfs cfg hyps pref_type\n\nsetup_tactic_parser\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-/\nmeta def tactic.interactive.linarith (red : parse ((tk \"!\")?))\n  (restr : parse ((tk \"only\")?)) (hyps : parse pexpr_list?)\n  (cfg : linarith_config := {}) : tactic unit :=\ntactic.linarith red.is_some restr.is_some (hyps.get_or_else []) cfg\n\nadd_hint_tactic \"linarith\"\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 : ℚ) (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 : ℚ) : id x ≥ 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-/\nadd_tactic_doc\n{ name       := \"linarith\",\n  category   := doc_category.tactic,\n  decl_names := [`tactic.interactive.linarith],\n  tags       := [\"arithmetic\", \"decision procedure\", \"finishing\"] }\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 ≤ a ^ 2` or `0 ≤ a * a` is added to the context.\n* For every pair of hypotheses `a1 R1 b1`, `a2 R2 b2` in the context, `R1, R2 ∈ {<, ≤, =}`,\n  the assumption `0 R' (b1 - a1) * (b2 - a2)` is added to the context (non-recursively),\n  where `R ∈ {<, ≤, =}` is the appropriate comparison derived from `R1, R2`.\n-/\nmeta def tactic.interactive.nlinarith (red : parse ((tk \"!\")?))\n  (restr : parse ((tk \"only\")?)) (hyps : parse pexpr_list?)\n  (cfg : linarith_config := {}) : tactic unit :=\ntactic.linarith red.is_some restr.is_some (hyps.get_or_else [])\n  { cfg with preprocessors := some $\n      cfg.preprocessors.get_or_else default_preprocessors ++ [nlinarith_extras] }\n\nadd_hint_tactic \"nlinarith\"\n\nadd_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": "mathlib", "sha": "5e526d18cea33550268dcbbddcb822d5cde40654", "save_path": "github-repos/lean/leanprover-community-mathlib", "path": "github-repos/lean/leanprover-community-mathlib/mathlib-5e526d18cea33550268dcbbddcb822d5cde40654/src/tactic/linarith/frontend.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625003089676, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7549307149817179}}
{"text": "-- Suma_de_progresion_geometrica.lean\n-- Suma de progresión geométrica\n-- José A. Alonso Jiménez\n-- Sevilla, 20 de septiembre de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que la suma de los términos de la progresión geomética\n--    a + aq + aq² + ··· + aqⁿ\n-- es\n--      a(1 - qⁿ⁺¹)\n--    --------------\n--        1 - q\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\nopen nat\n\nvariable  (n : ℕ)\nvariables (a q : ℝ)\n\nset_option pp.structure_projections false\n\n@[simp]\ndef sumaPG : ℝ → ℝ → ℕ → ℝ\n| a q 0       := a\n| a q (n + 1) := sumaPG a q n + (a * q^(n + 1))\n\nexample :\n  (1 - q) * sumaPG a q n = a * (1 - q^(n + 1)) :=\nbegin\n  induction n with n HI,\n  { simp,\n    ac_refl, },\n  { calc (1 - q) * sumaPG a q (succ n)\n         = (1 - q) * (sumaPG a q n + (a * q^(n + 1)))\n           : rfl\n     ... = (1 - q) * sumaPG a q n + (1 - q) * (a * q^(n + 1))\n           : by ring_nf\n     ... = a * (1 - q ^ (n + 1)) + (1 - q) * (a * q^(n + 1))\n           : by {congr ; rw HI}\n     ... = a * (1 - q ^ (succ n + 1))\n           : by ring_nf },\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_geometrica.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7549307128027983}}
{"text": "import data.real.basic\nimport tactic\nopen function real\n\nnamespace vilnius\n\n\n/-- Composite of two injective functions is injective -/\ntheorem injective_comp (X Y Z : Type) (f : X → Y) (g : Y → Z) \n  (hf : injective f) (hg : injective g) : injective (g ∘ f) :=\nbegin\n  sorry,\nend\n\n/- ### The λ notation:\nIn Lean (or in Type Theory, rather) the way to define a function is to use λ expressions: here, you should think that `λ = ∀`: so, the function\n`λ x, 3*x ^ 2 + 1`\nis nothing else that the function\n`f(x)=3*x ^ 2 + 1` or `f : x ↦ 3*x ^ 2 + 1`.\n\nAs for usual functions, the name of the variable does not matter, so\n`λ x, 3*x ^ 2 + 1` is the same as `λ w, 3*w ^ 2 + 1` \n\nThe tactic to get rid of a `λ` term is\n* `simp only` (possibly: at h)\nbecause it \"evaluates a λ-term\", transforming, for instance\n`(λ x, 2 * x + 1) 3` into `2 * 3 + 1`.\n-/\n\ntheorem injective_id (X : Type) : injective (λ x : X, x) :=\nbegin\n  sorry,\nend\n\n\ndefinition is_linear (f : ℝ → ℝ) : Prop := ∀ c x y, f (c * x + y) = c * f (x) + f(y) \n\n/-- ## The tactics have and rewrite (rw)\n* have (h) : It allows to introduce a claim, called h. After, you need to prove it. This states the (to be proven) existence of a term whose type is the RHS.\nThere exists also\n* have (h) := This gives the name h to the term on the right.\n-/\n\n\ntheorem linear_at_0 (f : ℝ → ℝ) (H : is_linear f) : f 0 = 0 :=\nbegin\n  sorry,\nend\n\n/-- The tactic\n* `use a` specializes an existential quantifier at x\n* `ext`: the \"extensionality rule\": two functions f,  g are equal if and only if for all x, f x = g x\n-/\n\ntheorem linear_explicit (f : ℝ → ℝ) (H : is_linear f) : ∃ a, f = λ x, a * x :=\nbegin\n  sorry,\nend\n\ndefinition is_affine (f : ℝ → ℝ) : Prop := ∃ a, ∀ x y, f (y) - f(x) = a * (y - x)\n\ntheorem linear_add_cnst_of_affine (f : ℝ → ℝ) : is_affine f → (∃ a : ℝ, ∃ g : ℝ → ℝ, (f = g + (λ x, a)) ∧ is_linear g) :=\nbegin\n  sorry,\nend\n\ntheorem affine_of_linear_add_cnst (f : ℝ → ℝ) : (∃ b : ℝ, ∃ g : ℝ → ℝ,\n  (f = g + (λ x, b)) ∧ is_linear g) → is_affine f :=\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/Course.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.8670357735451835, "lm_q1q2_score": 0.7548389877049183}}
{"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\nimport data.list.chain\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 `≤`-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\nnamespace list\n\n/-!\n### The predicate `list.sorted`\n-/\n\nsection sorted\nuniverse variable uu\nvariables {α : Type uu} {r : α → α → Prop}\n\n/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`\n  is a `<` or `≤`-like relation (transitive and antisymmetric or asymmetric) -/\ndef sorted := @pairwise\n\ninstance decidable_sorted [decidable_rel r] (l : list α) : decidable (sorted r l) :=\nlist.decidable_pairwise _\n\n@[simp] theorem sorted_nil : sorted r [] := pairwise.nil\n\ntheorem sorted_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) → sorted r l :=\npairwise_of_pairwise_cons\n\ntheorem sorted.tail {r : α → α → Prop} {l : list α} (h : sorted r l) : sorted r l.tail :=\nh.tail\n\ntheorem rel_of_sorted_cons {a : α} {l : list α} : sorted r (a :: l) →\n  ∀ b ∈ l, r a b :=\nrel_of_pairwise_cons\n\n@[simp] theorem sorted_cons {a : α} {l : list α} :\n  sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ sorted r l :=\npairwise_cons\n\nprotected theorem sorted.nodup {r : α → α → Prop} [is_irrefl α r] {l : list α} (h : sorted r l) :\n  nodup l :=\nh.nodup\n\ntheorem eq_of_perm_of_sorted [is_antisymm α r]\n  {l₁ l₂ : list α} (p : l₁ ~ l₂) (s₁ : sorted r l₁) (s₂ : sorted r l₂) : l₁ = l₂ :=\nbegin\n  induction s₁ with a l₁ h₁ s₁ IH generalizing l₂,\n  { exact p.nil_eq },\n  { have : a ∈ l₂ := p.subset (mem_cons_self _ _),\n    rcases mem_split this with ⟨u₂, v₂, rfl⟩,\n    have p' := (perm_cons a).1 (p.trans perm_middle),\n    have := IH p' (pairwise_of_sublist (by simp) s₂), subst l₁,\n    change a::u₂ ++ v₂ = u₂ ++ ([a] ++ v₂), rw ← append_assoc, congr,\n    have : ∀ (x : α) (h : x ∈ u₂), x = a := λ x m,\n      antisymm ((pairwise_append.1 s₂).2.2 _ m a (mem_cons_self _ _))\n        (h₁ _ (by simp [m])),\n    rw [(@eq_repeat _ a (length u₂ + 1) (a::u₂)).2,\n        (@eq_repeat _ a (length u₂ + 1) (u₂++[a])).2];\n    split; simp [iff_true_intro this, or_comm] }\nend\n\n@[simp] theorem sorted_singleton (a : α) : sorted r [a] := pairwise_singleton _ _\n\nlemma sorted.rel_nth_le_of_lt {l : list α}\n  (h : l.sorted r) {a b : ℕ} (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 α r] {l : list α}\n  (h : l.sorted r) {a b : ℕ} (ha : a < l.length) (hb : b < l.length) (hab : a ≤ 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 α} (h : list.sorted r l)\n  {k : ℕ} {x y : α} (hx : x ∈ list.take k l) (hy : y ∈ list.drop k l) :\n  r x y :=\nbegin\n  obtain ⟨iy, hiy, rfl⟩ := nth_le_of_mem hy,\n  obtain ⟨ix, hix, rfl⟩ := 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\nuniverse variable uu\nvariables {α : Type uu} (r : α → α → Prop) [decidable_rel r]\nlocal infix ` ≼ ` : 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 : α) : list α → list α\n| []       := [a]\n| (b :: l) := if a ≼ 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 α → list α\n| []       := []\n| (b :: l) := ordered_insert r b (insertion_sort l)\n\n@[simp] lemma ordered_insert_nil (a : α) : [].ordered_insert r a = [a] := rfl\n\ntheorem ordered_insert_length : Π (L : list α) (a : α), (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 : α) : ∀ l : list α,\n  l.ordered_insert r a = l.take_while (λ b, ¬(a ≼ b)) ++ (a :: l.drop_while (λ b, ¬(a ≼ 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 : α) (l : list α) :\n  insertion_sort r (a :: l) = (insertion_sort r l).take_while (λ b, ¬(a ≼ b)) ++\n    (a :: (insertion_sort r l).drop_while (λ b, ¬(a ≼ b))) :=\nordered_insert_eq_take_drop r a _\n\nsection correctness\nopen perm\n\ntheorem perm_ordered_insert (a) : ∀ l : list α, ordered_insert r a l ~ a :: l\n| []       := perm.refl _\n| (b :: l) := by by_cases a ≼ 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 α] (L : list α) (a b : α) :\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 : ∀ l : list α, 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 : ∀ {l : list α} (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 α r] [is_trans α r]\n\ntheorem sorted.ordered_insert (a : α) : ∀ l, sorted r l → sorted r (ordered_insert r a l)\n| []       h := sorted_singleton a\n| (b :: l) h := begin\n  by_cases h' : a ≼ b,\n  { simpa [ordered_insert, h', h] using λ b' bm, trans h' (rel_of_sorted_cons h _ bm) },\n  { suffices : ∀ (b' : α), b' ∈ ordered_insert r a l → r b b',\n    { simpa [ordered_insert, h', (sorted_of_sorted_cons h).ordered_insert l] },\n    intros b' bm,\n    cases (show b' = a ∨ b' ∈ 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 : ∀ 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 α → list α × list α\n| []       := ([], [])\n| (a :: l) := let (l₁, l₂) := split l in (a :: l₂, l₁)\n\ntheorem split_cons_of_eq (a : α) {l l₁ l₂ : list α} (h : split l = (l₁, l₂)) :\n  split (a :: l) = (a :: l₂, l₁) :=\nby rw [split, h]; refl\n\ntheorem length_split_le : ∀ {l l₁ l₂ : list α},\n  split l = (l₁, l₂) → length l₁ ≤ length l ∧ length l₂ ≤ length l\n| []     ._  ._  rfl := ⟨nat.le_refl 0, nat.le_refl 0⟩\n| (a::l) l₁' l₂' h   := begin\n  cases e : split l with l₁ l₂,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂',\n  cases length_split_le e with h₁ h₂,\n  exact ⟨nat.succ_le_succ h₂, nat.le_succ_of_le h₁⟩\nend\n\ntheorem length_split_lt {a b} {l l₁ l₂ : list α} (h : split (a::b::l) = (l₁, l₂)) :\n  length l₁ < length (a::b::l) ∧ length l₂ < length (a::b::l) :=\nbegin\n  cases e : split l with l₁' l₂',\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs l₁ l₂,\n  cases length_split_le e with h₁ h₂,\n  exact ⟨nat.succ_le_succ (nat.succ_le_succ h₁), nat.succ_le_succ (nat.succ_le_succ h₂)⟩\nend\n\ntheorem perm_split : ∀ {l l₁ l₂ : list α}, split l = (l₁, l₂) → l ~ l₁ ++ l₂\n| []     ._  ._  rfl := perm.refl _\n| (a::l) l₁' l₂' h   := begin\n  cases e : split l with l₁ l₂,\n  injection (split_cons_of_eq _ e).symm.trans h, substs l₁' l₂',\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 α → list α → list α\n| []       l'        := l'\n| l        []        := l\n| (a :: l) (b :: l') := if a ≼ 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 α → list α\n| []        := []\n| [a]       := [a]\n| (a::b::l) := begin\n  cases e : split (a::b::l) with l₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  exact merge r (merge_sort l₁) (merge_sort l₂)\nend\nusing_well_founded {\n  rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_cons_cons {a b} {l l₁ l₂ : list α}\n  (h : split (a::b::l) = (l₁, l₂)) :\n  merge_sort r (a::b::l) = merge r (merge_sort r l₁) (merge_sort r l₂) :=\nbegin\n  suffices : ∀ (L : list α) h1, @@and.rec\n    (λ a a (_ : length l₁ < length l + 1 + 1 ∧\n      length l₂ < 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 : ∀ (l l' : list α), 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 ≼ 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 : ∀ l : list α, 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₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  rw [merge_sort_cons_cons r e],\n  apply (perm_merge r _ _).trans,\n  exact ((perm_merge_sort l₁).append (perm_merge_sort l₂)).trans (perm_split e).symm\nend\nusing_well_founded {\n  rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\n@[simp] lemma length_merge_sort (l : list α) : (merge_sort r l).length = l.length :=\n(perm_merge_sort r _).length_eq\n\nsection total_and_transitive\nvariables {r} [is_total α r] [is_trans α r]\n\ntheorem sorted.merge : ∀ {l l' : list α}, sorted r l → sorted r l' → sorted r (merge r l l')\n| []       []        h₁ h₂ := by simp [merge]\n| []       (b :: l') h₁ h₂ := by simpa [merge] using h₂\n| (a :: l) []        h₁ h₂ := by simpa [merge] using h₁\n| (a :: l) (b :: l') h₁ h₂ := begin\n  by_cases a ≼ b,\n  { suffices : ∀ (b' : α) (_ : b' ∈ merge r l (b :: l')), r a b',\n    { simpa [merge, h, (sorted_of_sorted_cons h₁).merge h₂] },\n    intros b' bm,\n    rcases (show b' = b ∨ b' ∈ l ∨ b' ∈ 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₁ _ bl },\n    { exact trans h (rel_of_sorted_cons h₂ _ bl') } },\n  { suffices : ∀ (b' : α) (_ : b' ∈ merge r (a :: l) l'), r b b',\n    { simpa [merge, h, h₁.merge (sorted_of_sorted_cons h₂)] },\n    intros b' bm,\n    have ba : b ≼ a := (total_of r _ _).resolve_left h,\n    rcases (show b' = a ∨ b' ∈ l ∨ b' ∈ 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₁ _ bl) },\n    { exact rel_of_sorted_cons h₂ _ bl' } }\nend\n\nvariable (r)\n\ntheorem sorted_merge_sort : ∀ l : list α, 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₁ l₂,\n  cases length_split_lt e with h₁ h₂,\n  rw [merge_sort_cons_cons r e],\n  exact (sorted_merge_sort l₁).merge (sorted_merge_sort l₂)\nend\nusing_well_founded {\n  rel_tac := λ_ _, `[exact ⟨_, inv_image.wf length nat.lt_wf⟩],\n  dec_tac := tactic.assumption }\n\ntheorem merge_sort_eq_self [is_antisymm α r] {l : list α} : sorted r l → 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 α r] (l : list α) :\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\nend merge_sort\nend sort\n\n/- try them out! -/\n\n--#eval insertion_sort (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n\n--#eval merge_sort     (λ m n : ℕ, m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\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/sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7547759582199278}}
{"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.ordered.basic\n\n/-!\n# Bounded monotone sequences converge\n\nIn this file we prove a few theorems of the form “if the range of a monotone function `f : ι → α`\nadmits a least upper bound `a`, then `f x` tends to `a` as `x → ∞`”, as well as version of this\nstatement for (conditionally) complete lattices that use `⨆ 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 ≤ a` for all `n`.\n\n## Tags\n\nmonotone convergence\n-/\n\nopen filter set function\nopen_locale filter topological_space classical\n\nvariables {α β : Type*}\n\n/-- We say that `α` is a `Sup_convergence_class` if the following holds. Let `f : ι → α` be a\nmonotone function, let `a : α` be a least upper bound of `set.range f`. Then `f x` tends to `𝓝 a` as\n`x → ∞` (formally, at the filter `filter.at_top`). We require this for `ι = (s : set α)`, `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 (α : Type*) [preorder α] [topological_space α] : Prop :=\n(tendsto_coe_at_top_is_lub : ∀ (a : α) (s : set α), is_lub s a → tendsto (coe : s → α) at_top (𝓝 a))\n\n/-- We say that `α` is an `Inf_convergence_class` if the following holds. Let `f : ι → α` be a\nmonotone function, let `a : α` be a greatest lower bound of `set.range f`. Then `f x` tends to `𝓝 a`\nas `x → -∞` (formally, at the filter `filter.at_bot`). We require this for `ι = (s : set α)`,\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 (α : Type*) [preorder α] [topological_space α] : Prop :=\n(tendsto_coe_at_bot_is_glb : ∀ (a : α) (s : set α), is_glb s a → tendsto (coe : s → α) at_bot (𝓝 a))\n\ninstance order_dual.Sup_convergence_class [preorder α] [topological_space α]\n  [Inf_convergence_class α] : Sup_convergence_class (order_dual α) :=\n⟨‹Inf_convergence_class α›.1⟩\n\ninstance order_dual.Inf_convergence_class [preorder α] [topological_space α]\n  [Sup_convergence_class α] : Inf_convergence_class (order_dual α) :=\n⟨‹Sup_convergence_class α›.1⟩\n\n@[priority 100] -- see Note [lower instance priority]\ninstance linear_order.Sup_convergence_class [topological_space α] [linear_order α]\n  [order_topology α] : Sup_convergence_class α :=\nbegin\n  refine ⟨λ a s ha, tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩⟩,\n  { rcases ha.exists_between hb with ⟨c, hcs, bc, bca⟩,\n    lift c to s using hcs,\n    refine (eventually_ge_at_top c).mono (λ x hx, bc.trans_le hx) },\n  { exact eventually_of_forall (λ 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 α] [linear_order α]\n  [order_topology α] : Inf_convergence_class α :=\nshow Inf_convergence_class (order_dual $ order_dual α), from order_dual.Inf_convergence_class\n\nsection\n\nvariables {ι : Type*} [preorder ι] [topological_space α]\n\nsection is_lub\n\nvariables [preorder α] [Sup_convergence_class α] {f : ι → α} {a : α}\n\nlemma tendsto_at_top_is_lub (h_mono : monotone f) (ha : is_lub (set.range f) a) :\n  tendsto f at_top (𝓝 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 (λ b, b.2.imp $ λ 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 (𝓝 a) :=\n@tendsto_at_top_is_lub α (order_dual ι) _ _ _ _ f a h_anti.dual ha\n\nend is_lub\n\nsection is_glb\n\nvariables [preorder α] [Inf_convergence_class α] {f : ι → α} {a : α}\n\nlemma tendsto_at_bot_is_glb (h_mono : monotone f) (ha : is_glb (set.range f) a) :\n  tendsto f at_bot (𝓝 a) :=\n@tendsto_at_top_is_lub (order_dual α) (order_dual ι) _ _ _ _ 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 (𝓝 a) :=\n@tendsto_at_top_is_lub (order_dual α) ι _ _ _ _ f a h_anti ha\n\nend is_glb\n\nsection csupr\n\nvariables [conditionally_complete_lattice α] [Sup_convergence_class α] {f : ι → α} {a : α}\n\nlemma tendsto_at_top_csupr (h_mono : monotone f) (hbdd : bdd_above $ range f) :\n  tendsto f at_top (𝓝 (⨆i, f i)) :=\nbegin\n  casesI is_empty_or_nonempty ι,\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 (𝓝 (⨆i, f i)) :=\n@tendsto_at_top_csupr α (order_dual ι) _ _ _ _ _ h_anti.dual hbdd\n\nend csupr\n\nsection cinfi\n\nvariables [conditionally_complete_lattice α] [Inf_convergence_class α] {f : ι → α} {a : α}\n\nlemma tendsto_at_bot_cinfi (h_mono : monotone f) (hbdd : bdd_below $ range f) :\n  tendsto f at_bot (𝓝 (⨅i, f i)) :=\n@tendsto_at_top_csupr (order_dual α) (order_dual ι) _ _ _ _ _ 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 (𝓝 (⨅i, f i)) :=\n@tendsto_at_top_csupr (order_dual α) ι _ _ _ _ _ h_anti hbdd\n\nend cinfi\n\nsection supr\n\nvariables [complete_lattice α] [Sup_convergence_class α] {f : ι → α} {a : α}\n\nlemma tendsto_at_top_supr (h_mono : monotone f) : tendsto f at_top (𝓝 (⨆i, 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 (𝓝 (⨆i, f i)) :=\ntendsto_at_bot_csupr h_anti (order_top.bdd_above _)\n\nend supr\n\nsection infi\n\nvariables [complete_lattice α] [Inf_convergence_class α] {f : ι → α} {a : α}\n\nlemma tendsto_at_bot_infi (h_mono : monotone f) : tendsto f at_bot (𝓝 (⨅i, 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 (𝓝 (⨅i, f i)) :=\ntendsto_at_top_cinfi h_anti (order_bot.bdd_below _)\n\nend infi\n\nend\n\ninstance [preorder α] [preorder β] [topological_space α] [topological_space β]\n  [Sup_convergence_class α] [Sup_convergence_class β] : Sup_convergence_class (α × β) :=\nbegin\n  constructor,\n  rintro ⟨a, b⟩ s h,\n  rw [is_lub_prod, ← range_restrict, ← range_restrict] at h,\n  have A : tendsto (λ x : s, (x : α × β).1) at_top (𝓝 a),\n    from tendsto_at_top_is_lub (monotone_fst.restrict s) h.1,\n  have B : tendsto (λ x : s, (x : α × β).2) at_top (𝓝 b),\n    from tendsto_at_top_is_lub (monotone_snd.restrict s) h.2,\n  convert A.prod_mk_nhds B,\n  ext1 ⟨⟨x, y⟩, h⟩, refl\nend\n\ninstance [preorder α] [preorder β] [topological_space α] [topological_space β]\n  [Inf_convergence_class α] [Inf_convergence_class β] : Inf_convergence_class (α × β) :=\nshow Inf_convergence_class (order_dual $ (order_dual α × order_dual β)),\n  from order_dual.Inf_convergence_class\n\ninstance {ι : Type*} {α : ι → Type*} [Π i, preorder (α i)] [Π i, topological_space (α i)]\n  [Π i, Sup_convergence_class (α i)] : Sup_convergence_class (Π i, α i) :=\nbegin\n  refine ⟨λ f s h, _⟩,\n  simp only [is_lub_pi, ← range_restrict] at h,\n  exact tendsto_pi_nhds.2 (λ i, tendsto_at_top_is_lub ((monotone_eval _).restrict _) (h i))\nend\n\ninstance {ι : Type*} {α : ι → Type*} [Π i, preorder (α i)] [Π i, topological_space (α i)]\n  [Π i, Inf_convergence_class (α i)] : Inf_convergence_class (Π i, α i) :=\nshow Inf_convergence_class (order_dual $ Π i, order_dual (α i)),\n  from order_dual.Inf_convergence_class\n\ninstance pi.Sup_convergence_class' {ι : Type*} [preorder α] [topological_space α]\n  [Sup_convergence_class α] : Sup_convergence_class (ι → α) :=\npi.Sup_convergence_class\n\ninstance pi.Inf_convergence_class' {ι : Type*} [preorder α] [topological_space α]\n  [Inf_convergence_class α] : Inf_convergence_class (ι → α) :=\npi.Inf_convergence_class\n\nlemma tendsto_of_monotone {ι α : Type*} [preorder ι] [topological_space α]\n  [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :\n  tendsto f at_top at_top ∨ (∃ l, tendsto f at_top (𝓝 l)) :=\nif H : bdd_above (range f) then or.inr ⟨_, tendsto_at_top_csupr h_mono H⟩\nelse or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H\n\nlemma tendsto_iff_tendsto_subseq_of_monotone {ι₁ ι₂ α : Type*} [semilattice_sup ι₁] [preorder ι₂]\n  [nonempty ι₁] [topological_space α] [conditionally_complete_linear_order α] [order_topology α]\n  [no_top_order α] {f : ι₂ → α} {φ : ι₁ → ι₂} {l : α} (hf : monotone f)\n  (hg : tendsto φ at_top at_top) :\n  tendsto f at_top (𝓝 l) ↔ tendsto (f ∘ φ) at_top (𝓝 l) :=\nbegin\n  split; intro h,\n  { exact h.comp hg },\n  { rcases tendsto_of_monotone hf with h' | ⟨l', hl'⟩,\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` and `supr_eq_of_tendsto`, are converses\nto the standard fact that bounded monotone functions converge. They state, that if a monotone\nfunction `f` tends to `a` along `at_top`, then that value `a` is a least upper bound for the range\nof `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 {α β : Type*} [topological_space α] [preorder α]\n  [order_closed_topology α] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f)\n  (ha : tendsto f at_top (𝓝 a)) (b : β) :\n  f b ≤ a :=\nbegin\n  haveI : nonempty β := nonempty.intro b,\n  exact ge_of_tendsto ha ((eventually_ge_at_top b).mono (λ _ hxy, hf hxy))\nend\n\nlemma monotone.le_of_tendsto {α β : Type*} [topological_space α] [preorder α]\n  [order_closed_topology α] [semilattice_inf β] {f : β → α} {a : α} (hf : monotone f)\n  (ha : tendsto f at_bot (𝓝 a)) (b : β) :\n  a ≤ f b :=\n@monotone.ge_of_tendsto (order_dual α) (order_dual β) _ _ _ _ f _ hf.dual ha b\n\nlemma is_lub_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α]\n  [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f)\n  (ha : tendsto f at_top (𝓝 a)) :\n  is_lub (set.range f) a :=\nbegin\n  split,\n  { rintros _ ⟨b, rfl⟩,\n    exact hf.ge_of_tendsto ha b },\n  { exact λ _ hb, le_of_tendsto' ha (λ x, hb (set.mem_range_self x)) }\nend\n\nlemma is_glb_of_tendsto {α β : Type*} [topological_space α] [preorder α] [order_closed_topology α]\n  [nonempty β] [semilattice_inf β] {f : β → α} {a : α} (hf : monotone f)\n  (ha : tendsto f at_bot (𝓝 a)) :\n  is_glb (set.range f) a :=\n@is_lub_of_tendsto (order_dual α) (order_dual β) _ _ _ _ _ _ _ hf.dual ha\n\nlemma supr_eq_of_tendsto {α β} [topological_space α] [complete_linear_order α] [order_topology α]\n  [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) :\n  tendsto f at_top (𝓝 a) → supr f = a :=\ntendsto_nhds_unique (tendsto_at_top_supr hf)\n\nlemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [order_topology α]\n  [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : antitone f) :\n  tendsto f at_top (𝓝 a) → infi f = a :=\ntendsto_nhds_unique (tendsto_at_top_infi hf)\n\nlemma supr_eq_supr_subseq_of_monotone {ι₁ ι₂ α : Type*} [preorder ι₂] [complete_lattice α]\n  {l : filter ι₁} [l.ne_bot] {f : ι₂ → α} {φ : ι₁ → ι₂} (hf : monotone f)\n  (hφ : tendsto φ l at_top) :\n  (⨆ i, f i) = (⨆ i, f (φ i)) :=\nle_antisymm\n  (supr_le_supr2 $ λ i, exists_imp_exists (λ j (hj : i ≤ φ j), hf hj)\n    (hφ.eventually $ eventually_ge_at_top i).exists)\n  (supr_le_supr2 $ λ i, ⟨φ i, le_refl _⟩)\n\nlemma infi_eq_infi_subseq_of_monotone {ι₁ ι₂ α : Type*} [preorder ι₂] [complete_lattice α]\n  {l : filter ι₁} [l.ne_bot] {f : ι₂ → α} {φ : ι₁ → ι₂} (hf : monotone f)\n  (hφ : tendsto φ l at_bot) :\n  (⨅ i, f i) = (⨅ i, f (φ i)) :=\nsupr_eq_supr_subseq_of_monotone hf.dual hφ\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/monotone_convergence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.75477594816993}}
{"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 1 : \"forall\" (`∀`)\n\nA lot of questions about sets can be reduced to questions about logic.\nWe explain how to do this in Lean.\n\nAll the sets we consider on this and the next few sheets will all be\nsubsets of an underlying set `X`, which is our \"universe\" where all\nthe maths we do will take place. This underlying set `X` is called a \"type\" in\nLean. It plays the role of a \"universe\" -- every element we consider will\nalways be an element of `X`, and every subset we consider will\nbe a subset of `X`.\n\nNotation: elements of `X` are called *terms* of the type `X` and the\nnotation is `x : X`. All the variables `x`, `y` and `z` which appear in this\nsheet will always be terms of type `X`, i.e. elements of the set `X`\nif you want to think set-theoretically.\n\nAll the sets `A`, `B`, `C` etc we consider will be subsets of `X`. \nIf `x : X` then `x` may or may not be an element of `A`, `B`, `C`,\nbut it will always be an element of `X`.\n\n## Tactics\n\nTactics you will need to know for this sheet:\n\n* `intro` (it works for `∀` goals as well as for `P → Q`)\n* `specialize`\n\n### The `intro` tactic\n\nIf the goal is `∀ x, P(x)` then `intro a,` lets `a` be an arbitrary\nelement of `X` (or, more precisely, an arbitrary term of type `X`)\nand changes the goal to `P(a)`.\n\n### The `specialize` tactic\n\nIf we have a hypothesis `h : ∀ x, P(x)` and we have a term `a : X`\nthen `specialize h a,` changes `h` to `h : P(a)`.\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-- You can start this one with `intro x`\nexample : ∀ x : X, x ∈ A → x ∈ A :=\nbegin\n  sorry,\nend\n\nexample : ∀ x : X, (x ∈ A ∧ x ∈ B) → x ∈ A :=\nbegin\n  sorry\nend\n\n-- for this one if you start with `intros h x` then you might well\n-- need `specialize h x` later on. This is how to use hypotheses with `∀` in.\nexample : (∀ x, x ∈ A ∧ x ∈ B) → (∀ x, x ∈ A) :=\nbegin\n  sorry\nend\n\nexample : (∀ x, x ∈ A ∧ x ∈ B) → (∀ y, y ∈ B ∧ y ∈ A) :=\nbegin\n  sorry\nend\n\nexample : (∀ x, x ∈ A → x ∈ B) → (∀ y, y ∈ B → y ∈ C) →\n  (∀ z, z ∈ A → z ∈ C) :=\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/2021/sets/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7546874370118934}}
{"text": "import tactic\nimport data.matrix.basic\nimport data.matrix.block\nimport linear_algebra.matrix.block\nimport linear_algebra.matrix.nonsingular_inverse\nimport algebra.group.units\nimport order.well_founded\nimport algebra.big_operators.basic\n\n-- allows notation for matrix multiplication and summations\nopen_locale matrix\nopen_locale big_operators\n\n/-\nCurrently, whole framework is for a Eucldiean Domains (some results could be weakened to PID or even weaker), and later lemmas have been restriced to nxn matrices rather than nxm\n-/\n\n-- # Elementary Matrices\n/-\nDefines the basis matrix, all zero's except for a 1 in the (i, j)'th entry and three elementary matrices\nLeft multiplication acts on rows, right multiplication acts on columns, but the effect of the elementary matrices is expressed as lemmas later\n\n* `add_mult n i j a` - is the matrix that (via multiplication) induces the map which adds `a` times row/column `i` to row/column `j`\n* `mul_by_unit n i u` - induces a similar map which multiplies row/column `i` by `u`\n-/\n\n-- ## Definiton of the Elementary Matrices\n\nnamespace elem_matrix\n\n-- Basis Δ (as called in Jacobson)\ndef basis (R : Type*) [euclidean_domain R] (n : ℕ) (i j : fin n) : matrix (fin n) (fin n) R :=\n(λ i' j', if i = i' ∧ j = j' then 1 else 0)\n\n-- Type I: Add multiple of column/row i to j\ndef add_mult {R : Type*} [euclidean_domain R] (n : ℕ) (i j : fin n) (a : R) (h : i ≠ j) : matrix (fin n) (fin n) R :=\n1 + a • (basis R n i j)\n\n-- Type II: Multiply row/column by a unit\ndef mul_by_unit {R : Type*} [euclidean_domain R] (n : ℕ) (i : fin n) (u : R) (h : is_unit u) : matrix (fin n) (fin n) R :=\nmatrix.diagonal (λ i', if i' = i then u else 1)\n--1 + (u - 1) • (basis R n i i)\n\n-- Type III: Permutation\ndef perm (R : Type*) [euclidean_domain R] (n : ℕ) (i j : fin n) : matrix (fin n) (fin n) R :=\n(equiv.to_pequiv (equiv.swap i j)).to_matrix\n-- 1 - (basis R n i i) - (basis R n j j) + (basis R n i j) + (basis R n j i)\n\n\n-- ## Elementary Matrices are Invertible (units)\n/-\nProof all three elementary matrices are invertible, which is expressed as `is_unit M`, by using equivalence between `is_unit M` and `is_unit (det M)`\n-/\n\ntheorem add_mult_inv {R : Type*} [euclidean_domain R] {n : ℕ} {i j : fin n} {a : R} (h : i ≠ j) : is_unit (add_mult n i j a h) :=\nbegin\n  apply (matrix.is_unit_iff_is_unit_det (add_mult n i j a h)).2,\n  by_cases h' : i < j, -- case split to use upper and lower triangular theorems (essentially same argument), could be condensed\n  { rw (matrix.det_of_upper_triangular (add_mult n i j a h) _),\n    { unfold add_mult,\n      unfold basis,\n      have h₁ : ∀ (x : fin n), ¬(i = x ∧ j = x),\n      { simp [h.symm] },\n      simp [h₁] },\n    intros k l hlk,\n    unfold add_mult,\n    unfold basis,\n    have h₂ : ¬ (i = k ∧ j = l),\n    { rintro ⟨rfl, rfl⟩,\n      exact asymm h' hlk },\n    simp [h₂, (ne_of_lt hlk).symm] },\n  rw (matrix.det_of_lower_triangular (add_mult n i j a h) _),\n  { unfold add_mult,\n    unfold basis,\n    have h₁ : ∀ (x : fin n), ¬(i = x ∧ j = x),\n    { simp [h.symm] },\n    simp [h₁] },\n  intros k l hkl,\n  unfold add_mult,\n  unfold basis,\n  have h₂ : ¬ (i = k ∧ j = l),\n  { rintro ⟨rfl, rfl⟩,\n    exact h (false.rec (i = j) (h' hkl)) },\n  simp [h₂, (ne_of_lt hkl)],\nend\n\ntheorem mul_by_unit_inv {R : Type*} [euclidean_domain R] {n : ℕ} {i : fin n} {u : R} {h : is_unit u} : is_unit (mul_by_unit n i u h) := \nbegin\n  apply (matrix.is_unit_iff_is_unit_det (mul_by_unit n i u h)).2,\n  unfold mul_by_unit,\n  simp [matrix.det_diagonal, finset.prod_ite],\n  exact is_unit.pow (finset.filter (λ (x : fin n), x = i) finset.univ).card h,\nend\n\ntheorem perm_inv {R : Type*} [euclidean_domain R] {n : ℕ} {i j : fin n} : is_unit (perm R n i j) := \nbegin\n  apply (matrix.is_unit_iff_is_unit_det (perm R n i j)).2, -- has determinant -1\n  unfold perm,\n  rw matrix.det_permutation,\n  by_cases h : i = j,\n  { rw equiv.perm.sign_swap',\n    simp [h] },\n  rw equiv.perm.sign_swap,\n  { use -1,\n    simp },\n  exact h,\nend\n\n-- ## Lemmas About The Elementary Matrices\n/-\nADD TO LIBRARY IN `data.matrix.pequiv`\nThis lemma fills in a missing lemma in `data.matrix.pequiv` which is necessary for proof of the effect of the permutation matrix\nThere are two different expressions of the theorem below, with the second one (using `matrix.submatrix`) being used\n-/\n\n/--\nvariables {m n α : Type*} \n\nlemma to_pequiv_matrix_mul [fintype n] [decidable_eq n] [semiring α] (f : n ≃ n) (M : matrix m n α): \n(M ⬝ f.to_pequiv.to_matrix) = λ i j, M i (f.symm j) :=\nmatrix.ext $ λ i j, by rw [pequiv.matrix_mul_apply, ←equiv.to_pequiv_symm, equiv.to_pequiv_apply]\n-/\n\nlemma pequiv.to_pequiv_matrix_mul {m n α : Type*} [fintype n] [decidable_eq n] [semiring α]\n  (f : n ≃ n) (M : matrix m n α) : (M ⬝ f.to_pequiv.to_matrix) = M.submatrix id (f.symm) :=\nmatrix.ext $ λ i j, by rw [pequiv.matrix_mul_apply, ←equiv.to_pequiv_symm,\n                           equiv.to_pequiv_apply, matrix.submatrix_apply, id.def]\n-- necessary for later lemmas\n\n-- ### Effect of Permutation Matrix\n/-\nEffect of left and right multiplication by the permutation matrix expressed in two ways each\n-/\n\nlemma perm_mul {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (k l : fin n) : ∀ (i j : fin n), A i j = ((elem_matrix.perm R n k l) ⬝ A) (ite (i = k) l (ite (i = l) k i)) j\n:= λ i j, by { unfold elem_matrix.perm, simp [pequiv.to_pequiv_mul_matrix, ←equiv.swap_apply_def] }\n\nlemma perm_mul' {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (k l : fin n) : ∀ (i j : fin n), ((elem_matrix.perm R n k l) ⬝ A) i j = A (ite (i = k) l (ite (i = l) k i)) j \n:= λ i j, by { unfold elem_matrix.perm, simp [pequiv.to_pequiv_mul_matrix, equiv.swap_apply_def] }\n\nlemma mul_perm {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (k l : fin n) : ∀ (i j : fin n), A i j = (A ⬝ (elem_matrix.perm R n k l)) i (ite (j = k) l (ite (j = l) k j))\n:= λ i j, by { unfold elem_matrix.perm, simp [pequiv.to_pequiv_matrix_mul, ←equiv.swap_apply_def] }\n\nlemma mul_perm' {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (k l : fin n) : ∀ (i j : fin n), (A ⬝ (elem_matrix.perm R n k l)) i j = A i (ite (j = k) l (ite (j = l) k j))\n:= λ i j, by { unfold elem_matrix.perm, simp [pequiv.to_pequiv_matrix_mul, equiv.swap_apply_def] }\n\nlemma perm_eq_id {R : Type*} [euclidean_domain R] {n : ℕ} : ∀ {i : fin n}, elem_matrix.perm R n i i = (1 : matrix (fin n) (fin n) R) :=\nbegin\n  intro i,\n  unfold perm,\n  simp,\nend\n\n-- ### Effect of Add Mult Matrix\n\n-- Left Mult\nlemma add_mult_mul {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (i j : fin n) (c : R) (h : i ≠ j) : ((add_mult n i j c h) ⬝ A) i j  = (A i j) + c * (A j j)  :=\nbegin\n  rw matrix.mul_apply,\n  unfold add_mult basis,\n  simp,\n  ring_nf,\n  rw finset.sum_add_distrib,\n  rw fintype.sum_eq_add_sum_compl i,\n  simp,\n  rw finset.sum_eq_zero _,\n  intros x hx,\n  rw [finset.mem_compl, finset.mem_singleton] at hx,\n  simp [matrix.one_apply_ne (ne_comm.mp hx)]\nend\n\n-- Right Mult\nlemma mul_add_mult {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (i j : fin n) (c : R) (h : i ≠ j) : (A ⬝ (add_mult n i j c h)) i j  = (A i j) + c * (A i i) :=\nbegin\n  rw matrix.mul_apply,\n  unfold add_mult basis,\n  simp,\n  ring_nf,\n  simp [add_mul],\n  rw finset.sum_add_distrib,\n  rw fintype.sum_eq_add_sum_compl j,\n  simp,\n  rw finset.sum_eq_zero _,\n  { ring_nf },\n  intros x hx,\n  rw [finset.mem_compl, finset.mem_singleton] at hx,\n  simp [matrix.one_apply_ne hx]\nend\n\n/-\nNo lemmas about the effect of the `unit_mul` elementary matrix since it isn't used in the restriced snf definition (where we don't require diagonal entries successively divide)\n-/\n\nend elem_matrix\n\n\n\n-- # Equivalence of m x n matrices\n/-\nBasic Framework for the equivalence of matrices, that this is an equivalence relation and that left and right multiplication by invertable (`is_unit`) matrices preserves equivalence\n-/\n\nnamespace matrix_equiv_rel\n\n-- ## Equivalence Definition\n-- two mxn matrices A and B are quivalent if A = M B N and M and N are invertible\ndef r (R : Type*) [euclidean_domain R] (m n : ℕ) : (matrix (fin m) (fin n) R) → (matrix (fin m) (fin n) R) → Prop :=\nλ A, (λ B, ∃ (M : matrix (fin m) (fin m) R) (N : matrix (fin n) (fin n) R), (is_unit M) ∧ (is_unit N) ∧ ( A = M ⬝ B ⬝ N ))\n\n-- ## Matrix Equivalence is an Equivalence Relation\n\nlemma r_refl {R : Type*} [euclidean_domain R] {m n : ℕ} : reflexive (r R m n) :=\nbegin\n  intro A,\n  use [1,1],\n  finish,\nend\n\nlemma r_symm {R : Type*} [euclidean_domain R] {m n : ℕ} : symmetric (r R m n) :=\nbegin\n  rintros A B ⟨M, N, hM, hN, h⟩,\n  use [M⁻¹, N⁻¹],\n  simp [matrix.nonsing_inv_eq_ring_inverse, hM, hN] ,\n  simp [← matrix.nonsing_inv_eq_ring_inverse],\n  calc\n    B = (M⁻¹ ⬝ M) ⬝ B ⬝ (N ⬝ N⁻¹) : by {simp [matrix.mul_nonsing_inv N ((matrix.is_unit_iff_is_unit_det N).mp hN), matrix.nonsing_inv_mul M ((matrix.is_unit_iff_is_unit_det M).mp hM)]}\n    ... = M⁻¹ ⬝ (M ⬝ B ⬝ N) ⬝ N⁻¹ : by {simp [matrix.mul_assoc]}\n    ... = M⁻¹ ⬝ A ⬝ N⁻¹ : by {rw h}\nend\n\nlemma r_trans {R : Type*} [euclidean_domain R] {m n : ℕ} : transitive (r R m n) :=\nbegin\n  rintros A B C ⟨M₁, N₁, hM₁, hN₁, h₁⟩ ⟨M₂, N₂, hM₂, hN₂, h₂⟩,\n  use [M₁ ⬝ M₂, N₂ ⬝ N₁],\n  split,\n  { exact is_unit.mul hM₁ hM₂ },\n  split,\n  { exact is_unit.mul hN₂ hN₁ },\n  calc\n    A = M₁ ⬝ B ⬝ N₁ : h₁\n    ... = M₁ ⬝ (M₂ ⬝ C ⬝ N₂) ⬝ N₁ : by {rw h₂}\n    ... = M₁ ⬝ M₂ ⬝ C ⬝ (N₂ ⬝ N₁) : by {simp only [matrix.mul_assoc]}\nend\n\ntheorem r_equiv {R : Type*} [euclidean_domain R] {m n : ℕ} : equivalence (r R m n) := ⟨r_refl, r_symm, r_trans⟩\n\n\n\n\n-- ## Basic Equivalence Lemmas\n\n-- left and right multiplication by invertible matrix preserves equivalence (in particular the elementary matrices)\n\nlemma unit_mul {R : Type*} [euclidean_domain R] {m n : ℕ} (M : matrix (fin m) (fin n) R) (A : matrix (fin m) (fin m) R) (h : is_unit A) : r R m n M (A ⬝ M) :=\nbegin\n  use [A⁻¹, 1],\n  simp [matrix.nonsing_inv_eq_ring_inverse, h, ← matrix.mul_assoc, ← matrix.mul_eq_mul, (ring.inverse_mul_cancel A h)]\nend\n\nlemma mul_unit {R : Type*} [euclidean_domain R] {m n : ℕ} (M : matrix (fin m) (fin n) R) (A : matrix (fin n) (fin n) R) (h : is_unit A) : r R m n M (M ⬝ A) :=\nbegin\n  use [1, A⁻¹],\n  simp [matrix.nonsing_inv_eq_ring_inverse, h, matrix.mul_assoc, ← matrix.mul_eq_mul, (ring.mul_inverse_cancel A h)]\nend\n\nend matrix_equiv_rel\n\n\n-- # Smith Normal Form\n\n-- Notation for euclidean_domain.r, the well_founded relation to replace euclidean valuation function\nlocal infix ` ≺ `:50 := euclidean_domain.r\n\n-- If `δ` was the euclidean valuation function, as in Jacobson book, then we have the following equivalence `a ≺ b  ↔  δ(a) < δ(b)`\n\nnamespace smith_norm_form\n\n-- ## Definitions\n\n-- Simple version of smith normal form, without division condition, and limited to nxn\n-- See full definition in comments at bottom\ndef snf {n : ℕ} {R : Type*} [euclidean_domain R] [decidable_eq R] (A : matrix (fin n) (fin n) R) : Prop :=\n∃ (d : (fin n) → R) (r : ℕ), (A = matrix.diagonal d) ∧ (∀ (i : fin n), ↑i ≥ r ↔ d i = 0 ) --∧ (∀ (i j : fin n), (i ≤ j) → ↑j < r → (d i) ∣ (d j))\n\n-- desired form for induction step\ndef simple_block_diag {R : Type*} [euclidean_domain R] {n : ℕ} (a : R) (A : matrix (fin n) (fin n) R) : matrix (fin (n + 1)) (fin (n + 1)) R :=\nmatrix.reindex (fin_sum_fin_equiv.trans fin_add_flip) (fin_sum_fin_equiv.trans fin_add_flip) (matrix.from_blocks (a • (1 : matrix (fin 1) (fin 1) R)) 0 0 A)\n-- use `matrix.submatrix` instead?\n/-\na 0 0 0\n0 (   )\n0 | A |\n0 (   )\n-/\n\n-- An element of a matrix (over a ED) is minimal if it's non zero and has minimal valuation (excluding zeros)\ndef is_minimal {R : Type*} [euclidean_domain R] {n : ℕ} (A : matrix (fin n) (fin n) R) (k l : fin n) : Prop := (A k l ≠ 0) ∧ (∀ (i j : fin n), A i j ≠ 0 → ¬((A i j) ≺ (A k l)))\n\n\n-- ## Lemmas Setting Up Main Result\n\n-- Every non-zero matrix has an element with minimal valuation\n-- this lemma specifically can give the indices of the minimal element\nlemma min_valuation_of_mat {R : Type*} [euclidean_domain R] [decidable_eq R] {n : ℕ} (A : matrix (fin n) (fin n) R) (hA0 : A ≠ 0) : ∃ (k l : fin n), is_minimal A k l :=\nbegin\n  -- A as a finset without the zero's\n  let A' := finset.filter (λ (a : R), a ≠ 0) (finset.image₂ A finset.univ finset.univ),\n  -- A has a non-zero element\n  have hA0' : ∃ (i' j' : fin n), A i' j' ≠ 0,\n  { by_contra h',\n    push_neg at h',\n    have : A = 0,\n    ext A,\n    exact h' _ _,\n    contradiction },\n  rcases hA0' with ⟨i', j', hA0'⟩,\n  -- A' is nonempty\n  have hA'ne : A'.nonempty,\n  { use A i' j',\n    simp [A'],\n    use [i', j'] },\n  -- A' has a minimal element since ≺ is well founded\n  rcases (well_founded.has_min euclidean_domain.r_well_founded (↑A') hA'ne) with ⟨m, hm, hmin⟩,\n  rcases ((finset.mem_image₂).mp (finset.mem_of_mem_filter m hm)) with ⟨k, l, _, _, hmin'⟩,\n  use [k, l],\n  split,\n  { rw hmin',\n    exact (finset.mem_filter.mp hm).2 },\n  intros i j h,\n  have h'' : (A i j) ∈ A',\n  { dsimp [A'],\n    rw finset.mem_filter,\n    split,\n    { rw finset.mem_image₂,\n      use [i, j],\n      simp },\n    exact h },\n  rw hmin',\n  exact hmin (A i j) h''\nend\n\n\n-- Moves minimal element to top left\nlemma minimal_element_to_00 {R : Type*} [euclidean_domain R] [decidable_eq R] {n : ℕ} (A : matrix (fin (n + 1)) (fin (n + 1)) R)  (hA0 : A ≠ 0) : ∃ (B : matrix (fin (n + 1)) (fin (n + 1)) R), is_minimal B 0 0 ∧ matrix_equiv_rel.r R (n + 1) (n + 1) A B :=\nbegin\n  rcases (min_valuation_of_mat A hA0) with ⟨i, j, h⟩, -- A i j is minimal elt of A\n  use ((elem_matrix.perm R (n + 1) 0 i) ⬝ A ⬝ (elem_matrix.perm R (n + 1) 0 j)),\n  split,\n  { -- minimal element is at 0 0\n    have aux : ∀ (k : fin (n + 1)), (ite (k = 0) k (ite (k = k) 0 k)) = 0,\n      { have hj : j = 0 ∨ j ≠ 0, by tauto,\n        cases hj;\n        simp [hj] },\n    have h₁ : A i j = ((elem_matrix.perm R (n + 1) 0 i) ⬝ A ⬝ (elem_matrix.perm R (n + 1) 0 j)) 0 0,\n    { have H₁ := (elem_matrix.mul_perm ((elem_matrix.perm R (n + 1) 0 i) ⬝ A) 0 j) 0 j,\n      rw [aux j] at H₁,\n      rw [← H₁, ((elem_matrix.perm_mul A 0 i) i j), aux i] },\n    have h₂ : ∀ (i' j' : fin (n + 1)), ∃ (k l : fin (n + 1)), A k l = ((elem_matrix.perm R (n + 1) 0 i) ⬝ A ⬝ (elem_matrix.perm R (n + 1) 0 j)) i' j',\n    { intros i' j',\n      -- Very manual solution\n      have hi' : i' = 0 ∨ i' = i ∨ (i' ≠ 0 ∧ i' ≠ i), by tauto,\n      have hj' : j' = 0 ∨ j' = j ∨ (j' ≠ 0 ∧ j' ≠ j), by tauto,\n      have hi : i = 0 ∨ i ≠ 0, by tauto,\n      have hj : j = 0 ∨ j ≠ 0, by tauto,\n      cases hi;\n      cases hj,\n      { rw [hi, hj, elem_matrix.perm_eq_id],\n        use [i', j'],\n        simp },\n      { rw [hi, elem_matrix.perm_eq_id],\n        simp,\n        rcases hj' with hj' | hj' | ⟨hj'₁, hj'₂⟩,\n        { use [i', j],\n          rw [hj', (elem_matrix.mul_perm A 0 j) i' j, aux j] },\n        { use [i', 0],\n          simp [hj', (elem_matrix.mul_perm A 0 j) i' 0] },\n        { use [i', j'],\n          simp [(elem_matrix.mul_perm A 0 j) i' j', hj'₁, hj'₂] } },\n      { rw [hj, elem_matrix.perm_eq_id],\n        simp,\n        rcases hi' with hi' | hi' | ⟨hi'₁, hi'₂⟩,\n        { use [i, j'],\n          rw [hi', (elem_matrix.perm_mul A 0 i) i j', aux i] },\n        { use [0, j'],\n          simp [hi', (elem_matrix.perm_mul A 0 i) 0 j'] },\n        { use [i', j'],\n          simp [(elem_matrix.perm_mul A 0 i) i' j', hi'₁, hi'₂] } },\n      { have H₁ := elem_matrix.mul_perm ((elem_matrix.perm R (n + 1) 0 i) ⬝ A) 0 j,\n        have H₂ := elem_matrix.perm_mul A 0 i,\n        rcases hi' with hi' | hi' | ⟨hi'₁, hi'₂⟩;\n        rcases hj' with hj' | hj' | ⟨hj'₁, hj'₂⟩,\n        { rw [hi', hj'] at *,\n          use [i, j],\n          have H₁' := H₁ 0 j,\n          rw [aux j] at H₁',\n          rw [← H₁', (H₂ i j), aux i] },\n        { rw [hi', hj'] at *,\n          use [i, 0],\n          have H₁' := H₁ 0 0,\n          simp at H₁',\n          rw [← H₁', (H₂ i 0), aux i] },\n        { rw [hi'] at *,\n          use [i, j'],\n          have H₁' := H₁ 0 j',\n          simp [hj'₁, hj'₂] at H₁',\n          rw [← H₁', (H₂ i j'), aux i] },\n        { rw [hi', hj'] at *,\n          use [0, j],\n          have H₁' := H₁ i j,\n          rw [aux j] at H₁',\n          simp [← H₁', (H₂ 0 j)] },\n        { rw [hi', hj'] at *,\n          use [0, 0],\n          have H₁' := H₁ i 0,\n          simp at H₁',\n          simp [← H₁', (H₂ 0 0)] },\n        { rw hi' at *,\n          use [0, j'],\n          have H₁' := H₁ i j',\n          simp [hj'₁, hj'₂] at H₁',\n          simp [← H₁', (H₂ 0 j')] },\n        { rw hj' at *,\n          use [i', j],\n          have H₁' := H₁ i' j,\n          rw aux j at H₁',\n          simp [← H₁', (H₂ i' j), hi'₁, hi'₂] },\n        { rw hj' at *,\n          use [i', 0],\n          have H₁' := H₁ i' 0,\n          simp at H₁',\n          simp [← H₁', (H₂ i' 0), hi'₁, hi'₂] },\n        { use [i', j'],\n          have H₁' := H₁ i' j',\n          simp [hj'₁, hj'₂] at H₁',\n          simp [← H₁', (H₂ i' j'), hi'₁, hi'₂] } } },\n    unfold is_minimal at h ⊢,\n    rw ← h₁,\n    split,\n    { exact h.1 },\n    intros i' j' H,\n    rcases h₂ i' j' with ⟨k, l, h'⟩,\n    rw ← h' at H ⊢,\n    exact h.2 k l H },\n  -- matrices are equivalent\n  have h₁ := matrix_equiv_rel.unit_mul A (elem_matrix.perm R (n + 1) 0 i) elem_matrix.perm_inv,\n  have h₂ := matrix_equiv_rel.mul_unit ((elem_matrix.perm R (n + 1) 0 i) ⬝ A) (elem_matrix.perm R (n + 1) 0 j) elem_matrix.perm_inv,\n  exact matrix_equiv_rel.r_trans h₁ h₂,\nend\n\n-- Assume B 0 0 doesn't divide all elements in row 1 or column 1, then perform EA to give a new (smaller) minimal element\nlemma temp1 {R : Type*} [euclidean_domain R] [decidable_eq R] {n : ℕ} (A : matrix (fin (n + 1)) (fin (n + 1)) R)  (hA0 : A ≠ 0) (h00 : is_minimal A 0 0) (i : fin (n + 1)) (H : ¬(A 0 0 ∣ A i 0) ∨ ¬(A 0 0 ∣ A 0 i) ) : ∃ (B : matrix (fin (n + 1)) (fin (n + 1)) R), ((B i 0 ≺ A 0 0) ∨ (B 0 i ≺ A 0 0)) ∧ matrix_equiv_rel.r R (n + 1) (n + 1) A B :=\nbegin\n  have hi : i ≠ 0,\n    { intro hc,\n      rw hc at H,\n      cases H;\n      contradiction },\n  cases H,\n  -- Argument for column 0 and row 0 are almost identical but do have small differences\n  -- column 0\n  { let B := (elem_matrix.add_mult (n + 1) i 0 (-((A i 0) / (A 0 0))) hi),\n    have h' : is_unit B,\n    { exact @elem_matrix.add_mult_inv R _inst_1 (n + 1) i 0 (-((A i 0) / (A 0 0))) hi },\n    use [B ⬝ A],\n    split,\n    { left,\n      -- minimal valuation is lower\n      have h : (B ⬝ A) i 0 = (A i 0) % (A 0 0),\n      { simp [euclidean_domain.mod_eq_sub_mul_div],\n        rw elem_matrix.add_mult_mul A i 0 (-((A i 0) / (A 0 0))) hi,\n        ring_nf },\n      rw h,\n      exact euclidean_domain.remainder_lt (A i 0) h00.1 },\n    -- matrices are equivalent\n    -- unfold matrix_equiv_rel.r,\n    use [B⁻¹, 1],\n    simp,\n    split,\n    { cases h' with u h',\n      use u⁻¹,\n      simp [h'] },\n    simp [← matrix.mul_assoc, matrix.nonsing_inv_mul B ((matrix.is_unit_iff_is_unit_det B).1 h')] },\n  -- row zero\n  let B := (elem_matrix.add_mult (n + 1) 0 i (-((A 0 i) / (A 0 0))) hi.symm),\n  have h' : is_unit B,\n    { exact @elem_matrix.add_mult_inv R _inst_1 (n + 1) 0 i (-((A 0 i) / (A 0 0))) hi.symm },\n  use [A ⬝ B],\n  split,\n  { right,\n    -- minimal valuation is lower\n    have h : (A ⬝ B) 0 i = (A 0 i) % (A 0 0),\n    { simp [euclidean_domain.mod_eq_sub_mul_div],\n      rw elem_matrix.mul_add_mult A 0 i (-((A 0 i) / (A 0 0))) hi.symm,\n      ring_nf },\n    rw h,\n    exact euclidean_domain.remainder_lt (A 0 i) h00.1 },\n  -- matrices are equivalent\n  -- unfold matrix_equiv_rel.r,\n  use [1, B⁻¹],\n  simp,\n  split,\n  { cases h' with u h',\n    use u⁻¹,\n    simp [h'] },\n  have := ((matrix.is_unit_iff_is_unit_det B).1 h'),\n  simp [matrix.mul_assoc, matrix.mul_nonsing_inv B ((matrix.is_unit_iff_is_unit_det B).1 h')]\nend\n\n-- __1__ Assume B 0 0 does divide all elements in row 1 or column 1, then can make them all into zero's __For Loop Implementation__\n\n\n-- __2__ We will always be in one of the above cases, if first one, there will be finitely many steps to second case (using well founded tactics, see extended EA and gcd processes proof) By The Equation Compiler and __Using_Well_Founded__\n\n\n-- inductive steps between n and (n + 1)\n-- __3__ \nlemma equiv_simple_block_diag {R : Type*} [euclidean_domain R] {n : ℕ} (h : n > 0) (A : matrix (fin (n + 1)) (fin (n + 1)) R) : ∃ (B : matrix (fin n) (fin n) R) (b : R), matrix_equiv_rel.r R (n + 1) (n + 1) A (simple_block_diag b B) :=\nbegin\n  unfold simple_block_diag,\n  sorry\nend\n-- use `matrix.submatrix`?\n\n\n-- __4__ \nlemma temp2 {R : Type*} [euclidean_domain R] [decidable_eq R] {n : ℕ} (hn : n > 0) (A : matrix (fin n) (fin n) R) (B : matrix (fin n) (fin n) R) (hB : snf B) (hA : matrix_equiv_rel.r R n n A B) {a : R} : ∃ (C : matrix (fin (n + 1)) (fin (n + 1)) R), matrix_equiv_rel.r R (n + 1) (n + 1) (simple_block_diag a A) C ∧ snf C := sorry\n\n-- Show that any zero matrix is in smith normal form\n-- show that any non-zero 1x1 matrix is in smith normal form\n\n\n\n\n/-\n__Miscellaneous Defintions of SNF not currently implemented__\n\ndef smith_norm_form {n : ℕ} {D : Type*} [euclidean_domain D] (A : matrix (fin n) (fin n) D) : Prop :=\n∃ (d : (fin n) → D) (r : ℕ), (A = matrix.diagonal d) ∧ (∀ (i : fin n), ↑i ≥ r ↔ d i = 0 ) ∧ (∀ (i j : fin n), (i ≤ j) → ↑j < r → (d i) ∣ (d j))\n\n\n\n-- # Smith Normal Form (limited to nxn matrices)\n\ndef smith_norm_form {n : ℕ} {D : Type*} [euclidean_domain D] (A : matrix (fin n) (fin n) D) : Prop :=\n∃ (d : (fin n) → D) (r : ℕ), (A = matrix.diagonal d) ∧ (∀ (i : fin n), ↑i ≥ r ↔ d i = 0 ) ∧ (∀ (i j : fin n), (i ≤ j) → ↑j < r → (d i) ∣ (d j))\n\n-- # Main Theorem\n\ntheorem mat_equiv_to_smith_norm_mat {n : ℕ} {D : Type*} {D : Type*} [euclidean_domain D] (A : matrix (fin n) (fin n) D) : ∃ (B : matrix (fin n) (fin n) D), smith_norm_form B ∧ (matrix_equiv_rel.R D n n A B) :=\nbegin\n  sorry\nend\n\n-/\n\n\nend smith_norm_form", "meta": {"author": "jreaso", "repo": "smith-normal-form", "sha": "d5b1815987787c38adf42f7e88abe5737a9f98c8", "save_path": "github-repos/lean/jreaso-smith-normal-form", "path": "github-repos/lean/jreaso-smith-normal-form/smith-normal-form-d5b1815987787c38adf42f7e88abe5737a9f98c8/src/smith-normal-form.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294209307224, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7546874336366278}}
{"text": "/-\nCopyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël Dillies, Bhavik Mehta\n\n! This file was ported from Lean 3 source module order.partition.equipartition\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.Set.Equitable\nimport Mathlib.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.IsEquipartition`: Predicate for a `Finpartition` to be an equipartition.\n-/\n\n\nopen Finset Fintype\n\nnamespace Finpartition\n\nvariable {α : Type _} [DecidableEq α] {s t : Finset α} (P : Finpartition s)\n\n/-- An equipartition is a partition whose parts are all the same size, up to a difference of `1`. -/\ndef IsEquipartition : Prop :=\n  (P.parts : Set (Finset α)).EquitableOn card\n#align finpartition.is_equipartition Finpartition.IsEquipartition\n\ntheorem isEquipartition_iff_card_parts_eq_average :\n    P.IsEquipartition ↔\n      ∀ a : Finset α,\n        a ∈ P.parts → a.card = s.card / P.parts.card ∨ a.card = s.card / P.parts.card + 1 :=\n  by simp_rw [IsEquipartition, Finset.equitableOn_iff, P.sum_card_parts]\n#align finpartition.is_equipartition_iff_card_parts_eq_average\n    Finpartition.isEquipartition_iff_card_parts_eq_average\n\nvariable {P}\n\ntheorem Set.Subsingleton.isEquipartition (h : (P.parts : Set (Finset α)).Subsingleton) :\n    P.IsEquipartition :=\n  Set.Subsingleton.equitableOn h _\n#align finpartition.set.subsingleton.is_equipartition Finpartition.Set.Subsingleton.isEquipartition\n\ntheorem IsEquipartition.card_parts_eq_average (hP : P.IsEquipartition) (ht : t ∈ P.parts) :\n    t.card = s.card / P.parts.card ∨ t.card = s.card / P.parts.card + 1 :=\n  P.isEquipartition_iff_card_parts_eq_average.1 hP _ ht\n#align finpartition.is_equipartition.card_parts_eq_average Finpartition.IsEquipartition.card_parts_eq_average\n\ntheorem IsEquipartition.average_le_card_part (hP : P.IsEquipartition) (ht : t ∈ P.parts) :\n    s.card / P.parts.card ≤ t.card := by\n  rw [← P.sum_card_parts]\n  exact Finset.EquitableOn.le hP ht\n#align finpartition.is_equipartition.average_le_card_part Finpartition.IsEquipartition.average_le_card_part\n\ntheorem IsEquipartition.card_part_le_average_add_one (hP : P.IsEquipartition) (ht : t ∈ P.parts) :\n    t.card ≤ s.card / P.parts.card + 1 := by\n  rw [← P.sum_card_parts]\n  exact Finset.EquitableOn.le_add_one hP ht\n#align finpartition.is_equipartition.card_part_le_average_add_one Finpartition.IsEquipartition.card_part_le_average_add_one\n\n/-! ### Discrete and indiscrete finpartition -/\n\n\nvariable (s) -- [Decidable (a = ⊥)]\n\ntheorem bot_isEquipartition : (⊥ : Finpartition s).IsEquipartition :=\n  Set.equitableOn_iff_exists_eq_eq_add_one.2 ⟨1, by simp⟩\n#align finpartition.bot_is_equipartition Finpartition.bot_isEquipartition\n\ntheorem top_isEquipartition [Decidable (s = ⊥)] : (⊤ : Finpartition s).IsEquipartition :=\n  Set.Subsingleton.isEquipartition (parts_top_subsingleton _)\n#align finpartition.top_is_equipartition Finpartition.top_isEquipartition\n\ntheorem indiscrete_isEquipartition {hs : s ≠ ∅} : (indiscrete hs).IsEquipartition := by\n  rw [IsEquipartition, indiscrete_parts, coe_singleton]\n  exact Set.equitableOn_singleton s _\n#align finpartition.indiscrete_is_equipartition Finpartition.indiscrete_isEquipartition\n\nend Finpartition\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/Partition/Equipartition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7546874301617894}}
{"text": "def zeroEqualsZero : 0 = 0 := rfl\n#check zeroEqualsZero\n\ntheorem theorem1 : 2 = 1 + 1 := rfl\n#check theorem1\n#reduce theorem1\n\ntheorem theorem1' : 2 = 1 + 1 := eq.refl 2\n#check theorem1'\n#reduce theorem1'\n\ntheorem theorem2 : tt = tt := rfl\n#check theorem2\n#reduce theorem2\n\n/- Doesn't work due to memory constraints-/\ntheorem theorem3 : \"Hello Lean\" = \"Hello \" ++ \"Lean\" := rfl\n#check theorem3\n\ntheorem pythagorean : 3*3 + 4*4 = 5*5 := rfl\n#check pythagorean\n#reduce pythagorean\n\n-- a = b, b = a\n#check eq.symm\n\n/- \n    (T: Type) (a,b: T) (a Eq b: a = b)\n    ----------------------------------\n        \n\n-/", "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/LeanTutorial/LeanDay2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7546874289615766}}
{"text": "import tactic\nimport data.nat.basic\n\nopen nat\n\nlemma div_3_le_9 (x : ℕ) (h9 : x ≤ 9) (h3 : 3 ∣ x) : x = 0 ∨ x = 3 ∨ x = 6 ∨ x = 9 :=\nbegin\n    cases h3 with k h3k,\n    have : k ≤ 3 := by linarith,\n    interval_cases k; dec_trivial!,\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/imo/div_3_le_9.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088064979618, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.7546731742903791}}
{"text": "import tactic\nimport data.real.basic\nimport data.set\nimport reals_ps\n\n/--\nA sequence a n is monotone increasing iff each term is greater than or equal to the last.\n-/\ndef monotone_increasing (a : ℕ → ℝ) : Prop :=\n∀(n : ℕ),  a n ≤ a (n+1)\n\nlemma monotone_increasing_def {a : ℕ → ℝ} :\n  monotone_increasing a ↔ ∀(n : ℕ),  a n ≤ a (n+1) := by refl\n\n--The induction tactic won't start at n so we need to prove this lemma first to get what we want.\nlemma monotone_increasing_add {a : ℕ → ℝ}:\n monotone_increasing a → ∀(n : ℕ), ∀ (m : ℕ),  a n ≤ a (m+n):=\nbegin\n  intro h,\n  intros n m,\n  induction m,\n  rw zero_add,\n  rw nat.succ_eq_one_add,\n  have h2: a (m_n + n) ≤ a ( (m_n + n) + 1),\n  rw monotone_increasing_def at h,\n  specialize h (m_n + n),\n  exact h,\n  rw add_assoc,\n  rw add_comm,\n  linarith,\nend\n\n--An equivalent definition of monotone increasing. We need both for the theorems later!\nlemma monotone_increasing_ind {a : ℕ → ℝ}:\nmonotone_increasing a ↔ ∀(n : ℕ), ∀ (m : ℕ), n ≤ m → a n ≤ a m :=\nbegin\n  split,\n  {\n    intro h,\n    intros n m,\n    intro h2,\n    have h3 : ∃ (r: ℕ), n + r = m,\n    use m - n,\n    linarith,\n    cases h3 with s hs,\n    rw ←hs,\n    rw add_comm,\n    apply monotone_increasing_add, exact h,\n  },\n  {\n    intro h,\n    intro n,\n    specialize h n (n+1),\n    apply h,\n    norm_num,\n  }\nend\n\n/--\nA sequence is monotone decreasing iff each term is less than or equal to the last.\n-/\ndef monotone_decreasing (a : ℕ → ℝ) : Prop := \n  ∀(n : ℕ), a (n+1) ≤ a n\n\n/-\nThe corresponding lemma is not needed here since we don't directly prove the \nmonotone convergence theorem for decreasing sequences.\n-/\n\n/--\nA function f : ℕ → ℕ is strictly increasing if each f(x + 1) > f(x) for every x.\n-/\ndef strictly_increasing (a : ℕ → ℕ) : Prop :=\n  ∀(n : ℕ), a n < a (n + 1)\n\n/--\nGiven a sequence a n and an index i, a i is a peak of a n iff\nall following terms are smaller.\n-/\ndef peak (a : ℕ → ℝ) (i : ℕ) : Prop:=\n  ∀(n : ℕ), i < n → a n < a i\n\n/--\nTakes a function f : ℕ → ℕ and an initial value i : ℕ and returns a function g : ℕ → ℕ such that\ng(n) = g^(n+1)(i)\n-/\ndef recursive (f : ℕ → ℕ) (i : ℕ) : ℕ → ℕ\n| 0       :=  f i\n| (x + 1) :=  f (recursive x)\n\n/--\nA monotone increasing sequence that is bounded above converges to some limit.\n-/\ntheorem bdd_inc_seq_converges {a : ℕ → ℝ} (hb: ∃(M:ℝ), ∀(n: ℕ), a n ≤ M) (hm : monotone_increasing a): ∃(l : ℝ), tendsto a l :=\nbegin\n  let S := set.range a,\n  have hsb : bdd_above S, --Prove that S is bounded above\n  cases hb with M hbh,\n  use M,\n  intro a,\n  intro as,\n  rw set.mem_range at as,\n  cases as with ay,\n  specialize hbh ay,\n  rw ←as_h,\n  exact hbh,\n  let t := Sup S,\n  use t, -- this is the limit\n  intro eps,\n  intro heps,\n  let d := t - eps/2,\n  have hds : d ≤ t,\n  norm_num,\n  linarith,\n  rw real.le_Sup_iff at hds,\n  {\n    specialize hds (-eps/2), --go at most epsilon away from the supremum\n    have hxs: (∃ (x : ℝ) (H : x ∈ S), d + -eps/2 < x), apply hds, linarith,\n    cases hxs with x hxsi,\n    cases hxsi with xs hxs_h,\n    rw set.mem_range at xs,\n    cases xs with b,\n    use b,\n    intro n,\n    intro hbn,\n    --We use the other definition of monotone increasing here.\n    have han_ab: a n ≥ a b,\n    rw monotone_increasing_ind at hm,\n    specialize hm b n,\n    apply hm,\n    exact hbn,\n    rw abs_sub_comm (a n) t,\n    have hnomod: |t - a n| = t - a n, -- remove the modulus so linarith works\n    rw abs_eq_self,\n    rw sub_nonneg,\n    apply le_cSup, \n    exact hsb,\n    rw set.mem_range,\n    use n,\n    rw hnomod,\n    rw ←xs_h at hxs_h,\n    change  t - eps/2 + -eps / 2 < a b at hxs_h,\n    linarith,\n  },\n  {exact hsb,}, --We have already proven that S is bounded above. For some reason this comes after the main goal.\n  { --S is non empty\n    use a 1,\n    rw set.mem_range,\n    use 1,\n  }\nend\n\n/--\nA monotone decreasing sequence that is bounded below converges to some limit.\n-/\ntheorem bdd_dec_seq_converges {a : ℕ → ℝ} (hb: ∃(M:ℝ), ∀(n: ℕ), M ≤ a n) (hm : monotone_decreasing a): ∃(l : ℝ), tendsto a l :=\nbegin\n  -- recycle the proof for increasing sequences \n  -- and combine with tendsto_neg (modified to be an iff so we can go both ways)\n  let b := (λ n, - a n),\n  have hi: monotone_increasing b,\n  intro n,\n  specialize hm n,\n  change -a (n + 1) ≥ -a n,\n  norm_num, exact hm,\n  cases hb,\n  have hbt: ∃(M:ℝ), ∀(n: ℕ), b n ≤ M,\n  use -hb_w,\n  change ∀ (n : ℕ), -a n ≤ -hb_w,\n  intro n,\n  specialize hb_h n,\n  norm_num, exact hb_h,\n  have hbc: ∃(s : ℝ), tendsto b s,\n  apply bdd_inc_seq_converges,\n  exact hbt,\n  exact hi,\n  cases hbc with nl hnl,\n  use -nl,\n  rw tendsto_neg_iff,\n  rw neg_neg,\n  exact hnl,\nend\n\n/--\nA bounded sequence has a convergent subsequence.\n-/\ntheorem bolzano_weierstrass {a : ℕ → ℝ} (hb: ∃(M:ℝ), ∀(n: ℕ), |a n| ≤ M) :\n∃(n: ℕ → ℕ) (hn: strictly_increasing n) (l : ℝ), tendsto (λ t, a (n t)) l :=\nbegin\n  --Either there are infinitely many peaks or finitely many peaks.\n  by_cases (∀(t : ℕ), ∃(u: ℕ), u > t ∧ peak a u),\n  {\n    choose r hr using h,\n    let s := recursive r 0,\n    have hinc : strictly_increasing s,\n    {\n      intro n,\n      specialize hr (s n),\n      cases hr with hi,\n      exact hi,\n    },\n    --Prove that every point in the subsequence is a peak.\n    --The hypothesis hr is not quite what we need since given s(n) it tells us that s(n+1) is a peak.\n    have hpeak: ∀(n : ℕ), peak a (s n),{ \n      intro n,\n      by_cases n = 0,\n      rw h,\n      change peak a (r 0),\n      specialize hr 0,\n      cases hr,\n      exact hr_right,\n      have h2 : ∃ (c : ℕ), n = c.succ,\n      apply nat.exists_eq_succ_of_ne_zero,\n      exact h,\n      cases h2,\n      rw h2_h,\n      change peak a (r (s h2_w)),\n      specialize hr (s h2_w),\n      cases hr,\n      exact hr_right,\n    },\n    --Prove monotonicity.\n    have hsmi : monotone_decreasing (λ t, a (s t)),\n    {\n      intro n,\n      change a ( s ( n + 1)) ≤ a ( s n ),\n      specialize hpeak n,\n      specialize hpeak (s (n + 1)),\n      specialize hinc n,\n      have g: a (s (n + 1)) < a (s n),\n      apply hpeak, exact hinc,\n      linarith,\n    },\n    --Plug in all the right functions and proofs to end the proof for this case.\n    use s,\n    split,\n    exact hinc,\n    apply bdd_dec_seq_converges,\n    cases hb,\n    use -hb_w,\n    intro n,\n    specialize hb_h (s n),\n    exact neg_le_of_abs_le hb_h,\n    exact hsmi,\n  },{\n    have h2: ∃ (p : ℕ), ∀ (q : ℕ), p < q → (∃ (n : ℕ), q < n ∧ a q ≤ a n),\n    --Some logic to get this into a form that is easier to work with.\n    {\n      rw not_forall at h, cases h,\n      use h_w, rw not_exists at h_h,\n      intro q,\n      specialize h_h q,\n      rw not_and at h_h,\n      intro hnq,\n      have hp: ¬peak a q,\n      apply h_h, exact hnq,\n      change ¬(∀(n : ℕ), n > q → a n < a q) at hp,\n      rw not_forall at hp,\n      cases hp,\n      use hp_w,\n      rw ←not_lt,\n      rw ←not_le,\n      rw ←not_or_distrib,\n      rw ←not_lt,\n      rw gt_iff_lt at hp_h,\n      rw ←imp_iff_not_or,\n      exact hp_h\n    },\n    --More tinkering so that the hypothesis works with the choose tactic.\n    cases h2 with p h3,\n    have h4: ∀ (r : ℕ), ∃ (n : ℕ), r < n ∧ a (r + (p+1)) ≤ a (n+ (p+1)),\n    intro r, specialize h3 (r + (p+1)),\n    have h5: (∃ (n : ℕ), r + (p+1) < n ∧ a (r + (p+1)) ≤ a n),\n    apply h3,\n    rw add_comm,\n    rw add_assoc,\n    rw lt_add_iff_pos_right,\n    exact nat.zero_lt_one_add r,\n    cases h5,\n    cases h5_h,\n    use h5_w - (p + 1),\n    split,\n    rw lt_tsub_iff_right,\n    exact h5_h_left,\n    --We haven't proven that h5_w - (p + 1) exists in ℕ.\n    have h6: h5_w - (p + 1) + (p + 1) = h5_w,\n    apply nat.sub_add_cancel,\n    linarith [h5_h_left],\n    rw h6,\n    exact h5_h_right,\n    -- Construct the subsequence\n    choose b hbs using h4,\n    let c := recursive b 0,\n    let s := (λ n, c n + (p + 1)),\n    \n    have hinc : strictly_increasing s,\n    {\n      intro n,\n      specialize hbs (c n),\n      cases hbs,\n      rw add_lt_add_iff_right,\n      exact hbs_left,\n    },\n    -- Prove that it's monotone to apply the theorem.\n    have hmi : monotone_increasing (λ n, a (s n)),\n    {\n      intro n,\n      specialize hbs (c n),\n      cases hbs,\n      exact hbs_right,\n    },\n    use s,\n    split,\n    exact hinc,\n    apply bdd_inc_seq_converges,\n    cases hb,\n    use hb_w,\n    intro n,\n    specialize hb_h (s n),\n    apply le_of_abs_le,\n    exact hb_h,\n    exact hmi,\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/cw1/cw1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.7546709469420777}}
{"text": "/- 30 Aug 2019 -/\n-- degree\n-- incidence matrix\n-- adjacency matrix\n\n/-\n## Definitions:\n* A sequence of nonnegative integers is called `graphic` if it is the degree\n  sequence of a simple graph.\n\nhow does one write dn where n is a subscript?\n\nHavel-Hakimi Theorem: Let d_1 ≥ d_2 ≥ ... ≥ d_n ≥ 0 be a (finite) sequence of \nnonnegative integers. The sequence is graphic iff the sequence \n  d_2 - 1, ... , d_(t + 1) - 1, d_(t + 2), ... , d_n, where t = d_1, is graphic.\n\n\nLet 0 ≤ d_1 ≤ d_2 ≤ ... ≤ d_n be a (finite) sequence of \nnonnegative integers. The sequence is graphic iff the sequence \n  d_2 - 1, ... , d_(t + 1) - 1, d_(t + 2), ... , d_n, where t = d_1 is graphic.\n-/\n\nimport data.list.sort\nimport combinatorics.simple_graph.basic\nimport data.multiset.sort\n\nuniverse u\nvariables (V : Type u) [fintype V]\n\n-- what type should i use?\n  -- `list.sorted` or `list.pairwise`\n-- i think i can just use nat since that includes zero\n\n-- oh god i need some kind of counter? or index\n-- copy over the sequence except erase largest element and \n  -- subtract one from the n next largest elements\ndef sub_one_n_times' (n : ℕ) (l : list ℕ) : list ℕ :=\n(l.take n).map (nat.pred) ++ l.drop n\n-- this one works i think, but ordering does matter\n\n/-def list.pos_filter (l : list ℕ) : list ℕ := l.filter (λ n, 0 < n)\n-- this probably already exists, just don't feel like looking it up\n\ndef n_pos_list_check (n : ℕ) (l : list ℕ) : Prop := n ≤ l.pos_filter.length-/\n\n-- def nth_is_pos (n : ℕ) (l : list ℕ) [l.sorted (≤)] : Prop := 0 < (l.nth n)\n-- bad\n\ndef sub_one_n_times (n : ℕ) (l : list ℕ) (h : l.sorted (≥)) : option (list ℕ) := \n  if n ≤ (l.filter (λ n, 0 < n)).length then some (sub_one_n_times' n l) else none\n\ndef havel_hakimi' (l : list ℕ) (h : l.sorted (≥)) : option (list ℕ) := \n  if (l.filter (λ n, 0 < n)) = [] then some [] else sub_one_n_times l.head l.tail h.tail\n-- you can't get the empty list out of applying sub_one_n_times and removing the largest degree repeatedly, so when \n  -- you get the empty list, you're done\n-- is there another way of doing it? is there something else i can return\n-- also need to re-sort\n\ndef havel_hakimi_step (l : list ℕ) (h : l.sorted (≥)) : multiset ℕ := sub_one_n_times' l.head l.tail\n\n-- ideas for degree sequence\n  -- multiset of vertices, take the image\n  -- `multiset.sort` to get sorted list\nvariables {V}\n\ndef simple_graph.degree_multiset (G : simple_graph V) [decidable_rel G.adj] : multiset ℕ := finset.univ.val.map (λ v, G.degree v)\n\ndef simple_graph.degree_sequence (G : simple_graph V) [decidable_rel G.adj] : list ℕ := G.degree_multiset.sort (≥)\n-- test out definition - good for algebraic graph theory? - look through lecture notes\n\n--variables (l : list ℕ) [l.sorted (≥)] \n\n-- in pseudocode,\n-- a multiset ℕ is graphic if it is the degree sequence of some graph `G`\ndef graphic' (s : multiset ℕ) : Prop := ∃ (G : simple_graph V) [decidable_rel G.adj], by exactI s = G.degree_multiset\n\n-- a sorted list is graphic if blah blah\ndef graphic (l : list ℕ) : Prop := ∃ (n : ℕ) (G : simple_graph $ fin n) [decidable_rel G.adj], by exactI l = G.degree_sequence\n\n-- theorem statement from wikipedia:\n/-\nLet `S = (d_{1},\\dots ,d_{n})` be a finite list of nonnegative integers that is nonincreasing. \nList `S` is graphic if and only if the finite list `S' = (d_{2}-1,d_{3}-1,\\dots ,d_{{d_{1}+1}}-1,d_{{d_{1}+2}},\\dots ,d_{n})` \nhas nonnegative integers and is graphic.\n-/\nvariables (S : list ℕ) (h : S.sorted (≥))\n\ndef simple_graph.degree' (G : simple_graph V) [decidable_rel G.adj] : V → ℕ := λ v, G.degree v\n\ntheorem havel_hakimi_A : graphic S → (S.head ≤ (S.filter (λ n, 0 < n)).length) ∧ graphic ((havel_hakimi_step S h).sort (≥)) :=\nbegin\n  intros h2, \n  split,\n  { -- this is just the fact that S.head is largest degree, so the vertex with that degree is adjacent \n    -- to S.head many vertices, which then means that they have degree at least 1\n    rcases h2 with ⟨n, G, hdec, hds⟩,\n    have h3 : S.head = (@simple_graph.degree_sequence (fin n) _ G hdec).head,\n    exact congr_arg list.head hds,\n    let d1 := (@simple_graph.degree_sequence (fin n) _ G hdec).head,\n    -- let v1 := simple_graph.degree_multiset⁻¹ G d1, -- how to get to the preimage of the map in degree_multiset\n    sorry },\n  { -- the proof here is that performing the algorithm step is allowed because you can do the edge swap\n    sorry }, \nend\n\nlemma havel_hakimi_B : (S.head ≤ (S.filter (λ n, 0 < n)).length) ∧ graphic ((havel_hakimi_step S h).sort (≥)) →  graphic S :=\nbegin\n  intros h2,\n  rcases h2 with ⟨hnneg, n, G, hdec, hds⟩,\n  sorry,\nend\n\ntheorem havel_hakimi : graphic S ↔ (S.head ≤ (S.filter (λ n, 0 < n)).length) ∧ graphic ((havel_hakimi_step S h).sort (≥)) :=\n ⟨havel_hakimi_A S h, havel_hakimi_B S h⟩\n\nvariables (G : simple_graph V) [decidable_eq V] (v w x y : V) \nvariables (h1 : G.adj v w) (h2 : G.adj x y) (hn1 : ¬ G.adj v x) (hn2 : ¬ G.adj w y)\n\ndef new_graph : simple_graph V := \n{ adj := λ a b, if (((a = v) ∧ (b = w)) ∨ ((a = v) ∧ (b = x)) ∨ (((a = w) ∧ (b = y)) ∨ ((a = x) ∧ (b = y)))) then ¬ G.adj a b \n                else G.adj a b, \n  -- there's gotta be a better way of doing this\n  sym := λ a b,\n  begin\n    simp,\n    intros h,\n    sorry,\n  end,\n  loopless := sorry, }\n\n/-def new_graph : simple_graph V := \n{ adj := λ a b, if ((a ≠ v) ∧ (a ≠ w)) ∨ ((b ≠ x) ∧ (b ≠ y)) then G.adj a b \n                else ¬ G.adj a b, \n  -- there's gotta be a better way of doing this\n  sym := λ a b,\n  begin\n    simp,\n    intros h,\n  end,\n  loopless := _ }-/\n\n-- okay shit this is gonna be annoying\n\n-- going to need to show that the max degree is le the number of remaining vertices\n\n-- sequence D is graphic if ∃ (G : simple_graph V), D is deg seq for G\n\n-- for proof, need to define swapping edge algo\n  -- BUT FIRST we need to define edge deletion lmao", "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-688/lectures/lec-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7546532626723896}}
{"text": "\n\ntheorem Ex013(a b : Prop): (a → b) → (¬b → ¬a) := \n  assume H1:a → b,\n    assume H2:¬b,\n    show ¬a, from not.intro\n    (\n      assume H3:a,\n      have b,from H1 H3,\n      show false, from H2 this\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/Ex013.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517072737735, "lm_q2_score": 0.785308580887758, "lm_q1q2_score": 0.7546436215408353}}
{"text": "import analysis.specific_limits\nimport data.int.parity\nimport topology.sequences\n\nattribute [instance] classical.prop_decidable\n\n/- \nLemmas from that file were hidden in my course, or restating things which\nwere proved without name in previous files.\n-/\n\nnotation `|`x`|` := abs x\n\n-- The mathlib version is unusable because it is stated in terms of ≤\nlemma ge_max_iff {α : Type*} [linear_order α] {p q r : α} : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\n/- No idea why this is not in mathlib-/\nlemma eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h, \n  apply eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\nlemma unique_limit {u l l'} : seq_limit u l → seq_limit u l' → l = l' :=\nbegin\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros ε ε_pos,\n  specialize hl (ε/2) (by linarith),\n  cases hl with N hN,\n  specialize hl' (ε/2) (by linarith),\n  cases hl' with N' hN',\n  specialize hN (max N N') (le_max_left _ _),\n  specialize hN' (max N N') (le_max_right _ _),\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring\n  ... ≤ |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  ... ≤ ε/2 + ε/2 : by linarith\n  ... = ε : by ring,\nend\n\nlemma le_of_le_add_all {x y : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\ndef upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y\n\nlemma lt_sup {A : set ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\nlemma squeeze {u v w : ℕ → ℝ} {l} (hu : seq_limit u l) (hw : seq_limit w l)\n(h : ∀ n, u n ≤ v n)\n(h' : ∀ n, v n ≤ w n) : seq_limit v l :=\nbegin\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases hw ε ε_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 ; linarith\nend\n\ndef extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m\n\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\nlemma lim_le {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\nlemma inv_succ_le_all :  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    intros h ε ε_pos,\n    cases h (ε/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n    specialize hN n hn,\n    linarith,\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\nlemma limit_const (x : ℝ) : seq_limit (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\nlemma limit_of_sub_le_inv_succ {u : ℕ → ℝ} {x : ℝ} (h : ∀ n, |u n - x| ≤ 1/(n+1)) :\nseq_limit u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\nlemma limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ; linarith [@nat.one_div_pos_of_nat ℝ _ n])\n\nlemma limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\nlemma id_le_extraction {φ}: extraction φ → ∀ n, n ≤ φ 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\nlemma seq_limit_id : tendsto_infinity (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N, exact_mod_cast hn, \n  linarith,\nend\n\nvariables {u : ℕ → ℝ} {l : ℝ} {φ : ℕ → ℕ}\n\nopen set filter\n\ndef cluster_point (u : ℕ → ℝ) (a : ℝ) :=\n∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a\n\nlemma bolzano_weierstrass {a b : ℝ} {u : ℕ → ℝ} (h : ∀ n, u n ∈ Icc a b) :\n∃ c ∈ Icc a b, cluster_point u c :=\nbegin\n  rcases (compact_Icc : is_compact (Icc a b)).tendsto_subseq h with ⟨c, c_in, φ, hφ, lim⟩,\n  use [c, c_in, φ, hφ],\n  simp_rw [metric.tendsto_nhds, eventually_at_top, real.dist_eq] at lim,\n  intros ε ε_pos,\n  rcases lim ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  exact le_of_lt (hN n hn)\nend\n\nlemma not_seq_limit_of_tendstoinfinity {u : ℕ → ℝ} :\n  tendsto_infinity u → ∀ x, ¬ seq_limit u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\nopen real \n\nlemma sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :\n  ∃ x ∈ Icc a b, is_sup A x :=\nbegin\n  have b_maj :  ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : upper_bound A (Sup A),\n  { intro x,\n    apply real.le_Sup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply Sup_le_ub A hnonvide b_maj } },\n  { use Sup_maj,\n    intros y y_in,\n    rwa real.Sup_le _ hnonvide ⟨b, b_maj⟩ },\nend\n\nlemma subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn \n     ... ≤ φ n : id_le_extraction hφ n, \nend\nnamespace tactic.interactive\nopen tactic\n\nmeta def check_me : tactic unit :=\n`[ { repeat { unfold seq_limit},\n   repeat { unfold continue_en },\n   push_neg,\n   try { simp only [exists_prop] },\n   try { exact iff.rfl },\n   done } <|> fail \"That's not quite right. Please try again.\" ]\n\nend tactic.interactive\n", "meta": {"author": "Seeram", "repo": "Lean-proof-assistant", "sha": "e672d46e0e5f39d8de2933ad4f4cac095ca6094f", "save_path": "github-repos/lean/Seeram-Lean-proof-assistant", "path": "github-repos/lean/Seeram-Lean-proof-assistant/Lean-proof-assistant-e672d46e0e5f39d8de2933ad4f4cac095ca6094f/tutorials/src/solutions/tuto_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319863, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7545239668839085}}
{"text": "/- # LoVe Exercise 3: Forward Proofs -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n/- ## Question 1: Connectives and Quantifiers\n1.1. Supply structured proofs of the following lemmas. -/\n\nlemma I (a : Prop) :\n  a → a :=\nassume ha,\nha\n\nlemma K (a b : Prop) :\n  a → b → b :=\nassume ha,\nassume hb,\nhb\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nassume habc,\nassume b,\nassume a,\nhabc a b\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nassume ha,\nassume ha2,\nha\n\n/- Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nassume ha,\nI (a)\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nassume habc,\nassume ha,\nassume hac,\nassume hb,\nhac ha\n\n/- 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nassume hab,\nassume hnob,\nassume ha,\nhnob (hab (ha))\n\n/- 1.3. Supply a structured proof of the distributivity of `∀` over `∧`. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\niff.intro\n(\n  assume h1,\n  and.intro \n  (\n    assume x,\n    and.elim_left (h1 x)\n  )\n  (\n    assume x,\n    and.elim_right (h1 x)\n  )\n)\n(\n  assume h1,\n  assume x,\n  and.intro \n  (\n    and.elim_left h1 x\n  ) \n  (\n    and.elim_right h1 x\n  )\n)\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 {α : Type} (r s : α → α → Prop) :\n  (∀x, r x x ∧ s x x) ↔ (∀x, r x x) ∧ (∀x, s x x) :=\nforall_and (λ x:α, r x x)(λ x:α, s x x)\n\n\n/- ## Question 2: Chain of Equalities\n2.1. Write the following proof using `calc`.\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`\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 : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\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₂ (a b : ℕ) :\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₃ (a b : ℕ) :\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\n3.1 (**optional**). Prove that the following wrong formulation of the one-point\nrule for `∀` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {α : Type} {t : α} {p : α → Prop} :\n  (∀x : α, x = t ∧ p x) ↔ p t\n\nlemma proof_of_false :\n  false :=\nbegin\n  have wrong : (∀x, x = 0 ∧ true) ↔ true :=\n    @forall.one_point_wrong ℕ 0 (λ_, 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 `∃` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {α : Type} {t : α} {p : α → Prop} :\n  (∃x : α, x = t → p x) ↔ p t\n\nlemma proof_of_false₂ :\n  false :=\nbegin\n  have wrong : (∃x, x ≠ 0) ↔ false :=\n    @exists.one_point_wrong ℕ 0 (λ_, false),\n  simp at wrong,\n  have one_eq_zero : 1 = 0 :=\n    wrong 1,\n  cc\nend\n\nend LoVe", "meta": {"author": "raulmom", "repo": "Colab", "sha": "6c0b668e7ac308047faa34b21bb06759ef0b9f6c", "save_path": "github-repos/lean/raulmom-Colab", "path": "github-repos/lean/raulmom-Colab/Colab-6c0b668e7ac308047faa34b21bb06759ef0b9f6c/UACourse/Tema_3/Exercise_3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7545162198669778}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que, para todo a ∈ ℝ, la función constante\n--    s(x) = a\n-- converge a a.\n-- ----------------------------------------------------------------------\n\nimport .Definicion_de_convergencia\n\nlemma converges_to_const\n  (a : ℝ)\n  : converges_to (λ x : ℕ, a) a :=\nbegin\n  intros ε εpos,\n  use 0,\n  intros n nge,\n  dsimp,\n  rw sub_self,\n  rw abs_zero,\n  exact εpos,\nend\n\n-- Prueba\n-- ======\n\n/-\na : ℝ\n⊢ converges_to (λ (x : ℕ), a) a\n  >> intros ε εpos,\na ε : ℝ,\nεpos : ε > 0\n⊢ ∃ (N : ℕ), ∀ (n : ℕ), n ≥ N → abs ((λ (x : ℕ), a) n - a) < ε\n  >> use 0,\n⊢ ∀ (n : ℕ), n ≥ 0 → abs ((λ (x : ℕ), a) n - a) < ε\n  >> intros n nge,\nn : ℕ,\nnge : n ≥ 0\n⊢ abs ((λ (x : ℕ), a) n - a) < ε\n  >> dsimp,\n⊢ abs (a - a) < ε\n  >> rw sub_self,\n⊢ abs 0 < ε\n  >> rw abs_zero,\n⊢ abs 0 < ε\n  >> exact εpos,\nno goals\n-/\n\n-- Comentario: Se han usado los lemas\n-- + sub_self a : a - a = 0\n-- + abs_zero : abs 0 = 0\n\nvariables (a : ℝ)\n-- #check @sub_self _ _ a\n-- #check @abs_zero _ _\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_de_la_funcion_constante.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7545162174451483}}
{"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`Level_01_of_real.lean`\n`Level_02_I.lean`\n`Level_03_conj.lean`\n`Level_04_norm_sq.lean`\n`Level_05_field.lean`\n`Level_06_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\n  numbers, the real part and the imaginary part of the complex numberd. -/\nstructure complex : Type :=\n(re : ℝ) (im : ℝ)\n\n-- Let's use the usual notation for the complex numbers\nnotation `ℂ` := complex\n\n-- You make the complex number with real part 3 and imaginary part 4 like this:\nexample : ℂ :=\n{ re := 3,\n  im := 4 }\n\n-- Or like this:\nexample : ℂ := complex.mk 3 4\n\n-- or like this:\nexample : ℂ := ⟨3, 4⟩\n\n-- They all give the same complex number.\n\nexample : complex.mk 3 4 = ⟨3, 4⟩ := 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 : ℝ := re(mk 3 4) -- this term is (3 : ℝ)\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 : ℂ) : 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 ℂ -/\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 : ℂ := ⟨0, 0⟩\n\n-- Now we set up notation so that `0 : ℂ` will mean `zero`. \n\n/-- notation `0` for `zero` -/\ninstance : has_zero ℂ := ⟨zero⟩\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 : ℂ) = 0 := begin refl end\n@[simp] lemma zero_im : im(0 : ℂ) = 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 : ℂ := ⟨1, 0⟩\n\n/-- Notation `1` for `one` -/\ninstance : has_one ℂ := ⟨one⟩ \n\n-- name the basic properties and tag them with `simp`\n@[simp] lemma one_re : re(1 : ℂ) = 1 := begin refl end\n@[simp] lemma one_im : im(1 : ℂ) = 0 := begin refl end\n\n\n\n\n/-! ## add (+) -/\n\n-- Now let's define addition\n\n/-- addition `z+w` of complex numbers -/\ndef add (z w : ℂ) : ℂ := ⟨z.re + w.re, z.im + w.im⟩\n\n/-- Notation `+` for addition -/\ninstance : has_add ℂ := ⟨add⟩\n\n-- basic properties\n@[simp] lemma add_re (z w : ℂ) : re(z + w) = re(z) + re(w) := begin refl end\n@[simp] lemma add_im (z w : ℂ) : 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 : ℂ) : ℂ := ⟨-re(z), -im(z)⟩\n\n/-- Notation `-` for negation -/\ninstance : has_neg ℂ := ⟨neg⟩\n\n-- how neg interacts with re and im\n@[simp] lemma neg_re (z : ℂ) : re(-z) = -re(z) := begin refl end\n@[simp] lemma neg_im (z : ℂ) : 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 : ℂ) : ℂ :=\n  ⟨re(z) * re(w) - im(z) * im(w), re(z) * im(w) + im(z) * re(w)⟩\n\n/-- Notation `*` for multiplication -/\ninstance : has_mul ℂ := ⟨mul⟩\n\n-- how `mul` reacts with `re` and `im`\n@[simp] lemma mul_re (z w : ℂ) : re(z * w) = re(z) * re(w) - im(z) * im(w) :=\nbegin\n  refl\nend\n\n@[simp] lemma mul_im (z w : ℂ) : im(z * w) = re(z) * im(w) + im(z) * re(w) :=\nrfl\n\n/-! ## Example of what `simp` can now do\n\nexample (a b c : ℂ) :\n  re(a*(b+c)) = re(a) * (re(b) + re(c)) - im(a) * (im(b) + im(c)) :=\nbegin\n  simp,\nend\n\n-/\n\n\n/-! # `ext` : A mathematical triviality -/\n\n/- \nTwo complex numbers with the same and imaginary parts are equal. This is an\n\"extensionality lemma\", i.e. a lemma of the form \"if two things are made from\nthe same pieces, they are equal\". This is not hard to prove, but we want to\ngive the result a name so we can tag it with the `ext` attribute, meaning that\nthe `ext` tactic will know it. To add to the confusion, let's call the\ntheorem `ext` :-)\n-/\n\n/-- If two complex numbers z and w have equal real and imaginary parts,\n    they are equal -/\n@[ext] theorem ext {z w : ℂ}\n  (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 *,\nend\n\n/-! # Theorem:  The complex numbers are a commutative ring\n\nProof: we've defined all the structure, and every axiom can be checked by\nreducing it to checking real and imaginary parts with `ext`, expanding\neverything out with `simp`, and then using the fact that the real numbers are\na commutative ring (which we already know)\n\n-/\n\n/-- The complex numbers are a commutative ring -/\ninstance : comm_ring ℂ :=\nbegin\n  -- first the data\n  refine_struct {\n      zero := (0 : ℂ), add := (+), neg := has_neg.neg, one := 1, mul := (*),\n  ..};\n  -- now the axioms\n  -- of which there seem to be 11\n  -- Note the semicolons, which mean \"apply next tactic to all goals\".\n\n  -- First introduce the variables\n  intros;\n  -- we now have to prove an equality between two complex numbers.\n  -- It suffices to check on real and imaginary parts\n  ext;\n  -- the simplifier can simplify stuff like re(a+0)\n  simp;\n  -- all the goals now are identities between *real* numbers,\n  -- and the reals are already known to be a ring\n  ring,\nend\n\n\n/-\n\nThat is the end of the proof that the complexes form a ring. We built\na basic API which was honed towards the general idea that to prove\ncertain statements about the complex numbers, for example distributivity,\nwe could just check on real and imaginary parts. We trained the\nsimplifier to expand out things like re(z*w) in terms\nof re(z), im(z), re(w), im(w).\n\n-/\n\n/-!\n\n# Optional (for mathematicians) : more basic infrastructure, and term mode\n\n-/\n\n/-! \n## `ext` revisited\n\nRecall extensionality:\n\ntheorem ext {z w : ℂ}\n  (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' : ∀ z w : ℂ, z.re = w.re → z.im = w.im → z = w :=\nbegin\n  rintros ⟨zr, zi⟩ ⟨_, _⟩ ⟨rfl⟩ ⟨rfl⟩,\n  refl,\nend\n\n\n/-!\n\nExplanation: `rintros` does `cases` as many times as you like using this cool\n`⟨ ⟩` syntax for the case splits. Note that if you say that a proof of `a = b`\nis `rfl` then Lean will define a to be b, or b to be a, and not even introduce\nnew notation for it.\n\n-/\n\n-- Here is the same proof in term mode.\n\ntheorem ext'' : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w\n| ⟨zr, zi⟩ ⟨_, _⟩ 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/-- ⟨z.re, z.im⟩ is equal to z -/\n@[simp] theorem eta : ∀ z : ℂ, 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' : ∀ z : ℂ, complex.mk z.re z.im = z\n| ⟨x, y⟩ := 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\nproduced by this one\"\n-/\n\ntheorem ext_iff {z w : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=\nbegin\n  split,\n  { intro H,\n    simp [H]},\n  {\n    rintro ⟨hre, him⟩,\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 : ℂ} : z = w ↔ z.re = w.re ∧ z.im = w.im :=\n⟨λ H, by simp [H], and.rec ext⟩\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`⟨z.re, z.im⟩ = 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/src/complex/Level_00_basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7545162088227515}}
{"text": "import tactic tactic.explode\n\nopen classical\n\n/- Fill in the `sorry`s below -/\n\nlocal attribute [instance, priority 0] prop_decidable\n\nexample (p : Prop) : p ∨ ¬ p :=\nbegin\n  by_cases p,\n  { left, assumption },\n  { right, assumption }\nend\n\n\n\nexample (p : Prop) : p ∨ ¬ p :=\nbegin\n  by_cases h' : p,\n  { left, exact h' },\n  { right, exact h' }\nend\n\nexample (p : Prop) : p ∨ ¬ p :=\nbegin\n  by_cases h' : p,\n  { exact or.inl h' },\n  { exact or.inr h' }\nend\n\n/-\nGive a calculational proof of the theorem log_mul below. You can use the \nrewrite tactic `rw` (and `calc` if you want), but not `simp`.\n\nThese objects are actually defined in mathlib, but for now, we'll\njust declare them.\n-/\n\nconstant real : Type\n@[instance] constant  orreal : ordered_ring real\nconstants (log exp : real → real)\nconstant  log_exp_eq : ∀ x, log (exp x) = x\nconstant  exp_log_eq : ∀ {x}, x > 0 → exp (log x) = x\nconstant  exp_pos    : ∀ x, exp x > 0\nconstant  exp_add    : ∀ x y, exp (x + y) = exp x * exp y\n\nattribute [ematch] 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 ‹_›\n\ntheorem log_mul' {x y : real} (hx : x > 0) (hy : y > 0) :\n  log (x * y) = log x + log y :=\nbegin\n  rw[<-exp_log_eq hx, <-exp_log_eq hy, <-exp_add],\n  simp only [log_exp_eq]\nend\n\n\nsection\n\nvariables {p q r : Prop}\n\nexample : (p → q) → (¬q → ¬p) :=\nby finish\n\nexample : (p → (q → r)) → (p ∧ q → r) :=\nby finish\n\nexample : p ∧ ¬q → ¬(p → q) :=\nby finish\n\nexample : (¬p ∨ q) → (p → q) :=\nby intros; cc\n\nexample : (p ∨ q → r) → (p → r) ∧ (q → r) :=\nby intros; finish\n\nexample : (p → q) → (¬p ∨ q) :=\nby intros; finish\n\nend\n\nsection\n\nvariables {α β : Type} (p q : α → Prop) (r : α → β → Prop)\n\nexample : (∀ x, p x) ∧ (∀ x, q x) → ∀ x, p x ∧ q x :=\nbegin\n  intros a x, cases a, fsplit, work_on_goal 0 { solve_by_elim }, solve_by_elim\nend\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\nbegin\n  intro H, cases H, tidy, left, finish, right, finish\nend\n\nexample : (∃ x, ∀ y, r x y) → ∀ y, ∃ x, r x y :=\nbegin\n  intro H, cases H,\n  /- `tidy` says -/ intros y, fsplit, work_on_goal 1 { solve_by_elim }\nend\n\ntheorem e1 : (¬ ∃ x, p x) → ∀ x, ¬ p x :=\nbegin\n  intro H, push_neg at H, exact H\nend\n\nexample : (¬ ∀ x, ¬ p x) → ∃ x, p x :=\nbegin\n  intro H, push_neg at H, from ‹_›\nend\n\nexample : (¬ ∀ x, ¬ p x) → ∃ x, p x :=\nbegin\n  intro H, push_neg at H, from ‹_›\nend\n\nend\n\nsection\n\n/-\nThere is a man in the town who is the barber. The barber shaves all men who do not shave themselves.\n\nDoes the barber shave himself?\n-/\n\nvariables (man : Type) (barber : man)\nvariable  (shaves : man → man → Prop)\n\nexample (H : ∀ x : man, shaves barber x ↔ ¬ shaves x x) : false :=\nby {[smt] eblast_using[H barber]}\n\nend\n\nsection\n\nvariables {α : Type} (p : α → Prop) (r : Prop) (a : α)\n\ninclude a\nexample : (r → ∃ x, p x) → ∃ x, (r → p x) :=\nbegin\n  by_cases r,\n    {intro H, specialize H ‹_›, cases H with x Hx,\n    use x, intro, from ‹_›},\n  \n    {intro H, use a}\nend\n\nend\n\n/-\nProve the theorem below, using only the ring properties of ℤ enumerated \nin Section 4.2 and the theorem sub_self. You should probably work out \na pen-and-paper proof first.\n-/\n\nexample (x : ℤ) : x * 0 = 0 :=\nby simp\n\nsection\nopen list\n\nvariable {α : Type*}\nvariables s t : list α \nvariable a : α\n\nexample : length (s ++ t) = length s + length t :=\nby simp\n\nend\n\n/-\nDefine an inductive data type consisting of terms built up from the \nfollowing constructors:\n\n  `const n`, a constant denoting the natural number n\n  `var n`, a variable, numbered n\n  `plus s t`, denoting the sum of s and t\n  `times s t`, denoting the product of s and t\n-/\n\ninductive nat_term\n| const : ℕ → nat_term\n| var : ℕ → nat_term\n| plus : nat_term → nat_term → nat_term\n| times : nat_term → nat_term → nat_term\n\nopen nat_term\n\n/-\nRecursively define a function that evaluates any such term with respect to \nan assignment `val : ℕ → ℕ` of values to the variables.\n\nFor example, if `val 4 = 3\n-/\n\ndef eval (val : ℕ → ℕ) : nat_term → ℕ\n| (const k) := k\n| (var k) := val k\n| (plus s t) := (eval s) + (eval t)\n| (times s t) := (eval s) * (eval t)\n\n/-\nTest it out by using #eval on some terms. You can use the following `val` function. In that case, for example, we would expect to have\n\n  eval val (plus (const 2) (var 1)) = 5\n-/\n\ndef val : ℕ → ℕ \n| 0 := 4\n| 1 := 3\n| 2 := 8\n| _ := 0\n\nexample : eval val (plus (const 2) (var 1)) = 5 := rfl\n\n#eval eval val (plus (const 2) (var 1))\n\n\n/-\nBelow, we define a function `rev` that reverses a list. It uses an auxiliary function\n`append1`. \n\nIf you can, prove that the length of the list is preserved, and that\n`rev (rev l) = l` for every `l`. The theorem below is given as an example, and should\nbe helpful. \n\nNote that when you use the equation compiler to define a function foo, `rw [foo]` uses\none of the defining equations if it can. For example, `rw [append1, ...]` in the theorem\nuses the second equation in the definition of `append1`\n-/\n\nsection\n\nopen list\nvariable {α : Type*}\n\ndef append1 (a : α) : list α → list α \n| nil      := [a]\n| (b :: l) := b :: (append1 l)\n\ndef rev : list α → list α\n| nil := nil\n| (a :: l) := append1 a (rev l)\n\ntheorem length_append1 (a : α) (l : list α): length (append1 a l) = length l + 1 :=\nbegin\n  induction l,\n    { simp[append1] },\n    { unfold append1 at l_ih ⊢, finish }\nend\n\ntheorem length_rev (l : list α) : length (rev l) = length l :=\nbegin\n  induction l,\n    { unfold rev },\n    { unfold rev, finish[length_append1] }\nend\n\nlemma hd_rev (a : α) (l : list α) :\n  a :: rev l =  rev (append1 a l) :=\nbegin\n  induction l,\n    { simp[rev, append1] },\n    { rw[rev, append1, rev, <-l_ih, append1] }\nend\n\ntheorem rev_rev (l : list α) : rev (rev l) = l :=\nbegin\n  induction l,\n    { refl },\n    { conv {to_rhs, rw[<-l_ih], rw[hd_rev]}, refl }\nend\n\nend\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/jesse/exercises-day-one-solutions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7545162080654416}}
{"text": "/- LoVe Homework 2: Tactical Proofs -/\n\nimport .love02_tactical_proofs_exercise\n\nnamespace LoVe\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) : ¬¬ (¬¬ p → p) :=\nbegin\n  intro hnnnpp,\n  apply hnnnpp,\n  intro hnnp,\n  apply false.elim,\n  apply hnnp,\n  intro hp,\n  apply hnnnpp,\n  intro hnnp,\n  exact hp\nend\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 ∨ ¬ 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 → excluded_middle :=\nbegin\n  simp [double_negation, excluded_middle],\n  intros hdoubleneg p,\n  apply hdoubleneg,\n  intro hnponp,\n  apply hnponp,\n  apply or.intro_right,\n  intro hnp,\n  apply hnponp,\n  apply or.intro_left,\n  assumption\nend\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\nlemma dn_imp_peirce : double_negation → peirce :=\nbegin\n  intro h,\n  apply peirce_of_em,\n  apply em_of_dn,\n  exact h\nend\n\nlemma peirce_imp_em : peirce → excluded_middle :=\nbegin\n  intro h,\n  apply em_of_dn,\n  apply dn_of_peirce,\n  exact h\nend\n\nlemma em_imp_dn : excluded_middle → double_negation :=\nbegin\n  intro h,\n  apply dn_of_peirce,\n  apply peirce_of_em,\n  exact h\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/love02_tactical_proofs_homework_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.8519528000888386, "lm_q1q2_score": 0.7545162062510223}}
{"text": "import ring_theory.localization.basic\n\nopen is_localization\n\nvariables {A : Type*} (B : Type*) [comm_ring A] [comm_ring B] [algebra A B]\nvariables {S : submonoid A} [is_localization S B]\n-- L'hypothèse `is_localization S B` signifie que `B=S⁻¹ A`.\n/-- The typeclass `is_localization (S : submodule A) B` where `B` is an `A`-algebra\nexpresses that `B` is isomorphic to the localization of `A` at `S`. -/\n\nlemma prod_units (u v : A) : is_unit u → is_unit v → is_unit (u * v) :=\nbegin\n  intros hu hv,\n  simp only [is_unit.mul_iff],\n  split,\n  exact hu,\n  exact hv,\nend\n\nvariable (f : A →+* A)\n#check (f : A →+ A)\n#check (f: A → A)\n\nlemma inv_unit (u v : Aˣ) : is_unit (u⁻¹) :=\nbegin\n  use u⁻¹,\n  use u,\n  exact mul_left_inv u, --mais `simp` aurait marché! Et si vous écrivez `squeeze_simp` il vous dit\n  --comment il a fait! Pensez bien que si on doit suffrir pour montrer que dans un groupe le produit\n  -- d'un élément avec son inverse fait l'identité, on peut se tirer une balle! C'est fort probablement\n  -- quelque chose que `simp` doit savoir résoudre!\n\n  exact mul_right_inv u,\n  simp only [units.coe_mk],\nend\n\nexample (a : S) : is_unit (algebra_map A B a) :=\nbegin\n  apply map_units,\nend\n\nlemma becomes_unit (a : A) : a ∈ S → is_unit (algebra_map A B a) :=\nbegin\n  intro ha,\n -- J'imagine qu'on est d'accord qu'il faut \"en gros\" faire la même chose que dans l'`exemple l.36`:\n -- Le problème est que si on fait\n--  `apply map_units`, --on reçoit l'erreur\n--  `invalid apply tactic, failed to unify`\n--   `is_unit (⇑(algebra_map A B) a)` \n--  \t `with`\n--   `is_unit (⇑(algebra_map ?m_3 ?m_1) ↑?m_7)`\n-- Essayons de le comprendre: on voudrait `?m_3=A`, puis `?m_1=B` et `↑?m_7=a`. Pour voir ce qui\n-- se passe, il est parfois commode d'utiliser un `have :=`, qui ne mène nulle part mais nous fait\n-- voir ce que Lean attend: par exemple,\n-- have premier := map_units,\n-- fait apparaître un terme `premier` qui demande clairement en variables un Type `S` qui doit être un\n-- `comm_semiring`, puis un terme `?m_1` qui n'apparaît pas mais dont on comprend que `S` doit\n-- être une algèbre sur `?m_1` (regardez `_inst_3`), et après un terme `self` qui doit être une\n-- preuve que `S` est un localisé à `?m_3`. Ces variables bizarres sont nommées ainsi automatiquement\n-- par Lean, parce que si on lui fournit un terme de type `is_localization ?m_3 S` il comprendra qui\n-- est `?m_3`. Chez nous, `B` est un localisé de `A` à `S`, donc à la fin on voudra\n-- * ?m_1=A\n-- * ?m_3=S\n-- * S = B\n-- On peut alors améliorer `premier` en\n-- have deuxieme := map_units B,\n-- et on aurait même envie de prendre `y = a` maintenant... *MAIS* on voit bien que `y` doit être un\n-- terme de type `↥?m_3 = ↥S` et non pas de type `S`... il y a une flèchette vers le haut. En effet\n-- `have := deuxieme a,`\n-- (que je vous conseille de tester) donne un erreur. D'ailleurs, vous voyez que si vous\n-- clickez sur `↥?m_3` vous voyez que ça doit être un `Type` alors que `?m_3` est un `submonoid`...\n-- Le point est que `a` est un terme de type `A` et `deuxieme` veut un terme de type `S`: on peut le\n-- créer!\nlet b : S := ⟨a, ha⟩,\n-- Grâce à `ha`, qui nous dit que `a` *appartient* à `S`, on a crée un terme de type `↥S`, où la\n-- flêche indique qu'on regarde maintenant `S` comme un type à part entière. On peut donc conclure\n-- avec\n  exact map_units B b,\n  -- (si vous voyez plein de goals, encore, c'est parce que j'ai introduit plein de choses à vérifier\n  -- dans `premier` et `deuxième`: si vous les commentez, vous voyez le `goals_accomplished`.\n  -- D'ailleurs, on a pas besoin de déclarer `b`: on pourrait simplement faire\n  -- exact map_units B ⟨a, ha⟩),\nend\n\nlemma from_S (a : A) (v : B) (h : algebra_map A B a = v) : ∃ s : S, mk' B a s = v :=\nbegin\n use (1:S),\n rw mk'_eq_iff_eq_mul,\n rw ← h,\n simp only [submonoid.coe_one, map_one, mul_one],\nend\n\nlemma unit_from_S (a : A) (v : Bˣ) : a ∈ S → is_unit ((algebra_map A B a) * v):=\nbegin\n  intro ha,\n  let b : S := ⟨a, ha⟩,\n  apply prod_units,\n  apply map_units B b,\n  simp only [units.is_unit],\nend\n\n/- J'admets avoir résolu les deux derniers exercices plutôt en déduisant de ce que je pouvais comprendre des\nlemmes de algebra_map et is_localization, qu'en les comprenant réellement -/\n\n\ninclude B\nvariables {C : Type*} [comm_ring C] \n/-\nCe qu' on est en train de dire dans la définition suivante est que si vous avez un morphisme\nd'anneaux `f : A → C` qui envoie tout élément de `S` sur une unité de `C`, alors vous pouvez étendre\n`f` à un morphisme `F : B=S⁻¹A → C`. Moralement, comme les éléments de `B` sont de la forme `a/s`\navec `a ∈ A` et `s ∈ S` vous pouvez définir l'extension `F` par la formule `F(a/s) = f(a)/f(s)` ce\nqui a un sens d'après l'hypothèse que `f(s)` est une unité.\n-/\n\ndef extended {f : A →+* C} (hf : ∀ s : S, is_unit (f s)) : (B →+* C) :=\n{ to_fun := λ b, f((sec S b).1) * ((hf (sec S b).2).unit)⁻¹.1,\n  map_one' := _,\n  map_mul' := _,\n  map_zero' := _,\n  map_add' := _ }\n\n--***Question:***: Savez-vous quelle est la différence entre les parenthèses `(` et `{`?\n/- les () sont des éléments nécessaires à rentre pour que lean comprenne de quoi on parle, les {} peuvent être déduit\ndes autres hypothèses -/\nlemma injective {f : A →+* C} (hf : ∀ s : S, is_unit (f s)) (h_inj: function.injective f) :\n  function.injective (extended B hf) := sorry\n", "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/Exercices/localisation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7545162045865029}}
{"text": "-- Contributors : Adarsh, Anurag, Nikhesh, Sainiranjan.\n\nimport Mathlib\nimport PnP2023.Lec_02_03.InductiveTypes\n\n/-!\nVectors, i.e., lists of a fixed length, can be defined in (at least) two ways. One way is as an indexed inductive type `Vec`, as we saw in lecture and is in the file `InductiveTypes.lean`. \n\nA different definition is as a subtype `Vector` of lists consisting of those of a fixed length. This is the definition used in `mathlib` and is recalled below.\n\n```lean\n/-- `Vector α n` is the type of lists of length `n` with elements of type `α`. -/\ndef Vector (α : Type u) (n : ℕ) :=\n  { l : List α // l.length = n }\n```\n\nIn this lab, you will relate the two definitions by constructing functions that convert between the two definitions and prove that these functions are inverses of each other.\n-/\nuniverse u\n\n/-- Convert a `Vector` to a `Vec` -/\ndef Vec.ofVector {α : Type u}: (n : ℕ) →  Vector α n → Vec α n \n| 0, _ => Vec.nil\n| k + 1, ⟨ head :: tail, h ⟩ => by\n  have h1 : tail.length = k := by\n    simp [List.length_cons] at h\n    assumption\n  apply Vec.cons head (Vec.ofVector k ⟨ tail, h1⟩ )\n\n/-- Convert a `Vec` to a `Vector` -/\ndef Vec.toVector {α : Type u}: (n : ℕ) →  Vec α n → Vector α n\n| 0, _ => ⟨ [], rfl ⟩\n| k + 1, Vec.cons head tail => ⟨ head :: (Vec.toVector k tail).val, by\n    simp [List.length]; apply (Vec.toVector k tail).property⟩ \n\n/-- Mapping a `Vec` to a `Vector` and back gives the original `Vec` -/\ntheorem Vec.ofVector.toVector {α : Type u} (n : ℕ) (v : Vec α n) :\n  Vec.ofVector n (Vec.toVector n v) = v := \n  match n with\n  | 0 => by\n    rw [Vec.ofVector]\n    match v with\n    | Vec.nil => rfl\n  \n  | k + 1 => by\n    match v with\n    | Vec.cons head tail => \n      simp [Vec.ofVector]  \n      apply Vec.ofVector.toVector k tail\n\n/-- Mapping a `Vector` to a `Vec` and back gives the original `Vector` -/\ntheorem Vec.toVector.ofVector {α : Type u} (n : ℕ) (v : Vector α n) :\n  Vec.toVector n (Vec.ofVector n v) = v := \n  match n with\n  | 0 => by\n    rw [Vec.toVector]\n    match v with\n    | Vector.nil => rfl\n  \n  | k + 1 => by\n    match v with\n    | ⟨ head :: tail, h⟩ =>\n      simp[toVector]\n      simp[ofVector]", "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/tester.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7544873970687306}}
{"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\n! This file was ported from Lean 3 source module algebra.ring.defs\n! leanprover-community/mathlib commit 76de8ae01554c3b37d66544866659ff174e66e1f\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.Algebra.GroupWithZero.Defs\nimport Mathlib.Data.Int.Cast.Defs\nimport Mathlib.Logic.Nontrivial\nimport Mathlib.Tactic.Spread\n\n/-!\n# Semirings and rings\n\nThis file defines semirings, rings and domains. This is analogous to `Algebra.Group.Defs` and\n`Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while\nthe present file is about their interaction.\n\n## Main definitions\n\n* `Distrib`: Typeclass for distributivity of multiplication over addition.\n* `HasDistribNeg`: Typeclass for commutativity of negation and multiplication. This is useful when\n  dealing with multiplicative submonoids which are closed under negation without being closed under\n  addition, for example `units`.\n* `(NonUnital_)(NonAssoc_)(Semi)ring`: Typeclasses for possibly non-unital or non-associative\n  rings and semirings. Some combinations are not defined yet because they haven't found use.\n\n## Tags\n\n`Semiring`, `CommSemiring`, `Ring`, `CommRing`, domain, `IsDomain`, nonzero, units\n-/\n\n\nuniverse u v w x\n\nvariable {α : Type u} {β : Type v} {γ : Type w} {R : Type x}\n\nopen Function\n\n/-!\n### `distrib` class\n-/\n\n\n/-- A typeclass stating that multiplication is left and right distributive\nover addition. -/\nclass Distrib (R : Type _) extends Mul R, Add R where\n  /-- Multiplication is left distributive over addition -/\n  protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c\n  /-- Multiplication is right distributive over addition -/\n  protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c\n#align distrib Distrib\n\n/-- A typeclass stating that multiplication is left distributive over addition. -/\nclass LeftDistribClass (R : Type _) [Mul R] [Add R] where\n  /-- Multiplication is left distributive over addition -/\n  protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c\n#align left_distrib_class LeftDistribClass\n\n/-- A typeclass stating that multiplication is right distributive over addition. -/\nclass RightDistribClass (R : Type _) [Mul R] [Add R] where\n  /-- Multiplication is right distributive over addition -/\n  protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c\n#align right_distrib_class RightDistribClass\n\n-- see Note [lower instance priority]\ninstance (priority := 100) Distrib.leftDistribClass (R : Type _) [Distrib R] : LeftDistribClass R :=\n  ⟨Distrib.left_distrib⟩\n#align distrib.left_distrib_class Distrib.leftDistribClass\n\n-- see Note [lower instance priority]\ninstance (priority := 100) Distrib.rightDistribClass (R : Type _) [Distrib R] :\n    RightDistribClass R :=\n  ⟨Distrib.right_distrib⟩\n#align distrib.right_distrib_class Distrib.rightDistribClass\n\ntheorem left_distrib [Mul R] [Add R] [LeftDistribClass R] (a b c : R) :\n    a * (b + c) = a * b + a * c :=\n  LeftDistribClass.left_distrib a b c\n#align left_distrib left_distrib\n\nalias left_distrib ← mul_add\n#align mul_add mul_add\n\ntheorem right_distrib [Mul R] [Add R] [RightDistribClass R] (a b c : R) :\n    (a + b) * c = a * c + b * c :=\n  RightDistribClass.right_distrib a b c\n#align right_distrib right_distrib\n\nalias right_distrib ← add_mul\n#align add_mul add_mul\n\ntheorem distrib_three_right [Mul R] [Add R] [RightDistribClass R] (a b c d : R) :\n    (a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib]\n#align distrib_three_right distrib_three_right\n\n/-!\n### Semirings\n-/\n\n\n/-- A not-necessarily-unital, not-necessarily-associative semiring. -/\nclass NonUnitalNonAssocSemiring (α : Type u) extends AddCommMonoid α, Distrib α, MulZeroClass α\n#align non_unital_non_assoc_semiring NonUnitalNonAssocSemiring\n\n/-- An associative but not-necessarily unital semiring. -/\nclass NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α\n#align non_unital_semiring NonUnitalSemiring\n\n/-- A unital but not-necessarily-associative semiring. -/\nclass NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α,\n    AddCommMonoidWithOne α\n#align non_assoc_semiring NonAssocSemiring\n\nclass Semiring (α : Type u) extends NonUnitalSemiring α, NonAssocSemiring α, MonoidWithZero α\n#align semiring Semiring\n\nsection DistribMulOneClass\n\nvariable [Add α] [MulOneClass α]\n\ntheorem add_one_mul [RightDistribClass α] (a b : α) : (a + 1) * b = a * b + b := by\n  rw [add_mul, one_mul]\n#align add_one_mul add_one_mul\n\ntheorem mul_add_one [LeftDistribClass α] (a b : α) : a * (b + 1) = a * b + a := by\n  rw [mul_add, mul_one]\n#align mul_add_one mul_add_one\n\ntheorem one_add_mul [RightDistribClass α] (a b : α) : (1 + a) * b = b + a * b := by\n  rw [add_mul, one_mul]\n#align one_add_mul one_add_mul\n\ntheorem mul_one_add [LeftDistribClass α] (a b : α) : a * (1 + b) = a + a * b := by\n  rw [mul_add, mul_one]\n#align mul_one_add mul_one_add\n\nend DistribMulOneClass\n\nsection NonAssocSemiring\n\nvariable [NonAssocSemiring α]\n\n-- Porting note: was [has_add α] [mul_one_class α] [right_distrib_class α]\ntheorem two_mul (n : α) : 2 * n = n + n :=\n  (congrArg₂ _ one_add_one_eq_two.symm rfl).trans <| (right_distrib 1 1 n).trans (by rw [one_mul])\n#align two_mul two_mul\n\n-- Porting note: was [has_add α] [mul_one_class α] [right_distrib_class α]\nset_option linter.deprecated false in\ntheorem bit0_eq_two_mul (n : α) : bit0 n = 2 * n :=\n  (two_mul _).symm\n#align bit0_eq_two_mul bit0_eq_two_mul\n\n-- Porting note: was [has_add α] [mul_one_class α] [left_distrib_class α]\ntheorem mul_two (n : α) : n * 2 = n + n :=\n  (congrArg₂ _ rfl one_add_one_eq_two.symm).trans <| (left_distrib n 1 1).trans (by rw [mul_one])\n#align mul_two mul_two\n\nend NonAssocSemiring\n\n@[to_additive]\ntheorem mul_ite {α} [Mul α] (P : Prop) [Decidable P] (a b c : α) :\n    (a * if P then b else c) = if P then a * b else a * c := by split_ifs <;> rfl\n#align mul_ite mul_ite\n#align add_ite add_ite\n\n@[to_additive]\ntheorem ite_mul {α} [Mul α] (P : Prop) [Decidable P] (a b c : α) :\n    (if P then a else b) * c = if P then a * c else b * c := by split_ifs <;> rfl\n#align ite_mul ite_mul\n#align ite_add ite_add\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 `∑ 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-- Porting note: no @[simp] because simp proves it\ntheorem mul_boole {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) :\n    (a * if P then 1 else 0) = if P then a else 0 := by simp\n#align mul_boole mul_boole\n\n-- Porting note: no @[simp] because simp proves it\ntheorem boole_mul {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) :\n    (if P then 1 else 0) * a = if P then a else 0 := by simp\n#align boole_mul boole_mul\n\ntheorem ite_mul_zero_left {α : Type _} [MulZeroClass α] (P : Prop) [Decidable P] (a b : α) :\n    ite P (a * b) 0 = ite P a 0 * b := by by_cases h : P <;> simp [h]\n#align ite_mul_zero_left ite_mul_zero_left\n\ntheorem ite_mul_zero_right {α : Type _} [MulZeroClass α] (P : Prop) [Decidable P] (a b : α) :\n    ite P (a * b) 0 = a * ite P b 0 := by by_cases h : P <;> simp [h]\n#align ite_mul_zero_right ite_mul_zero_right\n\ntheorem ite_and_mul_zero {α : Type _} [MulZeroClass α] (P Q : Prop) [Decidable P] [Decidable Q]\n    (a b : α) : ite (P ∧ Q) (a * b) 0 = ite P a 0 * ite Q b 0 := by\n  simp only [← ite_and, ite_mul, mul_ite, mul_zero, zero_mul, and_comm]\n#align ite_and_mul_zero ite_and_mul_zero\n\n/-- A non-unital commutative semiring is a `NonUnitalSemiring` with commutative multiplication.\nIn other words, it is a type with the following structures: additive commutative monoid\n(`AddCommMonoid`), commutative semigroup (`CommSemigroup`), distributive laws (`Distrib`), and\nmultiplication by zero law (`MulZeroClass`). -/\nclass NonUnitalCommSemiring (α : Type u) extends NonUnitalSemiring α, CommSemigroup α\n#align non_unital_comm_semiring NonUnitalCommSemiring\n\nclass CommSemiring (R : Type u) extends Semiring R, CommMonoid R\n#align comm_semiring CommSemiring\n\n-- see Note [lower instance priority]\ninstance (priority := 100) CommSemiring.toNonUnitalCommSemiring [CommSemiring α] :\n    NonUnitalCommSemiring α :=\n  { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with }\n#align comm_semiring.to_non_unital_comm_semiring CommSemiring.toNonUnitalCommSemiring\n\n-- see Note [lower instance priority]\ninstance (priority := 100) CommSemiring.toCommMonoidWithZero [CommSemiring α] :\n    CommMonoidWithZero α :=\n  { inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with }\n#align comm_semiring.to_comm_monoid_with_zero CommSemiring.toCommMonoidWithZero\n\nsection CommSemiring\n\nvariable [CommSemiring α] {a b c : α}\n\ntheorem add_mul_self_eq (a b : α) : (a + b) * (a + b) = a * a + 2 * a * b + b * b := by\n  simp only [two_mul, add_mul, mul_add, add_assoc, mul_comm b]\n#align add_mul_self_eq add_mul_self_eq\n\nend CommSemiring\n\nsection HasDistribNeg\n\n/-- Typeclass for a negation operator that distributes across multiplication.\n\nThis is useful for dealing with submonoids of a ring that contain `-1` without having to duplicate\nlemmas. -/\nclass HasDistribNeg (α : Type _) [Mul α] extends InvolutiveNeg α where\n  /-- Negation is left distributive over multiplication -/\n  neg_mul : ∀ x y : α, -x * y = -(x * y)\n  /-- Negation is right distributive over multiplication -/\n  mul_neg : ∀ x y : α, x * -y = -(x * y)\n#align has_distrib_neg HasDistribNeg\n\nsection Mul\n\nvariable [Mul α] [HasDistribNeg α]\n\n@[simp]\ntheorem neg_mul (a b : α) : -a * b = -(a * b) :=\n  HasDistribNeg.neg_mul _ _\n#align neg_mul neg_mul\n\n@[simp]\ntheorem mul_neg (a b : α) : a * -b = -(a * b) :=\n  HasDistribNeg.mul_neg _ _\n#align mul_neg mul_neg\n\ntheorem neg_mul_neg (a b : α) : -a * -b = a * b := by simp\n#align neg_mul_neg neg_mul_neg\n\ntheorem neg_mul_eq_neg_mul (a b : α) : -(a * b) = -a * b :=\n  (neg_mul _ _).symm\n#align neg_mul_eq_neg_mul neg_mul_eq_neg_mul\n\ntheorem neg_mul_eq_mul_neg (a b : α) : -(a * b) = a * -b :=\n  (mul_neg _ _).symm\n#align neg_mul_eq_mul_neg neg_mul_eq_mul_neg\n\ntheorem neg_mul_comm (a b : α) : -a * b = a * -b := by simp\n#align neg_mul_comm neg_mul_comm\n\nend Mul\n\nsection MulOneClass\n\nvariable [MulOneClass α] [HasDistribNeg α]\n\ntheorem neg_eq_neg_one_mul (a : α) : -a = -1 * a := by simp\n#align neg_eq_neg_one_mul neg_eq_neg_one_mul\n\n/-- An element of a ring multiplied by the additive inverse of one is the element's additive\n  inverse. -/\ntheorem mul_neg_one (a : α) : a * -1 = -a := by simp\n#align mul_neg_one mul_neg_one\n\n/-- The additive inverse of one multiplied by an element of a ring is the element's additive\n  inverse. -/\ntheorem neg_one_mul (a : α) : -1 * a = -a := by simp\n#align neg_one_mul neg_one_mul\n\nend MulOneClass\n\nsection MulZeroClass\n\nvariable [MulZeroClass α] [HasDistribNeg α]\n\ninstance (priority := 100) MulZeroClass.negZeroClass : NegZeroClass α where\n  __ := inferInstanceAs (Zero α); __ := inferInstanceAs (InvolutiveNeg α)\n  neg_zero := by rw [← zero_mul (0 : α), ← neg_mul, mul_zero, mul_zero]\n#align mul_zero_class.neg_zero_class MulZeroClass.negZeroClass\n\nend MulZeroClass\n\nend HasDistribNeg\n\n/-!\n### Rings\n-/\n\n\n/-- A not-necessarily-unital, not-necessarily-associative ring. -/\nclass NonUnitalNonAssocRing (α : Type u) extends AddCommGroup α, NonUnitalNonAssocSemiring α\n#align non_unital_non_assoc_ring NonUnitalNonAssocRing\n\n-- We defer the instance `NonUnitalNonAssocRing.toHasDistribNeg` to `Algebra.Ring.Basic`\n-- as it relies on the lemma `eq_neg_of_add_eq_zero_left`.\n/-- An associative but not-necessarily unital ring. -/\nclass NonUnitalRing (α : Type _) extends NonUnitalNonAssocRing α, NonUnitalSemiring α\n#align non_unital_ring NonUnitalRing\n\n/-- A unital but not-necessarily-associative ring. -/\nclass NonAssocRing (α : Type _) extends NonUnitalNonAssocRing α, NonAssocSemiring α,\n    AddCommGroupWithOne α\n#align non_assoc_ring NonAssocRing\n\nclass Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R\n#align ring Ring\n\nsection NonUnitalNonAssocRing\n\nvariable [NonUnitalNonAssocRing α]\n\ninstance (priority := 100) NonUnitalNonAssocRing.toHasDistribNeg : HasDistribNeg α where\n  neg := Neg.neg\n  neg_neg := neg_neg\n  neg_mul a b := eq_neg_of_add_eq_zero_left <| by rw [← right_distrib, add_left_neg, zero_mul]\n  mul_neg a b := eq_neg_of_add_eq_zero_left <| by rw [← left_distrib, add_left_neg, mul_zero]\n#align non_unital_non_assoc_ring.to_has_distrib_neg NonUnitalNonAssocRing.toHasDistribNeg\n\ntheorem mul_sub_left_distrib (a b c : α) : a * (b - c) = a * b - a * c := by\n  simpa only [sub_eq_add_neg, neg_mul_eq_mul_neg] using mul_add a b (-c)\n#align mul_sub_left_distrib mul_sub_left_distrib\n\nalias mul_sub_left_distrib ← mul_sub\n#align mul_sub mul_sub\n\ntheorem mul_sub_right_distrib (a b c : α) : (a - b) * c = a * c - b * c := by\n  simpa only [sub_eq_add_neg, neg_mul_eq_neg_mul] using add_mul a (-b) c\n#align mul_sub_right_distrib mul_sub_right_distrib\n\nalias mul_sub_right_distrib ← sub_mul\n#align sub_mul sub_mul\n\nvariable {a b c d e : α}\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 ↔ (a - b) * e + c = d :=\n  calc\n    a * e + c = b * e + d ↔ a * e + c = d + b * e := by simp [add_comm]\n    _ ↔ a * e + c - b * e = d :=\n      Iff.intro\n        (fun h => by\n          rw [h]\n          simp)\n        fun h => by\n        rw [← h]\n        simp\n    _ ↔ (a - b) * e + c = d := by simp [sub_mul, sub_add_eq_add_sub]\n\n#align mul_add_eq_mul_add_iff_sub_mul_add_eq mul_add_eq_mul_add_iff_sub_mul_add_eq\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 (h : a * e + c = b * e + d) : (a - b) * e + c = d :=\n  calc\n    (a - b) * e + c = a * e + c - b * e := by simp [sub_mul, sub_add_eq_add_sub]\n    _ = d := by rw [h]; simp [@add_sub_cancel α]\n\n#align sub_mul_add_eq_of_mul_add_eq_mul_add sub_mul_add_eq_of_mul_add_eq_mul_add\n\nend NonUnitalNonAssocRing\n\nsection NonAssocRing\n\nvariable [NonAssocRing α]\n\ntheorem sub_one_mul (a b : α) : (a - 1) * b = a * b - b := by rw [sub_mul, one_mul]\n#align sub_one_mul sub_one_mul\n\ntheorem mul_sub_one (a b : α) : a * (b - 1) = a * b - a := by rw [mul_sub, mul_one]\n#align mul_sub_one mul_sub_one\n\ntheorem one_sub_mul (a b : α) : (1 - a) * b = b - a * b := by rw [sub_mul, one_mul]\n#align one_sub_mul one_sub_mul\n\ntheorem mul_one_sub (a b : α) : a * (1 - b) = a - a * b := by rw [mul_sub, mul_one]\n#align mul_one_sub mul_one_sub\n\nend NonAssocRing\n\nsection Ring\n\nvariable [Ring α] {a b c d e : α}\n\n-- A (unital, associative) ring is a not-necessarily-unital ring\n-- see Note [lower instance priority]\ninstance (priority := 100) Ring.toNonUnitalRing : NonUnitalRing α where\n  __ := ‹Ring α›\n  zero_mul := fun a => add_left_cancel (a := 0 * a) <| by rw [← add_mul, zero_add, add_zero]\n  mul_zero := fun a => add_left_cancel (a := a * 0) <| by rw [← mul_add, add_zero, add_zero]\n#align ring.to_non_unital_ring Ring.toNonUnitalRing\n\n-- A (unital, associative) ring is a not-necessarily-associative ring\n-- see Note [lower instance priority]\ninstance (priority := 100) Ring.toNonAssocRing : NonAssocRing α where\n  __ := ‹Ring α›\n  zero_mul := fun a => add_left_cancel (a := 0 * a) <| by rw [← add_mul, zero_add, add_zero]\n  mul_zero := fun a => add_left_cancel (a := a * 0) <| by rw [← mul_add, add_zero, add_zero]\n#align ring.to_non_assoc_ring Ring.toNonAssocRing\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. -/\ninstance (priority := 200) : Semiring α :=\n  { ‹Ring α› with }\n#align ring.to_semiring Ring.toSemiring\n\nend Ring\n\n/-- A non-unital commutative ring is a `NonUnitalRing` with commutative multiplication. -/\nclass NonUnitalCommRing (α : Type u) extends NonUnitalRing α, CommSemigroup α\n#align non_unital_comm_ring NonUnitalCommRing\n\n-- see Note [lower instance priority]\ninstance (priority := 100) NonUnitalCommRing.toNonUnitalCommSemiring [s : NonUnitalCommRing α] :\n    NonUnitalCommSemiring α :=\n  { s with }\n#align non_unital_comm_ring.to_non_unital_comm_semiring NonUnitalCommRing.toNonUnitalCommSemiring\n\nclass CommRing (α : Type u) extends Ring α, CommMonoid α\n#align comm_ring CommRing\n\ninstance (priority := 100) CommRing.toCommSemiring [s : CommRing α] : CommSemiring α :=\n  { s with }\n#align comm_ring.to_comm_semiring CommRing.toCommSemiring\n\n-- see Note [lower instance priority]\ninstance (priority := 100) CommRing.toNonUnitalCommRing [s : CommRing α] : NonUnitalCommRing α :=\n  { s with }\n#align comm_ring.to_non_unital_comm_ring CommRing.toNonUnitalCommRing\n\n-- see Note [lower instance priority]\ninstance (priority := 100) CommRing.toAddCommGroupWithOne [s : CommRing α] :\n    AddCommGroupWithOne α :=\n  { s with }\n\n/-- A domain is a nontrivial semiring such multiplication by a non zero element is cancellative,\n  on both sides. In other words, a nontrivial semiring `R` satisfying\n  `∀ {a b c : R}, a ≠ 0 → a * b = a * c → b = c` and\n  `∀ {a b c : R}, b ≠ 0 → a * b = c * b → a = c`.\n\n  This is implemented as a mixin for `Semiring α`.\n  To obtain an integral domain use `[CommRing α] [IsDomain α]`. -/\nclass IsDomain (α : Type u) [Semiring α] extends IsCancelMulZero α, Nontrivial α : Prop\n#align is_domain IsDomain\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/Defs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624557, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7544873970687306}}
{"text": "/-\nLet's construct a fully formal and certifiable correct proof of the \ncommutativity of conjunction.\n-/\n\n-- theorem and_commutes : ∀ (P Q : Prop), P ∧ Q → Q ∧ P := _\n\ntheorem                           -- keyword: we're going to create a proof\nand_commutes:                     -- this will be its name\n∀ (P Q : Prop), P ∧ Q → Q ∧ P     -- the proposition/claim to be proved\n:=                                -- bind the proof to the name, and_commutes\nbegin                             -- ⊢ ∀ (P Q : Prop), P ∧ Q → Q ∧ P\n  assume P Q,                     -- P Q : Prop ⊢ P ∧ Q → Q ∧ P       (∀-intro)\n  assume h : P ∧ Q,               -- P Q : Prop, h : P ∧ Q ⊢ Q ∧ P    (→ intro)\n  let p : P := and.elim_left h,   -- P Q : Prop, h : P ∧ Q, p : P ⊢ Q ∧ P   (∧-elim-left)\n  let q : Q := and.elim_right h,  -- P Q : Prop, h : P ∧ Q, p : P, q : Q ⊢ Q ∧ P  (right)\n  apply and.intro q p,            -- QED (that means the claim has been proven)\nend\n\n/-\nTheorem: Logical \"and\" is commutative.\n\nProof: Assume P and Q are arbitrary but specific propositions, \nand that we have proof of P ∧ Q. From this proof we can derive\nproofs of P and of Q separately (using and elimination). Then \nwe can combine these proofs in the opposite order to construct \na proof of Q ∧ P.\n-/\n\n-- Here are two versions of a formal proof\n\ntheorem         -- a keyword saying we're going to construct a proof\nor_commutes:   -- the name we'll give to the proof once it's accepted\n∀ (P Q : Prop), P ∧ Q → Q ∨ P -- the proposition that's to be proved\n:=              -- syntax for binding a name to a (proof) value\nbegin           -- and now, between begin/end, we build the proof \n/-\n  intros P Q,\n  assume h : P ∨ Q,\n  apply or.elim h _ _,\n  \n  -- case where P ∨ Q is true because P is\n  assume p : P,\n  apply or.intro_right,\n  exact p,\n\n  -- case where P ∨ Q is true because Q is\n  assume q : Q,\n  apply or.intro_left,\n  exact q,\n-/\n  -- In either case, we can prove that Q ∨ P is true. QED.\nassume P Q h,\ncases h with p q,      -- applies or.elim to h\nexact or.inr p,\n-- exact or.inl q,\nend\n\nexample : \n  ∀ (P Q R S: Prop),\n    R → P ∨ Q ∨ R ∨ S :=\nbegin\n  intros P Q R S,\n  assume r,\n  apply or.intro_right,\n  apply or.intro_right,\n  apply or.intro_left,\n  assumption,\nend\n\nexample : ∀ (P Q R S: Prop),\n    Q → R → P ∨ Q ∨ R ∨ S := _\n\nexample : \n  ∀ (P Q R: Prop), \n    (P ∨ Q) ∧ R →\n    (P ∧ R) ∨ (Q ∧ R) :=\nbegin\n  intros P Q R h,\n  cases h with pq r,\n  cases pq with p q,\n  apply or.intro_left,\n  apply and.intro p r,\n  apply or.intro_right,\n  apply and.intro q r,\nend \n\n/-\n\n-/\n\n\nexample : \n  ∀ (P Q R S: Prop), \n    (P ∨ Q) ∧ (R ∨ S) →\n    (P ∧ R) ∨ (P ∧ S) ∨ (Q ∧ R) ∨ (Q ∧ S) :=\nbegin\n  intros P Q R S h,\n  cases h,\n  cases h_left with p q,\n  cases h_right with r s,\n  \n  apply or.intro_left,\n  apply and.intro p r,\n\n  apply or.intro_right,\n  apply or.intro_left,\n  apply and.intro p s,\n\n  cases h_right with r s,\n  apply or.intro_right,\n  apply or.intro_right,\n  apply or.intro_left,\n  apply and.intro q r,\n\n  apply or.intro_right,\n  apply or.intro_right,\n  apply or.intro_right,\n  apply and.intro q s,\nend \n\n#print or_commutes", "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/09_15_22_and_is_commutative.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8418256412990658, "lm_q1q2_score": 0.7544873869533781}}
{"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-/\nimport group_theory.free_group\nimport group_theory.quotient_group\n\n/-!\n# Defining a group given by generators and relations\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nGiven a subset `rels` of relations of the free group on a type `α`, this file constructs the group\ngiven by generators `x : α` and relations `r ∈ rels`.\n\n## Main definitions\n\n* `presented_group rels`: the quotient group of the free group on a type `α` by a subset `rels` of\n  relations of the free group on `α`.\n* `of`: The canonical map from `α` to a presented group with generators `α`.\n* `to_group f`: the canonical group homomorphism `presented_group rels → G`, given a function\n  `f : α → G` from a type `α` to a group `G` which satisfies the relations `rels`.\n\n## Tags\n\ngenerators, relations, group presentations\n-/\n\nvariables {α : Type*}\n\n/-- Given a set of relations, rels, over a type `α`, presented_group constructs the group with\ngenerators `x : α` and relations `rels` as a quotient of free_group `α`.-/\ndef presented_group (rels : set (free_group α)) :=\nfree_group α ⧸ subgroup.normal_closure rels\n\nnamespace presented_group\n\ninstance (rels : set (free_group α)) : group (presented_group (rels)) :=\nquotient_group.quotient.group _\n\n/-- `of` is the canonical map from `α` to a presented group with generators `x : α`. The term `x` is\nmapped to the equivalence class of the image of `x` in `free_group α`. -/\ndef of {rels : set (free_group α)} (x : α) : presented_group rels :=\nquotient_group.mk (free_group.of x)\n\nsection to_group\n\n/-\nPresented groups satisfy a universal property. If `G` is a group and `f : α → G` is a map such that\nthe images of `f` satisfy all the given relations, then `f` extends uniquely to a group homomorphism\nfrom `presented_group rels` to `G`.\n-/\n\nvariables {G : Type*} [group G] {f : α → G} {rels : set (free_group α)}\n\nlocal notation `F` := free_group.lift f\n\nvariable (h : ∀ r ∈ rels, F r = 1)\n\nlemma closure_rels_subset_ker : subgroup.normal_closure rels ≤ monoid_hom.ker F :=\nsubgroup.normal_closure_le_normal (λ x w, (monoid_hom.mem_ker _).2 (h x w))\n\nlemma to_group_eq_one_of_mem_closure : ∀ x ∈ subgroup.normal_closure rels, F x = 1 :=\nλ x w, (monoid_hom.mem_ker _).1 $ closure_rels_subset_ker h w\n\n/-- The extension of a map `f : α → G` that satisfies the given relations to a group homomorphism\nfrom `presented_group rels → G`. -/\ndef to_group : presented_group rels →* G :=\nquotient_group.lift (subgroup.normal_closure rels) F (to_group_eq_one_of_mem_closure h)\n\n@[simp] lemma to_group.of {x : α} : to_group h (of x) = f x := free_group.lift.of\n\ntheorem to_group.unique (g : presented_group rels →* G)\n  (hg : ∀ x : α, g (of x) = f x) : ∀ {x}, g x = to_group h x :=\nλ x, quotient_group.induction_on x\n    (λ _, free_group.lift.unique (g.comp (quotient_group.mk' _)) hg)\n\nend to_group\n\ninstance (rels : set (free_group α)) : inhabited (presented_group rels) := ⟨1⟩\n\nend presented_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/presented_group.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642804, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7544208114981847}}
{"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 → Y` and `g : Y → Z` and `g ∘ 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 → Y\n| X.a := Y.b\n\n-- define g by g(Y.b)=g(Y.c)=Z.d\ndef g : Y → 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 ≠ Y.c :=\nbegin\n  intro h, -- x ≠ y is definitionally equal to (x = y) → 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  refl,\n  -- they're both definitionally `Z.d` so which tactic solves this goal?\nend\n\nopen function\n\nlemma gf_injective : injective (g ∘ f) :=\nbegin\n  rw [injective, comp],\n  dsimp only,\n  intros a1 a2,\n  cases a1;\n  cases a2;\n  -- intros h,\n  -- rw f at h, -- also works\n  rw [f, g],\n  intro 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 : ∀ A, ...`, then `specialize h X`\n-- will specialize `h` to the specific case `A = X`.\nexample : ¬ (∀ A B C : Type, ∀ (φ : A → B) (ψ : B → C), injective (ψ ∘ φ) → injective ψ) :=\nbegin\n  intros h,\n  have h1 : ¬ injective g, {\n    intros h2,\n    exact Yb_ne_Yc (h2 gYb_eq_gYc), },\n  exact h1 ((h X Y Z f g) gf_injective),\nend\n\nlemma gf_surjective : surjective (g ∘ f) :=\nbegin\n  rw surjective,\n  intro b,\n  cases b,\n  use X.a,\n  rw comp, -- god please there must be a better way\n  dsimp,\n  rw [f, g],\nend\n\nlemma f_not_surjective : ¬ surjective f :=\nbegin\n  intro h,\n  specialize h Y.c,\n  cases h with a h,\n  cases a,\n  exact Yb_ne_Yc h,\nend\n\n-- This is another one. You might want to make some sublemmas first.\nexample : ¬ (∀ A B C : Type, ∀ (φ : A → B) (ψ : B → C), surjective (ψ ∘ φ) → surjective φ) :=\nbegin\n  intros h,\n  exact f_not_surjective (h _ _ _ _ _ gf_surjective),\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/section03functions/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.7543349963532399}}
{"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 group_theory.subgroup\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 : α` and a subset `s ⊆ α`, 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 : α` and a subset `s ⊆ α`, 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 `α` to `α/s` for a subgroup `s` of `α`, 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## TODO\n\nAdd `to_additive` to `preimage_mk_equiv_subgroup_times_set`.\n-/\n\nopen set function\n\nvariable {α : Type*}\n\n/-- The left coset `a * s` for an element `a : α` and a subset `s : set α` -/\n@[to_additive left_add_coset \"The left coset `a+s` for an element `a : α`\nand a subset `s : set α`\"]\ndef left_coset [has_mul α] (a : α) (s : set α) : set α := (λ x, a * x) '' s\n\n/-- The right coset `s * a` for an element `a : α` and a subset `s : set α` -/\n@[to_additive right_add_coset \"The right coset `s+a` for an element `a : α`\nand a subset `s : set α`\"]\ndef right_coset [has_mul α] (s : set α) (a : α) : set α := (λ 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 α]\n\n@[to_additive mem_left_add_coset]\nlemma mem_left_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a *l s :=\nmem_image_of_mem (λ b : α, a * b) hxS\n\n@[to_additive mem_right_add_coset]\nlemma mem_right_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ s *r a :=\nmem_image_of_mem (λ b : α, 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 α) (a b : α) := a *l s = b *l s\n\n@[to_additive left_add_coset_equivalence_rel]\nlemma left_coset_equivalence_rel (s : set α) : equivalence (left_coset_equivalence s) :=\nmk_equivalence (left_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ 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 α) (a b : α) := s *r a = s *r b\n\n@[to_additive right_add_coset_equivalence_rel]\nlemma right_coset_equivalence_rel (s : set α) : equivalence (right_coset_equivalence s) :=\nmk_equivalence (right_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans)\n\nend coset_mul\n\nsection coset_semigroup\nvariable [semigroup α]\n\n@[simp] lemma left_coset_assoc (s : set α) (a b : α) : a *l (b *l s) = (a * b) *l s :=\nby simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc]\nattribute [to_additive left_add_coset_assoc] left_coset_assoc\n\n@[simp] lemma right_coset_assoc (s : set α) (a b : α) : s *r a *r b = s *r (a * b) :=\nby simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc]\nattribute [to_additive right_add_coset_assoc] right_coset_assoc\n\n@[to_additive left_add_coset_right_add_coset]\nlemma left_coset_right_coset (s : set α) (a b : α) : 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 α] (s : set α)\n\n@[simp] lemma one_left_coset : 1 *l s = s :=\nset.ext $ by simp [left_coset]\nattribute [to_additive zero_left_add_coset] one_left_coset\n\n@[simp] lemma right_coset_one : s *r 1 = s :=\nset.ext $ by simp [right_coset]\nattribute [to_additive right_add_coset_zero] right_coset_one\n\nend coset_monoid\n\nsection coset_submonoid\nopen submonoid\nvariables [monoid α] (s : submonoid α)\n\n@[to_additive mem_own_left_add_coset]\nlemma mem_own_left_coset (a : α) : a ∈ a *l s :=\nsuffices a * 1 ∈ 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 : α) : a ∈ (s : set α) *r a :=\nsuffices 1 * a ∈ (s : set α) *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 : α} (ha : a *l s = s) : a ∈ s :=\nby rw [←set_like.mem_coe, ←ha]; 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 : α} (ha : (s : set α) *r a = s) : a ∈ s :=\nby rw [←set_like.mem_coe, ←ha]; exact mem_own_right_coset s a\n\nend coset_submonoid\n\nsection coset_group\nvariables [group α] {s : set α} {x : α}\n\n@[to_additive mem_left_add_coset_iff]\nlemma mem_left_coset_iff (a : α) : x ∈ a *l s ↔ a⁻¹ * x ∈ s :=\niff.intro\n  (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb])\n  (assume h, ⟨a⁻¹ * x, h, by simp⟩)\n\n@[to_additive mem_right_add_coset_iff]\nlemma mem_right_coset_iff (a : α) : x ∈ s *r a ↔ x * a⁻¹ ∈ s :=\niff.intro\n  (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb])\n  (assume h, ⟨x * a⁻¹, h, by simp⟩)\n\nend coset_group\n\nsection coset_subgroup\nopen subgroup\n\nvariables [group α] (s : subgroup α)\n\n@[to_additive left_add_coset_mem_left_add_coset]\nlemma left_coset_mem_left_coset {a : α} (ha : a ∈ 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 : α} (ha : a ∈ s) : (s : set α) *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 : α) : 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 : ∀ g : α, g *l s = s *r g) : s.normal :=\n⟨assume a ha g, show g * a * g⁻¹ ∈ (s : set α),\n  by rw [← mem_right_coset_iff, ← h]; exact mem_left_coset g ha⟩\n\n@[to_additive normal_iff_eq_add_cosets]\ntheorem normal_iff_eq_cosets : s.normal ↔ ∀ g : α, g *l s = s *r g :=\n⟨@eq_cosets_of_normal _ _ s, normal_of_eq_cosets s⟩\n\nend coset_subgroup\n\nrun_cmd to_additive.map_namespace `quotient_group `quotient_add_group\n\nnamespace quotient_group\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 [group α] (s : subgroup α) : setoid α :=\n⟨λ x y, x⁻¹ * y ∈ s,\n  assume x, by simp [s.one_mem],\n  assume x y hxy,\n    have (x⁻¹ * y)⁻¹ ∈ s, from s.inv_mem hxy,\n    by simpa using this,\n  assume x y z hxy hyz,\n    have x⁻¹ * y * (y⁻¹ * z) ∈ s, from s.mul_mem hxy hyz,\n    by simpa [mul_assoc] using this⟩\n\n@[to_additive]\ninstance left_rel_decidable [group α] (s : subgroup α) [d : decidable_pred (λ a, a ∈ s)] :\n  decidable_rel (left_rel s).r := λ _ _, d _\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 [group α] (s : subgroup α) : Type* := quotient (left_rel s)\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 [group α] (s : subgroup α) : setoid α :=\n⟨λ x y, y * x⁻¹ ∈ s,\n  assume x, by simp [s.one_mem],\n  assume x y hxy,\n    have (y * x⁻¹)⁻¹ ∈ s, from s.inv_mem hxy,\n    by simpa using this,\n  assume x y z hxy hyz,\n    have (z * y⁻¹) * (y * x⁻¹) ∈ s, from s.mul_mem hyz hxy,\n    by simpa [mul_assoc] using this⟩\n\n@[to_additive]\ninstance right_rel_decidable [group α] (s : subgroup α) [d : decidable_pred (λ a, a ∈ s)] :\n  decidable_rel (left_rel s).r := λ _ _, d _\n\nend quotient_group\n\nnamespace quotient_add_group\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 [add_group α] (s : add_subgroup α) : Type* := quotient (left_rel s)\n\nend quotient_add_group\n\nattribute [to_additive quotient_add_group.quotient] quotient_group.quotient\n\nnamespace quotient_group\n\nvariables [group α] {s : subgroup α}\n\n@[to_additive]\ninstance fintype [fintype α] (s : subgroup α) [decidable_rel (left_rel s).r] :\n  fintype (quotient_group.quotient s) :=\nquotient.fintype (left_rel s)\n\n/-- The canonical map from a group `α` to the quotient `α/s`. -/\n@[to_additive \"The canonical map from an `add_group` `α` to the quotient `α/s`.\"]\nabbreviation mk (a : α) : quotient s :=\nquotient.mk' a\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on {C : quotient s → Prop} (x : quotient s)\n  (H : ∀ z, C (quotient_group.mk z)) : C x :=\nquotient.induction_on' x H\n\n@[to_additive]\ninstance : has_coe_t α (quotient s) := ⟨mk⟩ -- note [use has_coe_t]\n\n@[elab_as_eliminator, to_additive]\nlemma induction_on' {C : quotient s → Prop} (x : quotient s)\n  (H : ∀ z : α, C z) : C x :=\nquotient.induction_on' x H\n\n@[to_additive]\ninstance (s : subgroup α) : inhabited (quotient s) :=\n⟨((1 : α) : quotient s)⟩\n\n@[to_additive quotient_add_group.eq]\nprotected lemma eq {a b : α} : (a : quotient s) = b ↔ a⁻¹ * b ∈ s :=\nquotient.eq'\n\n@[to_additive]\nlemma eq_class_eq_left_coset (s : subgroup α) (g : α) :\n  {x : α | (x : quotient s) = g} = left_coset g s :=\nset.ext $ λ z, by { rw [mem_left_coset_iff, set.mem_set_of_eq, eq_comm, quotient_group.eq], simp }\n\n@[to_additive]\nlemma preimage_image_coe (N : subgroup α) (s : set α) :\n  coe ⁻¹' ((coe : α → quotient N) '' s) = ⋃ x : N, (λ y : α, y * x) '' 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, ← eq_inv_mul_iff_mul_eq],\n  exact ⟨λ ⟨y, hs, hN⟩, ⟨_, hN, y, hs, rfl⟩, λ ⟨z, hN, y, hs, hyz⟩, ⟨y, hs, hyz ▸ hN⟩⟩\nend\n\nend quotient_group\n\nnamespace subgroup\nopen quotient_group\nvariables [group α] {s : subgroup α}\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 : α) : left_coset g s ≃ s :=\n⟨λ x, ⟨g⁻¹ * x.1, (mem_left_coset_iff _).1 x.2⟩,\n λ x, ⟨g * x.1, x.1, x.2, rfl⟩,\n λ ⟨x, hx⟩, subtype.eq $ by simp,\n λ ⟨g, hg⟩, subtype.eq $ by simp⟩\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 : α) : right_coset ↑s g ≃ s :=\n⟨λ x, ⟨x.1 * g⁻¹, (mem_right_coset_iff _).1 x.2⟩,\n λ x, ⟨x.1 * g, x.1, x.2, rfl⟩,\n λ ⟨x, hx⟩, subtype.eq $ by simp,\n λ ⟨g, hg⟩, subtype.eq $ by simp⟩\n\n/-- A (non-canonical) bijection between a group `α` and the product `(α/s) × s` -/\n@[to_additive \"A (non-canonical) bijection between an add_group `α` and the product `(α/s) × s`\"]\nnoncomputable def group_equiv_quotient_times_subgroup :\n  α ≃ quotient s × s :=\ncalc α ≃ Σ L : quotient s, {x : α // (x : quotient s) = L} :\n  (equiv.sigma_preimage_equiv quotient_group.mk).symm\n    ... ≃ Σ L : quotient s, left_coset (quotient.out' L) s :\n  equiv.sigma_congr_right (λ L,\n    begin\n      rw ← eq_class_eq_left_coset,\n      show _root_.subtype (λ x : α, quotient.mk' x = L) ≃\n        _root_.subtype (λ x : α, quotient.mk' x = quotient.mk' _),\n      simp [-quotient.eq'],\n    end)\n    ... ≃ Σ L : quotient s, s :\n  equiv.sigma_congr_right (λ L, left_coset_equiv_subgroup _)\n    ... ≃ quotient s × s :\n  equiv.sigma_equiv_prod _ _\n\nlemma card_eq_card_quotient_mul_card_subgroup [fintype α] (s : subgroup α) [fintype s]\n  [decidable_pred (λ a, a ∈ s)] : fintype.card α = fintype.card (quotient s) * fintype.card s :=\nby rw ← fintype.card_prod;\n  exact fintype.card_congr (subgroup.group_equiv_quotient_times_subgroup)\n\nlemma card_subgroup_dvd_card [fintype α] (s : subgroup α) [fintype s] :\n  fintype.card s ∣ fintype.card α :=\nby haveI := classical.prop_decidable; simp [card_eq_card_quotient_mul_card_subgroup s]\n\nlemma card_quotient_dvd_card [fintype α] (s : subgroup α) [decidable_pred (λ a, a ∈ s)]\n  [fintype s] : fintype.card (quotient s) ∣ fintype.card α :=\nby simp [card_eq_card_quotient_mul_card_subgroup s]\n\nend subgroup\n\nnamespace quotient_group\n\nvariables [group α]\n\n-- FIXME -- why is there no `to_additive`?\n\n/-- If `s` is a subgroup of the group `α`, and `t` is a subset of `α/s`, then\nthere is a (typically non-canonical) bijection between the preimage of `t` in\n`α` and the product `s × t`. -/\nnoncomputable def preimage_mk_equiv_subgroup_times_set\n  (s : subgroup α) (t : set (quotient s)) : quotient_group.mk ⁻¹' t ≃ s × t :=\nhave h : ∀ {x : quotient s} {a : α}, x ∈ t → a ∈ s →\n  (quotient.mk' (quotient.out' x * a) : quotient s) = quotient.mk' (quotient.out' x) :=\n    λ x a hx ha, quotient.sound' (show (quotient.out' x * a)⁻¹ * quotient.out' x ∈ s,\n      from (s.inv_mem_iff).1 $\n        by rwa [mul_inv_rev, inv_inv, ← mul_assoc, inv_mul_self, one_mul]),\n{ to_fun := λ ⟨a, ha⟩, ⟨⟨(quotient.out' (quotient.mk' a))⁻¹ * a,\n    @quotient.exact' _ (left_rel s) _ _ $ (quotient.out_eq' _)⟩,\n      ⟨quotient.mk' a, ha⟩⟩,\n  inv_fun := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, ⟨quotient.out' x * a, show quotient.mk' _ ∈ t,\n    by simp [h hx ha, hx]⟩,\n  left_inv := λ ⟨a, ha⟩, subtype.eq $ show _ * _ = a, by simp,\n  right_inv := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, 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": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/group_theory/coset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7543349841341336}}
{"text": "namespace my_bool\n\ninductive mybool : Type\n| mytt : mybool\n| myff : mybool\n\n#check mybool.mytt\n\n/-\nWe declare mybool to be an \ninductively defined type:\na value of type, Type. \n\nThe set of values of this \ntype that can be constructed \nis defined by the available \nconstructors.\n\nHere there are just two, \nmytt and myff, neither having \nany arguments, so these are\nthe only two values of this \ntype: mytt and myff.\n-/\n\n-- We open the mybool namespace\nopen mybool\n\n#check mytt\n\n/-\nWith this data type in hand,\nwe can now define an \"algebra\"\ninvolving such values. This will\nbe out little implementation of\nBoolean algebra. \n\nFirst we'll define the unary\nfunctions involving values of\nthis type only. Then we'll do\na few binary functions, leaving\nyou a few more as exercises.\n-/\n\n/- Unary Operations -/\n\n-- id_mybool returns what it's given\ndef id_mybool (b: mybool) : mybool := b\n\n-- true_mybool always returns true\ndef true_mybool (b: mybool) := mytt\n\n-- false_mybool always returns false\ndef false_mybool (b: mybool) := myff\n\n-- not_mybool returns the other value\ndef not_mybool (b: mybool) :=\n    match b with \n    | mytt := myff\n    | myff := mytt\n    end\n\n#reduce not_mybool mytt\n#reduce not_mybool myff\n\n/-\nThe match command does a kind of case\nanalysis on b. b, being of type, mybool,\ncan only have been \"built\" by the mytt\nor myff constructors. In the first case,\nthe function returns myff. In the latter\ncase, it returns mytt.\n-/\n\n-- look, it works\n#reduce id_mybool myff\n#reduce id_mybool mytt\n#reduce not_mybool myff\n#reduce not_mybool mytt\n\n/-\nEXERCISE: use #reduce to test the other\ntwo functions (false_ and true_mybool).\n-/\n\n/-\nSo we've just defined a data type and\nsome operations on values of this type.\nDo our operations capture what we want,\nwhich is to implement Boolean algebra?\nLet's \"verify\" our software by proving\na proposition that we think should be\ntrue: that if you apply not_mybool to \na value, b, of type mybool and apply it\nagain to the result, we should get back\nto b. \n-/\n\ntheorem not_inverse : \n    ∀ b : mybool, \n        not_mybool (not_mybool b) = b :=\nbegin\n    intro b,\n    cases b,\n    apply rfl,\n    apply rfl,\nend\n\n/-\nThat's amazing. We didn't \"test\" our\nsoftware by running it with various\ninputs. Rather we proved a fact about\nits behavior on *all* possible values\nof its inputs using logic.\n-/\n\n/-\nHere's a binary function, and_mybool,\ntaking two mybools and returning one\nas a result. We intend this function \nto implement the Boolean and operator.\n-/\n\ndef and_mybool' (b1 b2 : mybool) : mybool :=\nmatch b1, b2 with\n    | mytt, mytt := mytt\n    | mytt, myff := myff\n    | myff, mytt := myff\n    | myff, myff := myff\nend\n\n#reduce and_mybool' mytt myff\n\n/-\nThe new concept here is that we can match\non several arguments. \n-/\n\n/-\nWe notice that all of the combinations of\ninput values after mytt and mytt return\nmyff. We can use \"wildcards\" in matches to\nmatch any value. Matches are attempted in\nthe order in which rules appear in code.\n(It's important to try to match mytt, mytt\nbefore applying the wildcarded rule! Why?)\n-/\n\ndef and_mybool (b1 b2 : mybool) : mybool :=\nmatch b1, b2 with\n    | mytt, mytt := mytt\n    | _, _ := myff\nend\n\n/-\nEXERCISE: Now you should implement each of \nthe following Boolean operators:\n\n- or, as or_mybool\n- implies, as implies_mybool\n-/\n\ndef or_mybool (b1 b2: mybool) : mybool :=\nmatch b1, b2 with\n| myff, myff := myff\n| _, _ := mytt\nend\n\n/-\nEXERCISE: To test that you have given\nvalid implementations, state and prove \nthe propositon that for any values, b1\nand b2, not_mybool (and_mybool b1 b2) =\nor_mybool (not_mybool b1) (not_mybool b2).\n-/\n\ntheorem demorgan1 : ∀ b1 b2 : mybool, \n    not_mybool \n        (and_mybool b1 b2) \n    =\n    or_mybool \n        (not_mybool b1) \n        (not_mybool b2) :=\n begin\n intros b1 b2,\n cases b1,\n cases b2,\n apply rfl,\n apply rfl,\n cases b2,\n apply rfl, \n apply rfl,\n end\n\n theorem demorgan2 : \n    ∀ b1 b2 : mybool, not_mybool (or_mybool b1 b2) = and_mybool (not_mybool b1) (not_mybool b2) := \nbegin\nintros b1 b2,\ncases b1,\ncases b2,\nsorry\nend\n\n/-\nEXERCISE: State and prove the other \nDeMorgan Law for Boolean algebra.\n-/\n\nend my_bool", "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/14.Inductive_Definitions/Data_Types/mybool.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736692, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7543349837580496}}
{"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.list.sort\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.List.OfFn\nimport Mathlib.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 `≤`-like relation. Then we define two sorting algorithms:\n`List.insertionSort` and `List.mergeSort`, and prove their correctness.\n-/\n\n\nopen List.Perm\n\nuniverse uu\n\nnamespace List\n\n/-!\n### The predicate `List.Sorted`\n-/\n\n\nsection Sorted\n\nvariable {α : Type uu} {r : α → α → Prop} {a : α} {l : List α}\n\n/-- `Sorted r l` is the same as `Pairwise r l`, preferred in the case that `r`\n  is a `<` or `≤`-like relation (transitive and antisymmetric or asymmetric) -/\ndef Sorted :=\n  @Pairwise\n#align list.sorted List.Sorted\n\ninstance decidableSorted [DecidableRel r] (l : List α) : Decidable (Sorted r l) :=\n  List.instDecidablePairwise _\n#align list.decidable_sorted List.decidableSorted\n\nprotected theorem Sorted.le_of_lt [Preorder α] {l : List α} (h : l.Sorted (· < ·)) :\n    l.Sorted (· ≤ ·) :=\n  h.imp le_of_lt\n\nprotected theorem Sorted.lt_of_le [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≤ ·))\n    (h₂ : l.Nodup) : l.Sorted (· < ·) :=\n  h₁.imp₂ (fun _ _ => lt_of_le_of_ne)  h₂\n\n@[simp]\ntheorem sorted_nil : Sorted r [] :=\n  Pairwise.nil\n#align list.sorted_nil List.sorted_nil\n\ntheorem Sorted.of_cons : Sorted r (a :: l) → Sorted r l :=\n  Pairwise.of_cons\n#align list.sorted.of_cons List.Sorted.of_cons\n\ntheorem Sorted.tail {r : α → α → Prop} {l : List α} (h : Sorted r l) : Sorted r l.tail :=\n  Pairwise.tail h\n#align list.sorted.tail List.Sorted.tail\n\ntheorem rel_of_sorted_cons {a : α} {l : List α} : Sorted r (a :: l) → ∀ b ∈ l, r a b :=\n  rel_of_pairwise_cons\n#align list.rel_of_sorted_cons List.rel_of_sorted_cons\n\n@[simp]\ntheorem sorted_cons {a : α} {l : List α} : Sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ Sorted r l :=\n  pairwise_cons\n#align list.sorted_cons List.sorted_cons\n\nprotected theorem Sorted.nodup {r : α → α → Prop} [IsIrrefl α r] {l : List α} (h : Sorted r l) :\n    Nodup l :=\n  Pairwise.nodup h\n#align list.sorted.nodup List.Sorted.nodup\n\ntheorem eq_of_perm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (p : l₁ ~ l₂) (s₁ : Sorted r l₁)\n    (s₂ : Sorted r l₂) : l₁ = l₂ := by\n  induction' s₁ with a l₁ h₁ s₁ IH generalizing l₂\n  · exact p.nil_eq\n  · have : a ∈ l₂ := p.subset (mem_cons_self _ _)\n    rcases mem_split this with ⟨u₂, v₂, rfl⟩\n    have p' := (perm_cons a).1 (p.trans perm_middle)\n    obtain rfl := IH p' (s₂.sublist <| by simp)\n    change a :: u₂ ++ v₂ = u₂ ++ ([a] ++ v₂)\n    rw [← append_assoc]\n    congr\n    have : ∀ (x : α) (_ : x ∈ u₂), x = a := fun x m =>\n      antisymm ((pairwise_append.1 s₂).2.2 _ m a (mem_cons_self _ _)) (h₁ _ (by simp [m]))\n    rw [(@eq_replicate _ a (length u₂ + 1) (a :: u₂)).2,\n          (@eq_replicate _ a (length u₂ + 1) (u₂ ++ [a])).2] <;>\n        constructor <;>\n      simp [iff_true_intro this, or_comm]\n#align list.eq_of_perm_of_sorted List.eq_of_perm_of_sorted\n\ntheorem sublist_of_subperm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (p : l₁ <+~ l₂)\n    (s₁ : l₁.Sorted r) (s₂ : l₂.Sorted r) : l₁ <+ l₂ := by\n  let ⟨_, h, h'⟩ := p\n  rwa [← eq_of_perm_of_sorted h (s₂.sublist h') s₁]\n#align list.sublist_of_subperm_of_sorted List.sublist_of_subperm_of_sorted\n\n@[simp 1100] --Porting note: higher priority for linter\ntheorem sorted_singleton (a : α) : Sorted r [a] :=\n  pairwise_singleton _ _\n#align list.sorted_singleton List.sorted_singleton\n\ntheorem Sorted.rel_get_of_lt {l : List α} (h : l.Sorted r) {a b : Fin l.length} (hab : a < b) :\n    r (l.get a) (l.get b) :=\n  List.pairwise_iff_get.1 h _ _ hab\n\ntheorem Sorted.rel_nthLe_of_lt {l : List α} (h : l.Sorted r) {a b : ℕ} (ha : a < l.length)\n    (hb : b < l.length) (hab : a < b) : r (l.nthLe a ha) (l.nthLe b hb) :=\n  List.pairwise_iff_get.1 h ⟨a, ha⟩ ⟨b, hb⟩ hab\n#align list.sorted.rel_nth_le_of_lt List.Sorted.rel_nthLe_of_lt\n\ntheorem Sorted.rel_get_of_le [IsRefl α r] {l : List α} (h : l.Sorted r) {a b : Fin l.length}\n    (hab : a ≤ b) : r (l.get a) (l.get b) := by\n  rcases hab.eq_or_lt with (rfl | hlt)\n  exacts [refl _, h.rel_get_of_lt hlt]\n\ntheorem Sorted.rel_nthLe_of_le [IsRefl α r] {l : List α} (h : l.Sorted r) {a b : ℕ}\n    (ha : a < l.length) (hb : b < l.length) (hab : a ≤ b) : r (l.nthLe a ha) (l.nthLe b hb) :=\n  h.rel_get_of_le hab\n#align list.sorted.rel_nth_le_of_le List.Sorted.rel_nthLe_of_le\n\ntheorem Sorted.rel_of_mem_take_of_mem_drop {l : List α} (h : List.Sorted r l) {k : ℕ} {x y : α}\n    (hx : x ∈ List.take k l) (hy : y ∈ List.drop k l) : r x y := by\n  obtain ⟨⟨iy, hiy⟩, rfl⟩ := get_of_mem hy\n  obtain ⟨⟨ix, hix⟩, rfl⟩ := get_of_mem hx\n  rw [get_take', get_drop']\n  rw [length_take] at hix\n  exact h.rel_nthLe_of_lt _ _ (ix.lt_add_right _ _ (lt_min_iff.mp hix).left)\n#align list.sorted.rel_of_mem_take_of_mem_drop List.Sorted.rel_of_mem_take_of_mem_drop\n\nend Sorted\n\nsection Monotone\n\nvariable {n : ℕ} {α : Type uu} [Preorder α] {f : Fin n → α}\n\ntheorem sorted_ofFn_iff {r : α → α → Prop} : (ofFn f).Sorted r ↔ ((· < ·) ⇒ r) f f := by\n  simp_rw [Sorted, pairwise_iff_get, length_ofFn, get_ofFn, Relator.LiftFun]\n  exact Iff.symm (Fin.cast _).surjective.forall₂\n\n/-- The list `List.ofFn f` is strictly sorted with respect to `(· ≤ ·)` if and only if `f` is\nstrictly monotone. -/\n@[simp] theorem sorted_lt_ofFn_iff : (ofFn f).Sorted (· < ·) ↔ StrictMono f := sorted_ofFn_iff\n\n/-- The list `List.ofFn f` is sorted with respect to `(· ≤ ·)` if and only if `f` is monotone. -/\n@[simp] theorem sorted_le_ofFn_iff : (ofFn f).Sorted (· ≤ ·) ↔ Monotone f :=\n  sorted_ofFn_iff.trans monotone_iff_forall_lt.symm\n\n/-- A tuple is monotone if and only if the list obtained from it is sorted. -/\n@[deprecated sorted_le_ofFn_iff]\ntheorem monotone_iff_ofFn_sorted : Monotone f ↔ (ofFn f).Sorted (· ≤ ·) := sorted_le_ofFn_iff.symm\n#align list.monotone_iff_of_fn_sorted List.monotone_iff_ofFn_sorted\n\n/-- The list obtained from a monotone tuple is sorted. -/\nalias sorted_le_ofFn_iff ↔ _ _root_.Monotone.ofFn_sorted\n#align list.monotone.of_fn_sorted Monotone.ofFn_sorted\n\nend Monotone\n\nsection sort\n\nvariable {α : Type uu} (r : α → α → Prop) [DecidableRel r]\n\nlocal infixl:50 \" ≼ \" => r\n\n/-! ### Insertion sort -/\n\n\nsection InsertionSort\n\n/-- `orderedInsert a l` inserts `a` into `l` at such that\n  `orderedInsert a l` is sorted if `l` is. -/\n@[simp]\ndef orderedInsert (a : α) : List α → List α\n  | [] => [a]\n  | b :: l => if a ≼ b then a :: b :: l else b :: orderedInsert a l\n#align list.ordered_insert List.orderedInsert\n\n/-- `insertionSort l` returns `l` sorted using the insertion sort algorithm. -/\n@[simp]\ndef insertionSort : List α → List α\n  | [] => []\n  | b :: l => orderedInsert r b (insertionSort l)\n#align list.insertion_sort List.insertionSort\n\n@[simp]\ntheorem orderedInsert_nil (a : α) : [].orderedInsert r a = [a] :=\n  rfl\n#align list.ordered_insert_nil List.orderedInsert_nil\n\ntheorem orderedInsert_length : ∀ (L : List α) (a : α), (L.orderedInsert r a).length = L.length + 1\n  | [], a => rfl\n  | hd :: tl, a => by\n    dsimp [orderedInsert]\n    split_ifs <;> simp [orderedInsert_length tl]\n#align list.ordered_insert_length List.orderedInsert_length\n\n/-- An alternative definition of `orderedInsert` using `takeWhile` and `dropWhile`. -/\ntheorem orderedInsert_eq_take_drop (a : α) :\n    ∀ l : List α,\n      l.orderedInsert r a = (l.takeWhile fun b => ¬a ≼ b) ++ a :: l.dropWhile fun b => ¬a ≼ b\n  | [] => rfl\n  | b :: l => by\n    dsimp only [orderedInsert]\n    split_ifs with h <;> simp [takeWhile, dropWhile, *, orderedInsert_eq_take_drop a l]\n#align list.ordered_insert_eq_take_drop List.orderedInsert_eq_take_drop\n\ntheorem insertionSort_cons_eq_take_drop (a : α) (l : List α) :\n    insertionSort r (a :: l) =\n      ((insertionSort r l).takeWhile fun b => ¬a ≼ b) ++\n        a :: (insertionSort r l).dropWhile fun b => ¬a ≼ b :=\n  orderedInsert_eq_take_drop r a _\n#align list.insertion_sort_cons_eq_take_drop List.insertionSort_cons_eq_take_drop\n\nsection Correctness\n\nopen Perm\n\n\n\ntheorem orderedInsert_count [DecidableEq α] (L : List α) (a b : α) :\n    count a (L.orderedInsert r b) = count a L + if a = b then 1 else 0 := by\n  rw [(L.perm_orderedInsert r b).count_eq, count_cons]\n  split_ifs <;> simp only [Nat.succ_eq_add_one, add_zero]\n#align list.ordered_insert_count List.orderedInsert_count\n\ntheorem perm_insertionSort : ∀ l : List α, insertionSort r l ~ l\n  | [] => Perm.nil\n  | b :: l => by\n    simpa [insertionSort] using (perm_orderedInsert _ _ _).trans ((perm_insertionSort l).cons b)\n#align list.perm_insertion_sort List.perm_insertionSort\n\nvariable {r}\n\n/-- If `l` is already `List.Sorted` with respect to `r`, then `insertionSort` does not change\nit. -/\ntheorem Sorted.insertionSort_eq : ∀ {l : List α} (_ : Sorted r l), insertionSort r l = l\n  | [], _ => rfl\n  | [a], _ => rfl\n  | a :: b :: l, h => by\n    rw [insertionSort, Sorted.insertionSort_eq, orderedInsert, if_pos]\n    exacts[rel_of_sorted_cons h _ (mem_cons_self _ _), h.tail]\n#align list.sorted.insertion_sort_eq List.Sorted.insertionSort_eq\n\nsection TotalAndTransitive\n\nvariable [IsTotal α r] [IsTrans α r]\n\ntheorem Sorted.orderedInsert (a : α) : ∀ l, Sorted r l → Sorted r (orderedInsert r a l)\n  | [], _ => sorted_singleton a\n  | b :: l, h => by\n    by_cases h' : a ≼ b\n    · -- Porting note: was\n      -- `simpa [orderedInsert, h', h] using fun b' bm => trans h' (rel_of_sorted_cons h _ bm)`\n      rw [List.orderedInsert, if_pos h', sorted_cons]\n      exact ⟨forall_mem_cons.2 ⟨h', fun c hc => _root_.trans h' (rel_of_sorted_cons h _ hc)⟩, h⟩\n    · suffices ∀ b' : α, b' ∈ List.orderedInsert r a l → r b b' by\n        simpa [orderedInsert, h', h.of_cons.orderedInsert a l]\n      intro b' bm\n      cases' show b' = a ∨ b' ∈ l by simpa using (perm_orderedInsert _ _ _).subset bm with be bm\n      · subst b'\n        exact (total_of r _ _).resolve_left h'\n      · exact rel_of_sorted_cons h _ bm\n#align list.sorted.ordered_insert List.Sorted.orderedInsert\n\nvariable (r)\n\n/-- The list `List.insertionSort r l` is `List.Sorted` with respect to `r`. -/\ntheorem sorted_insertionSort : ∀ l, Sorted r (insertionSort r l)\n  | [] => sorted_nil\n  | a :: l => (sorted_insertionSort l).orderedInsert a _\n#align list.sorted_insertion_sort List.sorted_insertionSort\n\nend TotalAndTransitive\n\nend Correctness\n\nend InsertionSort\n\n/-! ### Merge sort -/\n\n\nsection MergeSort\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/-- Split `l` into two lists of approximately equal length.\n\n     split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/\n@[simp]\ndef split : List α → List α × List α\n  | [] => ([], [])\n  | a :: l =>\n    let (l₁, l₂) := split l\n    (a :: l₂, l₁)\n#align list.split List.split\n\ntheorem split_cons_of_eq (a : α) {l l₁ l₂ : List α} (h : split l = (l₁, l₂)) :\n    split (a :: l) = (a :: l₂, l₁) := by rw [split, h]\n#align list.split_cons_of_eq List.split_cons_of_eq\n\ntheorem length_split_le :\n    ∀ {l l₁ l₂ : List α}, split l = (l₁, l₂) → length l₁ ≤ length l ∧ length l₂ ≤ length l\n  | [], _, _, rfl => ⟨Nat.le_refl 0, Nat.le_refl 0⟩\n  | a :: l, l₁', l₂', h => by\n    cases' e : split l with l₁ l₂\n    injection (split_cons_of_eq _ e).symm.trans h; substs l₁' l₂'\n    cases' length_split_le e with h₁ h₂\n    exact ⟨Nat.succ_le_succ h₂, Nat.le_succ_of_le h₁⟩\n#align list.length_split_le List.length_split_le\n\ntheorem length_split_lt {a b} {l l₁ l₂ : List α} (h : split (a :: b :: l) = (l₁, l₂)) :\n    length l₁ < length (a :: b :: l) ∧ length l₂ < length (a :: b :: l) := by\n  cases' e : split l with l₁' l₂'\n  injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h; substs l₁ l₂\n  cases' length_split_le e with h₁ h₂\n  exact ⟨Nat.succ_le_succ (Nat.succ_le_succ h₁), Nat.succ_le_succ (Nat.succ_le_succ h₂)⟩\n#align list.length_split_lt List.length_split_lt\n\ntheorem perm_split : ∀ {l l₁ l₂ : List α}, split l = (l₁, l₂) → l ~ l₁ ++ l₂\n  | [], _, _, rfl => Perm.refl _\n  | a :: l, l₁', l₂', h => by\n    cases' e : split l with l₁ l₂\n    injection (split_cons_of_eq _ e).symm.trans h; substs l₁' l₂'\n    exact ((perm_split e).trans perm_append_comm).cons a\n#align list.perm_split List.perm_split\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 α → List α → List α\n  | [], l' => l'\n  | l, [] => l\n  | a :: l, b :: l' => if a ≼ b then a :: merge l (b :: l') else b :: merge (a :: l) l'\n  termination_by merge l₁ l₂ => length l₁ + length l₂\n#align list.merge List.merge\n\n/-- Implementation of a merge sort algorithm to sort a list. -/\ndef mergeSort : List α → List α\n  | [] => []\n  | [a] => [a]\n  | a :: b :: l => by\n    -- Porting note: rewrote to make `mergeSort_cons_cons` proof easier\n    let ls := (split (a :: b :: l))\n    have e : split (a :: b :: l) = ⟨ls.1, ls.2⟩ := rfl\n    have h := length_split_lt e\n    have := h.1\n    have := h.2\n    exact merge r (mergeSort ls.1) (mergeSort ls.2)\n  termination_by mergeSort l => length l\n#align list.merge_sort List.mergeSort\n\n@[nolint unusedHavesSuffices] --Porting note: false positive\ntheorem mergeSort_cons_cons {a b} {l l₁ l₂ : List α} (h : split (a :: b :: l) = (l₁, l₂)) :\n    mergeSort r (a :: b :: l) = merge r (mergeSort r l₁) (mergeSort r l₂) := by\n  simp only [mergeSort, h]\n#align list.merge_sort_cons_cons List.mergeSort_cons_cons\n\nsection Correctness\n\ntheorem perm_merge : ∀ l l' : List α, 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' => by\n    by_cases h : a ≼ b\n    · simpa [merge, h] using perm_merge _ _\n    · suffices b :: merge r (a :: l) l' ~ a :: (l ++ b :: l') by simpa [merge, h]\n      exact ((perm_merge _ _).cons _).trans ((swap _ _ _).trans (perm_middle.symm.cons _))\n  termination_by perm_merge l₁ l₂ => length l₁ + length l₂\n#align list.perm_merge List.perm_merge\n\ntheorem perm_mergeSort : ∀ l : List α, mergeSort r l ~ l\n  | [] => by simp [mergeSort]\n  | [a] => by simp [mergeSort]\n  | a :: b :: l => by\n    cases' e : split (a :: b :: l) with l₁ l₂\n    cases' length_split_lt e with h₁ h₂\n    rw [mergeSort_cons_cons r e]\n    apply (perm_merge r _ _).trans\n    exact\n      ((perm_mergeSort l₁).append (perm_mergeSort l₂)).trans (perm_split e).symm\n  termination_by perm_mergeSort l => length l\n#align list.perm_merge_sort List.perm_mergeSort\n\n@[simp]\ntheorem length_mergeSort (l : List α) : (mergeSort r l).length = l.length :=\n  (perm_mergeSort r _).length_eq\n#align list.length_merge_sort List.length_mergeSort\n\nsection TotalAndTransitive\n\nvariable {r} [IsTotal α r] [IsTrans α r]\n\ntheorem Sorted.merge : ∀ {l l' : List α}, Sorted r l → Sorted r l' → Sorted r (merge r l l')\n  | [], [], _, _ => by simp [List.merge]\n  | [], b :: l', _, h₂ => by simpa [List.merge] using h₂\n  | a :: l, [], h₁, _ => by simpa [List.merge] using h₁\n  | a :: l, b :: l', h₁, h₂ => by\n    by_cases h : a ≼ b\n    · suffices ∀ (b' : α) (_ : b' ∈ List.merge r l (b :: l')), r a b' by\n        simpa [List.merge, h, h₁.of_cons.merge h₂]\n      intro b' bm\n      rcases show b' = b ∨ b' ∈ l ∨ b' ∈ l' by\n          simpa [or_left_comm] using (perm_merge _ _ _).subset bm with\n        (be | bl | bl')\n      · subst b'\n        assumption\n      · exact rel_of_sorted_cons h₁ _ bl\n      · exact _root_.trans h (rel_of_sorted_cons h₂ _ bl')\n    · suffices ∀ (b' : α) (_ : b' ∈ List.merge r (a :: l) l'), r b b' by\n        simpa [List.merge, h, h₁.merge h₂.of_cons]\n      intro b' bm\n      have ba : b ≼ a := (total_of r _ _).resolve_left h\n      have : b' = a ∨ b' ∈ l ∨ b' ∈ l' := by simpa using (perm_merge _ _ _).subset bm\n      rcases this with (be | bl | bl')\n      · subst b'\n        assumption\n      · exact _root_.trans ba (rel_of_sorted_cons h₁ _ bl)\n      · exact rel_of_sorted_cons h₂ _ bl'\n  termination_by Sorted.merge l₁ l₂ _ _ => length l₁ + length l₂\n\n#align list.sorted.merge List.Sorted.merge\n\nvariable (r)\n\ntheorem sorted_mergeSort : ∀ l : List α, Sorted r (mergeSort r l)\n  | [] => by simp [mergeSort]\n  | [a] => by simp [mergeSort]\n  | a :: b :: l => by\n    cases' e : split (a :: b :: l) with l₁ l₂\n    cases' length_split_lt e with h₁ h₂\n    rw [mergeSort_cons_cons r e]\n    exact (sorted_mergeSort l₁).merge (sorted_mergeSort l₂)\n  termination_by sorted_mergeSort l => length l\n#align list.sorted_merge_sort List.sorted_mergeSort\n\ntheorem mergeSort_eq_self [IsAntisymm α r] {l : List α} : Sorted r l → mergeSort r l = l :=\n  eq_of_perm_of_sorted (perm_mergeSort _ _) (sorted_mergeSort _ _)\n#align list.merge_sort_eq_self List.mergeSort_eq_self\n\ntheorem mergeSort_eq_insertionSort [IsAntisymm α r] (l : List α) :\n    mergeSort r l = insertionSort r l :=\n  eq_of_perm_of_sorted ((perm_mergeSort r l).trans (perm_insertionSort r l).symm)\n    (sorted_mergeSort r l) (sorted_insertionSort r l)\n#align list.merge_sort_eq_insertion_sort List.mergeSort_eq_insertionSort\n\nend TotalAndTransitive\n\nend Correctness\n\n@[simp]\ntheorem mergeSort_nil : [].mergeSort r = [] := by rw [List.mergeSort]\n#align list.merge_sort_nil List.mergeSort_nil\n\n@[simp]\ntheorem mergeSort_singleton (a : α) : [a].mergeSort r = [a] := by rw [List.mergeSort]\n#align list.merge_sort_singleton List.mergeSort_singleton\n\nend MergeSort\n\nend sort\n\n-- try them out!\n--#eval insertionSort (fun m n : ℕ => m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\n--#eval mergeSort     (fun m n : ℕ => m ≤ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]\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/Sort.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.7543349814040666}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que en los reales, si\n--    x ≤ y ∧ x ≠ y\n-- entonces\n--    ¬ y ≤ x \n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {x y : ℝ} \n\n-- 1ª demostración\n-- ===============\n\nexample \n  (h : x ≤ y ∧ x ≠ y) \n  : ¬ y ≤ x :=\nbegin\n  cases h with h₀ h₁,\n  contrapose! h₁,\n  exact le_antisymm h₀ h₁,\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : ℝ,\nh : x ≤ y ∧ x ≠ y\n⊢ ¬y ≤ x\n  >> cases h with h₀ h₁,\nh₀ : x ≤ y,\nh₁ : x ≠ y\n⊢ ¬y ≤ x\n  >> contrapose! h₁,\nh₀ : x ≤ y,\nh₁ : y ≤ x\n⊢ x = y\n  >> exact le_antisymm h₀ h₁, \nno goals\n-/\n\n\n-- Comentario: La táctica (cases h with h₀ h₁,) si la hipótesis h es una\n-- conjunción (P ∧ Q), aplica la regla de eliminación de la conjunción;\n-- es decir, sustituy h por las hipótesis (h₀ : P) y (h₁ : Q).\n\n-- 2ª demostración\n-- ===============\n\nexample : x ≤ y ∧ x ≠ y → ¬ y ≤ x :=\nbegin\n  rintros ⟨h₀, h₁⟩ h',\n  exact h₁ (le_antisymm h₀ h'),\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : ℝ\n⊢ x ≤ y ∧ x ≠ y → ¬y ≤ x\n  >> rintros ⟨h₀, h₁⟩ h',\nh' : y ≤ x,\nh₀ : x ≤ y,\nh₁ : x ≠ y\n⊢ false\n  >> exact h₁ (le_antisymm h₀ h'),\nno goals\n-/\n\n-- Comentario: La táctica (rintros ⟨h₀, h₁⟩ h') \n-- + si el objetivo es de la forma (P ∧ Q → (R → S)) añade las hipótesis \n--   (h₀ : P), (h₁ : Q), (h' : R) y sustituye el objetivo por S.\n-- + si el objetivo es de la forma (P ∧ Q → ¬R) añade las hipótesis \n--   (h₀ : P), (h₁ : Q), (h' : R) y sustituye el objetivo por false.\n\n-- 3ª demostración\n-- ===============\n\nexample : x ≤ y ∧ x ≠ y → ¬ y ≤ x :=\nλ ⟨h₀, h₁⟩ h', h₁ (le_antisymm h₀ h')\n\n-- 4ª demostración\n-- ===============\n\nexample \n  (h : x ≤ y ∧ x ≠ y) \n  : ¬ y ≤ x :=\nbegin\n  intro h',\n  apply h.right,\n  exact le_antisymm h.left h',\nend\n\n-- Prueba\n-- ======\n\n/-\nx y : ℝ,\nh : x ≤ y ∧ x ≠ y\n⊢ ¬y ≤ x\n  >> intro h',\nh' : y ≤ x\n⊢ false\n  >> apply h.right,\nh' : y ≤ x\n⊢ x = y\n  >> exact le_antisymm h.left h',\nno goals\n-/\n\n-- Comentario: Si h es una conjunción (P ∧ Q), entonces h.left es P y\n-- h.right es Q. \n\n-- 5ª demostración\n-- ===============\n\nexample {x y : ℝ} (h : x ≤ y ∧ x ≠ y) : ¬ y ≤ x :=\nλ h', h.right (le_antisymm h.left h')\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/Eliminacion_de_la_conjuncion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7543017268395419}}
{"text": "/-\nLemma 10.16.4. Suppose that φ:R→R′ is a ring homomorphism. The induced map\nSpec(φ):Spec(R′)⟶Spec(R),𝔭′⟼φ−1(𝔭′)\nis continuous for the Zariski topologies. In fact, for any element f∈R we have Spec(φ)−1(D(f))=D(φ(f)).\n\nProof. It is tag 00BV that 𝔭:=φ−1(𝔭′) is indeed a prime ideal of R. The last assertion of the lemma follows directly from the definitions, and implies the first. \n-/\n\nimport Kenny_comm_alg.Zariski analysis.topology.continuity\n\nuniverses u v\n\nvariables {α : Type u} {β : Type v} [comm_ring α] [comm_ring β]\nvariables (f : α → β) [is_ring_hom f]\n\ndef Zariski.induced : X β → X α :=\nλ p, ⟨f ⁻¹' p.1, @@is_prime_ideal.hom_preimage _ _ f _ p.1 p.2⟩\n\ninstance zariski.open := Zariski α\n\ntheorem Zariski.induced.continuous : continuous (Zariski.induced f) :=\nλ A ⟨E, ha⟩, ⟨f '' E, set.ext $ λ z,\n⟨λ h hz, suffices (⟨f ⁻¹' z.val, _⟩ : X α) ∈ Spec.V E, by rw ha at this; exact this hz,\n   λ x hx, h ⟨x, hx, rfl⟩,\n λ h x ⟨w, H, hw⟩, have (⟨f ⁻¹' z.val, _⟩ : X α) ∈ Spec.V E, by rw ha; exact h,\n   by rw ← hw; exact this H⟩⟩\n\ntheorem Zariski.induced.preimage_D (x : α) : Zariski.induced f ⁻¹' (Spec.D' x) = Spec.D' (f x) :=\nset.ext $ λ z, by simp [Spec.D', Zariski.induced, Spec.V']", "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/tag00E2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7543017264286042}}
{"text": "import data.real.basic\n\n/- TEXT:\n.. _disjunction:\n\nDisjunction\n-----------\n\n.. index:: left, right, tactics ; left, tactics ; right\n\nThe canonical way to prove a disjunction ``A ∨ B`` is to prove\n``A`` or to prove ``B``.\nThe ``left`` tactic chooses ``A``,\nand the ``right`` tactic chooses ``B``.\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {x y : ℝ}\n\n-- EXAMPLES:\nexample (h : y > x^2) : y > 0 ∨ y < -1 :=\nby { left, linarith [pow_two_nonneg x] }\n\nexample (h : -y > x^2 + 1) : y > 0 ∨ y < -1 :=\nby { right, linarith [pow_two_nonneg x] }\n-- QUOTE.\n\n/- TEXT:\nWe cannot use an anonymous constructor to construct a proof\nof an \"or\" because Lean would have to guess\nwhich disjunct we are trying to prove.\nWhen we write proof terms we can use\n``or.inl`` and ``or.inr`` instead\nto make the choice explicitly.\nHere, ``inl`` is short for \"introduction left\" and\n``inr`` is short for \"introduction right.\"\nTEXT. -/\n-- QUOTE:\nexample (h : y > 0) : y > 0 ∨ y < -1 :=\nor.inl h\n\nexample (h : y < -1) : y > 0 ∨ y < -1 :=\nor.inr h\n-- QUOTE.\n\n/- TEXT:\nIt may seem strange to prove a disjunction by proving one side\nor the other.\nIn practice, which case holds usually depends a case distinction\nthat is implicit or explicit in the assumptions and the data.\nThe ``cases`` tactic allows us to make use of a hypothesis\nof the form ``A ∨ B``.\nIn contrast to the use of ``cases`` with conjunction or an\nexistential quantifier,\nhere the ``cases`` tactic produces *two* goals.\nBoth have the same conclusion, but in the first case,\n``A`` is assumed to be true,\nand in the second case,\n``B`` is assumed to be true.\nIn other words, as the name suggests,\nthe ``cases`` tactic carries out a proof by cases.\nAs usual, we can tell Lean what names to use for the hypotheses.\nIn the next example, we tell Lean\nto use the name ``h`` on each branch.\nTEXT. -/\n-- QUOTE:\nexample : x < abs y → x < y ∨ x < -y :=\nbegin\n  cases le_or_gt 0 y with h h,\n  { rw abs_of_nonneg h,\n    intro h, left, exact h },\n  rw abs_of_neg h,\n  intro h, right, exact h\nend\n-- QUOTE.\n\n/- TEXT:\nThe absolute value function is defined in such a way\nthat we can immediately prove that\n``x ≥ 0`` implies ``abs x = x``\n(this is the theorem ``abs_of_nonneg``)\nand ``x < 0`` implies ``abs x = -x`` (this is ``abs_of_neg``).\nThe expression ``le_or_gt 0 x`` establishes ``0 ≤ x ∨ x < 0``,\nallowing us to split on those two cases.\nTry proving the triangle inequality using the two\nfirst two theorems in the next snippet.\nThey are given the same names they have in mathlib.\nTEXT. -/\n-- BOTH:\n-- QUOTE:\nnamespace my_abs\n\n-- EXAMPLES:\ntheorem le_abs_self (x : ℝ) : x ≤ abs x :=\nsorry\n\ntheorem neg_le_abs_self (x : ℝ) : -x ≤ abs x :=\nsorry\n\ntheorem abs_add (x y : ℝ) : abs (x + y) ≤ abs x + abs y :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem le_abs_selfαα (x : ℝ) : x ≤ abs x :=\nbegin\n  cases le_or_gt 0 x with h h,\n  { rw abs_of_nonneg h },\n  rw abs_of_neg h,\n  linarith\nend\n\ntheorem neg_le_abs_selfαα (x : ℝ) : -x ≤ abs x :=\nbegin\n  cases le_or_gt 0 x with h h,\n  { rw abs_of_nonneg h,\n    linarith },\n  rw abs_of_neg h\nend\n\ntheorem abs_addαα (x y : ℝ) : abs (x + y) ≤ abs x + abs y :=\nbegin\n  cases le_or_gt 0 (x + y) with h h,\n  { rw abs_of_nonneg h,\n    linarith [le_abs_self x, le_abs_self y] },\n  rw abs_of_neg h,\n  linarith [neg_le_abs_self x, neg_le_abs_self y]\nend\n\n/- TEXT:\nIn case you enjoyed these (pun intended) and\nyou want more practice with disjunction,\ntry these.\nTEXT. -/\n-- QUOTE:\ntheorem lt_abs : x < abs y ↔ x < y ∨ x < -y :=\nsorry\n\ntheorem abs_lt : abs x < y ↔ - y < x ∧ x < y :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\ntheorem lt_absαα : x < abs y ↔ x < y ∨ x < -y :=\nbegin\n  cases le_or_gt 0 y with h h,\n  { rw abs_of_nonneg h,\n    split,\n    { intro h', left, exact h' },\n    intro h',\n    cases h' with h' h',\n    { exact h' },\n    linarith },\n  rw abs_of_neg h,\n  split,\n  { intro h', right, exact h' },\n  intro h',\n  cases h' with h' h',\n  { linarith },\n  exact h'\nend\n\ntheorem abs_ltαα : abs x < y ↔ - y < x ∧ x < y :=\nbegin\n  cases le_or_gt 0 x with h h,\n  { rw abs_of_nonneg h,\n    split,\n    { intro h',\n      split,\n      { linarith },\n      exact h' },\n    intro h',\n    cases h' with h1 h2,\n    exact h2 },\n  rw abs_of_neg h,\n  split,\n  { intro h',\n    split,\n    { linarith },\n    linarith },\n  intro h',\n  linarith\nend\n\n-- BOTH:\nend my_abs\nend\n\n/- TEXT:\nYou can also use ``rcases`` and ``rintros`` with disjunctions.\nWhen these result in a genuine case split with multiple goals,\nthe patterns for each new goal are separated by a vertical bar.\nTEXT. -/\n-- QUOTE:\nexample {x : ℝ} (h : x ≠ 0) : x < 0 ∨ x > 0 :=\nbegin\n  rcases lt_trichotomy x 0 with xlt | xeq | xgt,\n  { left, exact xlt },\n  { contradiction },\n  right, exact xgt\nend\n-- QUOTE.\n\n/- TEXT:\nYou can still nest patterns and use the ``rfl`` keyword\nto substitute equations:\nTEXT. -/\n-- QUOTE:\nexample {m n k : ℕ} (h : m ∣ n ∨ m ∣ k) : m ∣ n * k :=\nbegin\n  rcases h with ⟨a, rfl⟩ | ⟨b, rfl⟩,\n  { rw [mul_assoc],\n    apply dvd_mul_right },\n  rw [mul_comm, mul_assoc],\n  apply dvd_mul_right\nend\n-- QUOTE.\n\n/- TEXT:\nSee if you can prove the following with a single (long) line.\nUse ``rcases`` to unpack the hypotheses and split on cases,\nand use a semicolon and ``linarith`` to solve each branch.\nTEXT. -/\n-- QUOTE:\nexample {z : ℝ} (h : ∃ x y, z = x^2 + y^2 ∨ z = x^2 + y^2 + 1) :\n  z ≥ 0 :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample {z : ℝ} (h : ∃ x y, z = x^2 + y^2 ∨ z = x^2 + y^2 + 1) :\n  z ≥ 0 :=\nby { rcases h with ⟨x, y, rfl | rfl⟩; linarith [sq_nonneg x, sq_nonneg y] }\n\n/- TEXT:\nOn the real numbers, an equation ``x * y = 0``\ntells us that ``x = 0`` or ``y = 0``.\nIn mathlib, this fact is known as ``eq_zero_or_eq_zero_of_mul_eq_zero``,\nand it is another nice example of how a disjunction can arise.\nSee if you can use it to prove the following:\nTEXT. -/\n-- QUOTE:\nexample {x : ℝ} (h : x^2 = 1) : x = 1 ∨ x = -1 :=\nsorry\n\nexample {x y : ℝ} (h : x^2 = y^2) : x = y ∨ x = -y :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample {x : ℝ} (h : x^2 = 1) : x = 1 ∨ x = -1 :=\nbegin\n  have h' : x^2 - 1 = 0,\n  { rw [h, sub_self] },\n  have h'' : (x + 1) * (x - 1) = 0,\n  { rw ← h',\n    ring },\n  cases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 h1,\n  { right,\n    exact eq_neg_iff_add_eq_zero.mpr h1 },\n  left,\n  exact eq_of_sub_eq_zero h1\nend\n\nexample {x y : ℝ} (h : x^2 = y^2) : x = y ∨ x = -y :=\nbegin\n  have h' : x^2 - y^2 = 0,\n  { rw [h, sub_self] },\n  have h'' : (x + y) * (x - y) = 0,\n  { rw ← h',\n    ring },\n  cases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 h1,\n  { right,\n    exact eq_neg_iff_add_eq_zero.mpr h1 },\n  left,\n  exact eq_of_sub_eq_zero h1\nend\n\n/- TEXT:\nRemember that you can use the ``ring`` tactic to help\nwith calculations.\n\nIn an arbitrary ring :math:`R`, an element :math:`x` such\nthat :math:`x y = 0` for some nonzero :math:`y` is called\na *left zero divisor*,\nan element :math:`x` such\nthat :math:`y x = 0` for some nonzero :math:`y` is called\na *right zero divisor*,\nand an element that is either a left or right zero divisor\nis called simply a *zero divisor*.\nThe theorem ``eq_zero_or_eq_zero_of_mul_eq_zero``\nsays that the real numbers have no nontrivial zero divisors.\nA commutative ring with this property is called an *integral domain*.\nYour proofs of the two theorems above should work equally well\nin any integral domain:\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {R : Type*} [comm_ring R] [is_domain R]\nvariables (x y : R)\n\n-- EXAMPLES:\nexample (h : x^2 = 1) : x = 1 ∨ x = -1 :=\nsorry\n\nexample (h : x^2 = y^2) : x = y ∨ x = -y :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : x^2 = 1) : x = 1 ∨ x = -1 :=\nbegin\n  have h' : x^2 - 1 = 0,\n  { rw [h, sub_self] },\n  have h'' : (x + 1) * (x - 1) = 0,\n  { rw ← h',\n    ring },\n  cases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 h1,\n  { right,\n    exact eq_neg_iff_add_eq_zero.mpr h1 },\n  left,\n  exact eq_of_sub_eq_zero h1\nend\n\nexample (h : x^2 = y^2) : x = y ∨ x = -y :=\nbegin\n  have h' : x^2 - y^2 = 0,\n  { rw [h, sub_self] },\n  have h'' : (x + y) * (x - y) = 0,\n  { rw ← h',\n    ring },\n  cases eq_zero_or_eq_zero_of_mul_eq_zero h'' with h1 h1,\n  { right,\n    exact eq_neg_iff_add_eq_zero.mpr h1 },\n  left,\n  exact eq_of_sub_eq_zero h1\nend\n\n-- BOTH:\nend\n\n/- TEXT:\nIn fact, if you are careful, you can prove the first\ntheorem without using commutativity of multiplication.\nIn that case, it suffices to assume that ``R`` is\na ``domain`` instead of an ``integral_domain``.\n\n.. index:: excluded middle\n\nSometimes in a proof we want to split on cases\ndepending on whether some statement is true or not.\nFor any proposition ``P``, we can use\n``classical.em P : P ∨ ¬ P``.\nThe name ``em`` is short for \"excluded middle.\"\nTEXT. -/\n-- QUOTE:\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro h,\n  cases classical.em P,\n  { assumption },\n  contradiction\nend\n-- QUOTE.\n\n/- TEXT:\n.. index:: by_cases, tactics ; by_cases\n\nYou can shorten ``classical.em`` to ``em``\nby opening the ``classical`` namespace with the command\n``open classical``.\nAlternatively, you can use the ``by_cases`` tactic.\nThe ``open_locale classical`` command guarantees that Lean can\nmake implicit use of the law of the excluded middle.\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nopen_locale classical\n\n-- EXAMPLES:\nexample (P : Prop) : ¬ ¬ P → P :=\nbegin\n  intro h,\n  by_cases h' : P,\n  { assumption },\n  contradiction\nend\n-- QUOTE.\n\n/- TEXT:\nNotice that the ``by_cases`` tactic lets you\nspecify a label for the hypothesis that is\nintroduced in each branch,\nin this case, ``h' : P`` in one and ``h' : ¬ P``\nin the other.\nIf you leave out the label,\nLean uses ``h`` by default.\nTry proving the following equivalence,\nusing ``by_cases`` to establish one direction.\nTEXT. -/\n-- QUOTE:\nexample (P Q : Prop) : (P → Q) ↔ ¬ P ∨ Q :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (P Q : Prop) : (P → Q) ↔ ¬ P ∨ Q :=\nbegin\n  split,\n  { intro h,\n    by_cases h' : P,\n    { right,\n      exact h h'},\n    left,\n    exact h' },\n  rintros (h | h),\n  { intro h',\n    exact absurd h' h },\n  intro _,\n  exact h\nend\n\n-- BOTH:\nend", "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_05_Disjunction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7543017215454967}}
{"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.apply_fun\nimport algebra.field.opposite\nimport algebra.field_power\nimport data.equiv.ring_aut\nimport group_theory.group_action.units\nimport group_theory.group_action.opposite\nimport algebra.ring.comp_typeclasses\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] [star_ring R]`.\nThis avoids difficulties with diamond inheritance.\n\nWe also define the class `star_ordered_ring 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†`, `rᘁ`, 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`star_ordered_ring` could be defined for this case. Note that the current definition has the\nadvantage of not requiring a topology.\n-/\n\n\nuniverses u v\n\nopen mul_opposite\n\n/--\nNotation typeclass (with no default notation!) for an algebraic structure with a star operation.\n-/\nclass has_star (R : Type u) :=\n(star : R → R)\n\nvariables {R : Type u}\n\nexport has_star (star)\n\n/--\nA star operation (e.g. complex conjugate).\n-/\nadd_decl_doc star\n\n\n/--\nTypeclass for a star operation with is involutive.\n-/\nclass has_involutive_star (R : Type u) extends has_star R :=\n(star_involutive : function.involutive star)\n\nexport has_involutive_star (star_involutive)\n\n@[simp] lemma star_star [has_involutive_star R] (r : R) : star (star r) = r :=\nstar_involutive _\n\nlemma star_injective [has_involutive_star R] : function.injective (star : R → R) :=\nstar_involutive.injective\n\n/--\nTypeclass for a trivial star operation. This is mostly meant for `ℝ`.\n-/\nclass has_trivial_star (R : Type u) [has_star R] :=\n(star_trivial : ∀ (r : R), star r = r)\n\nexport has_trivial_star (star_trivial)\nattribute [simp] star_trivial\n\n/--\nA `*`-monoid is a monoid `R` with an involutive operations `star`\nso `star (r * s) = star s * star r`.\n-/\nclass star_monoid (R : Type u) [monoid R] extends has_involutive_star R :=\n(star_mul : ∀ r s : R, star (r * s) = star s * star r)\n\nexport star_monoid (star_mul)\nattribute [simp] star_mul\n\n/-- In a commutative ring, make `simp` prefer leaving the order unchanged. -/\n@[simp] lemma star_mul' [comm_monoid R] [star_monoid R] (x y : R) :\n  star (x * y) = star x * star y :=\n(star_mul x y).trans (mul_comm _ _)\n\n/-- `star` as an `mul_equiv` from `R` to `Rᵐᵒᵖ` -/\n@[simps apply]\ndef star_mul_equiv [monoid R] [star_monoid R] : R ≃* Rᵐᵒᵖ :=\n{ to_fun := λ x, mul_opposite.op (star x),\n  map_mul' := λ x y, (star_mul x y).symm ▸ (mul_opposite.op_mul _ _),\n  ..(has_involutive_star.star_involutive.to_equiv star).trans op_equiv}\n\n/-- `star` as a `mul_aut` for commutative `R`. -/\n@[simps apply]\ndef star_mul_aut [comm_monoid R] [star_monoid R] : mul_aut R :=\n{ to_fun := star,\n  map_mul' := star_mul',\n  ..(has_involutive_star.star_involutive.to_equiv star) }\n\nvariables (R)\n\n@[simp] lemma star_one [monoid R] [star_monoid R] : star (1 : R) = 1 :=\nop_injective $ (star_mul_equiv : R ≃* Rᵐᵒᵖ).map_one.trans (op_one _).symm\n\nvariables {R}\n\n@[simp] lemma star_pow [monoid R] [star_monoid R] (x : R) (n : ℕ) : star (x ^ n) = star x ^ n :=\nop_injective $\n  ((star_mul_equiv : R ≃* Rᵐᵒᵖ).to_monoid_hom.map_pow x n).trans (op_pow (star x) n).symm\n\n@[simp] lemma star_inv [group R] [star_monoid R] (x : R) : star (x⁻¹) = (star x)⁻¹ :=\nop_injective $\n  ((star_mul_equiv : R ≃* Rᵐᵒᵖ).to_monoid_hom.map_inv x).trans (op_inv (star x)).symm\n\n@[simp] lemma star_zpow [group R] [star_monoid R] (x : R) (z : ℤ) : star (x ^ z) = star x ^ z :=\nop_injective $\n  ((star_mul_equiv : R ≃* Rᵐᵒᵖ).to_monoid_hom.map_zpow x z).trans (op_zpow (star x) z).symm\n\n/-- When multiplication is commutative, `star` preserves division. -/\n@[simp] lemma star_div [comm_group R] [star_monoid R] (x y : R) : star (x / y) = star x / star y :=\n(star_mul_aut : R ≃* R).to_monoid_hom.map_div _ _\n\nsection\nopen_locale big_operators\n\n@[simp] lemma star_prod [comm_monoid R] [star_monoid R] {α : Type*}\n  (s : finset α) (f : α → R):\n  star (∏ x in s, f x) = ∏ x in s, star (f x) :=\n(star_mul_aut : R ≃* R).map_prod _ _\n\nend\n\n/--\nAny commutative monoid admits the trivial `*`-structure.\n\nSee note [reducible non-instances].\n-/\n@[reducible]\ndef star_monoid_of_comm {R : Type*} [comm_monoid R] : star_monoid R :=\n{ star := id,\n  star_involutive := λ x, rfl,\n  star_mul := mul_comm }\n\nsection\nlocal attribute [instance] star_monoid_of_comm\n\n/-- Note that since `star_monoid_of_comm` is reducible, `simp` can already prove this. --/\nlemma star_id_of_comm {R : Type*} [comm_semiring R] {x : R} : star x = x := rfl\n\nend\n\n/--\nA `*`-additive monoid `R` is an additive monoid with an involutive `star` operation which\npreserves addition.\n-/\nclass star_add_monoid (R : Type u) [add_monoid R] extends has_involutive_star R :=\n(star_add : ∀ r s : R, star (r + s) = star r + star s)\n\nexport star_add_monoid (star_add)\nattribute [simp] star_add\n\n/-- `star` as an `add_equiv` -/\n@[simps apply]\ndef star_add_equiv [add_monoid R] [star_add_monoid R] : R ≃+ R :=\n{ to_fun := star,\n  map_add' := star_add,\n  ..(has_involutive_star.star_involutive.to_equiv star)}\n\nvariables (R)\n\n@[simp] lemma star_zero [add_monoid R] [star_add_monoid R] : star (0 : R) = 0 :=\n(star_add_equiv : R ≃+ R).map_zero\n\nvariables {R}\n\n@[simp] lemma star_neg [add_group R] [star_add_monoid R] (r : R) : star (-r) = - star r :=\n(star_add_equiv : R ≃+ R).map_neg _\n\n@[simp] lemma star_sub [add_group R] [star_add_monoid R] (r s : R) :\n  star (r - s) = star r - star s :=\n(star_add_equiv : R ≃+ R).map_sub _ _\n\n@[simp] lemma star_nsmul [add_comm_monoid R] [star_add_monoid R] (x : R) (n : ℕ) :\n  star (n • x) = n • star x :=\n(star_add_equiv : R ≃+ R).to_add_monoid_hom.map_nsmul _ _\n\n@[simp] lemma star_zsmul [add_comm_group R] [star_add_monoid R] (x : R) (n : ℤ) :\n  star (n • x) = n • star x :=\n(star_add_equiv : R ≃+ R).to_add_monoid_hom.map_zsmul _ _\n\nsection\nopen_locale big_operators\n\n@[simp] lemma star_sum [add_comm_monoid R] [star_add_monoid R] {α : Type*}\n  (s : finset α) (f : α → R):\n  star (∑ x in s, f x) = ∑ x in s, star (f x) :=\n(star_add_equiv : R ≃+ R).map_sum _ _\n\nend\n\n/--\nA `*`-ring `R` is a (semi)ring with an involutive `star` operation which is additive\nwhich makes `R` with its multiplicative structure into a `*`-monoid\n(i.e. `star (r * s) = star s * star r`).\n-/\nclass star_ring (R : Type u) [semiring R] extends star_monoid R :=\n(star_add : ∀ r s : R, star (r + s) = star r + star s)\n\n@[priority 100]\ninstance star_ring.to_star_add_monoid [semiring R] [star_ring R] : star_add_monoid R :=\n{ star_add := star_ring.star_add }\n\n/-- `star` as an `ring_equiv` from `R` to `Rᵐᵒᵖ` -/\n@[simps apply]\ndef star_ring_equiv [semiring R] [star_ring R] : R ≃+* Rᵐᵒᵖ :=\n{ to_fun := λ x, mul_opposite.op (star x),\n  ..star_add_equiv.trans (mul_opposite.op_add_equiv : R ≃+ Rᵐᵒᵖ),\n  ..star_mul_equiv }\n\n/-- `star` as a ring automorphism, for commutative `R`. -/\n@[simps apply]\ndef star_ring_aut [comm_semiring R] [star_ring R] : ring_aut R :=\n{ to_fun := star,\n  ..star_add_equiv,\n  ..star_mul_aut }\n\nvariables (R)\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 `complex_conjugate`.\n\nNote that this is the preferred form (over `star_ring_aut`, available under the same hypotheses)\nbecause the notation `E →ₗ⋆[R] F` for an `R`-conjugate-linear map (short for\n`E →ₛₗ[star_ring_end R] F`) does not pretty-print if there is a coercion involved, as would be the\ncase for `(↑star_ring_aut : R →* R)`. -/\ndef star_ring_end [comm_semiring R] [star_ring R] : R →+* R := @star_ring_aut R _ _\nvariables {R}\n\nlocalized \"notation `conj` := star_ring_end _\" in complex_conjugate\n\n/-- This is not a simp lemma, since we usually want simp to keep `star_ring_end` 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`. -/\nlemma star_ring_end_apply [comm_semiring R] [star_ring R] {x : R} :\n  star_ring_end R x = star x := rfl\n\n@[simp] lemma star_ring_end_self_apply [comm_semiring R] [star_ring R] (x : R) :\n  star_ring_end R (star_ring_end R x) = x := star_star x\n\n-- A more convenient name for complex conjugation\nalias star_ring_end_self_apply ← complex.conj_conj\nalias star_ring_end_self_apply ← is_R_or_C.conj_conj\n\n@[simp] lemma star_inv' [division_ring R] [star_ring R] (x : R) : star (x⁻¹) = (star x)⁻¹ :=\nop_injective $\n  ((star_ring_equiv : R ≃+* Rᵐᵒᵖ).to_ring_hom.map_inv x).trans (op_inv (star x)).symm\n\n@[simp] lemma star_zpow₀ [division_ring R] [star_ring R] (x : R) (z : ℤ) :\n  star (x ^ z) = star x ^ z :=\nop_injective $\n  ((star_ring_equiv : R ≃+* Rᵐᵒᵖ).to_ring_hom.map_zpow x z).trans (op_zpow (star x) z).symm\n\n/-- When multiplication is commutative, `star` preserves division. -/\n@[simp] lemma star_div' [field R] [star_ring R] (x y : R) : star (x / y) = star x / star y :=\n(star_ring_end R).map_div _ _\n\n@[simp] lemma star_bit0 [ring R] [star_ring R] (r : R) : star (bit0 r) = bit0 (star r) :=\nby simp [bit0]\n\n@[simp] lemma star_bit1 [ring R] [star_ring R] (r : R) : star (bit1 r) = bit1 (star r) :=\nby simp [bit1]\n\n/--\nAny commutative semiring admits the trivial `*`-structure.\n\nSee note [reducible non-instances].\n-/\n@[reducible]\ndef star_ring_of_comm {R : Type*} [comm_semiring R] : star_ring R :=\n{ star := id,\n  star_add := λ x y, rfl,\n  ..star_monoid_of_comm }\n\n/--\nAn ordered `*`-ring is a ring which is both an `ordered_add_comm_group` and a `*`-ring,\nand `0 ≤ r ↔ ∃ s, r = star s * s`.\n-/\nclass star_ordered_ring (R : Type u) [ring R] [partial_order R] extends star_ring R :=\n(add_le_add_left       : ∀ a b : R, a ≤ b → ∀ c : R, c + a ≤ c + b)\n(nonneg_iff            : ∀ r : R, 0 ≤ r ↔ ∃ s, r = star s * s)\n\nnamespace star_ordered_ring\n\nvariables [ring R] [partial_order R] [star_ordered_ring R]\n\n@[priority 100] -- see note [lower instance priority]\ninstance : ordered_add_comm_group R :=\n{ ..show ring R, by apply_instance,\n  ..show partial_order R, by apply_instance,\n  ..show star_ordered_ring R, by apply_instance }\n\nend star_ordered_ring\n\nlemma star_mul_self_nonneg [ring R] [partial_order R] [star_ordered_ring R] {r : R} :\n  0 ≤ star r * r :=\n(star_ordered_ring.nonneg_iff _).mpr ⟨r, rfl⟩\n\nlemma star_mul_self_nonneg' [ring R] [partial_order R] [star_ordered_ring R] {r : R} :\n  0 ≤ r * star r :=\nby { nth_rewrite_rhs 0 [←star_star r], exact star_mul_self_nonneg }\n\n/--\nA 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 • a) = star r • star a`.\n\nNote that it is up to the user of this typeclass to enforce\n`[semiring R] [star_ring R] [add_comm_monoid A] [star_add_monoid A] [module R A]`, and that\nthe statement only requires `[has_star R] [has_star A] [has_scalar R A]`.\n\nIf used as `[comm_ring R] [star_ring R] [semiring A] [star_ring A] [algebra R A]`, this represents a\nstar algebra.\n-/\nclass star_module (R : Type u) (A : Type v) [has_star R] [has_star A] [has_scalar R A] :=\n(star_smul : ∀ (r : R) (a : A), star (r • a) = star r • star a)\n\nexport star_module (star_smul)\nattribute [simp] star_smul\n\n/-- A commutative star monoid is a star module over itself via `monoid.to_mul_action`. -/\ninstance star_monoid.to_star_module [comm_monoid R] [star_monoid R] : star_module R R :=\n⟨star_mul'⟩\n\nnamespace ring_hom_inv_pair\n\n/-- Instance needed to define star-linear maps over a commutative star ring\n(ex: conjugate-linear maps when R = ℂ).  -/\ninstance [comm_semiring R] [star_ring R] :\n  ring_hom_inv_pair (star_ring_end R) (star_ring_end R) :=\n⟨ring_hom.ext star_star, ring_hom.ext star_star⟩\n\nend ring_hom_inv_pair\n\n/-! ### Instances -/\n\nnamespace units\n\nvariables [monoid R] [star_monoid R]\n\ninstance : star_monoid Rˣ :=\n{ star := λ u,\n  { val := star u,\n    inv := star ↑u⁻¹,\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 := λ u, units.ext (star_involutive _),\n  star_mul := λ u v, units.ext (star_mul _ _) }\n\n@[simp] lemma coe_star (u : Rˣ) : ↑(star u) = (star ↑u : R) := rfl\n@[simp] lemma coe_star_inv (u : Rˣ) : ↑(star u)⁻¹ = (star ↑u⁻¹ : R) := rfl\n\ninstance {A : Type*} [has_star A] [has_scalar R A] [star_module R A] : star_module Rˣ A :=\n⟨λ u a, (star_smul ↑u a : _)⟩\n\nend units\n\nlemma is_unit.star [monoid R] [star_monoid R] {a : R} : is_unit a → is_unit (star a)\n| ⟨u, hu⟩ := ⟨star u, hu ▸ rfl⟩\n\n@[simp] lemma is_unit_star [monoid R] [star_monoid R] {a : R} : is_unit (star a) ↔ is_unit a :=\n⟨λ h, star_star a ▸ h.star, is_unit.star⟩\n\nlemma ring.inverse_star [semiring R] [star_ring R] (a : R) :\n  ring.inverse (star a) = star (ring.inverse a) :=\nbegin\n  by_cases ha : is_unit a,\n  { obtain ⟨u, rfl⟩ := ha,\n    rw [ring.inverse_unit, ←units.coe_star, ring.inverse_unit, ←units.coe_star_inv], },\n  rw [ring.inverse_non_unit _ ha, ring.inverse_non_unit _ (mt is_unit_star.mp ha), star_zero],\nend\n\nnamespace mul_opposite\n\n/-- The opposite type carries the same star operation. -/\ninstance [has_star R] : has_star (Rᵐᵒᵖ) :=\n{ star := λ r, op (star (r.unop)) }\n\n@[simp] lemma unop_star [has_star R] (r : Rᵐᵒᵖ) : unop (star r) = star (unop r) := rfl\n@[simp] lemma op_star [has_star R] (r : R) : op (star r) = star (op r) := rfl\n\ninstance [has_involutive_star R] : has_involutive_star (Rᵐᵒᵖ) :=\n{ star_involutive := λ r, unop_injective (star_star r.unop) }\n\ninstance [monoid R] [star_monoid R] : star_monoid (Rᵐᵒᵖ) :=\n{ star_mul := λ x y, unop_injective (star_mul y.unop x.unop) }\n\ninstance [add_monoid R] [star_add_monoid R] : star_add_monoid (Rᵐᵒᵖ) :=\n{ star_add := λ x y, unop_injective (star_add x.unop y.unop) }\n\ninstance [semiring R] [star_ring R] : star_ring (Rᵐᵒᵖ) :=\n{ .. mul_opposite.star_add_monoid }\n\nend mul_opposite\n\n/-- A commutative star monoid is a star module over its opposite via\n`monoid.to_opposite_mul_action`. -/\ninstance star_monoid.to_opposite_star_module [comm_monoid R] [star_monoid R] : star_module Rᵐᵒᵖ R :=\n⟨λ r s, star_mul' s r.unop⟩\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7543017146558465}}
{"text": "import data.nat.modeq\nimport data.nat.basic\nimport data.int.basic\nimport data.nat.prime\nimport data.nat.gcd\nimport data.zmod.quadratic_reciprocity\n\n#check zmodp.fermat_little\n\n#check zmodp.eq_zero_iff_dvd_nat\n\nlemma lcm_property (e d p q: ℕ) : (e*d = 1 % (nat.lcm p q)) → e*d -1 = 0 ∨ (∃ h: ℕ, e*d - 1 = h*(p - 1)) :=\nbegin\nintro h,\nsorry\nend\n\n/- These are the two major helper theorems for the RSA_correctness theorem -/\ntheorem RSA_lemma_modp (e d m p q: ℕ): ((nat.prime p ∧ nat.prime q ∧ p ≠ q) ∧ (e*d = 1 % (nat.lcm p q))) → (m^e)^d ≡ m [MOD p] :=\nbegin\n    intro hyp,\n    by_cases (m = 0 % p),\n    {sorry},\n    sorry\nend\n\ntheorem RSA_lemma_modq (e d m p q: ℕ): ((nat.prime p ∧ nat.prime q ∧ p ≠ q) ∧ (e*d = 1 % (nat.lcm p q))) → (m^e)^d ≡ m [MOD q] :=\nbegin\n    intro hyp,\n    by_cases (m = 0 % p),\n    {sorry},\n    sorry\nend\n\n/- This is a small lemma that says that if you have two different primes, they are coprime. -/\n#check nat.prime.coprime_iff_not_dvd\nlemma coprime_prime_and_prime {p q : ℕ}: nat.prime p ∧ nat.prime q ∧ p ≠ q → nat.coprime p q :=\nbegin\nintro hyp,\nhave h1: nat.prime p, from hyp.left,\nhave h2: nat.prime q, from (hyp.right).left,\nhave h3: p ≠ q, from (hyp.right).right,\nhave iff_conc: (nat.coprime p q ↔ ¬ p | q), from nat.prime.coprime_iff_not_dvd h1,\nsorry\nend\n\n/- Technically you can get this theorem for all m in Z but to avoid casting we state it for nats -/\n#check nat.modeq.modeq_and_modeq_iff_modeq_mul\ntheorem RSA_correctness (e d m p q: ℕ): ((nat.prime p ∧ nat.prime q ∧ p ≠ q) ∧ (e*d = 1 % (nat.lcm p q))) → (m^e)^d ≡ m [MOD (p*q)] :=\nbegin\n    intro hyp,\n    have hyp1: nat.prime p ∧ nat.prime q ∧ p ≠ q, from hyp.left,\n    have h1: (m^e)^d ≡ m [MOD p], from RSA_lemma_modp e d m p q hyp,\n    have h2: (m^e)^d ≡ m [MOD q], from RSA_lemma_modq e d m p q hyp,\n     have h1andh2: (m^e)^d ≡ m [MOD p] ∧ (m^e)^d ≡ m [MOD q], from and.intro h1 h2,\n    have h3: nat.coprime p q, from coprime_prime_and_prime hyp.left,\n    have h4: ((m^e)^d ≡ m [MOD p] ∧ (m^e)^d ≡ m [MOD q]) ↔ (m^e)^d ≡ m [MOD p*q], from nat.modeq.modeq_and_modeq_iff_modeq_mul h3,\n    have h5: (m^e)^d ≡ m [MOD p*q], from (iff.elim_left h4) h1andh2,\n    exact h5\nend\n/-    intros e d m p q,\n    or.elim (em (m = 0 % p))\n    {sorry},\n    sorry-/", "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/NumberTheoryStuff.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7543010136024603}}
{"text": "import algebra.big_operators.intervals\nimport algebra.big_operators.order\nimport data.nat.basic\nimport data.nat.factorization.basic\nimport data.nat.factors\nimport data.nat.interval\nimport data.nat.log\nimport data.real.basic\nimport data.fintype.basic\nimport data.finset.basic\nimport data.set.intervals.basic\nimport order.with_bot  -- with_bot.decidable_le\n\nopen_locale big_operators\n\n-- def is_prime_le (n p : ℕ) : Prop := p ≤ n ∧ p.prime\n--\n-- -- Is this necessary? Feels redundant?\n-- instance decidable_is_prime_le (n p : ℕ) : decidable (is_prime_le n p) :=\n-- begin\n--   apply decidable_of_iff (p ≤ n ∧ p.prime),\n--   rw is_prime_le,\n-- end\n\n-- Could define all_factors_le using k.factors.maximum ≤ n?\n-- However, it's difficult to work with (list.maximum ≤ n).\n-- Instead define with for-all statement; use list.maximum to prove decidable.\n-- TODO: Consider k in ℕ+ rather than ℕ?\ndef all_factors_le (n k : ℕ) : Prop := ∀ (p : ℕ), p ∈ k.factors → p ≤ n\n\nlemma all_factors_le_one (n : ℕ) : all_factors_le n 1 := by simp [all_factors_le]\n\nlemma all_factors_le_of_le {n : ℕ} {k : ℕ} (hk : k ≤ n) : all_factors_le n k :=\nbegin\n  rw all_factors_le,\n  intros p hp,\n  apply le_trans _ hk,\n  exact nat.le_of_mem_factors hp,\nend\n\n-- Prove decidable.\n\nlemma exists_maximum_eq_coe_iff {l : list ℕ} : (∃ x : ℕ, l.maximum = ↑x) ↔ l ≠ list.nil :=\nbegin\n  apply iff.intro,\n  { intro h,\n    cases h with x hx,\n    rw list.maximum_eq_coe_iff at hx,\n    exact list.ne_nil_of_mem hx.left, },\n  { intro h,\n    replace h := list.foldr_max_of_ne_nil h,\n    rw ← h,\n    simp, },\nend\n\n-- This feels too fundamental? Doesn't exist in mathlib?\nlemma maximum_le_iff_forall_le {l : list ℕ} {m : ℕ} :\n  l.maximum ≤ ↑m ↔ ∀ (x : ℕ), x ∈ l → x ≤ m :=\nbegin\n  cases decidable.em (l = list.nil),\n  { rw h, simp, },\n  { rw (by simp : ¬l = list.nil ↔ l ≠ list.nil) at h,\n    -- Get the actual maximum.\n    rw ← exists_maximum_eq_coe_iff at h,\n    cases h with c hc,\n    rw hc,\n    simp,\n    rw list.maximum_eq_coe_iff at hc,\n    apply iff.intro,\n    { intros h x hx,\n      apply le_trans _ h,\n      exact hc.right x hx, },\n    { intro h,\n      exact h c hc.left, }, },\nend\n\n-- These two types are equal? Why do we need to define this?\ndef convert (x : option ℕ) : with_bot ℕ := x\n\n-- This feels like a more natural way to write maximum?\nlemma maximum_eq_foldr {l : list ℕ} : l.maximum = list.foldr (max ∘ coe) ⊥ l :=\nbegin\n  rw list.maximum,\n  rw list.argmax,\n  rw ← list.foldr_map,\n  rw ← list.foldl_eq_foldr max_commutative max_associative,\n  rw list.foldl_map,\n  -- Need list.foldl_hom because lhs uses (option ℕ) and rhs uses (with_bot ℕ).\n  have h : (∀ (x : option ℕ), x = convert x) := by { intro x, rw convert, },\n  rw h (list.foldl _ none _),\n  -- rw (h none : ⊥ = convert none),  -- Doesn't work like this?\n  have h_none : ⊥ = convert none := h none,\n  rw h_none,\n  rw list.foldl_hom,\n  intros x y,\n  rw [convert, convert],\n  simp,\n  rw list.arg_aux,\n  cases x,\n  { trivial, },\n  { simp,\n    rw [option.some_eq_coe, option.some_eq_coe],\n    rw ite_eq_iff,\n    rw [eq_comm, max_eq_right_iff],\n    rw [eq_comm, max_eq_left_iff],\n    simp,\n    cases lt_or_le x y with hxy hyx,\n    { left, exact and.intro hxy (le_of_lt hxy), },\n    { right, exact hyx, }, },\nend\n\n-- Prove using foldr instead.\nlemma maximum_le_iff_forall_le' {l : list ℕ} {m : ℕ} :\n  l.maximum ≤ ↑m ↔ ∀ (x : ℕ), x ∈ l → x ≤ m :=\nbegin\n  rw maximum_eq_foldr,\n  apply iff.intro,\n  { induction l with a l' hl', simp,\n    simp,\n    intros ha h,\n    exact and.intro ha (hl' h), },\n  { intro h,\n    rw ← list.foldr_map,\n    -- Use `max_le_of_forall_le` instead of induction.\n    -- (Induction might be cleaner?)\n    apply list.max_le_of_forall_le _ _ _,\n    intro x,\n    cases x, simp,\n    rw option.some_eq_coe,\n    have h_inj : function.injective (coe : ℕ → option ℕ) := by\n    { rw function.injective,\n      simp [← option.some_eq_coe], },\n    rw list.mem_map_of_injective h_inj,\n    simp,\n    apply h, },\nend\n\n-- Do we need to prove this?\ninstance all_factors_le_decidable {n k : ℕ} : decidable (all_factors_le n k) :=\nbegin\n  rw all_factors_le,\n  rw ← maximum_le_iff_forall_le,\n  apply with_bot.decidable_le,\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/factors_le.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7543010097163994}}
{"text": "import tactic.push_neg\nimport data.int.basic\n\nexample (h : ∃ p: ℕ, ¬ ∀ n : ℕ, n > p) (h' : ∃ p: ℕ, ¬ ∃ n : ℕ, n < p) : ¬ ∀ n : ℕ, n = 0 :=\nbegin\n  push_neg at *,\n  guard_target_strict ∃ (n : ℕ), n ≠ 0,\n  guard_hyp_strict h : ∃ (p n : ℕ), n ≤ p,\n  guard_hyp_strict h' : ∃ (p : ℕ), ∀ (n : ℕ), p ≤ n,\n  use 1,\nend\n\n-- In the next example, ℤ should be ℝ in maths, but I don't want to import real numbers\n-- for testing only\nlocal notation `|` x `|` := abs x\n\nexample (a : ℕ → ℤ) (l : ℤ) (h : ¬ ∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε) : true :=\nbegin\n  push_neg at h,\n  guard_hyp_strict h : ∃ (ε : ℤ), ε > 0 ∧ ∀ (N : ℕ), ∃ (n : ℕ), n ≥ N ∧ ε ≤ |a n - l|,\n  trivial\nend\n\nexample (f : ℤ → ℤ) (x₀ y₀) (h : ¬ ∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - y₀| ≤ ε) : true :=\nbegin\n  push_neg at h,\n  guard_hyp_strict h : ∃ (ε : ℤ), ε > 0 ∧ ∀ δ > 0, (∃ (x : ℤ), |x - x₀| ≤ δ ∧ ε < |f x - y₀| ),\n  trivial\nend\n\nexample (n) : n*n ≠ 1 → n ≠ 1 :=\nbegin\n  contrapose,\n  rw [not_not, not_not],\n  intro h,\n  rw [h, one_mul]\nend\n\nexample (n) : n*n ≠ 1 → n ≠ 1 :=\nbegin\n  contrapose!,\n  intro h,\n  rw [h, one_mul]\nend\n\nexample (n) (h : n*n ≠ 1) : n ≠ 1 :=\nbegin\n  contrapose h,\n  rw not_not at *,\n  rw [h, one_mul]\nend\n\nexample (n) (h : n*n ≠ 1) : n ≠ 1 :=\nbegin\n  contrapose! h,\n  rw [h, one_mul]\nend\n\nexample (n) (h : n*n ≠ 1) : n ≠ 1 :=\nbegin\n  contrapose! h with newh,\n  rw [newh, one_mul]\nend\n\nexample : 0 = 0 :=\nbegin\n  success_if_fail_with_msg { contrapose }\n    \"The goal is not an implication, and you didn't specify an assumption\",\n  refl\nend\n\n-- Remember that ∀ is the same as Π which is a generalization of → so we need to make sure\n-- `contrapose` fails with a helpful error message in the next example.\nexample : ∀ x : ℕ, x = x :=\nbegin\n  success_if_fail_with_msg { contrapose }\n    \"contrapose only applies to nondependent arrows between props\",\n  intro, refl\nend\n\nopen tactic\nexample (X : Type) (f : X → ℕ) (h : ¬∀ x, f x = 0) (hf : false) : false :=\nbegin\n  have h1 := h,\n  -- h h1: ¬∀ (x : X), f x = 0\n  push_neg at h,\n  push_neg at h1,\n  (do ht ← get_local `h >>= infer_type,\n      h1t ← get_local `h1 >>= infer_type,\n      guard (ht = h1t) ),\n  exact 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/test/push_neg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7543010018242352}}
{"text": "/-\nCopyright (c) 2022 Rémy Degenne. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rémy Degenne\n-/\n\nimport probability.variance\n\n/-!\n# Moments and moment generating function\n\n## Main definitions\n\n* `moment X p μ`: `p`th moment of a real random variable `X` with respect to measure `μ`, `μ[X^p]`\n* `central_moment X p μ`:`p`th central moment of `X` with respect to measure `μ`, `μ[(X - μ[X])^p]`\n* `mgf X μ t`: moment generating function of `X` with respect to measure `μ`, `μ[exp(t*X)]`\n* `cgf X μ t`: cumulant generating function, logarithm of the moment generating function\n\n## Main results\n\n* `indep_fun.mgf_add`: if two real random variables `X` and `Y` are independent and their mgf are\n  defined at `t`, then `mgf (X + Y) μ t = mgf X μ t * mgf Y μ t`\n* `indep_fun.cgf_add`: if two real random variables `X` and `Y` are independent and their mgf are\n  defined at `t`, then `cgf (X + Y) μ t = cgf X μ t + cgf Y μ t`\n\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\nvariables {Ω : Type*} {m : measurable_space Ω} {X : Ω → ℝ} {p : ℕ} {μ : measure Ω}\n\ninclude m\n\n/-- Moment of a real random variable, `μ[X ^ p]`. -/\ndef moment (X : Ω → ℝ) (p : ℕ) (μ : measure Ω) : ℝ := μ[X ^ p]\n\n/-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/\ndef central_moment (X : Ω → ℝ) (p : ℕ) (μ : measure Ω) : ℝ := μ[(X - (λ x, μ[X])) ^ p]\n\n@[simp] lemma moment_zero (hp : p ≠ 0) : moment 0 p μ = 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 ≠ 0) : central_moment 0 p μ = 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 μ] (h_int : integrable X μ) :\n  central_moment X 1 μ = (1 - (μ set.univ).to_real) * μ[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 μ] : central_moment X 1 μ = 0 :=\nbegin\n  by_cases h_int : integrable X μ,\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 : ¬ integrable (λ x, X x - integral μ X) μ,\n    { refine λ h_sub, h_int _,\n      have h_add : X = (λ x, X x - integral μ X) + (λ x, integral μ X),\n      { ext1 x, simp, },\n      rw h_add,\n      exact h_sub.add (integrable_const _), },\n    rw integral_undef this, },\nend\n\n@[simp] lemma central_moment_two_eq_variance : central_moment X 2 μ = variance X μ := rfl\n\nsection moment_generating_function\n\nvariables {t : ℝ}\n\n/-- Moment generating function of a real random variable `X`: `λ t, μ[exp(t*X)]`. -/\ndef mgf (X : Ω → ℝ) (μ : measure Ω) (t : ℝ) : ℝ := μ[λ ω, real.exp (t * X ω)]\n\n/-- Cumulant generating function of a real random variable `X`: `λ t, log μ[exp(t*X)]`. -/\ndef cgf (X : Ω → ℝ) (μ : measure Ω) (t : ℝ) : ℝ := real.log (mgf X μ t)\n\n@[simp] lemma mgf_zero_fun : mgf 0 μ t = (μ set.univ).to_real :=\nby simp only [mgf, pi.zero_apply, mul_zero, real.exp_zero, integral_const, algebra.id.smul_eq_mul,\n  mul_one]\n\n@[simp] lemma cgf_zero_fun : cgf 0 μ t = real.log (μ set.univ).to_real :=\nby simp only [cgf, mgf_zero_fun]\n\n@[simp] lemma mgf_zero_measure : mgf X (0 : measure Ω) t = 0 :=\nby simp only [mgf, integral_zero_measure]\n\n@[simp] lemma cgf_zero_measure : cgf X (0 : measure Ω) t = 0 :=\nby simp only [cgf, real.log_zero, mgf_zero_measure]\n\n@[simp] lemma mgf_const' (c : ℝ) : mgf (λ _, c) μ t = (μ set.univ).to_real * real.exp (t * c) :=\nby simp only [mgf, integral_const, algebra.id.smul_eq_mul]\n\n@[simp] lemma mgf_const (c : ℝ) [is_probability_measure μ] : mgf (λ _, c) μ t = real.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 μ] (hμ : μ ≠ 0) (c : ℝ) :\n  cgf (λ _, c) μ t = real.log (μ set.univ).to_real + t * c :=\nbegin\n  simp only [cgf, mgf_const'],\n  rw real.log_mul _ (real.exp_pos _).ne',\n  { rw real.log_exp _, },\n  { rw [ne.def, ennreal.to_real_eq_zero_iff, measure.measure_univ_eq_zero],\n    simp only [hμ, measure_ne_top μ set.univ, or_self, not_false_iff], },\nend\n\n@[simp] lemma cgf_const [is_probability_measure μ] (c : ℝ) : cgf (λ _, c) μ t = t * c :=\nby simp only [cgf, mgf_const, real.log_exp]\n\n@[simp] lemma mgf_zero' : mgf X μ 0 = (μ set.univ).to_real :=\nby simp only [mgf, zero_mul, real.exp_zero, integral_const, algebra.id.smul_eq_mul, mul_one]\n\n@[simp] lemma mgf_zero [is_probability_measure μ] : mgf X μ 0 = 1 :=\nby simp only [mgf_zero', measure_univ, ennreal.one_to_real]\n\n@[simp] lemma cgf_zero' : cgf X μ 0 = real.log (μ set.univ).to_real :=\nby simp only [cgf, mgf_zero']\n\n@[simp] lemma cgf_zero [is_probability_measure μ] : cgf X μ 0 = 0 :=\nby simp only [cgf_zero', measure_univ, ennreal.one_to_real, real.log_one]\n\nlemma mgf_undef (hX : ¬ integrable (λ ω, real.exp (t * X ω)) μ) : mgf X μ t = 0 :=\nby simp only [mgf, integral_undef hX]\n\nlemma cgf_undef (hX : ¬ integrable (λ ω, real.exp (t * X ω)) μ) : cgf X μ t = 0 :=\nby simp only [cgf, mgf_undef hX, real.log_zero]\n\nlemma mgf_nonneg : 0 ≤ mgf X μ t :=\nbegin\n  refine integral_nonneg _,\n  intro ω,\n  simp only [pi.zero_apply],\n  exact (real.exp_pos _).le,\nend\n\nlemma mgf_pos' (hμ : μ ≠ 0) (h_int_X : integrable (λ ω, real.exp (t * X ω)) μ) : 0 < mgf X μ t :=\nbegin\n  simp_rw mgf,\n  have : ∫ (x : Ω), real.exp (t * X x) ∂μ = ∫ (x : Ω) in set.univ, real.exp (t * X x) ∂μ,\n  { simp only [measure.restrict_univ], },\n  rw [this, set_integral_pos_iff_support_of_nonneg_ae _ _],\n  { have h_eq_univ : function.support (λ (x : Ω), real.exp (t * X x)) = set.univ,\n    { ext1 x,\n      simp only [function.mem_support, set.mem_univ, iff_true],\n      exact (real.exp_pos _).ne', },\n    rw [h_eq_univ, set.inter_univ _],\n    refine ne.bot_lt _,\n    simp only [hμ, ennreal.bot_eq_zero, ne.def, measure.measure_univ_eq_zero, not_false_iff], },\n  { refine eventually_of_forall (λ x, _),\n    rw pi.zero_apply,\n    exact (real.exp_pos _).le, },\n  { rwa integrable_on_univ, },\nend\n\nlemma mgf_pos [is_probability_measure μ] (h_int_X : integrable (λ ω, real.exp (t * X ω)) μ) :\n  0 < mgf X μ t :=\nmgf_pos' (is_probability_measure.ne_zero μ) h_int_X\n\n\n\nlemma indep_fun.cgf_add {X Y : Ω → ℝ} (h_indep : indep_fun X Y μ)\n  (h_int_X : integrable (λ ω, real.exp (t * X ω)) μ)\n  (h_int_Y : integrable (λ ω, real.exp (t * Y ω)) μ) :\n  cgf (X + Y) μ t = cgf X μ t + cgf Y μ t :=\nbegin\n  by_cases hμ : μ = 0,\n  { simp [hμ], },\n  simp only [cgf, h_indep.mgf_add h_int_X h_int_Y],\n  exact real.log_mul (mgf_pos' hμ h_int_X).ne' (mgf_pos' hμ h_int_Y).ne',\nend\n\nend moment_generating_function\n\nend probability_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/probability/moments.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7542572370614812}}
{"text": "import tactic\n\nnamespace vilnius\n\n\n/- ### implication -/\n\nexample (P Q : Prop) : P → Q → P :=\nbegin\n  intros hP HQ,\n  exact hP,\nend\n\n/- ### not -/\n\nexample (P Q : Prop) : (P → ¬ Q) → (Q → ¬ P) :=\nbegin\n  intros hPnQ hQ hP,\n  apply hPnQ,\n  exact hP,\n  exact hQ,\nend\n\n\n/- ### and -/\n\nexample (P Q : Prop) : P ∧ Q → Q :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n  exact hQ,\nend\n\nexample (P Q : Prop) : P → Q → P ∧ Q :=\nbegin\n  intros hP hQ,\n  split,\n  exact hP,\n  exact hQ,\nend\n\n\nexample (P Q : Prop) : P ∧ Q → Q ∧ P :=\nbegin\n  intro hPQ,\n  cases hPQ with hP hQ,\n  split,\n  exact hQ,\n  exact hP,\nend\n\n\nexample (P : Prop) : P ∧ ¬ P → false :=\nbegin\n  intro hPnP,\n  cases hPnP with hP hnP,\n  apply hnP,\n  exact hP,\nend\n\n\n/- ## Or -/\n\n\nexample (P Q : Prop) : ¬ P ∨ Q → P → Q :=\nbegin\n  intros hnPQ hP,\n  cases hnPQ with hnP hQ,\n  by_contradiction,\n  apply hnP,\n  exact hP,\n  exact hQ,\nend\n\n\nexample (P Q R : Prop) : P ∨ (Q ∧ R) → ¬ P → ¬ Q → false :=\nbegin\n  intros hPQR hnP hnQ,\n  cases hPQR with hP hQR,\n  apply hnP,\n  exact hP,\n\n  cases hQR with hQ hR,\n  apply hnQ,\n  exact hQ,\nend\n\n\nend vilnius\n\n", "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/Exercices/A.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.7542572212703793}}
{"text": "/-\nCopyright (c) 2023 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Jujian Zhang\n-/\n\nimport ring_theory.ideal.operations\nimport topology.algebra.polynomial\nimport topology.bases\n\n/-!\n# Prime spectrum of a ring and its Zariski topology\n\nThis files contains the following: \n- Zariski topology on the set of all prime ideals of any ring `R`.\n- a basis for Zariski topology \n- if `f : R →+* S` is a ring homomorphism, then `𝔭 ↦ f⁻¹ 𝔭` is continuous. \n- for integral domains, there is a unique generic point.\n-/\n\nopen topological_space\nopen_locale pointwise\n\nuniverse u\n\nvariables (R S : Type u) [comm_ring R] [comm_ring S]\n\n/--\n`Spec R` is the set of prime ideals of `R`\n-/\n@[ext]\nstructure Spec : Type u := \n(as_ideal : ideal R)\n(is_prime : as_ideal.is_prime)\n\nattribute [instance] Spec.is_prime -- making sure class inference knows term of `Spec R` is prime\n\nsection\n\nvariable {R}\n\n/--\nzero locus of a set `s ⊆ R` is the set of all prime ideals larger than `s`.\n\nif `f : R`, then it defines a function `𝔭 ↦ ([f] : R ⧸ 𝔭)`.\n\nSo `V s` is exactly those primes\nvanishing for all `f ∈ s`.\n-/\ndef V (s : set R) : set (Spec R) :=\n{ I : Spec R | s ⊆ I.as_ideal }\n\nlemma mem_V (s : set R) {p : Spec R} : p ∈ V s ↔ s ⊆ p.as_ideal := \niff.rfl\n\n/--\nempty set is zero locus of `R`\n-/\nlemma V_univ : V (set.univ : set R) = ∅ :=\nsorry\n\n/--\nR is zero locus of `∅`\n-/\nlemma V_empty : V (∅ : set R) = set.univ :=\nsorry\n\n/--\nunion of zero loci is zero locus of pointwise product\n-/\nlemma V_union (s t : set R) : V s ∪ V t = V (s * t) :=\nsorry\n\n/--\nintersection of zero loci is zero locus of union\n-/\nlemma V_inter {ι : Sort*} (s : ι → set R) : \n  (⋂ i : ι, V (s i)) = V (⋃ i, (s i)) := \nsorry\n\nend\n\ninstance Zariski_topology : topological_space (Spec R) := sorry\n\n/--\nopen sets of Zariski topology are complement of zero loci\n-/\nlemma zt_is_open (s : set (Spec R)) : is_open s ↔ ∃ (t : set R), s = (V t)ᶜ := sorry\n\nsection\n\nvariables {R S}\n\n/--\nBasic open sets\n-/\ndef D (f : R) : set (Spec R) := (V {f})ᶜ\n\nlemma mem_D (f : R) (p : Spec R) : p ∈ D f ↔ f ∉ p.as_ideal := sorry\nlemma open_D (f : R) : is_open (D f) := sorry\n\n/--\nBasic open sets form a basis\n-/\nlemma D_is_basis : is_topological_basis (set.range (D : R → set (Spec R))) :=\nsorry\n\n/--\nRing homomorphisms induces continuous map (contravariantly).\n-/\ndef comap (f : R →+* S) : Spec S → Spec R :=\nsorry\n\nlemma comap_as_ideal (f : R →+* S) (p : Spec S) : \n  (comap f p).as_ideal = p.as_ideal.comap f :=\nsorry\n\nlemma continuous_comap (f : R →+* S) : continuous (comap f) :=\nsorry\n\nlocal notation `ℤ[X]` := (polynomial ℤ)\n-- every thing from this points work for a generic integral domain\n/--\nthe point corresponding to the zero ideal.\n-/\n@[simps]\ndef η : Spec ℤ[X] :=\n{ as_ideal := sorry,\n  is_prime := sorry }\n\n/--\nthis is a generic point.\n-/\nlemma generic_η : closure {η} = (set.univ : set (Spec ℤ[X])) :=\nsorry\n\n/--\nGeneric points is unique.\n-/\nlemma generic_point_uniq (x : Spec ℤ[X]) (hx : closure {x} = (set.univ : set (Spec ℤ[X]))) :\n  x = η :=\nsorry\n\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/section10topological_stuffs/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7541962838244187}}
{"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, sheet 6 : 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 `⊢ 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 ∈ A ↔ x ∈ 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 ⊆ B → B ⊆ A → A = B :=\nbegin\n  sorry\nend\n\nexample : A ∪ A = A :=\nbegin\n  sorry\nend\n\nexample : A ∩ A = A :=\nbegin\n  sorry\nend\n\nexample : A ∩ B = B ∩ A :=\nbegin\n  sorry\nend\n\nexample : A ∩ (B ∩ C) = (A ∩ B) ∩ C :=\nbegin\n  sorry\nend\n\nexample : A ∪ (B ∪ C) = (A ∪ B) ∪ C :=\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/2021/sets/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7541962668163974}}
{"text": "/-\nCopyright (c) 2021 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Floris Van Doorn, Yury Kudryashov\n-/\n\nimport measure_theory.constructions.borel_space\n\n/-!\n# Regular measures\n\nA measure is `outer_regular` if the measure of any measurable set `A` is the infimum of `μ 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 `μ 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 `μ 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 `μ`, and this implication is recorded as an instance.\n\nIn order to avoid code duplication, we also define a measure `μ` to be `inner_regular` for sets\nsatisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set\n`U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ 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 `ℝ × ℝ` 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 `ℝ × {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 μ`: a typeclass registering that a measure `μ` on a\n  topological space is outer regular.\n* `measure_theory.measure.regular μ`: a typeclass registering that a measure `μ` on a topological\n  space is regular.\n* `measure_theory.measure.weakly_regular μ`: a typeclass registering that a measure `μ` on a\n  topological space is weakly regular.\n* `measure_theory.measure.inner_regular μ p q`: a non-typeclass predicate saying that a measure `μ`\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 `μ` 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 `μ` is outer regular, for every set `s`\n  and `r > μ s` there exists an open superset `U ⊇ 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 < μ U`, there exists a closed `F ⊆ 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 < μ F` and `μ s < μ F + ε`, 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 < μ U`, there exists a compact `K ⊆ 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 < μ K` and `μ s < μ K + ε`, 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 `σ`-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 `σ`-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, §52][halmos1950measure]. Note that Halmos uses an unusual definition of\nBorel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his\nproofs or statements do not apply directly.\n\n[Billingsley, Convergence of Probability Measures][billingsley1999]\n-/\n\nopen set filter\nopen_locale ennreal topology nnreal big_operators\n\nnamespace measure_theory\nnamespace measure\n\n/-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : set α → Prop`,\nif for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ 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 inner_regular {α} {m : measurable_space α} (μ : measure α) (p q : set α → Prop) :=\n∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K ⊆ U, p K ∧ r < μ K\n\nnamespace inner_regular\n\nvariables {α : Type*} {m : measurable_space α} {μ : measure α} {p q : set α → Prop}\n  {U : set α} {ε : ℝ≥0∞}\n\nlemma measure_eq_supr (H : inner_regular μ p q) (hU : q U) : μ U = ⨆ (K ⊆ U) (hK : p K), μ K :=\nbegin\n  refine le_antisymm (le_of_forall_lt $ λ r hr, _) (supr₂_le $ λ K hK, supr_le $ λ _, μ.mono hK),\n  simpa only [lt_supr_iff, exists_prop] using H hU r hr\nend\n\nlemma exists_subset_lt_add (H : inner_regular μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞)\n  (hε : ε ≠ 0) :\n  ∃ K ⊆ U, p K ∧ μ U < μ K + ε :=\nbegin\n  cases eq_or_ne (μ U) 0 with h₀ h₀,\n  { refine ⟨∅, empty_subset _, h0, _⟩,\n    rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero] },\n  { rcases H hU _ (ennreal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩,\n    exact ⟨K, hKU, hKc, ennreal.lt_add_of_sub_lt_right (or.inl hμU) hrK⟩ }\nend\n\nlemma map {α β} [measurable_space α] [measurable_space β] {μ : measure α} {pa qa : set α → Prop}\n  (H : inner_regular μ pa qa) (f : α ≃ β) (hf : ae_measurable f μ)\n  {pb qb : set β → Prop} (hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K))\n  (hB₁ : ∀ K, pb K → measurable_set K) (hB₂ : ∀ U, qb U → measurable_set U) :\n  inner_regular (map f μ) pb qb :=\nbegin\n  intros U hU r hr,\n  rw [map_apply_of_ae_measurable hf (hB₂ _ hU)] at hr,\n  rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩,\n  refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, _⟩,\n  rwa [map_apply_of_ae_measurable hf (hB₁ _ $ hAB' _ hKc), f.preimage_image]\nend\n\nlemma smul (H : inner_regular μ p q) (c : ℝ≥0∞) : inner_regular (c • μ) p q :=\nbegin\n  intros U hU r hr,\n  rw [smul_apply, H.measure_eq_supr hU, smul_eq_mul] at hr,\n  simpa only [ennreal.mul_supr, lt_supr_iff, exists_prop] using hr\nend\n\nlemma trans {q' : set α → Prop} (H : inner_regular μ p q) (H' : inner_regular μ q q') :\n  inner_regular μ p q' :=\nbegin\n  intros U hU r hr,\n  rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩, rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩,\n  exact ⟨K, hKF.trans hFU, hpK, hrK⟩\nend\n\nend inner_regular\n\nvariables {α β : Type*} [measurable_space α] [topological_space α] {μ : measure α}\n\n/-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ 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] class outer_regular (μ : measure α) : Prop :=\n(outer_regular : ∀ ⦃A : set α⦄, measurable_set A → ∀ r > μ A, ∃ U ⊇ A, is_open U ∧ μ U < r)\n\n/-- A measure `μ` is regular if\n  - it is finite on all compact sets;\n  - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;\n  - it is inner regular for open sets, using compact sets:\n    `μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/\n@[protect_proj] class regular (μ : measure α)\n  extends is_finite_measure_on_compacts μ, outer_regular μ : Prop :=\n(inner_regular : inner_regular μ is_compact is_open)\n\n/-- A measure `μ` is weakly regular if\n  - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;\n  - it is inner regular for open sets, using closed sets:\n    `μ(U) = sup {μ(F) | F ⊆ U compact}` for `U` open. -/\n@[protect_proj] class weakly_regular (μ : measure α) extends outer_regular μ : Prop :=\n(inner_regular : inner_regular μ is_closed is_open)\n\n/-- A regular measure is weakly regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance regular.weakly_regular [t2_space α] [regular μ] : weakly_regular μ :=\n{ inner_regular := λ U hU r hr, let ⟨K, hKU, hcK, hK⟩ := regular.inner_regular hU r hr\n  in ⟨K, hKU, hcK.is_closed, hK⟩ }\n\nnamespace outer_regular\n\ninstance zero : outer_regular (0 : measure α) :=\n⟨λ A hA r hr, ⟨univ, subset_univ A, is_open_univ, hr⟩⟩\n\n/-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with\nmeasure less than `r`. -/\nlemma _root_.set.exists_is_open_lt_of_lt [outer_regular μ] (A : set α) (r : ℝ≥0∞) (hr : μ A < r) :\n  ∃ U ⊇ A, is_open U ∧ μ U < r :=\nbegin\n  rcases outer_regular.outer_regular (measurable_set_to_measurable μ A) r\n    (by rwa measure_to_measurable) with ⟨U, hAU, hUo, hU⟩,\n  exact ⟨U, (subset_to_measurable _ _).trans hAU, hUo, hU⟩\nend\n\n/-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets\ncontaining it. -/\nlemma _root_.set.measure_eq_infi_is_open (A : set α) (μ : measure α) [outer_regular μ] :\n  μ A = (⨅ (U : set α) (h : A ⊆ U) (h2 : is_open U), μ U) :=\nbegin\n  refine le_antisymm (le_infi₂ $ λ s hs, le_infi $ λ h2s, μ.mono hs) _,\n  refine le_of_forall_lt' (λ r hr, _),\n  simpa only [infi_lt_iff, exists_prop] using A.exists_is_open_lt_of_lt r hr\nend\n\nlemma _root_.set.exists_is_open_lt_add [outer_regular μ] (A : set α) (hA : μ A ≠ ∞)\n  {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ U ⊇ A, is_open U ∧ μ U < μ A + ε :=\nA.exists_is_open_lt_of_lt _ (ennreal.lt_add_right hA hε)\n\nlemma _root_.set.exists_is_open_le_add (A : set α) (μ : measure α) [outer_regular μ]\n  {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ U ⊇ A, is_open U ∧ μ U ≤ μ A + ε :=\nbegin\n  rcases eq_or_ne (μ A) ∞ with H|H,\n  { exact ⟨univ, subset_univ _, is_open_univ, by simp only [H, _root_.top_add, le_top]⟩ },\n  { rcases A.exists_is_open_lt_add H hε with ⟨U, AU, U_open, hU⟩,\n    exact ⟨U, AU, U_open, hU.le⟩ }\nend\n\nlemma _root_.measurable_set.exists_is_open_diff_lt [outer_regular μ] {A : set α}\n  (hA : measurable_set A) (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ U ⊇ A, is_open U ∧ μ U < ∞ ∧ μ (U \\ A) < ε :=\nbegin\n  rcases A.exists_is_open_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩,\n  use [U, hAU, hUo, hU.trans_le le_top],\n  exact measure_diff_lt_of_lt_add hA hAU hA' hU,\nend\n\nprotected lemma map [opens_measurable_space α] [measurable_space β] [topological_space β]\n  [borel_space β] (f : α ≃ₜ β) (μ : measure α) [outer_regular μ] :\n  (measure.map f μ).outer_regular :=\nbegin\n  refine ⟨λ A hA r hr, _⟩,\n  rw [map_apply f.measurable hA, ← f.image_symm] at hr,\n  rcases set.exists_is_open_lt_of_lt _ r hr with ⟨U, hAU, hUo, hU⟩,\n  have : is_open (f.symm ⁻¹' U), from hUo.preimage f.symm.continuous,\n  refine ⟨f.symm ⁻¹' U, image_subset_iff.1 hAU, this, _⟩,\n  rwa [map_apply f.measurable this.measurable_set, f.preimage_symm, f.preimage_image],\nend\n\nprotected lemma smul (μ : measure α) [outer_regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) :\n  (x • μ).outer_regular :=\nbegin\n  rcases eq_or_ne x 0 with rfl|h0,\n  { rw zero_smul, exact outer_regular.zero },\n  { refine ⟨λ A hA r hr, _⟩,\n    rw [smul_apply, A.measure_eq_infi_is_open, smul_eq_mul] at hr,\n    simpa only [ennreal.mul_infi_of_ne h0 hx, gt_iff_lt, infi_lt_iff, exists_prop] using hr }\nend\n\nend outer_regular\n\n/-- If a measure `μ` admits finite spanning open sets such that the restriction of `μ` to each set\nis outer regular, then the original measure is outer regular as well. -/\nprotected lemma finite_spanning_sets_in.outer_regular [opens_measurable_space α] {μ : measure α}\n  (s : μ.finite_spanning_sets_in {U | is_open U ∧ outer_regular (μ.restrict U)}) :\n  outer_regular μ :=\nbegin\n  refine ⟨λ A hA r hr, _⟩,\n  have hm : ∀ n, measurable_set (s.set n), from λ n, (s.set_mem n).1.measurable_set,\n  haveI : ∀ n, outer_regular (μ.restrict (s.set n)) := λ n, (s.set_mem n).2,\n  -- Note that `A = ⋃ n, A ∩ disjointed s n`. We replace `A` with this sequence.\n  obtain ⟨A, hAm, hAs, hAd, rfl⟩ : ∃ A' : ℕ → set α, (∀ n, measurable_set (A' n)) ∧\n    (∀ n, A' n ⊆ s.set n) ∧ pairwise (disjoint on A') ∧ A = ⋃ n, A' n,\n  { refine ⟨λ n, A ∩ disjointed s.set n, λ n, hA.inter (measurable_set.disjointed hm _),\n      λ n, (inter_subset_right _ _).trans (disjointed_subset _ _),\n      (disjoint_disjointed s.set).mono (λ k l hkl, hkl.mono inf_le_right inf_le_right), _⟩,\n    rw [← inter_Union, Union_disjointed, s.spanning, inter_univ] },\n  rcases ennreal.exists_pos_sum_of_countable' (tsub_pos_iff_lt.2 hr).ne' ℕ with ⟨δ, δ0, hδε⟩,\n  rw [lt_tsub_iff_right, add_comm] at hδε,\n  have : ∀ n, ∃ U ⊇ A n, is_open U ∧ μ U < μ (A n) + δ n,\n  { intro n,\n    have H₁ : ∀ t, μ.restrict (s.set n) t = μ (t ∩ s.set n), from λ t, restrict_apply' (hm n),\n    have Ht : μ.restrict (s.set n) (A n) ≠ ⊤,\n    { rw H₁, exact ((measure_mono $ inter_subset_right _ _).trans_lt (s.finite n)).ne },\n    rcases (A n).exists_is_open_lt_add Ht (δ0 n).ne' with ⟨U, hAU, hUo, hU⟩,\n    rw [H₁, H₁, inter_eq_self_of_subset_left (hAs _)] at hU,\n    exact ⟨U ∩ s.set n, subset_inter hAU (hAs _), hUo.inter (s.set_mem n).1, hU⟩ },\n  choose U hAU hUo hU,\n  refine ⟨⋃ n, U n, Union_mono hAU, is_open_Union hUo, _⟩,\n  calc μ (⋃ n, U n) ≤ ∑' n, μ (U n)             : measure_Union_le _\n                ... ≤ ∑' n, (μ (A n) + δ n)     : ennreal.tsum_le_tsum (λ n, (hU n).le)\n                ... = ∑' n, μ (A n) + ∑' n, δ n : ennreal.tsum_add\n                ... = μ (⋃ n, A n) + ∑' n, δ n  : congr_arg2 (+) (measure_Union hAd hAm).symm rfl\n                ... < r                         : hδε\nend\n\nnamespace inner_regular\n\nvariables {p q : set α → Prop} {U s : set α} {ε r : ℝ≥0∞}\n\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. -/\nlemma measurable_set_of_open [outer_regular μ]\n  (H : inner_regular μ p is_open) (h0 : p ∅) (hd : ∀ ⦃s U⦄, p s → is_open U → p (s \\ U)) :\n  inner_regular μ p (λ s, measurable_set s ∧ μ s ≠ ∞) :=\nbegin\n  rintros s ⟨hs, hμs⟩ r hr,\n  obtain ⟨ε, hε, hεs, rfl⟩ : ∃ ε ≠ 0, ε + ε ≤ μ s ∧ r = μ s - (ε + ε),\n  { use (μ s - r) / 2, simp [*, hr.le, ennreal.add_halves, ennreal.sub_sub_cancel, le_add_right] },\n  rcases hs.exists_is_open_diff_lt hμs hε with ⟨U, hsU, hUo, hUt, hμU⟩,\n  rcases (U \\ s).exists_is_open_lt_of_lt _ hμU with ⟨U', hsU', hU'o, hμU'⟩,\n  replace hsU' := diff_subset_comm.1 hsU',\n  rcases H.exists_subset_lt_add h0 hUo hUt.ne hε with ⟨K, hKU, hKc, hKr⟩,\n  refine ⟨K \\ U', λ x hx, hsU' ⟨hKU hx.1, hx.2⟩, hd hKc hU'o, ennreal.sub_lt_of_lt_add hεs _⟩,\n  calc μ s ≤ μ U                   : μ.mono hsU\n       ... < μ K + ε               : hKr\n       ... ≤ μ (K \\ U') + μ U' + ε :\n    add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _\n       ... ≤ μ (K \\ U') + ε + ε    : by { mono*, exacts [hμU'.le, le_rfl] }\n       ... = μ (K \\ U') + (ε + ε)  : add_assoc _ _ _\nend\n\nopen finset\n\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. -/\nlemma weakly_regular_of_finite [borel_space α] (μ : measure α) [is_finite_measure μ]\n  (H : inner_regular μ is_closed is_open) : weakly_regular μ :=\nbegin\n  have hfin : ∀ {s}, μ s ≠ ⊤ := measure_ne_top μ,\n  suffices : ∀ s, measurable_set s → ∀ ε ≠ 0,\n    ∃ (F ⊆ s) (U ⊇ s), is_closed F ∧ is_open U ∧ μ s ≤ μ F + ε ∧ μ U ≤ μ s + ε,\n  { refine { outer_regular := λ s hs r hr, _, inner_regular := H },\n    rcases exists_between hr with ⟨r', hsr', hr'r⟩,\n    rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with ⟨-, -, U, hsU, -, hUo, -, H⟩,\n    refine ⟨U, hsU, hUo, _⟩,\n    rw [add_tsub_cancel_of_le hsr'.le] at H, exact H.trans_lt hr'r },\n  refine measurable_set.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  { intros U hU ε hε,\n    rcases H.exists_subset_lt_add is_closed_empty hU hfin hε with ⟨F, hsF, hFc, hF⟩,\n    exact ⟨F, hsF, U, subset.rfl, hFc, hU, hF.le, le_self_add⟩ },\n  -- check for complements\n  { rintros s hs H ε hε,\n    rcases H ε hε with ⟨F, hFs, U, hsU, hFc, hUo, hF, hU⟩,\n    refine ⟨Uᶜ, compl_subset_compl.2 hsU, Fᶜ, compl_subset_compl.2 hFs,\n      hUo.is_closed_compl, hFc.is_open_compl, _⟩,\n    simp only [measure_compl_le_add_iff, *, hUo.measurable_set, hFc.measurable_set, true_and] },\n  -- check for disjoint unions\n  { intros s hsd hsm H ε ε0, have ε0' : ε / 2 ≠ 0, from (ennreal.half_pos ε0).ne',\n    rcases ennreal.exists_pos_sum_of_countable' ε0' ℕ with ⟨δ, δ0, hδε⟩,\n    choose F hFs U hsU hFc hUo hF hU using λ n, H n (δ n) (δ0 n).ne',\n    -- the approximating closed set is constructed by considering finitely many sets `s i`, which\n    -- cover all the measure up to `ε/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 (λ t, ∑ k in t, μ (s k) + ε / 2) at_top (𝓝 $ μ (⋃ n, s n) + ε / 2),\n    { rw measure_Union hsd hsm, exact tendsto.add ennreal.summable.has_sum tendsto_const_nhds },\n    rcases (this.eventually $ lt_mem_nhds $ ennreal.lt_add_right hfin ε0').exists with ⟨t, ht⟩,\n    -- the approximating open set is constructed by taking for each `s n` an approximating open set\n    -- `U n` with measure at most `μ (s n) + δ n` for a summable `δ`, and taking the union of these.\n    refine ⟨⋃ k ∈ t, F k, Union_mono $ λ k, Union_subset $ λ _, hFs _,\n      ⋃ n, U n, Union_mono hsU, is_closed_bUnion t.finite_to_set $ λ k _, hFc k,\n      is_open_Union hUo, ht.le.trans _, _⟩,\n    { calc ∑ k in t, μ (s k) + ε / 2 ≤ ∑ k in t, μ (F k) + ∑ k in t, δ k + ε / 2 :\n        by { rw ← sum_add_distrib, exact add_le_add_right (sum_le_sum $ λ k hk, hF k) _ }\n      ... ≤ ∑ k in t, μ (F k) + ε / 2 + ε / 2 :\n        add_le_add_right (add_le_add_left ((ennreal.sum_le_tsum _).trans hδε.le) _) _\n      ... = μ (⋃ k ∈ t, F k) + ε : _,\n      rw [measure_bUnion_finset, add_assoc, ennreal.add_halves],\n      exacts [λ k _ n _ hkn, (hsd hkn).mono (hFs k) (hFs n), λ k hk, (hFc k).measurable_set] },\n    { calc μ (⋃ n, U n) ≤ ∑' n, μ (U n) : measure_Union_le _\n      ... ≤ ∑' n, (μ (s n) + δ n) : ennreal.tsum_le_tsum hU\n      ... = μ (⋃ n, s n) + ∑' n, δ n : by rw [measure_Union hsd hsm, ennreal.tsum_add]\n      ... ≤ μ (⋃ n, s n) + ε : add_le_add_left (hδε.le.trans ennreal.half_le_self) _ } }\nend\n\n/-- In a metric space (or even a pseudo emetric space), an open set can be approximated from inside\nby closed sets. -/\nlemma of_pseudo_emetric_space {X : Type*} [pseudo_emetric_space X]\n  [measurable_space X] (μ : measure X) :\n  inner_regular μ is_closed is_open :=\nbegin\n  intros U hU r hr,\n  rcases hU.exists_Union_is_closed with ⟨F, F_closed, -, rfl, F_mono⟩,\n  rw measure_Union_eq_supr F_mono.directed_le at hr,\n  rcases lt_supr_iff.1 hr with ⟨n, hn⟩,\n  exact ⟨F n, subset_Union _ _, F_closed n, hn⟩\nend\n\n/-- In a `σ`-compact space, any closed set can be approximated by a compact subset. -/\nlemma is_compact_is_closed {X : Type*} [topological_space X]\n  [sigma_compact_space X] [measurable_space X] (μ : measure X) :\n  inner_regular μ is_compact is_closed :=\nbegin\n  intros F hF r hr,\n  set B : ℕ → set X := compact_covering X,\n  have hBc : ∀ n, is_compact (F ∩ B n), from λ n, (is_compact_compact_covering X n).inter_left hF,\n  have hBU : (⋃ n, F ∩ B n) = F, by rw [← inter_Union, Union_compact_covering, set.inter_univ],\n  have : μ F = ⨆ n, μ (F ∩ B n),\n  { rw [← measure_Union_eq_supr, hBU],\n    exact monotone.directed_le\n      (λ m n h, inter_subset_inter_right _ (compact_covering_subset _ h)) },\n  rw this at hr, rcases lt_supr_iff.1 hr with ⟨n, hn⟩,\n  exact ⟨_, inter_subset_left _ _, hBc n, hn⟩\nend\n\nend inner_regular\n\nnamespace regular\n\ninstance zero : regular (0 : measure α) :=\n⟨λ U hU r hr, ⟨∅, empty_subset _, is_compact_empty, hr⟩⟩\n\n/-- If `μ` is a regular measure, then any open set can be approximated by a compact subset. -/\nlemma _root_.is_open.exists_lt_is_compact [regular μ] ⦃U : set α⦄ (hU : is_open U)\n  {r : ℝ≥0∞} (hr : r < μ U) :\n  ∃ K ⊆ U, is_compact K ∧ r < μ K :=\nregular.inner_regular hU r hr\n\n/-- The measure of an open set is the supremum of the measures of compact sets it contains. -/\nlemma _root_.is_open.measure_eq_supr_is_compact ⦃U : set α⦄ (hU : is_open U)\n  (μ : measure α) [regular μ] :\n  μ U = (⨆ (K : set α) (h : K ⊆ U) (h2 : is_compact K), μ K) :=\nregular.inner_regular.measure_eq_supr hU\n\nlemma exists_compact_not_null [regular μ] : (∃ K, is_compact K ∧ μ K ≠ 0) ↔ μ ≠ 0 :=\nby simp_rw [ne.def, ← measure_univ_eq_zero, is_open_univ.measure_eq_supr_is_compact,\n    ennreal.supr_eq_zero, not_forall, exists_prop, subset_univ, true_and]\n\n/-- If `μ` 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`. -/\nlemma inner_regular_measurable [regular μ] :\n  inner_regular μ is_compact (λ s, measurable_set s ∧ μ s ≠ ∞) :=\nregular.inner_regular.measurable_set_of_open is_compact_empty (λ _ _, is_compact.diff)\n\n/-- If `μ` 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`. -/\nlemma _root_.measurable_set.exists_is_compact_lt_add\n  [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ K ⊆ A, is_compact K ∧ μ A < μ K + ε :=\nregular.inner_regular_measurable.exists_subset_lt_add is_compact_empty ⟨hA, h'A⟩ h'A hε\n\n/-- If `μ` 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`. -/\nlemma _root_.measurable_set.exists_is_compact_diff_lt [opens_measurable_space α] [t2_space α]\n  [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ K ⊆ A, is_compact K ∧ μ (A \\ K) < ε :=\nbegin\n  rcases hA.exists_is_compact_lt_add h'A hε with ⟨K, hKA, hKc, hK⟩,\n  exact ⟨K, hKA, hKc, measure_diff_lt_of_lt_add hKc.measurable_set hKA\n    (ne_top_of_le_ne_top h'A $ measure_mono hKA) hK⟩\nend\n\n/-- If `μ` 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`. -/\nlemma _root_.measurable_set.exists_lt_is_compact_of_ne_top [regular μ] ⦃A : set α⦄\n  (hA : measurable_set A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) :\n  ∃ K ⊆ A, is_compact K ∧ r < μ K :=\nregular.inner_regular_measurable ⟨hA, h'A⟩ _ hr\n\n/-- Given a regular measure, any measurable set of finite mass can be approximated from\ninside by compact sets. -/\nlemma _root_.measurable_set.measure_eq_supr_is_compact_of_ne_top [regular μ]\n  ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) :\n  μ A = (⨆ (K ⊆ A) (h : is_compact K), μ K) :=\nregular.inner_regular_measurable.measure_eq_supr ⟨hA, h'A⟩\n\nprotected lemma map [opens_measurable_space α] [measurable_space β] [topological_space β]\n  [t2_space β] [borel_space β] [regular μ] (f : α ≃ₜ β) :\n  (measure.map f μ).regular :=\nbegin\n  haveI := outer_regular.map f μ,\n  haveI := is_finite_measure_on_compacts.map μ f,\n  exact ⟨regular.inner_regular.map f.to_equiv f.measurable.ae_measurable\n    (λ U hU, hU.preimage f.continuous) (λ K hK, hK.image f.continuous)\n    (λ K hK, hK.measurable_set) (λ U hU, hU.measurable_set)⟩\nend\n\nprotected lemma smul [regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) :\n  (x • μ).regular :=\nbegin\n  haveI := outer_regular.smul μ hx,\n  haveI := is_finite_measure_on_compacts.smul μ hx,\n  exact ⟨regular.inner_regular.smul x⟩\nend\n\n/-- A regular measure in a σ-compact space is σ-finite. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance sigma_finite [sigma_compact_space α] [regular μ] : sigma_finite μ :=\n⟨⟨{ set := compact_covering α,\n  set_mem := λ n, trivial,\n  finite := λ n, (is_compact_compact_covering α n).measure_lt_top,\n  spanning := Union_compact_covering α }⟩⟩\n\nend regular\n\nnamespace weakly_regular\n\n/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/\nlemma _root_.is_open.exists_lt_is_closed [weakly_regular μ] ⦃U : set α⦄ (hU : is_open U)\n  {r : ℝ≥0∞} (hr : r < μ U) :\n  ∃ F ⊆ U, is_closed F ∧ r < μ F :=\nweakly_regular.inner_regular hU r hr\n\n/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/\nlemma _root_.is_open.measure_eq_supr_is_closed ⦃U : set α⦄ (hU : is_open U)\n  (μ : measure α) [weakly_regular μ] :\n  μ U = (⨆ (F ⊆ U) (h : is_closed F), μ F) :=\nweakly_regular.inner_regular.measure_eq_supr hU\n\nlemma inner_regular_measurable [weakly_regular μ] :\n  inner_regular μ is_closed (λ s, measurable_set s ∧ μ s ≠ ∞) :=\nweakly_regular.inner_regular.measurable_set_of_open is_closed_empty\n  (λ _ _ h₁ h₂, h₁.inter h₂.is_closed_compl)\n\n/-- If `s` is a measurable set, a weakly regular measure `μ` is finite on `s`, and `ε` is a positive\nnumber, then there exist a closed set `K ⊆ s` such that `μ s < μ K + ε`. -/\nlemma _root_.measurable_set.exists_is_closed_lt_add [weakly_regular μ] {s : set α}\n  (hs : measurable_set s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ K ⊆ s, is_closed K ∧ μ s < μ K + ε :=\ninner_regular_measurable.exists_subset_lt_add is_closed_empty ⟨hs, hμs⟩ hμs hε\n\nlemma _root_.measurable_set.exists_is_closed_diff_lt [opens_measurable_space α]\n  [weakly_regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :\n  ∃ F ⊆ A, is_closed F ∧ μ (A \\ F) < ε :=\nbegin\n  rcases hA.exists_is_closed_lt_add h'A hε with ⟨F, hFA, hFc, hF⟩,\n  exact ⟨F, hFA, hFc, measure_diff_lt_of_lt_add hFc.measurable_set hFA\n    (ne_top_of_le_ne_top h'A $ measure_mono hFA) hF⟩\nend\n\n/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from\ninside by closed sets. -/\nlemma _root_.measurable_set.exists_lt_is_closed_of_ne_top [weakly_regular μ]\n  ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) :\n  ∃ K ⊆ A, is_closed K ∧ r < μ K :=\ninner_regular_measurable ⟨hA, h'A⟩ _ hr\n\n/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from\ninside by closed sets. -/\nlemma _root_.measurable_set.measure_eq_supr_is_closed_of_ne_top [weakly_regular μ] ⦃A : set α⦄\n  (hA : measurable_set A) (h'A : μ A ≠ ∞) :\n  μ A = (⨆ (K ⊆ A) (h : is_closed K), μ K) :=\ninner_regular_measurable.measure_eq_supr ⟨hA, h'A⟩\n\n/-- The restriction of a weakly regular measure to a measurable set of finite measure is\nweakly regular. -/\nlemma restrict_of_measurable_set [borel_space α] [weakly_regular μ] (A : set α)\n  (hA : measurable_set A) (h'A : μ A ≠ ∞) : weakly_regular (μ.restrict A) :=\nbegin\n  haveI : fact (μ A < ∞) := ⟨h'A.lt_top⟩,\n  refine inner_regular.weakly_regular_of_finite _ (λ V V_open, _),\n  simp only [restrict_apply' hA], intros r hr,\n  have : μ (V ∩ A) ≠ ∞, from ne_top_of_le_ne_top h'A (measure_mono $ inter_subset_right _ _),\n  rcases (V_open.measurable_set.inter hA).exists_lt_is_closed_of_ne_top this hr\n    with ⟨F, hFVA, hFc, hF⟩,\n  refine ⟨F, hFVA.trans (inter_subset_left _ _), hFc, _⟩,\n  rwa inter_eq_self_of_subset_left (hFVA.trans $ inter_subset_right _ _)\nend\n\n/-- Any finite measure on a metric space (or even a pseudo emetric space) is weakly regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance of_pseudo_emetric_space_of_is_finite_measure {X : Type*} [pseudo_emetric_space X]\n  [measurable_space X] [borel_space X] (μ : measure X) [is_finite_measure μ] :\n  weakly_regular μ :=\n(inner_regular.of_pseudo_emetric_space μ).weakly_regular_of_finite μ\n\n/-- Any locally finite measure on a second countable metric space (or even a pseudo emetric space)\nis weakly regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance of_pseudo_emetric_second_countable_of_locally_finite {X : Type*} [pseudo_emetric_space X]\n  [topological_space.second_countable_topology X] [measurable_space X] [borel_space X]\n  (μ : measure X) [is_locally_finite_measure μ] :\n  weakly_regular μ :=\nbegin\n  haveI : outer_regular μ,\n  { refine (μ.finite_spanning_sets_in_open'.mono' $ λ U hU, _).outer_regular,\n    haveI : fact (μ U < ∞), from ⟨hU.2⟩,\n    exact ⟨hU.1, infer_instance⟩ },\n  exact ⟨inner_regular.of_pseudo_emetric_space μ⟩\nend\n\nend weakly_regular\n\nlocal attribute [instance] emetric.second_countable_of_sigma_compact\n\n/-- Any locally finite measure on a `σ`-compact (e)metric space is regular. -/\n@[priority 100] -- see Note [lower instance priority]\ninstance regular.of_sigma_compact_space_of_is_locally_finite_measure {X : Type*}\n  [emetric_space X] [sigma_compact_space X] [measurable_space X] [borel_space X] (μ : measure X)\n  [is_locally_finite_measure μ] : regular μ :=\n{ lt_top_of_is_compact := λ K hK, hK.measure_lt_top,\n  inner_regular := (inner_regular.is_compact_is_closed μ).trans\n    (inner_regular.of_pseudo_emetric_space μ) }\n\nend measure\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/measure/regular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7541962666768595}}
{"text": "open classical\nvariable A : Prop\nexample : ¬ (¬ ( A ∨ ¬ A)) :=\n(assume h1 :  ¬ (A ∨ ¬ A),\n    have h2 : ¬ A, from \n        assume h3 : A,\n        have h4 : A ∨ ¬ A, from or.inl h3,\n        show false, from h1 h4,\n    have h5 : A ∨ ¬ A, from or.inr h2,\n    show false, from h1 h5)", "meta": {"author": "ucmani", "repo": "leanexamples", "sha": "387daef46eaf61bd4a08db076f60ac237daff559", "save_path": "github-repos/lean/ucmani-leanexamples", "path": "github-repos/lean/ucmani-leanexamples/leanexamples-387daef46eaf61bd4a08db076f60ac237daff559/notnotA.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.96036116089903, "lm_q2_score": 0.7853085708384735, "lm_q1q2_score": 0.7541798507543945}}
{"text": "import standard\n\nmeta def blast : tactic unit :=\nusing_smt $ return ()\n\nstructure Category :=\n  (Obj : Type)\n  (Hom : Obj -> Obj -> Type)\n  (identity : Π A : Obj, Hom A A)\n  (compose  : Π ⦃A B C : Obj⦄, Hom A B → Hom B C → Hom A C)\n\n  (left_identity  : Π ⦃A B : Obj⦄ (f : Hom A B), compose (identity _) f = f)\n  (right_identity : Π ⦃A B : Obj⦄ (f : Hom A B), compose f (identity _) = f)\n  (associativity  : Π ⦃A B C D : Obj⦄ (f : Hom A B) (g : Hom B C) (h : Hom C D),\n    compose (compose f g) h = compose f (compose g h))\n\nattribute [class] Category\n\nstructure Functor (C : Category) (D : Category) :=\n  (onObjects   : C^.Obj → D^.Obj)\n  (onMorphisms : Π ⦃A B : C^.Obj⦄,\n                C^.Hom A B → D^.Hom (onObjects A) (onObjects B))\n  (identities : Π (A : C^.Obj),\n    onMorphisms (C^.identity A) = D^.identity (onObjects A))\n  (functoriality : Π ⦃X Y Z : C^.Obj⦄ (f : C^.Hom X Y) (g : C^.Hom Y Z),\n    onMorphisms (C^.compose f g) = D^.compose (onMorphisms f) (onMorphisms g))\n\nattribute [class] Functor\n\ninstance Functor_to_onObjects { C D : Category }: has_coe_to_fun (Functor C D) :=\n{ F   := λ f, C^.Obj -> D^.Obj,\n  coe := Functor.onObjects }\n\nnamespace Functor\n  infix `<$>`:50 := λ {C : Category} {D : Category}\n                      (F : Functor C D) {A B : C^.Obj} (f : C^.Hom A B),\n                      onMorphisms F f\nend Functor\n\nstructure NaturalTransformation { C D : Category } ( F G : Functor C D ) :=\n  (components: Π A : C^.Obj, D^.Hom (F A) (G A))\n  (naturality: Π { A B : C^.Obj }, Π f : C^.Hom A B, D^.compose (F <$> f) (components B) = D^.compose (components A) (G <$> f))\n\ninstance NaturalTransformation_to_components { C D : Category } { F G : Functor C D } : has_coe_to_fun (NaturalTransformation F G) :=\n{ F   := λ f, Π A : C^.Obj, D^.Hom (F A) (G A),\n  coe := NaturalTransformation.components }\n\n-- We'll want to be able to prove that two natural transformations are equal if they are componentwise equal.\nlemma NaturalTransformations_componentwise_equal\n  { C D : Category } \n  { F G : Functor C D } \n  ( α β : NaturalTransformation F G )\n  ( w: Π X : C^.Obj, α X = β X ) : α = β :=\n  begin\n    induction α,\n    induction β,\n    -- Argh, how to complete this proof?\n    exact sorry\n  end\n\n\n", "meta": {"author": "semorrison", "repo": "proof", "sha": "5ee398aa239a379a431190edbb6022b1a0aa2c70", "save_path": "github-repos/lean/semorrison-proof", "path": "github-repos/lean/semorrison-proof/proof-5ee398aa239a379a431190edbb6022b1a0aa2c70/lean/natural-transformation-equality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582632076909, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7541167913387845}}
{"text": "/-\nM1F 2017-18 Sheet 1 Question 2 to 4 solutions.\nAuthor : Kevin Buzzard\nThis file should work with any version of lean -- whether you installed it yourself\nor are running the version on https://leanprover.github.io/live/latest/\n-/\n-- We probably need the \"law of the excluded middle\" for this question -- every\n-- proposition is either true or false! Don't even ask me to explain what the\n-- other options are, but Lean does not come with this axiom by default (blame\n-- the computer scientists) and mathematicians have to add it themselves.\n-- It's easy to add though. \"em\" for excluded middle.\n\naxiom em (X : Prop) : X ∨ ¬ X\n\n\nvariables P Q R S : Prop -- A \"Prop\" is a proposition, that is, a true/false statement.\n\n-- Sheet 1 Q2 is true.\n\ntheorem m1f_sheet01_q02_is_T (HQP : Q → P) (HnQnR : ¬ Q → ¬ R) : R → P :=\nbegin\nintro HR, -- hypothesis R\ncases em Q with HQ HnQ, -- Q is either true or false.\n  -- Q is true in this branch.\n  exact HQP HQ, -- HPQ HQ is a proof of P.\n\n  -- Q is false in this branch\n  -- HnQ is the hypothesis \"not Q\"\n  -- HnQnR is \"not Q implies not R\"\n  -- so HnQnR HnQ is a proof of \"not R\"\n      -- i.e. a proof of \"R implies false\"\n  -- but HR is a proof of R\n  -- and that's enough for a contradiction.\n  have HnR : ¬ R,\n  exact HnQnR HnQ,\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/0102/S0102.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7541062531674523}}
{"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, Leonardo de Moura, Jeremy Avigad, Mario Carneiro\n\nBasic operations on the natural numbers.\n-/\nimport logic.basic algebra.ordered_ring data.option.basic\n\nuniverses u v\n\nnamespace nat\nvariables {m n k : ℕ}\n\n-- Sometimes a bare `nat.add` or similar appears as a consequence of unfolding\n-- during pattern matching. These lemmas package them back up as typeclass\n-- mediated operations.\n@[simp] theorem add_def {a b : ℕ} : nat.add a b = a + b := rfl\n@[simp] theorem mul_def {a b : ℕ} : nat.mul a b = a * b := rfl\n\nattribute [simp] nat.add_sub_cancel nat.add_sub_cancel_left\nattribute [simp] nat.sub_self\n\ntheorem succ_inj' {n m : ℕ} : succ n = succ m ↔ n = m :=\n⟨succ_inj, congr_arg _⟩\n\ntheorem succ_le_succ_iff {m n : ℕ} : succ m ≤ succ n ↔ m ≤ n :=\n⟨le_of_succ_le_succ, succ_le_succ⟩\n\ntheorem lt_succ_iff {m n : ℕ} : m < succ n ↔ m ≤ n :=\nsucc_le_succ_iff\n\nlemma succ_le_iff {m n : ℕ} : succ m ≤ n ↔ m < n :=\n⟨lt_of_succ_le, succ_le_of_lt⟩\n\ntheorem pred_eq_of_eq_succ {m n : ℕ} (H : m = n.succ) : m.pred = n := by simp [H]\n\ntheorem pred_sub (n m : ℕ) : pred n - m = pred (n - m) :=\nby rw [← sub_one, nat.sub_sub, one_add]; refl\n\nlemma pred_eq_sub_one (n : ℕ) : pred n = n - 1 := rfl\n\nlemma one_le_of_lt {n m : ℕ} (h : n < m) : 1 ≤ m :=\nlt_of_le_of_lt (nat.zero_le _) h\n\nlemma le_pred_of_lt {n m : ℕ} (h : m < n) : m ≤ n - 1 :=\nnat.sub_le_sub_right h 1\n\n/-- This ensures that `simp` succeeds on `pred (n + 1) = n`. -/\n@[simp] lemma pred_one_add (n : ℕ) : pred (1 + n) = n :=\nby rw [add_comm, add_one, pred_succ]\n\ntheorem pos_iff_ne_zero : n > 0 ↔ n ≠ 0 :=\n⟨ne_of_gt, nat.pos_of_ne_zero⟩\n\ntheorem pos_iff_ne_zero' : 0 < n ↔ n ≠ 0 := pos_iff_ne_zero\n\nlemma one_lt_iff_ne_zero_and_ne_one : ∀ {n : ℕ}, 1 < n ↔ n ≠ 0 ∧ n ≠ 1\n| 0     := dec_trivial\n| 1     := dec_trivial\n| (n+2) := dec_trivial\n\ntheorem eq_of_lt_succ_of_not_lt {a b : ℕ} (h1 : a < b + 1) (h2 : ¬ a < b) : a = b :=\nhave h3 : a ≤ b, from le_of_lt_succ h1,\nor.elim (eq_or_lt_of_not_lt h2) (λ h, h) (λ h, absurd h (not_lt_of_ge h3))\n\nprotected theorem le_sub_add (n m : ℕ) : n ≤ n - m + m :=\nor.elim (le_total n m)\n  (assume : n ≤ m, begin rw [sub_eq_zero_of_le this, zero_add], exact this end)\n  (assume : m ≤ n, begin rw (nat.sub_add_cancel this) end)\n\ntheorem sub_add_eq_max (n m : ℕ) : n - m + m = max n m :=\neq_max (nat.le_sub_add _ _) (le_add_left _ _) $ λ k h₁ h₂,\nby rw ← nat.sub_add_cancel h₂; exact\nadd_le_add_right (nat.sub_le_sub_right h₁ _) _\n\ntheorem sub_add_min (n m : ℕ) : n - m + min n m = n :=\n(le_total n m).elim\n  (λ h, by rw [min_eq_left h, sub_eq_zero_of_le h, zero_add])\n  (λ h, by rw [min_eq_right h, nat.sub_add_cancel h])\n\nprotected theorem add_sub_cancel' {n m : ℕ} (h : n ≥ m) : m + (n - m) = n :=\nby rw [add_comm, nat.sub_add_cancel h]\n\nprotected theorem sub_eq_of_eq_add (h : k = m + n) : k - m = n :=\nbegin rw [h, nat.add_sub_cancel_left] end\n\nlemma sub_sub_sub_cancel_right {a b c : ℕ} (h₂ : c ≤ b) : (a - c) - (b - c) = a - b :=\nby rw [nat.sub_sub, ←nat.add_sub_assoc h₂, nat.add_sub_cancel_left]\n\ntheorem sub_min (n m : ℕ) : n - min n m = n - m :=\nnat.sub_eq_of_eq_add $ by rw [add_comm, sub_add_min]\n\nprotected theorem lt_of_sub_pos (h : n - m > 0) : m < n :=\nlt_of_not_ge\n  (assume : m ≥ n,\n    have n - m = 0, from sub_eq_zero_of_le this,\n    begin rw this at h, exact lt_irrefl _ h end)\n\nprotected theorem lt_of_sub_lt_sub_right : m - k < n - k → m < n :=\nlt_imp_lt_of_le_imp_le (λ h, nat.sub_le_sub_right h _)\n\nprotected theorem lt_of_sub_lt_sub_left : m - n < m - k → k < n :=\nlt_imp_lt_of_le_imp_le (nat.sub_le_sub_left _)\n\nprotected theorem sub_lt_self (h₁ : m > 0) (h₂ : n > 0) : m - n < m :=\ncalc\n  m - n = succ (pred m) - succ (pred n) : by rw [succ_pred_eq_of_pos h₁, succ_pred_eq_of_pos h₂]\n    ... = pred m - pred n               : by rw succ_sub_succ\n    ... ≤ pred m                        : sub_le _ _\n    ... < succ (pred m)                 : lt_succ_self _\n    ... = m                             : succ_pred_eq_of_pos h₁\n\nprotected theorem le_sub_right_of_add_le (h : m + k ≤ n) : m ≤ n - k :=\nby rw ← nat.add_sub_cancel m k; exact nat.sub_le_sub_right h k\n\nprotected theorem le_sub_left_of_add_le (h : k + m ≤ n) : m ≤ n - k :=\nnat.le_sub_right_of_add_le (by rwa add_comm at h)\n\nprotected theorem lt_sub_right_of_add_lt (h : m + k < n) : m < n - k :=\nlt_of_succ_le $ nat.le_sub_right_of_add_le $\nby rw succ_add; exact succ_le_of_lt h\n\nprotected theorem lt_sub_left_of_add_lt (h : k + m < n) : m < n - k :=\nnat.lt_sub_right_of_add_lt (by rwa add_comm at h)\n\nprotected theorem add_lt_of_lt_sub_right (h : m < n - k) : m + k < n :=\n@nat.lt_of_sub_lt_sub_right _ _ k (by rwa nat.add_sub_cancel)\n\nprotected theorem add_lt_of_lt_sub_left (h : m < n - k) : k + m < n :=\nby rw add_comm; exact nat.add_lt_of_lt_sub_right h\n\nprotected theorem le_add_of_sub_le_right : n - k ≤ m → n ≤ m + k :=\nle_imp_le_of_lt_imp_lt nat.lt_sub_right_of_add_lt\n\nprotected theorem le_add_of_sub_le_left : n - k ≤ m → n ≤ k + m :=\nle_imp_le_of_lt_imp_lt nat.lt_sub_left_of_add_lt\n\nprotected theorem lt_add_of_sub_lt_right : n - k < m → n < m + k :=\nlt_imp_lt_of_le_imp_le nat.le_sub_right_of_add_le\n\nprotected theorem lt_add_of_sub_lt_left : n - k < m → n < k + m :=\nlt_imp_lt_of_le_imp_le nat.le_sub_left_of_add_le\n\nprotected theorem sub_le_left_of_le_add : n ≤ k + m → n - k ≤ m :=\nle_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_left\n\nprotected theorem sub_le_right_of_le_add : n ≤ m + k → n - k ≤ m :=\nle_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_right\n\nprotected theorem sub_lt_left_iff_lt_add (H : n ≤ k) : k - n < m ↔ k < n + m :=\n⟨nat.lt_add_of_sub_lt_left,\n λ h₁,\n  have succ k ≤ n + m,   from succ_le_of_lt h₁,\n  have succ (k - n) ≤ m, from\n    calc succ (k - n) = succ k - n : by rw (succ_sub H)\n          ...     ≤ n + m - n      : nat.sub_le_sub_right this n\n          ...     = m              : by rw nat.add_sub_cancel_left,\n  lt_of_succ_le this⟩\n\nprotected theorem le_sub_left_iff_add_le (H : m ≤ k) : n ≤ k - m ↔ m + n ≤ k :=\nle_iff_le_iff_lt_iff_lt.2 (nat.sub_lt_left_iff_lt_add H)\n\nprotected theorem le_sub_right_iff_add_le (H : n ≤ k) : m ≤ k - n ↔ m + n ≤ k :=\nby rw [nat.le_sub_left_iff_add_le H, add_comm]\n\nprotected theorem lt_sub_left_iff_add_lt : n < k - m ↔ m + n < k :=\n⟨nat.add_lt_of_lt_sub_left, nat.lt_sub_left_of_add_lt⟩\n\nprotected theorem lt_sub_right_iff_add_lt : m < k - n ↔ m + n < k :=\nby rw [nat.lt_sub_left_iff_add_lt, add_comm]\n\ntheorem sub_le_left_iff_le_add : m - n ≤ k ↔ m ≤ n + k :=\nle_iff_le_iff_lt_iff_lt.2 nat.lt_sub_left_iff_add_lt\n\ntheorem sub_le_right_iff_le_add : m - k ≤ n ↔ m ≤ n + k :=\nby rw [nat.sub_le_left_iff_le_add, add_comm]\n\nprotected theorem sub_lt_right_iff_lt_add (H : k ≤ m) : m - k < n ↔ m < n + k :=\nby rw [nat.sub_lt_left_iff_lt_add H, add_comm]\n\nprotected theorem sub_le_sub_left_iff (H : k ≤ m) : m - n ≤ m - k ↔ k ≤ n :=\n⟨λ h,\n  have k + (m - k) - n ≤ m - k, by rwa nat.add_sub_cancel' H,\n  nat.le_of_add_le_add_right (nat.le_add_of_sub_le_left this),\nnat.sub_le_sub_left _⟩\n\nprotected theorem sub_lt_sub_right_iff (H : k ≤ m) : m - k < n - k ↔ m < n :=\nlt_iff_lt_of_le_iff_le (nat.sub_le_sub_right_iff _ _ _ H)\n\nprotected theorem sub_lt_sub_left_iff (H : n ≤ m) : m - n < m - k ↔ k < n :=\nlt_iff_lt_of_le_iff_le (nat.sub_le_sub_left_iff H)\n\nprotected theorem sub_le_iff : m - n ≤ k ↔ m - k ≤ n :=\nnat.sub_le_left_iff_le_add.trans nat.sub_le_right_iff_le_add.symm\n\nprotected lemma sub_le_self (n m : ℕ) : n - m ≤ n :=\nnat.sub_le_left_of_le_add (nat.le_add_left _ _)\n\nprotected theorem sub_lt_iff (h₁ : n ≤ m) (h₂ : k ≤ m) : m - n < k ↔ m - k < n :=\n(nat.sub_lt_left_iff_lt_add h₁).trans (nat.sub_lt_right_iff_lt_add h₂).symm\n\nlemma pred_le_iff {n m : ℕ} : pred n ≤ m ↔ n ≤ succ m :=\n@nat.sub_le_right_iff_le_add n m 1\n\nlemma lt_pred_iff {n m : ℕ} : n < pred m ↔ succ n < m :=\n@nat.lt_sub_right_iff_add_lt n 1 m\n\nprotected theorem mul_ne_zero {n m : ℕ} (n0 : n ≠ 0) (m0 : m ≠ 0) : n * m ≠ 0\n| nm := (eq_zero_of_mul_eq_zero nm).elim n0 m0\n\n@[simp] protected theorem mul_eq_zero {a b : ℕ} : a * b = 0 ↔ a = 0 ∨ b = 0 :=\niff.intro eq_zero_of_mul_eq_zero (by simp [or_imp_distrib] {contextual := tt})\n\n@[simp] protected theorem zero_eq_mul {a b : ℕ} : 0 = a * b ↔ a = 0 ∨ b = 0 :=\nby rw [eq_comm, nat.mul_eq_zero]\n\n@[elab_as_eliminator]\nprotected def strong_rec' {p : ℕ → Sort u} (H : ∀ n, (∀ m, m < n → p m) → p n) : ∀ (n : ℕ), p n\n| n := H n (λ m hm, strong_rec' m)\n\nattribute [simp] nat.div_self\n\nprotected lemma div_le_of_le_mul' {m n : ℕ} {k} (h : m ≤ k * n) : m / k ≤ n :=\n(eq_zero_or_pos k).elim\n  (λ k0, by rw [k0, nat.div_zero]; apply zero_le)\n  (λ k0, (decidable.mul_le_mul_left k0).1 $\n    calc k * (m / k)\n        ≤ m % k + k * (m / k) : le_add_left _ _\n    ... = m                   : mod_add_div _ _\n    ... ≤ k * n               : h)\n\nprotected lemma div_le_self' (m n : ℕ) : m / n ≤ m :=\n(eq_zero_or_pos n).elim\n  (λ n0, by rw [n0, nat.div_zero]; apply zero_le)\n  (λ n0, nat.div_le_of_le_mul' $ calc\n      m = 1 * m : (one_mul _).symm\n    ... ≤ n * m : mul_le_mul_right _ n0)\n\ntheorem le_div_iff_mul_le' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x ≤ y / k ↔ x * k ≤ y :=\nbegin\n  revert x, refine nat.strong_rec' _ y,\n  clear y, intros y IH x,\n  cases decidable.lt_or_le y k with h h,\n  { rw [div_eq_of_lt h],\n    cases x with x,\n    { simp [zero_mul, zero_le] },\n    { rw succ_mul,\n      exact iff_of_false (not_succ_le_zero _)\n        (not_le_of_lt $ lt_of_lt_of_le h (le_add_left _ _)) } },\n  { rw [div_eq_sub_div k0 h],\n    cases x with x,\n    { simp [zero_mul, zero_le] },\n    { rw [← add_one, nat.add_le_add_iff_le_right, succ_mul,\n        IH _ (sub_lt_of_pos_le _ _ k0 h), add_le_to_le_sub _ h] } }\nend\n\ntheorem div_mul_le_self' (m n : ℕ) : m / n * n ≤ m :=\n(nat.eq_zero_or_pos n).elim (λ n0, by simp [n0, zero_le]) $ λ n0,\n(le_div_iff_mul_le' n0).1 (le_refl _)\n\ntheorem div_lt_iff_lt_mul' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x / k < y ↔ x < y * k :=\nlt_iff_lt_of_le_iff_le $ le_div_iff_mul_le' k0\n\nprotected theorem div_le_div_right {n m : ℕ} (h : n ≤ m) {k : ℕ} : n / k ≤ m / k :=\n(nat.eq_zero_or_pos k).elim (λ k0, by simp [k0]) $ λ hk,\n(le_div_iff_mul_le' hk).2 $ le_trans (nat.div_mul_le_self' _ _) h\n\nprotected theorem eq_mul_of_div_eq_right {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) :\n  a = b * c :=\nby rw [← H2, nat.mul_div_cancel' H1]\n\nprotected theorem div_eq_iff_eq_mul_right {a b c : ℕ} (H : b > 0) (H' : b ∣ a) :\n  a / b = c ↔ a = b * c :=\n⟨nat.eq_mul_of_div_eq_right H', nat.div_eq_of_eq_mul_right H⟩\n\nprotected theorem div_eq_iff_eq_mul_left {a b c : ℕ} (H : b > 0) (H' : b ∣ a) :\n  a / b = c ↔ a = c * b :=\nby rw mul_comm; exact nat.div_eq_iff_eq_mul_right H H'\n\nprotected theorem eq_mul_of_div_eq_left {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) :\n  a = c * b :=\nby rw [mul_comm, nat.eq_mul_of_div_eq_right H1 H2]\n\nprotected theorem mul_div_cancel_left' {a b : ℕ} (Hd :  a ∣ b) : a * (b / a) = b :=\nby rw [mul_comm,nat.div_mul_cancel Hd]\n\nprotected theorem div_mod_unique {n k m d : ℕ} (h : 0 < k) :\n  n / k = d ∧ n % k = m ↔ m + k * d = n ∧ m < k :=\n⟨λ ⟨e₁, e₂⟩, e₁ ▸ e₂ ▸ ⟨mod_add_div _ _, mod_lt _ h⟩,\n λ ⟨h₁, h₂⟩, h₁ ▸ by rw [add_mul_div_left _ _ h, add_mul_mod_self_left];\n   simp [div_eq_of_lt, mod_eq_of_lt, h₂]⟩\n\nlemma two_mul_odd_div_two {n : ℕ} (hn : n % 2 = 1) : 2 * (n / 2) = n - 1 :=\nby conv {to_rhs, rw [← nat.mod_add_div n 2, hn, nat.add_sub_cancel_left]}\n\nlemma div_dvd_of_dvd {a b : ℕ} (h : b ∣ a) : (a / b) ∣ a :=\n⟨b, (nat.div_mul_cancel h).symm⟩\n\nprotected lemma div_pos {a b : ℕ} (hba : b ≤ a) (hb : 0 < b) : 0 < a / b :=\nnat.pos_of_ne_zero (λ h, lt_irrefl a\n  (calc a = a % b : by simpa [h] using (mod_add_div a b).symm\n      ... < b : nat.mod_lt a hb\n      ... ≤ a : hba))\n\nprotected theorem mul_right_inj {a b c : ℕ} (ha : a > 0) : b * a = c * a ↔ b = c :=\n⟨nat.eq_of_mul_eq_mul_right ha, λ e, e ▸ rfl⟩\n\nprotected theorem mul_left_inj {a b c : ℕ} (ha : a > 0) : a * b = a * c ↔ b = c :=\n⟨nat.eq_of_mul_eq_mul_left ha, λ e, e ▸ rfl⟩\n\nprotected lemma div_div_self : ∀ {a b : ℕ}, b ∣ a → 0 < a → a / (a / b) = b\n| a     0     h₁ h₂ := by rw eq_zero_of_zero_dvd h₁; refl\n| 0     b     h₁ h₂ := absurd h₂ dec_trivial\n| (a+1) (b+1) h₁ h₂ :=\n(nat.mul_right_inj (nat.div_pos (le_of_dvd (succ_pos a) h₁) (succ_pos b))).1 $\n  by rw [nat.div_mul_cancel (div_dvd_of_dvd h₁), nat.mul_div_cancel' h₁]\n\nprotected lemma div_lt_of_lt_mul {m n k : ℕ} (h : m < n * k) : m / n < k :=\nlt_of_mul_lt_mul_left\n  (calc n * (m / n) ≤ m % n + n * (m / n) : nat.le_add_left _ _\n    ... = m : mod_add_div _ _\n    ... < n * k : h)\n  (nat.zero_le n)\n\nprotected lemma div_eq_zero_iff {a b : ℕ} (hb : 0 < b) : a / b = 0 ↔ a < b :=\n⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb,\n  λ h, by rw [← nat.mul_left_inj hb, ← @add_left_cancel_iff _ _ (a % b), mod_add_div,\n    mod_eq_of_lt h, mul_zero, add_zero]⟩\n\nlemma mod_mul_right_div_self (a b c : ℕ) : a % (b * c) / b = (a / b) % c :=\nif hb : b = 0 then by simp [hb] else if hc : c = 0 then by simp [hc]\nelse by conv {to_rhs, rw ← mod_add_div a (b * c)};\nrw [mul_assoc, nat.add_mul_div_left _ _ (nat.pos_of_ne_zero hb), add_mul_mod_self_left,\n  mod_eq_of_lt (nat.div_lt_of_lt_mul (mod_lt _ (mul_pos (nat.pos_of_ne_zero hb) (nat.pos_of_ne_zero hc))))]\n\nlemma mod_mul_left_div_self (a b c : ℕ) : a % (c * b) / b = (a / b) % c :=\nby rw [mul_comm c, mod_mul_right_div_self]\n\n@[simp] protected theorem dvd_one {n : ℕ} : n ∣ 1 ↔ n = 1 :=\n⟨eq_one_of_dvd_one, λ e, e.symm ▸ dvd_refl _⟩\n\nprotected theorem dvd_add_left {k m n : ℕ} (h : k ∣ n) : k ∣ m + n ↔ k ∣ m :=\n(nat.dvd_add_iff_left h).symm\n\nprotected theorem dvd_add_right {k m n : ℕ} (h : k ∣ m) : k ∣ m + n ↔ k ∣ n :=\n(nat.dvd_add_iff_right h).symm\n\nprotected theorem mul_dvd_mul_iff_left {a b c : ℕ} (ha : a > 0) : a * b ∣ a * c ↔ b ∣ c :=\nexists_congr $ λ d, by rw [mul_assoc, nat.mul_left_inj ha]\n\nprotected theorem mul_dvd_mul_iff_right {a b c : ℕ} (hc : c > 0) : a * c ∣ b * c ↔ a ∣ b :=\nexists_congr $ λ d, by rw [mul_right_comm, nat.mul_right_inj hc]\n\n@[simp] theorem mod_mod (a n : ℕ) : (a % n) % n = a % n :=\n(eq_zero_or_pos n).elim\n  (λ n0, by simp [n0])\n  (λ npos, mod_eq_of_lt (mod_lt _ npos))\n\ntheorem add_pos_left {m : ℕ} (h : m > 0) (n : ℕ) : m + n > 0 :=\ncalc\n  m + n > 0 + n : nat.add_lt_add_right h n\n    ... = n     : nat.zero_add n\n    ... ≥ 0     : zero_le n\n\ntheorem add_pos_right (m : ℕ) {n : ℕ} (h : n > 0) : m + n > 0 :=\nbegin rw add_comm, exact add_pos_left h m end\n\ntheorem add_pos_iff_pos_or_pos (m n : ℕ) : m + n > 0 ↔ m > 0 ∨ n > 0 :=\niff.intro\n  begin\n    intro h,\n    cases m with m,\n    {simp [zero_add] at h, exact or.inr h},\n    exact or.inl (succ_pos _)\n  end\n  begin\n    intro h, cases h with mpos npos,\n    { apply add_pos_left mpos },\n    apply add_pos_right _ npos\n  end\n\nlemma add_eq_one_iff : ∀ {a b : ℕ}, a + b = 1 ↔ (a = 0 ∧ b = 1) ∨ (a = 1 ∧ b = 0)\n| 0     0     := dec_trivial\n| 0     1     := dec_trivial\n| 1     0     := dec_trivial\n| 1     1     := dec_trivial\n| (a+2) _     := by rw add_right_comm; exact dec_trivial\n| _     (b+2) := by rw [← add_assoc]; simp only [nat.succ_inj', nat.succ_ne_zero]; simp\n\nlemma mul_eq_one_iff : ∀ {a b : ℕ}, a * b = 1 ↔ a = 1 ∧ b = 1\n| 0     0     := dec_trivial\n| 0     1     := dec_trivial\n| 1     0     := dec_trivial\n| (a+2) 0     := by simp\n| 0     (b+2) := by simp\n| (a+1) (b+1) := ⟨λ h, by simp only [add_mul, mul_add, mul_add, one_mul, mul_one,\n    (add_assoc _ _ _).symm, nat.succ_inj', add_eq_zero_iff] at h; simp [h.1.2, h.2],\n  by clear_aux_decl; finish⟩\n\nlemma mul_right_eq_self_iff {a b : ℕ} (ha : 0 < a): a * b = a ↔ b = 1 :=\nsuffices a * b = a * 1 ↔ b = 1, by rwa mul_one at this,\nnat.mul_left_inj ha\n\nlemma mul_left_eq_self_iff {a b : ℕ} (hb : 0 < b): a * b = b ↔ a = 1 :=\nby rw [mul_comm, nat.mul_right_eq_self_iff hb]\n\nlemma lt_succ_iff_lt_or_eq {n i : ℕ} : n < i.succ ↔ (n < i ∨ n = i) :=\nlt_succ_iff.trans le_iff_lt_or_eq\n\ntheorem le_zero_iff {i : ℕ} : i ≤ 0 ↔ i = 0 :=\n⟨nat.eq_zero_of_le_zero, assume h, h ▸ le_refl i⟩\n\ntheorem le_add_one_iff {i j : ℕ} : i ≤ j + 1 ↔ (i ≤ j ∨ i = j + 1) :=\n⟨assume 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  end,\n  or.rec (assume h, le_trans h $ nat.le_add_right _ _) le_of_eq⟩\n\ntheorem mul_self_inj {n m : ℕ} : n * n = m * m ↔ n = m :=\nle_antisymm_iff.trans (le_antisymm_iff.trans\n  (and_congr mul_self_le_mul_self_iff mul_self_le_mul_self_iff)).symm\n\ninstance decidable_ball_lt (n : nat) (P : Π k < n, Prop) :\n  ∀ [H : ∀ n h, decidable (P n h)], decidable (∀ n h, P n h) :=\nbegin\n  induction n with n IH; intro; resetI,\n  { exact is_true (λ n, dec_trivial) },\n  cases IH (λ k h, P k (lt_succ_of_lt h)) with h,\n  { refine is_false (mt _ h), intros hn k h, apply hn },\n  by_cases p : P n (lt_succ_self n),\n  { exact is_true (λ k h',\n     (lt_or_eq_of_le $ le_of_lt_succ h').elim (h _)\n       (λ e, match k, e, h' with _, rfl, h := p end)) },\n  { exact is_false (mt (λ hn, hn _ _) p) }\nend\n\ninstance decidable_forall_fin {n : ℕ} (P : fin n → Prop)\n  [H : decidable_pred P] : decidable (∀ i, P i) :=\ndecidable_of_iff (∀ k h, P ⟨k, h⟩) ⟨λ a ⟨k, h⟩, a k h, λ a k h, a ⟨k, h⟩⟩\n\ninstance decidable_ball_le (n : ℕ) (P : Π k ≤ n, Prop)\n  [H : ∀ n h, decidable (P n h)] : decidable (∀ n h, P n h) :=\ndecidable_of_iff (∀ k (h : k < succ n), P k (le_of_lt_succ h))\n⟨λ a k h, a k (lt_succ_of_le h), λ a k h, a k _⟩\n\ninstance decidable_lo_hi (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] : decidable (∀x, lo ≤ x → x < hi → P x) :=\ndecidable_of_iff (∀ x < hi - lo, P (lo + x))\n⟨λal x hl hh, by have := al (x - lo) (lt_of_not_ge $\n  (not_congr (nat.sub_le_sub_right_iff _ _ _ hl)).2 $ not_le_of_gt hh);\n  rwa [nat.add_sub_of_le hl] at this,\nλal x h, al _ (nat.le_add_right _ _) (nat.add_lt_of_lt_sub_left h)⟩\n\ninstance decidable_lo_hi_le (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] : decidable (∀x, lo ≤ x → x ≤ hi → P x) :=\ndecidable_of_iff (∀x, lo ≤ x → x < hi + 1 → P x) $\nball_congr $ λ x hl, imp_congr lt_succ_iff iff.rfl\n\nprotected theorem bit0_le {n m : ℕ} (h : n ≤ m) : bit0 n ≤ bit0 m :=\nadd_le_add h h\n\nprotected theorem bit1_le {n m : ℕ} (h : n ≤ m) : bit1 n ≤ bit1 m :=\nsucc_le_succ (add_le_add h h)\n\ntheorem bit_le : ∀ (b : bool) {n m : ℕ}, n ≤ m → bit b n ≤ bit b m\n| tt n m h := nat.bit1_le h\n| ff n m h := nat.bit0_le h\n\ntheorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 :=\nby cases b; [exact nat.bit0_ne_zero h, exact nat.bit1_ne_zero _]\n\ntheorem bit0_le_bit : ∀ (b) {m n : ℕ}, m ≤ n → bit0 m ≤ bit b n\n| tt m n h := le_of_lt $ nat.bit0_lt_bit1 h\n| ff m n h := nat.bit0_le h\n\ntheorem bit_le_bit1 : ∀ (b) {m n : ℕ}, m ≤ n → bit b m ≤ bit1 n\n| ff m n h := le_of_lt $ nat.bit0_lt_bit1 h\n| tt m n h := nat.bit1_le h\n\ntheorem bit_lt_bit0 : ∀ (b) {n m : ℕ}, n < m → bit b n < bit0 m\n| tt n m h := nat.bit1_lt_bit0 h\n| ff n m h := nat.bit0_lt h\n\ntheorem bit_lt_bit (a b) {n m : ℕ} (h : n < m) : bit a n < bit b m :=\nlt_of_lt_of_le (bit_lt_bit0 _ h) (bit0_le_bit _ (le_refl _))\n\n/- partial subtraction -/\n\n/-- Partial predecessor operation. Returns `ppred n = some m`\n  if `n = m + 1`, otherwise `none`. -/\n@[simp] def ppred : ℕ → option ℕ\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 : ℕ) : ℕ → option ℕ\n| 0     := some m\n| (n+1) := psub n >>= ppred\n\ntheorem pred_eq_ppred (n : ℕ) : pred n = (ppred n).get_or_else 0 :=\nby cases n; refl\n\ntheorem sub_eq_psub (m : ℕ) : ∀ 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 : ℕ} : ∀ {n}, ppred n = some m ↔ 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 : ∀ {n : ℕ}, ppred n = none ↔ n = 0\n| 0     := by simp\n| (n+1) := by dsimp; split; contradiction\n\ntheorem psub_eq_some {m : ℕ} : ∀ {n k}, psub m n = some k ↔ k + n = m\n| 0     k := by simp [eq_comm]\n| (n+1) k := by dsimp; apply option.bind_eq_some.trans; simp [psub_eq_some]\n\ntheorem psub_eq_none (m n : ℕ) : psub m n = none ↔ m < n :=\nbegin\n  cases s : psub m n; simp [eq_comm],\n  { show m < n, refine lt_of_not_ge (λ 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 ≤ m, rw ← 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 ≤ 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 ← psub m n, psub x k :=\nby induction k; simp [*, add_succ, bind_assoc]\n\n/- pow -/\n\nattribute [simp] nat.pow_zero nat.pow_one\n\n@[simp] lemma one_pow : ∀ n : ℕ, 1 ^ n = 1\n| 0 := rfl\n| (k+1) := show 1^k * 1 = 1, by rw [mul_one, one_pow]\n\ntheorem pow_add (a m n : ℕ) : a^(m + n) = a^m * a^n :=\nby induction n; simp [*, pow_succ, mul_assoc]\n\ntheorem pow_two (a : ℕ) : a ^ 2 = a * a := show (1 * a) * a = _, by rw one_mul\n\ntheorem pow_dvd_pow (a : ℕ) {m n : ℕ} (h : m ≤ n) : a^m ∣ a^n :=\nby rw [← nat.add_sub_cancel' h, pow_add]; apply dvd_mul_right\n\ntheorem pow_dvd_pow_of_dvd {a b : ℕ} (h : a ∣ b) : ∀ n:ℕ, a^n ∣ b^n\n| 0     := dvd_refl _\n| (n+1) := mul_dvd_mul (pow_dvd_pow_of_dvd n) h\n\ntheorem mul_pow (a b n : ℕ) : (a * b) ^ n = a ^ n * b ^ n :=\nby induction n; simp [*, nat.pow_succ, mul_comm, mul_assoc, mul_left_comm]\n\nprotected theorem pow_mul (a b n : ℕ) : n ^ (a * b) = (n ^ a) ^ b :=\nby induction b; simp [*, nat.succ_eq_add_one, nat.pow_add, mul_add, mul_comm]\n\ntheorem pow_pos {p : ℕ} (hp : p > 0) : ∀ n : ℕ, p ^ n > 0\n| 0 := by simpa using zero_lt_one\n| (k+1) := mul_pos (pow_pos _) hp\n\nlemma pow_eq_mul_pow_sub (p : ℕ) {m n : ℕ} (h : m ≤ n) : p ^ m * p ^ (n - m)  = p ^ n :=\nby rw [←nat.pow_add, nat.add_sub_cancel' h]\n\nlemma pow_lt_pow_succ {p : ℕ} (h : p > 1) (n : ℕ) : p^n < p^(n+1) :=\nsuffices p^n*1 < p^n*p, by simpa,\nnat.mul_lt_mul_of_pos_left h (nat.pow_pos (lt_of_succ_lt h) n)\n\nlemma lt_pow_self {p : ℕ} (h : p > 1) : ∀ n : ℕ, n < p ^ n\n| 0 := by simp [zero_lt_one]\n| (n+1) := calc\n  n + 1 < p^n + 1 : nat.add_lt_add_right (lt_pow_self _) _\n    ... ≤ p ^ (n+1) : pow_lt_pow_succ h _\n\nlemma not_pos_pow_dvd : ∀ {p k : ℕ} (hp : p > 1) (hk : k > 1), ¬ p^k ∣ p\n| (succ p) (succ k) hp hk h :=\n  have (succ p)^k * succ p ∣ 1 * succ p, by simpa,\n  have (succ p) ^ k ∣ 1, from dvd_of_mul_dvd_mul_right (succ_pos _) this,\n  have he : (succ p) ^ k = 1, from eq_one_of_dvd_one this,\n  have k < (succ p) ^ k, from lt_pow_self hp k,\n  have k < 1, by rwa [he] at this,\n  have k = 0, from eq_zero_of_le_zero $ le_of_lt_succ this,\n  have 1 > 1, by rwa [this] at hk,\n  absurd this dec_trivial\n\n@[simp] theorem bodd_div2_eq (n : ℕ) : bodd_div2 n = (bodd n, div2 n) :=\nby unfold bodd div2; cases bodd_div2 n; refl\n\n@[simp] lemma bodd_bit0 (n) : bodd (bit0 n) = ff := bodd_bit ff n\n@[simp] lemma bodd_bit1 (n) : bodd (bit1 n) = tt := bodd_bit tt n\n\n@[simp] lemma div2_bit0 (n) : div2 (bit0 n) = n := div2_bit ff n\n@[simp] lemma div2_bit1 (n) : div2 (bit1 n) = n := div2_bit tt n\n\n/- iterate -/\n\nsection\nvariables {α : Sort*} (op : α → α)\n\n@[simp] theorem iterate_zero (a : α) : op^[0] a = a := rfl\n\n@[simp] theorem iterate_succ (n : ℕ) (a : α) : op^[succ n] a = (op^[n]) (op a) := rfl\n\ntheorem iterate_add : ∀ (m n : ℕ) (a : α), op^[m + n] a = (op^[m]) (op^[n] a)\n| m 0 a := rfl\n| m (succ n) a := iterate_add m n _\n\ntheorem iterate_succ' (n : ℕ) (a : α) : op^[succ n] a = op (op^[n] a) :=\nby rw [← one_add, iterate_add]; refl\n\ntheorem iterate₀ {α : Type u} {op : α → α} {x : α} (H : op x = x) {n : ℕ} :\n  op^[n] x = x :=\nby induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]]\n\ntheorem iterate₁ {α : Type u} {β : Type v} {op : α → α} {op' : β → β} {op'' : α → β}\n  (H : ∀ x, op' (op'' x) = op'' (op x)) {n : ℕ} {x : α} :\n  op'^[n] (op'' x) = op'' (op^[n] x) :=\nby induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]]\n\ntheorem iterate₂ {α : Type u} {op : α → α} {op' : α → α → α} (H : ∀ x y, op (op' x y) = op' (op x) (op y)) {n : ℕ} {x y : α} :\n  op^[n] (op' x y) = op' (op^[n] x) (op^[n] y) :=\nby induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]]\n\ntheorem iterate_cancel {α : Type u} {op op' : α → α} (H : ∀ x, op (op' x) = x) {n : ℕ} {x : α} : op^[n] (op'^[n] x) = x :=\nby induction n; [refl, rwa [iterate_succ, iterate_succ', H]]\n\ntheorem iterate_inj {α : Type u} {op : α → α} (Hinj : function.injective op) (n : ℕ) (x y : α)\n  (H : (op^[n] x) = (op^[n] y)) : x = y :=\nby induction n with n ih; simp only [iterate_zero, iterate_succ'] at H;\n[exact H, exact ih (Hinj H)]\n\nend\n\n/- size and shift -/\n\ntheorem shiftl'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftl' b m n ≠ 0 :=\nby induction n; simp [shiftl', bit_ne_zero, *]\n\ntheorem shiftl'_tt_ne_zero (m) : ∀ {n} (h : n ≠ 0), shiftl' tt m n ≠ 0\n| 0        h := absurd rfl h\n| (succ n) _ := nat.bit1_ne_zero _\n\n@[simp] theorem size_zero : size 0 = 0 := rfl\n\n@[simp] theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) :=\nbegin\n  rw size,\n  conv { to_lhs, rw [binary_rec], simp [h] },\n  rw div2_bit, refl\nend\n\n@[simp] theorem size_bit0 {n} (h : n ≠ 0) : size (bit0 n) = succ (size n) :=\n@size_bit ff n (nat.bit0_ne_zero h)\n\n@[simp] theorem size_bit1 (n) : size (bit1 n) = succ (size n) :=\n@size_bit tt n (nat.bit1_ne_zero n)\n\n@[simp] theorem size_one : size 1 = 1 := by apply size_bit1 0\n\n@[simp] theorem size_shiftl' {b m n} (h : shiftl' b m n ≠ 0) :\n  size (shiftl' b m n) = size m + n :=\nbegin\n  induction n with n IH; simp [shiftl'] at h ⊢,\n  rw [size_bit h, nat.add_succ],\n  by_cases s0 : shiftl' b m n = 0; [skip, rw [IH s0]],\n  rw s0 at h ⊢,\n  cases b, {exact absurd rfl h},\n  have : shiftl' tt m n + 1 = 1 := congr_arg (+1) s0,\n  rw [shiftl'_tt_eq_mul_pow] at this,\n  have m0 := succ_inj (eq_one_of_dvd_one ⟨_, this.symm⟩),\n  subst m0,\n  simp at this,\n  have : n = 0 := eq_zero_of_le_zero (le_of_not_gt $ λ hn,\n    ne_of_gt (pow_lt_pow_of_lt_right dec_trivial hn) this),\n  subst n, refl\nend\n\n@[simp] theorem size_shiftl {m} (h : m ≠ 0) (n) :\n  size (shiftl m n) = size m + n :=\nsize_shiftl' (shiftl'_ne_zero_left _ h _)\n\ntheorem lt_size_self (n : ℕ) : n < 2^size n :=\nbegin\n  rw [← one_shiftl],\n  have : ∀ {n}, n = 0 → n < shiftl 1 (size n) :=\n    λ n e, by subst e; exact dec_trivial,\n  apply binary_rec _ _ n, {apply this rfl},\n  intros b n IH,\n  by_cases bit b n = 0, {apply this h},\n  rw [size_bit h, shiftl_succ],\n  exact bit_lt_bit0 _ IH\nend\n\ntheorem size_le {m n : ℕ} : size m ≤ n ↔ m < 2^n :=\n⟨λ h, lt_of_lt_of_le (lt_size_self _) (pow_le_pow_of_le_right dec_trivial h),\nbegin\n  rw [← one_shiftl], revert n,\n  apply binary_rec _ _ m,\n  { intros n h, apply zero_le },\n  { intros b m IH n h,\n    by_cases e : bit b m = 0, { rw e, apply zero_le },\n    rw [size_bit e],\n    cases n with n,\n    { exact e.elim (eq_zero_of_le_zero (le_of_lt_succ h)) },\n    { apply succ_le_succ (IH _),\n      apply lt_imp_lt_of_le_imp_le (λ h', bit0_le_bit _ h') h } }\nend⟩\n\ntheorem lt_size {m n : ℕ} : m < size n ↔ 2^m ≤ n :=\nby rw [← not_lt, iff_not_comm, not_lt, size_le]\n\ntheorem size_pos {n : ℕ} : 0 < size n ↔ 0 < n :=\nby rw lt_size; refl\n\ntheorem size_eq_zero {n : ℕ} : size n = 0 ↔ n = 0 :=\nby have := @size_pos n; simp [pos_iff_ne_zero'] at this;\n   exact not_iff_not.1 this\n\ntheorem size_pow {n : ℕ} : size (2^n) = n+1 :=\nle_antisymm\n  (size_le.2 $ pow_lt_pow_of_lt_right dec_trivial (lt_succ_self _))\n  (lt_size.2 $ le_refl _)\n\ntheorem size_le_size {m n : ℕ} (h : m ≤ n) : size m ≤ size n :=\nsize_le.2 $ lt_of_le_of_lt h (lt_size_self _)\n\n/- factorial -/\n\n/-- `fact n` is the factorial of `n`. -/\n@[simp] def fact : nat → nat\n| 0        := 1\n| (succ n) := succ n * fact n\n\n@[simp] theorem fact_zero : fact 0 = 1 := rfl\n\n@[simp] theorem fact_one : fact 1 = 1 := rfl\n\n@[simp] theorem fact_succ (n) : fact (succ n) = succ n * fact n := rfl\n\ntheorem fact_pos : ∀ n, fact n > 0\n| 0        := zero_lt_one\n| (succ n) := mul_pos (succ_pos _) (fact_pos n)\n\ntheorem fact_ne_zero (n : ℕ) : fact n ≠ 0 := ne_of_gt (fact_pos _)\n\ntheorem fact_dvd_fact {m n} (h : m ≤ n) : fact m ∣ fact n :=\nbegin\n  induction n with n IH; simp,\n  { have := eq_zero_of_le_zero h, subst m, simp },\n  { cases eq_or_lt_of_le h with he hl,\n    { subst m, simp },\n    { apply dvd_mul_of_dvd_right (IH (le_of_lt_succ hl)) } }\nend\n\ntheorem dvd_fact : ∀ {m n}, m > 0 → m ≤ n → m ∣ fact n\n| (succ m) n _ h := dvd_of_mul_right_dvd (fact_dvd_fact h)\n\ntheorem fact_le {m n} (h : m ≤ n) : fact m ≤ fact n :=\nle_of_dvd (fact_pos _) (fact_dvd_fact h)\n\nlemma fact_mul_pow_le_fact : ∀ {m n : ℕ}, m.fact * m.succ ^ n ≤ (m + n).fact\n| m 0     := by simp\n| m (n+1) :=\nby  rw [← add_assoc, nat.fact_succ, mul_comm (nat.succ _), nat.pow_succ, ← mul_assoc];\n  exact mul_le_mul fact_mul_pow_le_fact\n    (nat.succ_le_succ (nat.le_add_right _ _)) (nat.zero_le _) (nat.zero_le _)\n\nsection find_greatest\n\n/-- `find_greatest P b` is the largest `i ≤ bound` such that `P i` holds, or `0` if no such `i`\nexists -/\nprotected def find_greatest (P : ℕ → Prop) [decidable_pred P] : ℕ → ℕ\n| 0       := 0\n| (n + 1) := if P (n + 1) then n + 1 else find_greatest n\n\nvariables {P : ℕ → Prop} [decidable_pred P]\n\n@[simp] lemma find_greatest_zero : nat.find_greatest P 0 = 0 := rfl\n\n@[simp] lemma find_greatest_eq : ∀{b}, P b → nat.find_greatest P b = b\n| 0       h := rfl\n| (n + 1) h := by simp [nat.find_greatest, h]\n\n@[simp] lemma find_greatest_of_not {b} (h : ¬ P (b + 1)) :\n  nat.find_greatest P (b + 1) = nat.find_greatest P b :=\nby simp [nat.find_greatest, h]\n\nlemma find_greatest_spec_and_le :\n  ∀{b m}, m ≤ b → P m → P (nat.find_greatest P b) ∧ m ≤ nat.find_greatest P b\n| 0       m hm hP :=\n  have m = 0, from le_antisymm hm (nat.zero_le _),\n  show P 0 ∧ m ≤ 0, from this ▸ ⟨hP, le_refl _⟩\n| (b + 1) m hm hP :=\n  begin\n    by_cases h : P (b + 1),\n    { simp [h, hm] },\n    { have : m ≠ b + 1 := assume this, h $ this ▸ hP,\n      have : m ≤ b := (le_of_not_gt $ assume h : b + 1 ≤ m, this $ le_antisymm hm h),\n      have : P (nat.find_greatest P b) ∧ m ≤ nat.find_greatest P b :=\n        find_greatest_spec_and_le this hP,\n      simp [h, this] }\n  end\n\nlemma find_greatest_spec {b} : (∃m, m ≤ b ∧ P m) → P (nat.find_greatest P b)\n| ⟨m, hmb, hm⟩ := (find_greatest_spec_and_le hmb hm).1\n\nlemma find_greatest_le : ∀ {b}, nat.find_greatest P b ≤ b\n| 0       := le_refl _\n| (b + 1) :=\n  have nat.find_greatest P b ≤ b + 1, from le_trans find_greatest_le (nat.le_succ b),\n  by by_cases P (b + 1); simp [h, this]\n\nlemma le_find_greatest {b m} (hmb : m ≤ b) (hm : P m) : m ≤ nat.find_greatest P b :=\n(find_greatest_spec_and_le hmb hm).2\n\nlemma find_greatest_is_greatest {P : ℕ → Prop} [decidable_pred P] {b} :\n  (∃ m, m ≤ b ∧ P m) → ∀ k, nat.find_greatest P b < k ∧ k ≤ b → ¬ P k\n| ⟨m, hmb, hP⟩ k ⟨hk, hkb⟩ hPk := lt_irrefl k $ lt_of_le_of_lt (le_find_greatest hkb hPk) hk\n\nend find_greatest\n\nsection div\nlemma dvd_div_of_mul_dvd {a b c : ℕ} (h : a * b ∣ c) : b ∣ c / a :=\nif ha : a = 0 then\n  by simp [ha]\nelse\n  have ha : a > 0, from nat.pos_of_ne_zero ha,\n  have h1 : ∃ d, c = a * b * d, from h,\n  let ⟨d, hd⟩ := h1 in\n  have hac : a ∣ c, from dvd_of_mul_right_dvd h,\n  have h2 : c / a = b * d, from nat.div_eq_of_eq_mul_right ha (by simpa [mul_assoc] using hd),\n  show ∃ d, c / a = b * d, from ⟨d, h2⟩\n\nlemma mul_dvd_of_dvd_div {a b c : ℕ} (hab : c ∣ b) (h : a ∣ b / c) : c * a ∣ b :=\nhave h1 : ∃ d, b / c = a * d, from h,\nhave h2 : ∃ e, b = c * e, from hab,\nlet ⟨d, hd⟩ := h1, ⟨e, he⟩ := h2 in\nhave h3 : b = a * d * c, from\n  nat.eq_mul_of_div_eq_left hab hd,\nshow ∃ d, b = c * a * d, from ⟨d, by cc⟩\n\nlemma div_mul_div {a b c d : ℕ} (hab : b ∣ a) (hcd : d ∣ c) :\n      (a / b) * (c / d) = (a * c) / (b * d) :=\nhave exi1 : ∃ x, a = b * x, from hab,\nhave exi2 : ∃ y, c = d * y, from hcd,\nif hb : b = 0 then by simp [hb]\nelse have b > 0, from nat.pos_of_ne_zero hb,\nif hd : d = 0 then by simp [hd]\nelse have d > 0, from nat.pos_of_ne_zero hd,\nbegin\n  cases exi1 with x hx, cases exi2 with y hy,\n  rw [hx, hy, nat.mul_div_cancel_left, nat.mul_div_cancel_left],\n  symmetry,\n  apply nat.div_eq_of_eq_mul_left,\n  apply mul_pos,\n  repeat {assumption},\n  cc\nend\n\nlemma pow_dvd_of_le_of_pow_dvd {p m n k : ℕ} (hmn : m ≤ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k :=\nhave p ^ m ∣ p ^ n, from pow_dvd_pow _ hmn,\ndvd_trans this hdiv\n\nlemma dvd_of_pow_dvd {p k m : ℕ} (hk : 1 ≤ k) (hpk : p^k ∣ m) : p ∣ m :=\nby rw ←nat.pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk\n\nend div\n\nlemma exists_eq_add_of_le : ∀ {m n : ℕ}, m ≤ n → ∃ k : ℕ, n = m + k\n| 0 0 h := ⟨0, by simp⟩\n| 0 (n+1) h := ⟨n+1, by simp⟩\n| (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk]⟩\n\nlemma exists_eq_add_of_lt : ∀ {m n : ℕ}, m < n → ∃ k : ℕ, n = m + k + 1\n| 0 0 h := false.elim $ lt_irrefl _ h\n| 0 (n+1) h := ⟨n, by simp⟩\n| (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk]⟩\n\nlemma with_bot.add_eq_zero_iff : ∀ {n m : with_bot ℕ}, n + m = 0 ↔ n = 0 ∧ m = 0\n| none     m        := iff_of_false dec_trivial (λ h, absurd h.1 dec_trivial)\n| n        none     := iff_of_false (by cases n; exact dec_trivial)\n  (λ h, absurd h.2 dec_trivial)\n| (some n) (some m) := show (n + m : with_bot ℕ) = (0 : ℕ) ↔ (n : with_bot ℕ) = (0 : ℕ) ∧\n    (m : with_bot ℕ) = (0 : ℕ),\n  by rw [← with_bot.coe_add, with_bot.coe_eq_coe, with_bot.coe_eq_coe,\n    with_bot.coe_eq_coe, add_eq_zero_iff' (nat.zero_le _) (nat.zero_le _)]\n\nlemma with_bot.add_eq_one_iff : ∀ {n m : with_bot ℕ}, n + m = 1 ↔ (n = 0 ∧ m = 1) ∨ (n = 1 ∧ m = 0)\n| none     none     := dec_trivial\n| none     (some m) := dec_trivial\n| (some n) none     := iff_of_false dec_trivial (λ h, h.elim (λ h, absurd h.2 dec_trivial)\n  (λ h, absurd h.2 dec_trivial))\n| (some n) (some 0) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe,\n    with_bot.coe_eq_coe]; simp\n| (some n) (some (m + 1)) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe,\n    with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp [nat.add_succ, nat.succ_inj', nat.succ_ne_zero]\n\n-- induction\n\n@[elab_as_eliminator] lemma le_induction {P : nat → Prop} {m} (h0 : P m) (h1 : ∀ n ≥ m, P n → P (n + 1)) :\n  ∀ n ≥ m, P n :=\nby apply nat.less_than_or_equal.rec h0; exact h1\n\nend nat\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/nat/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7540983340931747}}
{"text": "import data.real.basic\n\nvariables (a b c d e : ℝ)\n#check (min_le_left a b : min a b ≤ a)\n#check (min_le_right a b : min a b ≤ b)\n#check (le_min : c ≤ a → c ≤ b → c ≤ min a b)\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  { show min a b ≤ min b a,\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left,},\n  { show min b a ≤ min a b,\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left,},\nend\n\n#check min\n\n\nexample : min a b = min b a :=\nbegin\n  apply le_antisymm,\n  repeat {\n    apply le_min,\n    apply min_le_right,\n    apply min_le_left }\nend\n\nexample : max a b = max b a :=\nbegin \n  have h : ∀ (x y : ℝ), max x y ≤ max y x := by \n  { intros,\n    apply max_le,\n    apply le_max_right,\n    apply le_max_left,},\n  apply ge_antisymm,\n  repeat {apply h},\nend \n\nexample : min (min a b) c = min a (min b c) :=\nbegin \n  apply le_antisymm,\n  { apply le_min,\n    { have h : min a b ≤ a := by apply min_le_left,\n      have : min (min a b) c ≤ min a b := by apply min_le_left,\n      show min (min a b) c ≤ a,\n      apply le_trans this h,},\n    { show min (min a b) c ≤ min b c,\n      apply le_min,\n      { have h : min a b ≤ b := by apply min_le_right,\n        have : min (min a b) c ≤ min a b := by apply min_le_left,\n        show min (min a b) c ≤ b,\n        apply le_trans this h,},\n      { show min (min a b) c ≤ c,\n        apply min_le_right,},},\n    },\n  { apply le_min,\n    { show min a (min b c) ≤ min a b,\n      apply le_min,\n      { show min a (min b c) ≤ a,\n        apply min_le_left,},\n      { show min a (min b c) ≤ b,\n        have h : min b c ≤ b := by apply min_le_left,\n        have : min a (min b c) ≤ min b c := by apply min_le_right,\n        apply le_trans this h,},\n      },\n    { show min a (min b c) ≤ c,\n      have h : min b c ≤ c := by apply min_le_right,\n      have : min a (min b c) ≤ min b c := by apply min_le_right,\n      apply le_trans this h,},\n  },\nend\n\n \nlemma aux : min a b + c ≤ min (a + c) (b + c) :=\nbegin \n  apply le_min,\n  { show min a b + c ≤ a + c,\n    apply add_le_add_right,\n    apply min_le_left,},\n  { show min a b + c ≤ b + c,\n    apply add_le_add_right,\n    apply min_le_right,},\nend\n\nexample : min a b + c = min (a + c) (b + c) :=\nbegin\n  apply le_antisymm,\n  { show min a b + c ≤ min (a + c) (b + c),\n    apply aux,},\n  { show min (a + c) (b + c) ≤ min a b + c,\n    have : min (a + c) (b + c) + -c ≤ min (a + c + -c) (b + c + -c) :=\n      by apply aux,\n    rw [add_neg_cancel_right a c] at this,\n    rw add_neg_cancel_right b at this,\n    have : min (a + c) (b + c) + -c + c ≤ min a b + c := \n      by apply add_le_add_right this,\n    rw [add_assoc, add_comm (-c) c, ←add_assoc, add_neg_cancel_right] at this,\n    exact this,\n},\nend\n\n\n\n#check (abs_add : ∀ a b : ℝ, abs (a + b) ≤ abs a + abs b)\n\n\nexample : |a| - |b| ≤ |a - b| :=\nbegin \n  have : |a| ≤ |a - b| + |b|,\n    calc \n      |a| = |a - b + b| : by ring_nf\n      ... ≤ |a - b| + |b| : by apply abs_add,\n  linarith,\nend\n\n\n\n\nvariables (x y z w : ℕ)\n\nexample (h₀ : x ∣ y) (h₁ : y ∣ z) : x ∣ z :=\ndvd_trans h₀ h₁\n\nexample : x ∣ y * x * z :=\nbegin\n  apply dvd_mul_of_dvd_left,\n  apply dvd_mul_left\nend\n\nexample : x ∣ x^2 :=\nby apply dvd_mul_right\n\nexample (h : x ∣ w) : x ∣ y * (x * z) + x^2 + w^2 :=\nbegin \n  repeat {apply dvd_add},\n  { show x ∣ y * (x * z),\n    have : x ∣ (x * z) := by apply dvd_mul_right,\n    apply dvd_trans,\n    apply dvd_mul_right,\n    exact z,\n    apply dvd_mul_left,},\n  { show x ∣ x^2,\n    apply dvd_mul_right,},\n  { show x ∣ w^2,\n    apply dvd_trans h,\n    apply dvd_mul_right,},\nend\n \n\n#check @dvd_trans\n\nvariables m n : ℕ\nopen nat\n\n#check (gcd_zero_right n : gcd n 0 = n)\n#check (gcd_zero_left n  : gcd 0 n = n)\n#check (lcm_zero_right n : lcm n 0 = 0)\n#check (lcm_zero_left n  : lcm 0 n = 0)\n\n\nexample : gcd m n = gcd n m :=\nbegin \n  apply gcd_greatest,\n  apply gcd_dvd_right,\n  apply gcd_dvd_left, \n  { show ∀ e, e ∣ n → e ∣ m → e ∣ gcd m n,\n    intros e hn hm,\n    apply dvd_gcd hm hn,\n  },\nend\n\n\n#check gcd_greatest", "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/04_More_Divisibility_Order.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7540983256515433}}
{"text": "import topology.metric_space.basic\n\nnamespace playground\n\nclass my_add_semigroup (α : Type) :=\n(add : α → α → α)\n(add_assoc' : ∀ a b c, add (add a b) c = add a (add b c))\n(add_comm' : ∀ a b, add a b = add b a)\n\nsection\nopen my_add_semigroup\n\ntheorem comm_assoc' {α : Type} [my_add_semigroup α] (a b c : α) :\n  add (add a b) c = add c (add b a) :=\nbegin rw [add_comm' _ c, add_comm' b] end\n\n--set_option old_structure_cmd true\nclass my_add_group (α : Type) extends my_add_semigroup α :=\n(zero : α)\n(add_zero' : ∀ a, add a zero = a)\n\n#print my_add_group\n\nopen my_add_group\n\ntheorem zero_add' {α : Type} [my_add_group α] (a : α) :\n  add (zero α) a = a :=\nbegin rw [add_comm', add_zero'] end\n\n\ninstance : my_add_semigroup ℕ :=\n{ add := (+),\n  add_assoc' := by intros; simp,\n  add_comm' := by intros; simp }\n\ntheorem nat_comm_assoc (a b c : ℕ) : (a + b) + c = c + (b + a) :=\ncomm_assoc' a b c\n\nset_option pp.all true\n#print nat_comm_assoc\nset_option pp.all false\n\ntheorem new_thm {α : Type} [my_add_group α] (a : α) :\n  add a a = a :=\nsorry\n\nexample (α : Type) [my_add_semigroup α] (a : α) : add a a = a :=\nbegin\n  rw new_thm\nend\n\nend\n\n\n\n#check topological_space\n#check @continuous\n#check metric_space\n\nexample (α : Type) [metric_space α] : continuous (λ x : α, x) :=\ncontinuous_id\n\n\nclass t1 (α : Type) :=\n(val1 : α)\n\nclass t2 (α : Type) :=\n(val2 : ℕ)\n\nclass t3 (α : Type) :=\n(val3 : α) (val4 : ℕ)\n\ninstance inst_t1_of_t3 (α : Type) [t3 α] : t1 α :=\n{ val1 := t3.val3 α }\n\ninstance inst_t2_of_t3 (α : Type) [t3 α] : t2 α :=\n{ val2 := t3.val4 α }\n\ninstance t3_int : t3 ℤ :=\n{ val3 := -1, val4 := 100 }\n\n#eval t1.val1 ℤ\n\n/- instance inst_t3_of_t1_t2 (α : Type) [t1 α] [t2 α] : t3 α :=\n{ val3 := t1.val1 α, val4 := t2.val2 α } -/\n\nexample (α : Type) [t1 α] [t2 α] : ℕ := t3.val4 α\n\nset_option trace.class_instances true\nexample (α : Type) : ℕ := t3.val4 α\nset_option trace.class_instances false\n\n\n\n\ninstance bad_instance (α β : Type) [has_add β] : t2 α :=\n{ val2 := 5 }\n\nset_option trace.class_instances true\n#check t2.val2 ℕ\nset_option trace.class_instances false\n\nend playground\n\n#check group\n#check comm_group\n#check ordered_comm_group\n#check ring\n#check field\n#check discrete_field\n\n#check fintype\n\n#check decidable_eq\n\n\n/-\n  Exercise:\n  Define a type class for your favorite kind of structure.\n  Suggestions: monoids, groups, additive groups, rings, fields\n\n  Define instances of your type class.\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/rob/type_classes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.754098324814764}}
{"text": "-- M40002 (Analysis I) Chapter 6. Differentiation\n\nimport M40002.M40002_C5\n\nnamespace M40002\n\n-- Definition of a function being differntiable at a point\ndef is_derivative (f : ℝ → ℝ) (a l : ℝ) := func_converges_to (λ x : ℝ, (f x - f a) / (x - a)) a l\ndef differentiable_at (f : ℝ → ℝ) (a : ℝ) := ∃ l : ℝ, is_derivative f a l\ndef differentiable (f : ℝ → ℝ) := ∀ a : ℝ, differentiable_at f a\n\n-- Differentiable at a point implies continuity at a point\ntheorem diff_at_to_contin_at (f : ℝ → ℝ) (a : ℝ) : differentiable_at f a → func_continuous_at f a :=\nbegin\n  rw func_continuous_at_to_pos,\n  rintros ⟨l, hl⟩ ε hε,\n  rcases (hl ε hε) with ⟨δ, ⟨hδ₁, hδ₂⟩⟩,\n  let ε' : ℝ := ε / (ε + abs(l)),\n  have hε' : 0 < ε' := show 0 < ε / (ε + abs l),\n    by {apply (lt_div_iff' _).mpr, linarith,\n    from lt_add_of_lt_of_nonneg hε (abs_nonneg l)\n    },\n  let δ' : ℝ := min δ ε',\n  have hδ' : 0 < δ' := show 0 < min δ ε',\n    by {rw lt_min_iff, from ⟨hδ₁, hε'⟩},\n  use δ', use hδ',\n  intros x hx,\n  suffices : abs (f x - f a) ≤ abs (f x - f a - (x - a) * l) + abs ((x - a) * l),\n  swap, have : abs (f x - f a - (x - a) * l + (x - a) * l) = abs (f x - f a) := by simp,\n  rw ←this,\n  apply abs_add,\n    apply lt_of_le_of_lt this,\n    have hlt : abs (f x - f a - (x - a) * l) < abs (x - a) * ε :=\n      by {rw ←div_lt_iff' hx.left,\n      rw ←abs_div,\n      convert hδ₂ x (lt_of_lt_of_le hx.right (min_le_left δ ε')),\n      show (f x - f a - (x - a) * l) / (x - a) = (f x - f a) / (x - a) - l,\n      rw sub_div,\n      repeat {rw sub_eq_add_neg <|> rw add_left_inj ((f x + -f a) / (x + -a))},\n      rw mul_div_cancel_left, from abs_pos_iff.mp hx.left\n      },\n    apply lt_of_lt_of_le ((add_lt_add_iff_right (abs ((x - a) * l))).mpr hlt),\n    rw [abs_mul, tactic.ring_exp.add_overlap_pf (abs (x - a)) rfl],\n    apply le_trans (le_of_lt ((mul_lt_mul_right (lt_add_of_lt_of_nonneg hε (abs_nonneg l))).mpr hx.right)),\n    have hδle : δ' * (ε + abs l) ≤ (ε / (ε + abs(l))) * (ε + abs l) :=\n      by {rw mul_le_mul_right (lt_add_of_lt_of_nonneg hε (abs_nonneg l)), from min_le_right δ ε'},\n    apply le_trans hδle,\n    rwa [div_eq_mul_inv, mul_assoc, inv_mul_cancel _], linarith,\n    suffices : 0 < ε + abs l, linarith,\n    from lt_add_of_lt_of_nonneg hε (abs_nonneg l)\nend\n\n-- Cor. Differentiable implies continuity\ntheorem diff_to_contin (f : ℝ → ℝ) : differentiable f → func_continuous f :=\nbegin\n  intros hdiff a,\n  apply diff_at_to_contin_at, from hdiff a\nend\n\n-- If f and g are both differentiable then so is f + g\ntheorem diff_sum_diff_func (f g : ℝ → ℝ)  (hf : differentiable f) (hg : differentiable g) : \ndifferentiable (f + g) :=\nbegin\n  intro a,\n  cases hf a with l hl,\n  cases hg a with k hk, \n  use l + k, unfold is_derivative,\n  simp [(show ∀ (x : ℝ), (f x + g x - (f a + g a)) / (x - a) = \n    (f x - f a) / (x - a) + (g x - g a) / (x - a), by intro x; ring)],\n  exact func_add_func_conv _ _ a l k ⟨hl, hk⟩,\nend\n\n-- Local and global maximums and minimums\ndef local_max (f : ℝ → ℝ) (x₀ : ℝ) := ∃ δ > 0, ∀ x ∈ open_interval (x₀ - δ) (x₀ + δ), f x₀ < f x\ndef local_min (f : ℝ → ℝ) (x₀ : ℝ) := ∃ δ > 0, ∀ x ∈ open_interval (x₀ - δ) (x₀ + δ), f x < f x₀\n\ndef global_max (f : ℝ → ℝ) (x₀ : ℝ) := ∀ x : ℝ, f x₀ < f x\ndef global_min (f : ℝ → ℝ) (x₀ : ℝ) := ∀ x : ℝ, f x < f x₀\n\ntheorem global_max_is_local_max {f : ℝ → ℝ} {x₀ : ℝ} : global_max f x₀ → local_max f x₀ :=\nbegin\n  intro hgmax,\n  use 1,\n  split, norm_num,\n  intros x hx,\n  from hgmax x\nend\n\ntheorem global_min_is_local_min {f : ℝ → ℝ} {x₀ : ℝ} : global_min f x₀ → local_min f x₀ := \nbegin\n  intro hgmix,\n  use 1,\n  split, norm_num,\n  intros x hx,\n  from hgmix x\nend\n\n-- Fermat's theorem\ntheorem local_min_diff_zero {f : ℝ → ℝ} {x₀ : ℝ} (h : local_min f x₀) : \ndifferentiable_at f x₀ → is_derivative f x₀ 0 := sorry\n\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_C6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7540087888061514}}
{"text": "theorem T1_1 {A B : Prop} (ha : A ) (hb : B ) : (B /\\ A) /\\ B := \n and.intro (and.intro hb ha) hb\n\n\ntheorem T1_2 {A : Prop} (ha : A )  : A /\\ A := \n and.intro ha ha\n\ntheorem T2_1 {A B : Prop} (h : A /\\ B)  : B /\\ A := \n  and.intro (and.right h) (and.left h)\n\ntheorem T3_1 {A B C: Prop} (h : A )  : C \\/  (A \\/ B) := \n   or.inr (or.inl h) \n\ntheorem T4_1 {A : Prop}  : A ->  ( A /\\ A) := \n assume (h : A), and.intro h h \n\ntheorem T5_1 {A B C : Prop}  : ((A /\\ B) \\/ C) -> ((A /\\ B) \\/ C)   := \n assume (h : ((A /\\ B) \\/ C) ), h\n\n theorem T5_2 {A B : Prop}  : B -> (A -> A)   := \n assume (hb :B), assume (ha :A), ha \n\n theorem T6_1 {A : Prop}  : A -> A   := \n assume (ha :A), ha \n\ntheorem T7_1 {A B : Prop}  : A -> (B -> A)  := \n  assume (ha : A), assume (hb : B), ha \n\ntheorem T8_1 {A B : Prop} (h1 : A)  (h2 : (A -> B) ) : B:= \n  h2 h1\n\ntheorem T9_1 {A B : Prop} (h: A \\/  B) : B \\/  A := \n  or.elim\n    h \n    (assume (h1 : A ), or.inr h1)\n    (assume (h1 : B ), or.inl h1) \n\ntheorem T9_2 {A : Prop} (h: A \\/  A) : A := \n  or.elim\n    h \n    (assume (h1 : A ), h1)\n    (assume (h1 : A ), h1) \n\ntheorem T10_1 {A B: Prop} (h1: A) (h2: A <-> B): B := \n  iff.elim_left h2 h1\n\ntheorem T11_1 {A B: Prop} (h: A /\\ not A ) : B := \n  show B, from false.elim ((and.right h) (and.left h)) \n\n", "meta": {"author": "lkimelfeld", "repo": "qedlean", "sha": "b5aedf874fa36d746777cdd905c1b95e32e3dac5", "save_path": "github-repos/lean/lkimelfeld-qedlean", "path": "github-repos/lean/lkimelfeld-qedlean/qedlean-b5aedf874fa36d746777cdd905c1b95e32e3dac5/qed-lean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7540087881525179}}
{"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.nat.sqrt\nimport data.set.lattice\nimport algebra.group.prod\nimport algebra.order.monoid.min_max\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 `⟦0, n^2 - 1⟧` to\n`⟦0, n - 1⟧²`.\n-/\n\nopen prod decidable function\n\nnamespace nat\n\n/-- Pairing function for the natural numbers. -/\n@[pp_nodot] def mkpair (a b : ℕ) : ℕ :=\nif a < b then b*b + a else a*a + a + b\n\n/-- Unpairing function for the natural numbers. -/\n@[pp_nodot] def unpair (n : ℕ) : ℕ × ℕ :=\nlet s := sqrt n in\nif n - s*s < s then (n - s*s, s) else (s, n - s*s - s)\n\n@[simp] theorem mkpair_unpair (n : ℕ) : mkpair (unpair n).1 (unpair n).2 = n :=\nbegin\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  { simp [mkpair, h, sm] },\n  { have hl : n - s*s - s ≤ s :=\n      tsub_le_iff_left.mpr (tsub_le_iff_left.mpr $\n      by rw ← 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] }\nend\n\ntheorem mkpair_unpair' {n a b} (H : unpair n = (a, b)) : mkpair a b = n :=\nby simpa [H] using mkpair_unpair n\n\n@[simp] theorem unpair_mkpair (a b : ℕ) : unpair (mkpair a b) = (a, b) :=\nbegin\n  dunfold mkpair, split_ifs,\n  { show unpair (b * b + a) = (a, b),\n    have be : sqrt (b * b + a) = b,\n      from sqrt_add_eq _ (le_trans (le_of_lt h) (nat.le_add_left _ _)),\n    simp [unpair, be, add_tsub_cancel_right, h] },\n  { show unpair (a * a + a + b) = (a, b),\n    have ae : sqrt (a * a + (a + b)) = a,\n    { rw sqrt_add_eq, exact add_le_add_left (le_of_not_gt h) _ },\n    simp [unpair, ae, nat.not_lt_zero, add_assoc] }\nend\n\n/-- An equivalence between `ℕ × ℕ` and `ℕ`. -/\n@[simps { fully_applied := ff }] def mkpair_equiv : ℕ × ℕ ≃ ℕ :=\n⟨uncurry mkpair, unpair, λ ⟨a, b⟩, unpair_mkpair a b, mkpair_unpair⟩\n\nlemma surjective_unpair : surjective unpair :=\nmkpair_equiv.symm.surjective\n\n@[simp] lemma mkpair_eq_mkpair {a b c d : ℕ} : mkpair a b = mkpair c d ↔ a = c ∧ b = d :=\nmkpair_equiv.injective.eq_iff.trans (@prod.ext_iff ℕ ℕ (a, b) (c, d))\n\ntheorem unpair_lt {n : ℕ} (n1 : 1 ≤ n) : (unpair n).1 < n :=\nlet s := sqrt n in begin\n  simp [unpair], change sqrt n with s,\n  by_cases h : n - s * s < s; simp [h],\n  { exact lt_of_lt_of_le h (sqrt_le_self _) },\n  { 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)) }\nend\n\n@[simp] lemma unpair_zero : unpair 0 = 0 :=\nby { rw unpair, simp }\n\ntheorem unpair_left_le : ∀ (n : ℕ), (unpair n).1 ≤ n\n| 0     := by simp\n| (n+1) := le_of_lt (unpair_lt (nat.succ_pos _))\n\ntheorem left_le_mkpair (a b : ℕ) : a ≤ mkpair a b :=\nby simpa using unpair_left_le (mkpair a b)\n\ntheorem right_le_mkpair (a b : ℕ) : b ≤ mkpair a b :=\nbegin\n  by_cases h : a < b; simp [mkpair, h],\n  exact le_trans (le_mul_self _) (nat.le_add_right _ _)\nend\n\ntheorem unpair_right_le (n : ℕ) : (unpair n).2 ≤ n :=\nby simpa using right_le_mkpair n.unpair.1 n.unpair.2\n\ntheorem mkpair_lt_mkpair_left {a₁ a₂} (b) (h : a₁ < a₂) : mkpair a₁ b < mkpair a₂ b :=\nbegin\n  by_cases h₁ : a₁ < b; simp [mkpair, h₁, add_assoc],\n  { by_cases h₂ : a₂ < b; simp [mkpair, h₂, h],\n    simp at h₂,\n    apply add_lt_add_of_le_of_lt,\n    exact mul_self_le_mul_self h₂,\n    exact lt_add_right _ _ _ h },\n  { simp at h₁,\n    simp [not_lt_of_gt (lt_of_le_of_lt h₁ h)],\n    apply add_lt_add,\n    exact mul_self_lt_mul_self h,\n    apply add_lt_add_right; assumption }\nend\n\ntheorem mkpair_lt_mkpair_right (a) {b₁ b₂} (h : b₁ < b₂) : mkpair a b₁ < mkpair a b₂ :=\nbegin\n  by_cases h₁ : a < b₁; simp [mkpair, h₁, add_assoc],\n  { simp [mkpair, lt_trans h₁ h, h],\n    exact mul_self_lt_mul_self h },\n  { by_cases h₂ : a < b₂; simp [mkpair, h₂, h],\n    simp at h₁,\n    rw [add_comm, add_comm _ a, add_assoc, add_lt_add_iff_left],\n    rwa [add_comm, ← sqrt_lt, sqrt_add_eq],\n    exact le_trans h₁ (nat.le_add_left _ _) }\nend\n\ntheorem mkpair_lt_max_add_one_sq (m n : ℕ) : mkpair m n < (max m n + 1) ^ 2 :=\nbegin\n  rw [mkpair, add_sq, mul_one, two_mul, sq, add_assoc, add_assoc],\n  cases lt_or_le m n,\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 }\nend\n\ntheorem max_sq_add_min_le_mkpair (m n : ℕ) : max m n ^ 2 + min m n ≤ mkpair m n :=\nbegin\n  rw mkpair,\n  cases lt_or_le m n,\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 }\nend\n\ntheorem add_le_mkpair (m n : ℕ) : m + n ≤ mkpair m n :=\n(max_sq_add_min_le_mkpair _ _).trans' $\n  by { rw [sq, ←min_add_max, add_comm, add_le_add_iff_right], exact le_mul_self _ }\n\ntheorem unpair_add_le (n : ℕ) : (unpair n).1 + (unpair n).2 ≤ n :=\n(add_le_mkpair _ _).trans_eq (mkpair_unpair _)\n\nend nat\nopen nat\n\nsection complete_lattice\n\nlemma supr_unpair {α} [complete_lattice α] (f : ℕ → ℕ → α) :\n  (⨆ n : ℕ, f n.unpair.1 n.unpair.2) = ⨆ i j : ℕ, f i j :=\nby rw [← (supr_prod : (⨆ i : ℕ × ℕ, f i.1 i.2) = _), ← nat.surjective_unpair.supr_comp]\n\nlemma infi_unpair {α} [complete_lattice α] (f : ℕ → ℕ → α) :\n  (⨅ n : ℕ, f n.unpair.1 n.unpair.2) = ⨅ i j : ℕ, f i j :=\nsupr_unpair (show ℕ → ℕ → αᵒᵈ, from f)\n\nend complete_lattice\n\nnamespace set\n\nlemma Union_unpair_prod {α β} {s : ℕ → set α} {t : ℕ → set β} :\n  (⋃ n : ℕ, s n.unpair.fst ×ˢ t n.unpair.snd) = (⋃ n, s n) ×ˢ (⋃ n, t n) :=\nby { rw [← Union_prod], convert surjective_unpair.Union_comp _, refl }\n\nlemma Union_unpair {α} (f : ℕ → ℕ → set α) :\n  (⋃ n : ℕ, f n.unpair.1 n.unpair.2) = ⋃ i j : ℕ, f i j :=\nsupr_unpair f\n\nlemma Inter_unpair {α} (f : ℕ → ℕ → set α) :\n  (⋂ n : ℕ, f n.unpair.1 n.unpair.2) = ⋂ i j : ℕ, f i j :=\ninfi_unpair f\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/nat/pairing.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7540087879346399}}
{"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ölzl, 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\n\nopen finsupp finset\n\nnamespace polynomial\nuniverses u v w\nvariables {R : Type u} {S : Type v} { ι : Type w} {a b : R} {m n : ℕ}\n\nsection semiring\nvariables [semiring R] {p q r : polynomial R}\n\nsection degree\n\nlemma nat_degree_comp_le : nat_degree (p.comp q) ≤ 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 ↑(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm\n  ... = _ : congr_arg degree comp_eq_sum_left\n  ... ≤ _ : degree_sum_le _ _\n  ... ≤ _ : sup_le (λ n hn,\n    calc degree (C (coeff p n) * q ^ n)\n        ≤ degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _\n    ... ≤ nat_degree (C (coeff p n)) + n • (degree q) :\n      add_le_add degree_le_nat_degree (degree_pow_le _ _)\n    ... ≤ nat_degree (C (coeff p n)) + n • (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 : ℕ) :\n     by rw [nat_degree_C, with_bot.coe_zero, zero_add, ← with_bot.coe_nsmul,\n       nsmul_eq_mul]; simp\n    ... ≤ (nat_degree p * nat_degree q : ℕ) : 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 : polynomial R} (hp : p ≠ 0) (h : is_root p a) : 0 < degree p :=\nlt_of_not_ge $ λ 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 ≤ n ↔ ∀ N : ℕ, n < N → 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 : polynomial R) :\n  (C a * f).nat_degree ≤ f.nat_degree :=\ncalc\n  (C a * f).nat_degree ≤ (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 : polynomial R) (a : R) :\n  (f * C a).nat_degree ≤ f.nat_degree :=\ncalc\n  (f * C a).nat_degree ≤ 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 ≤ n) (ns : n ∈ 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 [← one_mul p]\n  ... = (C ai * (C a * p)).nat_degree : by rw [← C_1, ← au, ring_hom.map_mul, ← mul_assoc]\n  ... ≤ (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 [← mul_one p]\n  ... = ((p * C a) * C ai).nat_degree : by rw [← C_1, ← au, ring_hom.map_mul, ← mul_assoc]\n  ... ≤ (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 ≠ 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 ≠ 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 ≠ 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 ≠ 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 : polynomial R) :\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\nvariables [semiring S]\n\nlemma nat_degree_pos_of_eval₂_root {p : polynomial R} (hp : p ≠ 0) (f : R →+* S)\n  {z : S} (hz : eval₂ f z p = 0) (inj : ∀ (x : R), f x = 0 → x = 0) :\n  0 < nat_degree p :=\nlt_of_not_ge $ λ hlt, begin\n  have A : p = C (p.coeff 0) := eq_C_of_nat_degree_le_zero hlt,\n  rw [A, eval₂_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₂_root {p : polynomial R} (hp : p ≠ 0) (f : R →+* S)\n  {z : S} (hz : eval₂ f z p = 0) (inj : ∀ (x : R), f x = 0 → x = 0) :\n  0 < degree p :=\nnat_degree_pos_iff_degree_pos.mp (nat_degree_pos_of_eval₂_root hp f hz inj)\n\n@[simp] lemma coe_lt_degree {p : polynomial R} {n : ℕ} :\n  ((n : with_bot ℕ) < degree p) ↔ 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 : polynomial R}\n\nlemma nat_degree_mul_C_eq_of_no_zero_divisors (a0 : a ≠ 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 ≠ 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\nend no_zero_divisors\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/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642528975397, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7540087870004217}}
{"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_cont_on_cl\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 : ℂ → 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 : ℂ → 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 • 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 : ℂ → 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 : ℂ → E` is continuous on a closed annulus `{z | r ≤ |z - c| ≤ R}` and is complex\n  differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)⁻¹ • 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 : ℂ → E` is continuous on a punctured closed disc `{z | |z - c| ≤ R ∧ z ≠ c}`, is\n  complex differentiable on the corresponding punctured open disc, and tends to `y` as `z → c`,\n  `z ≠ c`, then the integral of `(z - c)⁻¹ • f z` over the circle `|z - c| = R` is equal to\n  `2πiy`. 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πif(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 : ℂ → 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)⁻¹ • f z` over the boundary of the disc is equal to `2πif(w)`.\n  Two versions of the lemma put the multiplier `2πi` at the different sides of the equality.\n\n* `complex.has_fpower_series_on_ball_of_differentiable_off_countable`: If `f : ℂ → 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 : ℂ → 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 : ℂ → E` is differentiable\n  on a neighborhood of a point, then it is analytic at this point. In particular, if `f : ℂ → E`\n  is differentiable on the whole `ℂ`, then it is analytic at every point `z : ℂ`.\n\n* `differentiable.has_power_series_on_ball`: If `f : ℂ → 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) → ℝ`),\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 `ℝ × ℝ`).\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 `ℂ → E`, and relate the integral\nof `f` over the boundary of a rectangle in `ℂ` 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 `ℂ`.\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 ≤ |z - c| ≤ 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)⁻¹ • f z` because `f z` belongs to some Banach space over `ℂ` and `f z / (z - c)` is\nundefined.\n\nTaking the limit of this equality as `r` tends to `𝓝[>] 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| ≤ 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) • 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 : ℂ → E` given by `g z = (z - w)⁻¹ • (f z - f w)` if `z ≠ 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 * π * 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 ∈ s`. So, we use\nthe proof outlined in the previous paragraph for `w ∉ 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ᶜ` 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 topology big_operators\n\nnoncomputable theory\n\nuniverses u\n\nvariables {E : Type u} [normed_add_comm_group E] [normed_space ℂ E] [complete_space E]\n\nnamespace complex\n\n/-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at\n`z w : ℂ`, 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 : ℂ → E)\n  (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (s : set ℂ) (hs : s.countable)\n  (Hc : continuous_on f ([z.re, w.re] ×ℂ [z.im, w.im]))\n  (Hd : ∀ x ∈ (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im)) \\ s,\n    has_fderiv_at f (f' x) x)\n  (Hi : integrable_on (λ z, I • f' z 1 - f' z I) ([z.re, w.re] ×ℂ [z.im, w.im])) :\n  (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) +\n    (I • ∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) =\n    ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I :=\nbegin\n  set e : (ℝ × ℝ) ≃L[ℝ] ℂ := equiv_real_prod_clm.symm,\n  have he : ∀ x y : ℝ, ↑x + ↑y * I = e (x, y), from λ x y, (mk_eq_add_mul_I x y).symm,\n  have he₁ : e (1, 0) = 1 := rfl, have he₂ : e (0, 1) = I := rfl,\n  simp only [he] at *,\n  set F : (ℝ × ℝ) → E := f ∘ e,\n  set F' : (ℝ × ℝ) → (ℝ × ℝ) →L[ℝ] E := λ p, (f' (e p)).comp (e : (ℝ × ℝ) →L[ℝ] ℂ),\n  have hF' : ∀ p : ℝ × ℝ, (-(I • F' p)) (1, 0) + F' p (0, 1) = -(I • f' (e p) 1 - f' (e p) I),\n  { rintro ⟨x, y⟩,\n    simp only [continuous_linear_map.neg_apply, continuous_linear_map.smul_apply, F',\n      continuous_linear_map.comp_apply, continuous_linear_equiv.coe_coe, he₁, he₂,\n      neg_add_eq_sub, neg_sub], },\n  set R : set (ℝ × ℝ) := [z.re, w.re] ×ˢ [w.im, z.im],\n  set t : set (ℝ × ℝ) := e ⁻¹' s,\n  rw [uIcc_comm z.im] at Hc Hi, rw [min_comm z.im, max_comm z.im] at Hd,\n  have hR : e ⁻¹' ([z.re, w.re] ×ℂ [w.im, z.im]) = R := rfl,\n  have htc : continuous_on F R, from Hc.comp e.continuous_on hR.ge,\n  have htd : ∀ p ∈ Ioo (min z.re w.re) (max z.re w.re) ×ˢ Ioo (min w.im z.im) (max w.im z.im) \\ t,\n    has_fderiv_at F (F' p) p := λ p hp, (Hd (e p) hp).comp p e.has_fderiv_at,\n  simp_rw [← interval_integral.integral_smul, interval_integral.integral_symm w.im z.im,\n    ← interval_integral.integral_neg, ← hF'],\n  refine (integral2_divergence_prod_of_has_fderiv_within_at_off_countable\n      (λ p, -(I • F p)) F (λ p, - (I • F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective)\n      (htc.const_smul _).neg htc (λ p hp, ((htd p hp).const_smul I).neg) htd _).symm,\n  rw [← (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 : ℂ → E` is continuous on a closed rectangle with opposite corners at\n`z w : ℂ`, 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 : ℂ → E)\n  (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ)\n  (Hc : continuous_on f ([z.re, w.re] ×ℂ [z.im, w.im]))\n  (Hd : ∀ x ∈ (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im)),\n    has_fderiv_at f (f' x) x)\n  (Hi : integrable_on (λ z, I • f' z 1 - f' z I) ([z.re, w.re] ×ℂ [z.im, w.im])) :\n  (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) +\n    (I • ∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) =\n    ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I :=\nintegral_boundary_rect_of_has_fderiv_at_real_off_countable f f' z w ∅ countable_empty Hc\n  (λ x hx, Hd x hx.1) Hi\n\n/-- Suppose that a function `f : ℂ → E` is *real* differentiable on a closed rectangle with opposite\ncorners at `z w : ℂ` 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 : ℂ → E) (z w : ℂ)\n  (Hd : differentiable_on ℝ f ([z.re, w.re] ×ℂ [z.im, w.im]))\n  (Hi : integrable_on (λ z, I • fderiv ℝ f z 1 - fderiv ℝ f z I) ([z.re, w.re] ×ℂ [z.im, w.im])) :\n  (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) +\n    (I • ∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) =\n    ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im,\n      I • fderiv ℝ f (x + y * I) 1 - fderiv ℝ f (x + y * I) I :=\nintegral_boundary_rect_of_has_fderiv_at_real_off_countable f (fderiv ℝ f) z w ∅ countable_empty\n  Hd.continuous_on\n  (λ x hx, Hd.has_fderiv_at $ by simpa only [← mem_interior_iff_mem_nhds,\n    interior_re_prod_im, uIcc, 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 : ℂ → E)\n  (z w : ℂ) (s : set ℂ) (hs : s.countable) (Hc : continuous_on f ([z.re, w.re] ×ℂ [z.im, w.im]))\n  (Hd : ∀ x ∈ (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im)) \\ s,\n    differentiable_at ℂ f x) :\n  (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) +\n    (I • ∫ y : ℝ in z.im..w.im, f (re w + y * I)) -\n      I • ∫ y : ℝ 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  (λ z, (fderiv ℂ f z).restrict_scalars ℝ) z w s hs Hc\n  (λ x hx, (Hd x hx).has_fderiv_at.restrict_scalars ℝ) _).trans _;\n    simp [← 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 : ℂ → E) (z w : ℂ)\n  (Hc : continuous_on f ([z.re, w.re] ×ℂ [z.im, w.im]))\n  (Hd : differentiable_on ℂ f\n    (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im))) :\n  (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) +\n    (I • ∫ y : ℝ in z.im..w.im, f (re w + y * I)) -\n      I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) = 0 :=\nintegral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w ∅ countable_empty\n  Hc $ λ 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 : ℂ → E` is continuous the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ 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)⁻¹ • f z`) over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are\nequal to each other. -/\nlemma circle_integral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable\n  {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : set ℂ} (hs : s.countable)\n  (hc : continuous_on f (closed_ball c R \\ ball c r))\n  (hd : ∀ z ∈ ball c R \\ closed_ball c r \\ s, differentiable_at ℂ f z) :\n  ∮ z in C(c, R), (z - c)⁻¹ • f z = ∮ z in C(c, r), (z - c)⁻¹ • f z :=\nbegin\n  /- We apply the previous lemma to `λ z, f (c + exp z)` on the rectangle\n  `[log r, log R] × [0, 2 * π]`. -/\n  set A := closed_ball c R \\ ball c r,\n  obtain ⟨a, rfl⟩ : ∃ a, real.exp a = r, from ⟨real.log r, real.exp_log h0⟩,\n  obtain ⟨b, rfl⟩ : ∃ b, real.exp b = R, from ⟨real.log R, real.exp_log (h0.trans_le hle)⟩,\n  rw [real.exp_le_exp] at hle,\n  -- Unfold definition of `circle_integral` and cancel some terms.\n  suffices : ∫ θ in 0..2 * π, I • f (circle_map c (real.exp b) θ) =\n    ∫ θ in 0..2 * π, I • f (circle_map c (real.exp a) θ),\n    by simpa only [circle_integral, add_sub_cancel', of_real_exp, ← exp_add, smul_smul,\n      ← 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] ×ℂ [0, 2 * π],\n  set g : ℂ → ℂ := (+) c ∘ exp,\n  have hdg : differentiable ℂ g := differentiable_exp.const_add _,\n  replace hs : (g ⁻¹' s).countable := (hs.preimage (add_right_injective c)).preimage_cexp,\n  have h_maps : maps_to g R A,\n  { rintro z ⟨h, -⟩, simpa [dist_eq, g, abs_exp, hle] using h.symm },\n  replace hc : continuous_on (f ∘ g) R, from hc.comp hdg.continuous.continuous_on h_maps,\n  replace hd : ∀ z ∈ (Ioo (min a b) (max a b) ×ℂ Ioo (min 0 (2 * π)) (max 0 (2 * π))) \\ g ⁻¹' s,\n    differentiable_at ℂ (f ∘ g) z,\n  { refine λ z hz, (hd (g z) ⟨_, hz.2⟩).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, ← exp_add]\n    using integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ ⟨a, 0⟩ ⟨b, 2 * π⟩\n      _ hs hc hd\nend\n\n/-- **Cauchy-Goursat theorem** for an annulus. If `f : ℂ → E` is continuous on the closed annulus\n`r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of\nits interior, then the integrals of `f` over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal\nto each other. -/\nlemma circle_integral_eq_of_differentiable_on_annulus_off_countable\n  {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : set ℂ} (hs : s.countable)\n  (hc : continuous_on f (closed_ball c R \\ ball c r))\n  (hd : ∀ z ∈ ball c R \\ closed_ball c r \\ s, differentiable_at ℂ f z) :\n  ∮ z in C(c, R), f z = ∮ z in C(c, r), f z :=\ncalc ∮ z in C(c, R), f z = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z :\n  (circle_integral.integral_sub_inv_smul_sub_smul _ _ _ _).symm\n... = ∮ z in C(c, r), (z - c)⁻¹ • (z - c) • 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    (λ z hz, (differentiable_at_id.sub_const _).smul (hd z hz))\n... = ∮ 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_{‖z-c‖=R} \\frac{f(z)}{z-c}\\,dz$ is equal to $2πiy`. -/\nlemma circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto\n  {c : ℂ} {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {y : E} {s : set ℂ} (hs : s.countable)\n  (hc : continuous_on f (closed_ball c R \\ {c}))\n  (hd : ∀ z ∈ ball c R \\ {c} \\ s, differentiable_at ℂ f z) (hy : tendsto f (𝓝[{c}ᶜ] c) (𝓝 y)) :\n  ∮ z in C(c, R), (z - c)⁻¹ • f z = (2 * π * I : ℂ) • y :=\nbegin\n  rw [← sub_eq_zero, ← norm_le_zero_iff],\n  refine le_of_forall_le_of_dense (λ ε ε0, _),\n  obtain ⟨δ, δ0, hδ⟩ :\n    ∃ δ > (0 : ℝ), ∀ z ∈ closed_ball c δ \\ {c}, dist (f z) y < ε / (2 * π),\n    from ((nhds_within_has_basis nhds_basis_closed_ball _).tendsto_iff nhds_basis_ball).1 hy _\n      (div_pos ε0 real.two_pi_pos),\n  obtain ⟨r, hr0, hrδ, hrR⟩ : ∃ r, 0 < r ∧ r ≤ δ ∧ r ≤ R :=\n    ⟨min δ R, lt_min δ0 h0, min_le_left _ _, min_le_right _ _⟩,\n  have hsub : closed_ball c R \\ ball c r ⊆ 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 ⊆ ball c R \\ {c},\n    from diff_subset_diff_right (singleton_subset_iff.2 $ mem_closed_ball_self hr0.le),\n  have hzne : ∀ z ∈ sphere c r, z ≠ c,\n    from λ z hz, ne_of_mem_of_not_mem hz (λ h, hr0.ne' $ dist_self c ▸ eq.symm h),\n  /- The integral `∮ z in C(c, r), f z / (z - c)` does not depend on `0 < r ≤ R` and tends to\n  `2πIy` as `r → 0`. -/\n  calc ‖(∮ z in C(c, R), (z - c)⁻¹ • f z) - (2 * ↑π * I) • y‖\n      = ‖(∮ z in C(c, r), (z - c)⁻¹ • f z) - ∮ z in C(c, r), (z - c)⁻¹ • y‖ :\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) (λ z hz, hd z ⟨hsub' hz.1, hz.2⟩) },\n      { simp [hr0.ne'] }\n    end\n  ... = ‖∮ z in C(c, r), (z - c)⁻¹ • (f z - y)‖ :\n    begin\n      simp only [smul_sub],\n      have hc' : continuous_on (λ z, (z - c)⁻¹) (sphere c r),\n        from (continuous_on_id.sub continuous_on_const).inv₀ (λ 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  ... ≤ 2 * π * r * (r⁻¹ * (ε / (2 * π))) :\n    begin\n      refine circle_integral.norm_integral_le_of_norm_le_const hr0.le (λ z hz, _),\n      specialize hzne z hz,\n      rw [mem_sphere, dist_eq_norm] at hz,\n      rw [norm_smul, norm_inv, hz, ← dist_eq_norm],\n      refine mul_le_mul_of_nonneg_left (hδ _ ⟨_, hzne⟩).le (inv_nonneg.2 hr0.le),\n      rwa [mem_closed_ball_iff_norm, hz]\n    end\n  ... = ε : 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 : ℂ → 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πiy`. -/\nlemma circle_integral_sub_center_inv_smul_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 < R)\n  {f : ℂ → E} {c : ℂ} {s : set ℂ} (hs : s.countable)\n  (hc : continuous_on f (closed_ball c R)) (hd : ∀ z ∈ ball c R \\ s, differentiable_at ℂ f z) :\n  ∮ z in C(c, R), (z - c)⁻¹ • f z = (2 * π * I : ℂ) • f c :=\ncircle_integral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs\n  (hc.mono $ diff_subset _ _) (λ z hz, hd z ⟨hz.1.1, hz.2⟩)\n  (hc.continuous_at $ closed_ball_mem_nhds _ h0).continuous_within_at\n\n/-- **Cauchy-Goursat theorem** for a disk: if `f : ℂ → E` is continuous on a closed disk\n`{z | ‖z - c‖ ≤ 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 : ℝ} (h0 : 0 ≤ R) {f : ℂ → E}\n  {c : ℂ} {s : set ℂ} (hs : s.countable) (hc : continuous_on f (closed_ball c R))\n  (hd : ∀ z ∈ ball c R \\ s, differentiable_at ℂ f z) :\n  ∮ 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 ∮ z in C(c, R), f z = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z :\n    (circle_integral.integral_sub_inv_smul_sub_smul _ _ _ _).symm\n  ... = (2 * ↑π * I : ℂ) • (c - c) • 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      (λ 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 ∉ s` while the main lemma drops this assumption. -/\nlemma circle_integral_sub_inv_smul_of_differentiable_on_off_countable_aux {R : ℝ} {c w : ℂ}\n  {f : ℂ → E} {s : set ℂ} (hs : s.countable) (hw : w ∈ ball c R \\ s)\n  (hc : continuous_on f (closed_ball c R)) (hd : ∀ x ∈ ball c R \\ s, differentiable_at ℂ f x) :\n  ∮ z in C(c, R), (z - w)⁻¹ • f z = (2 * π * I : ℂ) • f w :=\nbegin\n  have hR : 0 < R := dist_nonneg.trans_lt hw.1,\n  set F : ℂ → E := dslope f w,\n  have hws : (insert w s).countable := hs.insert w,\n  have hnhds : closed_ball c R ∈ 𝓝 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 ⟨hc, hd _ hw⟩,\n  have hdF : ∀ z ∈ ball (c : ℂ) R \\ (insert w s), differentiable_at ℂ F z,\n    from λ 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 : ∀ z ∈ sphere c R, z ≠ w, from λ z hz, ne_of_mem_of_not_mem hz (ne_of_lt hw.1),\n  have hFeq : eq_on F (λ z, (z - w)⁻¹ • f z - (z - w)⁻¹ • f w) (sphere c R),\n  { intros z hz,\n    calc F z = (z - w)⁻¹ • (f z - f w) : update_noteq (hne z hz) _ _\n    ... = (z - w)⁻¹ • f z - (z - w)⁻¹ • f w : smul_sub _ _ _ },\n  have hc' : continuous_on (λ z, (z - w)⁻¹) (sphere c R),\n    from (continuous_on_id.sub continuous_on_const).inv₀ (λ z hz, sub_ne_zero.2 $ hne z hz),\n  rw [← circle_integral.integral_sub_inv_of_mem_ball hw.1, ← circle_integral.integral_smul_const,\n    ← sub_eq_zero, ← circle_integral.integral_sub, ← 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 : ℂ → 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πi}\\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 : ℝ} {c w : ℂ} {f : ℂ → E} {s : set ℂ} (hs : s.countable) (hw : w ∈ ball c R)\n  (hc : continuous_on f (closed_ball c R)) (hd : ∀ x ∈ ball c R \\ s, differentiable_at ℂ f x) :\n  (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z = f w :=\nbegin\n  have hR : 0 < R := dist_nonneg.trans_lt hw,\n  suffices : w ∈ closure (ball c R \\ s),\n  { lift R to ℝ≥0 using hR.le,\n    have A : continuous_at (λ w, (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • 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₀],\n    simp [real.pi_ne_zero, I_ne_zero] },\n  refine mem_closure_iff_nhds.2 (λ t ht, _),\n  -- TODO: generalize to any vector space over `ℝ`\n  set g : ℝ → ℂ := λ x, w + x,\n  have : tendsto g (𝓝 0) (𝓝 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 ⟨l, u, hlu₀, hlu_sub⟩,\n  obtain ⟨x, hx⟩ : (Ioo l u \\ g ⁻¹' s).nonempty,\n  { refine nonempty_diff.2 (λ hsub, _),\n    have : (Ioo l u).countable,\n      from (hs.preimage ((add_right_injective w).comp of_real_injective)).mono hsub,\n    rw [← cardinal.le_aleph_0_iff_set_countable,\n      cardinal.mk_Ioo_real (hlu₀.1.trans hlu₀.2)] at this,\n    exact this.not_lt cardinal.aleph_0_lt_continuum },\n  exact ⟨g x, (hlu_sub hx.1).1, (hlu_sub hx.1).2, hx.2⟩\nend\n\n/-- **Cauchy integral formula**: if `f : ℂ → 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πif(w)$.\n-/\nlemma circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n  {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : set ℂ} (hs : s.countable) (hw : w ∈ ball c R)\n  (hc : continuous_on f (closed_ball c R)) (hd : ∀ x ∈ ball c R \\ s, differentiable_at ℂ f x) :\n  ∮ z in C(c, R), (z - w)⁻¹ • f z = (2 * π * I : ℂ) • f w :=\nby { rw [← two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n  hs hw hc hd, smul_inv_smul₀], simp [real.pi_ne_zero, I_ne_zero] }\n\n/-- **Cauchy integral formula**: if `f : ℂ → 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πif(w)$. -/\nlemma _root_.diff_cont_on_cl.circle_integral_sub_inv_smul {R : ℝ} {c w : ℂ} {f : ℂ → E}\n  (h : diff_cont_on_cl ℂ f (ball c R)) (hw : w ∈ ball c R) :\n  ∮ z in C(c, R), (z - w)⁻¹ • f z = (2 * π * I : ℂ) • f w :=\ncircle_integral_sub_inv_smul_of_differentiable_on_off_countable countable_empty hw\n  h.continuous_on_ball $ λ x hx, h.differentiable_at is_open_ball hx.1\n\n/-- **Cauchy integral formula**: if `f : ℂ → 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πi}\\oint_{|z-c|=R}(z-w)^{-1}f(z)\\,dz=f(w)$. -/\nlemma _root_.diff_cont_on_cl.two_pi_I_inv_smul_circle_integral_sub_inv_smul {R : ℝ} {c w : ℂ}\n  {f : ℂ → E} (hf : diff_cont_on_cl ℂ f (ball c R)) (hw : w ∈ ball c R) :\n  (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z = f w :=\nbegin\n  have hR : 0 < R := not_le.mp (ball_eq_empty.not.mp (nonempty_of_mem hw).ne_empty),\n  refine two_pi_I_inv_smul_circle_integral_sub_inv_smul_of_differentiable_on_off_countable\n    countable_empty hw _ _,\n  { simpa only [closure_ball c hR.ne.symm] using hf.continuous_on },\n  { simpa only [diff_empty] using λ z hz, hf.differentiable_at is_open_ball hz }\nend\n\n/-- **Cauchy integral formula**: if `f : ℂ → 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πif(w)$. -/\nlemma _root_.differentiable_on.circle_integral_sub_inv_smul {R : ℝ} {c w : ℂ} {f : ℂ → E}\n  (hd : differentiable_on ℂ f (closed_ball c R)) (hw : w ∈ ball c R)  :\n  ∮ z in C(c, R), (z - w)⁻¹ • f z = (2 * π * I : ℂ) • f w :=\n(hd.mono closure_ball_subset_closed_ball).diff_cont_on_cl.circle_integral_sub_inv_smul hw\n\n/-- **Cauchy integral formula**: if `f : ℂ → ℂ` 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 : ℝ} {c w : ℂ} {s : set ℂ}\n  (hs : s.countable) (hw : w ∈ ball c R) {f : ℂ → ℂ} (hc : continuous_on f (closed_ball c R))\n  (hd : ∀ z ∈ ball c R \\ s, differentiable_at ℂ f z) :\n  ∮ z in C(c, R), f z / (z - w) = 2 * π * 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 : ℂ → 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 : ℝ≥0} {c : ℂ} {f : ℂ → E}\n  {s : set ℂ} (hs : s.countable) (hc : continuous_on f (closed_ball c R))\n  (hd : ∀ z ∈ ball c R \\ s, differentiable_at ℂ 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 := λ w hw,\n    begin\n      have hw' : c + w ∈ ball c R,\n        by simpa only [add_mem_ball_iff_norm, ← coe_nnnorm, mem_emetric_ball_zero_iff,\n          nnreal.coe_lt_coe, ennreal.coe_lt_coe] using hw,\n      rw ← 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 : ℂ → 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. -/\nlemma _root_.diff_cont_on_cl.has_fpower_series_on_ball {R : ℝ≥0} {c : ℂ} {f : ℂ → E}\n  (hf : diff_cont_on_cl ℂ f (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_ball\n  (λ z hz, hf.differentiable_at is_open_ball hz.1) hR\n\n/-- If `f : ℂ → 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 : ℝ≥0} {c : ℂ} {f : ℂ → E}\n  (hd : differentiable_on ℂ f (closed_ball c R)) (hR : 0 < R) :\n  has_fpower_series_on_ball f (cauchy_power_series f c R) c R :=\n(hd.mono closure_ball_subset_closed_ball).diff_cont_on_cl.has_fpower_series_on_ball hR\n\n/-- If `f : ℂ → E` is complex differentiable on some set `s`, then it is analytic at any point `z`\nsuch that `s ∈ 𝓝 z` (equivalently, `z ∈ interior s`). -/\nprotected lemma _root_.differentiable_on.analytic_at {s : set ℂ} {f : ℂ → E} {z : ℂ}\n  (hd : differentiable_on ℂ f s) (hz : s ∈ 𝓝 z) : analytic_at ℂ f z :=\nbegin\n  rcases nhds_basis_closed_ball.mem_iff.1 hz with ⟨R, hR0, hRs⟩,\n  lift R to ℝ≥0 using hR0.le,\n  exact ((hd.mono hRs).has_fpower_series_on_ball hR0).analytic_at\nend\n\nlemma _root_.differentiable_on.analytic_on {s : set ℂ} {f : ℂ → E} (hd : differentiable_on ℂ f s)\n  (hs : is_open s) : analytic_on ℂ f s :=\nλ z hz, hd.analytic_at (hs.mem_nhds hz)\n\n/-- A complex differentiable function `f : ℂ → E` is analytic at every point. -/\nprotected lemma _root_.differentiable.analytic_at {f : ℂ → E} (hf : differentiable ℂ f) (z : ℂ) :\n  analytic_at ℂ f z :=\nhf.differentiable_on.analytic_at univ_mem\n\n/-- When `f : ℂ → E` is differentiable, the `cauchy_power_series f z R` represents `f` as a power\nseries centered at `z` in the entirety of `ℂ`, regardless of `R : ℝ≥0`, with  `0 < R`. -/\nprotected lemma _root_.differentiable.has_fpower_series_on_ball {f : ℂ → E}\n  (h : differentiable ℂ f) (z : ℂ) {R : ℝ≥0} (hR : 0 < R) :\n  has_fpower_series_on_ball f (cauchy_power_series f z R) z ∞ :=\n(h.differentiable_on.has_fpower_series_on_ball hR).r_eq_top_of_exists $ λ r hr,\n  ⟨_, h.differentiable_on.has_fpower_series_on_ball hr⟩\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/cauchy_integral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.754008784976814}}
{"text": "import game.order.level09\nimport data.real.basic -- imports the real numbers ℝ\n\nnamespace xena -- hide\n\n-- World name : Sup and Inf\n\n/-\n# Chapter 3 : Sup and Inf\n\n## Level 1 : Upper bounds\n-/\n\n/-\nLet $X$ be a set of real numbers.\n\nWe say a real number $b$ is an *upper bound* for $X$ if every $x \\in X$ is at most $b$.\n-/\n\ndefinition is_upper_bound (S : set ℝ) (x : ℝ) := ∀ s ∈ S, s ≤ x \n\n/-\nHere is an easy fact about upper bounds, which we shall prove below: \nIf $X \\subseteq Y$ are two sets of reals, and $b$ is an upper bound for $Y$, \nthen it's also an upper bound for $X$.\n\nYou can prove this easily in Lean using the `change` tactic. \n-/\n\n/- Lemma\nIf $X \\subseteq Y$ are two sets of reals, and $b$ is an upper bound for $Y$, \nthen it's also an upper bound for $X$.\n-/\nlemma upper_bounds_mono (X Y : set ℝ) (h1 : X ⊆ Y) (b : ℝ) : is_upper_bound Y b → is_upper_bound X b :=\nbegin\n  intro h2,\n  intro a,\n  intro ha,\n  apply h2,\n  change ∀ a, a ∈ X → a ∈ Y at h1,\n--  unfold has_subset.subset set.subset at h1,\n  apply h1,\n  exact ha,\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/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7540087804938433}}
{"text": "import tactic.ring\nimport tactic.pi_instances\nimport analysis.complex.basic\nimport ring_theory.coprime.basic\nimport ring_theory.int.basic\nimport data.complex.basic\nimport analysis.p_series\nimport data.real.nnreal\nimport analysis.special_functions.pow\n\nuniverses u v\n\nopen complex\n\nopen_locale big_operators\n\nnoncomputable theory\n\n\n/-! ### Riemann zeta function -/\n\n\ndef rie (k : ℝ): ℕ → ℝ :=\nλ x, 1/((x: ℝ)^k)\n\n\n/--The `Riemann zeta function` defined on the real numbers.\nIt is defined as the infinite sum of the reciprocals of the naturals to the power `k`. We check it is summable at the end for real `k` greater than 1.-/\n\ndef Riemann_zeta (k : ℝ): ℝ :=\n ∑' (x : ℕ), (rie k x)\n\n\nlemma Riemann_zeta_is_summmable (k: ℝ) (h: 1 < k): summable (rie k):=\nbegin\nrw rie,\n\nhave h2:=nnreal.summable_one_div_rpow.2 h, simp only [one_div, real.summable_nat_rpow_inv], exact h,\nend\n\nlemma int_Riemann_zeta_is_summmable (k: ℤ) (h: 1 < k): summable (rie k):=\nbegin\napply Riemann_zeta_is_summmable, norm_cast, exact h,\nend\n\nlemma Riemann_zeta_pos (k : ℝ) (h: 1 < k) : 0 < Riemann_zeta k :=\nbegin\n  rw Riemann_zeta,\n  apply tsum_pos (Riemann_zeta_is_summmable k h) _ 1,\n  rw rie,\n  simp,\n  intro b,\n  simp_rw rie,\n  simp,\n  apply real.rpow_nonneg_of_nonneg,\n  norm_cast,\n  linarith,\nend\n", "meta": {"author": "CBirkbeck", "repo": "ModularForms", "sha": "9ef5fda326f3d8dd132da5a09ea64cb8b29b82bc", "save_path": "github-repos/lean/CBirkbeck-ModularForms", "path": "github-repos/lean/CBirkbeck-ModularForms/ModularForms-9ef5fda326f3d8dd132da5a09ea64cb8b29b82bc/src/mod_forms/Riemann_zeta_fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.919642533380189, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7540087784702357}}
{"text": "import data.real.basic\n\ndef converges_to (s : ℕ → ℝ) (a : ℝ) :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, abs (s n - a) < ε\n\nopen_locale classical\n\n#check @half_pos\n#check @abs_sub_comm\n#check @abs_sub_le\n#check @add_halves\n\n-- BEGIN\ntheorem converges_to_unique {s : ℕ → ℝ} {a b : ℝ}\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 := abs_pos.mpr (sub_ne_zero_of_ne abne),\n  let ε := abs (a - b) / 2,\n  have εpos : ε > 0 := half_pos this,\n  cases sa ε εpos with Na hNa,\n  cases sb ε εpos with Nb hNb,\n  let N := max Na Nb,\n  have absa : abs (s N - a) < ε := hNa N (le_max_left Na Nb),\n  have absb : abs (s N - b) < ε := hNb N (le_max_right Na Nb),\n  have : abs (a - b) < abs (a - b),\n  { nth_rewrite 1 (by simp : |a - b| = ε + ε),\n    -- OR: nth_rewrite 1 ← add_halves (abs (a - b)),\n    rw abs_sub_comm at absa,\n    linarith only [absa, absb, abs_sub_le a (s N) b], },\n  exact lt_irrefl _ 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/9_Tactics used for classical reasoning/9.1_by_contra/ex4_by_contra_converge_unique.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425289753969, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7540087768823837}}
{"text": "/- Lecture 1.1: Basics — Specifications -/\n\n/- Natural numbers -/\n\nnamespace my_nat\n\ninductive nat\n| zero : nat\n| succ : nat → nat\n\n#check nat\n#check nat.zero\n#check nat.succ\n\n#print nat\n\ndef add : nat → nat → nat\n| m nat.zero     := m\n| m (nat.succ n) := nat.succ (add m n)\n\n#reduce add (nat.succ nat.zero) (nat.succ nat.zero)\n\nlemma add_comm (m n : nat) : add m n = add n m :=\n_\n\nlemma add_assoc (l m n : nat) : add (add l m) n = add l (add m n) :=\n_\n\ndef mul : nat → nat → nat\n| _ nat.zero     := nat.zero\n| m (nat.succ n) := add m (mul m n)\n\n#reduce mul (nat.succ (nat.succ nat.zero)) (nat.succ (nat.succ nat.zero))\n\nlemma mul_comm (m n : nat) : mul m n = mul n m :=\nbegin\ninduction n,\nsimp[mul],\ninduction m,\nsimp[mul],\nrw[m_ih],\nend\n\nlemma mul_assoc (l m n : nat) : mul (mul l m) n = mul l (mul m n) :=\n_\n\nlemma mul_add (l m n : nat) : mul l (add m n) = add (mul l m) (mul l n) :=\n_\n\n#print mul\n#print mul._main\n\n-- illegal\ndef evil : nat → nat\n| n := nat.succ (evil n)\n\nend my_nat\n\ndef power : ℕ → ℕ → ℕ\n| _ 0            := 1\n| m (nat.succ n) := m * power m n\n\n#reduce power 2 5\n\ndef power' (m : ℕ) : ℕ → ℕ\n| 0            := 1\n| (nat.succ n) := m * power' n\n\n#reduce power' 2 5\n\ndef iter (α : Type) (z : α) (f : α → α) : ℕ → α\n| 0            := z\n| (nat.succ n) := f (iter n)\n\n#check iter\n\ndef power'' (m n : ℕ) :=\niter _ 1 (λl, m * l) n\n\n#reduce power'' 2 5\n\n\n/- Lists -/\n\nnamespace my_list\n\ninductive list (α : Type)\n| nil : list\n| cons : α → list → list\n\n#check list.nil\n#check list.cons\n#check @list.cons\n\ndef append (α : Type) : list α → list α → list α\n| (list.nil _)     ys := ys\n| (list.cons x xs) ys := list.cons x (append xs ys)\n\n#check append\n#reduce append _ (list.cons 1 (list.nil _)) (list.cons 2 (list.nil _))\n\ndef append' {α : Type} : list α → list α → list α\n| (list.nil _)     ys := ys\n| (list.cons x xs) ys := list.cons x (append' xs ys)\n\n#check append'\n#reduce append' (list.cons 1 (list.nil _)) (list.cons 2 (list.nil _))\n\nend my_list\n\n#print list\n\ndef reverse {α : Type} : list α → list α\n| []        := []\n| (x :: xs) := reverse xs ++ [x]\n\nlemma reverse_reverse {α : Type} (xs : list α) : reverse (reverse xs) = xs :=\nbegin\ninduction xs,\nrefl,\nrw[<-xs_ih],\nsimp[list.append_assoc]\nend\n\n\nlemma reverse_concat {α: Type} {β: Type} (xs : list α) (ls : list α): reverse (append xs ls) = append (reverse xs) (reverse ls) :=\nbegin \nsimp[append],\nsimp\n\n\nend\n\n/- Some basic types -/\n\n#print bool\n\n#reduce ff || tt\n\n#print prod\n#print sum\n\n#print empty\n\n#check (ℕ → ℕ) → list ℕ → list ℕ\n#check Πα β, (α → β) → list α → list β\n\n\n/- RGB values -/\n\nstructure rgb :=\n(red green blue : ℕ)\n\nstructure rgba extends rgb :=\n(alpha : ℕ)\n\n#print rgb\n#print rgba\n\n#reduce rgb.mk 0xff 0xcc 0xff\n#reduce ({red := 0xff, green := 0xcc, blue := 0xff} : rgb)\n#reduce ({red := 0xff, green := 0xcc, blue := 0xff, alpha := 0x7f} : rgba)\n\ndef red : rgb := {red := 0xff, green := 0x00, blue := 0x00}\ndef semitransparent_red : rgba := {alpha := 0x7f, ..red}\ndef green : rgb := ⟨0x00, 0xff, 0x00⟩\n\n#print red\n#print semitransparent_red\n#print green\n\ndef shuffle (c : rgb) : rgb :=\n{red := c.green, green := c.blue, blue := c.red}\n\nlemma shuffle_shuffle_shuffle (c : rgb) : shuffle (shuffle (shuffle c)) = c :=\nby cases c; refl\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/11_lecture.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7540087750766539}}
{"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\nInstantiate the complex numbers as a normed space, by temporarily making it an inner product space\nover the reals.\n-/\nimport theories.analysis.inner_product data.complex\nopen nat real complex analysis classical\nnoncomputable theory\n\nnamespace complex\n  namespace real_inner_product_space\n    definition smul (a : ℝ) (z : ℂ) : ℂ := complex.mk (a * re z) (a * im z)\n\n    definition ip (z w : ℂ) : ℝ := re z * re w + im z * im w\n\n    proposition smul_left_distrib (a : ℝ) (z w : ℂ) : smul a (z + w) = smul a z + smul a w :=\n    by rewrite [↑smul, *re_add, *im_add, *left_distrib]\n\n    proposition smul_right_distrib (a b : ℝ) (z : ℂ) : smul (a + b) z = smul a z + smul b z :=\n    by rewrite [↑smul, *right_distrib]\n\n    proposition mul_smul (a b : ℝ) (z : ℂ) : smul (a * b) z = smul a (smul b z) :=\n    by rewrite [↑smul, *mul.assoc]\n\n    proposition one_smul (z : ℂ) : smul 1 z = z := by rewrite [↑smul, *one_mul, complex.eta]\n\n    proposition inner_add_left (x y z : ℂ) : ip (x + y) z = ip x z + ip y z :=\n    by rewrite [↑ip, re_add, im_add, *right_distrib, *add.assoc, add.left_comm (re y * re z)]\n\n    proposition inner_smul_left (a : ℝ) (x y : ℂ) : ip (smul a x) y = a * ip x y :=\n    by rewrite [↑ip, ↑smul, left_distrib, *mul.assoc]\n\n    proposition inner_comm (x y : ℂ) : ip x y = ip y x :=\n    by rewrite [↑ip, mul.comm, mul.comm (im x)]\n\n    proposition inner_self_nonneg (x : ℂ) : ip x x ≥ 0 :=\n    add_nonneg (mul_self_nonneg (re x)) (mul_self_nonneg (im x))\n\n    proposition eq_zero_of_inner_self_eq_zero {x : ℂ} (H : ip x x = 0) : x = 0 :=\n    have re x = 0, from eq_zero_of_mul_self_add_mul_self_eq_zero H,\n    have im x = 0, from eq_zero_of_mul_self_add_mul_self_eq_zero\n                         (by rewrite [↑ip at H, add.comm at H]; exact H),\n    by rewrite [-complex.eta, `re x = 0`, `im x = 0`]\n  end real_inner_product_space\n\n  protected definition real_inner_product_space [reducible] : inner_product_space ℂ :=\n  ⦃ inner_product_space, complex.discrete_field,\n    smul               := real_inner_product_space.smul,\n    inner              := real_inner_product_space.ip,\n    smul_left_distrib  := real_inner_product_space.smul_left_distrib,\n    smul_right_distrib := real_inner_product_space.smul_right_distrib,\n    mul_smul           := real_inner_product_space.mul_smul,\n    one_smul           := real_inner_product_space.one_smul,\n    inner_add_left     := real_inner_product_space.inner_add_left,\n    inner_smul_left    := real_inner_product_space.inner_smul_left,\n    inner_comm         := real_inner_product_space.inner_comm,\n    inner_self_nonneg  := real_inner_product_space.inner_self_nonneg,\n    eq_zero_of_inner_self_eq_zero := @real_inner_product_space.eq_zero_of_inner_self_eq_zero\n  ⦄\n\n  local attribute complex.real_inner_product_space [trans_instance]\n\n  protected definition normed_vector_space [trans_instance] : normed_vector_space ℂ :=\n  _\n\n  theorem norm_squared_eq_cmod (z : ℂ) : ∥ z ∥^2 = cmod z := by rewrite norm_squared\nend complex\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/complex_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7538675512331019}}
{"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 logic.function.iterate\nimport tactic.ring\n\n/-!\n# The Fibonacci Sequence\n\n## Summary\n\nDefinition of the Fibonacci sequence `F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`.\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ₙ₊₂ = Fₙ + Fₙ₊₁.`.\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 : ℕ) : ℕ := ((λ p : ℕ × ℕ, (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ₙ₊₂ = Fₙ + Fₙ₊₁.` -/\nlemma fib_add_two {n : ℕ} : fib (n + 2) = fib n + fib (n + 1) :=\nby simp only [fib, function.iterate_succ']\n\nlemma fib_le_fib_succ {n : ℕ} : fib n ≤ fib (n + 1) := by { cases n; simp [fib_add_two] }\n\n@[mono] lemma fib_mono : monotone fib :=\nmonotone_nat_of_le_succ $ λ _, fib_le_fib_succ\n\nlemma fib_pos {n : ℕ} (n_pos : 0 < n) : 0 < fib n :=\ncalc 0 < fib 1 : dec_trivial\n   ... ≤ fib n : fib_mono n_pos\n\nlemma fib_lt_fib_succ {n : ℕ} (hn : 2 ≤ n) : fib n < fib (n + 1) :=\nbegin\n  rcases le_iff_exists_add.1 hn with ⟨n, rfl⟩,\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 (λ n, fib (n + 2)) :=\nbegin\n  refine strict_mono_nat_of_lt_succ (λ n, _),\n  rw add_right_comm,\n  exact fib_lt_fib_succ (self_le_add_left _ _)\nend\n\nlemma le_fib_self {n : ℕ} (five_le_n : 5 ≤ n) : n ≤ fib n :=\nbegin\n  induction five_le_n with n five_le_n IH,\n  { -- 5 ≤ fib 5\n    refl },\n  { -- n + 1 ≤ fib (n + 1) for 5 ≤ n\n    rw succ_le_iff,\n    calc n ≤ 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 : ℕ) : 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 : ℕ) :\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, ← ih],\n    ring, }\nend\n\n\nlemma gcd_fib_add_self (m n : ℕ) : 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 [← 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_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 : ℕ) : ∀ k, gcd (fib m) (fib (n + k * m)) = gcd (fib m) (fib n)\n| 0     := by simp\n| (k+1) := by rw [← gcd_fib_add_mul_self k, add_mul, ← 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 : ℕ) (h : m ∣ n) : fib m ∣ fib n :=\nby rwa [gcd_eq_left_iff_dvd, ← fib_gcd, gcd_eq_left_iff_dvd.mp]\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/fib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7538675509632335}}
{"text": "/-\nThis modules defines a type for representing integers modulo a natural number n,\nalong with the standard commutative ring operations.\n\nThe representation uses a canonical form of numbers between 0 and n-1.  Operations\npreserve the canonical form.\n-/\nimport galois.nat.div_lemmas\n\ndef intmod (n:ℕ) := { x : ℕ // x < n }\n\nnamespace intmod\n\nopen nat\n\nvariable {n : nat}\n\ndef of_nat (x:ℕ) : intmod (succ n) :=\n ⟨ x % succ n, nat.mod_lt x (nat.zero_lt_succ _) ⟩\n\nprivate lemma mlt {b : nat} : ∀ {a}, n > a → 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\ndef zero : intmod (succ n) := ⟨ 0, nat.succ_pos n ⟩\ndef one  : intmod (succ n) := of_nat 1\ndef add  : intmod n → intmod n → intmod n\n| ⟨x,x_lt⟩ ⟨y,y_lt⟩ :=\n  if p:x+y < n then\n    ⟨x+y, p⟩\n  else\n    let q : (x+y)-n < n :=\n         begin\n           simp [nat.sub_lt_iff'],\n           have xy_lt_nn : x + y < n + n := add_lt_add x_lt y_lt,\n           have n_le_xy  : n ≤ x + y := le_of_not_gt p,\n           cc,\n         end in\n    ⟨ (x+y)-n, q⟩\n\ndef neg  : intmod n → intmod n\n| ⟨x,p⟩ :=\n  let r := if x = 0 then 0 else n-x in\n  let q : (if x = 0 then 0 else n-x) < n :=\n    begin\n      by_cases x = 0,\n      { simp [h],\n        simp [h] at p,\n        exact p,\n      },\n      {\n        -- Show x > 0\n        have x_pos := nat.eq_zero_or_pos x,\n        simp [h] at x_pos,\n        -- show n - x < n\n        simp [h, nat.sub_lt_iff'],\n        -- Decompose and\n        constructor,\n        -- n < n + x\n        exact lt_add_of_le_of_pos (le_refl n) x_pos,\n        -- show 0 < n\n        exact or.inr (lt_trans x_pos p),\n      }\n    end in\n  ⟨r, q ⟩\n\ndef sub  : intmod n → intmod n → intmod n\n| ⟨x,h⟩ ⟨y,y_lt⟩ :=\n  if p : y ≤ x then\n    let q : x - y < n :=\n      begin\n        apply nat.lt_of_le_of_lt,\n        apply nat.sub_le,\n        exact h,\n      end in\n    ⟨ x-y, q ⟩\n  else\n    let q : x + n - y < n :=\n          begin\n            --have p : x < y := sorry,\n            simp [nat.sub_lt_iff'],\n            constructor,\n            { apply add_lt_add_left,\n              -- Enforce h := x < y\n              exact lt_of_not_ge p,\n            },\n            { -- Pick right branch to prove y ≤ n + x\n              apply or.inr,\n              transitivity,\n              exact nat.le_of_lt y_lt,\n              apply nat.le_add_right,\n            }\n          end  in\n    ⟨ x+n-y, q ⟩\n\ndef mul : intmod n → intmod n → intmod n\n| ⟨x,h⟩ ⟨y,_⟩ := ⟨(x*y)%n, mlt h ⟩\n\ninstance (n:ℕ) : has_zero (intmod (succ n)) := ⟨ zero ⟩\ninstance (n:ℕ) : has_one  (intmod (succ n)) := ⟨ one ⟩\ninstance (n:ℕ) : has_add  (intmod n) := ⟨ add ⟩\ninstance (n:ℕ) : has_neg  (intmod n) := ⟨ neg ⟩\ninstance (n:ℕ) : has_sub  (intmod n) := ⟨ sub ⟩\ninstance (n:ℕ) : has_mul  (intmod n) := ⟨ mul ⟩\n\ntheorem zero_val (n : ℕ) : (0 : intmod (succ n)).val = 0 := rfl\n\ntheorem one_val (n : ℕ) : (1 : intmod (succ n)).val = 1 % succ n := rfl\n\ntheorem add_val (x y : intmod n) : (x + y).val = (x.val + y.val) % n :=\nbegin\n  cases x with xv x_lt,\n  cases y with yv y_lt,\n  transitivity,\n  unfold has_add.add,\n  by_cases (xv + yv < n) with p,\n  {\n    simp [add, p, nat.mod_eq_of_lt],\n  },\n  {\n    -- Show xv + yv ≥ n\n    have q : xv + yv ≥ n :=\n      or.resolve_left (nat.lt_or_ge (xv + yv) n) p,\n    have r : (xv + yv - n) < n,\n    { simp [nat.sub_lt_iff'],\n      constructor,\n      {\n        transitivity,\n        exact nat.add_lt_add_left  y_lt _,\n        exact nat.add_lt_add_right x_lt _,\n      },\n      -- Show n ≤ x + y\n      exact or.inr q,\n    },\n    simp [add, mod_eq_sub_mod,  mod_eq_of_lt, *],\n  },\nend\n\ntheorem mul_val (x y : intmod n) : (x * y).val = (x.val * y.val) % n :=\nbegin\n  cases x with xv xp,\n  cases y with yv yp,\n  refl,\nend\n\ntheorem zero_add (x : intmod (succ n)) : 0 + x = x :=\nbegin\n  apply subtype.eq,\n  simp [add_val, zero_val],\n  exact nat.mod_eq_of_lt x.property,\nend\n\ntheorem add_zero (x : intmod (succ n)) : x + 0 = x :=\nbegin\n  apply subtype.eq,\n  simp [add_val, zero_val],\n  exact nat.mod_eq_of_lt x.property,\nend\n\ntheorem add_assoc (x y z : intmod n) : (x + y) + z = x + (y + z) :=\nbegin\n  apply subtype.eq,\n  simp [add_val, nat.mod_add_right_mod],\nend\n\ntheorem add_comm (x y : intmod n) : x + y = y + x :=\nbegin\n  apply subtype.eq,\n  simp [add_val],\nend\n\n theorem add_left_neg (x : intmod (succ n)) : -x + x = 0 :=\n begin\n   cases x with xv x_lt,\n\n   apply subtype.eq,\n   simp [add_val, has_neg.neg, neg],\n   by_cases (xv = 0) with h,\n   {\n      simp [h, zero_val],\n   },\n   {\n     have x_le : xv ≤ succ n := nat.le_of_lt x_lt,\n     simp only [h, if_false, nat.add_comm xv, ge, *, nat.sub_add_cancel],\n     simp [nat.mod_eq_sub_mod, zero_val],\n   }\n end\n\ntheorem one_mul (x : intmod (succ n)) : 1 * x = x :=\nbegin\n  apply subtype.eq,\n  simp [mul_val, one_val, nat.mod_mul_left_mod, nat.mod_mul_right_mod],\n  exact nat.mod_eq_of_lt x.property,\nend\n\ntheorem mul_one (x : intmod (succ n)) : x * 1 = x :=\nbegin\n  apply subtype.eq,\n  simp [mul_val, one_val, nat.mod_mul_left_mod, nat.mod_mul_right_mod],\n  exact nat.mod_eq_of_lt x.property,\nend\n\ntheorem mul_assoc (x y z : intmod n) : (x * y) * z = x * (y * z) :=\nbegin\n  apply subtype.eq,\n  simp [mul_val, nat.mod_mul_right_mod],\nend\n\ntheorem mul_comm (x y : intmod n) : x * y = y * x :=\nbegin\n  apply subtype.eq,\n  simp [mul_val],\nend\n\ntheorem left_distrib (a b c : intmod n)\n: a * (b + c) = a * b + a * c :=\nbegin\n  apply subtype.eq,\n  simp [add_val, mul_val],\n  simp [nat.mod_add_right_mod,\n        nat.mod_mul_right_mod,\n        nat.left_distrib],\nend\n\ntheorem right_distrib (a b c : intmod n)\n: (a + b) * c = a * c + b * c :=\nbegin\n  simp only [mul_comm _ c, left_distrib],\nend\n\ninstance (n:ℕ) : comm_ring (intmod (succ n)) :=\n{ zero := 0\n, one  := 1\n, add := add\n, neg := neg\n, mul := mul\n, zero_add := zero_add\n, add_zero := add_zero\n, add_assoc := add_assoc\n, add_comm  := add_comm\n, add_left_neg := add_left_neg\n, one_mul   := one_mul\n, mul_one   := mul_one\n, mul_assoc := mul_assoc\n, mul_comm  := mul_comm\n, left_distrib  := left_distrib\n, right_distrib := right_distrib\n}\n\nend intmod\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/intmod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7538675407918866}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\n/-!\n# Advanced Proposition world\n\n## Level 1: the `constructor` tactic.\n\nThe logical symbol `∧` means \"and\". If `P` and `Q` are propositions, then `P ∧ Q` is the proposition\n\"`P` and `Q`\". If your *goal* is `P ∧ Q` then you can make progress with the [`constructor` tactic](../Tactics/constructor.lean.md).,\nwhich turns one goal `⊢ P ∧ Q` into two goals, namely `⊢ P` and `⊢ Q`. In the level below, after a\n`constructor`, you can finish off the two new sub-goals with the `exact` tactic since both `p` and\n`q` provide exactly what we need.  You could also use the `assumption` tactic.\n\n## Lemma\nIf `P` and `Q` are true, then `P ∧ Q` is true.\n-/\nexample (P Q : Prop) (p : P) (q : Q) : P ∧ Q := by\n  constructor\n  exact p\n  exact q\n/-!\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/AdvancedPropositionWorld/Level1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.7538675327627561}}
{"text": "import data.fintype.basic\nimport tactic\nimport matroid\nimport finset\nimport base_of\n\nvariables {α : Type*} [fintype α] [decidable_eq α] {m : matroid α} {A B: finset α}\n\nopen finset\n\nnamespace matroid\n\nlemma base_eq_card (hA : m.base A) (hB : m.base B) : A.card = B.card := \n  by {rw [←base_of_univ_iff_base] at *, exact base_of_eq_card hA hB} \n\nlemma ind_subset_base : m.ind A → ∃ B, A ⊆ B ∧ m.base B := λ hA, begin\n  obtain ⟨B, hAB, h_base⟩ := ind_subset_base_of (subset_univ A) hA,\n  rw base_of_univ_iff_base at h_base,\n  use [B, hAB, h_base],\nend\n\ntheorem exists_base : ∃ A, m.base A := \nbegin\n  obtain ⟨B, _, Bbase⟩ := ind_subset_base m.ind_empty,\n  exact ⟨B, Bbase⟩,\nend\n\ntheorem base_not_subset {A B} : m.base A → m.base B → A ⊆ B → A = B :=\nbegin\n  rintro Abase Bbase h_subset,\n  exact eq_of_subset_of_card_le h_subset (ge_of_eq $ base_eq_card Abase Bbase),\nend\n\nlemma ind_and_card_eq_card_base_iff_base {A B} (Abase : m.base A) : (m.ind B ∧ A.card = B.card) ↔ m.base B :=\nbegin\n  split, {\n    rintro ⟨Bind, Acard⟩,\n    use Bind,\n    intros x xB h_insert_ind,\n    obtain ⟨C, Bsubset, Cbase⟩ := ind_subset_base h_insert_ind,\n    replace Bsubset := card_le_of_subset Bsubset,\n    rw [base_eq_card Abase Cbase] at Acard,\n    rw card_insert_of_not_mem xB at Bsubset,\n    linarith,\n  }, {\n    intro Bbase,\n    exact ⟨Bbase.1, base_eq_card Abase Bbase⟩,\n  }\nend\n\ntheorem base_exchange {A B} : m.base A → m.base B → A ≠ B → ∀ x ∈ A \\ B, ∃ b ∈ B, b ∉ A ∧ m.base (insert b (A.erase x)) :=\nbegin\n  intros Abase Bbase h_neq x xA,\n  rcases m.ind_exchange (A.erase x) B _ Bbase.1 _ with ⟨c, cB, cA, cinsert⟩,\n  use [c, cB],\n  {\n    rw mem_sdiff at xA,\n    split, {\n      finish,\n    }, {\n      apply (ind_and_card_eq_card_base_iff_base Abase).1,\n      use cinsert,\n      rw [card_insert_of_not_mem cA, card_erase_of_mem' xA.1],\n    },\n  }, { \n    exact m.ind_subset _ _ (erase_subset _ _) Abase.1, \n  }, {\n    rw mem_sdiff at xA,\n    rw [← base_eq_card Abase Bbase, card_erase_of_mem xA.1],\n    exact nat.pred_lt (card_ne_zero_of_mem xA.1),\n  },\nend\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/base.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505248181418, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7538675268758422}}
{"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 : ℕ) : ¬ 2 ∣ mersenne (k + 1) :=\nby simp [← even_iff_two_dvd, ← nat.even_succ, nat.succ_eq_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 : ℕ) : σ 1 (2 ^ k) = mersenne (k + 1) :=\nby simpa [mersenne, prime_two, ← geom_sum_mul_add 1 (k+1)]\n\n\n/-- Euclid's theorem that Mersenne primes induce perfect numbers -/\ntheorem perfect_two_pow_mul_mersenne_of_prime (k : ℕ) (pr : (mersenne (k + 1)).prime) :\n  perfect ((2 ^ k) * mersenne (k + 1)) :=\nbegin\n  rw [perfect_iff_sum_divisors_eq_two_mul, ← mul_assoc, ← pow_succ, ← 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] },\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 : ℕ) (pr : (mersenne (k + 1)).prime) :\n  k ≠ 0 :=\nbegin\n  rintro rfl,\n  simpa [mersenne, not_prime_one] using pr,\nend\n\ntheorem even_two_pow_mul_mersenne_of_prime (k : ℕ) (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 : ℕ} (hpos : 0 < n) :\n  ∃ (k m : ℕ), n = 2 ^ k * m ∧ ¬ even m :=\nbegin\n  have h := (multiplicity.finite_nat_iff.2 ⟨nat.prime_two.ne_one, hpos⟩),\n  cases multiplicity.pow_multiplicity_dvd h with m hm,\n  use [(multiplicity 2 n).get h, m],\n  refine ⟨hm, _⟩,\n  rw even_iff_two_dvd,\n  have hg := multiplicity.is_greatest' h (nat.lt_succ_self _),\n  contrapose! hg,\n  rcases hg with ⟨k, rfl⟩,\n  apply dvd.intro k,\n  rw [pow_succ', mul_assoc, ← hm],\nend\n\n/-- 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 : ℕ} (ev : even n) (perf : perfect n) :\n  ∃ (k : ℕ), prime (mersenne (k + 1)) ∧ n = 2 ^ k * mersenne (k + 1) :=\nbegin\n  have hpos := perf.2,\n  rcases eq_two_pow_mul_odd hpos with ⟨k, m, rfl, hm⟩,\n  use k,\n  rw [perfect_iff_sum_divisors_eq_two_mul hpos, ← 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, ← mul_assoc, ← 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 ⟨j, rfl⟩,\n  rw [← mul_assoc, mul_comm _ (mersenne _), mul_assoc] at perf,\n  have h := mul_left_cancel' (ne_of_gt (mersenne_pos (nat.succ_pos _))) perf,\n  rw [sigma_one_apply, sum_divisors_eq_sum_proper_divisors_add_self, ← 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 [← one_mul j, ← mul_assoc, mul_one] at jcon,\n    have jcon2 := mul_right_cancel' _ jcon,\n    { exfalso,\n      cases k,\n      { apply hm,\n        rw [← jcon2, pow_zero, one_mul, one_mul] at ev,\n        rw [← jcon2, one_mul],\n        exact ev },\n      apply ne_of_lt _ jcon2,\n      rw [mersenne, ← nat.pred_eq_sub_one, lt_pred_iff, ← 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 : ℕ} :\n  (even n ∧ perfect n) ↔ ∃ (k : ℕ), prime (mersenne (k + 1)) ∧ n = 2 ^ k * mersenne (k + 1) :=\nbegin\n  split,\n  { rintro ⟨ev, perf⟩,\n    exact eq_two_pow_mul_prime_mersenne_of_even_perfect ev perf },\n  { rintro ⟨k, pr, rfl⟩,\n    exact ⟨even_two_pow_mul_mersenne_of_prime k pr, perfect_two_pow_mul_mersenne_of_prime k pr⟩ }\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/archive/100-theorems-list/70_perfect_numbers.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7538594393827422}}
{"text": "import data.finset\nimport data.fin\nimport data.rat\nimport data.nat.basic\nimport data.fintype\nimport algebra.big_operators\nimport algebra.group_power\nimport tactic.omega\nimport tactic.linarith\n\nopen fintype\n\nvariables {X : Type*}\nvariables [fintype X] [decidable_eq X]\nvariables {r : ℕ}\n\n/- \nDefine a type for rsets, give an easy constructor of rsets and a lemma for their cardinality. \nAlso, we can use extensionality on them, and they're a finite type with cardinality a binomial.\n-/\nsection rset\n  @[reducible] def rset (r : ℕ) (X) [fintype X] := {x : finset X // x ∈ finset.powerset_len r (elems X)}\n\n  @[reducible]\n  def rset_mk (A : finset X) (H : finset.card A = r) : rset r X := \n  begin\n    refine ⟨A, _⟩,\n    rw finset.mem_powerset_len,\n    exact ⟨finset.subset_univ _, H⟩\n  end\n\n  @[simp] lemma card_of_rset {x : rset r X} : finset.card x.val = r := (finset.mem_powerset_len.1 x.2).2\n\n  @[reducible] instance : has_mem X (rset r X) := ⟨λ i A, i ∈ A.1⟩\n\n  theorem eq_of_veq : ∀ {s t : rset r X}, s.1 = t.1 → s = t\n  | ⟨s, _⟩ ⟨t, _⟩ rfl := rfl\n\n  theorem val_inj {s t : rset r X} : s.1 = t.1 ↔ s = t :=\n  ⟨eq_of_veq, congr_arg _⟩\n\n  theorem ext {s₁ s₂ : rset r X} : s₁ = s₂ ↔ (∀ a, a ∈ s₁ ↔ a ∈ s₂) :=\n  val_inj.symm.trans finset.ext\n\n  @[ext]\n  theorem ext' {s₁ s₂ : rset r X} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ :=\n  ext.2\n\n  instance rset_fintype (r : ℕ) : fintype (rset r X) := finset.subtype.fintype _\n\n  theorem rset_card (r : ℕ) : card (rset r X) = nat.choose (card X) r := \n  begin\n    rw card_of_subtype (finset.powerset_len r (elems X)) (λ _, iff.rfl),\n    apply finset.card_powerset_len\n  end\nend rset\n\n-- An example of an rset, and a set system.\n#eval elems (rset 3 (fin 5))\n\ndef example1 : rset 4 (fin 9) := rset_mk {0,1,4,5} (by trivial)\ndef example2 : finset (rset 3 (fin 5)) := \n{ rset_mk {0,1,2} (by trivial),\n  rset_mk {0,1,3} (by trivial),\n  rset_mk {0,2,3} (by trivial),\n  rset_mk {0,2,4} (by trivial)\n  }\n\n#eval example1\n#eval example2\n\nsection stretch_and_erase\n  def stretch (A : rset r X) (s : X) (h : s ∉ A) : rset (r+1) X := \n  rset_mk (insert s (A.1)) $ by rw [finset.card_insert_of_not_mem h, card_of_rset]\n\n  lemma mem_stretch (A : rset r X) (s : X) {h : s ∉ A} (i : X) : i ∈ stretch A s h ↔ i ∈ A ∨ i = s := \n  by rw [stretch, finset.mem_insert]; tauto\n\n  lemma stretch_subset {A : rset r X} {s : X} (h : s ∉ A) : A.1 ⊆ (stretch A s h).1 := \n  finset.subset_insert _ _\n\n  lemma mem_stretch_self {A : rset r X} {s : X} (h : s ∉ A) : s ∈ stretch A s h := \n  finset.mem_insert_self _ _\n\n  lemma mem_stretch_of_mem {A : rset r X} {s t : X} {p : s ∉ A} : t ∈ A → t ∈ stretch A s p := \n  finset.mem_insert_of_mem\n\n\n  def erase (A : rset (r+1) X) (s : X) (h : s ∈ A) : rset r X :=\n  rset_mk (finset.erase (A.1) s) $ by rw [finset.card_erase_of_mem h, card_of_rset]; trivial\n\n  lemma mem_erase (A : rset (r+1) X) (s : X) (h : s ∈ A) (i : X) : i ∈ erase A s h ↔ i ∈ A ∧ i ≠ s :=\n  by rw [erase, finset.mem_erase]; tauto\n\n  lemma mem_of_mem_erase {A : rset (r+1) X} {i s : X} {h : s ∈ A} : i ∈ erase A s h → i ∈ A :=\n  finset.mem_of_mem_erase\n\n  lemma subset_erase {A : rset (r+1) X} {s : X} (h : s ∈ A) : (erase A s h).1 ⊆ A.1 :=\n  finset.erase_subset _ _\n\n  theorem not_mem_erase_self {A : rset (r+1) X} {s : X} (h : s ∈ A) : s ∉ erase A s h := \n  finset.not_mem_erase _ _\n\n\n  lemma erase_iff_stretch {A : rset r X} {B : rset (r+1) X} {s : X} {H1 : s ∉ A} {H2 : s ∈ B} : stretch A s H1 = B ↔ erase B s H2 = A:=\n  begin\n    split,\n    all_goals {intros p, ext, rw mem_erase <|> rw mem_stretch, split},\n    all_goals {intro k, rw ← p at *},\n    { rw mem_stretch at k, finish },\n    { split, apply mem_stretch_of_mem k, intro i, exact H1 (i ▸ k) },\n    { cases k, exact mem_of_mem_erase k, exact (k.symm ▸ H2) },\n    { rw mem_erase, finish }\n  end\n\n  lemma erase_stretch (A : rset r X) (s : X) (h : s ∉ A) : erase (stretch A s h) s (mem_stretch_self h) = A := \n  erase_iff_stretch.1 rfl\n\n  lemma stretch_erase (A : rset (r+1) X) (s : X) (h : s ∈ A) : stretch (erase A s h) s (not_mem_erase_self h) = A := \n  erase_iff_stretch.2 rfl\n\n  lemma erase_iff_stretch' {A : rset r X} {B : rset (r+1) X} : (∃ i ∉ A, stretch A i H = B) ↔ (∃ i ∈ B, erase B i H = A) := \n  begin\n    split,\n    all_goals \n    { rintro ⟨i, Hi, t⟩, use i, refine ⟨_, _⟩, rw ← t,\n      any_goals {apply mem_stretch_self <|> apply not_mem_erase_self},\n      any_goals {rw erase_iff_stretch <|> rw ← erase_iff_stretch},\n      exact t }\n  end\nend stretch_and_erase\n\nlemma card_map {α β} [decidable_eq β] {f : α ↪ β} {s : finset α} : (s.map f).card = s.card := \nbegin\n  rw finset.map_eq_image,\n  rw finset.card_image_of_injective,\n  exact f.2\nend\n\ndef all_removals {r : ℕ} (A : rset (r+1) X) : finset (rset r X) :=\nA.1.attach.map ⟨λ i, erase A i.1 i.2, -- prove the function is injective\n  begin\n    rintro ⟨x1, x1p⟩ ⟨x2, x2p⟩ _, congr, dsimp at a,\n    have m : x1 ∉ erase A x1 _ := not_mem_erase_self x1p,\n    rw [a, mem_erase] at m, by_contra, apply m, tauto\n  end\n⟩\n\ndef mem_all_removals {r : ℕ} {A : rset (r+1) X} {B : rset r X} : B ∈ all_removals A ↔ ∃ i ∈ A, erase A i H = B :=\nby simp [all_removals]\n\nlemma card_all_removals {r : ℕ} {A : rset (r+1) X} : (all_removals A).card = r + 1 :=\nby rw [all_removals, card_map, finset.card_attach]; exact card_of_rset\n\ndef shadow {r : ℕ} (𝒜 : finset (rset (r+1) X)) : finset (rset r X) := \n𝒜.bind all_removals\n\nreserve prefix `∂`:30\nnotation ∂𝒜 := shadow 𝒜\n\n#eval ∂example2 -- should be {{0,1}, {0,2}, {0,3}, {0,4}, {1,2}, {1,3}, {2,3}, {2,4}}\n\ndef mem_shadow {r : ℕ} {𝒜 : finset (rset (r+1) X)} (B : rset r X) : B ∈ ∂𝒜 ↔ ∃ A ∈ 𝒜, ∃ i ∈ A, erase A i H = B := \nby simp [shadow, all_removals]\n\ndef cube_graph : rel (rset r X) (rset (r+1) X) := λ A B, A.1 ⊆ B.1\n\nlemma test {A : rset r X} {B : rset (r+1) X} : finset.card (B.1 \\ A.1) = 1 ↔ cube_graph A B := \nbegin\n  rw cube_graph, dsimp,\n  rw [← finset.sdiff_eq_empty_iff_subset, ← finset.card_eq_zero],\n  have q: finset.card A.1 + finset.card (B.1 \\ A.1) = finset.card B.1 + finset.card (A.1 \\ B.1),\n    rw [← finset.card_disjoint_union (finset.disjoint_sdiff), \n        ← finset.card_disjoint_union (finset.disjoint_sdiff), \n        finset.union_sdiff_symm], \n  simp [card_of_rset] at q,\n  rw [q, nat.one_add, nat.succ_inj']\nend\n\nlemma stretch_iff_related {A : rset r X} {B : rset (r+1) X} : cube_graph A B ↔ ∃ (i ∉ A), stretch A i H = B := \nbegin\n  rw cube_graph,\n  split, intro p,\n    cases finset.card_eq_one.1 (test.2 p) with i _, \n    use i,\n    have k' : ∀ a, a ∈ B ∧ a ∉ A ↔ a = i,\n      intro a,\n      rw [← finset.mem_sdiff, ← finset.mem_singleton, h], \n    have k : i ∈ B ∧ i ∉ A := (k' i).2 rfl,\n    use k.2, ext, rw mem_stretch,\n    refine ⟨λ s, s.elim _ (λ v, v.symm ▸ k.1), λ s, _⟩,\n      apply p, \n    safe,\n  rintros ⟨_, _, k⟩,\n  rw ← k,\n  apply stretch_subset\nend\n\nlemma erase_iff_related (A : rset r X) (B : rset (r+1) X) : cube_graph A B ↔ ∃ (i ∈ B), erase B i H = A := \niff.trans stretch_iff_related erase_iff_stretch'\n\nlemma all_removals_iff_related {r : ℕ} {A : rset r X} {B : rset (r+1) X} : A ∈ all_removals B ↔ cube_graph A B :=\nby rw [erase_iff_related, mem_all_removals]\n\nlemma nat.choose_succ_right_eq {n k : ℕ} : nat.choose n (k + 1) * (k + 1) = nat.choose n k * (n - k) :=\nbegin\n  have e : (n+1) * nat.choose n k = nat.choose n k * (k+1) + nat.choose n (k+1) * (k+1),\n    rw [← nat.right_distrib, ← nat.choose_succ_succ, nat.succ_mul_choose_eq],\n  rw [← nat.sub_eq_of_eq_add e, mul_comm, ← nat.mul_sub_left_distrib],\n  simp\nend\n\ntheorem div_le_div_iff {α} [linear_ordered_field α] {a b c d : α}\n  (hc : 0 < c) (hd : 0 < d) : a / c ≤ b / d ↔ a * d ≤ b * c :=\nby rw [le_div_iff hd, div_mul_eq_mul_div, div_le_iff hc]\n\nlemma multiply_out {A B n r : ℕ} (hr1 : 1 ≤ r) (hr2 : r ≤ n)\n  (h : A * r ≤ B * (n - r + 1)) :\n  (A : ℚ) / (nat.choose n r) ≤ B / nat.choose n (r-1) :=\nbegin\n  rw div_le_div_iff; norm_cast,\n  apply le_of_mul_le_mul_right _,\n    exact hr1,\n  cases r,\n    simp,\n  rw nat.succ_eq_add_one at *,\n  rw [← 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, ← 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)\nend\n\ndef from_above {n : ℕ} (𝒜 : finset (rset (r+1) (fin n))) : finset (rset (r+1) (fin n) × rset r (fin n)) :=\n𝒜.bind $ λ A, (all_removals A).map ⟨λ x, (A, x), λ _ _, by simp⟩\n\nlemma mem_from_above {n : ℕ} {𝒜 : finset (rset (r+1) (fin n))} {A : rset (r+1) (fin n)} {B : rset r (fin n)} : \n  (A,B) ∈ from_above 𝒜 ↔ A ∈ 𝒜 ∧ B ∈ all_removals A :=\nbegin\n  rw [from_above, finset.mem_bind], \n  split; intro h,\n    rcases h with ⟨a, Ha, h⟩,\n    rw finset.mem_map at h,\n    rcases h with ⟨b, Hb, h⟩,\n    injection h with Ah Bh,\n    rw [Ah, Bh] at *,\n    exact ⟨Ha, Hb⟩,\n  use A,\n  use h.1,\n  rw finset.mem_map,\n  use B,\n  use h.2,\n  refl\nend\n\nlemma card_from_above {n : ℕ} (𝒜 : finset (rset (r+1) (fin n))) : (from_above 𝒜).card = 𝒜.card * (r+1) :=\nbegin\n  rw [from_above, finset.card_bind, ← nat.smul_eq_mul, ← finset.sum_const], \n    congr, ext,\n    rw card_map,\n    exact card_all_removals,\n  intros,\n  rw finset.disjoint_iff_ne,\n  finish\nend\n\ndef from_below {n : ℕ} (𝒜 : finset (rset (r+1) (fin n))) : finset (rset (r+1) (fin n) × rset r (fin n)) :=\nbegin\n  refine (∂𝒜).bind (λ B, _),\n  refine (finset.univ \\ B.1).attach.map ⟨λ x, (stretch B x.1 (finset.mem_sdiff.1 x.2).2, B), _⟩,\n  rintros ⟨x₁, x₁h⟩ ⟨x₂, x₂h⟩ h,\n  rw finset.mem_sdiff at x₂h,\n  injection h,\n  congr,\n  have q := mem_stretch_self x₂h.2,\n  rw [← h_1, mem_stretch] at q,\n  tauto\nend\n\nlemma mem_from_below {n : ℕ} {𝒜 : finset (rset (r+1) (fin n))} {A : rset (r+1) (fin n)} {B : rset r (fin n)} :\n  A ∈ 𝒜 ∧ (∃ (i ∉ B), stretch B i H = A) → (A,B) ∈ from_below 𝒜 :=\nbegin\n  intro h,\n  rw [from_below, finset.mem_bind],\n  use B,\n  split,\n    rw mem_shadow,\n    exact ⟨A, h.1, erase_iff_stretch'.1 h.2⟩,\n  rw [finset.mem_map],\n  rcases h.2 with ⟨_, _, _⟩,\n  refine ⟨⟨w, finset.mem_sdiff.2 ⟨complete _, ‹_›⟩⟩, by simp, _⟩,\n  dsimp,\n  rw ‹stretch B w _ = A›\nend\n\nlemma above_sub_below {n : ℕ} {𝒜 : finset (rset (r+1) (fin n))} : from_above 𝒜 ⊆ from_below 𝒜 :=\nbegin\n  rintros ⟨x,y⟩ h,\n  apply mem_from_below,\n  rwa [← stretch_iff_related, ← all_removals_iff_related, ← mem_from_above]\nend\n\nlemma card_from_below {n : ℕ} (𝒜 : finset (rset (r+1) (fin n))) : (from_below 𝒜).card ≤ (∂𝒜).card * (n-r) :=\nbegin\n  rw [from_below],\n  transitivity,\n    apply finset.card_bind_le,\n  apply ge_of_eq,\n  rw [← nat.smul_eq_mul, ← finset.sum_const],\n  congr,\n  ext,\n  rw [card_map, finset.card_attach, finset.card_sdiff, card_of_rset, finset.card_univ, fintype.card_fin],\n  apply finset.subset_univ\nend\n\nlemma finally {n r : ℕ} (hr2 : r + 1 ≤ n) : n - (r + 1) + 1 = n - r := by omega\n\ntheorem localLYM {n r : ℕ} (𝒜 : finset (rset (r+1) (fin n))) {hr2 : r + 1 ≤ n} :\n  (𝒜.card : ℚ) / nat.choose n (r+1) ≤ (∂𝒜).card / nat.choose n r :=\nbegin\n  apply multiply_out (by simp) hr2,\n  rw ← card_from_above,\n  transitivity,\n    apply finset.card_le_of_subset above_sub_below,\n  transitivity,\n    apply card_from_below,\n  apply nat.mul_le_mul_left,\n  omega,\nend\n\ntheorem localLYM {n r : ℕ} (𝒜 : finset (rset (r+1) (fin n))) {hr2 : r + 1 ≤ n} :\n  (𝒜.card : ℚ) / nat.choose n (r+1) ≤ (∂𝒜).card / nat.choose n r :=\nbegin\n  apply main_lemma (by simp) hr2,\n  rw [finally hr2],\n  exact (\n    calc 𝒜.card * (r + 1) = (from_above 𝒜).card : (card_from_above 𝒜).symm\n         ... ≤ (from_below 𝒜).card : begin apply finset.card_le_of_subset _, apply above_sub_below end\n         ... ≤ finset.card (∂𝒜) * (n - r) : (card_from_below 𝒜)\n  )\nend", "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.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7538311818971231}}
{"text": "/- Comment -/\n\n-- comment\n\n-- declaring objects\nconstants m n : nat\nconstant f : nat → nat\nconstant p : prod nat nat\n\n#check (m, n)\n#check p.1\n\n-- types are objects\n#check nat\n\nconstants α β : Type\nconstant F : Type → Type\n\n#check α\n#check F α\n\n-- of what type is the type Type?\n#check Type\n#check Type 1\n#check Type 2\n--...\n\n-- Prop is a special type\n#check Prop\n\n-- Polymorphic types\n#check list\n#check prod\n-- in order to create polymorphic types, one must use universe variables,\n-- where these variables range over the level of types\nuniverse u\nconstant γ : Type u\n#check γ\n\n-- besides of application, abstraction (creating functions from other ones) comes into play when dealing with functions\n#check λ x : nat, x + 5\n#check λ x : nat, x + 7\n-- we can rely on type inference\n#check λ x, x + 8\n\n-- expressions that are the same up to renaming of bound variables are called alpha equivalent\n-- the process of simplifying an expression (λ x, t) s to t[s/x] is known as beta reduction, and\n-- two terms that reduce to a common term are called beta equivalent\n#reduce (m, n).1\n\n-- important feature of dependent type theory: every term has a computational behaviour, and supports a notion of\n-- reduction, or normalization. In principle, two terms that reduce to the same value are called\n-- definitionally equal\n\n-- this computation behaviour makes it possible to use Lean as a programming language as well\n#eval 1234*1234\n\n-- constant allows to declare objects, but how can we define them?\n\ndef foo : (ℕ → ℕ) → ℕ := λ f, f 0\n\n#check foo\n#print foo\n\n-- alternative notation\ndef double (x : ℕ) : ℕ := x + x\n\n-- local definitions, using the let construct\n#check let y := 2 in y + y\n\ndef bar := (λ a : Type, λ x : a, x) nat -- works, because the expression doesn't depend on the value of a\n--def bar := (λ a : Type, λ x : a, x+2) nat -- doesn't work, because x+2 doesn't make sense for every value of a\n\n-- it is better to use variables instead of extending the system with new constants\n-- for that, there are the local declarations and the variable and variables constructs\ndef compose (α β γ : Type) (g : β → γ) (f : α → β) (x : α) : γ :=\n    g (f x)\n\nvariable k : ℕ\ndef my_double := 2 * k\n\n-- sections can help to define scopes\n-- namespaces can be used to group definitions\n-- the construct open allow to use the names inside a namespace\n\n-- dependent type theory: types can depend on parameters\n-- Pi type or dependent function type: Π x:α, β x means \n-- the type of all functions f which when take a value x\n-- of type α, return a value of type β x\n\nnamespace hidden\n\nuniverse v\n\nconstant list : Type v → Type v\n\nconstant cons : Π α : Type u, α → list α → list α\n\n#check list ℕ\n\nend hidden\n\n-- seamingly, sigma types generalize the notion of products,\n-- such that the type of the second element depends on\n-- the type of the first element\n\n-- implicit arguments: type inference over dependent types\n-- use _ to hide the type and let the type inference mechanism act\n-- use { } when declaring a parameter, and this will default to\n-- always use the type inference mechanism\n-- { } works also on variables/variable declarations\n\n-- tactics mode\n-- tactics are instructions that tell Lean how to construct a proof term\n-- tactics-style contrasts with term-style\ntheorem test (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=\nbegin\n    apply and.intro,\n    exact hp,\n    apply and.intro,\n    exact hq,\n    exact hp\nend\n\n#print test\n\n-- one can use the by keyword when there is only one\n-- step for the proof\n-- the include command tells lean to include the indicated variables\n-- the omit keywork limit the effect of an include\n-- examples of tactics: apply, exact, intro, reflexivity, symmetry, transitivity\n-- assumption, repeat, fapply, revert, generalize, sorry, rewrite, left, right,\n-- cases, constructor, existsi, split, induction, contradiction\n-- it is possible to mix term-style and tactics-style proofs\n-- := can be used in place of from\n\n-- tactics combinators allows for the creation of\n-- new tactics from old ones\n-- examples: the comma, {tactics1,...,tacticsn}\n-- t1;t2 (parallel), <|> (orelse) try and backtrack when fail, try,\n-- all_goals, any_goals\n\n-- simplifier: a powerful tool for automation, using identities\n-- tagged with [simp] attribute\n-- uses the simp tactic to iteratively rewrite subterms in an expression\n-- keyword at help to simplify a hypothesis\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/test.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7538252299000958}}
{"text": "import algebra.ring algebra.group_power group_theory.submonoid order.boolean_algebra\nimport algebra.geom_sum\nimport commutative_algebra.nilpotent commutative_algebra.regular\nimport tactic.ring\n\nuniverse u\nvariables {A : Type u} [comm_ring A]\n\nnamespace commutative_algebra \n\ndef is_idempotent (a : A) := a * a = a\n\ntheorem is_idempotent' {a : A} : is_idempotent a ↔ a * (1 - a) = 0 := \nby { dsimp [is_idempotent], rw [mul_sub, mul_one,sub_eq_zero], exact comm}\n\nnamespace is_idempotent \n\n/-- 0 and 1 are idempotent, and (1,0) and (0,1) are idempotent in \n  a product ring.\n-/\ntheorem zero : is_idempotent (0 : A) := mul_zero 0\ntheorem one  : is_idempotent (1 : A) := mul_one 1\n\ntheorem left {B : Type*} {C : Type*} [comm_ring B] [comm_ring C] : \n  is_idempotent (⟨1, 0⟩ : B × C) := \nshow  prod.mk ((1 : B) * (1 : B)) ((0 : C) * (0 : C)) = ⟨1, 0⟩,\nby { rw [mul_one, mul_zero] }\n\ntheorem right {B : Type*} {C : Type*} [comm_ring B] [comm_ring C] : \n  is_idempotent (⟨0, 1⟩ : B × C) := \nshow  prod.mk ((0 : B) * (0 : B)) ((1 : C) * (1 : C)) = ⟨0, 1⟩,\nby { rw [mul_one, mul_zero] }\n\n/-- If a is idempotent, then (1 - 2 * a) ^ 2 = 1 -/\ndef invol (a : A) := 1 - 2 * a\n\nsection one_variable \n\nvariables {a : A} (ha : is_idempotent a)\ninclude ha\n\n/-- Positive powers of idempotents are idempotent -/\ntheorem pow : ∀ (n : ℕ), a ^ (n + 1) = a \n| 0 := by { rw [zero_add, pow_one] }\n| (n + 1) := by { have : a * a = a := ha, rw [pow_succ, pow n, this] }\n\n/-- If a is idempotent, then so is 1 - a.  We call this (not a), \n because it is the negation operation for a boolean algebra structure\n on the set of idempotents.\n-/\ntheorem not : is_idempotent (1 - a) := \nby { rw [is_idempotent'] at ha ⊢, rw [mul_comm, sub_sub_cancel], exact ha }\n\n/-- 1 is the only regular idempotent -/\ntheorem regular (hr : is_regular a) : a = 1 := \nby { symmetry, rw [← sub_eq_zero], exact hr _ (is_idempotent'.mp ha) }\n\n/-- 0 is the only nilpotent idempotent -/\ntheorem nilpotent (hn : is_nilpotent a) : a = 0 := \nby { rcases hn with ⟨n, hn'⟩, rw [← pow ha n, pow_succ, hn', mul_zero] }\n\ntheorem mul_self_invol : a * (invol a) = - a := \nby { dsimp [is_idempotent, invol] at *,\n    rw [mul_sub, mul_one, two_mul, mul_add, ha],\n    rw [← sub_sub, sub_self, zero_sub] }\n\ntheorem invol_square : (invol a) * (invol a) = 1 := \nbegin\n  change (1 - 2 * a) * invol a = 1,\n  rw [sub_mul, mul_assoc, mul_self_invol ha, one_mul],\n  dsimp [invol], \n  rw[mul_neg, sub_sub, add_neg_self, sub_zero]\nend\n\nend one_variable\n\nsection two_variables \nvariables {a b : A} (ha : is_idempotent a) (hb : is_idempotent b)\ninclude ha hb\n\n/-- The set of idempotents is a boolean algebra under the \n  operations given below.\n-/\ntheorem and  : is_idempotent (a * b) := \nshow (a * b) * (a * b) = a * b,\nby { dsimp [is_idempotent] at ha hb,\n     rw [mul_assoc, mul_comm b, mul_assoc, hb, ← mul_assoc, ha] }\n\ntheorem add (hab : a * b = 0) : is_idempotent (a + b) := \nby { dsimp [is_idempotent] at *,\n     rw [mul_add, add_mul, add_mul, mul_comm b a, ha, hb, hab, \n         zero_add, add_zero] }\n\ntheorem or : is_idempotent (a + b - a * b) := \nbegin\n  have : a + b - a * b = a + (1 - a) * b := \n    by { rw [sub_mul, one_mul, add_sub] },\n  rw [this],\n  apply add ha (and (not ha) hb),\n  rw [← mul_assoc, is_idempotent'.mp ha, zero_mul],\nend\n\ntheorem xor : is_idempotent (a + b - 2 * a * b) := \nbegin\n  let u := a * (1 - b),\n  let v := (1 - a) * b,\n  have : a + b - 2 * a * b = u + v := by { dsimp [u, v], ring },\n  rw [this],\n  have hu := and ha (not hb),\n  have hv := and (not ha) hb,\n  have huv : u * v = 0 := \n  by { dsimp [u, v], rw [mul_comm a, mul_assoc, ← mul_assoc a],\n       have : a * (1 - a) = 0 := is_idempotent'.mp ha,\n       rw [this, zero_mul, mul_zero] },\n  exact add hu hv huv\nend\n\nend two_variables \n\n/-- Idempotents are equal if their difference is nilpotent -/\ntheorem eq_of_sub_nilp {e₀ e₁ : A}\n  (h₀ : is_idempotent e₀) (h₁ : is_idempotent e₁)\n  (h : is_nilpotent (e₀ - e₁)) : e₀ = e₁ := \nbegin\n  dsimp [is_idempotent] at h₀ h₁,\n  let x := e₀ - e₁,\n  let u := 1 - 2 * e₀,\n  let v := 1 + u * x, \n  have hvx := calc\n  v * x = (e₀ * e₀ - e₀) * (4 * e₁ - 2 * e₀ - 1) +\n          (e₁ * e₁ - e₁) * (1 - 2 * e₀) : \n    by { dsimp [v, u, x], ring }\n   ... = 0 : by { rw [h₀, h₁, sub_self, sub_self, zero_mul, zero_mul, zero_add] },\n have hv : is_regular v := \n  regular.add_nilpotent_aux (is_regular_one A) (is_nilpotent_smul u h),\n have hx : x = 0 := hv x hvx,\n rw [← sub_eq_zero],\n exact hx,\nend\n\n/-- If e * (1 - e) is nilpotent, then there is a unique idempotent\n  that is congruent to e mod nilpotents.\n-/\ndef lift : ∀ (e : A) (h : as_nilpotent (e * (1 - e))), A := \n λ e ⟨n, hx⟩, let y := (1 - e ^ (n + 2) - (1 - e) ^ (n + 2)) in \n  e ^ (n + 2) * (finset.range n).sum (λ i, y ^ i)\n\ndef lift_spec (e : A) (h : as_nilpotent (e * (1 - e))) :\n pprod (is_idempotent (lift e h)) (as_nilpotent ((lift e h) - e)) :=\nbegin \n rcases h with ⟨n, hx⟩,\n let x := e * (1 - e), change x ^ n = 0 at hx,\n let y := 1 - e ^ (n + 2) - (1 - e) ^ (n + 2),\n let u := (finset.range n).sum (λ i, y ^ i),\n let e₁ := e ^ (n + 2) * u,\n have : lift e ⟨n, hx⟩ = e₁ := rfl,\n rw [this],\n let f := λ (i : ℕ), e ^ i * (1 - e) ^ (n + 2 - i) * nat.choose (n + 2) i,\n let z := (finset.range (n + 1)).sum \n            (λ j, e ^ j * (1 - e) ^ (n - j) * (nat.choose (n + 2) (j + 1))),\n let xz := (finset.range (n + 1)).sum (f ∘ nat.succ),\n have hxz : x * z = xz := by {\n   dsimp [xz, x], rw [finset.mul_sum], apply finset.sum_congr rfl, intros i hi,\n   replace hi : i ≤ n := nat.le_of_lt_succ (finset.mem_range.mp hi),\n   have : (f ∘ nat.succ) i = f (i + 1) := rfl, rw [this], dsimp [f],\n   have : n + 2 - (i + 1) = (n - i) + 1 := calc \n    n + 2 - (i + 1) = n + 1 - i : by { rw [nat.succ_sub_succ] }\n    ... = (i + (n - i)) + 1 - i : by { rw [nat.add_sub_of_le hi] }  \n    ... = (n - i) + 1 : by { simp only [add_comm, add_assoc, nat.add_sub_cancel_left] }, \n   rw [this, pow_succ, pow_succ], repeat { rw [mul_assoc] }, congr' 1,\n   repeat { rw [← mul_assoc] }, rw [mul_comm (1 - e) (e ^ i)],   \n },\n have hf₀ : f 0 = (1 - e) ^ (n + 2) :=\n  by { dsimp [f], rw [nat.choose, nat.cast_one, pow_zero, one_mul, mul_one] },\n have hf₁ := finset.sum_range_succ' f (n + 1),\n rw[hf₀] at hf₁,\n have hf₂ : f (n + 2) = e ^ (n + 2) := \n  by { dsimp [f], rw [nat.choose_self, nat.cast_one, nat.sub_self, pow_zero, mul_one, mul_one] },\n have hf₃ := finset.sum_range_succ f (n + 2),\n rw[hf₂] at hf₃,\n have := calc\n  (1 : A) = (1 : A) ^ (n + 2) : (one_pow (n + 2)).symm\n  ... = (e + (1 - e)) ^ (n + 2) :\n   by { congr, rw [add_sub, add_comm, add_sub_cancel] }\n  ... = (finset.range (n + 2).succ).sum f : add_pow e (1 - e) (n + 2) \n  ... = ((finset.range (n + 2)).sum f)  + e ^ (n + 2): hf₃ \n  ... = (xz + (1 - e) ^ (n + 2)) + e ^ (n + 2) :  by { rw [hf₁] } \n  ... = (x * z + (1 - e) ^ (n + 2)) + e ^ (n + 2) : by { rw [hxz] },\n have hxyz := calc \n  y = 1 - e ^ (n + 2) - (1 - e) ^ (n + 2) : rfl \n  ... = ((x * z + (1 - e) ^ (n + 2)) + e ^ (n + 2)) - e ^ (n + 2) - (1 - e) ^ (n + 2) : \n   by { congr' 2 }\n  ... = x * z : by { simp only [sub_eq_add_neg, add_comm, add_left_comm,\n                               add_neg_cancel_left, add_neg_cancel_right] },\n have hy : y ^ n = 0 := by { rw [hxyz, mul_pow, hx, zero_mul] },\n have hu : u * (y - 1) = y ^ n - 1 := geom_sum_mul y n,\n rw [mul_comm, hy, zero_sub] at hu, replace hu := congr_arg has_neg.neg hu,\n rw [neg_neg, neg_mul_eq_neg_mul, neg_sub] at hu,\n have : 1 - y = e ^ (n + 2) + (1 - e) ^ (n + 2) := \n  calc 1 - y = 1 - (1 - e ^ (n + 2) - (1 - e) ^ (n + 2)) : by { simp only [y] }\n   ... = e ^ (n + 2) + (1 - e) ^ (n + 2) : by rw [sub_sub, sub_sub_cancel],\n let hu' := hu, rw [this] at hu',\n have := calc\n  1 - e₁ = (e ^ (n + 2) + (1 - e) ^ (n + 2)) * u - e₁ : by { rw [hu'] }\n  ... = e ^ (n + 2) * u + (1 - e) ^ (n + 2) * u - e ^ (n + 2) * u :\n   by { rw [add_mul] }\n  ... = (1 - e) ^ (n + 2) * u : by { rw [add_comm, add_sub_cancel] },\n have := calc \n  e₁ * (1 - e₁) = (e ^ (n + 2) * u) * (1 - e₁) : rfl\n  ... = u * (e ^ (n + 2) * (1 - e₁)) : by { rw [mul_comm (e ^ (n + 2))], rw [← mul_assoc] }\n  ... = u * (e ^ (n + 2) * (1 - e) ^ (n + 2) * u) : by { rw [this, mul_assoc] }\n  ... = u * (x ^ (n + 2) * u) : by { rw [mul_pow, pow_add] }\n  ... = 0 : by { rw [pow_add, hx, zero_mul, zero_mul, mul_zero] },\n split, exact is_idempotent'.mpr this,\n let w := geom_sum₂ 1 e (n + 1), \n have hw : x * w = e - e ^ (n + 2) := calc \n  x * w = e * (w * (1 - e)) : by { dsimp [x], rw [mul_assoc, mul_comm _ w] }\n  ... = e * (1 - e ^ (n + 1)) : by { rw [geom_sum₂_mul 1 e (n + 1), one_pow] }\n  ... = e - e ^ (n + 2) : by { rw [mul_sub, mul_one, pow_succ e (n + 1)] },\n have hu'' : u = 1 + x * z * u := by {\n   rw [sub_mul, hxyz, one_mul] at hu, rw [← hu, sub_add_cancel],\n },\n have := calc\n  e₁ - e = e ^ (n + 2) * u - e : rfl\n  ... = e ^ (n + 2) * (1 + x * z * u) - e : by { congr' 2 }\n  ... = (e ^ (n + 2) * (x * z * u) + e ^ (n + 2)) - e : \n         by { rw [mul_add, mul_one, add_comm] }\n  ... = x * (e ^ (n + 2) * z * u) - (e - e ^ (n + 2)) : \n         by { rw [← sub_add, sub_eq_add_neg, sub_eq_add_neg],\n             rw [← mul_assoc, ← mul_assoc, mul_comm (e ^ (n + 2))],\n             repeat { rw [add_assoc] }, rw [add_comm (e ^ (n + 2))],\n             repeat { rw [mul_assoc] } }\n  ... = x * (e ^ (n + 2) * z * u - w) : by { rw [mul_sub, hw] },\n have : (e₁ - e) ^ n = 0 := by { rw [this, mul_pow, hx, zero_mul] },\n exact ⟨n, this⟩,\nend\n\ntheorem lift_unique (e e₁ : A) \n (h : as_nilpotent (e * (1 - e))) (hi : is_idempotent e₁)\n (hn : is_nilpotent (e₁ - e)) : e₁ = lift e h := \nbegin\n rcases lift_spec e h with ⟨hi', hn'⟩,\n apply eq_of_sub_nilp hi hi',\n have : e₁ - lift e h = (e₁ - e) - (lift e h - e) := \n  by { rw [sub_sub_sub_cancel_right] },\n rw [this], apply is_nilpotent_sub hn ⟨hn'⟩\nend\n\nend is_idempotent\n\nnamespace is_idempotent\n\nvariables {e : A} (he : is_idempotent e)\ninclude he\n\n/-- An idempotent e gives a splitting of the form A ≃ B × C.  \n  The first factor will be denoted by (axis he), where he\n  is the proof that e is idempotent.\n-/\n\ndef axis := {b : A // b * e = b}\n\nnamespace axis \n\ninstance : has_coe (axis he) A := ⟨subtype.val⟩\n\ntheorem eq (b₁ b₂ : axis he) : (b₁ : A) = (b₂ : A) → b₁ = b₂ := subtype.eq\n\ndef mk (b : A) (hb : b * e = b) : axis he := ⟨b, hb⟩\n\ntheorem coe_mk {b : A} (hb : b * e = b) : ((mk he b hb) : A) = b := rfl\n\ninstance : has_zero (axis he) := ⟨⟨(0 : A), zero_mul e⟩⟩\n\ninstance : has_one (axis he) := ⟨⟨e, he⟩⟩\n\ninstance : has_neg (axis he) := \n ⟨λ b, axis.mk he (- b.val) (by { rw [← neg_mul_eq_neg_mul, b.property] })⟩\n\ninstance : has_add (axis he) := \n ⟨λ b₁ b₂, axis.mk he (b₁.val + b₂.val) (by { rw [add_mul, b₁.property, b₂.property] })⟩ \n\ninstance : has_mul (axis he) := \n ⟨λ b₁ b₂, axis.mk he (b₁.val * b₂.val) (by { rw [mul_assoc, b₂.property] })⟩\n\n@[simp] theorem zero_coe : ((0 : axis he) : A) = 0 := rfl\n\n@[simp] theorem one_coe  : ((1 : axis he) : A) = e := rfl\n\n@[simp] theorem neg_coe (b : axis he) : (((- b) : axis he) : A) = - b := rfl\n\n@[simp] theorem add_coe (b₁ b₂ : axis he) : \n ((b₁ + b₂ : axis he) : A) = b₁ + b₂ := rfl\n\n@[simp] theorem mul_coe (b₁ b₂ : axis he) : \n ((b₁ * b₂ : axis he) : A) = b₁ * b₂ := rfl\n\ninstance : comm_ring (axis he) := begin\n  refine_struct { \n   zero := has_zero.zero, add := (+), neg := has_neg.neg, sub := λ a b, a + (-b), \n   one := has_one.one, mul := (*),\n   nsmul := nsmul_rec,\n   npow := npow_rec, \n   zsmul := zsmul_rec,\n   nsmul_zero' := λ x, rfl,\n   nsmul_succ' := λ n x, rfl, \n   zsmul_zero' := λ x, rfl,\n   zsmul_succ' := λ n x, rfl,\n   zsmul_neg'  := λ n x, rfl,\n   npow_zero'  := λ x, rfl,\n   npow_succ'  := λ n x, rfl\n };\n try { rintro a }; \n try { rintro b }; \n try { rintro c }; \n apply eq;\n repeat { rw[add_coe] };\n repeat { rw[neg_coe] };\n repeat { rw[mul_coe] };\n repeat { rw[add_coe] };\n repeat { rw[zero_coe] };\n repeat { rw[one_coe] },\n { rw[add_assoc] },\n { rw[zero_add] },\n { rw[add_zero] },\n { rw[neg_add_self] },\n { rw[add_comm] },\n { rw[mul_assoc] },\n { rw[mul_comm], exact a.property },\n { exact a.property },\n { rw[mul_add] },\n { rw[add_mul] },\n { rw[mul_comm] }\nend\n\ndef proj : A →+* axis he := {\n to_fun := λ a, ⟨a * e, by { dsimp [is_idempotent] at he, rw [mul_assoc, he] }⟩,\n map_zero' := by { apply eq, change 0 * e = 0, exact zero_mul e },\n map_one' := by { apply eq, change 1 * e = e, exact one_mul e },\n map_add' := λ a b, by { apply eq, \n                        change (a + b) * e = a * e + b * e,\n                        rw [add_mul] },\n map_mul' := λ a b, by { dsimp [is_idempotent] at he, \n                        apply eq,\n                        change (a * b) * e = (a * e) * (b * e),\n                        rw [mul_assoc a e, ← mul_assoc e b e, mul_comm e b,\n                            mul_assoc b e, he, mul_assoc] }\n}\n\ndef split : A →+* (axis he) × (axis (is_idempotent.not he)) := \n let he' := is_idempotent.not he in {\n to_fun := λ a, ⟨(proj he a), (proj (is_idempotent.not he) a)⟩,\n map_zero' := by { rw[(proj he).map_zero, (proj _).map_zero], refl },\n map_one' := by { rw[(proj he).map_one, (proj _).map_one], refl },\n map_add' := λ a b, by { rw[(proj he).map_add, (proj _).map_add], refl },\n map_mul' := λ a b, by { rw[(proj he).map_mul, (proj _).map_mul], refl }\n}\n\ntheorem mul_eq_zero (b : axis he) (c : axis (is_idempotent.not he)) : \n (b : A) * (c : A) = 0 := \nbegin\n  rcases b with ⟨b, hb⟩,\n  rcases c with ⟨c, hc⟩,\n  change b * c = 0,\n  exact calc\n    b * c = (b * e) * (c * (1 - e)) : by rw [hb, hc]\n    ... = b * (e * (1 - e)) * c : \n      by { rw [mul_comm c, mul_assoc, mul_assoc, mul_assoc] }\n    ... = 0 : by { rw [is_idempotent'.mp he, mul_zero, zero_mul] }\nend\n\ndef combine : (axis he) × (axis (is_idempotent.not he)) →+* A := { \n to_fun := λ bc, (bc.1 : A) + (bc.2 : A),\n map_zero' := by { \n   change ((0 : axis he) : A) + ((0 : axis (is_idempotent.not he)) : A) = 0,\n   rw[zero_coe, zero_coe, zero_add] \n },\n map_one' := by { \n   change e + (1 - e) = 1, rw [add_sub_cancel'_right]\n },\n map_add' := λ bc₁ bc₂, by {\n    rcases bc₁ with ⟨⟨b₁, hb₁⟩, ⟨c₁, hc₁⟩⟩,\n    rcases bc₂ with ⟨⟨b₂, hb₂⟩, ⟨c₂, hc₂⟩⟩,\n    change (b₁ + b₂) + (c₁ + c₂) = (b₁ + c₁) + (b₂ + c₂),\n    rw [add_assoc, ← add_assoc b₂, add_comm b₂ c₁, add_assoc, add_assoc] },\n  map_mul' := λ bc₁ bc₂, by {\n    rcases bc₁ with ⟨⟨b₁, hb₁⟩, ⟨c₁, hc₁⟩⟩,\n    rcases bc₂ with ⟨⟨b₂, hb₂⟩, ⟨c₂, hc₂⟩⟩,\n    change (b₁ * b₂) + (c₁ * c₂) = (b₁ + c₁) * (b₂ + c₂),\n    have ebc : b₁ * c₂ = 0 := mul_eq_zero he ⟨b₁, hb₁⟩ ⟨c₂, hc₂⟩,\n    have ecb : b₂ * c₁ = 0 := mul_eq_zero he ⟨b₂, hb₂⟩ ⟨c₁, hc₁⟩,\n    rw [mul_comm] at ecb,\n    rw [mul_add, add_mul, add_mul, ebc, ecb, zero_add, add_zero] } }\n\ntheorem combine_split (a : A) : combine he (split he a) = a := \nby { change a * e + a * (1 - e) = a, \n     rw [mul_sub, mul_one, add_sub_cancel'_right] }\n\ntheorem split_combine (bc : (axis he) × (axis (is_idempotent.not he))) : \n  split he (combine he bc) = bc := \nbegin\n  have he' : e * (1 - e) = 0 := is_idempotent'.mp he,\n  rcases bc with ⟨⟨b, hb⟩, ⟨c, hc⟩⟩,\n  ext, \n  { change (b + c) * e = b,\n    rw [← hc, add_mul, hb, mul_assoc, mul_comm (1 - e), he', mul_zero, add_zero] },\n  { change (b + c) * (1 - e) = c,\n    rw [← hb, add_mul, hc, mul_assoc, he', mul_zero, zero_add] }\nend\n\nend axis\n\nend is_idempotent\n\nvariable (A)\ndef idempotent := {a : A // is_idempotent a}\nvariable {A}\n\nnamespace idempotent \n\nvariables (a b c : idempotent A)\n\ninstance : has_coe (idempotent A) A := ⟨subtype.val⟩\n\ntheorem eq (a₁ a₂ : idempotent A) : (a₁ : A) = (a₂ : A) → a₁ = a₂ := \nsubtype.eq\n\ntheorem mul_self : (a * a : A) = a := a.property\n\ntheorem mul_not : (a * (1 - a) : A) = 0 := is_idempotent'.mp a.property\n\ninstance : has_le (idempotent A) := ⟨λ a b, (a * b : A) = a⟩\ninstance : has_bot (idempotent A) := ⟨⟨0, is_idempotent.zero⟩⟩\ninstance : has_top (idempotent A) := ⟨⟨1, is_idempotent.one⟩⟩\n\ninstance : has_compl (idempotent A) :=\n⟨λ a, ⟨((1 - a) : A), is_idempotent.not a.property⟩⟩\n\ninstance : has_inf (idempotent A) := \n⟨λ a b, ⟨a * b, is_idempotent.and a.property b.property⟩⟩\n\ninstance : has_sup (idempotent A) := \n⟨λ a b, ⟨a + b - a * b, is_idempotent.or a.property b.property⟩⟩\n\ntheorem le_iff {a b : idempotent A} : a ≤ b ↔ (a * b : A) = a := by { refl }\ntheorem bot_coe : ((⊥ : idempotent A) : A) = 0 := rfl\ntheorem top_coe : ((⊤ : idempotent A) : A) = 1 := rfl\n\ntheorem compl_coe : ((aᶜ : idempotent A) : A) = 1 - a := rfl\ntheorem inf_coe : ((a ⊓ b : idempotent A) : A) = a * b := rfl\ntheorem sup_coe : ((a ⊔ b : idempotent A) : A) = a + b - a * b := rfl\n\ntheorem compl_compl : aᶜᶜ = a := \nby { apply eq, rw [compl_coe, compl_coe, sub_sub_cancel] }\n\ntheorem compl_inj {a b : idempotent A} (h : aᶜ = bᶜ) : a = b := \nby { rw [← compl_compl a, ← compl_compl b, h] }\n\ntheorem compl_le_compl {a b : idempotent A} : a ≤ b ↔ bᶜ ≤ aᶜ := \nbegin\n  rw [le_iff, le_iff, compl_coe, compl_coe, mul_sub, sub_mul, sub_mul],\n  rw [mul_one, mul_one, one_mul, sub_sub, mul_comm (b : A)], \n  rw[sub_right_inj],\n  split,\n  { intro h, rw [h, sub_self, add_zero] },\n  { intro h, symmetry, rw [← sub_eq_zero],\n    exact (add_right_inj (b : A)).mp (h.trans (add_zero (b : A)).symm) }\nend\n\ntheorem compl_bot : (⊥ : idempotent A)ᶜ = ⊤ := \nby { apply eq, rw [compl_coe, bot_coe, top_coe, sub_zero] }\n\ntheorem compl_sup : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := \nby { apply eq, rw [compl_coe, sup_coe, inf_coe, compl_coe, compl_coe], ring }\n\ntheorem compl_top : (⊤ : idempotent A)ᶜ = ⊥ := \nby { apply eq, rw [compl_coe, bot_coe, top_coe, sub_self] }\n\ntheorem compl_inf : (a ⊓ b)ᶜ = aᶜ ⊔ bᶜ := \nby { apply compl_inj, rw [compl_sup, compl_compl, compl_compl, compl_compl] }\n\ntheorem le_refl : a ≤ a := by { rw [le_iff, a.mul_self] }\n\ntheorem le_antisymm {a b : idempotent A} (hab : a ≤ b) (hba : b ≤ a) : a = b := \nby { apply eq, rw [le_iff] at *, rw [mul_comm] at hba, exact hab.symm.trans hba }\n\ntheorem le_trans {a b c : idempotent A} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := \nby { rw [le_iff] at *, exact calc\n     ((a * c) : A) = a * b * c : by rw [hab]\n      ... = a : by rw [mul_assoc, hbc, hab] }\n\ntheorem le_top : a ≤ ⊤ := by rw [le_iff, top_coe, mul_one]\n\ntheorem le_inf (hab : a ≤ b) (hac : a ≤ c) : a ≤ b ⊓ c := \n by { rw [le_iff] at *, rw [inf_coe, ← mul_assoc, hab, hac] }\n\ntheorem inf_le_left : a ⊓ b ≤ a := \n by { rw [le_iff, inf_coe, mul_comm, ← mul_assoc, a.mul_self] }\n\ntheorem inf_le_right : a ⊓ b ≤ b := \n by { rw [le_iff, inf_coe, mul_assoc, b.mul_self] }\n\ntheorem bot_le : ⊥ ≤ a := \n by { rw [le_iff, bot_coe, zero_mul] }\n\ntheorem sup_le (hac : a ≤ c) (hbc : b ≤ c) : a ⊔ b ≤ c := \n  by { rw [compl_le_compl] at *, rw [compl_sup], exact le_inf _ _ _ hac hbc }\n\ntheorem le_sup_left : a ≤ a ⊔ b := \n by { rw [compl_le_compl, compl_sup], apply inf_le_left }\n\ntheorem le_sup_right : b ≤ a ⊔ b := \n by { rw [compl_le_compl, compl_sup], apply inf_le_right }\n\ntheorem inf_sup_distrib : a ⊓ (b ⊔ c) = (a ⊓ b) ⊔ (a ⊓ c) := \n  by { apply eq, simp only [inf_coe, sup_coe, mul_add, mul_sub],\n      congr' 1, rw [← mul_assoc, ← mul_assoc], congr' 1,\n      rw [mul_assoc, mul_comm (b : A), ← mul_assoc, a.mul_self] }\n\ntheorem sup_inf_distrib : a ⊔ (b ⊓ c) = (a ⊔ b) ⊓ (a ⊔ c) := \nby { apply compl_inj, \n     rw [compl_sup, compl_inf], rw[compl_inf, compl_sup, compl_sup, inf_sup_distrib] }\n\ntheorem inf_compl_eq_bot (a : idempotent A) : a ⊓ aᶜ = ⊥ := \nby { apply eq, rw [inf_coe, bot_coe, compl_coe, mul_not] }\n\ntheorem sup_compl_eq_top (a : idempotent A) : a ⊔ aᶜ = ⊤ := \nby { apply compl_inj, rw [compl_sup, compl_top, inf_compl_eq_bot] }\n\ninstance : boolean_algebra (idempotent A) := boolean_algebra.of_core {\n  le := has_le.le,\n  bot := ⊥, \n  top := ⊤,\n  sup := has_sup.sup,\n  inf := has_inf.inf,\n  compl := has_compl.compl,\n  le_refl := le_refl,\n  le_antisymm := λ a b hab hba, le_antisymm hab hba, \n  le_trans := λ a b c hab hbc, le_trans hab hbc,\n  bot_le := bot_le,\n  le_top := le_top,\n  le_inf := le_inf,\n  inf_le_left := inf_le_left,\n  inf_le_right := inf_le_right, \n  sup_le := sup_le,\n  le_sup_left := le_sup_left,\n  le_sup_right := le_sup_right,\n  le_sup_inf := λ a b c, by { rw [sup_inf_distrib] },\n  inf_compl_le_bot := λ a, by { rw[inf_compl_eq_bot] },\n  top_le_sup_compl := λ a, by { rw[sup_compl_eq_top] }\n}\n\nend idempotent\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/idempotent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455084, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7537397688287297}}
{"text": "import algebra.periodic\n\n/-!\n# Big operators on periodic sequences indexed by ℕ\n\nHere we just prove the following result.\nLet `M` be a commutative monoid and `n : ℕ`.\nLet `a : ℕ → M` be an `n`-periodic sequence.\nThen `∏ [i < n] a(i) = ∏ [i < n] a(i + k)` for any `k : ℕ`.\nSimilar results hold when `M` is a commutative additive monoid with sums.\n-/\n\nnamespace IMOSL\nnamespace extra\n\nopen function finset\n\nlemma periodic_prod_const {M : Type*} [comm_monoid M] {a : ℕ → M} {n : ℕ}\n  (h : periodic a n) (k : ℕ) : (range n).prod (λ m, a (m + k)) = (range n).prod a :=\nbegin\n  induction k with k k_ih,\n  simp only [add_zero],\n  conv_lhs { congr, skip, funext, rw [nat.succ_eq_one_add, ← add_assoc] },\n  cases n with n n,\n  rw [prod_range_zero, prod_range_zero],\n  rw [prod_range_succ, add_comm, h, ← k_ih, prod_range_succ', zero_add]\nend\n\nlemma periodic_sum_const {M : Type*} [add_comm_monoid M] {a : ℕ → M} {n : ℕ}\n  (h : periodic a n) (k : ℕ) : (range n).sum (λ m, a (m + k)) = (range n).sum a :=\nbegin\n  induction k with k k_ih,\n  simp only [add_zero],\n  conv_lhs { congr, skip, funext, rw [nat.succ_eq_one_add, ← add_assoc] },\n  cases n with n n,\n  rw [sum_range_zero, sum_range_zero],\n  rw [sum_range_succ, add_comm (n + 1), h, ← k_ih, sum_range_succ', zero_add]\nend\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/periodic/big_operators.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218412907381, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7537397685336847}}
{"text": "variable {p : Prop}\nvariable {q : Prop}\n\nsection hrm\n-- theorems involving only `→` can be proved w lambda\n-- `theorem` command intrduces new theorem - basically a version of `def` command (kernel sees it the same)\n  theorem t1 : p → q → p := fun hp : p => fun hq : q => hp\n  #print t1\n\n  -- this is like definition of constant function, but using args of `Prop` rather than `Type`\n  -- intuitively, it assumes `p` and `q` are true, & uses first hypothesis (trivially) to establish conclusion `p` is true\n\n-- `theorem` - basically a version of `def` command (kernel sees it the same)\n-- but there's a few pragmatic diffs:\n  -- in normal circumstances - not necessary to unfold def of a theorem\n  -- lean tags proofs as irreducible - hint to not unfold\n  -- lean also able to process & check proofs in parallel (since assissing correctness of proof does not require knowing details of another)\n\n/- I THINK THIS IS THE IMPORTANT PART -/\n\n-- lambda abstractions `hp : p` and `hq : q` can be viewed as temporary assumptions in proof of `t2`\n  -- lean allows us to specify type of final term `hp` with `show` statement\n    -- adding this extra info can improve clarity of a proof and help detect errors.\n    -- `show` does nothing more than annotate the type\n    -- internally, all presentations of `t2` produce same term\n\n  theorem t2 : p → q → p :=\n    fun hp : p =>\n    fun hq : q =>\n    show p from hp\n  #print t2\n\n-- can move lambda abs variables to left of the colon:  \n  theorem t3 (hp : p) (hq : q) : p := hp\n  #print t3    -- p → q → p\n\n  -- then apply theorem t4 as func application\n  axiom hp : p \n  theorem t4 : q → p := t1 hp\n  -- here `axiom` declaration postulates existence of element of given type (& may compromise logical consistency)\n    -- ie can use to postulate empty type `False` has an element\n\n      axiom unsound : False\n      -- Everything follows from false\n      theorem ex : 1 = 0 :=\n      False.elim unsound\n  -- thus declaring an axiom `hp : p` is tantamount to declaring that `p` is true as witnessed by `hp`\n  -- applying theorem `t4 : p → q → p` to fact that `hp : p` that `p` is ture yields `t1 hp : q → p`\n\n  -- type of t1,2,3,4 is now `∀ {p q : Prop}, p → q → p` \n    -- can read this as, \"for every pair of props `p q`, we hv `p → q → p`\"\n    -- ie can move all parameters to right of colon\n      theorem t5 : ∀ {p q : Prop}, p → q → p :=\n        fun {p q : Prop} (hp : p) (hq : q) => hp\n    \n    -- (if p and q has been delcared as variables, lean can generalize)\n      variable {p q : Prop}\n      theorem t6 : p → q → p := fun (hp : p) (hq : q) => hp\n\n    -- THEN by props-as-types correspondence, we can declare the assumption `hp` that `p` holds, as another variable\n      -- lean detects it uses `hp` and automatically adds `hp : p` as premise\n      variable {p q : Prop}\n      variable (hp : p)\n      theorem t7 : q → p := fun (hq : q) => hp\n      #print t7\nend hrm\n\n\n/- generalizing t -/\n-- applies to all variables\nsection bruv\ntheorem t0 (p q : Prop) (hp : p) (hq : q) : p := hp\n\nvariable (p q r s : Prop)\n\n#check t0 p q                -- p → q → p\n#check t0 r s                -- r → s → r\n#check t0 (r → s) (s → r)    -- (r → s) → (s → r) → r → s\n\nvariable (h : r → s)\n-- variable `h` of type `r → s` can be views as hypothesis or premise that `r → s` holds\n#check t0 (r → s) (s → r) h  -- (s → r) → r → s\n\n\n/- this is composition func from chapter 2 but using props instead of types-/\nvariable (p q r s : Prop)\n\ntheorem t01 (h₁ : q → r) (h₂ : p → q) : p → r :=\nfun h₃ : p =>\nshow r from h₁ (h₂ h₃)\n-- t01 says fun of h₁ and h₂ defined above composes idk\n\nend bruv", "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.2workingwpropsastype.lean.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7536388051460398}}
{"text": "/-\nCopyright (c) 2021 Kalle Kytölä. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Kalle Kytölä\n-/\nimport topology.instances.real\nimport topology.instances.ennreal\nimport portmanteau_comeonlean_lemmas\n\n\n\nnoncomputable theory\nopen set \nopen filter\nopen_locale topological_space\n\n\nnamespace portmanteau\n\n\nabbreviation liminf_R (s : ℕ → ℝ) : ℝ := liminf at_top s\n\nabbreviation limsup_R (s : ℕ → ℝ) : ℝ := limsup at_top s\n\nabbreviation liminf_enn (s : ℕ → ennreal) : ennreal := liminf at_top s\n\nabbreviation limsup_enn (s : ℕ → ennreal) : ennreal := limsup at_top s\n\nabbreviation lim_R (s : ℕ → ℝ) (l : ℝ) : Prop := tendsto s at_top (𝓝 l)\n\nabbreviation lim_enn (s : ℕ → ennreal) (l : ennreal) : Prop := tendsto s at_top (𝓝 l)\n\nlemma lim_R_rw (s : ℕ → ℝ) (l : ℝ) : lim_R s l = tendsto s at_top (𝓝 l) := by refl\n\nlemma liminf_enn_rw {s : ℕ → ennreal} : liminf_enn s = liminf at_top s := by refl\n\nlemma limsup_enn_rw {s : ℕ → ennreal} : limsup_enn s = limsup at_top s := by refl\n\n\nsection portmanteau_limsup_liminf_lemmas\n\n\nlemma liminf_le_limsup_enn (s : ℕ → ennreal) :\n  (liminf_enn s) ≤ (limsup_enn s) :=\nbegin\n  apply @liminf_le_limsup ennreal _ _ _ _ s ,\n  exact at_top_ne_bot ,\nend\n\n\nlemma lim_eq_liminf_of_limsup_le_liminf_ennreal {s : ℕ → ennreal}\n  (hle : limsup_enn s ≤ liminf_enn s ) : \n    lim_enn (s) (liminf_enn s)  :=\nbegin\n  have heq : limsup_enn s = liminf_enn s := le_antisymm hle (liminf_le_limsup_enn s) ,\n  set l := liminf_enn s with hl,\n  exact tendsto_of_liminf_eq_limsup hl heq ,\nend\n\n\nlemma lim_eq_limsup_of_limsup_le_liminf_ennreal {s : ℕ → ennreal}\n  (hle : limsup_enn s ≤ liminf_enn s ) : \n    lim_enn s (limsup_enn s) :=\nbegin\n  rw le_antisymm hle (liminf_le_limsup_enn s) ,\n  exact lim_eq_liminf_of_limsup_le_liminf_ennreal hle ,\nend\n\n\nlemma lim_eq_limsup_ennreal {s : ℕ → ennreal} {l : ennreal} (hlim : lim_enn s l ) :\n  limsup_enn s = l := tendsto.limsup_eq hlim \n\n\nlemma lim_eq_liminf_ennreal {s : ℕ → ennreal} {l : ennreal} (hlim : lim_enn s l ) :\n  liminf_enn s = l := tendsto.liminf_eq hlim \n\n\nlemma limsup_le_of_le_ennreal {s : ℕ → ennreal} {b : ennreal} (hb : ∀ n , s(n) ≤ b ) :\n  limsup_enn s ≤ b :=\nbegin\n  have key : s ≤ᶠ[at_top] (λ n , b) := eventually_of_forall hb ,\n  have le := limsup_le_limsup key ,\n  have lim : tendsto (λ (n:ℕ) , b) at_top (𝓝 b) := tendsto_const_nhds ,\n  have eq : at_top.limsup (λ n , b) = b := lim_eq_limsup_ennreal lim ,\n  rwa eq at le ,\nend\n\n\nlemma liminf_le_of_le_ennreal {s : ℕ → ennreal} {b : ennreal} (hb : ∀ n , s(n) ≤ b ) :\n  liminf_enn s ≤ b :=\nbegin\n  have key : s ≤ᶠ[at_top] (λ n , b) := eventually_of_forall hb ,\n  have le := liminf_le_liminf key ,\n  have lim : tendsto (λ (n:ℕ) , b) at_top (𝓝 b) := tendsto_const_nhds ,\n  have eq : at_top.liminf (λ n , b) = b := lim_eq_liminf_ennreal lim ,\n  rwa eq at le ,\nend\n\n\n-- TODO: Why does Limsup_le_Limsup_of_le not work?\nlemma limsup_enn_mono {s t : ℕ → ennreal} (hst : ∀ (n : ℕ) , s(n) ≤ t(n)) :\n    limsup_enn s ≤ limsup_enn t :=\nbegin\n  have relax : s ≤ᶠ[at_top] t ,\n  { apply eventually_of_mem (@univ_mem_sets ℕ at_top) ,\n    intros n hn ,\n    exact hst n , } ,\n  exact limsup_le_limsup relax ,\nend\n\n\n-- TODO: Why does Liminf_le_Liminf_of_le not work?\nlemma liminf_enn_mono {s t : ℕ → ennreal} (hst : ∀ (n : ℕ) , s(n) ≤ t(n)) :\n    liminf_enn s ≤ liminf_enn t :=\nbegin\n  have relax : s ≤ᶠ[at_top] t ,\n  { apply eventually_of_mem (@univ_mem_sets ℕ at_top) ,\n    intros n hn ,\n    exact hst n , } ,\n  exact liminf_le_liminf relax ,\nend\n\n\nlemma Sup_neg (A : set ℝ) : Sup {x : ℝ | -x ∈ A} = - Inf A :=\nbegin\n  set mA := {x : ℝ | -x ∈ A} with hmA ,\n  set z := Sup mA with hz ,\n  have key := real.Inf_def A ,\n  rw key ,\n  simp ,\nend\n\n\nlemma Inf_neg (A : set ℝ) : Inf {x : ℝ | -x ∈ A} = - Sup A :=\nbegin\n  set mA := {x : ℝ | -x ∈ A} with hmA ,\n  have key := Sup_neg mA ,\n  set mmA := {x : ℝ | -x ∈ mA} with hmmA ,\n  have AmmA : A = mmA := by simp [hmA , hmmA],\n  rw [AmmA, key] ,\n  simp ,\nend\n\n\nlemma liminf_neg {s : ℕ → ℝ} :\n    liminf_R (-s) = - limsup_R s :=\nbegin\n  set A := { a : ℝ | ∃ (a_1 : ℕ) , ∀ (b : ℕ) , a_1 ≤ b → s b ≤ a } with hA ,\n  set mA := { a : ℝ | -a ∈ A } with hmA ,\n  have mA_rw : mA = { a : ℝ | ∃ (a_1 : ℕ) , ∀ (b : ℕ) , a_1 ≤ b → a ≤ - s b } ,\n  { ext a ,\n    rw mem_set_of_eq ,\n    split ; -- hide in corners\n    { intro h ,\n      cases h with k hk ,\n      use k ,\n      intros l hl ,\n      specialize hk l hl ,\n      linarith , } ,\n    } ,\n  have ls_eq : limsup_R s = Inf A ,\n  { change limsup at_top s = Inf A ,\n    rw limsup_eq , \n    simp only [eventually_at_top] , } , \n  have li_eq : liminf_R (-s) = Sup mA ,\n  { change liminf at_top (-s) = Sup mA ,\n    rw liminf_eq , \n    simp only [mA_rw, pi.neg_apply, eventually_at_top] , } , \n  rw [li_eq, ls_eq] ,\n  exact Sup_neg A ,\nend\n\n\nlemma limsup_neg {s : ℕ → ℝ} :\n    limsup_R (-s) = - liminf_R s :=\nbegin\n  set t := -s with ht ,\n  have nt_rw : s = -t := by tidy ,\n  have key := @liminf_neg t ,\n  rw nt_rw ,\n  linarith ,\nend\n\n\n-- TODO: should the following couple of lemmas be done in more generality?\n-- Probably `complete_semilattice_Sup` and `order_topology` etc.\n-- would be good general assumptions.\nlemma f_Sup_eq_Sup_f_ennreal (f : ennreal → ennreal) (f_mono : monotone f) (f_cont : continuous f)\n  (T : set ennreal) (nonemp_T : T.nonempty) : \n    Sup (f '' T) = f(Sup T) :=\nbegin\n  have ub : ∀ y ∈ f '' T , y ≤ f (Sup T) ,\n  { intros y hy ,\n    rcases hy with ⟨ x , hxT , fx_eq_y ⟩ ,\n    rw ← fx_eq_y ,\n    exact f_mono (le_Sup hxT) , } ,\n  have lub : ∀ (b : ennreal) , (∀ y ∈ f '' T , y ≤ b) → f (Sup T) ≤ b ,\n  { have tends : tendsto f (𝓝 (Sup T)) (𝓝 (f (Sup T))) := continuous.tendsto f_cont (Sup T) ,\n    have tends' : tendsto f (𝓝[T] (Sup T)) (𝓝 (f (Sup T))) := tendsto_nhds_within_of_tendsto_nhds tends ,\n    have tada : is_lub T (Sup T) := is_lub_Sup T ,\n    have key := is_lub.is_lub_of_tendsto _ tada nonemp_T tends' ,\n    { intros b hb ,\n      exact key.2 hb , } ,\n    { intros a haT b hbT hab ,\n      exact f_mono hab , } ,\n    } ,\n  apply le_antisymm ,\n  { apply Sup_le ub , } ,\n  { apply le_Sup_iff.mpr lub , } ,\nend\n\n\nlemma f_Inf_eq_Inf_f_ennreal (f : ennreal → ennreal) (f_mono : monotone f) (f_cont : continuous f)\n  (T : set ennreal) (nonemp_T : T.nonempty) : \n    Inf (f '' T) = f(Inf T) :=\nbegin\n  have lb : ∀ y ∈ f '' T , f (Inf T) ≤ y ,\n  { intros y hy ,\n    rcases hy with ⟨ x , hxT , fx_eq_y ⟩ ,\n    rw ← fx_eq_y ,\n    exact f_mono (Inf_le hxT) , } ,\n  have glb : ∀ (b : ennreal) , (∀ y ∈ f '' T , b ≤ y) → b ≤ f (Inf T) ,\n  { have tends : tendsto f (𝓝 (Inf T)) (𝓝 (f (Inf T))) := continuous.tendsto f_cont (Inf T) ,\n    have tends' : tendsto f (𝓝[T] (Inf T)) (𝓝 (f (Inf T))) := tendsto_nhds_within_of_tendsto_nhds tends ,\n    have inf_is_glb : is_glb T (Inf T) := is_glb_Inf T ,\n    have key := is_glb.is_glb_of_tendsto _ inf_is_glb nonemp_T tends' ,\n    { intros b hb ,\n      exact key.2 hb , } ,\n    { intros a haT b hbT hab ,\n      exact f_mono hab , } ,\n    } ,\n  apply le_antisymm ,\n  { apply Inf_le_iff.mpr glb , } ,\n  { apply le_Inf lb , } ,\nend\n\n\nlemma f_Sup_eq_Inf_f_ennreal (f : ennreal → ennreal) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) (f_cont : continuous f)\n  (T : set ennreal) (nonemp_T : T.nonempty) : Inf (f '' T) = f(Sup T) :=\nbegin\n  have lb : ∀ y ∈ f '' T , f (Sup T) ≤ y,\n  { intros y hy ,\n    rcases hy with ⟨ x , hxT , fx_eq_y ⟩ ,\n    rw ← fx_eq_y ,\n    exact f_antimono (le_Sup hxT) , } ,\n  have glb : ∀ (b : ennreal) , (∀ y ∈ f '' T , b ≤ y ) → b ≤ f (Sup T) ,\n  { have tends : tendsto f (𝓝 (Sup T)) (𝓝 (f (Sup T))) := continuous.tendsto f_cont (Sup T) ,\n    have tends' : tendsto f (𝓝[T] (Sup T)) (𝓝 (f (Sup T))) := tendsto_nhds_within_of_tendsto_nhds tends ,\n    have sup_is_lub : is_lub T (Sup T) := is_lub_Sup T ,\n    have key := is_lub.is_glb_of_tendsto _ sup_is_lub nonemp_T tends' ,\n    { intros b hb ,\n      exact key.2 hb , } ,\n    { intros a haT b hbT hab ,\n      exact f_antimono hab , } ,\n    } ,\n  apply le_antisymm ,\n  { exact Inf_le_iff.mpr glb , } ,\n  { exact le_Inf lb , } ,\nend\n\n\nlemma f_Inf_eq_Sup_f_ennreal (f : ennreal → ennreal) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) (f_cont : continuous f)\n  (T : set ennreal) (nonemp_T : T.nonempty) : Sup (f '' T) = f(Inf T) :=\nbegin\n  have ub : ∀ y ∈ f '' T , y ≤ f (Inf T) ,\n  { intros y hy ,\n    rcases hy with ⟨ x , hxT , fx_eq_y ⟩ ,\n    rw ← fx_eq_y ,\n    exact f_antimono (Inf_le hxT) , } ,\n  have lub : ∀ (b : ennreal) , (∀ y ∈ f '' T , y ≤ b) → f (Inf T) ≤ b ,\n  { have tends : tendsto f (𝓝 (Inf T)) (𝓝 (f (Inf T))) := continuous.tendsto f_cont (Inf T) ,\n    have tends' : tendsto f (𝓝[T] (Inf T)) (𝓝 (f (Inf T))) := tendsto_nhds_within_of_tendsto_nhds tends ,\n    have inf_is_glb : is_glb T (Inf T) := is_glb_Inf T ,\n    have key := is_glb.is_lub_of_tendsto _ inf_is_glb nonemp_T tends' ,\n    { intros b hb ,\n      exact key.2 hb , } ,\n    { intros a haT b hbT hab ,\n      exact f_antimono hab , } ,\n    } ,\n  apply le_antisymm ,\n  { apply Sup_le ub , } ,\n  { apply le_Sup_iff.mpr lub , } ,\nend\n\n\nlemma image_range {α β γ : Type*} (g : β → γ) (f : α → β) :\n  g '' (range f) = range (g ∘ f) :=\nbegin\n  ext w ,\n  simp only [mem_image, mem_range, exists_exists_eq_and] ,\nend\n\n\nlemma inf_tails_mono_ennreal (s : ℕ → ennreal) :\n  monotone (λ (m : ℕ) , Inf (s '' (Ici m))) :=\nbegin\n  intros n m hnm ,\n  exact Inf_le_Inf (image_subset s (Ici_subset_Ici.mpr hnm)) ,\nend\n\n\n-- I did not manage to state this result correctly \n-- using `@monotone` and `order_dual`...\nlemma sup_tails_antimono_ennreal (s : ℕ → ennreal) :\n  ∀ (k l : ℕ) , k ≤ l → (λ (m : ℕ) , Sup (s '' (Ici m))) l ≤ (λ (m : ℕ) , Sup (s '' (Ici m))) k :=\nbegin\n  intros k l hkl ,\n  exact Sup_le_Sup (image_subset s (Ici_subset_Ici.mpr hkl)) ,\nend\n\n\nlemma Sup_eq_Inf_upper_bounds (γ : Type) [complete_lattice γ] (A : set γ) :\n  Sup A = Inf (upper_bounds(A)) :=\nbegin\n  have key := is_lub_Sup A ,\n  apply le_antisymm ,\n  { cases key , \n    simp only [le_Inf_iff, Sup_le_iff] ,\n    intros b hbub b' hb' , \n    solve_by_elim , } ,\n  { cases key, \n    exact Inf_le key_left , } ,\nend\n\n\nlemma Inf_eq_Sup_lower_bounds (γ : Type) [complete_lattice γ] (A : set γ) :\n  Inf A = Sup (lower_bounds(A)) :=\nbegin\n  have key := is_glb_Inf A ,\n  apply le_antisymm ,\n  { cases key,\n    exact le_Sup key_left , } ,\n  { cases key , \n    simp only [le_Inf_iff, Sup_le_iff] ,\n    intros b hblb b' hb' , \n    solve_by_elim , } ,\nend\n\n\nlemma liminf_eq_Sup_Inf_ennreal (s : ℕ → ennreal) :\n  liminf_enn s = Sup ( range( λ (m : ℕ) , Inf (s '' (Ici m))) ) :=\nbegin\n  have mono := inf_tails_mono_ennreal s ,\n  set s_inf_tail := λ (m : ℕ) , Inf (s '' (Ici m)) with h_s_inf_tail ,\n  set A := { a : ennreal | ∃ (m : ℕ) , ∀ (n : ℕ) , m ≤ n → a ≤ s(n) } with hA ,\n  have ls_eq : liminf_enn s = Sup A ,\n  { change liminf at_top s = Sup A ,\n    rw liminf_eq , \n    simp , } , \n  rw ls_eq ,\n  have A_eq : A = { a : ennreal | ∃ (m : ℕ) , a ≤ s_inf_tail m} ,\n  { simp only [mem_image, and_imp, mem_Ici, le_Inf_iff, forall_apply_eq_imp_iff₂, exists_imp_distrib] , } ,\n  have ss : range(s_inf_tail) ⊆ { a : ennreal | ∃ (m : ℕ) , a ≤ s_inf_tail m } ,\n  { intros x hx ,\n    cases hx with n hn , -- corners\n    use n ,\n    rw hn ,\n    exact le_refl x , } ,\n  have key : upper_bounds { a : ennreal | ∃ (m : ℕ) , a ≤ s_inf_tail m } = upper_bounds (range(s_inf_tail)) ,\n  { apply le_antisymm ,\n    { intros b h_bub x hxran , -- more corners, safe place\n      exact h_bub (ss hxran) , } ,\n    { intros b h_bub x hx ,\n      cases hx with m hm ,\n      exact le_trans hm (h_bub (mem_range_self m)) , } ,\n    } ,\n  rw ← A_eq at key ,\n  rw Sup_eq_Inf_upper_bounds ,\n  rw Sup_eq_Inf_upper_bounds ,\n  exact congr_arg Inf key ,\nend\n\n\nlemma limsup_eq_Inf_Sup_ennreal (s : ℕ → ennreal) :\n  limsup_enn s = Inf ( range( λ (m : ℕ) , Sup (s '' (Ici m))) ) :=\nbegin\n  have antimono := sup_tails_antimono_ennreal s ,\n  set s_sup_tail := λ (m : ℕ) , Sup (s '' (Ici m)) with h_s_sup_tail ,\n  set A := { a : ennreal | ∃ (m : ℕ) , ∀ (n : ℕ) , m ≤ n → s(n) ≤ a } with hA ,\n  have ls_eq : limsup_enn s = Inf A ,\n  { change limsup at_top s = Inf A ,\n    rw limsup_eq , \n    simp , } , \n  rw ls_eq ,\n  have A_eq : A = { a : ennreal | ∃ (m : ℕ) , s_sup_tail m ≤ a } ,\n  { simp only [mem_image, and_imp, mem_Ici, Sup_le_iff, forall_apply_eq_imp_iff₂, exists_imp_distrib] , } ,\n  have ss : range(s_sup_tail) ⊆ { a : ennreal | ∃ (m : ℕ) , s_sup_tail m ≤ a} ,\n  { intros x hx ,\n    cases hx with n hn ,\n    use n ,\n    rw hn , -- hide\n    exact le_refl x , } ,\n  have key : lower_bounds { a : ennreal | ∃ (m : ℕ) , s_sup_tail m ≤ a} = lower_bounds (range(s_sup_tail)) ,\n  { apply le_antisymm ,\n    { intros b h_blb x hxran ,\n      exact h_blb (ss hxran) , } ,\n    { intros b h_blb x hx , -- keep quiet\n      cases hx with m hm ,\n      exact le_trans (h_blb (mem_range_self m)) hm , } ,\n    } ,\n  rw ← A_eq at key ,\n  rw Inf_eq_Sup_lower_bounds ,\n  rw Inf_eq_Sup_lower_bounds ,\n  exact congr_arg Sup key ,\nend\n\n\nlemma liminf_eq_supr_Inf_ennreal (s : ℕ → ennreal) :\n  liminf_enn s = supr ( λ (m : ℕ) , Inf (s '' (Ici m))) :=\nbegin\n  have eq : supr ( λ (m : ℕ) , Inf (s '' (Ici m))) = Sup ( range( λ (m : ℕ) , Inf (s '' (Ici m))) ) := by refl ,\n  rw eq ,\n  apply liminf_eq_Sup_Inf_ennreal ,\nend\n\n\nlemma liminf_apply_cont_mono_ennreal {s : ℕ → ennreal}\n  (f : ennreal → ennreal) (f_cont : continuous f) (f_mono : monotone f) :\n    liminf_enn (f ∘ s) = f ( liminf_enn s) :=\nbegin\n  nth_rewrite 1 liminf_eq_Sup_Inf_ennreal ,\n  rw ← f_Sup_eq_Sup_f_ennreal f f_mono f_cont (range (λ (m : ℕ) , Inf (s '' (Ici m)))) (range_nonempty _) ,\n  rw image_range _ _ ,\n  have eq : (f ∘ λ (m : ℕ), Inf (s '' Ici m)) = (λ (m : ℕ), Inf ((f ∘ s) '' Ici m)) ,\n  { funext m ,\n    dsimp ,\n    rw ← f_Inf_eq_Inf_f_ennreal f f_mono f_cont (s '' Ici m) nonempty_of_nonempty_subtype ,\n    have eq_im : (f '' (s '' (Ici m))) = ((f ∘ s) '' (Ici m)) ,\n    { ext , \n      simp only [mem_image, exists_exists_and_eq_and] , } ,\n    simp only [eq_im] , } ,\n  rw [eq , liminf_eq_Sup_Inf_ennreal] ,\nend\n\n\nlemma liminf_apply_cont_antimono_ennreal {s : ℕ → ennreal}\n  (f : ennreal → ennreal) (f_cont : continuous f) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) :\n    liminf_enn (f ∘ s) = f ( limsup_enn s) :=\nbegin\n  rw limsup_eq_Inf_Sup_ennreal ,\n  rw ← f_Inf_eq_Sup_f_ennreal f f_antimono f_cont (range (λ (m : ℕ) , Sup (s '' (Ici m)))) (range_nonempty _) , \n  rw image_range _ _ ,\n  have eq : (f ∘ λ (m : ℕ), Sup (s '' Ici m)) = (λ (m : ℕ), Inf ((f ∘ s) '' Ici m)) ,\n  { funext m ,\n    dsimp ,\n    rw ← f_Sup_eq_Inf_f_ennreal f f_antimono f_cont (s '' Ici m) nonempty_of_nonempty_subtype ,\n    have eq_im : (f '' (s '' (Ici m))) = ((f ∘ s) '' (Ici m)) ,\n    { ext , \n      simp only [mem_image, exists_exists_and_eq_and] , } ,\n    simp only [eq_im] , } ,\n  rw [eq , liminf_eq_Sup_Inf_ennreal] ,\nend\n\n\nlemma limsup_apply_cont_antimono_ennreal {s : ℕ → ennreal}\n  (f : ennreal → ennreal) (f_cont : continuous f) (f_antimono : @monotone ennreal (order_dual(ennreal)) _ _ f) :\n    limsup_enn (f ∘ s) = f ( liminf_enn s) :=\nbegin\n  rw liminf_eq_Sup_Inf_ennreal ,\n  rw ← f_Sup_eq_Inf_f_ennreal f f_antimono f_cont (range (λ (m : ℕ) , Inf (s '' (Ici m)))) (range_nonempty _) , \n  rw image_range _ _ ,\n  have eq : (f ∘ λ (m : ℕ), Inf (s '' Ici m)) = (λ (m : ℕ), Sup ((f ∘ s) '' Ici m)) ,\n  { funext m ,\n    dsimp ,\n    rw ← f_Inf_eq_Sup_f_ennreal f f_antimono f_cont (s '' Ici m) nonempty_of_nonempty_subtype ,\n    have eq_im : (f '' (s '' (Ici m))) = ((f ∘ s) '' (Ici m)) ,\n    { ext , \n      simp only [mem_image, exists_exists_and_eq_and] , } ,\n    simp only [eq_im] , } ,\n  rw [eq , limsup_eq_Inf_Sup_ennreal] ,\nend\n\n\nlemma liminf_const_sub (a : ennreal) (a_ne_top : a ≠ ⊤) (s : ℕ → ennreal) :\n  liminf at_top (λ n , (a - s(n))) = a - limsup at_top s :=\nbegin\n  have cont : continuous (λ (x : ennreal) , a-x ) := continuous_const_sub_ennreal a a_ne_top ,\n  set f := λ (x : ennreal) , a-x with hf ,\n  -- TODO: the following is repeated many times, but stating it as lemma\n  -- gets messed up, because Lean doesn't know that in `order_dual(ennreal)`\n  -- I want to use the same `-` (`sub`) as in `ennreal`...\n  have antimono : @monotone ennreal (order_dual(ennreal)) _ _ f , \n  { intros x y hxy ,\n    exact self_sub_le_self_sub_ennreal a y x hxy , } ,\n  apply liminf_apply_cont_antimono_ennreal _ cont antimono ,\nend\n\n\nlemma limsup_const_sub (a : ennreal) (a_ne_top : a ≠ ⊤) (s : ℕ → ennreal) :\n  limsup at_top (λ n , (a - s(n))) = a - liminf at_top s :=\nbegin\n  have cont : continuous (λ (x : ennreal) , a-x ) := continuous_const_sub_ennreal a a_ne_top ,\n  set f := λ (x : ennreal) , a-x with hf ,\n  have antimono : @monotone ennreal (order_dual(ennreal)) _ _ f , \n  { intros x y hxy ,\n    exact self_sub_le_self_sub_ennreal a y x hxy , } ,\n  apply limsup_apply_cont_antimono_ennreal _ cont antimono ,\nend\n\n\n\nend portmanteau_limsup_liminf_lemmas\n\nend portmanteau\n\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_limsup_lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8056321959813274, "lm_q1q2_score": 0.7535452612751511}}
{"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ε`, where `a` and `b` are typically elements of a\ncommutative ring `R`, and `ε` is a symbol satisfying `ε^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[ε]` is a shorthand for `dual_number R`\n* `ε` 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ε$ where $ε^2 = 0$.-/\nabbreviation dual_number (R : Type*) : Type* := triv_sq_zero_ext R R\n\n/-- The unit element $ε$ 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 `ε` := dual_number.eps\" in dual_number\nlocalized \"postfix `[ε]`:1025 := dual_number\" in dual_number\n\nopen_locale dual_number\n\nnamespace dual_number\n\nopen triv_sq_zero_ext\n\n@[simp] lemma fst_eps [has_zero R] [has_one R] : fst ε = (0 : R) := fst_inr _ _\n@[simp] lemma snd_eps [has_zero R] [has_one R] : snd ε = (1 : R) := snd_inr _ _\n\n/-- A version of `triv_sq_zero_ext.snd_mul` with `*` instead of `•`. -/\n@[simp] lemma snd_mul [semiring R] (x y : R[ε]) : snd (x * y) = fst x * snd y + fst y * snd x :=\nsnd_mul _ _\n\n@[simp] lemma eps_mul_eps [semiring R] : (ε * ε : R[ε]) = 0 := inr_mul_inr _ _ _\n\n@[simp] lemma inr_eq_smul_eps [mul_zero_one_class R] (r : R) : inr r = (r • ε : R[ε]) :=\next (mul_zero r).symm (mul_one r).symm\n\n/-- For two algebra morphisms out of `R[ε]` to agree, it suffices for them to agree on `ε`. -/\n@[ext] lemma alg_hom_ext {A} [comm_semiring R] [semiring A] [algebra R A]\n  ⦃f g : R[ε] →ₐ[R] A⦄ (h : f ε = g ε) : 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[ε] →ₐ[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} ≃ (R[ε] →ₐ[R] A) :=\nequiv.trans\n  (show {e : A // e * e = 0} ≃ {f : R →ₗ[R] A // ∀ x y, f x * f y = 0}, from\n    (linear_map.ring_lmap_equiv_self R ℕ A).symm.to_equiv.subtype_equiv $ λ a, begin\n      dsimp,\n      simp_rw smul_mul_smul,\n      refine ⟨λ h x y, h.symm ▸ smul_zero _, λ h, by simpa using h 1 1⟩,\n    end)\n  triv_sq_zero_ext.lift\n\n/- When applied to `ε`, `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 (ε : R[ε]) = 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 ⟨ε, by exact eps_mul_eps⟩ = alg_hom.id R R[ε] :=\nalg_hom_ext $ lift_apply_eps _\n\nend dual_number\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/dual_number.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7535398736743372}}
{"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_norm\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.NumberTheory.Padics.PadicVal\n\n/-!\n# p-adic norm\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 `p`-adic norm on `ℚ`.\n\nThe `p`-adic valuation on `ℚ` 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 `ℚ`. This norm is a nonarchimedean absolute value.\nIt takes values in {0} ∪ {1/p^k | k ∈ ℤ}.\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êa, *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\n#print padicNorm /-\n/-- If `q ≠ 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`. -/\ndef padicNorm (p : ℕ) (q : ℚ) : ℚ :=\n  if q = 0 then 0 else (p : ℚ) ^ (-padicValRat p q)\n#align padic_norm padicNorm\n-/\n\nnamespace padicNorm\n\nopen padicValRat\n\nvariable {p : ℕ}\n\n/- warning: padic_norm.eq_zpow_of_nonzero -> padicNorm.eq_zpow_of_nonzero is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {q : Rat}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) -> (Eq.{1} Rat (padicNorm p q) (HPow.hPow.{0, 0, 0} Rat Int Rat (instHPow.{0, 0} Rat Int (DivInvMonoid.Pow.{0} Rat (DivisionRing.toDivInvMonoid.{0} Rat Rat.divisionRing))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p) (Neg.neg.{0} Int Int.hasNeg (padicValRat p q))))\nbut is expected to have type\n  forall {p : Nat} {q : Rat}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) -> (Eq.{1} Rat (padicNorm p q) (HPow.hPow.{0, 0, 0} Rat Int Rat (instHPow.{0, 0} Rat Int (DivInvMonoid.Pow.{0} Rat (DivisionRing.toDivInvMonoid.{0} Rat Rat.divisionRing))) (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p) (Neg.neg.{0} Int Int.instNegInt (padicValRat p q))))\nCase conversion may be inaccurate. Consider using '#align padic_norm.eq_zpow_of_nonzero padicNorm.eq_zpow_of_nonzeroₓ'. -/\n/-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/\n@[simp]\nprotected theorem eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :\n    padicNorm p q = p ^ (-padicValRat p q) := by simp [hq, padicNorm]\n#align padic_norm.eq_zpow_of_nonzero padicNorm.eq_zpow_of_nonzero\n\n/- warning: padic_norm.nonneg -> padicNorm.nonneg is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} (q : Rat), LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) (padicNorm p q)\nbut is expected to have type\n  forall {p : Nat} (q : Rat), LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (padicNorm p q)\nCase conversion may be inaccurate. Consider using '#align padic_norm.nonneg padicNorm.nonnegₓ'. -/\n/-- The `p`-adic norm is nonnegative. -/\nprotected theorem nonneg (q : ℚ) : 0 ≤ padicNorm p q :=\n  if hq : q = 0 then by simp [hq, padicNorm]\n  else by\n    unfold padicNorm <;> split_ifs\n    apply zpow_nonneg\n    exact_mod_cast Nat.zero_le _\n#align padic_norm.nonneg padicNorm.nonneg\n\n#print padicNorm.zero /-\n/-- The `p`-adic norm of `0` is `0`. -/\n@[simp]\nprotected theorem zero : padicNorm p 0 = 0 := by simp [padicNorm]\n#align padic_norm.zero padicNorm.zero\n-/\n\n#print padicNorm.one /-\n/-- The `p`-adic norm of `1` is `1`. -/\n@[simp]\nprotected theorem one : padicNorm p 1 = 1 := by simp [padicNorm]\n#align padic_norm.one padicNorm.one\n-/\n\n/- warning: padic_norm.padic_norm_p -> padicNorm.padicNorm_p is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) p) -> (Eq.{1} Rat (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p)) (Inv.inv.{0} Rat Rat.hasInv ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p)))\nbut is expected to have type\n  forall {p : Nat}, (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) p) -> (Eq.{1} Rat (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p)) (Inv.inv.{0} Rat Rat.instInvRat (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p)))\nCase conversion may be inaccurate. Consider using '#align padic_norm.padic_norm_p padicNorm.padicNorm_pₓ'. -/\n/-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`.\n\nSee also `padic_norm.padic_norm_p_of_prime` for a version assuming `p` is prime. -/\ntheorem padicNorm_p (hp : 1 < p) : padicNorm p p = p⁻¹ := by\n  simp [padicNorm, (pos_of_gt hp).ne', padicValNat.self hp]\n#align padic_norm.padic_norm_p padicNorm.padicNorm_p\n\n/- warning: padic_norm.padic_norm_p_of_prime -> padicNorm.padicNorm_p_of_prime is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [_inst_1 : Fact (Nat.Prime p)], Eq.{1} Rat (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p)) (Inv.inv.{0} Rat Rat.hasInv ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p))\nbut is expected to have type\n  forall {p : Nat} [_inst_1 : Fact (Nat.Prime p)], Eq.{1} Rat (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p)) (Inv.inv.{0} Rat Rat.instInvRat (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p))\nCase conversion may be inaccurate. Consider using '#align padic_norm.padic_norm_p_of_prime padicNorm.padicNorm_p_of_primeₓ'. -/\n/-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime.\n\nSee also `padic_norm.padic_norm_p` for a version assuming `1 < p`. -/\n@[simp]\ntheorem padicNorm_p_of_prime [Fact p.Prime] : padicNorm p p = p⁻¹ :=\n  padicNorm_p <| Nat.Prime.one_lt (Fact.out _)\n#align padic_norm.padic_norm_p_of_prime padicNorm.padicNorm_p_of_prime\n\n/- warning: padic_norm.padic_norm_of_prime_of_ne -> padicNorm.padicNorm_of_prime_of_ne is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {q : Nat} [p_prime : Fact (Nat.Prime p)] [q_prime : Fact (Nat.Prime q)], (Ne.{1} Nat p q) -> (Eq.{1} Rat (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) q)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne))))\nbut is expected to have type\n  forall {p : Nat} {q : Nat} [p_prime : Fact (Nat.Prime p)] [q_prime : Fact (Nat.Prime q)], (Ne.{1} Nat p q) -> (Eq.{1} Rat (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) q)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1)))\nCase conversion may be inaccurate. Consider using '#align padic_norm.padic_norm_of_prime_of_ne padicNorm.padicNorm_of_prime_of_neₓ'. -/\n/-- The `p`-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/\ntheorem padicNorm_of_prime_of_ne {q : ℕ} [p_prime : Fact p.Prime] [q_prime : Fact q.Prime]\n    (neq : p ≠ q) : padicNorm p q = 1 :=\n  by\n  have p : padicValRat p q = 0 := by exact_mod_cast @padicValNat_primes p q p_prime q_prime neq\n  simp [padicNorm, p, q_prime.1.1, q_prime.1.NeZero]\n#align padic_norm.padic_norm_of_prime_of_ne padicNorm.padicNorm_of_prime_of_ne\n\n/- warning: padic_norm.padic_norm_p_lt_one -> padicNorm.padicNorm_p_lt_one is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat}, (LT.lt.{0} Nat Nat.hasLt (OfNat.ofNat.{0} Nat 1 (OfNat.mk.{0} Nat 1 (One.one.{0} Nat Nat.hasOne))) p) -> (LT.lt.{0} Rat Rat.hasLt (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne))))\nbut is expected to have type\n  forall {p : Nat}, (LT.lt.{0} Nat instLTNat (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1)) p) -> (LT.lt.{0} Rat Rat.instLTRat_1 (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1)))\nCase conversion may be inaccurate. Consider using '#align padic_norm.padic_norm_p_lt_one padicNorm.padicNorm_p_lt_oneₓ'. -/\n/-- The `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 `p` is prime. -/\ntheorem padicNorm_p_lt_one (hp : 1 < p) : padicNorm p p < 1 :=\n  by\n  rw [padic_norm_p hp, inv_lt_one_iff]\n  exact_mod_cast Or.inr hp\n#align padic_norm.padic_norm_p_lt_one padicNorm.padicNorm_p_lt_one\n\n/- warning: padic_norm.padic_norm_p_lt_one_of_prime -> padicNorm.padicNorm_p_lt_one_of_prime is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [_inst_1 : Fact (Nat.Prime p)], LT.lt.{0} Rat Rat.hasLt (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))\nbut is expected to have type\n  forall {p : Nat} [_inst_1 : Fact (Nat.Prime p)], LT.lt.{0} Rat Rat.instLTRat_1 (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))\nCase conversion may be inaccurate. Consider using '#align padic_norm.padic_norm_p_lt_one_of_prime padicNorm.padicNorm_p_lt_one_of_primeₓ'. -/\n/-- The `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`. -/\ntheorem padicNorm_p_lt_one_of_prime [Fact p.Prime] : padicNorm p p < 1 :=\n  padicNorm_p_lt_one <| Nat.Prime.one_lt (Fact.out _)\n#align padic_norm.padic_norm_p_lt_one_of_prime padicNorm.padicNorm_p_lt_one_of_prime\n\n/- warning: padic_norm.values_discrete -> padicNorm.values_discrete is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} {q : Rat}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero)))) -> (Exists.{1} Int (fun (z : Int) => Eq.{1} Rat (padicNorm p q) (HPow.hPow.{0, 0, 0} Rat Int Rat (instHPow.{0, 0} Rat Int (DivInvMonoid.Pow.{0} Rat (DivisionRing.toDivInvMonoid.{0} Rat Rat.divisionRing))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p) (Neg.neg.{0} Int Int.hasNeg z))))\nbut is expected to have type\n  forall {p : Nat} {q : Rat}, (Ne.{1} Rat q (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0))) -> (Exists.{1} Int (fun (z : Int) => Eq.{1} Rat (padicNorm p q) (HPow.hPow.{0, 0, 0} Rat Int Rat (instHPow.{0, 0} Rat Int (DivInvMonoid.Pow.{0} Rat (DivisionRing.toDivInvMonoid.{0} Rat Rat.divisionRing))) (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p) (Neg.neg.{0} Int Int.instNegInt z))))\nCase conversion may be inaccurate. Consider using '#align padic_norm.values_discrete padicNorm.values_discreteₓ'. -/\n/-- `padic_norm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/\nprotected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padicNorm p q = p ^ (-z) :=\n  ⟨padicValRat p q, by simp [padicNorm, hq]⟩\n#align padic_norm.values_discrete padicNorm.values_discrete\n\n#print padicNorm.neg /-\n/-- `padic_norm p` is symmetric. -/\n@[simp]\nprotected theorem neg (q : ℚ) : padicNorm p (-q) = padicNorm p q :=\n  if hq : q = 0 then by simp [hq] else by simp [padicNorm, hq]\n#align padic_norm.neg padicNorm.neg\n-/\n\nvariable [hp : Fact p.Prime]\n\ninclude hp\n\n#print padicNorm.nonzero /-\n/-- If `q ≠ 0`, then `padic_norm p q ≠ 0`. -/\nprotected theorem nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q ≠ 0 :=\n  by\n  rw [padicNorm.eq_zpow_of_nonzero hq]\n  apply zpow_ne_zero_of_ne_zero\n  exact_mod_cast ne_of_gt hp.1.Pos\n#align padic_norm.nonzero padicNorm.nonzero\n-/\n\n#print padicNorm.zero_of_padicNorm_eq_zero /-\n/-- If the `p`-adic norm of `q` is 0, then `q` is `0`. -/\ntheorem zero_of_padicNorm_eq_zero {q : ℚ} (h : padicNorm p q = 0) : q = 0 :=\n  by\n  apply by_contradiction; intro hq\n  unfold padicNorm 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.NeZero\n#align padic_norm.zero_of_padic_norm_eq_zero padicNorm.zero_of_padicNorm_eq_zero\n-/\n\n#print padicNorm.mul /-\n/-- The `p`-adic norm is multiplicative. -/\n@[simp]\nprotected theorem mul (q r : ℚ) : padicNorm p (q * r) = padicNorm p q * padicNorm p r :=\n  if hq : q = 0 then by simp [hq]\n  else\n    if hr : r = 0 then by simp [hr]\n    else by\n      have : q * r ≠ 0 := mul_ne_zero hq hr\n      have : (p : ℚ) ≠ 0 := by simp [hp.1.NeZero]\n      simp [padicNorm, *, padicValRat.mul, zpow_add₀ this, mul_comm]\n#align padic_norm.mul padicNorm.mul\n-/\n\n#print padicNorm.div /-\n/-- The `p`-adic norm respects division. -/\n@[simp]\nprotected theorem div (q r : ℚ) : padicNorm p (q / r) = padicNorm p q / padicNorm p r :=\n  if hr : r = 0 then by simp [hr]\n  else eq_div_of_mul_eq (padicNorm.nonzero hr) (by rw [← padicNorm.mul, div_mul_cancel _ hr])\n#align padic_norm.div padicNorm.div\n-/\n\n/- warning: padic_norm.of_int -> padicNorm.of_int is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (z : Int), LE.le.{0} Rat Rat.hasLe (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) z)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (z : Int), LE.le.{0} Rat Rat.instLERat (padicNorm p (Int.cast.{0} Rat Rat.instIntCastRat z)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))\nCase conversion may be inaccurate. Consider using '#align padic_norm.of_int padicNorm.of_intₓ'. -/\n/-- The `p`-adic norm of an integer is at most `1`. -/\nprotected theorem of_int (z : ℤ) : padicNorm p z ≤ 1 :=\n  if hz : z = 0 then by simp [hz, zero_le_one]\n  else by\n    unfold padicNorm\n    rw [if_neg _]\n    · refine' zpow_le_one_of_nonpos _ _\n      · exact_mod_cast le_of_lt hp.1.one_lt\n      · rw [padicValRat.of_int, neg_nonpos]\n        norm_cast\n        simp\n    exact_mod_cast hz\n#align padic_norm.of_int padicNorm.of_int\n\nprivate theorem nonarchimedean_aux {q r : ℚ} (h : padicValRat p q ≤ padicValRat p r) :\n    padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) :=\n  have hnqp : padicNorm p q ≥ 0 := padicNorm.nonneg _\n  have hnrp : padicNorm p r ≥ 0 := padicNorm.nonneg _\n  if hq : q = 0 then by simp [hq, max_eq_right hnrp, le_max_right]\n  else\n    if hr : r = 0 then by simp [hr, max_eq_left hnqp, le_max_left]\n    else\n      if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)\n      else by\n        unfold padicNorm; 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 : padicValRat p q = min (padicValRat p q) (padicValRat p r) := (min_eq_left h).symm\n          rw [this]\n          apply min_le_padic_val_rat_add <;> assumption\n#align padic_norm.nonarchimedean_aux padic_norm.nonarchimedean_aux\n\n/- warning: padic_norm.nonarchimedean -> padicNorm.nonarchimedean is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, LE.le.{0} Rat Rat.hasLe (padicNorm p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) q r)) (LinearOrder.max.{0} Rat Rat.linearOrder (padicNorm p q) (padicNorm p r))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, LE.le.{0} Rat Rat.instLERat (padicNorm p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) q r)) (Max.max.{0} Rat (LinearOrderedRing.toMax.{0} Rat Rat.instLinearOrderedRingRat) (padicNorm p q) (padicNorm p r))\nCase conversion may be inaccurate. Consider using '#align padic_norm.nonarchimedean padicNorm.nonarchimedeanₓ'. -/\n/-- The `p`-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p`\nand the norm of `q`. -/\nprotected theorem nonarchimedean {q r : ℚ} :\n    padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) :=\n  by\n  wlog hle : padicValRat p q ≤ padicValRat p r generalizing q r\n  · rw [add_comm, max_comm]\n    exact this (le_of_not_le hle)\n  exact nonarchimedean_aux hle\n#align padic_norm.nonarchimedean padicNorm.nonarchimedean\n\n/- warning: padic_norm.triangle_ineq -> padicNorm.triangle_ineq is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (q : Rat) (r : Rat), LE.le.{0} Rat Rat.hasLe (padicNorm p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) q r)) (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) (padicNorm p q) (padicNorm p r))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (q : Rat) (r : Rat), LE.le.{0} Rat Rat.instLERat (padicNorm p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) q r)) (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) (padicNorm p q) (padicNorm p r))\nCase conversion may be inaccurate. Consider using '#align padic_norm.triangle_ineq padicNorm.triangle_ineqₓ'. -/\n/-- The `p`-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of\n`p` plus the norm of `q`. -/\ntheorem triangle_ineq (q r : ℚ) : padicNorm p (q + r) ≤ padicNorm p q + padicNorm p r :=\n  calc\n    padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := padicNorm.nonarchimedean\n    _ ≤ padicNorm p q + padicNorm p r :=\n      max_le_add_of_nonneg (padicNorm.nonneg _) (padicNorm.nonneg _)\n    \n#align padic_norm.triangle_ineq padicNorm.triangle_ineq\n\n/- warning: padic_norm.sub -> padicNorm.sub is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, LE.le.{0} Rat Rat.hasLe (padicNorm p (HSub.hSub.{0, 0, 0} Rat Rat Rat (instHSub.{0} Rat (SubNegMonoid.toHasSub.{0} Rat (AddGroup.toSubNegMonoid.{0} Rat Rat.addGroup))) q r)) (LinearOrder.max.{0} Rat Rat.linearOrder (padicNorm p q) (padicNorm p r))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, LE.le.{0} Rat Rat.instLERat (padicNorm p (HSub.hSub.{0, 0, 0} Rat Rat Rat (instHSub.{0} Rat Rat.instSubRat) q r)) (Max.max.{0} Rat (LinearOrderedRing.toMax.{0} Rat Rat.instLinearOrderedRingRat) (padicNorm p q) (padicNorm p r))\nCase conversion may be inaccurate. Consider using '#align padic_norm.sub padicNorm.subₓ'. -/\n/-- The `p`-adic norm of a difference is at most the max of each component. Restates the archimedean\nproperty of the `p`-adic norm. -/\nprotected theorem sub {q r : ℚ} : padicNorm p (q - r) ≤ max (padicNorm p q) (padicNorm p r) := by\n  rw [sub_eq_add_neg, ← padicNorm.neg r] <;> apply padicNorm.nonarchimedean\n#align padic_norm.sub padicNorm.sub\n\n/- warning: padic_norm.add_eq_max_of_ne -> padicNorm.add_eq_max_of_ne is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, (Ne.{1} Rat (padicNorm p q) (padicNorm p r)) -> (Eq.{1} Rat (padicNorm p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.hasAdd) q r)) (LinearOrder.max.{0} Rat Rat.linearOrder (padicNorm p q) (padicNorm p r)))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {q : Rat} {r : Rat}, (Ne.{1} Rat (padicNorm p q) (padicNorm p r)) -> (Eq.{1} Rat (padicNorm p (HAdd.hAdd.{0, 0, 0} Rat Rat Rat (instHAdd.{0} Rat Rat.instAddRat) q r)) (Max.max.{0} Rat (LinearOrderedRing.toMax.{0} Rat Rat.instLinearOrderedRingRat) (padicNorm p q) (padicNorm p r)))\nCase conversion may be inaccurate. Consider using '#align padic_norm.add_eq_max_of_ne padicNorm.add_eq_max_of_neₓ'. -/\n/-- If the `p`-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max\nof the norms of `q` and `r`. -/\ntheorem add_eq_max_of_ne {q r : ℚ} (hne : padicNorm p q ≠ padicNorm p r) :\n    padicNorm p (q + r) = max (padicNorm p q) (padicNorm p r) :=\n  by\n  wlog hlt : padicNorm p r < padicNorm p q\n  · rw [add_comm, max_comm]\n    exact this hne.symm (hne.lt_or_lt.resolve_right hlt)\n  have : padicNorm p q ≤ max (padicNorm p (q + r)) (padicNorm p r) :=\n    calc\n      padicNorm p q = padicNorm p (q + r - r) := by congr <;> ring\n      _ ≤ max (padicNorm p (q + r)) (padicNorm p (-r)) := padicNorm.nonarchimedean\n      _ = max (padicNorm p (q + r)) (padicNorm p r) := by simp\n      \n  have hnge : padicNorm p r ≤ padicNorm p (q + r) :=\n    by\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 : padicNorm p q ≤ padicNorm p (q + r) := by rwa [max_eq_left hnge] at this\n  apply _root_.le_antisymm\n  · apply padicNorm.nonarchimedean\n  · rwa [max_eq_left_of_lt hlt]\n#align padic_norm.add_eq_max_of_ne padicNorm.add_eq_max_of_ne\n\n/-- The `p`-adic norm is an absolute value: positive-definite and multiplicative, satisfying the\ntriangle inequality. -/\ninstance : IsAbsoluteValue (padicNorm p)\n    where\n  abv_nonneg := padicNorm.nonneg\n  abv_eq_zero _ := ⟨zero_of_padicNorm_eq_zero, fun hx => by simpa only [hx] ⟩\n  abv_add := padicNorm.triangle_ineq\n  abv_mul := padicNorm.mul\n\n/- warning: padic_norm.dvd_iff_norm_le -> padicNorm.dvd_iff_norm_le is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {n : Nat} {z : Int}, Iff (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat (Monoid.Pow.{0} Nat Nat.monoid)) p n)) z) (LE.le.{0} Rat Rat.hasLe (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) z)) (HPow.hPow.{0, 0, 0} Rat Int Rat (instHPow.{0, 0} Rat Int (DivInvMonoid.Pow.{0} Rat (DivisionRing.toDivInvMonoid.{0} Rat Rat.divisionRing))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) p) (Neg.neg.{0} Int Int.hasNeg ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) n))))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {n : Nat} {z : Int}, Iff (Dvd.dvd.{0} Int Int.instDvdInt (Nat.cast.{0} Int instNatCastInt (HPow.hPow.{0, 0, 0} Nat Nat Nat (instHPow.{0, 0} Nat Nat instPowNat) p n)) z) (LE.le.{0} Rat Rat.instLERat (padicNorm p (Int.cast.{0} Rat Rat.instIntCastRat z)) (HPow.hPow.{0, 0, 0} Rat Int Rat (instHPow.{0, 0} Rat Int (DivInvMonoid.Pow.{0} Rat (DivisionRing.toDivInvMonoid.{0} Rat Rat.divisionRing))) (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) p) (Neg.neg.{0} Int Int.instNegInt (Nat.cast.{0} Int instNatCastInt n))))\nCase conversion may be inaccurate. Consider using '#align padic_norm.dvd_iff_norm_le padicNorm.dvd_iff_norm_leₓ'. -/\ntheorem dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p ^ n) ∣ z ↔ padicNorm p z ≤ p ^ (-n : ℤ) :=\n  by\n  unfold padicNorm; split_ifs with hz\n  · norm_cast  at hz\n    have : 0 ≤ (p ^ n : ℚ) := by\n      apply pow_nonneg\n      exact_mod_cast le_of_lt hp.1.Pos\n    simp [hz, this]\n  · rw [zpow_le_iff_le, neg_le_neg_iff, padicValRat.of_int,\n      padicValInt.of_ne_one_ne_zero hp.1.ne_one _]\n    · norm_cast\n      rw [← PartENat.coe_le_coe, PartENat.natCast_get, ← multiplicity.pow_dvd_iff_le_multiplicity]\n      simp\n    · exact_mod_cast hz\n    · exact_mod_cast hp.1.one_lt\n#align padic_norm.dvd_iff_norm_le padicNorm.dvd_iff_norm_le\n\n/- warning: padic_norm.int_eq_one_iff -> padicNorm.int_eq_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Int), Iff (Eq.{1} Rat (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) m)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))) (Not (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) m))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Int), Iff (Eq.{1} Rat (padicNorm p (Int.cast.{0} Rat Rat.instIntCastRat m)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))) (Not (Dvd.dvd.{0} Int Int.instDvdInt (Nat.cast.{0} Int instNatCastInt p) m))\nCase conversion may be inaccurate. Consider using '#align padic_norm.int_eq_one_iff padicNorm.int_eq_one_iffₓ'. -/\n/-- The `p`-adic norm of an integer `m` is one iff `p` doesn't divide `m`. -/\ntheorem int_eq_one_iff (m : ℤ) : padicNorm p m = 1 ↔ ¬(p : ℤ) ∣ m :=\n  by\n  nth_rw 2 [← pow_one p]\n  simp only [dvd_iff_norm_le, Int.cast_ofNat, Nat.cast_one, zpow_neg, zpow_one, not_le]\n  constructor\n  · intro h\n    rw [h, inv_lt_one_iff_of_pos] <;> norm_cast\n    · exact Nat.Prime.one_lt (Fact.out _)\n    · exact Nat.Prime.pos (Fact.out _)\n  · simp only [padicNorm]\n    split_ifs\n    · rw [inv_lt_zero, ← Nat.cast_zero, Nat.cast_lt]\n      intro h\n      exact (Nat.not_lt_zero p h).elim\n    · have : 1 < (p : ℚ) := by norm_cast <;> exact Nat.Prime.one_lt (Fact.out _ : Nat.Prime p)\n      rw [← zpow_neg_one, zpow_lt_iff_lt this]\n      have : 0 ≤ padicValRat p m\n      simp only [of_int, Nat.cast_nonneg]\n      intro h\n      rw [← zpow_zero (p : ℚ), zpow_inj] <;> linarith\n#align padic_norm.int_eq_one_iff padicNorm.int_eq_one_iff\n\n/- warning: padic_norm.int_lt_one_iff -> padicNorm.int_lt_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Int), Iff (LT.lt.{0} Rat Rat.hasLt (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Int Rat (HasLiftT.mk.{1, 1} Int Rat (CoeTCₓ.coe.{1, 1} Int Rat (Int.castCoe.{0} Rat Rat.hasIntCast))) m)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))) (Dvd.Dvd.{0} Int (semigroupDvd.{0} Int Int.semigroup) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Int (HasLiftT.mk.{1, 1} Nat Int (CoeTCₓ.coe.{1, 1} Nat Int (coeBase.{1, 1} Nat Int Int.hasCoe))) p) m)\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Int), Iff (LT.lt.{0} Rat Rat.instLTRat_1 (padicNorm p (Int.cast.{0} Rat Rat.instIntCastRat m)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))) (Dvd.dvd.{0} Int Int.instDvdInt (Nat.cast.{0} Int instNatCastInt p) m)\nCase conversion may be inaccurate. Consider using '#align padic_norm.int_lt_one_iff padicNorm.int_lt_one_iffₓ'. -/\ntheorem int_lt_one_iff (m : ℤ) : padicNorm p m < 1 ↔ (p : ℤ) ∣ m :=\n  by\n  rw [← not_iff_not, ← int_eq_one_iff, eq_iff_le_not_lt]\n  simp only [padicNorm.of_int, true_and_iff]\n#align padic_norm.int_lt_one_iff padicNorm.int_lt_one_iff\n\n/- warning: padic_norm.of_nat -> padicNorm.of_nat is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Nat), LE.le.{0} Rat Rat.hasLe (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) m)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Nat), LE.le.{0} Rat Rat.instLERat (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) m)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))\nCase conversion may be inaccurate. Consider using '#align padic_norm.of_nat padicNorm.of_natₓ'. -/\ntheorem of_nat (m : ℕ) : padicNorm p m ≤ 1 :=\n  padicNorm.of_int (m : ℤ)\n#align padic_norm.of_nat padicNorm.of_nat\n\n/- warning: padic_norm.nat_eq_one_iff -> padicNorm.nat_eq_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Nat), Iff (Eq.{1} Rat (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) m)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))) (Not (Dvd.Dvd.{0} Nat Nat.hasDvd p m))\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Nat), Iff (Eq.{1} Rat (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) m)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))) (Not (Dvd.dvd.{0} Nat Nat.instDvdNat p m))\nCase conversion may be inaccurate. Consider using '#align padic_norm.nat_eq_one_iff padicNorm.nat_eq_one_iffₓ'. -/\n/-- The `p`-adic norm of a natural `m` is one iff `p` doesn't divide `m`. -/\ntheorem nat_eq_one_iff (m : ℕ) : padicNorm p m = 1 ↔ ¬p ∣ m := by\n  simp only [← Int.coe_nat_dvd, ← int_eq_one_iff, Int.cast_ofNat]\n#align padic_norm.nat_eq_one_iff padicNorm.nat_eq_one_iff\n\n/- warning: padic_norm.nat_lt_one_iff -> padicNorm.nat_lt_one_iff is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Nat), Iff (LT.lt.{0} Rat Rat.hasLt (padicNorm p ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) Nat Rat (HasLiftT.mk.{1, 1} Nat Rat (CoeTCₓ.coe.{1, 1} Nat Rat (Nat.castCoe.{0} Rat (AddMonoidWithOne.toNatCast.{0} Rat (AddGroupWithOne.toAddMonoidWithOne.{0} Rat (AddCommGroupWithOne.toAddGroupWithOne.{0} Rat (Ring.toAddCommGroupWithOne.{0} Rat (StrictOrderedRing.toRing.{0} Rat (LinearOrderedRing.toStrictOrderedRing.{0} Rat Rat.linearOrderedRing))))))))) m)) (OfNat.ofNat.{0} Rat 1 (OfNat.mk.{0} Rat 1 (One.one.{0} Rat Rat.hasOne)))) (Dvd.Dvd.{0} Nat Nat.hasDvd p m)\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] (m : Nat), Iff (LT.lt.{0} Rat Rat.instLTRat_1 (padicNorm p (Nat.cast.{0} Rat (NonAssocRing.toNatCast.{0} Rat (Ring.toNonAssocRing.{0} Rat (DivisionRing.toRing.{0} Rat Rat.divisionRing))) m)) (OfNat.ofNat.{0} Rat 1 (Rat.instOfNatRat 1))) (Dvd.dvd.{0} Nat Nat.instDvdNat p m)\nCase conversion may be inaccurate. Consider using '#align padic_norm.nat_lt_one_iff padicNorm.nat_lt_one_iffₓ'. -/\ntheorem nat_lt_one_iff (m : ℕ) : padicNorm p m < 1 ↔ p ∣ m := by\n  simp only [← Int.coe_nat_dvd, ← int_lt_one_iff, Int.cast_ofNat]\n#align padic_norm.nat_lt_one_iff padicNorm.nat_lt_one_iff\n\nopen BigOperators\n\n#print padicNorm.sum_lt /-\ntheorem sum_lt {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α} :\n    s.Nonempty → (∀ i ∈ s, padicNorm p (F i) < t) → padicNorm p (∑ i in s, F i) < t := by\n  classical\n    refine' s.induction_on (by rintro ⟨-, ⟨⟩⟩) _\n    rintro a S haS IH - ht\n    by_cases hs : S.nonempty\n    · rw [Finset.sum_insert haS]\n      exact\n        lt_of_le_of_lt padicNorm.nonarchimedean\n          (max_lt (ht a (Finset.mem_insert_self a S))\n            (IH hs fun b hb => ht b (Finset.mem_insert_of_mem hb)))\n    · simp_all\n#align padic_norm.sum_lt padicNorm.sum_lt\n-/\n\n/- warning: padic_norm.sum_le -> padicNorm.sum_le is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {α : Type.{u1}} {F : α -> Rat} {t : Rat} {s : Finset.{u1} α}, (Finset.Nonempty.{u1} α s) -> (forall (i : α), (Membership.Mem.{u1, u1} α (Finset.{u1} α) (Finset.hasMem.{u1} α) i s) -> (LE.le.{0} Rat Rat.hasLe (padicNorm p (F i)) t)) -> (LE.le.{0} Rat Rat.hasLe (padicNorm p (Finset.sum.{0, u1} Rat α Rat.addCommMonoid s (fun (i : α) => F i))) t)\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {α : Type.{u1}} {F : α -> Rat} {t : Rat} {s : Finset.{u1} α}, (Finset.Nonempty.{u1} α s) -> (forall (i : α), (Membership.mem.{u1, u1} α (Finset.{u1} α) (Finset.instMembershipFinset.{u1} α) i s) -> (LE.le.{0} Rat Rat.instLERat (padicNorm p (F i)) t)) -> (LE.le.{0} Rat Rat.instLERat (padicNorm p (Finset.sum.{0, u1} Rat α Rat.addCommMonoid s (fun (i : α) => F i))) t)\nCase conversion may be inaccurate. Consider using '#align padic_norm.sum_le padicNorm.sum_leₓ'. -/\ntheorem sum_le {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α} :\n    s.Nonempty → (∀ i ∈ s, padicNorm p (F i) ≤ t) → padicNorm p (∑ i in s, F i) ≤ t := by\n  classical\n    refine' s.induction_on (by rintro ⟨-, ⟨⟩⟩) _\n    rintro a S haS IH - ht\n    by_cases hs : S.nonempty\n    · rw [Finset.sum_insert haS]\n      exact\n        padic_norm.nonarchimedean.trans\n          (max_le (ht a (Finset.mem_insert_self a S))\n            (IH hs fun b hb => ht b (Finset.mem_insert_of_mem hb)))\n    · simp_all\n#align padic_norm.sum_le padicNorm.sum_le\n\n#print padicNorm.sum_lt' /-\ntheorem sum_lt' {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α}\n    (hF : ∀ i ∈ s, padicNorm p (F i) < t) (ht : 0 < t) : padicNorm p (∑ i in s, F i) < t :=\n  by\n  obtain rfl | hs := Finset.eq_empty_or_nonempty s\n  · simp [ht]\n  · exact sum_lt hs hF\n#align padic_norm.sum_lt' padicNorm.sum_lt'\n-/\n\n/- warning: padic_norm.sum_le' -> padicNorm.sum_le' is a dubious translation:\nlean 3 declaration is\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {α : Type.{u1}} {F : α -> Rat} {t : Rat} {s : Finset.{u1} α}, (forall (i : α), (Membership.Mem.{u1, u1} α (Finset.{u1} α) (Finset.hasMem.{u1} α) i s) -> (LE.le.{0} Rat Rat.hasLe (padicNorm p (F i)) t)) -> (LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) t) -> (LE.le.{0} Rat Rat.hasLe (padicNorm p (Finset.sum.{0, u1} Rat α Rat.addCommMonoid s (fun (i : α) => F i))) t)\nbut is expected to have type\n  forall {p : Nat} [hp : Fact (Nat.Prime p)] {α : Type.{u1}} {F : α -> Rat} {t : Rat} {s : Finset.{u1} α}, (forall (i : α), (Membership.mem.{u1, u1} α (Finset.{u1} α) (Finset.instMembershipFinset.{u1} α) i s) -> (LE.le.{0} Rat Rat.instLERat (padicNorm p (F i)) t)) -> (LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) t) -> (LE.le.{0} Rat Rat.instLERat (padicNorm p (Finset.sum.{0, u1} Rat α Rat.addCommMonoid s (fun (i : α) => F i))) t)\nCase conversion may be inaccurate. Consider using '#align padic_norm.sum_le' padicNorm.sum_le'ₓ'. -/\ntheorem sum_le' {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α}\n    (hF : ∀ i ∈ s, padicNorm p (F i) ≤ t) (ht : 0 ≤ t) : padicNorm p (∑ i in s, F i) ≤ t :=\n  by\n  obtain rfl | hs := Finset.eq_empty_or_nonempty s\n  · simp [ht]\n  · exact sum_le hs hF\n#align padic_norm.sum_le' padicNorm.sum_le'\n\nend padicNorm\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/Padics/PadicNorm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7535398726084431}}
{"text": "/- # LoVe Homework 2: Backward Proofs\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\n1.1 (3 points). Complete the following proofs using basic tactics such as\n`intro`, `apply`, and `exact`.\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 → b) → (c → a) → c → b :=\nbegin\n  assume hab,\n  assume hca,\n  assume c,\n  exact (hab (hca c)),\nend\n\nlemma S (a b c : Prop) :\n  (a → b → c) → (a → b) → a → c :=\nbegin\n  assume h1,\n  assume hab,\n  assume a,\n  exact (h1 a (hab a)),\nend\n\nlemma more_nonsense (a b c : Prop) :\n  (c → (a → b) → a) → c → b → a :=\nbegin\n  assume h1,\n  assume hc,\n  assume hb,\n  apply h1,\n  {\n    exact hc,\n  },\n  {\n    assume ha,\n    exact hb,\n  }\nend\n\nlemma even_more_nonsense (a b c : Prop) :\n  (a → a → b) → (b → c) → a → b → c :=\nbegin\n  assume haab,\n  assume hbc,\n  assume ha,\n  assume hb,\n  exact (hbc hb),\nend\n\n/- 1.2 (1 point). Prove the following lemma using basic tactics. -/\n\nlemma weak_peirce (a b : Prop) :\n  ((((a → b) → a) → a) → b) → b :=\nbegin\n  assume h1,\n  apply h1,\n  assume h2,\n  apply h2,\n  assume ha,\n  apply h1,\n  assume h3,\n  exact ha,\nend\n\n\n/- ## Question 2 (5 points): Logical Connectives\n2.1 (1 point). Prove the following property about implication using basic\ntactics.\nHints:\n* Keep in mind that `¬ a` is the same as `a → false`. You can start by invoking\n  `rw not_def` if this helps you.\n* You will need to apply the elimination rules for `∨` and `false` at some\n  point. -/\n\nlemma about_implication (a b : Prop) :\n  ¬ a ∨ b → a → b :=\nbegin\n  assume h1,\n  assume ha,\n  apply or.elim (h1),\n  {\n    assume hnoa,\n    apply false.elim,\n    exact hnoa ha,\n  },\n  {\n    assume hb,\n    exact hb,\n  }\nend\n\nnamespace sorry_lemmas\n/- ## Question 3 (**optional**): Intuitionistic Logic\nIntuitionistic logic is extended to classical logic by assuming a classical\naxiom. There are several possibilities for the choice of axiom. In this\nquestion, we are concerned with the logical equivalence of three different\naxioms: -/\n\ndef excluded_middle :=\n∀a : Prop, a ∨ ¬ a\n\ndef peirce :=\n∀a b : Prop, ((a → b) → a) → a\n\ndef double_negation :=\n∀a : Prop, (¬¬ a) → a\n\n/- For the proofs below, please avoid using lemmas from Lean's `classical`\nnamespace, because this would defeat the purpose of the exercise.\n3.1 (**optional**). Prove the following implication using tactics.\nHint: You will need `or.elim` and `false.elim`. You can use\n`rw excluded_middle` to unfold the definition of `excluded_middle`,\nand similarly for `peirce`. -/\n\nlemma peirce_of_em :\n  excluded_middle → peirce :=\nbegin\n  rw excluded_middle,\n  rw peirce,\n  assume exc,\n  assume ha hb,\n  assume h1,\n  apply or.elim (exc ha),\n  {\n    assume a,\n    exact a,\n  },\n  {\n    assume noa,\n    apply h1,\n    assume a,\n    apply false.elim,\n    exact noa a,\n  }\nend\n\n/- 3.2 (**optional**). Prove the following implication using tactics. -/\n\nlemma dn_of_peirce :\n  peirce → double_negation :=\nbegin\n  rw peirce,\n  rw double_negation,\n  assume hpeir,\n  assume a,\n  assume hnonoa,\n  apply hpeir a false,\n  assume hnoa,\n  apply false.elim,\n  apply hnonoa,\n  exact hnoa,\nend\n\n/- 2.2 (2 points). Prove the missing link in our chain of classical axiom\nimplications.\nHints:\n* You can use `rw double_negation` to unfold the definition of\n  `double_negation`, and similarly for the other definitions.\n* You will need to apply the double negation hypothesis for `a ∨ ¬ a`. You will\n  also need the left and right introduction rules for `∨` at some point. -/\n\n#check excluded_middle\n#check peirce\n#check double_negation\n\nlemma em_of_dn :\n  double_negation → excluded_middle :=\nbegin\n  rw double_negation,\n  rw excluded_middle,\n  assume hdn,\n  assume a,\n  apply hdn,\n  assume hneg,\n  apply hneg,\n  apply or.intro_left,\n  apply hdn,\n  assume hna,\n  apply hneg,\n  apply or.intro_right,\n  exact hna,\nend\n\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.\nlemma em_of_peirce:\n  peirce → excluded_middle:=\nbegin\n  assume hpeirce,\n  exact (em_of_dn (dn_of_peirce (hpeirce))),\nend\n\nlemma peirce_of_dn:\n  double_negation → peirce:=\nbegin\n  assume hdn,\n  exact (peirce_of_em (em_of_dn (hdn))),\nend\n\nlemma dn_of_em:\n  excluded_middle → double_negation:=\nbegin\n  assume hem,\n  exact (dn_of_peirce (peirce_of_em (hem))),\nend\n\nend sorry_lemmas\n\nend backward_proofs\n\nend LoVe", "meta": {"author": "raulmom", "repo": "Colab", "sha": "6c0b668e7ac308047faa34b21bb06759ef0b9f6c", "save_path": "github-repos/lean/raulmom-Colab", "path": "github-repos/lean/raulmom-Colab/Colab-6c0b668e7ac308047faa34b21bb06759ef0b9f6c/UACourse/Tema_2/Homework_2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.7535164205672075}}
{"text": "-- Conjuntos con Lean\n-- ==================\n\nimport data.set\nopen set\n\nsection Conjuntos\n\nvariable  {U : Type}\nvariable  {x : U}\nvariables {A B C : set U}\n\n-- * Elementos básicos sobre conjuntos\n-- ===================================\n\n-- ** Pruebas de la reflexividad de la inclusión de conjuntos\n-- ==========================================================\n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar\n--    A ⊆ A\n-- ----------------------------------------------------\n\n-- #reduce x ∈ A\n-- #reduce B ⊆ C\n\n-- 1ª demostración\nexample : A ⊆ A :=\nbegin\n  intros x h,\n  exact h,\nend\n\n-- 2ª demostración\nexample : A ⊆ A :=\nassume x, \nassume h : x ∈ A,\nshow x ∈ A, from h\n\n-- 3ª demostración\nexample : A ⊆ A :=\nassume x, \nassume h : x ∈ A,\nh\n\n-- 4ª demostración\nexample : A ⊆ A :=\nassume x, \nλ h : x ∈ A, h\n\n-- 5ª demostración\nexample : A ⊆ A :=\nassume x, \nid\n\n-- 6ª demostración\nexample : A ⊆ A :=\nλ x, id\n\n-- 7ª demostración\nexample : A ⊆ A :=\n-- by library_search\nset.subset.rfl\n\nopen set\n\n-- 8ª demostración\nexample : A ⊆ A :=\nsubset.rfl\n\n-- 9ª demostración\nexample : A ⊆ A :=\n-- by hint\nby tauto\n\n-- 10ª demostración\nexample : A ⊆ A :=\nby finish\n\n-- 11ª demostración\nexample : A ⊆ A :=\nby refl \n\n-- ** Pruebas de la antisimetría de la inclusión de conjuntos\n-- ==========================================================\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar\n--    A ⊆ B, B ⊆ A ⊢ A = B \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample \n  (h1 : A ⊆ B)\n  (h2 : B ⊆ A)\n  : A = B :=\nbegin\n  ext,\n  split,\n  { intro h,\n    exact h1 h, },\n  { intro h,\n    exact h2 h, },\nend\n\n-- 2ª demostración\nexample \n  (h1 : A ⊆ B)\n  (h2 : B ⊆ A)\n  : A = B :=\next \n( assume x, \n  iff.intro\n  ( assume h : x ∈ A,\n    show x ∈ B, from h1 h)\n  ( assume h : x ∈ B,\n    show x ∈ A, from h2 h))\n\n-- 3ª demostración\nexample \n  (h1 : A ⊆ B)\n  (h2 : B ⊆ A)\n  : A = B :=\next \n(λ x, \n iff.intro\n (λ h, h1 h)\n (λ h, h2 h))\n\n-- 4ª demostración\nexample \n  (h1 : A ⊆ B)\n  (h2 : B ⊆ A)\n  : A = B :=\neq_of_subset_of_subset\n  ( assume x,\n    assume h : x ∈ A,\n    show x ∈ B, from h1 h)\n  ( assume x,\n    assume h : x ∈ B,\n    show x ∈ A, from h2 h)\n\n-- 5ª demostración\nexample \n  (h1 : A ⊆ B)\n  (h2 : B ⊆ A)\n  : A = B :=\neq_of_subset_of_subset h1 h2\n\n-- 6ª demostración\nexample \n  (h1 : A ⊆ B)\n  (h2 : B ⊆ A)\n  : A = B :=\n-- by library_search\nsubset.antisymm h1 h2\n\n-- ** Introducción de la intersección\n-- ==================================\n\n-- ----------------------------------------------------\n-- Ej. 3. Demostrar\n--    x ∈ A → x ∈ B → x ∈ A ∩ B\n-- ----------------------------------------------------\n\n-- #reduce x ∈ A ∩ B\n\n-- 1ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nbegin\n  intros h1 h2,\n  simp,\n  split,\n  { exact h1, },\n  { exact h2, },\nend\n\n-- 2ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nbegin\n  intros h1 h2,\n  split,\n  { exact h1, },\n  { exact h2, },\nend\n\n-- 3ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\nshow x ∈ A ∩ B, from and.intro h1 h2\n\n-- 4ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\nshow x ∈ A ∩ B, from ⟨h1, h2⟩\n\n-- 5ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nassume h1 : x ∈ A,\nassume h2 : x ∈ B,\n⟨h1, h2⟩\n\n-- 6ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\nλ h1 h2, ⟨h1, h2⟩\n\n-- 7ª demostración\nexample : x ∈ A → x ∈ B → x ∈ A ∩ B :=\n-- by library_search\nmem_inter\n\n-- *** Introducción de la unión\n-- ============================\n\n-- ----------------------------------------------------\n-- Ej. 4. Demostrar\n--    A ⊆ A ∪ B\n-- ----------------------------------------------------\n\n-- #reduce x ∈ A ∪ B\n\n-- 1ª demostración\nexample : A ⊆ A ∪ B :=\nbegin\n  intros x h,\n  simp,\n  left,\n  exact h,\nend\n\n-- 2ª demostración\nexample : A ⊆ A ∪ B :=\nbegin\n  intros x h,\n  left,\n  exact h,\nend\n\n-- 3ª demostración\nexample : A ⊆ A ∪ B :=\nassume x,\nassume h : x ∈ A,\nshow x ∈ A ∪ B, from or.inl h\n\n-- 4ª demostración\nexample : A ⊆ A ∪ B :=\nassume x,\nassume h : x ∈ A,\nor.inl h\n\n-- 5ª demostración\nexample : A ⊆ A ∪ B :=\nassume x,\nλ h : x ∈ A, or.inl h\n\n-- 6ª demostración\nexample : A ⊆ A ∪ B :=\nassume x, or.inl \n\n-- 7ª demostración\nexample : A ⊆ A ∪ B :=\nλ x, or.inl \n\n-- 8ª demostración\nexample : A ⊆ A ∪ B :=\n-- by library_search\nsubset_union_left A B\n\n-- 9ª demostración\nexample : A ⊆ A ∪ B :=\nλ x, mem_union_left B\n\n-- 10ª demostración\nexample : A ⊆ A ∪ B :=\n-- by hint\nby finish\n\n-- 11ª demostración\nexample : A ⊆ A ∪ B :=\nby simp\n\n-- ** El conjunto vacío\n-- ====================\n\n-- ----------------------------------------------------\n-- Ej. 5. Demostrar\n--    ∅ ⊆ A\n-- ----------------------------------------------------\n\n-- #reduce (∅ : set U)\n-- #reduce x ∈ (∅ : set U) \n\n-- 1ª demostración\nexample : ∅ ⊆ A :=\nbegin\n  intros x h,\n  simp at h,\n  exfalso,\n  exact h,\nend\n\n-- 2ª demostración\nexample : ∅ ⊆ A :=\nbegin\n  intros x h,\n  exfalso,\n  exact h,\nend\n\n-- 3ª demostración\nexample : ∅ ⊆ A :=\nassume x,\nassume h : x ∈ (∅ : set U),\nshow x ∈ A, from false.elim h\n\n-- 4ª demostración\nexample : ∅ ⊆ A :=\nλ x, λ h, false.elim h\n\n-- 5ª demostración\nexample : ∅ ⊆ A :=\nλ _, false.elim \n\n-- 6ª demostración\nexample : ∅ ⊆ A :=\n-- by library_search\nempty_subset A\n\n-- 7ª demostración\nexample : ∅ ⊆ A :=\nassume x,\nassume h : x ∈ (∅ : set U),\nshow x ∈ A, from absurd h (not_mem_empty x)\n\n-- 8ª demostración\nexample : ∅ ⊆ A :=\nλ x h, absurd h (not_mem_empty x)\n\n-- 9ª demostración\nexample : ∅ ⊆ A :=\n-- by hint\nby tauto\n\n-- 10ª demostración\nexample : ∅ ⊆ A :=\nby finish\n\n-- 11ª demostración\nexample : ∅ ⊆ A :=\nby simp \n\n-- ** Diferencia de conjuntos\n-- ==========================\n\n-- ----------------------------------------------------\n-- Ej. 6. Demostrar\n--    A \\ B ⊆ A\n-- ----------------------------------------------------\n\n-- #reduce (A \\ B)\n-- #reduce x ∈ A \\ B\n\n-- 1ª demostración\nexample : A \\ B ⊆ A :=\nbegin\n  intros x h,\n  simp at h,\n  exact h.left,\nend\n\n-- 2ª demostración\nexample : A \\ B ⊆ A :=\nbegin\n  intros x h,\n  exact h.left,\nend\n\n-- 3ª demostración\nexample : A \\ B ⊆ A :=\nassume x,\nassume h : x ∈ A \\ B,\nshow x ∈ A, from h.left\n\n-- 4ª demostración\nexample : A \\ B ⊆ A :=\nassume x,\nassume h : x ∈ A \\ B,\nand.left h\n\n-- 5ª demostración\nexample : A \\ B ⊆ A :=\nassume x,\nλ h, and.left h\n\n-- 6ª demostración\nexample : A \\ B ⊆ A :=\nassume x, and.left \n\n-- 7ª demostración\nexample : A \\ B ⊆ A :=\nλ _, and.left \n\n-- 8ª demostración\nexample : A \\ B ⊆ A :=\n-- by library_search\ndiff_subset A B\n\n-- 9ª demostración\nexample : A \\ B ⊆ A :=\nassume x,\nassume h : x ∈ A \\ B,\nshow x ∈ A, from mem_of_mem_diff h\n\n-- 10ª demostración\nexample : A \\ B ⊆ A :=\nλ _, mem_of_mem_diff \n\n-- 11ª demostración\nexample : A \\ B ⊆ A :=\nby finish [subset_def]\n\n-- ** Complementario de un conjunto\n-- ================================\n\n-- ----------------------------------------------------\n-- Ej. 7. Demostrar\n--    A \\ B ⊆ Bᶜ\n-- ----------------------------------------------------\n\n-- #reduce x ∈ Bᶜ\n-- #reduce Bᶜ\n\n-- 1ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nbegin\n  intros x h,\n  simp at *,\n  exact h.right,\nend\n\n-- 2ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nbegin\n  intros x h,\n  exact h.right,\nend\n\n-- 3ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nassume x,\nassume h1 : x ∈ A \\ B,\nhave h2 : x ∉ B, from and.right h1,\nshow x ∈ Bᶜ,     from h2\n\n-- 4ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nassume x,\nassume h1 : x ∈ A \\ B,\nshow x ∈ Bᶜ, from and.right h1\n\n-- 5ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nassume x,\nλ h1, and.right h1\n\n-- 6ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nassume x, \nand.right\n\n-- 7ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nλ _, and.right \n\n-- 8ª demostración\nexample : A \\ B ⊆ Bᶜ :=\nλ _, not_mem_of_mem_diff \n\n-- ** Pruebas de la conmutatividad de la intersección\n-- ==================================================\n\n-- ----------------------------------------------------\n-- Ej. 8. Demostrar\n--    A ∩ B ⊆ B ∩ A\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  intros x h,\n  simp at *,\n  split,\n  { exact h.right, },\n  { exact h.left,  },\nend\n\n-- 2ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  intros x h,\n  split,\n  { exact h.right, },\n  { exact h.left,  },\nend\n\n-- 3ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  rintros x ⟨h1, h2⟩,\n  split,\n  { exact h2, },\n  { exact h1, },\nend\n\n-- 4ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nbegin\n  rintros x ⟨h1, h2⟩,\n  exact ⟨h2, h1⟩,\nend\n\n-- 5ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nhave h1 : x ∈ A, from and.left h,\nhave h2 : x ∈ B, from and.right h,\nshow x ∈ B ∩ A,  from and.intro h2 h1\n\n-- 6ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nhave h1 : x ∈ A ∧ x ∈ B, from h,\nhave h2 : x ∈ B ∧ x ∈ A, from and.comm.mp h1,\nshow x ∈ B ∩ A,          from h2 \n\n-- 7ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nshow x ∈ B ∩ A, from and.comm.mp h\n\n-- 8ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nassume h : x ∈ A ∩ B,\nand.comm.mp h\n\n-- 9ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nλ h, and.comm.mp h\n\n-- 10ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nassume x,\nand.comm.mp \n\n-- 10ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\nλ _, and.comm.mp \n\n-- 11ª demostración\nexample : A ∩ B ⊆ B ∩ A :=\n-- by hint\nby finish\n\n-- 12ª demostración\nlemma aux : A ∩ B ⊆ B ∩ A :=\nby simp\n\n-- ----------------------------------------------------\n-- Ej. 9. Demostrar\n--    A ∩ B = B ∩ A\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : A ∩ B = B ∩ A :=\nbegin\n  apply eq_of_subset_of_subset,\n  { exact aux, },\n  { exact aux, },\nend\n\n-- 2ª demostración\nexample : A ∩ B = B ∩ A :=\neq_of_subset_of_subset aux aux\n\n-- 3ª demostración\nexample : A ∩ B = B ∩ A :=\n-- by library_search\ninter_comm A B\n\n-- 4ª demostración\nexample : A ∩ B = B ∩ A :=\n-- by hint\nby finish\n\n-- * Identidades conjuntistas\n-- ==========================\n\n-- ** Distributiva de la intersección sobre la unión\n-- =================================================\n\n-- ----------------------------------------------------\n-- Ej. 10. Demostrar\n--    A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) :=\nbegin\n  intros x h,\n  cases h with ha hbc,\n  cases hbc with hb hc,\n  { left,\n    split,\n    { exact ha, },\n    { exact hb, }},\n  { right,\n    split, \n    { exact ha, },\n    { exact hc, }},\nend\n\n-- 2ª demostración\nexample :\n  A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) :=\nbegin\n  intros x h,\n  cases h with ha hbc,\n  cases hbc with hb hc,\n  { left,\n    split,\n    { assumption, },\n    { assumption, }},\n  { right,\n    split, \n    { assumption, },\n    { assumption, }},\nend\n\n-- 3ª demostración\nexample :\n  A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) :=\nbegin\n  intros x h,\n  cases h with ha hbc,\n  cases hbc with hb hc,\n  { left,\n    split, \n    assumption', },\n  { right,\n    split,\n    assumption', },\nend\n\n-- 4ª demostración\nexample :\n  A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) :=\nbegin\n  rintros x ⟨ha, (hb | hc)⟩,\n  { left,\n    split, \n    assumption', },\n  { right,\n    split,\n    assumption', },\nend\n\n-- 5ª demostración\nexample :\n  A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) :=\nassume x,\nassume h : x ∈ A ∩ (B ∪ C),\nhave x ∈ A, from and.left h,\nhave x ∈ B ∪ C, from and.right h,\nor.elim (‹x ∈ B ∪ C›)\n  ( assume : x ∈ B,\n    have x ∈ A ∩ B, from and.intro ‹x ∈ A› ‹x ∈ B›,\n    show x ∈ (A ∩ B) ∪ (A ∩ C), from or.inl this)\n  ( assume : x ∈ C,\n    have x ∈ A ∩ C, from and.intro ‹x ∈ A› ‹x ∈ C›,\n    show x ∈ (A ∩ B) ∪ (A ∩ C), from or.inr this)\n\n-- 6ª demostración\nlemma inter_union_l1 :\n  A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) :=\nassume x,\nassume h : x ∈ A ∩ (B ∪ C),\nhave ha : x ∈ A, from and.left h,\nhave hbc : x ∈ B ∪ C, from and.right h,\nor.elim hbc\n  ( assume hb : x ∈ B,\n    have hab: x ∈ A ∩ B, from and.intro ha hb, \n    show x ∈ (A ∩ B) ∪ (A ∩ C), from or.inl hab)\n  ( assume hc : x ∈ C,\n    have hac : x ∈ A ∩ C, from and.intro ha hc,\n    show x ∈ (A ∩ B) ∪ (A ∩ C), from or.inr hac)\n\n-- ----------------------------------------------------\n-- Ej. 11. Demostrar\n--    (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C)\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C) :=\nbegin\n  intros x h,\n  cases h with hab hac,\n  { split,\n    { exact hab.left, },\n    { left,\n      exact hab.right, }},\n  { split,\n    { exact hac.left, },\n    { right,\n      exact hac.right, }},\nend\n\n-- 2ª demostración\nexample :\n  (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C) :=\nbegin\n  rintros x (⟨ha, hb⟩ | ⟨ha, hc⟩),\n  { split,\n    { exact ha, },\n    { left,\n      exact hb, }},\n  { split,\n    { exact ha, },\n    { right,\n      exact hc, }},\nend\n\n-- 3ª demostración\nlemma inter_union_l2 :\n  (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C) :=\nassume x,\nassume : x ∈ (A ∩ B) ∪ (A ∩ C),\nor.elim this\n  ( assume h : x ∈ A ∩ B,\n    have x ∈ A, from and.left h,\n    have x ∈ B, from and.right h,\n    have x ∈ B ∪ C, from or.inl this,\n    show x ∈ A ∩ (B ∪ C), from and.intro ‹x ∈ A› this)\n  ( assume h : x ∈ A ∩ C,\n    have x ∈ A, from and.left h,\n    have x ∈ C, from and.right h,\n    have x ∈ B ∪ C, from or.inr this,\n    show x ∈ A ∩ (B ∪ C), from and.intro ‹x ∈ A› this)\n\n-- ----------------------------------------------------\n-- Ej. 12. Demostrar\n--    (A ∩ B) ∪ (A ∩ C) = A ∩ (B ∪ C)\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=\n-- by library_search\ninter_distrib_left A B C\n\n-- 2ª demostración\ntheorem inter_union : \n  A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=\neq_of_subset_of_subset inter_union_l1 inter_union_l2\n\n-- 3ª demostración\nexample : \n  A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=\nbegin\n  ext,\n  simp,\n  exact and_or_distrib_left,\nend\n\n-- 4ª demostración\nexample : \n  A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=\nbegin\n  ext,\n  exact and_or_distrib_left,\nend\n\n-- 5ª demostración\nexample : \n  A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) :=\next (λ x, and_or_distrib_left)\n\n-- ** (A ∩ Bᶜ) ∪ B = A ∪ B\n-- =======================\n\n-- ----------------------------------------------------\n-- Ej. 1e. Demostrar\n--    (A ∩ Bᶜ) ∪ B = A ∪ B\n-- ----------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : (A ∩ Bᶜ) ∪ B = A ∪ B :=\ncalc\n  (A ∩ Bᶜ) ∪ B = (A ∪ B) ∩ (Bᶜ ∪ B) : by rw union_distrib_right\n           ... = (A ∪ B) ∩ univ     : by rw compl_union_self\n           ... = A ∪ B              : by rw inter_univ\n\nexample : (A ∩ B) ∪ C = (A ∪ C) ∩ (B ∪ C) :=\n-- by library_search \nunion_distrib_right A B C\n\nexample : Bᶜ ∪ B = univ :=\n-- by library_search\ncompl_union_self B\n\nexample : A ∩ univ = A :=\n-- by library_search\ninter_univ A\n\n-- 2ª demostración\n-- ===============\n\nexample : (A ∩ Bᶜ) ∪ B = A ∪ B :=\nbegin\n  rw union_distrib_right,\n  rw compl_union_self,\n  rw inter_univ,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : (A ∩ Bᶜ) ∪ B = A ∪ B :=\nby rw [union_distrib_right, compl_union_self, inter_univ]\n\n-- 4ª demostración\n-- ===============\n\nexample : (A ∩ Bᶜ) ∪ B = A ∪ B :=\nby simp [union_distrib_right]\n\nend Conjuntos\n\n-- * Familias de conjuntos\n-- =======================\n\nsection Familias\n\nvariables {I U : Type}\nvariable  {x : U}\nvariables {A B : I → set U}\n\n-- ** Pertenencia a uniones e intersecciones de familias\n-- =====================================================\n\n-- ----------------------------------------------------\n-- Ej. 14. Demostrar que\n--    (x ∈ ⋃ i, A i) ↔ (∃ i, x ∈ A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  (x ∈ ⋃ i, A i) ↔ (∃ i, x ∈ A i) :=\n-- by library_search\nmem_Union\n\n-- 2ª demostración\nexample :\n  (x ∈ ⋃ i, A i) ↔ (∃ i, x ∈ A i) :=\nby simp \n\n-- ----------------------------------------------------\n-- Ej. 15. Demostrar que\n--    (x ∈ ⋂ i, A i) ↔ (∀ i, x ∈ A i)\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  (x ∈ ⋂ i, A i) ↔ (∀ i, x ∈ A i) :=\n-- by library_search\nmem_Inter\n\n-- 2ª demostración\nexample :\n  (x ∈ ⋂ i, A i) ↔ (∀ i, x ∈ A i) :=\nby simp\n\n-- ** Distributiva de la intersección general sobre la intersección\n-- ================================================================\n\n-- 1ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\nbegin\n  ext,\n  split,\n  { intro h,\n    rw mem_Inter at h,\n    split,\n    { rw mem_Inter,\n      intro i,\n      exact (h i).left, },\n    { rw mem_Inter,\n      intro i,\n      exact (h i).right, }},\n  { rintro ⟨h1, h2⟩,\n    rw mem_Inter at *,\n    intro i,\n    exact ⟨h1 i, h2 i⟩, },\nend\n\n-- 2ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\next $\nassume x : U,\niff.intro\n( assume h : x ∈ ⋂ i, A i ∩ B i,\n  have h1 : ∀ i, x ∈ A i ∩ B i,     \n    from mem_Inter.mp h,\n  have h2 : ∀ i, x ∈ A i,           \n    from assume i, and.left (h1 i),\n  have h3 : ∀ i, x ∈ B i,           \n    from assume i, and.right (h1 i),\n  have h4 : x ∈ ⋂ i, A i,           \n    from mem_Inter.mpr h2,\n  have h5 : x ∈ ⋂ i, B i,           \n    from mem_Inter.mpr h3,\n  show x ∈ (⋂ i, A i) ∩ (⋂ i, B i), \n    from and.intro h4 h5)\n( assume h : x ∈ (⋂ i, A i) ∩ (⋂ i, B i),\n  have h1 : ∀ i, x ∈ A i,\n    from mem_Inter.mp (and.left h), \n  have h2 : ∀ i, x ∈ B i,\n    from mem_Inter.mp (and.right h),\n  have h3 : ∀ i, x ∈ A i ∩ B i,\n    from assume i, and.intro (h1 i) (h2 i),\n  show x ∈ ⋂ i, A i ∩ B i, \n    from mem_Inter.mpr h3)\n\n-- 3ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\n-- by library_search\nInter_inter_distrib A B\n\n-- 4ª demostración\nexample : \n  (⋂ i, A i ∩ B i) = (⋂ i, A i) ∩ (⋂ i, B i) :=\next (by finish)\n\n-- ** Pruebas de intersección sobre unión general\n-- ==============================================\n\nvariable  {C : set U}\n\n-- ----------------------------------------------------\n-- Ej. 16. Demostrar\n--    C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i)  :=\nbegin\n  rintros x ⟨hC, hU⟩,\n  rw mem_Union at hU,\n  cases hU with i hA,\n  apply mem_Union.mpr,\n  use i,\n  split,\n  assumption',\nend\n\n-- 2ª demostración\nexample : \n  C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i)  :=\nbegin\n  intros x h,\n  simp * at *,\nend\n\n-- 3ª demostración\nlemma inter_Uni_l1 : \n  C ∩ (⋃i, A i) ⊆ (⋃ i, C ∩ A i)  :=\nby {intros x h, simp * at *}\n\n-- ----------------------------------------------------\n-- Ej. 17. Demostrar\n--    (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nbegin\n  intros x h,\n  rw mem_Union at h,\n  cases h with i hi,\n  cases hi with hC hA,\n  split,\n  { exact hC, },\n  { apply mem_Union.mpr,\n    use i,\n    exact hA, },\nend\n\n-- 2ª demostración\nexample : (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nbegin\n  intros x h,\n  rw mem_Union at h,\n  rcases h with ⟨i, hC, hA⟩,\n  split,\n  { exact hC, },\n  { apply mem_Union.mpr,\n    use i,\n    exact hA, },\nend\n\n-- 3ª demostración\nexample : \n  (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nbegin\n  intros x h,\n  simp * at *,\nend\n\n-- 4ª demostración\nlemma inter_Uni_l2 : \n  (⋃ i, C ∩ A i) ⊆ C ∩ (⋃i, A i) :=\nby {intros x h, simp * at *}\n\n-- ----------------------------------------------------\n-- Ej. 18. Demostrar\n--    C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\neq_of_subset_of_subset inter_Uni_l1 inter_Uni_l2\n\n-- 2ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\n-- by library_search\ninter_Union C A\n\n-- 3ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\next $ by simp\n\n-- 4ª demostración\nexample : \n  C ∩ (⋃i, A i) = (⋃ i, C ∩ A i) :=\nby {ext, simp}\n\nend Familias\n\n-- ** Pruebas de (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j)\n-- ===============================================\n\nsection FamiliaDoble\n\nvariables {I J U : Type}\nvariables (A : I → J → set U)\n\n-- ----------------------------------------------------\n-- Ej. 19. Demostrar\n--    (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j)\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j) :=\nbegin\n  intros x h,\n  rw mem_Union at h,\n  cases h with i hi,\n  rw mem_Inter at hi,\n  apply mem_Inter.mpr,\n  intro j,\n  apply mem_Union.mpr,\n  use i,\n  exact (hi j),\nend\n\n-- 2ª demostración\nexample : (⋃i, ⋂j, A i j) ⊆ (⋂j, ⋃i, A i j) :=\nbegin\n  intros x h,\n  simp * at *,\n  cases h with i hi,\n  intro j,\n  use i,\n  exact (hi j),\nend\n\nend FamiliaDoble\n\n-- * Conjunto potencia\n-- ===================\n\nsection Potencia\n\nvariable  {U : Type}\nvariables {A B C : set U}\n\n-- ** Monotonía del conjunto potencia\n-- ==================================\n\n-- #reduce 𝒫 A\n-- #reduce B ∈ 𝒫 A\n\n-- ----------------------------------------------------\n-- Ej. 20. Demostrar\n--    𝒫 A ⊆ 𝒫 B → A ⊆ B \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ 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ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nbegin\n  intro h,\n  apply h,\n  exact subset.rfl,\nend\n\n-- 3ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nbegin\n  intro h,\n  exact (h subset.rfl),\nend\n\n-- 4ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nλ h, h subset.rfl\n\n-- 5ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nassume h1 : 𝒫 A ⊆ 𝒫 B,\nhave h2 : A ⊆ A, from subset.rfl,\nhave h3 : A ∈ 𝒫 A, from h2,\nhave h4 : A ∈ 𝒫 B, from h1 h3,\nshow A ⊆ B, from h4\n\n-- 6ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nassume h1 : 𝒫 A ⊆ 𝒫 B,\nhave h2 : A ⊆ A, from subset.rfl,\nhave h3 : A ∈ 𝒫 A, from h2,\nh1 h3\n\n-- 7ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nassume h1 : 𝒫 A ⊆ 𝒫 B,\nhave h2 : A ⊆ A, from subset.rfl,\nh1 h2\n\n-- 8ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nassume h1 : 𝒫 A ⊆ 𝒫 B,\nh1 subset.rfl\n\n-- 9ª demostración\nlemma aux1 : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\nλ h, h subset.rfl\n\n-- 10ª demostración\nexample : 𝒫 A ⊆ 𝒫 B → A ⊆ B :=\npowerset_mono.mp\n\n-- ----------------------------------------------------\n-- Ej. 21. Demostrar\n--    A ⊆ B → 𝒫 A ⊆ 𝒫 B \n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : A ⊆ B → 𝒫 A ⊆ 𝒫 B :=\nbegin\n  intro h,\n  intros C hCA,\n  apply mem_powerset,\n  apply subset.trans hCA h,\nend\n\n-- 2ª demostración\nexample : A ⊆ B → 𝒫 A ⊆ 𝒫 B :=\nbegin\n  intros h C hCA,\n  apply subset.trans hCA h,\nend\n\n-- 3ª demostración\nlemma aux2 : A ⊆ B → 𝒫 A ⊆ 𝒫 B :=\nλ h C hCA, subset.trans hCA h\n\n-- 4ª demostración\nexample : A ⊆ B → 𝒫 A ⊆ 𝒫 B :=\npowerset_mono.mpr\n\n-- ----------------------------------------------------\n-- Ej. 22. Demostrar\n--    𝒫 A ⊆ 𝒫 B ↔ A ⊆ B\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : 𝒫 A ⊆ 𝒫 B ↔ A ⊆ B :=\niff.intro aux1 aux2\n\n-- 2ª demostración\nexample : 𝒫 A ⊆ 𝒫 B ↔ A ⊆ B :=\n-- by library_search\npowerset_mono\n\n-- 3ª demostración\nexample : 𝒫 A ⊆ 𝒫 B ↔ A ⊆ B :=\n-- by hint\nby finish\n\n-- 4ª demostración\nexample : 𝒫 A ⊆ 𝒫 B ↔ A ⊆ B :=\nby simp\n\nend Potencia\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/temas/T3_Conjuntos.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048444, "lm_q2_score": 0.8824278633625322, "lm_q1q2_score": 0.7535164159270318}}
{"text": "/-\nCopyright (c) 2022 Chris Birkbeck. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Chris Birkbeck\n\n! This file was ported from Lean 3 source module measure_theory.integral.circle_transform\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.Complex.Basic\nimport Mathbin.MeasureTheory.Integral.CircleIntegral\n\n/-!\n# Circle integral transform\n\nIn this file we define the circle integral transform of a function `f` with complex domain. This is\ndefined as $(2πi)^{-1}\\frac{f(x)}{x-w}$ where `x` moves along a circle. We then prove some basic\nfacts about these functions.\n\nThese results are useful for proving that the uniform limit of a sequence of holomorphic functions\nis holomorphic.\n\n-/\n\n\nopen Set MeasureTheory Metric Filter Function\n\nopen Interval Real\n\nnoncomputable section\n\nvariable {E : Type _} [NormedAddCommGroup E] [NormedSpace ℂ E] (R : ℝ) (z w : ℂ)\n\nnamespace Complex\n\n/-- Given a function `f : ℂ → E`, `circle_transform R z w f` is the functions mapping `θ` to\n`(2 * ↑π * I)⁻¹ • deriv (circle_map z R) θ • ((circle_map z R θ) - w)⁻¹ • f (circle_map z R θ)`.\n\nIf `f` is differentiable and `w` is in the interior of the ball, then the integral from `0` to\n`2 * π` of this gives the value `f(w)`. -/\ndef circleTransform (f : ℂ → E) (θ : ℝ) : E :=\n  (2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • (circleMap z R θ - w)⁻¹ • f (circleMap z R θ)\n#align complex.circle_transform Complex.circleTransform\n\n/-- The derivative of `circle_transform` w.r.t `w`.-/\ndef circleTransformDeriv (f : ℂ → E) (θ : ℝ) : E :=\n  (2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • ((circleMap z R θ - w) ^ 2)⁻¹ • f (circleMap z R θ)\n#align complex.circle_transform_deriv Complex.circleTransformDeriv\n\ntheorem circleTransformDeriv_periodic (f : ℂ → E) :\n    Periodic (circleTransformDeriv R z w f) (2 * π) :=\n  by\n  have := periodic_circleMap\n  simp_rw [periodic] at *\n  intro x\n  simp_rw [circle_transform_deriv, this]\n  congr 2\n  simp [this]\n#align complex.circle_transform_deriv_periodic Complex.circleTransformDeriv_periodic\n\ntheorem circleTransformDeriv_eq (f : ℂ → E) :\n    circleTransformDeriv R z w f = fun θ => (circleMap z R θ - w)⁻¹ • circleTransform R z w f θ :=\n  by\n  ext\n  simp_rw [circle_transform_deriv, circle_transform, ← mul_smul, ← mul_assoc]\n  ring_nf\n  rw [inv_pow]\n  congr\n  ring\n#align complex.circle_transform_deriv_eq Complex.circleTransformDeriv_eq\n\ntheorem integral_circleTransform [CompleteSpace E] (f : ℂ → E) :\n    (∫ θ : ℝ in 0 ..2 * π, circleTransform R z w f θ) =\n      (2 * ↑π * I)⁻¹ • ∮ z in C(z, R), (z - w)⁻¹ • f z :=\n  by\n  simp_rw [circle_transform, circleIntegral, deriv_circleMap, circleMap]\n  simp\n#align complex.integral_circle_transform Complex.integral_circleTransform\n\ntheorem continuous_circleTransform {R : ℝ} (hR : 0 < R) {f : ℂ → E} {z w : ℂ}\n    (hf : ContinuousOn f <| sphere z R) (hw : w ∈ ball z R) :\n    Continuous (circleTransform R z w f) :=\n  by\n  apply_rules [Continuous.smul, continuous_const]\n  simp_rw [deriv_circleMap]\n  apply_rules [Continuous.mul, continuous_circleMap 0 R, continuous_const]\n  · apply continuous_circleMap_inv hw\n  · apply ContinuousOn.comp_continuous hf (continuous_circleMap z R)\n    exact fun _ => (circleMap_mem_sphere _ hR.le) _\n#align complex.continuous_circle_transform Complex.continuous_circleTransform\n\ntheorem continuous_circleTransformDeriv {R : ℝ} (hR : 0 < R) {f : ℂ → E} {z w : ℂ}\n    (hf : ContinuousOn f (sphere z R)) (hw : w ∈ ball z R) :\n    Continuous (circleTransformDeriv R z w f) :=\n  by\n  rw [circle_transform_deriv_eq]\n  exact (continuous_circleMap_inv hw).smul (continuous_circle_transform hR hf hw)\n#align complex.continuous_circle_transform_deriv Complex.continuous_circleTransformDeriv\n\n/-- A useful bound for circle integrals (with complex codomain)-/\ndef circleTransformBoundingFunction (R : ℝ) (z : ℂ) (w : ℂ × ℝ) : ℂ :=\n  circleTransformDeriv R z w.1 (fun x => 1) w.2\n#align complex.circle_transform_bounding_function Complex.circleTransformBoundingFunction\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem continuousOn_prod_circle_transform_function {R r : ℝ} (hr : r < R) {z : ℂ} :\n    ContinuousOn (fun w : ℂ × ℝ => (circleMap z R w.snd - w.fst)⁻¹ ^ 2) (closedBall z r ×ˢ univ) :=\n  by\n  simp_rw [← one_div]\n  apply_rules [ContinuousOn.pow, ContinuousOn.div, continuousOn_const]\n  refine'\n    ((continuous_circleMap z R).ContinuousOn.comp continuousOn_snd fun _ => And.right).sub\n      (continuous_on_id.comp continuousOn_fst fun _ => And.left)\n  simp only [mem_prod, Ne.def, and_imp, Prod.forall]\n  intro a b ha hb\n  have ha2 : a ∈ ball z R := by\n    simp at *\n    linarith\n  exact sub_ne_zero.2 (circleMap_ne_mem_ball ha2 b)\n#align complex.continuous_on_prod_circle_transform_function Complex.continuousOn_prod_circle_transform_function\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem continuousOn_abs_circleTransformBoundingFunction {R r : ℝ} (hr : r < R) (z : ℂ) :\n    ContinuousOn (abs ∘ fun t => circleTransformBoundingFunction R z t) (closedBall z r ×ˢ univ) :=\n  by\n  have : ContinuousOn (circle_transform_bounding_function R z) (closed_ball z r ×ˢ (⊤ : Set ℝ)) :=\n    by\n    apply_rules [ContinuousOn.smul, continuousOn_const]\n    simp only [deriv_circleMap]\n    have c := (continuous_circleMap 0 R).ContinuousOn\n    apply_rules [ContinuousOn.mul, c.comp continuousOn_snd fun _ => And.right, continuousOn_const]\n    simp_rw [← inv_pow]\n    apply continuous_on_prod_circle_transform_function hr\n  refine' continuous_abs.continuous_on.comp this _\n  show maps_to _ _ (⊤ : Set ℂ)\n  simp [maps_to]\n#align complex.continuous_on_abs_circle_transform_bounding_function Complex.continuousOn_abs_circleTransformBoundingFunction\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/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\ntheorem abs_circleTransformBoundingFunction_le {R r : ℝ} (hr : r < R) (hr' : 0 ≤ r) (z : ℂ) :\n    ∃ x : closedBall z r ×ˢ [0, 2 * π],\n      ∀ y : closedBall z r ×ˢ [0, 2 * π],\n        abs (circleTransformBoundingFunction R z y) ≤ abs (circleTransformBoundingFunction R z x) :=\n  by\n  have cts := continuous_on_abs_circle_transform_bounding_function hr z\n  have comp : IsCompact (closed_ball z r ×ˢ [0, 2 * π]) := by\n    apply_rules [IsCompact.prod, ProperSpace.isCompact_closedBall z r, isCompact_uIcc]\n  have none : (closed_ball z r ×ˢ [0, 2 * π]).Nonempty :=\n    (nonempty_closed_ball.2 hr').Prod nonempty_uIcc\n  have :=\n    IsCompact.exists_forall_ge comp none\n      (cts.mono\n        (by\n          intro z\n          simp only [mem_prod, mem_closed_ball, mem_univ, and_true_iff, and_imp]\n          tauto))\n  simpa only [SetCoe.forall, Subtype.coe_mk, SetCoe.exists]\n#align complex.abs_circle_transform_bounding_function_le Complex.abs_circleTransformBoundingFunction_le\n\n/-- The derivative of a `circle_transform` is locally bounded. -/\ntheorem circleTransformDeriv_bound {R : ℝ} (hR : 0 < R) {z x : ℂ} {f : ℂ → ℂ} (hx : x ∈ ball z R)\n    (hf : ContinuousOn f (sphere z R)) :\n    ∃ B ε : ℝ,\n      0 < ε ∧\n        ball x ε ⊆ ball z R ∧ ∀ (t : ℝ), ∀ y ∈ ball x ε, ‖circleTransformDeriv R z y f t‖ ≤ B :=\n  by\n  obtain ⟨r, hr, hrx⟩ := exists_lt_mem_ball_of_mem_ball hx\n  obtain ⟨ε', hε', H⟩ := exists_ball_subset_ball hrx\n  obtain ⟨⟨⟨a, b⟩, ⟨ha, hb⟩⟩, hab⟩ :=\n    abs_circle_transform_bounding_function_le hr (pos_of_mem_ball hrx).le z\n  let V : ℝ → ℂ → ℂ := fun θ w => circle_transform_deriv R z w (fun x => 1) θ\n  have funccomp : ContinuousOn (fun r => abs (f r)) (sphere z R) :=\n    by\n    have cabs : ContinuousOn abs ⊤ := by apply continuous_abs.continuous_on\n    apply cabs.comp hf\n    rw [maps_to]\n    tauto\n  have sbou :=\n    IsCompact.exists_forall_ge (isCompact_sphere z R) (NormedSpace.sphere_nonempty.2 hR.le) funccomp\n  obtain ⟨X, HX, HX2⟩ := sbou\n  refine' ⟨abs (V b a) * abs (f X), ε', hε', subset.trans H (ball_subset_ball hr.le), _⟩\n  intro y v hv\n  obtain ⟨y1, hy1, hfun⟩ :=\n    periodic.exists_mem_Ico₀ (circle_transform_deriv_periodic R z v f) Real.two_pi_pos y\n  have hy2 : y1 ∈ [0, 2 * π] := by\n    convert Ico_subset_Icc_self hy1\n    simp [uIcc_of_le real.two_pi_pos.le]\n  have :=\n    mul_le_mul (hab ⟨⟨v, y1⟩, ⟨ball_subset_closed_ball (H hv), hy2⟩⟩)\n      (HX2 (circleMap z R y1) (circleMap_mem_sphere z hR.le y1)) (complex.abs.nonneg _)\n      (complex.abs.nonneg _)\n  simp_rw [hfun]\n  simp only [circle_transform_bounding_function, circle_transform_deriv, V, norm_eq_abs,\n    Algebra.id.smul_eq_mul, deriv_circleMap, map_mul, abs_circleMap_zero, abs_I, mul_one, ←\n    mul_assoc, mul_inv_rev, inv_I, abs_neg, abs_inv, abs_of_real, one_mul, abs_two, abs_pow,\n    mem_ball, gt_iff_lt, Subtype.coe_mk, SetCoe.forall, mem_prod, mem_closed_ball, and_imp,\n    Prod.forall, NormedSpace.sphere_nonempty, mem_sphere_iff_norm] at *\n  exact this\n#align complex.circle_transform_deriv_bound Complex.circleTransformDeriv_bound\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/MeasureTheory/Integral/CircleTransform.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533088603708, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.7534849492138369}}
{"text": "import basic.conventional\n\n/-\nA groupoid (G, ⊕) is a gyrogroup if its 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 ∈ G. \n* There is an element 0 ∈ G satisfying axiom (G1) such that for each a ∈ G there is an element \n⊖a ∈ G, called a left inverse of a, satisfying\n(G2) ⊖a⊕a = 0\n* Moreover, for any a, b, c ∈ G there exists a unique element gyr[a, b]c ∈ G such that the binary \noperation obeys the left gyroassociative law\n(G3) a⊕(b⊕c) = (a⊕b)⊕gyr[a, b]c\n* The map gyr[a, b] : G → G given by c 7→ gyr[a, b]c is an automorphism of the groupoid (G, ⊕),\n(G4) gyr[a, b] ∈ Aut(G, ⊕)\nand the automorphism gyr[a, b] of G is called the gyroautomorphism of G,\ngenerated by a, b ∈ G. The operation gyr : G × G → Aut(G, ⊕) is called\nthe gyrooperation of G. \n* Finally, the gyroautomorphism gyr[a, b] generated by any a, b ∈ G possesses the left loop property\n(G5) gyr[a, b] = gyr[a⊕b, b]\n-/\n\nclass gyrogroup (G : Type) extends has_gyrop G, has_subgyrop G, has_neggyrop G, has_zero G :=\n-- axiom 1: 0 ⊕ a = a\n(zero_gyro : ∀ (a : G), 0 ⊙ a = a)\n-- axiom 2: ⊖a⊕a = 0\n(gyr_add_left_neg : ∀ (a : G), ⊝a ⊙ a = 0)\n(gyr : G → G → G → G) -- gyr a b c is gyr[a, b]c in the notation from the Wiki\n-- axiom 3: ∀ a b c ∈ G, a + (b + c) = (a + b) + gyr a b c\n(add_gyr_assoc : ∀ a b c, a ⊙ (b ⊙ c) = (a ⊙ b) ⊙ gyr a b c)\n(add_gyr_assoc_inj : ∀ a b c d, a ⊙ (b ⊙ c) = (a ⊙ b) ⊙ d → d = gyr a b c) -- uniqueness\n-- axiom 4: gyr a b ∈ Aut (G, ⊙) \n(gyr_bijective : ∀ a b, function.bijective (gyr a b))\n(map_gyrop : ∀ a b c d, gyr a b (c ⊙ d) = gyr a b c ⊙ gyr a b d )\n-- axiom 5: gyr a b = gyr (a + b) b\n(gyr_loop : ∀ a b, gyr a b = gyr (a ⊙ b) b)\n\n-- axiom 4 has been removed and is going to be a seperate function, see below\nvariables (G : Type) [gyrogroup G]\nvariables (a b c d : G)\n\n@[simp] lemma zero_gyro : ∀ (a : G), 0 ⊙ a = a := gyrogroup.zero_gyro\n@[simp] lemma gyr_add_left_neg : ∀ (a : G), ⊝a ⊙ a = 0 := gyrogroup.gyr_add_left_neg\nlemma add_gyr_assoc : ∀ (a b c : G), a ⊙ (b ⊙ c) = (a ⊙ b) ⊙ gyrogroup.gyr a b c := gyrogroup.add_gyr_assoc\nlemma add_gyr_assoc_inj : ∀ (a b c d : G), a ⊙ (b ⊙ c) = (a ⊙ b) ⊙ d → d = gyrogroup.gyr a b c := gyrogroup.add_gyr_assoc_inj \nlemma gyr_bijective : ∀ (a b : G), function.bijective (gyrogroup.gyr a b) := gyrogroup.gyr_bijective\n@[simp] lemma map_gyrop : ∀ (a b c d : G), gyrogroup.gyr a b (c ⊙ d) = gyrogroup.gyr a b c ⊙ gyrogroup.gyr a b d  := gyrogroup.map_gyrop\n@[simp] lemma gyr_loop : ∀ (a b : G), gyrogroup.gyr a b = gyrogroup.gyr (a ⊙ b) b := gyrogroup.gyr_loop\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/non_comm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.753390439231932}}
{"text": "import data.nat.basic \nimport tactic \n\n--Problems taken from https://www.math.upenn.edu/~peal/files/Proof.by.Induction[2018][Eng]-ALEXANDERSSON.pdf\n\nopen nat\n\n--explanation of how guards work and pattern matching. Maybe give more examples\ndef mysum (f : ℕ → ℕ) : ℕ → ℕ\n| 0 := (f 0)\n| (succ k) := (f (succ k)) + (mysum k)\n\ndef factorial : ℕ → ℕ \n| 0 := 1\n| (succ n) := (succ n)*(factorial n)\n\n--TODO: these but using finset instead for comparison. Maybe implement the stuff below using finset as well\n\n--putting 2 on LHS because nat division is weird and I think it's best to \n--avoid it at this level. Could be a good example of \"this thing you took \n--for granted in math hasn't been implemented yet so you have to find a \n--way to say the same thing without using it\"\ntheorem sum_identity_1 (n : ℕ) : 2 * mysum id n = n*(n+1) := \nbegin \n    induction n with k hk,\n    {refl}, \n    {rw mysum,\n    rw mul_add,\n    rw hk,\n    repeat {rw succ_eq_add_one},\n    simp only [add_assoc, add_zero, id.def],\n    ring}\nend \n\ndef square (n : ℕ) : ℕ := n^2 \n\ntheorem sum_identity_2 (n : ℕ) : 6 * mysum square n =  n*(n+1)*(2*n+1)  := \nbegin \n    induction n with k hk,\n    {refl}, \n    {rw mysum,\n    rw mul_add,\n    rw hk,\n    unfold square,\n    repeat {rw succ_eq_add_one},\n    simp only [add_assoc, add_zero],\n    ring}\nend \n\n--could have more similar identities. The proofs are almost all the same. Could be a good confidence building goal to have some examples and then similar problems without solutions.\n\n\n\n#eval factorial 0\n#eval factorial 10\n\n/-discussion of how @[simp] lets you give simp more stuff. Show that before\nthe @[simp] statements the example below doesn't work, but it does after\n-/\n\n-- example : factorial 4 = 4 * factorial 3 := \n-- begin \n--     simp,\n--     ring,\n-- end \n\n@[simp]\nlemma factorial0 : factorial 0 = 1 := rfl\n@[simp]\nlemma factorial1 : factorial 1 = 1 := rfl\n@[simp]\nlemma factorial2 : factorial 2 = 2 := rfl\n@[simp]\nlemma factorial3 : factorial 3 = 6 := rfl\n@[simp]\nlemma factorial4 : factorial 4 = 24 := rfl\n\nexample : factorial 4 = 4 * factorial 3 := \nbegin \n    simp,\n    ring,\nend \n\n--these feel unnecessary, but could be a good teaching moment if we can't fix it?\n@[simp]\nlemma stupid1 (h : 2 ≥ 4) : false := \nbegin\n    linarith,\nend\n@[simp]\nlemma stupid2 (h : 3 ≥ 4) : false :=  --idk why linarith isn't resolving this in my proof\nbegin\n    linarith,\nend\n\nlemma two_pow_nonneg (n : ℕ) : 2 ^ n ≥ 0 := \nbegin \nlinarith,\nend\n\n\n\n--this is a bit long but conceptually I think it's within reach. \n--How could we break it up into multiple steps/subgoals?\ntheorem identity_3 (n : ℕ) (h : n ≥ 4) : factorial n ≥ 2^n := \nbegin \ncases n, linarith,\ncases n, linarith,\ncases n, \n    simp only [ge_iff_le, factorial2, nat_zero_eq_zero, nat.pow_succ], \n    norm_num,\n    apply stupid1,\n    exact h,\ncases n, \n    simp only [ge_iff_le, factorial2, nat_zero_eq_zero, nat.pow_succ], \n    norm_num,\n    apply stupid2,\n    exact h,\nrepeat {rw succ_eq_add_one},\nring,\nclear h,\ninduction n with k hk,\nsimp,\nexact le_add_left (2 ^ 4) (5 + 3),\nrw succ_add,\nrw factorial,\nrw nat.pow_succ,\nhave h1 : succ (k+4) ≥ 2, \n    rw succ_eq_add_one,\n    linarith,\ncalc succ (k + 4) * factorial (k + 4) ≥ succ (k+4) * 2 ^ (k + 4) : by sorry\n    ... ≥ 2*2^(k+4) : by refine mul_mono_nonneg (by linarith) h1\n    ... = 2^(k+4) * 2 : by rw mul_comm\n    ... = 2^succ (k+4) : by rw ← nat.pow_succ,\nend \n\n#check mul_mono_nonneg\n\n\n\n\n--me trying to find these identities in mathlib\nexample (a b c d: ℕ) (h1 : a > b) (h2 : c > d) : a*c > b*d := \nbegin \n    simp,\n    sorry,\nend\n\nexample (a b c : ℕ) (h : a < b) : a*c < b*c := \nbegin \n    sorry,\nend\n\n#check pow_two_nonneg", "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/simple_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895028, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.753390434712342}}
{"text": "-- Pruebas de conc (coge n xs) (elimina n xs) = xs\n-- ===============================================\n\nimport tactic\nopen list\nopen nat\n\nvariable  {α : Type}\nvariable  (x : α)\nvariables (xs ys : list α)\nvariable  (n : ℕ)\n\n-- ----------------------------------------------------\n-- Nota. Se usará la definición y propiedades de la\n-- función conc estudiadas anteriormente.\n-- ----------------------------------------------------\n\ndef conc : list α → list α → list α\n| []        ys := ys\n| (x :: xs) ys := x :: (conc xs ys)\n\n@[simp]\nlemma conc_nil :\n  conc ([] : list α) ys = ys :=\nrfl\n\n@[simp]\nlemma conc_cons :\n  conc (x :: xs) ys = x :: (conc xs ys) :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 1. Definir la función\n--    coge : ℕ → list α → list α\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\ndef coge : ℕ → list α → list α\n| 0        _         := []\n| (succ _) []        := []\n| (succ n) (x :: xs) := x :: coge n xs\n\n-- #eval coge 2 [1,4,2,7]\n\n-- ----------------------------------------------------\n-- Ejercicio 2. 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\n@[simp]\nlemma coge_cero :\n  coge 0 xs = [] :=\nrfl\n\n@[simp]\nlemma coge_nil :\n  ∀ n, coge n ([] : list α) = []\n| 0     := rfl\n| (n+1) := rfl\n\n@[simp]\nlemma coge_cons :\n  coge (succ n) (x :: xs) = x :: coge n xs :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 3. Definir la función\n--    elimina : ℕ → list α → list α\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\ndef elimina : ℕ → list α → list α\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-- Ejercicio 4. 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\n@[simp]\nlemma elimina_cero :\n  elimina 0 xs = xs :=\nrfl\n\n@[simp]\nlemma elimina_nil :\n  ∀ n, elimina n ([] : list α) = []\n| 0     := rfl\n| (n+1) := rfl\n\n@[simp]\nlemma elimina_cons :\n  elimina (succ n) (x :: xs) = elimina n xs :=\nrfl\n\n-- ----------------------------------------------------\n-- Ejercicio 5. (p. 35) Demostrar que\n--    conc (coge n xs) (elimina n xs) = xs\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample :\n  ∀ xs : list α, conc (coge n xs) (elimina n xs) = xs :=\nbegin\n  induction n with m HI1,\n  { intro,\n    rw coge_cero,\n    rw elimina_cero,\n    rw conc_nil, },\n  { intro,\n    induction xs with a as HI2,\n    { rw coge_nil,\n      rw elimina_nil,\n      rw conc_nil, },\n    { rw coge_cons,\n      rw elimina_cons,\n      rw conc_cons,\n      rw (HI1 as), }, },\nend\n\n-- 2ª demostración\nexample :\n  ∀ xs : list α, conc (coge n xs) (elimina n xs) = xs :=\nbegin\n  induction n with m HI1,\n  { intro,\n    calc conc (coge 0 xs) (elimina 0 xs)\n         = conc [] (elimina 0 xs) : by rw coge_cero\n     ... = conc [] xs             : by rw elimina_cero\n     ... = xs                     : by rw conc_nil, },\n  { intro,\n    induction xs with a as HI2,\n    { calc conc (coge (succ m) []) (elimina (succ m) [])\n           = conc ([] : list α) (elimina (succ m) []) : by rw coge_nil\n       ... = conc [] []                               : by rw elimina_nil\n       ... = []                                       : by rw conc_nil, },\n    { calc conc (coge (succ m) (a :: as)) (elimina (succ m) (a :: as))\n           = conc (a :: coge m as) (elimina (succ m) (a :: as)) :by rw coge_cons\n       ... = conc (a :: coge m as) (elimina m as)               :by rw elimina_cons\n       ... = a :: conc (coge m as) (elimina m as)               :by rw conc_cons\n       ... = a :: as                                            :by rw (HI1 as), }, },\nend\n\n-- 3ª demostración\nexample :\n  ∀ xs : list α, conc (coge n xs) (elimina n xs) = xs :=\nbegin\n  induction n with m HI1,\n  { intro,\n    simp, },\n  { intro,\n    induction xs with a as HI2,\n    { simp, },\n    { simp [HI1 as], }, },\nend\n\n-- 4ª demostración\nexample :\n  ∀ xs : list α, conc (coge n xs) (elimina n xs) = xs :=\nnat.rec_on n\n  ( assume xs,\n    show conc (coge 0 xs) (elimina 0 xs) = xs, from\n      calc conc (coge 0 xs) (elimina 0 xs)\n           = conc ([] : list α) (elimina 0 xs) : by rw coge_cero\n       ... = conc [] xs                        : by rw elimina_cero\n       ... = xs                                : by rw conc_nil)\n  ( assume m,\n    assume HI1 : ∀ xs, conc (coge m xs) (elimina m xs) = xs,\n    assume xs,\n    show conc (coge (succ m) xs) (elimina (succ m) xs) = xs, from\n      list.rec_on xs\n      ( show conc (coge (succ m) []) (elimina (succ m) []) = [], from\n          calc conc (coge (succ m) []) (elimina (succ m) [])\n                     = conc ([] : list α) (elimina (succ m) []) : by rw coge_nil\n                 ... = conc [] []                               : by rw elimina_nil\n                 ... = []                                       : by rw conc_nil)\n      ( assume a as,\n        assume HI2 : conc (coge (succ m) as) (elimina (succ m) as) = as,\n        show conc (coge (succ m) (a :: as)) (elimina (succ m) (a :: as)) = a :: as, from\n          calc conc (coge (succ m) (a :: as)) (elimina (succ m) (a :: as))\n                     = conc (a :: coge m as) (elimina (succ m) (a :: as)) :by rw coge_cons\n                 ... = conc (a :: coge m as) (elimina m as)               :by rw elimina_cons\n                 ... = a :: conc (coge m as) (elimina m as)               :by rw conc_cons\n                 ... = a :: as                                            :by rw (HI1 as)))\n\n-- 5ª demostración\nexample :\n  ∀ xs : list α, conc (coge n xs) (elimina n xs) = xs :=\nnat.rec_on n\n  (by simp)\n  (λ m HI1 xs, list.rec_on xs\n    (by simp)\n    (by simp [HI1]))\n\n-- 6ª demostración\nlemma conc_coge_elimina_1 :\n  ∀ (n : ℕ) (xs : list α), 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)                                : by rw coge_cero\n    ... = conc [] xs                                            : by rw elimina_cero\n    ... = xs                                                    : by rw conc_nil\n| (succ m) [] := by calc\n    conc (coge (succ m) []) (elimina (succ m) [])\n        = conc ([] : list α) (elimina (succ m) [])              : by rw coge_nil\n    ... = conc [] []                                            : by rw elimina_nil\n    ... = []                                                    : by rw conc_nil\n| (succ m) (a :: as) := by calc\n    conc (coge (succ m) (a :: as)) (elimina (succ m) (a :: as))\n        = conc (a :: coge m as) (elimina (succ m) (a :: as))    : by rw coge_cons\n    ... = conc (a :: coge m as) (elimina m as)                  : by rw elimina_cons\n    ... = a :: conc (coge m as) (elimina m as)                  : by rw conc_cons\n    ... = a :: as                                               : by rw conc_coge_elimina_1\n\n-- 7ª demostración\nlemma conc_coge_elimina_2 :\n  ∀ (n : ℕ) (xs : list α), conc (coge n xs) (elimina n xs) = xs\n| 0        xs        := by simp\n| (succ m) []        := by simp\n| (succ m) (a :: as) := by simp [conc_coge_elimina_2]\n\n-- 8ª demostración\nlemma conc_coge_elimina_3 :\n  ∀ (n : ℕ) (xs : list α), conc (coge n xs) (elimina n xs) = xs\n| 0        xs        := rfl\n| (succ m) []        := rfl\n| (succ m) (a :: as) := congr_arg (cons a) (conc_coge_elimina_3 m as)\n\n-- Comentarios sobre las funciones take y drop:\n-- + Para usarlas hay que importar la librería\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 calcular. Por ejemplo,\n--      #eval take 2 [1,4,2,7]\n--      #eval drop 2 [1,4,2,7,0]\n-- + Se puede demostrar. Por ejemplo,\nexample : take n xs ++ drop n xs = xs :=\n-- by library_search\ntake_append_drop n xs\n\nlemma take_drop_1 :\n  ∀ (n : ℕ) (xs : list α), take n xs ++ drop n xs = xs\n| 0        xs        := by simp\n| (succ n) []        := by simp\n| (succ n) (x :: xs) := by simp [take_drop_1]\n\nexample : take n xs ++ drop n xs = xs :=\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/7_Programas/Pruebas_de_conc_(coge_n_xs)_(elimina_n_xs)_Ig_xs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.7533038884894434}}
{"text": "/-\n# Proposition world. \n\n## Level 6: `(P → (Q → R)) → ((P → Q) → (P → 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 `have j : Q → R := f p` if `f : P → (Q → R)`\nand `p : P`. I recommend that you start with `intro f` rather than `intro p`\nbecause even though the goal starts `P → ...`, the brackets mean that\nthe goal is not the statement that `P` implies anything, it's the statement that\n$P\\implies (Q\\implies R)$ implies something. In fact I'd recommend that you started\nwith `intros f h p`, which introduces three variables at once.\nYou then find that your your goal is `⊢ R`. If you try `have j : Q → 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\n/- Lemma : no-side-bar\nIf $P$ and $Q$ and $R$ are true/false statements, then\n$$(P\\implies(Q\\implies R))\\implies((P\\implies Q)\\implies(P\\implies R)).$$\n-/\nexample (P Q R : Prop) : (P → (Q → R)) → ((P → Q) → (P → R)) :=\nbegin\n  intro f,\n  intro h,\n  intro p,\n  have j : Q → R := f p,\n  apply j,\n  apply h,\n  exact p,\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/world6/level6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404096760998, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7532918510357425}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Mario Carneiro, Floris van Doorn\n-/\nimport set_theory.ordinal\n\n/-!\n# Ordinal arithmetic\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₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that\n  every element of `o₁` is smaller than every element of `o₂`.\n* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.\n* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.\n* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the\n  divisibility predicate, and a modulo operation.\n* `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 also define the power function and the logarithm function on ordinals, and discuss the properties\nof casts of natural numbers of and of `omega` with respect to these operations.\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\n* `is_normal`: a function `f : ordinal → 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* `nfp f a`: the next fixed point of a function `f` on ordinals, above `a`. It behaves well\n  for normal functions.\n\n* `CNF b o` is the Cantor normal form of the ordinal `o` in base `b`.\n\n* `sup`: the supremum of an indexed family of ordinals in `Type u`, as an ordinal in `Type u`.\n* `bsup`: the supremum of a set of ordinals indexed by ordinals less than a given ordinal `o`.\n-/\n\nnoncomputable theory\n\nopen function cardinal set equiv\nopen_locale classical cardinal\n\nuniverses u v w\nvariables {α : Type*} {β : Type*} {γ : Type*}\n  {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}\n\nnamespace ordinal\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₂ a b $ λ ⟨α, r, _⟩ ⟨β, s, _⟩,\nquotient.sound ⟨(rel_iso.preimage equiv.ulift _).trans\n (rel_iso.sum_lex_congr (rel_iso.preimage equiv.ulift _)\n   (rel_iso.preimage equiv.ulift _)).symm⟩\n\n@[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) :=\nby unfold succ; simp only [lift_add, lift_one]\n\ntheorem add_le_add_iff_left (a) {b c : ordinal} : a + b ≤ a + c ↔ b ≤ c :=\n⟨induction_on a $ λ α r hr, induction_on b $ λ β₁ s₁ hs₁, induction_on c $ λ β₂ s₂ hs₂ ⟨f⟩, ⟨\n  have fl : ∀ a, f (sum.inl a) = sum.inl a := λ 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₂)\n        ((initial_seg.le_add r s₁).trans f) (initial_seg.le_add r s₂) a,\n  have ∀ b, {b' // f (sum.inr b) = sum.inr b'}, begin\n    intro b, cases e : f (sum.inr b),\n    { rw ← fl at e, have := f.inj' e, contradiction },\n    { exact ⟨_, rfl⟩ }\n  end,\n  let g (b) := (this b).1 in\n  have fr : ∀ b, f (sum.inr b) = sum.inr (g b), from λ b, (this b).2,\n  ⟨⟨⟨g, λ x y h, by injection f.inj'\n    (by rw [fr, fr, h] : f (sum.inr x) = f (sum.inr y))⟩,\n    λ a b, by simpa only [sum.lex_inr_inr, fr, rel_embedding.coe_fn_to_embedding,\n        initial_seg.coe_fn_to_rel_embedding, function.embedding.coe_fn_mk]\n      using @rel_embedding.map_rel_iff _ _ _ _ f.to_rel_embedding (sum.inr a) (sum.inr b)⟩,\n    λ a b H, begin\n      rcases f.init' (by rw fr; exact sum.lex_inr_inr.2 H) with ⟨a'|a', h⟩,\n      { rw fl at h, cases h },\n      { rw fr at h, exact ⟨a', sum.inr.inj h⟩ }\n    end⟩⟩,\nλ h, add_le_add_left h _⟩\n\ntheorem add_succ (o₁ o₂ : ordinal) : o₁ + succ o₂ = succ (o₁ + o₂) :=\n(add_assoc _ _ _).symm\n\n@[simp] theorem succ_zero : succ 0 = 1 := zero_add _\n\ntheorem one_le_iff_pos {o : ordinal} : 1 ≤ o ↔ 0 < o :=\nby rw [← succ_zero, succ_le]\n\ntheorem one_le_iff_ne_zero {o : ordinal} : 1 ≤ o ↔ o ≠ 0 :=\nby rw [one_le_iff_pos, ordinal.pos_iff_ne_zero]\n\ntheorem succ_pos (o : ordinal) : 0 < succ o :=\nlt_of_le_of_lt (ordinal.zero_le _) (lt_succ_self _)\n\ntheorem succ_ne_zero (o : ordinal) : succ o ≠ 0 :=\nne_of_gt $ succ_pos o\n\n@[simp] theorem card_succ (o : ordinal) : card (succ o) = card o + 1 :=\nby simp only [succ, card_add, card_one]\n\ntheorem nat_cast_succ (n : ℕ) : (succ n : ordinal) = n.succ := rfl\n\ntheorem add_left_cancel (a) {b c : ordinal} : a + b = a + c ↔ b = c :=\nby simp only [le_antisymm_iff, add_le_add_iff_left]\n\ntheorem lt_succ {a b : ordinal} : a < succ b ↔ a ≤ b :=\nby rw [← not_le, succ_le, not_lt]\n\ntheorem add_lt_add_iff_left (a) {b c : ordinal} : a + b < a + c ↔ b < c :=\nby rw [← not_le, ← not_le, add_le_add_iff_left]\n\ntheorem lt_of_add_lt_add_right {a b c : ordinal} : a + b < c + b → a < c :=\nlt_imp_lt_of_le_imp_le (λ h, add_le_add_right h _)\n\n@[simp] theorem succ_lt_succ {a b : ordinal} : succ a < succ b ↔ a < b :=\nby rw [lt_succ, succ_le]\n\n@[simp] theorem succ_le_succ {a b : ordinal} : succ a ≤ succ b ↔ a ≤ b :=\nle_iff_le_iff_lt_iff_lt.2 succ_lt_succ\n\ntheorem succ_inj {a b : ordinal} : succ a = succ b ↔ a = b :=\nby simp only [le_antisymm_iff, succ_le_succ]\n\ntheorem add_le_add_iff_right {a b : ordinal} (n : ℕ) : a + n ≤ b + n ↔ a ≤ b :=\nby induction n with n ih; [rw [nat.cast_zero, add_zero, add_zero],\n  rw [← nat_cast_succ, add_succ, add_succ, succ_le_succ, ih]]\n\ntheorem add_right_cancel {a b : ordinal} (n : ℕ) : a + n = b + n ↔ a = b :=\nby simp only [le_antisymm_iff, add_le_add_iff_right]\n\n/-! ### The zero ordinal -/\n\n@[simp] theorem card_eq_zero {o} : card o = 0 ↔ o = 0 :=\n⟨induction_on o $ λ α r _ h, begin\n  refine le_antisymm (le_of_not_lt $\n    λ hn, ne_zero_iff_nonempty.2 _ h) (ordinal.zero_le _),\n  rw [← succ_le, succ_zero] at hn, cases hn with f,\n  exact ⟨f punit.star⟩\nend, λ e, by simp only [e, card_zero]⟩\n\ntheorem type_ne_zero_iff_nonempty [is_well_order α r] : type r ≠ 0 ↔ nonempty α :=\n(not_congr (@card_eq_zero (type r))).symm.trans ne_zero_iff_nonempty\n\n@[simp] theorem type_eq_zero_iff_empty [is_well_order α r] : type r = 0 ↔ ¬ nonempty α :=\n(not_iff_comm.1 type_ne_zero_iff_nonempty).symm\n\nprotected lemma one_ne_zero : (1 : ordinal) ≠ 0 :=\ntype_ne_zero_iff_nonempty.2 ⟨punit.star⟩\n\ninstance : nontrivial ordinal.{u} :=\n⟨⟨1, 0, ordinal.one_ne_zero⟩⟩\n\ntheorem zero_lt_one : (0 : ordinal) < 1 :=\nlt_iff_le_and_ne.2 ⟨ordinal.zero_le _, ne.symm $ ordinal.one_ne_zero⟩\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.{u}) : ordinal.{u} :=\nif h : ∃ a, o = succ a then classical.some h else o\n\n@[simp] theorem pred_succ (o) : pred (succ o) = o :=\nby have h : ∃ a, succ o = succ a := ⟨_, rfl⟩;\n   simpa only [pred, dif_pos h] using (succ_inj.1 $ classical.some_spec h).symm\n\ntheorem pred_le_self (o) : pred o ≤ o :=\nif h : ∃ a, o = succ a then let ⟨a, e⟩ := h in\nby rw [e, pred_succ]; exact le_of_lt (lt_succ_self _)\nelse by rw [pred, dif_neg h]\n\ntheorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬ ∃ a, o = succ a :=\n⟨λ e ⟨a, e'⟩, by rw [e', pred_succ] at e; exact ne_of_lt (lt_succ_self _) e,\n λ h, dif_neg h⟩\n\ntheorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ 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\ntheorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=\n⟨λ e, ⟨_, e.symm⟩, λ ⟨a, e⟩, by simp only [e, pred_succ]⟩\n\ntheorem succ_lt_of_not_succ {o} (h : ¬ ∃ a, o = succ a) {b} : succ b < o ↔ b < o :=\n⟨lt_trans (lt_succ_self _), λ l,\n  lt_of_le_of_ne (succ_le.2 l) (λ e, h ⟨_, e.symm⟩)⟩\n\ntheorem lt_pred {a b} : a < pred b ↔ succ a < b :=\nif h : ∃ a, b = succ a then let ⟨c, e⟩ := h in\nby rw [e, pred_succ, succ_lt_succ]\nelse by simp only [pred, dif_neg h, succ_lt_of_not_succ h]\n\ntheorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=\nle_iff_le_iff_lt_iff_lt.2 lt_pred\n\n@[simp] theorem lift_is_succ {o} : (∃ a, lift o = succ a) ↔ (∃ a, o = succ a) :=\n⟨λ ⟨a, h⟩,\n  let ⟨b, e⟩ := lift_down $ show a ≤ lift o, from le_of_lt $\n    h.symm ▸ lt_succ_self _ in\n  ⟨b, lift_inj.1 $ by rw [h, ← e, lift_succ]⟩,\n λ ⟨a, h⟩, ⟨lift a, by simp only [h, lift_succ]⟩⟩\n\n@[simp] theorem lift_pred (o) : lift (pred o) = pred (lift o) :=\nif h : ∃ 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 ≠ 0 ∧ ∀ a < o, succ a < o\n\ntheorem not_zero_is_limit : ¬ is_limit 0\n| ⟨h, _⟩ := h rfl\n\ntheorem not_succ_is_limit (o) : ¬ is_limit (succ o)\n| ⟨_, h⟩ := lt_irrefl _ (h _ (lt_succ_self _))\n\ntheorem not_succ_of_is_limit {o} (h : is_limit o) : ¬ ∃ a, o = succ a\n| ⟨a, e⟩ := not_succ_is_limit a (e ▸ h)\n\ntheorem succ_lt_of_is_limit {o} (h : is_limit o) {a} : succ a < o ↔ a < o :=\n⟨lt_trans (lt_succ_self _), h.2 _⟩\n\ntheorem le_succ_of_is_limit {o} (h : is_limit o) {a} : o ≤ succ a ↔ o ≤ 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 ≤ a ↔ ∀ x < o, x ≤ a :=\n⟨λ h x l, le_trans (le_of_lt l) h,\n λ H, (le_succ_of_is_limit h).1 $ le_of_not_lt $ λ hn,\n  not_lt_of_le (H _ hn) (lt_succ_self _)⟩\n\ntheorem lt_limit {o} (h : is_limit o) {a} : a < o ↔ ∃ 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) ↔ is_limit o :=\nand_congr (not_congr $ by simpa only [lift_zero] using @lift_inj o 0)\n⟨λ H a h, lift_lt.1 $ by simpa only [lift_succ] using H _ (lift_lt.2 h),\n λ H a h, let ⟨a', e⟩ := lift_down (le_of_lt h) in\n   by rw [← e, ← lift_succ, lift_lt];\n      rw [← e, lift_lt] at h; exact H a' h⟩\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\ntheorem is_limit.nat_lt {o : ordinal} (h : is_limit o) : ∀ n : ℕ, (n : ordinal) < o\n| 0     := h.pos\n| (n+1) := h.2 _ (is_limit.nat_lt n)\n\ntheorem zero_or_succ_or_limit (o : ordinal) :\n  o = 0 ∨ (∃ a, o = succ a) ∨ is_limit o :=\nif o0 : o = 0 then or.inl o0 else\nif h : ∃ a, o = succ a then or.inr (or.inl h) else\nor.inr $ or.inr ⟨o0, λ a, (succ_lt_of_not_succ h).2⟩\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 → Sort*}\n  (o : ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o))\n  (H₃ : ∀ o, is_limit o → (∀ o' < o, C o') → C o) : C o :=\nwf.fix (λ o IH,\n  if o0 : o = 0 then by rw o0; exact H₁ else\n  if h : ∃ a, o = succ a then\n    by rw ← succ_pred_iff_is_succ.2 h; exact\n    H₂ _ (IH _ $ pred_lt_iff_is_succ.2 h)\n  else H₃ _ ⟨o0, λ a, (succ_lt_of_not_succ h).2⟩ IH) o\n\n@[simp] theorem limit_rec_on_zero {C} (H₁ H₂ H₃) : @limit_rec_on C 0 H₁ H₂ H₃ = H₁ :=\nby rw [limit_rec_on, well_founded.fix_eq, dif_pos rfl]; refl\n\n@[simp] theorem limit_rec_on_succ {C} (o H₁ H₂ H₃) :\n  @limit_rec_on C (succ o) H₁ H₂ H₃ = H₂ o (@limit_rec_on C o H₁ H₂ H₃) :=\nbegin\n  have h : ∃ a, succ o = succ a := ⟨_, rfl⟩,\n  rw [limit_rec_on, well_founded.fix_eq,\n      dif_neg (succ_ne_zero o), dif_pos h],\n  generalize : limit_rec_on._proof_2 (succ o) h = h₂,\n  generalize : limit_rec_on._proof_3 (succ o) h = h₃,\n  revert h₂ h₃, 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₁ H₂ H₃ h) :\n  @limit_rec_on C o H₁ H₂ H₃ = H₃ o h (λ x h, @limit_rec_on C x H₁ H₂ H₃) :=\nby rw [limit_rec_on, well_founded.fix_eq,\n       dif_neg h.1, dif_neg (not_succ_of_is_limit h)]; refl\n\nlemma has_succ_of_is_limit {α} {r : α → α → Prop} [wo : is_well_order α r]\n  (h : (type r).is_limit) (x : α) : ∃y, r x y :=\nbegin\n  use enum r (typein r x).succ (h.2 _ (typein_lt_type r x)),\n  convert (enum_lt (typein_lt_type r x) _).mpr (lt_succ_self _), rw [enum_typein]\nend\n\nlemma type_subrel_lt (o : ordinal.{u}) :\n  type (subrel (<) {o' : ordinal | o' < o}) = ordinal.lift.{u u+1} o :=\nbegin\n  refine quotient.induction_on o _,\n  rintro ⟨α, r, wo⟩, resetI, apply quotient.sound,\n  constructor, symmetry, refine (rel_iso.preimage equiv.ulift r).trans (typein_iso r)\nend\n\nlemma mk_initial_seg (o : ordinal.{u}) :\n  #{o' : ordinal | o' < o} = cardinal.lift.{u u+1} o.card :=\nby rw [lift_card, ←type_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 → ordinal) : Prop :=\n(∀ o, f o < f (succ o)) ∧ ∀ o, is_limit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a\n\ntheorem is_normal.limit_le {f} (H : is_normal f) : ∀ {o}, is_limit o →\n  ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a := H.2\n\ntheorem is_normal.limit_lt {f} (H : is_normal f) {o} (h : is_limit o) {a} :\n  a < f o ↔ ∃ 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.lt_iff {f} (H : is_normal f) {a b} : f a < f b ↔ a < b :=\nstrict_mono.lt_iff_lt $ λ a b,\nlimit_rec_on b (not.elim (not_lt_of_le $ ordinal.zero_le _))\n  (λ b IH h, (lt_or_eq_of_le (lt_succ.1 h)).elim\n    (λ h, lt_trans (IH h) (H.1 _))\n    (λ e, e ▸ H.1 _))\n  (λ b l IH h, lt_of_lt_of_le (H.1 a)\n    ((H.2 _ l _).1 (le_refl _) _ (l.2 _ h)))\n\ntheorem is_normal.le_iff {f} (H : is_normal f) {a b} : f a ≤ f b ↔ a ≤ 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 ↔ a = b :=\nby simp only [le_antisymm_iff, H.le_iff]\n\ntheorem is_normal.le_self {f} (H : is_normal f) (a) : a ≤ f a :=\nlimit_rec_on a (ordinal.zero_le _)\n  (λ a IH, succ_le.2 $ lt_of_le_of_lt IH (H.1 _))\n  (λ a l IH, (limit_le l).2 $ λ b h,\n    le_trans (IH b h) $ H.le_iff.2 $ le_of_lt h)\n\ntheorem is_normal.le_set {f} (H : is_normal f) (p : ordinal → Prop)\n  (p0 : ∃ x, p x) (S)\n  (H₂ : ∀ o, S ≤ o ↔ ∀ a, p a → a ≤ o) {o} :\n  f S ≤ o ↔ ∀ a, p a → f a ≤ o :=\n⟨λ h a pa, le_trans (H.le_iff.2 ((H₂ _).1 (le_refl _) _ pa)) h,\nλ h, begin\n  revert H₂, apply limit_rec_on S,\n  { intro H₂,\n     cases p0 with x px,\n     have := ordinal.le_zero.1 ((H₂ _).1 (ordinal.zero_le _) _ px),\n     rw this at px, exact h _ px },\n  { intros S _ H₂,\n    rcases not_ball.1 (mt (H₂ S).2 $ not_le_of_lt $ lt_succ_self _) with ⟨a, h₁, h₂⟩,\n    exact le_trans (H.le_iff.2 $ succ_le.2 $ not_le.1 h₂) (h _ h₁) },\n  { intros S L _ H₂, apply (H.2 _ L _).2, intros a h',\n    rcases not_ball.1 (mt (H₂ a).2 (not_le.2 h')) with ⟨b, h₁, h₂⟩,\n    exact le_trans (H.le_iff.2 $ le_of_lt $ not_le.1 h₂) (h _ h₁) }\nend⟩\n\ntheorem is_normal.le_set' {f} (H : is_normal f) (p : α → Prop) (g : α → ordinal)\n  (p0 : ∃ x, p x) (S)\n  (H₂ : ∀ o, S ≤ o ↔ ∀ a, p a → g a ≤ o) {o} :\n  f S ≤ o ↔ ∀ a, p a → f (g a) ≤ o :=\n(H.le_set (λ x, ∃ y, p y ∧ x = g y)\n  (let ⟨x, px⟩ := p0 in ⟨_, _, px, rfl⟩) _\n  (λ o, (H₂ o).trans ⟨λ H a ⟨y, h1, h2⟩, h2.symm ▸ H y h1,\n    λ H a h1, H (g a) ⟨a, h1, rfl⟩⟩)).trans\n⟨λ H a h, H (g a) ⟨a, h, rfl⟩, λ H a ⟨y, h1, h2⟩, h2.symm ▸ H y h1⟩\n\ntheorem is_normal.refl : is_normal id :=\n⟨λ x, lt_succ_self _, λ o l a, limit_le l⟩\n\ntheorem is_normal.trans {f g} (H₁ : is_normal f) (H₂ : is_normal g) :\n  is_normal (λ x, f (g x)) :=\n⟨λ x, H₁.lt_iff.2 (H₂.1 _),\n λ o l a, H₁.le_set' (< o) g ⟨_, l.pos⟩ _ (λ c, H₂.2 _ l _)⟩\n\ntheorem is_normal.is_limit {f} (H : is_normal f) {o} (l : is_limit o) :\n  is_limit (f o) :=\n⟨ne_of_gt $ lt_of_le_of_lt (ordinal.zero_le _) $ H.lt_iff.2 l.pos,\nλ a h, let ⟨b, h₁, h₂⟩ := (H.limit_lt l).1 h in\n  lt_of_le_of_lt (succ_le.2 h₂) (H.lt_iff.2 h₁)⟩\n\ntheorem add_le_of_limit {a b c : ordinal.{u}}\n  (h : is_limit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=\n⟨λ h b' l, le_trans (add_le_add_left (le_of_lt l) _) h,\nλ H, le_of_not_lt $\ninduction_on a (λ α r _, induction_on b $ λ β s _ h H l, begin\n  resetI,\n  suffices : ∀ x : β, 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 [← typein_lt_typein (sum.lex r s), typein_enum],\n  have := H _ (h.2 _ (typein_lt_type s x)),\n  rw [add_succ, succ_le] at this,\n  refine lt_of_le_of_lt (type_le'.2\n    ⟨rel_embedding.of_monotone (λ a, _) (λ a b, _)⟩) this,\n  { rcases a with ⟨a | b, h⟩,\n    { exact sum.inl a },\n    { exact sum.inr ⟨b, by cases h; assumption⟩ } },\n  { rcases a with ⟨a | a, h₁⟩; rcases b with ⟨b | b, h₂⟩; cases h₁; cases h₂;\n      rintro ⟨⟩; constructor; assumption }\nend) h H⟩\n\ntheorem add_is_normal (a : ordinal) : is_normal ((+) a) :=\n⟨λ b, (add_lt_add_iff_left a).2 (lt_succ_self _),\n λ b l c, add_le_of_limit l⟩\n\ntheorem add_is_limit (a) {b} : is_limit b → is_limit (a + b) :=\n(add_is_normal a).is_limit\n\n/-! ### Subtraction on ordinals-/\n\n/-- `a - b` is the unique ordinal satisfying\n  `b + (a - b) = a` when `b ≤ a`. -/\ndef sub (a b : ordinal.{u}) : ordinal.{u} :=\nomin {o | a ≤ b+o} ⟨a, le_add_left _ _⟩\n\ninstance : has_sub ordinal := ⟨sub⟩\n\ntheorem le_add_sub (a b : ordinal) : a ≤ b + (a - b) :=\nomin_mem {o | a ≤ b+o} _\n\ntheorem sub_le {a b c : ordinal} : a - b ≤ c ↔ a ≤ b + c :=\n⟨λ h, le_trans (le_add_sub a b) (add_le_add_left h _),\n λ h, omin_le h⟩\n\ntheorem lt_sub {a b c : ordinal} : a < b - c ↔ 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_refl _)\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 ▸ add_sub_cancel _ _\n\ntheorem sub_le_self (a b : ordinal) : a - b ≤ a :=\nsub_le.2 $ le_add_left _ _\n\ntheorem add_sub_cancel_of_le {a b : ordinal} (h : b ≤ a) : b + (a - b) = a :=\nle_antisymm begin\n  rcases zero_or_succ_or_limit (a-b) with e|⟨c,e⟩|l,\n  { simp only [e, add_zero, h] },\n  { rw [e, add_succ, succ_le, ← lt_sub, e], apply lt_succ_self },\n  { exact (add_le_of_limit l).2 (λ c l, le_of_lt (lt_sub.1 l)) }\nend (le_add_sub _ _)\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 ← 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\ntheorem sub_eq_zero_iff_le {a b : ordinal} : a - b = 0 ↔ a ≤ b :=\n⟨λ h, by simpa only [h, add_zero] using le_add_sub a b,\n λ h, by rwa [← ordinal.le_zero, sub_le, add_zero]⟩\n\ntheorem sub_sub (a b c : ordinal) : a - b - c = a - (b + c) :=\neq_of_forall_ge_iff $ λ d, by rw [sub_le, sub_le, sub_le, add_assoc]\n\ntheorem add_sub_add_cancel (a b c : ordinal) : a + b - (a + c) = b - c :=\nby rw [← sub_sub, add_sub_cancel]\n\ntheorem sub_is_limit {a b} (l : is_limit a) (h : b < a) : is_limit (a - b) :=\n⟨ne_of_gt $ lt_sub.2 $ by rwa add_zero,\n λ c h, by rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩\n\n@[simp] theorem one_add_omega : 1 + omega.{u} = omega :=\nbegin\n  refine le_antisymm _ (le_add_left _ _),\n  rw [omega, one_eq_lift_type_unit, ← lift_add, lift_le, type_add],\n  have : is_well_order unit empty_relation := by apply_instance,\n  refine ⟨rel_embedding.collapse (rel_embedding.of_monotone _ _)⟩,\n  { apply sum.rec, exact λ _, 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 : omega ≤ o) : 1 + o = o :=\nby rw [← add_sub_cancel_of_le h, ← add_assoc, one_add_omega]\n\n/-! ### Multiplication of ordinals-/\n\n/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on\n`o₂ × o₁`. -/\ninstance : monoid ordinal.{u} :=\n{ mul := λ a b, quotient.lift_on₂ a b\n      (λ ⟨α, r, wo⟩ ⟨β, s, wo'⟩, ⟦⟨β × α, prod.lex s r, by exactI prod.lex.is_well_order⟩⟧\n        : Well_order → Well_order → ordinal) $\n    λ ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩,\n    quot.sound ⟨rel_iso.prod_lex_congr g f⟩,\n  one := 1,\n  mul_assoc := λ a b c, quotient.induction_on₃ a b c $ λ ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩,\n    eq.symm $ quotient.sound ⟨⟨prod_assoc _ _ _, λ a b, begin\n      rcases a with ⟨⟨a₁, a₂⟩, a₃⟩,\n      rcases b with ⟨⟨b₁, b₂⟩, b₃⟩,\n      simp [prod.lex_def, and_or_distrib_left, or_assoc, and_assoc]\n    end⟩⟩,\n  mul_one := λ a, induction_on a $ λ α r _, quotient.sound\n    ⟨⟨punit_prod _, λ a b, by rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩;\n    simp only [prod.lex_def, empty_relation, false_or];\n    simp only [eq_self_iff_true, true_and]; refl⟩⟩,\n  one_mul := λ a, induction_on a $ λ α r _, quotient.sound\n    ⟨⟨prod_punit _, λ a b, by rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩;\n    simp only [prod.lex_def, empty_relation, and_false, or_false]; refl⟩⟩ }\n\n@[simp] theorem type_mul {α β : Type u} (r : α → α → Prop) (s : β → β → Prop)\n  [is_well_order α r] [is_well_order β s] : type r * type s = type (prod.lex s r) := rfl\n\n@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=\nquotient.induction_on₂ a b $ λ ⟨α, r, _⟩ ⟨β, s, _⟩,\nquotient.sound ⟨(rel_iso.preimage equiv.ulift _).trans\n (rel_iso.prod_lex_congr (rel_iso.preimage equiv.ulift _)\n   (rel_iso.preimage equiv.ulift _)).symm⟩\n\n@[simp] theorem card_mul (a b) : card (a * b) = card a * card b :=\nquotient.induction_on₂ a b $ λ ⟨α, r, _⟩ ⟨β, s, _⟩,\nmul_comm (mk β) (mk α)\n\n@[simp] theorem mul_zero (a : ordinal) : a * 0 = 0 :=\ninduction_on a $ λ α _ _, by exactI\ntype_eq_zero_iff_empty.2 (λ ⟨⟨e, _⟩⟩, e.elim)\n\n@[simp] theorem zero_mul (a : ordinal) : 0 * a = 0 :=\ninduction_on a $ λ α _ _, by exactI\ntype_eq_zero_iff_empty.2 (λ ⟨⟨_, e⟩⟩, e.elim)\n\ntheorem mul_add (a b c : ordinal) : a * (b + c) = a * b + a * c :=\nquotient.induction_on₃ a b c $ λ ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩,\nquotient.sound ⟨⟨sum_prod_distrib _ _ _, begin\n  rintro ⟨a₁|a₁, a₂⟩ ⟨b₁|b₁, b₂⟩; 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⟩⟩\n\n@[simp] theorem mul_add_one (a b : ordinal) : a * (b + 1) = a * b + a :=\nby simp only [mul_add, mul_one]\n\n@[simp] theorem mul_succ (a b : ordinal) : a * succ b = a * b + a := mul_add_one _ _\n\ntheorem mul_le_mul_left {a b} (c : ordinal) : a ≤ b → c * a ≤ c * b :=\nquotient.induction_on₃ a b c $ λ ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩, begin\n  resetI,\n  refine type_le'.2 ⟨rel_embedding.of_monotone\n    (λ a, (f a.1, a.2))\n    (λ a b h, _)⟩, clear_,\n  cases h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h',\n  { exact prod.lex.left _ _ (f.to_rel_embedding.map_rel_iff.2 h') },\n  { exact prod.lex.right _ h' }\nend\n\ntheorem mul_le_mul_right {a b} (c : ordinal) : a ≤ b → a * c ≤ b * c :=\nquotient.induction_on₃ a b c $ λ ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩, begin\n  resetI,\n  refine type_le'.2 ⟨rel_embedding.of_monotone\n    (λ a, (a.1, f a.2))\n    (λ a b h, _)⟩,\n  cases h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h',\n  { exact prod.lex.left _ _ h' },\n  { exact prod.lex.right _ (f.to_rel_embedding.map_rel_iff.2 h') }\nend\n\ntheorem mul_le_mul {a b c d : ordinal} (h₁ : a ≤ c) (h₂ : b ≤ d) : a * b ≤ c * d :=\nle_trans (mul_le_mul_left _ h₂) (mul_le_mul_right _ h₁)\n\nprivate lemma mul_le_of_limit_aux {α β r s} [is_well_order α r] [is_well_order β s]\n  {c} (h : is_limit (type s)) (H : ∀ b' < type s, type r * b' ≤ c)\n  (l : c < type r * type s) : false :=\nbegin\n  suffices : ∀ 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 [← typein_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 := lt_of_lt_of_le ((add_lt_add_iff_left _).2\n    (typein_lt_type _ a)) this,\n  refine lt_of_le_of_lt _ this,\n  refine (type_le'.2 _),\n  constructor,\n  refine rel_embedding.of_monotone (λ a, _) (λ a b, _),\n  { rcases a with ⟨⟨b', a'⟩, h⟩,\n    by_cases e : b = b',\n    { refine sum.inr ⟨a', _⟩,\n      subst e, cases h with _ _ _ _ h _ _ _ h,\n      { exact (irrefl _ h).elim },\n      { exact h } },\n    { refine sum.inl (⟨b', _⟩, a'),\n      cases h with _ _ _ _ h _ _ _ h,\n      { exact h }, { exact (e rfl).elim } } },\n  { rcases a with ⟨⟨b₁, a₁⟩, h₁⟩,\n    rcases b with ⟨⟨b₂, a₂⟩, h₂⟩,\n    intro h, by_cases e₁ : b = b₁; by_cases e₂ : b = b₂,\n    { substs b₁ b₂,\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₁,\n      simp only [subrel_val, prod.lex_def, e₂, 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 ⊢,\n      cases h₂; [exact asymm h h₂_h, exact e₂ rfl] },\n    { simp only [e₂, dif_pos, eq_self_iff_true, dif_neg e₁, not_false_iff, sum.lex.sep] },\n    { simpa only [dif_neg e₁, dif_neg e₂, 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.{u}}\n  (h : is_limit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=\n⟨λ h b' l, le_trans (mul_le_mul_left _ (le_of_lt l)) h,\nλ H, le_of_not_lt $ induction_on a (λ α r _, induction_on b $ λ β s _,\n  by exactI mul_le_of_limit_aux) h H⟩\n\ntheorem mul_is_normal {a : ordinal} (h : 0 < a) : is_normal ((*) a) :=\n⟨λ b, by rw mul_succ; simpa only [add_zero] using (add_lt_add_iff_left (a*b)).2 h,\n λ b l c, mul_le_of_limit l⟩\n\ntheorem lt_mul_of_limit {a b c : ordinal.{u}}\n  (h : is_limit c) : a < b * c ↔ ∃ 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 ↔ 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 ≤ a * c ↔ b ≤ 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₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b :=\nby simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁\n\ntheorem mul_ne_zero {a b : ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 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 ≤ c * b) (h0 : 0 < c) : a ≤ b :=\nle_imp_le_of_lt_imp_lt (λ 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 ↔ b = c :=\n(mul_is_normal a0).inj\n\ntheorem mul_is_limit {a b : ordinal}\n  (a0 : 0 < a) : is_limit b → 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|⟨b,rfl⟩|lb,\n  { exact (lt_irrefl _).elim b0 },\n  { rw mul_succ, exact add_is_limit _ l },\n  { exact mul_is_limit l.pos lb }\nend\n\n/-! ### Division on ordinals -/\n\nprotected lemma div_aux (a b : ordinal.{u}) (h : b ≠ 0) : set.nonempty {o | a < b * succ o} :=\n⟨a, succ_le.1 $\n  by simpa only [succ_zero, one_mul]\n    using mul_le_mul_right (succ a) (succ_le.2 (ordinal.pos_iff_ne_zero.2 h))⟩\n\n/-- `a / b` is the unique ordinal `o` satisfying\n  `a = b * o + o'` with `o' < b`. -/\nprotected def div (a b : ordinal.{u}) : ordinal.{u} :=\nif h : b = 0 then 0 else omin {o | a < b * succ o} (ordinal.div_aux a b h)\n\ninstance : has_div ordinal := ⟨ordinal.div⟩\n\n@[simp] theorem div_zero (a : ordinal) : a / 0 = 0 := dif_pos rfl\n\nlemma div_def (a) {b : ordinal} (h : b ≠ 0) :\n  a / b = omin {o | a < b * succ o} (ordinal.div_aux a b h) := dif_neg h\n\ntheorem lt_mul_succ_div (a) {b : ordinal} (h : b ≠ 0) : a < b * succ (a / b) :=\nby rw div_def a h; exact omin_mem {o | a < b * succ o} _\n\ntheorem lt_mul_div_add (a) {b : ordinal} (h : b ≠ 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 ≠ 0) : a / b ≤ c ↔ a < b * succ c :=\n⟨λ h, lt_of_lt_of_le (lt_mul_succ_div a b0) (mul_le_mul_left _ $ succ_le_succ.2 h),\n λ h, by rw div_def a b0; exact omin_le h⟩\n\ntheorem lt_div {a b c : ordinal} (c0 : c ≠ 0) : a < b / c ↔ c * succ a ≤ b :=\nby rw [← not_le, div_le c0, not_lt]\n\ntheorem le_div {a b c : ordinal} (c0 : c ≠ 0) :\n  a ≤ b / c ↔ c * a ≤ b :=\nbegin\n  apply limit_rec_on a,\n  { simp only [mul_zero, ordinal.zero_le] },\n  { intros, rw [succ_le, 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 ≠ 0) :\n  a / b < c ↔ 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 ≤ b * c) : a / b ≤ c :=\nif b0 : b = 0 then by simp only [b0, div_zero, ordinal.zero_le] else\n(div_le b0).2 $ lt_of_le_of_lt h $\nmul_lt_mul_of_pos_left (lt_succ_self _) (ordinal.pos_iff_ne_zero.2 b0)\n\ntheorem mul_lt_of_lt_div {a b c : ordinal} : a < b / c → 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) ≤ a :=\nif b0 : b = 0 then by simp only [b0, zero_mul, ordinal.zero_le] else (le_div b0).1 (le_refl _)\n\ntheorem mul_add_div (a) {b : ordinal} (b0 : b ≠ 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 [← ordinal.le_zero, div_le $ ordinal.pos_iff_ne_zero.1 $ lt_of_le_of_lt (ordinal.zero_le _) h],\n  simpa only [succ_zero, mul_one] using h\nend\n\n@[simp] theorem mul_div_cancel (a) {b : ordinal} (b0 : b ≠ 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 ≠ 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 $ λ d,\nby rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]\n\ntheorem is_limit_add_iff {a b} : is_limit (a + b) ↔ is_limit b ∨ (b = 0 ∧ is_limit a) :=\nbegin\n  split; intro h,\n  { by_cases h' : b = 0,\n    { rw [h', add_zero] at h, right, exact ⟨h', h⟩ },\n      left, rw [←add_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|⟨rfl, h⟩, exact add_is_limit a h, simpa only [add_zero]\nend\n\ntheorem dvd_add_iff : ∀ {a b c : ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)\n| a _ c ⟨b, rfl⟩ :=\n ⟨λ ⟨d, e⟩, ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩,\n  λ ⟨d, e⟩, by { rw [e, ← mul_add], apply dvd_mul_right }⟩\n\ntheorem dvd_add {a b c : ordinal} (h₁ : a ∣ b) : a ∣ c → a ∣ b + c :=\n(dvd_add_iff h₁).2\n\ntheorem dvd_zero (a : ordinal) : a ∣ 0 := ⟨_, (mul_zero _).symm⟩\n\ntheorem zero_dvd {a : ordinal} : 0 ∣ a ↔ a = 0 :=\n⟨λ ⟨h, e⟩, by simp only [e, zero_mul], λ e, e.symm ▸ dvd_zero _⟩\n\ntheorem one_dvd (a : ordinal) : 1 ∣ a := ⟨a, (one_mul _).symm⟩\n\ntheorem div_mul_cancel : ∀ {a b : ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b\n| a _ a0 ⟨b, rfl⟩ := by rw [mul_div_cancel _ a0]\n\ntheorem le_of_dvd : ∀ {a b : ordinal}, b ≠ 0 → a ∣ b → a ≤ b\n| a _ b0 ⟨b, rfl⟩ := by simpa only [mul_one] using mul_le_mul_left a\n  (one_le_iff_ne_zero.2 (λ h : b = 0, by simpa only [h, mul_zero] using b0))\n\ntheorem dvd_antisymm {a b : ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=\nif a0 : a = 0 then by subst a; exact (zero_dvd.1 h₁).symm else\nif b0 : b = 0 then by subst b; exact zero_dvd.1 h₂ else\nle_antisymm (le_of_dvd b0 h₁) (le_of_dvd a0 h₂)\n\n/-- `a % b` is the unique ordinal `o'` satisfying\n  `a = b * o + o'` with `o' < b`. -/\ninstance : has_mod ordinal := ⟨λ a b, a - b * (a / b)⟩\n\ntheorem mod_def (a b : ordinal) : a % b = a - b * (a / b) := rfl\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 :=\nadd_sub_cancel_of_le $ mul_div_le _ _\n\ntheorem mod_lt (a) {b : ordinal} (h : b ≠ 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\n/-! ### Supremum of a family of ordinals -/\n\n/-- The supremum of a family of ordinals -/\ndef sup {ι} (f : ι → ordinal) : ordinal :=\nomin {c | ∀ i, f i ≤ c}\n  ⟨(sup (cardinal.succ ∘ card ∘ f)).ord, λ i, le_of_lt $\n    cardinal.lt_ord.2 (lt_of_lt_of_le (cardinal.lt_succ_self _) (le_sup _ _))⟩\n\ntheorem le_sup {ι} (f : ι → ordinal) : ∀ i, f i ≤ sup f :=\nomin_mem {c | ∀ i, f i ≤ c} _\n\ntheorem sup_le {ι} {f : ι → ordinal} {a} : sup f ≤ a ↔ ∀ i, f i ≤ a :=\n⟨λ h i, le_trans (le_sup _ _) h, λ h, omin_le h⟩\n\ntheorem lt_sup {ι} {f : ι → ordinal} {a} : a < sup f ↔ ∃ i, a < f i :=\nby simpa only [not_forall, not_le] using not_congr (@sup_le _ f a)\n\ntheorem is_normal.sup {f} (H : is_normal f)\n  {ι} {g : ι → ordinal} (h : nonempty ι) : f (sup g) = sup (f ∘ g) :=\neq_of_forall_ge_iff $ λ a,\nby rw [sup_le, comp, H.le_set' (λ_:ι, true) g (let ⟨i⟩ := h in ⟨i, ⟨⟩⟩)];\n  intros; simp only [sup_le, true_implies_iff]\n\ntheorem sup_ord {ι} (f : ι → cardinal) : sup (λ i, (f i).ord) = (cardinal.sup f).ord :=\neq_of_forall_ge_iff $ λ a, by simp only [sup_le, cardinal.ord_le, cardinal.sup_le]\n\nlemma sup_succ {ι} (f : ι → ordinal) : sup (λ i, succ (f i)) ≤ succ (sup f) :=\nby { rw [ordinal.sup_le], intro i, rw ordinal.succ_le_succ, apply ordinal.le_sup }\n\nlemma unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [is_well_order α r] (f : β → α)\n  (h : type r ≤ sup.{u u} (typein r ∘ f)) : unbounded r (range f) :=\nbegin\n  apply (not_bounded_iff _).mp, rintro ⟨x, hx⟩, apply not_lt_of_ge h,\n  refine lt_of_le_of_lt _ (typein_lt_type r x), rw [sup_le], intro y,\n  apply le_of_lt, rw typein_lt_typein, apply hx, apply mem_range_self\nend\n\n/-- The supremum of a family of ordinals indexed by the set\n  of ordinals less than some `o : ordinal.{u}`.\n  (This is not a special case of `sup` over the subtype,\n  because `{a // a < o} : Type (u+1)` and `sup` only works over\n  families in `Type u`.) -/\ndef bsup (o : ordinal.{u}) : (Π a < o, ordinal.{max u v}) → ordinal.{max u v} :=\nmatch o, o.out, o.out_eq with\n| _, ⟨α, r, _⟩, rfl, f := by exactI sup (λ a, f (typein r a) (typein_lt_type _ _))\nend\n\ntheorem bsup_le {o f a} : bsup.{u v} o f ≤ a ↔ ∀ i h, f i h ≤ a :=\nmatch o, o.out, o.out_eq, f :\n ∀ o w (e : ⟦w⟧ = o) (f : Π (a : ordinal.{u}), a < o → ordinal.{(max u v)}),\n   bsup._match_1 o w e f ≤ a ↔ ∀ i h, f i h ≤ a with\n| _, ⟨α, r, _⟩, rfl, f := by rw [bsup._match_1, sup_le]; exactI\n  ⟨λ H i h, by simpa only [typein_enum] using H (enum r i h), λ H b, H _ _⟩\nend\n\ntheorem bsup_type (r : α → α → Prop) [is_well_order α r] (f) :\n  bsup (type r) f = sup (λ a, f (typein r a) (typein_lt_type _ _)) :=\neq_of_forall_ge_iff $ λ o,\nby rw [bsup_le, sup_le]; exact\n  ⟨λ H b, H _ _, λ H i h, by simpa only [typein_enum] using H (enum r i h)⟩\n\ntheorem le_bsup {o} (f : Π a < o, ordinal) (i h) : f i h ≤ bsup o f :=\nbsup_le.1 (le_refl _) _ _\n\ntheorem lt_bsup {o : ordinal} {f : Π a < o, ordinal}\n  (hf : ∀{a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha')\n  (ho : o.is_limit) (i h) : f i h < bsup o f :=\nlt_of_lt_of_le (hf _ _ $ lt_succ_self i) (le_bsup f i.succ $ ho.2 _ h)\n\ntheorem bsup_id {o} (ho : is_limit o) : bsup.{u u} o (λ x _, x) = o :=\nbegin\n  apply le_antisymm, rw [bsup_le], intro i, apply le_of_lt,\n  rw [←not_lt], intro h, apply lt_irrefl (bsup.{u u} o (λ x _, x)),\n  apply lt_of_le_of_lt _ (lt_bsup _ ho _ h), refl, intros, assumption\nend\n\ntheorem is_normal.bsup {f} (H : is_normal f)\n  {o : ordinal} : ∀ (g : Π a < o, ordinal) (h : o ≠ 0),\n  f (bsup o g) = bsup o (λ a h, f (g a h)) :=\ninduction_on o $ λ α r _ g h,\nby resetI; rw [bsup_type,\n     H.sup (type_ne_zero_iff_nonempty.1 h), bsup_type]\n\ntheorem is_normal.bsup_eq {f} (H : is_normal f) {o : ordinal} (h : is_limit o) :\n  bsup.{u} o (λx _, f x) = f o :=\nby { rw [←is_normal.bsup.{u u} H (λ x _, x) h.1, bsup_id h] }\n\n/-! ### Ordinal exponential -/\n\n/-- The ordinal exponential, defined by transfinite recursion. -/\ndef power (a b : ordinal) : ordinal :=\nif a = 0 then 1 - b else\nlimit_rec_on b 1 (λ _ IH, IH * a) (λ b _, bsup.{u u} b)\n\ninstance : has_pow ordinal ordinal := ⟨power⟩\nlocal infixr ^ := @pow ordinal ordinal ordinal.has_pow\n\ntheorem zero_power' (a : ordinal) : 0 ^ a = 1 - a :=\nby simp only [pow, power, if_pos rfl]\n\n@[simp] theorem zero_power {a : ordinal} (a0 : a ≠ 0) : 0 ^ a = 0 :=\nby rwa [zero_power', sub_eq_zero_iff_le, one_le_iff_ne_zero]\n\n@[simp] theorem power_zero (a : ordinal) : a ^ 0 = 1 :=\nby by_cases a = 0; [simp only [pow, power, if_pos h, sub_zero],\nsimp only [pow, power, if_neg h, limit_rec_on_zero]]\n\n@[simp] theorem power_succ (a b : ordinal) : a ^ succ b = a ^ b * a :=\nif h : a = 0 then by subst a; simp only [zero_power (succ_ne_zero _), mul_zero]\nelse by simp only [pow, power, limit_rec_on_succ, if_neg h]\n\ntheorem power_limit {a b : ordinal} (a0 : a ≠ 0) (h : is_limit b) :\n  a ^ b = bsup.{u u} b (λ c _, a ^ c) :=\nby simp only [pow, power, if_neg a0]; rw limit_rec_on_limit _ _ _ _ h; refl\n\ntheorem power_le_of_limit {a b c : ordinal} (a0 : a ≠ 0) (h : is_limit b) :\n  a ^ b ≤ c ↔ ∀ b' < b, a ^ b' ≤ c :=\nby rw [power_limit a0 h, bsup_le]\n\ntheorem lt_power_of_limit {a b c : ordinal} (b0 : b ≠ 0) (h : is_limit c) :\n  a < b ^ c ↔ ∃ c' < c, a < b ^ c' :=\nby rw [← not_iff_not, not_exists]; simp only [not_lt, power_le_of_limit b0 h, exists_prop, not_and]\n\n@[simp] theorem power_one (a : ordinal) : a ^ 1 = a :=\nby rw [← succ_zero, power_succ]; simp only [power_zero, one_mul]\n\n@[simp] theorem one_power (a : ordinal) : 1 ^ a = 1 :=\nbegin\n  apply limit_rec_on a,\n  { simp only [power_zero] },\n  { intros _ ih, simp only [power_succ, ih, mul_one] },\n  refine λ b l IH, eq_of_forall_ge_iff (λ c, _),\n  rw [power_le_of_limit ordinal.one_ne_zero l],\n  exact ⟨λ H, by simpa only [power_zero] using H 0 l.pos,\n         λ H b' h, by rwa IH _ h⟩,\nend\n\ntheorem power_pos {a : ordinal} (b)\n  (a0 : 0 < a) : 0 < a ^ b :=\nbegin\n  have h0 : 0 < a ^ 0, {simp only [power_zero, zero_lt_one]},\n  apply limit_rec_on b,\n  { exact h0 },\n  { intros b IH, rw [power_succ],\n    exact mul_pos IH a0 },\n  { exact λ b l _, (lt_power_of_limit (ordinal.pos_iff_ne_zero.1 a0) l).2\n      ⟨0, l.pos, h0⟩ },\nend\n\ntheorem power_ne_zero {a : ordinal} (b)\n  (a0 : a ≠ 0) : a ^ b ≠ 0 :=\nordinal.pos_iff_ne_zero.1 $ power_pos b $ ordinal.pos_iff_ne_zero.2 a0\n\ntheorem power_is_normal {a : ordinal} (h : 1 < a) : is_normal ((^) a) :=\nhave a0 : 0 < a, from lt_trans zero_lt_one h,\n⟨λ b, by simpa only [mul_one, power_succ] using\n  (mul_lt_mul_iff_left (power_pos b a0)).2 h,\n λ b l c, power_le_of_limit (ne_of_gt a0) l⟩\n\ntheorem power_lt_power_iff_right {a b c : ordinal}\n  (a1 : 1 < a) : a ^ b < a ^ c ↔ b < c :=\n(power_is_normal a1).lt_iff\n\ntheorem power_le_power_iff_right {a b c : ordinal}\n  (a1 : 1 < a) : a ^ b ≤ a ^ c ↔ b ≤ c :=\n(power_is_normal a1).le_iff\n\ntheorem power_right_inj {a b c : ordinal}\n  (a1 : 1 < a) : a ^ b = a ^ c ↔ b = c :=\n(power_is_normal a1).inj\n\ntheorem power_is_limit {a b : ordinal}\n  (a1 : 1 < a) : is_limit b → is_limit (a ^ b) :=\n(power_is_normal a1).is_limit\n\ntheorem power_is_limit_left {a b : ordinal}\n  (l : is_limit a) (hb : b ≠ 0) : is_limit (a ^ b) :=\nbegin\n  rcases zero_or_succ_or_limit b with e|⟨b,rfl⟩|l',\n  { exact absurd e hb },\n  { rw power_succ,\n    exact mul_is_limit (power_pos _ l.pos) l },\n  { exact power_is_limit l.one_lt l' }\nend\n\ntheorem power_le_power_right {a b c : ordinal}\n  (h₁ : 0 < a) (h₂ : b ≤ c) : a ^ b ≤ a ^ c :=\nbegin\n  cases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ h₁,\n  { exact (power_le_power_iff_right h₁).2 h₂ },\n  { subst a, simp only [one_power] }\nend\n\ntheorem power_le_power_left {a b : ordinal} (c)\n  (ab : a ≤ b) : a ^ c ≤ b ^ c :=\nbegin\n  by_cases a0 : a = 0,\n  { subst a, by_cases c0 : c = 0,\n    { subst c, simp only [power_zero] },\n    { simp only [zero_power c0, ordinal.zero_le] } },\n  { apply limit_rec_on c,\n    { simp only [power_zero] },\n    { intros c IH, simpa only [power_succ] using mul_le_mul IH ab },\n    { exact λ c l IH, (power_le_of_limit a0 l).2\n        (λ b' h, le_trans (IH _ h) (power_le_power_right\n          (lt_of_lt_of_le (ordinal.pos_iff_ne_zero.2 a0) ab) (le_of_lt h))) } }\nend\n\ntheorem le_power_self {a : ordinal} (b) (a1 : 1 < a) : b ≤ a ^ b :=\n(power_is_normal a1).le_self _\n\ntheorem power_lt_power_left_of_succ {a b c : ordinal}\n  (ab : a < b) : a ^ succ c < b ^ succ c :=\nby rw [power_succ, power_succ]; exact\nlt_of_le_of_lt\n  (mul_le_mul_right _ $ power_le_power_left _ $ le_of_lt ab)\n  (mul_lt_mul_of_pos_left ab (power_pos _ (lt_of_le_of_lt (ordinal.zero_le _) ab)))\n\ntheorem power_add (a b c : ordinal) : a ^ (b + c) = a ^ b * a ^ c :=\nbegin\n  by_cases a0 : a = 0,\n  { subst a,\n    by_cases c0 : c = 0, {simp only [c0, add_zero, power_zero, mul_one]},\n    have : b+c ≠ 0 := ne_of_gt (lt_of_lt_of_le\n      (ordinal.pos_iff_ne_zero.2 c0) (le_add_left _ _)),\n    simp only [zero_power c0, zero_power this, mul_zero] },\n  cases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 a1,\n  { subst a1, simp only [one_power, mul_one] },\n  apply limit_rec_on c,\n  { simp only [add_zero, power_zero, mul_one] },\n  { intros c IH,\n    rw [add_succ, power_succ, IH, power_succ, mul_assoc] },\n  { intros c l IH,\n    refine eq_of_forall_ge_iff (λ d, (((power_is_normal a1).trans\n      (add_is_normal b)).limit_le l).trans _),\n    simp only [IH] {contextual := tt},\n    exact (((mul_is_normal $ power_pos b (ordinal.pos_iff_ne_zero.2 a0)).trans\n      (power_is_normal a1)).limit_le l).symm }\nend\n\ntheorem power_dvd_power (a) {b c : ordinal}\n  (h : b ≤ c) : a ^ b ∣ a ^ c :=\nby { rw [← add_sub_cancel_of_le h, power_add], apply dvd_mul_right }\n\ntheorem power_dvd_power_iff {a b c : ordinal}\n  (a1 : 1 < a) : a ^ b ∣ a ^ c ↔ b ≤ c :=\n⟨λ h, le_of_not_lt $ λ hn,\n  not_le_of_lt ((power_lt_power_iff_right a1).2 hn) $\n   le_of_dvd (power_ne_zero _ $ one_le_iff_ne_zero.1 $ le_of_lt a1) h,\npower_dvd_power _⟩\n\ntheorem power_mul (a b c : ordinal) : a ^ (b * c) = (a ^ b) ^ c :=\nbegin\n  by_cases b0 : b = 0, {simp only [b0, zero_mul, power_zero, one_power]},\n  by_cases a0 : a = 0,\n  { subst a,\n    by_cases c0 : c = 0, {simp only [c0, mul_zero, power_zero]},\n    simp only [zero_power b0, zero_power c0, zero_power (mul_ne_zero b0 c0)] },\n  cases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 a1,\n  { subst a1, simp only [one_power] },\n  apply limit_rec_on c,\n  { simp only [mul_zero, power_zero] },\n  { intros c IH,\n    rw [mul_succ, power_add, IH, power_succ] },\n  { intros c l IH,\n    refine eq_of_forall_ge_iff (λ d, (((power_is_normal a1).trans\n      (mul_is_normal (ordinal.pos_iff_ne_zero.2 b0))).limit_le l).trans _),\n    simp only [IH] {contextual := tt},\n    exact (power_le_of_limit (power_ne_zero _ a0) l).symm }\nend\n\n/-! ### Ordinal logarithm -/\n\n/-- The ordinal logarithm is the solution `u` to the equation\n  `x = b ^ u * v + w` where `v < b` and `w < b`. -/\ndef log (b : ordinal) (x : ordinal) : ordinal :=\nif h : 1 < b then pred $\n  omin {o | x < b^o} ⟨succ x, succ_le.1 (le_power_self _ h)⟩\nelse 0\n\n@[simp] theorem log_not_one_lt {b : ordinal} (b1 : ¬ 1 < b) (x : ordinal) : log b x = 0 :=\nby simp only [log, dif_neg b1]\n\ntheorem log_def {b : ordinal} (b1 : 1 < b) (x : ordinal) : log b x =\n  pred (omin {o | x < b^o} (log._proof_1 b x b1)) :=\nby simp only [log, dif_pos b1]\n\n@[simp] theorem log_zero (b : ordinal) : log b 0 = 0 :=\nif b1 : 1 < b then\n  by rw [log_def b1, ← ordinal.le_zero, pred_le];\n     apply omin_le; change 0<b^succ 0;\n     rw [succ_zero, power_one];\n     exact lt_trans zero_lt_one b1\nelse by simp only [log_not_one_lt b1]\n\ntheorem succ_log_def {b x : ordinal} (b1 : 1 < b) (x0 : 0 < x) : succ (log b x) =\n  omin {o | x < b^o} (log._proof_1 b x b1) :=\nbegin\n  let t := omin {o | x < b^o} (log._proof_1 b x b1),\n  have : x < b ^ t := omin_mem {o | x < b^o} _,\n  rcases zero_or_succ_or_limit t with h|h|h,\n  { refine (not_lt_of_le (one_le_iff_pos.2 x0) _).elim,\n    simpa only [h, power_zero] },\n  { rw [show log b x = pred t, from log_def b1 x,\n        succ_pred_iff_is_succ.2 h] },\n  { rcases (lt_power_of_limit (ne_of_gt $ lt_trans zero_lt_one b1) h).1 this with ⟨a, h₁, h₂⟩,\n    exact (not_le_of_lt h₁).elim (le_omin.1 (le_refl t) a h₂) }\nend\n\ntheorem lt_power_succ_log {b : ordinal} (b1 : 1 < b) (x : ordinal) :\n  x < b ^ succ (log b x) :=\nbegin\n  cases lt_or_eq_of_le (ordinal.zero_le x) with x0 x0,\n  { rw [succ_log_def b1 x0], exact omin_mem {o | x < b^o} _ },\n  { subst x, apply power_pos _ (lt_trans zero_lt_one b1) }\nend\n\ntheorem power_log_le (b) {x : ordinal} (x0 : 0 < x) :\n  b ^ log b x ≤ x :=\nbegin\n  by_cases b0 : b = 0,\n  { rw [b0, zero_power'],\n    refine le_trans (sub_le_self _ _) (one_le_iff_pos.2 x0) },\n  cases lt_or_eq_of_le (one_le_iff_ne_zero.2 b0) with b1 b1,\n  { refine le_of_not_lt (λ h, not_le_of_lt (lt_succ_self (log b x)) _),\n    have := @omin_le {o | x < b^o} _ _ h,\n    rwa ← succ_log_def b1 x0 at this },\n  { rw [← b1, one_power], exact one_le_iff_pos.2 x0 }\nend\n\ntheorem le_log {b x c : ordinal} (b1 : 1 < b) (x0 : 0 < x) :\n  c ≤ log b x ↔ b ^ c ≤ x :=\n⟨λ h, le_trans ((power_le_power_iff_right b1).2 h) (power_log_le b x0),\n λ h, le_of_not_lt $ λ hn,\n   not_le_of_lt (lt_power_succ_log b1 x) $\n   le_trans ((power_le_power_iff_right b1).2 (succ_le.2 hn)) h⟩\n\ntheorem log_lt {b x c : ordinal} (b1 : 1 < b) (x0 : 0 < x) :\n  log b x < c ↔ x < b ^ c :=\nlt_iff_lt_of_le_iff_le (le_log b1 x0)\n\ntheorem log_le_log (b) {x y : ordinal} (xy : x ≤ y) :\n  log b x ≤ log b y :=\nif x0 : x = 0 then by simp only [x0, log_zero, ordinal.zero_le] else\nhave x0 : 0 < x, from ordinal.pos_iff_ne_zero.2 x0,\nif b1 : 1 < b then\n  (le_log b1 (lt_of_lt_of_le x0 xy)).2 $ le_trans (power_log_le _ x0) xy\nelse by simp only [log_not_one_lt b1, ordinal.zero_le]\n\ntheorem log_le_self (b x : ordinal) : log b x ≤ x :=\nif x0 : x = 0 then by simp only [x0, log_zero, ordinal.zero_le] else\nif b1 : 1 < b then\n  le_trans (le_power_self _ b1) (power_log_le b (ordinal.pos_iff_ne_zero.2 x0))\nelse by simp only [log_not_one_lt b1, ordinal.zero_le]\n\n/-! ### The Cantor normal form -/\n\ntheorem CNF_aux {b o : ordinal} (b0 : b ≠ 0) (o0 : o ≠ 0) :\n  o % b ^ log b o < o :=\nlt_of_lt_of_le\n  (mod_lt _ $ power_ne_zero _ b0)\n  (power_log_le _ $ ordinal.pos_iff_ne_zero.2 o0)\n\n/-- Proving properties of ordinals by induction over their Cantor normal form. -/\n@[elab_as_eliminator] noncomputable def CNF_rec {b : ordinal} (b0 : b ≠ 0)\n  {C : ordinal → Sort*}\n  (H0 : C 0)\n  (H : ∀ o, o ≠ 0 → o % b ^ log b o < o → C (o % b ^ log b o) → C o)\n  : ∀ o, C o\n| o :=\n  if o0 : o = 0 then by rw o0; exact H0 else\n  have _, from CNF_aux b0 o0,\n  H o o0 this (CNF_rec (o % b ^ log b o))\nusing_well_founded {dec_tac := `[assumption]}\n\n@[simp] theorem CNF_rec_zero {b} (b0) {C H0 H} : @CNF_rec b b0 C H0 H 0 = H0 :=\nby rw [CNF_rec, dif_pos rfl]; refl\n\n@[simp] theorem CNF_rec_ne_zero {b} (b0) {C H0 H o} (o0) :\n  @CNF_rec b b0 C H0 H o = H o o0 (CNF_aux b0 o0) (@CNF_rec b b0 C H0 H _) :=\nby rw [CNF_rec, dif_neg o0]\n\n/-- The Cantor normal form of an ordinal is the list of coefficients\n  in the base-`b` expansion of `o`.\n\n    CNF b (b ^ u₁ * v₁ + b ^ u₂ * v₂) = [(u₁, v₁), (u₂, v₂)] -/\nnoncomputable def CNF (b := omega) (o : ordinal) : list (ordinal × ordinal) :=\nif b0 : b = 0 then [] else\nCNF_rec b0 [] (λ o o0 h IH, (log b o, o / b ^ log b o) :: IH) o\n\n@[simp] theorem zero_CNF (o) : CNF 0 o = [] :=\ndif_pos rfl\n\n@[simp] theorem CNF_zero (b) : CNF b 0 = [] :=\nif b0 : b = 0 then dif_pos b0 else\n(dif_neg b0).trans $ CNF_rec_zero _\n\ntheorem CNF_ne_zero {b o : ordinal} (b0 : b ≠ 0) (o0 : o ≠ 0) :\n  CNF b o = (log b o, o / b ^ log b o) :: CNF b (o % b ^ log b o) :=\nby unfold CNF; rw [dif_neg b0, dif_neg b0, CNF_rec_ne_zero b0 o0]\n\ntheorem one_CNF {o : ordinal} (o0 : o ≠ 0) :\n  CNF 1 o = [(0, o)] :=\nby rw [CNF_ne_zero ordinal.one_ne_zero o0, log_not_one_lt (lt_irrefl _), power_zero, mod_one,\n       CNF_zero, div_one]\n\ntheorem CNF_foldr {b : ordinal} (b0 : b ≠ 0) (o) :\n  (CNF b o).foldr (λ p r, b ^ p.1 * p.2 + r) 0 = o :=\nCNF_rec b0 (by rw CNF_zero; refl)\n  (λ o o0 h IH, by rw [CNF_ne_zero b0 o0, list.foldr_cons, IH, div_add_mod]) o\n\ntheorem CNF_pairwise_aux (b := omega) (o) :\n  (∀ p ∈ CNF b o, prod.fst p ≤ log b o) ∧\n  (CNF b o).pairwise (λ p q, q.1 < p.1) :=\nbegin\n  by_cases b0 : b = 0,\n  { simp only [b0, zero_CNF, list.pairwise.nil, and_true], exact λ _, false.elim },\n  cases lt_or_eq_of_le (one_le_iff_ne_zero.2 b0) with b1 b1,\n  { refine CNF_rec b0 _ _ o,\n    { simp only [CNF_zero, list.pairwise.nil, and_true], exact λ _, false.elim },\n    intros o o0 H IH, cases IH with IH₁ IH₂,\n    simp only [CNF_ne_zero b0 o0, list.forall_mem_cons, list.pairwise_cons, IH₂, and_true],\n    refine ⟨⟨le_refl _, λ p m, _⟩, λ p m, _⟩,\n    { exact le_trans (IH₁ p m) (log_le_log _ $ le_of_lt H) },\n    { refine lt_of_le_of_lt (IH₁ p m) ((log_lt b1 _).2 _),\n      { rw ordinal.pos_iff_ne_zero, intro e,\n        rw e at m, simpa only [CNF_zero] using m },\n      { exact mod_lt _ (power_ne_zero _ b0) } } },\n  { by_cases o0 : o = 0,\n    { simp only [o0, CNF_zero, list.pairwise.nil, and_true], exact λ _, false.elim },\n    rw [← b1, one_CNF o0],\n    simp only [list.mem_singleton, log_not_one_lt (lt_irrefl _), forall_eq, le_refl, true_and,\n      list.pairwise_singleton] }\nend\n\ntheorem CNF_pairwise (b := omega) (o) :\n  (CNF b o).pairwise (λ p q, prod.fst q < p.1) :=\n(CNF_pairwise_aux _ _).2\n\ntheorem CNF_fst_le_log (b := omega) (o) :\n  ∀ p ∈ CNF b o, prod.fst p ≤ log b o :=\n(CNF_pairwise_aux _ _).1\n\ntheorem CNF_fst_le (b := omega) (o) (p ∈ CNF b o) : prod.fst p ≤ o :=\nle_trans (CNF_fst_le_log _ _ p H) (log_le_self _ _)\n\ntheorem CNF_snd_lt {b : ordinal} (b1 : 1 < b) (o) :\n  ∀ p ∈ CNF b o, prod.snd p < b :=\nbegin\n  have b0 := ne_of_gt (lt_trans zero_lt_one b1),\n  refine CNF_rec b0 (λ _, by rw [CNF_zero]; exact false.elim) _ o,\n  intros o o0 H IH,\n  simp only [CNF_ne_zero b0 o0, list.mem_cons_iff, forall_eq_or_imp, iff_true_intro IH, and_true],\n  rw [div_lt (power_ne_zero _ b0), ← power_succ],\n  exact lt_power_succ_log b1 _,\nend\n\ntheorem CNF_sorted (b := omega) (o) :\n  ((CNF b o).map prod.fst).sorted (>) :=\nby rw [list.sorted, list.pairwise_map]; exact CNF_pairwise b o\n\n/-! ### Casting naturals into ordinals, compatibility with operations -/\n\n@[simp] theorem nat_cast_mul {m n : ℕ} : ((m * n : ℕ) : ordinal) = m * n :=\nby induction n with n IH; [simp only [nat.cast_zero, nat.mul_zero, mul_zero],\n  rw [nat.mul_succ, nat.cast_add, IH, nat.cast_succ, mul_add_one]]\n\n@[simp] theorem nat_cast_power {m n : ℕ} : ((pow m n : ℕ) : ordinal) = m ^ n :=\nby induction n with n IH; [simp only [pow_zero, nat.cast_zero, power_zero, nat.cast_one],\n  rw [pow_succ', nat_cast_mul, IH, nat.cast_succ, ← succ_eq_add_one, power_succ]]\n\n@[simp] theorem nat_cast_le {m n : ℕ} : (m : ordinal) ≤ n ↔ m ≤ n :=\nby rw [← cardinal.ord_nat, ← cardinal.ord_nat,\n       cardinal.ord_le_ord, cardinal.nat_cast_le]\n\n@[simp] theorem nat_cast_lt {m n : ℕ} : (m : ordinal) < n ↔ m < n :=\nby simp only [lt_iff_le_not_le, nat_cast_le]\n\n@[simp] theorem nat_cast_inj {m n : ℕ} : (m : ordinal) = n ↔ m = n :=\nby simp only [le_antisymm_iff, nat_cast_le]\n\n@[simp] theorem nat_cast_eq_zero {n : ℕ} : (n : ordinal) = 0 ↔ n = 0 :=\n@nat_cast_inj n 0\n\ntheorem nat_cast_ne_zero {n : ℕ} : (n : ordinal) ≠ 0 ↔ n ≠ 0 :=\nnot_congr nat_cast_eq_zero\n\n@[simp] theorem nat_cast_pos {n : ℕ} : (0 : ordinal) < n ↔ 0 < n :=\n@nat_cast_lt 0 n\n\n@[simp] theorem nat_cast_sub {m n : ℕ} : ((m - n : ℕ) : ordinal) = m - n :=\n(_root_.le_total m n).elim\n  (λ h, by rw [nat.sub_eq_zero_iff_le.2 h, sub_eq_zero_iff_le.2 (nat_cast_le.2 h)]; refl)\n  (λ h, (add_left_cancel n).1 $ by rw [← nat.cast_add,\n     nat.add_sub_cancel' h, add_sub_cancel_of_le (nat_cast_le.2 h)])\n\n@[simp] theorem nat_cast_div {m n : ℕ} : ((m / n : ℕ) : ordinal) = m / n :=\nif n0 : n = 0 then by simp only [n0, nat.div_zero, nat.cast_zero, div_zero] else\nhave n0':_, from nat_cast_ne_zero.2 n0,\nle_antisymm\n  (by rw [le_div n0', ← nat_cast_mul, nat_cast_le, mul_comm];\n      apply nat.div_mul_le_self)\n  (by rw [div_le n0', succ, ← nat.cast_succ, ← nat_cast_mul,\n          nat_cast_lt, mul_comm, ← nat.div_lt_iff_lt_mul _ _ (nat.pos_of_ne_zero n0)];\n      apply nat.lt_succ_self)\n\n@[simp] theorem nat_cast_mod {m n : ℕ} : ((m % n : ℕ) : ordinal) = m % n :=\nby rw [← add_left_cancel (n*(m/n)), div_add_mod, ← nat_cast_div, ← nat_cast_mul, ← nat.cast_add,\n       nat.div_add_mod]\n\n@[simp] theorem nat_le_card {o} {n : ℕ} : (n : cardinal) ≤ card o ↔ (n : ordinal) ≤ o :=\n⟨λ h, by rwa [← cardinal.ord_le, cardinal.ord_nat] at h,\n λ h, card_nat n ▸ card_le_card h⟩\n\n@[simp] theorem nat_lt_card {o} {n : ℕ} : (n : cardinal) < card o ↔ (n : ordinal) < o :=\nby rw [← succ_le, ← cardinal.succ_le, ← cardinal.nat_succ, nat_le_card]; refl\n\n@[simp] theorem card_lt_nat {o} {n : ℕ} : card o < n ↔ o < n :=\nlt_iff_lt_of_le_iff_le nat_le_card\n\n@[simp] theorem card_le_nat {o} {n : ℕ} : card o ≤ n ↔ o ≤ n :=\nle_iff_le_iff_lt_iff_lt.2 nat_lt_card\n\n@[simp] theorem card_eq_nat {o} {n : ℕ} : card o = n ↔ o = n :=\nby simp only [le_antisymm_iff, card_le_nat, nat_le_card]\n\n@[simp] theorem type_fin (n : ℕ) : @type (fin n) (<) _ = n :=\nby rw [← card_eq_nat, card_type, mk_fin]\n\n@[simp] theorem lift_nat_cast (n : ℕ) : lift n = n :=\nby induction n with n ih; [simp only [nat.cast_zero, lift_zero],\n  simp only [nat.cast_succ, lift_add, ih, lift_one]]\n\ntheorem lift_type_fin (n : ℕ) : lift (@type (fin n) (<) _) = n :=\nby simp only [type_fin, lift_nat_cast]\n\ntheorem fintype_card (r : α → α → Prop) [is_well_order α r] [fintype α] : type r = fintype.card α :=\nby rw [← card_eq_nat, card_type, fintype_card]\n\nend ordinal\n\n/-! ### Properties of `omega` -/\n\nnamespace cardinal\nopen ordinal\n\n@[simp] theorem ord_omega : ord.{u} omega = ordinal.omega :=\nle_antisymm (ord_le.2 $ le_refl _) $\nle_of_forall_lt $ λ o h, begin\n  rcases ordinal.lt_lift_iff.1 h with ⟨o, rfl, h'⟩,\n  rw [lt_ord, ← lift_card, ← lift_omega.{0 u},\n      lift_lt, ← typein_enum (<) h'],\n  exact lt_omega_iff_fintype.2 ⟨set.fintype_lt_nat _⟩\nend\n\n@[simp] theorem add_one_of_omega_le {c} (h : omega ≤ c) : c + 1 = c :=\nby rw [add_comm, ← card_ord c, ← card_one,\n       ← card_add, one_add_of_omega_le];\n   rwa [← ord_omega, ord_le_ord]\n\nend cardinal\n\nnamespace ordinal\n\ntheorem lt_omega {o : ordinal.{u}} : o < omega ↔ ∃ n : ℕ, o = n :=\nby rw [← cardinal.ord_omega, cardinal.lt_ord, lt_omega]; simp only [card_eq_nat]\n\ntheorem nat_lt_omega (n : ℕ) : (n : ordinal) < omega :=\nlt_omega.2 ⟨_, rfl⟩\n\ntheorem omega_pos : 0 < omega := nat_lt_omega 0\n\ntheorem omega_ne_zero : omega ≠ 0 := ne_of_gt omega_pos\n\ntheorem one_lt_omega : 1 < omega := by simpa only [nat.cast_one] using nat_lt_omega 1\n\ntheorem omega_is_limit : is_limit omega :=\n⟨omega_ne_zero, λ o h,\n  let ⟨n, e⟩ := lt_omega.1 h in\n  by rw [e]; exact nat_lt_omega (n+1)⟩\n\ntheorem omega_le {o : ordinal.{u}} : omega ≤ o ↔ ∀ n : ℕ, (n : ordinal) ≤ o :=\n⟨λ h n, le_trans (le_of_lt (nat_lt_omega _)) h,\n λ H, le_of_forall_lt $ λ a h,\n   let ⟨n, e⟩ := lt_omega.1 h in\n   by rw [e, ← succ_le]; exact H (n+1)⟩\n\ntheorem nat_lt_limit {o} (h : is_limit o) : ∀ n : ℕ, (n : ordinal) < 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) : omega ≤ o :=\nomega_le.2 $ λ n, le_of_lt $ nat_lt_limit h n\n\ntheorem add_omega {a : ordinal} (h : a < omega) : a + omega = omega :=\nbegin\n  rcases lt_omega.1 h with ⟨n, rfl⟩,\n  clear h, induction n with n IH,\n  { rw [nat.cast_zero, zero_add] },\n  { rw [nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _), IH] }\nend\n\ntheorem add_lt_omega {a b : ordinal} (ha : a < omega) (hb : b < omega) : a + b < omega :=\nmatch a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_add]; apply nat_lt_omega\nend\n\ntheorem mul_lt_omega {a b : ordinal} (ha : a < omega) (hb : b < omega) : a * b < omega :=\nmatch a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_mul]; apply nat_lt_omega\nend\n\ntheorem is_limit_iff_omega_dvd {a : ordinal} : is_limit a ↔ a ≠ 0 ∧ omega ∣ a :=\nbegin\n  refine ⟨λ l, ⟨l.1, ⟨a / omega, le_antisymm _ (mul_div_le _ _)⟩⟩, λ h, _⟩,\n  { refine (limit_le l).2 (λ x hx, le_of_lt _),\n    rw [← div_lt omega_ne_zero, ← succ_le, le_div omega_ne_zero,\n        mul_succ, add_le_of_limit omega_is_limit],\n    intros b hb,\n    rcases lt_omega.1 hb with ⟨n, rfl⟩,\n    exact le_trans (add_le_add_right (mul_div_le _ _) _)\n      (le_of_lt $ lt_sub.1 $ nat_lt_limit (sub_is_limit l hx) _) },\n  { rcases h with ⟨a0, b, rfl⟩,\n    refine mul_is_limit_left omega_is_limit\n      (ordinal.pos_iff_ne_zero.2 $ mt _ a0),\n    intro e, simp only [e, mul_zero] }\nend\n\nlocal infixr ^ := @pow ordinal ordinal ordinal.has_pow\n\ntheorem power_lt_omega {a b : ordinal} (ha : a < omega) (hb : b < omega) : a ^ b < omega :=\nmatch a, b, lt_omega.1 ha, lt_omega.1 hb with\n| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_power]; apply nat_lt_omega\nend\n\ntheorem add_omega_power {a b : ordinal} (h : a < omega ^ b) : a + omega ^ b = omega ^ b :=\nbegin\n  refine le_antisymm _ (le_add_left _ _),\n  revert h, apply limit_rec_on b,\n  { intro h, rw [power_zero, ← succ_zero, lt_succ, ordinal.le_zero] at h,\n    rw [h, zero_add] },\n  { intros b _ h, rw [power_succ] at h,\n    rcases (lt_mul_of_limit omega_is_limit).1 h with ⟨x, xo, ax⟩,\n    refine le_trans (add_le_add_right (le_of_lt ax) _) _,\n    rw [power_succ, ← mul_add, add_omega xo] },\n  { intros b l IH h, rcases (lt_power_of_limit omega_ne_zero l).1 h with ⟨x, xb, ax⟩,\n    refine (((add_is_normal a).trans (power_is_normal one_lt_omega))\n      .limit_le l).2 (λ y yb, _),\n    let z := max x y,\n    have := IH z (max_lt xb yb)\n      (lt_of_lt_of_le ax $ power_le_power_right omega_pos (le_max_left _ _)),\n    exact le_trans (add_le_add_left (power_le_power_right omega_pos (le_max_right _ _)) _)\n      (le_trans this (power_le_power_right omega_pos $ le_of_lt $ max_lt xb yb)) }\nend\n\ntheorem add_lt_omega_power {a b c : ordinal} (h₁ : a < omega ^ c) (h₂ : b < omega ^ c) :\n  a + b < omega ^ c :=\nby rwa [← add_omega_power h₁, add_lt_add_iff_left]\n\ntheorem add_absorp {a b c : ordinal} (h₁ : a < omega ^ b) (h₂ : omega ^ b ≤ c) : a + c = c :=\nby rw [← add_sub_cancel_of_le h₂, ← add_assoc, add_omega_power h₁]\n\ntheorem add_absorp_iff {o : ordinal} (o0 : 0 < o) : (∀ a < o, a + o = o) ↔ ∃ a, o = omega ^ a :=\n⟨λ H, ⟨log omega o, begin\n  refine ((lt_or_eq_of_le (power_log_le _ o0))\n    .resolve_left $ λ h, _).symm,\n  have := H _ h,\n  have := lt_power_succ_log one_lt_omega o,\n  rw [power_succ, lt_mul_of_limit omega_is_limit] at this,\n  rcases this with ⟨a, ao, h'⟩,\n  rcases lt_omega.1 ao with ⟨n, rfl⟩, clear ao,\n  revert h', apply not_lt_of_le,\n  suffices e : omega ^ log omega o * ↑n + o = o,\n  { simpa only [e] using le_add_right (omega ^ log omega o * ↑n) 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λ ⟨b, e⟩, e.symm ▸ λ a, add_omega_power⟩\n\ntheorem add_mul_limit_aux {a b c : ordinal} (ba : b + a = a)\n  (l : is_limit c)\n  (IH : ∀ 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 $ λ c' h, begin\n    apply le_trans (mul_le_mul_left _ (le_of_lt $ lt_succ_self _)),\n    rw IH _ h,\n    apply le_trans (add_le_add_left _ _),\n    { rw ← mul_succ, exact mul_le_mul_left _ (succ_le.2 $ l.2 _ h) },\n    { rw ← 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, ← add_assoc, add_assoc _ b, ba, ← 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 (λ c' _, add_mul_succ c' ba)\n\ntheorem mul_omega {a : ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=\nle_antisymm\n  ((mul_le_of_limit omega_is_limit).2 $ λ b hb, le_of_lt (mul_lt_omega ha hb))\n  (by simpa only [one_mul] using mul_le_mul_right omega (one_le_iff_pos.2 a0))\n\ntheorem mul_lt_omega_power {a b c : ordinal}\n  (c0 : 0 < c) (ha : a < omega ^ c) (hb : b < omega) : a * b < omega ^ c :=\nif b0 : b = 0 then by simp only [b0, mul_zero, power_pos _ omega_pos] else begin\n  rcases zero_or_succ_or_limit c with rfl|⟨c,rfl⟩|l,\n  { exact (lt_irrefl _).elim c0 },\n  { rw power_succ at ha,\n    rcases ((mul_is_normal $ power_pos _ omega_pos).limit_lt\n      omega_is_limit).1 ha with ⟨n, hn, an⟩,\n    refine lt_of_le_of_lt (mul_le_mul_right _ (le_of_lt an)) _,\n    rw [power_succ, mul_assoc, mul_lt_mul_iff_left (power_pos _ omega_pos)],\n    exact mul_lt_omega hn hb },\n  { rcases ((power_is_normal one_lt_omega).limit_lt l).1 ha with ⟨x, hx, ax⟩,\n    refine lt_of_le_of_lt (mul_le_mul (le_of_lt ax) (le_of_lt hb)) _,\n    rw [← power_succ, power_lt_power_iff_right one_lt_omega],\n    exact l.2 _ hx }\nend\n\ntheorem mul_omega_dvd {a : ordinal}\n  (a0 : 0 < a) (ha : a < omega) : ∀ {b}, omega ∣ b → a * b = b\n| _ ⟨b, rfl⟩ := by rw [← mul_assoc, mul_omega a0 ha]\n\ntheorem mul_omega_power_power {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, power_zero, power_one] at h ⊢, exact mul_omega a0 h},\n  refine le_antisymm _\n    (by simpa only [one_mul] using mul_le_mul_right (omega^omega^b) (one_le_iff_pos.2 a0)),\n  rcases (lt_power_of_limit omega_ne_zero (power_is_limit_left omega_is_limit b0)).1 h\n    with ⟨x, xb, ax⟩,\n  refine le_trans (mul_le_mul_right _ (le_of_lt ax)) _,\n  rw [← power_add, add_omega_power xb]\nend\n\ntheorem power_omega {a : ordinal} (a1 : 1 < a) (h : a < omega) : a ^ omega = omega :=\nle_antisymm\n  ((power_le_of_limit (one_le_iff_ne_zero.1 $ le_of_lt a1) omega_is_limit).2\n    (λ b hb, le_of_lt (power_lt_omega h hb)))\n  (le_power_self _ a1)\n\n/-! ### Fixed points of normal functions -/\n\n/-- The next fixed point function, the least fixed point of the\n  normal function `f` above `a`. -/\ndef nfp (f : ordinal → ordinal) (a : ordinal) :=\nsup (λ n : ℕ, f^[n] a)\n\ntheorem iterate_le_nfp (f a n) : f^[n] a ≤ nfp f a :=\nle_sup _ n\n\ntheorem le_nfp_self (f a) : a ≤ nfp f a :=\niterate_le_nfp f a 0\n\ntheorem is_normal.lt_nfp {f} (H : is_normal f) {a b} :\n  f b < nfp f a ↔ b < nfp f a :=\nlt_sup.trans $ iff.trans\n  (by exact\n   ⟨λ ⟨n, h⟩, ⟨n, lt_of_le_of_lt (H.le_self _) h⟩,\n    λ ⟨n, h⟩, ⟨n+1, by rw iterate_succ'; exact H.lt_iff.2 h⟩⟩)\n  lt_sup.symm\n\ntheorem is_normal.nfp_le {f} (H : is_normal f) {a b} :\n  nfp f a ≤ f b ↔ nfp f a ≤ b :=\nle_iff_le_iff_lt_iff_lt.2 H.lt_nfp\n\ntheorem is_normal.nfp_le_fp {f} (H : is_normal f) {a b}\n  (ab : a ≤ b) (h : f b ≤ b) : nfp f a ≤ b :=\nsup_le.2 $ λ i, begin\n  induction i with i IH generalizing a, {exact ab},\n  exact IH (le_trans (H.le_iff.2 ab) h),\nend\n\ntheorem is_normal.nfp_fp {f} (H : is_normal f) (a) : f (nfp f a) = nfp f a :=\nbegin\n  refine le_antisymm _ (H.le_self _),\n  cases le_or_lt (f a) a with aa aa,\n  { rwa le_antisymm (H.nfp_le_fp (le_refl _) aa) (le_nfp_self _ _) },\n  rcases zero_or_succ_or_limit (nfp f a) with e|⟨b, e⟩|l,\n  { refine @le_trans _ _ _ (f a) _ (H.le_iff.2 _) (iterate_le_nfp f a 1),\n    simp only [e, ordinal.zero_le] },\n  { have : f b < nfp f a := H.lt_nfp.2 (by simp only [e, lt_succ_self]),\n    rw [e, lt_succ] at this,\n    have ab : a ≤ b,\n    { rw [← lt_succ, ← e],\n      exact lt_of_lt_of_le aa (iterate_le_nfp f a 1) },\n    refine le_trans (H.le_iff.2 (H.nfp_le_fp ab this))\n      (le_trans this (le_of_lt _)),\n    simp only [e, lt_succ_self] },\n  { exact (H.2 _ l _).2 (λ b h, le_of_lt (H.lt_nfp.2 h)) }\nend\n\ntheorem is_normal.le_nfp {f} (H : is_normal f) {a b} :\n  f b ≤ nfp f a ↔ b ≤ nfp f a :=\n⟨le_trans (H.le_self _), λ h,\n  by simpa only [H.nfp_fp] using H.le_iff.2 h⟩\n\ntheorem nfp_eq_self {f : ordinal → ordinal} {a} (h : f a = a) : nfp f a = a :=\nle_antisymm (sup_le.mpr $ λ i, by rw [iterate_fixed h]) (le_nfp_self f a)\n\n/-- The derivative of a normal function `f` is\n  the sequence of fixed points of `f`. -/\ndef deriv (f : ordinal → ordinal) (o : ordinal) : ordinal :=\nlimit_rec_on o (nfp f 0)\n  (λ a IH, nfp f (succ IH))\n  (λ a l, bsup.{u u} a)\n\n@[simp] theorem deriv_zero (f) : deriv f 0 = nfp f 0 := limit_rec_on_zero _ _ _\n\n@[simp] theorem deriv_succ (f o) : deriv f (succ o) = nfp f (succ (deriv f o)) :=\nlimit_rec_on_succ _ _ _ _\n\ntheorem deriv_limit (f) {o} : is_limit o →\n  deriv f o = bsup.{u u} o (λ a _, deriv f a) :=\nlimit_rec_on_limit _ _ _ _\n\ntheorem deriv_is_normal (f) : is_normal (deriv f) :=\n⟨λ o, by rw [deriv_succ, ← succ_le]; apply le_nfp_self,\n λ o l a, by rw [deriv_limit _ l, bsup_le]⟩\n\ntheorem is_normal.deriv_fp {f} (H : is_normal f) (o) : f (deriv.{u} f o) = deriv f o :=\nbegin\n  apply limit_rec_on o,\n  { rw [deriv_zero, H.nfp_fp] },\n  { intros o ih, rw [deriv_succ, H.nfp_fp] },\n  intros o l IH,\n  rw [deriv_limit _ l, is_normal.bsup.{u u u} H _ l.1],\n  refine eq_of_forall_ge_iff (λ c, _),\n  simp only [bsup_le, IH] {contextual:=tt}\nend\n\ntheorem is_normal.fp_iff_deriv {f} (H : is_normal f)\n  {a} : f a ≤ a ↔ ∃ o, a = deriv f o :=\n⟨λ ha, begin\n  suffices : ∀ o (_:a ≤ deriv f o), ∃ o, a = deriv f o,\n  from this a ((deriv_is_normal _).le_self _),\n  intro o, apply limit_rec_on o,\n  { intros h₁,\n    refine ⟨0, le_antisymm h₁ _⟩,\n    rw deriv_zero,\n    exact H.nfp_le_fp (ordinal.zero_le _) ha },\n  { intros o IH h₁,\n    cases le_or_lt a (deriv f o), {exact IH h},\n    refine ⟨succ o, le_antisymm h₁ _⟩,\n    rw deriv_succ,\n    exact H.nfp_le_fp (succ_le.2 h) ha },\n  { intros o l IH h₁,\n    cases eq_or_lt_of_le h₁, {exact ⟨_, h⟩},\n    rw [deriv_limit _ l, ← not_le, bsup_le, not_ball] at h,\n    exact let ⟨o', h, hl⟩ := h in IH o' h (le_of_not_le hl) }\nend, λ ⟨o, e⟩, e.symm ▸ le_of_eq (H.deriv_fp _)⟩\n\nend ordinal\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/ordinal_arithmetic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305638, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7532918504924346}}
{"text": "import shannon_theory\n\n---- MUTUAL INFORMATION\n\nopen_locale big_operators\n\nuniverse x\n\nvariables {ι : Type x} [fintype ι]\n(X Y : ι → ℝ) [rnd_var X] [rnd_var Y]\n\n/--\nDefinition (mutual information): Let X and Y be discrete random variables with\njoint probability distribution pX,Y (x, y). The mutual information I(X; Y ) is the marginal\nentropy H(X) less the conditional entropy H(X|Y):\nI(X; Y ) ≡ H(X) − H(X|Y).\nhttps://arxiv.org/pdf/1106.1445.pdf \n-/\ndef mut_info : ℝ := \nShannon_entropy(X) - (cond_entropy XY X Y)\n\nnotation `I(`X`;`Y`)` := mut_info X Y\n\nvariables {X} {Y}\n\n/--\nLemma (symmetry in the input): mutual information is symmetric in the input.\n-/\n@[simp] lemma mut_info_comm : I(X;Y) = I(Y;X) :=\nbegin\n    sorry,\nend\n\n/--\nLemma (nonnegativity): The mutual information I(X;Y) is non-negative for any \nrandom variables X and Y :\nI(X; Y ) ≥ 0.\n-/\nlemma mut_info_nonneg : I(X;Y) ≥ 0 := \nbegin\n    sorry,\nend\n\n/--\nLemma (mutual info zero iff independent random variable) : I(X;Y) = 0 if and \nonly if X and Y are independent random variables (i.e., if pX,Y (x, y) =\npX(x)pY (y)).\n-/\nlemma mut_info_zero_iff_independent : \nI(X;Y) = 0 ↔ indpndnt_rnd_vars X Y :=\nbegin\n    sorry,\nend", "meta": {"author": "BassemSafieldeen", "repo": "Shannon-theory", "sha": "7258c8e33739c30f1078b7f7f53513d36559f89c", "save_path": "github-repos/lean/BassemSafieldeen-Shannon-theory", "path": "github-repos/lean/BassemSafieldeen-Shannon-theory/Shannon-theory-7258c8e33739c30f1078b7f7f53513d36559f89c/src/mut_info.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8104789155369047, "lm_q1q2_score": 0.7532918489542534}}
{"text": "section modular\nparameter (m : ℤ)\n\ndefinition divides (x y: ℤ) :Prop:= ∃ k, x * k = y\n\ndefinition con (a b :ℤ):Prop := divides m (b-a)\n\ntheorem reflex (a:ℤ): con a a :=\nbegin\ndunfold con,\nsimp,\nrw [divides],\nexistsi (0:ℤ),\napply mul_zero,\nend\n\ntheorem symm (a b:ℤ): con a b → con b a :=\nbegin\ndunfold con,\nrw [divides,divides],\nintro H,\ncases H with k hk,\nexistsi (-k),\nrw [mul_neg_eq_neg_mul_symm, hk],\nrw [neg_sub],\nend\n#check congr_arg\n\ntheorem congr_two {α : Type} (f : α → α → α) {a b c d : α} :\na = b → c = d → f a c = f b d :=\nbegin\nintro H,\nintro H2,\nrw [congr_arg f H],\nrw [congr_arg (f b) H2],\nend\n\ntheorem trans (a b c:ℤ): con a b ∧ con b c → con a c :=\nbegin\ndunfold con,\nrw [divides, divides, divides],\nintro H,\ncases H.left with k L,\ncases H.right with k R,\nhave S := congr_two (+) R L,\nsimp,\ndedup,\nrw [←mul_add] at S,\nsimp at S,\nrw [←add_assoc] at S,\nrw [←add_assoc] at S,\nrw [add_comm b c] at S,\nrw [add_assoc] at S,\nrw [add_comm (-a) (-b)] at S,\nrw [←add_assoc] at S,\nsimp at S,\nexistsi (k+k_1),\nexact S,\nend\n\ntheorem addit (a b c d: ℤ): con a c ∧ con b d → con (a+b) (c+d) :=\nbegin\ndunfold con,\nrw [divides, divides, divides],\nintro H,\ncases H.left with k L,\ncases H.right with k R,\ndedup,\nhave S := congr_two (+) R L,\nsimp,\nsimp at S,\nexistsi (k+k_1),\nrw [mul_add],\nexact S,\nend\n\ntheorem mult_scal (a b c: ℤ): con a b → con (a*c) (b*c):=\nbegin\ndunfold con,\nrw [divides, divides],\nintro H,\nrw [←sub_mul],\ncases H with k H2,\nrw [←H2],\nexistsi k*c,\nrw [mul_assoc],\nend\n\ntheorem mult (a b c d: ℤ): con a c ∧ con b d → con (a*b) (c*d) :=\nbegin\ndunfold con,\nrw [divides, divides, divides],\nintro H,\ncases H.left with k L,\ncases H.right with k R,\ndedup,\nhave T: a=a,\n    refl,\nhave LT:= congr_two (+) L T,\nhave T: b=b,\n    refl,\nhave RT:= congr_two (+) R T,\nclear T T R L,\nsimp at LT,\nsimp at RT,\nrw [←RT, ←LT],\nrw [mul_add,mul_comm,mul_add,mul_comm],\nsimp,\nrw [←mul_add],\nexistsi b * k + k_1 * (a + m * k),\nrefl,\nend\n\n#print eqv_gen.setoid\n\nend modular ", "meta": {"author": "kbuzzard", "repo": "xena", "sha": "cd2f0b5e948b7171dbafc5cb519a3220d318bd9d", "save_path": "github-repos/lean/kbuzzard-xena", "path": "github-repos/lean/kbuzzard-xena/xena-cd2f0b5e948b7171dbafc5cb519a3220d318bd9d/student_contributions/Julian_Wykowski_congruence2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7532918314379388}}
{"text": "import MyNat.Definition\nnamespace MyNat\nopen MyNat\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 also gives us some other things,\nwhich we'll take a look at now:\n\n- a term `(0 : MyNat)`, interpreted as the `MyNat.zero`.\n- a function `succ : MyNat → MyNat`, with `succ n` interpreted as \"the number after n\", or the successor of `n`.\n- The principle of mathematical induction.\n\nThese axioms are essentially the axioms isolated by Peano which uniquely characterize the natural\nnumbers (you also need recursion, but you can ignore it for now). The first axiom says that 0 is a\nnatural number. The second says that there is a `succ` function which eats a number and spits out the\nnumber after it, so `succ 0 = 1`, `succ 1 = 2`, and so on.\n\nPeano's last axiom is the principle of mathematical induction. This is a deeper fact. It says that\nif you have infinitely many true/false statements `P(0)`, `P(1)`, `P(2)`, and so on, and if\n`P(0)` is true, and if for every natural number `d` you know that `P(d)` implies `P(succ d)`, then\n`P(n)` must be true for every natural number `n`.\nIt's like saying that if you have a long line of dominoes, and if you knock the first one down, and\nif you know that if a domino falls down then the one after it will fall down too, then you can\ndeduce that all the dominos will fall down. You can also think of it as saying that every natural\nnumber can 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 the natural numbers, and\nsecondly that these axioms alone can be used to build a whole bunch of other structure on the\nnatural numbers, for example addition, multiplication and so on.\n\nThis world is all about seeing how far these axioms of Peano can take us.\n\nLet's practice your use of the `rewrite` tactic in the following example. The hypothesis `h` is a proof that\n`succ a = b` and you want to prove that `succ (succ a) = succ b`. In words, you're going to prove that if\n`b` is the number after `a` then `succ b` is the number after `succ a`. Now here's a tricky question. If\nyour goal is `⊢ succ (succ a) = succ b`, and your hypothesis is `h : succ a = b`, then what will the goal\nchange to when we type `rewrite [h]`?\n\n## Lemma\n\nIf `succ a = b`, then `succ (succ a) = succ b`.\n-/\n\nlemma example3 (a b : MyNat) (h : (succ a) = b) : succ (succ a) = succ b := by\n  rewrite [h]\n  rfl\n\n/-!\n\nRemember that `rewrite [h]` will look 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 then try it.\n\nThe answer: Lean changed `succ a` into `b`, so the goal became `succ b = succ b`. That goal is of\nthe form `X = X`, so you can complete prove the proof using `rfl` which `rw` does for you.\n\nImportant note : the tactic `rewrite` expects a proof afterwards (e.g. `rewrite [h1]`).\nBut `rfl` is just `rfl`.\n\nYou may be wondering whether you could have just substituted in the definition of `b` and proved the\ngoal that way. To do that, you would want to replace the right hand side of `h` with the left hand\nside. You do this in Lean by writing `rw [← h]`. You get the left-arrow by typing `\\l` and then a space;\nnote that this is a small letter `L`, not 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 is because we haven't\ndefined addition yet! On the next level, the final level of Tutorial World, we will introduce\naddition, and then you'll be ready to enter Addition World.\n\nNow you are ready for [Level4.lean](./Level4.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/TutorialWorld/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765304654121, "lm_q2_score": 0.8244619328462579, "lm_q1q2_score": 0.7532915183037765}}
{"text": "/-\n -----------------------------------------------------------\n  Uniform distributions over zmod q, bitvecs, and finite groups\n -----------------------------------------------------------\n-/\n\nimport to_mathlib\n\nvariables (G : Type) [fintype G] [group G] [decidable_eq G]\n\nnoncomputable theory \n\ndef uniform_bitvec (n : ℕ) : pmf (bitvec n) := \n  pmf.of_multiset (bitvec.fintype n).elems.val (bitvec.multiset_ne_zero n)\n\ndef uniform_grp : pmf G := \n  pmf.of_multiset (fintype.elems G).val (group.multiset_ne_zero G)\n\ndef uniform_zmod (n : ℕ) [fact (0 < n)] : pmf (zmod n) := uniform_grp (zmod n)\n\ndef uniform_2 : pmf (zmod 2) := uniform_zmod 2 \n\nlemma uniform_grp_prob : \n  ∀ (g : G), (uniform_grp G) g = 1 / multiset.card (fintype.elems G).val :=\nbegin\n  intro g,\n  have h1 : ⇑(uniform_grp G) = (λ (a : G), \n    (multiset.count a (fintype.elems G).val : nnreal) / multiset.card (fintype.elems G).val) := \n  begin \n    ext,\n    simp [uniform_grp, pmf.of_multiset, coe_fn],\n    simp [has_coe_to_fun.coe],\n    congr,\n  end,\n  have h2 : (uniform_grp G) g = \n    multiset.count g (fintype.elems G).val / multiset.card (fintype.elems G).val := \n  begin\n    exact congr_fun h1 g,\n  end,\n  rw h2,\n  have h3 : multiset.count g (fintype.elems G).val = 1 := multiset.count_univ g,\n  rw h3,\n  simp,\nend \n\nlemma uniform_zmod_prob {n : ℕ} [fact (0 < n)] : \n  ∀ (a : zmod n), (uniform_zmod n) a = 1/n := \nbegin\n  intro a,\n  simp [uniform_zmod],\n  have h1 := uniform_grp_prob (zmod n) a,\n  have h2 : multiset.card (fintype.elems (zmod n)).val = n := zmod.card n,\n  rw h2 at h1,\n  rw inv_eq_one_div (n : nnreal),\n  exact h1,\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/uniform.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7532915143954282}}
{"text": "import Mathlib.Logic.Basic\n\nvariable {P L : Type}\n\nclass Geometry (P : Type _) where\n  line : Type _\n  incidence : Membership P line\n\nattribute [instance] Geometry.incidence\n\nnamespace Geometry\nvariable {p q r s: P}\n\n\ndef collinear [Geometry P] (p q r : P) : Prop :=\n  ∃ l : line P, p ∈ l ∧ q ∈ l ∧ r ∈ l \n\ndef isQuadrangle [Geometry P] (p q r s : P) : Prop :=\n    ¬ collinear p q r\n  ∧ ¬ collinear p q s\n  ∧ ¬ collinear p r s\n  ∧ ¬ collinear q r s\n\ninstance dual [Geometry P] : Geometry (line P) where\n  line := P\n  incidence := ⟨fun l p => p ∈ l⟩\n\ntheorem triangle_rotate [Geometry P] : ¬ collinear p q r -> ¬ collinear q r p := by\n  simp[collinear]\n  intro triangle_pqr l hq hr hp\n  apply triangle_pqr <;> assumption\n\ntheorem quadrangle_rotate [Geometry P] : isQuadrangle p q r s -> isQuadrangle q r s p := by\n  intro ⟨triangle_pqr, triangle_pqs, triangle_prs, triangle_qrs⟩\n  exact ⟨triangle_qrs, triangle_rotate triangle_pqr, triangle_rotate triangle_pqs, triangle_rotate triangle_prs⟩\n\nend Geometry\n\nclass ProjectivePlane (P : Type _) extends Geometry P :=\n  exists_connecting_line : ∀ p q : P, ∃ l : line, p ∈ l ∧ q ∈ l\n  exists_intersection_point : ∀ l m : line, ∃ p : P, p ∈ l ∧ p ∈ m\n  point_line_uniq : ∀ {p q : P} {l m : line}, p ∈ l → q ∈ l → p ∈ m → q ∈ m → p = q ∨ l = m\n  exists_quadrangle : ∃ (p q r s : P), Geometry.isQuadrangle p q r s\n\nnamespace ProjectivePlane\nopen Geometry\nopen Classical\n\nvariable {p q r s : P}\n\nnoncomputable def connectingLine [ProjectivePlane P] (p q : P) : line P := Exists.choose <| exists_connecting_line p q\n\ninfix:75 \" ⊔ \" => connectingLine\n\n@[simp] theorem connectingLine_left [ProjectivePlane P] : ∀ (p q : P),  p ∈ p ⊔ q := by\n    intro p q\n    exact (Exists.choose_spec (exists_connecting_line p q)).left\n\n@[simp] theorem connectingLine_right [ProjectivePlane P] : ∀ (p q : P),  q ∈ p ⊔ q := by\n    intro p q\n    exact (Exists.choose_spec (exists_connecting_line p q)).right\n\ntheorem connectingLine_uniq [ProjectivePlane P] : ∀ {p q : P} {l : line P}, p ≠ q → p ∈ l → q ∈ l → l = p ⊔ q := by\n  intro p q l hpq hpl hql\n  let m := p ⊔ q\n  have hpm : p ∈ m := by simp\n  have hqm : q ∈ m := by simp \n  have h : p = q ∨ l = m := point_line_uniq hpl hql hpm hqm \n  cases h with\n  | inl hpq' => contradiction\n  | inr h' => assumption\n\ntheorem connectingLine_comm [ProjectivePlane P] : ∀ (p q: P), p ⊔ q = q ⊔ p := fun p q =>\n  byCases\n    (fun h : q = p => by rw[h])\n    (fun hpq : q ≠ p => by\n      apply connectingLine_uniq <;> (simp ; try assumption)\n    )\n\nnoncomputable def intersectionPoint [ProjectivePlane P] (l m : line P) : P := Exists.choose <| exists_intersection_point l m\n\ninfix:75 \" ⊓ \" => intersectionPoint\n\n@[simp] theorem intersectionPoint_left [ProjectivePlane P] : ∀ (l m : line P),  l ⊓ m ∈ l := by\n    intro l m\n    exact (Exists.choose_spec (exists_intersection_point l m)).left\n\n@[simp] theorem intersectionPoint_right [ProjectivePlane P] : ∀ (l m : line P),  l ⊓ m ∈ m := by\n  intro l m\n  exact (Exists.choose_spec (exists_intersection_point l m)).right\n\ntheorem intersectionPoint_uniq [ProjectivePlane P] : ∀ {l m : line P} {p : P}, l ≠ m → p ∈ l → p ∈ m → p = l ⊓ m := by\n  intro l m p hlm hpl hpm\n  let q :=  l ⊓ m\n  have hql : q ∈ l := by simp\n  have hqm : q ∈ m := by simp \n  have h : p = q ∨ l = m := point_line_uniq hpl hql hpm hqm\n  cases h with\n  | inl h' => exact h'\n  | inr hlm' => contradiction\n\ntheorem intersectionPoint_comm [ProjectivePlane P] : ∀ (l m : line P), l ⊓ m = m ⊓ l := fun l m =>\n  byCases\n    (fun h : m = l => by rw[h])\n    (fun hpq : m ≠ l => by\n      apply intersectionPoint_uniq <;> (simp ; try assumption)\n    )\n\ntheorem triangle_lines_unequal [ProjectivePlane P] : ¬ collinear p q r -> (p ⊔ q) ≠ (q ⊔ r) ∧ (p ⊔ q) ≠ (r ⊔ p) ∧ (q ⊔ r) ≠ (r ⊔ p) := by\n  intro hnc\n  apply And.intro\n  . intro h\n    simp[collinear] at hnc\n    apply hnc (p ⊔ q)\n    . simp\n    . simp\n    . simp[h]\n  . apply And.intro\n    . intro h\n      simp[collinear] at hnc\n      apply (hnc (p ⊔ q))\n      . simp\n      . simp\n      . simp[h]\n    . intro h\n      simp[collinear] at hnc\n      apply (hnc (q ⊔ r))\n      . simp[h]\n      . simp\n      . simp[h]\n\ntheorem dual_triangle [ProjectivePlane P] : ¬ collinear p q r -> ¬ collinear (p ⊔ q) (q ⊔ r) (r ⊔ p) := by\n  let a := p ⊔ q\n  let b := q ⊔ r\n  intro hnc\n  simp[collinear]\n  -- assume there is a point s such on all three lines\n  intro s hpq hqr hrp\n\n  -- s must be equal to q because it is on a and b\n  have hsq : s = q := by\n    have diff_lines : a ≠ b := (triangle_lines_unequal hnc).left\n    have hsq': s = q ∨ a = b := by\n      apply point_line_uniq <;> (simp ; try assumption)\n    cases hsq' with\n    | inl it => exact it\n    | inr not_it => contradiction\n\n  -- that means p q r are collinear -> contradiction\n  have c : collinear p q r := by\n   exists (r ⊔ p)\n   rw[hsq] at hrp\n   simp\n   assumption\n\n  contradiction\n\n\ntheorem dual_quadrangle_part [ProjectivePlane P] : isQuadrangle p q r s -> ¬ collinear (p ⊔ q) (q ⊔ r) (r ⊔ s) := by\n  intro ⟨triangle_pqr, _, _, triangle_qrs⟩\n  let a := p ⊔ q\n  let b := q ⊔ r\n  let c := r ⊔ s\n\n  let t := a ⊓ c\n\n  have t_is_not_q : q ≠ t := by\n      intro h\n      -- if q = t = (p ⊔ q) ⊓ (r ⊔ s), then r ⊔ s contains q and hence q, r, s are collinear\n      have : collinear q r s := by\n        simp[collinear]\n        rw[h]\n        exists c\n        apply And.intro\n        . simp\n        . apply And.intro\n          . simp\n          . simp\n      contradiction\n\n  have t_is_not_r : r ≠ t := by\n    intro h\n    have : collinear p q r := by\n     simp[collinear]\n     rw[h]\n     exists a\n     apply And.intro\n     . simp\n     . apply And.intro\n       . simp\n       . simp\n    contradiction\n\n  have a_is_q_t : a = q ⊔ t := by\n      apply connectingLine_uniq\n      . assumption\n      . simp\n      . simp\n\n  have c_is_r_t : c = r ⊔ t := by\n    apply connectingLine_uniq\n    . assumption\n    . simp\n    . simp\n\n  have triangle_tqr :  ¬ collinear t q r := by\n    simp[collinear]\n    -- assume there is a line l containing q, r, t\n    intro l htl hql hrl\n\n    -- l = a because l contains both q and t\n    have l_is_a : l = a := by\n      rw[a_is_q_t]\n      apply connectingLine_uniq <;> assumption\n    rw[l_is_a] at hrl\n    -- a = l contains p, q, r\n    have : collinear p q r := by\n      simp[collinear]\n      exists a\n      apply And.intro\n      . simp\n      . apply And.intro\n        . simp\n        . assumption\n    contradiction\n\n  have : ¬ collinear a b c := by\n    rw[a_is_q_t, c_is_r_t, connectingLine_comm]\n    apply dual_triangle\n    assumption\n\n  assumption\n\ntheorem dual_quadrangle [ProjectivePlane P] : isQuadrangle p q r s -> isQuadrangle (p ⊔ q) (q ⊔ r) (r ⊔ s) (s ⊔ p) := by\n  intro ⟨triangle_pqr, triangle_pqs, triangle_prs, triangle_qrs⟩\n  let a := p ⊔ q\n  let b := q ⊔ r\n  let c := r ⊔ s\n  let d := s ⊔ p\n\n  have triangle_abc : ¬ collinear a b c := by\n    apply dual_quadrangle_part\n    exact ⟨triangle_pqr, triangle_pqs, triangle_prs, triangle_qrs⟩\n\n  have triangle_abd : ¬ collinear a b d := by\n    apply triangle_rotate\n    apply dual_quadrangle_part\n    apply quadrangle_rotate\n    apply quadrangle_rotate\n    apply quadrangle_rotate\n    exact ⟨triangle_pqr, triangle_pqs, triangle_prs, triangle_qrs⟩\n\n  have triangle_acd : ¬ collinear a c d := by\n    apply triangle_rotate\n    apply triangle_rotate\n    apply dual_quadrangle_part\n    apply quadrangle_rotate\n    apply quadrangle_rotate\n    exact ⟨triangle_pqr, triangle_pqs, triangle_prs, triangle_qrs⟩\n\n  have triangle_bcd : ¬ collinear b c d := by\n    apply dual_quadrangle_part\n    apply quadrangle_rotate\n    exact ⟨triangle_pqr, triangle_pqs, triangle_prs, triangle_qrs⟩\n\n  exact ⟨triangle_abc, triangle_abd, triangle_acd, triangle_bcd⟩  \n\ninstance dual [inst : ProjectivePlane P] : ProjectivePlane (line P) where\n  line := P\n  incidence := ⟨fun l p => p ∈ l⟩\n  exists_connecting_line := inst.exists_intersection_point\n  exists_intersection_point := inst.exists_connecting_line\n  point_line_uniq := by\n    intros\n    rw[or_comm]\n    apply inst.point_line_uniq <;> assumption\n  exists_quadrangle := \n    match inst.exists_quadrangle with\n    | ⟨p, q, r, s, prf⟩ => ⟨ (p ⊔ q), (q ⊔ r), (r ⊔ s), (s ⊔ p), dual_quadrangle prf⟩\n    \ntheorem dual_involution [h : ProjectivePlane P] :\n  let h' : ProjectivePlane (line (line P)) := inferInstance\n  h' = h := by rfl\nend ProjectivePlane\n\nnamespace Fano\nopen Geometry\n\ninductive Points where\n  | p1\n  | p2\n  | p3 \n  | p4\n  | p5\n  | p6\n  | p7\nderiving DecidableEq, Repr\n\ninductive Lines where\n  | l1\n  | l2\n  | l3 \n  | l4\n  | l5\n  | l6\n  | l7\nderiving DecidableEq, Repr\n\ndef Lines.points : Lines → List Points\n  | .l1 => [.p1, .p2, .p4]\n  | .l2 => [.p2, .p3, .p5]\n  | .l3 => [.p3, .p4, .p6]\n  | .l4 => [.p4, .p5, .p7]\n  | .l5 => [.p5, .p6, .p1]\n  | .l6 => [.p6, .p7, .p2]\n  | .l7 => [.p7, .p1, .p3]\n\ninstance FanoMembership : Membership Points Lines where\n  mem p l := p ∈ l.points\n\ninstance FanoGeometry : Geometry Points where\nline := Lines\nincidence := FanoMembership\n\nattribute [local simp] line\n\ninstance (p : Points) (l : Lines) : Decidable (p ∈ l) := by\n  cases l <;> rw [FanoMembership] <;> simp <;> infer_instance\n\ninstance (P : Points → Prop) [∀ p, Decidable (P p)] : Decidable (∀ p, P p) :=\n  if h : P .p1 ∧ P .p2 ∧ P .p3 ∧ P .p4 ∧ P .p5 ∧ P .p6 ∧ P .p7 then\n    isTrue <| by\n      repeat\n        try rename_i h\n        cases h\n      intro p\n      cases p <;> assumption\n  else\n    isFalse <| by\n      intro H\n      apply h\n      repeat\n        try constructor <;> try apply H\n\ninstance (P : Points → Prop) [∀ p, Decidable (P p)] : Decidable (∃ p, P p) :=\n  if h : ∀ p, ¬ P p then\n    isFalse <| by simp [not_exists, h]\n  else\n    isTrue <| by\n      simp [not_forall, not_not] at h\n      exact h\n\ninstance (P : Lines → Prop) [∀ l, Decidable (P l)] : Decidable (∀ l, P l) :=\n  if h : P .l1 ∧ P .l2 ∧ P .l3 ∧ P .l4 ∧ P .l5 ∧ P .l6 ∧ P .l7 then\n    isTrue <| by\n      repeat\n        try rename_i h\n        cases h\n      intro l\n      cases l <;> assumption\n  else\n    isFalse <| by\n      intro H\n      apply h\n      repeat\n        try constructor <;> try apply H\n\ninstance (P : Lines → Prop) [∀ l, Decidable (P l)] : Decidable (∃ l, P l) :=\n  if h : ∀ l, ¬ P l then\n    isFalse <| by simp [not_exists, h]\n  else\n    isTrue <| by\n      simp [not_forall, not_not] at h\n      exact h\n\n\ndef Fano.exists_connecting_line : ∀ (p q : Points), ∃ l : Lines, p ∈ l ∧ q ∈ l := by\n  decide\n\ndef Fano.exists_intersection_point : ∀ (l m : Lines), ∃ p : Points, p ∈ l ∧ p ∈ m := by\n  decide\n \ntheorem Fano.quadrangle1236 : Geometry.isQuadrangle Points.p1 Points.p2 Points.p3 Points.p6 :=\n  ⟨by simp[collinear], by simp[collinear], by simp[collinear], by simp[collinear]⟩\n\ntheorem Fano.point_line_uniq : ∀ {p q : Points} {l m : Lines}, p ∈ l -> q ∈ l -> p ∈ m -> q ∈ m -> p = q ∨ l = m := by\n  decide\n    \ninstance : ProjectivePlane Points where\n  exists_connecting_line := Fano.exists_connecting_line  \n  exists_intersection_point := Fano.exists_intersection_point\n  exists_quadrangle := ⟨.p1, .p2, .p3, .p6, Fano.quadrangle1236⟩\n  point_line_uniq := Fano.point_line_uniq\n", "meta": {"author": "loewenheim", "repo": "projective-plane", "sha": "7ade52678ac3df537f38d04de46db9aca752f3ca", "save_path": "github-repos/lean/loewenheim-projective-plane", "path": "github-repos/lean/loewenheim-projective-plane/projective-plane-7ade52678ac3df537f38d04de46db9aca752f3ca/ProjectivePlane.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7532915047056885}}
{"text": "import data.real.basic\n-- import data.set.basic\n-- import tactic.ring\n\nuniverse u\n\n-- test for reals\nexample (x : ℝ) : (1 - x) + x = 1 := by ring\n\n-- test for set theory\nexample {α : Type} (A B : set α) : A ∪ B = B ∪ A := set.union_comm A B\n-- example {α : Type} (A B : set α) : A ∪ B = B ∪ A := by finish\n\nconstant α : Type u\nnotation `S` := set.univ\n\n#check @set.subset_empty_iff\nexample : ∀ (A : set α), A ∪ -A = set.univ := set.union_compl_self\nexample : ∀ (A : set α), A ⊆ ∅ ↔ A = ∅ := λ s, set.subset_empty_iff\nexample : ∀ (A B : set α), A ⊆ B → A ∪ B \\ A = B := λ a b, set.union_diff_cancel\n\n#check set.inter_compl_self\n\nlemma s.union_comm : ∀ {A B : set α}, A ∪ B = B ∪ A := set.union_comm\nlemma s.union_with_complement : ∀ {A : set α}, A ∪ -A = set.univ := set.union_compl_self\nlemma s.intersection_with_complement : ∀ {A : set α}, A ∩ -A = ∅ := set.inter_compl_self\nlemma s.union_empty : ∀ (A : set α), A ∪ ∅ = A := set.union_empty\nlemma s.inter_empty : ∀ (A : set α), A ∩ ∅ = ∅ := set.inter_empty\nlemma s.inter_univ : ∀ (A : set α), A ∩ S = A := set.inter_univ\nlemma s.diff_eq : ∀ (A B : set α), A \\ B = A ∩ -B := set.diff_eq\nlemma s.not_univ : -@set.univ α = ∅ := sorry\nlemma s.inter_distrib : ∀ (A B C : set α), A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) := sorry\n-- A = A ∩ -B ∪ A ∩ B = A ∩ (-B ∪ B) = A ∩ S = A\n\n#check set.union_empty\n#check @set.union_diff_cancel\n\n\nnamespace prob\nconstant P : set α → ℝ\n-- ********** axioms of probability **********\naxiom a1 : ∀ A : set α, P A ≥ 0\naxiom a2 : P set.univ = 1\naxiom a3 : ∀ A B : set α, A ∩ B = ∅ → P (A ∪ B) = P A + P B\n-- axiom a2_2 : P ∅ = 0\n-- ********** axioms of probability **********\n\ntheorem t1 (A : set α) : P (-A) = 1 - P A :=\nbegin\n  have h₁ : P (A ∪ -A) = P A + P (-A) := a3 A (-A) s.intersection_with_complement,\n  rw [s.union_with_complement, a2] at h₁,\n  rw h₁,\n  exact eq.symm (add_sub_cancel' (P A) (P (-A))),\nend\n\ntheorem t2 : ∀ A : set α, P A ≤ 1 :=\nbegin\n  sorry,\nend\n\ntheorem t3 : P ∅ = 0 :=\nbegin\n  have h₁ := t1 S,\n  rw s.not_univ at h₁,\n  rw [h₁, a2],\n  exact sub_self 1,\nend\n\nlemma lemma1 (A B : set α) : P (A ∪ B) = P (A \\ B) + P (A ∩ B) + P (B \\ A) := sorry\n\nlemma lemma2 (A B : set α) : P A = P (A \\ B) + P (A ∩ B) :=\nbegin\n  have h₀ : (A \\ B) ∩ (A ∩ B) = ∅ := by {\n  calc (A \\ B) ∩ (A ∩ B) = (A ∩ -B) ∩ (A ∩ B) : by rw s.diff_eq\n                     ... = (A ∩ -B) ∩ (B ∩ A) : by rw set.inter_comm A B\n                     ... = A ∩ -B ∩ B ∩ A     : by rw ←set.inter_assoc\n                     ... = A ∩ (-B ∩ B) ∩ A   : by rw set.inter_assoc A\n                     ... = A ∩ (B ∩ -B) ∩ A   : by rw set.inter_comm _ B\n                     ... = A ∩ ∅ ∩ A          : by rw s.intersection_with_complement\n                     ... = A ∩ (∅ ∩ A)        : by rw set.inter_assoc\n                     ... = ∅ ∩ A ∩ A          : by rw set.inter_comm\n                     ... = ∅ ∩ (A ∩ A)        : by rw set.inter_assoc\n                     ... = A ∩ A ∩ ∅          : by rw set.inter_comm\n                     ... = ∅                  : s.inter_empty (A ∩ A)\n  },\n  have h₀ : (A \\ B) ∩ (A ∩ B) = ∅ := by {\n    rw s.diff_eq,\n    rw set.inter_comm A B,\n    rw ←set.inter_assoc,\n    rw set.inter_assoc A,\n    rw set.inter_comm _ B,             -- A ∩ (B ∩ -B) ∩ A = ∅\n    rw s.intersection_with_complement, -- A ∩ ∅ ∩ A = ∅\n    rw set.inter_assoc,                -- A ∩ (∅ ∩ A) = ∅\n    rw set.inter_comm,                 -- ∅ ∩ A ∩ A = ∅\n    rw set.inter_assoc,                -- ∅ ∩ (A ∩ A) = ∅\n    rw set.inter_comm,                 -- A ∩ A ∩ ∅ = ∅\n    exact s.inter_empty _,             -- ∅ = ∅\n  },\n  -- A = A ∩ -B ∪ A ∩ B = A ∩ (-B ∪ B) = A ∩ S = A\n  have h𝔸 : A = A \\ B ∪ A ∩ B := by {\n    rw s.diff_eq,\n    rw ←s.inter_distrib,\n    rw s.union_comm,\n    rw s.union_with_complement,\n    rw s.inter_univ,\n  },\n  have h₁ := a3 (A \\ B) (A ∩ B) h₀,\n  rw ←h𝔸 at h₁,\n  exact h₁,\nend\n\ntheorem t4 (A B : set α) : P (A ∪ B) = P A + P B - P (A ∩ B) :=\nbegin\n  have h₁ : P A = P (A \\ B) + P (A ∩ B) := lemma2 A B,\n  have h₂ : P B = P (B \\ A) + P (B ∩ A) := lemma2 B A,\n  rw set.inter_comm at h₂,\n  rw [h₁, h₂],\n  ring, -- simplify expression using P (A ∩ B) - P (A ∩ B) = 0, \n        -- idea: make config of computable object (in beginning of proof) to auto-check this\n        -- use relational-tactic-keywords instead of one-way tactic methods\n  rw ←add_assoc,\n  exact lemma1 A B,\nend\n\ntheorem t5 (A B : set α) : A ⊆ B → P A ≤ P B :=\nbegin\n  have h₁ : P (B \\ A) ≥ 0 := sorry, -- use a1\n  -- have h₂ : \n  sorry,\nend\n\n\nend prob\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/foundations_of_mathematics/probability_theory.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631689, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7532914987295819}}
{"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-/\nimport algebra.module.torsion\nimport ring_theory.dedekind_domain.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 = ∏ 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\nuniverses u v\nopen_locale big_operators\n\nvariables {R : Type u} [comm_ring R] [is_domain R] {M : Type v} [add_comm_group M] [module R M]\n\nopen_locale direct_sum\n\nnamespace submodule\nvariables [is_dedekind_domain R]\nopen unique_factorization_monoid\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 = ∏ i, p i ^ e i` is its unique decomposition in prime ideals.-/\nlemma is_internal_prime_power_torsion_of_is_torsion_by_ideal {I : ideal R} (hI : I ≠ ⊥)\n  (hM : module.is_torsion_by_set R M I) :\n  ∃ (P : finset $ ideal R) [decidable_eq P] [∀ p ∈ P, prime p] (e : P → ℕ),\n  by exactI direct_sum.is_internal (λ p : P, torsion_by_set R M (p ^ e p : ideal R)) :=\nbegin\n  classical,\n  let P := factors I,\n  have prime_of_mem := λ p (hp : p ∈ P.to_finset), prime_of_factor p (multiset.mem_to_finset.mp hp),\n  refine ⟨P.to_finset, infer_instance, prime_of_mem, λ i, P.count i, _⟩,\n  apply @torsion_by_set_is_internal _ _ _ _ _ _ _ _ (λ p, p ^ P.count p) _,\n  { convert hM,\n    rw [← finset.inf_eq_infi, is_dedekind_domain.inf_prime_pow_eq_prod,\n      ← finset.prod_multiset_count, ← associated_iff_eq],\n    { exact factors_prod hI },\n    { exact prime_of_mem }, { exact λ _ _ _ _ ij, ij } },\n  { intros p hp q hq pq, dsimp,\n    rw irreducible_pow_sup,\n    { suffices : (normalized_factors _).count p = 0,\n      { rw [this, zero_min, pow_zero, ideal.one_eq_top] },\n      { rw [multiset.count_eq_zero, normalized_factors_of_irreducible_pow\n          (prime_of_mem q hq).irreducible, multiset.mem_replicate],\n        exact λ H, pq $ H.2.trans $ normalize_eq q } },\n    { rw ← ideal.zero_eq_bot, apply pow_ne_zero, exact (prime_of_mem q hq).ne_zero },\n    { exact (prime_of_mem p hp).irreducible } }\nend\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 is_internal_prime_power_torsion [module.finite R M] (hM : module.is_torsion R M) :\n  ∃ (P : finset $ ideal R) [decidable_eq P] [∀ p ∈ P, prime p] (e : P → ℕ),\n  by exactI direct_sum.is_internal (λ p : P, torsion_by_set R M (p ^ e p : ideal R)) :=\nbegin\n  obtain ⟨I, hI, hM'⟩ := 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 ←set.nonempty_iff_ne_empty at hI, rw submodule.ne_bot_iff,\n  obtain ⟨x, H, hx⟩ := hI, exact ⟨x, H, non_zero_divisors.ne_zero hx⟩\nend\n\nend submodule\n", "meta": {"author": "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/dedekind_domain.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7532914929157378}}
{"text": "import data.real.basic\n-- this is a proof that ∀ vectors a, b ∈ ℝ³, \n-- (a × b) ⬝ a = 0 ∧ (a × b) ⬝ b = 0\n\ndef dot: ℝ × ℝ × ℝ → ℝ × ℝ × ℝ → ℝ := λ ⟨a, b, c⟩ ⟨d, e, f⟩, a*d + b*e + c*f\ndef cross: ℝ × ℝ × ℝ → ℝ × ℝ × ℝ → ℝ × ℝ × ℝ := λ ⟨a, b, c⟩ ⟨d, e, f⟩, ⟨b*f - c*e, c*d - a*f, a*e - b*d⟩\n\nvariables m n p j k l : ℝ\n#check dot (cross (m, n, p) (j, k, l)) (j, k, l)\n\ntheorem cross' (a b c d e f: ℝ) : cross (a, b, c) (d, e, f) = (b*f - c*e, c*d - a*f, a*e - b*d) := rfl\ntheorem dot' (a b c d e f: ℝ) : dot (a, b, c) (d, e, f) = a*d + b*e + c*f := rfl\n\nlocal attribute [simp] mul_comm mul_assoc mul_right_comm\n\ntheorem proof1 : ∀ {a b c d e f: ℝ}, dot (cross (a, b, c) (d, e, f)) (a, b, c) = 0 :=\nassume a b c d e f,\ncalc\n    dot (cross (a, b, c) (d, e, f)) (a, b, c) = dot (b*f - c*e, c*d - a*f, a*e - b*d) (a, b, c) : by rw cross'\n    ... = (b*f - c*e)*a + (c*d - a*f)*b + (a*e - b*d)*c : by rw dot'\n    ... = b*f*a - c*e*a + (c*d*b - a*f*b) + (a*e*c - b*d*c) : by repeat {rw sub_mul}\n    ... = 0 : by simp\n#check proof1\n\ntheorem proof2 : ∀ {a b c d e f: ℝ}, dot (cross (a, b, c) (d, e, f)) (d, e, f) = 0 :=\nassume a b c d e f,\ncalc\n    dot (cross (a, b, c) (d, e, f)) (d, e, f) = dot (b*f - c*e, c*d - a*f, a*e - b*d) (d, e, f) : by rw cross'\n    ... = (b*f - c*e)*d + (c*d - a*f)*e + (a*e - b*d)*f : by rw dot'\n    ... = b*f*d - c*e*d + (c*d*e - a*f*e) + (a*e*f - b*d*f) : by repeat {rw sub_mul}\n    ... = a * (e * f) + (c * (d * e) + (-(a * (e * f)) + -(c * (d * e)))) : by simp\n    ... = a * (e * f) + (c * (d * e) + -(a * (e * f)) + -(c * (d * e))) : by rw add_assoc\n    ... = 0 : by simp\n#check proof2\n\nexample (a b c d e f: ℝ) : \n     dot (cross (a, b, c) (d, e, f)) (a, b, c) = 0 ∧ dot (cross (a, b, c) (d, e, f)) (d, e, f) = 0 :=\n    and.intro proof1 proof2", "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/real_vector3d_cross.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7532828305438009}}
{"text": "import algebra.group algebra.group_power\n\nvariables {G: Type*}\n\n-- if (a * b) ^ n = a ^ n * b ^ n for three consecutive integers, G is abelian.\n-- (the `rw`s  should really be re-written in calc so that it's human-readable.)\ndef Q_04h (G: Type*) [group G] (k: ℕ): Prop :=\n  ∀ a b: G, (a * b) ^ k = a ^ k * b ^ k\n\nlemma Q_04a [group G]: ∀ n: ℕ, ∀ a b: G,\n  (a * b) ^ (n + 1) = a * (b * a) ^ n * b\n| 0 :=\n  λ a b, by rw [ zero_add, pow_one, pow_zero, mul_one ]\n| (nat.succ r) :=\n  λ a b, by rw [ pow_succ, Q_04a, pow_succ,\n                 ←mul_assoc, ←mul_assoc,\n                 ←mul_assoc, ←mul_assoc ]\n\nlemma Q_04b [group G]: ∀ n: ℕ,\n  (Q_04h G n) ∧ (Q_04h G (n + 1))\n  → (∀ a b: G, (a * b) ^ n = (b * a) ^ n)\n| 0 :=\n  λ ⟨h1, h2⟩ a b, by rw [ pow_zero, pow_zero ]\n| (nat.succ r) :=\n  λ ⟨h1, h2⟩ a b,\n  let h1' := h1 a b in\n  let h2' := h2 a b in\n  begin\n    rw [\n      Q_04a,\n      pow_succ a (nat.succ r),\n      pow_succ' b (nat.succ r),\n      ←mul_assoc, mul_assoc a _ (b ^ nat.succ r),\n      ←h1\n    ] at h2',\n\n    exact mul_left_cancel (mul_right_cancel h2'.symm)\n  end\n\ntheorem Q_04 [hG: group G] (n: ℕ):\n  (Q_04h G n) ∧ (Q_04h G (n + 1)) ∧ (Q_04h G (n + 2))\n  → comm_group G :=\nλ ⟨h1, ⟨h2, h3⟩⟩, {\n  mul_comm := λ a b, begin\n    have t0, from Q_04b n ⟨h1, h2⟩,\n    have t1, from Q_04b (n + 1) ⟨h2, h3⟩ a b,\n    rw [ pow_succ, pow_succ, Q_04b n ⟨h1, h2⟩ ] at t1,\n    exact mul_right_cancel t1,\n  end,\n  .. hG\n}\n\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_04.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897426182322, "lm_q2_score": 0.8006920068519378, "lm_q1q2_score": 0.7532828270427103}}
{"text": "-- source: mathlib/test/simp_rw.lean\nimport tactic.simp_rw\n\nset_option trace.simplify.rewrite true\n-- `simp_rw` can perform rewrites under binders:\nexample : (λ (x y : ℕ), x + y) = (λ x y, y + x) := by simp [add_comm]\nexample : (λ (x y : ℕ), x + y) = (λ x y, y + x) := by simp_rw [add_comm]\n\n-- `simp_rw` can apply reverse rules:\nexample (f : ℕ → ℕ) {a b c : ℕ} (ha : f b = a) (hc : f b = c) :\n  a = c := by simp_rw [←ha, hc]\n\n-- `simp_rw` performs rewrites in the given order\n-- example {α β : Type} {f : α → β} {t : set β} :\n--   (∀ s, f ∈ s ⊆ t) = ∀ s : set α, ∀ x ∈ s, x ∈ f t :=\n\n-- `simp_rw` applies rewrite rules multiple times:\nexample (a b c d : ℕ) : a + (b + (c + d)) = ((d + c) + b) + a := by simp [add_comm]\nexample (a b c d : ℕ) : a + (b + (c + d)) = ((d + c) + b) + a := by simp_rw [add_comm]", "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/simp_rw.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897492587141, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7532828234109302}}
{"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          ```x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1```\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, each\ndifferent 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 ≥ 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 : ℝ) (h : x*y*z = 1) :\n  ∃ a b c : ℝ, a ≠ 0 ∧ b ≠ 0 ∧ c ≠ 0 ∧ x = a/b ∧ y = b/c ∧ z = c /a :=\nbegin\n  use x, use 1, use 1/y,\n  have h₁ : x ≠ 0,              { intro p, rw p at h, simp at h, exact h },\n  have h₂ : (1 : ℝ) ≠ (0 : ℝ),  exact one_ne_zero,\n  have hy_ne_zero : y ≠ 0,      { intro p, rw p at h, simp at h, exact h },\n  have h₃ : 1/y ≠ 0,            exact one_div_ne_zero hy_ne_zero,\n  have h₄ : x = x / 1,          exact (div_one x).symm,\n  have h₅ : y = 1 / (1 / y),    exact (one_div_one_div y).symm,\n  have h₆ : z = 1 / y / x,      { field_simp, linarith [h] },\n  exact ⟨h₁, h₂, h₃, h₄, h₅, h₆⟩,\nend\n\ntheorem imo2008_q2a (x y z : ℝ) (h : x*y*z = 1) (hx : x ≠ 1) (hy : y ≠ 1) (hz : z ≠ 1) :\n  x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1 :=\nbegin\n  rcases (subst_abc _ _ _ h) with ⟨a, b, c, ha, hb, hc, hx₂, hy₂, hz₂⟩,\n\n  let m := c-b,\n  let n := b-a,\n\n  have hm_abc : m = c - b,          exact rfl,\n  have hn_abc : n = b - a,          exact rfl,\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 ≠ 0,\n  { rw hm_abc, rw hy₂ at hy, intro p, apply hy, field_simp, linarith },\n\n  have hn_ne_zero : n ≠ 0,\n  { rw hn_abc, rw hx₂ at hx, intro p, apply hx, field_simp, linarith },\n\n  have hmn_ne_zero : m + n ≠ 0,\n  { rw hm_abc, rw hn_abc, rw hz₂ 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 ≥ 0,\n\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₂, hy₂, hz₂]\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  ... ≥ 0 :\n        by exact pow_two_nonneg _ ,\n\n  linarith [key],\nend\n\ndef rational_solutions := { s : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧\n  x ≠ 1 ∧ y ≠ 1 ∧ z ≠ 1 ∧ x*y*z = 1 ∧ 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 : ℚ×ℚ×ℚ | ∃ (x y z : ℚ), s = (x, y, z) ∧\n    ∃ t : ℚ, t > 0 ∧ x = -(t+1)/t^2 ∧ y = t/(t+1)^2 ∧ z = -t*(t+1)},\n\n  have hW_sub_S : W ⊆ rational_solutions,\n  { intros s hs_in_W,\n    rw rational_solutions,\n    simp at hs_in_W ⊢,\n    rcases hs_in_W with ⟨x, y, z, hs_xyz, ht⟩,\n    rcases ht with ⟨t, ht_gt_zero, hx_t, hy_t, hz_t⟩,\n    use x, use y, use z,\n\n    have ht_ne_zero : t ≠ 0, exact ne_of_gt ht_gt_zero,\n    have ht1_ne_zero : t+1 ≠ 0, linarith[ht_gt_zero],\n\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 ≠ 0, exact ne_of_gt key_gt_zero,\n\n    have h₂ : x ≠ 1, { rw hx_t, field_simp, linarith[key_gt_zero] },\n    have h₃ : y ≠ 1, { rw hy_t, field_simp, linarith[key_gt_zero] },\n    have h₄ : z ≠ 1, { rw hz_t, linarith[key_gt_zero] },\n\n    have h₅ : x*y*z = 1, { rw [hx_t, hy_t, hz_t], field_simp, ring },\n\n    have h₆ : 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,\n      { field_simp, rw hx_t, field_simp, ring },\n      have hy1 : (y - 1)^2 = (t^2 + t + 1)^2/(t+1)^4,\n      { field_simp, rw hy_t, field_simp, ring },\n      have hz1 : (z - 1)^2 = (t^2 + t + 1)^2,\n      { 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 ⟨hs_xyz, h₂, h₃, h₄, h₅, h₆⟩,\n  },\n\n  have hW_inf : set.infinite W,\n  { let g : ℚ×ℚ×ℚ → ℚ := (λs, -s.2.2),\n    let Z := g '' W,\n\n    have hZ_not_bdd : ¬bdd_above Z,\n    { rw not_bdd_above_iff,\n      intro q,\n      let t : ℚ := max (q+1) 1,\n      use t*(t+1),\n      let x : ℚ := (-1 + -t)/t^2,\n      let y : ℚ := t/(t+1)^2,\n      let z : ℚ := -t*(t+1),\n      have hz_def : z = -t*(t+1), exact rfl,\n\n      split,\n      { simp, use x, use y, use z, split,\n        { use x, use y, use z, split,\n          { split, refl, split, refl, refl },\n          { use t, split,\n            { simp, right, exact zero_lt_one },\n            { split, refl, split, refl, linarith[hz_def] } } },\n        { have hg_eval : g(x, y, z) = -z, exact rfl,\n          rw hg_eval, linarith[hz_def] } },\n      { calc q < q + 1    : by { linarith }\n           ... ≤ t        : by { exact le_max_left (q + 1) 1 }\n           ... ≤ t+t^2    : by { linarith [pow_two_nonneg t] }\n           ... = t*(t+1)  : by { ring } },\n    },\n\n    have hZ_inf : set.infinite Z,\n    { intro h, apply hZ_not_bdd, exact set.finite.bdd_above h },\n\n    exact set.infinite_of_infinite_image g hZ_inf,\n  },\n\n  exact set.infinite_mono hW_sub_S hW_inf,\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_q2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7532617285419918}}
{"text": "import tactic.interactive tactic.ring\n\ninductive is_even : ℕ → Prop\n| zero : is_even 0\n| step {n} : is_even n → is_even (n + 2)\n\nexample : is_even 4 :=\nbegin\nrepeat { apply is_even.step },\napply is_even.zero,\nend\n\nexample : ¬ is_even 5 :=\nbegin\nintro even_five,\ncases even_five with _ even_three,\ncases even_three with _ even_one,\ncases even_one,\nend\n\nlemma even_if_double {n} : is_even (2*n) :=\nbegin\ninduction n with d hd,\n{ exact is_even.zero },\n{ show is_even (2 * (d + 1)),\n  rw mul_add,\n  apply is_even.step,\n  assumption,\n },\nend\n\nlemma double_if_even {n} : is_even n → ∃ m, n = 2*m :=\nbegin\nintro h, induction h with d Hd ih,\n{ use 0,\n  refl\n},\n{ cases ih with n Hn,\n  use (n + 1),\n  rw Hn,\n  refl,\n }\nend\n\nlemma even_iff_double {n} : is_even n ↔ ∃ m, n = 2*m :=\nbegin\nsplit, apply double_if_even,\nintro h, cases h with d Hd, rw Hd, \n  apply even_if_double\nend\n\ninductive is_odd : ℕ → Prop\n| one : is_odd 1\n| step {n} : is_odd n → is_odd (n + 2)\n\nlemma odd_iff_double_add_one {n} : is_odd n ↔ ∃ m, n = 2*m + 1 :=\nsorry\n\nlemma even_of_not_odd : ∀ n, \n¬ is_odd n → is_even n\n| 0 h := is_even.zero\n| 1 h := begin exfalso, apply h, constructor end\n| (n+2) h :=\n  have ih : _, from even_of_not_odd n,\n  begin\n  constructor,\n  apply ih,\n  intro hn,\n  apply h,\n  constructor, assumption,\n  end\n\n#print even_of_not_odd\n\nlemma not_odd_of_even : ∀ n, is_even n → ¬ is_odd n :=\nbegin\nintros n h,\ninduction h with m m hm,\n{intro h, cases h},\n{intro h, apply hm, cases h, assumption},\nend\n\nlemma even_iff_not_odd : ∀ n, is_even n ↔ ¬ is_odd n :=\nbegin\nintro n, split, apply not_odd_of_even, apply even_of_not_odd\nend\n\nlemma odd_square (n : ℕ) : is_odd n → is_odd (n*n) :=\nbegin\nsimp [odd_iff_double_add_one],\nintro m,\nintros  h,\nuse 2*m + 2*m*m, subst h, ring,\nend\n\nlemma even_square (n : ℕ) : is_even (n*n) → is_even n :=\nbegin\nconv in (is_even (n*n)) { simp [even_iff_not_odd] },\nsimp [even_iff_not_odd],\nintros h1 h2, apply h1,\napply odd_square, assumption\nend\n\nset_option pp.all true\n#check (7 : ℤ)", "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/infinite_primes.lean/sqrt2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7532567250064823}}
{"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 ℚ\n\nThis file proves that ℚ is infinite, denumerable, and deduces that it has cardinality `omega`.\n-/\n\nnamespace rat\nopen denumerable\n\ninstance : infinite ℚ :=\ninfinite.of_injective (coe : ℕ → ℚ) nat.cast_injective\n\nprivate def denumerable_aux : ℚ ≃ { x : ℤ × ℕ // 0 < x.2 ∧ x.1.nat_abs.coprime x.2 } :=\n{ to_fun := λ x, ⟨⟨x.1, x.2⟩, x.3, x.4⟩,\n  inv_fun := λ x, ⟨x.1.1, x.1.2, x.2.1, x.2.2⟩,\n  left_inv := λ ⟨_, _, _, _⟩, rfl,\n  right_inv := λ ⟨⟨_, _⟩, _, _⟩, rfl }\n\n/-- **Denumerability of the Rational Numbers** -/\ninstance : denumerable ℚ :=\nbegin\n  let T := { x : ℤ × ℕ // 0 < x.2 ∧ 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 : #ℚ = ℵ₀ := by simp\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/rat/denumerable.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7532567226446321}}
{"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 data.nat.prime\nimport data.nat.mul_ind\n\n/-!\n# Prime factorizations\n\n `n.factorization` is the finitely supported function `ℕ →₀ ℕ`\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 : ℕ`.\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-/\n\nopen nat finset list finsupp\nopen_locale big_operators\n\nnamespace nat\n\n/-- `n.factorization` is the finitely supported function `ℕ →₀ ℕ`\n mapping each prime factor of `n` to its multiplicity in `n`. -/\nnoncomputable def factorization (n : ℕ) : ℕ →₀ ℕ := (n.factors : multiset ℕ).to_finsupp\n\n@[simp] lemma factorization_prod_pow_eq_self {n : ℕ} (hn : n ≠ 0) : n.factorization.prod pow = n :=\nbegin\n  simp only [←prod_to_multiset, factorization, multiset.coe_prod, multiset.to_finsupp_to_multiset],\n  exact prod_factors hn.bot_lt,\nend\n\nlemma factorization_eq_count {n p : ℕ} : n.factorization p = n.factors.count p :=\nby simp [factorization]\n-- TODO: As part of the unification mentioned in the TODO above,\n-- consider making this a [simp] lemma from `n.factors.count` to `n.factorization`\n\n/-- Every nonzero natural number has a unique prime factorization -/\nlemma factorization_inj : set.inj_on factorization { x : ℕ | x ≠ 0 } :=\nλ a ha b hb h, eq_of_count_factors_eq\n  (zero_lt_iff.mpr ha) (zero_lt_iff.mpr hb) (λ p, by simp [←factorization_eq_count, h])\n\n@[simp] lemma factorization_zero : factorization 0 = 0  :=\nby simp [factorization]\n\n@[simp] lemma factorization_one : factorization 1 = 0 :=\nby simp [factorization]\n\n/-- The support of `n.factorization` is exactly `n.factors.to_finset` -/\n@[simp] lemma support_factorization {n : ℕ} :\n  n.factorization.support = n.factors.to_finset :=\nby simpa [factorization, multiset.to_finsupp_support]\n\nlemma factor_iff_mem_factorization {n p : ℕ} : p ∈ n.factorization.support ↔ p ∈ n.factors :=\nby simp only [support_factorization, list.mem_to_finset]\n\nlemma prime_of_mem_factorization {n p : ℕ} : p ∈ n.factorization.support → p.prime :=\n(@prime_of_mem_factors n p) ∘ (@factor_iff_mem_factorization n p).mp\n\nlemma pos_of_mem_factorization {n p : ℕ} : p ∈ n.factorization.support → 0 < p :=\n(@prime.pos p) ∘ (@prime_of_mem_factorization n p)\n\nlemma factorization_eq_zero_of_non_prime (n p : ℕ) (hp : ¬p.prime) : n.factorization p = 0 :=\nnot_mem_support_iff.1 (mt prime_of_mem_factorization hp)\n\n/-- The only numbers with empty prime factorization are `0` and `1` -/\nlemma factorization_eq_zero_iff (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 :=\nby simp [factorization, add_equiv.map_eq_zero_iff, multiset.coe_eq_zero]\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 : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :\n  (a * b).factorization = a.factorization + b.factorization :=\nby { ext p, simp only [add_apply, factorization_eq_count,\n  count_factors_mul_of_pos (zero_lt_iff.mpr ha) (zero_lt_iff.mpr hb)] }\n\n/-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/\nlemma factorization_pow {n k : ℕ} :\n  factorization (n^k) = k • n.factorization :=\nby { ext p, simp [factorization_eq_count, factors_count_pow] }\n\n/-- The only prime factor of prime `p` is `p` itself, with multiplicity `1` -/\n@[simp] lemma prime.factorization {p : ℕ} (hp : prime p) :\n  p.factorization = single p 1 :=\nbegin\n  ext q,\n  rw [factorization_eq_count, factors_prime hp, single_apply, count_singleton', if_congr eq_comm];\n  refl,\nend\n\n/-- For prime `p` the only prime factor of `p^k` is `p` with multiplicity `k` -/\n@[simp] lemma prime.factorization_pow {p k : ℕ} (hp : prime p) :\n  factorization (p^k) = single p k :=\nby simp [factorization_pow, hp.factorization]\n\n/-- For any `p : ℕ` and any function `g : α → ℕ` that's non-zero on `S : finset α`,\nthe power of `p` in `S.prod g` equals the sum over `x ∈ 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 {α : Type*} {S : finset α} {g : α → ℕ} (hS : ∀ x ∈ S, g x ≠ 0) :\n  (S.prod g).factorization = S.sum (λ 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 ≠ 0 := prod_ne_zero_iff.mpr (λ x hx, hS x (hTS hx)),\n    simp [prod_insert hxT, sum_insert hxT, ←IH, factorization_mul (hS x hxS) hT] }\nend\n\n/-! ### Factorizations of pairs of coprime numbers -/\n\n/-- The prime factorizations of coprime `a` and `b` are disjoint -/\nlemma factorization_disjoint_of_coprime {a b : ℕ} (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 power of `p` in `a * b` is the sum of the powers in `a` and `b` -/\nlemma factorization_mul_of_coprime {a b : ℕ} (hab : coprime a b) :\n  (a * b).factorization = a.factorization + b.factorization :=\nbegin\n  ext q,\n  simp only [finsupp.coe_add, add_apply, factorization_eq_count, count_factors_mul_of_coprime hab],\nend\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 : ℕ} (hab : coprime a b) :\n  (a * b).factorization.support = a.factorization.support ∪ b.factorization.support :=\nbegin\n  rw factorization_mul_of_coprime hab,\n  exact support_add_eq (factorization_disjoint_of_coprime hab),\nend\n\nlemma factorization_mul_support {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :\n  (a * b).factorization.support = a.factorization.support ∪ b.factorization.support :=\nbegin\n  ext q,\n  simp only [finset.mem_union, factor_iff_mem_factorization],\n  rw mem_factors_mul ha hb,\nend\n\n/-- For any multiplicative function `f` with `f 1 = 1` and any `n > 0`,\nwe can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/\nlemma multiplicative_factorization {β : Type*} [comm_monoid β] (f : ℕ → β)\n  (h_mult : ∀ x y : ℕ, coprime x y → f (x * y) = f x * f y) (hf : f 1 = 1) :\n  ∀ {n : ℕ}, n ≠ 0 → f n = n.factorization.prod (λ p k, f (p ^ k)) :=\nbegin\n  apply' nat.rec_on_pos_prime_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, ←prod_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' {β : Type*} [comm_monoid β] (f : ℕ → β)\n  (h_mult : ∀ x y : ℕ, coprime x y → f (x * y) = f x * f y) (hf0 : f 0 = 1) (hf1 : f 1 = 1) :\n  ∀ {n : ℕ}, f n = n.factorization.prod (λ p k, f (p ^ k)) :=\nbegin\n  apply' nat.rec_on_pos_prime_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, ←prod_add_index_of_disjoint],\n    convert (factorization_disjoint_of_coprime hab) },\nend\n\n/-! ### Factorization and divisibility -/\n\nlemma factorization_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :\n  d.factorization ≤ n.factorization ↔ d ∣ n :=\nbegin\n  split,\n  { intro hdn,\n    set K := n.factorization - d.factorization with hK,\n    use K.prod pow,\n    rw [←factorization_prod_pow_eq_self hn, ←factorization_prod_pow_eq_self hd,\n        ←finsupp.prod_add_index pow_zero pow_add, hK, add_tsub_cancel_of_le hdn] },\n  { rintro ⟨c, rfl⟩, rw factorization_mul hd (right_ne_zero_of_mul hn), simp },\nend\n\nlemma prime_pow_dvd_iff_le_factorization (p k n : ℕ) (pp : prime p) (hn : n ≠ 0) :\n  p ^ k ∣ n ↔ k ≤ n.factorization p :=\nby rw [←factorization_le_iff_dvd (pow_pos pp.pos k).ne' hn, pp.factorization_pow, single_le_iff]\n\nlemma exists_factorization_lt_of_lt {a b : ℕ} (ha : a ≠ 0) (hab : a < b) :\n  ∃ p : ℕ, a.factorization p < b.factorization p :=\nbegin\n  have hb : b ≠ 0 := (ha.bot_lt.trans hab).ne',\n  contrapose! hab,\n  rw [←finsupp.le_def, factorization_le_iff_dvd hb ha] at hab,\n  exact le_of_dvd ha.bot_lt hab,\nend\n\n@[simp]\nlemma div_factorization_eq_tsub_of_dvd {d n : ℕ} (hn : n ≠ 0) (h : d ∣ n) :\n  (n / d).factorization = n.factorization - d.factorization :=\nbegin\n  have hd : d ≠ 0 := ne_zero_of_dvd_ne_zero hn h,\n  cases dvd_iff_exists_eq_mul_left.mp h with c hc,\n  have hc_pos : c ≠ 0, { subst hc, exact left_ne_zero_of_mul hn },\n  rw [hc, nat.mul_div_cancel c hd.bot_lt, factorization_mul hc_pos hd, add_tsub_cancel_right],\nend\n\nlemma dvd_iff_div_factorization_eq_tsub (d n : ℕ) (hd : d ≠ 0) (hdn : d ≤ n) :\n  d ∣ n ↔ (n / d).factorization = n.factorization - d.factorization :=\nbegin\n  have hn : n ≠ 0 := (lt_of_lt_of_le hd.bot_lt hdn).ne.symm,\n  refine ⟨div_factorization_eq_tsub_of_dvd hn, _⟩,\n  { rcases eq_or_lt_of_le hdn with rfl | hd_lt_n, { simp },\n    have h1 : n / d ≠ 0 := λ 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, ←lt_tsub_iff_right, h, tsub_apply,\n      lt_self_iff_false] at hp },\nend\n\nlemma pow_factorization_dvd (p d : ℕ) : p ^ d.factorization p ∣ d :=\nbegin\n  rcases eq_or_ne d 0 with rfl | hd, { simp },\n  by_cases pp : prime p,\n  { rw prime_pow_dvd_iff_le_factorization p _ d pp hd },\n  { rw factorization_eq_zero_of_non_prime d p pp, simp },\nend\n\nlemma dvd_iff_prime_pow_dvd_dvd {n d : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :\n  d ∣ n ↔ ∀ p k : ℕ, prime p → p^k ∣ d → p^k ∣ n :=\nbegin\n  split,\n  { exact λ h p k pp hpkd, dvd_trans hpkd h },\n  { intros h,\n    rw [←factorization_le_iff_dvd hd hn, finsupp.le_def],\n    intros p,\n    by_cases pp : prime p, swap,\n    { rw factorization_eq_zero_of_non_prime d p pp, exact zero_le' },\n    rw ←prime_pow_dvd_iff_le_factorization p _ n pp hn,\n    exact h p _ pp (pow_factorization_dvd p _) },\nend\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/factorization.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025424, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7532567179048336}}
{"text": "-- Unicidad_del_limite_de_las_sucesiones_convergentes.lean\n-- Unicidad del límite de las sucesiones convergentes\n-- José A. Alonso Jiménez\n-- Sevilla, 12 de julio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, una sucesión u₀, u₁, u₂, ... se puede representar mediante\n-- una función (u : ℕ → ℝ) de forma que u(n) es uₙ.\n--\n-- Se define que a es el límite de la sucesión u, por\n--    def limite : (ℕ → ℝ) → ℝ → Prop :=\n--    λ u a, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - a| < ε\n-- donde se usa la notación |x| para el valor absoluto de x\n--    notation `|`x`|` := abs x\n--\n-- Demostrar que cada sucesión tiene como máximo un límite.\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables {u : ℕ → ℝ}\nvariables {a b : ℝ}\n\nnotation `|`x`|` := abs x\n\ndef limite : (ℕ → ℝ) → ℝ → Prop :=\nλ u c, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - c| < ε\n\n-- 1ª demostración\n-- ===============\n\nlemma aux\n  (ha : limite u a)\n  (hb : limite u b)\n  : b ≤ a :=\nbegin\n  by_contra h,\n  set ε := b - a with hε,\n  cases ha (ε/2) (by linarith) with A hA,\n  cases hb (ε/2) (by linarith) with B hB,\n  set N := max A B with hN,\n  have hAN : A ≤ N := le_max_left A B,\n  have hBN : B ≤ N := le_max_right A B,\n  specialize hA N hAN,\n  specialize hB N hBN,\n  rw abs_lt at hA hB,\n  linarith,\nend\n\nexample\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nle_antisymm (aux hb ha) (aux ha hb)\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  by_contra h,\n  wlog hab : a < b,\n  { have : a < b ∨ a = b ∨ b < a := lt_trichotomy a b,\n    tauto },\n  set ε := b - a with hε,\n  specialize ha (ε/2),\n  have hε2 : ε/2 > 0 := by linarith,\n  specialize ha hε2,\n  cases ha with A hA,\n  cases hb (ε/2) (by linarith) with B hB,\n  set N := max A B with hN,\n  have hAN : A ≤ N := le_max_left A B,\n  have hBN : B ≤ N := le_max_right A B,\n  specialize hA N hAN,\n  specialize hB N hBN,\n  rw abs_lt at hA hB,\n  linarith,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample\n  (ha : limite u a)\n  (hb : limite u b)\n  : a = b :=\nbegin\n  by_contra h,\n  wlog hab : a < b,\n  { have : a < b ∨ a = b ∨ b < a := lt_trichotomy a b,\n    tauto },\n  set ε := b - a with hε,\n  cases ha (ε/2) (by linarith) with A hA,\n  cases hb (ε/2) (by linarith) with B hB,\n  set N := max A B with hN,\n  have hAN : A ≤ N := le_max_left A B,\n  have hBN : B ≤ N := le_max_right A B,\n  specialize hA N hAN,\n  specialize hB N hBN,\n  rw abs_lt at hA hB,\n  linarith,\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/Unicidad_del_limite_de_las_sucesiones_convergentes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7532153647767502}}
{"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\" (`¬`)\n\nWe learn about how to manipulate `¬ P` in Lean.\n\n# The definition of `¬ P`\n\nIn Lean, `¬ P` is *defined* to mean `P → false`. So `¬ P` and `P → false`\nare *definitionally equal*. Check out the explanation of definitional\nequality in the \"equality\" section of Part B of the course notes:\nhttps://www.ma.imperial.ac.uk/~buzzard/xena/formalising-mathematics-2023/Part_B/equality.html\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 : ¬ true → false :=\nbegin\n  sorry\nend\n\nexample : false → ¬ true :=\nbegin\n  sorry\nend\n\nexample : ¬ false → true :=\nbegin\n  sorry\nend\n\nexample : true → ¬ false :=\nbegin\n  sorry\nend\n\nexample : false → ¬ P :=\nbegin\n  sorry\nend\n\nexample : P → ¬ P → false :=\nbegin\n  sorry\nend\n\nexample : P → ¬ (¬ P) :=\nbegin\n  sorry\nend\n\nexample : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  sorry\nend\n\nexample : ¬ ¬ false → false :=\nbegin\n  sorry\nend\n\nexample : ¬ ¬ P → P :=\nbegin\n  sorry\nend\n\nexample : (¬ Q → ¬ P) → (P → Q) :=\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/section01logic/sheet3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.82893881677331, "lm_q1q2_score": 0.7531886402800859}}
{"text": "/-\nCopyright (c) 2022 Hans Parshall. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Hans Parshall\n-/\nimport analysis.matrix\nimport analysis.normed_space.basic\nimport data.complex.is_R_or_C\nimport linear_algebra.unitary_group\n\n/-!\n# Unitary matrices\n\nThis file collects facts about the unitary matrices over `𝕜` (either `ℝ` or `ℂ`).\n-/\n\nopen_locale big_operators matrix\n\nvariables {𝕜 n E : Type*}\n\nnamespace matrix\nvariables [fintype n] [semi_normed_group E] [star_add_monoid E] [normed_star_group E]\n\nlocal attribute [instance] matrix.semi_normed_group\n\n@[simp] lemma entrywise_sup_norm_star_eq_norm (M : matrix n n E) : ∥star M∥ = ∥M∥ :=\nbegin\n  refine le_antisymm (by simp [matrix.norm_le_iff, M.norm_entry_le_entrywise_sup_norm]) _,\n  refine ((matrix.norm_le_iff (norm_nonneg _)).mpr (λ i j, _)).trans\n    (congr_arg _ M.star_eq_conj_transpose).ge,\n  exact (normed_star_group.norm_star).symm.le.trans Mᴴ.norm_entry_le_entrywise_sup_norm\nend\n\n@[priority 100] -- see Note [lower instance priority]\ninstance to_normed_star_group : normed_star_group (matrix n n E) :=\n⟨matrix.entrywise_sup_norm_star_eq_norm⟩\n\nend matrix\n\nsection entrywise_sup_norm\nvariables [is_R_or_C 𝕜] [fintype n] [decidable_eq n]\n\nlemma entry_norm_bound_of_unitary {U : matrix n n 𝕜} (hU : U ∈ matrix.unitary_group n 𝕜) (i j : n):\n  ∥U i j∥ ≤ 1 :=\nbegin\n  -- The norm squared of an entry is at most the L2 norm of its row.\n  have norm_sum : ∥ U i j ∥^2 ≤ (∑ x, ∥ U i x ∥^2),\n  { apply multiset.single_le_sum,\n    { intros x h_x,\n      rw multiset.mem_map at h_x,\n      cases h_x with a h_a,\n      rw ← h_a.2,\n      apply sq_nonneg },\n    { rw multiset.mem_map,\n      use j,\n      simp only [eq_self_iff_true, finset.mem_univ_val, and_self, sq_eq_sq] } },\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ\n  have diag_eq_norm_sum : (U ⬝ Uᴴ) i i = ∑ (x : n), ∥ U i x ∥^2,\n  { simp only [matrix.mul_apply, matrix.conj_transpose_apply, ←star_ring_end_apply,\n               is_R_or_C.mul_conj, is_R_or_C.norm_sq_eq_def', is_R_or_C.of_real_pow] },\n  -- The L2 norm of a row is a diagonal entry of U ⬝ Uᴴ, real part\n  have re_diag_eq_norm_sum : is_R_or_C.re ((U ⬝ Uᴴ) i i) = ∑ (x : n), ∥ U i x ∥^2,\n  { rw is_R_or_C.ext_iff at diag_eq_norm_sum,\n    rw diag_eq_norm_sum.1,\n    norm_cast },\n  -- Since U is unitary, the diagonal entries of U ⬝ Uᴴ are all 1\n  have mul_eq_one : (U ⬝ Uᴴ) = 1, from unitary.mul_star_self_of_mem hU,\n  have diag_eq_one : is_R_or_C.re ((U ⬝ Uᴴ) i i) = 1,\n  { simp only [mul_eq_one, eq_self_iff_true, matrix.one_apply_eq, is_R_or_C.one_re] },\n  -- Putting it all together\n  rw [← sq_le_one_iff (norm_nonneg (U i j)), ← diag_eq_one, re_diag_eq_norm_sum],\n  exact norm_sum,\nend\n\nlocal attribute [instance] matrix.normed_group\n\n/-- The entrywise sup norm of a unitary matrix is at most 1. -/\nlemma entrywise_sup_norm_bound_of_unitary {U : matrix n n 𝕜} (hU : U ∈ matrix.unitary_group n 𝕜) :\n  ∥ U ∥ ≤ 1 :=\nbegin\n  simp_rw pi_norm_le_iff zero_le_one,\n  intros i j,\n  exact entry_norm_bound_of_unitary hU _ _\nend\n\nend entrywise_sup_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/normed_space/star/matrix.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178944582995, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7531886384915478}}
{"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ölzl, Yuyang Zhao\n-/\nimport algebra.order.monoid.lemmas\nimport algebra.order.zero_le_one\nimport data.nat.cast.defs\n\n/-!\n# Order of numerials in an `add_monoid_with_one`.\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n-/\n\nvariable {α : Type*}\n\nopen function\n\nlemma lt_add_one [has_one α] [add_zero_class α] [partial_order α] [zero_le_one_class α]\n  [ne_zero (1 : α)] [covariant_class α α (+) (<)] (a : α) : a < a + 1 :=\nlt_add_of_pos_right _ zero_lt_one\n\nlemma lt_one_add [has_one α] [add_zero_class α] [partial_order α] [zero_le_one_class α]\n  [ne_zero (1 : α)] [covariant_class α α (swap (+)) (<)] (a : α) : a < 1 + a :=\nlt_add_of_pos_left _ zero_lt_one\n\nvariable [add_monoid_with_one α]\n\nlemma zero_le_two [preorder α] [zero_le_one_class α] [covariant_class α α (+) (≤)] :\n  (0 : α) ≤ 2 :=\nadd_nonneg zero_le_one zero_le_one\n\nlemma zero_le_three [preorder α] [zero_le_one_class α] [covariant_class α α (+) (≤)] :\n  (0 : α) ≤ 3 :=\nadd_nonneg zero_le_two zero_le_one\n\nlemma zero_le_four [preorder α] [zero_le_one_class α] [covariant_class α α (+) (≤)] :\n  (0 : α) ≤ 4 :=\nadd_nonneg zero_le_two zero_le_two\n\nlemma one_le_two [has_le α] [zero_le_one_class α] [covariant_class α α (+) (≤)] :\n  (1 : α) ≤ 2 :=\ncalc 1 = 1 + 0 : (add_zero 1).symm\n   ... ≤ 1 + 1 : add_le_add_left zero_le_one _\n\nlemma one_le_two' [has_le α] [zero_le_one_class α] [covariant_class α α (swap (+)) (≤)] :\n  (1 : α) ≤ 2 :=\ncalc 1 = 0 + 1 : (zero_add 1).symm\n   ... ≤ 1 + 1 : add_le_add_right zero_le_one _\n\nsection\nvariables [partial_order α] [zero_le_one_class α] [ne_zero (1 : α)]\n\nsection\nvariables [covariant_class α α (+) (≤)]\n\n/-- See `zero_lt_two'` for a version with the type explicit. -/\n@[simp] lemma zero_lt_two : (0 : α) < 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 : α) < 3 := 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 : α) < 4 := lt_add_of_lt_of_nonneg zero_lt_two zero_le_two\n\nvariables (α)\n\n/-- See `zero_lt_two` for a version with the type implicit. -/\nlemma zero_lt_two' : (0 : α) < 2 := zero_lt_two\n/-- See `zero_lt_three` for a version with the type implicit. -/\nlemma zero_lt_three' : (0 : α) < 3 := zero_lt_three\n/-- See `zero_lt_four` for a version with the type implicit. -/\nlemma zero_lt_four' : (0 : α) < 4 := zero_lt_four\n\ninstance zero_le_one_class.ne_zero.two : ne_zero (2 : α) := ⟨zero_lt_two.ne'⟩\ninstance zero_le_one_class.ne_zero.three : ne_zero (3 : α) := ⟨zero_lt_three.ne'⟩\ninstance zero_le_one_class.ne_zero.four : ne_zero (4 : α) := ⟨zero_lt_four.ne'⟩\n\nend\n\nlemma one_lt_two [covariant_class α α (+) (<)] : (1 : α) < 2 := lt_add_one _\n\nend\n\nalias zero_lt_two ← two_pos\nalias zero_lt_three ← three_pos\nalias zero_lt_four ← four_pos\n", "meta": {"author": "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/nat_cast.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7531597457364295}}
{"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.basic\n\n/-!\n## Counit morphisms for multivariate polynomials\n\nOne may consider the ring of multivariate polynomials `mv_polynomial A R` with coefficients in `R`\nand variables indexed by `A`. If `A` is not just a type, but an algebra over `R`,\nthen there is a natural surjective algebra homomorphism `mv_polynomial A R →ₐ[R] A`\nobtained by `X a ↦ a`.\n\n### Main declarations\n\n* `mv_polynomial.acounit R A` is the natural surjective algebra homomorphism\n  `mv_polynomial A R →ₐ[R] A` obtained by `X a ↦ a`\n* `mv_polynomial.counit` is an “absolute” variant with `R = ℤ`\n* `mv_polynomial.counit_nat` is an “absolute” variant with `R = ℕ`\n\n-/\n\nnamespace mv_polynomial\nopen function\n\nvariables (A B R : Type*) [comm_semiring A] [comm_semiring B] [comm_ring R] [algebra A B]\n\n/-- `mv_polynomial.acounit A B` is the natural surjective algebra homomorphism\n`mv_polynomial B A →ₐ[A] B` obtained by `X a ↦ a`.\n\nSee `mv_polynomial.counit` for the “absolute” variant with `A = ℤ`,\nand `mv_polynomial.counit_nat` for the “absolute” variant with `A = ℕ`. -/\nnoncomputable def acounit : mv_polynomial B A →ₐ[A] B :=\naeval id\n\nvariables {B}\n\n@[simp] lemma acounit_X (b : B) : acounit A B (X b) = b := aeval_X _ b\n\nvariables {A} (B)\n\n@[simp] lemma acounit_C (a : A) : acounit A B (C a) = algebra_map A B a := aeval_C _ a\n\nvariables (A)\n\nlemma acounit_surjective : surjective (acounit A B) := λ b, ⟨X b, acounit_X A b⟩\n\n/-- `mv_polynomial.counit R` is the natural surjective ring homomorphism\n`mv_polynomial R ℤ →+* R` obtained by `X r ↦ r`.\n\nSee `mv_polynomial.acounit` for a “relative” variant for algebras over a base ring,\nand `mv_polynomial.counit_nat` for the “absolute” variant with `R = ℕ`. -/\nnoncomputable def counit : mv_polynomial R ℤ →+* R :=\nacounit ℤ R\n\n/-- `mv_polynomial.counit_nat A` is the natural surjective ring homomorphism\n`mv_polynomial A ℕ →+* A` obtained by `X a ↦ a`.\n\nSee `mv_polynomial.acounit` for a “relative” variant for algebras over a base ring\nand `mv_polynomial.counit` for the “absolute” variant with `A = ℤ`. -/\nnoncomputable def counit_nat : mv_polynomial A ℕ →+* A :=\nacounit ℕ A\n\n\nlemma counit_surjective : surjective (counit R) := acounit_surjective ℤ R\nlemma counit_nat_surjective : surjective (counit_nat A) := acounit_surjective ℕ A\n\n\n\nvariables {R A}\n\n@[simp] lemma counit_X (r : R) : counit R (X r) = r := acounit_X _ _\n@[simp] lemma counit_nat_X (a : A) : counit_nat A (X a) = a := acounit_X _ _\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/counit.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.753159741250952}}
{"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 `ℤ` involving powers.\n-/\n\n\nopen Nat\n\nnamespace Int\n\nset_option linter.deprecated false in\n@[simp]\ntheorem sign_pow_bit1 (k : ℕ) : ∀ n : ℤ, n.sign ^ bit1 k = n.sign\n  | (_ + 1 : ℕ) => 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 : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) :\n    ↑(p ^ m) ∣ 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 ↑(p ^ m) ∣ -(↑(k + 1) : ℤ)\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 : ℕ} {m : ℤ} (hk : 1 ≤ k) (hpk : ↑(p ^ k) ∣ m) : ↑p ∣ m := by\n  rw [← 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": "siddhartha-gadgil", "repo": "LeanAide", "sha": "7862af73ee2f0be08b20fd3e4148e20bf4a81054", "save_path": "github-repos/lean/siddhartha-gadgil-LeanAide", "path": "github-repos/lean/siddhartha-gadgil-LeanAide/LeanAide-7862af73ee2f0be08b20fd3e4148e20bf4a81054/LeanCodePrompts/PowTest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8459424353665382, "lm_q1q2_score": 0.7531376707631842}}
{"text": "import tactic.push_neg \nimport .src_11_lem_reductio\n\nvariables p q r : Prop \n\nnamespace mth1001\n\nsection contrapositive\n/-\nRecall that the contrapositive of the statement `p → q` is the statement `¬q → ¬p`.\n\nLean has a tactic `contrapose` that turns any goal of the form `p → q` into its contrapositive.\n-/\n\nexample (h : ¬q → ¬p) : p → q :=\nbegin\n  contrapose,\n  exact h,\nend \n\n/-\nBelow, `contrapose` replaces `¬q → ¬p` with its contrapositve, `¬¬p → ¬¬q`. We simplify this\nexpression using our result `not_not` which asserts `¬¬a ↔ a`, for any proposition `a`.\n-/\nexample (h : p → q) : ¬q → ¬p :=\nbegin \n  contrapose,\n  rw [not_not, not_not],\n  exact h,\nend \n\n/-\nInstead of `not_not`, we can use the tactic `push_neg`, a big bag of tricks used to push a negation\ninside the goal. \n-/\nexample (h : p → q) : ¬q → ¬p :=\nbegin \n  contrapose,\n  push_neg,\n  exact h,\nend\n\n-- Exercise 069:\n/-\nUsing only the tactics `push_neg`, `intro`, and `exact`, prove the following,\nwhich we've seen as `not_and_of_not_or_not`.\n-/\nexample : (¬p ∨ ¬ q) → ¬(p ∧ q) :=\nbegin\n  sorry  \nend \n\n-- Exercise 070:\n-- We can use `contrapose` to reprove `not_or_not_of_not_and`. Don't use `push_neg` in this example.\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\nbegin \n  contrapose,\n  rw not_not,\n  intro h,\n  have h₁ : p ↔ ¬¬p, from not_not.symm,\n  sorry  \nend \n\n/-\nThe above result is proved easily using the combination of `contrapose` and `push_neg`. In fact,\nthis is such a commmon combination that Lean offers it as the single tactic `contrapose!`.\n-/\n\nexample : (¬q → ¬p) → (p → q) :=\nbegin \n  intro h,\n  contrapose!,\n  exact h,\nend\n\n-- Exercise 071:\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\nbegin\n  contrapose!,\n  sorry  \nend\n\n/-\nA typical first step in proving a goal `p → q` is implication introduction, applying the tactic\n`intro h₁` (say) to introduce the premise `h₁ : p` and changing the goal to `q`.\n\nSometimes, it's useful to go in the other direction. In the following example, the goal is `q`\nwhile there are premises `h₁ : p` and `h₂ : ¬q → ¬p`.\n\nThe `revert` tactic 'puts back' the premise `h₁ : p`, transforming the goal into `p → q` and\nremoving `h₁`. After reversion, the goal is amenable to the `contrapose` tactic.\n-/\nexample (h₁ : p) (h₂ : ¬q → ¬p) : q :=\nbegin \n  revert h₁,\n  contrapose,\n  exact h₂,\nend\n\n-- Exercise 072:\n-- Prove the following using `revert`, `apply`, and `not_or_not_of_not_and`.\nexample (h : ¬(p ∧ q)) : ¬p ∨ ¬q :=\nbegin\n  sorry  \nend\n\n/-\nAn alternative to `revert` is to use `contrapose` with the name of a premise. At the point of\napplication in the proof below, the goal is `q` and `h₁` is the assertion `h₁ : p`. Focussing just\non this premise and the goal, we have to prove `p → q`. The contrapositive is `¬q → ¬p`.\nThe application `contrapose h₁` replaces the goal with `¬p` and replaces `h₁` with `h₁ : ¬q`.\n-/\nexample (h₁ : p) (h₂ : ¬q → ¬p) : q :=\nbegin \n  contrapose h₁,\n  exact h₂ h₁,\nend\n\n-- Exercise 073:\n-- Prove the following using the `revert`, `rw`, `apply`, `exact`, `contrapose`, tactics with\n-- the results `not_not` and `not_and_not_of_not_or`.\nexample (h : ¬(p ∧ q) ) : ¬p ∨ ¬q :=\nbegin \n  have k : ¬(¬¬p ∧ ¬¬q),\n  { sorry, }, \n  sorry  \nend \n\nend contrapositive\n\n/-\nSUMMARY:\n\n* The contrapositive of `p → q` is `¬q → ¬p`.\n* The `contrapose` tactic changes a goal into its contrapositive.\n* Given `⊢ q` and `h : p`, `contrapose h` produces `⊢ ¬p` and `h : ¬q`.\n* The `push_neg` tactic pushes a negation into a goal or premise.\n* `contrapose!` is a combination of `contrapose` and `push_neg`.\n* The `revert` tactic puts a premise back into the goal.\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_12_contrapositive.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424489603726, "lm_q2_score": 0.8902942173896131, "lm_q1q2_score": 0.7531376705538277}}
{"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.order_dual\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 ≤ z → (x ⊔ y) ⊓ z ≤ x ⊔ (y ⊓ z)`\n- `inf_Icc_order_iso_Icc_sup` gives an order isomorphism between the intervals\n  `[a ⊓ b, a]` and `[b, a ⊔ 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 ⊓ z) ⊔ (y ⊓ z) = ((x ⊓ z) ⊔ y) ⊓ 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 {α : Type*}\n\n/-- A modular lattice is one with a limited associativity between `⊓` and `⊔`. -/\nclass is_modular_lattice α [lattice α] : Prop :=\n(sup_inf_le_assoc_of_le : ∀ {x : α} (y : α) {z : α}, x ≤ z → (x ⊔ y) ⊓ z ≤ x ⊔ (y ⊓ z))\n\nsection is_modular_lattice\nvariables [lattice α] [is_modular_lattice α ]\n\ntheorem sup_inf_assoc_of_le {x : α} (y : α) {z : α} (h : x ≤ z) :\n  (x ⊔ y) ⊓ z = x ⊔ (y ⊓ 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 : α} :\n  (x ⊓ z) ⊔ (y ⊓ z) = ((x ⊓ z) ⊔ y) ⊓ z :=\n(sup_inf_assoc_of_le y inf_le_right).symm\n\nlemma inf_sup_assoc_of_le {x : α} (y : α) {z : α} (h : z ≤ x) :\n  (x ⊓ y) ⊔ z = x ⊓ (y ⊔ z) :=\nby rw [inf_comm, sup_comm, ← sup_inf_assoc_of_le y h, inf_comm, sup_comm]\n\ninstance : is_modular_lattice (order_dual α) :=\n⟨λ 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) })⟩\n\ntheorem is_modular_lattice.sup_inf_sup_assoc {x y z : α} :\n  (x ⊔ z) ⊓ (y ⊔ z) = ((x ⊔ z) ⊓ y) ⊔ z :=\n@is_modular_lattice.inf_sup_inf_assoc (order_dual α) _ _ _ _ _\n\n/-- The diamond isomorphism between the intervals `[a ⊓ b, a]` and `[b, a ⊔ b]` -/\ndef inf_Icc_order_iso_Icc_sup (a b : α) : set.Icc (a ⊓ b) a ≃o set.Icc b (a ⊔ b) :=\n{ to_fun := λ x, ⟨x ⊔ b, ⟨le_sup_right, sup_le_sup_right x.prop.2 b⟩⟩,\n  inv_fun := λ x, ⟨a ⊓ x, ⟨inf_le_inf_left a x.prop.1, inf_le_left⟩⟩,\n  left_inv := λ x, subtype.ext (by { change a ⊓ (↑x ⊔ b) = ↑x,\n    rw [sup_comm, ← inf_sup_assoc_of_le _ x.prop.2, sup_eq_right.2 x.prop.1] }),\n  right_inv := λ x, subtype.ext (by { change a ⊓ ↑x ⊔ b = ↑x,\n    rw [inf_comm, inf_sup_assoc_of_le _ x.prop.1, inf_eq_left.2 x.prop.2] }),\n  map_rel_iff' := λ x y, begin\n    simp only [subtype.mk_le_mk, equiv.coe_fn_mk, and_true, le_sup_right],\n    rw [← subtype.coe_le_coe],\n    refine ⟨λ h, _, λ h, sup_le_sup_right h _⟩,\n    rw [← sup_eq_right.2 x.prop.1, inf_sup_assoc_of_le _ x.prop.2, sup_comm,\n      ← 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 [bounded_lattice α] [is_modular_lattice α]\n\n/-- The diamond isomorphism between the intervals `set.Iic a` and `set.Ici b`. -/\ndef Iic_order_iso_Ici {a b : α} (h : is_compl a b) : set.Iic a ≃o set.Ici b :=\n(order_iso.set_congr (set.Iic a) (set.Icc (a ⊓ b) a) (h.inf_eq_bot.symm ▸ set.Icc_bot.symm)).trans $\n  (inf_Icc_order_iso_Icc_sup a b).trans\n  (order_iso.set_congr (set.Icc b (a ⊔ b)) (set.Ici b) (h.sup_eq_top.symm ▸ set.Icc_top))\n\nend is_compl\n\ntheorem is_modular_lattice_iff_inf_sup_inf_assoc [lattice α] :\n  is_modular_lattice α ↔ ∀ (x y z : α), (x ⊓ z) ⊔ (y ⊓ z) = ((x ⊓ z) ⊔ y) ⊓ z :=\n⟨λ h, @is_modular_lattice.inf_sup_inf_assoc _ _ h, λ h, ⟨λ x y z xz, by rw [← inf_eq_left.2 xz, h]⟩⟩\n\nnamespace distrib_lattice\n\n@[priority 100]\ninstance [distrib_lattice α] : is_modular_lattice α :=\n⟨λ x y z xz, by rw [inf_sup_right, inf_eq_left.2 xz]⟩\n\nend distrib_lattice\n\ntheorem disjoint.disjoint_sup_right_of_disjoint_sup_left\n  [bounded_lattice α] [is_modular_lattice α] {a b c : α}\n  (h : disjoint a b) (hsup : disjoint (a ⊔ b) c) :\n  disjoint a (b ⊔ c) :=\nbegin\n  rw [disjoint, ← h.eq_bot, sup_comm],\n  apply le_inf inf_le_left,\n  apply (inf_le_inf_right (c ⊔ b) le_sup_right).trans,\n  rw [sup_comm, is_modular_lattice.sup_inf_sup_assoc, hsup.eq_bot, bot_sup_eq]\nend\n\nnamespace is_modular_lattice\n\nvariables [bounded_lattice α] [is_modular_lattice α] {a : α}\n\ninstance is_modular_lattice_Iic : is_modular_lattice (set.Iic a) :=\n⟨λ x y z xz, (sup_inf_le_assoc_of_le (y : α) xz : (↑x ⊔ ↑y) ⊓ ↑z ≤ ↑x ⊔ ↑y ⊓ ↑z)⟩\n\ninstance is_modular_lattice_Ici : is_modular_lattice (set.Ici a) :=\n⟨λ x y z xz, (sup_inf_le_assoc_of_le (y : α) xz : (↑x ⊔ ↑y) ⊓ ↑z ≤ ↑x ⊔ ↑y ⊓ ↑z)⟩\n\nsection is_complemented\nvariables [is_complemented α]\n\ninstance is_complemented_Iic : is_complemented (set.Iic a) :=\n⟨λ ⟨x, hx⟩, ⟨⟨(classical.some (exists_is_compl x)) ⊓ a, set.mem_Iic.2 inf_le_right⟩, begin\n    split,\n    { change x ⊓ (classical.some _ ⊓ a) ≤ ⊥, -- improve lattice subtype API\n      rw ← inf_assoc,\n      exact le_trans inf_le_left (classical.some_spec (exists_is_compl x)).1 },\n    { change a ≤ x ⊔ (classical.some _ ⊓ a), -- improve lattice subtype API\n      rw [← sup_inf_assoc_of_le _ (set.mem_Iic.1 hx),\n          top_le_iff.1 (classical.some_spec (exists_is_compl x)).2, top_inf_eq] }\n  end⟩⟩\n\ninstance is_complemented_Ici : is_complemented (set.Ici a) :=\n⟨λ ⟨x, hx⟩, ⟨⟨(classical.some (exists_is_compl x)) ⊔ a, set.mem_Ici.2 le_sup_right⟩, begin\n    split,\n    { change x ⊓ (classical.some _ ⊔ a) ≤ a, -- improve lattice subtype API\n      rw [← inf_sup_assoc_of_le _ (set.mem_Ici.1 hx),\n          le_bot_iff.1 (classical.some_spec (exists_is_compl x)).1, bot_sup_eq] },\n    { change ⊤ ≤ x ⊔ (classical.some _ ⊔ a), -- improve lattice subtype API\n      rw ← sup_assoc,\n      exact le_trans (classical.some_spec (exists_is_compl x)).2 le_sup_left }\n  end⟩⟩\n\nend is_complemented\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/modular_lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7531376648429496}}
{"text": "#print \"------------------------------------------------\"\n#print \"Section 2.8 Dependent Types\" -- (page 16 in new ed)\n\n/- It is clear that `cons α` should have type \n            α → list α → list α \n   But what type should `cons` itself have? A first guess might be \n            Type → α → list α → list α\n   But on reflection, we see this does not make sense: the α in this expression \n   does not refer to anything, whereas it should refer to the argument of type Type. \n\n   In other words, assuming `α : Type` is the first argument to the function, the \n   type of the next two elements are `α` and `list α`. These types *depend* on the \n   first argument `α`. \n\n   This is an instance of a `Pi` type, or dependent function type. \n   If we are given `α : Type` and `β : α → Type`, then we think of β as \n   a family of types indexed by α. That is, we have a type `β a` for each `a : α`.  \n   The type \n            Π x : α, β x \n   denotes the type of functions f such that, for each `a : α`, \n   `f a` is an element of `β a`.\n\n   Note that `Π x : α, β` makes sense for any expression `β : Type`. \n   When the value of β happens to depend on x, then `Π x : α, β` denotes a \n   *dependent* function type. When β doesn't depend on x, then `Π x : α, β` \n   is the same as the type `α → β`. \n\n   Indeed, in dependent type theory (and in Lean), the `Pi` construction is \n   fundamental, and `α → β` is just notation for `Π x : α, β` when β doesn't \n   depend on α.\n-/\n\nnamespace page25\n  #print \"----- page17, new ed-------------------\"\n  universe u\n  constant list : Type u → Type u   -- N.B. we don't just want `list : Type → Type`\n  constant cons : Π (α : Type u), α → list α → list α\n  constant nil : Π (α : Type u), list α\n  constant head : Π (α : Type u), list α → α\n  constant tail : Π (α : Type u), list α → list α\n  constant append : Π (α : Type u), list α → list α → list α\n\n  #check list\n  #check @cons\n  #check @nil\n  #check @head\n  #check @tail\n  #check @append\n\nend page25  \n\n\n\nnamespace page18 --(new edition)\n  universe u\n  constant vec : Type u → ℕ → Type u\n\n  namespace vec\n    constant empty : Π (α : Type u), vec α 0\n    constant cons : Π (α : Type u) (n : ℕ), α → vec α n → vec α (n+1)\n    constant append : Π (α : Type u) (n m : ℕ), vec α n → vec α m → vec α (n+m)\n  end vec\nend page18\n\n/- One more important and illustrative example of dependent types, the\n   *Sigma types*, `Σ x : α, β x`, sometimes known as *dependent products*.\n\n   `Σ x : α, β x` denotes the type of pairs `sigma.mk a b` where `a : α` and `b : β a`.\n-/\n    \n/- Pi types Π x : α, β x generalize the notion of a function type α → β by\n   allowing β to depend on α.\n\n   Sigma types `Σ x : α, β x` generalize the cartesian product `α × β` in the same way; \n   in the expression sigma.mk a b, the type of the second element, `b : β a`, depends \n   on the first element, `a : α`.\n-/\n\nnamespace page27\n  #print \"----- page18, new ed-------------------\"\n  variable α : Type\n  variable β : α → Type\n  variable a : α\n  variable b : β a\n\n  #check sigma.mk a b          -- (a, b) : Σ (a : α), β a\n  #check (sigma.mk a b).1      -- (a, b).fst : α\n  #check (sigma.mk a b).2      -- β (sigma.fst (sigma.mk a b))\n\n  #reduce (sigma.mk a b).1\n  #reduce (sigma.mk a b).2\nend page27\n\n/- `(sigma.mk a b).1` and `(sigma.mk a b).2` are short for \n   `sigma.fst (sigma.mk a b)` and `sigma.snd (sigma.mk a b)`, \n   and these reduce to a and b, respectively.\n   (cf. 3rd to last line of output below)\n-/\n\n/- Section 2.8 output\n                list : Type u_1 → Type u_1\n                cons : Π {T : Type u_1}, T → list T → list T\n                nil : Π {T : Type u_1}, list T\n                head : Π {α : Type u_1} [_inst_1 : inhabited α], list α → α\n                tail : Π {α : Type u_1}, list α → list α\n                append : Π {α : Type u_1} [c : has_append α], α → α → α\n                ⟨a, b⟩ : Σ (a : α), β a\n                ⟨a, b⟩.fst : α\n                ⟨a, b⟩.snd : (λ (a : α), β a) (⟨a, b⟩.fst)\n                a\n                b\n-/\n                \n#print \"------------------------------------------------\"\n#print \"Section 2.9 Implicit Arguments\"\n/- Lean allows us to specify that this argument should, by default, be left implicit. \n   This is done by putting the arguments in curly braces. -/\nnamespace implicits\n  universe u\n  def ident {α : Type u} (x : α) := x\n  variables α β : Type u\n  variables (a : α) (b : β)\n  #check ident\n  #check ident a\n  #check ident b\n\n  /- This makes the first argument to ident implicit. Notationally, this hides the specification\n     of the type, making it look as though ident simply takes an argument of any type. -/\n\n  /- Sometimes, however, we may find ourselves in a situation where we have declared an\n     argument to a function to be implicit, but now want to provide the argument explicitly. -/\n\n  #check @id\n  #check @id α\n  #check @id β\n  #check @id α a\n  #check @id β b\n\n  /- Notice that the first #check command now gives the type of the identifier, id, without\n     inserting placeholders. Moreover, the output indicates that the first argument is \n     implicit. -/\n\nend implicits\n\n\n/- Section 2.9 output\n                ident : ?M_1 → ?M_1\n                ident a : α\n                ident b : β\n                id : Π {α : Sort u_1}, α → α\n                id : α → α\n                id : β → β\n                id a : α\n                id b : β\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/02-dependent_types_part2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942203004185, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7531376626426195}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: María Inés de Frutos-Fernández\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 spectral_norm_unique\nimport normed_valued\n\n/-!\n# The `p`-adic complex numbers.\n\nIn this file we define the field `ℂ_[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 `ℂ_[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 `ℂ_[p]`.\n\n\n## Main Results\n\n* `padic_complex.norm_extends` : the norm on `ℂ_[p]` extends the norm on `Q_p_alg p`, and hence\n  the norm on `ℚ_[p]`.\n* `padic_complex.is_nonarchimedean` : The norm on `ℂ_[p]` is nonarchimedean.\n\n\n## Notation\n\nWe introduce the notation `ℂ_[p]` for the `p`-adic complex numbers, and `𝓞_ℂ_[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 : ℕ) [fact (nat.prime p)]\n\n/-- `Q_p_alg p` is the algebraic closure of `ℚ_[p]`. -/\n@[reducible] def Q_p_alg : Type* := algebraic_closure ℚ_[p]\n\n/-- `Q_p_alg p` is an algebraic extension of `ℚ_[p]`. -/\nlemma Q_p_alg.is_algebraic : algebra.is_algebraic ℚ_[p] (Q_p_alg p) := \nalgebraic_closure.is_algebraic _\n\ninstance : has_coe ℚ_[p] (Q_p_alg p) := ⟨algebra_map ℚ_[p] (Q_p_alg p)⟩\n\nprotected lemma coe_eq : (coe : ℚ_[p] → (Q_p_alg p)) = algebra_map ℚ_[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 `ℚ_[p]`. -/\ninstance normed_field : normed_field (Q_p_alg p) := \n@spectral_norm_to_normed_field ℚ_[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) → ℝ) :=\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 `ℚ_[p]`. -/\nlemma norm_def (x : Q_p_alg p) : ‖ x ‖ = spectral_norm ℚ_[p] (Q_p_alg p) x := rfl\n\n/-- The norm on `Q_p_alg p` extends the `p`-adic norm on `ℚ_[p]`. -/\nlemma Q_p.norm_extends (x : ℚ_[p]) : ‖ (x : Q_p_alg p) ‖ = ‖ x ‖ := \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) ℝ≥0 :=\nnormed_field.to_valued (Q_p_alg.is_nonarchimedean p)\n\n/-- The valuation of `x : Q_p_alg p` agrees with its `ℝ≥0`-valued norm. -/\nlemma v_def (x : Q_p_alg p) : valued.v x = ‖ x ‖₊ := rfl\n\n/-- The coercion of the valuation of `x : Q_p_alg p` to `ℝ` agrees with its norm. -/\nlemma v_def_coe (x : Q_p_alg p) : \n  ((valued.v x : ℝ≥0) : ℝ) = spectral_norm ℚ_[p] (Q_p_alg p) x := rfl\n\n/-- The valuation of `p : Q_p_alg p` is `1/p`. -/\nlemma valuation_p (p : ℕ) [fact p.prime] : valued.v (p : Q_p_alg p) = 1/(p : ℝ≥0) :=\nbegin\n  rw [← map_nat_cast (algebra_map  ℚ_[p] (Q_p_alg p)), ← 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/-- `ℂ_[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 `ℂ_[`p`]` := padic_complex p\n\nnamespace padic_complex\n\n/-- The `p`-adic complex numbers have a field structure. -/\ninstance : field ℂ_[p] := uniform_space.completion.field\n\n/-- The `p`-adic complex numbers are inhabited. -/\ninstance : inhabited ℂ_[p] := ⟨0⟩\n\n/-- `ℂ_[p]` is a valued field, where the valuation is the one extending that on `Q_p_alg p`. -/\ninstance valued_field : valued (ℂ_[p]) ℝ≥0 := valued.valued_completion \n\n/-- `ℂ_[p]` is a complete space. -/\ninstance complete_space : complete_space (ℂ_[p]) := uniform_space.completion.complete_space _\n\ninstance : has_coe_t (Q_p_alg p) ℂ_[p] := uniform_space.completion.has_coe_t _\n\n/-- The valuation on `ℂ_[p]` extends the valuation on `Q_p_alg p`. -/\nlemma valuation_extends (x : Q_p_alg p) : valued.v (x : ℂ_[p]) = valued.v x := \nvalued.extension_extends _\n\n/-- `ℂ_[p]` is an algebra over `Q_p_alg p`. -/\ninstance : algebra (Q_p_alg p) ℂ_[p] := uniform_space.completion.algebra' _\n\nlemma coe_eq : (coe : (Q_p_alg p) → ℂ_[p]) = algebra_map (Q_p_alg p) ℂ_[p] := rfl\n\nlemma coe_zero : ((0 : Q_p_alg p) : ℂ_[p]) = 0 := rfl\n\n/-- The valuation of `p : ℂ_[p]` is `1/p`. -/\nlemma valuation_p (p : ℕ) [fact p.prime] : valued.v (p : ℂ_[p]) = 1/(p : ℝ≥0) :=\nby rw [← map_nat_cast (algebra_map _ _), ← coe_eq, valuation_extends, Q_p_alg.valuation_p]\n\n/-- The valuation on `ℂ_[p]` has rank one. -/\ninstance : is_rank_one (padic_complex.valued_field p).v := \n{ hom := monoid_with_zero_hom.id ℝ≥0,\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 ⟨hp.ne_zero, hp.ne_one⟩,\n  end }\n\n/-- `ℂ_[p]` is a normed field, where the norm corresponds to the extension of the `p`-adic \n  valuation.-/\ninstance : normed_field ℂ_[p] := valued_field.to_normed_field\n\n/-- The norm on `ℂ_[p]` agrees with the valuation. -/\nlemma norm_def : (norm : ℂ_[p] → ℝ) = rank_one_valuation.norm_def := rfl\n\n/-- The norm on `ℂ_[p]` extends the norm on `Q_p_alg p`. -/\nlemma norm_extends (x : Q_p_alg p) : ‖ (x : ℂ_[p]) ‖ = ‖ x ‖ := \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 `ℝ≥0`-valued norm on `ℂ_[p]` extends that on `Q_p_alg p`. -/\nlemma nnnorm_extends (x : Q_p_alg p) : ‖ (x : ℂ_[p]) ‖₊ = ‖ x ‖₊ := \nby { ext, exact norm_extends p x }\n\n/-- The norm on `ℂ_[p]` is nonarchimedean. -/\nlemma is_nonarchimedean : is_nonarchimedean (norm : ℂ_[p] → ℝ) :=\nbegin\n  intros x y,\n  apply uniform_space.completion.induction_on₂ x y,\n  { exact is_closed_le (continuous.comp continuous_norm continuous_add) (continuous.max\n      (continuous.comp (@continuous_norm ℂ_[p] _) (continuous.fst continuous_id))\n      (continuous.comp (@continuous_norm ℂ_[p] _) (continuous.snd continuous_id))) },\n  { intros a b,\n    simp only [← 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 `𝓞_ℂ_[p]` as the subring elements of `ℂ_[p]` with valuation `≤ 1`. -/\ndef padic_complex_integers : subring ℂ_[p] := (padic_complex.valued_field p).v.integer\n\nnotation `𝓞_ℂ_[`p`]` := padic_complex_integers p\n\n/-- `𝓞_ℂ_[p]` is the ring of integers of `ℂ_[p]`. -/\nlemma padic_complex.integers : valuation.integers (padic_complex.valued_field p).v  𝓞_ℂ_[p] := \nvaluation.integer.integers _", "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/Cp_def.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121388082479, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7531220222955295}}
{"text": "/-\nCopyright (c) 2022 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel, Yury Kudryashov\n\n! This file was ported from Lean 3 source module order.monotone.extension\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.Order.ConditionallyCompleteLattice.Basic\n\n/-!\n# Extension of a monotone function from a set to the whole space\n\nIn this file we prove that if a function is monotone and is bounded on a set `s`, then it admits a\nmonotone extension to the whole space.\n-/\n\n\nopen Set\n\nvariable {α β : Type _} [LinearOrder α] [ConditionallyCompleteLinearOrder β] {f : α → β} {s : Set α}\n  {a b : α}\n\n/-- If a function is monotone and is bounded on a set `s`, then it admits a monotone extension to\nthe whole space. -/\ntheorem MonotoneOn.exists_monotone_extension (h : MonotoneOn f s) (hl : BddBelow (f '' s))\n    (hu : BddAbove (f '' s)) : ∃ g : α → β, Monotone g ∧ EqOn f g s := by\n  classical\n    /- The extension is defined by `f x = f a` for `x ≤ a`, and `f x` is the supremum of the values\n      of `f`  to the left of `x` for `x ≥ a`. -/\n    rcases hl with ⟨a, ha⟩\n    have hu' : ∀ x, BddAbove (f '' (Iic x ∩ s)) := fun x =>\n      hu.mono (image_subset _ (inter_subset_right _ _))\n    let g : α → β := fun x => if Disjoint (Iic x) s then a else supₛ (f '' (Iic x ∩ s))\n    have hgs : EqOn f g s := by\n      intro x hx\n      simp only []\n      have : IsGreatest (Iic x ∩ s) x := ⟨⟨right_mem_Iic, hx⟩, fun y hy => hy.1⟩\n      rw [if_neg this.nonempty.not_disjoint,\n        ((h.mono <| inter_subset_right _ _).map_isGreatest this).csupₛ_eq]\n    refine' ⟨g, fun x y hxy => _, hgs⟩\n    by_cases hx : Disjoint (Iic x) s <;> by_cases hy : Disjoint (Iic y) s <;>\n      simp only [if_pos, if_neg, not_false_iff, *, refl]\n    · rcases not_disjoint_iff_nonempty_inter.1 hy with ⟨z, hz⟩\n      exact le_csupₛ_of_le (hu' _) (mem_image_of_mem _ hz) (ha <| mem_image_of_mem _ hz.2)\n    · exact (hx <| hy.mono_left <| Iic_subset_Iic.2 hxy).elim\n    · rw [not_disjoint_iff_nonempty_inter] at hx hy\n      refine' csupₛ_le_csupₛ (hu' _) (hx.image _) (image_subset _ _)\n      exact inter_subset_inter_left _ (Iic_subset_Iic.2 hxy)\n#align monotone_on.exists_monotone_extension MonotoneOn.exists_monotone_extension\n\n/-- If a function is antitone and is bounded on a set `s`, then it admits an antitone extension to\nthe whole space. -/\ntheorem AntitoneOn.exists_antitone_extension (h : AntitoneOn f s) (hl : BddBelow (f '' s))\n    (hu : BddAbove (f '' s)) : ∃ g : α → β, Antitone g ∧ EqOn f g s :=\n  h.dual_right.exists_monotone_extension hu hl\n#align antitone_on.exists_antitone_extension AntitoneOn.exists_antitone_extension\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/Extension.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213880824791, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7531220186509445}}
{"text": "-- Church numerals\n\n-- Another way of doing nat.\n\n-- The church nat, chℕ (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ℕ := Π X : Type, (X → X) → X → X \nnamespace chnat\n\nopen nat \n-- map from normal nats\ndef of_nat : ℕ → chℕ \n| 0 := λ X f x, x\n| (succ n) := λ 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ℕ to ℕ\ndefinition to_nat : chℕ → ℕ := λ m, m ℕ nat.succ 0 -- there is a beauty here\n-- it is almost as if the structure ℕ were built to be fed into chℕ \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ℕ → chℕ := λ 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 : ℕ) : 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ℕ) : 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ℕ → chℕ → chℕ := λ m n X f x, n X f (m X f x) -- KB can do this\ninstance : has_add chℕ := ⟨add⟩ -- 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 : ℕ) : 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ℕ → chℕ → chℕ := λ m n X f, n X (m X f) -- KB can do this\ninstance : has_mul chℕ := ⟨mul⟩ -- 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 : ℕ) : 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ℕ → chℕ → chℕ := λ m n X, n (X → X) (m X) -- KB can do this one\n-- instance : has_pow chℕ := ⟨pow⟩ -- 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 : ℕ) : 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ℕ → chℕ → chℕ :=\nλ m n X, m ((((X → X) → (X → X)) → (X → X) → (X → X)) → ((X → X) → X → X))\n  (λ m_ih n f, n\n    (λ 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    (λ x, m_ih id f x))\n  (λ n f, n\n    (λ n_ih x, f (n_ih x))\n    (λ x, f x))\n  (n (X → 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ℕ 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ℕ) : m + n = n + m := sorry \n\n-- KB thinks this might be chℕ's free theorem\n-- KB can't prove it\ntheorem free_chnat : ∀ (A B : Type), ∀ f : A → B, \n∀ r : chℕ, ∀ a : A, r (A → B) (λ g,f) f a  = r (A → B) (λ g,g) f a \n := sorry\n\nstructure equiv' (α : Sort*) (β : Sort*) :=\n(to_fun    : α → β)\n(inv_fun   : β → α)\n(left_inv  : ∀ (x : α), inv_fun (to_fun x) = x)\n(right_inv : ∀ (y : β), to_fun (inv_fun y) = y)\n\n-- is ℕ equiv to chℕ ?\n\ntheorem ij : ∀ n : ℕ, 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 : ∀ c : chℕ, 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 ℕ_is_chℕ : equiv' ℕ chℕ := sorry \n\n-- idle question\ntheorem is_it_true (X : Type) (f : X → X) (x : X) : f x = x := sorry\n\nend chnat\n", "meta": {"author": "kckennylau", "repo": "Lean", "sha": "907d0a4d2bd8f23785abd6142ad53d308c54fdcb", "save_path": "github-repos/lean/kckennylau-Lean", "path": "github-repos/lean/kckennylau-Lean/Lean-907d0a4d2bd8f23785abd6142ad53d308c54fdcb/church_blog_questions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.753055835095149}}
{"text": "import tools.super .card\nopen classical nat function set tactic\n\nsection\n-- some facts about sets in the old library\n\nparameter {X : Type}\n\n-- theorem ext {a b : set X} (H : ∀x, x ∈ a ↔ x ∈ b) : a = b := funext (λ x, propext (H x))\n\n-- theorem not_mem_empty (x : X) : ¬ (x ∈ (∅ : set X)) := λ H, H\n\n-- theorem eq_empty_of_forall_not_mem {s : set X} (H : ∀ x, x ∉ s) : s = ∅ :=\n-- set.ext (λ x, iff.intro (λ xs, absurd xs (H x)) (λ xe, absurd xe (set.not_mem_empty _)))\n\n-- theorem exists_mem_of_ne_empty {s : set X} (H : s ≠ ∅) : ∃ x, x ∈ s :=\n-- by_contradiction (λ H', H (eq_empty_of_forall_not_mem (forall_not_of_not_exists H')))\n\nend\n\n\nsection\n-- the least number principle.\n\ndef complete_induction_on (n : ℕ) {p : ℕ → Prop} (h : ∀ n, (∀ m < n, p m) → p n) : p n :=\nsuffices ∀ n, ∀ m < n, p m, from this (succ n) _ (lt_succ_self n),\ntake n,\nnat.rec_on n\n  (take m, suppose m < 0, absurd this (not_lt_zero m))\n  (take n,\n    assume ih : ∀ m < n, p m,\n    take m,\n    suppose m < succ n,\n    or.elim (lt_or_eq_of_le (le_of_lt_succ this))\n      (ih m)\n      (suppose m = n,\n        begin rw this, apply h, exact ih end))\n\nlemma wf_aux {A : set ℕ} (n : ℕ) : n ∈ A → ∃ a, a ∈ A ∧ ∀ b,  b ∈  A → a ≤ b := \n@complete_induction_on n (λ x, x ∈ A → ∃ a, a ∈  A ∧ ∀ b, b ∈ A → a ≤ b)\n(λ k ih h, by_cases\n(suppose ∃ m, m ∈ A ∧ m <k, let ⟨m, Hmem, Hlt⟩ := this in ih m Hlt Hmem)\n(λ Hn, have ∀ m, m ∈  A →  ¬ m < k, by super, ⟨k,h,(λ m h, le_of_not_gt $ this m h)⟩))\n\ntheorem wf_of_le (S : set ℕ) (H : S ≠ ∅) : ∃ a, a ∈ S ∧ ∀ b, b ∈ S → a ≤ b :=\nlet ⟨n,Hn⟩ := exists_mem_of_ne_empty H in wf_aux n Hn\n\nnoncomputable definition least (S : set ℕ) (H : S ≠ ∅) : ℕ := some (wf_of_le S H)\n\ntheorem least_is_mem (S : set ℕ) (H : S ≠ ∅) : least S H ∈ S := \nlet ⟨bound, Ha⟩ := some_spec (wf_of_le S H) in bound\n\ntheorem minimality {S : set ℕ} (neq : S ≠ ∅): ∀ x, x ∈ S → least S neq ≤ x := \nλ x Hx, let ⟨bound, Ha⟩ := some_spec (wf_of_le S neq) in Ha x Hx\n\nend\n\nlemma nonzero_card_of_finite {A : Type} {S : set A} (H : card S ≠ 0) : finite S :=\nby_contradiction\n(suppose ¬ finite S,\nhave card S = 0, from card_of_not_finite this,\nH this)\n\nlemma mem_not_in_diff {A : Type} {S : set A} {a : A} : a ∉ S \\ insert a (∅ : set A) := \nassume h,\nhave a ∉ insert a (∅ : set A), from not_mem_of_mem_diff h,\nthis (mem_singleton a)\n\nlemma insert_of_diff_singleton {A : Type} {S : set A} {a : A} (H : a ∈ S) : insert a (S \\ insert a (∅ : set A)) = S :=\nbegin\napply eq_of_subset_of_subset,\nintros x h, apply or.elim h, intro h1, simp [H, h1], -- simp,\nintro hr, apply and.left hr,\nintros x h', cases (decidable.em (x ∈ insert a (∅ : set A))),\napply or.inl, apply eq_of_mem_singleton, assumption,\napply or.inr, apply and.intro, repeat {assumption}\nend\n\n-- lemma union_of_diff_singleton {A : Type} {S : set A} {a : A} (H : a ∈ S) \n--   : S \\ (insert a (∅ : set A)) ∪ (insert a (∅ : set A)) = S := \n-- begin\n-- apply eq_of_subset_of_subset,\n--   intros x h, apply or.elim h, intro hl, apply and.left hl,\n--   intro hr, have h : x = a, from (mem_singleton_iff x a)^.mp hr,\n--   rewrite h, simp,\n--   intros x h', cases (decidable.em (x ∈ insert a (∅ : set A))),\n--   apply or.inr, simp, apply or.inl, apply and.intro, repeat {simp}\n-- end\n\n\n-- lemma finite_singleton {A : Type} {a : A} : finite '{a} := \n-- have carda : card '{a} = 1, from card_singleton a,\n-- have (1:ℕ) ≠ 0, from dec_trivial,\n-- have card '{a} ≠ 0, by+ rewrite -carda at this;exact this,\n-- nonzero_card_of_finite this\n\n-- lemma sub_of_eq {A : Type} {S T: set A} (H : S = T) : S ⊆ T :=\n-- have T ⊆ T, from subset.refl T,\n-- by+ rewrite -H at this{1};exact this\n\n-- theorem ne_empty_of_mem' {X : Type} {s : set X} {x : X} (H : x ∈ s) : s ≠ ∅ :=\n-- begin intro Hs, rewrite Hs at H, apply not_mem_empty _ H end --this is on github\n", "meta": {"author": "minchaowu", "repo": "Kruskal.lean3", "sha": "a14516f47b21e636e9df914fc6ebe64cbe5cd38d", "save_path": "github-repos/lean/minchaowu-Kruskal.lean3", "path": "github-repos/lean/minchaowu-Kruskal.lean3/Kruskal.lean3-a14516f47b21e636e9df914fc6ebe64cbe5cd38d/lemmas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8740772482857833, "lm_q1q2_score": 0.7530509411776366}}
{"text": "/-\nCopyright (c) 2022 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.Linear\n\nnamespace Nat\n\ntheorem nextPowerOfTwo_dec {n power : Nat} (h₁ : power > 0) (h₂ : power < n) : n - power * 2 < n - power := by\n  have : power * 2 = power + power := by simp_arith\n  rw [this, Nat.sub_add_eq]\n  exact Nat.sub_lt (Nat.zero_lt_sub_of_lt h₂) h₁\n\ndef nextPowerOfTwo (n : Nat) : Nat :=\n  go 1 (by decide)\nwhere\n  go (power : Nat) (h : power > 0) : Nat :=\n    if power < n then\n      go (power * 2) (Nat.mul_pos h (by decide))\n    else\n      power\ntermination_by go p h => n - p\ndecreasing_by simp_wf; apply nextPowerOfTwo_dec <;> assumption\n\ndef isPowerOfTwo (n : Nat) := ∃ k, n = 2 ^ k\n\ntheorem one_isPowerOfTwo : isPowerOfTwo 1 :=\n  ⟨0, by decide⟩\n\ntheorem mul2_isPowerOfTwo_of_isPowerOfTwo (h : isPowerOfTwo n) : isPowerOfTwo (n * 2) :=\n  have ⟨k, h⟩ := h\n  ⟨k+1, by simp [h, Nat.pow_succ]⟩\n\ntheorem pos_of_isPowerOfTwo (h : isPowerOfTwo n) : n > 0 := by\n  have ⟨k, h⟩ := h\n  rw [h]\n  apply Nat.pos_pow_of_pos\n  decide\n\ntheorem isPowerOfTwo_nextPowerOfTwo (n : Nat) : n.nextPowerOfTwo.isPowerOfTwo := by\n  apply isPowerOfTwo_go\n  apply one_isPowerOfTwo\nwhere\n  isPowerOfTwo_go (power : Nat) (h₁ : power > 0) (h₂ : power.isPowerOfTwo) : (nextPowerOfTwo.go n power h₁).isPowerOfTwo := by\n    unfold nextPowerOfTwo.go\n    split\n    . exact isPowerOfTwo_go (power*2) (Nat.mul_pos h₁ (by decide)) (Nat.mul2_isPowerOfTwo_of_isPowerOfTwo h₂)\n    . assumption\ntermination_by isPowerOfTwo_go p _ _ => n - p\ndecreasing_by simp_wf; apply nextPowerOfTwo_dec <;> assumption\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/Power2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.8615382094310355, "lm_q1q2_score": 0.753050927610242}}
{"text": "/-\nChange the below line to \nimport week_2.kb_solutions.Part_A_groups_solutions\n(once the solutions are posted) if you want to get rid of the warning\n-/\n\nimport wk4.groups\n\n/-!\n## Subgroups\nWe define the structure `subgroup G`, whose terms are subgroups of `G`.\nA subgroup of `G` is implemented as a subset of `G` closed under\n`1`, `*` and `⁻¹`.\n-/\n\nnamespace xena\n\n/-- A subgroup of a group G is a subset containing 1\nand closed under multiplication and inverse. -/\nstructure subgroup (G : Type) [group G] :=\n(carrier : set G)\n(one_mem' : (1 : G) ∈ carrier)\n(mul_mem' {x y} : x ∈ carrier → y ∈ carrier → x * y ∈ carrier)\n(inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier)\n\n/-\nAt this point, here's what we have.\nA term `H` of type `subgroup G`, written `H : subgroup G`, is a\n*quadruple*. To give a term `H : subgroup G` is to give the following four things:\n1) `H.carrier` (a subset of `G`),\n2) `H.one_mem'` (a proof that `1 ∈ H.carrier`),\n3) `H.mul_mem'` (a proof that `H` is closed under multiplication)\n4) `H.inv_mem'` (a proof that `H` is closed under inverses).\nNote in particular that Lean, being super-pedantic, *distinguishes* between\nthe subgroup `H` and the subset `H.carrier`. One is a subgroup, one is\na subset. When we get going we will start by setting up some infrastructure\nso that this difference will be hard to notice.\nNote also that if `x` is in the subgroup `H` of `H` then the _type_ of `x` is still `G`,\nand `x ∈ carrier` is a Proposition. Note also that `x : carrier` doesn't\nmake sense (`carrier` is a term, not a type, rather counterintuitively).\n-/\n\nnamespace subgroup\n\nopen xena.group\n\n-- let G be a group and let H and K be subgroups\nvariables {G : Type} [group G] (H J K : subgroup G)\n\n/-\nThis `h ∈ H.carrier` notation kind of stinks. I don't want to write `H.carrier`\neverywhere, because I want to be able to identify the subgroup `H` with\nits underlying subset `H.carrier`. Note that these things are not _equal_,\nfirstly because `H` contains the proof that `H.carrier` is a subgroup, and\nsecondly because these terms have different types! `H` has type `subgroup G`\nand `H.carrier` has type `set G`. Let's start by sorting this out.\n-/\n\n-- If `x : G` and `H : subgroup G` then let's define the notation\n-- `x ∈ H` to mean `x ∈ H.carrier`\ninstance : has_mem G (subgroup G) := ⟨λ m H, m ∈ H.carrier⟩\n\n-- Let's also define a \"coercion\", a.k.a. an \"invisible map\"\n-- from subgroups of `G` to subsets of `G`, sending `H` to `H.carrier`. \n-- The map is not completely invisible -- it's a little ↑. So\n-- if you see `↑H` in the future, it means the subset `H.carrier` by definition.\ninstance : has_coe (subgroup G) (set G) := ⟨λ H, H.carrier⟩\n\n-- `λ` is just computer science notation for ↦ (mapsto); so\n-- `λ H, H.carrier` is the function `H ↦ H.carrier`.\n\n-- Let's check we have this working, and also tell the simplifier that we\n-- would rather talk about `g ∈ H` than any other way of saying it.\n\n/-- `g` is in the underlying subset of `H` iff `g ∈ H`. -/\n@[simp] lemma mem_carrier {g : G} : g ∈ H.carrier ↔ g ∈ H :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-- `g` is in `H` considered as a subset of `G`, iff `g` is in `H` considered\nas subgroup of `G`. -/\n@[simp] lemma mem_coe {g : G} : g ∈ (↑H : set G) ↔ g ∈ H :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- Now let's define theorems without the `'`s in, which use this\n-- more natural notation\n\n/-- A subgroup contains the group's 1. -/\ntheorem one_mem : (1 : G) ∈ H := H.one_mem'\n\n/-- A subgroup is closed under multiplication. -/\ntheorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := \nbegin\n  apply H.mul_mem'\nend\n\n/-\nbegin\n  intros x y,\n  apply mul_mem';\n  rw mem_carrier,\n  { exact x},\n  { exact y},\n  -- what do you think?\nend\n-/\n\n/-- A subgroup is closed under inverse -/\ntheorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H :=\nbegin\n  apply H.inv_mem',\n  -- what do you think?\nend\n\n/-\nSo here are the three theorems which you need to remember about subgroups.\nSay `H : subgroup G`. Then:\n`H.one_mem : (1 : G) ∈ H`\n`H.mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H`\n`H.inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H`\nThese now look like the way a mathematician would write things.\nNow let's start to prove basic theorems about subgroups (or, as a the computer\nscientists would say, make a basic _interface_ or _API_ for subgroups),\nusing this sensible notation.\nHere's an example; let's prove `x ∈ H ↔ x⁻¹ ∈ H`. Let's put the more\ncomplicated expression on the left hand side of the `↔` though, because then\nwe can make it a `simp` lemma.\n-/\n\n-- Remember that `xena.group.inv_inv x` is the statement that `x⁻¹⁻¹ = x`\n\n@[simp] theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := \nbegin\n  split,\n  { intros H,\n  -- fiddled around with using inv_mem, doesn't work, so I need another inv\n    rw ← inv_inv x, -- this adds another inv\n    apply inv_mem, -- this gets rid of one of the inv\n    exact H, \n  },\n  { apply inv_mem,}\nend\n\n-- We could prove a bunch more theorems here. Let's just do one more.\n-- Let's show that if x and xy are in H then so is y.\n\ntheorem mem_of_mem_mul_mem {x y : G} (hx : x ∈ H) (hxy : x * y ∈ H) : y ∈ H :=\nbegin\n  rw ← inv_mem_iff at hx,\n  convert H.mul_mem hx hxy,\n  simp only [eq_self_iff_true, xena.group.inv_mul_cancel_left],\nend\n\n/-\nSubgroups are extensional objects (like most things in mathematics):\ntwo subgroups are equal if they have the same underlying subset,\nand also if they have the same underlying elements.\nLet's prove variants of this triviality now. The first one is rather\nun-mathematical: it takes a subgroup apart into its pieces. I'll see if\nyou can do the other two!\n-/\n\n/-- Two subgroups are equal if the underlying subsets are equal. -/\ntheorem ext' {H K : subgroup G} (h : H.carrier = K.carrier) : H = K :=\nbegin\n  -- first take H and K apart\n  cases H, -- H now broken up into its underlying 3-tuple.\n  cases K,\n  -- and now it must be obvious, so let's see if the simplifier can do it.\n  simp * at *, -- it can!\nend\n\n-- here's a variant. You can prove it using `ext'`. \n\n/-- Two subgroups are equal if and only if the underlying subsets are equal. -/\ntheorem ext'_iff {H K : subgroup G} :\n  H.carrier = K.carrier ↔ H = K :=\nbegin\n  split,\n  { exact ext',},\n  { intro h,\n    rw h,\n  }\nend\n\n-- to do this next one, first apply the `ext'` theorem we just proved,\n-- and then use the `ext` tactic (which works on sets)\n\n/-- Two subgroups are equal if they have the same elements. -/\n@[ext] theorem ext {H K : subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K :=\nbegin\n  apply ext',\n  ext,\n  apply h,\nend\n\n/-\nWe tagged that theorem with `ext`, so now the `ext` tactic works on subgroups\ntoo: if you ever have a goal of proving that two subgroups are equal, you can\nuse the `ext` tactic to reduce to showing that they have the same elements.\n-/\n\n/-\n## The lattice structure on subgroups\nSubgroups of a group form what is known as a *lattice*. \nThis is a partially ordered set with a sensible notion of\nmax and min. We partially order subgroups by saying `H ≤ K` if\n`H.carrier ⊆ K.carrier`. Subgroups even have a good notion of an infinite\nSup and Inf (the Inf of a bunch of subgroups is just their intersection;\ntheir Sup is the subgroup generated by their union).\nThis combinatorial structure (a partially ordered set with good\nfinite and infinite notions of Sup and Inf) is called a \"complete lattice\",\nand Lean has this structure inbuilt into it. We will construct\na complete lattice structure on `subgroup G`.\nWe start by defining a relation ≤ on the type of subgroups of a group.\nWe say H ≤ K iff H.carrier ⊆ K.carrier .\n-/\n\n/-- If `H` and `K` are subgroups of `G`, we write `H ≤ K` to\n  mean `H.carrier ⊆ K.carrier` -/\ninstance : has_le (subgroup G) := ⟨λ H K, H.carrier ⊆ K.carrier⟩\n\n-- useful to restate the definition so we can `rw` it\nlemma le_def : H ≤ K ↔ H.carrier ⊆ K.carrier :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- another useful variant\nlemma le_iff : H ≤ K ↔ ∀ g, g ∈ H → g ∈ K :=\nbegin\n  -- true by definition\n  refl,\nend\n\n\n\n-- Now let's check the axioms for a partial order.\n-- These are not hard, they just reduce immediately to the\n-- fact that ⊆ is a partial order\n@[refl] lemma le_refl : H ≤ H :=\nbegin\n  rw le_def,\n  -- Lean knows ⊆ is reflexive so the sneaky `refl` which Lean tries after `rw` \n  -- has closed the goal!\nend\n\nlemma le_antisymm : H ≤ K → K ≤ H → H = K :=\nbegin\n  rw [le_def, le_def, ← ext'_iff],\n  intros HK KH,\n  -- now this is antisymmetry of ⊆, which Lean knows\n  exact set.subset.antisymm HK KH,\nend\n\n@[trans] lemma le_trans : H ≤ J → J ≤ K → H ≤ K :=\nbegin\n  rw [le_def, le_def, le_def],\n  -- now this is transitivity of ⊆, which Lean knows\n  exact set.subset.trans,\nend\n\n-- We've made `subgroup G` into a partial order!\ninstance : partial_order (subgroup G) :=\n{ le := (≤),\n  le_refl := le_refl,\n  le_antisymm := le_antisymm,\n  le_trans := le_trans }\n\n/-\n### intersections\nLet's prove that the intersection of two subgroups is a subgroup. In Lean\nthis is a definition: given two subgroups, we define a new subgroup whose\nunderlying subset is the intersection of the subsets, and then prove\nthe axioms.\n-/\n\n/-- The intersection of two subgroups is also a subgroup -/\ndef inf (H K : subgroup G) : subgroup G :=\n{ carrier := H.carrier ∩ K.carrier, -- the carrier is the intersection\n  one_mem' := \n  begin\n    -- recall that x ∈ Y ∩ Z is _by definition_ x ∈ Y ∧ x ∈ Z, so you can `split` this. \n    split,\n    { exact H.one_mem,},\n    { exact K.one_mem,},\n  end,\n  mul_mem' := \n  begin\n    intros x y hx hy,\n    cases hx with hx1 hx2,\n    cases hy with hy1 hy2,\n    exact ⟨H.mul_mem hx1 hy1, K.mul_mem hx2 hy2⟩\n  end,\n  inv_mem' :=\n  begin\n    rintros x ⟨h1, h2⟩,\n    exact ⟨ H.inv_mem h1, K.inv_mem h2 ⟩,\n  end }\n\n-- Notation for `inf` in computer science circles is ⊓.\n\ninstance : has_inf (subgroup G) := ⟨inf⟩\n\n/-- The underlying set of the inf of two subgroups is just their intersection -/\nlemma inf_def (H K : subgroup G) : (H ⊓ K : set G) = (H : set G) ∩ K :=\nbegin\n  -- true by definition\n  refl\nend\n\n/-\n## Subgroup generated by a subset.\nTo do the sup of two subgroups is harder, because we don't just take\nthe union, we need to then look at the subgroup generated by this union\n(e.g. the union of the x and y axes in ℝ² is not a subgroup). So we need\nto have a machine to spit out the subgroup of `G` generated by a subset `S : set G`.\nThere are two completely different ways to do this. The first is a \"top-down\"\napproach. We could define the subgroup generated by `S` to be the intersection of\nall the subgroups of `G` that contain `S`. The second is a \"bottom-up\" approach.\nWe could define the subgroup generated by `S` \"by induction\" (or more precisely\nby recursion), saying that `S` is in the subgroup, 1 is in the subgroup,\nthe product of two things in the subgroup is in the subgroup, the\ninverse of something in the subgroup is in the subgroup, and that's it.\nBoth methods come out rather nicely in Lean. Let's do the first one.\nWe are going to be using a bunch of theorems about \"bounded intersections\",\na.k.a. `set.bInter`. We will soon get tired of writing `set.blah` so let's\n`open set` so that we can skip it. \n-/\n\nopen set\n\n/-\nHere is the API for `set.bInter` (or `bInter`, as we can now call it):\nNotation: `⋂` (type with `\\I`)\nIf `X : set (subgroup G)`, i.e. if `X` is a set of subgroups of `G`, then\n`⋂ K ∈ X, (K : set G)` means \"take the intersection of the underlying subsets\".\n-- mem_bInter_iff says you're in the intersection iff you're in\n-- all the things you're intersecting. Very useful for rewriting.\n`mem_bInter_iff : (g ∈ ⋂ (K ∈ S), f K) ↔ (∀ K, K ∈ s → g ∈ f K)`\n-- mem_bInter is just the one way implication. Very useful for `apply`ing.\n`mem_bInter : (∀ K, K ∈ s → g ∈ f K) → (g ∈ ⋂ (K ∈ S), f K)`\n-/\n/- \nWe will consider the closure of a set as the intersect of all subgroups\ncontaining the set\n-/\n\n/-- The Inf of a set of subgroups of G is their intersection. -/\ndef Inf (X : set (subgroup G)) : subgroup G :=\n{ carrier := ⋂ K ∈ X, (K : set G), -- carrier is the intersection of the underlying sets\n  one_mem' := \n  begin\n    rw mem_bInter_iff,\n    intros x hxX,\n    apply x.one_mem,\n    end,\n  mul_mem' := begin\n    intros x y hx hy,\n    rw mem_bInter_iff at hx hy ⊢,\n    intros a haX,\n    -- specialize hx a haX,\n    -- specialize hy a haX,\n    apply a.mul_mem (hx a haX) (hy a haX),  -- a.mul_mem hx hy\n  end,\n  inv_mem' := begin\n    intros x hx,\n    rw mem_bInter_iff at hx ⊢,\n    intros a haX,\n    apply a.inv_mem (hx a haX),\n  end,\n}\n\n\n/-- The *closure* of a subset `S` of `G` is the `Inf` of the subgroups of `G`\n  which contain `S`. -/\ndef closure (S : set G) : subgroup G := Inf {H : subgroup G | S ⊆ H}\n\n-- we can restate mem_bInter_iff using our new \"closure\" language:\nlemma mem_closure_iff {S : set G} {x : G} : \n  x ∈ closure S ↔ ∀ H : subgroup G, S ⊆ H → x ∈ H := mem_bInter_iff\n\n/- \nThere is an underlying abstraction here, which you may not know about.\nA \"closure operator\" in mathematics \nhttps://en.wikipedia.org/wiki/Closure_operator\nis something mapping subsets of a set X to subsets of X, and satisfying three\naxioms:\n1) `subset_closure : S ⊆ closure S`\n2) `closure_mono : (S ⊆ T) → (closure S ⊆ closure T)`\n3) `closure_closure : closure (closure S) = closure S`\nIt works for closure in topological spaces, and it works here too.\nIt also works for algebraic closures of fields, and there are several\nother places in mathematics where it shows up. This idea, of \"abstracting\"\nand axiomatising a phenomenon which shows up in more than one place,\nis really key in Lean.\nLet's prove these three lemmas in the case where `X = G` and `closure S`\nis the subgroup generated by `S`.\nHere are some things you might find helpful.\nRemember \n`mem_coe : g ∈ ↑H ↔ g ∈ H`\n`mem_carrier : g ∈ H.carrier ↔ g ∈ H`\nThere's \n`mem_closure_iff : x ∈ closure S ↔ ∀ (H : subgroup G), S ⊆ ↑H → x ∈ H`\n(`closure S` is a subgroup so you might need to use `mem_coe` or `mem_carrier` first)\nFor subsets there's\n`subset.trans : X ⊆ Y → Y ⊆ Z → X ⊆ Z`\nYou might find `le_antisymm : H ≤ K → K ≤ H → H = K` from above useful\n-/\n\n/-\nReminder: X ⊆ Y means `∀ g, g ∈ X → g ∈ Y` and it's definitional,\nso you can just start this with `intro g`.\n-/\nlemma subset_closure (S : set G) : S ⊆ ↑(closure S) :=\nbegin\n  intros g hgS,\n  rw [mem_coe, mem_closure_iff],\n  intros H hSH,\n  exact hSH hgS, -- as X ⊆ Y means `∀ g, g ∈ X → g ∈ Y`, then giving hSH hgS \n                  -- will just return a term of type that is the same as the goal\nend\n\n-- It's useful to know `subset.trans : X ⊆ Y → Y ⊆ Z → X ⊆ Z`\nlemma closure_mono {S T : set G} (hST : S ⊆ T) : closure S ≤ closure T :=\nbegin\n  intros x hxS,\n  rw [mem_carrier, mem_closure_iff] at ⊢ hxS,\n  -- apply hST hxS, -- has type x ∈ closure S but is expected to have type ?m_1 ∈ S\n  -- so this is useful, but after we have something like a ∈ S.\n  --rw mem_closure_iff at hxS ⊢,\n  intros H hH,\n  -- have hH2 := subset.trans hST hH,\n  -- rw mem_closure_iff at hxS,\n  -- specialize hxS H (subset.trans hST hH),\n  exact (hxS H (subset.trans hST hH)), \nend\n\n-- not one of the axioms, but sometimes handy\nlemma closure_le (S : set G) (H : subgroup G) : closure S ≤ H ↔ S ⊆ ↑H :=\nbegin\n  split,\n  { intros hSH,\n    apply subset.trans (subset_closure S) hSH,\n  },\n  { intros hSH g hg,\n    rw mem_carrier,\n    rw [mem_carrier, mem_closure_iff] at hg,\n    apply hg H hSH,\n  },\nend\n\n-- You can start this one by applying `le_antisymm`,\nlemma closure_closure (S : set G) : closure S = closure (closure S) :=\nbegin\n  apply le_antisymm,\n  { apply subset_closure,},\n  { rw closure_le,\n    intros x hx,\n    exact hx,\n  },\nend\n\n-- This shows that every subgroup is the closure of something, namely its\n-- underlying subset. \nlemma closure_self {H : subgroup G} : closure ↑H = H :=\nbegin\n  apply le_antisymm,\n  { rw le_iff,\n    intros g hg,\n    rw mem_closure_iff at hg,\n    apply hg H, refl,\n  },\n  { apply subset_closure,},\nend\n\n/-\nRecall the second proposed construction of the subgroup closure of a subset `S`;\nit is the smallest subgroup `H` of `G` such that `S ⊆ H` and which contains\n`1` and is closed under `*` and `⁻¹`. This inductive constuction (which we\ndid not make) comes with a so-called \"recursor\": if we have a true/false\nstatement `p g` attached to each element `g` of G with the following properties:\n1) `p s` is true for all `s ∈ S`,\n2) `p 1` is true,\n3) If `p x` and `p y` then `p (x * y)`,\n4) If `p x` then `p x⁻¹`\nThen `p` is true on all of `closure S`.\nIf we had made an inductive definition of `closure S` then this would have been true\nby definition! We used another definition, so we will have to prove it\nourselves.\n-/\n\n/-- An induction principle for closures. -/\nlemma closure_induction {p : G → Prop} {S : set G}\n  (HS : ∀ x ∈ S, p x)\n  (H1 : p 1)\n  (Hmul : ∀ x y, p x → p y → p (x * y))\n  (Hinv : ∀ x, p x → p x⁻¹) : \n  -- conclusion after colon\n  ∀ x, x ∈ closure S → p x :=\nbegin\n  -- the subset of G where `p` is true is a subgroup. Let's call it H\n  let H : subgroup G :=\n  { carrier := p, \n    one_mem' := H1, \n    mul_mem' := Hmul,\n    inv_mem' := Hinv },\n  -- The goal is just that closure S ≤ H, by definition.\n  change closure S ≤ H,  \n  -- Our hypothesis HS is just that S ⊆ ↑H, by definition\n  change S ⊆ ↑H at HS, \n  -- I think you can take it from here!\n  rw closure_le,\n  exact HS, -- assumption\nend\n\n/-\nFinally we prove that the `closure` and `coe` maps form a `galois_insertion`.\nThis is another abstraction, it generalises `galois_connection`, which is\nsomething that shows up all over the place (algebraic geometry, Galois theory etc).\nSee\nhttps://en.wikipedia.org/wiki/Galois_connection\nA partial order can be considered as a category, with Hom(A,B) having\none element if A ≤ B and no elements otherwise. A Galois connection between\ntwo partial orders is just a pair of adjoint functors between the categories.\nAdjointness in our case is `S ⊆ ↑H ↔ closure S ≤ H`. \nThe reason it's an insertion and not just a connection is that if you start\nwith a subgroup, take the underlying subset, and then look at the subgroup\ngenerated by that set, you get back to where you started. So it's like one\nof the adjoint functors being a forgetful functor.\n-/\n\n/-- THIS IS A DOCSTRING -/\ndef gi : galois_insertion (closure : set G → subgroup G) (coe : subgroup G → set G) :=\n{ choice := λ S _, closure S,\n  gc := closure_le,\n  le_l_u := λ H, subset_closure (H : set G),\n  choice_eq := λ _ _, rfl }\n\n\n/-\nOne use of this abstraction is that now we can pull back the complete\nlattice structure on `set G` to get a complete lattice structure on `subgroup G`. \n-/\n\ninstance : complete_lattice (subgroup G) :=\n{.. galois_insertion.lift_complete_lattice gi}\n\n/-\nWe just proved loads of lemmas about Infs and Sups of subgroups automatically,\nand have access to a ton more because the `complete_lattice` structure in\nLean has a big API. See for example\nhttps://leanprover-community.github.io/mathlib_docs/order/complete_lattice.html#complete_lattice\nAll those theorems are now true for subgroups. None are particularly hard to prove,\nbut the point is that we don't now have to prove any of them ourselves.\n-/\nend subgroup\n\nend xena\n\n\n/-\nFurther work: `bot` and `top` (would have to explain the\nAPI for `singleton` and `univ`)\n-/", "meta": {"author": "jamesa9283", "repo": "LiaLeanTutor", "sha": "c7ac1400f26eb2992f5f1ee0aaafb54b74665072", "save_path": "github-repos/lean/jamesa9283-LiaLeanTutor", "path": "github-repos/lean/jamesa9283-LiaLeanTutor/LiaLeanTutor-c7ac1400f26eb2992f5f1ee0aaafb54b74665072/src/wk4/subgroups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7530071421067279}}
{"text": "import MyNat.Definition\nimport MyNat.Addition\nnamespace MyNat\nopen MyNat\n\n/-!\n\n# Advanced Addition World\n\n## Level 3: `succ_eq_succ_of_eq`.\n\nWe are going to prove something completely obvious: if `a=b` then\n`succ a = succ b`. This is *not* `succ_inj`!\nThis is trivial -- we can just rewrite our proof of `a=b`.\nBut how do we get to that proof? Use the `intro` tactic.\n\n## Theorem\nFor all naturals `a` and `b`, `a = b ⟹ succ a = succ b`.\n-/\ntheorem succ_eq_succ_of_eq {a b : MyNat} : a = b → succ a = succ b := by\n  intro h\n  rw [h]\n\n/-!\nNext up [Level 4](./Level4.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/Level3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9433475778774728, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7529675612101336}}
{"text": "import MyNat.Definition\nimport MyNat.Addition -- add_zero\nimport MyNat.Inequality -- le_iff_exists_add\nimport Mathlib.Tactic.Use -- use tactic\nimport AdditionWorld.Level2 -- add_assoc\nimport AdditionWorld.Level3 -- succ_add\nimport InequalityWorld.Level2 -- le_refl\nnamespace MyNat\nopen MyNat\n/-!\n\n# Inequality world.\n\n## Level 15: introducing `<`\n\nTo get the remaining collectibles in this world, we need to\ngive a definition of `<`. By default, the definition of `a < b`\nin Lean, once `≤` is defined, is this:\n\n`a < b := a ≤ b ∧ ¬ (b ≤ a)`\n\nBut a much more usable definition would be this:\n\n`a < b := succ a ≤ b`\n\nLet's prove that these two definitions are the same\n\n## Lemma : lt_aux₁\nFor all naturals `a` and `b`, `a ≤ b ∧ ¬(b ≤ a) ⟹ succ a ≤ b.`\n-/\nlemma lt_aux₁ (a b : MyNat) : a ≤ b ∧ ¬ (b ≤ a) → succ a ≤ b := by\n  intro h\n  cases h with\n  | _ h1 h2 =>\n    cases h1 with\n    | _ c hc =>\n      cases c with\n      | zero =>\n        exfalso\n        rw [zero_is_0, add_zero] at hc\n        apply h2\n        rw [hc]\n      | succ d =>\n        use d\n        rw [hc]\n        rw [add_succ]\n        rw [succ_add]\n\n/-!\nNext up [Level 16](./Level16.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/Level15.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920261, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7529675586675522}}
{"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 `ℝⁿ` and a function `r : ℝⁿ → ℝ` positive on `I` there exists a tagged partition `π` of `I` such\nthat\n\n* `π` is a Henstock partition;\n* `π` is subordinate to `r`;\n* each box in `π` 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 topology\nnoncomputable theory\n\nvariables {ι : Type*} [fintype ι] {I J : box ι}\n\nnamespace prepartition\n\n/-- Split a box in `ℝⁿ` into `2 ^ n` boxes by hyperplanes passing through its center. -/\ndef split_center (I : box ι) : 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 _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ Hne,\n      exact I.disjoint_split_center_box (mt (congr_arg _) Hne)\n    end }\n\n@[simp] lemma mem_split_center : J ∈ split_center I ↔ ∃ s, I.split_center_box s = J :=\nby simp [split_center]\n\nlemma is_partition_split_center (I : box ι) : is_partition (split_center I) :=\nλ x hx, by simp [hx]\n\nlemma upper_sub_lower_of_mem_split_center (h : J ∈ split_center I) (i : ι) :\n  J.upper i - J.lower i = (I.upper i - I.lower i) / 2 :=\nlet ⟨s, hs⟩ := mem_split_center.1 h in hs ▸ 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 ι`, let `I` be a box. Suppose that the following two properties\nhold true.\n\n* Consider a smaller box `J ≤ 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 ≤ I` such that `z ∈ J.Icc ⊆ 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 ι → Prop} (I : box ι)\n  (H_ind : ∀ J ≤ I, (∀ J' ∈ split_center J, p J') → p J)\n  (H_nhds : ∀ z ∈ I.Icc, ∃ (U ∈ 𝓝[I.Icc] z), ∀ (J ≤ I) (m : ℕ), z ∈ J.Icc → J.Icc ⊆ U →\n    (∀ i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) → p J) :\n  p I :=\nbegin\n  refine subbox_induction_on' I (λ J hle hs, H_ind J hle $ λ J' h', _) H_nhds,\n  rcases mem_split_center.1 h' with ⟨s, rfl⟩,\n  exact hs s\nend\n\n/-- Given a box `I` in `ℝⁿ` and a function `r : ℝⁿ → (0, ∞)`, there exists a tagged partition `π` of\n`I` such that\n\n* `π` is a Henstock partition;\n* `π` is subordinate to `r`;\n* each box in `π` 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 ι)\n  (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  ∃ π : tagged_prepartition I, π.is_partition ∧ π.is_Henstock ∧ π.is_subordinate r ∧\n    (∀ J ∈ π, ∃ m : ℕ, ∀ i, (J : _).upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) ∧\n    π.distortion = I.distortion :=\nbegin\n  refine subbox_induction_on I (λ J hle hJ, _) (λ z hz, _),\n  { choose! πi hP hHen hr Hn Hd using hJ, choose! n hn using Hn,\n    have hP : ((split_center J).bUnion_tagged πi).is_partition,\n      from (is_partition_split_center _).bUnion_tagged hP,\n    have hsub : ∀ (J' ∈ (split_center J).bUnion_tagged πi), ∃ n : ℕ, ∀ 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 ⟨J₁, h₁, h₂⟩,\n      refine ⟨n J₁ J' + 1, λ i, _⟩,\n      simp only [hn J₁ h₁ J' h₂, upper_sub_lower_of_mem_split_center h₁, pow_succ, div_div] },\n    refine ⟨_, hP, is_Henstock_bUnion_tagged.2 hHen, is_subordinate_bUnion_tagged.2 hr, hsub, _⟩,\n    refine tagged_prepartition.distortion_of_const _ hP.nonempty_boxes (λ J' h', _),\n    rcases hsub J' h' with ⟨n, hn⟩,\n    exact box.distortion_eq_of_sub_eq_div hn },\n  { refine ⟨I.Icc ∩ closed_ball z (r z),\n      inter_mem_nhds_within _ (closed_ball_mem_nhds _ (r z).coe_prop), _⟩,\n    intros J Hle n Hmem HIcc Hsub,\n    rw set.subset_inter_iff at HIcc,\n    refine ⟨single _ _ le_rfl _ Hmem, is_partition_single _, is_Henstock_single _,\n      (is_subordinate_single _ _).2 HIcc.2, _, distortion_single _ _⟩,\n    simp only [tagged_prepartition.mem_single, forall_eq],\n    refine ⟨0, λ i, _⟩, simp }\nend\n\nend box\n\nnamespace prepartition\n\nopen tagged_prepartition finset function\n\n/-- Given a box `I` in `ℝⁿ`, a function `r : ℝⁿ → (0, ∞)`, and a prepartition `π` of `I`, there\nexists a tagged prepartition `π'` of `I` such that\n\n* each box of `π'` is included in some box of `π`;\n* `π'` is a Henstock partition;\n* `π'` is subordinate to `r`;\n* `π'` covers exactly the same part of `I` as `π`;\n* the distortion of `π'` is equal to the distortion of `π`.\n-/\nlemma exists_tagged_le_is_Henstock_is_subordinate_Union_eq {I : box ι} (r : (ι → ℝ) → Ioi (0 : ℝ))\n  (π : prepartition I) :\n  ∃ π' : tagged_prepartition I, π'.to_prepartition ≤ π ∧\n    π'.is_Henstock ∧ π'.is_subordinate r ∧ π'.distortion = π.distortion ∧\n    π'.Union = π.Union :=\nbegin\n  have := λ J, box.exists_tagged_partition_is_Henstock_is_subordinate_homothetic J r,\n  choose! πi πip πiH πir hsub πid, clear hsub,\n  refine ⟨π.bUnion_tagged πi, bUnion_le _ _, is_Henstock_bUnion_tagged.2 (λ J _, πiH J),\n    is_subordinate_bUnion_tagged.2 (λ J _, πir J), _, π.Union_bUnion_partition (λ J _, πip J)⟩,\n  rw [distortion_bUnion_tagged],\n  exact sup_congr rfl (λ J _, πid J)\nend\n\n/-- Given a prepartition `π` of a box `I` and a function `r : ℝⁿ → (0, ∞)`, `π.to_subordinate r`\nis a tagged partition `π'` such that\n\n* each box of `π'` is included in some box of `π`;\n* `π'` is a Henstock partition;\n* `π'` is subordinate to `r`;\n* `π'` covers exactly the same part of `I` as `π`;\n* the distortion of `π'` is equal to the distortion of `π`.\n-/\ndef to_subordinate (π : prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : tagged_prepartition I :=\n(π.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some\n\n\n\nlemma is_Henstock_to_subordinate (π : prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π.to_subordinate r).is_Henstock :=\n(π.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.1\n\nlemma is_subordinate_to_subordinate (π : prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π.to_subordinate r).is_subordinate r :=\n(π.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.2.1\n\n@[simp] lemma distortion_to_subordinate (π : prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π.to_subordinate r).distortion = π.distortion :=\n(π.exists_tagged_le_is_Henstock_is_subordinate_Union_eq r).some_spec.2.2.2.1\n\n@[simp] lemma Union_to_subordinate (π : prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π.to_subordinate r).Union = π.Union :=\n(π.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 `π₁`, a prepartition `π₂` that covers exactly `I \\ π₁.Union`, and\na function `r : ℝⁿ → (0, ∞)`, returns the union of `π₁` and `π₂.to_subordinate r`. This partition\n`π` has the following properties:\n\n* `π` is a partition, i.e. it covers the whole `I`;\n* `π₁.boxes ⊆ π.boxes`;\n* `π.tag J = π₁.tag J` whenever `J ∈ π₁`;\n* `π` is Henstock outside of `π₁`: `π.tag J ∈ J.Icc` whenever `J ∈ π`, `J ∉ π₁`;\n* `π` is subordinate to `r` outside of `π₁`;\n* the distortion of `π` is equal to the maximum of the distortions of `π₁` and `π₂`.\n-/\ndef union_compl_to_subordinate (π₁ : tagged_prepartition I) (π₂ : prepartition I)\n  (hU : π₂.Union = I \\ π₁.Union) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  tagged_prepartition I :=\nπ₁.disj_union (π₂.to_subordinate r)\n  (((π₂.Union_to_subordinate r).trans hU).symm ▸ disjoint_sdiff_self_right)\n\nlemma is_partition_union_compl_to_subordinate (π₁ : tagged_prepartition I) (π₂ : prepartition I)\n  (hU : π₂.Union = I \\ π₁.Union) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  is_partition (π₁.union_compl_to_subordinate π₂ hU r) :=\nprepartition.is_partition_disj_union_of_eq_diff ((π₂.Union_to_subordinate r).trans hU)\n\n@[simp] lemma union_compl_to_subordinate_boxes (π₁ : tagged_prepartition I) (π₂ : prepartition I)\n  (hU : π₂.Union = I \\ π₁.Union) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π₁.union_compl_to_subordinate π₂ hU r).boxes = π₁.boxes ∪ (π₂.to_subordinate r).boxes :=\nrfl\n\n@[simp] lemma Union_union_compl_to_subordinate_boxes (π₁ : tagged_prepartition I)\n  (π₂ : prepartition I) (hU : π₂.Union = I \\ π₁.Union) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π₁.union_compl_to_subordinate π₂ hU r).Union = I :=\n(is_partition_union_compl_to_subordinate _ _ _ _).Union_eq\n\n@[simp] lemma distortion_union_compl_to_subordinate (π₁ : tagged_prepartition I)\n  (π₂ : prepartition I) (hU : π₂.Union = I \\ π₁.Union) (r : (ι → ℝ) → Ioi (0 : ℝ)) :\n  (π₁.union_compl_to_subordinate π₂ hU r).distortion = max π₁.distortion π₂.distortion :=\nby simp [union_compl_to_subordinate]\n\nend tagged_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/subbox_induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7529620345999894}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio . Demostrar que si f es una función suprayectiva de ℝ en ℝ,\n-- entonces existe un x tal que (f x)^2 = 4.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nopen function\n\nexample \n  {f : ℝ → ℝ} \n  (h : surjective f) \n  : ∃ x, (f x)^2 = 4 :=\nbegin\n  cases h 2 with x hx,\n  use x,\n  rw hx,\n  norm_num,\nend\n\n-- La prueba es\n-- \n-- f : ℝ → ℝ,\n-- h : surjective f\n-- ⊢ ∃ (x : ℝ), f x ^ 2 = 4\n--    >> cases h 2 with x hx,\n-- x : ℝ,\n-- hx : f x = 2\n-- ⊢ ∃ (x : ℝ), f x ^ 2 = 4\n--    >> use x,\n-- ⊢ f x ^ 2 = 4\n--    >> rw hx,\n-- ⊢ 2 ^ 2 = 4\n--    >> norm_num,\n-- no 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/Propiedad_de_suprayectivas.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.8128673178375734, "lm_q1q2_score": 0.7529620287469835}}
{"text": "\ndef fact : Nat → Nat\n| 0     => 1\n| (n+1) => (n+1)*fact n\n\ndef v1 := fact 10\ntheorem v1Eq : v1 = fact 10 :=\nEq.refl (fact 10)\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/reduce2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037302939514, "lm_q2_score": 0.8128673178375735, "lm_q1q2_score": 0.7529620287469834}}
{"text": "-- Ley_de_absorcion_1.lean\n-- Si R es un retículo y x, y ∈ R, entonces x ⊓ (x ⊔ y) = x\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 20-octubre-2022\n-- ---------------------------------------------------------------------\n\nimport order.lattice\nvariables {R : Type*} [lattice R]\nvariables x y : R\n\n-- 1ª demostración\n-- ===============\n\nexample : x ⊓ (x ⊔ y) = x :=\nbegin\n  have h1 : x ⊓ (x ⊔ y) ≤ x, finish,\n  have h2 : x ≤ x ⊓ (x ⊔ y), finish,\n  show x ⊓ (x ⊔ y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : x ⊓ (x ⊔ y) = x :=\nbegin\n  have h1 : x ⊓ (x ⊔ y) ≤ x := inf_le_left,\n  have h2 : x ≤ x ⊓ (x ⊔ y),\n  { have h2a : x ≤ x := rfl.ge,\n    have h2b : x ≤ x ⊔ y := le_sup_left,\n    show x ≤ x ⊓ (x ⊔ y),\n      by exact le_inf h2a h2b, },\n  show x ⊓ (x ⊔ y) = x,\n    by exact le_antisymm h1 h2,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : x ⊓ (x ⊔ 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-- 4ª demostración\nexample : x ⊓ (x ⊔ y) = x :=\n-- by library_search\ninf_sup_self\n\n-- 5ª demostración\n-- ===============\n\nexample : x ⊓ (x ⊔ 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_1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869916479466, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7528823361854999}}
{"text": "import Mathlib.Tactic.Basic\nimport Mathlib.Tactic.Cases\n\n/-!\n## Induction by Pattern Matching\n\nIn [Proofs by Mathematical Induction](../BackwardProofs/Induction.lean.md), we reviewed the use of\nthe induction’ tactic to perform proofs by induction. An alternative, more flexible style relies on\npattern matching and the Curry–Howard correspondence.\n\nRecall the definition of the reverse of a list from [Function Definitions](../Basics/FunctionDefinitions.lean.md):\n\n-/\ndef reverse {α : Type} : List α → List α\n| [] => []\n| (x :: xs) => reverse xs ++ [x]\n\n/-!\nIn fact, `reverse` exists in Lean’s standard library, as `List.reverse`, but our definition is\noptimized for reasoning. A useful property to prove is that `reverse` is its own inverse: `reverse\n(reverse xs) = xs` for all lists `xs`. However, if we try to prove it by induction, we quickly run\ninto an obstacle. The induction step is\n```lean\nih : ∀xs, reverse (reverse xs) = xs ⊢ reverse (reverse xs ++ [x]) = x :: xs\n```\nWhat is unpleasant about this subgoal is the presence of `++ [x]` inside the double\n`reverse` sandwich. We need a way to “distribute” the outer `reverse` over `++` to\nobtain a term that matches the induction hypothesis’s left-hand side. The trick is\nto prove and use the following lemma:\n-/\nlemma reverse_append {α : Type} :\n  ∀ xs ys : List α, reverse (xs ++ ys) = reverse ys ++ reverse xs\n  | [], ys => by simp [reverse]\n  | (x :: xs), ys => by simp [reverse, reverse_append xs, List.append_assoc]\n\n/-!\nIn the proof of the lemma, the patterns on the left, `[]` and `x :: xs`, correspond to\nthe two constructors of the ∀-quantified variable `xs :: List α`. On the right-hand\nside of each `=>` symbol is a proof for the corresponding case.\n\nInside the induction step’s proof, the induction hypothesis is available under\nthe same name as the lemma we are proving (`reverse_append`). We explicitly\npass `xs` as argument to the induction hypothesis. This is useful as documentation,\nand it also prevents Lean from accidentally invoking the induction hypothesis in\na circular fashion on `x :: xs`. Lean’s termination checker would notice that the\nargument is ill-founded and raise an error.\n\nFor reference, the corresponding tactical proof is as follows:\n-/\nlemma reverse_append₂ {α : Type} (xs ys : List α) :\n  reverse (xs ++ ys) = reverse ys ++ reverse xs := by\n  induction' xs\n  case nil => simp [reverse]\n  case cons x xs ih => simp [reverse, ih, List.append_assoc]\n/-!\nwhich can also be written\n-/\n\nlemma reverse_append₃ (as bs : List α) :\n  (as ++ bs).reverse = bs.reverse ++ as.reverse := by\n  induction as generalizing bs with\n  | nil => simp\n  | cons a as ih => simp [ih, List.append_assoc]\n\n/-!\nThe lemma would also be provable, and useful, if we put `[y]` instead of `ys`. But it is a good\nhabit to state lemmas as generally as possible. This results in more reusable libraries. Moreover,\nthis is often necessary to obtain a strong enough induction hypothesis in a proof by induction. In\ngeneral, finding the right inductions and lemmas can be diffcult, requiring thought and creativity.\n\nSimultaneous pattern matching on multiple variables is supported (e.g., `xs` and `ys` above). The\npatterns are then separated by spaces. This explains why Lean requires us to put parentheses around\ncomplex patterns, even when we match on a single variable. The general format is\n\n```lean\nlemma name (params₁ : type1₁) . . . (paramsₘ : typeₘ) :\nstatement\n| patterns₁ := proof₁\n.\n.\n.\n| patternsₙ := proofₙ\n```\nNotice the strong similarity with the syntax of `def` (Section 1.3). The two commands are, in fact,\nalmost the same, the main exception being that `lemma` considers the defined term or the proof opaque,\nwhereas `def` keeps it transparent. Since the actual proofs are irrelevant once a lemma is proven\n(Section 11), there is no need to expand them later. A similar distinction exists between `let` and\n`have`.\n\nBy the Curry–Howard correspondence, a proof by induction by pattern matching is the same as a\nrecursive proof term. When we invoke the induction hypothesis, we are really just invoking a\nrecursive function recursively. This explains why the induction hypothesis has the same name as the\nlemma we prove. Lean’s termination checker is used to establish well-foundedness of the proof by\ninduction.\n\nWith the reverse_append lemma in place, we can return to our initial goal:\n-/\nlemma reverse_reverse {α : Type} :\n  ∀ xs : List α, reverse (reverse xs) = xs\n  | [] => by rfl\n  | (x :: xs) =>\n  by simp [reverse, reverse_append, reverse_reverse xs]\n\n/-!\nInduction by pattern matching is highly popular among Lean users. Its main advantages are its\nconvenient syntax and its support for well-founded induction and not only structural induction, as\nprovided by the [induction’ tactic](../BackwardProofs/InductionTactic.lean.md). However, in this\nguide, we will not need the full power of well-founded induction. Furthermore, for subtle logical\nreasons, induction by pattern matching is not available for inductive predicates, which are the\ntopic of Chapter 5.\n\n--BUGBUG: is this still true in lean4?\n-/\n\n", "meta": {"author": "lovettchris", "repo": "hglv", "sha": "339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b", "save_path": "github-repos/lean/lovettchris-hglv", "path": "github-repos/lean/lovettchris-hglv/hglv-339f0b10f4b4a2b1e53e2b29532003a5ea4d9c9b/ForwardProofs/InductionPatterns.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.752882314867333}}
{"text": "import algebra.ring.basic\nimport data.rat.basic\nimport tactic.ring\n\n/-\nBulgarian Mathematical Olympiad 1998, Problem 8\n\nThe polynomials Pₙ(x,y) for n = 1, 2, ... are defined by P₁(x,y) = 1 and\n\n  Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y)\n\nProve that Pₙ(x,y) = Pₙ(y,x) for all x,y,n.\n\n-/\n\nvariables {R : Type} [comm_ring R]\n\ndef P : ℕ → R → R → R\n| 0 _ _ := 1\n| (n+1) x y := (x + y - 1) * (y + 1) * P n x (y + 2) + (y - y^2) * P n x y\n\n/- helper function\n   Sₙ₋₁(x,y) = [(x + y)² - 1](y + 1)(x + 1)Pₙ₋₁(y+2, x+2).\n-/\ndef S : ℕ → R → R → R\n| n x y := ((x + y)^2 - 1) * (y + 1) * (x + 1) * P n (y + 2) (x + 2)\n\n/- helper function\n   Tₙ₋₁(x,y) = (y - y²)(x - x²)Pₙ₋₁(y, x).\n-/\ndef T : ℕ → R → R → R\n| n x y := (y - y^2) * (x - x^2) * P n y x\n\n/- helper function\n   Uₙ₋₁(x,y) = (x + y - 1) [(y + 1)(x - x²)Pₙ₋₁(y + 2, x)\n                           + (x + 1)(y - y²) Pₙ₋₁(y, x + 2)]\n-/\ndef U : ℕ → R → R → R\n| n x y := (x + y - 1) *((y + 1)*(x - x^2) * P n (y + 2) x\n                           + (x + 1) * (y - y^2) * P n y (x + 2))\n\ntheorem bulgaria1998_q8 (n : ℕ) (x y : R) : P n x y = P n y x :=\nbegin\n  -- We induct on n. For n = 1,2 the result is evident.\n  -- So we take n > 1 and suppose that the result is true for\n  -- Pₙ₋₁(x,y) and Pₙ₋₂(x,y).\n  revert x y,\n  induction n using nat.strong_induction_on with n ih,\n  cases n, { intros, refl },\n  cases n,\n  { intros, unfold P, ring },\n  -- in the informal proof at this point, we're trying to\n  -- prove the end result at n+1.\n  -- In our formal version, that corresponds to proving the result for\n  -- n.succ.succ\n\n  /- We have\n     Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y)\n               = (x + y - 1)(y + 1)Pₙ(y+2,x) + (y - y²)Pₙ(y,x)\n  -/\n\n  have ih1 := ih n.succ (lt_add_one (nat.succ n)),\n  have h1 : ∀ x y : R, P n.succ.succ x y =\n             (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) +\n                 (y - y^2) * (P n.succ y x),\n  { intros x y,\n    calc P (n.succ.succ) x y\n               = (x + y - 1) * (y + 1) * (P n.succ x (y + 2)) +\n                   (y - y^2) * (P n.succ x y) : rfl\n           ... = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) +\n                   (y - y^2) * (P n.succ y x) : by {rw[ih1 x y,ih1 x (y+2)]} },\n\n  have h2 : ∀ x y : R, (x + y - 1) * (y + 1) * P n.succ (y + 2) x\n      = S n x y + (x + y - 1)* (y + 1) * (x - x^2)* P n (y+2) x,\n  {intros x y, unfold S P, ring},\n\n  have h_s_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, S m x y = S m y x,\n  { intros m hm x y, unfold S, rw[ih m hm (x + 2) (y + 2)], ring },\n\n  have h4 : ∀ x y : R, (y - y^2) * P n.succ y x =\n            (y - y^2) * (x + y -1) * (x + 1) * P n y (x + 2) + T n x y,\n  { intros x y, unfold T P, ring },\n\n  have h_t_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, T m x y = T m y x,\n  { intros m hm x y, unfold T, rw[ih m hm x y], ring },\n\n  have h_u_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, U m x y = U m y x,\n  { intros m hm x y, unfold U, rw[ih m hm (y+2) x, ih m hm (x+2) y], ring },\n\n  have h7 : ∀ x y : R, P n.succ.succ x y = S n x y + T n x y + U n x y,\n  { intros x y, rw[h1 x y, h2 x y, h4 x y], unfold U, ring,},\n\n  have h9 : n < n.succ.succ := nat.lt.step (lt_add_one n),\n\n  intros x y,\n  calc P n.succ.succ x y = S n x y + T n x y + U n x y : h7 x y\n                     ... = S n y x + T n x y + U n x y : by rw[h_s_symm n h9 x y]\n                     ... = S n y x + T n y x + U n x y : by rw[h_t_symm n h9 x y]\n                     ... = S n y x + T n y x + U n y x : by rw[h_u_symm n h9 x y]\n                     ... = P n.succ.succ y x : (h7 y x).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/bulgaria1998_q8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.752814141313189}}
{"text": "/- ** Inference rules ** -/\n\n/-\nSo how do we decide whether a given proposition\ncan be judged to be true or not? Here is where \nthe semantics of a logic come into play.\n\nThe semantics of a logic comprises a set of rules,\ncalled inference rules, that define the conditions \nunder which a given proposition can be judged to \nbe true.\n\nOversimplifying a bit, if you can apply one or more \ninference rules to propositions you already know \nto be true, and if by doing this you \"deduce\" some\nnew proposition, then you can conclude that that\nnew proposition must also be true. Such a \"chain\"\nof inference rules, linking things already known\nto be true to propositions that you want to prove\nto be true because they follow logically is called\na proof. A valid proof is incontrovertible evidence\nthat the final proposition is true.\n\nAn inference rule is like a little program: it says,\nif you can give me evidence (i.e., proofs) showing\nthat certain \"input\" propositions can be judged to\nbe true, then I will hand you back evidence (i.e.,\na proof) that shows that some new proposition can \nalso be judged to be true. We would say that from \nthe  proofs of the premises (the input propositions\nalready known to be true), the rule derives or deduces\na proof of the conclusion.\n\nLogicians often write inference rules like this:\n\n  list of input truth judgments \n  ----------------------------- (name-of-rule)\n  truth judgment for conclusion\n\nThe required input judgments, called premises (or\nantecedents), are listed above the line. The name \nof the rule is given to the right of the line. And\nthe proposition (or consequent) that can thereby\nbe judged to be true (the conclusion of the rule)\nis written below the line.\n\nFor example, if we already have the truth judgment,\n(0 = 0 : true), and another, (1 = 1: true), then the \ninference rule that logicians call \"and introduction\"\n(or \"conjunction introduction\") can be used to derive\na truth judgment for the new proposition, \"0 = 0 and\n1 = 1\", typically written as 0 = 0 ∧ 1 = 1. (Hover\nyour mouse over special symbols in this editor to\nlearn how to use them in your work.)\n\nPredicate logic will thus (in effect) include such\ninference rules as this:\n\n0 = 0 : true, 1 = 1 : true\n-------------------------- and-introduction-*\n      0 = 0 ∧ 1 = 1\n\nThis can be pronounced as, \"If you already have \nevidence (a proof) supporting the judgment that \n0 = 0 is true, and if you also have evidence (a\nproof) supporting the judgment that 1 = 1 is true, \nthen by applying the and-introduction-* rule, \nyou can deduce (obtain a proof justifying a truth\njudgment for) the proposition, 0 = 0 ∧  1 = 1\". \n\nWe've put a * on the name of this rule to indicate\nthat it's really just a special case of a far more\ngeneral inference rule for reasoning about equality. \n\nInference rules are usually written not in terms of \nvery specific propositions, such as 0 = 0, but in \nterms of variables that can refer to any arbitrary \npropositions. They are often called meta-variables.\n\nIn this way, inference rules become program-like, in\nthat they can take arbitrary inputs (of the correct \ntypes), and whenever they are given such inputs, they\nproduce result of a promised type.\n\nHere's a simple example of such a parameterized and\nthereby generalized rule. If P is *any* proposition \n(e.g., it could be 0 = 0 but might be some other\nproposition), and Q is another proposition (e.g.,\n1 = 1), and if both propositions are already known\nto be true, then you can always conclude that the \nproposition \"P and Q\", written P ∧ Q, must also be\ntrue, for whatever propositions P and Q happen to \nbe.\n\nHere is how the general form of this inference rule \nwould typically be written in a book on logic.\n\nP : true, Q : true\n------------------ (and.intro)\n   P ∧ Q : true\n\nThe inference rule is called \"and introduction\"\nbecause it produces a proof of a proposition \nthat now contains an \"and\" (∧). The rule can be\nread as follows. If P and Q are propositions,\nand if you have judged P to be true and you \nhave judged Q to be true, then you can judge\nP ∧ Q to be true. \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/02_inference_rules.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.817574471748733, "lm_q2_score": 0.9207896710002322, "lm_q1q2_score": 0.7528141288597046}}
{"text": "/-\nCopyright (c) 2021 Ivan Sadofschi Costa. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Ivan Sadofschi Costa\n-/\nimport data.finsupp.defs\n\n/-!\n# `cons` and `tail` for maps `fin n →₀ M`\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nWe interpret maps `fin n →₀ M` as `n`-tuples of elements of `M`,\nWe define the following operations:\n* `finsupp.tail` : the tail of a map `fin (n + 1) →₀ M`, i.e., its last `n` entries;\n* `finsupp.cons` : adding an element at the beginning of an `n`-tuple, to get an `n + 1`-tuple;\n\nIn this context, we prove some usual properties of `tail` and `cons`, analogous to those of\n`data.fin.tuple.basic`.\n-/\n\nnoncomputable theory\n\nnamespace finsupp\n\nvariables {n : ℕ} (i : fin n) {M : Type*} [has_zero M] (y : M)\n  (t : fin (n + 1) →₀ M) (s : fin n →₀ M)\n\n/-- `tail` for maps `fin (n + 1) →₀ M`. See `fin.tail` for more details. -/\ndef tail (s : fin (n + 1) →₀ M) : fin n →₀ M :=\nfinsupp.equiv_fun_on_finite.symm (fin.tail s)\n\n/-- `cons` for maps `fin n →₀ M`. See `fin.cons` for more details. -/\ndef cons (y : M) (s : fin n →₀ M) : fin (n + 1) →₀ M :=\nfinsupp.equiv_fun_on_finite.symm (fin.cons y s : fin (n + 1) → M)\n\nlemma tail_apply : tail t i = t i.succ := rfl\n\n@[simp] lemma cons_zero : cons y s 0 = y := rfl\n\n@[simp] lemma cons_succ : cons y s i.succ = s i := fin.cons_succ _ _ _\n\n@[simp] lemma tail_cons : tail (cons y s) = s :=\next $ λ k, by simp only [tail_apply, cons_succ]\n\n@[simp] lemma cons_tail : cons (t 0) (tail t) = t :=\nbegin\n  ext,\n  by_cases c_a : a = 0,\n  { rw [c_a, cons_zero] },\n  { rw [←fin.succ_pred a c_a, cons_succ, ←tail_apply] },\nend\n\n@[simp] lemma cons_zero_zero : cons 0 (0 : fin n →₀ M) = 0 :=\nbegin\n  ext,\n  by_cases c : a = 0,\n  { simp [c] },\n  { rw [←fin.succ_pred a c, cons_succ],\n    simp },\nend\n\nvariables {s} {y}\n\nlemma cons_ne_zero_of_left (h : y ≠ 0) : cons y s ≠ 0 :=\nbegin\n  contrapose! h with c,\n  rw [←cons_zero y s, c, finsupp.coe_zero, pi.zero_apply],\nend\n\nlemma cons_ne_zero_of_right (h : s ≠ 0) : cons y s ≠ 0 :=\nbegin\n  contrapose! h with c,\n  ext,\n  simp [ ← cons_succ a y s, c],\nend\n\nlemma cons_ne_zero_iff : cons y s ≠ 0 ↔ y ≠ 0 ∨ s ≠ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, h.cases_on cons_ne_zero_of_left cons_ne_zero_of_right⟩,\n  refine imp_iff_not_or.1 (λ h' c, h _),\n  rw [h', c, finsupp.cons_zero_zero],\nend\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/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927011, "lm_q2_score": 0.8499711794579722, "lm_q1q2_score": 0.7527612386293356}}
{"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.field.basic\nimport algebra.group_power.lemmas\nimport algebra.group_power.order\nimport algebra.order.ring\nimport order.bounds\nimport tactic.monotonicity.basic\n\n/-!\n# Linear ordered (semi)fields\n\nA linear ordered (semi)field is a (semi)field equipped with a linear order such that\n* addition respects the order: `a ≤ b → c + a ≤ c + b`;\n* multiplication of positives is positive: `0 < a → 0 < b → 0 < a * b`;\n* `0 < 1`.\n\n## Main Definitions\n\n* `linear_ordered_semifield`: Typeclass for linear order semifields.\n* `linear_ordered_field`: Typeclass for linear ordered fields.\n-/\n\nset_option old_structure_cmd true\n\nvariables {α β : Type*}\n\n/-- A linear ordered semifield is a field with a linear order respecting the operations. -/\n@[protect_proj] class linear_ordered_semifield (α : Type*)\n  extends linear_ordered_semiring α, semifield α\n\n/-- A linear ordered field is a field with a linear order respecting the operations. -/\n@[protect_proj] class linear_ordered_field (α : Type*) extends linear_ordered_comm_ring α, field α\n\n@[priority 100] -- See note [lower instance priority]\ninstance linear_ordered_field.to_linear_ordered_semifield [linear_ordered_field α] :\n  linear_ordered_semifield α :=\n{ ..linear_ordered_ring.to_linear_ordered_semiring, ..‹linear_ordered_field α› }\n\nnamespace function\n\n/-- Pullback a `linear_ordered_semifield` under an injective map. -/\n@[reducible] -- See note [reducible non-instances]\ndef injective.linear_ordered_semifield [linear_ordered_semifield α] [has_zero β] [has_one β]\n  [has_add β] [has_mul β] [has_pow β ℕ] [has_smul ℕ β] [has_nat_cast β] [has_inv β] [has_div β]\n  [has_pow β ℤ] (f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)\n  (inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)\n  (nsmul : ∀ x (n : ℕ), f (n • x) = n • f x)\n  (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n)\n  (nat_cast : ∀ n : ℕ, f n = n) :\n  linear_ordered_semifield β :=\n{ ..hf.linear_ordered_semiring f zero one add mul nsmul npow nat_cast,\n  ..hf.semifield f zero one add mul inv div nsmul npow zpow nat_cast }\n\n/-- Pullback a `linear_ordered_field` under an injective map. -/\n@[reducible] -- See note [reducible non-instances]\ndef injective.linear_ordered_field [linear_ordered_field α] [has_zero β] [has_one β] [has_add β]\n  [has_mul β] [has_neg β] [has_sub β] [has_pow β ℕ] [has_smul ℕ β] [has_smul ℤ β]\n  [has_nat_cast β] [has_int_cast β][has_inv β] [has_div β] [has_pow β ℤ]\n  (f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)\n  (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)\n  (neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y)\n  (inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)\n  (nsmul : ∀ x (n : ℕ), f (n • x) = n • f x) (zsmul : ∀ x (n : ℤ), f (n • x) = n • f x)\n  (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n)\n  (nat_cast : ∀ n : ℕ, f n = n) (int_cast : ∀ n : ℤ, f n = n) :\n  linear_ordered_field β :=\n{ .. hf.linear_ordered_ring f zero one add mul neg sub nsmul zsmul npow nat_cast int_cast,\n  .. hf.field f zero one add mul neg sub inv div nsmul zsmul npow zpow nat_cast int_cast }\n\nend function\n\nsection linear_ordered_semifield\nvariables [linear_ordered_semifield α] {a b c d e : α}\n\n/-- `equiv.mul_left₀` as an order_iso. -/\n@[simps {simp_rhs := tt}]\ndef order_iso.mul_left₀ (a : α) (ha : 0 < a) : α ≃o α :=\n{ map_rel_iff' := λ _ _, mul_le_mul_left ha, ..equiv.mul_left₀ a ha.ne' }\n\n/-- `equiv.mul_right₀` as an order_iso. -/\n@[simps {simp_rhs := tt}]\ndef order_iso.mul_right₀ (a : α) (ha : 0 < a) : α ≃o α :=\n{ map_rel_iff' := λ _ _, mul_le_mul_right ha, ..equiv.mul_right₀ a ha.ne' }\n\n/-!\n### Lemmas about pos, nonneg, nonpos, neg\n-/\n\n@[simp] lemma inv_pos : 0 < a⁻¹ ↔ 0 < a :=\nsuffices ∀ a : α, 0 < a → 0 < a⁻¹,\nfrom ⟨λ h, inv_inv a ▸ this _ h, this a⟩,\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 ≤ a⁻¹ ↔ 0 ≤ a :=\nby simp only [le_iff_eq_or_lt, inv_pos, zero_eq_inv]\n\n@[simp] lemma inv_lt_zero : a⁻¹ < 0 ↔ a < 0 :=\nby simp only [← not_le, inv_nonneg]\n\n@[simp] lemma inv_nonpos : a⁻¹ ≤ 0 ↔ a ≤ 0 :=\nby simp only [← not_lt, inv_pos]\n\nlemma one_div_pos : 0 < 1 / a ↔ 0 < a :=\ninv_eq_one_div a ▸ inv_pos\n\nlemma one_div_neg : 1 / a < 0 ↔ a < 0 :=\ninv_eq_one_div a ▸ inv_lt_zero\n\nlemma one_div_nonneg : 0 ≤ 1 / a ↔ 0 ≤ a :=\ninv_eq_one_div a ▸ inv_nonneg\n\nlemma one_div_nonpos : 1 / a ≤ 0 ↔ a ≤ 0 :=\ninv_eq_one_div a ▸ inv_nonpos\n\nlemma div_pos (ha : 0 < a) (hb : 0 < b) : 0 < a / b :=\nby { rw div_eq_mul_inv, exact mul_pos ha (inv_pos.2 hb) }\n\nlemma div_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b :=\nby { rw div_eq_mul_inv, exact mul_nonneg ha (inv_nonneg.2 hb) }\n\nlemma div_nonpos_of_nonpos_of_nonneg (ha : a ≤ 0) (hb : 0 ≤ b) : a / b ≤ 0 :=\nby { rw div_eq_mul_inv, exact mul_nonpos_of_nonpos_of_nonneg ha (inv_nonneg.2 hb) }\n\nlemma div_nonpos_of_nonneg_of_nonpos (ha : 0 ≤ a) (hb : b ≤ 0) : a / b ≤ 0 :=\nby { rw div_eq_mul_inv, exact mul_nonpos_of_nonneg_of_nonpos ha (inv_nonpos.2 hb) }\n\n/-!\n### Relating one division with another term.\n-/\n\nlemma le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b :=\n⟨λ h, div_mul_cancel b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le,\n  λ h, calc\n    a   = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc).symm\n    ... ≤ 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⟩\n\nlemma le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b :=\nby rw [mul_comm, le_div_iff hc]\n\nlemma div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b :=\n⟨λ h, calc\n  a = a / b * b : by rw (div_mul_cancel _ (ne_of_lt hb).symm)\n  ... ≤ c * b     : mul_le_mul_of_nonneg_right h hb.le,\n  λ h, calc\n  a / b = a * (1 / b)     : div_eq_mul_one_div a b\n  ... ≤ (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⟩\n\nlemma div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c :=\nby rw [mul_comm, div_le_iff hb]\n\nlemma lt_div_iff (hc : 0 < c) : a < b / c ↔ 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 ↔ c * a < b :=\nby rw [mul_comm, lt_div_iff hc]\n\nlemma div_lt_iff (hc : 0 < c) : b / c < a ↔ 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 ↔ b < c * a :=\nby rw [mul_comm, div_lt_iff hc]\n\nlemma inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c :=\nbegin\n  rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div],\n  exact div_le_iff' h,\nend\n\nlemma inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b :=\nby rw [inv_mul_le_iff h, mul_comm]\n\nlemma mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c :=\nby rw [mul_comm, inv_mul_le_iff h]\n\nlemma mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b :=\nby rw [mul_comm, inv_mul_le_iff' h]\n\nlemma div_self_le_one (a : α) : a / a ≤ 1 :=\nif h : a = 0 then by simp [h] else by simp [h]\n\nlemma inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c :=\nbegin\n  rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div],\n  exact div_lt_iff' h,\nend\n\nlemma inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b :=\nby rw [inv_mul_lt_iff h, mul_comm]\n\nlemma mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c :=\nby rw [mul_comm, inv_mul_lt_iff h]\n\nlemma mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ 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⁻¹ ≤ b ↔ 1 ≤ 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⁻¹ ≤ b ↔ 1 ≤ 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⁻¹ < b ↔ 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⁻¹ < b ↔ 1 < a * b :=\nby { rw [inv_eq_one_div], exact div_lt_iff' ha }\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 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ 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 ≤ b) (hb : 0 ≤ b) : a / b ≤ 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 ≤ b) : b⁻¹ ≤ a⁻¹ :=\nby rwa [← one_div a, le_div_iff' ha, ← 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⁻¹ ≤ b⁻¹ ↔ b ≤ a :=\nby rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul]\n\n/-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`.\nSee also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/\nlemma inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=\nby rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv]\n\nlemma inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a :=\n(inv_le ha ((inv_pos.2 ha).trans_le h)).1 h\n\nlemma le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=\nby rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv]\n\n/-- See `inv_lt_inv_of_lt` for the implication from right-to-left with one fewer assumption. -/\nlemma inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a :=\nlt_iff_lt_of_le_iff_le (inv_le_inv hb ha)\n\nlemma inv_lt_inv_of_lt (hb : 0 < b) (h : b < a) : a⁻¹ < b⁻¹ :=\n(inv_lt_inv (hb.trans h) hb).2 h\n\n/-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`.\nSee also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/\nlemma inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a :=\nlt_iff_lt_of_le_iff_le (le_inv hb ha)\n\nlemma inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a :=\n(inv_lt ha ((inv_pos.2 ha).trans h)).1 h\n\nlemma lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ :=\nlt_iff_lt_of_le_iff_le (inv_le hb ha)\n\nlemma inv_lt_one (ha : 1 < a) : a⁻¹ < 1 :=\nby rwa [inv_lt ((@zero_lt_one α _ _).trans ha) zero_lt_one, inv_one]\n\nlemma one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ :=\nby rwa [lt_inv (@zero_lt_one α _ _) h₁, inv_one]\n\nlemma inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 :=\nby rwa [inv_le ((@zero_lt_one α _ _).trans_le ha) zero_lt_one, inv_one]\n\nlemma one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ :=\nby rwa [le_inv (@zero_lt_one α _ _) h₁, inv_one]\n\nlemma inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a :=\n⟨λ h₁, inv_inv a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩\n\nlemma inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 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⁻¹ ↔ 0 < a ∧ a < 1 :=\n⟨λ h, ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩\n\nlemma inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ 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 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 :=\n⟨λ h, ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩\n\n/-!\n### Relating two divisions.\n-/\n\n@[mono] lemma div_le_div_of_le (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_le_mul_of_nonneg_right h (one_div_nonneg.2 hc)\nend\n\n-- Not a `mono` lemma b/c `div_le_div` is strictly more general\nlemma div_le_div_of_le_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ 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 ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c :=\ndiv_le_div_of_le hc hab\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_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b :=\n⟨le_imp_le_of_lt_imp_lt $ div_lt_div_of_lt hc, div_le_div_of_le $ hc.le⟩\n\nlemma div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b :=\nlt_iff_lt_of_le_iff_le $ div_le_div_right hc\n\nlemma div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ 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 ≤ a / c ↔ c ≤ 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 ↔ 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 ≤ c / d ↔ a * d ≤ 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 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ 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 ≤ b) (c0 : 0 ≤ 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 ≤ 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 (hc : 0 < c) (hb : 0 < b) (h : b < a) : 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 div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a :=\nby simpa only [div_one] using div_le_div_of_le_left ha zero_lt_one hb\n\nlemma div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a :=\nby simpa only [div_one] using div_lt_div_of_lt_left ha zero_lt_one hb\n\nlemma le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b :=\nby simpa only [div_one] using div_le_div_of_le_left ha hb₀ hb₁\n\nlemma one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a :=\nby rw [le_div_iff hb, one_mul]\n\nlemma div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b :=\nby rw [div_le_iff hb, one_mul]\n\nlemma one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a :=\nby rw [lt_div_iff hb, one_mul]\n\nlemma div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b :=\nby rw [div_lt_iff hb, one_mul]\n\nlemma one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a :=\nby simpa using inv_le ha hb\n\nlemma one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a :=\nby simpa using inv_lt ha hb\n\nlemma le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a :=\nby simpa using le_inv ha hb\n\nlemma lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a :=\nby simpa using lt_inv ha hb\n\n/-!\n### Relating two divisions, involving `1`\n-/\nlemma one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 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, ← div_eq_mul_one_div, div_lt_one (ha.trans h)]\n\nlemma le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ 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\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 ≤ 1 / b ↔ b ≤ 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 ↔ b < a :=\ndiv_lt_div_left zero_lt_one ha hb\n\nlemma one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a :=\nby rwa [lt_one_div (@zero_lt_one α _ _) h1, one_div_one]\n\nlemma one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a :=\nby rwa [le_one_div (@zero_lt_one α _ _) h1, one_div_one]\n\n/-!\n### Results about halving.\n\nThe equalities also hold in semifields of characteristic `0`.\n-/\n\n/- TODO: Unify `add_halves` and `add_halves'` into a single lemma about\n`division_semiring` + `char_zero` -/\nlemma add_halves (a : α) : a / 2 + a / 2 = a :=\nby rw [div_add_div_same, ← two_mul, mul_div_cancel_left a two_ne_zero]\n\n-- TODO: Generalize to `division_semiring`\nlemma add_self_div_two (a : α) : (a + a) / 2 = a :=\nby rw [← 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:α) < 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 α _ _)], exact lt_mul_of_one_lt_right h one_lt_two }\n\nlemma half_lt_self : 0 < a → a / 2 < a := div_two_lt_of_pos\n\nlemma half_le_self (ha_nonneg : 0 ≤ a) : a / 2 ≤ a :=\nbegin\n  by_cases h0 : a = 0,\n  { simp [h0], },\n  { rw ← 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 : α) < 1 := half_lt_self zero_lt_one\n\nlemma left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff, mul_two]\n\nlemma add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff, mul_two]\n\n/-!\n### Miscellaneous lemmas\n-/\n\nlemma mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c :=\nbegin\n  rw [← mul_div_assoc] at h,\n  rwa [mul_comm b, ← div_le_iff hc],\nend\n\nlemma div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) :\n  a / (b * e) ≤ 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_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a :=\nbegin\n  have : 0 < a / max (b + 1) 1, from div_pos h (lt_max_iff.2 (or.inr zero_lt_one)),\n  refine ⟨a / max (b + 1) 1, this, _⟩,\n  rw [← lt_div_iff this, div_div_cancel' h.ne'],\n  exact lt_max_iff.2 (or.inl $ lt_add_one _)\nend\n\nlemma monotone.div_const {β : Type*} [preorder β] {f : β → α} (hf : monotone f)\n  {c : α} (hc : 0 ≤ c) : monotone (λ 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 {β : Type*} [preorder β] {f : β → α} (hf : strict_mono f)\n  {c : α} (hc : 0 < c) :\n  strict_mono (λ 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 α :=\n{ dense := λ a₁ a₂ h, ⟨(a₁ + a₂) / 2,\n  calc a₁ = (a₁ + a₁) / 2 : (add_self_div_two a₁).symm\n      ... < (a₁ + a₂) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_left h _),\n  calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 : div_lt_div_of_lt zero_lt_two (add_lt_add_right h _)\n                 ... = a₂            : add_self_div_two a₂⟩ }\n\nlemma min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = (min a b) / c :=\neq.symm $ monotone.map_min (λ x y, div_le_div_of_le hc)\n\nlemma max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = (max a b) / c :=\neq.symm $ monotone.map_max (λ x y, div_le_div_of_le hc)\n\nlemma one_div_strict_anti_on : strict_anti_on (λ x : α, 1 / x) (set.Ioi 0) :=\nλ x x1 y y1 xy, (one_div_lt_one_div (set.mem_Ioi.mp y1) (set.mem_Ioi.mp x1)).mpr xy\n\nlemma one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :\n  1 / a ^ n ≤ 1 / a ^ m :=\nby refine (one_div_le_one_div _ _).mpr (pow_le_pow a1 mn);\n  exact pow_pos (zero_lt_one.trans_le a1) _\n\nlemma one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :\n  1 / a ^ n < 1 / a ^ m :=\nby refine (one_div_lt_one_div _ _).mpr (pow_lt_pow a1 mn);\n  exact pow_pos (trans zero_lt_one a1) _\n\nlemma one_div_pow_anti (a1 : 1 ≤ a) : antitone (λ n : ℕ, 1 / a ^ n) :=\nλ m n, one_div_pow_le_one_div_pow_of_le a1\n\nlemma one_div_pow_strict_anti (a1 : 1 < a) : strict_anti (λ n : ℕ, 1 / a ^ n) :=\nλ m n, one_div_pow_lt_one_div_pow_of_lt a1\n\nlemma inv_strict_anti_on : strict_anti_on (λ x : α, x⁻¹) (set.Ioi 0) :=\nλ x hx y hy xy, (inv_lt_inv hy hx).2 xy\n\nlemma inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :\n  (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ :=\nby convert one_div_pow_le_one_div_pow_of_le a1 mn; simp\n\nlemma inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :\n  (a ^ n)⁻¹ < (a ^ m)⁻¹ :=\nby convert one_div_pow_lt_one_div_pow_of_lt a1 mn; simp\n\nlemma inv_pow_anti (a1 : 1 ≤ a) : antitone (λ n : ℕ, (a ^ n)⁻¹) :=\nλ m n, inv_pow_le_inv_pow_of_le a1\n\nlemma inv_pow_strict_anti (a1 : 1 < a) : strict_anti (λ n : ℕ, (a ^ n)⁻¹) :=\nλ m n, inv_pow_lt_inv_pow_of_lt a1\n\n/-! ### Results about `is_lub` and `is_glb` -/\n\nlemma is_glb.mul_left {s : set α} (ha : 0 ≤ a) (hs : is_glb s b) :\n  is_glb ((λ b, a * b) '' s) (a * b) :=\nbegin\n  rcases lt_or_eq_of_le ha with ha | rfl,\n  { exact (order_iso.mul_left₀ _ ha).is_glb_image'.2 hs, },\n  { simp_rw zero_mul,\n    rw hs.nonempty.image_const,\n    exact is_glb_singleton },\nend\n\nlemma is_glb.mul_right {s : set α} (ha : 0 ≤ a) (hs : is_glb s b) :\n  is_glb ((λ b, b * a) '' s) (b * a) :=\nby simpa [mul_comm] using hs.mul_left ha\n\nend linear_ordered_semifield\n\nsection\nvariables [linear_ordered_field α] {a b c d : α}\n\n/-! ### Lemmas about pos, nonneg, nonpos, neg -/\n\nlemma div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp [division_def, mul_pos_iff]\nlemma div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff]\n\nlemma div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 :=\nby simp [division_def, mul_nonneg_iff]\n\nlemma div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b :=\nby simp [division_def, mul_nonpos_iff]\n\nlemma div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b :=\ndiv_nonneg_iff.2 $ or.inr ⟨ha, hb⟩\n\nlemma div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=\ndiv_pos_iff.2 $ or.inr ⟨ha, hb⟩\n\nlemma div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=\ndiv_neg_iff.2 $ or.inr ⟨ha, hb⟩\n\nlemma div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=\ndiv_neg_iff.2 $ or.inl ⟨ha, hb⟩\n\n/-! ### Relating one division with another term -/\n\nlemma div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b :=\n⟨λ h, div_mul_cancel b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le,\n  λ h, calc\n    a = a * c * (1 / c) : mul_mul_div a (ne_of_lt hc)\n  ... ≥ 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⟩\n\nlemma div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b :=\nby rw [mul_comm, div_le_iff_of_neg hc]\n\nlemma le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c :=\nby rw [← neg_neg c, mul_neg, div_neg, le_neg,\n    div_le_iff (neg_pos.2 hc), neg_mul]\n\nlemma le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ 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 ↔ 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 ↔ 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 ↔ 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 ↔ b < c * a :=\nby rw [mul_comm, lt_div_iff_of_neg hc]\n\n/-! ### Bi-implications of inequalities using inversions -/\n\nlemma inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=\nby rw [← one_div, div_le_iff_of_neg ha, ← 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⁻¹ ≤ b ↔ b⁻¹ ≤ a :=\nby rw [← 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 ≤ b⁻¹ ↔ b ≤ a⁻¹ :=\nby rw [← 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⁻¹ < b⁻¹ ↔ 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⁻¹ < b ↔ b⁻¹ < 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⁻¹ ↔ b < a⁻¹ :=\nlt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)\n\n/-! ### Relating two divisions -/\n\nlemma div_le_div_of_nonpos_of_le (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_le_mul_of_nonpos_right h (one_div_nonpos.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_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a :=\n⟨le_imp_le_of_lt_imp_lt $ div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le $ hc.le⟩\n\nlemma div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a :=\nlt_iff_lt_of_le_iff_le $ div_le_div_right_of_neg hc\n\n/-! ### Relating one division and involving `1` -/\n\nlemma one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b :=\nby rw [le_div_iff_of_neg hb, one_mul]\n\nlemma div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a :=\nby rw [div_le_iff_of_neg hb, one_mul]\n\nlemma one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ 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 ↔ b < a :=\nby rw [div_lt_iff_of_neg hb, one_mul]\n\nlemma one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ 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 ↔ 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 ≤ 1 / b ↔ b ≤ 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 ↔ b < 1 / a :=\nby simpa using lt_inv_of_neg ha hb\n\nlemma one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ 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 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ 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 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ 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 ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ 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/-! ### Relating two divisions, involving `1` -/\n\nlemma one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a :=\nby rwa [div_le_iff_of_neg' hb, ← 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, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)]\n\nlemma le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ 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_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 ≤ 1 / b ↔ b ≤ 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 ↔ b < a :=\nlt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)\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 ≤ a) : 1 / a ≤ -1 :=\nsuffices 1 / a ≤ 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/-! ### Results about halving -/\n\nlemma sub_self_div_two (a : α) : 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 : α) : 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_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b :=\nbegin\n  rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b/2), ← add_assoc, ← sub_eq_add_neg,\n    ← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_right (@zero_lt_two α _ _)]\nend\n\n/--  An inequality involving `2`. -/\nlemma sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 :=\nbegin\n  -- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a`\n  refine (inv_le_inv_of_le (inv_pos.2 zero_lt_two) _).trans_eq (inv_inv (2 : α)),\n  -- move `1 / a` to the left and `1 - 1 / 2 = 1 / 2` to the right to obtain `1 / a ≤ ⅟ 2`\n  refine (le_sub_iff_add_le.2 (_ : _ + 2⁻¹ = _ ).le).trans ((sub_le_sub_iff_left 1).2 _),\n  { -- show 2⁻¹ + 2⁻¹ = 1\n    exact (two_mul _).symm.trans (mul_inv_cancel two_ne_zero) },\n  { -- take inverses on both sides and use the assumption `2 ≤ a`.\n    exact (one_div a).le.trans (inv_le_inv_of_le zero_lt_two a2) }\nend\n\n/-! ### Results about `is_lub` and `is_glb` -/\n\n-- TODO: Generalize to `linear_ordered_semifield`\nlemma is_lub.mul_left {s : set α} (ha : 0 ≤ a) (hs : is_lub s b) :\n  is_lub ((λ b, a * b) '' s) (a * b) :=\nbegin\n  rcases lt_or_eq_of_le ha with ha | rfl,\n  { exact (order_iso.mul_left₀ _ ha).is_lub_image'.2 hs, },\n  { simp_rw zero_mul,\n    rw hs.nonempty.image_const,\n    exact is_lub_singleton },\nend\n\n-- TODO: Generalize to `linear_ordered_semifield`\nlemma is_lub.mul_right {s : set α} (ha : 0 ≤ a) (hs : is_lub s b) :\n  is_lub ((λ b, b * a) '' s) (b * a) :=\nby simpa [mul_comm] using hs.mul_left ha\n\n/-! ### Miscellaneous lemmmas -/\n\nlemma mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) :\n  (a * d - b * c) / (c * d) < 0 ↔ a / c < b / d :=\nby rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero]\n\nlemma mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) :\n  (a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d :=\nby rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos]\n\nalias mul_sub_mul_div_mul_neg_iff ↔ div_lt_div_of_mul_sub_mul_div_neg mul_sub_mul_div_mul_neg\nalias mul_sub_mul_div_mul_nonpos_iff ↔\n  div_le_div_of_mul_sub_mul_div_nonpos mul_sub_mul_div_mul_nonpos\n\nlemma exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c, b + c < a ∧ 0 < c :=\n⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩\n\nlemma le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a :=\nbegin\n  contrapose! h,\n  simpa only [and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt]\n    using exists_add_lt_and_pos_of_lt h,\nend\n\nlemma mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b :=\nmul_self_eq_mul_self_iff.trans $ or_iff_left_of_imp $\n  λ h, by { subst a, have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0, rw [this, neg_zero] }\n\nlemma min_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : min (a / c) (b / c) = (max a b) / c :=\neq.symm $ antitone.map_max $ λ x y, div_le_div_of_nonpos_of_le hc\n\nlemma max_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : max (a / c) (b / c) = (min a b) / c :=\neq.symm $ antitone.map_min $ λ x y, div_le_div_of_nonpos_of_le hc\n\nlemma abs_inv (a : α) : |a⁻¹| = (|a|)⁻¹ := (abs_hom : α →*₀ α).map_inv a\nlemma abs_div (a b : α) : |a / b| = |a| / |b| := (abs_hom : α →*₀ α).map_div a b\nlemma abs_one_div (a : α) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one]\n\nlemma pow_minus_two_nonneg : 0 ≤ a^(-2 : ℤ) :=\nbegin\n  simp only [inv_nonneg, zpow_neg],\n  change 0 ≤ a ^ ((2 : ℕ) : ℤ),\n  rw zpow_coe_nat,\n  apply sq_nonneg,\nend\n\n/-- Bernoulli's inequality reformulated to estimate `(n : α)`. -/\nlemma nat.cast_le_pow_sub_div_sub (H : 1 < a)  (n : ℕ) : (n : α) ≤ (a ^ n - 1) / (a - 1) :=\n(le_div_iff (sub_pos.2 H)).2 $ le_sub_left_of_add_le $\n  one_add_mul_sub_le_pow ((neg_le_self zero_le_one).trans H.le) _\n\n/-- For any `a > 1` and a natural `n` we have `n ≤ a ^ n / (a - 1)`. See also\n`nat.cast_le_pow_sub_div_sub` for a stronger inequality with `a ^ n - 1` in the numerator. -/\ntheorem nat.cast_le_pow_div_sub (H : 1 < a) (n : ℕ) : (n : α) ≤ a ^ n / (a - 1) :=\n(n.cast_le_pow_sub_div_sub H).trans $ div_le_div_of_le (sub_nonneg.2 H.le)\n  (sub_le_self _ zero_le_one)\n\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/algebra/order/field.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7527612189862294}}
{"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-/\nimport data.mv_polynomial.monad\n\n/-!\n## Expand multivariate polynomials\n\nGiven a multivariate polynomial `φ`, 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 `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.\n-/\n\nopen_locale big_operators\n\nnamespace mv_polynomial\n\nvariables {σ τ R S : Type*} [comm_semiring R] [comm_semiring S]\n\n/-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.\n\nSee also `polynomial.expand`. -/\nnoncomputable def expand (p : ℕ) : mv_polynomial σ R →ₐ[R] mv_polynomial σ R :=\n{ commutes' := λ r, eval₂_hom_C _ _ _,\n  .. (eval₂_hom C (λ i, (X i) ^ p) : mv_polynomial σ R →+* mv_polynomial σ R) }\n\n@[simp] lemma expand_C (p : ℕ) (r : R) : expand p (C r : mv_polynomial σ R) = C r :=\neval₂_hom_C _ _ _\n\n@[simp] lemma expand_X (p : ℕ) (i : σ) : expand p (X i : mv_polynomial σ R) = X i ^ p :=\neval₂_hom_X' _ _ _\n\n@[simp] lemma expand_monomial (p : ℕ) (d : σ →₀ ℕ) (r : R) :\n  expand p (monomial d r) = C r * ∏ i in d.support, (X i ^ p) ^ d i :=\nbind₁_monomial _ _ _\n\nlemma expand_one_apply (f : mv_polynomial σ R) : expand 1 f = f :=\nby simp only [expand, bind₁_X_left, alg_hom.id_apply, ring_hom.to_fun_eq_coe,\n  eval₂_hom_C_left, alg_hom.coe_to_ring_hom, pow_one, alg_hom.coe_mk]\n\n@[simp] lemma expand_one : expand 1 = alg_hom.id R (mv_polynomial σ R) :=\nby { ext1 f, rw [expand_one_apply, alg_hom.id_apply] }\n\nlemma expand_comp_bind₁ (p : ℕ) (f : σ → mv_polynomial τ R) :\n  (expand p).comp (bind₁ f) = bind₁ (λ i, expand p (f i)) :=\nby { apply alg_hom_ext, intro i, simp only [alg_hom.comp_apply, bind₁_X_right], }\n\nlemma expand_bind₁ (p : ℕ) (f : σ → mv_polynomial τ R) (φ : mv_polynomial σ R) :\n  expand p (bind₁ f φ) = bind₁ (λ i, expand p (f i)) φ :=\nby rw [← alg_hom.comp_apply, expand_comp_bind₁]\n\n@[simp]\nlemma map_expand (f : R →+* S) (p : ℕ) (φ : mv_polynomial σ R) :\n  map f (expand p φ) = expand p (map f φ) :=\nby simp [expand, map_bind₁]\n\n@[simp]\nlemma rename_expand (f : σ → τ) (p : ℕ) (φ : mv_polynomial σ R) :\n  rename f (expand p φ) = expand p (rename f φ) :=\nby simp [expand, bind₁_rename, rename_bind₁]\n\n@[simp] lemma rename_comp_expand (f : σ → τ) (p : ℕ) :\n  (rename f).comp (expand p) =\n    (expand p).comp (rename f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R) :=\nby { ext1 φ, simp only [rename_expand, alg_hom.comp_apply] }\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/expand.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7527612156204777}}
{"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ölzl\n\n! This file was ported from Lean 3 source module algebra.order.group.abs\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.Abs\nimport Mathlib.Algebra.Order.Group.OrderIso\nimport Mathlib.Order.MinMax\n\n/-!\n# Absolute values in ordered groups.\n-/\n\n\nvariable {α : Type _}\n\nopen Function\n\nsection CovariantAddLe\n\nsection Neg\n\n-- see Note [lower instance priority]\n/-- `abs a` is the absolute value of `a`. -/\n@[to_additive \"`abs a` is the absolute value of `a`\"]\ninstance (priority := 100) Inv.toHasAbs [Inv α] [Sup α] : Abs α :=\n  ⟨fun a => a ⊔ a⁻¹⟩\n#align has_inv.to_has_abs Inv.toHasAbs\n#align has_neg.to_has_abs Neg.toHasAbs\n\n@[to_additive]\ntheorem abs_eq_sup_inv [Inv α] [Sup α] (a : α) : |a| = a ⊔ a⁻¹ :=\n  rfl\n#align abs_eq_sup_inv abs_eq_sup_inv\n#align abs_eq_sup_neg abs_eq_sup_neg\n\nvariable [Neg α] [LinearOrder α] {a b : α}\n\ntheorem abs_eq_max_neg : abs a = max a (-a) :=\n  rfl\n#align abs_eq_max_neg abs_eq_max_neg\n\ntheorem abs_choice (x : α) : |x| = x ∨ |x| = -x :=\n  max_choice _ _\n#align abs_choice abs_choice\n\ntheorem abs_le' : |a| ≤ b ↔ a ≤ b ∧ -a ≤ b :=\n  max_le_iff\n#align abs_le' abs_le'\n\ntheorem le_abs : a ≤ |b| ↔ a ≤ b ∨ a ≤ -b :=\n  le_max_iff\n#align le_abs le_abs\n\ntheorem le_abs_self (a : α) : a ≤ |a| :=\n  le_max_left _ _\n#align le_abs_self le_abs_self\n\ntheorem neg_le_abs_self (a : α) : -a ≤ |a| :=\n  le_max_right _ _\n#align neg_le_abs_self neg_le_abs_self\n\ntheorem lt_abs : a < |b| ↔ a < b ∨ a < -b :=\n  lt_max_iff\n#align lt_abs lt_abs\n\ntheorem abs_le_abs (h₀ : a ≤ b) (h₁ : -a ≤ b) : |a| ≤ |b| :=\n  (abs_le'.2 ⟨h₀, h₁⟩).trans (le_abs_self b)\n#align abs_le_abs abs_le_abs\n\ntheorem abs_by_cases (P : α → Prop) {a : α} (h1 : P a) (h2 : P (-a)) : P (|a|) :=\n  sup_ind _ _ h1 h2\n#align abs_by_cases abs_by_cases\n\nend Neg\n\nsection AddGroup\n\nvariable [AddGroup α] [LinearOrder α]\n\n@[simp]\ntheorem abs_neg (a : α) : |(-a)| = |a| := by rw [abs_eq_max_neg, max_comm, neg_neg, abs_eq_max_neg]\n#align abs_neg abs_neg\n\ntheorem eq_or_eq_neg_of_abs_eq {a b : α} (h : |a| = b) : a = b ∨ a = -b := by\n  simpa only [← h, eq_comm (a := |a|), neg_eq_iff_eq_neg] using abs_choice a\n#align eq_or_eq_neg_of_abs_eq eq_or_eq_neg_of_abs_eq\n\ntheorem abs_eq_abs {a b : α} : |a| = |b| ↔ a = b ∨ a = -b := by\n  refine' ⟨fun h => _, fun h => _⟩\n  · obtain rfl | rfl := eq_or_eq_neg_of_abs_eq h <;>\n      simpa only [neg_eq_iff_eq_neg (a := |b|), neg_inj, or_comm] using abs_choice b\n  · cases' h with h h <;>\n    simp [h, abs_neg]\n#align abs_eq_abs abs_eq_abs\n\ntheorem abs_sub_comm (a b : α) : |a - b| = |b - a| :=\n  calc\n    |a - b| = |(-(b - a))| := congr_arg _ (neg_sub b a).symm\n    _ = |b - a| := abs_neg (b - a)\n\n#align abs_sub_comm abs_sub_comm\n\nvariable [CovariantClass α α (· + ·) (· ≤ ·)] {a b c : α}\n\ntheorem abs_of_nonneg (h : 0 ≤ a) : |a| = a :=\n  max_eq_left <| (neg_nonpos.2 h).trans h\n#align abs_of_nonneg abs_of_nonneg\n\ntheorem abs_of_pos (h : 0 < a) : |a| = a :=\n  abs_of_nonneg h.le\n#align abs_of_pos abs_of_pos\n\ntheorem abs_of_nonpos (h : a ≤ 0) : |a| = -a :=\n  max_eq_right <| h.trans (neg_nonneg.2 h)\n#align abs_of_nonpos abs_of_nonpos\n\ntheorem abs_of_neg (h : a < 0) : |a| = -a :=\n  abs_of_nonpos h.le\n#align abs_of_neg abs_of_neg\n\ntheorem abs_le_abs_of_nonneg (ha : 0 ≤ a) (hab : a ≤ b) : |a| ≤ |b| := by\n  rwa [abs_of_nonneg ha, abs_of_nonneg (ha.trans hab)]\n#align abs_le_abs_of_nonneg abs_le_abs_of_nonneg\n\n@[simp]\ntheorem abs_zero : |0| = (0 : α) :=\n  abs_of_nonneg le_rfl\n#align abs_zero abs_zero\n\n@[simp]\ntheorem abs_pos : 0 < |a| ↔ a ≠ 0 := by\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]\n#align abs_pos abs_pos\n\ntheorem abs_pos_of_pos (h : 0 < a) : 0 < |a| :=\n  abs_pos.2 h.ne.symm\n#align abs_pos_of_pos abs_pos_of_pos\n\ntheorem abs_pos_of_neg (h : a < 0) : 0 < |a| :=\n  abs_pos.2 h.ne\n#align abs_pos_of_neg abs_pos_of_neg\n\ntheorem neg_abs_le_self (a : α) : -|a| ≤ a := by\n  cases' le_total 0 a with h h\n  · calc\n      -|a| = -a := congr_arg Neg.neg (abs_of_nonneg h)\n      _ ≤ 0 := neg_nonpos.mpr h\n      _ ≤ a := h\n\n  · calc\n      -|a| = - -a := congr_arg Neg.neg (abs_of_nonpos h)\n      _ ≤ a := (neg_neg a).le\n\n#align neg_abs_le_self neg_abs_le_self\n\ntheorem add_abs_nonneg (a : α) : 0 ≤ a + |a| := by\n  rw [← add_right_neg a]\n  apply add_le_add_left\n  exact neg_le_abs_self a\n#align add_abs_nonneg add_abs_nonneg\n\ntheorem neg_abs_le_neg (a : α) : -|a| ≤ -a := by simpa using neg_abs_le_self (-a)\n#align neg_abs_le_neg neg_abs_le_neg\n\n@[simp]\ntheorem abs_nonneg (a : α) : 0 ≤ |a| :=\n  (le_total 0 a).elim (fun h => h.trans (le_abs_self a)) fun h =>\n    (neg_nonneg.2 h).trans <| neg_le_abs_self a\n#align abs_nonneg abs_nonneg\n\n@[simp]\ntheorem abs_abs (a : α) : |(|a|)| = |a| :=\n  abs_of_nonneg <| abs_nonneg a\n#align abs_abs abs_abs\n\n@[simp]\ntheorem abs_eq_zero : |a| = 0 ↔ a = 0 :=\n  Decidable.not_iff_not.1 <| ne_comm.trans <| (abs_nonneg a).lt_iff_ne.symm.trans abs_pos\n#align abs_eq_zero abs_eq_zero\n\n@[simp]\ntheorem abs_nonpos_iff {a : α} : |a| ≤ 0 ↔ a = 0 :=\n  (abs_nonneg a).le_iff_eq.trans abs_eq_zero\n#align abs_nonpos_iff abs_nonpos_iff\n\nvariable [CovariantClass α α (swap (· + ·)) (· ≤ ·)]\n\ntheorem abs_le_abs_of_nonpos (ha : a ≤ 0) (hab : b ≤ a) : |a| ≤ |b| := by\n  rw [abs_of_nonpos ha, abs_of_nonpos (hab.trans ha)]\n  exact neg_le_neg_iff.mpr hab\n#align abs_le_abs_of_nonpos abs_le_abs_of_nonpos\n\ntheorem abs_lt : |a| < b ↔ -b < a ∧ a < b :=\n  max_lt_iff.trans <| and_comm.trans <| by rw [neg_lt]\n#align abs_lt abs_lt\n\ntheorem neg_lt_of_abs_lt (h : |a| < b) : -b < a :=\n  (abs_lt.mp h).1\n#align neg_lt_of_abs_lt neg_lt_of_abs_lt\n\ntheorem lt_of_abs_lt (h : |a| < b) : a < b :=\n  (abs_lt.mp h).2\n#align lt_of_abs_lt lt_of_abs_lt\n\ntheorem max_sub_min_eq_abs' (a b : α) : max a b - min a b = |a - b| := by\n  cases' le_total a b with ab ba\n  · rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub]\n    rwa [sub_nonpos]\n  · rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg]\n    rwa [sub_nonneg]\n#align max_sub_min_eq_abs' max_sub_min_eq_abs'\n\ntheorem max_sub_min_eq_abs (a b : α) : max a b - min a b = |b - a| := by\n  rw [abs_sub_comm]\n  exact max_sub_min_eq_abs' _ _\n#align max_sub_min_eq_abs max_sub_min_eq_abs\n\nend AddGroup\n\nend CovariantAddLe\n\nsection LinearOrderedAddCommGroup\n\nvariable [LinearOrderedAddCommGroup α] {a b c d : α}\n\n-- Porting note:\n-- Lean can perfectly well find this instance,\n-- but in the rewrites below it is going looking for it without having fixed `α`.\nexample : CovariantClass α α (swap fun x y ↦ x + y) fun x y ↦ x ≤ y := inferInstance\n\ntheorem abs_le : |a| ≤ b ↔ -b ≤ a ∧ a ≤ b := by rw [abs_le', and_comm, @neg_le α]\n#align abs_le abs_le\n\ntheorem le_abs' : a ≤ |b| ↔ b ≤ -a ∨ a ≤ b := by rw [le_abs, or_comm, @le_neg α]\n#align le_abs' le_abs'\n\ntheorem neg_le_of_abs_le (h : |a| ≤ b) : -b ≤ a :=\n  (abs_le.mp h).1\n#align neg_le_of_abs_le neg_le_of_abs_le\n\ntheorem le_of_abs_le (h : |a| ≤ b) : a ≤ b :=\n  (abs_le.mp h).2\n#align le_of_abs_le le_of_abs_le\n\n@[to_additive]\ntheorem apply_abs_le_mul_of_one_le' {β : Type _} [MulOneClass β] [Preorder β]\n    [CovariantClass β β (· * ·) (· ≤ ·)] [CovariantClass β β (swap (· * ·)) (· ≤ ·)] {f : α → β}\n    {a : α} (h₁ : 1 ≤ f a) (h₂ : 1 ≤ f (-a)) : f (|a|) ≤ f a * f (-a) :=\n  (le_total a 0).rec (fun ha => (abs_of_nonpos ha).symm ▸ le_mul_of_one_le_left' h₁) fun ha =>\n    (abs_of_nonneg ha).symm ▸ le_mul_of_one_le_right' h₂\n#align apply_abs_le_mul_of_one_le' apply_abs_le_mul_of_one_le'\n#align apply_abs_le_add_of_nonneg' apply_abs_le_add_of_nonneg'\n\n@[to_additive]\ntheorem apply_abs_le_mul_of_one_le {β : Type _} [MulOneClass β] [Preorder β]\n    [CovariantClass β β (· * ·) (· ≤ ·)] [CovariantClass β β (swap (· * ·)) (· ≤ ·)] {f : α → β}\n    (h : ∀ x, 1 ≤ f x) (a : α) : f (|a|) ≤ f a * f (-a) :=\n  apply_abs_le_mul_of_one_le' (h _) (h _)\n#align apply_abs_le_mul_of_one_le apply_abs_le_mul_of_one_le\n#align apply_abs_le_add_of_nonneg apply_abs_le_add_of_nonneg\n\n/-- The **triangle inequality** in `LinearOrderedAddCommGroup`s. -/\ntheorem abs_add (a b : α) : |a + b| ≤ |a| + |b| :=\n  abs_le.2\n    ⟨(neg_add (|a|) (|b|)).symm ▸\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 _)⟩\n#align abs_add abs_add\n\ntheorem abs_add' (a b : α) : |a| ≤ |b| + |b + a| := by simpa using abs_add (-b) (b + a)\n#align abs_add' abs_add'\n\ntheorem abs_sub (a b : α) : |a - b| ≤ |a| + |b| := by\n  rw [sub_eq_add_neg, ← abs_neg b]\n  exact abs_add a _\n#align abs_sub abs_sub\n\ntheorem abs_sub_le_iff : |a - b| ≤ c ↔ a - b ≤ c ∧ b - a ≤ c := by\n  rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add']\n#align abs_sub_le_iff abs_sub_le_iff\n\ntheorem abs_sub_lt_iff : |a - b| < c ↔ a - b < c ∧ b - a < c := by\n  rw [@abs_lt α, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add']\n#align abs_sub_lt_iff abs_sub_lt_iff\n\ntheorem sub_le_of_abs_sub_le_left (h : |a - b| ≤ c) : b - c ≤ a :=\n  sub_le_comm.1 <| (abs_sub_le_iff.1 h).2\n#align sub_le_of_abs_sub_le_left sub_le_of_abs_sub_le_left\n\ntheorem sub_le_of_abs_sub_le_right (h : |a - b| ≤ c) : a - c ≤ b :=\n  sub_le_of_abs_sub_le_left (abs_sub_comm a b ▸ h)\n#align sub_le_of_abs_sub_le_right sub_le_of_abs_sub_le_right\n\ntheorem sub_lt_of_abs_sub_lt_left (h : |a - b| < c) : b - c < a :=\n  sub_lt_comm.1 <| (abs_sub_lt_iff.1 h).2\n#align sub_lt_of_abs_sub_lt_left sub_lt_of_abs_sub_lt_left\n\ntheorem sub_lt_of_abs_sub_lt_right (h : |a - b| < c) : a - c < b :=\n  sub_lt_of_abs_sub_lt_left (abs_sub_comm a b ▸ h)\n#align sub_lt_of_abs_sub_lt_right sub_lt_of_abs_sub_lt_right\n\ntheorem abs_sub_abs_le_abs_sub (a b : α) : |a| - |b| ≤ |a - b| :=\n  (@sub_le_iff_le_add α ..).2 <|\n    calc\n      |a| = |a - b + b| := by rw [sub_add_cancel]\n      _ ≤ |a - b| + |b| := abs_add _ _\n\n#align abs_sub_abs_le_abs_sub abs_sub_abs_le_abs_sub\n\ntheorem abs_abs_sub_abs_le_abs_sub (a b : α) : |(|a| - |b|)| ≤ |a - b| :=\n  abs_sub_le_iff.2\n    ⟨abs_sub_abs_le_abs_sub _ _, by rw [abs_sub_comm]; apply abs_sub_abs_le_abs_sub⟩\n#align abs_abs_sub_abs_le_abs_sub abs_abs_sub_abs_le_abs_sub\n\ntheorem abs_eq (hb : 0 ≤ b) : |a| = b ↔ a = b ∨ a = -b := by\n  refine' ⟨eq_or_eq_neg_of_abs_eq, _⟩\n  rintro (rfl | rfl) <;> simp only [abs_neg, abs_of_nonneg hb]\n#align abs_eq abs_eq\n\ntheorem abs_le_max_abs_abs (hab : a ≤ b) (hbc : b ≤ c) : |b| ≤ max (|a|) (|c|) :=\n  abs_le'.2\n    ⟨by simp [hbc.trans (le_abs_self c)], by\n      simp [((@neg_le_neg_iff α ..).mpr hab).trans (neg_le_abs_self a)]⟩\n#align abs_le_max_abs_abs abs_le_max_abs_abs\n\ntheorem min_abs_abs_le_abs_max : min (|a|) (|b|) ≤ |max a b| :=\n  (le_total a b).elim (fun h => (min_le_right _ _).trans_eq <| congr_arg _ (max_eq_right h).symm)\n    fun h => (min_le_left _ _).trans_eq <| congr_arg _ (max_eq_left h).symm\n#align min_abs_abs_le_abs_max min_abs_abs_le_abs_max\n\ntheorem min_abs_abs_le_abs_min : min (|a|) (|b|) ≤ |min a b| :=\n  (le_total a b).elim (fun h => (min_le_left _ _).trans_eq <| congr_arg _ (min_eq_left h).symm)\n    fun h => (min_le_right _ _).trans_eq <| congr_arg _ (min_eq_right h).symm\n#align min_abs_abs_le_abs_min min_abs_abs_le_abs_min\n\ntheorem abs_max_le_max_abs_abs : |max a b| ≤ max (|a|) (|b|) :=\n  (le_total a b).elim (fun h => (congr_arg _ <| max_eq_right h).trans_le <| le_max_right _ _)\n    fun h => (congr_arg _ <| max_eq_left h).trans_le <| le_max_left _ _\n#align abs_max_le_max_abs_abs abs_max_le_max_abs_abs\n\ntheorem abs_min_le_max_abs_abs : |min a b| ≤ max (|a|) (|b|) :=\n  (le_total a b).elim (fun h => (congr_arg _ <| min_eq_left h).trans_le <| le_max_left _ _) fun h =>\n    (congr_arg _ <| min_eq_right h).trans_le <| le_max_right _ _\n#align abs_min_le_max_abs_abs abs_min_le_max_abs_abs\n\ntheorem eq_of_abs_sub_eq_zero {a b : α} (h : |a - b| = 0) : a = b :=\n  sub_eq_zero.1 <| abs_eq_zero.1 h\n#align eq_of_abs_sub_eq_zero eq_of_abs_sub_eq_zero\n\ntheorem abs_sub_le (a b c : α) : |a - c| ≤ |a - b| + |b - c| :=\n  calc\n    |a - c| = |a - b + (b - c)| := by rw [sub_add_sub_cancel]\n    _ ≤ |a - b| + |b - c| := abs_add _ _\n\n#align abs_sub_le abs_sub_le\n\ntheorem abs_add_three (a b c : α) : |a + b + c| ≤ |a| + |b| + |c| :=\n  (abs_add _ _).trans (add_le_add_right (abs_add _ _) _)\n#align abs_add_three abs_add_three\n\ntheorem dist_bdd_within_interval {a b lb ub : α} (hal : lb ≤ a) (hau : a ≤ ub) (hbl : lb ≤ b)\n    (hbu : b ≤ ub) : |a - b| ≤ ub - lb :=\n  abs_sub_le_iff.2 ⟨sub_le_sub hau hbl, sub_le_sub hbu hal⟩\n#align dist_bdd_within_interval dist_bdd_within_interval\n\ntheorem eq_of_abs_sub_nonpos (h : |a - b| ≤ 0) : a = b :=\n  eq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))\n#align eq_of_abs_sub_nonpos eq_of_abs_sub_nonpos\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/Abs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7527372693017169}}
{"text": "import\n  ring_theory.mv_polynomial.homogeneous\n  ring_theory.coprime.basic\n  data.mv_polynomial.comm_ring\n  data.nat.totient\n  field_theory.finite.basic\n  data.zmod.basic\n\n/-! # IMO 2017 N7 (P6) -/\n\nnamespace IMOSL\nnamespace IMO2017N7\n\nopen mv_polynomial finset\n\n\n\nsection extra\n\nprivate lemma int_is_coprime_mul_eq {a b c d : ℤ}\n  (h : is_coprime a c) (h0 : is_coprime b d) (h1 : a * d = b * c) :\n  (a = b ∧ c = d) ∨ (a = -b ∧ c = -d) :=\nbegin\n  rcases eq_or_ne a 0 with rfl | ha,\n  { rw [zero_mul, zero_eq_mul, or_comm] at h1,\n    rcases h with ⟨u, v, h⟩,\n    rcases h1 with rfl | rfl,\n    rw [← add_mul, mul_zero] at h,\n    exfalso; exact zero_ne_one h,\n    rcases h0 with ⟨s, t, h0⟩,\n    rw [mul_zero, zero_add] at h h0,\n    replace h : c ∣ 1 := ⟨v, by rw [mul_comm, h]⟩,\n    replace h0 : d ∣ 1 := ⟨t, by rw [mul_comm, h0]⟩,\n    rw [← is_unit_iff_dvd_one, int.is_unit_iff] at h h0,\n    rcases h with rfl | rfl; rcases h0 with rfl | rfl; norm_num },\n  { have h2 : a.nat_abs = b.nat_abs :=\n    begin\n      apply nat.dvd_antisymm; rw int.nat_abs_dvd_iff_dvd,\n      exact is_coprime.dvd_of_dvd_mul_right h ⟨d, h1.symm⟩,\n      exact is_coprime.dvd_of_dvd_mul_right h0 ⟨c, h1⟩\n    end,\n    rw int.nat_abs_eq_nat_abs_iff at h2,\n    rcases h2 with rfl | rfl,\n    left; refine ⟨rfl, _⟩,\n    rwa [eq_comm, mul_right_inj' ha] at h1,\n    right; refine ⟨rfl, _⟩,\n    rw neg_ne_zero at ha,\n    rwa [neg_mul_comm, eq_comm, mul_right_inj' ha] at h1 }\nend\n\nprivate lemma int_exists_pow_modeq_one_of_coprime {a b : ℤ} (h : is_coprime a b) :\n  ∃ K : ℕ, 0 < K ∧ a ^ K ≡ 1 [ZMOD b] :=\nbegin\n  rcases eq_or_ne b 0 with rfl | h0,\n  rw is_coprime_zero_right at h; exact ⟨2, two_pos, by rw int.is_unit_sq h⟩,\n  replace h0 := int.nat_abs_pos_of_ne_zero h0,\n  refine ⟨b.nat_abs.totient, nat.totient_pos h0, int.modeq.symm _⟩,\n  rw [int.modeq_iff_dvd, ← int.nat_abs_dvd],\n  rw int.coprime_iff_nat_coprime at h,\n  generalize_hyp : b.nat_abs = n at h h0 ⊢; clear b,\n  rw [← nat.succ_le_iff, le_iff_eq_or_lt] at h0,\n  rcases h0 with rfl | h0,\n  rw nat.cast_one; exact one_dvd _,\n  rw [← nat.succ_le_iff, le_iff_eq_or_lt] at h0,\n  rcases h0 with rfl | h0,\n  { rw [nat.coprime_comm, nat.prime.coprime_iff_not_dvd nat.prime_two] at h,\n    rw [nat.cast_succ, nat.cast_one, nat.totient_two, pow_one, ← bit0],\n    apply int.dvd_sub_of_mod_eq,\n    rwa [← int.not_even_iff, ← int.nat_abs_even, nat.even_iff, ← nat.dvd_iff_mod_eq_zero] },\n  replace h := nat.modeq.pow_totient h,\n  obtain ⟨c, h1⟩ := nat.totient_even h0,\n  rw [h1, ← two_mul] at h ⊢,\n  rw [pow_mul, ← int.nat_abs_sq, ← pow_mul, ← nat.cast_pow],\n  change (1 : ℤ) with ((1 : ℕ) : ℤ),\n  rw [← int.modeq_iff_dvd, int.coe_nat_modeq_iff],\n  exact nat.modeq.symm h\nend\n\nprivate lemma int_coprime_iff_not_exists_prime_dvd (a b : ℤ) :\n  is_coprime a b ↔ ∀ p : ℕ, p.prime → ¬((p : ℤ) ∣ a ∧ (p : ℤ) ∣ b) :=\nbegin\n  conv_rhs { find (¬_) { rw [← int.nat_abs_dvd_iff_dvd, int.nat_abs_of_nat,\n    ← int.nat_abs_dvd_iff_dvd, int.nat_abs_of_nat, ← nat.dvd_gcd_iff] } },\n  rw [← nat.eq_one_iff_not_exists_prime_dvd, int.coprime_iff_nat_coprime]\nend\n\n\n\nsection is_homogeneous\n\nvariables {σ R : Type*} [comm_ring R]\n\nprivate lemma homogeneous_smul_eval (f : σ → R) (r : R) {φ : mv_polynomial σ R}\n  {n : ℕ} (h : φ.is_homogeneous n) : eval (r • f) φ = r ^ n * eval f φ :=\nbegin\n  rw [eval_eq, eval_eq, mul_sum],\n  refine finset.sum_congr rfl (λ d hd, _),\n  simp only [smul_eq_mul, pi.smul_apply, mul_pow],\n  rw [mul_left_comm, prod_mul_distrib, prod_pow_eq_pow_sum]; congr,\n  exact h (mem_support_iff.mp hd)\nend\n\nprivate lemma homogeneous_smul_eval₂ {S : Type*} [comm_ring S] (ρ : R →+* S)\n  (f : σ → S) (r : S) {φ : mv_polynomial σ R} {n : ℕ} (h : φ.is_homogeneous n) :\n  eval₂ ρ (r • f) φ = r ^ n * eval₂ ρ f φ :=\nbegin\n  rw [eval₂_eq, eval₂_eq, mul_sum],\n  refine finset.sum_congr rfl (λ d hd, _),\n  simp only [smul_eq_mul, pi.smul_apply, mul_pow],\n  rw [mul_left_comm, prod_mul_distrib, prod_pow_eq_pow_sum]; congr,\n  exact h (mem_support_iff.mp hd)\nend\n\nprivate lemma homogeneous_pow (k : ℕ) {φ : mv_polynomial σ R} {n : ℕ} (h : φ.is_homogeneous n) :\n  (φ ^ k).is_homogeneous (k * n) :=\nbegin\n  induction k with k k_ih,\n  rw [pow_zero, zero_mul]; exact is_homogeneous_one σ R,\n  rw [pow_succ', nat.succ_mul]; exact is_homogeneous.mul k_ih h\nend\n\nend is_homogeneous\n\n\n\nsection CCX\n\nsection comm_ring\n\nvariables {R : Type*} [comm_ring R]\n\nprivate noncomputable def CCX (u v : R) : mv_polynomial bool R := C u * X tt + C v * X ff\n\nprivate lemma CCX_is_homogeneous_one (u v : R) : (CCX u v).is_homogeneous 1 :=\nbegin\n  refine is_homogeneous.add _ _; rw ← zero_add 1,\n  all_goals { exact is_homogeneous.mul (is_homogeneous_C bool _) (is_homogeneous_X R _) }\nend\n\nprivate lemma CCX_eval (u v : R) (c : bool → R) : eval c (CCX u v) = u * c tt + v * c ff :=\n  by simp only [CCX, map_add, map_mul, eval_C, eval_X]\n\nprivate lemma CCX_prod_is_homogeneous_card [decidable_eq R] (xy : finset (bool → R)) :\n  (xy.prod (λ p, CCX (p ff) (-p tt))).is_homogeneous xy.card :=\nbegin\n  induction xy using finset.induction_on with c xy h h0,\n  rw [prod_empty, card_empty]; exact is_homogeneous_one bool R,\n  rw [prod_insert h, card_insert_of_not_mem h, add_comm],\n  exact is_homogeneous.mul (CCX_is_homogeneous_one _ _) h0\nend\n\nprivate lemma CCX_prod_eval_eq_zero_of_mem [decidable_eq R] [is_domain R]\n  {xy : finset (bool → R)} {p : bool → R} (h : p ∈ xy) :\n  eval p (xy.prod (λ p, CCX (p ff) (-p tt))) = 0 :=\nbegin\n  rw [eval_prod, prod_eq_zero_iff],\n  refine ⟨p, h, _⟩,\n  rw [CCX_eval, neg_mul, mul_comm, add_neg_self]\nend\n\nend comm_ring\n\n\n\nsection field\n\nvariables {F : Type*} [field F]\n\nprivate lemma CCX_eval_eq_zero_iff_exists_eq_smul (p : bool → F) (u v : F) :\n  eval p (CCX u v) = 0 ↔ p = 0 ∨ ∃ α : F, u = α * p ff ∧ v = -α * p tt :=\nbegin\n  rw [CCX_eval, add_eq_zero_iff_eq_neg, ← neg_mul],\n  cases eq_or_ne (p tt) 0 with h h,\n  { rw [h, mul_zero, zero_eq_mul],\n    cases eq_or_ne (p ff) 0 with h0 h0,\n    rw [h0, eq_self_iff_true, or_true, true_iff],\n    left; ext b; cases b; assumption,\n    rw [iff_false_intro h0, or_false, neg_eq_zero, or_iff_right],\n    work_on_goal 2 { rintros rfl; exact h0 rfl },\n    refine ⟨λ h1, ⟨u / p ff, (div_mul_cancel _ h0).symm, by rw [mul_zero, h1]⟩, λ h1, _⟩,\n    rcases h1 with ⟨α, rfl, rfl⟩,\n    rw mul_zero },\n  { rw or_iff_right,\n    work_on_goal 2 { rintros rfl; exact h rfl },\n    refine ⟨λ h1, ⟨-v / p tt, _, _⟩, λ h1, _⟩,\n    rw [← mul_div_right_comm, ← h1, mul_div_cancel _ h],\n    rw [neg_div, neg_neg, div_mul_cancel _ h],\n    rcases h1 with ⟨α, rfl, rfl⟩,\n    rw [neg_mul α, neg_neg, mul_right_comm] }\nend\n\nend field\n\nend CCX\n\n\n\nsection zmod\n\nprivate lemma CCX_eval_zmod_cast (p : ℕ) (u v : ℤ) (c : bool → ℤ) :\n  (eval c (CCX u v) : zmod p) = eval (coe ∘ c) (CCX (u : zmod p) v) :=\n  by simp only [CCX_eval, function.comp_app, int.cast_add, int.cast_mul]\n\nend zmod\n\nend extra\n\n\n\n/-- Final solution -/\ntheorem final_solution {xy : finset (bool → ℤ)}\n  (h : ∀ p : bool → ℤ, p ∈ xy → is_coprime (p tt) (p ff)) :\n  ∃ (φ : mv_polynomial bool ℤ) (d : ℕ),\n    0 < d ∧ is_homogeneous φ d ∧ ∀ p : bool → ℤ, p ∈ xy → mv_polynomial.eval p φ = 1 :=\nbegin\n\n  -- First we solve the case xy = ∅ and the inductive base case |xy| = 1.\n  induction xy using finset.induction_on with c xy hcxy xy_ih,\n  exact ⟨0, 1, one_pos, is_homogeneous_zero bool ℤ 1, λ p h0, by exfalso; exact h0⟩,\n  rcases xy.eq_empty_or_nonempty with rfl | hxy,\n  rcases h c (mem_insert_self c ∅) with ⟨u, v, h0⟩,\n  refine ⟨CCX u v, 1, one_pos, CCX_is_homogeneous_one _ _, λ p h1, _⟩,\n  rw [mem_insert, or_iff_left (not_mem_empty p)] at h1,\n  rw [CCX_eval, h1, h0],\n  rw ← card_pos at hxy,\n\n  /-\n  Now we focus on the induction step.\n  Set ρ = ∏ [p ∈ xy] (λ p, p_f X - p_t Y). \n  The desired polynomial is φ^K + Mρ (uc_t + vc_f)^L for some K L : ℕ and M : ℤ.\n  The sufficient properties for its construction is Kd = |xy| + L and ρ(c) ∣ φ(c)^K - 1.\n  Simplifying, it suffices to prove that there exists K such that |xy| ≤ Kd and ρ(c) ∣ φ(c)^K - 1.\n  -/\n  simp only [mem_insert, forall_eq_or_imp] at h,\n  cases h with hc_cop hxy_cop,\n  replace xy_ih := xy_ih hxy_cop,\n  rcases xy_ih with ⟨φ, d, hd0, hd1, h0⟩,\n  let ρ := xy.prod (λ p, CCX (p ff) (-p tt)),\n  suffices : ∃ K : ℕ, xy.card ≤ K * d ∧ eval c ρ ∣ (eval c φ) ^ K - 1,\n  { rcases this with ⟨K, h1, M, h2⟩,\n    rcases hc_cop with ⟨u, v, hc_cop⟩,\n    rw le_iff_exists_add at h1; cases h1 with L h1,\n    refine ⟨φ ^ K + C (-M) * ρ * (CCX u v) ^ L, xy.card + L, _, is_homogeneous.add _ _, λ p hp, _⟩,\n    exact lt_of_lt_of_le hxy (self_le_add_right _ _),\n    rw ← h1; exact homogeneous_pow K hd1,\n    { rw ← nat.zero_add xy.card,\n      refine is_homogeneous.mul (is_homogeneous.mul (is_homogeneous_C bool (-M)) _) _,\n      exact CCX_prod_is_homogeneous_card xy,\n      convert homogeneous_pow L (CCX_is_homogeneous_one u v); rw mul_one },\n    { simp only [map_add, map_mul, map_pow, C_neg, map_neg, neg_mul, eval_C],\n      rw mem_insert at hp; rcases hp with rfl | h3,\n      rw [CCX_eval, hc_cop, one_pow, mul_one, mul_comm, ← h2, neg_sub, add_comm, sub_add_cancel],\n      rw [h0 p h3, one_pow, CCX_prod_eval_eq_zero_of_mem h3,\n          mul_zero, zero_mul, neg_zero, add_zero] } },\n\n  -- One can reduce one step further: only need to show that φ(c) and ρ(c) are coprime.\n  suffices : is_coprime (eval c φ) (eval c ρ),\n  { rcases int_exists_pow_modeq_one_of_coprime this with ⟨K, h1, h2⟩,\n    refine ⟨xy.card * K, _, _⟩,\n    rw mul_assoc; exact nat.le_mul_of_pos_right (mul_pos h1 hd0),\n    rw [mul_comm, pow_mul, ← int.modeq_iff_dvd],\n    convert int.modeq.symm (int.modeq.pow xy.card h2); rw one_pow },\n\n  -- Next, reduce to coprimality with respect to each p ∈ xy, then chore.\n  rw eval_prod; refine is_coprime.prod_right (λ p hp, _),\n  replace h0 := h0 p hp,\n  replace hxy_cop := hxy_cop p hp,\n  clear hcxy hxy ρ hp hd0 xy,\n\n  -- Now prove the coprimality result.\n  rw int_coprime_iff_not_exists_prime_dvd at hc_cop hxy_cop ⊢,\n  intros q hq h1; replace hxy_cop := hxy_cop q hq; replace hc_cop := hc_cop q hq,\n  repeat { rw ← zmod.int_coe_zmod_eq_zero_iff_dvd at hc_cop hxy_cop h1 },\n  haveI : fact q.prime := ⟨hq⟩,\n  cases h1 with h1 h2,\n  rw [CCX_eval_zmod_cast, CCX_eval_eq_zero_iff_exists_eq_smul] at h2,\n  rcases h2 with h2 | ⟨α, h2⟩,\n  exact hc_cop ⟨congr_fun h2 tt, congr_fun h2 ff⟩,\n  revert h0; suffices : (eval p φ : zmod q) = 0,\n  { intros h0,\n    rw [zmod.int_coe_zmod_eq_zero_iff_dvd, h0] at this,\n    replace this := int.eq_one_of_dvd_one q.cast_nonneg this,\n    rw nat.cast_eq_one at this,\n    rw this at hq; exact nat.not_prime_one hq },\n  clear hc_cop hxy_cop,\n  rw [eval, ← int.coe_cast_ring_hom, map_eval₂_hom,\n      coe_eval₂_hom, ring_hom_comp_triple.comp_eq] at h1 ⊢,\n  replace h2 : (λ i, int.cast_ring_hom (zmod q) (p i))\n    = α • (λ i, int.cast_ring_hom (zmod q) (c i)) :=\n  begin\n    cases h2 with h2 h3,\n    rw [neg_mul, int.cast_neg, neg_inj] at h3,\n    ext b; rw [eq_int_cast, pi.smul_apply, smul_eq_mul, eq_int_cast],\n    cases b; assumption\n  end,\n  rw [h2, homogeneous_smul_eval₂ _ _ _ hd1, h1, mul_zero]\nend\n\nend IMO2017N7\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/IMO2017/N7/N7.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731765, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7526843134566482}}
{"text": "/-\nCopyright (c) 2019 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Mario Carneiro\n\n! This file was ported from Lean 3 source module data.rat.sqrt\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.Rat.Order\nimport Mathbin.Data.Rat.Lemmas\nimport Mathbin.Data.Int.Sqrt\n\n/-!\n# Square root on rational numbers\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 square root function on rational numbers `rat.sqrt`\nand proves several theorems about it.\n\n-/\n\n\nnamespace Rat\n\n#print Rat.sqrt /-\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]\ndef sqrt (q : ℚ) : ℚ :=\n  Rat.mk (Int.sqrt q.num) (Nat.sqrt q.den)\n#align rat.sqrt Rat.sqrt\n-/\n\n/- warning: rat.sqrt_eq -> Rat.sqrt_eq is a dubious translation:\nlean 3 declaration is\n  forall (q : Rat), Eq.{1} Rat (Rat.sqrt (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.hasMul) q q)) (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.hasNeg Rat.hasSup) q)\nbut is expected to have type\n  forall (q : Rat), Eq.{1} Rat (Rat.sqrt (HMul.hMul.{0, 0, 0} Rat Rat Rat (instHMul.{0} Rat Rat.instMulRat) q q)) (Abs.abs.{0} Rat (Neg.toHasAbs.{0} Rat Rat.instNegRat Rat.instSupRat) q)\nCase conversion may be inaccurate. Consider using '#align rat.sqrt_eq Rat.sqrt_eqₓ'. -/\ntheorem sqrt_eq (q : ℚ) : Rat.sqrt (q * q) = |q| := by\n  rw [sqrt, mul_self_num, mul_self_denom, Int.sqrt_eq, Nat.sqrt_eq, abs_def]\n#align rat.sqrt_eq Rat.sqrt_eq\n\n#print Rat.exists_mul_self /-\ntheorem exists_mul_self (x : ℚ) : (∃ q, q * q = x) ↔ Rat.sqrt x * Rat.sqrt x = x :=\n  ⟨fun ⟨n, hn⟩ => by rw [← hn, sqrt_eq, abs_mul_abs_self], fun h => ⟨Rat.sqrt x, h⟩⟩\n#align rat.exists_mul_self Rat.exists_mul_self\n-/\n\n/- warning: rat.sqrt_nonneg -> Rat.sqrt_nonneg is a dubious translation:\nlean 3 declaration is\n  forall (q : Rat), LE.le.{0} Rat Rat.hasLe (OfNat.ofNat.{0} Rat 0 (OfNat.mk.{0} Rat 0 (Zero.zero.{0} Rat Rat.hasZero))) (Rat.sqrt q)\nbut is expected to have type\n  forall (q : Rat), LE.le.{0} Rat Rat.instLERat (OfNat.ofNat.{0} Rat 0 (Rat.instOfNatRat 0)) (Rat.sqrt q)\nCase conversion may be inaccurate. Consider using '#align rat.sqrt_nonneg Rat.sqrt_nonnegₓ'. -/\ntheorem sqrt_nonneg (q : ℚ) : 0 ≤ Rat.sqrt q :=\n  nonneg_iff_zero_le.1 <|\n    (divInt_nonneg _ <|\n          Int.coe_nat_pos.2 <|\n            Nat.pos_of_ne_zero fun H => pos_iff_ne_zero.1 q.Pos <| Nat.sqrt_eq_zero.1 H).2 <|\n      Int.coe_nat_nonneg _\n#align rat.sqrt_nonneg Rat.sqrt_nonneg\n\nend Rat\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/Sqrt.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7526127255092945}}
{"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\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\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+ `σ : Type*` (indexing the variables)\n\n+ `R : Type*` `[comm_semiring R]` (the coefficients)\n\n-/\n\nnamespace mv_polynomial\nvariables {σ : Type*} {τ : Type*} {υ : Type*} {R : Type*} [comm_semiring R]\n\n/--\nGiven an algebra hom `f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R`\nand a variable evaluation `v : τ → R`,\n`comap f v` produces a variable evaluation `σ → R`.\n-/\nnoncomputable def comap (f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R) :\n  (τ → R) → (σ → R) :=\nλ x i, aeval x (f (X i))\n\n@[simp] lemma comap_apply (f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R) (x : τ → R) (i : σ) :\n  comap f x i = aeval x (f (X i)) := rfl\n\n@[simp] lemma comap_id_apply (x : σ → R) : comap (alg_hom.id R (mv_polynomial σ R)) x = x :=\nby { funext i, simp only [comap, alg_hom.id_apply, id.def, aeval_X], }\n\nvariables (σ R)\n\nlemma comap_id : comap (alg_hom.id R (mv_polynomial σ R)) = id :=\nby { funext x, exact comap_id_apply x }\n\nvariables {σ R}\n\nlemma comap_comp_apply (f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R)\n  (g : mv_polynomial τ R →ₐ[R] mv_polynomial υ R) (x : υ → R) :\n  comap (g.comp f) x = comap f (comap g x) :=\nbegin\n  funext i,\n  transitivity (aeval x (aeval (λ i, g (X i)) (f (X i)))),\n  { apply eval₂_hom_congr rfl rfl,\n    rw alg_hom.comp_apply,\n    suffices : g = aeval (λ i, g (X i)), { rw ← this, },\n    exact aeval_unique g },\n  { simp only [comap, aeval_eq_eval₂_hom, map_eval₂_hom, alg_hom.comp_apply],\n    refine eval₂_hom_congr _ rfl rfl,\n    ext r, apply aeval_C },\nend\n\nlemma comap_comp (f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R)\n  (g : mv_polynomial τ R →ₐ[R] mv_polynomial υ R) :\n  comap (g.comp f) = comap f ∘ comap g :=\nby { funext x, exact comap_comp_apply _ _ _ }\n\nlemma comap_eq_id_of_eq_id (f : mv_polynomial σ R →ₐ[R] mv_polynomial σ R)\n  (hf : ∀ φ, f φ = φ) (x : σ → R) :\n  comap f x = x :=\nby { convert comap_id_apply x, ext1 φ, rw [hf, alg_hom.id_apply] }\n\nlemma comap_rename (f : σ → τ) (x : τ → R) : comap (rename f) x = x ∘ 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 σ R ≃ₐ[R] mv_polynomial τ R) :\n  (τ → R) ≃ (σ → R) :=\n{ to_fun    := comap f,\n  inv_fun   := comap f.symm,\n  left_inv  := by { intro x, rw [← 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 [← 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 σ R ≃ₐ[R] mv_polynomial τ R) :\n  (comap_equiv f : (τ → R) → (σ → R)) = comap f := rfl\n\n@[simp] lemma comap_equiv_symm_coe (f : mv_polynomial σ R ≃ₐ[R] mv_polynomial τ R) :\n  ((comap_equiv f).symm : (σ → R) → (τ → R)) = comap f.symm := rfl\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/comap.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8397339636614178, "lm_q1q2_score": 0.7526127226525651}}
{"text": "/-\nCopyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nMetric spaces.\n\nAuthors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel\n\nMany definitions and theorems expected on metric spaces are already introduced on uniform spaces and\ntopological spaces. For example:\n  open and closed sets, compactness, completeness, continuity and uniform continuity\n-/\nimport data.real.nnreal topology.metric_space.emetric_space topology.algebra.ordered\nopen lattice set filter classical topological_space\nnoncomputable theory\n\nlocal notation `𝓤` := uniformity\n\nuniverses u v w\nvariables {α : Type u} {β : Type v} {γ : Type w}\n\n/-- Construct a uniform structure from a distance function and metric space axioms -/\ndef uniform_space_of_dist\n  (dist : α → α → ℝ)\n  (dist_self : ∀ x : α, dist x x = 0)\n  (dist_comm : ∀ x y : α, dist x y = dist y x)\n  (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=\nuniform_space.of_core {\n  uniformity := (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}),\n  refl       := le_infi $ assume ε, le_infi $\n    by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},\n  comp       := le_infi $ assume ε, le_infi $ assume h, lift'_le\n    (mem_infi_sets (ε / 2) $ mem_infi_sets (div_pos_of_pos_of_pos h two_pos) (subset.refl _)) $\n    have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,\n      from assume a b c hac hcb,\n      calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _\n        ... < ε / 2 + ε / 2 : add_lt_add hac hcb\n        ... = ε : by rw [div_add_div_same, add_self_div_two],\n    by simpa [comp_rel],\n  symm       := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,\n    tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [dist_comm] }\n\n/-- The distance function (given an ambient metric space on `α`), which returns\n  a nonnegative real number `dist x y` given `x y : α`. -/\nclass has_dist (α : Type*) := (dist : α → α → ℝ)\n\nexport has_dist (dist)\n\n/-- Metric space\n\nEach metric space induces a canonical `uniform_space` and hence a canonical `topological_space`.\nThis is enforced in the type class definition, by extending the `uniform_space` structure. When\ninstantiating a `metric_space` structure, the uniformity fields are not necessary, they will be\nfilled in by default. In the same way, each metric space induces an emetric space structure.\nIt is included in the structure, but filled in by default.\n\nWhen one instantiates a metric space structure, for instance a product structure,\nthis makes it possible to use a uniform structure and an edistance that are exactly\nthe ones for the uniform spaces product and the emetric spaces products, thereby\nensuring that everything in defeq in diamonds.-/\nclass metric_space (α : Type u) extends has_dist α : Type u :=\n(dist_self : ∀ x : α, dist x x = 0)\n(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)\n(dist_comm : ∀ x y : α, dist x y = dist y x)\n(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)\n(edist : α → α → ennreal := λx y, ennreal.of_real (dist x y))\n(edist_dist : ∀ x y : α, edist x y = ennreal.of_real (dist x y) . control_laws_tac)\n(to_uniform_space : uniform_space α := uniform_space_of_dist dist dist_self dist_comm dist_triangle)\n(uniformity_dist : 𝓤 α = ⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)\n\nvariables [metric_space α]\n\ninstance metric_space.to_uniform_space' : uniform_space α :=\nmetric_space.to_uniform_space α\n\ninstance metric_space.to_has_edist : has_edist α := ⟨metric_space.edist⟩\n\n@[simp] theorem dist_self (x : α) : dist x x = 0 := metric_space.dist_self x\n\ntheorem eq_of_dist_eq_zero {x y : α} : dist x y = 0 → x = y :=\nmetric_space.eq_of_dist_eq_zero\n\ntheorem dist_comm (x y : α) : dist x y = dist y x := metric_space.dist_comm x y\n\ntheorem edist_dist (x y : α) : edist x y = ennreal.of_real (dist x y) :=\nmetric_space.edist_dist _ x y\n\n@[simp] theorem dist_eq_zero {x y : α} : dist x y = 0 ↔ x = y :=\niff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)\n\n@[simp] theorem zero_eq_dist {x y : α} : 0 = dist x y ↔ x = y :=\nby rw [eq_comm, dist_eq_zero]\n\ntheorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=\nmetric_space.dist_triangle x y z\n\ntheorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=\nby rw dist_comm z; apply dist_triangle\n\ntheorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=\nby rw dist_comm y; apply dist_triangle\n\nlemma dist_triangle4 (x y z w : α) :\n  dist x w ≤ dist x y + dist y z + dist z w :=\ncalc\n  dist x w ≤ dist x z + dist z w : dist_triangle x z w\n       ... ≤ (dist x y + dist y z) + dist z w : add_le_add_right (metric_space.dist_triangle x y z) _\n\nlemma dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :\n  dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=\nby rw [add_left_comm, dist_comm x₁, ← add_assoc]; apply dist_triangle4\n\nlemma dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :\n  dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=\nby rw [add_right_comm, dist_comm y₁]; apply dist_triangle4\n\ntheorem swap_dist : function.swap (@dist α _) = dist :=\nby funext x y; exact dist_comm _ _\n\ntheorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=\nabs_sub_le_iff.2\n ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),\n  sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩\n\ntheorem dist_nonneg {x y : α} : 0 ≤ dist x y :=\nhave 2 * dist x y ≥ 0,\n  from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]\n    ... ≥ 0 : by rw ← dist_self x; apply dist_triangle,\nnonneg_of_mul_nonneg_left this two_pos\n\n@[simp] theorem dist_le_zero {x y : α} : dist x y ≤ 0 ↔ x = y :=\nby simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y\n\n@[simp] theorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=\nby simpa [-dist_le_zero] using not_congr (@dist_le_zero _ _ x y)\n\n@[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=\nabs_of_nonneg dist_nonneg\n\ntheorem eq_of_forall_dist_le {x y : α} (h : ∀ε, ε > 0 → dist x y ≤ ε) : x = y :=\neq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)\n\ndef nndist (a b : α) : nnreal := ⟨dist a b, dist_nonneg⟩\n\n/--Express `nndist` in terms of `edist`-/\nlemma nndist_edist (x y : α) : nndist x y = (edist x y).to_nnreal :=\nby simp [nndist, edist_dist, nnreal.of_real, max_eq_left dist_nonneg, ennreal.of_real]\n\n/--Express `edist` in terms of `nndist`-/\nlemma edist_nndist (x y : α) : edist x y = ↑(nndist x y) :=\nby simp [nndist, edist_dist, nnreal.of_real, max_eq_left dist_nonneg, ennreal.of_real]\n\n/--In a metric space, the extended distance is always finite-/\nlemma edist_ne_top (x y : α) : edist x y ≠ ⊤ :=\nby rw [edist_dist x y]; apply ennreal.coe_ne_top\n\n/--`nndist x x` vanishes-/\n@[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)\n\n/--Express `dist` in terms of `nndist`-/\nlemma dist_nndist (x y : α) : dist x y = ↑(nndist x y) := rfl\n\n/--Express `nndist` in terms of `dist`-/\nlemma nndist_dist (x y : α) : nndist x y = nnreal.of_real (dist x y) :=\nby rw [dist_nndist, nnreal.of_real_coe]\n\n/--Deduce the equality of points with the vanishing of the nonnegative distance-/\ntheorem eq_of_nndist_eq_zero {x y : α} : nndist x y = 0 → x = y :=\nby simp only [nnreal.eq_iff.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, dist_eq_zero]\n\ntheorem nndist_comm (x y : α) : nndist x y = nndist y x :=\nby simpa [nnreal.eq_iff.symm] using dist_comm x y\n\n/--Characterize the equality of points with the vanishing of the nonnegative distance-/\n@[simp] theorem nndist_eq_zero {x y : α} : nndist x y = 0 ↔ x = y :=\nby simp only [nnreal.eq_iff.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, dist_eq_zero]\n\n@[simp] theorem zero_eq_nndist {x y : α} : 0 = nndist x y ↔ x = y :=\nby simp only [nnreal.eq_iff.symm, (dist_nndist _ _).symm, imp_self, nnreal.coe_zero, zero_eq_dist]\n\n/--Triangle inequality for the nonnegative distance-/\ntheorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=\nby simpa [nnreal.coe_le] using dist_triangle x y z\n\ntheorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=\nby simpa [nnreal.coe_le] using dist_triangle_left x y z\n\ntheorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=\nby simpa [nnreal.coe_le] using dist_triangle_right x y z\n\n/--Express `dist` in terms of `edist`-/\nlemma dist_edist (x y : α) : dist x y = (edist x y).to_real :=\nby rw [edist_dist, ennreal.to_real_of_real (dist_nonneg)]\n\nnamespace metric\n\n/- instantiate metric space as a topology -/\nvariables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}\n\n/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/\ndef ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}\n\n@[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl\n\ntheorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl\n\n/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/\ndef closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}\n\n@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl\n\ntheorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=\nassume y, by simp; intros h; apply le_of_lt h\n\ntheorem pos_of_mem_ball (hy : y ∈ ball x ε) : ε > 0 :=\nlt_of_le_of_lt dist_nonneg hy\n\ntheorem mem_ball_self (h : ε > 0) : x ∈ ball x ε :=\nshow dist x x < ε, by rw dist_self; assumption\n\ntheorem mem_closed_ball_self (h : ε ≥ 0) : x ∈ closed_ball x ε :=\nshow dist x x ≤ ε, by rw dist_self; assumption\n\ntheorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=\nby simp [dist_comm]\n\ntheorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=\nλ y (yx : _ < ε₁), lt_of_lt_of_le yx h\n\ntheorem closed_ball_subset_closed_ball {α : Type u} [metric_space α] {ε₁ ε₂ : ℝ} {x : α} (h : ε₁ ≤ ε₂) :\n  closed_ball x ε₁ ⊆ closed_ball x ε₂ :=\nλ y (yx : _ ≤ ε₁), le_trans yx h\n\ntheorem ball_disjoint (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=\neq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,\nnot_lt_of_le (dist_triangle_left x y z)\n  (lt_of_lt_of_le (add_lt_add h₁ h₂) h)\n\ntheorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=\nball_disjoint $ by rwa [← two_mul, ← le_div_iff' two_pos]\n\ntheorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=\nλ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact\nlt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)\n\ntheorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=\nball_subset $ by rw sub_self_div_two; exact le_of_lt h\n\ntheorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=\n⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩\n\ntheorem ball_eq_empty_iff_nonpos : ε ≤ 0 ↔ ball x ε = ∅ :=\n(eq_empty_iff_forall_not_mem.trans\n⟨λ h, le_of_not_gt $ λ ε0, h _ $ mem_ball_self ε0,\n λ ε0 y h, not_lt_of_le ε0 $ pos_of_mem_ball h⟩).symm\n\ntheorem uniformity_dist : 𝓤 α = (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}) :=\nmetric_space.uniformity_dist _\n\ntheorem uniformity_dist' : 𝓤 α = (⨅ε:{ε:ℝ // ε>0}, principal {p:α×α | dist p.1 p.2 < ε.val}) :=\nby simp [infi_subtype]; exact uniformity_dist\n\ntheorem mem_uniformity_dist {s : set (α×α)} :\n  s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=\nbegin\n  rw [uniformity_dist', mem_infi],\n  simp [subset_def],\n  exact assume ⟨r, hr⟩ ⟨p, hp⟩, ⟨⟨min r p, lt_min hr hp⟩, by simp [lt_min_iff, (≥)] {contextual := tt}⟩,\n  exact ⟨⟨1, zero_lt_one⟩⟩\nend\n\ntheorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :\n  {p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α :=\nmem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩\n\ntheorem uniform_continuous_iff [metric_space β] {f : α → β} :\n  uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,\n    ∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=\nuniform_continuous_def.trans\n⟨λ H ε ε0, mem_uniformity_dist.1 $ H _ $ dist_mem_uniformity ε0,\n λ H r ru,\n  let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru, ⟨δ, δ0, hδ⟩ := H _ ε0 in\n  mem_uniformity_dist.2 ⟨δ, δ0, λ a b h, hε (hδ h)⟩⟩\n\ntheorem uniform_embedding_iff [metric_space β] {f : α → β} :\n  uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧\n    ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=\nuniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl\n⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),\n               ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in\n  ⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,\n λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in\n  ⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩\n\ntheorem totally_bounded_iff {s : set α} :\n  totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=\n⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),\n λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,\n               ⟨t, ft, h⟩ := H ε ε0 in\n  ⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩\n\n/-- A metric space space is totally bounded if one can reconstruct up to any ε>0 any element of the\nspace from finitely many data. -/\nlemma totally_bounded_of_finite_discretization {α : Type u} [metric_space α] {s : set α}\n  (H : ∀ε > (0 : ℝ), ∃ (β : Type u) [fintype β] (F : s → β),\n    ∀x y, F x = F y → dist (x:α) y < ε) :\n  totally_bounded s :=\nbegin\n  classical, by_cases hs : s = ∅,\n  { rw hs, exact totally_bounded_empty },\n  rcases exists_mem_of_ne_empty hs with ⟨x0, hx0⟩,\n  haveI : inhabited s := ⟨⟨x0, hx0⟩⟩,\n  refine totally_bounded_iff.2 (λ ε ε0, _),\n  rcases H ε ε0 with ⟨β, fβ, F, hF⟩,\n  let Finv := function.inv_fun F,\n  refine ⟨range (subtype.val ∘ Finv), finite_range _, λ x xs, _⟩,\n  let x' := Finv (F ⟨x, xs⟩),\n  have : F x' = F ⟨x, xs⟩ := function.inv_fun_eq ⟨⟨x, xs⟩, rfl⟩,\n  simp only [set.mem_Union, set.mem_range],\n  exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩\nend\n\nprotected lemma cauchy_iff {f : filter α} :\n  cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε :=\ncauchy_iff.trans $ and_congr iff.rfl\n⟨λ H ε ε0, let ⟨t, tf, ts⟩ := H _ (dist_mem_uniformity ε0) in\n   ⟨t, tf, λ x y xt yt, @ts (x, y) ⟨xt, yt⟩⟩,\n λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,\n               ⟨t, tf, h⟩ := H ε ε0 in\n   ⟨t, tf, λ ⟨x, y⟩ ⟨hx, hy⟩, hε (h x y hx hy)⟩⟩\n\ntheorem nhds_eq : nhds x = (⨅ε:{ε:ℝ // ε>0}, principal (ball x ε.val)) :=\nbegin\n  rw [nhds_eq_uniformity, uniformity_dist', lift'_infi],\n  { apply congr_arg, funext ε,\n    rw [lift'_principal],\n    { simp [ball, dist_comm] },\n    { exact monotone_preimage } },\n  { exact ⟨⟨1, zero_lt_one⟩⟩ },\n  { intros, refl }\nend\n\ntheorem mem_nhds_iff : s ∈ nhds x ↔ ∃ε>0, ball x ε ⊆ s :=\nbegin\n  rw [nhds_eq, mem_infi],\n  { simp },\n  { intros y z, cases y with y hy, cases z with z hz,\n    refine ⟨⟨min y z, lt_min hy hz⟩, _⟩,\n    simp [ball_subset_ball, min_le_left, min_le_right, (≥)] },\n  { exact ⟨⟨1, zero_lt_one⟩⟩ }\nend\n\ntheorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=\nby simp [is_open_iff_nhds, mem_nhds_iff]\n\ntheorem is_open_ball : is_open (ball x ε) :=\nis_open_iff.2 $ λ y, exists_ball_subset_ball\n\ntheorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ nhds x :=\nmem_nhds_sets is_open_ball (mem_ball_self ε0)\n\ntheorem tendsto_nhds_nhds [metric_space β] {f : α → β} {a b} :\n  tendsto f (nhds a) (nhds b) ↔\n    ∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=\n⟨λ H ε ε0, mem_nhds_iff.1 (H (ball_mem_nhds _ ε0)),\n λ H s hs,\n  let ⟨ε, ε0, hε⟩ := mem_nhds_iff.1 hs, ⟨δ, δ0, hδ⟩ := H _ ε0 in\n  mem_nhds_iff.2 ⟨δ, δ0, λ x h, hε (hδ h)⟩⟩\n\ntheorem continuous_iff [metric_space β] {f : α → β} :\n  continuous f ↔\n    ∀b (ε > 0), ∃ δ > 0, ∀a, dist a b < δ → dist (f a) (f b) < ε :=\ncontinuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_nhds\n\ntheorem exists_delta_of_continuous [metric_space β] {f : α → β} {ε : ℝ}\n  (hf : continuous f) (hε : ε > 0) (b : α) :\n  ∃ δ > 0, ∀a, dist a b ≤ δ → dist (f a) (f b) < ε :=\nlet ⟨δ, δ_pos, hδ⟩ := continuous_iff.1 hf b ε hε in\n⟨δ / 2, half_pos δ_pos, assume a ha, hδ a $ lt_of_le_of_lt ha $ div_two_lt_of_pos δ_pos⟩\n\ntheorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :\n  tendsto u f (nhds a) ↔ ∀ ε > 0, ∃ n ∈ f, ∀x ∈ n,  dist (u x) a < ε :=\nby simp only [metric.nhds_eq, tendsto_infi, subtype.forall, tendsto_principal, mem_ball];\n  exact forall_congr (assume ε, forall_congr (assume hε, exists_sets_subset_iff.symm))\n\ntheorem continuous_iff' [topological_space β] {f : β → α} :\n  continuous f ↔ ∀a (ε > 0), ∃ n ∈ nhds a, ∀b ∈ n, dist (f b) (f a) < ε :=\ncontinuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds\n\ntheorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :\n  tendsto u at_top (nhds a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε :=\nby simp only [metric.nhds_eq, tendsto_infi, subtype.forall, tendsto_at_top_principal]; refl\n\nend metric\n\nopen metric\n\ninstance metric_space.to_separated : separated α :=\nseparated_def.2 $ λ x y h, eq_of_forall_dist_le $\n  λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))\n\n/-Instantiate a metric space as an emetric space. Before we can state the instance,\nwe need to show that the uniform structure coming from the edistance and the\ndistance coincide. -/\n\n/-- Expressing the uniformity in terms of `edist` -/\nprotected lemma metric.mem_uniformity_edist {s : set (α×α)} :\n  s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, edist a b < ε → (a, b) ∈ s) :=\nbegin\n  refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩,\n  { refine ⟨ennreal.of_real ε, _, λ a b, _⟩,\n    { rwa [gt, ennreal.of_real_pos] },\n    { rw [edist_dist, ennreal.of_real_lt_of_real_iff ε0],\n      exact Hε } },\n  { rcases ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩,\n    rw [ennreal.of_real_pos] at ε0',\n    refine ⟨ε', ε0', λ a b h, Hε (lt_trans _ hε)⟩,\n    rwa [edist_dist, ennreal.of_real_lt_of_real_iff ε0'] }\nend\n\nprotected theorem metric.uniformity_edist' : 𝓤 α = (⨅ε:{ε:ennreal // ε>0}, principal {p:α×α | edist p.1 p.2 < ε.val}) :=\nbegin\n  ext s, rw mem_infi,\n  { simp [metric.mem_uniformity_edist, subset_def] },\n  { rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩,\n    simp [lt_min_iff, (≥)] {contextual := tt} },\n  { exact ⟨⟨1, ennreal.zero_lt_one⟩⟩ }\nend\n\ntheorem uniformity_edist : 𝓤 α = (⨅ ε>0, principal {p:α×α | edist p.1 p.2 < ε}) :=\nby simpa [infi_subtype] using @metric.uniformity_edist' α _\n\n/-- A metric space induces an emetric space -/\ninstance metric_space.to_emetric_space : emetric_space α :=\n{ edist               := edist,\n  edist_self          := by simp [edist_dist],\n  eq_of_edist_eq_zero := assume x y h, by simpa [edist_dist] using h,\n  edist_comm          := by simp only [edist_dist, dist_comm]; simp,\n  edist_triangle      := assume x y z, begin\n    simp only [edist_dist, (ennreal.of_real_add _ _).symm, dist_nonneg],\n    rw ennreal.of_real_le_of_real_iff _,\n    { exact dist_triangle _ _ _ },\n    { simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg }\n  end,\n  uniformity_edist    := uniformity_edist,\n  ..‹metric_space α› }\n\n/-- Balls defined using the distance or the edistance coincide -/\nlemma metric.emetric_ball {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = ball x ε :=\nbegin\n  classical, by_cases h : 0 < ε,\n  { ext y, by simp [edist_dist, ennreal.of_real_lt_of_real_iff h] },\n  { have h' : ε ≤ 0, by simpa using h,\n    have A : ball x ε = ∅, by simpa [ball_eq_empty_iff_nonpos.symm],\n    have B : emetric.ball x (ennreal.of_real ε) = ∅,\n      by simp [ennreal.of_real_eq_zero.2 h', emetric.ball_eq_empty_iff],\n    rwa [A, B] }\nend\n\n/-- Closed balls defined using the distance or the edistance coincide -/\nlemma metric.emetric_closed_ball {x : α} {ε : ℝ} (h : 0 ≤ ε) :\n  emetric.closed_ball x (ennreal.of_real ε) = closed_ball x ε :=\nby ext y; simp [edist_dist]; rw ennreal.of_real_le_of_real_iff h\n\ndef metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α)\n  (H : @uniformity _ U = @uniformity _ (metric_space.to_uniform_space α)) :\n  metric_space α :=\n{ dist               := @dist _ m.to_has_dist,\n  dist_self          := dist_self,\n  eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,\n  dist_comm          := dist_comm,\n  dist_triangle      := dist_triangle,\n  edist              := edist,\n  edist_dist         := edist_dist,\n  to_uniform_space   := U,\n  uniformity_dist    := H.trans (metric_space.uniformity_dist α) }\n\n/-- One gets a metric space from an emetric space if the edistance\nis everywhere finite. We set it up so that the edist and the uniformity are\ndefeq in the metric space and the emetric space -/\n\ndef emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀x y: α, edist x y ≠ ⊤) :\n  metric_space α :=\nlet m : metric_space α :=\n{ dist               := λx y, ennreal.to_real (edist x y),\n  eq_of_dist_eq_zero := λx y hxy, by simpa [dist, ennreal.to_real_eq_zero_iff, h x y] using hxy,\n  dist_self          := λx, by simp,\n  dist_comm          := λx y, by simp [emetric_space.edist_comm],\n  dist_triangle      := λx y z, begin\n    rw [← ennreal.to_real_add (h _ _) (h _ _), ennreal.to_real_le_to_real (h _ _)],\n    { exact edist_triangle _ _ _ },\n    { simp [ennreal.add_eq_top, h] }\n  end,\n  edist              := λx y, edist x y,\n  edist_dist         := λx y, by simp [ennreal.of_real_to_real, h] } in\nmetric_space.replace_uniformity m (by rw [uniformity_edist, uniformity_edist']; refl)\n\nsection real\n\n/-- Instantiate the reals as a metric space. -/\ninstance real.metric_space : metric_space ℝ :=\n{ dist               := λx y, abs (x - y),\n  dist_self          := by simp [abs_zero],\n  eq_of_dist_eq_zero := by simp [add_neg_eq_zero],\n  dist_comm          := assume x y, abs_sub _ _,\n  dist_triangle      := assume x y z, abs_sub_le _ _ _ }\n\ntheorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl\n\ntheorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=\nby simp [real.dist_eq]\n\ninstance : orderable_topology ℝ :=\norderable_topology_of_nhds_abs $ λ x, begin\n  simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r,\n    by simp [-sub_eq_add_neg, abs_sub, ball, real.dist_eq]],\n  apply le_antisymm,\n  { simp [le_infi_iff],\n    exact λ ε ε0, mem_nhds_sets (is_open_ball) (mem_ball_self ε0) },\n  { intros s h,\n    rcases mem_nhds_iff.1 h with ⟨ε, ε0, ss⟩,\n    exact mem_infi_sets _ (mem_infi_sets ε0 (mem_principal_sets.2 ss)) },\nend\n\nlemma closed_ball_Icc {x r : ℝ} : closed_ball x r = Icc (x-r) (x+r) :=\nby ext y; rw [mem_closed_ball, dist_comm, real.dist_eq,\n  abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le]\n\nlemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)\n  (g0 : tendsto g t₀ (nhds 0)) : tendsto f t₀ (nhds 0) :=\nbegin\n  apply tendsto_of_tendsto_of_tendsto_of_le_of_le (tendsto_const_nhds) g0;\n  simp [*]; exact filter.univ_mem_sets\nend\n\ntheorem metric.uniformity_eq_comap_nhds_zero :\n  𝓤 α = comap (λp:α×α, dist p.1 p.2) (nhds (0 : ℝ)) :=\nbegin\n  simp only [uniformity_dist', nhds_eq, comap_infi, comap_principal],\n  congr, funext ε,\n  rw [principal_eq_iff_eq],\n  ext ⟨a, b⟩,\n  simp [real.dist_0_eq_abs]\nend\n\nlemma cauchy_seq_iff_tendsto_dist_at_top_0 [inhabited β] [semilattice_sup β] {u : β → α} :\n  cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (nhds 0) :=\nby rw [cauchy_seq_iff_prod_map, metric.uniformity_eq_comap_nhds_zero, ← map_le_iff_le_comap,\n  filter.map_map, tendsto, prod.map_def]\n\nend real\n\nsection cauchy_seq\nvariables [inhabited β] [semilattice_sup β]\n\n/-- In a metric space, Cauchy sequences are characterized by the fact that, eventually,\nthe distance between its elements is arbitrarily small -/\ntheorem metric.cauchy_seq_iff {u : β → α} :\n  cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε :=\nbegin\n  unfold cauchy_seq,\n  rw metric.cauchy_iff,\n  simp only [true_and, exists_prop, filter.mem_at_top_sets, filter.at_top_ne_bot,\n             filter.mem_map, ne.def, filter.map_eq_bot_iff, not_false_iff, set.mem_set_of_eq],\n  split,\n  { intros H ε εpos,\n    rcases H ε εpos with ⟨t, ⟨N, hN⟩, ht⟩,\n    exact ⟨N, λm n hm hn, ht _ _ (hN _ hm) (hN _ hn)⟩ },\n  { intros H ε εpos,\n    rcases H (ε/2) (half_pos εpos) with ⟨N, hN⟩,\n    existsi ball (u N) (ε/2),\n    split,\n    { exact ⟨N, λx hx, hN _ _ hx (le_refl N)⟩ },\n    { exact λx y hx hy, calc\n        dist x y ≤ dist x (u N) + dist y (u N) : dist_triangle_right _ _ _\n        ... < ε/2 + ε/2 : add_lt_add hx hy\n        ... = ε : add_halves _ } }\nend\n\n/-- A variation around the metric characterization of Cauchy sequences -/\ntheorem metric.cauchy_seq_iff' {u : β → α} :\n  cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε :=\nbegin\n  rw metric.cauchy_seq_iff,\n  split,\n  { intros H ε εpos,\n    rcases H ε εpos with ⟨N, hN⟩,\n    exact ⟨N, λn hn, hN _ _ hn (le_refl N)⟩ },\n  { intros H ε εpos,\n    rcases H (ε/2) (half_pos εpos) with ⟨N, hN⟩,\n    exact ⟨N, λ m n hm hn, calc\n       dist (u m) (u n) ≤ dist (u m) (u N) + dist (u n) (u N) : dist_triangle_right _ _ _\n                    ... < ε/2 + ε/2 : add_lt_add (hN _ hm) (hN _ hn)\n                    ... = ε : add_halves _⟩ }\nend\n\n/-- A Cauchy sequence on the natural numbers is bounded. -/\ntheorem cauchy_seq_bdd {u : ℕ → α} (hu : cauchy_seq u) :\n  ∃ R > 0, ∀ m n, dist (u m) (u n) < R :=\nbegin\n  rcases metric.cauchy_seq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩,\n  suffices : ∃ R > 0, ∀ n, dist (u n) (u N) < R,\n  { rcases this with ⟨R, R0, H⟩,\n    exact ⟨_, add_pos R0 R0, λ m n,\n      lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ },\n  let R := finset.sup (finset.range N) (λ n, nndist (u n) (u N)),\n  refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, λ n, _⟩,\n  cases le_or_lt N n,\n  { exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) },\n  { have : _ ≤ R := finset.le_sup (finset.mem_range.2 h),\n    exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) }\nend\n\n/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the\nmost efficient. -/\nlemma cauchy_seq_iff_le_tendsto_0 {s : ℕ → α} : cauchy_seq s ↔ ∃ b : ℕ → ℝ,\n  (∀ n, 0 ≤ b n) ∧\n  (∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧\n  tendsto b at_top (nhds 0) :=\n⟨λ hs, begin\n  /- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking\n  the supremum of the distances between `s n` and `s m` for `n m ≥ N`.\n  First, we prove that all these distances are bounded, as otherwise the Sup\n  would not make sense. -/\n  let S := λ N, (λ(p : ℕ × ℕ), dist (s p.1) (s p.2)) '' {p | p.1 ≥ N ∧ p.2 ≥ N},\n  have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x,\n  { rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,\n    refine λ N, ⟨R, _⟩, rintro _ ⟨⟨m, n⟩, _, rfl⟩,\n    exact le_of_lt (hR m n) },\n  have bdd : bdd_above (range (λ(p : ℕ × ℕ), dist (s p.1) (s p.2))),\n  { rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,\n    use R, rintro _ ⟨⟨m, n⟩, rfl⟩, exact le_of_lt (hR m n) },\n  -- Prove that it bounds the distances of points in the Cauchy sequence\n  have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ real.Sup (S N) :=\n    λ m n N hm hn, real.le_Sup _ (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩,\n  have S0m : ∀ n, (0:ℝ) ∈ S n := λ n, ⟨⟨n, n⟩, ⟨le_refl _, le_refl _⟩, dist_self _⟩,\n  have S0 := λ n, real.le_Sup _ (hS n) (S0m n),\n  -- Prove that it tends to `0`, by using the Cauchy property of `s`\n  refine ⟨λ N, real.Sup (S N), S0, ub, metric.tendsto_at_top.2 (λ ε ε0, _)⟩,\n  refine (metric.cauchy_seq_iff.1 hs (ε/2) (half_pos ε0)).imp (λ N hN n hn, _),\n  rw [real.dist_0_eq_abs, abs_of_nonneg (S0 n)],\n  refine lt_of_le_of_lt (real.Sup_le_ub _ ⟨_, S0m _⟩ _) (half_lt_self ε0),\n  rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩,\n  exact le_of_lt (hN _ _ (le_trans hn hm') (le_trans hn hn'))\n  end,\nλ ⟨b, _, b_bound, b_lim⟩, metric.cauchy_seq_iff.2 $ λ ε ε0,\n  (metric.tendsto_at_top.1 b_lim ε ε0).imp $ λ N hN m n hm hn,\n  calc dist (s m) (s n) ≤ b N : b_bound m n N hm hn\n                    ... ≤ abs (b N) : le_abs_self _\n                    ... = dist (b N) 0 : by rw real.dist_0_eq_abs; refl\n                    ... < ε : (hN _ (le_refl N)) ⟩\n\nend cauchy_seq\n\ndef metric_space.induced {α β} (f : α → β) (hf : function.injective f)\n  (m : metric_space β) : metric_space α :=\n{ dist               := λ x y, dist (f x) (f y),\n  dist_self          := λ x, dist_self _,\n  eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),\n  dist_comm          := λ x y, dist_comm _ _,\n  dist_triangle      := λ x y z, dist_triangle _ _ _,\n  edist              := λ x y, edist (f x) (f y),\n  edist_dist         := λ x y, edist_dist _ _,\n  to_uniform_space   := uniform_space.comap f m.to_uniform_space,\n  uniformity_dist    := begin\n    apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, dist (f x) (f y)),\n    refine λ s, mem_comap_sets.trans _,\n    split; intro H,\n    { rcases H with ⟨r, ru, rs⟩,\n      rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,\n      refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },\n    { rcases H with ⟨ε, ε0, hε⟩,\n      exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }\n  end }\n\ninstance subtype.metric_space {p : α → Prop} [t : metric_space α] : metric_space (subtype p) :=\nmetric_space.induced subtype.val (λ x y, subtype.eq) t\n\ntheorem subtype.dist_eq {p : α → Prop} [t : metric_space α] (x y : subtype p) :\n  dist x y = dist x.1 y.1 := rfl\n\nsection nnreal\n\ninstance : metric_space nnreal := by unfold nnreal; apply_instance\n\nend nnreal\n\nsection prod\n\ninstance prod.metric_space_max [metric_space β] : metric_space (α × β) :=\n{ dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),\n  dist_self := λ x, by simp,\n  eq_of_dist_eq_zero := λ x y h, begin\n    cases max_le_iff.1 (le_of_eq h) with h₁ h₂,\n    exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩\n  end,\n  dist_comm := λ x y, by simp [dist_comm],\n  dist_triangle := λ x y z, max_le\n    (le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))\n    (le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),\n  edist := λ x y, max (edist x.1 y.1) (edist x.2 y.2),\n  edist_dist := assume x y, begin\n    have : monotone ennreal.of_real := assume x y h, ennreal.of_real_le_of_real h,\n    rw [edist_dist, edist_dist, (max_distrib_of_monotone this).symm]\n  end,\n  uniformity_dist := begin\n    refine uniformity_prod.trans _,\n    simp [uniformity_dist, comap_infi],\n    rw ← infi_inf_eq, congr, funext,\n    rw ← infi_inf_eq, congr, funext,\n    simp [inf_principal, ext_iff, max_lt_iff]\n  end,\n  to_uniform_space := prod.uniform_space }\n\nlemma prod.dist_eq [metric_space β] {x y : α × β} :\n  dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl\n\nend prod\n\ntheorem uniform_continuous_dist' : uniform_continuous (λp:α×α, dist p.1 p.2) :=\nmetric.uniform_continuous_iff.2 (λ ε ε0, ⟨ε/2, half_pos ε0,\nbegin\n  suffices,\n  { intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,\n    cases max_lt_iff.1 h with h₁ h₂, clear h,\n    dsimp at h₁ h₂ ⊢,\n    rw real.dist_eq,\n    refine abs_sub_lt_iff.2 ⟨_, _⟩,\n    { revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },\n    { apply this; rwa dist_comm } },\n  intros p₁ p₂ q₁ q₂ h₁ h₂,\n  have := add_lt_add\n    (abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1\n    (abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,\n  rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this\nend⟩)\n\ntheorem uniform_continuous_dist [uniform_space β] {f g : β → α}\n  (hf : uniform_continuous f) (hg : uniform_continuous g) :\n  uniform_continuous (λb, dist (f b) (g b)) :=\n(hf.prod_mk hg).comp uniform_continuous_dist'\n\ntheorem continuous_dist' : continuous (λp:α×α, dist p.1 p.2) :=\nuniform_continuous_dist'.continuous\n\ntheorem continuous_dist [topological_space β] {f g : β → α}\n  (hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=\n(hf.prod_mk hg).comp continuous_dist'\n\ntheorem tendsto_dist {f g : β → α} {x : filter β} {a b : α}\n  (hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) :\n  tendsto (λx, dist (f x) (g x)) x (nhds (dist a b)) :=\nhave tendsto (λp:α×α, dist p.1 p.2) (nhds (a, b)) (nhds (dist a b)),\n  from continuous_iff_continuous_at.mp continuous_dist' (a, b),\n(hf.prod_mk hg).comp (by rw [nhds_prod_eq] at this; exact this)\n\nlemma nhds_comap_dist (a : α) : (nhds (0 : ℝ)).comap (λa', dist a' a) = nhds a :=\nhave h₁ : ∀ε, (λa', dist a' a) ⁻¹' ball 0 ε ⊆ ball a ε,\n  by simp [subset_def, real.dist_0_eq_abs],\nhave h₂ : tendsto (λa', dist a' a) (nhds a) (nhds (dist a a)),\n  from tendsto_dist tendsto_id tendsto_const_nhds,\nle_antisymm\n  (by simp [h₁, nhds_eq, infi_le_infi, principal_mono,\n      -le_principal_iff, -le_infi_iff])\n  (by simpa [map_le_iff_le_comap.symm, tendsto] using h₂)\n\nlemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :\n  (tendsto f x (nhds a)) ↔ (tendsto (λb, dist (f b) a) x (nhds 0)) :=\nby rw [← nhds_comap_dist a, tendsto_comap_iff]\n\nlemma uniform_continuous_nndist' : uniform_continuous (λp:α×α, nndist p.1 p.2) :=\nuniform_continuous_subtype_mk uniform_continuous_dist' _\n\nlemma continuous_nndist' : continuous (λp:α×α, nndist p.1 p.2) :=\nuniform_continuous_nndist'.continuous\n\nlemma tendsto_nndist' (a b :α) :\n  tendsto (λp:α×α, nndist p.1 p.2) (filter.prod (nhds a) (nhds b)) (nhds (nndist a b)) :=\nby rw [← nhds_prod_eq]; exact continuous_iff_continuous_at.1 continuous_nndist' _\n\nnamespace metric\nvariables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}\n\ntheorem is_closed_ball : is_closed (closed_ball x ε) :=\nis_closed_le (continuous_dist continuous_id continuous_const) continuous_const\n\n/-- ε-characterization of the closure in metric spaces-/\ntheorem mem_closure_iff' {α : Type u} [metric_space α] {s : set α} {a : α} :\n  a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=\n⟨begin\n  intros ha ε hε,\n  have A : ball a ε ∩ s ≠ ∅ := mem_closure_iff.1 ha _ is_open_ball (mem_ball_self hε),\n  cases ne_empty_iff_exists_mem.1 A with b hb,\n  simp,\n  exact ⟨b, ⟨hb.2, by have B := hb.1; simpa [mem_ball'] using B⟩⟩\nend,\nbegin\n  intros H,\n  apply mem_closure_iff.2,\n  intros o ho ao,\n  rcases is_open_iff.1 ho a ao with ⟨ε, ⟨εpos, hε⟩⟩,\n  rcases H ε εpos with ⟨b, ⟨bs, bdist⟩⟩,\n  have B : b ∈ o ∩ s := ⟨hε (by simpa [dist_comm]), bs⟩,\n  apply ne_empty_of_mem B\nend⟩\n\ntheorem mem_of_closed' {α : Type u} [metric_space α] {s : set α} (hs : is_closed s)\n  {a : α} : a ∈ s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=\nby simpa only [closure_eq_of_is_closed hs] using @mem_closure_iff' _ _ s a\n\nend metric\n\nsection pi\nopen finset lattice\nvariables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]\n\ninstance has_dist_pi : has_dist (Πb, π b) :=\n⟨λf g, ((finset.sup univ (λb, nndist (f b) (g b)) : nnreal) : ℝ)⟩\n\nlemma dist_pi_def (f g : Πb, π b) :\n  dist f g = (finset.sup univ (λb, nndist (f b) (g b)) : nnreal) := rfl\n\ninstance metric_space_pi : metric_space (Πb, π b) :=\n{ dist := dist,\n  dist_self := assume f, (nnreal.coe_eq_zero _).2 $ bot_unique $ finset.sup_le $ by simp,\n  dist_comm := assume f g, nnreal.eq_iff.2 $ by congr; ext a; exact nndist_comm _ _,\n  dist_triangle := assume f g h, show dist f h ≤ (dist f g) + (dist g h), from\n    begin\n      simp only [dist_pi_def, (nnreal.coe_add _ _).symm, nnreal.coe_le.symm,\n        finset.sup_le_iff],\n      assume b hb,\n      exact le_trans (nndist_triangle _ (g b) _) (add_le_add (le_sup hb) (le_sup hb))\n    end,\n  eq_of_dist_eq_zero := assume f g eq0,\n    begin\n      simp only [dist_pi_def, nnreal.coe_eq_zero, nnreal.bot_eq_zero.symm, eq_bot_iff,\n        finset.sup_le_iff] at eq0,\n      exact (funext $ assume b, eq_of_nndist_eq_zero $ bot_unique $ eq0 b $ mem_univ b),\n    end,\n  edist := λ f g, finset.sup univ (λb, edist (f b) (g b)),\n  edist_dist := assume x y, begin\n    have A : sup univ (λ (b : β), ((nndist (x b) (y b)) : ennreal)) = ↑(sup univ (λ (b : β), nndist (x b) (y b))),\n    { refine eq.symm (comp_sup_eq_sup_comp _ _ _),\n      exact (assume x y h, ennreal.coe_le_coe.2 h), refl },\n    simp [dist, edist_nndist, ennreal.of_real, A]\n  end }\n\nend pi\n\nsection compact\n\n/-- Any compact set in a metric space can be covered by finitely many balls of a given positive\nradius -/\nlemma finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α}\n  (hs : compact s) {e : ℝ} (he : e > 0) :\n  ∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e :=\nbegin\n  apply compact_elim_finite_subcover_image hs,\n  { simp [is_open_ball] },\n  { intros x xs,\n    simp,\n    exact ⟨x, ⟨xs, by simpa⟩⟩ }\nend\n\nend compact\n\nsection proper_space\nopen metric\n\n/-- A metric space is proper if all closed balls are compact. -/\nclass proper_space (α : Type u) [metric_space α] : Prop :=\n(compact_ball : ∀x:α, ∀r, compact (closed_ball x r))\n\n/- A compact metric space is proper -/\ninstance proper_of_compact [metric_space α] [compact_space α] : proper_space α :=\n⟨assume x r, compact_of_is_closed_subset compact_univ is_closed_ball (subset_univ _)⟩\n\n/-- A proper space is locally compact -/\ninstance locally_compact_of_proper [metric_space α] [proper_space α] :\n  locally_compact_space α :=\nbegin\n  apply locally_compact_of_compact_nhds,\n  intros x,\n  existsi closed_ball x 1,\n  split,\n  { apply mem_nhds_iff.2,\n    existsi (1 : ℝ),\n    simp,\n    exact ⟨zero_lt_one, ball_subset_closed_ball⟩ },\n  { apply proper_space.compact_ball }\nend\n\n/-- A proper space is complete -/\ninstance complete_of_proper {α : Type u} [metric_space α] [proper_space α] : complete_space α :=\n⟨begin\n  intros f hf,\n  /- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed\n  ball (therefore compact by properness) where it is nontrivial. -/\n  have A : ∃ t ∈ f, ∀ x y ∈ t, dist x y < 1 := (metric.cauchy_iff.1 hf).2 1 zero_lt_one,\n  rcases A with ⟨t, ⟨t_fset, ht⟩⟩,\n  rcases inhabited_of_mem_sets hf.1 t_fset with ⟨x, xt⟩,\n  have : t ⊆ closed_ball x 1 := by intros y yt; simp [dist_comm]; apply le_of_lt (ht x y xt yt),\n  have : closed_ball x 1 ∈ f := f.sets_of_superset t_fset this,\n  rcases (compact_iff_totally_bounded_complete.1 (proper_space.compact_ball x 1)).2 f hf (le_principal_iff.2 this)\n    with ⟨y, _, hy⟩,\n  exact ⟨y, hy⟩\nend⟩\n\n/-- A proper metric space is separable, and therefore second countable. Indeed, any ball is\ncompact, and therefore admits a countable dense subset. Taking a countable union over the balls\ncentered at a fixed point and with integer radius, one obtains a countable set which is\ndense in the whole space. -/\ninstance second_countable_of_proper [metric_space α] [proper_space α] :\n  second_countable_topology α :=\nbegin\n  /- We show that the space admits a countable dense subset. The case where the space is empty\n  is special, and trivial. -/\n  have A : (univ : set α) = ∅ → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=\n    assume H, ⟨∅, ⟨by simp, by simp; exact H.symm⟩⟩,\n  have B : (univ : set α) ≠ ∅ → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=\n  begin\n    /- When the space is not empty, we take a point `x` in the space, and then a countable set\n    `T r` which is dense in the closed ball `closed_ball x r` for each `r`. Then the set\n    `t = ⋃ T n` (where the union is over all integers `n`) is countable, as a countable union\n    of countable sets, and dense in the space by construction. -/\n    assume non_empty,\n    rcases ne_empty_iff_exists_mem.1 non_empty with ⟨x, x_univ⟩,\n    choose T a using show ∀ (r:ℝ), ∃ t ⊆ closed_ball x r, (countable (t : set α) ∧ closed_ball x r = closure t),\n      from assume r, emetric.countable_closure_of_compact (proper_space.compact_ball _ _),\n    let t := (⋃n:ℕ, T (n : ℝ)),\n    have T₁ : countable t := by finish [countable_Union],\n    have T₂ : closure t ⊆ univ := by simp,\n    have T₃ : univ ⊆ closure t :=\n    begin\n      intros y y_univ,\n      rcases exists_nat_gt (dist y x) with ⟨n, n_large⟩,\n      have h : y ∈ closed_ball x (n : ℝ) := by simp; apply le_of_lt n_large,\n      have h' : closed_ball x (n : ℝ) = closure (T (n : ℝ)) := by finish,\n      have : y ∈ closure (T (n : ℝ)) := by rwa h' at h,\n      show y ∈ closure t, from mem_of_mem_of_subset this (by apply closure_mono; apply subset_Union (λ(n:ℕ), T (n:ℝ))),\n    end,\n    exact ⟨t, ⟨T₁, subset.antisymm T₂ T₃⟩⟩\n  end,\n  haveI : separable_space α := ⟨by_cases A B⟩,\n  apply emetric.second_countable_of_separable,\nend\n\nend proper_space\n\nnamespace metric\nsection second_countable\nopen topological_space\n\n/-- A metric space is second countable if, for every ε > 0, there is a countable set which is ε-dense. -/\nlemma second_countable_of_almost_dense_set\n  (H : ∀ε > (0 : ℝ), ∃ s : set α, countable s ∧ (∀x, ∃y ∈ s, dist x y ≤ ε)) :\n  second_countable_topology α :=\nbegin\n  choose T T_dense using H,\n  have I1 : ∀n:ℕ, (n:ℝ) + 1 > 0 :=\n    λn, lt_of_lt_of_le zero_lt_one (le_add_of_nonneg_left (nat.cast_nonneg _)),\n  have I : ∀n:ℕ, (n+1 : ℝ)⁻¹ > 0 := λn, inv_pos'.2 (I1 n),\n  let t := ⋃n:ℕ, T (n+1)⁻¹ (I n),\n  have count_t : countable t := by finish [countable_Union],\n  have clos_t : closure t = univ,\n  { refine subset.antisymm (subset_univ _) (λx xuniv, mem_closure_iff'.2 (λε εpos, _)),\n    rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩,\n    have : ε⁻¹ < n + 1 := lt_of_lt_of_le hn (le_add_of_nonneg_right zero_le_one),\n    have nε : ((n:ℝ)+1)⁻¹ < ε := (inv_lt (I1 n) εpos).2 this,\n    rcases (T_dense (n+1)⁻¹ (I n)).2 x with ⟨y, yT, Dxy⟩,\n    have : y ∈ t := mem_of_mem_of_subset yT (by apply subset_Union (λ (n:ℕ), T (n+1)⁻¹ (I n))),\n    exact ⟨y, this, lt_of_le_of_lt Dxy nε⟩ },\n  haveI : separable_space α := ⟨⟨t, ⟨count_t, clos_t⟩⟩⟩,\n  exact emetric.second_countable_of_separable α\nend\n\n/-- A metric space space is second countable if one can reconstruct up to any ε>0 any element of the\nspace from countably many data. -/\nlemma second_countable_of_countable_discretization {α : Type u} [metric_space α]\n  (H : ∀ε > (0 : ℝ), ∃ (β : Type u) [encodable β] (F : α → β), ∀x y, F x = F y → dist x y ≤ ε) :\n  second_countable_topology α :=\nbegin\n  classical, by_cases hs : (univ : set α) = ∅,\n  { haveI : compact_space α := ⟨by rw hs; exact compact_of_finite (set.finite_empty)⟩, by apply_instance },\n  rcases exists_mem_of_ne_empty hs with ⟨x0, hx0⟩,\n  letI : inhabited α := ⟨x0⟩,\n  refine second_countable_of_almost_dense_set (λε ε0, _),\n  rcases H ε ε0 with ⟨β, fβ, F, hF⟩,\n  let Finv := function.inv_fun F,\n  refine ⟨range Finv, ⟨countable_range _, λx, _⟩⟩,\n  let x' := Finv (F x),\n  have : F x' = F x := function.inv_fun_eq ⟨x, rfl⟩,\n  exact ⟨x', mem_range_self _, hF _ _ this.symm⟩\nend\n\nend second_countable\nend metric\n\nlemma lebesgue_number_lemma_of_metric\n  {s : set α} {ι} {c : ι → set α} (hs : compact s)\n  (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :\n  ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=\nlet ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,\n    ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in\n⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in\n ⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩\n\nlemma lebesgue_number_lemma_of_metric_sUnion\n  {s : set α} {c : set (set α)} (hs : compact s)\n  (hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :\n  ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=\nby rw sUnion_eq_Union at hc₂;\n   simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂\n\nnamespace metric\n\n/-- Boundedness of a subset of a metric space. We formulate the definition to work\neven in the empty space. -/\ndef bounded (s : set α) : Prop :=\n∃C, ∀x y ∈ s, dist x y ≤ C\n\nsection bounded\nvariables {x : α} {s t : set α} {r : ℝ}\n\n@[simp] lemma bounded_empty : bounded (∅ : set α) :=\n⟨0, by simp⟩\n\nlemma bounded_iff_mem_bounded : bounded s ↔ ∀ x ∈ s, bounded s :=\n⟨λ h _ _, h, λ H, begin\n  classical, by_cases s = ∅,\n  { subst s, exact ⟨0, by simp⟩ },\n  { rcases exists_mem_of_ne_empty h with ⟨x, hx⟩,\n    exact H x hx }\nend⟩\n\n/-- Subsets of a bounded set are also bounded -/\nlemma bounded.subset (incl : s ⊆ t) : bounded t → bounded s :=\nExists.imp $ λ C hC x y hx hy, hC x y (incl hx) (incl hy)\n\n/-- Closed balls are bounded -/\nlemma bounded_closed_ball : bounded (closed_ball x r) :=\n⟨r + r, λ y z hy hz, begin\n  simp only [mem_closed_ball] at *,\n  calc dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _\n            ... ≤ r + r : add_le_add hy hz\nend⟩\n\n/-- Open balls are bounded -/\nlemma bounded_ball : bounded (ball x r) :=\nbounded_closed_ball.subset ball_subset_closed_ball\n\n/-- Given a point, a bounded subset is included in some ball around this point -/\nlemma bounded_iff_subset_ball (c : α) : bounded s ↔ ∃r, s ⊆ closed_ball c r :=\nbegin\n  split; rintro ⟨C, hC⟩,\n  { classical, by_cases s = ∅,\n    { subst s, exact ⟨0, by simp⟩ },\n    { rcases exists_mem_of_ne_empty h with ⟨x, hx⟩,\n      exact ⟨C + dist x c, λ y hy, calc\n        dist y c ≤ dist y x + dist x c : dist_triangle _ _ _\n            ... ≤ C + dist x c : add_le_add_right (hC y x hy hx) _⟩ } },\n  { exact bounded_closed_ball.subset hC }\nend\n\n/-- The union of two bounded sets is bounded iff each of the sets is bounded -/\n@[simp] lemma bounded_union :\n  bounded (s ∪ t) ↔ bounded s ∧ bounded t :=\n⟨λh, ⟨h.subset (by simp), h.subset (by simp)⟩,\nbegin\n  rintro ⟨hs, ht⟩,\n  refine bounded_iff_mem_bounded.2 (λ x _, _),\n  rw bounded_iff_subset_ball x at hs ht ⊢,\n  rcases hs with ⟨Cs, hCs⟩, rcases ht with ⟨Ct, hCt⟩,\n  exact ⟨max Cs Ct, union_subset\n    (subset.trans hCs $ closed_ball_subset_closed_ball $ le_max_left _ _)\n    (subset.trans hCt $ closed_ball_subset_closed_ball $ le_max_right _ _)⟩,\nend⟩\n\n/-- A finite union of bounded sets is bounded -/\nlemma bounded_bUnion {I : set β} {s : β → set α} (H : finite I) :\n  bounded (⋃i∈I, s i) ↔ ∀i ∈ I, bounded (s i) :=\nfinite.induction_on H (by simp) $ λ x I _ _ IH,\nby simp [or_imp_distrib, forall_and_distrib, IH]\n\n/-- A compact set is bounded -/\nlemma bounded_of_compact {s : set α} (h : compact s) : bounded s :=\n-- We cover the compact set by finitely many balls of radius 1,\n-- and then argue that a finite union of bounded sets is bounded\nlet ⟨t, ht, fint, subs⟩ := finite_cover_balls_of_compact h zero_lt_one in\nbounded.subset subs $ (bounded_bUnion fint).2 $ λ i hi, bounded_ball\n\n/-- A finite set is bounded -/\nlemma bounded_of_finite {s : set α} (h : finite s) : bounded s :=\nbounded_of_compact $ compact_of_finite h\n\n/-- A singleton is bounded -/\nlemma bounded_singleton {x : α} : bounded ({x} : set α) :=\nbounded_of_finite $ finite_singleton _\n\n/-- Characterization of the boundedness of the range of a function -/\nlemma bounded_range_iff {f : β → α} : bounded (range f) ↔ ∃C, ∀x y, dist (f x) (f y) ≤ C :=\nexists_congr $ λ C, ⟨\n  λ H x y, H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩,\n  by rintro H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact H x y⟩\n\n/-- In a compact space, all sets are bounded -/\nlemma bounded_of_compact_space [compact_space α] : bounded s :=\n(bounded_of_compact compact_univ).subset (subset_univ _)\n\n/-- In a proper space, a set is compact if and only if it is closed and bounded -/\nlemma compact_iff_closed_bounded [proper_space α] :\n  compact s ↔ is_closed s ∧ bounded s :=\n⟨λ h, ⟨closed_of_compact _ h, bounded_of_compact h⟩, begin\n  rintro ⟨hc, hb⟩,\n  classical, by_cases s = ∅, {simp [h, compact_empty]},\n  rcases exists_mem_of_ne_empty h with ⟨x, hx⟩,\n  rcases (bounded_iff_subset_ball x).1 hb with ⟨r, hr⟩,\n  exact compact_of_is_closed_subset (proper_space.compact_ball x r) hc hr\nend⟩\n\nend bounded\n\nsection diam\nvariables {s : set α} {x y : α}\n\n/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter\nshould be infinite, we express it in terms of the emetric.diameter -/\ndef diam (s : set α) : ℝ := ennreal.to_real (emetric.diam s)\n\n/-- The diameter of a set is always nonnegative -/\nlemma diam_nonneg : 0 ≤ diam s :=\nby simp [diam]\n\n/-- The empty set has zero diameter -/\n@[simp] lemma diam_empty : diam (∅ : set α) = 0 :=\nby simp [diam]\n\n/-- A singleton has zero diameter -/\n@[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=\nby simp [diam]\n\n/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/\nlemma bounded_iff_diam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ :=\nbegin\n  classical, by_cases hs : s = ∅,\n  { simp [hs] },\n  { rcases ne_empty_iff_exists_mem.1 hs with ⟨x, hx⟩,\n    split,\n    { assume bs,\n      rcases (bounded_iff_subset_ball x).1 bs with ⟨r, hr⟩,\n      have r0 : 0 ≤ r := by simpa [closed_ball] using hr hx,\n      have : emetric.diam s < ⊤ := calc\n        emetric.diam s ≤ emetric.diam (emetric.closed_ball x (ennreal.of_real r)) :\n          by rw emetric_closed_ball r0; exact emetric.diam_mono hr\n        ... ≤ 2 * (ennreal.of_real r) : emetric.diam_closed_ball\n        ... < ⊤ : begin apply ennreal.lt_top_iff_ne_top.2, simp [ennreal.mul_eq_top], end,\n      exact ennreal.lt_top_iff_ne_top.1 this },\n    { assume ds,\n      have : s ⊆ closed_ball x (ennreal.to_real (emetric.diam s)),\n      { rw [← emetric_closed_ball ennreal.to_real_nonneg, ennreal.of_real_to_real ds],\n        exact λy hy, emetric.edist_le_diam_of_mem hy hx },\n      exact bounded.subset this (bounded_closed_ball) }}\nend\n\n/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.\nThis lemma makes it possible to avoid side conditions in some situations -/\nlemma diam_eq_zero_of_unbounded (h : ¬(bounded s)) : diam s = 0 :=\nbegin\n  simp only [bounded_iff_diam_ne_top, not_not, ne.def] at h,\n  simp [diam, h]\nend\n\n/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/\nlemma diam_mono {s t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t :=\nbegin\n  unfold diam,\n  rw ennreal.to_real_le_to_real (bounded_iff_diam_ne_top.1 (bounded.subset h ht)) (bounded_iff_diam_ne_top.1 ht),\n  exact emetric.diam_mono h\nend\n\n/-- The distance between two points in a set is controlled by the diameter of the set. -/\nlemma dist_le_diam_of_mem (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=\nbegin\n  rw [diam, dist_edist],\n  rw ennreal.to_real_le_to_real (edist_ne_top _ _) (bounded_iff_diam_ne_top.1 h),\n  exact emetric.edist_le_diam_of_mem hx hy\nend\n\n/-- If the distance between any two points in a set is bounded by some constant, this constant\nbounds the diameter. -/\nlemma diam_le_of_forall_dist_le {d : real} (hd : d ≥ 0) (h : ∀x y ∈ s, dist x y ≤ d) : diam s ≤ d :=\nbegin\n  have I : emetric.diam s ≤ ennreal.of_real d,\n  { refine emetric.diam_le_of_forall_edist_le (λx y hx hy, _),\n    rw [edist_dist],\n    exact ennreal.of_real_le_of_real (h x y hx hy) },\n  have A : emetric.diam s ≠ ⊤ :=\n    ennreal.lt_top_iff_ne_top.1 (lt_of_le_of_lt I (ennreal.lt_top_iff_ne_top.2 (by simp))),\n  rw [← ennreal.to_real_of_real hd, diam, ennreal.to_real_le_to_real A],\n  { exact I },\n  { simp }\nend\n\n/-- The diameter of a union is controlled by the sum of the diameters, and the distance between\nany two points in each of the sets. This lemma is true without any side condition, since it is\nobviously true if `s ∪ t` is unbounded. -/\nlemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) : diam (s ∪ t) ≤ diam s + dist x y + diam t :=\nhave I1 : ¬(bounded (s ∪ t)) → diam (s ∪ t) ≤ diam s + dist x y + diam t := λh, calc\n  diam (s ∪ t) = 0 + 0 + 0 : by simp [diam_eq_zero_of_unbounded h]\n  ... ≤ diam s + dist x y + diam t : add_le_add (add_le_add diam_nonneg dist_nonneg) diam_nonneg,\nhave I2 : (bounded (s ∪ t)) → diam (s ∪ t) ≤ diam s + dist x y + diam t := λh,\nbegin\n  have : bounded s := bounded.subset (subset_union_left _ _) h,\n  have : bounded t := bounded.subset (subset_union_right _ _) h,\n  have A : ∀a ∈ s, ∀b ∈ t, dist a b ≤ diam s + dist x y + diam t := λa ha b hb, calc\n    dist a b ≤ dist a x + dist x y + dist y b : dist_triangle4 _ _ _ _\n    ... ≤ diam s + dist x y + diam t :\n      add_le_add (add_le_add (dist_le_diam_of_mem ‹bounded s› ha xs) (le_refl _)) (dist_le_diam_of_mem ‹bounded t› yt hb),\n  have B : ∀a b ∈ s ∪ t, dist a b ≤ diam s + dist x y + diam t := λa b ha hb,\n  begin\n    cases (mem_union _ _ _).1 ha with h'a h'a; cases (mem_union _ _ _).1 hb with h'b h'b,\n    { calc dist a b ≤ diam s : dist_le_diam_of_mem ‹bounded s› h'a h'b\n           ... = diam s + (0 + 0) : by simp\n           ... ≤ diam s + (dist x y + diam t) : add_le_add (le_refl _) (add_le_add dist_nonneg diam_nonneg)\n           ... = diam s + dist x y + diam t : by simp only [add_comm, eq_self_iff_true, add_left_comm] },\n    { exact A a h'a b h'b },\n    { have Z := A b h'b a h'a, rwa [dist_comm] at Z },\n    { calc dist a b ≤ diam t : dist_le_diam_of_mem ‹bounded t› h'a h'b\n           ... = (0 + 0) + diam t : by simp\n           ... ≤ (diam s + dist x y) + diam t : add_le_add (add_le_add diam_nonneg dist_nonneg) (le_refl _) }\n  end,\n  have C : 0 ≤ diam s + dist x y + diam t := calc\n    0 = 0 + 0 + 0 : by simp\n    ... ≤ diam s + dist x y + diam t : add_le_add (add_le_add diam_nonneg dist_nonneg) diam_nonneg,\n  exact diam_le_of_forall_dist_le C B\nend,\nclassical.by_cases I2 I1\n\n/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/\nlemma diam_union' {t : set α} (h : s ∩ t ≠ ∅) : diam (s ∪ t) ≤ diam s + diam t :=\nbegin\n  rcases ne_empty_iff_exists_mem.1 h with ⟨x, ⟨xs, xt⟩⟩,\n  simpa using diam_union xs xt\nend\n\n/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/\nlemma diam_closed_ball {r : ℝ} (h : r ≥ 0) : diam (closed_ball x r) ≤ 2 * r :=\ndiam_le_of_forall_dist_le (mul_nonneg (by norm_num) h) $ λa b ha hb, calc\n  dist a b ≤ dist a x + dist b x : dist_triangle_right _ _ _\n  ... ≤ r + r : add_le_add ha hb\n  ... = 2 * r : by simp [mul_two, mul_comm]\n\n/-- The diameter of a ball of radius `r` is at most `2 r`. -/\nlemma diam_ball {r : ℝ} (h : r ≥ 0) : diam (ball x r) ≤ 2 * r :=\nle_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)\n\nend diam\n\nend metric\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7525949879314285}}
{"text": "import galois.tactic\n       galois.list.preds\n\nuniverses u v w\n/-- Defines a subset of a type -/\ndef subset (A : Sort u) := A → Prop\n\nnamespace subset\nsection\nparameter {A : Type u}\n/-- A subset that is the same for all members of the type -/\ndef const (P : Prop) : subset A := λ _, P\n\n/-- The subset with all memebers -/\ndef tt : subset A := const true\n\n/-- The empty subset -/\ndef ff : subset A := const false\n\n/-- Subset P is included in subset Q if all members of P are also in Q -/\ndef included (P Q : subset A) := ∀ x : A, P x → Q x\n\n/-- The intersection of two subsets contains all shared members -/\ndef bintersection (P Q : subset A) := λ x, P x ∧ Q x\n\n/-- The union of two subsets contains all members of both-/\ndef bunion (P Q : subset A) := λ x, P x ∨ Q x\n\n/-- Lifting of prop implication --/\ndef tImp {T : Type u} (P Q : subset T) : subset T :=\n  λ x, P x → Q x\n\ninfixr `=>` : 50 := tImp\n\n\ninstance subset_has_union : has_union (subset A)\n  := ⟨ bunion ⟩\n\ninstance subset_has_inter : has_inter (subset A)\n  := ⟨ bintersection ⟩\n\ninstance subset_has_le : has_le (subset A):= ⟨ included ⟩\n\n/-- If two subsets include eachother they are the same -/\nlemma included_eq {P Q : subset A}\n  (PQ : P ≤ Q) (QP : Q ≤ P) : P = Q\n:= begin\napply funext, intros x, apply propext, split,\napply PQ, apply QP\nend\n\n/-- Every set includes itself -/\nlemma included_refl (P : subset A)\n  : P ≤ P := λ _ H, H\n\n/-- Transitivity of inclusion -/\nlemma included_trans {P Q R : subset A}\n  (PQ : P ≤ Q) (QR : Q ≤ R)\n  : P ≤ R :=\nbegin\nintros x HP, apply QR, apply PQ, assumption\nend\n\n/-- Intersection is monotonic, it grows as either of its arguments grows -/\nlemma bintersection_mono {P P' Q Q' : subset A}\n  (HP : P ≤ P') (HQ : Q ≤ Q')\n  : P ∩ Q ≤ P' ∩ Q'\n:= begin\nintros x H, induction H with Hl Hr,\nconstructor, apply HP,  assumption,\napply HQ, assumption\nend\n\n/-- Union is monotonic, it grows as either of its arguments grows -/\nlemma bunion_mono {P P' Q Q' : subset A}\n  (HP : P ≤ P') (HQ : Q ≤ Q')\n  : P ∪ Q ≤ P' ∪ Q'\n:= begin\nintros x H, induction H with Hl Hr,\n{ apply or.inl, apply HP, assumption },\n{ apply or.inr, apply HQ, assumption }\nend\n\n/--  Intersection such that: The intersection of all subsets defined by F -/\ndef intersection_st (F : subset A → Prop)\n  : subset A\n  := λ x, ∀ P, F P → P x\n\n/-- Union such that: The union of all subsets defined by F -/\ninductive union_st (F : subset A → Prop)\n  (x : A) : Prop\n| mk : ∀ P, F P → P x → union_st\n\ndef union_st' (F : subset A → Prop) : subset A := union_st F\n\n/-- union_st distributes over and -/\nlemma union_st_bintersection {F G : subset A → Prop}\n  : union_st' (λ x, F x ∧ G x) ≤ union_st' F ∩ union_st' G\n:= begin\nintros x H,\ninduction H with P FGP Px,\ninduction FGP with FP GP,\nconstructor; constructor; assumption\nend\n/-- union st is monotone -/\nlemma union_st_mono {F G : subset (subset A)}\n  (H : F ≤ G)\n  : union_st' F ≤ union_st' G\n:= begin\nintros x H,\ninduction H with P FP Px,\nconstructor, apply H, assumption, assumption\nend\n\n/-- Every set is contained in tt -/\nlemma tt_top (P : subset A) : P ≤ tt :=\nbegin intros x H, constructor end\n\n/-- false is contained in every set -/\nlemma ff_bot (P : subset A) : ff ≤ P :=\nbegin intros x H, exfalso, apply H, end\n\ndefinition from_list' (l : list A) : subset A :=\nfun x :A, x ∈ l\n\n/-- Create a subset of items contained in a list -/\ninductive from_list : list A → subset A\n| here : ∀ {x xs}, (from_list (x :: xs)) x\n| there : ∀ {x y xs}, from_list xs y → from_list (x :: xs) y\n\n/-- Union of an indexed set such that : If we have a set of indexes\n    defined by P, and a mapping from those indexes to subsets defined\n    by F, this function gives the union of the range of F over P -/\ninductive union_ix_st {Ix : Type v} (P : Ix → Prop) (F : Ix → subset A) (x : A) : Prop\n| mk : ∀ ix, P ix → F ix x → union_ix_st\n\n/-- Intersection of an indexed set: If we have an indexed collection of\n    subsets, this is the intersection over the entire range of those subsets -/\ndef intersection_ix {Ix : Type v} (F : Ix → subset A) : subset A\n  := λ x, ∀ ix : Ix, F ix x\n\n/-- Intersection of an indexed set: If we have an indexed collection of\n    subsets, this is the union over the entire range of those subsets -/\ndef union_ix {Ix : Type v} (F : Ix → subset A) : subset A :=\n  union_ix_st (λ _, true) F\n\n/-- If we increase the domain of the indexes, the union of the range increases as well -/\nlemma union_ix_st_mono {Ix : Type v} {P Q : subset Ix} {F G : Ix → subset A}\n  (H1 : P ≤ Q)\n  (H : ∀ ix : Ix, F ix ≤ G ix)\n  : @has_le.le _ subset_has_le (union_ix_st P F) (union_ix_st Q G)\n:= begin\nintros x H,\ninduction H with P _ FP Px,\nconstructor, apply H1, assumption, apply H, assumption,\nend\n\n/-- If we increase the range of the indexed sets, union ix\n    of those index sets increases -/\nlemma union_ix_mono {Ix : Type v} {F G : Ix → subset A}\n  (H : ∀ ix : Ix, F ix ≤ G ix)\n  : union_ix F ≤ union_ix G\n:= begin\napply union_ix_st_mono, intros x H', apply H',\nassumption\nend\n\nlemma intersection_ix_mono {Ix : Type v} {F G : Ix → subset A}\n  (H : ∀ ix : Ix, F ix ≤ G ix)\n  : intersection_ix F ≤ intersection_ix G\n:= begin\nintros x H' ix, apply H, apply H'\nend\n\nlemma imp_or (P Q : subset A)\n  : (P ≤ Q) = (P ∪ Q = Q)\n:= begin\napply propext, split; intros H,\n{ apply included_eq, intros x H',\n  induction H' with H' H', apply H, assumption, assumption,\n  intros x Qx, apply or.inr, assumption },\n{ rw ← H, intros x Px, apply or.inl, assumption }\nend\n\nlemma imp_and (P Q : subset A)\n  : (P ≤ Q) = (P = P ∩ Q)\n:= begin\napply propext, split; intros H,\n{ apply included_eq, intros x Px,\n  constructor, assumption, apply H, assumption,\n  intros x PQx, induction PQx with H1 H2,\n  assumption },\n{ rw H, intros x PQx, induction PQx with H1 H2,\n  assumption }\nend\n\nlemma and_distr_l (P Q R : subset A)\n : (P ∩ Q) ∪ (P ∩ R) = P ∩ (Q ∪ R)\n:= begin\napply included_eq; intros x Hx,\ninduction Hx with H H, induction H with H H',\nconstructor, assumption, apply or.inl, assumption,\ninduction H with H H', constructor, assumption,\napply or.inr, assumption,\ninduction Hx with H H', induction H' with H' H',\napply or.inl, constructor; assumption,\napply or.inr, constructor; assumption\nend\n\nlemma inter_comm (P Q : subset A) : P ∩ Q = Q ∩ P\n:= begin\napply funext, intros x, simp [has_inter.inter],\nunfold bintersection, rw and_comm,\nend\n\nend\n\nlemma intersection_ix_precompose {A : Type u} {B : Type w}\n  {Ix : Type v} (F : Ix → subset B) (f : A → B)\n  : intersection_ix F ∘ f = intersection_ix (λ ix, F ix ∘ f)\n:= begin\nunfold intersection_ix\nend\n\n\n/-- Definition of monotone for unary functions over subsets -/\ndef monotone {A : Type u} {B : Type v} (F : subset A → subset B) :=\n  ∀ P Q, P ≤ Q → F P ≤ F Q\n\nend subset\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/subset/subset.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7525949767516279}}
{"text": "/-\nCopyright (c) 2019 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Sébastien Gouëzel\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 ⊕ Y`. The corresponding metric quotient is `optimal_GH_coupling X Y`.\n-/\n\nnoncomputable theory\nopen_locale classical topological_space 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 ⊕ 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 ⊕ Y) × (X ⊕ Y)) → ℝ\n@[reducible] private def Cb : Type* := bounded_continuous_function ((X ⊕ Y) × (X ⊕ Y)) ℝ\n\nprivate def max_var : ℝ≥0 :=\n2 * ⟨diam (univ : set X), diam_nonneg⟩ + 1 + 2 * ⟨diam (univ : set Y), diam_nonneg⟩\n\nprivate lemma one_le_max_var : 1 ≤ max_var X Y := calc\n  (1 : real) = 2 * 0 + 1 + 2 * 0 : by simp\n  ... ≤ 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 ⊕ 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 | (((((∀ x y : X, f (sum.inl x, sum.inl y) = dist x y)\n    ∧ (∀ x y : Y, f (sum.inr x, sum.inr y) = dist x y))\n    ∧ (∀ x y,     f (x, y) = f (y, x)))\n    ∧ (∀ x y z,   f (x, z) ≤ f (x, y) + f (y, z)))\n    ∧ (∀ x,       f (x, x) = 0))\n    ∧ (∀ x y,     f (x, y) ≤ 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 : _ → ℝ) ∈ 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 ⊕ Y}\nlocal attribute [instance, priority 10] inhabited_of_nonempty'\n\nprivate lemma max_var_bound : dist x y ≤ max_var X Y := calc\n  dist x y ≤ diam (univ : set (X ⊕ Y)) :\n    dist_le_diam_of_mem bounded_of_compact_space (mem_univ _) (mem_univ _)\n  ... = diam (inl '' (univ : set X) ∪ inr '' (univ : set Y)) :\n    by apply congr_arg; ext x y z; cases x; simp [mem_univ, mem_range_self]\n  ... ≤ diam (inl '' (univ : set X)) + dist (inl (default X)) (inr (default Y)) +\n          diam (inr '' (univ : set Y)) :\n    diam_union (mem_image_of_mem _ (mem_univ _)) (mem_image_of_mem _ (mem_univ _))\n  ... = diam (univ : set X) + (dist (default X) (default X) + 1 + dist (default Y) (default Y)) +\n          diam (univ : set Y) :\n    by { rw [isometry_on_inl.diam_image, isometry_on_inr.diam_image], refl }\n  ... = 1 * diam (univ : set X) + 1 + 1 * diam (univ : set Y) : by simp\n  ... ≤ 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 ∈ candidates X Y) : f (x, y) = f (y, x) := fA.1.1.1.2 x y\n\nprivate lemma candidates_triangle (fA : f ∈ candidates X Y) : f (x, z) ≤ f (x, y) + f (y, z) :=\n  fA.1.1.2 x y z\n\nprivate lemma candidates_refl (fA : f ∈ candidates X Y) : f (x, x) = 0 := fA.1.2 x\n\nprivate lemma candidates_nonneg (fA : f ∈ candidates X Y) : 0 ≤ f (x, y) :=\nbegin\n  have : 0 ≤ 2 * f (x, y) := calc\n    0 = f (x, x) : (candidates_refl fA).symm\n    ... ≤ 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 ∈ 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 ∈ 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 ∈ candidates X Y) : f (x, y) ≤ 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 ∈ candidates X Y) :\n  ∀ {x y : X ⊕ Y}, f (x, y) ≤ 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    ... ≤ 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) ≤ max_var X Y : candidates_le_max_var fA\n    ... = max_var X Y * 1 : by simp\n    ... ≤ 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) ≤ max_var X Y : candidates_le_max_var fA\n    ... = max_var X Y * 1 : by simp\n    ... ≤ 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    ... ≤ 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 ∈ candidates X Y) :\n  f (x, y) - f (z, t) ≤ 2 * max_var X Y * dist (x, y) (z, t) :=\ncalc\n  f (x, y) - f(z, t) ≤ f (x, t) + f (t, y) - f (z, t) : sub_le_sub_right (candidates_triangle fA) _\n  ... ≤ (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  ... ≤ 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  ... ≤ 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 ∈ candidates X Y) :\n  lipschitz_with (2 * max_var X Y) f :=\nbegin\n  apply lipschitz_with.of_dist_le_mul,\n  rintros ⟨x, y⟩ ⟨z, t⟩,\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 ∈ candidates X Y) : Cb X Y :=\nbounded_continuous_function.mk_of_compact ⟨f, (candidates_lipschitz fA).continuous⟩\n\nlemma candidates_b_of_candidates_mem (f : prod_space_fun X Y) (fA : f ∈ candidates X Y) :\n  candidates_b_of_candidates f fA ∈ candidates_b X Y := fA\n\n/-- The distance on `X ⊕ Y` is a candidate -/\nprivate lemma dist_mem_candidates : (λp : (X ⊕ Y) × (X ⊕ Y), dist p.1 p.2) ∈ 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 (λa y z, dist_triangle_left _ _ _)\n    <|> exact (λx y, by refl)\n    <|> exact (λx y, max_var_bound) }\nend\n\n/-- The distance on `X ⊕ 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 ∈ candidates_b X Y :=\ncandidates_b_of_candidates_mem _ _\n\nprivate lemma candidates_b_nonempty : (candidates_b X Y).nonempty :=\n⟨_,  candidates_b_dist_mem_candidates_b⟩\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 : ∀ x y, is_closed {f : Cb X Y | f (inl x, inl y) = dist x y} :=\n    λx y, is_closed_eq continuous_evalx continuous_const,\n  have I2 : ∀ x y, is_closed {f : Cb X Y | f (inr x, inr y) = dist x y } :=\n    λx y, is_closed_eq continuous_evalx continuous_const,\n  have I3 : ∀ x y, is_closed {f : Cb X Y | f (x, y) = f (y, x)} :=\n    λx y, is_closed_eq continuous_evalx continuous_evalx,\n  have I4 : ∀ x y z, is_closed {f : Cb X Y | f (x, z) ≤ f (x, y) + f (y, z)} :=\n    λx y z, is_closed_le continuous_evalx (continuous_evalx.add continuous_evalx),\n  have I5 : ∀ x, is_closed {f : Cb X Y | f (x, x) = 0} :=\n    λx, is_closed_eq continuous_evalx continuous_const,\n  have I6 : ∀ x y, is_closed {f : Cb X Y | f (x, y) ≤ max_var X Y} :=\n    λx y, is_closed_le continuous_evalx continuous_const,\n  have : candidates_b X Y = (⋂x y, {f : Cb X Y | f ((@inl X Y x), (@inl X Y y)) = dist x y})\n               ∩ (⋂x y, {f : Cb X Y | f ((@inr X Y x), (@inr X Y y)) = dist x y})\n               ∩ (⋂x y, {f : Cb X Y | f (x, y) = f (y, x)})\n               ∩ (⋂x y z, {f : Cb X Y | f (x, z) ≤ f (x, y) + f (y, z)})\n               ∩ (⋂x, {f : Cb X Y | f (x, x) = 0})\n               ∩ (⋂x y, {f : Cb X Y | f (x, y) ≤ max_var X Y}),\n  { ext, simp only [candidates_b, candidates, mem_inter_eq, 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 compact_candidates_b : is_compact (candidates_b X Y) :=\nbegin\n  refine arzela_ascoli₂ (Icc 0 (max_var X Y)) is_compact_Icc (candidates_b X Y)\n  closed_candidates_b _ _,\n  { rintros f ⟨x1, x2⟩ hf,\n    simp only [set.mem_Icc],\n    exact ⟨candidates_nonneg hf, candidates_le_max_var hf⟩ },\n  { refine equicontinuous_of_continuity_modulus (λt, 2 * max_var X Y * t) _ _ _,\n    { have : tendsto (λ (t : ℝ), 2 * (max_var X Y : ℝ) * t) (𝓝 0) (𝓝 (2 * max_var X Y * 0)) :=\n        tendsto_const_nhds.mul tendsto_id,\n      simpa using this },\n    { assume x y f hf,\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 (⨆ x, ⨅ y, f (inl x, inr y)) (⨆ y, ⨅ 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 `ℝ`, 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 : ℝ) {x : X} :\n  bdd_below (range (λ (y : Y), f (inl x, inr y) + C)) :=\nlet ⟨cf, hcf⟩ := (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 in\n⟨cf + C, forall_range_iff.2 (λi, add_le_add_right ((λx, hcf (mem_range_self x)) _) _)⟩\n\nprivate lemma HD_bound_aux1 (f : Cb X Y) (C : ℝ) :\n  bdd_above (range (λ (x : X), ⨅ y, f (inl x, inr y) + C)) :=\nbegin\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).2 with ⟨Cf, hCf⟩,\n  refine ⟨Cf + C, forall_range_iff.2 (λx, _)⟩,\n  calc (⨅ y, f (inl x, inr y) + C) ≤ f (inl x, inr (default Y)) + C :\n    cinfi_le (HD_below_aux1 C) (default Y)\n    ... ≤ Cf + C : add_le_add ((λx, hCf (mem_range_self x)) _) (le_refl _)\nend\n\nlemma HD_below_aux2 {f : Cb X Y} (C : ℝ) {y : Y} :\n  bdd_below (range (λ (x : X), f (inl x, inr y) + C)) :=\nlet ⟨cf, hcf⟩ := (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 in\n⟨cf + C, forall_range_iff.2 (λi, add_le_add_right ((λx, hcf (mem_range_self x)) _) _)⟩\n\nprivate lemma HD_bound_aux2 (f : Cb X Y) (C : ℝ) :\n  bdd_above (range (λ (y : Y), ⨅ x, f (inl x, inr y) + C)) :=\nbegin\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).2 with ⟨Cf, hCf⟩,\n  refine ⟨Cf + C, forall_range_iff.2 (λy, _)⟩,\n  calc (⨅ x, f (inl x, inr y) + C) ≤ f (inl (default X), inr y) + C :\n    cinfi_le (HD_below_aux2 C) (default X)\n  ... ≤ Cf + C : add_le_add ((λx, hCf (mem_range_self x)) _) (le_refl _)\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) ≤ diam (univ : set X) + 1 + diam (univ : set Y) :=\nbegin\n  refine max_le (csupr_le (λx, _)) (csupr_le (λy, _)),\n  { have A : (⨅ y, candidates_b_dist X Y (inl x, inr y)) ≤\n      candidates_b_dist X Y (inl x, inr (default Y)) :=\n      cinfi_le (by simpa using HD_below_aux1 0) (default Y),\n    have B : dist (inl x) (inr (default Y)) ≤ diam (univ : set X) + 1 + diam (univ : set Y) := calc\n      dist (inl x) (inr (default Y)) = dist x (default X) + 1 + dist (default Y) (default Y) : rfl\n      ... ≤ diam (univ : set X) + 1 + diam (univ : set Y) :\n      begin\n        apply add_le_add (add_le_add _ (le_refl _)),\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 ℝ },\n        any_goals { exact ordered_add_comm_monoid.to_covariant_class_right ℝ },\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 : (⨅ x, candidates_b_dist X Y (inl x, inr y)) ≤\n      candidates_b_dist X Y (inl (default X), inr y) :=\n      cinfi_le (by simpa using HD_below_aux2 0) (default X),\n    have B : dist (inl (default X)) (inr y) ≤ diam (univ : set X) + 1 + diam (univ : set Y) := calc\n      dist (inl (default X)) (inr y) = dist (default X) (default X) + 1 + dist (default Y) y : rfl\n      ... ≤ diam (univ : set X) + 1 + diam (univ : set Y) :\n      begin\n        apply add_le_add (add_le_add _ (le_refl _)),\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 ℝ },\n        any_goals { exact ordered_add_comm_monoid.to_covariant_class_right ℝ },\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  (⨆ x, ⨅ y, f (inl x, inr y)) ≤ (⨆ x, ⨅ 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 ⟨cg, hcg⟩,\n  have Hcg : ∀ x, cg ≤ g x := λx, hcg (mem_range_self x),\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 with ⟨cf, hcf⟩,\n  have Hcf : ∀ x, cf ≤ f x := λx, 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 : (⨆ x, ⨅ y, f (inl x, inr y)) ≤ ⨆ x, ⨅ y, g (inl x, inr y) + dist f g :=\n    csupr_le_csupr (HD_bound_aux1 _ (dist f g))\n      (λx, cinfi_le_cinfi ⟨cf, forall_range_iff.2(λi, Hcf _)⟩ (λy, 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 : ∀ x, (⨅ y, g (inl x, inr y)) + dist f g = ⨅ y, g (inl x, inr y) + dist f g,\n  { assume x,\n    refine map_cinfi_of_continuous_at_of_monotone (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { show bdd_below (range (λ (y : Y), g (inl x, inr y))),\n        from ⟨cg, forall_range_iff.2(λi, Hcg _)⟩ } },\n  have E2 : (⨆ x, ⨅ y, g (inl x, inr y)) + dist f g = ⨆ x, (⨅ y, g (inl x, inr y)) + dist f g,\n  { refine map_csupr_of_continuous_at_of_monotone (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { by 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  (⨆ y, ⨅ x, f (inl x, inr y)) ≤ (⨆ y, ⨅ 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 ⟨cg, hcg⟩,\n  have Hcg : ∀ x, cg ≤ g x := λx, hcg (mem_range_self x),\n  rcases (real.bounded_iff_bdd_below_bdd_above.1 f.bounded_range).1 with ⟨cf, hcf⟩,\n  have Hcf : ∀ x, cf ≤ f x := λx, 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 : (⨆ y, ⨅ x, f (inl x, inr y)) ≤ ⨆ y, ⨅ x, g (inl x, inr y) + dist f g :=\n    csupr_le_csupr (HD_bound_aux2 _ (dist f g))\n      (λy, cinfi_le_cinfi  ⟨cf, forall_range_iff.2(λi, Hcf _)⟩ (λy, 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 : ∀ y, (⨅ x, g (inl x, inr y)) + dist f g = ⨅ x, g (inl x, inr y) + dist f g,\n  { assume y,\n    refine map_cinfi_of_continuous_at_of_monotone (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { show bdd_below (range (λx:X, g (inl x, inr y))),\n        from ⟨cg, forall_range_iff.2 (λi, Hcg _)⟩ } },\n  have E2 : (⨆ y, ⨅ x, g (inl x, inr y)) + dist f g = ⨆ y, (⨅ x, g (inl x, inr y)) + dist f g,\n  { refine map_csupr_of_continuous_at_of_monotone (continuous_at_id.add continuous_at_const) _ _,\n    { assume x y hx, simpa },\n    { by 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 ≤ 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 → ℝ) :=\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 : ∃ f ∈ candidates_b X Y, ∀ g ∈ candidates_b X Y, HD f ≤ HD g :=\ncompact_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 ∈ 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 ∈ candidates_b X Y) :\n  HD (optimal_GH_dist X Y) ≤ HD g :=\nlet ⟨Z1, Z2⟩ := classical.some_spec (exists_minimizer X Y) in Z2 g hg\n\n/-- With the optimal candidate, construct a premetric space structure on `X ⊕ 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 ⊕ Y) :=\n{ dist := λp q, optimal_GH_dist X Y (p, q),\n  dist_self := λx, candidates_refl (optimal_GH_dist_mem_candidates_b X Y),\n  dist_comm := λx y, candidates_symm (optimal_GH_dist_mem_candidates_b X Y),\n  dist_triangle := λx y z, candidates_triangle (optimal_GH_dist_mem_candidates_b X Y) }\n\nlocal attribute [instance] premetric_optimal_GH_dist pseudo_metric.dist_setoid\n\n/-- A metric space which realizes the optimal coupling between `X` and `Y` -/\n@[derive metric_space, nolint has_inhabited_instance]\ndefinition optimal_GH_coupling : Type* :=\npseudo_metric_quot (X ⊕ Y)\n\n/-- Injection of `X` in the optimal coupling between `X` and `Y` -/\ndef optimal_GH_injl (x : X) : optimal_GH_coupling X Y := ⟦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) :=\nbegin\n  refine isometry_emetric_iff_metric.2 (λx y, _),\n  change dist ⟦inl x⟧ ⟦inl y⟧ = dist x y,\n  exact candidates_dist_inl (optimal_GH_dist_mem_candidates_b X Y) _ _,\nend\n\n/-- Injection of `Y` in the optimal coupling between `X` and `Y` -/\ndef optimal_GH_injr (y : Y) : optimal_GH_coupling X Y := ⟦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) :=\nbegin\n  refine isometry_emetric_iff_metric.2 (λx y, _),\n  change dist ⟦inr x⟧ ⟦inr y⟧ = dist x y,\n  exact candidates_dist_inr (optimal_GH_dist_mem_candidates_b X Y) _ _,\nend\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⟨begin\n  have : (univ : set (optimal_GH_coupling X Y)) =\n           (optimal_GH_injl X Y '' univ) ∪ (optimal_GH_injr X Y '' univ),\n  { refine subset.antisymm (λxc hxc, _) (subset_univ _),\n    rcases quotient.exists_rep xc with ⟨x, hx⟩,\n    cases x; rw ← hx,\n    { have : ⟦inl x⟧ = optimal_GH_injl X Y x := rfl,\n      rw this,\n      exact mem_union_left _ (mem_image_of_mem _ (mem_univ _)) },\n    { have : ⟦inr x⟧ = optimal_GH_injr X Y x := rfl,\n      rw this,\n      exact mem_union_right _ (mem_image_of_mem _ (mem_univ _)) } },\n  rw this,\n  exact (compact_univ.image (isometry_optimal_GH_injl X Y).continuous).union\n    (compact_univ.image (isometry_optimal_GH_injr X Y).continuous)\nend⟩\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 ∈ candidates_b X Y) :\n  Hausdorff_dist (range (optimal_GH_injl X Y)) (range (optimal_GH_injr X Y)) ≤ HD f :=\nbegin\n  refine le_trans (le_of_forall_le_of_dense (λr hr, _)) (HD_optimal_GH_dist_le X Y f h),\n  have A : ∀ x ∈ range (optimal_GH_injl X Y), ∃ y ∈ range (optimal_GH_injr X Y), dist x y ≤ r,\n  { assume x hx,\n    rcases mem_range.1 hx with ⟨z, hz⟩,\n    rw ← hz,\n    have I1 : (⨆ x, ⨅ y, optimal_GH_dist X Y (inl x, inr y)) < r :=\n      lt_of_le_of_lt (le_max_left _ _) hr,\n    have I2 : (⨅ y, optimal_GH_dist X Y (inl z, inr y)) ≤\n        ⨆ x, ⨅ 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 : (⨅ 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 ⟨r', r'range, hr'⟩,\n    rcases mem_range.1 r'range with ⟨z', hz'⟩,\n    existsi [optimal_GH_injr X Y z', mem_range_self _],\n    have : (optimal_GH_dist X Y) (inl z, inr z') ≤ r, by { rw hz', exact le_of_lt hr' },\n    exact this },\n  refine Hausdorff_dist_le_of_mem_dist _ A _,\n  { rcases exists_mem_of_nonempty X with ⟨xX, _⟩,\n    have : optimal_GH_injl X Y xX ∈ range (optimal_GH_injl X Y) := mem_range_self _,\n    rcases A _ this with ⟨y, yrange, hy⟩,\n    exact le_trans dist_nonneg hy },\n  { assume y hy,\n    rcases mem_range.1 hy with ⟨z, hz⟩,\n    rw ← hz,\n    have I1 : (⨆ y, ⨅ x, optimal_GH_dist X Y (inl x, inr y)) < r :=\n      lt_of_le_of_lt (le_max_right _ _) hr,\n    have I2 : (⨅ x, optimal_GH_dist X Y (inl x, inr z)) ≤\n        ⨆ y, ⨅ 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 : (⨅ 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 ⟨r', r'range, hr'⟩,\n    rcases mem_range.1 r'range with ⟨z', hz'⟩,\n    existsi [optimal_GH_injl X Y z', mem_range_self _],\n    have : (optimal_GH_dist X Y) (inl z', inr z) ≤ r, by { rw hz', exact le_of_lt hr' },\n    rw dist_comm,\n    exact this }\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": "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/gromov_hausdorff_realized.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.752491521900311}}
{"text": "/-\nCopyright (c) 2021 François Sunatori. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: François Sunatori\n-/\nimport analysis.complex.circle\nimport linear_algebra.determinant\nimport linear_algebra.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 `|` x `|` := complex.abs x\n\n/-- An element of the unit circle defines a `linear_isometry_equiv` from `ℂ` to itself, by\nrotation. -/\ndef rotation : circle →* (ℂ ≃ₗᵢ[ℝ] ℂ) :=\n{ to_fun := λ a,\n  { norm_map' := λ x, show |a * x| = |x|, by rw [complex.abs_mul, abs_coe_circle, one_mul],\n    ..distrib_mul_action.to_linear_equiv ℝ ℂ a },\n  map_one' := linear_isometry_equiv.ext $ one_smul _,\n  map_mul' := λ _ _, linear_isometry_equiv.ext $ mul_smul _ _ }\n\n@[simp] lemma rotation_apply (a : circle) (z : ℂ) : rotation a z = a * z := rfl\n\n@[simp] lemma rotation_symm (a : circle) : (rotation a).symm = rotation a⁻¹ :=\nlinear_isometry_equiv.ext $ λ 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 ≠ 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, ← 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 `ℂ ≃ₗᵢ[ℝ] ℂ` and checks if it is a rotation, returns an element of the\nunit circle. -/\n@[simps]\ndef rotation_of (e : ℂ ≃ₗᵢ[ℝ] ℂ) : circle :=\n⟨(e 1) / complex.abs (e 1), by simp⟩\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 : ℂ →ₗᵢ[ℝ] ℂ)\n  (h₃ : ∀ z, z + conj z = f z + conj (f z)) (z : ℂ) : (f z).re = z.re :=\nby simpa [ext_iff, add_re, add_im, conj_re, conj_im, ←two_mul,\n         (show (2 : ℝ) ≠ 0, by simp [two_ne_zero'])] using (h₃ z).symm\n\nlemma linear_isometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ}\n  (h₂ : ∀ z, (f z).re = z.re) (z : ℂ) :\n  (f z).im = z.im ∨ (f z).im = -z.im :=\nbegin\n  have h₁ := f.norm_map z,\n  simp only [complex.abs, norm_eq_abs] at h₁,\n  rwa [real.sqrt_inj (norm_sq_nonneg _) (norm_sq_nonneg _), norm_sq_apply (f z), norm_sq_apply z,\n    h₂, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h₁,\nend\n\nlemma linear_isometry.im_apply_eq_im {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) :\n  z + conj z = f z + conj (f z) :=\nbegin\n  have : ∥f z - 1∥ = ∥z - 1∥ := by rw [← f.norm_map (z - 1), f.map_sub, h],\n  apply_fun λ x, x ^ 2 at this,\n  simp only [norm_eq_abs, ←norm_sq_eq_abs] at this,\n  rw [←of_real_inj, ←mul_conj, ←mul_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, ←norm_eq_abs, linear_isometry.norm_map] at this,\n  rw [mul_conj, norm_sq_eq_abs, ←norm_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, ←this, add_comm],\nend\n\nlemma linear_isometry.re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : (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 : ℂ ≃ₗᵢ[ℝ] ℂ} (h : f 1 = 1) :\n  f = linear_isometry_equiv.refl ℝ ℂ ∨ f = conj_lie :=\nbegin\n  have h0 : f I = I ∨ f I = -I,\n  { have : |f I| = 1 := by simpa using f.norm_map complex.I,\n    simp only [ext_iff, ←and_or_distrib_left, neg_re, I_re, neg_im, neg_zero],\n    split,\n    { rw ←I_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 (λ h' : f I = I, _) (λ 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 : ℂ ≃ₗᵢ[ℝ] ℂ) :\n  ∃ a : circle, f = rotation a ∨ f = conj_lie.trans (rotation a) :=\nbegin\n  let a : circle := ⟨f 1, by simpa using f.norm_map 1⟩,\n  use a,\n  have : (f.trans (rotation a).symm) 1 = 1,\n  { simpa using rotation_apply a⁻¹ (f 1) },\n  refine (linear_isometry_complex_aux this).imp (λ h₁, _) (λ h₂, _),\n  { simpa using eq_mul_of_inv_mul_eq h₁ },\n  { exact eq_mul_of_inv_mul_eq h₂ }\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, ←norm_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 : ℂ →ₗ[ℝ] ℂ).det = 1 :=\nbegin\n  rw [←linear_map.det_to_matrix basis_one_I, to_matrix_rotation, matrix.det_fin_two],\n  simp [←norm_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 [←units.eq_iff, linear_equiv.coe_det, det_rotation, units.coe_one]\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/isometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7524915111954487}}
{"text": "/-\nCopyright (c) 2022 Joël Riou. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Joël Riou\n-/\n\nimport for_mathlib.dold_kan.equivalence_pseudoabelian\nimport for_mathlib.dold_kan.normalized\n\n/-!\n\n# The Dold-Kan correspondence\n\nThe Dold-Kan correspondence states that for any abelian category `A`, there is\nan equivalence between the category of simplicial objects in `A` and the\ncategory of chain complexes in `A` (with degrees indexed by `ℕ` and the\nhomological convention that the degree is decreased by the differentials).\n\nIn this file, we finish the construction of this equivalence by providing\n`category_theory.abelian.dold_kan.equivalence` which is of type\n`simplicial_object A ≌ chain_complex A ℕ` for any abelian category `A`.\nThe functor `simplicial_object A ⥤ chain_complex A ℕ` of this equivalence is\ndefinitionally equal to `normalized_Moore_complex A`.\n\n## Overall strategy of the proof of the correspondence\n\nBefore starting the implementation of the proof in Lean, the author noticed\nthat the Dold-Kan equivalence not only applies to abelian categories, but\nshould also hold generally for any pseudoabelian category `C`\n(i.e. a category with instances `[additive_category C]` and\n`[is_idempotent_complete C]`): this is\n`category_theory.idempotents.dold_kan.equivalence`.\n\nWhen the alternating face map complex `K[X]` of a simplicial object `X` in an\nabelian is studied, it is shown that it decomposes as a direct sum of the\nnormalized subcomplex and of the degenerate subcomplex. The crucial observation\nis that in this decomposition, the projection on the normalized subcomplex can\nbe defined in each degree using simplicial operators. Then, the definition\nof this projection `P_infty : K[X] ⟶ K[X]` can be carried for any\n`(X : simplicial_object C)` when `C` is a preadditive category.\n\nThe construction of the endomorphism `P_infty` is done in the files\n`homotopies.lean`, `faces.lean`, `projections.lean` and `p_infty.lean`.\nEventually, as we would also like to show that the inclusion of the normalized\nMoore complex is an homotopy equivalence (cf. file `homotopy_equivalence.lean`),\nthis projection `P_infty` needs to be homotopic to the identity. In our\nconstruction, we get this for free because `P_infty` is obtained by altering\nthe identity endomorphism by null homotopic maps. More details about this\naspect of the proof in the file `homotopies.lean`.\n\nWhen the alternating face map complex `K[X]` is equipped with the idempotent\nendomorphism `P_infty`, it becomes an object in `karoubi (chain_complex C ℕ)`\nwhich is the pseudoabelianisation of the category `chain_complex C ℕ`. In `functor_n.lean`,\nwe obtain this functor `N₁ : simplicial_object C ⥤ karoubi (chain_complex C ℕ)`,\nwhich is formally extended as\n`N₂ : karoubi (simplicial_object C) ⥤ karoubi (chain_complex C ℕ)`. (Here, some functors\nhave an index which is the number of occurrences of `karoubi` at the source or the\ntarget.)\n\nIn `functor_gamma.lean`, assuming that the category `C` is additive,\nwe define the functor in the other direction\n`Γ₂ : karoubi (chain_complex C ℕ) ⥤ karoubi (simplicial_object C)` as the formal\nextension of a functor `Γ₀ : chain_complex C ℕ ⥤ simplicial_object C` which is\ndefined similarly as in *Simplicial Homotopy Theory* by Goerss-Jardine.\nIn `degeneracies.lean`, we show that `P_infty` vanishes in the image of degeneracy\noperators, which is one of the key properties that makes possible to contruct\nthe isomorphism `N₂Γ₂ : Γ₂ ⋙ N₂ ≅ 𝟭 (karoubi (chain_complex C ℕ))`.\n\nThe rest of the proof follows the strategy in the original paper by Dold. We show\nthat the functor `N₂` reflects isomorphisms in `n_reflects_iso.lean`: this relies on a\ndecomposition of the identity of `X _[n]` using `P_infty.f n` and degeneracies obtained in\n`decomposition.lean`. Then, in `n_comp_gamma.lean`, we construct a natural transformation\n`Γ₂N₂_trans : N₂ ⋙ Γ₂ ⟶ 𝟭 (karoubi (simplicial_object C))`. It is shown that it is an\nisomorphism using the fact thet `N₂` reflects isomorphisms, and because we can show\nthat the composition `N₂ ⟶ N₂ ⋙ Γ₂ ⋙ N₂ ⟶ N₂` is the identity (see `identity_N₂`). The fact\nthat `N₂` is defined as a formal direct factor makes the proof easier because we only\nhave to compare endomorphisms of an alternating face map complex `K[X]` and we do not\nhave to worry with inclusions of kernel subobjects.\n\nIn `equivalence_additive.lean`, we obtain\nthe equivalence `equivalence : karoubi (simplicial_object C) ≌ karoubi (chain_complex C ℕ)`.\nIt is in the namespace `category_theory.preadditive.dold_kan`. The functors in this\nequivalence are named `N` and `Γ`: by definition, they are `N₂` and `Γ₂`.\n\nIn `equivalence_pseudoabelian.lean`, assuming `C` is idempotent complete,\nwe obtain `equivalence : simplicial_object C ≌ chain_complex C ℕ`\nin the namespace `category_theory.idempotents.dold_kan`. This could be roughly\nobtained by composing the previous equivalence with the equivalences\n`simplicial_object C ≌ karoubi (simplicial_object C)` and\n`karoubi (chain_complex C ℕ) ≌ chain_complex C ℕ`. Instead, we polish this construction\nin `compatibility.lean` by ensuring good definitional properties of the equivalence (e.g.\nthe inverse functor is definitionallly equal to\n`Γ₀' : chain_complex C ℕ ⥤ simplicial_object C`) and\nshowing compatibilities for the unit and counit isomorphisms.\n\nIn this file `equivalence.lean`, assuming the category `A` is abelian, we obtain\n`equivalence : simplicial_object A ≌ chain_complex A ℕ` in the namespace\n`category_theory.abelian.dold_kan`. This is obtained by replacing the functor\n`category_theory.idempotents.dold_kan.N` of the equivalence in the pseudoabelian case\nwith the isomorphic functor `normalized_Moore_complex A` thanks to the isomorphism\nobtained in `normalized.lean`.\n\nFinally, we show functoriality properties of the three equivalences above in\n`functoriality_additive.lean`, `functoriality_pseudoabelian.lean` and\n`functoriality.lean`. More precisely, for example in the case of abelian\ncategories `A` and `B`, if `F : A ⥤ B` is an additive functor,\nwe show that the functor `N` for `A` and `B` are compatible with the functors\n`simplicial_object A ⥤ simplicial_object B` and\n`chain_complex A ℕ ⥤ chain_complex B ℕ` induced by `F`. (Note that this does not\nrequire that `F` is an exact functor!)\n\n## References\n* Albrecht Dold, Homology of Symmetric Products and Other Functors of Complexes,\nAnnals of Mathematics, Second Series, Vol. 68 No. 1 (Jul. 1958), pp. 54-80.\n* Paul G. Goerss, John F. Jardine, Simplicial Homotopy Theory, Modern Birkhäuser Classics,\nReprint of the 1999 edition.\n\n-/\n\nnoncomputable theory\n\nopen category_theory\nopen category_theory.category\nopen category_theory.idempotents\n\nvariables {A : Type*} [category A] [abelian A]\n\nnamespace category_theory\n\nnamespace abelian\n\nnamespace dold_kan\n\nopen algebraic_topology.dold_kan\n\n/-- The functor `N` for the equivalence is `normalized_Moore_complex A` -/\ndef N : simplicial_object A ⥤ chain_complex A ℕ := algebraic_topology.normalized_Moore_complex A\n\n/-- The functor `Γ` for the equivalence is the same as in the pseudoabelian case. -/\ndef Γ : chain_complex A ℕ ⥤ simplicial_object A := idempotents.dold_kan.Γ\n\n/-- The equivalence `chain_complex A ℕ ≌ karoubi (chain_complex A ℕ) ` -/\ndef κequiv' := to_karoubi_equivalence (chain_complex A ℕ)\n\n/-- The comparison isomorphism between `normalized_Moore_complex A` and\nthe functor `idempotents.dold_kan.N` from the pseudoabelian case -/\n@[simps]\ndef comparison_N : (N : simplicial_object A ⥤ _) ≅ idempotents.dold_kan.N :=\ncalc N ≅ N ⋙ 𝟭 _ : functor.left_unitor N\n... ≅ N ⋙ ((to_karoubi_equivalence _).functor ⋙ (to_karoubi_equivalence _).inverse) :\n  iso_whisker_left _ κequiv'.unit_iso\n... ≅ (N ⋙ (to_karoubi_equivalence _).functor) ⋙ (to_karoubi_equivalence _).inverse :\n  iso.refl _\n... ≅ N₁ ⋙ (to_karoubi_equivalence _).inverse : iso_whisker_right\n  (N₁_iso_normalized_Moore_complex_comp_to_karoubi A).symm _\n... ≅ idempotents.dold_kan.N : by refl\n\n/-- The Dold-Kan equivalence for abelian categories -/\n@[simps]\ndef equivalence : simplicial_object A ≌ chain_complex A ℕ :=\nbegin\n  let F : simplicial_object A ⥤ _ := idempotents.dold_kan.N,\n  let hF : is_equivalence F := is_equivalence.of_equivalence idempotents.dold_kan.equivalence,\n  letI : is_equivalence (N : simplicial_object A ⥤ _ ) :=\n    is_equivalence.of_iso comparison_N.symm hF,\n  exact N.as_equivalence,\nend\n\nlemma equivalence_functor : (equivalence : simplicial_object A ≌ _).functor = N := rfl\nlemma equivalence_inverse : (equivalence : simplicial_object A ≌ _).inverse = Γ := rfl\n\nend dold_kan\n\nend abelian\n\nend category_theory\n", "meta": {"author": "joelriou", "repo": "dold-kan", "sha": "a083fe264275774ac49ac520caf25f2ee29debb1", "save_path": "github-repos/lean/joelriou-dold-kan", "path": "github-repos/lean/joelriou-dold-kan/dold-kan-a083fe264275774ac49ac520caf25f2ee29debb1/src/for_mathlib/dold_kan/equivalence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7524557568099557}}
{"text": "import data.stream.basic\nimport tactic\n\nnamespace padovan\n\nprivate def padovan_aux_step : (ℕ × ℕ × ℕ) → (ℕ × ℕ × ℕ) := λ t, ⟨t.2.1, t.2.2, t.1 + t.2.1⟩\n\nprivate def padovan_aux_stream : stream (ℕ × ℕ × ℕ) := stream.iterate padovan_aux_step ⟨1, 1, 1⟩\n\ndef padovan (n : ℕ) : ℕ := (padovan_aux_stream n).1\n\n@[simp] lemma padovan_zero : padovan 0 = 1 := rfl\n@[simp] lemma padovan_one : padovan 1 = 1 := rfl\n@[simp] lemma padovan_two : padovan 2 = 1 := rfl\n\nprivate lemma padovan_aux_stream_succ {n : ℕ} :\n    padovan_aux_stream (n + 1) = padovan_aux_step (padovan_aux_stream n) :=\nbegin\n  change (stream.nth (n + 1) $ stream.iterate padovan_aux_step ⟨1, 1, 1⟩) =\n      padovan_aux_step (stream.nth n $ stream.iterate padovan_aux_step ⟨1, 1, 1⟩),\n  rw [stream.nth_succ_iterate, stream.map_iterate, stream.nth_map],\nend\n\nlemma padovan_succ_succ_succ {n : ℕ} : padovan (n + 3) = padovan n + padovan (n + 1) :=\nbegin\n  simp only [padovan, padovan_aux_stream_succ, padovan_aux_step],\nend\n\nlemma padovan_increasing (n m : ℕ): n ≤ m → padovan n ≤ padovan m :=\nbegin\n  intros h,\n  sorry\nend\n\nlemma padovan_pos (n : ℕ) : 0 < padovan n :=\nbegin\n  induction n with k nk,\n  { rw padovan_zero,\n    linarith,\n  },\n  { cases k,\n    { rw padovan_one,\n      linarith,\n    },\n    { sorry },\n  },\nend\n\nend padovan\n", "meta": {"author": "SnobbyDragon", "repo": "happynumbers", "sha": "e71d1c05d461a27db7dfbaa34561ad7c1e141836", "save_path": "github-repos/lean/SnobbyDragon-happynumbers", "path": "github-repos/lean/SnobbyDragon-happynumbers/happynumbers-e71d1c05d461a27db7dfbaa34561ad7c1e141836/src/padovan_sequence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7524187742231958}}
{"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\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 `φ` 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 : ℕ) : ℕ := ((range n).filter (nat.coprime n)).card\n\nlocalized \"notation `φ` := nat.totient\" in nat\n\n@[simp] theorem totient_zero : φ 0 = 0 := rfl\n\n@[simp] theorem totient_one : φ 1 = 1 :=\nby simp [totient]\n\nlemma totient_eq_card_coprime (n : ℕ) : φ n = ((range n).filter (nat.coprime n)).card := rfl\n\nlemma totient_le (n : ℕ) : φ n ≤ n :=\ncalc totient n ≤ (range n).card : card_filter_le _ _\n           ... = n              : card_range _\n\nlemma totient_lt (n : ℕ) (hn : 1 < n) : φ n < n :=\ncalc totient n ≤ ((range n).filter (≠ 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 : ∀ {n : ℕ}, 0 < n → 0 < φ n\n| 0 := dec_trivial\n| 1 := by simp [totient]\n| (n+2) := λ h, card_pos.2 ⟨1, mem_filter.2 ⟨mem_range.2 dec_trivial, coprime_one_right _⟩⟩\n\nopen zmod\n\n/-- Note this takes an explicit `fintype (units (zmod n))` argument to avoid trouble with instance\ndiamonds. -/\n@[simp] lemma _root_.zmod.card_units_eq_totient (n : ℕ) [fact (0 < n)] [fintype (units (zmod n))] :\n  fintype.card (units (zmod n)) = φ n :=\ncalc fintype.card (units (zmod n)) = fintype.card {x : zmod n // x.val.coprime n} :\n  fintype.card_congr zmod.units_equiv_coprime\n... = φ n :\nbegin\n  apply finset.card_congr (λ (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 ⟨⟨b, _⟩, finset.mem_univ _, _⟩,\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_mul {m n : ℕ} (h : m.coprime n) : φ (m * n) = φ m * φ 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)) := ⟨nat.pos_of_ne_zero hmn0⟩,\n    haveI : fact (0 < m) := ⟨nat.pos_of_ne_zero $ left_ne_zero_of_mul hmn0⟩,\n    haveI : fact (0 < n) := ⟨nat.pos_of_ne_zero $ right_ne_zero_of_mul hmn0⟩,\n    rw [← zmod.card_units_eq_totient, ← zmod.card_units_eq_totient,\n      ← 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 : ℕ} (hp : p.prime) (n : ℕ) :\n  φ (p ^ (n + 1)) = p ^ n * (p - 1) :=\ncalc φ (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 ⟨b, rfl⟩,\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 λ x _ y _, (nat.mul_left_inj hp.pos).1,\nhave h2 : (range (p ^ n)).image (* p) ⊆ range (p ^ (n + 1)),\n  from λ 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, ← one_mul (p ^ n), pow_succ, ← tsub_mul,\n    one_mul, mul_comm]\nend\n\n/-- When `p` is prime, then the totient of `p ^ ` is `p ^ (n - 1) * (p - 1)` -/\nlemma totient_prime_pow {p : ℕ} (hp : p.prime) {n : ℕ} (hn : 0 < n) :\n  φ (p ^ n) = p ^ (n - 1) * (p - 1) :=\nby rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with ⟨m, rfl⟩;\n  exact totient_prime_pow_succ hp _\n\nlemma totient_prime {p : ℕ} (hp : p.prime) : φ p = p - 1 :=\nby rw [← pow_one p, totient_prime_pow hp]; simp\n\nlemma totient_eq_iff_prime {p : ℕ} (hp : 0 < p) : p.totient = p - 1 ↔ p.prime :=\nbegin\n  refine ⟨λ h, _, totient_prime⟩,\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, ←Ico_insert_succ_left hp.le, finset.filter_insert,\n    if_neg (tactic.norm_num.nat_coprime_helper_zero_right p hp), ←nat.card_Ico 1 p] at h,\n  refine p.prime_of_coprime hp (λ n hn hnz, finset.filter_card_eq h n $ finset.mem_Ico.mpr ⟨_, hn⟩),\n  rwa [succ_le_iff, pos_iff_ne_zero],\nend\n\nlemma card_units_zmod_lt_sub_one {p : ℕ} (hp : 1 < p) [fintype (units (zmod p))] :\n  fintype.card (units (zmod p)) ≤ p - 1 :=\nbegin\n  haveI : fact (0 < p) := ⟨zero_lt_one.trans hp⟩,\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 : ℕ) [fintype (units (zmod p))] :\n  p.prime ↔ fintype.card (units (zmod p)) = 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 (units ℤ) ≠ 0, { convert this },\n    simp },\n  haveI : fact (0 < p) := ⟨nat.pos_of_ne_zero hp⟩,\n  rw [zmod.card_units_eq_totient, nat.totient_eq_iff_prime (fact.out (0 < p))],\nend\n\n@[simp] lemma totient_two : φ 2 = 1 :=\n(totient_prime prime_two).trans (by norm_num)\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/totient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095294, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7524187693255893}}
{"text": "-- BOTH:\nimport data.real.basic\n\n/- TEXT:\n.. _negation:\n\nNegation\n--------\n\nThe symbol ``¬`` is meant to express negation,\nso ``¬ x < y`` says that ``x`` is not less than ``y``,\n``¬ x = y`` (or, equivalently, ``x ≠ y``) says that\n``x`` is not equal to ``y``,\nand ``¬ ∃ z, x < z ∧ z < y`` says that there does not exist a ``z``\nstrictly between ``x`` and ``y``.\nIn Lean, the notation ``¬ A`` abbreviates ``A → false``,\nwhich you can think of as saying that ``A`` implies a contradiction.\nPractically speaking, this means that you already know something\nabout how to work with negations:\nyou can prove ``¬ A`` by introducing a hypothesis ``h : A``\nand proving ``false``,\nand if you have ``h : ¬ A`` and ``h' : A``,\nthen applying ``h`` to ``h'`` yields ``false``.\n\nTo illustrate, consider the irreflexivity principle ``lt_irrefl``\nfor a strict order,\nwhich says that we have ``¬ a < a`` for every ``a``.\nThe asymmetry principle ``lt_asymm`` says that we have\n``a < b → ¬ b < a``. Let's show that ``lt_asymm`` follows\nfrom ``lt_irrefl``.\nTEXT. -/\n-- BOTH:\nsection\nvariables a b : ℝ\n\n-- EXAMPLES:\n-- QUOTE:\nexample (h : a < b) : ¬ b < a :=\nbegin\n  intro h',\n  have : a < a,\n    from lt_trans h h',\n  apply lt_irrefl a this\nend\n-- QUOTE.\n\n/- TEXT:\n.. index:: this, have, tactics ; have, from, tactics ; from\n\nThis example introduces a couple of new tricks.\nFirst, when you use ``have`` without providing\na label,\nLean uses the name ``this``,\nproviding a convenient way to refer back to it.\nAlso, the ``from`` tactic is syntactic sugar for ``exact``,\nproviding a nice way to justify a ``have`` with an explicit\nproof term.\nBut what you should really be paying attention to in this\nproof is the result of the ``intro`` tactic,\nwhich leaves a goal of ``false``,\nand the fact that we eventually prove ``false``\nby applying ``lt_irrefl`` to a proof of ``a < a``.\n\nHere is another example, which uses the\npredicate ``fn_has_ub`` defined in the last section,\nwhich says that a function has an upper bound.\nTEXT. -/\n-- BOTH:\ndef fn_ub (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, f x ≤ a\ndef fn_lb (f : ℝ → ℝ) (a : ℝ) : Prop := ∀ x, a ≤ f x\n\ndef fn_has_ub (f : ℝ → ℝ) := ∃ a, fn_ub f a\ndef fn_has_lb (f : ℝ → ℝ) := ∃ a, fn_lb f a\n\nvariable f : ℝ → ℝ\n\n-- EXAMPLES:\n-- QUOTE:\nexample (h : ∀ a, ∃ x, f x > a) : ¬ fn_has_ub f :=\nbegin\n  intros fnub,\n  cases fnub with a fnuba,\n  cases h a with x hx,\n  have : f x ≤ a,\n    from fnuba x,\n  linarith\nend\n-- QUOTE.\n\n/- TEXT:\nSee if you can prove these in a similar way:\nTEXT. -/\n-- QUOTE:\nexample (h : ∀ a, ∃ x, f x < a) : ¬ fn_has_lb f :=\nsorry\n\nexample : ¬ fn_has_ub (λ x, x) :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : ∀ a, ∃ x, f x < a) : ¬ fn_has_lb f :=\nbegin\n  rintros ⟨a, ha⟩,\n  rcases h a with ⟨x, hx⟩,\n  have := ha x,\n  linarith\nend\n\nexample : ¬ fn_has_ub (λ x, x) :=\nbegin\n  rintros ⟨a, ha⟩,\n  have : a + 1 ≤ a := ha (a + 1),\n  linarith\nend\n\n/- TEXT:\nMathlib offers a number of useful theorems for relating orders\nand negations:\nTEXT. -/\n-- QUOTE:\n#check (not_le_of_gt : a > b → ¬ a ≤ b)\n#check (not_lt_of_ge : a ≥ b → ¬ a < b)\n#check (lt_of_not_ge : ¬ a ≥ b → a < b)\n#check (le_of_not_gt : ¬ a > b → a ≤ b)\n-- QUOTE.\n\n/- TEXT:\nRecall the predicate ``monotone f``,\nwhich says that ``f`` is nondecreasing.\nUse some of the theorems just enumerated to prove the following:\nTEXT. -/\n-- QUOTE:\nexample (h : monotone f) (h' : f a < f b) : a < b :=\nsorry\n\nexample (h : a ≤ b) (h' : f b < f a) : ¬ monotone f :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : monotone f) (h' : f a < f b) : a < b :=\nbegin\n  apply lt_of_not_ge,\n  intro h'',\n  apply absurd h',\n  apply not_lt_of_ge (h h'')\nend\n\nexample (h : a ≤ b) (h' : f b < f a) : ¬ monotone f :=\nbegin\n  intro h'',\n  apply absurd h',\n  apply not_lt_of_ge,\n  apply h'' h\nend\n\n/- TEXT:\nRemember that it is often convenient to use ``linarith``\nwhen a goal follows from linear equations and\ninequalities that in the context.\n\nWe can show that the first example in the last snippet\ncannot be proved if we replace ``<`` by ``≤``.\nNotice that we can prove the negation of a universally\nquantified statement by giving a counterexample.\nComplete the proof.\nTEXT. -/\n-- QUOTE:\nexample :\n  ¬ ∀ {f : ℝ → ℝ}, monotone f → ∀ {a b}, f a ≤ f b → a ≤ b :=\nbegin\n  intro h,\n  let f := λ x : ℝ, (0 : ℝ),\n  have monof : monotone f,\n  { sorry },\n  have h' : f 1 ≤ f 0,\n    from le_refl _,\n  sorry\nend\n-- QUOTE.\n\n-- SOLUTIONS:\nexample :\n  ¬ ∀ {f : ℝ → ℝ}, monotone f → ∀ {a b}, f a ≤ f b → a ≤ b :=\nbegin\n  intro h,\n  let f := λ x : ℝ, (0 : ℝ),\n  have monof : monotone f,\n  { intros a b leab,\n    refl },\n  have h' : f 1 ≤ f 0,\n    from le_refl _,\n  have : (1 : ℝ) ≤ 0 := h monof h',\n  linarith\nend\n\n/- TEXT:\n.. index:: let, tactics ; let\n\nThis example introduces the ``let`` tactic,\nwhich adds a *local definition* to the context.\nIf you put the cursor after the ``let`` command,\nin the goal window you will see that the definition\n``f : ℝ → ℝ := λ (x : ℝ), 0`` has been added to the context.\nLean will unfold the definition of ``f`` when it has to.\nIn particular, when we prove ``f 1 ≤ f 0`` with ``le_refl``,\nLean reduces ``f 1`` and ``f 0`` to ``0``.\n\nUse ``le_of_not_gt`` to prove the following:\nTEXT. -/\n-- QUOTE:\nexample (x : ℝ) (h : ∀ ε > 0, x < ε) : x ≤ 0 :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (x : ℝ) (h : ∀ ε > 0, x < ε) : x ≤ 0 :=\nbegin\n  apply le_of_not_gt,\n  intro h',\n  linarith [h _ h']\nend\n\n-- BOTH:\nend\n\n/- TEXT:\nImplicit in many of the proofs we have just done\nis the fact that if ``P`` is any property,\nsaying that there is nothing with property ``P``\nis the same as saying that everything fails to have\nproperty ``P``,\nand saying that not everything has property ``P``\nis equivalent to saying that something fails to have property ``P``.\nIn other words, all four of the following implications\nare valid (but one of them cannot be proved with what we explained so\nfar):\nTEXT. -/\n-- BOTH:\nsection\n-- QUOTE:\nvariables {α : Type*} (P : α → Prop) (Q : Prop)\n\n-- EXAMPLES:\nexample (h : ¬ ∃ x, P x) : ∀ x, ¬ P x :=\nsorry\n\nexample (h : ∀ x, ¬ P x) : ¬ ∃ x, P x :=\nsorry\n\nexample (h : ¬ ∀ x, P x) : ∃ x, ¬ P x :=\nsorry\n\nexample (h : ∃ x, ¬ P x) : ¬ ∀ x, P x :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : ¬ ∃ x, P x) : ∀ x, ¬ P x :=\nbegin\n  intros x Px,\n  apply h,\n  use [x, Px]\nend\n\nexample (h : ∀ x, ¬ P x) : ¬ ∃ x, P x :=\nbegin\n  rintros ⟨x, Px⟩,\n  exact h x Px\nend\n\nexample (h : ∃ x, ¬ P x) : ¬ ∀ x, P x :=\nbegin\n  intro h',\n  rcases h with ⟨x, nPx⟩,\n  apply nPx,\n  apply h'\nend\n\n\n/- TEXT:\nThe first, second, and fourth are straightforward to\nprove using the methods you have already seen.\nWe encourage you to try it.\nThe third is more difficult, however,\nbecause it concludes that an object exists\nfrom the fact that its nonexistence is contradictory.\nThis is an instance of *classical* mathematical reasoning,\nand, in general, you have to declare your intention\nof using such reasoning by adding the command\n``open_locale classical`` to your file.\nWith that command, we can use proof by contradiction\nto prove the third implication as follows.\nTEXT. -/\n-- QUOTE:\nopen_locale classical\n\nexample (h : ¬ ∀ x, P x) : ∃ x, ¬ P x :=\nbegin\n  by_contradiction h',\n  apply h,\n  intro x,\n  show P x,\n  by_contradiction h'',\n  exact h' ⟨x, h''⟩\nend\n-- QUOTE.\n\n/- TEXT:\n.. index:: by_contradiction, by_contra, tactics ; by_contra and by_contradiction,\n\nMake sure you understand how this works.\nThe ``by_contradiction`` tactic (also abbreviated to ``by_contra``)\nallows us to prove a goal ``Q`` by assuming ``¬ Q``\nand deriving a contradiction.\nIn fact, it is equivalent to using the\nequivalence ``not_not : ¬ ¬ Q ↔ Q``.\nConfirm that you can prove the forward direction\nof this equivalence using ``by_contradiction``,\nwhile the reverse direction follows from the\nordinary rules for negation.\nTEXT. -/\n-- QUOTE:\nexample (h : ¬ ¬ Q) : Q :=\nsorry\n\nexample (h : Q) : ¬ ¬ Q :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : ¬ ¬ Q) : Q :=\nbegin\n  by_contradiction h',\n  exact h h'\nend\n\nexample (h : Q) : ¬ ¬ Q :=\nbegin\n  intro h',\n  exact h' h\nend\n\n-- BOTH:\nend\n\n/- TEXT:\nUse proof by contradiction to establish the following,\nwhich is the converse of one of the implications we proved above.\n(Hint: use ``intro`` first.)\nTEXT. -/\n-- BOTH:\nopen_locale classical\nsection\nvariable (f : ℝ → ℝ)\n\n-- EXAMPLES:\n-- QUOTE:\nexample (h : ¬ fn_has_ub f) : ∀ a, ∃ x, f x > a :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : ¬ fn_has_ub f) : ∀ a, ∃ x, f x > a :=\nbegin\n  intro a,\n  by_contradiction h',\n  apply h,\n  use a,\n  intro x,\n  apply le_of_not_gt,\n  intro h'',\n  apply h',\n  use [x, h'']\nend\n\n/- TEXT:\n.. index:: push_neg, tactics ; push_neg\n\nIt is often tedious to work with compound statements with\na negation in front,\nand it is a common mathematical pattern to replace such\nstatements with equivalent forms in which the negation\nhas been pushed inward.\nTo facilitate this, mathlib offers a ``push_neg`` tactic,\nwhich restates the goal in this way.\nThe command ``push_neg at h`` restates the hypothesis ``h``.\nTEXT. -/\n-- QUOTE:\nexample (h : ¬ ∀ a, ∃ x, f x > a) : fn_has_ub f :=\nbegin\n  push_neg at h,\n  exact h\nend\n\nexample (h : ¬ fn_has_ub f) : ∀ a, ∃ x, f x > a :=\nbegin\n  simp only [fn_has_ub, fn_ub] at h,\n  push_neg at h,\n  exact h\nend\n-- QUOTE.\n\n/- TEXT:\nIn the second example, we use Lean's simplifier to\nexpand the definitions of ``fn_has_ub`` and ``fn_ub``.\n(We need to use ``simp`` rather than ``rw``\nto expand ``fn_ub``,\nbecause it appears in the scope of a quantifier.)\nYou can verify that in the examples above\nwith ``¬ ∃ x, P x`` and ``¬ ∀ x, P x``,\nthe ``push_neg`` tactic does the expected thing.\nWithout even knowing how to use the conjunction\nsymbol,\nyou should be able to use ``push_neg``\nto prove the following:\nTEXT. -/\n-- QUOTE:\nexample (h : ¬ monotone f) : ∃ x y, x ≤ y ∧ f y < f x :=\nsorry\n-- QUOTE.\n\n-- SOLUTIONS:\nexample (h : ¬ monotone f) : ∃ x y, x ≤ y ∧ f y < f x :=\nbegin\n  rw [monotone] at h,\n  push_neg at h,\n  exact h\nend\n\n/- TEXT:\n.. index:: contrapose, tactics ; contrapose\n\nMathlib also has a tactic, ``contrapose``,\nwhich transforms a goal ``A → B`` to ``¬ B → ¬ A``.\nSimilarly, given a goal of proving ``B`` from\nhypothesis ``h : A``,\n``contrapose h`` leaves you with a goal of proving\n``¬ A`` from hypothesis ``¬ B``.\nUsing ``contrapose!`` instead of ``contrapose``\napplies ``push_neg`` to the goal and the relevant\nhypothesis as well.\nTEXT. -/\n-- QUOTE:\nexample (h : ¬ fn_has_ub f) : ∀ a, ∃ x, f x > a :=\nbegin\n  contrapose! h,\n  exact h\nend\n\nexample (x : ℝ) (h : ∀ ε > 0, x ≤ ε) : x ≤ 0 :=\nbegin\n  contrapose! h,\n  use x / 2,\n  split; linarith\nend\n-- QUOTE.\n\n-- BOTH:\nend\n\n/- TEXT:\nWe have not yet explained the ``split`` command\nor the use of the semicolon after it,\nbut we will do that in the next section.\n\n.. TODO: make sure we explain split and the semicolon\n   in the next section\n\nWe close this section with\nthe principle of *ex falso*,\nwhich says that anything follows from a contradiction.\nIn Lean, this is represented by ``false.elim``,\nwhich establishes ``false → P`` for any proposition ``P``.\nThis may seem like a strange principle,\nbut it comes up fairly often.\nWe often prove a theorem by splitting on cases,\nand sometimes we can show that one of\nthe cases is contradictory.\nIn that case, we need to assert that the contradiction\nestablishes the goal so we can move on to the next one.\n(We will see instances of reasoning by cases in\n:numref:`disjunction`.)\n\n.. index:: exfalso, contradiction, absurd, tactics ; exfalso, tactics ; contradiction\n\nLean provides a number of ways of closing\na goal once a contradiction has been reached.\nTEXT. -/\nsection\nvariable a : ℕ\n\n-- QUOTE:\nexample (h : 0 < 0) : a > 37 :=\nbegin\n  exfalso,\n  apply lt_irrefl 0 h\nend\n\nexample (h : 0 < 0) : a > 37 :=\nabsurd h (lt_irrefl 0)\n\nexample (h : 0 < 0) : a > 37 :=\nbegin\n  have h' : ¬ 0 < 0,\n    from lt_irrefl 0,\n  contradiction\nend\n-- QUOTE.\n\nend\n\n/- TEXT:\nThe ``exfalso`` tactic replaces the current goal with\nthe goal of proving ``false``.\nGiven ``h : P`` and ``h' : ¬ P``,\nthe term ``absurd h h'`` establishes any proposition.\nFinally, the ``contradiction`` tactic tries to close a goal\nby finding a contradiction in the hypotheses,\nsuch as a pair of the form ``h : P`` and ``h' : ¬ P``.\nOf course, in this example, ``linarith`` also works.\nTEXT. -/", "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_03_Negation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835289107307, "lm_q2_score": 0.9005297867852853, "lm_q1q2_score": 0.7523778041525981}}
{"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önne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.basic\nimport topology.algebra.order.proj_Icc\n\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\nnoncomputable theory\nopen_locale classical topological_space filter\nopen set filter\n\nopen_locale real\n\nnamespace real\n\n/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.\nIt defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/\n@[pp_nodot] noncomputable def arcsin : ℝ → ℝ :=\ncoe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm\n\nlemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _\n\n@[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) :=\nby { rw [arcsin, range_comp coe], simp [Icc] }\n\nlemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2\n\nlemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1\n\nlemma arcsin_proj_Icc (x : ℝ) :\n  arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one ℝ _) x) = arcsin x :=\nby rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]\n\nlemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 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 ⟨x, hx⟩)\n\nlemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=\nsin_arcsin' ⟨hx₁, hx₂⟩\n\nlemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 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 : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=\narcsin_sin' ⟨hx₁, hx₂⟩\n\nlemma strict_mono_on_arcsin : strict_mono_on arcsin (Icc (-1) 1) :=\n(subtype.strict_mono_coe _).comp_strict_mono_on $\n  sin_order_iso.symm.strict_mono.strict_mono_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_on_arcsin.inj_on\n\nlemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :\n  arcsin x = arcsin y ↔ x = y :=\ninj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩\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 : ℝ} : continuous_at arcsin x :=\ncontinuous_arcsin.continuous_at\n\nlemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin y = x :=\nbegin\n  subst y,\n  exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))\nend\n\n@[simp] lemma arcsin_zero : arcsin 0 = 0 :=\narcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩\n\n@[simp] lemma arcsin_one : arcsin 1 = π / 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 : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 :=\nby rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]\n\nlemma arcsin_neg_one : arcsin (-1) = -(π / 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 : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) :=\nby rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]\n\n@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=\nbegin\n  cases le_total x (-1) with hx₁ hx₁,\n  { rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] },\n  cases le_total 1 x with hx₂ hx₂,\n  { rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] },\n  refine arcsin_eq_of_sin_eq _ _,\n  { rw [sin_neg, sin_arcsin hx₁ hx₂] },\n  { exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ }\nend\n\nlemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin x ≤ y ↔ x ≤ sin y :=\nby rw [← arcsin_sin' hy, strict_mono_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]\n\nlemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :\n  arcsin x ≤ y ↔ x ≤ sin y :=\nbegin\n  cases le_total x (-1) with hx₁ hx₁,\n  { simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] },\n  cases lt_or_le 1 x with hx₂ hx₂,\n  { simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] },\n  exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)\nend\n\nlemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :\n  x ≤ arcsin y ↔ sin x ≤ y :=\nby rw [← neg_le_neg_iff, ← arcsin_neg,\n  arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩,\n  sin_neg, neg_le_neg_iff]\n\nlemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :\n  x ≤ arcsin y ↔ sin x ≤ y :=\nby rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,\n  sin_neg, neg_le_neg_iff]\n\nlemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin x < y ↔ 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 : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :\n  arcsin x < y ↔ 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 : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :\n  x < arcsin y ↔ 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 : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :\n  x < arcsin y ↔ 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 : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :\n  arcsin x = y ↔ 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 : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=\n(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero]\n\n@[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=\nneg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg\n\n@[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 :=\nby simp [le_antisymm_iff]\n\n@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=\neq_comm.trans arcsin_eq_zero_iff\n\n@[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=\nlt_iff_lt_of_le_iff_le arcsin_nonpos\n\n@[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=\nlt_iff_lt_of_le_iff_le arcsin_nonneg\n\n@[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ 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 : ℝ} : -(π / 2) < arcsin x ↔ -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 : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=\n⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩\n\n@[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=\neq_comm.trans arcsin_eq_pi_div_two\n\n@[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ 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 : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=\n⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩\n\n@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=\neq_comm.trans arcsin_eq_neg_pi_div_two\n\n@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=\n(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two\n\n@[simp] \n\nlemma maps_to_sin_Ioo : maps_to sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) :=\nλ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin,\n  arcsin_sin h.1.le h.2.le]\n\n/-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/\n@[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ :=\n{ to_fun := sin,\n  inv_fun := arcsin,\n  source := Ioo (-(π / 2)) (π / 2),\n  target := Ioo (-1) 1,\n  map_source' := maps_to_sin_Ioo,\n  map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩,\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 := 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 : ℝ) : 0 ≤ cos (arcsin x) :=\ncos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩\n\nlemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 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 [← eq_sub_iff_add_eq', ← 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₁ hx₂],\nend\n\n/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.\n  If the argument is not between `-1` and `1` it defaults to `π / 2` -/\n@[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ :=\nπ / 2 - arcsin x\n\nlemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl\n\nlemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=\nby simp [arccos]\n\nlemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=\nby unfold arccos; linarith [neg_pi_div_two_le_arcsin x]\n\nlemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=\nby unfold arccos; linarith [arcsin_le_pi_div_two x]\n\nlemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=\nby rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]\n\nlemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=\nby rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith\n\nlemma strict_anti_on_arccos : strict_anti_on arccos (Icc (-1) 1) :=\nλ x hx y hy h, sub_lt_sub_left (strict_mono_on_arcsin hx hy h) _\n\nlemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_anti_on_arccos.inj_on\n\nlemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :\n  arccos x = arccos y ↔ x = y :=\narccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩\n\n@[simp] lemma arccos_zero : arccos 0 = π / 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) = π := by simp [arccos, add_halves]\n\n@[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x :=\nby simp [arccos, sub_eq_zero]\n\n@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 :=\nby simp [arccos]\n\n@[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 :=\nby rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]\n\nlemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=\nby rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]\n\nlemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 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₁ hx₂]\n\n@[simp] lemma arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos]\n\n@[simp] lemma arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ sqrt 2 / 2 ≤ x :=\nby { rw [arccos, ← pi_div_four_le_arcsin], split; { intro, linarith } }\n\n@[continuity]\nlemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin\n\nend real\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/inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8354835289107309, "lm_q1q2_score": 0.7523777969038584}}
{"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 data.set.intervals.ord_connected\nimport data.set.intervals.image_preimage\nimport data.complex.module\nimport linear_algebra.affine_space.affine_map\nimport algebra.module.ordered\n\n\n/-!\n# Convex sets and functions on real vector spaces\n\nIn a real vector space, we define the following objects and properties.\n\n* `segment x y` is the closed segment joining `x` and `y`.\n* A set `s` is `convex` if for any two points `x y ∈ s` it includes `segment x y`;\n* A function `f : E → β` is `convex_on` a set `s` if `s` is itself a convex set, and for any two\n  points `x y ∈ s` the segment joining `(x, f x)` to `(y, f y)` is (non-strictly) above the graph\n  of `f`; equivalently, `convex_on f s` means that the epigraph\n  `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set;\n* Center mass of a finite set of points with prescribed weights.\n* Convex hull of a set `s` is the minimal convex set that includes `s`.\n* Standard simplex `std_simplex ι [fintype ι]` is the intersection of the positive quadrant with\n  the hyperplane `s.sum = 1` in the space `ι → ℝ`.\n\nWe also provide various equivalent versions of the definitions above, prove that some specific sets\nare convex, and prove Jensen's inequality.\n\nNote: To define convexity for functions `f : E → β`, we need `β` to be an ordered vector space,\ndefined using the instance `ordered_module ℝ β`.\n\n## Notations\n\nWe use the following local notations:\n\n* `I = Icc (0:ℝ) 1`;\n* `[x, y] = segment x y`.\n\nThey are defined using `local notation`, so they are not available outside of this file.\n-/\n\nuniverses u' u v v' w x\n\nvariables {E : Type u} {F : Type v} {ι : Type w} {ι' : Type x} {α : Type v'}\n  [add_comm_group E] [module ℝ E] [add_comm_group F] [module ℝ F]\n  [linear_ordered_field α]\n  {s : set E}\n\nopen set linear_map\nopen_locale classical big_operators\n\nlocal notation `I` := (Icc 0 1 : set ℝ)\n\nsection sets\n\n/-! ### Segment -/\n\n/-- Segments in a vector space. -/\ndef segment (x y : E) : set E :=\n{z : E | ∃ (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1), a • x + b • y = z}\n\nlocal notation `[`x `, ` y `]` := segment x y\n\nlemma segment_symm (x y : E) : [x, y] = [y, x] :=\nset.ext $ λ z,\n⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,\n  λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩\n\nlemma left_mem_segment (x y : E) : x ∈ [x, y] :=\n⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩\n\nlemma right_mem_segment (x y : E) : y ∈ [x, y] :=\nsegment_symm y x ▸ left_mem_segment y x\n\nlemma segment_same (x : E) : [x, x] = {x} :=\nset.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩,\n  by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz,\n  λ h, mem_singleton_iff.1 h ▸ left_mem_segment z z⟩\n\nlemma segment_eq_image (x y : E) : segment x y = (λ (θ : ℝ), (1 - θ) • x + θ • y) '' I :=\nset.ext $ λ z,\n  ⟨λ ⟨a, b, ha, hb, hab, hz⟩,\n    ⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩,\n    λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1-θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩\n\nlemma segment_eq_image' (x y : E) : segment x y = (λ (θ : ℝ), x + θ • (y - x)) '' I :=\nby { convert segment_eq_image x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel }\n\nlemma segment_eq_image₂ (x y : E) :\n  segment x y = (λ p:ℝ×ℝ, p.1 • x + p.2 • y) '' {p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1} :=\nby simp only [segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc]\n\nlemma segment_eq_Icc {a b : ℝ} (h : a ≤ b) : [a, b] = Icc a b :=\nbegin\n  rw [segment_eq_image'],\n  show (((+) a) ∘ (λ t, t * (b - a))) '' Icc 0 1 = Icc a b,\n  rw [image_comp, image_mul_right_Icc (@zero_le_one ℝ _) (sub_nonneg.2 h), image_const_add_Icc],\n  simp\nend\n\nlemma segment_eq_Icc' (a b : ℝ) : [a, b] = Icc (min a b) (max a b) :=\nby cases le_total a b; [skip, rw segment_symm]; simp [segment_eq_Icc, *]\n\nlemma segment_eq_interval (a b : ℝ) : segment a b = interval a b :=\nsegment_eq_Icc' _ _\n\nlemma mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b, a + c] ↔ x ∈ [b, c] :=\nbegin\n  rw [segment_eq_image', segment_eq_image'],\n  refine exists_congr (λ θ, and_congr iff.rfl _),\n  simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj]\nend\n\nlemma segment_translate_preimage (a b c : E) : (λ x, a + x) ⁻¹' [a + b, a + c] = [b, c] :=\nset.ext $ λ x, mem_segment_translate a\n\nlemma segment_translate_image (a b c: E) : (λx, a + x) '' [b, c] = [a + b, a + c] :=\nsegment_translate_preimage a b c ▸ image_preimage_eq _ $ add_left_surjective a\n\nlemma segment_image (f : E →ₗ[ℝ] F) (a b : E) : f '' [a, b] = [f a, f b] :=\nset.ext (λ x, by simp [segment_eq_image])\n\n/-! ### Convexity of sets -/\n\n/-- Convexity of sets. -/\ndef convex (s : set E) :=\n∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →\n  a • x + b • y ∈ s\n\nlemma convex_iff_forall_pos :\n  convex s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s :=\nbegin\n  refine ⟨λ h x y hx hy a b ha hb hab, h hx hy (le_of_lt ha) (le_of_lt hb) hab, _⟩,\n  intros h x y hx hy a b ha hb hab,\n  cases eq_or_lt_of_le ha with ha ha,\n  { subst a, rw [zero_add] at hab, simp [hab, hy] },\n  cases eq_or_lt_of_le hb with hb hb,\n  { subst b, rw [add_zero] at hab, simp [hab, hx] },\n  exact h hx hy ha hb hab\nend\n\nlemma convex_iff_segment_subset : convex s ↔ ∀ ⦃x y⦄, x ∈ s → y ∈ s → [x, y] ⊆ s :=\nby simp only [convex, segment_eq_image₂, subset_def, ball_image_iff, prod.forall,\n  mem_set_of_eq, and_imp]\n\nlemma convex.segment_subset (h : convex s) {x y:E} (hx : x ∈ s) (hy : y ∈ s) : [x, y] ⊆ s :=\nconvex_iff_segment_subset.1 h hx hy\n\n/-- Alternative definition of set convexity, in terms of pointwise set operations. -/\nlemma convex_iff_pointwise_add_subset:\n  convex s ↔ ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s :=\niff.intro\n  begin\n    rintros hA a b ha hb hab w ⟨au, bv, ⟨u, hu, rfl⟩, ⟨v, hv, rfl⟩, rfl⟩,\n    exact hA hu hv ha hb hab\n  end\n  (λ h x y hx hy a b ha hb hab,\n    (h ha hb hab) (set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩))\n\n/-- Alternative definition of set convexity, using division. -/\nlemma convex_iff_div:\n  convex s ↔ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄,\n    0 ≤ a → 0 ≤ b → 0 < a + b → (a/(a+b)) • x + (b/(a+b)) • y ∈ s :=\n⟨begin\n  assume h x y hx hy a b ha hb hab,\n  apply h hx hy,\n  have ha', from mul_le_mul_of_nonneg_left ha (le_of_lt (inv_pos.2 hab)),\n  rwa [mul_zero, ←div_eq_inv_mul] at ha',\n  have hb', from mul_le_mul_of_nonneg_left hb (le_of_lt (inv_pos.2 hab)),\n  rwa [mul_zero, ←div_eq_inv_mul] at hb',\n  rw [←add_div],\n  exact div_self (ne_of_lt hab).symm\nend,\nbegin\n  assume h x y hx hy a b 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⟩\n\n/-! ### Examples of convex sets -/\n\nlemma convex_empty : convex (∅ : set E) :=  by finish\n\nlemma convex_singleton (c : E) : convex ({c} : set E) :=\nbegin\n  intros x y hx hy a b ha hb hab,\n  rw [set.eq_of_mem_singleton hx, set.eq_of_mem_singleton hy, ←add_smul, hab, one_smul],\n  exact mem_singleton c\nend\n\nlemma convex_univ : convex (set.univ : set E) := λ _ _ _ _ _ _ _ _ _, trivial\n\nlemma convex.inter {t : set E} (hs: convex s) (ht: convex t) : convex (s ∩ t) :=\nλ x y (hx : x ∈ s ∩ t) (hy : y ∈ s ∩ t) a b (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1),\n  ⟨hs hx.left hy.left ha hb hab, ht hx.right hy.right ha hb hab⟩\n\nlemma convex_sInter {S : set (set E)} (h : ∀ s ∈ S, convex s) : convex (⋂₀ S) :=\nassume x y hx hy a b ha hb hab s hs,\nh s hs (hx s hs) (hy s hs) ha hb hab\n\nlemma convex_Inter {ι : Sort*} {s: ι → set E} (h: ∀ i : ι, convex (s i)) : convex (⋂ i, s i) :=\n(sInter_range s) ▸ convex_sInter $ forall_range_iff.2 h\n\nlemma convex.prod {s : set E} {t : set F} (hs : convex s) (ht : convex t) :\n  convex (s.prod t) :=\nbegin\n  intros x y hx hy a b ha hb hab,\n  apply mem_prod.2,\n  exact ⟨hs (mem_prod.1 hx).1 (mem_prod.1 hy).1 ha hb hab,\n        ht (mem_prod.1 hx).2 (mem_prod.1 hy).2 ha hb hab⟩\nend\n\nlemma convex.combo_to_vadd {a b : ℝ} {x y : E} (h : a + b = 1) :\n  a • x + b • y = b • (y - x) + x :=\ncalc\n  a • x + b • y = (b • y - b • x) + (a • x + b • x) : by abel\n            ... = b • (y - x) + (a + b) • x         : by rw [smul_sub, add_smul]\n            ... = b • (y - x) + (1 : ℝ) • x         : by rw [h]\n            ... = b • (y - x) + x                   : by rw [one_smul]\n\n/--\nApplying an affine map to an affine combination of two points yields\nan affine combination of the images.\n-/\nlemma convex.combo_affine_apply {a b : ℝ} {x y : E} {f : E →ᵃ[ℝ] F} (h : a + b = 1) :\n  f (a • x + b • y) = a • f x + b • f y :=\nbegin\n  simp only [convex.combo_to_vadd h, ← vsub_eq_sub],\n  exact f.apply_line_map _ _ _,\nend\n\n/-- The preimage of a convex set under an affine map is convex. -/\nlemma convex.affine_preimage (f : E →ᵃ[ℝ] F) {s : set F} (hs : convex s) :\n  convex (f ⁻¹' s) :=\nbegin\n  intros x y xs ys a b ha hb hab,\n  rw [mem_preimage, convex.combo_affine_apply hab],\n  exact hs xs ys ha hb hab,\nend\n\n/-- The image of a convex set under an affine map is convex. -/\nlemma convex.affine_image (f : E →ᵃ[ℝ] F) {s : set E} (hs : convex s) :\n  convex (f '' s) :=\nbegin\n  rintros x y ⟨x', ⟨hx', hx'f⟩⟩ ⟨y', ⟨hy', hy'f⟩⟩ a b ha hb hab,\n  refine ⟨a • x' + b • y', ⟨hs hx' hy' ha hb hab, _⟩⟩,\n  rw [convex.combo_affine_apply hab, hx'f, hy'f]\nend\n\nlemma convex.linear_image (hs : convex s) (f : E →ₗ[ℝ] F) : convex (image f s) :=\nhs.affine_image f.to_affine_map\n\nlemma convex.is_linear_image (hs : convex s) {f : E → F} (hf : is_linear_map ℝ f) :\n  convex (f '' s) :=\nhs.linear_image $ hf.mk' f\n\nlemma convex.linear_preimage {s : set F} (hs : convex s) (f : E →ₗ[ℝ] F) :\n  convex (preimage f s) :=\nhs.affine_preimage f.to_affine_map\n\nlemma convex.is_linear_preimage {s : set F} (hs : convex s) {f : E → F} (hf : is_linear_map ℝ f) :\n  convex (preimage f s) :=\nhs.linear_preimage $ hf.mk' f\n\nlemma convex.neg (hs : convex s) : convex ((λ z, -z) '' s) :=\nhs.is_linear_image is_linear_map.is_linear_map_neg\n\nlemma convex.neg_preimage (hs : convex s) : convex ((λ z, -z) ⁻¹' s) :=\nhs.is_linear_preimage is_linear_map.is_linear_map_neg\n\nlemma convex.smul (c : ℝ) (hs : convex s) : convex (c • s) :=\nhs.linear_image (linear_map.lsmul _ _ c)\n\nlemma convex.smul_preimage (c : ℝ) (hs : convex s) : convex ((λ z, c • z) ⁻¹' s) :=\nhs.linear_preimage (linear_map.lsmul _ _ c)\n\nlemma convex.add {t : set E}  (hs : convex s) (ht : convex t) : convex (s + t) :=\nby { rw ← add_image_prod, exact (hs.prod ht).is_linear_image is_linear_map.is_linear_map_add }\n\nlemma convex.sub {t : set E}  (hs : convex s) (ht : convex t) :\n  convex ((λx : E × E, x.1 - x.2) '' (s.prod t)) :=\n(hs.prod ht).is_linear_image is_linear_map.is_linear_map_sub\n\nlemma convex.translate (hs : convex s) (z : E) : convex ((λx, z + x) '' s) :=\nhs.affine_image $ affine_map.const ℝ E z +ᵥ affine_map.id ℝ E\n\n/-- The translation of a convex set is also convex. -/\nlemma convex.translate_preimage_right (hs : convex s) (a : E) : convex ((λ z, a + z) ⁻¹' s) :=\nhs.affine_preimage $ affine_map.const ℝ E a +ᵥ affine_map.id ℝ E\n\n/-- The translation of a convex set is also convex. -/\nlemma convex.translate_preimage_left (hs : convex s) (a : E) : convex ((λ z, z + a) ⁻¹' s) :=\nby simpa only [add_comm] using hs.translate_preimage_right a\n\nlemma convex.affinity (hs : convex s) (z : E) (c : ℝ) : convex ((λx, z + c • x) '' s) :=\nhs.affine_image $ affine_map.const ℝ E z +ᵥ c • affine_map.id ℝ E\n\nlemma real.convex_iff_ord_connected {s : set ℝ} : convex s ↔ ord_connected s :=\nbegin\n  simp only [convex_iff_segment_subset, segment_eq_interval, ord_connected_iff_interval_subset],\n  exact forall_congr (λ x, forall_swap)\nend\n\nalias real.convex_iff_ord_connected ↔ convex.ord_connected set.ord_connected.convex\n\nlemma convex_Iio (r : ℝ) : convex (Iio r) := ord_connected_Iio.convex\nlemma convex_Ioi (r : ℝ) : convex (Ioi r) := ord_connected_Ioi.convex\nlemma convex_Iic (r : ℝ) : convex (Iic r) := ord_connected_Iic.convex\nlemma convex_Ici (r : ℝ) : convex (Ici r) := ord_connected_Ici.convex\nlemma convex_Ioo (r s : ℝ) : convex (Ioo r s) := ord_connected_Ioo.convex\nlemma convex_Ico (r s : ℝ) : convex (Ico r s) := ord_connected_Ico.convex\nlemma convex_Ioc (r : ℝ) (s : ℝ) : convex (Ioc r s) := ord_connected_Ioc.convex\nlemma convex_Icc (r : ℝ) (s : ℝ) : convex (Icc r s) := ord_connected_Icc.convex\nlemma convex_interval (r : ℝ) (s : ℝ) : convex (interval r s) := ord_connected_interval.convex\n\nlemma convex_segment (a b : E) : convex [a, b] :=\nbegin\n  have : (λ (t : ℝ), a + t • (b - a)) = (λz : E, a + z) ∘ (λt:ℝ, t • (b - a)) := rfl,\n  rw [segment_eq_image', this, image_comp],\n  refine ((convex_Icc _ _).is_linear_image _).translate _,\n  exact is_linear_map.is_linear_map_smul' _\nend\n\nlemma convex_halfspace_lt {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) :\n  convex {w | f w < r} :=\n(convex_Iio r).is_linear_preimage h\n\nlemma convex_halfspace_le {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) :\n  convex {w | f w ≤ r} :=\n(convex_Iic r).is_linear_preimage h\n\nlemma convex_halfspace_gt {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) :\n  convex {w | r < f w} :=\n(convex_Ioi r).is_linear_preimage h\n\nlemma convex_halfspace_ge {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) :\n  convex {w | r ≤ f w} :=\n(convex_Ici r).is_linear_preimage h\n\nlemma convex_hyperplane {f : E → ℝ} (h : is_linear_map ℝ f) (r : ℝ) :\n  convex {w | f w = r} :=\nbegin\n  show convex (f ⁻¹' {p | p = r}),\n  rw set_of_eq_eq_singleton,\n  exact (convex_singleton r).is_linear_preimage h\nend\n\nlemma convex_halfspace_re_lt (r : ℝ) : convex {c : ℂ | c.re < r} :=\nconvex_halfspace_lt (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_re_le (r : ℝ) : convex {c : ℂ | c.re ≤ r} :=\nconvex_halfspace_le (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_re_gt (r : ℝ) : convex {c : ℂ | r < c.re } :=\nconvex_halfspace_gt (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_re_lge (r : ℝ) : convex {c : ℂ | r ≤ c.re} :=\nconvex_halfspace_ge (is_linear_map.mk complex.add_re complex.smul_re) _\n\nlemma convex_halfspace_im_lt (r : ℝ) : convex {c : ℂ | c.im < r} :=\nconvex_halfspace_lt (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_halfspace_im_le (r : ℝ) : convex {c : ℂ | c.im ≤ r} :=\nconvex_halfspace_le (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_halfspace_im_gt (r : ℝ) : convex {c : ℂ | r < c.im } :=\nconvex_halfspace_gt (is_linear_map.mk complex.add_im complex.smul_im) _\n\nlemma convex_halfspace_im_lge (r : ℝ) : convex {c : ℂ | r ≤ c.im} :=\nconvex_halfspace_ge (is_linear_map.mk complex.add_im complex.smul_im) _\n\n/-! ### Convex combinations in intervals -/\n\nlemma convex.combo_self (a : α) {x y : α} (h : x + y = 1) : a = x * a + y * a :=\ncalc\n  a   = 1 * a         : by rw [one_mul]\n  ... = (x + y) * a   : by rw [h]\n  ... = x * a + y * a : by rw [add_mul]\n\n/--\nIf `x` is in an `Ioo`, it can be expressed as a convex combination of the endpoints.\n-/\nlemma convex.mem_Ioo {a b x : α} (h : a < b) :\n  x ∈ Ioo a b ↔ ∃ (x_a x_b : α), 0 < x_a ∧ 0 < x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x :=\nbegin\n  split,\n  { rintros ⟨h_ax, h_bx⟩,\n    by_cases hab : ¬a < b,\n    { exfalso; exact hab h },\n    { refine ⟨(b-x) / (b-a), (x-a) / (b-a), _⟩,\n      refine ⟨div_pos (by linarith) (by linarith), div_pos (by linarith) (by linarith),_,_⟩;\n      { field_simp [show b - a ≠ 0, by linarith], ring } } },\n  { rw [mem_Ioo],\n    rintros ⟨xa, xb, ⟨hxa, hxb, hxaxb, h₂⟩⟩,\n    rw [←h₂],\n    exact ⟨by nlinarith [convex.combo_self a hxaxb], by nlinarith [convex.combo_self b hxaxb]⟩ }\nend\n\n/-- If `x` is in an `Ioc`, it can be expressed as a convex combination of the endpoints. -/\nlemma convex.mem_Ioc {a b x : α} (h : a < b) :\n  x ∈ Ioc a b ↔ ∃ (x_a x_b : α), 0 ≤ x_a ∧ 0 < x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x :=\nbegin\n  split,\n  { rintros ⟨h_ax, h_bx⟩,\n    by_cases h_x : x = b,\n    { exact ⟨0, 1, by linarith, by linarith, by ring, by {rw [h_x], ring}⟩ },\n    { rcases (convex.mem_Ioo h).mp ⟨h_ax, lt_of_le_of_ne h_bx h_x⟩ with ⟨x_a, x_b, Ioo_case⟩,\n      exact ⟨x_a, x_b, by linarith, Ioo_case.2⟩ } },\n  { rw [mem_Ioc],\n    rintros ⟨xa, xb, ⟨hxa, hxb, hxaxb, h₂⟩⟩,\n    rw [←h₂],\n    exact ⟨by nlinarith [convex.combo_self a hxaxb], by nlinarith [convex.combo_self b hxaxb]⟩ }\nend\n\n/-- If `x` is in an `Ico`, it can be expressed as a convex combination of the endpoints. -/\nlemma convex.mem_Ico {a b x : α} (h : a < b) :\n  x ∈ Ico a b ↔ ∃ (x_a x_b : α), 0 < x_a ∧ 0 ≤ x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x :=\nbegin\n  split,\n  { rintros ⟨h_ax, h_bx⟩,\n    by_cases h_x : x = a,\n    { exact ⟨1, 0, by linarith, by linarith, by ring, by {rw [h_x], ring}⟩ },\n    { rcases (convex.mem_Ioo h).mp ⟨lt_of_le_of_ne h_ax (ne.symm h_x), h_bx⟩\n              with ⟨x_a, x_b, Ioo_case⟩,\n      exact ⟨x_a, x_b, Ioo_case.1, by linarith, (Ioo_case.2).2⟩ } },\n  { rw [mem_Ico],\n    rintros ⟨xa, xb, ⟨hxa, hxb, hxaxb, h₂⟩⟩,\n    rw [←h₂],\n    exact ⟨by nlinarith [convex.combo_self a hxaxb], by nlinarith [convex.combo_self b hxaxb]⟩ }\nend\n\n/-- If `x` is in an `Icc`, it can be expressed as a convex combination of the endpoints. -/\nlemma convex.mem_Icc {a b x : α} (h : a ≤ b) :\n  x ∈ Icc a b ↔ ∃ (x_a x_b : α), 0 ≤ x_a ∧ 0 ≤ x_b ∧ x_a + x_b = 1 ∧ x_a * a + x_b * b = x :=\nbegin\n  split,\n  { intro x_in_I,\n    rw [Icc, mem_set_of_eq] at x_in_I,\n    rcases x_in_I with ⟨h_ax, h_bx⟩,\n    by_cases hab' : a = b,\n    { exact ⟨0, 1, le_refl 0, by linarith, by ring, by linarith⟩ },\n    change a ≠ b at hab',\n    replace h : a < b, exact lt_of_le_of_ne h hab',\n    by_cases h_x : x = a,\n    { exact ⟨1, 0, by linarith, by linarith, by ring, by {rw [h_x], ring}⟩ },\n    { rcases (convex.mem_Ioc h).mp ⟨lt_of_le_of_ne h_ax (ne.symm h_x), h_bx⟩\n              with ⟨x_a, x_b, Ioo_case⟩,\n      exact ⟨x_a, x_b, Ioo_case.1, by linarith, (Ioo_case.2).2⟩ } },\n  { rw [mem_Icc],\n    rintros ⟨xa, xb, ⟨hxa, hxb, hxaxb, h₂⟩⟩,\n    rw [←h₂],\n    exact ⟨by nlinarith [convex.combo_self a hxaxb], by nlinarith [convex.combo_self b hxaxb]⟩ }\nend\n\n\nsection submodule\n\nopen submodule\n\nlemma submodule.convex (K : submodule ℝ E) : convex (↑K : set E) :=\nby { repeat {intro}, refine add_mem _ (smul_mem _ _ _) (smul_mem _ _ _); assumption }\n\nlemma subspace.convex (K : subspace ℝ E) : convex (↑K : set E) := K.convex\n\nend submodule\n\nend sets\n\n/-! ### Convex and concave functions -/\n\nsection functions\n\nvariables {β : Type*} [ordered_add_comm_monoid β] [module ℝ β]\n\nlocal notation `[`x `, ` y `]` := segment x y\n\n/-- Convexity of functions -/\ndef convex_on (s : set E) (f : E → β) : Prop :=\n  convex s ∧\n  ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →\n    f (a • x + b • y) ≤ a • f x + b • f y\n\n/-- Concavity of functions -/\ndef concave_on (s : set E) (f : E → β) : Prop :=\n  convex s ∧\n  ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →\n    a • f x + b • f y ≤ f (a • x + b • y)\n\nsection\nvariables [ordered_module ℝ β]\n\n/-- A function `f` is concave iff `-f` is convex. -/\n@[simp] lemma neg_convex_on_iff {γ : Type*} [ordered_add_comm_group γ] [module ℝ γ]\n  (s : set E) (f : E → γ) : convex_on s (-f) ↔ concave_on s f :=\nbegin\n  split,\n  { rintros ⟨hconv, h⟩,\n    refine ⟨hconv, _⟩,\n    intros x y xs ys a b ha hb hab,\n    specialize h xs ys ha hb hab,\n    simp [neg_apply, neg_le, add_comm] at h,\n    exact h },\n  { rintros ⟨hconv, h⟩,\n    refine ⟨hconv, _⟩,\n    intros x y xs ys a b ha hb hab,\n    specialize h xs ys ha hb hab,\n    simp [neg_apply, neg_le, add_comm, h] }\nend\n\n/-- A function `f` is concave iff `-f` is convex. -/\n@[simp] lemma neg_concave_on_iff {γ : Type*} [ordered_add_comm_group γ] [module ℝ γ]\n  (s : set E) (f : E → γ) : concave_on s (-f) ↔ convex_on s f:=\nby rw [← neg_convex_on_iff s (-f), neg_neg f]\n\nend\n\nlemma convex_on_id {s : set ℝ} (hs : convex s) : convex_on s id := ⟨hs, by { intros, refl }⟩\n\nlemma concave_on_id {s : set ℝ} (hs : convex s) : concave_on s id := ⟨hs, by { intros, refl }⟩\n\nlemma convex_on_const (c : β) (hs : convex s) : convex_on s (λ x:E, c) :=\n⟨hs, by { intros, simp only [← add_smul, *, one_smul] }⟩\n\nlemma concave_on_const (c : β) (hs : convex s) : concave_on s (λ x:E, c) :=\n@convex_on_const _ _ _ _ (order_dual β) _ _ c hs\n\nvariables {t : set E}\n\nlemma convex_on_iff_div {f : E → β} :\n  convex_on s f ↔ convex s ∧ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀  ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → 0 < a + b →\n    f ((a/(a+b)) • x + (b/(a+b)) • y) ≤ (a/(a+b)) • f x + (b/(a+b)) • f y :=\nand_congr iff.rfl\n⟨begin\n  intros h x y hx hy a b ha hb hab,\n  apply h hx hy (div_nonneg ha $ le_of_lt hab) (div_nonneg hb $ le_of_lt hab),\n  rw [←add_div],\n  exact div_self (ne_of_gt hab)\nend,\nbegin\n  intros h x y hx hy a b ha hb hab,\n  simpa [hab, zero_lt_one] using h hx hy ha hb,\nend⟩\n\nlemma concave_on_iff_div {f : E → β} :\n  concave_on s f ↔ convex s ∧ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀  ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → 0 < a + b →\n    (a/(a+b)) • f x + (b/(a+b)) • f y ≤ f ((a/(a+b)) • x + (b/(a+b)) • y) :=\n@convex_on_iff_div _ _ _ _ (order_dual β) _ _ _\n\n/-- For a function on a convex set in a linear ordered space, in order to prove that it is convex\nit suffices to verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y`\nand positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with\nlexicographic order. -/\nlemma linear_order.convex_on_of_lt {f : E → β} [linear_order E] (hs : convex s)\n  (hf : ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → x < y → ∀ ⦃a b : ℝ⦄, 0 < a → 0 < b → a + b = 1 →\n    f (a • x + b • y) ≤ a • f x + b • f y) : convex_on s f :=\nbegin\n  use hs,\n  intros x y hx hy a b ha hb hab,\n  wlog hxy : x<=y using [x y a b, y x b a],\n  { exact le_total _ _ },\n  { cases eq_or_lt_of_le hxy with hxy hxy,\n      by { subst y, rw [← add_smul, ← add_smul, hab, one_smul, one_smul] },\n    cases eq_or_lt_of_le ha with ha ha,\n      by { subst a, rw [zero_add] at hab, subst b, simp },\n    cases eq_or_lt_of_le hb with hb hb,\n      by { subst b, rw [add_zero] at hab, subst a, simp },\n    exact hf hx hy hxy ha hb hab }\nend\n\n/-- For a function on a convex set in a linear ordered space, in order to prove that it is concave\nit suffices to verify the inequality `a • f x + b • f y ≤ f (a • x + b • y)` only for `x < y`\nand positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with\nlexicographic order. -/\nlemma linear_order.concave_on_of_lt {f : E → β} [linear_order E] (hs : convex s)\n  (hf : ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → x < y → ∀ ⦃a b : ℝ⦄, 0 < a → 0 < b → a + b = 1 →\n     a • f x + b • f y ≤ f (a • x + b • y)) : concave_on s f :=\n@linear_order.convex_on_of_lt _ _ _ _ (order_dual β) _ _ f _ hs hf\n\n/-- For a function `f` defined on a convex subset `D` of `ℝ`, if for any three points `x<y<z`\nthe slope of the secant line of `f` on `[x, y]` is less than or equal to the slope\nof the secant line of `f` on `[x, z]`, then `f` is convex on `D`. This way of proving convexity\nof a function is used in the proof of convexity of a function with a monotone derivative. -/\nlemma convex_on_real_of_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ → ℝ}\n  (hf : ∀ {x y z : ℝ}, x ∈ s → z ∈ s → x < y → y < z →\n    (f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) :\n  convex_on 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 [← one_mul x, ← hab, add_mul],\n    exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },\n  have hyz : y < z,\n  { rw [← one_mul z, ← 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_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),\n  have A : z - y + (y - x) = z - x, by abel,\n  have B : 0 < z - x, from sub_pos.2 (lt_trans hxy hyz),\n  rw [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, A,\n    ← le_div_iff B, add_div, mul_div_assoc, mul_div_assoc,\n    mul_comm (f x), mul_comm (f z)] at this,\n  rw [eq_comm, ← sub_eq_iff_eq_add] at hab; subst a,\n  convert this; symmetry; simp only [div_eq_iff (ne_of_gt B), y]; ring\nend\n\n/-- For a function `f` defined on a subset `D` of `ℝ`, if `f` is convex on `D`, then for any three\npoints `x<y<z`, the slope of the secant line of `f` on `[x, y]` is less than or equal to the slope\nof the secant line of `f` on `[x, z]`. -/\nlemma convex_on.slope_mono_adjacent {s : set ℝ} {f : ℝ → ℝ} (hf : convex_on s f)\n  {x y z : ℝ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :\n  (f y - f x) / (y - x) ≤ (f z - f y) / (z - y) :=\nbegin\n  have h₁ : 0 < y - x := by linarith,\n  have h₂ : 0 < z - y := by linarith,\n  have h₃ : 0 < z - x := by linarith,\n  suffices : f y / (y - x) + f y / (z - y) ≤ f x / (y - x) + f z / (z - y),\n    by { ring_nf at this ⊢, linarith },\n  set a := (z - y) / (z - x),\n  set b := (y - x) / (z - x),\n  have heqz : a • x + b • z = y, by { field_simp, rw div_eq_iff; [ring, linarith], },\n  have key, from\n    hf.2 hx hz\n      (show 0 ≤ a, by apply div_nonneg; linarith)\n      (show 0 ≤ b, by apply div_nonneg; linarith)\n      (show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith], }),\n  rw heqz at key,\n  replace key := mul_le_mul_of_nonneg_left key (le_of_lt h₃),\n  field_simp [ne_of_gt h₁, ne_of_gt h₂, ne_of_gt h₃, mul_comm (z - x) _] at key ⊢,\n  rw div_le_div_right,\n  { linarith, },\n  { nlinarith, },\nend\n\n/-- For a function `f` defined on a convex subset `D` of `ℝ`, `f` is convex on `D` iff for any three\npoints `x<y<z` the slope of the secant line of `f` on `[x, y]` is less than or equal to the slope\nof the secant line of `f` on `[x, z]`. -/\nlemma convex_on_real_iff_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ → ℝ} :\n  convex_on s f ↔\n  (∀ {x y z : ℝ}, x ∈ s → z ∈ s → x < y → y < z →\n    (f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) :=\n⟨convex_on.slope_mono_adjacent, convex_on_real_of_slope_mono_adjacent hs⟩\n\n/-- For a function `f` defined on a convex subset `D` of `ℝ`, if for any three points `x<y<z`\nthe slope of the secant line of `f` on `[x, y]` is greater than or equal to the slope\nof the secant line of `f` on `[x, z]`, then `f` is concave on `D`. -/\nlemma concave_on_real_of_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ → ℝ}\n  (hf : ∀ {x y z : ℝ}, x ∈ s → z ∈ s → x < y → y < z →\n    (f z - f y) / (z - y) ≤ (f y - f x) / (y - x)) : concave_on s f :=\nbegin\n  rw [←neg_convex_on_iff],\n  apply convex_on_real_of_slope_mono_adjacent hs,\n  intros x y z xs zs xy yz,\n  rw [←neg_le_neg_iff, ←neg_div, ←neg_div, neg_sub, neg_sub],\n  simp only [hf xs zs xy yz, neg_sub_neg, pi.neg_apply],\nend\n\n/-- For a function `f` defined on a subset `D` of `ℝ`, if `f` is concave on `D`, then for any three\npoints `x<y<z`, the slope of the secant line of `f` on `[x, y]` is greater than or equal to the\nslope of the secant line of `f` on `[x, z]`. -/\nlemma concave_on.slope_mono_adjacent {s : set ℝ} {f : ℝ → ℝ} (hf : concave_on s f)\n  {x y z : ℝ} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :\n  (f z - f y) / (z - y) ≤ (f y - f x) / (y - x) :=\nbegin\n  rw [←neg_le_neg_iff, ←neg_div, ←neg_div, neg_sub, neg_sub],\n  rw [←neg_sub_neg (f y), ←neg_sub_neg (f z)],\n  simp_rw [←pi.neg_apply],\n  rw [←neg_convex_on_iff] at hf,\n  apply convex_on.slope_mono_adjacent hf; assumption,\nend\n\n/-- For a function `f` defined on a convex subset `D` of `ℝ`, `f` is concave on `D` iff for any\nthree points `x<y<z` the slope of the secant line of `f` on `[x, y]` is greater than or equal to\nthe slope of the secant line of `f` on `[x, z]`. -/\nlemma concave_on_real_iff_slope_mono_adjacent {s : set ℝ} (hs : convex s) {f : ℝ → ℝ} :\n  concave_on s f ↔\n  (∀ {x y z : ℝ}, x ∈ s → z ∈ s → x < y → y < z →\n    (f z - f y) / (z - y) ≤ (f y - f x) / (y - x)) :=\n⟨concave_on.slope_mono_adjacent, concave_on_real_of_slope_mono_adjacent hs⟩\n\nlemma convex_on.subset {f : E → β} (h_convex_on : convex_on t f)\n  (h_subset : s ⊆ t) (h_convex : convex s) : convex_on s f :=\nbegin\n  apply and.intro h_convex,\n  intros x y hx hy,\n  exact h_convex_on.2 (h_subset hx) (h_subset hy),\nend\n\nlemma concave_on.subset {f : E → β} (h_concave_on : concave_on t f)\n  (h_subset : s ⊆ t) (h_convex : convex s) : concave_on s f :=\n@convex_on.subset _ _ _ _ (order_dual β) _ _ t f h_concave_on h_subset h_convex\n\nlemma convex_on.add {f g : E → β} (hf : convex_on s f) (hg : convex_on s g) :\n  convex_on s (λx, f x + g x) :=\nbegin\n  apply and.intro hf.1,\n  intros x y hx hy a b ha hb hab,\n  calc\n    f (a • x + b • y) + g (a • x + b • y) ≤ (a • f x + b • f y) + (a • g x + b • g y)\n      : add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)\n    ... = a • f x + a • g x + b • f y + b • g y : by abel\n    ... = a • (f x + g x) + b • (f y + g y) : by simp [smul_add, add_assoc]\nend\n\nlemma concave_on.add {f g : E → β} (hf : concave_on s f) (hg : concave_on s g) :\n  concave_on s (λx, f x + g x) :=\n@convex_on.add _ _ _ _ (order_dual β) _ _ f g hf hg\n\nlemma convex_on.smul [ordered_module ℝ β] {f : E → β} {c : ℝ} (hc : 0 ≤ c)\n  (hf : convex_on s f) : convex_on s (λx, c • f x) :=\nbegin\n  apply and.intro hf.1,\n  intros x y hx hy a b ha hb hab,\n  calc\n    c • f (a • x + b • y) ≤ c • (a • f x + b • f y)\n      : smul_le_smul_of_nonneg (hf.2 hx hy ha hb hab) hc\n    ... = a • (c • f x) + b • (c • f y) : by simp only [smul_add, smul_comm c]\nend\n\nlemma concave_on.smul [ordered_module ℝ β] {f : E → β} {c : ℝ} (hc : 0 ≤ c)\n  (hf : concave_on s f) : concave_on s (λx, c • f x) :=\n@convex_on.smul _ _ _ _ (order_dual β) _ _ _ f c hc hf\n\n/-- A convex function on a segment is upper-bounded by the max of its endpoints. -/\nlemma convex_on.le_on_segment' {γ : Type*}\n  [linear_ordered_add_comm_group γ] [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} {x y : E} {a b : ℝ}\n  (hf : convex_on s f) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :\n  f (a • x + b • y) ≤ max (f x) (f y) :=\ncalc\n  f (a • x + b • y) ≤ a • f x + b • f y : hf.2 hx hy ha hb hab\n  ... ≤ a • max (f x) (f y) + b • max (f x) (f y) :\n    add_le_add (smul_le_smul_of_nonneg (le_max_left _ _) ha)\n      (smul_le_smul_of_nonneg (le_max_right _ _) hb)\n  ... ≤ max (f x) (f y) : by rw [←add_smul, hab, one_smul]\n\n/-- A concave function on a segment is lower-bounded by the min of its endpoints. -/\nlemma concave_on.le_on_segment' {γ : Type*}\n  [linear_ordered_add_comm_group γ] [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} {x y : E} {a b : ℝ}\n  (hf : concave_on s f) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :\n  min (f x) (f y) ≤ f (a • x + b • y) :=\n@convex_on.le_on_segment' _ _ _ _ (order_dual γ) _ _ _ f x y a b hf hx hy ha hb hab\n\n/-- A convex function on a segment is upper-bounded by the max of its endpoints. -/\nlemma convex_on.le_on_segment {γ : Type*}\n  [linear_ordered_add_comm_group γ] [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} (hf : convex_on s f) {x y z : E}\n  (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x, y]) :\n  f z ≤ max (f x) (f y) :=\nlet ⟨a, b, ha, hb, hab, hz⟩ := hz in hz ▸ hf.le_on_segment' hx hy ha hb hab\n\n/-- A concave function on a segment is lower-bounded by the min of its endpoints. -/\nlemma concave_on.le_on_segment {γ : Type*}\n  [linear_ordered_add_comm_group γ] [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} (hf : concave_on s f) {x y z : E}\n  (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x, y]) :\n    min (f x) (f y) ≤ f z :=\n@convex_on.le_on_segment _ _ _ _ (order_dual γ) _ _ _ f hf x y z hx hy hz\n\nlemma convex_on.convex_le [ordered_module ℝ β] {f : E → β} (hf : convex_on s f) (r : β) :\n  convex {x ∈ s | f x ≤ r} :=\nconvex_iff_segment_subset.2 $ λ x y hx hy z hz,\nbegin\n  refine ⟨hf.1.segment_subset hx.1 hy.1 hz,_⟩,\n  rcases hz with ⟨za,zb,hza,hzb,hzazb,H⟩,\n  rw ←H,\n  calc\n    f (za • x + zb • y) ≤ za • (f x) + zb • (f y) : hf.2 hx.1 hy.1 hza hzb hzazb\n                    ... ≤ za • r + zb • r         : add_le_add (smul_le_smul_of_nonneg hx.2 hza)\n                                                      (smul_le_smul_of_nonneg hy.2 hzb)\n                    ... ≤ r                       : by simp [←add_smul, hzazb]\nend\n\nlemma concave_on.concave_le [ordered_module ℝ β] {f : E → β} (hf : concave_on s f) (r : β) :\n  convex {x ∈ s | r ≤ f x} :=\n@convex_on.convex_le _ _ _ _ (order_dual β) _ _ _ f hf r\n\nlemma convex_on.convex_lt {γ : Type*} [ordered_cancel_add_comm_monoid γ]\n  [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} (hf : convex_on s f) (r : γ) : convex {x ∈ s | f x < r} :=\nbegin\n  intros a b as bs xa xb hxa hxb hxaxb,\n  refine ⟨hf.1 as.1 bs.1 hxa hxb hxaxb, _⟩,\n  dsimp,\n  by_cases H : xa = 0,\n  { have H' : xb = 1 := by rwa [H, zero_add] at hxaxb,\n    rw [H, H', zero_smul, one_smul, zero_add],\n    exact bs.2 },\n  { calc\n      f (xa • a + xb • b) ≤ xa • (f a) + xb • (f b) : hf.2 as.1 bs.1 hxa hxb hxaxb\n                      ... < xa • r + xb • (f b)     : (add_lt_add_iff_right (xb • (f b))).mpr\n                                                        (smul_lt_smul_of_pos as.2\n                                                          (lt_of_le_of_ne hxa (ne.symm H)))\n                      ... ≤ xa • r + xb • r         : (add_le_add_iff_left (xa • r)).mpr\n                                                        (smul_le_smul_of_nonneg bs.2.le hxb)\n                      ... = r                       : by simp only [←add_smul, hxaxb, one_smul] }\nend\n\nlemma concave_on.convex_lt {γ : Type*} [ordered_cancel_add_comm_monoid γ]\n  [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} (hf : concave_on s f) (r : γ) : convex {x ∈ s | r < f x} :=\n@convex_on.convex_lt _ _ _ _ (order_dual γ) _ _ _ f hf r\n\nlemma convex_on.convex_epigraph {γ : Type*} [ordered_add_comm_group γ]\n  [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} (hf : convex_on s f) :\n  convex {p : E × γ | p.1 ∈ s ∧ f p.1 ≤ p.2} :=\nbegin\n  rintros ⟨x, r⟩ ⟨y, t⟩ ⟨hx, hr⟩ ⟨hy, ht⟩ a b ha hb hab,\n  refine ⟨hf.1 hx hy ha hb hab, _⟩,\n  calc f (a • x + b • y) ≤ a • f x + b • f y : hf.2 hx hy ha hb hab\n  ... ≤ a • r + b • t : add_le_add (smul_le_smul_of_nonneg hr ha)\n                            (smul_le_smul_of_nonneg ht hb)\nend\n\nlemma concave_on.convex_hypograph {γ : Type*} [ordered_add_comm_group γ]\n  [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} (hf : concave_on s f) :\n  convex {p : E × γ | p.1 ∈ s ∧ p.2 ≤ f p.1} :=\n@convex_on.convex_epigraph _ _ _ _ (order_dual γ) _ _ _ f hf\n\nlemma convex_on_iff_convex_epigraph {γ : Type*} [ordered_add_comm_group γ]\n  [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} :\n  convex_on s f ↔ convex {p : E × γ | p.1 ∈ s ∧ f p.1 ≤ p.2} :=\nbegin\n  refine ⟨convex_on.convex_epigraph, λ h, ⟨_, _⟩⟩,\n  { assume x y hx hy a b ha hb hab,\n    exact (@h (x, f x) (y, f y) ⟨hx, le_refl _⟩ ⟨hy, le_refl _⟩ a b ha hb hab).1 },\n  { assume x y hx hy a b ha hb hab,\n    exact (@h (x, f x) (y, f y) ⟨hx, le_refl _⟩ ⟨hy, le_refl _⟩ a b ha hb hab).2 }\nend\n\nlemma concave_on_iff_convex_hypograph {γ : Type*} [ordered_add_comm_group γ]\n  [module ℝ γ] [ordered_module ℝ γ]\n  {f : E → γ} :\n  concave_on s f ↔ convex {p : E × γ | p.1 ∈ s ∧ p.2 ≤ f p.1} :=\n@convex_on_iff_convex_epigraph _ _ _ _ (order_dual γ) _ _ _ f\n\n/-- If a function is convex on `s`, it remains convex when precomposed by an affine map. -/\nlemma convex_on.comp_affine_map {f : F → β} (g : E →ᵃ[ℝ] F) {s : set F}\n  (hf : convex_on s f) : convex_on (g ⁻¹' s) (f ∘ g) :=\nbegin\n  refine ⟨hf.1.affine_preimage  _,_⟩,\n  intros x y xs ys a b ha hb hab,\n  calc\n    (f ∘ g) (a • x + b • y) = f (g (a • x + b • y))         : rfl\n                       ...  = f (a • (g x) + b • (g y))     : by rw [convex.combo_affine_apply hab]\n                       ...  ≤ a • f (g x) + b • f (g y)     : hf.2 xs ys ha hb hab\n                       ...  = a • (f ∘ g) x + b • (f ∘ g) y : rfl\nend\n\n/-- If a function is concave on `s`, it remains concave when precomposed by an affine map. -/\nlemma concave_on.comp_affine_map {f : F → β} (g : E →ᵃ[ℝ] F) {s : set F}\n  (hf : concave_on s f) : concave_on (g ⁻¹' s) (f ∘ g) :=\n@convex_on.comp_affine_map _ _ _ _ _ _ (order_dual β) _ _ f g s hf\n\n/-- If `g` is convex on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/\nlemma convex_on.comp_linear_map {g : F → β} {s : set F} (hg : convex_on s g) (f : E →ₗ[ℝ] F) :\n  convex_on (f ⁻¹' s) (g ∘ f) :=\nhg.comp_affine_map f.to_affine_map\n\n/-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/\nlemma concave_on.comp_linear_map {g : F → β} {s : set F} (hg : concave_on s g) (f : E →ₗ[ℝ] F) :\n  concave_on (f ⁻¹' s) (g ∘ f) :=\nhg.comp_affine_map f.to_affine_map\n\n/-- If a function is convex on `s`, it remains convex after a translation. -/\nlemma convex_on.translate_right {f : E → β} {s : set E} {a : E} (hf : convex_on s f) :\n  convex_on ((λ z, a + z) ⁻¹' s) (f ∘ (λ z, a + z)) :=\nhf.comp_affine_map $ affine_map.const ℝ E a +ᵥ affine_map.id ℝ E\n\n/-- If a function is concave on `s`, it remains concave after a translation. -/\nlemma concave_on.translate_right {f : E → β} {s : set E} {a : E} (hf : concave_on s f) :\n  concave_on ((λ z, a + z) ⁻¹' s) (f ∘ (λ z, a + z)) :=\nhf.comp_affine_map $ affine_map.const ℝ E a +ᵥ affine_map.id ℝ E\n\n/-- If a function is convex on `s`, it remains convex after a translation. -/\nlemma convex_on.translate_left {f : E → β} {s : set E} {a : E} (hf : convex_on s f) :\n  convex_on ((λ z, a + z) ⁻¹' s) (f ∘ (λ z, z + a)) :=\nby simpa only [add_comm] using  hf.translate_right\n\n/-- If a function is concave on `s`, it remains concave after a translation. -/\nlemma concave_on.translate_left {f : E → β} {s : set E} {a : E} (hf : concave_on s f) :\n  concave_on ((λ z, a + z) ⁻¹' s) (f ∘ (λ z, z + a)) :=\nby simpa only [add_comm] using  hf.translate_right\n\nend functions\n\n/-! ### Center of mass -/\n\nsection center_mass\n\n/-- Center of mass of a finite collection of points with prescribed weights.\nNote that we require neither `0 ≤ w i` nor `∑ w = 1`. -/\nnoncomputable def finset.center_mass (t : finset ι) (w : ι → ℝ) (z : ι → E) : E :=\n(∑ i in t, w i)⁻¹ • (∑ i in t, w i • z i)\n\nvariables (i j : ι) (c : ℝ) (t : finset ι) (w : ι → ℝ) (z : ι → E)\n\nopen finset\n\nlemma finset.center_mass_empty : (∅ : finset ι).center_mass w z = 0 :=\nby simp only [center_mass, sum_empty, smul_zero]\n\nlemma finset.center_mass_pair (hne : i ≠ j) :\n  ({i, j} : finset ι).center_mass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • 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 ∉ t) (hw : ∑ j in t, w j ≠ 0) :\n  (insert i t).center_mass w z = (w i / (w i + ∑ j in t, w j)) • z i +\n    ((∑ j in t, w j) / (w i + ∑ j in t, w j)) • t.center_mass w z :=\nbegin\n  simp only [center_mass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← 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 ≠ 0) : ({i} : finset ι).center_mass w z = z i :=\nby rw [center_mass, sum_singleton, sum_singleton, ← mul_smul, inv_mul_cancel hw, one_smul]\n\nlemma finset.center_mass_eq_of_sum_1 (hw : ∑ i in t, w i = 1) :\n  t.center_mass w z = ∑ i in t, w i • z i :=\nby simp only [finset.center_mass, hw, inv_one, one_smul]\n\nlemma finset.center_mass_smul : t.center_mass w (λ i, c • z i) = c • 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 ι) (t : finset ι') (ws : ι → ℝ) (zs : ι → E) (wt : ι' → ℝ) (zt : ι' → E)\n  (hws : ∑ i in s, ws i = 1) (hwt : ∑ i in t, wt i = 1) (a b : ℝ) (hab : a + b = 1) :\n  a • s.center_mass ws zs + b • t.center_mass wt zt =\n    (s.map function.embedding.inl ∪ t.map function.embedding.inr).center_mass\n      (sum.elim (λ i, a * ws i) (λ 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, ← finset.sum_sum_elim, finset.center_mass_eq_of_sum_1],\n  { congr' with ⟨⟩; simp only [sum.elim_inl, sum.elim_inr, mul_smul] },\n  { rw [sum_sum_elim, ← mul_sum, ← 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 ι) (w₁ w₂ : ι → ℝ) (z : ι → E)\n  (hw₁ : ∑ i in s, w₁ i = 1) (hw₂ : ∑ i in s, w₂ i = 1) (a b : ℝ) (hab : a + b = 1) :\n  a • s.center_mass w₁ z + b • s.center_mass w₂ z =\n    s.center_mass (λ i, a * w₁ i + b * w₂ i) z :=\nhave hw : ∑ i in s, (a * w₁ i + b * w₂ 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 ∈ t) :\n  t.center_mass (λ j, if (i = j) then 1 else 0) z = z i :=\nbegin\n  rw [finset.center_mass_eq_of_sum_1],\n  transitivity ∑ j in t, if (i = j) then z i else 0,\n  { congr' with i, split_ifs, exacts [h ▸ 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 ι} (ht : t ⊆ t')\n  (h : ∀ i ∈ t', i ∉ t → 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 (λ i, w i ≠ 0)).center_mass w z = t.center_mass w z :=\nfinset.center_mass_subset z (filter_subset _ _) $ λ 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 s) :\n  (∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i in t, w i) → (∀ i ∈ t, z i ∈ s) → t.center_mass w z ∈ s :=\nbegin\n  induction t using finset.induction with i t hi ht, { simp [lt_irrefl] },\n  intros h₀ hpos hmem,\n  have zi : z i ∈ s, from hmem _ (mem_insert_self _ _),\n  have hs₀ : ∀ j ∈ t, 0 ≤ w j, from λ j hj, h₀ j $ mem_insert_of_mem hj,\n  rw [sum_insert hi] at hpos,\n  by_cases hsum_t : ∑ j in t, w j = 0,\n  { have ws : ∀ j ∈ t, w j = 0, from (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t,\n    have wz : ∑ j in t, w j • z j = 0, from sum_eq_zero (λ 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 [← 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₀ _ _) _ (sum_nonneg hs₀) hpos,\n    { exact lt_of_le_of_ne (sum_nonneg hs₀) (ne.symm hsum_t) },\n    { intros j hj, exact hmem j (mem_insert_of_mem hj) },\n    { exact h₀ _ (mem_insert_self _ _) } }\nend\n\nlemma convex.sum_mem (hs : convex s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i in t, w i = 1)\n  (hz : ∀ i ∈ t, z i ∈ s) :\n  ∑ i in t, w i • z i ∈ s :=\nby simpa only [h₁, center_mass, inv_one, one_smul] using\n  hs.center_mass_mem h₀ (h₁.symm ▸ zero_lt_one) hz\n\nlemma convex_iff_sum_mem :\n  convex s ↔\n    (∀ (t : finset E) (w : E → ℝ),\n      (∀ i ∈ t, 0 ≤ w i) → ∑ i in t, w i = 1 → (∀ x ∈ t, x ∈ s) → ∑ x in t, w x • x ∈ s ) :=\nbegin\n  refine ⟨λ hs t w hw₀ hw₁ hts, hs.sum_mem hw₀ hw₁ hts, _⟩,\n  intros h x y hx hy a b ha hb hab,\n  by_cases h_cases: x = y,\n  { rw [h_cases, ←add_smul, hab, one_smul], exact hy },\n  { convert h {x, y} (λ 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\n/-- Jensen's inequality, `finset.center_mass` version. -/\nlemma convex_on.map_center_mass_le {f : E → ℝ} (hf : convex_on s f)\n  (h₀ : ∀ i ∈ t, 0 ≤ w i) (hpos : 0 < ∑ i in t, w i)\n  (hmem : ∀ i ∈ t, z i ∈ s) : f (t.center_mass w z) ≤ t.center_mass w (f ∘ z) :=\nbegin\n  have hmem' : ∀ i ∈ t, (z i, (f ∘ z) i) ∈ {p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2},\n    from λ i hi, ⟨hmem i hi, le_refl _⟩,\n  convert (hf.convex_epigraph.center_mass_mem h₀ hpos hmem').2;\n    simp only [center_mass, function.comp, prod.smul_fst, prod.fst_sum, prod.smul_snd, prod.snd_sum]\nend\n\n/-- Jensen's inequality, `finset.sum` version. -/\nlemma convex_on.map_sum_le {f : E → ℝ} (hf : convex_on s f)\n  (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i in t, w i = 1)\n  (hmem : ∀ i ∈ t, z i ∈ s) : f (∑ i in t, w i • z i) ≤ ∑ i in t, w i * (f (z i)) :=\nby simpa only [center_mass, h₁, inv_one, one_smul]\n  using hf.map_center_mass_le h₀ (h₁.symm ▸ zero_lt_one) hmem\n\n/-- If a function `f` is convex on `s` takes value `y` at the center of mass of some points\n`z i ∈ s`, then for some `i` we have `y ≤ f (z i)`. -/\nlemma convex_on.exists_ge_of_center_mass {f : E → ℝ} (h : convex_on s f)\n  (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i in t, w i) (hz : ∀ i ∈ t, z i ∈ s) :\n  ∃ i ∈ t, f (t.center_mass w z) ≤ f (z i) :=\nbegin\n  set y := t.center_mass w z,\n  have : f y ≤ t.center_mass w (f ∘ z) := h.map_center_mass_le hw₀ hws hz,\n  rw ← sum_filter_ne_zero at hws,\n  rw [← finset.center_mass_filter_ne_zero (f ∘ z), center_mass, smul_eq_mul,\n    ← div_eq_inv_mul, le_div_iff hws, mul_sum] at this,\n  replace : ∃ i ∈ t.filter (λ i, w i ≠ 0), f y * w i ≤ w i • (f ∘ z) i :=\n    exists_le_of_sum_le (nonempty_of_sum_ne_zero (ne_of_gt hws)) this,\n  rcases this with ⟨i, hi, H⟩,\n  rw [mem_filter] at hi,\n  use [i, hi.1],\n  simp only [smul_eq_mul, mul_comm (w i)] at H,\n  refine (mul_le_mul_right _).1 H,\n  exact lt_of_le_of_ne (hw₀ i hi.1) hi.2.symm\nend\n\nend center_mass\n\n/-! ### Convex hull -/\n\nsection convex_hull\n\nvariable {t : set E}\n\n/-- The convex hull of a set `s` is the minimal convex set that includes `s`. -/\ndef convex_hull (s : set E) : set E :=\n⋂ (t : set E) (hst : s ⊆ t) (ht : convex t), t\n\nvariable (s)\n\nlemma subset_convex_hull : s ⊆ convex_hull s :=\nset.subset_Inter $ λ t, set.subset_Inter $ λ hst, set.subset_Inter $ λ ht, hst\n\nlemma convex_convex_hull : convex (convex_hull s) :=\nconvex_Inter $ λ t, convex_Inter $ λ ht, convex_Inter id\n\nvariable {s}\n\nlemma convex_hull_min (hst : s ⊆ t) (ht : convex t) : convex_hull s ⊆ t :=\nset.Inter_subset_of_subset t $ set.Inter_subset_of_subset hst $ set.Inter_subset _ ht\n\nlemma convex_hull_mono (hst : s ⊆ t) : convex_hull s ⊆ convex_hull t :=\nconvex_hull_min (set.subset.trans hst $ subset_convex_hull t) (convex_convex_hull t)\n\nlemma convex.convex_hull_eq {s : set E} (hs : convex s) : convex_hull s = s :=\nset.subset.antisymm (convex_hull_min (set.subset.refl _) hs) (subset_convex_hull s)\n\n@[simp]\nlemma convex_hull_empty :\n  convex_hull (∅ : set E) = ∅ :=\nconvex_empty.convex_hull_eq\n\n@[simp]\nlemma convex_hull_empty_iff :\n  convex_hull s = ∅ ↔ s = ∅ :=\nbegin\n  split,\n  { intro h,\n    rw [←set.subset_empty_iff, ←h],\n    exact subset_convex_hull _ },\n  { rintro rfl,\n    exact convex_hull_empty }\nend\n\n@[simp]\nlemma convex_hull_singleton {x : E} : convex_hull ({x} : set E) = {x} :=\n(convex_singleton x).convex_hull_eq\n\nlemma is_linear_map.image_convex_hull {f : E → F} (hf : is_linear_map ℝ f) :\n  f '' (convex_hull s) = convex_hull (f '' s) :=\nbegin\n  refine set.subset.antisymm _ _,\n  { rw [set.image_subset_iff],\n    exact convex_hull_min (set.image_subset_iff.1 $ subset_convex_hull $ f '' s)\n      ((convex_convex_hull (f '' s)).is_linear_preimage hf) },\n  { exact convex_hull_min (set.image_subset _ $ subset_convex_hull s)\n     ((convex_convex_hull s).is_linear_image hf) }\nend\n\nlemma linear_map.image_convex_hull (f : E →ₗ[ℝ] F) :\n  f '' (convex_hull s) = convex_hull (f '' s) :=\nf.is_linear.image_convex_hull\n\nlemma finset.center_mass_mem_convex_hull (t : finset ι) {w : ι → ℝ} (hw₀ : ∀ i ∈ t, 0 ≤ w i)\n  (hws : 0 < ∑ i in t, w i) {z : ι → E} (hz : ∀ i ∈ t, z i ∈ s) :\n  t.center_mass w z ∈ convex_hull s :=\n(convex_convex_hull s).center_mass_mem hw₀ hws (λ i hi, subset_convex_hull s $ hz i hi)\n\n-- TODO : Do we need other versions of the next lemma?\n\n/-- Convex hull of `s` is equal to the set of all centers of masses of `finset`s `t`, `z '' t ⊆ s`.\nThis version allows finsets in any type in any universe. -/\nlemma convex_hull_eq (s : set E) :\n  convex_hull s = {x : E | ∃ (ι : Type u') (t : finset ι) (w : ι → ℝ) (z : ι → E)\n    (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hw₁ : ∑ i in t, w i = 1) (hz : ∀ i ∈ t, z i ∈ 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}, λ _, 1, λ _, x, λ _ _, zero_le_one,\n      finset.sum_singleton, λ _ _, hx],\n    simp only [finset.center_mass, finset.sum_singleton, inv_one, one_smul] },\n  { rintros x y ⟨ι, sx, wx, zx, hwx₀, hwx₁, hzx, rfl⟩ ⟨ι', sy, wy, zy, hwy₀, hwy₁, hzy, rfl⟩\n      a b ha hb hab,\n    rw [finset.center_mass_segment' _ _ _ _ _ _ hwx₁ hwy₁ _ _ hab],\n    refine ⟨_, _, _, _, _, _, _, rfl⟩,\n    { rintros i hi,\n      rw [finset.mem_union, finset.mem_map, finset.mem_map] at hi,\n      rcases hi with ⟨j, hj, rfl⟩|⟨j, hj, rfl⟩;\n        simp only [sum.elim_inl, sum.elim_inr];\n        apply_rules [mul_nonneg, hwx₀, hwy₀] },\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 ⟨j, hj, rfl⟩|⟨j, hj, rfl⟩; apply_rules [hzx, hzy] } },\n  { rintros _ ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩,\n    exact t.center_mass_mem_convex_hull hw₀ (hw₁.symm ▸ zero_lt_one) hz }\nend\n\n/-- Maximum principle for convex functions. If a function `f` is convex on the convex hull of `s`,\nthen `f` can't have a maximum on `convex_hull s` outside of `s`. -/\nlemma convex_on.exists_ge_of_mem_convex_hull {f : E → ℝ} (hf : convex_on (convex_hull s) f)\n  {x} (hx : x ∈ convex_hull s) : ∃ y ∈ s, f x ≤ f y :=\nbegin\n  rw convex_hull_eq at hx,\n  rcases hx with ⟨α, t, w, z, hw₀, hw₁, hz, rfl⟩,\n  rcases hf.exists_ge_of_center_mass hw₀ (hw₁.symm ▸ zero_lt_one)\n    (λ i hi, subset_convex_hull s (hz i hi)) with ⟨i, hit, Hi⟩,\n  exact ⟨z i, hz i hit, Hi⟩\nend\n\nlemma finset.convex_hull_eq (s : finset E) :\n  convex_hull ↑s = {x : E | ∃ (w : E → ℝ) (hw₀ : ∀ y ∈ s, 0 ≤ w y) (hw₁ : ∑ 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 ⟨_, _, _, finset.center_mass_ite_eq _ _ _ hx⟩,\n    { intros, split_ifs, exacts [zero_le_one, le_refl 0] },\n    { rw [finset.sum_ite_eq, if_pos hx] } },\n  { rintros x y ⟨wx, hwx₀, hwx₁, rfl⟩ ⟨wy, hwy₀, hwy₁, rfl⟩\n      a b ha hb hab,\n    rw [finset.center_mass_segment _ _ _ _ hwx₁ hwy₁ _ _ hab],\n    refine ⟨_, _, _, rfl⟩,\n    { rintros i hi,\n      apply_rules [add_nonneg, mul_nonneg, hwx₀, hwy₀], },\n    { simp only [finset.sum_add_distrib, finset.mul_sum.symm, mul_one, *] } },\n  { rintros _ ⟨w, hw₀, hw₁, rfl⟩,\n    exact s.center_mass_mem_convex_hull (λ x hx, hw₀ _  hx)\n      (hw₁.symm ▸ zero_lt_one) (λ x hx, hx) }\nend\n\nlemma set.finite.convex_hull_eq {s : set E} (hs : finite s) :\n  convex_hull s = {x : E | ∃ (w : E → ℝ) (hw₀ : ∀ y ∈ s, 0 ≤ w y)\n    (hw₁ : ∑ 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\nlemma convex_hull_eq_union_convex_hull_finite_subsets (s : set E) :\n  convex_hull s = ⋃ (t : finset E) (w : ↑t ⊆ s), convex_hull ↑t :=\nbegin\n  refine subset.antisymm _ _,\n  { rw [convex_hull_eq.{u}],\n    rintros x ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩,\n    simp only [mem_Union],\n    refine ⟨t.image z, _, _⟩,\n    { rw [finset.coe_image, image_subset_iff],\n      exact hz },\n    { apply t.center_mass_mem_convex_hull hw₀,\n      { simp only [hw₁, zero_lt_one] },\n      { exact λ i hi, finset.mem_coe.2 (finset.mem_image_of_mem _ hi) } } },\n   { exact Union_subset (λ i, Union_subset convex_hull_mono), },\nend\n\nlemma is_linear_map.convex_hull_image {f : E → F} (hf : is_linear_map ℝ f) (s : set E) :\n  convex_hull (f '' s) = f '' convex_hull s :=\nset.subset.antisymm (convex_hull_min (image_subset _ (subset_convex_hull s)) $\n  (convex_convex_hull s).is_linear_image hf)\n  (image_subset_iff.2 $ convex_hull_min\n    (image_subset_iff.1 $ subset_convex_hull _)\n    ((convex_convex_hull _).is_linear_preimage hf))\n\nlemma linear_map.convex_hull_image (f : E →ₗ[ℝ] F) (s : set E) :\n  convex_hull (f '' s) = f '' convex_hull s :=\nf.is_linear.convex_hull_image s\n\nend convex_hull\n\n/-! ### Simplex -/\n\nsection simplex\n\nvariables (ι) [fintype ι] {f : ι → ℝ}\n\n/-- The standard simplex in the space of functions `ι → ℝ` is the set\nof vectors with non-negative coordinates with total sum `1`. -/\ndef std_simplex (ι : Type*) [fintype ι] : set (ι → ℝ) :=\n{f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1}\n\nlemma std_simplex_eq_inter :\n  std_simplex ι = (⋂ x, {f | 0 ≤ f x}) ∩ {f | ∑ x, f x = 1} :=\nby { ext f, simp only [std_simplex, set.mem_inter_eq, set.mem_Inter, set.mem_set_of_eq] }\n\nlemma convex_std_simplex : convex (std_simplex ι) :=\nbegin\n  refine λ f g hf hg a b ha hb hab, ⟨λ x, _, _⟩,\n  { apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] },\n  { erw [finset.sum_add_distrib, ← finset.smul_sum, ← finset.smul_sum, hf.2, hg.2,\n      smul_eq_mul, smul_eq_mul, mul_one, mul_one],\n    exact hab }\nend\n\nvariable {ι}\n\nlemma ite_eq_mem_std_simplex (i : ι) : (λ j, ite (i = j) (1:ℝ) 0) ∈ std_simplex ι :=\n⟨λ j, by simp only; split_ifs; norm_num, by rw [finset.sum_ite_eq, if_pos (finset.mem_univ _)]⟩\n\n/-- `std_simplex ι` is the convex hull of the canonical basis in `ι → ℝ`. -/\nlemma convex_hull_basis_eq_std_simplex :\n  convex_hull (range $ λ(i j:ι), if i = j then (1:ℝ) else 0) = std_simplex ι :=\nbegin\n  refine subset.antisymm (convex_hull_min _ (convex_std_simplex ι)) _,\n  { rintros _ ⟨i, rfl⟩,\n    exact ite_eq_mem_std_simplex i },\n  { rintros w ⟨hw₀, hw₁⟩,\n    rw [pi_eq_sum_univ w, ← finset.univ.center_mass_eq_of_sum_1 _ hw₁],\n    exact finset.univ.center_mass_mem_convex_hull (λ i hi, hw₀ i)\n      (hw₁.symm ▸ zero_lt_one) (λ i hi, mem_range_self i) }\nend\n\nvariable {ι}\n\n/-- The convex hull of a finite set is the image of the standard simplex in `s → ℝ`\nunder the linear map sending each function `w` to `∑ x in s, w x • 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 → ℝ) →ₗ[ℝ] ℝ` 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 s = by haveI := hs.fintype; exact\n    (⇑(∑ x : s, (@linear_map.proj ℝ s _ (λ i, ℝ) _ _ x).smul_right x.1)) '' (std_simplex s) :=\nbegin\n  rw [← convex_hull_basis_eq_std_simplex, ← linear_map.convex_hull_image, ← set.range_comp, (∘)],\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 ∈ std_simplex ι` belong to `[0, 1]`. -/\nlemma mem_Icc_of_mem_std_simplex (hf : f ∈ std_simplex ι) (x) :\n  f x ∈ I :=\n⟨hf.1 x, hf.2 ▸ finset.single_le_sum (λ y hy, hf.1 y) (finset.mem_univ x)⟩\n\nend simplex\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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7522688784841106}}
{"text": "-- Imagen_de_la_union.lean\n-- Imagen de la unión.\n-- José A. Alonso Jiménez\n-- Sevilla, 4 de mayo de 2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, la imagen de un conjunto s por una función f se representa\n-- por `f '' s`; es decir,\n--    f '' s = {y | ∃ x, x ∈ s ∧ f x = y}\n--\n-- Demostrar que\n--    f '' (s ∪ t) = f '' s ∪ f '' t\n-- ----------------------------------------------------------------------\n\nimport data.set.basic\nimport tactic\n\nopen set\n\nvariables {α : Type*} {β : Type*}\nvariable  f : α → β\nvariables s t : set α\n\n-- 1ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ 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 ← 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ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro ⟨x, xst, rfl⟩,\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 ⟨x, xs, rfl⟩,\n      apply mem_image_of_mem,\n      left,\n      exact xs, },\n    { rcases yft with ⟨x, xt, rfl⟩,\n      apply mem_image_of_mem,\n      right,\n      exact xt, }},\nend\n\n-- 3ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro ⟨x, xst, rfl⟩,\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 ⟨x, xs, rfl⟩,\n      use [x, or.inl xs], },\n    { rcases yft with ⟨x, xt, rfl⟩,\n      use [x, or.inr xt], }},\nend\n\n-- 4ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y,\n  split,\n  { rintro ⟨x, xs | xt, rfl⟩,\n    { left,\n      use [x, xs], },\n    { right,\n      use [x, xt], }},\n  { rintros (⟨x, xs, rfl⟩ | ⟨x, xt, rfl⟩),\n    { use [x, or.inl xs], },\n    { use [x, or.inr xt], }},\nend\n\n-- 5ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y,\n  split,\n  { rintros ⟨x, xs | xt, rfl⟩ ; finish, },\n  { rintros (⟨x, xs, rfl⟩ | ⟨x, xt, rfl⟩) ; finish, },\nend\n\n-- 6ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y,\n  split,\n  { finish, },\n  { finish, },\nend\n\n-- 7ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nbegin\n  ext y,\n  rw iff_def,\n  finish,\nend\n\n-- 8ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nby finish [ext_iff, iff_def]\n\n-- 9ª demostración\n-- ===============\n\nexample : f '' (s ∪ t) = f '' s ∪ f '' t :=\nimage_union f s t\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.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7522688706362104}}
{"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 ⧸ I) := ⟨submodule.quotient.mk 1⟩\n\ninstance has_mul (I : ideal R) : has_mul (R ⧸ I) :=\n⟨λ a b, quotient.lift_on₂' a b (λ a b, submodule.quotient.mk (a * b)) $\n λ a₁ a₂ b₁ b₂ h₁ h₂, quot.sound $ begin\n  rw submodule.quotient_rel_r_def at h₁ h₂ ⊢,\n  have F := I.add_mem (I.mul_mem_left a₂ h₁) (I.mul_mem_right b₁ h₂),\n  have : a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁,\n  { rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁] },\n  rw ← this at F,\n  change _ ∈ _, convert F,\nend⟩\n\ninstance comm_ring (I : ideal R) : comm_ring (R ⧸ I) :=\n{ mul := (*),\n  one := 1,\n  nat_cast := λ n, submodule.quotient.mk n,\n  nat_cast_zero := by simp [nat.cast],\n  nat_cast_succ := by simp [nat.cast]; refl,\n  mul_assoc := λ a b c, quotient.induction_on₃' a b c $\n    λ a b c, congr_arg submodule.quotient.mk (mul_assoc a b c),\n  mul_comm := λ a b, quotient.induction_on₂' a b $\n    λ a b, congr_arg submodule.quotient.mk (mul_comm a b),\n  one_mul := λ a, quotient.induction_on' a $\n    λ a, congr_arg submodule.quotient.mk (one_mul a),\n  mul_one := λ a, quotient.induction_on' a $\n    λ a, congr_arg submodule.quotient.mk (mul_one a),\n  left_distrib := λ a b c, quotient.induction_on₃' a b c $\n    λ a b c, congr_arg submodule.quotient.mk (left_distrib a b c),\n  right_distrib := λ a b c, quotient.induction_on₃' a b c $\n    λ 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 →+* (R ⧸ I) :=\n⟨λ a, submodule.quotient.mk a, rfl, λ _ _, rfl, rfl, λ _ _, rfl⟩\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] ⦃f g : R ⧸ I →+* S⦄\n  (h : f.comp (mk I) = g.comp (mk I)) : f = g :=\nring_hom.ext $ λ x, quotient.induction_on' x $ (ring_hom.congr_fun h : _)\n\ninstance inhabited : inhabited (R ⧸ I) := ⟨mk I 37⟩\n\nprotected theorem eq : mk I x = mk I y ↔ x - y ∈ I := submodule.quotient.eq I\n\n@[simp] theorem mk_eq_mk (x : R) : (submodule.quotient.mk x : R ⧸ I) = mk I x := rfl\n\nlemma eq_zero_iff_mem {I : ideal R} : mk I a = 0 ↔ a ∈ I :=\nsubmodule.quotient.mk_eq_zero _\n\ntheorem zero_eq_one_iff {I : ideal R} : (0 : R ⧸ I) = 1 ↔ I = ⊤ :=\neq_comm.trans $ eq_zero_iff_mem.trans (eq_top_iff_one _).symm\n\ntheorem zero_ne_one_iff {I : ideal R} : (0 : R ⧸ I) ≠ 1 ↔ I ≠ ⊤ :=\nnot_congr zero_eq_one_iff\n\nprotected theorem nontrivial {I : ideal R} (hI : I ≠ ⊤) : nontrivial (R ⧸ I) :=\n⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩\n\nlemma subsingleton_iff {I : ideal R} : subsingleton (R ⧸ I) ↔ I = ⊤ :=\nby rw [eq_top_iff_one, ← subsingleton_iff_zero_eq_one, eq_comm,\n       ← I^.quotient.mk^.map_one, quotient.eq_zero_iff_mem]\n\ninstance : unique (R ⧸ (⊤ : ideal R)) :=\n⟨⟨0⟩, by rintro ⟨x⟩; exact quotient.eq_zero_iff_mem.mpr submodule.mem_top⟩\n\nlemma mk_surjective : function.surjective (mk I) :=\nλ y, quotient.induction_on' y (λ x, exists.intro x rfl)\n\n/-- If `I` is an ideal of a commutative ring `R`, if `q : R → R/I` is the quotient map, and if\n`s ⊆ R` is a subset, then `q⁻¹(q(s)) = ⋃ᵢ(i + s)`, the union running over all `i ∈ I`. -/\nlemma quotient_ring_saturate (I : ideal R) (s : set R) :\n  mk I ⁻¹' (mk I '' s) = (⋃ x : I, (λ y, x.1 + y) '' s) :=\nbegin\n  ext x,\n  simp only [mem_preimage, mem_image, mem_Union, ideal.quotient.eq],\n  exact ⟨λ ⟨a, a_in, h⟩, ⟨⟨_, I.neg_mem h⟩, a, a_in, by simp⟩,\n         λ ⟨⟨i, hi⟩, a, ha, eq⟩,\n           ⟨a, ha, by rw [← eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi⟩⟩\nend\n\ninstance is_domain (I : ideal R) [hI : I.is_prime] : is_domain (R ⧸ I) :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b,\n    quotient.induction_on₂' a b $ λ a b hab,\n      (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim\n        (or.inl ∘ eq_zero_iff_mem.2)\n        (or.inr ∘ eq_zero_iff_mem.2),\n  .. quotient.nontrivial hI.1 }\n\nlemma is_domain_iff_prime (I : ideal R) : is_domain (R ⧸ I) ↔ I.is_prime :=\n⟨ λ ⟨h1, h2⟩, ⟨zero_ne_one_iff.1 $ @zero_ne_one _ _ ⟨h2⟩, λ x y h,\n    by { simp only [←eq_zero_iff_mem, (mk I).map_mul] at ⊢ h, exact h1 h}⟩,\n  λ h, by { resetI, apply_instance }⟩\n\nlemma exists_inv {I : ideal R} [hI : I.is_maximal] :\n  ∀ {a : (R ⧸ I)}, a ≠ 0 → ∃ b : (R ⧸ I), a * b = 1 :=\nbegin\n  rintro ⟨a⟩ h,\n  rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with ⟨b, c, hc, abc⟩,\n  rw [mul_comm] at abc,\n  refine ⟨mk _ b, quot.sound _⟩, --quot.sound hb\n  rw ← eq_sub_iff_add_eq' at abc,\n  rw [abc, ← 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 ⧸ I) :=\n{ inv := λ a, if ha : a = 0 then 0 else classical.some (exists_inv ha),\n  mul_inv_cancel := λ a (ha : a ≠ 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 ⧸ I)) : I.is_maximal :=\nbegin\n  apply ideal.is_maximal_iff.2,\n  split,\n  { intro h,\n    rcases hqf.exists_pair_ne with ⟨⟨x⟩, ⟨y⟩, hxy⟩,\n    exact hxy (ideal.quotient.eq.2 (mul_one (x - y) ▸ 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 ⟨⟨y⟩, hy⟩,\n    rw [← zero_add (1 : R), ← 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 ↔ is_field (R ⧸ I) :=\n⟨λ h, by { letI := @quotient.field _ _ I h, exact field.to_is_field _ }, maximal_of_is_field _⟩\n\nvariable [comm_ring S]\n\n/-- Given a ring homomorphism `f : R →+* S` sending all elements of an ideal to zero,\nlift it to the quotient by this ideal. -/\ndef lift (I : ideal R) (f : R →+* S) (H : ∀ (a : R), a ∈ I → f a = 0) :\n  R ⧸ I →+* S :=\n{ map_one' := f.map_one,\n  map_zero' := f.map_zero,\n  map_add' := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ f.map_add,\n  map_mul' := λ a₁ a₂, quotient.induction_on₂' a₁ a₂ 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 →+* S) (H : ∀ (a : R), a ∈ I → 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 ≤ T) : R ⧸ S →+* R ⧸ T :=\nideal.quotient.lift S (T^.quotient.mk) (λ x hx, eq_zero_iff_mem.2 (H hx))\n\n@[simp] lemma factor_mk (S T : ideal R) (H : S ≤ 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 ≤ 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 ⧸ I) ≃+* R ⧸ J :=\n{ map_mul' := by { rintro ⟨x⟩ ⟨y⟩, 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 (ι : Type v)\n\n/-- `R^n/I^n` is a `R/I`-module. -/\ninstance module_pi : module (R ⧸ I) ((ι → R) ⧸ I.pi ι) :=\n{ smul := λ c m, quotient.lift_on₂' c m (λ r m, submodule.quotient.mk $ r • m) begin\n    intros c₁ m₁ c₂ m₂ 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 ⟨a⟩,\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 ⟨a⟩ ⟨b⟩ ⟨c⟩,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    simp only [(•)],\n    congr' with i, exact mul_assoc a b (c i),\n  end,\n  smul_add := begin\n    rintro ⟨a⟩ ⟨b⟩ ⟨c⟩,\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 ⟨a⟩,\n    change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,\n    congr' with i, exact mul_zero a,\n  end,\n  add_smul := begin\n    rintro ⟨a⟩ ⟨b⟩ ⟨c⟩,\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 ⟨a⟩,\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 : ((ι → R) ⧸ I.pi ι) ≃ₗ[(R ⧸ I)] (ι → (R ⧸ I)) :=\n{ to_fun := λ x, quotient.lift_on' x (λ f i, ideal.quotient.mk I (f i)) $\n    λ a b hab, funext (λ i, (submodule.quotient.eq' _).2 (hab i)),\n  map_add' := by { rintros ⟨_⟩ ⟨_⟩, refl },\n  map_smul' := by { rintros ⟨_⟩ ⟨_⟩, refl },\n  inv_fun := λ x, ideal.quotient.mk (I.pi ι) $ λ i, quotient.out' (x i),\n  left_inv :=\n  begin\n    rintro ⟨x⟩,\n    exact ideal.quotient.eq.2 (λ i, ideal.quotient.eq.1 (quotient.out_eq' _))\n  end,\n  right_inv :=\n  begin\n    intro x,\n    ext i,\n    obtain ⟨r, hr⟩ := @quot.exists_rep _ _ (x i),\n    simp_rw ←hr,\n    convert quotient.out_eq' _\n  end }\n\n/-- If `f : R^n → R^m` is an `R`-linear map and `I ⊆ R` is an ideal, then the image of `I^n` is\n    contained in `I^m`. -/\nlemma map_pi {ι} [fintype ι] {ι' : Type w} (x : ι → R) (hi : ∀ i, x i ∈ I)\n  (f : (ι → R) →ₗ[R] (ι' → R)) (i : ι') : f x i ∈ I :=\nbegin\n  classical,\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 (λ j hj, I.mul_mem_right _ (hi j))\nend\n\nend pi\n\nsection chinese_remainder\nvariables {ι : Type v}\n\ntheorem exists_sub_one_mem_and_mem (s : finset ι) {f : ι → ideal R}\n  (hf : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → f i ⊔ f j = ⊤) (i : ι) (his : i ∈ s) :\n  ∃ r : R, r - 1 ∈ f i ∧ ∀ j ∈ s, j ≠ i → r ∈ f j :=\nbegin\n  have : ∀ j ∈ s, j ≠ i → ∃ r : R, ∃ H : r - 1 ∈ f i, r ∈ 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 ⟨r, hri, s, hsj, hrs⟩, refine ⟨1 - r, _, _⟩,\n    { rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },\n    { rw [← hrs, add_sub_cancel'], exact hsj } },\n  classical,\n  have : ∃ g : ι → R, (∀ j, g j - 1 ∈ f i) ∧ ∀ j ∈ s, j ≠ i → g j ∈ f j,\n  { choose g hg1 hg2,\n    refine ⟨λ j, if H : j ∈ s ∧ j ≠ i then g j H.1 H.2 else 1, λ j, _, λ j, _⟩,\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 ⟨hjs, hji⟩ } },\n  rcases this with ⟨g, hgi, hgj⟩, use (∏ x in s.erase i, g x), split,\n  { rw [← quotient.eq, ring_hom.map_one, ring_hom.map_prod],\n    apply finset.prod_eq_one, intros, rw [← ring_hom.map_one, quotient.eq], apply hgi },\n  intros j hjs hji, rw [← 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 ι] {f : ι → ideal R}\n  (hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) (g : ι → R) :\n  ∃ r : R, ∀ i, r - g i ∈ f i :=\nbegin\n  have : ∃ φ : ι → R, (∀ i, φ i - 1 ∈ f i) ∧ (∀ i j, i ≠ j → φ i ∈ f j),\n  { have := exists_sub_one_mem_and_mem (finset.univ : finset ι) (λ i _ j _ hij, hf i j hij),\n    choose φ hφ,\n    existsi λ i, φ i (finset.mem_univ i),\n    exact ⟨λ i, (hφ i _).1, λ i j hij, (hφ i _).2 j (finset.mem_univ j) hij.symm⟩ },\n  rcases this with ⟨φ, hφ1, hφ2⟩,\n  use ∑ i, g i * φ i,\n  intros i,\n  rw [← 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φ2 j i hji) },\n  { intros hi, exact (hi $ finset.mem_univ i).elim },\n  specialize hφ1 i, rw [← quotient.eq, ring_hom.map_one] at hφ1,\n  rw [ring_hom.map_mul, hφ1, mul_one]\nend\n\n/-- The homomorphism from `R/(⋂ i, f i)` to `∏ 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 : ι → ideal R) :\n  R ⧸ (⨅ i, f i) →+* Π i, R ⧸ f i :=\nquotient.lift (⨅ i, f i)\n  (pi.ring_hom (λ i : ι, (quotient.mk (f i) : _))) $\n  λ 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 ι] {f : ι → ideal R}\n  (hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :\n  function.bijective (quotient_inf_to_pi_quotient f) :=\n⟨λ x y, quotient.induction_on₂' x y $ λ r s hrs, quotient.eq.2 $\n  (submodule.mem_infi _).2 $ λ i, quotient.eq.1 $\n  show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,\nλ g, let ⟨r, hr⟩ := exists_sub_mem hf (λ i, quotient.out' (g i)) in\n⟨quotient.mk _ r, funext $ λ i, quotient.out_eq' (g i) ▸ quotient.eq.2 (hr i)⟩⟩\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 ι] (f : ι → ideal R)\n  (hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :\n  R ⧸ (⨅ i, f i) ≃+* Π i, R ⧸ 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": "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/quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7522688666961588}}
{"text": "/-\nCopyright (c) 2021 Vladimir Goryachev. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yaël 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 dc6c365e751e34d100e80fe6e314c3c3e0fd2988\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\nimport Mathlib.Tactic.Ring\nimport Mathlib.Tactic.WLOG\n\n/-!\n# Counting on ℕ\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 : ℕ → Prop)\n\nsection Count\n\nvariable [DecidablePred p]\n\n/-- Count the number of naturals `k < n` satisfying `p k`. -/\ndef count (n : ℕ) : ℕ :=\n  (List.range n).countp p\n#align nat.count Nat.count\n\n@[simp]\ntheorem count_zero : count p 0 = 0 := by\n  rw [count, List.range_zero, List.countp, List.countp.go]\n#align nat.count_zero Nat.count_zero\n\n/-- A fintype instance for the set relevant to `Nat.count`. Locally an instance in locale `count` -/\ndef CountSet.fintype (n : ℕ) : Fintype { i // i < n ∧ p i } := by\n  apply Fintype.ofFinset ((Finset.range n).filter p)\n  intro x\n  rw [mem_filter, mem_range]\n  rfl\n#align nat.count_set.fintype Nat.CountSet.fintype\n\nscoped[Count] attribute [instance] Nat.CountSet.fintype\n\nopen Count\n\ntheorem count_eq_card_filter_range (n : ℕ) : count p n = ((range n).filter p).card := 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/-- `count p n` can be expressed as the cardinality of `{k // k < n ∧ p k}`. -/\ntheorem count_eq_card_fintype (n : ℕ) : count p n = Fintype.card { k : ℕ // k < n ∧ p k } := by\n  rw [count_eq_card_filter_range, ← Fintype.card_ofFinset, ← CountSet.fintype]\n  rfl\n#align nat.count_eq_card_fintype Nat.count_eq_card_fintype\n\ntheorem count_succ (n : ℕ) : count p (n + 1) = count p n + if p n then 1 else 0 := by\n  split_ifs with h <;> simp [count, List.range_succ, h]\n#align nat.count_succ Nat.count_succ\n\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\ntheorem count_add (a b : ℕ) : count p (a + b) = count p a + count (fun k ↦ p (a + k)) b := by\n  have : Disjoint ((range a).filter p) (((range b).map <| addLeftEmbedding a).filter p) := by\n    apply disjoint_filter_filter\n    rw [Finset.disjoint_left]\n    simp_rw [mem_map, mem_range, addLeftEmbedding_apply]\n    rintro x hx ⟨c, _, rfl⟩\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\ntheorem count_add' (a b : ℕ) : count p (a + b) = count (fun k ↦ p (k + b)) a + count p b := by\n  rw [add_comm, count_add, add_comm]\n  simp_rw [add_comm b]\n#align nat.count_add' Nat.count_add'\n\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\ntheorem count_succ' (n : ℕ) :\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\nvariable {p}\n\n@[simp]\ntheorem count_lt_count_succ_iff {n : ℕ} : count p n < count p (n + 1) ↔ 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\ntheorem count_succ_eq_succ_count_iff {n : ℕ} : count p (n + 1) = count p n + 1 ↔ 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\ntheorem count_succ_eq_count_iff {n : ℕ} : count p (n + 1) = count p n ↔ ¬p 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\nalias count_succ_eq_succ_count_iff ↔ _ 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 ↔ _ count_succ_eq_count\n#align nat.count_succ_eq_count Nat.count_succ_eq_count\n\ntheorem count_le_cardinal (n : ℕ) : (count p n : Cardinal) ≤ Cardinal.mk { k | p k } := by\n  rw [count_eq_card_fintype, ← 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\ntheorem lt_of_count_lt_count {a b : ℕ} (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\ntheorem count_strict_mono {m n : ℕ} (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\ntheorem count_injective {m n : ℕ} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n := by\n  by_contra' h : m ≠ 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\n#align nat.count_injective Nat.count_injective\n\ntheorem count_le_card (hp : (setOf p).Finite) (n : ℕ) : count p n ≤ hp.toFinset.card := by\n  rw [count_eq_card_filter_range]\n  exact Finset.card_mono fun x hx ↦ hp.mem_toFinset.2 (mem_filter.1 hx).2\n#align nat.count_le_card Nat.count_le_card\n\n\n\nvariable {q : ℕ → Prop}\n\nvariable [DecidablePred q]\n\ntheorem count_mono_left {n : ℕ} (hpq : ∀ k, p k → q k) : count p n ≤ count q 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\nend Count\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/Count.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811307, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7522308593037292}}
{"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 → Y` and `g : Y → Z`\n-- be functions\n\nvariables {X Y Z : Type} {f : X → Y} {g : Y → 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 ↔ ∀ a b : X, f a = f b → 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 → 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 → X) :=\nbegin\n  sorry,\nend\n\n-- function composition g ∘ f is satisfies (g ∘ f) (x) = g(f(x)). This\n-- is true by definition. Let's check this\n\nlemma comp_def : (g ∘ 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 ∘ 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  sorry,\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 ↔ ∀ y : Y, ∃ 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 → X) :=\nbegin\n  -- you can start with `rw surjective_def` if you like.\n  sorry,\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 ∘ f) :=\nbegin\n  sorry,\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 ↔ injective f ∧ 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 → X) :=\nbegin\n  sorry,\nend\n\n/-- A composite of bijective functions is bijective. -/\nlemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g ∘ f) :=\nbegin\n  sorry,\nend\n\nend xena\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_C_functions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.826711787666479, "lm_q1q2_score": 0.7522308495916935}}
{"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 → a :=\nsorry\n\nlemma K (a b : Prop) :\n  a → b → b :=\nsorry\n\nlemma C (a b c : Prop) :\n  (a → b → c) → b → a → c :=\nsorry\n\nlemma proj_1st (a : Prop) :\n  a → a → a :=\nsorry\n\n/- Please give a different answer than for `proj_1st`. -/\n\nlemma proj_2nd (a : Prop) :\n  a → a → a :=\nsorry\n\nlemma some_nonsense (a b c : Prop) :\n  (a → b → c) → a → (a → c) → b → c :=\nsorry\n\n/- 1.2. Supply a structured proof of the contraposition rule. -/\n\nlemma contrapositive (a b : Prop) :\n  (a → b) → ¬ b → ¬ a :=\nsorry\n\n/- 1.3. Supply a structured proof of the distributivity of `∀` over `∧`. -/\n\nlemma forall_and {α : Type} (p q : α → Prop) :\n  (∀x, p x ∧ q x) ↔ (∀x, p x) ∧ (∀x, q x) :=\nsorry\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 {α : Type} (r s : α → α → Prop) :\n  (∀x, r x x ∧ s x x) ↔ (∀x, r x x) ∧ (∀x, s x x) :=\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 : ℕ) :\n  (a + b) * (a + b) = a * a + 2 * a * b + b * b :=\nsorry\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₂ (a b : ℕ) :\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₃ (a b : ℕ) :\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 `∀` is inconsistent, using a structured proof. -/\n\naxiom forall.one_point_wrong {α : Type} {t : α} {p : α → Prop} :\n  (∀x : α, x = t ∧ p x) ↔ 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 `∃` is inconsistent, using a tactical or structured proof. -/\n\naxiom exists.one_point_wrong {α : Type} {t : α} {p : α → Prop} :\n  (∃x : α, x = t → p x) ↔ p t\n\nlemma proof_of_false₂ :\n  false :=\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_exercise_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069962657176, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7522308472626961}}
{"text": "import data.real.basic\n\n/-\nCorrectness 90/90\nStyle: 10/10\nGood work Priya!\n-/\n\n/-\nFIRST EXERCISE: Strict monotonicity\n\nSection 3.1 of MIL discusses the `monotone` predicate. There is also a strict\nversion. Prove the theorems below, *and* come up with suitable names\n(in other words, replace `example` with `theorem foo`.)\n\n(Don't use any library theorems about `strict_mono` or `monotone`! You should\nonly use basic properties of orderings.)\n-/\n\n#print monotone. \n#print strict_mono. \n\nnamespace strict_mono_exercise\n\nvariables (f : ℝ → ℝ) (g : ℝ → ℝ)\n\ntheorem add_strict_mono (hf : strict_mono f) (hg : strict_mono g) : strict_mono (f + g) :=\nbegin\n  intros a b aleb,\n  apply add_lt_add,\n  exact hf aleb,\n  exact hg aleb,\nend\n\n-- You'll have to guess at the name of a theorem for this one.\ntheorem mul_pos_strict_mono (c : ℝ) (hf : strict_mono f) (hc : 0 < c) :\n  strict_mono (λ x, c * f x) :=\nbegin\n  intros a b aleb,\n  rw mul_lt_mul_left,\n  apply hf,\n  apply aleb,\n  exact hc,\nend\n\n-- This is trickier than you might think. Use `by_cases h : a = b` to split\n-- on cases whether `a = b`. You can also use `lt_of_le_of_ne`.\n\ntheorem strict_mono_to_mono (hf : strict_mono f) : monotone f :=\nbegin\n  intros a b aleb,\n  by_cases h : a = b,\n  {rw h},\n  {apply le_of_lt,\n  apply hf,\n  apply lt_of_le_of_ne,\n  exact aleb,\n  exact h,},\nend\n\n/-\nThe following (trivial) example shows how to use trichotomy. You do not need\nto fully understand the pattern now; you can take it as a black box.\n-/\n\ntheorem example_for_trichotomy (x1 x2 : ℝ) : x1 ≤ x2 ∨ x2 < x1 :=\nbegin\n  rcases trichotomous_of (<) x1 x2 with h | h | h,\n  { -- In this case, we have `h : x1 < x2`.\n    left,\n    apply le_of_lt h },\n  { -- In this case, we have `h : x1 = x2`.\n    left,\n    rw h },\n  -- In this case, we have `h : x2 < x1`\n  right,\n  exact h,\nend\n\nopen function\n\n/-\nHere is an example that shows that `x ↦ x + 1` is injective.\n-/\n\nexample : injective (λ x, x + 1) :=\nbegin\n  intros x1 x2 h,\n  dsimp at h,  -- this makes `h` more readable\n  exact add_right_cancel h,\nend\n\n/-\nShow that every strictly monotone function is injective.\n-/\n\ntheorem injective_of_strict_mono (hf : strict_mono f) : injective f :=\nbegin\n  intros x y,\n  rcases trichotomous_of (<) x y with h | h | h,\n  { -- In this case, we have `h : x < y`.\n    contrapose,\n    intro,\n    have fx_lt_fy : f x < f y,\n    {\n      apply hf h,\n    },\n    apply ne_of_lt fx_lt_fy, \n  },\n  { -- In this case, we have `h : x = y`.\n    intro,\n    apply h,\n  },\n  {-- In this case, we have `h : y < x`\n    contrapose,\n    intro,\n    have fx_gt_fy : f x > f y,\n    {\n      apply hf h,\n    },\n    apply ne_of_gt fx_gt_fy, \n  },\nend\n\nend strict_mono_exercise\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n/-\nSECOND EXERCISE: Galois connections\n\nGiven `α` with a partial order, a *closure operator* `cl : α → α` has the\nfollowing properties:\n\n- `cl` is monotone\n- `cl` is increasing, in the sense that for every `a : α`, `a ≤ cl a`\n- `cl` is idempotent, in the sense that for every `a : α`, `cl (cl a) = cl a`.\n\nGiven `α` and `β` with partial orders, a *Galois connection* is a pair of\nmonotone functions `f : α → β` and `g : β → α` satisfying the following:\n\n  For every `a` and `b`, `f a ≤ b` if and only if `a ≤ g b`.\n\nYou can read more about these here:\n\n  https://en.wikipedia.org/wiki/Closure_operator\n  https://en.wikipedia.org/wiki/Galois_connection\n\nThe exercises below ask you to show that if `f` and `g` form a Galois\nconnection, then `g ∘ f` is a closure operator, and `f ∘ g` is a closure\noperator on the reverse order.\n-/\n\nnamespace galois_connection_exercise\n\nvariables {α β : Type*} [partial_order α] [partial_order β]\nvariable  {f : α → β}\nvariable  {g : β → α}\nvariable  mono_f : monotone f\nvariable  mono_g : monotone g\nvariable  adj1 : ∀ a b, f a ≤ b → a ≤ g b\nvariable  adj2 : ∀ a b, a ≤ g b → f a ≤ b\n\nsection\n-- you can use these:\ninclude mono_f mono_g\n\ntheorem mono_gf : monotone (g ∘ f) :=\nbegin\n  intros x y xley,\n  apply mono_g,\n  apply mono_f xley,\nend\n\ntheorem mono_fg : monotone (f ∘ g) :=\nbegin\n  intros x y xley,\n  apply mono_f,\n  apply mono_g xley,\nend\n\nend\n\nsection\ninclude adj1\n\ntheorem increasing_gf : ∀ a, a ≤ g (f a) :=\nbegin\n  intro a,\n  apply adj1,\n  refl,\nend\nend\n\nsection\ninclude adj2\n\ntheorem decreasing_fg : ∀ b, f (g b) ≤ b :=\nbegin\n  intro b,\n  apply adj2,\n  refl,\nend\nend\n\ninclude mono_f mono_g adj1 adj2\n\n/-\nUnfortunately, for the theorems you just proved, you have to give the\nhypotheses as arguments.\n-/\n\n#check mono_fg mono_f mono_g\n#check mono_gf mono_f mono_g\n#check increasing_gf adj1\n#check decreasing_fg adj2\n\ntheorem idempotent_gf : ∀ a, g (f (g (f a))) = g (f a) :=\nbegin\n  intro a,\n  apply le_antisymm,\n  {\n    apply adj1,\n    apply le_trans,\n    apply decreasing_fg adj2,\n    apply decreasing_fg adj2,\n  },\n  {\n    apply increasing_gf adj1,\n  },\nend\n\ntheorem idempotent_fg : ∀ b, f (g (f (g b))) = f (g b) :=\nbegin\n  intro b,\n  apply le_antisymm,\n  {\n    apply decreasing_fg adj2,\n  },\n  {\n    apply adj2,\n    apply le_trans,\n    apply increasing_gf adj1,\n    apply increasing_gf adj1,\n  },\nend\n\nend galois_connection_exercise\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/-\nTHIRD EXERCISE: convergence to infinity\n\nBelow, `to_infinity f` expresses that `f x` approaches infinity as\n`x` approaches infinity.\n\nThe properties below are analogous to properties proved in Sections 3.2\nand 3.6 in Mathematics in Lean. They involve the universal and existential\nquantifiers (both no other logical connectives).\n-/\n\ndef to_infinity (f : ℝ → ℝ) := ∀ b, ∃ x₀, ∀ x, x₀ ≤ x → b < f x\n\n-- hint: you can use `linarith` at the end\nexample (f : ℝ → ℝ) (r : ℝ) (hf : to_infinity f) :\n  to_infinity (λ x, f x  + r) :=\nbegin\n  intro,\n  unfold to_infinity,\n  cases hf(b-r) with x₀ h,\n  use x₀,\n  intros x x₀_le_x,\n  specialize h x x₀_le_x,\n  linarith,\nend\n\n-- hint: `div_lt_iff'` is useful here\nexample (f : ℝ → ℝ) (r : ℝ) (hr : 0 < r) (hf : to_infinity f) :\n  to_infinity (λ x, r * f x) :=\nbegin\n  intro b,\n  unfold to_infinity,\n  cases hf (b/r) with x₀ h,\n  use x₀,\n  intros x hx₀_le_x,\n  specialize h x hx₀_le_x,\n  have h: b < f x * r,\n  {\n    rw ← div_lt_iff hr,\n    apply h,  \n  },\n  linarith,\nend\n\n-- hint: you can use `le_max_left` and `le_max_right`\nexample (f g : ℝ → ℝ) (hf : to_infinity f) (hg : to_infinity g) :\n  to_infinity (f + g) :=\nbegin\n  unfold to_infinity,\n  intro b,\n  dsimp,\n  cases hf (b/2) with fx₀ hf2,\n  cases hg (b/2) with gx₀ hg2,\n  use max fx₀ gx₀,\n  intros x max_fx₀_gx₀_le_x,\n  have fx₀_le_x : fx₀ ≤ x,\n  {\n    apply le_trans,\n    apply le_max_left,\n    swap,\n    exact max_fx₀_gx₀_le_x,\n  },\n  have gx₀_le_x : gx₀ ≤ x,\n  {\n    apply le_trans,\n    apply le_max_right,\n    swap,\n    exact max_fx₀_gx₀_le_x,\n  },\n  specialize hf2 x fx₀_le_x,\n  specialize hg2 x gx₀_le_x,\n  linarith,\nend\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/assignment3/assignment3.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900945711678, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7522216130683947}}
{"text": "/-\nHow to learn LEAN by reading code:\n\nPlace your cursor before and after each line within the begin-end block.\n\nThe goal is prove the goal (after :) from whatever we have in the arguments of the function/theorem/lemma/example\n\n-/\n\ntheorem my_first_theorem : \n    ∀ p, p → p :=\nbegin\n    intro p,\n    intro proof_of_p,\n    exact proof_of_p,\nend\n\n/-\nA theorem is made of a name, arguments, goal and proof. \n\nThe first example has no arguments and has type \"∀ p, p → p\" and this is what we want to prove.\n\nIn each line we make progress either on the context (what comes before the turnstile ⊢) or the goal (after it).\nEach line has a tactic and arguments. (It is similar to haskell's do-notation for monads, if you known what it is.)\n\nThe first tactic here is intro, which pushes the left-most ∀ or → into the context with the given name and out of the goal.\nAnother name for this tactic is \"assume\", which might be more familiar for those with a math background.\n\nThe second tactic is exact, which provides exactly a proof of the goal (similarly to monad's return).\n\n-/\n\n\ntheorem my_first_theorem_2 : \n    ∀ p, p → p :=\nbegin\n    intro p,\n    exact id,\nend\n\n/-\nThis second version of the same theorem uses an existing lemma for this purpose.\n\nThis theorem was defined in the first \"language\" of lean: the implementation language. \nTheorems are implemented as functions and they are exactly the same thing. If you have a \nmoment, please see Phil Wadler's talk on Propositions as Types (https://www.youtube.com/watch?v=IOiZatlZtGU&t=11s).\n\ndef id {α : Sort u} (a : α) : α := a\n-/\n\n\ntheorem my_first_theorem_3 (p:Prop):\n    p → p :=\nbegin\n    exact id,\nend\n\n/-\nThis third version moves the universial quantifier from the goal to the context directly in the definition (as opposed to using intro).\nThis is akin to haskell's function definition using lambda or using arguments.\n\nf a = a + 1\nf = \\ a -> a + 1\n-/\n\n\n\ntheorem my_first_theorem_4 (p:Prop) (proof_of_p:p):\n    p :=\nbegin\n    exact proof_of_p,\nend\n\n/-\nThis fourth version moves both the universial quantifier and the p into the context in the definition. This is the more popular style.\n-/\n\n\nlemma my_first_theorem_5 (p:Prop):\n    p → p :=\nbegin\n    exact id,\nend\n\n/-\n\nLemmas and Theorems are the same thing for the language. You can choose which one serves your purpose.\n\n-/\n\nexample (p:Prop):\n    p → p :=\nbegin\n    exact id,\nend\n\n/-\n\nExamples are anonymous lemmas or theorems. We use when there is no point in giving it a name.\n\n-/\n\n\ntheorem  my_first_theorem_6 (p:Prop) : p → p := by exact id\n\n/-\n\nThis is the most common style for proofs. I don't like it, so we will always use begin-end blocks.\n\n-/\n\n\ntheorem my_first_theorem_7 : \n    ∀ p:Prop, p → p :=\nbegin\n    intros p proof_of_p,\n    exact proof_of_p,\nend\n\n/-\n\nThis seventh version uses intros p proof_of_p, instead of two intro. You can use this\nshortcut to introduce as many variables into context as you want.\n\n-/\n\n\n\n\n/-\n    Exercice time! Now it's your turn to apply what you did:\n-/\n\ntheorem my_second_theorem : \n    ∀ p q : Prop, p → q → p :=\nbegin\n  sorry, -- now it's your turn to do some proving.\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/01_first.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7521238640264487}}
{"text": "--variable (α : ℕ) (b c d a e x: ℕ)\n\n--variable(hab : a = b) (hcb : c = b) (hcd : c = d)\n\n--example : a = d :=\n\n--Eq.trans (Eq.trans hab (Eq.symm hcb)) hcd\n\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     := Eq.symm h4\n\n\nexample : ∃ x : Nat , x > 0 :=\n  have h : 1 > 0 := Nat.zero_lt_succ 0\n  ⟨1, h⟩ \n\n-- ∀x ∈ ℕ, 0 * x = x * 0 = 0  \n\nexample : ∀ x : Nat, x * 0 = 0 :=  \n  λ(a1 : Nat) =>\n    rfl\n\n-- ∀x ∈ ℕ, 0 * x = 0  \nexample : ∀ x : Nat, 0 * x = 0 :=\n  λ(a1 : Nat) => \n    Nat.recOn a1 (rfl : 0 * 0 = 0) (λ(n : Nat) => \n      λ(h1 : 0 * n = 0) => by\n        calc\n          0 * (n+1) = (0 * n) + 0 := rfl\n          _ = 0 + 0               := by rw[h1]\n          _ = 0                   := rfl\n        )\n\n-- \n\ndef ChrisSum (p : Nat) : Nat :=\n  match p with\n    | 0 => 0\n    | n + 1 => ChrisSum n + (n+1)\n\n-- ChrisSum n = n * (n+1)/2\n\nexample : ∀ x : Nat, ChrisSum x = x * (x+1) / 2 :=\n  λ(a : Nat) =>\n    Nat.recOn a (rfl) (λ(n : Nat) =>\n      λ(h1 : ChrisSum n = n * (n+1) / 2) =>\n        calc\n          ChrisSum (n+1) = ChrisSum n + (n+1)   := rfl\n          _ = (n * (n+1) / 2) + (n+1)           := by rw[h1]\n          _ = (n+1) * (n/2 + 1)                 := by rw[<-Nat.left_distrib]\n    ) ", "meta": {"author": "cmloura", "repo": "LeanPractice2023", "sha": "6819825e67228bfe5e69aa309f8d2bd37ef48ce3", "save_path": "github-repos/lean/cmloura-LeanPractice2023", "path": "github-repos/lean/cmloura-LeanPractice2023/LeanPractice2023-6819825e67228bfe5e69aa309f8d2bd37ef48ce3/mathlogic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7520903381047271}}
{"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_norm\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.Algebra.Order.Field.Power\nimport Mathlib.NumberTheory.Padics.PadicVal\n\n/-!\n# p-adic norm\n\nThis file defines the `p`-adic norm on `ℚ`.\n\nThe `p`-adic valuation on `ℚ` 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 `ℚ`. This norm is a nonarchimedean absolute value.\nIt takes values in {0} ∪ {1/p^k | k ∈ ℤ}.\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êa, *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\n/-- If `q ≠ 0`, the `p`-adic norm of a rational `q` is `p ^ (-padicValRat p q)`.\nIf `q = 0`, the `p`-adic norm of `q` is `0`. -/\ndef padicNorm (p : ℕ) (q : ℚ) : ℚ :=\n  if q = 0 then 0 else (p : ℚ) ^ (-padicValRat p q)\n#align padic_norm padicNorm\n\nnamespace padicNorm\n\nopen padicValRat\n\nvariable {p : ℕ}\n\n/-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/\n@[simp]\nprotected theorem eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :\n    padicNorm p q = (p : ℚ) ^ (-padicValRat p q) := by simp [hq, padicNorm]\n#align padic_norm.eq_zpow_of_nonzero padicNorm.eq_zpow_of_nonzero\n\n/-- The `p`-adic norm is nonnegative. -/\nprotected theorem nonneg (q : ℚ) : 0 ≤ padicNorm p q :=\n  if hq : q = 0 then by simp [hq, padicNorm]\n  else by\n    unfold padicNorm\n    split_ifs\n    apply zpow_nonneg\n    exact_mod_cast Nat.zero_le _\n#align padic_norm.nonneg padicNorm.nonneg\n\n/-- The `p`-adic norm of `0` is `0`. -/\n@[simp]\nprotected theorem zero : padicNorm p 0 = 0 := by simp [padicNorm]\n#align padic_norm.zero padicNorm.zero\n\n/-- The `p`-adic norm of `1` is `1`. -/\n-- @[simp] -- Porting note: simp can prove this\nprotected theorem one : padicNorm p 1 = 1 := by simp [padicNorm]\n#align padic_norm.one padicNorm.one\n\n/-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`.\n\nSee also `padicNorm.padicNorm_p_of_prime` for a version assuming `p` is prime. -/\ntheorem padicNorm_p (hp : 1 < p) : padicNorm p p = (p : ℚ)⁻¹ := by\n  simp [padicNorm, (pos_of_gt hp).ne', padicValNat.self hp]\n#align padic_norm.padic_norm_p padicNorm.padicNorm_p\n\n/-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime.\n\nSee also `padicNorm.padicNorm_p` for a version assuming `1 < p`. -/\n@[simp]\ntheorem padicNorm_p_of_prime [Fact p.Prime] : padicNorm p p = (p : ℚ)⁻¹ :=\n  padicNorm_p <| Nat.Prime.one_lt Fact.out\n#align padic_norm.padic_norm_p_of_prime padicNorm.padicNorm_p_of_prime\n\n/-- The `p`-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/\ntheorem padicNorm_of_prime_of_ne {q : ℕ} [p_prime : Fact p.Prime] [q_prime : Fact q.Prime]\n    (neq : p ≠ q) : padicNorm p q = 1 := by\n  have p : padicValRat p q = 0 := by exact_mod_cast padicValNat_primes neq\n  rw [padicNorm, p]\n  simp [q_prime.1.ne_zero]\n#align padic_norm.padic_norm_of_prime_of_ne padicNorm.padicNorm_of_prime_of_ne\n\n/-- The `p`-adic norm of `p` is less than `1` if `1 < p`.\n\nSee also `padicNorm.padicNorm_p_lt_one_of_prime` for a version assuming `p` is prime. -/\ntheorem padicNorm_p_lt_one (hp : 1 < p) : padicNorm p p < 1 := by\n  rw [padicNorm_p hp, inv_lt_one_iff]\n  exact_mod_cast Or.inr hp\n#align padic_norm.padic_norm_p_lt_one padicNorm.padicNorm_p_lt_one\n\n/-- The `p`-adic norm of `p` is less than `1` if `p` is prime.\n\nSee also `padicNorm.padicNorm_p_lt_one` for a version assuming `1 < p`. -/\ntheorem padicNorm_p_lt_one_of_prime [Fact p.Prime] : padicNorm p p < 1 :=\n  padicNorm_p_lt_one <| Nat.Prime.one_lt Fact.out\n#align padic_norm.padic_norm_p_lt_one_of_prime padicNorm.padicNorm_p_lt_one_of_prime\n\n/-- `padicNorm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/\nprotected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padicNorm p q = (p : ℚ) ^ (-z) :=\n  ⟨padicValRat p q, by simp [padicNorm, hq]⟩\n#align padic_norm.values_discrete padicNorm.values_discrete\n\n/-- `padicNorm p` is symmetric. -/\n@[simp]\nprotected theorem neg (q : ℚ) : padicNorm p (-q) = padicNorm p q :=\n  if hq : q = 0 then by simp [hq] else by simp [padicNorm, hq]\n#align padic_norm.neg padicNorm.neg\n\nvariable [hp : Fact p.Prime]\n\n/-- If `q ≠ 0`, then `padicNorm p q ≠ 0`. -/\nprotected theorem nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q ≠ 0 := by\n  rw [padicNorm.eq_zpow_of_nonzero hq]\n  apply zpow_ne_zero_of_ne_zero\n  exact_mod_cast ne_of_gt hp.1.pos\n#align padic_norm.nonzero padicNorm.nonzero\n\n/-- If the `p`-adic norm of `q` is 0, then `q` is `0`. -/\ntheorem zero_of_padicNorm_eq_zero {q : ℚ} (h : padicNorm p q = 0) : q = 0 := by\n  apply by_contradiction; intro hq\n  unfold padicNorm 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\n#align padic_norm.zero_of_padic_norm_eq_zero padicNorm.zero_of_padicNorm_eq_zero\n\n/-- The `p`-adic norm is multiplicative. -/\n@[simp]\nprotected theorem mul (q r : ℚ) : padicNorm p (q * r) = padicNorm p q * padicNorm p r :=\n  if hq : q = 0 then by simp [hq]\n  else\n    if hr : r = 0 then by simp [hr]\n    else by\n      have : (p : ℚ) ≠ 0 := by simp [hp.1.ne_zero]\n      simp [padicNorm, *, padicValRat.mul, zpow_add₀ this, mul_comm]\n#align padic_norm.mul padicNorm.mul\n\n/-- The `p`-adic norm respects division. -/\n@[simp]\nprotected theorem div (q r : ℚ) : padicNorm p (q / r) = padicNorm p q / padicNorm p r :=\n  if hr : r = 0 then by simp [hr]\n  else eq_div_of_mul_eq (padicNorm.nonzero hr) (by rw [← padicNorm.mul, div_mul_cancel _ hr])\n#align padic_norm.div padicNorm.div\n\n/-- The `p`-adic norm of an integer is at most `1`. -/\nprotected theorem of_int (z : ℤ) : padicNorm p z ≤ 1 :=\n  if hz : z = 0 then by simp [hz, zero_le_one]\n  else by\n    unfold padicNorm\n    rw [if_neg _]\n    · refine' zpow_le_one_of_nonpos _ _\n      · exact_mod_cast le_of_lt hp.1.one_lt\n      · rw [padicValRat.of_int, neg_nonpos]\n        norm_cast\n        simp\n    exact_mod_cast hz\n#align padic_norm.of_int padicNorm.of_int\n\nprivate theorem nonarchimedean_aux {q r : ℚ} (h : padicValRat p q ≤ padicValRat p r) :\n    padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) :=\n  have hnqp : padicNorm p q ≥ 0 := padicNorm.nonneg _\n  have hnrp : padicNorm p r ≥ 0 := padicNorm.nonneg _\n  if hq : q = 0 then by simp [hq, max_eq_right hnrp, le_max_right]\n  else\n    if hr : r = 0 then by simp [hr, max_eq_left hnqp, le_max_left]\n    else\n      if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)\n      else by\n        unfold padicNorm; 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 : padicValRat p q = min (padicValRat p q) (padicValRat p r) := (min_eq_left h).symm\n          rw [this]\n          exact min_le_padicValRat_add hqr\n\n/-- The `p`-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p`\nand the norm of `q`. -/\nprotected theorem nonarchimedean {q r : ℚ} :\n    padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := by\n  wlog hle : padicValRat p q ≤ padicValRat p r generalizing q r\n  · rw [add_comm, max_comm]\n    exact this (le_of_not_le hle)\n  exact nonarchimedean_aux hle\n#align padic_norm.nonarchimedean padicNorm.nonarchimedean\n\n/-- The `p`-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of\n`p` plus the norm of `q`. -/\ntheorem triangle_ineq (q r : ℚ) : padicNorm p (q + r) ≤ padicNorm p q + padicNorm p r :=\n  calc\n    padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := padicNorm.nonarchimedean\n    _ ≤ padicNorm p q + padicNorm p r :=\n      max_le_add_of_nonneg (padicNorm.nonneg _) (padicNorm.nonneg _)\n#align padic_norm.triangle_ineq padicNorm.triangle_ineq\n\n/-- The `p`-adic norm of a difference is at most the max of each component. Restates the archimedean\nproperty of the `p`-adic norm. -/\nprotected theorem sub {q r : ℚ} : padicNorm p (q - r) ≤ max (padicNorm p q) (padicNorm p r) := by\n  rw [sub_eq_add_neg, ← padicNorm.neg r]\n  exact padicNorm.nonarchimedean\n#align padic_norm.sub padicNorm.sub\n\n/-- If the `p`-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max\nof the norms of `q` and `r`. -/\ntheorem add_eq_max_of_ne {q r : ℚ} (hne : padicNorm p q ≠ padicNorm p r) :\n    padicNorm p (q + r) = max (padicNorm p q) (padicNorm p r) := by\n  wlog hlt : padicNorm p r < padicNorm p q\n  · rw [add_comm, max_comm]\n    exact this hne.symm (hne.lt_or_lt.resolve_right hlt)\n  have : padicNorm p q ≤ max (padicNorm p (q + r)) (padicNorm p r) :=\n    calc\n      padicNorm p q = padicNorm p (q + r + (-r)) := by ring_nf\n      _ ≤ max (padicNorm p (q + r)) (padicNorm p (-r)) := padicNorm.nonarchimedean\n      _ = max (padicNorm p (q + r)) (padicNorm p r) := by simp\n  have hnge : padicNorm p r ≤ padicNorm p (q + r) := by\n    apply le_of_not_gt\n    intro hgt\n    rw [max_eq_right_of_lt hgt] at this\n    exact not_lt_of_ge this hlt\n  have : padicNorm p q ≤ padicNorm p (q + r) := by rwa [max_eq_left hnge] at this\n  apply _root_.le_antisymm\n  · apply padicNorm.nonarchimedean\n  · rwa [max_eq_left_of_lt hlt]\n#align padic_norm.add_eq_max_of_ne padicNorm.add_eq_max_of_ne\n\n/-- The `p`-adic norm is an absolute value: positive-definite and multiplicative, satisfying the\ntriangle inequality. -/\ninstance : IsAbsoluteValue (padicNorm p)\n    where\n  abv_nonneg' := padicNorm.nonneg\n  abv_eq_zero' := ⟨zero_of_padicNorm_eq_zero, fun hx ↦ by simp [hx]⟩\n  abv_add' := padicNorm.triangle_ineq\n  abv_mul' := padicNorm.mul\n\ntheorem dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p ^ n) ∣ z ↔ padicNorm p z ≤ (p : ℚ) ^ (-n : ℤ) := by\n  unfold padicNorm; split_ifs with hz\n  · norm_cast at hz\n    simp [hz]\n  · rw [zpow_le_iff_le, neg_le_neg_iff, padicValRat.of_int,\n      padicValInt.of_ne_one_ne_zero hp.1.ne_one _]\n    · norm_cast\n      rw [← PartENat.coe_le_coe, PartENat.natCast_get, ← multiplicity.pow_dvd_iff_le_multiplicity,\n        Nat.cast_pow]\n      exact_mod_cast hz\n    · exact_mod_cast hp.1.one_lt\n#align padic_norm.dvd_iff_norm_le padicNorm.dvd_iff_norm_le\n\n/-- The `p`-adic norm of an integer `m` is one iff `p` doesn't divide `m`. -/\ntheorem int_eq_one_iff (m : ℤ) : padicNorm p m = 1 ↔ ¬(p : ℤ) ∣ m := by\n  nth_rw 2 [← pow_one p]\n  simp only [dvd_iff_norm_le, Int.cast_ofNat, Nat.cast_one, zpow_neg, zpow_one, not_le]\n  constructor\n  · intro h\n    rw [h, inv_lt_one_iff_of_pos] <;> norm_cast\n    · exact Nat.Prime.one_lt Fact.out\n    · exact Nat.Prime.pos Fact.out\n  · simp only [padicNorm]\n    split_ifs\n    · rw [inv_lt_zero, ← Nat.cast_zero, Nat.cast_lt]\n      intro h\n      exact (Nat.not_lt_zero p h).elim\n    · have : 1 < (p : ℚ) := by norm_cast; exact Nat.Prime.one_lt (Fact.out : Nat.Prime p)\n      rw [← zpow_neg_one, zpow_lt_iff_lt this]\n      have : 0 ≤ padicValRat p m\n      simp only [of_int, Nat.cast_nonneg]\n      intro h\n      rw [← zpow_zero (p : ℚ), zpow_inj] <;> linarith\n#align padic_norm.int_eq_one_iff padicNorm.int_eq_one_iff\n\ntheorem int_lt_one_iff (m : ℤ) : padicNorm p m < 1 ↔ (p : ℤ) ∣ m := by\n  rw [← not_iff_not, ← int_eq_one_iff, eq_iff_le_not_lt]\n  simp only [padicNorm.of_int, true_and_iff]\n#align padic_norm.int_lt_one_iff padicNorm.int_lt_one_iff\n\ntheorem of_nat (m : ℕ) : padicNorm p m ≤ 1 :=\n  padicNorm.of_int (m : ℤ)\n#align padic_norm.of_nat padicNorm.of_nat\n\n/-- The `p`-adic norm of a natural `m` is one iff `p` doesn't divide `m`. -/\ntheorem nat_eq_one_iff (m : ℕ) : padicNorm p m = 1 ↔ ¬p ∣ m := by\n  rw [← Int.coe_nat_dvd, ← int_eq_one_iff, Int.cast_ofNat]\n#align padic_norm.nat_eq_one_iff padicNorm.nat_eq_one_iff\n\n\n\nopen BigOperators\n\ntheorem sum_lt {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α} :\n    s.Nonempty → (∀ i ∈ s, padicNorm p (F i) < t) → padicNorm p (∑ i in s, F i) < t := by\n  classical\n    refine' s.induction_on (by rintro ⟨-, ⟨⟩⟩) _\n    rintro a S haS IH - ht\n    by_cases hs : S.Nonempty\n    · rw [Finset.sum_insert haS]\n      exact\n        lt_of_le_of_lt padicNorm.nonarchimedean\n          (max_lt (ht a (Finset.mem_insert_self a S))\n            (IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb)))\n    · simp_all\n#align padic_norm.sum_lt padicNorm.sum_lt\n\ntheorem sum_le {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α} :\n    s.Nonempty → (∀ i ∈ s, padicNorm p (F i) ≤ t) → padicNorm p (∑ i in s, F i) ≤ t := by\n  classical\n    refine' s.induction_on (by rintro ⟨-, ⟨⟩⟩) _\n    rintro a S haS IH - ht\n    by_cases hs : S.Nonempty\n    · rw [Finset.sum_insert haS]\n      exact\n        padicNorm.nonarchimedean.trans\n          (max_le (ht a (Finset.mem_insert_self a S))\n            (IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb)))\n    · simp_all\n#align padic_norm.sum_le padicNorm.sum_le\n\ntheorem sum_lt' {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α}\n    (hF : ∀ i ∈ s, padicNorm p (F i) < t) (ht : 0 < t) : padicNorm p (∑ i in s, F i) < t := by\n  obtain rfl | hs := Finset.eq_empty_or_nonempty s\n  · simp [ht]\n  · exact sum_lt hs hF\n#align padic_norm.sum_lt' padicNorm.sum_lt'\n\ntheorem sum_le' {α : Type _} {F : α → ℚ} {t : ℚ} {s : Finset α}\n    (hF : ∀ i ∈ s, padicNorm p (F i) ≤ t) (ht : 0 ≤ t) : padicNorm p (∑ i in s, F i) ≤ t := by\n  obtain rfl | hs := Finset.eq_empty_or_nonempty s\n  · simp [ht]\n  · exact sum_le hs hF\n#align padic_norm.sum_le' padicNorm.sum_le'\n\nend padicNorm\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/PadicNorm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464796, "lm_q2_score": 0.8198933315126791, "lm_q1q2_score": 0.7520903354267586}}
{"text": "import set_theory_world.image_Union -- hide\nopen function -- hide\nopen_locale big_operators -- hide\n/-\n## The preimage of a function\n\nGiven a function `f : X → Y`, the preimage of a subset $B ⊆ Y$ is written\nas `f⁻¹' B`. We will also need to refer to $X$ as a subset of itself. It is\ncalled `univ` in Lean. The following lemma is very well known.\n-/\nvariables{X Y: Type} -- hide\nvariables {B : set Y}\nvariables {x : X} -- hide\nvariables {f : X → Y} -- hide\n\nlemma mem_preimage : x ∈ f ⁻¹' B ↔ f x ∈ B\n:= set.mem_preimage\n\n/- Axiom:\nmem_preimage : x ∈ f ⁻¹' B ↔ f x ∈ B\n-/\n\n/- Lemma\nThe image of the preimage of a set $B$ is $B ∩ \\textrm{Im}(f)$.\n-/\nlemma image_preimage (B : set Y) :\nf '' (f⁻¹' B ) = B ∩ f '' set.univ :=\nbegin\n  ext y,\n  split,\n  {\n    intro h,\n    rw mem_image at h,\n    obtain ⟨x, ⟨hx1, hx2⟩⟩ := h,\n    rw mem_preimage at hx1,\n    dsimp,\n    split,\n    {\n      rw ←hx2,\n      assumption,\n    },\n    {\n      use x,\n      split,\n      {\n        apply set.mem_univ,\n      },\n      {\n        assumption,\n      }\n    }\n  },\n  {\n    intro h,\n    cases h with h1 h2,\n    obtain ⟨x, ⟨hx1, hx2⟩⟩ := h2,\n    use x,\n    split,\n    {\n      rw mem_preimage,\n      rw hx2,\n      assumption,\n    },\n    {\n      assumption,\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/preimage.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388752, "lm_q2_score": 0.8128673201042492, "lm_q1q2_score": 0.752089202405159}}
{"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, Yaël Dillies\n-/\nimport algebra.punit_instances\nimport tactic.abel\nimport tactic.ring\nimport order.hom.lattice\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`: Turn a Boolean ring into a Boolean algebra.\n* `boolean_algebra.to_boolean_ring`: Turn a Boolean algebra into a Boolean ring.\n* `as_boolalg`: Type-synonym for the Boolean algebra associated to a Boolean ring.\n* `as_boolring`: Type-synonym for the Boolean ring associated to a Boolean algebra.\n\n## Implementation notes\n\nWe provide two ways of turning a Boolean algebra/ring into a Boolean ring/algebra:\n* Instances on the same type accessible in locales `boolean_algebra_of_boolean_ring` and\n  `boolean_ring_of_boolean_algebra`.\n* Type-synonyms `as_boolalg` and `as_boolring`.\n\nAt this point in time, it is not clear the first way is useful, but we keep it for educational\npurposes and because it is easier than dealing with\n`of_boolalg`/`to_boolalg`/`of_boolring`/`to_boolring` explicitly.\n\n## Tags\n\nboolean ring, boolean algebra\n-/\n\nvariables {α β γ : Type*}\n\n/-- A Boolean ring is a ring where multiplication is idempotent. -/\nclass boolean_ring α extends ring α :=\n(mul_self : ∀ a : α, a * a = a)\n\nsection boolean_ring\nvariables [boolean_ring α] (a b : α)\n\ninstance : is_idempotent α (*) := ⟨boolean_ring.mul_self⟩\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 [←neg_add_self, add_assoc]\n    ... = a           : by rw [add_self, zero_add]\n\nlemma add_eq_zero : a + b = 0 ↔ a = b :=\ncalc a + b = 0 ↔ a = -b : add_eq_zero_iff_eq_neg\n           ... ↔ 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 α :=\n{ mul_comm := λ a b, by rw [←add_eq_zero, mul_add_mul],\n  .. (infer_instance : boolean_ring α) }\n\nend boolean_ring\n\ninstance : boolean_ring punit := ⟨λ _, subsingleton.elim _ _⟩\n\n/-! ### Turning a Boolean ring into a Boolean algebra -/\n\nsection ring_to_algebra\n\n/-- Type synonym to view a Boolean ring as a Boolean algebra. -/\ndef as_boolalg (α : Type*) := α\n\n/-- The \"identity\" equivalence between `as_boolalg α` and `α`. -/\ndef to_boolalg : α ≃ as_boolalg α := equiv.refl _\n\n/-- The \"identity\" equivalence between `α` and `as_boolalg α`. -/\ndef of_boolalg : as_boolalg α ≃ α := equiv.refl _\n\n@[simp] lemma to_boolalg_symm_eq : (@to_boolalg α).symm = of_boolalg := rfl\n@[simp] lemma of_boolalg_symm_eq : (@of_boolalg α).symm = to_boolalg := rfl\n@[simp] lemma to_boolalg_of_boolalg (a : as_boolalg α) : to_boolalg (of_boolalg a) = a := rfl\n@[simp] lemma of_boolalg_to_boolalg (a : α) : of_boolalg (to_boolalg a) = a := rfl\n@[simp] lemma to_boolalg_inj {a b : α} : to_boolalg a = to_boolalg b ↔ a = b := iff.rfl\n@[simp] lemma of_boolalg_inj {a b : as_boolalg α} : of_boolalg a = of_boolalg b ↔ a = b := iff.rfl\n\ninstance [inhabited α] : inhabited (as_boolalg α) := ‹inhabited α›\n\nvariables [boolean_ring α] [boolean_ring β] [boolean_ring γ]\n\nnamespace boolean_ring\n\n/-- The join operation in a Boolean ring is `x + y + x * y`. -/\ndef has_sup : has_sup α := ⟨λ x y, x + y + x * y⟩\n/-- The meet operation in a Boolean ring is `x * y`. -/\ndef has_inf : has_inf α := ⟨(*)⟩\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 : α) : a ⊔ b = b ⊔ a := by { dsimp only [(⊔)], ring }\nlemma inf_comm (a b : α) : a ⊓ b = b ⊓ a := by { dsimp only [(⊓)], ring }\n\nlemma sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := by { dsimp only [(⊔)], ring }\nlemma inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := by { dsimp only [(⊓)], ring }\n\nlemma sup_inf_self (a b : α) : a ⊔ a ⊓ b = a :=\nby { dsimp only [(⊔), (⊓)], assoc_rw [mul_self, add_self, add_zero] }\nlemma inf_sup_self (a b : α) : a ⊓ (a ⊔ b) = a :=\nbegin\n  dsimp only [(⊔), (⊓)],\n  rw [mul_add, mul_add, mul_self, ←mul_assoc, mul_self, add_assoc, add_self, add_zero]\nend\n\n\n\nlemma le_sup_inf (a b c : α) : (a ⊔ b) ⊓ (a ⊔ c) ⊔ (a ⊔ b ⊓ c) = a ⊔ b ⊓ c :=\nby { dsimp only [(⊔), (⊓)], 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 ⊔ b` unfolds to `a + b + a * b`\n* `a ⊓ b` unfolds to `a * b`\n* `a ≤ b` unfolds to `a + b + a * b = b`\n* `⊥` unfolds to `0`\n* `⊤` unfolds to `1`\n* `aᶜ` unfolds to `1 + a`\n* `a \\ b` unfolds to `a * (1 + b)`\n-/\ndef to_boolean_algebra : boolean_algebra α :=\n{ le_sup_inf := le_sup_inf,\n  top := 1,\n  le_top := λ a, show a + 1 + a * 1 = 1, by assoc_rw [mul_one, add_comm, add_self, add_zero],\n  bot := 0,\n  bot_le := λ a, show 0 + a + 0 * a = a, by rw [zero_mul, zero_add, add_zero],\n  compl := λ a, 1 + a,\n  inf_compl_le_bot := λ 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 := λ 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 [←add_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\ninstance : boolean_algebra (as_boolalg α) := @boolean_ring.to_boolean_algebra α _\n\n@[simp] lemma of_boolalg_top : of_boolalg (⊤ : as_boolalg α) = 1 := rfl\n@[simp] lemma of_boolalg_bot : of_boolalg (⊥ : as_boolalg α) = 0 := rfl\n\n@[simp] lemma of_boolalg_sup (a b : as_boolalg α) :\n  of_boolalg (a ⊔ 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 α) :\n  of_boolalg (a ⊓ b) = of_boolalg a * of_boolalg b := rfl\n\n@[simp] lemma of_boolalg_compl (a : as_boolalg α) : of_boolalg aᶜ = 1 + of_boolalg a := rfl\n\n@[simp] lemma of_boolalg_sdiff (a b : as_boolalg α) :\n  of_boolalg (a \\ b) = of_boolalg a * (1 + of_boolalg b) := rfl\n\nprivate lemma of_boolalg_symm_diff_aux (a b : α) : (a + b + a * b) * (1 + a * b) = a + b :=\ncalc (a + b + a * b) * (1 + a * b)\n      = a + b + (a * b + (a * b) * (a * b)) + (a * (b * b) + (a * a) * b) : by ring\n  ... = a + b : by simp only [mul_self, add_self, add_zero]\n\n@[simp] lemma of_boolalg_symm_diff (a b : as_boolalg α) :\n  of_boolalg (a ∆ b) = of_boolalg a + of_boolalg b :=\nby { rw symm_diff_eq_sup_sdiff_inf, exact of_boolalg_symm_diff_aux _ _ }\n\n@[simp] lemma of_boolalg_mul_of_boolalg_eq_left_iff {a b : as_boolalg α} :\n  of_boolalg a * of_boolalg b = of_boolalg a ↔ a ≤ b :=\n@inf_eq_left (as_boolalg α) _ _ _\n\n@[simp] lemma to_boolalg_zero : to_boolalg (0 : α) = ⊥ := rfl\n@[simp] lemma to_boolalg_one : to_boolalg (1 : α) = ⊤ := rfl\n\n@[simp] lemma to_boolalg_mul (a b : α) :\n  to_boolalg (a * b) = to_boolalg a ⊓ to_boolalg b := rfl\n\n-- `to_boolalg_add` simplifies the LHS but this lemma is eligible to `dsimp`\n@[simp, nolint simp_nf] lemma to_boolalg_add_add_mul (a b : α) :\n  to_boolalg (a + b + a * b) = to_boolalg a ⊔ to_boolalg b := rfl\n\n@[simp] lemma to_boolalg_add (a b : α) : to_boolalg (a + b) = to_boolalg a ∆ to_boolalg b :=\n(of_boolalg_symm_diff _ _).symm\n\n/-- Turn a ring homomorphism from Boolean rings `α` to `β` into a bounded lattice homomorphism\nfrom `α` to `β` considered as Boolean algebras. -/\n@[simps] protected def ring_hom.as_boolalg (f : α →+* β) :\n  bounded_lattice_hom (as_boolalg α) (as_boolalg β) :=\n{ to_fun := to_boolalg ∘ f ∘ of_boolalg,\n  map_sup' := λ 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 α).as_boolalg = bounded_lattice_hom.id _ := rfl\n\n@[simp] lemma ring_hom.as_boolalg_comp (g : β →+* γ) (f : α →+* β) :\n  (g.comp f).as_boolalg = g.as_boolalg.comp f.as_boolalg := rfl\n\nend ring_to_algebra\n\n/-! ### Turning a Boolean algebra into a Boolean ring -/\n\nsection algebra_to_ring\n\n/-- Type synonym to view a Boolean ring as a Boolean algebra. -/\ndef as_boolring (α : Type*) := α\n\n/-- The \"identity\" equivalence between `as_boolring α` and `α`. -/\ndef to_boolring : α ≃ as_boolring α := equiv.refl _\n\n/-- The \"identity\" equivalence between `α` and `as_boolring α`. -/\ndef of_boolring : as_boolring α ≃ α := equiv.refl _\n\n@[simp] lemma to_boolring_symm_eq : (@to_boolring α).symm = of_boolring := rfl\n@[simp] lemma of_boolring_symm_eq : (@of_boolring α).symm = to_boolring := rfl\n@[simp] lemma to_boolring_of_boolring (a : as_boolring α) : to_boolring (of_boolring a) = a := rfl\n@[simp] lemma of_boolring_to_boolring (a : α) : of_boolring (to_boolring a) = a := rfl\n@[simp] lemma to_boolring_inj {a b : α} : to_boolring a = to_boolring b ↔ a = b := iff.rfl\n@[simp] lemma of_boolring_inj {a b : as_boolring α} : of_boolring a = of_boolring b ↔ a = b :=\niff.rfl\n\ninstance [inhabited α] : inhabited (as_boolring α) := ‹inhabited α›\n\n/-- Every generalized Boolean algebra has the structure of a non unital commutative ring with the\nfollowing data:\n\n* `a + b` unfolds to `a ∆ b` (symmetric difference)\n* `a * b` unfolds to `a ⊓ b`\n* `-a` unfolds to `a`\n* `0` unfolds to `⊥`\n-/\n@[reducible] -- See note [reducible non-instances]\ndef generalized_boolean_algebra.to_non_unital_comm_ring [generalized_boolean_algebra α] :\n  non_unital_comm_ring α :=\n{ add := (∆),\n  add_assoc := symm_diff_assoc,\n  zero := ⊥,\n  zero_add := bot_symm_diff,\n  add_zero := symm_diff_bot,\n  zero_mul := λ _, bot_inf_eq,\n  mul_zero := λ _, inf_bot_eq,\n  neg := id,\n  add_left_neg := symm_diff_self,\n  add_comm := symm_diff_comm,\n  mul := (⊓),\n  mul_assoc := λ _ _ _, inf_assoc,\n  mul_comm := λ _ _, inf_comm,\n  left_distrib := inf_symm_diff_distrib_left,\n  right_distrib := inf_symm_diff_distrib_right }\n\ninstance [generalized_boolean_algebra α] : non_unital_comm_ring (as_boolring α) :=\n@generalized_boolean_algebra.to_non_unital_comm_ring α _\n\nvariables [boolean_algebra α] [boolean_algebra β] [boolean_algebra γ]\n\n/-- Every Boolean algebra has the structure of a Boolean ring with the following data:\n\n* `a + b` unfolds to `a ∆ b` (symmetric difference)\n* `a * b` unfolds to `a ⊓ b`\n* `-a` unfolds to `a`\n* `0` unfolds to `⊥`\n* `1` unfolds to `⊤`\n-/\n@[reducible] -- See note [reducible non-instances]\ndef boolean_algebra.to_boolean_ring : boolean_ring α :=\n{ one := ⊤,\n  one_mul := λ _, top_inf_eq,\n  mul_one := λ _, inf_top_eq,\n  mul_self := λ b, inf_idem,\n  ..generalized_boolean_algebra.to_non_unital_comm_ring }\n\nlocalized \"attribute [instance, priority 100] generalized_boolean_algebra.to_non_unital_comm_ring\n  boolean_algebra.to_boolean_ring\" in boolean_ring_of_boolean_algebra\n\ninstance : boolean_ring (as_boolring α) := @boolean_algebra.to_boolean_ring α _\n\n@[simp] lemma of_boolring_zero : of_boolring (0 : as_boolring α) = ⊥ := rfl\n@[simp] lemma of_boolring_one : of_boolring (1 : as_boolring α) = ⊤ := rfl\n\n-- `sub_eq_add` proves this lemma but it is eligible for `dsimp`\n@[simp, nolint simp_nf] lemma of_boolring_neg (a : as_boolring α) :\n  of_boolring (-a) = of_boolring a := rfl\n\n@[simp] lemma of_boolring_add (a b : as_boolring α) :\n  of_boolring (a + b) = of_boolring a ∆ of_boolring b := rfl\n\n-- `sub_eq_add` simplifies the LHS but this lemma is eligible for `dsimp`\n@[simp, nolint simp_nf] lemma of_boolring_sub (a b : as_boolring α) :\n  of_boolring (a - b) = of_boolring a ∆ of_boolring b := rfl\n\n@[simp] lemma of_boolring_mul (a b : as_boolring α) :\n  of_boolring (a * b) = of_boolring a ⊓ of_boolring b := rfl\n\n@[simp] lemma of_boolring_le_of_boolring_iff {a b : as_boolring α} :\n  of_boolring a ≤ of_boolring b ↔ a * b = a := inf_eq_left.symm\n\n@[simp] lemma to_boolring_bot : to_boolring (⊥ : α) = 0 := rfl\n@[simp] lemma to_boolring_top : to_boolring (⊤ : α) = 1 := rfl\n@[simp] lemma to_boolring_inf (a b : α) : to_boolring (a ⊓ b) = to_boolring a * to_boolring b := rfl\n\n@[simp] lemma to_boolring_symm_diff (a b : α) :\n  to_boolring (a ∆ b) = to_boolring a + to_boolring b := rfl\n\n/-- Turn a bounded lattice homomorphism from Boolean algebras `α` to `β` into a ring homomorphism\nfrom `α` to `β` considered as Boolean rings. -/\n@[simps] protected def bounded_lattice_hom.as_boolring (f : bounded_lattice_hom α β) :\n  as_boolring α →+* as_boolring β :=\n{ to_fun := to_boolring ∘ f ∘ of_boolring,\n  map_zero' := f.map_bot',\n  map_one' := f.map_top',\n  map_add' := map_symm_diff' f,\n  map_mul' := f.map_inf' }\n\n@[simp] lemma bounded_lattice_hom.as_boolring_id :\n  (bounded_lattice_hom.id α).as_boolring = ring_hom.id _ := rfl\n\n@[simp] lemma bounded_lattice_hom.as_boolring_comp (g : bounded_lattice_hom β γ)\n  (f : bounded_lattice_hom α β) :\n  (g.comp f).as_boolring = g.as_boolring.comp f.as_boolring := rfl\n\nend algebra_to_ring\n\n/-! ### Equivalence between Boolean rings and Boolean algebras -/\n\n/-- Order isomorphism between `α` considered as a Boolean ring considered as a Boolean algebra and\n`α`. -/\n@[simps] def order_iso.as_boolalg_as_boolring (α : Type*) [boolean_algebra α] :\n  as_boolalg (as_boolring α) ≃o α :=\n⟨of_boolalg.trans of_boolring, λ a b,\n  of_boolring_le_of_boolring_iff.trans of_boolalg_mul_of_boolalg_eq_left_iff⟩\n\n/-- Ring isomorphism between `α` considered as a Boolean algebra considered as a Boolean ring and\n`α`. -/\n@[simps] def ring_equiv.as_boolring_as_boolalg (α : Type*) [boolean_ring α] :\n  as_boolring (as_boolalg α) ≃+* α :=\n{ map_mul' := λ a b, rfl,\n  map_add' := of_boolalg_symm_diff,\n  ..of_boolring.trans of_boolalg }\n\nopen bool\n\ninstance : boolean_ring bool :=\n{ add := bxor,\n  add_assoc := bxor_assoc,\n  zero := ff,\n  zero_add := ff_bxor,\n  add_zero := bxor_ff,\n  neg := id,\n  sub := bxor,\n  sub_eq_add_neg := λ _ _, rfl,\n  add_left_neg := bxor_self,\n  add_comm := bxor_comm,\n  one := tt,\n  mul := band,\n  mul_assoc := band_assoc,\n  one_mul := tt_band,\n  mul_one := band_tt,\n  left_distrib := band_bxor_distrib_left,\n  right_distrib := band_bxor_distrib_right,\n  mul_self := band_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/algebra/ring/boolean_ring.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89330940889474, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7520107677937794}}
{"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-/\nimport topology.basic\nimport topology.constructions\nimport topology.algebra.ordered.basic\n\n/-!\n# Topological lattices\n\nIn this file we define mixin classes `has_continuous_inf` and `has_continuous_sup`. We define the\nclass `topological_lattice` as a topological space and lattice `L` extending `has_continuous_inf`\nand `has_continuous_sup`.\n\n## References\n\n* [Gierz et al, A Compendium of Continuous Lattices][GierzEtAl1980]\n\n## Tags\n\ntopological, lattice\n-/\n\n/--\nLet `L` be a topological space and let `L×L` be equipped with the product topology and let\n`⊓:L×L → L` be an infimum. Then `L` is said to have *(jointly) continuous infimum* if the map\n`⊓:L×L → L` is continuous.\n-/\nclass has_continuous_inf (L : Type*) [topological_space L] [has_inf L] : Prop :=\n(continuous_inf : continuous (λ p : L × L, p.1 ⊓ p.2))\n\n/--\nLet `L` be a topological space and let `L×L` be equipped with the product topology and let\n`⊓:L×L → L` be a supremum. Then `L` is said to have *(jointly) continuous supremum* if the map\n`⊓:L×L → L` is continuous.\n-/\nclass has_continuous_sup (L : Type*) [topological_space L] [has_sup L] : Prop :=\n(continuous_sup : continuous (λ p : L × L, p.1 ⊔ p.2))\n\n/--\nLet `L` be a topological space with a supremum. If the order dual has a continuous infimum then the\nsupremum is continuous.\n-/\n@[priority 100] -- see Note [lower instance priority]\ninstance has_continuous_inf_dual_has_continuous_sup\n  (L : Type*) [topological_space L] [has_sup L] [h: has_continuous_inf (order_dual L)] :\n  has_continuous_sup  L :=\n{ continuous_sup :=\n    @has_continuous_inf.continuous_inf (order_dual L) _ _ h }\n\n/--\nLet `L` be a lattice equipped with a topology such that `L` has continuous infimum and supremum.\nThen `L` is said to be a *topological lattice*.\n-/\nclass topological_lattice (L : Type*) [topological_space L] [lattice L]\n  extends has_continuous_inf L, has_continuous_sup L\n\nvariables {L : Type*} [topological_space L]\nvariables {X : Type*} [topological_space X]\n\n@[continuity] lemma continuous_inf [has_inf L] [has_continuous_inf L] :\n  continuous (λp:L×L, p.1 ⊓ p.2) :=\nhas_continuous_inf.continuous_inf\n\n@[continuity] lemma continuous.inf [has_inf L] [has_continuous_inf L]\n  {f g : X → L} (hf : continuous f) (hg : continuous g) :\n  continuous (λx, f x ⊓ g x) :=\ncontinuous_inf.comp (hf.prod_mk hg : _)\n\n@[continuity] lemma continuous_sup [has_sup L] [has_continuous_sup L] :\n  continuous (λp:L×L, p.1 ⊔ p.2) :=\nhas_continuous_sup.continuous_sup\n\n@[continuity] lemma continuous.sup [has_sup L] [has_continuous_sup L]\n  {f g : X → L} (hf : continuous f) (hg : continuous g) :\n  continuous (λx, f x ⊔ g x) :=\ncontinuous_sup.comp (hf.prod_mk 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/order/lattice.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308073258009, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7520019089244807}}
{"text": "\ntheorem Ex003_1 (a b: Prop) : ¬a → a → b :=\nassume A:¬a,\n  assume B:a,\n  have C:false, from  A B,\n  show b, from false.elim C\n\n\ntheorem Ex003_2 (a b : Prop) : ¬a → a → b := \nbegin\n  intro,\n  intro,\n  contradiction\nend \n\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/Ex003.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308184368929, "lm_q2_score": 0.805632181981183, "lm_q1q2_score": 0.7520019069857955}}
{"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.analysis.calculus.mean_value\nimport Mathlib.PostPort\n\nnamespace Mathlib\n\n/-!\n# Darboux's theorem\n\nIn this file we prove that the derivative of a differentiable function on an interval takes all\nintermediate values. The proof is based on the\n[Wikipedia](https://en.wikipedia.org/wiki/Darboux%27s_theorem_(analysis)) page about this theorem.\n-/\n\n/-- Darboux's theorem: if `a ≤ b` and `f' a < m < f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/\ntheorem exists_has_deriv_within_at_eq_of_gt_of_lt {a : ℝ} {b : ℝ} {f : ℝ → ℝ} {f' : ℝ → ℝ} (hab : a ≤ b) (hf : ∀ (x : ℝ), x ∈ set.Icc a b → has_deriv_within_at f (f' x) (set.Icc a b) x) {m : ℝ} (hma : f' a < m) (hmb : m < f' b) : m ∈ f' '' set.Icc a b := sorry\n\n/-- Darboux's theorem: if `a ≤ b` and `f' a > m > f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/\ntheorem exists_has_deriv_within_at_eq_of_lt_of_gt {a : ℝ} {b : ℝ} {f : ℝ → ℝ} {f' : ℝ → ℝ} (hab : a ≤ b) (hf : ∀ (x : ℝ), x ∈ set.Icc a b → has_deriv_within_at f (f' x) (set.Icc a b) x) {m : ℝ} (hma : m < f' a) (hmb : f' b < m) : m ∈ f' '' set.Icc a b := sorry\n\n/-- Darboux's theorem: the image of a convex set under `f'` is a convex set. -/\ntheorem convex_image_has_deriv_at {f : ℝ → ℝ} {f' : ℝ → ℝ} {s : set ℝ} (hs : convex s) (hf : ∀ (x : ℝ), x ∈ s → has_deriv_at f (f' x) x) : convex (f' '' s) := sorry\n\n/-- If the derivative of a function is never equal to `m`, then either\nit is always greater than `m`, or it is always less than `m`. -/\ntheorem deriv_forall_lt_or_forall_gt_of_forall_ne {f : ℝ → ℝ} {f' : ℝ → ℝ} {s : set ℝ} (hs : convex s) (hf : ∀ (x : ℝ), x ∈ s → has_deriv_at f (f' x) x) {m : ℝ} (hf' : ∀ (x : ℝ), x ∈ s → f' x ≠ m) : (∀ (x : ℝ), x ∈ s → f' x < m) ∨ ∀ (x : ℝ), x ∈ s → m < f' 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/analysis/calculus/darboux.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.751999590456013}}
{"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.apply_fun\nimport ring_theory.matrix_algebra\nimport ring_theory.polynomial_algebra\nimport linear_algebra.nonsingular_inverse\nimport tactic.squeeze\n\n/-!\n# Characteristic polynomials and the Cayley-Hamilton theorem\n\nWe define characteristic polynomials of matrices and\nprove the Cayley–Hamilton 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\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/--\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 (M : matrix n n R) : matrix n n (polynomial R) :=\nmatrix.scalar n (X : polynomial R) - (C : R →+* polynomial R).map_matrix M\n\n@[simp] lemma char_matrix_apply_eq (M : matrix n n R) (i : n) :\n  char_matrix M i i = (X : polynomial R) - C (M i i) :=\nby simp only [char_matrix, sub_left_inj, pi.sub_apply, scalar_apply_eq,\n  ring_hom.map_matrix_apply, map_apply, dmatrix.sub_apply]\n\n@[simp] lemma char_matrix_apply_ne (M : matrix n n R) (i j : n) (h : i ≠ j) :\n  char_matrix M i j = - C (M i j) :=\nby simp only [char_matrix, 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_char_matrix (M : matrix n n R) :\n  mat_poly_equiv (char_matrix 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 [char_matrix_apply_eq, coeff_sub],\n    simp only [coeff_X, coeff_C],\n    split_ifs; simp, },\n  { rw [char_matrix_apply_ne _ _ _ h, coeff_X, coeff_neg, coeff_C, coeff_C],\n    split_ifs; simp [h], }\nend\n\n/--\nThe characteristic polynomial of a matrix `M` is given by $\\det (t I - M)$.\n-/\ndef char_poly (M : matrix n n R) : polynomial R :=\n(char_matrix M).det\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 aeval_self_char_poly (M : matrix n n R) :\n  aeval M (char_poly M) = 0 :=\nbegin\n  -- We begin with the fact $χ_M(t) I = adjugate (t I - M) * (t I - M)$,\n  -- as an identity in `matrix n n (polynomial R)`.\n  have h : (char_poly M) • (1 : matrix n n (polynomial R)) =\n    adjugate (char_matrix M) * (char_matrix M) :=\n    (adjugate_mul _).symm,\n  -- Using the algebra isomorphism `matrix n n (polynomial R) ≃ₐ[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_char_matrix] 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 (λ p, p.eval M) at h,\n  rw eval_mul_X_sub_C at h,\n  -- Now $χ_M (t) I$, when thought of as a polynomial of matrices\n  -- and evaluated at some `N` is exactly $χ_M (N)$.\n  rw [mat_poly_equiv_smul_one, eval_map] at h,\n  -- Thus we have $χ_M(M) = 0$, which is the desired result.\n  exact 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/src/linear_algebra/char_poly/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701655, "lm_q2_score": 0.8031737963569014, "lm_q1q2_score": 0.7519995811107544}}
{"text": "/-\nCopyright (c) 2023 Jujian Zhang. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : Jujian Zhang\n-/\n\nimport topology.bases               -- definition of topological bases\nimport topology.metric_space.basic  -- facts about intervals in ℝ\nimport topology.algebra.order.floor -- facts about floor function, fractional part function etc\n\nnoncomputable theory\n\n/-!\n\n# Topological Spaces in Lean\n\nFor any `X : Type`, a topology on `X` is defined as:\n```\n@[protect_proj] structure topological_space (α : Type u) :=\n(is_open        : set α → Prop)\n(is_open_univ   : is_open univ)\n(is_open_inter  : ∀s t, is_open s → is_open t → is_open (s ∩ t))\n(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))\n```\n\nIn this sheet, the following can be found:\n- defining several topological spaces;\n- proof or disproof of some functions being continuous;\n- denseness, compactness;\n- homeomorphism\n-/\n\nuniverse u\n\nnamespace topological_space\n\nvariables (X : Type u)\n\n/--\nThe discrete topology is the one the most open sets.\n-/\ndef discrete : topological_space X :=\n{ is_open := λ _, true,\n  is_open_univ := ⟨⟩,\n  is_open_inter := λ _ _ _ _, ⟨⟩,\n  is_open_sUnion := λ _ _, ⟨⟩ }\n\n/--\nThe indiscrete topology is the one with the least open sets.\n-/\ndef indiscrete : topological_space X :=\n{ is_open := λ s, s = set.univ ∨ s = ∅,\n  is_open_univ := or.intro_left _ rfl,\n  is_open_inter := by rintros _ _ (rfl|rfl) (rfl|rfl); simp,\n  is_open_sUnion := \n  begin \n    intros S h,\n    by_cases h' : set.univ ∈ S,\n    { left,\n      refine le_antisymm (λ _ _, ⟨⟩) (λ x _, _),\n      rw [set.mem_sUnion],\n      refine ⟨_, h', ⟨⟩⟩, },\n    { right,\n      simp_rw [set.eq_empty_iff_forall_not_mem, set.mem_sUnion],\n      push_neg,\n      rintros _ s hs,\n      exact (h s hs).elim (λ H, false.elim $ h' $ by rwa H at hs) \n        (λ H, H.symm ▸ id), },\n  end }\n\n/--\n                `1`\n`(X, discrete) ----->  (X, indiscrete)` is continuous \n-/\nexample : @@continuous (discrete X) (indiscrete X) id :=\n{ is_open_preimage := λ _ _, ⟨⟩ }\n\n/--\nBut is\n                   `1`\n`(X, indiscrete) ------> (X, discrete)` continuous?\n-/\nexample (x y : X) (h : x ≠ y) : ¬ @@continuous (indiscrete X) (discrete X) id :=\nbegin \n  rw continuous_def,\n  push_neg,\n  refine ⟨{x}, ⟨⟩, not_or (_ : _ ≠ _) $ λ r, set.eq_empty_iff_forall_not_mem.mp r x rfl⟩,\n  rw set.ne_univ_iff_exists_not_mem,\n  refine ⟨y, λ r', h (set.mem_singleton_iff.mp (set.mem_preimage.mp r')).symm⟩,\nend\n\n/--\nFinite sets only have finitely many possible topology on them.\n-/\ninstance finitely_many_topologies [fintype X] : fintype (topological_space X) :=\nlet i : topological_space X → set (set X) := λ τ, τ.is_open in\nhave inj_i : function.injective i, by { intros τ1 τ2 h, ext1, exact h },\nbegin \n  haveI : fintype (set (set X)) := infer_instance,\n  exact fintype.of_injective i inj_i,\nend\n\n/--\nThe upper bound is 2^2^|X|\n-/\nlemma card_topology_le [fintype X] : \n  fintype.card (topological_space X) ≤ 2 ^ (2 ^ fintype.card X):=\nlet i : topological_space X → set (set X) := λ τ, τ.is_open in\nhave inj_i : function.injective i, by { intros τ1 τ2 h, ext1, exact h },\nbegin \n  refine le_trans (fintype.card_le_of_injective i inj_i) _,\n  rw [fintype.card_set, fintype.card_set],\nend\n\n/--\n`ℝ` has a basis consisted of all open intervals\n-/\nexample : is_topological_basis { I | ∃ (a b : ℝ), I = set.Ioo a b } :=\nis_topological_basis_of_open_of_nhds \n  (by { rintros _ ⟨a, b, rfl⟩, rw real.Ioo_eq_ball, exact metric.is_open_ball }) $ \nλ x s hx hs, \nbegin\n  rw metric.is_open_iff at hs,\n  obtain ⟨ε, hε, subset1⟩ := hs x hx,\n  rw real.ball_eq_Ioo at subset1,\n  exact ⟨_, ⟨_, _, rfl⟩, ⟨show x - ε < x, by linarith, by linarith⟩, subset1⟩,\nend\n\n/--\n`ℚ ⊆ ℝ` is dense\n-/\nlemma dense_ℚ : dense (algebra_map ℚ ℝ '' set.univ) :=\nbegin \n  intros x,\n  rw mem_closure_iff,\n  intros v hv hx,\n  rw metric.is_open_iff at hv,\n  specialize hv x hx,\n  obtain ⟨ε, hε, subset1⟩ := hv,\n  rw real.ball_eq_Ioo at subset1,\n  obtain ⟨q, hq⟩ := exists_rat_near x hε,\n  rw abs_lt at hq,\n  cases hq,\n  refine ⟨q, subset1 ⟨_, _⟩, ⟨_, ⟨⟩, rfl⟩⟩;\n  linarith,\nend\n\n/--\nHence functions `ℝ → ℝ` is uniquely determined on `ℚ`.\n-/\nexample (f g : ℝ → ℝ) (hf : continuous f) (hg : continuous g) \n  (heq : ∀ (x : ℚ), f x = g x) : f = g :=\ncontinuous.ext_on dense_ℚ hf hg $ λ _ ⟨q, ⟨⟩, h⟩, h ▸ heq q\n\n/--\nAn algebraic interpretation of unit circle `S¹` defined as `ℝ ⧸ ℤ` with the quotient topology,\ni.e. `V ⊆ S¹` is open iff `π ⁻¹ V` is open in `ℝ` where `π : ℝ → ℝ ⧸ ℤ`.\n-/\n@[derive [topological_space, add_comm_group, inhabited]]\ndef circle := ℝ ⧸ (algebra_map ℤ ℝ).to_add_monoid_hom.range\n\nnamespace circle\n\n/-- π -/\ndef from_real : ℝ → circle := quotient.mk'\n\n/-- `[0, 1) → ℝ → S¹` -/\ndef from_Ico : set.Ico (0 : ℝ) 1 → circle :=\nfrom_real ∘ subtype.val\n\n@[continuity]\nlemma continuous_from_real : continuous from_real := ⟨λ _, id⟩\n\n@[continuity]\nlemma continuous_on_from_real : continuous_on from_real (set.Ico 0 1) := \ncontinuous.continuous_on ⟨λ s, id⟩\n\n@[continuity]\nlemma continuous_from_Ico : continuous from_Ico :=\nbegin \n  rw continuous_iff_continuous_on_univ,\n  refine continuous_on.comp _ _ _,\n  { exact set.Ico 0 1 },\n  { exact continuous_on_from_real },\n  { refine continuous.continuous_on _, continuity, },\n  { intros x hx, exact x.2, },\nend\n\nlemma from_Ico_inj : function.injective from_Ico :=\nbegin \n  rintros ⟨x, hx1, hx2⟩ ⟨y, hy1, hy2⟩ h,\n  dsimp only [from_Ico, from_real, function.comp_apply] at h,\n  rw [quotient.eq', quotient_add_group.left_rel_eq] at h,\n  obtain ⟨z, (hz : ↑z = -(x : ℝ) + y)⟩ := h,\n  rw neg_add_eq_sub at hz,\n  have ineq1 : abs (y - x : ℝ) < 1,\n  { rw abs_lt, split; linarith, },\n  rw ←hz at ineq1,\n  norm_cast at ineq1,\n  rw int.abs_lt_one_iff at ineq1,\n  rw ineq1 at hz,\n  norm_cast at hz,\n  replace hz := hz.symm,\n  rw sub_eq_zero at hz,\n  simp_rw hz,\n  refl,\nend\n\nlemma from_Ico_surj : function.surjective from_Ico :=\nbegin \n  intros x,\n  induction x using quotient.induction_on',\n  dsimp only [from_Ico, from_real, function.comp_apply],\n  refine ⟨⟨int.fract x, int.fract_nonneg _, int.fract_lt_one _⟩, _⟩,\n  rw quotient.eq',\n  rw [quotient_add_group.left_rel_eq, neg_add_eq_sub, int.self_sub_fract],\n  exact ⟨_, rfl⟩,\nend\n\n/--\n`S¹` is compact.\n-/\ninstance is_compact : compact_space circle :=\n{ is_compact_univ := \n  begin \n    rw show set.univ = from_real '' (set.Icc 0 1), from _,\n    { exact is_compact.image is_compact_Icc ⟨λ s h, h⟩, },\n    symmetry,\n    rw set.eq_univ_iff_forall,\n    intros x,\n    induction x using quotient.induction_on',\n    dsimp only [from_Ico, from_real, function.comp_apply],\n    refine ⟨int.fract x, ⟨int.fract_nonneg _, le_of_lt $ int.fract_lt_one _⟩, _⟩,\n    rw quotient.eq',\n    rw [quotient_add_group.left_rel_eq, neg_add_eq_sub, int.self_sub_fract],\n    exact ⟨_, rfl⟩,\n  end }\n\n/--\nThe half open interval `[0, 1)` continuously bijects to `S¹`.\n-/\ndef equiv_Ico : set.Ico (0 : ℝ) 1 ≃ circle :=\nequiv.of_bijective from_Ico ⟨from_Ico_inj, from_Ico_surj⟩\n\n/--\nHowever, its inverse is not continuous.\n-/\nlemma not_cont_inv : ¬ continuous equiv_Ico.symm :=\nhave nc : ¬ compact_space (set.Ico (0 : ℝ) 1),\nbegin \n  intros r,\n  have seteq : (subtype.val : set.Ico (0 : ℝ) 1 → ℝ) '' set.univ = set.Ico 0 1,\n  { refine set.ext (λ x, ⟨_, _⟩),\n    { rintros ⟨y, ⟨⟨⟩, rfl⟩⟩, exact y.2 },\n    { rintros ⟨hx1, hx2⟩, exact ⟨⟨x, hx1, hx2⟩, ⟨⟩, rfl⟩, }, },\n  have c' : is_compact (set.Ico (0 : ℝ) 1),\n  { rw ←seteq, exact r.1.image (by continuity), },\n  have c'' := c'.is_closed.closure_eq,\n  rw [closure_Ico (by norm_num : (0 : ℝ) ≠ 1), set.ext_iff] at c'',\n  linarith [((c'' 1).mp ⟨zero_le_one, le_refl _⟩).2],\nend,\nbegin\n  contrapose! nc,\n  let i : homeomorph (set.Ico (0 : ℝ) 1) circle := \n  { continuous_to_fun := by continuity,\n    continuous_inv_fun := nc, ..equiv_Ico },\n  exact i.symm.compact_space,\nend\n\nend circle\n\nend topological_space\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/section10topological_stuffs.lean/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362849986365571, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.75199957682694}}
{"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\nimport tactic.interactive\n\nuniverse u\n\nnamespace eckmann_hilton\nvariables {X : Type u}\n\nlocal notation a `<`m`>` b := m a b\n\nclass is_unital (m : X → X → X) (e : X) : Prop :=\n(one_mul : ∀ x : X, (e <m> x) = x)\n(mul_one : ∀ x : X, (x <m> e) = x)\n\nlemma group.is_unital [G : group X] : is_unital (*) (1 : X) := { ..G }\n\nvariables {m₁ m₂ : X → X → X} {e₁ e₂ : X}\nvariables (h₁ : is_unital m₁ e₁) (h₂ : is_unital m₂ e₂)\nvariables (distrib : ∀ a b c d, ((a <m₂> b) <m₁> (c <m₂> d)) = ((a <m₁> c) <m₂> (b <m₁> d)))\ninclude h₁ h₂ distrib\n\nlemma one : e₁ = e₂ :=\nby simpa only [h₁.one_mul, h₁.mul_one, h₂.one_mul, h₂.mul_one] using distrib e₂ e₁ e₁ e₂\n\nlemma mul : (m₁ = m₂) :=\nbegin\n  funext a b,\n  calc m₁ a b = m₁ (m₂ a e₁) (m₂ e₁ b) :\n    by simp only [one h₁ h₂ distrib, h₁.one_mul, h₁.mul_one, h₂.one_mul, h₂.mul_one]\n          ... = m₂ a b :\n    by simp only [distrib, h₁.one_mul, h₁.mul_one, h₂.one_mul, h₂.mul_one]\nend\n\nlemma mul_comm : is_commutative _ m₂ :=\n⟨λ a b, by simpa [mul h₁ h₂ distrib, h₂.one_mul, h₂.mul_one] using distrib e₂ a b e₂⟩\n\nlemma mul_assoc : is_associative _ m₂ :=\n⟨λ a b c, by simpa [mul h₁ h₂ distrib, h₂.one_mul, h₂.mul_one] using distrib a b e₂ c⟩\n\ndef comm_monoid : comm_monoid X :=\n{ mul := m₂,\n  one := e₂,\n  mul_comm := (mul_comm h₁ h₂ distrib).comm,\n  mul_assoc := (mul_assoc h₁ h₂ distrib).assoc,\n  ..h₂ }\n\ndef comm_group [G : group X] (distrib : ∀ a b c d, ((a * b) <m₁> (c * d)) = ((a <m₁> c) * (b <m₁> d))) : comm_group X :=\n{ mul_comm := (eckmann_hilton.comm_monoid h₁ group.is_unital distrib).mul_comm,\n  ..G }\n\nend eckmann_hilton\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/group_theory/eckmann_hilton.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7519275035907919}}
{"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.fintype.card\nimport data.zmod.basic\nimport group_theory.exponent\nimport data.int.parity\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 ≠ 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`\nrepresents the rotations of the `n`-gon by `2πi/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 ≠ 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πi/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 : ℕ) : Type\n| r : zmod n → dihedral_group\n| sr : zmod n → dihedral_group\n\nnamespace dihedral_group\n\nvariables {n : ℕ}\n\n/--\nMultiplication of the dihedral group.\n-/\nprivate def mul : dihedral_group n → dihedral_group n → 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) := ⟨one⟩\n\n/--\nThe inverse of a an element of the dihedral group.\n-/\nprivate def inv : dihedral_group n → 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 ⊕ zmod n) ≃ dihedral_group n :=\n{ inv_fun := λ i, match i with\n                 | (r j) := sum.inl j\n                 | (sr j) := sum.inr j\n                 end,\n  to_fun := λ 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) := ⟨⟨r 0, sr 0, dec_trivial⟩⟩\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 [← fintype.card_eq.mpr ⟨fintype_helper⟩, fintype.card_sum, zmod.card, two_mul]\n\n@[simp] lemma r_one_pow (k : ℕ) : (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 ⟨nat.prime_two⟩ },\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 n.eq_zero_or_pos 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  { haveI := fact.mk hn,\n    apply (nat.le_of_dvd hn $ order_of_dvd_of_pow_eq_one $ @r_one_pow_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 [← 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 [fact (0 < n)] (i : zmod n) : order_of (r i) = n / nat.gcd n i.val :=\nbegin\n  conv_lhs { rw ←zmod.nat_cast_zmod_val i },\n  rw [←r_one_pow, order_of_pow, order_of_r_one]\nend\n\nlemma exponent : monoid.exponent (dihedral_group n) = lcm n 2 :=\nbegin\n  rcases n.eq_zero_or_pos with rfl | hn,\n  { exact monoid.exponent_eq_zero_of_order_zero order_of_r_one },\n  haveI := fact.mk hn,\n  apply nat.dvd_antisymm,\n  { apply monoid.exponent_dvd_of_forall_pow_eq_one,\n    rintro (m | m),\n    { rw [←order_of_dvd_iff_pow_eq_one, order_of_r],\n      refine nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2),\n      { exact (nat.div_mul_cancel (nat.gcd_dvd_left n m.val)).symm } },\n    { rw [←order_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": "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/specific_groups/dihedral.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7519275027177154}}
{"text": "-- Not related to the CFR project.\n-- The variance proof here was just a little thing I did in order to get familiar with Lean.\n\nimport data.rat\n\nvariable (α : Type)\n\ntheorem list.eq.identity : ∀ (l : list α), list.map id l = l\n    | [] := rfl\n    | (x :: l) := by simp [list.eq.identity l]\n\ndef mean (l : list rat) : rat := list.sum l / l.length\n@[simp] def sqr (x : rat) := x ^ 2\ntheorem sqr.eq.a_minus_b (a b : rat) : sqr (a - b) = sqr a - 2 * a * b + sqr b := by {unfold sqr, ring}\n\ndef E (f : rat -> rat) (l : list rat) := mean $ list.map f l\n\ndef var (l : list rat) (m : rat) := E (fun x, (x - m) ^ 2) l\ndef var' (l : list rat) (m : rat) := mean (list.map sqr l) - sqr m\n\ntheorem list.eq.sum_add (f g : rat → rat) : \n        ∀ (l : list rat), list.sum (list.map (λ x, f x + g x) l) = list.sum (list.map f l) + list.sum (list.map g l)\n    | [] := rfl\n    | (x :: l) := by simp [list.eq.sum_add]\n\ntheorem list.eq.sum_sub (f g : rat → rat) : \n        ∀ (l : list rat), list.sum (list.map (λ x, f x - g x) l) = list.sum (list.map f l) - list.sum (list.map g l)\n    | [] := rfl\n    | (x :: l) := by { \n        have := list.eq.sum_sub l,\n        simp [list.eq.sum_add] at ⊢ this, \n        assumption\n        }\n\ntheorem list.eq.sum_mul (c : rat) (f : rat → rat) : \n        ∀ (l : list rat), list.sum (list.map (λ x, c * f x) l) = c * list.sum (list.map f l)\n    | [] := by simp\n    | (x :: l) := by { simp, rw list.eq.sum_mul, ring }\n\ntheorem E.add {f g : rat -> rat} (l : list rat) : E (fun x, f x + g x) l = E f l + E g l :=\n    by { unfold E mean, simp only [list.length_map, list.eq.sum_add], ring }\n\ntheorem E.sub {f g : rat -> rat} (l : list rat) : E (fun x, f x - g x) l = E f l - E g l :=\n    by { unfold E mean, simp only [list.length_map, list.eq.sum_sub], ring }\n\ntheorem E.const_left {f : rat -> rat} (c : rat) (l : list rat) : E (fun x, c * f x) l = c * E f l :=\n    by { simp [E, mean], rw [list.eq.sum_mul], ring }\n\ntheorem rat.eq.mult_elim (n : rat) :  n / n = 1 ∨ n = 0 :=\n    if h : n = 0 then or.inr h\n    else or.inl $ div_self h\n\ntheorem list.eq.repeat (c : rat) (l : list rat) : list.sum (list.map (fun _, c) l) = c * list.length l :=\n    by { simp, rw add_monoid.smul_eq_mul _ c, ring }\n\ntheorem E.const_none (c : rat) : ∀ (x : rat) (l : list rat), E (fun x, c) (x :: l) = c\n    | x l := \n        by {\n            simp only [E, mean],\n            rw list.eq.repeat,\n            rw list.length_map,\n            simp,\n            from match rat.eq.mult_elim (1 + ↑(list.length l)) with\n            | or.inl is_one := by { \n                have := congr_arg (fun x, c * x) is_one, \n                simp at this,\n                ring at ⊢ this,\n                assumption\n                }\n            | or.inr is_zero := by {\n                ring at is_zero,\n                norm_cast at is_zero\n            }\n            end\n        }\n    \ntheorem E.const_right (c : rat) (l : list rat) : E (fun x, x * c) l = E id l * c :=\n    calc\n        E (fun x, x * c) l = E (fun x, c * x) l : by simp [mul_comm]\n        ... = c * E id l : by rw ← E.const_left; refl\n        ... = E id l * c : by rw mul_comm\n\ntheorem E.const_both (c c' : rat) (l : list rat) : E (fun x, c * x * c') l = c * E id l * c' :=\n    calc\n        E (fun x, c * x * c') l = E (fun x, c * (x * c')) l : by simp [mul_assoc]\n        ... = c * E (fun x, x * c') l : by rw E.const_left\n        ... = c * (E id l * c') : by rw E.const_right\n        ... = c * E id l * c' : by rw ← mul_assoc\n\ntheorem E.identity_is_mean (l : list rat) : E id l = mean l :=\n    calc\n        E id l = mean (list.map id l) : by unfold E\n        ... = mean l : by rw list.eq.identity\n\ntheorem E.sqr_split (m : rat) (x : rat) (xs : list rat) : E (fun x, (x - m) ^ 2) (x :: xs) = E (fun x, x ^ 2) (x :: xs) - 2 * mean (x :: xs) * m + m ^ 2 :=\n    let l := x :: xs in\n    calc \n        E (fun x, (x - m) ^ 2) l = E (fun x, x ^ 2 - 2 * x * m + m ^ 2) l : by ring\n        ... = E (fun x, x ^ 2) l - E (fun x, 2 * x * m) l + E (fun _, m ^ 2) l : by rw [E.add, E.sub]\n        ... = E (fun x, x ^ 2) l - 2 * E id l * m + m ^ 2 : by rw [E.const_both, E.const_none]\n        ... = E (fun x, x ^ 2) l - 2 * mean l * m + m ^ 2 : by rw [E.identity_is_mean]\n\ntheorem var_equals_var' : ∀ (l : list rat), var l (mean l) = var' l (mean l) \n    | [] := rfl\n    | l@(x :: xs) := \n        let m := mean l in\n        calc\n            var l m = E (fun x, (x - m) ^ 2) l : by unfold var\n            ... = E (fun x, x ^ 2) l - 2 * m * m + m ^ 2 : by rw E.sqr_split\n            ... = E (fun x, x ^ 2) l - 2 * (m * m) + m ^ 2 : by rw [mul_assoc]\n            ... = E (fun x, x ^ 2) l - 2 * m ^ 2 + m ^ 2 : by ring\n            ... = E (fun x, x ^ 2) l - m ^ 2 : by ring\n            ... = var' l m : by refl\n\n-- Is also known as MSE = variance + bias ^ 2 proof\ntheorem mean_is_global_minima_of_variance (m' : rat) : ∀ (l : list rat), var l (mean l) <= var l m'\n    | [] := by simp [var]\n    | l@(x :: xs) := \n        let m := mean l in\n        calc \n            var l m = E (fun x, (x - m) ^ 2) l : rfl\n            ... = E (fun x, x ^ 2) l - 2 * m * m + m ^ 2 : by rw E.sqr_split\n            ... <= E (fun x, x ^ 2) l - 2 * m * m' + m' ^ 2 : by { repeat {rw [sub_eq_add_neg, add_assoc]}, apply add_le_add_left, apply @le_of_add_le_add_right _ _ _ (m ^ 2), convert (pow_two_nonneg (m - m')); ring }\n            ... = E (fun x, (x - m') ^ 2) l : by rw ← E.sqr_split\n            ... = var l m' : rfl", "meta": {"author": "mrakgr", "repo": "CFR-in-Lean", "sha": "720a3260297bcc158e08833d38964450dcaad2eb", "save_path": "github-repos/lean/mrakgr-CFR-in-Lean", "path": "github-repos/lean/mrakgr-CFR-in-Lean/CFR-in-Lean-720a3260297bcc158e08833d38964450dcaad2eb/src/v0.1/dump/variance.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7519274940206179}}
{"text": "/- Proving question -/\n\ndef sum_to : Nat → Nat\n| 0 => 0\n| n + 1 => sum_to n + n + 1\n\ntheorem sum_to_eq (n : Nat) : 2 * sum_to n = n * (n + 1) := by\n  induction n with\n  | zero => rfl\n  | succ n ih =>\n    show 2 * (sum_to n + n + 1) = _\n    simp [Nat.mul_add, ih]\n    simp [Nat.succ_mul, Nat.add_succ, Nat.mul_succ, Nat.succ_add, Nat.add_assoc]\n\n/- Programming question -/\n\nstructure Run where\n  max : Nat\n  len : Nat\n  sum : Nat\n  best_len : Nat\n  best_sum : Nat\n\ndef Run.init : Run where\n  max := 0\n  len := 0\n  sum := 0\n  best_len := 0\n  best_sum := 0\n\ndef Run.commit (r : Run) : Run :=\n  if r.len ≥ 2 && r.len > r.best_len then\n    { r with best_len := r.len, best_sum := r.sum }\n  else\n    r\n\ndef Run.push (r : Run) (n : Nat) : Run :=\n  if r.max + 1 == n then\n    { r with\n      max := n,\n      len := r.len + 1,\n      sum := r.sum + n }\n  else\n    { r.commit with\n      max := n\n      len := 1\n      sum := n }\n\ndef Run.extract (r : Run) : Nat := r.commit.best_sum\n\ndef longest_consec_sublist_sum (l : List Nat) : Nat := (l.foldl Run.push Run.init).extract\n\n#eval longest_consec_sublist_sum [1, 2, 3, 100, 7, 8] -- 6\n#eval longest_consec_sublist_sum [1, 2, 3, 4, 100, 7, 8, 9, 10, 2, 3, 4, 5, 6] -- 20\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/kyle-miller-4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7519274921279653}}
{"text": "-- Las relaciones reflexivas y euclídeas son de equivalencia\n-- =========================================================\n\n-- ----------------------------------------------------\n-- Una relación binaria (≈) es euclídea si\n--    ∀ {a b c}, a ≈ b → c ≈ b → a ≈ c\n--\n-- El objetivo de esta teoría es demostrar que si una \n-- relación es reflexiva y euclídea, entonces es de \n-- equivalencia.\n-- ----------------------------------------------------\n\nimport tactic\n\nsection\n\nparameter {A : Type} \nparameter (R : A → A → Prop)\n\nlocal infix ≈ := R\n\nparameter reflexivaR : reflexive (≈)\nparameter euclideaR : ∀ {a b c}, a ≈ b → c ≈ b → a ≈ c\n\ninclude reflexivaR euclideaR \n\n-- ----------------------------------------------------\n-- Ej. 1. Demostrar que las relaciones reflexivas y \n-- y euclídeas son simétricas.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : symmetric (≈) :=\nbegin\n  intros a b h,\n  exact euclideaR (reflexivaR b) h,\nend\n\n-- 2ª demostración\nexample : symmetric (≈) :=\nλ a b h, euclideaR (reflexivaR b) h\n\n-- 3ª demostración\nlemma simetricaR : symmetric (≈) :=\nassume a b (h1 : a ≈ b),\nhave h2 : b ≈ b, from (reflexivaR b),\nshow b ≈ a, from euclideaR h2 h1\n\n-- ----------------------------------------------------\n-- Ej. 2. Demostrar que las relaciones reflexivas y \n-- y euclídeas son transitivas.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : transitive (≈) :=\nbegin\n  rintros a b c h1 h2,\n  apply euclideaR h1,\n  exact euclideaR (reflexivaR c) h2,\nend\n\n-- 2ª demostración\nlemma transitivaR : transitive (≈) :=\nλ a b c h1 h2, (euclideaR h1) (euclideaR (reflexivaR c) h2)\n\n-- 3ª demostración\nexample : transitive (≈) :=\nassume a b c (h1 : a ≈ b) (h2 : b ≈ c),\nhave h3 : c ≈ b, from euclideaR (reflexivaR c) h2,\nshow a ≈ c, from euclideaR h1 h3\n\n-- ----------------------------------------------------\n-- Ej. 3. Demostrar que las relaciones reflexivas y \n-- y euclídeas son de equivalencia.\n-- ----------------------------------------------------\n\n-- 1ª demostración\nexample : equivalence (≈) :=\nbegin\n  unfold equivalence,\n  exact ⟨reflexivaR, simetricaR, transitivaR⟩,\nend\n\n-- 2ª demostración\nexample : equivalence (≈) :=\n⟨reflexivaR, simetricaR, transitivaR⟩\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/4_Relaciones/Las_relaciones_reflexivas_y_euclideas_son_de_equivalencia.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7519274912548896}}
{"text": "import data.nat.prime\nimport data.rat.basic\nimport data.real.basic\nimport tactic\n\nnamespace uwyo -- hide\n\n/-\n# Chapter 1 : Basic facts\n\n## Level 1\n\nIn this level you need to prove that `sqrt 2` is irrational.\nThis is adapted from a similar proof from chapter 2 of \"logic and Proof\"\nby J. Avigad, R. Y. Lewis and F. van Doorn, freely available online.\n-/\n\n\n/- Lemma\nFor any two arbitrary natural numbers $a$ and $b$, it is not true that\n$$ a^2 = 2 b^2.$$\n-/\ntheorem sqrt_two_irrational {a b : ℕ} (co : nat.gcd a b = 1) : a^2 ≠ 2 * b^2 :=\nbegin\n    intro h,\n    have h1 : 2 ∣ a^2, simp [h],\n    have h2 : 2 ∣ 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 ∣ b^2, by simp [eq.symm h4],\n    have hb : 2 ∣ b, from nat.prime.dvd_of_dvd_pow nat.prime_two h5,\n    have ha : 2 ∣ a, from nat.prime.dvd_of_dvd_pow nat.prime_two h1,\n    have h6 : 2 ∣ nat.gcd a b, from nat.dvd_gcd ha hb,\n    have habs : 2 ∣ (1 : ℕ), by \n        {rw co at h6, exact h6},\n    have h7 : ¬ 2 ∣ 1, exact dec_trivial,\n    exact h7 habs, done\nend\n\nend uwyo -- hide\n", "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/level01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422241476943, "lm_q2_score": 0.7905303137346444, "lm_q1q2_score": 0.7519067608617443}}
{"text": "-- propositions\n-- proofs\n-- predicates\n    -- sets\n    -- relations\n    -- equality\n-- connectives\n    -- not\n    -- and\n    -- or\n\n\n-- proposition\ninductive nifty_was_a_cat : Prop\n-- proofs\n| there_are_pictures_of_nifty\n| we_remember_nifty_fondly\n\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 → Prop\n| nifty_proof : was_a_cat nifty\n| tom_proof : was_a_cat tom\n\nopen was_a_cat\n\ntheorem nwac : was_a_cat nifty := \n    nifty_proof\n\ntheorem cwac : was_a_cat cheese := _ \n\n/-\nProperty of a pet: that of having \nbeen a cat. Some have it. Some don't\n\na predicate defines a property of its argument type \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.\n\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 → Prop → Prop. This is just a\nProp parameterized by two Props, \nwhich we might call α and β. We\nneed a polymorphic type. \n-/\n\n#print and\n\nnamespace our_logic\n\n/-\nINTRODUCTION\n\nGiven proofs, α and β, we can build\na proof, (and.intro α β), of α ∧ β.\nHere are three ways to write exactly\nthe same inductive definition.\n-/\n\ninductive and'' (α β : Prop) : Prop\n| intro : α → β → and''\n\ninductive and' (α β : Prop) : Prop\n| intro (left : α) (right : β) : and'\n\nstructure and (a b : Prop) : Prop :=\nintro :: (left : a) (right : b)\n\n-- if you have only one data type, you can use structure\n-- building  data type with just one constructor  \n\ndef x := and (was_a_cat nifty) (was_a_cat tom) \n\ndef pf4 : x := and.intro nifty_proof tom_proof\n\n#reduce pf4.left\n#reduce pf4.right\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\n\n\ndef nwac_and_twac : Prop :=\n    and'' (was_a_cat nifty) (was_a_cat tom)\n\ndef pf2 : nwac_and_twac := \n    and''.intro nifty_proof tom_proof  \n\ndef pf3 : and'' (was_a_cat nifty) (was_a_cat tom) := \n    and''.intro nifty_proof tom_proof  \n\n#reduce pf2\n\n\n\ndef and''_elim_left {α β : Prop} : (and'' α β) → α \n| (and''.intro a b) := a \n\n#reduce and''_elim_left pf2\n\n\ndef and''_elim_right{α β : Prop} : (and'' α β) → β  \n| (and''.intro a b) := b \n\n#reduce and''_elim_right pf2\n\n\n\ninductive and' (α β : Prop) : Prop \n| intro (left : α) (right : β) : and' \n\n\nend our_logic\n\nnamespace our_logic \n\nnotation P ^ Q := and P Q   -- we don't overload ∧\n\ntheorem were_cats_nifty_and_cheese :\n    was_a_cat nifty ^ was_a_cat cheese :=\nbegin\n    apply and.intro _ _, -- don't need the _ _, implied \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\n\nIf we have a proof of P ^ Q, we can obtain\nindividual proofs of P and Q, respectively.\n-/\n\ndef and.elim_left {α β : Prop} : and α β → α\n| (and.intro a b) := a\n\ndef and.elim_right {α β : Prop} : and α β → β\n| (and.intro a b) := b\n\nend our_logic\n\n/-Now we[re using lean libraries-/\n-- PROPOSITIONS\ndef P1 : Prop := 0 = 0 -- propositions are types\ndef P2 : Prop := 1 = 1\n\n#check and P1 P2 \n\n-- PROOFS\n#check 0 = 0\n\n-- eq is a 2 place predicate. (its .equals equivalent from java)\n-- inductive eq {alpha : Tyoe}: α → α → Prop\n-- refl: α → eq α α \ndef p1 : P1 := eq.refl 0\ndef p2 : P2 := eq.refl 1\n\nexample: 1 = 1 + 0 := eq.refl 1\n\n/-\nProve 0 = 0. \n\nProof: equality is reflexive, this means that for any value a of any kind\nor type α , a = a. \n\n∀ {T:Type}, ∀ (t : T),  t = t.\nWe apply this axiom to 0 in particluar to derive a proof that 0 equals 0. \n\nthia ia called universal generalization. \n-/\n\ndef P1_and_P2' : Prop := and P1 P2\ndef P1_and_P2 : Prop := P1 ∧ P2\n\ndef p1_and_p2' : P1_and_P2 := and.intro p1 p2 \n\ndef p1_and_p2 : P1_and_P2 :=\nbegin\n    apply and.intro _ _,\n    exact p1,\n    exact p2,\nend\n\n#check p1_and_p2 \n\n#check and.elim_left p1_and_p2\n#check p1_and_p2.left\n\n#check and.elim_right p1_and_p2\n#check p1_and_p2.right \n\n#check @and.elim_left\n\ntheorem my_elim_left : ∀ (P1 P2 : Prop), P1 ∧ P2 → P1 := \nλ P1 P2 h, \n    match h with \n    | and.intro a b := a \n    end \n\n/-\nEnglish Language.\n\n\n-/\n\n/-\nIf we have a proof that nifty was a cat ∧\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 → \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/-\nLean provides exactly such this polymorphic\nlogical and connective. It's called \"and\" has\n∧ 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 ∧ 0 = 0 := \n    and.intro tom_proof (eq.refl 0)\n\n\nexample : was_a_cat tom ∧ 0 = 0 := \nbegin\n    apply and.intro tom_proof (eq.refl 0),\nend\n\nexample : was_a_cat tom ∧ 0 = 0 := \nbegin\n    apply and.intro tom_proof, -- arg as subgoal\n    exact (eq.refl 0)\nend\n\nexample : was_a_cat tom ∧ 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.\n\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 ∧ Q,\nfor example, then by applying one of the two\n\"and elimination\" axioms (rules of natural\ndeduction) to the proof of P ∧ Q, one can\nobtain either a proof of P, or a proof of Q. \n\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.\n\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.\n\nTheorem: For all propositions, P and Q,\n(P ∧ Q) → P. \n\nProof. Suppose that P and Q are arbitrary\nbut specific propositions. What remains to\nprove is that (P ∧ Q) → P. To prove this,\nassume we have a proof of P ∧ Q. Applying\nthe natural deduction principle of and \nelimination (left) yields of proof of P.\nQED. \n\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 : ∀ (P Q : Prop), P ∧ Q → P :=\n    λ P Q,\n        λ h, \n            and.elim_left h\n\ndef pf1' : ∀ (P Q : Prop), P ∧ Q → P :=\n    λ X Y,\n        λ 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 ∀ (P Q : Prop), P ∧ Q → P. \n\nWe use ∀ (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 ∧ Q → P. \n\nWe thus have the overall proposition: for \n*any* propositions, P and Q, if P ∧ Q (is\ntrue, has a proof) then P (is true, has a\nproof), i.e., P ∧ Q → P. In curt English: \n\"If P ∧ Q then P.\"\n\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 ∧ Q. \n\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.\n\nWe wrote the formal proof of ∀ (P Q : Prop), \nP ∧ Q → 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.\n\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 ∧ 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 : ∀ (P Q : Prop), P ∧ Q → P :=\nbegin\n    assume (X Y : Prop),    \n    assume (h : X ∧ Y),\n    exact and.elim_left h,\nend\n\n-- proof script, args already assumed\ndef pf4 (P Q : Prop) (h : P ∧ Q) : P :=\nbegin -- look: arguments are assumptions\n    exact and.elim_left h,\nend\n\n-- using cases notation\ndef pf5 : ∀ (P Q : Prop), P ∧ Q → P\n| P Q h := and.elim_left h\n\n/-\nFalse Elimination: ∀ (P : Prop), false → 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. \n\nA clear example involves the proof that\n\"false implies (the truth of) anything\".\nFormally: ∀ (P : Prop), false → 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 → 0 = 1)\neven though one can never produce a proof\nof false. The truth of (false → 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 → 0 = 1 :=\n    λ h, false.elim h\n\ntheorem false_elim_example' (h : false) : 0 = 1 :=\n    false.elim h\n\nexample : false → 0 = 1 := λ h, false.elim h\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/Notes/2019.11.05.Prop.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.751894003235131}}
{"text": "-- aplicaciones.lean\n-- Aplicaciones inyectivas. suprayectivas y biyectivas.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 16-junio-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 1. Importar la librería de tácticas-\n-- ---------------------------------------------------------------------\n\nimport tactic\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 2. Abrir la lógica clásica.\n-- ---------------------------------------------------------------------\n\nopen classical  \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 3. Declarar X, Y y Z variables de tipo-\n-- ---------------------------------------------------------------------\n\nvariables {X Y Z : Type*}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 4. Definir la función es_inyectiva tal (es_inyectiva f)\n-- expresa que f es inyectiva.\n-- ---------------------------------------------------------------------\n\ndef es_inyectiva \n  (f : X → Y) := \n  ∀ x x', f x = f x' → x = x'\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 5. Definir la función es_suprayectiva tal (es_suprayectiva f)\n-- expresa que f es suprayectiva.\n-- ---------------------------------------------------------------------\n\ndef es_suprayectiva \n  (f : X → Y) := \n  ∀ y, ∃ x, f x = y  \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 6. Definir la función es_biyectiva tal (es_biyectiva f)\n-- expresa que f es biyectiva.\n-- ---------------------------------------------------------------------\n\ndef es_biyectiva\n  (f : X → Y) := \n  es_inyectiva f ∧ es_suprayectiva f    \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 7. Demostrar que las funciones biyectivas son inyectivas.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {f : X → Y}\n  (f_biyectiva : es_biyectiva f)\n  : es_inyectiva f := \nand.elim_left f_biyectiva\n\n-- 2ª demostración\n-- ===============\n\nlemma biy_iny\n  {f : X → Y}\n  (f_biyectiva: es_biyectiva f)\n  : es_inyectiva f := \nf_biyectiva.1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 8. Demostrar que las funciones biyectivas son suprayectivas.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {f : X → Y}\n  (f_biyectiva : es_biyectiva f)\n  : es_suprayectiva f := \nand.elim_right f_biyectiva\n\n-- 2ª demostración\n-- ===============\n\nlemma biy_supr\n  {f : X → Y}\n  (f_biyectiva : es_biyectiva f)\n  : es_suprayectiva f := \nf_biyectiva.2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 9. Demostrar que si f es suprayectiva e inyectiva, entonces\n-- es biyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {f : X → Y}\n  (f_suprayectiva : es_suprayectiva f)\n  (f_inyectiva : es_inyectiva f)\n  : es_biyectiva f :=\nand.intro f_inyectiva f_suprayectiva\n\n-- 2ª demostración\n-- ===============\n\nlemma supr_iny_biy\n  {f : X → Y}\n  (f_suprayectiva : es_suprayectiva f)\n  (f_inyectiva : es_inyectiva f)\n  : es_biyectiva f :=\n⟨f_inyectiva, f_suprayectiva⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 10. Demostrar que si (g ∘ f) es inyectiva, entonces f es\n-- inyectiva. \n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  {f : X → Y}\n  {g : Y → Z}\n  (gf_inyectiva : es_inyectiva (g ∘ f))\n  : es_inyectiva f :=  \nbegin\n  intros x x' f_xx',\n  apply gf_inyectiva,\n  simp [f_xx'],\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma iny_comp_iny_primera \n  {f : X → Y}\n  {g : Y → Z}\n  (gf_inyectiva : es_inyectiva (g ∘ f))\n  : es_inyectiva f :=  \nbegin\n  assume x  : X, \n  assume x' : X, \n  assume f_xx' : f x = f x',\n  have gf_xx' : (g ∘ f) x = (g ∘ f) x', from \n    calc (g ∘ f) x = g (f x)    : by simp\n               ... = g (f x')   : by simp [f_xx']\n               ... = (g ∘ f) x' : by simp,\n  show x = x', \n    { apply gf_inyectiva, \n      apply gf_xx'},\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 11. Demostrar que si (g ∘ f) es suprayectiva, entonces f es\n-- suprayectiva. \n-- ---------------------------------------------------------------------\n\nlemma supr_comp_supr_segunda\n  {f : X → Y}\n  {g : Y → Z}\n  (gf_suprayectiva : es_suprayectiva (g ∘ f))\n  : es_suprayectiva g  := \nbegin\n  assume z : Z,\n  rcases gf_suprayectiva z with ⟨ x : X, gf_x_z : (g ∘ f) x = z⟩,\n  let y : Y := f x,\n  use y,\n  show g y = z, from\n    calc g y = g (f x)   : by simp\n         ... = (g ∘ f) x : by simp\n         ... = z         : by exact gf_x_z,\nend  \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 12. Demostrar que si (f ∘ f) es biyectiva, entonces f es\n-- biyectiva. \n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (f : X → X)\n  (ff_biyectiva : es_biyectiva (f ∘ f))\n  : es_biyectiva f :=\nbegin\n  apply supr_iny_biy,\n  { apply supr_comp_supr_segunda,\n    apply biy_supr,\n    exact ff_biyectiva, },\n  { apply iny_comp_iny_primera,\n    apply biy_iny,\n    exact ff_biyectiva, },\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma cuadrado_biy_biy\n  (f : X → X)\n  (ff_biyectiva : es_biyectiva (f ∘ f))\n  : es_biyectiva f :=\nbegin\n  have f_inyectiva : es_inyectiva f, from\n    begin\n      have ff_inyectiva : es_inyectiva (f ∘ f), \n        by exact biy_iny ff_biyectiva,\n      show _,\n        by exact iny_comp_iny_primera ff_inyectiva,\n    end,\n  have f_suprayectiva: es_suprayectiva f, from\n    begin\n      have ff_suprayectiva : es_suprayectiva (f ∘ f),\n        by exact biy_supr ff_biyectiva,\n      show _,\n        by exact supr_comp_supr_segunda ff_suprayectiva,     \n    end,\n  show es_biyectiva f, \n    by exact supr_iny_biy f_suprayectiva f_inyectiva,\nend      \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 13. Definir el tipo A con los constructores A1, A2 y A3.\n-- ---------------------------------------------------------------------\n\ninductive A : Type\n  | A1\n  | A2\n  | A3\n\nopen A\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 14. Definir la función\n--   f ; A -> A\n-- tal que \n--   f A1 = A1, \n--   f A2 = A1 y\n--   f A3 = A2.\n-- ---------------------------------------------------------------------\n\ndef f : A → A\n  | A1 := A1\n  | A2 := A1\n  | A3 := A2\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 15. Demostrar que f no es inyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : ¬ es_inyectiva f :=\nbegin\n  unfold es_inyectiva,\n  simp,\n  use [A1, A2],\n  split,\n  { dsimp [f],\n    refl, },\n  { simp, },\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma f_no_iny \n  : ¬ es_inyectiva f :=\nbegin\n  let x  := A1,\n  let x' := A2,\n  have f_xx'_x_diferente_x' : f x = f x' ∧ x ≠ x', from\n    begin\n      have f_xx' : f x  = f x', by simp [f],\n      have x_diferente_x' :  x ≠ x', by finish,\n      show _, by exact and.intro f_xx' x_diferente_x',\n    end,\n  show ¬ es_inyectiva f, from\n    begin\n      simp only [es_inyectiva, not_forall], \n      use x,\n      use x',\n      exact f_xx'_x_diferente_x',\n    end\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 16. Demostrar que f no es suprayectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : ¬ es_suprayectiva f:=\nbegin\n  unfold es_suprayectiva,\n  rw not_forall,\n  use A3,\n  rw not_exists,\n  intro x,\n  cases x,\n  { simp [f], },\n  { simp [f], },\n  { simp [f], },\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  : ¬ es_suprayectiva f:=\nbegin\n  unfold es_suprayectiva,\n  push_neg,\n  use A3,\n  intro x,\n  cases x; finish,\nend\n\n-- 3ª demostración\n-- ===============\n\nlemma f_no_es_supr\n  : ¬ es_suprayectiva f:=\nbegin\n  simp only [es_suprayectiva, not_forall],\n  show ∃ y : A, ¬(∃ x : A, f x = y), by\n    begin\n      use A3,\n      have A3_no_es_imagen : ∀ x : A, ¬ f x = A3, from\n        begin\n          assume x : A,\n          cases x,\n            case A1 : {simp [f] }, \n            case A2 : {simp [f] },\n            case A3 : {simp [f] },\n        end,\n      show _, \n        by {simp only [not_exists], exact A3_no_es_imagen}\n    end \nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 17. Definir el tipo B con los constructores B1 y B2.\n-- ---------------------------------------------------------------------\n\ninductive B \n  | B1\n  | B2\n\nopen B\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 18. Definir la función \n--    g : B → B\n-- tal que \n--    g B1 = B2 \n--    g B2 = B1\n-- ---------------------------------------------------------------------\n\ndef g : B → B\n  | B1 := B2\n  | B2 := B1\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 19. Demostrar que g es biyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : es_biyectiva g := \nbegin\n  apply supr_iny_biy,\n  { unfold es_suprayectiva,\n    intro y,\n    cases y,\n    { use B2,\n      simp [g], },\n    { use B1,\n      simp [g], }},\n  { unfold es_inyectiva,\n    intros x x' gxx',\n    cases x,\n    { cases x',\n      { refl, },\n      { dsimp [g] at gxx',\n        rw gxx', }},\n    { cases x',\n      { dsimp [g] at gxx',\n        rw gxx', },\n      { refl, }}},\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma g_es_biyectiva \n  : es_biyectiva g := \nbegin\n  have g_es_inyectiva : es_inyectiva g, from \n    begin\n      assume x  : B,\n      assume x' : B,\n      assume g_xx' : g x = g x',\n      cases x,\n        case B1 : begin cases x', finish, finish end,\n        case B2 : begin cases x', finish, finish end,\n    end,\n  have g_es_suprayectiva : es_suprayectiva g, from\n    begin\n      assume y : B,\n      cases y,\n        case B1 : begin use B2, finish end,\n        case B2 : begin use B1, finish end,\n    end,\n  show _,\n    by exact supr_iny_biy g_es_suprayectiva g_es_inyectiva\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 20. Definir el conjunto conj_123 cuyos elementos son los\n-- números naturales 1, 2 y 3.\n-- ---------------------------------------------------------------------\n\ndef conj_123 : set ℕ := \n  {1,2,3}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 21. Demostrar que\n--    1 ∈ conj_123\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : 1 ∈ conj_123  :=\nbegin\n  fconstructor,\n  refl,\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma uno_en_123 : 1 ∈ conj_123 := \nby {fconstructor, refl}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 22. Demostrar que\n--    2 ∈ conj_123\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : 2 ∈ conj_123  :=\nbegin\n  apply or.inr,\n  fconstructor,\n  refl,\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma dos_en_123 : 2 ∈ conj_123 := \nby {apply or.inr, simp}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 23. Demostrar que\n--    3 ∈ conj_123\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample : 3 ∈ conj_123  :=\nbegin\n  apply or.inr,\n  apply or.inr,\n  fconstructor,\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma tres_en_123 : 3 ∈ conj_123 := \nby {apply or.inr, simp}\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 24. Definir la función\n--    const1 : conj_123 → conj_123 \n-- que aplica todos los elementos en el 1.\n-- ---------------------------------------------------------------------\n\ndef const1 : conj_123 → conj_123 := \nλ ⟨x, _⟩, ⟨1, uno_en_123⟩ \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 25. Definir la función \n--    h : conj_123 → conj_123\n-- que aplica el 3 en el 2 y los demás en el 1.\n-- ---------------------------------------------------------------------\n\ndef h : conj_123 → conj_123 := \nλ ⟨x, x_in_123⟩, \n  if x = 3 then ⟨ 2, dos_en_123 ⟩\n           else ⟨ 1, uno_en_123 ⟩\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 26. Demostrar que h no es inyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : ¬ es_inyectiva h :=\nbegin\n  unfold es_inyectiva,\n  push_neg,\n  let x1 : ↥conj_123 := ⟨ 1, uno_en_123 ⟩,\n  let x2 : ↥conj_123 := ⟨ 2, dos_en_123 ⟩,\n  use [x1, x2],\n  split,\n  { simp [h], },\n  { simp, },\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma h_no_es_inyectiva \n  : ¬ es_inyectiva h :=\nbegin\n  let x1 : ↥conj_123 := ⟨ 1, uno_en_123 ⟩,\n  let x2 : ↥conj_123 := ⟨ 2, dos_en_123 ⟩,\n  refine not_forall.mpr _,\n  use x1,\n  refine not_forall.mpr _,\n  use x2,\n  finish,\nend\n\n-- =====================================================================\n-- § Ejercicios complementarios\n-- =====================================================================\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 27. Definir la aplicación identidad\n-- ---------------------------------------------------------------------\n\ndef apl_id \n  (X : Type*)\n  : X → X := \nλ x, x\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 28. Demostrar que la aplicación identidad es biyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (X : Type*)\n  : es_biyectiva (apl_id X) :=\nbegin\n  apply supr_iny_biy,\n  { unfold es_suprayectiva,\n    intro y,\n    use y,\n    simp [apl_id], },\n  { unfold es_inyectiva,\n    intros x x' f_xx',\n    simp [apl_id] at f_xx',\n    exact f_xx', },\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma id_biyectiva \n  (X : Type*)\n  : es_biyectiva (apl_id X) :=\nbegin\n  let f : X → X := apl_id X,\n  have id_iny : es_inyectiva f, from\n    begin\n      assume x x' : X,\n      assume f_xx' : f x = f x',\n      show x = x', by \n        calc x = f x  : by refl\n           ... = f x' : by simp [f_xx']\n           ... = x'   : by refl,\n    end,\n  have id_supr : es_suprayectiva f, from\n    begin\n      assume y : X,\n      use y,\n      show f y = y, by refl,\n    end,\n  show _, \n    by exact supr_iny_biy id_supr id_iny,\nend  \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 29. Demostrar que la composición de funciones inyectivas\n-- es inyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (f : X → Y)\n  (g : Y → Z)\n  (f_inyectiva : es_inyectiva f)\n  (g_inyectiva : es_inyectiva g)\n  : es_inyectiva (g ∘ f) :=\nbegin\n  unfold es_inyectiva,\n  intros x x' gf_xx',\n  apply f_inyectiva,\n  apply g_inyectiva,\n  calc g (f x) = (g ∘ f) x  : rfl\n           ... = (g ∘ f) x' : gf_xx'\n           ... = g (f x')   : rfl\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma comp_iny_es_iny \n  (f : X → Y)\n  (g : Y → Z)\n  (f_inyectiva : es_inyectiva f)\n  (g_inyectiva : es_inyectiva g)\n  : es_inyectiva (g ∘ f) :=\nbegin\n  assume x x' : X,\n  assume gf_xx' : (g ∘ f) x = (g ∘ f) x',\n  show x = x', by\n    begin\n      have f_xx' : f x = f x', from\n        begin\n          have g_fxfx' : g (f x) = g (f x'), from\n            calc g (f x) = (g ∘ f) x  : by simp\n                     ... = (g ∘ f) x' : by simp[gf_xx']\n                     ... = g (f x')   : by simp,\n          show _, \n            by {apply g_inyectiva, apply g_fxfx'},\n        end, \n      show _, \n        by {apply f_inyectiva, apply f_xx'},\n    end\nend      \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 30. Sea f : X → Y tal que existen x, x' ∈ X tales que \n-- x ≠ x' y f x = f x'. Demostrar que f no es inyectiva.\n-- ---------------------------------------------------------------------\n\nlemma CS_inyectiva \n  (f : X → Y)\n  (x : X)\n  (x' : X)\n  (x_neq_x' : x ≠ x')\n  (f_xx' : f x = f x')\n  : ¬ es_inyectiva f := \nbegin\n  simp only [es_inyectiva, not_forall],\n  use [x, x'], \n  finish,\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 31.  Usar el lema anterior para demostrar que f no es\n-- inyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : ¬ es_inyectiva f :=\nbegin\n  apply CS_inyectiva f A1 A2,\n  { trivial, },\n  { simp [f] },\nend\n\n\n-- 2ª demostración\n-- ===============\n\nexample\n  : ¬ es_inyectiva f :=\nbegin\n  let x  : A := A1,\n  let x' : A := A2,\n  have x_diferente_x' : x ≠ x', by finish,\n  have f_xx' : f x = f x', by refl,\n  show _, \n    by exact (CS_inyectiva f x x' x_diferente_x' f_xx'),\nend\n\n-- ---------------------------------------------------------------------\n-- Ejercicio 32. Demostrar que (g ∘ g = id).\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : g ∘ g = apl_id B :=\nbegin\n  ext1,\n  simp [apl_id],\n  cases x,\n  { calc g (g B1) = g B2 : by simp [g]\n              ... = B1   : by simp [g] },\n  { calc g (g B2) = g B1 : by simp [g]\n              ... = B2   : by simp [g] },\nend\n\n-- 2ª demostración\n-- ===============\n\nlemma gg_id \n  : g ∘ g = apl_id B :=\nbegin\n  have g_id : ∀ x : B, (g ∘ g) x = apl_id B x, from\n    begin\n       assume x : B,\n       cases x,\n         {finish},\n         {finish},\n    end,\n  show _, by {ext1, tauto},\nend    \n\n-- ---------------------------------------------------------------------\n-- Ejercicio 33. Demostrar que g es biyectiva.\n-- ---------------------------------------------------------------------\n\n-- 1ª demostración\n-- ===============\n\nexample\n  : es_biyectiva g :=\nbegin\n  apply cuadrado_biy_biy g,\n  convert id_biyectiva B,\n  exact gg_id,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  : es_biyectiva g :=\nbegin\n  have gg_biy : es_biyectiva (g ∘ g), from\n    begin\n      have gg_id : g ∘ g = apl_id B, by exact gg_id,\n      show _, by {simp only [gg_id], apply id_biyectiva B},\n    end, \n  show _, by exact (cuadrado_biy_biy g gg_biy),\nend    \n\n-- Referencia\n-- ==========\n\n-- Basado en \"Injective, surjective, bijective maps\" de Clara Löh que se\n-- encuentra en https://bit.ly/3xzYqun\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/aplicaciones.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7518387789870172}}
{"text": "/-\nCopyright (c) 2018 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, 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\nimport data.finset.noncomm_prod\n\n/-!\n# Submonoids: membership criteria\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 ∈ S` where `S` is a multiplicative (resp., additive) submonoid and\n  `n` is a natural number, then `x^n` (resp., `n • 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 : _ →* 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 : _ →* M).map_multiset_prod m\n\n@[simp, norm_cast, to_additive] theorem coe_finset_prod {ι M} [comm_monoid M] [set_like B M]\n  [submonoid_class B M] (f : ι → S) (s : finset ι) :\n  ↑(∏ i in s, f i) = (∏ i in s, f i : M) :=\n(submonoid_class.subtype S : _ →* M).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 : ∀ x ∈ l, x ∈ S) : l.prod ∈ S :=\nby { lift l to list S using hl, rw ← 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 : ∀ a ∈ m, a ∈ S) : m.prod ∈ S :=\nby { lift m to multiset S using hm, rw ← 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  {ι : Type*} {t : finset ι} {f : ι → M} (h : ∀c ∈ t, f c ∈ S) :\n  ∏ c in t, f c ∈ S :=\nmultiset_prod_mem (t.1.map f) $ λ x hx, let ⟨i, hi, hix⟩ := multiset.mem_map.1 hx in hix ▸ h i hi\n\nend submonoid_class\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 {ι M} [comm_monoid M] (S : submonoid M)\n  (f : ι → S) (s : finset ι) :\n  ↑(∏ i in s, f i) = (∏ 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 : ∀ x ∈ l, x ∈ s) : l.prod ∈ s :=\nby { lift l to list s using hl, rw ← 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 : ∀ a ∈ m, a ∈ S) : m.prod ∈ S :=\nby { lift m to multiset S using hm, rw ← coe_multiset_prod, exact m.prod.coe_prop }\n\n@[to_additive]\nlemma multiset_noncomm_prod_mem (S : submonoid M) (m : multiset M)\n  (comm : ∀ (x ∈ m) (y ∈ m), commute x y) (h : ∀ (x ∈ m), x ∈ S) :\n  m.noncomm_prod comm ∈ 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  {ι : Type*} {t : finset ι} {f : ι → M} (h : ∀c ∈ t, f c ∈ S) :\n  ∏ c in t, f c ∈ S :=\nS.multiset_prod_mem (t.1.map f) $ λ x hx, let ⟨i, hi, hix⟩ := multiset.mem_map.1 hx in hix ▸ h i hi\n\n@[to_additive]\nlemma noncomm_prod_mem (S : submonoid M) {ι : Type*} (t : finset ι) (f : ι → M)\n  (comm : ∀ (x ∈ t) (y ∈ t), commute (f x) (f y)) (h : ∀ c ∈ t, f c ∈ S) :\n  t.noncomm_prod f comm ∈ S :=\nbegin\n  apply multiset_noncomm_prod_mem,\n  intro y,\n  rw multiset.mem_map,\n  rintros ⟨x, ⟨hx, rfl⟩⟩,\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 {ι} [hι : nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S)\n  {x : M} :\n  x ∈ (⨆ i, S i) ↔ ∃ i, x ∈ S i :=\nbegin\n  refine ⟨_, λ ⟨i, hi⟩, (set_like.le_def.1 $ le_supr S i) hi⟩,\n  suffices : x ∈ closure (⋃ i, (S i : set M)) → ∃ i, x ∈ S i,\n    by simpa only [closure_Union, closure_eq (S _)] using this,\n  refine (λ hx, closure_induction hx (λ _, mem_Union.1) _ _),\n  { exact hι.elim (λ i, ⟨i, (S i).one_mem⟩) },\n  { rintros x y ⟨i, hi⟩ ⟨j, hj⟩,\n    rcases hS i j with ⟨k, hki, hkj⟩,\n    exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ }\nend\n\n@[to_additive]\nlemma coe_supr_of_directed {ι} [nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S) :\n  ((⨆ i, S i : submonoid M) : set M) = ⋃ i, ↑(S i) :=\nset.ext $ λ 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 (≤) S) {x : M} :\n  x ∈ Sup S ↔ ∃ s ∈ S, x ∈ 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 (≤) S) :\n  (↑(Sup S) : set M) = ⋃ s ∈ S, ↑s :=\nset.ext $ λ x, by simp [mem_Sup_of_directed_on Sne hS]\n\n@[to_additive]\nlemma mem_sup_left {S T : submonoid M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T :=\nshow S ≤ S ⊔ T, from le_sup_left\n\n@[to_additive]\nlemma mem_sup_right {S T : submonoid M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T :=\nshow T ≤ S ⊔ T, from le_sup_right\n\n@[to_additive]\nlemma mul_mem_sup {S T : submonoid M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=\n(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)\n\n@[to_additive]\nlemma mem_supr_of_mem {ι : Sort*} {S : ι → submonoid M} (i : ι) :\n  ∀ {x : M}, x ∈ S i → x ∈ supr S :=\nshow S i ≤ supr S, from le_supr _ _\n\n@[to_additive]\nlemma mem_Sup_of_mem {S : set (submonoid M)} {s : submonoid M}\n  (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ Sup S :=\nshow s ≤ Sup S, from le_Sup hs\n\n/-- An induction principle for elements of `⨆ 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 `⨆ 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 {ι : Sort*} (S : ι → submonoid M) {C : M → Prop} {x : M} (hx : x ∈ ⨆ i, S i)\n  (hp : ∀ i (x ∈ S i), C x)\n  (h1 : C 1)\n  (hmul : ∀ x y, C x → C y → C (x * y)) : C x :=\nbegin\n  rw supr_eq_closure at hx,\n  refine closure_induction hx (λ x hx, _) h1 hmul,\n  obtain ⟨i, hi⟩ := 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' {ι : Sort*} (S : ι → submonoid M) {C : Π x, (x ∈ ⨆ i, S i) → Prop}\n  (hp : ∀ i (x ∈ S i), C x (mem_supr_of_mem i ‹_›))\n  (h1 : C 1 (one_mem _))\n  (hmul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem _ ‹_› ‹_›))\n  {x : M} (hx : x ∈ ⨆ i, S i) : C x hx :=\nbegin\n  refine exists.elim _ (λ (hx : x ∈ ⨆ i, S i) (hc : C x hx), hc),\n  refine supr_induction S hx (λ i x hx, _) _ (λ x y, _),\n  { exact ⟨_, hp _ _ hx⟩ },\n  { exact ⟨_, h1⟩ },\n  { rintro ⟨_, Cx⟩ ⟨_, Cy⟩,\n    refine ⟨_, hmul _ _ _ _ Cx Cy⟩ },\nend\n\nend submonoid\n\nend non_assoc\n\nnamespace free_monoid\n\nvariables {α : Type*}\n\nopen submonoid\n\n@[to_additive]\ntheorem closure_range_of : closure (set.range $ @of α) = ⊤ :=\neq_top_iff.2 $ λ x hx, free_monoid.rec_on x (one_mem _) $ λ 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 ⟨multiplicative.of_add 1, pow_one x⟩) $\n  λ x ⟨n, hn⟩, hn ▸ submonoid.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 ∈ closure ({x} : set M) ↔ ∃ n:ℕ, x^n=y :=\nby rw [closure_singleton_eq, mem_mrange]; refl\n\nlemma mem_closure_singleton_self {y : M} : y ∈ closure ({y} : set M) :=\nmem_closure_singleton.2 ⟨1, pow_one y⟩\n\nlemma closure_singleton_one : closure ({1} : set M) = ⊥ :=\nby simp [eq_bot_iff_forall, mem_closure_singleton]\n\n@[to_additive]\nlemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift (coe : s → M)).mrange :=\nby rw [mrange_eq_map, ← free_monoid.closure_range_of, map_mclosure, ← set.range_comp,\n  free_monoid.lift_comp_of, subtype.range_coe]\n\n@[to_additive]\nlemma exists_list_of_mem_closure {s : set M} {x : M} (hx : x ∈ closure s) :\n  ∃ (l : list M) (hl : ∀ y ∈ l, y ∈ s), l.prod = x :=\nbegin\n  rw [closure_eq_mrange, mem_mrange] at hx,\n  rcases hx with ⟨l, hx⟩,\n  exact ⟨list.map coe l, λ y hy, let ⟨z, hz, hy⟩ := list.mem_map.1 hy in hy ▸ z.2, hx⟩\nend\n\n@[to_additive]\nlemma exists_multiset_of_mem_closure {M : Type*} [comm_monoid M] {s : set M}\n  {x : M} (hx : x ∈ closure s) : ∃ (l : multiset M) (hl : ∀ y ∈ l, y ∈ s), l.prod = x :=\nbegin\n  obtain ⟨l, h1, h2⟩ := exists_list_of_mem_closure hx,\n  exact ⟨l, h1, (multiset.coe_prod l).trans h2⟩,\nend\n\n@[to_additive]\nlemma closure_induction_left {s : set M} {p : M → Prop} {x : M} (h : x ∈ closure s) (H1 : p 1)\n  (Hmul : ∀ (x ∈ s) y, p y → p (x * y)) : p x :=\nbegin\n  rw closure_eq_mrange at h,\n  obtain ⟨l, rfl⟩ := 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@[to_additive]\nlemma closure_induction_right {s : set M} {p : M → Prop} {x : M} (h : x ∈ closure s) (H1 : p 1)\n  (Hmul : ∀ x (y ∈ s), p x → p (x * y)) : p x :=\n@closure_induction_left _ _ (mul_opposite.unop ⁻¹' s) (p ∘ mul_opposite.unop) (mul_opposite.op x)\n  (closure_induction h (λ x hx, subset_closure hx) (one_mem _) (λ x y hx hy, mul_mem _ hy hx))\n  H1 (λ x hx y, Hmul _ _ hx)\n\n/-- The submonoid generated by an element. -/\ndef powers (n : M) : submonoid M :=\nsubmonoid.copy (powers_hom M n).mrange (set.range ((^) n : ℕ → M)) $\nset.ext (λ n, exists_congr $ λ i, by simp; refl)\n\n@[simp] lemma mem_powers (n : M) : n ∈ powers n := ⟨1, pow_one _⟩\n\nlemma mem_powers_iff (x z : M) : x ∈ powers z ↔ ∃ n : ℕ, 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 ∈ P) : powers n ≤ P :=\nλ x hx, match x, hx with _, ⟨i, rfl⟩ := P.pow_mem h i end\n\n/-- Exponentiation map from natural numbers to powers. -/\n@[simps] def pow (n : M) (m : ℕ) : powers n :=\n(powers_hom M n).mrange_restrict (multiplicative.of_add m)\n\nlemma pow_apply (n : M) (m : ℕ) : submonoid.pow n m = ⟨n ^ m, m, rfl⟩ := rfl\n\n/-- Logarithms from powers to natural numbers. -/\ndef log [decidable_eq M] {n : M} (p : powers n) : ℕ :=\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 (λ m : ℕ, n ^ m) ↔ 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 (λ m : ℕ, n ^ m))\n  (m : ℕ) : 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 (λ m : ℕ, n ^ m)) :\n  multiplicative ℕ ≃* powers n :=\n{ to_fun := λ m, pow n m.to_add,\n  inv_fun := λ m, multiplicative.of_add (log m),\n  left_inv := log_pow_eq_self h,\n  right_inv := pow_log_eq_self,\n  map_mul' := λ _ _, by { simp only [pow, map_mul, of_add_add, to_add_mul] } }\n\nlemma log_mul [decidable_eq M] {n : M} (h : function.injective (λ m : ℕ, 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 : ℤ} (h : 1 < x.nat_abs) (m : ℕ) : 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*} [monoid N] (f : M →* N) (m : M) :\n  (powers m).map f = powers (f m) :=\nby simp only [powers_eq_closure, f.map_mclosure, 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 : ∀ (a ∈ s) (b ∈ s), a * b = b * a) :\n  comm_monoid (closure s) :=\n{ mul_comm := λ x y,\n  begin\n    ext,\n    simp only [submonoid.coe_mul],\n    exact closure_induction₂ x.prop y.prop hcomm\n      (λ x, by simp only [mul_one, one_mul])\n      (λ x, by simp only [mul_one, one_mul])\n      (λ x y z h₁ h₂, by rw [mul_assoc, h₂, ←mul_assoc, h₁, mul_assoc])\n      (λ x y z h₁ h₂, by rw [←mul_assoc, h₁, mul_assoc, h₂, ←mul_assoc]),\n  end,\n  ..(closure s).to_monoid }\n\nend submonoid\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 ⊔ t = (s.subtype.coprod t.subtype).mrange :=\nby rw [mrange_eq_map, ← 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 ∈ s ⊔ t ↔ ∃ (y ∈ s) (z ∈ 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 ⟨1, one_nsmul x⟩) $\n  λ x ⟨n, hn⟩, hn ▸ 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 ∈ closure ({x} : set A) ↔ ∃ n:ℕ, n • x = y :=\nby rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl\n\nlemma closure_singleton_zero : closure ({0} : set A) = ⊥ :=\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 (λ i, i • x : ℕ → A)) $\nset.ext (λ n, exists_congr $ λ i, by simp; refl)\n\n@[simp] lemma mem_multiples (x : A) : x ∈ multiples x := ⟨1, one_nsmul _⟩\n\nlemma mem_multiples_iff (x z : A) : x ∈ multiples z ↔ ∃ n : ℕ, n • z = x := iff.rfl\n\nlemma multiples_eq_closure (x : A) : multiples x = closure {x} :=\nby { ext, exact mem_closure_singleton.symm }\n\nlemma multiples_subset {x : A} {P : add_submonoid A} (h : x ∈ P) : multiples x ≤ P :=\nλ x hx, match x, hx with _, ⟨i, rfl⟩ := P.nsmul_mem h i end\n\nattribute [to_additive add_submonoid.multiples] submonoid.powers\nattribute [to_additive add_submonoid.mem_multiples] submonoid.mem_powers\nattribute [to_additive add_submonoid.mem_multiples_iff] submonoid.mem_powers_iff\nattribute [to_additive add_submonoid.multiples_eq_closure] submonoid.powers_eq_closure\nattribute [to_additive add_submonoid.multiples_subset] submonoid.powers_subset\n\nend add_submonoid\n\n/-! Lemmas about additive closures of `submonoid`. -/\nnamespace submonoid\n\nvariables {R : Type*} [non_assoc_semiring R] (S : submonoid R) {a b : R}\n\n/-- The product of an element of the additive closure of a multiplicative submonoid `M`\nand an element of `M` is contained in the additive closure of `M`. -/\nlemma mul_right_mem_add_closure\n  (ha : a ∈ add_submonoid.closure (S : set R)) (hb : b ∈ S) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nbegin\n  revert b,\n  refine add_submonoid.closure_induction ha _ _ _; clear ha a,\n  { exact λ r hr b hb, add_submonoid.mem_closure.mpr (λ y hy, hy (S.mul_mem hr hb)) },\n  { exact λ b hb, by simp only [zero_mul, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw add_mul,\n    exact λ 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 ∈ add_submonoid.closure (S : set R)) (hb : b ∈ add_submonoid.closure (S : set R)) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nbegin\n  revert a,\n  refine add_submonoid.closure_induction hb _ _ _; clear hb b,\n  { exact λ r hr b hb, S.mul_right_mem_add_closure hb hr },\n  { exact λ b hb, by simp only [mul_zero, (add_submonoid.closure (S : set R)).zero_mem] },\n  { simp_rw mul_add,\n    exact λ 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 ∈ S) (hb : b ∈ add_submonoid.closure (S : set R)) :\n  a * b ∈ add_submonoid.closure (S : set R) :=\nS.mul_mem_add_closure (add_submonoid.mem_closure.mpr (λ sT hT, hT ha)) hb\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 ⟨y, ⟨n, hy1⟩, hy2⟩,\n    use n,\n    simpa [← of_mul_pow, hy1] },\n  { rintros ⟨n, hn⟩,\n    refine ⟨x ^ n, ⟨n, rfl⟩, _⟩,\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": "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/membership.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.751838775154106}}
{"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\n\n/-!\n\n# Interlude: types.\n\nLean uses something called \"types\" instead of sets, as its foundational\nway of saying a \"collection of stuff\". For example, the real numbers\nare a type in Lean, a group `G` is a type `G` equipped with a multiplication\nand satisfying some axioms, and so on. \n\nSometimes, especially when making counterexamples, it's helpful to have a way\nof making your own types. For example if I asked you to give an example\nof a surjective function which wasn't injective then rather than using\nLean's inbuilt types like `ℕ` and `ℝ` you might just want to let `X={a,b}`\nand `Y={c}` and define `f(a)=f(b)=c`. In this sheet we learn how to do this.\n\n## Inductive types\n\nThere are three ways to make types in Lean. There are function types, quotient\ntypes, and inductive types. Turns out that all types that mathematicians use\nto build mathematics are made in one of these three ways. For more information\nabout all three kinds of types, see the course notes\n\nhttps://www.ma.imperial.ac.uk/~buzzard/xena/formalising-mathematics-2023/Part_B/threekindsoftypes.html\n\nIn this sheet, we will focus on inductive types, which are something like\n\"types for which you can list all the elements in a certain kind of way\".\nThe definition of the type will basically be the list.\n\nIn the rest of this section, the only kinds of types you'll need to know about are\nfinite types, so let's start by talking about these. Let's make\na type which just has three terms.\n\n-/\n\n-- A type with three terms\ninductive X : Type\n| a : X\n| b : X\n| c : X\n\n-- Here `X` is a new type, with three terms whose full names are `X.a`, `X.b` and `X.c`. \n-- You can think of `X` as a set, with three elements `X = {X.a, X.b, X.c}`. Typing\n-- `X.` gets old very quickly so we `open X` meaning that we don't have to do this.\n\nopen X\n\n#check a -- works, and says `a : X`, i.e. type of `a` is `X`. \n\n-- Given a general term `x : X`, you can do `cases x` and Lean will turn one goal into\n-- three goals with this command, one for `x = a`, one for `x = b` and one for `x = c`.\n\nexample (x : X) : x = a ∨ x = b ∨ x = c :=\nbegin\n  cases x,\n  { left, refl, },\n  { right, left, refl },\n  { right, right, refl },\nend\n\n-- How does Lean know that `a` and `b` are *distinct* elements of `X`? If you\n-- have `h : a = b` then you can do `cases h` to close any goal, because \"there\n-- are no cases\". Lean knows deep down in its core that different constructors\n-- for inductive types produce different terms\n\nexample : a ≠ b :=\nbegin\n  -- `a ≠ b` is definitionally equal to `¬ (a = b)` which is \n  -- definitionally equal to `a = b → false`. So `intro` works\n  intro h,\n  -- `h : a = b`\n  cases h, -- closes the goal. \nend\n\n\n-- We defined `X` using the `inductive` keyword and these funny `|` \"pipe\" symbols.\n-- If you want to define a function from `X` to another type you can use `def`\n-- and the `|` symbols again. \n\ndef f : X → ℕ \n| a := 37\n| b := 42\n| c := 0\n\nexample : f a = 37 :=\nbegin\n  -- true by definition\n  refl\nend\n\n-- Here is a proof that `f` is an injective function. \n-- At some point in this proof there are 9 goals; you can see them\n-- by changing the `;` after `cases y` to a `,`. The semicolon means\n-- \"apply the next tactic to all the goals produced by the last tactic\".\n\n-- Lean 3 is not very good at displaying goals when semicolons are involved;\n-- to see the nine goals change `cases y;` to `cases y, end #exit`\n\nexample : function.injective f :=\nbegin\n  intros x y h,\n  cases x;\n  cases y;\n  -- at this point there are 9 goals, and for each goal either the conclusion\n  -- is true by refl, or there's a false hypothesis `h`.\n  try {refl};\n  try {cases h},\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/section03functions/sheet2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8459424295406087, "lm_q1q2_score": 0.7518387655649968}}
{"text": "import tactic\n\n-- Этот файл переведен и адаптирован из второй недели курса Formalising Mathematics: https://github.com/ImperialCollegeLondon/formalising-mathematics/tree/master/src/week_2\n-- Там же есть продолжение про подгруппы, скачайте репозиторий с помощью\n-- `leanproject get ImperialCollegeLondon/formalising-mathematics`\n-- И самостоятельно пройдите то, что там есть \n\nnamespace itmo.lean\n\n/-\nОпределим группу как тайпкласс (подробнее: https://leanprover.github.io/theorem_proving_in_lean/type_classes.html), расширяющий `has_mul`, `has_one` и `has_inv`. \n\n`has_mul G` означает, что на `G` определено умножение `* : G → G → G`\n`has_one G` означает, что в `G` есть единица `1 : G`\n`has_inv G` означает, что есть функция, выдающая обратный для элемента `G`: `⁻¹ : G → G`\n\nВсе эти определения - просто нотация, свойства и взаимодействие этих функций надо будет добавить. Определим класс `group` с аксиомами групп:\n-/\n\nclass group (G : Type) extends has_mul G, has_one G, has_inv G :=\n(mul_assoc : ∀ (a b c : G), a * b * c = a * (b * c))\n(one_mul : ∀ (a : G), 1 * a = a)\n(mul_left_inv : ∀ (a : G), a⁻¹ * a = 1)\n\n/-\nФормально, `group G` это структура, в которой есть умножение, 1, обратный элемент, и доказательства аксиом групп. Поскольку `group G` это тайпкласс, то добавить в сигнатуру функции \"пусть `G` - группа\" нужно, как `(G : Type) [group G]`. Квадратные скобки используются для тайпклассов и автоматически (насколько получится) находятся соответствующие инстансы для `G`.\n\nОбратите внимание, что набор использованных аксиом минимален, например, нет аксиом \n`mul_one : ∀ (a : G), a * 1 = a` и \n`mul_right_inv : ∀ (a : G), a * a⁻¹ = 1`.\n\nНа самом деле, эти аксиомы следуют из основных, и мы это докажем.\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  rw ← one_mul b,\n  rw ← one_mul c,\n  rw ← mul_left_inv a,\n  rw mul_assoc,\n  rw mul_assoc,\n  rw Habac,\nend\n\n-- Доказательства из длинных цепочек равенств или неравенств часто можно заменить на `calc` (справка по `calc`: https://leanprover-community.github.io/extras/calc.html)\n-- Пример решения задачи с IMO 2020 с использованием `calc`: https://github.com/leanprover-community/mathlib/blob/master/archive/imo/imo2020_q2.lean\n\nexample (a b c : G) (Habac : a * b = a * c) : b = c := \nbegin\n calc b = 1 * b         : by rw one_mul\n    ... = (a⁻¹ * a) * b : by rw ← mul_left_inv a\n    ... = a⁻¹ * (a * b) : by rw ← mul_assoc\n    ... = a⁻¹ * (a * c) : by rw Habac\n    ... = (a⁻¹ * a) * c : by rw ← mul_assoc\n    ... = 1 * c         : by rw mul_left_inv a\n    ... = c             : by rw one_mul,\nend\n\nlemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = a⁻¹ * y) : a * x = y :=\nbegin\n  apply mul_left_cancel,\n  rwa [← mul_assoc, mul_left_inv, one_mul],\nend\n\nvariables (a b c x y : G)\n\n/-\nПопробуйте начать доказательство с `apply mul_eq_of_eq_inv_mul`.\n-/\n\n@[simp] theorem mul_one : a * 1 = a :=\nbegin\n  exact mul_eq_of_eq_inv_mul (mul_left_inv _).symm, \nend\n\n@[simp] theorem mul_right_inv : a * a⁻¹ = 1 :=\nbegin\n  exact mul_eq_of_eq_inv_mul (mul_one _).symm,\nend\n\n\n/-\n\nХорошей идеей было бы научить `simp` работать с леммами вида `A = B` или `A ↔ B`, которые мы описали выше. Для этого мы написали атрибут `@[simp]` перед леммой. В идеале, хочется, чтобы равенства в группах решались автоматически:\n\n`example : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1`\n\nТактика `simp` будет пытаться \"упростить\" цель как можно больше, в идеале закрыть цель с помощью известных ей лемм. `simp` работает переписываниями, только используя переписывания слева направо (если хочется изменить направление, можно дать дополнительный аргумент `simp [← h] at ...`). Поэтому, в тождествах, помеченных `simp`, правая часть должна быть \"проще\", чем левая. В частности, `add_comm (a b : ℕ) : a + b = b + a` - плохая лемма для `simp`. Обратите внимание, что во всех леммах выше, например,\n\n`@[simp] theorem mul_one (a : G) : a * 1 = a`\n`@[simp] theorem mul_right_inv (a : G) : a * a⁻¹ = 1`\n\nправая часть проще левой. Помечать равенство  `a = a * 1` тегом `@[simp]` - плохая идея.\n\nУже определенным функциям (или определенным в другом файле) можно ретроспективно проставить атрибуты вручную.\n-/\n\nattribute [simp] one_mul mul_left_inv mul_assoc\n\n/-\nНаучим `simp` использовать следующие пять лемм: \n\n`inv_mul_cancel_left : a⁻¹ * (a * b) = b`\n`mul_inv_cancel_left : a * (a⁻¹ * b) = b`\n`inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹`\n`one_inv : (1 : G)⁻¹ = 1`\n`inv_inv : (a⁻¹)⁻¹ = a`\n\nОбратите внимание, что везде правая часть \"проще\" левой.\n-/\n\n@[simp] lemma inv_mul_cancel_left : a⁻¹ * (a * b) = b :=\nbegin\n  rw ← mul_assoc,\n  -- Здесь уже `simp` сможет переписать `a⁻¹ * a = 1` и `1 * b = b`\n  simp,\nend\n\n@[simp] lemma mul_inv_cancel_left : a * (a⁻¹ * b) = b :=\nbegin\n  rw [← mul_assoc],\n  simp,\nend\n\n@[simp] lemma inv_mul : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\nbegin\n  apply mul_left_cancel (a * b),\n  rw mul_right_inv,\n  simp,\nend\n\n@[simp] lemma one_inv : (1 : G)⁻¹ = 1 :=\nbegin\n  apply mul_left_cancel (1 : G),\n  rw mul_right_inv,\n  simp,\nend\n\n@[simp] lemma inv_inv : a ⁻¹ ⁻¹ = a :=\nbegin\n  apply mul_left_cancel a⁻¹,\n  simp,\nend\n\n/-\nЭти 5 лемм выбраны неспроста: это вывод алгоритма Кнута-Бендикса для переписываний в группе:\n\nhttps://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group\n-/\n\n-- Сложный пример теперь решается автоматически\nexample : (a * b) * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1 := by simp\n\nlemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * c⁻¹ :=\nbegin\n  rw ← h,\n  simp,\nend\n\nlemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = b⁻¹ * c :=\nbegin\n  rw ← h,\n  simp,\nend\n\nlemma mul_left_eq_self {a b : G} : a * b = b ↔ a = 1 :=\nbegin\n  split, {\n    intro h,\n    replace h := congr_arg (λ x, x * b⁻¹) h,\n    simpa using h,\n  }, {\n    intro h,\n    simp [h],\n  }\nend\n\nlemma mul_right_eq_self {a b : G} : a * b = a ↔ b = 1 :=\nbegin\n  split, {\n    intro h,\n    replace h := congr_arg (λ x, a⁻¹ * x) h,\n    simp at h,\n    exact h,\n  }, {\n    intro h,\n    simp [h],\n  }\nend\n\nlemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = b⁻¹ :=\ncalc  a = a * 1 : by rw mul_one\n    ... = a * (b * b⁻¹) : by rw mul_right_inv\n    ... = (a * b) * b⁻¹ : by rw mul_assoc\n    ... = 1 * b⁻¹ : by rw h\n    ... = b⁻¹   : one_mul _\n\nlemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : a⁻¹ = b :=\nbegin\n  replace h := eq_inv_of_mul_eq_one h,\n  simp [h],\nend\n\nlemma unique_left_id {e : G} (h : ∀ x : G, e * x = x) : e = 1 :=\nbegin\n  have h1 := h 1,\n  simpa using h1,\nend\n\nlemma unique_right_inv {a b : G} (h : a * b = 1) : b = a⁻¹ :=\nbegin\n  apply mul_left_cancel a,\n  simp [h],\nend\n\nlemma mul_left_cancel_iff (a x y : G) : a * x = a * y ↔ x = y :=\nbegin\n  split,\n  { apply mul_left_cancel },\n  { intro hxy,\n    rwa hxy }\nend\n\n-- В режим `calc` можно войти даже вне блока begin-end \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⁻¹) : by rw ← mul_right_inv\n  ... = (x * a) * a⁻¹ : by rw ← mul_assoc\n  ... = (y * a) * a⁻¹ : by rw Habac\n  ... = y * (a * a⁻¹) : by rw mul_assoc\n  ... = y * 1 : by rw mul_right_inv\n  ... = y : by rw mul_one\n\n@[simp] theorem inv_inj_iff {a b : G}: a⁻¹ = b⁻¹ ↔ a = b :=\nbegin\n  split, {\n    intro h,\n    rw [← inv_inv a, h, inv_inv],\n  }, {\n    rintro rfl,\n    refl,\n  }\nend   \n\ntheorem inv_eq {a b : G}: a⁻¹ = b ↔ b⁻¹ = a :=\nbegin\n  split, \n  all_goals {\n    rintro rfl,\n    simp only [inv_inv],\n  },\nend  \n\nend group\n\nend itmo.lean\n\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/week04/solutions/e01_groups.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527906914787, "lm_q2_score": 0.8824278618165526, "lm_q1q2_score": 0.7517868794585265}}
{"text": "import algebra.group algebra.group_power\n\nvariables {G: Type*}\n\ntheorem Q_03 [hG: group G]:\n  (∀ a b: G, (a * b) ^ 2 = a ^ 2 * b ^ 2) → comm_group G :=\nλ h, begin\n\n  have lem: ∀ a b: G, a * (a * b) * b = a * (b * a) * b,\n    from λ a b, calc a * (a * b) * b\n    = a * a * (b * b)         : by rw [←mul_assoc, mul_assoc]\n... = a * a ^ 1 * (b * b ^ 1) : by rw [pow_one, pow_one]\n... = a ^ 2 * b ^ 2           : by rw [←pow_succ, ←pow_succ]\n... = (a * b) ^ 2             : (h a b).symm\n... = a * b * (a * b)         : by rw [pow_succ, pow_one]\n... = a * (b * a) * b         : by rw [←mul_assoc, ←mul_assoc],\n\n  have comm: ∀ a b: G, a * b = b * a,\n  from λ a b, mul_left_cancel (mul_right_cancel (lem a b)),\n\n  -- G is a group, together with comm, show that\n  -- G is an abelian group:\n  exact { mul_comm := comm, .. hG },\nend\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_03.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799462157138, "lm_q2_score": 0.7799928900257126, "lm_q1q2_score": 0.7517415055976204}}
{"text": "import analysis.specific_limits\nimport data.int.parity\nimport topology.sequences\n\n\nattribute [instance] classical.prop_decidable\n\n/-\nLemmas from that file were hidden in my course, or restating things which\nwere proved without name in previous files.\n-/\n\nnotation `|`x`|` := abs x\n\n-- The mathlib version is unusable because it is stated in terms of ≤\nlemma ge_max_iff {α : Type*} [linear_order α] {p q r : α} : r ≥ max p q  ↔ r ≥ p ∧ r ≥ q :=\nmax_le_iff\n\n/- No idea why this is not in mathlib-/\nlemma eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y :=\nbegin\n  intro h,\n  apply eq_of_abs_sub_nonpos,\n  by_contradiction H,\n  push_neg at H,\n  specialize h ( |x-y|/2) (by linarith),\n  linarith,\nend\n\ndef seq_limit (u : ℕ → ℝ) (l : ℝ) : Prop :=\n∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε\n\nlemma unique_limit {u l l'} : seq_limit u l → seq_limit u l' → l = l' :=\nbegin\n  intros hl hl',\n  apply eq_of_abs_sub_le_all,\n  intros ε ε_pos,\n  specialize hl (ε/2) (by linarith),\n  cases hl with N hN,\n  specialize hl' (ε/2) (by linarith),\n  cases hl' with N' hN',\n  specialize hN (max N N') (le_max_left _ _),\n  specialize hN' (max N N') (le_max_right _ _),\n  calc |l - l'| = |(l-u (max N N')) + (u (max N N') -l')| : by ring\n  ... ≤ |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  ... ≤ ε/2 + ε/2 : by linarith\n  ... = ε : by ring,\nend\n\nlemma le_of_le_add_all {x y : ℝ} :\n  (∀ ε > 0, y ≤ x + ε) →  y ≤ x :=\nbegin\n  contrapose!,\n  intro h,\n  use (y-x)/2,\n  split ; linarith,\nend\n\ndef upper_bound (A : set ℝ) (x : ℝ) := ∀ a ∈ A, a ≤ x\n\ndef is_sup (A : set ℝ) (x : ℝ) := upper_bound A x ∧ ∀ y, upper_bound A y → x ≤ y\n\nlemma lt_sup {A : set ℝ} {x : ℝ} (hx : is_sup A x) :\n∀ y, y < x → ∃ a ∈ A, y < a :=\nbegin\n  intro y,\n  contrapose!,\n  exact hx.right y,\nend\n\nlemma squeeze {u v w : ℕ → ℝ} {l} (hu : seq_limit u l) (hw : seq_limit w l)\n(h : ∀ n, u n ≤ v n)\n(h' : ∀ n, v n ≤ w n) : seq_limit v l :=\nbegin\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases hw ε ε_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 ; linarith\nend\n\ndef extraction (φ : ℕ → ℕ) := ∀ n m, n < m → φ n < φ m\n\ndef tendsto_infinity (u : ℕ → ℝ) := ∀ A, ∃ N, ∀ n ≥ N, u n ≥ A\n\nlemma lim_le {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∀ n, u n ≤ y) : x ≤ y :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  specialize hN N (by linarith),\n  specialize ineg N,\n  rw abs_le at hN,\n  linarith,\nend\n\nlemma inv_succ_le_all :  ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, 1/(n + 1 : ℝ) ≤ ε :=\nbegin\n  convert metric.tendsto_at_top.mp (tendsto_one_div_add_at_top_nhds_0_nat),\n  apply propext,\n  simp only [real.dist_eq, sub_zero],\n  split,\n    intros h ε ε_pos,\n    cases h (ε/2) (by linarith) with N hN,\n    use N,\n    intros n hn,\n    rw abs_of_pos (nat.one_div_pos_of_nat : 1/(n+1 : ℝ) > 0),\n    specialize hN n hn,\n    linarith,\n  intros h ε ε_pos,\n  cases h ε (by linarith) with N hN,\n  use N,\n  intros n hn,\n  specialize hN n hn,\n  rw abs_of_pos (@nat.one_div_pos_of_nat ℝ _ n) at hN,\n  linarith,\nend\n\nlemma limit_const (x : ℝ) : seq_limit (λ n, x) x :=\nλ ε ε_pos, ⟨0, λ _ _, by simp [le_of_lt ε_pos]⟩\n\nlemma limit_of_sub_le_inv_succ {u : ℕ → ℝ} {x : ℝ} (h : ∀ n, |u n - x| ≤ 1/(n+1)) :\nseq_limit u x :=\nbegin\n  intros ε ε_pos,\n  rcases inv_succ_le_all ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  specialize h n,\n  specialize hN n hn,\n  linarith,\nend\n\nlemma limit_const_add_inv_succ (x : ℝ) : seq_limit (λ n, x + 1/(n+1)) x :=\nlimit_of_sub_le_inv_succ (λ n, by rw abs_of_pos ; linarith [@nat.one_div_pos_of_nat ℝ _ n])\n\nlemma limit_const_sub_inv_succ (x : ℝ) : seq_limit (λ n, x - 1/(n+1)) x :=\nbegin\n  refine limit_of_sub_le_inv_succ (λ n, _),\n  rw [show x - 1 / (n + 1) - x = -(1/(n+1)), by ring, abs_neg,  abs_of_pos],\n  linarith [@nat.one_div_pos_of_nat ℝ _ n]\nend\n\nlemma id_le_extraction {φ}: extraction φ → ∀ n, n ≤ φ 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\nlemma seq_limit_id : tendsto_infinity (λ n, n) :=\nbegin\n  intros A,\n  cases exists_nat_gt A with N hN,\n  use N,\n  intros n hn,\n  have : (n : ℝ) ≥ N, exact_mod_cast hn,\n  linarith,\nend\n\nvariables {u : ℕ → ℝ} {l : ℝ} {φ : ℕ → ℕ}\n\nopen set filter\n\ndef cluster_point (u : ℕ → ℝ) (a : ℝ) :=\n∃ φ, extraction φ ∧ seq_limit (u ∘ φ) a\n\nlemma bolzano_weierstrass {a b : ℝ} {u : ℕ → ℝ} (h : ∀ n, u n ∈ Icc a b) :\n∃ c ∈ Icc a b, cluster_point u c :=\nbegin\n  rcases (compact_Icc : is_compact (Icc a b)).tendsto_subseq h with ⟨c, c_in, φ, hφ, lim⟩,\n  use [c, c_in, φ, hφ],\n  simp_rw [metric.tendsto_nhds, eventually_at_top, real.dist_eq] at lim,\n  intros ε ε_pos,\n  rcases lim ε ε_pos with ⟨N, hN⟩,\n  use N,\n  intros n hn,\n  exact le_of_lt (hN n hn)\nend\n\nlemma not_seq_limit_of_tendstoinfinity {u : ℕ → ℝ} :\n  tendsto_infinity u → ∀ x, ¬ seq_limit u x :=\nbegin\n  intros lim_infinie x lim_x,\n  cases lim_x 1 (by linarith) with N hN,\n  cases lim_infinie (x+2) with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left _ _),\n  specialize hN' N₀ (le_max_right _ _),\n  rw abs_le at hN,\n  linarith,\nend\n\nopen real\n\nlemma sup_segment {a b : ℝ} {A : set ℝ} (hnonvide : ∃ x, x ∈ A) (h : A ⊆ Icc a b) :\n  ∃ x ∈ Icc a b, is_sup A x :=\nbegin\n  have b_maj :  ∀ (y : ℝ), y ∈ A → y ≤ b,\n    from λ y y_in, (h y_in).2,\n  have Sup_maj : upper_bound A (Sup A),\n  { intro x,\n    apply real.le_Sup,\n    use [b, b_maj] } ,\n  refine ⟨Sup A, _, _⟩,\n  { split,\n    { cases hnonvide with x x_in,\n      exact le_trans (h x_in).1 (Sup_maj _ x_in) },\n    { apply Sup_le_ub A hnonvide b_maj } },\n  { use Sup_maj,\n    intros y y_in,\n    rwa real.Sup_le _ hnonvide ⟨b, b_maj⟩ },\nend\n\nlemma subseq_tendsto_of_tendsto (h : seq_limit u l) (hφ : extraction φ) :\nseq_limit (u ∘ φ) l :=\nbegin\n  intros ε ε_pos,\n  cases h ε ε_pos with N hN,\n  use N,\n  intros n hn,\n  apply hN,\n  calc N ≤ n   : hn\n     ... ≤ φ n : id_le_extraction hφ n,\nend\nnamespace tactic.interactive\nopen tactic\n\nmeta def check_me : tactic unit :=\n`[ { repeat { unfold seq_limit},\n   repeat { unfold continue_en },\n   push_neg,\n   try { simp only [exists_prop] },\n   try { exact iff.rfl },\n   done } <|> fail \"That's not quite right. Please try again.\" ]\n\nend tactic.interactive\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/7_Ampliacion_de_limites/tuto_lib.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.7517298354533537}}
{"text": "\nimport .basic \nimport prelim.intervals \nimport prelim.collections prelim.embed prelim.size prelim.induction prelim.minmax finsum.fin_api\nimport matroid.pointcount matroid.submatroid.minor_iso \n\nnoncomputable theory \nopen_locale classical big_operators \n\nopen set matroid \n\nvariables {α β : Type*} [fintype α] [comm_semiring β] [no_zero_divisors β]\n\n/-- the size of a projective geometry over a `q`-element field; i.e `1 + q + q^2 + ... + q^{n-1}` -/\ndef pg_size' : β → ℕ → β\n| q 0     := 0\n| q (n+1) := 1 + q * (pg_size' q n)\n\n@[simp] lemma pg_size'_zero (q : β) : pg_size' q 0 = 0 := rfl \n\n@[simp] lemma pg_size'_succ {q : β}{n : ℕ}: pg_size' q n.succ = 1 + q * (pg_size' q n) := rfl \n\n@[simp] lemma pg_size'_order_one (n : ℕ) : pg_size' (1 : ℤ) n = n := \nby {induction n with n ih, simp, simp [pg_size', ih, add_comm]  }\n\nlemma pg_size'_eq_powsum (q : β) (n : ℕ) : pg_size' q n = ∑ᶠ i in Ico 0 n , q^i  := \nbegin\n  induction n with n ih, \n    simp, \n  rw [pg_size', ih], rw mul_distrib_finsum_in q, \n  conv in (_ * _) {rw ← pow_succ}, \n  rw [← pow_zero q, finsum_Ico_shift, Ico_ℕ_eq_Ioo, nat.zero_add, nat.sub_self,\n   ← finsum_in_insert, Ioo_insert_left_eq_Ico];\n  simp [set.Ioo_ℕ_finite],  \nend\n\nlemma pg_size'_rat (q : ℤ) (n : ℕ) (hq : 2 ≤ q) : (pg_size' q n : ℚ) = (q^n - 1)/(q - 1) := \nbegin\n  induction n with n ih, \n    simp, \n  replace hq : (q : ℚ) -1 ≠ 0 := by {norm_cast, linarith}, \n  rw [pg_size', ih, ← mul_div_assoc, one_add_div hq, div_left_inj' hq, pow_succ], \n  ring, \nend\n\n/- the size of a rank-`n` projective geometry over `GF(q)`, or equivalently the value of the sum\n`1 + q + q² + q³ + ... + q^{n-1}` For convenience, this is defined for all integers `n`, taking \nthe value `0` if `n ≤ 0`.  -/\ndef pg_size (q n : ℤ) := pg_size' q n.to_nat \n\nlemma pg_size_eq_zero (q n : ℤ)(hn : n ≤ 0) : pg_size q n = 0 := \nby {rw pg_size, convert pg_size'_zero q, rw int.to_nat_zero_of_nonpos hn, }\n\nlemma pg_size_rec (q : ℤ) {n : ℤ} (hn : 1 ≤ n) : pg_size q n = 1 + q * (pg_size q (n-1)) :=\nbegin\n  rw [pg_size, pg_size], \n  obtain ⟨m,rfl⟩ := int.eq_coe_of_zero_le (by linarith : 0 ≤ n), \n  norm_num, \n  cases m, exfalso, norm_num at hn, refl, \nend\n\nlemma pg_size_eq_powsum (q n : ℤ) : pg_size q n = ∑ᶠ i in Ico 0 n.to_nat, q^i  := \nbegin\n  cases le_or_lt n 0 with hn hn', \n  { convert finsum_in_empty.symm, \n    exact pg_size_eq_zero q n hn, \n    apply Ico_eq_empty, \n    rw int.to_nat_zero_of_nonpos hn,  },\n  convert pg_size'_eq_powsum q n.to_nat, \nend\n\nlemma pg_size_nonneg (q n : ℤ)(hq : 0 ≤ q): 0 ≤ pg_size q n :=\nby {rw pg_size_eq_powsum, exact nonneg_of_finsum_in_nonneg (λ i hi, pow_nonneg hq i)}\n\n/- Kung's lemma - the number of points in a rank-`r` matroid with no `U_{2,q+2}`-minor is at most \n`1 + q + q^2 + ... + q^{n-1}`. -/\ntheorem rank_le_rank_pg_of_no_line {q : ℤ} (hq : 1 ≤ q) {M : matroid α} :\n  M.has_no_line_minor (q+2) → M.ε univ ≤ pg_size q (M.rank) := \nbegin\n  /- If the result fails, we can choose M to be a minimal counterexample-/\n  rw rank, revert M, \n  by_contra hn, \n  obtain ⟨M,hM⟩ := min_counterexample_nonneg_int_param \n    _ (λ (M : matroid α), size (M.nonloops)) (λ s, size_nonneg _) hn, \n  push_neg at hM, \n  rcases hM with ⟨⟨hMq, hMs⟩, hM_min⟩,  \n  \n  /- The counterexample doesn't have rank zero, so it has a nonloop e-/\n  by_cases hr : M.r univ ≤ 0, \n  { linarith [pg_size_nonneg q (M.r univ) (by linarith : 0 ≤ q), \n              ε_eq_r_of_r_le_one (by linarith: M.r univ ≤ 1)]},\n  obtain ⟨e,-,he⟩ := contains_nonloop_of_one_le_rank (lt_of_not_ge' hr), \n\n  /- Write ε M in terms of the sum of lengths of lines through e-/\n  rw ε_as_ε_proj_nonloop he at hMs, \n\n  /- These lines all contain at most q points other than e... -/\n  set lines := {L : set α | M.is_line L ∧ e ∈ L} with hlines, \n  have h_L_ub : ∀ L ∈ lines, M.ε L -1 ≤ q, \n  { rintros L ⟨hL,-⟩, exact int.sub_right_le_of_le_add (line_restr_ub_ε (by linarith) hMq hL)},\n\n  /- ... so we can get an upper bound on the sum of their lengths, which then translates to an \n  upper bound in terms of `ε (M ⟋ e)`.  . -/\n  have h_le : ∑ᶠ (L : set α) in lines, (M.ε L - 1) ≤  q * ((M ⟋ {e}).ε univ), \n  { convert fin.finsum_in_le_finsum_in h_L_ub, \n    rw [int.finsum_in_const_eq_mul_size, hlines, ε_proj_nonloop _ he]}, \n  \n  /- Since `M ⟋ e` isn't a counterexample, it doesn't have too many points  -/\n  specialize hM_min (M ⟋ {e}) \n    (size_strict_monotone (project_nonloop_fewer_nonloops he))\n    (pminor_has_no_uniform_minor (by norm_num) (by linarith) (pr_is_pminor M {e}) hMq),\n  \n  /- Now `M`, being a counterexample, has lots of points, whereas `M ⟋ e` doesn't have too many.\n  This is a contradiction. -/\n  have hlt := calc \n    pg_size q (M.r univ)  < 1 + ∑ᶠ (L : set α) in lines, (M.ε L - 1) \n                        : hMs \n                      ... ≤ 1 + q * (M ⟋ {e}).ε univ                 \n                        : add_le_add_left h_le 1\n                      ... ≤ 1 + q * (pg_size q ((M ⟋ {e}).r univ))   \n                        : add_le_add_left ((mul_le_mul_left (by linarith : 0 < q)).mpr hM_min) 1,\n\n  rw [project_r, univ_union, rank_nonloop he, ← pg_size_rec q (by linarith : 1 ≤ M.r univ)] at hlt, \n  exact lt_irrefl _ hlt, \nend\n\n\n\ntheorem rank_set_le_rank_pg_of_no_line {q : ℤ}(hq : 1 ≤ q){α : Type*} [fintype α] {M : matroid α}\n(X : set α) (h : M.has_no_line_minor (q+2)):\n  M.ε X ≤ pg_size q (M.r X) := \nbegin\n  rw ← ε_loopify_to_eq_ε, \n  convert rank_le_rank_pg_of_no_line hq _ using 1, \n  { rw [loopify_to_r, univ_inter]},\n  exact pminor_has_no_uniform_minor (by norm_num : (1 : ℤ) ≤ 2) (by linarith : 2 ≤ q + 2)\n    (lp_is_pminor _ _) h, \nend\n  \n\n \n\n/-\n  This is (almost) boilerplate for the fact that a minimal counterexample has no parallel pairs. \n  Not needed for the proof above, as it turned out, but may be useful later. \n\n  have no_parallel : ∀ e f, M.parallel e f → e = f, \n  { by_contra hn', push_neg at hn', obtain ⟨e,f,hef,hne⟩ := hn', \n    set M' := M ⟍ {f} with hM', \n    specialize hM_min M' \n      (size_strict_monotone (loopify_nonloop_fewer_nonloops hef.nonloop_right))\n      (pminor_has_no_uniform_minor (by norm_num) (by linarith) (lp_is_pminor M {f}) hMq), \n    rw [rank_nat, r_nat] at hM_min hMs, \n    rw [hM', rank_eq_rank_loopify_parallel hef hne, \n          ε_loopify_parallel _ (ne.symm hne) (hef.symm)] at hM_min, \n    exact lt_irrefl _ (lt_of_le_of_lt hM_min hMs)},\n\n  have h' : M.is_simple_set (M.nonloops),\n  { rw [simple_set_iff_no_loops_or_parallel_pairs, loopless_set_iff_subset_nonloops], \n     refine ⟨subset.refl _, λ e f _ _ hef, no_parallel e f hef⟩},\n\n  clear no_parallel hn, \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/uniform_minor/kung.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.8104789178257654, "lm_q1q2_score": 0.7516084002870856}}
{"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 number_theory.padics.padic_val\n\n/-!\n# p-adic norm\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 `p`-adic norm on `ℚ`.\n\nThe `p`-adic valuation on `ℚ` 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 `ℚ`. This norm is a nonarchimedean absolute value.\nIt takes values in {0} ∪ {1/p^k | k ∈ ℤ}.\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êa, *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/-- If `q ≠ 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`. -/\ndef padic_norm (p : ℕ) (q : ℚ) : ℚ := if q = 0 then 0 else (p : ℚ) ^ -padic_val_rat p q\n\nnamespace padic_norm\n\nopen padic_val_rat\nvariables {p : ℕ}\n\n/-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/\n@[simp] protected lemma eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :\n  padic_norm p q = p ^ -padic_val_rat p q :=\nby simp [hq, padic_norm]\n\n/-- The `p`-adic norm is nonnegative. -/\nprotected lemma nonneg (q : ℚ) : 0 ≤ 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/-- The `p`-adic norm of `0` is `0`. -/\n@[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm]\n\n/-- The `p`-adic norm of `1` is `1`. -/\n@[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm]\n\n/-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`.\n\nSee also `padic_norm.padic_norm_p_of_prime` for a version assuming `p` is prime. -/\nlemma padic_norm_p (hp : 1 < p) : padic_norm p p = p⁻¹ :=\nby simp [padic_norm, (pos_of_gt hp).ne', padic_val_nat.self hp]\n\n/-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime.\n\nSee also `padic_norm.padic_norm_p` for a version assuming `1 < p`. -/\n@[simp] lemma padic_norm_p_of_prime [fact p.prime] : padic_norm p p = 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 {q : ℕ} [p_prime : fact p.prime] [q_prime : fact q.prime]\n  (neq : p ≠ 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/-- The `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 `p` is prime. -/\nlemma padic_norm_p_lt_one (hp : 1 < p) : padic_norm p p < 1 :=\nbegin\n  rw [padic_norm_p hp, inv_lt_one_iff],\n  exact_mod_cast (or.inr hp)\nend\n\n/-- The `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`. -/\nlemma padic_norm_p_lt_one_of_prime [fact p.prime] : padic_norm p p < 1 :=\npadic_norm_p_lt_one $ nat.prime.one_lt (fact.out _)\n\n/-- `padic_norm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/\nprotected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padic_norm p q = p ^ -z :=\n⟨ (padic_val_rat p q), by simp [padic_norm, hq] ⟩\n\n/-- `padic_norm p` is symmetric. -/\n@[simp] protected lemma neg (q : ℚ) : 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/-- If `q ≠ 0`, then `padic_norm p q ≠ 0`. -/\nprotected lemma nonzero {q : ℚ} (hq : q ≠ 0) : padic_norm p q ≠ 0 :=\nbegin\n  rw padic_norm.eq_zpow_of_nonzero hq,\n  apply zpow_ne_zero_of_ne_zero,\n  exact_mod_cast ne_of_gt hp.1.pos\nend\n\n/-- If the `p`-adic norm of `q` is 0, then `q` is `0`. -/\nlemma zero_of_padic_norm_eq_zero {q : ℚ} (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/-- The `p`-adic norm is multiplicative. -/\n@[simp] protected theorem mul (q r : ℚ) : 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 ≠ 0, from mul_ne_zero hq hr,\n  have (p : ℚ) ≠ 0, by simp [hp.1.ne_zero],\n  by simp [padic_norm, *, padic_val_rat.mul, zpow_add₀ this, mul_comm]\n\n/-- The `p`-adic norm respects division. -/\n@[simp] protected theorem div (q r : ℚ) : 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 [←padic_norm.mul, div_mul_cancel _ hr])\n\n/-- The `p`-adic norm of an integer is at most `1`. -/\nprotected theorem of_int (z : ℤ) : padic_norm p z ≤ 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, neg_nonpos],\n      norm_cast, simp }},\n  exact_mod_cast hz,\nend\n\nprivate lemma nonarchimedean_aux {q r : ℚ} (h : padic_val_rat p q ≤ padic_val_rat p r) :\n  padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) :=\nhave hnqp : padic_norm p q ≥ 0, from padic_norm.nonneg _,\nhave hnrp : padic_norm p r ≥ 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/-- The `p`-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p`\nand the norm of `q`. -/\nprotected theorem nonarchimedean {q r : ℚ} :\n  padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) :=\nbegin\n  wlog hle : (padic_val_rat p q) ≤ (padic_val_rat p r) generalizing q r,\n  { rw [add_comm, max_comm], exact this (le_of_not_le hle) },\n  exact nonarchimedean_aux hle\nend\n\n/-- The `p`-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of\n`p` plus the norm of `q`. -/\ntheorem triangle_ineq (q r : ℚ) : padic_norm p (q + r) ≤ padic_norm p q + padic_norm p r :=\ncalc padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean\n                       ... ≤ padic_norm p q + padic_norm p r :\n                         max_le_add_of_nonneg (padic_norm.nonneg _) (padic_norm.nonneg _)\n\n/-- The `p`-adic norm of a difference is at most the max of each component. Restates the archimedean\nproperty of the `p`-adic norm. -/\nprotected theorem sub {q r : ℚ} : padic_norm p (q - r) ≤ max (padic_norm p q) (padic_norm p r) :=\nby rw [sub_eq_add_neg, ←padic_norm.neg r]; apply padic_norm.nonarchimedean\n\n/-- If the `p`-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max\nof the norms of `q` and `r`. -/\nlemma add_eq_max_of_ne {q r : ℚ} (hne : padic_norm p q ≠ padic_norm p r) :\n  padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) :=\nbegin\n  wlog hlt : (padic_norm p r) < (padic_norm p q),\n  { rw [add_comm, max_comm], exact this hne.symm (hne.lt_or_lt.resolve_right hlt) },\n  have : padic_norm p q ≤ 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               ... ≤ max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean\n               ... = max (padic_norm p (q + r)) (padic_norm p r) : by simp,\n  have hnge : padic_norm p r ≤ 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 ≤ padic_norm p (q + r), by rwa [max_eq_left hnge] at this,\n  apply _root_.le_antisymm,\n  { apply padic_norm.nonarchimedean },\n  { rwa max_eq_left_of_lt hlt }\nend\n\n/-- The `p`-adic norm is an absolute value: positive-definite and multiplicative, satisfying the\ntriangle inequality. -/\ninstance : is_absolute_value (padic_norm p) :=\n{ abv_nonneg := padic_norm.nonneg,\n  abv_eq_zero := λ _, ⟨zero_of_padic_norm_eq_zero, λ hx, by simpa only [hx]⟩,\n  abv_add := padic_norm.triangle_ineq,\n  abv_mul := padic_norm.mul }\n\nlemma dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p ^ n) ∣ z ↔ padic_norm p z ≤ p ^ (-n : ℤ) :=\nbegin\n  unfold padic_norm, split_ifs with hz,\n  { norm_cast at hz,\n    have : 0 ≤ (p ^ n : ℚ), {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,\n      padic_val_int.of_ne_one_ne_zero hp.1.ne_one _],\n    { norm_cast,\n      rw [← part_enat.coe_le_coe, part_enat.coe_get, ← multiplicity.pow_dvd_iff_le_multiplicity],\n      simp },\n    { exact_mod_cast hz },\n    { exact_mod_cast hp.1.one_lt } }\nend\n\n/-- The `p`-adic norm of an integer `m` is one iff `p` doesn't divide `m`. -/\nlemma int_eq_one_iff (m : ℤ) : padic_norm p m = 1 ↔ ¬ (p : ℤ) ∣ m :=\nbegin\n  nth_rewrite 1 ← pow_one p,\n  simp only [dvd_iff_norm_le, int.cast_coe_nat, nat.cast_one, zpow_neg, zpow_one, not_le],\n  split,\n  { intro h,\n    rw [h, inv_lt_one_iff_of_pos];\n    norm_cast,\n    { exact nat.prime.one_lt (fact.out _), },\n    { exact nat.prime.pos (fact.out _), }, },\n  { simp only [padic_norm],\n    split_ifs,\n    { rw [inv_lt_zero, ← nat.cast_zero, nat.cast_lt],\n      intro h, exact (nat.not_lt_zero p h).elim, },\n    { have : 1 < (p : ℚ) := by norm_cast; exact (nat.prime.one_lt (fact.out _ : nat.prime p)),\n      rw [← zpow_neg_one, zpow_lt_iff_lt this],\n      have : 0 ≤ padic_val_rat p m, simp only [of_int, nat.cast_nonneg],\n      intro h,\n      rw [← zpow_zero (p : ℚ), zpow_inj];\n      linarith, } },\nend\n\nlemma int_lt_one_iff (m : ℤ) : padic_norm p m < 1 ↔ (p : ℤ) ∣ m :=\nbegin\n  rw [← not_iff_not, ← int_eq_one_iff, eq_iff_le_not_lt],\n  simp only [padic_norm.of_int, true_and],\nend\n\nlemma of_nat (m : ℕ) : padic_norm p m ≤ 1 := padic_norm.of_int (m : ℤ)\n\n/-- The `p`-adic norm of a natural `m` is one iff `p` doesn't divide `m`. -/\nlemma nat_eq_one_iff (m : ℕ) : padic_norm p m = 1 ↔ ¬ p ∣ m :=\nby simp only [←int.coe_nat_dvd, ←int_eq_one_iff, int.cast_coe_nat]\n\nlemma nat_lt_one_iff (m : ℕ) : padic_norm p m < 1 ↔ p ∣ m :=\nby simp only [←int.coe_nat_dvd, ←int_lt_one_iff, int.cast_coe_nat]\n\nopen_locale big_operators\n\nlemma sum_lt {α : Type*} {F : α → ℚ} {t : ℚ} {s : finset α} :\n  s.nonempty → (∀ i ∈ s, padic_norm p (F i) < t) → padic_norm p (∑ i in s, F i) < t :=\nbegin\n  classical,\n  refine s.induction_on (by { rintro ⟨-, ⟨⟩⟩, }) _,\n  rintro a S haS IH - ht,\n  by_cases hs : S.nonempty,\n  { rw finset.sum_insert haS,\n    exact lt_of_le_of_lt padic_norm.nonarchimedean (max_lt\n      (ht a (finset.mem_insert_self a S))\n      (IH hs (λ b hb, ht b (finset.mem_insert_of_mem hb)))), },\n  { simp * at *, },\nend\n\nlemma sum_le {α : Type*} {F : α → ℚ} {t : ℚ} {s : finset α} :\n  s.nonempty → (∀ i ∈ s, padic_norm p (F i) ≤ t) → padic_norm p (∑ i in s, F i) ≤ t :=\nbegin\n  classical,\n  refine s.induction_on (by { rintro ⟨-, ⟨⟩⟩, }) _,\n  rintro a S haS IH - ht,\n  by_cases hs : S.nonempty,\n  { rw finset.sum_insert haS,\n    exact padic_norm.nonarchimedean.trans (max_le\n      (ht a (finset.mem_insert_self a S))\n      (IH hs (λ b hb, ht b (finset.mem_insert_of_mem hb)))), },\n  { simp * at *, },\nend\n\nlemma sum_lt' {α : Type*} {F : α → ℚ} {t : ℚ} {s : finset α} (hF : ∀ i ∈ s, padic_norm p (F i) < t)\n  (ht : 0 < t) : padic_norm p (∑ i in s, F i) < t :=\nbegin\n  obtain rfl | hs := finset.eq_empty_or_nonempty s,\n  { simp [ht], },\n  { exact sum_lt hs hF, },\nend\n\nlemma sum_le' {α : Type*} {F : α → ℚ} {t : ℚ} {s : finset α} (hF : ∀ i ∈ s, padic_norm p (F i) ≤ t)\n  (ht : 0 ≤ t) : padic_norm p (∑ i in s, F i) ≤ t :=\nbegin\n  obtain rfl | hs := finset.eq_empty_or_nonempty s,\n  { simp [ht], },\n  { exact sum_le hs hF, },\nend\n\nend padic_norm\n", "meta": {"author": "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/padics/padic_norm.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8104789063814616, "lm_q1q2_score": 0.7516083896740582}}
{"text": "import data.real.basic\nimport topology.basic\nopen function\nopen set\n\nnamespace xena -- hide\n\n/-\n# Chapter 7 : Cardinality\n\n## Level 3\n\nA classical result about countable sets.\n-/\n\n/- Lemma\nIf $f : X \\to Y$ is an injective function and $Y$ is countable, then\n$X$ is also countable.\n-/\ntheorem countable_inj (X Y : set ℝ) (f : X → Y) (hY : countable Y) : \n    injective f → countable X :=\nbegin\n   intro hf,\n    have H := countable_iff_exists_injective.1 hY,\n    cases H with g hg,\n    have G := countable_iff_exists_injective.2 ⟨g ∘ f, injective.comp hg hf⟩,\n    exact G, done\nend\n\nend xena -- hide\n\n-- begin hide\n-- term mode proof due to Kenny Lau\ntheorem countable_inj_2 (X Y : set ℝ) (f : X → Y) (hY : countable Y) :\n    injective f → countable X :=\nλ hf, let ⟨g, hg⟩ := countable_iff_exists_injective.1 hY in\ncountable_iff_exists_injective.2 ⟨g ∘ f, injective.comp hg hf⟩\n-- end 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/cardinality/countable_inj.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.8104789109591832, "lm_q1q2_score": 0.7516083874111144}}
{"text": "/-\nCopyright (c) 2020 Anatole Dedecker. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Anatole Dedecker, Alexey Soloyev, Junyan Xu\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.real.irrational\nimport Mathlib.data.nat.fib\nimport Mathlib.data.matrix.notation\nimport Mathlib.tactic.ring_exp\nimport Mathlib.algebra.linear_recurrence\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# The golden ratio and its conjugate\n\nThis file defines the golden ratio `φ := (1 + √5)/2` and its conjugate\n`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.\n\nAlong with various computational facts about them, we prove their\nirrationality, and we link them to the Fibonacci sequence by proving\nBinet's formula.\n-/\n\n/-- The golden ratio `φ := (1 + √5)/2`. -/\ndef golden_ratio : ℝ :=\n  (1 + real.sqrt (bit1 (bit0 1))) / bit0 1\n\n/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/\ndef golden_conj : ℝ :=\n  (1 - real.sqrt (bit1 (bit0 1))) / bit0 1\n\n/-- The inverse of the golden ratio is the opposite of its conjugate. -/\ntheorem inv_gold : golden_ratio⁻¹ = -golden_conj := sorry\n\n/-- The opposite of the golden ratio is the inverse of its conjugate. -/\ntheorem inv_gold_conj : golden_conj⁻¹ = -golden_ratio := sorry\n\n@[simp] theorem gold_mul_gold_conj : golden_ratio * golden_conj = -1 := sorry\n\n@[simp] theorem gold_conj_mul_gold : golden_conj * golden_ratio = -1 :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (golden_conj * golden_ratio = -1)) (mul_comm golden_conj golden_ratio)))\n    gold_mul_gold_conj\n\n@[simp] theorem gold_add_gold_conj : golden_ratio + golden_conj = 1 := sorry\n\ntheorem one_sub_gold_conj : 1 - golden_ratio = golden_conj := sorry\n\ntheorem one_sub_gold : 1 - golden_conj = golden_ratio := sorry\n\n@[simp] theorem gold_sub_gold_conj : golden_ratio - golden_conj = real.sqrt (bit1 (bit0 1)) := sorry\n\n@[simp] theorem gold_sq : golden_ratio ^ bit0 1 = golden_ratio + 1 := sorry\n\n@[simp] theorem gold_conj_sq : golden_conj ^ bit0 1 = golden_conj + 1 := sorry\n\ntheorem gold_pos : 0 < golden_ratio := sorry\n\ntheorem gold_ne_zero : golden_ratio ≠ 0 :=\n  ne_of_gt gold_pos\n\ntheorem one_lt_gold : 1 < golden_ratio := sorry\n\ntheorem gold_conj_neg : golden_conj < 0 := sorry\n\ntheorem gold_conj_ne_zero : golden_conj ≠ 0 :=\n  ne_of_lt gold_conj_neg\n\ntheorem neg_one_lt_gold_conj : -1 < golden_conj :=\n  eq.mpr (id (Eq._oldrec (Eq.refl (-1 < golden_conj)) (propext neg_lt)))\n    (eq.mpr (id (Eq._oldrec (Eq.refl (-golden_conj < 1)) (Eq.symm inv_gold))) (inv_lt_one one_lt_gold))\n\n/-!\n## Irrationality\n-/\n\n/-- The golden ratio is irrational. -/\ntheorem gold_irrational : irrational golden_ratio := sorry\n\n/-- The conjugate of the golden ratio is irrational. -/\ntheorem gold_conj_irrational : irrational golden_conj := sorry\n\n/-!\n## Links with Fibonacci sequence\n-/\n\n/-- The recurrence relation satisfied by the Fibonacci sequence. -/\ndef fib_rec {α : Type u_1} [comm_semiring α] : linear_recurrence α :=\n  linear_recurrence.mk (bit0 1) (matrix.vec_cons 1 (matrix.vec_cons 1 matrix.vec_empty))\n\n/-- The characteristic polynomial of `fib_rec` is `X² - (X + 1)`. -/\ntheorem fib_rec_char_poly_eq {β : Type u_1} [comm_ring β] : linear_recurrence.char_poly fib_rec = polynomial.X ^ bit0 1 - (polynomial.X + 1) := sorry\n\n/-- As expected, the Fibonacci sequence is a solution of `fib_rec`. -/\ntheorem fib_is_sol_fib_rec {α : Type u_1} [comm_semiring α] : linear_recurrence.is_solution fib_rec fun (x : ℕ) => ↑(nat.fib x) := sorry\n\n/-- The geometric sequence `λ n, φ^n` is a solution of `fib_rec`. -/\ntheorem geom_gold_is_sol_fib_rec : linear_recurrence.is_solution fib_rec (pow golden_ratio) := sorry\n\n/-- The geometric sequence `λ n, ψ^n` is a solution of `fib_rec`. -/\ntheorem geom_gold_conj_is_sol_fib_rec : linear_recurrence.is_solution fib_rec (pow golden_conj) := sorry\n\n/-- Binet's formula as a function equality. -/\ntheorem real.coe_fib_eq' : (fun (n : ℕ) => ↑(nat.fib n)) = fun (n : ℕ) => (golden_ratio ^ n - golden_conj ^ n) / real.sqrt (bit1 (bit0 1)) := sorry\n\n/-- Binet's formula as a dependent equality. -/\ntheorem real.coe_fib_eq (n : ℕ) : ↑(nat.fib n) = (golden_ratio ^ n - golden_conj ^ n) / real.sqrt (bit1 (bit0 1)) := 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/real/golden_ratio.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7516083854288471}}
{"text": "-- different versions of one proof in tactic mode\n\n-- proofs with the or connective\nexample (p q : Prop) : p ∨ q → q ∨ p := by\nintro h\napply Or.elim h\nintro hp\nexact Or.intro_right q hp\nintro hq\nexact Or.intro_left p hq\n\nexample (p q : Prop) : p ∨ q → q ∨ p := by\nintro h\ncases h\napply Or.intro_right\nassumption\napply Or.intro_left\nassumption\n\nexample (p q : Prop) : p ∨ q → q ∨ p := by\nintro h\ncases h with\n  | inl hp => apply Or.intro_right\n              exact hp\n  | inr hq => apply Or.intro_left\n              exact hq\n\nexample (p q : Prop) : p ∨ q → q ∨ p := by\nintro h\ncases h with\n  | inl => apply Or.intro_right\n           assumption\n  | inr => apply Or.intro_left\n           assumption\n\n-- proofs with the and connective\n\nexample (p q : Prop) : p ∧ q → q ∧ p := by\nintro h\napply And.intro\nexact h.right\nexact h.left\n\nexample (p q : Prop) : p ∧ q → q ∧ p := by\nintro h  \ncases h\napply And.intro\nrepeat assumption\n\nexample (p q : Prop) : p ∧ q → q ∧ p := by\nintro h  \ncases h with\n| intro hp hq => exact (And.intro hq hp)\n\nexample (p q : Prop) : p ∧ q → q ∧ p := by\nintro h  \ncases h with\n| intro => apply And.intro\n           repeat assumption\n\nexample (p q : Prop) : p ∧ q → q ∧ p :=\nfun h => And.intro h.right h.left", "meta": {"author": "Euctemon", "repo": "learning-lean", "sha": "bf93d5996f53f3b874cfd049d03e7d9a7beee46e", "save_path": "github-repos/lean/Euctemon-learning-lean", "path": "github-repos/lean/Euctemon-learning-lean/learning-lean-bf93d5996f53f3b874cfd049d03e7d9a7beee46e/proving/prove_chap5.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7515926883726205}}
{"text": "/-\nCopyright (c) 2020 Yury Kudryashov. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Yury Kudryashov, Eric Wieser\n-/\nimport algebra.quaternion\nimport analysis.inner_product_space.basic\nimport analysis.inner_product_space.pi_L2\nimport topology.algebra.algebra\n\n/-!\n# Quaternions as a normed algebra\n\nIn this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions:\n\n* inner product space;\n* normed ring;\n* normed space over `ℝ`.\n\nWe show that the norm on `ℍ[ℝ]` agrees with the euclidean norm of its components.\n\n## Notation\n\nThe following notation is available with `open_locale quaternion`:\n\n* `ℍ` : quaternions\n\n## Tags\n\nquaternion, normed ring, normed space, normed algebra\n-/\n\nlocalized \"notation (name := quaternion.real) `ℍ` := quaternion ℝ\" in quaternion\nopen_locale real_inner_product_space\n\nnamespace quaternion\n\ninstance : has_inner ℝ ℍ := ⟨λ a b, (a * b.conj).re⟩\n\nlemma inner_self (a : ℍ) : ⟪a, a⟫ = norm_sq a := rfl\n\nlemma inner_def (a b : ℍ) : ⟪a, b⟫ = (a * b.conj).re := rfl\n\nnoncomputable instance : normed_add_comm_group ℍ :=\n@inner_product_space.of_core.to_normed_add_comm_group ℝ ℍ _ _ _\n{ inner := has_inner.inner,\n  conj_symm := λ x y, by simp [inner_def, mul_comm],\n  nonneg_re := λ x, norm_sq_nonneg,\n  definite := λ x, norm_sq_eq_zero.1,\n  add_left := λ x y z, by simp only [inner_def, add_mul, add_re],\n  smul_left := λ x y r, by simp [inner_def] }\n\nnoncomputable instance : inner_product_space ℝ ℍ :=\ninner_product_space.of_core _\n\nlemma norm_sq_eq_norm_sq (a : ℍ) : norm_sq a = ‖a‖ * ‖a‖ :=\nby rw [← inner_self, real_inner_self_eq_norm_mul_norm]\n\ninstance : norm_one_class ℍ :=\n⟨by rw [norm_eq_sqrt_real_inner, inner_self, norm_sq.map_one, real.sqrt_one]⟩\n\n@[simp, norm_cast] lemma norm_coe (a : ℝ) : ‖(a : ℍ)‖ = ‖a‖ :=\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 : ℝ) : ‖(a : ℍ)‖₊ = ‖a‖₊ :=\nsubtype.ext $ norm_coe a\n\n@[simp] lemma norm_conj (a : ℍ) : ‖conj a‖ = ‖a‖ :=\nby simp_rw [norm_eq_sqrt_real_inner, inner_self, norm_sq_conj]\n\n@[simp] lemma nnnorm_conj (a : ℍ) : ‖conj a‖₊ = ‖a‖₊ :=\nsubtype.ext $ norm_conj a\n\nnoncomputable instance : normed_division_ring ℍ :=\n{ dist_eq := λ _ _, rfl,\n  norm_mul' := λ 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\ninstance : normed_algebra ℝ ℍ :=\n{ norm_smul_le := norm_smul_le,\n  to_algebra := (quaternion.algebra : algebra ℝ ℍ) }\n\ninstance : cstar_ring ℍ :=\n{ norm_star_mul_self := λ x, (norm_mul _ _).trans $ congr_arg (* ‖x‖) (norm_conj x) }\n\ninstance : has_coe ℂ ℍ := ⟨λ z, ⟨z.re, z.im, 0, 0⟩⟩\n\n@[simp, norm_cast] \n\n@[simp, norm_cast] lemma coe_complex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext; simp\n@[simp, norm_cast] lemma coe_complex_zero : ((0 : ℂ) : ℍ) = 0 := rfl\n@[simp, norm_cast] lemma coe_complex_one : ((1 : ℂ) : ℍ) = 1 := rfl\n@[simp, norm_cast] lemma coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z :=\nby ext; simp\n@[simp, norm_cast] lemma coe_complex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r := rfl\n\n/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/\ndef of_complex : ℂ →ₐ[ℝ] ℍ :=\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' := λ x, rfl }\n\n@[simp] lemma coe_of_complex : ⇑of_complex = coe := rfl\n\n/-- The norm of the components as a euclidean vector equals the norm of the quaternion. -/\nlemma norm_pi_Lp_equiv_symm_equiv_tuple (x : ℍ) :\n  ‖(pi_Lp.equiv 2 (λ _ : fin 4, _)).symm (equiv_tuple ℝ x)‖ = ‖x‖ :=\nbegin\n  rw [norm_eq_sqrt_real_inner, norm_eq_sqrt_real_inner, inner_self, norm_sq_def', pi_Lp.inner_apply,\n    fin.sum_univ_four],\n  simp_rw [is_R_or_C.inner_apply, star_ring_end_apply, star_trivial, ←sq],\n  refl,\nend\n\n/-- `quaternion_algebra.linear_equiv_tuple` as a `linear_isometry_equiv`. -/\n@[simps apply symm_apply]\nnoncomputable def linear_isometry_equiv_tuple : ℍ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin 4) :=\n{ to_fun := λ a, (pi_Lp.equiv _ (λ _ : fin 4, _)).symm ![a.1, a.2, a.3, a.4],\n  inv_fun := λ a, ⟨a 0, a 1, a 2, a 3⟩,\n  norm_map' := norm_pi_Lp_equiv_symm_equiv_tuple,\n  ..(quaternion_algebra.linear_equiv_tuple (-1 : ℝ) (-1 : ℝ)).trans\n      (pi_Lp.linear_equiv 2 ℝ (λ _ : fin 4, ℝ)).symm }\n\n@[continuity] lemma continuous_conj : continuous (conj : ℍ → ℍ) :=\ncontinuous_star\n\n@[continuity] lemma continuous_coe : continuous (coe : ℝ → ℍ) :=\ncontinuous_algebra_map ℝ ℍ\n\n@[continuity] lemma continuous_norm_sq : continuous (norm_sq : ℍ → ℝ) :=\nby simpa [←norm_sq_eq_norm_sq]\n  using (continuous_norm.mul continuous_norm : continuous (λ q : ℍ, ‖q‖ * ‖q‖))\n\n@[continuity] lemma continuous_re : continuous (λ q : ℍ, q.re) :=\n(continuous_apply 0).comp linear_isometry_equiv_tuple.continuous\n\n@[continuity] lemma continuous_im_i : continuous (λ q : ℍ, q.im_i) :=\n(continuous_apply 1).comp linear_isometry_equiv_tuple.continuous\n\n@[continuity] lemma continuous_im_j : continuous (λ q : ℍ, q.im_j) :=\n(continuous_apply 2).comp linear_isometry_equiv_tuple.continuous\n\n@[continuity] lemma continuous_im_k : continuous (λ q : ℍ, q.im_k) :=\n(continuous_apply 3).comp linear_isometry_equiv_tuple.continuous\n\n@[continuity] lemma continuous_im : continuous (λ q : ℍ, q.im) :=\nby simpa only [←sub_self_re] using continuous_id.sub (continuous_coe.comp continuous_re)\n\ninstance : complete_space ℍ :=\nbegin\n  have : uniform_embedding linear_isometry_equiv_tuple.to_linear_equiv.to_equiv.symm :=\n    linear_isometry_equiv_tuple.to_continuous_linear_equiv.symm.uniform_embedding,\n  exact (complete_space_congr this).1 (by apply_instance)\nend\n\nsection infinite_sum\nvariables {α : Type*}\n\n@[simp, norm_cast] lemma has_sum_coe {f : α → ℝ} {r : ℝ} :\n  has_sum (λ a, (f a : ℍ)) (↑r : ℍ) ↔ has_sum f r :=\n⟨λ h, by simpa only using\n  h.map (show ℍ →ₗ[ℝ] ℝ, from quaternion_algebra.re_lm _ _) continuous_re,\n  λ h, by simpa only using h.map (algebra_map ℝ ℍ) (continuous_algebra_map _ _)⟩\n\n@[simp, norm_cast]\nlemma summable_coe {f : α → ℝ} : summable (λ a, (f a : ℍ)) ↔ summable f :=\nby simpa only using summable.map_iff_of_left_inverse (algebra_map ℝ ℍ)\n  (show ℍ →ₗ[ℝ] ℝ, from quaternion_algebra.re_lm _ _)\n  (continuous_algebra_map _ _) continuous_re coe_re\n\n@[norm_cast] lemma tsum_coe (f : α → ℝ) : ∑' a, (f a : ℍ) = ↑(∑' a, f a) :=\nbegin\n  by_cases hf : summable f,\n  { exact (has_sum_coe.mpr hf.has_sum).tsum_eq, },\n  { simp [tsum_eq_zero_of_not_summable hf,\n      tsum_eq_zero_of_not_summable (summable_coe.not.mpr hf)] },\nend\n\nend infinite_sum\n\nend quaternion\n", "meta": {"author": "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/quaternion.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206659843132, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7515926777183253}}
{"text": "/- Lecture 1.3: Basics — More Logic and Proofs -/\n\n/- Logical connectives and quantifiers -/\n\n-- introduction rules\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#check false.elim\n#check and.elim_left\n#check and.elim_right\n#check or.elim\n#check exists.elim\n\n-- aliases\n#check and.left\n#check and.right\n\n-- definition of `¬` and related lemmas\n#print not\n#check classical.em\n#check classical.by_contradiction\n\nexample (p q : Prop) : p ∧ q → p := and.elim_left\n\nexample (p q : Prop) : p ∧ q → q ∧ p :=\nassume hpq : p ∧ q,\nhave hp : p := and.left hpq,\nhave hq : q := and.right hpq,\nshow q ∧ p, from and.intro hq hp\n\n-- conjunction (`and`)\n\nexample (p q : Prop) : p ∧ q → q ∧ p :=\nλhpq : p ∧ q,\n  (λhp : p,\n    (λhq : q,\n      (and.intro hq hp : q ∧ p))\n    (and.right hpq))\n  (and.left hpq)\n\nexample : ∀p q : Prop, p ∧ q → q ∧ p :=\nbegin\n  intros _ _ hpq,\n  exact and.intro (and.right hpq) (and.left hpq)\nend\n\nexample (p q : Prop) (h : p ∧ q) : q ∧ p :=\n⟨h.right, h.left⟩\n\nexample : ∀p q : Prop, p ∧ q → q ∧ p :=\nbegin\n  intros _ _ hpq,\n  apply and.intro,\n  exact hpq.right,\n  exact hpq.left\nend\n\n-- disjunction (`or`)\n\nexample (p q : Prop) : p ∨ q → q ∨ p\n| (or.inl h) := or.inr h\n| (or.inr h) := or.inl h\n\nexample (p q : Prop) : p ∨ q → q ∨ p :=\nbegin\n  intros hpq,\n  apply (or.elim hpq),\n  { intros h, apply or.inr h },\n  { intros h, apply or.inl h }\nend\n\n-- implication (`imp`)\n\nexample (p q : Prop) : p → q → p :=\nassume hp hq,\nshow p, from hp\n\n-- modus ponens (elimination of implication)\n\nexample (p q : Prop) (h : p → q) (hp : p) : q :=\nh hp\n\nexample (p q : Prop) (h : p → q) (hp : p) : q :=\nbegin\n  apply h,\n  exact hp\nend\n\nexample (p q : Prop) (h : p → q) (hp : p) : q :=\nbegin\n  apply h,\n  assumption\nend\n\n-- proof of negation\n\nexample (p : Prop) : p → ¬¬ p :=\nbegin\n  dunfold not,\n  intro hp,\n  apply not.intro,\n  intro hnp,\n  apply hnp,\n  exact hp\nend\n\nexample (p : Prop) : p → ¬¬ p :=\nbegin\n  intros hp hnp,\n  refine hnp _,\n  exact hp\nend\n\n-- proof by contradiction\n\nexample (p : Prop) : ¬¬ p → p :=\nbegin\n  intro hnnp,\n  apply classical.by_contradiction,\n  apply hnnp\nend\n\nexample (p : Prop) : ¬¬ p → p :=\nbegin\n  intro,\n  apply classical.by_contradiction,\n  assumption\nend\n\n\n/- Arithmetic calculations -/\n\n-- `#mul` in Visual Studio Code's command palette\n#check two_mul\n\nexample (m 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", "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/13_lecture.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.751580628919123}}
{"text": "import ..prooflab\nimport lectures.lec18_nat_trans\nimport tactic.basic\n\n--open PROOFS\nopen PROOFS.STR\n\nopen category_str\n\n--Q1\n--Let's do this for additive groups. multiplicative groups are basically the same\n--We have defined the type of additve groups\n#check additive_Group\n\nuniverse u\n--we need to define the morphism between additive groups\n--let's define it like we did for additive_monoid\n@[ext]\nclass additive_monoid.morphism (M : Type u) (N : Type u) [additive_monoid_str M] [additive_monoid_str N] :=\n(to_fun : M → N) -- f : M → N -- the underlying function of morphism\n(resp_zero : to_fun 0 = 0) -- f (1_M ) = 1_N\n(resp_add : ∀ x y : M, to_fun (x + y) = to_fun x + to_fun y) -- f(x *_M y) = (f x) *_N (f y)\n\n@[ext]\nclass additive_group.morphism (M : Type u) (N : Type u) [additive_group_str M] [additive_group_str N] :=\n(to_fun : M → N) -- f : M → N -- the underlying function of morphism\n(resp_zero : to_fun 0 = 0) -- f (1_M ) = 1_N\n(resp_add : ∀ x y : M, to_fun (x + y) = to_fun x + to_fun y) -- f(x *_M y) = (f x) *_N (f y)\n\n--let's also define identity\ndef additive_group.morphism.id {M : Type}[additive_group_str M] : additive_group.morphism M M := \n{\n  to_fun := id, --just identity\n  resp_zero := by {simp}, --simplify by previous lemmas\n  resp_add := by {simp}, --same here\n}\n\n--we also need composition\n@[simp]\ndef additive_group.morphism.comp {L M N : Type} [additive_group_str L] [additive_group_str M] [additive_group_str N] (g : additive_group.morphism M N) (f : additive_group.morphism L M) : additive_group.morphism L N := \n{ to_fun := g.to_fun ∘ f.to_fun, --compose the to_funs\n  resp_zero := by \n  {\n    dsimp, --simplify by definition\n    rw f.resp_zero, --use the individual properties of the morphisms to get to the goal\n    rw g.resp_zero,\n  },\n  resp_add := by \n  {\n    intros x y, --introduction for ∀\n    dsimp, --simplfy by definition\n    rw f.resp_add, --again, rewrite using individual properties\n    rw g.resp_add,\n  }, \n  }\n\n--let's prove id_comp comp_id, and comp_assoc\n\n--id_comp\n@[simp]\nlemma additive_group.morphism.id_comp {L M : Type} [additive_group_str L] [additive_group_str M]  (f : additive_group.morphism L M)  : \n  additive_group.morphism.comp additive_group.morphism.id f = f :=\nbegin \n  ext, --apply extensionality\n  refl, --lhs is exactly rhs\nend \n\n--comp_id\n@[simp]\nlemma additive_group.morphism.comp_id {L M : Type} [additive_group_str L] [additive_group_str M]  (f : additive_group.morphism L M)  : \n  additive_group.morphism.comp f additive_group.morphism.id = f := \nbegin \n  ext, --apply extensionality\n  refl, --lhs is exactly rhs\nend\n\n--comp_assoc\n@[simp]\ndef additive_group.morphism.comp_assoc {K L M N: Type} [additive_group_str K] [additive_group_str L] [additive_group_str M] [additive_group_str N] (f : additive_group.morphism K L) (g : additive_group.morphism L M) (h : additive_group.morphism M N) : \n  additive_group.morphism.comp (additive_group.morphism.comp h g) f = additive_group.morphism.comp h (additive_group.morphism.comp g f) := \nbegin \n  refl, --after simplifcation lhs is exactly rhs\nend   \n\ninstance cat_of_additive_groups : large_category_str (additive_Group) :=\n{ hom := λ X Y, additive_group.morphism X.carrier Y.carrier, --morphisms are additive_group.morphisms\n  id := λ X, additive_group.morphism.id, --identiy is identity\n  comp := λ X Y Z f g, additive_group.morphism.comp g f, --composition is defined above\n  id_comp' := by {intros X Y f, apply additive_group.morphism.id_comp}, --proved above\n  comp_id' := by {intros X Y f, apply additive_group.morphism.comp_id}, --proved above\n  comp_assoc' := by {intros X Y Z W f g h, apply additive_group.morphism.comp_assoc}, --again, proved above\n}\n\n--Q2\n@[ext]\nclass mult_monoid_action (M A : Type) [mult_monoid_str M] :=\n(smul : M → A → A) -- the scalar multiplication of `M` on `A`.\n(one_smul' : ∀ (x : A), smul (1 : M) x = x)\n(mul_smul' : ∀ (r s : M) (x : A),\nsmul (r * s)  x = smul r (smul s x))\n\n--Show that a monoid action gives rise to a functor from the delooping category of the monoid to the category of types. You can show that by filling in for the sorry placeholder in below.\nset_option trace.simp_lemmas true\n\ndef delooping_monoid_action (A : Type) [M : mult_Monoid] [mult_monoid_action M.carrier A] : (delooping_cat M).carrier ⥤ Type* :=  \n{ obj := λ Y, A, --element of delooping monoid to element of type\n  mor := λ X Y (m : M.carrier), λ a, mult_monoid_action.smul m a, --map unit morphism to function in A. use the scalar multiplication above to send a : A to the action of m on a (still A)\n  resp_id' := by \n  {\n    intro X, --introduction for ∀\n    cases X, --extract the properties of X\n    funext, --function extensionality\n    apply mult_monoid_action.one_smul', --this is one_mul of the monoid action\n  },\n  resp_comp' := by \n  {\n    intros X Y Z f g, --introduction for ∀\n    cases X, --extract the properties of X Y Z\n    cases Y,\n    cases Z,\n    simp only [precategory_str.comp], --simplify by how we defined composition\n    funext, --function extensionality\n    dsimp, --simplify by definition\n    rw ← mult_monoid_action.mul_smul', --rw the rhs as defined in mult_monoid_action.mul_smul'\n    sorry, \n  },\n}\n\n--Q3 Yoneda\n\nopen nat_trans\n\nlocal notation f ` ⊚ `:80 g:80 := precategory_str.comp g f    -- type as \\oo\n\nuniverses v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄\n\nvariables {𝓒 : Type u₁} [category_str.{v₁} 𝓒] {𝓓 : Type u₂} [category_str.{v₂} 𝓓]\n\ndef Yoneda (X Y : 𝓒) (α : category_str.equiv (ℍom.obj X) (ℍom.obj Y)) : \n  category_str.equiv X Y :=\n{\n  to_mor := α.to_mor.cmpt (op X) (𝟙 X),\n  inv_mor := α.inv_mor.cmpt (op Y) (𝟙 Y),\n  left_inv := by\n  {\n    have h₁, from α.inv_mor.naturality (α.to_mor.cmpt (op X) (𝟙 X)),\n    simp at h₁,\n    cases α,\n    cases α_to_mor,\n    cases α_inv_mor,\n    simp at *,\n    sorry,\n\n  },\n  right_inv := by\n  {\n    sorry,\n  },\n}\n\n\n--Q4\n/-! ## The Arrow Category :\nGiven a category 𝓒 we want to construct a new category whose objects are morphisms of 𝓒 and whose morphisms are commutative squares in 𝓒.\n -/\n\n-- @[ext]\n-- structure arrow_type (𝓒 : Type*) [small_category_str 𝓒] :=\n-- (dom : 𝓒)\n-- (cod : 𝓒)\n-- (arrow : dom ⟶ cod)\n\n-- #check arrow_type\n\n\nlocal notation `𝔸𝕣` : 10 := arrow_type\n\n-- @[ext]\n-- structure arrow_type_hom {𝓒 : Type*}[small_category_str 𝓒] (α β : 𝔸𝕣 𝓒 ) :=\n-- (top : α.dom ⟶ β.dom)\n-- (bot : α.cod ⟶ β.cod)\n-- (eq : β.arrow ⊚ top = bot ⊚ α.arrow)\n\n\n-- #check arrow_type_hom\n\n/-\nShow that we can equip `𝓒[→]` with the structure of a category where morphisms of 𝓒 and whose morphisms are commutative squares in 𝓒.\n-/\n\n--added extensionality to functor and arrow structures.\n\ninstance arrow_cat (𝓒 : Type*)[small_category_str 𝓒] : small_category_str (𝔸𝕣 𝓒) :=\n{ hom := λ α, λ β, arrow_type_hom α β ,\n  id := λ α, ⟨𝟙 α.dom, 𝟙 α.cod, by {simp,}⟩ ,\n  comp := by\n  {\n    intros X Y Z, --introduce X, Y, Z for for all\n    intros f g, --introduce f, g for the implication\n    cases f, --extract f components\n    cases g, --extract g components\n    exact\n    ⟨\n    g_top ⊚ f_top, --composed top is the composition of the top components\n    g_bot ⊚ f_bot, --composed bot is the composition of the bottom components\n    by \n    {\n      simp, --simplify by how we defined compostion\n      rw ←category_str.comp_assoc, --rewrite with the associativity of composition\n      rw g_eq, --rewrite using g_eq\n      rw category_str.comp_assoc, --use composition associativity again\n      rw f_eq, --we can use f_eq to get the rhs to be the same as the lhs\n    }\n    ⟩, --done\n  },\n  id_comp' := \n  by\n  {\n    intros X Y f, --introduction for ∀\n    cases f, --extract f components\n    simp, --simplify by previous definitions and lemmas\n  }\n  ,\n  comp_id' := \n  by\n  {\n    intros X Y f,  --introduction for ∀\n    cases f, --extract f components\n    simp, --simplify by previous definitions and lemmas\n  },\n  comp_assoc' := \n  by\n  {\n    intros W X Y Z f g h, --introduction for ∀\n    cases f, --extract f,g,h components\n    cases g,\n    cases h,\n    dsimp, --simplify by definition\n    ext, --use extensionality of arrow_type_hom to prove equality\n    {--top part\n      dsimp, --simplify by definition\n      apply category_str.comp_assoc, --this is composition associativity\n    },\n    {--bottom part\n      dsimp, --simplify by definition\n      apply category_str.comp_assoc, --again, composition associativity\n    },\n  }, }\n\n#check category_str.comp_assoc\n\n\n/-\nWe shall define two functors form `𝔸𝕣 𝓒` to `𝓒`: `Dom` and `Cod`. `Dom` takes an arrow `f : X ⟶ Y` to its domain `X` and `Cod` takes `f` to `Y`.\n-/\n\n\ndef Dom (𝓒 : Type*)[small_category_str 𝓒] :\n  (𝔸𝕣 𝓒) ⥤ 𝓒 :=\n{ obj := λ α, α.dom,\n  mor := λ α β f, f.top, --just the top morphism\n  resp_id' := by\n  {\n    intro X, --introduction for ∀\n    cases X, --extract X components\n    dsimp, --simplify by definition\n    refl, --reflexivity after simplification. the left identiy is the same as the right identity (both X_dom after stuff in lhs ().top)\n  },\n  resp_comp' := by \n  {\n    intros X Y Z f g, --introduction for ∀\n    cases f, --extract f,g components\n    cases g,\n    dsimp, --simplify by definition\n    refl, --reflexivity after simplification. .top lhs gives you the composition on the rhs\n  }\n,}\n\n\ndef Cod (𝓒 : Type*)[small_category_str 𝓒] :\n  (𝔸𝕣 𝓒) ⥤ 𝓒 :=\n{ obj := λ α, α.cod,\n  mor := λ α β f, f.bot, --similar to Dom, but we use the bottom morphism this time\n  resp_id' := by\n  {--the proof will be similar to the proof for Dom\n    intro X, --introduction for ∀\n    cases X, --extract X components\n    dsimp, --simplify by definition\n    refl, --reflexivity after simplification. the left identiy is the same as the right identity after taking .bot\n  },\n  resp_comp' := by \n  {\n    intros X Y Z f g, --introduction for ∀\n    cases f, --extract f,g components\n    cases g,\n    dsimp, --simplify by definition\n    refl, --reflexivity after simplification. .bot lhs gives you the composition on the rhs\n  }\n,}\n\n\n\n/- Theorem:\nFor functors `F G : 𝓒 ⥤ 𝓓`, the type of natural transformations `F ⟶ G` is equivalent to the type of functors `𝓒 ⥤ 𝔸𝕣 𝓓`  whose composition with `Dom` and `Cod` are equal to `F` and `G` respectively.\n\nTherefore, the arrow category classifies natural transformations.\n-/\n\nlocal notation F ` ⊚⊚ `:80 G:80 := category_str.functor.comp G F\n\n\n\ndef arrow_cat_classifies_nat_trans {𝓒 𝓓 : Type*}[small_category_str 𝓒] [small_category_str 𝓓] (F G : 𝓒 ⥤ 𝓓) :\nfun_equiv (F ⟶ G) ({ H : 𝓒 ⥤ 𝔸𝕣 𝓓 // ( (Dom 𝓓) ⊚⊚ H = F ) ∧ ((Cod 𝓓) ⊚⊚ H = G) })   :=\n\n{ to_fun := λ X,\n{\n  val := \n          {\n            obj := λ α, \n            {\n              dom := F.obj α,\n              cod := G.obj α,\n              arrow := by {\n                            cases X, --extract X components\n                            exact X_cmpt α, --use the object map on α\n                          },\n            },\n\n            mor := by {\n                        intros α β f, --introduction for ∀\n                        cases X, --extract X components\n                        cases F, --extract F components\n                        cases G, --extract G components\n                        dsimp at *, --simplify by definitions\n                        have h1 := F_mor f, --use the F morphism map on f\n                        have h2 := G_mor f, --use the G morphism map on f\n                        sorry,\n                      },\n\n\n\n\n\n\n\n            resp_id' := _,\n            resp_comp' := _ \n          },\n  property :=_,\n\n},  \n\n\n{val := \n  { obj := λ α, { dom := F.obj α, cod := G.obj α, arrow := --object morphisms on α\n  by\n  {\n    cases X, --extract X components\n    exact X_cmpt α, --use the object map on α\n  },},\n  mor := λ α β f, { top := F.map f, bot := G.map f,} --morphisms on f\n  resp_id' := _,\n  resp_comp' := _ }\n,\n\n  inv_fun := _,\n  left_inv := _,\n  right_inv := _ }\n\n\n\n,\n\n\n\n\n  inv_fun := _,\n  left_inv := _,\n  right_inv := _ }", "meta": {"author": "sinhp", "repo": "ProofLab", "sha": "f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2", "save_path": "github-repos/lean/sinhp-ProofLab", "path": "github-repos/lean/sinhp-ProofLab/ProofLab-f14b2d0e8d1f6281b9ca16877aa06a8db0a690e2/src/homework/assignment_2513942_export/hw13_submissions/james-hw13.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969193, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.7515606042439285}}
{"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 data.polynomial.eval\nimport linear_algebra.dimension\n\n/-!\n# Linear recurrence\n\nInformally, a \"linear recurrence\" is an assertion of the form\n`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,\nwhere `u` is a sequence, `d` is the *order* of the recurrence and the `a i`\nare its *coefficients*.\n\nIn this file, we define the structure `linear_recurrence` so that\n`linear_recurrence.mk d a` represents the above relation, and we call\na sequence `u` which verifies it a *solution* of the linear recurrence.\n\nWe prove a few basic lemmas about this concept, such as :\n\n* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`\n  is a field)\n* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`\n  between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two\n  solutions are equal if and only if their first `d` terms are equals.\n* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,\n  which we call the *characteristic polynomial* of the recurrence\n\nOf course, although we can inductively generate solutions (cf `mk_sol`), the\ninteresting part would be to determinate closed-forms for the solutions.\nThis is currently *not implemented*, as we are waiting for definition and\nproperties of eigenvalues and eigenvectors.\n\n-/\n\nnoncomputable theory\nopen finset\nopen_locale big_operators polynomial\n\n/-- A \"linear recurrence relation\" over a commutative semiring is given by its\n  order `n` and `n` coefficients. -/\nstructure linear_recurrence (α : Type*) [comm_semiring α] := (order : ℕ) (coeffs : fin order → α)\n\ninstance (α : Type*) [comm_semiring α] : inhabited (linear_recurrence α) :=\n⟨⟨0, default⟩⟩\n\nnamespace linear_recurrence\n\nsection comm_semiring\n\nvariables {α : Type*} [comm_semiring α] (E : linear_recurrence α)\n\n/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have\n  `u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/\ndef is_solution (u : ℕ → α) :=\n  ∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)\n\n/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.\n  We will prove this is the only such solution. -/\ndef mk_sol (init : fin E.order → α) : ℕ → α\n| n := if h : n < E.order then init ⟨n, h⟩ else\n  ∑ k : fin E.order,\n    have n - E.order + k < n :=\n    begin\n      rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h), tsub_lt_iff_left],\n      { exact add_lt_add_right k.is_lt n },\n      { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h),\n        simp only [zero_add] }\n    end,\n    E.coeffs k * mk_sol (n - E.order + k)\n\n/-- `E.mk_sol` indeed gives solutions to `E`. -/\nlemma is_sol_mk_sol (init : fin E.order → α) : E.is_solution (E.mk_sol init) :=\n  λ n, by rw mk_sol; simp\n\n/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/\nlemma mk_sol_eq_init (init : fin E.order → α) : ∀ n : fin E.order, E.mk_sol init n = init n :=\n  λ n, by { rw mk_sol, simp only [n.is_lt, dif_pos, fin.mk_coe, fin.eta] }\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `∀ n, u n = E.mk_sol init n`. -/\nlemma eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) :\n  ∀ n, u n = E.mk_sol init n\n| n := if h' : n < E.order\n  then by rw mk_sol; simp only [h', dif_pos]; exact_mod_cast heq ⟨n, h'⟩\n  else begin\n    rw [mk_sol, ← tsub_add_cancel_of_le (le_of_not_lt h'), h (n-E.order)],\n    simp [h'],\n    congr' with k,\n    exact have wf : n - E.order + k < n :=\n      begin\n        rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h'), tsub_lt_iff_left],\n        { exact add_lt_add_right k.is_lt n },\n        { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h'),\n          simp only [zero_add] }\n      end,\n      by rw eq_mk_of_is_sol_of_eq_init\n  end\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution\n  of `E` whose first `E.order` values are given by `init`. -/\nlemma eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) : u = E.mk_sol init :=\n  funext (E.eq_mk_of_is_sol_of_eq_init h heq)\n\n/-- The space of solutions of `E`, as a `submodule` over `α` of the module `ℕ → α`. -/\ndef sol_space : submodule α (ℕ → α) :=\n{ carrier := {u | E.is_solution u},\n  zero_mem' := λ n, by simp,\n  add_mem' := λ u v hu hv n, by simp [mul_add, sum_add_distrib, hu n, hv n],\n  smul_mem' := λ a u hu n, by simp [hu n, mul_sum]; congr'; ext; ac_refl }\n\n/-- Defining property of the solution space : `u` is a solution\n  iff it belongs to the solution space. -/\nlemma is_sol_iff_mem_sol_space (u : ℕ → α) : E.is_solution u ↔ u ∈ E.sol_space :=\n  iff.rfl\n\n/-- The function that maps a solution `u` of `E` to its first\n  `E.order` terms as a `linear_equiv`. -/\ndef to_init :\n  E.sol_space ≃ₗ[α] (fin E.order → α) :=\n{ to_fun := λ u x, (u : ℕ → α) x,\n  map_add' := λ u v, by { ext, simp },\n  map_smul' := λ a u, by { ext, simp },\n  inv_fun := λ u, ⟨E.mk_sol u, E.is_sol_mk_sol u⟩,\n  left_inv := λ u, by ext n; symmetry; apply E.eq_mk_of_is_sol_of_eq_init u.2; intros k; refl,\n  right_inv := λ u, function.funext_iff.mpr (λ n, E.mk_sol_eq_init u n) }\n\n/-- Two solutions are equal iff they are equal on `range E.order`. -/\nlemma sol_eq_of_eq_init (u v : ℕ → α) (hu : E.is_solution u) (hv : E.is_solution v) :\n  u = v ↔ set.eq_on u v ↑(range E.order) :=\nbegin\n  refine iff.intro (λ h x hx, h ▸ rfl) _,\n  intro h,\n  set u' : ↥(E.sol_space) := ⟨u, hu⟩,\n  set v' : ↥(E.sol_space) := ⟨v, hv⟩,\n  change u'.val = v'.val,\n  suffices h' : u' = v', from h' ▸ rfl,\n  rw [← E.to_init.to_equiv.apply_eq_iff_eq, linear_equiv.coe_to_equiv],\n  ext x,\n  exact_mod_cast h (mem_range.mpr x.2)\nend\n\n/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. This operation is quite useful for determining closed-form\n  solutions of `E`. -/\n\n/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. -/\ndef tuple_succ : (fin E.order → α) →ₗ[α] (fin E.order → α) :=\n{ to_fun := λ X i, if h : (i : ℕ) + 1 < E.order then X ⟨i+1, h⟩ else (∑ i, E.coeffs i * X i),\n  map_add' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_add, sum_add_distrib],\n    end,\n  map_smul' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_sum],\n      exact sum_congr rfl (λ x _, by ac_refl),\n    end }\n\nend comm_semiring\n\nsection field\n\nvariables {α : Type*} [field α] (E : linear_recurrence α)\n\n/-- The dimension of `E.sol_space` is `E.order`. -/\nlemma sol_space_dim : module.rank α E.sol_space = E.order :=\n@dim_fin_fun α _ E.order ▸ E.to_init.dim_eq\n\nend field\n\nsection comm_ring\n\nvariables {α : Type*} [comm_ring α] (E : linear_recurrence α)\n\n/-- The characteristic polynomial of `E` is\n`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/\ndef char_poly : α[X] :=\n  polynomial.monomial E.order 1 - (∑ i : fin E.order, polynomial.monomial i (E.coeffs i))\n\n/-- The geometric sequence `q^n` is a solution of `E` iff\n  `q` is a root of `E`'s characteristic polynomial. -/\nlemma geom_sol_iff_root_char_poly (q : α) : E.is_solution (λ n, q^n) ↔ E.char_poly.is_root q :=\nbegin\n  rw [char_poly, polynomial.is_root.def, polynomial.eval],\n  simp only [polynomial.eval₂_finset_sum, one_mul,\n              ring_hom.id_apply, polynomial.eval₂_monomial, polynomial.eval₂_sub],\n  split,\n  { intro h,\n    simpa [sub_eq_zero] using h 0 },\n  { intros h n,\n    simp only [pow_add, sub_eq_zero.mp h, mul_sum],\n    exact sum_congr rfl (λ _ _, by ring) }\nend\n\nend comm_ring\n\nend linear_recurrence\n", "meta": {"author": "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/linear_recurrence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7515605819525892}}
{"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ölzl, Jens Wagemaker\n\nTheory of univariate polynomials, represented as `ℕ →₀ α`, where α is a commutative semiring.\n-/\nimport data.finsupp algebra.euclidean_domain\n\n/-- `polynomial α` is the type of univariate polynomials over `α`.\n\nPolynomials should be seen as (semi-)rings with the additional the constructor `X`. `C` is the\nembedding from `α`. -/\ndef polynomial (α : Type*) [comm_semiring α] := ℕ →₀ α\n\nopen finsupp finset lattice\n\nnamespace polynomial\nuniverse u\nvariables {α : Type u} {a b : α} {m n : ℕ}\nvariables [decidable_eq α]\n\nsection comm_semiring\nvariables [comm_semiring α] {p q : polynomial α}\n\ninstance : has_coe_to_fun (polynomial α) := finsupp.has_coe_to_fun\ninstance : has_zero (polynomial α) := finsupp.has_zero\ninstance : has_one (polynomial α) := finsupp.has_one\ninstance : has_add (polynomial α) := finsupp.has_add\ninstance : has_mul (polynomial α) := finsupp.has_mul\ninstance : comm_semiring (polynomial α) := finsupp.to_comm_semiring\ninstance : decidable_eq (polynomial α) := finsupp.decidable_eq\n\ninstance [has_repr α] : has_repr (polynomial α) :=\n⟨λ p, if p = 0 then \"0\"\n  else (p.support.sort (≤)).foldr\n    (λ n a, a ++ (if a = \"\" then \"\" else \" + \") ++\n      if n = 0\n        then \"C (\" ++ repr (p n) ++ \")\"\n        else if n = 1\n          then if (p n) = 1 then \"X\" else \"C (\" ++ repr (p n) ++ \") * X\"\n          else if (p n) = 1 then \"X ^ \" ++ repr n\n            else \"C (\" ++ repr (p n) ++ \") * X ^ \" ++ repr n) \"\"⟩\n\nlocal attribute [instance] finsupp.to_comm_semiring\n\n@[simp] lemma support_zero : (0 : polynomial α).support = ∅ := rfl\n\n/-- `C a` is the constant polynomial `a`. -/\ndef C (a : α) : polynomial α := single 0 a\n\n/-- `X` is the polynomial variable (aka indeterminant). -/\ndef X : polynomial α := single 1 1\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 ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise\n`degree 0 = ⊥`. -/\ndef degree (p : polynomial α) : with_bot ℕ := p.support.sup some\n\ndef degree_lt_wf : well_founded (λp q : polynomial α, degree p < degree q) :=\ninv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)\n\n/-- `nat_degree p` forces `degree p` to ℕ, by fixing the zero polnomial to the 0 degree. -/\ndef nat_degree (p : polynomial α) : ℕ := (degree p).get_or_else 0\n\nlemma single_eq_C_mul_X : ∀{n}, single n a = C a * X^n\n| 0     := by simp; refl\n| (n+1) :=\n  calc single (n + 1) a = single n a * X : by rw [X, single_mul_single, mul_one]\n    ... = (C a * X^n) * X : by rw [single_eq_C_mul_X]\n    ... = C a * X^(n+1) : by simp [pow_add, mul_assoc]\n\nlemma sum_C_mul_X_eq (p : polynomial α) : p.sum (λn a, C a * X^n) = p :=\neq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) finsupp.sum_single\n\n@[elab_as_eliminator] protected lemma induction_on {M : polynomial α → Prop} (p : polynomial α)\n  (h_C : ∀a, M (C a))\n  (h_add : ∀p q, M p → M q → M (p + q))\n  (h_monomial : ∀(n : ℕ) (a : α), M (C a * X^n) → M (C a * X^(n+1))) :\n  M p :=\nhave ∀{n:ℕ} {a}, M (C a * X^n),\nbegin\n  assume n a,\n  induction n with n ih,\n  { simp [h_C] },\n  { exact h_monomial _ _ ih }\nend,\nfinsupp.induction p\n  (suffices M (C 0), by simpa [C],\n    h_C 0)\n  (assume n a p _ _ hp, suffices M (C a * X^n + p), by rwa [single_eq_C_mul_X],\n    h_add _ _ this hp)\n\n@[simp] lemma zero_apply (n : ℕ) : (0 : polynomial α) n = 0 := rfl\n\n@[simp] lemma one_apply_zero (n : ℕ) : (1 : polynomial α) 0 = 1 := rfl\n\n@[simp] lemma add_apply (p q : polynomial α) (n : ℕ) : (p + q) n = p n + q n :=\nfinsupp.add_apply\n\nlemma C_apply : (C a : ℕ → α) n = ite (0 = n) a 0 := rfl\n\n@[simp] lemma C_apply_zero : (C a : ℕ → α) 0 = a := rfl\n\n@[simp] lemma X_apply_one : (X : polynomial α) 1 = 1 := rfl\n\n@[simp] lemma C_0 : C (0 : α) = 0 := by simp [C]; refl\n\n@[simp] lemma C_1 : C (1 : α) = 1 := rfl\n\n@[simp] lemma C_mul : C (a * b) = C a * C b :=\nby simp [C, single_mul_single]\n\n@[simp] lemma C_add : C (a + b) = C a + C b := finsupp.single_add\n\ninstance C.is_semiring_hom : is_semiring_hom (C : α → polynomial α) :=\n⟨C_0, C_1, λ _ _, C_add, λ _ _, C_mul⟩\n\n@[simp] lemma C_mul_apply (p : polynomial α) : (C a * p) n = a * p n :=\nbegin\n  conv in (a * _) { rw [← @sum_single _ _ _ _ _ p, sum_apply] },\n  rw [mul_def, C, sum_single_index],\n  { simp [single_apply, finsupp.mul_sum],\n    apply sum_congr rfl,\n    assume i hi, by_cases i = n; simp [h] },\n  simp\nend\n\nlemma C_inj : C a = C b ↔ a = b :=\n⟨λ h, C_apply_zero.symm.trans (h.symm ▸ C_apply_zero), congr_arg C⟩\n\n@[simp] lemma X_pow_apply (n i : ℕ) : (X ^ n : polynomial α) i = (if n = i then 1 else 0) :=\nsuffices (single n 1 : polynomial α) i = (if n = i then 1 else 0),\n  by rw [single_eq_C_mul_X] at this; simpa,\nsingle_apply\n\nsection eval₂\nvariables {β : Type*} [comm_semiring β]\nvariables (f : α → β) [is_semiring_hom f] (x : β)\nopen is_semiring_hom\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 -/\ndef eval₂ (p : polynomial α) : β :=\np.sum (λ e a, f a * x ^ e)\n\n@[simp] lemma eval₂_C : (C a).eval₂ f x = f a :=\nby simp [C, eval₂, sum_single_index, map_zero f]\n\n@[simp] lemma eval₂_X : X.eval₂ f x = x :=\nby simp [X, eval₂, sum_single_index, map_zero f, map_one f]\n\n@[simp] lemma eval₂_zero : (0 : polynomial α).eval₂ f x = 0 :=\nfinsupp.sum_zero_index\n\n@[simp] lemma eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x :=\nfinsupp.sum_add_index (by simp [map_zero f]) (by simp [add_mul, map_add f])\n\n@[simp] lemma eval₂_one : (1 : polynomial α).eval₂ f x = 1 :=\nby rw [← C_1, eval₂_C, map_one f]\n\n@[simp] lemma eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x :=\nbegin\n  dunfold eval₂,\n  rw [mul_def, finsupp.sum_mul _ p],\n  simp [finsupp.mul_sum _ q, sum_sum_index, map_zero f, map_add f, add_mul,\n    sum_single_index, map_mul f, pow_add],\n  exact sum_congr rfl (assume i hi, sum_congr rfl $ assume j hj, by ac_refl)\nend\n\ninstance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f x) :=\n⟨eval₂_zero _ _, eval₂_one _ _, λ _ _, eval₂_add _ _, λ _ _, eval₂_mul _ _⟩\n\nlemma eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n := map_pow _ _ _\n\nend eval₂\n\nsection eval\nvariable {x : α}\n\n/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/\ndef eval : α → polynomial α → α := eval₂ id\n\n@[simp] lemma eval_C : (C a).eval x = a := eval₂_C _ _\n\n@[simp] lemma eval_X : X.eval x = x := eval₂_X _ _\n\n@[simp] lemma eval_zero : (0 : polynomial α).eval x = 0 :=  eval₂_zero _ _\n\n@[simp] lemma eval_add : (p + q).eval x = p.eval x + q.eval x := eval₂_add _ _\n\n@[simp] lemma eval_one : (1 : polynomial α).eval x = 1 := eval₂_one _ _\n\n@[simp] lemma eval_mul : (p * q).eval x = p.eval x * q.eval x := eval₂_mul _ _\n\ninstance eval.is_semiring_hom : is_semiring_hom (eval x) := eval₂.is_semiring_hom _ _\n\nlemma eval_pow (n : ℕ) : (p ^ n).eval x = p.eval x ^ n := eval₂_pow _ _ _\n\n/-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/\ndef is_root (p : polynomial α) (a : α) : Prop := p.eval a = 0\n\ninstance : decidable (is_root p a) := by unfold is_root; apply_instance\n\n@[simp] lemma is_root.def : is_root p a ↔ p.eval a = 0 := iff.rfl\n\nlemma root_mul_left_of_is_root (p : polynomial α) {q : polynomial α} :\n  is_root q a → is_root (p * q) a :=\nby simp [is_root.def, eval_mul] {contextual := tt}\n\nlemma root_mul_right_of_is_root {p : polynomial α} (q : polynomial α) :\n  is_root p a → is_root (p * q) a :=\nby simp [is_root.def, eval_mul] {contextual := tt}\n\nend eval\n\nsection map\nvariables {β : Type*} [comm_semiring β] [decidable_eq β]\nvariables (f : α → β) [is_semiring_hom f]\n\n/-- `map f p` maps a polynomial `p` across a ring hom `f` -/\ndef map : polynomial α → polynomial β := eval₂ (C ∘ f) X\n\n@[simp] lemma map_C : (C a).map f = C (f a) := eval₂_C _ _\n\n@[simp] lemma map_X : X.map f = X := eval₂_X _ _\n\n@[simp] lemma map_zero : (0 : polynomial α).map f = 0 :=  eval₂_zero _ _\n\n@[simp] lemma map_add : (p + q).map f = p.map f + q.map f := eval₂_add _ _\n\n@[simp] lemma map_one : (1 : polynomial α).map f = 1 := eval₂_one _ _\n\n@[simp] lemma map_mul : (p * q).map f = p.map f * q.map f := eval₂_mul _ _\n\ninstance map.is_semiring_hom : is_semiring_hom (map f) := eval₂.is_semiring_hom _ _\n\nlemma map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n := eval₂_pow _ _ _\n\nend map\n\n/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/\ndef leading_coeff (p : polynomial α) : α := p (nat_degree p)\n\n/-- a polynomial is `monic` if its leading coefficient is 1 -/\ndef monic (p : polynomial α) := leading_coeff p = (1 : α)\n\nlemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl\n\ninstance monic.decidable : decidable (monic p) :=\nby unfold monic; apply_instance\n\n@[simp] lemma degree_zero : degree (0 : polynomial α) = ⊥ := rfl\n\n@[simp] lemma nat_degree_zero : nat_degree (0 : polynomial α) = 0 :=\nby simp [nat_degree]; refl\n\n@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=\nshow sup (ite (a = 0) ∅ {0}) some = 0,\nby rw [if_neg ha]; refl\n\nlemma degree_C_le : degree (C a) ≤ (0 : with_bot ℕ) :=\nby by_cases h : a = 0; simp [h]; exact le_refl _\n\nlemma degree_one_le : degree (1 : polynomial α) ≤ (0 : with_bot ℕ) :=\nby rw [← C_1]; exact degree_C_le\n\nlemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=\n⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h;\n  exact support_eq_empty.1 (max_eq_none.1 h),\nλ h, h.symm ▸ rfl⟩\n\nlemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=\nlet ⟨n, hn⟩ :=\n  classical.not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in\nhave hn : degree p = some n := not_not.1 hn,\nby rw [nat_degree, hn]; refl\n\n@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=\nbegin\n  by_cases hp : p = 0, { simp [hp] },\n  rw [degree_eq_nat_degree hp],\n  exact le_refl _\nend\n\nlemma nat_degree_eq_of_degree_eq (h : degree p = degree q) : nat_degree p = nat_degree q :=\nby unfold nat_degree; rw h\n\nlemma le_degree_of_ne_zero (h : p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=\nshow @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),\nfrom finset.le_sup ((finsupp.mem_support_iff _ _).2 h)\n\nlemma le_nat_degree_of_ne_zero (h : p n ≠ 0) : n ≤ nat_degree p :=\nbegin\n  rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],\n  exact le_degree_of_ne_zero h,\n  { assume h, subst h, exact h rfl }\nend\n\nlemma degree_le_degree (h : q (nat_degree p) ≠ 0) : degree p ≤ degree q :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp] },\n  { rw [degree_eq_nat_degree hp], exact le_degree_of_ne_zero h }\nend\n\n@[simp] lemma nat_degree_C (a : α) : nat_degree (C a) = 0 :=\nbegin\n  by_cases ha : a = 0,\n  { have : C a = 0, { simp [ha] },\n    rw [nat_degree, degree_eq_bot.2 this],\n    refl },\n  { rw [nat_degree, degree_C ha], refl }\nend\n\n@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=\nby rw [← single_eq_C_mul_X, degree, support_single_ne_zero ha]; refl\n\nlemma degree_monomial_le (n : ℕ) (a : α) : degree (C a * X ^ n) ≤ n :=\nif h : a = 0 then by simp [h] else le_of_eq (degree_monomial n h)\n\nlemma eq_zero_of_degree_lt (h : degree p < n) : p n = 0 :=\nnot_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))\n\nlemma apply_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) : p (nat_degree q) = 0 :=\neq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)\n\nlemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=\nmt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))\n\nlemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (p 0) :=\nbegin\n  ext n,\n  cases n,\n  { refl },\n  { have : degree p < ↑(nat.succ n) := lt_of_le_of_lt h (with_bot.some_lt_some.2 (nat.succ_pos _)),\n    rw [C_apply, if_neg (nat.succ_ne_zero _).symm, eq_zero_of_degree_lt this] }\nend\n\nlemma degree_add_le (p q : polynomial α) : degree (p + q) ≤ max (degree p) (degree q) :=\ncalc degree (p + q) = ((p + q).support).sup some : rfl\n  ... ≤ (p.support ∪ q.support).sup some : sup_mono support_add\n  ... = p.support.sup some ⊔ q.support.sup some : sup_union\n  ... = _ : with_bot.sup_eq_max _ _\n\n@[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial α) = 0 := rfl\n\n@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=\n⟨λ h, by_contradiction $ λ hp, mt (mem_support_iff _ _).1\n  (not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),\nby simp {contextual := tt}⟩\n\nlemma degree_add_eq_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=\nle_antisymm (max_eq_right_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $\n  begin\n    rw [add_apply, apply_nat_degree_eq_zero_of_degree_lt h, zero_add],\n    exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)\n  end\n\nlemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :\n  degree (p + q) = max p.degree q.degree :=\nle_antisymm (degree_add_le _ _) $\n  match lt_trichotomy (degree p) (degree q) with\n  | or.inl hlt :=\n    by rw [degree_add_eq_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _\n  | or.inr (or.inl heq) :=\n    le_of_not_gt $\n      assume hlt : max (degree p) (degree q) > degree (p + q),\n      h $ show leading_coeff p + leading_coeff q = 0,\n      begin\n        rw [heq, max_self] at hlt,\n        rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← add_apply],\n        exact apply_nat_degree_eq_zero_of_degree_lt hlt\n      end\n  | or.inr (or.inr hlt) :=\n    by rw [add_comm, degree_add_eq_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _\n  end\n\nlemma degree_erase_le (p : polynomial α) (n : ℕ) : degree (p.erase n) ≤ degree p :=\nsup_mono (erase_subset _ _)\n\nlemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=\nlt_of_le_of_ne (degree_erase_le _ _) $\n  (degree_eq_nat_degree hp).symm ▸ λ h, not_mem_erase _ _ (mem_of_max h)\n\nlemma degree_sum_le {β : Type*} [decidable_eq β] (s : finset β) (f : β → polynomial α) :\n  degree (s.sum f) ≤ s.sup (degree ∘ f) :=\nfinset.induction_on s (by simp [finsupp.support_zero]) $\n  assume a s has ih,\n  calc degree (sum (insert a s) f) ≤ max (degree (f a)) (degree (s.sum f)) :\n    by rw sum_insert has; exact degree_add_le _ _\n  ... ≤ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih\n\nlemma degree_mul_le (p q : polynomial α) : degree (p * q) ≤ degree p + degree q :=\ncalc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (p i * a) * X ^ (i + j)))) :\n    by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _\n  ... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (p i * q j) * X ^ (i + j)))) :\n    finset.sup_mono_fun (assume i hi,  degree_sum_le _ _)\n  ... ≤ degree p + degree q :\n    begin\n      refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_monomial_le _ _) _)),\n      rw [with_bot.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    end\n\nlemma degree_pow_le (p : polynomial α) : ∀ n, degree (p ^ n) ≤ add_monoid.smul n (degree p)\n| 0     := by rw [pow_zero, add_monoid.zero_smul]; exact degree_one_le\n| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :\n    by rw pow_succ; exact degree_mul_le _ _\n  ... ≤ _ : by rw succ_smul; exact add_le_add' (le_refl _) (degree_pow_le _)\n\n@[simp] lemma leading_coeff_monomial (a : α) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=\nbegin\n  by_cases ha : a = 0,\n  { simp [ha] },\n  { rw [leading_coeff, nat_degree, degree_monomial _ ha, ← single_eq_C_mul_X],\n    exact finsupp.single_eq_same }\nend\n\n@[simp] lemma leading_coeff_C (a : α) : leading_coeff (C a) = a :=\nsuffices leading_coeff (C a * X^0) = a, by simpa,\nleading_coeff_monomial a 0\n\n@[simp] lemma leading_coeff_X : leading_coeff (X : polynomial α) = 1 :=\nsuffices leading_coeff (C (1:α) * X^1) = 1, by simpa,\nleading_coeff_monomial 1 1\n\n@[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial α) = 1 :=\nsuffices leading_coeff (C (1:α) * X^0) = 1, by simpa,\nleading_coeff_monomial 1 0\n\n@[simp] lemma monic_one : monic (1 : polynomial α) := leading_coeff_C _\n\nlemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :\n  leading_coeff (p + q) = leading_coeff q :=\nhave p (nat_degree q) = 0, from apply_nat_degree_eq_zero_of_degree_lt h,\nby simp [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_of_degree_lt h), this]\n\nlemma leading_coeff_add_of_degree_eq (h : degree p = degree q)\n  (hlc : leading_coeff p + leading_coeff q ≠ 0) :\n  leading_coeff (p + q) = leading_coeff p + leading_coeff q :=\nhave nat_degree (p + q) = nat_degree p,\n  by apply nat_degree_eq_of_degree_eq; rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],\nby simp [leading_coeff, this, nat_degree_eq_of_degree_eq h]\n\n@[simp] lemma mul_apply_degree_add_degree (p q : polynomial α) :\n  (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=\nhave ∀i, p i ≠ 0 → i ≠ nat_degree p →\n    q.support.sum (λj, ite (i + j = nat_degree p + nat_degree q) (p i * q j) 0) = 0,\nbegin\n  assume i hpi hid,\n  rw [finset.sum_eq_single (nat_degree q)]; simp [hid],\n  assume j hqj hjd,\n  have hi : j < nat_degree q, from lt_of_le_of_ne (le_nat_degree_of_ne_zero hqj) hjd,\n  have hj : i < nat_degree p, from lt_of_le_of_ne (le_nat_degree_of_ne_zero hpi) hid,\n  exact if_neg (ne_of_lt $ add_lt_add hj hi)\nend,\nbegin\n  rw [mul_def, sum_apply, finsupp.sum, finset.sum_eq_single (nat_degree p),\n      sum_apply, finsupp.sum, finset.sum_eq_single (nat_degree q)];\n    simp [single_apply, leading_coeff] {contextual := tt},\n  assumption\nend\n\nlemma degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  degree (p * q) = degree p + degree q :=\nhave hp : p ≠ 0 := by refine mt _ h; simp {contextual := tt},\nhave hq : q ≠ 0 := by refine mt _ h; by simp {contextual := tt},\nle_antisymm (degree_mul_le _ _)\nbegin\n  rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],\n  refine le_degree_of_ne_zero _,\n  rwa mul_apply_degree_add_degree\nend\n\nlemma nat_degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  nat_degree (p * q) = nat_degree p + nat_degree q :=\nhave hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, by simpa [h₁] using h),\nhave hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, by simpa [h₁] using h),\nhave hpq : p * q ≠ 0 := λ hpq, by rw [← mul_apply_degree_add_degree, hpq, zero_apply] at h;\n  exact h rfl,\noption.some_inj.1 (show (nat_degree (p * q) : with_bot ℕ) = nat_degree p + nat_degree q,\n  by rw [← degree_eq_nat_degree hpq, degree_mul_eq' h, degree_eq_nat_degree hp, degree_eq_nat_degree hq])\n\nlemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :\n  leading_coeff (p * q) = leading_coeff p * leading_coeff q :=\nbegin\n  unfold leading_coeff,\n  rw [nat_degree_mul_eq' h, mul_apply_degree_add_degree],\n  refl\nend\n\nlemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →\n  leading_coeff (p ^ n) = leading_coeff p ^ n :=\nnat.rec_on n (by simp) $\nλ n ih h,\nhave h₁ : leading_coeff p ^ n ≠ 0 :=\n  λ h₁, by simpa [h₁, pow_succ] using h,\nhave h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=\n  by rwa [pow_succ, ← ih h₁] at h,\nby rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]\n\nlemma degree_pow_eq' : ∀ {n}, leading_coeff p ^ n ≠ 0 →\n  degree (p ^ n) = add_monoid.smul n (degree p)\n| 0     := λ h, by rw [pow_zero, ← C_1] at *;\n  rw [degree_C h, add_monoid.zero_smul]\n| (n+1) := λ h,\nhave h₁ : leading_coeff p ^ n ≠ 0 := λ h₁,\n  by simpa [h₁, pow_succ] using h,\nhave h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=\n  by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,\nby rw [pow_succ, degree_mul_eq' h₂, succ_smul, degree_pow_eq' h₁]\n\n@[simp] lemma leading_coeff_X_pow : ∀ n : ℕ, leading_coeff ((X : polynomial α) ^ n) = 1\n| 0 := by simp\n| (n+1) :=\nif h10 : (1 : α) = 0\nthen by rw [pow_succ, ← one_mul X, ← C_1, h10]; simp\nelse\nhave h : leading_coeff (X : polynomial α) * leading_coeff (X ^ n) ≠ 0,\n  by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul];\n    exact h10,\nby rw [pow_succ, leading_coeff_mul' h, leading_coeff_X, leading_coeff_X_pow, one_mul]\n\nend comm_semiring\n\nsection comm_ring\nvariables [comm_ring α] {p q : polynomial α}\ninstance : comm_ring (polynomial α) := finsupp.to_comm_ring\ninstance : has_scalar α (polynomial α) := finsupp.to_has_scalar\ninstance : module α (polynomial α) := finsupp.to_module α\n\ninstance C.is_ring_hom : is_ring_hom (@C α _ _) := by apply is_ring_hom.of_semiring\n\ninstance eval₂.is_ring_hom {β} [comm_ring β]\n  (f : α → β) [is_ring_hom f] {x : β} : is_ring_hom (eval₂ f x) :=\nby apply is_ring_hom.of_semiring\n\ninstance eval.is_ring_hom {x : α} : is_ring_hom (eval x) := eval₂.is_ring_hom _\n\ninstance map.is_ring_hom {β} [comm_ring β] [decidable_eq β]\n  (f : α → β) [is_ring_hom f] : is_ring_hom (map f) :=\neval₂.is_ring_hom (C ∘ f)\n\n@[simp] lemma degree_neg (p : polynomial α) : degree (-p) = degree p :=\nby unfold degree; rw support_neg\n\n@[simp] lemma neg_apply (p : polynomial α) (n : ℕ) : (-p) n = -p n := neg_apply\n\n@[simp] lemma eval_neg (p : polynomial α) (x : α) : (-p).eval x = -p.eval x :=\nis_ring_hom.map_neg _\n\n@[simp] lemma eval_sub (p q : polynomial α) (x : α) : (p - q).eval x = p.eval x - q.eval x :=\nis_ring_hom.map_sub _\n\nlemma degree_sub_lt (hd : degree p = degree q)\n  (hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :\n  degree (p - q) < degree p :=\nhave hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=\n  finsupp.single_add_erase,\nhave hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=\n  finsupp.single_add_erase,\nhave hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,\nhave hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),\ncalc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :\n  by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]}\n... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))\n  : degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _\n... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩\n\ninstance : has_well_founded (polynomial α) := ⟨_, degree_lt_wf⟩\n\nlemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0\n| h := begin\n  rw [h, monic.def, leading_coeff_zero] at hq,\n  rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp,\n  exact hp rfl\nend\n\nlemma div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : monic q) :\n  degree (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) < degree p :=\nhave hp : leading_coeff p ≠ 0 := mt leading_coeff_eq_zero.1 h.2,\nhave hpq : leading_coeff (C (leading_coeff p) * X ^ (nat_degree p - nat_degree q)) *\n    leading_coeff q ≠ 0,\n  by rwa [leading_coeff_monomial, monic.def.1 hq, mul_one],\nif h0 : p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q = 0\nthen h0.symm ▸ (lt_of_not_ge $ mt le_bot_iff.1 (mt degree_eq_bot.1 h.2))\nelse\n  have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic h.2 hq,\n  have hlt : nat_degree q ≤ nat_degree p := with_bot.coe_le_coe.1\n    (by rw [← degree_eq_nat_degree h.2, ← degree_eq_nat_degree hq0];\n    exact h.1),\n  degree_sub_lt\n  (by rw [degree_mul_eq' hpq, degree_monomial _ hp, degree_eq_nat_degree h.2,\n      degree_eq_nat_degree hq0, ← with_bot.coe_add, nat.sub_add_cancel hlt])\n  h.2\n  (by rw [leading_coeff_mul' hpq, leading_coeff_monomial, monic.def.1 hq, mul_one])\n\ndef div_mod_by_monic_aux : Π (p : polynomial α) {q : polynomial α},\n  monic q → polynomial α × polynomial α\n| p := λ q hq, if h : degree q ≤ degree p ∧ p ≠ 0 then\n  let z := C (leading_coeff p) * X^(nat_degree p - nat_degree q)  in\n  have wf : _ := div_wf_lemma h hq,\n  let dm := div_mod_by_monic_aux (p - z * q) hq in\n  ⟨z + dm.1, dm.2⟩\n  else ⟨0, p⟩\nusing_well_founded {dec_tac := tactic.assumption}\n\n/-- `div_by_monic` gives the quotient of `p` by a monic polynomial `q`. -/\ndef div_by_monic (p q : polynomial α) : polynomial α :=\nif hq : monic q then (div_mod_by_monic_aux p hq).1 else 0\n\n/-- `mod_by_monic` gives the remainder of `p` by a monic polynomial `q`. -/\ndef mod_by_monic (p q : polynomial α) : polynomial α :=\nif hq : monic q then (div_mod_by_monic_aux p hq).2 else p\n\ninfixl  ` /ₘ ` : 70 := div_by_monic\n\ninfixl ` %ₘ ` : 70 := mod_by_monic\n\nlemma degree_mod_by_monic_lt : ∀ (p : polynomial α) {q : polynomial α} (hq : monic q)\n  (hq0 : q ≠ 0), degree (p %ₘ q) < degree q\n| p := λ q hq hq0,\nif h : degree q ≤ degree p ∧ p ≠ 0 then\n  have wf : _ := div_wf_lemma ⟨h.1, h.2⟩ hq,\n  have degree ((p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) %ₘ q) < degree q :=\n      degree_mod_by_monic_lt (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q)\n      hq hq0,\n  begin\n    unfold mod_by_monic at this ⊢,\n    unfold div_mod_by_monic_aux,\n    rw dif_pos hq at this ⊢,\n    rw if_pos h,\n    exact this\n  end\nelse\n  or.cases_on (not_and_distrib.1 h) begin\n    unfold mod_by_monic div_mod_by_monic_aux,\n    rw [dif_pos hq, if_neg h],\n    exact lt_of_not_ge,\n  end\n  begin\n    assume hp,\n    unfold mod_by_monic div_mod_by_monic_aux,\n    rw [dif_pos hq, if_neg h, not_not.1 hp],\n    exact lt_of_le_of_ne bot_le\n      (ne.symm (mt degree_eq_bot.1 hq0)),\n  end\nusing_well_founded {dec_tac := tactic.assumption}\n\nlemma mod_by_monic_eq_sub_mul_div : ∀ (p : polynomial α) {q : polynomial α} (hq : monic q),\n  p %ₘ q = p - q * (p /ₘ q)\n| p := λ q hq,\n  if h : degree q ≤ degree p ∧ p ≠ 0 then\n    have wf : _ := div_wf_lemma h hq,\n    have ih : _ := mod_by_monic_eq_sub_mul_div\n      (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq,\n    begin\n      unfold mod_by_monic div_by_monic div_mod_by_monic_aux,\n      rw [dif_pos hq, if_pos h],\n      rw [mod_by_monic, dif_pos hq] at ih,\n      refine ih.trans _,\n      simp [mul_add, add_mul, mul_comm, hq, h, div_by_monic]\n    end\n  else\n    begin\n      unfold mod_by_monic div_by_monic div_mod_by_monic_aux,\n      rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h],\n      simp\n    end\nusing_well_founded {dec_tac := tactic.assumption}\n\nlemma subsingleton_of_monic_zero (h : monic (0 : polynomial α)) :\n  (∀ p q : polynomial α, p = q) ∧ (∀ a b : α, a = b) :=\nby rw [monic.def, leading_coeff_zero] at h;\n  exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero],\n    λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩\n\nlemma mod_by_monic_add_div (p : polynomial α) {q : polynomial α} (hq : monic q) :\n  p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (mod_by_monic_eq_sub_mul_div p hq)\n\n@[simp] lemma zero_mod_by_monic (p : polynomial α) : 0 %ₘ p = 0 :=\nbegin\n  unfold mod_by_monic div_mod_by_monic_aux,\n  split_ifs;\n  simp * at *\nend\n\n@[simp] lemma zero_div_by_monic (p : polynomial α) : 0 /ₘ p = 0 :=\nbegin\n  unfold div_by_monic div_mod_by_monic_aux,\n  split_ifs;\n  simp * at *\nend\n\n@[simp] lemma mod_by_monic_zero (p : polynomial α) : p %ₘ 0 = p :=\nif h : monic (0 : polynomial α) then (subsingleton_of_monic_zero h).1 _ _ else\nbegin\n  unfold mod_by_monic div_mod_by_monic_aux,\n  split_ifs;\n  simp * at *\nend\n\n@[simp] lemma div_by_monic_zero (p : polynomial α) : p /ₘ 0 = 0 :=\nif h : monic (0 : polynomial α) then (subsingleton_of_monic_zero h).1 _ _ else\nbegin\n  unfold div_by_monic div_mod_by_monic_aux,\n  split_ifs;\n  simp * at *\nend\n\nlemma div_by_monic_eq_of_not_monic (p : polynomial α) (hq : ¬monic q) : p /ₘ q = 0 := dif_neg hq\n\nlemma mod_by_monic_eq_of_not_monic (p : polynomial α) (hq : ¬monic q) : p %ₘ q = p := dif_neg hq\n\nlemma mod_by_monic_eq_self_iff (hq : monic q) (hq0 : q ≠ 0) : p %ₘ q = p ↔ degree p < degree q :=\n⟨λ h, h ▸ degree_mod_by_monic_lt _ hq hq0,\nλ h, have ¬ degree q ≤ degree p := not_le_of_gt h,\n  by unfold mod_by_monic div_mod_by_monic_aux; simp *⟩\n\nlemma div_by_monic_eq_zero_iff (hq : monic q) (hq0 : q ≠ 0) : p /ₘ q = 0 ↔ degree p < degree q :=\n⟨λ h, by have := mod_by_monic_add_div p hq;\n  rwa [h, mul_zero, add_zero, mod_by_monic_eq_self_iff hq hq0] at this,\nλ h, have ¬ degree q ≤ degree p := not_le_of_gt h,\n  by unfold div_by_monic div_mod_by_monic_aux; simp *⟩\n\nlemma degree_add_div_by_monic (hq : monic q) (h : degree q ≤ degree p) :\n  degree q + degree (p /ₘ q) = degree p :=\nif hq0 : q = 0 then\n  have ∀ (p : polynomial α), p = 0,\n    from λ p, (@subsingleton_of_monic_zero α _ _ (hq0 ▸ hq)).1 _ _,\n  by rw [this (p /ₘ q), this p, this q]; refl\nelse\nhave hdiv0 : p /ₘ q ≠ 0 := by rwa [(≠), div_by_monic_eq_zero_iff hq hq0, not_lt],\nhave hlc : leading_coeff q * leading_coeff (p /ₘ q) ≠ 0 :=\n  by rwa [monic.def.1 hq, one_mul, (≠), leading_coeff_eq_zero],\nhave hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) :=\n  calc degree (p %ₘ q) < degree q : degree_mod_by_monic_lt _ hq hq0\n  ... ≤ _ : by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0,\n      degree_eq_nat_degree hdiv0, ← with_bot.coe_add, with_bot.coe_le_coe];\n    exact nat.le_add_right _ _,\ncalc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) : eq.symm (degree_mul_eq' hlc)\n... = degree (p %ₘ q + q * (p /ₘ q)) : (degree_add_eq_of_degree_lt hmod).symm\n... = _ : congr_arg _ (mod_by_monic_add_div _ hq)\n\nlemma degree_div_by_monic_le (p q : polynomial α) : degree (p /ₘ q) ≤ degree p :=\nif hp0 : p = 0 then by simp [hp0]\nelse if hq : monic q then\n  have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq,\n  if h : degree q ≤ degree p\n  then by rw [← degree_add_div_by_monic hq h, degree_eq_nat_degree hq0,\n      degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 (not_lt.2 h))];\n    exact with_bot.coe_le_coe.2 (nat.le_add_left _ _)\n  else\n    by unfold div_by_monic div_mod_by_monic_aux;\n      simp [dif_pos hq, h]\nelse (div_by_monic_eq_of_not_monic p hq).symm ▸ bot_le\n\nlemma degree_div_by_monic_lt (p : polynomial α) {q : polynomial α} (hq : monic q)\n  (hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p :=\nhave hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq,\nif hpq : degree p < degree q\nthen begin\n  rw [(div_by_monic_eq_zero_iff hq hq0).2 hpq, degree_eq_nat_degree hp0],\n  exact with_bot.bot_lt_some _\nend\nelse begin\n  rw [← degree_add_div_by_monic hq (not_lt.1 hpq), degree_eq_nat_degree hq0,\n        degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 hpq)],\n  exact with_bot.coe_lt_coe.2 (nat.lt_add_of_pos_left\n    (with_bot.coe_lt_coe.1 $ (degree_eq_nat_degree hq0) ▸ h0q))\nend\n\nlemma dvd_iff_mod_by_monic_eq_zero (hq : monic q) : p %ₘ q = 0 ↔ q ∣ p :=\n⟨λ h, by rw [← mod_by_monic_add_div p hq, h, zero_add];\n  exact dvd_mul_right _ _,\nλ h, if hq0 : q = 0 then by rw hq0 at hq;\n  exact (subsingleton_of_monic_zero hq).1 _ _\n  else\n  let ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h in\n  by_contradiction (λ hpq0,\n  have hmod : p %ₘ q = q * (r - p /ₘ q) :=\n    by rw [mod_by_monic_eq_sub_mul_div _ hq, mul_sub, ← hr],\n  have degree (q * (r - p /ₘ q)) < degree q :=\n    hmod ▸ degree_mod_by_monic_lt _ hq hq0,\n  have hrpq0 : leading_coeff (r - p /ₘ q) ≠ 0 :=\n    λ h, hpq0 $ leading_coeff_eq_zero.1\n      (by rw [hmod, leading_coeff_eq_zero.1 h, mul_zero, leading_coeff_zero]),\n  have hlc : leading_coeff q * leading_coeff (r - p /ₘ q) ≠ 0 :=\n    by rwa [monic.def.1 hq, one_mul],\n  by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0,\n      degree_eq_nat_degree (mt leading_coeff_eq_zero.2 hrpq0)] at this;\n    exact not_lt_of_ge (nat.le_add_right _ _) (with_bot.some_lt_some.1 this))⟩\n\nend comm_ring\n\nsection nonzero_comm_ring\nvariables [nonzero_comm_ring α] {p q : polynomial α}\n\ninstance : nonzero_comm_ring (polynomial α) :=\n{ zero_ne_one := λ (h : (0 : polynomial α) = 1),\n    @zero_ne_one α _ $\n    calc (0 : α) = eval 0 0 : eval_zero.symm\n      ... = eval 0 1 : congr_arg _ h\n      ... = 1 : eval_C,\n  ..polynomial.comm_ring }\n\n@[simp] lemma degree_one : degree (1 : polynomial α) = (0 : with_bot ℕ) :=\ndegree_C (show (1 : α) ≠ 0, from zero_ne_one.symm)\n\n@[simp] lemma degree_X : degree (X : polynomial α) = 1 :=\nbegin\n  unfold X degree single finsupp.support,\n  rw if_neg (zero_ne_one).symm,\n  refl\nend\n\n@[simp] lemma degree_X_sub_C (a : α) : degree (X - C a) = 1 :=\nbegin\n  rw [sub_eq_add_neg, add_comm, ← @degree_X α],\n  by_cases ha : a = 0,\n  { simp [ha] },\n  exact degree_add_eq_of_degree_lt (by rw [degree_X, degree_neg, degree_C ha]; exact dec_trivial)\nend\n\n@[simp] lemma degree_X_pow : ∀ (n : ℕ), degree ((X : polynomial α) ^ n) = n\n| 0 := by simp; refl\n| (n+1) :=\nhave h : leading_coeff (X : polynomial α) * leading_coeff (X ^ n) ≠ 0,\n  by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul];\n    exact zero_ne_one.symm,\nby rw [pow_succ, degree_mul_eq' h, degree_X, degree_X_pow, add_comm]; refl\n\nlemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : α) :\n  degree ((X : polynomial α) ^ n - C a) = n :=\nhave degree (-C a) < degree ((X : polynomial α) ^ n),\n  from calc degree (-C a) ≤ 0 : by rw degree_neg; exact degree_C_le\n  ... < degree ((X : polynomial α) ^ n) : by rwa [degree_X_pow];\n    exact with_bot.coe_lt_coe.2 hn,\nby rw [sub_eq_add_neg, add_comm, degree_add_eq_of_degree_lt this, degree_X_pow]\n\nlemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : α) :\n  (X : polynomial α) ^ n - C a ≠ 0 :=\nmt degree_eq_bot.2 (show degree ((X : polynomial α) ^ n - C a) ≠ ⊥,\n  by rw degree_X_pow_sub_C hn; exact dec_trivial)\n\n@[simp] lemma not_monic_zero : ¬monic (0 : polynomial α) :=\nby simp [monic, zero_ne_one]\n\nlemma ne_zero_of_monic (h : monic p) : p ≠ 0 :=\nλ h₁, @not_monic_zero α _ _ (h₁ ▸ h)\n\nlemma monic_X_sub_C (a : α) : monic (X - C a) :=\nhave degree (-C a) < degree (X : polynomial α) :=\nif ha : a = 0 then by simp [ha]; exact dec_trivial else by simp [degree_C ha]; exact dec_trivial,\nby unfold monic;\n  rw [sub_eq_add_neg, add_comm, leading_coeff_add_of_degree_lt this, leading_coeff_X]\n\nlemma root_X_sub_C : is_root (X - C a) b ↔ a = b :=\nby rw [is_root.def, eval_sub, eval_X, eval_C, sub_eq_zero_iff_eq, eq_comm]\n\n@[simp] lemma mod_by_monic_X_sub_C_eq_C_eval (p : polynomial α) (a : α) : p %ₘ (X - C a) = C (p.eval a) :=\nhave h : (p %ₘ (X - C a)).eval a = p.eval a :=\n  by rw [mod_by_monic_eq_sub_mul_div _ (monic_X_sub_C a), eval_sub, eval_mul,\n    eval_sub, eval_X, eval_C, sub_self, zero_mul, sub_zero],\nhave degree (p %ₘ (X - C a)) < 1 :=\n  degree_X_sub_C a ▸ degree_mod_by_monic_lt p (monic_X_sub_C a) ((degree_X_sub_C a).symm ▸\n    ne_zero_of_monic (monic_X_sub_C _)),\nhave degree (p %ₘ (X - C a)) ≤ 0 :=\n  begin\n    cases (degree (p %ₘ (X - C a))),\n    { exact bot_le },\n    { exact with_bot.some_le_some.2 (nat.le_of_lt_succ (with_bot.some_lt_some.1 this)) }\n  end,\nbegin\n  rw [eq_C_of_degree_le_zero this, eval_C] at h,\n  rw [eq_C_of_degree_le_zero this, h]\nend\n\nlemma mul_div_by_monic_eq_iff_is_root : (X - C a) * (p /ₘ (X - C a)) = p ↔ is_root p a :=\n⟨λ h, by rw [← h, is_root.def, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul],\nλ h : p.eval a = 0,\n  by conv {to_rhs, rw ← mod_by_monic_add_div p (monic_X_sub_C a)};\n    rw [mod_by_monic_X_sub_C_eq_C_eval, h, C_0, zero_add]⟩\n\nlemma dvd_iff_is_root : (X - C a) ∣ p ↔ is_root p a :=\n⟨λ h, by rwa [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _),\n    mod_by_monic_X_sub_C_eq_C_eval, ← C_0, C_inj] at h,\n  λ h, ⟨(p /ₘ (X - C a)), by rw mul_div_by_monic_eq_iff_is_root.2 h⟩⟩\n\nend nonzero_comm_ring\n\nsection integral_domain\nvariables [integral_domain α] {p q : polynomial α}\n\n@[simp] lemma degree_mul_eq : degree (p * q) = degree p + degree q :=\nif hp0 : p = 0 then by simp [hp0]\nelse if hq0 : q = 0 then  by simp [hq0]\nelse degree_mul_eq' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)\n    (mt leading_coeff_eq_zero.1 hq0)\n\n@[simp] lemma degree_pow_eq (p : polynomial α) (n : ℕ) :\n  degree (p ^ n) = add_monoid.smul n (degree p) :=\nby induction n; simp [*, pow_succ, succ_smul]\n\n@[simp] lemma leading_coeff_mul (p q : polynomial α) : leading_coeff (p * q) =\n  leading_coeff p * leading_coeff q :=\nbegin\n  by_cases hp : p = 0,\n  { simp [hp] },\n  { by_cases hq : q = 0,\n    { simp [hq] },\n    { rw [leading_coeff_mul'],\n      exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }\nend\n\n@[simp] lemma leading_coeff_pow (p : polynomial α) (n : ℕ) :\n  leading_coeff (p ^ n) = leading_coeff p ^ n :=\nby induction n; simp [*, pow_succ]\n\ninstance : integral_domain (polynomial α) :=\n{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h, begin\n    have : leading_coeff 0 = leading_coeff a * leading_coeff b := h ▸ leading_coeff_mul a b,\n    rw [leading_coeff_zero, eq_comm] at this,\n    rw [← leading_coeff_eq_zero, ← leading_coeff_eq_zero],\n    exact eq_zero_or_eq_zero_of_mul_eq_zero this\n  end,\n  ..polynomial.nonzero_comm_ring }\n\nlemma root_or_root_of_root_mul (h : is_root (p * q) a) : is_root p a ∨ is_root q a :=\nby rw [is_root, eval_mul] at h;\n  exact eq_zero_or_eq_zero_of_mul_eq_zero h\n\nlemma degree_pos_of_root (hp : p ≠ 0) (h : is_root p a) : 0 < degree p :=\nlt_of_not_ge $ λ hlt, begin\n  have := eq_C_of_degree_le_zero hlt,\n  rw [is_root, this, eval_C] at h,\n  exact hp (ext (λ n, show p n = 0, from\n    nat.cases_on n h (λ _, eq_zero_of_degree_lt (lt_of_le_of_lt hlt\n      (with_bot.coe_lt_coe.2 (nat.succ_pos _)))))),\nend\n\nlemma degree_le_mul_left (p : polynomial α) (hq : q ≠ 0) : degree p ≤ degree (p * q) :=\nif hp : p = 0 then by simp [hp]\nelse by rw [degree_mul_eq, degree_eq_nat_degree hp,\n    degree_eq_nat_degree hq];\n  exact with_bot.coe_le_coe.2 (nat.le_add_right _ _)\n\nlemma exists_finset_roots : ∀ {p : polynomial α} (hp : p ≠ 0),\n  ∃ s : finset α, (s.card : with_bot ℕ) ≤ degree p ∧ ∀ x, x ∈ s ↔ is_root p x\n| p := λ hp, by haveI := classical.prop_decidable (∃ x, is_root p x); exact\nif h : ∃ x, is_root p x\nthen\n  let ⟨x, hx⟩ := h in\n  have hpd : 0 < degree p := degree_pos_of_root hp hx,\n  have hd0 : p /ₘ (X - C x) ≠ 0 :=\n    λ h, by have := mul_div_by_monic_eq_iff_is_root.2 hx;\n      simp * at *,\n  have wf : degree (p /ₘ _) < degree p :=\n    degree_div_by_monic_lt _ (monic_X_sub_C x) hp\n    ((degree_X_sub_C x).symm ▸ dec_trivial),\n  let ⟨t, htd, htr⟩ := @exists_finset_roots (p /ₘ (X - C x)) hd0 in\n  have hdeg : degree (X - C x) ≤ degree p := begin\n    rw [degree_X_sub_C, degree_eq_nat_degree hp],\n    rw degree_eq_nat_degree hp at hpd,\n    exact with_bot.coe_le_coe.2 (with_bot.coe_lt_coe.1 hpd)\n  end,\n  have hdiv0 : p /ₘ (X - C x) ≠ 0 := mt (div_by_monic_eq_zero_iff (monic_X_sub_C x)\n    (ne_zero_of_monic (monic_X_sub_C x))).1 $ not_lt.2 hdeg,\n  ⟨insert x t, calc (card (insert x t) : with_bot ℕ) ≤ card t + 1 :\n    with_bot.coe_le_coe.2 $ finset.card_insert_le _ _\n    ... ≤ degree p :\n      by rw [← degree_add_div_by_monic (monic_X_sub_C x) hdeg,\n          degree_X_sub_C, add_comm];\n        exact add_le_add' (le_refl (1 : with_bot ℕ)) htd,\n  begin\n    assume y,\n    rw [mem_insert, htr, eq_comm, ← root_X_sub_C],\n    conv {to_rhs, rw ← mul_div_by_monic_eq_iff_is_root.2 hx},\n    exact ⟨λ h, or.cases_on h (root_mul_right_of_is_root _) (root_mul_left_of_is_root _),\n      root_or_root_of_root_mul⟩\n  end⟩\nelse\n  ⟨∅, (degree_eq_nat_degree hp).symm ▸ with_bot.coe_le_coe.2 (nat.zero_le _),\n    by clear exists_finset_roots; finish⟩\nusing_well_founded {dec_tac := tactic.assumption}\n\n/-- `roots p` noncomputably gives a finset containing all the roots of `p` -/\nnoncomputable def roots (p : polynomial α) : finset α :=\nif h : p = 0 then ∅ else classical.some (exists_finset_roots h)\n\nlemma card_roots (hp0 : p ≠ 0) : ((roots p).card : with_bot ℕ) ≤ degree p :=\nbegin\n  unfold roots,\n  rw dif_neg hp0,\n  exact (classical.some_spec (exists_finset_roots hp0)).1\nend\n\n@[simp] lemma mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ is_root p a :=\nby unfold roots; rw dif_neg hp; exact (classical.some_spec (exists_finset_roots hp)).2 _\n\nlemma card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : α) :\n  (roots ((X : polynomial α) ^ n - C a)).card ≤ n :=\nwith_bot.coe_le_coe.1 $\ncalc ((roots ((X : polynomial α) ^ n - C a)).card : with_bot ℕ)\n      ≤ degree ((X : polynomial α) ^ n - C a) : card_roots (X_pow_sub_C_ne_zero hn a)\n  ... = n : degree_X_pow_sub_C hn a\n\n/-- `nth_roots n a` noncomputably returns the solutions to `x ^ n = a`-/\nnoncomputable def nth_roots {α : Type*} [integral_domain α] (n : ℕ) (a : α) : finset α :=\nby letI := classical.prop_decidable; exact\nroots ((X : polynomial α) ^ n - C a)\n\n@[simp] lemma mem_nth_roots {α : Type*} [integral_domain α] {n : ℕ} (hn : 0 < n) {a x : α} :\n  x ∈ nth_roots n a ↔ x ^ n = a :=\nby letI := classical.prop_decidable;\nrw [nth_roots, mem_roots (X_pow_sub_C_ne_zero hn a),\n  is_root.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero_iff_eq]\n\nlemma card_nth_roots {α : Type*} [integral_domain α] (n : ℕ) (a : α) :\n  (nth_roots n a).card ≤ n :=\nby letI := classical.prop_decidable; exact\nif hn : n = 0\nthen if h : (X : polynomial α) ^ n - C a = 0\n  then by simp [nat.zero_le, nth_roots, roots, h]\n  else with_bot.coe_le_coe.1 (le_trans (card_roots h)\n    (by rw [hn, pow_zero, ← @C_1 α _, ← is_ring_hom.map_sub (@C α _ _)];\n      exact degree_C_le))\nelse by rw [← with_bot.coe_le_coe, ← degree_X_pow_sub_C (nat.pos_of_ne_zero hn) a];\n  exact card_roots (X_pow_sub_C_ne_zero (nat.pos_of_ne_zero hn) a)\n\nend integral_domain\n\nsection field\nvariables [field α] {p q : polynomial α}\ninstance : vector_space α (polynomial α) :=\n{ ..finsupp.to_module α }\n\nlemma monic_mul_leading_coeff_inv (h : p ≠ 0) :\n  monic (p * C (leading_coeff p)⁻¹) :=\nby rw [monic, leading_coeff_mul, leading_coeff_C,\n  mul_inv_cancel (show leading_coeff p ≠ 0, from mt leading_coeff_eq_zero.1 h)]\n\nlemma degree_mul_leading_coeff_inv (h : p ≠ 0) :\n  degree (p * C (leading_coeff p)⁻¹) = degree p :=\nhave h₁ : (leading_coeff p)⁻¹ ≠ 0 :=\n  inv_ne_zero (mt leading_coeff_eq_zero.1 h),\nby rw [degree_mul_eq, degree_C h₁, add_zero]\n\ndef div (p q : polynomial α) :=\nC (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹))\n\ndef mod (p q : polynomial α) :=\np %ₘ (q * C (leading_coeff q)⁻¹)\n\nprivate lemma quotient_mul_add_remainder_eq_aux (p q : polynomial α) :\n  q * div p q + mod p q = p :=\nif h : q = 0 then by simp [h, mod_by_monic, div, mod]\nelse begin\n  conv {to_rhs, rw ← mod_by_monic_add_div p (monic_mul_leading_coeff_inv h)},\n  rw [div, mod, add_comm, mul_assoc]\nend\n\nprivate lemma remainder_lt_aux (p : polynomial α) (hq : q ≠ 0) :\n  degree (mod p q) < degree q :=\ndegree_mul_leading_coeff_inv hq ▸\n  degree_mod_by_monic_lt p (monic_mul_leading_coeff_inv hq)\n    (mul_ne_zero hq (mt leading_coeff_eq_zero.2 (by rw leading_coeff_C;\n      exact inv_ne_zero (mt leading_coeff_eq_zero.1 hq))))\n\ninstance : has_div (polynomial α) := ⟨div⟩\n\ninstance : has_mod (polynomial α) := ⟨mod⟩\n\nlemma div_def : p / q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)) := rfl\n\nlemma mod_def : p % q = p %ₘ (q * C (leading_coeff q)⁻¹) := rfl\n\nlemma mod_by_monic_eq_mod (p : polynomial α) (hq : monic q) : p %ₘ q = p % q :=\nshow p %ₘ q = p %ₘ (q * C (leading_coeff q)⁻¹), by simp [monic.def.1 hq]\n\nlemma div_by_monic_eq_div (p : polynomial α) (hq : monic q) : p /ₘ q = p / q :=\nshow p /ₘ q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)),\nby simp [monic.def.1 hq]\n\nlemma mod_X_sub_C_eq_C_eval (p : polynomial α) (a : α) : p % (X - C a) = C (p.eval a) :=\nmod_by_monic_eq_mod p (monic_X_sub_C a) ▸ mod_by_monic_X_sub_C_eq_C_eval _ _\n\nlemma mul_div_eq_iff_is_root : (X - C a) * (p / (X - C a)) = p ↔ is_root p a :=\ndiv_by_monic_eq_div p (monic_X_sub_C a) ▸ mul_div_by_monic_eq_iff_is_root\n\ninstance : euclidean_domain (polynomial α) :=\n{ quotient := (/),\n  remainder := (%),\n  r := _,\n  r_well_founded := degree_lt_wf,\n  quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux,\n  remainder_lt := λ p q hq, remainder_lt_aux _ hq,\n  mul_left_not_lt := λ p q hq, not_lt_of_ge (degree_le_mul_left _ hq) }\n\nlemma mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=\n⟨λ h, h ▸ euclidean_domain.mod_lt _ hq0,\nλ h, have ¬degree (q * C (leading_coeff q)⁻¹) ≤ degree p :=\n  not_le_of_gt $ by rwa degree_mul_leading_coeff_inv hq0,\nbegin\n  rw [mod_def, mod_by_monic, dif_pos (monic_mul_leading_coeff_inv hq0)],\n  unfold div_mod_by_monic_aux,\n  simp [this]\nend⟩\n\nlemma div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=\n⟨λ h, by have := euclidean_domain.div_add_mod p q;\n  rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,\nλ h, have hlt : degree p < degree (q * C (leading_coeff q)⁻¹),\n    by rwa degree_mul_leading_coeff_inv hq0,\n  have hm : monic (q * C (leading_coeff q)⁻¹) := monic_mul_leading_coeff_inv hq0,\n  by rw [div_def, (div_by_monic_eq_zero_iff hm (ne_zero_of_monic hm)).2 hlt, mul_zero]⟩\n\nlemma degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :\n  degree q + degree (p / q) = degree p :=\nhave degree (p % q) < degree (q * (p / q)) :=\n  calc degree (p % q) < degree q : euclidean_domain.mod_lt _ hq0\n  ... ≤ _ : degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)),\nby conv {to_rhs, rw [← euclidean_domain.div_add_mod p q, add_comm,\n    degree_add_eq_of_degree_lt this, degree_mul_eq]}\n\nend field\n\nsection derivative\nvariables [comm_semiring α] {β : Type*}\n\n/-- `derivative p` formal derivative of the polynomial `p` -/\ndef derivative (p : polynomial α) : polynomial α := p.sum (λn a, C (a * n) * X^(n - 1))\n\nlemma derivative_apply (p : polynomial α) (n : ℕ) : (derivative p) n = p (n + 1) * (n + 1) :=\nbegin\n  rw [derivative],\n  simp [finsupp.sum],\n  rw [finset.sum_eq_single (n + 1)]; simp {contextual := tt},\n  assume b, cases b; simp [nat.succ_eq_add_one] {contextual := tt},\nend\n\n@[simp] lemma derivative_zero : derivative (0 : polynomial α) = 0 :=\nfinsupp.sum_zero_index\n\nlemma derivative_monomial (a : α) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) :=\nby rw [← single_eq_C_mul_X, ← single_eq_C_mul_X, derivative, sum_single_index, single_eq_C_mul_X];\n  simp; refl\n\n@[simp] lemma derivative_C {a : α} : derivative (C a) = 0 :=\nsuffices derivative (C a * X^0) = C (a * 0:α) * X ^ 0, by simpa,\nderivative_monomial a 0\n\n@[simp] lemma derivative_X : derivative (X : polynomial α) = 1 :=\nsuffices derivative (C (1:α) * X^1) = C (1 * (1:ℕ)) * X ^ (1 - 1), by simpa,\nderivative_monomial 1 1\n\n@[simp] lemma derivative_one : derivative (1 : polynomial α) = 0 :=\nderivative_C\n\n@[simp] lemma derivative_add {f g : polynomial α} :\n  derivative (f + g) = derivative f + derivative g :=\nby refine finsupp.sum_add_index _ _; simp [add_mul]\n\n@[simp] lemma derivative_sum {s : finset β} {f : β → polynomial α} :\n  derivative (s.sum f) = s.sum (λb, derivative (f b)) :=\nbegin\n  apply (finset.sum_hom derivative _ _).symm,\n  exact derivative_zero,\n  exact assume x y, derivative_add\nend\n\n@[simp] lemma derivative_mul {f g : polynomial α} :\n  derivative (f * g) = derivative f * g + f * derivative g :=\ncalc derivative (f * g) = f.sum (λn a, g.sum (λm b, C ((a * b) * (n + m : ℕ)) * 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    dsimp,\n    transitivity,\n    { apply congr_arg, exact single_eq_C_mul_X },\n    exact derivative_monomial _ _\n  end\n  ... = f.sum (λn a, g.sum (λm b,\n      (C (a * n) * X^(n - 1)) * (C b * X^m) + (C (b * m) * X^(m - 1)) * (C a * X^n))) :\n    sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm,\n      by cases n; cases m; simp [mul_add, add_mul, mul_assoc, mul_comm, mul_left_comm,\n          add_assoc, add_comm, add_left_comm, pow_add, pow_succ]\n  ... = derivative f * g + f * derivative g :\n    begin\n      simp [finsupp.sum_add],\n      conv {\n        to_rhs,\n        congr,\n        { rw [← sum_C_mul_X_eq f, derivative] },\n        { rw [← sum_C_mul_X_eq g, derivative] },\n      },\n      simp [finsupp.mul_sum, finsupp.sum_mul],\n      simp [finsupp.sum, mul_assoc, mul_comm, mul_left_comm]\n    end\n\nend derivative\n\nsection domain\nvariables [integral_domain α]\n\nlemma mem_support_derivative [char_zero α] (p : polynomial α) (n : ℕ) :\n  n ∈ (derivative p).support ↔ n + 1 ∈ p.support :=\nsuffices (¬(p (n + 1) = 0 ∨ ((1 + n:ℕ) : α) = 0)) ↔ p (n + 1) ≠ 0, by simpa [derivative_apply],\nby rw [nat.cast_eq_zero]; simp\n\n@[simp] lemma degree_derivative_eq [char_zero α] (p : polynomial α) (hp : 0 < nat_degree p) :\n  degree (derivative p) = (nat_degree p - 1 : ℕ) :=\nle_antisymm\n  (le_trans (degree_sum_le _ _) $ sup_le $ assume n hn,\n    have n ≤ nat_degree p,\n    begin\n      rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],\n      { refine le_degree_of_ne_zero _, simpa using hn },\n      { assume h, simpa [h] using hn }\n    end,\n    le_trans (degree_monomial_le _ _) $ with_bot.coe_le_coe.2 $ nat.sub_le_sub_right this _)\n  begin\n    refine le_sup _,\n    rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff],\n    { show ¬ 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\n  end\n\nend domain\n\nend polynomial\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/polynomial.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381987656672, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.7515605787302341}}
{"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.regular.basic\nimport algebra.iterate_hom\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 : ℕ) (rla : is_left_regular a) : is_left_regular (a ^ n) :=\nby simp only [is_left_regular, ← mul_left_iterate, rla.iterate n]\n\n/--  Any power of a right-regular element is right-regular. -/\nlemma is_right_regular.pow (n : ℕ) (rra : is_right_regular a) : is_right_regular (a ^ n) :=\nby { rw [is_right_regular, ← mul_right_iterate], exact rra.iterate n }\n\n/--  Any power of a regular element is regular. -/\nlemma is_regular.pow (n : ℕ) (ra : is_regular a) : is_regular (a ^ n) :=\n⟨is_left_regular.pow n ra.left, is_right_regular.pow n ra.right⟩\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 : ℕ} (n0 : 0 < n) :\n  is_left_regular (a ^ n) ↔ is_left_regular a :=\nbegin\n  refine ⟨_, is_left_regular.pow n⟩,\n  rw [← 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 : ℕ} (n0 : 0 < n) :\n  is_right_regular (a ^ n) ↔ is_right_regular a :=\nbegin\n  refine ⟨_, is_right_regular.pow n⟩,\n  rw [← 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 : ℕ} (n0 : 0 < n) :\n  is_regular (a ^ n) ↔ is_regular a :=\n⟨λ h, ⟨(is_left_regular.pow_iff n0).mp h.left, (is_right_regular.pow_iff n0).mp h.right⟩,\n  λ h, ⟨is_left_regular.pow n h.left, is_right_regular.pow n h.right⟩⟩\n\nend 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/algebra/regular/pow.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.7514125132488484}}
{"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\n\n/-\n\n# Groups\n\n## How to use Lean's groups\n\nIn previous courses I have made groups from scratch, but it's kind of irritating\nto do (because all the lemma names like `mul_one` are already taken) and I'm\nnot entirely sure that most students want to know how to make their own\ngroups, rings, whatever: what's the point if these things are there already?\n\nSo in this sheet I explain how to use Lean's groups.\n\n-/\n\n-- let G be a group\nvariables (G : Type) [group G]\n\n-- Let's see what just happened.\nexample (g : G) : g⁻¹ * g = 1 :=\nbegin\n  /- The tactic state now looks like this:\n  \n  G : Type\n  _inst_1 : group G\n  g : G\n  ⊢ g⁻¹ * g = 1\n  \n  So G is what most mathematicians would call a \"set\", and what in this course\n  we call a \"type\" (they're the same thing as far as you're concerned), and\n  `g : G` just mean \"g is an element of G\". The remaining thing is this \n  `_inst_1` thing, and that means \"G has a multiplication `*`, an identity `1`,\n  an inverse function `⁻¹`, and satisfies all the group axioms; furthermore\n  all of this will be taken care of by \"instances\", which are a part\n  of Lean's \"type class inference system\". The type class inference system\n  is the system which deals with stuff in square brackets. You don't have\n  to worry about it right now -- all that matters is that you have access\n  to all the group axioms. This one is called `inv_mul_self g`. \n  -/\n  exact inv_mul_self g,\nend\n\n-- Why don't you use `library_search` to see the names of the other axioms\n-- of a group? Note that when `library_search` has run, you can click on\n-- the output (the blue output in the infoview) and replace `library_search`\n-- with the name of the axiom it found. Note also that you can instead *guess*\n-- the names of the axioms. For example what do you think the proof of `1 * a = a` is called?\n\nexample (a b c : G) : (a * b) * c = a * (b * c) :=\nbegin\n  exact mul_assoc a b c, -- can be found with `library_search` if you didn't know the answer already\nend\n\nexample (a : G) : a * 1 = a :=\nbegin\n  exact mul_one a,\nend\n\n-- Can you guess the last two?\nexample (a : G) : 1 * a = a :=\nbegin\n  exact one_mul a\nend\n\nexample (a : G) : a * a⁻¹ = 1 :=\nbegin\n  exact mul_inv_self a\nend\n\n-- As well as the axioms, Lean has many other standard facts which are true\n-- in all groups. See if you can prove these from the axioms, or find them\n-- in the library.\n\n-- let a,b,c be elements of G in the below.\nvariables (a b c : G)\n\n-- inv_mul_cancel_left\nexample : a⁻¹ * (a * b) = b :=\nbegin\n  rw [← mul_assoc, inv_mul_self, one_mul],\nend\n\n-- mul_inv_cancel_left\nexample : a * (a⁻¹ * b) = b :=\nbegin\n  rw [← mul_assoc, mul_inv_self, one_mul]\nend\n\n-- left_inv_eq_right_inv\nexample {a b c : G} (h1 : b * a = 1) (h2 : a * c = 1) : b = c :=\nbegin\n  have h : b * (a * c) = (b * a) * c,\n  { rw mul_assoc, },\n  rwa [h1, h2, mul_one, one_mul] at h,\nend\n\n-- mul_eq_one_iff_inv_eq\nexample : a * b = 1 ↔ a⁻¹ = b :=\nbegin\n  split,\n  { intro h,\n    exact left_inv_eq_right_inv (inv_mul_self a) h, },\n  { rintro rfl,\n    exact mul_inv_self a, },\nend\n\n-- inv_one\nexample : (1 : G)⁻¹ = 1 :=\nbegin\n  rw [← mul_eq_one_iff_inv_eq, mul_one],\nend\n\n-- inv_inv\nexample : (a⁻¹)⁻¹ = a :=\nbegin\n  rw [← mul_eq_one_iff_inv_eq, inv_mul_self],\nend\n\n-- mul_inv_rev\nexample : (a * b)⁻¹ = b⁻¹ * a⁻¹ := \nbegin\n  rw [← mul_eq_one_iff_inv_eq, ← mul_assoc, mul_assoc a, mul_inv_self, mul_one, mul_inv_self],\nend\n\n/-\n\nRemember the `ring` tactic which didn't look at hypotheses but which could\nprove hypothesis-free identities in commutative rings? There's also a `group`\ntactic which does the same thing for groups. This tactic would have solved\nmany of the examples above.  NB the way it works is that it just uses\nLean's simplifier but armed with all the examples above; a theorem of Knuth and Bendix\nsays that these examples and the axioms of a group give a \"confluent rewrite system\"\nwhich can solve any identity in group theory. If you like you can\ntry and prove the next example manually by rewriting with the lemmas above\n(if you know their names, which you can find out with `library_search` or by\neducated guessing).\n\n-/\n\nexample : (b⁻¹ * a⁻¹)⁻¹ * 1⁻¹⁻¹ * b⁻¹ * (a⁻¹ * a⁻¹⁻¹⁻¹) * a = 1 :=\nbegin\n  rw [inv_one, inv_one, mul_one, mul_inv_rev, inv_inv, inv_inv, mul_assoc, mul_assoc, mul_assoc,\n      mul_inv_cancel_left, mul_assoc, mul_inv_cancel_left, inv_mul_self],\nend\n\n-- Try this trickier problem: if g^2=1 for all g in G, then G is abelian\nexample (h : ∀ g : G, g * g = 1) : ∀ g h : G, g * h = h * g :=\nbegin\n  have useful : ∀ g : G, g = g⁻¹,\n  { intro g,\n    rw [← eq_comm, ← mul_eq_one_iff_inv_eq],\n    exact h g, },\n  intros g h,\n  rw [useful (g * h), mul_inv_rev, ← useful g, ← useful h],\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/section04groups/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7514125013662585}}
{"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 `⊢` sign is the **goal**. A **tactic** is some move that makes the goal change, hopefully\ntowards an easier one.\n\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 → P`.\n-/\n\n-- **The implication → :**\n\n\ntheorem self_implication (P : Prop) : P → P :=\nbegin\n  intro h,\n  exact h,\nend\n\ntheorem forall_imp (P Q R : Prop) : (P → Q → R) → (P → Q) → (P → R) :=\nbegin\n  intro h1,\n  intro h2,\n  intro hP,\n  apply h1,-- ***why two things? explain...***--\n  exact hP,\n  apply h2,\n  exact hP,\nend\n\ntheorem modus_ponens (P Q : Prop) : P → (P → Q) → Q :=\nbegin\n  intro hP,\n  intro h1,\n  apply h1,\n  exact hP,\nend\n\n/- **not ¬**\n`not P`, with notation `¬ P`, is *defined* to mean `P → false`, so the fact that P implies false.\nYou can easily check with a truth table that P → false and ¬ P are equivalent. -/\n\n\ntheorem modus_tollens (P Q : Prop) : (P → Q) → (¬ Q → ¬ P) :=\nbegin\n  intros h1 hnQ hP,-- ***remember: `¬ P` is equivalent to `P → false`***\n  apply hnQ,\n  apply h1,\n  exact hP,\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) : ¬ (¬ P) → P :=\nbegin\n  intro hnnP,\n  by_contradiction,\n  apply hnnP,\n  exact h,\nend\n\n/- **∧**\nGiven two propositions P and Q, P ∧ Q is the proposition that is true precisely if both P and Q are\ntrue. 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 ∧ Q :=\nbegin\n  split,\n  exact hP,\n  exact hQ,\nend\n\n\n\n/-- ## cases \n If you want to _use_ an assumption of the form P ∧ 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 ∧ Q → P :=\nbegin\n  intro h,\n  cases h,\n  exact h_left,\nend\n\n\n/- **∨**\nSimilarly, given propositions P and Q, the proposition P ∨ 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 ¬ 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 ∨ Q → ¬ P → Q :=\nbegin\n  intros h1 h2,\n  cases h1,\n  { by_contradiction,\n    apply h2,\n    exact h1 },\n  { exact h1 },\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/fae_solutions/Course.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.751407911909794}}
{"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 data.polynomial.eval\nimport linear_algebra.dimension\n\n/-!\n# Linear recurrence\n\nInformally, a \"linear recurrence\" is an assertion of the form\n`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,\nwhere `u` is a sequence, `d` is the *order* of the recurrence and the `a i`\nare its *coefficients*.\n\nIn this file, we define the structure `linear_recurrence` so that\n`linear_recurrence.mk d a` represents the above relation, and we call\na sequence `u` which verifies it a *solution* of the linear recurrence.\n\nWe prove a few basic lemmas about this concept, such as :\n\n* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`\n  is a field)\n* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`\n  between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two\n  solutions are equal if and only if their first `d` terms are equals.\n* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,\n  which we call the *characteristic polynomial* of the recurrence\n\nOf course, although we can inductively generate solutions (cf `mk_sol`), the\ninteresting part would be to determinate closed-forms for the solutions.\nThis is currently *not implemented*, as we are waiting for definition and\nproperties of eigenvalues and eigenvectors.\n\n-/\n\nnoncomputable theory\nopen finset\nopen_locale big_operators\n\n/-- A \"linear recurrence relation\" over a commutative semiring is given by its\n  order `n` and `n` coefficients. -/\nstructure linear_recurrence (α : Type*) [comm_semiring α] := (order : ℕ) (coeffs : fin order → α)\n\ninstance (α : Type*) [comm_semiring α] : inhabited (linear_recurrence α) :=\n⟨⟨0, default _⟩⟩\n\nnamespace linear_recurrence\n\nsection comm_semiring\n\nvariables {α : Type*} [comm_semiring α] (E : linear_recurrence α)\n\n/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have\n  `u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/\ndef is_solution (u : ℕ → α) :=\n  ∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)\n\n/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.\n  We will prove this is the only such solution. -/\ndef mk_sol (init : fin E.order → α) : ℕ → α\n| n := if h : n < E.order then init ⟨n, h⟩ else\n  ∑ k : fin E.order,\n    have n - E.order + k < n :=\n    begin\n      rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h), tsub_lt_iff_left],\n      { exact add_lt_add_right k.is_lt n },\n      { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h),\n        simp only [zero_add] }\n    end,\n    E.coeffs k * mk_sol (n - E.order + k)\n\n/-- `E.mk_sol` indeed gives solutions to `E`. -/\nlemma is_sol_mk_sol (init : fin E.order → α) : E.is_solution (E.mk_sol init) :=\n  λ n, by rw mk_sol; simp\n\n/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/\nlemma mk_sol_eq_init (init : fin E.order → α) : ∀ n : fin E.order, E.mk_sol init n = init n :=\n  λ n, by { rw mk_sol, simp only [n.is_lt, dif_pos, fin.mk_coe, fin.eta] }\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `∀ n, u n = E.mk_sol init n`. -/\nlemma eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) :\n  ∀ n, u n = E.mk_sol init n\n| n := if h' : n < E.order\n  then by rw mk_sol; simp only [h', dif_pos]; exact_mod_cast heq ⟨n, h'⟩\n  else begin\n    rw [mk_sol, ← tsub_add_cancel_of_le (le_of_not_lt h'), h (n-E.order)],\n    simp [h'],\n    congr' with k,\n    exact have wf : n - E.order + k < n :=\n      begin\n        rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h'), tsub_lt_iff_left],\n        { exact add_lt_add_right k.is_lt n },\n        { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h'),\n          simp only [zero_add] }\n      end,\n      by rw eq_mk_of_is_sol_of_eq_init\n  end\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution\n  of `E` whose first `E.order` values are given by `init`. -/\nlemma eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) : u = E.mk_sol init :=\n  funext (E.eq_mk_of_is_sol_of_eq_init h heq)\n\n/-- The space of solutions of `E`, as a `submodule` over `α` of the module `ℕ → α`. -/\ndef sol_space : submodule α (ℕ → α) :=\n{ carrier := {u | E.is_solution u},\n  zero_mem' := λ n, by simp,\n  add_mem' := λ u v hu hv n, by simp [mul_add, sum_add_distrib, hu n, hv n],\n  smul_mem' := λ a u hu n, by simp [hu n, mul_sum]; congr'; ext; ac_refl }\n\n/-- Defining property of the solution space : `u` is a solution\n  iff it belongs to the solution space. -/\nlemma is_sol_iff_mem_sol_space (u : ℕ → α) : E.is_solution u ↔ u ∈ E.sol_space :=\n  iff.rfl\n\n/-- The function that maps a solution `u` of `E` to its first\n  `E.order` terms as a `linear_equiv`. -/\ndef to_init :\n  E.sol_space ≃ₗ[α] (fin E.order → α) :=\n{ to_fun := λ u x, (u : ℕ → α) x,\n  map_add' := λ u v, by { ext, simp },\n  map_smul' := λ a u, by { ext, simp },\n  inv_fun := λ u, ⟨E.mk_sol u, E.is_sol_mk_sol u⟩,\n  left_inv := λ u, by ext n; symmetry; apply E.eq_mk_of_is_sol_of_eq_init u.2; intros k; refl,\n  right_inv := λ u, function.funext_iff.mpr (λ n, E.mk_sol_eq_init u n) }\n\n/-- Two solutions are equal iff they are equal on `range E.order`. -/\nlemma sol_eq_of_eq_init (u v : ℕ → α) (hu : E.is_solution u) (hv : E.is_solution v) :\n  u = v ↔ set.eq_on u v ↑(range E.order) :=\nbegin\n  refine iff.intro (λ h x hx, h ▸ rfl) _,\n  intro h,\n  set u' : ↥(E.sol_space) := ⟨u, hu⟩,\n  set v' : ↥(E.sol_space) := ⟨v, hv⟩,\n  change u'.val = v'.val,\n  suffices h' : u' = v', from h' ▸ rfl,\n  rw [← E.to_init.to_equiv.apply_eq_iff_eq, linear_equiv.coe_to_equiv],\n  ext x,\n  exact_mod_cast h (mem_range.mpr x.2)\nend\n\n/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. This operation is quite useful for determining closed-form\n  solutions of `E`. -/\n\n/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. -/\ndef tuple_succ : (fin E.order → α) →ₗ[α] (fin E.order → α) :=\n{ to_fun := λ X i, if h : (i : ℕ) + 1 < E.order then X ⟨i+1, h⟩ else (∑ i, E.coeffs i * X i),\n  map_add' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_add, sum_add_distrib],\n    end,\n  map_smul' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_sum],\n      exact sum_congr rfl (λ x _, by ac_refl),\n    end }\n\nend comm_semiring\n\nsection field\n\nvariables {α : Type*} [field α] (E : linear_recurrence α)\n\n/-- The dimension of `E.sol_space` is `E.order`. -/\nlemma sol_space_dim : module.rank α E.sol_space = E.order :=\n@dim_fin_fun α _ E.order ▸ E.to_init.dim_eq\n\nend field\n\nsection comm_ring\n\nvariables {α : Type*} [comm_ring α] (E : linear_recurrence α)\n\n/-- The characteristic polynomial of `E` is\n`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/\ndef char_poly : polynomial α :=\n  polynomial.monomial E.order 1 - (∑ i : fin E.order, polynomial.monomial i (E.coeffs i))\n\n/-- The geometric sequence `q^n` is a solution of `E` iff\n  `q` is a root of `E`'s characteristic polynomial. -/\nlemma geom_sol_iff_root_char_poly (q : α) : E.is_solution (λ n, q^n) ↔ E.char_poly.is_root q :=\nbegin\n  rw [char_poly, polynomial.is_root.def, polynomial.eval],\n  simp only [polynomial.eval₂_finset_sum, one_mul,\n              ring_hom.id_apply, polynomial.eval₂_monomial, polynomial.eval₂_sub],\n  split,\n  { intro h,\n    simpa [sub_eq_zero] using h 0 },\n  { intros h n,\n    simp only [pow_add, sub_eq_zero.mp h, mul_sum],\n    exact sum_congr rfl (λ _ _, by ring) }\nend\n\nend comm_ring\n\nend linear_recurrence\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/linear_recurrence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011835, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7514079051903927}}
{"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.basic\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 `μ(F) = c * μ(E)`\nfor two sets `E` and `F`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be\nthe characteristic functions of `E` and `F`.\nAssume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`\npreserves the measure `μ.prod ν`, which means that\n```\n  ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ\n```\nIf we apply this to `h x y := e x * f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E)`, we can rewrite the RHS to\n`μ(F)`, and the LHS to `c * μ(E)`, where `c = c(ν)` does not depend on `μ`.\nApplying this to `μ` and to `ν` gives `μ (F) / μ (E) = ν (F) / ν (E)`, which is the uniqueness up to\nscalar multiplication.\n\nThe proof in [Halmos] seems to contain an omission in §60 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 pointwise\n\nnamespace measure_theory\n\nopen measure\n\nvariables {G : Type*} [topological_space G] [measurable_space G] [second_countable_topology G]\nvariables [borel_space G] [group G] [topological_group G]\nvariables {μ ν : measure G} [sigma_finite ν] [sigma_finite μ]\n\n/-- This condition is part of the definition of a measurable group in [Halmos, §59].\n  There, the map in this lemma is called `S`. -/\n@[to_additive map_prod_sum_eq]\nlemma map_prod_mul_eq (hν : is_mul_left_invariant ν) :\n  map (λ z : G × G, (z.1, z.1 * z.2)) (μ.prod ν) = μ.prod ν :=\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ν _ ht, lintegral_indicator _ hs, set_lintegral_const, mul_comm]\nend\n\n/-- The function we are mapping along is `SR` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_add_eq_swap]\nlemma map_prod_mul_eq_swap (hμ : is_mul_left_invariant μ) :\n  map (λ z : G × G, (z.2, z.2 * z.1)) (μ.prod ν) = ν.prod μ :=\nbegin\n  rw [← 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μ\nend\n\n/-- The function we are mapping along is `S⁻¹` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq`. -/\n@[to_additive map_prod_neg_add_eq]\nlemma map_prod_inv_mul_eq (hν : is_mul_left_invariant ν) :\n  map (λ z : G × G, (z.1, z.1⁻¹ * z.2)) (μ.prod ν) = μ.prod ν :=\n(homeomorph.shear_mul_right G).to_measurable_equiv.map_apply_eq_iff_map_symm_apply_eq.mp $\n  map_prod_mul_eq hν\n\n/-- The function we are mapping along is `S⁻¹R` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_neg_add_eq_swap]\nlemma map_prod_inv_mul_eq_swap (hμ : is_mul_left_invariant μ) :\n  map (λ z : G × G, (z.2, z.2⁻¹ * z.1)) (μ.prod ν) = ν.prod μ :=\nbegin\n  rw [← 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μ\nend\n\n/-- The function we are mapping along is `S⁻¹RSR` in [Halmos, §59],\n  where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/\n@[to_additive map_prod_add_neg_eq]\nlemma map_prod_mul_inv_eq (hμ : is_mul_left_invariant μ) (hν : is_mul_left_invariant ν) :\n  map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod ν) = μ.prod ν :=\nbegin\n  let S := (homeomorph.shear_mul_right G).to_measurable_equiv,\n  suffices : map ((λ z : G × G, (z.2, z.2⁻¹ * z.1)) ∘ (λ z : G × G, (z.2, z.2 * z.1))) (μ.prod ν) =\n    μ.prod ν,\n  { convert this, ext1 ⟨x, y⟩, simp },\n  simp_rw [← 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μ,\n    map_prod_inv_mul_eq_swap hν]\nend\n\n@[to_additive] lemma quasi_measure_preserving_inv (hμ : is_mul_left_invariant μ) :\n  quasi_measure_preserving (has_inv.inv : G → G) μ μ :=\nbegin\n  refine ⟨measurable_inv, absolutely_continuous.mk $ λ s hsm hμs, _⟩,\n  rw [map_apply measurable_inv hsm, inv_preimage],\n  have hf : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=\n    (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  suffices : map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod μ) ((s⁻¹).prod s⁻¹) = 0,\n  { simpa only [map_prod_mul_inv_eq hμ hμ, prod_prod, mul_eq_zero, or_self] using this },\n  have hsm' : measurable_set (s⁻¹.prod s⁻¹) := 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, set.inv_inv, measure_mono_null (inter_subset_right _ _) hμs, lintegral_zero]\nend\n\n@[to_additive]\nlemma measure_inv_null (hμ : is_mul_left_invariant μ) {E : set G} :\n  μ ((λ x, x⁻¹) ⁻¹' E) = 0 ↔ μ E = 0 :=\nbegin\n  refine ⟨λ hE, _, (quasi_measure_preserving_inv hμ).preimage_null⟩,\n  convert (quasi_measure_preserving_inv hμ).preimage_null hE,\n  exact set.inv_inv.symm\nend\n\n@[to_additive]\nlemma measurable_measure_mul_right {E : set G} (hE : measurable_set E) :\n  measurable (λ x, μ ((λ y, y * x) ⁻¹' E)) :=\nbegin\n  suffices :\n    measurable (λ y, μ ((λ x, (x, y)) ⁻¹' ((λ z : G × G, (1, z.1 * z.2)) ⁻¹' 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\n@[to_additive]\nlemma lintegral_lintegral_mul_inv (hμ : is_mul_left_invariant μ) (hν : is_mul_left_invariant ν)\n  (f : G → G → ℝ≥0∞) (hf : ae_measurable (uncurry f) (μ.prod ν)) :\n  ∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ :=\nbegin\n  have h : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=\n  (measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,\n  have h2f : ae_measurable (uncurry $ λ x y, f (y * x) x⁻¹) (μ.prod ν),\n  { apply hf.comp_measurable' h (map_prod_mul_inv_eq hμ hν).absolutely_continuous },\n  simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],\n  conv_rhs { rw [← map_prod_mul_inv_eq hμ hν] },\n  symmetry,\n  exact lintegral_map' (hf.mono' (map_prod_mul_inv_eq hμ hν).absolutely_continuous) h,\nend\n\n@[to_additive]\nlemma measure_mul_right_null (hμ : is_mul_left_invariant μ) {E : set G} (y : G) :\n  μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ E = 0 :=\ncalc μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ (has_inv.inv ⁻¹' ((λ x, y⁻¹ * x) ⁻¹' (has_inv.inv ⁻¹' E))) = 0 :\n  by simp only [preimage_preimage, mul_inv_rev, inv_inv]\n... ↔ μ E = 0 : by simp only [measure_inv_null hμ, hμ.measure_preimage_mul]\n\n@[to_additive]\nlemma measure_mul_right_ne_zero (hμ : is_mul_left_invariant μ) {E : set G}\n  (h2E : μ E ≠ 0) (y : G) : μ ((λ x, x * y) ⁻¹' E) ≠ 0 :=\n(not_iff_not_of_iff (measure_mul_right_null hμ y)).mpr h2E\n\n/-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A].\n  Note that if `f` is the characteristic function of a measurable set `F` this states that\n  `μ F = c * μ E` for a constant `c` that does not depend on `μ`.\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⁻¹)ν(Ex⁻¹) = f(x)` holds if we can prove that\n  `0 < ν(Ex⁻¹) < ∞`. The first inequality follows from §59, 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 `ν` is a regular measure (we only need that it is finite on compact\n  sets). -/\n@[to_additive]\nlemma measure_lintegral_div_measure [t2_space G] (hμ : is_mul_left_invariant μ)\n  (hν : is_mul_left_invariant ν) [regular ν] {E : set G} (hE : is_compact E) (h2E : ν E ≠ 0)\n  (f : G → ℝ≥0∞) (hf : measurable f) :\n  μ E * ∫⁻ y, f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E) ∂ν = ∫⁻ x, f x ∂μ :=\nbegin\n  have Em := hE.measurable_set,\n  symmetry,\n  set g := λ y, f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E),\n  have hg : measurable g := (hf.comp measurable_inv).div\n    ((measurable_measure_mul_right Em).comp measurable_inv),\n  rw [← set_lintegral_one, ← lintegral_indicator _ Em,\n    ← lintegral_lintegral_mul (measurable_const.indicator Em).ae_measurable hg.ae_measurable,\n    ← lintegral_lintegral_mul_inv hμ hν],\n  swap, { exact (((measurable_const.indicator Em).comp measurable_fst).mul\n      (hg.comp measurable_snd)).ae_measurable },\n  have mE : ∀ x : G, measurable (λ y, ((λ z, z * x) ⁻¹' E).indicator (λ z, (1 : ℝ≥0∞)) y) :=\n  λ x, measurable_const.indicator (measurable_mul_const _ Em),\n  have : ∀ x y, E.indicator (λ (z : G), (1 : ℝ≥0∞)) (y * x) =\n    ((λ z, z * x) ⁻¹' E).indicator (λ (b : G), 1) y,\n  { intros x y, symmetry, convert indicator_comp_right (λ y, y * x), ext1 z, refl },\n  have h3E : ∀ y, ν ((λ x, x * y) ⁻¹' E) ≠ ∞ :=\n    λ y, (regular.lt_top_of_is_compact $ (homeomorph.mul_right _).compact_preimage.mpr hE).ne,\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ν 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` -/\n@[to_additive]\nlemma measure_mul_measure_eq [t2_space G] (hμ : is_mul_left_invariant μ)\n  (hν : is_mul_left_invariant ν) [regular ν] {E F : set G}\n  (hE : is_compact E) (hF : measurable_set F) (h2E : ν E ≠ 0) : μ E * ν F = ν E * μ F :=\nbegin\n  have h1 := measure_lintegral_div_measure hν hν hE h2E (F.indicator (λ x, 1))\n    (measurable_const.indicator hF),\n  have h2 := measure_lintegral_div_measure hμ hν hE h2E (F.indicator (λ x, 1))\n    (measurable_const.indicator hF),\n  rw [lintegral_indicator _ hF, set_lintegral_one] at h1 h2,\n  rw [← h1, mul_left_comm, h2],\nend\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/group/prod.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7513851087113482}}
{"text": "import MyNat.Definition\nimport MultiplicationWorld.Level6 -- succ_mul\nimport MyNat.Multiplication -- mul_succ, mul_zero\nimport AdvancedMultiplicationWorld.Level2 -- eq_zero_or_eq_zero_of_mul_eq_zero\nnamespace MyNat\nopen MyNat\n\n/-!\n# Advanced Multiplication World\n\n## Level 4: `mul_left_cancel`\n\nThis is the last of the bonus multiplication levels. `mul_left_cancel` will be useful in inequality\nworld.\n\nPeople find this level hard. I have probably had more questions about this level than all the other\nlevels put together, in fact. Many levels in this game can just be solved by \"running at it\" -- do\ninduction on one of the variables, keep your head, and you're done. In fact, if you like a\nchallenge, it might be instructive if you stop reading after the end of this paragraph and try\nsolving this level now by induction, seeing the trouble you run into, and reading the rest of these\ncomments afterwards. This level has 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 theorem in this level. Exactly what\nstatement do you want to prove by induction? It is subtle.\n\nOk so here are some spoilers. The problem with naively running at it, is that if you try induction\non, say, `c`, then you are imagining `a` and `b` as fixed, and your inductive hypothesis `P(c)` is\n`ab=ac ⟹ b=c`. So for your inductive step you will be able to assume `ab=ad ⟹ b=d` and your goal\nwill be to show `ab=a(d+1) ⟹ b=d+1`. When you also assume `ab=a(d+1)` you will realize that your\ninductive hypothesis is *useless*, because `ab=ad` is not true! The statement `P(c)` (with `a` and\n`b` regarded as constants) is not provable by induction.\n\nWhat you *can* prove by induction is the following *stronger* statement. Imagine `a ≠ 0` as fixed,\nand then prove \"for all `b`, if `ab=ac` then `b=c`\" by induction on `c`. This gives us the extra\nflexibility we require. Note 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 you can write `revert b`. The\n`revert` tactic is the opposite of the `intro` tactic; it replaces the `b` in the hypotheses with\n\"for all `b`\" in the goal.\n\nAlternatively, you can write `induction c generalizing b with` 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## Theorem\nIf `a ≠ 0`, `b` and `c` are natural numbers such that ` ab = ac, ` then `b = c`.\n-/\n\nset_option trace.Meta.Tactic.simp true\ntheorem mul_left_cancel (a b c : MyNat) (ha : a ≠ 0) : a * b = a * c → b = c := by\n  induction c generalizing b with\n  | zero =>\n    rw [zero_is_0]\n    rw [mul_zero]\n    intro h\n    cases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ h) with\n    | inl h1 =>\n      exfalso\n      apply ha\n      assumption\n    | inr h2 =>\n      assumption\n  | succ d hd =>\n    intro hb\n    cases b with\n    | zero =>\n      rw [zero_is_0] at hb\n      rw [mul_zero] at hb\n      rw [zero_is_0]\n      exfalso\n      apply ha\n      have hb := hb.symm\n      cases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ hb) with\n      | inl h =>\n        exact h\n      | inr h =>\n        exfalso\n        exact succ_ne_zero _ h\n    | succ c =>\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\n/-!\nYou should now be ready for [Inequality World](../InequalityWorld.lean.md).\n\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/AdvancedMultiplicationWorld/Level4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7513851022049641}}
{"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 data.complex.module\nimport ring_theory.norm\nimport ring_theory.trace\n\n/-! # Lemmas about `algebra.trace` and `algebra.norm` on `ℂ` -/\n\nopen complex\n\nlemma algebra.left_mul_matrix_complex (z : ℂ) :\n  algebra.left_mul_matrix complex.basis_one_I z = !![z.re, -z.im; z.im, z.re] :=\nbegin\n  ext i j,\n  rw [algebra.left_mul_matrix_eq_repr_mul, complex.coe_basis_one_I_repr, complex.coe_basis_one_I,\n    mul_re, mul_im, matrix.of_apply],\n  fin_cases j,\n  { simp_rw [matrix.cons_val_zero, one_re, one_im, mul_zero, mul_one, sub_zero, zero_add],\n    fin_cases i; refl },\n  { simp_rw [matrix.cons_val_one, matrix.head_cons, I_re, I_im, mul_zero, mul_one, zero_sub,\n      add_zero],\n    fin_cases i; refl },\nend\n\nlemma algebra.trace_complex_apply (z : ℂ) : algebra.trace ℝ ℂ z = 2*z.re :=\nbegin\n  rw [algebra.trace_eq_matrix_trace complex.basis_one_I,\n    algebra.left_mul_matrix_complex, matrix.trace_fin_two],\n  exact (two_mul _).symm\nend\n\nlemma algebra.norm_complex_apply (z : ℂ) : algebra.norm ℝ z = z.norm_sq :=\nbegin\n  rw [algebra.norm_eq_matrix_det complex.basis_one_I,\n    algebra.left_mul_matrix_complex, matrix.det_fin_two, norm_sq_apply],\n  simp,\nend\n\nlemma algebra.norm_complex_eq : algebra.norm ℝ = norm_sq.to_monoid_hom :=\nmonoid_hom.ext algebra.norm_complex_apply\n", "meta": {"author": "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/complex.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7513850979448266}}
{"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 linear_algebra.matrix.charpoly.basic\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.Adjugate\nimport Mathbin.RingTheory.PolynomialAlgebra\nimport Mathbin.Tactic.ApplyFun\nimport Mathbin.Tactic.Squeeze\n\n/-!\n# Characteristic polynomials and the Cayley-Hamilton theorem\n\nWe define characteristic polynomials of matrices and\nprove the Cayley–Hamilton 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\n\nnoncomputable section\n\nuniverse u v w\n\nopen Polynomial Matrix\n\nopen BigOperators Polynomial\n\nvariable {R : Type u} [CommRing R]\n\nvariable {n : Type w} [DecidableEq n] [Fintype n]\n\nopen Finset\n\n/-- The \"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] :=\n  Matrix.scalar n (X : R[X]) - (C : R →+* R[X]).mapMatrix M\n#align charmatrix charmatrix\n\ntheorem 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) :=\n  rfl\n#align charmatrix_apply charmatrix_apply\n\n@[simp]\ntheorem charmatrix_apply_eq (M : Matrix n n R) (i : n) :\n    charmatrix M i i = (X : R[X]) - C (M i i) := by\n  simp only [charmatrix, sub_left_inj, Pi.sub_apply, scalar_apply_eq, RingHom.mapMatrix_apply,\n    map_apply, DMatrix.sub_apply]\n#align charmatrix_apply_eq charmatrix_apply_eq\n\n@[simp]\ntheorem charmatrix_apply_ne (M : Matrix n n R) (i j : n) (h : i ≠ j) :\n    charmatrix M i j = -C (M i j) := by\n  simp only [charmatrix, Pi.sub_apply, scalar_apply_ne _ _ _ h, zero_sub, RingHom.mapMatrix_apply,\n    map_apply, DMatrix.sub_apply]\n#align charmatrix_apply_ne charmatrix_apply_ne\n\ntheorem matPolyEquiv_charmatrix (M : Matrix n n R) : matPolyEquiv (charmatrix M) = X - C M :=\n  by\n  ext (k i j)\n  simp only [matPolyEquiv_coeff_apply, coeff_sub, Pi.sub_apply]\n  by_cases h : i = j\n  · subst h\n    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]\n#align mat_poly_equiv_charmatrix matPolyEquiv_charmatrix\n\ntheorem charmatrix_reindex {m : Type v} [DecidableEq m] [Fintype m] (e : n ≃ m) (M : Matrix n n R) :\n    charmatrix (reindex e e M) = reindex e e (charmatrix M) :=\n  by\n  ext (i j x)\n  by_cases h : i = j\n  all_goals simp [h]\n#align charmatrix_reindex charmatrix_reindex\n\n/-- The 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#align matrix.charpoly Matrix.charpoly\n\ntheorem Matrix.charpoly_reindex {m : Type v} [DecidableEq m] [Fintype m] (e : n ≃ m)\n    (M : Matrix n n R) : (reindex e e M).charpoly = M.charpoly :=\n  by\n  unfold Matrix.charpoly\n  rw [charmatrix_reindex, Matrix.det_reindex_self]\n#align matrix.charpoly_reindex Matrix.charpoly_reindex\n\n-- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf\n/-- The **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-/\ntheorem Matrix.aeval_self_charpoly (M : Matrix n n R) : aeval M M.charpoly = 0 :=\n  by\n  -- We begin with the fact $χ_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 • (1 : Matrix n n R[X]) = adjugate (charmatrix M) * charmatrix M :=\n    (adjugate_mul _).symm\n  -- Using the algebra isomorphism `matrix n n R[X] ≃ₐ[R] polynomial (matrix n n R)`,\n  -- we have the same identity in `polynomial (matrix n n R)`.\n  apply_fun matPolyEquiv  at h\n  simp only [mat_poly_equiv.map_mul, matPolyEquiv_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 fun p => p.eval M  at h\n  rw [eval_mul_X_sub_C] at h\n  -- Now $χ_M (t) I$, when thought of as a polynomial of matrices\n  -- and evaluated at some `N` is exactly $χ_M (N)$.\n  rw [matPolyEquiv_smul_one, eval_map] at h\n  -- Thus we have $χ_M(M) = 0$, which is the desired result.\n  exact h\n#align matrix.aeval_self_charpoly Matrix.aeval_self_charpoly\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/Charpoly/Basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7513149516168772}}
{"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 data.nat.cast\nimport data.int.basic\nimport tactic.localized\nimport tactic.apply_fun\nimport order.rel_iso\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…`. 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\n### Casts\n\n* `cast_lt i h` : embed `i` into a `fin` where `h` proves it belongs into;\n* `cast_le h` : embed `fin n` into `fin m`, `h : n ≤ m`;\n* `cast eq` : embed `fin n` into `fin m`, `eq : n = m`;\n* `cast_add m` : embed `fin n` into `fin (n+m)`;\n* `cast_succ` : embed `fin n` into `fin (n+1)`;\n* `succ_above p` : embed `fin n` into `fin (n + 1)` with a hole around `p`;\n* `pred_above (p : fin n) i` : embed `i : fin (n+1)` into `fin n` by subtracting one if `p < i`;\n* `cast_pred` : embed `fin (n + 2)` into `fin (n + 1)` by mapping `last (n + 1)` to `last n`;\n* `sub_nat i h` : subtract `m` from `i ≥ m`, generalizes `fin.pred`;\n* `add_nat m i` : add `m` on `i` on the right, generalizes `fin.succ`;\n* `nat_add n i` adds `n` on `i` on the left;\n* `clamp n m` : `min n m` as an element of `fin (m + 1)`;\n\n### Operation on tuples\n\nWe interpret maps `Π i : fin n, α i` as tuples `(α 0, …, α (n-1))`.\nIf `α i` is a constant map, then tuples are isomorphic (but not definitionally equal)\nto `vector`s.\n\nWe define the following operations:\n\n* `tail` : the tail of an `n+1` tuple, i.e., its last `n` entries;\n* `cons` : adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple;\n* `init` : the beginning of an `n+1` tuple, i.e., its first `n` entries;\n* `snoc` : adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc`\n  comes from `cons` (i.e., adding an element to the left of a tuple) read in reverse order.\n* `insert_nth` : insert an element to a tuple at a given position.\n* `find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never\n  satisfied.\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 {α : fin 0 → Sort u} (x : fin 0) : α x := x.elim0\n\nlemma fact.succ.pos {n} : fact (0 < succ n) := ⟨zero_lt_succ _⟩\n\nlemma fact.bit0.pos {n} [h : fact (0 < n)] : fact (0 < bit0 n) :=\n⟨nat.zero_lt_bit0 $ ne_of_gt h.1⟩\n\nlemma fact.bit1.pos {n} : fact (0 < bit1 n) :=\n⟨nat.zero_lt_bit1 _⟩\n\nlemma fact.pow.pos {p n : ℕ} [h : fact $ 0 < p] : fact (0 < p ^ n) :=\n⟨pow_pos h.1 _⟩\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 : ℕ} {a b : fin n}\n\ninstance fin_to_nat (n : ℕ) : has_coe (fin n) nat := ⟨subtype.val⟩\n\nsection coe\n\n/-!\n### coercions and constructions\n-/\n\n@[simp] protected lemma eta (a : fin n) (h : (a : ℕ) < n) : (⟨(a : ℕ), h⟩ : fin n) = a :=\nby cases a; refl\n\n@[ext]\nlemma ext {a b : fin n} (h : (a : ℕ) = b) : a = b := eq_of_veq h\n\nlemma ext_iff (a b : fin n) : a = b ↔ (a : ℕ) = b :=\niff.intro (congr_arg _) fin.eq_of_veq\n\nlemma coe_injective {n : ℕ} : injective (coe : fin n → ℕ) := subtype.coe_injective\n\nlemma eq_iff_veq (a b : fin n) : a = b ↔ a.1 = b.1 :=\n⟨veq_of_eq, eq_of_veq⟩\n\nlemma ne_iff_vne (a b : fin n) : a ≠ b ↔ a.1 ≠ b.1 :=\n⟨vne_of_ne, ne_of_vne⟩\n\n@[simp] lemma mk_eq_subtype_mk (a : ℕ) (h : a < n) : mk a h = ⟨a, h⟩ := rfl\n\nprotected lemma mk.inj_iff {n a b : ℕ} {ha : a < n} {hb : b < n} :\n  (⟨a, ha⟩ : fin n) = ⟨b, hb⟩ ↔ a = b :=\nsubtype.mk_eq_mk\n\nlemma mk_val {m n : ℕ} (h : m < n) : (⟨m, h⟩ : fin n).val = m := rfl\n\nlemma eq_mk_iff_coe_eq {k : ℕ} {hk : k < n} : a = ⟨k, hk⟩ ↔ (a : ℕ) = k :=\nfin.eq_iff_veq a ⟨k, hk⟩\n\n@[simp, norm_cast] lemma coe_mk {m n : ℕ} (h : m < n) : ((⟨m, h⟩ : fin n) : ℕ) = m := rfl\n\nlemma mk_coe (i : fin n) : (⟨i, i.property⟩ : fin n) = i :=\nfin.eta _ _\n\nlemma coe_eq_val (a : fin n) : (a : ℕ) = 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 {α : Sort*} {k l : ℕ} (h : k = l) {f : fin k → α} {g : fin l → α} :\n  f == g ↔ (∀ (i : fin k), f i = g ⟨(i : ℕ), h ▸ i.2⟩) :=\nby { induction h, simp [heq_iff_eq, function.funext_iff] }\n\nprotected lemma heq_ext_iff {k l : ℕ} (h : k = l) {i : fin k} {j : fin l} :\n  i == j ↔ (i : ℕ) = (j : ℕ) :=\nby { induction h, simp [ext_iff] }\n\nlemma exists_iff {p : fin n → Prop} : (∃ i, p i) ↔ ∃ i h, p ⟨i, h⟩ :=\n⟨λ h, exists.elim h (λ ⟨i, hi⟩ hpi, ⟨i, hi, hpi⟩),\n  λ h, exists.elim h (λ i hi, ⟨⟨i, hi.fst⟩, hi.snd⟩)⟩\n\nlemma forall_iff {p : fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩ :=\n⟨λ h i hi, h ⟨i, hi⟩, λ h ⟨i, hi⟩, h i hi⟩\n\nend coe\n\nsection order\n\n/-!\n### order\n-/\n\nlemma is_lt (i : fin n) : (i : ℕ) < n := i.2\n\nlemma is_le (i : fin (n + 1)) : (i : ℕ) ≤ n := le_of_lt_succ i.is_lt\n\nlemma lt_iff_coe_lt_coe : a < b ↔ (a : ℕ) < b := iff.rfl\n\nlemma le_iff_coe_le_coe : a ≤ b ↔ (a : ℕ) ≤ b := iff.rfl\n\nlemma mk_lt_of_lt_coe {a : ℕ} (h : a < b) : (⟨a, h.trans b.is_lt⟩ : fin n) < b := h\n\nlemma mk_le_of_le_coe {a : ℕ} (h : a ≤ b) : (⟨a, h.trans_lt b.is_lt⟩ : fin n) ≤ 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 : ℕ} {a b : fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=\niff.rfl\n\n/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `fin n`. -/\n@[norm_cast, simp] lemma coe_fin_le {n : ℕ} {a b : fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=\niff.rfl\n\ninstance {n : ℕ} : linear_order (fin n) :=\n{ le := (≤), 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 → ℕ) (@fin.eq_of_veq _) }\n\n/-- The inclusion map `fin n → ℕ` is a relation embedding. -/\ndef coe_embedding (n) : (fin n) ↪o ℕ :=\n⟨⟨coe, @fin.eq_of_veq _⟩, λ a b, iff.rfl⟩\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 : ℕ} : fin n → ℕ\n| ⟨0, _⟩ := 1\n| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩\n```\n-/\ninstance {n : ℕ} : has_well_founded (fin n) :=\n⟨_, measure_wf coe⟩\n\n@[simp] lemma coe_zero {n : ℕ} : ((0 : fin (n+1)) : ℕ) = 0 := rfl\nattribute [simp] val_zero\n@[simp] lemma val_zero' (n) : (0 : fin (n+1)).val = 0 := rfl\n@[simp] lemma mk_zero : (⟨0, nat.succ_pos'⟩ : fin (n + 1)) = (0 : fin _) := rfl\n\nlemma zero_le (a : fin (n + 1)) : 0 ≤ a := zero_le a.1\n\nlemma pos_iff_ne_zero (a : fin (n+1)) : 0 < a ↔ a ≠ 0 :=\nbegin\n  split,\n  { rintros h rfl, exact lt_irrefl _ h, },\n  { rintros h,\n    apply (@pos_iff_ne_zero _ _ (a : ℕ)).mpr,\n    cases a,\n    rintro w,\n    apply h,\n    simp at w,\n    subst w,\n    refl, },\nend\n\n/-- The greatest value of `fin (n+1)` -/\ndef last (n : ℕ) : fin (n+1) := ⟨_, n.lt_succ_self⟩\n\n@[simp, norm_cast] lemma coe_last (n : ℕ) : (last n : ℕ) = n := rfl\n\nlemma last_val (n : ℕ) : (last n).val = n := rfl\n\ntheorem le_last (i : fin (n+1)) : i ≤ last n :=\nle_of_lt_succ i.is_lt\n\ninstance : bounded_lattice (fin (n + 1)) :=\n{ top := last n,\n  le_top := le_last,\n  bot := 0,\n  bot_le := zero_le,\n  .. fin.linear_order, .. 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 : ¬ (i : ℕ) < n) : i = last n :=\nle_antisymm (le_last i) (not_lt.1 h)\n\nsection\n\nvariables {α : Type*} [preorder α]\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 : ℕ) = (i : ℕ)`. -/\n@[simp] lemma coe_order_iso_apply (e : fin n ≃o fin m) (i : fin n) : (e i : ℕ) = i :=\nbegin\n  rcases i with ⟨i, hi⟩,\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 $ λ j hj, _) (forall_lt_iff_le.1 $ λ 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 [← h j hj (hj.trans hi), ← lt_iff_coe_lt_coe, e.lt_iff_lt] }\nend\n\ninstance order_iso_subsingleton : subsingleton (fin n ≃o α) :=\n⟨λ e e', by { ext i,\n  rw [← e.symm.apply_eq_iff_eq, e.symm_apply_apply, ← e'.trans_apply, ext_iff,\n    coe_order_iso_apply] }⟩\n\ninstance order_iso_subsingleton' : subsingleton (α ≃o fin n) :=\norder_iso.symm_injective.subsingleton\n\ninstance order_iso_unique : unique (fin n ≃o 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 → α} (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 → α)) (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 ↪o α} (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 {α : Type*} [preorder α] {f : fin n → α} :\n  strict_mono f ↔ ∀ i (h : i + 1 < n), f ⟨i, lt_of_le_of_lt (nat.le_succ i) h⟩ < f ⟨i+1, h⟩ :=\nbegin\n  split,\n  { assume H i hi,\n    apply H,\n    exact nat.lt_succ_self _ },\n  { assume H,\n    have A : ∀ i j (h : i < j) (h' : j < n), f ⟨i, lt_trans h h'⟩ < f ⟨j, h'⟩,\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 : ℕ) (j : ℕ) 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/-- convert a `ℕ` to `fin n`, provided `n` is positive -/\ndef of_nat' [h : fact (0 < n)] (i : ℕ) : fin n := ⟨i%n, mod_lt _ h.1⟩\n\nlemma one_val {n : ℕ} : (1 : fin (n+1)).val = 1 % (n+1) := rfl\nlemma coe_one' {n : ℕ} : ((1 : fin (n+1)) : ℕ) = 1 % (n+1) := rfl\n@[simp] lemma val_one  {n : ℕ} : (1 : fin (n+2)).val = 1 := rfl\n@[simp] lemma coe_one  {n : ℕ} : ((1 : fin (n+2)) : ℕ) = 1 := rfl\n@[simp] lemma mk_one : (⟨1, nat.succ_lt_succ (nat.succ_pos n)⟩ : fin (n + 2)) = (1 : fin _) := rfl\n\ninstance {n : ℕ} : nontrivial (fin (n + 2)) := ⟨⟨0, 1, dec_trivial⟩⟩\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 : ℕ) : 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 : ℕ} : ∀ a b : fin n, (a + b).val = (a.val + b.val) % n\n| ⟨_, _⟩ ⟨_, _⟩ := rfl\n\nlemma coe_add {n : ℕ} : ∀ a b : fin n, ((a + b : fin n) : ℕ) = (a + b) % n\n| ⟨_, _⟩ ⟨_, _⟩ := rfl\n\nlemma coe_bit0 {n : ℕ} (k : fin n) : ((bit0 k : fin n) : ℕ) = bit0 (k : ℕ) % n :=\nby { cases k, refl }\n\nlemma coe_bit1 {n : ℕ} (k : fin (n + 1)) :\n  ((bit1 k : fin (n + 1)) : ℕ) = bit1 (k : ℕ) % (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 : ℕ} {i : fin n.succ} (h : i < last _) :\n  (↑(i + 1) : ℕ) = i + 1 :=\nbegin\n  -- First show that `((1 : fin n.succ) : ℕ) = 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 : ∀ 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 : ℕ} (i : fin (n + 1)) :\n  ((i + 1 : fin (n + 1)) : ℕ) = 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 : ℕ} (h : bit0 m < n) :\n  (⟨bit0 m, h⟩ : fin n) = (bit0 ⟨m, (nat.le_add_right m m).trans_lt h⟩ : fin _) :=\neq_of_veq (nat.mod_eq_of_lt h).symm\n\n@[simp] lemma mk_bit1 {m n : ℕ} (h : bit1 m < n + 1) :\n  (⟨bit1 m, h⟩ : fin (n + 1)) = (bit1 ⟨m, (nat.le_add_right m m).trans_lt\n    ((m + m).lt_succ_self.trans h)⟩ : fin _) :=\nbegin\n  ext,\n  simp only [bit1, bit0] at h,\n  simp only [bit1, bit0, coe_add, coe_one', coe_mk, ←nat.add_mod, nat.mod_eq_of_lt h],\nend\n\nend bit\n\n@[simp] lemma val_two  {n : ℕ} : (2 : fin (n+3)).val = 2 := rfl\n@[simp] lemma coe_two  {n : ℕ} : ((2 : fin (n+3)) : ℕ) = 2 := rfl\n\nsection of_nat_coe\n\n@[simp]\nlemma of_nat_eq_coe (n : ℕ) (a : ℕ) : (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, ← 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 : ℕ} {a : ℕ} (h : a < n + 1) :\n  ((a : fin (n + 1)).val) = a :=\nbegin\n  rw ←of_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 : ℕ} (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 `ℕ`, results in that number. -/\nlemma coe_coe_of_lt {n : ℕ} {a : ℕ} (h : a < n + 1) :\n  ((a : fin (n + 1)) : ℕ) = a :=\ncoe_val_of_lt h\n\n/-- Converting a `fin (n + 1)` to `ℕ` and back results in the same\nvalue. -/\n@[simp] lemma coe_coe_eq_self {n : ℕ} (a : fin (n + 1)) : ((a : ℕ) : 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 [←fin.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 ≤ 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, ←add_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)) ≠ 1 := ne_of_lt one_pos\n\n@[simp] lemma zero_eq_one_iff : (0 : fin (n + 1)) = 1 ↔ 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 ↔ 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 : ℕ) = 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 : ℕ) : fin n ↪o fin (n + 1) :=\norder_embedding.of_strict_mono fin.succ $ λ ⟨i, hi⟩ ⟨j, hj⟩ h, succ_lt_succ h\n\n@[simp] lemma coe_succ_embedding : ⇑(succ_embedding n) = fin.succ := rfl\n\n@[simp] lemma succ_le_succ_iff : a.succ ≤ b.succ ↔ a ≤ b :=\n(succ_embedding n).le_iff_le\n\n@[simp] lemma succ_lt_succ_iff : a.succ < b.succ ↔ a < b :=\n(succ_embedding n).lt_iff_lt\n\nlemma succ_injective (n : ℕ) : injective (@fin.succ n) :=\n(succ_embedding n).injective\n\n@[simp] lemma succ_inj {a b : fin n} : a.succ = b.succ ↔ a = b :=\n(succ_injective n).eq_iff\n\nlemma succ_ne_zero {n} : ∀ k : fin n, fin.succ k ≠ 0\n| ⟨k, hk⟩ 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 : ℕ) (h : i < n) : fin.succ ⟨i, h⟩ = ⟨i + 1, nat.succ_lt_succ h⟩ :=\nrfl\n\nlemma mk_succ_pos (i : ℕ) (h : i < n) : (0 : fin (n + 1)) < ⟨i.succ, add_lt_add_right h 1⟩ :=\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 [←succ_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) ≠ 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 := ⟨i.1, h⟩\n\n@[simp] lemma coe_cast_lt (i : fin m) (h : i.1 < n) : (cast_lt i h : ℕ) = i := rfl\n\n@[simp] lemma cast_lt_mk (i n m : ℕ) (hn : i < n) (hm : i < m) : cast_lt ⟨i, hn⟩ hm = ⟨i, hm⟩ := rfl\n\n/-- `cast_le h i` embeds `i` into a larger `fin` type.  -/\ndef cast_le (h : n ≤ m) : fin n ↪o fin m :=\norder_embedding.of_strict_mono (λ a, cast_lt a (lt_of_lt_of_le a.2 h)) $ λ a b h, h\n\n@[simp] lemma coe_cast_le (h : n ≤ m) (i : fin n) : (cast_le h i : ℕ) = i := rfl\n\n@[simp] lemma cast_le_mk (i n m : ℕ) (hn : i < n) (h : n ≤ m) :\n  cast_le h ⟨i, hn⟩ = ⟨i, lt_of_lt_of_le hn h⟩ := rfl\n\n@[simp] lemma cast_le_zero {n m : ℕ} (h : n.succ ≤ m.succ) :\n  cast_le h 0 = 0 :=\nby simp [eq_iff_veq]\n\n@[simp] lemma range_cast_le {n k : ℕ} (h : n ≤ k) :\n  set.range (cast_le h) = {i | (i : ℕ) < n} :=\nset.ext (λ x, ⟨λ ⟨y, hy⟩, hy ▸ y.2, λ hx, ⟨⟨x, hx⟩, fin.ext rfl⟩⟩)\n\n@[simp] lemma coe_of_injective_cast_le_symm {n k : ℕ} (h : n ≤ k) (i : fin k) (hi) :\n  ((equiv.of_injective _ (cast_le h).injective).symm ⟨i, hi⟩ : ℕ) = i :=\nbegin\n  rw ← coe_cast_le,\n  exact congr_arg coe (equiv.apply_of_injective_symm _ _ _)\nend\n\n/-- `cast eq i` embeds `i` into a equal `fin` type. -/\ndef cast (eq : n = m) : fin n ≃o fin m :=\n{ to_equiv := ⟨cast_le eq.le, cast_le eq.symm.le, λ a, eq_of_veq rfl, λ a, eq_of_veq rfl⟩,\n  map_rel_iff' := λ a b, iff.rfl }\n\n@[simp] lemma symm_cast (h : n = m) : (cast h).symm = cast h.symm := rfl\n\nlemma coe_cast (h : n = m) (i : fin n) : (cast h i : ℕ) = i := rfl\n\n@[simp] lemma cast_mk (h : n = m) (i : ℕ) (hn : i < n) :\n  cast h ⟨i, hn⟩ = ⟨i, lt_of_lt_of_le hn h.le⟩ := rfl\n\n@[simp] lemma cast_trans {k : ℕ} (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 ▸ 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 → fin m) = _root_.cast (h ▸ rfl) :=\nby { subst h, ext, simp }\n\n/-- `cast_add m i` embeds `i : fin n` in `fin (n+m)`. -/\ndef cast_add (m) : fin n ↪o fin (n + m) := cast_le $ le_add_right n m\n\n@[simp] lemma coe_cast_add (m : ℕ) (i : fin n) : (cast_add m i : ℕ) = i := rfl\n\n@[simp] lemma cast_add_mk (m : ℕ) (i : ℕ) (h : i < n) :\n  cast_add m ⟨i, h⟩ = ⟨i, lt_add_right i n m h⟩ := rfl\n\n/-- `cast_succ i` embeds `i : fin n` in `fin (n+1)`. -/\ndef cast_succ : fin n ↪o fin (n + 1) := cast_add 1\n\n@[simp] lemma coe_cast_succ (i : fin n) : (i.cast_succ : ℕ) = i := rfl\n\n@[simp] lemma cast_succ_mk (n i : ℕ) (h : i < n) : cast_succ ⟨i, h⟩ = ⟨i, nat.lt.step h⟩ := 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 ≤ j.cast_succ ↔ 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 : ℕ) : (last n).succ = last (n.succ) := rfl\n\n@[simp] lemma succ_eq_last_succ {n : ℕ} (i : fin n.succ) :\n  i.succ = last (n + 1) ↔ i = last n :=\nby rw [← succ_last, (succ_injective _).eq_iff]\n\n@[simp] lemma cast_succ_cast_lt (i : fin (n + 1)) (h : (i : ℕ) < n) : cast_succ (cast_lt i h) = i :=\nfin.eq_of_veq rfl\n\n@[simp] lemma cast_lt_cast_succ {n : ℕ} (a : fin n) (h : (a : ℕ) < 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 ↔ a < b :=\n(@cast_succ n).lt_iff_lt\n\nlemma cast_succ_injective (n : ℕ) : injective (@fin.cast_succ n) :=\n(cast_succ : fin n ↪o _).injective\n\nlemma cast_succ_inj {a b : fin n} : a.cast_succ = b.cast_succ ↔ 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 : ℕ} : 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\nlemma cast_succ_fin_succ (n : ℕ) (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 : ℕ} :\n  set.range (cast_succ : fin n → fin n.succ) = {i | (i : ℕ) < n} :=\nrange_cast_le _\n\n@[simp] lemma coe_of_injective_cast_succ_symm {n : ℕ} (i : fin n.succ) (hi) :\n  ((equiv.of_injective cast_succ (cast_succ_injective _)).symm ⟨i, hi⟩ : ℕ) = i :=\nbegin\n  rw ← coe_cast_succ,\n  exact congr_arg coe (equiv.apply_of_injective_symm _ _ _)\nend\n\n/-- `add_nat m i` adds `m` to `i`, generalizes `fin.succ`. -/\ndef add_nat (m) : fin n ↪o fin (n + m) :=\norder_embedding.of_strict_mono (λ i, ⟨(i : ℕ) + m, add_lt_add_right i.2 _⟩) $\n  λ i j h, lt_iff_coe_lt_coe.2 $ add_lt_add_right h _\n\n@[simp] lemma coe_add_nat (m : ℕ) (i : fin n) : (add_nat m i : ℕ) = i + m := rfl\n\n/-- `nat_add n i` adds `n` to `i` \"on the left\". -/\ndef nat_add (n) {m} : fin m ↪o fin (n + m) :=\norder_embedding.of_strict_mono (λ i, ⟨n + (i : ℕ), add_lt_add_left i.2 _⟩) $\n  λ i j h, lt_iff_coe_lt_coe.2 $ add_lt_add_left h _\n\n@[simp] lemma coe_nat_add (n : ℕ) {m : ℕ} (i : fin m) : (nat_add n i : ℕ) = n + i := rfl\n\nlemma nat_add_zero {n : ℕ} : fin.nat_add 0 = (fin.cast (zero_add n).symm).to_rel_embedding :=\nby { ext, apply zero_add }\n\nend succ\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…`.\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 : Π n, fin n → Sort*}\n  (H0 : Π n, C (succ n) 0)\n  (Hs : Π n i, C n i → C (succ n) i.succ) : Π {n : ℕ} (i : fin n), C n i\n| 0        i           := i.elim0\n| (succ n) ⟨0, _⟩      := H0 _\n| (succ n) ⟨succ i, h⟩ := Hs _ _ (succ_rec ⟨i, lt_of_succ_lt_succ h⟩)\n\n/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`.\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 : ℕ} (i : fin n)\n  {C : Π n, fin n → Sort*}\n  (H0 : Π n, C (succ n) 0)\n  (Hs : Π n i, C n i → C (succ n) i.succ) : C n i :=\ni.succ_rec H0 Hs\n\n@[simp] theorem succ_rec_on_zero {C : ∀ n, fin n → 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 : ∀ n, fin n → 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) → Sort*}\n  (h0 : C 0)\n  (hs : ∀ i : fin n, C i.cast_succ → C i.succ) :\n  Π (i : fin (n + 1)), C i :=\nbegin\n  rintro ⟨i, hi⟩,\n  induction i with i IH,\n  { rwa [fin.mk_zero] },\n  { refine hs ⟨i, lt_of_succ_lt_succ hi⟩ _,\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) → Sort*}\n  (h0 : C 0)\n  (hs : ∀ i : fin n, C i.cast_succ → C i.succ) : C i :=\ninduction h0 hs i\n\n/-- Define `f : Π 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) → Sort*} (H0 : C 0) (Hs : Π i : fin n, C (i.succ)) :\n  Π (i : fin (succ n)), C i :=\ninduction H0 (λ i _, Hs i)\n\n@[simp] theorem cases_zero {n} {C : fin (succ n) → Sort*} {H0 Hs} : @fin.cases n C H0 Hs 0 = H0 :=\nrfl\n\n@[simp] theorem cases_succ {n} {C : fin (succ n) → 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) → Sort*} {H0 Hs} {i : ℕ} (h : i + 1 < n + 1) :\n  @fin.cases n C H0 Hs ⟨i.succ, h⟩ = Hs ⟨i, lt_of_succ_lt_succ h⟩ :=\nby cases i; refl\n\nlemma forall_fin_succ {P : fin (n+1) → Prop} :\n  (∀ i, P i) ↔ P 0 ∧ (∀ i:fin n, P i.succ) :=\n⟨λ H, ⟨H 0, λ i, H _⟩, λ ⟨H0, H1⟩ i, fin.cases H0 H1 i⟩\n\nlemma exists_fin_succ {P : fin (n+1) → Prop} :\n  (∃ i, P i) ↔ P 0 ∨ (∃i:fin n, P i.succ) :=\n⟨λ ⟨i, h⟩, fin.cases or.inl (λ i hi, or.inr ⟨i, hi⟩) i h,\n  λ h, or.elim h (λ h, ⟨0, h⟩) $ λ⟨i, hi⟩, ⟨i.succ, hi⟩⟩\n\nend rec\n\nsection pred\n\n/-!\n### pred\n-/\n\n@[simp] lemma coe_pred (j : fin (n+1)) (h : j ≠ 0) : (j.pred h : ℕ) = j - 1 :=\nby { cases j, refl }\n\n@[simp] lemma succ_pred : ∀(i : fin (n+1)) (h : i ≠ 0), (i.pred h).succ = i\n| ⟨0,     h⟩ hi := by contradiction\n| ⟨n + 1, h⟩ hi := rfl\n\n@[simp] lemma pred_succ (i : fin n) {h : i.succ ≠ 0} : i.succ.pred h = i :=\nby { cases i, refl }\n\n@[simp] lemma pred_mk_succ (i : ℕ) (h : i < n + 1) :\n  fin.pred ⟨i + 1, add_lt_add_right h 1⟩ (ne_of_vne (ne_of_gt (mk_succ_pos i h))) = ⟨i, h⟩ :=\nby simp only [ext_iff, coe_pred, coe_mk, nat.add_sub_cancel]\n\n-- This is not a simp lemma by default, because `pred_mk_succ` is nicer when it applies.\nlemma pred_mk {n : ℕ} (i : ℕ) (h : i < n + 1) (w) :\n  fin.pred ⟨i, h⟩ w =\n  ⟨i - 1, by rwa nat.sub_lt_right_iff_lt_add (nat.pos_of_ne_zero (fin.vne_of_ne w))⟩ :=\nrfl\n\n@[simp] lemma pred_le_pred_iff {n : ℕ} {a b : fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :\n  a.pred ha ≤ b.pred hb ↔ a ≤ b :=\nby rw [←succ_le_succ_iff, succ_pred, succ_pred]\n\n@[simp] lemma pred_lt_pred_iff {n : ℕ} {a b : fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :\n  a.pred ha < b.pred hb ↔ a < b :=\nby rw [←succ_lt_succ_iff, succ_pred, succ_pred]\n\n@[simp] lemma pred_inj :\n  ∀ {a b : fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b\n| ⟨0,   _⟩  b         ha hb := by contradiction\n| ⟨i+1, _⟩  ⟨0,   _⟩  ha hb := by contradiction\n| ⟨i+1, hi⟩ ⟨j+1, hj⟩ ha hb := by simp [fin.eq_iff_veq]\n\n@[simp] lemma pred_one {n : ℕ} : 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 : ℕ) < 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, nat.add_sub_cancel],\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 ≤ (i : ℕ)) : fin n :=\n⟨(i : ℕ) - m, by { rw [nat.sub_lt_right_iff_lt_add h], exact i.is_lt }⟩\n\n@[simp] lemma coe_sub_nat (i : fin (n + m)) (h : m ≤ i) : (i.sub_nat m h : ℕ) = i - m :=\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\nend pred\n\nsection add_group\n\nopen nat int\n\n/-- Negation on `fin n` -/\ninstance (n : ℕ) : has_neg (fin n) :=\n⟨λ a, ⟨(n - a) % n, nat.mod_lt _ (lt_of_le_of_lt (nat.zero_le _) a.2)⟩⟩\n\n/-- Abelian group structure on `fin (n+1)`. -/\ninstance (n : ℕ) : add_comm_group (fin (n+1)) :=\n{ add_left_neg := λ ⟨a, ha⟩, fin.ext $ trans (nat.mod_add_mod _ _ _) $\n    by { rw [fin.coe_mk, fin.coe_zero, nat.sub_add_cancel, nat.mod_self], exact le_of_lt ha },\n  sub_eq_add_neg := λ ⟨a, ha⟩ ⟨b, hb⟩, 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) : ℕ) = (n - a) % n := rfl\n\nprotected lemma coe_sub (a b : fin n) : ((a - b : fin n) : ℕ) = (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 (λ i : fin n, if i.cast_succ < p then i.cast_succ else i.succ) :=\n(cast_succ : fin n ↪o _).strict_mono.ite (succ_embedding n).strict_mono\n  (λ i j hij hj, lt_trans ((cast_succ : fin n ↪o _).lt_iff_lt.2 hij) hj)\n  (λ 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 ↪o 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/-- Embedding `fin n` into `fin (n + 1)` with a hole around zero embeds by `succ`. -/\n@[simp] lemma succ_above_zero : ⇑(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 ≤ 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 ∨ p ≤ 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 ∨ p < i.succ :=\nor.cases_on (succ_above_lt_ge p i)\n  (λ h, or.inl h) (λ 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 ↔ 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 ↔ p ≤ 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 ≠ p :=\nbegin\n  intro eq,\n  by_cases H : i.cast_succ < p,\n  { simpa [lt_irrefl, ←succ_above_below _ _ H, eq] using H },\n  { simpa [←succ_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/-- The range of `p.succ_above` is everything except `p`. -/\nlemma range_succ_above (p : fin (n + 1)) : set.range (p.succ_above) = { i | i ≠ p } :=\nbegin\n  ext,\n  simp only [set.mem_range, ne.def, set.mem_set_of_eq],\n  split,\n  { rintro ⟨y, rfl⟩,\n    exact succ_above_ne _ _ },\n  { intro h,\n    cases lt_or_gt_of_ne h with H H,\n    { refine ⟨x.cast_lt _, _⟩,\n      { exact lt_of_lt_of_le H p.le_last },\n      { rw succ_above_below,\n        { simp },\n        { exact H } } },\n    { refine ⟨x.pred _, _⟩,\n      { exact (ne_of_lt (lt_of_le_of_lt p.zero_le H)).symm },\n      { rw succ_above_above,\n        { simp },\n        { simpa [le_iff_coe_le_coe] using nat.le_pred_of_lt H } } } }\nend\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 ↔ 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λ _ _ h, by simpa [range_succ_above] using congr_arg (λ f : fin n ↪o fin (n + 1), (set.range f)ᶜ) h\n\n/-- `succ_above` is injective at the pivot -/\nlemma succ_above_left_inj {x y : fin (n + 1)} :\n  x.succ_above = y.succ_above ↔ x = y :=\nsucc_above_left_injective.eq_iff\n\n@[simp] lemma zero_succ_above {n : ℕ} (i : fin n) :\n  (0 : fin (n + 1)).succ_above i = i.succ :=\nrfl\n\n@[simp] lemma succ_succ_above_zero {n : ℕ} (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 : ℕ} (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  (λ 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  (λ h, have h' : i.succ ≤ 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 : ℕ} :\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 : ℕ} (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 : ℕ} (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 : ℕ} :\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λ 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 _ ≤ _ : nat.pred_le _\n        ... ≤ _ : 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 (λ p, pred_above p i) :=\nλ 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 ≠ 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 : ℕ) (h : i < n + 1) :\n  cast_pred ⟨i, lt_succ_of_lt h⟩ = ⟨i, h⟩ :=\nbegin\n  have : ¬cast_succ (last n) < ⟨i, lt_succ_of_lt h⟩,\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 ≤ p.cast_succ) :\n  p.pred_above i = i.cast_pred :=\nbegin\n  have : i ≤ (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 ≠ 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 ⟨p, _⟩,\n  rcases i with ⟨i, _⟩,\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 ⟨p, _⟩,\n  rcases i with ⟨i, _⟩,\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\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 : ℕ) ≤ 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 : ℕ) < i ↔ 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 ←cast_succ_cast_pred H,\n    simp }\nend\n\nlemma lt_last_iff_coe_cast_pred {i : fin (n + 2)} : i < fin.last _ ↔ (i.cast_pred : ℕ) = i :=\nbegin\n  rcases i.le_last.eq_or_lt with rfl|H,\n  { simp },\n  { simp only [H],\n    rw ←cast_succ_cast_pred H,\n    simp }\nend\n\nlemma forall_iff_succ_above {p : fin (n + 1) → Prop} (i : fin (n + 1)) :\n  (∀ j, p j) ↔ p i ∧ ∀ j, p (i.succ_above j) :=\n⟨λ h, ⟨h _, λ j, h _⟩,\n  λ h j, if hj : j = i then (hj.symm ▸ h.1) else\n  begin\n    cases n,\n    { convert h.1 },\n    { cases lt_or_gt_of_ne hj with lt gt,\n      { rcases j.zero_le.eq_or_lt with rfl|H,\n        { convert h.2 0, rw succ_above_below; simp [lt] },\n        { have ltl : j < last _ := lt.trans_le i.le_last,\n          convert h.2 j.cast_pred,\n          simp [succ_above_below, cast_succ_cast_pred ltl, lt] } },\n      { convert h.2 (j.pred (i.zero_le.trans_lt gt).ne.symm),\n        rw succ_above_above;\n        simp [le_cast_succ_iff, gt.lt] } }\n  end⟩\n\nend pred_above\n\n/-- `min n m` as an element of `fin (m + 1)` -/\ndef clamp (n m : ℕ) : fin (m + 1) := of_nat $ min n m\n\n@[simp] lemma coe_clamp (n m : ℕ) : (clamp n m : ℕ) = min n m :=\nnat.mod_eq_of_lt $ nat.lt_succ_iff.mpr $ min_le_right _ _\n\nsection tuple\n/-!\n### Tuples\n\nWe can think of the type `Π(i : fin n), α i` as `n`-tuples of elements of possibly varying type\n`α i`. A particular case is `fin n → α` of elements with all the same type. Here are some relevant\noperations, first about adding or removing elements at the beginning of a tuple.\n-/\n\n/-- There is exactly one tuple of size zero. -/\ninstance tuple0_unique (α : fin 0 → Sort u) : unique (Π i : fin 0, α i) :=\npi.unique_of_empty fin.elim0 α\n\n@[simp] lemma tuple0_le {α : Π i : fin 0, Type*} [Π i, preorder (α i)] (f g : Π i, α i) : f ≤ g :=\nfin_zero_elim\n\nvariables {α : fin (n+1) → Type u} (x : α 0) (q : Πi, α i) (p : Π(i : fin n), α (i.succ))\n  (i : fin n) (y : α i.succ) (z : α 0)\n\n/-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/\ndef tail (q : Πi, α i) : (Π(i : fin n), α (i.succ)) := λ i, q i.succ\n\nlemma tail_def {n : ℕ} {α : fin (n+1) → Type*} {q : Π i, α i} :\n  tail (λ k : fin (n+1), q k) = (λ k : fin n, q k.succ) := rfl\n\n/-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/\ndef cons (x : α 0) (p : Π(i : fin n), α (i.succ)) : Πi, α i :=\nλ j, fin.cases x p j\n\n@[simp] lemma tail_cons : tail (cons x p) = p :=\nby simp [tail, cons]\n\n@[simp] lemma cons_succ : cons x p i.succ = p i :=\nby simp [cons]\n\n@[simp] lemma cons_zero : cons x p 0 = x :=\nby simp [cons]\n\n/-- Updating a tuple and adding an element at the beginning commute. -/\n@[simp] lemma cons_update : cons x (update p i y) = update (cons x p) i.succ y :=\nbegin\n  ext j,\n  by_cases h : j = 0,\n  { rw h, simp [ne.symm (succ_ne_zero i)] },\n  { let j' := pred j h,\n    have : j'.succ = j := succ_pred j h,\n    rw [← this, cons_succ],\n    by_cases h' : j' = i,\n    { rw h', simp },\n    { have : j'.succ ≠ i.succ, by rwa [ne.def, succ_inj],\n      rw [update_noteq h', update_noteq this, cons_succ] } }\nend\n\n/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it\ndirectly. -/\nlemma update_cons_zero : update (cons x p) 0 z = cons z p :=\nbegin\n  ext j,\n  by_cases h : j = 0,\n  { rw h, simp },\n  { simp only [h, update_noteq, ne.def, not_false_iff],\n    let j' := pred j h,\n    have : j'.succ = j := succ_pred j h,\n    rw [← this, cons_succ, cons_succ] }\nend\n\n/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/\n@[simp] lemma cons_self_tail : cons (q 0) (tail q) = q :=\nbegin\n  ext j,\n  by_cases h : j = 0,\n  { rw h, simp },\n  { let j' := pred j h,\n    have : j'.succ = j := succ_pred j h,\n    rw [← this, tail, cons_succ] }\nend\n\n/-- Updating the first element of a tuple does not change the tail. -/\n@[simp] lemma tail_update_zero : tail (update q 0 z) = tail q :=\nby { ext j, simp [tail, fin.succ_ne_zero] }\n\n/-- Updating a nonzero element and taking the tail commute. -/\n@[simp] lemma tail_update_succ :\n  tail (update q i.succ y) = update (tail q) i y :=\nbegin\n  ext j,\n  by_cases h : j = i,\n  { rw h, simp [tail] },\n  { simp [tail, (fin.succ_injective n).ne h, h] }\nend\n\nlemma comp_cons {α : Type*} {β : Type*} (g : α → β) (y : α) (q : fin n → α) :\n  g ∘ (cons y q) = cons (g y) (g ∘ q) :=\nbegin\n  ext j,\n  by_cases h : j = 0,\n  { rw h, refl },\n  { let j' := pred j h,\n    have : j'.succ = j := succ_pred j h,\n    rw [← this, cons_succ, comp_app, cons_succ] }\nend\n\nlemma comp_tail {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) :\n  g ∘ (tail q) = tail (g ∘ q) :=\nby { ext j, simp [tail] }\n\nlemma le_cons [Π i, preorder (α i)] {x : α 0} {q : Π i, α i} {p : Π i : fin n, α i.succ} :\n  q ≤ cons x p ↔ q 0 ≤ x ∧ tail q ≤ p :=\nforall_fin_succ.trans $ and_congr iff.rfl $ forall_congr $ λ j, by simp [tail]\n\nlemma cons_le [Π i, preorder (α i)] {x : α 0} {q : Π i, α i} {p : Π i : fin n, α i.succ} :\n  cons x p ≤ q ↔ x ≤ q 0 ∧ p ≤ tail q :=\n@le_cons  _ (λ i, order_dual (α i)) _ x q p\n\n@[simp]\nlemma range_cons {α : Type*} {n : ℕ} (x : α) (b : fin n → α) :\n  set.range (fin.cons x b : fin n.succ → α) = insert x (set.range b) :=\nbegin\n  ext y,\n  simp only [set.mem_range, set.mem_insert_iff],\n  split,\n  { rintros ⟨i, rfl⟩,\n    refine cases (or.inl (cons_zero _ _)) (λ i, or.inr ⟨i, _⟩) i,\n    rw cons_succ },\n  { rintros (rfl | ⟨i, hi⟩),\n    { exact ⟨0, fin.cons_zero _ _⟩ },\n    { refine ⟨i.succ, _⟩,\n      rw [cons_succ, hi] } }\nend\n\n/-- `fin.append ho u v` appends two vectors of lengths `m` and `n` to produce\none of length `o = m + n`.  `ho` provides control of definitional equality\nfor the vector length. -/\ndef append {α : Type*} {o : ℕ} (ho : o = m + n) (u : fin m → α) (v : fin n → α) : fin o → α :=\nλ i, if h : (i : ℕ) < m\n  then u ⟨i, h⟩\n  else v ⟨(i : ℕ) - m, (nat.sub_lt_left_iff_lt_add (le_of_not_lt h)).2 (ho ▸ i.property)⟩\n\n@[simp] lemma fin_append_apply_zero {α : Type*} {o : ℕ} (ho : (o + 1) = (m + 1) + n)\n  (u : fin (m + 1) → α) (v : fin n → α) :\n  fin.append ho u v 0 = u 0 := rfl\n\nend tuple\n\nsection tuple_right\n/-! In the previous section, we have discussed inserting or removing elements on the left of a\ntuple. In this section, we do the same on the right. A difference is that `fin (n+1)` is constructed\ninductively from `fin n` starting from the left, not from the right. This implies that Lean needs\nmore help to realize that elements belong to the right types, i.e., we need to insert casts at\nseveral places. -/\n\nvariables {α : fin (n+1) → Type u} (x : α (last n)) (q : Πi, α i) (p : Π(i : fin n), α i.cast_succ)\n(i : fin n) (y : α i.cast_succ) (z : α (last n))\n\n/-- The beginning of an `n+1` tuple, i.e., its first `n` entries -/\ndef init (q : Πi, α i) (i : fin n) : α i.cast_succ :=\nq i.cast_succ\n\nlemma init_def {n : ℕ} {α : fin (n+1) → Type*} {q : Π i, α i} :\n  init (λ k : fin (n+1), q k) = (λ k : fin n, q k.cast_succ) := rfl\n\n/-- Adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from\n`cons` (i.e., adding an element to the left of a tuple) read in reverse order. -/\ndef snoc (p : Π(i : fin n), α i.cast_succ) (x : α (last n)) (i : fin (n+1)) : α i :=\nif h : i.val < n\nthen _root_.cast (by rw fin.cast_succ_cast_lt i h) (p (cast_lt i h))\nelse _root_.cast (by rw eq_last_of_not_lt h) x\n\n@[simp] lemma init_snoc : init (snoc p x) = p :=\nbegin\n  ext i,\n  have h' := fin.cast_lt_cast_succ i i.is_lt,\n  simp [init, snoc, i.is_lt, h'],\n  convert cast_eq rfl (p i)\nend\n\n@[simp] lemma snoc_cast_succ : snoc p x i.cast_succ = p i :=\nbegin\n  have : i.cast_succ.val < n := i.is_lt,\n  have h' := fin.cast_lt_cast_succ i i.is_lt,\n  simp [snoc, this, h'],\n  convert cast_eq rfl (p i)\nend\n\n@[simp] lemma snoc_last : snoc p x (last n) = x :=\nby { simp [snoc] }\n\n/-- Updating a tuple and adding an element at the end commute. -/\n@[simp] lemma snoc_update : snoc (update p i y) x = update (snoc p x) i.cast_succ y :=\nbegin\n  ext j,\n  by_cases h : j.val < n,\n  { simp only [snoc, h, dif_pos],\n    by_cases h' : j = cast_succ i,\n    { have C1 : α i.cast_succ = α j, by rw h',\n      have E1 : update (snoc p x) i.cast_succ y j = _root_.cast C1 y,\n      { have : update (snoc p x) j (_root_.cast C1 y) j = _root_.cast C1 y, by simp,\n        convert this,\n        { exact h'.symm },\n        { exact heq_of_cast_eq (congr_arg α (eq.symm h')) rfl } },\n      have C2 : α i.cast_succ = α (cast_succ (cast_lt j h)),\n        by rw [cast_succ_cast_lt, h'],\n      have E2 : update p i y (cast_lt j h) = _root_.cast C2 y,\n      { have : update p (cast_lt j h) (_root_.cast C2 y) (cast_lt j h) = _root_.cast C2 y,\n          by simp,\n        convert this,\n        { simp [h, h'] },\n        { exact heq_of_cast_eq C2 rfl } },\n      rw [E1, E2],\n      exact eq_rec_compose _ _ _ },\n    { have : ¬(cast_lt j h = i),\n        by { assume E, apply h', rw [← E, cast_succ_cast_lt] },\n      simp [h', this, snoc, h] } },\n  { rw eq_last_of_not_lt h,\n    simp [ne.symm (ne_of_lt (cast_succ_lt_last i))] }\nend\n\n/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it\ndirectly. -/\nlemma update_snoc_last : update (snoc p x) (last n) z = snoc p z :=\nbegin\n  ext j,\n  by_cases h : j.val < n,\n  { have : j ≠ last n := ne_of_lt h,\n    simp [h, update_noteq, this, snoc] },\n  { rw eq_last_of_not_lt h,\n    simp }\nend\n\n/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/\n@[simp] lemma snoc_init_self : snoc (init q) (q (last n)) = q :=\nbegin\n  ext j,\n  by_cases h : j.val < n,\n  { have : j ≠ last n := ne_of_lt h,\n    simp [h, update_noteq, this, snoc, init, cast_succ_cast_lt],\n    have A : cast_succ (cast_lt j h) = j := cast_succ_cast_lt _ _,\n    rw ← cast_eq rfl (q j),\n    congr' 1; rw A },\n  { rw eq_last_of_not_lt h,\n    simp }\nend\n\n/-- Updating the last element of a tuple does not change the beginning. -/\n@[simp] lemma init_update_last : init (update q (last n) z) = init q :=\nby { ext j, simp [init, ne_of_lt, cast_succ_lt_last] }\n\n/-- Updating an element and taking the beginning commute. -/\n@[simp] lemma init_update_cast_succ :\n  init (update q i.cast_succ y) = update (init q) i y :=\nbegin\n  ext j,\n  by_cases h : j = i,\n  { rw h, simp [init] },\n  { simp [init, h] }\nend\n\n/-- `tail` and `init` commute. We state this lemma in a non-dependent setting, as otherwise it\nwould involve a cast to convince Lean that the two types are equal, making it harder to use. -/\nlemma tail_init_eq_init_tail {β : Type*} (q : fin (n+2) → β) :\n  tail (init q) = init (tail q) :=\nby { ext i, simp [tail, init, cast_succ_fin_succ] }\n\n/-- `cons` and `snoc` commute. We state this lemma in a non-dependent setting, as otherwise it\nwould involve a cast to convince Lean that the two types are equal, making it harder to use. -/\nlemma cons_snoc_eq_snoc_cons {β : Type*} (a : β) (q : fin n → β) (b : β) :\n  @cons n.succ (λ i, β) a (snoc q b) = snoc (cons a q) b :=\nbegin\n  ext i,\n  by_cases h : i = 0,\n  { rw h, refl },\n  set j := pred i h with ji,\n  have : i = j.succ, by rw [ji, succ_pred],\n  rw [this, cons_succ],\n  by_cases h' : j.val < n,\n  { set k := cast_lt j h' with jk,\n    have : j = k.cast_succ, by rw [jk, cast_succ_cast_lt],\n    rw [this, ← cast_succ_fin_succ],\n    simp },\n  rw [eq_last_of_not_lt h', succ_last],\n  simp\nend\n\n\nlemma comp_snoc {α : Type*} {β : Type*} (g : α → β) (q : fin n → α) (y : α) :\n  g ∘ (snoc q y) = snoc (g ∘ q) (g y) :=\nbegin\n  ext j,\n  by_cases h : j.val < n,\n  { have : j ≠ last n := ne_of_lt h,\n    simp [h, this, snoc, cast_succ_cast_lt] },\n  { rw eq_last_of_not_lt h,\n    simp }\nend\n\nlemma comp_init {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) :\n  g ∘ (init q) = init (g ∘ q) :=\nby { ext j, simp [init] }\n\nend tuple_right\n\nsection insert_nth\n\nvariables {α : fin (n+1) → Type u} {β : Type v}\n\n/-- Insert an element into a tuple at a given position, auxiliary definition.\nFor the general definition, see `insert_nth`. -/\ndef insert_nth' {α : fin (n + 2) → Type u} (i : fin (n + 2)) (x : α i)\n  (p : Π j : fin (n + 1), α (i.succ_above j)) (j : fin (n + 2)) : α j :=\nif h : i = j\nthen _root_.cast (congr_arg α h) x\nelse if h' : j < i then _root_.cast (congr_arg α $ begin\n  obtain ⟨k, hk⟩ : ∃ (k : fin (n + 1)), k.cast_succ = j,\n    { refine ⟨⟨(j : ℕ), _⟩, _⟩,\n      { exact lt_of_lt_of_le h' i.is_le, },\n      { simp },\n    },\n  subst hk,\n  simp [succ_above_below, h'],\nend)\n  (p j.cast_pred) else _root_.cast (congr_arg α $ begin\n  have lt : i < j := lt_of_le_of_ne (le_of_not_lt h') h,\n  have : j ≠ 0 := (ne_of_gt (lt_of_le_of_lt i.zero_le lt)),\n  rw [←succ_pred j this, ←le_cast_succ_iff] at lt,\n  simp [pred_above_zero this, succ_above_above _ _ lt]\nend) (p (fin.pred_above 0 j))\n\n/-- Insert an element into a tuple at a given position. For `i = 0` see `fin.cons`,\nfor `i = fin.last n` see `fin.snoc`. -/\ndef insert_nth : Π {n : ℕ} {α : fin (n + 1) → Type u} (i : fin (n + 1)) (x : α i)\n  (p : Π j : fin n, α (i.succ_above j)) (j : fin (n + 1)), α j\n| 0       _ _ x _ _ := _root_.cast (by congr) x\n| (n + 1) _ i x p j := insert_nth' i x p j\n\n@[simp] lemma insert_nth_apply_same (i : fin (n + 1)) (x : α i) (p : Π j, α (i.succ_above j)) :\n  insert_nth i x p i = x :=\nby { cases n; simp [insert_nth, insert_nth'] }\n\n@[simp] lemma insert_nth_apply_succ_above (i : fin (n + 1)) (x : α i) (p : Π j, α (i.succ_above j))\n  (j : fin n) :\n  insert_nth i x p (i.succ_above j) = p j :=\nbegin\n  cases n,\n  { exact j.elim0 },\n  simp only [insert_nth, insert_nth', dif_neg (succ_above_ne _ _).symm],\n  cases succ_above_lt_ge i j with h h,\n  { rw dif_pos,\n    refine eq_of_heq ((cast_heq _ _).trans _),\n    { simp [h] },\n    { congr,\n      simp [succ_above_below, h] } },\n  { rw dif_neg,\n    refine eq_of_heq ((cast_heq _ _).trans _),\n    { simp [h] },\n    { congr,\n      simp [succ_above_above, h, succ_ne_zero] } }\nend\n\n@[simp] lemma insert_nth_comp_succ_above (i : fin (n + 1)) (x : β) (p : fin n → β) :\n  insert_nth i x p ∘ i.succ_above = p :=\nfunext $ insert_nth_apply_succ_above i x p\n\nlemma insert_nth_eq_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :\n  i.insert_nth x p = q ↔ q i = x ∧ p = (λ j, q (i.succ_above j)) :=\nby simp [funext_iff, forall_iff_succ_above i, eq_comm]\n\nlemma eq_insert_nth_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :\n  q = i.insert_nth x p ↔ q i = x ∧ p = (λ j, q (i.succ_above j)) :=\neq_comm.trans insert_nth_eq_iff\n\nlemma insert_nth_zero (x : α 0) (p : Π j : fin n, α (succ_above 0 j)) :\n  insert_nth 0 x p = cons x (λ j, _root_.cast (congr_arg α (congr_fun succ_above_zero j)) (p j)) :=\nbegin\n  refine insert_nth_eq_iff.2 ⟨by simp, _⟩,\n  ext j,\n  convert (cons_succ _ _ _).symm\nend\n\n@[simp] lemma insert_nth_zero' (x : β) (p : fin n → β) :\n  @insert_nth _ (λ _, β) 0 x p = cons x p :=\nby simp [insert_nth_zero]\n\nlemma insert_nth_last (x : α (last n)) (p : Π j : fin n, α ((last n).succ_above j)) :\n  insert_nth (last n) x p =\n    snoc (λ j, _root_.cast (congr_arg α (succ_above_last_apply j)) (p j)) x :=\nbegin\n  refine insert_nth_eq_iff.2 ⟨by simp, _⟩,\n  ext j,\n  apply eq_of_heq,\n  transitivity snoc (λ j, _root_.cast (congr_arg α (succ_above_last_apply j)) (p j)) x j.cast_succ,\n  { rw [snoc_cast_succ], exact (cast_heq _ _).symm },\n  { apply congr_arg_heq,\n    rw [succ_above_last] }\nend\n\n@[simp] lemma insert_nth_last' (x : β) (p : fin n → β) :\n  @insert_nth _ (λ _, β) (last n) x p = snoc p x :=\nby simp [insert_nth_last]\n\nvariables [Π i, preorder (α i)]\n\nlemma insert_nth_le_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :\n  i.insert_nth x p ≤ q ↔ x ≤ q i ∧ p ≤ (λ j, q (i.succ_above j)) :=\nby simp [pi.le_def, forall_iff_succ_above i]\n\nlemma le_insert_nth_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :\n  q ≤ i.insert_nth x p ↔ q i ≤ x ∧ (λ j, q (i.succ_above j)) ≤ p :=\nby simp [pi.le_def, forall_iff_succ_above i]\n\nopen set\n\nlemma insert_nth_mem_Icc {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)}\n  {q₁ q₂ : Π j, α j} :\n  i.insert_nth x p ∈ Icc q₁ q₂ ↔\n    x ∈ Icc (q₁ i) (q₂ i) ∧ p ∈ Icc (λ j, q₁ (i.succ_above j)) (λ j, q₂ (i.succ_above j)) :=\nby simp only [mem_Icc, insert_nth_le_iff, le_insert_nth_iff, and.assoc, and.left_comm]\n\nlemma preimage_insert_nth_Icc_of_mem {i : fin (n + 1)} {x : α i} {q₁ q₂ : Π j, α j}\n  (hx : x ∈ Icc (q₁ i) (q₂ i)) :\n  i.insert_nth x ⁻¹' (Icc q₁ q₂) = Icc (λ j, q₁ (i.succ_above j)) (λ j, q₂ (i.succ_above j)) :=\nset.ext $ λ p, by simp only [mem_preimage, insert_nth_mem_Icc, hx, true_and]\n\nlemma preimage_insert_nth_Icc_of_not_mem {i : fin (n + 1)} {x : α i} {q₁ q₂ : Π j, α j}\n  (hx : x ∉ Icc (q₁ i) (q₂ i)) :\n  i.insert_nth x ⁻¹' (Icc q₁ q₂) = ∅ :=\nset.ext $ λ p, by simp only [mem_preimage, insert_nth_mem_Icc, hx, false_and, mem_empty_eq]\n\nend insert_nth\n\nsection find\n\n/-- `find p` returns the first index `n` where `p n` is satisfied, and `none` if it is never\nsatisfied. -/\ndef find : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p], option (fin n)\n| 0     p _ := none\n| (n+1) p _ := by resetI; exact option.cases_on\n  (@find n (λ i, p (i.cast_lt (nat.lt_succ_of_lt i.2))) _)\n  (if h : p (fin.last n) then some (fin.last n) else none)\n  (λ i, some (i.cast_lt (nat.lt_succ_of_lt i.2)))\n\n/-- If `find p = some i`, then `p i` holds -/\nlemma find_spec : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p] {i : fin n}\n  (hi : i ∈ by exactI fin.find p), p i\n| 0     p I i hi := option.no_confusion hi\n| (n+1) p I i hi := begin\n  dsimp [find] at hi,\n  resetI,\n  cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,\n  { rw h at hi,\n    dsimp at hi,\n    split_ifs at hi with hl hl,\n    { exact option.some_inj.1 hi ▸ hl },\n    { exact option.no_confusion hi } },\n  { rw h at hi,\n    rw [← option.some_inj.1 hi],\n    exact find_spec _ h }\nend\n\n/-- `find p` does not return `none` if and only if `p i` holds at some index `i`. -/\nlemma is_some_find_iff : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p],\n  by exactI (find p).is_some ↔ ∃ i, p i\n| 0     p _ := iff_of_false (λ h, bool.no_confusion h) (λ ⟨i, _⟩, fin_zero_elim i)\n| (n+1) p _ := ⟨λ h, begin\n  rw [option.is_some_iff_exists] at h,\n  cases h with i hi,\n  exactI ⟨i, find_spec _ hi⟩\nend, λ ⟨⟨i, hin⟩, hi⟩,\nbegin\n  resetI,\n  dsimp [find],\n  cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,\n  { split_ifs with hl hl,\n    { exact option.is_some_some },\n    { have := (@is_some_find_iff n (λ x, p (x.cast_lt (nat.lt_succ_of_lt x.2))) _).2\n        ⟨⟨i, lt_of_le_of_ne (nat.le_of_lt_succ hin)\n        (λ h, by clear_aux_decl; cases h; exact hl hi)⟩, hi⟩,\n      rw h at this,\n      exact this } },\n  { simp }\nend⟩\n\n/-- `find p` returns `none` if and only if `p i` never holds. -/\nlemma find_eq_none_iff {n : ℕ} {p : fin n → Prop} [decidable_pred p] :\n  find p = none ↔ ∀ i, ¬ p i :=\nby rw [← not_exists, ← is_some_find_iff]; cases (find p); simp\n\n/-- If `find p` returns `some i`, then `p j` does not hold for `j < i`, i.e., `i` is minimal among\nthe indices where `p` holds. -/\nlemma find_min : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p] {i : fin n}\n  (hi : i ∈ by exactI fin.find p) {j : fin n} (hj : j < i), ¬ p j\n| 0     p _ i hi j hj hpj := option.no_confusion hi\n| (n+1) p _ i hi ⟨j, hjn⟩ hj hpj := begin\n  resetI,\n  dsimp [find] at hi,\n  cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with k,\n  { rw [h] at hi,\n    split_ifs at hi with hl hl,\n    { have := option.some_inj.1 hi,\n      subst this,\n      rw [find_eq_none_iff] at h,\n      exact h ⟨j, hj⟩ hpj },\n    { exact option.no_confusion hi } },\n  { rw h at hi,\n    dsimp at hi,\n    have := option.some_inj.1 hi,\n    subst this,\n    exact find_min h (show (⟨j, lt_trans hj k.2⟩ : fin n) < k, from hj) hpj }\nend\n\nlemma find_min' {p : fin n → Prop} [decidable_pred p] {i : fin n}\n  (h : i ∈ fin.find p) {j : fin n} (hj : p j) : i ≤ j :=\nle_of_not_gt (λ hij, find_min h hij hj)\n\nlemma nat_find_mem_find {p : fin n → Prop} [decidable_pred p]\n  (h : ∃ i, ∃ hin : i < n, p ⟨i, hin⟩) :\n  (⟨nat.find h, (nat.find_spec h).fst⟩ : fin n) ∈ find p :=\nlet ⟨i, hin, hi⟩ := h in\nbegin\n  cases hf : find p with f,\n  { rw [find_eq_none_iff] at hf,\n    exact (hf ⟨i, hin⟩ hi).elim },\n  { refine option.some_inj.2 (le_antisymm _ _),\n    { exact find_min' hf (nat.find_spec h).snd },\n    { exact nat.find_min' _ ⟨f.2, by convert find_spec p hf;\n        exact fin.eta _ _⟩ } }\nend\n\nlemma mem_find_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} :\n  i ∈ fin.find p ↔ p i ∧ ∀ j, p j → i ≤ j :=\n⟨λ hi, ⟨find_spec _ hi, λ _, find_min' hi⟩,\n  begin\n    rintros ⟨hpi, hj⟩,\n    cases hfp : fin.find p,\n    { rw [find_eq_none_iff] at hfp,\n      exact (hfp _ hpi).elim },\n    { exact option.some_inj.2 (le_antisymm (find_min' hfp hpi) (hj _ (find_spec _ hfp))) }\n  end⟩\n\nlemma find_eq_some_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} :\n  fin.find p = some i ↔ p i ∧ ∀ j, p j → i ≤ j :=\n mem_find_iff\n\nlemma mem_find_of_unique {p : fin n → Prop} [decidable_pred p]\n  (h : ∀ i j, p i → p j → i = j) {i : fin n} (hi : p i) : i ∈ fin.find p :=\nmem_find_iff.2 ⟨hi, λ j hj, le_of_eq $ h i j hi hj⟩\n\nend find\n\n@[simp]\nlemma coe_of_nat_eq_mod (m n : ℕ) :\n  ((n : fin (succ m)) : ℕ) = n % succ m :=\nby rw [← of_nat_eq_coe]; refl\n\n@[simp] lemma coe_of_nat_eq_mod' (m n : ℕ) [I : fact (0 < m)] :\n  (@fin.of_nat' _ I n : ℕ) = n % m :=\nrfl\n\nsection mul\n\n/-!\n### mul\n-/\n\nlemma val_mul {n : ℕ} :  ∀ a b : fin n, (a * b).val = (a.val * b.val) % n\n| ⟨_, _⟩ ⟨_, _⟩ := rfl\n\nlemma coe_mul {n : ℕ} :  ∀ a b : fin n, ((a * b : fin n) : ℕ) = (a * b) % n\n| ⟨_, _⟩ ⟨_, _⟩ := 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": "JLimperg", "repo": "aesop3", "sha": "a4a116f650cc7403428e72bd2e2c4cda300fe03f", "save_path": "github-repos/lean/JLimperg-aesop3", "path": "github-repos/lean/JLimperg-aesop3/aesop3-a4a116f650cc7403428e72bd2e2c4cda300fe03f/src/data/fin.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7513149379657142}}
{"text": "-- založeno na Lean Tutorial / 05_sequence_limits.lean\nimport resources\n\n/- \nUžitečná lemmata:\n\n`le_max_left  p q` říká `p ≤ max p q`\n`le_max_right p q` říká `q ≤ max p q`\n\n`eq_of_abs_sub_le_all_pos x y` říká `(∀ ε > 0, |x - y| ≤ ε) → x = y`\n-/\n\n-- S touto definicí limity posloupnosti budeme pracovat ve všech následujících cvičeních.\ndef seq_limit (s : ℕ → ℝ) (a : ℝ) : Prop :=\n∀ ε : ℝ, ε > 0 → ∃ n₀ : ℕ, ∀ n : ℕ, n ≥ n₀ → |s n - a| ≤ ε\n\n\n-- Součet limit:\n-- Pokud [`u` konverguje k `a`] a [`v` konverguje k `b`],\n-- pak [`u + v` konverguje k `a + b`].\nexample (u v : ℕ → ℝ) (a b : ℝ) (hu : seq_limit u a) (hv : seq_limit v b) :\n  seq_limit (u + v) (a + b) :=\nbegin\n  sorry,\nend\n\n-- Věta o dvou policajtech:\n-- Pokud [posloupnost `u` konverguje k `z`] a stejně tak [posloupnost `v` konverguje k `z`],\n-- pak [posloupnost `w` taková že `u ≤ w ≤ v` konverguje k `z` taktéž].\nexample (u v w : ℕ → ℝ) (z : ℝ) (hu : seq_limit u z) (hv : seq_limit v z)\n        (below : ∀ n, u n ≤ w n) (above : ∀ n, w n ≤ v n) :\n  seq_limit w z :=\nbegin\n  sorry,\nend\n\n-- Každá posloupnost má nejvýše jednu limitu.\nexample (w : ℕ → ℝ) (a b : ℝ) (ha : seq_limit w a) (hb : seq_limit w b) :\n  a = b :=\nbegin\n  sorry,\nend\n", "meta": {"author": "madvorak", "repo": "lean-showcase", "sha": "d405796deef7a7903befa438d5d7ac2873960a98", "save_path": "github-repos/lean/madvorak-lean-showcase", "path": "github-repos/lean/madvorak-lean-showcase/lean-showcase-d405796deef7a7903befa438d5d7ac2873960a98/src/sequence_limits_cz.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436395, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7513149369267946}}
{"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ölzl, Scott Morrison, Jens Wagemaker\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.data.polynomial.coeff\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\n\n/-!\n# Theory of univariate polynomials\n\nThe main results are `induction_on` and `as_sum`.\n-/\n\nnamespace polynomial\n\n\ntheorem sum_C_mul_X_eq {R : Type u} [semiring R] (p : polynomial R) : (finsupp.sum p fun (n : ℕ) (a : R) => coe_fn C a * X ^ n) = p :=\n  Eq.trans (finset.sum_congr rfl fun (n : ℕ) (hn : n ∈ finsupp.support p) => Eq.symm single_eq_C_mul_X)\n    (finsupp.sum_single p)\n\ntheorem sum_monomial_eq {R : Type u} [semiring R] (p : polynomial R) : (finsupp.sum p fun (n : ℕ) (a : R) => coe_fn (monomial n) a) = p := sorry\n\nprotected theorem induction_on {R : Type u} [semiring R] {M : polynomial R → Prop} (p : polynomial R) (h_C : ∀ (a : R), M (coe_fn C a)) (h_add : ∀ (p q : polynomial R), M p → M q → M (p + q)) (h_monomial : ∀ (n : ℕ) (a : R), M (coe_fn C a * X ^ n) → M (coe_fn C a * X ^ (n + 1))) : M p := sorry\n\n/--\nTo prove something about polynomials,\nit suffices to show the condition is closed under taking sums,\nand it holds for monomials.\n-/\nprotected theorem induction_on' {R : Type u} [semiring R] {M : polynomial R → Prop} (p : polynomial R) (h_add : ∀ (p q : polynomial R), M p → M q → M (p + q)) (h_monomial : ∀ (n : ℕ) (a : R), M (coe_fn (monomial n) a)) : M p :=\n  polynomial.induction_on p (h_monomial 0) h_add\n    fun (n : ℕ) (a : R) (h : M (coe_fn C a * X ^ n)) =>\n      eq.mpr (id (Eq._oldrec (Eq.refl (M (coe_fn C a * X ^ (n + 1)))) (Eq.symm single_eq_C_mul_X))) (h_monomial (n + 1) a)\n\ntheorem coeff_mul_monomial {R : Type u} [semiring R] (p : polynomial R) (n : ℕ) (d : ℕ) (r : R) : coeff (p * coe_fn (monomial n) r) (d + n) = coeff p d * r := sorry\n\ntheorem coeff_monomial_mul {R : Type u} [semiring R] (p : polynomial R) (n : ℕ) (d : ℕ) (r : R) : coeff (coe_fn (monomial n) r * p) (d + n) = r * coeff p d := sorry\n\n-- This can already be proved by `simp`.\n\ntheorem coeff_mul_monomial_zero {R : Type u} [semiring R] (p : polynomial R) (d : ℕ) (r : R) : coeff (p * coe_fn (monomial 0) r) d = coeff p d * r :=\n  coeff_mul_monomial p 0 d r\n\n-- This can already be proved by `simp`.\n\ntheorem coeff_monomial_zero_mul {R : Type u} [semiring R] (p : polynomial R) (d : ℕ) (r : R) : coeff (coe_fn (monomial 0) r * p) d = r * coeff p d :=\n  coeff_monomial_mul p 0 d r\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/induction.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7513149351307246}}
{"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, Mario Carneiro\n\nBinary representation of integers using inductive types.\n\nNote: Unlike in Coq, where this representation is preferred because of\nthe reliance on kernel reduction, in Lean this representation is discouraged\nin favor of the \"Peano\" natural numbers `nat`, and the purpose of this\ncollection of theorems is to show the equivalence of the different approaches.\n-/\n\nimport data.pnat data.bool data.vector data.bitvec\n\n/-- The type of positive binary numbers.\n\n     13 = 1101(base 2) = bit1 (bit0 (bit1 one)) -/\n@[derive has_reflect, derive decidable_eq]\ninductive pos_num : Type\n| one  : pos_num\n| bit1 : pos_num → pos_num\n| bit0 : pos_num → pos_num\ninstance : has_one pos_num := ⟨pos_num.one⟩\n\n/-- The type of nonnegative binary numbers, using `pos_num`.\n\n     13 = 1101(base 2) = pos (bit1 (bit0 (bit1 one))) -/\n@[derive has_reflect, derive decidable_eq]\ninductive num : Type\n| zero  : num\n| pos   : pos_num → num\ninstance : has_zero num := ⟨num.zero⟩\ninstance : has_one num := ⟨num.pos 1⟩\n\n/-- Representation of integers using trichotomy around zero.\n\n     13 = 1101(base 2) = pos (bit1 (bit0 (bit1 one)))\n     -13 = -1101(base 2) = neg (bit1 (bit0 (bit1 one))) -/\n@[derive has_reflect, derive decidable_eq]\ninductive znum : Type\n| zero : znum\n| pos  : pos_num → znum\n| neg  : pos_num → znum\ninstance : has_zero znum := ⟨znum.zero⟩\ninstance : has_one znum := ⟨znum.pos 1⟩\n\n/-- See `snum`. -/\n@[derive has_reflect, derive decidable_eq]\ninductive nzsnum : Type\n| msb : bool → nzsnum\n| bit : bool → nzsnum → nzsnum\n/-- Alternative representation of integers using a sign bit at the end.\n  The convention on sign here is to have the argument to `msb` denote\n  the sign of the MSB itself, with all higher bits set to the negation\n  of this sign. The result is interpreted in two's complement.\n\n     13  = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb tt))))\n     -13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb ff))))\n\n  As with `num`, a special case must be added for zero, which has no msb,\n  but by two's complement symmetry there is a second special case for -1.\n  Here the `bool` field indicates the sign of the number.\n\n     0  = ..0000000(base 2) = zero ff\n     -1 = ..1111111(base 2) = zero tt -/\n@[derive has_reflect, derive decidable_eq]\ninductive snum : Type\n| zero : bool → snum\n| nz : nzsnum → snum\ninstance : has_coe nzsnum snum := ⟨snum.nz⟩\ninstance : has_zero snum := ⟨snum.zero ff⟩\ninstance : has_one nzsnum := ⟨nzsnum.msb tt⟩\ninstance : has_one snum := ⟨snum.nz 1⟩\n\nnamespace pos_num\n\n  def bit (b : bool) : pos_num → pos_num := cond b bit1 bit0\n\n  def succ : pos_num → pos_num\n  | 1        := bit0 one\n  | (bit1 n) := bit0 (succ n)\n  | (bit0 n) := bit1 n\n\n  def is_one : pos_num → bool\n  | 1 := tt\n  | _ := ff\n\n  protected def add : pos_num → pos_num → pos_num\n  | 1        b        := succ b\n  | a        1        := succ a\n  | (bit0 a) (bit0 b) := bit0 (add a b)\n  | (bit1 a) (bit1 b) := bit0 (succ (add a b))\n  | (bit0 a) (bit1 b) := bit1 (add a b)\n  | (bit1 a) (bit0 b) := bit1 (add a b)\n\n  instance : has_add pos_num := ⟨pos_num.add⟩\n\n  def pred' : pos_num → num\n  | 1        := 0\n  | (bit0 n) := num.pos (num.cases_on (pred' n) 1 bit1)\n  | (bit1 n) := num.pos (bit0 n)\n\n  def pred (a : pos_num) : pos_num :=\n  num.cases_on (pred' a) 1 id\n\n  def size : pos_num → pos_num\n  | 1        := 1\n  | (bit0 n) := succ (size n)\n  | (bit1 n) := succ (size n)\n\n  def nat_size : pos_num → nat\n  | 1        := 1\n  | (bit0 n) := nat.succ (nat_size n)\n  | (bit1 n) := nat.succ (nat_size n)\n\n  protected def mul (a : pos_num) : pos_num → pos_num\n  | 1        := a\n  | (bit0 b) := bit0 (mul b)\n  | (bit1 b) := bit0 (mul b) + a\n\n  instance : has_mul pos_num := ⟨pos_num.mul⟩\n\n  def of_nat_succ : ℕ → pos_num\n  | 0            := 1\n  | (nat.succ n) := succ (of_nat_succ n)\n\n  def of_nat (n : ℕ) : pos_num := of_nat_succ (nat.pred n)\n\n  open ordering\n  def cmp : pos_num → pos_num → ordering\n  | 1        1        := eq\n  | _        1        := gt\n  | 1        _        := lt\n  | (bit0 a) (bit0 b) := cmp a b\n  | (bit0 a) (bit1 b) := ordering.cases_on (cmp a b) lt lt gt\n  | (bit1 a) (bit0 b) := ordering.cases_on (cmp a b) lt gt gt\n  | (bit1 a) (bit1 b) := cmp a b\n\n  instance : has_lt pos_num := ⟨λa b, cmp a b = ordering.lt⟩\n  instance : has_le pos_num := ⟨λa b, ¬ b < a⟩\n\n  instance decidable_lt : @decidable_rel pos_num (<)\n  | a b := by dsimp [(<)]; apply_instance\n\n  instance decidable_le : @decidable_rel pos_num (≤)\n  | a b := by dsimp [(≤)]; apply_instance\n\nend pos_num\n\nsection\n  variables {α : Type*} [has_zero α] [has_one α] [has_add α]\n\n  def cast_pos_num : pos_num → α\n  | 1                := 1\n  | (pos_num.bit0 a) := bit0 (cast_pos_num a)\n  | (pos_num.bit1 a) := bit1 (cast_pos_num a)\n\n  def cast_num : num → α\n  | 0           := 0\n  | (num.pos p) := cast_pos_num p\n\n  @[priority 0] instance pos_num_coe : has_coe pos_num α := ⟨cast_pos_num⟩\n\n  @[priority 0] instance num_nat_coe : has_coe num α := ⟨cast_num⟩\n\n  instance : has_repr pos_num := ⟨λ n, repr (n : ℕ)⟩\n  instance : has_repr num := ⟨λ n, repr (n : ℕ)⟩\nend\n\nnamespace num\n  open pos_num\n\n  def succ' : num → pos_num\n  | 0       := 1\n  | (pos p) := succ p\n\n  def succ (n : num) : num := pos (succ' n)\n\n  protected def add : num → num → num\n  | 0       a       := a\n  | b       0       := b\n  | (pos a) (pos b) := pos (a + b)\n\n  instance : has_add num := ⟨num.add⟩\n\n  protected def bit0 : num → num\n  | 0       := 0\n  | (pos n) := pos (pos_num.bit0 n)\n\n  protected def bit1 : num → num\n  | 0       := 1\n  | (pos n) := pos (pos_num.bit1 n)\n\n  def bit (b : bool) : num → num := cond b num.bit1 num.bit0\n\n  def size : num → num\n  | 0       := 0\n  | (pos n) := pos (pos_num.size n)\n\n  def nat_size : num → nat\n  | 0       := 0\n  | (pos n) := pos_num.nat_size n\n\n  protected def mul : num → num → num\n  | 0       _       := 0\n  | _       0       := 0\n  | (pos a) (pos b) := pos (a * b)\n\n  instance : has_mul num := ⟨num.mul⟩\n\n  open ordering\n  def cmp : num → num → ordering\n  | 0       0       := eq\n  | _       0       := gt\n  | 0       _       := lt\n  | (pos a) (pos b) := pos_num.cmp a b\n\n  instance : has_lt num := ⟨λa b, cmp a b = ordering.lt⟩\n  instance : has_le num := ⟨λa b, ¬ b < a⟩\n\n  instance decidable_lt : @decidable_rel num (<)\n  | a b := by dsimp [(<)]; apply_instance\n\n  instance decidable_le : @decidable_rel num (≤)\n  | a b := by dsimp [(≤)]; apply_instance\n\n  def to_znum : num → znum\n  | 0       := 0\n  | (pos a) := znum.pos a\n\n  def to_znum_neg : num → znum\n  | 0       := 0\n  | (pos a) := znum.neg a\n\n  def of_nat' : ℕ → num :=\n  nat.binary_rec 0 (λ b n, cond b num.bit1 num.bit0)\n\nend num\n\nnamespace znum\n  open pos_num\n\n  def zneg : znum → znum\n  | 0       := 0\n  | (pos a) := neg a\n  | (neg a) := pos a\n\n  instance : has_neg znum := ⟨zneg⟩\n\n  def abs : znum → num\n  | 0       := 0\n  | (pos a) := num.pos a\n  | (neg a) := num.pos a\n\n  def succ : znum → znum\n  | 0       := 1\n  | (pos a) := pos (pos_num.succ a)\n  | (neg a) := (pos_num.pred' a).to_znum_neg\n\n  def pred : znum → znum\n  | 0       := neg 1\n  | (pos a) := (pos_num.pred' a).to_znum\n  | (neg a) := neg (pos_num.succ a)\n\n  protected def bit0 : znum → znum\n  | 0       := 0\n  | (pos n) := pos (pos_num.bit0 n)\n  | (neg n) := neg (pos_num.bit0 n)\n\n  protected def bit1 : znum → znum\n  | 0       := 1\n  | (pos n) := pos (pos_num.bit1 n)\n  | (neg n) := neg (num.cases_on (pred' n) 1 pos_num.bit1)\n\n  protected def bitm1 : znum → znum\n  | 0       := neg 1\n  | (pos n) := pos (num.cases_on (pred' n) 1 pos_num.bit1)\n  | (neg n) := neg (pos_num.bit1 n)\n\n  def of_int' : ℤ → znum\n  | (n : ℕ) := num.to_znum (num.of_nat' n)\n  | -[1+ n] := num.to_znum_neg (num.of_nat' (n+1))\n\nend znum\n\nnamespace pos_num\n  open znum\n\n  def sub' : pos_num → pos_num → znum\n  | a        1        := (pred' a).to_znum\n  | 1        b        := (pred' b).to_znum_neg\n  | (bit0 a) (bit0 b) := (sub' a b).bit0\n  | (bit0 a) (bit1 b) := (sub' a b).bitm1\n  | (bit1 a) (bit0 b) := (sub' a b).bit1\n  | (bit1 a) (bit1 b) := (sub' a b).bit0\n\n  def of_znum' : znum → option pos_num\n  | (znum.pos p) := some p\n  | _            := none\n\n  def of_znum : znum → pos_num\n  | (znum.pos p) := p\n  | _            := 1\n\n  protected def sub (a b : pos_num) : pos_num :=\n  match sub' a b with\n  | (znum.pos p) := p\n  | _ := 1\n  end\n\n  instance : has_sub pos_num := ⟨pos_num.sub⟩\nend pos_num\n\nnamespace num\n  def ppred : num → option num\n  | 0       := none\n  | (pos p) := some p.pred'\n\n  def pred : num → num\n  | 0       := 0\n  | (pos p) := p.pred'\n\n  def div2 : num → num\n  | 0 := 0\n  | 1 := 0\n  | (pos (pos_num.bit0 p)) := pos p\n  | (pos (pos_num.bit1 p)) := pos p\n\n  def of_znum' : znum → option num\n  | 0            := some 0\n  | (znum.pos p) := some (pos p)\n  | (znum.neg p) := none\n\n  def of_znum : znum → num\n  | (znum.pos p) := pos p\n  | _            := 0\n\n  def sub' : num → num → znum\n  | 0       0       := 0\n  | (pos a) 0       := znum.pos a\n  | 0       (pos b) := znum.neg b\n  | (pos a) (pos b) := a.sub' b\n\n  def psub (a b : num) : option num :=\n  of_znum' (sub' a b)\n\n  protected def sub (a b : num) : num :=\n  of_znum (sub' a b)\n\n  instance : has_sub num := ⟨num.sub⟩\nend num\n\nnamespace znum\n  open pos_num\n\n  protected def add : znum → znum → znum\n  | 0       a       := a\n  | b       0       := b\n  | (pos a) (pos b) := pos (a + b)\n  | (pos a) (neg b) := sub' a b\n  | (neg a) (pos b) := sub' b a\n  | (neg a) (neg b) := neg (a + b)\n\n  instance : has_add znum := ⟨znum.add⟩\n\n  protected def mul : znum → znum → znum\n  | 0       a       := 0\n  | b       0       := 0\n  | (pos a) (pos b) := pos (a * b)\n  | (pos a) (neg b) := neg (a * b)\n  | (neg a) (pos b) := neg (a * b)\n  | (neg a) (neg b) := pos (a * b)\n\n  instance : has_mul znum := ⟨znum.mul⟩\n\n  open ordering\n  def cmp : znum → znum → ordering\n  | 0       0       := eq\n  | (pos a) (pos b) := pos_num.cmp a b\n  | (neg a) (neg b) := pos_num.cmp b a\n  | (pos _) _       := gt\n  | (neg _) _       := lt\n  | _       (pos _) := lt\n  | _       (neg _) := gt\n\n  instance : has_lt znum := ⟨λa b, cmp a b = ordering.lt⟩\n  instance : has_le znum := ⟨λa b, ¬ b < a⟩\n\n  instance decidable_lt : @decidable_rel znum (<)\n  | a b := by dsimp [(<)]; apply_instance\n\n  instance decidable_le : @decidable_rel znum (≤)\n  | a b := by dsimp [(≤)]; apply_instance\n\nend znum\n\nnamespace pos_num\n  \n  def divmod_aux (d : pos_num) (q r : num) : num × num :=\n  match num.of_znum' (num.sub' r (num.pos d)) with\n  | some r' := (num.bit1 q, r')\n  | none    := (num.bit0 q, r)\n  end\n  \n  def divmod (d : pos_num) : pos_num → num × num\n  | (bit0 n) := let (q, r₁) := divmod n in\n    divmod_aux d q (num.bit0 r₁)\n  | (bit1 n) := let (q, r₁) := divmod n in\n    divmod_aux d q (num.bit1 r₁)\n  | 1        := divmod_aux d 0 1\n\n  def div' (n d : pos_num) : num := (divmod d n).1\n\n  def mod' (n d : pos_num) : num := (divmod d n).2\n\n  def sqrt_aux1 (b : pos_num) (r n : num) : num × num :=\n  match num.of_znum' (n.sub' (r + num.pos b)) with\n  | some n' := (r.div2 + num.pos b, n')\n  | none := (r.div2, n)\n  end\n    \n  def sqrt_aux : pos_num → num → num → num\n  | b@(bit0 b') r n := let (r', n') := sqrt_aux1 b r n in sqrt_aux b' r' n'\n  | b@(bit1 b') r n := let (r', n') := sqrt_aux1 b r n in sqrt_aux b' r' n'\n  | 1           r n := (sqrt_aux1 1 r n).1\n/-\n\ndef sqrt_aux : ℕ → ℕ → ℕ → ℕ\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 : ℕ) : ℤ) with\n  | (n' : ℕ) := 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:ℕ` such that `k*k ≤ n`. -/\ndef sqrt (n : ℕ) : ℕ :=\nmatch size n with\n| 0      := 0\n| succ s := sqrt_aux (shiftl 1 (bit0 (div2 s))) 0 n\nend\n-/\n\nend pos_num\n\nnamespace num\n\n  def div : num → num → num\n  | 0       _       := 0\n  | _       0       := 0\n  | (pos n) (pos d) := pos_num.div' n d\n\n  def mod : num → num → num\n  | 0       _       := 0\n  | n       0       := n\n  | (pos n) (pos d) := pos_num.mod' n d\n\n  instance : has_div num := ⟨num.div⟩\n  instance : has_mod num := ⟨num.mod⟩\n\n  def gcd_aux : nat → num → num → num\n  | 0            a b := b\n  | (nat.succ n) 0 b := b\n  | (nat.succ n) a b := gcd_aux n (b % a) a\n\n  def gcd (a b : num) : num :=\n  if a ≤ b then\n    gcd_aux (a.nat_size + b.nat_size) a b\n  else\n    gcd_aux (b.nat_size + a.nat_size) b a\n\nend num\n\nnamespace znum\n\n  def div : znum → znum → znum\n  | 0       _       := 0\n  | _       0       := 0\n  | (pos n) (pos d) := num.to_znum (pos_num.div' n d)\n  | (pos n) (neg d) := num.to_znum_neg (pos_num.div' n d)\n  | (neg n) (pos d) := neg (pos_num.pred' n / num.pos d).succ'\n  | (neg n) (neg d) := pos (pos_num.pred' n / num.pos d).succ'\n\n  def mod : znum → znum → znum\n  | 0       d := 0\n  | (pos n) d := num.to_znum (num.pos n % d.abs)\n  | (neg n) d := d.abs.sub' (pos_num.pred' n % d.abs).succ\n\n  instance : has_div znum := ⟨znum.div⟩\n  instance : has_mod znum := ⟨znum.mod⟩\n\n  def gcd (a b : znum) : num := a.abs.gcd b.abs\n\nend znum\n\nsection\n  variables {α : Type*} [has_zero α] [has_one α] [has_add α] [has_neg α]\n\n  def cast_znum : znum → α\n  | 0            := 0\n  | (znum.pos p) := p\n  | (znum.neg p) := -p\n\n  @[priority 0] instance znum_coe : has_coe znum α := ⟨cast_znum⟩\n\n  instance : has_repr znum := ⟨λ n, repr (n : ℤ)⟩\nend\n\n/- The snum representation uses a bit string, essentially a list of 0 (ff) and 1 (tt) bits,\n   and the negation of the MSB is sign-extended to all higher bits. -/\nnamespace nzsnum\n  notation a :: b := bit a b\n\n  def sign : nzsnum → bool\n  | (msb b) := bnot b\n  | (b :: p) := sign p\n\n  @[pattern] def not : nzsnum → nzsnum\n  | (msb b) := msb (bnot b)\n  | (b :: p) := bnot b :: not p\n  prefix ~ := not\n\n  def bit0 : nzsnum → nzsnum := bit ff\n  def bit1 : nzsnum → nzsnum := bit tt\n\n  def head : nzsnum → bool\n  | (msb b)  := b\n  | (b :: p) := b\n\n  def tail : nzsnum → snum\n  | (msb b)  := snum.zero (bnot b)\n  | (b :: p) := p\n\nend nzsnum\n\nnamespace snum\n  open nzsnum\n\n  def sign : snum → bool\n  | (zero z) := z\n  | (nz p)   := p.sign\n\n  @[pattern] def not : snum → snum\n  | (zero z) := zero (bnot z)\n  | (nz p)   := ~p\n  prefix ~ := not\n\n  @[pattern] def bit : bool → snum → snum\n  | b (zero z) := if b = z then zero b else msb b\n  | b (nz p)   := p.bit b\n\n  notation a :: b := bit a b\n\n  def bit0 : snum → snum := bit ff\n  def bit1 : snum → snum := bit tt\n\n  theorem bit_zero (b) : b :: zero b = zero b := by cases b; refl\n\n  theorem bit_one (b) : b :: zero (bnot b) = msb b := by cases b; refl\n\nend snum\n\nnamespace nzsnum\n  open snum\n\n  def drec' {C : snum → Sort*} (z : Π b, C (snum.zero b))\n    (s : Π b p, C p → C (b :: p)) : Π p : nzsnum, C p\n  | (msb b)  := by rw ←bit_one; exact s b (snum.zero (bnot b)) (z (bnot b))\n  | (bit b p) := s b p (drec' p)\nend nzsnum\n\nnamespace snum\n  open nzsnum\n\n  def head : snum → bool\n  | (zero z) := z\n  | (nz p)   := p.head\n\n  def tail : snum → snum\n  | (zero z) := zero z\n  | (nz p)   := p.tail\n\n  def drec' {C : snum → Sort*} (z : Π b, C (snum.zero b))\n    (s : Π b p, C p → C (b :: p)) : Π p, C p\n  | (zero b) := z b\n  | (nz p)   := p.drec' z s\n\n  def rec' {α} (z : bool → α) (s : bool → snum → α → α) : snum → α :=\n  drec' z s\n\n  def bits : snum → Π n, vector bool n\n  | p 0     := vector.nil\n  | p (n+1) := head p :: bits (tail p) n\n\n  def test_bit : nat → snum → bool\n  | 0     p := head p\n  | (n+1) p := test_bit n (tail p)\n\n  def succ : snum → snum :=\n  rec' (λ b, cond b 0 1) (λb p succp, cond b (ff :: succp) (tt :: p))\n\n  def pred : snum → snum :=\n  rec' (λ b, cond b (~1) ~0) (λb p predp, cond b (ff :: p) (tt :: predp))\n\n  protected def neg (n : snum) : snum := succ ~n\n\n  instance : has_neg snum := ⟨snum.neg⟩\n\n  -- First bit is 0 or 1 (tt), second bit is 0 or -1 (tt)\n  def czadd : bool → bool → snum → snum\n  | ff ff p := p\n  | ff tt p := pred p\n  | tt ff p := succ p\n  | tt tt p := p\n\n  def cadd : snum → snum → bool → snum :=\n  rec' (λ a p c, czadd c a p) $ λa p IH,\n  rec' (λb c, czadd c b (a :: p)) $ λb q _ c,\n  bitvec.xor3 a b c :: IH q (bitvec.carry a b c)\n\n  protected def add (a b : snum) : snum := cadd a b ff\n\n  instance : has_add snum := ⟨snum.add⟩\n\n  protected def sub (a b : snum) : snum := a + -b\n\n  instance : has_sub snum := ⟨snum.sub⟩\n\n  protected def mul (a : snum) : snum → snum :=\n  rec' (λ b, cond b (-a) 0) $ λb q IH,\n  cond b (bit0 IH + a) (bit0 IH)\n\n  instance : has_mul snum := ⟨snum.mul⟩\n\nend snum\n\nnamespace int\n  def of_snum : snum → ℤ :=\n  snum.rec' (λ a, cond a (-1) 0) (λa p IH, cond a (bit1 IH) (bit0 IH))\n\n  instance snum_coe : has_coe snum ℤ := ⟨of_snum⟩\nend int\n\ninstance : has_lt snum := ⟨λa b, (a : ℤ) < b⟩\ninstance : has_le snum := ⟨λa b, (a : ℤ) ≤ b⟩\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/num/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942203004186, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7513149288488045}}
{"text": "def even (n : Nat) : Prop :=\n  ∃ k : Nat, n = 2 * k\n\ndef prime (n : Nat) : Prop :=\n  ∀ m1 m2 : Nat, (m1 * m2 = n) → (m1 = n ∨ m2 = n) \n\ndef infinitely_many_primes : Prop :=\n  ∀ n m : Nat, (m > n ∧ prime m)\n\ndef Fermat_prime (n : Nat) : Prop :=\n  prime n ∧ ∃ k : Nat, n = (2 ^ (2 ^ k) + 1) \n\ndef infinitely_many_Fermat_primes : Prop :=\n  ∀ n m : Nat, (m > n ∧ Fermat_prime m) \n\ndef goldbach_conjecture : Prop :=\n  ∀ n : Nat, (n > 2) → (∃ s1 s2 : Nat, (prime s1 ∧ prime s2) ∧ (s1 + s2 = n))\n\ndef Goldbach's_weak_conjecture : Prop :=\n  ∀ n : Nat, ((n > 5) ∧ ¬ (even n)) → (∃ s1 s2 s3 : Nat, (prime s1 ∧ prime s2 ∧ prime s3) ∧ (s1 + s2 + s3 = n))  \n\ndef Fermat's_last_theorem : Prop :=\n  ∀ n : Nat, (n > 2) → (∀ a b c : Nat, a^n + b^n ≠ c^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/Definitions.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342037088041, "lm_q2_score": 0.7853085859124002, "lm_q1q2_score": 0.751253053749996}}
{"text": "universes u\n\n#check true ∧ false ∨ (3 > 1 → 1 < 3)\n#check 4 = 2+2\n#check ∀ n : ℕ, n ≠ 0 → ∃ m, n = m+1\n\n/-\n  Curry-Howard: Propositions as types\n\n  (A proposition is true if there is a value of the type.)\n-/\n\n-- Functions are proofs of implication\nlemma p1 {a b : Prop} : a → b → a :=\nλ ha hb, ha\n\n-- Functions are proofs of forall\nlemma p2 : ∀ n : ℕ, n = n :=\nλ n, rfl\n\n-- Conjunction is a product (defined as a structure!)\nlemma p3 {a b : Prop} (ha : a) (hb : b) : a ∧ b :=\n{ left := ha, right := hb }\n\n-- A proof of exists is a pair of witness and proof\nlemma p4 (n : ℕ) : ∃ m, n+1 ≤ m :=\n⟨n+1, le_refl _⟩\n\n-- Disjunction is a sum type\nlemma p5 {a b : Prop} (ha : a) : a ∨ b :=\nor.inl ha\n\n/-\n  Proofs are \"just\" expressions; pattern-matching, recursive definitions,\n  etc. just work.\n-/\n\nlemma p6 {a b : Prop} : a ∨ b → b ∨ a\n| (or.inl ha) := or.inr ha\n| (or.inr hb) := or.inl hb\n\nlemma p7 {α : Type u} (p q : α → Prop) : (∃ x, p x) → (∃ x, q x) → (∃ x y, p x ∧ q y)\n| ⟨x, hpx⟩ ⟨y, hpy⟩ := ⟨x, y, hpx, hpy⟩\n\nlemma p8 : ∀ n : ℕ, 0 ≤ n\n| 0 := le_refl _\n| (n+1) :=\n  let  h1 : n ≥ 0 := p8 n in\n  have h2 : n+1 ≥ n, from nat.le_succ n,\n  show 0 ≤ n+1, from le_trans h1 h2\n\n/-\n  Subtypes restrict types to a subset of values.\n-/\ndef positive_nat := { n : ℕ // n > 0 }\n\nexample : positive_nat := ⟨10, dec_trivial⟩\n\n/-\n  There are two different kinds of \"truth values\":\n   - Prop: types, erased at runtime\n   - bool: inductive type with values tt/ff, computable\n-/\n\n#check true ∧ false ∨ 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 (∀ x ∈ [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 ∀ x ∈ [1,2,3,4], x^2 < x + 10 then \"ok\" else \"ko\"\n#check guard $ ∀ x ∈ [1,2,3,4], x^2 < x + 10\n#check list.filter (λ x, x^2 < x + 10)\n\n/-\n  Since Prop is erased at runtime, we can use classical logic in Prop without any problems.\n-/\nexample {p : Prop} : p ∨ ¬ p :=\nclassical.em p\n\n-- Classical logic 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] classical.prop_decidable\n\n-- However we cannot execute definitions that use classical.prop_decidable to\n-- construct data, such definitions are then marked as \"noncomputable\".\nnoncomputable def find_zero (f : ℕ → ℕ) : ℕ :=\nif h : ∃ i, f i = 0 then classical.some h else 0", "meta": {"author": "gebner", "repo": "avm2017_tutorial", "sha": "3954983cdc8aef0e58e1a5809c0b3e217057ac4c", "save_path": "github-repos/lean/gebner-avm2017_tutorial", "path": "github-repos/lean/gebner-avm2017_tutorial/avm2017_tutorial-3954983cdc8aef0e58e1a5809c0b3e217057ac4c/02_logic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768651485395, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.751241966072711}}
{"text": "import ..lovelib\n\n\n/-! # LoVe Demo 13: Rational and Real Numbers\n\nWe review the construction of `ℚ` and `ℝ` as quotient types.\n\nOur procedure to construct types with specific properties:\n\n1. Create a new type that can represent all elements, but not necessarily in a\n   unique manner.\n\n2. Quotient this representation, equating elements that should be equal.\n\n3. Define operators on the quotient type by lifting functions from the base\n   type and prove that they are compatible with the quotient relation.\n\nWe used this approach in lecture 11 to construct `ℤ`. It can be used for `ℚ` and\n`ℝ` as well. -/\n\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n\nnamespace LoVe\n\n\n/-! ## Rational Numbers\n\n**Step 1:** A rational number is a number that can be expressed as a fraction\n`n / d` of integers `n` and `d ≠ 0`: -/\n\nstructure fraction :=\n(num           : ℤ)\n(denom         : ℤ)\n(denom_ne_zero : denom ≠ 0)\n\n/-! The number `n` is called the numerator, and the number `d` is called the\ndenominator.\n\nThe representation of a rational number as a fraction is not unique—e.g.,\n`1 / 2 = 2 / 4 = -1 / -2`.\n\n**Step 2:** Two fractions `n₁ / d₁` and `n₂ / d₂` represent the same rational\nnumber if the ratio between numerator and denominator are the same—i.e.,\n`n₁ * d₂ = n₂ * d₁`. This will be our equivalence relation `≈` on fractions. -/\n\nnamespace fraction\n\n@[instance] def setoid : setoid fraction :=\n{ r     := λa b : fraction, num a * denom b = num b * denom a,\n  iseqv :=\n    begin\n      repeat { apply and.intro },\n      { intros a; refl },\n      { intros a b h; cc },\n      { intros a b c eq_ab eq_bc,\n        apply int.eq_of_mul_eq_mul_right (denom_ne_zero b),\n        cc }\n    end }\n\nlemma setoid_iff (a b : fraction) :\n  a ≈ b ↔ num a * denom b = num b * denom a :=\nby refl\n\n/-! **Step 3:** Define `0 := 0 / 1`, `1 := 1 / 1`, addition, multiplication, etc.\n\n    `n₁ / d₁ + n₂ / d₂`     := `(n₁ * d₂ + n₂ * d₁) / (d₁ * d₂)`\n    `(n₁ / d₁) * (n₂ / d₂)` := `(n₁ * n₂) / (d₁ * d₂)`\n\nThen show that they are compatible with `≈`. -/\n\ndef of_int (i : ℤ) : fraction :=\n{ num           := i,\n  denom         := 1,\n  denom_ne_zero := by simp }\n\n@[instance] def has_zero : has_zero fraction :=\n{ zero := of_int 0 }\n\n@[instance] def has_one : has_one fraction :=\n{ one := of_int 1 }\n\n@[instance] def has_add : has_add fraction :=\n{ add := λa b : fraction,\n    { num           := num a * denom b + num b * denom a,\n      denom         := denom a * denom b,\n      denom_ne_zero :=\n        by apply mul_ne_zero; exact denom_ne_zero _ } }\n\n@[simp] lemma add_num (a b : fraction) :\n  num (a + b) = num a * denom b + num b * denom a :=\nby refl\n\n@[simp] lemma add_denom (a b : fraction) :\n  denom (a + b) = denom a * denom b :=\nby refl\n\nlemma add_equiv_add {a a' b b' : fraction} (ha : a ≈ a')\n    (hb : b ≈ b') :\n  a + b ≈ a' + b' :=\nbegin\n  simp [setoid_iff] at *, \n  calc  (num a * denom b + num b * denom a)\n          * (denom a' * denom b')\n      = num a * denom a' * denom b * denom b'\n          + num b * denom b' * denom a * denom a' :\n    by simp [add_mul, mul_add]; ac_refl\n  ... = num a' * denom a * denom b * denom b'\n          + num b' * denom b * denom a * denom a' :\n    by simp [*]\n  ... = (num a' * denom b' + num b' * denom a')\n          * (denom a * denom b) :\n    by simp [add_mul, mul_add]; ac_refl\nend\n\n@[instance] def has_neg : has_neg fraction :=\n{ neg := λa : fraction,\n    { num := - num a,\n      ..a } }\n\n@[simp] lemma neg_num (a : fraction) :\n  num (- a) = - num a :=\nby refl\n\n@[simp] lemma neg_denom (a : fraction) :\n  denom (- a) = denom a :=\nby refl\n\nlemma setoid_neg {a a' : fraction} (hab : a ≈ a') :\n  - a ≈ - a' :=\nby simp [setoid_iff] at hab ⊢; exact hab\n\n@[instance] def has_mul : has_mul fraction :=\n{ mul := λa b : fraction,\n    { num           := num a * num b,\n      denom         := denom a * denom b,\n      denom_ne_zero :=\n        mul_ne_zero (denom_ne_zero a) (denom_ne_zero b) } }\n\n@[simp] lemma mul_num (a b : fraction) :\n  num (a * b) = num a * num b :=\nby refl\n\n@[simp] lemma mul_denom (a b : fraction) :\n  denom (a * b) = denom a * denom b :=\nby refl\n\nlemma setoid_mul {a a' b b' : fraction} (ha : a ≈ a')\n    (hb : b ≈ b') :\n  a * b ≈ a' * b' :=\nby simp [setoid_iff] at ha hb ⊢; cc\n\n@[instance] def has_inv : has_inv fraction :=\n{ inv := λa : fraction,\n    if ha : num a = 0 then\n      0\n    else\n      { num           := denom a,\n        denom         := num a,\n        denom_ne_zero := ha } }\n\nlemma inv_def (a : fraction) (ha : num a ≠ 0) :\n  a⁻¹ =\n  { num           := denom a,\n    denom         := num a,\n    denom_ne_zero := ha } :=\ndif_neg ha\n\nlemma inv_zero (a : fraction) (ha : num a = 0) :\n  a⁻¹ = 0 :=\ndif_pos ha\n\n@[simp] lemma inv_num (a : fraction) (ha : num a ≠ 0) :\n  num (a⁻¹) = denom a :=\nby rw inv_def a ha\n\n@[simp] lemma inv_denom (a : fraction) (ha : num a ≠ 0) :\n  denom (a⁻¹) = num a :=\nby rw inv_def a ha\n\nlemma setoid_inv {a a' : fraction} (ha : a ≈ a') :\n  a⁻¹ ≈ a'⁻¹ :=\nbegin\n  cases' classical.em (num a = 0),\n  case inl : ha0 {\n    cases' classical.em (num a' = 0),\n    case inl : ha'0 {\n      simp [ha0, ha'0, inv_zero] },\n    case inr : ha'0 {\n      simp [ha0, ha'0, setoid_iff, denom_ne_zero] at ha,\n      cc } },\n  case inr : ha0 {\n    cases' classical.em (num a' = 0),\n    case inl : ha'0 {\n      simp [setoid_iff, ha'0, denom_ne_zero] at ha,\n      cc },\n    case inr : ha'0 {\n      simp [setoid_iff, ha0, ha'0] at ha ⊢,\n      cc } }\nend\n\nend fraction\n\ndef rat : Type :=\nquotient fraction.setoid\n\nnamespace rat\n\n@[instance] def has_zero : has_zero rat :=\n{ zero := ⟦0⟧ }\n\n@[instance] def has_one : has_one rat :=\n{ one := ⟦1⟧ }\n\n@[instance] def has_add : has_add rat :=\n{ add := quotient.lift₂ (λa b : fraction, ⟦a + b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact fraction.add_equiv_add ha hb\n    end }\n\n@[instance] def has_neg : has_neg rat :=\n{ neg := quotient.lift (λa : fraction, ⟦- a⟧)\n    begin\n      intros a a' ha,\n      apply quotient.sound,\n      exact fraction.setoid_neg ha\n    end }\n\n@[instance] def has_mul : has_mul rat :=\n{ mul := quotient.lift₂ (λa b : fraction, ⟦a * b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact fraction.setoid_mul ha hb\n    end }\n\n@[instance] def has_inv : has_inv rat :=\n{ inv := quotient.lift (λa : fraction, ⟦a⁻¹⟧)\n    begin\n      intros a a' ha,\n      apply quotient.sound,\n      exact fraction.setoid_inv ha\n    end }\n\nlemma add_commutes (a b : rat) : a + b = b + a :=\nbegin \n  apply quotient.induction_on₂ a b,\n  intros a' b',\n  apply quotient.sound,\n  simp [fraction.setoid_iff, fraction.add_denom, fraction.add_num],\n  ring\nend\n\nend rat\n\n\n/-! ### Alternative Definitions of `ℚ`\n\n**Alternative 1:** Define `ℚ` as a subtype of `fraction`, with the requirement\nthat the denominator is positive and that the numerator and the denominator have\nno common divisors except `1` and `-1`: -/\n\nnamespace alternative_1\n\ndef rat.is_canonical (a : fraction) : Prop :=\nfraction.denom a > 0\n∧ nat.coprime (int.nat_abs (fraction.num a))\n  (int.nat_abs (fraction.denom a))\n\ndef rat : Type :=\n{a : fraction // rat.is_canonical a}\n\nend alternative_1\n\n/-! This is more or less the `mathlib` definition.\n\nAdvantages:\n\n* no quotient required;\n* more efficient computation;\n* more properties are syntactic equalities up to computation.\n\nDisadvantage:\n\n* more complicated function definitions.\n\n**Alternative 2**: Define all elements syntactically, including the desired\noperations: -/\n\nnamespace alternative_2\n\ninductive pre_rat : Type\n| zero : pre_rat\n| one  : pre_rat\n| add  : pre_rat → pre_rat → pre_rat\n| sub  : pre_rat → pre_rat → pre_rat\n| mul  : pre_rat → pre_rat → pre_rat\n| div  : pre_rat → pre_rat → pre_rat\n\n/-! Then quotient `pre_rat` to enforce congruence rules and the field axioms: -/\n\ninductive rat.rel : pre_rat → pre_rat → Prop\n| add_congr {a b c d : pre_rat} :\n  rat.rel a b → rat.rel c d →\n  rat.rel (pre_rat.add a c) (pre_rat.add b d)\n| add_assoc {a b c : pre_rat} :\n  rat.rel (pre_rat.add a (pre_rat.add b c))\n    (pre_rat.add (pre_rat.add a b) c)\n| zero_add {a : pre_rat} :\n  rat.rel (pre_rat.add pre_rat.zero a) a\n-- etc.\n\ndef rat : Type :=\nquot rat.rel\n\nend alternative_2\n\n/-! Advantages:\n\n* no dependency on `ℤ`;\n* easy proofs of the field axioms;\n* general recipe reusable for other algebraic constructions (e.g., free monoids,\n  free groups).\n\nDisadvantage:\n\n* the definition of orders and lemmas about them are more complicated.\n\n\n### Real Numbers\n\nSome sequences of rational numbers seem to converge because the numbers in the\nsequence get closer and closer to each other, and yet do not converge to a\nrational number.\n\nExample:\n\n    `a₀ = 1`\n    `a₁ = 1.4`\n    `a₂ = 1.41`\n    `a₃ = 1.414`\n    `a₄ = 1.4142`\n    `a₅ = 1.41421`\n    `a₆ = 1.414213`\n    `a₇ = 1.4142135`\n       ⋮\n\nThis sequence seems to converge because each `a_n` is at most `10^-n` away from\nany of the following numbers. But the limit is `√2`, which is not a rational\nnumber.\n\nThe rational numbers are incomplete, and the reals are their  __completion__.\n\nTo construct the reals, we need to fill in the gaps that are revealed by these\nsequences that seem to converge, but do not.\n\nMathematically, a sequence `a₀, a₁, …` of rational numbers is __Cauchy__ if for\nany `ε > 0`, there exists an `N ∈ ℕ` such that for all `m ≥ N`, we have\n`|a_N - a_m| < ε`.\n\nIn other words, no matter how small we choose `ε`, we can always find a point in\nthe sequence from which all following numbers deviate less than by `ε`. -/\n\ndef is_cau_seq (f : ℕ → ℚ) : Prop :=\n∀ε > 0, ∃N, ∀m ≥ N, abs (f N - f m) < ε\n\n/-! Not every sequence is a Cauchy sequence: -/\n\nlemma id_not_cau_seq :\n  ¬ is_cau_seq (λn : ℕ, (n : ℚ)) :=\nbegin\n  rw is_cau_seq,\n  intro h,\n  cases' h 1 zero_lt_one with i hi,\n  have hi_succi :=\n    hi (i + 1) (by simp),\n  simp [←sub_sub] at hi_succi,\n  assumption\nend\n\n/-! We define a type of Cauchy sequences as a subtype: -/\n\ndef cau_seq : Type :=\n{f : ℕ → ℚ // is_cau_seq f}\n\ndef seq_of (f : cau_seq) : ℕ → ℚ :=\nsubtype.val f\n\n/-! Cauchy sequences represent real numbers:\n\n* `a_n = 1 / n` represents the real number `0`;\n* `1, 1.4, 1.41, …` represents the real number `√2`;\n* `a_n = 0` also represents the real number `0`.\n\nSince different Cauchy sequences can represent the same real number, we need to\ntake the quotient. Formally, two sequences represent the same real number when\ntheir difference converges to zero: -/\n\nnamespace cau_seq\n\n@[instance] def setoid : setoid cau_seq :=\n{ r     := λf g : cau_seq,\n    ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε,\n  iseqv :=\n    begin\n      apply and.intro,\n      { intros f ε hε,\n        apply exists.intro 0,\n        intros, simp, assumption },\n      apply and.intro,\n      { intros f g hfg ε hε,\n        cases' hfg ε hε with N hN,\n        apply exists.intro N,\n        intros m hm,\n        rw abs_sub,\n        apply hN m hm },\n      { intros f g h hfg hgh ε hε,\n        cases' hfg (ε / 2) (half_pos hε) with N₁ hN₁,\n        cases' hgh (ε / 2) (half_pos hε) with N₂ hN₂,\n        apply exists.intro (max N₁ N₂),\n        intros m hm,\n        calc  abs (seq_of f m - seq_of h m)\n            ≤ abs (seq_of f m - seq_of g m)\n              + abs (seq_of g m - seq_of h m) :\n          by apply abs_sub_le\n        ... < ε / 2 + ε / 2 :\n          add_lt_add (hN₁ m (le_of_max_le_left hm))\n            (hN₂ m (le_of_max_le_right hm))\n        ... = ε :\n          by simp }\n    end }\n\nlemma setoid_iff (f g : cau_seq) :\n  f ≈ g ↔\n  ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε :=\nby refl\n\n/-! We can define constants such as `0` and `1` as a constant sequence. Any\nconstant sequence is a Cauchy sequence: -/\n\ndef const (q : ℚ) : cau_seq :=\nsubtype.mk (λ_ : ℕ, q) (by rw is_cau_seq; intros ε hε; finish)\n\n/-! Defining addition of real numbers requires a little more effort. We define\naddition on Cauchy sequences as pairwise addition: -/\n\n@[instance] def has_add : has_add cau_seq :=\n{ add := λf g : cau_seq,\n    subtype.mk (λn : ℕ, seq_of f n + seq_of g n) sorry }\n\nlemma add_def (f g : cau_seq) : \n  seq_of (f + g) = λ n, seq_of f n + seq_of g n := \nrfl\n\n/-! Above, we omit the proof that the addition of two Cauchy sequences is again\na Cauchy sequence.\n\nNext, we need to show that this addition is compatible with `≈`: -/\n\nlemma add_equiv_add {f f' g g' : cau_seq} (hf : f ≈ f')\n    (hg : g ≈ g') :\n  f + g ≈ f' + g' :=\nbegin\n  intros ε₀ hε₀,\n  simp [setoid_iff],\n  cases' hf (ε₀ / 2) (half_pos hε₀) with Nf hNf,\n  cases' hg (ε₀ / 2) (half_pos hε₀) with Ng hNg,\n  apply exists.intro (max Nf Ng),\n  intros m hm,\n  calc  abs (seq_of (f + g) m - seq_of (f' + g') m)\n      = abs ((seq_of f m + seq_of g m)\n           - (seq_of f' m + seq_of g' m)) :\n    by refl\n  ... = abs ((seq_of f m - seq_of f' m)\n           + (seq_of g m - seq_of g' m)) :\n    begin\n      have arg_eq :\n        seq_of f m + seq_of g m - (seq_of f' m + seq_of g' m) =\n        seq_of f m - seq_of f' m + (seq_of g m - seq_of g' m),\n        by linarith,\n      rw arg_eq\n    end\n  ... ≤ abs (seq_of f m - seq_of f' m)\n      + abs (seq_of g m - seq_of g' m) :\n    by apply abs_add\n  ... < ε₀ / 2 + ε₀ / 2 :\n    add_lt_add (hNf m (le_of_max_le_left hm))\n      (hNg m (le_of_max_le_right hm))\n  ... = ε₀ :\n    by simp\nend\n\nlemma add_comm {f g : cau_seq} :\n  f + g ≈ g + f :=\nbegin\n  intros ε hε,\n  apply exists.intro 0,\n  intros m hm,\n  simp [add_def, add_comm],\n  assumption\nend\n\nend cau_seq\n\n/-! The real numbers are the quotient: -/\n\ndef real : Type :=\nquotient cau_seq.setoid\n\nnamespace real\n\n@[instance] def has_zero : has_zero real :=\n{ zero := ⟦cau_seq.const 0⟧ }\n\n@[instance] def has_one : has_one real :=\n{ one := ⟦cau_seq.const 1⟧ }\n\n@[instance] def has_add : has_add real :=\n{ add := quotient.lift₂ (λa b : cau_seq, ⟦a + b⟧)\n    begin\n      intros a b a' b' ha hb,\n      apply quotient.sound,\n      exact cau_seq.add_equiv_add ha hb,\n    end }\n\nlemma add_comm (a b : real) : a + b = b + a :=\nbegin \n  apply quotient.induction_on₂ a b,\n  intros a' b',\n  apply quotient.sound,\n  apply cau_seq.add_comm\nend \n\nend real\n\n\n/-! ### Alternative Definitions of `ℝ`\n\n* Dedekind cuts: `r : ℝ` is represented essentially as `{x : ℚ | x < r}`.\n\n* Binary sequences `ℕ → bool` can represent the interval `[0, 1]`. This can be\n  used to build `ℝ`. -/\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/love13_rational_and_real_numbers_demo.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797100118213, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7512329789915911}}
{"text": "/-\nCopyright (c) 2017 Johannes Hölzl. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Johannes Hölzl, Mario Carneiro\n-/\nimport measure_theory.outer_measure\nimport order.filter.countable_Inter\nimport data.set.accumulate\n\n/-!\n# Measure spaces\n\nGiven a measurable space `α`, a measure on `α` is a function that sends measurable sets to the\nextended nonnegative reals that satisfies the following conditions:\n1. `μ ∅ = 0`;\n2. `μ` 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 `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.\n\nWe introduce the following typeclasses for measures:\n\n* `probability_measure μ`: `μ univ = 1`;\n* `finite_measure μ`: `μ univ < ∞`;\n* `sigma_finite μ`: there exists a countable collection of measurable sets that cover `univ`\n  where `μ` is finite;\n* `locally_finite_measure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`;\n* `has_no_atoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as\n  `∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`.\n\nGiven a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding\nouter measure (so `s` might not be measurable). We can then define the completion of `μ` as the\nmeasure on the least `σ`-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 `μ : measure α`, `μ 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éodory 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 π-system generating\n  the measurable sets, if the π-system contains a spanning increasing sequence of sets where the\n  measures take finite value (in particular the measures are σ-finite). This is a special case of\n  the more general `ext_of_generate_from_of_cover`\n* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system\n  generating the measurable sets. This is a special case of `ext_of_generate_from_of_Union` using\n  `C ∪ {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\nnoncomputable theory\n\nopen classical set filter (hiding map) function measurable_space\nopen_locale classical topological_space big_operators filter ennreal nnreal\n\nvariables {α β γ δ ι : Type*}\n\nnamespace measure_theory\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 (α : Type*) [measurable_space α] extends outer_measure α :=\n(m_Union ⦃f : ℕ → set α⦄ :\n  (∀ i, measurable_set (f i)) → pairwise (disjoint on f) →\n  measure_of (⋃ i, f i) = ∑' i, measure_of (f i))\n(trimmed : to_outer_measure.trim = 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-/\ninstance measure.has_coe_to_fun [measurable_space α] : has_coe_to_fun (measure α) :=\n⟨λ _, set α → ℝ≥0∞, λ m, m.to_outer_measure⟩\n\nsection\n\nvariables [measurable_space α] {μ μ₁ μ₂ : measure α} {s s₁ s₂ t : set α}\n\nnamespace measure\n\n/-! ### General facts about measures -/\n\n/-- Obtain a measure by giving a countably additive function that sends `∅` to `0`. -/\ndef of_measurable (m : Π (s : set α), measurable_set s → ℝ≥0∞)\n  (m0 : m ∅ measurable_set.empty = 0)\n  (mU : ∀ {{f : ℕ → set α}} (h : ∀ i, measurable_set (f i)), pairwise (disjoint on f) →\n    m (⋃ i, f i) (measurable_set.Union h) = ∑' i, m (f i) (h i)) : measure α :=\n{ m_Union := λ f hf hd,\n  show induced_outer_measure m _ m0 (Union f) =\n      ∑' i, induced_outer_measure m _ m0 (f i), begin\n    rw [induced_outer_measure_eq m0 mU, mU hf hd],\n    congr, funext n, rw induced_outer_measure_eq m0 mU\n  end,\n  trimmed :=\n  show (induced_outer_measure m _ m0).trim = induced_outer_measure m _ m0, begin\n    unfold outer_measure.trim,\n    congr, funext s hs,\n    exact induced_outer_measure_eq m0 mU hs\n  end,\n  ..induced_outer_measure m _ m0 }\n\nlemma of_measurable_apply {m : Π (s : set α), measurable_set s → ℝ≥0∞}\n  {m0 : m ∅ measurable_set.empty = 0}\n  {mU : ∀ {{f : ℕ → set α}} (h : ∀ i, measurable_set (f i)), pairwise (disjoint on f) →\n    m (⋃ i, f i) (measurable_set.Union h) = ∑' i, m (f i) (h i)}\n  (s : set α) (hs : measurable_set s) : of_measurable m m0 mU s = m s hs :=\ninduced_outer_measure_eq m0 mU hs\n\nlemma to_outer_measure_injective : injective (to_outer_measure : measure α → outer_measure α) :=\nλ ⟨m₁, u₁, h₁⟩ ⟨m₂, u₂, h₂⟩ h, by { congr, exact h }\n\n@[ext] lemma ext (h : ∀ s, measurable_set s → μ₁ s = μ₂ s) : μ₁ = μ₂ :=\nto_outer_measure_injective $ by rw [← trimmed, outer_measure.trim_congr h, trimmed]\n\nlemma ext_iff : μ₁ = μ₂ ↔ ∀ s, measurable_set s → μ₁ s = μ₂ s :=\n⟨by { rintro rfl s hs, refl }, measure.ext⟩\n\nend measure\n\n@[simp] lemma coe_to_outer_measure : ⇑μ.to_outer_measure = μ := rfl\n\nlemma to_outer_measure_apply (s : set α) : μ.to_outer_measure s = μ s := rfl\n\nlemma measure_eq_trim (s : set α) : μ s = μ.to_outer_measure.trim s :=\nby rw μ.trimmed; refl\n\nlemma measure_eq_infi (s : set α) : μ s = ⨅ t (st : s ⊆ t) (ht : measurable_set t), μ t :=\nby rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl\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`. -/\nlemma measure_eq_infi' (μ : measure α) (s : set α) :\n  μ s = ⨅ t : { t // s ⊆ t ∧ measurable_set t}, μ t :=\nby simp_rw [infi_subtype, infi_and, subtype.coe_mk, ← measure_eq_infi]\n\nlemma measure_eq_induced_outer_measure :\n  μ s = induced_outer_measure (λ s _, μ s) measurable_set.empty μ.empty s :=\nmeasure_eq_trim _\n\nlemma to_outer_measure_eq_induced_outer_measure :\n  μ.to_outer_measure = induced_outer_measure (λ s _, μ s) measurable_set.empty μ.empty :=\nμ.trimmed.symm\n\nlemma measure_eq_extend (hs : measurable_set s) :\n  μ s = extend (λ t (ht : measurable_set t), μ t) s :=\nby { rw [measure_eq_induced_outer_measure, induced_outer_measure_eq_extend _ _ hs],\n  exact μ.m_Union }\n\n@[simp] lemma measure_empty : μ ∅ = 0 := μ.empty\n\nlemma nonempty_of_measure_ne_zero (h : μ s ≠ 0) : s.nonempty :=\nne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ measure_empty\n\nlemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.mono h\n\nlemma measure_mono_null (h : s₁ ⊆ s₂) (h₂ : μ s₂ = 0) : μ s₁ = 0 :=\nnonpos_iff_eq_zero.1 $ h₂ ▸ measure_mono h\n\nlemma measure_mono_top (h : s₁ ⊆ s₂) (h₁ : μ s₁ = ∞) : μ s₂ = ∞ :=\ntop_unique $ h₁ ▸ measure_mono h\n\n/-- For every set there exists a measurable superset of the same measure. -/\nlemma exists_measurable_superset (μ : measure α) (s : set α) :\n  ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = μ s :=\nby simpa only [← measure_eq_trim] using μ.to_outer_measure.exists_measurable_superset_eq_trim s\n\n/-- For every set `s` and a countable collection of measures `μ i` there exists a measurable\nsuperset `t ⊇ s` such that each measure `μ i` takes the same value on `s` and `t`. -/\nlemma exists_measurable_superset_forall_eq {ι} [encodable ι] (μ : ι → measure α) (s : set α) :\n  ∃ t, s ⊆ t ∧ measurable_set t ∧ ∀ i, μ i t = μ i s :=\nby simpa only [← measure_eq_trim]\n  using outer_measure.exists_measurable_superset_forall_eq_trim (λ i, (μ i).to_outer_measure) s\n\n/-- A measurable set `t ⊇ s` such that `μ t = μ s`. -/\ndef to_measurable (μ : measure α) (s : set α) : set α :=\nclassical.some (exists_measurable_superset μ s)\n\nlemma subset_to_measurable (μ : measure α) (s : set α) : s ⊆ to_measurable μ s :=\n(classical.some_spec (exists_measurable_superset μ s)).1\n\n@[simp] lemma measurable_set_to_measurable (μ : measure α) (s : set α) :\n  measurable_set (to_measurable μ s) :=\n(classical.some_spec (exists_measurable_superset μ s)).2.1\n\n@[simp] lemma measure_to_measurable (s : set α) : μ (to_measurable μ s) = μ s :=\n(classical.some_spec (exists_measurable_superset μ s)).2.2\n\nlemma exists_measurable_superset_of_null (h : μ s = 0) :\n  ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0 :=\nouter_measure.exists_measurable_superset_of_trim_eq_zero (by rw [← measure_eq_trim, h])\n\nlemma exists_measurable_superset_iff_measure_eq_zero :\n  (∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0) ↔ μ s = 0 :=\n⟨λ ⟨t, hst, _, ht⟩, measure_mono_null hst ht, exists_measurable_superset_of_null⟩\n\ntheorem measure_Union_le [encodable β] (s : β → set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) :=\nμ.to_outer_measure.Union _\n\nlemma measure_bUnion_le {s : set β} (hs : countable s) (f : β → set α) :\n  μ (⋃ b ∈ s, f b) ≤ ∑' p : s, μ (f p) :=\nbegin\n  haveI := hs.to_encodable,\n  rw [bUnion_eq_Union],\n  apply measure_Union_le\nend\n\nlemma measure_bUnion_finset_le (s : finset β) (f : β → set α) :\n  μ (⋃ b ∈ s, f b) ≤ ∑ p in s, μ (f p) :=\nbegin\n  rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],\n  exact measure_bUnion_le s.countable_to_set f\nend\n\nlemma measure_bUnion_lt_top {s : set β} {f : β → set α} (hs : finite s)\n  (hfin : ∀ i ∈ s, μ (f i) < ∞) : μ (⋃ i ∈ s, f i) < ∞ :=\nbegin\n  convert (measure_bUnion_finset_le hs.to_finset f).trans_lt _,\n  { ext, rw [finite.mem_to_finset] },\n  apply ennreal.sum_lt_top, simpa only [finite.mem_to_finset]\nend\n\nlemma measure_Union_null [encodable β] {s : β → set α} :\n  (∀ i, μ (s i) = 0) → μ (⋃ i, s i) = 0 :=\nμ.to_outer_measure.Union_null\n\nlemma measure_Union_null_iff [encodable ι] {s : ι → set α} :\n  μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 :=\n⟨λ h i, measure_mono_null (subset_Union _ _) h, measure_Union_null⟩\n\nlemma measure_bUnion_null_iff {s : set ι} (hs : countable s) {t : ι → set α} :\n  μ (⋃ i ∈ s, t i) = 0 ↔ ∀ i ∈ s, μ (t i) = 0 :=\nby { haveI := hs.to_encodable, rw [← Union_subtype, measure_Union_null_iff, set_coe.forall], refl }\n\ntheorem measure_union_le (s₁ s₂ : set α) : μ (s₁ ∪ s₂) ≤ μ s₁ + μ s₂ :=\nμ.to_outer_measure.union _ _\n\nlemma measure_union_null : μ s₁ = 0 → μ s₂ = 0 → μ (s₁ ∪ s₂) = 0 :=\nμ.to_outer_measure.union_null\n\nlemma measure_union_null_iff : μ (s₁ ∪ s₂) = 0 ↔ μ s₁ = 0 ∧ μ s₂ = 0:=\n⟨λ h, ⟨measure_mono_null (subset_union_left _ _) h, measure_mono_null (subset_union_right _ _) h⟩,\n  λ h, measure_union_null h.1 h.2⟩\n\n/-! ### The almost everywhere filter -/\n\n/-- The “almost everywhere” filter of co-null sets. -/\ndef measure.ae (μ : measure α) : filter α :=\n{ sets := {s | μ sᶜ = 0},\n  univ_sets := by simp,\n  inter_sets := λ s t hs ht, by simp only [compl_inter, mem_set_of_eq];\n    exact measure_union_null hs ht,\n  sets_of_superset := λ s t hs hst, measure_mono_null (set.compl_subset_compl.2 hst) hs }\n\nnotation `∀ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.eventually P (measure.ae μ)) := r\nnotation `∃ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.frequently P (measure.ae μ)) := r\nnotation f ` =ᵐ[`:50 μ:50 `] `:0 g:50 := f =ᶠ[measure.ae μ] g\nnotation f ` ≤ᵐ[`:50 μ:50 `] `:0 g:50 := f ≤ᶠ[measure.ae μ] g\n\nlemma mem_ae_iff {s : set α} : s ∈ μ.ae ↔ μ sᶜ = 0 := iff.rfl\n\nlemma ae_iff {p : α → Prop} : (∀ᵐ a ∂ μ, p a) ↔ μ { a | ¬ p a } = 0 := iff.rfl\n\nlemma compl_mem_ae_iff {s : set α} : sᶜ ∈ μ.ae ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl]\n\nlemma frequently_ae_iff {p : α → Prop} : (∃ᵐ a ∂μ, p a) ↔ μ {a | p a} ≠ 0 :=\nnot_congr compl_mem_ae_iff\n\nlemma frequently_ae_mem_iff {s : set α} : (∃ᵐ a ∂μ, a ∈ s) ↔ μ s ≠ 0 :=\nnot_congr compl_mem_ae_iff\n\nlemma measure_zero_iff_ae_nmem {s : set α} : μ s = 0 ↔ ∀ᵐ a ∂ μ, a ∉ s :=\ncompl_mem_ae_iff.symm\n\nlemma ae_of_all {p : α → Prop} (μ : measure α) : (∀ a, p a) → ∀ᵐ a ∂ μ, p a :=\neventually_of_forall\n\ninstance ae_is_measurably_generated : is_measurably_generated μ.ae :=\n⟨λ s hs, let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs in\n  ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩\n\ninstance : countable_Inter_filter μ.ae :=\n⟨begin\n  intros S hSc hS,\n  simp only [mem_ae_iff, compl_sInter, sUnion_image, bUnion_eq_Union] at hS ⊢,\n  haveI := hSc.to_encodable,\n  exact measure_Union_null (subtype.forall.2 hS)\nend⟩\n\nlemma ae_imp_iff {p : α → Prop} {q : Prop} : (∀ᵐ x ∂μ, q → p x) ↔ (q → ∀ᵐ x ∂μ, p x) :=\nfilter.eventually_imp_distrib_left\n\nlemma ae_all_iff [encodable ι] {p : α → ι → Prop} :\n  (∀ᵐ a ∂ μ, ∀ i, p a i) ↔ (∀ i, ∀ᵐ a ∂ μ, p a i) :=\neventually_countable_forall\n\nlemma ae_ball_iff {S : set ι} (hS : countable S) {p : Π (x : α) (i ∈ S), Prop} :\n  (∀ᵐ x ∂ μ, ∀ i ∈ S, p x i ‹_›) ↔ ∀ i ∈ S, ∀ᵐ x ∂ μ, p x i ‹_› :=\neventually_countable_ball hS\n\nlemma ae_eq_refl (f : α → δ) : f =ᵐ[μ] f := eventually_eq.rfl\n\nlemma ae_eq_symm {f g : α → δ} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f :=\nh.symm\n\nlemma ae_eq_trans {f g h: α → δ} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) :\n  f =ᵐ[μ] h :=\nh₁.trans h₂\n\n@[simp] lemma ae_eq_empty : s =ᵐ[μ] (∅ : set α) ↔ μ s = 0 :=\neventually_eq_empty.trans $ by simp [ae_iff]\n\nlemma ae_le_set : s ≤ᵐ[μ] t ↔ μ (s \\ t) = 0 :=\ncalc s ≤ᵐ[μ] t ↔ ∀ᵐ x ∂μ, x ∈ s → x ∈ t : iff.rfl\n           ... ↔ μ (s \\ t) = 0          : by simp [ae_iff]; refl\n\n@[simp] lemma union_ae_eq_right : (s ∪ t : set α) =ᵐ[μ] t ↔ μ (s \\ t) = 0 :=\nby simp [eventually_le_antisymm_iff, ae_le_set, union_diff_right,\n  diff_eq_empty.2 (set.subset_union_right _ _)]\n\nlemma diff_ae_eq_self : (s \\ t : set α) =ᵐ[μ] s ↔ μ (s ∩ t) = 0 :=\nby simp [eventually_le_antisymm_iff, ae_le_set, diff_diff_right,\n  diff_diff, diff_eq_empty.2 (set.subset_union_right _ _)]\n\nlemma ae_eq_set {s t : set α} :\n  s =ᵐ[μ] t ↔ μ (s \\ t) = 0 ∧ μ (t \\ s) = 0 :=\nby simp [eventually_le_antisymm_iff, ae_le_set]\n\n/-- If `s ⊆ t` modulo a set of measure `0`, then `μ s ≤ μ t`. -/\n@[mono] lemma measure_mono_ae (H : s ≤ᵐ[μ] t) : μ s ≤ μ t :=\ncalc μ s ≤ μ (s ∪ t)       : measure_mono $ subset_union_left s t\n     ... = μ (t ∪ s \\ t)   : by rw [union_diff_self, set.union_comm]\n     ... ≤ μ t + μ (s \\ t) : measure_union_le _ _\n     ... = μ t             : by rw [ae_le_set.1 H, add_zero]\n\nalias measure_mono_ae ← filter.eventually_le.measure_le\n\n/-- If two sets are equal modulo a set of measure zero, then `μ s = μ t`. -/\nlemma measure_congr (H : s =ᵐ[μ] t) : μ s = μ t :=\nle_antisymm H.le.measure_le H.symm.le.measure_le\n\n/-- A measure space is a measurable space equipped with a\n  measure, referred to as `volume`. -/\nclass measure_space (α : Type*) extends measurable_space α :=\n(volume : measure α)\n\nexport measure_space (volume)\n\n/-- `volume` is the canonical  measure on `α`. -/\nadd_decl_doc volume\n\nsection measure_space\n\nnotation `∀ᵐ` binders `, ` r:(scoped P, filter.eventually P\n  (measure_theory.measure.ae measure_theory.measure_space.volume)) := r\n\nnotation `∃ᵐ` binders `, ` r:(scoped P, filter.frequently P\n  (measure_theory.measure.ae measure_theory.measure_space.volume)) := r\n\n/-- The tactic `exact volume`, to be used in optional (`auto_param`) arguments. -/\nmeta def volume_tac : tactic unit := `[exact measure_theory.measure_space.volume]\n\nend measure_space\n\nlemma measure_Union [encodable β] {f : β → set α}\n  (hn : pairwise (disjoint on f)) (h : ∀ i, measurable_set (f i)) :\n  μ (⋃ i, f i) = ∑' i, μ (f i) :=\nbegin\n  rw [measure_eq_extend (measurable_set.Union h),\n    extend_Union measurable_set.empty _ measurable_set.Union _ hn h],\n  { simp [measure_eq_extend, h] },\n  { exact μ.empty },\n  { exact μ.m_Union }\nend\n\nlemma measure_union (hd : disjoint s₁ s₂) (h₁ : measurable_set s₁) (h₂ : measurable_set s₂) :\n  μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=\nbegin\n  rw [union_eq_Union, measure_Union, tsum_fintype, fintype.sum_bool, cond, cond],\n  exacts [pairwise_disjoint_on_bool.2 hd, λ b, bool.cases_on b h₂ h₁]\nend\n\nlemma measure_bUnion {s : set β} {f : β → set α} (hs : countable s)\n  (hd : pairwise_on s (disjoint on f)) (h : ∀ b ∈ s, measurable_set (f b)) :\n  μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=\nbegin\n  haveI := hs.to_encodable,\n  rw bUnion_eq_Union,\n  exact measure_Union (hd.on_injective subtype.coe_injective $ λ x, x.2) (λ x, h x x.2)\nend\n\nlemma measure_sUnion {S : set (set α)} (hs : countable S)\n  (hd : pairwise_on S disjoint) (h : ∀ s ∈ S, measurable_set s) :\n  μ (⋃₀ S) = ∑' s : S, μ s :=\nby rw [sUnion_eq_bUnion, measure_bUnion hs hd h]\n\nlemma measure_bUnion_finset {s : finset ι} {f : ι → set α} (hd : pairwise_on ↑s (disjoint on f))\n  (hm : ∀ b ∈ s, measurable_set (f b)) :\n  μ (⋃ b ∈ s, f b) = ∑ p in s, μ (f p) :=\nbegin\n  rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],\n  exact measure_bUnion s.countable_to_set hd hm\nend\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 ⁻¹' {y}`. -/\nlemma tsum_measure_preimage_singleton {s : set β} (hs : countable s) {f : α → β}\n  (hf : ∀ y ∈ s, measurable_set (f ⁻¹' {y})) :\n  ∑' b : s, μ (f ⁻¹' {↑b}) = μ (f ⁻¹' s) :=\nby rw [← set.bUnion_preimage_singleton, measure_bUnion hs (pairwise_on_disjoint_fiber _ _) hf]\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 ⁻¹' {y}`. -/\nlemma sum_measure_preimage_singleton (s : finset β) {f : α → β}\n  (hf : ∀ y ∈ s, measurable_set (f ⁻¹' {y})) :\n  ∑ b in s, μ (f ⁻¹' {b}) = μ (f ⁻¹' ↑s) :=\nby simp only [← measure_bUnion_finset (pairwise_on_disjoint_fiber _ _) hf,\n  finset.set_bUnion_preimage_singleton]\n\nlemma measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \\ s₂) = μ s₁ :=\nmeasure_congr $ diff_ae_eq_self.2 h\n\nlemma measure_diff_null (h : μ s₂ = 0) : μ (s₁ \\ s₂) = μ s₁ :=\nmeasure_diff_null' $ measure_mono_null (inter_subset_right _ _) h\n\nlemma measure_diff (h : s₂ ⊆ s₁) (h₁ : measurable_set s₁) (h₂ : measurable_set s₂)\n  (h_fin : μ s₂ < ∞) :\n  μ (s₁ \\ s₂) = μ s₁ - μ s₂ :=\nbegin\n  refine (ennreal.add_sub_self' h_fin).symm.trans _,\n  rw [← measure_union disjoint_diff h₂ (h₁.diff h₂), union_diff_cancel h]\nend\n\nlemma measure_compl (h₁ : measurable_set s) (h_fin : μ s < ∞) : μ (sᶜ) = μ univ - μ s :=\nby { rw compl_eq_univ_diff, exact measure_diff (subset_univ s) measurable_set.univ h₁ h_fin }\n\nlemma sum_measure_le_measure_univ {s : finset ι} {t : ι → set α} (h : ∀ i ∈ s, measurable_set (t i))\n  (H : pairwise_on ↑s (disjoint on t)) :\n  ∑ i in s, μ (t i) ≤ μ (univ : set α) :=\nby { rw ← measure_bUnion_finset H h, exact measure_mono (subset_univ _) }\n\nlemma tsum_measure_le_measure_univ {s : ι → set α} (hs : ∀ i, measurable_set (s i))\n  (H : pairwise (disjoint on s)) :\n  ∑' i, μ (s i) ≤ μ (univ : set α) :=\nbegin\n  rw [ennreal.tsum_eq_supr_sum],\n  exact supr_le (λ s, sum_measure_le_measure_univ (λ i hi, hs i) (λ i hi j hj hij, H i j hij))\nend\n\n/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then\none of the intersections `s i ∩ s j` is not empty. -/\nlemma exists_nonempty_inter_of_measure_univ_lt_tsum_measure (μ : measure α) {s : ι → set α}\n  (hs : ∀ i, measurable_set (s i)) (H : μ (univ : set α) < ∑' i, μ (s i)) :\n  ∃ i j (h : i ≠ j), (s i ∩ s j).nonempty :=\nbegin\n  contrapose! H,\n  apply tsum_measure_le_measure_univ hs,\n  exact λ i j hij x hx, H i j hij ⟨x, hx⟩\nend\n\n/-- Pigeonhole principle for measure spaces: if `s` is a `finset` and\n`∑ i in s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/\nlemma exists_nonempty_inter_of_measure_univ_lt_sum_measure (μ : measure α) {s : finset ι}\n  {t : ι → set α} (h : ∀ i ∈ s, measurable_set (t i)) (H : μ (univ : set α) < ∑ i in s, μ (t i)) :\n  ∃ (i ∈ s) (j ∈ s) (h : i ≠ j), (t i ∩ t j).nonempty :=\nbegin\n  contrapose! H,\n  apply sum_measure_le_measure_univ h,\n  exact λ i hi j hj hij x hx, H i hi j hj hij ⟨x, hx⟩\nend\n\n/-- Continuity from below: the measure of the union of a directed sequence of measurable sets\nis the supremum of the measures. -/\nlemma measure_Union_eq_supr [encodable ι] {s : ι → set α} (h : ∀ i, measurable_set (s i))\n  (hd : directed (⊆) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) :=\nbegin\n  by_cases hι : nonempty ι, swap,\n  { simp only [supr_of_empty hι, Union], exact measure_empty },\n  resetI,\n  refine le_antisymm _ (supr_le $ λ i, measure_mono $ subset_Union _ _),\n  have : ∀ n, measurable_set (disjointed (λ n, ⋃ b ∈ encodable.decode2 ι n, s b) n) :=\n    measurable_set.disjointed (measurable_set.bUnion_decode2 h),\n  rw [← encodable.Union_decode2, ← Union_disjointed, measure_Union disjoint_disjointed this,\n    ennreal.tsum_eq_supr_nat],\n  simp only [← measure_bUnion_finset (disjoint_disjointed.pairwise_on _) (λ n _, this n)],\n  refine supr_le (λ n, _),\n  refine le_trans (_ : _ ≤ μ (⋃ (k ∈ finset.range n) (i ∈ encodable.decode2 ι k), s i)) _,\n  exact measure_mono (bUnion_subset_bUnion_right (λ k hk, disjointed_subset)),\n  simp only [← finset.set_bUnion_option_to_finset, ← finset.set_bUnion_bUnion],\n  generalize : (finset.range n).bUnion (λ k, (encodable.decode2 ι k).to_finset) = t,\n  rcases hd.finset_le t with ⟨i, hi⟩,\n  exact le_supr_of_le i (measure_mono $ bUnion_subset hi)\nend\n\nlemma measure_bUnion_eq_supr {s : ι → set α} {t : set ι} (ht : countable t)\n  (h : ∀ i ∈ t, measurable_set (s i)) (hd : directed_on ((⊆) on s) t) :\n  μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) :=\nbegin\n  haveI := ht.to_encodable,\n  rw [bUnion_eq_Union, measure_Union_eq_supr (set_coe.forall'.1 h) hd.directed_coe,\n    supr_subtype'],\n  refl\nend\n\n/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable\nsets is the infimum of the measures. -/\nlemma measure_Inter_eq_infi [encodable ι] {s : ι → set α}\n  (h : ∀ i, measurable_set (s i)) (hd : directed (⊇) s)\n  (hfin : ∃ i, μ (s i) < ∞) :\n  μ (⋂ i, s i) = (⨅ i, μ (s i)) :=\nbegin\n  rcases hfin with ⟨k, hk⟩,\n  rw [← ennreal.sub_sub_cancel (by exact hk) (infi_le _ k), ennreal.sub_infi,\n    ← ennreal.sub_sub_cancel (by exact hk) (measure_mono (Inter_subset _ k)),\n    ← measure_diff (Inter_subset _ k) (h k) (measurable_set.Inter h)\n      (lt_of_le_of_lt (measure_mono (Inter_subset _ k)) hk),\n    diff_Inter, measure_Union_eq_supr],\n  { congr' 1,\n    refine le_antisymm (supr_le_supr2 $ λ i, _) (supr_le_supr $ λ i, _),\n    { rcases hd i k with ⟨j, hji, hjk⟩,\n      use j,\n      rw [← measure_diff hjk (h _) (h _) ((measure_mono hjk).trans_lt hk)],\n      exact measure_mono (diff_subset_diff_right hji) },\n    { rw [ennreal.sub_le_iff_le_add, ← measure_union disjoint_diff.symm ((h k).diff (h i)) (h i),\n        set.union_comm],\n      exact measure_mono (diff_subset_iff.1 $ subset.refl _) } },\n  { exact λ i, (h k).diff (h i) },\n  { exact hd.mono_comp _ (λ _ _, diff_subset_diff_right) }\nend\n\nlemma measure_eq_inter_diff (hs : measurable_set s) (ht : measurable_set t) :\n  μ s = μ (s ∩ t) + μ (s \\ t) :=\nhave hd : disjoint (s ∩ t) (s \\ t) := assume a ⟨⟨_, hs⟩, _, hns⟩, hns hs ,\nby rw [← measure_union hd (hs.inter ht) (hs.diff ht), inter_union_diff s t]\n\nlemma measure_union_add_inter (hs : measurable_set s) (ht : measurable_set t) :\n  μ (s ∪ t) + μ (s ∩ t) = μ s + μ t :=\nby { rw [measure_eq_inter_diff (hs.union ht) ht, set.union_inter_cancel_right,\n  union_diff_right, measure_eq_inter_diff hs ht], ac_refl }\n\n/-- Continuity from below: the measure of the union of an increasing sequence of measurable sets\nis the limit of the measures. -/\nlemma tendsto_measure_Union {s : ℕ → set α} (hs : ∀ n, measurable_set (s n)) (hm : monotone s) :\n  tendsto (μ ∘ s) at_top (𝓝 (μ (⋃ n, s n))) :=\nbegin\n  rw measure_Union_eq_supr hs (directed_of_sup hm),\n  exact tendsto_at_top_supr (assume n m hnm, measure_mono $ hm hnm)\nend\n\n/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable\nsets is the limit of the measures. -/\nlemma tendsto_measure_Inter {s : ℕ → set α}\n  (hs : ∀ n, measurable_set (s n)) (hm : ∀ ⦃n m⦄, n ≤ m → s m ⊆ s n) (hf : ∃ i, μ (s i) < ∞) :\n  tendsto (μ ∘ s) at_top (𝓝 (μ (⋂ n, s n))) :=\nbegin\n  rw measure_Inter_eq_infi hs (directed_of_sup hm) hf,\n  exact tendsto_at_top_infi (assume n m hnm, measure_mono $ hm hnm),\nend\n\n/-- One direction of the Borel-Cantelli lemma: if (sᵢ) is a sequence of measurable sets such that\n  ∑ μ sᵢ exists, then the limit superior of the sᵢ is a null set. -/\nlemma measure_limsup_eq_zero {s : ℕ → set α} (hs : ∀ i, measurable_set (s i))\n  (hs' : ∑' i, μ (s i) ≠ ∞) : μ (limsup at_top s) = 0 :=\nbegin\n  rw limsup_eq_infi_supr_of_nat',\n  -- We will show that both `μ (⨅ n, ⨆ i, s (i + n))` and `0` are the limit of `μ (⊔ i, s (i + n))`\n  -- as `n` tends to infinity. For the former, we use continuity from above.\n  refine tendsto_nhds_unique\n    (tendsto_measure_Inter (λ i, measurable_set.Union (λ b, hs (b + i))) _\n      ⟨0, lt_of_le_of_lt (measure_Union_le s) (ennreal.lt_top_iff_ne_top.2 hs')⟩) _,\n  { intros n m hnm x,\n    simp only [set.mem_Union],\n    exact λ ⟨i, hi⟩, ⟨i + (m - n), by simpa only [add_assoc, nat.sub_add_cancel hnm] using hi⟩ },\n  { -- For the latter, notice that, `μ (⨆ i, s (i + n)) ≤ ∑' s (i + n)`. Since the right hand side\n    -- converges to `0` by hypothesis, so does the former and the proof is complete.\n    exact (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds\n      (ennreal.tendsto_sum_nat_add (μ ∘ s) hs')\n      (eventually_of_forall (by simp only [forall_const, zero_le]))\n      (eventually_of_forall (λ i, measure_Union_le _))) }\nend\n\nlemma measure_if {x : β} {t : set β} {s : set α} {μ : measure α} :\n  μ (if x ∈ t then s else ∅) = indicator t (λ _, μ s) x :=\nby { split_ifs; simp [h] }\n\nend\n\nsection outer_measure\n\nvariables [ms : measurable_space α] {s t : set α}\ninclude ms\n\n/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are\n  Carathéodory measurable. -/\ndef outer_measure.to_measure (m : outer_measure α) (h : ms ≤ m.caratheodory) : measure α :=\nmeasure.of_measurable (λ s _, m s) m.empty\n  (λ f hf hd, m.Union_eq_of_caratheodory (λ i, h _ (hf i)) hd)\n\nlemma le_to_outer_measure_caratheodory (μ : measure α) : ms ≤ μ.to_outer_measure.caratheodory :=\nbegin\n  assume s hs,\n  rw to_outer_measure_eq_induced_outer_measure,\n  refine outer_measure.of_function_caratheodory (λ t, le_infi $ λ ht, _),\n  rw [← measure_eq_extend (ht.inter hs),\n    ← measure_eq_extend (ht.diff hs),\n    ← measure_union _ (ht.inter hs) (ht.diff hs),\n    inter_union_diff],\n  exact le_refl _,\n  exact λ x ⟨⟨_, h₁⟩, _, h₂⟩, h₂ h₁\nend\n\n@[simp] lemma to_measure_to_outer_measure (m : outer_measure α) (h : ms ≤ m.caratheodory) :\n  (m.to_measure h).to_outer_measure = m.trim := rfl\n\n@[simp] lemma to_measure_apply (m : outer_measure α) (h : ms ≤ m.caratheodory)\n  {s : set α} (hs : measurable_set s) : m.to_measure h s = m s :=\nm.trim_eq hs\n\nlemma le_to_measure_apply (m : outer_measure α) (h : ms ≤ m.caratheodory) (s : set α) :\n  m s ≤ m.to_measure h s :=\nm.le_trim s\n\n@[simp] lemma to_outer_measure_to_measure {μ : measure α} :\n  μ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = μ :=\nmeasure.ext $ λ s, μ.to_outer_measure.trim_eq\n\nend outer_measure\n\nvariables [measurable_space α] [measurable_space β] [measurable_space γ]\nvariables {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : measure α} {s s' t : set α}\n\nnamespace measure\n\nprotected lemma caratheodory (μ : measure α) (hs : measurable_set s) :\n  μ (t ∩ s) + μ (t \\ s) = μ t :=\n(le_to_outer_measure_caratheodory μ s hs t).symm\n\n/-! ### The `ℝ≥0∞`-module of measures -/\n\ninstance : has_zero (measure α) :=\n⟨{ to_outer_measure := 0,\n   m_Union := λ f hf hd, tsum_zero.symm,\n   trimmed := outer_measure.trim_zero }⟩\n\n@[simp] theorem zero_to_outer_measure : (0 : measure α).to_outer_measure = 0 := rfl\n\n@[simp, norm_cast] theorem coe_zero : ⇑(0 : measure α) = 0 := rfl\n\nlemma eq_zero_of_not_nonempty (h : ¬nonempty α) (μ : measure α) : μ = 0 :=\next $ λ s hs, by simp only [eq_empty_of_not_nonempty h s, measure_empty]\n\ninstance : inhabited (measure α) := ⟨0⟩\n\ninstance : has_add (measure α) :=\n⟨λ μ₁ μ₂, {\n  to_outer_measure := μ₁.to_outer_measure + μ₂.to_outer_measure,\n  m_Union := λ s hs hd,\n    show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)),\n    by rw [ennreal.tsum_add, measure_Union hd hs, measure_Union hd hs],\n  trimmed := by rw [outer_measure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩\n\n@[simp] theorem add_to_outer_measure (μ₁ μ₂ : measure α) :\n  (μ₁ + μ₂).to_outer_measure = μ₁.to_outer_measure + μ₂.to_outer_measure := rfl\n\n@[simp, norm_cast] theorem coe_add (μ₁ μ₂ : measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl\n\ntheorem add_apply (μ₁ μ₂ : measure α) (s : set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl\n\ninstance add_comm_monoid : add_comm_monoid (measure α) :=\nto_outer_measure_injective.add_comm_monoid to_outer_measure zero_to_outer_measure\n  add_to_outer_measure\n\ninstance : has_scalar ℝ≥0∞ (measure α) :=\n⟨λ c μ,\n  { to_outer_measure := c • μ.to_outer_measure,\n    m_Union := λ s hs hd, by simp [measure_Union, *, ennreal.tsum_mul_left],\n    trimmed := by rw [outer_measure.trim_smul, μ.trimmed] }⟩\n\n@[simp] theorem smul_to_outer_measure (c : ℝ≥0∞) (μ : measure α) :\n  (c • μ).to_outer_measure = c • μ.to_outer_measure :=\nrfl\n\n@[simp, norm_cast] theorem coe_smul (c : ℝ≥0∞) (μ : measure α) : ⇑(c • μ) = c • μ :=\nrfl\n\ntheorem smul_apply (c : ℝ≥0∞) (μ : measure α) (s : set α) : (c • μ) s = c * μ s :=\nrfl\n\ninstance : module ℝ≥0∞ (measure α) :=\ninjective.module ℝ≥0∞ ⟨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\ninstance : partial_order (measure α) :=\n{ le          := λ m₁ m₂, ∀ s, measurable_set s → m₁ s ≤ m₂ s,\n  le_refl     := assume m s hs, le_refl _,\n  le_trans    := assume m₁ m₂ m₃ h₁ h₂ s hs, le_trans (h₁ s hs) (h₂ s hs),\n  le_antisymm := assume m₁ m₂ h₁ h₂, ext $\n    assume s hs, le_antisymm (h₁ s hs) (h₂ s hs) }\n\ntheorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, measurable_set s → μ₁ s ≤ μ₂ s := iff.rfl\n\ntheorem to_outer_measure_le : μ₁.to_outer_measure ≤ μ₂.to_outer_measure ↔ μ₁ ≤ μ₂ :=\nby rw [← μ₂.trimmed, outer_measure.le_trim_iff]; refl\n\ntheorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s :=\nto_outer_measure_le.symm\n\ntheorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, measurable_set s ∧ μ s < ν s :=\nlt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff, not_forall, not_le, exists_prop]\n\ntheorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=\nlt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff', not_forall, not_le]\n\n-- TODO: add typeclasses for `∀ c, monotone ((*) c)` and `∀ c, monotone ((+) c)`\n\nprotected lemma add_le_add_left (ν : measure α) (hμ : μ₁ ≤ μ₂) : ν + μ₁ ≤ ν + μ₂ :=\nλ s hs, add_le_add_left (hμ s hs) _\n\nprotected lemma add_le_add_right (hμ : μ₁ ≤ μ₂) (ν : measure α) : μ₁ + ν ≤ μ₂ + ν :=\nλ s hs, add_le_add_right (hμ s hs) _\n\nprotected lemma add_le_add (hμ : μ₁ ≤ μ₂) (hν : ν₁ ≤ ν₂) :\n  μ₁ + ν₁ ≤ μ₂ + ν₂ :=\nλ s hs, add_le_add (hμ s hs) (hν s hs)\n\nprotected lemma le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν :=\nλ s hs, le_add_left (h s hs)\n\nprotected lemma le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' :=\nλ s hs, le_add_right (h s hs)\n\nsection Inf\nvariables {m : set (measure α)}\n\nlemma Inf_caratheodory (s : set α) (hs : measurable_set s) :\n  (Inf (to_outer_measure '' m)).caratheodory.measurable_set' s :=\nbegin\n  rw [outer_measure.Inf_eq_bounded_by_Inf_gen],\n  refine outer_measure.bounded_by_caratheodory (λ t, _),\n  simp only [outer_measure.Inf_gen, le_infi_iff, ball_image_iff, coe_to_outer_measure,\n    measure_eq_infi t],\n  intros μ hμ u htu hu,\n  have hm : ∀ {s t}, s ⊆ t → outer_measure.Inf_gen (to_outer_measure '' m) s ≤ μ t,\n  { intros s t hst,\n    rw [outer_measure.Inf_gen_def],\n    refine infi_le_of_le (μ.to_outer_measure) (infi_le_of_le (mem_image_of_mem _ hμ) _),\n    rw [to_outer_measure_apply],\n    refine measure_mono hst },\n  rw [measure_eq_inter_diff hu hs],\n  refine add_le_add (hm $ inter_subset_inter_left _ htu) (hm $ diff_subset_diff_left htu)\nend\n\ninstance : has_Inf (measure α) :=\n⟨λ m, (Inf (to_outer_measure '' m)).to_measure $ Inf_caratheodory⟩\n\nlemma Inf_apply (hs : measurable_set s) : Inf m s = Inf (to_outer_measure '' m) s :=\nto_measure_apply _ _ hs\n\nprivate lemma measure_Inf_le (h : μ ∈ m) : Inf m ≤ μ :=\nhave Inf (to_outer_measure '' m) ≤ μ.to_outer_measure := Inf_le (mem_image_of_mem _ h),\nassume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s\n\nprivate lemma measure_le_Inf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ Inf m :=\nhave μ.to_outer_measure ≤ Inf (to_outer_measure '' m) :=\n  le_Inf $ ball_image_of_ball $ assume μ hμ, to_outer_measure_le.2 $ h _ hμ,\nassume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s\n\ninstance : complete_semilattice_Inf (measure α) :=\n{ Inf_le := λ s a, measure_Inf_le,\n  le_Inf := λ s a, measure_le_Inf,\n  ..(by apply_instance : partial_order (measure α)),\n  ..(by apply_instance : has_Inf (measure α)), }\n\ninstance : complete_lattice (measure α) :=\n{ bot := 0,\n  bot_le := assume a s hs, by exact bot_le,\n/- Adding an explicit `top` makes `leanchecker` fail, see lean#364, disable for now\n\n  top := (⊤ : outer_measure α).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 ⊤ _ hs, outer_measure.top_apply],\n-/\n  .. complete_lattice_of_complete_semilattice_Inf (measure α) }\n\nend Inf\n\nprotected lemma zero_le (μ : measure α) : 0 ≤ μ := bot_le\n\nlemma nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 :=\nμ.zero_le.le_iff_eq\n\n@[simp] lemma measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 :=\n⟨λ h, bot_unique $ λ s hs, trans_rel_left (≤) (measure_mono (subset_univ s)) h, λ h, h.symm ▸ rfl⟩\n\n/-! ### Pushforward and pullback -/\n\n/-- Lift a linear map between `outer_measure` spaces such that for each measure `μ` every measurable\nset is caratheodory-measurable w.r.t. `f μ` to a linear map between `measure` spaces. -/\ndef lift_linear (f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β)\n  (hf : ∀ μ : measure α, ‹_› ≤ (f μ.to_outer_measure).caratheodory) :\n  measure α →ₗ[ℝ≥0∞] measure β :=\n{ to_fun := λ μ, (f μ.to_outer_measure).to_measure (hf μ),\n  map_add' := λ μ₁ μ₂, ext $ λ s hs, by simp [hs],\n  map_smul' := λ c μ, ext $ λ s hs, by simp [hs] }\n\n@[simp] lemma lift_linear_apply {f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β} (hf)\n  {s : set β} (hs : measurable_set s) : lift_linear f hf μ s = f μ.to_outer_measure s :=\nto_measure_apply _ _ hs\n\nlemma le_lift_linear_apply {f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β} (hf) (s : set β) :\n  f μ.to_outer_measure s ≤ lift_linear f hf μ s :=\nle_to_measure_apply _ _ s\n\n/-- The pushforward of a measure. It is defined to be `0` if `f` is not a measurable function. -/\ndef map (f : α → β) : measure α →ₗ[ℝ≥0∞] measure β :=\nif hf : measurable f then\n  lift_linear (outer_measure.map f) $ λ μ s hs t,\n    le_to_outer_measure_caratheodory μ _ (hf hs) (f ⁻¹' t)\nelse 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 {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :\n  map f μ s = μ (f ⁻¹' s) :=\nby simp [map, dif_pos hf, hs]\n\ntheorem map_of_not_measurable {f : α → β} (hf : ¬measurable f) :\n  map f μ = 0 :=\nby rw [map, dif_neg hf, linear_map.zero_apply]\n\n@[simp] lemma map_id : map id μ = μ :=\next $ λ s, map_apply measurable_id\n\nlemma map_map {g : β → γ} {f : α → β} (hg : measurable g) (hf : measurable f) :\n  map g (map f μ) = map (g ∘ f) μ :=\next $ λ s hs,\nby simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp]\n\n@[mono] lemma map_mono (f : α → β) (h : μ ≤ ν) : map f μ ≤ map f ν :=\nif hf : measurable f then λ s hs, by simp only [map_apply hf hs, h _ (hf hs)]\nelse by simp only [map_of_not_measurable hf, le_rfl]\n\n/-- Even if `s` is not measurable, we can bound `map f μ s` from below.\n  See also `measurable_equiv.map_apply`. -/\ntheorem le_map_apply {f : α → β} (hf : measurable f) (s : set β) : μ (f ⁻¹' s) ≤ map f μ s :=\nbegin\n  rw [measure_eq_infi' (map f μ)], refine le_infi _, rintro ⟨t, hst, ht⟩,\n  convert measure_mono (preimage_mono hst),\n  exact map_apply hf ht\nend\n\n/-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/\nlemma preimage_null_of_map_null {f : α → β} (hf : measurable f) {s : set β}\n  (hs : map f μ s = 0) : μ (f ⁻¹' s) = 0 :=\nnonpos_iff_eq_zero.mp $ (le_map_apply hf s).trans_eq hs\n\nlemma tendsto_ae_map {f : α → β} (hf : measurable f) : tendsto f μ.ae (map f μ).ae :=\nλ s hs, preimage_null_of_map_null hf hs\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 μ s = μ (f '' s)`. -/\ndef comap (f : α → β) : measure β →ₗ[ℝ≥0∞] measure α :=\nif hf : injective f ∧ ∀ s, measurable_set s → measurable_set (f '' s) then\n  lift_linear (outer_measure.comap f) $ λ μ s hs t,\n  begin\n    simp only [coe_to_outer_measure, outer_measure.comap_apply, ← image_inter hf.1,\n      image_diff hf.1],\n    apply le_to_outer_measure_caratheodory,\n    exact hf.2 s hs\n  end\nelse 0\n\nlemma comap_apply (f : α → β) (hfi : injective f)\n  (hf : ∀ s, measurable_set s → measurable_set (f '' s)) (μ : measure β) (hs : measurable_set s) :\n  comap f μ s = μ (f '' s) :=\nbegin\n  rw [comap, dif_pos, lift_linear_apply _ hs, outer_measure.comap_apply, coe_to_outer_measure],\n  exact ⟨hfi, hf⟩\nend\n\n/-! ### Restricting a measure -/\n\n/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/\ndef restrictₗ (s : set α) : measure α →ₗ[ℝ≥0∞] measure α :=\nlift_linear (outer_measure.restrict s) $ λ μ s' hs' t,\nbegin\n  suffices : μ (s ∩ t) = μ (s ∩ t ∩ s') + μ (s ∩ t \\ s'),\n  { simpa [← set.inter_assoc, set.inter_comm _ s, ← inter_diff_assoc] },\n  exact le_to_outer_measure_caratheodory _ _ hs' _,\nend\n\n/-- Restrict a measure `μ` to a set `s`. -/\ndef restrict (μ : measure α) (s : set α) : measure α := restrictₗ s μ\n\n@[simp] lemma restrictₗ_apply (s : set α) (μ : measure α) :\n  restrictₗ s μ = μ.restrict s :=\nrfl\n\n/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of\n  the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`\n  be measurable instead of `t` exists as `measure.restrict_apply'`. -/\n@[simp] lemma restrict_apply (ht : measurable_set t) : μ.restrict s t = μ (t ∩ s) :=\nby simp [← restrictₗ_apply, restrictₗ, ht]\n\nlemma restrict_eq_self (h_meas_t : measurable_set t) (h : t ⊆ s) : μ.restrict s t = μ t :=\nby rw [restrict_apply h_meas_t, inter_eq_left_iff_subset.mpr h]\n\nlemma restrict_apply_self (μ:measure α) (h_meas_s : measurable_set s) :\n  (μ.restrict s) s = μ s := (restrict_eq_self h_meas_s (set.subset.refl _))\n\nlemma restrict_apply_univ (s : set α) : μ.restrict s univ = μ s :=\nby rw [restrict_apply measurable_set.univ, set.univ_inter]\n\nlemma le_restrict_apply (s t : set α) :\n  μ (t ∩ s) ≤ μ.restrict s t :=\nby { rw [restrict, restrictₗ], convert le_lift_linear_apply _ t, simp }\n\n@[simp] lemma restrict_add (μ ν : measure α) (s : set α) :\n  (μ + ν).restrict s = μ.restrict s + ν.restrict s :=\n(restrictₗ s).map_add μ ν\n\n@[simp] lemma restrict_zero (s : set α) : (0 : measure α).restrict s = 0 :=\n(restrictₗ s).map_zero\n\n@[simp] lemma restrict_smul (c : ℝ≥0∞) (μ : measure α) (s : set α) :\n  (c • μ).restrict s = c • μ.restrict s :=\n(restrictₗ s).map_smul c μ\n\n@[simp] lemma restrict_restrict (hs : measurable_set s) :\n  (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=\next $ λ u hu, by simp [*, set.inter_assoc]\n\nlemma restrict_apply_eq_zero (ht : measurable_set t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=\nby rw [restrict_apply ht]\n\nlemma measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=\nnonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)\n\nlemma restrict_apply_eq_zero' (hs : measurable_set s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=\nbegin\n  refine ⟨measure_inter_eq_zero_of_restrict, λ h, _⟩,\n  rcases exists_measurable_superset_of_null h with ⟨t', htt', ht', ht'0⟩,\n  apply measure_mono_null ((inter_subset _ _ _).1 htt'),\n  rw [restrict_apply (hs.compl.union ht'), union_inter_distrib_right, compl_inter_self,\n    set.empty_union],\n  exact measure_mono_null (inter_subset_left _ _) ht'0\nend\n\n@[simp] lemma restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 :=\nby rw [← measure_univ_eq_zero, restrict_apply_univ]\n\n@[simp] lemma restrict_empty : μ.restrict ∅ = 0 := ext $ λ s hs, by simp [hs]\n\n@[simp] lemma restrict_univ : μ.restrict univ = μ := ext $ λ s hs, by simp [hs]\n\nlemma restrict_eq_self_of_measurable_subset (ht : measurable_set t) (t_subset : t ⊆ s) :\n  μ.restrict s t = μ t :=\nby rw [measure.restrict_apply ht, set.inter_eq_self_of_subset_left t_subset]\n\nlemma restrict_union_apply (h : disjoint (t ∩ s) (t ∩ s')) (hs : measurable_set s)\n  (hs' : measurable_set s') (ht : measurable_set t) :\n  μ.restrict (s ∪ s') t = μ.restrict s t + μ.restrict s' t :=\nbegin\n  simp only [restrict_apply, ht, set.inter_union_distrib_left],\n  exact measure_union h (ht.inter hs) (ht.inter hs'),\nend\n\nlemma restrict_union (h : disjoint s t) (hs : measurable_set s) (ht : measurable_set t) :\n  μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=\next $ λ t' ht', restrict_union_apply (h.mono inf_le_right inf_le_right) hs ht ht'\n\nlemma restrict_union_add_inter (hs : measurable_set s) (ht : measurable_set t) :\n  μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=\nbegin\n  ext1 u hu,\n  simp only [add_apply, restrict_apply hu, inter_union_distrib_left],\n  convert measure_union_add_inter (hu.inter hs) (hu.inter ht) using 3,\n  rw [set.inter_left_comm (u ∩ s), set.inter_assoc, ← set.inter_assoc u u, set.inter_self]\nend\n\n@[simp] lemma restrict_add_restrict_compl (hs : measurable_set s) :\n  μ.restrict s + μ.restrict sᶜ = μ :=\nby rw [← restrict_union (@disjoint_compl_right (set α) _ _) hs hs.compl,\n    union_compl_self, restrict_univ]\n\n@[simp] lemma restrict_compl_add_restrict (hs : measurable_set s) :\n  μ.restrict sᶜ + μ.restrict s = μ :=\nby rw [add_comm, restrict_add_restrict_compl hs]\n\nlemma restrict_union_le (s s' : set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=\nbegin\n  intros t ht,\n  suffices : μ (t ∩ s ∪ t ∩ s') ≤ μ (t ∩ s) + μ (t ∩ s'),\n    by simpa [ht, inter_union_distrib_left],\n  apply measure_union_le\nend\n\nlemma restrict_Union_apply [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))\n  (hm : ∀ i, measurable_set (s i)) {t : set α} (ht : measurable_set t) :\n  μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=\nbegin\n  simp only [restrict_apply, ht, inter_Union],\n  exact measure_Union (λ i j hij, (hd i j hij).mono inf_le_right inf_le_right)\n    (λ i, ht.inter (hm i))\nend\n\nlemma restrict_Union_apply_eq_supr [encodable ι] {s : ι → set α}\n  (hm : ∀ i, measurable_set (s i)) (hd : directed (⊆) s) {t : set α} (ht : measurable_set t) :\n  μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t :=\nbegin\n  simp only [restrict_apply ht, inter_Union],\n  rw [measure_Union_eq_supr],\n  exacts [λ i, ht.inter (hm i), hd.mono_comp _ (λ s₁ s₂, inter_subset_inter_right _)]\nend\n\nlemma restrict_map {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :\n  (map f μ).restrict s = map f (μ.restrict $ f ⁻¹' s) :=\next $ λ t ht, by simp [*, hf ht]\n\nlemma map_comap_subtype_coe (hs : measurable_set s) :\n  (map (coe : s → α)).comp (comap coe) = restrictₗ s :=\nlinear_map.ext $ λ μ, ext $ λ t ht,\nby rw [restrictₗ_apply, restrict_apply ht, linear_map.comp_apply,\n  map_apply measurable_subtype_coe ht,\n  comap_apply (coe : s → α) subtype.val_injective (λ _, hs.subtype_image) _\n    (measurable_subtype_coe ht), subtype.image_preimage_coe]\n\n/-- Restriction of a measure to a subset is monotone both in set and in measure. -/\n@[mono] lemma restrict_mono ⦃s s' : set α⦄ (hs : s ⊆ s') ⦃μ ν : measure α⦄ (hμν : μ ≤ ν) :\n  μ.restrict s ≤ ν.restrict s' :=\nassume t ht,\ncalc μ.restrict s t = μ (t ∩ s) : restrict_apply ht\n... ≤ μ (t ∩ s') : measure_mono $ inter_subset_inter_right _ hs\n... ≤ ν (t ∩ s') : le_iff'.1 hμν (t ∩ s')\n... = ν.restrict s' t : (restrict_apply ht).symm\n\nlemma restrict_le_self : μ.restrict s ≤ μ :=\nassume t ht,\ncalc μ.restrict s t = μ (t ∩ s) : restrict_apply ht\n... ≤ μ t : measure_mono $ inter_subset_left t s\n\nlemma restrict_congr_meas (hs : measurable_set s) :\n  μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, measurable_set t → μ t = ν t :=\n⟨λ H t hts ht,\n   by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht],\n λ H, ext $ λ t ht,\n   by rw [restrict_apply ht, restrict_apply ht, H _ (inter_subset_right _ _) (ht.inter hs)]⟩\n\nlemma restrict_congr_mono (hs : s ⊆ t) (hm : measurable_set s) (h : μ.restrict t = ν.restrict t) :\n  μ.restrict s = ν.restrict s :=\nby rw [← inter_eq_self_of_subset_left hs, ← restrict_restrict hm, h, restrict_restrict hm]\n\n/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all\nmeasurable subsets of `s ∪ t`. -/\nlemma restrict_union_congr (hsm : measurable_set s) (htm : measurable_set t) :\n  μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔\n    μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t :=\nbegin\n  refine ⟨λ h, ⟨restrict_congr_mono (subset_union_left _ _) hsm h,\n    restrict_congr_mono (subset_union_right _ _) htm h⟩, _⟩,\n  simp only [restrict_congr_meas, hsm, htm, hsm.union htm],\n  rintros ⟨hs, ht⟩ u hu hum,\n  rw [measure_eq_inter_diff hum hsm, measure_eq_inter_diff hum hsm,\n    hs _ (inter_subset_right _ _) (hum.inter hsm),\n    ht _ (diff_subset_iff.2 hu) (hum.diff hsm)]\nend\n\nlemma restrict_finset_bUnion_congr {s : finset ι} {t : ι → set α}\n  (htm : ∀ i ∈ s, measurable_set (t i)) :\n  μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔\n    ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) :=\nbegin\n  induction s using finset.induction_on with i s hi hs, { simp },\n  simp only [finset.mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at htm ⊢,\n  simp only [finset.set_bUnion_insert, ← hs htm.2],\n  exact restrict_union_congr htm.1 (s.measurable_set_bUnion htm.2)\nend\n\nlemma restrict_Union_congr [encodable ι] {s : ι → set α} (hm : ∀ i, measurable_set (s i)) :\n  μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔\n    ∀ i, μ.restrict (s i) = ν.restrict (s i) :=\nbegin\n  refine ⟨λ h i, restrict_congr_mono (subset_Union _ _) (hm i) h, λ h, _⟩,\n  ext1 t ht,\n  have M : ∀ t : finset ι, measurable_set (⋃ i ∈ t, s i) :=\n    λ t, t.measurable_set_bUnion (λ i _, hm i),\n  have D : directed (⊆) (λ t : finset ι, ⋃ i ∈ t, s i) :=\n    directed_of_sup (λ t₁ t₂ ht, bUnion_subset_bUnion_left ht),\n  rw [Union_eq_Union_finset],\n  simp only [restrict_Union_apply_eq_supr M D ht,\n    (restrict_finset_bUnion_congr (λ i hi, hm i)).2 (λ i hi, h i)],\nend\n\nlemma restrict_bUnion_congr {s : set ι} {t : ι → set α} (hc : countable s)\n  (htm : ∀ i ∈ s, measurable_set (t i)) :\n  μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔\n    ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) :=\nbegin\n  simp only [bUnion_eq_Union, set_coe.forall'] at htm ⊢,\n  haveI := hc.to_encodable,\n  exact restrict_Union_congr htm\nend\n\nlemma restrict_sUnion_congr {S : set (set α)} (hc : countable S) (hm : ∀ s ∈ S, measurable_set s) :\n  μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=\nby rw [sUnion_eq_bUnion, restrict_bUnion_congr hc hm]\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. -/\nlemma restrict_to_outer_measure_eq_to_outer_measure_restrict (h : measurable_set s) :\n    (μ.restrict s).to_outer_measure = outer_measure.restrict s μ.to_outer_measure :=\nby simp_rw [restrict, restrictₗ, lift_linear, linear_map.coe_mk, to_measure_to_outer_measure,\n  outer_measure.restrict_trim h, μ.trimmed]\n\n/-- This lemma shows that `Inf` and `restrict` commute for measures. -/\nlemma restrict_Inf_eq_Inf_restrict {m : set (measure α)} (hm : m.nonempty) (ht : measurable_set t) :\n  (Inf m).restrict t = Inf ((λ μ : measure α, μ.restrict t) '' m) :=\nbegin\n  ext1 s hs,\n  simp_rw [Inf_apply hs, restrict_apply hs, Inf_apply (measurable_set.inter hs ht), set.image_image,\n    restrict_to_outer_measure_eq_to_outer_measure_restrict ht, ← set.image_image _ to_outer_measure,\n    ← outer_measure.restrict_Inf_eq_Inf_restrict _ (hm.image _),\n    outer_measure.restrict_apply]\nend\n\n/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of\nthe measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of\n`measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/\nlemma restrict_apply' (hs : measurable_set s) : μ.restrict s t = μ (t ∩ s) :=\nby rw [← coe_to_outer_measure, measure.restrict_to_outer_measure_eq_to_outer_measure_restrict hs,\n      outer_measure.restrict_apply s t _, coe_to_outer_measure]\n\nlemma restrict_eq_self_of_subset_of_measurable (hs : measurable_set s) (t_subset : t ⊆ s) :\n  μ.restrict s t = μ t :=\nby rw [restrict_apply' hs, set.inter_eq_self_of_subset_left t_subset]\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`). -/\nlemma ext_iff_of_Union_eq_univ [encodable ι] {s : ι → set α}\n  (hm : ∀ i, measurable_set (s i)) (hs : (⋃ i, s i) = univ) :\n  μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) :=\nby rw [← restrict_Union_congr hm, hs, restrict_univ, restrict_univ]\n\nalias ext_iff_of_Union_eq_univ ↔ _ measure_theory.measure.ext_of_Union_eq_univ\n\n/-- Two measures are equal if they have equal restrictions on a spanning collection of sets\n  (formulated using `bUnion`). -/\nlemma ext_iff_of_bUnion_eq_univ {S : set ι} {s : ι → set α} (hc : countable S)\n  (hm : ∀ i ∈ S, measurable_set (s i)) (hs : (⋃ i ∈ S, s i) = univ) :\n  μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) :=\nby rw [← restrict_bUnion_congr hc hm, hs, restrict_univ, restrict_univ]\n\nalias ext_iff_of_bUnion_eq_univ ↔ _ measure_theory.measure.ext_of_bUnion_eq_univ\n\n/-- Two measures are equal if they have equal restrictions on a spanning collection of sets\n  (formulated using `sUnion`). -/\nlemma ext_iff_of_sUnion_eq_univ {S : set (set α)} (hc : countable S)\n  (hm : ∀ s ∈ S, measurable_set s) (hs : (⋃₀ S) = univ) :\n  μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=\next_iff_of_bUnion_eq_univ hc hm $ by rwa ← sUnion_eq_bUnion\n\nalias ext_iff_of_sUnion_eq_univ ↔ _ measure_theory.measure.ext_of_sUnion_eq_univ\n\nlemma ext_of_generate_from_of_cover {S T : set (set α)}\n  (h_gen : ‹_› = generate_from S) (hc : countable T)\n  (h_inter : is_pi_system S)\n  (hm : ∀ t ∈ T, measurable_set t) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t < ∞)\n  (ST_eq : ∀ (t ∈ T) (s ∈ S), μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) :\n  μ = ν :=\nbegin\n  refine ext_of_sUnion_eq_univ hc hm hU (λ t ht, _),\n  ext1 u hu,\n  simp only [restrict_apply hu],\n  refine induction_on_inter h_gen h_inter _ (ST_eq t ht) _ _ hu,\n  { simp only [set.empty_inter, measure_empty] },\n  { intros v hv hvt,\n    have := T_eq t ht,\n    rw [set.inter_comm] at hvt ⊢,\n    rwa [measure_eq_inter_diff (hm _ ht) hv, measure_eq_inter_diff (hm _ ht) hv, ← hvt,\n      ennreal.add_right_inj] at this,\n    exact (measure_mono $ set.inter_subset_left _ _).trans_lt (htop t ht) },\n  { intros f hfd hfm h_eq,\n    have : pairwise (disjoint on λ n, f n ∩ t) :=\n      λ m n hmn, (hfd m n hmn).mono (inter_subset_left _ _) (inter_subset_left _ _),\n    simp only [Union_inter, measure_Union this (λ n, (hfm n).inter (hm t ht)), h_eq] }\nend\n\n/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,\n  and they are both finite on a increasing spanning sequence of sets in the π-system.\n  This lemma is formulated using `sUnion`. -/\nlemma ext_of_generate_from_of_cover_subset {S T : set (set α)}\n  (h_gen : ‹_› = generate_from S)\n  (h_inter : is_pi_system S)\n  (h_sub : T ⊆ S) (hc : countable T) (hU : ⋃₀ T = univ) (htop : ∀ s ∈ T, μ s < ∞)\n  (h_eq : ∀ s ∈ S, μ s = ν s) :\n  μ = ν :=\nbegin\n  refine ext_of_generate_from_of_cover h_gen hc h_inter _ hU htop _ (λ t ht, h_eq t (h_sub ht)),\n  { intros t ht, rw [h_gen], exact generate_measurable.basic _ (h_sub ht) },\n  { intros t ht s hs, cases (s ∩ t).eq_empty_or_nonempty with H H,\n    { simp only [H, measure_empty] },\n    { exact h_eq _ (h_inter _ _ hs (h_sub ht) H) } }\nend\n\n/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,\n  and they are both finite on a increasing spanning sequence of sets in the π-system.\n  This lemma is formulated using `Union`.\n  `finite_spanning_sets_in.ext` is a reformulation of this lemma. -/\nlemma ext_of_generate_from_of_Union (C : set (set α)) (B : ℕ → set α)\n  (hA : ‹_› = generate_from C) (hC : is_pi_system C) (h1B : (⋃ i, B i) = univ)\n  (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) < ∞) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=\nbegin\n  refine ext_of_generate_from_of_cover_subset hA hC _ (countable_range B) h1B _ h_eq,\n  { rintro _ ⟨i, rfl⟩, apply h2B },\n  { rintro _ ⟨i, rfl⟩, apply hμB }\nend\n\n/-- The dirac measure. -/\ndef dirac (a : α) : measure α :=\n(outer_measure.dirac a).to_measure (by simp)\n\nlemma le_dirac_apply {a} : s.indicator 1 a ≤ dirac a s :=\nouter_measure.dirac_apply a s ▸ le_to_measure_apply _ _ _\n\n@[simp] lemma dirac_apply' (a : α) (hs : measurable_set s) :\n  dirac a s = s.indicator 1 a :=\nto_measure_apply _ _ hs\n\n@[simp] lemma dirac_apply_of_mem {a : α} (h : a ∈ s) :\n  dirac a s = 1 :=\nbegin\n  have : ∀ t : set α, a ∈ t → t.indicator (1 : α → ℝ≥0∞) a = 1,\n    from λ t ht, indicator_of_mem ht 1,\n  refine le_antisymm (this univ trivial ▸ _) (this s h ▸ le_dirac_apply),\n  rw [← dirac_apply' a measurable_set.univ],\n  exact measure_mono (subset_univ s)\nend\n\n@[simp] lemma dirac_apply [measurable_singleton_class α] (a : α) (s : set α) :\n  dirac a s = s.indicator 1 a :=\nbegin\n  by_cases h : a ∈ s, by rw [dirac_apply_of_mem h, indicator_of_mem h, pi.one_apply],\n  rw [indicator_of_not_mem h, ← nonpos_iff_eq_zero],\n  calc dirac a s ≤ dirac a {a}ᶜ : measure_mono (subset_compl_comm.1 $ singleton_subset_iff.2 h)\n             ... = 0            : by simp [dirac_apply' _ (measurable_set_singleton _).compl]\nend\n\nlemma map_dirac {f : α → β} (hf : measurable f) (a : α) :\n  map f (dirac a) = dirac (f a) :=\next $ assume s hs, by simp [hs, map_apply hf hs, hf hs, indicator_apply]\n\n/-- Sum of an indexed family of measures. -/\ndef sum (f : ι → measure α) : measure α :=\n(outer_measure.sum (λ i, (f i).to_outer_measure)).to_measure $\nle_trans\n  (by exact le_infi (λ i, le_to_outer_measure_caratheodory _))\n  (outer_measure.le_sum_caratheodory _)\n\nlemma le_sum_apply (f : ι → measure α) (s : set α) :\n  (∑' i, f i s) ≤ sum f s :=\nle_to_measure_apply _ _ _\n\n@[simp] lemma sum_apply (f : ι → measure α) {s : set α} (hs : measurable_set s) :\n  sum f s = ∑' i, f i s :=\nto_measure_apply _ _ hs\n\nlemma le_sum (μ : ι → measure α) (i : ι) : μ i ≤ sum μ :=\nλ s hs, by simp only [sum_apply μ hs, ennreal.le_tsum i]\n\nlemma restrict_Union [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))\n  (hm : ∀ i, measurable_set (s i)) :\n  μ.restrict (⋃ i, s i) = sum (λ i, μ.restrict (s i)) :=\next $ λ t ht, by simp only [sum_apply _ ht, restrict_Union_apply hd hm ht]\n\nlemma restrict_Union_le [encodable ι] {s : ι → set α} :\n  μ.restrict (⋃ i, s i) ≤ sum (λ i, μ.restrict (s i)) :=\nbegin\n  intros t ht,\n  suffices : μ (⋃ i, t ∩ s i) ≤ ∑' i, μ (t ∩ s i), by simpa [ht, inter_Union],\n  apply measure_Union_le\nend\n\n@[simp] lemma sum_bool (f : bool → measure α) : sum f = f tt + f ff :=\next $ λ s hs, by simp [hs, tsum_fintype]\n\n@[simp] lemma sum_cond (μ ν : measure α) : sum (λ b, cond b μ ν) = μ + ν :=\nsum_bool _\n\n@[simp] lemma restrict_sum (μ : ι → measure α) {s : set α} (hs : measurable_set s) :\n  (sum μ).restrict s = sum (λ i, (μ i).restrict s) :=\next $ λ t ht, by simp only [sum_apply, restrict_apply, ht, ht.inter hs]\n\n/-- Counting measure on any measurable space. -/\ndef count : measure α := sum dirac\n\nlemma le_count_apply : (∑' i : s, 1 : ℝ≥0∞) ≤ count s :=\ncalc (∑' i : s, 1 : ℝ≥0∞) = ∑' i, indicator s 1 i : tsum_subtype s 1\n... ≤ ∑' i, dirac i s : ennreal.tsum_le_tsum $ λ x, le_dirac_apply\n... ≤ count s : le_sum_apply _ _\n\nlemma count_apply (hs : measurable_set s) : count s = ∑' i : s, 1 :=\nby simp only [count, sum_apply, hs, dirac_apply', ← tsum_subtype s 1, pi.one_apply]\n\n@[simp] lemma count_apply_finset [measurable_singleton_class α] (s : finset α) :\n  count (↑s : set α) = s.card :=\ncalc count (↑s : set α) = ∑' i : (↑s : set α), 1 : count_apply s.measurable_set\n                    ... = ∑ i in s, 1 : s.tsum_subtype 1\n                    ... = s.card : by simp\n\nlemma count_apply_finite [measurable_singleton_class α] (s : set α) (hs : finite s) :\n  count s = hs.to_finset.card :=\nby rw [← count_apply_finset, finite.coe_to_finset]\n\n/-- `count` measure evaluates to infinity at infinite sets. -/\nlemma count_apply_infinite (hs : s.infinite) : count s = ∞ :=\nbegin\n  refine top_unique (le_of_tendsto' ennreal.tendsto_nat_nhds_top $ λ n, _),\n  rcases hs.exists_subset_card_eq n with ⟨t, ht, rfl⟩,\n  calc (t.card : ℝ≥0∞) = ∑ i in t, 1 : by simp\n  ... = ∑' i : (t : set α), 1 : (t.tsum_subtype 1).symm\n  ... ≤ count (t : set α) : le_count_apply\n  ... ≤ count s : measure_mono ht\nend\n\n@[simp] lemma count_apply_eq_top [measurable_singleton_class α] : count s = ∞ ↔ s.infinite :=\nbegin\n  by_cases hs : s.finite,\n  { simp [set.infinite, hs, count_apply_finite] },\n  { change s.infinite at hs,\n    simp [hs, count_apply_infinite] }\nend\n\n@[simp] lemma count_apply_lt_top [measurable_singleton_class α] : count s < ∞ ↔ s.finite :=\ncalc count s < ∞ ↔ count s ≠ ∞ : lt_top_iff_ne_top\n             ... ↔ ¬s.infinite : not_congr count_apply_eq_top\n             ... ↔ s.finite    : not_not\n\n/-! ### Absolute continuity -/\n\n/-- We say that `μ` is absolutely continuous with respect to `ν`, or that `μ` is dominated by `ν`,\n  if `ν(A) = 0` implies that `μ(A) = 0`. -/\ndef absolutely_continuous (μ ν : measure α) : Prop :=\n∀ ⦃s : set α⦄, ν s = 0 → μ s = 0\n\ninfix ` ≪ `:50 := absolutely_continuous\n\nlemma absolutely_continuous_of_le (h : μ ≤ ν) : μ ≪ ν :=\nλ s hs, nonpos_iff_eq_zero.1 $ hs ▸ le_iff'.1 h s\n\nalias absolutely_continuous_of_le ← has_le.le.absolutely_continuous\n\nlemma absolutely_continuous_of_eq (h : μ = ν) : μ ≪ ν :=\nh.le.absolutely_continuous\n\nalias absolutely_continuous_of_eq ← eq.absolutely_continuous\n\nnamespace absolutely_continuous\n\nlemma mk (h : ∀ ⦃s : set α⦄, measurable_set s → ν s = 0 → μ s = 0) : μ ≪ ν :=\nbegin\n  intros s hs,\n  rcases exists_measurable_superset_of_null hs with ⟨t, h1t, h2t, h3t⟩,\n  exact measure_mono_null h1t (h h2t h3t),\nend\n\n@[refl] protected lemma refl (μ : measure α) : μ ≪ μ := rfl.absolutely_continuous\n\nprotected lemma rfl : μ ≪ μ := λ s hs, hs\n\n@[trans] protected lemma trans (h1 : μ₁ ≪ μ₂) (h2 : μ₂ ≪ μ₃) : μ₁ ≪ μ₃ :=\nλ s hs, h1 $ h2 hs\n\n@[mono] protected lemma map (h : μ ≪ ν) (f : α → β) : map f μ ≪ map f ν :=\nif hf : measurable f then absolutely_continuous.mk $ λ s hs, by simpa [hf, hs] using @h _\nelse by simp only [map_of_not_measurable hf]\n\nend absolutely_continuous\n\nlemma ae_le_iff_absolutely_continuous : μ.ae ≤ ν.ae ↔ μ ≪ ν :=\n⟨λ h s, by { rw [measure_zero_iff_ae_nmem, measure_zero_iff_ae_nmem], exact λ hs, h hs },\n  λ h s hs, h hs⟩\n\nalias ae_le_iff_absolutely_continuous ↔ has_le.le.absolutely_continuous_of_ae\n  measure_theory.measure.absolutely_continuous.ae_le\nalias absolutely_continuous.ae_le ← ae_mono'\n\nlemma absolutely_continuous.ae_eq (h : μ ≪ ν) {f g : α → δ} (h' : f =ᵐ[ν] g) : f =ᵐ[μ] g :=\nh.ae_le h'\n\n/-! ### Quasi measure preserving maps (a.k.a. non-singular maps) -/\n\n/-- A map `f : α → β` is said to be *quasi measure preserving* (a.k.a. non-singular) w.r.t. measures\n`μa` and `μb` if it is measurable and `μb s = 0` implies `μa (f ⁻¹' s) = 0`. -/\n@[protect_proj]\nstructure quasi_measure_preserving (f : α → β) (μa : measure α . volume_tac)\n  (μb : measure β . volume_tac) : Prop :=\n(measurable : measurable f)\n(absolutely_continuous : map f μa ≪ μb)\n\nnamespace quasi_measure_preserving\n\nprotected lemma id (μ : measure α) : quasi_measure_preserving id μ μ :=\n⟨measurable_id, map_id.absolutely_continuous⟩\n\nvariables {μa μa' : measure α} {μb μb' : measure β} {μc : measure γ} {f : α → β}\n\nlemma mono_left (h : quasi_measure_preserving f μa μb)\n  (ha : μa' ≪ μa) : quasi_measure_preserving f μa' μb :=\n⟨h.1, (ha.map f).trans h.2⟩\n\nlemma mono_right (h : quasi_measure_preserving f μa μb)\n  (ha : μb ≪ μb') : quasi_measure_preserving f μa μb' :=\n⟨h.1, h.2.trans ha⟩\n\n@[mono] lemma mono (ha : μa' ≪ μa) (hb : μb ≪ μb') (h : quasi_measure_preserving f μa μb) :\n  quasi_measure_preserving f μa' μb' :=\n(h.mono_left ha).mono_right hb\n\nprotected lemma comp {g : β → γ} {f : α → β} (hg : quasi_measure_preserving g μb μc)\n  (hf : quasi_measure_preserving f μa μb) :\n  quasi_measure_preserving (g ∘ f) μa μc :=\n⟨hg.measurable.comp hf.measurable, by { rw ← map_map hg.1 hf.1, exact (hf.2.map g).trans hg.2 }⟩\n\nprotected lemma iterate {f : α → α} (hf : quasi_measure_preserving f μa μa) :\n  ∀ n, quasi_measure_preserving (f^[n]) μa μa\n| 0 := quasi_measure_preserving.id μa\n| (n + 1) := (iterate n).comp hf\n\nlemma ae_map_le (h : quasi_measure_preserving f μa μb) : (map f μa).ae ≤ μb.ae :=\nh.2.ae_le\n\nlemma tendsto_ae (h : quasi_measure_preserving f μa μb) : tendsto f μa.ae μb.ae :=\n(tendsto_ae_map h.1).mono_right h.ae_map_le\n\nlemma ae (h : quasi_measure_preserving f μa μb) {p : β → Prop} (hg : ∀ᵐ x ∂μb, p x) :\n  ∀ᵐ x ∂μa, p (f x) :=\nh.tendsto_ae hg\n\nlemma ae_eq (h : quasi_measure_preserving f μa μb) {g₁ g₂ : β → δ} (hg : g₁ =ᵐ[μb] g₂) :\n  g₁ ∘ f =ᵐ[μa] g₂ ∘ f :=\nh.ae hg\n\nend quasi_measure_preserving\n\n/-! ### The `cofinite` filter -/\n\n/-- The filter of sets `s` such that `sᶜ` has finite measure. -/\ndef cofinite (μ : measure α) : filter α :=\n{ sets := {s | μ sᶜ < ∞},\n  univ_sets := by simp,\n  inter_sets := λ s t hs ht, by { simp only [compl_inter, mem_set_of_eq],\n    calc μ (sᶜ ∪ tᶜ) ≤ μ sᶜ + μ tᶜ : measure_union_le _ _\n                ... < ∞ : ennreal.add_lt_top.2 ⟨hs, ht⟩ },\n  sets_of_superset := λ s t hs hst, lt_of_le_of_lt (measure_mono $ compl_subset_compl.2 hst) hs }\n\nlemma mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := iff.rfl\n\nlemma compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ :=\nby rw [mem_cofinite, compl_compl]\n\nlemma eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ {x | ¬p x} < ∞ := iff.rfl\n\nend measure\nopen measure\n\n@[simp] lemma ae_eq_bot : μ.ae = ⊥ ↔ μ = 0 :=\nby rw [← empty_in_sets_eq_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]\n\n@[simp] lemma ae_ne_bot : μ.ae.ne_bot ↔ μ ≠ 0 :=\nne_bot_iff.trans (not_congr ae_eq_bot)\n\n@[simp] lemma ae_zero : (0 : measure α).ae = ⊥ := ae_eq_bot.2 rfl\n\n@[mono] lemma ae_mono {μ ν : measure α} (h : μ ≤ ν) : μ.ae ≤ ν.ae :=\nh.absolutely_continuous.ae_le\n\nlemma mem_ae_map_iff {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :\n  s ∈ (map f μ).ae ↔ (f ⁻¹' s) ∈ μ.ae :=\nby simp only [mem_ae_iff, map_apply hf hs.compl, preimage_compl]\n\nlemma mem_ae_of_mem_ae_map {f : α → β} (hf : measurable f) {s : set β} (hs : s ∈ (map f μ).ae) :\n  f ⁻¹' s ∈ μ.ae :=\nbegin\n  apply le_antisymm _ bot_le,\n  calc μ (f ⁻¹' sᶜ) ≤ (map f μ) sᶜ : le_map_apply hf sᶜ\n  ... = 0 : hs\nend\n\nlemma ae_map_iff {f : α → β} (hf : measurable f) {p : β → Prop} (hp : measurable_set {x | p x}) :\n  (∀ᵐ y ∂ (map f μ), p y) ↔ ∀ᵐ x ∂ μ, p (f x) :=\nmem_ae_map_iff hf hp\n\nlemma ae_of_ae_map {f : α → β} (hf : measurable f) {p : β → Prop} (h : ∀ᵐ y ∂ (map f μ), p y) :\n  ∀ᵐ x ∂ μ, p (f x) :=\nmem_ae_of_mem_ae_map hf h\n\nlemma ae_map_mem_range (f : α → β) (hf : measurable_set (range f)) (μ : measure α) :\n  ∀ᵐ x ∂(map f μ), x ∈ range f :=\nbegin\n  by_cases h : measurable f,\n  { change range f ∈ (map f μ).ae,\n    rw mem_ae_map_iff h hf,\n    apply eventually_of_forall,\n    exact mem_range_self },\n  { simp [map_of_not_measurable h] }\nend\n\nlemma ae_restrict_iff {p : α → Prop} (hp : measurable_set {x | p x}) :\n  (∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=\nbegin\n  simp only [ae_iff, ← compl_set_of, restrict_apply hp.compl],\n  congr' with x, simp [and_comm]\nend\n\nlemma ae_imp_of_ae_restrict {s : set α} {p : α → Prop} (h : ∀ᵐ x ∂(μ.restrict s), p x) :\n  ∀ᵐ x ∂μ, x ∈ s → p x :=\nbegin\n  simp only [ae_iff] at h ⊢,\n  simpa [set_of_and, inter_comm] using measure_inter_eq_zero_of_restrict h\nend\n\nlemma ae_restrict_iff' {s : set α} {p : α → Prop} (hp : measurable_set s) :\n  (∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=\nbegin\n  simp only [ae_iff, ← compl_set_of, restrict_apply_eq_zero' hp],\n  congr' with x, simp [and_comm]\nend\n\nlemma ae_restrict_of_ae {s : set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) :\n  (∀ᵐ x ∂(μ.restrict s), p x) :=\neventually.filter_mono (ae_mono measure.restrict_le_self) h\n\nlemma ae_restrict_of_ae_restrict_of_subset {s t : set α} {p : α → Prop} (hst : s ⊆ t)\n  (h : ∀ᵐ x ∂(μ.restrict t), p x) :\n  (∀ᵐ x ∂(μ.restrict s), p x) :=\nh.filter_mono (ae_mono $ measure.restrict_mono hst (le_refl μ))\n\nlemma ae_smul_measure {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) (c : ℝ≥0∞) : ∀ᵐ x ∂(c • μ), p x :=\nae_iff.2 $ by rw [smul_apply, ae_iff.1 h, mul_zero]\n\nlemma ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) :\n  (∀ᵐ x ∂(c • μ), p x) ↔ ∀ᵐ x ∂μ, p x :=\nby simp [ae_iff, hc]\n\nlemma ae_add_measure_iff {p : α → Prop} {ν} : (∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=\nadd_eq_zero_iff\n\nlemma ae_eq_comp' {ν : measure β} {f : α → β} {g g' : β → δ} (hf : measurable f)\n  (h : g =ᵐ[ν] g') (h2 : map f μ ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=\n(quasi_measure_preserving.mk hf h2).ae_eq h\n\nlemma ae_eq_comp {f : α → β} {g g' : β → δ} (hf : measurable f)\n  (h : g =ᵐ[measure.map f μ] g') : g ∘ f =ᵐ[μ] g' ∘ f :=\nae_eq_comp' hf h absolutely_continuous.rfl\n\nlemma le_ae_restrict : μ.ae ⊓ 𝓟 s ≤ (μ.restrict s).ae :=\nλ s hs, eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)\n\n@[simp] lemma ae_restrict_eq (hs : measurable_set s) : (μ.restrict s).ae = μ.ae ⊓ 𝓟 s :=\nbegin\n  ext t,\n  simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_set_of,\n    not_imp, and_comm (_ ∈ s)],\n  refl\nend\n\n@[simp] lemma ae_restrict_eq_bot {s} : (μ.restrict s).ae = ⊥ ↔ μ s = 0 :=\nae_eq_bot.trans restrict_eq_zero\n\n@[simp] lemma ae_restrict_ne_bot {s} : (μ.restrict s).ae.ne_bot ↔ 0 < μ s :=\nne_bot_iff.trans $ (not_congr ae_restrict_eq_bot).trans pos_iff_ne_zero.symm\n\nlemma self_mem_ae_restrict {s} (hs : measurable_set s) : s ∈ (μ.restrict s).ae :=\nby simp only [ae_restrict_eq hs, exists_prop, mem_principal_sets, mem_inf_sets];\n  exact ⟨_, univ_mem_sets, s, by rw [univ_inter, and_self]⟩\n\n/-- A version of the Borel-Cantelli lemma: if `sᵢ` is a sequence of measurable sets such that\n`∑ μ sᵢ` exists, then for almost all `x`, `x` does not belong to almost all `sᵢ`. -/\nlemma ae_eventually_not_mem {s : ℕ → set α} (hs : ∀ i, measurable_set (s i))\n  (hs' : ∑' i, μ (s i) ≠ ∞) : ∀ᵐ x ∂ μ, ∀ᶠ n in at_top, x ∉ s n :=\nbegin\n  refine measure_mono_null _ (measure_limsup_eq_zero hs hs'),\n  rw ←set.le_eq_subset,\n  refine le_Inf (λ t ht x hx, _),\n  simp only [le_eq_subset, not_exists, eventually_map, exists_prop, ge_iff_le, mem_set_of_eq,\n    eventually_at_top, mem_compl_eq, not_forall, not_not_mem] at hx ht,\n  rcases ht with ⟨i, hi⟩,\n  rcases hx i with ⟨j, ⟨hj, hj'⟩⟩,\n  exact hi j hj hj'\nend\n\nlemma mem_ae_dirac_iff {a : α} (hs : measurable_set s) : s ∈ (dirac a).ae ↔ a ∈ s :=\nby by_cases a ∈ s; simp [mem_ae_iff, dirac_apply', hs.compl, indicator_apply, *]\n\nlemma ae_dirac_iff {a : α} {p : α → Prop} (hp : measurable_set {x | p x}) :\n  (∀ᵐ x ∂(dirac a), p x) ↔ p a :=\nmem_ae_dirac_iff hp\n\n@[simp] lemma ae_dirac_eq [measurable_singleton_class α] (a : α) : (dirac a).ae = pure a :=\nby { ext s, simp [mem_ae_iff, imp_false] }\n\nlemma ae_eq_dirac' [measurable_singleton_class β] {a : α} {f : α → β} (hf : measurable f) :\n  f =ᵐ[dirac a] const α (f a) :=\n(ae_dirac_iff $ show measurable_set (f ⁻¹' {f a}), from hf $ measurable_set_singleton _).2 rfl\n\nlemma ae_eq_dirac [measurable_singleton_class α] {a : α} (f : α → δ) :\n  f =ᵐ[dirac a] const α (f a) :=\nby simp [filter.eventually_eq]\n\nlemma restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=\nbegin\n  intros u hu,\n  simp only [restrict_apply hu],\n  exact measure_mono_ae (h.mono $ λ x hx, and.imp id hx)\nend\n\nlemma restrict_congr_set (H : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=\nle_antisymm (restrict_mono_ae H.le) (restrict_mono_ae H.symm.le)\n\n/-- A measure `μ` is called a probability measure if `μ univ = 1`. -/\nclass probability_measure (μ : measure α) : Prop := (measure_univ : μ univ = 1)\n\ninstance measure.dirac.probability_measure {x : α} : probability_measure (dirac x) :=\n⟨dirac_apply_of_mem $ mem_univ x⟩\n\n/-- A measure `μ` is called finite if `μ univ < ∞`. -/\nclass finite_measure (μ : measure α) : Prop := (measure_univ_lt_top : μ univ < ∞)\n\ninstance restrict.finite_measure (μ : measure α) [hs : fact (μ s < ∞)] :\n  finite_measure (μ.restrict s) :=\n⟨by simp [hs.elim]⟩\n\n/-- Measure `μ` *has no atoms* if the measure of each singleton is zero.\n\nNB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure,\nthere exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`,\nthe converse is not true. -/\nclass has_no_atoms (μ : measure α) : Prop :=\n(measure_singleton : ∀ x, μ {x} = 0)\n\nexport probability_measure (measure_univ) has_no_atoms (measure_singleton)\n\nattribute [simp] measure_singleton\n\nlemma measure_lt_top (μ : measure α) [finite_measure μ] (s : set α) : μ s < ∞ :=\n(measure_mono (subset_univ s)).trans_lt finite_measure.measure_univ_lt_top\n\nlemma measure_ne_top (μ : measure α) [finite_measure μ] (s : set α) : μ s ≠ ∞ :=\nne_of_lt (measure_lt_top μ s)\n\n/-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/\ndef measure_univ_nnreal (μ : measure α) : ℝ≥0 := (μ univ).to_nnreal\n\n@[simp] lemma coe_measure_univ_nnreal (μ : measure α) [finite_measure μ] :\n  ↑(measure_univ_nnreal μ) = μ univ :=\nennreal.coe_to_nnreal (measure_ne_top μ univ)\n\ninstance finite_measure_zero : finite_measure (0 : measure α) := ⟨by simp⟩\n\n@[simp] lemma measure_univ_nnreal_zero : measure_univ_nnreal (0 : measure α) = 0 := rfl\n\n@[simp] lemma measure_univ_nnreal_eq_zero [finite_measure μ] : measure_univ_nnreal μ = 0 ↔ μ = 0 :=\nbegin\n  rw [← measure_theory.measure.measure_univ_eq_zero, ← coe_measure_univ_nnreal],\n  norm_cast\nend\n\nlemma measure_univ_nnreal_pos [finite_measure μ] (hμ : μ ≠ 0) : 0 < measure_univ_nnreal μ :=\nbegin\n  contrapose! hμ,\n  simpa [measure_univ_nnreal_eq_zero, le_zero_iff] using hμ\nend\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 μ is finite. -/\nlemma measure.le_of_add_le_add_left {μ ν₁ ν₂ : measure α} [finite_measure μ]\n  (A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ :=\nλ S B1, ennreal.le_of_add_le_add_left (measure_theory.measure_lt_top μ S) (A2 S B1)\n\n@[priority 100]\ninstance probability_measure.to_finite_measure (μ : measure α) [probability_measure μ] :\n  finite_measure μ :=\n⟨by simp only [measure_univ, ennreal.one_lt_top]⟩\n\nlemma probability_measure.ne_zero (μ : measure α) [probability_measure μ] : μ ≠ 0 :=\nmt measure_univ_eq_zero.2 $ by simp [measure_univ]\n\nsection no_atoms\n\nvariables [has_no_atoms μ]\n\nlemma measure_countable (h : countable s) : μ s = 0 :=\nbegin\n  rw [← bUnion_of_singleton s, ← nonpos_iff_eq_zero],\n  refine le_trans (measure_bUnion_le h _) _,\n  simp\nend\n\nlemma measure_finite (h : s.finite) : μ s = 0 :=\nmeasure_countable h.countable\n\nlemma measure_finset (s : finset α) : μ ↑s = 0 :=\nmeasure_finite s.finite_to_set\n\nlemma insert_ae_eq_self (a : α) (s : set α) :\n  (insert a s : set α) =ᵐ[μ] s :=\nunion_ae_eq_right.2 $ measure_mono_null (diff_subset _ _) (measure_singleton _)\n\nvariables [partial_order α] {a b : α}\n\nlemma Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a :=\nby simp only [← Iic_diff_right, diff_ae_eq_self,\n  measure_mono_null (set.inter_subset_right _ _) (measure_singleton a)]\n\nlemma Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a :=\n@Iio_ae_eq_Iic (order_dual α) ‹_› ‹_› _ _ _\n\nlemma Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b :=\n(ae_eq_refl _).inter Iio_ae_eq_Iic\n\nlemma Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b :=\nIoi_ae_eq_Ici.inter (ae_eq_refl _)\n\nlemma Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b :=\nIoi_ae_eq_Ici.inter (ae_eq_refl _)\n\nlemma Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b :=\nIoi_ae_eq_Ici.inter Iio_ae_eq_Iic\n\nlemma Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b :=\n(ae_eq_refl _).inter Iio_ae_eq_Iic\n\nlemma Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b :=\nIoo_ae_eq_Ico.symm.trans Ioo_ae_eq_Ioc\n\nend no_atoms\n\nlemma ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : set α) (hs_zero : μ s = 0) :\n  (λ x, ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g :=\nbegin\n  have h_ss : sᶜ ⊆ {a : α | ite (a ∈ s) (f a) (g a) = g a},\n    from λ x hx, by simp [(set.mem_compl_iff _ _).mp hx],\n  refine measure_mono_null _ hs_zero,\n  nth_rewrite 0 ←compl_compl s,\n  rwa set.compl_subset_compl,\nend\n\nlemma ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ) (s : set α) (hs_zero : μ sᶜ = 0) :\n  (λ x, ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f :=\nby { filter_upwards [hs_zero], intros, split_ifs, refl }\n\nnamespace measure\n\n/-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`.\nEquivalently, it is eventually finite at `s` in `f.lift' powerset`. -/\ndef finite_at_filter (μ : measure α) (f : filter α) : Prop := ∃ s ∈ f, μ s < ∞\n\nlemma finite_at_filter_of_finite (μ : measure α) [finite_measure μ] (f : filter α) :\n  μ.finite_at_filter f :=\n⟨univ, univ_mem_sets, measure_lt_top μ univ⟩\n\nlemma finite_at_filter.exists_mem_basis {μ : measure α} {f : filter α} (hμ : finite_at_filter μ f)\n  {p : ι → Prop} {s : ι → set α} (hf : f.has_basis p s) :\n  ∃ i (hi : p i), μ (s i) < ∞ :=\n(hf.exists_iff (λ s t hst ht, (measure_mono hst).trans_lt ht)).1 hμ\n\nlemma finite_at_bot (μ : measure α) : μ.finite_at_filter ⊥ :=\n⟨∅, mem_bot_sets, by simp only [measure_empty, with_top.zero_lt_top]⟩\n\n/-- `μ` 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: `μ` is σ-finite if there exists a sequence of\n  finite spanning sets in the collection of all measurable sets. -/\n@[protect_proj, nolint has_inhabited_instance]\nstructure finite_spanning_sets_in (μ : measure α) (C : set (set α)) :=\n(set : ℕ → set α)\n(set_mem : ∀ i, set i ∈ C)\n(finite : ∀ i, μ (set i) < ∞)\n(spanning : (⋃ i, set i) = univ)\n\nend measure\nopen measure\n\n/-- A measure `μ` is called σ-finite if there is a countable collection of sets\n  `{ A i | i ∈ ℕ }` such that `μ (A i) < ∞` and `⋃ i, A i = s`. -/\nclass sigma_finite (μ : measure α) : Prop :=\n(out' : nonempty (μ.finite_spanning_sets_in {s | measurable_set s}))\n\ntheorem sigma_finite_iff {μ : measure α} : sigma_finite μ ↔\n  nonempty (μ.finite_spanning_sets_in {s | measurable_set s}) :=\n⟨λ h, h.1, λ h, ⟨h⟩⟩\n\ntheorem sigma_finite.out {μ : measure α} (h : sigma_finite μ) :\n  nonempty (μ.finite_spanning_sets_in {s | measurable_set s}) := h.1\n\n/-- If `μ` is σ-finite it has finite spanning sets in the collection of all measurable sets. -/\ndef measure.to_finite_spanning_sets_in (μ : measure α) [h : sigma_finite μ] :\n  μ.finite_spanning_sets_in {s | measurable_set s} :=\nclassical.choice h.out\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 (μ : measure α) [sigma_finite μ] (i : ℕ) : set α :=\naccumulate μ.to_finite_spanning_sets_in.set i\n\nlemma monotone_spanning_sets (μ : measure α) [sigma_finite μ] :\n  monotone (spanning_sets μ) :=\nmonotone_accumulate\n\nlemma measurable_spanning_sets (μ : measure α) [sigma_finite μ] (i : ℕ) :\n  measurable_set (spanning_sets μ i) :=\nmeasurable_set.Union $ λ j, measurable_set.Union_Prop $\n  λ hij, μ.to_finite_spanning_sets_in.set_mem j\n\nlemma measure_spanning_sets_lt_top (μ : measure α) [sigma_finite μ] (i : ℕ) :\n  μ (spanning_sets μ i) < ∞ :=\nmeasure_bUnion_lt_top (finite_le_nat i) $ λ j _, μ.to_finite_spanning_sets_in.finite j\n\nlemma Union_spanning_sets (μ : measure α) [sigma_finite μ] :\n  (⋃ i : ℕ, spanning_sets μ i) = univ :=\nby simp_rw [spanning_sets, Union_accumulate, μ.to_finite_spanning_sets_in.spanning]\n\nlemma is_countably_spanning_spanning_sets (μ : measure α) [sigma_finite μ] :\n  is_countably_spanning (range (spanning_sets μ)) :=\n⟨spanning_sets μ, mem_range_self, Union_spanning_sets μ⟩\n\nnamespace measure\n\nlemma supr_restrict_spanning_sets [sigma_finite μ] (hs : measurable_set s) :\n  (⨆ i, μ.restrict (spanning_sets μ i) s) = μ s :=\nbegin\n  convert (restrict_Union_apply_eq_supr (measurable_spanning_sets μ) _ hs).symm,\n  { simp [Union_spanning_sets] },\n  { exact directed_of_sup (monotone_spanning_sets μ) }\nend\n\nnamespace finite_spanning_sets_in\n\nvariables {C D : set (set α)}\n\n/-- If `μ` has finite spanning sets in `C` and `C ⊆ D` then `μ` has finite spanning sets in `D`. -/\nprotected def mono (h : μ.finite_spanning_sets_in C) (hC : C ⊆ D) : μ.finite_spanning_sets_in D :=\n⟨h.set, λ i, hC (h.set_mem i), h.finite, h.spanning⟩\n\n/-- If `μ` has finite spanning sets in the collection of measurable sets `C`, then `μ` is σ-finite.\n-/\nprotected lemma sigma_finite (h : μ.finite_spanning_sets_in C) (hC : ∀ s ∈ C, measurable_set s) :\n  sigma_finite μ :=\n⟨⟨h.mono 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 lemma ext {ν : measure α} {C : set (set α)} (hA : ‹_› = generate_from C)\n  (hC : is_pi_system C) (h : μ.finite_spanning_sets_in C) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=\next_of_generate_from_of_Union C _ hA hC h.spanning h.set_mem h.finite h_eq\n\nprotected lemma is_countably_spanning (h : μ.finite_spanning_sets_in C) : is_countably_spanning C :=\n⟨_, h.set_mem, h.spanning⟩\n\nend finite_spanning_sets_in\n\nlemma sigma_finite_of_not_nonempty (μ : measure α) (hα : ¬ nonempty α) : sigma_finite μ :=\n⟨⟨⟨λ _, ∅, λ n, measurable_set.empty, λ n, by simp, by simp [eq_empty_of_not_nonempty hα univ]⟩⟩⟩\n\nlemma sigma_finite_of_countable {S : set (set α)} (hc : countable S)\n  (hμ : ∀ s ∈ S, μ s < ∞) (hU : ⋃₀ S = univ) :\n  sigma_finite μ :=\nbegin\n  obtain ⟨s, hμ, hs⟩ : ∃ s : ℕ → set α, (∀ n, μ (s n) < ∞) ∧ (⋃ n, s n) = univ,\n    from (exists_seq_cover_iff_countable ⟨∅, by simp⟩).2 ⟨S, hc, hμ, hU⟩,\n  refine ⟨⟨⟨λ n, to_measurable μ (s n), λ n, measurable_set_to_measurable _ _, by simpa, _⟩⟩⟩,\n  exact eq_univ_of_subset (Union_subset_Union $ λ n, subset_to_measurable μ (s n)) hs\nend\n\nend measure\n\n/-- Every finite measure is σ-finite. -/\n@[priority 100]\ninstance finite_measure.to_sigma_finite (μ : measure α) [finite_measure μ] : sigma_finite μ :=\n⟨⟨⟨λ _, univ, λ _, measurable_set.univ, λ _, measure_lt_top μ _, Union_const _⟩⟩⟩\n\ninstance restrict.sigma_finite (μ : measure α) [sigma_finite μ] (s : set α) :\n  sigma_finite (μ.restrict s) :=\nbegin\n  refine ⟨⟨⟨spanning_sets μ, measurable_spanning_sets μ, λ i, _, Union_spanning_sets μ⟩⟩⟩,\n  rw [restrict_apply (measurable_spanning_sets μ i)],\n  exact (measure_mono $ inter_subset_left _ _).trans_lt (measure_spanning_sets_lt_top μ i)\nend\n\ninstance sum.sigma_finite {ι} [fintype ι] (μ : ι → measure α) [∀ i, sigma_finite (μ i)] :\n  sigma_finite (sum μ) :=\nbegin\n  haveI : encodable ι := (encodable.trunc_encodable_of_fintype ι).out,\n  have : ∀ n, measurable_set (⋂ (i : ι), spanning_sets (μ i) n) :=\n    λ n, measurable_set.Inter (λ i, measurable_spanning_sets (μ i) n),\n  refine ⟨⟨⟨λ n, ⋂ i, spanning_sets (μ i) n, this, λ n, _, _⟩⟩⟩,\n  { rw [sum_apply _ (this n), tsum_fintype, ennreal.sum_lt_top_iff],\n    rintro i -,\n    exact (measure_mono $ Inter_subset _ i).trans_lt (measure_spanning_sets_lt_top (μ i) n) },\n  { rw [Union_Inter_of_monotone], simp_rw [Union_spanning_sets, Inter_univ],\n    exact λ i, monotone_spanning_sets (μ i), }\nend\n\ninstance add.sigma_finite (μ ν : measure α) [sigma_finite μ] [sigma_finite ν] :\n  sigma_finite (μ + ν) :=\nby { rw [← sum_cond], refine @sum.sigma_finite _ _ _ _ _ (bool.rec _ _); simpa }\n\nlemma sigma_finite.of_map (μ : measure α) {f : α → β} (hf : measurable f)\n  (h : sigma_finite (map f μ)) :\n  sigma_finite μ :=\n⟨⟨⟨λ n, f ⁻¹' (spanning_sets (map f μ) n),\n   λ n, hf $ measurable_spanning_sets _ _,\n   λ n, by simp only [← map_apply hf, measurable_spanning_sets, measure_spanning_sets_lt_top],\n   by rw [← preimage_Union, Union_spanning_sets, preimage_univ]⟩⟩⟩\n\n/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/\nclass locally_finite_measure [topological_space α] (μ : measure α) : Prop :=\n(finite_at_nhds : ∀ x, μ.finite_at_filter (𝓝 x))\n\n@[priority 100] -- see Note [lower instance priority]\ninstance finite_measure.to_locally_finite_measure [topological_space α] (μ : measure α)\n  [finite_measure μ] :\n  locally_finite_measure μ :=\n⟨λ x, finite_at_filter_of_finite _ _⟩\n\nlemma measure.finite_at_nhds [topological_space α] (μ : measure α)\n  [locally_finite_measure μ] (x : α) :\n  μ.finite_at_filter (𝓝 x) :=\nlocally_finite_measure.finite_at_nhds x\n\nlemma measure.smul_finite {α : Type*} [measurable_space α] (μ : measure α) [finite_measure μ]\n  {c : ℝ≥0∞} (hc : c < ∞) :\n  finite_measure (c • μ) :=\nbegin\n  refine ⟨_⟩,\n  rw measure.smul_apply,\n  exact ennreal.mul_lt_top hc (measure_lt_top μ set.univ),\nend\n\nlemma measure.exists_is_open_measure_lt_top [topological_space α] (μ : measure α)\n  [locally_finite_measure μ] (x : α) :\n  ∃ s : set α, x ∈ s ∧ is_open s ∧ μ s < ∞ :=\nby simpa only [exists_prop, and.assoc]\n  using (μ.finite_at_nhds x).exists_mem_basis (nhds_basis_opens x)\n\n@[priority 100] -- see Note [lower instance priority]\ninstance sigma_finite_of_locally_finite [topological_space α]\n  [topological_space.second_countable_topology α]\n  {μ : measure α} [locally_finite_measure μ] :\n  sigma_finite μ :=\nbegin\n  choose s hsx hsμ using μ.finite_at_nhds,\n  rcases topological_space.countable_cover_nhds hsx with ⟨t, htc, htU⟩,\n  refine measure.sigma_finite_of_countable (htc.image s) (ball_image_iff.2 $ λ x hx, hsμ x) _,\n  rwa sUnion_image\nend\n\n/-- If two finite measures give the same mass to the whole space and coincide on a π-system made\nof measurable sets, then they coincide on all sets in the σ-algebra generated by the π-system. -/\nlemma ext_on_measurable_space_of_generate_finite {α} (m₀ : measurable_space α)\n  {μ ν : measure α} [finite_measure μ]\n  (C : set (set α)) (hμν : ∀ s ∈ C, μ s = ν s) {m : measurable_space α}\n  (h : m ≤ m₀) (hA : m = measurable_space.generate_from C) (hC : is_pi_system C)\n  (h_univ : μ set.univ = ν set.univ) {s : set α} (hs : m.measurable_set' s) :\n  μ s = ν s :=\nbegin\n  haveI : @finite_measure _ m₀ ν := begin\n     constructor,\n     rw ← h_univ,\n     apply finite_measure.measure_univ_lt_top,\n  end,\n  refine induction_on_inter hA hC (by simp) hμν _ _ hs,\n  { intros t h1t h2t,\n    have h1t_ : @measurable_set α m₀ t, from h _ h1t,\n    rw [@measure_compl α m₀ μ t h1t_ (@measure_lt_top α m₀ μ _ t),\n      @measure_compl α m₀ ν t h1t_ (@measure_lt_top α m₀ ν _ t), h_univ, h2t], },\n  { intros f h1f h2f h3f,\n    have h2f_ : ∀ (i : ℕ), @measurable_set α m₀ (f i), from (λ i, h _ (h2f i)),\n    have h_Union : @measurable_set α m₀ (⋃ (i : ℕ), f i),from @measurable_set.Union α ℕ m₀ _ f h2f_,\n    simp [measure_Union, h_Union, h1f, h3f, h2f_], },\nend\n\n/-- Two finite measures are equal if they are equal on the π-system generating the σ-algebra\n  (and `univ`). -/\nlemma ext_of_generate_finite (C : set (set α)) (hA : _inst_1 = generate_from C)\n  (hC : is_pi_system C) {μ ν : measure α} [finite_measure μ]\n  (hμν : ∀ s ∈ C, μ s = ν s) (h_univ : μ univ = ν univ) :\n  μ = ν :=\nmeasure.ext (λ s hs,\n  ext_on_measurable_space_of_generate_finite _inst_1 C hμν (le_refl _inst_1) hA hC h_univ hs)\n\nnamespace measure\n\nnamespace finite_at_filter\n\nvariables {f g : filter α}\n\nlemma filter_mono (h : f ≤ g) : μ.finite_at_filter g → μ.finite_at_filter f :=\nλ ⟨s, hs, hμ⟩, ⟨s, h hs, hμ⟩\n\nlemma inf_of_left (h : μ.finite_at_filter f) : μ.finite_at_filter (f ⊓ g) :=\nh.filter_mono inf_le_left\n\nlemma inf_of_right (h : μ.finite_at_filter g) : μ.finite_at_filter (f ⊓ g) :=\nh.filter_mono inf_le_right\n\n@[simp] lemma inf_ae_iff : μ.finite_at_filter (f ⊓ μ.ae) ↔ μ.finite_at_filter f :=\nbegin\n  refine ⟨_, λ h, h.filter_mono inf_le_left⟩,\n  rintros ⟨s, ⟨t, ht, u, hu, hs⟩, hμ⟩,\n  suffices : μ t ≤ μ s, from ⟨t, ht, this.trans_lt hμ⟩,\n  exact measure_mono_ae (mem_sets_of_superset hu (λ x hu ht, hs ⟨ht, hu⟩))\nend\n\nalias inf_ae_iff ↔ measure_theory.measure.finite_at_filter.of_inf_ae _\n\nlemma filter_mono_ae (h : f ⊓ μ.ae ≤ g) (hg : μ.finite_at_filter g) : μ.finite_at_filter f :=\ninf_ae_iff.1 (hg.filter_mono h)\n\nprotected lemma measure_mono (h : μ ≤ ν) : ν.finite_at_filter f → μ.finite_at_filter f :=\nλ ⟨s, hs, hν⟩, ⟨s, hs, (measure.le_iff'.1 h s).trans_lt hν⟩\n\n@[mono] protected lemma mono (hf : f ≤ g) (hμ : μ ≤ ν) :\n  ν.finite_at_filter g → μ.finite_at_filter f :=\nλ h, (h.filter_mono hf).measure_mono hμ\n\nprotected lemma eventually (h : μ.finite_at_filter f) : ∀ᶠ s in f.lift' powerset, μ s < ∞ :=\n(eventually_lift'_powerset' $ λ s t hst ht, (measure_mono hst).trans_lt ht).2 h\n\nlemma filter_sup : μ.finite_at_filter f → μ.finite_at_filter g → μ.finite_at_filter (f ⊔ g) :=\nλ ⟨s, hsf, hsμ⟩ ⟨t, htg, htμ⟩,\n ⟨s ∪ t, union_mem_sup hsf htg, (measure_union_le s t).trans_lt (ennreal.add_lt_top.2 ⟨hsμ, htμ⟩)⟩\n\nend finite_at_filter\n\nlemma finite_at_nhds_within [topological_space α] (μ : measure α) [locally_finite_measure μ]\n  (x : α) (s : set α) :\n  μ.finite_at_filter (𝓝[s] x) :=\n(finite_at_nhds μ x).inf_of_left\n\n@[simp] lemma finite_at_principal : μ.finite_at_filter (𝓟 s) ↔ μ s < ∞ :=\n⟨λ ⟨t, ht, hμ⟩, (measure_mono ht).trans_lt hμ, λ h, ⟨s, mem_principal_self s, h⟩⟩\n\n/-! ### Subtraction of measures -/\n\n/-- The measure `μ - ν` is defined to be the least measure `τ` such that `μ ≤ τ + ν`.\nIt is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures.\nCompare with `ennreal.has_sub`.\nSpecifically, note that if you have `α = {1,2}`, and  `μ {1} = 2`, `μ {2} = 0`, and\n`ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and\n`ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/\nnoncomputable instance has_sub {α : Type*} [measurable_space α] : has_sub (measure α) :=\n⟨λ μ ν, Inf {τ | μ ≤ τ + ν} ⟩\n\nsection measure_sub\n\nlemma sub_def : μ - ν = Inf {d | μ ≤ d + ν} := rfl\n\nlemma sub_eq_zero_of_le (h : μ ≤ ν) : μ - ν = 0 :=\nbegin\n  rw [← nonpos_iff_eq_zero', measure.sub_def],\n  apply @Inf_le (measure α) _ _,\n  simp [h],\nend\n\n/-- This application lemma only works in special circumstances. Given knowledge of\nwhen `μ ≤ ν` and `ν ≤ μ`, a more general application lemma can be written. -/\nlemma sub_apply [finite_measure ν] (h₁ : measurable_set s) (h₂ : ν ≤ μ) : (μ - ν) s = μ s - ν s :=\nbegin\n  -- We begin by defining `measure_sub`, which will be equal to `(μ - ν)`.\n  let measure_sub : measure α := @measure_theory.measure.of_measurable α _\n    (λ (t : set α) (h_t_measurable_set : measurable_set t), (μ t - ν t))\n    begin\n      simp\n    end\n    begin\n      intros g h_meas h_disj, simp only, rw ennreal.tsum_sub,\n      repeat { rw ← measure_theory.measure_Union h_disj h_meas },\n      apply measure_theory.measure_lt_top, intro i, apply h₂, apply h_meas\n    end,\n  -- Now, we demonstrate `μ - ν = measure_sub`, and apply it.\n  begin\n    have h_measure_sub_add : (ν + measure_sub = μ),\n    { ext t h_t_measurable_set,\n      simp only [pi.add_apply, coe_add],\n      rw [measure_theory.measure.of_measurable_apply _ h_t_measurable_set, add_comm,\n        ennreal.sub_add_cancel_of_le (h₂ t h_t_measurable_set)] },\n    have h_measure_sub_eq : (μ - ν) = measure_sub,\n    { rw measure_theory.measure.sub_def, apply le_antisymm,\n      { apply @Inf_le (measure α) measure.complete_semilattice_Inf,\n        simp [le_refl, add_comm, h_measure_sub_add] },\n      apply @le_Inf (measure α) measure.complete_semilattice_Inf,\n      intros d h_d, rw [← h_measure_sub_add, mem_set_of_eq, add_comm d] at h_d,\n      apply measure.le_of_add_le_add_left h_d },\n    rw h_measure_sub_eq,\n    apply measure.of_measurable_apply _ h₁,\n  end\nend\n\nlemma sub_add_cancel_of_le [finite_measure ν] (h₁ : ν ≤ μ) : μ - ν + ν = μ :=\nbegin\n  ext s h_s_meas,\n  rw [add_apply, sub_apply h_s_meas h₁, ennreal.sub_add_cancel_of_le (h₁ s h_s_meas)],\nend\n\nend measure_sub\n\nlemma restrict_sub_eq_restrict_sub_restrict (h_meas_s : measurable_set s) :\n  (μ - ν).restrict s = (μ.restrict s) - (ν.restrict s) :=\nbegin\n  repeat {rw sub_def},\n  have h_nonempty : {d | μ ≤ d + ν}.nonempty,\n  { apply @set.nonempty_of_mem _ _ μ, rw mem_set_of_eq, intros t h_meas,\n    apply le_add_right (le_refl (μ t)) },\n  rw restrict_Inf_eq_Inf_restrict h_nonempty h_meas_s,\n  apply le_antisymm,\n  { apply @Inf_le_Inf_of_forall_exists_le (measure α) _,\n    intros ν' h_ν'_in, rw mem_set_of_eq at h_ν'_in, apply exists.intro (ν'.restrict s),\n    split,\n    { rw mem_image, apply exists.intro (ν' + (⊤ : measure_theory.measure α).restrict sᶜ),\n      rw mem_set_of_eq,\n      split,\n      { rw [add_assoc, add_comm _ ν, ← add_assoc, measure_theory.measure.le_iff],\n        intros t h_meas_t,\n        have h_inter_inter_eq_inter : ∀ t' : set α , t ∩ t' ∩ t' = t ∩ t',\n        { intro t', rw set.inter_eq_self_of_subset_left, apply set.inter_subset_right t t' },\n        have h_meas_t_inter_s : measurable_set (t ∩ s) :=\n           h_meas_t.inter h_meas_s,\n        repeat {rw measure_eq_inter_diff h_meas_t h_meas_s, rw set.diff_eq},\n        apply add_le_add _ _; rw add_apply,\n        { apply le_add_right _,\n          rw add_apply,\n          rw ← @restrict_eq_self _ _ μ s _ h_meas_t_inter_s (set.inter_subset_right _ _),\n          rw ← @restrict_eq_self _ _ ν s _ h_meas_t_inter_s (set.inter_subset_right _ _),\n          apply h_ν'_in _ h_meas_t_inter_s },\n        cases (@set.eq_empty_or_nonempty _ (t ∩ sᶜ)) with h_inter_empty h_inter_nonempty,\n        { simp [h_inter_empty] },\n        { have h_meas_inter_compl :=\n            h_meas_t.inter (measurable_set.compl h_meas_s),\n          rw [restrict_apply h_meas_inter_compl, h_inter_inter_eq_inter sᶜ],\n          have h_mu_le_add_top : μ ≤ ν' + ν + ⊤,\n          { rw add_comm,\n            have h_le_top : μ ≤ ⊤ := le_top,\n            apply (λ t₂ h_meas, le_add_right (h_le_top t₂ h_meas)) },\n          apply h_mu_le_add_top _ h_meas_inter_compl } },\n      { ext1 t h_meas_t,\n        simp [restrict_apply h_meas_t,\n              restrict_apply (h_meas_t.inter h_meas_s),\n              set.inter_assoc] } },\n    { apply restrict_le_self } },\n  { apply @Inf_le_Inf_of_forall_exists_le (measure α) _,\n    intros s h_s_in, cases h_s_in with t h_t, cases h_t with h_t_in h_t_eq, subst s,\n    apply exists.intro (t.restrict s), split,\n    { rw [set.mem_set_of_eq, ← restrict_add],\n      apply restrict_mono (set.subset.refl _) h_t_in },\n    { apply le_refl _ } },\nend\n\nlemma sub_apply_eq_zero_of_restrict_le_restrict\n  (h_le : μ.restrict s ≤ ν.restrict s) (h_meas_s : measurable_set s) :\n  (μ - ν) s = 0 :=\nbegin\n  rw [← restrict_apply_self _ h_meas_s, restrict_sub_eq_restrict_sub_restrict,\n      sub_eq_zero_of_le],\n  repeat {simp [*]},\nend\n\nend measure\n\nend measure_theory\n\nopen measure_theory measure_theory.measure\n\nnamespace measurable_equiv\n\n/-! Interactions of measurable equivalences and measures -/\n\nopen equiv measure_theory.measure\n\nvariables [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β}\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 (f : α ≃ᵐ β) (s : set β) : map f μ s = μ (f ⁻¹' s) :=\nbegin\n  refine le_antisymm _ (le_map_apply f.measurable s),\n  rw [measure_eq_infi' μ],\n  refine le_infi _, rintro ⟨t, hst, ht⟩,\n  rw [subtype.coe_mk],\n  have := f.symm.to_equiv.image_eq_preimage,\n  simp only [←coe_eq, symm_symm, symm_to_equiv] at this,\n  rw [← this, image_subset_iff] at hst,\n  convert measure_mono hst,\n  rw [map_apply, preimage_preimage],\n  { refine congr_arg μ (eq.symm _), convert preimage_id, exact funext f.left_inv },\n  exacts [f.measurable, f.measurable_inv_fun ht]\nend\n\n@[simp] lemma map_symm_map (e : α ≃ᵐ β) : map e.symm (map e μ) = μ :=\nby simp [map_map e.symm.measurable e.measurable]\n\n@[simp] lemma map_map_symm (e : α ≃ᵐ β) : map e (map e.symm ν) = ν :=\nby simp [map_map e.measurable e.symm.measurable]\n\nlemma map_measurable_equiv_injective (e : α ≃ᵐ β) : injective (map e) :=\nby { intros μ₁ μ₂ hμ, apply_fun map e.symm at hμ, simpa [map_symm_map e] using hμ }\n\nlemma map_apply_eq_iff_map_symm_apply_eq (e : α ≃ᵐ β) : map e μ = ν ↔ map e.symm ν = μ :=\nby rw [← (map_measurable_equiv_injective e).eq_iff, map_map_symm, eq_comm]\n\n\nend measurable_equiv\n\nsection is_complete\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 `μ s = 0`. -/\nclass measure_theory.measure.is_complete {_ : measurable_space α} (μ : measure α) : Prop :=\n(out' : ∀ s, μ s = 0 → measurable_set s)\n\ntheorem measure_theory.measure.is_complete_iff {_ : measurable_space α} {μ : measure α} :\n  μ.is_complete ↔ ∀ s, μ s = 0 → measurable_set s := ⟨λ h, h.1, λ h, ⟨h⟩⟩\ntheorem measure_theory.measure.is_complete.out {_ : measurable_space α} {μ : measure α}\n  (h : μ.is_complete) : ∀ s, μ s = 0 → measurable_set s := h.1\n\nvariables [measurable_space α] {μ : measure α} {s t z : set α}\n\n/-- A set is null measurable if it is the union of a null set and a measurable set. -/\ndef null_measurable_set (μ : measure α) (s : set α) : Prop :=\n∃ t z, s = t ∪ z ∧ measurable_set t ∧ μ z = 0\n\ntheorem null_measurable_set_iff : null_measurable_set μ s ↔\n  ∃ t, t ⊆ s ∧ measurable_set t ∧ μ (s \\ t) = 0 :=\nbegin\n  split,\n  { rintro ⟨t, z, rfl, ht, hz⟩,\n    refine ⟨t, set.subset_union_left _ _, ht, measure_mono_null _ hz⟩,\n    simp [union_diff_left, diff_subset] },\n  { rintro ⟨t, st, ht, hz⟩,\n    exact ⟨t, _, (union_diff_cancel st).symm, ht, hz⟩ }\nend\n\ntheorem null_measurable_set_measure_eq (st : t ⊆ s) (hz : μ (s \\ t) = 0) : μ s = μ t :=\nbegin\n  refine le_antisymm _ (measure_mono st),\n  have := measure_union_le t (s \\ t),\n  rw [union_diff_cancel st, hz] at this, simpa\nend\n\ntheorem measurable_set.null_measurable_set (μ : measure α) (hs : measurable_set s) :\n  null_measurable_set μ s :=\n⟨s, ∅, by simp, hs, μ.empty⟩\n\ntheorem null_measurable_set_of_complete (μ : measure α) [c : μ.is_complete] :\n  null_measurable_set μ s ↔ measurable_set s :=\n⟨by rintro ⟨t, z, rfl, ht, hz⟩; exact\n  measurable_set.union ht (c.out _ hz),\n λ h, h.null_measurable_set _⟩\n\ntheorem null_measurable_set.union_null (hs : null_measurable_set μ s) (hz : μ z = 0) :\n  null_measurable_set μ (s ∪ z) :=\nbegin\n  rcases hs with ⟨t, z', rfl, ht, hz'⟩,\n  exact ⟨t, z' ∪ z, set.union_assoc _ _ _, ht, nonpos_iff_eq_zero.1\n    (le_trans (measure_union_le _ _) $ by simp [hz, hz'])⟩\nend\n\ntheorem null_null_measurable_set (hz : μ z = 0) : null_measurable_set μ z :=\nby simpa using (measurable_set.empty.null_measurable_set _).union_null hz\n\ntheorem null_measurable_set.Union_nat {s : ℕ → set α} (hs : ∀ i, null_measurable_set μ (s i)) :\n  null_measurable_set μ (Union s) :=\nbegin\n  choose t ht using assume i, null_measurable_set_iff.1 (hs i),\n  simp [forall_and_distrib] at ht,\n  rcases ht with ⟨st, ht, hz⟩,\n  refine null_measurable_set_iff.2\n    ⟨Union t, Union_subset_Union st, measurable_set.Union ht,\n      measure_mono_null _ (measure_Union_null hz)⟩,\n  rw [diff_subset_iff, ← Union_union_distrib],\n  exact Union_subset_Union (λ i, by rw ← diff_subset_iff)\nend\n\ntheorem measurable_set.diff_null (hs : measurable_set s) (hz : μ z = 0) :\n  null_measurable_set μ (s \\ z) :=\nbegin\n  rw measure_eq_infi at hz,\n  choose f hf using show ∀ q : {q : ℚ // q > 0}, ∃ t : set α,\n    z ⊆ t ∧ measurable_set t ∧ μ t < (nnreal.of_real q.1 : ℝ≥0∞),\n  { rintro ⟨ε, ε0⟩,\n    have : 0 < (nnreal.of_real ε : ℝ≥0∞), { simpa using ε0 },\n    rw ← hz at this, simpa [infi_lt_iff] },\n  refine null_measurable_set_iff.2 ⟨s \\ Inter f,\n    diff_subset_diff_right (subset_Inter (λ i, (hf i).1)),\n    hs.diff (measurable_set.Inter (λ i, (hf i).2.1)),\n    measure_mono_null _ (nonpos_iff_eq_zero.1 $ le_of_not_lt $ λ h, _)⟩,\n  { exact Inter f },\n  { rw [diff_subset_iff, diff_union_self],\n    exact subset.trans (diff_subset _ _) (subset_union_left _ _) },\n  rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨ε, ε0', ε0, h⟩,\n  simp at ε0,\n  apply not_le_of_lt (lt_trans (hf ⟨ε, ε0⟩).2.2 h),\n  exact measure_mono (Inter_subset _ _)\nend\n\ntheorem null_measurable_set.diff_null (hs : null_measurable_set μ s) (hz : μ z = 0) :\n  null_measurable_set μ (s \\ z) :=\nbegin\n  rcases hs with ⟨t, z', rfl, ht, hz'⟩,\n  rw [set.union_diff_distrib],\n  exact (ht.diff_null hz).union_null (measure_mono_null (diff_subset _ _) hz')\nend\n\ntheorem null_measurable_set.compl (hs : null_measurable_set μ s) : null_measurable_set μ sᶜ :=\nbegin\n  rcases hs with ⟨t, z, rfl, ht, hz⟩,\n  rw compl_union,\n  exact ht.compl.diff_null hz\nend\n\ntheorem null_measurable_set_iff_ae {s : set α} :\n  null_measurable_set μ s ↔ ∃ t, measurable_set t ∧ s =ᵐ[μ] t :=\nbegin\n  simp only [ae_eq_set],\n  split,\n  { assume h,\n    rcases null_measurable_set_iff.1 h with ⟨t, ts, tmeas, ht⟩,\n    refine ⟨t, tmeas, ht, _⟩,\n    rw [diff_eq_empty.2 ts, measure_empty] },\n  { rintros ⟨t, tmeas, h₁, h₂⟩,\n    have : null_measurable_set μ (t ∪ (s \\ t)) :=\n      null_measurable_set.union_null (tmeas.null_measurable_set _) h₁,\n    have A : null_measurable_set μ ((t ∪ (s \\ t)) \\ (t \\ s)) :=\n      null_measurable_set.diff_null this h₂,\n    have : (t ∪ (s \\ t)) \\ (t \\ s) = s,\n    { apply subset.antisymm,\n      { assume x hx,\n        simp only [mem_union_eq, not_and, mem_diff, not_not_mem] at hx,\n        cases hx.1, { exact hx.2 h }, { exact h.1 } },\n      { assume x hx,\n        simp [hx, classical.em (x ∈ t)] } },\n    rwa this at A }\nend\n\ntheorem null_measurable_set_iff_sandwich {s : set α} :\n  null_measurable_set μ s ↔\n  ∃ (t u : set α), measurable_set t ∧ measurable_set u ∧ t ⊆ s ∧ s ⊆ u ∧ μ (u \\ t) = 0 :=\nbegin\n  split,\n  { assume h,\n    rcases null_measurable_set_iff.1 h with ⟨t, ts, tmeas, ht⟩,\n    rcases null_measurable_set_iff.1 h.compl with ⟨u', u's, u'meas, hu'⟩,\n    have A : s ⊆ u'ᶜ := subset_compl_comm.mp u's,\n    refine ⟨t, u'ᶜ, tmeas, u'meas.compl, ts, A, _⟩,\n    have : sᶜ \\ u' = u'ᶜ \\ s, by simp [compl_eq_univ_diff, diff_diff, union_comm],\n    rw this at hu',\n    apply le_antisymm _ bot_le,\n    calc μ (u'ᶜ \\ t) ≤ μ ((u'ᶜ \\ s) ∪ (s \\ t)) :\n    begin\n      apply measure_mono,\n      assume x hx,\n      simp at hx,\n      simp [hx, or_comm, classical.em],\n    end\n    ... ≤ μ (u'ᶜ \\ s) + μ (s \\ t) : measure_union_le _ _\n    ... = 0 : by rw [ht, hu', zero_add] },\n  { rintros ⟨t, u, tmeas, umeas, ts, su, hμ⟩,\n    refine null_measurable_set_iff.2 ⟨t, ts, tmeas, _⟩,\n    apply le_antisymm _ bot_le,\n    calc μ (s \\ t) ≤ μ (u \\ t) : measure_mono (diff_subset_diff_left su)\n    ... = 0 : hμ }\nend\n\nlemma restrict_apply_of_null_measurable_set {s t : set α}\n  (ht : null_measurable_set (μ.restrict s) t) : μ.restrict s t = μ (t ∩ s) :=\nbegin\n  rcases null_measurable_set_iff_sandwich.1 ht with ⟨u, v, umeas, vmeas, ut, tv, huv⟩,\n  apply le_antisymm _ (le_restrict_apply _ _),\n  calc μ.restrict s t ≤ μ.restrict s v : measure_mono tv\n  ... = μ (v ∩ s) : restrict_apply vmeas\n  ... ≤ μ ((u ∩ s) ∪ ((v \\ u) ∩ s)) : measure_mono $\n    by { assume x hx, simp at hx, simp [hx, classical.em] }\n  ... ≤ μ (u ∩ s) + μ ((v \\ u) ∩ s) : measure_union_le _ _\n  ... = μ (u ∩ s) + μ.restrict s (v \\ u) : by rw measure.restrict_apply (vmeas.diff umeas)\n  ... = μ (u ∩ s) : by rw [huv, add_zero]\n  ... ≤ μ (t ∩ s) : measure_mono $ inter_subset_inter_left s ut\nend\n\n/-- The measurable space of all null measurable sets. -/\ndef null_measurable (μ : measure α) : measurable_space α :=\n{ measurable_set' := null_measurable_set μ,\n  measurable_set_empty := measurable_set.empty.null_measurable_set _,\n  measurable_set_compl := λ s hs, hs.compl,\n  measurable_set_Union := λ f, null_measurable_set.Union_nat }\n\n/-- Given a measure we can complete it to a (complete) measure on all null measurable sets. -/\ndef completion (μ : measure α) : @measure_theory.measure α (null_measurable μ) :=\n{ to_outer_measure := μ.to_outer_measure,\n  m_Union := λ s hs hd, show μ (Union s) = ∑' i, μ (s i), begin\n    choose t ht using assume i, null_measurable_set_iff.1 (hs i),\n    simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩,\n    rw null_measurable_set_measure_eq (Union_subset_Union st),\n    { rw measure_Union _ ht,\n      { congr, funext i,\n        exact (null_measurable_set_measure_eq (st i) (hz i)).symm },\n      { rintro i j ij x ⟨h₁, h₂⟩,\n        exact hd i j ij ⟨st i h₁, st j h₂⟩ } },\n    { refine measure_mono_null _ (measure_Union_null hz),\n      rw [diff_subset_iff, ← Union_union_distrib],\n      exact Union_subset_Union (λ i, by rw ← diff_subset_iff) }\n  end,\n  trimmed := begin\n    letI := null_measurable μ,\n    refine le_antisymm (λ s, _) (outer_measure.le_trim _),\n    rw outer_measure.trim_eq_infi,\n    dsimp,\n    clear _inst,\n    resetI,\n    rw measure_eq_infi s,\n    exact infi_le_infi (λ t, infi_le_infi $ λ st,\n      infi_le_infi2 $ λ ht, ⟨ht.null_measurable_set _, le_refl _⟩)\n  end }\n\ninstance completion.is_complete (μ : measure α) : (completion μ).is_complete :=\n⟨λ z hz, null_null_measurable_set hz⟩\n\nlemma measurable.ae_eq {α β} [measurable_space α] [measurable_space β] {μ : measure α}\n  [hμ : μ.is_complete] {f g : α → β} (hf : measurable f) (hfg : f =ᵐ[μ] g) :\n  measurable g :=\nbegin\n  intros s hs,\n  let t := {x | f x = g x},\n  have ht_compl : μ tᶜ = 0, by rwa [filter.eventually_eq, ae_iff] at hfg,\n  rw (set.inter_union_compl (g ⁻¹' s) t).symm,\n  refine measurable_set.union _ _,\n  { have h_g_to_f : (g ⁻¹' s) ∩ t = (f ⁻¹' s) ∩ t,\n    { ext,\n      simp only [set.mem_inter_iff, set.mem_preimage, and.congr_left_iff, set.mem_set_of_eq],\n      exact λ hx, by rw hx, },\n    rw h_g_to_f,\n    exact measurable_set.inter (hf hs) (measurable_set.compl_iff.mp (hμ.out tᶜ ht_compl)), },\n  { exact hμ.out (g ⁻¹' s ∩ tᶜ) (measure_mono_null (set.inter_subset_right _ _) ht_compl), },\nend\n\nend is_complete\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 μ`, and discuss several of its properties\nthat are analogous to properties of measurable functions.\n-/\n\nsection\nopen measure_theory\n\nvariables [measurable_space α] [measurable_space β]\n{f g : α → β} {μ ν : measure α}\n\n/-- A function is almost everywhere measurable if it coincides almost everywhere with a measurable\nfunction. -/\ndef ae_measurable (f : α → β) (μ : measure α . measure_theory.volume_tac) : Prop :=\n∃ g : α → β, measurable g ∧ f =ᵐ[μ] g\n\nlemma measurable.ae_measurable (h : measurable f) : ae_measurable f μ :=\n⟨f, h, ae_eq_refl f⟩\n\n@[nontriviality] lemma subsingleton.ae_measurable [subsingleton α] : ae_measurable f μ :=\nsubsingleton.measurable.ae_measurable\n\n@[simp] lemma ae_measurable_zero_measure : ae_measurable f 0 :=\nbegin\n  nontriviality α, inhabit α,\n  exact ⟨λ x, f (default α), measurable_const, rfl⟩\nend\n\nlemma ae_measurable_iff_measurable [μ.is_complete] :\n  ae_measurable f μ ↔ measurable f :=\nbegin\n  split; intro h,\n  { rcases h with ⟨g, hg_meas, hfg⟩,\n    exact hg_meas.ae_eq hfg.symm, },\n  { exact h.ae_measurable, },\nend\n\nnamespace ae_measurable\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 (f : α → β) (h : ae_measurable f μ) : α → β := classical.some h\n\nlemma measurable_mk (h : ae_measurable f μ) : measurable (h.mk f) :=\n(classical.some_spec h).1\n\nlemma ae_eq_mk (h : ae_measurable f μ) : f =ᵐ[μ] (h.mk f) :=\n(classical.some_spec h).2\n\nlemma congr (hf : ae_measurable f μ) (h : f =ᵐ[μ] g) : ae_measurable g μ :=\n⟨hf.mk f, hf.measurable_mk, h.symm.trans hf.ae_eq_mk⟩\n\nlemma mono_measure (h : ae_measurable f μ) (h' : ν ≤ μ) : ae_measurable f ν :=\n⟨h.mk f, h.measurable_mk, eventually.filter_mono (ae_mono h') h.ae_eq_mk⟩\n\nlemma mono_set {s t} (h : s ⊆ t) (ht : ae_measurable f (μ.restrict t)) :\n  ae_measurable f (μ.restrict s) :=\nht.mono_measure (restrict_mono h le_rfl)\n\nprotected lemma mono' (h : ae_measurable f μ) (h' : ν ≪ μ) : ae_measurable f ν :=\n⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩\n\nlemma ae_mem_imp_eq_mk {s} (h : ae_measurable f (μ.restrict s)) :\n  ∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=\nae_imp_of_ae_restrict h.ae_eq_mk\n\nlemma ae_inf_principal_eq_mk {s} (h : ae_measurable f (μ.restrict s)) :\n  f =ᶠ[μ.ae ⊓ 𝓟 s] h.mk f :=\nle_ae_restrict h.ae_eq_mk\n\nlemma add_measure {f : α → β} (hμ : ae_measurable f μ) (hν : ae_measurable f ν) :\n  ae_measurable f (μ + ν) :=\nbegin\n  let s := {x | f x ≠ hμ.mk f x},\n  have : μ s = 0 := hμ.ae_eq_mk,\n  obtain ⟨t, st, t_meas, μt⟩ : ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0 :=\n    exists_measurable_superset_of_null this,\n  let g : α → β := t.piecewise (hν.mk f) (hμ.mk f),\n  refine ⟨g, measurable.piecewise t_meas hν.measurable_mk hμ.measurable_mk, _⟩,\n  change μ {x | f x ≠ g x} + ν {x | f x ≠ g x} = 0,\n  suffices : μ {x | f x ≠ g x} = 0 ∧ ν {x | f x ≠ g x} = 0, by simp [this.1, this.2],\n  have ht : {x | f x ≠ g x} ⊆ t,\n  { assume x hx,\n    by_contra h,\n    simp only [g, h, mem_set_of_eq, ne.def, not_false_iff, piecewise_eq_of_not_mem] at hx,\n    exact h (st hx) },\n  split,\n  { have : μ {x | f x ≠ g x} ≤ μ t := measure_mono ht,\n    rw μt at this,\n    exact le_antisymm this bot_le },\n  { have : {x | f x ≠ g x} ⊆ {x | f x ≠ hν.mk f x},\n    { assume x hx,\n      simpa [ht hx, g] using hx },\n    apply le_antisymm _ bot_le,\n    calc ν {x | f x ≠ g x} ≤ ν {x | f x ≠ hν.mk f x} : measure_mono this\n    ... = 0 : hν.ae_eq_mk }\nend\n\nlemma smul_measure (h : ae_measurable f μ) (c : ℝ≥0∞) :\n  ae_measurable f (c • μ) :=\n⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩\n\nlemma comp_measurable [measurable_space δ] {f : α → δ} {g : δ → β}\n  (hg : ae_measurable g (map f μ)) (hf : measurable f) : ae_measurable (g ∘ f) μ :=\n⟨hg.mk g ∘ f, hg.measurable_mk.comp hf, ae_eq_comp hf hg.ae_eq_mk⟩\n\nlemma comp_measurable' {δ} [measurable_space δ] {ν : measure δ} {f : α → δ} {g : δ → β}\n  (hg : ae_measurable g ν) (hf : measurable f) (h : map f μ ≪ ν) : ae_measurable (g ∘ f) μ :=\n(hg.mono' h).comp_measurable hf\n\nlemma prod_mk {γ : Type*} [measurable_space γ] {f : α → β} {g : α → γ}\n  (hf : ae_measurable f μ) (hg : ae_measurable g μ) : ae_measurable (λ x, (f x, g x)) μ :=\n⟨λ a, (hf.mk f a, hg.mk g a), hf.measurable_mk.prod_mk hg.measurable_mk,\n  eventually_eq.prod_mk hf.ae_eq_mk hg.ae_eq_mk⟩\n\nprotected lemma null_measurable_set (h : ae_measurable f μ) {s : set β} (hs : measurable_set s) :\n  null_measurable_set μ (f ⁻¹' s) :=\nbegin\n  apply null_measurable_set_iff_ae.2,\n  refine ⟨(h.mk f) ⁻¹' s, h.measurable_mk hs, _⟩,\n  filter_upwards [h.ae_eq_mk],\n  assume x hx,\n  change (f x ∈ s) = ((h.mk f) x ∈ s),\n  rwa hx\nend\n\nend ae_measurable\n\nlemma ae_measurable_congr (h : f =ᵐ[μ] g) :\n  ae_measurable f μ ↔ ae_measurable g μ :=\n⟨λ hf, ae_measurable.congr hf h, λ hg, ae_measurable.congr hg h.symm⟩\n\n@[simp] lemma ae_measurable_add_measure_iff :\n  ae_measurable f (μ + ν) ↔ ae_measurable f μ ∧ ae_measurable f ν :=\n⟨λ h, ⟨h.mono_measure (measure.le_add_right (le_refl _)),\n         h.mono_measure (measure.le_add_left (le_refl _))⟩,\n  λ h, h.1.add_measure h.2⟩\n\n@[simp] lemma ae_measurable_const {b : β} : ae_measurable (λ a : α, b) μ :=\nmeasurable_const.ae_measurable\n\n@[simp, to_additive] lemma ae_measurable_one [has_one β] : ae_measurable (λ a : α, (1 : β)) μ :=\nmeasurable_one.ae_measurable\n\n@[simp] lemma ae_measurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :\n  ae_measurable f (c • μ) ↔ ae_measurable f μ :=\n⟨λ h, ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩,\n  λ h, ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩\n\nlemma measurable.comp_ae_measurable [measurable_space δ] {f : α → δ} {g : δ → β}\n  (hg : measurable g) (hf : ae_measurable f μ) : ae_measurable (g ∘ f) μ :=\n⟨g ∘ hf.mk f, hg.comp hf.measurable_mk, eventually_eq.fun_comp hf.ae_eq_mk _⟩\n\nend\n\nnamespace is_compact\n\nvariables [topological_space α] [measurable_space α] {μ : measure α} {s : set α}\n\nlemma finite_measure_of_nhds_within (hs : is_compact s) :\n  (∀ a ∈ s, μ.finite_at_filter (𝓝[s] a)) → μ s < ∞ :=\nby simpa only [← measure.compl_mem_cofinite, measure.finite_at_filter]\n  using hs.compl_mem_sets_of_nhds_within\n\nlemma finite_measure [locally_finite_measure μ] (hs : is_compact s) : μ s < ∞ :=\nhs.finite_measure_of_nhds_within $ λ a ha, μ.finite_at_nhds_within _ _\n\nlemma measure_zero_of_nhds_within (hs : is_compact s) :\n  (∀ a ∈ s, ∃ t ∈ 𝓝[s] a, μ t = 0) → μ s = 0 :=\nby simpa only [← compl_mem_ae_iff] using hs.compl_mem_sets_of_nhds_within\n\nend is_compact\n\nlemma metric.bounded.finite_measure [metric_space α] [proper_space α]\n  [measurable_space α] {μ : measure α} [locally_finite_measure μ] {s : set α}\n  (hs : metric.bounded s) :\n  μ s < ∞ :=\n(measure_mono subset_closure).trans_lt (metric.compact_iff_closed_bounded.2\n  ⟨is_closed_closure, metric.bounded_closure_of_bounded hs⟩).finite_measure\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/measure_space.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7512329770501112}}
{"text": "import data.polynomial.basic\nimport data.polynomial.eval\n\nnamespace polynomial\n\nvariables {R : Type*} {a b c d e : R} [semiring R]\n\nlemma degree_cubic_lt_degree_C_mul_X_cb (ha : a ≠ 0) :\n  degree (C b * X ^ 3 + C c * X ^ 2 + C d * X + C e) < degree (C a * X ^ 4) :=\nby simpa only [degree_C_mul_X_pow 4 ha] using degree_cubic_lt\n\n@[simp] lemma leading_coeff_quartic (ha : a ≠ 0):\n  leading_coeff (C a * X ^ 4 + C b * X ^ 3 + C c * X ^ 2 + C d * X + C e) = a :=\nby rw [add_assoc, add_assoc, add_assoc, ← add_assoc (C b * X ^ 3),\n         ← add_assoc (C b * X ^ 3 + C c * X ^ 2), add_comm, leading_coeff_add_of_degree_lt $\n         degree_cubic_lt_degree_C_mul_X_cb ha, leading_coeff_C_mul_X_pow]\n\nlemma degree_quartic_le : degree (C a * X ^ 4 + C b * X ^ 3 + C c * X ^ 2 + C d * X + C e) ≤ 4 :=\nby simpa only [add_assoc] using degree_add_le_of_degree_le (degree_C_mul_X_pow_le 4 a)\n  (le_trans degree_cubic_le $ with_bot.coe_le_coe.mpr $ nat.le_succ 3)\n\n@[simp] lemma degree_quartic (ha : a ≠ 0) : degree (C a * X ^ 4 + C b * X ^ 3 + C c * X ^ 2 + C d * X + C e) = 4 :=\nbegin\n  rw [add_assoc, add_assoc, add_assoc, ← add_assoc (C b * X ^ 3),\n         ← add_assoc (C b * X ^ 3 + C c * X ^ 2), degree_add_eq_left_of_degree_lt $\n        degree_cubic_lt_degree_C_mul_X_cb ha, degree_C_mul_X_pow 4 ha],\n  refl\nend\n\n@[simp] lemma nat_degree_quartic (ha : a ≠ 0) :\n  nat_degree (C a * X ^ 4 + C b * X ^ 3 + C c * X ^ 2 + C d * X + C e) = 4 :=\nnat_degree_eq_of_degree_eq_some $ degree_quartic ha\n\nend polynomial\n", "meta": {"author": "anivegesana", "repo": "quartic", "sha": "f12d2cd969c84510caf83e4367034a4218c7b5c1", "save_path": "github-repos/lean/anivegesana-quartic", "path": "github-repos/lean/anivegesana-quartic/quartic-f12d2cd969c84510caf83e4367034a4218c7b5c1/src/data/polynomial/nat_degree_quartic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640647, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.751232976932431}}
{"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> 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ᵒᵈ`.\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 `α`, `filter α` represents the same mathematical object as\n`pfilter (set α)`.\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ᵒᵈ)\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ᵒᵈ _ 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⟨h.to_ideal⟩\n\nnamespace pfilter\n\nsection preorder\nvariables [preorder P] {x y : P} (F s t : pfilter P)\n\ninstance [inhabited P] : inhabited (pfilter P) := ⟨⟨default⟩⟩\n\n/-- A filter on `P` is a subset of `P`. -/\ninstance : has_coe (pfilter P) (set P) := ⟨λ F, F.dual.carrier⟩\n\n/-- For the notation `x ∈ F`. -/\ninstance : has_mem P (pfilter P) := ⟨λ x F, x ∈ (F : set P)⟩\n\n@[simp] lemma mem_coe : x ∈ (F : set P) ↔ x ∈ 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 (≥) (F : set P) := F.dual.directed\n\nlemma mem_of_le {F : pfilter P} : x ≤ y → x ∈ F → y ∈ F := λ 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 ∈ F → F ≤ G → x ∈ G :=\nideal.mem_of_mem_of_le\n\n/-- The smallest filter containing a given element. -/\ndef principal (p : P) : pfilter P := ⟨ideal.principal p⟩\n\n@[simp] lemma mem_def (x : P) (I : ideal Pᵒᵈ) :\n  x ∈ (⟨I⟩ : pfilter P) ↔ order_dual.to_dual x ∈ I :=\niff.rfl\n\n@[simp] lemma principal_le_iff {F : pfilter P} : principal x ≤ F ↔ x ∈ F :=\nideal.principal_le_iff\n\n@[simp] lemma mem_principal : x ∈ principal y ↔ y ≤ x :=\nideal.mem_principal -- defeq abuse\n\nlemma antitone_principal : antitone (principal : P → pfilter P) := by delta antitone; simp\n\nlemma principal_le_principal_iff {p q : P} : principal q ≤ principal p ↔ p ≤ 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 : ⊤ ∈ F := ideal.bot_mem _\n\n/-- There is a bottom filter when `P` has a top element. -/\ninstance : order_bot (pfilter P) :=\n{ bot := ⟨⊥⟩,\n  bot_le := λ F, (bot_le : ⊥ ≤ 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 := ⟨⊤⟩,\n  le_top := λ F, (le_top : F.dual ≤ ⊤) }\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 ∈ F) (hy : y ∈ F) : x ⊓ y ∈ F := ideal.sup_mem hx hy\n\n@[simp] lemma inf_mem_iff : x ⊓ y ∈ F ↔ x ∈ F ∧ y ∈ 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 (λ x, order_dual.to_dual (principal x))\n  (λ F, Inf (order_dual.of_dual F : pfilter P)) :=\nλ 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 (λ x, order_dual.to_dual (principal x))\n  (λ F, Inf (order_dual.of_dual F : pfilter P)) :=\n{ choice := λ F _, Inf (id F : pfilter P),\n  gc := Inf_gc,\n  u_l_le := λ s, Inf_le $ mem_principal.2 $ le_refl s,\n  choice_eq := λ _ _, rfl }\n\nend complete_semilattice_Inf\n\nend pfilter\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/pfilter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7512329750615593}}
{"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 data.polynomial.eval\nimport linear_algebra.dimension\n\n/-!\n# Linear recurrence\n\nInformally, a \"linear recurrence\" is an assertion of the form\n`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,\nwhere `u` is a sequence, `d` is the *order* of the recurrence and the `a i`\nare its *coefficients*.\n\nIn this file, we define the structure `linear_recurrence` so that\n`linear_recurrence.mk d a` represents the above relation, and we call\na sequence `u` which verifies it a *solution* of the linear recurrence.\n\nWe prove a few basic lemmas about this concept, such as :\n\n* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`\n  is a field)\n* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`\n  between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two\n  solutions are equal if and only if their first `d` terms are equals.\n* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,\n  which we call the *characteristic polynomial* of the recurrence\n\nOf course, although we can inductively generate solutions (cf `mk_sol`), the\ninteresting part would be to determinate closed-forms for the solutions.\nThis is currently *not implemented*, as we are waiting for definition and\nproperties of eigenvalues and eigenvectors.\n\n-/\n\nnoncomputable theory\nopen finset\nopen_locale big_operators\n\n/-- A \"linear recurrence relation\" over a commutative semiring is given by its\n  order `n` and `n` coefficients. -/\nstructure linear_recurrence (α : Type*) [comm_semiring α] := (order : ℕ) (coeffs : fin order → α)\n\ninstance (α : Type*) [comm_semiring α] : inhabited (linear_recurrence α) :=\n⟨⟨0, default⟩⟩\n\nnamespace linear_recurrence\n\nsection comm_semiring\n\nvariables {α : Type*} [comm_semiring α] (E : linear_recurrence α)\n\n/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have\n  `u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/\ndef is_solution (u : ℕ → α) :=\n  ∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)\n\n/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.\n  We will prove this is the only such solution. -/\ndef mk_sol (init : fin E.order → α) : ℕ → α\n| n := if h : n < E.order then init ⟨n, h⟩ else\n  ∑ k : fin E.order,\n    have n - E.order + k < n :=\n    begin\n      rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h), tsub_lt_iff_left],\n      { exact add_lt_add_right k.is_lt n },\n      { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h),\n        simp only [zero_add] }\n    end,\n    E.coeffs k * mk_sol (n - E.order + k)\n\n/-- `E.mk_sol` indeed gives solutions to `E`. -/\nlemma is_sol_mk_sol (init : fin E.order → α) : E.is_solution (E.mk_sol init) :=\n  λ n, by rw mk_sol; simp\n\n/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/\nlemma mk_sol_eq_init (init : fin E.order → α) : ∀ n : fin E.order, E.mk_sol init n = init n :=\n  λ n, by { rw mk_sol, simp only [n.is_lt, dif_pos, fin.mk_coe, fin.eta] }\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `∀ n, u n = E.mk_sol init n`. -/\nlemma eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) :\n  ∀ n, u n = E.mk_sol init n\n| n := if h' : n < E.order\n  then by rw mk_sol; simp only [h', dif_pos]; exact_mod_cast heq ⟨n, h'⟩\n  else begin\n    rw [mk_sol, ← tsub_add_cancel_of_le (le_of_not_lt h'), h (n-E.order)],\n    simp [h'],\n    congr' with k,\n    exact have wf : n - E.order + k < n :=\n      begin\n        rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h'), tsub_lt_iff_left],\n        { exact add_lt_add_right k.is_lt n },\n        { convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h'),\n          simp only [zero_add] }\n      end,\n      by rw eq_mk_of_is_sol_of_eq_init\n  end\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution\n  of `E` whose first `E.order` values are given by `init`. -/\nlemma eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : fin E.order → α}\n  (h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) : u = E.mk_sol init :=\n  funext (E.eq_mk_of_is_sol_of_eq_init h heq)\n\n/-- The space of solutions of `E`, as a `submodule` over `α` of the module `ℕ → α`. -/\ndef sol_space : submodule α (ℕ → α) :=\n{ carrier := {u | E.is_solution u},\n  zero_mem' := λ n, by simp,\n  add_mem' := λ u v hu hv n, by simp [mul_add, sum_add_distrib, hu n, hv n],\n  smul_mem' := λ a u hu n, by simp [hu n, mul_sum]; congr'; ext; ac_refl }\n\n/-- Defining property of the solution space : `u` is a solution\n  iff it belongs to the solution space. -/\nlemma is_sol_iff_mem_sol_space (u : ℕ → α) : E.is_solution u ↔ u ∈ E.sol_space :=\n  iff.rfl\n\n/-- The function that maps a solution `u` of `E` to its first\n  `E.order` terms as a `linear_equiv`. -/\ndef to_init :\n  E.sol_space ≃ₗ[α] (fin E.order → α) :=\n{ to_fun := λ u x, (u : ℕ → α) x,\n  map_add' := λ u v, by { ext, simp },\n  map_smul' := λ a u, by { ext, simp },\n  inv_fun := λ u, ⟨E.mk_sol u, E.is_sol_mk_sol u⟩,\n  left_inv := λ u, by ext n; symmetry; apply E.eq_mk_of_is_sol_of_eq_init u.2; intros k; refl,\n  right_inv := λ u, function.funext_iff.mpr (λ n, E.mk_sol_eq_init u n) }\n\n/-- Two solutions are equal iff they are equal on `range E.order`. -/\nlemma sol_eq_of_eq_init (u v : ℕ → α) (hu : E.is_solution u) (hv : E.is_solution v) :\n  u = v ↔ set.eq_on u v ↑(range E.order) :=\nbegin\n  refine iff.intro (λ h x hx, h ▸ rfl) _,\n  intro h,\n  set u' : ↥(E.sol_space) := ⟨u, hu⟩,\n  set v' : ↥(E.sol_space) := ⟨v, hv⟩,\n  change u'.val = v'.val,\n  suffices h' : u' = v', from h' ▸ rfl,\n  rw [← E.to_init.to_equiv.apply_eq_iff_eq, linear_equiv.coe_to_equiv],\n  ext x,\n  exact_mod_cast h (mem_range.mpr x.2)\nend\n\n/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. This operation is quite useful for determining closed-form\n  solutions of `E`. -/\n\n/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. -/\ndef tuple_succ : (fin E.order → α) →ₗ[α] (fin E.order → α) :=\n{ to_fun := λ X i, if h : (i : ℕ) + 1 < E.order then X ⟨i+1, h⟩ else (∑ i, E.coeffs i * X i),\n  map_add' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_add, sum_add_distrib],\n    end,\n  map_smul' := λ x y,\n    begin\n      ext i,\n      split_ifs ; simp [h, mul_sum],\n      exact sum_congr rfl (λ x _, by ac_refl),\n    end }\n\nend comm_semiring\n\nsection field\n\nvariables {α : Type*} [field α] (E : linear_recurrence α)\n\n/-- The dimension of `E.sol_space` is `E.order`. -/\nlemma sol_space_dim : module.rank α E.sol_space = E.order :=\n@dim_fin_fun α _ E.order ▸ E.to_init.dim_eq\n\nend field\n\nsection comm_ring\n\nvariables {α : Type*} [comm_ring α] (E : linear_recurrence α)\n\n/-- The characteristic polynomial of `E` is\n`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/\ndef char_poly : polynomial α :=\n  polynomial.monomial E.order 1 - (∑ i : fin E.order, polynomial.monomial i (E.coeffs i))\n\n/-- The geometric sequence `q^n` is a solution of `E` iff\n  `q` is a root of `E`'s characteristic polynomial. -/\nlemma geom_sol_iff_root_char_poly (q : α) : E.is_solution (λ n, q^n) ↔ E.char_poly.is_root q :=\nbegin\n  rw [char_poly, polynomial.is_root.def, polynomial.eval],\n  simp only [polynomial.eval₂_finset_sum, one_mul,\n              ring_hom.id_apply, polynomial.eval₂_monomial, polynomial.eval₂_sub],\n  split,\n  { intro h,\n    simpa [sub_eq_zero] using h 0 },\n  { intros h n,\n    simp only [pow_add, sub_eq_zero.mp h, mul_sum],\n    exact sum_congr rfl (λ _ _, by ring) }\nend\n\nend comm_ring\n\nend linear_recurrence\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/linear_recurrence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7512221569469565}}
{"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\n! This file was ported from Lean 3 source module ring_theory.ideal.quotient\n! leanprover-community/mathlib commit bd9851ca476957ea4549eb19b40e7b5ade9428cc\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.Fin\nimport Mathlib.Algebra.Ring.Prod\nimport Mathlib.LinearAlgebra.Quotient\nimport Mathlib.RingTheory.Congruence\nimport Mathlib.RingTheory.Ideal.Basic\nimport Mathlib.Tactic.FinCases\n\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.RingQuot` 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.quotientInfRingEquivPiQuotient`: the **Chinese Remainder Theorem**\n-/\n\n\nuniverse u v w\n\nnamespace Ideal\n\nopen Set\nopen BigOperators\n\nvariable {R : Type u} [CommRing R] (I : Ideal R) {a b : R}\nvariable {S : Type v}\n\n-- Porting note: we need η for TC\nset_option synthInstance.etaExperiment true\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/-- 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@[reducible]\ninstance : HasQuotient R (Ideal R) :=\n  Submodule.hasQuotient\n\nnamespace Quotient\n\nvariable {I} {x y : R}\n\ninstance hasOne (I : Ideal R) : One (R ⧸ I) :=\n  ⟨Submodule.Quotient.mk 1⟩\n#align ideal.quotient.has_one Ideal.Quotient.hasOne\n\n/-- On `Ideal`s, `Submodule.quotientRel` is a ring congruence. -/\nprotected def ringCon (I : Ideal R) : RingCon R :=\n  { QuotientAddGroup.con I.toAddSubgroup with\n    mul' := fun {a₁ b₁ a₂ b₂} h₁ h₂ =>\n      by\n      rw [Submodule.quotientRel_r_def] at h₁ h₂⊢\n      have F := I.add_mem (I.mul_mem_left a₂ h₁) (I.mul_mem_right b₁ h₂)\n      have : a₁ * a₂ - b₁ * b₂ = a₂ * (a₁ - b₁) + (a₂ - b₂) * b₁ := by\n        rw [mul_sub, sub_mul, sub_add_sub_cancel, mul_comm, mul_comm b₁]\n      rw [← this] at F\n      convert F }\n#align ideal.quotient.ring_con Ideal.Quotient.ringCon\n\ninstance commRing (I : Ideal R) : CommRing (R ⧸ I) :=\n  { @Submodule.Quotient.addCommGroup _ _ (id _) (id _) (id _) I,\n    inferInstanceAs (CommRing (Quotient.ringCon I).Quotient) with }\n#align ideal.quotient.comm_ring Ideal.Quotient.commRing\n\n/-- The ring homomorphism from a ring `R` to a quotient ring `R/I`. -/\ndef mk (I : Ideal R) : R →+* R ⧸ I where\n  toFun a := Submodule.Quotient.mk a\n  map_zero' := rfl\n  map_one' := rfl\n  map_mul' _ _ := rfl\n  map_add' _ _ := rfl\n#align ideal.quotient.mk Ideal.Quotient.mk\n\n/-- Two `RingHom`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]\ntheorem ringHom_ext [NonAssocSemiring S] ⦃f g : R ⧸ I →+* S⦄ (h : f.comp (mk I) = g.comp (mk I)) :\n    f = g :=\n  RingHom.ext fun x => Quotient.inductionOn' x <| (RingHom.congr_fun h : _)\n#align ideal.quotient.ring_hom_ext Ideal.Quotient.ringHom_ext\n\ninstance inhabited : Inhabited (R ⧸ I) :=\n  ⟨mk I 37⟩\n#align ideal.quotient.inhabited Ideal.Quotient.inhabited\n\nprotected theorem eq : mk I x = mk I y ↔ x - y ∈ I :=\n  Submodule.Quotient.eq I\n#align ideal.quotient.eq Ideal.Quotient.eq\n\n@[simp]\ntheorem mk_eq_mk (x : R) : (Submodule.Quotient.mk x : R ⧸ I) = mk I x := rfl\n#align ideal.quotient.mk_eq_mk Ideal.Quotient.mk_eq_mk\n\ntheorem eq_zero_iff_mem {I : Ideal R} : mk I a = 0 ↔ a ∈ I :=\n  Submodule.Quotient.mk_eq_zero _\n#align ideal.quotient.eq_zero_iff_mem Ideal.Quotient.eq_zero_iff_mem\n\n-- Porting note: new theorem\ntheorem mk_eq_mk_iff_sub_mem (x y : R) : mk I x = mk I y ↔ x - y ∈ I := by\n  rw [← eq_zero_iff_mem, map_sub, sub_eq_zero]\n\ntheorem zero_eq_one_iff {I : Ideal R} : (0 : R ⧸ I) = 1 ↔ I = ⊤ :=\n  eq_comm.trans <| eq_zero_iff_mem.trans (eq_top_iff_one _).symm\n#align ideal.quotient.zero_eq_one_iff Ideal.Quotient.zero_eq_one_iff\n\ntheorem zero_ne_one_iff {I : Ideal R} : (0 : R ⧸ I) ≠ 1 ↔ I ≠ ⊤ :=\n  not_congr zero_eq_one_iff\n#align ideal.quotient.zero_ne_one_iff Ideal.Quotient.zero_ne_one_iff\n\nprotected theorem nontrivial {I : Ideal R} (hI : I ≠ ⊤) : Nontrivial (R ⧸ I) :=\n  ⟨⟨0, 1, zero_ne_one_iff.2 hI⟩⟩\n#align ideal.quotient.nontrivial Ideal.Quotient.nontrivial\n\ntheorem subsingleton_iff {I : Ideal R} : Subsingleton (R ⧸ I) ↔ I = ⊤ := by\n  rw [eq_top_iff_one, ← subsingleton_iff_zero_eq_one, eq_comm, ← (mk I).map_one,\n    Quotient.eq_zero_iff_mem]\n#align ideal.quotient.subsingleton_iff Ideal.Quotient.subsingleton_iff\n\ninstance : Unique (R ⧸ (⊤ : Ideal R)) :=\n  ⟨⟨0⟩, by rintro ⟨x⟩; exact Quotient.eq_zero_iff_mem.mpr Submodule.mem_top⟩\n\ntheorem mk_surjective : Function.Surjective (mk I) := fun y =>\n  Quotient.inductionOn' y fun x => Exists.intro x rfl\n#align ideal.quotient.mk_surjective Ideal.Quotient.mk_surjective\n\ninstance : RingHomSurjective (mk I) :=\n  ⟨mk_surjective⟩\n\n/-- If `I` is an ideal of a commutative ring `R`, if `q : R → R/I` is the quotient map, and if\n`s ⊆ R` is a subset, then `q⁻¹(q(s)) = ⋃ᵢ(i + s)`, the union running over all `i ∈ I`. -/\ntheorem quotient_ring_saturate (I : Ideal R) (s : Set R) :\n    mk I ⁻¹' (mk I '' s) = ⋃ x : I, (fun y => x.1 + y) '' s := by\n  ext x\n  simp only [mem_preimage, mem_image, mem_unionᵢ, Ideal.Quotient.eq]\n  exact\n    ⟨fun ⟨a, a_in, h⟩ => ⟨⟨_, I.neg_mem h⟩, a, a_in, by simp⟩, fun ⟨⟨i, hi⟩, a, ha, Eq⟩ =>\n      ⟨a, ha, by rw [← Eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub]; exact I.neg_mem hi⟩⟩\n#align ideal.quotient.quotient_ring_saturate Ideal.Quotient.quotient_ring_saturate\n\ninstance noZeroDivisors (I : Ideal R) [hI : I.IsPrime] : NoZeroDivisors (R ⧸ I) where\n    eq_zero_or_eq_zero_of_mul_eq_zero {a b} := Quotient.inductionOn₂' a b fun {_ _} hab =>\n      (hI.mem_or_mem (eq_zero_iff_mem.1 hab)).elim (Or.inl ∘ eq_zero_iff_mem.2)\n        (Or.inr ∘ eq_zero_iff_mem.2)\n#align ideal.quotient.no_zero_divisors Ideal.Quotient.noZeroDivisors\n\ninstance isDomain (I : Ideal R) [hI : I.IsPrime] : IsDomain (R ⧸ I) :=\n  let _ := Quotient.nontrivial hI.1\n  NoZeroDivisors.to_isDomain _\n#align ideal.quotient.is_domain Ideal.Quotient.isDomain\n\ntheorem isDomain_iff_prime (I : Ideal R) : IsDomain (R ⧸ I) ↔ I.IsPrime := by\n  refine' ⟨fun H => ⟨zero_ne_one_iff.1 _, fun {x y} h => _⟩, fun h => inferInstance⟩\n  · haveI : Nontrivial (R ⧸ I) := ⟨H.2.1⟩\n    exact zero_ne_one\n  · simp only [← eq_zero_iff_mem, (mk I).map_mul] at h⊢\n    haveI := @IsDomain.to_noZeroDivisors (R ⧸ I) _ H\n    exact eq_zero_or_eq_zero_of_mul_eq_zero h\n#align ideal.quotient.is_domain_iff_prime Ideal.Quotient.isDomain_iff_prime\n\ntheorem exists_inv {I : Ideal R} [hI : I.IsMaximal] :\n    ∀ {a : R ⧸ I}, a ≠ 0 → ∃ b : R ⧸ I, a * b = 1 := by\n  rintro ⟨a⟩ h\n  rcases hI.exists_inv (mt eq_zero_iff_mem.2 h) with ⟨b, c, hc, abc⟩\n  rw [mul_comm] at abc\n  refine' ⟨mk _ b, Quot.sound _⟩\n  --quot.sound hb\n  rw [← eq_sub_iff_add_eq'] at abc\n  rw [abc, ← neg_mem_iff (G := R) (H := I), neg_sub] at hc\n  rw [Submodule.quotientRel_r_def]\n  convert hc\n#align ideal.quotient.exists_inv Ideal.Quotient.exists_inv\n\nopen 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.IsMaximal] : Field (R ⧸ I) :=\n  { Quotient.commRing I,\n    Quotient.isDomain\n      I with\n    inv := fun a => if ha : a = 0 then 0 else Classical.choose (exists_inv ha)\n    mul_inv_cancel := fun a (ha : a ≠ 0) =>\n      show a * dite _ _ _ = _ by rw [dif_neg ha]; exact Classical.choose_spec (exists_inv ha)\n    inv_zero := dif_pos rfl }\n#align ideal.quotient.field Ideal.Quotient.field\n\n/-- If the quotient by an ideal is a field, then the ideal is maximal. -/\ntheorem maximal_of_isField (I : Ideal R) (hqf : IsField (R ⧸ I)) : I.IsMaximal := by\n  apply Ideal.isMaximal_iff.2\n  constructor\n  · intro h\n    rcases hqf.exists_pair_ne with ⟨⟨x⟩, ⟨y⟩, hxy⟩\n    exact hxy (Ideal.Quotient.eq.2 (mul_one (x - y) ▸ I.mul_mem_left _ h))\n  · intro J x hIJ hxnI hxJ\n    rcases hqf.mul_inv_cancel (mt Ideal.Quotient.eq_zero_iff_mem.1 hxnI) with ⟨⟨y⟩, hy⟩\n    rw [← zero_add (1 : R), ← sub_self (x * y), sub_add]\n    refine' J.sub_mem (J.mul_mem_right _ hxJ) (hIJ (Ideal.Quotient.eq.1 hy))\n#align ideal.quotient.maximal_of_is_field Ideal.Quotient.maximal_of_isField\n\n/-- The quotient of a ring by an ideal is a field iff the ideal is maximal. -/\ntheorem maximal_ideal_iff_isField_quotient (I : Ideal R) : I.IsMaximal ↔ IsField (R ⧸ I) :=\n  ⟨fun h =>\n    let _i := @Quotient.field _ _ I h\n    Field.toIsField _,\n    maximal_of_isField _⟩\n#align ideal.quotient.maximal_ideal_iff_is_field_quotient Ideal.Quotient.maximal_ideal_iff_isField_quotient\n\nvariable [CommRing S]\n\n/-- Given a ring homomorphism `f : R →+* S` sending all elements of an ideal to zero,\nlift it to the quotient by this ideal. -/\ndef lift (I : Ideal R) (f : R →+* S) (H : ∀ a : R, a ∈ I → f a = 0) : R ⧸ I →+* S :=\n  {\n    QuotientAddGroup.lift I.toAddSubgroup f.toAddMonoidHom\n      H with\n    map_one' := f.map_one\n    map_zero' := f.map_zero\n    map_add' := fun a₁ a₂ => Quotient.inductionOn₂' a₁ a₂ f.map_add\n    map_mul' := fun a₁ a₂ => Quotient.inductionOn₂' a₁ a₂ f.map_mul }\n#align ideal.quotient.lift Ideal.Quotient.lift\n\n@[simp]\n\n\ntheorem lift_surjective_of_surjective (I : Ideal R) {f : R →+* S} (H : ∀ a : R, a ∈ I → f a = 0)\n    (hf : Function.Surjective f) : Function.Surjective (Ideal.Quotient.lift I f H) := by\n  intro y\n  obtain ⟨x, rfl⟩ := hf y\n  use Ideal.Quotient.mk I x\n  simp only [Ideal.Quotient.lift_mk]\n#align ideal.quotient.lift_surjective_of_surjective Ideal.Quotient.lift_surjective_of_surjective\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 ≤ T) : R ⧸ S →+* R ⧸ T :=\n  Ideal.Quotient.lift S (mk T) fun _ hx => eq_zero_iff_mem.2 (H hx)\n#align ideal.quotient.factor Ideal.Quotient.factor\n\n@[simp]\ntheorem factor_mk (S T : Ideal R) (H : S ≤ T) (x : R) : factor S T H (mk S x) = mk T x :=\n  rfl\n#align ideal.quotient.factor_mk Ideal.Quotient.factor_mk\n\n@[simp]\ntheorem factor_comp_mk (S T : Ideal R) (H : S ≤ T) : (factor S T H).comp (mk S) = mk T := by\n  ext x\n  rw [RingHom.comp_apply, factor_mk]\n#align ideal.quotient.factor_comp_mk Ideal.Quotient.factor_comp_mk\n\nend Quotient\n\n/-- Quotienting by equal ideals gives equivalent rings.\n\nSee also `Submodule.quotEquivOfEq`.\n-/\ndef quotEquivOfEq {R : Type _} [CommRing R] {I J : Ideal R} (h : I = J) : R ⧸ I ≃+* R ⧸ J :=\n  { Submodule.quotEquivOfEq I J h with\n    map_mul' := by\n      rintro ⟨x⟩ ⟨y⟩\n      rfl }\n#align ideal.quot_equiv_of_eq Ideal.quotEquivOfEq\n\n@[simp]\ntheorem quotEquivOfEq_mk {R : Type _} [CommRing R] {I J : Ideal R} (h : I = J) (x : R) :\n    quotEquivOfEq h (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J x :=\n  rfl\n#align ideal.quot_equiv_of_eq_mk Ideal.quotEquivOfEq_mk\n\n@[simp]\ntheorem quotEquivOfEq_symm {R : Type _} [CommRing R] {I J : Ideal R} (h : I = J) :\n    (Ideal.quotEquivOfEq h).symm = Ideal.quotEquivOfEq h.symm := by ext; rfl\n#align ideal.quot_equiv_of_eq_symm Ideal.quotEquivOfEq_symm\n\nsection Pi\n\nvariable (ι : Type v)\n\n/-- `R^n/I^n` is a `R/I`-module. -/\ninstance modulePi : Module (R ⧸ I) ((ι → R) ⧸ I.pi ι) where\n  smul c m :=\n    Quotient.liftOn₂' c m (fun r m => Submodule.Quotient.mk <| r • m) $ by\n      intro c₁ m₁ c₂ m₂ hc hm\n      apply Ideal.Quotient.eq.2\n      rw [Submodule.quotientRel_r_def] at hc hm\n      intro i\n      exact I.mul_sub_mul_mem hc (hm i)\n  one_smul := by\n    rintro ⟨a⟩\n    convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _\n    congr with i; exact one_mul (a i)\n  mul_smul := by\n    rintro ⟨a⟩ ⟨b⟩ ⟨c⟩\n    convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _\n    congr 1; funext i; exact mul_assoc a b (c i)\n  smul_add := by\n    rintro ⟨a⟩ ⟨b⟩ ⟨c⟩\n    convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _\n    congr with i; exact mul_add a (b i) (c i)\n  smul_zero := by\n    rintro ⟨a⟩\n    convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _\n    congr with _; exact mul_zero a\n  add_smul := by\n    rintro ⟨a⟩ ⟨b⟩ ⟨c⟩\n    convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _\n    congr with i; exact add_mul a b (c i)\n  zero_smul := by\n    rintro ⟨a⟩\n    convert_to Ideal.Quotient.mk (I.pi ι) _ = Ideal.Quotient.mk (I.pi ι) _\n    congr with i; exact zero_mul (a i)\n#align ideal.module_pi Ideal.modulePi\n\nset_option synthInstance.etaExperiment false in -- Porting note: needed, otherwise type times out\n/-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/\nnoncomputable def piQuotEquiv : ((ι → R) ⧸ I.pi ι) ≃ₗ[R ⧸ I] ι → (R ⧸ I) := by\n  refine' ⟨⟨⟨?toFun, _⟩, _⟩, ?invFun, _, _⟩\n  case toFun => set_option synthInstance.etaExperiment true in -- Porting note: to get `Module R R`\n    exact fun x ↦\n      Quotient.liftOn' x (fun f i => Ideal.Quotient.mk I (f i)) fun a b hab =>\n        funext fun i => (Submodule.Quotient.eq' _).2 (QuotientAddGroup.leftRel_apply.mp hab i)\n  case invFun =>\n    exact fun x ↦ Ideal.Quotient.mk (I.pi ι) fun i ↦ Quotient.out' (x i)\n  · rintro ⟨_⟩ ⟨_⟩; rfl\n  · rintro ⟨_⟩ ⟨_⟩; rfl\n  · rintro ⟨x⟩\n    exact Ideal.Quotient.eq.2 fun i => Ideal.Quotient.eq.1 (Quotient.out_eq' _)\n  · intro x\n    ext i\n    obtain ⟨_, _⟩ := @Quot.exists_rep _ _ (x i)\n    convert Quotient.out_eq' (x i)\n#align ideal.pi_quot_equiv Ideal.piQuotEquiv\n\n/-- If `f : R^n → R^m` is an `R`-linear map and `I ⊆ R` is an ideal, then the image of `I^n` is\n    contained in `I^m`. -/\ntheorem map_pi {ι : Type _} [Finite ι] {ι' : Type w} (x : ι → R) (hi : ∀ i, x i ∈ I)\n    (f : (ι → R) →ₗ[R] ι' → R) (i : ι') : f x i ∈ I := by\n  classical\n    cases nonempty_fintype ι\n    rw [pi_eq_sum_univ x]\n    simp only [Finset.sum_apply, smul_eq_mul, LinearMap.map_sum, Pi.smul_apply, LinearMap.map_smul]\n    exact I.sum_mem fun j _ => I.mul_mem_right _ (hi j)\n#align ideal.map_pi Ideal.map_pi\n\nend Pi\n\nsection ChineseRemainder\n\nvariable {ι : Type v}\n\ntheorem exists_sub_one_mem_and_mem (s : Finset ι) {f : ι → Ideal R}\n    (hf : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → f i ⊔ f j = ⊤) (i : ι) (his : i ∈ s) :\n    ∃ r : R, r - 1 ∈ f i ∧ ∀ j ∈ s, j ≠ i → r ∈ f j := by\n  have : ∀ j ∈ s, j ≠ i → ∃ r : R, ∃ _ : r - 1 ∈ f i, r ∈ f j := by\n    intro j hjs hji\n    specialize hf i his j hjs hji.symm\n    rw [eq_top_iff_one, Submodule.mem_sup] at hf\n    rcases hf with ⟨r, hri, s, hsj, hrs⟩\n    refine' ⟨1 - r, _, _⟩\n    · rw [sub_right_comm, sub_self, zero_sub]\n      exact (f i).neg_mem hri\n    · rw [← hrs, add_sub_cancel']\n      exact hsj\n  classical\n    have : ∃ g : ι → R, (∀ j, g j - 1 ∈ f i) ∧ ∀ j ∈ s, j ≠ i → g j ∈ f j := by\n      choose g hg1 hg2 using this\n      refine' ⟨fun j => if H : j ∈ s ∧ j ≠ i then g j H.1 H.2 else 1, fun j => _, fun j => _⟩\n      · dsimp only\n        split_ifs with h\n        · apply hg1\n        rw [sub_self]\n        exact (f i).zero_mem\n      · intro hjs hji\n        dsimp only\n        rw [dif_pos]\n        · apply hg2\n        exact ⟨hjs, hji⟩\n    rcases this with ⟨g, hgi, hgj⟩\n    use ∏ x in s.erase i, g x\n    constructor\n    · rw [← Ideal.Quotient.mk_eq_mk_iff_sub_mem, map_one, map_prod]\n      apply Finset.prod_eq_one\n      intros\n      rw [← RingHom.map_one, Ideal.Quotient.mk_eq_mk_iff_sub_mem]\n      apply hgi\n    · intro j hjs hji\n      rw [← Quotient.eq_zero_iff_mem, map_prod]\n      -- Porting note: Added the below line to help instance inferrence\n      letI : CommMonoidWithZero (R ⧸ f j) := CommSemiring.toCommMonoidWithZero\n      refine' Finset.prod_eq_zero (Finset.mem_erase_of_ne_of_mem hji hjs) _\n      rw [Quotient.eq_zero_iff_mem]\n      exact hgj j hjs hji\n#align ideal.exists_sub_one_mem_and_mem Ideal.exists_sub_one_mem_and_mem\n\ntheorem exists_sub_mem [Finite ι] {f : ι → Ideal R} (hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤)\n    (g : ι → R) : ∃ r : R, ∀ i, r - g i ∈ f i := by\n  cases nonempty_fintype ι\n  have : ∃ φ : ι → R, (∀ i, φ i - 1 ∈ f i) ∧ ∀ i j, i ≠ j → φ i ∈ f j := by\n    have := exists_sub_one_mem_and_mem (Finset.univ : Finset ι) fun i _ j _ hij => hf i j hij\n    choose φ hφ using this\n    exists fun i => φ i (Finset.mem_univ i)\n    exact ⟨fun i => (hφ i _).1, fun i j hij => (hφ i _).2 j (Finset.mem_univ j) hij.symm⟩\n  rcases this with ⟨φ, hφ1, hφ2⟩\n  use ∑ i, g i * φ i\n  intro i\n  rw [← Quotient.mk_eq_mk_iff_sub_mem, map_sum]\n  refine' Eq.trans (Finset.sum_eq_single i _ _) _\n  · intro j _ hji\n    rw [Quotient.eq_zero_iff_mem]\n    exact (f i).mul_mem_left _ (hφ2 j i hji)\n  · intro hi\n    exact (hi <| Finset.mem_univ i).elim\n  specialize hφ1 i\n  rw [← Quotient.mk_eq_mk_iff_sub_mem, RingHom.map_one] at hφ1\n  rw [RingHom.map_mul, hφ1, mul_one]\n#align ideal.exists_sub_mem Ideal.exists_sub_mem\n\n/-- The homomorphism from `R/(⋂ i, f i)` to `∏ i, (R / f i)` featured in the Chinese\n  Remainder Theorem. It is bijective if the ideals `f i` are comaximal. -/\ndef quotientInfToPiQuotient (f : ι → Ideal R) : (R ⧸ ⨅ i, f i) →+* ∀ i, R ⧸ f i :=\n  Quotient.lift (⨅ i, f i) (Pi.ringHom fun i : ι => (Quotient.mk (f i) : _)) fun r hr =>\n    by\n    rw [Submodule.mem_infᵢ] at hr\n    ext i\n    exact Quotient.eq_zero_iff_mem.2 (hr i)\n#align ideal.quotient_inf_to_pi_quotient Ideal.quotientInfToPiQuotient\n\ntheorem quotientInfToPiQuotient_bijective [Finite ι] {f : ι → Ideal R}\n    (hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) : Function.Bijective (quotientInfToPiQuotient f) :=\n  ⟨fun x y =>\n    Quotient.inductionOn₂' x y fun r s hrs =>\n      Quotient.eq.2 <|\n        (Submodule.mem_infᵢ _).2 fun i =>\n          Quotient.eq.1 <|\n            show quotientInfToPiQuotient f (Quotient.mk'' r) i = _ by rw [hrs]; rfl,\n    fun g =>\n    let ⟨r, hr⟩ := exists_sub_mem hf fun i => Quotient.out' (g i)\n    ⟨Quotient.mk _ r, funext fun i => Quotient.out_eq' (g i) ▸ Quotient.eq.2 (hr i)⟩⟩\n#align ideal.quotient_inf_to_pi_quotient_bijective Ideal.quotientInfToPiQuotient_bijective\n\n/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/\nnoncomputable def quotientInfRingEquivPiQuotient [Finite ι] (f : ι → Ideal R)\n    (hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) : (R ⧸ ⨅ i, f i) ≃+* ∀ i, R ⧸ f i :=\n  { Equiv.ofBijective _ (quotientInfToPiQuotient_bijective hf), quotientInfToPiQuotient f with }\n#align ideal.quotient_inf_ring_equiv_pi_quotient Ideal.quotientInfRingEquivPiQuotient\n\nend ChineseRemainder\n\n/-- **Chinese remainder theorem**, specialized to two ideals. -/\nnoncomputable def quotientInfEquivQuotientProd (I J : Ideal R) (coprime : I ⊔ J = ⊤) :\n    R ⧸ I ⊓ J ≃+* (R ⧸ I) × R ⧸ J :=\n  let f : Fin 2 → Ideal R := ![I, J]\n  have hf : ∀ i j : Fin 2, i ≠ j → f i ⊔ f j = ⊤ := by\n    intro i j h\n    fin_cases i <;> fin_cases j <;> try contradiction\n    · assumption\n    · rwa [sup_comm]\n  (Ideal.quotEquivOfEq (by simp [infᵢ, inf_comm])).trans <|\n            (Ideal.quotientInfRingEquivPiQuotient f hf).trans <| RingEquiv.piFinTwo fun i => R ⧸ f i\n#align ideal.quotient_inf_equiv_quotient_prod Ideal.quotientInfEquivQuotientProd\n\n@[simp]\ntheorem quotientInfEquivQuotientProd_fst (I J : Ideal R) (coprime : I ⊔ J = ⊤) (x : R ⧸ I ⊓ J) :\n    (quotientInfEquivQuotientProd I J coprime x).fst =\n      Ideal.Quotient.factor (I ⊓ J) I inf_le_left x :=\n  Quot.inductionOn x fun _ => rfl\n#align ideal.quotient_inf_equiv_quotient_prod_fst Ideal.quotientInfEquivQuotientProd_fst\n\n@[simp]\ntheorem quotientInfEquivQuotientProd_snd (I J : Ideal R) (coprime : I ⊔ J = ⊤) (x : R ⧸ I ⊓ J) :\n    (quotientInfEquivQuotientProd I J coprime x).snd =\n      Ideal.Quotient.factor (I ⊓ J) J inf_le_right x :=\n  Quot.inductionOn x fun _ => rfl\n#align ideal.quotient_inf_equiv_quotient_prod_snd Ideal.quotientInfEquivQuotientProd_snd\n\n@[simp]\ntheorem fst_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : I ⊔ J = ⊤) :\n    (RingHom.fst _ _).comp\n        (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) =\n      Ideal.Quotient.factor (I ⊓ J) I inf_le_left := by\n  apply Quotient.ringHom_ext; ext; rfl\n#align ideal.fst_comp_quotient_inf_equiv_quotient_prod Ideal.fst_comp_quotientInfEquivQuotientProd\n\n@[simp]\ntheorem snd_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : I ⊔ J = ⊤) :\n    (RingHom.snd _ _).comp\n        (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) =\n      Ideal.Quotient.factor (I ⊓ J) J inf_le_right := by\n  apply Quotient.ringHom_ext; ext; rfl\n#align ideal.snd_comp_quotient_inf_equiv_quotient_prod Ideal.snd_comp_quotientInfEquivQuotientProd\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/Quotient.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.8221891392358014, "lm_q1q2_score": 0.7512149162580996}}
{"text": "\n\n-- Exercise # 1\n\ntheorem and_com {p q : Prop} : p ∧ q ↔ q ∧ p :=\nbegin\n  apply iff.intro,\n  all_goals {intro h, constructor, {exact h.right}, {exact h.left}}\nend\n\n\nsection\nuniverse u\n\nvariables (α β : Type u)\n\nexample (α : Type u) (a b : α) (p : α → Prop) (h1 :a = b) (h2 : p a) : p b :=\n  by {rw h1 at h2, assumption}\n\nend\n\nsection\n\nvariables x y z : ℤ\nexample (x y z : ℕ) : x * (y + z) = x * y + x * z :=\n  by {apply left_distrib}\n\nend\n\nsection\nvariables (α : Type) (p q : α → Prop)\n\nexample (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x :=\nbegin\n  cases h with x pqx,\n  constructor, rw and_comm, assumption\nend\n\n\n-- Exercise # 2\nexample (p q r : Prop) (hp : p) :\n  (p ∨ q ∨ r) ∧ (q ∨ p ∨ r) ∧ (q ∨ r ∨ p) :=\n  by {split, any_goals {split}, all_goals { {left, assumption} <|> {right, left, assumption} <|> {right, right, assumption}}}\n\nend\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-8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.822189121808099, "lm_q1q2_score": 0.7512148964696058}}
{"text": "-- Asociativa_conmutativa_de_los_reales.lean\n-- Asociativa conmutativa de los reales.\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 22-agosto-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que los números reales tienen la siguente propiedad\n--    (a * b) * c = b * (a * c)\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables a b c : ℝ\n\n-- 1ª demostración\n-- ===============\n\nexample : (a * b) * c = b * (a * c) :=\nbegin\n  rw mul_comm a b,\n  rw mul_assoc b a c,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample : (a * b) * c = b * (a * c) :=\ncalc (a * b) * c\n     = (b * a) * c : by rw mul_comm a b\n ... = b * (a * c) : by rw mul_assoc b a c\n\n-- 3ª demostración\n-- ===============\n\nexample : (a * b) * c = b * (a * c) :=\ncalc (a * b) * c\n     = (b * a) * c : by ring\n ... = b * (a * c) : by ring\n\n-- 4ª demostración\n-- ===============\n\nexample : (a * b) * c = b * (a * c) :=\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/Asociativa_conmutativa_de_los_reales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7512144092281812}}
{"text": "/-\nCopyright (c) 2020 Kenny Lau. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor: Kenny Lau.\n-/\nimport Mathlib.PrePort\nimport Mathlib.Lean3Lib.init.default\nimport Mathlib.ring_theory.polynomial.default\nimport Mathlib.algebra.big_operators.basic\nimport Mathlib.PostPort\n\nuniverses u \n\nnamespace Mathlib\n\n/-!\n# Lagrange interpolation\n\n## Main definitions\n\n* `lagrange.basis s x` where `s : finset F` and `x : F`: the Lagrange basis polynomial\n  that evaluates to `1` at `x` and `0` at other elements of `s`.\n* `lagrange.interpolate s f` where `s : finset F` and `f : s → F`: the Lagrange interpolant\n  that evaluates to `f x` at `x` for `x ∈ s`.\n\n-/\n\nnamespace lagrange\n\n\n/-- Lagrange basis polynomials that evaluate to 1 at `x` and 0 at other elements of `s`. -/\ndef basis {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) : polynomial F :=\n  finset.prod (finset.erase s x) fun (y : F) => coe_fn polynomial.C (x - y⁻¹) * (polynomial.X - coe_fn polynomial.C y)\n\n@[simp] theorem basis_empty {F : Type u} [DecidableEq F] [field F] (x : F) : basis ∅ x = 1 :=\n  rfl\n\n@[simp] theorem eval_basis_self {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) : polynomial.eval x (basis s x) = 1 := sorry\n\n@[simp] theorem eval_basis_ne {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) (y : F) (h1 : y ∈ s) (h2 : y ≠ x) : polynomial.eval y (basis s x) = 0 := sorry\n\ntheorem eval_basis {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) (y : F) (h : y ∈ s) : polynomial.eval y (basis s x) = ite (y = x) 1 0 := sorry\n\n@[simp] theorem nat_degree_basis {F : Type u} [DecidableEq F] [field F] (s : finset F) (x : F) (hx : x ∈ s) : polynomial.nat_degree (basis s x) = finset.card s - 1 := sorry\n\n/-- Lagrange interpolation: given a finset `s` and a function `f : s → F`,\n`interpolate s f` is the unique polynomial of degree `< s.card`\nthat takes value `f x` on all `x` in `s`. -/\ndef interpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) : polynomial F :=\n  finset.sum (finset.attach s) fun (x : Subtype fun (x : F) => x ∈ s) => coe_fn polynomial.C (f x) * basis s ↑x\n\n@[simp] theorem interpolate_empty {F : Type u} [DecidableEq F] [field F] (f : ↥↑∅ → F) : interpolate ∅ f = 0 :=\n  rfl\n\n@[simp] theorem eval_interpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) (x : F) (H : x ∈ s) : polynomial.eval x (interpolate s f) = f { val := x, property := H } := sorry\n\ntheorem degree_interpolate_lt {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) : polynomial.degree (interpolate s f) < ↑(finset.card s) := sorry\n\n/-- Linear version of `interpolate`. -/\ndef linterpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) : linear_map F (↥↑s → F) (polynomial F) :=\n  linear_map.mk (interpolate s) sorry sorry\n\n@[simp] theorem interpolate_add {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) (g : ↥↑s → F) : interpolate s (f + g) = interpolate s f + interpolate s g :=\n  linear_map.map_add (linterpolate s) f g\n\n@[simp] theorem interpolate_zero {F : Type u} [DecidableEq F] [field F] (s : finset F) : interpolate s 0 = 0 :=\n  linear_map.map_zero (linterpolate s)\n\n@[simp] theorem interpolate_neg {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) : interpolate s (-f) = -interpolate s f :=\n  linear_map.map_neg (linterpolate s) f\n\n@[simp] theorem interpolate_sub {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : ↥↑s → F) (g : ↥↑s → F) : interpolate s (f - g) = interpolate s f - interpolate s g :=\n  linear_map.map_sub (linterpolate s) f g\n\n@[simp] theorem interpolate_smul {F : Type u} [DecidableEq F] [field F] (s : finset F) (c : F) (f : ↥↑s → F) : interpolate s (c • f) = c • interpolate s f :=\n  linear_map.map_smul (linterpolate s) c f\n\ntheorem eq_zero_of_eval_eq_zero {F' : Type u} [field F'] (s' : finset F') {f : polynomial F'} (hf1 : polynomial.degree f < ↑(finset.card s')) (hf2 : ∀ (x : F'), x ∈ s' → polynomial.eval x f = 0) : f = 0 := sorry\n\ntheorem eq_of_eval_eq {F' : Type u} [field F'] (s' : finset F') {f : polynomial F'} {g : polynomial F'} (hf : polynomial.degree f < ↑(finset.card s')) (hg : polynomial.degree g < ↑(finset.card s')) (hfg : ∀ (x : F'), x ∈ s' → polynomial.eval x f = polynomial.eval x g) : f = g := sorry\n\ntheorem eq_interpolate {F : Type u} [DecidableEq F] [field F] (s : finset F) (f : polynomial F) (hf : polynomial.degree f < ↑(finset.card s)) : (interpolate s fun (x : ↥↑s) => polynomial.eval (↑x) f) = f :=\n  eq_of_eval_eq s (degree_interpolate_lt s fun (x : ↥↑s) => polynomial.eval (↑x) f) hf\n    fun (x : F) (hx : x ∈ s) => eval_interpolate s (fun (x : ↥↑s) => polynomial.eval (↑x) f) x hx\n\n/-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials\nof degree less than `s.card`. -/\ndef fun_equiv_degree_lt {F : Type u} [DecidableEq F] [field F] (s : finset F) : linear_equiv F (↥(polynomial.degree_lt F (finset.card s))) (↥↑s → F) :=\n  linear_equiv.mk (fun (f : ↥(polynomial.degree_lt F (finset.card s))) (x : ↥↑s) => polynomial.eval (↑x) (subtype.val f))\n    sorry sorry (fun (f : ↥↑s → F) => { val := interpolate s f, property := 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/linear_algebra/lagrange.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787566, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7512046887918552}}
{"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.continuum\nimport analysis.specific_limits.basic\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. `#ℝ = 𝔠`.\n\nWe show that `#ℝ ≤ 𝔠` by noting that every real number is determined by a Cauchy-sequence of the\nform `ℕ → ℚ`, which has cardinality `𝔠`. To show that `#ℝ ≥ 𝔠` we define an injection from\n`{0, 1} ^ ℕ` to `ℝ` with `f ↦ Σ 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} ^ ℕ` to `ℝ` by\n  `f ↦ Σ' n, f n * (1 / 3) ^ n`\n\n## Main statements\n\n* `cardinal.mk_real : #ℝ = 𝔠`: 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 ∈ {i,o,c}` state that intervals on the reals\n  have cardinality continuum.\n\n## Notation\n\n* `𝔠` : 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 : ℝ} {f g : ℕ → bool} {n : ℕ}\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 : ℝ) (f : ℕ → bool) (n : ℕ) : ℝ := 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 ≤ c) : 0 ≤ 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 : ℕ → bool) :\n  (λ n, cantor_function_aux c f (n + 1)) = λ n, c * cantor_function_aux c (λ n, f (n + 1)) n :=\nby { ext n, cases h : f (n + 1); simp [h, pow_succ] }\n\nlemma summable_cantor_function (f : ℕ → bool) (h1 : 0 ≤ 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 : ℕ → bool)` is `Σ 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 : ℝ) (f : ℕ → bool) : ℝ := ∑' n, cantor_function_aux c f n\n\nlemma cantor_function_le (h1 : 0 ≤ c) (h2 : c < 1) (h3 : ∀ n, f n → g n) :\n  cantor_function c f ≤ 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 : ℕ → bool) (h1 : 0 ≤ c) (h2 : c < 1) :\n  cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (λ 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 `ℕ → 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 : ℕ} {f g : ℕ → bool}\n  (hn : ∀(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 : ℕ → bool := λ n, nat.rec ff (λ _ _, tt) n,\n    have hf_max : ∀n, f n → f_max n,\n    { intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },\n    let g_min : ℕ → bool := λ n, nat.rec tt (λ _ _, ff) n,\n    have hg_min : ∀n, g_min n → 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          ←tsum_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 (λ 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 : ∃n, f n ≠ g n,\n  { rw [←not_forall], intro h', apply h, ext, apply h' },\n  let n := nat.find this,\n  have hn : ∀ (k : ℕ), k < n → 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 [←fn], apply ne.symm, exact nat.find_spec this },\n  { apply ne_of_gt, refine increasing_cantor_function h1 h2 (λ k hk, (hn k hk).symm) _ fn,\n    apply eq_ff_of_not_eq_tt, rw [←fn], apply ne.symm, exact nat.find_spec this }\nend\n\n/-- The cardinality of the reals, as a type. -/\nlemma mk_real : #ℝ = 𝔠 :=\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 [← power_def, mk_nat, mk_rat, omega_power_omega] },\n  { convert mk_le_of_injective (cantor_function_injective _ _),\n    rw [←power_def, mk_bool, mk_nat, two_power_omega], 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 ℝ) = 𝔠 :=\nby rw [mk_univ, mk_real]\n\n/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/\nlemma not_countable_real : ¬ countable (set.univ : set ℝ) :=\nby { rw [← mk_set_le_omega, not_le, mk_univ_real], apply cantor }\n\n/-- The cardinality of the interval (a, ∞). -/\nlemma mk_Ioi_real (a : ℝ) : #(Ioi a) = 𝔠 :=\nbegin\n  refine le_antisymm (mk_real ▸ mk_set_le _) _,\n  rw [← not_lt], intro h,\n  refine ne_of_lt _ mk_univ_real,\n  have hu : Iio a ∪ {a} ∪ Ioi a = set.univ,\n  { convert Iic_union_Ioi, exact Iio_union_right },\n  rw ← 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 : (λ x, a + a - x) '' Ioi a = Iio a,\n  { convert image_const_sub_Ioi _ _, simp },\n  rw ← 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, ∞). -/\nlemma mk_Ici_real (a : ℝ) : #(Ici a) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Ioi_real a ▸ mk_le_mk_of_subset Ioi_subset_Ici_self)\n\n/-- The cardinality of the interval (-∞, a). -/\nlemma mk_Iio_real (a : ℝ) : #(Iio a) = 𝔠 :=\nbegin\n  refine le_antisymm (mk_real ▸ mk_set_le _) _,\n  have h2 : (λ x, a + a - x) '' Iio a = Ioi a,\n  { convert image_const_sub_Iio _ _, simp },\n  exact mk_Ioi_real a ▸ h2 ▸ mk_image_le\nend\n\n/-- The cardinality of the interval (-∞, a]. -/\nlemma mk_Iic_real (a : ℝ) : #(Iic a) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Iio_real a ▸ mk_le_mk_of_subset Iio_subset_Iic_self)\n\n/-- The cardinality of the interval (a, b). -/\nlemma mk_Ioo_real {a b : ℝ} (h : a < b) : #(Ioo a b) = 𝔠 :=\nbegin\n  refine le_antisymm (mk_real ▸ mk_set_le _) _,\n  have h1 : #((λ x, x - a) '' Ioo a b) ≤ #(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)) ≤ #(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 : ℝ} (h : a < b) : #(Icc a b) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Icc_self)\n\n/-- The cardinality of the interval (a, b]. -/\nlemma mk_Ioc_real {a b : ℝ} (h : a < b) : #(Ioc a b) = 𝔠 :=\nle_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Ioc_self)\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/data/real/cardinality.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418116217418, "lm_q2_score": 0.8128673223709251, "lm_q1q2_score": 0.7512046799039811}}
{"text": "import data.real 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' {α : Type u} [discrete_field α] (a : α) (n : ℕ) : (monoid.pow a n)⁻¹ = monoid.pow a⁻¹ 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 {α : Type u} [decidable_linear_ordered_comm_ring α] (a : α) (n : ℕ) : 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 {α : Type u}  [linear_ordered_semiring α] {x : α} {n m : ℕ} : 1 < x → n < m → 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 ←one_mul (1 : α),\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 {α : Type u}  [discrete_linear_ordered_field α] {x : α} {n m : ℕ} : x < 1 → 0 < x → n < m → monoid.pow x m < monoid.pow x n := begin\n  assume x1 x0 nm,rw [←inv_lt_inv,pow_inv',pow_inv'],\n  have x11 : 1 < x⁻¹ ,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 : ℝ} (y : ℝ) : 1 < x → ∃ n : ℕ, y < monoid.pow x n := begin\n  assume x1,\n  have : ∀ m : ℕ, (x - 1) * m < monoid.pow x m ∧ 1 ≤ monoid.pow x m,\n    assume m, induction m with m' hi,\n    simp,{norm_num},\n    rw [←add_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 ←sub_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 [←this, ←one_mul (1 : ℝ)],\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 {α : Type u} [has_add α] [has_zero α] (f : ℕ → α) : ℕ → α \n| 0        := 0\n| (succ n) := sum_lt_nat n + f n\n\nlemma sum_nonneg {α : Type u} [linear_ordered_semiring α] {f : ℕ → α} (n : ℕ) : (∀ m : ℕ, 0 ≤ f m) → 0 ≤ 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 {α : Type u} [semiring α] (f : ℕ → α) (a : α) (n : ℕ) : a * sum_lt_nat f n = sum_lt_nat (λ 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 {α : Type u} [linear_ordered_semiring α] {f : ℕ → α} (i j : ℕ) : (∀ m ≥ i, 0 ≤ f m) → i ≤ j → sum_lt_nat f i ≤ 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 ≤ k' + i,rw ←zero_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 ←zero_add (sum_lt_nat f (k' + i)),refine add_le_add _ _,refine h _ ik,simp,\nend\n\nlemma sum_le_of_terms_le₁ {α : Type u} [linear_ordered_semiring α] {f g : ℕ → α} (i j : ℕ) : i ≤ j → (∀ m ≥ i, f m ≤ g m) → sum_lt_nat f j + sum_lt_nat g i ≤ sum_lt_nat g j + sum_lt_nat f i := begin\n  generalize hk : j - i = k,revert i j,\n  induction k with k' hi,assume i j hk ij h,\n  rw nat.sub_eq_zero_iff_le at hk, replace ij := le_antisymm hk ij,rw [ij,add_comm],\n  assume i j hk ij h,rw [nat.sub_eq_iff_eq_add ij,succ_add] at hk,rw hk,simp!,\n  have ik : i ≤ k' + i,rw ←zero_add i,refine add_le_add _ _,exact zero_le _,simp,\n  refine add_le_add _ _,\n  refine h _ ik,\n  have := hi i (k' + i) (by rw nat.add_sub_cancel) ik h,\n  rwa [add_comm,add_comm _ (sum_lt_nat g (k' + i))],\nend\n\nlemma sum_le_of_terms_le₂ {α : Type u} [linear_ordered_ring α] {f g : ℕ → α} (i j : ℕ) : i ≤ j → (∀ m ≥ i, f m ≤ g m) → sum_lt_nat f j - sum_lt_nat f i ≤ sum_lt_nat g j - sum_lt_nat g i := begin\n  assume ij h,\n  have := sum_le_of_terms_le₁ i j ij h,rw sub_le_iff_le_add,rw add_comm,rw ←add_sub_assoc,rwa le_sub_iff_add_le,rwa add_comm (sum_lt_nat f i),\nend\nlemma geometric_series_l (n : ℕ) (x : ℝ) : x ≠ 1 → sum_lt_nat (monoid.pow x) n = (1 - monoid.pow x n) / (1 - x) := begin\n  assume x1,have x1' : 1 + -x ≠ 0,assume h,rw [eq_comm, ←sub_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 : ℝ) : abs x < 1 → is_cau_seq (sum_lt_nat (monoid.pow x)):= begin\n  assume x1, have : sum_lt_nat (monoid.pow x) = λ 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 ←h at x1,\n  have : ¬abs (1 : ℝ) < 1,norm_num,trivial,simp at absx,\n  cases classical.em (x = 0),rw h,simp[monoid.pow],assume ε ε0,existsi 1,assume j j1,simpa!,\n  cases j,exact absurd j1 dec_trivial,simpa!,\n  have x2: 1 < (abs x)⁻¹,rw lt_inv,simpa,{norm_num},exact abs_pos_of_ne_zero h,\n  assume ε ε0,cases pow_unbounded_of_gt_one (2 / (ε * abs (1 - x))) x2 with i hi,\n  rw [←pow_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 : ℝ) < 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 ←pow_abs,\n  rw [abs_neg,←pow_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 ε0 _,simpa,\n  refine pow_pos (abs_pos_of_ne_zero h) _,\nend\nlemma geometric_series_const (a x : ℝ) : abs x < 1 → is_cau_seq (sum_lt_nat (λ n, a * monoid.pow x n)) := begin\n  assume x1 ε ε0,\n  cases classical.em (a = 0),\n  existsi 0,intros,rw [←sum_lt_nat_mul],induction j,simp!,assumption,rw h,simpa!,\n  cases geometric_series_cauchy x x1 (ε / abs a) (div_pos ε0 (abs_pos_of_ne_zero h)) with i hi,\n  existsi i,assume j ji,rw [←sum_lt_nat_mul,←sum_lt_nat_mul,←mul_sub,abs_mul,mul_comm,←lt_div_iff],exact hi j ji,exact abs_pos_of_ne_zero h,\nend\nlemma le_test (f g : ℕ → ℝ) (n : ℕ) : (∀ m ≥ n, abs (f m) ≤ g m) → is_cau_seq (sum_lt_nat g) → is_cau_seq (sum_lt_nat f) := begin\n  assume hm hg ε ε0,cases hg (ε / 2) (div_pos ε0 (by norm_num)) with i hi,\n  existsi max n i,\n  assume j ji,\n  have hi₁ := hi j (le_trans (le_max_right n i) ji),\n  have hi₂ := 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₁ hi₂,rw abs_sub (sum_lt_nat g (max n i)) at this,\n  have ε2 : ε / 2 + ε / 2 = ε,rw [←add_div,(by ring : ε + ε = ε * 2),mul_div_cancel],{norm_num},\n  rw ε2 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 : ∀ m : ℕ, m ≥ max n i → f m ≤ abs (f m),assume m h, exact le_abs_self _,\n  have := sum_le_of_terms_le₂ (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₂ _ _ _ _,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₂ _ _ _ _,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 ←abs_neg, exact le_abs_self _,\nend\n\nlemma exp_series_cau (x : ℝ) : is_cau_seq (sum_lt_nat (λ m, monoid.pow x m / fact m)) := begin\n  have nat_nonneg : ∀ n : ℕ, 0 ≤ (n : ℝ),assume n,rw [←nat.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 : ℝ)],simpa,\n  rw [←nat.cast_zero,(λ x y, by simp : ∀ x y : ℝ, x ≥ y ↔ y ≤ 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 / ↑n)) _),\n  assume m mn,\n  generalize hk : m - n = k,\n  have :  monoid.pow (abs (x / ↑n)) m = monoid.pow (abs x) m * (monoid.pow (n : ℝ) m)⁻¹,\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 ↑n m)⁻¹ * (↑n)⁻¹) = (abs x * (n : ℝ)⁻¹) * ((monoid.pow n m)⁻¹ * monoid.pow (abs x) m),ring,\n    rw this,rw [←div_eq_mul_inv,hi,abs_div],have : abs (n : ℝ) = n,rw abs_of_nonneg,rw[← nat.cast_zero,(λ x y, by simp : Π x y : ℝ, x ≥ y ↔ y ≤ x),nat.cast_le],exact zero_le _,\n    rw this,ring,\n  rw [this,mul_left_comm,abs_div,div_eq_mul_inv,←pow_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,←one_mul (1 : ℝ)],refine mul_le_mul _ _ _ _,\n  rw [←nat.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 [←nat.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 ≥ n,rw ←zero_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',←mul_assoc],\n  refine mul_le_mul _ _ _ _,assumption,\n  rw inv_le_inv,refine le_trans _ (le_abs_self _),\n  rw [nat.cast_le,←add_succ,←add_zero n],refine add_le_add _ _,\n  simp,exact zero_le _,\n  refine abs_pos_of_ne_zero _,\n  rw [←nat.cast_zero,ne.def,nat.cast_inj],exact dec_trivial,\n  refine lt_of_le_of_lt _ nx,exact abs_nonneg _,\n  rw ←abs_inv,exact abs_nonneg _,\n  refine mul_nonneg _ _,\n  refine pow_nonneg _ _,rw [← nat.cast_zero,(λ x y,by simp : Π x y : ℝ, x ≥ y ↔ y ≤ x), nat.cast_le],exact zero_le _,\n  rw [(λ x y,by simp : Π x y : ℝ, x ≥ y ↔ y ≤ 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 : ℝ) : ℝ := lim ⟨(sum_lt_nat (λ m, monoid.pow x m / fact m)), exp_series_cau x⟩\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_real_exponential.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418137109956, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7512046690338875}}
{"text": "\nimport analysis.calculus.local_extr\nimport analysis.convex.slope\nimport analysis.convex.topology\nimport data.complex.is_R_or_C\nimport data.real.basic\nimport tactic.suggest\nimport tuto_lib\nimport data.nat.modeq\nimport tactic\n\n-- whnf, weak head normal form\n--\n-- normal form\n-- 1 + 2 is not normal form, since it can be evaluated to 3, thus\n-- the normal form is 3 since there is nothing to be further evaluated\n-- \n-- weak head normal form only evaluates the outermost structure,\n-- sub-expressions may not have been evaluated\n-- \n-- (Haskell example) (1 + 1, 2 + 2) is in whnf since the outermost\n-- expression, the data constructor (,) cannot be further evaluated\n-- \n-- https://stackoverflow.com/questions/6872898/what-is-weak-head-normal-form\n\nexample (a b c d : ℕ) : (a * d) * (b * c) = (d * a) * (c * b) :=\nbegin\n  -- solutions to a = (b * c) = a * (c * b)\n\n  -- rw mul_comm,             -- unhelpful, it doesn't rewrite what we want it to\n  \n  -- rw mul_comm b c,\n\n  -- nth_rewrite 1 mul_comm,  -- another useful tactic\n\n  -- solution to (a * d) * (b * c) = (d * a) * (c * b)\n\n  conv\n  begin                       -- | (a * d) * (b * c) = a * (c * b)\n    to_lhs,                   -- | (a * d) * (b * c)\n    congr,                    -- 2 goals : | a * d and | b * c\n    rw mul_comm,              -- | d * a\n    skip,                     -- | b * c\n    rw mul_comm,              -- | c * b\n  end,                        -- ⊢ (d * a) * (c * b) = (d * a) * (c * b)\nend\n\nexample : (λ x : ℕ, 0 + x) = (λ x, x) :=\nbegin\n  -- rw zero_add, -- unhelpful, can't get past λ binder\n  \n  -- by funext;\n  -- rw zero_add,\n\n  conv\n  begin           -- | (λ (x : ℕ), 0 + x) = λ (x : ℕ), x\n    to_lhs,       -- | λ (x : ℕ), 0 + x\n    funext,       -- | 0 + x\n    rw zero_add,  -- | x\n  end\nend\n\n-- \"Beware that a well known bug makes Lean printing: \"find converter failed, pattern was not found\"\n-- when the tactics inside conversion mode fail, even if the pattern was actually found.\"\nexample (a b c : ℕ) : a * (b * c) = a * (c * b) :=\nbegin\n  conv in (b*c)  -- finds the first match to the pattern\n  begin          -- | b * c\n    rw mul_comm, -- | c * b\n  end\nend\n\n-- one liner\nexample (a b c : ℕ) : a * (b * c) = a * (c * b) :=\nby conv in (b*c) { rw mul_comm }\n\n-- wildcard\nexample (a b c : ℕ) : a + (b * c) = a + (c * b) :=\nby conv in (_ * c) { rw mul_comm }\n\n-- mul_comm on only 2nd and 3rd (b * c)\nexample (a b c : ℕ) : (b * c) * (b * c) * (b * c) = (b * c) * (c * b)  * (c * b):=\nby conv { for (b * c) [2, 3] { rw mul_comm } }\n\n---------------------------------------------------------\n\n\n\n-- contrapose + push_neg = contrapose!\n\nexample (x y : ℝ) : x < y → y > x :=\nbegin\n  -- contrapose,     -- take the contrapositive\n  -- push_neg,       -- rewrite without negation\n  contrapose!,\n  simp,\nend\n\n-- calculation environment\n\nexample (a b c : ℕ) (H1 : a = b + 1) (H2 : b = c) : a = c + 1 :=\ncalc a = b + 1 : H1\n...    = c + 1 : by rw H2\n\nexample (a b c : ℕ) (H1 : a = b + 1) (H2 : b = c) : a = c + 1 :=\nbegin\n  calc a = b + 1 : H1\n  ...    = c + 1 : _,\n  { rw H2 }\nend\n\n-- Using operators other than equality\n\ndefinition j : ℕ → ℕ → Prop := sorry\n@[trans] theorem j_trans (a b c : ℕ) : j a b → j b c → j a c := sorry\ninfix `****`: 50 := j     -- left (by default) binding power of 50\n\nexample (a b c : ℕ) (H1 : a **** b) (H2 : b **** c) : a **** c :=\ncalc a **** b : H1\n...    **** c : H2\n\n-- Using more than one operator\n\ntheorem T2 (a b c d : ℕ)\n  (h1 : a = b) (h2 : b ≤ c) (h3 : c + 1 < d) : a < d :=\nbegin\ncalc\n  a     = b     : h1\n    ... < b + 1 : nat.lt_succ_self b\n    ... ≤ c + 1 : nat.succ_le_succ h2\n    ... < d     : h3,\nend\n\n-- \"The way this is done, Kevin thinks (can someone verify this?) is that Lean continually tries to amalgamate\n-- the first two operators in the list, until there is only one left.\"\n-- \n-- a = b < b + 1 ≤ c < d\n-- a < b + 1 ≤ c + 1 < d\n-- a < c + 1 < d\n-- a < d\n\n-- Lean recognizes that, given U op1 V and V op2 W, there may be some op3 (which could equal op1 or op2)\n-- such that U op3 W\n-- \"Lean knows:\n-- \n-- #check @trans_rel_right -- ∀ {α : Sort u_1} {a b c : α} (r : α → α → Prop), a = b → r b c → r a c\n-- #check @trans_rel_left -- ∀ {α : Sort u_1} {a b c : α} (r : α → α → Prop), r a b → b = c → r a c\n-- \n-- and (Kevin believes) uses them if one of the operators is an equality operator.\"\n-- If neither are an equality operator, lean searches the database of theorems tagged [trans]\n-- and applies them instead, for example\n\n-- @[trans] lemma lt_of_lt_of_le [preorder α] : ∀ {a b c : α}, a < b → b ≤ c → a < c\n-- @[trans] lemma lt_trans [preorder α] : ∀ {a b c : α}, a < b → b < c → a < c\n\n-- the combination of two operators can be a new operator\ndefinition r : ℕ → ℕ → Prop := sorry\ndefinition s : ℕ → ℕ → Prop := sorry\ndefinition t : ℕ → ℕ → Prop := sorry\n@[trans] theorem rst_trans (a b c : ℕ) : r a b → s b c → t a c := sorry\ninfix `***`: 50 := r\ninfix `&&&` : 50 := s\ninfix `%%%` : 50 := t\n\nexample (a b c : ℕ) (H1 : a *** b) (H2 : b &&& c) : a %%% c :=\ncalc a *** b : H1\n...    &&& c : H2\n\n-- https://leanprover-community.github.io/extras/calc.html\n\n--------------------------------------\n\n-- operator precedence parsing:\n\n-- left and right binding power (\"infix\" and \"infixr\"), \"prefix\"\n\n-- \"binding power\" defines which operations take precedence, similar to PEMDAS\n-- left and right binding power define operator associativity. 'a ~ b ~ c' can be interpreted as\n-- '(a ~ b) ~ c' or 'a ~ (b ~ c)', left or right binding power respectively determines which way\n-- it is interpreted\n\n-- \"When 'expression' is called, it is provided the 'rbp' - right binding power of the operator that called it.\n-- It consumes tokens until it meets a token whose left binding power is equal or lower than rbp. Specifically,\n-- it means that it collects all tokens that bind together before returning it to the operator that called it.\"\n\n-- negation has a left binding power of 100, i.e. negation of a variable should never be what ends\n-- the tokens binding together\n\n-- According to Eli Bendersky's simplified parser example, '(' has a lbp of 0, i.e. it should stop anything\n\n-- https://eli.thegreenplace.net/2010/01/02/top-down-operator-precedence-parsing\n\n-- binding power in lean:\n\n-- https://github.com/leanprover/lean/blob/master/library/init/core.lean\n\n/- Logical operations and relations -/\n\nreserve prefix `¬`:40\nreserve prefix `~`:40\nreserve infixr ` ∧ `:35\nreserve infixr ` /\\ `:35\nreserve infixr ` \\/ `:30\nreserve infixr ` ∨ `:30\nreserve infix ` <-> `:20\nreserve infix ` ↔ `:20\nreserve infix ` = `:50\nreserve infix ` == `:50\nreserve infix ` ≠ `:50\nreserve infix ` ≈ `:50\nreserve infix ` ~ `:50\nreserve infix ` ≡ `:50\nreserve infixl ` ⬝ `:75\nreserve infixr ` ▸ `:75\nreserve infixr ` ▹ `:75\n\n/- types and type constructors -/\n\nreserve infixr ` ⊕ `:30\nreserve infixr ` × `:35\n\n/- arithmetic operations -/\n\nreserve infixl ` + `:65\nreserve infixl ` - `:65\nreserve infixl ` * `:70\nreserve infixl ` / `:70\nreserve infixl ` % `:70\nreserve prefix `-`:100\nreserve infixr ` ^ `:80\n\nreserve infixr ` ∘ `:90                 -- input with \\comp\n\nreserve infix ` <= `:50\nreserve infix ` ≤ `:50\nreserve infix ` < `:50\nreserve infix ` >= `:50\nreserve infix ` ≥ `:50\nreserve infix ` > `:50\n\n/- boolean operations -/\n\nreserve infixl ` && `:70\nreserve infixl ` || `:65\n\n/- set operations -/\n\nreserve infix ` ∈ `:50\nreserve infix ` ∉ `:50\nreserve infixl ` ∩ `:70\nreserve infixl ` ∪ `:65\nreserve infix ` ⊆ `:50\nreserve infix ` ⊇ `:50\nreserve infix ` ⊂ `:50\nreserve infix ` ⊃ `:50\nreserve infix ` \\ `:70\n\n/- other symbols -/\n\nreserve infix ` ∣ `:50\nreserve infixl ` ++ `:65\nreserve infixr ` :: `:67\nreserve infixl `; `:1\n\n--------------------------------------\n\n-- some simplifications were made to make proving this easier, but perhaps the proof\n-- can be modified in order to remove them.\ntheorem ivt_0 (f : ℝ → ℝ) {a b y : ℝ} (hab : a < b) (hfab : f a < f b) (hfc : continuous_on f (set.Icc a b)) (hy : y ∈ set.Ioo (f a) (f b)):\n∃ (c : ℝ) (H : c ∈ set.Ioo a b), f(c) = y :=\nbegin\n  -- define a set S which contains all x in [a, b] such that f(x) < k\n  -- let c be the supremum of S\n  -- c ≠ a since by continuity of f and with ε = (k - f(a)) / 2 there is\n  -- some δ > 0 such that |a - x| < δ |f(x) - f(a)| < ε → f(x) < k, so since\n  -- ∃ x > a such that f(x) < k → x ∈ S, then a cannot be the supremum.\n  -- b cannot be the supremum for similar reasons, there is a neighborhood around b\n  -- where all f(x) are greater than k, so some value less than b must be the supremum.\n  -- Now, having c ∈ (a, b), use continuity to show that ∀ ε > 0 we have\n  -- k - ε < f(c) < k + ε, since if not then c would not be the supremum of S.\n  sorry,\nend\n\n-- theorem ivt (f : ℝ → ℝ) {a b : ℝ} (hab : a < b) (hfc : continuous_on f (set.Icc a b))\n\n--------------------------------------\n\ndef continuous_at_pt (f : ℝ → ℝ) (x₀ : ℝ) : Prop :=\n∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - f x₀| ≤ ε\n\nlemma is_sup_iff (A : set ℝ) (x : ℝ) :\n(is_sup A x) ↔ (upper_bound A x ∧ ∃ u : ℕ → ℝ, seq_limit u x ∧ ∀ n, u n ∈ A ) :=\nbegin\n  split,\n  { intro h,\n    split,\n    {\n      exact h.1,\n    },\n    { have : ∀ n : ℕ, ∃ a ∈ A, x - 1/(n+1) < a,\n      { intros n,\n        have : 1/(n+1 : ℝ) > 0,\n          exact nat.one_div_pos_of_nat,\n        exact lt_sup h _ (by linarith),\n      },\n      choose u hu using this,\n      use u,\n      split,\n      { apply squeeze (limit_const_sub_inv_succ x) (limit_const x),\n        { intros n,\n          exact le_of_lt (hu n).2, },\n        { intro n,\n          exact h.1 _ (hu n).left, } },\n      { intro n,\n        exact (hu n).left },\n  } },\n  { rintro ⟨maj, u, limu, u_in⟩, \n    split,\n    { exact maj },\n    { intros y ymaj,\n      apply lim_le limu,\n      intro n,\n      apply ymaj,\n      apply u_in },\n  },\nend\n\n\nvariables {f : ℝ → ℝ} {x₀ : ℝ} {u : ℕ → ℝ}\n\nlemma seq_continuous_of_continuous (hf : continuous_at_pt f x₀)\n  (hu : seq_limit u x₀) : seq_limit (f ∘ u) (f x₀) :=\nbegin\n  intros ε ε_pos,\n  unfold continuous_at_pt at hf,\n  rcases hf ε ε_pos with ⟨δ, δ_pos, hδ⟩,\n  cases hu δ δ_pos with N hN,\n  use N,\n  intros n hn,\n  apply hδ,\n  exact hN n hn,\nend\n\nlemma stupid {a b x : ℝ} (h : x ∈ set.Icc a b) (h' : x ≠ b) : x < b :=\nlt_of_le_of_ne h.right h'\n\nlemma le_lim {x y : ℝ} {u : ℕ → ℝ} (hu : seq_limit u x)\n  (ineg : ∃ N, ∀ n ≥ N, y ≤ u n) : y ≤ x :=\nbegin\n  apply le_of_le_add_all,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N hN,\n  cases ineg with N' hN',\n  let N₀ := max N N',\n  specialize hN N₀ (le_max_left N N'),\n  specialize hN' N₀ (le_max_right N N'),\n  rw abs_le at hN,\n  linarith,\nend\n\ntheorem ivt (f : ℝ → ℝ) (a b c : ℝ) (hab : a ≤ b) (hf : ∀ (x ∈ set.Icc a b), continuous_at_pt f x) (h₀ : f a < c) (h₁ : f b > c) :\n∃ x₀ ∈ set.Icc a b, f x₀ = c :=\nbegin\n  let A := { x | x ∈ set.Icc a b ∧ f x < c},\n  have ex_x₀ : ∃ x₀ ∈ set.Icc a b, is_sup A x₀,\n  {\n    apply sup_segment,\n      use a,\n      split,\n        split, linarith, linarith,\n      exact h₀,\n    intros x hx,\n    exact hx.left\n  },\n  rcases ex_x₀ with ⟨x₀, x₀_in, x₀_sup⟩,\n  use [x₀, x₀_in],\n  have : f x₀ ≤ c,\n  {\n    rw is_sup_iff at x₀_sup,\n    rcases x₀_sup with ⟨maj_x₀, u, lim_u, u_dans⟩,\n    have : seq_limit (f ∘ u) (f x₀),\n      exact seq_continuous_of_continuous (hf x₀ x₀_in) lim_u,\n    apply lim_le this,\n    intros n,\n    have : f (u n) < c,\n      exact (u_dans n).right,\n    linarith\n  },\n  have x₀_1: x₀ < b,\n  {\n    apply stupid x₀_in,\n    intro h,\n    rw ← h at h₁,\n    linarith\n  },\n  have : f x₀ ≥ c,\n  { have in_I : ∃ N : ℕ, ∀ n ≥ N, x₀ + 1/(n+1) ∈ set.Icc a b,\n    { have : ∃ N : ℕ, ∀ n≥ N, 1/(n+1 : ℝ) ≤ b-x₀,\n      {\n        apply inv_succ_le_all,\n        linarith,\n      },\n      cases this with N hN,\n      use N,\n      intros n hn,\n      specialize hN n hn,\n      have : 1/(n+1 : ℝ) > 0,\n        exact nat.one_div_pos_of_nat,\n      change a ≤ x₀ ∧ x₀ ≤ b at x₀_in,\n      split ; linarith,\n    },\n    have not_in : ∀ n : ℕ, x₀ + 1/(n+1) ∉ A,\n    {\n      intros n hn,\n      cases x₀_sup with x₀_maj _,\n      specialize x₀_maj _ hn,\n      have : 1/(n+1 : ℝ) > 0,\n        from nat.one_div_pos_of_nat,\n      linarith,\n    },\n    dsimp [A] at not_in,\n    push_neg at not_in,\n    have lim : seq_limit (λ n, f(x₀ + 1/(n+1))) (f x₀),\n    { apply seq_continuous_of_continuous (hf x₀ x₀_in),\n      apply limit_const_add_inv_succ },\n    apply le_lim lim,\n    cases in_I with N hN,\n    use N,\n    intros n hn,\n    exact not_in n (hN n hn),\n  },\n  linarith,\nend\n\n-- Next Steps: Currently, this proof requires a ≤ b and f a < f b. Can this proof\n-- be modified such that it works for a ≥ b and/or f a > f b? How about the trivial\n-- case f a = c = f b?", "meta": {"author": "raymondpg", "repo": "XLL", "sha": "f97237922687d0edfa3fdab4c9cb831b39284e49", "save_path": "github-repos/lean/raymondpg-XLL", "path": "github-repos/lean/raymondpg-XLL/XLL-f97237922687d0edfa3fdab4c9cb831b39284e49/src/Hastin/presentation.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.8991213799730774, "lm_q1q2_score": 0.7512011255577034}}
{"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_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/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.8991213718636754, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7512010985252802}}
{"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, Joachim Breitner\n\n! This file was ported from Lean 3 source module group_theory.nilpotent\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.GroupTheory.QuotientGroup\nimport Mathbin.GroupTheory.Solvable\nimport Mathbin.GroupTheory.PGroup\nimport Mathbin.GroupTheory.Sylow\nimport Mathbin.Data.Nat.Factorization.Basic\nimport Mathbin.Tactic.Tfae\n\n/-!\n\n# Nilpotent groups\n\nAn API for nilpotent groups, that is, groups for which the upper central series\nreaches `⊤`.\n\n## Main definitions\n\nRecall that if `H K : subgroup G` then `⁅H, K⁆ : subgroup G` is the subgroup of `G` generated\nby the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the\nsubgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`.\n\n* `upper_central_series G : ℕ → 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 = ⊥` and\n     `H (n + 1) / H n` is the centre of `G / H n`.\n* `lower_central_series G : ℕ → 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 = ⊤` and\n     `H (n + 1) = ⁅H n, G⁆`.\n* `is_nilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or\n    equivalently if its lower central series reaches `⊥`.\n* `nilpotency_class` : the length of the upper central series of a nilpotent group.\n* `is_ascending_central_series (H : ℕ → subgroup G) : Prop` and\n* `is_descending_central_series (H : ℕ → 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 `⊤`, finishing at `⊥`, 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 `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series\n    may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an\n    *ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no\n    requirement that the series reaches `⊤` 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 `⊤`.\n* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central\n    series reaches `⊤`.\n* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central\n    series reaches `⊥`.\n* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`.\n* The `nilpotency_class` can likeways be obtained from these equivalent\n  definitions, see `least_ascending_central_series_length_eq_nilpotency_class`,\n  `least_descending_central_series_length_eq_nilpotency_class` and\n  `lower_central_series_length_eq_nilpotency_class`.\n* If `G` is nilpotent, then so are its subgroups, images, quotients and preimages.\n  Binary and finite products of nilpotent groups are nilpotent.\n  Infinite products are nilpotent if their nilpotent class is bounded.\n  Corresponding lemmas about the `nilpotency_class` are provided.\n* The `nilpotency_class` of `G ⧸ center G` is given explicitly, and an induction principle\n  is derived from that.\n* `is_nilpotent.to_is_solvable`: If `G` is nilpotent, it is solvable.\n\n\n## Warning\n\nA \"central series\" is usually defined to be a finite sequence of normal subgroups going\nfrom `⊥` to `⊤` 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\n\nopen Subgroup\n\nsection WithGroup\n\nvariable {G : Type _} [Group G] (H : Subgroup G) [Normal H]\n\n/-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}`\nis a subgroup of `G` (because it is the preimage in `G` of the centre of the\nquotient group `G/H`.)\n-/\ndef upperCentralSeriesStep : Subgroup G\n    where\n  carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H }\n  one_mem' y := by simp [Subgroup.one_mem]\n  mul_mem' a b ha hb y :=\n    by\n    convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1\n    group\n  inv_mem' x hx y := by\n    specialize hx y⁻¹\n    rw [mul_assoc, inv_inv] at hx⊢\n    exact Subgroup.Normal.mem_comm inferInstance hx\n#align upper_central_series_step upperCentralSeriesStep\n\ntheorem mem_upperCentralSeriesStep (x : G) :\n    x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H :=\n  Iff.rfl\n#align mem_upper_central_series_step mem_upperCentralSeriesStep\n\nopen QuotientGroup\n\n/-- The proof that `upper_central_series_step H` is the preimage of the centre of `G/H` under\nthe canonical surjection. -/\ntheorem upperCentralSeriesStep_eq_comap_center :\n    upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) :=\n  by\n  ext\n  rw [mem_comap, mem_center_iff, forall_coe]\n  apply forall_congr'\n  intro y\n  rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem,\n    div_eq_mul_inv, mul_inv_rev, mul_assoc]\n#align upper_central_series_step_eq_comap_center upperCentralSeriesStep_eq_comap_center\n\ninstance : Normal (upperCentralSeriesStep H) :=\n  by\n  rw [upperCentralSeriesStep_eq_comap_center]\n  infer_instance\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 upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H\n  | 0 => ⟨⊥, inferInstance⟩\n  | n + 1 =>\n    let un := upperCentralSeriesAux n\n    let un_normal := un.2\n    ⟨upperCentralSeriesStep un.1, inferInstance⟩\n#align upper_central_series_aux upperCentralSeriesAux\n\n/-- `upper_central_series G n` is the `n`th term in the upper central series of `G`. -/\ndef upperCentralSeries (n : ℕ) : Subgroup G :=\n  (upperCentralSeriesAux G n).1\n#align upper_central_series upperCentralSeries\n\ninstance (n : ℕ) : Normal (upperCentralSeries G n) :=\n  (upperCentralSeriesAux G n).2\n\n@[simp]\ntheorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ :=\n  rfl\n#align upper_central_series_zero upperCentralSeries_zero\n\n@[simp]\ntheorem upperCentralSeries_one : upperCentralSeries G 1 = center G :=\n  by\n  ext\n  simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, center, Set.center,\n    mem_mk, mem_bot, Set.mem_setOf_eq]\n  exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm]\n#align upper_central_series_one upperCentralSeries_one\n\n/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such\nthat `⁅x,G⁆ ⊆ H n`-/\ntheorem mem_upperCentralSeries_succ_iff (n : ℕ) (x : G) :\n    x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n :=\n  Iff.rfl\n#align mem_upper_central_series_succ_iff mem_upperCentralSeries_succ_iff\n\n/- ./././Mathport/Syntax/Translate/Command.lean:388:30: infer kinds are unsupported in Lean 4: #[`nilpotent] [] -/\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.IsNilpotent (G : Type _) [Group G] : Prop where\n  nilpotent : ∃ n : ℕ, upperCentralSeries G n = ⊤\n#align group.is_nilpotent Group.IsNilpotent\n\nopen Group\n\nvariable {G}\n\n/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and\n  `⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/\ndef IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop :=\n  H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n\n#align is_ascending_central_series IsAscendingCentralSeries\n\n/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and\n  `⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not requre that `H n = {1}` for some `n`. -/\ndef IsDescendingCentralSeries (H : ℕ → Subgroup G) :=\n  H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1)\n#align is_descending_central_series IsDescendingCentralSeries\n\n/-- Any ascending central series for a group is bounded above by the upper central series. -/\ntheorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) :\n    ∀ n : ℕ, H n ≤ upperCentralSeries G n\n  | 0 => hH.1.symm ▸ le_refl ⊥\n  | n + 1 => by\n    intro x hx\n    rw [mem_upperCentralSeries_succ_iff]\n    exact fun y => ascending_central_series_le_upper n (hH.2 x n hx y)\n#align ascending_central_series_le_upper ascending_central_series_le_upper\n\nvariable (G)\n\n/-- The upper central series of a group is an ascending central series. -/\ntheorem upperCentralSeries_isAscendingCentralSeries :\n    IsAscendingCentralSeries (upperCentralSeries G) :=\n  ⟨rfl, fun x n h => h⟩\n#align upper_central_series_is_ascending_central_series upperCentralSeries_isAscendingCentralSeries\n\ntheorem upperCentralSeries_mono : Monotone (upperCentralSeries G) :=\n  by\n  refine' monotone_nat_of_le_succ _\n  intro n x hx y\n  rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹]\n  exact mul_mem hx (normal.conj_mem (upperCentralSeries.Subgroup.normal G n) x⁻¹ (inv_mem hx) y)\n#align upper_central_series_mono upperCentralSeries_mono\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    IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ :=\n  by\n  constructor\n  · rintro ⟨n, nH⟩\n    refine' ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩\n  · rintro ⟨n, H, hH, hn⟩\n    use n\n    rw [eq_top_iff, ← hn]\n    exact ascending_central_series_le_upper H hH n\n#align nilpotent_iff_finite_ascending_central_series nilpotent_iff_finite_ascending_central_series\n\ntheorem is_decending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤)\n    (hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) :=\n  by\n  cases' hasc with h0 hH\n  refine' ⟨hn, fun x m hx g => _⟩\n  dsimp at hx\n  by_cases hm : n ≤ m\n  · rw [tsub_eq_zero_of_le hm, 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 [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_sub_succ]\n#align is_decending_rev_series_of_is_ascending is_decending_rev_series_of_is_ascending\n\ntheorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥)\n    (hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) :=\n  by\n  cases' hdesc with h0 hH\n  refine' ⟨hn, fun x m hx g => _⟩\n  dsimp only at hx⊢\n  by_cases hm : n ≤ m\n  · have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm\n    rw [hnm, h0]\n    exact mem_top _\n  · push_neg  at hm\n    convert hH x _ hx g\n    rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_sub_succ]\n#align is_ascending_rev_series_of_is_descending is_ascending_rev_series_of_is_descending\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    IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ :=\n  by\n  rw [nilpotent_iff_finite_ascending_central_series]\n  constructor\n  · rintro ⟨n, H, hH, hn⟩\n    refine' ⟨n, fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, _⟩\n    rw [tsub_self]\n    exact hH.1\n  · rintro ⟨n, H, hH, hn⟩\n    refine' ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, _⟩\n    rw [tsub_self]\n    exact hH.1\n#align nilpotent_iff_finite_descending_central_series nilpotent_iff_finite_descending_central_series\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≥1`, `H (n + 1) = ⁅H n, G⁆` -/\ndef lowerCentralSeries (G : Type _) [Group G] : ℕ → Subgroup G\n  | 0 => ⊤\n  | n + 1 => ⁅lowerCentralSeries n, ⊤⁆\n#align lower_central_series lowerCentralSeries\n\nvariable {G}\n\n@[simp]\ntheorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ :=\n  rfl\n#align lower_central_series_zero lowerCentralSeries_zero\n\n@[simp]\ntheorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G :=\n  rfl\n#align lower_central_series_one lowerCentralSeries_one\n\ntheorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) :\n    q ∈ lowerCentralSeries G (n + 1) ↔\n      q ∈\n        closure\n          { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=\n  Iff.rfl\n#align mem_lower_central_series_succ_iff mem_lowerCentralSeries_succ_iff\n\ntheorem lowerCentralSeries_succ (n : ℕ) :\n    lowerCentralSeries G (n + 1) =\n      closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=\n  rfl\n#align lower_central_series_succ lowerCentralSeries_succ\n\ninstance (n : ℕ) : Normal (lowerCentralSeries G n) :=\n  by\n  induction' n with d hd\n  · exact (⊤ : Subgroup G).normal_of_characteristic\n  · exact Subgroup.commutator_normal (lowerCentralSeries G d) ⊤\n\ntheorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) :=\n  by\n  refine' antitone_nat_of_succ_le fun n x hx => _\n  simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left,\n    true_and_iff] at hx\n  refine'\n    closure_induction hx _ (Subgroup.one_mem _) (@Subgroup.mul_mem _ _ _) (@Subgroup.inv_mem _ _ _)\n  rintro y ⟨z, hz, a, ha⟩\n  rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹]\n  exact mul_mem hz (normal.conj_mem (lowerCentralSeries.Subgroup.normal n) z⁻¹ (inv_mem hz) a)\n#align lower_central_series_antitone lowerCentralSeries_antitone\n\n/-- The lower central series of a group is a descending central series. -/\ntheorem lowerCentralSeries_isDescendingCentralSeries :\n    IsDescendingCentralSeries (lowerCentralSeries G) :=\n  by\n  constructor; rfl\n  intro x n hxn g\n  exact commutator_mem_commutator hxn (mem_top g)\n#align lower_central_series_is_descending_central_series lowerCentralSeries_isDescendingCentralSeries\n\n/-- Any descending central series for a group is bounded below by the lower central series. -/\ntheorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) :\n    ∀ n : ℕ, lowerCentralSeries G n ≤ H n\n  | 0 => hH.1.symm ▸ le_refl ⊤\n  | n + 1 => commutator_le.mpr fun x hx q _ => hH.2 x n (descending_central_series_ge_lower n hx) q\n#align descending_central_series_ge_lower descending_central_series_ge_lower\n\n/-- A group is nilpotent if and only if its lower central series eventually reaches\n  the trivial subgroup. -/\ntheorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ :=\n  by\n  rw [nilpotent_iff_finite_descending_central_series]\n  constructor\n  · rintro ⟨n, H, ⟨h0, hs⟩, hn⟩\n    use n\n    rw [eq_bot_iff, ← hn]\n    exact descending_central_series_ge_lower H ⟨h0, hs⟩ n\n  · rintro ⟨n, hn⟩\n    exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩\n#align nilpotent_iff_lower_central_series nilpotent_iff_lowerCentralSeries\n\nsection Classical\n\nopen Classical\n\nvariable [hG : IsNilpotent G]\n\ninclude hG\n\nvariable (G)\n\n/-- The nilpotency class of a nilpotent group is the smallest natural `n` such that\nthe `n`'th term of the upper central series is `G`. -/\nnoncomputable def Group.nilpotencyClass : ℕ :=\n  Nat.find (IsNilpotent.nilpotent G)\n#align group.nilpotency_class Group.nilpotencyClass\n\nvariable {G}\n\n@[simp]\ntheorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ :=\n  Nat.find_spec (IsNilpotent.nilpotent G)\n#align upper_central_series_nilpotency_class upperCentralSeries_nilpotencyClass\n\ntheorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} :\n    upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n :=\n  by\n  constructor\n  · intro h\n    exact Nat.find_le h\n  · intro h\n    apply eq_top_iff.mpr\n    rw [← upperCentralSeries_nilpotencyClass]\n    exact upperCentralSeries_mono _ h\n#align upper_central_series_eq_top_iff_nilpotency_class_le upperCentralSeries_eq_top_iff_nilpotencyClass_le\n\n/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending\ncentral series reaches `G` in its `n`'th term. -/\ntheorem least_ascending_central_series_length_eq_nilpotencyClass :\n    Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) = Group.nilpotencyClass G :=\n  by\n  refine' le_antisymm (Nat.find_mono _) (Nat.find_mono _)\n  · intro n hn\n    exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩\n  · rintro n ⟨H, ⟨hH, hn⟩⟩\n    rw [← top_le_iff, ← hn]\n    exact ascending_central_series_le_upper H hH n\n#align least_ascending_central_series_length_eq_nilpotency_class least_ascending_central_series_length_eq_nilpotencyClass\n\n/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending\ncentral series reaches `⊥` in its `n`'th term. -/\ntheorem least_descending_central_series_length_eq_nilpotencyClass :\n    Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) = Group.nilpotencyClass G :=\n  by\n  rw [← least_ascending_central_series_length_eq_nilpotencyClass]\n  refine' le_antisymm (Nat.find_mono _) (Nat.find_mono _)\n  · rintro n ⟨H, ⟨hH, hn⟩⟩\n    refine' ⟨fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, _⟩\n    rw [tsub_self]\n    exact hH.1\n  · rintro n ⟨H, ⟨hH, hn⟩⟩\n    refine' ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, _⟩\n    rw [tsub_self]\n    exact hH.1\n#align least_descending_central_series_length_eq_nilpotency_class least_descending_central_series_length_eq_nilpotencyClass\n\n/-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/\ntheorem lowerCentralSeries_length_eq_nilpotencyClass :\n    Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = @Group.nilpotencyClass G _ _ :=\n  by\n  rw [← least_descending_central_series_length_eq_nilpotencyClass]\n  refine' le_antisymm (Nat.find_mono _) (Nat.find_mono _)\n  · rintro n ⟨H, ⟨hH, hn⟩⟩\n    rw [← le_bot_iff, ← hn]\n    exact descending_central_series_ge_lower H hH n\n  · rintro n h\n    exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩\n#align lower_central_series_length_eq_nilpotency_class lowerCentralSeries_length_eq_nilpotencyClass\n\n@[simp]\ntheorem lowerCentralSeries_nilpotencyClass : lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ :=\n  by\n  rw [← lowerCentralSeries_length_eq_nilpotencyClass]\n  exact Nat.find_spec (nilpotent_iff_lower_central_series.mp _)\n#align lower_central_series_nilpotency_class lowerCentralSeries_nilpotencyClass\n\ntheorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} :\n    lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n :=\n  by\n  constructor\n  · intro h\n    rw [← lowerCentralSeries_length_eq_nilpotencyClass]\n    exact Nat.find_le h\n  · intro h\n    apply eq_bot_iff.mpr\n    rw [← lowerCentralSeries_nilpotencyClass]\n    exact lowerCentralSeries_antitone h\n#align lower_central_series_eq_bot_iff_nilpotency_class_le lowerCentralSeries_eq_bot_iff_nilpotencyClass_le\n\nend Classical\n\ntheorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) :\n    (lowerCentralSeries H n).map H.Subtype ≤ lowerCentralSeries G n :=\n  by\n  induction' n with d hd\n  · simp\n  · rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure]\n    apply Subgroup.closure_mono\n    rintro x1 ⟨x2, ⟨x3, hx3, x4, hx4, rfl⟩, rfl⟩\n    exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩\n#align lower_central_series_map_subtype_le lowerCentralSeries_map_subtype_le\n\n/-- A subgroup of a nilpotent group is nilpotent -/\ninstance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H :=\n  by\n  rw [nilpotent_iff_lowerCentralSeries] at *\n  rcases hG with ⟨n, hG⟩\n  use n\n  have := lowerCentralSeries_map_subtype_le H n\n  simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this\n  exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x hx)\n#align subgroup.is_nilpotent Subgroup.isNilpotent\n\n/-- A the nilpotency class of a subgroup is less or equal the the nilpotency class of the group -/\ntheorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] :\n    Group.nilpotencyClass H ≤ Group.nilpotencyClass G :=\n  by\n  repeat' rw [← lowerCentralSeries_length_eq_nilpotencyClass]\n  apply Nat.find_mono\n  intro n hG\n  have := lowerCentralSeries_map_subtype_le H n\n  simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this\n  exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x hx)\n#align subgroup.nilpotency_class_le Subgroup.nilpotencyClass_le\n\ninstance (priority := 100) isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G :=\n  nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩\n#align is_nilpotent_of_subsingleton isNilpotent_of_subsingleton\n\ntheorem upperCentralSeries.map {H : Type _} [Group H] {f : G →* H} (h : Function.Surjective f)\n    (n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n :=\n  by\n  induction' n with d hd\n  · simp\n  · rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y'\n    rcases h y' with ⟨y, rfl⟩\n    simpa using hd (mem_map_of_mem f (hx y))\n#align upper_central_series.map upperCentralSeries.map\n\ntheorem lowerCentralSeries.map {H : Type _} [Group H] (f : G →* H) (n : ℕ) :\n    Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n :=\n  by\n  induction' n with d hd\n  · simp [Nat.zero_eq]\n  · rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩\n    refine'\n      closure_induction hx _ (by simp [f.map_one, Subgroup.one_mem _])\n        (fun y z hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) fun y hy => by\n        simp [f.map_inv, Subgroup.inv_mem _ hy]\n    rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩\n    apply mem_closure.mpr\n    exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩\n#align lower_central_series.map lowerCentralSeries.map\n\ntheorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) :\n    lowerCentralSeries G (n + 1) = ⊥ :=\n  by\n  rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff]\n  rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩\n  rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm]\n  exact mem_center_iff.mp (h hy1) z\n#align lower_central_series_succ_eq_bot lowerCentralSeries_succ_eq_bot\n\n/-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained\nin the center -/\ntheorem isNilpotent_of_ker_le_center {H : Type _} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G)\n    (hH : IsNilpotent H) : IsNilpotent G :=\n  by\n  rw [nilpotent_iff_lowerCentralSeries] at *\n  rcases hH with ⟨n, hn⟩\n  use n + 1\n  refine' lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp _) hf1)\n  exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n)\n#align is_nilpotent_of_ker_le_center isNilpotent_of_ker_le_center\n\ntheorem nilpotencyClass_le_of_ker_le_center {H : Type _} [Group H] (f : G →* H)\n    (hf1 : f.ker ≤ center G) (hH : IsNilpotent H) :\n    @Group.nilpotencyClass G _ (isNilpotent_of_ker_le_center f hf1 hH) ≤\n      Group.nilpotencyClass H + 1 :=\n  by\n  rw [← lowerCentralSeries_length_eq_nilpotencyClass]\n  apply Nat.find_min'\n  refine' lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp _) hf1)\n  apply eq_bot_iff.mpr\n  apply le_trans (lowerCentralSeries.map f _)\n  simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff]\n#align nilpotency_class_le_of_ker_le_center nilpotencyClass_le_of_ker_le_center\n\n/-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/\ntheorem nilpotent_of_surjective {G' : Type _} [Group G'] [h : IsNilpotent G] (f : G →* G')\n    (hf : Function.Surjective f) : IsNilpotent G' :=\n  by\n  rcases h with ⟨n, hn⟩\n  use n\n  apply eq_top_iff.mpr\n  calc\n    ⊤ = f.range := symm (f.range_top_of_surjective hf)\n    _ = Subgroup.map f ⊤ := (MonoidHom.range_eq_map _)\n    _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]\n    _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n\n    \n#align nilpotent_of_surjective nilpotent_of_surjective\n\n/-- The nilpotency class of the range of a surejctive homomorphism from a\nnilpotent group is less or equal the nilpotency class of the domain -/\ntheorem nilpotencyClass_le_of_surjective {G' : Type _} [Group G'] (f : G →* G')\n    (hf : Function.Surjective f) [h : IsNilpotent G] :\n    @Group.nilpotencyClass G' _ (nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G :=\n  by\n  apply Nat.find_mono\n  intro n hn\n  apply eq_top_iff.mpr\n  calc\n    ⊤ = f.range := symm (f.range_top_of_surjective hf)\n    _ = Subgroup.map f ⊤ := (MonoidHom.range_eq_map _)\n    _ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]\n    _ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n\n    \n#align nilpotency_class_le_of_surjective nilpotencyClass_le_of_surjective\n\n/-- Nilpotency respects isomorphisms -/\ntheorem nilpotent_of_mulEquiv {G' : Type _} [Group G'] [h : IsNilpotent G] (f : G ≃* G') :\n    IsNilpotent G' :=\n  nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f)\n#align nilpotent_of_mul_equiv nilpotent_of_mulEquiv\n\n/-- A quotient of a nilpotent group is nilpotent -/\ninstance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [h : IsNilpotent G] :\n    IsNilpotent (G ⧸ H) :=\n  nilpotent_of_surjective _ (show Function.Surjective (QuotientGroup.mk' H) by tidy)\n#align nilpotent_quotient_of_nilpotent nilpotent_quotient_of_nilpotent\n\n/-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/\ntheorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [h : IsNilpotent G] :\n    Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G :=\n  nilpotencyClass_le_of_surjective _ _\n#align nilpotency_class_quotient_le nilpotencyClass_quotient_le\n\n-- This technical lemma helps with rewriting the subgroup, which occurs in indices\nprivate theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) :\n    comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h\n#align comap_center_subst comap_center_subst\n\ntheorem comap_upperCentralSeries_quotient_center (n : ℕ) :\n    comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ :=\n  by\n  induction' n with n ih\n  · simp\n  · let Hn := upperCentralSeries (G ⧸ center G) n\n    calc\n      comap (mk' (center G)) (upperCentralSeriesStep Hn) =\n          comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) :=\n        by rw [upperCentralSeriesStep_eq_comap_center]\n      _ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) :=\n        QuotientGroup.comap_comap_center\n      _ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) :=\n        (comap_center_subst ih)\n      _ = upperCentralSeriesStep (upperCentralSeries G n.succ) :=\n        symm (upperCentralSeriesStep_eq_comap_center _)\n      \n#align comap_upper_central_series_quotient_center comap_upperCentralSeries_quotient_center\n\ntheorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] :\n    Group.nilpotencyClass G = 0 ↔ Subsingleton G := by\n  simp [Group.nilpotencyClass, Nat.find_eq_zero, subsingleton_iff_bot_eq_top]\n#align nilpotency_class_zero_iff_subsingleton nilpotencyClass_zero_iff_subsingleton\n\n/-- Quotienting the `center G` reduces the nilpotency class by 1 -/\ntheorem nilpotencyClass_quotient_center [hH : IsNilpotent G] :\n    Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 :=\n  by\n  generalize hn : Group.nilpotencyClass G = n\n  rcases n with (rfl | n)\n  · simp [nilpotencyClass_zero_iff_subsingleton] at *\n    haveI := hn\n    infer_instance\n  · suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa\n    apply le_antisymm\n    · apply upper_central_series_eq_top_iff_nilpotency_class_le.mp\n      apply @comap_injective G _ _ _ (mk' (center G)) (surjective_quot_mk _)\n      rw [comap_upperCentralSeries_quotient_center, comap_top, ← hn]\n      exact upperCentralSeries_nilpotencyClass\n    · apply le_of_add_le_add_right\n      calc\n        n + 1 = n.succ := rfl\n        _ = Group.nilpotencyClass G := (symm hn)\n        _ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 :=\n          nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk _)) _\n        \n#align nilpotency_class_quotient_center nilpotencyClass_quotient_center\n\n/-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/\ntheorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] :\n    Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 :=\n  by\n  rw [nilpotencyClass_quotient_center]\n  rcases h : Group.nilpotencyClass G with ⟨⟩\n  · exfalso\n    rw [nilpotencyClass_zero_iff_subsingleton] at h\n    skip\n    apply false_of_nontrivial_of_subsingleton G\n  · simp\n#align nilpotency_class_eq_quotient_center_plus_one nilpotencyClass_eq_quotient_center_plus_one\n\n/-- If the quotient by `center G` is nilpotent, then so is G. -/\ntheorem of_quotient_center_nilpotent (h : IsNilpotent (G ⧸ center G)) : IsNilpotent G :=\n  by\n  obtain ⟨n, hn⟩ := h.nilpotent\n  use n.succ\n  simp [← comap_upperCentralSeries_quotient_center, hn]\n#align of_quotient_center_nilpotent of_quotient_center_nilpotent\n\n/-- A custom induction principle for nilpotent groups. The base case is a trivial group\n(`subsingleton G`), and in the induction step, one can assume the hypothesis for\nthe group quotiented by its center. -/\n@[elab_as_elim]\ntheorem nilpotent_center_quotient_ind {P : ∀ (G) [Group G], ∀ [IsNilpotent G], Prop} (G : Type _)\n    [Group G] [IsNilpotent G] (hbase : ∀ (G) [Group G] [Subsingleton G], P G)\n    (hstep : ∀ (G) [Group G], ∀ [IsNilpotent G], ∀ ih : P (G ⧸ center G), P G) : P G :=\n  by\n  obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩\n  induction' n with n ih generalizing G\n  · haveI := nilpotency_class_zero_iff_subsingleton.mp h\n    exact hbase _\n  · have hn : Group.nilpotencyClass (G ⧸ center G) = n := by\n      simp [nilpotencyClass_quotient_center, h]\n    exact hstep _ (ih _ hn)\n#align nilpotent_center_quotient_ind nilpotent_center_quotient_ind\n\ntheorem derived_le_lower_central (n : ℕ) : derivedSeries G n ≤ lowerCentralSeries G n :=\n  by\n  induction' n with i ih\n  · simp\n  · apply commutator_mono ih\n    simp\n#align derived_le_lower_central derived_le_lower_central\n\n/-- Abelian groups are nilpotent -/\ninstance (priority := 100) CommGroup.isNilpotent {G : Type _} [CommGroup G] : IsNilpotent G :=\n  by\n  use 1\n  rw [upperCentralSeries_one]\n  apply CommGroup.center_eq_top\n#align comm_group.is_nilpotent CommGroup.isNilpotent\n\n/-- Abelian groups have nilpotency class at most one -/\ntheorem CommGroup.nilpotencyClass_le_one {G : Type _} [CommGroup G] : Group.nilpotencyClass G ≤ 1 :=\n  by\n  apply upper_central_series_eq_top_iff_nilpotency_class_le.mp\n  rw [upperCentralSeries_one]\n  apply CommGroup.center_eq_top\n#align comm_group.nilpotency_class_le_one CommGroup.nilpotencyClass_le_one\n\n/-- Groups with nilpotency class at most one are abelian -/\ndef commGroupOfNilpotencyClass [IsNilpotent G] (h : Group.nilpotencyClass G ≤ 1) : CommGroup G :=\n  Group.commGroupOfCenterEqTop <| by\n    rw [← upperCentralSeries_one]\n    exact upper_central_series_eq_top_iff_nilpotency_class_le.mpr h\n#align comm_group_of_nilpotency_class commGroupOfNilpotencyClass\n\nsection Prod\n\nvariable {G₁ G₂ : Type _} [Group G₁] [Group G₂]\n\ntheorem lowerCentralSeries_prod (n : ℕ) :\n    lowerCentralSeries (G₁ × G₂) n = (lowerCentralSeries G₁ n).Prod (lowerCentralSeries G₂ n) :=\n  by\n  induction' n with n ih\n  · simp\n  ·\n    calc\n      lowerCentralSeries (G₁ × G₂) n.succ = ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ := rfl\n      _ = ⁅(lowerCentralSeries G₁ n).Prod (lowerCentralSeries G₂ n), ⊤⁆ := by rw [ih]\n      _ = ⁅(lowerCentralSeries G₁ n).Prod (lowerCentralSeries G₂ n), (⊤ : Subgroup G₁).Prod ⊤⁆ := by\n        simp\n      _ = ⁅lowerCentralSeries G₁ n, (⊤ : Subgroup G₁)⁆.Prod ⁅lowerCentralSeries G₂ n, ⊤⁆ :=\n        (commutator_prod_prod _ _ _ _)\n      _ = (lowerCentralSeries G₁ n.succ).Prod (lowerCentralSeries G₂ n.succ) := rfl\n      \n#align lower_central_series_prod lowerCentralSeries_prod\n\n/-- Products of nilpotent groups are nilpotent -/\ninstance isNilpotent_prod [IsNilpotent G₁] [IsNilpotent G₂] : IsNilpotent (G₁ × G₂) :=\n  by\n  rw [nilpotent_iff_lowerCentralSeries]\n  refine' ⟨max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂), _⟩\n  rw [lowerCentralSeries_prod,\n    lower_central_series_eq_bot_iff_nilpotency_class_le.mpr (le_max_left _ _),\n    lower_central_series_eq_bot_iff_nilpotency_class_le.mpr (le_max_right _ _), bot_prod_bot]\n#align is_nilpotent_prod isNilpotent_prod\n\n/-- The nilpotency class of a product is the max of the nilpotency classes of the factors -/\ntheorem nilpotencyClass_prod [IsNilpotent G₁] [IsNilpotent G₂] :\n    Group.nilpotencyClass (G₁ × G₂) = max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂) :=\n  by\n  refine' eq_of_forall_ge_iff fun k => _\n  simp only [max_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,\n    lowerCentralSeries_prod, prod_eq_bot_iff]\n#align nilpotency_class_prod nilpotencyClass_prod\n\nend Prod\n\nsection BoundedPi\n\n-- First the case of infinite products with bounded nilpotency class\nvariable {η : Type _} {Gs : η → Type _} [∀ i, Group (Gs i)]\n\ntheorem lowerCentralSeries_pi_le (n : ℕ) :\n    lowerCentralSeries (∀ i, Gs i) n ≤ Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n :=\n  by\n  let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f\n  induction' n with n ih\n  · simp [pi_top]\n  ·\n    calc\n      lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl\n      _ ≤ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := (commutator_mono ih (le_refl _))\n      _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]\n      _ ≤ pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := (commutator_pi_pi_le _ _)\n      _ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl\n      \n#align lower_central_series_pi_le lowerCentralSeries_pi_le\n\n/-- products of nilpotent groups are nilpotent if their nipotency class is bounded -/\ntheorem isNilpotent_pi_of_bounded_class [∀ i, IsNilpotent (Gs i)] (n : ℕ)\n    (h : ∀ i, Group.nilpotencyClass (Gs i) ≤ n) : IsNilpotent (∀ i, Gs i) :=\n  by\n  rw [nilpotent_iff_lowerCentralSeries]\n  refine' ⟨n, _⟩\n  rw [eq_bot_iff]\n  apply le_trans (lowerCentralSeries_pi_le _)\n  rw [← eq_bot_iff, pi_eq_bot_iff]\n  intro i\n  apply lower_central_series_eq_bot_iff_nilpotency_class_le.mpr (h i)\n#align is_nilpotent_pi_of_bounded_class isNilpotent_pi_of_bounded_class\n\nend BoundedPi\n\nsection FinitePi\n\n-- Now for finite products\nvariable {η : Type _} {Gs : η → Type _} [∀ i, Group (Gs i)]\n\ntheorem lowerCentralSeries_pi_of_finite [Finite η] (n : ℕ) :\n    lowerCentralSeries (∀ i, Gs i) n = Subgroup.pi Set.univ fun i => lowerCentralSeries (Gs i) n :=\n  by\n  let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f\n  induction' n with n ih\n  · simp [pi_top]\n  ·\n    calc\n      lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl\n      _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := by rw [ih]\n      _ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]\n      _ = pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := (commutator_pi_pi_of_finite _ _)\n      _ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl\n      \n#align lower_central_series_pi_of_finite lowerCentralSeries_pi_of_finite\n\n/-- n-ary products of nilpotent groups are nilpotent -/\ninstance isNilpotent_pi [Finite η] [∀ i, IsNilpotent (Gs i)] : IsNilpotent (∀ i, Gs i) :=\n  by\n  cases nonempty_fintype η\n  rw [nilpotent_iff_lowerCentralSeries]\n  refine' ⟨finset.univ.sup fun i => Group.nilpotencyClass (Gs i), _⟩\n  rw [lowerCentralSeries_pi_of_finite, pi_eq_bot_iff]\n  intro i\n  apply lower_central_series_eq_bot_iff_nilpotency_class_le.mpr\n  exact\n    @Finset.le_sup _ _ _ _ Finset.univ (fun i => Group.nilpotencyClass (Gs i)) _ (Finset.mem_univ i)\n#align is_nilpotent_pi isNilpotent_pi\n\n/-- The nilpotency class of an n-ary product is the sup of the nilpotency classes of the factors -/\ntheorem nilpotencyClass_pi [Fintype η] [∀ i, IsNilpotent (Gs i)] :\n    Group.nilpotencyClass (∀ i, Gs i) = Finset.univ.sup fun i => Group.nilpotencyClass (Gs i) :=\n  by\n  apply eq_of_forall_ge_iff\n  intro k\n  simp only [Finset.sup_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,\n    lowerCentralSeries_pi_of_finite, pi_eq_bot_iff, Finset.mem_univ, true_imp_iff]\n#align nilpotency_class_pi nilpotencyClass_pi\n\nend FinitePi\n\n/-- A nilpotent subgroup is solvable -/\ninstance (priority := 100) IsNilpotent.to_isSolvable [h : IsNilpotent G] : IsSolvable G :=\n  by\n  obtain ⟨n, hn⟩ := nilpotent_iff_lowerCentralSeries.1 h\n  use n\n  rw [eq_bot_iff, ← hn]\n  exact derived_le_lower_central n\n#align is_nilpotent.to_is_solvable IsNilpotent.to_isSolvable\n\ntheorem normalizerCondition_of_isNilpotent [h : IsNilpotent G] : NormalizerCondition G :=\n  by\n  -- roughly based on https://groupprops.subwiki.org/wiki/Nilpotent_implies_normalizer_condition\n  rw [normalizerCondition_iff_only_full_group_self_normalizing]\n  apply nilpotent_center_quotient_ind G <;> clear! G\n  · intro G _ _ H _\n    apply Subsingleton.elim\n  · intro G _ _ ih H hH\n    have hch : center G ≤ H := subgroup.center_le_normalizer.trans (le_of_eq hH)\n    have hkh : (mk' (center G)).ker ≤ H := by simpa using hch\n    have hsur : Function.Surjective (mk' (center G)) := surjective_quot_mk _\n    let H' := H.map (mk' (center G))\n    have hH' : H'.normalizer = H' := by\n      apply comap_injective hsur\n      rw [comap_normalizer_eq_of_surjective _ hsur, comap_map_eq_self hkh]\n      exact hH\n    apply map_injective_of_ker_le (mk' (center G)) hkh le_top\n    exact (ih H' hH').trans (symm (map_top_of_surjective _ hsur))\n#align normalizer_condition_of_is_nilpotent normalizerCondition_of_isNilpotent\n\nend WithGroup\n\nsection WithFiniteGroup\n\nopen Group Fintype\n\nvariable {G : Type _} [hG : Group G]\n\ninclude hG\n\n/-- A p-group is nilpotent -/\ntheorem IsPGroup.isNilpotent [Finite G] {p : ℕ} [hp : Fact (Nat.Prime p)] (h : IsPGroup p G) :\n    IsNilpotent G := by\n  cases nonempty_fintype G\n  classical\n    revert hG\n    induction' val using Fintype.induction_subsingleton_or_nontrivial with G hG hS G hG hN ih\n    · infer_instance\n    · intro\n      intro h\n      have hcq : Fintype.card (G ⧸ center G) < Fintype.card G :=\n        by\n        rw [card_eq_card_quotient_mul_card_subgroup (center G)]\n        apply lt_mul_of_one_lt_right\n        exact fintype.card_pos_iff.mpr One.nonempty\n        exact (Subgroup.one_lt_card_iff_ne_bot _).mpr (ne_of_gt h.bot_lt_center)\n      have hnq : IsNilpotent (G ⧸ center G) := ih _ hcq (h.to_quotient (center G))\n      exact of_quotient_center_nilpotent hnq\n#align is_p_group.is_nilpotent IsPGroup.isNilpotent\n\nvariable [Fintype G]\n\n/-- If a finite group is the direct product of its Sylow groups, it is nilpotent -/\ntheorem isNilpotent_of_product_of_sylow_group\n    (e : (∀ p : (Fintype.card G).factorization.support, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G) :\n    IsNilpotent G := by\n  classical\n    let ps := (Fintype.card G).factorization.support\n    have : ∀ (p : ps) (P : Sylow p G), IsNilpotent (↑P : Subgroup G) :=\n      by\n      intro p P\n      haveI : Fact (Nat.Prime ↑p) := Fact.mk (Nat.prime_of_mem_factorization (Finset.coe_mem p))\n      exact P.is_p_group'.is_nilpotent\n    exact nilpotent_of_mulEquiv e\n#align is_nilpotent_of_product_of_sylow_group isNilpotent_of_product_of_sylow_group\n\n/-- A finite group is nilpotent iff the normalizer condition holds, and iff all maximal groups are\nnormal and iff all sylow groups are normal and iff the group is the direct product of its sylow\ngroups. -/\ntheorem isNilpotent_of_finite_tFAE :\n    TFAE\n      [IsNilpotent G, NormalizerCondition G, ∀ H : Subgroup G, IsCoatom H → H.Normal,\n        ∀ (p : ℕ) (hp : Fact p.Prime) (P : Sylow p G), (↑P : Subgroup G).Normal,\n        Nonempty\n          ((∀ p : (card G).factorization.support, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G)] :=\n  by\n  tfae_have 1 → 2; · exact @normalizerCondition_of_isNilpotent _ _\n  tfae_have 2 → 3; · exact fun h H => normalizer_condition.normal_of_coatom H h\n  tfae_have 3 → 4;\n  · intro h p _ P\n    exact Sylow.normal_of_all_max_subgroups_normal h _\n  tfae_have 4 → 5; · exact fun h => Nonempty.intro (Sylow.directProductOfNormal h)\n  tfae_have 5 → 1;\n  · rintro ⟨e⟩\n    exact isNilpotent_of_product_of_sylow_group e\n  tfae_finish\n#align is_nilpotent_of_finite_tfae isNilpotent_of_finite_tFAE\n\nend WithFiniteGroup\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/Nilpotent.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.751165141608471}}
{"text": "-- Cota_del_valor_absoluto_del_producto.lean\n-- Si x,y,ε ∈ ℝ tales que 0 < ε ≤ 1, |x| < ε y |y| < ε, entonces |x*y| < ε\n-- José A. Alonso Jiménez <https://jaalonso.github.io>\n-- Sevilla, 1-noviembre-2022\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- Demostrar que si x,y,ε ∈ ℝ tales que 0 < ε ≤ 1, |x| < ε y |y| < ε,\n-- entonces |x*y| < ε.\n-- ---------------------------------------------------------------------\n\nimport data.real.basic tactic\n\n-- 1ª demostración\n-- ===============\n\nexample :\n  ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε :=\nbegin\n  intros x y ε he1 he2 hx hy,\n  by_cases h : (|x| = 0),\n  { calc |x * y|\n         = |x| * |y| : abs_mul x y\n     ... = 0 * |y|   : by rw h\n     ... = 0         : zero_mul (abs y)\n     ... < ε         : he1 },\n  { have h1 : 0 < |x|,\n    { have h2 : 0 ≤ |x| := abs_nonneg x,\n      show 0 < |x|,\n        exact lt_of_le_of_ne h2 (ne.symm h) },\n    calc |x * y|\n         = |x| * |y| : abs_mul x y\n     ... < |x| * ε   : (mul_lt_mul_left h1).mpr hy\n     ... < ε * ε     : (mul_lt_mul_right he1).mpr hx\n     ... ≤ 1 * ε     : (mul_le_mul_right he1).mpr he2\n     ... = ε         : one_mul ε },\nend\n\n-- 2ª demostración\n-- ===============\n\nexample :\n  ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε :=\nbegin\n  intros x y ε he1 he2 hx hy,\n  by_cases h : (|x| = 0),\n  { calc |x * y|\n         = |x| * |y| : by apply abs_mul\n     ... = 0 * |y|   : by rw h\n     ... = 0         : by apply zero_mul\n     ... < ε         : by apply he1 },\n  { have h1 : 0 < |x|,\n      { have h2 : 0 ≤ |x|,\n          apply abs_nonneg,\n        exact lt_of_le_of_ne h2 (ne.symm h) },\n    calc |x * y|\n         = |x| * |y| : by rw abs_mul\n     ... < |x| * ε   : by apply (mul_lt_mul_left h1).mpr hy\n     ... < ε * ε     : by apply (mul_lt_mul_right he1).mpr hx\n     ... ≤ 1 * ε     : by apply (mul_le_mul_right he1).mpr he2\n     ... = ε         : by rw [one_mul] },\nend\n\n-- 3ª demostración\n-- ===============\n\nexample :\n  ∀ {x y ε : ℝ}, 0 < ε → ε ≤ 1 → |x| < ε → |y| < ε → |x * y| < ε :=\nbegin\n  intros x y ε he1 he2 hx hy,\n  by_cases (|x| = 0),\n  { by finish },\n  { have : 0 < |x|, by finish,\n    calc |x * y|\n         = |x| * |y| : by rw abs_mul\n     ... < |x| * ε   : by finish\n     ... ≤ 1 * ε     : by nlinarith\n     ... = ε         : by 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/Cota_del_valor_absoluto_del_producto.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7511651356834385}}
{"text": "/-\n  The goal of this assignment is to formalize a proof that there are infinitely many\n  primes.\n-/\nimport tools.super   -- provides some automation\n\n/-\n   The statement\n-/\n\nnamespace nat\n\nprotected def dvd (m n : ℕ) : Prop := ∃ k, n = m * k\n\ninstance : has_dvd nat := ⟨nat.dvd⟩\n\n-- remember, type \"dvd\" with \\|\ndef prime (n : ℕ) : Prop := n ≥ 2 ∧ ∀ m, m ∣ n → m = 1 ∨ m = n\n\n-- this is what you need to prove:\ncheck ∀ n, ∃ p, prime p ∧ p > n\n\nend nat\n\n/-\n   Some useful things\n\n   (You can use these also as examples.)\n-/\n\nnamespace nat\n\ntheorem dvd_refl (m : ℕ) : m ∣ m :=\n⟨1, by rw mul_one⟩\n\ntheorem dvd_trans : ∀ {m n k : ℕ}, m ∣ n → n ∣ k → m ∣ k\n| m ._ ._ ⟨u, rfl⟩ ⟨v, rfl⟩ := ⟨u * v, by simp⟩\n\ntheorem dvd_mul_left (m n : ℕ) : m ∣ m * n :=\n⟨n, rfl⟩\n\ntheorem dvd_mul_right (m n : ℕ) : m ∣ n * m :=\n⟨n, by simp⟩\n\ntheorem dvd_add : ∀ {m n k : ℕ}, m ∣ n → m ∣ k → m ∣ (n + k)\n| m ._ ._ ⟨u, rfl⟩ ⟨v, rfl⟩ := ⟨u + v, by simp [mul_add]⟩\n\ntheorem eq_sub_of_add_eq {m n k : ℕ} (h : m + n = k) : m = k - n :=\ncalc\n  m = m + n - n : by rw nat.add_sub_cancel\n  ... = k - n   : by rw h\n\ntheorem mul_sub (n m k : ℕ) : n * (m - k) = n * m - n * k :=\nor.elim (le_or_gt m k)\n  (assume h : m ≤ k,\n    have n * m ≤ n * k, from mul_le_mul_left _ h,\n    by simp [sub_eq_zero_of_le h, sub_eq_zero_of_le this])\n  (suppose m > k,\n    have m ≥ k, from le_of_lt this,\n    eq_sub_of_add_eq begin rw [-mul_add, nat.sub_add_cancel this] end)\n\ntheorem dvd_sub : ∀ {m n k : ℕ}, m ∣ n → m ∣ k → m ∣ (n - k)\n| m ._ ._ ⟨u, rfl⟩ ⟨v, rfl⟩ := begin rw -nat.mul_sub, apply dvd_mul_left end\n\ntheorem eq_or_ge_succ_of_ge {n m : ℕ} (h : n ≥ m) : n = m ∨ n ≥ succ m :=\nbegin\n  cases (lt_or_eq_of_le h) with h₁ h₂,\n  { right, assumption },\n  left, symmetry, assumption\nend\n\ntheorem eq_zero_or_eq_one_or_ge_2 (n : ℕ) : n = 0 ∨ n = 1 ∨ n ≥ 2 :=\nbegin\n  cases (nat.eq_or_lt_of_le (zero_le n)) with h₀ h₁,\n  { left, symmetry, assumption},\n  cases (nat.eq_or_lt_of_le h₁) with h₁ h₂,\n  { right, left, symmetry, assumption},\n  right, right, exact h₂\nend\n\ndef ge_2_of_prime {p : ℕ} (h : prime p) : p ≥ 2 := h^.left\n\n-- a nice bit of automation!\ntheorem has_divisor_of_not_prime {n : ℕ} (h₁ : n ≥ 2) (h₂ : ¬ prime n) :\n  ∃ m, m ∣ n ∧ m ≠ 1 ∧ m ≠ n :=\nby super\n\ndef complete_induction_on (n : ℕ) {p : ℕ → Prop} (h : ∀ n, (∀ m < n, p m) → p n) : p n :=\nsuffices ∀ n, ∀ m < n, p m, from this (succ n) _ (lt_succ_self n),\ntake n,\nnat.induction_on n\n  (take m, suppose m < 0, absurd this (not_lt_zero m))\n  (take n,\n    assume ih : ∀ m < n, p m,\n    take m,\n    suppose m < succ n,\n    or.elim (lt_or_eq_of_le (le_of_lt_succ this))\n      (ih m)\n      (suppose m = n,\n        begin rw this, apply h, exact ih end))\n\ntheorem le_of_dvd {m n : ℕ} (h : m ∣ n) (h' : n ≠ 0) : m ≤ n :=\nlet ⟨k, hk⟩ := h in\nhave k ≠ 0, begin intro h, rw [h, mul_zero] at hk, contradiction end,\nbegin\n  rw [-(mul_one m), hk], apply mul_le_mul_left,\n  cases eq_or_ge_succ_of_ge (zero_le k),\n  { contradiction },\n  assumption\nend\n\ntheorem le_or_eq_succ_of_le_succ {m n : ℕ} (h : m ≤ succ n) : m ≤ n ∨ m = succ n :=\nbegin\n  cases m,\n  { left, apply zero_le },\n  cases lt_or_eq_of_le (le_of_succ_le_succ h),\n  { left, assumption },\n  right, apply congr_arg, assumption\nend\n\nend nat\n\n/-\n  Here is an outline of my solution. You do not need to follow it.\n\n  If you succeed and are looking for more to do, try (stating and) proving that there are\n  infinitely many primes congruent to 3 modulo 4.\n-/\n\nopen nat\n\n-- This requires a fair bit of work. I used complete induction on n.\ntheorem has_prime_divisor (n : ℕ) : n ≥ 2 → ∃ p, prime p ∧ p ∣ n := sorry\n\ndef fact : ℕ → ℕ\n| 0     := 1\n| (n+1) := (n+1) * fact n\n\ntheorem fact_ge_1 : ∀ n, fact n ≥ 1 := sorry\n\ntheorem fact_ge_self {n : ℕ} (nnz : n ≠ 0) : fact n ≥ n := sorry\n\ntheorem dvd_fact_of_le : ∀ n, ∀ m ≤ n, m > 0 → m ∣ fact n := sorry\n\n-- lots of intermediate steps are deleted!\ntheorem infinitely_many_primes : ∀ n, ∃ p, prime p ∧ p > n :=\nsuffices h : ∀ n, n ≥ 2 → ∃ p, prime p ∧ p > n, from sorry,\ntake n,\nassume nge2 : n ≥ 2,\nhave fact n + 1 ≥ 2, from succ_le_succ (fact_ge_1 n),\nmatch has_prime_divisor _ this with\n| ⟨p, primep, pdvd⟩ :=\n  have p > n, from lt_of_not_ge\n    (suppose p ≤ n,\n      have p ≤ fact n, from sorry,\n      have p > 0, from lt_of_lt_of_le dec_trivial (ge_2_of_prime primep),\n      have p ∣ fact n, from sorry,\n      have p ∣ fact n + 1 - fact n, from sorry,\n      have p ∣ 1, from sorry,\n      have p ≤ 1, from sorry,\n      have 2 ≤ 1, from sorry,\n      show false, from absurd this dec_trivial),\n  ⟨p, primep, this⟩\nend\n", "meta": {"author": "mtegene", "repo": "homework-mtegene-master", "sha": "5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5", "save_path": "github-repos/lean/mtegene-homework-mtegene-master", "path": "github-repos/lean/mtegene-homework-mtegene-master/homework-mtegene-master-5f9b3623a46d2d3b98c54d8cbc82962d3fef49f5/homework4/homework4.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7511651319101951}}
{"text": "/-\nCopyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthor : María Inés de Frutos-Fernández\n-/\n\nimport tactic \nimport data.real.basic\n\n/-\n# Ejercicios sobre números reales\n\nLos siguientes ejercicios aparecen como pasos intermedios en algunos\nde los problemas de `limites.lean`. Intenta resolverlos utilizando\nlas tácticas `library_search` y `linarith`.\n\nNOTA: adaptado de los cursos de formalización de Kevin Buzzard.\n-/\n\nexample (x : ℝ) : |(-x)| = |x| :=\nbegin\n  exact abs_neg x,\nend\n\nexample (x y : ℝ) : |x - y| = |y - x| :=\nbegin\n  exact abs_sub_comm x y,\nend \n\nexample (A B C : ℕ) : max A B ≤ C ↔ A ≤ C ∧ B ≤ C :=\nbegin\n  exact max_le_iff,\nend\n\nexample (x y : ℝ) : |x| < y ↔ -y < x ∧ x < y :=\nbegin\n  exact abs_lt,\nend\n\nexample (ε : ℝ) (hε : 0 < ε) : 0 < ε / 2 :=\nbegin\n  linarith,\nend\n\nexample (a b x y : ℝ) (h1 : a < x) (h2 : b < y) : a + b < x + y :=\nbegin\n  linarith,\nend\n\nexample (ε : ℝ) (hε : 0 < ε) : 0 < ε / 3 :=\nbegin\n  linarith,\nend\n\nexample (a b c d x y : ℝ) (h1 : a + c < x) (h2 : b + d < y) :\n  a + b + c + d < x + y :=\nbegin\n  linarith,\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/soluciones/reales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7511651278187507}}
{"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\n! This file was ported from Lean 3 source module analysis.complex.circle\n! leanprover-community/mathlib commit ad3dfaca9ea2465198bcf58aa114401c324e29d1\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.Topology.ContinuousFunction.Basic\nimport Mathbin.Analysis.Normed.Field.UnitBall\n\n/-!\n# The circle\n\nThis file defines `circle` to be the metric sphere (`metric.sphere`) in `ℂ` centred at `0` of\nradius `1`.  We equip it with the following structure:\n\n* a submonoid of `ℂ`\n* a group\n* a topological group\n\nWe furthermore define `exp_map_circle` to be the natural map `λ t, exp (t * I)` from `ℝ` 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 : ℂ | abs (z - 0) = 1}`.  This prevents certain algebraic facts from working definitionally --\nfor example, the circle is not defeq to `{z : ℂ | abs z = 1}`, which is the kernel of `complex.abs`\nconsidered as a homomorphism from `ℂ` to `ℝ`, nor is it defeq to `{z : ℂ | norm_sq z = 1}`, which\nis the kernel of the homomorphism `complex.norm_sq` from `ℂ` to `ℝ`.\n\n-/\n\n\nnoncomputable section\n\nopen Complex Metric\n\nopen ComplexConjugate\n\n/-- The unit circle in `ℂ`, here given the structure of a submonoid of `ℂ`. -/\ndef circle : Submonoid ℂ :=\n  Submonoid.unitSphere ℂ\n#align circle circle\n\n@[simp]\ntheorem mem_circle_iff_abs {z : ℂ} : z ∈ circle ↔ abs z = 1 :=\n  mem_sphere_zero_iff_norm\n#align mem_circle_iff_abs mem_circle_iff_abs\n\ntheorem circle_def : ↑circle = { z : ℂ | abs z = 1 } :=\n  Set.ext fun z => mem_circle_iff_abs\n#align circle_def circle_def\n\n@[simp]\ntheorem abs_coe_circle (z : circle) : abs z = 1 :=\n  mem_circle_iff_abs.mp z.2\n#align abs_coe_circle abs_coe_circle\n\ntheorem mem_circle_iff_normSq {z : ℂ} : z ∈ circle ↔ normSq z = 1 := by simp [Complex.abs]\n#align mem_circle_iff_norm_sq mem_circle_iff_normSq\n\n@[simp]\ntheorem normSq_eq_of_mem_circle (z : circle) : normSq z = 1 := by simp [norm_sq_eq_abs]\n#align norm_sq_eq_of_mem_circle normSq_eq_of_mem_circle\n\ntheorem ne_zero_of_mem_circle (z : circle) : (z : ℂ) ≠ 0 :=\n  ne_zero_of_mem_unit_sphere z\n#align ne_zero_of_mem_circle ne_zero_of_mem_circle\n\ninstance : CommGroup circle :=\n  Metric.sphere.commGroup\n\n@[simp]\ntheorem coe_inv_circle (z : circle) : ↑z⁻¹ = (z : ℂ)⁻¹ :=\n  rfl\n#align coe_inv_circle coe_inv_circle\n\ntheorem coe_inv_circle_eq_conj (z : circle) : ↑z⁻¹ = conj (z : ℂ) := by\n  rw [coe_inv_circle, inv_def, normSq_eq_of_mem_circle, inv_one, of_real_one, mul_one]\n#align coe_inv_circle_eq_conj coe_inv_circle_eq_conj\n\n@[simp]\ntheorem coe_div_circle (z w : circle) : ↑(z / w) = (z : ℂ) / w :=\n  circle.Subtype.map_div z w\n#align coe_div_circle coe_div_circle\n\n/-- The elements of the circle embed into the units. -/\ndef circle.toUnits : circle →* Units ℂ :=\n  unitSphereToUnits ℂ\n#align circle.to_units circle.toUnits\n\n-- written manually because `@[simps]` was slow and generated the wrong lemma\n@[simp]\ntheorem circle.toUnits_apply (z : circle) :\n    circle.toUnits z = Units.mk0 z (ne_zero_of_mem_circle z) :=\n  rfl\n#align circle.to_units_apply circle.toUnits_apply\n\ninstance : CompactSpace circle :=\n  Metric.sphere.compactSpace _ _\n\ninstance : TopologicalGroup circle :=\n  Metric.sphere.topologicalGroup\n\n/-- If `z` is a nonzero complex number, then `conj z / z` belongs to the unit circle. -/\n@[simps]\ndef circle.ofConjDivSelf (z : ℂ) (hz : z ≠ 0) : circle :=\n  ⟨conj z / z,\n    mem_circle_iff_abs.2 <| by rw [map_div₀, abs_conj, div_self (complex.abs.ne_zero hz)]⟩\n#align circle.of_conj_div_self circle.ofConjDivSelf\n\n/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ`. -/\ndef expMapCircle : C(ℝ, circle)\n    where toFun t := ⟨exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]⟩\n#align exp_map_circle expMapCircle\n\n@[simp]\ntheorem expMapCircle_apply (t : ℝ) : ↑(expMapCircle t) = Complex.exp (t * Complex.I) :=\n  rfl\n#align exp_map_circle_apply expMapCircle_apply\n\n@[simp]\ntheorem expMapCircle_zero : expMapCircle 0 = 1 :=\n  Subtype.ext <| by\n    rw [expMapCircle_apply, of_real_zero, MulZeroClass.zero_mul, exp_zero, Submonoid.coe_one]\n#align exp_map_circle_zero expMapCircle_zero\n\n@[simp]\ntheorem expMapCircle_add (x y : ℝ) : expMapCircle (x + y) = expMapCircle x * expMapCircle y :=\n  Subtype.ext <| by\n    simp only [expMapCircle_apply, Submonoid.coe_mul, of_real_add, add_mul, Complex.exp_add]\n#align exp_map_circle_add expMapCircle_add\n\n/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ`, considered as a homomorphism of\ngroups. -/\n@[simps]\ndef expMapCircleHom : ℝ →+ Additive circle\n    where\n  toFun := Additive.ofMul ∘ expMapCircle\n  map_zero' := expMapCircle_zero\n  map_add' := expMapCircle_add\n#align exp_map_circle_hom expMapCircleHom\n\n@[simp]\ntheorem expMapCircle_sub (x y : ℝ) : expMapCircle (x - y) = expMapCircle x / expMapCircle y :=\n  expMapCircleHom.map_sub x y\n#align exp_map_circle_sub expMapCircle_sub\n\n@[simp]\ntheorem expMapCircle_neg (x : ℝ) : expMapCircle (-x) = (expMapCircle x)⁻¹ :=\n  expMapCircleHom.map_neg x\n#align exp_map_circle_neg expMapCircle_neg\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/Circle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7511651256669611}}
{"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 algebra.char_p.char_and_card\n! leanprover-community/mathlib commit 2fae5fd7f90711febdadf19c44dc60fae8834d1b\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.GroupTheory.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\n/-- A prime `p` is a unit in a commutative ring `R` of nonzero characterstic iff it does not divide\nthe characteristic. -/\ntheorem isUnit_iff_not_dvd_char_of_ringChar_ne_zero (R : Type _) [CommRing R] (p : ℕ) [Fact p.Prime]\n    (hR : ringChar R ≠ 0) : IsUnit (p : R) ↔ ¬p ∣ ringChar R :=\n  by\n  have hch := CharP.cast_eq_zero R (ringChar R)\n  have hp : p.prime := Fact.out p.prime\n  constructor\n  · rintro h₁ ⟨q, hq⟩\n    rcases IsUnit.exists_left_inv h₁ with ⟨a, ha⟩\n    have h₃ : ¬ringChar R ∣ q := by\n      rintro ⟨r, hr⟩\n      rw [hr, ← mul_assoc, mul_comm p, mul_assoc] at hq\n      nth_rw 1 [← mul_one (ringChar R)] at hq\n      exact Nat.Prime.not_dvd_one hp ⟨r, mul_left_cancel₀ hR hq⟩\n    have h₄ := mt (CharP.int_cast_eq_zero_iff R (ringChar R) q).mp\n    apply_fun (coe : ℕ → R)  at hq\n    apply_fun (· * ·) a  at hq\n    rw [Nat.cast_mul, hch, MulZeroClass.mul_zero, ← mul_assoc, ha, one_mul] at hq\n    norm_cast  at h₄\n    exact h₄ h₃ hq.symm\n  · intro h\n    rcases(hp.coprime_iff_not_dvd.mpr h).IsCoprime with ⟨a, b, hab⟩\n    apply_fun (coe : ℤ → R)  at hab\n    push_cast at hab\n    rw [hch, MulZeroClass.mul_zero, add_zero, mul_comm] at hab\n    exact isUnit_of_mul_eq_one (p : R) a hab\n#align is_unit_iff_not_dvd_char_of_ring_char_ne_zero isUnit_iff_not_dvd_char_of_ringChar_ne_zero\n\n/-- A prime `p` is a unit in a finite commutative ring `R`\niff it does not divide the characteristic. -/\ntheorem isUnit_iff_not_dvd_char (R : Type _) [CommRing R] (p : ℕ) [Fact p.Prime] [Finite R] :\n    IsUnit (p : R) ↔ ¬p ∣ ringChar R :=\n  isUnit_iff_not_dvd_char_of_ringChar_ne_zero R p <| CharP.char_ne_zero_of_finite R (ringChar R)\n#align is_unit_iff_not_dvd_char isUnit_iff_not_dvd_char\n\n/-- The prime divisors of the characteristic of a finite commutative ring are exactly\nthe prime divisors of its cardinality. -/\ntheorem prime_dvd_char_iff_dvd_card {R : Type _} [CommRing R] [Fintype R] (p : ℕ) [Fact p.Prime] :\n    p ∣ ringChar R ↔ p ∣ Fintype.card R :=\n  by\n  refine'\n    ⟨fun h =>\n      h.trans <|\n        int.coe_nat_dvd.mp <|\n          (CharP.int_cast_eq_zero_iff R (ringChar R) (Fintype.card R)).mp <| by\n            exact_mod_cast CharP.cast_card_eq_zero R,\n      fun h => _⟩\n  by_contra h₀\n  rcases exists_prime_addOrderOf_dvd_card p h with ⟨r, hr⟩\n  have hr₁ := addOrderOf_nsmul_eq_zero r\n  rw [hr, nsmul_eq_mul] at hr₁\n  rcases IsUnit.exists_left_inv ((isUnit_iff_not_dvd_char R p).mpr h₀) with ⟨u, hu⟩\n  apply_fun (· * ·) u  at hr₁\n  rw [MulZeroClass.mul_zero, ← mul_assoc, hu, one_mul] at hr₁\n  exact\n    mt add_monoid.order_of_eq_one_iff.mpr (ne_of_eq_of_ne hr (Nat.Prime.ne_one (Fact.out p.prime)))\n      hr₁\n#align prime_dvd_char_iff_dvd_card prime_dvd_char_iff_dvd_card\n\n/-- A prime that does not divide the cardinality of a finite commutative ring `R`\nis a unit in `R`. -/\ntheorem not_isUnit_prime_of_dvd_card {R : Type _} [CommRing R] [Fintype R] (p : ℕ) [Fact p.Prime]\n    (hp : p ∣ Fintype.card R) : ¬IsUnit (p : R) :=\n  mt (isUnit_iff_not_dvd_char R p).mp\n    (Classical.not_not.mpr ((prime_dvd_char_iff_dvd_card p).mpr hp))\n#align not_is_unit_prime_of_dvd_card not_isUnit_prime_of_dvd_card\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/CharAndCard.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8289387998695209, "lm_q1q2_score": 0.7510101059861557}}
{"text": "import ..lectures.love12_basic_mathematical_structures_demo\nimport tactic\n\n/-! # LoVe Homework 7: Basic Mathematical Structures (7 points)\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/-! ### Question 1 : Graph Definitions\n\nThere are many definitions of *graphs* in both the math and CS literature.\nGraphs have *vertices* (or *nodes*) which are connected by *edges*.\nSome definitions specify edges to be *directed*, i.e. \nan edge that connects vertex `a` to vertex `b` does not connect `b` to `a`.\nOthers are undirected.\nSome allow *loops*, i.e. edges from a vertex `a` to itself. \nSome don't. \n\nA (undirected, loopless) graph is usually defined as a list of vertices\nalong with a list of tuples of vertices, representing edges:-/\n\nstructure list_graph (V : Type) :=\n(edges : list (V × V))\n\n/-! For large graphs, this data structure can get cumbersome. Instead, we\ncan define graphs based on an adjacency function. To ensure undirectedness\nand looplessness, we need to prove our adjacency function is symmetric and\nirreflexive, respectively. -/\n\nstructure func_graph (V : Type) :=\n(adj : V → V → Prop)\n(symm : symmetric adj)\n(loopless : irreflexive adj )\n\n/- 1.1 (3 points).\nA complete graph is a graph in which each vertex is adjacent to each other vertex. \nDefine the complete graph on four vertices, K₄, as a `list_graph` and as a `func_graph`.\nYou can use a predefined function for the adjacency function, or you can make your own! -/\n\ninductive quad : Type\n| one | two | three | four\n\nnamespace quad\n\ndef K₄' : list_graph quad := sorry\n\ndef K₄ : func_graph quad := sorry\n\nend quad\n\n/- 1.2 (4 points) \nIf we choose the right type for a graph, it can be easier to define, manipulate, and manage\nthe graph. A `path graph` is a graph with vertices v₁,...,vₙ whose only edges are connecting\nvᵢ and vᵢ₊₁ for i < n. Define a path graph `path₅` on the type `fin 5` by designing a symmetric \nand irreflexive function. You'll need to prove symmetry and irreflexivity, too!\n-/\n#check fin\n/-\nBe careful with addition on `fin`. You might recognize this type mathematically as `ℤ/5ℤ`.\n-/\n#eval (4 : fin 5) + 1\n/-\nYou also might be surprised that tactics like `linarith` don't work on `fin 5`. \nTurns out that algorithm doesn't like it when `5 = 0`!\nIf you end up with a hypothesis `h : 0 = 1` or something like that,\n`cases h` may come in handy.\n-/\n\ndef path₅ : func_graph (fin 5) := sorry\n\n/- 1.3 (1 point)\nUsing this functional definition of a graph, we can easily generalize the above path graph\nto make an arbitrarily large path. Fill in the following definition, utilizing your previous\nanswer. -/\n\ndef pathBIG : func_graph (fin 100) := sorry\n\n/- Extra Challenge: define `pathBig` as a list_graph. (just kidding don't do that)-/\n\n\n/- 1.4 (Bonus)\nWe lied a bit: the definitions `func_graph` and `list_graph` are actually capturing \nslightly different graph concepts!\n\nTo make that more precise: we can state the *equivalence* of a `list_graph` and a `func_graph`. \n-/\ndef graph_equiv {α : Type} (lg : list_graph α) (fg : func_graph α) : Prop :=\n∀ v₁ v₂ : α, fg.adj v₁ v₂ ↔ ((v₁, v₂) ∈ lg.edges ∨ (v₂, v₁) ∈ lg.edges)\n\n/-\nI claim that I can find two non-equal `func_graphs` that are equivalent to the same `list_graph`.\n\nCan you give an example? What graph theory concept is appearing here?\n-/\n\n\n\n/- For question 2, you may chose to do **one** of Question 2α or Question 2β. You may do both,\nbut you will only be graded for one. Please indicate which one you want to be graded.\nQuestion 2α will be more in the realm of math and logic.\nQuestion 2β will be more about CS, PL, and functional programming. -/\n\n/- ### Question 2α : Automorphism Groups of Graphs (6 points) -/\n/- An automorphism of a graph is a function on (or permutation of) its vertices that preserves\nthe edge structure of the graph. In other words: -/\ndef is_graph_automorphism {α : Type} (G : func_graph α) (A : α → α) : Prop :=\n  ∀(v₁ v₂ : α), G.adj v₁ v₂ ↔ G.adj (A v₁) (A v₂)\n\n/- We can define a structure like this to define an automorphism of a graph. -/\nstructure graph_automorphism (α : Type) (G : func_graph α) :=\n(f : α → α)\n(is_aut : is_graph_automorphism G f)\n\n\n/- Let's focus on a particular graph, say, the graph `path₅` defined above, to define and study\nits automorphisms. It has two automorphisms: the identity, which fixes all vertices, and a 'flip',\nwhich fixes the middle vertex, maps terminal vertices to terminal vertices, and the two remaining\nvertices to each other. -/\n\n/- 2α.1 (1 point)\nDefine the two functions corresponding to the `flip` and the `identity` on the `path₅` graph.\n-/\n\ndef path₅_flip : fin 5 → fin 5 := sorry\n\ndef path₅_id : fin 5 → fin 5 := sorry\n\n/- 2α.2 (1 point)\nNow prove that these functions are indeed automorphisms.\n-/\n\nlemma path₅_flip_is_aut : is_graph_automorphism path₅ path₅_flip := sorry\n\nlemma path₅_id_is_aut : is_graph_automorphism path₅ path₅_id := sorry\n\n/- Now we can define the two elements of our structure! -/\ndef path₅_flip_aut : graph_automorphism (fin 5) path₅ :=\n{\n  f := path₅_flip,\n  is_aut := path₅_flip_is_aut\n}\n\ndef path₅_id_aut : graph_automorphism (fin 5) path₅ :=\n{\n  f := path₅_id,\n  is_aut := path₅_id_is_aut\n}\n\n/- Graph automorphisms under the operation of function composition form a group! Let's work \ntowards building that group for our path₅ graph.\n-/\n\n/- Question 2α.3 (2 points) \nFirst, let's prove that automorphisms are closed under composition (`aut_comp_aut`).\nThen we'll define the composition function as `aut_comp`. \n\nHint for the lemma: `iff.trans` might be handy!\n-/\n\nlemma aut_comp_aut {α : Type} (G : func_graph α) (f g : α → α) :\n  is_graph_automorphism G f → is_graph_automorphism G g → is_graph_automorphism G (f ∘ g) :=\nsorry\n\n\ndef aut_comp {α : Type} (G : func_graph α) :\n graph_automorphism α G → graph_automorphism α G → graph_automorphism α G := sorry\n\ninfix ` ∘₅ ` : 90 := aut_comp path₅\n\n/- Question 2α.4 (2 points) \nNow prove that this operation is associative and define an inverse function. (Note that the\ninverse function is defined only on the path₅ graph, so don't overthink it! What are the inverses\nof each element?) -/\n\nlemma graph_automorphism.assoc : \n  ∀ (a b c : graph_automorphism (fin 5) path₅), a ∘₅ b ∘₅ c = a ∘₅ (b ∘₅ c) := sorry\n\ndef graph_automorphism.inv : graph_automorphism (fin 5) path₅ → graph_automorphism (fin 5) path₅ := sorry\n\n/- You don't have to prove the rest, but if you did, you'd have a group! Notice also how easy it would\nbe to generalize this group to an automorphism group of any path graph. -/\n\naxiom graph_automorphism.one_mul : ∀ (a : graph_automorphism (fin 5) path₅), path₅_id_aut ∘₅ a = a\naxiom graph_automorphism.mul_one : ∀ (a : graph_automorphism (fin 5) path₅), a ∘₅ path₅_id_aut = a\naxiom graph_automorphism.mul_left_inv : ∀ (a : graph_automorphism (fin 5) path₅), graph_automorphism.inv a ∘₅ a = path₅_id_aut\n\n@[instance] def automorphism_group_path₅ : group (graph_automorphism (fin 5) path₅) :=\n{\n  mul := aut_comp path₅,\n  one := path₅_id_aut,\n  mul_assoc := graph_automorphism.assoc,\n  one_mul := graph_automorphism.one_mul,\n  inv := graph_automorphism.inv,\n  mul_one := graph_automorphism.mul_one,\n  mul_left_inv := graph_automorphism.mul_left_inv,\n}\n\n/- ### Question 2β : Computer Networks (6 points)-/\n/- Computer networks can be modeled by graphs. Suppose we have a system of routers, and\nwe want any router to be able to send and receive information from any other router. Graph\ntheoretically, we want our graph to be connected.\n-/\n\n/- Question 2β.1 (2 points)\nWe'll say a path is valid if it\n* Starts with the starting vertex `start_v`\n* Ends with the ending vertex `end_v`\n* For each element in the list vᵢ, vᵢ₊₁ is adjacent to vᵢ\n\nFill in the predicate `is_path` that holds when an input list is a valid path.\n-/\n\ndef is_path {α : Type} (G : func_graph α) (start_v end_v: α) : list α → Prop := sorry\n\ndef is_connected {α : Type} (G : func_graph α) : Prop :=\n  ∀(v₁ v₂ : α), v₁ ≠ v₂ → ∃p, is_path G v₁ v₂ p\n\n/- Suppose now that Ian, infamous for hating routers, destroys one of the routers. It's very\nmuch possible that the destruction of that router disconnected the rest of the network, i.e., after that\nrouter is destroyed, there are some routers that can no longer communicate with others. We would\ncall that router a **separation vertex**. We might consider employing the stricter condition of\n**biconnectivity** to avoid this problem. Biconnectivity is when there are no separation vertices\nin the graph, or, alternatively, for every two vertices there are two disjoint paths connecting them. -/\n\n/- Question 2β.2 (1 point) \nWrite an inductive predicate that holds when two lists are totally disjoint (their intersection is empty). -/\n\ninductive list_disj {α : Type} : list α → list α → Prop\n\n/- Question 2β.3 (1 point)\nUse the predicate above to write a definition for biconnectivity. -/\n\ndef is_biconnected {α : Type} (G : func_graph α) : Prop := sorry\n\n/-  Question 2β.4 (2 points)\n\nDefine a biconnected graph of your choice (with at least 4 vertices) and prove that it is biconnected!\n-/\n\ndef bcgraph : func_graph sorry := sorry \n\nlemma bc_graph_is_biconnected : is_biconnected bcgraph :=\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/homework/love07_basic_mathematical_structures_homework_sheet.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7509895198428228}}
{"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# Vector spaces\n\nOk so groups in Lean are called `group` and fields are called `field`, so\nI think I owe you an explanation for why vector spaces are called `module`.\n\nThe lie is that `module` is French for vector space, and we used a French source.\nIf you're happy with that explanation, then you can skip the actual explanation below.\n\nThe truth is the following. The definition of a vector space `V` over a field `k` is:\n\n1) `V` is an abelian group\n2) If `r : k` and `v : V` there's an element `r • v : V`\n3) Axioms for `•`: `(r + s) • v = r • v + s • v`, `r • (v + w) = r • v = r • w`,\n  `1 • v = v` and `(r * s) • v = r • (s • v)`.\n\nRecall that `k` was a field. Fields have division and inverses (except for 0), \nbut look at those axioms: there is no mention of inverses or division for `k` in the axioms\nof a vector space. The only things we use on `k` are `1`, `+` and `*`. \n\nThis 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\nNote to self: we should be able to add notation `vector_space` for `module` in a locale.\nBut let's just tell them it's French for vector space.\n-/\n\n-- 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-- The field `k` acts on the vector space `V` and the notation for this is `•`, \n-- which is notation for `smul`. We don't use `mul` because for `a * b` to make\n-- sense in Lean we need `a` and `b` to have the same type. Here `a : k` and `v : V`\n-- so this isn't satisfied.\n\nexample (a : k) (v : V) : V := a • v\n\n-- Axioms for a vector space\n\nvariables (a b : k) (v w : V)\n\nexample : a • (v + w) = a • v + a • w := smul_add a v w\nexample : (a + b) • v = a • v + b • v := add_smul a b v\nexample : (1 : k) • v = v := one_smul k v\nexample : a • (b • v) = (a * b) • v := smul_smul a b v\n\n-- Other standard facts about vector spaces:\nexample : (a - b) • v = a • v - b • v := sub_smul a b v \nexample : (0 : k) • v = 0 := zero_smul k v\n\n/-\n\n## Subspaces\n\nThe type of subspaces of a vector space is called `subspace k V`. You\nhave to mention `k` because there are real world examples like `ℂⁿ` which\nare vector spaces over both the reals and the complexes, so they have\nmore real subspaces than complex subspaces. \n\nSubspaces of a vector space form a complete lattice, so Lean uses lattice notation for them.\n\n-/\n\n-- let `X` and `Y` be subspaces of `V`\nvariables (X Y : subspace k V)\n\n-- Note that `X` and `Y` are terms not types.\n\n-- How do we say `X ⊆ Y`?\n\n-- #check X ⊆ Y -- doesn't work! `⊆` only works for terms of type `set V`. \n\n-- We use *lattice notation* and it works fine.\n\nexample : Prop := X ≤ Y -- `X ≤ Y` is a true-false statement\n\nexample : subspace k V := X ⊓ Y -- intersection of `X` and `Y`, as a subspace\n\nexample : subspace k V := X ⊔ Y -- `X` + `Y`, as a subspace. It's the smallest vector subspace of\n                                -- `V` containing `X` and `Y`, so it's the sup of `X` and `Y`\n                                -- in the lattice of subspaces.\n\nexample : subspace k V := ⊥ -- the 0-dimensional subspace\n\nexample : 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 of subspaces it's just like sets:\n\nexample : Prop := v ∈ X -- the type of `v` is `V`, and the true-false statement is `v ∈ X`\n\n-- Let `W` be another `k`-vector space\nvariables (W : Type) [add_comm_group W] [module k W]\n\n-- `k`-linear maps from `V` to `W` are terms of type `V →ₗ[k] W`. This is notation\n-- for `linear_map (ring_hom.id k) V W`.\n\n-- let `φ : V → W` be a linear map\nvariable (φ : V →ₗ[k] W)\n\n-- Axioms for a linear map:\nexample : φ (a • v) = a • φ v := φ.map_smul a v\nexample : φ (v + w) = φ v + φ w := φ.map_add v w\n\n-- quotients work just like in group theory\nexample := V ⧸ X\n\n-- The linear map from `V` to `V ⧸ X` is called `submodule.mkq X`\n\nexample : V →ₗ[k] V ⧸ X := submodule.mkq X\n\n-- ...which is inconsistent with the group theory quotient conventions, something I only \n-- just spotted when preparing this course sheet.\n\n-- You can take the image and preimage of subspaces along a linear map.\n\nexample (X : subspace k V) : subspace k W := X.map φ\nexample (Y : subspace k W) : subspace k V := Y.comap φ\n\n-- Here's an actual question at long last. If φ : V → W is a linear map,\n-- if X is a subspace of V and Y a subspace of W, prove that φ(X) ⊆ Y iff X ⊆ φ⁻¹(Y)\nexample (X : subspace k V) (Y : subspace k W) : X.map φ ≤ Y ↔ X ≤ Y.comap φ :=\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/section11vector_spaces/sheet1.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.7509895019374747}}
{"text": "set_option pp.width 60\nsection\n/-\nvariables p q : Prop\nvariable hp : p\nexample (hq : q) : p ∧ q := and.intro hp hq\n\nvariable h : p ∨ q\nexample : q ∨ p :=\nor.elim h\n(assume hp : p, or.inr hp)\n(assume hq : q, or.intro_left p hq)\ncheck @or.intro_right q p hp\ncheck @or.elim\ncheck @or.intro_left\ncheck @or.intro_right\n-/\n\nvariables p q : Prop\ntheorem contra (hpq : p → q) : ¬q → ¬p :=\nλ hnq : ¬q, λ hp : p, false.elim (hnq (hpq hp))\n\ntheorem aswap : p ∧ q ↔ q ∧ p :=\niff.intro\n(assume h : p ∧ q, show q ∧ p, from and.intro (and.right h) (and.left h))\n(assume h : q ∧ p, show p ∧ q, from and.intro (and.right h)(and.left h))\n\ntheorem aaswap : ∀ {p q : Prop}, p ∧ q ↔ q ∧ p :=\nλ p q : Prop,\niff.intro\n(λ h : p ∧ q, and.intro (and.right h) (and.left h))\n(λ h : q ∧ p, and.intro (and.right h) (and.left h))\n\nvariables x y : Prop\nvariable z : y ∧ x\nlemma a : x ∧ y := iff.mp (aaswap) z\n\nlemma b : x ∧ y := and.intro\n(and.right z)\n(and.left z)\n\nlemma c : x ∧ y := \n(λ (hx : x),\n(λ (hy : y),\nand.intro hx hy) (and.left z)) (and.right z)\n\nlemma havelist : x ∧ y :=\nhave hx : x, from and.right z,\nhave hy : y, from and.left z,\nshow x ∧ y, from and.intro hx hy\n\nlemma suff : x ∧ y :=\nhave hx : x, from and.right z,\nsuffices hy : y, from and.intro hx hy,\nshow y, from and.left z\n\n\nopen classical\ntheorem dner {p : Prop} : p → ¬¬p :=\nassume hp : p,\n    not.intro (assume np : ¬p, np hp)\n\ntheorem dne {p : Prop} : ¬¬p → p :=\n--λ h : ¬¬p,\nassume h : ¬¬p,\nshow p, from or.elim (em p)\n(λ hp : p, hp)\n(λ hnp : ¬p, absurd hnp h)\n\nexample (h : ¬¬p) : p :=\nby_contradiction (assume h1: ¬p, show false, from h h1)\n\nlemma demorg (h : ¬(p ∧ q)) : ¬p ∨ ¬q :=\n--or.elim (em p)\nby_cases\n(assume hp : p, or.inr (show ¬q, from assume hq : q, h ⟨hp, hq⟩))\n(assume hp : ¬p, or.inl hp)\n\nend\n\nsection propositional_validities --Proofs of lots of propositions\n\nvariables p q r s : Prop\n\n--commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=\niff.intro\n(assume x : p ∧ q,\nshow q ∧ p, from and.intro (and.right x) (and.left x))\n(assume y : q ∧ p,\nshow p ∧ q, from and.intro (and.right y) (and.left y))\n--cleaner(?) version\nexample : p ∧ q ↔ q ∧ p :=\nhave for : p ∧ q → q ∧ p, from (assume x : p ∧ q,\n    have z : q, from and.right x,\n    have c : p, from and.left x,\n    and.intro z c),\nhave bac : q ∧ p → p ∧ q, from (assume y : q ∧ p, and.intro (and.right y) (and.left y)),\niff.intro for bac\n\nexample : p ∨ q ↔ q ∨ p :=\niff.intro\n(assume x : p ∨ q,\nshow q ∨ p, from or.elim x\n(assume hp : p, or.inr hp) (assume hq : q, or.inl hq))\n(assume y : q ∨ p,\nshow p ∨ q, from or.elim y\n(assume hq : q, or.inr hq) (assume hp : p, or.inl hp))\n--associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\niff.intro\n(assume x : (p ∧ q) ∧ r,\nshow p ∧ (q ∧ r), from and.intro (and.left (and.left x))\n(and.intro (and.right (and.left x))\n(and.right x)))\n(assume y : p ∧ (q ∧ r),\nshow (p ∧ q) ∧ r, from and.intro (and.intro\n(and.left y) (and.left (and.right y)))\n(and.right (and.right y)))\n\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) :=\nhave forward : (p ∨ q) ∨ r → p ∨ (q ∨ r), from (\nassume x : (p ∨ q) ∨ r, show p ∨ (q ∨ r), from \nor.elim x (assume hpq : p ∨ q,\nor.elim hpq (assume hp : p, or.inl hp)\n(assume hq : q, or.inr (or.inl hq)))\n(assume hr : r, or.inr (or.inr hr))),\nhave backward : p ∨ (q ∨ r) → (p ∨ q) ∨ r, from (\nassume x : p ∨ (q ∨ r), show (p ∨ q) ∨ r, from\nor.elim x (assume hp : p, or.inl (or.inl hp))\n(assume hqr : q ∨ r, or.elim hqr\n(assume hq : q, or.inl (or.inr hq))\n(assume hr : r, or.inr hr))),\niff.intro forward backward\n--distributivity of ∧ and ∨\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=\niff.intro\n    (assume h : p ∧ (q ∨ r),\n        have hp : p, from h^.left,\n        have hqr : q ∨ r, from h^.right,\n        or.elim hqr\n            (assume hq : q, or.inl ⟨hp,hq⟩)\n            (assume hr : r, or.inr ⟨hp,hr⟩))\n    (assume h : (p ∧ q) ∨ (p ∧ r),\n        have hp : p, from\n            or.elim h\n                (assume hpq : p ∧ q, hpq^.left)\n                (assume hpr : p ∧ r, hpr^.left),\n        have hqr : q ∨ r, from\n            or.elim h\n                (assume hpq : p ∧ q, or.inl hpq^.right)\n                (assume hpr : p ∧ r, or.inr hpr^.right),\n        ⟨hp,hqr⟩)\n\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) :=\niff.intro\n    (assume h : p ∨ (q ∧ r),\n        or.elim h\n            (assume hp : p, ⟨or.inl hp,or.inl hp⟩)\n            (assume hqr : q ∧ r, ⟨or.inr hqr^.left, or.inr hqr^.right⟩))\n    (assume h : (p ∨ q) ∧ (p ∨ r),\n        have hpq : p ∨ q, from h^.left,\n        have hpr : p ∨ r, from h^.right,\n         or.elim hpq\n            (assume hp : p, or.inl hp)\n            (assume hq : q,\n                or.elim hpr\n                    (assume hp : p, or.inl hp)\n                    (assume hr : r, or.inr ⟨hq, hr⟩)\n            )\n    )\n--other propositional proofs (non-classical)\nexample : (p → (q → r)) ↔ (p ∧ q → r) :=\niff.intro\n    (assume h : p → (q → r),\n        assume hpq : p ∧ q,\n            h hpq^.left hpq^.right)\n    (assume h : p ∧ q → r,\n        assume hp : p,\n            assume hq : q,\n                h ⟨hp, hq⟩)\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) :=\niff.intro\n    (assume h : (p ∨ q) → r,\n        have hpr : p → r, from\n            assume hp : p,\n                h (or.inl hp),\n        have hqr : q → r, from\n            assume hq : q,\n                h (or.inr hq),\n        ⟨hpr, hqr⟩)\n    (assume h : (p → r) ∧ (q → r),\n        have hpr : p → r, from h^.left,\n        have hqr : q → r, from h^.right,\n        assume hpq : p ∨ q,\n            show r, from or.elim hpq\n                (assume hp : p, hpr hp)\n                (assume hq : q, hqr hq))\n\nlemma lem₁ {p q : Prop} : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\niff.intro\n    (assume h : ¬(p ∨ q),\n        have np : ¬p, from\n            not.intro (show p → false, from (assume hp : p, h (or.inl hp))),\n        have nq : ¬q, from\n            not.intro (assume hq : q, h (or.inr hq)),\n        ⟨np, nq⟩)\n    (assume h : ¬p ∧ ¬q,\n        show ¬(p ∨ q), from\n            not.intro (assume hpq : p ∨ q, or.elim hpq\n            (assume hp : p, h^.left hp)\n            (assume hq : q, h^.right hq)))\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) :=\nassume h : ¬p ∨ ¬q,\n    or.elim h\n        (assume np : ¬p, not.intro (assume hpq : p ∧ q, np hpq^.left))\n        (assume nq : ¬q, not.intro (assume hpq : p ∧ q, nq hpq^.right))\n\nexample : ¬(p ∧ ¬p) :=\nnot.intro (assume h : p ∧ ¬p, h^.right h^.left)\n\nexample : p ∧ ¬q → ¬(p → q) :=\nassume h : p ∧ ¬q,\n    not.intro (assume hpq : p → q, h^.right (hpq h^.left))\n\nexample : ¬p → (p → q) :=\nassume np : ¬p,\n    assume hp : p,\n        false.elim (np hp)\n\nlemma lem₄ {p q : Prop} : (¬p ∨ q) → (p → q) :=\nassume h : ¬p ∨ q,\n    assume hp : p,\n        or.elim h\n            (assume np : ¬p, false.elim (np hp))\n            (assume hq : q, hq)\n\nexample : p ∨ false ↔ p :=\niff.intro\n    (assume h : p ∨ false, or.elim h\n        (assume hp : p, hp)\n        (assume fal, false.elim fal))\n    (assume h : p, or.inl h)\n\nexample : p ∧ false ↔ false :=\niff.intro\n    (assume h : p ∧ false, h^.right)\n    (assume h : false, false.elim h)\n\nexample : ¬(p ↔ ¬p) :=\nnot.intro\n    (assume h : p ↔ ¬p,\n        have np : ¬p, from not.intro\n            (assume hp : p,\n                ((iff.elim_left h hp) hp)),\n        (np (iff.elim_right h np)))\n\nexample : ¬(p ↔ ¬p) := --fully lambda???\nnot.intro (λ h : p ↔ ¬p, ((not.intro (λ hp : p, ((iff.elim_left h hp) hp))) (iff.elim_right h (not.intro (λ hp : p, ((iff.elim_left h hp) hp))))))\n\nexample : (p → q) → (¬q → ¬p) :=\nassume h : p → q,\n    assume nq : ¬q,\n        not.intro\n            (assume hp : p, nq (h hp))\n--propositions that rely on classical logic\nopen classical\n\nlemma lem₃ {p q : Prop} : ¬(p ∧ q) → ¬p ∨ ¬q :=\nassume h : ¬(p ∧ q),\n    or.elim (em (¬p ∨ ¬q))\n        (assume h₁ : ¬p ∨ ¬q, h₁)\n        (assume h₂ : ¬(¬p ∨ ¬q),\n            have nnpq : (¬¬p ∧ ¬¬q),\n                from iff.elim_left (@lem₁ (¬p) (¬q)) h₂,\n            have hp : p, from dne nnpq^.left,\n            have hq : q, from dne nnpq^.right,\n            absurd (and.intro hp hq) h)\n\nlemma lem₂ {p q : Prop} : ¬(p → q) → p ∧ ¬q :=\nassume h : ¬(p → q),\n    by_contradiction (assume h₂ : ¬(p ∧ ¬q),\n        have nnpq : ¬p ∨ ¬¬q, from lem₃ h₂,\n        have npq : ¬p ∨ q, from or.elim nnpq (assume np : ¬p, or.inl np) (assume nnq : ¬¬q, or.inr (dne nnq)),\n        h (lem₄ npq))\n\n\nexample : (p → r ∨ s) → (p → r) ∨ (p → s) :=\nassume h : p → r ∨ s,\n    by_contradiction (assume h₂ : ¬((p → r) ∨ (p → s)),\n        have h₃ : ¬(p → r) ∧ ¬(p → s), from iff.elim_left lem₁ h₂,\n        have npr : ¬(p → r), from h₃^.left,\n        have nps : ¬(p → s), from h₃^.right,\n        have pnr : p ∧ ¬r, from lem₂ npr,\n        have pns : p ∧ ¬s, from lem₂ nps,\n        have hp : p, from pnr^.left,\n        have nr : ¬r, from pnr^.right,\n        have ns : ¬s, from pns^.right,\n        or.elim (h hp)\n            (assume hr : r, nr hr)\n            (assume hs : s, ns hs)\n    )\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q := --same as lem₃\nassume h : ¬(p ∧ q),\n    by_contradiction (assume h₂ : ¬(¬p ∨ ¬q),\n        have nnpq : (¬¬p ∧ ¬¬q), from iff.elim_left (@lem₁ (¬p) (¬q)) h₂,\n        h ⟨dne nnpq^.left, dne nnpq^.right⟩)\n\nexample : (p → q) → (¬p ∨ q) :=\nassume h : p → q,\n    or.elim (em (¬p ∨ q))\n        (assume npq : ¬p ∨ q, npq)\n        (assume nnpq : ¬(¬p ∨ q),\n            have nh : ¬¬p ∧ ¬q, from (iff.elim_left lem₁) nnpq,\n            have hp : p, from dne nh^.left,\n            have hq : q, from h hp,\n            or.inr hq)\n\nexample : (¬q → ¬p) → (p → q) :=\nassume h : ¬q → ¬p,\n    assume hp : p,\n        or.elim (em q)\n            (assume hq : q, hq)\n            (assume nq : ¬q,\n                have np : ¬p, from h nq,\n                absurd hp np)\n\nexample : p ∨ ¬p := em p\n\nlemma lem₆ : (((p → q) → p) → p) :=\nassume h : (p → q) → p,\n    show p, from or.elim (em (p → q))\n        (assume h₂ : p → q, h h₂)\n        (assume h₃ : ¬(p → q),\n            have h₄ : p ∧ ¬q, from lem₂ h₃,\n            h₄^.left)\n\nend propositional_validities\n\nsection\nopen classical\nlemma iffcontradiction {p : Prop} (h : p ↔ ¬p) : false :=\nhave h₁ : p → ¬p, from iff.elim_left h,\nhave h₂ : ¬p → p, from iff.elim_right h,\nby_cases\n    (assume h₃ : p, (h₁ h₃) h₃)\n    (assume h₄ : ¬p, h₄ (h₂ h₄))\nend\n\nsection\n\nvariables (α : Type) (p q : α → Prop)\n\nexample : (∀ x : α, p x ∧ q x) → ∀ z : α, p z :=\nassume h : ∀ x : α, p x ∧ q x,\n    take y : α,\n        show p y, from (h y)^.left\n\n    section\n    variable (r : α → α → Prop)\n    variable transr : ∀ {x y z}, r x y → r y z → r x z\n    variable reflr : ∀ x, r x x\n    variable symmr : ∀ {x y}, r x y → r y x\n\n    lemma a1short (a b c d : α) (hab : r a b) (hcb : r c b) (hcd : r c d) : r a d :=\n    transr (transr hab (symmr hcb)) hcd\n\n    lemma a1full\n    : Π α : Type, Π r : α → α → Prop, Π transr : Π {x y z}, r x y → r y z → r x z, Π symmr : Π x y, r x y → r y x, Π a b c d : α, r a b → r c b → r c d → r a d :=\n    λ α : Type, λ r : α → α → Prop, λ transr : Π {x y z}, r x y → r y z → r x z, λ symmr : Π x y, r x y → r y x, λ a b c d : α, λ hab : r a b, λ hcb : r c b, λ (hcd : r c d), (transr (transr hab (symmr c b hcb)) hcd)\n    end\n--variables (α : Type) (p q : α → Prop) is above\n\nexample : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=\niff.intro\n    (assume h : ∀ x, p x ∧ q x,\n        and.intro \n            (take z : α, show p z, from (h z)^.left)\n            (take z : α, show q z, from (h z)^.right))\n    (assume h : (∀ x, p x) ∧ (∀ x, q x),\n        take z : α,\n            show p z ∧ q z, from ⟨h^.left z, h^.right z⟩)\n\nexample : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=\nassume h : ∀ x, p x → q x,\n    assume h₂ : ∀ x, p x,\n        take z,\n            show q z, from (h z) (h₂ z)\n\nexample : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=\nassume h : (∀ x, p x) ∨ (∀ x, q x),\n    take x : α,\n        or.elim h\n            (assume h₂ : ∀ x, p x,\n                or.inl (h₂ x))\n            (assume h₃ : ∀ x, q x,\n                or.inr (h₃ x))\n\n    section\n    variable r : Prop\n    open classical\n    example : α → ((∀ x : α, r) ↔ r) :=\n    assume h : α,\n        iff.intro\n            (assume h₂ : ∀ x : α, r,\n                h₂ h)\n            (assume hr : r,\n                take x : α, hr)\n\n    example : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=\n    iff.intro\n        (assume h : ∀ x, p x ∨ r, by_contradiction\n        (assume h₃ : ¬((∀ x, p x) ∨ r),\n            have h₄ : ¬(∀ x, p x) ∧ ¬r, from (iff.elim_left lem₁) h₃,\n            have hapx : ∀ x, p x, from\n                take x : α, or.elim (h x)\n                    (assume hpx : p x, hpx)\n                    (assume hr : r, absurd hr h₄^.right),\n            h₄^.left hapx))\n        (assume h : (∀ x, p x) ∨ r,\n            or.elim h\n                (assume hpx : ∀ x, p x,\n                    take x : α,\n                        or.inl (hpx x))\n                (assume hr : r,\n                    take x : α,\n                        or.inr hr))\n\n    example : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=\n    iff.intro\n        (assume h : ∀ x, r → p x,\n            assume hr : r,\n                take x : α,\n                    h x hr)\n        (assume h : r → ∀ x, p x,\n            take x : α,\n                assume hr : r,\n                    h hr x)\n    end\n     \n    section\n    open classical\n    variables (men : Type) (barber : men) (shaves : men → men → Prop)\n\n    example (h : ∀ x : men, shaves barber x ↔ ¬ shaves x x) : false :=\n    iffcontradiction (h barber)\n    end\n\nend\n\nsection\n\nexample : 2 + 3 = 5 := rfl\n\nexample (x : ℕ) (h : x > 0) : ∃ y, y < x :=\n@exists.intro ℕ (λ y, y < x) 0 (h)\n\nexample (x : ℕ) (h : 0 < x) : @Exists (ℕ) (λ y, y < x) :=\nexists.intro 0 h\nsection\nvariables (α : Type) (p q : α → Prop)\n\nexample (h : ∃ x, p x ∧ q x) : ∃ x, q x ∧ p x :=\n@exists.elim α (λ x : α, p x ∧ q x) (∃ x, q x ∧ p x) h\n(take w : α,\nassume hw : (λ x : α, p x ∧ q x) w,\nshow ∃ x, q x ∧ p x, from @exists.intro α (λ x : α, q x ∧ p x) w ⟨hw^.right, hw^.left⟩)--⟨w, hw^.right, hw^.left⟩)\nend\nsection\ndef is_even (a : ℕ) := ∃ b, a = 2 * b\n/-\nis_even : ℕ → Prop\nexists.elim : ∀ (α : Type) (p : α → Prop) (b : Prop), (∃ (x : α), p x)\nexists.elim : ∀ (α : ℕ) (p : ℕ → Prop) (b : Prop), (∃ (x : ℕ), p x)\nexists.elim : ∀ (α : ℕ) (p : ℕ → Prop) (b : Prop), (∃ (x : ℕ), (p x) : Prop)\na : nat\nh1 : is_even a = Prop\nis_even a = ∃ b, eq a (2 * b)\nis_even = ∃ b, a = 2*b\n-/\ntheorem even_plus_even {a b : ℕ} (h1 : is_even a) (h2 : is_even b) : is_even (a + b) :=\n@exists.elim ℕ (λ b : ℕ, a = 2 * b) (is_even (a + b)) h1 (take w1, assume hw1 : a = 2 * w1,\nexists.elim h2 (take w2, assume hw2 : b = 2 * w2,\n    @exists.intro ℕ (λ (b_1 : ℕ), a + b = 2 * b_1) (w1 + w2)\n        (calc\n            a + b = 2 * w1 + 2 * w2 : by rw [hw1, hw2]\n              ... = 2 * (w1 + w2)   : by rw mul_add)))\nend\n\nsection\n\nsection\nopen classical\n\ntheorem contrapositive {p q : Prop} : p → q ↔ ¬q → ¬p :=\niff.intro\n    (assume h : p → q,\n        assume nq : ¬q,\n            by_contradiction (assume nnp : ¬¬p,\n                nq $ h $ dne nnp))\n    (assume h : ¬q → ¬p,\n        assume hp : p,\n            by_contradiction (assume nq : ¬q,\n                h nq hp))\n\nend\n\nopen classical\nvariables (α : Type) (p q : α → Prop)\nvariable a : α\nvariable r : Prop\n\nexample : (∃ x : α, r) → r :=\nassume h : (∃ x : α, r),\n    @exists.elim α (λ x : α, r) r h\n        (take a : α,\n            assume r,\n                r)\n\nexample : (∃ x : α, r) → r :=\nassume h : (∃ x : α, r),\n    match h with ⟨(a : α), (x : (λ y, r) a)⟩ :=\n        x\n    end\n\nlemma existstests₂ : r → (∃ x : α, r) :=\nassume hr : r,\n    ⟨a, hr⟩\nset_option pp.implicit true\n--check @exists.intro\n--print existstests₂\n\nexample : r → (∃ x : α, r) :=\nλ (hr : r), @Exists.intro α (λ (x : α), r) a hr\n\nexample : (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r :=\niff.intro\n    (assume h : ∃ x, p x ∧ r,\n        match h with ⟨(x : α), (hp : p x ∧ r)⟩ :=\n            ⟨⟨x, hp^.left⟩, hp^.right⟩\n        end)\n    (assume h : (∃ x, p x) ∧ r,\n        have hr : r, from h^.right,\n        have hp : ∃ x, p x, from h^.left,\n        match hp with ⟨(x : α), (hhp : p x)⟩ :=\n            ⟨x, hhp, hr⟩\n        end)\n\nexample : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=\niff.intro\n    (assume h : ∃ x, p x ∨ q x,\n        match h with ⟨(x : α), (hpq : p x ∨ q x)⟩ :=\n            or.elim hpq\n                (assume hpx : p x,\n                    or.inl ⟨x, hpx⟩)\n                (assume hqx : q x,\n                    or.inr ⟨x, hqx⟩)\n        end)\n    (assume h : (∃ x, p x) ∨ (∃ x, q x),\n        or.elim h\n            (assume epx : ∃ x, p x,\n                match epx with ⟨x, (hp : p x)⟩ :=\n                    ⟨x, or.inl hp⟩\n                end)\n            (assume eqx : ∃ x, q x,\n                match eqx with ⟨x, (hq : q x)⟩ :=\n                    ⟨x, or.inr hq⟩\n                end))\n\nlemma leme₁ {α : Type} {p : α → Prop} : (∀ x, p x) ↔ ¬(∃ x, ¬p x) :=\niff.intro\n    (assume h : ∀ x, p x,\n        not.intro (assume h₂ : ∃ x, ¬p x,\n            match h₂ with ⟨(t : α), (np : ¬p t)⟩ :=\n                np (h t)\n            end))\n    (assume h : ¬(∃ x, ¬p x),\n        take x,\n            by_contradiction\n                (assume np : ¬p x,\n                    h ⟨x, np⟩))\n\nlemma leme₂ {α : Type} {p : α → Prop} : (¬∃ x, p x) → (∀ x, ¬p x) :=\nassume h : ¬∃ x, p x,\n    take x,\n        (assume hpx : p x,\n            false.elim $ h ⟨x, hpx⟩)\n\nlemma leme₃ {α : Type} {p : α → Prop} : (∃ x, p x) ↔ ¬(∀ x, ¬p x) :=\niff.intro\n    (assume h : ∃ x, p x,\n        not.intro (assume n : ∀ x, ¬p x,\n            match h with ⟨x, hp⟩ :=\n                n x hp\n            end))\n    (assume h : ¬(∀ x, ¬p x),\n        by_contradiction\n            (assume h₂ : ¬∃ x, p x,\n                false.elim $ h $ leme₂ h₂))\n\nlemma leme₄ : (∀ x, ¬p x) → (¬∃ x, p x) :=\nassume h : ∀ x, ¬p x,\n    by_contradiction\n        (assume h₂ : ¬¬∃ x, p x,\n            false.elim $ leme₃^.elim_left (dne h₂) h) \n\nexample : (¬∀ x, p x) ↔ (∃ x, ¬p x) :=\niff.intro\n    (assume h : ¬∀ x, p x,\n        by_contradiction (assume hn : ¬∃ x, ¬p x,\n            h $ leme₁^.elim_right hn))\n    (assume h : ∃ x, ¬p x,\n        by_contradiction (assume hn : ¬¬∀ x, p x,\n            leme₁^.elim_left (dne hn) h))\n\nexample : (∀ x, p x → r) ↔ (∃ x, p x) → r :=\niff.intro\n    (assume h : ∀ x, p x → r,\n        assume h₂ : ∃ x, p x,\n            match h₂ with ⟨x, hpx⟩ :=\n                h x hpx\n            end)\n    (assume h : (∃ x, p x) → r,\n        take x,\n            assume h₂ : p x,\n                h (show ∃ x, p x, from\n                    ⟨x, h₂⟩))\n\nexample : (∃ x, p x → r) ↔ (∀ x, p x) → r :=\niff.intro\n    (assume h : ∃ x, p x → r,\n        assume h₂ : ∀ x, p x,\n            match h with ⟨a, h₃⟩ :=\n                h₃ $ h₂ a\n            end)\n    (assume h : (∀ x, p x) → r,\n        by_cases\n            (assume hap : ∀ x, p x,\n                ⟨a, take hpx : p a, h hap⟩)\n            (assume hnap : ¬∀ x, p x,\n                by_contradiction (assume h₂ : ¬∃ x, p x → r,\n                    have hap : ∀ x, p x, from\n                        take x, by_contradiction (assume hnp : ¬p x,\n                            have hex : ∃ x, p x → r, from\n                                ⟨x, (assume hp, absurd hp hnp)⟩,\n                            h₂ hex),\n                    hnap hap)))\n\nexample : (∃ x, r → p x) → (r → ∃ x, p x) := --TODO converse\n--iff.intro\n    (assume h : ∃ x, r → p x,\n        assume hr : r,\n            match h with ⟨y, hy⟩ :=\n                ⟨y, hy hr⟩\n            end)\n    /-\n    (assume h : r → ∃ x, p x,\n        by_cases\n            (assume h₂ : p a,\n                ⟨a, (assume hr : r, h₂)⟩)\n            (assume h₃ : ¬p a,\n                by_contradiction (assume h₄ : ¬(∃ x, r → p x),\n                    by_contradiction (assume hnnr : ¬¬r,\n                        have hr : r, from dne hnnr,\n                        have hexp : ∃ x, p x, from h hr,\n                        _\n                    )\n                    have h₅ : ∃ x, r → p x, from\n                        ⟨a, (assume hr : r, absurd hr nr)⟩,\n                    h₄ h₅))\n    -/\n\nend\n\n--check and.intro\ntheorem test (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=\n/-begin\n    apply and.intro,\n    exact hp,\n    apply and.intro,\n    exact hq,\n    exact hp\nend\n-/\nby apply and.intro hp (and.intro hq hp)\n\nvariables x y z w : ℕ\nexample (h₁ : x = y) (h₂ : y = z) (h₃ : z = w) : x = w :=\nbegin\n    apply eq.trans,\n    assumption,\n    apply eq.trans,\n    assumption,\n    assumption\nend\n\nexample (h₁ : x = y) (h₂ : y = z) (h₃ : z = w) : x = w :=\nbegin\n    apply eq.trans _ h₃,\n    apply eq.trans _ h₂,\n    assumption\nend\n\nexample : ∀ a b c : ℕ, a = b → a = c → c = b :=\nbegin\n    intros,\n    apply eq.trans,\n    apply eq.symm,\n    assumption,\n    assumption\nend\n\nexample : x + y + z = x + y + z :=\nbegin\n    generalize (x + y + z) w, -- goal is x y z : N ⊢ ∀ (w : N), w = w\n    clear x y z,\n    intro u, -- goal is x y z u : N ⊢ u = u\n    reflexivity\nend\n\nexample (x : ℕ) : x = x :=\nbegin\n    revert x, -- goal is ⊢ ∀ (x : N), x = x\n    intro y, -- goal is y : N ⊢ y = y\n    reflexivity\nend\n\nexample (x y : ℕ) (h : x = y) : y = x :=\n    begin\n    revert h, -- goal is x y : N ⊢ x = y → y = x\n    intro h₁, -- goal is x y : N, h 1 : x = y ⊢ y = x\n    symmetry,\n    assumption\nend\n\nexample (p q : Prop) : p ∨ q → q ∨ p :=\nbegin\n    intro h,\n    cases h with hp hq,\n    -- case hp : p\n    right, exact hp,\n    -- case hq : q\n    left, exact hq\nend\n\nexample (p q : ℕ → Prop) : (∃ x, p x) → ∃ x, p x ∨ q x :=\nbegin\n    revert p q,\n    intros p q h,\n    cases h with x px,\n    existsi x, left, exact px\nend\n\nsection\nopen nat\nexample (P : ℕ → Prop) (h₀ : P 0) (h₁ : ∀ n, P (succ n)) (m : ℕ) : P m :=\nbegin\n    cases m with m', exact h₀, exact h₁ m'\nend\nend\n\nexample : ∃ x : ℕ, x + 3 = 8 :=\nbegin\n    pose x := 5,\n    existsi 5,\n    clear x,\n    reflexivity\nend\n\nexample (a b : ℕ) (h : a = b) : a + 0 = b + 0 :=\nbegin\n    change a = b, --since a + 0 is defined to be a\n    assumption\nend\n\nsection\nvariables (f : ℕ → ℕ) (k : ℕ)\nexample (h₁ : f 0 = 0) (h₂ : k = 0) : f k = 0 :=\nbegin\n    rw h₂, -- replace k with 0\n    rw h₁  -- replace f 0 with 0\nend\nend\n\nexample (a b c : ℕ) : a + b + c = a + c + b :=\nbegin\n    rw [add_assoc, add_comm b, -add_assoc]\nend\n\nexample (a b c : ℕ) : a + b + c = a + c + b :=\nbegin\n    rw [add_assoc, add_assoc, add_comm b]\nend\n\nexample (a b c : ℕ) : a + b + c = a + c + b :=\nbegin\n    rw [add_assoc, add_assoc, add_comm _ b]\nend\n\nsection\nvariables (f : ℕ → ℕ) (a : ℕ)\nexample (h : a + 0 = 0) : f a = f 0 :=\nbegin\n    rw add_zero at h, rw h\nend\nend\n\nend\n\nnamespace nat\ndef addy (m n : nat) : nat :=\nnat.rec_on n m (λ n addy_m_n, succ addy_m_n)\n\n--eval addy (succ zero) (succ (succ zero))\n--set_option pp.implicit true\n\nend nat\n\nnamespace testin\ninductive es\n| zero : es\n| succ : es → es\n| succi : es → (es → es)\n| succ₂ : es → es → es\n\nend testin\n\nnamespace inductivetypes\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\ndef daynumber (d : weekday) : ℕ :=\nweekday.rec_on d (λ (x : ℕ), 4 * x) 10 15 20 25 30 35\n\n--check weekday.rec_on\n--check daynumber\n--check weekday.induction_on\n--eval daynumber (weekday.sunday 3)\n\ninductive bol : Type\n| tt : bol\n| ff : bol\n\nopen bol\n\ndef bnot (b : bol) : bol :=\nbol.rec_on b ff tt\n\ndef bor (b₁ b₂ : bol) : bol :=\nbol.rec_on b₁ tt (bol.rec_on b₂ tt ff) \n\ndef band (b₁ b₂ : bol) : bol :=\nbol.rec_on b₁ (bol.rec_on b₂ tt ff) ff\n\nexample : bnot tt = ff := rfl\nexample : bnot ff = tt := rfl\nexample : bnot (bnot tt) = tt := rfl\nexample (b : bol) : bnot (bnot b) = b :=\nbol.rec_on b\n    (show bnot (bnot tt) = tt, from rfl)\n    (show bnot (bnot ff) = ff, from rfl)\nexample (b₁ b₂ : bol) : bor b₁ b₂ = bor b₂ b₁ :=\nbol.rec_on b₁\n    (bol.rec_on b₂ rfl rfl)\n    (bol.rec_on b₂ rfl rfl)\nexample (b₁ b₂ : bol) : bor b₁ b₂ = bnot (band (bnot b₁) (bnot b₂)) :=\nbol.rec_on b₁\n    (bol.rec_on b₂ rfl rfl)\n    (bol.rec_on b₂ rfl rfl)\nsection universevariables\n\nuniverse variables u v\ninductive pro (α : Type u) (β : Type v)\n| mk : α → β → pro\ninductive su (α : Type u) (β : Type v)\n| il {} : α → su\n| ir {} : β → su\nopen pro su\n\ndef fst {α : Type u} {β : Type v} (p : pro α β) : α :=\npro.rec_on p (λ a b, a)\ndef snd {α : Type u} {β : Type v} (p : pro α β) : β :=\npro.rec_on p (λ a b, b)\n\ndef funky₁ (s : su ℕ ℕ) : ℕ :=\nsu.rec_on s (λ x, x + 12) (λ x, x * 7)\n\n--eval funky₁ $ su.ir 3\n\ninductive maybe (α : Type u)\n| nothing {} : maybe\n| just       : α → maybe\n\n--check maybe.rec_on\n\ndef bolmaybefun (m : maybe bol) : bol :=\nmaybe.rec_on m (bol.ff) (λ b, b)\n\n--eval bolmaybefun $ maybe.just ff\n\ndef maybeffun (f : ℕ) : maybe ℕ :=\ncond (f < 5) (maybe.nothing) (maybe.just (f*f))\n--check maybeffun\n\ninductive inhab (α : Type u)\n| mk : α → inhab\n\ndef partialsub (a : ℕ) (b : ℕ) : maybe ℕ :=\ncond (a < b) (maybe.nothing) (maybe.just (a-b))\n\n--def partialcomp {α β γ : Type u} (f : maybe (α → β)) (g : maybe (β → γ)) : maybe (α → γ) :=\nlemma inhabnat : inhab ℕ :=\ninhab.mk 0\n\nlemma inhabbol : inhab bol :=\ninhab.mk bol.tt\n\nlemma inhabprod (α : Type u) (β : Type v) (a : inhab α) (b : inhab β) : inhab (α × β) :=\ninhab.mk (prod.mk (inhab.rec_on a (λ a₂, a₂)) (inhab.rec_on b (λ b₂, b₂)))\n\ninductive pfalse : Prop\n\ninductive ptrue : Prop\n| intro : ptrue\n\ninductive pand (a b : Prop) : Prop\n| intro : a → b → pand\n\ninductive por (a b : Prop) : Prop\n| inl {} : a → por\n| inr {} : b → por\n\ninductive pexists {α : Type u} (p : α → Prop) : Prop\n| intro : ∀ (a : α), p a → pexists\n\n/-\ncheck @pand.rec_on\ncheck @por.rec_on\ncheck @pexists.rec_on\ncheck @nat.rec_on\n-/\n\nend universevariables\n\nend inductivetypes\n\nnamespace inductivetactics\n\nopen nat\nvariable p : ℕ → Prop\n\nexample (hz : p 0) (hs : ∀ n, p (succ n)) : ∀ n, p n :=\nbegin\n    intro n,\n    cases n,\n    exact hz,\n    apply hs\nend\n\ndef f (n : ℕ) : ℕ :=\nbegin\n    cases n, exact 3, exact 7\nend\n\n/-\ncheck list.rec\n\nvariable α : Type\ndef appendy (s t : list α) : list α :=\nlist.rec t (λ x l u, x::u) s\nprint appendy\n-/\n\ndef is_not_zero (a : nat) : bool :=\nmatch a with\n| 0 := ff\n| (n+1) := tt\nend\n\nuniverse variable u\nclass has_add (α : Type u) :=\n(add : α → α → α)\n\ndef add {α : Type u} [has_add α] : α → α → α := has_add.add\n\ninstance nat_has_add : has_add nat :=\n--⟨nat.add⟩\nhas_add.mk nat.add --should be equivalent\n\nend inductivetactics\n\n/-\ndefinition compA : Π p q r : Prop, (q → r) → (p → q) → p → r :=\nλ p, λ q, λ r, λ h1, λ h2, λ h3, h1 (h2 h3)\nvariables p q r s : Prop\ntheorem comp (h1 : q → r) (h2 : p → q) (h3 : p): r := h1 (h2 h3)\ntheorem com3 (h1 : q → r) (h2 : p → q) : p → r :=\nλ h3 : p, h1 (h2 h3)\ntheorem com2 : (q → r) → (p → q) → p → r :=\nλ h1, λ h2, λ h3, h1 (h2 h3)\nvariable h1 : q → r\nvariable h2 : p → q\nvariable h3 : p\ntheorem compy : r := h1 (h2 h3)\n\ncheck compA\ncheck comp\ncheck compy\n-/\n\n/-\nuniverse variable u\ndef ident (α : Type u) (x : α) := x\ndef ident' := λ α : Type u, λ x : α, x\ndef identy {α : Type u} (x : α) := x\n\ncheck ident\ncheck ident'\n\nvariable β : Type\nvariable b : β\ncheck identy b\ncheck @identy β b\n\nsection\nvariables p q : Prop\ntheorem t1 : p → q → p := λ hp : p, λ hq : q, hp\nend\n--theorem t1 := λ p : Prop, λ q : Prop, λ hp : p, λ hq : q, hp\ntheorem t1' (p q : Prop) (hp : p) (hq : q) : p := hp\ntheorem t₁ (p q : Prop) : p → q → p := λ hp, λ hq, hp\ntheorem t₁' (p q : Prop) (hp : p) : q → p := λ hq, hp\ntheorem t₂ : Π p : Prop, Π q : Prop, p → q → p := λ p : Prop, λ q : Prop, λ hp, λ hq, hp\ntheorem t₃ : Π p q : Prop, p → q → p := λ p : Prop, λ q : Prop, λ hp, λ hq, hp\n--theorem t1₁ (p q : Prop) (hp : p) (hq : q) : p := hp\ncheck t1\ncheck t1'\ncheck t₁'\ncheck t₁\ncheck t₂\n-/\n", "meta": {"author": "OwenGraves", "repo": "TaoAnalysis", "sha": "695b149b5decdb6f8e46c883ea112f0a12082548", "save_path": "github-repos/lean/OwenGraves-TaoAnalysis", "path": "github-repos/lean/OwenGraves-TaoAnalysis/TaoAnalysis-695b149b5decdb6f8e46c883ea112f0a12082548/LeanTest.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.750986935617872}}
{"text": "import Leanhello\n\ndef main : IO Unit := do\n  IO.println s!\"Hello, {hello}!\"\n  IO.println s!\"Hello, {hello}!\"\n\ninductive Palindrome: List α -> Prop where\n  | nil : Palindrome []\n  | single : (a : α) -> Palindrome [a]\n  | sandwich : (a : α) -> Palindrome as -> Palindrome ([a] ++ as ++ [a])\n\ntheorem palindrome_reverse (h: Palindrome as) : Palindrome as.reverse := by\n  induction h with \n  | nil => exact Palindrome.nil\n  | single a => exact Palindrome.single a\n  | sandwich a h ih => simp; exact Palindrome.sandwich _ ih\n\ntheorem reverse_eq_of_palindrome (hh: Palindrome as) : as.reverse = as := by\n  induction hh with\n  | nil => rfl\n  | single a => rfl\n  | sandwich a _ ih => simp [ih]\n\nexample (h: Palindrome as) : as.reverse = as := by\n  simp [reverse_eq_of_palindrome h, h]\n\ndef List.last : (as : List α) → as ≠ [] → α\n  | [a],        _ => a\n  | _::a₂::as, _ => (a₂::as).last (by simp)\n\n@[simp] theorem List.dropLast_append_last (h : as ≠ []) : as.dropLast ++ [as.last h] = as := by\n  match as with\n  | [] => contradiction\n  | [a] => simp_all [last, dropLast]\n  | a₁ :: a₂ :: as =>\n    simp [last ,dropLast]\n    exact dropLast_append_last (as := a₂ :: as) (by simp)\n\ntheorem List.palindrome_ind (motive : List α → Prop)\n    (h₁ : motive [])\n    (h₂ : (a : α) → motive [a])\n    (h₃ : (a b : α) → (as : List α) → motive as → motive ([a] ++ as ++ [b]))\n    (as : List α)\n    : motive as :=\n  match as with\n  | []  => h₁\n  | [a] => h₂ a\n  | a₁::a₂::as' =>\n    have ih := palindrome_ind motive h₁ h₂ h₃ (a₂::as').dropLast\n    have : [a₁] ++ (a₂::as').dropLast ++ [(a₂::as').last (by simp)] = a₁::a₂::as' := by simp\n    this ▸ h₃ _ _ _ ih\ntermination_by _ as => as.length\n\ntheorem List.palindrome_of_eq_reverse (h : as.reverse = as) : Palindrome as := by\n  induction as using palindrome_ind\n  next => exact Palindrome.nil\n  next a => exact Palindrome.single a\n  next a b as ih =>\n    have : a = b := by simp_all\n    subst this\n    have : as.reverse = as := by simp_all\n    exact Palindrome.sandwich a (ih this)\n\ndef List.isPalindrome [DecidableEq α] (as : List α) : Bool :=\n    as.reverse = as\n\ntheorem List.isPalindrome_correct [DecidableEq α] (as : List α) : as.isPalindrome ↔ Palindrome as := by\n  simp [isPalindrome]\n  exact Iff.intro (fun h => palindrome_of_eq_reverse h) (fun h => reverse_eq_of_palindrome h)\n\n#eval [1, 2, 1].isPalindrome\n#eval [1, 2, 3, 1].isPalindrome\n\nexample : [1, 2, 1].isPalindrome := rfl\n", "meta": {"author": "denjiry", "repo": "leanhello", "sha": "3f2a471a78a63c4124d39b39b551c63586e68590", "save_path": "github-repos/lean/denjiry-leanhello", "path": "github-repos/lean/denjiry-leanhello/leanhello-3f2a471a78a63c4124d39b39b551c63586e68590/Main.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7507667046748269}}
{"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önne, Benjamin Davidson\n-/\nimport analysis.special_functions.trigonometric.basic\nimport topology.algebra.ordered.proj_Icc\n\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\nnoncomputable theory\nopen_locale classical topological_space filter\nopen set filter\n\nopen_locale real\n\nnamespace real\n\n/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.\nIt defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/\n@[pp_nodot] noncomputable def arcsin : ℝ → ℝ :=\ncoe ∘ Icc_extend (neg_le_self zero_le_one) sin_order_iso.symm\n\nlemma arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := subtype.coe_prop _\n\n@[simp] lemma range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) :=\nby { rw [arcsin, range_comp coe], simp [Icc] }\n\nlemma arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2\n\nlemma neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1\n\nlemma arcsin_proj_Icc (x : ℝ) :\n  arcsin (proj_Icc (-1) 1 (neg_le_self $ @zero_le_one ℝ _) x) = arcsin x :=\nby rw [arcsin, function.comp_app, Icc_extend_coe, function.comp_app, Icc_extend]\n\nlemma sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 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 ⟨x, hx⟩)\n\nlemma sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=\nsin_arcsin' ⟨hx₁, hx₂⟩\n\nlemma arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 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 : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=\narcsin_sin' ⟨hx₁, hx₂⟩\n\nlemma strict_mono_on_arcsin : strict_mono_on arcsin (Icc (-1) 1) :=\n(subtype.strict_mono_coe _).comp_strict_mono_on $\n  sin_order_iso.symm.strict_mono.strict_mono_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_on_arcsin.inj_on\n\nlemma arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :\n  arcsin x = arcsin y ↔ x = y :=\ninj_on_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩\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 : ℝ} : continuous_at arcsin x :=\ncontinuous_arcsin.continuous_at\n\nlemma arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin y = x :=\nbegin\n  subst y,\n  exact inj_on_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))\nend\n\n@[simp] lemma arcsin_zero : arcsin 0 = 0 :=\narcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩\n\n@[simp] lemma arcsin_one : arcsin 1 = π / 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 : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 :=\nby rw [← arcsin_proj_Icc, proj_Icc_of_right_le _ hx, subtype.coe_mk, arcsin_one]\n\nlemma arcsin_neg_one : arcsin (-1) = -(π / 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 : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) :=\nby rw [← arcsin_proj_Icc, proj_Icc_of_le_left _ hx, subtype.coe_mk, arcsin_neg_one]\n\n@[simp] lemma arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x :=\nbegin\n  cases le_total x (-1) with hx₁ hx₁,\n  { rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] },\n  cases le_total 1 x with hx₂ hx₂,\n  { rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] },\n  refine arcsin_eq_of_sin_eq _ _,\n  { rw [sin_neg, sin_arcsin hx₁ hx₂] },\n  { exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ }\nend\n\nlemma arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin x ≤ y ↔ x ≤ sin y :=\nby rw [← arcsin_sin' hy, strict_mono_on_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]\n\nlemma arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :\n  arcsin x ≤ y ↔ x ≤ sin y :=\nbegin\n  cases le_total x (-1) with hx₁ hx₁,\n  { simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] },\n  cases lt_or_le 1 x with hx₂ hx₂,\n  { simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] },\n  exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)\nend\n\nlemma le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :\n  x ≤ arcsin y ↔ sin x ≤ y :=\nby rw [← neg_le_neg_iff, ← arcsin_neg,\n  arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩,\n  sin_neg, neg_le_neg_iff]\n\nlemma le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :\n  x ≤ arcsin y ↔ sin x ≤ y :=\nby rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,\n  sin_neg, neg_le_neg_iff]\n\nlemma arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :\n  arcsin x < y ↔ 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 : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :\n  arcsin x < y ↔ 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 : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :\n  x < arcsin y ↔ 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 : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :\n  x < arcsin y ↔ 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 : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :\n  arcsin x = y ↔ 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 : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=\n(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans $ by rw [sin_zero]\n\n@[simp] lemma arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=\nneg_nonneg.symm.trans $ arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg\n\n@[simp] lemma arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 :=\nby simp [le_antisymm_iff]\n\n@[simp] lemma zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=\neq_comm.trans arcsin_eq_zero_iff\n\n@[simp] lemma arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=\nlt_iff_lt_of_le_iff_le arcsin_nonpos\n\n@[simp] lemma arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=\nlt_iff_lt_of_le_iff_le arcsin_nonneg\n\n@[simp] lemma arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ 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 : ℝ} : -(π / 2) < arcsin x ↔ -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 : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=\n⟨λ h, not_lt.1 $ λ h', (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩\n\n@[simp] lemma pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=\neq_comm.trans arcsin_eq_pi_div_two\n\n@[simp] lemma pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ 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 : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=\n⟨λ h, not_lt.1 $ λ h', (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩\n\n@[simp] lemma neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=\neq_comm.trans arcsin_eq_neg_pi_div_two\n\n@[simp] lemma arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -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 (-(π / 2)) (π / 2)) (Ioo (-1) 1) :=\nλ x h, by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin,\n  arcsin_sin h.1.le h.2.le]\n\n/-- `real.sin` as a `local_homeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/\n@[simp] def sin_local_homeomorph : local_homeomorph ℝ ℝ :=\n{ to_fun := sin,\n  inv_fun := arcsin,\n  source := Ioo (-(π / 2)) (π / 2),\n  target := Ioo (-1) 1,\n  map_source' := maps_to_sin_Ioo,\n  map_target' := λ y hy, ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩,\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 := 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 : ℝ) : 0 ≤ cos (arcsin x) :=\ncos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩\n\nlemma cos_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 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 [← eq_sub_iff_add_eq', ← 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₁ hx₂],\nend\n\n/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.\n  If the argument is not between `-1` and `1` it defaults to `π / 2` -/\n@[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ :=\nπ / 2 - arcsin x\n\nlemma arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x := rfl\n\nlemma arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x :=\nby simp [arccos]\n\nlemma arccos_le_pi (x : ℝ) : arccos x ≤ π :=\nby unfold arccos; linarith [neg_pi_div_two_le_arcsin x]\n\nlemma arccos_nonneg (x : ℝ) : 0 ≤ arccos x :=\nby unfold arccos; linarith [arcsin_le_pi_div_two x]\n\nlemma cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x :=\nby rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]\n\nlemma arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x :=\nby rw [arccos, ← sin_pi_div_two_sub, arcsin_sin]; simp [sub_eq_add_neg]; linarith\n\nlemma strict_anti_on_arccos : strict_anti_on arccos (Icc (-1) 1) :=\nλ x hx y hy h, sub_lt_sub_left (strict_mono_on_arcsin hx hy h) _\n\nlemma arccos_inj_on : inj_on arccos (Icc (-1) 1) := strict_anti_on_arccos.inj_on\n\nlemma arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :\n  arccos x = arccos y ↔ x = y :=\narccos_inj_on.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩\n\n@[simp] lemma arccos_zero : arccos 0 = π / 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) = π := by simp [arccos, add_halves]\n\n@[simp] lemma arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x :=\nby simp [arccos, sub_eq_zero]\n\n@[simp] lemma arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 :=\nby simp [arccos, sub_eq_iff_eq_add]\n\n@[simp] lemma arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 :=\nby rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]\n\nlemma arccos_neg (x : ℝ) : arccos (-x) = π - arccos x :=\nby rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]\n\nlemma sin_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 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₁ hx₂]\n\n@[continuity]\nlemma continuous_arccos : continuous arccos := continuous_const.sub continuous_arcsin\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/trigonometric/inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7507666919670115}}
{"text": "/-\n2. Prove the following identities, replacing the “sorry” placeholders with actual proofs. These require classical reasoning.\n-/\n\nopen classical\n\nvariables p q r s : Prop\n\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n    assume h : p → r ∨ s,\n    (em p).elim\n    (\n        assume hp : p,\n        have hrs : r ∨ s, from h hp,\n        hrs.elim\n        (\n            assume hr : r,\n            show (p → r) ∨ (p → s),\n            from or.inl (assume hp : p, hr)\n        )\n        (\n            assume hs : s,\n            show (p → r) ∨ (p → s),\n            from or.inr (assume hp : p, hs)\n        )\n    )\n    (\n        assume hnp : ¬p,\n        suffices hpr : p → r, from or.inl hpr,\n        show p → r, from\n            assume hp : p,\n            show r, from false.elim (hnp hp)\n    )\n-- short version\nexample : (p → r ∨ s) → ((p → r) ∨ (p → s)) :=\n    λ h,\n    (em p).elim\n    (\n        λ hp,\n        (h hp).elim\n        (λ hr, or.inl (λ hp : p, hr))\n        (λ hs, or.inr (λ hp : p, hs))\n    )\n    (λ hnp, or.inl (λ hp, absurd hp hnp))\n\n\n\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n    assume h : ¬(p ∧ q),\n    or.elim (em p)\n    (\n        assume hp : p,\n        have hnq : ¬q, from\n            assume hq : q,\n            h ⟨hp, hq⟩,\n        or.inr hnq\n    )\n    (\n        assume hnp : ¬p,\n        or.inl hnp\n    )\n-- short version\nexample : ¬(p ∧ q) → ¬p ∨ ¬q :=\n    λ h,\n    or.elim (em p)\n    (λ hp, or.inr (λ hq, h ⟨hp, hq⟩))\n    (λ hnp, or.inl hnp)\n\n\n\nexample : ¬(p → q) → p ∧ ¬q :=\n    assume h : ¬(p → q),\n    (em p).elim\n    (\n        assume hp : p,\n        (em q).elim\n        (\n            assume hq : q,\n            have hpimplq : p → q, from\n                assume hp' : p,\n                hq,\n            show p ∧ ¬q, from false.elim (h hpimplq)\n        )\n        (\n            assume hnq : ¬q,\n            show p ∧ ¬q, from ⟨hp, hnq⟩\n        )\n    )\n    (\n        assume hnp : ¬p,\n        have hpimplq : p → q, from\n            assume hp : p,\n            false.elim (hnp hp),\n        false.elim (h hpimplq)\n    )\n-- short version\nexample : ¬(p → q) → p ∧ ¬q :=\n    λ h,\n    (em p).elim\n    (\n        λ hp : p,\n        (em q).elim\n        (λ hq, absurd (λ hp', hq) h)\n        (λ hnq, ⟨hp, hnq⟩)\n    )\n    (\n        λ hnp,\n        false.elim (h (λ hp, absurd hp hnp))\n    )\n\n\n\nexample : (p → q) → (¬p ∨ q) :=\n    assume h : p → q,\n    (em p).elim\n    (\n        assume hp : p,\n        or.inr (h hp)\n    )\n    (\n        assume hnp : ¬p,\n        or.inl hnp\n    )\n-- short version\nexample : (p → q) → (¬p ∨ q) :=\n    λ h,\n    (em p).elim\n    (λ hp, or.inr (h hp))\n    (λ hnp, or.inl hnp)\n\n\n\nexample : (¬q → ¬p) → (p → q) :=\n    assume h : ¬q → ¬p,\n    assume hp : p,\n    (em q).elim\n    (\n        assume hq : q,\n        hq\n    )\n    (\n        assume hnq : ¬q,\n        absurd hp (h hnq)\n    )\n-- short version\nexample : (¬q → ¬p) → (p → q) :=\n    λ h,\n    λ hp,\n    (em q).elim\n    id\n    (λ hnq, absurd hp (h hnq))\n\n\n\nexample : p ∨ ¬p :=\n    em p\n\n\n\nexample : (((p → q) → p) → p) :=\n    assume h : (p → q) → p,\n    (em p).elim\n    (\n        assume hp : p,\n        hp\n    )\n    (\n        assume hnp : ¬p,\n        have hpimplq : p → q, from\n            assume hp : p,\n            absurd hp hnp,\n        absurd (h hpimplq) hnp\n    )\n-- short version\nexample : (((p → q) → p) → p) :=\n    λ h,\n    (em p).elim\n    id\n    (λ hnp, absurd (h (λ hp : p, absurd hp 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-ex02.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.8104789040926007, "lm_q1q2_score": 0.7507496371321889}}
{"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 analysis.special_functions.exponential\n/-!\n# Trigonometric functions as sums of infinite series\n\nIn this file we express trigonometric functions in terms of their series expansion.\n\n## Main results\n\n* `complex.has_sum_cos`, `complex.tsum_cos`: `complex.cos` as the sum of an infinite series.\n* `real.has_sum_cos`, `real.tsum_cos`: `real.cos` as the sum of an infinite series.\n* `complex.has_sum_sin`, `complex.tsum_sin`: `complex.sin` as the sum of an infinite series.\n* `real.has_sum_sin`, `real.tsum_sin`: `real.sin` as the sum of an infinite series.\n-/\n\nopen_locale nat\n\n/-! ### `cos` and `sin` for `ℝ` and `ℂ` -/\n\nsection sin_cos\n\nlemma complex.has_sum_cos' (z : ℂ) :\n  has_sum (λ n : ℕ, (z * complex.I) ^ (2 * n) / ↑(2 * n)!) (complex.cos z) :=\nbegin\n  rw [complex.cos, complex.exp_eq_exp_ℂ],\n  have := ((exp_series_div_has_sum_exp ℂ (z * complex.I)).add\n          (exp_series_div_has_sum_exp ℂ (-z * complex.I))).div_const 2,\n  replace := ((nat.div_mod_equiv 2)).symm.has_sum_iff.mpr this,\n  dsimp [function.comp] at this,\n  simp_rw [←mul_comm 2 _] at this,\n  refine this.prod_fiberwise (λ k, _),\n  dsimp only,\n  convert has_sum_fintype (_ : fin 2 → ℂ) using 1,\n  rw fin.sum_univ_two,\n  simp_rw [fin.coe_zero, fin.coe_one, add_zero, pow_succ', pow_mul,\n    mul_pow, neg_sq, ←two_mul, neg_mul, mul_neg, neg_div, add_right_neg, zero_div, add_zero,\n    mul_div_cancel_left _ (two_ne_zero : (2 : ℂ) ≠ 0)],\nend\n\nlemma complex.has_sum_sin' (z : ℂ) :\n  has_sum (λ n : ℕ, (z * complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / complex.I) (complex.sin z) :=\nbegin\n  rw [complex.sin, complex.exp_eq_exp_ℂ],\n  have := (((exp_series_div_has_sum_exp ℂ (-z * complex.I)).sub\n          (exp_series_div_has_sum_exp ℂ (z * complex.I))).mul_right complex.I).div_const 2,\n  replace := ((nat.div_mod_equiv 2)).symm.has_sum_iff.mpr this,\n  dsimp [function.comp] at this,\n  simp_rw [←mul_comm 2 _] at this,\n  refine this.prod_fiberwise (λ k, _),\n  dsimp only,\n  convert has_sum_fintype (_ : fin 2 → ℂ) using 1,\n  rw fin.sum_univ_two,\n  simp_rw [fin.coe_zero, fin.coe_one, add_zero, pow_succ', pow_mul,\n    mul_pow, neg_sq, sub_self, zero_mul, zero_div, zero_add,\n    neg_mul, mul_neg, neg_div, ← neg_add', ←two_mul, neg_mul, neg_div, mul_assoc,\n    mul_div_cancel_left _ (two_ne_zero : (2 : ℂ) ≠ 0), complex.div_I],\nend\n\n/-- The power series expansion of `complex.cos`. -/\nlemma complex.has_sum_cos (z : ℂ) :\n  has_sum (λ n : ℕ, ((-1) ^ n) * z ^ (2 * n) / ↑(2 * n)!) (complex.cos z) :=\nbegin\n  convert complex.has_sum_cos' z using 1,\n  simp_rw [mul_pow, pow_mul, complex.I_sq, mul_comm]\nend\n\n/-- The power series expansion of `complex.sin`. -/\nlemma complex.has_sum_sin (z : ℂ) :\n  has_sum (λ n : ℕ, ((-1) ^ n) * z ^ (2 * n + 1) / ↑(2 * n + 1)!) (complex.sin z) :=\nbegin\n  convert complex.has_sum_sin' z using 1,\n  simp_rw [mul_pow, pow_succ', pow_mul, complex.I_sq, ←mul_assoc,\n    mul_div_assoc, div_right_comm, div_self complex.I_ne_zero, mul_comm _ ((-1 : ℂ)^_), mul_one_div,\n    mul_div_assoc, mul_assoc]\nend\n\nlemma complex.cos_eq_tsum' (z : ℂ) :\n  complex.cos z = ∑' n : ℕ, (z * complex.I) ^ (2 * n) / ↑(2 * n)! :=\n(complex.has_sum_cos' z).tsum_eq.symm\n\nlemma complex.sin_eq_tsum' (z : ℂ) :\n  complex.sin z = ∑' n : ℕ, (z * complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / complex.I :=\n(complex.has_sum_sin' z).tsum_eq.symm\n\nlemma complex.cos_eq_tsum (z : ℂ) :\n  complex.cos z = ∑' n : ℕ, ((-1) ^ n) * z ^ (2 * n) / ↑(2 * n)! :=\n(complex.has_sum_cos z).tsum_eq.symm\n\nlemma complex.sin_eq_tsum (z : ℂ) :\n  complex.sin z = ∑' n : ℕ, ((-1) ^ n) * z ^ (2 * n + 1) / ↑(2 * n + 1)! :=\n(complex.has_sum_sin z).tsum_eq.symm\n\n/-- The power series expansion of `real.cos`. -/\nlemma real.has_sum_cos (r : ℝ) :\n  has_sum (λ n : ℕ, ((-1) ^ n) * r ^ (2 * n) / ↑(2 * n)!) (real.cos r) :=\nby exact_mod_cast complex.has_sum_cos r\n\n/-- The power series expansion of `real.sin`. -/\nlemma real.has_sum_sin (r : ℝ) :\n  has_sum (λ n : ℕ, ((-1) ^ n) * r ^ (2 * n + 1) / ↑(2 * n + 1)!) (real.sin r) :=\nby exact_mod_cast complex.has_sum_sin r\n\nlemma real.cos_eq_tsum (r : ℝ) :\n  real.cos r = ∑' n : ℕ, ((-1) ^ n) * r ^ (2 * n) / ↑(2 * n)! :=\n(real.has_sum_cos r).tsum_eq.symm\n\nlemma real.sin_eq_tsum (r : ℝ) :\n  real.sin r = ∑' n : ℕ, ((-1) ^ n) * r ^ (2 * n + 1) / ↑(2 * n + 1)! :=\n(real.has_sum_sin r).tsum_eq.symm\n\nend sin_cos\n", "meta": {"author": "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/series.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.750749423773399}}
{"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) : (¬¬p) = p :=\n  propext not_not\n\ntheorem not_and_eq (p : Prop) (q : Prop) : (¬(p ∧ q)) = (p → ¬q) :=\n  propext not_and\n\ntheorem not_or_eq (p : Prop) (q : Prop) : (¬(p ∨ q)) = (¬p ∧ ¬q) :=\n  propext not_or_distrib\n\ntheorem not_forall_eq {α : Sort u} (s : α → Prop) : (¬∀ (x : α), s x) = ∃ (x : α), ¬s x :=\n  propext not_forall\n\ntheorem not_exists_eq {α : Sort u} (s : α → Prop) : (¬∃ (x : α), s x) = ∀ (x : α), ¬s x :=\n  propext not_exists\n\ntheorem not_implies_eq (p : Prop) (q : Prop) : (¬(p → q)) = (p ∧ ¬q) :=\n  propext not_imp\n\ntheorem classical.implies_iff_not_or (p : Prop) (q : Prop) : p → q ↔ ¬p ∨ q :=\n  imp_iff_not_or\n\ntheorem not_eq {α : Sort u} (a : α) (b : α) : ¬a = b ↔ a ≠ b :=\n  iff.rfl\n\ntheorem not_le_eq {β : Type u} [linear_order β] (a : β) (b : β) : (¬a ≤ b) = (b < a) :=\n  propext not_le\n\ntheorem not_lt_eq {β : Type u} [linear_order β] (a : β) (b : β) : (¬a < b) = (b ≤ 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 : ¬ ∀ x, ∃ y, x ≤ y` will be transformed by `push_neg at h` into\n`h : ∃ x, ∀ y, y < x`. Variables names are conserved.\n\nThis tactic pushes negations inside expressions. For instance, given an assumption\n```lean\nh : ¬ ∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - y₀| ≤ ε)\n```\nwriting `push_neg at h` will turn `h` into\n```lean\nh : ∃ ε, ε > 0 ∧ ∀ δ, δ > 0 → (∃ x, |x - x₀| ≤ δ ∧ ε < |f x - y₀|),\n```\n\n(the pretty printer does *not* use the abreviations `∀ δ > 0` and `∃ ε > 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' ⊢` as usual.\n-/\ntheorem imp_of_not_imp_not (P : Prop) (Q : Prop) : (¬Q → ¬P) → P → Q :=\n  fun (h : ¬Q → ¬P) (hP : P) => classical.by_contradiction fun (h' : ¬Q) => 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 → Q` into `¬ Q → ¬ P`\n* `contrapose!`    turns a goal `P → Q` into `¬ Q → ¬ 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-/\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/push_neg.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7507494220038965}}
{"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.multiset.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.Multiset.Nodup\nimport Mathbin.Data.List.NatAntidiagonal\n\n/-!\n# Antidiagonals in ℕ × ℕ as multisets\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 ℕ × ℕ as multisets: the `n`-th antidiagonal is the multiset\nof pairs `(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 file `data.list.nat_antidiagonal` and is further refined by file\n`data.finset.nat_antidiagonal`.\n-/\n\n\nnamespace Multiset\n\nnamespace Nat\n\n#print Multiset.Nat.antidiagonal /-\n/-- The antidiagonal of a natural number `n` is\n    the multiset of pairs `(i, j)` such that `i + j = n`. -/\ndef antidiagonal (n : ℕ) : Multiset (ℕ × ℕ) :=\n  List.Nat.antidiagonal n\n#align multiset.nat.antidiagonal Multiset.Nat.antidiagonal\n-/\n\n#print Multiset.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 : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := by\n  rw [antidiagonal, mem_coe, List.Nat.mem_antidiagonal]\n#align multiset.nat.mem_antidiagonal Multiset.Nat.mem_antidiagonal\n-/\n\n/- warning: multiset.nat.card_antidiagonal -> Multiset.Nat.card_antidiagonal is a dubious translation:\nlean 3 declaration is\n  forall (n : Nat), Eq.{1} Nat (coeFn.{1, 1} (AddMonoidHom.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.orderedCancelAddCommMonoid.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (fun (_x : AddMonoidHom.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.orderedCancelAddCommMonoid.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) => (Multiset.{0} (Prod.{0, 0} Nat Nat)) -> Nat) (AddMonoidHom.hasCoeToFun.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.orderedCancelAddCommMonoid.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.card.{0} (Prod.{0, 0} Nat Nat)) (Multiset.Nat.antidiagonal n)) (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), Eq.{1} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Multiset.{0} (Prod.{0, 0} Nat Nat)) => Nat) (Multiset.Nat.antidiagonal n)) (FunLike.coe.{1, 1, 1} (AddMonoidHom.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.instOrderedCancelAddCommMonoidMultiset.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{0} (Prod.{0, 0} Nat Nat)) (fun (_x : Multiset.{0} (Prod.{0, 0} Nat Nat)) => (fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Multiset.{0} (Prod.{0, 0} Nat Nat)) => Nat) _x) (AddHomClass.toFunLike.{0, 0, 0} (AddMonoidHom.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.instOrderedCancelAddCommMonoidMultiset.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddZeroClass.toAdd.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.instOrderedCancelAddCommMonoidMultiset.{0} (Prod.{0, 0} Nat Nat)))))))) (AddZeroClass.toAdd.{0} Nat (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (AddMonoidHomClass.toAddHomClass.{0, 0, 0} (AddMonoidHom.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.instOrderedCancelAddCommMonoidMultiset.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)) (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.instOrderedCancelAddCommMonoidMultiset.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid) (AddMonoidHom.addMonoidHomClass.{0, 0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) Nat (AddMonoid.toAddZeroClass.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddRightCancelMonoid.toAddMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelMonoid.toAddRightCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (AddCancelCommMonoid.toAddCancelMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (OrderedCancelAddCommMonoid.toCancelAddCommMonoid.{0} (Multiset.{0} (Prod.{0, 0} Nat Nat)) (Multiset.instOrderedCancelAddCommMonoidMultiset.{0} (Prod.{0, 0} Nat Nat))))))) (AddMonoid.toAddZeroClass.{0} Nat Nat.addMonoid)))) (Multiset.card.{0} (Prod.{0, 0} Nat Nat)) (Multiset.Nat.antidiagonal n)) (HAdd.hAdd.{0, 0, 0} Nat ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Multiset.{0} (Prod.{0, 0} Nat Nat)) => Nat) (Multiset.Nat.antidiagonal n)) Nat (instHAdd.{0} Nat instAddNat) n (OfNat.ofNat.{0} ((fun (x._@.Mathlib.Algebra.Hom.Group._hyg.403 : Multiset.{0} (Prod.{0, 0} Nat Nat)) => Nat) (Multiset.Nat.antidiagonal n)) 1 (instOfNatNat 1)))\nCase conversion may be inaccurate. Consider using '#align multiset.nat.card_antidiagonal Multiset.Nat.card_antidiagonalₓ'. -/\n/-- The cardinality of the antidiagonal of `n` is `n+1`. -/\n@[simp]\ntheorem card_antidiagonal (n : ℕ) : (antidiagonal n).card = n + 1 := by\n  rw [antidiagonal, coe_card, List.Nat.length_antidiagonal]\n#align multiset.nat.card_antidiagonal Multiset.Nat.card_antidiagonal\n\n#print Multiset.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 multiset.nat.antidiagonal_zero Multiset.Nat.antidiagonal_zero\n-/\n\n#print Multiset.Nat.nodup_antidiagonal /-\n/-- The antidiagonal of `n` does not contain duplicate entries. -/\n@[simp]\ntheorem nodup_antidiagonal (n : ℕ) : Nodup (antidiagonal n) :=\n  coe_nodup.2 <| List.Nat.nodup_antidiagonal n\n#align multiset.nat.nodup_antidiagonal Multiset.Nat.nodup_antidiagonal\n-/\n\n#print Multiset.Nat.antidiagonal_succ /-\n@[simp]\ntheorem antidiagonal_succ {n : ℕ} :\n    antidiagonal (n + 1) = (0, n + 1) ::ₘ (antidiagonal n).map (Prod.map Nat.succ id) := by\n  simp only [antidiagonal, List.Nat.antidiagonal_succ, coe_map, cons_coe]\n#align multiset.nat.antidiagonal_succ Multiset.Nat.antidiagonal_succ\n-/\n\n#print Multiset.Nat.antidiagonal_succ' /-\ntheorem antidiagonal_succ' {n : ℕ} :\n    antidiagonal (n + 1) = (n + 1, 0) ::ₘ (antidiagonal n).map (Prod.map id Nat.succ) := by\n  rw [antidiagonal, List.Nat.antidiagonal_succ', ← coe_add, add_comm, antidiagonal, coe_map,\n    coe_add, List.singleton_append, cons_coe]\n#align multiset.nat.antidiagonal_succ' Multiset.Nat.antidiagonal_succ'\n-/\n\n#print Multiset.Nat.antidiagonal_succ_succ' /-\ntheorem antidiagonal_succ_succ' {n : ℕ} :\n    antidiagonal (n + 2) =\n      (0, n + 2) ::ₘ (n + 2, 0) ::ₘ (antidiagonal n).map (Prod.map Nat.succ Nat.succ) :=\n  by\n  rw [antidiagonal_succ, antidiagonal_succ', map_cons, map_map, Prod_map]\n  rfl\n#align multiset.nat.antidiagonal_succ_succ' Multiset.Nat.antidiagonal_succ_succ'\n-/\n\n#print Multiset.Nat.map_swap_antidiagonal /-\ntheorem map_swap_antidiagonal {n : ℕ} : (antidiagonal n).map Prod.swap = antidiagonal n := by\n  rw [antidiagonal, coe_map, List.Nat.map_swap_antidiagonal, coe_reverse]\n#align multiset.nat.map_swap_antidiagonal Multiset.Nat.map_swap_antidiagonal\n-/\n\nend Nat\n\nend 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/Multiset/NatAntidiagonal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7507494171626411}}
{"text": "import ..library.src_field\nimport 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) := ∀ x : R, (x + u = x) ∧ (u + x = x)\n\nexample : add_identity (0 : R) :=\nbegin\n  intro x,\n  exact and.intro (add_zero x) (zero_add x),\nend\n\nlemma has_add_inverse : ∀ a : R, ∃ b : R, (a + b = 0) ∧ (b + a = 0) :=\nbegin\n  intro a,\n  use (-a),\n  exact and.intro (add_neg a) (neg_add a)\nend\n\ntheorem add_identity_unique {a b : R} (h₁ : add_identity a) (h₂ : add_identity b)\n  : a = b :=\nbegin\n  specialize h₁ b, -- `h₁ : (b + a = b) ∧ (a + b = b)`\n  specialize h₂ a, -- `h₂ : (a + b = a) ∧ (b + a = a)`\n  calc  a = a + b : h₂.left.symm -- If `h : x = y`, then `h.symm : y = x`.\n      ... = b     : h₁.right\nend\n\ndef add_inverse (y x : R) := (x + y = 0) ∧ (y + x = 0)\n\ntheorem add_inverse_unique {a b x : R} (h₁ : add_inverse a x) (h₂ : add_inverse b x)\n  : a = b :=\ncalc  a = a + 0        : (add_zero a).symm\n    ... = a + (x + b)  : by rw h₂.left\n    ... = (a + x) + b  : by rw add_assoc\n    ... = 0 + b        : by rw h₁.right\n    ... = b            : zero_add b\n\n\n-- Exercise 146:\nlemma add_left_eq_self_mp {x a : R} : x + a = a → x = 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 147:\nlemma add_left_eq_self_mpr {x a : R} : x = 0 → x + a = a :=\nbegin\n  sorry  \nend\n\n-- Exercise 148:\n-- You can prove the following in one line using the above two results.\ntheorem add_left_eq_self (x a : R) : x + a = a ↔ x = 0:=\nsorry \n\n-- Exercise 149:\ntheorem add_left_inj (x a b : R) : a + x = b + x ↔ a = b :=\nbegin\n  sorry    \nend\n\nlemma sub_eq_add_neg (x y : R) : x - y = x + (-y) := rfl \n\n-- Exercise 150:\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 151:\nlemma sub_zero (a : R) : a - 0 = a :=\nsorry  \n\n-- Exercise 152:\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 ↔ x = y :=\nsorry \n\n-- Exercise 153:\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 154:\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\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 ≠ 0 → x * x⁻¹  = 1 := myfield.mul_inv x\nlemma inv_mul (x : R) : x ≠ 0 → x⁻¹ * 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) ≠ (1 : R) := myfield.zero_ne_one\n\ndef mul_identity (u : R) := ∀ x : R, (x * u = x) ∧ (u * x = x)\n\n-- Exercise 155:\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 156:\ntheorem mul_identity_unique {a b : R} (h₁ : mul_identity a) (h₂ : mul_identity b) \n  : a = b :=\nbegin\n  sorry  \nend\n\ndef mul_inverse (y x : R) := (x * y = 1) ∧ (y * x = 1)\n\n-- Exercise 157:\ntheorem mul_inverse_unique {a b x : R} (h₁ : mul_inverse a x) (h₂ : mul_inverse b x)\n  : a = b :=\nsorry \n\n-- Exercise 158:\n-- This exercise is somewhat challenging.\ntheorem mul_zero {x : R} : x * (0 : R) = (0 : R) :=\nbegin\n  have h₁ : 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 159:\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 160:\ntheorem neg_one_mul (x : R) : (-1) * x = -x :=\nbegin\n  sorry  \nend\n\n-- Exercise 161:\n-- Use the result above to prove this lemma.\nlemma neg_one_mul_neg_one : (-(1 : R)) * (-1) = 1 :=\nsorry \n\n-- Exercise 162:\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 [←neg_one_mul, mul_assoc, mul_comm x _, ←mul_assoc, ←mul_assoc, neg_one_mul_neg_one, one_mul]\n\n-- Exercise 163:\nlemma neg_mul_neg (x y : R) : (-x) * (-y) = x * y :=\nbegin\n  sorry  \nend\n\n-- Exercise 164:\nlemma one_inv : (1 : R)⁻¹ = (1 : R) :=\nsorry \n-- Exercise 165:\ntheorem mul_sub (x y z : R) : x * (y - z) = x * y - x * z :=\nbegin\n  sorry  \nend\n\n-- Exercise 166:\ntheorem mul_left_inj' (x a b : R) (h₁ : x ≠ 0): a * x = b * x ↔ a = b :=\nbegin\n  sorry    \nend\n\nopen_locale classical\n\n-- Exercise 167:\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₁ : b ≠ 0) (h₂ : x * b = 0) : x = 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 168:\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 ∨ y = 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 169:\nlemma mul_inv' (x y : R) (h₁ : x ≠ 0) (h₂ : y ≠ 0) : (x * y)⁻¹ = y⁻¹ * x⁻¹ :=\nbegin\n  have h : x * y ≠ 0,\n  { sorry, }, \n  rw ←(mul_left_inj' _ _ _ h₁),\n  sorry  \nend\n\n-- Exercise 170:\ntheorem inv_ne_zero {a : R} : a ≠ 0 → a⁻¹ ≠ 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 171:\ntheorem inv_inv' (a : R) (h : a ≠ 0 ) : (a⁻¹)⁻¹ = a :=\nbegin\n  sorry  end\n\nend fieldlaws\n\nsection powers\n\nvariables {R : Type} [myfield R]\n\ndef pow1 : R → ℕ → R\n| x 0            := (1 : R)\n| x (nat.succ n) := (pow1 x n) * x  -- `nat.succ` is the Lean version of our function `S`\n\n-- Exercise 172:\nexample (x : R) : pow1 x 2 = x * x :=\nbegin\n  sorry  end\n\n-- Exercise 173:\n-- Prove the following by induction on `n`.\ntheorem pow_ne_zero (x : R) (n : ℕ) (h : x ≠ 0) : pow1 x n ≠ 0 :=\nbegin\n  sorry  \nend\n\n-- Exercise 174:\n-- Use induction. Make use of `nat.add_zero`.\ntheorem pow1_add (x : R) (m n : ℕ) : pow1 x (m + n) = (pow1 x m) * (pow1 x n) :=\nbegin\n  sorry  \nend\n\n-- Exercise 175:\n-- Use induction. Make use of `nat.mul_zero`, `nat.succ_eq_add_one`, and `nat.mul_one`.begin\n-- You'll need `left_distrib`, a synonym of `mul_add` for `ℕ`.\ntheorem pow1_mul (x : R) (m n : ℕ) : pow1 x (m*n) = pow1 (pow1 x m) n :=\nbegin\n  sorry  \nend\n\nlemma sub_succ_eq_pred_sub_of_le (b k : ℕ) : nat.succ k ≤ b → (b-(nat.succ k)) = (b - 1) - k :=\nbegin\n  induction k with m hm,\n  { rw nat.sub_zero, intro h, refl, },\n  { intro h,\n    exact (nat.pred_sub b (nat.succ m)).symm, },\nend\n\n-- Exercise 176:\n-- The exercise below is very hard. Use the result above together with any other appropriate\n-- results concerning the natural numbers from mathlib.\ntheorem pow1_sub (x : R) (h₁ : x ≠ 0) (n : ℕ) :\n  ∀ m : ℕ, n ≤ m → pow1 x (m - n) = (pow1 x m) * (pow1 x n)⁻¹ :=\nbegin\n  sorry  \nend\n\ndef pow2 (x : R) (m : ℤ) := ite (m ≥ 0) (pow1 x (int.to_nat m)) (pow1 x (int.to_nat (-m)))\n\nend powers\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_35_algebraic_axioms.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7507494008693709}}
{"text": "def divisor (n m : Nat) : Prop := ∃ c, n = m*c\ndef even (n : Nat) : Prop := ∃ d, n=2*d\n\ninfixl:40 \" | \" => divisor\n\nexample : (a | b*c) → a | b ∧ a | c := by\nintro h\napply Exists.elim h\nintro x hx\napply And.intro <;> rw [Nat.mul_assoc] at hx\nexact Exists.intro (c*x) hx\nrw [Nat.mul_left_comm] at hx\nexact Exists.intro (b*x) hx\n\ndef rel_prime (n m : Nat) : Prop := (¬ n = 1 ∧ ¬ m = 1) ∧ ∀ c, (n | c) ∧ (m | c) → c = 1\n\nexample (a b : Nat) : even a → rel_prime a b → ¬ even b := by\nintro h1 h2 h3\napply Exists.elim h1\nintro x hx\napply Exists.elim h3\nintro y hy\nhave ab_even : a | 2 ∧ b | 2 := And.intro (Exists.intro x hx) (Exists.intro y hy)\nhave : 2 = 1 := (h2.right 2) ab_even\ncontradiction\n\ntheorem rel_prime_not_eq (n m : Nat) : rel_prime n m → ¬ n = m := by\nintro h1 h2\nhave h4 : n | m ∧ m | m → m = 1 := h1.right m\napply h1.left.right\napply h4\napply And.intro\nrw [h2]\napply Exists.intro 1\nexact Eq.symm (Nat.mul_one m)\napply Exists.intro 1\nexact Eq.symm (Nat.mul_one m)", "meta": {"author": "Euctemon", "repo": "proofs-in-lean", "sha": "2a6d10e17ae1c15e814ad9ab24a76e937f95586a", "save_path": "github-repos/lean/Euctemon-proofs-in-lean", "path": "github-repos/lean/Euctemon-proofs-in-lean/proofs-in-lean-2a6d10e17ae1c15e814ad9ab24a76e937f95586a/divisors.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813476288299, "lm_q2_score": 0.7853085909370423, "lm_q1q2_score": 0.7507403650684912}}
{"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.asymptotic_equivalent\nimport analysis.asymptotics.specific_asymptotics\nimport data.polynomial.erase_lead\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 +∞.\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\nopen filter finset asymptotics\nopen_locale asymptotics topological_space\n\nnamespace polynomial\n\nvariables {𝕜 : Type*} [normed_linear_ordered_field 𝕜] (P Q : polynomial 𝕜)\n\nlemma eventually_no_roots (hP : P ≠ 0) : ∀ᶠ x in filter.at_top, ¬ P.is_root x :=\nbegin\n  obtain ⟨x₀, hx₀⟩ := polynomial.exists_max_root P hP,\n  refine filter.eventually_at_top.mpr (⟨x₀ + 1, λ x hx h, _⟩),\n  exact absurd (hx₀ x h) (not_le.mpr (lt_of_lt_of_le (lt_add_one x₀) hx)),\nend\n\nvariables [order_topology 𝕜]\n\nlemma is_equivalent_at_top_lead :\n  (λ x, eval x P) ~[at_top] (λ x, P.leading_coeff * x ^ P.nat_degree) :=\nbegin\n  by_cases h : P = 0,\n  { simp [h] },\n  { conv_lhs\n    { funext,\n      rw [polynomial.eval_eq_finset_sum, sum_range_succ] },\n    exact is_equivalent.refl.add_is_o (is_o.sum $ λ i hi, is_o.const_mul_left\n      (is_o.const_mul_right (λ hz, h $ leading_coeff_eq_zero.mp hz) $\n        is_o_pow_pow_at_top_of_lt (mem_range.mp hi)) _) }\nend\n\nlemma tendsto_at_top_of_leading_coeff_nonneg (hdeg : 1 ≤ P.degree) (hnng : 0 ≤ P.leading_coeff) :\n  tendsto (λ x, eval x P) at_top at_top :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_top\n  (tendsto_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)\n    (lt_of_le_of_ne hnng $ ne.symm $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))\n\nlemma tendsto_at_bot_of_leading_coeff_nonpos (hdeg : 1 ≤ P.degree) (hnps : P.leading_coeff ≤ 0) :\n  tendsto (λ x, eval x P) at_top at_bot :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_bot\n  (tendsto_neg_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)\n    (lt_of_le_of_ne hnps $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))\n\nlemma abs_tendsto_at_top (hdeg : 1 ≤ P.degree) :\n  tendsto (λ x, abs $ eval x P) at_top at_top :=\nbegin\n  by_cases hP : 0 ≤ P.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.tendsto_at_top_of_leading_coeff_nonneg hdeg hP)},\n  { push_neg at hP,\n    exact tendsto_abs_at_bot_at_top.comp (P.tendsto_at_bot_of_leading_coeff_nonpos hdeg hP.le)}\nend\n\nlemma is_equivalent_at_top_div :\n  (λ x, (eval x P)/(eval x Q)) ~[at_top]\n    λ x, P.leading_coeff/Q.leading_coeff * x^(P.nat_degree - Q.nat_degree : ℤ) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP] },\n  by_cases hQ : Q = 0,\n  { simp [hQ] },\n  refine (P.is_equivalent_at_top_lead.symm.div\n          Q.is_equivalent_at_top_lead.symm).symm.trans\n         (eventually_eq.is_equivalent ((eventually_gt_at_top 0).mono $ λ x hx, _)),\n  simp [← div_mul_div, hP, hQ, fpow_sub hx.ne.symm]\nend\n\nlemma div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP, tendsto_const_nhds] },\n  rw ←  nat_degree_lt_nat_degree_iff hP at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw ← mul_zero,\n  refine (tendsto_fpow_at_top_zero _).const_mul _,\n  linarith\nend\n\nlemma div_tendsto_leading_coeff_div_of_degree_eq (hdeg : P.degree = Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 $ P.leading_coeff / Q.leading_coeff) :=\nbegin\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw show (P.nat_degree : ℤ) = Q.nat_degree, by simp [hdeg, nat_degree],\n  simp [tendsto_const_nhds]\nend\n\nlemma div_tendsto_at_top_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hpos : 0 < P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hpos, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_top _,\n  apply tendsto.const_mul_at_top hpos,\n  apply tendsto_fpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnng : 0 ≤ P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nhave ratio_pos : 0 < P.leading_coeff/Q.leading_coeff,\n  from lt_of_le_of_ne hnng\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)).symm,\ndiv_tendsto_at_top_of_degree_gt' P Q hdeg ratio_pos\n\nlemma div_tendsto_at_bot_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hneg : P.leading_coeff/Q.leading_coeff < 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hneg, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_bot _,\n  apply tendsto.neg_const_mul_at_top hneg,\n  apply tendsto_fpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_bot_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnps : P.leading_coeff/Q.leading_coeff ≤ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nhave ratio_neg : P.leading_coeff/Q.leading_coeff < 0,\n  from lt_of_le_of_ne hnps\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)),\ndiv_tendsto_at_bot_of_degree_gt' P Q hdeg ratio_neg\n\nlemma eval_div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) :\n  tendsto (λ x, abs ((eval x P)/(eval x Q))) at_top at_top :=\nbegin\n  by_cases h : 0 ≤ P.leading_coeff/Q.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.div_tendsto_at_top_of_degree_gt Q hdeg hQ h) },\n  { 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) }\nend\n\ntheorem is_O_of_degree_le (h : P.degree ≤ Q.degree) :\n  is_O (λ x, eval x P) (λ x, eval x Q) filter.at_top :=\nbegin\n  by_cases hp : P = 0,\n  { simpa [hp] using is_O_zero (λ x, eval x Q) filter.at_top },\n  { have hq : Q ≠ 0 := ne_zero_of_degree_ge_degree h hp,\n    have hPQ : ∀ᶠ (x : 𝕜) in at_top, eval x Q = 0 → eval x P = 0 :=\n      filter.mem_sets_of_superset (polynomial.eventually_no_roots Q hq) (λ x h h', absurd h' h),\n    cases le_iff_lt_or_eq.mp h with h h,\n    { exact is_O_of_div_tendsto_nhds hPQ 0 (div_tendsto_zero_of_degree_lt P Q h) },\n    { exact is_O_of_div_tendsto_nhds hPQ _ (div_tendsto_leading_coeff_div_of_degree_eq P Q h) } }\nend\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/analysis/special_functions/polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7507146511410479}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Demostrar que si c es no negativo y f es monótona,\n-- entonces c * f es monótona.\n-- ----------------------------------------------------------------------\n\nimport data.real.basic\n\nvariables (f : ℝ → ℝ)\nvariable  {c : ℝ}\n\n-- 1ª demostración\n-- ===============\n\nexample\n  (mf : monotone f)\n  (nnc : 0 ≤ c)\n  : monotone (λ x, c * f x) :=\nbegin\n  have h1 : ∀ a b, a ≤ b → (λ x, c * f x) a ≤ (λ x, c * f x) b,\n    { intros a b hab,\n      have h2 : f a ≤ f b := mf hab,\n      have h3 : c * f a ≤ c * f b := mul_le_mul_of_nonneg_left h2 nnc,\n      show (λ x, c * f x) a ≤ (λ x, c * f x) b,\n        by exact h3, },\n  show monotone (λ x, c * f x),\n    by exact h1,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample\n  (mf : monotone f)\n  (nnc : 0 ≤ c)\n  : monotone (λ x, c * f x) :=\nbegin\n  intros a b hab,\n  apply mul_le_mul_of_nonneg_left,\n  apply mf hab,\n  apply nnc\nend\n\n-- Su desarrollo es\n--\n-- f : ℝ → ℝ,\n-- c : ℝ,\n-- mf : monotone f,\n-- nnc : 0 ≤ c\n-- ⊢ monotone (λ (x : ℝ), c * f x)\n--    >> intros a b hab,\n-- a b : ℝ,\n-- hab : a ≤ b\n-- ⊢ (λ (x : ℝ), c * f x) a ≤ (λ (x : ℝ), c * f x) b\n--    >> apply mul_le_mul_of_nonneg_left,\n-- | ⊢ f a ≤ f b\n-- |    >> apply mf hab,\n-- | ⊢ 0 ≤ c\n-- |    >> apply nnc\n-- no goals\n\n-- 3ª demostración\n-- ===============\n\nexample (mf : monotone f) (nnc : 0 ≤ c) :\n  monotone (λ x, c * f x) :=\nλ a b hab, mul_le_mul_of_nonneg_left (mf hab) nnc\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_de_un_positivo_por_una_funcion_monotona.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467675095292, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7507146315900303}}
{"text": "\nnamespace Ex\n\n\n-- 7.2 Define some operations on lists like `length` and `reverse`.\n\ninductive List (α : Type u) where\n  | nil : List α\n  | cons (head : α) (tail : List α) : List α\n\n\nopen Ex.List\n\ndef list123 := cons 1 (cons 2 (cons 3 nil))\ndef list456 := cons 3 (cons 5 (cons 6 nil))\ndef list654 := cons 6 (cons 5 (cons 4 nil))\ndef list123456 := cons 1 (cons 2 (cons 3 (cons 4 (cons 5 (cons 6 nil)))))\n\n\ndef length (s : List α) : Nat :=\n  match s with\n  | nil       => 0\n  | cons _ s' => 1 + length s'\n\nexample : length (nil : List α) = 0 := rfl\n\nexample : length list123 = 3 := rfl\n\n\ndef append (s t : List α) : List α :=\n  match s with\n  | nil       => t  \n  | cons x s' => cons x (append s' t)\n\n--example : append list123 list456 = list123456 := by\n--  simp [cons_append]\n\n\ndef reverse (s : List α) : List α :=\n  match s with\n  | nil       => nil\n  | cons x s' => append (reverse s') (cons x nil)\n\n\n-- 7.2.a. `length (s ++ t) = length s + length t`\n\ntheorem length_nil : length (nil : List α) = 0 := rfl\n\ntheorem length_cons (s : List α) : length (cons x s) = 1 + length s := rfl\n\ntheorem cons_append (s t : List α) : append (cons x s) t = cons x (append s t) := rfl\n\ntheorem nil_append (s : List α) : append nil s = s := rfl\n\ntheorem append_nil (s : List α) : append s nil = s := by\n  induction s with\n  | nil          => rfl\n  | cons x s' ih => rw [cons_append, ih]\n\ntheorem length_append (s t : List α) : length (append s t) = length s + length t := by\n  induction s with\n  | nil          => rw [nil_append, length_nil, Nat.zero_add]\n  | cons x s' ih => rw [cons_append, length_cons, length_cons, Nat.add_assoc, ih]\n\n\n-- 7.2.b. `length (reverse t) = length t`\n\ntheorem reverse_cons (x : α) (s : List α) : reverse (cons x s) = append (reverse s) (cons x nil) := by\n  induction s with\n  | nil           => rfl\n  | cons x' s' ih => rfl\n\ntheorem length_reverse (s : List α) : length (reverse s) = length s := by\n  induction s with\n  | nil          => rfl\n  | cons x s' ih => rw [length_cons, reverse_cons, length_append, ih, length_cons, length_nil, Nat.add_zero, Nat.add_comm]\n\n\n-- 7.2.c. `reverse (reverse t) = t`\n\ntheorem reverse_nil : reverse (nil : List α) = (nil : List α) := rfl\n\ntheorem append_assoc (s t u : List α) : append s (append t u) = append (append s t) u := by\n  induction s with \n  | nil          => rw [nil_append, nil_append]\n  | cons x s' ih => rw [cons_append, ih, cons_append, cons_append]\n\ntheorem reverse_append (s t : List α) : reverse (append s t) = append (reverse t) (reverse s) := by\n  induction s with\n  | nil          => rw [nil_append, reverse_nil, append_nil]\n  | cons x s' ih => rw [cons_append, reverse_cons, ih, reverse_cons, append_assoc]\n\ntheorem reverse_reverse (s : List α) : reverse (reverse s) = s := by\n  induction s with\n  | nil          => rfl\n  | cons x s' ih => rw [reverse_cons, reverse_append, ih, reverse_cons, reverse_nil, nil_append, cons_append, nil_append]\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-7/Exercises-7-2.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127380808499, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.7507146153074279}}
{"text": "/-\nCopyright (c) 2022 Rishikesh Vaishnav. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rishikesh Vaishnav\n-/\nimport probability.independence\n\n/-!\n# Conditional Probability\n\nThis file defines conditional probability and includes basic results relating to it.\n\nGiven some measure `μ` defined on a measure space on some type `α` and some `s : set α`,\nwe define the measure of `μ` conditioned on `s` as the restricted measure scaled by\nthe inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling\nensures that this is a probability measure (when `μ` is a finite measure).\n\nFrom this definition, we derive the \"axiomatic\" definition of conditional probability\nbased on application: for any `s t : set α`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`.\n\n## Main Statements\n\n* `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent\n  to conditioning on their intersection.\n* `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`.\n\n## Notations\n\nThis file uses the notation `μ[|s]` the measure of `μ` conditioned on `s`,\nand `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the\napplication `μ[|s] t`).\n\nThese notations are contained in the locale `probability_theory`.\n\n## Implementation notes\n\nBecause we have the alternative measure restriction application principles\n`measure.restrict_apply` and `measure.restrict_apply'`, which require\nmeasurability of the restricted and restricting sets, respectively,\nmany of the theorems here will have corresponding alternatives as well.\nFor the sake of brevity, we've chosen to only go with `measure.restrict_apply'`\nfor now, but the alternative theorems can be added if needed.\n\nUse of `@[simp]` generally follows the rule of removing conditions on a measure\nwhen possible.\n\nHypotheses that are used to \"define\" a conditional distribution by requiring that\nthe conditioning set has non-zero measure should be named using the abbreviation\n\"c\" (which stands for \"conditionable\") rather than \"nz\". For example `(hci : μ (s ∩ t) ≠ 0)`\n(rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined.\n\n## Tags\nconditional, conditioned, bayes\n-/\n\nnoncomputable theory\n\nopen_locale ennreal\n\nopen measure_theory measurable_space\n\nvariables {α : Type*} {m : measurable_space α} (μ : measure α) {s t : set α}\n\nnamespace probability_theory\n\nsection definitions\n\n/-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s`\nand scaled by the inverse of `μ s` (to make it a probability measure):\n`(μ s)⁻¹ • μ.restrict s`. -/\ndef cond (s : set α) : measure α :=\n  (μ s)⁻¹ • μ.restrict s\n\nend definitions\n\nlocalized \"notation  μ `[` s `|` t `]` := probability_theory.cond μ t s\" in probability_theory\nlocalized \"notation  μ `[|`:60 t`]` := probability_theory.cond μ t\" in probability_theory\n\n/-- The conditional probability measure of any finite measure on any set of positive measure\nis a probability measure. -/\nlemma cond_is_probability_measure [is_finite_measure μ] (hcs : μ s ≠ 0) :\n  is_probability_measure $ μ[|s] :=\n⟨by { rw [cond, measure.smul_apply, measure.restrict_apply measurable_set.univ,\n  set.univ_inter], exact ennreal.inv_mul_cancel hcs (measure_ne_top _ s) }⟩\n\nsection bayes\n\n@[simp] lemma cond_empty : μ[|∅] = 0 :=\nby simp [cond]\n\n@[simp] lemma cond_univ [is_probability_measure μ] :\n  μ[|set.univ] = μ :=\nby simp [cond, measure_univ, measure.restrict_univ]\n\n/-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/\nlemma cond_apply (hms : measurable_set s) (t : set α) :\n  μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) :=\nby { rw [cond, measure.smul_apply, measure.restrict_apply' hms, set.inter_comm], refl }\n\nlemma cond_inter_self (hms : measurable_set s) (t : set α) :\n  μ[s ∩ t|s] = μ[t|s] :=\nby rw [cond_apply _ hms, ← set.inter_assoc, set.inter_self, ← cond_apply _ hms]\n\nlemma inter_pos_of_cond_ne_zero (hms : measurable_set s) (hcst : μ[t|s] ≠ 0) :\n  0 < μ (s ∩ t) :=\nbegin\n  refine pos_iff_ne_zero.mpr (right_ne_zero_of_mul _),\n  { exact (μ s)⁻¹ },\n  convert hcst,\n  simp [hms, set.inter_comm]\nend\n\nlemma cond_pos_of_inter_ne_zero [is_finite_measure μ]\n  (hms : measurable_set s) (hci : μ (s ∩ t) ≠ 0) :\n  0 < μ[|s] t :=\nbegin\n  rw cond_apply _ hms,\n  refine ennreal.mul_pos _ hci,\n  exact ennreal.inv_ne_zero.mpr (measure_ne_top _ _),\nend\n\nlemma cond_cond_eq_cond_inter'\n  (hms : measurable_set s) (hmt : measurable_set t) (hcs : μ s ≠ ∞) (hci : μ (s ∩ t) ≠ 0) :\n  μ[|s][|t] = μ[|s ∩ t] :=\nbegin\n  have hcs : μ s ≠ 0 := (μ.to_outer_measure.pos_of_subset_ne_zero\n    (set.inter_subset_left _ _) hci).ne',\n  ext u,\n  simp [*, hms.inter hmt, cond_apply, ← mul_assoc, ← set.inter_assoc,\n    ennreal.mul_inv, mul_comm, ← mul_assoc, ennreal.inv_mul_cancel],\nend\n\n/-- Conditioning first on `s` and then on `t` results in the same measure as conditioning\non `s ∩ t`. -/\nlemma cond_cond_eq_cond_inter [is_finite_measure μ]\n  (hms : measurable_set s) (hmt : measurable_set t) (hci : μ (s ∩ t) ≠ 0) :\n  μ[|s][|t] = μ[|s ∩ t] :=\ncond_cond_eq_cond_inter' μ hms hmt (measure_ne_top μ s) hci\n\nlemma cond_mul_eq_inter'\n  (hms : measurable_set s) (hcs : μ s ≠ 0) (hcs' : μ s ≠ ∞) (t : set α) :\n  μ[t|s] * μ s = μ (s ∩ t) :=\nby rw [cond_apply μ hms t, mul_comm, ←mul_assoc,\n  ennreal.mul_inv_cancel hcs hcs', one_mul]\n\nlemma cond_mul_eq_inter [is_finite_measure μ]\n  (hms : measurable_set s) (hcs : μ s ≠ 0) (t : set α) :\n  μ[t|s] * μ s = μ (s ∩ t) :=\ncond_mul_eq_inter' μ hms hcs (measure_ne_top _ s) t\n\n/-- A version of the law of total probability. -/\nlemma cond_add_cond_compl_eq [is_finite_measure μ]\n  (hms : measurable_set s) (hcs : μ s ≠ 0) (hcs' : μ sᶜ ≠ 0) :\n  μ[t|s] * μ s + μ[t|sᶜ] * μ sᶜ = μ t :=\nbegin\n  rw [cond_mul_eq_inter μ hms hcs, cond_mul_eq_inter μ hms.compl hcs', set.inter_comm _ t,\n    set.inter_comm _ t],\n  exact measure_inter_add_diff t hms,\nend\n\n/-- **Bayes' Theorem** -/\ntheorem cond_eq_inv_mul_cond_mul [is_finite_measure μ]\n  (hms : measurable_set s) (hmt : measurable_set t) :\n  μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t) :=\nbegin\n  by_cases ht : μ t = 0,\n  { simp [cond, ht, measure.restrict_apply hmt, or.inr (measure_inter_null_of_null_left s ht)] },\n  { rw [mul_assoc, cond_mul_eq_inter μ hmt ht s, set.inter_comm, cond_apply _ hms] }\nend\n\nend bayes\n\nend probability_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/probability/conditional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7506576540353903}}
{"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 6 : \"or\" (∨`)\n\nWe learn about how to manipulate `P ∨ 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-/\n\n-- Throughout this sheet, `P`, `Q`, `R` and `S` will denote propositions.\n\nvariables (P Q R S : Prop)\n\nexample : P → P ∨ Q :=\nbegin\n  intro hP,\n  left,\n  exact hP,\nend\n\nexample : Q → P ∨ Q :=\nbegin\n  intro hQ,\n  right,\n  exact hQ,\nend\n\nexample : P ∨ Q → (P → R) → (Q → R) → R :=\nbegin\n  intros hPQ hPR hQR,\n  cases hPQ with hP hQ,\n  exact hPR hP,\n  exact hQR hQ,\nend\n\n-- symmetry of `or`\nexample : P ∨ Q → Q ∨ P :=\nbegin\n  sorry\nend\n\n-- associativity of `or`\nexample : (P ∨ Q) ∨ R ↔ P ∨ (Q ∨ R) :=\nbegin\n  sorry,\nend\n\nexample : (P → R) → (Q → S) → P ∨ Q → R ∨ S :=\nbegin\n  sorry,\nend\n\nexample : (P → Q) → P ∨ R → Q ∨ R :=\nbegin\n  sorry,\nend\n\nexample : (P ↔ R) → (Q ↔ S) → (P ∨ Q ↔ R ∨ S) :=\nbegin\n  sorry,\nend\n\n-- de Morgan's laws\nexample : ¬ (P ∨ Q) ↔ ¬ P ∧ ¬ Q :=\nbegin\n  sorry\nend\n\nexample : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=\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/section01logic/sheet6.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951680216529, "lm_q2_score": 0.8031737940012418, "lm_q1q2_score": 0.7504817121963787}}
{"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ébastien Gouëzel, Yury Kudryashov\n-/\nimport analysis.asymptotics.asymptotic_equivalent\nimport analysis.calculus.tangent_cone\nimport analysis.normed_space.bounded_linear_maps\nimport analysis.normed_space.units\n\n/-!\n# The Fréchet derivative\n\nLet `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a\ncontinuous 𝕜-linear map, where `𝕜` 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 → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,\ni.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → 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 : 𝕜 → E` as an element of `E` (by identifying\na linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet 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 : ℝ) : differentiable ℝ (λ 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 : ℝ) (h : 1 + sin x ≠ 0) : differentiable_at ℝ (λ 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échet 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 𝕜 f s x` (where `𝕜` 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 𝕜 f x`,\n`differentiable_on 𝕜 f s` and `differentiable 𝕜 f` to express the existence of a derivative.\n\nTo be able to compute with derivatives, we write `fderiv_within 𝕜 f s x` and `fderiv 𝕜 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 `(λ 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échet, calculus\n\n-/\n\nopen filter asymptotics continuous_linear_map set metric\nopen_locale topology classical nnreal filter asymptotics ennreal\n\nnoncomputable theory\n\n\nsection\n\nvariables {𝕜 : Type*} [nontrivially_normed_field 𝕜]\nvariables {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]\nvariables {F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]\nvariables {G : Type*} [normed_add_comm_group G] [normed_space 𝕜 G]\nvariables {G' : Type*} [normed_add_comm_group G'] [normed_space 𝕜 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 = 𝓝 x` (in `has_fderiv_at`), giving rise to the usual notion\nof Fréchet derivative, and for `L = 𝓝[s] x` (in `has_fderiv_within_at`), giving rise to\nthe notion of Fréchet derivative along the set `s`. -/\ndef has_fderiv_at_filter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : filter E) :=\n(λ x', f x' - f x - f' (x' - x)) =o[L] (λ x', x' - x)\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 → F) (f' : E →L[𝕜] F) (s : set E) (x : E) :=\nhas_fderiv_at_filter f f' x (𝓝[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 → F) (f' : E →L[𝕜] F) (x : E) :=\nhas_fderiv_at_filter f f' x (𝓝 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 → a`. This form of differentiability is required,\ne.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly\ndifferentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/\ndef has_strict_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) :=\n(λ p : E × E, f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] (λ p : E × E, p.1 - p.2)\n\nvariables (𝕜)\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 → F) (s : set E) (x : E) :=\n∃f' : E →L[𝕜] 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 → F) (x : E) :=\n∃f' : E →L[𝕜] F, has_fderiv_at f f' x\n\n/-- If `f` has a derivative at `x` within `s`, then `fderiv_within 𝕜 f s x` is such a derivative.\nOtherwise, it is set to `0`. -/\ndef fderiv_within (f : E → F) (s : set E) (x : E) : E →L[𝕜] F :=\nif h : ∃f', 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 𝕜 f x` is such a derivative. Otherwise, it is\nset to `0`. -/\ndef fderiv (f : E → F) (x : E) : E →L[𝕜] F :=\nif h : ∃f', has_fderiv_at f f' x then classical.some h else 0\n\n/-- `differentiable_on 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/\ndef differentiable_on (f : E → F) (s : set E) :=\n∀x ∈ s, differentiable_within_at 𝕜 f s x\n\n/-- `differentiable 𝕜 f` means that `f` is differentiable at any point. -/\ndef differentiable (f : E → F) :=\n∀x, differentiable_at 𝕜 f x\n\nvariables {𝕜}\nvariables {f f₀ f₁ g : E → F}\nvariables {f' f₀' f₁' g' : E →L[𝕜] F}\nvariables (e : E →L[𝕜] F)\nvariables {x : E}\nvariables {s t : set E}\nvariables {L L₁ L₂ : filter E}\n\nlemma fderiv_within_zero_of_not_differentiable_within_at\n  (h : ¬ differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = 0 :=\nhave ¬ ∃ 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 : ¬ differentiable_at 𝕜 f x) : fderiv 𝕜 f x = 0 :=\nhave ¬ ∃ 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) {α : Type*} (l : filter α)\n  {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)\n  (clim : tendsto (λ n, ‖c n‖) l at_top)\n  (cdlim : tendsto (λ n, c n • d n) l (𝓝 v)) :\n  tendsto (λn, c n • (f (x + d n) - f x)) l (𝓝 (f' v)) :=\nbegin\n  have tendsto_arg : tendsto (λ n, x + d n) l (𝓝[s] x),\n  { conv in (𝓝[s] x) { rw ← 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 : (λ y, f y - f x - f' (y - x)) =o[𝓝[s] x] (λ y, y - x) := h,\n  have : (λ n, f (x + d n) - f x - f' ((x + d n) - x)) =o[l] (λ n, (x + d n)  - x) :=\n    this.comp_tendsto tendsto_arg,\n  have : (λ n, f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel'],\n  have : (λ n, c n • (f (x + d n) - f x - f' (d n))) =o[l] (λ n, c n • d n) :=\n    (is_O_refl c l).smul_is_o this,\n  have : (λ n, c n • (f (x + d n) - f x - f' (d n))) =o[l] (λ n, (1:ℝ)) :=\n    this.trans_is_O (cdlim.is_O_one ℝ),\n  have L1 : tendsto (λn, c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=\n    (is_o_one_iff ℝ).1 this,\n  have L2 : tendsto (λn, f' (c n • d n)) l (𝓝 (f' v)) :=\n    tendsto.comp f'.cont.continuous_at cdlim,\n  have L3 : tendsto (λn, (c n • (f (x + d n) - f x - f' (d n)) +  f' (c n • d n)))\n            l (𝓝 (0 + f' v)) :=\n    L1.add L2,\n  have : (λn, (c n • (f (x + d n) - f x - f' (d n)) +  f' (c n • d n)))\n          = (λn, c n • (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₁'` 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₁' s x) :\n  eq_on f' f₁' (tangent_cone_at 𝕜 s x) :=\nλ y ⟨c, d, dtop, clim, cdlim⟩,\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 𝕜 s x)\n  (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : f' = f₁' :=\ncontinuous_linear_map.ext_on H.1 (hf.unique_on hg)\n\ntheorem unique_diff_on.eq (H : unique_diff_on 𝕜 s) (hx : x ∈ s)\n  (h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' :=\n(H x hx).eq h h₁\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 ↔\n  tendsto (λ x', ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) :=\nhave h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0, from λ x' hx',\n  by { rw [sub_eq_zero.1 (norm_eq_zero.1 hx')], simp },\nbegin\n  unfold has_fderiv_at_filter,\n  rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h],\n  exact tendsto_congr (λ _, div_eq_inv_mul _ _),\nend\n\ntheorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x ↔\n  tendsto (λ x', ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x ↔\n  tendsto (λ x', ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) :=\nhas_fderiv_at_filter_iff_tendsto\n\ntheorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x ↔\n  (λ h : E, f (x + h) - f x - f' h) =o[𝓝 0] (λh, h) :=\nbegin\n  rw [has_fderiv_at, has_fderiv_at_filter, ← map_add_left_nhds_zero x, is_o_map],\n  simp [(∘)]\nend\n\n/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz\non a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. This version\nonly assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/\nlemma has_fderiv_at.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀)\n  {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖f'‖ ≤ C :=\nbegin\n  refine le_of_forall_pos_le_add (λ ε ε0, op_norm_le_of_nhds_zero _ _),\n  exact add_nonneg hC₀ ε0.le,\n  rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip,\n  filter_upwards [is_o_iff.1 (has_fderiv_at_iff_is_o_nhds_zero.1 hf) ε0, hlip] with y hy hyC,\n  rw add_sub_cancel' at hyC,\n  calc ‖f' y‖ ≤ ‖f (x₀ + y) - f x₀‖ + ‖f (x₀ + y) - f x₀ - f' y‖ : norm_le_insert _ _\n          ... ≤ C * ‖y‖ + ε * ‖y‖                                : add_le_add hyC hy\n          ... = (C + ε) * ‖y‖                                    : (add_mul _ _ _).symm\nend\n\n/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz\non a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. -/\nlemma has_fderiv_at.le_of_lip {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀)\n  {s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ‖f'‖ ≤ C :=\nbegin\n  refine hf.le_of_lip' C.coe_nonneg _,\n  filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs),\nend\n\ntheorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :\n  has_fderiv_at_filter f f' x L₁ :=\nh.mono hst\n\ntheorem has_fderiv_within_at.mono_of_mem (h : has_fderiv_within_at f f' t x) (hst : t ∈ 𝓝[s] x) :\n  has_fderiv_within_at f f' s x :=\nh.mono $ nhds_within_le_iff.mpr hst\n\ntheorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s ⊆ 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 ≤ 𝓝 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 𝕜 f s x :=\n⟨f', h⟩\n\nlemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at 𝕜 f x :=\n⟨f', h⟩\n\n@[simp] lemma has_fderiv_within_at_univ :\n  has_fderiv_within_at f f' univ x ↔ has_fderiv_at f f' x :=\nby { simp only [has_fderiv_within_at, nhds_within_univ], refl }\n\nalias has_fderiv_within_at_univ ↔ has_fderiv_within_at.has_fderiv_at_of_univ _\n\nlemma has_fderiv_within_at_insert {y : E} {g' : E →L[𝕜] F}  :\n  has_fderiv_within_at g g' (insert y s) x ↔ has_fderiv_within_at g g' s x :=\nbegin\n  rcases eq_or_ne x y with rfl|h,\n  { simp_rw [has_fderiv_within_at, has_fderiv_at_filter],\n    apply asymptotics.is_o_insert,\n    simp only [sub_self, g'.map_zero] },\n  refine ⟨λ h, h.mono $ subset_insert y s, λ hg, hg.mono_of_mem _⟩,\n  simp_rw [nhds_within_insert_of_ne h, self_mem_nhds_within]\nend\n\nalias has_fderiv_within_at_insert ↔ has_fderiv_within_at.of_insert has_fderiv_within_at.insert'\n\nlemma has_fderiv_within_at.insert {g' : E →L[𝕜] F} (h : has_fderiv_within_at g g' s x) :\n  has_fderiv_within_at g g' (insert x s) x :=\nh.insert'\n\nlemma has_strict_fderiv_at.is_O_sub (hf : has_strict_fderiv_at f f' x) :\n  (λ p : E × E, f p.1 - f p.2) =O[𝓝 (x, x)] (λ p : E × E, p.1 - p.2) :=\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  (λ x', f x' - f x) =O[L] (λ x', x' - x) :=\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 (λ 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 𝕜 f x :=\nhf.has_fderiv_at.differentiable_at\n\n/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is\n`K`-Lipschitz in a neighborhood of `x`. -/\nlemma has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt (hf : has_strict_fderiv_at f f' x)\n  (K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, lipschitz_on_with K f s :=\nbegin\n  have := hf.add_is_O_with (f'.is_O_with_comp _ _) hK,\n  simp only [sub_add_cancel, is_O_with] at this,\n  rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩,\n  exact ⟨U, Uo.mem_nhds xU, lipschitz_on_with_iff_norm_sub_le.2 $\n    λ x hx y hy, hU (mk_mem_prod hx hy)⟩\nend\n\n/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a\nneighborhood of `x`. See also `has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt` for a\nmore precise statement. -/\nlemma has_strict_fderiv_at.exists_lipschitz_on_with (hf : has_strict_fderiv_at f f' x) :\n  ∃ K (s ∈ 𝓝 x), lipschitz_on_with K f s :=\n(exists_gt _).imp hf.exists_lipschitz_on_with_of_nnnorm_lt\n\n/-- Directional derivative agrees with `has_fderiv`. -/\nlemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {α : Type*} {c : α → 𝕜}\n  {l : filter α} (hc : tendsto (λ n, ‖c n‖) l at_top) :\n  tendsto (λ n, (c n) • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) :=\nbegin\n  refine (has_fderiv_within_at_univ.2 hf).lim _ univ_mem hc _,\n  assume U hU,\n  refine (eventually_ne_of_tendsto_norm_at_top hc (0:𝕜)).mono (λ y hy, _),\n  convert mem_of_mem_nhds hU,\n  dsimp only,\n  rw [← mul_smul, mul_inv_cancel hy, one_smul]\nend\n\ntheorem has_fderiv_at.unique\n  (h₀ : has_fderiv_at f f₀' x) (h₁ : has_fderiv_at f f₁' x) : f₀' = f₁' :=\nbegin\n  rw ← has_fderiv_within_at_univ at h₀ h₁,\n  exact unique_diff_within_at_univ.eq h₀ h₁\nend\n\nlemma has_fderiv_within_at_inter' (h : t ∈ 𝓝[s] x) :\n  has_fderiv_within_at f f' (s ∩ t) x ↔ 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 ∈ 𝓝 x) :\n  has_fderiv_within_at f f' (s ∩ t) x ↔ 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 ∪ t) x :=\nbegin\n  simp only [has_fderiv_within_at, nhds_within_union],\n  exact hs.sup ht,\nend\n\nlemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x)\n  (ht : s ∈ 𝓝[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 ∈ 𝓝 x) :\n  has_fderiv_at f f' x :=\nby rwa [← univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h\n\nlemma differentiable_within_at.differentiable_at\n  (h : differentiable_within_at 𝕜 f s x) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x :=\nh.imp (λ f' hf', hf'.has_fderiv_at hs)\n\nlemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at 𝕜 f s x) :\n  has_fderiv_within_at f (fderiv_within 𝕜 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 𝕜 f x) :\n  has_fderiv_at f (fderiv 𝕜 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 differentiable_on.has_fderiv_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :\n  has_fderiv_at f (fderiv 𝕜 f x) x :=\n((h x (mem_of_mem_nhds hs)).differentiable_at hs).has_fderiv_at\n\nlemma differentiable_on.differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :\n  differentiable_at 𝕜 f x :=\n(h.has_fderiv_at hs).differentiable_at\n\nlemma differentiable_on.eventually_differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) :\n  ∀ᶠ y in 𝓝 x, differentiable_at 𝕜 f y :=\n(eventually_eventually_nhds.2 hs).mono $ λ y, h.differentiable_at\n\nlemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv 𝕜 f x = f' :=\nby { ext, rw h.unique h.differentiable_at.has_fderiv_at }\n\nlemma fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, has_fderiv_at f (f' x) x) : fderiv 𝕜 f = f' :=\nfunext $ λ x, (h x).fderiv\n\n/-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz\non a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`.\nVersion using `fderiv`. -/\nlemma fderiv_at.le_of_lip {f : E → F} {x₀ : E} (hf : differentiable_at 𝕜 f x₀)\n  {s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ‖fderiv 𝕜 f x₀‖ ≤ 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 𝕜 s x) :\n  fderiv_within 𝕜 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 ∉ 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 𝕜 f t x) (st : s ⊆ t) :\n  differentiable_within_at 𝕜 f s x :=\nbegin\n  rcases h with ⟨f', hf'⟩,\n  exact ⟨f', hf'.mono st⟩\nend\n\nlemma differentiable_within_at.mono_of_mem (h : differentiable_within_at 𝕜 f s x) {t : set E}\n  (hst : s ∈ nhds_within x t) :\n  differentiable_within_at 𝕜 f t x :=\n(h.has_fderiv_within_at.mono_of_mem hst).differentiable_within_at\n\nlemma differentiable_within_at_univ :\n  differentiable_within_at 𝕜 f univ x ↔ differentiable_at 𝕜 f x :=\nby simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at]\n\nlemma differentiable_within_at_inter (ht : t ∈ 𝓝 x) :\n  differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 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 ∈ 𝓝[s] x) :\n  differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 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.antimono (h : differentiable_within_at 𝕜 f s x) (hst : s ⊆ t)\n  (hx : s ∈ 𝓝[t] x) :\n  differentiable_within_at 𝕜 f t x :=\nby rwa [← differentiable_within_at_inter' hx, inter_eq_self_of_subset_right hst]\n\nlemma has_fderiv_within_at.antimono (h : has_fderiv_within_at f f' s x) (hst : s ⊆ t)\n  (hs : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x) :\n  has_fderiv_within_at f f' t x :=\nbegin\n  have h' : has_fderiv_within_at f _ t x :=\n    (h.differentiable_within_at.antimono hst hx).has_fderiv_within_at,\n  rwa hs.eq h (h'.mono hst),\nend\n\nlemma differentiable_at.differentiable_within_at\n  (h : differentiable_at 𝕜 f x) : differentiable_within_at 𝕜 f s x :=\n(differentiable_within_at_univ.2 h).mono (subset_univ _)\n\nlemma differentiable.differentiable_at (h : differentiable 𝕜 f) :\n  differentiable_at 𝕜 f x :=\nh x\n\nlemma differentiable_at.fderiv_within\n  (h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=\nh.has_fderiv_at.has_fderiv_within_at.fderiv_within hxs\n\nlemma differentiable_on.mono (h : differentiable_on 𝕜 f t) (st : s ⊆ t) :\n  differentiable_on 𝕜 f s :=\nλ x hx, (h x (st hx)).mono st\n\nlemma differentiable_on_univ :\n  differentiable_on 𝕜 f univ ↔ differentiable 𝕜 f :=\nby simp only [differentiable_on, differentiable, differentiable_within_at_univ, mem_univ,\n  forall_true_left]\n\nlemma differentiable.differentiable_on (h : differentiable 𝕜 f) : differentiable_on 𝕜 f s :=\n(differentiable_on_univ.2 h).mono (subset_univ _)\n\nlemma differentiable_on_of_locally_differentiable_on\n  (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ differentiable_on 𝕜 f (s ∩ u)) : differentiable_on 𝕜 f s :=\nbegin\n  assume x xs,\n  rcases h x xs with ⟨t, t_open, xt, ht⟩,\n  exact (differentiable_within_at_inter (is_open.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩)\nend\n\nlemma fderiv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)\n  (h : differentiable_within_at 𝕜 f t x) :\n  fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x :=\n((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht\n\nlemma fderiv_within_subset' (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x)\n  (h : differentiable_within_at 𝕜 f s x) :\n  fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x :=\nfderiv_within_subset st ht (h.antimono st hx)\n\n@[simp] lemma fderiv_within_univ : fderiv_within 𝕜 f univ = fderiv 𝕜 f :=\nbegin\n  ext x : 1,\n  by_cases h : differentiable_at 𝕜 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 : ¬ differentiable_within_at 𝕜 f univ x,\n    { rwa 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 ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 f (s ∩ t) x = fderiv_within 𝕜 f s x :=\nbegin\n  by_cases h : differentiable_within_at 𝕜 f (s ∩ t) x,\n  { apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h),\n    apply hs.inter ht },\n  { have : ¬ differentiable_within_at 𝕜 f s x,\n    { rwa ←differentiable_within_at_inter ht },\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 ∈ 𝓝 x) :\n  fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=\nbegin\n  have : s = univ ∩ s, by simp only [univ_inter],\n  rw [this, ← 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 ∈ s) :\n  fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=\nfderiv_within_of_mem_nhds (is_open.mem_nhds hs hx)\n\nlemma fderiv_within_eq_fderiv (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_at 𝕜 f x) :\n  fderiv_within 𝕜 f s x = fderiv 𝕜 f x :=\nbegin\n  rw ← fderiv_within_univ,\n  exact fderiv_within_subset (subset_univ _) hs h.differentiable_within_at\nend\n\nlemma fderiv_mem_iff {f : E → F} {s : set (E →L[𝕜] F)} {x : E} :\n  fderiv 𝕜 f x ∈ s ↔ (differentiable_at 𝕜 f x ∧ fderiv 𝕜 f x ∈ s) ∨\n    (¬differentiable_at 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s) :=\nby by_cases hx : differentiable_at 𝕜 f x; simp [fderiv_zero_of_not_differentiable_at, *]\n\nlemma fderiv_within_mem_iff {f : E → F} {t : set E} {s : set (E →L[𝕜] F)} {x : E} :\n  fderiv_within 𝕜 f t x ∈ s ↔ (differentiable_within_at 𝕜 f t x ∧ fderiv_within 𝕜 f t x ∈ s) ∨\n    (¬differentiable_within_at 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s) :=\nby by_cases hx : differentiable_within_at 𝕜 f t x;\n  simp [fderiv_within_zero_of_not_differentiable_within_at, *]\n\nlemma asymptotics.is_O.has_fderiv_within_at {s : set E} {x₀ : E} {n : ℕ}\n  (h : f =O[𝓝[s] x₀] λ x, ‖x - x₀‖^n) (hx₀ : x₀ ∈ s) (hn : 1 < n) :\n  has_fderiv_within_at f (0 : E →L[𝕜] F) s x₀ :=\nby simp_rw [has_fderiv_within_at, has_fderiv_at_filter,\n  h.eq_zero_of_norm_pow_within hx₀ $ zero_lt_one.trans hn, zero_apply, sub_zero,\n  h.trans_is_o ((is_o_pow_sub_sub x₀ hn).mono nhds_within_le_nhds)]\n\nlemma asymptotics.is_O.has_fderiv_at {x₀ : E} {n : ℕ}\n  (h : f =O[𝓝 x₀] λ x, ‖x - x₀‖^n) (hn : 1 < n) :\n  has_fderiv_at f (0 : E →L[𝕜] F) x₀ :=\nbegin\n  rw [← nhds_within_univ] at h,\n  exact (h.has_fderiv_within_at (mem_univ _) hn).has_fderiv_at_of_univ\nend\n\nlemma has_fderiv_within_at.is_O {f : E → F} {s : set E} {x₀ : E} {f' : E →L[𝕜] F}\n  (h : has_fderiv_within_at f f' s x₀) :\n  (λ x, f x - f x₀) =O[𝓝[s] x₀] λ x, x - x₀ :=\nby simpa only [sub_add_cancel] using h.is_O.add (is_O_sub f' (𝓝[s] x₀) x₀)\n\nlemma has_fderiv_at.is_O {f : E → F} {x₀ : E} {f' : E →L[𝕜] F} (h : has_fderiv_at f f' x₀) :\n  (λ x, f x - f x₀) =O[𝓝 x₀] λ x, x - x₀ :=\nby simpa only [sub_add_cancel] using h.is_O.add (is_O_sub f' (𝓝 x₀) x₀)\n\nend fderiv_properties\n\nsection continuous\n/-! ### Deducing continuity from differentiability -/\n\ntheorem has_fderiv_at_filter.tendsto_nhds\n  (hL : L ≤ 𝓝 x) (h : has_fderiv_at_filter f f' x L) :\n  tendsto f L (𝓝 (f x)) :=\nbegin\n  have : tendsto (λ x', f x' - f x) L (𝓝 0),\n  { refine h.is_O_sub.trans_tendsto (tendsto.mono_left _ hL),\n    rw ← 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 only [sub_add_cancel, eq_self_iff_true, forall_const])\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_rfl h\n\nlemma differentiable_within_at.continuous_within_at (h : differentiable_within_at 𝕜 f s x) :\n  continuous_within_at f s x :=\nlet ⟨f', hf'⟩ := h in hf'.continuous_within_at\n\nlemma differentiable_at.continuous_at (h : differentiable_at 𝕜 f x) : continuous_at f x :=\nlet ⟨f', hf'⟩ := h in hf'.continuous_at\n\nlemma differentiable_on.continuous_on (h : differentiable_on 𝕜 f s) : continuous_on f s :=\nλx hx, (h x hx).continuous_within_at\n\nlemma differentiable.continuous (h : differentiable 𝕜 f) : continuous f :=\ncontinuous_iff_continuous_at.2 $ λx, (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 ≃L[𝕜] F}\n  (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) x) :\n  (λ p : E × E, p.1 - p.2) =O[𝓝 (x, x)](λ p : E × E, f p.1 - f p.2) :=\n((f'.is_O_comp_rev _ _).trans (hf.trans_is_O (f'.is_O_comp_rev _ _)).right_is_O_add).congr\n(λ _, rfl) (λ _, sub_add_cancel _ _)\n\nlemma has_fderiv_at_filter.is_O_sub_rev (hf : has_fderiv_at_filter f f' x L) {C}\n  (hf' : antilipschitz_with C f') :\n  (λ x', x' - x) =O[L] (λ x', f x' - f x) :=\nhave (λ x', x' - x) =O[L] (λ x', f' (x' - x)),\n  from is_O_iff.2 ⟨C, eventually_of_forall $ λ x',\n    add_monoid_hom_class.bound_of_antilipschitz f' hf' _⟩,\n(this.trans (hf.trans_is_O this).right_is_O_add).congr (λ _, rfl) (λ _, 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₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) :\n  has_strict_fderiv_at f₀ f₀' x ↔ has_strict_fderiv_at f₁ f₁' x :=\nbegin\n  refine is_o_congr ((h.prod_mk_nhds h).mono _) (eventually_of_forall $ λ _, rfl),\n  rintros p ⟨hp₁, hp₂⟩,\n  simp only [*]\nend\n\ntheorem has_strict_fderiv_at.congr_of_eventually_eq (h : has_strict_fderiv_at f f' x)\n  (h₁ : f =ᶠ[𝓝 x] f₁) : has_strict_fderiv_at f₁ f' x :=\n(h₁.has_strict_fderiv_at_iff (λ _, rfl)).1 h\n\ntheorem filter.eventually_eq.has_fderiv_at_filter_iff\n  (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :\n  has_fderiv_at_filter f₀ f₀' x L ↔ has_fderiv_at_filter f₁ f₁' x L :=\nis_o_congr (h₀.mono $ λ y hy, by simp only [hy, h₁, hx]) (eventually_of_forall $ λ _, rfl)\n\nlemma has_fderiv_at_filter.congr_of_eventually_eq (h : has_fderiv_at_filter f f' x L)\n  (hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_fderiv_at_filter f₁ f' x L :=\n(hL.has_fderiv_at_filter_iff hx $ λ _, rfl).2 h\n\ntheorem filter.eventually_eq.has_fderiv_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) :\n  has_fderiv_at f₀ f' x ↔ has_fderiv_at f₁ f' x :=\nh.has_fderiv_at_filter_iff h.eq_of_nhds (λ _, rfl)\n\ntheorem filter.eventually_eq.differentiable_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) :\n  differentiable_at 𝕜 f₀ x ↔ differentiable_at 𝕜 f₁ x :=\nexists_congr $ λ f', h.has_fderiv_at_iff\n\ntheorem filter.eventually_eq.has_fderiv_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) :\n  has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x :=\nh.has_fderiv_at_filter_iff hx (λ _, rfl)\n\ntheorem filter.eventually_eq.has_fderiv_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) :\n  has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x :=\nh.has_fderiv_within_at_iff (h.eq_of_nhds_within hx)\n\ntheorem filter.eventually_eq.differentiable_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁)\n  (hx : f₀ x = f₁ x) :\n  differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x :=\nexists_congr $ λ f', h.has_fderiv_within_at_iff hx\n\ntheorem filter.eventually_eq.differentiable_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁)\n  (hx : x ∈ s) :\n  differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x :=\nh.differentiable_within_at_iff (h.eq_of_nhds_within hx)\n\nlemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)\n  (hx : f₁ x = f x) (h₁ : t ⊆ s) : has_fderiv_within_at f₁ f' t x :=\nhas_fderiv_at_filter.congr_of_eventually_eq (h.mono h₁) (filter.mem_inf_of_right ht) hx\n\nlemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)\n  (hx : f₁ x = f x) : has_fderiv_within_at f₁ 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 : ∀x ∈ s, f₁ x = f x)\n  (hx : x ∈ s) : has_fderiv_within_at f₁ 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₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x :=\nhas_fderiv_at_filter.congr_of_eventually_eq h h₁ hx\n\nlemma has_fderiv_at.congr_of_eventually_eq (h : has_fderiv_at f f' x)\n  (h₁ : f₁ =ᶠ[𝓝 x] f) : has_fderiv_at f₁ f' x :=\nhas_fderiv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _)\n\nlemma differentiable_within_at.congr_mono (h : differentiable_within_at 𝕜 f s x)\n  (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : differentiable_within_at 𝕜 f₁ t x :=\n(has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h₁).differentiable_within_at\n\nlemma differentiable_within_at.congr (h : differentiable_within_at 𝕜 f s x)\n  (ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ 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 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f)\n  (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x :=\n(h.has_fderiv_within_at.congr_of_eventually_eq h₁ hx).differentiable_within_at\n\nlemma differentiable_on.congr_mono (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ t, f₁ x = f x)\n  (h₁ : t ⊆ s) : differentiable_on 𝕜 f₁ t :=\nλ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁\n\nlemma differentiable_on.congr (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ s, f₁ x = f x) :\n  differentiable_on 𝕜 f₁ s :=\nλ x hx, (h x hx).congr h' (h' x hx)\n\nlemma differentiable_on_congr (h' : ∀x ∈ s, f₁ x = f x) :\n  differentiable_on 𝕜 f₁ s ↔ differentiable_on 𝕜 f s :=\n⟨λ h, differentiable_on.congr h (λy hy, (h' y hy).symm),\nλ h, differentiable_on.congr h h'⟩\n\nlemma differentiable_at.congr_of_eventually_eq (h : differentiable_at 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) :\n  differentiable_at 𝕜 f₁ x :=\nhL.differentiable_at_iff.2 h\n\nlemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at 𝕜 f s x)\n  (hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_diff_within_at 𝕜 t x) (h₁ : t ⊆ s) :\n  fderiv_within 𝕜 f₁ t x = fderiv_within 𝕜 f s x :=\n(has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h₁).fderiv_within hxt\n\nlemma filter.eventually_eq.fderiv_within_eq (hs : unique_diff_within_at 𝕜 s x)\n  (hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :\n  fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=\nif h : differentiable_within_at 𝕜 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' : ¬ differentiable_within_at 𝕜 f₁ s x,\n  from mt (λ h, h.congr_of_eventually_eq (hL.mono $ λ 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 filter.eventually_eq.fderiv_within_eq_nhds (hs : unique_diff_within_at 𝕜 s x)\n  (hL : f₁ =ᶠ[𝓝 x] f) :\n  fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=\n(show f₁ =ᶠ[𝓝[s] x] f, from nhds_within_le_nhds hL).fderiv_within_eq hs (mem_of_mem_nhds hL : _)\n\nlemma fderiv_within_congr (hs : unique_diff_within_at 𝕜 s x)\n  (hL : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :\n  fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=\nbegin\n  apply filter.eventually_eq.fderiv_within_eq hs _ hx,\n  apply mem_of_superset self_mem_nhds_within,\n  exact hL\nend\n\nlemma fderiv_within_congr' (hs : unique_diff_within_at 𝕜 s x)\n  (hL : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) :\n  fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x :=\nfderiv_within_congr hs hL (hL x hx)\n\nlemma filter.eventually_eq.fderiv_eq (hL : f₁ =ᶠ[𝓝 x] f) :\n  fderiv 𝕜 f₁ x = fderiv 𝕜 f x :=\nbegin\n  have A : f₁ x = f x := hL.eq_of_nhds,\n  rw [← fderiv_within_univ, ← fderiv_within_univ],\n  rw ← nhds_within_univ at hL,\n  exact hL.fderiv_within_eq unique_diff_within_at_univ A\nend\n\nprotected lemma filter.eventually_eq.fderiv (h : f₁ =ᶠ[𝓝 x] f) :\n  fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f :=\nh.eventually_eq_nhds.mono $ λ x h, h.fderiv_eq\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 𝕜 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 𝕜 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 𝕜 E) s x :=\nhas_fderiv_at_filter_id _ _\n\ntheorem has_fderiv_at_id (x : E) : has_fderiv_at id (id 𝕜 E) x :=\nhas_fderiv_at_filter_id _ _\n\n@[simp] lemma differentiable_at_id : differentiable_at 𝕜 id x :=\n(has_fderiv_at_id x).differentiable_at\n\n@[simp] lemma differentiable_at_id' : differentiable_at 𝕜 (λ x, x) x :=\n(has_fderiv_at_id x).differentiable_at\n\nlemma differentiable_within_at_id : differentiable_within_at 𝕜 id s x :=\ndifferentiable_at_id.differentiable_within_at\n\n@[simp] lemma differentiable_id : differentiable 𝕜 (id : E → E) :=\nλx, differentiable_at_id\n\n@[simp] lemma differentiable_id' : differentiable 𝕜 (λ (x : E), x) :=\nλx, differentiable_at_id\n\nlemma differentiable_on_id : differentiable_on 𝕜 id s :=\ndifferentiable_id.differentiable_on\n\nlemma fderiv_id : fderiv 𝕜 id x = id 𝕜 E :=\nhas_fderiv_at.fderiv (has_fderiv_at_id x)\n\n@[simp] lemma fderiv_id' : fderiv 𝕜 (λ (x : E), x) x = continuous_linear_map.id 𝕜 E :=\nfderiv_id\n\nlemma fderiv_within_id (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 id s x = id 𝕜 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 𝕜 s x) :\n  fderiv_within 𝕜 (λ (x : E), x) s x = continuous_linear_map.id 𝕜 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 (λ _, c) (0 : E →L[𝕜] F) x :=\n(is_o_zero _ _).congr_left $ λ _, 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 (λ x, c) (0 : E →L[𝕜] F) x L :=\n(is_o_zero _ _).congr_left $ λ _, 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 (λ x, c) (0 : E →L[𝕜] F) s x :=\nhas_fderiv_at_filter_const _ _ _\n\ntheorem has_fderiv_at_const (c : F) (x : E) :\n  has_fderiv_at (λ x, c) (0 : E →L[𝕜] F) x :=\nhas_fderiv_at_filter_const _ _ _\n\n@[simp] lemma differentiable_at_const (c : F) : differentiable_at 𝕜 (λx, c) x :=\n⟨0, has_fderiv_at_const c x⟩\n\nlemma differentiable_within_at_const (c : F) : differentiable_within_at 𝕜 (λx, c) s x :=\ndifferentiable_at.differentiable_within_at (differentiable_at_const _)\n\nlemma fderiv_const_apply (c : F) : fderiv 𝕜 (λy, c) x = 0 :=\nhas_fderiv_at.fderiv (has_fderiv_at_const c x)\n\n@[simp] lemma fderiv_const (c : F) : fderiv 𝕜 (λ (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 𝕜 s x) :\n  fderiv_within 𝕜 (λy, 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 𝕜 (λx : E, c) :=\nλx, differentiable_at_const _\n\nlemma differentiable_on_const (c : F) : differentiable_on 𝕜 (λx, c) s :=\n(differentiable_const _).differentiable_on\n\nlemma has_fderiv_within_at_singleton (f : E → F) (x : E) :\n  has_fderiv_within_at f (0 : E →L[𝕜] F) {x} x :=\nby simp only [has_fderiv_within_at, nhds_within_singleton, has_fderiv_at_filter, is_o_pure,\n  continuous_linear_map.zero_apply, sub_self]\n\nlemma has_fderiv_at_of_subsingleton [h : subsingleton E] (f : E → F) (x : E) :\n  has_fderiv_at f (0 : E →L[𝕜] F) x :=\nbegin\n  rw [← has_fderiv_within_at_univ, subsingleton_univ.eq_singleton_of_mem (mem_univ x)],\n  exact has_fderiv_within_at_singleton f x\nend\n\nlemma differentiable_on_empty : differentiable_on 𝕜 f ∅ := λ x, false.elim\n\nlemma differentiable_on_singleton : differentiable_on 𝕜 f {x} :=\nforall_eq.2 (has_fderiv_within_at_singleton f x).differentiable_within_at\n\nlemma set.subsingleton.differentiable_on (hs : s.subsingleton) : differentiable_on 𝕜 f s :=\nhs.induction_on differentiable_on_empty (λ x, differentiable_on_singleton)\n\nlemma has_fderiv_at_zero_of_eventually_const\n  (c : F) (hf : f =ᶠ[𝓝 x] (λ y, c)) :\n  has_fderiv_at f (0 : E →L[𝕜] F) x :=\n(has_fderiv_at_const _ _).congr_of_eventually_eq hf\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 →L[𝕜] 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 $ λ 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 $ λ 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 𝕜 e x :=\ne.has_fderiv_at.differentiable_at\n\nprotected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at 𝕜 e s x :=\ne.differentiable_at.differentiable_within_at\n\n@[simp] protected lemma continuous_linear_map.fderiv : fderiv 𝕜 e x = e :=\ne.has_fderiv_at.fderiv\n\nprotected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 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 𝕜 e :=\nλx, e.differentiable_at\n\nprotected lemma continuous_linear_map.differentiable_on : differentiable_on 𝕜 e s :=\ne.differentiable.differentiable_on\n\nlemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map 𝕜 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 𝕜 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 𝕜 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 𝕜 f) :\n  differentiable_at 𝕜 f x :=\nh.has_fderiv_at.differentiable_at\n\nlemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map 𝕜 f) :\n  differentiable_within_at 𝕜 f s x :=\nh.differentiable_at.differentiable_within_at\n\nlemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map 𝕜 f) :\n  fderiv 𝕜 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 𝕜 f)\n  (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 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 𝕜 f) :\n  differentiable 𝕜 f :=\nλx, h.differentiable_at\n\nlemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map 𝕜 f) :\n  differentiable_on 𝕜 f s :=\nh.differentiable.differentiable_on\n\nend continuous_linear_map\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 → G} {g' : F →L[𝕜] G} {L' : filter F}\n  (hg : has_fderiv_at_filter g g' (f x) L')\n  (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L') :\n  has_fderiv_at_filter (g ∘ f) (g'.comp f') x L :=\nlet eq₁ := (g'.is_O_comp _ _).trans_is_o hf in\nlet eq₂ := (hg.comp_tendsto hL).trans_is_O hf.is_O_sub in\nby { refine eq₂.triangle (eq₁.congr_left (λ x', _)), simp }\n\n/- A readable version of the previous theorem,\n   a general form of the chain rule. -/\n\nexample {g : F → G} {g' : F →L[𝕜] 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 ∘ f) (g'.comp f') x L :=\nbegin\n  unfold has_fderiv_at_filter at hg,\n  have := calc (λ x', g (f x') - g (f x) - g' (f x' - f x)) =o[L] (λ x', f x' - f x) :\n    hg.comp_tendsto le_rfl\n  ... =O[L] (λ x', x' - x) : hf.is_O_sub,\n  refine this.triangle _,\n  calc (λ x' : E, g' (f x' - f x) - g'.comp f' (x' - x))\n      =ᶠ[L] λ x', g' (f x' - f x - f' (x' - x)) : eventually_of_forall (λ x', by simp)\n  ... =O[L] λ x', f x' - f x - f' (x' - x)      : g'.is_O_comp _ _\n  ... =o[L] λ x', x' - x                        : hf\nend\n\ntheorem has_fderiv_within_at.comp {g : F → G} {g' : F →L[𝕜] 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 : maps_to f s t) :\n  has_fderiv_within_at (g ∘ f) (g'.comp f') s x :=\nhg.comp x hf $ hf.continuous_within_at.tendsto_nhds_within hst\n\ntheorem has_fderiv_at.comp_has_fderiv_within_at {g : F → G} {g' : F →L[𝕜] 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 ∘ f) (g'.comp f') s x :=\nhg.comp x hf hf.continuous_within_at\n\ntheorem has_fderiv_within_at.comp_of_mem {g : F → G} {g' : F →L[𝕜] 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 : tendsto f (𝓝[s] x) (𝓝[t] f x)) :\n  has_fderiv_within_at (g ∘ f) (g'.comp f') s x :=\nhas_fderiv_at_filter.comp x hg hf hst\n\n/-- The chain rule. -/\ntheorem has_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G}\n  (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) :\n  has_fderiv_at (g ∘ f) (g'.comp f') x :=\nhg.comp x hf hf.continuous_at\n\nlemma differentiable_within_at.comp {g : F → G} {t : set F}\n  (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x)\n  (h : maps_to f s t) : differentiable_within_at 𝕜 (g ∘ f) s x :=\n(hg.has_fderiv_within_at.comp x hf.has_fderiv_within_at h).differentiable_within_at\n\nlemma differentiable_within_at.comp' {g : F → G} {t : set F}\n  (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) :\n  differentiable_within_at 𝕜 (g ∘ f) (s ∩ f⁻¹' t) x :=\nhg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)\n\nlemma differentiable_at.comp {g : F → G}\n  (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) :\n  differentiable_at 𝕜 (g ∘ 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 → G}\n  (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) :\n  differentiable_within_at 𝕜 (g ∘ f) s x :=\nhg.differentiable_within_at.comp x hf (maps_to_univ _ _)\n\nlemma fderiv_within.comp {g : F → G} {t : set F}\n  (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x)\n  (h : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (g ∘ f) s x = (fderiv_within 𝕜 g t (f x)).comp (fderiv_within 𝕜 f s x) :=\n(hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h).fderiv_within hxs\n\n/-- A version of `fderiv_within.comp` that is useful to rewrite the composition of two derivatives\n  into a single derivative. This version always applies, but creates a new side-goal `f x = y`. -/\nlemma fderiv_within_fderiv_within {g : F → G} {f : E → F} {x : E} {y : F} {s : set E} {t : set F}\n  (hg : differentiable_within_at 𝕜 g t y) (hf : differentiable_within_at 𝕜 f s x)\n  (h : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) (hy : f x = y) (v : E) :\n  fderiv_within 𝕜 g t y (fderiv_within 𝕜 f s x v) = fderiv_within 𝕜 (g ∘ f) s x v :=\nby { subst y, rw [fderiv_within.comp x hg hf h hxs], refl }\n\n/-- Ternary version of `fderiv_within.comp`, with equality assumptions of basepoints added, in\n  order to apply more easily as a rewrite from right-to-left. -/\nlemma fderiv_within.comp₃ {g' : G → G'} {g : F → G} {t : set F} {u : set G} {y : F} {y' : G}\n  (hg' : differentiable_within_at 𝕜 g' u y') (hg : differentiable_within_at 𝕜 g t y)\n  (hf : differentiable_within_at 𝕜 f s x)\n  (h2g : maps_to g t u) (h2f : maps_to f s t)\n  (h3g : g y = y') (h3f : f x = y) (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (g' ∘ g ∘ f) s x = (fderiv_within 𝕜 g' u y').comp\n    ((fderiv_within 𝕜 g t y).comp (fderiv_within 𝕜 f s x)) :=\nbegin\n  substs h3g h3f,\n  exact (hg'.has_fderiv_within_at.comp x\n    (hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h2f) $ h2g.comp h2f).fderiv_within hxs\nend\n\nlemma fderiv.comp {g : F → G}\n  (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) :\n  fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) :=\n(hg.has_fderiv_at.comp x hf.has_fderiv_at).fderiv\n\nlemma fderiv.comp_fderiv_within {g : F → G}\n  (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x)\n  (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (g ∘ f) s x = (fderiv 𝕜 g (f x)).comp (fderiv_within 𝕜 f s x) :=\n(hg.has_fderiv_at.comp_has_fderiv_within_at x hf.has_fderiv_within_at).fderiv_within hxs\n\nlemma differentiable_on.comp {g : F → G} {t : set F}\n  (hg : differentiable_on 𝕜 g t) (hf : differentiable_on 𝕜 f s) (st : maps_to f s t) :\n  differentiable_on 𝕜 (g ∘ f) s :=\nλx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st\n\nlemma differentiable.comp {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable 𝕜 f) :\n  differentiable 𝕜 (g ∘ f) :=\nλx, differentiable_at.comp x (hg (f x)) (hf x)\n\nlemma differentiable.comp_differentiable_on {g : F → G} (hg : differentiable 𝕜 g)\n  (hf : differentiable_on 𝕜 f s) :\n  differentiable_on 𝕜 (g ∘ f) s :=\nhg.differentiable_on.comp hf (maps_to_univ _ _)\n\n/-- The chain rule for derivatives in the sense of strict differentiability. -/\nprotected lemma has_strict_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G}\n  (hg : has_strict_fderiv_at g g' (f x)) (hf : has_strict_fderiv_at f f' x) :\n  has_strict_fderiv_at (λ 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 → E} (hf : differentiable 𝕜 f) (n : ℕ) :\n  differentiable 𝕜 (f^[n]) :=\nnat.rec_on n differentiable_id (λ n ihn, ihn.comp hf)\n\nprotected lemma differentiable_on.iterate {f : E → E} (hf : differentiable_on 𝕜 f s)\n  (hs : maps_to f s s) (n : ℕ) :\n  differentiable_on 𝕜 (f^[n]) s :=\nnat.rec_on n differentiable_on_id (λ n ihn, ihn.comp hf hs)\n\nvariable {x}\n\nprotected lemma has_fderiv_at_filter.iterate {f : E → E} {f' : E →L[𝕜] E}\n  (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) :\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  { rw [function.iterate_succ, pow_succ'],\n    rw ← hx at ihn,\n    exact ihn.comp x hf hL }\nend\n\nprotected lemma has_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E}\n  (hf : has_fderiv_at f f' x) (hx : f x = x) (n : ℕ) :\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 → E} {f' : E →L[𝕜] E}\n  (hf : has_fderiv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :\n  has_fderiv_within_at (f^[n]) (f'^n) s x :=\nbegin\n  refine hf.iterate _ hx n,\n  convert tendsto_inf.2 ⟨hf.continuous_within_at, _⟩,\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 → E} {f' : E →L[𝕜] E}\n  (hf : has_strict_fderiv_at f f' x) (hx : f x = x) (n : ℕ) :\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  { rw [function.iterate_succ, pow_succ'],\n    rw ← hx at ihn,\n    exact ihn.comp x hf }\nend\n\nprotected lemma differentiable_at.iterate {f : E → E} (hf : differentiable_at 𝕜 f x)\n  (hx : f x = x) (n : ℕ) :\n  differentiable_at 𝕜 (f^[n]) x :=\n(hf.has_fderiv_at.iterate hx n).differentiable_at\n\nprotected lemma differentiable_within_at.iterate {f : E → E} (hf : differentiable_within_at 𝕜 f s x)\n  (hx : f x = x) (hs : maps_to f s s) (n : ℕ) :\n  differentiable_within_at 𝕜 (f^[n]) s x :=\n(hf.has_fderiv_within_at.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₂ : E → G} {f₂' : E →L[𝕜] G}\n\nprotected lemma has_strict_fderiv_at.prod\n  (hf₁ : has_strict_fderiv_at f₁ f₁' x) (hf₂ : has_strict_fderiv_at f₂ f₂' x) :\n  has_strict_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x :=\nhf₁.prod_left hf₂\n\nlemma has_fderiv_at_filter.prod\n  (hf₁ : has_fderiv_at_filter f₁ f₁' x L) (hf₂ : has_fderiv_at_filter f₂ f₂' x L) :\n  has_fderiv_at_filter (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x L :=\nhf₁.prod_left hf₂\n\nlemma has_fderiv_within_at.prod\n  (hf₁ : has_fderiv_within_at f₁ f₁' s x) (hf₂ : has_fderiv_within_at f₂ f₂' s x) :\n  has_fderiv_within_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') s x :=\nhf₁.prod hf₂\n\nlemma has_fderiv_at.prod (hf₁ : has_fderiv_at f₁ f₁' x) (hf₂ : has_fderiv_at f₂ f₂' x) :\n  has_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x :=\nhf₁.prod hf₂\n\nlemma has_fderiv_at_prod_mk_left (e₀ : E) (f₀ : F) :\n  has_fderiv_at (λ e : E, (e, f₀)) (inl 𝕜 E F) e₀ :=\n(has_fderiv_at_id e₀).prod (has_fderiv_at_const f₀ e₀)\n\nlemma has_fderiv_at_prod_mk_right (e₀ : E) (f₀ : F) :\n  has_fderiv_at (λ f : F, (e₀, f)) (inr 𝕜 E F) f₀ :=\n(has_fderiv_at_const e₀ f₀).prod (has_fderiv_at_id f₀)\n\nlemma differentiable_within_at.prod\n  (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) :\n  differentiable_within_at 𝕜 (λx:E, (f₁ x, f₂ x)) s x :=\n(hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).differentiable_within_at\n\n@[simp]\nlemma differentiable_at.prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) :\n  differentiable_at 𝕜 (λx:E, (f₁ x, f₂ x)) x :=\n(hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.prod (hf₁ : differentiable_on 𝕜 f₁ s) (hf₂ : differentiable_on 𝕜 f₂ s) :\n  differentiable_on 𝕜 (λx:E, (f₁ x, f₂ x)) s :=\nλx hx, differentiable_within_at.prod (hf₁ x hx) (hf₂ x hx)\n\n@[simp]\nlemma differentiable.prod (hf₁ : differentiable 𝕜 f₁) (hf₂ : differentiable 𝕜 f₂) :\n  differentiable 𝕜 (λx:E, (f₁ x, f₂ x)) :=\nλ x, differentiable_at.prod (hf₁ x) (hf₂ x)\n\nlemma differentiable_at.fderiv_prod\n  (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) :\n  fderiv 𝕜 (λx:E, (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) :=\n(hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).fderiv\n\nlemma differentiable_at.fderiv_within_prod\n  (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x)\n  (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (λx:E, (f₁ x, f₂ x)) s x =\n    (fderiv_within 𝕜 f₁ s x).prod (fderiv_within 𝕜 f₂ s x) :=\n(hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).fderiv_within hxs\n\nend prod\n\nsection fst\n\nvariables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}\n\nlemma has_strict_fderiv_at_fst : has_strict_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p :=\n(fst 𝕜 E F).has_strict_fderiv_at\n\nprotected lemma has_strict_fderiv_at.fst (h : has_strict_fderiv_at f₂ f₂' x) :\n  has_strict_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=\nhas_strict_fderiv_at_fst.comp x h\n\nlemma has_fderiv_at_filter_fst {L : filter (E × F)} :\n  has_fderiv_at_filter (@prod.fst E F) (fst 𝕜 E F) p L :=\n(fst 𝕜 E F).has_fderiv_at_filter\n\nprotected lemma has_fderiv_at_filter.fst (h : has_fderiv_at_filter f₂ f₂' x L) :\n  has_fderiv_at_filter (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L :=\nhas_fderiv_at_filter_fst.comp x h tendsto_map\n\nlemma has_fderiv_at_fst : has_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p :=\nhas_fderiv_at_filter_fst\n\nprotected lemma has_fderiv_at.fst (h : has_fderiv_at f₂ f₂' x) :\n  has_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x :=\nh.fst\n\nlemma has_fderiv_within_at_fst {s : set (E × F)} :\n  has_fderiv_within_at (@prod.fst E F) (fst 𝕜 E F) s p :=\nhas_fderiv_at_filter_fst\n\nprotected lemma has_fderiv_within_at.fst (h : has_fderiv_within_at f₂ f₂' s x) :\n  has_fderiv_within_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x :=\nh.fst\n\nlemma differentiable_at_fst : differentiable_at 𝕜 prod.fst p :=\nhas_fderiv_at_fst.differentiable_at\n\n@[simp] protected lemma differentiable_at.fst (h : differentiable_at 𝕜 f₂ x) :\n  differentiable_at 𝕜 (λ x, (f₂ x).1) x :=\ndifferentiable_at_fst.comp x h\n\nlemma differentiable_fst : differentiable 𝕜 (prod.fst : E × F → E) :=\nλ x, differentiable_at_fst\n\n@[simp] protected lemma differentiable.fst (h : differentiable 𝕜 f₂) :\n  differentiable 𝕜 (λ x, (f₂ x).1) :=\ndifferentiable_fst.comp h\n\nlemma differentiable_within_at_fst {s : set (E × F)} : differentiable_within_at 𝕜 prod.fst s p :=\ndifferentiable_at_fst.differentiable_within_at\n\nprotected lemma differentiable_within_at.fst (h : differentiable_within_at 𝕜 f₂ s x) :\n  differentiable_within_at 𝕜 (λ x, (f₂ x).1) s x :=\ndifferentiable_at_fst.comp_differentiable_within_at x h\n\nlemma differentiable_on_fst {s : set (E × F)} : differentiable_on 𝕜 prod.fst s :=\ndifferentiable_fst.differentiable_on\n\nprotected lemma differentiable_on.fst (h : differentiable_on 𝕜 f₂ s) :\n  differentiable_on 𝕜 (λ x, (f₂ x).1) s :=\ndifferentiable_fst.comp_differentiable_on h\n\nlemma fderiv_fst : fderiv 𝕜 prod.fst p = fst 𝕜 E F := has_fderiv_at_fst.fderiv\n\nlemma fderiv.fst (h : differentiable_at 𝕜 f₂ x) :\n  fderiv 𝕜 (λ x, (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=\nh.has_fderiv_at.fst.fderiv\n\nlemma fderiv_within_fst {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) :\n  fderiv_within 𝕜 prod.fst s p = fst 𝕜 E F :=\nhas_fderiv_within_at_fst.fderiv_within hs\n\nlemma fderiv_within.fst (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) :\n  fderiv_within 𝕜 (λ x, (f₂ x).1) s x = (fst 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) :=\nh.has_fderiv_within_at.fst.fderiv_within hs\n\nend fst\n\nsection snd\n\nvariables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F}\n\nlemma has_strict_fderiv_at_snd : has_strict_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p :=\n(snd 𝕜 E F).has_strict_fderiv_at\n\nprotected lemma has_strict_fderiv_at.snd (h : has_strict_fderiv_at f₂ f₂' x) :\n  has_strict_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=\nhas_strict_fderiv_at_snd.comp x h\n\nlemma has_fderiv_at_filter_snd {L : filter (E × F)} :\n  has_fderiv_at_filter (@prod.snd E F) (snd 𝕜 E F) p L :=\n(snd 𝕜 E F).has_fderiv_at_filter\n\nprotected lemma has_fderiv_at_filter.snd (h : has_fderiv_at_filter f₂ f₂' x L) :\n  has_fderiv_at_filter (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L :=\nhas_fderiv_at_filter_snd.comp x h tendsto_map\n\nlemma has_fderiv_at_snd : has_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p :=\nhas_fderiv_at_filter_snd\n\nprotected lemma has_fderiv_at.snd (h : has_fderiv_at f₂ f₂' x) :\n  has_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x :=\nh.snd\n\nlemma has_fderiv_within_at_snd {s : set (E × F)} :\n  has_fderiv_within_at (@prod.snd E F) (snd 𝕜 E F) s p :=\nhas_fderiv_at_filter_snd\n\nprotected lemma has_fderiv_within_at.snd (h : has_fderiv_within_at f₂ f₂' s x) :\n  has_fderiv_within_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x :=\nh.snd\n\nlemma differentiable_at_snd : differentiable_at 𝕜 prod.snd p :=\nhas_fderiv_at_snd.differentiable_at\n\n@[simp] protected lemma differentiable_at.snd (h : differentiable_at 𝕜 f₂ x) :\n  differentiable_at 𝕜 (λ x, (f₂ x).2) x :=\ndifferentiable_at_snd.comp x h\n\nlemma differentiable_snd : differentiable 𝕜 (prod.snd : E × F → F) :=\nλ x, differentiable_at_snd\n\n@[simp] protected lemma differentiable.snd (h : differentiable 𝕜 f₂) :\n  differentiable 𝕜 (λ x, (f₂ x).2) :=\ndifferentiable_snd.comp h\n\nlemma differentiable_within_at_snd {s : set (E × F)} : differentiable_within_at 𝕜 prod.snd s p :=\ndifferentiable_at_snd.differentiable_within_at\n\nprotected lemma differentiable_within_at.snd (h : differentiable_within_at 𝕜 f₂ s x) :\n  differentiable_within_at 𝕜 (λ x, (f₂ x).2) s x :=\ndifferentiable_at_snd.comp_differentiable_within_at x h\n\nlemma differentiable_on_snd {s : set (E × F)} : differentiable_on 𝕜 prod.snd s :=\ndifferentiable_snd.differentiable_on\n\nprotected lemma differentiable_on.snd (h : differentiable_on 𝕜 f₂ s) :\n  differentiable_on 𝕜 (λ x, (f₂ x).2) s :=\ndifferentiable_snd.comp_differentiable_on h\n\nlemma fderiv_snd : fderiv 𝕜 prod.snd p = snd 𝕜 E F := has_fderiv_at_snd.fderiv\n\nlemma fderiv.snd (h : differentiable_at 𝕜 f₂ x) :\n  fderiv 𝕜 (λ x, (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) :=\nh.has_fderiv_at.snd.fderiv\n\nlemma fderiv_within_snd {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) :\n  fderiv_within 𝕜 prod.snd s p = snd 𝕜 E F :=\nhas_fderiv_within_at_snd.fderiv_within hs\n\nlemma fderiv_within.snd (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) :\n  fderiv_within 𝕜 (λ x, (f₂ x).2) s x = (snd 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) :=\nh.has_fderiv_within_at.snd.fderiv_within hs\n\nend snd\n\nsection prod_map\n\nvariables {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G)\n\nprotected theorem has_strict_fderiv_at.prod_map (hf : has_strict_fderiv_at f f' p.1)\n  (hf₂ : has_strict_fderiv_at f₂ f₂' p.2) :\n  has_strict_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p :=\n(hf.comp p has_strict_fderiv_at_fst).prod (hf₂.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₂ : has_fderiv_at f₂ f₂' p.2) :\n  has_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p :=\n(hf.comp p has_fderiv_at_fst).prod (hf₂.comp p has_fderiv_at_snd)\n\n@[simp] protected theorem differentiable_at.prod_map (hf : differentiable_at 𝕜 f p.1)\n  (hf₂ : differentiable_at 𝕜 f₂ p.2) :\n  differentiable_at 𝕜 (λ p : E × G, (f p.1, f₂ p.2)) p :=\n(hf.comp p differentiable_at_fst).prod (hf₂.comp p differentiable_at_snd)\n\nend prod_map\n\nend cartesian_product\n\nsection const_smul\n\nvariables {R : Type*} [semiring R] [module R F] [smul_comm_class 𝕜 R F]\n  [has_continuous_const_smul R F]\n\n/-! ### Derivative of a function multiplied by a constant -/\ntheorem has_strict_fderiv_at.const_smul (h : has_strict_fderiv_at f f' x) (c : R) :\n  has_strict_fderiv_at (λ x, c • f x) (c • f') x :=\n(c • (1 : F →L[𝕜] 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 : R) :\n  has_fderiv_at_filter (λ x, c • f x) (c • f') x L :=\n(c • (1 : F →L[𝕜] F)).has_fderiv_at_filter.comp x h tendsto_map\n\ntheorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : R) :\n  has_fderiv_within_at (λ x, c • f x) (c • f') s x :=\nh.const_smul c\n\ntheorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : R) :\n  has_fderiv_at (λ x, c • f x) (c • f') x :=\nh.const_smul c\n\nlemma differentiable_within_at.const_smul (h : differentiable_within_at 𝕜 f s x) (c : R) :\n  differentiable_within_at 𝕜 (λy, c • 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 𝕜 f x) (c : R) :\n  differentiable_at 𝕜 (λy, c • f y) x :=\n(h.has_fderiv_at.const_smul c).differentiable_at\n\nlemma differentiable_on.const_smul (h : differentiable_on 𝕜 f s) (c : R) :\n  differentiable_on 𝕜 (λy, c • f y) s :=\nλx hx, (h x hx).const_smul c\n\nlemma differentiable.const_smul (h : differentiable 𝕜 f) (c : R) :\n  differentiable 𝕜 (λy, c • f y) :=\nλx, (h x).const_smul c\n\nlemma fderiv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)\n  (h : differentiable_within_at 𝕜 f s x) (c : R) :\n  fderiv_within 𝕜 (λy, c • f y) s x = c • fderiv_within 𝕜 f s x :=\n(h.has_fderiv_within_at.const_smul c).fderiv_within hxs\n\nlemma fderiv_const_smul (h : differentiable_at 𝕜 f x) (c : R) :\n  fderiv 𝕜 (λy, c • f y) x = c • fderiv 𝕜 f x :=\n(h.has_fderiv_at.const_smul c).fderiv\n\nend const_smul\n\nsection add\n\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 (λ y, f y + g y) (f' + g') x :=\n(hf.add hg).congr_left $ λ y,\n  by { simp only [linear_map.sub_apply, linear_map.add_apply, map_sub, map_add, add_apply], 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 (λ y, f y + g y) (f' + g') x L :=\n(hf.add hg).congr_left $ λ _,\n  by { simp only [linear_map.sub_apply, linear_map.add_apply, map_sub, map_add, add_apply], 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 (λ 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 (λ x, f x + g x) (f' + g') x :=\nhf.add hg\n\nlemma differentiable_within_at.add\n  (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :\n  differentiable_within_at 𝕜 (λ 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 𝕜 f x) (hg : differentiable_at 𝕜 g x) :\n  differentiable_at 𝕜 (λ 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 𝕜 f s) (hg : differentiable_on 𝕜 g s) :\n  differentiable_on 𝕜 (λy, f y + g y) s :=\nλx hx, (hf x hx).add (hg x hx)\n\n@[simp] lemma differentiable.add\n  (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) :\n  differentiable 𝕜 (λy, f y + g y) :=\nλx, (hf x).add (hg x)\n\nlemma fderiv_within_add (hxs : unique_diff_within_at 𝕜 s x)\n  (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :\n  fderiv_within 𝕜 (λy, f y + g y) s x = fderiv_within 𝕜 f s x + fderiv_within 𝕜 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 𝕜 f x) (hg : differentiable_at 𝕜 g x) :\n  fderiv 𝕜 (λy, f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 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 (λ y, f y + c) f' x :=\nadd_zero f' ▸ 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 (λ y, f y + c) f' x L :=\nadd_zero f' ▸ 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 (λ 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 (λ x, f x + c) f' x :=\nhf.add_const c\n\nlemma differentiable_within_at.add_const\n  (hf : differentiable_within_at 𝕜 f s x) (c : F) :\n  differentiable_within_at 𝕜 (λ 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 𝕜 (λ y, f y + c) s x ↔ differentiable_within_at 𝕜 f s x :=\n⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩\n\nlemma differentiable_at.add_const\n  (hf : differentiable_at 𝕜 f x) (c : F) :\n  differentiable_at 𝕜 (λ 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 𝕜 (λ y, f y + c) x ↔ differentiable_at 𝕜 f x :=\n⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩\n\nlemma differentiable_on.add_const\n  (hf : differentiable_on 𝕜 f s) (c : F) :\n  differentiable_on 𝕜 (λy, f y + c) s :=\nλx hx, (hf x hx).add_const c\n\n@[simp] lemma differentiable_on_add_const_iff (c : F) :\n  differentiable_on 𝕜 (λ y, f y + c) s ↔ differentiable_on 𝕜 f s :=\n⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩\n\nlemma differentiable.add_const\n  (hf : differentiable 𝕜 f) (c : F) :\n  differentiable 𝕜 (λy, f y + c) :=\nλx, (hf x).add_const c\n\n@[simp] lemma differentiable_add_const_iff (c : F) :\n  differentiable 𝕜 (λ y, f y + c) ↔ differentiable 𝕜 f :=\n⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩\n\nlemma fderiv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :\n  fderiv_within 𝕜 (λy, f y + c) s x = fderiv_within 𝕜 f s x :=\nif hf : differentiable_within_at 𝕜 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 𝕜 (λy, f y + c) x = fderiv 𝕜 f x :=\nby simp only [← 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 (λ y, c + f y) f' x :=\nzero_add f' ▸ (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 (λ y, c + f y) f' x L :=\nzero_add f' ▸ (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 (λ 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 (λ x, c + f x) f' x :=\nhf.const_add c\n\nlemma differentiable_within_at.const_add\n  (hf : differentiable_within_at 𝕜 f s x) (c : F) :\n  differentiable_within_at 𝕜 (λ 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 𝕜 (λ y, c + f y) s x ↔ differentiable_within_at 𝕜 f s x :=\n⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩\n\nlemma differentiable_at.const_add\n  (hf : differentiable_at 𝕜 f x) (c : F) :\n  differentiable_at 𝕜 (λ 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 𝕜 (λ y, c + f y) x ↔ differentiable_at 𝕜 f x :=\n⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩\n\nlemma differentiable_on.const_add (hf : differentiable_on 𝕜 f s) (c : F) :\n  differentiable_on 𝕜 (λy, c + f y) s :=\nλx hx, (hf x hx).const_add c\n\n@[simp] lemma differentiable_on_const_add_iff (c : F) :\n  differentiable_on 𝕜 (λ y, c + f y) s ↔ differentiable_on 𝕜 f s :=\n⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩\n\nlemma differentiable.const_add (hf : differentiable 𝕜 f) (c : F) :\n  differentiable 𝕜 (λy, c + f y) :=\nλx, (hf x).const_add c\n\n@[simp] lemma differentiable_const_add_iff (c : F) :\n  differentiable 𝕜 (λ y, c + f y) ↔ differentiable 𝕜 f :=\n⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩\n\nlemma fderiv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) :\n  fderiv_within 𝕜 (λy, c + f y) s x = fderiv_within 𝕜 f s x :=\nby simpa only [add_comm] using fderiv_within_add_const hxs c\n\nlemma fderiv_const_add (c : F) : fderiv 𝕜 (λy, c + f y) x = fderiv 𝕜 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 {ι : Type*} {u : finset ι} {A : ι → (E → F)} {A' : ι → (E →L[𝕜] F)}\n\ntheorem has_strict_fderiv_at.sum (h : ∀ i ∈ u, has_strict_fderiv_at (A i) (A' i) x) :\n  has_strict_fderiv_at (λ y, ∑ i in u, A i y) (∑ 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 : ∀ i ∈ u, has_fderiv_at_filter (A i) (A' i) x L) :\n  has_fderiv_at_filter (λ y, ∑ i in u, A i y) (∑ 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 : ∀ i ∈ u, has_fderiv_within_at (A i) (A' i) s x) :\n  has_fderiv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x :=\nhas_fderiv_at_filter.sum h\n\ntheorem has_fderiv_at.sum (h : ∀ i ∈ u, has_fderiv_at (A i) (A' i) x) :\n  has_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x :=\nhas_fderiv_at_filter.sum h\n\ntheorem differentiable_within_at.sum (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :\n  differentiable_within_at 𝕜 (λ y, ∑ i in u, A i y) s x :=\nhas_fderiv_within_at.differentiable_within_at $ has_fderiv_within_at.sum $\nλ i hi, (h i hi).has_fderiv_within_at\n\n@[simp] theorem differentiable_at.sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :\n  differentiable_at 𝕜 (λ y, ∑ i in u, A i y) x :=\nhas_fderiv_at.differentiable_at $ has_fderiv_at.sum $ λ i hi, (h i hi).has_fderiv_at\n\ntheorem differentiable_on.sum (h : ∀ i ∈ u, differentiable_on 𝕜 (A i) s) :\n  differentiable_on 𝕜 (λ y, ∑ i in u, A i y) s :=\nλ x hx, differentiable_within_at.sum $ λ i hi, h i hi x hx\n\n@[simp] theorem differentiable.sum (h : ∀ i ∈ u, differentiable 𝕜 (A i)) :\n  differentiable 𝕜 (λ y, ∑ i in u, A i y) :=\nλ x, differentiable_at.sum $ λ i hi, h i hi x\n\ntheorem fderiv_within_sum (hxs : unique_diff_within_at 𝕜 s x)\n  (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) :\n  fderiv_within 𝕜 (λ y, ∑ i in u, A i y) s x = (∑ i in u, fderiv_within 𝕜 (A i) s x) :=\n(has_fderiv_within_at.sum (λ i hi, (h i hi).has_fderiv_within_at)).fderiv_within hxs\n\ntheorem fderiv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) :\n  fderiv 𝕜 (λ y, ∑ i in u, A i y) x = (∑ i in u, fderiv 𝕜 (A i) x) :=\n(has_fderiv_at.sum (λ i hi, (h i hi).has_fderiv_at)).fderiv\n\nend sum\n\nsection pi\n\n/-!\n### Derivatives of functions `f : E → Π 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 `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i`\n  and is designed to deduce differentiability of `λ x i, φ i x` from differentiability\n  of each `φ i`;\n* the version with `'` deals with `Φ : E → Π i, F' i` and `Φ' : E →L[𝕜] Π i, F' i`\n  and is designed to deduce differentiability of the components `λ x, Φ x i` from\n  differentiability of `Φ`.\n-/\n\nvariables {ι : Type*} [fintype ι] {F' : ι → Type*} [Π i, normed_add_comm_group (F' i)]\n  [Π i, normed_space 𝕜 (F' i)] {φ : Π i, E → F' i} {φ' : Π i, E →L[𝕜] F' i}\n  {Φ : E → Π i, F' i} {Φ' : E →L[𝕜] Π i, F' i}\n\n@[simp] lemma has_strict_fderiv_at_pi' :\n  has_strict_fderiv_at Φ Φ' x ↔\n    ∀ i, has_strict_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') 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 (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔\n    ∀ i, has_strict_fderiv_at (φ i) (φ' i) x :=\nhas_strict_fderiv_at_pi'\n\n@[simp] lemma has_fderiv_at_filter_pi' :\n  has_fderiv_at_filter Φ Φ' x L ↔\n    ∀ i, has_fderiv_at_filter (λ x, Φ x i) ((proj i).comp Φ') 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 (λ x i, φ i x) (continuous_linear_map.pi φ') x L ↔\n    ∀ i, has_fderiv_at_filter (φ i) (φ' i) x L :=\nhas_fderiv_at_filter_pi'\n\n@[simp] lemma has_fderiv_at_pi' :\n  has_fderiv_at Φ Φ' x ↔\n    ∀ i, has_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x :=\nhas_fderiv_at_filter_pi'\n\nlemma has_fderiv_at_pi :\n  has_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔\n    ∀ i, has_fderiv_at (φ i) (φ' i) x :=\nhas_fderiv_at_filter_pi\n\n@[simp] lemma has_fderiv_within_at_pi' :\n  has_fderiv_within_at Φ Φ' s x ↔\n    ∀ i, has_fderiv_within_at (λ x, Φ x i) ((proj i).comp Φ') s x :=\nhas_fderiv_at_filter_pi'\n\nlemma has_fderiv_within_at_pi :\n  has_fderiv_within_at (λ x i, φ i x) (continuous_linear_map.pi φ') s x ↔\n    ∀ i, has_fderiv_within_at (φ i) (φ' i) s x :=\nhas_fderiv_at_filter_pi\n\n@[simp] lemma differentiable_within_at_pi :\n  differentiable_within_at 𝕜 Φ s x ↔\n   ∀ i, differentiable_within_at 𝕜 (λ x, Φ x i) s x :=\n⟨λ h i, (has_fderiv_within_at_pi'.1 h.has_fderiv_within_at i).differentiable_within_at,\n  λ h, (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).differentiable_within_at⟩\n\n@[simp] lemma differentiable_at_pi :\n  differentiable_at 𝕜 Φ x ↔ ∀ i, differentiable_at 𝕜 (λ x, Φ x i) x :=\n⟨λ h i, (has_fderiv_at_pi'.1 h.has_fderiv_at i).differentiable_at,\n  λ h, (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).differentiable_at⟩\n\nlemma differentiable_on_pi :\n  differentiable_on 𝕜 Φ s ↔ ∀ i, differentiable_on 𝕜 (λ x, Φ x i) s :=\n⟨λ h i x hx, differentiable_within_at_pi.1 (h x hx) i,\n  λ h x hx, differentiable_within_at_pi.2 (λ i, h i x hx)⟩\n\nlemma differentiable_pi :\n  differentiable 𝕜 Φ ↔ ∀ i, differentiable 𝕜 (λ x, Φ x i) :=\n⟨λ h i x, differentiable_at_pi.1 (h x) i, λ h x, differentiable_at_pi.2 (λ i, h i x)⟩\n\n-- TODO: find out which version (`φ` or `Φ`) works better with `rw`/`simp`\nlemma fderiv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (φ i) s x)\n  (hs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (λ x i, φ i x) s x = pi (λ i, fderiv_within 𝕜 (φ i) s x) :=\n(has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).fderiv_within hs\n\nlemma fderiv_pi (h : ∀ i, differentiable_at 𝕜 (φ i) x) :\n  fderiv 𝕜 (λ x i, φ i x) x = pi (λ i, fderiv 𝕜 (φ i) x) :=\n(has_fderiv_at_pi.2 (λ 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 (λ x, -f x) (-f') x :=\n(-1 : F →L[𝕜] 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 (λ x, -f x) (-f') x L :=\n(-1 : F →L[𝕜] F).has_fderiv_at_filter.comp x h tendsto_map\n\ntheorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) :\n  has_fderiv_within_at (λ 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 (λ x, -f x) (-f') x :=\nh.neg\n\nlemma differentiable_within_at.neg (h : differentiable_within_at 𝕜 f s x) :\n  differentiable_within_at 𝕜 (λy, -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 𝕜 (λy, -f y) s x ↔ differentiable_within_at 𝕜 f s x :=\n⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩\n\nlemma differentiable_at.neg (h : differentiable_at 𝕜 f x) :\n  differentiable_at 𝕜 (λy, -f y) x :=\nh.has_fderiv_at.neg.differentiable_at\n\n@[simp] lemma differentiable_at_neg_iff :\n  differentiable_at 𝕜 (λy, -f y) x ↔ differentiable_at 𝕜 f x :=\n⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩\n\nlemma differentiable_on.neg (h : differentiable_on 𝕜 f s) :\n  differentiable_on 𝕜 (λy, -f y) s :=\nλx hx, (h x hx).neg\n\n@[simp] lemma differentiable_on_neg_iff :\n  differentiable_on 𝕜 (λy, -f y) s ↔ differentiable_on 𝕜 f s :=\n⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩\n\nlemma differentiable.neg (h : differentiable 𝕜 f) :\n  differentiable 𝕜 (λy, -f y) :=\nλx, (h x).neg\n\n@[simp] lemma differentiable_neg_iff : differentiable 𝕜 (λy, -f y) ↔ differentiable 𝕜 f :=\n⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩\n\nlemma fderiv_within_neg (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (λy, -f y) s x = - fderiv_within 𝕜 f s x :=\nif h : differentiable_within_at 𝕜 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 𝕜 (λy, -f y) x = - fderiv 𝕜 f x :=\nby simp only [← 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 (λ 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 (λ 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 (λ 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 (λ x, f x - g x) (f' - g') x :=\nhf.sub hg\n\nlemma differentiable_within_at.sub\n  (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :\n  differentiable_within_at 𝕜 (λ 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 𝕜 f x) (hg : differentiable_at 𝕜 g x) :\n  differentiable_at 𝕜 (λ 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 𝕜 f s) (hg : differentiable_on 𝕜 g s) :\n  differentiable_on 𝕜 (λy, f y - g y) s :=\nλx hx, (hf x hx).sub (hg x hx)\n\n@[simp] lemma differentiable.sub\n  (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) :\n  differentiable 𝕜 (λy, f y - g y) :=\nλx, (hf x).sub (hg x)\n\nlemma fderiv_within_sub (hxs : unique_diff_within_at 𝕜 s x)\n  (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :\n  fderiv_within 𝕜 (λy, f y - g y) s x = fderiv_within 𝕜 f s x - fderiv_within 𝕜 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 𝕜 f x) (hg : differentiable_at 𝕜 g x) :\n  fderiv 𝕜 (λy, f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 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 (λ 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 (λ 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 (λ 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 (λ x, f x - c) f' x :=\nhf.sub_const c\n\nlemma differentiable_within_at.sub_const\n  (hf : differentiable_within_at 𝕜 f s x) (c : F) :\n  differentiable_within_at 𝕜 (λ 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 𝕜 (λ y, f y - c) s x ↔ differentiable_within_at 𝕜 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 𝕜 f x) (c : F) :\n  differentiable_at 𝕜 (λ 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 𝕜 (λ y, f y - c) x ↔ differentiable_at 𝕜 f x :=\nby simp only [sub_eq_add_neg, differentiable_at_add_const_iff]\n\nlemma differentiable_on.sub_const (hf : differentiable_on 𝕜 f s) (c : F) :\n  differentiable_on 𝕜 (λy, f y - c) s :=\nλx hx, (hf x hx).sub_const c\n\n@[simp] lemma differentiable_on_sub_const_iff (c : F) :\n  differentiable_on 𝕜 (λ y, f y - c) s ↔ differentiable_on 𝕜 f s :=\nby simp only [sub_eq_add_neg, differentiable_on_add_const_iff]\n\nlemma differentiable.sub_const (hf : differentiable 𝕜 f) (c : F) :\n  differentiable 𝕜 (λy, f y - c) :=\nλx, (hf x).sub_const c\n\n@[simp] lemma differentiable_sub_const_iff (c : F) :\n  differentiable 𝕜 (λ y, f y - c) ↔ differentiable 𝕜 f :=\nby simp only [sub_eq_add_neg, differentiable_add_const_iff]\n\nlemma fderiv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) :\n  fderiv_within 𝕜 (λy, f y - c) s x = fderiv_within 𝕜 f s x :=\nby simp only [sub_eq_add_neg, fderiv_within_add_const hxs]\n\nlemma fderiv_sub_const (c : F) : fderiv 𝕜 (λy, f y - c) x = fderiv 𝕜 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 (λ 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 (λ 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 (λ 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 (λ x, c - f x) (-f') x :=\nhf.const_sub c\n\nlemma differentiable_within_at.const_sub\n  (hf : differentiable_within_at 𝕜 f s x) (c : F) :\n  differentiable_within_at 𝕜 (λ 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 𝕜 (λ y, c - f y) s x ↔ differentiable_within_at 𝕜 f s x :=\nby simp [sub_eq_add_neg]\n\nlemma differentiable_at.const_sub\n  (hf : differentiable_at 𝕜 f x) (c : F) :\n  differentiable_at 𝕜 (λ 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 𝕜 (λ y, c - f y) x ↔ differentiable_at 𝕜 f x :=\nby simp [sub_eq_add_neg]\n\nlemma differentiable_on.const_sub (hf : differentiable_on 𝕜 f s) (c : F) :\n  differentiable_on 𝕜 (λy, c - f y) s :=\nλx hx, (hf x hx).const_sub c\n\n@[simp] lemma differentiable_on_const_sub_iff (c : F) :\n  differentiable_on 𝕜 (λ y, c - f y) s ↔ differentiable_on 𝕜 f s :=\nby simp [sub_eq_add_neg]\n\nlemma differentiable.const_sub (hf : differentiable 𝕜 f) (c : F) :\n  differentiable 𝕜 (λy, c - f y) :=\nλx, (hf x).const_sub c\n\n@[simp] lemma differentiable_const_sub_iff (c : F) :\n  differentiable 𝕜 (λ y, c - f y) ↔ differentiable 𝕜 f :=\nby simp [sub_eq_add_neg]\n\nlemma fderiv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) :\n  fderiv_within 𝕜 (λy, c - f y) s x = -fderiv_within 𝕜 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 𝕜 (λy, c - f y) x = -fderiv 𝕜 f x :=\nby simp only [← 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 × F → G} {u : set (E × F)}\n\nopen normed_field\n\nlemma is_bounded_bilinear_map.has_strict_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :\n  has_strict_fderiv_at b (h.deriv p) p :=\nbegin\n  rw has_strict_fderiv_at,\n  set T := (E × F) × (E × F),\n  have : (λ q : T, b (q.1 - q.2)) =o[𝓝 (p, p)] (λ q : T, ‖q.1 - q.2‖ * 1),\n  { refine (h.is_O'.comp_tendsto le_top).trans_is_o _,\n    simp only [(∘)],\n    refine (is_O_refl (λ q : T, ‖q.1 - q.2‖) _).mul_is_o (is_o.norm_left $ (is_o_one_iff _).2 _),\n    rw [← 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 (λ q : T, h.deriv (p - q.2) (q.1 - q.2)) =o[𝓝 (p, p)] (λ q : T, q.1 - q.2),\n  { ext ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩⟩, rcases p with ⟨x, y⟩,\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 : (λ q : T, p - q.2) =o[𝓝 (p, p)] (λ q, (1:ℝ)),\n    from (is_o_one_iff _).2 (sub_self p ▸ 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 ⊤).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 𝕜 b) (p : E × 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 𝕜 b) (p : E × 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 𝕜 b) (p : E × F) :\n  differentiable_at 𝕜 b p :=\n(h.has_fderiv_at p).differentiable_at\n\nlemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map 𝕜 b)\n  (p : E × F) :\n  differentiable_within_at 𝕜 b u p :=\n(h.differentiable_at p).differentiable_within_at\n\nlemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) :\n  fderiv 𝕜 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 𝕜 b) (p : E × F)\n  (hxs : unique_diff_within_at 𝕜 u p) : fderiv_within 𝕜 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 𝕜 b) :\n  differentiable 𝕜 b :=\nλx, h.differentiable_at x\n\nlemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map 𝕜 b) :\n  differentiable_on 𝕜 b u :=\nh.differentiable.differentiable_on\n\nvariable (B : E →L[𝕜] F →L[𝕜] G)\n\nlemma continuous_linear_map.has_fderiv_within_at_of_bilinear\n  {f : G' → E} {g : G' → F} {f' : G' →L[𝕜] E} {g' : G' →L[𝕜] F} {x : G'} {s : set G'}\n  (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) :\n  has_fderiv_within_at (λ y, B (f y) (g y)) (B.precompR G' (f x) g' + B.precompL G' f' (g x)) s x :=\n(B.is_bounded_bilinear_map.has_fderiv_at (f x, g x)).comp_has_fderiv_within_at x (hf.prod hg)\n\nlemma continuous_linear_map.has_fderiv_at_of_bilinear\n  {f : G' → E} {g : G' → F} {f' : G' →L[𝕜] E} {g' : G' →L[𝕜] F} {x : G'}\n  (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) :\n  has_fderiv_at (λ y, B (f y) (g y)) (B.precompR G' (f x) g' + B.precompL G' f' (g x)) x :=\n(B.is_bounded_bilinear_map.has_fderiv_at (f x, g x)).comp x (hf.prod hg)\n\nlemma continuous_linear_map.fderiv_within_of_bilinear\n  {f : G' → E} {g : G' → F} {x : G'} {s : set G'}\n  (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x)\n  (hs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (λ y, B (f y) (g y)) s x =\n    (B.precompR G' (f x) (fderiv_within 𝕜 g s x) + B.precompL G' (fderiv_within 𝕜 f s x) (g x)) :=\n(B.has_fderiv_within_at_of_bilinear hf.has_fderiv_within_at hg.has_fderiv_within_at).fderiv_within\n  hs\n\nlemma continuous_linear_map.fderiv_of_bilinear {f : G' → E} {g : G' → F} {x : G'}\n  (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :\n  fderiv 𝕜 (λ y, B (f y) (g y)) x =\n    (B.precompR G' (f x) (fderiv 𝕜 g x) + B.precompL G' (fderiv 𝕜 f x) (g x)) :=\n(B.has_fderiv_at_of_bilinear hf.has_fderiv_at hg.has_fderiv_at).fderiv\n\nend bilinear_map\n\nsection clm_comp_apply\n/-! ### Derivative of the pointwise composition/application of continuous linear maps -/\n\nvariables {H : Type*} [normed_add_comm_group H] [normed_space 𝕜 H] {c : E → G →L[𝕜] H}\n  {c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G}\n  {u' : E →L[𝕜] G}\n\nlemma has_strict_fderiv_at.clm_comp (hc : has_strict_fderiv_at c c' x)\n  (hd : has_strict_fderiv_at d d' x) : has_strict_fderiv_at (λ y, (c y).comp (d y))\n  ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x :=\n(is_bounded_bilinear_map_comp.has_strict_fderiv_at (c x, d x)).comp x $ hc.prod hd\n\nlemma has_fderiv_within_at.clm_comp (hc : has_fderiv_within_at c c' s x)\n  (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, (c y).comp (d y))\n  ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x :=\n(is_bounded_bilinear_map_comp.has_fderiv_at (c x, d x)).comp_has_fderiv_within_at x $ hc.prod hd\n\nlemma has_fderiv_at.clm_comp (hc : has_fderiv_at c c' x)\n  (hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, (c y).comp (d y))\n  ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x :=\n(is_bounded_bilinear_map_comp.has_fderiv_at (c x, d x)).comp x $ hc.prod hd\n\nlemma differentiable_within_at.clm_comp\n  (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :\n  differentiable_within_at 𝕜 (λ y, (c y).comp (d y)) s x :=\n(hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).differentiable_within_at\n\nlemma differentiable_at.clm_comp (hc : differentiable_at 𝕜 c x)\n  (hd : differentiable_at 𝕜 d x) : differentiable_at 𝕜 (λ y, (c y).comp (d y)) x :=\n(hc.has_fderiv_at.clm_comp hd.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.clm_comp (hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) :\n  differentiable_on 𝕜 (λ y, (c y).comp (d y)) s :=\nλx hx, (hc x hx).clm_comp (hd x hx)\n\nlemma differentiable.clm_comp (hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) :\n  differentiable 𝕜 (λ y, (c y).comp (d y)) :=\nλx, (hc x).clm_comp (hd x)\n\nlemma fderiv_within_clm_comp (hxs : unique_diff_within_at 𝕜 s x)\n  (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :\n  fderiv_within 𝕜 (λ y, (c y).comp (d y)) s x =\n    (compL 𝕜 F G H (c x)).comp (fderiv_within 𝕜 d s x) +\n    ((compL 𝕜 F G H).flip (d x)).comp (fderiv_within 𝕜 c s x) :=\n(hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :\n  fderiv 𝕜 (λ y, (c y).comp (d y)) x =\n    (compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) +\n    ((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) :=\n(hc.has_fderiv_at.clm_comp hd.has_fderiv_at).fderiv\n\nlemma has_strict_fderiv_at.clm_apply (hc : has_strict_fderiv_at c c' x)\n  (hu : has_strict_fderiv_at u u' x) :\n  has_strict_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x :=\n(is_bounded_bilinear_map_apply.has_strict_fderiv_at (c x, u x)).comp x (hc.prod hu)\n\nlemma has_fderiv_within_at.clm_apply (hc : has_fderiv_within_at c c' s x)\n  (hu : has_fderiv_within_at u u' s x) :\n  has_fderiv_within_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x :=\n(is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp_has_fderiv_within_at x (hc.prod hu)\n\nlemma has_fderiv_at.clm_apply (hc : has_fderiv_at c c' x) (hu : has_fderiv_at u u' x) :\n  has_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x :=\n(is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp x (hc.prod hu)\n\nlemma differentiable_within_at.clm_apply\n  (hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) :\n  differentiable_within_at 𝕜 (λ y, (c y) (u y)) s x :=\n(hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).differentiable_within_at\n\nlemma differentiable_at.clm_apply (hc : differentiable_at 𝕜 c x)\n  (hu : differentiable_at 𝕜 u x) : differentiable_at 𝕜 (λ y, (c y) (u y)) x :=\n(hc.has_fderiv_at.clm_apply hu.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.clm_apply (hc : differentiable_on 𝕜 c s) (hu : differentiable_on 𝕜 u s) :\n  differentiable_on 𝕜 (λ y, (c y) (u y)) s :=\nλx hx, (hc x hx).clm_apply (hu x hx)\n\nlemma differentiable.clm_apply (hc : differentiable 𝕜 c) (hu : differentiable 𝕜 u) :\n  differentiable 𝕜 (λ y, (c y) (u y)) :=\nλx, (hc x).clm_apply (hu x)\n\nlemma fderiv_within_clm_apply (hxs : unique_diff_within_at 𝕜 s x)\n  (hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) :\n  fderiv_within 𝕜 (λ y, (c y) (u y)) s x =\n    ((c x).comp (fderiv_within 𝕜 u s x) + (fderiv_within 𝕜 c s x).flip (u x)) :=\n(hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) :\n  fderiv 𝕜 (λ y, (c y) (u y)) x = ((c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x)) :=\n(hc.has_fderiv_at.clm_apply hu.has_fderiv_at).fderiv\n\nend clm_comp_apply\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 `λ x, c x • 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 → ℂ` and `f : E → F` provided that `F` is a complex\nnormed vector space.\n-/\n\nvariables {𝕜' : Type*} [nontrivially_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']\n  [normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F]\nvariables {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'}\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 (λ y, c y • f y) (c x • 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 (λ y, c y • f y) (c x • 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 (λ y, c y • f y) (c x • 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 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :\n  differentiable_within_at 𝕜 (λ y, c y • 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 𝕜 c x) (hf : differentiable_at 𝕜 f x) :\n  differentiable_at 𝕜 (λ y, c y • f y) x :=\n(hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.smul (hc : differentiable_on 𝕜 c s) (hf : differentiable_on 𝕜 f s) :\n  differentiable_on 𝕜 (λ y, c y • f y) s :=\nλx hx, (hc x hx).smul (hf x hx)\n\n@[simp] lemma differentiable.smul (hc : differentiable 𝕜 c) (hf : differentiable 𝕜 f) :\n  differentiable 𝕜 (λ y, c y • f y) :=\nλx, (hc x).smul (hf x)\n\nlemma fderiv_within_smul (hxs : unique_diff_within_at 𝕜 s x)\n  (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :\n  fderiv_within 𝕜 (λ y, c y • f y) s x =\n    c x • fderiv_within 𝕜 f s x + (fderiv_within 𝕜 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 𝕜 c x) (hf : differentiable_at 𝕜 f x) :\n  fderiv 𝕜 (λ y, c y • f y) x =\n    c x • fderiv 𝕜 f x + (fderiv 𝕜 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 (λ y, c y • 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 (λ y, c y • 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 (λ y, c y • 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 𝕜 c s x) (f : F) :\n  differentiable_within_at 𝕜 (λ y, c y • f) s x :=\n(hc.has_fderiv_within_at.smul_const f).differentiable_within_at\n\nlemma differentiable_at.smul_const (hc : differentiable_at 𝕜 c x) (f : F) :\n  differentiable_at 𝕜 (λ y, c y • f) x :=\n(hc.has_fderiv_at.smul_const f).differentiable_at\n\nlemma differentiable_on.smul_const (hc : differentiable_on 𝕜 c s) (f : F) :\n  differentiable_on 𝕜 (λ y, c y • f) s :=\nλx hx, (hc x hx).smul_const f\n\nlemma differentiable.smul_const (hc : differentiable 𝕜 c) (f : F) :\n  differentiable 𝕜 (λ y, c y • f) :=\nλx, (hc x).smul_const f\n\nlemma fderiv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)\n  (hc : differentiable_within_at 𝕜 c s x) (f : F) :\n  fderiv_within 𝕜 (λ y, c y • f) s x =\n    (fderiv_within 𝕜 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 𝕜 c x) (f : F) :\n  fderiv 𝕜 (λ y, c y • f) x = (fderiv 𝕜 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 functions -/\n\nvariables {𝔸 𝔸' : Type*} [normed_ring 𝔸] [normed_comm_ring 𝔸'] [normed_algebra 𝕜 𝔸]\n  [normed_algebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'}\n\ntheorem has_strict_fderiv_at.mul' {x : E} (ha : has_strict_fderiv_at a a' x)\n  (hb : has_strict_fderiv_at b b' x) :\n  has_strict_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x :=\n((continuous_linear_map.mul 𝕜 𝔸).is_bounded_bilinear_map.has_strict_fderiv_at (a x, b x)).comp x\n  (ha.prod hb)\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 (λ y, c y * d y) (c x • d' + d x • c') x :=\nby { convert hc.mul' hd, ext z, apply mul_comm }\n\ntheorem has_fderiv_within_at.mul'\n  (ha : has_fderiv_within_at a a' s x) (hb : has_fderiv_within_at b b' s x) :\n  has_fderiv_within_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) s x :=\n((continuous_linear_map.mul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at\n  (a x, b x)).comp_has_fderiv_within_at x (ha.prod hb)\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 (λ y, c y * d y) (c x • d' + d x • c') s x :=\nby { convert hc.mul' hd, ext z, apply mul_comm }\n\ntheorem has_fderiv_at.mul'\n  (ha : has_fderiv_at a a' x) (hb : has_fderiv_at b b' x) :\n  has_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x :=\n((continuous_linear_map.mul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp x\n  (ha.prod hb)\n\ntheorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) :\n  has_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x :=\nby { convert hc.mul' hd, ext z, apply mul_comm }\n\nlemma differentiable_within_at.mul\n  (ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) :\n  differentiable_within_at 𝕜 (λ y, a y * b y) s x :=\n(ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).differentiable_within_at\n\n@[simp] lemma differentiable_at.mul (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) :\n  differentiable_at 𝕜 (λ y, a y * b y) x :=\n(ha.has_fderiv_at.mul' hb.has_fderiv_at).differentiable_at\n\nlemma differentiable_on.mul (ha : differentiable_on 𝕜 a s) (hb : differentiable_on 𝕜 b s) :\n  differentiable_on 𝕜 (λ y, a y * b y) s :=\nλx hx, (ha x hx).mul (hb x hx)\n\n@[simp] lemma differentiable.mul (ha : differentiable 𝕜 a) (hb : differentiable 𝕜 b) :\n  differentiable 𝕜 (λ y, a y * b y) :=\nλx, (ha x).mul (hb x)\n\nlemma differentiable_within_at.pow (ha : differentiable_within_at 𝕜 a s x) :\n  ∀ n : ℕ, differentiable_within_at 𝕜 (λ x, a x ^ n) s x\n| 0 := by simp only [pow_zero, differentiable_within_at_const]\n| (n + 1) := by simp only [pow_succ, differentiable_within_at.pow n, ha.mul]\n\n@[simp] lemma differentiable_at.pow (ha : differentiable_at 𝕜 a x) (n : ℕ) :\n  differentiable_at 𝕜 (λ x, a x ^ n) x :=\ndifferentiable_within_at_univ.mp $ ha.differentiable_within_at.pow n\n\nlemma differentiable_on.pow (ha : differentiable_on 𝕜 a s) (n : ℕ) :\n  differentiable_on 𝕜 (λ x, a x ^ n) s :=\nλ x h, (ha x h).pow n\n\n@[simp] lemma differentiable.pow (ha : differentiable 𝕜 a) (n : ℕ) :\n  differentiable 𝕜 (λ x, a x ^ n) :=\nλx, (ha x).pow n\n\nlemma fderiv_within_mul' (hxs : unique_diff_within_at 𝕜 s x)\n  (ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) :\n  fderiv_within 𝕜 (λ y, a y * b y) s x =\n    a x • fderiv_within 𝕜 b s x + (fderiv_within 𝕜 a s x).smul_right (b x) :=\n(ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_within_mul (hxs : unique_diff_within_at 𝕜 s x)\n  (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :\n  fderiv_within 𝕜 (λ y, c y * d y) s x =\n    c x • fderiv_within 𝕜 d s x + d x • fderiv_within 𝕜 c s x :=\n(hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs\n\nlemma fderiv_mul' (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) :\n  fderiv 𝕜 (λ y, a y * b y) x =\n    a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smul_right (b x) :=\n(ha.has_fderiv_at.mul' hb.has_fderiv_at).fderiv\n\nlemma fderiv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :\n  fderiv 𝕜 (λ y, c y * d y) x =\n    c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x :=\n(hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv\n\ntheorem has_strict_fderiv_at.mul_const' (ha : has_strict_fderiv_at a a' x) (b : 𝔸) :\n  has_strict_fderiv_at (λ y, a y * b) (a'.smul_right b) x :=\n(((continuous_linear_map.mul 𝕜 𝔸).flip b).has_strict_fderiv_at).comp x ha\n\ntheorem has_strict_fderiv_at.mul_const (hc : has_strict_fderiv_at c c' x) (d : 𝔸') :\n  has_strict_fderiv_at (λ y, c y * d) (d • c') x :=\nby { convert hc.mul_const' d, ext z, apply mul_comm }\n\ntheorem has_fderiv_within_at.mul_const' (ha : has_fderiv_within_at a a' s x) (b : 𝔸) :\n  has_fderiv_within_at (λ y, a y * b) (a'.smul_right b) s x :=\n(((continuous_linear_map.mul 𝕜 𝔸).flip b).has_fderiv_at).comp_has_fderiv_within_at x ha\n\ntheorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : 𝔸') :\n  has_fderiv_within_at (λ y, c y * d) (d • c') s x :=\nby { convert hc.mul_const' d, ext z, apply mul_comm }\n\ntheorem has_fderiv_at.mul_const' (ha : has_fderiv_at a a' x) (b : 𝔸) :\n  has_fderiv_at (λ y, a y * b) (a'.smul_right b) x :=\n(((continuous_linear_map.mul 𝕜 𝔸).flip b).has_fderiv_at).comp x ha\n\ntheorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : 𝔸') :\n  has_fderiv_at (λ y, c y * d) (d • c') x :=\nby { convert hc.mul_const' d, ext z, apply mul_comm }\n\nlemma differentiable_within_at.mul_const\n  (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :\n  differentiable_within_at 𝕜 (λ y, a y * b) s x :=\n(ha.has_fderiv_within_at.mul_const' b).differentiable_within_at\n\nlemma differentiable_at.mul_const (ha : differentiable_at 𝕜 a x) (b : 𝔸) :\n  differentiable_at 𝕜 (λ y, a y * b) x :=\n(ha.has_fderiv_at.mul_const' b).differentiable_at\n\nlemma differentiable_on.mul_const (ha : differentiable_on 𝕜 a s) (b : 𝔸) :\n  differentiable_on 𝕜 (λ y, a y * b) s :=\nλx hx, (ha x hx).mul_const b\n\nlemma differentiable.mul_const (ha : differentiable 𝕜 a) (b : 𝔸) :\n  differentiable 𝕜 (λ y, a y * b) :=\nλx, (ha x).mul_const b\n\nlemma fderiv_within_mul_const' (hxs : unique_diff_within_at 𝕜 s x)\n  (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :\n  fderiv_within 𝕜 (λ y, a y * b) s x = (fderiv_within 𝕜 a s x).smul_right b :=\n(ha.has_fderiv_within_at.mul_const' b).fderiv_within hxs\n\nlemma fderiv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)\n  (hc : differentiable_within_at 𝕜 c s x) (d : 𝔸') :\n  fderiv_within 𝕜 (λ y, c y * d) s x = d • fderiv_within 𝕜 c s x :=\n(hc.has_fderiv_within_at.mul_const d).fderiv_within hxs\n\nlemma fderiv_mul_const' (ha : differentiable_at 𝕜 a x) (b : 𝔸) :\n  fderiv 𝕜 (λ y, a y * b) x = (fderiv 𝕜 a x).smul_right b :=\n(ha.has_fderiv_at.mul_const' b).fderiv\n\nlemma fderiv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸') :\n  fderiv 𝕜 (λ y, c y * d) x = d • fderiv 𝕜 c x :=\n(hc.has_fderiv_at.mul_const d).fderiv\n\ntheorem has_strict_fderiv_at.const_mul (ha : has_strict_fderiv_at a a' x) (b : 𝔸) :\n  has_strict_fderiv_at (λ y, b * a y) (b • a') x :=\n(((continuous_linear_map.mul 𝕜 𝔸) b).has_strict_fderiv_at).comp x ha\n\ntheorem has_fderiv_within_at.const_mul\n  (ha : has_fderiv_within_at a a' s x) (b : 𝔸) :\n  has_fderiv_within_at (λ y, b * a y) (b • a') s x :=\n(((continuous_linear_map.mul 𝕜 𝔸) b).has_fderiv_at).comp_has_fderiv_within_at x ha\n\ntheorem has_fderiv_at.const_mul (ha : has_fderiv_at a a' x) (b : 𝔸) :\n  has_fderiv_at (λ y, b * a y) (b • a') x :=\n(((continuous_linear_map.mul 𝕜 𝔸) b).has_fderiv_at).comp x ha\n\nlemma differentiable_within_at.const_mul\n  (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :\n  differentiable_within_at 𝕜 (λ y, b * a y) s x :=\n(ha.has_fderiv_within_at.const_mul b).differentiable_within_at\n\nlemma differentiable_at.const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) :\n  differentiable_at 𝕜 (λ y, b * a y) x :=\n(ha.has_fderiv_at.const_mul b).differentiable_at\n\nlemma differentiable_on.const_mul (ha : differentiable_on 𝕜 a s) (b : 𝔸) :\n  differentiable_on 𝕜 (λ y, b * a y) s :=\nλx hx, (ha x hx).const_mul b\n\nlemma differentiable.const_mul (ha : differentiable 𝕜 a) (b : 𝔸) :\n  differentiable 𝕜 (λ y, b * a y) :=\nλx, (ha x).const_mul b\n\nlemma fderiv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)\n  (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) :\n  fderiv_within 𝕜 (λ y, b * a y) s x = b • fderiv_within 𝕜 a s x :=\n(ha.has_fderiv_within_at.const_mul b).fderiv_within hxs\n\nlemma fderiv_const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) :\n  fderiv 𝕜 (λ y, b * a y) x = b • fderiv 𝕜 a x :=\n(ha.has_fderiv_at.const_mul b).fderiv\n\nend mul\n\nsection algebra_inverse\nvariables {R : Type*} [normed_ring R] [normed_algebra 𝕜 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échet derivative of the inversion\noperation is the linear map `λ t, - x⁻¹ * t * x⁻¹`. -/\nlemma has_fderiv_at_ring_inverse (x : Rˣ) :\n  has_fderiv_at ring.inverse (-mul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹) x :=\nbegin\n  have h_is_o : (λ (t : R), inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) =o[𝓝 0] (λ (t : R), t),\n  { refine (inverse_add_norm_diff_second_order x).trans_is_o ((is_o_norm_norm).mp _),\n    simp only [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 (λ (y:R), y - x) (𝓝 x) (𝓝 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, mul_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 : Rˣ) : differentiable_at 𝕜 (@ring.inverse R _) x :=\n(has_fderiv_at_ring_inverse x).differentiable_at\n\nlemma fderiv_inverse (x : Rˣ) :\n  fderiv 𝕜 (@ring.inverse R _) x = - mul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹ :=\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 ≃L[𝕜] F)\n\nprotected lemma has_strict_fderiv_at :\n  has_strict_fderiv_at iso (iso : E →L[𝕜] 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 →L[𝕜] F) s x :=\niso.to_continuous_linear_map.has_fderiv_within_at\n\nprotected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x :=\niso.to_continuous_linear_map.has_fderiv_at_filter\n\nprotected lemma differentiable_at : differentiable_at 𝕜 iso x :=\niso.has_fderiv_at.differentiable_at\n\nprotected lemma differentiable_within_at :\n  differentiable_within_at 𝕜 iso s x :=\niso.differentiable_at.differentiable_within_at\n\nprotected lemma fderiv : fderiv 𝕜 iso x = iso :=\niso.has_fderiv_at.fderiv\n\nprotected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 iso s x = iso :=\niso.to_continuous_linear_map.fderiv_within hxs\n\nprotected lemma differentiable : differentiable 𝕜 iso :=\nλx, iso.differentiable_at\n\nprotected lemma differentiable_on : differentiable_on 𝕜 iso s :=\niso.differentiable.differentiable_on\n\nlemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} :\n  differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x :=\nbegin\n  refine ⟨λ H, _, λ H, iso.differentiable.differentiable_at.comp_differentiable_within_at x H⟩,\n  have : differentiable_within_at 𝕜 (iso.symm ∘ (iso ∘ f)) s x :=\n    iso.symm.differentiable.differentiable_at.comp_differentiable_within_at x H,\n  rwa [← function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this,\nend\n\nlemma comp_differentiable_at_iff {f : G → E} {x : G} :\n  differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x :=\nby rw [← differentiable_within_at_univ, ← differentiable_within_at_univ,\n       iso.comp_differentiable_within_at_iff]\n\nlemma comp_differentiable_on_iff {f : G → E} {s : set G} :\n  differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 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 → E} :\n  differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f :=\nbegin\n  rw [← differentiable_on_univ, ← differentiable_on_univ],\n  exact iso.comp_differentiable_on_iff\nend\n\nlemma comp_has_fderiv_within_at_iff\n  {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} :\n  has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x :=\nbegin\n  refine ⟨λ H, _, λ H, iso.has_fderiv_at.comp_has_fderiv_within_at x H⟩,\n  have A : f = iso.symm ∘ (iso ∘ f), by { rw [← function.comp.assoc, iso.symm_comp_self], refl },\n  have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f'),\n    by rw [← 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 → E} {x : G} {f' : G →L[𝕜] E} :\n  has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x :=\nbegin\n  refine ⟨λ H, _, λ H, iso.has_strict_fderiv_at.comp x H⟩,\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 → E} {x : G} {f' : G →L[𝕜] E} :\n  has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x :=\nby simp_rw [← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff]\n\nlemma comp_has_fderiv_within_at_iff'\n  {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} :\n  has_fderiv_within_at (iso ∘ f) f' s x ↔\n  has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x :=\nby rw [← iso.comp_has_fderiv_within_at_iff, ← 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 → E} {x : G} {f' : G →L[𝕜] F} :\n  has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x :=\nby simp_rw [← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff']\n\nlemma comp_fderiv_within {f : G → E} {s : set G} {x : G}\n  (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) :=\nbegin\n  by_cases h : differentiable_within_at 𝕜 f s x,\n  { rw [fderiv.comp_fderiv_within x iso.differentiable_at h hxs, iso.fderiv] },\n  { have : ¬differentiable_within_at 𝕜 (iso ∘ 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 → E} {x : G} :\n  fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=\nbegin\n  rw [← fderiv_within_univ, ← fderiv_within_univ],\n  exact iso.comp_fderiv_within unique_diff_within_at_univ,\nend\n\nlemma comp_right_differentiable_within_at_iff {f : F → G} {s : set F} {x : E} :\n  differentiable_within_at 𝕜 (f ∘ iso) (iso ⁻¹' s) x ↔ differentiable_within_at 𝕜 f s (iso x) :=\nbegin\n  refine ⟨λ H, _, λ H, H.comp x iso.differentiable_within_at (maps_to_preimage _ s)⟩,\n  have : differentiable_within_at 𝕜 ((f ∘ iso) ∘ iso.symm) s (iso x),\n  { rw ← iso.symm_apply_apply x at H,\n    apply H.comp (iso x) iso.symm.differentiable_within_at,\n    assume y hy,\n    simpa only [mem_preimage, apply_symm_apply] using hy },\n  rwa [function.comp.assoc, iso.self_comp_symm] at this,\nend\n\nlemma comp_right_differentiable_at_iff {f : F → G} {x : E} :\n  differentiable_at 𝕜 (f ∘ iso) x ↔ differentiable_at 𝕜 f (iso x) :=\nby simp only [← differentiable_within_at_univ, ← iso.comp_right_differentiable_within_at_iff,\n  preimage_univ]\n\nlemma comp_right_differentiable_on_iff {f : F → G} {s : set F} :\n  differentiable_on 𝕜 (f ∘ iso) (iso ⁻¹' s) ↔ differentiable_on 𝕜 f s :=\nbegin\n  refine ⟨λ H y hy, _, λ H y hy, iso.comp_right_differentiable_within_at_iff.2 (H _ hy)⟩,\n  rw [← iso.apply_symm_apply y, ← comp_right_differentiable_within_at_iff],\n  apply H,\n  simpa only [mem_preimage, apply_symm_apply] using hy,\nend\n\nlemma comp_right_differentiable_iff {f : F → G} :\n  differentiable 𝕜 (f ∘ iso) ↔ differentiable 𝕜 f :=\nby simp only [← differentiable_on_univ, ← iso.comp_right_differentiable_on_iff, preimage_univ]\n\nlemma comp_right_has_fderiv_within_at_iff\n  {f : F → G} {s : set F} {x : E} {f' : F →L[𝕜] G} :\n  has_fderiv_within_at (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) (iso ⁻¹' s) x ↔\n    has_fderiv_within_at f f' s (iso x) :=\nbegin\n  refine ⟨λ H, _, λ H, H.comp x iso.has_fderiv_within_at (maps_to_preimage _ s)⟩,\n  rw [← iso.symm_apply_apply x] at H,\n  have A : f = (f ∘ iso) ∘ iso.symm, by { rw [function.comp.assoc, iso.self_comp_symm], refl },\n  have B : f' =  (f'.comp (iso : E →L[𝕜] F)).comp (iso.symm : F →L[𝕜] E),\n    by rw [continuous_linear_map.comp_assoc, iso.coe_comp_coe_symm,\n             continuous_linear_map.comp_id],\n  rw [A, B],\n  apply H.comp (iso x) iso.symm.has_fderiv_within_at,\n  assume y hy,\n  simpa only [mem_preimage, apply_symm_apply] using hy\nend\n\nlemma comp_right_has_fderiv_at_iff {f : F → G} {x : E} {f' : F →L[𝕜] G} :\n  has_fderiv_at (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) x ↔ has_fderiv_at f f' (iso x) :=\nby simp only [← has_fderiv_within_at_univ, ← comp_right_has_fderiv_within_at_iff, preimage_univ]\n\nlemma comp_right_has_fderiv_within_at_iff'\n  {f : F → G} {s : set F} {x : E} {f' : E →L[𝕜] G} :\n  has_fderiv_within_at (f ∘ iso) f' (iso ⁻¹' s) x ↔\n  has_fderiv_within_at f (f'.comp (iso.symm : F →L[𝕜] E)) s (iso x) :=\nby rw [← iso.comp_right_has_fderiv_within_at_iff, continuous_linear_map.comp_assoc,\n    iso.coe_symm_comp_coe, continuous_linear_map.comp_id]\n\nlemma comp_right_has_fderiv_at_iff' {f : F → G} {x : E} {f' : E →L[𝕜] G} :\n  has_fderiv_at (f ∘ iso) f' x ↔ has_fderiv_at f (f'.comp (iso.symm : F →L[𝕜] E)) (iso x) :=\nby simp only [← has_fderiv_within_at_univ, ← iso.comp_right_has_fderiv_within_at_iff',\n  preimage_univ]\n\nlemma comp_right_fderiv_within {f : F → G} {s : set F} {x : E}\n  (hxs : unique_diff_within_at 𝕜 (iso ⁻¹' s) x) :\n  fderiv_within 𝕜 (f ∘ iso) (iso ⁻¹'s) x = (fderiv_within 𝕜 f s (iso x)).comp (iso : E →L[𝕜] F) :=\nbegin\n  by_cases h : differentiable_within_at 𝕜 f s (iso x),\n  { exact (iso.comp_right_has_fderiv_within_at_iff.2 (h.has_fderiv_within_at)).fderiv_within hxs },\n  { have : ¬ differentiable_within_at 𝕜 (f ∘ iso) (iso ⁻¹' s) x,\n    { assume h', exact h (iso.comp_right_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, continuous_linear_map.zero_comp] }\nend\n\nlemma comp_right_fderiv {f : F → G} {x : E} :\n  fderiv 𝕜 (f ∘ iso) x = (fderiv 𝕜 f (iso x)).comp (iso : E →L[𝕜] F) :=\nbegin\n  rw [← fderiv_within_univ, ← fderiv_within_univ, ← iso.comp_right_fderiv_within, preimage_univ],\n  exact 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 ≃ₗᵢ[𝕜] F)\n\nprotected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x :=\n(iso : E ≃L[𝕜] F).has_strict_fderiv_at\n\nprotected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x :=\n(iso : E ≃L[𝕜] F).has_fderiv_within_at\n\nprotected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x :=\n(iso : E ≃L[𝕜] F).has_fderiv_at\n\nprotected lemma differentiable_at : differentiable_at 𝕜 iso x :=\niso.has_fderiv_at.differentiable_at\n\nprotected lemma differentiable_within_at :\n  differentiable_within_at 𝕜 iso s x :=\niso.differentiable_at.differentiable_within_at\n\nprotected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv\n\nprotected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 iso s x = iso :=\n(iso : E ≃L[𝕜] F).fderiv_within hxs\n\nprotected lemma differentiable : differentiable 𝕜 iso :=\nλx, iso.differentiable_at\n\nprotected lemma differentiable_on : differentiable_on 𝕜 iso s :=\niso.differentiable.differentiable_on\n\nlemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} :\n  differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x :=\n(iso : E ≃L[𝕜] F).comp_differentiable_within_at_iff\n\nlemma comp_differentiable_at_iff {f : G → E} {x : G} :\n  differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x :=\n(iso : E ≃L[𝕜] F).comp_differentiable_at_iff\n\nlemma comp_differentiable_on_iff {f : G → E} {s : set G} :\n  differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s :=\n(iso : E ≃L[𝕜] F).comp_differentiable_on_iff\n\nlemma comp_differentiable_iff {f : G → E} :\n  differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f :=\n(iso : E ≃L[𝕜] F).comp_differentiable_iff\n\nlemma comp_has_fderiv_within_at_iff\n  {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} :\n  has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x :=\n(iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff\n\nlemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :\n  has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x :=\n(iso : E ≃L[𝕜] F).comp_has_strict_fderiv_at_iff\n\nlemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :\n  has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x :=\n(iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff\n\nlemma comp_has_fderiv_within_at_iff'\n  {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} :\n  has_fderiv_within_at (iso ∘ f) f' s x ↔\n  has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x :=\n(iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff'\n\nlemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :\n  has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x :=\n(iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff'\n\nlemma comp_fderiv_within {f : G → E} {s : set G} {x : G}\n  (hxs : unique_diff_within_at 𝕜 s x) :\n  fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) :=\n(iso : E ≃L[𝕜] F).comp_fderiv_within hxs\n\nlemma comp_fderiv {f : G → E} {x : G} :\n  fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) :=\n(iso : E ≃L[𝕜] 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'⁻¹` 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 → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}\n  (hg : continuous_at g a) (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) (g a))\n  (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :\n  has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) a :=\nbegin\n  replace hg := hg.prod_map' hg,\n  replace hfg := hfg.prod_mk_nhds hfg,\n  have : (λ p : F × F, g p.1 - g p.2 - f'.symm (p.1 - p.2)) =O[𝓝 (a, a)]\n    (λ p : F × F, f' (g p.1 - g p.2) - (p.1 - p.2)),\n  { refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, 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 $ λ _, rfl)).trans_is_O _,\n  { rintros p ⟨hp1, hp2⟩,\n    simp [hp1, hp2] },\n  { refine (hf.is_O_sub_rev.comp_tendsto hg).congr'\n      (eventually_of_forall $ λ _, rfl) (hfg.mono _),\n    rintros p ⟨hp1, hp2⟩,\n    simp only [(∘), 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'⁻¹` 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 → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F}\n  (hg : continuous_at g a) (hf : has_fderiv_at f (f' : E →L[𝕜] F) (g a))\n  (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) :\n  has_fderiv_at g (f'.symm : F →L[𝕜] E) a :=\nbegin\n  have : (λ x : F, g x - g a - f'.symm (x - a)) =O[𝓝 a] (λ x : F, f' (g x - g a) - (x - a)),\n  { refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, 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 $ λ _, rfl)).trans_is_O _,\n  { rintros p hp,\n    simp [hp, hfg.self_of_nhds] },\n  { refine ((hf.is_O_sub_rev f'.antilipschitz).comp_tendsto hg).congr'\n      (eventually_of_forall $ λ _, rfl) (hfg.mono _),\n    rintros p hp,\n    simp only [(∘), 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'⁻¹` 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 ≃L[𝕜] F} {a : F}\n  (ha : a ∈ f.target) (htff' : has_strict_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) :\n  has_strict_fderiv_at f.symm (f'.symm : F →L[𝕜] 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'⁻¹` 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 ≃L[𝕜] F} {a : F}\n  (ha : a ∈ f.target) (htff' : has_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) :\n  has_fderiv_at f.symm (f'.symm : F →L[𝕜] 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' : ∃ C, ∀ z, ‖z‖ ≤ C * ‖f' z‖) :\n  ∀ᶠ z in 𝓝[s \\ {x}] x, f z ≠ f x :=\nbegin\n  rw [nhds_within, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal],\n  have A : (λ z, z - x) =O[𝓝[s] x] (λ z, f' (z - x)) :=\n    (is_O_iff.2 $ hf'.imp $ λ C hC, eventually_of_forall $ λ z, hC _),\n  have : (λ z, f z - f x) ~[𝓝[s] x] (λ 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' : ∃ C, ∀ z, ‖z‖ ≤ C * ‖f' z‖) :\n  ∀ᶠ z in 𝓝[≠] x, f z ≠ 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échet derivative.\n-/\n\n\nvariables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E]\nvariables {F : Type*} [normed_add_comm_group F] [normed_space ℝ F]\nvariables {f : E → F} {f' : E →L[ℝ] F} {x : E}\n\ntheorem has_fderiv_at_filter_real_equiv {L : filter E} :\n  tendsto (λ x' : E, ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) ↔\n  tendsto (λ x' : E, ‖x' - x‖⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) :=\nbegin\n  symmetry,\n  rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (λ x', _),\n  have : ‖x' - x‖⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _),\n  simp [norm_smul, abs_of_nonneg this]\nend\n\nlemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) :\n  tendsto (λ (c:ℝ), c • (f (x + c⁻¹ • v) - f x)) at_top (𝓝 (f' v)) :=\nbegin\n  apply hf.lim v,\n  rw tendsto_at_top_at_top,\n  exact λ b, ⟨b, λ a ha, le_trans ha (le_abs_self _)⟩\nend\n\nend\n\nsection tangent_cone\n\nvariables {𝕜 : Type*} [nontrivially_normed_field 𝕜]\n{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]\n{F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]\n{f : E → F} {s : set E} {f' : E →L[𝕜] 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 𝕜 s x) (tangent_cone_at 𝕜 (f '' s) (f x)) :=\nbegin\n  rintros v ⟨c, d, dtop, clim, cdlim⟩,\n  refine ⟨c, (λn, f (x + d n) - f x), mem_of_superset dtop _, clim,\n    h.lim at_top dtop clim cdlim⟩,\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 𝕜 s x) (h' : dense_range f') :\n  unique_diff_within_at 𝕜 (f '' s) (f x) :=\nbegin\n  refine ⟨h'.dense_of_maps_to f'.continuous hs.1 _,\n    h.continuous_within_at.mem_closure_image hs.2⟩,\n  show submodule.span 𝕜 (tangent_cone_at 𝕜 s x) ≤\n    (submodule.span 𝕜 (tangent_cone_at 𝕜 (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 → E →L[𝕜] F} (hs : unique_diff_on 𝕜 s)\n  (hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hd : ∀ x ∈ s, dense_range (f' x)) :\n  unique_diff_on 𝕜 (f '' s) :=\nball_image_iff.2 $ λ 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 ≃L[𝕜] F) (h : has_fderiv_within_at f (e' : E →L[𝕜] F) s x)\n  (hs : unique_diff_within_at 𝕜 s x) :\n  unique_diff_within_at 𝕜 (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 ≃L[𝕜] F) (h : unique_diff_on 𝕜 s) :\n  unique_diff_on 𝕜 (e '' s) :=\nh.image (λ x _, e.has_fderiv_within_at) (λ x hx, e.surjective.dense_range)\n\n@[simp] lemma continuous_linear_equiv.unique_diff_on_image_iff (e : E ≃L[𝕜] F) :\n  unique_diff_on 𝕜 (e '' s) ↔ unique_diff_on 𝕜 s :=\n⟨λ h, e.symm_image_image s ▸ e.symm.unique_diff_on_image h, e.unique_diff_on_image⟩\n\n@[simp] lemma continuous_linear_equiv.unique_diff_on_preimage_iff (e : F ≃L[𝕜] E) :\n  unique_diff_on 𝕜 (e ⁻¹' s) ↔ unique_diff_on 𝕜 s :=\nby rw [← e.image_symm_eq_preimage, e.symm.unique_diff_on_image_iff]\n\nend tangent_cone\n\nsection restrict_scalars\n/-!\n### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜`\n\nIf a function is differentiable over `ℂ`, then it is differentiable over `ℝ`. In this paragraph,\nwe give variants of this statement, in the general situation where `ℂ` and `ℝ` are replaced\nrespectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra over `𝕜`.\n-/\n\nvariables (𝕜 : Type*) [nontrivially_normed_field 𝕜]\nvariables {𝕜' : Type*} [nontrivially_normed_field 𝕜'] [normed_algebra 𝕜 𝕜']\nvariables {E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] [normed_space 𝕜' E]\nvariables [is_scalar_tower 𝕜 𝕜' E]\nvariables {F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F] [normed_space 𝕜' F]\nvariables [is_scalar_tower 𝕜 𝕜' F]\nvariables {f : E → F} {f' : E →L[𝕜'] 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 𝕜) x := h\n\nlemma has_fderiv_at_filter.restrict_scalars {L} (h : has_fderiv_at_filter f f' x L) :\n  has_fderiv_at_filter f (f'.restrict_scalars 𝕜) x L := h\n\nlemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) :\n  has_fderiv_at f (f'.restrict_scalars 𝕜) 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 𝕜) s x := h\n\nlemma differentiable_at.restrict_scalars (h : differentiable_at 𝕜' f x) :\n  differentiable_at 𝕜 f x :=\n(h.has_fderiv_at.restrict_scalars 𝕜).differentiable_at\n\nlemma differentiable_within_at.restrict_scalars (h : differentiable_within_at 𝕜' f s x) :\n  differentiable_within_at 𝕜 f s x :=\n(h.has_fderiv_within_at.restrict_scalars 𝕜).differentiable_within_at\n\nlemma differentiable_on.restrict_scalars (h : differentiable_on 𝕜' f s) :\n  differentiable_on 𝕜 f s :=\nλx hx, (h x hx).restrict_scalars 𝕜\n\nlemma differentiable.restrict_scalars (h : differentiable 𝕜' f) :\n  differentiable 𝕜 f :=\nλx, (h x).restrict_scalars 𝕜\n\nlemma has_fderiv_within_at_of_restrict_scalars\n  {g' : E →L[𝕜] F} (h : has_fderiv_within_at f g' s x)\n  (H : f'.restrict_scalars 𝕜 = g') : has_fderiv_within_at f f' s x :=\nby { rw ← H at h, exact h }\n\nlemma has_fderiv_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_at f g' x)\n  (H : f'.restrict_scalars 𝕜 = g') : has_fderiv_at f f' x :=\nby { rw ← H at h, exact h }\n\nlemma differentiable_at.fderiv_restrict_scalars (h : differentiable_at 𝕜' f x) :\n  fderiv 𝕜 f x = (fderiv 𝕜' f x).restrict_scalars 𝕜 :=\n(h.has_fderiv_at.restrict_scalars 𝕜).fderiv\n\nlemma differentiable_within_at_iff_restrict_scalars\n  (hf : differentiable_within_at 𝕜 f s x) (hs : unique_diff_within_at 𝕜 s x) :\n  differentiable_within_at 𝕜' f s x ↔\n  ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv_within 𝕜 f s x :=\nbegin\n  split,\n  { rintros ⟨g', hg'⟩,\n    exact ⟨g', hs.eq (hg'.restrict_scalars 𝕜) hf.has_fderiv_within_at⟩, },\n  { rintros ⟨f', hf'⟩,\n    exact ⟨f', has_fderiv_within_at_of_restrict_scalars 𝕜 hf.has_fderiv_within_at hf'⟩, },\nend\n\nlemma differentiable_at_iff_restrict_scalars (hf : differentiable_at 𝕜 f x) :\n  differentiable_at 𝕜' f x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv 𝕜 f x :=\nbegin\n  rw [← differentiable_within_at_univ, ← fderiv_within_univ],\n  exact differentiable_within_at_iff_restrict_scalars 𝕜\n    hf.differentiable_within_at unique_diff_within_at_univ,\nend\n\nend restrict_scalars\n\n/-! ### Support of derivatives -/\n\nsection support\n\nopen function\nvariables (𝕜 : Type*) {E F : Type*} [nontrivially_normed_field 𝕜] [normed_add_comm_group E]\n  [normed_space 𝕜 E] [normed_add_comm_group F] [normed_space 𝕜 F] {f : E → F}\n\nlemma support_fderiv_subset : support (fderiv 𝕜 f) ⊆ tsupport f :=\nbegin\n  intros x,\n  rw [← not_imp_not],\n  intro h2x,\n  rw [not_mem_tsupport_iff_eventually_eq] at h2x,\n  exact nmem_support.mpr (h2x.fderiv_eq.trans $ fderiv_const_apply 0),\nend\n\nlemma has_compact_support.fderiv (hf : has_compact_support f) : has_compact_support (fderiv 𝕜 f) :=\nhf.mono' $ support_fderiv_subset 𝕜\n\nend support\n", "meta": {"author": "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.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266013, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7504336262569696}}
{"text": "/- El segundo módulo de este minicurso trata de los \nnúmeros naturales. Es decir, ahora vamos a tratar con\nobjetos matemáticos más concretos, no sólo con proposiciones\nlógicas -/\n\n/- Empezamos definiendo a los números naturales. Existen varias\nformas de definir los números naturales, en Lean y en este \nminicurso usaremos los axiomas de Peano. -/\n\n/- En esta hoja vamos a importar unas definiciones de Mathlib.\nEstas no las vamos a ocupar hasta al final, pero las incluímos\nal principio porque Lean requiere que todas las importaciones \nocurran al principio de la hoja. -/\nimport algebra.big_operators.intervals\n\n/- Definimos nuestro propio espacio de nombres para trabajar \ncon nuestras propias definiciones: -/\nnamespace smf22\n\n/- Ahora definimos un número natural según los axiomas de Peano: -/\ninductive natural\n| cero : natural -- El número cero (`0`) en un número natural\n| suc (n : natural) : natural -- Si `n` es un número natural, \n                              -- su sucesor también.\n\n/- Hemos definido la estructura de forma inductiva: tenemos un caso base, \ncero, que dice que `cero` es un numero natural, y luego tenemos el caso \ninductivo, `suc` (de sucesor), que dice que si `n` es un número natural,\ntambién su sucesor es un número natural.  El sucesor de un número \nnatural `n` es `n + 1`.\n\nLean tiene una forma generalizada de inducción ya incluída. Al decir\n`inductive` para definir un objecto matemático, Lean entiende dos cosas:\n - La definición no es circular, es inductiva\n - Lean genera un principio de inducción para estos objetos.\n\nPeano originalmente tenía mucho otros axiomas, como\nque todo natural es igual a sí mismo, ` ∀ x : natural, x = x`.\nEstos axiomas ya los tenemos por la base lógica en Lean y no hace\nfalta repetirlos para definir los números naturales.\n -/\n\n /- Podemos definir el número 1, por ejemplo: -/\ndef uno := natural.suc natural.cero\n\n/- Lean ocupa un punto `.` para acceder a los nombres definidos.\nCómo vamos a estar trabajando con los números naturales, es muy\ntedioso tener que escribir `natural.suc` cada vez; en vez, \nle decimos a Lean que \"abra las definiciones, para que no tengamos\nque escribir `natural` cada vez.  \"-/\nopen natural\n\n/- y podemos definir dos -/\ndef dos := suc (suc cero)\n\n/- Demostramos que 1 + 1 = 2. -/\nexample : suc uno = dos := \nbegin\n  refl -- por definición\nend\n\n/- Por el momento no hemos definido la suma, interpretamos al \nsucesor como `+ 1`, pero no está realmente definido. Es más, \nes al revez: definimos la suma usando al sucesor. -/\n\ndef suma : natural → natural → natural\n| a  cero     := a\n| a  (suc b) := suc (suma a b)\n\n\n#check suma uno uno\n\n/- Con esta definición, para escribir la suma de dos números\n`a` y `b`, tendríamos que escribir `suma a b`. Esto se puede \nvolver tedioso rápidamente. Afortunadamente, Lean nos permite definir\nnuestra propia notación para evitar esta confusion y tedio.\n-/\n\ninfix ` + `:60 := suma \n\n/- Lean dice `infix` porque el símbolo `+` va entre sus argumentos,\nno como sufijo o prefixo. El 60 es la \"precedencia\" del operador, \nsirve para desambiguar expresiones como 2 ⬝ 3 + 5, que podrían \nsignificar (2 ⬝ 3) + 5 ó 2 ⬝ (3 + 5). Por convención, lo \ninterpretamos como la primera opción, pero a Lean hay que \nenseñarle esta convención también! -/\n\n#check uno + uno -- ahora podemos escribirlo así\n\n/- Regresamos a nuestro \"teorema\": 1 + 1 = 2 -/\ntheorem uno_mas_uno : uno + uno = dos :=\nbegin\n  unfold uno, -- cual es la definición de uno?\n  unfold dos, -- cual es la definición de dos?\n  unfold suma, -- cual es la definición de la suma?\nend\n\ntheorem uno_mas_uno' : uno + uno = dos :=\nbegin\n  refl, -- Sigue siendo verdadero por definición\nend\n\n-- Vamos a trabajar con un par de variables (numeros naturales)\nvariables (l m n : natural)\n\n/- Igual, por definición, n + 0 = n. \nCuando es un solo paso, podemos decir `by` en vez de\nusar `begin` y `end`.  -/\ntheorem suma_cero : n + cero = n := by refl \n \n/- Ahora que pasa con lo opuesto (`cero + n = n`)?\nEsto no funciona por definición.  Cual es la diferencia entre estos dos? \nDe hecho, la única forma de demostrarlo es por inducción!\n-/\ntheorem cero_suma : cero + n = n :=\nbegin\n induction n with n hi,\n -- caso base (cero)\n {\n   refl,\n },\n {\n   unfold suma, --definición de suma\n   rw hi, --hipótesis de inducción\n }\nend\n\n/- Muy similar al caso con cero, como hemos visto,\n `suc n` es `n + 1`, por definición. Que pasa con `1 + n`? -/\ntheorem n_mas_uno : suc n = n + uno := by refl\n\n/- Un pequeño ejercicio: -/\ntheorem uno_mas_n : uno + n = suc n := \nbegin\n  sorry,\nend\n\n/- un ejericico un poco más interesante: -/\ntheorem suma_asociativa : (l + m) + n = l + (m + n)  :=\nbegin \n sorry,\nend\n\n/- Que tal si hacemos el caso más general, n + m = m + n? -/\ntheorem suma_conmutativa : n + m = m + n := \nbegin\n  induction n with n hi,\n  {\n    rw cero_suma,\n    rw suma_cero,\n  },\n  {\n    rw ← uno_mas_n,\n    rw ← (suma_asociativa m uno n),\n    rw ← n_mas_uno,\n    rw ← uno_mas_n,\n    rw suma_asociativa,\n    rw suma_asociativa,\n    rw hi,\n  }\nend\n\n/- Este lemma claramente es consecuencia de la distributividad\ny asociatividad de la suma, sin embargo resulta ser útil tenerlo\n aparte. -/\nlemma suma_izq_conm : n + (m + l) = m + (n + l) :=\nbegin\n  induction n with n hi,\n  {\n    rw cero_suma,\n    rw cero_suma,\n  },\n  {\n    rw ← suma_asociativa,\n    rw suma_asociativa,\n    rw suma_conmutativa,\n    rw suma_asociativa,\n    rw (suma_conmutativa (suc n) l),\n  }\nend\n/- En este último caso tuvimos que decirle a Lean que \nnumeros usar para aplicar la conmutatividad, lo cual podemos hacer\ndandole los argumentos explicitamente y poniendo todo en parentesis,\n como hicimos aquí. -/\n\n/- Vemos como podemos empezar a construir la teoría de los números \nnaturales en base a los axiomas de Peano. Vamos al siguiente paso:\ncomo definiríamos la multiplicación? -/\n\ndef mul : natural → natural → natural\n| m cero := cero\n| m (suc n) := mul m n + m\n\n/- definimos la multipliciación. Podemos usar ambos, `⬝` ó `*`. -/\ninfix ` * `:70 := mul \ninfix ` ⬝ `:70 := mul \n\n-- a la derecha otra vez es por definición\ntheorem mul_cero : n * cero = cero := by refl\n\n/- para la demostración por la izquierda necesitamos \nahora saber algo de la suma también! -/\ntheorem cero_mul : cero * n = cero := \nbegin\n induction n,\n refl,\n unfold mul,\n rw suma_cero,\n exact n_ih,\nend\n\n/- El siguiente objetivo aquí será demostrar la asociatividad y\n comutatividad de la muliplicación, así como la ley distributiva.\n Esto lleva mucho tiempo.  -/\n\nlemma suc_mul : (suc n) * m = (n * m) + m :=\nbegin\n  induction m with m hi,\n  refl,\n  unfold mul,\n  rw hi,\n  rw n_mas_uno,\n  rw suma_asociativa,\n  rw (suma_conmutativa (n + uno) m),\n  rw suma_asociativa,\n  rw (uno_mas_n m),\n  rw suma_asociativa,\nend\n\n-- La otra dirección es trivial por definición!\nlemma mul_suc : n * suc m = n * m + n := by refl\n\n/- Con esto podemos demostrar las leyes distributivas\n   para relacional la suma y la multiplicación:\n-/\ntheorem distrib_izq : n * (m + l) = n * m + n * l :=\nbegin\ninduction n with n hi,\n{\n  simp [cero_mul], -- que pasa si en vez hacemos rw cero_mul?\n  refl,\n},\n{\n  simp [suc_mul],\n  rw hi,\n  simp [suma_asociativa, suma_conmutativa, suma_izq_conm],\n}\nend\n\ntheorem distrib_der : (n + m) * l = n * l + m * l :=\nbegin \n  induction l with l hi,\n  refl,\n  {\n  simp [mul_suc, hi],\n  simp [suma_asociativa, suma_conmutativa, suma_izq_conm],\n  }\nend\n\ntheorem mul_asociativa  : (n * m) * l = n * (m * l) :=\nbegin\n  induction l with l hi,\n  refl,\n  simp [mul_suc, distrib_izq, hi],\nend\n\n/- La tarea: demuestre que la multiplicaicón es conmutativa! -/\ntheorem mul_conmutativa : n * m = m * n :=\nbegin\n  sorry,\nend\n\n/- Hasta aquí hemos ido construyendo la teoría de los números naturales\npaso a paso. Sin embargo, Lean ya la conoce, por supuesto! Vamos a cerrar\nnuestro espacio de nombres extra y ver como funciona esto -/\nend smf22\n\ninfix ` + `:60 := nat.add \n\n#check nat\n/- Para demostrar un poco como Lean puede ser mas poderoso, \ndemostraremos una propiedad de los numeros pares usando\nun poco mas de automatización -/\ntheorem producto_par : ∀ m n : ℕ, even n → even (m * n) :=\nbegin\n  intros m n hpar,\n  unfold even at hpar, -- cual es la definición de par?\n  /- En la hoja de lógica no vimos cuantificadores, pero no es muy \n  complejo. Si tenemos la existencia de un objeto con una propiedad,\n  podemos separarla igual que en los otros casos usando `cases`: -/\n  cases hpar with k hk, \n  use (m * k), -- demostramos la existencia explicitamente\n  rw hk,\n  ring, -- lean tiene tacticas mas poderosas, como `ring`\nend", "meta": {"author": "goens", "repo": "smf-ues-2022", "sha": "d0122da8b17aef50361c59e3ebcb6fd8f4b45ad1", "save_path": "github-repos/lean/goens-smf-ues-2022", "path": "github-repos/lean/goens-smf-ues-2022/smf-ues-2022-d0122da8b17aef50361c59e3ebcb6fd8f4b45ad1/src/numeros_naturales.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8333245891029456, "lm_q1q2_score": 0.7504336162162746}}
{"text": "import algebra.group.basic\n\nnamespace group.basic\n\ntheorem mul_mul_mul_eq_one_iff {G : Type*} [group G]: ∀ {x y z : G}, x*y*z = 1 ↔ y*z*x = 1 :=\nbegin\n  intros x y z,\n  conv_lhs \n  { rw [← mul_right_inj (x⁻¹), ← mul_assoc,\n    ← mul_assoc, inv_mul_self, one_mul,\n    mul_one, ← mul_left_inj x, inv_mul_self] }\nend\n\ntheorem mul_mul_mul_eq_one_iff' {G : Type*} [group G]: ∀ (x y z : G), x*y*z = 1 ↔ z*x*y = 1 :=\nbegin\n  intros x y z,\n  conv_lhs \n  { rw [mul_mul_mul_eq_one_iff,\n    ← mul_right_inj (y⁻¹), ← mul_assoc,\n    ← mul_assoc, inv_mul_self, one_mul,\n    mul_one, ← mul_left_inj y, inv_mul_self] },\nend\n\nend group.basic", "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/group_extras.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107949104868, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7504171877628185}}
{"text": "import tactic\nimport binary\nimport hamming\n\n/-!\n# Binary Codes\n\nThis file contains the definition of a binary code \nand several theorems relating to properties of binary codes.\n\n## Main Results\n\n- `s_error_detecting_iff_min_distance_gt_s` : \n  A code C is s-error-detecting if and only if d(C) > s.\n- `t_error_correcting_iff_min_distance_gte` :\n  A code C is t-error-correcting if and only if d(C) ≥ 2t + 1.\n- `hamming_bound` : \n  Establishes a bound on the number of codewords in an error-correcting code.\n\n## Notation\n\n- `|C|` for the number of codewords in a code `C`.\n- `d(C)` for the minimum distance of a codeword `C`.\n-/\n\nopen B BW\n\ndef min_distance {n : ℕ} (C : finset (BW n)) (h : C.card ≥ 2) : ℕ :=\nfinset.min' (finset.image (λ (x : BW n × BW n), d(x.fst, x.snd)) C.off_diag)\nbegin\n  have : ∃ (x y : BW n), x ∈ C ∧ y ∈ C ∧ x ≠ y, \n  from finset.one_lt_card_iff.mp h,\n  simp, rw finset.nonempty, simp,\n  rcases this with ⟨x, y, ⟨hx, hy, hxy⟩⟩,\n  existsi [x, hx, y, hy],\n  exact hxy,\nend\n\nstructure binary_code (n M d : ℕ) :=\n  (cws : finset (BW n))\n  (has_card_M : cws.card = M)\n  (card_gte : cws.card ≥ 2)\n  (has_min_distance_d : min_distance cws card_gte = d)\n\nnamespace binary_code\n\ninstance : Π {n m d : ℕ}, has_mem (BW n) (binary_code n m d) :=\nλ n m d, ⟨λ (x : BW n), λ (C : binary_code n m d), x ∈ C.cws⟩\n\nnotation `|` C `|` := C.cws.card\n\nnotation `d(` C `)` := min_distance C.cws C.card_gte\n\nvariables {n M d : ℕ} {C : binary_code n M d}\n\nlemma dist_neq_codewords_gte_min_distance:\n  ∀ (c₁ c₂ ∈ C), c₁ ≠ c₂ → d(C) ≤ d(c₁,c₂):=\nbegin\n  intros c₁ c₂ hc₁ hc₂ hneq,\n  unfold min_distance,\n  apply finset.min'_le,\n  simp,\n  existsi [c₁, c₂],\n  exact ⟨⟨hc₁, hc₂, hneq⟩, rfl⟩,\nend\n\nlemma min_distance_pair : ∃ (c₁ c₂ ∈ C), c₁ ≠ c₂ ∧ d(c₁,c₂) = d(C) :=\nbegin\n  have h_mem : d(C) ∈ (finset.image (λ (x : BW n × BW n), d(x.fst, x.snd)) C.cws.off_diag),\n  by {rw min_distance, apply finset.min'_mem},\n  simp at h_mem,\n  rcases h_mem with ⟨x, y, ⟨hx, hy, hneq⟩, h_dist⟩,\n  existsi [x, y, hx, hy],\n  exact ⟨hneq, h_dist⟩,\nend\n\n/--\nA code C is s-error-detecting if, \nwhenever a codeword has incurred at least one but at most s errors, \nthe resulting word is not a codeword.\n-/\ndef error_detecting (C : binary_code n M d) (s : ℕ) : Prop := \n∀ (x : BW n) (c ∈ C), (d(x,c) ≥ 1 ∧ d(x,c) ≤ s) → x ∉ C\n\ntheorem s_error_detecting_iff_min_distance_gt_s (s : ℕ) : \n  C.error_detecting s ↔ d(C) > s :=\nbegin\n  unfold error_detecting,\n  split,\n  -- Proof that d(C) ≤ s ⇒ not s-error-detecting.\n    {contrapose,\n    simp,\n    intro h_min_dist,\n    have : ∃ (c₁ c₂ ∈ C), c₁ ≠ c₂ ∧ d(c₁,c₂) = d(C), from min_distance_pair,\n    rcases this with ⟨x, y, hx, hy, ⟨hneq, h_dist_eq_min⟩⟩,\n    have h_lte_s : d(x,y) ≤ s, by linarith,\n    have h_gte_1 : d(x,y) ≥ 1, from (hamming.distance_neq_between_one_n x y hneq).left,\n    existsi [x, y],\n    exact ⟨hy, h_gte_1, h_lte_s, hx⟩,\n    },\n  -- Proof that d(C) > s ⇒ s-error-detecting \n    {intros h x c hc hdist,\n    intro hx,\n    by_cases heq : x = c,\n      {have h_dxc_eq_zero : d(x,c) = 0, from hamming.eq_distance_zero x c heq,\n      linarith},\n      {have : d(x,c) ≥ d(C), \n      from dist_neq_codewords_gte_min_distance x c hx hc heq,\n      linarith,}\n    },\nend\n\n/--\nA code C is t-error-correcting if the minimum distance\ndecoding rule can be used to correct t or fewer errors.\nThe minimum distance decoding rule will decode x to c ∈ C \nif the distance between x and c is smaller than the distance\nbetween x and any other codeword in C.\n-/\ndef error_correcting (C : binary_code n M d) (t : ℕ) : Prop := \n∀ (c ∈ C) (x : BW n), d(x,c) ≤ t → (∀ (c' ∈ C), c ≠ c' → d(x,c) < d(x,c'))\n\n/--\nGiven two words x and y, constructs a new word z\nby flipping the first t bits of x that disagree with y.\n-/\ndef change_t_disagreements : Π {n : ℕ}, ℕ → BW n → BW n → BW n\n| _ _     nil         nil       := nil\n| _ 0     (xhd::ᴮxtl) (_::ᴮytl) := xhd::ᴮxtl\n| _ t     (O::ᴮxtl)   (O::ᴮytl) :=   O::ᴮ(change_t_disagreements t xtl ytl)\n| _ t     (I::ᴮxtl)   (I::ᴮytl) :=   I::ᴮ(change_t_disagreements t xtl ytl)\n| _ (t+1) (O::ᴮxtl)   (I::ᴮytl) :=   I::ᴮ(change_t_disagreements t xtl ytl)\n| _ (t+1) (I::ᴮxtl)   (O::ᴮytl) :=   O::ᴮ(change_t_disagreements t xtl ytl)\n\nlemma dist_change_t_disagreements_first_arg : \n  Π {n : ℕ} (t : ℕ) (h₁ : 0 < t) (x y : BW n) (h₂ : t < d(x,y)), \n  d(x, change_t_disagreements t x y) = t\n| n t     h₁ nil         nil         h₂ := by {exfalso, simp at h₂, contradiction}\n| n 0     h₁ (xhd::ᴮxtl) (yhd::ᴮytl) h₂ := by {exfalso, simp at h₁, contradiction}\n| n (t+1) h₁ (xhd::ᴮxtl) (yhd::ᴮytl) h₂ := begin\n  cases xhd; cases yhd;\n    begin\n    rw change_t_disagreements, simp, simp at h₂,\n    apply dist_change_t_disagreements_first_arg (t+1) h₁ xtl ytl h₂,\n    end\n    <|>\n    begin\n    rw change_t_disagreements, simp,\n    rw ← nat.add_one, simp,\n    simp at h₂, have h₃ : t < d(xtl,ytl), from nat.lt_of_succ_lt_succ h₂,\n    cases t,\n      {simp, cases xtl with _ xhd xtl,\n        {rw nil_unique ytl, rw change_t_disagreements},\n      cases ytl with _ yhd ytl, cases xhd; cases yhd; rw change_t_disagreements,\n      },\n    have h₅ : 0 < t.succ, from nat.zero_lt_succ t,\n    apply dist_change_t_disagreements_first_arg (t+1) h₅ xtl ytl h₃,\n    end\nend\n\nlemma dist_change_t_disagreements_second_arg : \n  Π {n : ℕ} (t : ℕ) (x y : BW n), d(y, change_t_disagreements t x y) = d(x,y) - t \n| n t     nil         nil         := by {simp, cases t; rw change_t_disagreements}\n| n 0     (xhd::ᴮxtl) (yhd::ᴮytl) := begin\n  cases xhd; cases yhd; \n    {rw change_t_disagreements, simp, apply hamming.distance_symmetric}\nend\n| n (t+1) (xhd::ᴮxtl) (yhd::ᴮytl) := begin\n  cases xhd; cases yhd; \n    {rw change_t_disagreements, simp, apply dist_change_t_disagreements_second_arg}\nend\n\n/--\nForward direction of t-error-correting ⇔ d(C) ≥ 2t + 1.\nProof closely follows the structure of the proof given in accompanying report.\n-/\nlemma t_error_correcting_min_distance_gte (t : ℕ) :\n  C.error_correcting t → d(C) ≥ 2 * t + 1 :=\nbegin\n  -- Suppose that C is t-error-correcting.\n  intro h₁,\n  -- For the sake of contradiction, assume that d(C) < 2t + 1\n  by_contradiction h₂,\n  simp at h₂,\n  -- Then there exist distinct codewords c, c' ∈ C such that d(c, c') = d(C) \n  have h₃ : ∃ (c₁ c₂ ∈ C), c₁ ≠ c₂ ∧ d(c₁,c₂) = d(C),\n  from min_distance_pair,\n  rcases h₃ with ⟨c, c', hc, hc', ⟨hneq, h_dist_eq_min⟩⟩,\n  have h₄ : d(c,c') ≤ 2 * t, by linarith,\n  -- First, we establish via contradiction that t < d(c,c') < 2t.\n  have h₅ : d(c, c') ≥ t + 1, \n  by {\n    specialize h₁ c hc c',\n    by_contradiction h',\n    simp at h',\n    have h'' : d(c,c') ≤ t, from nat.le_of_lt_succ h',\n    rw hamming.distance_symmetric at h'',\n    specialize h₁ h'' c' hc' hneq,\n    have : d(c',c') = 0, from hamming.eq_distance_zero c' c' rfl,\n    rw this at h₁,\n    simp at h₁,\n    exact h₁,\n  },\n  -- Now, we construct a new word x by \n  -- flipping the first t bits of c that disagree with c'.\n  have h₆ : ∃ (x : BW n), 1 ≤ d(x,c') ∧ d(x,c') ≤ d(x,c) ∧ d(x,c) = t,\n  by {\n    use change_t_disagreements t c c',\n    have h_d₀ : 1 ≤ d(c,c') ∧ d(c,c') ≤ n, from hamming.distance_neq_between_one_n c c' hneq,\n    have h_d₁ : d(c, change_t_disagreements t c c') = t,\n    by {apply dist_change_t_disagreements_first_arg; linarith},\n    have h_d₂ : d(c', change_t_disagreements t c c') = d(c,c') - t,\n    by {apply dist_change_t_disagreements_second_arg},\n    rw [hamming.distance_symmetric _ c, hamming.distance_symmetric _ c'],\n    split,\n      {calc d(c',change_t_disagreements t c c') ≥ d(c,c') - t : by linarith\n      ...                                       ≥ t + 1 - t   : by exact nat.sub_le_sub_right h₅ t\n      ...                                       = 1           : by simp,},\n      split,\n      {rw [h_d₁, h_d₂], \n      apply nat.sub_le_left_iff_le_add.mpr,\n      conv {congr, skip, ring},\n      exact h₄,},\n      {linarith}\n  },\n  -- But the properties of this word contradict C being t-error-correcting.\n  -- Hence, d(C) ≥ 2t + 1.\n  rcases h₆ with ⟨x, ⟨h_dxgt1, h_dxc'_le_dxc, h_dxc_eq_t⟩⟩,\n  have h_dxc_le_t : d(x,c) ≤ t, by linarith,\n  specialize h₁ c hc x h_dxc_le_t c' hc' hneq,\n  linarith,\nend\n\n/--\nWe now present two proofs for\nthe backward direction of t-error-correting ⇔ d(C) ≥ 2t + 1.\nIn the second proof, we prove the contraposative and \nthe resulting proof is slightly simpler.\n-/\nlemma min_distance_gte_t_error_correcting' (t : ℕ) :\n  d(C) ≥ 2 * t + 1 → C.error_correcting t :=\nbegin\n  intro h,\n  intros c hc x h_dist_le_t c' hc' h_c_neq_c',\n  have h₁ : d(c,c') ≥ d(C), \n  from dist_neq_codewords_gte_min_distance c c' hc hc' h_c_neq_c',\n  have h₂ : d(c,c') ≥ 2 * t + 1, by linarith,\n  have h₃ : d(c,c') ≤ d(c,x) + d(x,c'), from hamming.distance_triangle_ineq c c' x,\n  calc d(x,c') ≥ d(c,c') - d(c,x)     : by {simp, exact nat.sub_le_left_of_le_add h₃}\n  ...          ≥ (2 * t + 1) - d(c,x) : by {simp, exact nat.sub_le_sub_right h₂ d(c,x)}\n  ...          ≥ (2 * t + 1) - t      : by {simp, rw hamming.distance_symmetric, \n                                            exact (2 * t + 1).sub_le_sub_left h_dist_le_t}\n  ...          = (t + t + 1) - t      : by ring\n  ...          = t + 1                : by {rw nat.add_assoc, simp}\n  ...          > d(x,c)               : by linarith,\nend\n\nlemma min_distance_gte_t_error_correcting (t : ℕ) :\n  d(C) ≥ 2 * t + 1 → C.error_correcting t :=\nbegin\n  contrapose, unfold error_correcting, simp, \n  intros c hc x hx c' hc' hneq hdist,\n  have h_x_c'_dist : d(x,c') ≤ t, by linarith,\n  calc d(C) ≤ d(c,c')          : dist_neq_codewords_gte_min_distance _ _ hc hc' hneq\n  ...       ≤ d(c,x) + d(x,c') : hamming.distance_triangle_ineq c c' x\n  ...       ≤ t + d(x,c')      : by {simp, rw hamming.distance_symmetric, exact hx,}\n  ...       ≤ t + t            : by {simp, exact h_x_c'_dist,}\n  ...       = 2 * t            : by ring\n  ...       < 2 * t + 1        : by simp,\nend\n\ntheorem t_error_correcting_iff_min_distance_gte (t : ℕ) :\n  C.error_correcting t ↔ d(C) ≥ 2 * t + 1 :=\niff.intro\n  (t_error_correcting_min_distance_gte t)\n  (min_distance_gte_t_error_correcting t)\n\nopen_locale big_operators\n\n/-! \nIn the remainder of this file, we build up a proof of the Hamming bound.\nWhen reading this code, it may actually be easier to start at the end and\nwork backwards, because the order of presentation goes from low-level\ndetails to high-level proofs.\n\nNote: Indices are numbered from 1.\n-/\n\n/-- The set {1,…,n} -/\ndef indices (n : ℕ) : finset ℕ := finset.erase (finset.range (n + 1)) 0\n\n@[simp]\nlemma indices_card_eq_word_size (n : ℕ) : (indices n).card = n :=\nby {rw [indices, finset.card_erase_of_mem], simp, simp}\n\n/-- Map a binary word x to a set of indices at which xᵢ ≠ 0 -/\ndef bw_to_nonzero_indices : Π {n : ℕ}, BW n → finset ℕ\n| 0 nil      := finset.empty\n| n (O::ᴮtl) := bw_to_nonzero_indices tl\n| n (I::ᴮtl) := insert n (bw_to_nonzero_indices tl)\n\nlemma mem_nonzero_indices_le_bw_size (x : BW n) (i : ℕ) : \n  i ∈ (bw_to_nonzero_indices x) → 1 ≤ i → i ≤ n :=\nbegin\n  intros h_mem h_gte_one, \n  induction x with k xhd xtl ih,\n    {rw bw_to_nonzero_indices at h_mem, \n    have : i ∉ finset.empty, from finset.not_mem_empty i, \n    contradiction},\n  cases xhd,\n    {rw bw_to_nonzero_indices at h_mem, specialize ih h_mem, linarith},\n    {rw bw_to_nonzero_indices at h_mem, \n    rw finset.mem_insert at h_mem, cases h_mem,\n      {rw h_mem},\n      {specialize ih h_mem, linarith},\n    }\nend\n\nlemma succ_not_mem_nonzero_indices (x : BW n) :\n  n.succ ∉ bw_to_nonzero_indices x :=\nbegin\n  by_contradiction h',\n  have h₀ : 1 ≤ n.succ, by {rw ← nat.add_one, linarith},\n  have h₁ : n.succ ≤ n, from mem_nonzero_indices_le_bw_size x n.succ h' h₀,\n  have h₂ : ¬ n.succ ≤ n, from nat.not_succ_le_self n,\n  contradiction\nend\n\n/--\nThe weight of a word x is the same as \nthe cardinality of the set of indices at which xᵢ ≠ 0.\n-/\nlemma weight_eq_card_nonzero_indices (x : BW n) :\n  wt(x) = (bw_to_nonzero_indices x).card :=\nbegin\n  induction n with k ih,\n    {rw nil_unique x, rw bw_to_nonzero_indices, rw hamming.weight, refl},\n  cases x with _ xhd xtl,\n  cases xhd,\n    {rw [hamming.weight, bw_to_nonzero_indices], apply ih},\n    {rw [hamming.weight, bw_to_nonzero_indices], \n    rw finset.card_insert_of_not_mem,\n      {rw nat.add_one, simp, apply ih},\n      {by_contradiction h, \n      have h₀ : 1 ≤ k.succ, by {rw ← nat.add_one, linarith},\n      have h₁ : k.succ ≤ k, from mem_nonzero_indices_le_bw_size xtl k.succ h h₀,\n      have h₂ : ¬ k.succ ≤ k, from nat.not_succ_le_self k,\n      contradiction,\n      }\n    }\nend\n\nlemma indices_subset_indices_succ (k : ℕ) : indices k ⊆ indices k.succ :=\nbegin\n  repeat {rw indices},\n  have h : finset.range (k + 1) ⊆ finset.range (k.succ + 1), by simp,\n  exact finset.erase_subset_erase 0 h,\nend\n\n/--\nGiven a word x\nthe set of indices at which xᵢ ≠ 0 is a subset of \nall indices of the word, i.e. the set {1,…,n}.\n-/\nlemma nonzero_indices_subset_indices (x : BW n) : \n (bw_to_nonzero_indices x) ⊆ (indices n) :=\nbegin\n  induction x with k xhd xtl ih,\n    {rw [bw_to_nonzero_indices, indices], refl},\n  cases xhd,\n    {rw bw_to_nonzero_indices, \n    have h : indices k ⊆ indices k.succ, from indices_subset_indices_succ k,\n    exact finset.subset.trans ih h},\n    {rw [bw_to_nonzero_indices, finset.insert_subset], split,\n      {rw indices, simp},\n    have h : indices k ⊆ indices k.succ, from indices_subset_indices_succ k,\n    exact finset.subset.trans ih h},\nend\n\n/--\nGiven a set representing some nonzero indices in a binary word,\nconstruct the unique binary word that produced this set of nonzero indices.\n-/\ndef nonzero_indices_to_bw : Π (n : ℕ), finset ℕ → BW n\n| 0     s := nil\n| (n+1) s :=\n  if (n + 1) ∈ s then\n    (I::ᴮnonzero_indices_to_bw n (s.erase (n + 1)))\n  else\n    (O::ᴮnonzero_indices_to_bw n s)\n\nlemma erase_last_index_subset {s : finset ℕ} : \n  s ⊆ indices (n + 1) → s.erase (n + 1) ⊆ indices n :=\nbegin\n  unfold indices,\n  intros h i hi,\n  specialize h (finset.mem_of_mem_erase hi),\n  rw finset.mem_erase at *,\n  split,\n    {exact h.left},\n    {rw finset.mem_range,\n    refine lt_of_le_of_ne _ hi.left,\n    rw ← finset.mem_range_succ_iff,\n    exact h.right}\nend\n\nlemma last_index_not_mem_subset {s : finset ℕ} : \n  s ⊆ indices (n + 1) → n + 1 ∉ s → s ⊆ indices n :=\nbegin\n  unfold indices,\n  intros h h' i hi,\n  specialize h hi,\n  rw finset.mem_erase at *,\n  split,\n    {exact h.left},\n    {rw finset.mem_range,\n    apply lt_of_le_of_ne,\n      {rw ← finset.mem_range_succ_iff, exact h.right},\n      {intro h, rw h at hi, exact h' hi}\n    }\nend\n\n\nlemma bw_to_nonzero_indices_inv_nonzero_indices_to_bw \n  (n : ℕ) (s : finset ℕ) (h : s ⊆ indices n) :\n  bw_to_nonzero_indices (nonzero_indices_to_bw n s) = s :=\nbegin\n  revert s,\n  induction n with n ih,\n    {intros s h, change ∅ = s, symmetry, rwa ← finset.subset_empty},\n  intros t h,\n  unfold nonzero_indices_to_bw,\n  split_ifs with h',\n    {specialize ih (t.erase (n + 1)) (erase_last_index_subset h),\n    unfold bw_to_nonzero_indices,\n    conv_rhs {rw [← finset.insert_erase h', ← ih]}},\n    {exact ih t (last_index_not_mem_subset h h')},\nend\n\nlemma all_nonzero_indices_eq_powerset_indices :\n  finset.image (λ v : BW n, bw_to_nonzero_indices v) finset.univ = \n  (indices n).powerset :=\nbegin\n  simp, ext,\n  split,\n    {simp, intros x h, rw ← h, exact nonzero_indices_subset_indices x},\n    {simp, intro h, use nonzero_indices_to_bw n a, \n    exact bw_to_nonzero_indices_inv_nonzero_indices_to_bw n a h},\nend\n\nlemma nonzero_indices_eq_powerset_len (w : ℕ) (h : w ≤ n) : \n  finset.filter (λ s : finset ℕ, s.card = w) \n    (finset.image (λ v : BW n, bw_to_nonzero_indices v) finset.univ)\n  = finset.powerset_len w (indices n) :=\nbegin\n  simp,\n  rw [finset.powerset_len_eq_filter, all_nonzero_indices_eq_powerset_indices],\nend\n\n/--\nIf the sets of nonzero indices of two binary words are equal,\nthen the binary words are equal.\n-/\nlemma eq_nonzero_indices_eq_words (a b : BW n) : \n  bw_to_nonzero_indices a = bw_to_nonzero_indices b → a = b :=\nbegin\n  intro h,\n  induction a with k ahd atl ih,\n    {rw nil_unique b},\n  cases b with _ bhd btl,\n  cases ahd,\n    {cases bhd,\n      {simp, exact ih btl h},\n      {simp, repeat {rw bw_to_nonzero_indices at h},\n      have h : k.succ ∉ bw_to_nonzero_indices atl, from succ_not_mem_nonzero_indices atl,\n      have h' : bw_to_nonzero_indices atl ≠ insert k.succ (bw_to_nonzero_indices btl),\n      from finset.ne_insert_of_not_mem _ _ h,\n      contradiction},\n    },\n    {cases bhd,\n      {simp, repeat {rw bw_to_nonzero_indices at h},\n      have h : k.succ ∉ bw_to_nonzero_indices btl, from succ_not_mem_nonzero_indices btl,\n      have h' : insert k.succ (bw_to_nonzero_indices atl) ≠ bw_to_nonzero_indices btl,\n      from (finset.ne_insert_of_not_mem _ _ h).symm,\n      contradiction},\n      {simp, repeat {rw [bw_to_nonzero_indices, finset.insert_eq] at h}, \n      have h₁ : k.succ ∉ bw_to_nonzero_indices atl, from succ_not_mem_nonzero_indices atl,\n      have h₂ : k.succ ∉ bw_to_nonzero_indices btl, from succ_not_mem_nonzero_indices btl,\n      have h₃ : bw_to_nonzero_indices atl ⊆ bw_to_nonzero_indices btl, \n        begin\n          rw finset.subset_iff, intros i hi,\n          have h' : i ∈ {k.succ} ∪ bw_to_nonzero_indices atl, from finset.mem_union_right _ hi,\n          rw h at h', simp at h', cases h',\n            {rw h' at hi, rw nat.add_one at hi, contradiction},\n            {exact h'},\n        end,\n      have h₄ : bw_to_nonzero_indices btl ⊆ bw_to_nonzero_indices atl,\n        begin\n          rw finset.subset_iff, intros i hi,\n          have h' : i ∈ {k.succ} ∪ bw_to_nonzero_indices btl, from finset.mem_union_right _ hi,\n          rw ← h at h', simp at h', cases h',\n            {rw h' at hi, rw nat.add_one at hi, contradiction},\n            {exact h'},\n        end,\n      have h₅ : bw_to_nonzero_indices atl = bw_to_nonzero_indices btl, \n      from finset.subset.antisymm h₃ h₄,\n      exact ih btl h₅,\n      },\n    }\nend\n\nlemma filter_size_same_as_size_filter (w : ℕ):\n  (finset.filter (λ v : BW n, (bw_to_nonzero_indices v).card = w) finset.univ).card =\n  (finset.filter (λ s : finset ℕ, s.card = w) \n    (finset.image (λ v : BW n, bw_to_nonzero_indices v) finset.univ)).card :=\nbegin\n  rw finset.card_congr (λ (v : BW n) h, bw_to_nonzero_indices v),\n    {simp},\n    {simp, intros a b ha hb hab, exact eq_nonzero_indices_eq_words _ _ hab},\n    {simp, intros b hb, use b, split, exact hb, refl},\nend\n\nlemma card_nonzero_indices (w : ℕ) (h : w ≤ n) :\n  (finset.filter \n    (λ v : BW n, (bw_to_nonzero_indices v).card = w) finset.univ).card = \n  n.choose w :=\nbegin\n  rw [filter_size_same_as_size_filter, nonzero_indices_eq_powerset_len],\n  simp, exact h,\nend \n\n/--\nThis is the key lemma for the proof of sphere size.\n-/\nlemma num_words_with_weight (w : ℕ) (h : w ≤ n): \n  (finset.filter (λ v : BW n, wt(v) = w) finset.univ).card = n.choose w :=\nbegin\n  conv {to_lhs, congr, congr, funext, rw weight_eq_card_nonzero_indices},\n  simp,\n  exact card_nonzero_indices w h,\nend\n\n/--\nGiven a word c and radius r, \nthis is set {x ∈ ℬⁿ | d(c,x) = r}\n-/\ndef words_at_dist (c : BW n) (r : ℕ) : finset (BW n) :=\nfinset.filter (λ v, d(c, v) = r) finset.univ\n\n/--\nGiven a word c and radius r, \nthis is set {x ∈ ℬⁿ | d(c,x) ≤ r}\n-/\ndef sphere (c : BW n) (r : ℕ) : finset (BW n) := \nfinset.filter (λ v, d(c, v) ≤ r) finset.univ\n\nlemma words_at_dist_mem (c : BW n) (r : ℕ) :\n  ∀ (bw : BW n), bw ∈ words_at_dist c r ↔ d(c, bw) = r :=\nby {unfold words_at_dist, simp}\n\nlemma sphere_mem (c : BW n) (r : ℕ) : ∀ (bw : BW n), bw ∈ sphere c r ↔ d(c, bw) ≤ r :=\nby {unfold sphere, simp}\n\nlemma words_unique (c : BW n) : (finset.filter (eq c) finset.univ).card = 1 :=\nby {rw finset.filter_eq finset.univ c, simp}\n\nlemma words_at_ne_dists_disjoint (c : BW n) (r₁ r₂ : ℕ) (h : r₁ ≠ r₂) :\n  disjoint (words_at_dist c r₁) (words_at_dist c r₂) :=\nbegin\n  rw finset.disjoint_right,\n  by_contradiction h₁, \n  push_neg at h₁,\n  cases h₁ with a h_a,\n  repeat {rw words_at_dist_mem at h_a},\n  have : r₁ = r₂, from hamming.distance_unique c a r₁ r₂ h_a.symm,\n  contradiction,\nend\n\nlemma words_at_dist_eq_words_with_sum_weight (c : BW n) (r : ℕ) :\n  (finset.filter (λ (v : BW n), wt(c + v) = r) finset.univ).card = \n    (finset.filter (λ (v : BW n), wt(v) = r) finset.univ).card :=\nbegin\n  rw finset.card_congr (λ (v : BW n) h, c + v),\n    {intros a ha, simp, simp at ha, exact ha},\n    {intros a b ha hb, simp},\n    {intros b hb, simp, simp at hb,\n    use b - c, split,\n      {simp, exact hb},\n      {simp}\n    },\nend\n\nlemma words_at_dist_size (c : BW n) (r : ℕ) (h : r ≤ n) : \n  (words_at_dist c r).card = n.choose r :=\nbegin\n  rw words_at_dist,\n  conv {to_lhs, congr, congr, funext, rw hamming.distance_eq_weight_of_sum},\n  simp,\n  rw [words_at_dist_eq_words_with_sum_weight, num_words_with_weight r h],\nend\n\nlemma sphere_eq_union_words_at_dist (c : BW n) (r : ℕ) (h : r ≤ n) :\n  sphere c r = finset.bUnion (finset.range (r + 1)) (words_at_dist c) :=\nbegin\n  unfold sphere,\n  ext,\n  split,\n    {simp,\n    intro h, \n    use d(c,a), \n    split,\n      {linarith},\n      {rw words_at_dist, simp}},\n    {simp,\n    intros x hx,\n    rw words_at_dist, \n    simp,\n    intro h_dist,\n    rw h_dist,\n    linarith,\n    }\nend\n\nlemma sphere_size_eq_sum_words_at_dist_size (c : BW n) (r : ℕ) (h : r ≤ n) :\n  (sphere c r).card = ∑ i in (finset.range (r + 1)), (words_at_dist c i).card :=\nbegin\n  rw sphere_eq_union_words_at_dist,\n  rw finset.card_bUnion,\n    {intros x hx y hy h_ne, \n    exact words_at_ne_dists_disjoint c x y h_ne},\n    {exact h},\nend\n\n/--\nLet c ∈ ℬⁿ be a binary word of length n and let r ∈ ℕ be such that r ≤ n.\nThen, \n|{x ∈ ℬⁿ | d(c,x) ≤ r}| = n.choose 0 + n.choose 1 + … + n.choose r\n-/\nlemma sphere_size (c : BW n) (r : ℕ) (h : r ≤ n) : \n  (sphere c r).card = ∑ i in (finset.range (r + 1)), n.choose i :=\nbegin\n  rw sphere_size_eq_sum_words_at_dist_size c r h,\n  apply finset.sum_congr,\n    {refl},\n  intros h hx,\n  rw words_at_dist_size,\n  simp at hx,\n  linarith,\nend\n\n/--\nLet C be a t-error-correcting code.\nThen, the spheres for any distinct codewords are disjoint.\n-/\nlemma t_error_correcting_spheres_disjoint (t : ℕ) \n  (t_error_correcting : C.error_correcting t) :\n  ∀ (c₁ c₂ ∈ C), c₁ ≠ c₂ → disjoint (sphere c₁ t) (sphere c₂ t) :=\nbegin\n  rw t_error_correcting_iff_min_distance_gte at t_error_correcting,\n  intros c₁ c₂ hc₁ hc₂ hne,\n  rw finset.disjoint_left,\n  repeat {rw sphere}, simp,\n  intros x hc₁x,\n  by_contradiction hc₂x, push_neg at hc₂x,\n  have h₁ : d(c₁,c₂) ≤ d(c₁,x) + d(x,c₂), from hamming.distance_triangle_ineq c₁ c₂ x,\n  have h₂ : d(c₁,c₂) ≤ 2 * t,\n  from calc d(c₁,c₂) ≤ t + d(x,c₂) : le_add_of_le_add_right h₁ hc₁x\n  ...                ≤ t + t       : by {simp, rw hamming.distance_symmetric, exact hc₂x}\n  ...                = 2 * t       : by ring,\n  have h₃ : d(C) ≤ d(c₁,c₂), from dist_neq_codewords_gte_min_distance c₁ c₂ hc₁ hc₂ hne,\n  linarith,\nend\n\n/-! We combine the next two lemmas to prove the Hamming bound. -/\n\nlemma codeword_sphere_union_card (t : ℕ) (ht : t ≤ n)\n  (t_error_correcting : C.error_correcting t) :\n  (finset.bUnion C.cws (λ c, sphere c t)).card = \n  |C| * ∑ i in (finset.range (t + 1)), n.choose i :=\nbegin \n  rw finset.card_bUnion,\n    {\n      have h : ∑ (u : BW n) in C.cws, (sphere u t).card = \n               ∑ (u : BW n) in C.cws, ∑ i in (finset.range (t + 1)), n.choose i,\n      begin\n        rw finset.sum_congr,\n          {refl},\n        intros x hx,\n        exact sphere_size x t ht,\n      end,\n      rw h, simp,\n    },\n    {intros x hx y hy hne,\n    exact (t_error_correcting_spheres_disjoint t t_error_correcting) x y hx hy hne}\nend\n\nlemma codeword_sphere_union_card_le_univ_card (t : ℕ) (ht : t ≤ n)\n  (t_error_correcting : C.error_correcting t) :\n  (finset.bUnion C.cws (λ c, sphere c t)).card ≤ 2 ^ n :=\nbegin \n  have h : (@finset.univ (BW n) BW.fintype).card = 2 ^ n, \n  by {rw finset.card_univ, simp},\n  rw ← h, apply finset.card_le_of_subset, rw finset.subset_iff, simp,\nend\n\n/--\nThe Hamming bound (Sphere-Packing bound) for a t-error-correcting code.\n|C| ≤ 2ⁿ / (n.choose 0 + n.choose 1 + … + n.choose t)\n-/\ntheorem hamming_bound (t : ℕ) (ht : t ≤ n)\n  (t_error_correcting : C.error_correcting t) :\n  |C| ≤ 2 ^ n / ∑ i in (finset.range (t + 1)), n.choose i :=\nbegin\n  have h : |C| * ∑ i in (finset.range (t + 1)), n.choose i ≤ 2 ^ n,\n  by {rw ← codeword_sphere_union_card t ht t_error_correcting, \n     exact codeword_sphere_union_card_le_univ_card t ht t_error_correcting},\n  have h₁ : ∑ (i : ℕ) in finset.range (t + 1), n.choose i > 0,\n  begin\n    by_contradiction h', push_neg at h', simp at h',\n    rw finset.sum_range_succ' at h',\n    simp at h', exact h',\n  end,\n  exact (nat.le_div_iff_mul_le (|C|) (2 ^ n) h₁).mpr h,\nend\n\n/--\nA code is perfect if it attains the Hamming bound.\n-/\ndef perfect (C : binary_code n M d) : Prop := \n|C| = 2 ^ n / ∑ i in (finset.range ((d - 1)/2 + 1)), n.choose i\n\nend binary_code", "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_codes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.8056321913146128, "lm_q1q2_score": 0.7504161821488229}}
{"text": "import algebra.ring\n\nnamespace my_ring\n\nvariables {R : Type*} [ring R]\nvariables a b c : R\n\n#check add_right_neg\n#check sub_eq_add_neg \n#check sub_eq_add_neg c\n\n-- BEGIN\ntheorem self_sub (a : R) : a - a = 0 :=\nbegin\n  rw sub_eq_add_neg a,\n  rw add_right_neg,\nend\n-- END\n\n#check self_sub\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/ex15_rw_self_sub.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8056321959813275, "lm_q1q2_score": 0.7504161818973453}}
{"text": "\nimport Mathlib.Data.Real.Basic\n\n\ndef log (x : ℝ) := x - 1\n\n\n\n-- #check \n\ntheorem log_mul_eq_add : log (a * b) = log a + log b := sorry\ntheorem log_add_eq_mul : log a + log b = log (a * b) := Iff.mp eq_comm log_mul_eq_add\n\n-- theorem log_pm (a n : ℝ) : log (a ^ n) = n * log a := sorry\n\ntheorem log_le_zero_iff : log a ≤ 0 ↔ a ≤ 1 := sorry\n\nlemma log_linear (x : ℝ) : log x ≤ x - 1 := by rfl\n\n\ntheorem log_ineq_iff (a b : ℝ) (hb : b > 0) : log (a / b) ≤ 0 ↔ b ≥ a := \n  calc \n    _ ↔ a / b ≤ 1 := log_le_zero_iff\n    _ ↔ _ := div_le_one hb\n\n-- theorem log_\n\nlemma sqrt_self (a : ℝ) : a = a^(1/2) * a^(1/2) := sorry\nlemma sqrt_decompose (a b : ℝ) : (a*b)^(1/2) = a^(1/2) * b^(1/2) := sorry\n\nlemma log_sqrt (a : ℝ) : log (a^(1/2)) = (1/2) * log a := sorry\nlemma add_map (a b : ℝ) (f : ℝ -> ℝ) : a + b = f a + f b := sorry\n\n\nlemma log_add_sqrt (a b : ℝ): log (a^(1/2)) + log (b^(1/2)) = (1/2) * log a + (1/2) * log b \n  := sorry\n\n\n\ntheorem log_bi_arith_geom_ineq (a b : ℝ) (ha : a > 0) (hb : b > 0) : \n  log ( (a*b)^(1/2) / ((a+b)/2) ) ≤ 0 := \n  have hale : _ := log_linear (2 * a/(a+b))\n  have hble : _ := log_linear (2 * b/(a+b))\n  have hline : log (2 * a/(a+b)) + log (2 * b/(a+b)) ≤ (2 * a/(a+b) - 1) + (2 * b/(a+b) - 1) \n    := add_le_add hale hble\n  have hsum : a + b ≠ 0 := sorry\n  have hp : _ := sorry\n  have hp' : _ := sorry\n  calc \n      _ = _ := sorry\n      _ = log ((2 * a/(a+b))^(1/2)) + log ((2*b/(a+b))^(1/2)) := log_mul_eq_add\n      _ = (1/2) * log (2 * a/(a+b)) + (1/2) * log (2*b/(a+b)) := log_add_sqrt _ _\n      _ = (1/2) * ( log (2 * a/(a+b)) + log (2 * b/(a+b)) ) := by ring\n      _ ≤ (1/2) * (2 * a/(a+b) - 1 + (2 * b/(a+b) - 1)) := mul_le_mul le_rfl hline hp hp'\n      _ = (a + b) / (a + b) - 1 := by ring\n      _ = 1 - 1 := by rw [div_self hsum]\n      _ = 0 := by simp\n\ntheorem bi_arith_geom_ineq (a b : ℝ)\n  (ha : a > 0) (hb : b > 0) : (a + b) / 2 ≥ (a*b)^(1/2) := \n  have hsum : a + b > 0 := add_pos ha hb\n  have h2 : 2 > 0 := by simp\n  have hbot : (a + b) / 2 > 0 := Iff.mp gt_iff_lt (div_pos hsum h2)\n  have hlog : _ := log_bi_arith_geom_ineq a b ha hb\n  show _ from Iff.mp (log_ineq_iff _ _ hbot) hlog\n\n\n\n  -- calc \n    \n  -- have heq1 : _ := sqrt_decompose a b\n--   have heq2 : (a * b)^(1/2) / ((a+b)/2) = a^(1/2)*b^(1/2) / ((a+b)/2) := sorry\n--   have heq3 : a^(1/2) * b^(1/2) / ((a+b)/2) = ((2 * a/(a+b))^(1/2)) * ((2*b/(a+b))^(1/2)) := sorry\n  \n--   have hle1 _ := log_linear (2*a/(a+b))\n--   -- have hle2 : (1/2) * log (2*a/(a+b)) ≤ (1/2) * (2 * a / (a + b) - 1) := mul_le_mul (le_refl _) hle1\n--   calc\n--     _ = log _ := congrArg log heq3\n--     _ = log ((2 * a/(a+b))^(1/2)) + log ((2*a/(a+b))^(1/2)) := log_mul_eq_add\n--     _ = (1/2) * log (2 * a/(a+b)) + (1/2) * log (2*b/(a+b)) := sorry\n--     _ ≤ 0 := sorry\n\n", "meta": {"author": "kokic", "repo": "ineq", "sha": "b036e74dbd29c9178d631c7d2505aa2cecab96d6", "save_path": "github-repos/lean/kokic-ineq", "path": "github-repos/lean/kokic-ineq/ineq-b036e74dbd29c9178d631c7d2505aa2cecab96d6/log-motif.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8056321843145405, "lm_q1q2_score": 0.7504161771613004}}
{"text": "-- ---------------------------------------------------------------------\n-- Ejercicio. Realizar las siguientes acciones:\n-- 1. Importar la teoría data.set.function\n-- 2. Declarar u y v como universos.\n-- 3. Declarar α como variable sobre tipo de u habitados.\n-- 4. Declarar β como variable sobre tipo de v.\n-- 5. Declarar la teoría como no computable.\n-- 6. Usar la lógica clásica.\n-- ----------------------------------------------------------------------\n\nimport data.set.function               -- 1\nuniverses u v                          -- 2\nvariables {α : Type u} [inhabited α]   -- 3\nvariables {β : Type v}                 -- 4\nnoncomputable theory                   -- 5\nopen_locale classical                  -- 6\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Definir la inversa de una función \n-- ----------------------------------------------------------------------\n\ndef inverse (f : α → β) : β → α :=\nλ y : β, if h : ∃ x, f x = y \n         then classical.some h \n         else default α\n\n-- ---------------------------------------------------------------------\n-- Ejercicio. Sea d una función de α en β e y un elemento de\n-- β. Demostrar que si \n--    ∃ x, f x = y\n-- entonces\n--    f (inverse f y) = y :=\n-- ----------------------------------------------------------------------\n\ntheorem inverse_spec \n  {f : α → β} \n  (y : β) \n  (h : ∃ 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-- Prueba\n-- ======\n\n/-\nα : Type u,\n_inst_1 : inhabited α,\nβ : Type v,\nf : α → β,\ny : β,\nh : ∃ (x : α), f x = y\n⊢ f (inverse f y) = y\n  >> rw inverse, dsimp, rw dif_pos h,\n⊢ f (classical.some h) = y\n  >> exact classical.some_spec h,\nno goals\n-/\n\n-- Comentarios: \n-- 1. La identidad (dif_pos h), cuando (h : e), reescribe la expresión\n--    (if h : e then x else y) a x. \n-- 2. La identidad (dif_neg h), cuando (h : ¬ e), reescribe la expresión\n--    (if h : e then x else y) a y. \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/Funcion_inversa.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391685381605, "lm_q2_score": 0.8128673269042767, "lm_q1q2_score": 0.7503083815575606}}
{"text": "import data.matrix.notation\nimport linear_algebra.matrix\nimport tactic.norm_fin\nimport tactic.noncomm_ring\nimport tactic.field_simp\nimport data.nat.parity\n\nopen_locale big_operators\n\n-- 1.1.7\n-- Find a formula for `![![1, 1, 1], ![0, 1, 1], ![0, 0, 1]]^n` and prove it by induction\nexample (n : ℕ) :\n  (![![1, 1, 1], ![0, 1, 1], ![0, 0, 1]] ^ n : matrix _ _ ℕ) =\n  ![![1, n, (n * (n + 1)) / 2], ![0, 1, n], ![0, 0, 1]] :=\nbegin\n  induction n with n hn,\n  { simp only [pow_two, nat.nat_zero_eq_zero, mul_zero, pow_zero],\n    norm_num,\n    ext i j,\n    fin_cases i;\n    fin_cases j;\n    norm_num [matrix.one_apply, -matrix.cons_val'] },\n  { suffices : n * (n + 1) / 2 + (n + 1) = (n + 1) * ((n + 1) + 1) / 2,\n      { rw [pow_succ, hn],\n        ext i j,\n        fin_cases i;\n        fin_cases j;\n        norm_num [this] },\n     apply nat.mul_left_injective (show 0 < 2, by norm_num),\n     dsimp,\n     rw [nat.div_mul_cancel (nat.even_mul_succ_self _), add_mul,\n         nat.div_mul_cancel (nat.even_mul_succ_self _)],\n     ring }\nend\n\n-- 1.1.16\n-- A square matrix `A` is called nilpotent if `A^k = 0` for some `k > 0`.\n-- Prove that if `A` is nilpotent, then `I + A` is invertible\nexample {R n : Type*} [comm_ring R] [fintype n] [decidable_eq n] (A : matrix n n R)\n  (k : ℕ) (hk : 0 < k) (nilpotent : A ^ k = 0) : is_unit (1 + A) :=\nbegin\n  have hr : ∀ m (x : matrix n n R), 1 - x ^ m = (1 - x) * ∑ i in finset.range m, x ^ i,\n    { intros m x,\n      induction m with m hm,\n      { simp },\n      { rw [finset.sum_range_succ, mul_add, ←hm, pow_succ],\n        noncomm_ring } },\n  have hl : ∀ m (x : matrix n n R), 1 - x ^ m = (∑ i in finset.range m, x ^ i) * (1 - x),\n    { intros m x,\n      induction m with m hm,\n      { simp },\n      { rw [finset.sum_range_succ, add_mul, ←hm, mul_sub, ←pow_succ', pow_succ],\n        noncomm_ring } },\n  specialize hr k (-A),\n  specialize hl k (-A),\n  rw [sub_neg_eq_add] at hr hl,\n  refine ⟨⟨1 + A, ∑ i in finset.range k, (-A) ^ i, _, _⟩, rfl⟩,\n  { simp [-matrix.mul_eq_mul, ←hr, neg_pow A k, nilpotent] },\n  { simp [-matrix.mul_eq_mul, ←hl, neg_pow A k, nilpotent] }\nend\n\n-- 1.1.17\n-- (a) Find infinitely many matrices `B` such that `BA = I₂` when\n-- `A = ![![2, 3], ![1, 2], ![2, 5]]`\n-- (b) Prove that there is no matrix `C` such that `AC = I₃`\nexample (A : matrix (fin 3) (fin 2) ℚ) (hA : A = ![![2, 3], ![1, 2], ![2, 5]]) :\n  (∃ (B : matrix (fin 2) (fin 3) ℚ) , B.mul A = 1) ∧\n  ∀ (C : matrix (fin 2) (fin 3) ℚ), A.mul C ≠ 1 :=\nbegin\n  split,\n  { have c : ℚ := arbitrary _,\n    set b : ℚ := - 4 * c - 3 with hb,\n    set a : ℚ := - (2 * b + 5 * c) / 3 with ha,\n    have d : ℚ := arbitrary _,\n    set f : ℚ := d + 1 with hf,\n    set e : ℚ := - 2 * (d + f) with he,\n    set B : matrix (fin 2) (fin 3) ℚ := ![![a, b, c], ![d, e, f]] with hB,\n    use B,\n    rw [hA],\n    ext i j,\n    fin_cases i;\n    fin_cases j;\n    simp [ha, hb, he, hf];\n    ring },\n  { intros C H,\n    set a : ℚ := C 0 0 with ha,\n    set b : ℚ := C 0 1 with hb,\n    set c : ℚ := C 0 2 with hc,\n    set d : ℚ := C 1 0 with hd,\n    set e : ℚ := C 1 1 with he,\n    set f : ℚ := C 1 2 with hf,\n    have : C = ![![a, b, c], ![d, e, f]],\n      { rw [ha, hb, hc, hd, he, hf],\n        ext i j,\n        fin_cases i;\n        fin_cases j;\n        refl },\n    rw [hA, this] at H,\n    have h22 := congr_fun (congr_fun H 2) 2,\n    replace h22 : 2 * c + 5 * f = 1,\n      { norm_num at h22, exact h22 },\n    have h02 := congr_fun (congr_fun H 0) 2,\n    have h12 := congr_fun (congr_fun H 1) 2,\n    norm_num [matrix.one_apply] at h02 h12,\n    replace h12 : c = - (2 * f) := add_eq_zero_iff_eq_neg.mp h12,\n    replace h02 : f = 0,\n      { rw h12 at h02,\n        norm_num at h02,\n        ring_nf at h02,\n        simpa using h02 },\n    replace h12 : c = 0 := by simpa [h02] using h12,\n    norm_num [h02, h12] at h22 }\nend\n", "meta": {"author": "pechersky", "repo": "e222", "sha": "db470367381d65dfc1e4e8fc1dd805b038dbfa93", "save_path": "github-repos/lean/pechersky-e222", "path": "github-repos/lean/pechersky-e222/e222-db470367381d65dfc1e4e8fc1dd805b038dbfa93/src/problems01.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133456181841, "lm_q2_score": 0.7981867825403177, "lm_q1q2_score": 0.750226409205684}}
{"text": "/-\n  Some basic results about ranges over finite sets that I found useful.\n\n  TODO : Check how much of this isn't actually somehwere in the mathlib.\n-/\n\nimport data.finset\nimport data.finsupp\nimport data.nat.choose\n\nuniverses u v w\n\nopen finset\n\nsection basics\n\n-- range(f) = f '' {γ1, ..., γn}.\n\nlemma finset.coe_image_univ {α : Type u} {β : Type v} [fintype α] [decidable_eq β] {f : α → β}\n: set.range f = ↑(finset.image f finset.univ) :=\nby rw [finset.coe_image, finset.coe_univ, ←set.image_univ]\n\n-- f (Σi=1..n ai) = Σi=1..n f (ai).\n\nlemma is_ring_hom.map_finset_sum \n{A : Type u} {B : Type v} [comm_ring A] [comm_ring B] (f : A → B) [is_ring_hom f] \n{C : Type w} [decidable_eq C] (s : C → A) (X : finset C)\n: f (finset.sum X s) = finset.sum X (f ∘ s) :=\nbegin\n  apply finset.induction_on X,\n  { iterate 2 { rw finset.sum_empty, },\n    exact is_ring_hom.map_zero f, },\n  { intros a T HanT IH,\n    iterate 2 { rw finset.sum_insert HanT, },\n    rw is_ring_hom.map_add f,\n    rw IH, }\nend\n\n-- Obvious: n ∉ {0, ..., n-1}.\n\n@[simp] lemma finset.range_not_mem : ∀ n : ℕ, n ∉ range n :=\nλ n Hn, (lt_irrefl n) (finset.mem_range.1 Hn)\n\n-- If f(i) = g(i) for i=0..n then Σi=0..n f(i) = Σi=0..n g(i).\n\nlemma finset.sum_range_eq {α : Type u} [comm_ring α] {f g : ℕ → α} \n: ∀ n, (∀ m, m < n → f m = g m) → sum (range n) f = sum (range n) g :=\nbegin\n  intros n Hn,\n  induction n with n IH,\n  { simp, },\n  { repeat { rw finset.range_succ, },\n    repeat { rw finset.sum_insert; try { apply finset.range_not_mem _, } },\n    rw Hn n (nat.lt_succ_self n),\n    rw IH,\n    intros m Hm,\n    exact Hn m (nat.lt_succ_of_lt Hm), }\nend\n\n-- Σi=0..(n+m) f(i) = (Σi=0..n f(i)) + (Σi=0..m f(i+n)).\n\nlemma finset.sum_range_add {α : Type u} [comm_ring α] (f : ℕ → α) \n: ∀ n m : ℕ, sum (range (n + m)) f = sum (range n) f + sum (range m) (λ i, f (i + n)) :=\nbegin\n  intros n m,\n  revert n,\n  induction m with m IH,\n  { simp, },\n  { intros n,\n    rw nat.add_succ,\n    repeat { rw finset.range_succ, },\n    repeat { rw finset.sum_insert; try { apply finset.range_not_mem _, } },\n    rw IH n,\n    simp, }\nend\n\nend basics\n\n-- (a + b)^(n + m) = x * b ^ m + y * a ^ n\n--  where x = Σi=0..(n-1) ((n+m), i) * a^i * b^(n-i),\n--        y = Σi=0..m ((n+m), (i+n)) * a^i * b^(m-i).\n\n-- Note: This might be way too specific.\n\nlemma add_pow_sum\n{α : Type u} [comm_ring α] \n: ∀ (a b : α), ∀ (n m : ℕ), ∃ (x y : α), \n  (a + b) ^ (n + m) = x * (b ^ m) + y * (a ^ n) :=\nbegin\n  intros a b n m,\n  rw add_pow,\n  let cnmi : ℕ → α := λ i, ((nat.choose (n+m) i):α), \n  use [finset.sum (range n) (λ i, a ^ i * b ^ (n - i) * (nat.choose (n + m) i))],\n  use [sum (range (nat.succ m)) (λ i, a ^ i * b ^ (m - i) * (nat.choose (n + m) (i + n)))],\n  rw add_comm (_ * _),\n  repeat { rw finset.sum_mul, },\n  repeat { rw finset.range_succ, },\n  repeat { rw finset.sum_insert; try { apply finset.range_not_mem, }, },\n  rw add_assoc,\n  congr' 1,\n  { rw [mul_assoc _ _ (a ^ n), mul_comm _ (a ^ n), ←mul_assoc _ (a ^ n) _],\n    rw [mul_assoc _ _ (a ^ n), mul_comm _ (a ^ n), ←mul_assoc _ (a ^ n) _],\n    rw [←pow_add, add_comm m],\n    simp, },\n  rw finset.sum_range_add,\n  rw add_comm,\n  congr' 1,\n  { apply finset.sum_range_eq,\n    intros z Hz,\n    rw [mul_assoc _ _ (a ^ n), mul_comm _ (a ^ n), ←mul_assoc _ (a ^ n) _],\n    rw [mul_assoc _ _ (a ^ n), mul_comm _ (a ^ n), ←mul_assoc _ (a ^ n) _],\n    rw [←pow_add, add_comm n, nat.add_sub_add_right, add_comm z], },\n  { apply finset.sum_range_eq,\n    intros z Hz,\n    rw [mul_assoc _ _ (b ^ m), mul_comm _ (b ^ m), ←mul_assoc _ (b ^ m) _],\n    rw [mul_assoc _ _ (b ^ m), ←pow_add, add_comm n _, add_comm (n - z) _], \n    rw [←nat.add_sub_assoc],\n    exact nat.le_of_lt Hz, },\nend\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/to_mathlib/finset_range.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8080672227971212, "lm_q1q2_score": 0.7502167210852468}}
{"text": "import data.list.basic\nopen list\nuniverse u\nvariables {α : Type} (x y z : α) (xs ys zs : list α)\n\ndef mk_symm (xs : list α) := xs ++ reverse xs\n\ntheorem reverse_mk_symm (xs : list α) :\n  reverse (mk_symm xs) = mk_symm xs :=\n  by simp [mk_symm]\n\nattribute [simp] reverse_mk_symm\n\nexample (xs ys : list ℕ) (p : list ℕ → Prop) (h : p (reverse (xs ++ (mk_symm ys)))) :\n  p (mk_symm ys ++ reverse xs) :=\n  by { simp at h; assumption }\n\n-- example (xs ys : list ℕ) (p : list ℕ → Prop) (h : p (reverse (xs ++ (mk_symm ys)))) :\n--   p (mk_symm ys ++ reverse xs) :=\n--   by { simp [-reverse_mk_symm] at h; assumption }\n\n-- example (xs ys : list ℕ) (p : list ℕ → Prop) (h : p (reverse (xs ++ (mk_symm ys)))) :\n--   p (mk_symm ys ++ reverse xs) :=\n--   by { simp only [reverse_append] at h; 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/ch5/ex0722.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088045171237, "lm_q2_score": 0.8080672135527632, "lm_q1q2_score": 0.7502167157040042}}
{"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-/\n\nimport algebra.group.defs\nimport logic.function.basic\n\n/-!\n# Basic lemmas about semigroups, monoids, and groups\n\nThis file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are\none-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see\n`algebra/group/defs.lean`.\n-/\n\nuniverse u\n\nsection associative\nvariables {α : Type u} (f : α → α → α) [is_associative α f] (x y : α)\n\n/--\nComposing two associative operations of `f : α → α → α` on the left\nis equal to an associative operation on the left.\n-/\nlemma comp_assoc_left : (f x) ∘ (f y) = (f (f x y)) :=\nby { ext z, rw [function.comp_apply, @is_associative.assoc _ f] }\n\n/--\nComposing two associative operations of `f : α → α → α` on the right\nis equal to an associative operation on the right.\n-/\nlemma comp_assoc_right : (λ z, f z x) ∘ (λ z, f z y) = (λ z, f z (f y x)) :=\nby { ext z, rw [function.comp_apply, @is_associative.assoc _ f] }\n\nend associative\n\nsection semigroup\nvariables {α : Type*}\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, to_additive\n\"Composing two additions on the left by `y` then `x`\nis equal to a addition on the left by `x + y`.\"]\nlemma comp_mul_left [semigroup α] (x y : α) :\n  ((*) x) ∘ ((*) y) = ((*) (x * y)) :=\ncomp_assoc_left _ _ _\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, to_additive\n\"Composing two additions on the right by `y` and `x`\nis equal to a addition on the right by `y + x`.\"]\nlemma comp_mul_right [semigroup α] (x y : α) :\n  (* x) ∘ (* y) = (* (y * x)) :=\ncomp_assoc_right _ _ _\n\nend semigroup\n\nsection mul_one_class\nvariables {M : Type u} [mul_one_class M]\n\n@[to_additive]\nlemma ite_mul_one {P : Prop} [decidable P] {a b : M} :\n  ite P (a * b) 1 = ite P a 1 * ite P b 1 :=\nby { by_cases h : P; simp [h], }\n\n@[to_additive]\nlemma eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 :=\nby split; { rintro rfl, simpa using h }\n\n@[to_additive]\nlemma one_mul_eq_id : ((*) (1 : M)) = id := funext one_mul\n\n@[to_additive]\nlemma mul_one_eq_id : (* (1 : M)) = id := funext mul_one\n\nend mul_one_class\n\nsection comm_semigroup\nvariables {G : Type u} [comm_semigroup G]\n\n@[no_rsimp, to_additive]\nlemma mul_left_comm : ∀ a b c : G, a * (b * c) = b * (a * c) :=\nleft_comm has_mul.mul mul_comm mul_assoc\nattribute [no_rsimp] add_left_comm\n\n@[to_additive]\nlemma mul_right_comm : ∀ a b c : G, a * b * c = a * c * b :=\nright_comm has_mul.mul mul_comm mul_assoc\n\n@[to_additive]\ntheorem mul_mul_mul_comm (a b c d : G) : (a * b) * (c * d) = (a * c) * (b * d) :=\nby simp only [mul_left_comm, mul_assoc]\n\nend comm_semigroup\n\nlocal attribute [simp] mul_assoc sub_eq_add_neg\n\nsection add_monoid\nvariables {M : Type u} [add_monoid M] {a b c : M}\n\n@[simp] lemma bit0_zero : bit0 (0 : M) = 0 := add_zero _\n@[simp] lemma bit1_zero [has_one M] : bit1 (0 : M) = 1 :=\nby rw [bit1, bit0_zero, zero_add]\n\nend add_monoid\n\nsection comm_monoid\nvariables {M : Type u} [comm_monoid M] {x y z : M}\n\n@[to_additive] lemma inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=\nleft_inv_eq_right_inv (trans (mul_comm _ _) hy) hz\n\nend comm_monoid\n\nsection left_cancel_monoid\n\nvariables {M : Type u} [left_cancel_monoid M] {a b : M}\n\n@[simp, to_additive] lemma mul_right_eq_self : a * b = a ↔ b = 1 :=\ncalc a * b = a ↔ a * b = a * 1 : by rw mul_one\n           ... ↔ b = 1         : mul_left_cancel_iff\n\n@[simp, to_additive] lemma self_eq_mul_right : a = a * b ↔ b = 1 :=\neq_comm.trans mul_right_eq_self\n\nend left_cancel_monoid\n\nsection right_cancel_monoid\n\nvariables {M : Type u} [right_cancel_monoid M] {a b : M}\n\n@[simp, to_additive] lemma mul_left_eq_self : a * b = b ↔ a = 1 :=\ncalc a * b = b ↔ a * b = 1 * b : by rw one_mul\n           ... ↔ a = 1         : mul_right_cancel_iff\n\n@[simp, to_additive] lemma self_eq_mul_left : b = a * b ↔ a = 1 :=\neq_comm.trans mul_left_eq_self\n\nend right_cancel_monoid\n\nsection div_inv_monoid\n\nvariables {G : Type u} [div_inv_monoid G]\n\n@[to_additive]\nlemma inv_eq_one_div (x : G) :\n  x⁻¹ = 1 / x :=\nby rw [div_eq_mul_inv, one_mul]\n\n@[to_additive]\nlemma mul_one_div (x y : G) :\n  x * (1 / y) = x / y :=\nby rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]\n\nlemma mul_div_assoc {a b c : G} : a * b / c = a * (b / c) :=\nby rw [div_eq_mul_inv, div_eq_mul_inv, mul_assoc _ _ _]\n\nlemma mul_div_assoc' (a b c : G) : a * (b / c) = (a * b) / c :=\nmul_div_assoc.symm\n\n@[simp, to_additive] lemma one_div (a : G) : 1 / a = a⁻¹ :=\n(inv_eq_one_div a).symm\n\nend div_inv_monoid\n\nsection group\nvariables {G : Type u} [group G] {a b c : G}\n\n@[simp, to_additive]\nlemma inv_mul_cancel_right (a b : G) : a * b⁻¹ * b = a :=\nby simp [mul_assoc]\n\n@[simp, to_additive neg_zero]\nlemma one_inv : 1⁻¹ = (1 : G) :=\ninv_eq_of_mul_eq_one (one_mul 1)\n\n@[to_additive]\ntheorem left_inverse_inv (G) [group G] :\n  function.left_inverse (λ a : G, a⁻¹) (λ a, a⁻¹) :=\ninv_inv\n\n@[simp, to_additive]\nlemma inv_involutive : function.involutive (has_inv.inv : G → G) := inv_inv\n\n@[to_additive]\nlemma inv_injective : function.injective (has_inv.inv : G → G) :=\ninv_involutive.injective\n\n@[simp, to_additive] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff\n\n@[simp, to_additive]\nlemma mul_inv_cancel_left (a b : G) : a * (a⁻¹ * b) = b :=\nby rw [← mul_assoc, mul_right_inv, one_mul]\n\n@[to_additive]\ntheorem mul_left_surjective (a : G) : function.surjective ((*) a) :=\nλ x, ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩\n\n@[to_additive]\ntheorem mul_right_surjective (a : G) : function.surjective (λ x, x * a) :=\nλ x, ⟨x * a⁻¹, inv_mul_cancel_right x a⟩\n\n@[simp, to_additive neg_add_rev]\nlemma mul_inv_rev (a b : G) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=\ninv_eq_of_mul_eq_one $ by simp\n\n@[to_additive]\nlemma eq_inv_of_eq_inv (h : a = b⁻¹) : b = a⁻¹ :=\nby simp [h]\n\n@[to_additive]\nlemma eq_inv_of_mul_eq_one (h : a * b = 1) : a = b⁻¹ :=\nhave a⁻¹ = b, from inv_eq_of_mul_eq_one h,\nby simp [this.symm]\n\n@[to_additive]\nlemma eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ :=\nby simp [h.symm]\n\n@[to_additive]\nlemma eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c :=\nby simp [h.symm]\n\n@[to_additive]\nlemma inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c :=\nby simp [h]\n\n@[to_additive]\nlemma mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c :=\nby simp [h]\n\n@[to_additive]\nlemma eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c :=\nby simp [h.symm]\n\n@[to_additive]\nlemma eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c :=\nby simp [h.symm, mul_inv_cancel_left]\n\n@[to_additive]\nlemma mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c :=\nby rw [h, mul_inv_cancel_left]\n\n@[to_additive]\nlemma mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c :=\nby simp [h]\n\n@[simp, to_additive]\ntheorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=\nby rw [← @inv_inj _ _ a 1, one_inv]\n\n@[simp, to_additive]\ntheorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 :=\nby rw [eq_comm, inv_eq_one]\n\n@[to_additive]\ntheorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=\nnot_congr inv_eq_one\n\n@[to_additive]\ntheorem eq_inv_iff_eq_inv : a = b⁻¹ ↔ b = a⁻¹ :=\n⟨eq_inv_of_eq_inv, eq_inv_of_eq_inv⟩\n\n@[to_additive]\ntheorem inv_eq_iff_inv_eq : a⁻¹ = b ↔ b⁻¹ = a :=\neq_comm.trans $ eq_inv_iff_eq_inv.trans eq_comm\n\n@[to_additive]\ntheorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ :=\n⟨eq_inv_of_mul_eq_one, λ h, by rw [h, mul_left_inv]⟩\n\n@[to_additive]\ntheorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b :=\nby rw [mul_eq_one_iff_eq_inv, eq_inv_iff_eq_inv, eq_comm]\n\n@[to_additive]\ntheorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 :=\nmul_eq_one_iff_eq_inv.symm\n\n@[to_additive]\ntheorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 :=\nmul_eq_one_iff_inv_eq.symm\n\n@[to_additive]\ntheorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b :=\n⟨λ h, by rw [h, inv_mul_cancel_right], λ h, by rw [← h, mul_inv_cancel_right]⟩\n\n@[to_additive]\ntheorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c :=\n⟨λ h, by rw [h, mul_inv_cancel_left], λ h, by rw [← h, inv_mul_cancel_left]⟩\n\n@[to_additive]\ntheorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c :=\n⟨λ h, by rw [← h, mul_inv_cancel_left], λ h, by rw [h, inv_mul_cancel_left]⟩\n\n@[to_additive]\ntheorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b :=\n⟨λ h, by rw [← h, inv_mul_cancel_right], λ h, by rw [h, mul_inv_cancel_right]⟩\n\n@[to_additive]\ntheorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b :=\nby rw [mul_eq_one_iff_eq_inv, inv_inv]\n\n@[to_additive]\ntheorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b :=\nby rw [mul_eq_one_iff_eq_inv, inv_inj]\n\n@[to_additive]\nlemma div_left_injective : function.injective (λ a, a / b) :=\nby simpa only [div_eq_mul_inv] using λ a a' h, mul_left_injective (b⁻¹) h\n\n@[to_additive]\nlemma div_right_injective : function.injective (λ a, b / a) :=\nby simpa only [div_eq_mul_inv] using λ a a' h, inv_injective (mul_right_injective b h)\n\nend group\n\nsection add_group\nvariables {G : Type u} [add_group G] {a b c d : G}\n\n@[simp] lemma sub_self (a : G) : a - a = 0 :=\nby rw [sub_eq_add_neg, add_right_neg a]\n\n@[simp] lemma sub_add_cancel (a b : G) : a - b + b = a :=\nby rw [sub_eq_add_neg, neg_add_cancel_right a b]\n\n@[simp] lemma add_sub_cancel (a b : G) : a + b - b = a :=\nby rw [sub_eq_add_neg, add_neg_cancel_right a b]\n\nlemma add_sub_assoc (a b c : G) : a + b - c = a + (b - c) :=\nby rw [sub_eq_add_neg, add_assoc, ←sub_eq_add_neg]\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@[simp] lemma sub_zero (a : G) : a - 0 = a :=\nby rw [sub_eq_add_neg, neg_zero, add_zero]\n\nlemma sub_ne_zero_of_ne (h : a ≠ b) : a - b ≠ 0 :=\nmt eq_of_sub_eq_zero h\n\n@[simp] lemma sub_neg_eq_add (a b : G) : a - (-b) = a + b :=\nby rw [sub_eq_add_neg, neg_neg]\n\n@[simp] lemma neg_sub (a b : G) : -(a - b) = b - a :=\nneg_eq_of_add_eq_zero (by rw [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left,\n  add_right_neg])\n\nlocal attribute [simp] add_assoc\n\nlemma add_sub (a b c : G) : a + (b - c) = a + b - c :=\nby simp\n\nlemma sub_add_eq_sub_sub_swap (a b c : G) : a - (b + c) = a - c - b :=\nby simp\n\n@[simp] lemma add_sub_add_right_eq_sub (a b c : G) : (a + c) - (b + c) = a - b :=\nby rw [sub_add_eq_sub_sub_swap]; simp\n\nlemma eq_sub_of_add_eq (h : a + c = b) : a = b - c :=\nby simp [← h]\n\nlemma sub_eq_of_eq_add (h : a = c + b) : a - b = c :=\nby simp [h]\n\nlemma eq_add_of_sub_eq (h : a - c = b) : a = b + c :=\nby simp [← h]\n\nlemma add_eq_of_eq_sub (h : a = c - b) : a + b = c :=\nby simp [h]\n\n@[simp] lemma sub_right_inj : a - b = a - c ↔ b = c :=\nsub_right_injective.eq_iff\n\n@[simp] lemma sub_left_inj : b - a = c - a ↔ b = c :=\nby { rw [sub_eq_add_neg, sub_eq_add_neg], exact add_left_inj _ }\n\nlemma sub_add_sub_cancel (a b c : G) : (a - b) + (b - c) = a - c :=\nby rw [← add_sub_assoc, sub_add_cancel]\n\nlemma sub_sub_sub_cancel_right (a b c : G) : (a - c) - (b - c) = a - b :=\nby rw [← neg_sub c b, sub_neg_eq_add, sub_add_sub_cancel]\n\ntheorem sub_sub_assoc_swap : a - (b - c) = a + c - b :=\nby simp\n\ntheorem sub_eq_zero : a - b = 0 ↔ a = b :=\n⟨eq_of_sub_eq_zero, λ h, by rw [h, sub_self]⟩\n\nalias sub_eq_zero ↔ _ sub_eq_zero_of_eq\n\ntheorem sub_ne_zero : a - b ≠ 0 ↔ a ≠ b :=\nnot_congr sub_eq_zero\n\n@[simp] theorem sub_eq_self : a - b = a ↔ b = 0 :=\nby rw [sub_eq_add_neg, add_right_eq_self, neg_eq_zero]\n\ntheorem eq_sub_iff_add_eq : a = b - c ↔ a + c = b :=\nby rw [sub_eq_add_neg, eq_add_neg_iff_add_eq]\n\ntheorem sub_eq_iff_eq_add : a - b = c ↔ a = c + b :=\nby rw [sub_eq_add_neg, add_neg_eq_iff_eq_add]\n\ntheorem eq_iff_eq_of_sub_eq_sub (H : a - b = c - d) : a = b ↔ c = d :=\nby rw [← sub_eq_zero, H, sub_eq_zero]\n\ntheorem left_inverse_sub_add_left (c : G) : function.left_inverse (λ x, x - c) (λ x, x + c) :=\nassume x, add_sub_cancel x c\n\ntheorem left_inverse_add_left_sub (c : G) : function.left_inverse (λ x, x + c) (λ x, x - c) :=\nassume x, sub_add_cancel x c\n\ntheorem left_inverse_add_right_neg_add (c : G) :\n  function.left_inverse (λ x, c + x) (λ x, - c + x) :=\nassume x, add_neg_cancel_left c x\n\ntheorem left_inverse_neg_add_add_right (c : G) :\n  function.left_inverse (λ x, - c + x) (λ x, c + x) :=\nassume x, neg_add_cancel_left c x\n\nend add_group\n\nsection comm_group\nvariables {G : Type u} [comm_group G]\n\n@[to_additive neg_add]\nlemma mul_inv (a b : G) : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=\nby rw [mul_inv_rev, mul_comm]\n\nend comm_group\n\nsection add_comm_group\nvariables {G : Type u} [add_comm_group G] {a b c d : G}\n\nlocal attribute [simp] add_assoc add_comm add_left_comm sub_eq_add_neg\n\nlemma sub_add_eq_sub_sub (a b c : G) : a - (b + c) = a - b - c :=\nby simp\n\nlemma neg_add_eq_sub (a b : G) : -a + b = b - a :=\nby simp\n\nlemma sub_add_eq_add_sub (a b c : G) : a - b + c = a + c - b :=\nby simp\n\nlemma sub_sub (a b c : G) : a - b - c = a - (b + c) :=\nby simp\n\nlemma sub_add (a b c : G) : a - b + c = a - (b - c) :=\nby simp\n\n@[simp] lemma add_sub_add_left_eq_sub (a b c : G) : (c + a) - (c + b) = a - b :=\nby simp\n\nlemma eq_sub_of_add_eq' (h : c + a = b) : a = b - c :=\nby simp [h.symm]\n\nlemma sub_eq_of_eq_add' (h : a = b + c) : a - b = c :=\nbegin simp [h], rw [add_left_comm], simp end\n\nlemma eq_add_of_sub_eq' (h : a - b = c) : a = b + c :=\nby simp [h.symm]\n\nlemma add_eq_of_eq_sub' (h : b = c - a) : a + b = c :=\nbegin simp [h], rw [add_comm c, add_neg_cancel_left] end\n\nlemma sub_sub_self (a b : G) : a - (a - b) = b :=\nbegin simp, rw [add_comm b, add_neg_cancel_left] end\n\nlemma add_sub_comm (a b c d : G) : a + b - (c + d) = (a - c) + (b - d) :=\nby simp\n\nlemma sub_eq_sub_add_sub (a b c : G) : a - b = c - b + (a - c) :=\nbegin simp, rw [add_left_comm c], simp end\n\nlemma neg_neg_sub_neg (a b : G) : - (-a - -b) = a - b :=\nby simp\n\n@[simp] lemma sub_sub_cancel (a b : G) : a - (a - b) = b := sub_sub_self a b\n\nlemma sub_eq_neg_add (a b : G) : a - b = -b + a :=\nby rw [sub_eq_add_neg, add_comm _ _]\n\ntheorem neg_add' (a b : G) : -(a + b) = -a - b :=\nby rw [sub_eq_add_neg, neg_add a b]\n\n@[simp]\nlemma neg_sub_neg (a b : G) : -a - -b = b - a :=\nby simp [sub_eq_neg_add, add_comm]\n\nlemma eq_sub_iff_add_eq' : a = b - c ↔ c + a = b :=\nby rw [eq_sub_iff_add_eq, add_comm]\n\nlemma sub_eq_iff_eq_add' : a - b = c ↔ a = b + c :=\nby rw [sub_eq_iff_eq_add, add_comm]\n\n@[simp]\nlemma add_sub_cancel' (a b : G) : a + b - a = b :=\nby rw [sub_eq_neg_add, neg_add_cancel_left]\n\n@[simp]\nlemma add_sub_cancel'_right (a b : G) : a + (b - a) = b :=\nby rw [← add_sub_assoc, add_sub_cancel']\n\n-- This lemma is in the `simp` set under the name `add_neg_cancel_comm_assoc`,\n-- defined  in `algebra/group/commute`\nlemma add_add_neg_cancel'_right (a b : G) : a + (b + -a) = b :=\nby rw [← sub_eq_add_neg, add_sub_cancel'_right a b]\n\nlemma sub_right_comm (a b c : G) : a - b - c = a - c - b :=\nby { repeat { rw sub_eq_add_neg }, exact add_right_comm _ _ _ }\n\n@[simp] lemma add_add_sub_cancel (a b c : G) : (a + c) + (b - c) = a + b :=\nby rw [add_assoc, add_sub_cancel'_right]\n\n@[simp] lemma sub_add_add_cancel (a b c : G) : (a - c) + (b + c) = a + b :=\nby rw [add_left_comm, sub_add_cancel, add_comm]\n\n@[simp] lemma sub_add_sub_cancel' (a b c : G) : (a - b) + (c - a) = c - b :=\nby rw add_comm; apply sub_add_sub_cancel\n\n@[simp] lemma add_sub_sub_cancel (a b c : G) : (a + b) - (a - c) = b + c :=\nby rw [← sub_add, add_sub_cancel']\n\n@[simp] lemma sub_sub_sub_cancel_left (a b c : G) : (c - a) - (c - b) = b - a :=\nby rw [← neg_sub b c, sub_neg_eq_add, add_comm, sub_add_sub_cancel]\n\nlemma sub_eq_sub_iff_add_eq_add : a - b = c - d ↔ a + d = c + b :=\nbegin\n  rw [sub_eq_iff_eq_add, sub_add_eq_add_sub, eq_comm, sub_eq_iff_eq_add'],\n  simp only [add_comm, eq_comm]\nend\n\nlemma sub_eq_sub_iff_sub_eq_sub : a - b = c - d ↔ a - c = b - d :=\nby rw [sub_eq_iff_eq_add, sub_add_eq_add_sub, sub_eq_iff_eq_add', add_sub_assoc]\n\nend add_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/basic.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907010924213, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7501836909746666}}
{"text": "/-\nCopyright (c) 2022 Rishikesh Vaishnav. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nAuthors: Rishikesh Vaishnav\n-/\nimport probability.independence\n\n/-!\n# Conditional Probability\n\nThis file defines conditional probability and includes basic results relating to it.\n\nGiven some measure `μ` defined on a measure space on some type `α` and some `s : set α`,\nwe define the measure of `μ` conditioned on `s` as the restricted measure scaled by\nthe inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling\nensures that this is a probability measure (when `μ` is a finite measure).\n\nFrom this definition, we derive the \"axiomatic\" definition of conditional probability\nbased on application: for any `s t : set α`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`.\n\n## Main Statements\n\n* `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent\n  to conditioning on their intersection.\n* `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`.\n\n## Notations\n\nThis file uses the local notation `μ[|s]` the measure of `μ` conditioned on `s`,\nand `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the\napplication `μ[|s] t`).\n\n## Implementation notes\n\nBecause we have the alternative measure restriction application principles\n`measure.restrict_apply` and `measure.restrict_apply'`, which require \nmeasurability of the restricted and restricting sets, respectively,\nmany of the theorems here will have corresponding alternatives as well.\nFor the sake of brevity, we've chosen to only go with `measure.restrict_apply'`\nfor now, but the alternative theorems can be added if needed.\n\nUse of `@[simp]` generally follows the rule of removing conditions on a measure\nwhen possible.\n\nHypotheses that are used to \"define\" a conditional distribution by requiring that\nthe conditioning set has non-zero measure should be named using the abbreviation\n\"c\" (which stands for \"conditionable\") rather than \"nz\". For example `(hci : μ (s ∩ t) ≠ 0)`\n(rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined.\n\n## Tags\nconditional, conditioned, bayes\n-/\n\nnoncomputable theory\n\nopen measure_theory measurable_space\n\nvariables {α : Type*} {m : measurable_space α} (μ : measure α) {s t : set α}\n\nnamespace probability_theory\n\nsection definitions\n\n/-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s` \nand scaled by the inverse of `μ s` (to make it a probability measure):\n`(μ s)⁻¹ • μ.restrict s`. -/\ndef cond (s : set α) : measure α :=\n  (μ s)⁻¹ • μ.restrict s\n\nend definitions\n\nlocal notation  μ `[` s `|` t `]` := cond μ t s\nlocal notation  μ `[|`:60 t`]` := cond μ t\n\n/-- The conditional probability measure of any finite measure on any set of positive measure\nis a probability measure. -/\nlemma cond_is_probability_measure [is_finite_measure μ] (hcs : μ s ≠ 0) :\n  is_probability_measure $ μ[|s] :=\n⟨by { rw [cond, measure.smul_apply, measure.restrict_apply measurable_set.univ,\n  set.univ_inter], exact ennreal.inv_mul_cancel hcs (measure_ne_top _ s) }⟩\n\nsection bayes\n\n@[simp] lemma cond_univ [is_probability_measure μ] :\n  μ[|set.univ] = μ :=\nby simp [cond, measure_univ, measure.restrict_univ]\n\n/-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/\n@[simp] lemma cond_apply (hms : measurable_set s) (t : set α) :\n  μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) :=\nby { rw [cond, measure.smul_apply, measure.restrict_apply' hms, set.inter_comm], refl }\n\nlemma inter_pos_of_cond_ne_zero (hms : measurable_set s) (hcst : μ[t|s] ≠ 0) :\n  0 < μ (s ∩ t) :=\nbegin\n  refine pos_iff_ne_zero.mpr (right_ne_zero_of_mul _),\n  { exact (μ s)⁻¹ },\n  convert hcst,\n  simp [hms, set.inter_comm]\nend\n\nvariable [is_finite_measure μ]\n\nlemma cond_pos_of_inter_ne_zero (hms : measurable_set s) (hci : μ (s ∩ t) ≠ 0) :\n  0 < μ[|s] t :=\nbegin\n  rw cond_apply _ hms,\n  refine ennreal.mul_pos _ hci,\n  exact ennreal.inv_ne_zero.mpr (measure_ne_top _ _),\nend\n\n/-- Conditioning first on `s` and then on `t` results in the same measure as conditioning\non `s ∩ t`. -/\n@[simp] lemma cond_cond_eq_cond_inter\n  (hms : measurable_set s) (hmt : measurable_set t) (hci : μ (s ∩ t) ≠ 0) :\n  μ[|s][|t] = μ[|s ∩ t] :=\nbegin\n  have := hms.inter hmt,\n  have := measure_ne_top μ s,\n  have hcs : μ s ≠ 0 := (μ.to_outer_measure.pos_of_subset_ne_zero\n    (set.inter_subset_left _ _) hci).ne',\n  ext1,\n  haveI := cond_is_probability_measure μ hcs,\n  simp only [*, cond_apply, ←mul_assoc, ←set.inter_assoc],\n  congr,\n  simp [*, ennreal.mul_inv, mul_comm, ←mul_assoc, ennreal.inv_mul_cancel]\nend\n\n@[simp] lemma cond_mul_eq_inter (hms : measurable_set s) (hcs : μ s ≠ 0) (t : set α) :\n  μ[t|s] * μ s = μ (s ∩ t) :=\nby rw [cond_apply μ hms t, mul_comm, ←mul_assoc,\n  ennreal.mul_inv_cancel hcs (measure_ne_top _ s), one_mul]\n\n/-- **Bayes' Theorem** -/\ntheorem cond_eq_inv_mul_cond_mul (hms : measurable_set s) (hmt : measurable_set t) (ht : μ t ≠ 0) :\n  μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t) :=\nby rw [mul_assoc, cond_mul_eq_inter μ hmt ht s, set.inter_comm, cond_apply _ hms]\n\nend bayes\n\nend probability_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/probability/conditional.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7501422584667478}}
{"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 missing.linear_algebra.matrix.block\n\n/-\n# Triangular Matrices\nThis file defines upper and lower triangular matrices. The definitions are based on\n`matrix.block_triangular`. All properties should ideally be proved for `matrix.block_triangular` in\ngeneral and then specialized to (nonblock)-triangular matrices here.\n-/\n\nnamespace matrix\nopen_locale big_operators\nopen_locale matrix\nvariables {α m n : Type*}\nvariables {R : Type*} [comm_ring R] {M N : matrix m m R}\n\n/-- An upper triangular matrix is a matrix whose entries are zero below the diagonal. -/\ndef upper_triangular [has_lt m] (M : matrix m m R) :=\n  M.block_triangular id\n\n/-- A lower triangular matrix is a matrix whose entries are zero above the diagonal. -/\ndef lower_triangular [has_lt m] (M : matrix m m R) :=\n  M.block_triangular order_dual.to_dual\n\n/-- The inverse of an upper triangular matrix is upper triangular -/\nlemma upper_triangular_inv_of_upper_triangular [fintype m] [linear_order m] [invertible M]\n  (hM : upper_triangular M) : upper_triangular M⁻¹ :=\nblock_triangular_inv_of_block_triangular hM\n\n/-- The inverse of a lower triangular matrix is lower triangular -/\nlemma lower_triangular_inv_of_lower_triangular [fintype m] [linear_order m] [invertible M]\n  (hM : lower_triangular M) : lower_triangular M⁻¹ :=\nblock_triangular_inv_of_block_triangular hM\n\n/-- Multiplication of upper triangular matrices is upper triangular -/\nlemma upper_triangular.mul [fintype m] [linear_order m]\n  (hM : upper_triangular M) (hN : upper_triangular N) : upper_triangular (M ⬝ N) :=\nblock_triangular.mul hM hN\n\n/-- Multiplication of lower triangular matrices is lower triangular -/\nlemma lower_triangular.mul [fintype m] [linear_order m]\n  (hM : lower_triangular M) (hN : lower_triangular N) : lower_triangular (M ⬝ N) :=\nblock_triangular.mul hM hN\n\n/-- Transpose of lower triangular matrix is upper triangular -/\nlemma lower_triangular.transpose [fintype m] [linear_order m]\n  (hM : lower_triangular M) : upper_triangular Mᵀ :=\nhM.transpose\n\n/-- Transpose of upper triangular matrix is lower triangular -/\nlemma upper_triangular.transpose [fintype m] [linear_order m]\n  (hM : upper_triangular M) : lower_triangular Mᵀ :=\nhM.transpose\n\nlemma diag_inv_mul_diag_eq_one_of_upper_triangular [fintype m] [linear_order m] [invertible M]\n  (hM : upper_triangular M) (k : m) : M⁻¹ k k * M k k = 1 :=\nbegin\n  letI : unique {a // id a = k} := ⟨⟨⟨k, rfl⟩⟩, λ j, subtype.ext j.property⟩,\n  simpa [matrix.mul, dot_product, fintype.sum_unique] using\n    congr_fun (congr_fun (to_square_block_inv_mul_to_square_block_eq_one hM k) ⟨k, rfl⟩) ⟨k, rfl⟩,\nend\n\nlemma diag_inv_mul_diag_eq_one_of_lower_triangular [fintype m] [linear_order m] [invertible M]\n  (hM : lower_triangular M) (k : m) : M⁻¹ k k * M k k = 1 :=\nbegin\n  letI : unique {a // order_dual.to_dual a = k} := ⟨⟨⟨k, rfl⟩⟩, λ j, subtype.ext j.property⟩,\n  simpa [matrix.mul, dot_product, fintype.sum_unique] using\n    congr_fun (congr_fun (to_square_block_inv_mul_to_square_block_eq_one hM k) ⟨k, rfl⟩) ⟨k, rfl⟩,\nend\n\nend matrix\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/triangular.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755218, "lm_q2_score": 0.8397339596505965, "lm_q1q2_score": 0.7501422518946592}}
{"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-/\nimport analysis.asymptotics.asymptotic_equivalent\nimport analysis.asymptotics.specific_asymptotics\nimport data.polynomial.ring_division\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 +∞.\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\nopen filter finset asymptotics\nopen_locale asymptotics topological_space\n\nnamespace polynomial\n\nvariables {𝕜 : Type*} [normed_linear_ordered_field 𝕜] (P Q : polynomial 𝕜)\n\nlemma eventually_no_roots (hP : P ≠ 0) : ∀ᶠ x in filter.at_top, ¬ P.is_root x :=\nbegin\n  obtain ⟨x₀, hx₀⟩ := exists_max_root P hP,\n  refine filter.eventually_at_top.mpr (⟨x₀ + 1, λ x hx h, _⟩),\n  exact absurd (hx₀ x h) (not_le.mpr (lt_of_lt_of_le (lt_add_one x₀) hx)),\nend\n\nvariables [order_topology 𝕜]\n\nsection polynomial_at_top\n\nlemma is_equivalent_at_top_lead :\n  (λ x, eval x P) ~[at_top] (λ x, P.leading_coeff * x ^ P.nat_degree) :=\nbegin\n  by_cases h : P = 0,\n  { simp [h] },\n  { conv_lhs\n    { funext,\n      rw [polynomial.eval_eq_finset_sum, sum_range_succ] },\n    exact is_equivalent.refl.add_is_o (is_o.sum $ λ i hi, is_o.const_mul_left\n      (is_o.const_mul_right (λ hz, h $ leading_coeff_eq_zero.mp hz) $\n        is_o_pow_pow_at_top_of_lt (mem_range.mp hi)) _) }\nend\n\nlemma tendsto_at_top_of_leading_coeff_nonneg (hdeg : 1 ≤ P.degree) (hnng : 0 ≤ P.leading_coeff) :\n  tendsto (λ x, eval x P) at_top at_top :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_top\n  (tendsto_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)\n    (lt_of_le_of_ne hnng $ ne.symm $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))\n\nlemma tendsto_at_top_iff_leading_coeff_nonneg :\n  tendsto (λ x, eval x P) at_top at_top ↔ 1 ≤ P.degree ∧ 0 ≤ P.leading_coeff :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_at_top_of_leading_coeff_nonneg P h.1 h.2⟩,\n  have : tendsto (λ x, P.leading_coeff * x ^ P.nat_degree) at_top at_top :=\n    is_equivalent.tendsto_at_top (is_equivalent_at_top_lead P) h,\n  rw tendsto_const_mul_pow_at_top_iff P.leading_coeff P.nat_degree at this,\n  rw [degree_eq_nat_degree (leading_coeff_ne_zero.mp (ne_of_lt this.2).symm), ← nat.cast_one],\n  refine ⟨with_bot.coe_le_coe.mpr this.1, le_of_lt this.2⟩,\nend\n\nlemma tendsto_at_bot_of_leading_coeff_nonpos (hdeg : 1 ≤ P.degree) (hnps : P.leading_coeff ≤ 0) :\n  tendsto (λ x, eval x P) at_top at_bot :=\nP.is_equivalent_at_top_lead.symm.tendsto_at_bot\n  (tendsto_neg_const_mul_pow_at_top (le_nat_degree_of_coe_le_degree hdeg)\n    (lt_of_le_of_ne hnps $ mt leading_coeff_eq_zero.mp $ ne_zero_of_coe_le_degree hdeg))\n\nlemma tendsto_at_bot_iff_leading_coeff_nonpos :\n  tendsto (λ x, eval x P) at_top at_bot ↔ 1 ≤ P.degree ∧ P.leading_coeff ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, tendsto_at_bot_of_leading_coeff_nonpos P h.1 h.2⟩,\n  have : tendsto (λ x, P.leading_coeff * x ^ P.nat_degree) at_top at_bot :=\n    (is_equivalent.tendsto_at_bot (is_equivalent_at_top_lead P) h),\n  rw tendsto_neg_const_mul_pow_at_top_iff P.leading_coeff P.nat_degree at this,\n  rw [degree_eq_nat_degree (leading_coeff_ne_zero.mp (ne_of_lt this.2)), ← nat.cast_one],\n  refine ⟨with_bot.coe_le_coe.mpr this.1, le_of_lt this.2⟩,\nend\n\nlemma abs_tendsto_at_top (hdeg : 1 ≤ P.degree) :\n  tendsto (λ x, abs $ eval x P) at_top at_top :=\nbegin\n  by_cases hP : 0 ≤ P.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.tendsto_at_top_of_leading_coeff_nonneg hdeg hP)},\n  { push_neg at hP,\n    exact tendsto_abs_at_bot_at_top.comp (P.tendsto_at_bot_of_leading_coeff_nonpos hdeg hP.le)}\nend\n\nlemma abs_is_bounded_under_iff :\n  is_bounded_under (≤) at_top (λ x, |eval x P|) ↔ P.degree ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, ⟨|P.coeff 0|, eventually_map.mpr (eventually_of_forall\n    (forall_imp (λ _, le_of_eq) (λ x, congr_arg abs $ trans (congr_arg (eval x)\n    (eq_C_of_degree_le_zero h)) (eval_C))))⟩⟩,\n  contrapose! h,\n  exact not_is_bounded_under_of_tendsto_at_top\n    (abs_tendsto_at_top P (nat.with_bot.one_le_iff_zero_lt.2 h))\nend\n\nlemma abs_tendsto_at_top_iff :\n  tendsto (λ x, abs $ eval x P) at_top at_top ↔ 1 ≤ P.degree :=\n⟨λ h, nat.with_bot.one_le_iff_zero_lt.2 (not_le.mp ((mt (abs_is_bounded_under_iff P).mpr)\n  (not_is_bounded_under_of_tendsto_at_top h))), abs_tendsto_at_top P⟩\n\nlemma tendsto_nhds_iff {c : 𝕜} :\n  tendsto (λ x, eval x P) at_top (𝓝 c) ↔ P.leading_coeff = c ∧ P.degree ≤ 0 :=\nbegin\n  refine ⟨λ h, _, λ h, _⟩,\n  { have := P.is_equivalent_at_top_lead.tendsto_nhds h,\n    by_cases hP : P.leading_coeff = 0,\n    { simp only [hP, zero_mul, tendsto_const_nhds_iff] at this,\n      refine ⟨trans hP this, by simp [leading_coeff_eq_zero.1 hP]⟩ },\n    { rw [tendsto_const_mul_pow_nhds_iff hP, nat_degree_eq_zero_iff_degree_le_zero] at this,\n      exact this.symm } },\n  { 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 }\nend\n\nend polynomial_at_top\n\nsection polynomial_div_at_top\n\nlemma is_equivalent_at_top_div :\n  (λ x, (eval x P)/(eval x Q)) ~[at_top]\n    λ x, P.leading_coeff/Q.leading_coeff * x^(P.nat_degree - Q.nat_degree : ℤ) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP] },\n  by_cases hQ : Q = 0,\n  { simp [hQ] },\n  refine (P.is_equivalent_at_top_lead.symm.div\n          Q.is_equivalent_at_top_lead.symm).symm.trans\n         (eventually_eq.is_equivalent ((eventually_gt_at_top 0).mono $ λ x hx, _)),\n  simp [← div_mul_div, hP, hQ, zpow_sub₀ hx.ne.symm]\nend\n\nlemma div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) :=\nbegin\n  by_cases hP : P = 0,\n  { simp [hP, tendsto_const_nhds] },\n  rw ←  nat_degree_lt_nat_degree_iff hP at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw ← mul_zero,\n  refine (tendsto_zpow_at_top_zero _).const_mul _,\n  linarith\nend\n\nlemma div_tendsto_zero_iff_degree_lt (hQ : Q ≠ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 0) ↔ P.degree < Q.degree :=\nbegin\n  refine ⟨λ h, _, div_tendsto_zero_of_degree_lt P Q⟩,\n  by_cases hPQ : P.leading_coeff / Q.leading_coeff = 0,\n  { simp only [div_eq_mul_inv, inv_eq_zero, mul_eq_zero] at hPQ,\n    cases hPQ with hP0 hQ0,\n    { rw [leading_coeff_eq_zero.1 hP0, degree_zero],\n      exact bot_lt_iff_ne_bot.2 (λ hQ', hQ (degree_eq_bot.1 hQ')) },\n    { exact absurd (leading_coeff_eq_zero.1 hQ0) hQ } },\n  { have := (is_equivalent_at_top_div P Q).tendsto_nhds h,\n    rw tendsto_const_mul_zpow_at_top_zero_iff hPQ at this,\n    cases this with h h,\n    { exact absurd h.2 hPQ },\n    { rw [sub_lt_iff_lt_add, zero_add, int.coe_nat_lt] at h,\n      exact degree_lt_degree h.1 } }\nend\n\nlemma div_tendsto_leading_coeff_div_of_degree_eq (hdeg : P.degree = Q.degree) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top (𝓝 $ P.leading_coeff / Q.leading_coeff) :=\nbegin\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_nhds _,\n  rw show (P.nat_degree : ℤ) = Q.nat_degree, by simp [hdeg, nat_degree],\n  simp [tendsto_const_nhds]\nend\n\nlemma div_tendsto_at_top_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hpos : 0 < P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hpos, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_top _,\n  apply tendsto.const_mul_at_top hpos,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnng : 0 ≤ P.leading_coeff/Q.leading_coeff) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_top :=\nhave ratio_pos : 0 < P.leading_coeff/Q.leading_coeff,\n  from lt_of_le_of_ne hnng\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)).symm,\ndiv_tendsto_at_top_of_degree_gt' P Q hdeg ratio_pos\n\nlemma div_tendsto_at_bot_of_degree_gt' (hdeg : Q.degree < P.degree)\n  (hneg : P.leading_coeff/Q.leading_coeff < 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nbegin\n  have hQ : Q ≠ 0 := λ h, by {simp only [h, div_zero, leading_coeff_zero] at hneg, linarith},\n  rw ← nat_degree_lt_nat_degree_iff hQ at hdeg,\n  refine (is_equivalent_at_top_div P Q).symm.tendsto_at_bot _,\n  apply tendsto.neg_const_mul_at_top hneg,\n  apply tendsto_zpow_at_top_at_top,\n  linarith\nend\n\nlemma div_tendsto_at_bot_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) (hnps : P.leading_coeff/Q.leading_coeff ≤ 0) :\n  tendsto (λ x, (eval x P)/(eval x Q)) at_top at_bot :=\nhave ratio_neg : P.leading_coeff/Q.leading_coeff < 0,\n  from lt_of_le_of_ne hnps\n    (div_ne_zero (λ h, ne_zero_of_degree_gt hdeg $ leading_coeff_eq_zero.mp h)\n      (λ h, hQ $ leading_coeff_eq_zero.mp h)),\ndiv_tendsto_at_bot_of_degree_gt' P Q hdeg ratio_neg\n\nlemma abs_div_tendsto_at_top_of_degree_gt (hdeg : Q.degree < P.degree)\n  (hQ : Q ≠ 0) :\n  tendsto (λ x, |(eval x P)/(eval x Q)|) at_top at_top :=\nbegin\n  by_cases h : 0 ≤ P.leading_coeff/Q.leading_coeff,\n  { exact tendsto_abs_at_top_at_top.comp (P.div_tendsto_at_top_of_degree_gt Q hdeg hQ h) },\n  { 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) }\nend\n\nend polynomial_div_at_top\n\ntheorem is_O_of_degree_le (h : P.degree ≤ Q.degree) :\n  is_O (λ x, eval x P) (λ x, eval x Q) filter.at_top :=\nbegin\n  by_cases hp : P = 0,\n  { simpa [hp] using is_O_zero (λ x, eval x Q) filter.at_top },\n  { have hq : Q ≠ 0 := ne_zero_of_degree_ge_degree h hp,\n    have hPQ : ∀ᶠ (x : 𝕜) in at_top, eval x Q = 0 → eval x P = 0 :=\n      filter.mem_of_superset (polynomial.eventually_no_roots Q hq) (λ x h h', absurd h' h),\n    cases le_iff_lt_or_eq.mp h with h h,\n    { exact is_O_of_div_tendsto_nhds hPQ 0 (div_tendsto_zero_of_degree_lt P Q h) },\n    { exact is_O_of_div_tendsto_nhds hPQ _ (div_tendsto_leading_coeff_div_of_degree_eq P Q 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/analysis/special_functions/polynomials.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7501422453431515}}
{"text": "-- Limite_de_sucesiones_constantes.lean\n-- Límite de sucesiones constantes.\n-- José A. Alonso Jiménez\n-- Sevilla, 11 de julio de 2021\n-- ---------------------------------------------------------------------\n\n-- ---------------------------------------------------------------------\n-- En Lean, una sucesión u₀, u₁, u₂, ... se puede representar mediante\n-- una función (u : ℕ → ℝ) de forma que u(n) es uₙ.\n--\n-- Se define que a es el límite de la sucesión u, por\n--    def limite : (ℕ → ℝ) → ℝ → Prop :=\n--    λ u a, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - a| < ε\n-- donde se usa la notación |x| para el valor absoluto de x\n--    notation `|`x`|` := abs x\n--\n-- Demostrar que el límite de la sucesión constante c es c.\n-- ---------------------------------------------------------------------\n\nimport data.real.basic\n\nvariable (u : ℕ → ℝ)\nvariable (c : ℝ)\n\nnotation `|`x`|` := abs x\n\ndef limite : (ℕ → ℝ) → ℝ → Prop :=\nλ u a, ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - a| < ε\n\n-- 1ª demostración\n-- ===============\n\nexample :\n  limite (λ n, c) c :=\nbegin\n  unfold limite,\n  intros ε hε,\n  use 0,\n  intros n hn,\n  dsimp,\n  simp,\n  exact hε,\nend\n\n-- 2ª demostración\n-- ===============\n\nexample :\n  limite (λ n, c) c :=\nbegin\n  intros ε hε,\n  use 0,\n  rintro n -,\n  norm_num,\n  assumption,\nend\n\n-- 3ª demostración\n-- ===============\n\nexample :\n  limite (λ n, c) c :=\nbegin\n  intros ε hε,\n  use 0,\n  intros n hn,\n  calc |(λ n, c) n - c|\n       = |c - c|  : rfl\n   ... = 0        : by simp\n   ... < ε        : hε\nend\n\n-- 4ª demostración\n-- ===============\n\nexample :\n  limite (λ n, c) c :=\nbegin\n  intros ε hε,\n  by finish,\nend\n\n-- 5ª demostración\n-- ===============\n\nexample :\n  limite (λ n, c) c :=\nλ ε hε, by finish\n\n-- 6ª demostración\n-- ===============\n\nexample :\n  limite (λ n, c) c :=\nassume ε,\nassume hε : ε > 0,\nexists.intro 0\n  ( assume n,\n    assume hn : n ≥ 0,\n    show |(λ n, c) n - c| < ε, from\n      calc |(λ n, c) n - c|\n           = |c - c|  : rfl\n       ... = 0        : by simp\n       ... < ε        : hε)\n", "meta": {"author": "jaalonso", "repo": "Calculemus", "sha": "0fb664ab298c0e90b4b8034729a2cdad20503e18", "save_path": "github-repos/lean/jaalonso-Calculemus", "path": "github-repos/lean/jaalonso-Calculemus/Calculemus-0fb664ab298c0e90b4b8034729a2cdad20503e18/src/Limite_de_sucesiones_constantes.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735663, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7501422417602471}}
{"text": "/-\nCopyright (c) 2018 Sébastien Gouëzel. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\nIsometries of emetric and metric spaces\nAuthors: Sébastien Gouëzel\n-/\nimport topology.metric_space.antilipschitz\n\n/-!\n# Isometries\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\nnoncomputable theory\n\nuniverses u v w\nvariables {α : Type u} {β : Type v} {γ : Type w}\n\nopen function set\nopen_locale topological_space\n\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 [pseudo_emetric_space α] [pseudo_emetric_space β] (f : α → β) : Prop :=\n∀x1 x2 : α, edist (f x1) (f x2) = edist x1 x2\n\n/-- On pseudometric spaces, a map is an isometry if and only if it preserves distances. -/\nlemma isometry_emetric_iff_metric [pseudo_metric_space α] [pseudo_metric_space β] {f : α → β} :\n  isometry f ↔ (∀x y, dist (f x) (f y) = dist x y) :=\n⟨assume H x y, by simp [dist_edist, H x y],\nassume H x y, by simp [edist_dist, H x y]⟩\n\n/-- An isometry preserves edistances. -/\ntheorem isometry.edist_eq [pseudo_emetric_space α] [pseudo_emetric_space β] {f : α → β}\n  (hf : isometry f) (x y : α) : edist (f x) (f y) = edist x y :=\nhf x y\n\n/-- An isometry preserves distances. -/\ntheorem isometry.dist_eq [pseudo_metric_space α] [pseudo_metric_space β] {f : α → β}\n  (hf : isometry f) (x y : α) : dist (f x) (f y) = dist x y :=\nby rw [dist_edist, dist_edist, hf]\n\nsection pseudo_emetric_isometry\n\nvariables [pseudo_emetric_space α] [pseudo_emetric_space β] [pseudo_emetric_space γ]\nvariables {f : α → β} {x y z : α}  {s : set α}\n\nlemma isometry.lipschitz (h : isometry f) : lipschitz_with 1 f :=\nlipschitz_with.of_edist_le $ λ x y, le_of_eq (h x y)\n\nlemma isometry.antilipschitz (h : isometry f) : antilipschitz_with 1 f :=\nλ x y, by simp only [h x y, ennreal.coe_one, one_mul, le_refl]\n\n/-- An isometry from an emetric space is injective -/\nlemma isometry.injective {α : Type u} [emetric_space α] {f : α → β} (h : isometry f) :\n  injective f := h.antilipschitz.injective\n\n/-- Any map on a subsingleton is an isometry -/\ntheorem isometry_subsingleton [subsingleton α] : isometry f :=\nλx y, by rw subsingleton.elim x y; simp\n\n/-- The identity is an isometry -/\nlemma isometry_id : isometry (id : α → α) :=\nλx y, rfl\n\n/-- The composition of isometries is an isometry -/\ntheorem isometry.comp {g : β → γ} {f : α → β} (hg : isometry g) (hf : isometry f) :\n  isometry (g ∘ f) :=\nassume x y, calc\n  edist ((g ∘ f) x) ((g ∘ f) y) = edist (f x) (f y) : hg _ _\n                            ... = edist x y : hf _ _\n\n/-- An isometry from a metric space is a uniform inducing map -/\ntheorem isometry.uniform_inducing (hf : isometry f) :\n  uniform_inducing f :=\nhf.antilipschitz.uniform_inducing hf.lipschitz.uniform_continuous\n\n/-- An isometry is continuous. -/\nlemma isometry.continuous (hf : isometry f) : continuous f :=\nhf.lipschitz.continuous\n\n/-- The right inverse of an isometry is an isometry. -/\nlemma isometry.right_inv {f : α → β} {g : β → α} (h : isometry f) (hg : right_inverse g f) :\n  isometry g :=\nλ x y, by rw [← h, hg _, hg _]\n\n/-- Isometries preserve the diameter in pseudoemetric spaces. -/\nlemma isometry.ediam_image (hf : isometry f) (s : set α) :\n  emetric.diam (f '' s) = emetric.diam s :=\neq_of_forall_ge_iff $ λ d,\nby simp only [emetric.diam_le_iff, ball_image_iff, hf.edist_eq]\n\nlemma isometry.ediam_range (hf : isometry f) :\n  emetric.diam (range f) = emetric.diam (univ : set α) :=\nby { rw ← image_univ, exact hf.ediam_image univ }\n\n/-- The injection from a subtype is an isometry -/\nlemma isometry_subtype_coe {s : set α} : isometry (coe : s → α) :=\nλx y, rfl\n\nlemma isometry.comp_continuous_on_iff {γ} [topological_space γ] (hf : isometry f) {g : γ → α}\n  {s : set γ} :\n  continuous_on (f ∘ g) s ↔ continuous_on g s :=\nhf.uniform_inducing.inducing.continuous_on_iff.symm\n\nlemma isometry.comp_continuous_iff {γ} [topological_space γ] (hf : isometry f) {g : γ → α} :\n  continuous (f ∘ g) ↔ continuous g :=\nhf.uniform_inducing.inducing.continuous_iff.symm\n\nend pseudo_emetric_isometry --section\n\nsection emetric_isometry\nvariables [emetric_space α]\n\n/-- An isometry from a metric space is a uniform embedding -/\ntheorem isometry.uniform_embedding [pseudo_emetric_space β] {f : α → β} (hf : isometry f) :\n  uniform_embedding f :=\nhf.antilipschitz.uniform_embedding hf.lipschitz.uniform_continuous\n\n/-- An isometry from a metric space is an embedding -/\ntheorem isometry.embedding [pseudo_emetric_space β] {f : α → β} (hf : isometry f) :\n  embedding f :=\nhf.uniform_embedding.embedding\n\n/-- An isometry from a complete emetric space is a closed embedding -/\ntheorem isometry.closed_embedding [complete_space α] [emetric_space β]\n  {f : α → β} (hf : isometry f) : closed_embedding f :=\nhf.antilipschitz.closed_embedding hf.lipschitz.uniform_continuous\n\nlemma isometry.tendsto_nhds_iff [emetric_space β] {ι : Type*} {f : α → β}\n  {g : ι → α} {a : filter ι} {b : α} (hf : isometry f) :\n  filter.tendsto g a (𝓝 b) ↔ filter.tendsto (f ∘ g) a (𝓝 (f b)) :=\nhf.embedding.tendsto_nhds_iff\n\nend emetric_isometry --section\n\n/-- An isometry preserves the diameter in pseudometric spaces. -/\nlemma isometry.diam_image [pseudo_metric_space α] [pseudo_metric_space β]\n  {f : α → β} (hf : isometry f) (s : set α) : metric.diam (f '' s) = metric.diam s :=\nby rw [metric.diam, metric.diam, hf.ediam_image]\n\nlemma isometry.diam_range [pseudo_metric_space α] [pseudo_metric_space β] {f : α → β}\n  (hf : isometry f) : metric.diam (range f) = metric.diam (univ : set α) :=\nby { rw ← image_univ, exact hf.diam_image univ }\n\n/-- `α` and `β` are isometric if there is an isometric bijection between them. -/\n@[nolint has_inhabited_instance] -- such a bijection need not exist\nstructure isometric (α : Type*) (β : Type*) [pseudo_emetric_space α] [pseudo_emetric_space β]\n  extends α ≃ β :=\n(isometry_to_fun  : isometry to_fun)\n\ninfix ` ≃ᵢ `:25 := isometric\n\nnamespace isometric\n\nsection pseudo_emetric_space\nvariables [pseudo_emetric_space α] [pseudo_emetric_space β] [pseudo_emetric_space γ]\n\ninstance : has_coe_to_fun (α ≃ᵢ β) (λ _, α → β) := ⟨λe, e.to_equiv⟩\n\nlemma coe_eq_to_equiv (h : α ≃ᵢ β) (a : α) : h a = h.to_equiv a := rfl\n\n@[simp] lemma coe_to_equiv (h : α ≃ᵢ β) : ⇑h.to_equiv = h := rfl\n\nprotected lemma isometry (h : α ≃ᵢ β) : isometry h := h.isometry_to_fun\n\nprotected lemma bijective (h : α ≃ᵢ β) : bijective h := h.to_equiv.bijective\nprotected lemma injective (h : α ≃ᵢ β) : injective h := h.to_equiv.injective\nprotected lemma surjective (h : α ≃ᵢ β) : surjective h := h.to_equiv.surjective\n\nprotected lemma edist_eq (h : α ≃ᵢ β) (x y : α) : edist (h x) (h y) = edist x y :=\nh.isometry.edist_eq x y\n\nprotected lemma dist_eq {α β : Type*} [pseudo_metric_space α] [pseudo_metric_space β] (h : α ≃ᵢ β)\n  (x y : α) : dist (h x) (h y) = dist x y :=\nh.isometry.dist_eq x y\n\nprotected lemma continuous (h : α ≃ᵢ β) : continuous h := h.isometry.continuous\n\n@[simp] lemma ediam_image (h : α ≃ᵢ β) (s : set α) : emetric.diam (h '' s) = emetric.diam s :=\nh.isometry.ediam_image s\n\nlemma to_equiv_inj : ∀ ⦃h₁ h₂ : α ≃ᵢ β⦄, (h₁.to_equiv = h₂.to_equiv) → h₁ = h₂\n| ⟨e₁, h₁⟩ ⟨e₂, h₂⟩ H := by { dsimp at H, subst e₁ }\n\n@[ext] lemma ext ⦃h₁ h₂ : α ≃ᵢ β⦄ (H : ∀ x, h₁ x = h₂ x) : h₁ = h₂ :=\nto_equiv_inj $ equiv.ext H\n\n/-- Alternative constructor for isometric bijections,\ntaking as input an isometry, and a right inverse. -/\ndef mk' {α : Type u} [emetric_space α] (f : α → β) (g : β → α) (hfg : ∀ x, f (g x) = x)\n  (hf : isometry f) : α ≃ᵢ β :=\n{ to_fun := f,\n  inv_fun := g,\n  left_inv := λ x, hf.injective $ hfg _,\n  right_inv := hfg,\n  isometry_to_fun := hf }\n\n/-- The identity isometry of a space. -/\nprotected def refl (α : Type*) [pseudo_emetric_space α] : α ≃ᵢ α :=\n{ isometry_to_fun := isometry_id, .. equiv.refl α }\n\n/-- The composition of two isometric isomorphisms, as an isometric isomorphism. -/\nprotected def trans (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) : α ≃ᵢ γ :=\n{ isometry_to_fun  := h₂.isometry_to_fun.comp h₁.isometry_to_fun,\n  .. equiv.trans h₁.to_equiv h₂.to_equiv }\n\n@[simp] lemma trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : α) : h₁.trans h₂ x = h₂ (h₁ x) := rfl\n\n/-- The inverse of an isometric isomorphism, as an isometric isomorphism. -/\nprotected def symm (h : α ≃ᵢ β) : β ≃ᵢ α :=\n{ isometry_to_fun  := h.isometry.right_inv h.right_inv,\n  to_equiv := h.to_equiv.symm }\n\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 : α ≃ᵢ β) : α → β := h\n/-- See Note [custom simps projection] -/\ndef simps.symm_apply (h : α ≃ᵢ β) : β → α := h.symm\n\ninitialize_simps_projections isometric\n  (to_equiv_to_fun → apply, to_equiv_inv_fun → symm_apply)\n\n@[simp] lemma symm_symm (h : α ≃ᵢ β) : h.symm.symm = h := to_equiv_inj h.to_equiv.symm_symm\n\n@[simp] lemma apply_symm_apply (h : α ≃ᵢ β) (y : β) : h (h.symm y) = y :=\nh.to_equiv.apply_symm_apply y\n\n@[simp] lemma symm_apply_apply (h : α ≃ᵢ β) (x : α) : h.symm (h x) = x :=\nh.to_equiv.symm_apply_apply x\n\nlemma symm_apply_eq (h : α ≃ᵢ β) {x : α} {y : β} :\n  h.symm y = x ↔ y = h x :=\nh.to_equiv.symm_apply_eq\n\nlemma eq_symm_apply (h : α ≃ᵢ β) {x : α} {y : β} :\n  x = h.symm y ↔ h x = y :=\nh.to_equiv.eq_symm_apply\n\nlemma symm_comp_self (h : α ≃ᵢ β) : ⇑h.symm ∘ ⇑h = id :=\nfunext $ assume a, h.to_equiv.left_inv a\n\nlemma self_comp_symm (h : α ≃ᵢ β) : ⇑h ∘ ⇑h.symm = id :=\nfunext $ assume a, h.to_equiv.right_inv a\n\n@[simp] lemma range_eq_univ (h : α ≃ᵢ β) : range h = univ :=\nh.to_equiv.range_eq_univ\n\nlemma image_symm (h : α ≃ᵢ β) : 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 : α ≃ᵢ β) : preimage h.symm = image h :=\n(image_eq_preimage_of_inverse h.to_equiv.left_inv h.to_equiv.right_inv).symm\n\n@[simp] lemma symm_trans_apply (h₁ : α ≃ᵢ β) (h₂ : β ≃ᵢ γ) (x : γ) :\n  (h₁.trans h₂).symm x = h₁.symm (h₂.symm x) := rfl\n\nlemma ediam_univ (h : α ≃ᵢ β) : emetric.diam (univ : set α) = emetric.diam (univ : set β) :=\nby rw [← h.range_eq_univ, h.isometry.ediam_range]\n\n@[simp] lemma ediam_preimage (h : α ≃ᵢ β) (s : set β) : emetric.diam (h ⁻¹' s) = emetric.diam s :=\nby rw [← image_symm, ediam_image]\n\n/-- The (bundled) homeomorphism associated to an isometric isomorphism. -/\n@[simps to_equiv] protected def to_homeomorph (h : α ≃ᵢ β) : α ≃ₜ β :=\n{ continuous_to_fun  := h.continuous,\n  continuous_inv_fun := h.symm.continuous,\n  to_equiv := h.to_equiv }\n\n@[simp] lemma coe_to_homeomorph (h : α ≃ᵢ β) : ⇑(h.to_homeomorph) = h := rfl\n\n@[simp] lemma coe_to_homeomorph_symm (h : α ≃ᵢ β) : ⇑(h.to_homeomorph.symm) = h.symm := rfl\n\n@[simp] lemma comp_continuous_on_iff {γ} [topological_space γ] (h : α ≃ᵢ β)\n  {f : γ → α} {s : set γ} :\n  continuous_on (h ∘ f) s ↔ continuous_on f s :=\nh.to_homeomorph.comp_continuous_on_iff _ _\n\n@[simp] lemma comp_continuous_iff {γ} [topological_space γ] (h : α ≃ᵢ β) {f : γ → α} :\n  continuous (h ∘ f) ↔ continuous f :=\nh.to_homeomorph.comp_continuous_iff\n\n@[simp] lemma comp_continuous_iff' {γ} [topological_space γ] (h : α ≃ᵢ β) {f : β → γ} :\n  continuous (f ∘ h) ↔ continuous f :=\nh.to_homeomorph.comp_continuous_iff'\n\n/-- The group of isometries. -/\ninstance : group (α ≃ᵢ α) :=\n  { one := isometric.refl _,\n    mul := λ e₁ e₂, e₂.trans e₁,\n    inv := isometric.symm,\n    mul_assoc := λ e₁ e₂ e₃, rfl,\n    one_mul := λ e, ext $ λ _, rfl,\n    mul_one := λ e, ext $ λ _, rfl,\n    mul_left_inv := λ e, ext e.symm_apply_apply }\n\n@[simp] lemma coe_one : ⇑(1 : α ≃ᵢ α) = id := rfl\n\n@[simp] lemma coe_mul (e₁ e₂ : α ≃ᵢ α) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl\n\nlemma mul_apply (e₁ e₂ : α ≃ᵢ α) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) := rfl\n\n@[simp] lemma inv_apply_self (e : α ≃ᵢ α) (x: α) : e⁻¹ (e x) = x := e.symm_apply_apply x\n\n@[simp] lemma apply_inv_self (e : α ≃ᵢ α) (x: α) : e (e⁻¹ x) = x := e.apply_symm_apply x\n\nprotected lemma complete_space [complete_space β] (e : α ≃ᵢ β) : complete_space α :=\ncomplete_space_of_is_complete_univ $ is_complete_of_complete_image e.isometry.uniform_inducing $\n  by rwa [set.image_univ, isometric.range_eq_univ, ← complete_space_iff_is_complete_univ]\n\nlemma complete_space_iff (e : α ≃ᵢ β) : complete_space α ↔ complete_space β :=\nby { split; introI H, exacts [e.symm.complete_space, e.complete_space] }\n\nend pseudo_emetric_space\n\nsection pseudo_metric_space\n\nvariables [pseudo_metric_space α] [pseudo_metric_space β] (h : α ≃ᵢ β)\n\n@[simp] lemma diam_image (s : set α) : metric.diam (h '' s) = metric.diam s :=\nh.isometry.diam_image s\n\n@[simp] lemma diam_preimage (s : set β) : metric.diam (h ⁻¹' s) = metric.diam s :=\nby rw [← image_symm, diam_image]\n\nlemma diam_univ : metric.diam (univ : set α) = metric.diam (univ : set β) :=\ncongr_arg ennreal.to_real h.ediam_univ\n\nend pseudo_metric_space\n\nend isometric\n\n/-- An isometry induces an isometric isomorphism between the source space and the\nrange of the isometry. -/\n@[simps to_equiv apply { simp_rhs := tt }]\ndef isometry.isometric_on_range [emetric_space α] [pseudo_emetric_space β] {f : α → β}\n  (h : isometry f) : α ≃ᵢ range f :=\n{ isometry_to_fun := λx y, by simpa [subtype.edist_eq] using h x y,\n  to_equiv := equiv.of_injective f h.injective }\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/isometry.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8633916205190225, "lm_q1q2_score": 0.7501377553541155}}
{"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 4c19a16e4b705bf135cf9a80ac18fcc99c438514\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.Order.UpperLower.Basic\nimport Mathbin.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□□□□□\n□□□\n□□□\n□\n```\nThis Young diagram corresponds to the [5, 3, 3, 1] partition of 12.\n\nWe represent it as a lower set in `ℕ × ℕ` in the product partial order. We write `(i, j) ∈ μ`\nto say that `(i, j)` (in matrix coordinates) is in the Young diagram `μ`.\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 `(⊥ : 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) ≤ (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\n\nopen Function\n\n#print YoungDiagram /-\n/-- A Young diagram is a finite collection of cells on the `ℕ × ℕ` 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 `ℕ × ℕ` that are lower sets with respect to the\nstandard order on products. -/\n@[ext]\nstructure YoungDiagram where\n  cells : Finset (ℕ × ℕ)\n  IsLowerSet : IsLowerSet (cells : Set (ℕ × ℕ))\n#align young_diagram YoungDiagram\n-/\n\nnamespace YoungDiagram\n\ninstance : SetLike YoungDiagram (ℕ × ℕ)\n    where\n  coe := coe YoungDiagram.cells\n  coe_injective' μ ν h := by rwa [YoungDiagram.ext_iff, ← Finset.coe_inj]\n\n#print YoungDiagram.mem_cells /-\n@[simp]\ntheorem mem_cells {μ : YoungDiagram} (c : ℕ × ℕ) : c ∈ μ.cells ↔ c ∈ μ :=\n  Iff.rfl\n#align young_diagram.mem_cells YoungDiagram.mem_cells\n-/\n\n#print YoungDiagram.mem_mk /-\n@[simp]\ntheorem mem_mk (c : ℕ × ℕ) (cells) (is_lower_set) :\n    c ∈ YoungDiagram.mk cells IsLowerSet ↔ c ∈ cells :=\n  Iff.rfl\n#align young_diagram.mem_mk YoungDiagram.mem_mk\n-/\n\n#print YoungDiagram.decidableMem /-\ninstance decidableMem (μ : YoungDiagram) : DecidablePred (· ∈ μ) :=\n  show DecidablePred (· ∈ μ.cells) by infer_instance\n#align young_diagram.decidable_mem YoungDiagram.decidableMem\n-/\n\n#print YoungDiagram.up_left_mem /-\n/-- In \"English notation\", a Young diagram is drawn so that (i1, j1) ≤ (i2, j2)\n    means (i1, j1) is weakly up-and-left of (i2, j2). -/\ntheorem up_left_mem (μ : YoungDiagram) {i1 i2 j1 j2 : ℕ} (hi : i1 ≤ i2) (hj : j1 ≤ j2)\n    (hcell : (i2, j2) ∈ μ) : (i1, j1) ∈ μ :=\n  μ.IsLowerSet (Prod.mk_le_mk.mpr ⟨hi, hj⟩) hcell\n#align young_diagram.up_left_mem YoungDiagram.up_left_mem\n-/\n\nsection DistribLattice\n\n/- warning: young_diagram.cells_subset_iff -> YoungDiagram.cells_subset_iff is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, Iff (HasSubset.Subset.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasSubset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells μ) (YoungDiagram.cells ν)) (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) μ ν)\nbut is expected to have type\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, Iff (HasSubset.Subset.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instHasSubsetFinset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells μ) (YoungDiagram.cells ν)) (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.instPartialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat))) μ ν)\nCase conversion may be inaccurate. Consider using '#align young_diagram.cells_subset_iff YoungDiagram.cells_subset_iffₓ'. -/\n@[simp]\ntheorem cells_subset_iff {μ ν : YoungDiagram} : μ.cells ⊆ ν.cells ↔ μ ≤ ν :=\n  Iff.rfl\n#align young_diagram.cells_subset_iff YoungDiagram.cells_subset_iff\n\n/- warning: young_diagram.cells_ssubset_iff -> YoungDiagram.cells_ssubset_iff is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, Iff (HasSSubset.SSubset.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasSsubset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells μ) (YoungDiagram.cells ν)) (LT.lt.{0} YoungDiagram (Preorder.toLT.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) μ ν)\nbut is expected to have type\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, Iff (HasSSubset.SSubset.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instHasSSubsetFinset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells μ) (YoungDiagram.cells ν)) (LT.lt.{0} YoungDiagram (Preorder.toLT.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.instPartialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat))) μ ν)\nCase conversion may be inaccurate. Consider using '#align young_diagram.cells_ssubset_iff YoungDiagram.cells_ssubset_iffₓ'. -/\n@[simp]\ntheorem cells_ssubset_iff {μ ν : YoungDiagram} : μ.cells ⊂ ν.cells ↔ μ < ν :=\n  Iff.rfl\n#align young_diagram.cells_ssubset_iff YoungDiagram.cells_ssubset_iff\n\ninstance : Sup YoungDiagram\n    where sup μ ν :=\n    { cells := μ.cells ∪ ν.cells\n      IsLowerSet := by\n        rw [Finset.coe_union]\n        exact μ.is_lower_set.union ν.is_lower_set }\n\n/- warning: young_diagram.cells_sup -> YoungDiagram.cells_sup is a dubious translation:\nlean 3 declaration is\n  forall (μ : YoungDiagram) (ν : YoungDiagram), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells (Sup.sup.{0} YoungDiagram YoungDiagram.hasSup μ ν)) (Union.union.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasUnion.{0} (Prod.{0, 0} Nat Nat) (fun (a : Prod.{0, 0} Nat Nat) (b : Prod.{0, 0} Nat Nat) => Prod.decidableEq.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) a b)) (YoungDiagram.cells μ) (YoungDiagram.cells ν))\nbut is expected to have type\n  forall (μ : YoungDiagram) (ν : YoungDiagram), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells (Sup.sup.{0} YoungDiagram YoungDiagram.instSupYoungDiagram μ ν)) (Union.union.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instUnionFinset.{0} (Prod.{0, 0} Nat Nat) (fun (a : Prod.{0, 0} Nat Nat) (b : Prod.{0, 0} Nat Nat) => instDecidableEqProd.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) a b)) (YoungDiagram.cells μ) (YoungDiagram.cells ν))\nCase conversion may be inaccurate. Consider using '#align young_diagram.cells_sup YoungDiagram.cells_supₓ'. -/\n@[simp]\ntheorem cells_sup (μ ν : YoungDiagram) : (μ ⊔ ν).cells = μ.cells ∪ ν.cells :=\n  rfl\n#align young_diagram.cells_sup YoungDiagram.cells_sup\n\n/- warning: young_diagram.coe_sup -> YoungDiagram.coe_sup is a dubious translation:\nlean 3 declaration is\n  forall (μ : YoungDiagram) (ν : YoungDiagram), Eq.{1} (Set.{0} (Prod.{0, 0} Nat Nat)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (HasLiftT.mk.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (CoeTCₓ.coe.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (SetLike.Set.hasCoeT.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) (Sup.sup.{0} YoungDiagram YoungDiagram.hasSup μ ν)) (Union.union.{0} (Set.{0} (Prod.{0, 0} Nat Nat)) (Set.hasUnion.{0} (Prod.{0, 0} Nat Nat)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (HasLiftT.mk.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (CoeTCₓ.coe.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (SetLike.Set.hasCoeT.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) μ) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (HasLiftT.mk.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (CoeTCₓ.coe.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (SetLike.Set.hasCoeT.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) ν))\nbut is expected to have type\n  forall (μ : YoungDiagram) (ν : YoungDiagram), Eq.{1} (Set.{0} (Prod.{0, 0} Nat Nat)) (SetLike.coe.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat (Sup.sup.{0} YoungDiagram YoungDiagram.instSupYoungDiagram μ ν)) (Union.union.{0} (Set.{0} (Prod.{0, 0} Nat Nat)) (Set.instUnionSet.{0} (Prod.{0, 0} Nat Nat)) (SetLike.coe.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat μ) (SetLike.coe.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat ν))\nCase conversion may be inaccurate. Consider using '#align young_diagram.coe_sup YoungDiagram.coe_supₓ'. -/\n@[simp, norm_cast]\ntheorem coe_sup (μ ν : YoungDiagram) : ↑(μ ⊔ ν) = (μ ∪ ν : Set (ℕ × ℕ)) :=\n  Finset.coe_union _ _\n#align young_diagram.coe_sup YoungDiagram.coe_sup\n\n/- warning: young_diagram.mem_sup -> YoungDiagram.mem_sup is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {ν : YoungDiagram} {x : Prod.{0, 0} Nat Nat}, Iff (Membership.Mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.hasMem.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike) x (Sup.sup.{0} YoungDiagram YoungDiagram.hasSup μ ν)) (Or (Membership.Mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.hasMem.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike) x μ) (Membership.Mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.hasMem.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike) x ν))\nbut is expected to have type\n  forall {μ : YoungDiagram} {ν : YoungDiagram} {x : Prod.{0, 0} Nat Nat}, Iff (Membership.mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.instMembership.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat) x (Sup.sup.{0} YoungDiagram YoungDiagram.instSupYoungDiagram μ ν)) (Or (Membership.mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.instMembership.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat) x μ) (Membership.mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.instMembership.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat) x ν))\nCase conversion may be inaccurate. Consider using '#align young_diagram.mem_sup YoungDiagram.mem_supₓ'. -/\n@[simp]\ntheorem mem_sup {μ ν : YoungDiagram} {x : ℕ × ℕ} : x ∈ μ ⊔ ν ↔ x ∈ μ ∨ x ∈ ν :=\n  Finset.mem_union\n#align young_diagram.mem_sup YoungDiagram.mem_sup\n\ninstance : Inf YoungDiagram\n    where inf μ ν :=\n    { cells := μ.cells ∩ ν.cells\n      IsLowerSet := by\n        rw [Finset.coe_inter]\n        exact μ.is_lower_set.inter ν.is_lower_set }\n\n/- warning: young_diagram.cells_inf -> YoungDiagram.cells_inf is a dubious translation:\nlean 3 declaration is\n  forall (μ : YoungDiagram) (ν : YoungDiagram), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells (Inf.inf.{0} YoungDiagram YoungDiagram.hasInf μ ν)) (Inter.inter.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasInter.{0} (Prod.{0, 0} Nat Nat) (fun (a : Prod.{0, 0} Nat Nat) (b : Prod.{0, 0} Nat Nat) => Prod.decidableEq.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) (fun (a : Nat) (b : Nat) => Nat.decidableEq a b) a b)) (YoungDiagram.cells μ) (YoungDiagram.cells ν))\nbut is expected to have type\n  forall (μ : YoungDiagram) (ν : YoungDiagram), Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells (Inf.inf.{0} YoungDiagram YoungDiagram.instInfYoungDiagram μ ν)) (Inter.inter.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instInterFinset.{0} (Prod.{0, 0} Nat Nat) (fun (a : Prod.{0, 0} Nat Nat) (b : Prod.{0, 0} Nat Nat) => instDecidableEqProd.{0, 0} Nat Nat (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) (fun (a : Nat) (b : Nat) => instDecidableEqNat a b) a b)) (YoungDiagram.cells μ) (YoungDiagram.cells ν))\nCase conversion may be inaccurate. Consider using '#align young_diagram.cells_inf YoungDiagram.cells_infₓ'. -/\n@[simp]\ntheorem cells_inf (μ ν : YoungDiagram) : (μ ⊓ ν).cells = μ.cells ∩ ν.cells :=\n  rfl\n#align young_diagram.cells_inf YoungDiagram.cells_inf\n\n#print YoungDiagram.coe_inf /-\n@[simp, norm_cast]\ntheorem coe_inf (μ ν : YoungDiagram) : ↑(μ ⊓ ν) = (μ ∩ ν : Set (ℕ × ℕ)) :=\n  Finset.coe_inter _ _\n#align young_diagram.coe_inf YoungDiagram.coe_inf\n-/\n\n#print YoungDiagram.mem_inf /-\n@[simp]\ntheorem mem_inf {μ ν : YoungDiagram} {x : ℕ × ℕ} : x ∈ μ ⊓ ν ↔ x ∈ μ ∧ x ∈ ν :=\n  Finset.mem_inter\n#align young_diagram.mem_inf YoungDiagram.mem_inf\n-/\n\n/-- The empty Young diagram is (⊥ : young_diagram). -/\ninstance : OrderBot YoungDiagram\n    where\n  bot :=\n    { cells := ∅\n      IsLowerSet := fun _ _ _ => False.elim }\n  bot_le _ _ := False.elim\n\n/- warning: young_diagram.cells_bot -> YoungDiagram.cells_bot is a dubious translation:\nlean 3 declaration is\n  Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells (Bot.bot.{0} YoungDiagram (OrderBot.toHasBot.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) YoungDiagram.orderBot))) (EmptyCollection.emptyCollection.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.hasEmptyc.{0} (Prod.{0, 0} Nat Nat)))\nbut is expected to have type\n  Eq.{1} (Finset.{0} (Prod.{0, 0} Nat Nat)) (YoungDiagram.cells (Bot.bot.{0} YoungDiagram (OrderBot.toBot.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.instPartialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat))) YoungDiagram.instOrderBotYoungDiagramToLEToPreorderInstPartialOrderProdNatInstSetLikeYoungDiagramProdNat))) (EmptyCollection.emptyCollection.{0} (Finset.{0} (Prod.{0, 0} Nat Nat)) (Finset.instEmptyCollectionFinset.{0} (Prod.{0, 0} Nat Nat)))\nCase conversion may be inaccurate. Consider using '#align young_diagram.cells_bot YoungDiagram.cells_botₓ'. -/\n@[simp]\ntheorem cells_bot : (⊥ : YoungDiagram).cells = ∅ :=\n  rfl\n#align young_diagram.cells_bot YoungDiagram.cells_bot\n\n/- warning: young_diagram.coe_bot -> YoungDiagram.coe_bot is a dubious translation:\nlean 3 declaration is\n  Eq.{1} (Set.{0} (Prod.{0, 0} Nat Nat)) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (HasLiftT.mk.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (CoeTCₓ.coe.{1, 1} YoungDiagram (Set.{0} (Prod.{0, 0} Nat Nat)) (SetLike.Set.hasCoeT.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) (Bot.bot.{0} YoungDiagram (OrderBot.toHasBot.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) YoungDiagram.orderBot))) (EmptyCollection.emptyCollection.{0} (Set.{0} (Prod.{0, 0} Nat Nat)) (Set.hasEmptyc.{0} (Prod.{0, 0} Nat Nat)))\nbut is expected to have type\n  Eq.{1} (Set.{0} (Prod.{0, 0} Nat Nat)) (Finset.toSet.{0} (Prod.{0, 0} Nat Nat) (YoungDiagram.cells (Bot.bot.{0} YoungDiagram (OrderBot.toBot.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.instPartialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat))) YoungDiagram.instOrderBotYoungDiagramToLEToPreorderInstPartialOrderProdNatInstSetLikeYoungDiagramProdNat)))) (EmptyCollection.emptyCollection.{0} (Set.{0} (Prod.{0, 0} Nat Nat)) (Set.instEmptyCollectionSet.{0} (Prod.{0, 0} Nat Nat)))\nCase conversion may be inaccurate. Consider using '#align young_diagram.coe_bot YoungDiagram.coe_botₓ'. -/\n@[simp, norm_cast]\ntheorem coe_bot : ↑(⊥ : YoungDiagram) = (∅ : Set (ℕ × ℕ)) :=\n  rfl\n#align young_diagram.coe_bot YoungDiagram.coe_bot\n\n/- warning: young_diagram.not_mem_bot -> YoungDiagram.not_mem_bot is a dubious translation:\nlean 3 declaration is\n  forall (x : Prod.{0, 0} Nat Nat), Not (Membership.Mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.hasMem.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike) x (Bot.bot.{0} YoungDiagram (OrderBot.toHasBot.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) YoungDiagram.orderBot)))\nbut is expected to have type\n  forall (x : Prod.{0, 0} Nat Nat), Not (Membership.mem.{0, 0} (Prod.{0, 0} Nat Nat) YoungDiagram (SetLike.instMembership.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat) x (Bot.bot.{0} YoungDiagram (OrderBot.toBot.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.instPartialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.instSetLikeYoungDiagramProdNat))) YoungDiagram.instOrderBotYoungDiagramToLEToPreorderInstPartialOrderProdNatInstSetLikeYoungDiagramProdNat)))\nCase conversion may be inaccurate. Consider using '#align young_diagram.not_mem_bot YoungDiagram.not_mem_botₓ'. -/\n@[simp]\ntheorem not_mem_bot (x : ℕ × ℕ) : x ∉ (⊥ : YoungDiagram) :=\n  Finset.not_mem_empty x\n#align young_diagram.not_mem_bot YoungDiagram.not_mem_bot\n\ninstance : Inhabited YoungDiagram :=\n  ⟨⊥⟩\n\ninstance : DistribLattice YoungDiagram :=\n  Function.Injective.distribLattice YoungDiagram.cells (fun μ ν h => by rwa [YoungDiagram.ext_iff])\n    (fun _ _ => rfl) fun _ _ => rfl\n\nend DistribLattice\n\n#print YoungDiagram.card /-\n/-- Cardinality of a Young diagram -/\n@[reducible]\nprotected def card (μ : YoungDiagram) : ℕ :=\n  μ.cells.card\n#align young_diagram.card YoungDiagram.card\n-/\n\nsection Transpose\n\n#print YoungDiagram.transpose /-\n/-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/\ndef transpose (μ : YoungDiagram) : YoungDiagram\n    where\n  cells := (Equiv.prodComm _ _).finsetCongr μ.cells\n  IsLowerSet _ _ h :=\n    by\n    simp only [Finset.mem_coe, Equiv.finsetCongr_apply, Finset.mem_map_equiv]\n    intro hcell\n    apply μ.is_lower_set _ hcell\n    simp [h]\n#align young_diagram.transpose YoungDiagram.transpose\n-/\n\n#print YoungDiagram.mem_transpose /-\n@[simp]\ntheorem mem_transpose {μ : YoungDiagram} {c : ℕ × ℕ} : c ∈ μ.transpose ↔ c.symm ∈ μ := by\n  simp [transpose]\n#align young_diagram.mem_transpose YoungDiagram.mem_transpose\n-/\n\n#print YoungDiagram.transpose_transpose /-\n@[simp]\ntheorem transpose_transpose (μ : YoungDiagram) : μ.transpose.transpose = μ :=\n  by\n  ext\n  simp\n#align young_diagram.transpose_transpose YoungDiagram.transpose_transpose\n-/\n\n#print YoungDiagram.transpose_eq_iff_eq_transpose /-\ntheorem transpose_eq_iff_eq_transpose {μ ν : YoungDiagram} : μ.transpose = ν ↔ μ = ν.transpose := by\n  constructor <;>\n    · rintro rfl\n      simp\n#align young_diagram.transpose_eq_iff_eq_transpose YoungDiagram.transpose_eq_iff_eq_transpose\n-/\n\n#print YoungDiagram.transpose_eq_iff /-\n@[simp]\ntheorem transpose_eq_iff {μ ν : YoungDiagram} : μ.transpose = ν.transpose ↔ μ = ν :=\n  by\n  rw [transpose_eq_iff_eq_transpose]\n  simp\n#align young_diagram.transpose_eq_iff YoungDiagram.transpose_eq_iff\n-/\n\n/- warning: young_diagram.le_of_transpose_le -> YoungDiagram.le_of_transpose_le is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) (YoungDiagram.transpose μ) ν) -> (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) μ (YoungDiagram.transpose ν))\nbut is expected to have type\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) (YoungDiagram.transpose μ) ν) -> (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) μ (YoungDiagram.transpose ν))\nCase conversion may be inaccurate. Consider using '#align young_diagram.le_of_transpose_le YoungDiagram.le_of_transpose_leₓ'. -/\n-- This is effectively both directions of `transpose_le_iff` below.\nprotected theorem le_of_transpose_le {μ ν : YoungDiagram} (h_le : μ.transpose ≤ ν) :\n    μ ≤ ν.transpose := fun c hc => by\n  simp only [mem_transpose]\n  apply h_le\n  simpa\n#align young_diagram.le_of_transpose_le YoungDiagram.le_of_transpose_le\n\n/- warning: young_diagram.transpose_le_iff -> YoungDiagram.transpose_le_iff is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, Iff (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) (YoungDiagram.transpose μ) (YoungDiagram.transpose ν)) (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) μ ν)\nbut is expected to have type\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, Iff (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) (YoungDiagram.transpose μ) (YoungDiagram.transpose ν)) (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) μ ν)\nCase conversion may be inaccurate. Consider using '#align young_diagram.transpose_le_iff YoungDiagram.transpose_le_iffₓ'. -/\n@[simp]\ntheorem transpose_le_iff {μ ν : YoungDiagram} : μ.transpose ≤ ν.transpose ↔ μ ≤ ν :=\n  ⟨fun h => by\n    convert YoungDiagram.le_of_transpose_le h\n    simp, fun h => by\n    convert@YoungDiagram.le_of_transpose_le _ _ _\n    simpa⟩\n#align young_diagram.transpose_le_iff YoungDiagram.transpose_le_iff\n\n/- warning: young_diagram.transpose_mono -> YoungDiagram.transpose_mono is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) μ ν) -> (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) (YoungDiagram.transpose μ) (YoungDiagram.transpose ν))\nbut is expected to have type\n  forall {μ : YoungDiagram} {ν : YoungDiagram}, (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) μ ν) -> (LE.le.{0} YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) (YoungDiagram.transpose μ) (YoungDiagram.transpose ν))\nCase conversion may be inaccurate. Consider using '#align young_diagram.transpose_mono YoungDiagram.transpose_monoₓ'. -/\n@[mono]\nprotected theorem transpose_mono {μ ν : YoungDiagram} (h_le : μ ≤ ν) : μ.transpose ≤ ν.transpose :=\n  transpose_le_iff.mpr h_le\n#align young_diagram.transpose_mono YoungDiagram.transpose_mono\n\n/- warning: young_diagram.transpose_order_iso -> YoungDiagram.transposeOrderIso is a dubious translation:\nlean 3 declaration is\n  OrderIso.{0, 0} YoungDiagram YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike))) (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SetLike.partialOrder.{0, 0} YoungDiagram (Prod.{0, 0} Nat Nat) YoungDiagram.Prod.setLike)))\nbut is expected to have type\n  OrderIso.{0, 0} YoungDiagram YoungDiagram (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram))))) (Preorder.toLE.{0} YoungDiagram (PartialOrder.toPreorder.{0} YoungDiagram (SemilatticeInf.toPartialOrder.{0} YoungDiagram (Lattice.toSemilatticeInf.{0} YoungDiagram (DistribLattice.toLattice.{0} YoungDiagram YoungDiagram.instDistribLatticeYoungDiagram)))))\nCase conversion may be inaccurate. Consider using '#align young_diagram.transpose_order_iso YoungDiagram.transposeOrderIsoₓ'. -/\n/-- Transposing Young diagrams is an `order_iso`. -/\n@[simps]\ndef transposeOrderIso : YoungDiagram ≃o YoungDiagram :=\n  ⟨⟨transpose, transpose, fun _ => by simp, fun _ => by simp⟩, by simp⟩\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 `μ.row` and `μ.row_len`, with the following API:\n      1.  `(i, j) ∈ μ ↔ j < μ.row_len i`\n      2.  `μ.row i = {i} ×ˢ (finset.range (μ.row_len i))`\n      3.  `μ.row_len i = (μ.row i).card`\n      4.  `∀ {i1 i2}, i1 ≤ i2 → μ.row_len i2 ≤ μ.row_len i1`\n\nNote: #3 is not convenient for defining `μ.row_len`; instead, `μ.row_len` is defined\nas the smallest `j` such that `(i, j) ∉ μ`. -/\n\n\n#print YoungDiagram.row /-\n/-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/\ndef row (μ : YoungDiagram) (i : ℕ) : Finset (ℕ × ℕ) :=\n  μ.cells.filterₓ fun c => c.fst = i\n#align young_diagram.row YoungDiagram.row\n-/\n\n#print YoungDiagram.mem_row_iff /-\ntheorem mem_row_iff {μ : YoungDiagram} {i : ℕ} {c : ℕ × ℕ} : c ∈ μ.row i ↔ c ∈ μ ∧ c.fst = i := by\n  simp [row]\n#align young_diagram.mem_row_iff YoungDiagram.mem_row_iff\n-/\n\n#print YoungDiagram.mk_mem_row_iff /-\ntheorem mk_mem_row_iff {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ.row i ↔ (i, j) ∈ μ := by simp [row]\n#align young_diagram.mk_mem_row_iff YoungDiagram.mk_mem_row_iff\n-/\n\n#print YoungDiagram.exists_not_mem_row /-\nprotected theorem exists_not_mem_row (μ : YoungDiagram) (i : ℕ) : ∃ j, (i, j) ∉ μ :=\n  by\n  obtain ⟨j, hj⟩ :=\n    Infinite.exists_not_mem_finset\n      (μ.cells.Preimage (Prod.mk i) fun _ _ _ _ h =>\n        by\n        cases h\n        rfl)\n  rw [Finset.mem_preimage] at hj\n  exact ⟨j, hj⟩\n#align young_diagram.exists_not_mem_row YoungDiagram.exists_not_mem_row\n-/\n\n#print YoungDiagram.rowLen /-\n/-- Length of a row of a Young diagram -/\ndef rowLen (μ : YoungDiagram) (i : ℕ) : ℕ :=\n  Nat.find <| μ.exists_not_mem_row i\n#align young_diagram.row_len YoungDiagram.rowLen\n-/\n\n#print YoungDiagram.mem_iff_lt_rowLen /-\ntheorem mem_iff_lt_rowLen {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ ↔ j < μ.rowLen i :=\n  by\n  rw [row_len, Nat.lt_find_iff]\n  push_neg\n  exact ⟨fun h _ hmj => μ.up_left_mem (by rfl) hmj h, fun h => h _ (by rfl)⟩\n#align young_diagram.mem_iff_lt_row_len YoungDiagram.mem_iff_lt_rowLen\n-/\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print YoungDiagram.row_eq_prod /-\ntheorem row_eq_prod {μ : YoungDiagram} {i : ℕ} : μ.row i = {i} ×ˢ Finset.range (μ.rowLen i) :=\n  by\n  ext ⟨a, b⟩\n  simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_row_iff,\n    mem_iff_lt_row_len, and_comm', and_congr_right_iff]\n  rintro rfl\n  rfl\n#align young_diagram.row_eq_prod YoungDiagram.row_eq_prod\n-/\n\n#print YoungDiagram.rowLen_eq_card /-\ntheorem rowLen_eq_card (μ : YoungDiagram) {i : ℕ} : μ.rowLen i = (μ.row i).card := by\n  simp [row_eq_prod]\n#align young_diagram.row_len_eq_card YoungDiagram.rowLen_eq_card\n-/\n\n#print YoungDiagram.rowLen_anti /-\n@[mono]\ntheorem rowLen_anti (μ : YoungDiagram) (i1 i2 : ℕ) (hi : i1 ≤ i2) : μ.rowLen i2 ≤ μ.rowLen i1 :=\n  by\n  by_contra' h_lt\n  rw [← lt_self_iff_false (μ.row_len i1)]\n  rw [← mem_iff_lt_row_len] at h_lt⊢\n  exact μ.up_left_mem hi (by rfl) h_lt\n#align young_diagram.row_len_anti YoungDiagram.rowLen_anti\n-/\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#print YoungDiagram.col /-\n/-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/\ndef col (μ : YoungDiagram) (j : ℕ) : Finset (ℕ × ℕ) :=\n  μ.cells.filterₓ fun c => c.snd = j\n#align young_diagram.col YoungDiagram.col\n-/\n\n#print YoungDiagram.mem_col_iff /-\ntheorem mem_col_iff {μ : YoungDiagram} {j : ℕ} {c : ℕ × ℕ} : c ∈ μ.col j ↔ c ∈ μ ∧ c.snd = j := by\n  simp [col]\n#align young_diagram.mem_col_iff YoungDiagram.mem_col_iff\n-/\n\n#print YoungDiagram.mk_mem_col_iff /-\ntheorem mk_mem_col_iff {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ.col j ↔ (i, j) ∈ μ := by simp [col]\n#align young_diagram.mk_mem_col_iff YoungDiagram.mk_mem_col_iff\n-/\n\n#print YoungDiagram.exists_not_mem_col /-\nprotected theorem exists_not_mem_col (μ : YoungDiagram) (j : ℕ) : ∃ i, (i, j) ∉ μ.cells :=\n  by\n  convert μ.transpose.exists_not_mem_row j\n  simp\n#align young_diagram.exists_not_mem_col YoungDiagram.exists_not_mem_col\n-/\n\n#print YoungDiagram.colLen /-\n/-- Length of a column of a Young diagram -/\ndef colLen (μ : YoungDiagram) (j : ℕ) : ℕ :=\n  Nat.find <| μ.exists_not_mem_col j\n#align young_diagram.col_len YoungDiagram.colLen\n-/\n\n#print YoungDiagram.colLen_transpose /-\n@[simp]\ntheorem colLen_transpose (μ : YoungDiagram) (j : ℕ) : μ.transpose.colLen j = μ.rowLen j := by\n  simp [row_len, col_len]\n#align young_diagram.col_len_transpose YoungDiagram.colLen_transpose\n-/\n\n#print YoungDiagram.rowLen_transpose /-\n@[simp]\ntheorem rowLen_transpose (μ : YoungDiagram) (i : ℕ) : μ.transpose.rowLen i = μ.colLen i := by\n  simp [row_len, col_len]\n#align young_diagram.row_len_transpose YoungDiagram.rowLen_transpose\n-/\n\n#print YoungDiagram.mem_iff_lt_colLen /-\ntheorem mem_iff_lt_colLen {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ ↔ i < μ.colLen j :=\n  by\n  rw [← row_len_transpose, ← mem_iff_lt_row_len]\n  simp\n#align young_diagram.mem_iff_lt_col_len YoungDiagram.mem_iff_lt_colLen\n-/\n\n/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/\n#print YoungDiagram.col_eq_prod /-\ntheorem col_eq_prod {μ : YoungDiagram} {j : ℕ} : μ.col j = Finset.range (μ.colLen j) ×ˢ {j} :=\n  by\n  ext ⟨a, b⟩\n  simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_col_iff,\n    mem_iff_lt_col_len, and_comm', and_congr_right_iff]\n  rintro rfl\n  rfl\n#align young_diagram.col_eq_prod YoungDiagram.col_eq_prod\n-/\n\n#print YoungDiagram.colLen_eq_card /-\ntheorem colLen_eq_card (μ : YoungDiagram) {j : ℕ} : μ.colLen j = (μ.col j).card := by\n  simp [col_eq_prod]\n#align young_diagram.col_len_eq_card YoungDiagram.colLen_eq_card\n-/\n\n#print YoungDiagram.colLen_anti /-\n@[mono]\ntheorem colLen_anti (μ : YoungDiagram) (j1 j2 : ℕ) (hj : j1 ≤ j2) : μ.colLen j2 ≤ μ.colLen j1 := by\n  convert μ.transpose.row_len_anti j1 j2 hj <;> simp\n#align young_diagram.col_len_anti YoungDiagram.colLen_anti\n-/\n\nend Columns\n\nsection RowLens\n\n/-! ### The list of row lengths of a Young diagram\n\nThis section defines `μ.row_lens : list ℕ`, the list of row lengths of a Young diagram `μ`.\n  1. `young_diagram.row_lens_sorted` : It is weakly decreasing (`list.sorted (≥)`).\n  2. `young_diagram.row_lens_pos` : It is strictly positive.\n\n-/\n\n\n#print YoungDiagram.rowLens /-\n/-- List of row lengths of a Young diagram -/\ndef rowLens (μ : YoungDiagram) : List ℕ :=\n  (List.range <| μ.colLen 0).map μ.rowLen\n#align young_diagram.row_lens YoungDiagram.rowLens\n-/\n\n/- warning: young_diagram.nth_le_row_lens -> YoungDiagram.get_rowLens is a dubious translation:\nlean 3 declaration is\n  forall {μ : YoungDiagram} {i : Nat} {hi : LT.lt.{0} Nat Nat.hasLt i (List.length.{0} Nat (YoungDiagram.rowLens μ))}, Eq.{1} Nat (List.nthLe.{0} Nat (YoungDiagram.rowLens μ) i hi) (YoungDiagram.rowLen μ i)\nbut is expected to have type\n  forall {μ : YoungDiagram} {i : Fin (List.length.{0} Nat (YoungDiagram.rowLens μ))}, Eq.{1} Nat (List.get.{0} Nat (YoungDiagram.rowLens μ) i) (YoungDiagram.rowLen μ (Fin.val (List.length.{0} Nat (YoungDiagram.rowLens μ)) i))\nCase conversion may be inaccurate. Consider using '#align young_diagram.nth_le_row_lens YoungDiagram.get_rowLensₓ'. -/\n@[simp]\ntheorem get_rowLens {μ : YoungDiagram} {i : ℕ} {hi : i < μ.rowLens.length} :\n    μ.rowLens.nthLe i hi = μ.rowLen i := by simp only [row_lens, List.nthLe_range, List.nthLe_map']\n#align young_diagram.nth_le_row_lens YoungDiagram.get_rowLens\n\n#print YoungDiagram.length_rowLens /-\n@[simp]\ntheorem length_rowLens {μ : YoungDiagram} : μ.rowLens.length = μ.colLen 0 := by\n  simp only [row_lens, List.length_map, List.length_range]\n#align young_diagram.length_row_lens YoungDiagram.length_rowLens\n-/\n\n#print YoungDiagram.rowLens_sorted /-\ntheorem rowLens_sorted (μ : YoungDiagram) : μ.rowLens.Sorted (· ≥ ·) :=\n  (List.pairwise_le_range _).map _ μ.rowLen_anti\n#align young_diagram.row_lens_sorted YoungDiagram.rowLens_sorted\n-/\n\n#print YoungDiagram.pos_of_mem_rowLens /-\ntheorem pos_of_mem_rowLens (μ : YoungDiagram) (x : ℕ) (hx : x ∈ μ.rowLens) : 0 < x :=\n  by\n  rw [row_lens, List.mem_map] at hx\n  obtain ⟨i, hi, rfl : μ.row_len i = x⟩ := hx\n  rwa [List.mem_range, ← mem_iff_lt_col_len, mem_iff_lt_row_len] at hi\n#align young_diagram.pos_of_mem_row_lens YoungDiagram.pos_of_mem_rowLens\n-/\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 `μ` 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 ≃ {w : list ℕ // w.sorted (≥) ∧ ∀ x ∈ w, 0 < x}`\n\nThe two directions are `young_diagram.row_lens` (defined above) and `young_diagram.of_row_lens`.\n\n-/\n\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 YoungDiagram.cellsOfRowLens /-\n/-- The cells making up a `young_diagram` from a list of row lengths -/\nprotected def cellsOfRowLens : List ℕ → Finset (ℕ × ℕ)\n  | [] => ∅\n  | w::ws =>\n    ({0} : Finset ℕ) ×ˢ Finset.range w ∪\n      (cells_of_row_lens ws).map (Embedding.prodMap ⟨_, Nat.succ_injective⟩ (Embedding.refl ℕ))\n#align young_diagram.cells_of_row_lens YoungDiagram.cellsOfRowLens\n-/\n\n#print YoungDiagram.mem_cellsOfRowLens /-\nprotected theorem mem_cellsOfRowLens {w : List ℕ} {c : ℕ × ℕ} :\n    c ∈ YoungDiagram.cellsOfRowLens w ↔ ∃ h : c.fst < w.length, c.snd < w.nthLe c.fst h :=\n  by\n  induction w generalizing c <;> rw [YoungDiagram.cellsOfRowLens]\n  · simp [YoungDiagram.cellsOfRowLens]\n  · rcases c with ⟨⟨_, _⟩, _⟩\n    · simp\n    · simpa [w_ih, -Finset.singleton_product, Nat.succ_lt_succ_iff]\n#align young_diagram.mem_cells_of_row_lens YoungDiagram.mem_cellsOfRowLens\n-/\n\n#print YoungDiagram.ofRowLens /-\n/-- Young diagram from a sorted list -/\ndef ofRowLens (w : List ℕ) (hw : w.Sorted (· ≥ ·)) : YoungDiagram\n    where\n  cells := YoungDiagram.cellsOfRowLens w\n  IsLowerSet := by\n    rintro ⟨i2, j2⟩ ⟨i1, j1⟩ ⟨hi : i1 ≤ i2, hj : j1 ≤ j2⟩ hcell\n    rw [Finset.mem_coe, YoungDiagram.mem_cellsOfRowLens] at hcell⊢\n    obtain ⟨h1, h2⟩ := hcell\n    refine' ⟨hi.trans_lt h1, _⟩\n    calc\n      j1 ≤ j2 := hj\n      _ < w.nth_le i2 _ := h2\n      _ ≤ w.nth_le i1 _ := _\n      \n    obtain rfl | h := eq_or_lt_of_le hi\n    · rfl\n    · apply list.pairwise_iff_nth_le.mp hw _ _ _ h\n#align young_diagram.of_row_lens YoungDiagram.ofRowLens\n-/\n\n#print YoungDiagram.mem_ofRowLens /-\ntheorem mem_ofRowLens {w : List ℕ} {hw : w.Sorted (· ≥ ·)} {c : ℕ × ℕ} :\n    c ∈ ofRowLens w hw ↔ ∃ h : c.fst < w.length, c.snd < w.nthLe c.fst h :=\n  YoungDiagram.mem_cellsOfRowLens\n#align young_diagram.mem_of_row_lens YoungDiagram.mem_ofRowLens\n-/\n\n#print YoungDiagram.rowLens_length_ofRowLens /-\n/-- The number of rows in `of_row_lens w hw` is the length of `w` -/\ntheorem rowLens_length_ofRowLens {w : List ℕ} {hw : w.Sorted (· ≥ ·)} (hpos : ∀ x ∈ w, 0 < x) :\n    (ofRowLens w hw).rowLens.length = w.length :=\n  by\n  simp only [length_row_lens, col_len, Nat.find_eq_iff, mem_cells, mem_of_row_lens,\n    lt_self_iff_false, IsEmpty.exists_iff, Classical.not_not]\n  exact ⟨id, fun n hn => ⟨hn, hpos _ (List.nthLe_mem _ _ hn)⟩⟩\n#align young_diagram.row_lens_length_of_row_lens YoungDiagram.rowLens_length_ofRowLens\n-/\n\n/- warning: young_diagram.row_len_of_row_lens -> YoungDiagram.rowLen_ofRowLens is a dubious translation:\nlean 3 declaration is\n  forall {w : List.{0} Nat} {hw : List.Sorted.{0} Nat (GE.ge.{0} Nat Nat.hasLe) w} (i : Nat) (hi : LT.lt.{0} Nat Nat.hasLt i (List.length.{0} Nat w)), Eq.{1} Nat (YoungDiagram.rowLen (YoungDiagram.ofRowLens w hw) i) (List.nthLe.{0} Nat w i hi)\nbut is expected to have type\n  forall {w : List.{0} Nat} {hw : List.Sorted.{0} Nat (fun (x._@.Mathlib.Combinatorics.Young.YoungDiagram._hyg.2936 : Nat) (x._@.Mathlib.Combinatorics.Young.YoungDiagram._hyg.2938 : Nat) => GE.ge.{0} Nat instLENat x._@.Mathlib.Combinatorics.Young.YoungDiagram._hyg.2936 x._@.Mathlib.Combinatorics.Young.YoungDiagram._hyg.2938) w} (i : Fin (List.length.{0} Nat w)), Eq.{1} Nat (YoungDiagram.rowLen (YoungDiagram.ofRowLens w hw) (Fin.val (List.length.{0} Nat w) i)) (List.get.{0} Nat w i)\nCase conversion may be inaccurate. Consider using '#align young_diagram.row_len_of_row_lens YoungDiagram.rowLen_ofRowLensₓ'. -/\n/-- The length of the `i`th row in `of_row_lens w hw` is the `i`th entry of `w` -/\ntheorem rowLen_ofRowLens {w : List ℕ} {hw : w.Sorted (· ≥ ·)} (i : ℕ) (hi : i < w.length) :\n    (ofRowLens w hw).rowLen i = w.nthLe i hi := by\n  simp [row_len, Nat.find_eq_iff, mem_of_row_lens, hi]\n#align young_diagram.row_len_of_row_lens YoungDiagram.rowLen_ofRowLens\n\n#print YoungDiagram.ofRowLens_to_rowLens_eq_self /-\n/-- The left_inv direction of the equivalence -/\ntheorem ofRowLens_to_rowLens_eq_self {μ : YoungDiagram} : ofRowLens _ (rowLens_sorted μ) = μ :=\n  by\n  ext ⟨i, j⟩\n  simp only [mem_cells, mem_of_row_lens, length_row_lens, nth_le_row_lens]\n  simpa [← mem_iff_lt_col_len, mem_iff_lt_row_len] 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\n#print YoungDiagram.rowLens_ofRowLens_eq_self /-\n/-- The right_inv direction of the equivalence -/\ntheorem rowLens_ofRowLens_eq_self {w : List ℕ} {hw : w.Sorted (· ≥ ·)} (hpos : ∀ x ∈ w, 0 < x) :\n    (ofRowLens w hw).rowLens = w := by\n  ext (i r)\n  cases lt_or_ge i w.length\n  · simp only [Option.mem_def, ← List.nthLe_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]\n#align young_diagram.row_lens_of_row_lens_eq_self YoungDiagram.rowLens_ofRowLens_eq_self\n-/\n\n#print YoungDiagram.equivListRowLens /-\n/-- Equivalence between Young diagrams and weakly decreasing lists of positive natural numbers.\nA Young diagram `μ` is equivalent to a list of row lengths. -/\n@[simps]\ndef equivListRowLens : YoungDiagram ≃ { w : List ℕ // w.Sorted (· ≥ ·) ∧ ∀ x ∈ w, 0 < x }\n    where\n  toFun μ := ⟨μ.rowLens, μ.rowLens_sorted, μ.pos_of_mem_rowLens⟩\n  invFun ww := ofRowLens ww.1 ww.2.1\n  left_inv μ := ofRowLens_to_rowLens_eq_self\n  right_inv := fun ⟨w, hw⟩ => Subtype.mk_eq_mk.mpr (rowLens_ofRowLens_eq_self hw.2)\n#align young_diagram.equiv_list_row_lens YoungDiagram.equivListRowLens\n-/\n\nend EquivListRowLens\n\nend YoungDiagram\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/YoungDiagram.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7501377388609054}}
{"text": "import .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 {α β : Type} [partial_order α] (f g : α → set (β × β))\n    (hf : monotone f) (hg : monotone g) :\n  monotone (λa, f a ◯ g a) :=\nbegin\n  intros a₁ a₂ 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 {α β : Type} [partial_order α] (f : α → set (β × β))\n    (p : β → Prop) (hf : monotone f) :\n  monotone (λa, f a ⇃ p) :=\nbegin\n  intros a₁ a₂ ha b hb,\n  cases' hb,\n  apply and.intro,\n  { exact left },\n  { apply hf _ _ ha,\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 ::= ∅\n        | ε\n        | a\n        | R ⬝ R\n        | R + R\n        | R*\n\nInformally, the semantics of regular expressions is as follows:\n\n* `∅` accepts nothing;\n* `ε` accepts the empty string;\n* `a` accepts the atom `a`;\n* `R ⬝ 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    `∅` ~ diverging statement (e.g., `while true do skip`)\n    `ε` ~ `skip`\n    `a` ~ `:=`\n    `⬝` ~ `;`\n    `+` ~ `if then else`\n    `*` ~ `while` loop -/\n\ninductive regex (α : Type) : Type\n| nothing {} : regex\n| empty {}   : regex\n| atom       : α → regex\n| concat     : regex → regex → regex\n| alt        : regex → regex → regex\n| star       : regex → 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 {α : Type} : regex (set (α × α)) → set (α × α)\n| regex.nothing        := ∅\n| regex.empty          := Id\n| (regex.atom s)       := s\n| (regex.concat r₁ r₂) := rel_of_regex r₁ ◯ rel_of_regex r₂\n| (regex.alt r₁ r₂)    := rel_of_regex r₁ ∪ rel_of_regex r₂\n| (regex.star r)       := lfp (λX, (rel_of_regex r ◯ X) ∪ Id)\n\n/- 2.2. Prove the following recursive equation about your definition. -/\n\nlemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :\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": "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_exercise_solution.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8198933447152498, "lm_q1q2_score": 0.750121209779628}}
{"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.basic\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/Pythagorean_theorem\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*} [inner_product_space ℝ V]\n\n/-- Pythagorean theorem, if-and-only-if vector angle form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :\n  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ angle x y = π / 2 :=\nbegin\n  rw norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero,\n  exact inner_eq_zero_iff_angle_eq_pi_div_two x y\nend\n\n/-- Pythagorean theorem, vector angle form. -/\nlemma norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :\n  ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\n(norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h\n\n/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) :\n  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ angle x y = π / 2 :=\nbegin\n  rw norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero,\n  exact inner_eq_zero_iff_angle_eq_pi_div_two x y\nend\n\n/-- Pythagorean theorem, subtracting vectors, vector angle form. -/\nlemma norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = π / 2) :\n  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=\n(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h\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  ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ - 2 * ∥x∥ * ∥y∥ * real.cos (angle x y) :=\nby rw [(show 2 * ∥x∥ * ∥y∥ * real.cos (angle x y) =\n             2 * (real.cos (angle x y) * (∥x∥ * ∥y∥)), by ring),\n       cos_angle_mul_norm_mul_norm, ←real_inner_self_eq_norm_mul_norm,\n       ←real_inner_self_eq_norm_mul_norm, ←real_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 : ∥x∥ = ∥y∥) :\n  angle x (x - y) = angle y (y - x) :=\nbegin\n  refine real.inj_on_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ _,\n  rw [cos_angle, cos_angle, h, ←neg_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 ≠ π) : ∥x∥ = ∥y∥ :=\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 [←norm_neg (y - x), neg_sub, mul_comm, mul_comm ∥y∥, div_eq_mul_inv, div_eq_mul_inv,\n        mul_inv_rev₀, mul_inv_rev₀, ←mul_assoc, ←mul_assoc] at h,\n    replace h :=\n      mul_right_cancel₀ (inv_ne_zero (λ 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        ←mul_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 (λ hz, hx0 (norm_eq_zero.1 hz)) (λ hz, hy0 (norm_eq_zero.1 hz)),\n            ←neg_sub, ←mul_div_assoc, mul_comm, mul_div_assoc, ←mul_neg_one] at h,\n        symmetry,\n        by_contradiction hyx,\n        replace h := (mul_left_cancel₀ (sub_ne_zero_of_ne hyx) h).symm,\n        rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ←angle_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 ≠ 0) (hy : y ≠ 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 : ∥x∥ ≠ 0 := (λ h, hx (norm_eq_zero.1 h)),\n    have hyn : ∥y∥ ≠ 0 := (λ h, hy (norm_eq_zero.1 h)),\n    have hxyn : ∥x - y∥ ≠ 0 := (λ h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),\n    apply mul_right_cancel₀ hxn,\n    apply mul_right_cancel₀ hyn,\n    apply mul_right_cancel₀ hxyn,\n    apply mul_right_cancel₀ hxyn,\n    have H1 : real.sin (angle x (x - y)) * real.sin (angle y (y - x)) *\n                ∥x∥ * ∥y∥ * ∥x - y∥ * ∥x - y∥ =\n              (real.sin (angle x (x - y)) * (∥x∥ * ∥x - y∥)) *\n                (real.sin (angle y (y - x)) * (∥y∥ * ∥x - y∥)), { ring },\n    have H2 : ⟪x, x⟫ * (inner x x - inner x y - (inner x y - inner y y)) -\n                (inner x x - inner x y) * (inner x x - inner x y) =\n              inner x x * inner y y - inner x y * inner x y, { ring },\n    have H3 : ⟪y, y⟫ * (inner y y - inner x y - (inner x y - inner x x)) -\n                (inner y y - inner x y) * (inner y y - inner x y) =\n              inner x x * inner y y - inner x y * inner x y, { 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 ≠ 0) (hy : y ≠ 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 : ∥x∥ ≠ 0 := (λ h, hx (norm_eq_zero.1 h)),\n    have hyn : ∥y∥ ≠ 0 := (λ h, hy (norm_eq_zero.1 h)),\n    have hxyn : ∥x - y∥ ≠ 0 := (λ h, hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))),\n    apply mul_right_cancel₀ hxn,\n    apply mul_right_cancel₀ hyn,\n    apply mul_right_cancel₀ hxyn,\n    apply mul_right_cancel₀ hxyn,\n    have H1 : real.sin (angle x (x - y)) * (⟪y, y - x⟫ / (∥y∥ * ∥y - x∥)) * ∥x∥ * ∥y∥ * ∥x - y∥ =\n                real.sin (angle x (x - y)) * (∥x∥ * ∥x - y∥) *\n                  (⟪y, y - x⟫ / (∥y∥ * ∥y - x∥)) * ∥y∥, { ring },\n    have H2 : ⟪x, x - y⟫ / (∥x∥ * ∥y - x∥) * real.sin (angle y (y - x)) * ∥x∥ * ∥y∥ * ∥y - x∥ =\n                ⟪x, x - y⟫ / (∥x∥ * ∥y - x∥) *\n                  (real.sin (angle y (y - x)) * (∥y∥ * ∥y - x∥)) * ∥x∥, { ring },\n    have H3 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) -\n                (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) =\n              ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫, { ring },\n    have H4 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) -\n                (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) =\n              ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫  * ⟪x, y⟫, { 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 ≠ 0) (hy : y ≠ 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, ←neg_mul_eq_mul_neg, ←neg_add',\n       add_comm, ←sq, ←sq, 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 ≠ 0) (hy : y ≠ 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 ≠ 0) (hy : y ≠ 0) :\n  angle x y + angle x (x - y) + angle y (y - x) = π :=\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 ≤ 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) ≤ π + π + π :=\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) < π + π + π,\n  { by_contradiction hnlt,\n    have hxy : angle x y = π,\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 ⟨hx, ⟨r, ⟨hr, hxr⟩⟩⟩,\n    rw [hxr, ←one_smul ℝ x, ←mul_smul, mul_one, ←sub_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 π real.pi_pos)) _ },\n  have hn0 : 0 ≤ 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 π + π + π = 3 * π, 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*} [inner_product_space ℝ V] [metric_space P]\n    [normed_add_torsor V P]\ninclude V\n\n/-- **Pythagorean theorem**, if-and-only-if angle-at-point form. -/\nlemma dist_sq_eq_dist_sq_add_dist_sq_iff_angle_eq_pi_div_two (p1 p2 p3 : P) :\n  dist p1 p3 * dist p1 p3 = dist p1 p2 * dist p1 p2 + dist p3 p2 * dist p3 p2 ↔\n    ∠ p1 p2 p3 = π / 2 :=\nby erw [pseudo_metric_space.dist_comm p3 p2, dist_eq_norm_vsub V p1 p3, dist_eq_norm_vsub V p1 p2,\n        dist_eq_norm_vsub V p2 p3,\n        ←norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two,\n        vsub_sub_vsub_cancel_right p1, ←neg_vsub_eq_vsub_rev p2 p3, norm_neg]\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 (∠ 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 -ᵥ p2 : V) (p3 -ᵥ 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 ← 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  ∠ p1 p2 p3 = ∠ 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 : ∠ p1 p2 p3 = ∠ p1 p3 p2)\n    (hpi : ∠ p2 p1 p3 ≠ π) : 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 [←angle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hpi,\n  rw [←vsub_sub_vsub_cancel_left p3 p2 p1, ←vsub_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 ≠ p1) (h3 : p3 ≠ p1) :\n  ∠ p1 p2 p3 + ∠ p2 p3 p1 + ∠ p3 p1 p2 = π :=\nbegin\n  rw [add_assoc, add_comm, add_comm (∠ p2 p3 p1), angle_comm p2 p3 p1],\n  unfold angle,\n  rw [←angle_neg_neg (p1 -ᵥ p3), ←angle_neg_neg (p1 -ᵥ p2), neg_vsub_eq_vsub_rev,\n      neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev,\n      ←vsub_sub_vsub_cancel_right p3 p2 p1, ←vsub_sub_vsub_cancel_right p2 p3 p1],\n  exact angle_add_angle_sub_add_angle_sub_eq_pi (λ he, h3 (vsub_eq_zero_iff_eq.1 he))\n                                                (λ he, h2 (vsub_eq_zero_iff_eq.1 he))\nend\n\n/-- **Stewart's Theorem**. -/\ntheorem dist_sq_mul_dist_add_dist_sq_mul_dist (a b c p : P) (h : ∠ b p c = π) :\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 ℝ 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 ℝ b c,\n    have : dist b c ≠ 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⁻¹ * dist b c) + dist a c ^ 2 * (2⁻¹ * dist b c)) :\n          by { field_simp, ring }\n    ... = 2 * (dist a (midpoint ℝ 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 : ℝ) (h : ∠ a' b' c' = ∠ 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 (∠ 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 (∠ a b c)) :\n          by { rw [h, hab, hcb], ring }\n    ... = (r * dist a c) ^ 2 : by simp [pow_two, ← law_cos a b c, mul_pow],\n  by_cases hab₁ : a = b,\n  { have hab'₁ : a' = b', { rw [← dist_eq_zero, hab, dist_eq_zero.mpr hab₁, mul_zero r] },\n    rw [hab₁, hab'₁, dist_comm b' c', dist_comm b c, hcb] },\n  { have h1 : 0 ≤ r * dist a b, { rw ← hab, exact dist_nonneg },\n    have h2 : 0 ≤ r := nonneg_of_mul_nonneg_right h1 (dist_pos.mpr hab₁),\n    exact (sq_eq_sq dist_nonneg (mul_nonneg h2 dist_nonneg)).mp h' },\nend\n\nend euclidean_geometry\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/euclidean/triangle.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009642742806, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7501212096688731}}
{"text": "import group_theory.quotient_group\n\nvariables (G : Type*) [group G] (N : subgroup G) [subgroup.normal N]\n\ndef the_fourth_isomorphism_theorem : \n  subgroup (G ⧸ N) ≃o { K : subgroup G | N ≤ K } :=\nlet π : G →* G ⧸ N := quotient_group.mk' _ in\n{ to_fun := λ H, \n  { val := H.comap π,\n    property := begin\n      dsimp, intros n hn,\n      dsimp,\n      have : (n : G ⧸ N) = 1, by simpa,\n      rw this,\n      apply H.one_mem,\n    end },\n  inv_fun := λ H, (H : subgroup G).map π,\n  left_inv := begin\n    intros H, dsimp,\n    ext x,\n    split,\n    { intros hx, simp at hx, obtain ⟨y,hy,rfl⟩ := hx, assumption, },\n    { intros hx, simp, obtain ⟨y,rfl⟩ := quotient_group.mk_surjective x, use [y, hx, rfl] }\n  end,\n  right_inv := begin\n    rintros ⟨H,hH⟩, dsimp at hH, apply subtype.ext, dsimp,\n    apply le_antisymm,\n    { intros x hx, simp at hx, obtain ⟨y,h1,h2⟩ := hx, \n      have : y⁻¹ * x ∈ N,\n      { rw ← quotient_group.eq, exact h2, },\n      simpa using (H.mul_mem h1 (hH this)) },\n    { exact subgroup.le_comap_map π H, }\n  end,\n  map_rel_iff' := begin\n    intros A B,\n    split,\n    { intros H, dsimp at H, \n      intros a ha,\n      obtain ⟨a,rfl⟩ := quotient_group.mk_surjective a,\n      replace ha := H ha,\n      exact ha },\n    { intros H, dsimp, intros a ha,\n      apply H,\n      exact ha }\n  end } ", "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_15.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7501211982543576}}
{"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 3dadefa3f544b1db6214777fe47910739b54c66a\n! Please do not edit these lines, except to modify the commit id\n! if you have ported upstream changes.\n-/\nimport Mathbin.CategoryTheory.Adjunction.Basic\nimport Mathbin.CategoryTheory.Category.Preorder\nimport Mathbin.CategoryTheory.IsomorphismClasses\nimport Mathbin.CategoryTheory.Thin\n\n/-!\n# Skeleton of a category\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\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₁ v₂ v₃ u₁ u₂ u₃\n\nnamespace CategoryTheory\n\nopen Category\n\nvariable (C : Type u₁) [Category.{v₁} C]\n\nvariable (D : Type u₂) [Category.{v₂} D]\n\nvariable {E : Type u₃} [Category.{v₃} E]\n\n#print CategoryTheory.Skeletal /-\n/-- A category is skeletal if isomorphic objects are equal. -/\ndef Skeletal : Prop :=\n  ∀ ⦃X Y : C⦄, IsIsomorphic X Y → X = Y\n#align category_theory.skeletal CategoryTheory.Skeletal\n-/\n\n#print CategoryTheory.IsSkeletonOf /-\n/-- `is_skeleton_of C D F` says that `F : D ⥤ 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 ⥤ C) where\n  skel : Skeletal D\n  eqv : IsEquivalence F\n#align category_theory.is_skeleton_of CategoryTheory.IsSkeletonOf\n-/\n\nattribute [local instance] is_isomorphic_setoid\n\nvariable {C D}\n\n#print CategoryTheory.Functor.eq_of_iso /-\n/-- If `C` is thin and skeletal, then any naturally isomorphic functors to `C` are equal. -/\ntheorem Functor.eq_of_iso {F₁ F₂ : D ⥤ C} [Quiver.IsThin C] (hC : Skeletal C) (hF : F₁ ≅ F₂) :\n    F₁ = F₂ :=\n  Functor.ext (fun X => hC ⟨hF.app X⟩) fun _ _ _ => Subsingleton.elim _ _\n#align category_theory.functor.eq_of_iso CategoryTheory.Functor.eq_of_iso\n-/\n\n#print CategoryTheory.functor_skeletal /-\n/-- If `C` is thin and skeletal, `D ⥤ C` is skeletal.\n`category_theory.functor_thin` shows it is thin also.\n-/\ntheorem functor_skeletal [Quiver.IsThin C] (hC : Skeletal C) : Skeletal (D ⥤ C) := fun F₁ F₂ h =>\n  h.elim (Functor.eq_of_iso hC)\n#align category_theory.functor_skeletal CategoryTheory.functor_skeletal\n-/\n\nvariable (C D)\n\n#print CategoryTheory.Skeleton /-\n/-- Construct the skeleton category as the induced category on the isomorphism classes, and derive\nits category structure.\n-/\ndef Skeleton : Type u₁ :=\n  InducedCategory C Quotient.out deriving Category\n#align category_theory.skeleton CategoryTheory.Skeleton\n-/\n\ninstance [Inhabited C] : Inhabited (Skeleton C) :=\n  ⟨⟦default⟧⟩\n\n#print CategoryTheory.fromSkeleton /-\n/-- The functor from the skeleton of `C` to `C`. -/\n@[simps]\nnoncomputable def fromSkeleton : Skeleton C ⥤ C :=\n  inducedFunctor _ deriving Full, Faithful\n#align category_theory.from_skeleton CategoryTheory.fromSkeleton\n-/\n\ninstance : EssSurj (fromSkeleton C) where mem_essImage X := ⟨Quotient.mk' X, Quotient.mk_out X⟩\n\nnoncomputable instance : IsEquivalence (fromSkeleton C) :=\n  Equivalence.ofFullyFaithfullyEssSurj (fromSkeleton C)\n\n/- warning: category_theory.skeleton_equivalence -> CategoryTheory.skeletonEquivalence is a dubious translation:\nlean 3 declaration is\n  forall (C : Type.{u2}) [_inst_1 : CategoryTheory.Category.{u1, u2} C], CategoryTheory.Equivalence.{u1, u1, u2, u2} (CategoryTheory.Skeleton.{u1, u2} C _inst_1) (CategoryTheory.Skeleton.category.{u2, u1} C _inst_1) C _inst_1\nbut is expected to have type\n  forall (C : Type.{u2}) [_inst_1 : CategoryTheory.Category.{u1, u2} C], CategoryTheory.Equivalence.{u1, u1, u2, u2} (CategoryTheory.Skeleton.{u1, u2} C _inst_1) C (CategoryTheory.instCategorySkeleton.{u1, u2} C _inst_1) _inst_1\nCase conversion may be inaccurate. Consider using '#align category_theory.skeleton_equivalence CategoryTheory.skeletonEquivalenceₓ'. -/\n/-- The equivalence between the skeleton and the category itself. -/\nnoncomputable def skeletonEquivalence : Skeleton C ≌ C :=\n  (fromSkeleton C).asEquivalence\n#align category_theory.skeleton_equivalence CategoryTheory.skeletonEquivalence\n\n#print CategoryTheory.skeleton_skeletal /-\ntheorem skeleton_skeletal : Skeletal (Skeleton C) :=\n  by\n  rintro X Y ⟨h⟩\n  have : X.out ≈ Y.out := ⟨(from_skeleton C).mapIso h⟩\n  simpa using Quotient.sound this\n#align category_theory.skeleton_skeletal CategoryTheory.skeleton_skeletal\n-/\n\n#print CategoryTheory.skeletonIsSkeleton /-\n/-- The `skeleton` of `C` given by choice is a skeleton of `C`. -/\nnoncomputable def skeletonIsSkeleton : IsSkeletonOf C (Skeleton C) (fromSkeleton C)\n    where\n  skel := skeleton_skeletal C\n  eqv := fromSkeleton.isEquivalence C\n#align category_theory.skeleton_is_skeleton CategoryTheory.skeletonIsSkeleton\n-/\n\nsection\n\nvariable {C D}\n\n/- warning: category_theory.equivalence.skeleton_equiv -> CategoryTheory.Equivalence.skeletonEquiv 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], (CategoryTheory.Equivalence.{u1, u2, u3, u4} C _inst_1 D _inst_2) -> (Equiv.{succ u3, succ u4} (CategoryTheory.Skeleton.{u1, u3} C _inst_1) (CategoryTheory.Skeleton.{u2, u4} D _inst_2))\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], (CategoryTheory.Equivalence.{u1, u2, u3, u4} C D _inst_1 _inst_2) -> (Equiv.{succ u3, succ u4} (CategoryTheory.Skeleton.{u1, u3} C _inst_1) (CategoryTheory.Skeleton.{u2, u4} D _inst_2))\nCase conversion may be inaccurate. Consider using '#align category_theory.equivalence.skeleton_equiv CategoryTheory.Equivalence.skeletonEquivₓ'. -/\n/-- Two categories which are categorically equivalent have skeletons with equivalent objects.\n-/\nnoncomputable def Equivalence.skeletonEquiv (e : C ≌ D) : Skeleton C ≃ 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 ⟨(f.unitIso.app X).symm⟩\n    right_inv := fun Y => skeleton_skeletal D ⟨f.counitIso.app Y⟩ }\n#align category_theory.equivalence.skeleton_equiv CategoryTheory.Equivalence.skeletonEquiv\n\nend\n\n#print CategoryTheory.ThinSkeleton /-\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₁ :=\n  Quotient (isIsomorphicSetoid C)\n#align category_theory.thin_skeleton CategoryTheory.ThinSkeleton\n-/\n\n#print CategoryTheory.inhabitedThinSkeleton /-\ninstance inhabitedThinSkeleton [Inhabited C] : Inhabited (ThinSkeleton C) :=\n  ⟨Quotient.mk' default⟩\n#align category_theory.inhabited_thin_skeleton CategoryTheory.inhabitedThinSkeleton\n-/\n\n#print CategoryTheory.ThinSkeleton.preorder /-\ninstance ThinSkeleton.preorder : Preorder (ThinSkeleton C)\n    where\n  le :=\n    Quotient.lift₂ (fun X Y => Nonempty (X ⟶ Y))\n      (by\n        rintro _ _ _ _ ⟨i₁⟩ ⟨i₂⟩\n        exact\n          propext\n            ⟨Nonempty.map fun f => i₁.inv ≫ f ≫ i₂.hom, Nonempty.map fun f => i₁.hom ≫ f ≫ i₂.inv⟩)\n  le_refl := by\n    refine' Quotient.ind fun a => _\n    exact ⟨𝟙 _⟩\n  le_trans a b c := Quotient.induction_on₃ a b c fun A B C => Nonempty.map2 (· ≫ ·)\n#align category_theory.thin_skeleton.preorder CategoryTheory.ThinSkeleton.preorder\n-/\n\n#print CategoryTheory.toThinSkeleton /-\n/-- The functor from a category to its thin skeleton. -/\n@[simps]\ndef toThinSkeleton : C ⥤ ThinSkeleton C\n    where\n  obj := Quotient.mk'\n  map X Y f := homOfLE (Nonempty.intro f)\n#align category_theory.to_thin_skeleton CategoryTheory.toThinSkeleton\n-/\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#print CategoryTheory.ThinSkeleton.thin /-\n/-- The thin skeleton is thin. -/\ninstance thin : Quiver.IsThin (ThinSkeleton C) := fun _ _ =>\n  ⟨by\n    rintro ⟨⟨f₁⟩⟩ ⟨⟨f₂⟩⟩\n    rfl⟩\n#align category_theory.thin_skeleton.thin CategoryTheory.ThinSkeleton.thin\n-/\n\nvariable {C} {D}\n\n#print CategoryTheory.ThinSkeleton.map /-\n/-- A functor `C ⥤ D` computably lowers to a functor `thin_skeleton C ⥤ thin_skeleton D`. -/\n@[simps]\ndef map (F : C ⥤ D) : ThinSkeleton C ⥤ ThinSkeleton D\n    where\n  obj := Quotient.map F.obj fun X₁ X₂ ⟨hX⟩ => ⟨F.mapIso hX⟩\n  map X Y := Quotient.recOnSubsingleton₂ X Y fun x y k => homOfLE (k.le.elim fun t => ⟨F.map t⟩)\n#align category_theory.thin_skeleton.map CategoryTheory.ThinSkeleton.map\n-/\n\n#print CategoryTheory.ThinSkeleton.comp_toThinSkeleton /-\ntheorem comp_toThinSkeleton (F : C ⥤ D) : F ⋙ toThinSkeleton D = toThinSkeleton C ⋙ map F :=\n  rfl\n#align category_theory.thin_skeleton.comp_to_thin_skeleton CategoryTheory.ThinSkeleton.comp_toThinSkeleton\n-/\n\n#print CategoryTheory.ThinSkeleton.mapNatTrans /-\n/-- Given a natural transformation `F₁ ⟶ F₂`, induce a natural transformation `map F₁ ⟶ map F₂`.-/\ndef mapNatTrans {F₁ F₂ : C ⥤ D} (k : F₁ ⟶ F₂) : map F₁ ⟶ map F₂\n    where app X := Quotient.recOnSubsingleton X fun x => ⟨⟨⟨k.app x⟩⟩⟩\n#align category_theory.thin_skeleton.map_nat_trans CategoryTheory.ThinSkeleton.mapNatTrans\n-/\n\n#print CategoryTheory.ThinSkeleton.map₂ /-\n-- TODO: state the lemmas about what happens when you compose with `to_thin_skeleton`\n/-- A functor `C ⥤ D ⥤ E` computably lowers to a functor\n`thin_skeleton C ⥤ thin_skeleton D ⥤ thin_skeleton E` -/\n@[simps]\ndef map₂ (F : C ⥤ D ⥤ E) : ThinSkeleton C ⥤ ThinSkeleton D ⥤ ThinSkeleton E\n    where\n  obj x :=\n    { obj := fun y =>\n        Quotient.map₂ (fun X Y => (F.obj X).obj Y)\n          (fun X₁ X₂ ⟨hX⟩ Y₁ Y₂ ⟨hY⟩ => ⟨(F.obj X₁).mapIso hY ≪≫ (F.mapIso hX).app Y₂⟩) x y\n      map := fun y₁ y₂ =>\n        Quotient.recOnSubsingleton x fun X =>\n          Quotient.recOnSubsingleton₂ y₁ y₂ fun Y₁ Y₂ hY =>\n            homOfLE (hY.le.elim fun g => ⟨(F.obj X).map g⟩) }\n  map x₁ x₂ :=\n    Quotient.recOnSubsingleton₂ x₁ x₂ fun X₁ X₂ f =>\n      {\n        app := fun y =>\n          Quotient.recOnSubsingleton y fun Y => homOfLE (f.le.elim fun f' => ⟨(F.map f').app Y⟩) }\n#align category_theory.thin_skeleton.map₂ CategoryTheory.ThinSkeleton.map₂\n-/\n\nvariable (C)\n\nsection\n\nvariable [Quiver.IsThin C]\n\n#print CategoryTheory.ThinSkeleton.toThinSkeleton_faithful /-\ninstance toThinSkeleton_faithful : Faithful (toThinSkeleton C) where\n#align category_theory.thin_skeleton.to_thin_skeleton_faithful CategoryTheory.ThinSkeleton.toThinSkeleton_faithful\n-/\n\n#print CategoryTheory.ThinSkeleton.fromThinSkeleton /-\n/-- Use `quotient.out` to create a functor out of the thin skeleton. -/\n@[simps]\nnoncomputable def fromThinSkeleton : ThinSkeleton C ⥤ C\n    where\n  obj := Quotient.out\n  map x y :=\n    Quotient.recOnSubsingleton₂ x y fun X Y f =>\n      (Nonempty.some (Quotient.mk_out X)).Hom ≫ f.le.some ≫ (Nonempty.some (Quotient.mk_out Y)).inv\n#align category_theory.thin_skeleton.from_thin_skeleton CategoryTheory.ThinSkeleton.fromThinSkeleton\n-/\n\n#print CategoryTheory.ThinSkeleton.fromThinSkeletonEquivalence /-\nnoncomputable instance fromThinSkeletonEquivalence : IsEquivalence (fromThinSkeleton C)\n    where\n  inverse := toThinSkeleton C\n  counitIso := NatIso.ofComponents (fun X => Nonempty.some (Quotient.mk_out X)) (by tidy)\n  unitIso :=\n    NatIso.ofComponents\n      (fun x =>\n        Quotient.recOnSubsingleton x fun X =>\n          eqToIso (Quotient.sound ⟨(Nonempty.some (Quotient.mk_out X)).symm⟩))\n      (by tidy)\n#align category_theory.thin_skeleton.from_thin_skeleton_equivalence CategoryTheory.ThinSkeleton.fromThinSkeletonEquivalence\n-/\n\n/- warning: category_theory.thin_skeleton.equivalence -> CategoryTheory.ThinSkeleton.equivalence is a dubious translation:\nlean 3 declaration is\n  forall (C : Type.{u2}) [_inst_1 : CategoryTheory.Category.{u1, u2} C] [_inst_4 : Quiver.IsThin.{u2, succ u1} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1))], CategoryTheory.Equivalence.{u2, u1, u2, u2} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) (Preorder.smallCategory.{u2} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) (CategoryTheory.ThinSkeleton.preorder.{u1, u2} C _inst_1)) C _inst_1\nbut is expected to have type\n  forall (C : Type.{u2}) [_inst_1 : CategoryTheory.Category.{u1, u2} C] [_inst_4 : Quiver.IsThin.{u2, succ u1} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1))], CategoryTheory.Equivalence.{u2, u1, u2, u2} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) C (Preorder.smallCategory.{u2} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) (CategoryTheory.ThinSkeleton.preorder.{u1, u2} C _inst_1)) _inst_1\nCase conversion may be inaccurate. Consider using '#align category_theory.thin_skeleton.equivalence CategoryTheory.ThinSkeleton.equivalenceₓ'. -/\n/-- The equivalence between the thin skeleton and the category itself. -/\nnoncomputable def equivalence : ThinSkeleton C ≌ C :=\n  (fromThinSkeleton C).asEquivalence\n#align category_theory.thin_skeleton.equivalence CategoryTheory.ThinSkeleton.equivalence\n\nvariable {C}\n\n#print CategoryTheory.ThinSkeleton.equiv_of_both_ways /-\ntheorem equiv_of_both_ways {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) : X ≈ Y :=\n  ⟨iso_of_both_ways f g⟩\n#align category_theory.thin_skeleton.equiv_of_both_ways CategoryTheory.ThinSkeleton.equiv_of_both_ways\n-/\n\n#print CategoryTheory.ThinSkeleton.thinSkeletonPartialOrder /-\ninstance thinSkeletonPartialOrder : PartialOrder (ThinSkeleton C) :=\n  { CategoryTheory.ThinSkeleton.preorder C with\n    le_antisymm :=\n      Quotient.ind₂\n        (by\n          rintro _ _ ⟨f⟩ ⟨g⟩\n          apply Quotient.sound (equiv_of_both_ways f g)) }\n#align category_theory.thin_skeleton.thin_skeleton_partial_order CategoryTheory.ThinSkeleton.thinSkeletonPartialOrder\n-/\n\n#print CategoryTheory.ThinSkeleton.skeletal /-\ntheorem skeletal : Skeletal (ThinSkeleton C) := fun X Y =>\n  Quotient.induction_on₂ X Y fun x y 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#print CategoryTheory.ThinSkeleton.map_comp_eq /-\ntheorem map_comp_eq (F : E ⥤ D) (G : D ⥤ C) : map (F ⋙ G) = map F ⋙ map G :=\n  Functor.eq_of_iso skeletal <|\n    NatIso.ofComponents (fun X => Quotient.recOnSubsingleton X fun x => Iso.refl _) (by tidy)\n#align category_theory.thin_skeleton.map_comp_eq CategoryTheory.ThinSkeleton.map_comp_eq\n-/\n\n#print CategoryTheory.ThinSkeleton.map_id_eq /-\ntheorem map_id_eq : map (𝟭 C) = 𝟭 (ThinSkeleton C) :=\n  Functor.eq_of_iso skeletal <|\n    NatIso.ofComponents (fun X => Quotient.recOnSubsingleton X fun x => Iso.refl _) (by tidy)\n#align category_theory.thin_skeleton.map_id_eq CategoryTheory.ThinSkeleton.map_id_eq\n-/\n\n#print CategoryTheory.ThinSkeleton.map_iso_eq /-\ntheorem map_iso_eq {F₁ F₂ : D ⥤ C} (h : F₁ ≅ F₂) : map F₁ = map F₂ :=\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\n#print CategoryTheory.ThinSkeleton.thinSkeletonIsSkeleton /-\n/-- `from_thin_skeleton 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-/\n\n#print CategoryTheory.ThinSkeleton.isSkeletonOfInhabited /-\nnoncomputable instance isSkeletonOfInhabited :\n    Inhabited (IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C)) :=\n  ⟨thinSkeletonIsSkeleton⟩\n#align category_theory.thin_skeleton.is_skeleton_of_inhabited CategoryTheory.ThinSkeleton.isSkeletonOfInhabited\n-/\n\nend\n\nvariable {C}\n\n#print CategoryTheory.ThinSkeleton.lowerAdjunction /-\n/-- An adjunction between thin categories gives an adjunction between their thin skeletons. -/\ndef lowerAdjunction (R : D ⥤ C) (L : C ⥤ D) (h : L ⊣ R) : ThinSkeleton.map L ⊣ ThinSkeleton.map R :=\n  Adjunction.mkOfUnitCounit\n    { Unit :=\n        {\n          app := fun X => by\n            letI := is_isomorphic_setoid C\n            refine' Quotient.recOnSubsingleton X fun x => hom_of_le ⟨h.unit.app x⟩ }\n      -- TODO: make quotient.rec_on_subsingleton' so the letI isn't needed\n      counit :=\n        {\n          app := fun X => by\n            letI := is_isomorphic_setoid D\n            refine' Quotient.recOnSubsingleton X fun x => hom_of_le ⟨h.counit.app x⟩ } }\n#align category_theory.thin_skeleton.lower_adjunction CategoryTheory.ThinSkeleton.lowerAdjunction\n-/\n\nend ThinSkeleton\n\nopen ThinSkeleton\n\nsection\n\nvariable {C} {α : Type _} [PartialOrder α]\n\n/- warning: category_theory.equivalence.thin_skeleton_order_iso -> CategoryTheory.Equivalence.thinSkeletonOrderIso is a dubious translation:\nlean 3 declaration is\n  forall {C : Type.{u2}} [_inst_1 : CategoryTheory.Category.{u1, u2} C] {α : Type.{u3}} [_inst_4 : PartialOrder.{u3} α] [_inst_5 : Quiver.IsThin.{u2, succ u1} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1))], (CategoryTheory.Equivalence.{u1, u3, u2, u3} C _inst_1 α (Preorder.smallCategory.{u3} α (PartialOrder.toPreorder.{u3} α _inst_4))) -> (OrderIso.{u2, u3} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) α (Preorder.toLE.{u2} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) (CategoryTheory.ThinSkeleton.preorder.{u1, u2} C _inst_1)) (Preorder.toLE.{u3} α (PartialOrder.toPreorder.{u3} α _inst_4)))\nbut is expected to have type\n  forall {C : Type.{u2}} [_inst_1 : CategoryTheory.Category.{u1, u2} C] {α : Type.{u3}} [_inst_4 : PartialOrder.{u3} α] [_inst_5 : Quiver.IsThin.{u2, succ u1} C (CategoryTheory.CategoryStruct.toQuiver.{u1, u2} C (CategoryTheory.Category.toCategoryStruct.{u1, u2} C _inst_1))], (CategoryTheory.Equivalence.{u1, u3, u2, u3} C α _inst_1 (Preorder.smallCategory.{u3} α (PartialOrder.toPreorder.{u3} α _inst_4))) -> (OrderIso.{u2, u3} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) α (Preorder.toLE.{u2} (CategoryTheory.ThinSkeleton.{u1, u2} C _inst_1) (CategoryTheory.ThinSkeleton.preorder.{u1, u2} C _inst_1)) (Preorder.toLE.{u3} α (PartialOrder.toPreorder.{u3} α _inst_4)))\nCase conversion may be inaccurate. Consider using '#align category_theory.equivalence.thin_skeleton_order_iso CategoryTheory.Equivalence.thinSkeletonOrderIsoₓ'. -/\n/--\nWhen `e : C ≌ α` is a categorical equivalence from a thin category `C` to some partial order `α`,\nthe `thin_skeleton C` is order isomorphic to `α`.\n-/\nnoncomputable def Equivalence.thinSkeletonOrderIso [Quiver.IsThin C] (e : C ≌ α) :\n    ThinSkeleton C ≃o α :=\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\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/Skeletal.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8198933315126792, "lm_q1q2_score": 0.7501211957981644}}
{"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\nFor the convolution product on `finsupp` when the domain has a binary operation,\nsee the type synonyms `add_monoid_algebra`\n(which is in turn used to define `polynomial` and `mv_polynomial`)\nand `monoid_algebra`.\n-/\n\nnoncomputable theory\n\nopen finset\n\nuniverses u₁ u₂ u₃ u₄ u₅\nvariables {α : Type u₁} {β : Type u₂} {γ : Type u₃} {δ : Type u₄} {ι : Type u₅}\n\nnamespace finsupp\n\n/-! ### Declarations about the pointwise product on `finsupp`s -/\n\nsection\nvariables [mul_zero_class β]\n\n/-- The product of `f g : α →₀ β` is the finitely supported function\n  whose value at `a` is `f a * g a`. -/\ninstance : has_mul (α →₀ β) := ⟨zip_with (*) (mul_zero 0)⟩\n\n@[simp] lemma mul_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ * g₂) a = g₁ a * g₂ a :=\nrfl\n\nlemma support_mul [decidable_eq α] {g₁ g₂ : α →₀ β} : (g₁ * g₂).support ⊆ g₁.support ∩ g₂.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 ←not_or_distrib,\n  intro w,\n  apply h,\n  cases w; { rw w, simp },\nend\n\ninstance : mul_zero_class (α →₀ β) :=\n{ zero      := 0,\n  mul       := (*),\n  mul_zero  := λ f, by { ext, simp only [mul_apply, zero_apply, mul_zero], },\n  zero_mul  := λ f, by { ext, simp only [mul_apply, zero_apply, zero_mul], }, }\n\nend\n\ninstance [semigroup_with_zero β] : semigroup_with_zero (α →₀ β) :=\n{ mul       := (*),\n  mul_assoc := λ f g h, by { ext, simp only [mul_apply, mul_assoc], },\n  ..(infer_instance : mul_zero_class (α →₀ β)) }\n\ninstance [non_unital_non_assoc_semiring β] : non_unital_non_assoc_semiring (α →₀ β) :=\n{ left_distrib := λ f g h, by { ext, simp only [mul_apply, add_apply, left_distrib] {proj := ff} },\n  right_distrib := λ f g h,\n    by { ext, simp only [mul_apply, add_apply, right_distrib] {proj := ff} },\n  ..(infer_instance : mul_zero_class (α →₀ β)),\n  ..(infer_instance : add_comm_monoid (α →₀ β)) }\n\ninstance [non_unital_semiring β] : non_unital_semiring (α →₀ β) :=\n{ ..(infer_instance : semigroup (α →₀ β)),\n  ..(infer_instance : non_unital_non_assoc_semiring (α →₀ β)) }\n\ninstance [non_unital_non_assoc_ring β] : non_unital_non_assoc_ring (α →₀ β) :=\n{ left_distrib := λ f g h, by { ext, simp only [mul_apply, add_apply, left_distrib] {proj := ff} },\n  right_distrib := λ f g h,\n    by { ext, simp only [mul_apply, add_apply, right_distrib] {proj := ff} },\n  ..(infer_instance : mul_zero_class (α →₀ β)),\n  ..(infer_instance : add_comm_group (α →₀ β)) }\n\n-- TODO can this be generalized in the direction of `pi.has_scalar'`\n-- (i.e. dependent functions and finsupps)\n-- TODO in theory this could be generalised, we only really need `smul_zero` for the definition\n/-- The pointwise multiplicative action of functions on finitely supported functions -/\ninstance pointwise_module [semiring β] : module (α → β) (α →₀ β) :=\n{ smul := λ f g, finsupp.of_support_finite (λ a, f a • g a) begin\n    apply set.finite.subset g.finite_support,\n    simp only [function.support_subset_iff, finsupp.mem_support_iff, ne.def,\n      finsupp.fun_support_eq, finset.mem_coe],\n    intros x hx h,\n    apply hx,\n    rw [h, smul_zero],\n  end,\n  one_smul := λ b,\n    by { ext a, simp only [one_smul, pi.one_apply, finsupp.of_support_finite_coe], },\n  mul_smul := λ x y b, by simp [finsupp.of_support_finite_coe, mul_smul],\n  smul_add := λ r x y, finsupp.ext (λ a, by simpa only [smul_add, pi.add_apply, coe_add]),\n  smul_zero := λ b, finsupp.ext (by simp [finsupp.of_support_finite_coe, smul_zero]),\n  zero_smul := λ a, finsupp.ext (λ b, by simp [finsupp.of_support_finite_coe]),\n  add_smul := λ r s x, finsupp.ext (λ b, by simp [finsupp.of_support_finite_coe, add_smul]) }\n\n@[simp]\nlemma coe_pointwise_module [semiring β] (f : α → β) (g : α →₀ β) :\n  ⇑(f • g) = f • g := rfl\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/pointwise.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7501211922148354}}
{"text": "-- 実数のインポート\nimport data.real.basic\n\nimport tactic.suggest\n\n-- 排中律を認める\nnoncomputable theory\nopen_locale classical\n\nuniverse u\n\n-- mathlibの実数の上界の定義\n#check upper_bounds\n\n-- 実数の集合の上界の集合\ndef up_bounds (A : set ℝ) := { x : ℝ | ∀ a ∈ A, a ≤ x }\n\ndef is_maximum (a : ℝ) (A : set ℝ) := a ∈ A ∧ a ∈ up_bounds A\ninfix ` is_a_max_of `:55 := is_maximum\n\n-- 実数の集合はただ一つの最大値を持つ．\nlemma unique_max {A : set ℝ} {x y : ℝ} (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=\nbegin\n  cases hx with x_in x_up,\n  cases hy with y_in y_up,\n  \n  specialize x_up y,\n  specialize x_up y_in,\n\n  specialize y_up x,\n  specialize y_up x_in,\n\n  -- x ≤ y かつ y ≤ x ならば x = y\n  linarith,\nend\n\n-- unique_maxの証明は次のようにも書ける．\nexample (A : set ℝ) (x y : ℝ) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=\nbegin\n  have : x ≤ y := hy.2 x hx.1,\n  have : y ≤ x := hx.2 y hy.1,\n  linarith,\nend \n\n-- unique_maxの証明は次のようにも書ける．(2)\nexample (A : set ℝ) (x y : ℝ) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=\n  le_antisymm (hy.2 x hx.1) (hx.2 y hy.1)\n\n-- 実数の下界の集合\ndef low_bounds (A : set ℝ) := { x : ℝ | ∀ a ∈ A, x ≤ a}\n\n-- infimum（下限）\ndef is_inf (x : ℝ) (A : set ℝ) := x is_a_max_of (low_bounds A)\ninfix ` is_an_inf_of `:55 := is_inf\n\n-- Aの下限より大きい数は，あるAの要素より大きい数である\nlemma inf_lt {A : set ℝ} {x : ℝ} (hx : x is_an_inf_of A) : ∀ y, x < y → ∃ a ∈ A, a < y :=\nbegin\n  intro y,\n  -- 対偶を示す\n  contrapose, \n  -- ¬∃を∀に変換\n  push_neg,\n  intro h, -- `h`は，`A`の下界が`y`であると主張している．\n  exact hx.2 y h,\nend\n\n-- `contrapose`と`push_neg`は`contrapose!`で略すこともできる．\n\n\n-- すべての正の`ε`に対して`y ≤ x + ε`ならば，`y ≤ x`\nlemma le_of_le_add_eps {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) → y ≤ x := \nbegin\n  contrapose!,\n  intro h,\n  -- ある`ε`について，`((y - x) / 2)`を代入\n  use ((y - x) / 2),\n  split,\n  linarith,\n  linarith,\nend\n\nexample {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) →  y ≤ x := \nbegin\n  contrapose!,\n  exact assume h, ⟨(y-x)/2, by linarith, by linarith⟩, \n  -- `∃ z, P z`の証明は，`z₀`の構成と，`P z₀`の証明の複合で成り立つ．これを`⟨z₀, h⟩`と表記する．\n  -- `P ∧ Q`の証明も同様に`⟨P, Q⟩`と表記する．\n  -- `⟨z₀, ⟨h₁, h₂⟩⟩`は右結合性より`⟨z₀, h₁, h₂⟩`と書ける．\nend\n\n-- `begin`/`end`は更に`by`を用いて次のように省略できる．\nexample {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) →  y ≤ x := \n  by {contrapose!, exact assume h, ⟨(y-x)/2, by linarith, by linarith⟩}\n\nexample {x y : ℝ} : (∀ ε > 0, y ≤ x + ε) →  y ≤ x := \nbegin\n  intro h,\n  -- 背理法\n  by_contradiction H,\n  push_neg at H,\n  have key := calc\n    y   ≤ x + (y - x)/2 : h _ (by linarith)\n    ... = x/2 + y/2     : by ring -- 環の性質より\n    ... < y             : by linarith, -- 線形性の性質より \n  -- linarith\n  apply lt_irrefl y,\n  exact key,\nend\n\n-- 絶対値\nlocal notation `|`x`|` := abs x\n\n-- 実数列の収束について．実数列`u`の極限は`l`に収束する．\n-- `(u n)`は数列`u`の`n`番目の項を指す．\ndef limit (u : ℕ → ℝ) (l : ℝ) := ∀ ε > 0, ∃ N, ∀ n ≥ N, |(u n) - l| ≤ ε\n\n-- 実数列uのすべてのn番目の項以下なら，極限値よりも小さい．\nlemma le_lim {x y : ℝ} {u : ℕ → ℝ} (hu : limit u x) (ineq : ∀ n, y ≤ (u n)) : y ≤ x :=\nbegin\n  apply le_of_le_add_eps,\n  intros ε ε_pos,\n  cases hu ε ε_pos with N HN,\n  calc\n    y   ≤ (u N)         : ineq N\n    ... = x + ((u N) - x) : by linarith\n    ... ≤ x + |(u N) - x| : add_le_add (by linarith) (by library_search) --- `library_search`で適した定理や補題を自動で持ってくる\n    ... ≤ x + ε           : add_le_add (by linarith) (HN N (by linarith)),\nend\n\n-- `(n + 1 : ℝ)`で自然数(ℕ)`n + 1`を実数(ℝ)に変換していることに注意．\nlemma inv_suc_pos : ∀ n : ℕ, 1 / (n + 1 : ℝ) > 0 :=\nbegin\n  intro n,\n  suffices : (n + 1 : ℝ) > 0,\n  { library_search }, -- 正の数の逆数は正であるという主張の補題を自動補完\n  norm_cast, -- 自然数についての主張に戻す\n  linarith,\nend\n\nexample : ∀ n : ℕ, 1/(n+1 : ℝ) > 0 :=\n  λ n, one_div_pos.mpr (by exact_mod_cast nat.succ_pos n)\n\nlemma limit_inv_succ : ∀ ε > 0, ∃ N : ℕ, ∀ n ≥ N, (1 / (n + 1 : ℝ)) ≤ ε :=\nbegin\n  intros ε ε_pos,\n  suffices : ∃ N : ℕ, 1 / ε ≤ N,\n  {\n    cases this with N HN,\n    use N,\n    intros n Hn,\n    rw [div_le_iff', ← div_le_iff ε_pos],\n    replace Hn : (N : ℝ) ≤ n, exact_mod_cast Hn,\n    linarith,\n    exact_mod_cast (nat.succ_pos n),\n  },\n  -- exact exists_nat_ge (1 / ε)\n  exact archimedean_iff_nat_le.1 (by apply_instance) (1/ε),\nend\n\nlemma inf_seq (A : set ℝ) (x : ℝ) :\n  (x is_an_inf_of A) ↔ (x ∈ low_bounds A ∧ (∃ u : ℕ → ℝ, ((limit u x) ∧ (∀ n, u n ∈ A)))) :=\nbegin\n  split,\n  {\n    intro h,\n    split,\n    { exact h.1 },\n    have key : ∀ n : ℕ, ∃ a ∈ A, a < x + 1/(n + 1),\n    {\n      intro n,\n      apply inf_lt h,\n      have : 0 < 1/(n+1:ℝ), from inv_suc_pos n,\n      linarith,\n    },\n    {\n      choose u hu using key, -- 選択公理\n      use u,\n      split,\n      {\n        intros ε ε_pos,\n        cases (limit_inv_succ ε ε_pos) with N H,\n        use N,\n        intros n hn,\n        have : x ≤ (u n), from h.1 _ (hu n).1,\n        have : (u n) < x + ε := calc\n          u n < x + 1/(n + 1) : (hu n).2\n          ... ≤ x + ε         : add_le_add (le_refl x) (H n hn),\n        rw abs_of_nonneg,\n        linarith, \n        linarith, \n      },\n      {\n        intro n,\n        exact (hu n).1,\n      },\n    }\n  },\n  {\n    intro h,\n    rcases h with ⟨ x_min, u, lim, huA⟩, \n    fconstructor,\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),\n  },\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/00_first_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012717045181, "lm_q2_score": 0.7931059438487663, "lm_q1q2_score": 0.7501206102885754}}
{"text": "/-\nCopyright (c) 2022 Sina Hazratpour. All rights reserved.\nReleased under Apache 2.0 license as described in the file LICENSE.\n----------------\n\n# Algebra of Functions (Part III) : Function Composition\nSina Hazratpour\nIntroduction to Proof  \nMATH 301, Johns Hopkins University, Fall 2022   \n-/\n\nimport ..prooflab\nimport lectures.lec4_equality_of_functions\n\nset_option pp.beta true\nset_option pp.generalized_field_notation false\n-- set_option pp.all true\n\n\n\n\n/- \nNew tactics we'll learn in this lesson: \n10. `dsimp` and its variants \n11. `cases`\n-/\n\n\nnamespace PROOFS\n\nvariables {A B C X Y Z U V W : Type}\n\n\n\n/-! ### Composition of Functions** -/\n\n/-\nA function can be implemented in different ways, but once it is implemented, we can forget about the details of its implementation and concentrate on how it interacts with other functions. There is an interesting algebra of interactions of functions.\n\n\nThe main way functions interact is via the operation of __composition__. The main idea of composition of functions is to create _compound_ functions from simpler functions which can do more tasks. \n\n\nThe operation of composition gives us an incredibly powerful tool to focus on these interaction of functions.\n\n\nSuppose `f : A → B` and `g : B → C` are functions. \nWe define a new function `g ∘ f : A → C` by letting\n\n` g ∘ f (x) =  g(f(x))`\n\n\nThe function `g ∘ f` is called the __composition__ of `f` and `g` which we also call \"f composed with g\" (or \"g after f\"). Often when there is no risk of confusion mathematicians dispense with `∘` in the notation above and simply write `g f` for the composition of `f` and `g`.\n-/\n\n\n-- namespace composition\n\ndef compose {X Y Z : Type} (g: Y → Z) (f: X → Y) : X → Z := \nλ x : X,  g (f x)\n\n#check compose\n#check @compose\n\n\ndef compose_Nicole {X Y Z : Type} (f : X → Y) (g : Y → Z): X → Z := \nλ x : X,  g (f x)\n\n#check @compose_Nicole\n\n/-\n*Note*: heed the explicit vs implicit variables! \n-/\n\nvariables (f₀ : ℕ → ℤ) (g₀ : ℤ → ℚ) (h₀ : ℚ → ℕ )\n\n#check compose g₀ f₀ \n#check g₀ ∘ f₀ -- shorthand notation for `compose g₀ f₀`. \n\n\n/-\n- Note that we can compose two functions only if the domain of the first one matches with the codomain of the second one. \n-/\n\n/- \n- A shorthand notation for `compose f g` is `f ∘ g`. To get `∘` type \"\\comp\".\n- infixr  ` ∘ ` := comp\n-/ \n\n-- #check g₀ ∘ f₀  \n#check h₀ ∘ f₀ -- can you understand the error?\n#check (h₀ ∘ g₀) ∘ f₀ \n#check h₀ ∘ (g₀ ∘ f₀)\n#check (h₀ ∘ g₀) ∘ f₀ \n#check g₀ ∘ (f₀ ∘ h₀) \n\n\n/-\n*Note*: by default, Lean reads `h₀ ∘ g₀ ∘ f₀` as `(h₀ ∘ g₀) ∘ f₀`, that is the bracketing is from the left to right.  \n-/\n\n\n\n\n/-\nThere is a wonderful yet very simple function which is defined in the same way for every object. This is the so-called __identity function__ of that object. For an object `A`, Lean defines a function `id : A → A` which assigns to an element `a` itself! Therefore, \n`id a = a`. \n-/ \n\nsection \nvariable a : A\n#check id \n#check id a\nend \n\nlemma id_def (a : A) : \n  id a = a \n:= \nbegin\nrefl,  \nend  \n\n\n\n#check switch \n#eval switch ff\n#check switch ∘ switch \n-- #eval (switch ∘ switch) ff\n\n\nsection \nvariable b : bool \n#check switch b \n#eval switch b\nend \n\n\nlemma switch_switch_alt : \n  switch ∘ switch = id := \nbegin\n  funext b, \n  dsimp,\n  refl, -- this does not work since `switch b` depends on the value of `b`, and we have to reason by cases. \nend \n\n\n\nlemma switch_switch : \n  switch ∘ switch = id := \nbegin\n  funext b, \n  dsimp,\n  cases b, -- tactic `cases` branches the proof into two branches, one when `b = ff` and the second branch when `b = tt` \n  {\n    refl, \n  }, \n  {\n    refl, \n  },\nend \n\n\n\n\nlemma switch_switch_alt_alt : \n  switch ∘ switch = id := \nbegin\n  funext b, \n  dsimp,\n  cases b, \n  repeat {refl},\nend \n\n\n\n\nlemma swap_square_is_id (X Y : Type) : (swap_pair Y X) ∘ (swap_pair X Y)= id := \nbegin\next p, \nrepeat {refl}, -- instead of writing refl two times. \nend \n\n\n\n\n-- function `fun_pair` takes two functions and returns their cartesian product, i.e. a function from the cartesian product of the domains of the input function to the cartesian product of the codomains of the the input functions. \n\ndef fun_pair (f : A → B) (g : X → Y) (p : A × X) : B × Y   := \n(f p.1 , g p.2)\n\n\n\n#check fun_pair \n#check fun_pair double switch \n#eval (fun_pair double switch) (2, ff)\n\n\n\n\n\n#check pairing\n#check @pairing \n\n\n/-\nTherer is a difference between the functions `pairing` and `fun_pair`. \n1. `pairing` takes two functions with the same domain as inputs.  \n2. `fun_pair` on the other hand takes any two functions as input. \n\nHowever, theorem `fun_pair_is_pairing` below proves that the two functions `pairing` and `fun_pair` are intimately related. \n-/\n\nlemma fun_pair_is_pairing (f : A → X) (g : B → Y) : \nfun_pair (f : A → X) (g : B → Y) =  \npairing (λ c : A × B, f c.1) (λ c : A × B, g c.2) := \nbegin\n  funext x, \n  refl, \nend \n\n\n\n/- \nProjection `fst` and `pairing` commute. \n-/\nlemma fun_of_fst_is_fst_of_fun_pair (X₁ Y₁ X₂ Y₂: Type) (f : X₁ → Y₁) (g : X₂ → Y₂) : fst ∘ (fun_pair f g) = f ∘ fst := \nbegin\n  ext p, \n  refl, \nend  \n\n\ndef associator (X Y Z : Type) : X × (Y × Z) → (X × Y) × Z := \nλ p, ((p.1, p.2.1), p.2.2)\n \n#check associator \n\n--Challenge: prove pentagon \n\n\n\n\n\n\n/-! ### Propoerties of composition of functions -/\n\n\n/- \n__unitality of composition__ is a fancy name for saying that the composition of the identity function and any function `f` is the same function `f`. \n-/\n\n/-\nFor any given function `f : X → Y` we want to prove that `id ∘ f = f`. Therefore in Lean we write \n\nlemma comp_left_unitality (f : X → Y) : id ∘ f = f  \n:= proof \n\nNow we need to supply the proof. But let's think about `id ∘ f`. For any `x : X`, we have \n`(id ∘ f) x = id (f x) = f x` where these equalities are proved by `rfl`. By `funext` we can conclude that \n`id ∘ f = f`. \n-/\n\n/-\n__left unitality of composition__\n-/ \n\nlemma comp_left_unit {X Y : Type} (f : X → Y) : \n  id ∘ f = f := \nbegin\nfunext x,\ndsimp,\nrefl,\nend \n\n\n/-\n__right unitality of composition__\n-/ \nlemma comp_right_unit {X Y : Type} (f : X → Y) : \n  f ∘ id = f := \nbegin \nfunext x, \ndsimp, \nrefl, \nend \n\n\n/- \nThe theorem __associativity of composition__ says in that the order of bracketing in the composition of three functions (with matching domaisn and codomains) does not matter since the two different ways of composition result in the same function, that is \n`(h ∘ g) ∘ f  = h ∘ (g ∘ f)` \nfor any three functions `(f : X → Y ) (g : Y → Z) (h : Z → W) `. \n-/\n\ntheorem comp_assoc {X Y Z W: Type} (f : X → Y ) (g : Y → Z) (h : Z → W) :   (h ∘ g) ∘ f  = h ∘ (g ∘ f)  := \nbegin \nfunext x, \ndsimp, \nrefl, \nend \n\n\n\ntheorem comp_tetrahedral_assoc (f : X → Y ) (g : Y → Z) (h : Z → W) (k : W → V) : k ∘ (h ∘ ( g ∘ f)) = ((k ∘ h) ∘ g) ∘ f \n:= \nbegin\n  funext x, \n  dsimp, \n  refl, \nend \n\n\ntheorem comp_tetrahedral_assoc_alt (f : X → Y ) (g : Y → Z) (h : Z → W) (k : W → V) : k ∘ (h ∘ ( g ∘ f)) = ((k ∘ h) ∘ g) ∘ f \n:= \nbegin\n  calc k ∘ (h ∘ ( g ∘ f)) = (k ∘ h ) ∘ (g ∘ f) : by rw comp_assoc (g ∘ f) h k \n  ... = ((k ∘ h) ∘ g) ∘ f : by rw comp_assoc f g (k ∘ h),   \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/lectures/lec5_function_composition.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7500857242578332}}
{"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.filter.lift\nimport topology.separation\nimport data.set.intervals.monotone\n\n/-!\n# Topology on the set of filters on a type\n\n> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.\n> Any changes to this file require a corresponding PR to mathlib4.\n\nIn this file introduce topology on `filter α`. It is generated by the sets\n`set.Iic (𝓟 s) = {l : filter α | s ∈ l}`, `s : set α`. A set `s : set (filter α)` is open if and\nonly if it is a union of a family of these basic open sets, see `filter.is_open_iff`.\n\nThis topology has the following important properties.\n\n* If `X` is a topological space, then the map `𝓝 : X → filter X` is a topology inducing map.\n\n* In particular, it is a continuous map, so `𝓝 ∘ f` tends to `𝓝 (𝓝 a)` whenever `f` tends to `𝓝 a`.\n\n* If `X` is an ordered topological space with order topology and no max element, then `𝓝 ∘ f` tends\n  to `𝓝 filter.at_top` whenever `f` tends to `filter.at_top`.\n\n* It turns `filter X` into a T₀ space and the order on `filter X` is the dual of the\n  `specialization_order (filter X)`.\n\n## Tags\n\nfilter, topological space\n-/\n\nopen set filter topological_space\nopen_locale filter topology\n\nvariables {ι : Sort*} {α β X Y : Type*}\n\nnamespace filter\n\n/-- Topology on `filter α` is generated by the sets `set.Iic (𝓟 s) = {l : filter α | s ∈ l}`,\n`s : set α`. A set `s : set (filter α)` is open if and only if it is a union of a family of these\nbasic open sets, see `filter.is_open_iff`. -/\ninstance : topological_space (filter α) := generate_from $ range $ Iic ∘ 𝓟\n\nlemma is_open_Iic_principal {s : set α} : is_open (Iic (𝓟 s)) :=\ngenerate_open.basic _ (mem_range_self _)\n\nlemma is_open_set_of_mem {s : set α} : is_open {l : filter α | s ∈ l} :=\nby simpa only [Iic_principal] using is_open_Iic_principal\n\nlemma is_topological_basis_Iic_principal :\n  is_topological_basis (range (Iic ∘ 𝓟 : set α → set (filter α))) :=\n{ exists_subset_inter :=\n    begin\n      rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ l hl,\n      exact ⟨Iic (𝓟 s) ∩ Iic (𝓟 t), ⟨s ∩ t, by simp⟩, hl, subset.rfl⟩\n    end,\n  sUnion_eq := sUnion_eq_univ_iff.2 $ λ l, ⟨Iic ⊤, ⟨univ, congr_arg Iic principal_univ⟩, le_top⟩,\n  eq_generate_from := rfl }\n\nlemma is_open_iff {s : set (filter α)} :\n  is_open s ↔ ∃ T : set (set α), s = ⋃ t ∈ T, Iic (𝓟 t) :=\nis_topological_basis_Iic_principal.open_iff_eq_sUnion.trans $\n  by simp only [exists_subset_range_iff, sUnion_image]\n\n\n\nlemma nhds_eq' (l : filter α) : 𝓝 l = l.lift' (λ s, {l' | s ∈ l'}) :=\nby simpa only [(∘), Iic_principal] using nhds_eq l\n\nprotected lemma tendsto_nhds {la : filter α} {lb : filter β} {f : α → filter β} :\n  tendsto f la (𝓝 lb) ↔ ∀ s ∈ lb, ∀ᶠ a in la, s ∈ f a :=\nby simp only [nhds_eq', tendsto_lift', mem_set_of_eq]\n\nlemma has_basis.nhds {l : filter α} {p : ι → Prop} {s : ι → set α} (h : has_basis l p s) :\n  has_basis (𝓝 l) p (λ i, Iic (𝓟 (s i))) :=\nby { rw nhds_eq, exact h.lift' monotone_principal.Iic }\n\n/-- Neighborhoods of a countably generated filter is a countably generated filter. -/\ninstance {l : filter α} [is_countably_generated l] : is_countably_generated (𝓝 l) :=\nlet ⟨b, hb⟩ := l.exists_antitone_basis in has_countable_basis.is_countably_generated $\n  ⟨hb.nhds, set.to_countable _⟩\n\nlemma has_basis.nhds' {l : filter α} {p : ι → Prop} {s : ι → set α} (h : has_basis l p s) :\n  has_basis (𝓝 l) p (λ i, {l' | s i ∈ l'}) :=\nby simpa only [Iic_principal] using h.nhds\n\nlemma mem_nhds_iff {l : filter α} {S : set (filter α)} :\n  S ∈ 𝓝 l ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ S :=\nl.basis_sets.nhds.mem_iff\n\nlemma mem_nhds_iff' {l : filter α} {S : set (filter α)} :\n  S ∈ 𝓝 l ↔ ∃ t ∈ l, ∀ ⦃l' : filter α⦄, t ∈ l' → l' ∈ S :=\nl.basis_sets.nhds'.mem_iff\n\n@[simp] lemma nhds_bot : 𝓝 (⊥ : filter α) = pure ⊥ :=\nby simp [nhds_eq, lift'_bot monotone_principal.Iic]\n\n@[simp] lemma nhds_top : 𝓝 (⊤ : filter α) = ⊤ := by simp [nhds_eq]\n\n@[simp] lemma nhds_principal (s : set α) : 𝓝 (𝓟 s) = 𝓟 (Iic (𝓟 s)) :=\n(has_basis_principal s).nhds.eq_of_same_basis (has_basis_principal _)\n\n@[simp] lemma nhds_pure (x : α) : 𝓝 (pure x : filter α) = 𝓟 {⊥, pure x} :=\nby rw [← principal_singleton, nhds_principal, principal_singleton, Iic_pure]\n\n@[simp] lemma nhds_infi (f : ι → filter α) : 𝓝 (⨅ i, f i) = ⨅ i, 𝓝 (f i) :=\nby { simp only [nhds_eq], apply lift'_infi_of_map_univ; simp }\n\n@[simp] lemma nhds_inf (l₁ l₂ : filter α) : 𝓝 (l₁ ⊓ l₂) = 𝓝 l₁ ⊓ 𝓝 l₂ :=\nby simpa only [infi_bool_eq] using nhds_infi (λ b, cond b l₁ l₂)\n\nlemma monotone_nhds : monotone (𝓝 : filter α → filter (filter α)) :=\nmonotone.of_map_inf nhds_inf\n\nlemma Inter_nhds (l : filter α) : ⋂₀ {s | s ∈ 𝓝 l} = Iic l :=\nby simp only [nhds_eq, sInter_lift'_sets monotone_principal.Iic, Iic, le_principal_iff,\n  ← set_of_forall, ← filter.le_def]\n\n@[simp] lemma nhds_mono {l₁ l₂ : filter α} : 𝓝 l₁ ≤ 𝓝 l₂ ↔ l₁ ≤ l₂ :=\nbegin\n  refine ⟨λ h, _, λ h, monotone_nhds h⟩,\n  rw [← Iic_subset_Iic, ← Inter_nhds, ← Inter_nhds],\n  exact sInter_subset_sInter h\nend\n\nprotected lemma mem_interior {s : set (filter α)} {l : filter α} :\n  l ∈ interior s ↔ ∃ t ∈ l, Iic (𝓟 t) ⊆ s :=\nby rw [mem_interior_iff_mem_nhds, mem_nhds_iff]\n\nprotected lemma mem_closure {s : set (filter α)} {l : filter α} :\n  l ∈ closure s ↔ ∀ t ∈ l, ∃ l' ∈ s, t ∈ l' :=\nby simp only [closure_eq_compl_interior_compl, filter.mem_interior, mem_compl_iff, not_exists,\n  not_forall, not_not, exists_prop, not_and, and_comm, subset_def, mem_Iic, le_principal_iff]\n\n@[simp] protected lemma closure_singleton (l : filter α) : closure {l} = Ici l :=\nby { ext l', simp [filter.mem_closure, filter.le_def] }\n\n@[simp] lemma specializes_iff_le {l₁ l₂ : filter α} : l₁ ⤳ l₂ ↔ l₁ ≤ l₂ :=\nby simp only [specializes_iff_closure_subset, filter.closure_singleton, Ici_subset_Ici]\n\ninstance : t0_space (filter α) :=\n⟨λ x y h, (specializes_iff_le.1 h.specializes).antisymm (specializes_iff_le.1 h.symm.specializes)⟩\n\nlemma nhds_at_top [preorder α] : 𝓝 at_top = ⨅ x : α, 𝓟 (Iic (𝓟 (Ici x))) :=\nby simp only [at_top, nhds_infi, nhds_principal]\n\nprotected lemma tendsto_nhds_at_top_iff [preorder β] {l : filter α} {f : α → filter β} :\n  tendsto f l (𝓝 at_top) ↔ ∀ y, ∀ᶠ a in l, Ici y ∈ f a :=\nby simp only [nhds_at_top, tendsto_infi, tendsto_principal, mem_Iic, le_principal_iff]\n\nlemma nhds_at_bot [preorder α] : 𝓝 at_bot = ⨅ x : α, 𝓟 (Iic (𝓟 (Iic x))) := @nhds_at_top αᵒᵈ _\n\nprotected lemma tendsto_nhds_at_bot_iff [preorder β] {l : filter α} {f : α → filter β} :\n  tendsto f l (𝓝 at_bot) ↔ ∀ y, ∀ᶠ a in l, Iic y ∈ f a :=\n@filter.tendsto_nhds_at_top_iff α βᵒᵈ _ _ _\n\nvariables [topological_space X]\n\nlemma nhds_nhds (x : X) :\n  𝓝 (𝓝 x) = ⨅ (s : set X) (hs : is_open s) (hx : x ∈ s), 𝓟 (Iic (𝓟 s)) :=\nby simp only [(nhds_basis_opens x).nhds.eq_binfi, infi_and, @infi_comm _ (_ ∈ _)]\n\nlemma inducing_nhds : inducing (𝓝 : X → filter X) :=\ninducing_iff_nhds.2 $ λ x, (nhds_def' _).trans $\n  by simp only [nhds_nhds, comap_infi, comap_principal, Iic_principal, preimage_set_of_eq,\n    ← mem_interior_iff_mem_nhds, set_of_mem_eq, is_open.interior_eq] { contextual := tt }\n\n@[continuity] lemma continuous_nhds : continuous (𝓝 : X → filter X) := inducing_nhds.continuous\n\nprotected lemma tendsto.nhds {f : α → X} {l : filter α} {x : X} (h : tendsto f l (𝓝 x)) :\n  tendsto (𝓝 ∘ f) l (𝓝 (𝓝 x)) :=\n(continuous_nhds.tendsto _).comp h\n\nend filter\n\nvariables [topological_space X] [topological_space Y] {f : X → Y} {x : X} {s : set X}\n\nlemma continuous_within_at.nhds (h : continuous_within_at f s x) :\n  continuous_within_at (𝓝 ∘ f) s x :=\nh.nhds\n\nlemma continuous_at.nhds (h : continuous_at f x) : continuous_at (𝓝 ∘ f) x := h.nhds\nlemma continuous_on.nhds (h : continuous_on f s) : continuous_on (𝓝 ∘ f) s := λ x hx, (h x hx).nhds\nlemma continuous.nhds (h : continuous f) : continuous (𝓝 ∘ f) := filter.continuous_nhds.comp 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/topology/filter.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312226373181, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7500857223209653}}
{"text": "import Mathlib.Algebra.Ring.Basic\nimport Mathlib.Data.Rat.Basic\nimport Mathlib.Tactic.Ring\n\n/-\nBulgarian Mathematical Olympiad 1998, Problem 8\nThe polynomials Pₙ(x,y) for n = 1, 2, ... are defined by P₁(x,y) = 1 and\n  Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y)\nProve that Pₙ(x,y) = Pₙ(y,x) for all x,y,n.\n-/\n\nvariable {R : Type} [CommRing R]\n\ndef P : ℕ → R → R → R\n| 0, _, _ => 1\n| n+1, x, y => (x + y - 1) * (y + 1) * P n x (y + 2) + (y - y^2) * P n x y\n\n/- helper function\n   Sₙ₋₁(x,y) = [(x + y)² - 1](y + 1)(x + 1)Pₙ₋₁(y+2, x+2).\n-/\ndef S : ℕ → R → R → R\n| n, x, y => ((x + y)^2 - 1) * (y + 1) * (x + 1) * P n (y + 2) (x + 2)\n\n/- helper function\n   Tₙ₋₁(x,y) = (y - y²)(x - x²)Pₙ₋₁(y, x).\n-/\ndef T : ℕ → R → R → R\n| n, x, y => (y - y^2) * (x - x^2) * P n y x\n\n/- helper function\n   Uₙ₋₁(x,y) = (x + y - 1) [(y + 1)(x - x²)Pₙ₋₁(y + 2, x)\n                           + (x + 1)(y - y²) Pₙ₋₁(y, x + 2)]\n-/\ndef U : ℕ → R → R → R\n| n, x, y => (x + y - 1) *((y + 1)*(x - x^2) * P n (y + 2) x\n                           + (x + 1) * (y - y^2) * P n y (x + 2))\n\ntheorem bulgaria1998_q8 (n : ℕ) (x y : R) : P n x y = P n y x := by\n  -- We induct on n. For n = 1,2 the result is evident.\n  -- So we take n > 1 and suppose that the result is true for\n  -- Pₙ₋₁(x,y) and Pₙ₋₂(x,y).\n  revert x y\n  induction n using Nat.strong_induction_on with | h n ih =>\n  cases n with | zero => intros; rfl | succ n =>\n  cases n with | zero => intros; dsimp only [P]; ring | succ n =>\n\n  -- in the informal proof at this point, we're trying to\n  -- prove the end result at n+1.\n  -- In our formal version, that corresponds to proving the result for\n  -- n.succ.succ\n\n  /- We have\n     Pₙ₊₁(x,y) = (x + y - 1)(y + 1)Pₙ(x,y+2) + (y - y²)Pₙ(x,y)\n               = (x + y - 1)(y + 1)Pₙ(y+2,x) + (y - y²)Pₙ(y,x)\n  -/\n\n  have ih1 := ih n.succ (lt_add_one n.succ)\n  have h1 : ∀ x y : R, P n.succ.succ x y =\n               (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) +\n                   (y - y^2) * (P n.succ y x) := by\n    intros x y\n    calc P (n.succ.succ) x y\n        = (x + y - 1) * (y + 1) * (P n.succ x (y + 2)) +\n          (y - y^2) * (P n.succ x y) := rfl\n      _ = (x + y - 1) * (y + 1) * (P n.succ (y + 2) x) +\n          (y - y^2) * (P n.succ y x) := by rw[ih1 x y, ih1 x (y+2)]\n\n  have h2 : ∀ x y : R, (x + y - 1) * (y + 1) * P n.succ (y + 2) x\n        = S n x y + (x + y - 1)* (y + 1) * (x - x^2)* P n (y+2) x := by\n     intros x y; dsimp only [S, P]; ring\n\n  have h_s_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, S m x y = S m y x := by\n    intros m hm x y; dsimp only [S]; rw[ih m hm (x + 2) (y + 2)]; ring\n\n  have h4 : ∀ x y : R, (y - y^2) * P n.succ y x =\n              (y - y^2) * (x + y -1) * (x + 1) * P n y (x + 2) + T n x y := by\n    intros x y; dsimp only[T, P]; ring\n\n  have h_t_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, T m x y = T m y x := by\n    intros m hm x y; dsimp only[T]; rw[ih m hm x y]; ring\n\n  have h_u_symm : ∀ m : ℕ, m < n.succ.succ → ∀ x y : R, U m x y = U m y x := by\n    intros m hm x y; dsimp only [U]; rw[ih m hm (y+2) x, ih m hm (x+2) y]; ring\n\n  have h7 : ∀ x y : R, P n.succ.succ x y = S n x y + T n x y + U n x y := by\n    intros x y; rw[h1 x y, h2 x y, h4 x y]; dsimp only [U]; ring\n\n  have h8 : n < n.succ := lt_add_one n\n  have h9 : n < n.succ.succ := Nat.lt.step h8\n\n  intros x y\n  calc P n.succ.succ x y\n      = S n x y + T n x y + U n x y := h7 x y\n    _ = S n y x + T n x y + U n x y := by rw[h_s_symm n h9 x y]\n    _ = S n y x + T n y x + U n x y := by rw[h_t_symm n h9 x y]\n    _ = S n y x + T n y x + U n y x := by rw[h_u_symm n h9 x y]\n    _ = P n.succ.succ y x := (h7 y x).symm\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/Bulgaria1998Q8.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7500857166454634}}
{"text": "variable {p : Prop}\nvariable {q : Prop}\n\n-- given a value in `p`, exhibit a function that takes a `q` and returns a `p`.\ntheorem t1 : p → (q → p) := fun (vp : p) => (fun (_vq : q) => vp)\n#print t1  -- fun {p q} vp _vq => vp\n\ntheorem t1_alt : p → q → p :=\n  fun hp : p =>\n  fun _hq : q =>\n  show p from hp\n#print t1_alt\n\ntheorem t1_alt2 (hp : p) (_hq : q) : p := hp\n#print t1_alt2\n\naxiom hp : p\n\n/- Apply theorem t1 -/\ntheorem t2 : q → p := t1 hp\n\n/-\nsection unsound\n  axiom unsound : False\n  theorem one_eq_zero : 1 = 0 := False.elim unsound\nend unsound\n\n#check unsound  -- unsoundness escapes the section!\n-/\n\nvariable (p q r s : Prop)\ntheorem compose (h₁ : q → r) (h₂ : p → q) (hp : p) : r :=\n  h₁ (h₂ hp)\n\ntheorem compose_alt (h₁ : q → r) (h₂ : p → q) : p → r :=\n  fun hp : p =>\n  show r from h₁ (h₂ hp)\n\n-- p → q and ¬ q implies ¬ p\nexample (hpq: p → q) (hnq: ¬ q) : ¬ p :=\n  fun hp : p => show False from hnq (hpq hp)\n\n-- ex falso\nexample (hp : p) (hnp : ¬ p) : q :=\n  show q from False.elim (hnp hp)\n\nexample (hp : p) (hnp : ¬ p) : q := absurd hp hnp\n#check absurd  -- absurd.{v} {a : Prop} {b : Sort v} (h₁ : a) (h₂ : ¬a) : b\n\n\n-- canonical proof of True\nexample (_t : True) := True.intro\n\n-- logical equivalence\n\ntheorem and_swap : p ∧ q ↔ q ∧ p :=\n  Iff.intro\n    -- left => right\n    (fun h : p ∧ q =>\n     show q ∧ p from And.intro (And.right h) (And.left h))\n    -- right => left\n    (fun h : q ∧ p =>\n     show p ∧ q from And.intro (And.right h) (And.left h))\n\n#check and_swap p q    -- p ∧ q ↔ q ∧ p\n\n-- compare to and_commutative.lean proof\nexample (h : p ∧ q) : q ∧ p := Iff.mp (and_swap p q) h\n\n-- using anonymous constructors for structural types `Iff` and `And`\ntheorem and_swap_alt : p ∧ q ↔ q ∧ p :=\n  ⟨ fun h => ⟨h.right, h.left⟩, fun h => ⟨h.right, h.left⟩ ⟩\n\nexample (h : p ∧ q) : q ∧ p := (and_swap p q).mp h\n#check Iff.mp  -- Iff.mp {a b : Prop} (self : a ↔ b) (a✝ : a) : b\n\n/-\n - Exercises: https://leanprover.github.io/theorem_proving_in_lean4/propositions_and_proofs.html\n -/\n\n section exercises\n variable (p q r : Prop)\n\n-- commutativity of ∧ and ∨\nexample : p ∧ q ↔ q ∧ p :=\n  Iff.intro\n    (fun (hpq : p ∧ q) => And.intro hpq.right hpq.left)\n    (fun (hqp : q ∧ p) => And.intro hqp.right hqp.left)\nexample : p ∨ q ↔ q ∨ p :=\n  Iff.intro\n    (fun (hpq : p ∨ q) =>\n      Or.elim hpq\n        (fun hp : p => Or.inr hp)\n        (fun hq : q => Or.inl hq))\n    (fun (hqp : q ∨ p) =>\n      Or.elim hqp\n        (fun hq : q => Or.inr hq)\n        (fun hp : p => Or.inl hp))\n\n-- associativity of ∧ and ∨\nexample : (p ∧ q) ∧ r ↔ p ∧ (q ∧ r) :=\n  Iff.intro\n    (fun hpqr =>\n      have hr : r := hpqr.right\n      have hpq : p ∧ q := hpqr.left\n      ⟨hpq.left, hpq.right, hr⟩)\n    (fun hpqr =>\n      have hp : p := hpqr.left\n      have hqr : q ∧ r := hpqr.right\n      ⟨⟨hp, hqr.left⟩, hqr.right⟩)\nexample : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := sorry\n\n-- distributivity\nexample : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) := sorry\nexample : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (p ∨ r) := sorry\n\n-- De Morgan's Law\ntheorem de_morgan_1 : ¬(p ∨ q) ↔ ¬p ∧ ¬q :=\n  Iff.intro\n    (fun hnpoq : (p ∨ q → False) =>\n      have hnp : ¬p := (fun hp: p => hnpoq (Or.inl hp))\n      have hnq : ¬q := (fun hq: q => hnpoq (Or.inr hq))\n      ⟨hnp, hnq⟩)\n    (fun hnpnq : ¬p ∧ ¬q =>\n      -- use partially applied And.left/And.right\n      fun hpoq : p ∨ q => Or.elim hpoq hnpnq.left hnpnq.right)\ntheorem de_morgan_2 : ¬(p ∧ q) ↔ (¬p ∨ ¬q) := sorry\n\n-- other properties\ntheorem pq_imply_r : (p → (q → r)) ↔ (p ∧ q → r) := sorry\n#check @pq_imply_r\ntheorem pq_imply_false : (p → ¬q) ↔ ¬(p ∧ q) := @pq_imply_r p q False\n#check pq_imply_false\n#check Iff.mp\n#check Iff.mp (@pq_imply_false p q)\n-- use pq_imply_false and De Morgan to prove this alternate tautology\nexample : (p → ¬q) ↔ ¬p ∨ ¬q :=\n  Iff.intro\n    (fun lhs : (p → ¬q) =>\n      have hnpq : ¬(p ∧ q) := (Iff.mp (@pq_imply_false p q)) lhs\n      show (¬p ∨ ¬q) from (Iff.mp (@de_morgan_2 p q) hnpq))\n    (fun rhs : ¬p ∨ ¬q =>\n      have hnpaq : ¬ (p ∧ q) := (Iff.mpr (@de_morgan_2 p q)) rhs\n      fun hp : p =>\n      fun hq : q => hnpaq ⟨hp, hq⟩)\n\n\nexample : ((p ∨ q) → r) ↔ (p → r) ∧ (q → r) := sorry\n\nexample : ¬p ∨ ¬q → ¬(p ∧ q) := sorry\nexample : ¬(p ∧ ¬p) := sorry\nexample : p ∧ ¬q → ¬(p → q) := sorry\nexample : ¬p → (p → q) := sorry\nexample : (¬p ∨ q) → (p → q) := sorry\nexample : p ∨ False ↔ p := sorry\nexample : p ∧ False ↔ False := sorry\nexample : (p → q) → (¬q → ¬p) := sorry\n\nend exercises", "meta": {"author": "benjaminfjones", "repo": "theorem-proving-lean4", "sha": "e4b5efe11e433bbe2fbe859c40f81785f83f55ef", "save_path": "github-repos/lean/benjaminfjones-theorem-proving-lean4", "path": "github-repos/lean/benjaminfjones-theorem-proving-lean4/theorem-proving-lean4-e4b5efe11e433bbe2fbe859c40f81785f83f55ef/TheoremProvingLean/propositions_and_proofs.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972784807408, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7500528157952098}}
{"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\nopen list set\n\nvariables {α : Type u}\n\n/-- A language is a set of strings over an alphabet. -/\n@[derive [has_mem (list α), has_singleton (list α), has_insert (list α), complete_boolean_algebra]]\ndef language (α) := set (list α)\n\nnamespace language\n\nlocal attribute [reducible] language\n\n/-- Zero language has no elements. -/\ninstance : has_zero (language α) := ⟨(∅ : set _)⟩\n/-- `1 : language α` contains only one element `[]`. -/\ninstance : has_one (language α) := ⟨{[]}⟩\n\ninstance : inhabited (language α) := ⟨0⟩\n\n/-- The sum of two languages is their union. -/\ninstance : has_add (language α) := ⟨set.union⟩\n\n/-- The product of two languages `l` and `m` is the language made of the strings `x ++ y` where\n`x ∈ l` and `y ∈ m`. -/\ninstance : has_mul (language α) := ⟨image2 (++)⟩\n\nlemma zero_def : (0 : language α) = (∅ : set _) := rfl\nlemma one_def : (1 : language α) = {[]} := rfl\n\nlemma add_def (l m : language α) : l + m = l ∪ m := rfl\nlemma mul_def (l m : language α) : l * m = 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 α) : language α :=\n{ x | ∃ S : list (list α), x = S.join ∧ ∀ y ∈ S, y ∈ l}\n\nlemma star_def (l : language α) :\n  l.star = { x | ∃ S : list (list α), x = S.join ∧ ∀ y ∈ S, y ∈ l} := rfl\n\n@[simp] lemma not_mem_zero (x : list α) : x ∉ (0 : language α) := id\nlemma nil_mem_one : [] ∈ (1 : language α) := mem_singleton _\n@[simp] lemma mem_one (x : list α) : x ∈ (1 : language α) ↔ x = [] := iff.rfl\n@[simp] lemma mem_add (l m : language α) (x : list α) : x ∈ l + m ↔ x ∈ l ∨ x ∈ m :=\nby simp [add_def]\nlemma mem_mul (l m : language α) (x : list α) : x ∈ l * m ↔ ∃ a b, a ∈ l ∧ b ∈ m ∧ a ++ b = x :=\nby simp [mul_def]\nlemma mem_star (l : language α) (x : list α) :\n  x ∈ l.star ↔ ∃ S : list (list α), x = S.join ∧ ∀ y ∈ S, y ∈ l :=\niff.rfl\n\ninstance : semiring (language α) :=\n{ add := (+),\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 := (*),\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  left_distrib := λ _ _ _, image2_union_right,\n  right_distrib := λ _ _ _, image2_union_left }\n\n@[simp] lemma add_self (l : language α) : l + l = l := sup_idem\n\nlemma star_def_nonempty (l : language α) :\n  l.star = {x | ∃ S : list (list α), x = S.join ∧ ∀ y ∈ S, y ∈ l ∧ y ≠ []} :=\nbegin\n  ext x,\n  split,\n  { rintro ⟨S, rfl, h⟩,\n    refine ⟨S.filter (λ l, ¬list.empty l), by simp, λ y hy, _⟩,\n    rw [mem_filter, empty_iff_eq_nil] at hy,\n    exact ⟨h y hy.1, hy.2⟩ },\n  { rintro ⟨S, hx, h⟩,\n    exact ⟨S, hx, λ y hy, (h y hy).1⟩ }\nend\n\n\n\nlemma le_mul_congr {l₁ l₂ m₁ m₂ : language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ * l₂ ≤ m₁ * m₂ :=\nbegin\n  intros h₁ h₂ x hx,\n  simp only [mul_def, exists_and_distrib_left, mem_image2, image_prod] at hx ⊢,\n  tauto\nend\n\nlemma le_add_congr {l₁ l₂ m₁ m₂ : language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ + l₂ ≤ m₁ + m₂ := sup_le_sup\n\nlemma mem_supr {ι : Sort v} {l : ι → language α} {x : list α} :\n  x ∈ (⨆ i, l i) ↔ ∃ i, x ∈ l i :=\nmem_Union\n\nlemma supr_mul {ι : Sort v} (l : ι → language α) (m : language α) :\n  (⨆ i, l i) * m = ⨆ i, l i * m :=\nimage2_Union_left _ _ _\n\nlemma mul_supr {ι : Sort v} (l : ι → language α) (m : language α) :\n  m * (⨆ i, l i) = ⨆ i, m * l i :=\nimage2_Union_right _ _ _\n\nlemma supr_add {ι : Sort v} [nonempty ι] (l : ι → language α) (m : language α) :\n  (⨆ i, l i) + m = ⨆ i, l i + m := supr_sup\n\nlemma add_supr {ι : Sort v} [nonempty ι] (l : ι → language α) (m : language α) :\n  m + (⨆ i, l i) = ⨆ i, m + l i := sup_supr\n\nlemma mem_pow {l : language α} {x : list α} {n : ℕ} :\n  x ∈ l ^ n ↔ ∃ S : list (list α), x = S.join ∧ S.length = n ∧ ∀ y ∈ S, y ∈ l :=\nbegin\n  induction n with n ihn generalizing x,\n  { simp only [mem_one, pow_zero, length_eq_zero],\n    split,\n    { rintro rfl, exact ⟨[], rfl, rfl, λ y h, h.elim⟩ },\n    { rintro ⟨_, rfl, rfl, _⟩, refl } },\n  { simp only [pow_succ, mem_mul, ihn],\n    split,\n    { rintro ⟨a, b, ha, ⟨S, rfl, rfl, hS⟩, rfl⟩,\n      exact ⟨a :: S, rfl, rfl, forall_mem_cons.2 ⟨ha, hS⟩⟩ },\n    { rintro ⟨_|⟨a, S⟩, rfl, hn, hS⟩; cases hn,\n      rw forall_mem_cons at hS,\n      exact ⟨a, _, hS.1, ⟨S, rfl, rfl, hS.2⟩, rfl⟩ } }\nend\n\nlemma star_eq_supr_pow (l : language α) : l.star = ⨆ i : ℕ, l ^ i :=\nbegin\n  ext x,\n  simp only [mem_star, mem_supr, mem_pow],\n  split,\n  { rintro ⟨S, rfl, hS⟩, exact ⟨_, S, rfl, rfl, hS⟩ },\n  { rintro ⟨_, S, rfl, rfl, hS⟩, exact ⟨S, rfl, hS⟩ }\nend\n\nlemma mul_self_star_comm (l : language α) : l.star * l = l * l.star :=\nby simp only [star_eq_supr_pow, mul_supr, supr_mul, ← pow_succ, ← pow_succ']\n\n@[simp] lemma one_add_self_mul_star_eq_star (l : language α) : 1 + l * l.star = l.star :=\nbegin\n  simp only [star_eq_supr_pow, mul_supr, ← pow_succ, ← pow_zero l],\n  exact sup_supr_nat_succ _\nend\n\n@[simp] lemma one_add_star_mul_self_eq_star (l : language α) : 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 α) : l * m ≤ m → l.star * m ≤ 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_rfl h) ih,\nend\n\nlemma star_mul_le_left_of_mul_le_left (l m : language α) : m * l ≤ m → m * l.star ≤ 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, ←mul_assoc m l (l^n)],\n  exact le_trans (le_mul_congr h le_rfl) ih\nend\n\nend language\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/computability/language.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7500382599188445}}
{"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-/\nimport algebra.regular.smul\nimport linear_algebra.matrix.adjugate\nimport linear_algebra.matrix.polynomial\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⁻¹` (`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⁻¹` (`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* `⅟A` (`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 `⁻¹` 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 `⅟A` and `ring.inverse A`.\nThe rest of the results in the file are then about `A⁻¹`\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\nnamespace matrix\nuniverses u v\nvariables {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α]\nopen_locale matrix big_operators\nopen equiv equiv.perm finset\n\nvariables (A : matrix n n α) (B : matrix n n α)\n\n/-! ### Matrices are `invertible` iff their determinants are -/\n\nsection invertible\n\n/-- A copy of `inv_of_mul_self` using `⬝` not `*`. -/\nprotected lemma inv_of_mul_self [invertible A] : ⅟A ⬝ A = 1 := inv_of_mul_self A\n\n/-- A copy of `mul_inv_of_self` using `⬝` not `*`. -/\nprotected lemma mul_inv_of_self [invertible A] : A ⬝ ⅟A = 1 := mul_inv_of_self A\n\n/-- If `A.det` has a constructive inverse, produce one for `A`. -/\ndef invertible_of_det_invertible [invertible A.det] : invertible A :=\n{ inv_of := ⅟A.det • A.adjugate,\n  mul_inv_of_self :=\n    by rw [mul_smul_comm, matrix.mul_eq_mul, mul_adjugate, smul_smul, inv_of_mul_self, one_smul],\n  inv_of_mul_self :=\n    by rw [smul_mul_assoc, matrix.mul_eq_mul, adjugate_mul, smul_smul, inv_of_mul_self, one_smul] }\n\nlemma inv_of_eq [invertible A.det] [invertible A] : ⅟A = ⅟A.det • A.adjugate :=\nby { letI := invertible_of_det_invertible A, convert (rfl : ⅟A = _) }\n\n/-- `A.det` is invertible if `A` has a left inverse. -/\ndef det_invertible_of_left_inverse (h : B ⬝ A = 1) : invertible A.det :=\n{ inv_of := B.det,\n  mul_inv_of_self := by rw [mul_comm, ← det_mul, h, det_one],\n  inv_of_mul_self := by rw [← det_mul, h, det_one] }\n\n/-- `A.det` is invertible if `A` has a right inverse. -/\ndef det_invertible_of_right_inverse (h : A ⬝ B = 1) : invertible A.det :=\n{ inv_of := B.det,\n  mul_inv_of_self := by rw [← det_mul, h, det_one],\n  inv_of_mul_self := by rw [mul_comm, ← det_mul, h, det_one] }\n\n/-- If `A` has a constructive inverse, produce one for `A.det`. -/\ndef det_invertible_of_invertible [invertible A] : invertible A.det :=\ndet_invertible_of_left_inverse A (⅟A) (inv_of_mul_self _)\n\nlemma det_inv_of [invertible A] [invertible A.det] : (⅟A).det = ⅟A.det :=\nby { letI := det_invertible_of_invertible A, convert (rfl : _ = ⅟A.det) }\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 invertible_equiv_det_invertible : invertible A ≃ invertible A.det :=\n{ to_fun := @det_invertible_of_invertible _ _ _ _ _ A,\n  inv_fun := @invertible_of_det_invertible _ _ _ _ _ A,\n  left_inv := λ _, subsingleton.elim _ _,\n  right_inv := λ _, subsingleton.elim _ _ }\n\nvariables {A B}\n\nlemma mul_eq_one_comm : A ⬝ B = 1 ↔ B ⬝ A = 1 :=\nsuffices ∀ A B, A ⬝ B = 1 → B ⬝ A = 1, from ⟨this A B, this B A⟩, assume A B h,\nbegin\n  letI : invertible B.det := det_invertible_of_left_inverse _ _ h,\n  letI : invertible B := invertible_of_det_invertible B,\n  calc B ⬝ A = (B ⬝ A) ⬝ (B ⬝ ⅟B) : by rw [matrix.mul_inv_of_self, matrix.mul_one]\n        ... = B ⬝ ((A ⬝ B) ⬝ ⅟B) : by simp only [matrix.mul_assoc]\n        ... = B ⬝ ⅟B : by rw [h, matrix.one_mul]\n        ... = 1 : matrix.mul_inv_of_self B,\nend\n\nvariables (A B)\n\n/-- We can construct an instance of invertible A if A has a left inverse. -/\ndef invertible_of_left_inverse (h : B ⬝ A = 1) : invertible A :=\n⟨B, h, mul_eq_one_comm.mp h⟩\n\n/-- We can construct an instance of invertible A if A has a right inverse. -/\ndef invertible_of_right_inverse (h : A ⬝ B = 1) : invertible A :=\n⟨B, mul_eq_one_comm.mp h, h⟩\n\n/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `units (matrix n n α)`-/\ndef unit_of_det_invertible [invertible A.det] : units (matrix n n α) :=\n@unit_of_invertible _ _ A (invertible_of_det_invertible A)\n\n/-- When lowered to a prop, `matrix.invertible_equiv_det_invertible` forms an `iff`. -/\nlemma is_unit_iff_is_unit_det : is_unit A ↔ is_unit A.det :=\nbegin\n  split; rintros ⟨x, hx⟩; refine @is_unit_of_invertible _ _ _ (id _),\n  { haveI : invertible A := hx.rec x.invertible,\n    apply det_invertible_of_invertible, },\n  { haveI : invertible A.det := hx.rec x.invertible,\n    apply invertible_of_det_invertible, },\nend\n\n/-! #### Variants of the statements above with `is_unit`-/\n\nlemma is_unit_det_of_invertible [invertible A] : is_unit A.det :=\n@is_unit_of_invertible _ _ _ (det_invertible_of_invertible A)\n\nvariables {A B}\n\nlemma is_unit_det_of_left_inverse (h : B ⬝ A = 1) : is_unit A.det :=\n@is_unit_of_invertible _ _ _ (det_invertible_of_left_inverse _ _ h)\n\nlemma is_unit_det_of_right_inverse (h : A ⬝ B = 1) : is_unit A.det :=\n@is_unit_of_invertible _ _ _ (det_invertible_of_right_inverse _ _ h)\n\nlemma det_ne_zero_of_left_inverse [nontrivial α] (h : B ⬝ A = 1) : A.det ≠ 0 :=\n(is_unit_det_of_left_inverse h).ne_zero\n\nlemma det_ne_zero_of_right_inverse [nontrivial α] (h : A ⬝ B = 1) : A.det ≠ 0 :=\n(is_unit_det_of_right_inverse h).ne_zero\n\nend invertible\n\nopen_locale classical\n\nlemma is_unit_det_transpose (h : is_unit A.det) : is_unit Aᵀ.det :=\nby { rw det_transpose, exact h, }\n\n/-! ### A noncomputable `has_inv` instance  -/\n\n/-- The inverse of a square matrix, when it is invertible (and zero otherwise).-/\nnoncomputable instance : has_inv (matrix n n α) := ⟨λ A, ring.inverse A.det • A.adjugate⟩\n\nlemma inv_def (A : matrix n n α) : A⁻¹ = ring.inverse A.det • A.adjugate := rfl\n\nlemma nonsing_inv_apply_not_is_unit (h : ¬ is_unit A.det) :\n  A⁻¹ = 0 :=\nby rw [inv_def, ring.inverse_non_unit _ h, zero_smul]\n\nlemma nonsing_inv_apply (h : is_unit A.det) :\n  A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate :=\nby rw [inv_def, ←ring.inverse_unit h.unit, is_unit.unit_spec]\n\n/-- The nonsingular inverse is the same as `inv_of` when `A` is invertible. -/\n@[simp] lemma inv_of_eq_nonsing_inv [invertible A] : ⅟A = A⁻¹ :=\nbegin\n  letI := det_invertible_of_invertible A,\n  rw [inv_def, ring.inverse_invertible, inv_of_eq],\nend\n\n/-- The nonsingular inverse is the same as the general `ring.inverse`. -/\nlemma nonsing_inv_eq_ring_inverse : A⁻¹ = ring.inverse A :=\nbegin\n  by_cases h_det : is_unit A.det,\n  { casesI (A.is_unit_iff_is_unit_det.mpr h_det).nonempty_invertible,\n    rw [←inv_of_eq_nonsing_inv, ring.inverse_invertible], },\n  { 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], },\nend\n\nlemma transpose_nonsing_inv : (A⁻¹)ᵀ = (Aᵀ)⁻¹ :=\nby rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]\n\nlemma conj_transpose_nonsing_inv [star_ring α] : (A⁻¹)ᴴ = (Aᴴ)⁻¹ :=\nby rw [inv_def, inv_def, conj_transpose_smul, det_conj_transpose, adjugate_conj_transpose,\n       ring.inverse_star]\n\n/-- The `nonsing_inv` of `A` is a right inverse. -/\n@[simp] lemma mul_nonsing_inv (h : is_unit A.det) : A ⬝ A⁻¹ = 1 :=\nbegin\n  casesI (A.is_unit_iff_is_unit_det.mpr h).nonempty_invertible,\n  rw [←inv_of_eq_nonsing_inv, matrix.mul_inv_of_self],\nend\n\n/-- The `nonsing_inv` of `A` is a left inverse. -/\n@[simp] lemma nonsing_inv_mul (h : is_unit A.det) : A⁻¹ ⬝ A = 1 :=\nbegin\n  casesI (A.is_unit_iff_is_unit_det.mpr h).nonempty_invertible,\n  rw [←inv_of_eq_nonsing_inv, matrix.inv_of_mul_self],\nend\n\n@[simp] lemma mul_inv_of_invertible [invertible A] : A ⬝ A⁻¹ = 1 :=\nmul_nonsing_inv A (is_unit_det_of_invertible A)\n\n@[simp] lemma inv_mul_of_invertible [invertible A] : A⁻¹ ⬝ A = 1 :=\nnonsing_inv_mul A (is_unit_det_of_invertible A)\n\nlemma nonsing_inv_cancel_or_zero :\n  (A⁻¹ ⬝ A = 1 ∧ A ⬝ A⁻¹ = 1) ∨ A⁻¹ = 0 :=\nbegin\n  by_cases h : is_unit A.det,\n  { exact or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩ },\n  { exact or.inr (nonsing_inv_apply_not_is_unit _ h) }\nend\n\nlemma det_nonsing_inv_mul_det (h : is_unit A.det) : A⁻¹.det * A.det = 1 :=\nby rw [←det_mul, A.nonsing_inv_mul h, det_one]\n\n@[simp] lemma det_nonsing_inv : A⁻¹.det = ring.inverse A.det :=\nbegin\n  by_cases h : is_unit A.det,\n  { casesI h.nonempty_invertible, letI := invertible_of_det_invertible A,\n    rw [ring.inverse_invertible, ←inv_of_eq_nonsing_inv, det_inv_of] },\n  casesI is_empty_or_nonempty n,\n  { rw [det_is_empty, det_is_empty, ring.inverse_one] },\n  { rw [ring.inverse_non_unit _ h, nonsing_inv_apply_not_is_unit _ h, det_zero ‹_›] },\nend\n\nlemma is_unit_nonsing_inv_det (h : is_unit A.det) : is_unit A⁻¹.det :=\nis_unit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)\n\n@[simp] lemma nonsing_inv_nonsing_inv (h : is_unit A.det) : (A⁻¹)⁻¹ = A :=\ncalc (A⁻¹)⁻¹ = 1 ⬝ (A⁻¹)⁻¹        : by rw matrix.one_mul\n         ... = A ⬝ A⁻¹ ⬝ (A⁻¹)⁻¹  : by rw A.mul_nonsing_inv h\n         ... = A                  : by { rw [matrix.mul_assoc,\n                                         (A⁻¹).mul_nonsing_inv (A.is_unit_nonsing_inv_det h),\n                                         matrix.mul_one], }\n\nlemma is_unit_nonsing_inv_det_iff {A : matrix n n α} :\n  is_unit A⁻¹.det ↔ is_unit A.det :=\nby rw [matrix.det_nonsing_inv, is_unit_ring_inverse]\n\n/- `is_unit.invertible` lifts the proposition `is_unit A` to a constructive inverse of `A`. -/\n\n/-- A version of `matrix.invertible_of_det_invertible` with the inverse defeq to `A⁻¹` that is\ntherefore noncomputable. -/\nnoncomputable def invertible_of_is_unit_det (h : is_unit A.det) : invertible A :=\n⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩\n\n/-- A version of `matrix.units_of_det_invertible` with the inverse defeq to `A⁻¹` that is therefore\nnoncomputable. -/\nnoncomputable def nonsing_inv_unit (h : is_unit A.det) : units (matrix n n α) :=\n@unit_of_invertible _ _ _ (invertible_of_is_unit_det A h)\n\nlemma unit_of_det_invertible_eq_nonsing_inv_unit [invertible A.det] :\n  unit_of_det_invertible A = nonsing_inv_unit A (is_unit_of_invertible _) :=\nby { ext, refl }\n\nvariables {A} {B}\n\n/-- If matrix A is left invertible, then its inverse equals its left inverse. -/\nlemma inv_eq_left_inv (h : B ⬝ A = 1) : A⁻¹ = B :=\nbegin\n  letI := invertible_of_left_inverse _ _ h,\n  exact inv_of_eq_nonsing_inv A ▸ inv_of_eq_left_inv h,\nend\n\n/-- If matrix A is right invertible, then its inverse equals its right inverse. -/\nlemma inv_eq_right_inv (h : A ⬝ B = 1) : A⁻¹ = B :=\ninv_eq_left_inv (mul_eq_one_comm.2 h)\n\nsection inv_eq_inv\n\nvariables {C : matrix n n α}\n\n/-- The left inverse of matrix A is unique when existing. -/\n\n\n/-- The right inverse of matrix A is unique when existing. -/\nlemma right_inv_eq_right_inv (h : A ⬝ B = 1) (g : A ⬝ C = 1) : B = C :=\nby rw [←inv_eq_right_inv h, ←inv_eq_right_inv g]\n\n/-- The right inverse of matrix A equals the left inverse of A when they exist. -/\nlemma right_inv_eq_left_inv (h : A ⬝ B = 1) (g : C ⬝ A = 1) : B = C :=\nby rw [←inv_eq_right_inv h, ←inv_eq_left_inv g]\n\nlemma inv_inj (h : A⁻¹ = B⁻¹) (h' : is_unit A.det) : A = B :=\nbegin\n  refine left_inv_eq_left_inv (mul_nonsing_inv _ h') _,\n  rw h,\n  refine mul_nonsing_inv _ _,\n  rwa [←is_unit_nonsing_inv_det_iff, ←h, is_unit_nonsing_inv_det_iff]\nend\n\nend inv_eq_inv\n\nvariable (A)\n\n@[simp] lemma inv_zero : (0 : matrix n n α)⁻¹ = 0 :=\nbegin\n  casesI (subsingleton_or_nontrivial α) with ht ht,\n  { simp },\n  cases (fintype.card n).zero_le.eq_or_lt with hc hc,\n  { rw [eq_comm, fintype.card_eq_zero_iff] at hc,\n    haveI := hc,\n    ext i,\n    exact (is_empty.false i).elim },\n  { have hn : nonempty n := fintype.card_pos_iff.mp hc,\n    refine nonsing_inv_apply_not_is_unit _ _,\n    simp [hn] },\nend\n\n@[simp] lemma inv_one : (1 : matrix n n α)⁻¹ = 1 :=\ninv_eq_left_inv (by simp)\n\nlemma inv_smul (k : α) [invertible k] (h : is_unit A.det) : (k • A)⁻¹ = ⅟k • A⁻¹ :=\ninv_eq_left_inv (by simp [h, smul_smul])\n\nlemma inv_smul' (k : units α) (h : is_unit A.det) : (k • A)⁻¹ = k⁻¹ • A⁻¹ :=\ninv_eq_left_inv (by simp [h, smul_smul])\n\nlemma inv_adjugate (A : matrix n n α) (h : is_unit A.det) :\n  (adjugate A)⁻¹ = h.unit⁻¹ • A :=\nbegin\n  refine inv_eq_left_inv _,\n  rw [smul_mul, mul_adjugate, units.smul_def, smul_smul, h.coe_inv_mul, one_smul]\nend\n\n@[simp] lemma inv_inv_inv (A : matrix n n α) : A⁻¹⁻¹⁻¹ = A⁻¹ :=\nbegin\n  by_cases h : is_unit A.det,\n  { rw [nonsing_inv_nonsing_inv _ h] },\n  { simp [nonsing_inv_apply_not_is_unit _ h] }\nend\n\nlemma mul_inv_rev (A B : matrix n n α) : (A ⬝ B)⁻¹ = B⁻¹ ⬝ A⁻¹ :=\nbegin\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],\nend\n\n/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/\n@[simp] lemma det_smul_inv_mul_vec_eq_cramer (A : matrix n n α) (b : n → α) (h : is_unit A.det) :\n  A.det • A⁻¹.mul_vec b = cramer A b :=\nbegin\n  rw [cramer_eq_adjugate_mul_vec, A.nonsing_inv_apply h, ← smul_mul_vec_assoc,\n      smul_smul, h.mul_coe_inv, one_smul]\nend\n\n/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/\n@[simp] lemma det_smul_inv_vec_mul_eq_cramer_transpose\n  (A : matrix n n α) (b : n → α) (h : is_unit A.det) :\n  A.det • A⁻¹.vec_mul b = cramer Aᵀ b :=\nby rw [← (A⁻¹).transpose_transpose, vec_mul_transpose, transpose_nonsing_inv, ← det_transpose,\n    Aᵀ.det_smul_inv_mul_vec_eq_cramer _ (is_unit_det_transpose A h)]\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/nonsingular_inverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7500382491807538}}
{"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\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 ≤ 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 : ℕ) : ℕ := ite (i ≤ N) (N-i) i\n\nlemma rev_at_fun_invol {N i : ℕ} : 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 : ℕ} : function.injective (rev_at_fun N) :=\nbegin\n  intros a b hab,\n  rw [← @rev_at_fun_invol N a, hab, rev_at_fun_invol],\nend\n\n/-- If `i ≤ N`, then `rev_at N i` returns `N - i`, otherwise it returns `i`.\nEssentially, this embedding is only used for `i ≤ N`.\nThe advantage of `rev_at N i` over `N - i` is that `rev_at` is an involution.\n-/\ndef rev_at (N : ℕ) : function.embedding ℕ ℕ :=\n{ to_fun := λ i , (ite (i ≤ 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 : ℕ) : rev_at_fun N i = rev_at N i := rfl\n\n@[simp] lemma rev_at_invol {N i : ℕ} : (rev_at N) (rev_at N i) = i :=\nrev_at_fun_invol\n\n@[simp] lemma rev_at_le {N i : ℕ} (H : i ≤ N) : rev_at N i = N - i :=\nif_pos H\n\nlemma rev_at_add {N O n o : ℕ} (hn : n ≤ N) (ho : o ≤ O) :\n  rev_at (N + O) (n + o) = rev_at N n + rev_at O o :=\nbegin\n  rcases nat.le.dest hn with ⟨n', rfl⟩,\n  rcases nat.le.dest ho with ⟨o', rfl⟩,\n  repeat { rw rev_at_le (le_add_right rfl.le) },\n  rw [add_assoc, add_left_comm n' o, ← 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 : ℕ) : 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 : ℕ) : R[X] → R[X]\n| ⟨f⟩ := ⟨finsupp.emb_domain (rev_at N) f⟩\n\nlemma reflect_support (N : ℕ) (f : R[X]) :\n  (reflect N f).support = image (rev_at N) f.support :=\nbegin\n  rcases f,\n  ext1,\n  rw [reflect, mem_image, support, support, support_emb_domain, mem_map],\nend\n\n@[simp] lemma coeff_reflect (N : ℕ) (f : R[X]) (i : ℕ) :\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 : ℕ} : reflect N (0 : R[X]) = 0 := rfl\n\n@[simp] lemma reflect_eq_zero_iff {N : ℕ} {f : R[X]} :\n  reflect N (f : R[X]) = 0 ↔ f = 0 :=\nby { rcases f, simp [reflect] }\n\n@[simp] lemma reflect_add (f g : R[X]) (N : ℕ) :\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 : ℕ) :\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 : ℕ) {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 [← one_mul (X ^ n), ← C_1] at a,\n    apply h,\n    rw [← (mem_support_C_mul_X_pow a), rev_at_invol], },\nend\n\n@[simp] lemma reflect_C (r : R) (N : ℕ) : reflect N (C r) = C r * X ^ N :=\nby conv_lhs { rw [← mul_one (C r), ← pow_zero X, reflect_C_mul_X_pow, rev_at_zero] }\n\n@[simp] lemma reflect_monomial (N n : ℕ) : reflect N ((X : R[X]) ^ n) = X ^ (rev_at N n) :=\nby rw [← one_mul (X ^ n), ← one_mul (X ^ (rev_at N n)), ← C_1, reflect_C_mul_X_pow]\n\nlemma reflect_mul_induction (cf cg : ℕ) :\n  ∀ N O : ℕ, ∀ f g : R[X],\n  f.support.card ≤ cf.succ → g.support.card ≤ cg.succ → f.nat_degree ≤ N → g.nat_degree ≤ O →\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 [← C_mul_X_pow_eq_self Cf, ← C_mul_X_pow_eq_self Cg],\n      simp_rw [mul_assoc, X_pow_mul, mul_assoc, ← 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        ← 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 [← 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 [← 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 : ℕ} (Ff : f.nat_degree ≤ F) (Gg : g.nat_degree ≤ 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₂\n\nvariables {S : Type*} [comm_semiring S]\n\nlemma eval₂_reflect_mul_pow (i : R →+* S) (x : S) [invertible x] (N : ℕ) (f : R[X])\n  (hf : f.nat_degree ≤ N) : eval₂ i (⅟x) (reflect N f) * x ^ N = eval₂ i x f :=\nbegin\n  refine induction_with_nat_degree_le (λ f, eval₂ i (⅟x) (reflect N f) * x ^ N = eval₂ 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₂_X_pow, eval₂_C, eval₂_mul],\n    conv in (x ^ N) { rw [← nat.sub_add_cancel hnN] },\n    rw [pow_add, ← mul_assoc, mul_assoc (i r), ← mul_pow, inv_of_mul_self, one_pow, mul_one] },\n  { intros,\n    simp [*, add_mul] }\nend\n\nlemma eval₂_reflect_eq_zero_iff (i : R →+* S) (x : S) [invertible x] (N : ℕ) (f : R[X])\n  (hf : f.nat_degree ≤ N) : eval₂ i (⅟x) (reflect N f) = 0 ↔ eval₂ i x f = 0 :=\nbegin\n  conv_rhs { rw [← eval₂_reflect_mul_pow i x N f hf] },\n  split,\n  { intro h, rw [h, zero_mul] },\n  { intro h, rw [← mul_one (eval₂ i (⅟x) _), ← one_pow N, ← mul_inv_of_self x,\n      mul_pow, ← mul_assoc, h, zero_mul] }\nend\n\nend eval₂\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 : ℕ) :\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 ↔ f = 0 :=\nby simp [reverse]\n\nlemma reverse_nat_degree_le (f : R[X]) : f.reverse.nat_degree ≤ 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, ←rev_at_le f.nat_trailing_degree_le_nat_degree, rev_at_invol],\n    exact trailing_coeff_nonzero_iff_nonzero.mpr hf },\n  { rw ← 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, ←rev_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 ← 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 : R[X]} (fg : f.leading_coeff * g.leading_coeff ≠ 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] [is_domain 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] [is_domain R] (p q : R[X]) :\n  (p * q).trailing_coeff = p.trailing_coeff * q.trailing_coeff :=\nby rw [←reverse_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₂\nvariables {S : Type*} [comm_semiring S]\n\nlemma eval₂_reverse_mul_pow (i : R →+* S) (x : S) [invertible x] (f : R[X]) :\n  eval₂ i (⅟x) (reverse f) * x ^ f.nat_degree = eval₂ i x f :=\neval₂_reflect_mul_pow i _ _ f le_rfl\n\n@[simp] lemma eval₂_reverse_eq_zero_iff (i : R →+* S) (x : S) [invertible x] (f : R[X]) :\n  eval₂ i (⅟x) (reverse f) = 0 ↔ eval₂ i x f = 0 :=\neval₂_reflect_eq_zero_iff i x _ _ le_rfl\n\nend eval₂\n\nend semiring\n\nsection ring\n\nvariables {R : Type*} [ring R]\n\n@[simp] lemma reflect_neg (f : R[X]) (N : ℕ) :\n  reflect N (- f) = - reflect N f :=\nby rw [neg_eq_neg_one_mul, ←C_1, ←C_neg, reflect_C_mul, C_neg, C_1, ←neg_eq_neg_one_mul]\n\n@[simp] lemma reflect_sub (f g : R[X]) (N : ℕ) :\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": "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/reverse.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7500191934415301}}
{"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.data.polynomial.degree.definitions\nimport Mathlib.PostPort\n\nuniverses u_1 \n\nnamespace Mathlib\n\n/-!\n# Cancel the leading terms of two polynomials\n\n## Definition\n\n* `cancel_leads p q`: the polynomial formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting.\n\n## Main Results\nThe degree of `cancel_leads` is less than that of the larger of the two polynomials being cancelled.\nThus it is useful for induction or minimal-degree arguments.\n-/\n\nnamespace polynomial\n\n\n/-- `cancel_leads p q` is formed by multiplying `p` and `q` by monomials so that they\n  have the same leading term, and then subtracting. -/\ndef cancel_leads {R : Type u_1} [comm_ring R] (p : polynomial R) (q : polynomial R) : polynomial R :=\n  coe_fn C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q -\n    coe_fn C (leading_coeff q) * X ^ (nat_degree q - nat_degree p) * p\n\n@[simp] theorem neg_cancel_leads {R : Type u_1} [comm_ring R] {p : polynomial R} {q : polynomial R} : -cancel_leads p q = cancel_leads q p :=\n  neg_sub (coe_fn C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q)\n    (coe_fn C (leading_coeff q) * X ^ (nat_degree q - nat_degree p) * p)\n\ntheorem dvd_cancel_leads_of_dvd_of_dvd {R : Type u_1} [comm_ring R] {p : polynomial R} {q : polynomial R} {r : polynomial R} (pq : p ∣ q) (pr : p ∣ r) : p ∣ cancel_leads q r :=\n  dvd_sub (dvd.trans pr (dvd.intro_left (coe_fn C (leading_coeff q) * X ^ (nat_degree q - nat_degree r)) rfl))\n    (dvd.trans pq (dvd.intro_left (coe_fn C (leading_coeff r) * X ^ (nat_degree r - nat_degree q)) rfl))\n\ntheorem nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree {R : Type u_1} [integral_domain R] {p : polynomial R} {q : polynomial R} (h : nat_degree p ≤ nat_degree q) (hq : 0 < nat_degree q) : nat_degree (cancel_leads p q) < nat_degree 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/polynomial/cancel_leads.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7500096507150967}}
{"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\n! This file was ported from Lean 3 source module algebra.linear_recurrence\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 Mathbin.Data.Polynomial.Eval\nimport Mathbin.LinearAlgebra.Dimension\n\n/-!\n# Linear recurrence\n\nInformally, a \"linear recurrence\" is an assertion of the form\n`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,\nwhere `u` is a sequence, `d` is the *order* of the recurrence and the `a i`\nare its *coefficients*.\n\nIn this file, we define the structure `linear_recurrence` so that\n`linear_recurrence.mk d a` represents the above relation, and we call\na sequence `u` which verifies it a *solution* of the linear recurrence.\n\nWe prove a few basic lemmas about this concept, such as :\n\n* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`\n  is a field)\n* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`\n  between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two\n  solutions are equal if and only if their first `d` terms are equals.\n* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,\n  which we call the *characteristic polynomial* of the recurrence\n\nOf course, although we can inductively generate solutions (cf `mk_sol`), the\ninteresting part would be to determinate closed-forms for the solutions.\nThis is currently *not implemented*, as we are waiting for definition and\nproperties of eigenvalues and eigenvectors.\n\n-/\n\n\nnoncomputable section\n\nopen Finset\n\nopen BigOperators Polynomial\n\n/-- A \"linear recurrence relation\" over a commutative semiring is given by its\n  order `n` and `n` coefficients. -/\nstructure LinearRecurrence (α : Type _) [CommSemiring α] where\n  order : ℕ\n  coeffs : Fin order → α\n#align linear_recurrence LinearRecurrence\n\ninstance (α : Type _) [CommSemiring α] : Inhabited (LinearRecurrence α) :=\n  ⟨⟨0, default⟩⟩\n\nnamespace LinearRecurrence\n\nsection CommSemiring\n\nvariable {α : Type _} [CommSemiring α] (E : LinearRecurrence α)\n\n/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have\n  `u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/\ndef IsSolution (u : ℕ → α) :=\n  ∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)\n#align linear_recurrence.is_solution LinearRecurrence.IsSolution\n\n/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.\n  We will prove this is the only such solution. -/\ndef mkSol (init : Fin E.order → α) : ℕ → α\n  | n =>\n    if h : n < E.order then init ⟨n, h⟩\n    else\n      ∑ k : Fin E.order,\n        have : n - E.order + k < n :=\n          by\n          rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h), tsub_lt_iff_left]\n          · exact add_lt_add_right k.is_lt n\n          · convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h)\n            simp only [zero_add]\n        E.coeffs k * mk_sol (n - E.order + k)\n#align linear_recurrence.mk_sol LinearRecurrence.mkSol\n\n/-- `E.mk_sol` indeed gives solutions to `E`. -/\ntheorem is_sol_mkSol (init : Fin E.order → α) : E.IsSolution (E.mkSol init) := fun n => by\n  rw [mk_sol] <;> simp\n#align linear_recurrence.is_sol_mk_sol LinearRecurrence.is_sol_mkSol\n\n/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/\ntheorem mkSol_eq_init (init : Fin E.order → α) : ∀ n : Fin E.order, E.mkSol init n = init n :=\n  fun n => by\n  rw [mk_sol]\n  simp only [n.is_lt, dif_pos, Fin.mk_val, Fin.eta]\n#align linear_recurrence.mk_sol_eq_init LinearRecurrence.mkSol_eq_init\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `∀ n, u n = E.mk_sol init n`. -/\ntheorem eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : Fin E.order → α} (h : E.IsSolution u)\n    (heq : ∀ n : Fin E.order, u n = init n) : ∀ n, u n = E.mkSol init n\n  | n =>\n    if h' : n < E.order then by\n      rw [mk_sol] <;> simp only [h', dif_pos] <;> exact_mod_cast HEq ⟨n, h'⟩\n    else by\n      rw [mk_sol, ← tsub_add_cancel_of_le (le_of_not_lt h'), h (n - E.order)]\n      simp [h']\n      congr with k\n      exact\n        by\n        have wf : n - E.order + k < n :=\n          by\n          rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h'), tsub_lt_iff_left]\n          · exact add_lt_add_right k.is_lt n\n          · convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h')\n            simp only [zero_add]\n        rw [eq_mk_of_is_sol_of_eq_init]\n#align linear_recurrence.eq_mk_of_is_sol_of_eq_init LinearRecurrence.eq_mk_of_is_sol_of_eq_init\n\n/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,\n  then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution\n  of `E` whose first `E.order` values are given by `init`. -/\ntheorem eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : Fin E.order → α} (h : E.IsSolution u)\n    (heq : ∀ n : Fin E.order, u n = init n) : u = E.mkSol init :=\n  funext (E.eq_mk_of_is_sol_of_eq_init h HEq)\n#align linear_recurrence.eq_mk_of_is_sol_of_eq_init' LinearRecurrence.eq_mk_of_is_sol_of_eq_init'\n\n/-- The space of solutions of `E`, as a `submodule` over `α` of the module `ℕ → α`. -/\ndef solSpace : Submodule α (ℕ → α)\n    where\n  carrier := { u | E.IsSolution u }\n  zero_mem' n := by simp\n  add_mem' u v hu hv n := by simp [mul_add, sum_add_distrib, hu n, hv n]\n  smul_mem' a u hu n := by simp [hu n, mul_sum] <;> congr <;> ext <;> ac_rfl\n#align linear_recurrence.sol_space LinearRecurrence.solSpace\n\n/-- Defining property of the solution space : `u` is a solution\n  iff it belongs to the solution space. -/\ntheorem is_sol_iff_mem_solSpace (u : ℕ → α) : E.IsSolution u ↔ u ∈ E.solSpace :=\n  Iff.rfl\n#align linear_recurrence.is_sol_iff_mem_sol_space LinearRecurrence.is_sol_iff_mem_solSpace\n\n/-- The function that maps a solution `u` of `E` to its first\n  `E.order` terms as a `linear_equiv`. -/\ndef toInit : E.solSpace ≃ₗ[α] Fin E.order → α\n    where\n  toFun u x := (u : ℕ → α) x\n  map_add' u v := by\n    ext\n    simp\n  map_smul' a u := by\n    ext\n    simp\n  invFun u := ⟨E.mkSol u, E.is_sol_mkSol u⟩\n  left_inv u := by ext n <;> symm <;> apply E.eq_mk_of_is_sol_of_eq_init u.2 <;> intro k <;> rfl\n  right_inv u := Function.funext_iff.mpr fun n => E.mkSol_eq_init u n\n#align linear_recurrence.to_init LinearRecurrence.toInit\n\n/-- Two solutions are equal iff they are equal on `range E.order`. -/\ntheorem sol_eq_of_eq_init (u v : ℕ → α) (hu : E.IsSolution u) (hv : E.IsSolution v) :\n    u = v ↔ Set.EqOn u v ↑(range E.order) :=\n  by\n  refine' Iff.intro (fun h x hx => h ▸ rfl) _\n  intro h\n  set u' : ↥E.sol_space := ⟨u, hu⟩\n  set v' : ↥E.sol_space := ⟨v, hv⟩\n  change u'.val = v'.val\n  suffices h' : u' = v'; exact h' ▸ rfl\n  rw [← E.to_init.to_equiv.apply_eq_iff_eq, LinearEquiv.coe_toEquiv]\n  ext x\n  exact_mod_cast h (mem_range.mpr x.2)\n#align linear_recurrence.sol_eq_of_eq_init LinearRecurrence.sol_eq_of_eq_init\n\n/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. This operation is quite useful for determining closed-form\n  solutions of `E`. -/\n\n\n/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,\n  where `n := E.order`. -/\ndef tupleSucc : (Fin E.order → α) →ₗ[α] Fin E.order → α\n    where\n  toFun X i := if h : (i : ℕ) + 1 < E.order then X ⟨i + 1, h⟩ else ∑ i, E.coeffs i * X i\n  map_add' x y := by\n    ext i\n    split_ifs <;> simp [h, mul_add, sum_add_distrib]\n  map_smul' x y := by\n    ext i\n    split_ifs <;> simp [h, mul_sum]\n    exact sum_congr rfl fun x _ => by ac_rfl\n#align linear_recurrence.tuple_succ LinearRecurrence.tupleSucc\n\nend CommSemiring\n\nsection Field\n\nvariable {α : Type _} [Field α] (E : LinearRecurrence α)\n\n/-- The dimension of `E.sol_space` is `E.order`. -/\ntheorem solSpace_dim : Module.rank α E.solSpace = E.order :=\n  @dim_fin_fun α _ E.order ▸ E.toInit.dim_eq\n#align linear_recurrence.sol_space_dim LinearRecurrence.solSpace_dim\n\nend Field\n\nsection CommRing\n\nvariable {α : Type _} [CommRing α] (E : LinearRecurrence α)\n\n/-- The characteristic polynomial of `E` is\n`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/\ndef charPoly : α[X] :=\n  Polynomial.monomial E.order 1 - ∑ i : Fin E.order, Polynomial.monomial i (E.coeffs i)\n#align linear_recurrence.char_poly LinearRecurrence.charPoly\n\n/-- The geometric sequence `q^n` is a solution of `E` iff\n  `q` is a root of `E`'s characteristic polynomial. -/\ntheorem geom_sol_iff_root_charPoly (q : α) : (E.IsSolution fun n => q ^ n) ↔ E.charPoly.IsRoot q :=\n  by\n  rw [char_poly, Polynomial.IsRoot.def, Polynomial.eval]\n  simp only [Polynomial.eval₂_finset_sum, one_mul, RingHom.id_apply, Polynomial.eval₂_monomial,\n    Polynomial.eval₂_sub]\n  constructor\n  · intro h\n    simpa [sub_eq_zero] using h 0\n  · intro h n\n    simp only [pow_add, sub_eq_zero.mp h, mul_sum]\n    exact sum_congr rfl fun _ _ => by ring\n#align linear_recurrence.geom_sol_iff_root_char_poly LinearRecurrence.geom_sol_iff_root_charPoly\n\nend CommRing\n\nend LinearRecurrence\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/LinearRecurrence.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7500096502670174}}
{"text": "import tactic\n\n/-!\n\n# The entourage definition of a uniform space\n\nWe start with a little section on `U ∘ V` (see axiom 4 of the wikipedia\nentourage definition of a uniform space)\n\nWe then give the entourage definition of a uniform space\n\n-/\n\n-- We first define U ∘ V. First the function itself (called `comp_ent`)\n\n/-- composition `∘` of two subsets of X × X -/\ndef comp_ent {X : Type} (U V : set (X×X)) :=\n  {p : X × X | ∃z : X, (p.1, z) ∈ U ∧ (z, p.2) ∈ V}\n\n-- and now the notation\nnotation U ` ∘ ` V := comp_ent U V\n\nvariables {X : Type} {U V : set (X × X)} {x y : X}\n\n/-- This is the theorem which gives the defining property of U ∘ V -/\n@[simp] theorem mem_comp_ent :\n  (x, y) ∈ U ∘ V ↔ ∃ z, (x, z) ∈ U ∧ (z, y) ∈ V := iff.rfl -- true by definition\n\nstructure uniform_space_entourage (X : Type) :=\n(entourages : set (set (X × X)))\n-- now go through the five axioms in Wikipedia\n(refl : ∀ U ∈ entourages, ∀ x : X, (x,x) ∈ U)\n(bigger : ∀ U V : set (X × X), U ∈ entourages → U ⊆ V → V ∈ entourages)\n(inter : ∀ U V ∈ entourages, U ∩ V ∈ entourages)\n(comp : ∀ U ∈ entourages, ∃ V ∈ entourages, V ∘ V ⊆ U)\n(symm : ∀ U ∈ entourages, {z : X × X | (z.2, z.1) ∈ U} ∈ entourages)\n\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/entourages.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7500096433605432}}
{"text": "/-*** #check ***-/\n\n/-\nIn Lean, the #check command is part of Lean but not part of\npredicate logic. It takes any expression does two things:\n\n(1) It checks it for syntax errors\n(2) If it's syntactically correct, it tells you its type\n\nLet's look at some examples. Hover over the blue squiggle.\n-/\n\n#check 5    -- 5 is a good expression; it's type is ℕ (natural number)\n#check ℕ    -- ℕ is a data type so *it's& type is Type\n\n\n/-\nThe type of the value 5 is ℕ\nThe type of ℕ is Type\nType is the type of every simple data type in Lean\n-/\n\n\n/-\nLet's look at another example\n-/\n\n#check \"Hi\"   -- \"Hi\" is a value true of the string data type\n#check string -- string is a data type so it's type is also Type\n\n\n/-\nThe type of 5 is ℕ (5 : ℕ) and the type of ℕ is type (ℕ : Type)\nThe type of \"Hi\" is string (\"Hi\" : string\") and the type of string is type (type : Type)\nSimilarly in Lean, the type of tt is bool (tt : bool) and the type of bool is Type (bool : Type)\nIn Lean, the type of every basic data type is just Type. Types are values, too, in Lean.\nThat let's us express ideas such as this: every value, t, of every data type T, equals itself\n-/\n\n#check ∀ (T : Type) (t : T), t = t\n-- for every type T, and every value t of this type, t = t.\n\n\n/-\nNow let's look at using #check to check expressions involving propositions. \n-/\n\n#check ∀ (P : Prop), P ∨ ¬P\n\n/-\nThe expression, ∀ (P : Prop), P ∨ ¬P, is syntactically correct;\nand because this value is a proposition, it's type is Prop. The \ntype of any proposition our higher-order predicate logic is Prop. \nHere's another example.\n-/\n\n#check 0 = 1\n\n/-\nThe expression 0 = 1 is a syntactically correct proposition,\nand because it's a proposition, it's type is also Prop\n-/\n\n#check true\n\n/-\nThe logical expression, true, is also a proposition,\nso it's type is also Prop.\n-/\n\n#check true.intro \n\n/-\nFinally we again see that propositions, themselves\nof type, Prop, are also types; just like string or\nbool are of type, Type, but are themselves types as\nwell. \n-/\n\n#check bool\n#check tt\n\n#check true\n#check true.intro\n\n/-\nProofs (or \"proof objects\" or \"proof terms\") in \nLean are values of logical/propositional types.\nIt's strange, but every proposition is its own\ntype in the higher-order constructive logic of\nLean. That is to say, in type theory, which you\nnow understand pretty well!\n-/\n\n/-\nExtra! So what's the type of Prop, or of Type?\nIn the following diagrams, --> means \"has type.\"\nSo, for example, Prop has type Type 0, which in\nLean we can and usually do write just as \"Type.\"\n\nProp   --> Type 0 --> Type 1 --> Type 2, ad inf.\nSort 0 --> Sort 1 --> Sort 2 --> Sort 3, ad inf.\n-/\n\n-- You can see it for yourself using #check\n\n-- Here with computational types\n#check 0\n#check nat\n#check Type\n#check Type 0\n#check Type 1\n-- ad infinitum\n\n-- Here with logical types\n#check true.intro -- a proof is a value\n#check true       -- a proposition is a type \"in\" Prop  \n#check Prop       -- the type of Prop is Type \n#check Type 1     -- etc.\n-- ad infinitum\n\n/-\nProp gets special treatment. In particular, and two\nproofs of any propositional type are considered to be\nequal, because they are considered to be equally good\n*as proofs*. This is certainly not the case for values\nof types that \"live in\" Type. Take bool, for example.\nIt has two obviously unqual values, tt and ff in Lean.\nBut suppose we have an arbitrary proposition, P, and\ntwo arbitrary proofs of it. Lean will treat them as\nbeing equal. \n-/\n\nexample (P : Prop) (pf1 pf2 : P) : pf1 = pf2 := rfl\n\n/-\nCool! Note by the way that here we used Python/C-style\n\"code\" by declaring named arguments before the colon.\nWe could have avoided that by binding names to formal\nparameters after the colon, with the same effect.\n-/\n\nexample : ∀ (P : Prop) (pf1 pf2 : P), pf1 = pf2 := \nbegin\nassume P p1 p2,\nexact rfl,\nend \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/01_Basic_Keywords/01_check.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703478, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.750009633765593}}
{"text": "-- proving 2^n > n^2 - 1\n\n-- https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/.E2.9C.94.20lean4.20induction.20with.20multiple.20base.20cases\n\nimport LeanUtils\nopen Nat\n\n\ntheorem two_exp_n (n : Nat) : 2^n > n^2 - 1 := by\n  match n with\n  | 0 => simp\n  | 1 => simp\n  | 2 => simp\n  | k+3 =>\n    have h₁ : 2^(k+2) > (k+2)^2 - 1 := two_exp_n (k + 2)\n    have h₂ : (k+3) >= 3 := by simp_arith\n    have h₃ : 2^(k+3) > (k+3)^2 - 1 := by calc\n      -- ring should be able to solve these types of equalities when fully implemented\n      2^(k+3) = 2 * 2^(k+2) := by admit\n      -- linarith should be able to solve this when implemented, but currently only in lean3\n      _ > 2 * ((k+2)^2 - 1) := by admit\n      _ = (k+2) ^ 2 + (k+2) ^ 2  - 2 := by admit\n      _ ≥ (k+2) ^ 2 + 3 * k - 2 := by admit\n      _ ≥ (k+2) ^ 2 + 2 * k + 1 := by admit\n      -- The following should be >, but gives \n      --    invalid 'calc' step, failed to synthesize `Trans` instance \n      --    Trans GT.gt GT.gt ?m.4046Lean\n      _ ≥ (k+2) ^ 2 + 2 * k := by admit\n      _ = (k+3) ^ 2 - 1 := by admit\n\n    assumption\n\n\n\n\n\n\n\n\n\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/not-working/2-exp-n/theorem.lean", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.787931188173138, "lm_q1q2_score": 0.7500027270642786}}
